linux-btrfs.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH for-4.20 0/3] Fix incorrectly created uuid tree
@ 2018-12-27  7:13 Qu Wenruo
  2018-12-27  7:13 ` [PATCH 1/3] btrfs-progs: uuid: Port kernel btrfs_uuid_tree_lookup() Qu Wenruo
                   ` (2 more replies)
  0 siblings, 3 replies; 16+ messages in thread
From: Qu Wenruo @ 2018-12-27  7:13 UTC (permalink / raw)
  To: linux-btrfs

This patchset can be fetched from github:
https://github.com/adam900710/btrfs-progs/tree/uuid_tree_support
Which is based on v4.19.1 tag.

Commit 2a496a5b8b74 ("btrfs-progs: mkfs: precreate the uuid tree")
creates uuid tree at mkfs time.

However it doesn't populate uuid tree correctly nor just create an empty
root.
It uses create_tree(), which just copies the content of fs root,
containing meaningless INODE_ITEM:

v4.15 mkfs (no uuid tree creation) + kernel mount:
  uuid tree key (UUID_TREE ROOT_ITEM 0)
  leaf 30572544 items 1 free space 16250 generation 7 owner UUID_TREE
  leaf 30572544 flags 0x1(WRITTEN) backref revision 1
  fs uuid 33ecddef-fc86-481a-93ce-846b01c11376
  chunk uuid 9e58f646-b0da-43ca-9c7d-8bbe3e120246
	item 0 key (0x92457c59d31491be UUID_KEY_SUBVOL 0xef908b5e79aa76a1) itemoff 16275 itemsize 8
		subvol_id 5

v4.19.1 mkfs (incorrect one), no kernel mount:
  uuid tree key (UUID_TREE ROOT_ITEM 0)
  leaf 30507008 items 2 free space 16061 generation 4 owner UUID_TREE
  leaf 30507008 flags 0x1(WRITTEN) backref revision 1
  fs uuid 162f5333-9b5d-4217-877c-ddaeaa79398e
  chunk uuid 7bc2c5c6-a6d2-4eec-a513-142b549c6541
	item 0 key (256 INODE_ITEM 0) itemoff 16123 itemsize 160
		generation 3 transid 0 size 0 nbytes 16384
		block group 0 mode 40755 links 1 uid 0 gid 0 rdev 0
		sequence 0 flags 0x0(none)
	item 1 key (256 INODE_REF 256) itemoff 16111 itemsize 12
		index 0 namelen 2 name: ..

This patchset will fix it by populuating uuid tree properly, as kernel
tree checker now doesn't accept empty uuid tree.

w/ this patchset, no kernel mount:
  uuid tree key (UUID_TREE ROOT_ITEM 0)
  leaf 30507008 items 1 free space 16250 generation 4 owner UUID_TREE
  leaf 30507008 flags 0x1(WRITTEN) backref revision 1
  fs uuid ae53079e-dbbc-409b-a565-5326c7b27731
  chunk uuid b5fb1bea-f20d-4af1-80f8-6ca3f0038d67
	item 0 key (0x334ba6b032d89c07 UUID_KEY_SUBVOL 0x86cde09cb78bcca0) itemoff 16275 itemsize 8
		subvol_id 5

Qu Wenruo (3):
  btrfs-progs: uuid: Port kernel btrfs_uuid_tree_lookup()
  btrfs-progs: uuid: Port btrfs_uuid_tree_add() function
  btrfs-progs: Create uuid tree with proper contents

 ctree.h       |   7 ++-
 disk-io.c     |   4 ++
 mkfs/common.c | 103 ++++++++++++++++++++++++++++++++++++++
 mkfs/common.h |   3 ++
 mkfs/main.c   |  36 +------------
 uuid-tree.c   | 136 +++++++++++++++++++++++++++++++++++++++++++++++++-
 6 files changed, 252 insertions(+), 37 deletions(-)

-- 
2.20.1


^ permalink raw reply	[flat|nested] 16+ messages in thread

* [PATCH 1/3] btrfs-progs: uuid: Port kernel btrfs_uuid_tree_lookup()
  2018-12-27  7:13 [PATCH for-4.20 0/3] Fix incorrectly created uuid tree Qu Wenruo
@ 2018-12-27  7:13 ` Qu Wenruo
  2018-12-27  7:37   ` Su Yue
  2018-12-27  7:13 ` [PATCH 2/3] btrfs-progs: uuid: Port btrfs_uuid_tree_add() function Qu Wenruo
  2018-12-27  7:13 ` [PATCH 3/3] btrfs-progs: Create uuid tree with proper contents Qu Wenruo
  2 siblings, 1 reply; 16+ messages in thread
From: Qu Wenruo @ 2018-12-27  7:13 UTC (permalink / raw)
  To: linux-btrfs

Although we have btrfs_uuid_tree_lookup_any(), it's an online function
utilizing tree search ioctl, not an offline search function.

This patch will port kernel btrfs_uuid_tree_lookup() into btrfs-progs
for later proper uuid tree initialization.

Signed-off-by: Qu Wenruo <wqu@suse.com>
---
 uuid-tree.c | 71 +++++++++++++++++++++++++++++++++++++++++++++++++++--
 1 file changed, 69 insertions(+), 2 deletions(-)

diff --git a/uuid-tree.c b/uuid-tree.c
index 320eb67e1404..b9190103c355 100644
--- a/uuid-tree.c
+++ b/uuid-tree.c
@@ -23,6 +23,7 @@
 #include "transaction.h"
 #include "disk-io.h"
 #include "print-tree.h"
