Skip to content

Commit

Permalink
convert_ext2fs_extent_get
Browse files Browse the repository at this point in the history
Signed-off-by: Anand Jain <[email protected]>
  • Loading branch information
asj committed Apr 17, 2024
1 parent a96e951 commit b75cea8
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 2 deletions.
16 changes: 15 additions & 1 deletion convert/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -236,6 +236,8 @@ static int create_image_file_range(struct btrfs_trans_handle *trans,
int ret;
u32 datacsum = convert_flags & CONVERT_FLAG_DATACSUM;

printf("ASJ: create_image_file_range ino %lld bytenr %llu len %llu\n",
ino, bytenr, len);
if (bytenr != round_down(bytenr, root->fs_info->sectorsize)) {
error("bytenr not sectorsize aligned: %llu", bytenr);
return -EINVAL;
Expand Down Expand Up @@ -376,6 +378,8 @@ static int migrate_one_reserved_range(struct btrfs_trans_handle *trans,
struct btrfs_key key;
int ret = 0;

printf("ASJ: migrate_one_reserved_range ino %lld range->start %lld range->len %lld\n",
ino, range->start, range->len);
/*
* It's possible that there are holes in reserved range:
* |<---------------- Reserved range ---------------------->|
Expand Down Expand Up @@ -419,12 +423,22 @@ static int migrate_one_reserved_range(struct btrfs_trans_handle *trans,
free(buf);
break;
}

//asj9424
#if 0
convert_ext2fs_extent_get(cur_len cur_off);
if (extent.flag == "unwritten")
buf={0};
#endif

ret = write_data_to_disk(root->fs_info, buf, key.objectid, key.offset);
free(buf);
if (ret < 0)
break;

/* Now handle extent item and file extent things */
printf("ASJ: migrate_one_reserved_range ino %lld cur_off %lld key.objectid %lld key.offset %lld\n",
ino, cur_off, key.objectid, key.offset);
/* Now handle extent item and file extent things */
ret = btrfs_record_file_extent(trans, root, ino, inode, cur_off,
key.objectid, key.offset);
if (ret < 0)
Expand Down
34 changes: 33 additions & 1 deletion convert/source-ext2.c
Original file line number Diff line number Diff line change
Expand Up @@ -295,6 +295,7 @@ static int ext2_block_iterate_proc(ext2_filsys fs, blk_t *blocknr,
int ret;
struct blk_iterate_data *idata;
idata = (struct blk_iterate_data *)priv_data;

ret = block_iterate_proc(*blocknr, blockcnt, idata);
if (ret) {
idata->errcode = ret;
Expand All @@ -303,13 +304,34 @@ static int ext2_block_iterate_proc(ext2_filsys fs, blk_t *blocknr,
return 0;
}

//ASJ
static int convert_ext2fs_extent_get(ext2_filsys ext2_fs, ext2_ino_t ext2_ino,
struct ext2_inode *inode)
{
int ret;
ext2_extent_handle_t handle;
struct ext2fs_extent extent;

ret = ext2fs_extent_open2(ext2_fs, ext2_ino, inode, &handle);
if (ret)
return ret;

ret = ext2fs_extent_get(handle, EXT2_EXTENT_ROOT, &extent);
printf("ASJ: phyblk %lld logblk %lld len %d extent.e_flags %x\n",
extent.e_pblk, extent.e_lblk, extent.e_len, extent.e_flags);

ext2fs_extent_free(handle);
return ret;
}

/*
* traverse file's data blocks, record these data blocks as file extents.
*/
static int ext2_create_file_extents(struct btrfs_trans_handle *trans,
struct btrfs_root *root, u64 objectid,
struct btrfs_inode_item *btrfs_inode,
ext2_filsys ext2_fs, ext2_ino_t ext2_ino,
struct ext2_inode *ext2_inode,
u32 convert_flags)
{
int ret;
Expand Down Expand Up @@ -337,6 +359,7 @@ static int ext2_create_file_extents(struct btrfs_trans_handle *trans,
u64 disk_bytenr = data.disk_block * sectorsize;
u64 nbytes;

printf("ASJ: inline ");
buffer = malloc(num_bytes);
if (!buffer)
return -ENOMEM;
Expand All @@ -352,11 +375,19 @@ static int ext2_create_file_extents(struct btrfs_trans_handle *trans,
nbytes = btrfs_stack_inode_nbytes(btrfs_inode) + num_bytes;
btrfs_set_stack_inode_nbytes(btrfs_inode, nbytes);
} else if (data.num_blocks > 0) {
printf("ASJ: regular ");
ret = record_file_blocks(&data, data.first_block,
data.disk_block, data.num_blocks);
if (ret)
goto fail;
}
//ASJ
printf("object %lld data.first_block %lld data.num_blocks %lld (%lld) disk_bytenr %lld ",
objectid, data.first_block, data.num_blocks,
data.num_blocks*sectorsize, data.disk_block * sectorsize);

ret = convert_ext2fs_extent_get(ext2_fs, ext2_ino, ext2_inode);

data.first_block += data.num_blocks;
last_block = (inode_size + sectorsize - 1) / sectorsize;
if (last_block > data.first_block) {
Expand Down Expand Up @@ -384,6 +415,7 @@ static int ext2_create_symlink(struct btrfs_trans_handle *trans,
btrfs_set_stack_inode_size(btrfs_inode, inode_size + 1);
ret = ext2_create_file_extents(trans, root, objectid,
btrfs_inode, ext2_fs, ext2_ino,
ext2_inode,
CONVERT_FLAG_DATACSUM |
CONVERT_FLAG_INLINE_DATA);
btrfs_set_stack_inode_size(btrfs_inode, inode_size);
Expand Down Expand Up @@ -903,7 +935,7 @@ static int ext2_copy_single_inode(struct btrfs_trans_handle *trans,
switch (ext2_inode->i_mode & S_IFMT) {
case S_IFREG:
ret = ext2_create_file_extents(trans, root, objectid,
&btrfs_inode, ext2_fs, ext2_ino, convert_flags);
&btrfs_inode, ext2_fs, ext2_ino, ext2_inode, convert_flags);
break;
case S_IFDIR:
ret = ext2_create_dir_entries(trans, root, objectid,
Expand Down

0 comments on commit b75cea8

Please sign in to comment.