Skip to contentSkip to conversation

gfs2: untangle the logic in gfs2_drevalidate

PATCH Superseded Bob Peterson 2 participants 3 messages Aug 6, 2019 – Aug 13, 2019 1 message not in the archive GFS2 file system

lore
Share & tools
lore

A message that is not in the archive (sent off-list or not yet received): [email protected]

#1 lore raw

PATCH 1/1 gfs2: untangle the logic in gfs2_drevalidate

Hi,

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.

---
 fs/gfs2/dentry.c | 45 +++++++++++----------------------------------
 1 file changed, 11 insertions(+), 34 deletions(-)
fs/gfs2/dentry.c +11 -34
index a7bb76e9a82b..26d73f94ae45 100644
@@ -38,7 +38,7 @@ static int gfs2_drevalidate(struct dentry *dentry, unsigned int flags)
 	struct inode *inode;
 	struct gfs2_holder d_gh;
 	struct gfs2_inode *ip = NULL;
-	int error;
+	int error, valid = 0;
 	int had_lock = 0;
 
 	if (flags & LOOKUP_RCU)
@@ -51,53 +51,30 @@ static int gfs2_drevalidate(struct dentry *dentry, unsigned int flags)
 
 	if (inode) {
 		if (is_bad_inode(inode))
-			goto invalid;
+			goto out;
 		ip = GFS2_I(inode);
 	}
 
-	if (sdp->sd_lockstruct.ls_ops->lm_mount == NULL)
-		goto valid;
+	if (sdp->sd_lockstruct.ls_ops->lm_mount == NULL) {
+		valid = 1;
+		goto out;
+	}
 
 	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);
 		if (error)
-			goto fail;
-	} 
-
-	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;
+			goto out;
 	}
 
-valid_gunlock:
-	if (!had_lock)
-		gfs2_glock_dq_uninit(&d_gh);
-valid:
-	dput(parent);
-	return 1;
+	error = gfs2_dir_check(d_inode(parent), &dentry->d_name, ip);
+	valid = (!error && inode) || ((error == -ENOENT) && !inode);
 
-invalid_gunlock:
 	if (!had_lock)
 		gfs2_glock_dq_uninit(&d_gh);
-invalid:
+out:
 	dput(parent);
-	return 0;
-
-fail_gunlock:
-	gfs2_glock_dq_uninit(&d_gh);
-fail:
-	dput(parent);
-	return 0;
+	return valid;
 }
 
 static int gfs2_dhash(const struct dentry *dentry, struct qstr *str)
#2 lore raw

PATCH 1/1 gfs2: untangle the logic in gfs2_drevalidate

Quoted 61 lines · Bob Peterson

Hi,

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.

---
 fs/gfs2/dentry.c | 45 +++++++++++----------------------------------
 1 file changed, 11 insertions(+), 34 deletions(-)
fs/gfs2/dentry.c +7 -19
index a7bb76e9a82b..26d73f94ae45 100644
@@ -38,7 +38,7 @@ static int gfs2_drevalidate(struct dentry *dentry, unsigned int flags)
        struct inode *inode;
        struct gfs2_holder d_gh;
        struct gfs2_inode *ip = NULL;
-       int error;
+       int error, valid = 0;
        int had_lock = 0;
 
        if (flags & LOOKUP_RCU)
@@ -51,53 +51,30 @@ static int gfs2_drevalidate(struct dentry *dentry, unsigned int flags)
 
        if (inode) {
                if (is_bad_inode(inode))
-                       goto invalid;
+                       goto out;
                ip = GFS2_I(inode);
        }
 
-       if (sdp->sd_lockstruct.ls_ops->lm_mount == NULL)
-               goto valid;
+       if (sdp->sd_lockstruct.ls_ops->lm_mount == NULL) {
+               valid = 1;
+               goto out;
+       }
 
        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);
                if (error)
-                       goto fail;
-       }
-
-       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;
+                       goto out;

fs/gfs2/dentry.c static int gfs2_drevalidate(struct dentry *dentry, unsigned int flags) · line 71

Quoted 10 lines
fs/gfs2/dentry.c +2 -6
        }
 
-valid_gunlock:
-       if (!had_lock)
-               gfs2_glock_dq_uninit(&d_gh);
-valid:
-       dput(parent);
-       return 1;
+       error = gfs2_dir_check(d_inode(parent), &dentry->d_name, ip);
+       valid = (!error && inode) || ((error == -ENOENT) && !inode);

valid = inode ? !error : (error == -ENOENT);

Quoted 7 lines
fs/gfs2/dentry.c +1 -3
-invalid_gunlock:
        if (!had_lock)
                gfs2_glock_dq_uninit(&d_gh);
-invalid:
+out:
        dput(parent);
-       return 0;

fs/gfs2/dentry.c static int gfs2_drevalidate(struct dentry *dentry, unsigned int flags) · line 80

Quoted 10 lines
fs/gfs2/dentry.c +1 -6
-
-fail_gunlock:
-       gfs2_glock_dq_uninit(&d_gh);
-fail:
-       dput(parent);
-       return 0;
+       return valid;
 }
 
 static int gfs2_dhash(const struct dentry *dentry, struct qstr *str)

Andreas

#3 lore raw

PATCH v2 1/1 gfs2: untangle the logic in gfs2_drevalidate

Hi,

This version 2 patch is the same as the original, but it implements Andreas's suggestion.
---
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.

---
 fs/gfs2/dentry.c | 45 +++++++++++----------------------------------
 1 file changed, 11 insertions(+), 34 deletions(-)
fs/gfs2/dentry.c +11 -34
index a7bb76e9a82b..2e215e8c3c88 100644
@@ -38,7 +38,7 @@ static int gfs2_drevalidate(struct dentry *dentry, unsigned int flags)
 	struct inode *inode;
 	struct gfs2_holder d_gh;
 	struct gfs2_inode *ip = NULL;
-	int error;
+	int error, valid = 0;
 	int had_lock = 0;
 
 	if (flags & LOOKUP_RCU)
@@ -51,53 +51,30 @@ static int gfs2_drevalidate(struct dentry *dentry, unsigned int flags)
 
 	if (inode) {
 		if (is_bad_inode(inode))
-			goto invalid;
+			goto out;
 		ip = GFS2_I(inode);
 	}
 
-	if (sdp->sd_lockstruct.ls_ops->lm_mount == NULL)
-		goto valid;
+	if (sdp->sd_lockstruct.ls_ops->lm_mount == NULL) {
+		valid = 1;
+		goto out;
+	}
 
 	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);
 		if (error)
-			goto fail;
-	} 
-
-	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;
+			goto out;
 	}
 
-valid_gunlock:
-	if (!had_lock)
-		gfs2_glock_dq_uninit(&d_gh);
-valid:
-	dput(parent);
-	return 1;
+	error = gfs2_dir_check(d_inode(parent), &dentry->d_name, ip);
+	valid = inode ? !error : (error == -ENOENT);
 
-invalid_gunlock:
 	if (!had_lock)
 		gfs2_glock_dq_uninit(&d_gh);
-invalid:
+out:
 	dput(parent);
-	return 0;
-
-fail_gunlock:
-	gfs2_glock_dq_uninit(&d_gh);
-fail:
-	dput(parent);
-	return 0;
+	return valid;
 }
 
 static int gfs2_dhash(const struct dentry *dentry, struct qstr *str)