reiserfs fixes patch set
cover reiserfs fixes patch set
This is a series of "safe" patches that have been in the openSUSE kernel for a while now.
* patches.suse/reiserfs-fix-lockdep-warnings
- Adds lockdep annotation to the xattr locks
* patches.suse/reiserfs-no-bug-on-panic.diff
- Replaces BUG with dump_stack in reiserfs_panic so it actually panics.
* patches.suse/reiserfs-use-is_reusable.diff
- Enables is_reusable() for bitmap sanity checking unconditionally.
* patches.suse/reiserfs-signedness-fixes.diff
- Ensures that block numbers are _always_ unsigned by using b_blocknr_t.
* patches.suse/reiserfs-fix-resize-meminit.diff
- Fixes a case where the old block number count was used to zero out the bitmap info array during resize.
* patches.suse/reiserfs-remove-first-zero-hint.diff
- Removes the first_zero_hint bitmap tracking code and extends the free count to 32-bit for support of block sizes > 8 KiB.
* patches.suse/reiserfs-fix-large-fs.diff
- Ignores the 16-bit on-disk bitmap block count value to allow file systems larger than 8 TiB.
Please apply.
-Jeff
--
Jeff Mahoney
SUSE Labs
PATCH 1/7 reiserfs: fix up lockdep warnings
This patch adds I_MUTEX_XATTR annotations to the inode locking in the reiserfs xattr code.
--- fs/reiserfs/xattr.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-)
fs/reiserfs/xattr.c +3 -2
@@ -478,7 +478,7 @@ reiserfs_xattr_set(struct inode *inode,/* Resize it so we're ok to write there */ newattrs.ia_size = buffer_size; newattrs.ia_valid =ATTR_SIZE |ATTR_CTIME ; -mutex_lock (&xinode->i_mutex); +mutex_lock_nested (&xinode->i_mutex,I_MUTEX_XATTR ); err =notify_change (fp->f_path.dentry, &newattrs);if (err) goto out_filp;
@@ -1217,7 +1217,8 @@ int reiserfs_xattr_init(struct super_bloif (!IS_ERR (dentry)) {if (!(mount_flags &MS_RDONLY ) && !dentry->d_inode) {struct inode *inode = dentry->d_parent->d_inode; -mutex_lock (&inode->i_mutex); +mutex_lock_nested (&inode->i_mutex, +I_MUTEX_XATTR ); err = inode->i_op->mkdir (inode, dentry,0700 );mutex_unlock (&inode->i_mutex);if (err) {
PATCH 2/7 reiserfs: dont use BUG when panicking
In reply to Jeff Mahoney This patch changes reiserfs_panic() to use panic() initially instead of BUG(). Using BUG() ignores the configurable panic behavior, so systems that should be failing and rebooting are left hanging. This causes problems in active/standby HA scenarios.
--- fs/reiserfs/prints.c | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-)
fs/reiserfs/prints.c +4 -6
@@ -356,13 +356,11 @@ extern struct tree_balance *cur_tb;void reiserfs_panic (struct super_block *sb,const char *fmt, ...) {do_reiserfs_warning (fmt); -printk (KERN_EMERG "REISERFS: panic (device %s): %s\n" , -reiserfs_bdevname (sb), error_buf); -BUG (); -/* this is not actually called, but makes reiserfs_panic() "noreturn" */ -panic ("REISERFS: panic (device %s): %s\n" , -reiserfs_bdevname (sb), error_buf); +dump_stack (); + +panic (KERN_EMERG "REISERFS: panic (device %s): %s\n" , +reiserfs_bdevname (sb), error_buf); }void reiserfs_abort (struct super_block *sb,int errno,const char *fmt, ...)
PATCH 3/7 reiserfs: use is_reusable to catch corruption
In reply to Jeff Mahoney This patch builds in is_reusable() unconditionally and uses it to catch corruption before it reaches the block freeing paths.
--
fs/reiserfs/bitmap.c | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-)
fs/reiserfs/bitmap.c +13 -8
@@ -56,7 +56,6 @@ static inline void get_bit_address(struc *offset = block & ((s->s_blocksize <<3 ) -1 ); } -#ifdef CONFIG_REISERFS_CHECK int is_reusable (struct super_block *s,b_blocknr_t block,int bit_value) {int bmap, offset;
@@ -106,7 +105,6 @@ int is_reusable(struct super_block *s, breturn 1 ; } -#endif /* CONFIG_REISERFS_CHECK */ /* searches in journal structures for a given block number (bmap, off). If block is found in reiserfs journal it suggests next free block candidate to test. */
@@ -434,12 +432,19 @@ void reiserfs_free_block(struct reiserfs int for_unformatted) {struct super_block *s = th->t_super; -BUG_ON (!th->t_trans_id);RFALSE (!s,"vs-4061: trying to free block on nonexistent device" ); -RFALSE (is_reusable (s, block,1 ) ==0 , -"vs-4071: can not free such block" ); +if (!is_reusable (s, block,1 )) +return ; + +if (block >sb_block_count (REISERFS_SB (s)->s_rs)) { +reiserfs_panic (th->t_super,"bitmap-4072" , +"Trying to free block outside file system " +"boundaries (%lu > %lu)" , + block,sb_block_count (REISERFS_SB (s)->s_rs)); +return ; + }/* mark it before we clear it, just in case */ journal_mark_freed (th, s, block);_reiserfs_free_block (th, inode, block, for_unformatted);
@@ -449,11 +454,11 @@ void reiserfs_free_block(struct reiserfsstatic void reiserfs_free_prealloc_block (struct reiserfs_transaction_handle *th,struct inode *inode,b_blocknr_t block) { +BUG_ON (!th->t_trans_id);RFALSE (!th->t_super,"vs-4060: trying to free block on nonexistent device" ); -RFALSE (is_reusable (th->t_super, block,1 ) ==0 , -"vs-4070: can not free such block" ); -BUG_ON (!th->t_trans_id); +if (!is_reusable (th->t_super, block,1 )) +return ;_reiserfs_free_block (th, inode, block,1 ); }
PATCH 4/7 reiserfs: fix usage of signed ints for block numbers
In reply to Jeff MahoneyThis patch does a quick signedness check for block numbers. There are a number of places where signed integers are used for block numbers, which limits the usable file system size to 8 TiB. The disk format, excepting a problem which will be fixed in the following patch, supports file systems up to 16 TiB in size. This patch cleans up those sites so that we can enable the full usable size.
---
fs/reiserfs/bitmap.c | 24 +++++++++++++----------- fs/reiserfs/inode.c | 8 ++++---- fs/reiserfs/journal.c | 18 ++++++++++-------- fs/reiserfs/stree.c | 6 +++--- include/linux/reiserfs_fs.h | 14 ++++++++------ 5 files changed, 38 insertions(+), 32 deletions(-)
fs/reiserfs/bitmap.c +13 -11
@@ -47,7 +47,9 @@ test_bit(_ALLOC_ ## optname , &SB_ALLOC_OPTS(s))static inline void get_bit_address (struct super_block *s, -b_blocknr_t block,int *bmap_nr,int *offset) +b_blocknr_t block, +unsigned int *bmap_nr, +unsigned int *offset) {/* It is in the bitmap block number equal to the block * number divided by the number of bits in a block. */
@@ -58,7 +60,7 @@ static inline void get_bit_address(strucint is_reusable (struct super_block *s,b_blocknr_t block,int bit_value) { -int bmap, offset; +unsigned int bmap, offset;if (block ==0 || block >=SB_BLOCK_COUNT (s)) { reiserfs_warning(s,
@@ -108,8 +110,8 @@ int is_reusable(struct super_block *s, b/* searches in journal structures for a given block number (bmap, off). If block is found in reiserfs journal it suggests next free block candidate to test. */ -static inline int is_block_in_journal (struct super_block *s,int bmap,int - off,int *next) +static inline int is_block_in_journal (struct super_block *s,unsigned int bmap, +int off,int *next) {b_blocknr_t tmp;
@@ -130,8 +132,8 @@ static inline int is_block_in_journal(st/* it searches for a window of zero bits with given minimum and maximum lengths in one bitmap * block; */ static int scan_bitmap_block (struct reiserfs_transaction_handle *th, -int bmap_n,int *beg,int boundary,int min, -int max,int unfm) +unsigned int bmap_n,int *beg,int boundary, +int min,int max,int unfm) {struct super_block *s = th->t_super;struct reiserfs_bitmap_info *bi = &SB_AP_BITMAP (s)[bmap_n];
@@ -307,16 +309,16 @@ __le32 reiserfs_choose_packing(struct in* bitmap and place new blocks there. Returns number of allocated blocks. */ static int scan_bitmap (struct reiserfs_transaction_handle *th,b_blocknr_t * start,b_blocknr_t finish, -int min,int max,int unfm,unsigned long file_block) +int min,int max,int unfm,sector_t file_block) {int nr_allocated =0 ;struct super_block *s = th->t_super;/* find every bm and bmap and bmap_nr in this file, and change them all to bitmap_blocknr * - Hans, it is not a block number - Zam. */ -int bm, off; -int end_bm, end_off; -int off_max = s->s_blocksize <<3 ; +unsigned int bm, off; +unsigned int end_bm, end_off; +unsigned int off_max = s->s_blocksize <<3 ;BUG_ON (!th->t_trans_id);
@@ -383,7 +385,7 @@ static void _reiserfs_free_block(structstruct reiserfs_super_block *rs;struct buffer_head *sbh, *bmbh;struct reiserfs_bitmap_info *apbi; -int nr, offset; +unsigned int nr, offset;BUG_ON (!th->t_trans_id);
fs/reiserfs/inode.c +4 -4
@@ -198,7 +198,7 @@ static inline void set_block_dev_mapped(// files which were created in the earlier version can not be longer, // than 2 gb // -static int file_capable (struct inode *inode,long block) +static int file_capable (struct inode *inode,sector_t block) {if (get_inode_item_key_version (inode) !=KEY_FORMAT_3_5 ||// it is new file. block < (1 << (31 - inode->i_sb->s_blocksize_bits)))// old file, but 'block' is inside of 2gb
@@ -241,7 +241,7 @@ static int file_capable(struct inode *in// Please improve the english/clarity in the comment above, as it is // hard to understand. -static int _get_block_create_0 (struct inode *inode,long block, +static int _get_block_create_0 (struct inode *inode,sector_t block,struct buffer_head *bh_result,int args) {INITIALIZE_PATH (path);
@@ -249,7 +249,7 @@ static int _get_block_create_0(struct instruct buffer_head *bh;struct item_head *ih, tmp_ih;int fs_gen; -int blocknr; +b_blocknr_t blocknr;char *p =NULL ;int chars;int ret;
@@ -568,7 +568,7 @@ static int convert_tail_for_hole(struct }static inline int _allocate_block (struct reiserfs_transaction_handle *th, -long block, +sector_t block,struct inode *inode,b_blocknr_t * allocated_block_nr,struct treepath *path,int flags)
fs/reiserfs/journal.c +10 -8
@@ -219,11 +219,12 @@ static void allocate_bitmap_nodes(struct } } -static int set_bit_in_list_bitmap (struct super_block *p_s_sb,int block, +static int set_bit_in_list_bitmap (struct super_block *p_s_sb, +b_blocknr_t block,struct reiserfs_list_bitmap *jb) { -int bmap_nr = block / (p_s_sb->s_blocksize <<3 ); -int bit_nr = block % (p_s_sb->s_blocksize <<3 ); +unsigned int bmap_nr = block / (p_s_sb->s_blocksize <<3 ); +unsigned int bit_nr = block % (p_s_sb->s_blocksize <<3 );if (!jb->bitmaps[bmap_nr]) { jb->bitmaps[bmap_nr] =get_bitmap_node (p_s_sb);
@@ -289,7 +290,7 @@ static int free_bitmap_nodes(struct supe*/ int reiserfs_allocate_list_bitmaps (struct super_block *p_s_sb,struct reiserfs_list_bitmap *jb_array, -int bmap_nr) +unsigned int bmap_nr) {int i;int failed =0 ;
@@ -483,7 +484,7 @@ static inline struct reiserfs_journal_cn** */ int reiserfs_in_journal (struct super_block *p_s_sb, -int bmap_nr,int bit_nr,int search_all, +unsigned int bmap_nr,int bit_nr,int search_all,b_blocknr_t * next_zero_bit) {struct reiserfs_journal *journal =SB_JOURNAL (p_s_sb);
@@ -986,7 +987,7 @@ static int flush_commit_list(struct supe struct reiserfs_journal_list *jl, int flushall) { int i; -int bn; +b_blocknr_t bn;struct buffer_head *tbh =NULL ;unsigned long trans_id = jl->j_trans_id;struct reiserfs_journal *journal =SB_JOURNAL (s);
@@ -2279,8 +2280,9 @@ static int journal_read_transaction(struRight now it is only used from journal code. But later we might use it from other places. Note: Do not use journal_getblk/sb_getblk functions here! */ -static struct buffer_head *reiserfs_breada (struct block_device *dev,int block, -int bufsize,unsigned int max_block) +static struct buffer_head *reiserfs_breada (struct block_device *dev, +b_blocknr_t block,int bufsize, +b_blocknr_t max_block) {struct buffer_head *bhlist[BUFNR ];unsigned int blocks =BUFNR ;
fs/reiserfs/stree.c +3 -3
@@ -559,7 +559,7 @@ static int is_tree_node(struct buffer_he/* The function is NOT SCHEDULE-SAFE! */ static void search_by_key_reada (struct super_block *s,struct buffer_head **bh, -unsigned long *b,int num) +b_blocknr_t *b,int num) {int i, j;
@@ -611,7 +611,7 @@ int search_by_key(struct super_block *p_DISK_LEAF_NODE_LEVEL */ ) { -int n_block_number; +b_blocknr_t n_block_number;int expected_level;struct buffer_head *p_s_bh;struct path_element *p_s_last_element;
@@ -619,7 +619,7 @@ int search_by_key(struct super_block *p_int right_neighbor_of_leaf_node;int fs_gen;struct buffer_head *reada_bh[SEARCH_BY_KEY_READA ]; -unsigned long reada_blocks[SEARCH_BY_KEY_READA ]; +b_blocknr_t reada_blocks[SEARCH_BY_KEY_READA ];int reada_count =0 ;#ifdef CONFIG_REISERFS_CHECK
include/linux/reiserfs_fs.h +8 -6
@@ -1736,8 +1736,8 @@ int journal_end_sync(struct reiserfs_traint journal_mark_freed (struct reiserfs_transaction_handle *,struct super_block *,b_blocknr_t blocknr);int journal_transaction_should_end (struct reiserfs_transaction_handle *,int ); -int reiserfs_in_journal (struct super_block *p_s_sb,int bmap_nr,int bit_nr, -int searchall,b_blocknr_t * next); +int reiserfs_in_journal (struct super_block *p_s_sb,unsigned int bmap_nr, +int bit_nr,int searchall,b_blocknr_t * next);int journal_begin (struct reiserfs_transaction_handle *,struct super_block *p_s_sb,unsigned long ); int journal_join_abort(struct reiserfs_transaction_handle *,
@@ -1745,7 +1745,7 @@ int journal_join_abort(struct reiserfs_tvoid reiserfs_journal_abort (struct super_block *sb,int errno);void reiserfs_abort (struct super_block *sb,int errno,const char *fmt, ...);int reiserfs_allocate_list_bitmaps (struct super_block *s, -struct reiserfs_list_bitmap *,int ); +struct reiserfs_list_bitmap *,unsigned int );void add_save_link (struct reiserfs_transaction_handle *th,struct inode *inode,int truncate);
@@ -2045,7 +2045,7 @@ struct buffer_head *get_FEB(struct tree_* arguments, such as node, search path, transaction_handle, etc. */ struct __reiserfs_blocknr_hint {struct inode *inode;/* inode passed to allocator, if we allocate unf. nodes */ -long block;/* file offset, in blocks */ +sector_t block;/* file offset, in blocks */ struct in_core_key key;struct treepath *path;/* search path, used by allocator to deternine search_start by * various ways */
@@ -2103,7 +2103,8 @@ static inline int reiserfs_new_form_blocstatic inline int reiserfs_new_unf_blocknrs (struct reiserfs_transaction_handle *th,struct inode *inode,b_blocknr_t * new_blocknrs, -struct treepath *path,long block) +struct treepath *path, +sector_t block) {reiserfs_blocknr_hint_t hint = { .th = th,
@@ -2120,7 +2121,8 @@ static inline int reiserfs_new_unf_blockstatic inline int reiserfs_new_unf_blocknrs2 (struct reiserfs_transaction_handle *th,struct inode *inode,b_blocknr_t * new_blocknrs, -struct treepath *path,long block) +struct treepath *path, +sector_t block) {reiserfs_blocknr_hint_t hint = { .th = th,
PATCH 5/7 reiserfs: fix memset byte count during resize
In reply to Jeff Mahoney The following patch corrects the memset in reiserfs_resize to clear the memory allocated for the new bitmap info structs. Previously, it would clear the memory used by the old size. Depending on the contents of memory, this could cause incorrect caching behavior for bitmap blocks in the newly allocated area.
--- fs/reiserfs/resize.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
fs/reiserfs/resize.c +1 -1
@@ -119,7 +119,7 @@ int reiserfs_resize(struct super_block *return -ENOMEM ; }memset (bitmap,0 , -sizeof (struct reiserfs_bitmap_info ) *SB_BMAP_NR (s)); +sizeof (struct reiserfs_bitmap_info ) * bmap_nr_new);for (i =0 ; i < bmap_nr; i++) bitmap[i] = old_bitmap[i];
PATCH 6/7 reiserfs: remove first_zero_hint
In reply to Jeff Mahoney The first_zero_hint metadata caching was never actually used, and it's of dubious optimization quality. This patch removes it.
It doesn't actually shrink the size of the reiserfs_bitmap_info struct, since that doesn't work with block sizes larger than 8K. There was a big fixme in there, and with all the work lately in allowing block size > page size, I might as well kill the fixme as well.
--- fs/reiserfs/bitmap.c | 27 +++++++++++---------------- fs/reiserfs/resize.c | 6 ------ include/linux/reiserfs_fs_sb.h | 4 +--- 3 files changed, 12 insertions(+), 25 deletions(-)
fs/reiserfs/bitmap.c +11 -16
@@ -273,7 +273,7 @@ static inline int block_group_used(struc* to make a better decision. This favors long-term performace gain * with a better on-disk layout vs. a short term gain of skipping the * read and potentially having a bad placement. */ -if (info->first_zero_hint ==0 ) { +if (info->free_count ==UINT_MAX ) {struct buffer_head *bh =reiserfs_read_bitmap_block (s, bm);brelse (bh); }
@@ -1271,27 +1271,22 @@ void reiserfs_cache_bitmap_metadata(stru {unsigned long *cur = (unsigned long *)(bh->b_data + bh->b_size); - info->first_zero_hint =1 << (sb->s_blocksize_bits +3 ); +/* The first bit must ALWAYS be 1 */ +BUG_ON (!reiserfs_test_le_bit (0 , (unsigned long )bh->b_data)) + + info->free_count = 0;while (--cur >= (unsigned long *)bh->b_data) { -int base = ((char *)cur - bh->b_data) <<3 ; +int i;/* 0 and ~0 are special, we can optimize for them */ -if (*cur ==0 ) { - info->first_zero_hint = base; +if (*cur ==0 ) info->free_count +=BITS_PER_LONG ; - }else if (*cur != ~0L ) {/* A mix, investigate */ -int b; -for (b =BITS_PER_LONG -1 ; b >=0 ; b--) { -if (!reiserfs_test_le_bit (b, cur)) { - info->first_zero_hint = base + b; +else if (*cur != ~0L )/* A mix, investigate */ +for (i =BITS_PER_LONG -1 ; i >=0 ; i--) +if (!reiserfs_test_le_bit (i, cur)) info->free_count++; - } - } - } } -/* The first bit must ALWAYS be 1 */ -BUG_ON (info->first_zero_hint ==0 ); } struct buffer_head *reiserfs_read_bitmap_block(struct super_block *sb,
@@ -1321,7 +1316,7 @@ struct buffer_head *reiserfs_read_bitmapBUG_ON (!buffer_uptodate (bh));BUG_ON (atomic_read (&bh->b_count) ==0 ); -if (info->first_zero_hint ==0 ) +if (info->free_count ==UINT_MAX )reiserfs_cache_bitmap_metadata (sb, bh, info); }
fs/reiserfs/resize.c +0 -6
@@ -143,7 +143,6 @@ int reiserfs_resize(struct super_block *mark_buffer_dirty (bh);sync_dirty_buffer (bh);// update bitmap_info stuff - bitmap[i].first_zero_hint =1 ; bitmap[i].free_count =sb_blocksize (sb) *8 -1 ;brelse (bh); }
@@ -173,8 +172,6 @@ int reiserfs_resize(struct super_block *for (i = block_r; i < s->s_blocksize *8 ; i++)reiserfs_test_and_clear_le_bit (i, bh->b_data); info->free_count += s->s_blocksize *8 - block_r; -if (!info->first_zero_hint) - info->first_zero_hint = block_r;journal_mark_dirty (&th, s, bh);brelse (bh);
@@ -196,9 +193,6 @@ int reiserfs_resize(struct super_block *brelse (bh); info->free_count -= s->s_blocksize *8 - block_r_new; -/* Extreme case where last bitmap is the only valid block in itself. */ -if (!info->free_count) - info->first_zero_hint =0 ;/* update super */ reiserfs_prepare_for_journal (s,SB_BUFFER_WITH_SB (s),1 ); free_blocks =SB_FREE_BLOCKS (s);
include/linux/reiserfs_fs_sb.h +1 -3
@@ -265,9 +265,7 @@ enum journal_state_bits {typedef __u32 (*hashf_t ) (const signed char *,int );struct reiserfs_bitmap_info { -// FIXME: Won't work with block sizes > 8K -__u16 first_zero_hint; -__u16 free_count; +__u32 free_count; };struct proc_dir_entry ;
Re: [patch 6/7] reiserfs: remove first_zero_hint
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
Quoted 7 lines · Jeff Mahoney
The
first_zero_hintmetadata caching was never actually used, and it's of dubious optimization quality. This patch removes it.It doesn't actually shrink the size of the
reiserfs_bitmap_infostruct, since that doesn't work with block sizes larger than 8K. There was a big fixme in there, and with all the work lately in allowing block size > page size, I might as well kill the fixme as well.
Please skip this one. It's missing a chunk. I'll post the updated patch shortly.
- -Jeff
- --
Jeff Mahoney
SUSE Labs
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v2.0.4-svn0 (GNU/Linux)
Comment: Using GnuPG with SUSE - http://enigmail.mozdev.org
iD8DBQFHF5+gLPWxlyuTD7IRAvbGAKCDEzonySupZZlsByKtllxjgFLGAACgmjJw 2nsFXIpE43J7BFzn2W+lOUA=
=m01z
-----END PGP SIGNATURE-----
PATCH 7/7 reiserfs: ignore on disk s_bmap_nr value
In reply to Jeff MahoneyThis patch implements support for file systems larger than 8 TiB.
The reiserfs superblock contains a 16 bit value for counting the number of bitmap blocks. The rest of the disk format supports file systems up to 2^32 blocks, but the bitmap block limitation artificially limits this to 8 TiB with a 4KiB block size.
Rather than trust the superblock's 16-bit bitmap block count, we calculate it dynamically based on the number of blocks in the file system. When an incorrect value is observed in the superblock, it is zeroed out, ensuring that older kernels will not be able to mount the file system.
Userspace support has already been implemented and shipped in reiserfsprogs 3.6.20.
---
fs/reiserfs/bitmap.c | 39 ++++++++++++++++++++++----------------- fs/reiserfs/journal.c | 6 +++--- fs/reiserfs/resize.c | 6 +++--- fs/reiserfs/super.c | 15 +++++++++++++++ include/linux/reiserfs_fs.h | 5 +++++ 5 files changed, 48 insertions(+), 23 deletions(-)
fs/reiserfs/bitmap.c +22 -17
@@ -61,6 +61,7 @@ static inline void get_bit_address(strucint is_reusable (struct super_block *s,b_blocknr_t block,int bit_value) {unsigned int bmap, offset; +unsigned int bmap_count =reiserfs_bmap_count (s);if (block ==0 || block >=SB_BLOCK_COUNT (s)) { reiserfs_warning(s,
@@ -76,25 +77,26 @@ int is_reusable(struct super_block *s, bif (unlikely (test_bit (REISERFS_OLD_FORMAT , &(REISERFS_SB (s)->s_properties)))) {b_blocknr_t bmap1 =REISERFS_SB (s)->s_sbh->b_blocknr +1 ; -if (block >= bmap1 && block <= bmap1 +SB_BMAP_NR (s)) { +if (block >= bmap1 && + block <= bmap1 + bmap_count) {reiserfs_warning (s,"vs: 4019: is_reusable: " "bitmap block %lu(%u) can't be freed or reused" , - block,SB_BMAP_NR (s)); + block, bmap_count);return 0 ; } }else {if (offset ==0 ) {reiserfs_warning (s,"vs: 4020: is_reusable: " "bitmap block %lu(%u) can't be freed or reused" , - block,SB_BMAP_NR (s)); + block, bmap_count);return 0 ; } } -if (bmap >=SB_BMAP_NR (s)) { +if (bmap >= bmap_count) {reiserfs_warning (s,"vs-4030: is_reusable: there is no so many bitmap blocks: " -"block=%lu, bitmap_nr=%d" , block, bmap); +"block=%lu, bitmap_nr=%u" , block, bmap);return 0 ; }
@@ -143,8 +145,8 @@ static int scan_bitmap_block(struct reisBUG_ON (!th->t_trans_id); -RFALSE (bmap_n >=SB_BMAP_NR (s),"Bitmap %d is out of range (0..%d)" , - bmap_n,SB_BMAP_NR (s) -1 ); +RFALSE (bmap_n >=reiserfs_bmap_count (s),"Bitmap %u is out of " +"range (0..%u)" , bmap_n,reiserfs_bmap_count (s) -1 );PROC_INFO_INC (s, scan_bitmap.bmap);/* this is unclear and lacks comments, explain how journal bitmaps work here for the reader. Convey a sense of the design here. What
@@ -249,12 +251,12 @@ static int bmap_hash_id(struct super_blo }else { hash_in = (char *)(&id); hash =keyed_hash (hash_in,4 ); - bm = hash %SB_BMAP_NR (s); + bm = hash %reiserfs_bmap_count (s);if (!bm) bm =1 ; }/* this can only be true when SB_BMAP_NR = 1 */ -if (bm >=SB_BMAP_NR (s)) +if (bm >=reiserfs_bmap_count (s)) bm =0 ;return bm; }
@@ -328,10 +330,10 @@ static int scan_bitmap(struct reiserfs_tget_bit_address (s, *start, &bm, &off);get_bit_address (s, finish, &end_bm, &end_off); -if (bm >SB_BMAP_NR (s)) +if (bm >reiserfs_bmap_count (s))return 0 ; -if (end_bm >SB_BMAP_NR (s)) - end_bm =SB_BMAP_NR (s); +if (end_bm >reiserfs_bmap_count (s)) + end_bm =reiserfs_bmap_count (s);/* When the bitmap is more than 10% free, anyone can allocate. * When it's less than 10% free, only files that already use the
@@ -397,10 +399,12 @@ static void _reiserfs_free_block(structget_bit_address (s, block, &nr, &offset); -if (nr >=sb_bmap_nr (rs)) { +if (nr >=reiserfs_bmap_count (s)) {reiserfs_warning (s,"vs-4075: reiserfs_free_block: " -"block %lu is out of range on %s" , - block,reiserfs_bdevname (s)); +"block %lu is out of range on %s " +"(nr=%u,max=%u)" , block, +reiserfs_bdevname (s), nr, +reiserfs_bmap_count (s));return ; }
@@ -1326,12 +1330,13 @@ struct buffer_head *reiserfs_read_bitmapint reiserfs_init_bitmap_cache (struct super_block *sb) {struct reiserfs_bitmap_info *bitmap; +unsigned int bmap_nr =reiserfs_bmap_count (sb); - bitmap =vmalloc (sizeof (*bitmap) *SB_BMAP_NR (sb)); + bitmap =vmalloc (sizeof (*bitmap) * bmap_nr);if (bitmap ==NULL )return -ENOMEM ; -memset (bitmap,0 ,sizeof (*bitmap) *SB_BMAP_NR (sb)); +memset (bitmap,0 ,sizeof (*bitmap) * bmap_nr);SB_AP_BITMAP (sb) = bitmap;
fs/reiserfs/journal.c +3 -3
@@ -240,7 +240,7 @@ static void cleanup_bitmap_list(struct sif (jb->bitmaps ==NULL )return ; -for (i =0 ; i <SB_BMAP_NR (p_s_sb); i++) { +for (i =0 ; i <reiserfs_bmap_count (p_s_sb); i++) {if (jb->bitmaps[i]) {free_bitmap_node (p_s_sb, jb->bitmaps[i]); jb->bitmaps[i] =NULL ;
@@ -2651,7 +2651,7 @@ int journal_init(struct super_block *p_s journal->j_persistent_trans =0 ;if (reiserfs_allocate_list_bitmaps (p_s_sb, journal->j_list_bitmap, -SB_BMAP_NR (p_s_sb))) +reiserfs_bmap_count (p_s_sb))) goto free_and_return;allocate_bitmap_nodes (p_s_sb);
@@ -2659,7 +2659,7 @@ int journal_init(struct super_block *p_sSB_JOURNAL_1st_RESERVED_BLOCK (p_s_sb) = (old_format ?REISERFS_OLD_DISK_OFFSET_IN_BYTES / p_s_sb->s_blocksize + -SB_BMAP_NR (p_s_sb) + +reiserfs_bmap_count (p_s_sb) +1 :REISERFS_DISK_OFFSET_IN_BYTES / p_s_sb->s_blocksize +2 );
fs/reiserfs/resize.c +3 -3
@@ -61,7 +61,7 @@ int reiserfs_resize(struct super_block * }/* count used bits in last bitmap block */ - block_r =SB_BLOCK_COUNT (s) - (SB_BMAP_NR (s) -1 ) * s->s_blocksize *8 ; + block_r =SB_BLOCK_COUNT (s) - (reiserfs_bmap_count (s) -1 ) * s->s_blocksize *8 ;/* count bitmap blocks in new fs */ bmap_nr_new = block_count_new / (s->s_blocksize *8 );
@@ -73,7 +73,7 @@ int reiserfs_resize(struct super_block */* save old values */ block_count =SB_BLOCK_COUNT (s); - bmap_nr =SB_BMAP_NR (s); + bmap_nr =reiserfs_bmap_count (s);/* resizing of reiserfs bitmaps (journal and real), if needed */ if (bmap_nr_new > bmap_nr) {
@@ -200,7 +200,7 @@ int reiserfs_resize(struct super_block * free_blocks + (block_count_new - block_count - (bmap_nr_new - bmap_nr)));PUT_SB_BLOCK_COUNT (s, block_count_new); -PUT_SB_BMAP_NR (s, bmap_nr_new); +PUT_SB_BMAP_NR (s,bmap_would_wrap (bmap_nr_new) ? : bmap_nr_new ); s->s_dirt =1 ;journal_mark_dirty (&th, s,SB_BUFFER_WITH_SB (s));
fs/reiserfs/super.c +15 -0
@@ -1713,6 +1713,21 @@ static int reiserfs_fill_super(struct suset_sb_umount_state (rs,REISERFS_ERROR_FS );set_sb_fs_state (rs,0 ); +/* Clear out s_bmap_nr if it would wrap. We can handle this +* case, but older revisions can't. This will cause the +* file system to fail mount on those older implementations, +* avoiding corruption. -jeffm */ +if (bmap_would_wrap (reiserfs_bmap_count (s)) && +sb_bmap_nr (rs) !=0 ) { +reiserfs_warning (s,"super-2030: This file system " +"claims to use %u bitmap blocks in " +"its super block, but requires %u. " +"Clearing to zero." ,sb_bmap_nr (rs), +reiserfs_bmap_count (s)); + +set_sb_bmap_nr (rs,0 ); + } +if (old_format_only (s)) {/* filesystem of format 3.5 either with standard or non-standard journal */
include/linux/reiserfs_fs.h +5 -0
@@ -231,6 +231,11 @@ struct reiserfs_super_block { ((!is_reiserfs_jr (SB_DISK_SUPER_BLOCK (s)) ? \SB_ONDISK_JOURNAL_SIZE (s) +1 :SB_ONDISK_RESERVED_FOR_JOURNAL (s))) +/* s_bmap_nr is a u16 */ +#define reiserfs_bmap_count (sb) reiserfs_bmap_nr(SB_BLOCK_COUNT(sb), sb->s_blocksize) +#define reiserfs_bmap_nr (count, blk_size) ((count - 1) / (blk_size * 8) + 1) +#define bmap_would_wrap (n) (n > ((1LL << 16) - 1)) +int is_reiserfs_3_5 (struct reiserfs_super_block *rs);int is_reiserfs_3_6 (struct reiserfs_super_block *rs);int is_reiserfs_jr (struct reiserfs_super_block *rs);
Re: [patch 7/7] reiserfs: ignore on disk s_bmap_nr value
include/linux/reiserfs_fs.h struct reiserfs_super_block { · line 237
Quoted 4 lines · On Tue, 16 Oct 2007 19:02:17 -0400 Jeff Mahoney <[email protected]> wrote:
include/linux/reiserfs_fs.h +4
-0+/* s_bmap_nr is a u16 */ +#define reiserfs_bmap_count (sb) reiserfs_bmap_nr(SB_BLOCK_COUNT(sb), sb->s_blocksize) +#define reiserfs_bmap_nr (count, blk_size) ((count - 1) / (blk_size * 8) + 1) +#define bmap_would_wrap (n) (n > ((1LL << 16) - 1))
Please only use macros when the code HAS to be implemented as a macro for some reason. These could have been implemented as (possibly inlined) C functions.
reiserfs_bmap_count() is in fact buggy - it references its argument more than once. Nobody will be doing reiserfs_bmap_count(foo++), but it is bad practice.
Also, all three macros fail to sufficiently parenthesise their arguments.
All this is fixable by coding in C, not cpp...
Quoted 3 lines · On Tue, 16 Oct 2007 19:02:10 -0400 Jeff Mahoney <[email protected]> wrote:
This is a series of "safe" patches that have been in the openSUSE kernel for a while now.
I'm not particularly happy seeing a large number of complex-looking patches against a not-very-well-maintained important filesystem more than a week into the merge window. It would have been far better to get this stuff sent a month ago.
Now we're left with a choice between holding it all back for 2.5 months or just jamming it into mainline with basically no testing. I sure hope it got good testing in the suse kernel.
Quoted 4 lines · Andrew Morton
Now we're left with a choice between holding it all back for 2.5 months or just jamming it into mainline with basically no testing. I sure hope it got good testing in the suse kernel.
Well, considering that probably 95% of reiserfs users are SuSE people, it probably did get a fairly good testing base.
That said, I agree - it would have been better to have this lined up before the merge window even started, in -mm or somewhere.
Linus
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
Quoted 7 lines · Andrew Morton
Quoted 3 lines · On Tue, 16 Oct 2007 19:02:10 -0400 Jeff Mahoney <[email protected]> wrote:
This is a series of "safe" patches that have been in the openSUSE kernel for a while now.
Quoted 8 lines
I'm not particularly happy seeing a large number of complex-looking patches against a not-very-well-maintained important filesystem more than a week into the merge window. It would have been far better to get this stuff sent a month ago.
Now we're left with a choice between holding it all back for 2.5 months or just jamming it into mainline with basically no testing. I sure hope it got good testing in the suse kernel.
I'm fine being conservative here and just keeping them in -mm, then. Depending on when our next release ends up being scheduled, I'll likely have to maintain them out of tree anyway.
- -Jeff
- --
Jeff Mahoney
SUSE Labs
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v2.0.4-svn0 (GNU/Linux)
Comment: Using GnuPG with SUSE - http://enigmail.mozdev.org
iD8DBQFHFpmMLPWxlyuTD7IRAjstAJ4ze5cRUEFhVOkGiPCHrOMW/oQBLACeKgea BYiWeJkzr/voo+1P60Xrgec=
=lo9N
-----END PGP SIGNATURE-----