Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Provide C interface for modularity APIs #874

Closed
jlebon opened this issue Jan 8, 2020 · 13 comments · Fixed by #1200
Closed

Provide C interface for modularity APIs #874

jlebon opened this issue Jan 8, 2020 · 13 comments · Fixed by #1200

Comments

@jlebon
Copy link
Contributor

jlebon commented Jan 8, 2020

Right now, AFAICT dnf module leverages the libdnf SWIG API for managing modules. This is an issue for C/Rust clients like rpm-ostree which also want to support modularity (coreos/rpm-ostree#1435).

Are those SWIG APIs considered stable/public at this point? Not having to support two interfaces would simplify things.

@cgwalters
Copy link
Collaborator

One thing tangentially related to this - I think we should be moving to running most of the libdnf stuff as a subprocess. This would allow us to drop privileges for it, and also help avoid things like the way librpm might call chroot() - so we'd end up with some sort of API (I was playing with ipc-channel in coreos/rpm-ostree#1680 ) wrapper around it.

Of course that inner subprocess would need to use C++ but the idea is we're avoiding intermixing C/Rust and C++ directly.

@Conan-Kudo
Copy link
Member

There are some plans to rewrite dnfdaemon from ManaTools into C++ and integrate it into the libdnf project to provide a D-BUS based interface for clients. How this will happen and what that will look like exactly hasn't been hammered out yet.

But there are no plans to drop the direct library interface. The daemon will merely provide an extra mechanism.

@lukash
Copy link
Contributor

lukash commented Jan 9, 2020

One thing tangentially related to this - I think we should be moving to running most of the libdnf stuff as a subprocess. This would allow us to drop privileges for it, and also help avoid things like the way librpm might call chroot() - so we'd end up with some sort of API (I was playing with ipc-channel in coreos/rpm-ostree#1680 ) wrapper around it.

Of course that inner subprocess would need to use C++ but the idea is we're avoiding intermixing C/Rust and C++ directly.

Hi, this looks like something worth elaborating on. I'm not sure I understand you correctly but it seems to be an important design aspect.

On the point of intermixing C++ and C/Rust, I'm not sure how you mean it, you can't directly intermix the two. If we have C++ API in libdnf, you can't use that from either C or Rust (at least that was true for Rust some time ago and I don't expect that to change), the C++ API needs to be wrapped in C API (either as part of libdnf, which is what our plan is, or alternatively as an external wrapper). So that's the way to do it and I think our plan how to cater to coreos.

What are the specific reasons for you to have libdnf code running as a subprocess? Those reasons are important, because using a subprocess is quite a change in design. As @Conan-Kudo said, we are planning on providing a D-BUS daemon (which solves issues like having to be root), and that is quite probably what you'd want to use if you wanted to have libdnf in a different process (instead of forking it directly)?

I suppose you cold also use the C++ and wrap that in some sort of IPC to for k as your own subprocess, but I'm not sure there are good reasons to do that.

The thing is, I think coreos is one of the major consumers of the planned C API (it may be the only one?), so if you ended up preferring to use the D-BUS API and the daemon, I assume the priorities for the C API would suddenly go down quite a bit (and the daemon would raise in priority).

My $0.02, hope it's making sense to you.

jlebon added a commit to jlebon/libdnf that referenced this issue Jan 27, 2020
For some reason, `dnf_repo_download_packages` would reread and re-apply
all the knobs from the keyfile, clobbering any runtime changes we
might've made.

This behaviour is quite old (about 5 years ago). It dates back to
cc0f5aa, which says it was originally a workaround for a recent librepo
behaviour change. It's not clear what that change was, but ISTM if we
hit any regressions from this, we should just fix either librepo or
whatever is throwing off librepo instead of re-reading the full keyfile.

This should fix Silverblue Rawhide rpm-ostree composes:
https://pagure.io/releng/failed-composes/issue/717
https://pagure.io/releng/failed-composes/issue/929

