Commit ba9145ad authored by Christoph Hellwig's avatar Christoph Hellwig Committed by David Sterba

btrfs: pass a flags argument to cow_file_range

The int used as bool unlock is not a very good way to describe the
behavior, and the next patch will have to add another behavior modifier.
We'll do that by two bool parameters instead of adding bit flags.  Now
specifies that the pages should always be kept locked.  This is the
inverse of the old unlock argument.
Reviewed-by: default avatarJosef Bacik <josef@toxicpanda.com>
Signed-off-by: default avatarChristoph Hellwig <hch@lst.de>
Reviewed-by: default avatarDavid Sterba <dsterba@suse.com>
[ switch flags to bool ]
Signed-off-by: default avatarDavid Sterba <dsterba@suse.com>
parent a6496849
...@@ -124,11 +124,12 @@ static struct kmem_cache *btrfs_inode_cachep; ...@@ -124,11 +124,12 @@ static struct kmem_cache *btrfs_inode_cachep;
static int btrfs_setsize(struct inode *inode, struct iattr *attr); static int btrfs_setsize(struct inode *inode, struct iattr *attr);
static int btrfs_truncate(struct btrfs_inode *inode, bool skip_writeback); static int btrfs_truncate(struct btrfs_inode *inode, bool skip_writeback);
static noinline int cow_file_range(struct btrfs_inode *inode, static noinline int cow_file_range(struct btrfs_inode *inode,
struct page *locked_page, struct page *locked_page,
u64 start, u64 end, int *page_started, u64 start, u64 end, int *page_started,
unsigned long *nr_written, int unlock, unsigned long *nr_written, u64 *done_offset,
u64 *done_offset); bool keep_locked);
static struct extent_map *create_io_em(struct btrfs_inode *inode, u64 start, static struct extent_map *create_io_em(struct btrfs_inode *inode, u64 start,
u64 len, u64 orig_start, u64 block_start, u64 len, u64 orig_start, u64 block_start,
u64 block_len, u64 orig_block_len, u64 block_len, u64 orig_block_len,
...@@ -1148,7 +1149,7 @@ static int submit_uncompressed_range(struct btrfs_inode *inode, ...@@ -1148,7 +1149,7 @@ static int submit_uncompressed_range(struct btrfs_inode *inode,
* can directly submit them without interruption. * can directly submit them without interruption.
*/ */
ret = cow_file_range(inode, locked_page, start, end, &page_started, ret = cow_file_range(inode, locked_page, start, end, &page_started,
&nr_written, 0, NULL); &nr_written, NULL, true);
/* Inline extent inserted, page gets unlocked and everything is done */ /* Inline extent inserted, page gets unlocked and everything is done */
if (page_started) if (page_started)
return 0; return 0;
...@@ -1361,25 +1362,18 @@ static u64 get_extent_allocation_hint(struct btrfs_inode *inode, u64 start, ...@@ -1361,25 +1362,18 @@ static u64 get_extent_allocation_hint(struct btrfs_inode *inode, u64 start,
* locked_page is the page that writepage had locked already. We use * locked_page is the page that writepage had locked already. We use
* it to make sure we don't do extra locks or unlocks. * it to make sure we don't do extra locks or unlocks.
* *
* *page_started is set to one if we unlock locked_page and do everything * When this function fails, it unlocks all pages except @locked_page.
* required to start IO on it. It may be clean and already done with
* IO when we return.
*
* When unlock == 1, we unlock the pages in successfully allocated regions.
* When unlock == 0, we leave them locked for writing them out.
* *
* However, we unlock all the pages except @locked_page in case of failure. * When this function successfully creates an inline extent, it sets page_started
* to 1 and unlocks all pages including locked_page and starts I/O on them.
* (In reality inline extents are limited to a single page, so locked_page is
* the only page handled anyway).
* *
* In summary, page locking state will be as follow: * When this function succeed and creates a normal extent, the page locking
* status depends on the passed in flags:
* *
* - page_started == 1 (return value) * - If @keep_locked is set, all pages are kept locked.
* - All the pages are unlocked. IO is started. * - Else all pages except for @locked_page are unlocked.
* - Note that this can happen only on success
* - unlock == 1
* - All the pages except @locked_page are unlocked in any case
* - unlock == 0
* - On success, all the pages are locked for writing out them
* - On failure, all the pages except @locked_page are unlocked
* *
* When a failure happens in the second or later iteration of the * When a failure happens in the second or later iteration of the
* while-loop, the ordered extents created in previous iterations are kept * while-loop, the ordered extents created in previous iterations are kept
...@@ -1390,8 +1384,8 @@ static u64 get_extent_allocation_hint(struct btrfs_inode *inode, u64 start, ...@@ -1390,8 +1384,8 @@ static u64 get_extent_allocation_hint(struct btrfs_inode *inode, u64 start,
static noinline int cow_file_range(struct btrfs_inode *inode, static noinline int cow_file_range(struct btrfs_inode *inode,
struct page *locked_page, struct page *locked_page,
u64 start, u64 end, int *page_started, u64 start, u64 end, int *page_started,
unsigned long *nr_written, int unlock, unsigned long *nr_written, u64 *done_offset,
u64 *done_offset) bool keep_locked)
{ {
struct btrfs_root *root = inode->root; struct btrfs_root *root = inode->root;
struct btrfs_fs_info *fs_info = root->fs_info; struct btrfs_fs_info *fs_info = root->fs_info;
...@@ -1557,7 +1551,7 @@ static noinline int cow_file_range(struct btrfs_inode *inode, ...@@ -1557,7 +1551,7 @@ static noinline int cow_file_range(struct btrfs_inode *inode,
* Do set the Ordered (Private2) bit so we know this page was * Do set the Ordered (Private2) bit so we know this page was
* properly setup for writepage. * properly setup for writepage.
*/ */
page_ops = unlock ? PAGE_UNLOCK : 0; page_ops = (keep_locked ? 0 : PAGE_UNLOCK);
page_ops |= PAGE_SET_ORDERED; page_ops |= PAGE_SET_ORDERED;
extent_clear_unlock_delalloc(inode, start, start + ram_size - 1, extent_clear_unlock_delalloc(inode, start, start + ram_size - 1,
...@@ -1626,10 +1620,10 @@ static noinline int cow_file_range(struct btrfs_inode *inode, ...@@ -1626,10 +1620,10 @@ static noinline int cow_file_range(struct btrfs_inode *inode,
* EXTENT_DEFRAG | EXTENT_CLEAR_META_RESV are handled by the cleanup * EXTENT_DEFRAG | EXTENT_CLEAR_META_RESV are handled by the cleanup
* function. * function.
* *
* However, in case of unlock == 0, we still need to unlock the pages * However, in case of @keep_locked, we still need to unlock the pages
* (except @locked_page) to ensure all the pages are unlocked. * (except @locked_page) to ensure all the pages are unlocked.
*/ */
if (!unlock && orig_start < start) { if (keep_locked && orig_start < start) {
if (!locked_page) if (!locked_page)
mapping_set_error(inode->vfs_inode.i_mapping, ret); mapping_set_error(inode->vfs_inode.i_mapping, ret);
extent_clear_unlock_delalloc(inode, orig_start, start - 1, extent_clear_unlock_delalloc(inode, orig_start, start - 1,
...@@ -1835,7 +1829,7 @@ static noinline int run_delalloc_zoned(struct btrfs_inode *inode, ...@@ -1835,7 +1829,7 @@ static noinline int run_delalloc_zoned(struct btrfs_inode *inode,
while (start <= end) { while (start <= end) {
ret = cow_file_range(inode, locked_page, start, end, page_started, ret = cow_file_range(inode, locked_page, start, end, page_started,
nr_written, 0, &done_offset); nr_written, &done_offset, true);
if (ret && ret != -EAGAIN) if (ret && ret != -EAGAIN)
return ret; return ret;
...@@ -1955,7 +1949,7 @@ static int fallback_to_cow(struct btrfs_inode *inode, struct page *locked_page, ...@@ -1955,7 +1949,7 @@ static int fallback_to_cow(struct btrfs_inode *inode, struct page *locked_page,
} }
return cow_file_range(inode, locked_page, start, end, page_started, return cow_file_range(inode, locked_page, start, end, page_started,
nr_written, 1, NULL); nr_written, NULL, false);
} }
struct can_nocow_file_extent_args { struct can_nocow_file_extent_args {
...@@ -2432,7 +2426,7 @@ int btrfs_run_delalloc_range(struct btrfs_inode *inode, struct page *locked_page ...@@ -2432,7 +2426,7 @@ int btrfs_run_delalloc_range(struct btrfs_inode *inode, struct page *locked_page
page_started, nr_written, wbc); page_started, nr_written, wbc);
else else
ret = cow_file_range(inode, locked_page, start, end, ret = cow_file_range(inode, locked_page, start, end,
page_started, nr_written, 1, NULL); page_started, nr_written, NULL, false);
out: out:
ASSERT(ret <= 0); ASSERT(ret <= 0);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment