Skip to contentSkip to conversation

erofs: fix erofs_module_init & exit

PATCH New Gao Xiang 3 participants 8 messages Jul 5, 2018 – Jul 6, 2018 EROFS file system

lore
Share & tools
lore

Gao Xiang

author
#0 lore raw

PATCH 1/1 erofs: fix erofs_module_init & exit

This patch adds missing parts and EROFS ondisk
layout check as well.

Signed-off-by Gao Xiang <gaoxiang25 at huawei.com>
---
 fs/erofs/erofs_fs.h | 13 +++++++++++++
 fs/erofs/super.c    | 28 +++++++++++++++++++++-------
 2 files changed, 34 insertions(+), 7 deletions(-)
fs/erofs/erofs_fs.h +13 -0
index ed943d4..0dbf08d 100644
@@ -253,5 +253,18 @@ enum {
 
 #define EROFS_NAME_LEN      255
 
+/* check the EROFS on-disk layout strictly at compile time */
+static inline void erofs_check_ondisk_layout(void)
+{
+	BUILD_BUG_ON(sizeof(struct erofs_super_block) != 128);
+	BUILD_BUG_ON(sizeof(struct erofs_inode_v1) != 32);
+	BUILD_BUG_ON(sizeof(struct erofs_inode_v2) != 64);
+	BUILD_BUG_ON(sizeof(struct erofs_xattr_ibody_header) != 12);
+	BUILD_BUG_ON(sizeof(struct erofs_xattr_entry) != 4);
+	BUILD_BUG_ON(sizeof(struct erofs_extent_header) != 16);
+	BUILD_BUG_ON(sizeof(struct erofs_decompressed_index_vle) != 8);
+	BUILD_BUG_ON(sizeof(struct erofs_dirent) != 12);
+}
+
 #endif
 
fs/erofs/super.c +21 -7
index a1826b9..d104d88 100644
@@ -37,6 +37,12 @@ static int erofs_init_inode_cache(void)
 	return erofs_inode_cachep != NULL ? 0 : -ENOMEM;
 }
 