+#include "utils.h"
 
 
 static void btrfs_uuid_to_key(const u8 *uuid, u64 *key_objectid,
@@ -32,8 +33,11 @@ static void btrfs_uuid_to_key(const u8 *uuid, u64 *key_objectid,
 	*key_offset = get_unaligned_le64(uuid + sizeof(u64));
 }
 
-
-/* return -ENOENT for !found, < 0 for errors, or 0 if an item was found */
+/*
+ * Search uuid tree of a *MOUNTED* btrfs (online)
+ *
+ * return -ENOENT for !found, < 0 for errors, or 0 if an item was found
+ */
 static int btrfs_uuid_tree_lookup_any(int fd, const u8 *uuid, u8 type,
 				      u64 *subid)
 {
@@ -103,3 +107,66 @@ int btrfs_lookup_uuid_received_subvol_item(int fd, const u8 *uuid,
 					  BTRFS_UUID_KEY_RECEIVED_SUBVOL,
 					  subvol_id);
 }
+
+/*
+ * Search uuid tree of an *UNMOUNTED* btrfs (offline)
+ */
+static int btrfs_uuid_tree_lookup(struct btrfs_root *uuid_root, u8 *uuid,
+				  u8 type, u64 subid)
+{
+	int ret;
+	struct btrfs_path *path = NULL;
+	struct extent_buffer *eb;
+	int slot;
+	u32 item_size;
+	unsigned long offset;
+	struct btrfs_key key;
+
+	if (!uuid_root) {
+		ret = -ENOENT;
+		goto out;
+	}
+
+	path = btrfs_alloc_path();
+	if (!path) {
+		ret = -ENOMEM;
+		goto out;
+	}
+
+	btrfs_uuid_to_key(uuid, &key.objectid, &key.offset);
+	key.type = type;
+	ret = btrfs_search_slot(NULL, uuid_root, &key, path, 0, 0);
+	if (ret < 0) {
+		goto out;
+	} else if (ret > 0) {
+		ret = -ENOENT;
+		goto out;
+	}
+
+	eb = path->nodes[0];
+	slot = path->slots[0];
+	item_size = btrfs_item_size_nr(eb, slot);
+	offset = btrfs_item_ptr_offset(eb, slot);
+	ret = -ENOENT;
+
+	if (!IS_ALIGNED(item_size, sizeof(u64))) {
+		warning("uuid item with illegal size %lu!",
+			(unsigned long)item_size);
+		goto out;
+	}
+	while (item_size) {
+		__le64 data;
+
+		read_extent_buffer(eb, &data, offset, sizeof(data));
+		if (le64_to_cpu(data) == subid) {
+			ret = 0;
+			break;
+		}
+		offset += sizeof(data);
+		item_size -= sizeof(data);
+	}
+
+out:
+	btrfs_free_path(path);
+	return ret;
+}
-- 
2.20.1


^ permalink raw reply related	[flat|nested] 16+ messages in thread

* [PATCH 2/3] btrfs-progs: uuid: Port btrfs_uuid_tree_add() function
  2018-12-27  7:13 [PATCH for-4.20 0/3] Fix incorrectly created uuid tree Qu Wenruo
  2018-12-27  7:13 ` [PATCH 1/3] btrfs-progs: uuid: Port kernel btrfs_uuid_tree_lookup() Qu Wenruo
@ 2018-12-27  7:13 ` Qu Wenruo
  2018-12-27  7:54   ` Su Yue
  2018-12-27  7:13 ` [PATCH 3/3] btrfs-progs: Create uuid tree with proper contents Qu Wenruo
  2 siblings, 1 reply; 16+ messages in thread
From: Qu Wenruo @ 2018-12-27  7:13 UTC (permalink / raw)
  To: linux-btrfs

This function provide the offline ability to add new uuid tree entry.
This provides the basis for later proper uuid tree initialization.

Signed-off-by: Qu Wenruo <wqu@suse.com>
---
 ctree.h     |  7 +++++-
 uuid-tree.c | 65 +++++++++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 71 insertions(+), 1 deletion(-)

diff --git a/ctree.h b/ctree.h
index f9c49d6041c1..7b9e3f1cef6e 100644
--- a/ctree.h
+++ b/ctree.h
@@ -1101,6 +1101,7 @@ struct btrfs_fs_info {
 	struct btrfs_root *csum_root;
 	struct btrfs_root *quota_root;
 	struct btrfs_root *free_space_root;
+	struct btrfs_root *uuid_root;
 
 	struct rb_root fs_root_tree;
 
@@ -2774,11 +2775,15 @@ int btrfs_csum_truncate(struct btrfs_trans_handle *trans,
 			struct btrfs_root *root, struct btrfs_path *path,
 			u64 isize);
 
-/* uuid-tree.c */
+/* uuid-tree.c, mounted fs (online) interface */
 int btrfs_lookup_uuid_subvol_item(int fd, const u8 *uuid, u64 *subvol_id);
 int btrfs_lookup_uuid_received_subvol_item(int fd, const u8 *uuid,
 					   u64 *subvol_id);
 
+/* uuid-tree.c, unmounted fs (offline) interface */
+int btrfs_uuid_tree_add(struct btrfs_trans_handle *trans, u8 *uuid, u8 type,
+			u64 subid_cpu);
+
 static inline int is_fstree(u64 rootid)
 {
 	if (rootid == BTRFS_FS_TREE_OBJECTID ||
diff --git a/uuid-tree.c b/uuid-tree.c
index b9190103c355..3f547198f016 100644
--- a/uuid-tree.c
+++ b/uuid-tree.c
@@ -170,3 +170,68 @@ out:
 	btrfs_free_path(path);
 	return ret;
 }
+
+int btrfs_uuid_tree_add(struct btrfs_trans_handle *trans, u8 *uuid, u8 type,
+			u64 subid_cpu)
+{
+	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;
+	__le64 subid_le;
+
+	if (!uuid_root) {
+		warning("%s: uuid root is not initialized", __func__);
+		return -EINVAL;
+	}
+
+	ret = btrfs_uuid_tree_lookup(uuid_root, uuid, type, subid_cpu);
+	if (ret != -ENOENT)
+		return ret;
+
+	key.type = type;
+	btrfs_uuid_to_key(uuid, &key.objectid, &key.offset);
+
+	path = btrfs_alloc_path();
+	if (!path) {
+		ret = -ENOMEM;
+		goto out;
+	}
+
+	ret = btrfs_insert_empty_item(trans, uuid_root, path, &key,
+				      sizeof(subid_le));
+	if (ret >= 0) {
+		/* Add an item for the type for the first time */
+		eb = path->nodes[0];
+		slot = path->slots[0];
+		offset = btrfs_item_ptr_offset(eb, slot);
+	} else if (ret == -EEXIST) {
+		/*
+		 * An item with that type already exists.
+		 * Extend the item and store the new subid at the end.
+		 */
+		btrfs_extend_item(uuid_root, path, sizeof(subid_le));
+		eb = path->nodes[0];
+		slot = path->slots[0];
+		offset = btrfs_item_ptr_offset(eb, slot);
+		offset += btrfs_item_size_nr(eb, slot) - sizeof(subid_le);
+	} else if (ret < 0) {
+		warning("insert uuid item failed %d (0x%016llx, 0x%016llx) type %u!",
+			ret, (unsigned long long)key.objectid,
+			(unsigned long long)key.offset, type);
+		goto out;
+	}
+
+	ret = 0;
+	subid_le = cpu_to_le64(subid_cpu);
+	write_extent_buffer(eb, &subid_le, offset, sizeof(subid_le));
+	btrfs_mark_buffer_dirty(eb);
+
+out:
+	btrfs_free_path(path);
+	return ret;
+}
-- 
2.20.1


^ permalink raw reply related	[flat|nested] 16+ messages in thread

* [PATCH 3/3] btrfs-progs: Create uuid tree with proper contents
  2018-12-27  7:13 [PATCH for-4.20 0/3] Fix incorrectly created uuid tree Qu Wenruo
  2018-12-27  7:13 ` [PATCH 1/3] btrfs-progs: uuid: Port kernel btrfs_uuid_tree_lookup() Qu Wenruo
  2018-12-27  7:13 ` [PATCH 2/3] btrfs-progs: uuid: Port btrfs_uuid_tree_add() function Qu Wenruo
@ 2018-12-27  7:13 ` Qu Wenruo
  2018-12-27 11:28   ` Su Yue
  2019-01-02  9:13   ` Nikolay Borisov
  2 siblings, 2 replies; 16+ messages in thread
From: Qu Wenruo @ 2018-12-27  7:13 UTC (permalink / raw)
  To: linux-btrfs

Commit 2a496a5b8b74 ("btrfs-progs: mkfs: precreate the uuid tree")
creates uuid tree at mkfs time.

However it doesn't populate uuid tree correctly nor just create an empty
root.
It uses create_tree(), which just copies the content of fs root,
containing meaningless INODE_ITEM:

v4.15 mkfs (no uuid tree creation) + kernel mount:
  uuid tree key (UUID_TREE ROOT_ITEM 0)
  leaf 30572544 items 1 free space 16250 generation 7 owner UUID_TREE
  leaf 30572544 flags 0x1(WRITTEN) backref revision 1
  fs uuid 33ecddef-fc86-481a-93ce-846b01c11376
  chunk uuid 9e58f646-b0da-43ca-9c7d-8bbe3e120246
	item 0 key (0x92457c59d31491be UUID_KEY_SUBVOL 0xef908b5e79aa76a1) itemoff 16275 itemsize 8
		subvol_id 5

v4.19.1 mkfs (incorrect one), no kernel mount:
  uuid tree key (UUID_TREE ROOT_ITEM 0)
  leaf 30507008 items 2 free space 16061 generation 4 owner UUID_TREE
  leaf 30507008 flags 0x1(WRITTEN) backref revision 1
  fs uuid 162f5333-9b5d-4217-877c-ddaeaa79398e
  chunk uuid 7bc2c5c6-a6d2-4eec-a513-142b549c6541
	item 0 key (256 INODE_ITEM 0) itemoff 16123 itemsize 160
		generation 3 transid 0 size 0 nbytes 16384
		block group 0 mode 40755 links 1 uid 0 gid 0 rdev 0
		sequence 0 flags 0x0(none)
	item 1 key (256 INODE_REF 256) itemoff 16111 itemsize 12
		index 0 namelen 2 name: ..

This patchset will fix it by populuating uuid tree properly:
(NOTE: due to tree-checker, kernel doesn't accept empty uuid tree, so we
 can only fix it by populating uuid tree correctly)

w/ this patchset, no kernel mount:
  uuid tree key (UUID_TREE ROOT_ITEM 0)
  leaf 30507008 items 1 free space 16250 generation 4 owner UUID_TREE
  leaf 30507008 flags 0x1(WRITTEN) backref revision 1
  fs uuid ae53079e-dbbc-409b-a565-5326c7b27731
  chunk uuid b5fb1bea-f20d-4af1-80f8-6ca3f0038d67
	item 0 key (0x334ba6b032d89c07 UUID_KEY_SUBVOL 0x86cde09cb78bcca0) itemoff 16275 itemsize 8
		subvol_id 5

For kernel, except tree-checker needs an non-empty uuid tree, both all
above behavior won't cause problem, but it's always better to keep a
good standardized behavior.

Furthermore, to avoid such problem from happening again, rename the
function create_tree() to create_empty_tree() and create_inode_tree(),
without an @root parameter to avoid such problem.

Fixes: 2a496a5b8b74 ("btrfs-progs: mkfs: precreate the uuid tree")
Signed-off-by: Qu Wenruo <wqu@suse.com>
---
 disk-io.c     |   4 ++
 mkfs/common.c | 103 ++++++++++++++++++++++++++++++++++++++++++++++++++
 mkfs/common.h |   3 ++
 mkfs/main.c   |  36 +-----------------
 4 files changed, 112 insertions(+), 34 deletions(-)

diff --git a/disk-io.c b/disk-io.c
index 5fafa144c0d3..2cb7f2097fc9 100644
--- a/disk-io.c
+++ b/disk-io.c
@@ -694,6 +694,8 @@ void btrfs_free_fs_info(struct btrfs_fs_info *fs_info)
 {
 	if (fs_info->quota_root)
 		free(fs_info->quota_root);
+	if (fs_info->uuid_root)
+		free(fs_info->uuid_root);
 
 	free(fs_info->tree_root);
 	free(fs_info->extent_root);
@@ -964,6 +966,8 @@ void btrfs_release_all_roots(struct btrfs_fs_info *fs_info)
 		free_extent_buffer(fs_info->log_root_tree->node);
 	if (fs_info->chunk_root)
 		free_extent_buffer(fs_info->chunk_root->node);
+	if (fs_info->uuid_root)
+		free_extent_buffer(fs_info->uuid_root->node);
 }
 
 static void free_map_lookup(struct cache_extent *ce)
diff --git a/mkfs/common.c b/mkfs/common.c
index f7e3badcf2b9..1f5e1d03a6e3 100644
--- a/mkfs/common.c
+++ b/mkfs/common.c
@@ -23,6 +23,7 @@
 #include "disk-io.h"
 #include "volumes.h"
 #include "utils.h"
+#include "transaction.h"
 #include "mkfs/common.h"
 
 static u64 reference_root_table[] = {
@@ -822,4 +823,106 @@ int test_minimum_size(const char *file, u64 min_dev_size)
 	return 0;
 }
 
+/*
+ * Create a tree with all its content copied from @source
+ *
+ * Caller must ensure @source only has one leaf.
+ */
+static int __create_tree(struct btrfs_trans_handle *trans,
+			 struct btrfs_root *root, u64 objectid)
+{
+	struct btrfs_fs_info *fs_info = trans->fs_info;
+	struct btrfs_key location;
+	struct btrfs_root_item root_item;
+	struct extent_buffer *tmp;
+	u8 uuid[BTRFS_UUID_SIZE] = {0};
+	int ret;
+
+	ASSERT(btrfs_header_level(root->node) == 0);
+
+	ret = btrfs_copy_root(trans, root, root->node, &tmp, objectid);
+	if (ret)
+		return ret;
+
+	memcpy(&root_item, &root->root_item, sizeof(root_item));
+	btrfs_set_root_bytenr(&root_item, tmp->start);
+	btrfs_set_root_level(&root_item, btrfs_header_level(tmp));
+	btrfs_set_root_generation(&root_item, trans->transid);
+	/* clear uuid and o/ctime of source tree */
+	memcpy(root_item.uuid, uuid, BTRFS_UUID_SIZE);
+	btrfs_set_stack_timespec_sec(&root_item.otime, 0);
+	btrfs_set_stack_timespec_sec(&root_item.ctime, 0);
+	free_extent_buffer(tmp);
+
+	location.objectid = objectid;
+	location.type = BTRFS_ROOT_ITEM_KEY;
+	location.offset = 0;
+	ret = btrfs_insert_root(trans, fs_info->tree_root,
+				&location, &root_item);
+
+	return ret;
+}
+
+/*
+ * Create an *EMPTY* tree
+ *
+ * Caller must ensure at the time of calling, csum tree is still empty
+ */
+static int create_empty_tree(struct btrfs_trans_handle *trans, u64 objectid)
+{
+	struct btrfs_root *csum_root = trans->fs_info->csum_root;
+
+	ASSERT(btrfs_header_level(csum_root->node) == 0 &&
+	       btrfs_header_nritems(csum_root->node) == 0);
+	return __create_tree(trans, csum_root, objectid);
+}
 
+/*
+ * Create a tree containing an root inode
+ *
+ * Caller must ensure at the time of calling, fs tree only contains 2 items
+ * (one for INODE_ITEM and one for INODE_REF)
+ */
+int create_inode_tree(struct btrfs_trans_handle *trans, u64 objectid)
+{
+	struct btrfs_root *fs_root = trans->fs_info->fs_root;
+
+	ASSERT(btrfs_header_level(fs_root->node) == 0 &&
+	       btrfs_header_nritems(fs_root->node) == 2);
+	return __create_tree(trans, fs_root, objectid);
+}
+
+int create_uuid_tree(struct btrfs_trans_handle *trans)
+{
+	struct btrfs_fs_info *fs_info = trans->fs_info;
+	struct btrfs_root *uuid_root = fs_info->uuid_root;
+	struct btrfs_key key;
+	int ret;
+
+	if (!uuid_root) {
+		ret = create_empty_tree(trans, BTRFS_UUID_TREE_OBJECTID);
+		if (ret < 0) {
+			errno = -ret;
+			error("failed to create uuid root: %m");
+			return ret;
+		}
+		key.objectid = BTRFS_UUID_TREE_OBJECTID;
+		key.type = BTRFS_ROOT_ITEM_KEY;
+		key.offset = 0;
+		uuid_root = btrfs_read_fs_root_no_cache(fs_info, &key);
+		if (IS_ERR(uuid_root)) {
+			errno = -PTR_ERR(uuid_root);
+			error("failed to read uuid root: %m");
+			return PTR_ERR(uuid_root);
+		}
+		fs_info->uuid_root = uuid_root;
+	}
+	ret = btrfs_uuid_tree_add(trans, fs_info->fs_root->root_item.uuid,
+				  BTRFS_UUID_KEY_SUBVOL,
+				  fs_info->fs_root->root_key.objectid);
+	if (ret < 0) {
+		errno = -ret;
+		error("failed to add uuid tree entry for fs root: %m");
+	}
+	return ret;
+}
diff --git a/mkfs/common.h b/mkfs/common.h
index 28912906d0a9..adb5d561c38d 100644
--- a/mkfs/common.h
+++ b/mkfs/common.h
@@ -75,4 +75,7 @@ int test_num_disk_vs_raid(u64 metadata_profile, u64 data_profile,
 int test_status_for_mkfs(const char *file, bool force_overwrite);
 int test_dev_for_mkfs(const char *file, int force_overwrite);
 
+int create_uuid_tree(struct btrfs_trans_handle *trans);
+int create_inode_tree(struct btrfs_trans_handle *trans, u64 objectid);
+
 #endif
diff --git a/mkfs/main.c b/mkfs/main.c
index b6748f7fe853..ea3d1ae80e5e 100644
--- a/mkfs/main.c
+++ b/mkfs/main.c
@@ -309,38 +309,6 @@ static int create_raid_groups(struct btrfs_trans_handle *trans,
 	return ret;
 }
 
-static int create_tree(struct btrfs_trans_handle *trans,
-			struct btrfs_root *root, u64 objectid)
-{
-	struct btrfs_key location;
-	struct btrfs_root_item root_item;
-	struct extent_buffer *tmp;
-	u8 uuid[BTRFS_UUID_SIZE] = {0};
-	int ret;
-
-	ret = btrfs_copy_root(trans, root, root->node, &tmp, objectid);
-	if (ret)
-		return ret;
-
-	memcpy(&root_item, &root->root_item, sizeof(root_item));
-	btrfs_set_root_bytenr(&root_item, tmp->start);
-	btrfs_set_root_level(&root_item, btrfs_header_level(tmp));
-	btrfs_set_root_generation(&root_item, trans->transid);
-	/* clear uuid and o/ctime of source tree */
-	memcpy(root_item.uuid, uuid, BTRFS_UUID_SIZE);
-	btrfs_set_stack_timespec_sec(&root_item.otime, 0);
-	btrfs_set_stack_timespec_sec(&root_item.ctime, 0);
-	free_extent_buffer(tmp);
-
-	location.objectid = objectid;
-	location.type = BTRFS_ROOT_ITEM_KEY;
-	location.offset = 0;
-	ret = btrfs_insert_root(trans, root->fs_info->tree_root,
-				&location, &root_item);
-
-	return ret;
-}
-
 static void print_usage(int ret)
 {
 	printf("Usage: mkfs.btrfs [options] dev [ dev ... ]\n");
@@ -1203,13 +1171,13 @@ raid_groups:
 		goto out;
 	}
 
-	ret = create_tree(trans, root, BTRFS_DATA_RELOC_TREE_OBJECTID);
+	ret = create_inode_tree(trans, BTRFS_DATA_RELOC_TREE_OBJECTID);
 	if (ret) {
 		error("unable to create data reloc tree: %d", ret);
 		goto out;
 	}
 
-	ret = create_tree(trans, root, BTRFS_UUID_TREE_OBJECTID);
+	ret = create_uuid_tree(trans);
 	if (ret)
 		warning(
 	"unable to create uuid tree, will be created after mount: %d", ret);
-- 
2.20.1


^ permalink raw reply related	[flat|nested] 16+ messages in thread

* Re: [PATCH 1/3] btrfs-progs: uuid: Port kernel btrfs_uuid_tree_lookup()
  2018-12-27  7:37   ` Su Yue
@ 2018-12-27  7:31     ` Qu Wenruo
  0 siblings, 0 replies; 16+ messages in thread
From: Qu Wenruo @ 2018-12-27  7:31 UTC (permalink / raw)
  To: Su Yue, linux-btrfs


[-- Attachment #1.1: Type: text/plain, Size: 4120 bytes --]



On 2018/12/27 下午3:37, Su Yue wrote:
> 
> 
> On 12/27/18 3:13 PM, Qu Wenruo wrote:
>> Although we have btrfs_uuid_tree_lookup_any(), it's an online function
>> utilizing tree search ioctl, not an offline search function.
>>
>> This patch will port kernel btrfs_uuid_tree_lookup() into btrfs-progs
>> for later proper uuid tree initialization.
>>
>> Signed-off-by: Qu Wenruo <wqu@suse.com>
> 
> One nitpick bellow.
> 
> Reviewed-by: Su Yue <damenly_su@gmx.com>
>> ---
>>   uuid-tree.c | 71 +++++++++++++++++++++++++++++++++++++++++++++++++++--
>>   1 file changed, 69 insertions(+), 2 deletions(-)
>>
>> diff --git a/uuid-tree.c b/uuid-tree.c
>> index 320eb67e1404..b9190103c355 100644
>> --- a/uuid-tree.c
>> +++ b/uuid-tree.c
>> @@ -23,6 +23,7 @@
>>   #include "transaction.h"
>>   #include "disk-io.h"
>>   #include "print-tree.h"
>> +#include "utils.h"
>>       static void btrfs_uuid_to_key(const u8 *uuid, u64 *key_objectid,
>> @@ -32,8 +33,11 @@ static void btrfs_uuid_to_key(const u8 *uuid, u64
>> *key_objectid,
>>       *key_offset = get_unaligned_le64(uuid + sizeof(u64));
>>   }
>>   -
>> -/* return -ENOENT for !found, < 0 for errors, or 0 if an item was
>> found */
>> +/*
>> + * Search uuid tree of a *MOUNTED* btrfs (online)
>> + *
>> + * return -ENOENT for !found, < 0 for errors, or 0 if an item was found
>> + */
>>   static int btrfs_uuid_tree_lookup_any(int fd, const u8 *uuid, u8 type,
>>                         u64 *subid)
>>   {
>> @@ -103,3 +107,66 @@ int btrfs_lookup_uuid_received_subvol_item(int
>> fd, const u8 *uuid,
>>                         BTRFS_UUID_KEY_RECEIVED_SUBVOL,
>>                         subvol_id);
>>   }
>> +
>> +/*
>> + * Search uuid tree of an *UNMOUNTED* btrfs (offline)
> 
> For consistency of btrfs_uuid_tree_lookup_any(), I'd like to add
> "> + * return -ENOENT for !found, < 0 for errors, or 0 if an item was
> found"
> here too :).

Indeed, this return value isn't the normal >0 for !found and in fact the
comment is from kernel.

I'll update the github version without a resend.

Thanks,
Qu

> 
>> + */
>> +static int btrfs_uuid_tree_lookup(struct btrfs_root *uuid_root, u8
>> *uuid,
>> +                  u8 type, u64 subid)
>> +{
>> +    int ret;
>> +    struct btrfs_path *path = NULL;
>> +    struct extent_buffer *eb;
>> +    int slot;
>> +    u32 item_size;
>> +    unsigned long offset;
>> +    struct btrfs_key key;
>> +
>> +    if (!uuid_root) {
>> +        ret = -ENOENT;
>> +        goto out;
>> +    }
>> +
>> +    path = btrfs_alloc_path();
>> +    if (!path) {
>> +        ret = -ENOMEM;
>> +        goto out;
>> +    }
>> +
>> +    btrfs_uuid_to_key(uuid, &key.objectid, &key.offset);
>> +    key.type = type;
>> +    ret = btrfs_search_slot(NULL, uuid_root, &key, path, 0, 0);
>> +    if (ret < 0) {
>> +        goto out;
>> +    } else if (ret > 0) {
>> +        ret = -ENOENT;
>> +        goto out;
>> +    }
>> +
>> +    eb = path->nodes[0];
>> +    slot = path->slots[0];
>> +    item_size = btrfs_item_size_nr(eb, slot);
>> +    offset = btrfs_item_ptr_offset(eb, slot);
>> +    ret = -ENOENT;
>> +
>> +    if (!IS_ALIGNED(item_size, sizeof(u64))) {
>> +        warning("uuid item with illegal size %lu!",
>> +            (unsigned long)item_size);
>> +        goto out;
>> +    }
>> +    while (item_size) {
>> +        __le64 data;
>> +
>> +        read_extent_buffer(eb, &data, offset, sizeof(data));
>> +        if (le64_to_cpu(data) == subid) {
>> +            ret = 0;
>> +            break;
>> +        }
>> +        offset += sizeof(data);
>> +        item_size -= sizeof(data);
>> +    }
>> +
>> +out:
>> +    btrfs_free_path(path);
>> +    return ret;
>> +}
>>
> 


[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 488 bytes --]

^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: [PATCH 1/3] btrfs-progs: uuid: Port kernel btrfs_uuid_tree_lookup()
  2018-12-27  7:13 ` [PATCH 1/3] btrfs-progs: uuid: Port kernel btrfs_uuid_tree_lookup() Qu Wenruo
@ 2018-12-27  7:37   ` Su Yue
  2018-12-27  7:31     ` Qu Wenruo
  0 siblings, 1 reply; 16+ messages in thread
From: Su Yue @ 2018-12-27  7:37 UTC (permalink / raw)
  To: Qu Wenruo, linux-btrfs



On 12/27/18 3:13 PM, Qu Wenruo wrote:
> Although we have btrfs_uuid_tree_lookup_any(), it's an online function
> utilizing tree search ioctl, not an offline search function.
> 
> This patch will port kernel btrfs_uuid_tree_lookup() into btrfs-progs
> for later proper uuid tree initialization.
> 
> Signed-off-by: Qu Wenruo <wqu@suse.com>

One nitpick bellow.

Reviewed-by: Su Yue <damenly_su@gmx.com>
> ---
>   uuid-tree.c | 71 +++++++++++++++++++++++++++++++++++++++++++++++++++--
>   1 file changed, 69 insertions(+), 2 deletions(-)
> 
> diff --git a/uuid-tree.c b/uuid-tree.c
> index 320eb67e1404..b9190103c355 100644
> --- a/uuid-tree.c
> +++ b/uuid-tree.c
> @@ -23,6 +23,7 @@
>   #include "transaction.h"
>   #include "disk-io.h"
>   #include "print-tree.h"
> +#include "utils.h"
>   
>   
>   static void btrfs_uuid_to_key(const u8 *uuid, u64 *key_objectid,
> @@ -32,8 +33,11 @@ static void btrfs_uuid_to_key(const u8 *uuid, u64 *key_objectid,
>   	*key_offset = get_unaligned_le64(uuid + sizeof(u64));
>   }
>   
> -
> -/* return -ENOENT for !found, < 0 for errors, or 0 if an item was found */
> +/*
> + * Search uuid tree of a *MOUNTED* btrfs (online)
> + *
> + * return -ENOENT for !found, < 0 for errors, or 0 if an item was found
> + */
>   static int btrfs_uuid_tree_lookup_any(int fd, const u8 *uuid, u8 type,
>   				      u64 *subid)
>   {
> @@ -103,3 +107,66 @@ int btrfs_lookup_uuid_received_subvol_item(int fd, const u8 *uuid,
>   					  BTRFS_UUID_KEY_RECEIVED_SUBVOL,
>   					  subvol_id);
>   }
> +
> +/*
> + * Search uuid tree of an *UNMOUNTED* btrfs (offline)

For consistency of btrfs_uuid_tree_lookup_any(), I'd like to add
"> + * return -ENOENT for !found, < 0 for errors, or 0 if an item was found"
here too :).

> + */
> +static int btrfs_uuid_tree_lookup(struct btrfs_root *uuid_root, u8 *uuid,
> +				  u8 type, u64 subid)
> +{
> +	int ret;
> +	struct btrfs_path *path = NULL;
> +	struct extent_buffer *eb;
> +	int slot;
> +	u32 item_size;
> +	unsigned long offset;
> +	struct btrfs_key key;
> +
> +	if (!uuid_root) {
> +		ret = -ENOENT;
> +		goto out;
> +	}
> +
> +	path = btrfs_alloc_path();
> +	if (!path) {
> +		ret = -ENOMEM;
> +		goto out;
> +	}
> +
> +	btrfs_uuid_to_key(uuid, &key.objectid, &key.offset);
> +	key.type = type;
> +	ret = btrfs_search_slot(NULL, uuid_root, &key, path, 0, 0);
> +	if (ret < 0) {
> +		goto out;
> +	} else if (ret > 0) {
> +		ret = -ENOENT;
> +		goto out;
> +	}
> +
> +	eb = path->nodes[0];
> +	slot = path->slots[0];
> +	item_size = btrfs_item_size_nr(eb, slot);
> +	offset = btrfs_item_ptr_offset(eb, slot);
> +	ret = -ENOENT;
> +
> +	if (!IS_ALIGNED(item_size, sizeof(u64))) {
> +		warning("uuid item with illegal size %lu!",
> +			(unsigned long)item_size);
> +		goto out;
> +	}
> +	while (item_size) {
> +		__le64 data;
> +
> +		read_extent_buffer(eb, &data, offset, sizeof(data));
> +		if (le64_to_cpu(data) == subid) {
> +			ret = 0;
> +			break;
> +		}
> +		offset += sizeof(data);
> +		item_size -= sizeof(data);
> +	}
> +
> +out:
> +	btrfs_free_path(path);
> +	return ret;
> +}
> 

^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: [PATCH 2/3] btrfs-progs: uuid: Port btrfs_uuid_tree_add() function
  2018-12-27  7:13 ` [PATCH 2/3] btrfs-progs: uuid: Port btrfs_uuid_tree_add() function Qu Wenruo
@ 2018-12-27  7:54   ` Su Yue
  0 siblings, 0 replies; 16+ messages in thread
From: Su Yue @ 2018-12-27  7:54 UTC (permalink / raw)
  To: Qu Wenruo, linux-btrfs



On 12/27/18 3:13 PM, Qu Wenruo wrote:
> This function provide the offline ability to add new uuid tree entry.
> This provides the basis for later proper uuid tree initialization.
> 
> Signed-off-by: Qu Wenruo <wqu@suse.com>

Reviewed-by: Su Yue <damenly_su@gmx.com>

> ---
>   ctree.h     |  7 +++++-
>   uuid-tree.c | 65 +++++++++++++++++++++++++++++++++++++++++++++++++++++
>   2 files changed, 71 insertions(+), 1 deletion(-)
> 
> diff --git a/ctree.h b/ctree.h
> index f9c49d6041c1..7b9e3f1cef6e 100644
> --- a/ctree.h
> +++ b/ctree.h
> @@ -1101,6 +1101,7 @@ struct btrfs_fs_info {
>   	struct btrfs_root *csum_root;
>   	struct btrfs_root *quota_root;
>   	struct btrfs_root *free_space_root;
> +	struct btrfs_root *uuid_root;
>   
>   	struct rb_root fs_root_tree;
>   
> @@ -2774,11 +2775,15 @@ int btrfs_csum_truncate(struct btrfs_trans_handle *trans,
>   			struct btrfs_root *root, struct btrfs_path *path,
>   			u64 isize);
>   
> -/* uuid-tree.c */
> +/* uuid-tree.c, mounted fs (online) interface */
>   int btrfs_lookup_uuid_subvol_item(int fd, const u8 *uuid, u64 *subvol_id);
>   int btrfs_lookup_uuid_received_subvol_item(int fd, const u8 *uuid,
>   					   u64 *subvol_id);
>   
> +/* uuid-tree.c, unmounted fs (offline) interface */
> +int btrfs_uuid_tree_add(struct btrfs_trans_handle *trans, u8 *uuid, u8 type,
> +			u64 subid_cpu);
> +
>   static inline int is_fstree(u64 rootid)
>   {
>   	if (rootid == BTRFS_FS_TREE_OBJECTID ||
> diff --git a/uuid-tree.c b/uuid-tree.c
> index b9190103c355..3f547198f016 100644
> --- a/uuid-tree.c
> +++ b/uuid-tree.c
> @@ -170,3 +170,68 @@ out:
>   	btrfs_free_path(path);
>   	return ret;
>   }
> +
> +int btrfs_uuid_tree_add(struct btrfs_trans_handle *trans, u8 *uuid, u8 type,
> +			u64 subid_cpu)
> +{
> +	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;
> +	__le64 subid_le;
> +
> +	if (!uuid_root) {
> +		warning("%s: uuid root is not initialized", __func__);
> +		return -EINVAL;
> +	}
> +
> +	ret = btrfs_uuid_tree_lookup(uuid_root, uuid, type, subid_cpu);
> +	if (ret != -ENOENT)
> +		return ret;
> +
> +	key.type = type;
> +	btrfs_uuid_to_key(uuid, &key.objectid, &key.offset);
> +
> +	path = btrfs_alloc_path();
> +	if (!path) {
> +		ret = -ENOMEM;
> +		goto out;
> +	}
> +
> +	ret = btrfs_insert_empty_item(trans, uuid_root, path, &key,
> +				      sizeof(subid_le));
> +	if (ret >= 0) {
> +		/* Add an item for the type for the first time */
> +		eb = path->nodes[0];
> +		slot = path->slots[0];
> +		offset = btrfs_item_ptr_offset(eb, slot);
> +	} else if (ret == -EEXIST) {
> +		/*
> +		 * An item with that type already exists.
> +		 * Extend the item and store the new subid at the end.
> +		 */
> +		btrfs_extend_item(uuid_root, path, sizeof(subid_le));
> +		eb = path->nodes[0];
> +		slot = path->slots[0];
> +		offset = btrfs_item_ptr_offset(eb, slot);
> +		offset += btrfs_item_size_nr(eb, slot) - sizeof(subid_le);
> +	} else if (ret < 0) {
> +		warning("insert uuid item failed %d (0x%016llx, 0x%016llx) type %u!",
> +			ret, (unsigned long long)key.objectid,
> +			(unsigned long long)key.offset, type);
> +		goto out;
> +	}
> +
> +	ret = 0;
> +	subid_le = cpu_to_le64(subid_cpu);
> +	write_extent_buffer(eb, &subid_le, offset, sizeof(subid_le));
> +	btrfs_mark_buffer_dirty(eb);
> +
> +out:
> +	btrfs_free_path(path);
> +	return ret;
> +}
> 

^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: [PATCH 3/3] btrfs-progs: Create uuid tree with proper contents
  2018-12-27  7:13 ` [PATCH 3/3] btrfs-progs: Create uuid tree with proper contents Qu Wenruo
@ 2018-12-27 11:28   ` Su Yue
  2018-12-27 11:32     ` Qu Wenruo
  2019-01-02 16:31     ` David Sterba
  2019-01-02  9:13   ` Nikolay Borisov
  1 sibling, 2 replies; 16+ messages in thread
From: Su Yue @ 2018-12-27 11:28 UTC (permalink / raw)
  To: Qu Wenruo, linux-btrfs



On 2018/12/27 3:13 PM, Qu Wenruo wrote:
> Commit 2a496a5b8b74 ("btrfs-progs: mkfs: precreate the uuid tree")
> creates uuid tree at mkfs time.
> 
> However it doesn't populate uuid tree correctly nor just create an empty
> root.
> It uses create_tree(), which just copies the content of fs root,
> containing meaningless INODE_ITEM:
> 
> v4.15 mkfs (no uuid tree creation) + kernel mount:
>    uuid tree key (UUID_TREE ROOT_ITEM 0)
>    leaf 30572544 items 1 free space 16250 generation 7 owner UUID_TREE
>    leaf 30572544 flags 0x1(WRITTEN) backref revision 1
>    fs uuid 33ecddef-fc86-481a-93ce-846b01c11376
>    chunk uuid 9e58f646-b0da-43ca-9c7d-8bbe3e120246
> 	item 0 key (0x92457c59d31491be UUID_KEY_SUBVOL 0xef908b5e79aa76a1) itemoff 16275 itemsize 8
> 		subvol_id 5
> 
> v4.19.1 mkfs (incorrect one), no kernel mount:
>    uuid tree key (UUID_TREE ROOT_ITEM 0)
>    leaf 30507008 items 2 free space 16061 generation 4 owner UUID_TREE
>    leaf 30507008 flags 0x1(WRITTEN) backref revision 1
>    fs uuid 162f5333-9b5d-4217-877c-ddaeaa79398e
>    chunk uuid 7bc2c5c6-a6d2-4eec-a513-142b549c6541
> 	item 0 key (256 INODE_ITEM 0) itemoff 16123 itemsize 160
> 		generation 3 transid 0 size 0 nbytes 16384
> 		block group 0 mode 40755 links 1 uid 0 gid 0 rdev 0
> 		sequence 0 flags 0x0(none)
> 	item 1 key (256 INODE_REF 256) itemoff 16111 itemsize 12
> 		index 0 namelen 2 name: ..
> 
> This patchset will fix it by populuating uuid tree properly:
> (NOTE: due to tree-checker, kernel doesn't accept empty uuid tree, so we
>   can only fix it by populating uuid tree correctly)
> 
> w/ this patchset, no kernel mount:
>    uuid tree key (UUID_TREE ROOT_ITEM 0)
>    leaf 30507008 items 1 free space 16250 generation 4 owner UUID_TREE
>    leaf 30507008 flags 0x1(WRITTEN) backref revision 1
>    fs uuid ae53079e-dbbc-409b-a565-5326c7b27731
>    chunk uuid b5fb1bea-f20d-4af1-80f8-6ca3f0038d67
> 	item 0 key (0x334ba6b032d89c07 UUID_KEY_SUBVOL 0x86cde09cb78bcca0) itemoff 16275 itemsize 8
> 		subvol_id 5
> 
> For kernel, except tree-checker needs an non-empty uuid tree, both all
> above behavior won't cause problem, but it's always better to keep a
> good standardized behavior.
> 
> Furthermore, to avoid such problem from happening again, rename the
> function create_tree() to create_empty_tree() and create_inode_tree(),
> without an @root parameter to avoid such problem.
> 
> Fixes: 2a496a5b8b74 ("btrfs-progs: mkfs: precreate the uuid tree")
> Signed-off-by: Qu Wenruo <wqu@suse.com>
> ---
>   disk-io.c     |   4 ++
>   mkfs/common.c | 103 ++++++++++++++++++++++++++++++++++++++++++++++++++
>   mkfs/common.h |   3 ++
>   mkfs/main.c   |  36 +-----------------
>   4 files changed, 112 insertions(+), 34 deletions(-)
> 
> diff --git a/disk-io.c b/disk-io.c
> index 5fafa144c0d3..2cb7f2097fc9 100644
> --- a/disk-io.c
> +++ b/disk-io.c
> @@ -694,6 +694,8 @@ void btrfs_free_fs_info(struct btrfs_fs_info *fs_info)
>   {
>   	if (fs_info->quota_root)
>   		free(fs_info->quota_root);
> +	if (fs_info->uuid_root)
> +		free(fs_info->uuid_root);
>   
>   	free(fs_info->tree_root);
>   	free(fs_info->extent_root);
> @@ -964,6 +966,8 @@ void btrfs_release_all_roots(struct btrfs_fs_info *fs_info)
>   		free_extent_buffer(fs_info->log_root_tree->node);
>   	if (fs_info->chunk_root)
>   		free_extent_buffer(fs_info->chunk_root->node);
> +	if (fs_info->uuid_root)
> +		free_extent_buffer(fs_info->uuid_root->node);
>   }
>   
>   static void free_map_lookup(struct cache_extent *ce)
> diff --git a/mkfs/common.c b/mkfs/common.c
> index f7e3badcf2b9..1f5e1d03a6e3 100644
> --- a/mkfs/common.c
> +++ b/mkfs/common.c
> @@ -23,6 +23,7 @@
>   #include "disk-io.h"
>   #include "volumes.h"
>   #include "utils.h"
> +#include "transaction.h"
>   #include "mkfs/common.h"
>   
>   static u64 reference_root_table[] = {
> @@ -822,4 +823,106 @@ int test_minimum_size(const char *file, u64 min_dev_size)
>   	return 0;
>   }
>   
> +/*
> + * Create a tree with all its content copied from @source
> + *
> + * Caller must ensure @source only has one leaf.
> + */
> +static int __create_tree(struct btrfs_trans_handle *trans,
> +			 struct btrfs_root *root, u64 objectid)
> +{
> +	struct btrfs_fs_info *fs_info = trans->fs_info;
> +	struct btrfs_key location;
> +	struct btrfs_root_item root_item;
> +	struct extent_buffer *tmp;
> +	u8 uuid[BTRFS_UUID_SIZE] = {0};
> +	int ret;
> +
> +	ASSERT(btrfs_header_level(root->node) == 0);
> +
> +	ret = btrfs_copy_root(trans, root, root->node, &tmp, objectid);
> +	if (ret)
> +		return ret;
> +
> +	memcpy(&root_item, &root->root_item, sizeof(root_item));
> +	btrfs_set_root_bytenr(&root_item, tmp->start);
> +	btrfs_set_root_level(&root_item, btrfs_header_level(tmp));
> +	btrfs_set_root_generation(&root_item, trans->transid);
> +	/* clear uuid and o/ctime of source tree */
> +	memcpy(root_item.uuid, uuid, BTRFS_UUID_SIZE);
> +	btrfs_set_stack_timespec_sec(&root_item.otime, 0);
> +	btrfs_set_stack_timespec_sec(&root_item.ctime, 0);
> +	free_extent_buffer(tmp);
> +
> +	location.objectid = objectid;
> +	location.type = BTRFS_ROOT_ITEM_KEY;
> +	location.offset = 0;
> +	ret = btrfs_insert_root(trans, fs_info->tree_root,
> +				&location, &root_item);
> +
> +	return ret;
> +}
> +
> +/*
> + * Create an *EMPTY* tree
> + *
> + * Caller must ensure at the time of calling, csum tree is still empty
> + */
> +static int create_empty_tree(struct btrfs_trans_handle *trans, u64 objectid)
> +{
> +	struct btrfs_root *csum_root = trans->fs_info->csum_root;
> +
> +	ASSERT(btrfs_header_level(csum_root->node) == 0 &&
> +	       btrfs_header_nritems(csum_root->node) == 0);
> +	return __create_tree(trans, csum_root, objectid);
> +}
>   
> +/*
> + * Create a tree containing an root inode
> + *
> + * Caller must ensure at the time of calling, fs tree only contains 2 items
> + * (one for INODE_ITEM and one for INODE_REF)
> + */
> +int create_inode_tree(struct btrfs_trans_handle *trans, u64 objectid)
> +{
> +	struct btrfs_root *fs_root = trans->fs_info->fs_root;
> +
> +	ASSERT(btrfs_header_level(fs_root->node) == 0 &&
> +	       btrfs_header_nritems(fs_root->node) == 2);
> +	return __create_tree(trans, fs_root, objectid);
> +}
> +
> +int create_uuid_tree(struct btrfs_trans_handle *trans)
> +{
> +	struct btrfs_fs_info *fs_info = trans->fs_info;
> +	struct btrfs_root *uuid_root = fs_info->uuid_root;
> +	struct btrfs_key key;
> +	int ret;
> +
> +	if (!uuid_root) {
> +		ret = create_empty_tree(trans, BTRFS_UUID_TREE_OBJECTID);
> +		if (ret < 0) {
> +			errno = -ret;
> +			error("failed to create uuid root: %m");

In personal taste, I don't like such assignment.
Let the community say.

Others look nice to me.

Thanks,
Su

> +			return ret;
> +		}
> +		key.objectid = BTRFS_UUID_TREE_OBJECTID;
> +		key.type = BTRFS_ROOT_ITEM_KEY;
> +		key.offset = 0;
> +		uuid_root = btrfs_read_fs_root_no_cache(fs_info, &key);
> +		if (IS_ERR(uuid_root)) {
> +			errno = -PTR_ERR(uuid_root);
> +			error("failed to read uuid root: %m");
> +			return PTR_ERR(uuid_root);
> +		}
> +		fs_info->uuid_root = uuid_root;
> +	}
> +	ret = btrfs_uuid_tree_add(trans, fs_info->fs_root->root_item.uuid,
> +				  BTRFS_UUID_KEY_SUBVOL,
> +				  fs_info->fs_root->root_key.objectid);
> +	if (ret < 0) {
> +		errno = -ret;
> +		error("failed to add uuid tree entry for fs root: %m");
> +	}
> +	return ret;
> +}
> diff --git a/mkfs/common.h b/mkfs/common.h
> index 28912906d0a9..adb5d561c38d 100644
> --- a/mkfs/common.h
> +++ b/mkfs/common.h
> @@ -75,4 +75,7 @@ int test_num_disk_vs_raid(u64 metadata_profile, u64 data_profile,
>   int test_status_for_mkfs(const char *file, bool force_overwrite);
>   int test_dev_for_mkfs(const char *file, int force_overwrite);
>   
> +int create_uuid_tree(struct btrfs_trans_handle *trans);
> +int create_inode_tree(struct btrfs_trans_handle *trans, u64 objectid);
> +
>   #endif
> diff --git a/mkfs/main.c b/mkfs/main.c
> index b6748f7fe853..ea3d1ae80e5e 100644
> --- a/mkfs/main.c
> +++ b/mkfs/main.c
> @@ -309,38 +309,6 @@ static int create_raid_groups(struct btrfs_trans_handle *trans,
>   	return ret;
>   }
>   
> -static int create_tree(struct btrfs_trans_handle *trans,
> -			struct btrfs_root *root, u64 objectid)
> -{
> -	struct btrfs_key location;
> -	struct btrfs_root_item root_item;
> -	struct extent_buffer *tmp;
> -	u8 uuid[BTRFS_UUID_SIZE] = {0};
> -	int ret;
> -
> -	ret = btrfs_copy_root(trans, root, root->node, &tmp, objectid);
> -	if (ret)
> -		return ret;
> -
> -	memcpy(&root_item, &root->root_item, sizeof(root_item));
> -	btrfs_set_root_bytenr(&root_item, tmp->start);
> -	btrfs_set_root_level(&root_item, btrfs_header_level(tmp));
> -	btrfs_set_root_generation(&root_item, trans->transid);
> -	/* clear uuid and o/ctime of source tree */
> -	memcpy(root_item.uuid, uuid, BTRFS_UUID_SIZE);
> -	btrfs_set_stack_timespec_sec(&root_item.otime, 0);
> -	btrfs_set_stack_timespec_sec(&root_item.ctime, 0);
> -	free_extent_buffer(tmp);
> -
> -	location.objectid = objectid;
> -	location.type = BTRFS_ROOT_ITEM_KEY;
> -	location.offset = 0;
> -	ret = btrfs_insert_root(trans, root->fs_info->tree_root,
> -				&location, &root_item);
> -
> -	return ret;
> -}
> -
>   static void print_usage(int ret)
>   {
>   	printf("Usage: mkfs.btrfs [options] dev [ dev ... ]\n");
> @@ -1203,13 +1171,13 @@ raid_groups:
>   		goto out;
>   	}
>   
> -	ret = create_tree(trans, root, BTRFS_DATA_RELOC_TREE_OBJECTID);
> +	ret = create_inode_tree(trans, BTRFS_DATA_RELOC_TREE_OBJECTID);
>   	if (ret) {
>   		error("unable to create data reloc tree: %d", ret);
>   		goto out;
>   	}
>   
> -	ret = create_tree(trans, root, BTRFS_UUID_TREE_OBJECTID);
> +	ret = create_uuid_tree(trans);
>   	if (ret)
>   		warning(
>   	"unable to create uuid tree, will be created after mount: %d", ret);
> 

^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: [PATCH 3/3] btrfs-progs: Create uuid tree with proper contents
  2018-12-27 11:28   ` Su Yue
@ 2018-12-27 11:32     ` Qu Wenruo
  2019-01-02 16:31     ` David Sterba
  1 sibling, 0 replies; 16+ messages in thread
From: Qu Wenruo @ 2018-12-27 11:32 UTC (permalink / raw)
  To: Su Yue, linux-btrfs


[-- Attachment #1.1: Type: text/plain, Size: 11765 bytes --]



On 2018/12/27 下午7:28, Su Yue wrote:
> 
> 
> On 2018/12/27 3:13 PM, Qu Wenruo wrote:
>> Commit 2a496a5b8b74 ("btrfs-progs: mkfs: precreate the uuid tree")
>> creates uuid tree at mkfs time.
>>
>> However it doesn't populate uuid tree correctly nor just create an empty
>> root.
>> It uses create_tree(), which just copies the content of fs root,
>> containing meaningless INODE_ITEM:
>>
>> v4.15 mkfs (no uuid tree creation) + kernel mount:
>>    uuid tree key (UUID_TREE ROOT_ITEM 0)
>>    leaf 30572544 items 1 free space 16250 generation 7 owner UUID_TREE
>>    leaf 30572544 flags 0x1(WRITTEN) backref revision 1
>>    fs uuid 33ecddef-fc86-481a-93ce-846b01c11376
>>    chunk uuid 9e58f646-b0da-43ca-9c7d-8bbe3e120246
>>     item 0 key (0x92457c59d31491be UUID_KEY_SUBVOL 0xef908b5e79aa76a1)
>> itemoff 16275 itemsize 8
>>         subvol_id 5
>>
>> v4.19.1 mkfs (incorrect one), no kernel mount:
>>    uuid tree key (UUID_TREE ROOT_ITEM 0)
>>    leaf 30507008 items 2 free space 16061 generation 4 owner UUID_TREE
>>    leaf 30507008 flags 0x1(WRITTEN) backref revision 1
>>    fs uuid 162f5333-9b5d-4217-877c-ddaeaa79398e
>>    chunk uuid 7bc2c5c6-a6d2-4eec-a513-142b549c6541
>>     item 0 key (256 INODE_ITEM 0) itemoff 16123 itemsize 160
>>         generation 3 transid 0 size 0 nbytes 16384
>>         block group 0 mode 40755 links 1 uid 0 gid 0 rdev 0
>>         sequence 0 flags 0x0(none)
>>     item 1 key (256 INODE_REF 256) itemoff 16111 itemsize 12
>>         index 0 namelen 2 name: ..
>>
>> This patchset will fix it by populuating uuid tree properly:
>> (NOTE: due to tree-checker, kernel doesn't accept empty uuid tree, so we
>>   can only fix it by populating uuid tree correctly)
>>
>> w/ this patchset, no kernel mount:
>>    uuid tree key (UUID_TREE ROOT_ITEM 0)
>>    leaf 30507008 items 1 free space 16250 generation 4 owner UUID_TREE
>>    leaf 30507008 flags 0x1(WRITTEN) backref revision 1
>>    fs uuid ae53079e-dbbc-409b-a565-5326c7b27731
>>    chunk uuid b5fb1bea-f20d-4af1-80f8-6ca3f0038d67
>>     item 0 key (0x334ba6b032d89c07 UUID_KEY_SUBVOL 0x86cde09cb78bcca0)
>> itemoff 16275 itemsize 8
>>         subvol_id 5
>>
>> For kernel, except tree-checker needs an non-empty uuid tree, both all
>> above behavior won't cause problem, but it's always better to keep a
>> good standardized behavior.
>>
>> Furthermore, to avoid such problem from happening again, rename the
>> function create_tree() to create_empty_tree() and create_inode_tree(),
>> without an @root parameter to avoid such problem.
>>
>> Fixes: 2a496a5b8b74 ("btrfs-progs: mkfs: precreate the uuid tree")
>> Signed-off-by: Qu Wenruo <wqu@suse.com>
>> ---
>>   disk-io.c     |   4 ++
>>   mkfs/common.c | 103 ++++++++++++++++++++++++++++++++++++++++++++++++++
>>   mkfs/common.h |   3 ++
>>   mkfs/main.c   |  36 +-----------------
>>   4 files changed, 112 insertions(+), 34 deletions(-)
>>
>> diff --git a/disk-io.c b/disk-io.c
>> index 5fafa144c0d3..2cb7f2097fc9 100644
>> --- a/disk-io.c
>> +++ b/disk-io.c
>> @@ -694,6 +694,8 @@ void btrfs_free_fs_info(struct btrfs_fs_info
>> *fs_info)
>>   {
>>       if (fs_info->quota_root)
>>           free(fs_info->quota_root);
>> +    if (fs_info->uuid_root)
>> +        free(fs_info->uuid_root);
>>         free(fs_info->tree_root);
>>       free(fs_info->extent_root);
>> @@ -964,6 +966,8 @@ void btrfs_release_all_roots(struct btrfs_fs_info
>> *fs_info)
>>           free_extent_buffer(fs_info->log_root_tree->node);
>>       if (fs_info->chunk_root)
>>           free_extent_buffer(fs_info->chunk_root->node);
>> +    if (fs_info->uuid_root)
>> +        free_extent_buffer(fs_info->uuid_root->node);
>>   }
>>     static void free_map_lookup(struct cache_extent *ce)
>> diff --git a/mkfs/common.c b/mkfs/common.c
>> index f7e3badcf2b9..1f5e1d03a6e3 100644
>> --- a/mkfs/common.c
>> +++ b/mkfs/common.c
>> @@ -23,6 +23,7 @@
>>   #include "disk-io.h"
>>   #include "volumes.h"
>>   #include "utils.h"
>> +#include "transaction.h"
>>   #include "mkfs/common.h"
>>     static u64 reference_root_table[] = {
>> @@ -822,4 +823,106 @@ int test_minimum_size(const char *file, u64
>> min_dev_size)
>>       return 0;
>>   }
>>   +/*
>> + * Create a tree with all its content copied from @source
>> + *
>> + * Caller must ensure @source only has one leaf.
>> + */
>> +static int __create_tree(struct btrfs_trans_handle *trans,
>> +             struct btrfs_root *root, u64 objectid)
>> +{
>> +    struct btrfs_fs_info *fs_info = trans->fs_info;
>> +    struct btrfs_key location;
>> +    struct btrfs_root_item root_item;
>> +    struct extent_buffer *tmp;
>> +    u8 uuid[BTRFS_UUID_SIZE] = {0};
>> +    int ret;
>> +
>> +    ASSERT(btrfs_header_level(root->node) == 0);
>> +
>> +    ret = btrfs_copy_root(trans, root, root->node, &tmp, objectid);
>> +    if (ret)
>> +        return ret;
>> +
>> +    memcpy(&root_item, &root->root_item, sizeof(root_item));
>> +    btrfs_set_root_bytenr(&root_item, tmp->start);
>> +    btrfs_set_root_level(&root_item, btrfs_header_level(tmp));
>> +    btrfs_set_root_generation(&root_item, trans->transid);
>> +    /* clear uuid and o/ctime of source tree */
>> +    memcpy(root_item.uuid, uuid, BTRFS_UUID_SIZE);
>> +    btrfs_set_stack_timespec_sec(&root_item.otime, 0);
>> +    btrfs_set_stack_timespec_sec(&root_item.ctime, 0);
>> +    free_extent_buffer(tmp);
>> +
>> +    location.objectid = objectid;
>> +    location.type = BTRFS_ROOT_ITEM_KEY;
>> +    location.offset = 0;
>> +    ret = btrfs_insert_root(trans, fs_info->tree_root,
>> +                &location, &root_item);
>> +
>> +    return ret;
>> +}
>> +
>> +/*
>> + * Create an *EMPTY* tree
>> + *
>> + * Caller must ensure at the time of calling, csum tree is still empty
>> + */
>> +static int create_empty_tree(struct btrfs_trans_handle *trans, u64
>> objectid)
>> +{
>> +    struct btrfs_root *csum_root = trans->fs_info->csum_root;
>> +
>> +    ASSERT(btrfs_header_level(csum_root->node) == 0 &&
>> +           btrfs_header_nritems(csum_root->node) == 0);
>> +    return __create_tree(trans, csum_root, objectid);
>> +}
>>   +/*
>> + * Create a tree containing an root inode
>> + *
>> + * Caller must ensure at the time of calling, fs tree only contains 2
>> items
>> + * (one for INODE_ITEM and one for INODE_REF)
>> + */
>> +int create_inode_tree(struct btrfs_trans_handle *trans, u64 objectid)
>> +{
>> +    struct btrfs_root *fs_root = trans->fs_info->fs_root;
>> +
>> +    ASSERT(btrfs_header_level(fs_root->node) == 0 &&
>> +           btrfs_header_nritems(fs_root->node) == 2);
>> +    return __create_tree(trans, fs_root, objectid);
>> +}
>> +
>> +int create_uuid_tree(struct btrfs_trans_handle *trans)
>> +{
>> +    struct btrfs_fs_info *fs_info = trans->fs_info;
>> +    struct btrfs_root *uuid_root = fs_info->uuid_root;
>> +    struct btrfs_key key;
>> +    int ret;
>> +
>> +    if (!uuid_root) {
>> +        ret = create_empty_tree(trans, BTRFS_UUID_TREE_OBJECTID);
>> +        if (ret < 0) {
>> +            errno = -ret;
>> +            error("failed to create uuid root: %m");
> 
> In personal taste, I don't like such assignment.
> Let the community say.

That's the new trend. I'm not a big fan either but it at least saves
some strerr(-ret) calls.

Thanks,
Qu

> 
> Others look nice to me.
> 
> Thanks,
> Su
> 
>> +            return ret;
>> +        }
>> +        key.objectid = BTRFS_UUID_TREE_OBJECTID;
>> +        key.type = BTRFS_ROOT_ITEM_KEY;
>> +        key.offset = 0;
>> +        uuid_root = btrfs_read_fs_root_no_cache(fs_info, &key);
>> +        if (IS_ERR(uuid_root)) {
>> +            errno = -PTR_ERR(uuid_root);
>> +            error("failed to read uuid root: %m");
>> +            return PTR_ERR(uuid_root);
>> +        }
>> +        fs_info->uuid_root = uuid_root;
>> +    }
>> +    ret = btrfs_uuid_tree_add(trans, fs_info->fs_root->root_item.uuid,
>> +                  BTRFS_UUID_KEY_SUBVOL,
>> +                  fs_info->fs_root->root_key.objectid);
>> +    if (ret < 0) {
>> +        errno = -ret;
>> +        error("failed to add uuid tree entry for fs root: %m");
>> +    }
>> +    return ret;
>> +}
>> diff --git a/mkfs/common.h b/mkfs/common.h
>> index 28912906d0a9..adb5d561c38d 100644
>> --- a/mkfs/common.h
>> +++ b/mkfs/common.h
>> @@ -75,4 +75,7 @@ int test_num_disk_vs_raid(u64 metadata_profile, u64
>> data_profile,
>>   int test_status_for_mkfs(const char *file, bool force_overwrite);
>>   int test_dev_for_mkfs(const char *file, int force_overwrite);
>>   +int create_uuid_tree(struct btrfs_trans_handle *trans);
>> +int create_inode_tree(struct btrfs_trans_handle *trans, u64 objectid);
>> +
>>   #endif
>> diff --git a/mkfs/main.c b/mkfs/main.c
>> index b6748f7fe853..ea3d1ae80e5e 100644
>> --- a/mkfs/main.c
>> +++ b/mkfs/main.c
>> @@ -309,38 +309,6 @@ static int create_raid_groups(struct
>> btrfs_trans_handle *trans,
>>       return ret;
>>   }
>>   -static int create_tree(struct btrfs_trans_handle *trans,
>> -            struct btrfs_root *root, u64 objectid)
>> -{
>> -    struct btrfs_key location;
>> -    struct btrfs_root_item root_item;
>> -    struct extent_buffer *tmp;
>> -    u8 uuid[BTRFS_UUID_SIZE] = {0};
>> -    int ret;
>> -
>> -    ret = btrfs_copy_root(trans, root, root->node, &tmp, objectid);
>> -    if (ret)
>> -        return ret;
>> -
>> -    memcpy(&root_item, &root->root_item, sizeof(root_item));
>> -    btrfs_set_root_bytenr(&root_item, tmp->start);
>> -    btrfs_set_root_level(&root_item, btrfs_header_level(tmp));
>> -    btrfs_set_root_generation(&root_item, trans->transid);
>> -    /* clear uuid and o/ctime of source tree */
>> -    memcpy(root_item.uuid, uuid, BTRFS_UUID_SIZE);
>> -    btrfs_set_stack_timespec_sec(&root_item.otime, 0);
>> -    btrfs_set_stack_timespec_sec(&root_item.ctime, 0);
>> -    free_extent_buffer(tmp);
>> -
>> -    location.objectid = objectid;
>> -    location.type = BTRFS_ROOT_ITEM_KEY;
>> -    location.offset = 0;
>> -    ret = btrfs_insert_root(trans, root->fs_info->tree_root,
>> -                &location, &root_item);
>> -
>> -    return ret;
>> -}
>> -
>>   static void print_usage(int ret)
>>   {
>>       printf("Usage: mkfs.btrfs [options] dev [ dev ... ]\n");
>> @@ -1203,13 +1171,13 @@ raid_groups:
>>           goto out;
>>       }
>>   -    ret = create_tree(trans, root, BTRFS_DATA_RELOC_TREE_OBJECTID);
>> +    ret = create_inode_tree(trans, BTRFS_DATA_RELOC_TREE_OBJECTID);
>>       if (ret) {
>>           error("unable to create data reloc tree: %d", ret);
>>           goto out;
>>       }
>>   -    ret = create_tree(trans, root, BTRFS_UUID_TREE_OBJECTID);
>> +    ret = create_uuid_tree(trans);
>>       if (ret)
>>           warning(
>>       "unable to create uuid tree, will be created after mount: %d",
>> ret);
>>
> 


[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 488 bytes --]

^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: [PATCH 3/3] btrfs-progs: Create uuid tree with proper contents
  2018-12-27  7:13 ` [PATCH 3/3] btrfs-progs: Create uuid tree with proper contents Qu Wenruo
  2018-12-27 11:28   ` Su Yue
@ 2019-01-02  9:13   ` Nikolay Borisov
  2019-01-02 10:00     ` Qu Wenruo
  1 sibling, 1 reply; 16+ messages in thread
From: Nikolay Borisov @ 2019-01-02  9:13 UTC (permalink / raw)
  To: Qu Wenruo, linux-btrfs



On 27.12.18 г. 9:13 ч., Qu Wenruo wrote:
> Commit 2a496a5b8b74 ("btrfs-progs: mkfs: precreate the uuid tree")
> creates uuid tree at mkfs time.
> 
> However it doesn't populate uuid tree correctly nor just create an empty
> root.
> It uses create_tree(), which just copies the content of fs root,
> containing meaningless INODE_ITEM:
> 
> v4.15 mkfs (no uuid tree creation) + kernel mount:
>   uuid tree key (UUID_TREE ROOT_ITEM 0)
>   leaf 30572544 items 1 free space 16250 generation 7 owner UUID_TREE
>   leaf 30572544 flags 0x1(WRITTEN) backref revision 1
>   fs uuid 33ecddef-fc86-481a-93ce-846b01c11376
>   chunk uuid 9e58f646-b0da-43ca-9c7d-8bbe3e120246
> 	item 0 key (0x92457c59d31491be UUID_KEY_SUBVOL 0xef908b5e79aa76a1) itemoff 16275 itemsize 8
> 		subvol_id 5
> 
> v4.19.1 mkfs (incorrect one), no kernel mount:
>   uuid tree key (UUID_TREE ROOT_ITEM 0)
>   leaf 30507008 items 2 free space 16061 generation 4 owner UUID_TREE
>   leaf 30507008 flags 0x1(WRITTEN) backref revision 1
>   fs uuid 162f5333-9b5d-4217-877c-ddaeaa79398e
>   chunk uuid 7bc2c5c6-a6d2-4eec-a513-142b549c6541
> 	item 0 key (256 INODE_ITEM 0) itemoff 16123 itemsize 160
> 		generation 3 transid 0 size 0 nbytes 16384
> 		block group 0 mode 40755 links 1 uid 0 gid 0 rdev 0
> 		sequence 0 flags 0x0(none)
> 	item 1 key (256 INODE_REF 256) itemoff 16111 itemsize 12
> 		index 0 namelen 2 name: ..
> 
> This patchset will fix it by populuating uuid tree properly:
> (NOTE: due to tree-checker, kernel doesn't accept empty uuid tree, so we
>  can only fix it by populating uuid tree correctly)
> 
> w/ this patchset, no kernel mount:
>   uuid tree key (UUID_TREE ROOT_ITEM 0)
>   leaf 30507008 items 1 free space 16250 generation 4 owner UUID_TREE
>   leaf 30507008 flags 0x1(WRITTEN) backref revision 1
>   fs uuid ae53079e-dbbc-409b-a565-5326c7b27731
>   chunk uuid b5fb1bea-f20d-4af1-80f8-6ca3f0038d67
> 	item 0 key (0x334ba6b032d89c07 UUID_KEY_SUBVOL 0x86cde09cb78bcca0) itemoff 16275 itemsize 8
> 		subvol_id 5
> 
> For kernel, except tree-checker needs an non-empty uuid tree, both all
> above behavior won't cause problem, but it's always better to keep a
> good standardized behavior.
> 
> Furthermore, to avoid such problem from happening again, rename the
> function create_tree() to create_empty_tree() and create_inode_tree(),
> without an @root parameter to avoid such problem.
> 
> Fixes: 2a496a5b8b74 ("btrfs-progs: mkfs: precreate the uuid tree")
> Signed-off-by: Qu Wenruo <wqu@suse.com>
> ---
>  disk-io.c     |   4 ++
>  mkfs/common.c | 103 ++++++++++++++++++++++++++++++++++++++++++++++++++
>  mkfs/common.h |   3 ++
>  mkfs/main.c   |  36 +-----------------
>  4 files changed, 112 insertions(+), 34 deletions(-)
> 
> diff --git a/disk-io.c b/disk-io.c
> index 5fafa144c0d3..2cb7f2097fc9 100644
> --- a/disk-io.c
> +++ b/disk-io.c
> @@ -694,6 +694,8 @@ void btrfs_free_fs_info(struct btrfs_fs_info *fs_info)
>  {
>  	if (fs_info->quota_root)
>  		free(fs_info->quota_root);
> +	if (fs_info->uuid_root)
> +		free(fs_info->uuid_root);
>  
>  	free(fs_info->tree_root);
>  	free(fs_info->extent_root);
> @@ -964,6 +966,8 @@ void btrfs_release_all_roots(struct btrfs_fs_info *fs_info)
>  		free_extent_buffer(fs_info->log_root_tree->node);
>  	if (fs_info->chunk_root)
>  		free_extent_buffer(fs_info->chunk_root->node);
> +	if (fs_info->uuid_root)
> +		free_extent_buffer(fs_info->uuid_root->node);
>  }
>  
>  static void free_map_lookup(struct cache_extent *ce)
> diff --git a/mkfs/common.c b/mkfs/common.c
> index f7e3badcf2b9..1f5e1d03a6e3 100644
> --- a/mkfs/common.c
> +++ b/mkfs/common.c
> @@ -23,6 +23,7 @@
>  #include "disk-io.h"
>  #include "volumes.h"
>  #include "utils.h"
> +#include "transaction.h"
>  #include "mkfs/common.h"
>  
>  static u64 reference_root_table[] = {
> @@ -822,4 +823,106 @@ int test_minimum_size(const char *file, u64 min_dev_size)
>  	return 0;
>  }
>  
> +/*
> + * Create a tree with all its content copied from @source
> + *
> + * Caller must ensure @source only has one leaf.
> + */
> +static int __create_tree(struct btrfs_trans_handle *trans,
> +			 struct btrfs_root *root, u64 objectid)
> +{
> +	struct btrfs_fs_info *fs_info = trans->fs_info;
> +	struct btrfs_key location;
> +	struct btrfs_root_item root_item;
> +	struct extent_buffer *tmp;
> +	u8 uuid[BTRFS_UUID_SIZE] = {0};
> +	int ret;
> +
> +	ASSERT(btrfs_header_level(root->node) == 0);
> +
> +	ret = btrfs_copy_root(trans, root, root->node, &tmp, objectid);
> +	if (ret)
> +		return ret;
> +
> +	memcpy(&root_item, &root->root_item, sizeof(root_item));
> +	btrfs_set_root_bytenr(&root_item, tmp->start);
> +	btrfs_set_root_level(&root_item, btrfs_header_level(tmp));
> +	btrfs_set_root_generation(&root_item, trans->transid);
> +	/* clear uuid and o/ctime of source tree */
> +	memcpy(root_item.uuid, uuid, BTRFS_UUID_SIZE);
> +	btrfs_set_stack_timespec_sec(&root_item.otime, 0);
> +	btrfs_set_stack_timespec_sec(&root_item.ctime, 0);
> +	free_extent_buffer(tmp);
> +
> +	location.objectid = objectid;
> +	location.type = BTRFS_ROOT_ITEM_KEY;
> +	location.offset = 0;
> +	ret = btrfs_insert_root(trans, fs_info->tree_root,
> +				&location, &root_item);
> +
> +	return ret;
> +}
> +
> +/*
> + * Create an *EMPTY* tree
> + *
> + * Caller must ensure at the time of calling, csum tree is still empty
> + */
> +static int create_empty_tree(struct btrfs_trans_handle *trans, u64 objectid)
> +{
> +	struct btrfs_root *csum_root = trans->fs_info->csum_root;
> +
> +	ASSERT(btrfs_header_level(csum_root->node) == 0 &&
> +	       btrfs_header_nritems(csum_root->node) == 0);
> +	return __create_tree(trans, csum_root, objectid);

nit: IMO this approach (of using a tree as a prototype) is rather bogus
since you exploit the fact that an arbitrary tree (in this case csum)
*should* be empty and so you use it as the source for another empty
tree. Analogically, further down you exploit the fact that the fs_tree
has a default inode and copy that.

I'd prefer it if every tree was created explicitly so that in the future
when its layout might change we touch the respective function. This is
not critical but it's something to think about.

> +}
>  
> +/*
> + * Create a tree containing an root inode
> + *
> + * Caller must ensure at the time of calling, fs tree only contains 2 items
> + * (one for INODE_ITEM and one for INODE_REF)
> + */
> +int create_inode_tree(struct btrfs_trans_handle *trans, u64 objectid)

This function is really misnamed, since it's creating the
DATA_RELOC_TREE, yet it's called create_inode_tree. Why not simply
create_data_reloc_tree or are you planning on using this function more
than once?

> +{
> +	struct btrfs_root *fs_root = trans->fs_info->fs_root;
> +
> +	ASSERT(btrfs_header_level(fs_root->node) == 0 &&
> +	       btrfs_header_nritems(fs_root->node) == 2);
> +	return __create_tree(trans, fs_root, objectid);
> +}
> +
> +int create_uuid_tree(struct btrfs_trans_handle *trans)
> +{
> +	struct btrfs_fs_info *fs_info = trans->fs_info;
> +	struct btrfs_root *uuid_root = fs_info->uuid_root;
> +	struct btrfs_key key;
> +	int ret;
> +
> +	if (!uuid_root) {

Isn't this always true,  so the conditional here is redundant?

> +		ret = create_empty_tree(trans, BTRFS_UUID_TREE_OBJECTID);
> +		if (ret < 0) {
> +			errno = -ret;
> +			error("failed to create uuid root: %m");
> +			return ret;
> +		}
> +		key.objectid = BTRFS_UUID_TREE_OBJECTID;
> +		key.type = BTRFS_ROOT_ITEM_KEY;
> +		key.offset = 0;
> +		uuid_root = btrfs_read_fs_root_no_cache(fs_info, &key);
> +		if (IS_ERR(uuid_root)) {
> +			errno = -PTR_ERR(uuid_root);
> +			error("failed to read uuid root: %m");
> +			return PTR_ERR(uuid_root);
> +		}
> +		fs_info->uuid_root = uuid_root;
> +	}
> +	ret = btrfs_uuid_tree_add(trans, fs_info->fs_root->root_item.uuid,
> +				  BTRFS_UUID_KEY_SUBVOL,
> +				  fs_info->fs_root->root_key.objectid);
> +	if (ret < 0) {
> +		errno = -ret;
> +		error("failed to add uuid tree entry for fs root: %m");
> +	}
> +	return ret;
> +}
> diff --git a/mkfs/common.h b/mkfs/common.h
> index 28912906d0a9..adb5d561c38d 100644
> --- a/mkfs/common.h
> +++ b/mkfs/common.h
> @@ -75,4 +75,7 @@ int test_num_disk_vs_raid(u64 metadata_profile, u64 data_profile,
>  int test_status_for_mkfs(const char *file, bool force_overwrite);
>  int test_dev_for_mkfs(const char *file, int force_overwrite);
>  
> +int create_uuid_tree(struct btrfs_trans_handle *trans);
> +int create_inode_tree(struct btrfs_trans_handle *trans, u64 objectid);
> +
>  #endif
> diff --git a/mkfs/main.c b/mkfs/main.c
> index b6748f7fe853..ea3d1ae80e5e 100644
> --- a/mkfs/main.c
> +++ b/mkfs/main.c
> @@ -309,38 +309,6 @@ static int create_raid_groups(struct btrfs_trans_handle *trans,
>  	return ret;
>  }
>  
> -static int create_tree(struct btrfs_trans_handle *trans,
> -			struct btrfs_root *root, u64 objectid)
> -{
> -	struct btrfs_key location;
> -	struct btrfs_root_item root_item;
> -	struct extent_buffer *tmp;
> -	u8 uuid[BTRFS_UUID_SIZE] = {0};
> -	int ret;
> -
> -	ret = btrfs_copy_root(trans, root, root->node, &tmp, objectid);
> -	if (ret)
> -		return ret;
> -
> -	memcpy(&root_item, &root->root_item, sizeof(root_item));
> -	btrfs_set_root_bytenr(&root_item, tmp->start);
> -	btrfs_set_root_level(&root_item, btrfs_header_level(tmp));
> -	btrfs_set_root_generation(&root_item, trans->transid);
> -	/* clear uuid and o/ctime of source tree */
> -	memcpy(root_item.uuid, uuid, BTRFS_UUID_SIZE);
> -	btrfs_set_stack_timespec_sec(&root_item.otime, 0);
> -	btrfs_set_stack_timespec_sec(&root_item.ctime, 0);
> -	free_extent_buffer(tmp);
> -
> -	location.objectid = objectid;
> -	location.type = BTRFS_ROOT_ITEM_KEY;
> -	location.offset = 0;
> -	ret = btrfs_insert_root(trans, root->fs_info->tree_root,
> -				&location, &root_item);
> -
> -	return ret;
> -}
> -
>  static void print_usage(int ret)
>  {
>  	printf("Usage: mkfs.btrfs [options] dev [ dev ... ]\n");
> @@ -1203,13 +1171,13 @@ raid_groups:
>  		goto out;
>  	}
>  
> -	ret = create_tree(trans, root, BTRFS_DATA_RELOC_TREE_OBJECTID);
> +	ret = create_inode_tree(trans, BTRFS_DATA_RELOC_TREE_OBJECTID);
>  	if (ret) {
>  		error("unable to create data reloc tree: %d", ret);
>  		goto out;
>  	}
>  
> -	ret = create_tree(trans, root, BTRFS_UUID_TREE_OBJECTID);
> +	ret = create_uuid_tree(trans);
>  	if (ret)
>  		warning(
>  	"unable to create uuid tree, will be created after mount: %d", ret);
> 

^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: [PATCH 3/3] btrfs-progs: Create uuid tree with proper contents
  2019-01-02  9:13   ` Nikolay Borisov
@ 2019-01-02 10:00     ` Qu Wenruo
  2019-01-02 10:07       ` Nikolay Borisov
  2019-01-03  4:50       ` Qu Wenruo
  0 siblings, 2 replies; 16+ messages in thread
From: Qu Wenruo @ 2019-01-02 10:00 UTC (permalink / raw)
  To: Nikolay Borisov, Qu Wenruo, linux-btrfs



On 2019/1/2 下午5:13, Nikolay Borisov wrote:
> 
> 
> On 27.12.18 г. 9:13 ч., Qu Wenruo wrote:
>> Commit 2a496a5b8b74 ("btrfs-progs: mkfs: precreate the uuid tree")
>> creates uuid tree at mkfs time.
>>
>> However it doesn't populate uuid tree correctly nor just create an empty
>> root.
>> It uses create_tree(), which just copies the content of fs root,
>> containing meaningless INODE_ITEM:
>>
>> v4.15 mkfs (no uuid tree creation) + kernel mount:
>>   uuid tree key (UUID_TREE ROOT_ITEM 0)
>>   leaf 30572544 items 1 free space 16250 generation 7 owner UUID_TREE
>>   leaf 30572544 flags 0x1(WRITTEN) backref revision 1
>>   fs uuid 33ecddef-fc86-481a-93ce-846b01c11376
>>   chunk uuid 9e58f646-b0da-43ca-9c7d-8bbe3e120246
>> 	item 0 key (0x92457c59d31491be UUID_KEY_SUBVOL 0xef908b5e79aa76a1) itemoff 16275 itemsize 8
>> 		subvol_id 5
>>
>> v4.19.1 mkfs (incorrect one), no kernel mount:
>>   uuid tree key (UUID_TREE ROOT_ITEM 0)
>>   leaf 30507008 items 2 free space 16061 generation 4 owner UUID_TREE
>>   leaf 30507008 flags 0x1(WRITTEN) backref revision 1
>>   fs uuid 162f5333-9b5d-4217-877c-ddaeaa79398e
>>   chunk uuid 7bc2c5c6-a6d2-4eec-a513-142b549c6541
>> 	item 0 key (256 INODE_ITEM 0) itemoff 16123 itemsize 160
>> 		generation 3 transid 0 size 0 nbytes 16384
>> 		block group 0 mode 40755 links 1 uid 0 gid 0 rdev 0
>> 		sequence 0 flags 0x0(none)
>> 	item 1 key (256 INODE_REF 256) itemoff 16111 itemsize 12
>> 		index 0 namelen 2 name: ..
>>
>> This patchset will fix it by populuating uuid tree properly:
>> (NOTE: due to tree-checker, kernel doesn't accept empty uuid tree, so we
>>  can only fix it by populating uuid tree correctly)
>>
>> w/ this patchset, no kernel mount:
>>   uuid tree key (UUID_TREE ROOT_ITEM 0)
>>   leaf 30507008 items 1 free space 16250 generation 4 owner UUID_TREE
>>   leaf 30507008 flags 0x1(WRITTEN) backref revision 1
>>   fs uuid ae53079e-dbbc-409b-a565-5326c7b27731
>>   chunk uuid b5fb1bea-f20d-4af1-80f8-6ca3f0038d67
>> 	item 0 key (0x334ba6b032d89c07 UUID_KEY_SUBVOL 0x86cde09cb78bcca0) itemoff 16275 itemsize 8
>> 		subvol_id 5
>>
>> For kernel, except tree-checker needs an non-empty uuid tree, both all
>> above behavior won't cause problem, but it's always better to keep a
>> good standardized behavior.
>>
>> Furthermore, to avoid such problem from happening again, rename the
>> function create_tree() to create_empty_tree() and create_inode_tree(),
>> without an @root parameter to avoid such problem.
>>
>> Fixes: 2a496a5b8b74 ("btrfs-progs: mkfs: precreate the uuid tree")
>> Signed-off-by: Qu Wenruo <wqu@suse.com>
>> ---
>>  disk-io.c     |   4 ++
>>  mkfs/common.c | 103 ++++++++++++++++++++++++++++++++++++++++++++++++++
>>  mkfs/common.h |   3 ++
>>  mkfs/main.c   |  36 +-----------------
>>  4 files changed, 112 insertions(+), 34 deletions(-)
>>
>> diff --git a/disk-io.c b/disk-io.c
>> index 5fafa144c0d3..2cb7f2097fc9 100644
>> --- a/disk-io.c
>> +++ b/disk-io.c
>> @@ -694,6 +694,8 @@ void btrfs_free_fs_info(struct btrfs_fs_info *fs_info)
>>  {
>>  	if (fs_info->quota_root)
>>  		free(fs_info->quota_root);
>> +	if (fs_info->uuid_root)
>> +		free(fs_info->uuid_root);
>>  
>>  	free(fs_info->tree_root);
>>  	free(fs_info->extent_root);
>> @@ -964,6 +966,8 @@ void btrfs_release_all_roots(struct btrfs_fs_info *fs_info)
>>  		free_extent_buffer(fs_info->log_root_tree->node);
>>  	if (fs_info->chunk_root)
>>  		free_extent_buffer(fs_info->chunk_root->node);
>> +	if (fs_info->uuid_root)
>> +		free_extent_buffer(fs_info->uuid_root->node);
>>  }
>>  
>>  static void free_map_lookup(struct cache_extent *ce)
>> diff --git a/mkfs/common.c b/mkfs/common.c
>> index f7e3badcf2b9..1f5e1d03a6e3 100644
>> --- a/mkfs/common.c
>> +++ b/mkfs/common.c
>> @@ -23,6 +23,7 @@
>>  #include "disk-io.h"
>>  #include "volumes.h"
>>  #include "utils.h"
>> +#include "transaction.h"
>>  #include "mkfs/common.h"
>>  
>>  static u64 reference_root_table[] = {
>> @@ -822,4 +823,106 @@ int test_minimum_size(const char *file, u64 min_dev_size)
>>  	return 0;
>>  }
>>  
>> +/*
>> + * Create a tree with all its content copied from @source
>> + *
>> + * Caller must ensure @source only has one leaf.
>> + */
>> +static int __create_tree(struct btrfs_trans_handle *trans,
>> +			 struct btrfs_root *root, u64 objectid)
>> +{
>> +	struct btrfs_fs_info *fs_info = trans->fs_info;
>> +	struct btrfs_key location;
>> +	struct btrfs_root_item root_item;
>> +	struct extent_buffer *tmp;
>> +	u8 uuid[BTRFS_UUID_SIZE] = {0};
>> +	int ret;
>> +
>> +	ASSERT(btrfs_header_level(root->node) == 0);
>> +
>> +	ret = btrfs_copy_root(trans, root, root->node, &tmp, objectid);
>> +	if (ret)
>> +		return ret;
>> +
>> +	memcpy(&root_item, &root->root_item, sizeof(root_item));
>> +	btrfs_set_root_bytenr(&root_item, tmp->start);
>> +	btrfs_set_root_level(&root_item, btrfs_header_level(tmp));
>> +	btrfs_set_root_generation(&root_item, trans->transid);
>> +	/* clear uuid and o/ctime of source tree */
>> +	memcpy(root_item.uuid, uuid, BTRFS_UUID_SIZE);
>> +	btrfs_set_stack_timespec_sec(&root_item.otime, 0);
>> +	btrfs_set_stack_timespec_sec(&root_item.ctime, 0);
>> +	free_extent_buffer(tmp);
>> +
>> +	location.objectid = objectid;
>> +	location.type = BTRFS_ROOT_ITEM_KEY;
>> +	location.offset = 0;
>> +	ret = btrfs_insert_root(trans, fs_info->tree_root,
>> +				&location, &root_item);
>> +
>> +	return ret;
>> +}
>> +
>> +/*
>> + * Create an *EMPTY* tree
>> + *
>> + * Caller must ensure at the time of calling, csum tree is still empty
>> + */
>> +static int create_empty_tree(struct btrfs_trans_handle *trans, u64 objectid)
>> +{
>> +	struct btrfs_root *csum_root = trans->fs_info->csum_root;
>> +
>> +	ASSERT(btrfs_header_level(csum_root->node) == 0 &&
>> +	       btrfs_header_nritems(csum_root->node) == 0);
>> +	return __create_tree(trans, csum_root, objectid);
> 
> nit: IMO this approach (of using a tree as a prototype) is rather bogus
> since you exploit the fact that an arbitrary tree (in this case csum)
> *should* be empty and so you use it as the source for another empty
> tree. Analogically, further down you exploit the fact that the fs_tree
> has a default inode and copy that.
> 
> I'd prefer it if every tree was created explicitly so that in the future
> when its layout might change we touch the respective function. This is
> not critical but it's something to think about.

Yes, I also though about this.

The primary reason here is to reduce new code and reuse as much code as
possible.

The trade off looks OK for mkfs usage, as we have the full control of
when certain tree is empty or not.
And that's why such create_empty_tree() is only exposed for mkfs, not
ctree.h.

But considering how many create_tree() we're implementing in different
sub commands, it looks pretty valid, and I'll try to refactor these
functions using mentioned solution.

> 
>> +}
>>  
>> +/*
>> + * Create a tree containing an root inode
>> + *
>> + * Caller must ensure at the time of calling, fs tree only contains 2 items
>> + * (one for INODE_ITEM and one for INODE_REF)
>> + */
>> +int create_inode_tree(struct btrfs_trans_handle *trans, u64 objectid)
> 
> This function is really misnamed, since it's creating the
> DATA_RELOC_TREE, yet it's called create_inode_tree. Why not simply
> create_data_reloc_tree or are you planning on using this function more
> than once?

In fact this could be used for fs, data reloc, and all subvolume trees.

That's my primary reason not naming it create_data_reloc_tree().
Although currently it's only used by data reloc tree.

> 
>> +{
>> +	struct btrfs_root *fs_root = trans->fs_info->fs_root;
>> +
>> +	ASSERT(btrfs_header_level(fs_root->node) == 0 &&
>> +	       btrfs_header_nritems(fs_root->node) == 2);
>> +	return __create_tree(trans, fs_root, objectid);
>> +}
>> +
>> +int create_uuid_tree(struct btrfs_trans_handle *trans)
>> +{
>> +	struct btrfs_fs_info *fs_info = trans->fs_info;
>> +	struct btrfs_root *uuid_root = fs_info->uuid_root;
>> +	struct btrfs_key key;
>> +	int ret;
>> +
>> +	if (!uuid_root) {
> 
> Isn't this always true,  so the conditional here is redundant?
Just a much better solution than ASSERT()/BUG_ON().

It won't hurt and will handle wrong calling order.

Thanks,
Qu

> 
>> +		ret = create_empty_tree(trans, BTRFS_UUID_TREE_OBJECTID);
>> +		if (ret < 0) {
>> +			errno = -ret;
>> +			error("failed to create uuid root: %m");
>> +			return ret;
>> +		}
>> +		key.objectid = BTRFS_UUID_TREE_OBJECTID;
>> +		key.type = BTRFS_ROOT_ITEM_KEY;
>> +		key.offset = 0;
>> +		uuid_root = btrfs_read_fs_root_no_cache(fs_info, &key);
>> +		if (IS_ERR(uuid_root)) {
>> +			errno = -PTR_ERR(uuid_root);
>> +			error("failed to read uuid root: %m");
>> +			return PTR_ERR(uuid_root);
>> +		}
>> +		fs_info->uuid_root = uuid_root;
>> +	}
>> +	ret = btrfs_uuid_tree_add(trans, fs_info->fs_root->root_item.uuid,
>> +				  BTRFS_UUID_KEY_SUBVOL,
>> +				  fs_info->fs_root->root_key.objectid);
>> +	if (ret < 0) {
>> +		errno = -ret;
>> +		error("failed to add uuid tree entry for fs root: %m");
>> +	}
>> +	return ret;
>> +}
>> diff --git a/mkfs/common.h b/mkfs/common.h
>> index 28912906d0a9..adb5d561c38d 100644
>> --- a/mkfs/common.h
>> +++ b/mkfs/common.h
>> @@ -75,4 +75,7 @@ int test_num_disk_vs_raid(u64 metadata_profile, u64 data_profile,
>>  int test_status_for_mkfs(const char *file, bool force_overwrite);
>>  int test_dev_for_mkfs(const char *file, int force_overwrite);
>>  
>> +int create_uuid_tree(struct btrfs_trans_handle *trans);
>> +int create_inode_tree(struct btrfs_trans_handle *trans, u64 objectid);
>> +
>>  #endif
>> diff --git a/mkfs/main.c b/mkfs/main.c
>> index b6748f7fe853..ea3d1ae80e5e 100644
>> --- a/mkfs/main.c
>> +++ b/mkfs/main.c
>> @@ -309,38 +309,6 @@ static int create_raid_groups(struct btrfs_trans_handle *trans,
>>  	return ret;
>>  }
>>  
>> -static int create_tree(struct btrfs_trans_handle *trans,
>> -			struct btrfs_root *root, u64 objectid)
>> -{
>> -	struct btrfs_key location;
>> -	struct btrfs_root_item root_item;
>> -	struct extent_buffer *tmp;
>> -	u8 uuid[BTRFS_UUID_SIZE] = {0};
>> -	int ret;
>> -
>> -	ret = btrfs_copy_root(trans, root, root->node, &tmp, objectid);
>> -	if (ret)
>> -		return ret;
>> -
>> -	memcpy(&root_item, &root->root_item, sizeof(root_item));
>> -	btrfs_set_root_bytenr(&root_item, tmp->start);
>> -	btrfs_set_root_level(&root_item, btrfs_header_level(tmp));
>> -	btrfs_set_root_generation(&root_item, trans->transid);
>> -	/* clear uuid and o/ctime of source tree */
>> -	memcpy(root_item.uuid, uuid, BTRFS_UUID_SIZE);
>> -	btrfs_set_stack_timespec_sec(&root_item.otime, 0);
>> -	btrfs_set_stack_timespec_sec(&root_item.ctime, 0);
>> -	free_extent_buffer(tmp);
>> -
>> -	location.objectid = objectid;
>> -	location.type = BTRFS_ROOT_ITEM_KEY;
>> -	location.offset = 0;
>> -	ret = btrfs_insert_root(trans, root->fs_info->tree_root,
>> -				&location, &root_item);
>> -
>> -	return ret;
>> -}
>> -
>>  static void print_usage(int ret)
>>  {
>>  	printf("Usage: mkfs.btrfs [options] dev [ dev ... ]\n");
>> @@ -1203,13 +1171,13 @@ raid_groups:
>>  		goto out;
>>  	}
>>  
>> -	ret = create_tree(trans, root, BTRFS_DATA_RELOC_TREE_OBJECTID);
>> +	ret = create_inode_tree(trans, BTRFS_DATA_RELOC_TREE_OBJECTID);
>>  	if (ret) {
>>  		error("unable to create data reloc tree: %d", ret);
>>  		goto out;
>>  	}
>>  
>> -	ret = create_tree(trans, root, BTRFS_UUID_TREE_OBJECTID);
>> +	ret = create_uuid_tree(trans);
>>  	if (ret)
>>  		warning(
>>  	"unable to create uuid tree, will be created after mount: %d", ret);
>>

^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: [PATCH 3/3] btrfs-progs: Create uuid tree with proper contents
  2019-01-02 10:00     ` Qu Wenruo
@ 2019-01-02 10:07       ` Nikolay Borisov
  2019-01-02 10:11         ` Qu Wenruo
  2019-01-03  4:50       ` Qu Wenruo
  1 sibling, 1 reply; 16+ messages in thread
From: Nikolay Borisov @ 2019-01-02 10:07 UTC (permalink / raw)
  To: Qu Wenruo, Qu Wenruo, linux-btrfs



On 2.01.19 г. 12:00 ч., Qu Wenruo wrote:
> 

<snip>

>>> +}
>>>  
>>> +/*
>>> + * Create a tree containing an root inode
>>> + *
>>> + * Caller must ensure at the time of calling, fs tree only contains 2 items
>>> + * (one for INODE_ITEM and one for INODE_REF)
>>> + */
>>> +int create_inode_tree(struct btrfs_trans_handle *trans, u64 objectid)
>>
>> This function is really misnamed, since it's creating the
>> DATA_RELOC_TREE, yet it's called create_inode_tree. Why not simply
>> create_data_reloc_tree or are you planning on using this function more
>> than once?
> 
> In fact this could be used for fs, data reloc, and all subvolume trees.
> 
> That's my primary reason not naming it create_data_reloc_tree().
> Although currently it's only used by data reloc tree.
> 
>>
>>> +{
>>> +	struct btrfs_root *fs_root = trans->fs_info->fs_root;
>>> +
>>> +	ASSERT(btrfs_header_level(fs_root->node) == 0 &&
>>> +	       btrfs_header_nritems(fs_root->node) == 2);
>>> +	return __create_tree(trans, fs_root, objectid);
>>> +}
>>> +
>>> +int create_uuid_tree(struct btrfs_trans_handle *trans)
>>> +{
>>> +	struct btrfs_fs_info *fs_info = trans->fs_info;
>>> +	struct btrfs_root *uuid_root = fs_info->uuid_root;
>>> +	struct btrfs_key key;
>>> +	int ret;
>>> +
>>> +	if (!uuid_root) {
>>
>> Isn't this always true,  so the conditional here is redundant?
> Just a much better solution than ASSERT()/BUG_ON().
> 
> It won't hurt and will handle wrong calling order.

What will the wrong calling order be? The only error that's possible is
if someone calls this function twice or creates the tree outside of this
api. This could only occur if someone is deliberately touching modifying
the code in which case a trigger of an ASSERT should suffice to force
them to think about what they are doing.

> 
> Thanks,
> Qu
> 

<snip>


^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: [PATCH 3/3] btrfs-progs: Create uuid tree with proper contents
  2019-01-02 10:07       ` Nikolay Borisov
@ 2019-01-02 10:11         ` Qu Wenruo
  0 siblings, 0 replies; 16+ messages in thread
From: Qu Wenruo @ 2019-01-02 10:11 UTC (permalink / raw)
  To: Nikolay Borisov, Qu Wenruo, linux-btrfs



On 2019/1/2 下午6:07, Nikolay Borisov wrote:
> 
> 
> On 2.01.19 г. 12:00 ч., Qu Wenruo wrote:
>>
> 
> <snip>
> 
>>>> +}
>>>>  
>>>> +/*
>>>> + * Create a tree containing an root inode
>>>> + *
>>>> + * Caller must ensure at the time of calling, fs tree only contains 2 items
>>>> + * (one for INODE_ITEM and one for INODE_REF)
>>>> + */
>>>> +int create_inode_tree(struct btrfs_trans_handle *trans, u64 objectid)
>>>
>>> This function is really misnamed, since it's creating the
>>> DATA_RELOC_TREE, yet it's called create_inode_tree. Why not simply
>>> create_data_reloc_tree or are you planning on using this function more
>>> than once?
>>
>> In fact this could be used for fs, data reloc, and all subvolume trees.
>>
>> That's my primary reason not naming it create_data_reloc_tree().
>> Although currently it's only used by data reloc tree.
>>
>>>
>>>> +{
>>>> +	struct btrfs_root *fs_root = trans->fs_info->fs_root;
>>>> +
>>>> +	ASSERT(btrfs_header_level(fs_root->node) == 0 &&
>>>> +	       btrfs_header_nritems(fs_root->node) == 2);
>>>> +	return __create_tree(trans, fs_root, objectid);
>>>> +}
>>>> +
>>>> +int create_uuid_tree(struct btrfs_trans_handle *trans)
>>>> +{
>>>> +	struct btrfs_fs_info *fs_info = trans->fs_info;
>>>> +	struct btrfs_root *uuid_root = fs_info->uuid_root;
>>>> +	struct btrfs_key key;
>>>> +	int ret;
>>>> +
>>>> +	if (!uuid_root) {
>>>
>>> Isn't this always true,  so the conditional here is redundant?
>> Just a much better solution than ASSERT()/BUG_ON().
>>
>> It won't hurt and will handle wrong calling order.
> 
> What will the wrong calling order be? The only error that's possible is
> if someone calls this function twice or creates the tree outside of this
> api. This could only occur if someone is deliberately touching modifying
> the code in which case a trigger of an ASSERT should suffice to force
> them to think about what they are doing.

OK, I'll change it to ASSERT().

Thanks,
Qu

> 
>>
>> Thanks,
>> Qu
>>
> 
> <snip>
> 

^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: [PATCH 3/3] btrfs-progs: Create uuid tree with proper contents
  2018-12-27 11:28   ` Su Yue
  2018-12-27 11:32     ` Qu Wenruo
@ 2019-01-02 16:31     ` David Sterba
  2019-01-02 23:46       ` Su Yue
  1 sibling, 1 reply; 16+ messages in thread
From: David Sterba @ 2019-01-02 16:31 UTC (permalink / raw)
  To: Su Yue; +Cc: Qu Wenruo, linux-btrfs

On Thu, Dec 27, 2018 at 07:28:40PM +0800, Su Yue wrote:
> > +}
> > +
> > +int create_uuid_tree(struct btrfs_trans_handle *trans)
> > +{
> > +	struct btrfs_fs_info *fs_info = trans->fs_info;
> > +	struct btrfs_root *uuid_root = fs_info->uuid_root;
> > +	struct btrfs_key key;
> > +	int ret;
> > +
> > +	if (!uuid_root) {
> > +		ret = create_empty_tree(trans, BTRFS_UUID_TREE_OBJECTID);
> > +		if (ret < 0) {
> > +			errno = -ret;
> > +			error("failed to create uuid root: %m");
> 
> In personal taste, I don't like such assignment.
> Let the community say.

Check eg. 251d32ea5cd1cf74cb52, replaces strerror(errno) with %m and
requires no change. As we're using strerror(-ret) in many places, it's a
followup that needs the extra errno assignment. This is IMO a small cost
on the source code size and the gain in space savings might be
noticeable for embedded devices, but we need to do all the conversions.

^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: [PATCH 3/3] btrfs-progs: Create uuid tree with proper contents
  2019-01-02 16:31     ` David Sterba
@ 2019-01-02 23:46       ` Su Yue
  0 siblings, 0 replies; 16+ messages in thread
From: Su Yue @ 2019-01-02 23:46 UTC (permalink / raw)
  To: dsterba, Qu Wenruo, linux-btrfs



On 2019/1/3 12:31 AM, David Sterba wrote:
> On Thu, Dec 27, 2018 at 07:28:40PM +0800, Su Yue wrote:
>>> +}
>>> +
>>> +int create_uuid_tree(struct btrfs_trans_handle *trans)
>>> +{
>>> +	struct btrfs_fs_info *fs_info = trans->fs_info;
>>> +	struct btrfs_root *uuid_root = fs_info->uuid_root;
>>> +	struct btrfs_key key;
>>> +	int ret;
>>> +
>>> +	if (!uuid_root) {
>>> +		ret = create_empty_tree(trans, BTRFS_UUID_TREE_OBJECTID);
>>> +		if (ret < 0) {
>>> +			errno = -ret;
>>> +			error("failed to create uuid root: %m");
>>
>> In personal taste, I don't like such assignment.
>> Let the community say.
> 
> Check eg. 251d32ea5cd1cf74cb52, replaces strerror(errno) with %m and
> requires no change. As we're using strerror(-ret) in many places, it's a
> followup that needs the extra errno assignment. This is IMO a small cost
> on the source code size and the gain in space savings might be
> noticeable for embedded devices, but we need to do all the conversions.
> 

Got it, Thanks.

^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: [PATCH 3/3] btrfs-progs: Create uuid tree with proper contents
  2019-01-02 10:00     ` Qu Wenruo
  2019-01-02 10:07       ` Nikolay Borisov
@ 2019-01-03  4:50       ` Qu Wenruo
  1 sibling, 0 replies; 16+ messages in thread
From: Qu Wenruo @ 2019-01-03  4:50 UTC (permalink / raw)
  To: Nikolay Borisov, Qu Wenruo, linux-btrfs



On 2019/1/2 下午6:00, Qu Wenruo wrote:
> 
> 
> On 2019/1/2 下午5:13, Nikolay Borisov wrote:
>>
>>
>> On 27.12.18 г. 9:13 ч., Qu Wenruo wrote:
>>> Commit 2a496a5b8b74 ("btrfs-progs: mkfs: precreate the uuid tree")
>>> creates uuid tree at mkfs time.
>>>
>>> However it doesn't populate uuid tree correctly nor just create an empty
>>> root.
>>> It uses create_tree(), which just copies the content of fs root,
>>> containing meaningless INODE_ITEM:
>>>
>>> v4.15 mkfs (no uuid tree creation) + kernel mount:
>>>   uuid tree key (UUID_TREE ROOT_ITEM 0)
>>>   leaf 30572544 items 1 free space 16250 generation 7 owner UUID_TREE
>>>   leaf 30572544 flags 0x1(WRITTEN) backref revision 1
>>>   fs uuid 33ecddef-fc86-481a-93ce-846b01c11376
>>>   chunk uuid 9e58f646-b0da-43ca-9c7d-8bbe3e120246
>>> 	item 0 key (0x92457c59d31491be UUID_KEY_SUBVOL 0xef908b5e79aa76a1) itemoff 16275 itemsize 8
>>> 		subvol_id 5
>>>
>>> v4.19.1 mkfs (incorrect one), no kernel mount:
>>>   uuid tree key (UUID_TREE ROOT_ITEM 0)
>>>   leaf 30507008 items 2 free space 16061 generation 4 owner UUID_TREE
>>>   leaf 30507008 flags 0x1(WRITTEN) backref revision 1
>>>   fs uuid 162f5333-9b5d-4217-877c-ddaeaa79398e
>>>   chunk uuid 7bc2c5c6-a6d2-4eec-a513-142b549c6541
>>> 	item 0 key (256 INODE_ITEM 0) itemoff 16123 itemsize 160
>>> 		generation 3 transid 0 size 0 nbytes 16384
>>> 		block group 0 mode 40755 links 1 uid 0 gid 0 rdev 0
>>> 		sequence 0 flags 0x0(none)
>>> 	item 1 key (256 INODE_REF 256) itemoff 16111 itemsize 12
>>> 		index 0 namelen 2 name: ..
>>>
>>> This patchset will fix it by populuating uuid tree properly:
>>> (NOTE: due to tree-checker, kernel doesn't accept empty uuid tree, so we
>>>  can only fix it by populating uuid tree correctly)
>>>
>>> w/ this patchset, no kernel mount:
>>>   uuid tree key (UUID_TREE ROOT_ITEM 0)
>>>   leaf 30507008 items 1 free space 16250 generation 4 owner UUID_TREE
>>>   leaf 30507008 flags 0x1(WRITTEN) backref revision 1
>>>   fs uuid ae53079e-dbbc-409b-a565-5326c7b27731
>>>   chunk uuid b5fb1bea-f20d-4af1-80f8-6ca3f0038d67
>>> 	item 0 key (0x334ba6b032d89c07 UUID_KEY_SUBVOL 0x86cde09cb78bcca0) itemoff 16275 itemsize 8
>>> 		subvol_id 5
>>>
>>> For kernel, except tree-checker needs an non-empty uuid tree, both all
>>> above behavior won't cause problem, but it's always better to keep a
>>> good standardized behavior.
>>>
>>> Furthermore, to avoid such problem from happening again, rename the
>>> function create_tree() to create_empty_tree() and create_inode_tree(),
>>> without an @root parameter to avoid such problem.
>>>
>>> Fixes: 2a496a5b8b74 ("btrfs-progs: mkfs: precreate the uuid tree")
>>> Signed-off-by: Qu Wenruo <wqu@suse.com>
>>> ---
>>>  disk-io.c     |   4 ++
>>>  mkfs/common.c | 103 ++++++++++++++++++++++++++++++++++++++++++++++++++
>>>  mkfs/common.h |   3 ++
>>>  mkfs/main.c   |  36 +-----------------
>>>  4 files changed, 112 insertions(+), 34 deletions(-)
>>>
>>> diff --git a/disk-io.c b/disk-io.c
>>> index 5fafa144c0d3..2cb7f2097fc9 100644
>>> --- a/disk-io.c
>>> +++ b/disk-io.c
>>> @@ -694,6 +694,8 @@ void btrfs_free_fs_info(struct btrfs_fs_info *fs_info)
>>>  {
>>>  	if (fs_info->quota_root)
>>>  		free(fs_info->quota_root);
>>> +	if (fs_info->uuid_root)
>>> +		free(fs_info->uuid_root);
>>>  
>>>  	free(fs_info->tree_root);
>>>  	free(fs_info->extent_root);
>>> @@ -964,6 +966,8 @@ void btrfs_release_all_roots(struct btrfs_fs_info *fs_info)
>>>  		free_extent_buffer(fs_info->log_root_tree->node);
>>>  	if (fs_info->chunk_root)
>>>  		free_extent_buffer(fs_info->chunk_root->node);
>>> +	if (fs_info->uuid_root)
>>> +		free_extent_buffer(fs_info->uuid_root->node);
>>>  }
>>>  
>>>  static void free_map_lookup(struct cache_extent *ce)
>>> diff --git a/mkfs/common.c b/mkfs/common.c
>>> index f7e3badcf2b9..1f5e1d03a6e3 100644
>>> --- a/mkfs/common.c
>>> +++ b/mkfs/common.c
>>> @@ -23,6 +23,7 @@
>>>  #include "disk-io.h"
>>>  #include "volumes.h"
>>>  #include "utils.h"
>>> +#include "transaction.h"
>>>  #include "mkfs/common.h"
>>>  
>>>  static u64 reference_root_table[] = {
>>> @@ -822,4 +823,106 @@ int test_minimum_size(const char *file, u64 min_dev_size)
>>>  	return 0;
>>>  }
>>>  
>>> +/*
>>> + * Create a tree with all its content copied from @source
>>> + *
>>> + * Caller must ensure @source only has one leaf.
>>> + */
>>> +static int __create_tree(struct btrfs_trans_handle *trans,
>>> +			 struct btrfs_root *root, u64 objectid)
>>> +{
>>> +	struct btrfs_fs_info *fs_info = trans->fs_info;
>>> +	struct btrfs_key location;
>>> +	struct btrfs_root_item root_item;
>>> +	struct extent_buffer *tmp;
>>> +	u8 uuid[BTRFS_UUID_SIZE] = {0};
>>> +	int ret;
>>> +
>>> +	ASSERT(btrfs_header_level(root->node) == 0);
>>> +
>>> +	ret = btrfs_copy_root(trans, root, root->node, &tmp, objectid);
>>> +	if (ret)
>>> +		return ret;
>>> +
>>> +	memcpy(&root_item, &root->root_item, sizeof(root_item));
>>> +	btrfs_set_root_bytenr(&root_item, tmp->start);
>>> +	btrfs_set_root_level(&root_item, btrfs_header_level(tmp));
>>> +	btrfs_set_root_generation(&root_item, trans->transid);
>>> +	/* clear uuid and o/ctime of source tree */
>>> +	memcpy(root_item.uuid, uuid, BTRFS_UUID_SIZE);
>>> +	btrfs_set_stack_timespec_sec(&root_item.otime, 0);
>>> +	btrfs_set_stack_timespec_sec(&root_item.ctime, 0);
>>> +	free_extent_buffer(tmp);
>>> +
>>> +	location.objectid = objectid;
>>> +	location.type = BTRFS_ROOT_ITEM_KEY;
>>> +	location.offset = 0;
>>> +	ret = btrfs_insert_root(trans, fs_info->tree_root,
>>> +				&location, &root_item);
>>> +
>>> +	return ret;
>>> +}
>>> +
>>> +/*
>>> + * Create an *EMPTY* tree
>>> + *
>>> + * Caller must ensure at the time of calling, csum tree is still empty
>>> + */
>>> +static int create_empty_tree(struct btrfs_trans_handle *trans, u64 objectid)
>>> +{
>>> +	struct btrfs_root *csum_root = trans->fs_info->csum_root;
>>> +
>>> +	ASSERT(btrfs_header_level(csum_root->node) == 0 &&
>>> +	       btrfs_header_nritems(csum_root->node) == 0);
>>> +	return __create_tree(trans, csum_root, objectid);
>>
>> nit: IMO this approach (of using a tree as a prototype) is rather bogus
>> since you exploit the fact that an arbitrary tree (in this case csum)
>> *should* be empty and so you use it as the source for another empty
>> tree. Analogically, further down you exploit the fact that the fs_tree
>> has a default inode and copy that.
>>
>> I'd prefer it if every tree was created explicitly so that in the future
>> when its layout might change we touch the respective function. This is
>> not critical but it's something to think about.
> 
> Yes, I also though about this.
> 
> The primary reason here is to reduce new code and reuse as much code as
> possible.

After a quick glance into the free space tree, it has
btrfs_create_tree() ported from kernel.

It's a way better solution than the current one.

I'll just use that function to do all the work.

Thanks,
Qu

> 
> The trade off looks OK for mkfs usage, as we have the full control of
> when certain tree is empty or not.
> And that's why such create_empty_tree() is only exposed for mkfs, not
> ctree.h.
> 
> But considering how many create_tree() we're implementing in different
> sub commands, it looks pretty valid, and I'll try to refactor these
> functions using mentioned solution.
> 
>>
>>> +}
>>>  
>>> +/*
>>> + * Create a tree containing an root inode
>>> + *
>>> + * Caller must ensure at the time of calling, fs tree only contains 2 items
>>> + * (one for INODE_ITEM and one for INODE_REF)
>>> + */
>>> +int create_inode_tree(struct btrfs_trans_handle *trans, u64 objectid)
>>
>> This function is really misnamed, since it's creating the
>> DATA_RELOC_TREE, yet it's called create_inode_tree. Why not simply
>> create_data_reloc_tree or are you planning on using this function more
>> than once?
> 
> In fact this could be used for fs, data reloc, and all subvolume trees.
> 
> That's my primary reason not naming it create_data_reloc_tree().
> Although currently it's only used by data reloc tree.
> 
>>
>>> +{
>>> +	struct btrfs_root *fs_root = trans->fs_info->fs_root;
>>> +
>>> +	ASSERT(btrfs_header_level(fs_root->node) == 0 &&
>>> +	       btrfs_header_nritems(fs_root->node) == 2);
>>> +	return __create_tree(trans, fs_root, objectid);
>>> +}
>>> +
>>> +int create_uuid_tree(struct btrfs_trans_handle *trans)
>>> +{
>>> +	struct btrfs_fs_info *fs_info = trans->fs_info;
>>> +	struct btrfs_root *uuid_root = fs_info->uuid_root;
>>> +	struct btrfs_key key;
>>> +	int ret;
>>> +
>>> +	if (!uuid_root) {
>>
>> Isn't this always true,  so the conditional here is redundant?
> Just a much better solution than ASSERT()/BUG_ON().
> 
> It won't hurt and will handle wrong calling order.
> 
> Thanks,
> Qu
> 
>>
>>> +		ret = create_empty_tree(trans, BTRFS_UUID_TREE_OBJECTID);
>>> +		if (ret < 0) {
>>> +			errno = -ret;
>>> +			error("failed to create uuid root: %m");
>>> +			return ret;
>>> +		}
>>> +		key.objectid = BTRFS_UUID_TREE_OBJECTID;
>>> +		key.type = BTRFS_ROOT_ITEM_KEY;
>>> +		key.offset = 0;
>>> +		uuid_root = btrfs_read_fs_root_no_cache(fs_info, &key);
>>> +		if (IS_ERR(uuid_root)) {
>>> +			errno = -PTR_ERR(uuid_root);
>>> +			error("failed to read uuid root: %m");
>>> +			return PTR_ERR(uuid_root);
>>> +		}
>>> +		fs_info->uuid_root = uuid_root;
>>> +	}
>>> +	ret = btrfs_uuid_tree_add(trans, fs_info->fs_root->root_item.uuid,
>>> +				  BTRFS_UUID_KEY_SUBVOL,
>>> +				  fs_info->fs_root->root_key.objectid);
>>> +	if (ret < 0) {
>>> +		errno = -ret;
>>> +		error("failed to add uuid tree entry for fs root: %m");
>>> +	}
>>> +	return ret;
>>> +}
>>> diff --git a/mkfs/common.h b/mkfs/common.h
>>> index 28912906d0a9..adb5d561c38d 100644
>>> --- a/mkfs/common.h
>>> +++ b/mkfs/common.h
>>> @@ -75,4 +75,7 @@ int test_num_disk_vs_raid(u64 metadata_profile, u64 data_profile,
>>>  int test_status_for_mkfs(const char *file, bool force_overwrite);
>>>  int test_dev_for_mkfs(const char *file, int force_overwrite);
>>>  
>>> +int create_uuid_tree(struct btrfs_trans_handle *trans);
>>> +int create_inode_tree(struct btrfs_trans_handle *trans, u64 objectid);
>>> +
>>>  #endif
>>> diff --git a/mkfs/main.c b/mkfs/main.c
>>> index b6748f7fe853..ea3d1ae80e5e 100644
>>> --- a/mkfs/main.c
>>> +++ b/mkfs/main.c
>>> @@ -309,38 +309,6 @@ static int create_raid_groups(struct btrfs_trans_handle *trans,
>>>  	return ret;
>>>  }
>>>  
>>> -static int create_tree(struct btrfs_trans_handle *trans,
>>> -			struct btrfs_root *root, u64 objectid)
>>> -{
>>> -	struct btrfs_key location;
>>> -	struct btrfs_root_item root_item;
>>> -	struct extent_buffer *tmp;
>>> -	u8 uuid[BTRFS_UUID_SIZE] = {0};
>>> -	int ret;
>>> -
>>> -	ret = btrfs_copy_root(trans, root, root->node, &tmp, objectid);
>>> -	if (ret)
>>> -		return ret;
>>> -
>>> -	memcpy(&root_item, &root->root_item, sizeof(root_item));
>>> -	btrfs_set_root_bytenr(&root_item, tmp->start);
>>> -	btrfs_set_root_level(&root_item, btrfs_header_level(tmp));
>>> -	btrfs_set_root_generation(&root_item, trans->transid);
>>> -	/* clear uuid and o/ctime of source tree */
>>> -	memcpy(root_item.uuid, uuid, BTRFS_UUID_SIZE);
>>> -	btrfs_set_stack_timespec_sec(&root_item.otime, 0);
>>> -	btrfs_set_stack_timespec_sec(&root_item.ctime, 0);
>>> -	free_extent_buffer(tmp);
>>> -
>>> -	location.objectid = objectid;
>>> -	location.type = BTRFS_ROOT_ITEM_KEY;
>>> -	location.offset = 0;
>>> -	ret = btrfs_insert_root(trans, root->fs_info->tree_root,
>>> -				&location, &root_item);
>>> -
>>> -	return ret;
>>> -}
>>> -
>>>  static void print_usage(int ret)
>>>  {
>>>  	printf("Usage: mkfs.btrfs [options] dev [ dev ... ]\n");
>>> @@ -1203,13 +1171,13 @@ raid_groups:
>>>  		goto out;
>>>  	}
>>>  
>>> -	ret = create_tree(trans, root, BTRFS_DATA_RELOC_TREE_OBJECTID);
>>> +	ret = create_inode_tree(trans, BTRFS_DATA_RELOC_TREE_OBJECTID);
>>>  	if (ret) {
>>>  		error("unable to create data reloc tree: %d", ret);
>>>  		goto out;
>>>  	}
>>>  
>>> -	ret = create_tree(trans, root, BTRFS_UUID_TREE_OBJECTID);
>>> +	ret = create_uuid_tree(trans);
>>>  	if (ret)
>>>  		warning(
>>>  	"unable to create uuid tree, will be created after mount: %d", ret);
>>>

^ permalink raw reply	[flat|nested] 16+ messages in thread

end of thread, other threads:[~2019-01-03  4:51 UTC | newest]

Thread overview: 16+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-12-27  7:13 [PATCH for-4.20 0/3] Fix incorrectly created uuid tree Qu Wenruo
2018-12-27  7:13 ` [PATCH 1/3] btrfs-progs: uuid: Port kernel btrfs_uuid_tree_lookup() Qu Wenruo
2018-12-27  7:37   ` Su Yue
2018-12-27  7:31     ` Qu Wenruo
2018-12-27  7:13 ` [PATCH 2/3] btrfs-progs: uuid: Port btrfs_uuid_tree_add() function Qu Wenruo
2018-12-27  7:54   ` Su Yue
2018-12-27  7:13 ` [PATCH 3/3] btrfs-progs: Create uuid tree with proper contents Qu Wenruo
2018-12-27 11:28   ` Su Yue
2018-12-27 11:32     ` Qu Wenruo
2019-01-02 16:31     ` David Sterba
2019-01-02 23:46       ` Su Yue
2019-01-02  9:13   ` Nikolay Borisov
2019-01-02 10:00     ` Qu Wenruo
2019-01-02 10:07       ` Nikolay Borisov
2019-01-02 10:11         ` Qu Wenruo
2019-01-03  4:50       ` Qu Wenruo

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).