Skip to content

Commit bc74aae

Browse files
AstralBobagruenba
authored andcommitted
gfs2: separate holder for rgrps in gfs2_rename
Before this patch, gfs2_rename added a holder for the rgrp glock to its array of holders, ghs. There's nothing wrong with that, but this patch separates it into a separate holder. This is done to ensure it's always locked last as per the proper glock lock ordering, and also to pave the way for a future patch in which we will lock the non-rgrp glocks asynchronously. Signed-off-by: Bob Peterson <rpeterso@redhat.com> Signed-off-by: Andreas Gruenbacher <agruenba@redhat.com>
1 parent bccaef9 commit bc74aae

1 file changed

Lines changed: 21 additions & 8 deletions

File tree

‎fs/gfs2/inode.c‎

Lines changed: 21 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1348,7 +1348,7 @@ static int gfs2_rename(struct inode *odir, struct dentry *odentry,
13481348
struct gfs2_inode *ip = GFS2_I(d_inode(odentry));
13491349
struct gfs2_inode *nip = NULL;
13501350
struct gfs2_sbd *sdp = GFS2_SB(odir);
1351-
struct gfs2_holder ghs[5], r_gh;
1351+
struct gfs2_holder ghs[4], r_gh, rd_gh;
13521352
struct gfs2_rgrpd *nrgd;
13531353
unsigned int num_gh;
13541354
int dir_rename = 0;
@@ -1357,6 +1357,7 @@ static int gfs2_rename(struct inode *odir, struct dentry *odentry,
13571357
int error;
13581358

13591359
gfs2_holder_mark_uninitialized(&r_gh);
1360+
gfs2_holder_mark_uninitialized(&rd_gh);
13601361
if (d_really_is_positive(ndentry)) {
13611362
nip = GFS2_I(d_inode(ndentry));
13621363
if (ip == nip)
@@ -1398,13 +1399,6 @@ static int gfs2_rename(struct inode *odir, struct dentry *odentry,
13981399
if (nip) {
13991400
gfs2_holder_init(nip->i_gl, LM_ST_EXCLUSIVE, 0, ghs + num_gh);
14001401
num_gh++;
1401-
/* grab the resource lock for unlink flag twiddling
1402-
* this is the case of the target file already existing
1403-
* so we unlink before doing the rename
1404-
*/
1405-
nrgd = gfs2_blk2rgrpd(sdp, nip->i_no_addr, 1);
1406-
if (nrgd)
1407-
gfs2_holder_init(nrgd->rd_gl, LM_ST_EXCLUSIVE, 0, ghs + num_gh++);
14081402
}
14091403

14101404
for (x = 0; x < num_gh; x++) {
@@ -1413,6 +1407,22 @@ static int gfs2_rename(struct inode *odir, struct dentry *odentry,
14131407
goto out_gunlock;
14141408
}
14151409

1410+
if (nip) {
1411+
/* Grab the resource group glock for unlink flag twiddling.
1412+
* This is the case where the target dinode already exists
1413+
* so we unlink before doing the rename.
1414+
*/
1415+
nrgd = gfs2_blk2rgrpd(sdp, nip->i_no_addr, 1);
1416+
if (!nrgd) {
1417+
error = -ENOENT;
1418+
goto out_gunlock;
1419+
}
1420+
error = gfs2_glock_nq_init(nrgd->rd_gl, LM_ST_EXCLUSIVE, 0,
1421+
&rd_gh);
1422+
if (error)
1423+
goto out_gunlock;
1424+
}
1425+
14161426
error = -ENOENT;
14171427
if (ip->i_inode.i_nlink == 0)
14181428
goto out_gunlock;
@@ -1541,6 +1551,9 @@ static int gfs2_rename(struct inode *odir, struct dentry *odentry,
15411551
gfs2_quota_unlock(ndip);
15421552
out_gunlock:
15431553
gfs2_dir_no_add(&da);
1554+
if (gfs2_holder_initialized(&rd_gh))
1555+
gfs2_glock_dq_uninit(&rd_gh);
1556+
15441557
while (x--) {
15451558
gfs2_glock_dq(ghs + x);
15461559
gfs2_holder_uninit(ghs + x);

0 commit comments

Comments
 (0)