]> git.karo-electronics.de Git - linux-beck.git/commitdiff
nfsd4: fix delegation-unlink/rename race
authorJ. Bruce Fields <bfields@redhat.com>
Fri, 24 Jan 2014 23:04:40 +0000 (18:04 -0500)
committerJ. Bruce Fields <bfields@redhat.com>
Mon, 27 Jan 2014 18:59:16 +0000 (13:59 -0500)
If a file is unlinked or renamed between the time when we do the local
open and the time when we get the delegation, then we will return to the
client indicating that it holds a delegation even though the file no
longer exists under the name it was open under.

But a client performing an open-by-name, when it is returned a
delegation, must be able to assume that the file is still linked at the
name it was opened under.

So, hold the parent i_mutex for longer to prevent concurrent renames or
unlinks.

Signed-off-by: J. Bruce Fields <bfields@redhat.com>
fs/nfsd/nfs4proc.c
fs/nfsd/vfs.c

index 844813a7e12a61eacaf6768147a35d16823d2b42..ef76ba6323871d9b86764d78046ea98a512d7a33 100644 (file)
@@ -279,11 +279,15 @@ do_open_lookup(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate, stru
                if (open->op_createmode == NFS4_CREATE_EXCLUSIVE && status == 0)
                        open->op_bmval[1] = (FATTR4_WORD1_TIME_ACCESS |
                                                        FATTR4_WORD1_TIME_MODIFY);
-       } else {
+       } else
+               /*
+                * Note this may exit with the parent still locked.
+                * We will hold the lock until nfsd4_open's final
+                * lookup, to prevent renames or unlinks until we've had
+                * a chance to an acquire a delegation if appropriate.
+                */
                status = nfsd_lookup(rqstp, current_fh,
                                     open->op_fname.data, open->op_fname.len, *resfh);
-               fh_unlock(current_fh);
-       }
        if (status)
                goto out;
        status = nfsd_check_obj_isreg(*resfh);
index e85b463fac4a94b2ef7e9e9b0b4321e120cabbb3..a41302a00650ea274dc3605afefa4779baa9aa88 100644 (file)
@@ -207,7 +207,12 @@ nfsd_lookup_dentry(struct svc_rqst *rqstp, struct svc_fh *fhp,
                                goto out_nfserr;
                }
        } else {
-               fh_lock(fhp);
+               /*
+                * In the nfsd4_open() case, this may be held across
+                * subsequent open and delegation acquisition which may
+                * need to take the child's i_mutex:
+                */
+               fh_lock_nested(fhp, I_MUTEX_PARENT);
                dentry = lookup_one_len(name, dparent, len);
                host_err = PTR_ERR(dentry);
                if (IS_ERR(dentry))