Skip to contentSkip to conversation

Implement progs support for removing received uuid on RW vols

PATCH In review Nikolay Borisov 5 participants 20 messages Sep 14, 2021 – Sep 21, 2021 Btrfs file system

lore
Share & tools
lore
#0 lore raw

v2 cover Implement progs support for removing received uuid on RW vols

Here's V2 which takes into account Qu's suggestions, namely:

- Add a helper which contains the common code to clear receive-related data
- Now there is a single patch which impements the check/clear for both orig and lowmem modes
- Added Reviewed-by from Qu.

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: Implement helper to remove received information of RW
subvol
btrfs-progs: check: Implement removing received data for RW subvols
btrfs-progs: tests: Add test for received information removal

 check/main.c                                  |  21 +++-
 check/mode-common.c                           |  40 ++++++++
 check/mode-common.h                           |   1 +
 check/mode-lowmem.c                           |  11 ++-
 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
 12 files changed, 202 insertions(+), 50 deletions(-)
 create mode 100644 tests/fsck-tests/050-subvol-recv-clear/test.raw.xz

--
2.17.1

#1 lore raw

PATCH v2 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
index 3cca60323e3d..f53436a7f38b 100644
@@ -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
index 21115a4d2d09..51a7b5d9ff5d 100644
@@ -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
#2 lore raw

Re: [PATCH v2 1/8] btrfs-progs: Add btrfs_is_empty_uuid

Quoted 31 lines · Nikolay Borisov

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
index 3cca60323e3d..f53436a7f38b 100644
@@ -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 +1 -0
index 21115a4d2d09..51a7b5d9ff5d 100644
@@ -109,3 +109,14 @@ int btrfs_lookup_uuid_received_subvol_item(int fd, const u8 *uuid,
  					  BTRFS_UUID_KEY_RECEIVED_SUBVOL,
  					  subvol_id);
  }
+

kernel-shared/uuid-tree.c int btrfs_lookup_uuid_received_subvol_item(int fd, const u8 *uuid, · line 122

Quoted 10 lines
kernel-shared/uuid-tree.c +10 -0
+int btrfs_is_empty_uuid(u8 *uuid)
+{
+	int i;
+
+	for (i = 0; i < BTRFS_UUID_SIZE; i++) {
+		if (uuid[i])
+			return 0;
+	}
+	return 1;
+}

You could use uuid_is_null(). No?

#3 lore raw

Re: [PATCH v2 1/8] btrfs-progs: Add btrfs_is_empty_uuid

Quoted 13 lines · Anand Jain
Quoted 12 lines · Nikolay Borisov
kernel-shared/uuid-tree.c +6 -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++) {
Quoted 8 lines

kernel-shared/uuid-tree.c int btrfs_lookup_uuid_received_subvol_item(int fd, const u8 *uuid, · line 122

Quoted 6 lines
kernel-shared/uuid-tree.c +5 -0
+		if (uuid[i])
+			return 0;
+	}
+	return 1;
+}

You could use uuid_is_null(). No?

Yeah, no need to duplicate that.

#4 lore raw

PATCH v2 2/8 btrfs-progs: Remove root argument from btrfs_fixup_low_keys

In reply to Nikolay Borisov

It'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
index a88518159830..6369bdd90656 100644
@@ -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
index 518718de04dd..02eb975338e5 100644
@@ -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_root
 		btrfs_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
index f53436a7f38b..a17bf50e29b4 100644
@@ -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,

--
2.17.1

#5 lore raw

PATCH v2 3/8 btrfs-progs: Remove fs_info argument from leaf_data_end

In reply to Nikolay Borisov

The 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
index 02eb975338e5..77766c2a7931 100644
@@ -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_root
 		     btrfs_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_root
 
 	if (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,

--
2.17.1

#6 lore raw

PATCH v2 4/8 btrfs-progs: Remove root argument from btrfs_truncate_item

In reply to 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.

---
 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
index 77766c2a7931..78f94c6cd42f 100644
@@ -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
index a17bf50e29b4..91a85796a678 100644
@@ -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
index 7dc606c132b5..590b79a929d3 100644
@@ -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
index 056a9256b9a4..a8e0c1e60e2e 100644
@@ -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
index 7e16b747e36c..c910e27e5a5d 100644
@@ -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
index 4e009746de0e..67173eb141d8 100644
@@ -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);

--
2.17.1

#7 lore raw

PATCH v2 5/8 btrfs-progs: Add btrfs_uuid_tree_remove

In reply to Nikolay Borisov

It 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
index 91a85796a678..158281a9fd67 100644
@@ -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
Reviewed-by on v2 5/8
#8 lore raw

Re: [PATCH v2 5/8] btrfs-progs: Add btrfs_uuid_tree_remove

Quoted 2 lines · Nikolay Borisov

It will be used to clear received data on RW snapshots that were received.

It would be more helpful to mention it's a backport of kernel function.

Quoted 2 lines

Thanks,
Qu

Quoted 110 lines
---
  kernel-shared/ctree.h     |  3 ++
  kernel-shared/uuid-tree.c | 82 +++++++++++++++++++++++++++++++++++++++
  2 files changed, 85 insertions(+)
kernel-shared/ctree.h +3 -0
index 91a85796a678..158281a9fd67 100644
@@ -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
index 51a7b5d9ff5d..0f0fbf667dda 100644
@@ -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;
+}
#9 lore raw

PATCH v2 6/8 btrfs-progs: Implement helper to remove received information of RW subvol

In reply to Nikolay Borisov
---
 check/mode-common.c | 40 ++++++++++++++++++++++++++++++++++++++++
 check/mode-common.h |  1 +
 2 files changed, 41 insertions(+)
check/mode-common.c +40 -0
index 0059672c6402..7a5313280f3f 100644
@@ -1301,3 +1301,43 @@ int repair_dev_item_bytes_used(struct btrfs_fs_info *fs_info,
 	btrfs_abort_transaction(trans, ret);
 	return ret;
 }
+
+int repair_received_subvol(struct btrfs_root *root)
+{
+	struct btrfs_root_item *root_item = &root->root_item;
+	struct btrfs_trans_handle *trans;
+	int ret;
+
+	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;
+	}
+
+	ret = btrfs_commit_transaction(trans, gfs_info->tree_root);
+	if (!ret)
+		printf("Cleared received information for subvol: %llu\n",
+				root->root_key.objectid);
+	return ret;
+}
check/mode-common.h +1 -0
index cdfb10d58cde..f1ec5dca0199 100644
@@ -130,6 +130,7 @@ int reset_imode(struct btrfs_trans_handle *trans, struct btrfs_root *root,
 		struct btrfs_path *path, u64 ino, u32 mode);
 int repair_imode_common(struct btrfs_root *root, struct btrfs_path *path);
 int check_repair_free_space_inode(struct btrfs_path *path);
