aboutsummaryrefslogtreecommitdiffstats
path: root/fs/reiserfs
diff options
context:
space:
mode:
Diffstat (limited to 'fs/reiserfs')
-rw-r--r--fs/reiserfs/bitmap.c111
-rw-r--r--fs/reiserfs/inode.c8
-rw-r--r--fs/reiserfs/journal.c24
-rw-r--r--fs/reiserfs/prints.c10
-rw-r--r--fs/reiserfs/resize.c15
-rw-r--r--fs/reiserfs/stree.c6
-rw-r--r--fs/reiserfs/super.c15
-rw-r--r--fs/reiserfs/xattr.c5
8 files changed, 106 insertions, 88 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
49static inline void get_bit_address(struct super_block *s, 49static 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
60int is_reusable(struct super_block *s, b_blocknr_t block, int bit_value) 61int 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. */
113static inline int is_block_in_journal(struct super_block *s, int bmap, int 115static 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; */
134static int scan_bitmap_block(struct reiserfs_transaction_handle *th, 136static 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. */
310static int scan_bitmap(struct reiserfs_transaction_handle *th, 312static 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,
449static void reiserfs_free_prealloc_block(struct reiserfs_transaction_handle *th, 460static 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
1233struct buffer_head *reiserfs_read_bitmap_block(struct super_block *sb, 1239struct 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,
1267int reiserfs_init_bitmap_cache(struct super_block *sb) 1273int 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
diff --git a/fs/reiserfs/inode.c b/fs/reiserfs/inode.c
index 0804289d355d..a991af96f3f0 100644
--- a/fs/reiserfs/inode.c
+++ b/fs/reiserfs/inode.c
@@ -199,7 +199,7 @@ static inline void set_block_dev_mapped(struct buffer_head *bh,
199// files which were created in the earlier version can not be longer, 199// files which were created in the earlier version can not be longer,
200// than 2 gb 200// than 2 gb
201// 201//
202static int file_capable(struct inode *inode, long block) 202static int file_capable(struct inode *inode, sector_t block)
203{ 203{
204 if (get_inode_item_key_version(inode) != KEY_FORMAT_3_5 || // it is new file. 204 if (get_inode_item_key_version(inode) != KEY_FORMAT_3_5 || // it is new file.
205 block < (1 << (31 - inode->i_sb->s_blocksize_bits))) // old file, but 'block' is inside of 2gb 205 block < (1 << (31 - inode->i_sb->s_blocksize_bits))) // old file, but 'block' is inside of 2gb
@@ -242,7 +242,7 @@ static int restart_transaction(struct reiserfs_transaction_handle *th,
242// Please improve the english/clarity in the comment above, as it is 242// Please improve the english/clarity in the comment above, as it is
243// hard to understand. 243// hard to understand.
244 244
245static int _get_block_create_0(struct inode *inode, long block, 245static int _get_block_create_0(struct inode *inode, sector_t block,
246 struct buffer_head *bh_result, int args) 246 struct buffer_head *bh_result, int args)
247{ 247{
248 INITIALIZE_PATH(path); 248 INITIALIZE_PATH(path);
@@ -250,7 +250,7 @@ static int _get_block_create_0(struct inode *inode, long block,
250 struct buffer_head *bh; 250 struct buffer_head *bh;
251 struct item_head *ih, tmp_ih; 251 struct item_head *ih, tmp_ih;
252 int fs_gen; 252 int fs_gen;
253 int blocknr; 253 b_blocknr_t blocknr;
254 char *p = NULL; 254 char *p = NULL;
255 int chars; 255 int chars;
256 int ret; 256 int ret;
@@ -569,7 +569,7 @@ static int convert_tail_for_hole(struct inode *inode,
569} 569}
570 570
571static inline int _allocate_block(struct reiserfs_transaction_handle *th, 571static inline int _allocate_block(struct reiserfs_transaction_handle *th,
572 long block, 572 sector_t block,
573 struct inode *inode, 573 struct inode *inode,
574 b_blocknr_t * allocated_block_nr, 574 b_blocknr_t * allocated_block_nr,
575 struct treepath *path, int flags) 575 struct treepath *path, int flags)
diff --git a/fs/reiserfs/journal.c b/fs/reiserfs/journal.c
index 4cad9e75ef56..bb05a3e51b93 100644
--- a/fs/reiserfs/journal.c
+++ b/fs/reiserfs/journal.c
@@ -219,11 +219,12 @@ static void allocate_bitmap_nodes(struct super_block *p_s_sb)
219 } 219 }
220} 220}
221 221
222static int set_bit_in_list_bitmap(struct super_block *p_s_sb, int block, 222static int set_bit_in_list_bitmap(struct super_block *p_s_sb,
223 b_blocknr_t block,
223 struct reiserfs_list_bitmap *jb) 224 struct reiserfs_list_bitmap *jb)
224{ 225{
225 int bmap_nr = block / (p_s_sb->s_blocksize << 3); 226 unsigned int bmap_nr = block / (p_s_sb->s_blocksize << 3);
226 int bit_nr = block % (p_s_sb->s_blocksize << 3); 227 unsigned int bit_nr = block % (p_s_sb->s_blocksize << 3);
227 228
228 if (!jb->bitmaps[bmap_nr]) { 229 if (!jb->bitmaps[bmap_nr]) {
229 jb->bitmaps[bmap_nr] = get_bitmap_node(p_s_sb); 230 jb->bitmaps[bmap_nr] = get_bitmap_node(p_s_sb);
@@ -239,7 +240,7 @@ static void cleanup_bitmap_list(struct super_block *p_s_sb,
239 if (jb->bitmaps == NULL) 240 if (jb->bitmaps == NULL)
240 return; 241 return;
241 242
242 for (i = 0; i < SB_BMAP_NR(p_s_sb); i++) { 243 for (i = 0; i < reiserfs_bmap_count(p_s_sb); i++) {
243 if (jb->bitmaps[i]) { 244 if (jb->bitmaps[i]) {
244 free_bitmap_node(p_s_sb, jb->bitmaps[i]); 245 free_bitmap_node(p_s_sb, jb->bitmaps[i]);
245 jb->bitmaps[i] = NULL; 246 jb->bitmaps[i] = NULL;
@@ -289,7 +290,7 @@ static int free_bitmap_nodes(struct super_block *p_s_sb)
289*/ 290*/
290int reiserfs_allocate_list_bitmaps(struct super_block *p_s_sb, 291int reiserfs_allocate_list_bitmaps(struct super_block *p_s_sb,
291 struct reiserfs_list_bitmap *jb_array, 292 struct reiserfs_list_bitmap *jb_array,
292 int bmap_nr) 293 unsigned int bmap_nr)
293{ 294{
294 int i; 295 int i;
295 int failed = 0; 296 int failed = 0;
@@ -483,7 +484,7 @@ static inline struct reiserfs_journal_cnode *get_journal_hash_dev(struct
483** 484**
484*/ 485*/
485int reiserfs_in_journal(struct super_block *p_s_sb, 486int reiserfs_in_journal(struct super_block *p_s_sb,
486 int bmap_nr, int bit_nr, int search_all, 487 unsigned int bmap_nr, int bit_nr, int search_all,
487 b_blocknr_t * next_zero_bit) 488 b_blocknr_t * next_zero_bit)
488{ 489{
489 struct reiserfs_journal *journal = SB_JOURNAL(p_s_sb); 490 struct reiserfs_journal *journal = SB_JOURNAL(p_s_sb);
@@ -1013,7 +1014,7 @@ static int flush_commit_list(struct super_block *s,
1013 struct reiserfs_journal_list *jl, int flushall) 1014 struct reiserfs_journal_list *jl, int flushall)
1014{ 1015{
1015 int i; 1016 int i;
1016 int bn; 1017 b_blocknr_t bn;
1017 struct buffer_head *tbh = NULL; 1018 struct buffer_head *tbh = NULL;
1018 unsigned long trans_id = jl->j_trans_id; 1019 unsigned long trans_id = jl->j_trans_id;
1019 struct reiserfs_journal *journal = SB_JOURNAL(s); 1020 struct reiserfs_journal *journal = SB_JOURNAL(s);
@@ -2307,8 +2308,9 @@ static int journal_read_transaction(struct super_block *p_s_sb,
2307 Right now it is only used from journal code. But later we might use it 2308 Right now it is only used from journal code. But later we might use it
2308 from other places. 2309 from other places.
2309 Note: Do not use journal_getblk/sb_getblk functions here! */ 2310 Note: Do not use journal_getblk/sb_getblk functions here! */
2310static struct buffer_head *reiserfs_breada(struct block_device *dev, int block, 2311static struct buffer_head *reiserfs_breada(struct block_device *dev,
2311 int bufsize, unsigned int max_block) 2312 b_blocknr_t block, int bufsize,
2313 b_blocknr_t max_block)
2312{ 2314{
2313 struct buffer_head *bhlist[BUFNR]; 2315 struct buffer_head *bhlist[BUFNR];
2314 unsigned int blocks = BUFNR; 2316 unsigned int blocks = BUFNR;
@@ -2732,7 +2734,7 @@ int journal_init(struct super_block *p_s_sb, const char *j_dev_name,
2732 journal->j_persistent_trans = 0; 2734 journal->j_persistent_trans = 0;
2733 if (reiserfs_allocate_list_bitmaps(p_s_sb, 2735 if (reiserfs_allocate_list_bitmaps(p_s_sb,
2734 journal->j_list_bitmap, 2736 journal->j_list_bitmap,
2735 SB_BMAP_NR(p_s_sb))) 2737 reiserfs_bmap_count(p_s_sb)))
2736 goto free_and_return; 2738 goto free_and_return;
2737 allocate_bitmap_nodes(p_s_sb); 2739 allocate_bitmap_nodes(p_s_sb);
2738 2740
@@ -2740,7 +2742,7 @@ int journal_init(struct super_block *p_s_sb, const char *j_dev_name,
2740 SB_JOURNAL_1st_RESERVED_BLOCK(p_s_sb) = (old_format ? 2742 SB_JOURNAL_1st_RESERVED_BLOCK(p_s_sb) = (old_format ?
2741 REISERFS_OLD_DISK_OFFSET_IN_BYTES 2743 REISERFS_OLD_DISK_OFFSET_IN_BYTES
2742 / p_s_sb->s_blocksize + 2744 / p_s_sb->s_blocksize +
2743 SB_BMAP_NR(p_s_sb) + 2745 reiserfs_bmap_count(p_s_sb) +
2744 1 : 2746 1 :
2745 REISERFS_DISK_OFFSET_IN_BYTES / 2747 REISERFS_DISK_OFFSET_IN_BYTES /
2746 p_s_sb->s_blocksize + 2); 2748 p_s_sb->s_blocksize + 2);
diff --git a/fs/reiserfs/prints.c b/fs/reiserfs/prints.c
index bc808a91eeaa..5e7388b32d02 100644
--- a/fs/reiserfs/prints.c
+++ b/fs/reiserfs/prints.c
@@ -356,13 +356,11 @@ extern struct tree_balance *cur_tb;
356void reiserfs_panic(struct super_block *sb, const char *fmt, ...) 356void reiserfs_panic(struct super_block *sb, const char *fmt, ...)
357{ 357{
358 do_reiserfs_warning(fmt); 358 do_reiserfs_warning(fmt);
359 printk(KERN_EMERG "REISERFS: panic (device %s): %s\n",
360 reiserfs_bdevname(sb), error_buf);
361 BUG();
362 359
363 /* this is not actually called, but makes reiserfs_panic() "noreturn" */ 360 dump_stack();
364 panic("REISERFS: panic (device %s): %s\n", 361
365 reiserfs_bdevname(sb), error_buf); 362 panic(KERN_EMERG "REISERFS: panic (device %s): %s\n",
363 reiserfs_bdevname(sb), error_buf);
366} 364}
367 365
368void reiserfs_abort(struct super_block *sb, int errno, const char *fmt, ...) 366void reiserfs_abort(struct super_block *sb, int errno, const char *fmt, ...)
diff --git a/fs/reiserfs/resize.c b/fs/reiserfs/resize.c
index 976cc7887a0d..f71c3948edef 100644
--- a/fs/reiserfs/resize.c
+++ b/fs/reiserfs/resize.c
@@ -61,7 +61,8 @@ int reiserfs_resize(struct super_block *s, unsigned long block_count_new)
61 } 61 }
62 62
63 /* count used bits in last bitmap block */ 63 /* count used bits in last bitmap block */
64 block_r = SB_BLOCK_COUNT(s) - (SB_BMAP_NR(s) - 1) * s->s_blocksize * 8; 64 block_r = SB_BLOCK_COUNT(s) -
65 (reiserfs_bmap_count(s) - 1) * s->s_blocksize * 8;
65 66
66 /* count bitmap blocks in new fs */ 67 /* count bitmap blocks in new fs */
67 bmap_nr_new = block_count_new / (s->s_blocksize * 8); 68 bmap_nr_new = block_count_new / (s->s_blocksize * 8);
@@ -73,7 +74,7 @@ int reiserfs_resize(struct super_block *s, unsigned long block_count_new)
73 74
74 /* save old values */ 75 /* save old values */
75 block_count = SB_BLOCK_COUNT(s); 76 block_count = SB_BLOCK_COUNT(s);
76 bmap_nr = SB_BMAP_NR(s); 77 bmap_nr = reiserfs_bmap_count(s);
77 78
78 /* resizing of reiserfs bitmaps (journal and real), if needed */ 79 /* resizing of reiserfs bitmaps (journal and real), if needed */
79 if (bmap_nr_new > bmap_nr) { 80 if (bmap_nr_new > bmap_nr) {
@@ -119,7 +120,7 @@ int reiserfs_resize(struct super_block *s, unsigned long block_count_new)
119 return -ENOMEM; 120 return -ENOMEM;
120 } 121 }
121 memset(bitmap, 0, 122 memset(bitmap, 0,
122 sizeof(struct reiserfs_bitmap_info) * SB_BMAP_NR(s)); 123 sizeof(struct reiserfs_bitmap_info) * bmap_nr_new);
123 for (i = 0; i < bmap_nr; i++) 124 for (i = 0; i < bmap_nr; i++)
124 bitmap[i] = old_bitmap[i]; 125 bitmap[i] = old_bitmap[i];
125 126
@@ -143,7 +144,6 @@ int reiserfs_resize(struct super_block *s, unsigned long block_count_new)
143 mark_buffer_dirty(bh); 144 mark_buffer_dirty(bh);
144 sync_dirty_buffer(bh); 145 sync_dirty_buffer(bh);
145 // update bitmap_info stuff 146 // update bitmap_info stuff
146 bitmap[i].first_zero_hint = 1;
147 bitmap[i].free_count = sb_blocksize(sb) * 8 - 1; 147 bitmap[i].free_count = sb_blocksize(sb) * 8 - 1;
148 brelse(bh); 148 brelse(bh);
149 } 149 }
@@ -173,8 +173,6 @@ int reiserfs_resize(struct super_block *s, unsigned long block_count_new)
173 for (i = block_r; i < s->s_blocksize * 8; i++) 173 for (i = block_r; i < s->s_blocksize * 8; i++)
174 reiserfs_test_and_clear_le_bit(i, bh->b_data); 174 reiserfs_test_and_clear_le_bit(i, bh->b_data);
175 info->free_count += s->s_blocksize * 8 - block_r; 175 info->free_count += s->s_blocksize * 8 - block_r;
176 if (!info->first_zero_hint)
177 info->first_zero_hint = block_r;
178 176
179 journal_mark_dirty(&th, s, bh); 177 journal_mark_dirty(&th, s, bh);
180 brelse(bh); 178 brelse(bh);
@@ -196,9 +194,6 @@ int reiserfs_resize(struct super_block *s, unsigned long block_count_new)
196 brelse(bh); 194 brelse(bh);
197 195
198 info->free_count -= s->s_blocksize * 8 - block_r_new; 196 info->free_count -= s->s_blocksize * 8 - block_r_new;
199 /* Extreme case where last bitmap is the only valid block in itself. */
200 if (!info->free_count)
201 info->first_zero_hint = 0;
202 /* update super */ 197 /* update super */
203 reiserfs_prepare_for_journal(s, SB_BUFFER_WITH_SB(s), 1); 198 reiserfs_prepare_for_journal(s, SB_BUFFER_WITH_SB(s), 1);
204 free_blocks = SB_FREE_BLOCKS(s); 199 free_blocks = SB_FREE_BLOCKS(s);
@@ -206,7 +201,7 @@ int reiserfs_resize(struct super_block *s, unsigned long block_count_new)
206 free_blocks + (block_count_new - block_count - 201 free_blocks + (block_count_new - block_count -
207 (bmap_nr_new - bmap_nr))); 202 (bmap_nr_new - bmap_nr)));
208 PUT_SB_BLOCK_COUNT(s, block_count_new); 203 PUT_SB_BLOCK_COUNT(s, block_count_new);
209 PUT_SB_BMAP_NR(s, bmap_nr_new); 204 PUT_SB_BMAP_NR(s, bmap_would_wrap(bmap_nr_new) ? : bmap_nr_new);
210 s->s_dirt = 1; 205 s->s_dirt = 1;
211 206
212 journal_mark_dirty(&th, s, SB_BUFFER_WITH_SB(s)); 207 journal_mark_dirty(&th, s, SB_BUFFER_WITH_SB(s));
diff --git a/fs/reiserfs/stree.c b/fs/reiserfs/stree.c
index 981027d1187b..ca41567d7890 100644
--- a/fs/reiserfs/stree.c
+++ b/fs/reiserfs/stree.c
@@ -559,7 +559,7 @@ static int is_tree_node(struct buffer_head *bh, int level)
559/* The function is NOT SCHEDULE-SAFE! */ 559/* The function is NOT SCHEDULE-SAFE! */
560static void search_by_key_reada(struct super_block *s, 560static void search_by_key_reada(struct super_block *s,
561 struct buffer_head **bh, 561 struct buffer_head **bh,
562 unsigned long *b, int num) 562 b_blocknr_t *b, int num)
563{ 563{
564 int i, j; 564 int i, j;
565 565
@@ -611,7 +611,7 @@ int search_by_key(struct super_block *p_s_sb, const struct cpu_key *p_s_key, /*
611 DISK_LEAF_NODE_LEVEL */ 611 DISK_LEAF_NODE_LEVEL */
612 ) 612 )
613{ 613{
614 int n_block_number; 614 b_blocknr_t n_block_number;
615 int expected_level; 615 int expected_level;
616 struct buffer_head *p_s_bh; 616 struct buffer_head *p_s_bh;
617 struct path_element *p_s_last_element; 617 struct path_element *p_s_last_element;
@@ -619,7 +619,7 @@ int search_by_key(struct super_block *p_s_sb, const struct cpu_key *p_s_key, /*
619 int right_neighbor_of_leaf_node; 619 int right_neighbor_of_leaf_node;
620 int fs_gen; 620 int fs_gen;
621 struct buffer_head *reada_bh[SEARCH_BY_KEY_READA]; 621 struct buffer_head *reada_bh[SEARCH_BY_KEY_READA];
622 unsigned long reada_blocks[SEARCH_BY_KEY_READA]; 622 b_blocknr_t reada_blocks[SEARCH_BY_KEY_READA];
623 int reada_count = 0; 623 int reada_count = 0;
624 624
625#ifdef CONFIG_REISERFS_CHECK 625#ifdef CONFIG_REISERFS_CHECK
diff --git a/fs/reiserfs/super.c b/fs/reiserfs/super.c
index b82897ae090b..57adfe90d5ae 100644
--- a/fs/reiserfs/super.c
+++ b/fs/reiserfs/super.c
@@ -1725,6 +1725,21 @@ static int reiserfs_fill_super(struct super_block *s, void *data, int silent)
1725 set_sb_umount_state(rs, REISERFS_ERROR_FS); 1725 set_sb_umount_state(rs, REISERFS_ERROR_FS);
1726 set_sb_fs_state(rs, 0); 1726 set_sb_fs_state(rs, 0);
1727 1727
1728 /* Clear out s_bmap_nr if it would wrap. We can handle this
1729 * case, but older revisions can't. This will cause the
1730 * file system to fail mount on those older implementations,
1731 * avoiding corruption. -jeffm */
1732 if (bmap_would_wrap(reiserfs_bmap_count(s)) &&
1733 sb_bmap_nr(rs) != 0) {
1734 reiserfs_warning(s, "super-2030: This file system "
1735 "claims to use %u bitmap blocks in "
1736 "its super block, but requires %u. "
1737 "Clearing to zero.", sb_bmap_nr(rs),
1738 reiserfs_bmap_count(s));
1739
1740 set_sb_bmap_nr(rs, 0);
1741 }
1742
1728 if (old_format_only(s)) { 1743 if (old_format_only(s)) {
1729 /* filesystem of format 3.5 either with standard or non-standard 1744 /* filesystem of format 3.5 either with standard or non-standard
1730 journal */ 1745 journal */
diff --git a/fs/reiserfs/xattr.c b/fs/reiserfs/xattr.c
index fab4b9b2664f..1597f6b649e0 100644
--- a/fs/reiserfs/xattr.c
+++ b/fs/reiserfs/xattr.c
@@ -484,7 +484,7 @@ reiserfs_xattr_set(struct inode *inode, const char *name, const void *buffer,
484 /* Resize it so we're ok to write there */ 484 /* Resize it so we're ok to write there */
485 newattrs.ia_size = buffer_size; 485 newattrs.ia_size = buffer_size;
486 newattrs.ia_valid = ATTR_SIZE | ATTR_CTIME; 486 newattrs.ia_valid = ATTR_SIZE | ATTR_CTIME;
487 mutex_lock(&xinode->i_mutex); 487 mutex_lock_nested(&xinode->i_mutex, I_MUTEX_XATTR);
488 err = notify_change(fp->f_path.dentry, &newattrs); 488 err = notify_change(fp->f_path.dentry, &newattrs);
489 if (err) 489 if (err)
490 goto out_filp; 490 goto out_filp;
@@ -1223,7 +1223,8 @@ int reiserfs_xattr_init(struct super_block *s, int mount_flags)
1223 if (!IS_ERR(dentry)) { 1223 if (!IS_ERR(dentry)) {
1224 if (!(mount_flags & MS_RDONLY) && !dentry->d_inode) { 1224 if (!(mount_flags & MS_RDONLY) && !dentry->d_inode) {
1225 struct inode *inode = dentry->d_parent->d_inode; 1225 struct inode *inode = dentry->d_parent->d_inode;
1226 mutex_lock(&inode->i_mutex); 1226 mutex_lock_nested(&inode->i_mutex,
1227 I_MUTEX_XATTR);
1227 err = inode->i_op->mkdir(inode, dentry, 0700); 1228 err = inode->i_op->mkdir(inode, dentry, 0700);
1228 mutex_unlock(&inode->i_mutex); 1229 mutex_unlock(&inode->i_mutex);
1229 if (err) { 1230 if (err) {