Skip to contentSkip to conversation

btrfs-progs: add BTRFS_DEV_ITEMS_OBJECTID in comment in print-tree

PATCH Superseded Anand Jain 4 participants 10 messages Aug 28, 2019 – Aug 29, 2019 Btrfs file system

lore
Share & tools
lore

Anand Jain

author
#0 lore raw

PATCH 1/2 btrfs-progs: add BTRFS_DEV_ITEMS_OBJECTID in comment in print-tree

So when searching for BTRFS_DEV_ITEMS_OBJECTID it hits. Albeit it is defined same as BTRFS_ROOT_TREE_OBJECTID.

---
 print-tree.c | 1 +
 1 file changed, 1 insertion(+)
print-tree.c +1 -0
index b31e515f8989..5832f3089e3d 100644
@@ -704,6 +704,7 @@ void print_objectid(FILE *stream, u64 objectid, u8 type)
 	}
 
 	switch (objectid) {
+	/* BTRFS_DEV_ITEMS_OBJECTID */
 	case BTRFS_ROOT_TREE_OBJECTID:
 		if (type == BTRFS_DEV_ITEM_KEY)
 			fprintf(stream, "DEV_ITEMS");
Signature · 1 line
2.21.0 (Apple Git-120)
author
#1 lore raw

PATCH 2/2 btrfs-progs: print-tree add missing DEV_STATS

Add missing BTRFS_DEV_STATS_OBJECTID into the print-tree.

before:
item 0 key (0 PERSISTENT_ITEM 1) itemoff 16243 itemsize 40
persistent item objectid 0 offset 1
after:
item 0 key (DEV_STATS PERSISTENT_ITEM 1) itemoff 16243 itemsize 40
persistent item objectid DEV_STATS offset 1

---
 print-tree.c | 6 ++++++
 1 file changed, 6 insertions(+)
print-tree.c +6 -0
index 5832f3089e3d..0f9b3a8f0f83 100644
@@ -689,6 +689,12 @@ void print_key_type(FILE *stream, u64 objectid, u8 type)
 void print_objectid(FILE *stream, u64 objectid, u8 type)
 {
 	switch (type) {
+	case BTRFS_PERSISTENT_ITEM_KEY:
+		if (objectid == BTRFS_DEV_STATS_OBJECTID)
+			fprintf(stream, "DEV_STATS");
+		else
+			fprintf(stream, "%llu", (unsigned long long)objectid);
+		return;
 	case BTRFS_DEV_EXTENT_KEY:
 		/* device id */
 		fprintf(stream, "%llu", (unsigned long long)objectid);
Signature · 1 line
2.21.0 (Apple Git-120)
#2 lore raw
In reply to Anand Jain
Quoted 13 lines · Anand Jain

So when searching for BTRFS_DEV_ITEMS_OBJECTID it hits. Albeit it is defined same as BTRFS_ROOT_TREE_OBJECTID.

---
 print-tree.c | 1 +
 1 file changed, 1 insertion(+)
print-tree.c +0 -0
index b31e515f8989..5832f3089e3d 100644

print-tree.c void print_objectid(FILE *stream, u64 objectid, u8 type) · line 707

Quoted 4 lines
print-tree.c +1 -0
@@ -704,6 +704,7 @@ void print_objectid(FILE *stream, u64 objectid, u8 type)
 	}
 
 	switch (objectid) {
+	/* BTRFS_DEV_ITEMS_OBJECTID */

That comment looks really cryptic to someone just looking at the code. Adding case BTRFS_DEV_ITEMS_OBJECTID: is better.

Quoted 4 lines
print-tree.c +0 -0
 	case BTRFS_ROOT_TREE_OBJECTID:
 		if (type == BTRFS_DEV_ITEM_KEY)
 			fprintf(stream, "DEV_ITEMS");
#3 lore raw
Quoted 18 lines · Nikolay Borisov
Quoted 15 lines · Anand Jain

So when searching for BTRFS_DEV_ITEMS_OBJECTID it hits. Albeit it is defined same as BTRFS_ROOT_TREE_OBJECTID.

---
 print-tree.c | 1 +
 1 file changed, 1 insertion(+)
print-tree.c +0 -0
index b31e515f8989..5832f3089e3d 100644
@@ -704,6 +704,7 @@ void print_objectid(FILE *stream, u64 objectid, u8 type)
 	}
 
Quoted 7 lines

print-tree.c void print_objectid(FILE *stream, u64 objectid, u8 type) · line 707

Quoted 2 lines
print-tree.c +1 -0
 	switch (objectid) {
+	/* BTRFS_DEV_ITEMS_OBJECTID */

That comment looks really cryptic to someone just looking at the code. Adding case BTRFS_DEV_ITEMS_OBJECTID: is better.

Quoted 1 line
print-tree.c +0 -0
 	case BTRFS_ROOT_TREE_OBJECTID:

Both constants have the same value so they can't be in one switch, but yeah the comment should be a bit more verbose, just the constant name is bringing more questions than answers.

author
#4 lore raw
Quoted 29 lines · David Sterba
Quoted 23 lines · Nikolay Borisov
Quoted 13 lines · Anand Jain

So when searching for BTRFS_DEV_ITEMS_OBJECTID it hits. Albeit it is defined same as BTRFS_ROOT_TREE_OBJECTID.

---
print-tree.c | 1 +

1 file changed, 1 insertion(+)
print-tree.c +0 -0
index b31e515f8989..5832f3089e3d 100644

print-tree.c void print_objectid(FILE *stream, u64 objectid, u8 type) · line 707

Quoted 4 lines
print-tree.c +1 -0
@@ -704,6 +704,7 @@ void print_objectid(FILE *stream, u64 objectid, u8 type)
 	}
 
 	switch (objectid) {
+	/* BTRFS_DEV_ITEMS_OBJECTID */

That comment looks really cryptic to someone just looking at the code. Adding case BTRFS_DEV_ITEMS_OBJECTID: is better.

Quoted 5 lines
Quoted 1 line

print-tree.c void print_objectid(FILE *stream, u64 objectid, u8 type) · line 708

Quoted 1 line
print-tree.c +0 -0
 	case BTRFS_ROOT_TREE_OBJECTID:

Both constants have the same value so they can't be in one switch, but yeah the comment should be a bit more verbose, just the constant name is bringing more questions than answers.

Oh. Hmm. Let me try.

Thanks, Anand

author
#5 lore raw
In reply to Nikolay Borisov
Quoted 22 lines · Nikolay Borisov
Quoted 15 lines · Anand Jain

So when searching for BTRFS_DEV_ITEMS_OBJECTID it hits. Albeit it is defined same as BTRFS_ROOT_TREE_OBJECTID.

---
print-tree.c | 1 +

1 file changed, 1 insertion(+)
print-tree.c +0 -0
index b31e515f8989..5832f3089e3d 100644
@@ -704,6 +704,7 @@ void print_objectid(FILE *stream, u64 objectid, u8 type)
 	}
 
Quoted 6 lines

print-tree.c void print_objectid(FILE *stream, u64 objectid, u8 type) · line 707

Quoted 2 lines
print-tree.c +1 -0
 	switch (objectid) {
+	/* BTRFS_DEV_ITEMS_OBJECTID */

That comment looks really cryptic to someone just looking at the code. Adding case BTRFS_DEV_ITEMS_OBJECTID: is better.

Both of them defined with the same value (we find which object by type). So only one of it can be in the case.

#define BTRFS_DEV_ITEMS_OBJECTID 1ULL
::
#define BTRFS_ROOT_TREE_OBJECTID 1ULL

Thanks, Anand

Quoted 4 lines
Quoted 4 lines
print-tree.c +0 -0
 	case BTRFS_ROOT_TREE_OBJECTID:
 		if (type == BTRFS_DEV_ITEM_KEY)
 			fprintf(stream, "DEV_ITEMS");
author
#6 lore raw

PATCH v2 1/2 btrfs-progs: add BTRFS_DEV_ITEMS_OBJECTID in comment in print-tree

In reply to Anand Jain

So when searching for BTRFS_DEV_ITEMS_OBJECTID, it hits, albeit it is defined same as BTRFS_ROOT_TREE_OBJECTID.

---
v1->v2: Improve comment.

 print-tree.c | 5 +++++
 1 file changed, 5 insertions(+)
print-tree.c +5 -0
index b31e515f8989..b1c59d776547 100644
@@ -705,6 +705,11 @@ void print_objectid(FILE *stream, u64 objectid, u8 type)
 
 	switch (objectid) {
 	case BTRFS_ROOT_TREE_OBJECTID:
+		/*
+		 * BTRFS_ROOT_TREE_OBJECTID and BTRFS_DEV_ITEMS_OBJECTID are
+		 * defined with the same value of 1ULL, distinguish them by
+		 * checking the type.
+		 */
 		if (type == BTRFS_DEV_ITEM_KEY)
 			fprintf(stream, "DEV_ITEMS");
 		else
Signature · 1 line
2.21.0 (Apple Git-120)
Reviewed-by on v2 1/2
#7 lore raw
Quoted 4 lines · Anand Jain

So when searching for BTRFS_DEV_ITEMS_OBJECTID, it hits, albeit it is defined same as BTRFS_ROOT_TREE_OBJECTID.

Quoted 11 lines

---
v1->v2: Improve comment.

 print-tree.c | 5 +++++
 1 file changed, 5 insertions(+)
print-tree.c +0 -0
index b31e515f8989..b1c59d776547 100644

print-tree.c void print_objectid(FILE *stream, u64 objectid, u8 type) · line 712

Quoted 8 lines
print-tree.c +5 -0
@@ -705,6 +705,11 @@ void print_objectid(FILE *stream, u64 objectid, u8 type)
 
 	switch (objectid) {
 	case BTRFS_ROOT_TREE_OBJECTID:
+		/*
+		 * BTRFS_ROOT_TREE_OBJECTID and BTRFS_DEV_ITEMS_OBJECTID are
+		 * defined with the same value of 1ULL, distinguish them by
+		 * checking the type.
+		 */

Oh, some bad design from the very beginning of btrfs.

Any other duplicated objectid?

Thanks,
Qu

Quoted 4 lines
print-tree.c +0 -0
 		if (type == BTRFS_DEV_ITEM_KEY)
 			fprintf(stream, "DEV_ITEMS");
 		else
#8 lore raw
Quoted 22 lines · Qu Wenruo
Quoted 4 lines · Anand Jain

So when searching for BTRFS_DEV_ITEMS_OBJECTID, it hits, albeit it is defined same as BTRFS_ROOT_TREE_OBJECTID.

Quoted 12 lines

---
v1->v2: Improve comment.

 print-tree.c | 5 +++++
 1 file changed, 5 insertions(+)
print-tree.c +0 -0
index b31e515f8989..b1c59d776547 100644
@@ -705,6 +705,11 @@ void print_objectid(FILE *stream, u64 objectid, u8 type)
 
Quoted 9 lines

print-tree.c void print_objectid(FILE *stream, u64 objectid, u8 type) · line 712

Quoted 7 lines
print-tree.c +5 -0
 	switch (objectid) {
 	case BTRFS_ROOT_TREE_OBJECTID:
+		/*
+		 * BTRFS_ROOT_TREE_OBJECTID and BTRFS_DEV_ITEMS_OBJECTID are
+		 * defined with the same value of 1ULL, distinguish them by
+		 * checking the type.
+		 */

Oh, some bad design from the very beginning of btrfs.

No, why bad design? Objectids need to be unique inside one group, like tree ids, but are otherwise independent and must be interpreted together with the key type. Which is exactly what print_objectid does.