From: Oleg Nesterov <oleg@redhat.com>
To: David Howells <dhowells@redhat.com>,
Marc Dionne <marc.dionne@auristor.com>
Cc: Chuck Lever <chuck.lever@oracle.com>,
linux-afs@lists.infradead.org, linux-kernel@vger.kernel.org
Subject: [PATCH] fs/afs: use read_seqbegin() rather than read_seqbegin_or_lock()
Date: Fri, 27 Oct 2023 12:12:05 +0200 [thread overview]
Message-ID: <20231027101205.GA31430@redhat.com> (raw)
read_seqbegin_or_lock() makes no sense unless you make "seq" odd
after the lockless access failed. See thread_group_cputime() as
an example, note that it does nextseq = 1 for the 2nd round.
So this code can use read_seqbegin() without changing the current
behaviour.
Signed-off-by: Oleg Nesterov <oleg@redhat.com>
---
fs/afs/callback.c | 7 +++----
fs/afs/inode.c | 15 ++++++---------
fs/afs/server.c | 17 +++++++----------
3 files changed, 16 insertions(+), 23 deletions(-)
diff --git a/fs/afs/callback.c b/fs/afs/callback.c
index a484fa642808..b33d8a4901f8 100644
--- a/fs/afs/callback.c
+++ b/fs/afs/callback.c
@@ -110,14 +110,14 @@ static struct afs_volume *afs_lookup_volume_rcu(struct afs_cell *cell,
{
struct afs_volume *volume = NULL;
struct rb_node *p;
- int seq = 0;
+ int seq;
do {
/* Unfortunately, rbtree walking doesn't give reliable results
* under just the RCU read lock, so we have to check for
* changes.
*/
- read_seqbegin_or_lock(&cell->volume_lock, &seq);
+ seq = read_seqbegin(&cell->volume_lock);
p = rcu_dereference_raw(cell->volumes.rb_node);
while (p) {
@@ -132,9 +132,8 @@ static struct afs_volume *afs_lookup_volume_rcu(struct afs_cell *cell,
volume = NULL;
}
- } while (need_seqretry(&cell->volume_lock, seq));
+ } while (read_seqretry(&cell->volume_lock, seq));
- done_seqretry(&cell->volume_lock, seq);
return volume;
}
diff --git a/fs/afs/inode.c b/fs/afs/inode.c
index 1c794a1896aa..88003fefff71 100644
--- a/fs/afs/inode.c
+++ b/fs/afs/inode.c
@@ -629,10 +629,10 @@ bool afs_check_validity(struct afs_vnode *vnode)
enum afs_cb_break_reason need_clear = afs_cb_break_no_break;
time64_t now = ktime_get_real_seconds();
unsigned int cb_break;
- int seq = 0;
+ int seq;
do {
- read_seqbegin_or_lock(&vnode->cb_lock, &seq);
+ seq = read_seqbegin(&vnode->cb_lock);
cb_break = vnode->cb_break;
if (test_bit(AFS_VNODE_CB_PROMISED, &vnode->flags)) {
@@ -650,9 +650,7 @@ bool afs_check_validity(struct afs_vnode *vnode)
need_clear = afs_cb_break_no_promise;
}
- } while (need_seqretry(&vnode->cb_lock, seq));
-
- done_seqretry(&vnode->cb_lock, seq);
+ } while (read_seqretry(&vnode->cb_lock, seq));
if (need_clear == afs_cb_break_no_break)
return true;
@@ -755,7 +753,7 @@ int afs_getattr(struct mnt_idmap *idmap, const struct path *path,
struct inode *inode = d_inode(path->dentry);
struct afs_vnode *vnode = AFS_FS_I(inode);
struct key *key;
- int ret, seq = 0;
+ int ret, seq;
_enter("{ ino=%lu v=%u }", inode->i_ino, inode->i_generation);
@@ -772,7 +770,7 @@ int afs_getattr(struct mnt_idmap *idmap, const struct path *path,
}
do {
- read_seqbegin_or_lock(&vnode->cb_lock, &seq);
+ seq = read_seqbegin(&vnode->cb_lock);
generic_fillattr(&nop_mnt_idmap, request_mask, inode, stat);
if (test_bit(AFS_VNODE_SILLY_DELETED, &vnode->flags) &&
stat->nlink > 0)
@@ -784,9 +782,8 @@ int afs_getattr(struct mnt_idmap *idmap, const struct path *path,
*/
if (S_ISDIR(inode->i_mode))
stat->size = vnode->netfs.remote_i_size;
- } while (need_seqretry(&vnode->cb_lock, seq));
+ } while (read_seqretry(&vnode->cb_lock, seq));
- done_seqretry(&vnode->cb_lock, seq);
return 0;
}
diff --git a/fs/afs/server.c b/fs/afs/server.c
index b5237206eac3..01a26c0e0d28 100644
--- a/fs/afs/server.c
+++ b/fs/afs/server.c
@@ -27,7 +27,7 @@ struct afs_server *afs_find_server(struct afs_net *net,
const struct afs_addr_list *alist;
struct afs_server *server = NULL;
unsigned int i;
- int seq = 0, diff;
+ int seq, diff;
rcu_read_lock();
@@ -35,7 +35,8 @@ struct afs_server *afs_find_server(struct afs_net *net,
if (server)
afs_unuse_server_notime(net, server, afs_server_trace_put_find_rsq);
server = NULL;
- read_seqbegin_or_lock(&net->fs_addr_lock, &seq);
+
+ seq = read_seqbegin(&net->fs_addr_lock);
if (srx->transport.family == AF_INET6) {
const struct sockaddr_in6 *a = &srx->transport.sin6, *b;
@@ -75,9 +76,7 @@ struct afs_server *afs_find_server(struct afs_net *net,
found:
server = afs_maybe_use_server(server, afs_server_trace_get_by_addr);
- } while (need_seqretry(&net->fs_addr_lock, seq));
-
- done_seqretry(&net->fs_addr_lock, seq);
+ } while (read_seqretry(&net->fs_addr_lock, seq));
rcu_read_unlock();
return server;
@@ -90,7 +89,7 @@ struct afs_server *afs_find_server_by_uuid(struct afs_net *net, const uuid_t *uu
{
struct afs_server *server = NULL;
struct rb_node *p;
- int diff, seq = 0;
+ int diff, seq;
_enter("%pU", uuid);
@@ -103,7 +102,7 @@ struct afs_server *afs_find_server_by_uuid(struct afs_net *net, const uuid_t *uu
afs_unuse_server(net, server, afs_server_trace_put_uuid_rsq);
server = NULL;
- read_seqbegin_or_lock(&net->fs_lock, &seq);
+ seq = read_seqbegin(&net->fs_lock);
p = net->fs_servers.rb_node;
while (p) {
@@ -121,9 +120,7 @@ struct afs_server *afs_find_server_by_uuid(struct afs_net *net, const uuid_t *uu
server = NULL;
}
- } while (need_seqretry(&net->fs_lock, seq));
-
- done_seqretry(&net->fs_lock, seq);
+ } while (read_seqretry(&net->fs_lock, seq));
_leave(" = %p", server);
return server;
--
2.25.1.362.g51ebf55
reply other threads:[~2023-10-27 10:14 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
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=20231027101205.GA31430@redhat.com \
--to=oleg@redhat.com \
--cc=chuck.lever@oracle.com \
--cc=dhowells@redhat.com \
--cc=linux-afs@lists.infradead.org \
--cc=linux-kernel@vger.kernel.org \
--cc=marc.dionne@auristor.com \
/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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.