Skip to content

context: introduce dependent context#238

Closed
ffromani wants to merge 3 commits into
jaypipes:masterfrom
ffromani:parent-context
Closed

context: introduce dependent context#238
ffromani wants to merge 3 commits into
jaypipes:masterfrom
ffromani:parent-context

Conversation

@ffromani

Copy link
Copy Markdown
Collaborator

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 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
(#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 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>
@ffromani

Copy link
Copy Markdown
Collaborator Author

@jaypipes a bunch of cleanups found while helping with #236
I know I need to add a lot of docstrings in b4b6650 :) But please review so we can discuss the concepts exposed in this PR.

@ffromani

Copy link
Copy Markdown
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.

@ffromani

Copy link
Copy Markdown
Collaborator Author

done, let's continue on #230

@ffromani ffromani closed this Apr 12, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant