From: Jeffrey Mahoney This patch cleans up ReiserFS's use of buffer head flags. All direct access of BH_* are made into macro calls, and all reiserfs-specific BH_* macro implementations have been removed and replaced with the BUFFER_FNS implementations found in linux/buffer_head.h Signed-off-by: Jeff Mahoney Signed-off-by: Andrew Morton --- 25-akpm/fs/reiserfs/do_balan.c | 2 25-akpm/fs/reiserfs/fix_node.c | 2 25-akpm/fs/reiserfs/journal.c | 94 +++++++++++------------------------- 25-akpm/fs/reiserfs/namei.c | 2 25-akpm/include/linux/reiserfs_fs.h | 48 ++++++------------ 5 files changed, 51 insertions(+), 97 deletions(-) diff -puN fs/reiserfs/do_balan.c~reiserfs-cleanup-internal-use-of-bh-macros fs/reiserfs/do_balan.c --- 25/fs/reiserfs/do_balan.c~reiserfs-cleanup-internal-use-of-bh-macros 2004-10-05 11:10:22.173833280 -0700 +++ 25-akpm/fs/reiserfs/do_balan.c 2004-10-05 11:10:22.185831456 -0700 @@ -1341,7 +1341,7 @@ static void check_internal_node (struct static int locked_or_not_in_tree (struct buffer_head * bh, char * which) { - if ( (!reiserfs_buffer_prepared(bh) && buffer_locked (bh)) || + if ( (!buffer_journal_prepared (bh) && buffer_locked (bh)) || !B_IS_IN_TREE (bh) ) { reiserfs_warning (NULL, "vs-12339: locked_or_not_in_tree: %s (%b)", which, bh); diff -puN fs/reiserfs/fix_node.c~reiserfs-cleanup-internal-use-of-bh-macros fs/reiserfs/fix_node.c --- 25/fs/reiserfs/fix_node.c~reiserfs-cleanup-internal-use-of-bh-macros 2004-10-05 11:10:22.175832976 -0700 +++ 25-akpm/fs/reiserfs/fix_node.c 2004-10-05 11:10:22.187831152 -0700 @@ -820,7 +820,7 @@ static int get_empty_nodes( RFALSE (p_s_tb->FEB[p_s_tb->cur_blknum], "PAP-8141: busy slot for new buffer"); - mark_buffer_journal_new(p_s_new_bh) ; + set_buffer_journal_new (p_s_new_bh); p_s_tb->FEB[p_s_tb->cur_blknum++] = p_s_new_bh; } diff -puN fs/reiserfs/journal.c~reiserfs-cleanup-internal-use-of-bh-macros fs/reiserfs/journal.c --- 25/fs/reiserfs/journal.c~reiserfs-cleanup-internal-use-of-bh-macros 2004-10-05 11:10:22.178832520 -0700 +++ 25-akpm/fs/reiserfs/journal.c 2004-10-05 11:10:22.192830392 -0700 @@ -122,7 +122,7 @@ static void init_journal_hash(struct sup static int reiserfs_clean_and_file_buffer(struct buffer_head *bh) { if (bh) { clear_buffer_dirty(bh); - clear_bit(BH_JTest, &bh->b_state); + clear_buffer_journal_test(bh); } return 0 ; } @@ -388,41 +388,9 @@ static void free_cnode(struct super_bloc SB_JOURNAL(p_s_sb)->j_cnode_free_list = cn ; } -static int clear_prepared_bits(struct buffer_head *bh) { - clear_bit(BH_JPrepared, &bh->b_state) ; - clear_bit(BH_JRestore_dirty, &bh->b_state) ; - return 0 ; -} - -/* buffer is in current transaction */ -inline int buffer_journaled(const struct buffer_head *bh) { - if (bh) - return test_bit(BH_JDirty, &bh->b_state) ; - else - return 0 ; -} - -/* disk block was taken off free list before being in a finished transation, or written to disk -** journal_new blocks can be reused immediately, for any purpose -*/ -inline int buffer_journal_new(const struct buffer_head *bh) { - if (bh) - return test_bit(BH_JNew, &bh->b_state) ; - else - return 0 ; -} - -inline int mark_buffer_journal_new(struct buffer_head *bh) { - if (bh) { - set_bit(BH_JNew, &bh->b_state) ; - } - return 0 ; -} - -inline int mark_buffer_not_journaled(struct buffer_head *bh) { - if (bh) - clear_bit(BH_JDirty, &bh->b_state) ; - return 0 ; +static void clear_prepared_bits(struct buffer_head *bh) { + clear_buffer_journal_prepared (bh); + clear_buffer_journal_restore_dirty (bh); } /* utility function to force a BUG if it is called without the big @@ -628,9 +596,9 @@ static void reiserfs_end_ordered_io(stru static void submit_logged_buffer(struct buffer_head *bh) { get_bh(bh) ; bh->b_end_io = reiserfs_end_buffer_io_sync ; - mark_buffer_notjournal_new(bh) ; + clear_buffer_journal_new (bh); clear_buffer_dirty(bh) ; - if (!test_and_clear_bit(BH_JTest, &bh->b_state)) + if (!test_clear_buffer_journal_test (bh)) BUG(); if (!buffer_uptodate(bh)) BUG(); @@ -1383,7 +1351,7 @@ free_cnode: /* note, we must clear the JDirty_wait bit after the up to date ** check, otherwise we race against our flushpage routine */ - if (!test_and_clear_bit(BH_JDirty_wait, &cn->bh->b_state)) + if (!test_clear_buffer_journal_dirty (cn->bh)) BUG(); /* undo the inc from journal_mark_dirty */ @@ -1476,7 +1444,7 @@ static int write_one_transaction(struct lock_buffer(tmp_bh); if (cn->bh && can_dirty(cn) && buffer_dirty(tmp_bh)) { if (!buffer_journal_dirty(tmp_bh) || - reiserfs_buffer_prepared(tmp_bh)) + buffer_journal_prepared(tmp_bh)) BUG(); add_to_chunk(chunk, tmp_bh, NULL, write_chunk); ret++; @@ -1517,11 +1485,11 @@ static int dirty_one_transaction(struct * or restored. If restored, we need to make sure * it actually gets marked dirty */ - mark_buffer_notjournal_new(cn->bh) ; - if (test_bit(BH_JPrepared, &cn->bh->b_state)) { - set_bit(BH_JRestore_dirty, &cn->bh->b_state); + clear_buffer_journal_new (cn->bh); + if (buffer_journal_prepared (cn->bh)) { + set_buffer_journal_restore_dirty (cn->bh); } else { - set_bit(BH_JTest, &cn->bh->b_state); + set_buffer_journal_test (cn->bh); mark_buffer_dirty(cn->bh); } } @@ -2777,8 +2745,8 @@ int journal_mark_dirty(struct reiserfs_t } p_s_sb->s_dirt = 1; - prepared = test_and_clear_bit(BH_JPrepared, &bh->b_state) ; - clear_bit(BH_JRestore_dirty, &bh->b_state); + prepared = test_clear_buffer_journal_prepared (bh); + clear_buffer_journal_restore_dirty (bh); /* already in this transaction, we are done */ if (buffer_journaled(bh)) { PROC_INFO_INC( p_s_sb, journal.mark_dirty_already ); @@ -2812,14 +2780,14 @@ int journal_mark_dirty(struct reiserfs_t if (buffer_journal_dirty(bh)) { count_already_incd = 1 ; PROC_INFO_INC( p_s_sb, journal.mark_dirty_notjournal ); - mark_buffer_notjournal_dirty(bh) ; + clear_buffer_journal_dirty (bh); } if (SB_JOURNAL(p_s_sb)->j_len > SB_JOURNAL(p_s_sb)->j_len_alloc) { SB_JOURNAL(p_s_sb)->j_len_alloc = SB_JOURNAL(p_s_sb)->j_len + JOURNAL_PER_BALANCE_CNT ; } - set_bit(BH_JDirty, &bh->b_state) ; + set_buffer_journaled (bh); /* now put this guy on the end */ if (!cn) { @@ -2913,10 +2881,10 @@ static int remove_from_transaction(struc } if (bh) remove_journal_hash(p_s_sb, SB_JOURNAL(p_s_sb)->j_hash_table, NULL, bh->b_blocknr, 0) ; - mark_buffer_not_journaled(bh) ; /* don't log this one */ + clear_buffer_journaled (bh); /* don't log this one */ if (!already_cleaned) { - mark_buffer_notjournal_dirty(bh) ; + clear_buffer_journal_dirty (bh); put_bh(bh) ; if (atomic_read(&(bh->b_count)) < 0) { reiserfs_warning (p_s_sb, "journal-1752: remove from trans, b_count < 0"); @@ -3183,7 +3151,7 @@ int journal_mark_freed(struct reiserfs_t } /* if it is journal new, we just remove it from this transaction */ if (bh && buffer_journal_new(bh)) { - mark_buffer_notjournal_new(bh) ; + clear_buffer_journal_new (bh); clear_prepared_bits(bh) ; reiserfs_clean_and_file_buffer(bh) ; cleaned = remove_from_transaction(p_s_sb, blocknr, cleaned) ; @@ -3213,7 +3181,7 @@ int journal_mark_freed(struct reiserfs_t /* remove_from_transaction will brelse the buffer if it was ** in the current trans */ - mark_buffer_notjournal_dirty(cn->bh) ; + clear_buffer_journal_dirty (cn->bh); cleaned = 1 ; put_bh(cn->bh) ; if (atomic_read(&(cn->bh->b_count)) < 0) { @@ -3320,18 +3288,18 @@ void reiserfs_restore_prepared_buffer(st if (!bh) { return ; } - if (test_and_clear_bit(BH_JRestore_dirty, &bh->b_state) && + if (test_clear_buffer_journal_restore_dirty (bh) && buffer_journal_dirty(bh)) { struct reiserfs_journal_cnode *cn; cn = get_journal_hash_dev(p_s_sb, SB_JOURNAL(p_s_sb)->j_list_hash_table, bh->b_blocknr); if (cn && can_dirty(cn)) { - set_bit(BH_JTest, &bh->b_state); + set_buffer_journal_test (bh); mark_buffer_dirty(bh); } } - clear_bit(BH_JPrepared, &bh->b_state) ; + clear_buffer_journal_prepared (bh); } extern struct tree_balance *cur_tb ; @@ -3351,10 +3319,10 @@ int reiserfs_prepare_for_journal(struct return 0; lock_buffer(bh); } - set_bit(BH_JPrepared, &bh->b_state); + set_buffer_journal_prepared (bh); if (test_clear_buffer_dirty(bh) && buffer_journal_dirty(bh)) { - clear_bit(BH_JTest, &bh->b_state); - set_bit(BH_JRestore_dirty, &bh->b_state); + clear_buffer_journal_test (bh); + set_buffer_journal_restore_dirty (bh); } unlock_buffer(bh); return 1; @@ -3499,7 +3467,7 @@ static int do_journal_end(struct reiserf */ trans_half = journal_trans_half(p_s_sb->s_blocksize); for (i = 0, cn = SB_JOURNAL(p_s_sb)->j_first ; cn ; cn = cn->next, i++) { - if (test_bit(BH_JDirty, &cn->bh->b_state) ) { + if (buffer_journaled (cn->bh)) { jl_cn = get_cnode(p_s_sb) ; if (!jl_cn) { reiserfs_panic(p_s_sb, "journal-1676, get_cnode returned NULL\n") ; @@ -3555,9 +3523,9 @@ static int do_journal_end(struct reiserf cn = SB_JOURNAL(p_s_sb)->j_first ; jindex = 1 ; /* start at one so we don't get the desc again */ while(cn) { - clear_bit(BH_JNew, &(cn->bh->b_state)) ; + clear_buffer_journal_new (cn->bh); /* copy all the real blocks into log area. dirty log blocks */ - if (test_bit(BH_JDirty, &cn->bh->b_state)) { + if (buffer_journaled (cn->bh)) { struct buffer_head *tmp_bh ; char *addr; struct page *page; @@ -3571,8 +3539,8 @@ static int do_journal_end(struct reiserf kunmap(page); mark_buffer_dirty(tmp_bh); jindex++ ; - set_bit(BH_JDirty_wait, &(cn->bh->b_state)) ; - clear_bit(BH_JDirty, &(cn->bh->b_state)) ; + set_buffer_journal_dirty (cn->bh); + clear_buffer_journaled (cn->bh); } else { /* JDirty cleared sometime during transaction. don't log this one */ reiserfs_warning(p_s_sb, "journal-2048: do_journal_end: BAD, buffer in journal hash, but not JDirty!") ; diff -puN fs/reiserfs/namei.c~reiserfs-cleanup-internal-use-of-bh-macros fs/reiserfs/namei.c --- 25/fs/reiserfs/namei.c~reiserfs-cleanup-internal-use-of-bh-macros 2004-10-05 11:10:22.179832368 -0700 +++ 25-akpm/fs/reiserfs/namei.c 2004-10-05 11:10:22.193830240 -0700 @@ -1289,7 +1289,7 @@ static int reiserfs_rename (struct inode } RFALSE( S_ISDIR(old_inode_mode) && - !reiserfs_buffer_prepared(dot_dot_de.de_bh), "" ); + !buffer_journal_prepared(dot_dot_de.de_bh), "" ); break; } diff -puN include/linux/reiserfs_fs.h~reiserfs-cleanup-internal-use-of-bh-macros include/linux/reiserfs_fs.h --- 25/include/linux/reiserfs_fs.h~reiserfs-cleanup-internal-use-of-bh-macros 2004-10-05 11:10:22.181832064 -0700 +++ 25-akpm/include/linux/reiserfs_fs.h 2004-10-05 11:10:22.195829936 -0700 @@ -1711,14 +1711,29 @@ struct reiserfs_journal_header { #define journal_bread(s, block) __bread(SB_JOURNAL(s)->j_dev_bd, block, s->s_blocksize) enum reiserfs_bh_state_bits { - BH_JDirty = BH_PrivateStart, + BH_JDirty = BH_PrivateStart, /* buffer is in current transaction */ BH_JDirty_wait, - BH_JNew, + BH_JNew, /* disk block was taken off free list before + * being in a finished transaction, or + * written to disk. Can be reused immed. */ BH_JPrepared, BH_JRestore_dirty, BH_JTest, // debugging only will go away }; +BUFFER_FNS(JDirty, journaled); +TAS_BUFFER_FNS(JDirty, journaled); +BUFFER_FNS(JDirty_wait, journal_dirty); +TAS_BUFFER_FNS(JDirty_wait, journal_dirty); +BUFFER_FNS(JNew, journal_new); +TAS_BUFFER_FNS(JNew, journal_new); +BUFFER_FNS(JPrepared, journal_prepared); +TAS_BUFFER_FNS(JPrepared, journal_prepared); +BUFFER_FNS(JRestore_dirty, journal_restore_dirty); +TAS_BUFFER_FNS(JRestore_dirty, journal_restore_dirty); +BUFFER_FNS(JTest, journal_test); +TAS_BUFFER_FNS(JTest, journal_test); + /* ** transaction handle which is passed around for all journal calls */ @@ -1796,37 +1811,8 @@ int journal_transaction_should_end(struc int reiserfs_in_journal(struct super_block *p_s_sb, 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 buffer_journaled(const struct buffer_head *bh) ; -int mark_buffer_journal_new(struct buffer_head *bh) ; int reiserfs_allocate_list_bitmaps(struct super_block *s, struct reiserfs_list_bitmap *, int) ; - /* why is this kerplunked right here? */ -static inline int reiserfs_buffer_prepared(const struct buffer_head *bh) { - if (bh && test_bit(BH_JPrepared, &bh->b_state)) - return 1 ; - else - return 0 ; -} - -/* buffer was journaled, waiting to get to disk */ -static inline int buffer_journal_dirty(const struct buffer_head *bh) { - if (bh) - return test_bit(BH_JDirty_wait, &bh->b_state) ; - else - return 0 ; -} -static inline int mark_buffer_notjournal_dirty(struct buffer_head *bh) { - if (bh) - clear_bit(BH_JDirty_wait, &bh->b_state) ; - return 0 ; -} -static inline int mark_buffer_notjournal_new(struct buffer_head *bh) { - if (bh) { - clear_bit(BH_JNew, &bh->b_state) ; - } - return 0 ; -} - void add_save_link (struct reiserfs_transaction_handle * th, struct inode * inode, int truncate); void remove_save_link (struct inode * inode, int truncate); _