]> git.proxmox.com Git - mirror_ubuntu-kernels.git/commitdiff
NFS: Fix up directory verifier races
authorTrond Myklebust <trondmy@gmail.com>
Wed, 5 Feb 2020 14:01:52 +0000 (09:01 -0500)
committerAnna Schumaker <Anna.Schumaker@Netapp.com>
Mon, 10 Feb 2020 15:38:48 +0000 (10:38 -0500)
In order to avoid having our dentry revalidation race with an update
of the directory on the server, we need to store the verifier before
the RPC calls to LOOKUP and READDIR.

Signed-off-by: Trond Myklebust <trond.myklebust@hammerspace.com>
Reviewed-by: Benjamin Coddington <bcodding@gmail.com>
Tested-by: Benjamin Coddington <bcodding@gmail.com>
Signed-off-by: Anna Schumaker <Anna.Schumaker@Netapp.com>
fs/nfs/dir.c

index 1320288ff9ec9c7d50d207908d77f3899c7def3b..b4e7558e42ab9c5fd6e417f37fb54d1d07473d3e 100644 (file)
@@ -155,6 +155,7 @@ typedef struct {
        loff_t          current_index;
        decode_dirent_t decode;
 
+       unsigned long   dir_verifier;
        unsigned long   timestamp;
        unsigned long   gencount;
        unsigned int    cache_entry_index;
@@ -353,6 +354,7 @@ int nfs_readdir_xdr_filler(struct page **pages, nfs_readdir_descriptor_t *desc,
  again:
        timestamp = jiffies;
        gencount = nfs_inc_attr_generation_counter();
+       desc->dir_verifier = nfs_save_change_attribute(inode);
        error = NFS_PROTO(inode)->readdir(file_dentry(file), cred, entry->cookie, pages,
                                          NFS_SERVER(inode)->dtsize, desc->plus);
        if (error < 0) {
@@ -455,13 +457,13 @@ void nfs_force_use_readdirplus(struct inode *dir)
 }
 
 static
-void nfs_prime_dcache(struct dentry *parent, struct nfs_entry *entry)
+void nfs_prime_dcache(struct dentry *parent, struct nfs_entry *entry,
+               unsigned long dir_verifier)
 {
        struct qstr filename = QSTR_INIT(entry->name, entry->len);
        DECLARE_WAIT_QUEUE_HEAD_ONSTACK(wq);
        struct dentry *dentry;
        struct dentry *alias;
-       struct inode *dir = d_inode(parent);
        struct inode *inode;
        int status;
 
@@ -500,7 +502,7 @@ again:
                if (nfs_same_file(dentry, entry)) {
                        if (!entry->fh->size)
                                goto out;
-                       nfs_set_verifier(dentry, nfs_save_change_attribute(dir));
+                       nfs_set_verifier(dentry, dir_verifier);
                        status = nfs_refresh_inode(d_inode(dentry), entry->fattr);
                        if (!status)
                                nfs_setsecurity(d_inode(dentry), entry->fattr, entry->label);
@@ -526,7 +528,7 @@ again:
                dput(dentry);
                dentry = alias;
        }
-       nfs_set_verifier(dentry, nfs_save_change_attribute(dir));
+       nfs_set_verifier(dentry, dir_verifier);
 out:
        dput(dentry);
 }
@@ -564,7 +566,8 @@ int nfs_readdir_page_filler(nfs_readdir_descriptor_t *desc, struct nfs_entry *en
                count++;
 
                if (desc->plus)
-                       nfs_prime_dcache(file_dentry(desc->file), entry);
+                       nfs_prime_dcache(file_dentry(desc->file), entry,
+                                       desc->dir_verifier);
 
                status = nfs_readdir_add_to_array(entry, page);
                if (status != 0)
@@ -1159,6 +1162,7 @@ nfs_lookup_revalidate_dentry(struct inode *dir, struct dentry *dentry,
        struct nfs_fh *fhandle;
        struct nfs_fattr *fattr;
        struct nfs4_label *label;
+       unsigned long dir_verifier;
        int ret;
 
        ret = -ENOMEM;
@@ -1168,6 +1172,7 @@ nfs_lookup_revalidate_dentry(struct inode *dir, struct dentry *dentry,
        if (fhandle == NULL || fattr == NULL || IS_ERR(label))
                goto out;
 
+       dir_verifier = nfs_save_change_attribute(dir);
        ret = NFS_PROTO(dir)->lookup(dir, dentry, fhandle, fattr, label);
        if (ret < 0) {
                switch (ret) {
@@ -1188,7 +1193,7 @@ nfs_lookup_revalidate_dentry(struct inode *dir, struct dentry *dentry,
                goto out;
 
        nfs_setsecurity(inode, fattr, label);
-       nfs_set_verifier(dentry, nfs_save_change_attribute(dir));
+       nfs_set_verifier(dentry, dir_verifier);
 
        /* set a readdirplus hint that we had a cache miss */
        nfs_force_use_readdirplus(dir);
@@ -1415,6 +1420,7 @@ struct dentry *nfs_lookup(struct inode *dir, struct dentry * dentry, unsigned in
        struct nfs_fh *fhandle = NULL;
        struct nfs_fattr *fattr = NULL;
        struct nfs4_label *label = NULL;
+       unsigned long dir_verifier;
        int error;
 
        dfprintk(VFS, "NFS: lookup(%pd2)\n", dentry);
@@ -1440,6 +1446,7 @@ struct dentry *nfs_lookup(struct inode *dir, struct dentry * dentry, unsigned in
        if (IS_ERR(label))
                goto out;
 
+       dir_verifier = nfs_save_change_attribute(dir);
        trace_nfs_lookup_enter(dir, dentry, flags);
        error = NFS_PROTO(dir)->lookup(dir, dentry, fhandle, fattr, label);
        if (error == -ENOENT)
@@ -1463,7 +1470,7 @@ no_entry:
                        goto out_label;
                dentry = res;
        }
-       nfs_set_verifier(dentry, nfs_save_change_attribute(dir));
+       nfs_set_verifier(dentry, dir_verifier);
 out_label:
        trace_nfs_lookup_exit(dir, dentry, flags, error);
        nfs4_label_free(label);