+static void erofs_exit_inode_cache(void)
+{
+	BUG_ON(erofs_inode_cachep == NULL);
+	kmem_cache_destroy(erofs_inode_cachep);
+}
+
 static struct inode *alloc_inode(struct super_block *sb)
 {
 	struct erofs_vnode *vi =
@@ -398,22 +404,30 @@ int __init erofs_module_init(void)
 {
 	int err;
 
+	erofs_check_ondisk_layout();
 	infoln("Initializing erofs " EROFS_VERSION);
 
 	err = erofs_init_inode_cache();
-	if (!err) {
-		err = register_filesystem(&erofs_fs_type);
-		if (!err) {
-			infoln("Successfully to initialize erofs");
-			return 0;
-		}
-	}
+	if (err)
+		goto icache_err;
+
+	err = register_filesystem(&erofs_fs_type);
+	if (err)
+		goto fs_err;
+
+	infoln("Successfully to initialize erofs");
+	return 0;
+
+fs_err:
+	erofs_exit_inode_cache();
+icache_err:
 	return err;
 }
 
 void __exit erofs_module_exit(void)
 {
 	unregister_filesystem(&erofs_fs_type);
+	erofs_exit_inode_cache();
 	infoln("Successfully finalize erofs");
 }
 
Signature · 1 line
1.9.1
maintainer
#1 lore raw

PATCH 1/1 erofs: fix erofs_module_init & exit

Hi Xiang,

Quoted 18 lines · Gao Xiang

This patch adds missing parts and EROFS ondisk
layout check as well.

Signed-off-by Gao Xiang <gaoxiang25 at huawei.com>
---
 fs/erofs/erofs_fs.h | 13 +++++++++++++
 fs/erofs/super.c    | 28 +++++++++++++++++++++-------
 2 files changed, 34 insertions(+), 7 deletions(-)
fs/erofs/erofs_fs.h +1 -0
index ed943d4..0dbf08d 100644
@@ -253,5 +253,18 @@ enum {
 
 #define EROFS_NAME_LEN      255
 
+/* check the EROFS on-disk layout strictly at compile time */

fs/erofs/erofs_fs.h enum { · line 266

Quoted 10 lines
fs/erofs/erofs_fs.h +10 -0
+static inline void erofs_check_ondisk_layout(void)
+{
+	BUILD_BUG_ON(sizeof(struct erofs_super_block) != 128);
+	BUILD_BUG_ON(sizeof(struct erofs_inode_v1) != 32);
+	BUILD_BUG_ON(sizeof(struct erofs_inode_v2) != 64);
+	BUILD_BUG_ON(sizeof(struct erofs_xattr_ibody_header) != 12);
+	BUILD_BUG_ON(sizeof(struct erofs_xattr_entry) != 4);
+	BUILD_BUG_ON(sizeof(struct erofs_extent_header) != 16);
+	BUILD_BUG_ON(sizeof(struct erofs_decompressed_index_vle) != 8);
+	BUILD_BUG_ON(sizeof(struct erofs_dirent) != 12);

We'd better define some macros include above constants.

Other parts look good to me.

Thanks,

Quoted 60 lines
fs/erofs/erofs_fs.h +2 -0
+}
+
 #endif
 
fs/erofs/super.c +21 -7
index a1826b9..d104d88 100644
@@ -37,6 +37,12 @@ static int erofs_init_inode_cache(void)
 	return erofs_inode_cachep != NULL ? 0 : -ENOMEM;
 }
 
+static void erofs_exit_inode_cache(void)
+{
+	BUG_ON(erofs_inode_cachep == NULL);
+	kmem_cache_destroy(erofs_inode_cachep);
+}
+
 static struct inode *alloc_inode(struct super_block *sb)
 {
 	struct erofs_vnode *vi =
@@ -398,22 +404,30 @@ int __init erofs_module_init(void)
 {
 	int err;
 
+	erofs_check_ondisk_layout();
 	infoln("Initializing erofs " EROFS_VERSION);
 
 	err = erofs_init_inode_cache();
-	if (!err) {
-		err = register_filesystem(&erofs_fs_type);
-		if (!err) {
-			infoln("Successfully to initialize erofs");
-			return 0;
-		}
-	}
+	if (err)
+		goto icache_err;
+
+	err = register_filesystem(&erofs_fs_type);
+	if (err)
+		goto fs_err;
+
+	infoln("Successfully to initialize erofs");
+	return 0;
+
+fs_err:
+	erofs_exit_inode_cache();
+icache_err:
 	return err;
 }
 
 void __exit erofs_module_exit(void)
 {
 	unregister_filesystem(&erofs_fs_type);
+	erofs_exit_inode_cache();
 	infoln("Successfully finalize erofs");
 }
 
author
#2 lore raw

PATCH 1/1 erofs: fix erofs_module_init & exit

Hi Chao,

Quoted 34 lines · Chao Yu

Hi Xiang,

Quoted 18 lines · Gao Xiang

This patch adds missing parts and EROFS ondisk
layout check as well.

Signed-off-by Gao Xiang <gaoxiang25 at huawei.com>
---
 fs/erofs/erofs_fs.h | 13 +++++++++++++
 fs/erofs/super.c    | 28 +++++++++++++++++++++-------
 2 files changed, 34 insertions(+), 7 deletions(-)
fs/erofs/erofs_fs.h +1 -0
index ed943d4..0dbf08d 100644
@@ -253,5 +253,18 @@ enum {
 
 #define EROFS_NAME_LEN      255
 
+/* check the EROFS on-disk layout strictly at compile time */

fs/erofs/erofs_fs.h enum { · line 266

Quoted 10 lines
fs/erofs/erofs_fs.h +10 -0
+static inline void erofs_check_ondisk_layout(void)
+{
+	BUILD_BUG_ON(sizeof(struct erofs_super_block) != 128);
+	BUILD_BUG_ON(sizeof(struct erofs_inode_v1) != 32);
+	BUILD_BUG_ON(sizeof(struct erofs_inode_v2) != 64);
+	BUILD_BUG_ON(sizeof(struct erofs_xattr_ibody_header) != 12);
+	BUILD_BUG_ON(sizeof(struct erofs_xattr_entry) != 4);
+	BUILD_BUG_ON(sizeof(struct erofs_extent_header) != 16);
+	BUILD_BUG_ON(sizeof(struct erofs_decompressed_index_vle) != 8);
+	BUILD_BUG_ON(sizeof(struct erofs_dirent) != 12);

We'd better define some macros include above constants.

Quoted 4 lines

Other parts look good to me.

Thanks,

I was also thinking of wrapping in macros, but I thought over again, it seems not too necessary because:

1) the above code is already well straight-forward to view and change if needed...

BUILD_BUG_ON(sizeof(struct erofs_super_block) != 128);
<==> #define EROFS_SUPER_BLOCK_ONDISK_SIZE 128

EROFS_SUPER_BLOCK_ONDISK_SIZE is not really needed since we could use sizeof(struct erofs_super_block) directly in code.

2) Besides, I also observed the other file systems, such as xfs, sysv, minix, and ubifs, eg.

fs/jffs2/super.c:
366 /* Paranoia checks for on-medium structures. If we ask GCC

367            to pack them with __attribute__((packed)) then it _also_
368            assumes that they're not aligned -- so it emits crappy
369            code on some architectures. Ideally we want an attribute
370            which means just 'no padding', without the alignment
371            thing. But GCC doesn't have that -- we have to just
372            hope the structs are the right sizes, instead. */
373         BUILD_BUG_ON(sizeof(struct jffs2_unknown_node) != 12);
374         BUILD_BUG_ON(sizeof(struct jffs2_raw_dirent) != 40);
375         BUILD_BUG_ON(sizeof(struct jffs2_raw_inode) != 68);
376         BUILD_BUG_ON(sizeof(struct jffs2_raw_summary) != 32);

fs/minix/inode.c:
174 BUILD_BUG_ON(32 != sizeof (struct minix_inode));
175 BUILD_BUG_ON(64 != sizeof(struct minix2_inode));

fs/ubifs/super.c:

359         BUILD_BUG_ON(1024 != sizeof (struct xenix_super_block));
360         BUILD_BUG_ON(512 != sizeof (struct sysv4_super_block));
361         BUILD_BUG_ON(512 != sizeof (struct sysv2_super_block));
362         BUILD_BUG_ON(500 != sizeof (struct coh_super_block));
363         BUILD_BUG_ON(64 != sizeof (struct sysv_inode));

fs/ubifs/super.c

2211         BUILD_BUG_ON(UBIFS_MAX_NODE_SZ      & 7);
2212         BUILD_BUG_ON(MIN_WRITE_SZ           & 7);
2213
2214         /* Check min. node size */
2215         BUILD_BUG_ON(UBIFS_INO_NODE_SZ  < MIN_WRITE_SZ);
2216         BUILD_BUG_ON(UBIFS_DENT_NODE_SZ < MIN_WRITE_SZ);
2217         BUILD_BUG_ON(UBIFS_XENT_NODE_SZ < MIN_WRITE_SZ);
2218         BUILD_BUG_ON(UBIFS_TRUN_NODE_SZ < MIN_WRITE_SZ);
2219
2220         BUILD_BUG_ON(UBIFS_MAX_DENT_NODE_SZ > UBIFS_MAX_NODE_SZ);
2221         BUILD_BUG_ON(UBIFS_MAX_XENT_NODE_SZ > UBIFS_MAX_NODE_SZ);
2222         BUILD_BUG_ON(UBIFS_MAX_DATA_NODE_SZ > UBIFS_MAX_NODE_SZ);
2223         BUILD_BUG_ON(UBIFS_MAX_INO_NODE_SZ  > UBIFS_MAX_NODE_SZ);
2224
2225         /* Defined node sizes */
2226         BUILD_BUG_ON(UBIFS_SB_NODE_SZ  != 4096);
2227         BUILD_BUG_ON(UBIFS_MST_NODE_SZ != 512);
2228         BUILD_BUG_ON(UBIFS_INO_NODE_SZ != 160);
2229         BUILD_BUG_ON(UBIFS_REF_NODE_SZ != 64);

how do you think? :) If you think it is necessary, I can change into marcos immediately~

Thanks,
Gao Xiang

Quoted 60 lines
Quoted 60 lines
fs/erofs/erofs_fs.h +2 -0
+}
+
 #endif
 
fs/erofs/super.c +21 -7
index a1826b9..d104d88 100644
@@ -37,6 +37,12 @@ static int erofs_init_inode_cache(void)
 	return erofs_inode_cachep != NULL ? 0 : -ENOMEM;
 }
 
+static void erofs_exit_inode_cache(void)
+{
+	BUG_ON(erofs_inode_cachep == NULL);
+	kmem_cache_destroy(erofs_inode_cachep);
+}
+
 static struct inode *alloc_inode(struct super_block *sb)
 {
 	struct erofs_vnode *vi =
@@ -398,22 +404,30 @@ int __init erofs_module_init(void)
 {
 	int err;
 
+	erofs_check_ondisk_layout();
 	infoln("Initializing erofs " EROFS_VERSION);
 
 	err = erofs_init_inode_cache();
-	if (!err) {
-		err = register_filesystem(&erofs_fs_type);
-		if (!err) {
-			infoln("Successfully to initialize erofs");
-			return 0;
-		}
-	}
+	if (err)
+		goto icache_err;
+
+	err = register_filesystem(&erofs_fs_type);
+	if (err)
+		goto fs_err;
+
+	infoln("Successfully to initialize erofs");
+	return 0;
+
+fs_err:
+	erofs_exit_inode_cache();
+icache_err:
 	return err;
 }
 
 void __exit erofs_module_exit(void)
 {
 	unregister_filesystem(&erofs_fs_type);
+	erofs_exit_inode_cache();
 	infoln("Successfully finalize erofs");
 }
 
#3 lore raw

PATCH 1/1 erofs: fix erofs_module_init & exit

Hi Xiang,

Quoted 100 lines · Gao Xiang

Hi Chao,

Quoted 34 lines · Chao Yu

Hi Xiang,

Quoted 18 lines · Gao Xiang

This patch adds missing parts and EROFS ondisk
layout check as well.

Signed-off-by Gao Xiang <gaoxiang25 at huawei.com>
---
 fs/erofs/erofs_fs.h | 13 +++++++++++++
 fs/erofs/super.c    | 28 +++++++++++++++++++++-------
 2 files changed, 34 insertions(+), 7 deletions(-)
fs/erofs/erofs_fs.h +1 -0
index ed943d4..0dbf08d 100644
@@ -253,5 +253,18 @@ enum {
 
 #define EROFS_NAME_LEN      255
 
+/* check the EROFS on-disk layout strictly at compile time */

fs/erofs/erofs_fs.h enum { · line 266

Quoted 10 lines
fs/erofs/erofs_fs.h +10 -0
+static inline void erofs_check_ondisk_layout(void)
+{
+	BUILD_BUG_ON(sizeof(struct erofs_super_block) != 128);
+	BUILD_BUG_ON(sizeof(struct erofs_inode_v1) != 32);
+	BUILD_BUG_ON(sizeof(struct erofs_inode_v2) != 64);
+	BUILD_BUG_ON(sizeof(struct erofs_xattr_ibody_header) != 12);
+	BUILD_BUG_ON(sizeof(struct erofs_xattr_entry) != 4);
+	BUILD_BUG_ON(sizeof(struct erofs_extent_header) != 16);
+	BUILD_BUG_ON(sizeof(struct erofs_decompressed_index_vle) != 8);
+	BUILD_BUG_ON(sizeof(struct erofs_dirent) != 12);

We'd better define some macros include above constants.

Quoted 4 lines

Other parts look good to me.

Thanks,

I was also thinking of wrapping in macros, but I thought over again, it seems not too necessary because:

1) the above code is already well straight-forward to view and change if needed...

BUILD_BUG_ON(sizeof(struct erofs_super_block) != 128);
   <==> #define EROFS_SUPER_BLOCK_ONDISK_SIZE  128

EROFS_SUPER_BLOCK_ONDISK_SIZE is not really needed since we could use sizeof(struct erofs_super_block) directly in code.

2) Besides, I also observed the other file systems, such as xfs, sysv, minix, and ubifs, eg.

fs/jffs2/super.c:
366 /* Paranoia checks for on-medium structures. If we ask GCC

367            to pack them with __attribute__((packed)) then it _also_
368            assumes that they're not aligned -- so it emits crappy
369            code on some architectures. Ideally we want an attribute
370            which means just 'no padding', without the alignment
371            thing. But GCC doesn't have that -- we have to just
372            hope the structs are the right sizes, instead. */
373         BUILD_BUG_ON(sizeof(struct jffs2_unknown_node) != 12);
374         BUILD_BUG_ON(sizeof(struct jffs2_raw_dirent) != 40);
375         BUILD_BUG_ON(sizeof(struct jffs2_raw_inode) != 68);
376         BUILD_BUG_ON(sizeof(struct jffs2_raw_summary) != 32);

fs/minix/inode.c:
174 BUILD_BUG_ON(32 != sizeof (struct minix_inode));
175 BUILD_BUG_ON(64 != sizeof(struct minix2_inode));

fs/ubifs/super.c:

359         BUILD_BUG_ON(1024 != sizeof (struct xenix_super_block));
360         BUILD_BUG_ON(512 != sizeof (struct sysv4_super_block));
361         BUILD_BUG_ON(512 != sizeof (struct sysv2_super_block));
362         BUILD_BUG_ON(500 != sizeof (struct coh_super_block));
363         BUILD_BUG_ON(64 != sizeof (struct sysv_inode));

fs/ubifs/super.c

2211         BUILD_BUG_ON(UBIFS_MAX_NODE_SZ      & 7);
2212         BUILD_BUG_ON(MIN_WRITE_SZ           & 7);
2213
2214         /* Check min. node size */
2215         BUILD_BUG_ON(UBIFS_INO_NODE_SZ  < MIN_WRITE_SZ);
2216         BUILD_BUG_ON(UBIFS_DENT_NODE_SZ < MIN_WRITE_SZ);
2217         BUILD_BUG_ON(UBIFS_XENT_NODE_SZ < MIN_WRITE_SZ);
2218         BUILD_BUG_ON(UBIFS_TRUN_NODE_SZ < MIN_WRITE_SZ);
2219
2220         BUILD_BUG_ON(UBIFS_MAX_DENT_NODE_SZ > UBIFS_MAX_NODE_SZ);
2221         BUILD_BUG_ON(UBIFS_MAX_XENT_NODE_SZ > UBIFS_MAX_NODE_SZ);
2222         BUILD_BUG_ON(UBIFS_MAX_DATA_NODE_SZ > UBIFS_MAX_NODE_SZ);
2223         BUILD_BUG_ON(UBIFS_MAX_INO_NODE_SZ  > UBIFS_MAX_NODE_SZ);
2224
2225         /* Defined node sizes */
2226         BUILD_BUG_ON(UBIFS_SB_NODE_SZ  != 4096);
2227         BUILD_BUG_ON(UBIFS_MST_NODE_SZ != 512);
2228         BUILD_BUG_ON(UBIFS_INO_NODE_SZ != 160);
2229         BUILD_BUG_ON(UBIFS_REF_NODE_SZ != 64);
Quoted 1 line

how do you think? :) If you think it is necessary, I can change into marcos immediately~

Alright, it's trivial, let's keep the code as original state. :)

Reviewed-by Chao Yu <yuchao0 at huawei.com>

Thanks,

Quoted 67 lines

Thanks,
Gao Xiang

Quoted 52 lines
Quoted 52 lines
fs/erofs/erofs_fs.h +2 -0
+}
+
 #endif
 
