Skip to content

Commit af550f7

Browse files
authored
Merge pull request #704 from cgwalters/drop-nix
install: Fork `blockdev --rereadpt` instead of internal ioctl
2 parents 37b6948 + 0002d6e commit af550f7

File tree

4 files changed

+5
-67
lines changed

4 files changed

+5
-67
lines changed

Cargo.lock

Lines changed: 1 addition & 20 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

lib/Cargo.toml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,6 @@ libc = { workspace = true }
2929
liboverdrop = "0.1.0"
3030
libsystemd = "0.7"
3131
openssl = "^0.10.64"
32-
# TODO drop this in favor of rustix
33-
nix = { version = "0.29", features = ["ioctl", "sched" ] }
3432
regex = "1.10.4"
3533
rustix = { "version" = "0.38.34", features = ["thread", "fs", "system", "process"] }
3634
schemars = { version = "0.8.17", features = ["chrono"] }

lib/src/blockdev.rs

Lines changed: 0 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,12 @@
11
use std::collections::HashMap;
22
use std::env;
3-
use std::fs::File;
4-
use std::os::unix::io::AsRawFd;
53
use std::path::Path;
64
use std::process::Command;
75
use std::sync::OnceLock;
86

97
use anyhow::{anyhow, Context, Result};
108
use camino::{Utf8Path, Utf8PathBuf};
119
use fn_error_context::context;
12-
use nix::errno::Errno;
1310
use regex::Regex;
1411
use serde::Deserialize;
1512

@@ -270,30 +267,6 @@ pub(crate) fn udev_settle() -> Result<()> {
270267
Ok(())
271268
}
272269

273-
#[allow(unsafe_code)]
274-
pub(crate) fn reread_partition_table(file: &mut File, retry: bool) -> Result<()> {
275-
let fd = file.as_raw_fd();
276-
// Reread sometimes fails inexplicably. Retry several times before
277-
// giving up.
278-
let max_tries = if retry { 20 } else { 1 };
279-
for retries in (0..max_tries).rev() {
280-
let result = unsafe { ioctl::blkrrpart(fd) };
281-
match result {
282-
Ok(_) => break,
283-
Err(err) if retries == 0 && err == Errno::EINVAL => {
284-
return Err(err)
285-
.context("couldn't reread partition table: device may not support partitions")
286-
}
287-
Err(err) if retries == 0 && err == Errno::EBUSY => {
288-
return Err(err).context("couldn't reread partition table: device is in use")
289-
}
290-
Err(err) if retries == 0 => return Err(err).context("couldn't reread partition table"),
291-
Err(_) => std::thread::sleep(std::time::Duration::from_millis(100)),
292-
}
293-
}
294-
Ok(())
295-
}
296-
297270
/// Parse key-value pairs from lsblk --pairs.
298271
/// Newer versions of lsblk support JSON but the one in CentOS 7 doesn't.
299272
fn split_lsblk_line(line: &str) -> HashMap<String, String> {
@@ -340,16 +313,6 @@ pub(crate) fn find_parent_devices(device: &str) -> Result<Vec<String>> {
340313
Ok(parents)
341314
}
342315

343-
// create unsafe ioctl wrappers
344-
#[allow(clippy::missing_safety_doc)]
345-
mod ioctl {
346-
use libc::c_int;
347-
use nix::{ioctl_none, ioctl_read, ioctl_read_bad, libc, request_code_none};
348-
ioctl_none!(blkrrpart, 0x12, 95);
349-
ioctl_read_bad!(blksszget, request_code_none!(0x12, 104), c_int);
350-
ioctl_read!(blkgetsize64, 0x12, 114, libc::size_t);
351-
}
352-
353316
/// Parse a string into mibibytes
354317
pub(crate) fn parse_size_mib(mut s: &str) -> Result<u64> {
355318
let suffixes = [

lib/src/install/baseline.rs

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -315,14 +315,10 @@ pub(crate) fn install_create_rootfs(
315315
tracing::debug!("Created partition table");
316316

317317
// Reread the partition table
318-
{
319-
let mut f = std::fs::OpenOptions::new()
320-
.write(true)
321-
.open(&devpath)
322-
.with_context(|| format!("opening {devpath}"))?;
323-
crate::blockdev::reread_partition_table(&mut f, true)
324-
.context("Rereading partition table")?;
325-
}
318+
Task::new("Reread partition table", "blockdev")
319+
.arg("--rereadpt")
320+
.arg(devpath.as_str())
321+
.run()?;
326322

327323
// Full udev sync; it'd obviously be better to await just the devices
328324
// we're targeting, but this is a simple coarse hammer.

0 commit comments

Comments
 (0)