From 6e2b515c5c178ba2ae3206933024ad24f658f368 Mon Sep 17 00:00:00 2001 From: Andrea Righi Date: Thu, 20 Jun 2024 15:34:20 +0200 Subject: [PATCH] virtme-ng-init: overlayfs: fall back to mounting without xino option 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: https://github.com/arighi/virtme-ng/pull/124 Reported-by: Juerg Haefliger Signed-off-by: Andrea Righi --- src/main.rs | 10 +++++++++- src/utils.rs | 14 +++++++++++++- 2 files changed, 22 insertions(+), 2 deletions(-) diff --git a/src/main.rs b/src/main.rs index 83651e7..046ea19 100644 --- a/src/main.rs +++ b/src/main.rs @@ -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); + } } } } diff --git a/src/utils.rs b/src/utils.rs index 20b3e10..2de74c5 100644 --- a/src/utils.rs +++ b/src/utils.rs @@ -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"); @@ -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);