fs/erofs/super.c +20 -7
index a1826b9..d104d88 100644
@@ -37,6 +37,12 @@ static int erofs_init_inode_cache(void)
 	return erofs_inode_cachep != NULL ? 0 : -ENOMEM;
 }
 
+static void erofs_exit_inode_cache(void)
+{
+	BUG_ON(erofs_inode_cachep == NULL);
+	kmem_cache_destroy(erofs_inode_cachep);
+}
+
 static struct inode *alloc_inode(struct super_block *sb)
 {
 	struct erofs_vnode *vi =
@@ -398,22 +404,30 @@ int __init erofs_module_init(void)
 {
 	int err;
 
+	erofs_check_ondisk_layout();
 	infoln("Initializing erofs " EROFS_VERSION);
 
 	err = erofs_init_inode_cache();
-	if (!err) {
-		err = register_filesystem(&erofs_fs_type);
-		if (!err) {
-			infoln("Successfully to initialize erofs");
-			return 0;
-		}
-	}
+	if (err)
+		goto icache_err;
+
+	err = register_filesystem(&erofs_fs_type);
+	if (err)
+		goto fs_err;
+
+	infoln("Successfully to initialize erofs");
+	return 0;
+
+fs_err:
+	erofs_exit_inode_cache();
+icache_err:
 	return err;
 }
 
Quoted 8 lines

fs/erofs/super.c int __init erofs_module_init(void) · line 433

Quoted 8 lines
fs/erofs/super.c +1 -0
 void __exit erofs_module_exit(void)
 {
 	unregister_filesystem(&erofs_fs_type);
+	erofs_exit_inode_cache();
 	infoln("Successfully finalize erofs");
 }
 

.

author
#4 lore raw

PATCH 1/1 erofs: fix erofs_module_init & exit

Hi Chao,

Quoted 101 lines · Chao Yu

Hi Xiang,

Quoted 98 lines · Gao Xiang

Hi Chao,

Quoted 33 lines · Chao Yu

Hi Xiang,

Quoted 18 lines · Gao Xiang

This patch adds missing parts and EROFS ondisk
layout check as well.

Signed-off-by Gao Xiang <gaoxiang25 at huawei.com>
---
 fs/erofs/erofs_fs.h | 13 +++++++++++++
 fs/erofs/super.c    | 28 +++++++++++++++++++++-------
 2 files changed, 34 insertions(+), 7 deletions(-)
fs/erofs/erofs_fs.h +1 -0
index ed943d4..0dbf08d 100644
@@ -253,5 +253,18 @@ enum {
 
 #define EROFS_NAME_LEN      255
 
+/* check the EROFS on-disk layout strictly at compile time */

fs/erofs/erofs_fs.h enum { · line 266

Quoted 10 lines
fs/erofs/erofs_fs.h +10 -0
+static inline void erofs_check_ondisk_layout(void)
+{
+	BUILD_BUG_ON(sizeof(struct erofs_super_block) != 128);
+	BUILD_BUG_ON(sizeof(struct erofs_inode_v1) != 32);
+	BUILD_BUG_ON(sizeof(struct erofs_inode_v2) != 64);
+	BUILD_BUG_ON(sizeof(struct erofs_xattr_ibody_header) != 12);
+	BUILD_BUG_ON(sizeof(struct erofs_xattr_entry) != 4);
+	BUILD_BUG_ON(sizeof(struct erofs_extent_header) != 16);
+	BUILD_BUG_ON(sizeof(struct erofs_decompressed_index_vle) != 8);
+	BUILD_BUG_ON(sizeof(struct erofs_dirent) != 12);

We'd better define some macros include above constants.

Quoted 4 lines

Other parts look good to me.

Thanks,

I was also thinking of wrapping in macros, but I thought over again, it seems not too necessary because:

1) the above code is already well straight-forward to view and change if needed...

BUILD_BUG_ON(sizeof(struct erofs_super_block) != 128);
   <==> #define EROFS_SUPER_BLOCK_ONDISK_SIZE  128

EROFS_SUPER_BLOCK_ONDISK_SIZE is not really needed since we could use sizeof(struct erofs_super_block) directly in code.

2) Besides, I also observed the other file systems, such as xfs, sysv, minix, and ubifs, eg.

fs/jffs2/super.c:
366 /* Paranoia checks for on-medium structures. If we ask GCC

367            to pack them with __attribute__((packed)) then it _also_
368            assumes that they're not aligned -- so it emits crappy
369            code on some architectures. Ideally we want an attribute
370            which means just 'no padding', without the alignment
371            thing. But GCC doesn't have that -- we have to just
372            hope the structs are the right sizes, instead. */
373         BUILD_BUG_ON(sizeof(struct jffs2_unknown_node) != 12);
374         BUILD_BUG_ON(sizeof(struct jffs2_raw_dirent) != 40);
375         BUILD_BUG_ON(sizeof(struct jffs2_raw_inode) != 68);
376         BUILD_BUG_ON(sizeof(struct jffs2_raw_summary) != 32);

fs/minix/inode.c:
174 BUILD_BUG_ON(32 != sizeof (struct minix_inode));
175 BUILD_BUG_ON(64 != sizeof(struct minix2_inode));

fs/ubifs/super.c:

359         BUILD_BUG_ON(1024 != sizeof (struct xenix_super_block));
360         BUILD_BUG_ON(512 != sizeof (struct sysv4_super_block));
361         BUILD_BUG_ON(512 != sizeof (struct sysv2_super_block));
362         BUILD_BUG_ON(500 != sizeof (struct coh_super_block));
363         BUILD_BUG_ON(64 != sizeof (struct sysv_inode));

fs/ubifs/super.c

2211         BUILD_BUG_ON(UBIFS_MAX_NODE_SZ      & 7);
2212         BUILD_BUG_ON(MIN_WRITE_SZ           & 7);
2213
2214         /* Check min. node size */
2215         BUILD_BUG_ON(UBIFS_INO_NODE_SZ  < MIN_WRITE_SZ);
2216         BUILD_BUG_ON(UBIFS_DENT_NODE_SZ < MIN_WRITE_SZ);
2217         BUILD_BUG_ON(UBIFS_XENT_NODE_SZ < MIN_WRITE_SZ);
2218         BUILD_BUG_ON(UBIFS_TRUN_NODE_SZ < MIN_WRITE_SZ);
2219
2220         BUILD_BUG_ON(UBIFS_MAX_DENT_NODE_SZ > UBIFS_MAX_NODE_SZ);
2221         BUILD_BUG_ON(UBIFS_MAX_XENT_NODE_SZ > UBIFS_MAX_NODE_SZ);
2222         BUILD_BUG_ON(UBIFS_MAX_DATA_NODE_SZ > UBIFS_MAX_NODE_SZ);
2223         BUILD_BUG_ON(UBIFS_MAX_INO_NODE_SZ  > UBIFS_MAX_NODE_SZ);
2224
2225         /* Defined node sizes */
2226         BUILD_BUG_ON(UBIFS_SB_NODE_SZ  != 4096);
2227         BUILD_BUG_ON(UBIFS_MST_NODE_SZ != 512);
2228         BUILD_BUG_ON(UBIFS_INO_NODE_SZ != 160);
2229         BUILD_BUG_ON(UBIFS_REF_NODE_SZ != 64);
Quoted 5 lines
Quoted 1 line

how do you think? :) If you think it is necessary, I can change into marcos immediately~

Alright, it's trivial, let's keep the code as original state. :)

