From b678b1f14c5a25b095d3b4b0f24407e6b7a86e48 Mon Sep 17 00:00:00 2001 From: lifubang Date: Mon, 29 Jun 2026 11:08:08 +0000 Subject: [PATCH] libct: add a fallback for nr_inodes=2 We don't know whether some kernels will fail with "nr_inodes=2", so let's fall back to mount a tmpfs without "nr_inodes". Signed-off-by: lifubang (cherry picked from commit 79ac57770f9f156d6851fa7f27857cde591d23b4) Signed-off-by: lifubang --- libcontainer/rootfs_linux.go | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/libcontainer/rootfs_linux.go b/libcontainer/rootfs_linux.go index 964332d46..fba22495d 100644 --- a/libcontainer/rootfs_linux.go +++ b/libcontainer/rootfs_linux.go @@ -1328,7 +1328,13 @@ func maskDir(path, mountLabel string) error { // "nr_inodes<2", so let's keep `nr_inodes=2` here! // For reference, search for "case Opt_nr_inodes" in: // https://git.launchpad.net/~ubuntu-kernel/ubuntu/+source/linux/+git/focal/plain/mm/shmem.c?h=Ubuntu-5.4.0-216.236 - return mount("tmpfs", path, "tmpfs", unix.MS_RDONLY, label.FormatMountLabel("nr_blocks=1,nr_inodes=2", mountLabel)) + err := mount("tmpfs", path, "tmpfs", unix.MS_RDONLY, label.FormatMountLabel("nr_blocks=1,nr_inodes=2", mountLabel)) + // We don't know whether some kernels will fail with "nr_inodes=2", + // so let's fall back to mount a tmpfs without this option. + if errors.Is(err, unix.EINVAL) { + err = mount("tmpfs", path, "tmpfs", unix.MS_RDONLY, label.FormatMountLabel("nr_blocks=1", mountLabel)) + } + return err } // maskPaths masks the top of the specified paths inside a container to avoid