Linux-EROFS Archive on lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] erofs: fix erofs_module_init & exit
@ 2018-07-05  5:03 Gao Xiang
  2018-07-05 16:19 ` Chao Yu
  2018-07-06 11:30 ` [PATCH v2] " Gao Xiang
  0 siblings, 2 replies; 8+ messages in thread
From: Gao Xiang @ 2018-07-05  5:03 UTC (permalink / raw)


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(-)

diff --git a/fs/erofs/erofs_fs.h b/fs/erofs/erofs_fs.h
index ed943d4..0dbf08d 100644
--- a/fs/erofs/erofs_fs.h
+++ b/fs/erofs/erofs_fs.h
@@ -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
 
diff --git a/fs/erofs/super.c b/fs/erofs/super.c
index a1826b9..d104d88 100644
--- a/fs/erofs/super.c
+++ b/fs/erofs/super.c
@@ -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");
 }
 
-- 
1.9.1

^ permalink raw reply related	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2018-07-06 11:56 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2018-07-05  5:03 [PATCH] erofs: fix erofs_module_init & exit Gao Xiang
2018-07-05 16:19 ` Chao Yu
2018-07-05 16:39   ` Gao Xiang
2018-07-06  1:30     ` Chao Yu
2018-07-06  2:09       ` Gao Xiang
2018-07-06 11:34         ` Gao Xiang
2018-07-06 11:56           ` Chao Yu
2018-07-06 11:30 ` [PATCH v2] " Gao Xiang

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox