Skip to content

Commit 5e86bdd

Browse files
zhangyi089tytso
authored andcommitted
ext4: cleanup bh release code in ext4_ind_remove_space()
Currently, we are releasing the indirect buffer where we are done with it in ext4_ind_remove_space(), so we can see the brelse() and BUFFER_TRACE() everywhere. It seems fragile and hard to read, and we may probably forget to release the buffer some day. This patch cleans up the code by putting of the code which releases the buffers to the end of the function. Signed-off-by: zhangyi (F) <yi.zhang@huawei.com> Signed-off-by: Theodore Ts'o <tytso@mit.edu> Reviewed-by: Jan Kara <jack@suse.cz>
1 parent 674a2b2 commit 5e86bdd

File tree

1 file changed

+22
-25
lines changed

1 file changed

+22
-25
lines changed

fs/ext4/indirect.c

Lines changed: 22 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1222,6 +1222,7 @@ int ext4_ind_remove_space(handle_t *handle, struct inode *inode,
12221222
ext4_lblk_t offsets[4], offsets2[4];
12231223
Indirect chain[4], chain2[4];
12241224
Indirect *partial, *partial2;
1225+
Indirect *p = NULL, *p2 = NULL;
12251226
ext4_lblk_t max_block;
12261227
__le32 nr = 0, nr2 = 0;
12271228
int n = 0, n2 = 0;
@@ -1263,7 +1264,7 @@ int ext4_ind_remove_space(handle_t *handle, struct inode *inode,
12631264
}
12641265

12651266

1266-
partial = ext4_find_shared(inode, n, offsets, chain, &nr);
1267+
partial = p = ext4_find_shared(inode, n, offsets, chain, &nr);
12671268
if (nr) {
12681269
if (partial == chain) {
12691270
/* Shared branch grows from the inode */
@@ -1288,13 +1289,11 @@ int ext4_ind_remove_space(handle_t *handle, struct inode *inode,
12881289
partial->p + 1,
12891290
(__le32 *)partial->bh->b_data+addr_per_block,
12901291
(chain+n-1) - partial);
1291-
BUFFER_TRACE(partial->bh, "call brelse");
1292-
brelse(partial->bh);
12931292
partial--;
12941293
}
12951294

12961295
end_range:
1297-
partial2 = ext4_find_shared(inode, n2, offsets2, chain2, &nr2);
1296+
partial2 = p2 = ext4_find_shared(inode, n2, offsets2, chain2, &nr2);
12981297
if (nr2) {
12991298
if (partial2 == chain2) {
13001299
/*
@@ -1324,16 +1323,14 @@ int ext4_ind_remove_space(handle_t *handle, struct inode *inode,
13241323
(__le32 *)partial2->bh->b_data,
13251324
partial2->p,
13261325
(chain2+n2-1) - partial2);
1327-
BUFFER_TRACE(partial2->bh, "call brelse");
1328-
brelse(partial2->bh);
13291326
partial2--;
13301327
}
13311328
goto do_indirects;
13321329
}
13331330

13341331
/* Punch happened within the same level (n == n2) */
1335-
partial = ext4_find_shared(inode, n, offsets, chain, &nr);
1336-
partial2 = ext4_find_shared(inode, n2, offsets2, chain2, &nr2);
1332+
partial = p = ext4_find_shared(inode, n, offsets, chain, &nr);
1333+
partial2 = p2 = ext4_find_shared(inode, n2, offsets2, chain2, &nr2);
13371334

13381335
/* Free top, but only if partial2 isn't its subtree. */
13391336
if (nr) {
@@ -1390,15 +1387,7 @@ int ext4_ind_remove_space(handle_t *handle, struct inode *inode,
13901387
partial->p + 1,
13911388
partial2->p,
13921389
(chain+n-1) - partial);
1393-
while (partial > chain) {
1394-
BUFFER_TRACE(partial->bh, "call brelse");
1395-
brelse(partial->bh);
1396-
}
1397-
while (partial2 > chain2) {
1398-
BUFFER_TRACE(partial2->bh, "call brelse");
1399-
brelse(partial2->bh);
1400-
}
1401-
return 0;
1390+
goto cleanup;
14021391
}
14031392

14041393
/*
@@ -1413,28 +1402,36 @@ int ext4_ind_remove_space(handle_t *handle, struct inode *inode,
14131402
partial->p + 1,
14141403
(__le32 *)partial->bh->b_data+addr_per_block,
14151404
(chain+n-1) - partial);
1416-
BUFFER_TRACE(partial->bh, "call brelse");
1417-
brelse(partial->bh);
14181405
partial--;
14191406
}
14201407
if (partial2 > chain2 && depth2 <= depth) {
14211408
ext4_free_branches(handle, inode, partial2->bh,
14221409
(__le32 *)partial2->bh->b_data,
14231410
partial2->p,
14241411
(chain2+n2-1) - partial2);
1425-
BUFFER_TRACE(partial2->bh, "call brelse");
1426-
brelse(partial2->bh);
14271412
partial2--;
14281413
}
14291414
}
1415+
1416+
cleanup:
1417+
while (p && p > chain) {
1418+
BUFFER_TRACE(p->bh, "call brelse");
1419+
brelse(p->bh);
1420+
p--;
1421+
}
1422+
while (p2 && p2 > chain2) {
1423+
BUFFER_TRACE(p2->bh, "call brelse");
1424+
brelse(p2->bh);
1425+
p2--;
1426+
}
14301427
return 0;
14311428

14321429
do_indirects:
14331430
/* Kill the remaining (whole) subtrees */
14341431
switch (offsets[0]) {
14351432
default:
14361433
if (++n >= n2)
1437-
return 0;
1434+
break;
14381435
nr = i_data[EXT4_IND_BLOCK];
14391436
if (nr) {
14401437
ext4_free_branches(handle, inode, NULL, &nr, &nr+1, 1);
@@ -1443,7 +1440,7 @@ int ext4_ind_remove_space(handle_t *handle, struct inode *inode,
14431440
/* fall through */
14441441
case EXT4_IND_BLOCK:
14451442
if (++n >= n2)
1446-
return 0;
1443+
break;
14471444
nr = i_data[EXT4_DIND_BLOCK];
14481445
if (nr) {
14491446
ext4_free_branches(handle, inode, NULL, &nr, &nr+1, 2);
@@ -1452,7 +1449,7 @@ int ext4_ind_remove_space(handle_t *handle, struct inode *inode,
14521449
/* fall through */
14531450
case EXT4_DIND_BLOCK:
14541451
if (++n >= n2)
1455-
return 0;
1452+
break;
14561453
nr = i_data[EXT4_TIND_BLOCK];
14571454
if (nr) {
14581455
ext4_free_branches(handle, inode, NULL, &nr, &nr+1, 3);
@@ -1462,5 +1459,5 @@ int ext4_ind_remove_space(handle_t *handle, struct inode *inode,
14621459
case EXT4_TIND_BLOCK:
14631460
;
14641461
}
1465-
return 0;
1462+
goto cleanup;
14661463
}

0 commit comments

Comments
 (0)