-
Notifications
You must be signed in to change notification settings - Fork 195
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
daemon/syscore: push livefs introspection to Rust
This starts bridging parts of the daemon syscore logic to Rust plumbing, moving the livefs detection logic over there as a first consumer. That was the simplest logic available for wiring, and mostly meant as a sanity check.
- Loading branch information
1 parent
af37608
commit 87775cb
Showing
9 changed files
with
132 additions
and
32 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
/*! | ||
Helper C functions from rpm-ostree. | ||
These are prime candidates for oxidation (e.g. to make interacting with | ||
strings more efficient). | ||
NOTICE: The C header definitions are canonical, please update those first | ||
then synchronize the entries here. | ||
!*/ | ||
|
||
use crate::syscore::ffi::RpmOstreeOrigin; | ||
use libdnf_sys::DnfPackage; | ||
|
||
// From `libpriv/rpmostree-rpm-util.h`. | ||
extern "C" { | ||
pub(crate) fn rpmostree_get_repodata_chksum_repr( | ||
package: *mut DnfPackage, | ||
chksum: *mut *mut libc::c_char, | ||
gerror: *mut *mut glib_sys::GError, | ||
) -> libc::c_int; | ||
} | ||
|
||
// From `libpriv/rpmostree-origin.h`. | ||
extern "C" { | ||
pub(crate) fn rpmostree_origin_get_live_state( | ||
origin: *mut RpmOstreeOrigin, | ||
out_inprogress: *mut *mut libc::c_char, | ||
out_livereplaced: *mut *mut libc::c_char, | ||
); | ||
} |
This file contains 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
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
use self::ffi::RpmOstreeOrigin; | ||
use std::ptr::NonNull; | ||
|
||
/// Reference to an `RpmOstreeOrigin`. | ||
#[derive(Debug)] | ||
pub(crate) struct OriginRef { | ||
origin: NonNull<RpmOstreeOrigin>, | ||
} | ||
|
||
impl OriginRef { | ||
/// Build a reference object from a C pointer. | ||
fn from_ffi_ptr(oref: *mut RpmOstreeOrigin) -> Self { | ||
Self { | ||
origin: NonNull::new(oref).expect("NULL RpmOstreeOrigin"), | ||
} | ||
} | ||
|
||
/// Get `livefs` details for this deployment origin. | ||
pub(crate) fn get_live_state<'o>(&'o self) -> OriginLiveState<'o> { | ||
use crate::includes::rpmostree_origin_get_live_state; | ||
use glib::translate::from_glib_full; | ||
|
||
let mut out_inprogress: *mut libc::c_char = std::ptr::null_mut(); | ||
let mut out_livereplaced: *mut libc::c_char = std::ptr::null_mut(); | ||
unsafe { | ||
rpmostree_origin_get_live_state( | ||
self.origin.as_ptr(), | ||
&mut out_inprogress, | ||
&mut out_livereplaced, | ||
); | ||
}; | ||
let in_progress = unsafe { from_glib_full(out_inprogress) }; | ||
let replaced = unsafe { from_glib_full(out_livereplaced) }; | ||
|
||
OriginLiveState { | ||
_origin: self, | ||
in_progress, | ||
replaced, | ||
} | ||
} | ||
} | ||
|
||
/// `livefs` state and details for a given deployment origin. | ||
#[derive(Debug)] | ||
pub(crate) struct OriginLiveState<'o> { | ||
/// Underlying deployment origin. | ||
_origin: &'o OriginRef, | ||
/// Checksum for the in-progress livefs. | ||
pub in_progress: Option<String>, | ||
/// Checksum for the underlying replaced commit. | ||
pub replaced: Option<String>, | ||
} | ||
|
||
impl<'o> OriginLiveState<'o> { | ||
/// Return whether the given deployment is live-modified. | ||
pub(crate) fn is_live(self) -> bool { | ||
self.in_progress.is_some() || self.replaced.is_some() | ||
} | ||
} | ||
|
||
pub mod ffi { | ||
use super::OriginRef; | ||
|
||
/// Opaque type for C interop: RpmOstreeOrigin. | ||
pub enum RpmOstreeOrigin {} | ||
|
||
#[no_mangle] | ||
pub extern "C" fn ror_origin_is_live(origin_ptr: *mut RpmOstreeOrigin) -> libc::c_int { | ||
let origin = OriginRef::from_ffi_ptr(origin_ptr); | ||
let livestate = origin.get_live_state(); | ||
livestate.is_live().into() | ||
} | ||
} |
This file contains 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
This file contains 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
This file contains 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
This file contains 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