nilfs2: use set_mask_bits() for operations on buffer state bitmap

nilfs_forget_buffer(), nilfs_clear_dirty_page(), and
nilfs_segctor_complete_write() are using a bunch of atomic bit operations
against buffer state bitmap.

This reduces the number of them by utilizing set_mask_bits() macro.

Signed-off-by: Ryusuke Konishi <konishi.ryusuke@lab.ntt.co.jp>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
This commit is contained in:
Ryusuke Konishi 2015-04-16 12:46:28 -07:00 committed by Linus Torvalds
parent 6fb7a61e98
commit ead8ecffa3
2 changed files with 18 additions and 20 deletions

View File

@ -89,18 +89,16 @@ struct buffer_head *nilfs_grab_buffer(struct inode *inode,
void nilfs_forget_buffer(struct buffer_head *bh) void nilfs_forget_buffer(struct buffer_head *bh)
{ {
struct page *page = bh->b_page; struct page *page = bh->b_page;
const unsigned long clear_bits =
(1 << BH_Uptodate | 1 << BH_Dirty | 1 << BH_Mapped |
1 << BH_Async_Write | 1 << BH_NILFS_Volatile |
1 << BH_NILFS_Checked | 1 << BH_NILFS_Redirected);
lock_buffer(bh); lock_buffer(bh);
clear_buffer_nilfs_volatile(bh); set_mask_bits(&bh->b_state, clear_bits, 0);
clear_buffer_nilfs_checked(bh);
clear_buffer_nilfs_redirected(bh);
clear_buffer_async_write(bh);
clear_buffer_dirty(bh);
if (nilfs_page_buffers_clean(page)) if (nilfs_page_buffers_clean(page))
__nilfs_clear_page_dirty(page); __nilfs_clear_page_dirty(page);
clear_buffer_uptodate(bh);
clear_buffer_mapped(bh);
bh->b_blocknr = -1; bh->b_blocknr = -1;
ClearPageUptodate(page); ClearPageUptodate(page);
ClearPageMappedToDisk(page); ClearPageMappedToDisk(page);
@ -421,6 +419,10 @@ void nilfs_clear_dirty_page(struct page *page, bool silent)
if (page_has_buffers(page)) { if (page_has_buffers(page)) {
struct buffer_head *bh, *head; struct buffer_head *bh, *head;
const unsigned long clear_bits =
(1 << BH_Uptodate | 1 << BH_Dirty | 1 << BH_Mapped |
1 << BH_Async_Write | 1 << BH_NILFS_Volatile |
1 << BH_NILFS_Checked | 1 << BH_NILFS_Redirected);
bh = head = page_buffers(page); bh = head = page_buffers(page);
do { do {
@ -430,13 +432,7 @@ void nilfs_clear_dirty_page(struct page *page, bool silent)
"discard block %llu, size %zu", "discard block %llu, size %zu",
(u64)bh->b_blocknr, bh->b_size); (u64)bh->b_blocknr, bh->b_size);
} }
clear_buffer_async_write(bh); set_mask_bits(&bh->b_state, clear_bits, 0);
clear_buffer_dirty(bh);
clear_buffer_nilfs_volatile(bh);
clear_buffer_nilfs_checked(bh);
clear_buffer_nilfs_redirected(bh);
clear_buffer_uptodate(bh);
clear_buffer_mapped(bh);
unlock_buffer(bh); unlock_buffer(bh);
} while (bh = bh->b_this_page, bh != head); } while (bh = bh->b_this_page, bh != head);
} }

View File

@ -24,6 +24,7 @@
#include <linux/pagemap.h> #include <linux/pagemap.h>
#include <linux/buffer_head.h> #include <linux/buffer_head.h>
#include <linux/writeback.h> #include <linux/writeback.h>
#include <linux/bitops.h>
#include <linux/bio.h> #include <linux/bio.h>
#include <linux/completion.h> #include <linux/completion.h>
#include <linux/blkdev.h> #include <linux/blkdev.h>
@ -1785,12 +1786,13 @@ static void nilfs_segctor_complete_write(struct nilfs_sc_info *sci)
*/ */
list_for_each_entry(bh, &segbuf->sb_payload_buffers, list_for_each_entry(bh, &segbuf->sb_payload_buffers,
b_assoc_buffers) { b_assoc_buffers) {
set_buffer_uptodate(bh); const unsigned long set_bits = (1 << BH_Uptodate);
clear_buffer_dirty(bh); const unsigned long clear_bits =
clear_buffer_async_write(bh); (1 << BH_Dirty | 1 << BH_Async_Write |
clear_buffer_delay(bh); 1 << BH_Delay | 1 << BH_NILFS_Volatile |
clear_buffer_nilfs_volatile(bh); 1 << BH_NILFS_Redirected);
clear_buffer_nilfs_redirected(bh);
set_mask_bits(&bh->b_state, clear_bits, set_bits);
if (bh == segbuf->sb_super_root) { if (bh == segbuf->sb_super_root) {
if (bh->b_page != bd_page) { if (bh->b_page != bd_page) {
end_page_writeback(bd_page); end_page_writeback(bd_page);