Skip to content

Commit

Permalink
virtme-ng-init: overlayfs: fall back to mounting without xino option
Browse files Browse the repository at this point in the history
Older kernels don't support the 'xino' overlayfs mount option so we end
up with no overlay mounts. Fall back to mounting without that option to
work around that. It's not pretty as we end up with errors like:

[ 0.380206] overlayfs: unrecognized mount option "xino=off" or missing value
[ 0.383246] overlayfs: unrecognized mount option "xino=off" or missing value

Apply to virtme-ng-init the same change applied by Juerg in virtme-init.

Link: arighi/virtme-ng#124
Reported-by: Juerg Haefliger <juergh@proton.me>
Signed-off-by: Andrea Righi <andrea.righi@canonical.com>
  • Loading branch information
Andrea Righi committed Jun 20, 2024
1 parent eeaf7c5 commit 6e2b515
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 2 deletions.
10 changes: 9 additions & 1 deletion src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -452,7 +452,15 @@ fn mount_virtme_overlays() {
utils::do_mkdir(dir);
utils::do_mkdir(upperdir);
utils::do_mkdir(workdir);
utils::do_mount(&key, &path, "overlay", 0, mnt_opts);
let result = utils::do_mount_check(&key, &path, "overlay", 0, mnt_opts);
if let Err(_) = result {
// Old kernels don't support xino=on|off, re-try without this option.
let mnt_opts = &format!(
"lowerdir={},upperdir={},workdir={}",
path, upperdir, workdir
);
utils::do_mount(&key, &path, "overlay", 0, mnt_opts);
}
}
}
}
Expand Down
14 changes: 13 additions & 1 deletion src/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,13 @@ pub fn do_symlink(src: &str, dst: &str) {
}
}

pub fn do_mount(source: &str, target: &str, fstype: &str, flags: usize, fsdata: &str) {
pub fn do_mount_check(
source: &str,
target: &str,
fstype: &str,
flags: usize,
fsdata: &str,
) -> Result<(), nix::Error> {
let source_cstr = CString::new(source).expect("CString::new failed");
let fstype_cstr = CString::new(fstype).expect("CString::new failed");
let fsdata_cstr = CString::new(fsdata).expect("CString::new failed");
Expand All @@ -124,6 +130,12 @@ pub fn do_mount(source: &str, target: &str, fstype: &str, flags: usize, fsdata:
MsFlags::from_bits_truncate(flags.try_into().unwrap()),
Some(fsdata_cstr.as_ref()),
);

result
}

pub fn do_mount(source: &str, target: &str, fstype: &str, flags: usize, fsdata: &str) {
let result = do_mount_check(source, target, fstype, flags, fsdata);
if let Err(err) = result {
if err != nix::errno::Errno::ENOENT {
log!("mount {} -> {}: {}", source, target, err);
Expand Down

0 comments on commit 6e2b515

Please sign in to comment.