Reviewed-by Chao Yu <yuchao0 at huawei.com>

:), Thanks for the review~

It seems that 'erofs_check_ondisk_layout_definations' is more proper than 'erofs_check_ondisk_layout', which seems used for the runtime sanity check..

Let me send the next version :)

Thanks,
Gao Xiang

Quoted 67 lines

Thanks,

Quoted 65 lines

Thanks,
Gao Xiang

Quoted 52 lines
Quoted 52 lines
fs/erofs/erofs_fs.h +2 -0
+}
+
 #endif
 
fs/erofs/super.c +20 -7
index a1826b9..d104d88 100644
@@ -37,6 +37,12 @@ static int erofs_init_inode_cache(void)
 	return erofs_inode_cachep != NULL ? 0 : -ENOMEM;
 }
 
+static void erofs_exit_inode_cache(void)
+{
+	BUG_ON(erofs_inode_cachep == NULL);
+	kmem_cache_destroy(erofs_inode_cachep);
+}
+
 static struct inode *alloc_inode(struct super_block *sb)
 {
 	struct erofs_vnode *vi =
@@ -398,22 +404,30 @@ int __init erofs_module_init(void)
 {
 	int err;
 
+	erofs_check_ondisk_layout();
 	infoln("Initializing erofs " EROFS_VERSION);
 
 	err = erofs_init_inode_cache();
-	if (!err) {
-		err = register_filesystem(&erofs_fs_type);
-		if (!err) {
-			infoln("Successfully to initialize erofs");
-			return 0;
-		}
-	}
+	if (err)
+		goto icache_err;
+
+	err = register_filesystem(&erofs_fs_type);
+	if (err)
+		goto fs_err;
+
+	infoln("Successfully to initialize erofs");
+	return 0;
+
+fs_err:
+	erofs_exit_inode_cache();
+icache_err:
 	return err;
 }
 
Quoted 8 lines

fs/erofs/super.c int __init erofs_module_init(void) · line 433

Quoted 8 lines
fs/erofs/super.c +1 -0
 void __exit erofs_module_exit(void)
 {
 	unregister_filesystem(&erofs_fs_type);
+	erofs_exit_inode_cache();
 	infoln("Successfully finalize erofs");
 }
 

.

author
#5 lore raw

PATCH 1/1 erofs: fix erofs_module_init & exit

Hi Chao,

Quoted 6 lines · Gao Xiang
Quoted 4 lines

Alright, it's trivial, let's keep the code as original state. :)

