NFS: Cache all entries in the readdirplus reply
authorTrond Myklebust <trond.myklebust@hammerspace.com>
Thu, 24 Feb 2022 16:48:35 +0000 (11:48 -0500)
committerTrond Myklebust <trond.myklebust@hammerspace.com>
Wed, 2 Mar 2022 13:43:39 +0000 (08:43 -0500)
Even if we're not able to cache all the entries in the readdir buffer,
let's ensure that we do prime the dcache.

Signed-off-by: Trond Myklebust <trond.myklebust@hammerspace.com>
fs/nfs/dir.c

index 033249a72e92c319243369ce26a0e407d1c2c3a9..7e12102b29e758e036a59b3acc58dce25a95562e 100644 (file)
@@ -789,6 +789,21 @@ out:
        dput(dentry);
 }
 
+static int nfs_readdir_entry_decode(struct nfs_readdir_descriptor *desc,
+                                   struct nfs_entry *entry,
+                                   struct xdr_stream *stream)
+{
+       int ret;
+
+       if (entry->fattr->label)
+               entry->fattr->label->len = NFS4_MAXLABELLEN;
+       ret = xdr_decode(desc, entry, stream);
+       if (ret || !desc->plus)
+               return ret;
+       nfs_prime_dcache(file_dentry(desc->file), entry, desc->dir_verifier);
+       return 0;
+}
+
 /* Perform conversion from xdr to cache array */
 static int nfs_readdir_page_filler(struct nfs_readdir_descriptor *desc,
                                   struct nfs_entry *entry,
@@ -811,17 +826,10 @@ static int nfs_readdir_page_filler(struct nfs_readdir_descriptor *desc,
        xdr_set_scratch_page(&stream, scratch);
 
        do {
-               if (entry->fattr->label)
-                       entry->fattr->label->len = NFS4_MAXLABELLEN;
-
-               status = xdr_decode(desc, entry, &stream);
+               status = nfs_readdir_entry_decode(desc, entry, &stream);
                if (status != 0)
                        break;
 
-               if (desc->plus)
-                       nfs_prime_dcache(file_dentry(desc->file), entry,
-                                       desc->dir_verifier);
-
                status = nfs_readdir_page_array_append(page, entry, &cookie);
                if (status != -ENOSPC)
                        continue;
@@ -849,15 +857,19 @@ static int nfs_readdir_page_filler(struct nfs_readdir_descriptor *desc,
 
        switch (status) {
        case -EBADCOOKIE:
-               if (entry->eof) {
-                       nfs_readdir_page_set_eof(page);
-                       status = 0;
-               }
-               break;
-       case -ENOSPC:
+               if (!entry->eof)
+                       break;
+               nfs_readdir_page_set_eof(page);
+               fallthrough;
        case -EAGAIN:
                status = 0;
                break;
+       case -ENOSPC:
+               status = 0;
+               if (!desc->plus)
+                       break;
+               while (!nfs_readdir_entry_decode(desc, entry, &stream))
+                       ;
        }
 
        if (page != *arrays)