@@ -59,6 +59,7 @@ static inline void get_bit_address(struct super_block *s,
5959int 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 */
0 commit comments