From: Benjamin Coddington <bcodding@redhat.com>
To: linux-nfs@vger.kernel.org
Subject: [PATCH v1 03/10] NFS: Add a struct to track readdir pagecache location
Date: Wed, 20 Jan 2021 11:59:47 -0500 [thread overview]
Message-ID: <e78ca3502aeaea97d85e5ea2beff775946cc7a3f.1611160121.git.bcodding@redhat.com> (raw)
In-Reply-To: <cover.1611160120.git.bcodding@redhat.com>
Directory entries in the NFS readdir pagecache are referenced by their
cookie value and offset. By defining a structure to group these values,
we'll simplify changes to validate pagecache pages in patches that follow.
Signed-off-by: Benjamin Coddington <bcodding@redhat.com>
---
fs/nfs/dir.c | 34 +++++++++++++++++-----------------
include/linux/nfs_fs.h | 6 ++++++
2 files changed, 23 insertions(+), 17 deletions(-)
diff --git a/fs/nfs/dir.c b/fs/nfs/dir.c
index ade73ca42a52..6626aff9f54d 100644
--- a/fs/nfs/dir.c
+++ b/fs/nfs/dir.c
@@ -154,10 +154,9 @@ struct nfs_readdir_descriptor {
struct file *file;
struct page *page;
struct dir_context *ctx;
- pgoff_t page_index;
u64 dir_cookie;
- u64 last_cookie;
u64 dup_cookie;
+ struct nfs_dir_page_cursor pgc;
loff_t current_index;
loff_t prev_index;
@@ -166,7 +165,6 @@ struct nfs_readdir_descriptor {
unsigned long timestamp;
unsigned long gencount;
unsigned long attr_gencount;
- unsigned int cache_entry_index;
signed char duped;
bool plus;
bool eof;
@@ -426,7 +424,7 @@ static int nfs_readdir_search_for_pos(struct nfs_cache_array *array,
index = (unsigned int)diff;
desc->dir_cookie = array->array[index].cookie;
- desc->cache_entry_index = index;
+ desc->pgc.entry_index = index;
return 0;
out_eof:
desc->eof = true;
@@ -494,7 +492,7 @@ static int nfs_readdir_search_for_cookie(struct nfs_cache_array *array,
else
desc->ctx->pos = new_pos;
desc->prev_index = new_pos;
- desc->cache_entry_index = i;
+ desc->pgc.entry_index = i;
return 0;
}
}
@@ -521,9 +519,9 @@ static int nfs_readdir_search_array(struct nfs_readdir_descriptor *desc)
status = nfs_readdir_search_for_cookie(array, desc);
if (status == -EAGAIN) {
- desc->last_cookie = array->last_cookie;
+ desc->pgc.index_cookie = array->last_cookie;
desc->current_index += array->size;
- desc->page_index++;
+ desc->pgc.page_index++;
}
kunmap_atomic(array);
return status;
@@ -927,8 +925,8 @@ static struct page *
nfs_readdir_page_get_cached(struct nfs_readdir_descriptor *desc)
{
return nfs_readdir_page_get_locked(desc->file->f_mapping,
- desc->page_index,
- desc->last_cookie);
+ desc->pgc.page_index,
+ desc->pgc.index_cookie);
}
/*
@@ -952,7 +950,7 @@ static int find_and_lock_cache_page(struct nfs_readdir_descriptor *desc)
nfs_readdir_page_unlock_and_put_cached(desc);
if (res == -EBADCOOKIE || res == -ENOTSYNC) {
invalidate_inode_pages2(desc->file->f_mapping);
- desc->page_index = 0;
+ desc->pgc.page_index = 0;
return -EAGAIN;
}
return res;
@@ -961,7 +959,7 @@ static int find_and_lock_cache_page(struct nfs_readdir_descriptor *desc)
}
res = nfs_readdir_search_array(desc);
if (res == 0) {
- nfsi->page_index = desc->page_index;
+ nfsi->page_index = desc->pgc.page_index;
return 0;
}
nfs_readdir_page_unlock_and_put_cached(desc);
@@ -991,10 +989,10 @@ static int readdir_search_pagecache(struct nfs_readdir_descriptor *desc)
return -EBADCOOKIE;
do {
- if (desc->page_index == 0) {
+ if (desc->pgc.page_index == 0) {
desc->current_index = 0;
desc->prev_index = 0;
- desc->last_cookie = 0;
+ desc->pgc.index_cookie = 0;
}
res = find_and_lock_cache_page(desc);
} while (res == -EAGAIN);
@@ -1012,7 +1010,7 @@ static void nfs_do_filldir(struct nfs_readdir_descriptor *desc)
unsigned int i = 0;
array = kmap(desc->page);
- for (i = desc->cache_entry_index; i < array->size; i++) {
+ for (i = desc->pgc.entry_index; i < array->size; i++) {
struct nfs_cache_array_entry *ent;
ent = &array->array[i];
@@ -1070,8 +1068,10 @@ static int uncached_readdir(struct nfs_readdir_descriptor *desc)
if (!arrays[0])
goto out;
- desc->page_index = 0;
- desc->last_cookie = desc->dir_cookie;
+ /* These values aren't referenced until we return, move/remove? */
+ desc->pgc.page_index = 0;
+ desc->pgc.index_cookie = desc->dir_cookie;
+
desc->duped = 0;
status = nfs_readdir_xdr_to_array(desc, desc->verf, verf, arrays, sz);
@@ -1154,7 +1154,7 @@ static int nfs_readdir(struct file *file, struct dir_context *ctx)
if (res == -ETOOSMALL && desc->plus) {
clear_bit(NFS_INO_ADVISE_RDPLUS, &NFS_I(inode)->flags);
nfs_zap_caches(inode);
- desc->page_index = 0;
+ desc->pgc.page_index = 0;
desc->plus = false;
desc->eof = false;
continue;
diff --git a/include/linux/nfs_fs.h b/include/linux/nfs_fs.h
index 681ed98e4ba8..557e54b7d555 100644
--- a/include/linux/nfs_fs.h
+++ b/include/linux/nfs_fs.h
@@ -91,6 +91,12 @@ struct nfs_open_context {
struct rcu_head rcu_head;
};
+struct nfs_dir_page_cursor {
+ __u64 index_cookie;
+ pgoff_t page_index;
+ unsigned int entry_index;
+};
+
struct nfs_open_dir_context {
struct list_head list;
unsigned long attr_gencount;
--
2.25.4
next prev parent reply other threads:[~2021-01-20 17:03 UTC|newest]
Thread overview: 17+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-01-20 16:59 [PATCH v1 00/10] NFS client readdir per-page validation Benjamin Coddington
2021-01-20 16:59 ` [PATCH v1 01/10] NFS: save the directory's change attribute on pagecache pages Benjamin Coddington
2021-01-20 16:59 ` [PATCH v1 02/10] NFSv4: Send GETATTR with READDIR Benjamin Coddington
2021-01-20 16:59 ` Benjamin Coddington [this message]
2021-01-20 16:59 ` [PATCH v1 04/10] NFS: Keep the readdir pagecache cursor updated Benjamin Coddington
2021-01-21 20:00 ` Trond Myklebust
2021-01-21 20:11 ` Trond Myklebust
2021-01-22 0:21 ` Benjamin Coddington
2021-01-20 16:59 ` [PATCH v1 05/10] NFS: readdir per-page cache validation Benjamin Coddington
2021-01-20 20:08 ` kernel test robot
2021-01-20 16:59 ` [PATCH v1 06/10] NFS: stash the readdir pagecache cursor on the open directory context Benjamin Coddington
2021-01-20 16:59 ` [PATCH v1 07/10] NFS: Support headless readdir pagecache pages Benjamin Coddington
2021-01-21 17:24 ` Anna Schumaker
2021-01-21 17:57 ` Benjamin Coddington
2021-01-20 16:59 ` [PATCH v1 08/10] NFS: Reset pagecache cursor on llseek Benjamin Coddington
2021-01-20 16:59 ` [PATCH v1 09/10] NFS: Remove nfs_readdir_dont_search_cache() Benjamin Coddington
2021-01-20 16:59 ` [PATCH v1 10/10] NFS: Revalidate the directory pagecache on every nfs_readdir() Benjamin Coddington
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=e78ca3502aeaea97d85e5ea2beff775946cc7a3f.1611160121.git.bcodding@redhat.com \
--to=bcodding@redhat.com \
--cc=linux-nfs@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox