Skip to content

Commit 6f17400

Browse files
adam900710kdave
authored andcommitted
btrfs: introduce helpers for subpage ordered status
This patch introduces the following functions to handle btrfs subpage ordered (Private2) status: - btrfs_subpage_set_ordered() - btrfs_subpage_clear_ordered() - btrfs_subpage_test_ordered() These helpers can only be called when the range is ensured to be inside the page. - btrfs_page_set_ordered() - btrfs_page_clear_ordered() - btrfs_page_test_ordered() These helpers can handle both regular sector size and subpage without problem. These functions are here to coordinate btrfs_invalidatepage() with btrfs_writepage_endio_finish_ordered(), to make sure only one of those functions can finish the ordered extent. Tested-by: Ritesh Harjani <riteshh@linux.ibm.com> # [ppc64] Tested-by: Anand Jain <anand.jain@oracle.com> # [aarch64] Signed-off-by: Qu Wenruo <wqu@suse.com> Signed-off-by: David Sterba <dsterba@suse.com>
1 parent 1e1de38 commit 6f17400

File tree

2 files changed

+33
-0
lines changed

2 files changed

+33
-0
lines changed

fs/btrfs/subpage.c

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -429,6 +429,32 @@ void btrfs_subpage_clear_writeback(const struct btrfs_fs_info *fs_info,
429429
spin_unlock_irqrestore(&subpage->lock, flags);
430430
}
431431

432+
void btrfs_subpage_set_ordered(const struct btrfs_fs_info *fs_info,
433+
struct page *page, u64 start, u32 len)
434+
{
435+
struct btrfs_subpage *subpage = (struct btrfs_subpage *)page->private;
436+
const u16 tmp = btrfs_subpage_calc_bitmap(fs_info, page, start, len);
437+
unsigned long flags;
438+
439+
spin_lock_irqsave(&subpage->lock, flags);
440+
subpage->ordered_bitmap |= tmp;
441+
SetPageOrdered(page);
442+
spin_unlock_irqrestore(&subpage->lock, flags);
443+
}
444+
445+
void btrfs_subpage_clear_ordered(const struct btrfs_fs_info *fs_info,
446+
struct page *page, u64 start, u32 len)
447+
{
448+
struct btrfs_subpage *subpage = (struct btrfs_subpage *)page->private;
449+
const u16 tmp = btrfs_subpage_calc_bitmap(fs_info, page, start, len);
450+
unsigned long flags;
451+
452+
spin_lock_irqsave(&subpage->lock, flags);
453+
subpage->ordered_bitmap &= ~tmp;
454+
if (subpage->ordered_bitmap == 0)
455+
ClearPageOrdered(page);
456+
spin_unlock_irqrestore(&subpage->lock, flags);
457+
}
432458
/*
433459
* Unlike set/clear which is dependent on each page status, for test all bits
434460
* are tested in the same way.
@@ -451,6 +477,7 @@ IMPLEMENT_BTRFS_SUBPAGE_TEST_OP(uptodate);
451477
IMPLEMENT_BTRFS_SUBPAGE_TEST_OP(error);
452478
IMPLEMENT_BTRFS_SUBPAGE_TEST_OP(dirty);
453479
IMPLEMENT_BTRFS_SUBPAGE_TEST_OP(writeback);
480+
IMPLEMENT_BTRFS_SUBPAGE_TEST_OP(ordered);
454481

455482
/*
456483
* Note that, in selftests (extent-io-tests), we can have empty fs_info passed
@@ -519,3 +546,5 @@ IMPLEMENT_BTRFS_PAGE_OPS(dirty, set_page_dirty, clear_page_dirty_for_io,
519546
PageDirty);
520547
IMPLEMENT_BTRFS_PAGE_OPS(writeback, set_page_writeback, end_page_writeback,
521548
PageWriteback);
549+
IMPLEMENT_BTRFS_PAGE_OPS(ordered, SetPageOrdered, ClearPageOrdered,
550+
PageOrdered);

fs/btrfs/subpage.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,9 @@ struct btrfs_subpage {
3434
struct {
3535
atomic_t readers;
3636
atomic_t writers;
37+
38+
/* Tracke pending ordered extent in this sector */
39+
u16 ordered_bitmap;
3740
};
3841
};
3942
};
@@ -111,6 +114,7 @@ DECLARE_BTRFS_SUBPAGE_OPS(uptodate);
111114
DECLARE_BTRFS_SUBPAGE_OPS(error);
112115
DECLARE_BTRFS_SUBPAGE_OPS(dirty);
113116
DECLARE_BTRFS_SUBPAGE_OPS(writeback);
117+
DECLARE_BTRFS_SUBPAGE_OPS(ordered);
114118

115119
bool btrfs_subpage_clear_and_test_dirty(const struct btrfs_fs_info *fs_info,
116120
struct page *page, u64 start, u32 len);

0 commit comments

Comments
 (0)