context: introduce dependent context#238
Closed
ffromani wants to merge 3 commits into
Closed
Conversation
The PR jaypipes#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` and `pci`. However, in this case, it would make more sense to reuse the context from the parent package, because the two packages are tightly coupled. Before the introduction of the the transparent snapshot support (jaypipes#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>
the pci package want to use the topology package, and passes its context down to it. However, nontrivial initialization is performed in pci.Info.load(), when snapshots are consumed - most notably in test. Hence, we need to ensure that `topology.WithContext` is called only after context.Setup() is called for the pci context. This is needed because in turn the pci packaged doesn't know (nor it should) if its context is a root (= top level) context, hence if it owns the resources which are passed to the dependent packages. Signed-off-by: Francesco Romani <fromani@redhat.com>
`WithChroot` and `WithSnapshot` conflicts to each other, and the users can get surprising results if they try to use them at the same time. Now: chroot is expected to be much more popular than snapshots, being the latter useful mostly for tests or offline debug/troubleshoot, but still the code should detect and handle these conflicts. This is made a bit awkward because the current `context` pkg API. Once we are free to break compatibility, we can make the flow more linear. Signed-off-by: Francesco Romani <fromani@redhat.com>
Collaborator
Author
Collaborator
Author
|
the SRIOV support (#230) is the main driver for this PR, so I think I'll just rebase 230 on top of this one. |
Collaborator
Author
|
done, let's continue on #230 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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
topologyandpci. 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