NFS client: mkdir on existing, uncached dir returns EROFS instead of EEXIST under ro bind mount
Subsystems (3)
Hi,
on Linux 6.12.48 (Debian 13) and 7.1.6 (Debian 14), calling mkdir() on a directory that already exists on an NFSv4.2 mount, through a read-only bind mount, returns EROFS instead of EEXIST, as long as the directory has not been looked up (e.g. listed via readdir of its parent) by this client yet. Also reproducible on Debian 14 with a custom compiled 7.3.1 kernel.
This breaks Flatpak/bubblewrap, which creates mount points with mkdir() and treats EEXIST as success but EROFS as fatal. With the Flatpak tree on NFS, apps fail after each reboot with "bwrap: Can't mkdir parents for ...: Read-only file system" until the tree has been walked once. The issue only occurs on NFS mounts, local file systems work fine with Flatpak/bubblewrap.
To reproduce:
# vanilla Debian install (stock kernel or 7.3.1, same result)
# set it up (root) apt install nfs-kernel-server mkdir -p /mnt/nfstest /etc/exports.d /srv/nfstest echo '/srv/nfstest 127.0.0.1(rw,sync,no_subtree_check,no_root_squash)' > /etc/exports.d/nfstest.exports mount -t tmpfs -o size=16m tmpfs /srv/nfstest mkdir -p /srv/nfstest/reprotest1/sub exportfs -ra mount -t nfs4 -o vers=4.2 127.0.0.1:/srv/nfstest /mnt/nfstest
# test (as regular user)
# 1st invocation
unshare -rm sh -c 'mount --bind "$1" "$1" && mount -o remount,bind,ro "$1" && mkdir "$1/sub"' sh /mnt/nfstest/reprotest1 # → mkdir: cannot create directory ‘/mnt/nfstest/reprotest1/sub’: Read-only file system
# walk the file system ls /mnt/nfstest/reprotest1 # → sub
# 2nd invocation
unshare -rm sh -c 'mount --bind "$1" "$1" && mount -o remount,bind,ro "$1" && mkdir "$1/sub"' sh /mnt/nfstest/reprotest1 # → mkdir: cannot create directory ‘/mnt/nfstest/reprotest1/sub’: File exists
strace of the original failure (bwrap):
mkdirat(7, "app", 0700) = -1 EEXIST (File exists)
mkdirat(8, "share", 0700) = -1 EROFS (Read-only file system) (but "share" exists)
I believe this behaviour is not intended. Let me know if I should provide more info.
Note: I'm not subscribed, so please CC me.
Regards
Marco
Chuck Lever
maintainerQuoted 53 lines · Marco
Hi,
on Linux 6.12.48 (Debian 13) and 7.1.6 (Debian 14), calling
mkdir()on a directory that already exists on an NFSv4.2 mount, through a read-only bind mount, returns EROFS instead of EEXIST, as long as the directory has not been looked up (e.g. listed via readdir of its parent) by this client yet. Also reproducible on Debian 14 with a custom compiled 7.3.1 kernel.This breaks Flatpak/bubblewrap, which creates mount points with
mkdir()and treats EEXIST as success but EROFS as fatal. With the Flatpak tree on NFS, apps fail after each reboot with "bwrap: Can't mkdir parents for ...: Read-only file system" until the tree has been walked once. The issue only occurs on NFS mounts, local file systems work fine with Flatpak/bubblewrap.To reproduce:
# vanilla Debian install (stock kernel or 7.3.1, same result)# set it up (root) apt install nfs-kernel-server mkdir -p /mnt/nfstest /etc/exports.d /srv/nfstest echo '/srv/nfstest 127.0.0.1(rw,sync,no_subtree_check,no_root_squash)'Quoted 1 line
/etc/exports.d/nfstest.exportsmount -t tmpfs -o size=16m tmpfs
/srv/nfstest
mkdir -p/srv/nfstest/reprotest1/sub
exportfs -ra
mount -t nfs4 -o vers=4.2 127.0.0.1:/srv/nfstest/mnt/nfstest# test (as regular user)# 1st invocation
unshare -rm sh -c 'mount --bind "$1" "$1" && mount -o remount,bind,ro "$1" && mkdir "$1/sub"' sh/mnt/nfstest/reprotest1
# → mkdir: cannot create directory ‘/mnt/nfstest/reprotest1/sub’:
Read-only file system# walk the file system ls /mnt/nfstest/reprotest1 # → sub# 2nd invocation
unshare -rm sh -c 'mount --bind "$1" "$1" && mount -o remount,bind,ro "$1" && mkdir "$1/sub"' sh/mnt/nfstest/reprotest1
# → mkdir: cannot create directory ‘/mnt/nfstest/reprotest1/sub’: File existsstrace of the original failure (bwrap):
mkdirat(7, "app", 0700)= -1 EEXIST (File exists)
mkdirat(8, "share", 0700)= -1 EROFS (Read-only file system) (but "share" exists)
Quoted 7 lines
I believe this behaviour is not intended. Let me know if I should provide more info.
Note: I'm not subscribed, so please CC me.
Regards
Marco
Attn: NFS client maintainers
Signature · 1 line
Chuck Lever (Come to NFS bake-a-thon! https://nfsv4bat.org)