Skip to contentSkip to conversation

btrfs: Make btrfs_(set|clear)_header_flag return void

PATCH In review Qu Wenruo 5 participants 9 messages Mar 19, 2019 – Mar 20, 2019 Btrfs file system

lore
Share & tools
lore

Qu Wenruo

author
#0 lore raw

PATCH 1/2 btrfs: Make btrfs_(set|clear)_header_flag return void

From the introduce of btrfs_(set|clear)_header_flag, there is no usage of its return value.

So just make it return void.

---
 fs/btrfs/ctree.h | 6 ++----
 1 file changed, 2 insertions(+), 4 deletions(-)
fs/btrfs/ctree.h +2 -4
index b3642367a595..c03852d1aa34 100644
@@ -2163,18 +2163,16 @@ static inline int btrfs_header_flag(const struct extent_buffer *eb, u64 flag)
 	return (btrfs_header_flags(eb) & flag) == flag;
 }
 
-static inline int btrfs_set_header_flag(struct extent_buffer *eb, u64 flag)
+static inline void btrfs_set_header_flag(struct extent_buffer *eb, u64 flag)
 {
 	u64 flags = btrfs_header_flags(eb);
 	btrfs_set_header_flags(eb, flags | flag);
-	return (flags & flag) == flag;
 }
 
-static inline int btrfs_clear_header_flag(struct extent_buffer *eb, u64 flag)
+static inline void btrfs_clear_header_flag(struct extent_buffer *eb, u64 flag)
 {
 	u64 flags = btrfs_header_flags(eb);
 	btrfs_set_header_flags(eb, flags & ~flag);
-	return (flags & flag) == flag;
 }
 
 static inline int btrfs_header_backref_rev(const struct extent_buffer *eb)
Signature · 1 line
2.21.0
author
#1 lore raw

PATCH 2/2 btrfs: Introduce new tree block flag, BTRFS_HEADER_FLAG_LOG

This new tree block flag is to indicate the tree block belongs to a log tree.

For btrfs on-disk format, there are several different trees could use the same owner number:
- ordinary subvolume tree
- log tree for ordinary subvolume
- reloc tree for ordinary subvolume

It's possible to do the backref walk or use the content to determine the real owner of the tree block.
But backref walk is too expensive, content detection is not reliable.

So adding a new flag to explicitly show the owner of log tree.

Thankfully, tree-checker hasn't checked header flags yet, and there is no real user for this flag yet.
So we don't need to introduce any compatibility flag for this modification.

The introduction of this new flag makes tree block owner easier to distinguish, making life easier for:
- tree checker on log tree
Log tree could contain some items impossible for regular trees
- performance profiler
Now it's much easier to distinguish log tree.

---
 fs/btrfs/disk-io.c              | 1 +
 include/uapi/linux/btrfs_tree.h | 6 ++++++
 2 files changed, 7 insertions(+)
fs/btrfs/disk-io.c +1 -0
index 6fe9197f6ee4..8cffdb7789d8 100644
@@ -1362,6 +1362,7 @@ static struct btrfs_root *alloc_log_tree(struct btrfs_trans_handle *trans,
 		return ERR_CAST(leaf);
 	}
 
+	btrfs_set_header_flag(leaf, BTRFS_HEADER_FLAG_LOG);
 	root->node = leaf;
 
 	btrfs_mark_buffer_dirty(root->node);
include/uapi/linux/btrfs_tree.h +6 -0
index e974f4bb5378..d4ef80b702a0 100644
@@ -447,9 +447,15 @@ struct btrfs_free_space_header {
 	__le64 num_bitmaps;
 } __attribute__ ((__packed__));
 
+/* Tree/super has written to disk */
 #define BTRFS_HEADER_FLAG_WRITTEN	(1ULL << 0)
+
+/* Tree block which gets relocated */
 #define BTRFS_HEADER_FLAG_RELOC		(1ULL << 1)
 
