diff options
Diffstat (limited to 'fs/reiserfs/bitmap.c')
-rw-r--r-- | fs/reiserfs/bitmap.c | 111 |
1 files changed, 59 insertions, 52 deletions
diff --git a/fs/reiserfs/bitmap.c b/fs/reiserfs/bitmap.c index 2a5dd34649b3..16b331dd9913 100644 --- a/fs/reiserfs/bitmap.c +++ b/fs/reiserfs/bitmap.c | |||
@@ -47,7 +47,9 @@ | |||
47 | test_bit(_ALLOC_ ## optname , &SB_ALLOC_OPTS(s)) | 47 | test_bit(_ALLOC_ ## optname , &SB_ALLOC_OPTS(s)) |
48 | 48 | ||
49 | static inline void get_bit_address(struct super_block *s, | 49 | static inline void get_bit_address(struct super_block *s, |
50 | b_blocknr_t block, int *bmap_nr, int *offset) | 50 | b_blocknr_t block, |
51 | unsigned int *bmap_nr, | ||
52 | unsigned int *offset) | ||
51 | { | 53 | { |
52 | /* It is in the bitmap block number equal to the block | 54 | /* It is in the bitmap block number equal to the block |
53 | * number divided by the number of bits in a block. */ | 55 | * number divided by the number of bits in a block. */ |
@@ -56,10 +58,10 @@ static inline void get_bit_address(struct super_block *s, | |||
56 | *offset = block & ((s->s_blocksize << 3) - 1); | 58 | *offset = block & ((s->s_blocksize << 3) - 1); |
57 | } | 59 | } |
58 | 60 | ||
59 | #ifdef CONFIG_REISERFS_CHECK | ||
60 | int is_reusable(struct super_block *s, b_blocknr_t block, int bit_value) | 61 | int is_reusable(struct super_block *s, b_blocknr_t block, int bit_value) |
61 | { | 62 | { |
62 | int bmap, offset; | 63 | unsigned int bmap, offset; |
64 | unsigned int bmap_count = reiserfs_bmap_count(s); | ||
63 | 65 | ||
64 | if (block == 0 || block >= SB_BLOCK_COUNT(s)) { | 66 | if (block == 0 || block >= SB_BLOCK_COUNT(s)) { |
65 | reiserfs_warning(s, | 67 | reiserfs_warning(s, |
@@ -75,25 +77,26 @@ int is_reusable(struct super_block *s, b_blocknr_t block, int bit_value) | |||
75 | if (unlikely(test_bit(REISERFS_OLD_FORMAT, | 77 | if (unlikely(test_bit(REISERFS_OLD_FORMAT, |
76 | &(REISERFS_SB(s)->s_properties)))) { | 78 | &(REISERFS_SB(s)->s_properties)))) { |
77 | b_blocknr_t bmap1 = REISERFS_SB(s)->s_sbh->b_blocknr + 1; | 79 | b_blocknr_t bmap1 = REISERFS_SB(s)->s_sbh->b_blocknr + 1; |
78 | if (block >= bmap1 && block <= bmap1 + SB_BMAP_NR(s)) { | 80 | if (block >= bmap1 && |
81 | block <= bmap1 + bmap_count) { | ||
79 | reiserfs_warning(s, "vs: 4019: is_reusable: " | 82 | reiserfs_warning(s, "vs: 4019: is_reusable: " |
80 | "bitmap block %lu(%u) can't be freed or reused", | 83 | "bitmap block %lu(%u) can't be freed or reused", |
81 | block, SB_BMAP_NR(s)); | 84 | block, bmap_count); |
82 | return 0; | 85 | return 0; |
83 | } | 86 | } |
84 | } else { | 87 | } else { |
85 | if (offset == 0) { | 88 | if (offset == 0) { |
86 | reiserfs_warning(s, "vs: 4020: is_reusable: " | 89 | reiserfs_warning(s, "vs: 4020: is_reusable: " |
87 | "bitmap block %lu(%u) can't be freed or reused", | 90 | "bitmap block %lu(%u) can't be freed or reused", |
88 | block, SB_BMAP_NR(s)); | 91 | block, bmap_count); |
89 | return 0; | 92 | return 0; |
90 | } | 93 | } |
91 | } | 94 | } |
92 | 95 | ||
93 | if (bmap >= SB_BMAP_NR(s)) { | 96 | if (bmap >= bmap_count) { |
94 | reiserfs_warning(s, | 97 | reiserfs_warning(s, |
95 | "vs-4030: is_reusable: there is no so many bitmap blocks: " | 98 | "vs-4030: is_reusable: there is no so many bitmap blocks: " |
96 | "block=%lu, bitmap_nr=%d", block, bmap); | 99 | "block=%lu, bitmap_nr=%u", block, bmap); |
97 | return 0; | 100 | return 0; |
98 | } | 101 | } |
99 | 102 | ||
@@ -106,12 +109,11 @@ int is_reusable(struct super_block *s, b_blocknr_t block, int bit_value) | |||
106 | 109 | ||
107 | return 1; | 110 | return 1; |
108 | } | 111 | } |
109 | #endif /* CONFIG_REISERFS_CHECK */ | ||
110 | 112 | ||
111 | /* searches in journal structures for a given block number (bmap, off). If block | 113 | /* searches in journal structures for a given block number (bmap, off). If block |
112 | is found in reiserfs journal it suggests next free block candidate to test. */ | 114 | is found in reiserfs journal it suggests next free block candidate to test. */ |
113 | static inline int is_block_in_journal(struct super_block *s, int bmap, int | 115 | static inline int is_block_in_journal(struct super_block *s, unsigned int bmap, |
114 | off, int *next) | 116 | int off, int *next) |
115 | { | 117 | { |
116 | b_blocknr_t tmp; | 118 | b_blocknr_t tmp; |
117 | 119 | ||
@@ -132,8 +134,8 @@ static inline int is_block_in_journal(struct super_block *s, int bmap, int | |||
132 | /* it searches for a window of zero bits with given minimum and maximum lengths in one bitmap | 134 | /* it searches for a window of zero bits with given minimum and maximum lengths in one bitmap |
133 | * block; */ | 135 | * block; */ |
134 | static int scan_bitmap_block(struct reiserfs_transaction_handle *th, | 136 | static int scan_bitmap_block(struct reiserfs_transaction_handle *th, |
135 | int bmap_n, int *beg, int boundary, int min, | 137 | unsigned int bmap_n, int *beg, int boundary, |
136 | int max, int unfm) | 138 | int min, int max, int unfm) |
137 | { | 139 | { |
138 | struct super_block *s = th->t_super; | 140 | struct super_block *s = th->t_super; |
139 | struct reiserfs_bitmap_info *bi = &SB_AP_BITMAP(s)[bmap_n]; | 141 | struct reiserfs_bitmap_info *bi = &SB_AP_BITMAP(s)[bmap_n]; |
@@ -143,8 +145,8 @@ static int scan_bitmap_block(struct reiserfs_transaction_handle *th, | |||
143 | 145 | ||
144 | BUG_ON(!th->t_trans_id); | 146 | BUG_ON(!th->t_trans_id); |
145 | 147 | ||
146 | RFALSE(bmap_n >= SB_BMAP_NR(s), "Bitmap %d is out of range (0..%d)", | 148 | RFALSE(bmap_n >= reiserfs_bmap_count(s), "Bitmap %u is out of " |
147 | bmap_n, SB_BMAP_NR(s) - 1); | 149 | "range (0..%u)", bmap_n, reiserfs_bmap_count(s) - 1); |
148 | PROC_INFO_INC(s, scan_bitmap.bmap); | 150 | PROC_INFO_INC(s, scan_bitmap.bmap); |
149 | /* this is unclear and lacks comments, explain how journal bitmaps | 151 | /* this is unclear and lacks comments, explain how journal bitmaps |
150 | work here for the reader. Convey a sense of the design here. What | 152 | work here for the reader. Convey a sense of the design here. What |
@@ -249,12 +251,12 @@ static int bmap_hash_id(struct super_block *s, u32 id) | |||
249 | } else { | 251 | } else { |
250 | hash_in = (char *)(&id); | 252 | hash_in = (char *)(&id); |
251 | hash = keyed_hash(hash_in, 4); | 253 | hash = keyed_hash(hash_in, 4); |
252 | bm = hash % SB_BMAP_NR(s); | 254 | bm = hash % reiserfs_bmap_count(s); |
253 | if (!bm) | 255 | if (!bm) |
254 | bm = 1; | 256 | bm = 1; |
255 | } | 257 | } |
256 | /* this can only be true when SB_BMAP_NR = 1 */ | 258 | /* this can only be true when SB_BMAP_NR = 1 */ |
257 | if (bm >= SB_BMAP_NR(s)) | 259 | if (bm >= reiserfs_bmap_count(s)) |
258 | bm = 0; | 260 | bm = 0; |
259 | return bm; | 261 | return bm; |
260 | } | 262 | } |
@@ -273,7 +275,7 @@ static inline int block_group_used(struct super_block *s, u32 id) | |||
273 | * to make a better decision. This favors long-term performace gain | 275 | * to make a better decision. This favors long-term performace gain |
274 | * with a better on-disk layout vs. a short term gain of skipping the | 276 | * with a better on-disk layout vs. a short term gain of skipping the |
275 | * read and potentially having a bad placement. */ | 277 | * read and potentially having a bad placement. */ |
276 | if (info->first_zero_hint == 0) { | 278 | if (info->free_count == UINT_MAX) { |
277 | struct buffer_head *bh = reiserfs_read_bitmap_block(s, bm); | 279 | struct buffer_head *bh = reiserfs_read_bitmap_block(s, bm); |
278 | brelse(bh); | 280 | brelse(bh); |
279 | } | 281 | } |
@@ -309,16 +311,16 @@ __le32 reiserfs_choose_packing(struct inode * dir) | |||
309 | * bitmap and place new blocks there. Returns number of allocated blocks. */ | 311 | * bitmap and place new blocks there. Returns number of allocated blocks. */ |
310 | static int scan_bitmap(struct reiserfs_transaction_handle *th, | 312 | static int scan_bitmap(struct reiserfs_transaction_handle *th, |
311 | b_blocknr_t * start, b_blocknr_t finish, | 313 | b_blocknr_t * start, b_blocknr_t finish, |
312 | int min, int max, int unfm, unsigned long file_block) | 314 | int min, int max, int unfm, sector_t file_block) |
313 | { | 315 | { |
314 | int nr_allocated = 0; | 316 | int nr_allocated = 0; |
315 | struct super_block *s = th->t_super; | 317 | struct super_block *s = th->t_super; |
316 | /* find every bm and bmap and bmap_nr in this file, and change them all to bitmap_blocknr | 318 | /* find every bm and bmap and bmap_nr in this file, and change them all to bitmap_blocknr |
317 | * - Hans, it is not a block number - Zam. */ | 319 | * - Hans, it is not a block number - Zam. */ |
318 | 320 | ||
319 | int bm, off; | 321 | unsigned int bm, off; |
320 | int end_bm, end_off; | 322 | unsigned int end_bm, end_off; |
321 | int off_max = s->s_blocksize << 3; | 323 | unsigned int off_max = s->s_blocksize << 3; |
322 | 324 | ||
323 | BUG_ON(!th->t_trans_id); | 325 | BUG_ON(!th->t_trans_id); |
324 | 326 | ||
@@ -328,10 +330,10 @@ static int scan_bitmap(struct reiserfs_transaction_handle *th, | |||
328 | 330 | ||
329 | get_bit_address(s, *start, &bm, &off); | 331 | get_bit_address(s, *start, &bm, &off); |
330 | get_bit_address(s, finish, &end_bm, &end_off); | 332 | get_bit_address(s, finish, &end_bm, &end_off); |
331 | if (bm > SB_BMAP_NR(s)) | 333 | if (bm > reiserfs_bmap_count(s)) |
332 | return 0; | 334 | return 0; |
333 | if (end_bm > SB_BMAP_NR(s)) | 335 | if (end_bm > reiserfs_bmap_count(s)) |
334 | end_bm = SB_BMAP_NR(s); | 336 | end_bm = reiserfs_bmap_count(s); |
335 | 337 | ||
336 | /* When the bitmap is more than 10% free, anyone can allocate. | 338 | /* When the bitmap is more than 10% free, anyone can allocate. |
337 | * When it's less than 10% free, only files that already use the | 339 | * When it's less than 10% free, only files that already use the |
@@ -385,7 +387,7 @@ static void _reiserfs_free_block(struct reiserfs_transaction_handle *th, | |||
385 | struct reiserfs_super_block *rs; | 387 | struct reiserfs_super_block *rs; |
386 | struct buffer_head *sbh, *bmbh; | 388 | struct buffer_head *sbh, *bmbh; |
387 | struct reiserfs_bitmap_info *apbi; | 389 | struct reiserfs_bitmap_info *apbi; |
388 | int nr, offset; | 390 | unsigned int nr, offset; |
389 | 391 | ||
390 | BUG_ON(!th->t_trans_id); | 392 | BUG_ON(!th->t_trans_id); |
391 | 393 | ||
@@ -397,10 +399,12 @@ static void _reiserfs_free_block(struct reiserfs_transaction_handle *th, | |||
397 | 399 | ||
398 | get_bit_address(s, block, &nr, &offset); | 400 | get_bit_address(s, block, &nr, &offset); |
399 | 401 | ||
400 | if (nr >= sb_bmap_nr(rs)) { | 402 | if (nr >= reiserfs_bmap_count(s)) { |
401 | reiserfs_warning(s, "vs-4075: reiserfs_free_block: " | 403 | reiserfs_warning(s, "vs-4075: reiserfs_free_block: " |
402 | "block %lu is out of range on %s", | 404 | "block %lu is out of range on %s " |
403 | block, reiserfs_bdevname(s)); | 405 | "(nr=%u,max=%u)", block, |
406 | reiserfs_bdevname(s), nr, | ||
407 | reiserfs_bmap_count(s)); | ||
404 | return; | 408 | return; |
405 | } | 409 | } |
406 | 410 | ||
@@ -434,12 +438,19 @@ void reiserfs_free_block(struct reiserfs_transaction_handle *th, | |||
434 | int for_unformatted) | 438 | int for_unformatted) |
435 | { | 439 | { |
436 | struct super_block *s = th->t_super; | 440 | struct super_block *s = th->t_super; |
437 | |||
438 | BUG_ON(!th->t_trans_id); | 441 | BUG_ON(!th->t_trans_id); |
439 | 442 | ||
440 | RFALSE(!s, "vs-4061: trying to free block on nonexistent device"); | 443 | RFALSE(!s, "vs-4061: trying to free block on nonexistent device"); |
441 | RFALSE(is_reusable(s, block, 1) == 0, | 444 | if (!is_reusable(s, block, 1)) |
442 | "vs-4071: can not free such block"); | 445 | return; |
446 | |||
447 | if (block > sb_block_count(REISERFS_SB(s)->s_rs)) { | ||
448 | reiserfs_panic(th->t_super, "bitmap-4072", | ||
449 | "Trying to free block outside file system " | ||
450 | "boundaries (%lu > %lu)", | ||
451 | block, sb_block_count(REISERFS_SB(s)->s_rs)); | ||
452 | return; | ||
453 | } | ||
443 | /* mark it before we clear it, just in case */ | 454 | /* mark it before we clear it, just in case */ |
444 | journal_mark_freed(th, s, block); | 455 | journal_mark_freed(th, s, block); |
445 | _reiserfs_free_block(th, inode, block, for_unformatted); | 456 | _reiserfs_free_block(th, inode, block, for_unformatted); |
@@ -449,11 +460,11 @@ void reiserfs_free_block(struct reiserfs_transaction_handle *th, | |||
449 | static void reiserfs_free_prealloc_block(struct reiserfs_transaction_handle *th, | 460 | static void reiserfs_free_prealloc_block(struct reiserfs_transaction_handle *th, |
450 | struct inode *inode, b_blocknr_t block) | 461 | struct inode *inode, b_blocknr_t block) |
451 | { | 462 | { |
463 | BUG_ON(!th->t_trans_id); | ||
452 | RFALSE(!th->t_super, | 464 | RFALSE(!th->t_super, |
453 | "vs-4060: trying to free block on nonexistent device"); | 465 | "vs-4060: trying to free block on nonexistent device"); |
454 | RFALSE(is_reusable(th->t_super, block, 1) == 0, | 466 | if (!is_reusable(th->t_super, block, 1)) |
455 | "vs-4070: can not free such block"); | 467 | return; |
456 | BUG_ON(!th->t_trans_id); | ||
457 | _reiserfs_free_block(th, inode, block, 1); | 468 | _reiserfs_free_block(th, inode, block, 1); |
458 | } | 469 | } |
459 | 470 | ||
@@ -1207,27 +1218,22 @@ void reiserfs_cache_bitmap_metadata(struct super_block *sb, | |||
1207 | { | 1218 | { |
1208 | unsigned long *cur = (unsigned long *)(bh->b_data + bh->b_size); | 1219 | unsigned long *cur = (unsigned long *)(bh->b_data + bh->b_size); |
1209 | 1220 | ||
1210 | info->first_zero_hint = 1 << (sb->s_blocksize_bits + 3); | 1221 | /* The first bit must ALWAYS be 1 */ |
1222 | BUG_ON(!reiserfs_test_le_bit(0, (unsigned long *)bh->b_data)); | ||
1223 | |||
1224 | info->free_count = 0; | ||
1211 | 1225 | ||
1212 | while (--cur >= (unsigned long *)bh->b_data) { | 1226 | while (--cur >= (unsigned long *)bh->b_data) { |
1213 | int base = ((char *)cur - bh->b_data) << 3; | 1227 | int i; |
1214 | 1228 | ||
1215 | /* 0 and ~0 are special, we can optimize for them */ | 1229 | /* 0 and ~0 are special, we can optimize for them */ |
1216 | if (*cur == 0) { | 1230 | if (*cur == 0) |
1217 | info->first_zero_hint = base; | ||
1218 | info->free_count += BITS_PER_LONG; | 1231 | info->free_count += BITS_PER_LONG; |
1219 | } else if (*cur != ~0L) { /* A mix, investigate */ | 1232 | else if (*cur != ~0L) /* A mix, investigate */ |
1220 | int b; | 1233 | for (i = BITS_PER_LONG - 1; i >= 0; i--) |
1221 | for (b = BITS_PER_LONG - 1; b >= 0; b--) { | 1234 | if (!reiserfs_test_le_bit(i, cur)) |
1222 | if (!reiserfs_test_le_bit(b, cur)) { | ||
1223 | info->first_zero_hint = base + b; | ||
1224 | info->free_count++; | 1235 | info->free_count++; |
1225 | } | ||
1226 | } | ||
1227 | } | ||
1228 | } | 1236 | } |
1229 | /* The first bit must ALWAYS be 1 */ | ||
1230 | BUG_ON(info->first_zero_hint == 0); | ||
1231 | } | 1237 | } |
1232 | 1238 | ||
1233 | struct buffer_head *reiserfs_read_bitmap_block(struct super_block *sb, | 1239 | struct buffer_head *reiserfs_read_bitmap_block(struct super_block *sb, |
@@ -1257,7 +1263,7 @@ struct buffer_head *reiserfs_read_bitmap_block(struct super_block *sb, | |||
1257 | BUG_ON(!buffer_uptodate(bh)); | 1263 | BUG_ON(!buffer_uptodate(bh)); |
1258 | BUG_ON(atomic_read(&bh->b_count) == 0); | 1264 | BUG_ON(atomic_read(&bh->b_count) == 0); |
1259 | 1265 | ||
1260 | if (info->first_zero_hint == 0) | 1266 | if (info->free_count == UINT_MAX) |
1261 | reiserfs_cache_bitmap_metadata(sb, bh, info); | 1267 | reiserfs_cache_bitmap_metadata(sb, bh, info); |
1262 | } | 1268 | } |
1263 | 1269 | ||
@@ -1267,12 +1273,13 @@ struct buffer_head *reiserfs_read_bitmap_block(struct super_block *sb, | |||
1267 | int reiserfs_init_bitmap_cache(struct super_block *sb) | 1273 | int reiserfs_init_bitmap_cache(struct super_block *sb) |
1268 | { | 1274 | { |
1269 | struct reiserfs_bitmap_info *bitmap; | 1275 | struct reiserfs_bitmap_info *bitmap; |
1276 | unsigned int bmap_nr = reiserfs_bmap_count(sb); | ||
1270 | 1277 | ||
1271 | bitmap = vmalloc(sizeof (*bitmap) * SB_BMAP_NR(sb)); | 1278 | bitmap = vmalloc(sizeof(*bitmap) * bmap_nr); |
1272 | if (bitmap == NULL) | 1279 | if (bitmap == NULL) |
1273 | return -ENOMEM; | 1280 | return -ENOMEM; |
1274 | 1281 | ||
1275 | memset(bitmap, 0, sizeof (*bitmap) * SB_BMAP_NR(sb)); | 1282 | memset(bitmap, 0xff, sizeof(*bitmap) * bmap_nr); |
1276 | 1283 | ||
1277 | SB_AP_BITMAP(sb) = bitmap; | 1284 | SB_AP_BITMAP(sb) = bitmap; |
1278 | 1285 | ||