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

Add blockdev and update bios.rs #820

Closed
wants to merge 3 commits into from

Conversation

HuijingHei
Copy link
Member

@HuijingHei HuijingHei commented Jan 20, 2025

Prep for #132


Add bootc-blockdev and local crate blockdev
See containers/bootc#1050


blockdev.rs: Add #[allow(dead_code)] for the unused functions


bios.rs: update functions to use blockdev

Copy link

openshift-ci bot commented Jan 20, 2025

Skipping CI for Draft Pull Request.
If you want CI signal for your change, please convert it to an actual PR.
You can still manually trigger a test run with /test all

src/bios.rs Outdated
let device = self.get_device()?;
let device = device.trim();
self.run_grub_install("/", device)?;
let sysroot = sysroot.recover_path()?;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is taking us back from being file-descriptor based to path based, which is OK here, but it's usually better to find a way to continue using the fd.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Make sense, update to use format!("/proc/self/fd/{}", sysroot.as_raw_fd()), is this that you meant?

src/bios.rs Outdated
self.run_grub_install("/", device)?;
let sysroot = sysroot.recover_path()?;
let dest_root = sysroot.to_str().unwrap_or("/");
let devices = blockdev::get_backing_devices(&dest_root)?
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In this case, one technique is doing e.g. findmnt -nv -T . -o SOURCE and passing the file descriptor as the working directory. This would extend our bindings in findmnt.rs.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry, seems this is a little confusing, findmnt find the source of mount point, for example on RAID1 is /dev/md127, what we want is call find_parent_devices() to get the parent device.

src/bios.rs Outdated
let devices = blockdev::get_backing_devices(&dest_root)?
.into_iter()
.next();
let dev = devices.unwrap();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's use .ok_or_else(|| anyhow::anyhow!("Failed to find backing device for {dest_root}")) or so

}

/// Find all bios_boot partitions on the backing devices with mountpoint boot
#[allow(dead_code)]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm fine with this as is but I think it'd be slightly cleaner if this was part of the second patch

@@ -0,0 +1,208 @@
use std::collections::HashMap;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not a blocker here but maybe we should try to sync this code with https://github.com/containers/bootc/blob/main/lib/src/blockdev.rs ?

I could try to refactor that into a separate internal crate that we sync back into bootupd and coreos-installer?

Or of course we could even try to publish it.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not a blocker here but maybe we should try to sync this code with https://github.com/containers/bootc/blob/main/lib/src/blockdev.rs ?

I could try to refactor that into a separate internal crate that we sync back into bootupd and coreos-installer?

Or of course we could even try to publish it.

Thanks, that would be better and make this easier.
I tried to copy the bootc/blockdev.rs, but seems there are a lot of dependencies that also need to sync, for example Task and bootc_utils::CommandRunExt, so I give up.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The idea of #820 (comment) is that the Task dependency is gone. However yes, we'd need to pull in bootc-utils too. We could even do that now.

OK I did just that in #821

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cool, thanks!

Copy link
Member Author

@HuijingHei HuijingHei Jan 21, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we import https://github.com/containers/bootc/blob/main/lib/src/blockdev.rs like what you did in #821 ? Or wait until it is published?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

src/bios.rs Outdated
let device = device.trim();
self.run_grub_install("/", device)?;
let target_root = "/";
let devices = blockdev::get_backing_devices(&target_root)?
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How about adding a helper function like blockdev::get_single_backing_device() that errors out if it finds > 1 (and also errors out if we somehow get zero).

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Update to use blockdev::get_single_device().

cgwalters added a commit to cgwalters/bootc that referenced this pull request Jan 20, 2025
The install code and the blockdev code call each other.
Clean up blockdev to only use `bootc-utils`.
Prep for splitting out the blockdev stuff into at least a
separate internal crate; ref
coreos/bootupd#820

Signed-off-by: Colin Walters <[email protected]>
cgwalters added a commit to cgwalters/bootc that referenced this pull request Jan 20, 2025
The install code and the blockdev code call each other.
Clean up blockdev to only use `bootc-utils`.
Prep for splitting out the blockdev stuff into at least a
separate internal crate; ref
coreos/bootupd#820

Signed-off-by: Colin Walters <[email protected]>
@cgwalters
Copy link
Member

FYI I did containers/bootc#1048 to try to prepare bootc's blockdev.rs for reuse, but again nonblocking

@HuijingHei HuijingHei force-pushed the add-blockdev branch 3 times, most recently from 45bc80f to 74f86fa Compare January 22, 2025 13:17
@HuijingHei HuijingHei marked this pull request as draft January 22, 2025 13:29
@HuijingHei
Copy link
Member Author

Close this as did in #824

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants