Skip to content

Commit 6689c86

Browse files
authored
Merge pull request #5358 from lifubang/fix-nr-inodes-focal
libct: retry with nr_inodes=2 to fix Focal mount errors
2 parents 89f46d6 + a5690a0 commit 6689c86

1 file changed

Lines changed: 8 additions & 10 deletions

File tree

libcontainer/rootfs_linux.go

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1331,16 +1331,14 @@ 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-
// 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))
1334+
err := mount("tmpfs", path, "tmpfs", unix.MS_RDONLY, label.FormatMountLabel("nr_blocks=1,nr_inodes=1", mountLabel))
1335+
if err != nil {
1336+
// On most kernels `nr_inodes=1` works fine. However, Ubuntu 20.04 (Focal) with
1337+
// the official 5.4 kernel carries a private patch in "mm/shmem.c" that rejects
1338+
// `nr_inodes<2`, so retry with `nr_inodes=2` here.
1339+
// For reference, search for "case Opt_nr_inodes" in:
1340+
// https://git.launchpad.net/~ubuntu-kernel/ubuntu/+source/linux/+git/focal/plain/mm/shmem.c?h=Ubuntu-5.4.0-216.236
1341+
err = mount("tmpfs", path, "tmpfs", unix.MS_RDONLY, label.FormatMountLabel("nr_blocks=1,nr_inodes=2", mountLabel))
13441342
}
13451343
return err
13461344
}

0 commit comments

Comments
 (0)