Commit 2613769d authored by zhangyi (F)'s avatar zhangyi (F) Committed by Stefan Bader

ext4: cleanup bh release code in ext4_ind_remove_space()

BugLink: https://bugs.launchpad.net/bugs/1828420

commit 5e86bdda upstream.

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: default avatarzhangyi (F) <yi.zhang@huawei.com>
Signed-off-by: default avatarTheodore Ts'o <tytso@mit.edu>
Reviewed-by: default avatarJan Kara <jack@suse.cz>
Cc: Jari Ruusu <jari.ruusu@gmail.com>
Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Signed-off-by: default avatarKleber Sacilotto de Souza <kleber.souza@canonical.com>
Signed-off-by: default avatarStefan Bader <stefan.bader@canonical.com>
parent 6786c90b
...@@ -1338,6 +1338,7 @@ int ext4_ind_remove_space(handle_t *handle, struct inode *inode, ...@@ -1338,6 +1338,7 @@ int ext4_ind_remove_space(handle_t *handle, struct inode *inode,
ext4_lblk_t offsets[4], offsets2[4]; ext4_lblk_t offsets[4], offsets2[4];
Indirect chain[4], chain2[4]; Indirect chain[4], chain2[4];
Indirect *partial, *partial2; Indirect *partial, *partial2;
Indirect *p = NULL, *p2 = NULL;
ext4_lblk_t max_block; ext4_lblk_t max_block;
__le32 nr = 0, nr2 = 0; __le32 nr = 0, nr2 = 0;
int n = 0, n2 = 0; int n = 0, n2 = 0;
...@@ -1379,7 +1380,7 @@ int ext4_ind_remove_space(handle_t *handle, struct inode *inode, ...@@ -1379,7 +1380,7 @@ int ext4_ind_remove_space(handle_t *handle, struct inode *inode,
} }
partial = ext4_find_shared(inode, n, offsets, chain, &nr); partial = p = ext4_find_shared(inode, n, offsets, chain, &nr);
if (nr) { if (nr) {
if (partial == chain) { if (partial == chain) {
/* Shared branch grows from the inode */ /* Shared branch grows from the inode */
...@@ -1404,13 +1405,11 @@ int ext4_ind_remove_space(handle_t *handle, struct inode *inode, ...@@ -1404,13 +1405,11 @@ int ext4_ind_remove_space(handle_t *handle, struct inode *inode,
partial->p + 1, partial->p + 1,
(__le32 *)partial->bh->b_data+addr_per_block, (__le32 *)partial->bh->b_data+addr_per_block,
(chain+n-1) - partial); (chain+n-1) - partial);
BUFFER_TRACE(partial->bh, "call brelse");
brelse(partial->bh);
partial--; partial--;
} }
end_range: end_range:
partial2 = ext4_find_shared(inode, n2, offsets2, chain2, &nr2); partial2 = p2 = ext4_find_shared(inode, n2, offsets2, chain2, &nr2);
if (nr2) { if (nr2) {
if (partial2 == chain2) { if (partial2 == chain2) {
/* /*
...@@ -1440,16 +1439,14 @@ int ext4_ind_remove_space(handle_t *handle, struct inode *inode, ...@@ -1440,16 +1439,14 @@ int ext4_ind_remove_space(handle_t *handle, struct inode *inode,
(__le32 *)partial2->bh->b_data, (__le32 *)partial2->bh->b_data,
partial2->p, partial2->p,
(chain2+n2-1) - partial2); (chain2+n2-1) - partial2);
BUFFER_TRACE(partial2->bh, "call brelse");
brelse(partial2->bh);
partial2--; partial2--;
} }
goto do_indirects; goto do_indirects;
} }
/* Punch happened within the same level (n == n2) */ /* Punch happened within the same level (n == n2) */
partial = ext4_find_shared(inode, n, offsets, chain, &nr); partial = p = ext4_find_shared(inode, n, offsets, chain, &nr);
partial2 = ext4_find_shared(inode, n2, offsets2, chain2, &nr2); partial2 = p2 = ext4_find_shared(inode, n2, offsets2, chain2, &nr2);
/* Free top, but only if partial2 isn't its subtree. */ /* Free top, but only if partial2 isn't its subtree. */
if (nr) { if (nr) {
...@@ -1506,15 +1503,7 @@ int ext4_ind_remove_space(handle_t *handle, struct inode *inode, ...@@ -1506,15 +1503,7 @@ int ext4_ind_remove_space(handle_t *handle, struct inode *inode,
partial->p + 1, partial->p + 1,
partial2->p, partial2->p,
(chain+n-1) - partial); (chain+n-1) - partial);
while (partial > chain) { goto cleanup;
BUFFER_TRACE(partial->bh, "call brelse");
brelse(partial->bh);
}
while (partial2 > chain2) {
BUFFER_TRACE(partial2->bh, "call brelse");
brelse(partial2->bh);
}
return 0;
} }
/* /*
...@@ -1529,8 +1518,6 @@ int ext4_ind_remove_space(handle_t *handle, struct inode *inode, ...@@ -1529,8 +1518,6 @@ int ext4_ind_remove_space(handle_t *handle, struct inode *inode,
partial->p + 1, partial->p + 1,
(__le32 *)partial->bh->b_data+addr_per_block, (__le32 *)partial->bh->b_data+addr_per_block,
(chain+n-1) - partial); (chain+n-1) - partial);
BUFFER_TRACE(partial->bh, "call brelse");
brelse(partial->bh);
partial--; partial--;
} }
if (partial2 > chain2 && depth2 <= depth) { if (partial2 > chain2 && depth2 <= depth) {
...@@ -1538,11 +1525,21 @@ int ext4_ind_remove_space(handle_t *handle, struct inode *inode, ...@@ -1538,11 +1525,21 @@ int ext4_ind_remove_space(handle_t *handle, struct inode *inode,
(__le32 *)partial2->bh->b_data, (__le32 *)partial2->bh->b_data,
partial2->p, partial2->p,
(chain2+n2-1) - partial2); (chain2+n2-1) - partial2);
BUFFER_TRACE(partial2->bh, "call brelse");
brelse(partial2->bh);
partial2--; partial2--;
} }
} }
cleanup:
while (p && p > chain) {
BUFFER_TRACE(p->bh, "call brelse");
brelse(p->bh);
p--;
}
while (p2 && p2 > chain2) {
BUFFER_TRACE(p2->bh, "call brelse");
brelse(p2->bh);
p2--;
}
return 0; return 0;
do_indirects: do_indirects:
...@@ -1550,7 +1547,7 @@ int ext4_ind_remove_space(handle_t *handle, struct inode *inode, ...@@ -1550,7 +1547,7 @@ int ext4_ind_remove_space(handle_t *handle, struct inode *inode,
switch (offsets[0]) { switch (offsets[0]) {
default: default:
if (++n >= n2) if (++n >= n2)
return 0; break;
nr = i_data[EXT4_IND_BLOCK]; nr = i_data[EXT4_IND_BLOCK];
if (nr) { if (nr) {
ext4_free_branches(handle, inode, NULL, &nr, &nr+1, 1); ext4_free_branches(handle, inode, NULL, &nr, &nr+1, 1);
...@@ -1558,7 +1555,7 @@ int ext4_ind_remove_space(handle_t *handle, struct inode *inode, ...@@ -1558,7 +1555,7 @@ int ext4_ind_remove_space(handle_t *handle, struct inode *inode,
} }
case EXT4_IND_BLOCK: case EXT4_IND_BLOCK:
if (++n >= n2) if (++n >= n2)
return 0; break;
nr = i_data[EXT4_DIND_BLOCK]; nr = i_data[EXT4_DIND_BLOCK];
if (nr) { if (nr) {
ext4_free_branches(handle, inode, NULL, &nr, &nr+1, 2); ext4_free_branches(handle, inode, NULL, &nr, &nr+1, 2);
...@@ -1566,7 +1563,7 @@ int ext4_ind_remove_space(handle_t *handle, struct inode *inode, ...@@ -1566,7 +1563,7 @@ int ext4_ind_remove_space(handle_t *handle, struct inode *inode,
} }
case EXT4_DIND_BLOCK: case EXT4_DIND_BLOCK:
if (++n >= n2) if (++n >= n2)
return 0; break;
nr = i_data[EXT4_TIND_BLOCK]; nr = i_data[EXT4_TIND_BLOCK];
if (nr) { if (nr) {
ext4_free_branches(handle, inode, NULL, &nr, &nr+1, 3); ext4_free_branches(handle, inode, NULL, &nr, &nr+1, 3);
...@@ -1575,5 +1572,5 @@ int ext4_ind_remove_space(handle_t *handle, struct inode *inode, ...@@ -1575,5 +1572,5 @@ int ext4_ind_remove_space(handle_t *handle, struct inode *inode,
case EXT4_TIND_BLOCK: case EXT4_TIND_BLOCK:
; ;
} }
return 0; goto cleanup;
} }
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