Skip to content

Commit ee479c6

Browse files
committed
Only try calling zfs on illumos machines
1 parent b0266aa commit ee479c6

File tree

1 file changed

+17
-45
lines changed

1 file changed

+17
-45
lines changed

downstairs/src/region.rs

Lines changed: 17 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -398,7 +398,13 @@ impl Region {
398398
Ok(())
399399
}
400400

401-
/// Looks up the recordsize for a particular path
401+
#[cfg(not(target_os = "illumos"))]
402+
fn get_recordsize(&self) -> Result<u64, CrucibleError> {
403+
Ok(extent_inner_raw_v2::DUMMY_RECORDSIZE)
404+
}
405+
406+
/// Looks up the recordsize for the base path
407+
#[cfg(target_os = "illumos")]
402408
fn get_recordsize(&self) -> Result<u64, CrucibleError> {
403409
let recordsize = {
404410
let p = std::process::Command::new("zfs")
@@ -407,69 +413,35 @@ impl Region {
407413
.arg("-ovalue")
408414
.arg("recordsize")
409415
.arg(&self.dir)
410-
.stdout(std::process::Stdio::piped())
411-
.stderr(std::process::Stdio::piped())
412-
.spawn();
416+
.output();
413417
match p {
414-
Ok(mut p) => {
415-
p.wait().map_err(|e| {
416-
CrucibleError::IoError(format!(
417-
"call to `zfs` failed: {e}"
418-
))
419-
})?;
420-
let mut err = vec![];
421-
p.stderr.unwrap().read_to_end(&mut err).map_err(|e| {
418+
Ok(p) => {
419+
let err = std::str::from_utf8(&p.stderr).map_err(|e| {
422420
CrucibleError::IoError(format!(
423-
"failed to read stderr from `zfs`: {e:?}"
424-
))
425-
})?;
426-
let err = std::str::from_utf8(&err).map_err(|e| {
427-
CrucibleError::IoError(format!(
428-
"zfs returned invalid UTF-8 string: {err:?} ({e})"
421+
"zfs returned invalid UTF-8 string: {e}"
429422
))
430423
})?;
431424
if err.contains("not a ZFS filesystem") {
432425
extent_inner_raw_v2::DUMMY_RECORDSIZE
433426
} else {
434-
let mut out = vec![];
435-
p.stdout.unwrap().read_to_end(&mut out).map_err(
436-
|e| {
427+
let out =
428+
std::str::from_utf8(&p.stdout).map_err(|e| {
437429
CrucibleError::IoError(format!(
438-
"failed to read stdout from `zfs`: {e:?}, \
430+
"zfs returned invalid UTF-8 string: {e}, \
439431
stderr: {err}"
440432
))
441-
},
442-
)?;
443-
let out = std::str::from_utf8(&out).map_err(|e| {
444-
CrucibleError::IoError(format!(
445-
"zfs returned invalid UTF-8 string: {out:?} \
446-
({e}), stderr: {err}"
447-
))
448-
})?;
433+
})?;
449434
out.trim().parse::<u64>().map_err(|e| {
450435
CrucibleError::IoError(format!(
451436
"zfs returned non-integer for recordsize: \
452-
{out:?} ({e}), stderr: {err}"
437+
{out:?} ({e}), stderr: {err}"
453438
))
454439
})?
455440
}
456441
}
457-
Err(e) if e.kind() == std::io::ErrorKind::NotFound => {
458-
// If the `zfs` executable isn't present, then we're
459-
// presumably on a non-ZFS filesystem and will use a default
460-
// recordsize, except on illumos (where `zfs` not being
461-
// present is a Problem).
462-
#[cfg(target_os = "illumos")]
463-
return Err(CrucibleError::IoError(format!(
464-
"could not find `zfs` executable: {e:?}"
465-
)));
466-
467-
#[cfg(not(target_os = "illumos"))]
468-
extent_inner_raw_v2::DUMMY_RECORDSIZE
469-
}
470442
Err(e) => {
471443
return Err(CrucibleError::IoError(format!(
472-
"could not call `zfs` executable: {e:?}"
444+
"could not call `zfs` executable: {e:?} {e}"
473445
)))
474446
}
475447
}

0 commit comments

Comments
 (0)