From: David Howells <dhowells@redhat.com>
To: Christian Brauner <christian@brauner.io>,
Steve French <smfrench@gmail.com>,
Matthew Wilcox <willy@infradead.org>
Cc: dhowells@redhat.com, Jeff Layton <jlayton@kernel.org>,
Gao Xiang <hsiangkao@linux.alibaba.com>,
Dominique Martinet <asmadeus@codewreck.org>,
Marc Dionne <marc.dionne@auristor.com>,
Paulo Alcantara <pc@manguebit.com>,
Shyam Prasad N <sprasad@microsoft.com>,
Tom Talpey <tom@talpey.com>,
Eric Van Hensbergen <ericvh@kernel.org>,
Ilya Dryomov <idryomov@gmail.com>,
netfs@lists.linux.dev, linux-afs@lists.infradead.org,
linux-cifs@vger.kernel.org, linux-nfs@vger.kernel.org,
ceph-devel@vger.kernel.org, v9fs@lists.linux.dev,
linux-erofs@lists.ozlabs.org, linux-fsdevel@vger.kernel.org,
linux-mm@kvack.org, netdev@vger.kernel.org,
linux-kernel@vger.kernel.org
Subject: Re: [PATCH v3 23/33] afs: Use netfslib for directories
Date: Fri, 08 Nov 2024 17:23:10 +0000 [thread overview]
Message-ID: <1360667.1731086590@warthog.procyon.org.uk> (raw)
In-Reply-To: <20241106123559.724888-24-dhowells@redhat.com>
The attached fix needs folding in across this patch (23), patch 24, patch
29 and patch 31.
David
---
commit 9d4429bc7bb3f2b518d6decd1ca0e99e4d80d58e
Author: David Howells <dhowells@redhat.com>
Date: Thu Nov 7 23:46:48 2024 +0000
afs: Fix handling of signals during readdir
When a directory is being read, whether or not the dvnode->directory buffer
pointer is NULL is used to track whether we've checked fscache yet.
However, if a signal occurs after the buffer being allocated but whilst
we're doing the read, we may end up in an invalid state with ->directory
set but no data in the buffer.
In this state, afs_readdir(), afs_lookup() and afs_d_revalidate() see
corrupt directory contents leading to a variety of malfunctions.
Fix this by providing a specific flag to record whether or not we've
performed a read yet - and, incidentally, sampled fscache - rather than
using the value in ->directory instead.
Signed-off-by: David Howells <dhowells@redhat.com>
cc: Marc Dionne <marc.dionne@auristor.com>
cc: linux-afs@lists.infradead.org
diff --git a/fs/afs/dir.c b/fs/afs/dir.c
index 663a212964d8..b6a202fd9926 100644
--- a/fs/afs/dir.c
+++ b/fs/afs/dir.c
@@ -323,7 +323,7 @@ ssize_t afs_read_dir(struct afs_vnode *dvnode, struct file *file)
* haven't read it yet.
*/
if (test_bit(AFS_VNODE_DIR_VALID, &dvnode->flags) &&
- dvnode->directory) {
+ test_bit(AFS_VNODE_DIR_READ, &dvnode->flags)) {
ret = i_size;
goto valid;
}
@@ -336,7 +336,7 @@ ssize_t afs_read_dir(struct afs_vnode *dvnode, struct file *file)
afs_invalidate_cache(dvnode, 0);
if (!test_bit(AFS_VNODE_DIR_VALID, &dvnode->flags) ||
- !dvnode->directory) {
+ !test_bit(AFS_VNODE_DIR_READ, &dvnode->flags)) {
trace_afs_reload_dir(dvnode);
ret = afs_read_single(dvnode, file);
if (ret < 0)
@@ -345,6 +345,7 @@ ssize_t afs_read_dir(struct afs_vnode *dvnode, struct file *file)
// TODO: Trim excess pages
set_bit(AFS_VNODE_DIR_VALID, &dvnode->flags);
+ set_bit(AFS_VNODE_DIR_READ, &dvnode->flags);
} else {
ret = i_size;
}
diff --git a/fs/afs/dir_edit.c b/fs/afs/dir_edit.c
index f6f4b1adc8dc..60a549f1d9c5 100644
--- a/fs/afs/dir_edit.c
+++ b/fs/afs/dir_edit.c
@@ -644,4 +644,5 @@ void afs_mkdir_init_dir(struct afs_vnode *dvnode, struct afs_vnode *parent_dvnod
netfs_single_mark_inode_dirty(&dvnode->netfs.inode);
set_bit(AFS_VNODE_DIR_VALID, &dvnode->flags);
+ set_bit(AFS_VNODE_DIR_READ, &dvnode->flags);
}
diff --git a/fs/afs/inode.c b/fs/afs/inode.c
index f5618564b3fc..e9538e91f848 100644
--- a/fs/afs/inode.c
+++ b/fs/afs/inode.c
@@ -39,6 +39,7 @@ void afs_init_new_symlink(struct afs_vnode *vnode, struct afs_operation *op)
p = kmap_local_folio(folioq_folio(vnode->directory, 0), 0);
memcpy(p, op->create.symlink, size);
kunmap_local(p);
+ set_bit(AFS_VNODE_DIR_READ, &vnode->flags);
netfs_single_mark_inode_dirty(&vnode->netfs.inode);
}
@@ -60,12 +61,12 @@ const char *afs_get_link(struct dentry *dentry, struct inode *inode,
if (!dentry) {
/* RCU pathwalk. */
- if (!vnode->directory || !afs_check_validity(vnode))
+ if (!test_bit(AFS_VNODE_DIR_READ, &vnode->flags) || !afs_check_validity(vnode))
return ERR_PTR(-ECHILD);
goto good;
}
- if (!vnode->directory)
+ if (test_bit(AFS_VNODE_DIR_READ, &vnode->flags))
goto fetch;
ret = afs_validate(vnode, NULL);
@@ -73,13 +74,14 @@ const char *afs_get_link(struct dentry *dentry, struct inode *inode,
return ERR_PTR(ret);
if (!test_and_clear_bit(AFS_VNODE_ZAP_DATA, &vnode->flags) &&
- vnode->directory)
+ test_bit(AFS_VNODE_DIR_READ, &vnode->flags))
goto good;
fetch:
ret = afs_read_single(vnode, NULL);
if (ret < 0)
return ERR_PTR(ret);
+ set_bit(AFS_VNODE_DIR_READ, &vnode->flags);
good:
folio = folioq_folio(vnode->directory, 0);
diff --git a/fs/afs/internal.h b/fs/afs/internal.h
index a5da0dd8e9cc..90f407774a9a 100644
--- a/fs/afs/internal.h
+++ b/fs/afs/internal.h
@@ -705,6 +705,7 @@ struct afs_vnode {
#define AFS_VNODE_NEW_CONTENT 8 /* Set if file has new content (create/trunc-0) */
#define AFS_VNODE_SILLY_DELETED 9 /* Set if file has been silly-deleted */
#define AFS_VNODE_MODIFYING 10 /* Set if we're performing a modification op */
+#define AFS_VNODE_DIR_READ 11 /* Set if we've read a dir's contents */
struct folio_queue *directory; /* Directory contents */
struct list_head wb_keys; /* List of keys available for writeback */
prev parent reply other threads:[~2024-11-08 17:23 UTC|newest]
Thread overview: 36+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-11-06 12:35 [PATCH v3 00/33] netfs: Read performance improvements and "single-blob" support David Howells
2024-11-06 12:35 ` [PATCH v3 01/33] kheaders: Ignore silly-rename files David Howells
2024-11-06 12:35 ` [PATCH v3 02/33] netfs: Remove call to folio_index() David Howells
2024-11-06 12:35 ` [PATCH v3 03/33] netfs: Fix a few minor bugs in netfs_page_mkwrite() David Howells
2024-11-06 12:35 ` [PATCH v3 04/33] netfs: Remove unnecessary references to pages David Howells
2024-11-06 12:35 ` [PATCH v3 05/33] netfs: Use a folio_queue allocation and free functions David Howells
2024-11-06 12:35 ` [PATCH v3 06/33] netfs: Add a tracepoint to log the lifespan of folio_queue structs David Howells
2024-11-06 12:35 ` [PATCH v3 07/33] netfs: Abstract out a rolling folio buffer implementation David Howells
2024-11-06 12:35 ` [PATCH v3 08/33] netfs: Make netfs_advance_write() return size_t David Howells
2024-11-06 12:35 ` [PATCH v3 09/33] netfs: Split retry code out of fs/netfs/write_collect.c David Howells
2024-11-06 12:35 ` [PATCH v3 10/33] netfs: Drop the error arg from netfs_read_subreq_terminated() David Howells
2024-11-06 12:35 ` [PATCH v3 11/33] netfs: Drop the was_async " David Howells
2024-11-06 12:35 ` [PATCH v3 12/33] netfs: Don't use bh spinlock David Howells
2024-11-06 12:35 ` [PATCH v3 13/33] afs: Don't use mutex for I/O operation lock David Howells
2024-11-06 12:35 ` [PATCH v3 14/33] afs: Fix EEXIST error returned from afs_rmdir() to be ENOTEMPTY David Howells
2024-11-06 12:35 ` [PATCH v3 15/33] afs: Fix directory format encoding struct David Howells
2024-11-06 12:35 ` [PATCH v3 16/33] netfs: Remove some extraneous directory invalidations David Howells
2024-11-06 12:35 ` [PATCH v3 17/33] cachefiles: Add some subrequest tracepoints David Howells
2024-11-06 12:35 ` [PATCH v3 18/33] cachefiles: Add auxiliary data trace David Howells
2024-11-06 12:35 ` [PATCH v3 19/33] afs: Add more tracepoints to do with tracking validity David Howells
2024-11-06 12:35 ` [PATCH v3 20/33] netfs: Add functions to build/clean a buffer in a folio_queue David Howells
2024-11-06 12:35 ` [PATCH v3 21/33] netfs: Add support for caching single monolithic objects such as AFS dirs David Howells
2024-11-06 12:35 ` [PATCH v3 22/33] afs: Make afs_init_request() get a key if not given a file David Howells
2024-11-06 12:35 ` [PATCH v3 23/33] afs: Use netfslib for directories David Howells
2024-11-06 12:35 ` [PATCH v3 24/33] afs: Use netfslib for symlinks, allowing them to be cached David Howells
2024-11-06 12:35 ` [PATCH v3 25/33] afs: Eliminate afs_read David Howells
2024-11-06 12:35 ` [PATCH v3 26/33] afs: Fix cleanup of immediately failed async calls David Howells
2024-11-06 12:35 ` [PATCH v3 27/33] afs: Make {Y,}FS.FetchData an asynchronous operation David Howells
2024-11-06 12:35 ` [PATCH v3 28/33] netfs: Change the read result collector to only use one work item David Howells
2024-11-06 12:35 ` [PATCH v3 29/33] afs: Make afs_mkdir() locally initialise a new directory's content David Howells
2024-11-06 12:35 ` [PATCH v3 30/33] afs: Use the contained hashtable to search a directory David Howells
2024-11-06 12:35 ` [PATCH v3 31/33] afs: Locally initialise the contents of a new symlink on creation David Howells
2024-11-06 12:35 ` [PATCH v3 32/33] afs: Add a tracepoint for afs_read_receive() David Howells
2024-11-06 12:35 ` [PATCH v3 33/33] netfs: Report on NULL folioq in netfs_writeback_unlock_folios() David Howells
2024-11-08 17:03 ` [PATCH v3 28/33] netfs: Change the read result collector to only use one work item David Howells
2024-11-08 17:23 ` David Howells [this message]
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=1360667.1731086590@warthog.procyon.org.uk \
--to=dhowells@redhat.com \
--cc=asmadeus@codewreck.org \
--cc=ceph-devel@vger.kernel.org \
--cc=christian@brauner.io \
--cc=ericvh@kernel.org \
--cc=hsiangkao@linux.alibaba.com \
--cc=idryomov@gmail.com \
--cc=jlayton@kernel.org \
--cc=linux-afs@lists.infradead.org \
--cc=linux-cifs@vger.kernel.org \
--cc=linux-erofs@lists.ozlabs.org \
--cc=linux-fsdevel@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=linux-nfs@vger.kernel.org \
--cc=marc.dionne@auristor.com \
--cc=netdev@vger.kernel.org \
--cc=netfs@lists.linux.dev \
--cc=pc@manguebit.com \
--cc=smfrench@gmail.com \
--cc=sprasad@microsoft.com \
--cc=tom@talpey.com \
--cc=v9fs@lists.linux.dev \
--cc=willy@infradead.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