Skip to contentSkip to conversation

Add missing flags in the kernel.

PATCH Superseded Anand Jain 3 participants 8 messages Jan 8, 2018 Btrfs file system

v3 of 4 Superseded Latest is v4 →

lore
Share & tools
lore

Anand Jain

author
#0 lore raw

v3 cover Add missing flags in the kernel.

v2->v3:
Modify BTRFS_SUPER_FLAG_SUPP so that it would fail instead of warn.

v1->v2:
Fail to mount if BTRFS_SUPER_FLAG_CHANGING_FSID is set.

Following bits are already used in user land, so bring it to the kernel as well.

#define BTRFS_SUPER_FLAG_METADUMP_V2 (1ULL << 34)
#define BTRFS_SUPER_FLAG_CHANGING_FSID (1ULL << 35)

Anand Jain (3):
btrfs: fail mount when sb flag is not in BTRFS_SUPER_FLAG_SUPP
btrfs: define SUPER_FLAG_METADUMP_V2
btrfs: add support for SUPER_FLAG_CHANGING_FSID in btrfs.ko

 fs/btrfs/disk-io.c              | 6 ++++--
 include/uapi/linux/btrfs_tree.h | 2 ++
 2 files changed, 6 insertions(+), 2 deletions(-)
Signature · 1 line
2.15.0
author
#1 lore raw

PATCH v3 1/3 btrfs: fail mount when sb flag is not in BTRFS_SUPER_FLAG_SUPP

It appear from the original commit [1] that there isn't any design specific reason not to fail the mount instead of just warning. This patch will change it to fail.

[1]
commit 319e4d0661e5323c9f9945f0f8fb5905e5fe74c3
btrfs: Enhance super validation check

---
 fs/btrfs/disk-io.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)
fs/btrfs/disk-io.c +4 -2
index a69e5944dc08..b04da740a9a2 100644
@@ -3906,9 +3906,11 @@ static int btrfs_check_super_valid(struct btrfs_fs_info *fs_info)
 		btrfs_err(fs_info, "no valid FS found");
 		ret = -EINVAL;
 	}
-	if (btrfs_super_flags(sb) & ~BTRFS_SUPER_FLAG_SUPP)
-		btrfs_warn(fs_info, "unrecognized super flag: %llu",
+	if (btrfs_super_flags(sb) & ~BTRFS_SUPER_FLAG_SUPP) {
+		btrfs_err(fs_info, "unrecognized or unsupported super flag: %llu",
 				btrfs_super_flags(sb) & ~BTRFS_SUPER_FLAG_SUPP);
+		ret = -EINVAL;
+	}
 	if (btrfs_super_root_level(sb) >= BTRFS_MAX_LEVEL) {
 		btrfs_err(fs_info, "tree_root level too big: %d >= %d",
 				btrfs_super_root_level(sb), BTRFS_MAX_LEVEL);
Signature · 1 line
2.15.0
Reviewed-by on v3 1/3
#2 lore raw

Re: [PATCH 1/3] btrfs: fail mount when sb flag is not in BTRFS_SUPER_FLAG_SUPP

Quoted 10 lines · Anand Jain

It appear from the original commit [1] that there isn't any design specific reason not to fail the mount instead of just warning. This patch will change it to fail.

[1]
commit 319e4d0661e5323c9f9945f0f8fb5905e5fe74c3
btrfs: Enhance super validation check

The patch itself is good.

But it should be the last patch, to avoid breaking bisect.

With that fixed, feel free to add my tag:

Thanks,
Qu

Quoted 23 lines
---
 fs/btrfs/disk-io.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)
fs/btrfs/disk-io.c +4 -2
index a69e5944dc08..b04da740a9a2 100644
@@ -3906,9 +3906,11 @@ static int btrfs_check_super_valid(struct btrfs_fs_info *fs_info)
 		btrfs_err(fs_info, "no valid FS found");
 		ret = -EINVAL;
 	}
-	if (btrfs_super_flags(sb) & ~BTRFS_SUPER_FLAG_SUPP)
-		btrfs_warn(fs_info, "unrecognized super flag: %llu",
+	if (btrfs_super_flags(sb) & ~BTRFS_SUPER_FLAG_SUPP) {
+		btrfs_err(fs_info, "unrecognized or unsupported super flag: %llu",
 				btrfs_super_flags(sb) & ~BTRFS_SUPER_FLAG_SUPP);
+		ret = -EINVAL;
+	}
 	if (btrfs_super_root_level(sb) >= BTRFS_MAX_LEVEL) {
 		btrfs_err(fs_info, "tree_root level too big: %d >= %d",
 				btrfs_super_root_level(sb), BTRFS_MAX_LEVEL);
author
#3 lore raw

PATCH v3 2/3 btrfs: define SUPER_FLAG_METADUMP_V2

In reply to Anand Jain

btrfs-progs uses super flag bit BTRFS_SUPER_FLAG_METADUMP_V2 (1ULL << 34). So just define that in kernel so that we know its been used. This patch does not add it to BTRFS_SUPER_FLAG_SUPP yet.

---
 include/uapi/linux/btrfs_tree.h | 1 +
 1 file changed, 1 insertion(+)
include/uapi/linux/btrfs_tree.h +1 -0
index 6d6e5da51527..38ab0e06259a 100644
@@ -456,6 +456,7 @@ struct btrfs_free_space_header {
 
 #define BTRFS_SUPER_FLAG_SEEDING	(1ULL << 32)
 #define BTRFS_SUPER_FLAG_METADUMP	(1ULL << 33)
+#define BTRFS_SUPER_FLAG_METADUMP_V2	(1ULL << 34)
 
 
 /*
Signature · 1 line
2.15.0
#4 lore raw

Re: [PATCH 2/3] btrfs: define SUPER_FLAG_METADUMP_V2

Quoted 14 lines · Anand Jain

btrfs-progs uses super flag bit BTRFS_SUPER_FLAG_METADUMP_V2 (1ULL << 34). So just define that in kernel so that we know its been used. This patch does not add it to BTRFS_SUPER_FLAG_SUPP yet.

---
 include/uapi/linux/btrfs_tree.h | 1 +
 1 file changed, 1 insertion(+)
include/uapi/linux/btrfs_tree.h +0 -0
index 6d6e5da51527..38ab0e06259a 100644

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

Quoted 4 lines
include/uapi/linux/btrfs_tree.h +1 -0
@@ -456,6 +456,7 @@ struct btrfs_free_space_header {
 
 #define BTRFS_SUPER_FLAG_SEEDING	(1ULL << 32)
 #define BTRFS_SUPER_FLAG_METADUMP	(1ULL << 33)
+#define BTRFS_SUPER_FLAG_METADUMP_V2	(1ULL << 34)

Please also include this to BTRFS_SUPER_FLAG_SUPP.

It's quite common developers (at least myself) may try to mount a recovered btrfs image.

(That's also the reason why the patch should be put before the BTRFS_SUPER_FLAG_SUPP check patch)

Thanks,
Qu

Quoted 4 lines
include/uapi/linux/btrfs_tree.h +0 -0
 /*
 
#5 lore raw

Re: [PATCH 2/3] btrfs: define SUPER_FLAG_METADUMP_V2

Quoted 24 lines · Qu Wenruo
Quoted 14 lines · Anand Jain

btrfs-progs uses super flag bit BTRFS_SUPER_FLAG_METADUMP_V2 (1ULL << 34). So just define that in kernel so that we know its been used. This patch does not add it to BTRFS_SUPER_FLAG_SUPP yet.

---
 include/uapi/linux/btrfs_tree.h | 1 +
 1 file changed, 1 insertion(+)
include/uapi/linux/btrfs_tree.h +0 -0
index 6d6e5da51527..38ab0e06259a 100644

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

Quoted 4 lines
include/uapi/linux/btrfs_tree.h +1 -0
@@ -456,6 +456,7 @@ struct btrfs_free_space_header {
 
 #define BTRFS_SUPER_FLAG_SEEDING	(1ULL << 32)
 #define BTRFS_SUPER_FLAG_METADUMP	(1ULL << 33)
+#define BTRFS_SUPER_FLAG_METADUMP_V2	(1ULL << 34)

Please also include this to BTRFS_SUPER_FLAG_SUPP.

Quoted 5 lines

It's quite common developers (at least myself) may try to mount a recovered btrfs image.

(That's also the reason why the patch should be put before the BTRFS_SUPER_FLAG_SUPP check patch)

Agreed.

author
#6 lore raw

PATCH v3 3/3 btrfs: add support for SUPER_FLAG_CHANGING_FSID in btrfs.ko

In reply to Anand Jain

Userland sets SUPER_FLAG_CHANGING_FSID and resets it only when changing fsid is complete. Its not a good idea to mount the device anything in between, so this patch fails the mount if SB SUPER_FLAG_CHANGING_FSID is set. As we don't add SUPER_FLAG_CHANGING_FSID into BTRFS_SUPER_FLAG_SUPP list, so mount will fail if SUPER_FLAG_CHANGING_FSID is set in the user land.

---
 include/uapi/linux/btrfs_tree.h | 1 +
 1 file changed, 1 insertion(+)
include/uapi/linux/btrfs_tree.h +1 -0
index 38ab0e06259a..aff1356c2bb8 100644
@@ -457,6 +457,7 @@ struct btrfs_free_space_header {
 #define BTRFS_SUPER_FLAG_SEEDING	(1ULL << 32)
 #define BTRFS_SUPER_FLAG_METADUMP	(1ULL << 33)
 #define BTRFS_SUPER_FLAG_METADUMP_V2	(1ULL << 34)
+#define BTRFS_SUPER_FLAG_CHANGING_FSID	(1ULL << 35)
 
 
 /*
Signature · 1 line
2.15.0
Reviewed-by on v3 3/3
#7 lore raw

Re: [PATCH 3/3] btrfs: add support for SUPER_FLAG_CHANGING_FSID in btrfs.ko

Quoted 9 lines · Anand Jain

Userland sets SUPER_FLAG_CHANGING_FSID and resets it only when changing fsid is complete. Its not a good idea to mount the device anything in between, so this patch fails the mount if SB SUPER_FLAG_CHANGING_FSID is set. As we don't add SUPER_FLAG_CHANGING_FSID into BTRFS_SUPER_FLAG_SUPP list, so mount will fail if SUPER_FLAG_CHANGING_FSID is set in the user land.

Thanks,
Qu

Quoted 17 lines
---
 include/uapi/linux/btrfs_tree.h | 1 +
 1 file changed, 1 insertion(+)
include/uapi/linux/btrfs_tree.h +1 -0
index 38ab0e06259a..aff1356c2bb8 100644
@@ -457,6 +457,7 @@ struct btrfs_free_space_header {
 #define BTRFS_SUPER_FLAG_SEEDING	(1ULL << 32)
 #define BTRFS_SUPER_FLAG_METADUMP	(1ULL << 33)
 #define BTRFS_SUPER_FLAG_METADUMP_V2	(1ULL << 34)
+#define BTRFS_SUPER_FLAG_CHANGING_FSID	(1ULL << 35)
 
 
 /*