fn _mount()

in metalos/metalctl/src/mount.rs [132:191]


fn _mount(log: Logger, opts: Opts, fstypes: &[String], mounter: impl Mounter) -> Result<()> {
    let (data, mut flags) = parse_options(opts.options);
    let source = evaluate_device_spec(&opts.source)?;

    if opts.bind {
        flags.insert(MsFlags::MS_BIND);
        return mounter
            .mount(
                &source,
                opts.target.as_path(),
                None,
                flags,
                Some(data.join(",").as_str()),
            )
            .context("mount failed");
    }

    let fstype = opts.fstype;
    #[cfg(blkid)]
    let fstype = fstype.or_else(|| match blkid::probe_fstype(&source) {
        Ok(fstype) => Some(fstype),
        Err(e) => {
            slog::warn!(
                log,
                "blkid could not determine fstype, trying all available filesystems: {:?}",
                e
            );
            None
        }
    });
    match fstype {
        None => {
            for fstype in fstypes {
                match mounter.mount(
                    &source,
                    opts.target.as_path(),
                    Some(fstype),
                    flags,
                    Some(data.join(",").as_str()),
                ) {
                    Ok(..) => return Ok(()),
                    Err(..) => continue,
                }
            }
            bail!(
                "Filesystem type not provided. I tried many filesystem types I know about with no success: {:?}. Stopping.",
                fstypes,
            );
        }
        Some(fstype) => mounter
            .mount(
                &source,
                opts.target.as_path(),
                Some(&fstype),
                flags,
                Some(data.join(",").as_str()),
            )
            .context("mount failed"),
    }
}