Skip to content

mnt: handle EROFS from mkdir/open on read-only mounts#260

Merged
robertswiecki merged 1 commit intogoogle:masterfrom
nemmyam:fix-erofs-mkdir-readonly-mounts
Apr 2, 2026
Merged

mnt: handle EROFS from mkdir/open on read-only mounts#260
robertswiecki merged 1 commit intogoogle:masterfrom
nemmyam:fix-erofs-mkdir-readonly-mounts

Conversation

@nemmyam
Copy link
Copy Markdown
Contributor

@nemmyam nemmyam commented Mar 20, 2026

Problem

When using --chroot on a read-only NFS export, nsjail aborts during mount target creation. Directories like /dev and /tmp already exist in the chroot image, but mkdir() returns EROFS instead of EEXIST.

On NFSv3/v4 with a cold dentry cache, the NFS client's exclusive-create optimization (nfs_is_exclusive_create in fs/nfs/dir.c) skips the on-wire LOOKUP, leaving a negative dentry. The VFS then hits the deferred mnt_want_write() error before discovering the entry already exists.

nsjail only tolerates EEXIST after mkdir/open(O_CREAT), so EROFS is treated as fatal (exit 255).

Fix

On EROFS, fall back to stat()/fstatat() and proceed if the entry exists with the expected type (S_ISDIR/S_ISREG). All 7 mkdir/mkdirat/open sites patched across mnt.cc, mnt_legacy.cc, mnt_newapi.cc, and util.cc.

mkdir() can return EROFS instead of EEXIST for existing entries on
read-only mounts (e.g. NFS). Fall back to stat()/fstatat() on EROFS
and proceed if the entry exists with the expected type.
@robertswiecki robertswiecki force-pushed the master branch 3 times, most recently from 3581327 to 033adf6 Compare March 30, 2026 07:00
@nemmyam
Copy link
Copy Markdown
Contributor Author

nemmyam commented Mar 31, 2026

Hi @robertswiecki, just wanted to check if you've had a chance to look at this. Happy to adjust the approach if you'd prefer something different. We're hitting this in production with read-only NFS mounts and the EROFS handling has been solid on our side. Let me know if there's anything I can do to make this easier to review.

@robertswiecki
Copy link
Copy Markdown
Collaborator

Thank you!

@robertswiecki robertswiecki merged commit f1a9dc6 into google:master Apr 2, 2026
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants