Skip to content

Commit 89f46d6

Browse files
authored
Merge pull request #5353 from lifubang/fix-maskdir-nrinode-2
libct: Enforce nr_inodes=2 to fix Focal mount errors
2 parents a081198 + 79ac577 commit 89f46d6

1 file changed

Lines changed: 12 additions & 1 deletion

File tree

libcontainer/rootfs_linux.go

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1331,7 +1331,18 @@ func verifyDevNull(f *os.File) error {
13311331

13321332
// maskDir mounts a read-only tmpfs on top of the specified path.
13331333
func maskDir(path, mountLabel string) error {
1334-
return mount("tmpfs", path, "tmpfs", unix.MS_RDONLY, label.FormatMountLabel("nr_blocks=1,nr_inodes=1", mountLabel))
1334+
// On most kernels `nr_inodes=1` works fine. However, Ubuntu 20.04 (Focal) with
1335+
// the official 5.4 kernel carries a private patch in mm/shmem.c that rejects
1336+
// "nr_inodes<2", so let's keep `nr_inodes=2` here!
1337+
// For reference, search for "case Opt_nr_inodes" in:
1338+
// https://git.launchpad.net/~ubuntu-kernel/ubuntu/+source/linux/+git/focal/plain/mm/shmem.c?h=Ubuntu-5.4.0-216.236
1339+
err := mount("tmpfs", path, "tmpfs", unix.MS_RDONLY, label.FormatMountLabel("nr_blocks=1,nr_inodes=2", mountLabel))
1340+
// We don't know whether some kernels will fail with "nr_inodes=2",
1341+
// so let's fall back to mount a tmpfs without this option.
1342+
if errors.Is(err, unix.EINVAL) {
1343+
err = mount("tmpfs", path, "tmpfs", unix.MS_RDONLY, label.FormatMountLabel("nr_blocks=1", mountLabel))
1344+
}
1345+
return err
13351346
}
13361347

13371348
// maskPaths masks the top of the specified paths inside a container to avoid

0 commit comments

Comments
 (0)