Skip to content

Commit 0b3dc17

Browse files
jeffmahoneyLinus Torvalds
authored andcommitted
[PATCH] reiserfs: clean up bitmap block buffer head references
Similar to the SB_JOURNAL cleanup that was accepted a while ago, this patch uses a temporary variable for buffer head references from the bitmap info array. This makes the code much more readable in some areas. It also uses proper reference counting, doing a get_bh() after using the pointer from the array and brelse()'ing it later. This may seem silly, but a later patch will replace the simple temporary variables with an actual read, so the reference freeing will be used then. Signed-off-by: Jeff Mahoney <jeffm@suse.com> Cc: <reiserfs-dev@namesys.com> Signed-off-by: Andrew Morton <akpm@osdl.org> Signed-off-by: Linus Torvalds <torvalds@osdl.org>
1 parent e1fabd3 commit 0b3dc17

2 files changed

Lines changed: 71 additions & 49 deletions

File tree

‎fs/reiserfs/bitmap.c‎

Lines changed: 36 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ static inline void get_bit_address(struct super_block *s,
5959
int is_reusable(struct super_block *s, b_blocknr_t block, int bit_value)
6060
{
6161
int bmap, offset;
62+
struct buffer_head *bh;
6263

6364
if (block == 0 || block >= SB_BLOCK_COUNT(s)) {
6465
reiserfs_warning(s,
@@ -96,20 +97,21 @@ int is_reusable(struct super_block *s, b_blocknr_t block, int bit_value)
9697
return 0;
9798
}
9899

99-
if ((bit_value == 0 &&
100-
reiserfs_test_le_bit(offset, SB_AP_BITMAP(s)[bmap].bh->b_data)) ||
101-
(bit_value == 1 &&
102-
reiserfs_test_le_bit(offset, SB_AP_BITMAP(s)[bmap].bh->b_data) == 0)) {
100+
bh = SB_AP_BITMAP(s)[bmap].bh;
101+
get_bh(bh);
102+
103+
if ((bit_value == 0 && reiserfs_test_le_bit(offset, bh->b_data)) ||
104+
(bit_value == 1 && reiserfs_test_le_bit(offset, bh->b_data) == 0)) {
103105
reiserfs_warning(s,
104106
"vs-4040: is_reusable: corresponding bit of block %lu does not "
105107
"match required value (bmap==%d, offset==%d) test_bit==%d",
106-
block, bmap, offset, reiserfs_test_le_bit(offset,
107-
SB_AP_BITMAP
108-
(s)[bmap].bh->
109-
b_data));
108+
block, bmap, offset,
109+
reiserfs_test_le_bit(offset, bh->b_data));
110110

111+
brelse(bh);
111112
return 0;
112113
}
114+
brelse(bh);
113115

114116
if (bit_value == 0 && block == SB_ROOT_BLOCK(s)) {
115117
reiserfs_warning(s,
@@ -151,6 +153,7 @@ static int scan_bitmap_block(struct reiserfs_transaction_handle *th,
151153
{
152154
struct super_block *s = th->t_super;
153155
struct reiserfs_bitmap_info *bi = &SB_AP_BITMAP(s)[bmap_n];
156+
struct buffer_head *bh;
154157
int end, next;
155158
int org = *beg;
156159

@@ -169,22 +172,28 @@ static int scan_bitmap_block(struct reiserfs_transaction_handle *th,
169172
bmap_n);
170173
return 0;
171174
}
172-
if (buffer_locked(bi->bh)) {
175+
bh = bi->bh;
176+
get_bh(bh);
177+
178+
if (buffer_locked(bh)) {
173179
PROC_INFO_INC(s, scan_bitmap.wait);
174-
__wait_on_buffer(bi->bh);
180+
__wait_on_buffer(bh);
175181
}
176182

177183
while (1) {
178184
cont:
179-
if (bi->free_count < min)
185+
if (bi->free_count < min) {
186+
brelse(bh);
180187
return 0; // No free blocks in this bitmap
188+
}
181189

182190
/* search for a first zero bit -- beggining of a window */
183191
*beg = reiserfs_find_next_zero_le_bit
184-
((unsigned long *)(bi->bh->b_data), boundary, *beg);
192+
((unsigned long *)(bh->b_data), boundary, *beg);
185193

186194
if (*beg + min > boundary) { /* search for a zero bit fails or the rest of bitmap block
187195
* cannot contain a zero window of minimum size */
196+
brelse(bh);
188197
return 0;
189198
}
190199

@@ -193,7 +202,7 @@ static int scan_bitmap_block(struct reiserfs_transaction_handle *th,
193202
/* first zero bit found; we check next bits */
194203
for (end = *beg + 1;; end++) {
195204
if (end >= *beg + max || end >= boundary
196-
|| reiserfs_test_le_bit(end, bi->bh->b_data)) {
205+
|| reiserfs_test_le_bit(end, bh->b_data)) {
197206
next = end;
198207
break;
199208
}
@@ -207,12 +216,12 @@ static int scan_bitmap_block(struct reiserfs_transaction_handle *th,
207216
* (end) points to one bit after the window end */
208217
if (end - *beg >= min) { /* it seems we have found window of proper size */
209218
int i;
210-
reiserfs_prepare_for_journal(s, bi->bh, 1);
219+
reiserfs_prepare_for_journal(s, bh, 1);
211220
/* try to set all blocks used checking are they still free */
212221
for (i = *beg; i < end; i++) {
213222
/* It seems that we should not check in journal again. */
214223
if (reiserfs_test_and_set_le_bit
215-
(i, bi->bh->b_data)) {
224+
(i, bh->b_data)) {
216225
/* bit was set by another process
217226
* while we slept in prepare_for_journal() */
218227
PROC_INFO_INC(s, scan_bitmap.stolen);
@@ -224,17 +233,16 @@ static int scan_bitmap_block(struct reiserfs_transaction_handle *th,
224233
/* otherwise we clear all bit were set ... */
225234
while (--i >= *beg)
226235
reiserfs_test_and_clear_le_bit
227-
(i, bi->bh->b_data);
228-
reiserfs_restore_prepared_buffer(s,
229-
bi->
230-
bh);
236+
(i, bh->b_data);
237+
reiserfs_restore_prepared_buffer(s, bh);
231238
*beg = org;
232239
/* ... and search again in current block from beginning */
233240
goto cont;
234241
}
235242
}
236243
bi->free_count -= (end - *beg);
237-
journal_mark_dirty(th, s, bi->bh);
244+
journal_mark_dirty(th, s, bh);
245+
brelse(bh);
238246

239247
/* free block count calculation */
240248
reiserfs_prepare_for_journal(s, SB_BUFFER_WITH_SB(s),
@@ -383,7 +391,7 @@ static void _reiserfs_free_block(struct reiserfs_transaction_handle *th,
383391
{
384392
struct super_block *s = th->t_super;
385393
struct reiserfs_super_block *rs;
386-
struct buffer_head *sbh;
394+
struct buffer_head *sbh, *bmbh;
387395
struct reiserfs_bitmap_info *apbi;
388396
int nr, offset;
389397

@@ -404,16 +412,20 @@ static void _reiserfs_free_block(struct reiserfs_transaction_handle *th,
404412
return;
405413
}
406414

407-
reiserfs_prepare_for_journal(s, apbi[nr].bh, 1);
415+
bmbh = apbi[nr].bh;
416+
get_bh(bmbh);
417+
418+
reiserfs_prepare_for_journal(s, bmbh, 1);
408419

409420
/* clear bit for the given block in bit map */
410-
if (!reiserfs_test_and_clear_le_bit(offset, apbi[nr].bh->b_data)) {
421+
if (!reiserfs_test_and_clear_le_bit(offset, bmbh->b_data)) {
411422
reiserfs_warning(s, "vs-4080: reiserfs_free_block: "
412423
"free_block (%s:%lu)[dev:blocknr]: bit already cleared",
413424
reiserfs_bdevname(s), block);
414425
}
415426
apbi[nr].free_count++;
416-
journal_mark_dirty(th, s, apbi[nr].bh);
427+
journal_mark_dirty(th, s, bmbh);
428+
brelse(bmbh);
417429

418430
reiserfs_prepare_for_journal(s, sbh, 1);
419431
/* update super block */

‎fs/reiserfs/resize.c‎

Lines changed: 35 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ int reiserfs_resize(struct super_block *s, unsigned long block_count_new)
2222
int err = 0;
2323
struct reiserfs_super_block *sb;
2424
struct reiserfs_bitmap_info *bitmap;
25+
struct reiserfs_bitmap_info *info;
2526
struct reiserfs_bitmap_info *old_bitmap = SB_AP_BITMAP(s);
2627
struct buffer_head *bh;
2728
struct reiserfs_transaction_handle th;
@@ -127,16 +128,19 @@ int reiserfs_resize(struct super_block *s, unsigned long block_count_new)
127128
* transaction begins, and the new bitmaps don't matter if the
128129
* transaction fails. */
129130
for (i = bmap_nr; i < bmap_nr_new; i++) {
130-
bitmap[i].bh = sb_getblk(s, i * s->s_blocksize * 8);
131-
memset(bitmap[i].bh->b_data, 0, sb_blocksize(sb));
132-
reiserfs_test_and_set_le_bit(0, bitmap[i].bh->b_data);
133-
134-
set_buffer_uptodate(bitmap[i].bh);
135-
mark_buffer_dirty(bitmap[i].bh);
136-
sync_dirty_buffer(bitmap[i].bh);
131+
bh = sb_getblk(s, i * s->s_blocksize * 8);
132+
get_bh(bh);
133+
memset(bh->b_data, 0, sb_blocksize(sb));
134+
reiserfs_test_and_set_le_bit(0, bh->b_data);
135+
136+
set_buffer_uptodate(bh);
137+
mark_buffer_dirty(bh);
138+
sync_dirty_buffer(bh);
137139
// update bitmap_info stuff
138140
bitmap[i].first_zero_hint = 1;
139141
bitmap[i].free_count = sb_blocksize(sb) * 8 - 1;
142+
bitmap[i].bh = bh;
143+
brelse(bh);
140144
}
141145
/* free old bitmap blocks array */
142146
SB_AP_BITMAP(s) = bitmap;
@@ -150,30 +154,36 @@ int reiserfs_resize(struct super_block *s, unsigned long block_count_new)
150154
if (err)
151155
return err;
152156

153-
/* correct last bitmap blocks in old and new disk layout */
154-
reiserfs_prepare_for_journal(s, SB_AP_BITMAP(s)[bmap_nr - 1].bh, 1);
157+
/* Extend old last bitmap block - new blocks have been made available */
158+
info = SB_AP_BITMAP(s) + bmap_nr - 1;
159+
bh = info->bh;
160+
get_bh(bh);
161+
162+
reiserfs_prepare_for_journal(s, bh, 1);
155163
for (i = block_r; i < s->s_blocksize * 8; i++)
156-
reiserfs_test_and_clear_le_bit(i,
157-
SB_AP_BITMAP(s)[bmap_nr -
158-
1].bh->b_data);
159-
SB_AP_BITMAP(s)[bmap_nr - 1].free_count += s->s_blocksize * 8 - block_r;
160-
if (!SB_AP_BITMAP(s)[bmap_nr - 1].first_zero_hint)
161-
SB_AP_BITMAP(s)[bmap_nr - 1].first_zero_hint = block_r;
164+
reiserfs_test_and_clear_le_bit(i, bh->b_data);
165+
info->free_count += s->s_blocksize * 8 - block_r;
166+
if (!info->first_zero_hint)
167+
info->first_zero_hint = block_r;
168+
169+
journal_mark_dirty(&th, s, bh);
170+
brelse(bh);
162171

163-
journal_mark_dirty(&th, s, SB_AP_BITMAP(s)[bmap_nr - 1].bh);
172+
/* Correct new last bitmap block - It may not be full */
173+
info = SB_AP_BITMAP(s) + bmap_nr_new - 1;
174+
bh = info->bh;
175+
get_bh(bh);
164176

165-
reiserfs_prepare_for_journal(s, SB_AP_BITMAP(s)[bmap_nr_new - 1].bh, 1);
177+
reiserfs_prepare_for_journal(s, bh, 1);
166178
for (i = block_r_new; i < s->s_blocksize * 8; i++)
167-
reiserfs_test_and_set_le_bit(i,
168-
SB_AP_BITMAP(s)[bmap_nr_new -
169-
1].bh->b_data);
170-
journal_mark_dirty(&th, s, SB_AP_BITMAP(s)[bmap_nr_new - 1].bh);
179+
reiserfs_test_and_set_le_bit(i, bh->b_data);
180+
journal_mark_dirty(&th, s, bh);
181+
brelse(bh);
171182

172-
SB_AP_BITMAP(s)[bmap_nr_new - 1].free_count -=
173-
s->s_blocksize * 8 - block_r_new;
183+
info->free_count -= s->s_blocksize * 8 - block_r_new;
174184
/* Extreme case where last bitmap is the only valid block in itself. */
175-
if (!SB_AP_BITMAP(s)[bmap_nr_new - 1].free_count)
176-
SB_AP_BITMAP(s)[bmap_nr_new - 1].first_zero_hint = 0;
185+
if (!info->free_count)
186+
info->first_zero_hint = 0;
177187
/* update super */
178188
reiserfs_prepare_for_journal(s, SB_BUFFER_WITH_SB(s), 1);
179189
free_blocks = SB_FREE_BLOCKS(s);

0 commit comments

Comments
 (0)