-
Notifications
You must be signed in to change notification settings - Fork 29
Make parent devices global #923
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
base: main
Are you sure you want to change the base?
Conversation
140d3ad
to
7b65bfb
Compare
@dustymabe I think you meant to initialize esp devices, store them and read after, this is the first step make parent devices global, initialize once and read then. Not sure if can make esp devices or bios devices like this, or other way? |
LGTM |
src/cli/bootupctl.rs
Outdated
let devices = crate::blockdev::get_devices(&dest_root) | ||
.with_context(|| "while looking for parent devices")?; | ||
crate::blockdev::init_parent_devices(devices); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Here's where I'd suggest moving the static
instead.
However even then in theory the parent devices are scoped to a particular destination root and so it can't actually be static. Which means it's hard to cache in that way.
So if we wanted to avoid querying the devices multiple times, then what we'd need to do is query them up front and then pass them down. That may involve more code churn though.
src/cli/bootupctl.rs
Outdated
let sysroot = openat::Dir::open("/").context("Opening root dir")?; | ||
let dest_fd = format!("/proc/self/fd/{}", sysroot.as_raw_fd()); | ||
let dest_root = std::fs::read_link(dest_fd)?; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmm so actually we always operated on /
, and this code pattern was just a really complicated way to go from /
-> file descriptor -> /
effectively.
The only tricky thing here is that eventually we actually do want to operate on the non-booted root! See #108
src/cli/bootupctl.rs
Outdated
let sysroot = openat::Dir::open("/").context("Opening root dir")?; | ||
let dest_fd = format!("/proc/self/fd/{}", sysroot.as_raw_fd()); | ||
let dest_root = std::fs::read_link(dest_fd)?; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Per above I think we can just for now hardcode something like
let devices = crate::blockdev::get_devices("/")
here.
It actually may make sense to move the static
to this function as it's the one that's also hardcoding /
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Updated, seems will read the static devices later, move the static
to crate::blockdev::get_parent_devices()
with option, add get_parent_devices(None)
to verify it works. WDYT?
As `PARENT_DEVICES` is used multiple times, initialize once at the begining and read them then, add this in `get_parent_devices()` according to coreos#923 (comment)
b61faad
to
60c61c5
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
IANA rust expert, but LGTM
Thank you all for the review! Does it make sense to do the same thing for
Or just |
Remove duplicated sysroot as `openat::Dir::open("/")` and pass as parameter
60c61c5
to
95af34c
Compare
Edit: |
Sorry that click the wrong button, reopen it. |
I think Dusty's original comment in #855 (comment) was correct in that we're clearly parsing the devices a lot. However, this is turning into a nontrivial architectural change and it's not clear to me that we have any real performance concerns here. (Really, most of this data is cached in the kernel or filesystem, we're just re-parsing files into JSON and then back into data structures, but computers are fast) Looking at this more I don't think we want a global cache, we just want to gather the context up front and pass it down. So instead of passing just plain "sysroot" we'd pass e.g.
or so? (And actually given all the pain that using openat has caused here, we might as well add |
This SGTM. |
The main of the patch is to initialize parent devices once at the beginning and read them then, also remove some duplicated sysroot as
openat::Dir::open("/")
and pass as a parameter.Refer to #855 (comment)