1 From 5e86bdda41534e17621d5a071b294943cae4376e Mon Sep 17 00:00:00 2001
2 From: "zhangyi (F)" <yi.zhang@huawei.com>
3 Date: Sat, 23 Mar 2019 11:56:01 -0400
4 Subject: ext4: cleanup bh release code in ext4_ind_remove_space()
6 From: zhangyi (F) <yi.zhang@huawei.com>
8 commit 5e86bdda41534e17621d5a071b294943cae4376e upstream.
10 Currently, we are releasing the indirect buffer where we are done with
11 it in ext4_ind_remove_space(), so we can see the brelse() and
12 BUFFER_TRACE() everywhere. It seems fragile and hard to read, and we
13 may probably forget to release the buffer some day. This patch cleans
14 up the code by putting of the code which releases the buffers to the
17 Signed-off-by: zhangyi (F) <yi.zhang@huawei.com>
18 Signed-off-by: Theodore Ts'o <tytso@mit.edu>
19 Reviewed-by: Jan Kara <jack@suse.cz>
20 Cc: Jari Ruusu <jari.ruusu@gmail.com>
21 Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
24 fs/ext4/indirect.c | 47 ++++++++++++++++++++++-------------------------
25 1 file changed, 22 insertions(+), 25 deletions(-)
27 --- a/fs/ext4/indirect.c
28 +++ b/fs/ext4/indirect.c
29 @@ -1312,6 +1312,7 @@ int ext4_ind_remove_space(handle_t *hand
30 ext4_lblk_t offsets[4], offsets2[4];
31 Indirect chain[4], chain2[4];
32 Indirect *partial, *partial2;
33 + Indirect *p = NULL, *p2 = NULL;
34 ext4_lblk_t max_block;
35 __le32 nr = 0, nr2 = 0;
37 @@ -1353,7 +1354,7 @@ int ext4_ind_remove_space(handle_t *hand
41 - partial = ext4_find_shared(inode, n, offsets, chain, &nr);
42 + partial = p = ext4_find_shared(inode, n, offsets, chain, &nr);
44 if (partial == chain) {
45 /* Shared branch grows from the inode */
46 @@ -1378,13 +1379,11 @@ int ext4_ind_remove_space(handle_t *hand
48 (__le32 *)partial->bh->b_data+addr_per_block,
49 (chain+n-1) - partial);
50 - BUFFER_TRACE(partial->bh, "call brelse");
51 - brelse(partial->bh);
56 - partial2 = ext4_find_shared(inode, n2, offsets2, chain2, &nr2);
57 + partial2 = p2 = ext4_find_shared(inode, n2, offsets2, chain2, &nr2);
59 if (partial2 == chain2) {
61 @@ -1414,16 +1413,14 @@ end_range:
62 (__le32 *)partial2->bh->b_data,
64 (chain2+n2-1) - partial2);
65 - BUFFER_TRACE(partial2->bh, "call brelse");
66 - brelse(partial2->bh);
72 /* Punch happened within the same level (n == n2) */
73 - partial = ext4_find_shared(inode, n, offsets, chain, &nr);
74 - partial2 = ext4_find_shared(inode, n2, offsets2, chain2, &nr2);
75 + partial = p = ext4_find_shared(inode, n, offsets, chain, &nr);
76 + partial2 = p2 = ext4_find_shared(inode, n2, offsets2, chain2, &nr2);
78 /* Free top, but only if partial2 isn't its subtree. */
80 @@ -1480,15 +1477,7 @@ end_range:
83 (chain+n-1) - partial);
84 - while (partial > chain) {
85 - BUFFER_TRACE(partial->bh, "call brelse");
86 - brelse(partial->bh);
88 - while (partial2 > chain2) {
89 - BUFFER_TRACE(partial2->bh, "call brelse");
90 - brelse(partial2->bh);
97 @@ -1503,8 +1492,6 @@ end_range:
99 (__le32 *)partial->bh->b_data+addr_per_block,
100 (chain+n-1) - partial);
101 - BUFFER_TRACE(partial->bh, "call brelse");
102 - brelse(partial->bh);
105 if (partial2 > chain2 && depth2 <= depth) {
106 @@ -1512,11 +1499,21 @@ end_range:
107 (__le32 *)partial2->bh->b_data,
109 (chain2+n2-1) - partial2);
110 - BUFFER_TRACE(partial2->bh, "call brelse");
111 - brelse(partial2->bh);
117 + while (p && p > chain) {
118 + BUFFER_TRACE(p->bh, "call brelse");
122 + while (p2 && p2 > chain2) {
123 + BUFFER_TRACE(p2->bh, "call brelse");
130 @@ -1524,7 +1521,7 @@ do_indirects:
131 switch (offsets[0]) {
136 nr = i_data[EXT4_IND_BLOCK];
138 ext4_free_branches(handle, inode, NULL, &nr, &nr+1, 1);
139 @@ -1532,7 +1529,7 @@ do_indirects:
145 nr = i_data[EXT4_DIND_BLOCK];
147 ext4_free_branches(handle, inode, NULL, &nr, &nr+1, 2);
148 @@ -1540,7 +1537,7 @@ do_indirects:
150 case EXT4_DIND_BLOCK:
154 nr = i_data[EXT4_TIND_BLOCK];
156 ext4_free_branches(handle, inode, NULL, &nr, &nr+1, 3);
157 @@ -1549,5 +1546,5 @@ do_indirects:
158 case EXT4_TIND_BLOCK: