btrfs-progs: btrfstune --remove-simple-quota
cover btrfs-progs: btrfstune --remove-simple-quota
To be able to nuke simple quotas entirely if you decide you don't want them (and especially the OWNER_REFs) in your filesystem after all.
If you run
btrfstune --remove-simple-quota <dev>
on an unmounted filesystem, it will be as if simple quotas never existed on that filesystem.
Boris Burkov (3):
btrfs-progs: add a helper for clearing all the items in a tree
btrfs-progs: btrfstune: fix documentation for --enable-simple-quota
btrfs-progs: btrfstune: add ability to remove squotas
kernel-shared/disk-io.c | 39 +++++ kernel-shared/disk-io.h | 2 + kernel-shared/free-space-tree.c | 42 +---- .../065-btrfstune-simple-quota/test.sh | 33 ++++ tune/main.c | 18 +- tune/quota.c | 160 ++++++++++++++++++ tune/tune.h | 1 + 7 files changed, 253 insertions(+), 42 deletions(-) create mode 100755 tests/misc-tests/065-btrfstune-simple-quota/test.sh
Signature · 1 line
2.45.2
PATCH 1/3 btrfs-progs: add a helper for clearing all the items in a tree
Used in clear_free_space_tree, this is a totally generic operation. It will also be used for clearing the qgroup tree from btrfstune.
--- kernel-shared/disk-io.c | 39 ++++++++++++++++++++++++++++++ kernel-shared/disk-io.h | 2 ++ kernel-shared/free-space-tree.c | 42 ++------------------------------- 3 files changed, 43 insertions(+), 40 deletions(-)
kernel-shared/disk-io.c +39 -0
@@ -2342,6 +2342,45 @@ static bool is_global_root(struct btrfs_root *root)return true;return false; } + +int btrfs_clear_tree (struct btrfs_trans_handle *trans, +struct btrfs_root *root) +{ +struct btrfs_path *path; +struct btrfs_key key; +struct extent_buffer *leaf =NULL ; +int ret; +int nr =0 ; + + path =btrfs_alloc_path (); +if (!path) +return -ENOMEM ; + + key.objectid =0 ; + key.offset =0 ; + key.type =0 ; + +while (1 ) { + ret =btrfs_search_slot (trans, root, &key, path,-1 ,1 ); +if (ret <0 ) + goto out; + leaf = path->nodes[0 ]; + nr =btrfs_header_nritems (leaf); +if (!nr) +break ; + path->slots[0 ] =0 ; + ret =btrfs_del_items (trans, root, path,0 , nr); +if (ret) + goto out; + +btrfs_release_path (path); + } + ret =0 ; +out: +btrfs_free_path (path); +return ret; +} +int btrfs_delete_and_free_root (struct btrfs_trans_handle *trans,struct btrfs_root *root) {
kernel-shared/disk-io.h +2 -0
@@ -241,6 +241,8 @@ int btrfs_fs_roots_compare_roots(const struct rb_node *node1, const struct rb_nostruct btrfs_root *btrfs_create_tree (struct btrfs_trans_handle *trans,struct btrfs_fs_info *fs_info,struct btrfs_key *key); +int btrfs_clear_tree (struct btrfs_trans_handle *trans, +struct btrfs_root *root);int btrfs_delete_and_free_root (struct btrfs_trans_handle *trans,struct btrfs_root *root);struct btrfs_root *btrfs_csum_root (struct btrfs_fs_info *fs_info,u64 bytenr);
kernel-shared/free-space-tree.c +2 -40
60 lines not on this page · raw message
Signature · 1 line
2.45.2
Re: [PATCH 1/3] btrfs-progs: add a helper for clearing all the items in a tree
Quoted 15 lines · Boris Burkov
Used in
clear_free_space_tree, this is a totally generic operation. It will also be used for clearing the qgroup tree from btrfstune.Signed-off-by Boris Burkov <[email protected]>--- kernel-shared/disk-io.c | 39 ++++++++++++++++++++++++++++++ kernel-shared/disk-io.h | 2 ++ kernel-shared/free-space-tree.c | 42 ++------------------------------- 3 files changed, 43 insertions(+), 40 deletions(-)kernel-shared/disk-io.c +0
-0
kernel-shared/disk-io.c static bool is_global_root(struct btrfs_root *root) · line 2347
Quoted 6 lines
kernel-shared/disk-io.c +3
-0@@ -2342,6 +2342,45 @@ static bool is_global_root(struct btrfs_root *root)return true;return false; } + +int btrfs_clear_tree (struct btrfs_trans_handle *trans, +struct btrfs_root *root)
The original function name clear_free_space_tree() is also shared inside kernel.
Maybe you can also do a cleanup for kernel?
Otherwise looks good to me.
Thanks,
Qu
Quoted 119 lines
kernel-shared/disk-io.c +36
-0+{ +struct btrfs_path *path; +struct btrfs_key key; +struct extent_buffer *leaf =NULL ; +int ret; +int nr =0 ; + + path =btrfs_alloc_path (); +if (!path) +return -ENOMEM ; + + key.objectid =0 ; + key.offset =0 ; + key.type =0 ; + +while (1 ) { + ret =btrfs_search_slot (trans, root, &key, path,-1 ,1 ); +if (ret <0 ) + goto out; + leaf = path->nodes[0 ]; + nr =btrfs_header_nritems (leaf); +if (!nr) +break ; + path->slots[0 ] =0 ; + ret =btrfs_del_items (trans, root, path,0 , nr); +if (ret) + goto out; + +btrfs_release_path (path); + } + ret =0 ; +out: +btrfs_free_path (path); +return ret; +} +int btrfs_delete_and_free_root (struct btrfs_trans_handle *trans,struct btrfs_root *root) {kernel-shared/disk-io.h +2
-0@@ -241,6 +241,8 @@ int btrfs_fs_roots_compare_roots(const struct rb_node *node1, const struct rb_nostruct btrfs_root *btrfs_create_tree (struct btrfs_trans_handle *trans,struct btrfs_fs_info *fs_info,struct btrfs_key *key); +int btrfs_clear_tree (struct btrfs_trans_handle *trans, +struct btrfs_root *root);int btrfs_delete_and_free_root (struct btrfs_trans_handle *trans,struct btrfs_root *root);struct btrfs_root *btrfs_csum_root (struct btrfs_fs_info *fs_info,u64 bytenr);kernel-shared/free-space-tree.c +2
-40@@ -1228,44 +1228,6 @@ out:btrfs_abort_transaction (trans, ret);return ret; } -static int clear_free_space_tree (struct btrfs_trans_handle *trans, -struct btrfs_root *root) -{ -struct btrfs_path *path; -struct btrfs_key key; -int nr; -int ret; - - path =btrfs_alloc_path (); -if (!path) -return -ENOMEM ; - - key.objectid =0 ; - key.type =0 ; - key.offset =0 ; - -while (1 ) { - ret =btrfs_search_slot (trans, root, &key, path,-1 ,1 ); -if (ret <0 ) - goto out; - - nr =btrfs_header_nritems (path->nodes[0 ]); -if (!nr) -break ; - - path->slots[0 ] =0 ; - ret =btrfs_del_items (trans, root, path,0 , nr); -if (ret) - goto out; - -btrfs_release_path (path); - } - - ret =0 ; -out: -btrfs_free_path (path); -return ret; -}int btrfs_clear_free_space_tree (struct btrfs_fs_info *fs_info) {@@ -1288,7 +1250,7 @@ int btrfs_clear_free_space_tree(struct btrfs_fs_info *fs_info)while (key.offset < fs_info->nr_global_roots) { free_space_root =btrfs_global_root (fs_info, &key); - ret =clear_free_space_tree (trans, free_space_root); + ret =btrfs_clear_tree (trans, free_space_root);if (ret) goto abort; key.offset++;@@ -1299,7 +1261,7 @@ int btrfs_clear_free_space_tree(struct btrfs_fs_info *fs_info) BTRFS_FEATURE_COMPAT_RO_FREE_SPACE_TREE);btrfs_set_super_compat_ro_flags (fs_info->super_copy, features); - ret =clear_free_space_tree (trans, free_space_root); + ret =btrfs_clear_tree (trans, free_space_root);if (ret) goto abort;
PATCH 2/3 btrfs-progs: btrfstune: fix documentation for --enable-simple-quota
In reply to Boris BurkovThe documentation lists -q as the flag for enabling simple quotas, but the actual parsing only handles --enable-simple-quota. Update the documentation string.
--- tune/main.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
tune/main.c +1 -1
@@ -103,7 +103,7 @@ static const char * const tune_usage[] = {OPTLINE ("-x" ,"enable skinny metadata extent refs (mkfs: skinny-metadata)" ),OPTLINE ("-n" ,"enable no-holes feature (mkfs: no-holes, more efficient sparse file representation)" ),OPTLINE ("-S <0|1>" ,"set/unset seeding status of a device" ), -OPTLINE ("-q" ,"enable simple quotas on the file system. (mkfs: squota)" ), +OPTLINE ("--enable-simple-quota" ,"enable simple quotas on the file system. (mkfs: squota)" ),OPTLINE ("--convert-to-block-group-tree" ,"convert filesystem to track block groups in " "the separate block-group-tree instead of extent tree (sets the incompat bit)" ), OPTLINE("--convert-from-block-group-tree",
Signature · 1 line
2.45.2
Re: [PATCH 2/3] btrfs-progs: btrfstune: fix documentation for --enable-simple-quota
Quoted 5 lines · Boris Burkov
The documentation lists -q as the flag for enabling simple quotas, but the actual parsing only handles --enable-simple-quota. Update the documentation string.
Signed-off-by Boris Burkov <[email protected]>
I didn't find the man page entry for simple quota in the latest devel branch.
Is it missing or still experimental?
Otherwise the change itself is good.
Thanks,
Qu
Quoted 17 lines
--- tune/main.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)tune/main.c +1
-1@@ -103,7 +103,7 @@ static const char * const tune_usage[] = {OPTLINE ("-x" ,"enable skinny metadata extent refs (mkfs: skinny-metadata)" ),OPTLINE ("-n" ,"enable no-holes feature (mkfs: no-holes, more efficient sparse file representation)" ),OPTLINE ("-S <0|1>" ,"set/unset seeding status of a device" ), -OPTLINE ("-q" ,"enable simple quotas on the file system. (mkfs: squota)" ), +OPTLINE ("--enable-simple-quota" ,"enable simple quotas on the file system. (mkfs: squota)" ),OPTLINE ("--convert-to-block-group-tree" ,"convert filesystem to track block groups in " "the separate block-group-tree instead of extent tree (sets the incompat bit)" ), OPTLINE("--convert-from-block-group-tree",
PATCH 3/3 btrfs-progs: btrfstune: add ability to remove squotas
In reply to Boris BurkovWhen simple quotas is enabled, every new data extent gets a special inline OWNER_REF item that identifies the owning subvolume. This makes simple quotas backwards incompatible with kernels older than v6.7. Even if you disable quotas on the filesystem, the OWNER_REF items are sprinkled throughout the extent tree and older kernels are unable to parse them.
However, it is relatively easy to simply walk the extent tree and remove these inline ref items. This gives squota adopters the option to *fully* disable squotas on their system and un-set the incompat bit. Add this capability to btrfstune, which requires only a little tricky btrfs item data shifting.
This functionality was tested with a new unit test, as well as a similar but more thorough integration test in fstests
--- .../065-btrfstune-simple-quota/test.sh | 33 ++++ tune/main.c | 16 +- tune/quota.c | 160 ++++++++++++++++++ tune/tune.h | 1 + 4 files changed, 209 insertions(+), 1 deletion(-) create mode 100755 tests/misc-tests/065-btrfstune-simple-quota/test.sh
tests/misc-tests/065-btrfstune-simple-quota/test.sh new file +33 -0
@@ -0,0 +1,33 @@ +#!/bin/bash +# Verify btrfstune for enabling and removing simple quotas + +source "$TEST_TOP/common" || exit +source "$TEST_TOP/common.convert" || exit + +check_experimental_build +setup_root_helper +prepare_test_dev + +# Create the fs without simple quota +run_check_mkfs_test_dev +run_check_mount_test_dev +populate_fs +run_check_umount_test_dev +# Enable simple quotas +run_check $SUDO_HELPER "$TOP/btrfstune" --enable-simple-quota "$TEST_DEV" +run_check_mount_test_dev +run_check $SUDO_HELPER dd if=/dev/zero of="$TEST_MNT"/file2 bs=1M count=1 +run_check_umount_test_dev +run_check $SUDO_HELPER "$TOP/btrfs" check "$TEST_DEV" + +# Populate new fs with simple quotas enabled +run_check_mkfs_test_dev -O squota +run_check_mount_test_dev +populate_fs +run_check_umount_test_dev +# Remove simple quotas +run_check $SUDO_HELPER "$TOP/btrfstune" --remove-simple-quota "$TEST_DEV" +run_check_mount_test_dev +run_check $SUDO_HELPER dd if=/dev/zero of="$TEST_MNT"/file3 bs=1M count=1 +run_check_umount_test_dev +run_check $SUDO_HELPER "$TOP/btrfs" check "$TEST_DEV"
tune/main.c +15 -1
@@ -104,6 +104,7 @@ static const char * const tune_usage[] = {OPTLINE ("-n" ,"enable no-holes feature (mkfs: no-holes, more efficient sparse file representation)" ),OPTLINE ("-S <0|1>" ,"set/unset seeding status of a device" ),OPTLINE ("--enable-simple-quota" ,"enable simple quotas on the file system. (mkfs: squota)" ), +OPTLINE ("--remove-simple-quota" ,"remove simple quotas from the file system." ),OPTLINE ("--convert-to-block-group-tree" ,"convert filesystem to track block groups in " "the separate block-group-tree instead of extent tree (sets the incompat bit)" ), OPTLINE("--convert-from-block-group-tree",
@@ -198,6 +199,7 @@ int BOX_MAIN(btrfstune)(int argc, char *argv[])int ret;u64 super_flags =0 ;int quota =0 ; +int remove_simple_quota =0 ;int fd =-1 ;int oflags =O_RDWR ;
@@ -209,7 +211,7 @@ int BOX_MAIN(btrfstune)(int argc, char *argv[])GETOPT_VAL_DISABLE_BLOCK_GROUP_TREE ,GETOPT_VAL_ENABLE_FREE_SPACE_TREE ,GETOPT_VAL_ENABLE_SIMPLE_QUOTA , - + GETOPT_VAL_REMOVE_SIMPLE_QUOTA, };static const struct option long_options[] = { { "help", no_argument, NULL, GETOPT_VAL_HELP},
@@ -221,6 +223,8 @@ int BOX_MAIN(btrfstune)(int argc, char *argv[]) GETOPT_VAL_ENABLE_FREE_SPACE_TREE}, {"enable-simple-quota" , no_argument,NULL , GETOPT_VAL_ENABLE_SIMPLE_QUOTA }, + { "remove-simple-quota", no_argument, NULL, + GETOPT_VAL_REMOVE_SIMPLE_QUOTA}, #if EXPERIMENTAL { "csum", required_argument, NULL, GETOPT_VAL_CSUM }, #endif
@@ -288,6 +292,10 @@ int BOX_MAIN(btrfstune)(int argc, char *argv[]) quota =1 ; btrfstune_cmd_groups[QGROUP ] = true;break ; +case GETOPT_VAL_REMOVE_SIMPLE_QUOTA : + remove_simple_quota =1 ; + btrfstune_cmd_groups[QGROUP ] = true; +break ;#if EXPERIMENTAL case GETOPT_VAL_CSUM : btrfs_warn_experimental(
@@ -535,6 +543,12 @@ int BOX_MAIN(btrfstune)(int argc, char *argv[]) goto out; } +if (remove_simple_quota) { + ret =remove_squota (root->fs_info); +if (ret) + goto out; + } + out:if (ret <0 ) { fs_info->readonly =1 ;
tune/quota.c +160 -0
166 lines not on this page · raw message
tune/tune.h +1 -0
@@ -33,5 +33,6 @@ int convert_to_extent_tree(struct btrfs_fs_info *fs_info);int btrfs_change_csum_type (struct btrfs_fs_info *fs_info,u16 new_csum_type);int enable_quota (struct btrfs_fs_info *fs_info,bool simple); +int remove_squota (struct btrfs_fs_info *fs_info);#endif
Signature · 1 line
2.45.2
Re: [PATCH 3/3] btrfs-progs: btrfstune: add ability to remove squotas
Quoted 185 lines · Boris Burkov
When simple quotas is enabled, every new data extent gets a special inline
OWNER_REFitem that identifies the owning subvolume. This makes simple quotas backwards incompatible with kernels older than v6.7. Even if you disable quotas on the filesystem, theOWNER_REFitems are sprinkled throughout the extent tree and older kernels are unable to parse them.However, it is relatively easy to simply walk the extent tree and remove these inline ref items. This gives squota adopters the option to *fully* disable squotas on their system and un-set the incompat bit. Add this capability to btrfstune, which requires only a little tricky btrfs item data shifting.
This functionality was tested with a new unit test, as well as a similar but more thorough integration test in fstests
Signed-off-by Boris Burkov <[email protected]>--- .../065-btrfstune-simple-quota/test.sh | 33 ++++ tune/main.c | 16 +- tune/quota.c | 160 ++++++++++++++++++ tune/tune.h | 1 + 4 files changed, 209 insertions(+), 1 deletion(-)create mode 100755
tests/misc-tests/065-btrfstune-simple-quota/test.shtests/misc-tests/065-btrfstune-simple-quota/test.sh new file +33
-0@@ -0,0 +1,33 @@ +#!/bin/bash +# Verify btrfstune for enabling and removing simple quotas + +source "$TEST_TOP/common" || exit +source "$TEST_TOP/common.convert" || exit + +check_experimental_build +setup_root_helper +prepare_test_dev + +# Create the fs without simple quota +run_check_mkfs_test_dev +run_check_mount_test_dev +populate_fs +run_check_umount_test_dev +# Enable simple quotas +run_check $SUDO_HELPER "$TOP/btrfstune" --enable-simple-quota "$TEST_DEV" +run_check_mount_test_dev +run_check $SUDO_HELPER dd if=/dev/zero of="$TEST_MNT"/file2 bs=1M count=1 +run_check_umount_test_dev +run_check $SUDO_HELPER "$TOP/btrfs" check "$TEST_DEV" + +# Populate new fs with simple quotas enabled +run_check_mkfs_test_dev -O squota +run_check_mount_test_dev +populate_fs +run_check_umount_test_dev +# Remove simple quotas +run_check $SUDO_HELPER "$TOP/btrfstune" --remove-simple-quota "$TEST_DEV" +run_check_mount_test_dev +run_check $SUDO_HELPER dd if=/dev/zero of="$TEST_MNT"/file3 bs=1M count=1 +run_check_umount_test_dev +run_check $SUDO_HELPER "$TOP/btrfs" check "$TEST_DEV"tune/main.c +15
-1@@ -104,6 +104,7 @@ static const char * const tune_usage[] = {OPTLINE ("-n" ,"enable no-holes feature (mkfs: no-holes, more efficient sparse file representation)" ),OPTLINE ("-S <0|1>" ,"set/unset seeding status of a device" ),OPTLINE ("--enable-simple-quota" ,"enable simple quotas on the file system. (mkfs: squota)" ), +OPTLINE ("--remove-simple-quota" ,"remove simple quotas from the file system." ),OPTLINE ("--convert-to-block-group-tree" ,"convert filesystem to track block groups in " "the separate block-group-tree instead of extent tree (sets the incompat bit)" ), OPTLINE("--convert-from-block-group-tree",@@ -198,6 +199,7 @@ int BOX_MAIN(btrfstune)(int argc, char *argv[])int ret;u64 super_flags =0 ;int quota =0 ; +int remove_simple_quota =0 ;int fd =-1 ;int oflags =O_RDWR ;@@ -209,7 +211,7 @@ int BOX_MAIN(btrfstune)(int argc, char *argv[])GETOPT_VAL_DISABLE_BLOCK_GROUP_TREE ,GETOPT_VAL_ENABLE_FREE_SPACE_TREE ,GETOPT_VAL_ENABLE_SIMPLE_QUOTA , - + GETOPT_VAL_REMOVE_SIMPLE_QUOTA, };static const struct option long_options[] = { { "help", no_argument, NULL, GETOPT_VAL_HELP},@@ -221,6 +223,8 @@ int BOX_MAIN(btrfstune)(int argc, char *argv[]) GETOPT_VAL_ENABLE_FREE_SPACE_TREE}, {"enable-simple-quota" , no_argument,NULL , GETOPT_VAL_ENABLE_SIMPLE_QUOTA }, + { "remove-simple-quota", no_argument, NULL, + GETOPT_VAL_REMOVE_SIMPLE_QUOTA}, #if EXPERIMENTAL { "csum", required_argument, NULL, GETOPT_VAL_CSUM }, #endif@@ -288,6 +292,10 @@ int BOX_MAIN(btrfstune)(int argc, char *argv[]) quota =1 ; btrfstune_cmd_groups[QGROUP ] = true;break ; +case GETOPT_VAL_REMOVE_SIMPLE_QUOTA : + remove_simple_quota =1 ; + btrfstune_cmd_groups[QGROUP ] = true; +break ;#if EXPERIMENTAL case GETOPT_VAL_CSUM : btrfs_warn_experimental(@@ -535,6 +543,12 @@ int BOX_MAIN(btrfstune)(int argc, char *argv[]) goto out; } +if (remove_simple_quota) { + ret =remove_squota (root->fs_info); +if (ret) + goto out; + } + out:if (ret <0 ) { fs_info->readonly =1 ;tune/quota.c +51
-0@@ -6,6 +6,166 @@#include "common/messages.h" #include "tune/tune.h" +static int remove_quota_tree (struct btrfs_fs_info *fs_info) +{ +int ret; +struct btrfs_root *quota_root = fs_info->quota_root; +struct btrfs_root *tree_root = fs_info->tree_root; +struct btrfs_super_block *sb = fs_info->super_copy; +int super_flags =btrfs_super_incompat_flags (sb); +struct btrfs_trans_handle *trans; + + trans =btrfs_start_transaction (quota_root,0 ); + ret =btrfs_clear_tree (trans, quota_root); +if (ret) { +btrfs_abort_transaction (trans, ret); +return ret; + } + + ret =btrfs_delete_and_free_root (trans, quota_root); +if (ret) { +btrfs_abort_transaction (trans, ret); +return ret; + } + fs_info->quota_root =NULL ; + super_flags &= ~BTRFS_FEATURE_INCOMPAT_SIMPLE_QUOTA ; +btrfs_set_super_incompat_flags (sb, super_flags); +btrfs_commit_transaction (trans, tree_root); +return 0 ; +} + +/* +* Given a pointer (ptr) into DATAi (i = slot), and an amount to shift, +* move all the data to the left (slots >= slot) of that ptr to the right by +* the shift amount. This overwrites the shift bytes after ptr, effectively +* removing them from the item data. We must update affected item sizes (only +* at slot) and offsets (slots >= slot). +* +* Leaf view, using '-' to show shift scale: +* Before: +* [ITEM0,...,ITEMi,...,ITEMn,-------,DATAn,...,[---DATAi---],...,DATA0] +* After: +* [ITEM0,...,ITEMi,...,ITEMn,--------,DATAn,...,[--DATAi---],...,DATA0] +* +* Zooming in on DATAi +* (ptr points at the start of the Ys, and shift is length of the Ys) +* Before: +* ...[DATAi+1][XXXXXXXXXXXXYYYYYYYYYYYYYYYYXXXXXXX][DATAi-1]... +* After: +* ...................[DATAi+1][XXXXXXXXXXXXXXXXXXX][DATAi-1]... +* Note that DATAi-1 and smaller are not affected. +*/ +static void shift_leaf_data(struct btrfs_trans_handle *trans, + struct extent_buffer *leaf, int slot,
tune/quota.c line 69
Quoted 10 lines
tune/quota.c +10
-0+ unsigned long ptr, u32 shift) +{ +u32 nr =btrfs_header_nritems (leaf); +u32 leaf_data_off =btrfs_item_ptr_offset (leaf, nr -1 ); +u32 len = ptr - leaf_data_off; +u32 new_size =btrfs_item_size (leaf, slot) - shift; +for (int i = slot; i < nr; i++) { +u32 old_item_offset =btrfs_item_offset (leaf, i); +btrfs_set_item_offset (leaf, i, old_item_offset + shift); + }
IIRC you can just handle the memmove inside the item, then let btrfs_truncate_item() to do all the remaining work.
Although I'm not sure if it's really going to save any code.
Otherwise looks good to me.
Thanks,
Qu
Quoted 113 lines
tune/quota.c +99
-0+memmove_extent_buffer (leaf, leaf_data_off + shift, leaf_data_off, len); +btrfs_set_item_size (leaf, slot, new_size); +btrfs_set_header_generation (leaf, trans->transid); +btrfs_mark_buffer_dirty (leaf); +} + +/* +* Iterate over the extent tree and for each EXTENT_DATA item that has an inline +* ref of type OWNER_REF, shift that leaf to eliminate the owner ref. +* +* Note: we use a search_slot per leaf rather than find_next_leaf to get the +* needed CoW-ing and rebalancing for each leaf and its path up to the root. +*/ +static int remove_owner_refs (struct btrfs_fs_info *fs_info) +{ +struct btrfs_trans_handle *trans; +struct btrfs_root *extent_root; +struct btrfs_key key; +struct extent_buffer *leaf; +struct btrfs_path path = {0 }; +int slot; +int ret; + + extent_root =btrfs_extent_root (fs_info,0 ); + + trans =btrfs_start_transaction (extent_root,0 ); + + key.objectid =0 ; + key.type =BTRFS_EXTENT_ITEM_KEY ; + key.offset =0 ; + +search_slot: + ret =btrfs_search_slot (trans, extent_root, &key, &path,1 ,1 ); +if (ret <0 ) +return ret; + leaf = path.nodes[0 ]; + slot = path.slots[0 ]; + +while (1 ) { +struct btrfs_key found_key; +struct btrfs_extent_item *ei; +struct btrfs_extent_inline_ref *iref; +u8 type; +unsigned long ptr; +unsigned long item_end; + +if (slot >=btrfs_header_nritems (leaf)) { + ret =btrfs_next_leaf (extent_root, &path); +if (ret <0 ) { +break ; + }else if (ret) { + ret =0 ; +break ; + } + leaf = path.nodes[0 ]; + slot = path.slots[0 ]; +btrfs_item_key_to_cpu (leaf, &key, slot); +btrfs_release_path (&path); + goto search_slot; + } + +btrfs_item_key_to_cpu (leaf, &found_key, slot); +if (found_key.type !=BTRFS_EXTENT_ITEM_KEY ) + goto next; + ei = btrfs_item_ptr(leaf, slot, struct btrfs_extent_item); + ptr = (unsigned long )(ei +1 ); + item_end = (unsigned long )ei +btrfs_item_size (leaf, slot); +/* No inline extent references; accessing type is invalid. */ +if (ptr > item_end) + goto next; + iref = (struct btrfs_extent_inline_ref *)ptr; + type =btrfs_extent_inline_ref_type (leaf, iref); +if (type ==BTRFS_EXTENT_OWNER_REF_KEY ) +shift_leaf_data (trans, leaf, slot, ptr,sizeof (*iref)); +next: + slot++; + } +btrfs_release_path (&path); + + ret =btrfs_commit_transaction (trans, extent_root); +if (ret <0 ) { + errno = -ret; +error_msg (ERROR_MSG_COMMIT_TRANS ,"%m" ); +return ret; + } +return 0 ; +} + +int remove_squota (struct btrfs_fs_info *fs_info) +{ +int ret; + + ret =remove_owner_refs (fs_info); +if (ret) +return ret; + +return remove_quota_tree (fs_info); +} +static int create_qgroup (struct btrfs_fs_info *fs_info,struct btrfs_trans_handle *trans,u64 qgroupid)tune/tune.h +1
-0@@ -33,5 +33,6 @@ int convert_to_extent_tree(struct btrfs_fs_info *fs_info);int btrfs_change_csum_type (struct btrfs_fs_info *fs_info,u16 new_csum_type);int enable_quota (struct btrfs_fs_info *fs_info,bool simple); +int remove_squota (struct btrfs_fs_info *fs_info);#endif
btrfstune --help shows -q as the option to enable simple quota, which does not work.
David, has this set missed integration? OR Boris could push?
The whole series looks good to me.
Thx.
Quoted 23 lines · Boris Burkov
To be able to nuke simple quotas entirely if you decide you don't want them (and especially the
OWNER_REFs) in your filesystem after all.If you run
btrfstune --remove-simple-quota <dev>
on an unmounted filesystem, it will be as if simple quotas never existed on that filesystem.Boris Burkov (3):
btrfs-progs: add a helper for clearing all the items in a tree
btrfs-progs: btrfstune: fix documentation for --enable-simple-quota
btrfs-progs: btrfstune: add ability to remove squotaskernel-shared/disk-io.c | 39 +++++ kernel-shared/disk-io.h | 2 + kernel-shared/free-space-tree.c | 42 +---- .../065-btrfstune-simple-quota/test.sh | 33 ++++ tune/main.c | 18 +- tune/quota.c | 160 ++++++++++++++++++ tune/tune.h | 1 + 7 files changed, 253 insertions(+), 42 deletions(-)create mode 100755
tests/misc-tests/065-btrfstune-simple-quota/test.sh
Sorry I forgot to merge them for so long..
Now merged into devel branch with all reviewed-by tags, and some small modifications:
- Put the doc fix first
- Add the missing man page entry for "--enable-simple-quota"
- Make remove_all_tree_items() to use btrfs_clear_tree() helper
- Add the missing man page entry for "--remove-simple-quota"
Thanks,
Qu
Quoted 38 lines · Anand Jain
btrfstune --help shows -q as the option to enable simple quota, which does not work.
David, has this set missed integration? OR Boris could push?
The whole series looks good to me.
Reviewed-by Anand Jain <[email protected]>Thx.
Quoted 23 lines · Boris Burkov
To be able to nuke simple quotas entirely if you decide you don't want them (and especially the
OWNER_REFs) in your filesystem after all.If you run
btrfstune --remove-simple-quota <dev>
on an unmounted filesystem, it will be as if simple quotas never existed on that filesystem.Boris Burkov (3):
btrfs-progs: add a helper for clearing all the items in a tree
btrfs-progs: btrfstune: fix documentation for --enable-simple-quota
btrfs-progs: btrfstune: add ability to remove squotaskernel-shared/disk-io.c | 39 +++++ kernel-shared/disk-io.h | 2 + kernel-shared/free-space-tree.c | 42 +---- .../065-btrfstune-simple-quota/test.sh | 33 ++++ tune/main.c | 18 +- tune/quota.c | 160 ++++++++++++++++++ tune/tune.h | 1 +
7 files changed, 253 insertions(+), 42 deletions(-)create mode 100755
tests/misc-tests/065-btrfstune-simple-quota/test.sh