mirror of https://gitee.com/openkylin/linux.git
btrfs: subpage: introduce helpers for dirty status
Introduce the following functions to handle subpage dirty status: - btrfs_subpage_set_dirty() - btrfs_subpage_clear_dirty() - btrfs_subpage_test_dirty() These helpers can only be called when the range is ensured to be inside the page. - btrfs_page_set_dirty() - btrfs_page_clear_dirty() - btrfs_page_test_dirty() These helpers can handle both regular sector size and subpage without problem. Thus they would be used to replace PageDirty() related calls in later patches. There is one special point to note here, just like set_page_dirty() and clear_page_dirty_for_io(), btrfs_*page_set_dirty() and btrfs_*page_clear_dirty() must be called with page locked. Signed-off-by: Qu Wenruo <wqu@suse.com> Reviewed-by: David Sterba <dsterba@suse.com> Signed-off-by: David Sterba <dsterba@suse.com>
This commit is contained in:
parent
d239bcb83b
commit
d8a5713e89
|
@ -220,6 +220,55 @@ void btrfs_subpage_clear_error(const struct btrfs_fs_info *fs_info,
|
|||
spin_unlock_irqrestore(&subpage->lock, flags);
|
||||
}
|
||||
|
||||
void btrfs_subpage_set_dirty(const struct btrfs_fs_info *fs_info,
|
||||
struct page *page, u64 start, u32 len)
|
||||
{
|
||||
struct btrfs_subpage *subpage = (struct btrfs_subpage *)page->private;
|
||||
u16 tmp = btrfs_subpage_calc_bitmap(fs_info, page, start, len);
|
||||
unsigned long flags;
|
||||
|
||||
spin_lock_irqsave(&subpage->lock, flags);
|
||||
subpage->dirty_bitmap |= tmp;
|
||||
spin_unlock_irqrestore(&subpage->lock, flags);
|
||||
set_page_dirty(page);
|
||||
}
|
||||
|
||||
/*
|
||||
* Extra clear_and_test function for subpage dirty bitmap.
|
||||
*
|
||||
* Return true if we're the last bits in the dirty_bitmap and clear the
|
||||
* dirty_bitmap.
|
||||
* Return false otherwise.
|
||||
*
|
||||
* NOTE: Callers should manually clear page dirty for true case, as we have
|
||||
* extra handling for tree blocks.
|
||||
*/
|
||||
bool btrfs_subpage_clear_and_test_dirty(const struct btrfs_fs_info *fs_info,
|
||||
struct page *page, u64 start, u32 len)
|
||||
{
|
||||
struct btrfs_subpage *subpage = (struct btrfs_subpage *)page->private;
|
||||
u16 tmp = btrfs_subpage_calc_bitmap(fs_info, page, start, len);
|
||||
unsigned long flags;
|
||||
bool last = false;
|
||||
|
||||
spin_lock_irqsave(&subpage->lock, flags);
|
||||
subpage->dirty_bitmap &= ~tmp;
|
||||
if (subpage->dirty_bitmap == 0)
|
||||
last = true;
|
||||
spin_unlock_irqrestore(&subpage->lock, flags);
|
||||
return last;
|
||||
}
|
||||
|
||||
void btrfs_subpage_clear_dirty(const struct btrfs_fs_info *fs_info,
|
||||
struct page *page, u64 start, u32 len)
|
||||
{
|
||||
bool last;
|
||||
|
||||
last = btrfs_subpage_clear_and_test_dirty(fs_info, page, start, len);
|
||||
if (last)
|
||||
clear_page_dirty_for_io(page);
|
||||
}
|
||||
|
||||
/*
|
||||
* Unlike set/clear which is dependent on each page status, for test all bits
|
||||
* are tested in the same way.
|
||||
|
@ -240,6 +289,7 @@ bool btrfs_subpage_test_##name(const struct btrfs_fs_info *fs_info, \
|
|||
}
|
||||
IMPLEMENT_BTRFS_SUBPAGE_TEST_OP(uptodate);
|
||||
IMPLEMENT_BTRFS_SUBPAGE_TEST_OP(error);
|
||||
IMPLEMENT_BTRFS_SUBPAGE_TEST_OP(dirty);
|
||||
|
||||
/*
|
||||
* Note that, in selftests (extent-io-tests), we can have empty fs_info passed
|
||||
|
@ -276,3 +326,5 @@ bool btrfs_page_test_##name(const struct btrfs_fs_info *fs_info, \
|
|||
IMPLEMENT_BTRFS_PAGE_OPS(uptodate, SetPageUptodate, ClearPageUptodate,
|
||||
PageUptodate);
|
||||
IMPLEMENT_BTRFS_PAGE_OPS(error, SetPageError, ClearPageError, PageError);
|
||||
IMPLEMENT_BTRFS_PAGE_OPS(dirty, set_page_dirty, clear_page_dirty_for_io,
|
||||
PageDirty);
|
||||
|
|
|
@ -20,6 +20,7 @@ struct btrfs_subpage {
|
|||
spinlock_t lock;
|
||||
u16 uptodate_bitmap;
|
||||
u16 error_bitmap;
|
||||
u16 dirty_bitmap;
|
||||
union {
|
||||
/*
|
||||
* Structures only used by metadata
|
||||
|
@ -87,5 +88,9 @@ bool btrfs_page_test_##name(const struct btrfs_fs_info *fs_info, \
|
|||
|
||||
DECLARE_BTRFS_SUBPAGE_OPS(uptodate);
|
||||
DECLARE_BTRFS_SUBPAGE_OPS(error);
|
||||
DECLARE_BTRFS_SUBPAGE_OPS(dirty);
|
||||
|
||||
bool btrfs_subpage_clear_and_test_dirty(const struct btrfs_fs_info *fs_info,
|
||||
struct page *page, u64 start, u32 len);
|
||||
|
||||
#endif
|
||||
|
|
Loading…
Reference in New Issue