Commit 8c5ca117 authored by Bob Peterson's avatar Bob Peterson Committed by Andreas Gruenbacher

gfs2: untangle the logic in gfs2_drevalidate

Before this patch, function gfs2_drevalidate was a horrific tangle of
unreadable labels, cases and goto statements. This patch tries to
simplify the logic and make it more readable.
Signed-off-by: default avatarBob Peterson <rpeterso@redhat.com>
Signed-off-by: default avatarAndreas Gruenbacher <agruenba@redhat.com>
parent 0a6a4abc
...@@ -38,7 +38,7 @@ static int gfs2_drevalidate(struct dentry *dentry, unsigned int flags) ...@@ -38,7 +38,7 @@ static int gfs2_drevalidate(struct dentry *dentry, unsigned int flags)
struct inode *inode; struct inode *inode;
struct gfs2_holder d_gh; struct gfs2_holder d_gh;
struct gfs2_inode *ip = NULL; struct gfs2_inode *ip = NULL;
int error; int error, valid = 0;
int had_lock = 0; int had_lock = 0;
if (flags & LOOKUP_RCU) if (flags & LOOKUP_RCU)
...@@ -51,53 +51,30 @@ static int gfs2_drevalidate(struct dentry *dentry, unsigned int flags) ...@@ -51,53 +51,30 @@ static int gfs2_drevalidate(struct dentry *dentry, unsigned int flags)
if (inode) { if (inode) {
if (is_bad_inode(inode)) if (is_bad_inode(inode))
goto invalid; goto out;
ip = GFS2_I(inode); ip = GFS2_I(inode);
} }
if (sdp->sd_lockstruct.ls_ops->lm_mount == NULL) if (sdp->sd_lockstruct.ls_ops->lm_mount == NULL) {
goto valid; valid = 1;
goto out;
}
had_lock = (gfs2_glock_is_locked_by_me(dip->i_gl) != NULL); had_lock = (gfs2_glock_is_locked_by_me(dip->i_gl) != NULL);
if (!had_lock) { 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, 0, &d_gh);
if (error) if (error)
goto fail; goto out;
}
error = gfs2_dir_check(d_inode(parent), &dentry->d_name, ip);
switch (error) {
case 0:
if (!inode)
goto invalid_gunlock;
break;
case -ENOENT:
if (!inode)
goto valid_gunlock;
goto invalid_gunlock;
default:
goto fail_gunlock;
} }
valid_gunlock: error = gfs2_dir_check(d_inode(parent), &dentry->d_name, ip);
if (!had_lock) valid = inode ? !error : (error == -ENOENT);
gfs2_glock_dq_uninit(&d_gh);
valid:
dput(parent);
return 1;
invalid_gunlock:
if (!had_lock) if (!had_lock)
gfs2_glock_dq_uninit(&d_gh); gfs2_glock_dq_uninit(&d_gh);
invalid: out:
dput(parent); dput(parent);
return 0; return valid;
fail_gunlock:
gfs2_glock_dq_uninit(&d_gh);
fail:
dput(parent);
return 0;
} }
static int gfs2_dhash(const struct dentry *dentry, struct qstr *str) static int gfs2_dhash(const struct dentry *dentry, struct qstr *str)
......
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