Skip to contentSkip to conversation

patch "staging: erofs: add requirements field in superblock" added to staging-linus

PATCH [email protected] 1 participant 1 message Jun 17, 2019

Subsystems (2)
lore
Share & tools
lore

[email protected]

author maintainer Applied
#0 lore raw

This is a note to let you know that I've just added the patch titled

staging: erofs: add requirements field in superblock

to my staging git tree which can be found at
git://git.kernel.org/pub/scm/linux/kernel/git/gregkh/staging.git
in the staging-linus branch.

The patch will show up in the next release of the linux-next tree (usually sometime within the next 24 hours during the week.)

The patch will hopefully also be merged in Linus's tree for the next -rc kernel release.

If you have any questions about this process, please let me know.

From 5efe5137f05bbb4688890620934538c005e7d1d6 Mon Sep 17 00:00:00 2001
From: Gao Xiang <[email protected]>
Date: Thu, 13 Jun 2019 16:35:41 +0800
Subject: staging: erofs: add requirements field in superblock

There are some backward incompatible features pending for months, mainly due to on-disk format expensions.

However, we should ensure that it cannot be mounted with old kernels. Otherwise, it will causes unexpected behaviors.

Fixes ba2b77a82022 ("staging: erofs: add super block operations")
Cc <[email protected]> # 4.19+
---
 drivers/staging/erofs/erofs_fs.h | 13 ++++++++++---
 drivers/staging/erofs/internal.h |  2 ++
 drivers/staging/erofs/super.c    | 19 +++++++++++++++++++
 3 files changed, 31 insertions(+), 3 deletions(-)
drivers/staging/erofs/erofs_fs.h +10 -3
index fa52898df006..8ddb2b3e7d39 100644
@@ -17,10 +17,16 @@
 #define EROFS_SUPER_MAGIC_V1    0xE0F5E1E2
 #define EROFS_SUPER_OFFSET      1024
 
+/*
+ * Any bits that aren't in EROFS_ALL_REQUIREMENTS should be
+ * incompatible with this kernel version.
+ */
+#define EROFS_ALL_REQUIREMENTS  0
+
 struct erofs_super_block {
 /*  0 */__le32 magic;           /* in the little endian */
 /*  4 */__le32 checksum;        /* crc32c(super_block) */
-/*  8 */__le32 features;
+/*  8 */__le32 features;        /* (aka. feature_compat) */
 /* 12 */__u8 blkszbits;         /* support block_size == PAGE_SIZE only */
 /* 13 */__u8 reserved;
 
@@ -34,9 +40,10 @@ struct erofs_super_block {
 /* 44 */__le32 xattr_blkaddr;
 /* 48 */__u8 uuid[16];          /* 128-bit uuid for volume */
 /* 64 */__u8 volume_name[16];   /* volume name */
+/* 80 */__le32 requirements;    /* (aka. feature_incompat) */
 
-/* 80 */__u8 reserved2[48];     /* 128 bytes */
-} __packed;
+/* 84 */__u8 reserved2[44];
+} __packed;                     /* 128 bytes */
 
 /*
  * erofs inode data mapping:
drivers/staging/erofs/internal.h +2 -0
index c47778b3fabd..382258fc124d 100644
@@ -115,6 +115,8 @@ struct erofs_sb_info {
 
 	u8 uuid[16];                    /* 128-bit uuid for volume */
 	u8 volume_name[16];             /* volume name */
+	u32 requirements;
+
 	char *dev_name;
 
 	unsigned int mount_opt;
drivers/staging/erofs/super.c +19 -0
index f580d4ef77a1..cadbcc11702a 100644
@@ -71,6 +71,22 @@ static void free_inode(struct inode *inode)
 	kmem_cache_free(erofs_inode_cachep, vi);
 }
 
+static bool check_layout_compatibility(struct super_block *sb,
+				       struct erofs_super_block *layout)
+{
+	const unsigned int requirements = le32_to_cpu(layout->requirements);
+
+	EROFS_SB(sb)->requirements = requirements;
+
+	/* check if current kernel meets all mandatory requirements */
+	if (requirements & (~EROFS_ALL_REQUIREMENTS)) {
+		errln("unidentified requirements %x, please upgrade kernel version",
+		      requirements & ~EROFS_ALL_REQUIREMENTS);
+		return false;
+	}
+	return true;
+}
+
 static int superblock_read(struct super_block *sb)
 {
 	struct erofs_sb_info *sbi;
@@ -104,6 +120,9 @@ static int superblock_read(struct super_block *sb)
 		goto out;
 	}
 
+	if (!check_layout_compatibility(sb, layout))
+		goto out;
+
 	sbi->blocks = le32_to_cpu(layout->blocks);
 	sbi->meta_blkaddr = le32_to_cpu(layout->meta_blkaddr);
 #ifdef CONFIG_EROFS_FS_XATTR
Signature · 1 line
2.22.0