Skip to content

Commit 32430c6

Browse files
naotakdave
authored andcommitted
btrfs: zoned: enable relocation on a zoned filesystem
Currently fallocate() is disabled on a zoned filesystem. Since current relocation process relies on preallocation to move file data extents, it must be handled differently. On a zoned filesystem, we just truncate the inode to the size that we wanted to pre-allocate. Then, we flush dirty pages on the file before finishing the relocation process. run_delalloc_zoned() will handle all the allocations and submit IOs to the underlying layers. Reviewed-by: Josef Bacik <[email protected]> Signed-off-by: Naohiro Aota <[email protected]> Signed-off-by: David Sterba <[email protected]>
1 parent 7db1c5d commit 32430c6

File tree

1 file changed

+32
-2
lines changed

1 file changed

+32
-2
lines changed

fs/btrfs/relocation.c

Lines changed: 32 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2553,6 +2553,31 @@ static noinline_for_stack int prealloc_file_extent_cluster(
25532553
if (ret)
25542554
return ret;
25552555

2556+
/*
2557+
* On a zoned filesystem, we cannot preallocate the file region.
2558+
* Instead, we dirty and fiemap_write the region.
2559+
*/
2560+
if (btrfs_is_zoned(inode->root->fs_info)) {
2561+
struct btrfs_root *root = inode->root;
2562+
struct btrfs_trans_handle *trans;
2563+
2564+
end = cluster->end - offset + 1;
2565+
trans = btrfs_start_transaction(root, 1);
2566+
if (IS_ERR(trans))
2567+
return PTR_ERR(trans);
2568+
2569+
inode->vfs_inode.i_ctime = current_time(&inode->vfs_inode);
2570+
i_size_write(&inode->vfs_inode, end);
2571+
ret = btrfs_update_inode(trans, root, inode);
2572+
if (ret) {
2573+
btrfs_abort_transaction(trans, ret);
2574+
btrfs_end_transaction(trans);
2575+
return ret;
2576+
}
2577+
2578+
return btrfs_end_transaction(trans);
2579+
}
2580+
25562581
inode_lock(&inode->vfs_inode);
25572582
for (nr = 0; nr < cluster->nr; nr++) {
25582583
start = cluster->boundary[nr] - offset;
@@ -2756,6 +2781,8 @@ static int relocate_file_extent_cluster(struct inode *inode,
27562781
}
27572782
}
27582783
WARN_ON(nr != cluster->nr);
2784+
if (btrfs_is_zoned(fs_info) && !ret)
2785+
ret = btrfs_wait_ordered_range(inode, 0, (u64)-1);
27592786
out:
27602787
kfree(ra);
27612788
return ret;
@@ -3434,8 +3461,12 @@ static int __insert_orphan_inode(struct btrfs_trans_handle *trans,
34343461
struct btrfs_path *path;
34353462
struct btrfs_inode_item *item;
34363463
struct extent_buffer *leaf;
3464+
u64 flags = BTRFS_INODE_NOCOMPRESS | BTRFS_INODE_PREALLOC;
34373465
int ret;
34383466

3467+
if (btrfs_is_zoned(trans->fs_info))
3468+
flags &= ~BTRFS_INODE_PREALLOC;
3469+
34393470
path = btrfs_alloc_path();
34403471
if (!path)
34413472
return -ENOMEM;
@@ -3450,8 +3481,7 @@ static int __insert_orphan_inode(struct btrfs_trans_handle *trans,
34503481
btrfs_set_inode_generation(leaf, item, 1);
34513482
btrfs_set_inode_size(leaf, item, 0);
34523483
btrfs_set_inode_mode(leaf, item, S_IFREG | 0600);
3453-
btrfs_set_inode_flags(leaf, item, BTRFS_INODE_NOCOMPRESS |
3454-
BTRFS_INODE_PREALLOC);
3484+
btrfs_set_inode_flags(leaf, item, flags);
34553485
btrfs_mark_buffer_dirty(leaf);
34563486
out:
34573487
btrfs_free_path(path);

0 commit comments

Comments
 (0)