diff options
author | Andreas Gruenbacher <agruenba@redhat.com> | 2016-06-17 08:31:27 -0400 |
---|---|---|
committer | Bob Peterson <rpeterso@redhat.com> | 2016-06-27 10:47:09 -0400 |
commit | 6df9f9a253c7dc9f8ed18bf89d762de350a31813 (patch) | |
tree | a048f6fb09f9da9d1616b7f5a9c9254ce6f1d7ab /fs/gfs2/inode.c | |
parent | cda9dd4207aeb29d0aa2298085cc2d1ebcb87e04 (diff) |
gfs2: Lock holder cleanup
Make the code more readable by cleaning up the different ways of
initializing lock holders and checking for initialized lock holders:
mark lock holders as uninitialized by setting the holder's glock to NULL
(gfs2_holder_mark_uninitialized) instead of zeroing out the entire
object or using a separate flag. Recognize initialized holders by their
non-NULL glock (gfs2_holder_initialized). Don't zero out holder objects
which are immeditiately initialized via gfs2_holder_init or
gfs2_glock_nq_init.
Signed-off-by: Andreas Gruenbacher <agruenba@redhat.com>
Signed-off-by: Bob Peterson <rpeterso@redhat.com>
Diffstat (limited to 'fs/gfs2/inode.c')
-rw-r--r-- | fs/gfs2/inode.c | 33 |
1 files changed, 15 insertions, 18 deletions
diff --git a/fs/gfs2/inode.c b/fs/gfs2/inode.c index 481b6496727d..de54d605cd09 100644 --- a/fs/gfs2/inode.c +++ b/fs/gfs2/inode.c | |||
@@ -127,9 +127,9 @@ struct inode *gfs2_inode_lookup(struct super_block *sb, unsigned int type, | |||
127 | struct gfs2_inode *ip; | 127 | struct gfs2_inode *ip; |
128 | struct gfs2_glock *io_gl = NULL; | 128 | struct gfs2_glock *io_gl = NULL; |
129 | struct gfs2_holder i_gh; | 129 | struct gfs2_holder i_gh; |
130 | bool unlock = false; | ||
131 | int error; | 130 | int error; |
132 | 131 | ||
132 | gfs2_holder_mark_uninitialized(&i_gh); | ||
133 | inode = gfs2_iget(sb, no_addr); | 133 | inode = gfs2_iget(sb, no_addr); |
134 | if (!inode) | 134 | if (!inode) |
135 | return ERR_PTR(-ENOMEM); | 135 | return ERR_PTR(-ENOMEM); |
@@ -159,7 +159,6 @@ struct inode *gfs2_inode_lookup(struct super_block *sb, unsigned int type, | |||
159 | GL_SKIP, &i_gh); | 159 | GL_SKIP, &i_gh); |
160 | if (error) | 160 | if (error) |
161 | goto fail_put; | 161 | goto fail_put; |
162 | unlock = true; | ||
163 | 162 | ||
164 | if (blktype != GFS2_BLKST_FREE) { | 163 | if (blktype != GFS2_BLKST_FREE) { |
165 | error = gfs2_check_blk_type(sdp, no_addr, | 164 | error = gfs2_check_blk_type(sdp, no_addr, |
@@ -191,7 +190,7 @@ struct inode *gfs2_inode_lookup(struct super_block *sb, unsigned int type, | |||
191 | unlock_new_inode(inode); | 190 | unlock_new_inode(inode); |
192 | } | 191 | } |
193 | 192 | ||
194 | if (unlock) | 193 | if (gfs2_holder_initialized(&i_gh)) |
195 | gfs2_glock_dq_uninit(&i_gh); | 194 | gfs2_glock_dq_uninit(&i_gh); |
196 | return inode; | 195 | return inode; |
197 | 196 | ||
@@ -203,7 +202,7 @@ fail_refresh: | |||
203 | fail_put: | 202 | fail_put: |
204 | if (io_gl) | 203 | if (io_gl) |
205 | gfs2_glock_put(io_gl); | 204 | gfs2_glock_put(io_gl); |
206 | if (unlock) | 205 | if (gfs2_holder_initialized(&i_gh)) |
207 | gfs2_glock_dq_uninit(&i_gh); | 206 | gfs2_glock_dq_uninit(&i_gh); |
208 | ip->i_gl->gl_object = NULL; | 207 | ip->i_gl->gl_object = NULL; |
209 | fail: | 208 | fail: |
@@ -281,8 +280,8 @@ struct inode *gfs2_lookupi(struct inode *dir, const struct qstr *name, | |||
281 | struct gfs2_holder d_gh; | 280 | struct gfs2_holder d_gh; |
282 | int error = 0; | 281 | int error = 0; |
283 | struct inode *inode = NULL; | 282 | struct inode *inode = NULL; |
284 | int unlock = 0; | ||
285 | 283 | ||
284 | gfs2_holder_mark_uninitialized(&d_gh); | ||
286 | if (!name->len || name->len > GFS2_FNAMESIZE) | 285 | if (!name->len || name->len > GFS2_FNAMESIZE) |
287 | return ERR_PTR(-ENAMETOOLONG); | 286 | return ERR_PTR(-ENAMETOOLONG); |
288 | 287 | ||
@@ -297,7 +296,6 @@ struct inode *gfs2_lookupi(struct inode *dir, const struct qstr *name, | |||
297 | error = gfs2_glock_nq_init(dip->i_gl, LM_ST_SHARED, 0, &d_gh); | 296 | error = gfs2_glock_nq_init(dip->i_gl, LM_ST_SHARED, 0, &d_gh); |
298 | if (error) | 297 | if (error) |
299 | return ERR_PTR(error); | 298 | return ERR_PTR(error); |
300 | unlock = 1; | ||
301 | } | 299 | } |
302 | 300 | ||
303 | if (!is_root) { | 301 | if (!is_root) { |
@@ -310,7 +308,7 @@ struct inode *gfs2_lookupi(struct inode *dir, const struct qstr *name, | |||
310 | if (IS_ERR(inode)) | 308 | if (IS_ERR(inode)) |
311 | error = PTR_ERR(inode); | 309 | error = PTR_ERR(inode); |
312 | out: | 310 | out: |
313 | if (unlock) | 311 | if (gfs2_holder_initialized(&d_gh)) |
314 | gfs2_glock_dq_uninit(&d_gh); | 312 | gfs2_glock_dq_uninit(&d_gh); |
315 | if (error == -ENOENT) | 313 | if (error == -ENOENT) |
316 | return NULL; | 314 | return NULL; |
@@ -1354,7 +1352,7 @@ static int gfs2_rename(struct inode *odir, struct dentry *odentry, | |||
1354 | struct gfs2_inode *ip = GFS2_I(d_inode(odentry)); | 1352 | struct gfs2_inode *ip = GFS2_I(d_inode(odentry)); |
1355 | struct gfs2_inode *nip = NULL; | 1353 | struct gfs2_inode *nip = NULL; |
1356 | struct gfs2_sbd *sdp = GFS2_SB(odir); | 1354 | struct gfs2_sbd *sdp = GFS2_SB(odir); |
1357 | struct gfs2_holder ghs[5], r_gh = { .gh_gl = NULL, }; | 1355 | struct gfs2_holder ghs[5], r_gh; |
1358 | struct gfs2_rgrpd *nrgd; | 1356 | struct gfs2_rgrpd *nrgd; |
1359 | unsigned int num_gh; | 1357 | unsigned int num_gh; |
1360 | int dir_rename = 0; | 1358 | int dir_rename = 0; |
@@ -1362,6 +1360,7 @@ static int gfs2_rename(struct inode *odir, struct dentry *odentry, | |||
1362 | unsigned int x; | 1360 | unsigned int x; |
1363 | int error; | 1361 | int error; |
1364 | 1362 | ||
1363 | gfs2_holder_mark_uninitialized(&r_gh); | ||
1365 | if (d_really_is_positive(ndentry)) { | 1364 | if (d_really_is_positive(ndentry)) { |
1366 | nip = GFS2_I(d_inode(ndentry)); | 1365 | nip = GFS2_I(d_inode(ndentry)); |
1367 | if (ip == nip) | 1366 | if (ip == nip) |
@@ -1551,7 +1550,7 @@ out_gunlock: | |||
1551 | gfs2_holder_uninit(ghs + x); | 1550 | gfs2_holder_uninit(ghs + x); |
1552 | } | 1551 | } |
1553 | out_gunlock_r: | 1552 | out_gunlock_r: |
1554 | if (r_gh.gh_gl) | 1553 | if (gfs2_holder_initialized(&r_gh)) |
1555 | gfs2_glock_dq_uninit(&r_gh); | 1554 | gfs2_glock_dq_uninit(&r_gh); |
1556 | out: | 1555 | out: |
1557 | return error; | 1556 | return error; |
@@ -1577,13 +1576,14 @@ static int gfs2_exchange(struct inode *odir, struct dentry *odentry, | |||
1577 | struct gfs2_inode *oip = GFS2_I(odentry->d_inode); | 1576 | struct gfs2_inode *oip = GFS2_I(odentry->d_inode); |
1578 | struct gfs2_inode *nip = GFS2_I(ndentry->d_inode); | 1577 | struct gfs2_inode *nip = GFS2_I(ndentry->d_inode); |
1579 | struct gfs2_sbd *sdp = GFS2_SB(odir); | 1578 | struct gfs2_sbd *sdp = GFS2_SB(odir); |
1580 | struct gfs2_holder ghs[5], r_gh = { .gh_gl = NULL, }; | 1579 | struct gfs2_holder ghs[5], r_gh; |
1581 | unsigned int num_gh; | 1580 | unsigned int num_gh; |
1582 | unsigned int x; | 1581 | unsigned int x; |
1583 | umode_t old_mode = oip->i_inode.i_mode; | 1582 | umode_t old_mode = oip->i_inode.i_mode; |
1584 | umode_t new_mode = nip->i_inode.i_mode; | 1583 | umode_t new_mode = nip->i_inode.i_mode; |
1585 | int error; | 1584 | int error; |
1586 | 1585 | ||
1586 | gfs2_holder_mark_uninitialized(&r_gh); | ||
1587 | error = gfs2_rindex_update(sdp); | 1587 | error = gfs2_rindex_update(sdp); |
1588 | if (error) | 1588 | if (error) |
1589 | return error; | 1589 | return error; |
@@ -1691,7 +1691,7 @@ out_gunlock: | |||
1691 | gfs2_holder_uninit(ghs + x); | 1691 | gfs2_holder_uninit(ghs + x); |
1692 | } | 1692 | } |
1693 | out_gunlock_r: | 1693 | out_gunlock_r: |
1694 | if (r_gh.gh_gl) | 1694 | if (gfs2_holder_initialized(&r_gh)) |
1695 | gfs2_glock_dq_uninit(&r_gh); | 1695 | gfs2_glock_dq_uninit(&r_gh); |
1696 | out: | 1696 | out: |
1697 | return error; | 1697 | return error; |
@@ -1788,9 +1788,8 @@ int gfs2_permission(struct inode *inode, int mask) | |||
1788 | struct gfs2_inode *ip; | 1788 | struct gfs2_inode *ip; |
1789 | struct gfs2_holder i_gh; | 1789 | struct gfs2_holder i_gh; |
1790 | int error; | 1790 | int error; |
1791 | int unlock = 0; | ||
1792 | |||
1793 | 1791 | ||
1792 | gfs2_holder_mark_uninitialized(&i_gh); | ||
1794 | ip = GFS2_I(inode); | 1793 | ip = GFS2_I(inode); |
1795 | if (gfs2_glock_is_locked_by_me(ip->i_gl) == NULL) { | 1794 | if (gfs2_glock_is_locked_by_me(ip->i_gl) == NULL) { |
1796 | if (mask & MAY_NOT_BLOCK) | 1795 | if (mask & MAY_NOT_BLOCK) |
@@ -1798,14 +1797,13 @@ int gfs2_permission(struct inode *inode, int mask) | |||
1798 | error = gfs2_glock_nq_init(ip->i_gl, LM_ST_SHARED, LM_FLAG_ANY, &i_gh); | 1797 | error = gfs2_glock_nq_init(ip->i_gl, LM_ST_SHARED, LM_FLAG_ANY, &i_gh); |
1799 | if (error) | 1798 | if (error) |
1800 | return error; | 1799 | return error; |
1801 | unlock = 1; | ||
1802 | } | 1800 | } |
1803 | 1801 | ||
1804 | if ((mask & MAY_WRITE) && IS_IMMUTABLE(inode)) | 1802 | if ((mask & MAY_WRITE) && IS_IMMUTABLE(inode)) |
1805 | error = -EACCES; | 1803 | error = -EACCES; |
1806 | else | 1804 | else |
1807 | error = generic_permission(inode, mask); | 1805 | error = generic_permission(inode, mask); |
1808 | if (unlock) | 1806 | if (gfs2_holder_initialized(&i_gh)) |
1809 | gfs2_glock_dq_uninit(&i_gh); | 1807 | gfs2_glock_dq_uninit(&i_gh); |
1810 | 1808 | ||
1811 | return error; | 1809 | return error; |
@@ -1977,17 +1975,16 @@ static int gfs2_getattr(struct vfsmount *mnt, struct dentry *dentry, | |||
1977 | struct gfs2_inode *ip = GFS2_I(inode); | 1975 | struct gfs2_inode *ip = GFS2_I(inode); |
1978 | struct gfs2_holder gh; | 1976 | struct gfs2_holder gh; |
1979 | int error; | 1977 | int error; |
1980 | int unlock = 0; | ||
1981 | 1978 | ||
1979 | gfs2_holder_mark_uninitialized(&gh); | ||
1982 | if (gfs2_glock_is_locked_by_me(ip->i_gl) == NULL) { | 1980 | if (gfs2_glock_is_locked_by_me(ip->i_gl) == NULL) { |
1983 | error = gfs2_glock_nq_init(ip->i_gl, LM_ST_SHARED, LM_FLAG_ANY, &gh); | 1981 | error = gfs2_glock_nq_init(ip->i_gl, LM_ST_SHARED, LM_FLAG_ANY, &gh); |
1984 | if (error) | 1982 | if (error) |
1985 | return error; | 1983 | return error; |
1986 | unlock = 1; | ||
1987 | } | 1984 | } |
1988 | 1985 | ||
1989 | generic_fillattr(inode, stat); | 1986 | generic_fillattr(inode, stat); |
1990 | if (unlock) | 1987 | if (gfs2_holder_initialized(&gh)) |
1991 | gfs2_glock_dq_uninit(&gh); | 1988 | gfs2_glock_dq_uninit(&gh); |
1992 | 1989 | ||
1993 | return 0; | 1990 | return 0; |