where we use a hack to allow rpm-ostree to install modular packages
until we fully support modules (which requires rpm-software-management#874) and this bit was
resetting the hack we do.
jlebon added a commit to jlebon/libdnf that referenced this issue Jan 29, 2020
We were setting the runtime value of the knob instead of the repoconfig
value. This meant that a user wanting to override the config via
`dnf_repo_set_module_hotfixes` (which also sets the runtime value) would
have its changes clobbered.

This should fix Silverblue Rawhide rpm-ostree composes:
https://pagure.io/releng/failed-composes/issue/717
https://pagure.io/releng/failed-composes/issue/929

where we use a hack to allow rpm-ostree to install modular packages
until we fully support modules (which requires rpm-software-management#874) and it was getting
reset because `dnf_repo_download_packages` wants to reset the repo
config from the keyfile. For more information, see discussions at:

rpm-software-management#885
rh-atomic-bot pushed a commit that referenced this issue Feb 4, 2020
We were setting the runtime value of the knob instead of the repoconfig
value. This meant that a user wanting to override the config via
`dnf_repo_set_module_hotfixes` (which also sets the runtime value) would
have its changes clobbered.

This should fix Silverblue Rawhide rpm-ostree composes:
https://pagure.io/releng/failed-composes/issue/717
https://pagure.io/releng/failed-composes/issue/929

where we use a hack to allow rpm-ostree to install modular packages
until we fully support modules (which requires #874) and it was getting
reset because `dnf_repo_download_packages` wants to reset the repo
config from the keyfile. For more information, see discussions at:

#885

Closes: #885
Approved by: j-mracek
@cgwalters
Copy link
Collaborator

Sorry, my mentioning of subprocessing was unnecessary and added too much confusion here.

Today, rpm-ostree's code is deeply entangled with the libdnf APIs; having C instead of C++ APIs would definitely be helpful in the short term.

@LorbusChris
Copy link

This issue has been dormant for 10 months now - I wonder what we can do to get some traction on the issue?

@Conan-Kudo
Copy link
Member

There is a gobject-based C interface for modularity with the release of libdnf 0.55.2. It is used in microdnf 3.5.1.

@jlebon
Copy link
Contributor Author

jlebon commented Apr 16, 2021

Looking more closely at this (while trying to implement support for it in rpm-ostree), it seems like this is missing the most crucial bit, which is exposing ModulePackageContainer::install(). Otherwise, there isn't any way to actually install modules. Can we re-open this?

@Conan-Kudo
Copy link
Member

I suppose so. Micro DNF just implements enable/disable/reset and lets the normal install command work, but I guess you want to implement the all-in-one workflow too?

@Conan-Kudo Conan-Kudo reopened this Apr 16, 2021
@jlebon
Copy link
Contributor Author

jlebon commented Apr 16, 2021

The API I'm trying to go for is something like this in the treefile:

modules:
  - cri-o:1.20

This should enable the module, and mark it for installation. I could use dnf_context_install() for the latter, but I want something more explicit there because dnf_context_install() is not modularity aware so e.g. nothing actually stops it from picking a bare package.

@Conan-Kudo
Copy link
Member

That's not correct. If you've enabled modules, they get factored into the solution process afterward. Otherwise microdnf would not be able to install the correct stuff from modules after users enabled/disabled/reset module states.

@jlebon
Copy link
Contributor Author

jlebon commented Apr 16, 2021

Hmm OK cool, that does work correctly. But we still need an API to be able to install modules at the profile level rather than the package level.

Edit: started hacking on a patch to add dnf_context_module_install.

@jlebon
Copy link
Contributor Author

jlebon commented Apr 16, 2021

I guess for rpm-ostree just like dnf we'll need to allow both cases, i.e. installing a module by profile and installing specific packages within a module. Need to think a bit on the cleanest declarative UX to represent these.

jlebon added a commit to jlebon/libdnf that referenced this issue Apr 19, 2021
This is a C-compatible API similar to `dnf_context_module_enable()`
which additionally marks the target packages for installation. This is
similar to `dnf module install`.

We intend to use this in rpm-ostree as well.

Closes: rpm-software-management#874
jlebon added a commit to jlebon/libdnf that referenced this issue Apr 19, 2021
This is a C-compatible API similar to `dnf_context_module_enable()`
which additionally marks the target packages for installation. This is
similar to `dnf module install`.

We intend to use this in rpm-ostree as well.

Closes: rpm-software-management#874
@jlebon
Copy link
Contributor Author

jlebon commented Apr 19, 2021

#1200

jlebon added a commit to jlebon/libdnf that referenced this issue Apr 20, 2021
This is a C-compatible API similar to `dnf_context_module_enable()`
which additionally marks the target packages for installation. This is
similar to `dnf module install`.

We intend to use this in rpm-ostree as well.

Closes: rpm-software-management#874

= changelog =
msg: Add new dnf_context_module_install() C API
type: enhancement
resolves: rpm-software-management#874
Conan-Kudo pushed a commit that referenced this issue Apr 21, 2021
This is a C-compatible API similar to `dnf_context_module_enable()`
which additionally marks the target packages for installation. This is
similar to `dnf module install`.

We intend to use this in rpm-ostree as well.

Closes: #874

= changelog =
msg: Add new dnf_context_module_install() C API
type: enhancement
resolves: #874
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 a pull request may close this issue.

5 participants