context: introduce dependent context #238
Closed
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
The PR #236 fixes a snapshot
directory leakage issue, but also highlight a context
lifecycle/ownership issue.
In general in ghw each package creates its own context, including
the cases on which a package is consumed by another, for example
topology
andpci
. However, in this case, it would make more senseto reuse the context from the parent package, because the two packages
are tightly coupled.
Before the introduction of the the transparent snapshot support
(#202), the above mechanism worked,
because each context, each time, was consuming over and over again the
same parameters (e.g. environment variables); besides some resource
waste, this had no negative effect.
When introducing snapshots in the picture, repeatedly unpacking the
same snapshot to consume the same data is much more wasteful.
So it makes sense to introduce explicitly the concept of dependent
context.
We add a functio to create a context subordinate to another.
The subordinate context will effectively borrow all the resources from
the parent one. The parent is in charge to perform any setup/teardown
(e.g. for snapshot, to learn which chroot should be used, if at all)
and so forth.
Making this dependency explicit allow the client code to manage
correctly the lifecycle of the topmost context, hence of all the
resources.
Signed-off-by: Francesco Romani fromani@redhat.com