+int repair_received_subvol(struct btrfs_root *root);
 
 /*
  * Check if the inode mode @imode is valid
Signature · 1 line
2.17.1
Reviewed-by on v2 6/8
#10 lore raw

Re: [PATCH v2 6/8] btrfs-progs: Implement helper to remove received information of RW subvol

Quoted 1 line · Nikolay Borisov

Thanks,
Qu

Quoted 66 lines
---
  check/mode-common.c | 40 ++++++++++++++++++++++++++++++++++++++++
  check/mode-common.h |  1 +
  2 files changed, 41 insertions(+)
check/mode-common.c +40 -0
index 0059672c6402..7a5313280f3f 100644
@@ -1301,3 +1301,43 @@ int repair_dev_item_bytes_used(struct btrfs_fs_info *fs_info,
  	btrfs_abort_transaction(trans, ret);
  	return ret;
  }
+
+int repair_received_subvol(struct btrfs_root *root)
+{
+	struct btrfs_root_item *root_item = &root->root_item;
+	struct btrfs_trans_handle *trans;
+	int ret;
+
+	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;
+	}
+
+	ret = btrfs_commit_transaction(trans, gfs_info->tree_root);
+	if (!ret)
+		printf("Cleared received information for subvol: %llu\n",
+				root->root_key.objectid);
+	return ret;
+}
check/mode-common.h +1 -0
index cdfb10d58cde..f1ec5dca0199 100644
@@ -130,6 +130,7 @@ int reset_imode(struct btrfs_trans_handle *trans, struct btrfs_root *root,
  		struct btrfs_path *path, u64 ino, u32 mode);
  int repair_imode_common(struct btrfs_root *root, struct btrfs_path *path);
  int check_repair_free_space_inode(struct btrfs_path *path);
+int repair_received_subvol(struct btrfs_root *root);
 
  /*
   * Check if the inode mode @imode is valid
#11 lore raw

PATCH v2 7/8 btrfs-progs: check: Implement removing received data for RW subvols

In reply to Nikolay Borisov

Making 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        | 16 +++++++++++++++-
 check/mode-lowmem.c | 11 ++++++++++-
 2 files changed, 25 insertions(+), 2 deletions(-)
check/main.c +15 -1
index 6369bdd90656..9d3822a2ebae 100644
@@ -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,19 @@ 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) {
+			ret = repair_received_subvol(root);
+			if (ret)
+				return ret;
+			rw_received_err = false;
+		}
+	}
+
 	while (1) {
 		ctx.item_count++;
 		wret = walk_down_tree(root, &path, wc, &level, &nrefs);
@@ -3722,7 +3736,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;
 }
check/mode-lowmem.c +10 -1
index 323e66bc4cb1..d8f783bea424 100644
@@ -5197,8 +5197,17 @@ 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))) {
+			error("Subvolume id: %llu is RW and has a received uuid",
+				  root->root_key.objectid);
+			if (repair)
+				ret = repair_received_subvol(root);
+			if (ret < 0)
+				return FATAL_ERROR;
+		}
+	}
 
 	level = btrfs_header_level(root->node);
 	btrfs_init_path(&path);
Signature · 1 line
2.17.1
#12 lore raw

Re: [PATCH v2 7/8] btrfs-progs: check: Implement removing received data for RW subvols

Quoted 67 lines · Nikolay Borisov

Making 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        | 16 +++++++++++++++-
  check/mode-lowmem.c | 11 ++++++++++-
  2 files changed, 25 insertions(+), 2 deletions(-)
check/main.c +15 -1
index 6369bdd90656..9d3822a2ebae 100644
@@ -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,19 @@ 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) {
+			ret = repair_received_subvol(root);
+			if (ret)
+				return ret;
+			rw_received_err = false;
+		}
+	}
+
  	while (1) {
  		ctx.item_count++;
  		wret = walk_down_tree(root, &path, wc, &level, &nrefs);
@@ -3722,7 +3736,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;
  }
check/mode-lowmem.c +0 -1
index 323e66bc4cb1..d8f783bea424 100644
@@ -5197,8 +5197,17 @@ static int check_btrfs_root(struct btrfs_root *root, int check_all)
  		ret = check_fs_first_inode(root);
  		if (ret < 0)
  			return FATAL_ERROR;
-	}

check/mode-lowmem.c static int check_btrfs_root(struct btrfs_root *root, int check_all) · line 5209

Quoted 10 lines
check/mode-lowmem.c +9 -0
 
+		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);
+			if (repair)
+				ret = repair_received_subvol(root);
+			if (ret < 0)
+				return FATAL_ERROR;
+		}

Not sure if we need to error out completely.

I guess continue the check would be better?

Despite that, everything looks good to me.

Thanks,
Qu

Quoted 5 lines
check/mode-lowmem.c +1 -0
+	}
 
  	level = btrfs_header_level(root->node);
  	btrfs_init_path(&path);
#13 lore raw

Re: [PATCH v2 7/8] btrfs-progs: check: Implement removing received data for RW subvols

Quoted 85 lines · Qu Wenruo
Quoted 71 lines · Nikolay Borisov

Making 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        | 16 +++++++++++++++-
  check/mode-lowmem.c | 11 ++++++++++-

  2 files changed, 25 insertions(+), 2 deletions(-)
check/main.c +15 -1
index 6369bdd90656..9d3822a2ebae 100644
@@ -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,19 @@ 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) {
+            ret = repair_received_subvol(root);
+            if (ret)
+                return ret;
+            rw_received_err = false;
+        }
+    }
+
       while (1) {
           ctx.item_count++;
           wret = walk_down_tree(root, &path, wc, &level, &nrefs);
@@ -3722,7 +3736,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;
   }
check/mode-lowmem.c +1 -1
index 323e66bc4cb1..d8f783bea424 100644
@@ -5197,8 +5197,17 @@ 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) ||

Quoted 8 lines

+                    btrfs_is_empty_uuid(root_item->received_uuid))) { +            error("Subvolume id: %llu is RW and has a received uuid", +                  root->root_key.objectid);
+            if (repair)
+                ret = repair_received_subvol(root);
+            if (ret < 0)
+                return FATAL_ERROR;
+        }

Not sure if we need to error out completely.

Quoted 1 line

I guess continue the check would be better?

There's that, but we still need to find a way to signify there is an error. So for lowmem mode the possibility is to introduce yet another bit (from 26 to 27) to signify this particular problem. Ok, will fix it in the next iteration but I'm still waiting for more feedback, especially from David.

Quoted 11 lines

Despite that, everything looks good to me.

Thanks,
Qu

Quoted 5 lines

+    }

      level = btrfs_header_level(root->node);
      btrfs_init_path(&path);

#14 lore raw
In reply to Nikolay Borisov
Quoted 19 lines · Nikolay Borisov

Here's V2 which takes into account Qu's suggestions, namely:

- Add a helper which contains the common code to clear receive-related data
- Now there is a single patch which impements the check/clear for both orig and lowmem modes
- Added Reviewed-by from Qu.

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: Implement helper to remove received information of RW
subvol
btrfs-progs: check: Implement removing received data for RW subvols
btrfs-progs: tests: Add test for received information removal

Quoted 12 lines
  check/main.c                                  |  21 +++-
  check/mode-common.c                           |  40 ++++++++
  check/mode-common.h                           |   1 +
  check/mode-lowmem.c                           |  11 ++-
  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

The images looks a little large than expected, so that the mailing list is rejected the armored patch.

Can we use btrfs-image? As there is no need for special layout which can't be dumped by btrfs-image.
Thus using btrfs-image -c9 would save quite some space.

Thanks,
Qu

Quoted 6 lines
  12 files changed, 202 insertions(+), 50 deletions(-)

create mode 100644 tests/fsck-tests/050-subvol-recv-clear/test.raw.xz

--
2.17.1

#15 lore raw
In reply to Nikolay Borisov
Quoted 19 lines · Nikolay Borisov

Here's V2 which takes into account Qu's suggestions, namely:

- Add a helper which contains the common code to clear receive-related data
- Now there is a single patch which impements the check/clear for both orig and lowmem modes
- Added Reviewed-by from Qu.

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: Implement helper to remove received information of RW
subvol
btrfs-progs: check: Implement removing received data for RW subvols
btrfs-progs: tests: Add test for received information removal

Quoted 12 lines
  check/main.c                                  |  21 +++-
  check/mode-common.c                           |  40 ++++++++
  check/mode-common.h                           |   1 +
  check/mode-lowmem.c                           |  11 ++-
  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

The image looks a little large than expected, so that the mailing list is rejected the armored patch.

Can we use btrfs-image? As there is no need for special layout which can't be dumped by btrfs-image.
Thus using btrfs-image -c9 would save quite some space.

Thanks,
Qu

Quoted 6 lines
  12 files changed, 202 insertions(+), 50 deletions(-)

create mode 100644 tests/fsck-tests/050-subvol-recv-clear/test.raw.xz

--
2.17.1

#16 lore raw
Quoted 37 lines · Qu Wenruo
Quoted 25 lines · Nikolay Borisov

Here's V2 which takes into account Qu's suggestions, namely:

- Add a helper which contains the common code to clear receive-related data
- Now there is a single patch which impements the check/clear for both orig and
lowmem modes
- Added Reviewed-by from Qu.

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: Implement helper to remove received information of RW subvol
   btrfs-progs: check: Implement removing received data for RW subvols
   btrfs-progs: tests: Add test for received information removal

  check/main.c                                  |  21 +++-

  check/mode-common.c                           |  40 ++++++++
  check/mode-common.h                           |   1 +
  check/mode-lowmem.c                           |  11 ++-
Quoted 8 lines

  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

Quoted 6 lines

The image looks a little large than expected, so that the mailing list is rejected the armored patch.

Can we use btrfs-image? As there is no need for special layout which can't be dumped by btrfs-image.
Thus using btrfs-image -c9 would save quite some space.

Well I did use a raw image, compressed with xz. But sure, I'll look into this but for the time being will wait to gather more feedback.

Quoted 11 lines

Thanks,
Qu

Quoted 6 lines
  12 files changed, 202 insertions(+), 50 deletions(-)

  create mode 100644 tests/fsck-tests/050-subvol-recv-clear/test.raw.xz

Signature · 1 line
2.17.1
#17 lore raw

PATCH v2 8/8 btrfs-progs: tests: Add test for received information removal

In reply to Nikolay Borisov

The 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
new file mode 100644
index 0000000000000000000000000000000000000000..074a53b49cdd473af4f2a97cbf7e3f0d3c6518aa
GIT binary patch
Signature · 1 line
2.17.1
#18 lore raw
In reply to Nikolay Borisov
Quoted 8 lines · Nikolay Borisov

Here's V2 which takes into account Qu's suggestions, namely:

- Add a helper which contains the common code to clear receive-related data
- Now there is a single patch which impements the check/clear for both orig and lowmem modes
- Added Reviewed-by from Qu.

Quoted 10 lines

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: Implement helper to remove received information of RW
subvol
btrfs-progs: check: Implement removing received data for RW subvols
btrfs-progs: tests: Add test for received information removal

Patches 2-5 added to devel as they're preparatory and otherwise OK as independent cleanups.

Regarding the rw and received_uuid, it's choosing between these options:

1) ro->rw resets received_uuid unconditionally

Pros:
- safe as it does not lead to unexpected results after incremental send

Cons:
- unconditional, so it's too easy to break the incremental send usecase, which is the main usecase, if that' for backups breaking the continuity is IMNSHO serious usability problem -- and main reason why I'm personally looking for other options

Issuing a warning when the ro status is changed by btrfs-progs is only partially fixing that as the raw ioctl or it's wrapper in libbtrfsutil will happily destroy the received_uuid. There's no log or other information that would make it possible to restore it.

Note that received_uuid can be set to any value using the BTRFS_IOC_SET_RECEIVED_SUBVOL ioctl, as long as the subvolume is writable.

2) don't allow ro->rw if received_uuid is set, it must be cleared first

As mentioned above, the received_uuid can be changed or reset (setting all zeros), but there's still the condition that the subvolume must be writable.

After 'receive' the subvolume is snapshotted, updated from stream, set received_uuid and set rw->ro.

Reusing the SET_RECEIVED_SUBVOL can't be used as-is, the subvol would have to be rw first. Which is a chicken-egg problem.

The safe steps would be:

- (after receive, subvolume is RO)
- set it to RW
- clear received_uuid
- either keep it RW or set RO again

This would be the single "clear received_uuid manually" and it would be up to the user to knowingly destroy the continuity of the incremental send.

The fix here is that the above steps would have to be atomic from user perspective, inside SET_RECEIVED_SUBVOL, eg. based on flag. And we'd have to add a btrfs-progs command somewhere.

#19 lore raw
Quoted 36 lines · David Sterba
Quoted 8 lines · Nikolay Borisov

Here's V2 which takes into account Qu's suggestions, namely:

- Add a helper which contains the common code to clear receive-related data
- Now there is a single patch which impements the check/clear for both orig and lowmem modes
- Added Reviewed-by from Qu.

Quoted 10 lines

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: Implement helper to remove received information of RW
subvol
btrfs-progs: check: Implement removing received data for RW subvols
btrfs-progs: tests: Add test for received information removal

Patches 2-5 added to devel as they're preparatory and otherwise OK as independent cleanups.

Regarding the rw and received_uuid, it's choosing between these options:

1) ro->rw resets received_uuid unconditionally

Pros:
- safe as it does not lead to unexpected results after incremental send

Cons:
- unconditional, so it's too easy to break the incremental send usecase, which is the main usecase, if that' for backups breaking the continuity is IMNSHO serious usability problem -- and main reason why I'm personally looking for other options

Quoted 8 lines

Issuing a warning when the ro status is changed by btrfs-progs is only partially fixing that as the raw ioctl or it's wrapper in libbtrfsutil will happily destroy the received_uuid. There's no log or other information that would make it possible to restore it.

Note that received_uuid can be set to any value using the BTRFS_IOC_SET_RECEIVED_SUBVOL ioctl, as long as the subvolume is writable.

How about...

Add a --force option.

ro->rw with received_uuid non-zero fails without --force, but displays a message something like:

"Subvolume is a received subvolume (received_uuid a0fd481e-ac7f-f14f-8bec-f09e3e096344). Setting the subvolume read-write would remove the received_uuid and prevent the subvolume being referenced in future btrfs receive operations. To avoid this, take a rw snapshot of the subvolume instead of setting it rw. If you are happy to clear the received_uuid, specify the --force option".

Don't bother to explain about the BTRFS_IOC_SET_RECEIVED_SUBVOL ioctl but at least the received_uuid has been displayed if the user wants to record it. Maybe even log it in a kernel message - I presume this will be a fairly rare action.

Quoted 28 lines

2) don't allow ro->rw if received_uuid is set, it must be cleared first

As mentioned above, the received_uuid can be changed or reset (setting all zeros), but there's still the condition that the subvolume must be writable.

After 'receive' the subvolume is snapshotted, updated from stream, set received_uuid and set rw->ro.

Reusing the SET_RECEIVED_SUBVOL can't be used as-is, the subvol would have to be rw first. Which is a chicken-egg problem.

The safe steps would be:

- (after receive, subvolume is RO)
- set it to RW
- clear received_uuid
- either keep it RW or set RO again

This would be the single "clear received_uuid manually" and it would be up to the user to knowingly destroy the continuity of the incremental send.

The fix here is that the above steps would have to be atomic from user perspective, inside SET_RECEIVED_SUBVOL, eg. based on flag. And we'd have to add a btrfs-progs command somewhere.