Commit Graph

420 Commits

Author SHA1 Message Date
Colin Walters
6eb3caf9a9 Add Rust progress task wrapper
The manual `std::mem::drop()` bits are ugly; while we can do
function pointers from Rust to C++, let's just add the obvious
high level wrapper in Rust that accepts a `FnOnce()`.

Note in one instance we directly pass a function pointer which
is quite clean.
2021-03-16 14:54:26 +00:00
Colin Walters
531907af90 rust: Rename progress.rs to console_progress.rs
To clarify it's effectively only a backend for our higher
level output abstraction.
2021-03-16 14:50:30 +00:00
Jonathan Lebon
acc3aa1ac7
Merge pull request #2657 from cgwalters/live-tmpfiles
rust: Introduce systemd-run based isolation mod, use in live
2021-03-16 09:13:19 -04:00
Luca Bruno
35c31205a6
Merge pull request #2664 from cgwalters/postprocess-rs-more
Various postprocess oxidation patches
2021-03-16 08:47:11 +00:00
Colin Walters
f90124f363 composepost: Clean up imports
From review comments.
2021-03-15 22:24:23 +00:00
Colin Walters
9126831b8b rust: Introduce systemd-run based isolation mod, use in live
I was thinking about privilege separation today with
systemd units, and that led me to the problem of "lifecycle binding".
We really want e.g. `systemctl stop rpm-ostreed` to kill any
separate systemd units we're managing.

systemd already has a mechanism for this with `BindsTo=`.

And then I realized we weren't doing this for the systemd-tmpfiles
invocations in the `live.rs` code.

Generalize this into a small `isolation` module that fixes this
and several other things at the same time.  I'd like to build
on this to further improve our multi-process isolation story
later.
2021-03-15 21:06:13 +00:00
Luca BRUNO
efb50f5cc1 passwd: minor cleanups
This contains a couple of minor code cleanups, left over from previous
reviews.
2021-03-15 15:32:44 -04:00
Jonathan Lebon
c41adb0ad2
Merge pull request #2648 from cgwalters/deployment-status-cleanup
Move some small daemon layering lookup into Rust
2021-03-15 14:11:56 -04:00
Colin Walters
a0acdb596d Move writing /usr/share/rpm-ostree/treefile.json to Rust
More oxidation.  Also with a quick unit test now.
2021-03-15 13:18:57 +00:00
Colin Walters
9ad499ffd3 Move units/machineid-compat checking to treefile in Rust
More oxidation.
2021-03-15 13:18:57 +00:00
Colin Walters
3e856cb3be postprocess: Move treefile externals sanitycheck to Rust
This code really makes sense as a method on the treefile.

And when that's done, we no longer need to expose
`get_postprocess_script()` via cxx, so we can return a nicely
Rust native `Option<&mut File>`.
2021-03-15 13:18:57 +00:00
Colin Walters
62b47c64c6 postprocess: Move add-files handling to Rust
Port add-files handling to Rust.

Note that there's one very magical line of diff here worth calling out:
We dropped an interface from the cxxrs bridge, because both sides
are now Rust!  The treefile code can directly return an `&mut File` reference
instead of needing to pass the raw fd as `i32`.
2021-03-15 13:18:57 +00:00
Colin Walters
ac92456bdd postprocess: Move script execution to Rust
Continuing oxidation.
2021-03-15 13:18:57 +00:00
Colin Walters
1b3bdc243e Move high level bwrap postprocess interface to C++
A future patch will then expose this interface via cxxrs, allowing
us to port more of the postprocess.cxx code to Rust.
2021-03-15 13:18:57 +00:00
Luca Bruno
9deeeedc5d
Merge pull request #2660 from cgwalters/postprocess-rs-nsswitch
Oxidize postprocessing `altfiles` addition to `/etc/nsswitch.conf`
2021-03-15 08:32:05 +00:00
Colin Walters
c675b385c7 Oxidize postprocessing altfiles addition to /etc/nsswitch.conf
The ugly C code for this turns into shorter Rust with a unit
test, a lot less allocation (notice how we don't malloc `NUL` terminated
strings in so many places).
2021-03-12 23:10:33 +00:00
Colin Walters
aa64df080d daemon: Fix serialization of unlocked state
It turns out there's a naming clash between `to_string()` here in
Rust *and* introspection is incorrectly associating the method
with `ostree::Deployment` because of the naming prefix.
2021-03-12 18:01:47 -05:00
Colin Walters
2187ef0f45 live: Don't output "services restart" for pure package additions
If all we're doing is layering new packages, no need to tell
the admin that things may need restarting.
2021-03-11 22:50:07 +00:00
Colin Walters
8ec0a3db12 rust: Support context attribute on CxxResult, use it more
Addresses review comment from
https://github.com/coreos/rpm-ostree/pull/2649#discussion_r591784574
and extends it in a few more random places I found that were
using `with_context()`.
2021-03-11 13:03:41 -05:00
Jonathan Lebon
5f17bc5c87 lockfile: Return LockfileConfig rather than Vec<StringMapping>
I don't like the use of `HY_GLOB` in the lockfile package matching. We
have all the information in the Rust object, so it's silly to condense
that to a single string in a hashmap.

Fix this by returning the `LockfileConfig` object itself and then adding
a function to fetch the list of locked packages. This allows the C++
side to see all the individual fields which makes filtering trivial.

The next step is moving all the code which needs the lockfile to Rust.
Then we can drop the shared `LockedPackage` type.

(I did start on converting `find_locked_packages`, though it requires
adding bindings for all the `HyQuery` stuff, which...  isn't great (and
also runs into the fact that `hy_query_run` needs to return a
GPtrArray). I think instead of a 1:1 mapping, we'll probably want the
libdnf-sys API wrappers to provide some sugar for the common paths.)
2021-03-11 00:01:46 +01:00
Jonathan Lebon
c03f5d50a3 lockfile: Drop ror_ prefix
That's a cbindgen-era thing.
2021-03-11 00:01:46 +01:00
Jonathan Lebon
2fedc3b0ac lockfile: Allow specifying EVR rather than EVRA
In FCOS, we use "override" lockfiles to pin packages to certain
versions. Right now, we have separate overrides for each base arch we
(eventually want to) support. But that makes maintaining the overrides
cumbersome because of all the duplication.

Let's allow lockfiles to specify only the `evr` of a package, which is
just as good for FCOS, and means that we'll only have to maintain a
single override file for all the architectures.
2021-03-11 00:01:46 +01:00
Timothée Ravier
775bdfd770 rust: Relicense some GPL-2.0-or-later to Apache-2.0 OR MIT
Explicit sign-off-by from authors:
Signed-off-by: Timothée Ravier <travier@redhat.com>
2021-03-10 21:55:50 +01:00
Colin Walters
95ff12b913 rust: Add and use fn-error-context
Same motivation as https://github.com/coreos/bootupd/pull/163

Effectively what we're doing here is creating a human-readable subset
of the stack trace. This is nicer than having the calling functions
add with_context() because it's more verbose (gets duplicative at
each call site), easy to forget, etc.
2021-03-10 19:56:48 +01:00
Colin Walters
e02fff3d5a Move some small daemon layering lookup into Rust
Prep for more oxidation work.  One notable improvement here is that about half
of the callers of the mega function `rpmostree_deployment_get_layered_info`
only wanted the base information, not the layered package lists
for example - so we were passing 4 `NULL`s to ignore those.

This Rust API returns a simple shared struct instead for those
cases.  I also changed things so that `base_commit` is always
set, avoiding the callers needing to do that.
2021-03-08 23:01:50 +00:00
Colin Walters
485c1862ce live: Disallow replacement/removal by default, add --allow-replacement
There's a huge difference between live updates that change
existing things, versus simply adding new packages (files).