Reviewed-by Chao Yu <yuchao0 at huawei.com>

:), Thanks for the review~

Quoted 9 lines

It seems that 'erofs_check_ondisk_layout_definations' is more proper than 'erofs_check_ondisk_layout', which seems used for the runtime sanity check..

Let me send the next version :)

Thanks,
Gao Xiang

Too many chores today... Sorry for late response.. Could you check the v2 patch and merge it? :)

Thanks,
Gao Xiang

maintainer
#6 lore raw

PATCH 1/1 erofs: fix erofs_module_init & exit

Hi Xiang,

Quoted 15 lines · Gao Xiang

Hi Chao,

Quoted 12 lines · Gao Xiang
Quoted 4 lines

Alright, it's trivial, let's keep the code as original state. :)

Reviewed-by Chao Yu <yuchao0 at huawei.com>

:), Thanks for the review~

It seems that 'erofs_check_ondisk_layout_definations' is more proper than 'erofs_check_ondisk_layout', which seems used for the runtime sanity check..

Let me send the next version :)

Quoted 6 lines
Quoted 3 lines

Thanks,
Gao Xiang

Too many chores today... Sorry for late response.. Could you check the v2 patch and merge it? :)

I have checked it, and updated it in erofs branch. :)

Thanks,

Quoted 4 lines

