]> git.ipfire.org Git - thirdparty/kernel/stable-queue.git/blob - queue-4.19/ext4-cleanup-bh-release-code-in-ext4_ind_remove_space.patch
Linux 4.14.111
[thirdparty/kernel/stable-queue.git] / queue-4.19 / ext4-cleanup-bh-release-code-in-ext4_ind_remove_space.patch
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()
5
6 From: zhangyi (F) <yi.zhang@huawei.com>
7
8 commit 5e86bdda41534e17621d5a071b294943cae4376e upstream.
9
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
15 end of the function.
16
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>
22
23 ---
24 fs/ext4/indirect.c | 47 ++++++++++++++++++++++-------------------------
25 1 file changed, 22 insertions(+), 25 deletions(-)
26
27 --- a/fs/ext4/indirect.c
28 +++ b/fs/ext4/indirect.c
29 @@ -1219,6 +1219,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;
36 int n = 0, n2 = 0;
37 @@ -1260,7 +1261,7 @@ int ext4_ind_remove_space(handle_t *hand
38 }
39
40
41 - partial = ext4_find_shared(inode, n, offsets, chain, &nr);
42 + partial = p = ext4_find_shared(inode, n, offsets, chain, &nr);
43 if (nr) {
44 if (partial == chain) {
45 /* Shared branch grows from the inode */
46 @@ -1285,13 +1286,11 @@ int ext4_ind_remove_space(handle_t *hand
47 partial->p + 1,
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);
52 partial--;
53 }
54
55 end_range:
56 - partial2 = ext4_find_shared(inode, n2, offsets2, chain2, &nr2);
57 + partial2 = p2 = ext4_find_shared(inode, n2, offsets2, chain2, &nr2);
58 if (nr2) {
59 if (partial2 == chain2) {
60 /*
61 @@ -1321,16 +1320,14 @@ end_range:
62 (__le32 *)partial2->bh->b_data,
63 partial2->p,
64 (chain2+n2-1) - partial2);
65 - BUFFER_TRACE(partial2->bh, "call brelse");
66 - brelse(partial2->bh);
67 partial2--;
68 }
69 goto do_indirects;
70 }
71
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);
77
78 /* Free top, but only if partial2 isn't its subtree. */
79 if (nr) {
80 @@ -1387,15 +1384,7 @@ end_range:
81 partial->p + 1,
82 partial2->p,
83 (chain+n-1) - partial);
84 - while (partial > chain) {
85 - BUFFER_TRACE(partial->bh, "call brelse");
86 - brelse(partial->bh);
87 - }
88 - while (partial2 > chain2) {
89 - BUFFER_TRACE(partial2->bh, "call brelse");
90 - brelse(partial2->bh);
91 - }
92 - return 0;
93 + goto cleanup;
94 }
95
96 /*
97 @@ -1410,8 +1399,6 @@ end_range:
98 partial->p + 1,
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);
103 partial--;
104 }
105 if (partial2 > chain2 && depth2 <= depth) {
106 @@ -1419,11 +1406,21 @@ end_range:
107 (__le32 *)partial2->bh->b_data,
108 partial2->p,
109 (chain2+n2-1) - partial2);
110 - BUFFER_TRACE(partial2->bh, "call brelse");
111 - brelse(partial2->bh);
112 partial2--;
113 }
114 }
115 +
116 +cleanup:
117 + while (p && p > chain) {
118 + BUFFER_TRACE(p->bh, "call brelse");
119 + brelse(p->bh);
120 + p--;
121 + }
122 + while (p2 && p2 > chain2) {
123 + BUFFER_TRACE(p2->bh, "call brelse");
124 + brelse(p2->bh);
125 + p2--;
126 + }
127 return 0;
128
129 do_indirects:
130 @@ -1431,7 +1428,7 @@ do_indirects:
131 switch (offsets[0]) {
132 default:
133 if (++n >= n2)
134 - return 0;
135 + break;
136 nr = i_data[EXT4_IND_BLOCK];
137 if (nr) {
138 ext4_free_branches(handle, inode, NULL, &nr, &nr+1, 1);
139 @@ -1439,7 +1436,7 @@ do_indirects:
140 }
141 case EXT4_IND_BLOCK:
142 if (++n >= n2)
143 - return 0;
144 + break;
145 nr = i_data[EXT4_DIND_BLOCK];
146 if (nr) {
147 ext4_free_branches(handle, inode, NULL, &nr, &nr+1, 2);
148 @@ -1447,7 +1444,7 @@ do_indirects:
149 }
150 case EXT4_DIND_BLOCK:
151 if (++n >= n2)
152 - return 0;
153 + break;
154 nr = i_data[EXT4_TIND_BLOCK];
155 if (nr) {
156 ext4_free_branches(handle, inode, NULL, &nr, &nr+1, 3);
157 @@ -1456,5 +1453,5 @@ do_indirects:
158 case EXT4_TIND_BLOCK:
159 ;
160 }
161 - return 0;
162 + goto cleanup;
163 }