]> git.ipfire.org Git - thirdparty/linux.git/commitdiff
NFSv2/v3: Fix error handling in nfs_atomic_open_v23()
authorTrond Myklebust <trond.myklebust@hammerspace.com>
Tue, 28 Oct 2025 21:27:43 +0000 (17:27 -0400)
committerAnna Schumaker <anna.schumaker@oracle.com>
Mon, 10 Nov 2025 19:30:45 +0000 (14:30 -0500)
When nfs_do_create() returns an EEXIST error, it means that a regular
file could not be created. That could mean that a symlink needs to be
resolved. If that's the case, a lookup needs to be kicked off.

Reported-by: Stephen Abbene <sabbene87@gmail.com>
Link: https://bugzilla.kernel.org/show_bug.cgi?id=220710
Fixes: 7c6c5249f061 ("NFS: add atomic_open for NFSv3 to handle O_TRUNC correctly.")
Signed-off-by: Trond Myklebust <trond.myklebust@hammerspace.com>
Reviewed-by: NeilBrown <neil@brown.name>
Signed-off-by: Anna Schumaker <anna.schumaker@oracle.com>
fs/nfs/dir.c

index 46d9c65d50f83fc1dc73f3d7f5868b84132bb0fd..ea9f6ca8f30fa250425921b403d67d05fcf13b61 100644 (file)
@@ -2268,11 +2268,12 @@ int nfs_atomic_open_v23(struct inode *dir, struct dentry *dentry,
                return -ENAMETOOLONG;
 
        if (open_flags & O_CREAT) {
-               file->f_mode |= FMODE_CREATED;
                error = nfs_do_create(dir, dentry, mode, open_flags);
-               if (error)
+               if (!error) {
+                       file->f_mode |= FMODE_CREATED;
+                       return finish_open(file, dentry, NULL);
+               } else if (error != -EEXIST || open_flags & O_EXCL)
                        return error;
-               return finish_open(file, dentry, NULL);
        }
        if (d_in_lookup(dentry)) {
                /* The only flags nfs_lookup considers are