The latter is really quite safe, and live layering is one
of the most requested features.
2021-03-08 20:54:18 +01:00
Colin Walters
0ec09e6155 live: Hold a single sysroot object
Rather than creating one only when `--reset` is used, hold
one open across the whole operation.
2021-03-08 20:54:18 +01:00
Colin Walters
03fd76d615 live: Use a shared constant for option
In the name of avoiding typos etc.
2021-03-08 20:54:18 +01:00
Colin Walters
b0eccadb22 live: Pass options GVariant down
I have no idea why I didn't do this originally, it's much
cleaner than parsing the options in C.
2021-03-08 20:54:18 +01:00
Colin Walters
01b59f20ba daemon: Move a bit more deployment-variant code to Rust
These are "base ostree" things we can move into the Rust
function.
2021-03-08 19:58:18 +01:00
dependabot[bot]
fbe01b403f build(deps): bump serde from 1.0.123 to 1.0.124
Bumps [serde](https://github.com/serde-rs/serde) from 1.0.123 to 1.0.124.
- [Release notes](https://github.com/serde-rs/serde/releases)
- [Commits](https://github.com/serde-rs/serde/compare/v1.0.123...v1.0.124)

Signed-off-by: dependabot[bot] <support@github.com>
2021-03-08 11:06:40 -05:00
Colin Walters
3d7ac1d637 rust/client: derive(Debug, Clone)
Zincati wants this and it's a friendly thing to do.
2021-03-08 09:58:56 -05:00
Jonathan Lebon
175de36732 compose/extensions: Handle no --base-rev
In this case, let's default to the tip of the tree ref.

Closes: #2633
2021-03-07 19:46:52 -05:00
Colin Walters
8f77970683 client: Add API to fetch base commit metadata
Also desired by Zincati.
2021-03-05 18:20:03 -05:00
Colin Walters
5b647af14a rust/client: Add Deployment/get_base_commit() API
Zincati wants this.
2021-03-05 18:20:03 -05:00
Colin Walters
14c17cfe52 rust/client: Add methods to find/require booted deployment
This is a common need.
2021-03-05 18:20:03 -05:00
Colin Walters
1662f246fd rust/client: Add a CliClient with agent ID, require for status
In prep for adding more methods, require the caller to identify
themselves.

For now this is `CliClient` - one could imagine in the future
we actually do direct DBus, but there's a whole other world
of stuff there.
2021-03-05 18:20:03 -05:00
Colin Walters
3354ca9d30 rust/client: Extend with more metadata for zincati
Add more metadata that zincati needs, like `base-commit-meta`
which includes the `fedora-coreos.stream` key and the cosa basearch,
etc.

Also `Derive(Debug)` since it's used in a cache struct that also
derives debug, and that's a friendly thing to do in general.
2021-03-05 05:47:01 -05:00
Colin Walters
0bae05d4c0 apply-live: Fix --target option
It is an option, not a positional.  (Not covered in CI it turns out)
2021-03-04 16:21:51 -05:00
Colin Walters
13804d84a1 Add more client Rust bindings, port apply-live builtin
This adds sufficient infrastructure to fully port the
`rpmostree-builtin-applylive.cxx` client code to Rust.
We just keep a stub entrypoint for now until we port
the rest of `rpmostree-builtin-ex.cxx`, at which point
a lot of C++ files go away.

The "finish" bits move from the daemon-oriented `live.rs`
into a new `rust/src/builtins` directory.  I'd like
to try to more cleanly split up the Rust sources along
core(shared)/client/daemon directories in the future.
2021-03-04 09:17:21 -05:00
Colin Walters
6fd9db246a Add basic Rust CLI bindings for DBus
This stubs out sufficient infrastructure for us to register
as a client and call the Moo API.

A glaring problem here is the lack of extensive `glib::Variant`
bindings; that's covered in the next gtk-rs release.

My real goal was to try porting the `rpmostree-builtin-apply-live.cxx`
code entirely to Rust, but there's more to do to expose the
transaction helper APIs we have.
2021-03-04 09:17:21 -05:00
Colin Walters
60e605b34e Introduce CxxGObjectArray, use in lockfile code
cxx-rs only supports a few basic types in `Vec<T>`/`CxxVector<T>`
and we need to pass an array of GObjects in a few cases.
Add a wrapper class hack instead of using `u64` so we at least
have some basic safety here and have a convenient place to
grep for later when we want to improve this.
2021-03-02 16:25:32 -08:00
Jonathan Lebon
5c1911445c Finish moving lockfile to cxx.rs
This moves the `ror_lockfile_write` to cxx.rs, which brings us closer to
getting rid of cbindgen now.

There's one massive hack this uses, which is that we pass an array of
pointers to `DnfPackage` and `DnfRepo` objects as u64. We'll want to
circle back and fix that up once either cxx.rs supports natively arrays
of pointers, or we just come up with our own wrapper type for it.

But for now at least, this unblocks the cbindgen transition and hacking
on the lockfile code.
2021-03-02 16:25:32 -08:00
Luca BRUNO
6b13f2596c rust/treefile: add support for check-passwd/groups data entries
This adds treefile support for both `check-passwd` and `check-groups`
entries with "type: data".
2021-03-02 08:08:05 -08:00
Colin Walters
9b3612b3ff cxxrsutil: Generalize cxxrs_bind! macro
This generalizes our binding macro, so we can trivially e.g.
add `Variant` into the entry of bound glib types.
2021-03-02 01:14:30 -08:00
dependabot[bot]
6dd2df19bc build(deps): bump serde_json from 1.0.62 to 1.0.64
Bumps [serde_json](https://github.com/serde-rs/json) from 1.0.62 to 1.0.64.
- [Release notes](https://github.com/serde-rs/json/releases)
- [Commits](https://github.com/serde-rs/json/compare/v1.0.62...v1.0.64)

Signed-off-by: dependabot[bot] <support@github.com>
2021-03-01 17:46:49 +01:00
Luca BRUNO
de7d20e43b libpriv/passwd: move UID/GID checker to Rust
This ports to Rust the logic for checking whether a directory tree
contains content owned by a given UID/GID.
2021-02-26 00:34:56 +01:00
Luca BRUNO
dbe2d50cf1 treefile: add getters for check-passwd and check-groups
This add default-aware getters for `check-passwd` and `check-groups`.
2021-02-25 19:24:12 +01:00
dependabot[bot]
380ebc5ada build(deps): bump cxx-build from 1.0.31 to 1.0.32
Bumps [cxx-build](https://github.com/dtolnay/cxx) from 1.0.31 to 1.0.32.
- [Release notes](https://github.com/dtolnay/cxx/releases)
- [Commits](https://github.com/dtolnay/cxx/compare/1.0.31...1.0.32)

Signed-off-by: dependabot[bot] <support@github.com>
2021-02-24 23:27:25 +01:00
Colin Walters
5a79ca9035 apply-live: Rework to use refs to store state
Came out of discussion in https://github.com/coreos/rpm-ostree/pull/2581
around some racy code for checking for the live commit object.

The reliability of apply-live depends on the
underlying commits not being garbage collected.  Our diff logic
is in terms of ostree commits, not the physical filesystem (this
allows us to make various optimizations too).

Ultimately I think we should drive some of the live-apply
logic into libostree itself; we can more easily have an atomic
state file instead of the two split refs.

(Or perhaps what we should add to ostree is like a refs.d model
 where a single atomic file can refer to multiple commits)

For now though let's rework the code here to write refs.  We
retain the file in `/run` as just a "stamp file" that signals
that a deployment has had `apply-live` run.
2021-02-23 21:51:22 -05:00