-
Notifications
You must be signed in to change notification settings - Fork 243
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
btrfs-progs: mkfs: add --compression #882
Changes from all commits
e35b891
82cec85
c614436
094d7ef
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -285,3 +285,93 @@ int btrfs_record_file_extent(struct btrfs_trans_handle *trans, | |
} | ||
return ret; | ||
} | ||
|
||
int btrfs_record_file_extent_comp(struct btrfs_trans_handle *trans, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please do no use But it will no longer be a problem if we address the next comment. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It turns out that we should not use The extra handling inside For mkfs cases, I'll craft a dedicated help for it with a more expandable interface during my cleanup. |
||
struct btrfs_root *root, u64 objectid, | ||
struct btrfs_inode_item *inode, | ||
u64 file_pos, u64 disk_bytenr, | ||
u64 extent_num_bytes, u64 ram_bytes, | ||
enum btrfs_compression_type comp) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Instead of the longer and longer parameter list, what about something just like So that we do not need two different This will need a dedicated cleanup patch first, to introduce some structure like |
||
{ | ||
struct btrfs_fs_info *info = root->fs_info; | ||
struct btrfs_root *extent_root = btrfs_extent_root(info, disk_bytenr); | ||
struct extent_buffer *leaf; | ||
struct btrfs_file_extent_item *fi; | ||
struct btrfs_key ins_key; | ||
struct btrfs_path *path; | ||
struct btrfs_extent_item *ei; | ||
u64 nbytes; | ||
u64 extent_bytenr; | ||
u64 extent_offset; | ||
int ret = 0; | ||
|
||
path = btrfs_alloc_path(); | ||
if (!path) | ||
return -ENOMEM; | ||
|
||
ins_key.objectid = disk_bytenr; | ||
ins_key.type = BTRFS_EXTENT_ITEM_KEY; | ||
ins_key.offset = extent_num_bytes; | ||
|
||
ret = btrfs_insert_empty_item(trans, extent_root, path, | ||
&ins_key, sizeof(*ei)); | ||
if (ret == 0) { | ||
leaf = path->nodes[0]; | ||
ei = btrfs_item_ptr(leaf, path->slots[0], | ||
struct btrfs_extent_item); | ||
|
||
btrfs_set_extent_refs(leaf, ei, 0); | ||
btrfs_set_extent_generation(leaf, ei, trans->transid); | ||
btrfs_set_extent_flags(leaf, ei, | ||
BTRFS_EXTENT_FLAG_DATA); | ||
btrfs_mark_buffer_dirty(leaf); | ||
|
||
ret = btrfs_update_block_group(trans, disk_bytenr, | ||
extent_num_bytes, 1, 0); | ||
if (ret) | ||
goto fail; | ||
} else if (ret != -EEXIST) { | ||
goto fail; | ||
} | ||
|
||
ret = remove_from_free_space_tree(trans, disk_bytenr, extent_num_bytes); | ||
if (ret) | ||
goto fail; | ||
|
||
btrfs_run_delayed_refs(trans, -1); | ||
extent_bytenr = disk_bytenr; | ||
extent_offset = 0; | ||
|
||
btrfs_release_path(path); | ||
ins_key.objectid = objectid; | ||
ins_key.type = BTRFS_EXTENT_DATA_KEY; | ||
ins_key.offset = file_pos; | ||
ret = btrfs_insert_empty_item(trans, root, path, &ins_key, sizeof(*fi)); | ||
if (ret) | ||
goto fail; | ||
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); | ||
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); | ||
btrfs_set_file_extent_num_bytes(leaf, fi, ram_bytes); | ||
btrfs_set_file_extent_ram_bytes(leaf, fi, ram_bytes); | ||
btrfs_set_file_extent_compression(leaf, fi, comp); | ||
btrfs_set_file_extent_encryption(leaf, fi, 0); | ||
btrfs_set_file_extent_other_encoding(leaf, fi, 0); | ||
btrfs_mark_buffer_dirty(leaf); | ||
|
||
nbytes = btrfs_stack_inode_nbytes(inode) + ram_bytes; | ||
btrfs_set_stack_inode_nbytes(inode, nbytes); | ||
btrfs_release_path(path); | ||
|
||
ret = btrfs_inc_extent_ref(trans, extent_bytenr, extent_num_bytes, | ||
0, root->root_key.objectid, objectid, | ||
file_pos - extent_offset); | ||
|
||
fail: | ||
btrfs_free_path(path); | ||
return ret; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since
level
is optional, please use--compress <algo>[:<level>]
instead.