Thanks,
Gao Xiang

author
#7 lore raw

PATCH v2 1/1 erofs: fix erofs_module_init & exit

In reply to Gao Xiang

This patch adds missing parts and EROFS ondisk
layout check as well.

Reviewed-by Chao Yu <yuchao0 at huawei.com>
Signed-off-by Gao Xiang <gaoxiang25 at huawei.com>

---
change log v2:
- erofs_check_ondisk_layout => erofs_check_ondisk_layout_definitions

 fs/erofs/erofs_fs.h | 13 +++++++++++++
 fs/erofs/super.c    | 28 +++++++++++++++++++++-------
 2 files changed, 34 insertions(+), 7 deletions(-)
fs/erofs/erofs_fs.h +13 -0
index ed943d4..11300414 100644
@@ -253,5 +253,18 @@ enum {
 
 #define EROFS_NAME_LEN      255
 
+/* check the EROFS on-disk layout strictly at compile time */
+static inline void erofs_check_ondisk_layout_definitions(void)
+{
+	BUILD_BUG_ON(sizeof(struct erofs_super_block) != 128);
+	BUILD_BUG_ON(sizeof(struct erofs_inode_v1) != 32);
+	BUILD_BUG_ON(sizeof(struct erofs_inode_v2) != 64);
+	BUILD_BUG_ON(sizeof(struct erofs_xattr_ibody_header) != 12);
+	BUILD_BUG_ON(sizeof(struct erofs_xattr_entry) != 4);
+	BUILD_BUG_ON(sizeof(struct erofs_extent_header) != 16);
+	BUILD_BUG_ON(sizeof(struct erofs_decompressed_index_vle) != 8);
+	BUILD_BUG_ON(sizeof(struct erofs_dirent) != 12);
+}
+
 #endif
 
fs/erofs/super.c +21 -7
index a1826b9..0dcf9c7 100644
@@ -37,6 +37,12 @@ static int erofs_init_inode_cache(void)
 	return erofs_inode_cachep != NULL ? 0 : -ENOMEM;
 }
 
