Sign Up
Log In
Log In
or
Sign Up
Places
All Projects
Status Monitor
Collapse sidebar
SUSE:SLE-12:GA
btrfsprogs
2000-btrfs-convert-clean-up-blk_iterate_data-ha...
Overview
Repositories
Revisions
Requests
Users
Attributes
Meta
File 2000-btrfs-convert-clean-up-blk_iterate_data-handling-wrt.patch of Package btrfsprogs
From c817013e5c0808f5e8e3068d9d9432f5e7c3fe41 Mon Sep 17 00:00:00 2001 From: Jeff Mahoney <jeffm@suse.com> Date: Wed, 14 Aug 2013 00:25:59 -0400 Subject: [PATCH 01/10] btrfs-convert: clean up blk_iterate_data handling wrt record_file_blocks Hand off initialization of blk_iterate_data to init_blk_iterate_data and pass the structure when the elements are the only values passed anyway. Signed-off-by: Jeff Mahoney <jeffm@suse.com> --- btrfs-convert.c | 145 +++++++++++++++++++++++++------------------------------- 1 file changed, 65 insertions(+), 80 deletions(-) --- a/btrfs-convert.c +++ b/btrfs-convert.c @@ -380,25 +380,6 @@ static int csum_disk_extent(struct btrfs return ret; } -static int record_file_blocks(struct btrfs_trans_handle *trans, - struct btrfs_root *root, u64 objectid, - struct btrfs_inode_item *inode, - u64 file_block, u64 disk_block, - u64 num_blocks, int checksum) -{ - int ret; - u64 file_pos = file_block * root->sectorsize; - u64 disk_bytenr = disk_block * root->sectorsize; - u64 num_bytes = num_blocks * root->sectorsize; - ret = btrfs_record_file_extent(trans, root, objectid, inode, file_pos, - disk_bytenr, num_bytes); - - if (ret || !checksum) - return ret; - - return csum_disk_extent(trans, root, disk_bytenr, num_bytes); -} - struct blk_iterate_data { struct btrfs_trans_handle *trans; struct btrfs_root *root; @@ -412,6 +393,43 @@ struct blk_iterate_data { int errcode; }; +static void init_blk_iterate_data(struct blk_iterate_data *data, + struct btrfs_trans_handle *trans, + struct btrfs_root *root, + struct btrfs_inode_item *inode, + u64 objectid, int checksum) +{ + data->trans = trans; + data->root = root; + data->inode = inode; + data->objectid = objectid; + data->first_block = 0; + data->disk_block = 0; + data->num_blocks = 0; + data->boundary = (u64)-1; + data->checksum = checksum; + data->errcode = 0; +} + +static int record_file_blocks(struct blk_iterate_data *data, + u64 file_block, u64 disk_block, u64 num_blocks) +{ + int ret; + struct btrfs_root *root = data->root; + u64 file_pos = file_block * root->sectorsize; + u64 disk_bytenr = disk_block * root->sectorsize; + u64 num_bytes = num_blocks * root->sectorsize; + ret = btrfs_record_file_extent(data->trans, data->root, + data->objectid, data->inode, file_pos, + disk_bytenr, num_bytes); + + if (ret || !data->checksum) + return ret; + + return csum_disk_extent(data->trans, data->root, disk_bytenr, + num_bytes); +} + static int block_iterate_proc(ext2_filsys ext2_fs, u64 disk_block, u64 file_block, struct blk_iterate_data *idata) @@ -420,7 +438,6 @@ static int block_iterate_proc(ext2_filsy int sb_region; int do_barrier; struct btrfs_root *root = idata->root; - struct btrfs_trans_handle *trans = idata->trans; struct btrfs_block_group_cache *cache; u64 bytenr = disk_block * root->sectorsize; @@ -430,20 +447,17 @@ static int block_iterate_proc(ext2_filsy (file_block > idata->first_block + idata->num_blocks) || (disk_block != idata->disk_block + idata->num_blocks)) { if (idata->num_blocks > 0) { - ret = record_file_blocks(trans, root, idata->objectid, - idata->inode, idata->first_block, - idata->disk_block, idata->num_blocks, - idata->checksum); + ret = record_file_blocks(idata, idata->first_block, + idata->disk_block, + idata->num_blocks); if (ret) goto fail; idata->first_block += idata->num_blocks; idata->num_blocks = 0; } if (file_block > idata->first_block) { - ret = record_file_blocks(trans, root, idata->objectid, - idata->inode, idata->first_block, - 0, file_block - idata->first_block, - idata->checksum); + ret = record_file_blocks(idata, idata->first_block, + 0, file_block - idata->first_block); if (ret) goto fail; } @@ -492,18 +506,11 @@ static int create_file_extents(struct bt u32 last_block; u32 sectorsize = root->sectorsize; u64 inode_size = btrfs_stack_inode_size(btrfs_inode); - struct blk_iterate_data data = { - .trans = trans, - .root = root, - .inode = btrfs_inode, - .objectid = objectid, - .first_block = 0, - .disk_block = 0, - .num_blocks = 0, - .boundary = (u64)-1, - .checksum = datacsum, - .errcode = 0, - }; + struct blk_iterate_data data; + + init_blk_iterate_data(&data, trans, root, btrfs_inode, objectid, + datacsum); + err = ext2fs_block_iterate2(ext2_fs, ext2_ino, BLOCK_FLAG_DATA_ONLY, NULL, __block_iterate_proc, &data); if (err) @@ -532,18 +539,16 @@ static int create_file_extents(struct bt nbytes = btrfs_stack_inode_nbytes(btrfs_inode) + num_bytes; btrfs_set_stack_inode_nbytes(btrfs_inode, nbytes); } else if (data.num_blocks > 0) { - ret = record_file_blocks(trans, root, objectid, btrfs_inode, - data.first_block, data.disk_block, - data.num_blocks, data.checksum); + ret = record_file_blocks(&data, data.first_block, + data.disk_block, data.num_blocks); if (ret) goto fail; } data.first_block += data.num_blocks; last_block = (inode_size + sectorsize - 1) / sectorsize; if (last_block > data.first_block) { - ret = record_file_blocks(trans, root, objectid, btrfs_inode, - data.first_block, 0, last_block - - data.first_block, data.checksum); + ret = record_file_blocks(&data, data.first_block, 0, + last_block - data.first_block); } fail: free(buffer); @@ -1105,18 +1110,11 @@ static int create_image_file_range(struc u32 block = start_byte / blocksize; u32 last_block = (end_byte + blocksize - 1) / blocksize; int ret = 0; - struct blk_iterate_data data = { - .trans = trans, - .root = root, - .inode = inode, - .objectid = objectid, - .first_block = block, - .disk_block = 0, - .num_blocks = 0, - .boundary = (u64)-1, - .checksum = 0, - .errcode = 0, - }; + struct blk_iterate_data data; + + init_blk_iterate_data(&data, trans, root, inode, objectid, 0); + data.first_block = block; + for (; start_byte < end_byte; block++, start_byte += blocksize) { if (!ext2fs_fast_test_block_bitmap(ext2_fs->block_map, block)) continue; @@ -1127,17 +1125,15 @@ static int create_image_file_range(struc } } if (data.num_blocks > 0) { - ret = record_file_blocks(trans, root, objectid, inode, - data.first_block, data.disk_block, - data.num_blocks, 0); + ret = record_file_blocks(&data, data.first_block, + data.disk_block, data.num_blocks); if (ret) goto fail; data.first_block += data.num_blocks; } if (last_block > data.first_block) { - ret = record_file_blocks(trans, root, objectid, inode, - data.first_block, 0, last_block - - data.first_block, 0); + ret = record_file_blocks(&data, data.first_block, 0, + last_block - data.first_block); if (ret) goto fail; } @@ -1835,18 +1831,9 @@ static int relocate_one_reference(struct btrfs_set_stack_inode_nbytes(&inode, nbytes); datacsum = !(btrfs_stack_inode_flags(&inode) & BTRFS_INODE_NODATASUM); - data = (struct blk_iterate_data) { - .trans = trans, - .root = root, - .inode = &inode, - .objectid = extent_key->objectid, - .first_block = extent_key->offset / sectorsize, - .disk_block = 0, - .num_blocks = 0, - .boundary = (u64)-1, - .checksum = datacsum, - .errcode = 0, - }; + init_blk_iterate_data(&data, trans, root, &inode, extent_key->objectid, + datacsum); + data.first_block = extent_key->offset; cur_offset = extent_key->offset; while (num_bytes > 0) { @@ -1889,10 +1876,8 @@ static int relocate_one_reference(struct } if (data.num_blocks > 0) { - ret = record_file_blocks(trans, root, - extent_key->objectid, &inode, - data.first_block, data.disk_block, - data.num_blocks, datacsum); + ret = record_file_blocks(&data, data.first_block, + data.disk_block, data.num_blocks); if (ret) goto fail; }
Locations
Projects
Search
Status Monitor
Help
OpenBuildService.org
Documentation
API Documentation
Code of Conduct
Contact
Support
@OBShq
Terms
openSUSE Build Service is sponsored by
The Open Build Service is an
openSUSE project
.
Sign Up
Log In
Places
Places
All Projects
Status Monitor