Implement progs support for removing received uuid on RW vols
cover Implement progs support for removing received uuid on RW vols
This series is the userspace counter part to a kernel patch titled:
"btrfs: Remove received information from snapshot on ro->rw switch". This will mainly serve people running old kernels that won't have this patch to be able to remove received uuid et al from snapshots which have been switched RO->RW. This is to ensure consistency.
First 3 patches are preparatory ones which pull needed code from the kernel as well as removing some arguments making respective functions as close to their kernel counterparts as possible. This enables to simply copy btrfs_uuid_tree_remove with no changes from the kernel.
Next 2 patches implement detection and repair support for RO->RW-switched volumes which have been received. And the final patch is an fs image with a received subvolume that has been switched to RW following a receive.
Nikolay Borisov (8):
btrfs-progs: Add btrfs_is_empty_uuid
btrfs-progs: Remove root argument from btrfs_fixup_low_keys
btrfs-progs: Remove fs_info argument from leaf_data_end
btrfs-progs: Remove root argument from btrfs_truncate_item
btrfs-progs: Add btrfs_uuid_tree_remove
btrfs-progs: check/original: Implement removing received data for RW
subvols
btrfs-progs: check/lowmem: Implement received info clearing for RW
volumes
btrfs-progs: tests: Add test for received information removal
check/main.c | 48 ++++++++- check/mode-lowmem.c | 38 +++++++ kernel-shared/ctree.c | 62 +++++------- kernel-shared/ctree.h | 12 ++- kernel-shared/dir-item.c | 2 +- kernel-shared/extent-tree.c | 2 +- kernel-shared/file-item.c | 4 +- kernel-shared/inode-item.c | 4 +- kernel-shared/uuid-tree.c | 93 ++++++++++++++++++ .../050-subvol-recv-clear/test.raw.xz | Bin 0 -> 493524 bytes 10 files changed, 216 insertions(+), 49 deletions(-) create mode 100644 tests/fsck-tests/050-subvol-recv-clear/test.raw.xz
--
2.17.1
PATCH 1/8 btrfs-progs: Add btrfs_is_empty_uuid
This utility function is needed by the RO->RW snapshot detection code.
--- kernel-shared/ctree.h | 2 ++ kernel-shared/uuid-tree.c | 11 +++++++++++ 2 files changed, 13 insertions(+)
kernel-shared/ctree.h +2 -0
@@ -2860,6 +2860,8 @@ int btrfs_lookup_uuid_received_subvol_item(int fd, const u8 *uuid,int btrfs_uuid_tree_add (struct btrfs_trans_handle *trans,u8 *uuid,u8 type,u64 subvol_id_cpu); +int btrfs_is_empty_uuid (u8 *uuid); +static inline int is_fstree (u64 rootid) { if (rootid == BTRFS_FS_TREE_OBJECTID ||
kernel-shared/uuid-tree.c +11 -0
@@ -109,3 +109,14 @@ int btrfs_lookup_uuid_received_subvol_item(int fd, const u8 *uuid,BTRFS_UUID_KEY_RECEIVED_SUBVOL , subvol_id); } + +int btrfs_is_empty_uuid (u8 *uuid) +{ +int i; + +for (i =0 ; i <BTRFS_UUID_SIZE ; i++) { +if (uuid[i]) +return 0 ; + } +return 1 ; +}
Signature · 1 line
2.17.1
Re: [PATCH 1/8] btrfs-progs: Add btrfs_is_empty_uuid
Quoted 26 lines · Nikolay Borisov
This utility function is needed by the
RO->RWsnapshot detection code.Signed-off-by Nikolay Borisov <[email protected]>--- kernel-shared/ctree.h | 2 ++ kernel-shared/uuid-tree.c | 11 +++++++++++ 2 files changed, 13 insertions(+)kernel-shared/ctree.h +2
-0@@ -2860,6 +2860,8 @@ int btrfs_lookup_uuid_received_subvol_item(int fd, const u8 *uuid,int btrfs_uuid_tree_add (struct btrfs_trans_handle *trans,u8 *uuid,u8 type,u64 subvol_id_cpu); +int btrfs_is_empty_uuid (u8 *uuid); +static inline int is_fstree (u64 rootid) { if (rootid == BTRFS_FS_TREE_OBJECTID ||kernel-shared/uuid-tree.c +0
-0
kernel-shared/uuid-tree.c int btrfs_lookup_uuid_received_subvol_item(int fd, const u8 *uuid, · line 114
Quoted 6 lines
kernel-shared/uuid-tree.c +3
-0@@ -109,3 +109,14 @@ int btrfs_lookup_uuid_received_subvol_item(int fd, const u8 *uuid,BTRFS_UUID_KEY_RECEIVED_SUBVOL , subvol_id); } + +int btrfs_is_empty_uuid (u8 *uuid) +{
I did the same work in my previous warning try, but it can be even easier:
u8 empty_uuid[BTRFS_UUID_SIZE] = 0; return !memcmpy(uuid, empty_uuid, BTRFS_UUID_SIZE);
So simple that I didn't even create a helper for it...
Thanks,
Qu
Quoted 9 lines
kernel-shared/uuid-tree.c +8
-0+int i; + +for (i =0 ; i <BTRFS_UUID_SIZE ; i++) { +if (uuid[i]) +return 0 ; + } +return 1 ; +}
PATCH 2/8 btrfs-progs: Remove root argument from btrfs_fixup_low_keys
In reply to Nikolay BorisovIt's not used, so just remove it.
--- check/main.c | 5 ++--- kernel-shared/ctree.c | 24 +++++++++++------------- kernel-shared/ctree.h | 4 ++-- 3 files changed, 15 insertions(+), 18 deletions(-)
check/main.c +2 -3
@@ -4197,8 +4197,7 @@ static int swap_values(struct btrfs_root *root, struct btrfs_path *path,struct btrfs_disk_key key;btrfs_node_key (buf, &key,0 ); -btrfs_fixup_low_keys (root, path, &key, -btrfs_header_level (buf) +1 ); +btrfs_fixup_low_keys (path, &key,btrfs_header_level (buf) +1 ); } }else {struct btrfs_item *item1, *item2;
@@ -4302,7 +4301,7 @@ static int delete_bogus_item(struct btrfs_root *root,struct btrfs_disk_key disk_key;btrfs_item_key (buf, &disk_key,0 ); -btrfs_fixup_low_keys (root, path, &disk_key,1 ); +btrfs_fixup_low_keys (path, &disk_key,1 ); }btrfs_mark_buffer_dirty (buf);return 0 ;
kernel-shared/ctree.c +11 -13
@@ -1437,8 +1437,8 @@ int btrfs_search_slot_for_read(struct btrfs_root *root,* fixing up pointers when a given leaf/node is not in slot 0 of the * higher levels */ -void btrfs_fixup_low_keys (struct btrfs_root *root,struct btrfs_path *path, -struct btrfs_disk_key *key,int level) +void btrfs_fixup_low_keys (struct btrfs_path *path,struct btrfs_disk_key *key, +int level) {int i;struct extent_buffer *t;
@@ -1485,7 +1485,7 @@ int btrfs_set_item_key_safe(struct btrfs_root *root, struct btrfs_path *path,btrfs_set_item_key (eb, &disk_key, slot);btrfs_mark_buffer_dirty (eb);if (slot ==0 ) -btrfs_fixup_low_keys (root, path, &disk_key,1 ); +btrfs_fixup_low_keys (path, &disk_key,1 );return 0 ; }
@@ -1508,7 +1508,7 @@ void btrfs_set_item_key_unsafe(struct btrfs_root *root,btrfs_set_item_key (eb, &disk_key, slot);btrfs_mark_buffer_dirty (eb);if (slot ==0 ) -btrfs_fixup_low_keys (root, path, &disk_key,1 ); +btrfs_fixup_low_keys (path, &disk_key,1 ); }/*
@@ -2184,7 +2184,7 @@ static int push_leaf_left(struct btrfs_trans_handle *trans, struct btrfs_rootbtrfs_mark_buffer_dirty (right);btrfs_item_key (right, &disk_key,0 ); -btrfs_fixup_low_keys (root, path, &disk_key,1 ); +btrfs_fixup_low_keys (path, &disk_key,1 );/* then fixup the leaf pointer in the path */ if (path->slots[0 ] < push_items) {
@@ -2415,10 +2415,8 @@ static noinline int split_leaf(struct btrfs_trans_handle *trans,free_extent_buffer (path->nodes[0 ]); path->nodes[0 ] = right; path->slots[0 ] =0 ; -if (path->slots[1 ] ==0 ) { -btrfs_fixup_low_keys (root, path, - &disk_key,1 ); - } +if (path->slots[1 ] ==0 ) +btrfs_fixup_low_keys (path, &disk_key,1 ); }btrfs_mark_buffer_dirty (right);return ret;
@@ -2632,7 +2630,7 @@ int btrfs_truncate_item(struct btrfs_root *root, struct btrfs_path *path,btrfs_set_disk_key_offset (&disk_key, offset + size_diff);btrfs_set_item_key (leaf, &disk_key, slot);if (slot ==0 ) -btrfs_fixup_low_keys (root, path, &disk_key,1 ); +btrfs_fixup_low_keys (path, &disk_key,1 ); } item =btrfs_item_nr (slot);
@@ -2809,7 +2807,7 @@ int btrfs_insert_empty_items(struct btrfs_trans_handle *trans, ret =0 ;if (slot ==0 ) {btrfs_cpu_key_to_disk (&disk_key, cpu_key); -btrfs_fixup_low_keys (root, path, &disk_key,1 ); +btrfs_fixup_low_keys (path, &disk_key,1 ); }if (btrfs_leaf_free_space (leaf) <0 ) {
@@ -2882,7 +2880,7 @@ int btrfs_del_ptr(struct btrfs_root *root, struct btrfs_path *path,struct btrfs_disk_key disk_key;btrfs_node_key (parent, &disk_key,0 ); -btrfs_fixup_low_keys (root, path, &disk_key, level +1 ); +btrfs_fixup_low_keys (path, &disk_key, level +1 ); }btrfs_mark_buffer_dirty (parent);return ret;
@@ -2982,7 +2980,7 @@ int btrfs_del_items(struct btrfs_trans_handle *trans, struct btrfs_root *root,struct btrfs_disk_key disk_key;btrfs_item_key (leaf, &disk_key,0 ); -btrfs_fixup_low_keys (root, path, &disk_key,1 ); +btrfs_fixup_low_keys (path, &disk_key,1 ); }/* delete the leaf if it is mostly empty */
kernel-shared/ctree.h +2 -2
@@ -2747,8 +2747,8 @@ static inline int btrfs_next_item(struct btrfs_root *root,int btrfs_prev_leaf (struct btrfs_root *root,struct btrfs_path *path);int btrfs_leaf_free_space (struct extent_buffer *leaf); -void btrfs_fixup_low_keys (struct btrfs_root *root,struct btrfs_path *path, -struct btrfs_disk_key *key,int level); +void btrfs_fixup_low_keys (struct btrfs_path *path,struct btrfs_disk_key *key, +int level);int btrfs_set_item_key_safe (struct btrfs_root *root,struct btrfs_path *path,struct btrfs_key *new_key); void btrfs_set_item_key_unsafe(struct btrfs_root *root,
Signature · 1 line
2.17.1
Re: [PATCH 2/8] btrfs-progs: Remove root argument from btrfs_fixup_low_keys
Quoted 3 lines · Nikolay Borisov
It's not used, so just remove it.
Signed-off-by Nikolay Borisov <[email protected]>
Just one unrelated topic inlined below.
Quoted 34 lines
--- check/main.c | 5 ++--- kernel-shared/ctree.c | 24 +++++++++++------------- kernel-shared/ctree.h | 4 ++-- 3 files changed, 15 insertions(+), 18 deletions(-)check/main.c +2
-3@@ -4197,8 +4197,7 @@ static int swap_values(struct btrfs_root *root, struct btrfs_path *path,struct btrfs_disk_key key;btrfs_node_key (buf, &key,0 ); -btrfs_fixup_low_keys (root, path, &key, -btrfs_header_level (buf) +1 ); +btrfs_fixup_low_keys (path, &key,btrfs_header_level (buf) +1 ); } }else {struct btrfs_item *item1, *item2;@@ -4302,7 +4301,7 @@ static int delete_bogus_item(struct btrfs_root *root,struct btrfs_disk_key disk_key;btrfs_item_key (buf, &disk_key,0 ); -btrfs_fixup_low_keys (root, path, &disk_key,1 ); +btrfs_fixup_low_keys (path, &disk_key,1 ); }btrfs_mark_buffer_dirty (buf);return 0 ;kernel-shared/ctree.c +0
-0
kernel-shared/ctree.c int btrfs_search_slot_for_read(struct btrfs_root *root, · line 1441
Quoted 5 lines
kernel-shared/ctree.c +0
-2@@ -1437,8 +1437,8 @@ int btrfs_search_slot_for_read(struct btrfs_root *root,* fixing up pointers when a given leaf/node is not in slot 0 of the * higher levels */ -void btrfs_fixup_low_keys (struct btrfs_root *root,struct btrfs_path *path, -struct btrfs_disk_key *key,int level)
Isn't it recommended to use btrfs_key instead of btrfs_disk_key nowadays?
Maybe a good time to cleanup unnecessary btrfs_disk_key usage?
Thanks,
Qu
Quoted 97 lines
kernel-shared/ctree.c +11
-11+void btrfs_fixup_low_keys (struct btrfs_path *path,struct btrfs_disk_key *key, +int level) {int i;struct extent_buffer *t;@@ -1485,7 +1485,7 @@ int btrfs_set_item_key_safe(struct btrfs_root *root, struct btrfs_path *path,btrfs_set_item_key (eb, &disk_key, slot);btrfs_mark_buffer_dirty (eb);if (slot ==0 ) -btrfs_fixup_low_keys (root, path, &disk_key,1 ); +btrfs_fixup_low_keys (path, &disk_key,1 );return 0 ; }@@ -1508,7 +1508,7 @@ void btrfs_set_item_key_unsafe(struct btrfs_root *root,btrfs_set_item_key (eb, &disk_key, slot);btrfs_mark_buffer_dirty (eb);if (slot ==0 ) -btrfs_fixup_low_keys (root, path, &disk_key,1 ); +btrfs_fixup_low_keys (path, &disk_key,1 ); }/* @@ -2184,7 +2184,7 @@ static int push_leaf_left(struct btrfs_trans_handle *trans, struct btrfs_rootbtrfs_mark_buffer_dirty (right);btrfs_item_key (right, &disk_key,0 ); -btrfs_fixup_low_keys (root, path, &disk_key,1 ); +btrfs_fixup_low_keys (path, &disk_key,1 );/* then fixup the leaf pointer in the path */ if (path->slots[0 ] < push_items) {@@ -2415,10 +2415,8 @@ static noinline int split_leaf(struct btrfs_trans_handle *trans,free_extent_buffer (path->nodes[0 ]); path->nodes[0 ] = right; path->slots[0 ] =0 ; -if (path->slots[1 ] ==0 ) { -btrfs_fixup_low_keys (root, path, - &disk_key,1 ); - } +if (path->slots[1 ] ==0 ) +btrfs_fixup_low_keys (path, &disk_key,1 ); }btrfs_mark_buffer_dirty (right);return ret;@@ -2632,7 +2630,7 @@ int btrfs_truncate_item(struct btrfs_root *root, struct btrfs_path *path,btrfs_set_disk_key_offset (&disk_key, offset + size_diff);btrfs_set_item_key (leaf, &disk_key, slot);if (slot ==0 ) -btrfs_fixup_low_keys (root, path, &disk_key,1 ); +btrfs_fixup_low_keys (path, &disk_key,1 ); } item =btrfs_item_nr (slot);@@ -2809,7 +2807,7 @@ int btrfs_insert_empty_items(struct btrfs_trans_handle *trans, ret =0 ;if (slot ==0 ) {btrfs_cpu_key_to_disk (&disk_key, cpu_key); -btrfs_fixup_low_keys (root, path, &disk_key,1 ); +btrfs_fixup_low_keys (path, &disk_key,1 ); }if (btrfs_leaf_free_space (leaf) <0 ) {@@ -2882,7 +2880,7 @@ int btrfs_del_ptr(struct btrfs_root *root, struct btrfs_path *path,struct btrfs_disk_key disk_key;btrfs_node_key (parent, &disk_key,0 ); -btrfs_fixup_low_keys (root, path, &disk_key, level +1 ); +btrfs_fixup_low_keys (path, &disk_key, level +1 ); }btrfs_mark_buffer_dirty (parent);return ret;@@ -2982,7 +2980,7 @@ int btrfs_del_items(struct btrfs_trans_handle *trans, struct btrfs_root *root,struct btrfs_disk_key disk_key;btrfs_item_key (leaf, &disk_key,0 ); -btrfs_fixup_low_keys (root, path, &disk_key,1 ); +btrfs_fixup_low_keys (path, &disk_key,1 ); }/* delete the leaf if it is mostly empty */ kernel-shared/ctree.h +2
-2@@ -2747,8 +2747,8 @@ static inline int btrfs_next_item(struct btrfs_root *root,int btrfs_prev_leaf (struct btrfs_root *root,struct btrfs_path *path);int btrfs_leaf_free_space (struct extent_buffer *leaf); -void btrfs_fixup_low_keys (struct btrfs_root *root,struct btrfs_path *path, -struct btrfs_disk_key *key,int level); +void btrfs_fixup_low_keys (struct btrfs_path *path,struct btrfs_disk_key *key, +int level);int btrfs_set_item_key_safe (struct btrfs_root *root,struct btrfs_path *path,struct btrfs_key *new_key); void btrfs_set_item_key_unsafe(struct btrfs_root *root,
PATCH 3/8 btrfs-progs: Remove fs_info argument from leaf_data_end
In reply to Nikolay BorisovThe function already takes an extent_buffer which has a reference to the owning filesystem's fs_info. This also brings the function in line with the kernel's signature.
--- kernel-shared/ctree.c | 35 +++++++++++++++-------------------- 1 file changed, 15 insertions(+), 20 deletions(-)
kernel-shared/ctree.c +15 -20
@@ -557,12 +557,11 @@ static int btrfs_comp_keys(struct btrfs_disk_key *disk,* this returns the address of the start of the last item, * which is the stop of the leaf data stack */ -static inline unsigned int leaf_data_end (const struct btrfs_fs_info *fs_info, -const struct extent_buffer *leaf) +static inline unsigned int leaf_data_end (const struct extent_buffer *leaf) {u32 nr =btrfs_header_nritems (leaf);if (nr ==0 ) -return BTRFS_LEAF_DATA_SIZE (fs_info); +return BTRFS_LEAF_DATA_SIZE (leaf->fs_info);return btrfs_item_offset_nr (leaf, nr -1 ); }
@@ -1980,10 +1979,10 @@ static int push_leaf_right(struct btrfs_trans_handle *trans, struct btrfs_root right_nritems =btrfs_header_nritems (right); push_space =btrfs_item_end_nr (left, left_nritems - push_items); - push_space -=leaf_data_end (fs_info, left); + push_space -=leaf_data_end (left);/* make room in the right data area */ - data_end =leaf_data_end (fs_info, right); + data_end =leaf_data_end (right); memmove_extent_buffer(right, btrfs_leaf_data(right) + data_end - push_space, btrfs_leaf_data(right) + data_end,
@@ -1992,8 +1991,7 @@ static int push_leaf_right(struct btrfs_trans_handle *trans, struct btrfs_root/* copy from the left data area */ copy_extent_buffer (right, left,btrfs_leaf_data (right) +BTRFS_LEAF_DATA_SIZE (root->fs_info) - push_space, -btrfs_leaf_data (left) +leaf_data_end (fs_info, left), - push_space); +btrfs_leaf_data (left) +leaf_data_end (left), push_space); memmove_extent_buffer(right, btrfs_item_nr_offset(push_items), btrfs_item_nr_offset(0),
@@ -2130,7 +2128,7 @@ static int push_leaf_left(struct btrfs_trans_handle *trans, struct btrfs_rootbtrfs_item_offset_nr (right, push_items -1 );copy_extent_buffer (left, right,btrfs_leaf_data (left) + -leaf_data_end (fs_info, left) - push_space, +leaf_data_end (left) - push_space,btrfs_leaf_data (right) +btrfs_item_offset_nr (right, push_items -1 ), push_space);
@@ -2157,13 +2155,12 @@ static int push_leaf_left(struct btrfs_trans_handle *trans, struct btrfs_rootif (push_items < right_nritems) { push_space =btrfs_item_offset_nr (right, push_items -1 ) - -leaf_data_end (fs_info, right); +leaf_data_end (right);memmove_extent_buffer (right,btrfs_leaf_data (right) +BTRFS_LEAF_DATA_SIZE (root->fs_info) - push_space,btrfs_leaf_data (right) + -leaf_data_end (fs_info, right), - push_space); +leaf_data_end (right), push_space); memmove_extent_buffer(right, btrfs_item_nr_offset(0), btrfs_item_nr_offset(push_items),
@@ -2222,8 +2219,7 @@ static noinline int copy_for_split(struct btrfs_trans_handle *trans, nritems = nritems - mid;btrfs_set_header_nritems (right, nritems); - data_copy_size =btrfs_item_end_nr (l, mid) - -leaf_data_end (root->fs_info, l); + data_copy_size =btrfs_item_end_nr (l, mid) -leaf_data_end (l); copy_extent_buffer(right, l, btrfs_item_nr_offset(0), btrfs_item_nr_offset(mid),
@@ -2231,9 +2227,8 @@ static noinline int copy_for_split(struct btrfs_trans_handle *trans,copy_extent_buffer (right, l,btrfs_leaf_data (right) + -BTRFS_LEAF_DATA_SIZE (root->fs_info) - - data_copy_size,btrfs_leaf_data (l) + -leaf_data_end (root->fs_info, l), data_copy_size); +BTRFS_LEAF_DATA_SIZE (root->fs_info) - data_copy_size, +btrfs_leaf_data (l) +leaf_data_end (l), data_copy_size); rt_data_off =BTRFS_LEAF_DATA_SIZE (root->fs_info) -btrfs_item_end_nr (l, mid);
@@ -2572,7 +2567,7 @@ int btrfs_truncate_item(struct btrfs_root *root, struct btrfs_path *path,return 0 ; nritems =btrfs_header_nritems (leaf); - data_end =leaf_data_end (root->fs_info, leaf); + data_end =leaf_data_end (leaf); old_data_start =btrfs_item_offset_nr (leaf, slot);
@@ -2661,7 +2656,7 @@ int btrfs_extend_item(struct btrfs_root *root, struct btrfs_path *path, leaf = path->nodes[0 ]; nritems =btrfs_header_nritems (leaf); - data_end =leaf_data_end (root->fs_info, leaf); + data_end =leaf_data_end (leaf);if (btrfs_leaf_free_space (leaf) < data_size) {btrfs_print_leaf (leaf,BTRFS_PRINT_TREE_DEFAULT );
@@ -2747,7 +2742,7 @@ int btrfs_insert_empty_items(struct btrfs_trans_handle *trans, leaf = path->nodes[0 ]; nritems =btrfs_header_nritems (leaf); - data_end =leaf_data_end (root->fs_info, leaf); + data_end =leaf_data_end (leaf);if (btrfs_leaf_free_space (leaf) < total_size) {btrfs_print_leaf (leaf,BTRFS_PRINT_TREE_DEFAULT );
@@ -2940,7 +2935,7 @@ int btrfs_del_items(struct btrfs_trans_handle *trans, struct btrfs_root *root, nritems =btrfs_header_nritems (leaf);if (slot + nr != nritems) { -int data_end =leaf_data_end (root->fs_info, leaf); +int data_end =leaf_data_end (leaf); memmove_extent_buffer(leaf, btrfs_leaf_data(leaf) + data_end + dsize,
Signature · 1 line
2.17.1
Re: [PATCH 3/8] btrfs-progs: Remove fs_info argument from leaf_data_end
Quoted 5 lines · Nikolay Borisov
The function already takes an
extent_bufferwhich has a reference to the owning filesystem'sfs_info. This also brings the function in line with the kernel's signature.Signed-off-by Nikolay Borisov <[email protected]>
Thanks,
Qu
Quoted 130 lines
--- kernel-shared/ctree.c | 35 +++++++++++++++-------------------- 1 file changed, 15 insertions(+), 20 deletions(-)kernel-shared/ctree.c +15
-20@@ -557,12 +557,11 @@ static int btrfs_comp_keys(struct btrfs_disk_key *disk,* this returns the address of the start of the last item, * which is the stop of the leaf data stack */ -static inline unsigned int leaf_data_end (const struct btrfs_fs_info *fs_info, -const struct extent_buffer *leaf) +static inline unsigned int leaf_data_end (const struct extent_buffer *leaf) {u32 nr =btrfs_header_nritems (leaf);if (nr ==0 ) -return BTRFS_LEAF_DATA_SIZE (fs_info); +return BTRFS_LEAF_DATA_SIZE (leaf->fs_info);return btrfs_item_offset_nr (leaf, nr -1 ); }@@ -1980,10 +1979,10 @@ static int push_leaf_right(struct btrfs_trans_handle *trans, struct btrfs_root right_nritems =btrfs_header_nritems (right); push_space =btrfs_item_end_nr (left, left_nritems - push_items); - push_space -=leaf_data_end (fs_info, left); + push_space -=leaf_data_end (left);/* make room in the right data area */ - data_end =leaf_data_end (fs_info, right); + data_end =leaf_data_end (right); memmove_extent_buffer(right, btrfs_leaf_data(right) + data_end - push_space, btrfs_leaf_data(right) + data_end,@@ -1992,8 +1991,7 @@ static int push_leaf_right(struct btrfs_trans_handle *trans, struct btrfs_root/* copy from the left data area */ copy_extent_buffer (right, left,btrfs_leaf_data (right) +BTRFS_LEAF_DATA_SIZE (root->fs_info) - push_space, -btrfs_leaf_data (left) +leaf_data_end (fs_info, left), - push_space); +btrfs_leaf_data (left) +leaf_data_end (left), push_space); memmove_extent_buffer(right, btrfs_item_nr_offset(push_items), btrfs_item_nr_offset(0),@@ -2130,7 +2128,7 @@ static int push_leaf_left(struct btrfs_trans_handle *trans, struct btrfs_rootbtrfs_item_offset_nr (right, push_items -1 );copy_extent_buffer (left, right,btrfs_leaf_data (left) + -leaf_data_end (fs_info, left) - push_space, +leaf_data_end (left) - push_space,btrfs_leaf_data (right) +btrfs_item_offset_nr (right, push_items -1 ), push_space);@@ -2157,13 +2155,12 @@ static int push_leaf_left(struct btrfs_trans_handle *trans, struct btrfs_rootif (push_items < right_nritems) { push_space =btrfs_item_offset_nr (right, push_items -1 ) - -leaf_data_end (fs_info, right); +leaf_data_end (right);memmove_extent_buffer (right,btrfs_leaf_data (right) +BTRFS_LEAF_DATA_SIZE (root->fs_info) - push_space,btrfs_leaf_data (right) + -leaf_data_end (fs_info, right), - push_space); +leaf_data_end (right), push_space); memmove_extent_buffer(right, btrfs_item_nr_offset(0), btrfs_item_nr_offset(push_items),@@ -2222,8 +2219,7 @@ static noinline int copy_for_split(struct btrfs_trans_handle *trans, nritems = nritems - mid;btrfs_set_header_nritems (right, nritems); - data_copy_size =btrfs_item_end_nr (l, mid) - -leaf_data_end (root->fs_info, l); + data_copy_size =btrfs_item_end_nr (l, mid) -leaf_data_end (l); copy_extent_buffer(right, l, btrfs_item_nr_offset(0), btrfs_item_nr_offset(mid),@@ -2231,9 +2227,8 @@ static noinline int copy_for_split(struct btrfs_trans_handle *trans,copy_extent_buffer (right, l,btrfs_leaf_data (right) + -BTRFS_LEAF_DATA_SIZE (root->fs_info) - - data_copy_size,btrfs_leaf_data (l) + -leaf_data_end (root->fs_info, l), data_copy_size); +BTRFS_LEAF_DATA_SIZE (root->fs_info) - data_copy_size, +btrfs_leaf_data (l) +leaf_data_end (l), data_copy_size); rt_data_off =BTRFS_LEAF_DATA_SIZE (root->fs_info) -btrfs_item_end_nr (l, mid);@@ -2572,7 +2567,7 @@ int btrfs_truncate_item(struct btrfs_root *root, struct btrfs_path *path,return 0 ; nritems =btrfs_header_nritems (leaf); - data_end =leaf_data_end (root->fs_info, leaf); + data_end =leaf_data_end (leaf); old_data_start =btrfs_item_offset_nr (leaf, slot);@@ -2661,7 +2656,7 @@ int btrfs_extend_item(struct btrfs_root *root, struct btrfs_path *path, leaf = path->nodes[0 ]; nritems =btrfs_header_nritems (leaf); - data_end =leaf_data_end (root->fs_info, leaf); + data_end =leaf_data_end (leaf);if (btrfs_leaf_free_space (leaf) < data_size) {btrfs_print_leaf (leaf,BTRFS_PRINT_TREE_DEFAULT );@@ -2747,7 +2742,7 @@ int btrfs_insert_empty_items(struct btrfs_trans_handle *trans, leaf = path->nodes[0 ]; nritems =btrfs_header_nritems (leaf); - data_end =leaf_data_end (root->fs_info, leaf); + data_end =leaf_data_end (leaf);if (btrfs_leaf_free_space (leaf) < total_size) {btrfs_print_leaf (leaf,BTRFS_PRINT_TREE_DEFAULT );@@ -2940,7 +2935,7 @@ int btrfs_del_items(struct btrfs_trans_handle *trans, struct btrfs_root *root, nritems =btrfs_header_nritems (leaf);if (slot + nr != nritems) { -int data_end =leaf_data_end (root->fs_info, leaf); +int data_end =leaf_data_end (leaf); memmove_extent_buffer(leaf, btrfs_leaf_data(leaf) + data_end + dsize,
PATCH 4/8 btrfs-progs: Remove root argument from btrfs_truncate_item
In reply to Nikolay BorisovThis function lies in the kernel-shared directory and is supposed to be close to 1:1 copy with its kernel counterpart, yet it takes one extra argument - root. But this is now unused to simply remove it.
--- kernel-shared/ctree.c | 3 +-- kernel-shared/ctree.h | 3 +-- kernel-shared/dir-item.c | 2 +- kernel-shared/extent-tree.c | 2 +- kernel-shared/file-item.c | 4 ++-- kernel-shared/inode-item.c | 4 ++-- 6 files changed, 8 insertions(+), 10 deletions(-)
kernel-shared/ctree.c +1 -2
@@ -2545,8 +2545,7 @@ int btrfs_split_item(struct btrfs_trans_handle *trans,return ret; } -int btrfs_truncate_item (struct btrfs_root *root,struct btrfs_path *path, -u32 new_size,int from_end) +int btrfs_truncate_item (struct btrfs_path *path,u32 new_size,int from_end) {int ret =0 ;int slot;
kernel-shared/ctree.h +1 -2
@@ -2670,8 +2670,7 @@ int btrfs_create_root(struct btrfs_trans_handle *trans, struct btrfs_fs_info *fs_info, u64 objectid);int btrfs_extend_item (struct btrfs_root *root,struct btrfs_path *path,u32 data_size); -int btrfs_truncate_item (struct btrfs_root *root,struct btrfs_path *path, -u32 new_size,int from_end); +int btrfs_truncate_item (struct btrfs_path *path,u32 new_size,int from_end); int btrfs_split_item(struct btrfs_trans_handle *trans, struct btrfs_root *root, struct btrfs_path *path,
kernel-shared/dir-item.c +1 -1
@@ -284,7 +284,7 @@ int btrfs_delete_one_dir_name(struct btrfs_trans_handle *trans, start =btrfs_item_ptr_offset (leaf, path->slots[0 ]);memmove_extent_buffer (leaf, ptr, ptr + sub_item_len, item_len - (ptr + sub_item_len - start)); -btrfs_truncate_item (root, path, item_len - sub_item_len,1 ); +btrfs_truncate_item (path, item_len - sub_item_len,1 ); }return ret; }
kernel-shared/extent-tree.c +1 -1
@@ -1166,7 +1166,7 @@ static int update_inline_extent_backref(struct btrfs_trans_handle *trans,memmove_extent_buffer (leaf, ptr, ptr + size, end - ptr - size); item_size -= size; - ret =btrfs_truncate_item (root, path, item_size,1 ); + ret =btrfs_truncate_item (path, item_size,1 );BUG_ON (ret); }btrfs_mark_buffer_dirty (leaf);
kernel-shared/file-item.c +2 -2
@@ -362,7 +362,7 @@ static noinline int truncate_one_csum(struct btrfs_root *root,*/ u32 new_size = (bytenr - key->offset) / blocksize; new_size *= csum_size; - ret =btrfs_truncate_item (root, path, new_size,1 ); + ret =btrfs_truncate_item (path, new_size,1 );BUG_ON (ret); }else if (key->offset >= bytenr && csum_end > end_byte && end_byte > key->offset) {
@@ -375,7 +375,7 @@ static noinline int truncate_one_csum(struct btrfs_root *root,u32 new_size = (csum_end - end_byte) / blocksize; new_size *= csum_size; - ret =btrfs_truncate_item (root, path, new_size,0 ); + ret =btrfs_truncate_item (path, new_size,0 );BUG_ON (ret); key->offset = end_byte;
kernel-shared/inode-item.c +2 -2
@@ -311,7 +311,7 @@ int btrfs_del_inode_extref(struct btrfs_trans_handle *trans,memmove_extent_buffer (leaf, ptr, ptr + del_len, item_size - (ptr + del_len - item_start)); -btrfs_truncate_item (root, path, item_size - del_len,1 ); +btrfs_truncate_item (path, item_size - del_len,1 ); out:btrfs_free_path (path);
@@ -432,7 +432,7 @@ int btrfs_del_inode_ref(struct btrfs_trans_handle *trans, item_start =btrfs_item_ptr_offset (leaf, path->slots[0 ]);memmove_extent_buffer (leaf, ptr, ptr + sub_item_len, item_size - (ptr + sub_item_len - item_start)); -btrfs_truncate_item (root, path, item_size - sub_item_len,1 ); +btrfs_truncate_item (path, item_size - sub_item_len,1 );btrfs_mark_buffer_dirty (path->nodes[0 ]); out:btrfs_free_path (path);
Signature · 1 line
2.17.1
Re: [PATCH 4/8] btrfs-progs: Remove root argument from btrfs_truncate_item
Quoted 5 lines · Nikolay Borisov
This function lies in the kernel-shared directory and is supposed to be close to 1:1 copy with its kernel counterpart, yet it takes one extra argument - root. But this is now unused to simply remove it.
Signed-off-by Nikolay Borisov <[email protected]>
Thanks,
Qu
Quoted 108 lines
--- kernel-shared/ctree.c | 3 +-- kernel-shared/ctree.h | 3 +-- kernel-shared/dir-item.c | 2 +- kernel-shared/extent-tree.c | 2 +- kernel-shared/file-item.c | 4 ++-- kernel-shared/inode-item.c | 4 ++-- 6 files changed, 8 insertions(+), 10 deletions(-)kernel-shared/ctree.c +1
-2@@ -2545,8 +2545,7 @@ int btrfs_split_item(struct btrfs_trans_handle *trans,return ret; } -int btrfs_truncate_item (struct btrfs_root *root,struct btrfs_path *path, -u32 new_size,int from_end) +int btrfs_truncate_item (struct btrfs_path *path,u32 new_size,int from_end) {int ret =0 ;int slot;kernel-shared/ctree.h +1
-2@@ -2670,8 +2670,7 @@ int btrfs_create_root(struct btrfs_trans_handle *trans, struct btrfs_fs_info *fs_info, u64 objectid);int btrfs_extend_item (struct btrfs_root *root,struct btrfs_path *path,u32 data_size); -int btrfs_truncate_item (struct btrfs_root *root,struct btrfs_path *path, -u32 new_size,int from_end); +int btrfs_truncate_item (struct btrfs_path *path,u32 new_size,int from_end); int btrfs_split_item(struct btrfs_trans_handle *trans, struct btrfs_root *root, struct btrfs_path *path,kernel-shared/dir-item.c +1
-1@@ -284,7 +284,7 @@ int btrfs_delete_one_dir_name(struct btrfs_trans_handle *trans, start =btrfs_item_ptr_offset (leaf, path->slots[0 ]);memmove_extent_buffer (leaf, ptr, ptr + sub_item_len, item_len - (ptr + sub_item_len - start)); -btrfs_truncate_item (root, path, item_len - sub_item_len,1 ); +btrfs_truncate_item (path, item_len - sub_item_len,1 ); }return ret; }kernel-shared/extent-tree.c +1
-1@@ -1166,7 +1166,7 @@ static int update_inline_extent_backref(struct btrfs_trans_handle *trans,memmove_extent_buffer (leaf, ptr, ptr + size, end - ptr - size); item_size -= size; - ret =btrfs_truncate_item (root, path, item_size,1 ); + ret =btrfs_truncate_item (path, item_size,1 );BUG_ON (ret); }btrfs_mark_buffer_dirty (leaf);kernel-shared/file-item.c +2
-2@@ -362,7 +362,7 @@ static noinline int truncate_one_csum(struct btrfs_root *root,*/ u32 new_size = (bytenr - key->offset) / blocksize; new_size *= csum_size; - ret =btrfs_truncate_item (root, path, new_size,1 ); + ret =btrfs_truncate_item (path, new_size,1 );BUG_ON (ret); }else if (key->offset >= bytenr && csum_end > end_byte && end_byte > key->offset) {@@ -375,7 +375,7 @@ static noinline int truncate_one_csum(struct btrfs_root *root,u32 new_size = (csum_end - end_byte) / blocksize; new_size *= csum_size; - ret =btrfs_truncate_item (root, path, new_size,0 ); + ret =btrfs_truncate_item (path, new_size,0 );BUG_ON (ret); key->offset = end_byte;kernel-shared/inode-item.c +2
-2@@ -311,7 +311,7 @@ int btrfs_del_inode_extref(struct btrfs_trans_handle *trans,memmove_extent_buffer (leaf, ptr, ptr + del_len, item_size - (ptr + del_len - item_start)); -btrfs_truncate_item (root, path, item_size - del_len,1 ); +btrfs_truncate_item (path, item_size - del_len,1 ); out:btrfs_free_path (path);@@ -432,7 +432,7 @@ int btrfs_del_inode_ref(struct btrfs_trans_handle *trans, item_start =btrfs_item_ptr_offset (leaf, path->slots[0 ]);memmove_extent_buffer (leaf, ptr, ptr + sub_item_len, item_size - (ptr + sub_item_len - item_start)); -btrfs_truncate_item (root, path, item_size - sub_item_len,1 ); +btrfs_truncate_item (path, item_size - sub_item_len,1 );btrfs_mark_buffer_dirty (path->nodes[0 ]); out:btrfs_free_path (path);
PATCH 5/8 btrfs-progs: Add btrfs_uuid_tree_remove
In reply to Nikolay BorisovIt will be used to clear received data on RW snapshots that were received.
--- kernel-shared/ctree.h | 3 ++ kernel-shared/uuid-tree.c | 82 +++++++++++++++++++++++++++++++++++++++ 2 files changed, 85 insertions(+)
kernel-shared/ctree.h +3 -0
@@ -2860,6 +2860,9 @@ int btrfs_uuid_tree_add(struct btrfs_trans_handle *trans, u8 *uuid, u8 type, u64 subvol_id_cpu);int btrfs_is_empty_uuid (u8 *uuid); +int btrfs_uuid_tree_remove (struct btrfs_trans_handle *trans,u8 *uuid,u8 type, +u64 subid); +static inline int is_fstree (u64 rootid) {
kernel-shared/uuid-tree.c +82 -0
85 lines not on this page · raw message
Signature · 1 line
2.17.1
Re: [PATCH 5/8] btrfs-progs: Add btrfs_uuid_tree_remove
Quoted 14 lines · Nikolay Borisov
It will be used to clear received data on RW snapshots that were received.
Signed-off-by Nikolay Borisov <[email protected]>--- kernel-shared/ctree.h | 3 ++ kernel-shared/uuid-tree.c | 82 +++++++++++++++++++++++++++++++++++++++ 2 files changed, 85 insertions(+)kernel-shared/ctree.h +0
-0
kernel-shared/ctree.h int btrfs_uuid_tree_add(struct btrfs_trans_handle *trans, u8 *uuid, u8 type, · line 2865
Quoted 6 lines
kernel-shared/ctree.h +3
-0@@ -2860,6 +2860,9 @@ int btrfs_uuid_tree_add(struct btrfs_trans_handle *trans, u8 *uuid, u8 type, u64 subvol_id_cpu);int btrfs_is_empty_uuid (u8 *uuid); +int btrfs_uuid_tree_remove (struct btrfs_trans_handle *trans,u8 *uuid,u8 type, +u64 subid); +
I have checked the callers in the incoming check patches, they are all starting a new trans on uuid tree, thus there is no need to start a trans out of this function.
Let's just pass the subvolume root into the function, and start a new trans in side the function.
So that we only need one parameter @root, everything else can be fetched from @root, and we can also modify the root item and uuid tree just in one go.
Thanks,
Qu
Quoted 94 lines
kernel-shared/ctree.h +0
-0static inline int is_fstree (u64 rootid) {kernel-shared/uuid-tree.c +82
-0@@ -120,3 +120,85 @@ int btrfs_is_empty_uuid(u8 *uuid) }return 1 ; } + +int btrfs_uuid_tree_remove (struct btrfs_trans_handle *trans,u8 *uuid,u8 type, +u64 subid) +{ +struct btrfs_fs_info *fs_info = trans->fs_info; +struct btrfs_root *uuid_root = fs_info->uuid_root; +int ret; +struct btrfs_path *path =NULL ; +struct btrfs_key key; +struct extent_buffer *eb; +int slot; +unsigned long offset; +u32 item_size; +unsigned long move_dst; +unsigned long move_src; +unsigned long move_len; + +if (!uuid_root) { + ret = -EINVAL ; + goto out; + } + +btrfs_uuid_to_key (uuid, &key); + key.type = type; + + path =btrfs_alloc_path (); +if (!path) { + ret = -ENOMEM ; + goto out; + } + + ret =btrfs_search_slot (trans, uuid_root, &key, path,-1 ,1 ); +if (ret <0 ) { +warning ("error %d while searching for uuid item!" , ret); + goto out; + } +if (ret >0 ) { + ret = -ENOENT ; + goto out; + } + + + eb = path->nodes[0 ]; + slot = path->slots[0 ]; + offset =btrfs_item_ptr_offset (eb, slot); + item_size =btrfs_item_size_nr (eb, slot); +if (!IS_ALIGNED (item_size,sizeof (u64))) { +warning ("uuid item with illegal size %lu!" , (unsigned long )item_size); + ret = -ENOENT ; + goto out; + } +while (item_size) { +__le64 read_subid; + +read_extent_buffer (eb, &read_subid, offset,sizeof (read_subid)); +if (le64_to_cpu (read_subid) == subid) +break ; + offset +=sizeof (read_subid); + item_size -=sizeof (read_subid); + } + +if (!item_size) { + ret = -ENOENT ; + goto out; + } + + item_size =btrfs_item_size_nr (eb, slot); +if (item_size ==sizeof (subid)) { + ret =btrfs_del_item (trans, uuid_root, path); + goto out; + } + + move_dst = offset; + move_src = offset +sizeof (subid); + move_len = item_size - (move_src -btrfs_item_ptr_offset (eb, slot)); +memmove_extent_buffer (eb, move_dst, move_src, move_len); +btrfs_truncate_item (path, item_size -sizeof (subid),1 ); + +out: +btrfs_free_path (path); +return ret; +}
Re: [PATCH 5/8] btrfs-progs: Add btrfs_uuid_tree_remove
Quoted 30 lines · Qu Wenruo
Quoted 14 lines · Nikolay Borisov
It will be used to clear received data on RW snapshots that were received.
Signed-off-by Nikolay Borisov <[email protected]>---
kernel-shared/ctree.h | 3 ++kernel-shared/uuid-tree.c| 82 +++++++++++++++++++++++++++++++++++++++2 files changed, 85 insertions(+)kernel-shared/ctree.h +0
-0kernel-shared/ctree.h int btrfs_uuid_tree_add(struct · line 2867
Quoted 8 lines
kernel-shared/ctree.h +3
-0@@ -2860,6 +2860,9 @@ int btrfs_uuid_tree_add(struct btrfs_trans_handle *trans, u8 *uuid, u8 type, u64 subvol_id_cpu); int btrfs_is_empty_uuid(u8 *uuid); +int btrfs_uuid_tree_remove (struct btrfs_trans_handle *trans,u8 *uuid,u8 type, + u64 subid); +I have checked the callers in the incoming check patches, they are all starting a new trans on uuid tree, thus there is no need to start a trans out of this function.
Quoted 6 lines
Let's just pass the subvolume root into the function, and start a new trans in side the function.
So that we only need one parameter @root, everything else can be fetched from @root, and we can also modify the root item and uuid tree just in one go.
I disagree, this function is a direct copy from the kernel with the only adjustment that btrfs_uuid_to_key doesn't set key.type. If I change it in progs then this means it won't be unified with the kernel when this happens (if ever). I really rather keep shared functions as close as possible.
Quoted 100 lines
Thanks,
QuQuoted 96 lines
kernel-shared/ctree.h +0
-0static inline int is_fstree(u64 rootid){
kernel-shared/uuid-tree.c +2
-0@@ -120,3 +120,85 @@ int btrfs_is_empty_uuid(u8 *uuid) } return 1; } + +int btrfs_uuid_tree_remove(struct btrfs_trans_handle *trans, u8*uuid, u8 type,
+ u64 subid)kernel-shared/uuid-tree.c +45
-0+{ + struct btrfs_fs_info *fs_info = trans->fs_info; + struct btrfs_root *uuid_root = fs_info->uuid_root; + int ret; + struct btrfs_path *path = NULL; + struct btrfs_key key; + struct extent_buffer *eb; + int slot; + unsigned long offset; + u32 item_size; + unsigned long move_dst; + unsigned long move_src; + unsigned long move_len; + + if (!uuid_root) { + ret = -EINVAL; + goto out; + } + + btrfs_uuid_to_key(uuid, &key); + key.type = type; + + path = btrfs_alloc_path(); + if (!path) { + ret = -ENOMEM; + goto out; + } + + ret = btrfs_search_slot(trans, uuid_root, &key, path, -1, 1); + if (ret < 0) { + warning("error %d while searching for uuid item!", ret); + goto out; + } + if (ret > 0) { + ret = -ENOENT; + goto out; + } + + + eb = path->nodes[0]; + slot = path->slots[0]; + offset = btrfs_item_ptr_offset(eb, slot); + item_size = btrfs_item_size_nr(eb, slot); + if (!IS_ALIGNED(item_size, sizeof(u64))) { + warning("uuid item with illegal size %lu!", (unsignedlong)item_size);
+ ret =-ENOENT;
+ goto out;
+ }
+ while (item_size) {
+__le64read_subid;kernel-shared/uuid-tree.c +29
-0+ + read_extent_buffer(eb, &read_subid, offset, sizeof(read_subid)); + if (le64_to_cpu(read_subid) == subid) + break; + offset += sizeof(read_subid); + item_size -= sizeof(read_subid); + } + + if (!item_size) { + ret = -ENOENT; + goto out; + } + + item_size = btrfs_item_size_nr(eb, slot); + if (item_size == sizeof(subid)) { + ret = btrfs_del_item(trans, uuid_root, path); + goto out; + } + + move_dst = offset; + move_src = offset + sizeof(subid); + move_len = item_size - (move_src - btrfs_item_ptr_offset(eb, slot)); + memmove_extent_buffer(eb, move_dst, move_src, move_len); + btrfs_truncate_item(path, item_size - sizeof(subid), 1); + +out: + btrfs_free_path(path); + return ret; +}
Re: [PATCH 5/8] btrfs-progs: Add btrfs_uuid_tree_remove
Quoted 40 lines · Nikolay Borisov
Quoted 30 lines · Qu Wenruo
Quoted 14 lines · Nikolay Borisov
It will be used to clear received data on RW snapshots that were received.
Signed-off-by Nikolay Borisov <[email protected]>--- kernel-shared/ctree.h | 3 ++ kernel-shared/uuid-tree.c | 82 +++++++++++++++++++++++++++++++++++++++ 2 files changed, 85 insertions(+)kernel-shared/ctree.h +0
-0kernel-shared/ctree.h int btrfs_uuid_tree_add(struct · line 2867
Quoted 8 lines
kernel-shared/ctree.h +3
-0@@ -2860,6 +2860,9 @@ int btrfs_uuid_tree_add(struct btrfs_trans_handle *trans, u8 *uuid, u8 type, u64 subvol_id_cpu); int btrfs_is_empty_uuid(u8 *uuid); +int btrfs_uuid_tree_remove (struct btrfs_trans_handle *trans,u8 *uuid,u8 type, + u64 subid); +I have checked the callers in the incoming check patches, they are all starting a new trans on uuid tree, thus there is no need to start a trans out of this function.
Quoted 6 lines
Let's just pass the subvolume root into the function, and start a new trans in side the function.
So that we only need one parameter @root, everything else can be fetched from @root, and we can also modify the root item and uuid tree just in one go.
Quoted 5 lines
I disagree, this function is a direct copy from the kernel with the only adjustment that
btrfs_uuid_to_keydoesn't set key.type. If I change it in progs then this means it won't be unified with the kernel when this happens (if ever). I really rather keep shared functions as close as possible.
OK, didn't notice it's really some shared function. (in kernel it's implemented in uuid-tree.c, not ctree.c).
Then maybe it's better to introduce a btrfs-progs specific helper like btrfs_remove_recevied_uuid(), other than calling the function directly.
In fact, both mode shares the same root item modification code, which is really a duplication.
As in btrfs-progs we don't need the other call sites in kernels which is shared for subvolume removal.
Thanks,
Qu
Quoted 101 lines
Quoted 101 lines
Thanks,
QuQuoted 96 lines
kernel-shared/ctree.h +0
-0static inline int is_fstree(u64 rootid){
kernel-shared/uuid-tree.c +2
-0@@ -120,3 +120,85 @@ int btrfs_is_empty_uuid(u8 *uuid) } return 1; } + +int btrfs_uuid_tree_remove(struct btrfs_trans_handle *trans, u8*uuid, u8 type,
+ u64 subid)kernel-shared/uuid-tree.c +45
-0+{ + struct btrfs_fs_info *fs_info = trans->fs_info; + struct btrfs_root *uuid_root = fs_info->uuid_root; + int ret; + struct btrfs_path *path = NULL; + struct btrfs_key key; + struct extent_buffer *eb; + int slot; + unsigned long offset; + u32 item_size; + unsigned long move_dst; + unsigned long move_src; + unsigned long move_len; + + if (!uuid_root) { + ret = -EINVAL; + goto out; + } + + btrfs_uuid_to_key(uuid, &key); + key.type = type; + + path = btrfs_alloc_path(); + if (!path) { + ret = -ENOMEM; + goto out; + } + + ret = btrfs_search_slot(trans, uuid_root, &key, path, -1, 1); + if (ret < 0) { + warning("error %d while searching for uuid item!", ret); + goto out; + } + if (ret > 0) { + ret = -ENOENT; + goto out; + } + + + eb = path->nodes[0]; + slot = path->slots[0]; + offset = btrfs_item_ptr_offset(eb, slot); + item_size = btrfs_item_size_nr(eb, slot); + if (!IS_ALIGNED(item_size, sizeof(u64))) { + warning("uuid item with illegal size %lu!", (unsignedlong)item_size);
+ ret =-ENOENT;
+ goto out;
+ }
+ while (item_size) {
+__le64read_subid;kernel-shared/uuid-tree.c +29
-0+ + read_extent_buffer(eb, &read_subid, offset, sizeof(read_subid)); + if (le64_to_cpu(read_subid) == subid) + break; + offset += sizeof(read_subid); + item_size -= sizeof(read_subid); + } + + if (!item_size) { + ret = -ENOENT; + goto out; + } + + item_size = btrfs_item_size_nr(eb, slot); + if (item_size == sizeof(subid)) { + ret = btrfs_del_item(trans, uuid_root, path); + goto out; + } + + move_dst = offset; + move_src = offset + sizeof(subid); + move_len = item_size - (move_src - btrfs_item_ptr_offset(eb, slot)); + memmove_extent_buffer(eb, move_dst, move_src, move_len); + btrfs_truncate_item(path, item_size - sizeof(subid), 1); + +out: + btrfs_free_path(path); + return ret; +}
PATCH 6/8 btrfs-progs: check/original: Implement removing received data for RW subvols
In reply to Nikolay BorisovMaking a received subvolume RO should preclude doing an incremental send of said subvolume since it can't be guaranteed that nothing changed in the structure and this in turn has correctness implications for send.
There is a pending kernel change that implements this behavior and ensures that in the future RO volumes which are switched to RW can't be used for incremental send. However, old kernels won't have that patch backported. To ensure there is a supported way for users to put their subvolumes in sane state let's implement the same functionality in progs.
--- check/main.c | 43 ++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 42 insertions(+), 1 deletion(-)
check/main.c +42 -1
@@ -3544,6 +3544,7 @@ static int check_fs_root(struct btrfs_root *root,int ret =0 ;int err =0 ;bool generation_err = false; +bool rw_received_err = false;int wret;int level;u64 super_generation;
@@ -3658,6 +3659,46 @@ static int check_fs_root(struct btrfs_root *root, sizeof(found_key))); } +if (!((btrfs_root_flags (root_item) &BTRFS_ROOT_SUBVOL_RDONLY ) || +btrfs_is_empty_uuid (root_item->received_uuid))) { +error ("Subvolume id: %llu is RW and has a received uuid" , + root->root_key.objectid); + rw_received_err = true; +if (repair) { +struct btrfs_trans_handle *trans =btrfs_start_transaction (root,2 ); +if (IS_ERR (trans)) +return PTR_ERR (trans); + + ret =btrfs_uuid_tree_remove (trans, root_item->received_uuid, +BTRFS_UUID_KEY_RECEIVED_SUBVOL , root->root_key.objectid); + +if (ret && ret != -ENOENT ) { +btrfs_abort_transaction (trans, ret); +return ret; + } + +memset (root_item->received_uuid,0 ,BTRFS_UUID_SIZE ); +btrfs_set_root_stransid (root_item,0 ); +btrfs_set_root_rtransid (root_item,0 ); +btrfs_set_stack_timespec_sec (&root_item->stime,0 ); +btrfs_set_stack_timespec_nsec (&root_item->stime,0 ); +btrfs_set_stack_timespec_sec (&root_item->rtime,0 ); +btrfs_set_stack_timespec_nsec (&root_item->rtime,0 ); + + ret =btrfs_update_root (trans, gfs_info->tree_root, &root->root_key, + root_item); +if (ret <0 ) { +btrfs_abort_transaction (trans, ret); +return ret; + } + +btrfs_commit_transaction (trans, gfs_info->tree_root); + rw_received_err = false; +printf ("Cleared received information for subvol: %llu\n" , + root->root_key.objectid); + } + } +while (1 ) { ctx.item_count++; wret =walk_down_tree (root, &path, wc, &level, &nrefs);
@@ -3722,7 +3763,7 @@ static int check_fs_root(struct btrfs_root *root,free_corrupt_blocks_tree (&corrupt_blocks); gfs_info->corrupt_blocks =NULL ; -if (!ret && generation_err) +if (!ret && (generation_err || rw_received_err)) ret =-1 ;return ret; }
Signature · 1 line
2.17.1
PATCH 7/8 btrfs-progs: check/lowmem: Implement received info clearing for RW volumes
In reply to Nikolay BorisovThis is the counterpart to the original mode's implementation but for lowmem. I've put the code under the if (!check_all) branch because otherwise the check is run multiple times - from check_chunks_and_extents_lowmem and from actual fs_root check. By having it under the !check_all condition in check_btrfs_root it ensures that the check is performed only when checking the fs roots themselves.
--- check/mode-lowmem.c | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+)
check/mode-lowmem.c +38 -0
@@ -5197,6 +5197,44 @@ static int check_btrfs_root(struct btrfs_root *root, int check_all) ret =check_fs_first_inode (root);if (ret <0 )return FATAL_ERROR ; + +if (!((btrfs_root_flags (root_item) &BTRFS_ROOT_SUBVOL_RDONLY ) || +btrfs_is_empty_uuid (root_item->received_uuid))) { +printf ("Subvolume id: %llu is RW and has a received uuid\n" , + root->root_key.objectid); +if (repair) { +struct btrfs_trans_handle *trans =btrfs_start_transaction (root,2 ); +if (IS_ERR (trans)) +return PTR_ERR (trans); + + ret =btrfs_uuid_tree_remove (trans, root_item->received_uuid, +BTRFS_UUID_KEY_RECEIVED_SUBVOL , root->root_key.objectid); + +if (ret && ret != -ENOENT ) { +btrfs_abort_transaction (trans, ret); +return ret; + } + +memset (root_item->received_uuid,0 ,BTRFS_UUID_SIZE ); +btrfs_set_root_stransid (root_item,0 ); +btrfs_set_root_rtransid (root_item,0 ); +btrfs_set_stack_timespec_sec (&root_item->stime,0 ); +btrfs_set_stack_timespec_nsec (&root_item->stime,0 ); +btrfs_set_stack_timespec_sec (&root_item->rtime,0 ); +btrfs_set_stack_timespec_nsec (&root_item->rtime,0 ); + + ret =btrfs_update_root (trans, gfs_info->tree_root, &root->root_key, + root_item); +if (ret <0 ) { +btrfs_abort_transaction (trans, ret); +return ret; + } + +btrfs_commit_transaction (trans, gfs_info->tree_root); +printf ("Cleared received information for subvol: %llu\n" , + root->root_key.objectid); + } + } }
Signature · 1 line
2.17.1
PATCH 8/8 btrfs-progs: tests: Add test for received information removal
In reply to Nikolay BorisovThe image contains a subvolume which as been received i.e has relevant received fields populated and subsequently has been switched to RW mode.
--- .../050-subvol-recv-clear/test.raw.xz | Bin 0 -> 493524 bytes 1 file changed, 0 insertions(+), 0 deletions(-) create mode 100644 tests/fsck-tests/050-subvol-recv-clear/test.raw.xz
tests/fsck-tests/050-subvol-recv-clear/test.raw.xz new file binary +0 -0
--
2.17.1