Skip to content

Commit 58c3ab7

Browse files
committed
rootfs: improve error messages for bind-mount vfs flag setting
While debugging an issue involving failing mounts, I discovered that just returning the plain mount error message when we are in the fallback code for handling locked mounts leads to unnecessary confusion. It also doesn't help that podman currently forcefully sets "rw" on mounts, which means that rootless containers are likely to hit the locked mounts issue fairly often. So we should improve our error messages to explain why the mount is failing in the locked flags case. Fixes: 7c71a22 ("rootfs: remove --no-mount-fallback and finally fix MS_REMOUNT") Signed-off-by: Aleksa Sarai <[email protected]>
1 parent 30302a2 commit 58c3ab7

File tree

1 file changed

+13
-5
lines changed

1 file changed

+13
-5
lines changed

libcontainer/rootfs_linux.go

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -666,11 +666,17 @@ func mountToRootfs(c *mountConfig, m mountEntry) error {
666666
return err
667667
}
668668
srcFlags := statfsToMountFlags(*st)
669+
670+
logrus.Debugf(
671+
"working around failure to set vfs flags on bind-mount %s: srcFlags=%s flagsSet=%s flagsClr=%s: %v",
672+
m.Destination, stringifyMountFlags(srcFlags),
673+
stringifyMountFlags(m.Flags), stringifyMountFlags(m.ClearedFlags), mountErr)
674+
669675
// If the user explicitly request one of the locked flags *not*
670676
// be set, we need to return an error to avoid producing mounts
671677
// that don't match the user's request.
672-
if srcFlags&m.ClearedFlags&mntLockFlags != 0 {
673-
return mountErr
678+
if cannotClearFlags := srcFlags & m.ClearedFlags & mntLockFlags; cannotClearFlags != 0 {
679+
return fmt.Errorf("cannot clear locked flags %s: %w", stringifyMountFlags(cannotClearFlags), mountErr)
674680
}
675681

676682
// If an MS_*ATIME flag was requested, it must match the
@@ -691,17 +697,19 @@ func mountToRootfs(c *mountConfig, m mountEntry) error {
691697
// MS_STRICTATIME mounts even if the user requested MS_RELATIME
692698
// or MS_NOATIME.
693699
if m.Flags&mntAtimeFlags != 0 && m.Flags&mntAtimeFlags != srcFlags&mntAtimeFlags {
694-
return mountErr
700+
return fmt.Errorf("cannot change locked atime flags %s: %w", stringifyMountFlags(srcFlags&mntAtimeFlags), mountErr)
695701
}
696702

697703
// Retry the mount with the existing lockable mount flags
698704
// applied.
699705
flags |= srcFlags & mntLockFlags
700706
mountErr = mountViaFds("", nil, m.Destination, dstFd, "", uintptr(flags), "")
701-
logrus.Debugf("remount retry: srcFlags=0x%x flagsSet=0x%x flagsClr=0x%x: %v", srcFlags, m.Flags, m.ClearedFlags, mountErr)
707+
if mountErr != nil {
708+
mountErr = fmt.Errorf("remount with locked flags %s re-applied: %w", stringifyMountFlags(srcFlags&mntLockFlags), mountErr)
709+
}
702710
return mountErr
703711
}); err != nil {
704-
return err
712+
return fmt.Errorf("failed to set user-requested vfs flags on bind-mount: %w", err)
705713
}
706714
}
707715

0 commit comments

Comments
 (0)