+/* Tree block which belows to log tree */
+#define BTRFS_HEADER_FLAG_LOG		(1ULL << 2)
+
 /* Super block flags */
 /* Errors detected */
 #define BTRFS_SUPER_FLAG_ERROR		(1ULL << 2)
Signature · 1 line
2.21.0
#2 lore raw

Re: [PATCH 2/2] btrfs: Introduce new tree block flag, BTRFS_HEADER_FLAG_LOG

Quoted 38 lines · Qu Wenruo

This new tree block flag is to indicate the tree block belongs to a log tree.

For btrfs on-disk format, there are several different trees could use the same owner number:
- ordinary subvolume tree
- log tree for ordinary subvolume
- reloc tree for ordinary subvolume

It's possible to do the backref walk or use the content to determine the real owner of the tree block.
But backref walk is too expensive, content detection is not reliable.

So adding a new flag to explicitly show the owner of log tree.

Thankfully, tree-checker hasn't checked header flags yet, and there is no real user for this flag yet.
So we don't need to introduce any compatibility flag for this modification.

The introduction of this new flag makes tree block owner easier to distinguish, making life easier for:
- tree checker on log tree
Log tree could contain some items impossible for regular trees
- performance profiler
Now it's much easier to distinguish log tree.

---
 fs/btrfs/disk-io.c              | 1 +
 include/uapi/linux/btrfs_tree.h | 6 ++++++
 2 files changed, 7 insertions(+)
fs/btrfs/disk-io.c +0 -0
index 6fe9197f6ee4..8cffdb7789d8 100644

fs/btrfs/disk-io.c static struct btrfs_root *alloc_log_tree(struct btrfs_trans_handle *trans, · line 1366

Quoted 5 lines
fs/btrfs/disk-io.c +1 -0
@@ -1362,6 +1362,7 @@ static struct btrfs_root *alloc_log_tree(struct btrfs_trans_handle *trans,
 		return ERR_CAST(leaf);
 	}
 
+	btrfs_set_header_flag(leaf, BTRFS_HEADER_FLAG_LOG);
 	root->node = leaf;

Unless you are going to tag ALL extent buffers which are allocated as part of the log tree this patch is redundant, because even now you can detect the root of the log tree by simply checking for the root->root_key.objectid. Alternatively if you are going to be tagging all such blocks then those 2 patches need to be part of a larger series so the intended usage is more clear.

include/uapi/linux/btrfs_tree.h struct btrfs_free_space_header { · line 450

Quoted 11 lines
fs/btrfs/disk-io.c +0 -0
 	btrfs_mark_buffer_dirty(root->node);
include/uapi/linux/btrfs_tree.h +1 -0
index e974f4bb5378..d4ef80b702a0 100644
@@ -447,9 +447,15 @@ struct btrfs_free_space_header {
 	__le64 num_bitmaps;
 } __attribute__ ((__packed__));
 
+/* Tree/super has written to disk */

tree block has been correctly written to disk

include/uapi/linux/btrfs_tree.h struct btrfs_free_space_header { · line 453

Quoted 3 lines
include/uapi/linux/btrfs_tree.h +2 -0
 #define BTRFS_HEADER_FLAG_WRITTEN	(1ULL << 0)
+
+/* Tree block which gets relocated */

tree block belongs to a relocation tree

Quoted 9 lines
include/uapi/linux/btrfs_tree.h +3 -0
 #define BTRFS_HEADER_FLAG_RELOC		(1ULL << 1)
 
+/* Tree block which belows to log tree */
+#define BTRFS_HEADER_FLAG_LOG		(1ULL << 2)
+
 /* Super block flags */
 /* Errors detected */
 #define BTRFS_SUPER_FLAG_ERROR		(1ULL << 2)
#3 lore raw

Re: [PATCH 2/2] btrfs: Introduce new tree block flag, BTRFS_HEADER_FLAG_LOG

Quoted 44 lines · Nikolay Borisov
Quoted 41 lines · Qu Wenruo

This new tree block flag is to indicate the tree block belongs to a log tree.

For btrfs on-disk format, there are several different trees could use the same owner number:
- ordinary subvolume tree
- log tree for ordinary subvolume
- reloc tree for ordinary subvolume

It's possible to do the backref walk or use the content to determine the real owner of the tree block.
But backref walk is too expensive, content detection is not reliable.

So adding a new flag to explicitly show the owner of log tree.

Thankfully, tree-checker hasn't checked header flags yet, and there is no real user for this flag yet.
So we don't need to introduce any compatibility flag for this modification.

The introduction of this new flag makes tree block owner easier to distinguish, making life easier for:
- tree checker on log tree
Log tree could contain some items impossible for regular trees
- performance profiler
Now it's much easier to distinguish log tree.

---
 fs/btrfs/disk-io.c              | 1 +
 include/uapi/linux/btrfs_tree.h | 6 ++++++
 2 files changed, 7 insertions(+)
fs/btrfs/disk-io.c +0 -0
index 6fe9197f6ee4..8cffdb7789d8 100644
@@ -1362,6 +1362,7 @@ static struct btrfs_root *alloc_log_tree(struct btrfs_trans_handle *trans,
 		return ERR_CAST(leaf);
 	}
 
Quoted 7 lines

fs/btrfs/disk-io.c static struct btrfs_root *alloc_log_tree(struct btrfs_trans_handle *trans, · line 1366

Quoted 2 lines
fs/btrfs/disk-io.c +1 -0
+	btrfs_set_header_flag(leaf, BTRFS_HEADER_FLAG_LOG);
 	root->node = leaf;

Unless you are going to tag ALL extent buffers which are allocated as part of the log tree this patch is redundant, because even now you can detect the root of the log tree by simply checking for the root->root_key.objectid.

That is obvious.

As mentioned, the purpose is to detect owner for root->log_root. So it's to tag all log tree blocks.

Quoted 3 lines

Alternatively if you are going to be tagging
all such blocks then those 2 patches need to be part of a larger series so the intended usage is more clear.

The problem is, the larger part is not going to be a kernel patch.

Mostly btrfs-progs patch and 3rd-part kernel profiling tool.

Quoted 11 lines
Quoted 11 lines
fs/btrfs/disk-io.c +0 -0
 	btrfs_mark_buffer_dirty(root->node);
include/uapi/linux/btrfs_tree.h +0 -0
index e974f4bb5378..d4ef80b702a0 100644
@@ -447,9 +447,15 @@ struct btrfs_free_space_header {
 	__le64 num_bitmaps;
 } __attribute__ ((__packed__));
 
Quoted 2 lines

include/uapi/linux/btrfs_tree.h struct btrfs_free_space_header { · line 450

Quoted 1 line
include/uapi/linux/btrfs_tree.h +1 -0
+/* Tree/super has written to disk */

tree block has been correctly written to disk

The trick here is, super block reuses this flag.
So we still need to mention the super block part.

Thanks,
Qu

Quoted 16 lines

include/uapi/linux/btrfs_tree.h struct btrfs_free_space_header { · line 453

Quoted 4 lines
include/uapi/linux/btrfs_tree.h +2 -0
 #define BTRFS_HEADER_FLAG_WRITTEN	(1ULL << 0)
+
+/* Tree block which gets relocated */

tree block belongs to a relocation tree

Quoted 9 lines
include/uapi/linux/btrfs_tree.h +3 -0
 #define BTRFS_HEADER_FLAG_RELOC		(1ULL << 1)
 
+/* Tree block which belows to log tree */
+#define BTRFS_HEADER_FLAG_LOG		(1ULL << 2)
+
 /* Super block flags */
 /* Errors detected */
 #define BTRFS_SUPER_FLAG_ERROR		(1ULL << 2)
#4 lore raw

Re: [PATCH 2/2] btrfs: Introduce new tree block flag, BTRFS_HEADER_FLAG_LOG

In reply to Qu Wenruo
Quoted 20 lines · Qu Wenruo

This new tree block flag is to indicate the tree block belongs to a log tree.

For btrfs on-disk format, there are several different trees could use the same owner number:
- ordinary subvolume tree
- log tree for ordinary subvolume
- reloc tree for ordinary subvolume

It's possible to do the backref walk or use the content to determine the real owner of the tree block.
But backref walk is too expensive, content detection is not reliable.

So adding a new flag to explicitly show the owner of log tree.

Thankfully, tree-checker hasn't checked header flags yet, and there is no real user for this flag yet.
So we don't need to introduce any compatibility flag for this modification.

Quoted 8 lines

The introduction of this new flag makes tree block owner easier to distinguish, making life easier for:
- tree checker on log tree
Log tree could contain some items impossible for regular trees
- performance profiler
Now it's much easier to distinguish log tree.

Please discard this patch, it lacks header flags inherit part.

E.g. when splitting tree block, the higher level and brother tree block doesn't inherit the header bit.

I'll address the problem in next version.

Thanks,
Qu

Quoted 38 lines
---
 fs/btrfs/disk-io.c              | 1 +
 include/uapi/linux/btrfs_tree.h | 6 ++++++
 2 files changed, 7 insertions(+)
fs/btrfs/disk-io.c +1 -0
index 6fe9197f6ee4..8cffdb7789d8 100644
@@ -1362,6 +1362,7 @@ static struct btrfs_root *alloc_log_tree(struct btrfs_trans_handle *trans,
 		return ERR_CAST(leaf);
 	}
 
+	btrfs_set_header_flag(leaf, BTRFS_HEADER_FLAG_LOG);
 	root->node = leaf;
 
 	btrfs_mark_buffer_dirty(root->node);
include/uapi/linux/btrfs_tree.h +6 -0
index e974f4bb5378..d4ef80b702a0 100644
@@ -447,9 +447,15 @@ struct btrfs_free_space_header {
 	__le64 num_bitmaps;
 } __attribute__ ((__packed__));
 
+/* Tree/super has written to disk */
 #define BTRFS_HEADER_FLAG_WRITTEN	(1ULL << 0)
+
+/* Tree block which gets relocated */
 #define BTRFS_HEADER_FLAG_RELOC		(1ULL << 1)
 
+/* Tree block which belows to log tree */
+#define BTRFS_HEADER_FLAG_LOG		(1ULL << 2)
+
 /* Super block flags */
 /* Errors detected */
 #define BTRFS_SUPER_FLAG_ERROR		(1ULL << 2)
#5 lore raw

Re: [PATCH 2/2] btrfs: Introduce new tree block flag, BTRFS_HEADER_FLAG_LOG

In reply to Qu Wenruo
Quoted 13 lines · Qu Wenruo

This new tree block flag is to indicate the tree block belongs to a log tree.

For btrfs on-disk format, there are several different trees could use the same owner number:
- ordinary subvolume tree
- log tree for ordinary subvolume
- reloc tree for ordinary subvolume

It's possible to do the backref walk or use the content to determine the real owner of the tree block.
But backref walk is too expensive, content detection is not reliable.

Quoted 6 lines

So adding a new flag to explicitly show the owner of log tree.

Thankfully, tree-checker hasn't checked header flags yet, and there is no real user for this flag yet.
So we don't need to introduce any compatibility flag for this modification.

I think we can't simply skip the backward compatibility here, this is a change of on-disk format and at least we have to understand what can go wrong when the combinations of new/old kernel/fs are used.

Quoted 6 lines

The introduction of this new flag makes tree block owner easier to distinguish, making life easier for:
- tree checker on log tree
Log tree could contain some items impossible for regular trees
- performance profiler
Now it's much easier to distinguish log tree.

So is this for enhanced correctness or performance helper? I'd tend to skip the performance part for now, it's not convincing argument for the on-disk change.

And for the correctness I'd like more details, but the idea sounds good in general.

#6 lore raw

Re: [PATCH 2/2] btrfs: Introduce new tree block flag, BTRFS_HEADER_FLAG_LOG

Quoted 16 lines · David Sterba
Quoted 15 lines · Qu Wenruo

This new tree block flag is to indicate the tree block belongs to a log tree.

For btrfs on-disk format, there are several different trees could use the same owner number:
- ordinary subvolume tree
- log tree for ordinary subvolume
- reloc tree for ordinary subvolume

It's possible to do the backref walk or use the content to determine the real owner of the tree block.
But backref walk is too expensive, content detection is not reliable.

So adding a new flag to explicitly show the owner of log tree.

Quoted 8 lines
Quoted 4 lines

Thankfully, tree-checker hasn't checked header flags yet, and there is no real user for this flag yet.
So we don't need to introduce any compatibility flag for this modification.

I think we can't simply skip the backward compatibility here, this is a change of on-disk format and at least we have to understand what can go wrong when the combinations of new/old kernel/fs are used.

Currently since neither new fs nor old fs cares the unused bit in extent buffer headers, so it won't cause anything different.

But if newer fs is going to rely on this bit to do tree-checker, then we should introduce a COMPATIBLE bit.
Without that bit, kernel do no tagging, to be backward compatible.

Quoted 8 lines
Quoted 7 lines

The introduction of this new flag makes tree block owner easier to distinguish, making life easier for:
- tree checker on log tree
Log tree could contain some items impossible for regular trees
- performance profiler
Now it's much easier to distinguish log tree.

Quoted 6 lines

So is this for enhanced correctness or performance helper? I'd tend to skip the performance part for now, it's not convincing argument for the on-disk change.

And for the correctness I'd like more details, but the idea sounds good in general.

The chaos of eb->owner is, we have 3 root referring to one subvolid:
ordinary root
root->reloc_root
root->log_root

For ordinary root and reloc root, they're the completely the same content, so tree-checker needs no modification at all.

But for log_root, its content is completely different, it can contain things like EXTENT_CSUM.

With the ability to know if a tree block is a log tree one, we can finally implement owner based key type checker.
E.g. if we have an EXTENT_CSUM item in subvol 256 and it's not a log tree eb, then we know something is definitely wrong.

Thanks,
Qu

Reviewed-by on v1 1/2
#7 lore raw
In reply to Qu Wenruo
Quoted 6 lines · Qu Wenruo

From the introduce of btrfs_(set|clear)_header_flag, there is no usage of its return value.

So just make it return void.

Quoted 30 lines
---
 fs/btrfs/ctree.h | 6 ++----
 1 file changed, 2 insertions(+), 4 deletions(-)
fs/btrfs/ctree.h +2 -4
index b3642367a595..c03852d1aa34 100644
@@ -2163,18 +2163,16 @@ static inline int btrfs_header_flag(const struct extent_buffer *eb, u64 flag)
 	return (btrfs_header_flags(eb) & flag) == flag;
 }
 
-static inline int btrfs_set_header_flag(struct extent_buffer *eb, u64 flag)
+static inline void btrfs_set_header_flag(struct extent_buffer *eb, u64 flag)
 {
 	u64 flags = btrfs_header_flags(eb);
 	btrfs_set_header_flags(eb, flags | flag);
-	return (flags & flag) == flag;
 }
 
-static inline int btrfs_clear_header_flag(struct extent_buffer *eb, u64 flag)
+static inline void btrfs_clear_header_flag(struct extent_buffer *eb, u64 flag)
 {
 	u64 flags = btrfs_header_flags(eb);
 	btrfs_set_header_flags(eb, flags & ~flag);
-	return (flags & flag) == flag;
 }
 
 static inline int btrfs_header_backref_rev(const struct extent_buffer *eb)