summaryrefslogtreecommitdiff
path: root/fs/gfs2/dentry.c
diff options
context:
space:
mode:
authorAbhi Das <adas@redhat.com>2023-11-10 13:10:08 +0100
committerAndreas Gruenbacher <agruenba@redhat.com>2023-12-18 14:24:33 +0100
commitdd00aaeb343255a8a30de671bd27bde79a47c8e5 (patch)
tree521dfaa2891b730c7d8260905c2bde3579102fd5 /fs/gfs2/dentry.c
parentf9f229c1f75df2f1fe63b16615d184da4e90bb10 (diff)
gfs2: Use GL_NOBLOCK flag for non-blocking lookups
Add the GL_NOBLOCK flag to the locking requests in gfs2_permission() and gfs2_drevalidate() when called with the MAY_NOT_BLOCK flag and LOOKUP_RCU flag, respectively. This will cause the locking requests to be handled without sleeping if possible. We bail out with -ECHILD if we can't grant the glock immediately. Make sure not to dget() + dput() the parent dentry in gfs2_drevalidate() in LOOKUP_RCU mode; dput() is a sleeping operation. Signed-off-by: Abhi Das <adas@redhat.com> Signed-off-by: Andreas Gruenbacher <agruenba@redhat.com>
Diffstat (limited to 'fs/gfs2/dentry.c')
-rw-r--r--fs/gfs2/dentry.c23
1 files changed, 14 insertions, 9 deletions
diff --git a/fs/gfs2/dentry.c b/fs/gfs2/dentry.c
index 2e215e8c3c88..177f1f41f225 100644
--- a/fs/gfs2/dentry.c
+++ b/fs/gfs2/dentry.c
@@ -32,21 +32,25 @@
static int gfs2_drevalidate(struct dentry *dentry, unsigned int flags)
{
- struct dentry *parent;
+ struct dentry *parent = NULL;
struct gfs2_sbd *sdp;
struct gfs2_inode *dip;
- struct inode *inode;
+ struct inode *dinode, *inode;
struct gfs2_holder d_gh;
struct gfs2_inode *ip = NULL;
int error, valid = 0;
int had_lock = 0;
- if (flags & LOOKUP_RCU)
- return -ECHILD;
-
- parent = dget_parent(dentry);
- sdp = GFS2_SB(d_inode(parent));
- dip = GFS2_I(d_inode(parent));
+ if (flags & LOOKUP_RCU) {
+ dinode = d_inode_rcu(READ_ONCE(dentry->d_parent));
+ if (!dinode)
+ return -ECHILD;
+ } else {
+ parent = dget_parent(dentry);
+ dinode = d_inode(parent);
+ }
+ sdp = GFS2_SB(dinode);
+ dip = GFS2_I(dinode);
inode = d_inode(dentry);
if (inode) {
@@ -62,7 +66,8 @@ static int gfs2_drevalidate(struct dentry *dentry, unsigned int flags)
had_lock = (gfs2_glock_is_locked_by_me(dip->i_gl) != NULL);
if (!had_lock) {
- error = gfs2_glock_nq_init(dip->i_gl, LM_ST_SHARED, 0, &d_gh);
+ error = gfs2_glock_nq_init(dip->i_gl, LM_ST_SHARED,
+ flags & LOOKUP_RCU ? GL_NOBLOCK : 0, &d_gh);
if (error)
goto out;
}