+static void erofs_exit_inode_cache(void)
+{
+	BUG_ON(erofs_inode_cachep == NULL);
+	kmem_cache_destroy(erofs_inode_cachep);
+}
+
 static struct inode *alloc_inode(struct super_block *sb)
 {
 	struct erofs_vnode *vi =
@@ -398,22 +404,30 @@ int __init erofs_module_init(void)
 {
 	int err;
 
+	erofs_check_ondisk_layout_definitions();
 	infoln("Initializing erofs " EROFS_VERSION);
 
 	err = erofs_init_inode_cache();
-	if (!err) {
-		err = register_filesystem(&erofs_fs_type);
-		if (!err) {
-			infoln("Successfully to initialize erofs");
-			return 0;
-		}
-	}
+	if (err)
+		goto icache_err;
+
+	err = register_filesystem(&erofs_fs_type);
+	if (err)
+		goto fs_err;
+
+	infoln("Successfully to initialize erofs");
+	return 0;
+
+fs_err:
+	erofs_exit_inode_cache();
+icache_err:
 	return err;
 }
 
 void __exit erofs_module_exit(void)
 {
 	unregister_filesystem(&erofs_fs_type);
+	erofs_exit_inode_cache();
 	infoln("Successfully finalize erofs");
 }
 
Signature · 1 line
1.9.1