Message ID | c4b3a3a5192fe56f7b2e1d1ec91046ec27eb1a02.1714722726.git.anand.jain@oracle.com (mailing list archive) |
---|---|
State | New, archived |
Headers | show |
Series | btrfs-progs: add support ext4 unwritten file extent | expand |
On Fri, May 03, 2024 at 05:08:54PM +0800, Anand Jain wrote: > This preparatory patch adds an argument '%prealloc' to the function > __btrfs_record_file_extent(), to be used in the following patches. > > Signed-off-by: Anand Jain <anand.jain@oracle.com> > --- > common/extent-tree-utils.c | 11 +++++++---- > common/extent-tree-utils.h | 2 +- > convert/main.c | 9 +++++---- > convert/source-fs.c | 5 +++-- > convert/source-reiserfs.c | 2 +- > mkfs/rootdir.c | 3 ++- > 6 files changed, 19 insertions(+), 13 deletions(-) > > diff --git a/common/extent-tree-utils.c b/common/extent-tree-utils.c > index 34c7e5095160..2ccac6b44cea 100644 > --- a/common/extent-tree-utils.c > +++ b/common/extent-tree-utils.c > @@ -122,7 +122,7 @@ static int __btrfs_record_file_extent(struct btrfs_trans_handle *trans, > struct btrfs_root *root, u64 objectid, > struct btrfs_inode_item *inode, > u64 file_pos, u64 disk_bytenr, > - u64 *ret_num_bytes) > + u64 *ret_num_bytes, bool prealloc) > { > int ret; > struct btrfs_fs_info *info = root->fs_info; > @@ -229,7 +229,10 @@ static int __btrfs_record_file_extent(struct btrfs_trans_handle *trans, > leaf = path->nodes[0]; > fi = btrfs_item_ptr(leaf, path->slots[0], struct btrfs_file_extent_item); > btrfs_set_file_extent_generation(leaf, fi, trans->transid); > - btrfs_set_file_extent_type(leaf, fi, BTRFS_FILE_EXTENT_REG); > + if (prealloc) > + btrfs_set_file_extent_type(leaf, fi, BTRFS_FILE_EXTENT_PREALLOC); > + else > + btrfs_set_file_extent_type(leaf, fi, BTRFS_FILE_EXTENT_REG); The bool parameter makes it less clear what it means in all the callers, as it is supposed to select the type of extent you could pass the BTRFS_FILE_ExTENT_ constant directly.
On 5/3/24 19:50, David Sterba wrote: > On Fri, May 03, 2024 at 05:08:54PM +0800, Anand Jain wrote: >> This preparatory patch adds an argument '%prealloc' to the function >> __btrfs_record_file_extent(), to be used in the following patches. >> >> Signed-off-by: Anand Jain <anand.jain@oracle.com> >> --- >> common/extent-tree-utils.c | 11 +++++++---- >> common/extent-tree-utils.h | 2 +- >> convert/main.c | 9 +++++---- >> convert/source-fs.c | 5 +++-- >> convert/source-reiserfs.c | 2 +- >> mkfs/rootdir.c | 3 ++- >> 6 files changed, 19 insertions(+), 13 deletions(-) >> >> diff --git a/common/extent-tree-utils.c b/common/extent-tree-utils.c >> index 34c7e5095160..2ccac6b44cea 100644 >> --- a/common/extent-tree-utils.c >> +++ b/common/extent-tree-utils.c >> @@ -122,7 +122,7 @@ static int __btrfs_record_file_extent(struct btrfs_trans_handle *trans, >> struct btrfs_root *root, u64 objectid, >> struct btrfs_inode_item *inode, >> u64 file_pos, u64 disk_bytenr, >> - u64 *ret_num_bytes) >> + u64 *ret_num_bytes, bool prealloc) >> { >> int ret; >> struct btrfs_fs_info *info = root->fs_info; >> @@ -229,7 +229,10 @@ static int __btrfs_record_file_extent(struct btrfs_trans_handle *trans, >> leaf = path->nodes[0]; >> fi = btrfs_item_ptr(leaf, path->slots[0], struct btrfs_file_extent_item); >> btrfs_set_file_extent_generation(leaf, fi, trans->transid); >> - btrfs_set_file_extent_type(leaf, fi, BTRFS_FILE_EXTENT_REG); >> + if (prealloc) >> + btrfs_set_file_extent_type(leaf, fi, BTRFS_FILE_EXTENT_PREALLOC); >> + else >> + btrfs_set_file_extent_type(leaf, fi, BTRFS_FILE_EXTENT_REG); > > The bool parameter makes it less clear what it means in all the callers, > as it is supposed to select the type of extent you could pass the > BTRFS_FILE_ExTENT_ constant directly. oh. ok. It can be done. Thx, Anand
diff --git a/common/extent-tree-utils.c b/common/extent-tree-utils.c index 34c7e5095160..2ccac6b44cea 100644 --- a/common/extent-tree-utils.c +++ b/common/extent-tree-utils.c @@ -122,7 +122,7 @@ static int __btrfs_record_file_extent(struct btrfs_trans_handle *trans, struct btrfs_root *root, u64 objectid, struct btrfs_inode_item *inode, u64 file_pos, u64 disk_bytenr, - u64 *ret_num_bytes) + u64 *ret_num_bytes, bool prealloc) { int ret; struct btrfs_fs_info *info = root->fs_info; @@ -229,7 +229,10 @@ static int __btrfs_record_file_extent(struct btrfs_trans_handle *trans, leaf = path->nodes[0]; fi = btrfs_item_ptr(leaf, path->slots[0], struct btrfs_file_extent_item); btrfs_set_file_extent_generation(leaf, fi, trans->transid); - btrfs_set_file_extent_type(leaf, fi, BTRFS_FILE_EXTENT_REG); + if (prealloc) + btrfs_set_file_extent_type(leaf, fi, BTRFS_FILE_EXTENT_PREALLOC); + else + btrfs_set_file_extent_type(leaf, fi, BTRFS_FILE_EXTENT_REG); btrfs_set_file_extent_disk_bytenr(leaf, fi, extent_bytenr); btrfs_set_file_extent_disk_num_bytes(leaf, fi, extent_num_bytes); btrfs_set_file_extent_offset(leaf, fi, extent_offset); @@ -265,7 +268,7 @@ int btrfs_record_file_extent(struct btrfs_trans_handle *trans, struct btrfs_root *root, u64 objectid, struct btrfs_inode_item *inode, u64 file_pos, u64 disk_bytenr, - u64 num_bytes) + u64 num_bytes, bool prealloc) { u64 cur_disk_bytenr = disk_bytenr; u64 cur_file_pos = file_pos; @@ -276,7 +279,7 @@ int btrfs_record_file_extent(struct btrfs_trans_handle *trans, ret = __btrfs_record_file_extent(trans, root, objectid, inode, cur_file_pos, cur_disk_bytenr, - &cur_num_bytes); + &cur_num_bytes, prealloc); if (ret < 0) break; cur_disk_bytenr += cur_num_bytes; diff --git a/common/extent-tree-utils.h b/common/extent-tree-utils.h index f03d9c438375..7abd0337ea0b 100644 --- a/common/extent-tree-utils.h +++ b/common/extent-tree-utils.h @@ -31,6 +31,6 @@ int btrfs_record_file_extent(struct btrfs_trans_handle *trans, struct btrfs_root *root, u64 objectid, struct btrfs_inode_item *inode, u64 file_pos, u64 disk_bytenr, - u64 num_bytes); + u64 num_bytes, bool prealloc); #endif diff --git a/convert/main.c b/convert/main.c index f18fab4a236c..d67c4e8eac25 100644 --- a/convert/main.c +++ b/convert/main.c @@ -337,7 +337,7 @@ static int create_image_file_range(struct btrfs_trans_handle *trans, return -EINVAL; } ret = btrfs_record_file_extent(trans, root, ino, inode, bytenr, - disk_bytenr, len); + disk_bytenr, len, false); if (ret < 0) return ret; @@ -426,7 +426,7 @@ static int migrate_one_reserved_range(struct btrfs_trans_handle *trans, /* Now handle extent item and file extent things */ ret = btrfs_record_file_extent(trans, root, ino, inode, cur_off, - key.objectid, key.offset); + key.objectid, key.offset, false); if (ret < 0) break; /* Finally, insert csum items */ @@ -438,7 +438,7 @@ static int migrate_one_reserved_range(struct btrfs_trans_handle *trans, hole_len = cur_off - hole_start; if (hole_len) { ret = btrfs_record_file_extent(trans, root, ino, inode, - hole_start, 0, hole_len); + hole_start, 0, hole_len, false); if (ret < 0) break; } @@ -455,7 +455,8 @@ static int migrate_one_reserved_range(struct btrfs_trans_handle *trans, */ if (range_end(range) - hole_start > 0) ret = btrfs_record_file_extent(trans, root, ino, inode, - hole_start, 0, range_end(range) - hole_start); + hole_start, 0, range_end(range) - hole_start, + false); return ret; } diff --git a/convert/source-fs.c b/convert/source-fs.c index 66561438866e..9039b0e66758 100644 --- a/convert/source-fs.c +++ b/convert/source-fs.c @@ -262,7 +262,7 @@ int record_file_blocks(struct blk_iterate_data *data, if (old_disk_bytenr == 0) return btrfs_record_file_extent(data->trans, root, data->objectid, data->inode, file_pos, 0, - num_bytes); + num_bytes, false); /* * Search real disk bytenr from convert root @@ -316,7 +316,8 @@ int record_file_blocks(struct blk_iterate_data *data, old_disk_bytenr + num_bytes) - cur_off; ret = btrfs_record_file_extent(data->trans, data->root, data->objectid, data->inode, file_pos, - real_disk_bytenr, cur_len); + real_disk_bytenr, cur_len, + false); if (ret < 0) break; cur_off += cur_len; diff --git a/convert/source-reiserfs.c b/convert/source-reiserfs.c index 3edc72ed08a5..c67ade9b4c90 100644 --- a/convert/source-reiserfs.c +++ b/convert/source-reiserfs.c @@ -365,7 +365,7 @@ static int convert_direct(struct btrfs_trans_handle *trans, return ret; return btrfs_record_file_extent(trans, root, objectid, inode, offset, - key.objectid, sectorsize); + key.objectid, sectorsize, false); } static int reiserfs_convert_tail(struct btrfs_trans_handle *trans, diff --git a/mkfs/rootdir.c b/mkfs/rootdir.c index 4ae9f435a7b7..cb6659319b7d 100644 --- a/mkfs/rootdir.c +++ b/mkfs/rootdir.c @@ -411,7 +411,8 @@ again: if (bytes_read) { ret = btrfs_record_file_extent(trans, root, objectid, - btrfs_inode, file_pos, first_block, cur_bytes); + btrfs_inode, file_pos, first_block, cur_bytes, + false); if (ret) goto end;
This preparatory patch adds an argument '%prealloc' to the function __btrfs_record_file_extent(), to be used in the following patches. Signed-off-by: Anand Jain <anand.jain@oracle.com> --- common/extent-tree-utils.c | 11 +++++++---- common/extent-tree-utils.h | 2 +- convert/main.c | 9 +++++---- convert/source-fs.c | 5 +++-- convert/source-reiserfs.c | 2 +- mkfs/rootdir.c | 3 ++- 6 files changed, 19 insertions(+), 13 deletions(-)