Commit df91b9df authored by Oleg Nesterov's avatar Oleg Nesterov Committed by David Howells

afs: use read_seqbegin() in afs_check_validity() and afs_getattr()

David Howells says:

 (3) afs_check_validity().
 (4) afs_getattr().

     These are both pretty short, so your solution is probably good for them.
     That said, afs_vnode_commit_status() can spend a long time under the
     write lock - and pretty much every file RPC op returns a status update.

Change these functions to use read_seqbegin(). This simplifies the code
and doesn't change the current behaviour, the "seq" counter is always even
so read_seqbegin_or_lock() can never take the lock.
Signed-off-by: default avatarOleg Nesterov <oleg@redhat.com>
Signed-off-by: default avatarDavid Howells <dhowells@redhat.com>
cc: Marc Dionne <marc.dionne@auristor.com>
cc: linux-afs@lists.infradead.org
Link: https://lore.kernel.org/r/20231130115617.GA21584@redhat.com/
parent 1702e065
...@@ -629,10 +629,10 @@ bool afs_check_validity(struct afs_vnode *vnode) ...@@ -629,10 +629,10 @@ bool afs_check_validity(struct afs_vnode *vnode)
enum afs_cb_break_reason need_clear = afs_cb_break_no_break; enum afs_cb_break_reason need_clear = afs_cb_break_no_break;
time64_t now = ktime_get_real_seconds(); time64_t now = ktime_get_real_seconds();
unsigned int cb_break; unsigned int cb_break;
int seq = 0; int seq;
do { do {
read_seqbegin_or_lock(&vnode->cb_lock, &seq); seq = read_seqbegin(&vnode->cb_lock);
cb_break = vnode->cb_break; cb_break = vnode->cb_break;
if (test_bit(AFS_VNODE_CB_PROMISED, &vnode->flags)) { if (test_bit(AFS_VNODE_CB_PROMISED, &vnode->flags)) {
...@@ -650,9 +650,7 @@ bool afs_check_validity(struct afs_vnode *vnode) ...@@ -650,9 +650,7 @@ bool afs_check_validity(struct afs_vnode *vnode)
need_clear = afs_cb_break_no_promise; need_clear = afs_cb_break_no_promise;
} }
} while (need_seqretry(&vnode->cb_lock, seq)); } while (read_seqretry(&vnode->cb_lock, seq));
done_seqretry(&vnode->cb_lock, seq);
if (need_clear == afs_cb_break_no_break) if (need_clear == afs_cb_break_no_break)
return true; return true;
...@@ -755,7 +753,7 @@ int afs_getattr(struct mnt_idmap *idmap, const struct path *path, ...@@ -755,7 +753,7 @@ int afs_getattr(struct mnt_idmap *idmap, const struct path *path,
struct inode *inode = d_inode(path->dentry); struct inode *inode = d_inode(path->dentry);
struct afs_vnode *vnode = AFS_FS_I(inode); struct afs_vnode *vnode = AFS_FS_I(inode);
struct key *key; struct key *key;
int ret, seq = 0; int ret, seq;
_enter("{ ino=%lu v=%u }", inode->i_ino, inode->i_generation); _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, ...@@ -772,7 +770,7 @@ int afs_getattr(struct mnt_idmap *idmap, const struct path *path,
} }
do { do {
read_seqbegin_or_lock(&vnode->cb_lock, &seq); seq = read_seqbegin(&vnode->cb_lock);
generic_fillattr(&nop_mnt_idmap, request_mask, inode, stat); generic_fillattr(&nop_mnt_idmap, request_mask, inode, stat);
if (test_bit(AFS_VNODE_SILLY_DELETED, &vnode->flags) && if (test_bit(AFS_VNODE_SILLY_DELETED, &vnode->flags) &&
stat->nlink > 0) stat->nlink > 0)
...@@ -784,9 +782,8 @@ int afs_getattr(struct mnt_idmap *idmap, const struct path *path, ...@@ -784,9 +782,8 @@ int afs_getattr(struct mnt_idmap *idmap, const struct path *path,
*/ */
if (S_ISDIR(inode->i_mode)) if (S_ISDIR(inode->i_mode))
stat->size = vnode->netfs.remote_i_size; 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; return 0;
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment