[PATCH] erofs-utils: wrap up sb feature operations

Gao Xiang gaoxiang25 at huawei.com
Tue Dec 31 19:22:00 AEDT 2019


Add some helpers for shorter lines. No logic change.

Signed-off-by: Gao Xiang <gaoxiang25 at huawei.com>
---
 include/erofs/internal.h | 17 +++++++++++++++++
 lib/compress.c           | 18 ++++++++----------
 mkfs/main.c              |  7 +++----
 3 files changed, 28 insertions(+), 14 deletions(-)

diff --git a/include/erofs/internal.h b/include/erofs/internal.h
index e13adda12257..0a82c226d170 100644
--- a/include/erofs/internal.h
+++ b/include/erofs/internal.h
@@ -62,6 +62,23 @@ struct erofs_sb_info {
 /* global sbi */
 extern struct erofs_sb_info sbi;
 
+#define EROFS_FEATURE_FUNCS(name, compat, feature) \
+static inline bool erofs_sb_has_##name(void) \
+{ \
+	return sbi.feature_##compat & EROFS_FEATURE_##feature; \
+} \
+static inline void erofs_sb_set_##name(void) \
+{ \
+	sbi.feature_##compat |= EROFS_FEATURE_##feature; \
+} \
+static inline void erofs_sb_clear_##name(void) \
+{ \
+	sbi.feature_##compat &= ~EROFS_FEATURE_##feature; \
+}
+
+EROFS_FEATURE_FUNCS(lz4_0padding, incompat, INCOMPAT_LZ4_0PADDING)
+EROFS_FEATURE_FUNCS(sb_chksum, compat, COMPAT_SB_CHKSUM)
+
 struct erofs_inode {
 	struct list_head i_hash, i_subdirs, i_xattrs;
 
diff --git a/lib/compress.c b/lib/compress.c
index 99fd527ead50..412557fe2627 100644
--- a/lib/compress.c
+++ b/lib/compress.c
@@ -120,13 +120,12 @@ static int write_uncompressed_block(struct z_erofs_vle_compress_ctx *ctx,
 	int ret;
 	unsigned int count;
 
-	if (!(sbi.feature_incompat & EROFS_FEATURE_INCOMPAT_LZ4_0PADDING)) {
-		/* fix up clusterofs to 0 if possable */
-		if (ctx->head >= ctx->clusterofs) {
-			ctx->head -= ctx->clusterofs;
-			*len += ctx->clusterofs;
-			ctx->clusterofs = 0;
-		}
+	/* reset clusterofs to 0 if permitted */
+	if (!erofs_sb_has_lz4_0padding() &&
+	    ctx->head >= ctx->clusterofs) {
+		ctx->head -= ctx->clusterofs;
+		*len += ctx->clusterofs;
+		ctx->clusterofs = 0;
 	}
 
 	/* write uncompressed data */
@@ -184,8 +183,7 @@ nocompression:
 			erofs_dbg("Writing %u compressed data to block %u",
 				  count, ctx->blkaddr);
 
-			if (sbi.feature_incompat &
-			    EROFS_FEATURE_INCOMPAT_LZ4_0PADDING)
+			if (erofs_sb_has_lz4_0padding())
 				ret = blk_write(dst - (EROFS_BLKSIZ - ret),
 						ctx->blkaddr, 1);
 			else
@@ -514,7 +512,7 @@ int z_erofs_compress_init(void)
 	 */
 	if (!cfg.c_compr_alg_master ||
 	    strncmp(cfg.c_compr_alg_master, "lz4", 3))
-		sbi.feature_incompat &= ~EROFS_FEATURE_INCOMPAT_LZ4_0PADDING;
+		erofs_sb_clear_lz4_0padding();
 
 	if (!cfg.c_compr_alg_master)
 		return 0;
diff --git a/mkfs/main.c b/mkfs/main.c
index 7493a481be82..817a6c1ab967 100644
--- a/mkfs/main.c
+++ b/mkfs/main.c
@@ -98,8 +98,7 @@ static int parse_extended_opts(const char *opts)
 				return -EINVAL;
 			/* disable compacted indexes and 0padding */
 			cfg.c_legacy_compress = true;
-			sbi.feature_incompat &=
-				~EROFS_FEATURE_INCOMPAT_LZ4_0PADDING;
+			erofs_sb_clear_lz4_0padding();
 		}
 
 		if (MATCH_EXTENTED_OPT("force-inode-compact", token, keylen)) {
@@ -117,7 +116,7 @@ static int parse_extended_opts(const char *opts)
 		if (MATCH_EXTENTED_OPT("nosbcrc", token, keylen)) {
 			if (vallen)
 				return -EINVAL;
-			sbi.feature_compat &= ~EROFS_FEATURE_COMPAT_SB_CHKSUM;
+			erofs_sb_clear_sb_chksum();
 		}
 	}
 	return 0;
@@ -424,7 +423,7 @@ int main(int argc, char **argv)
 	else
 		err = dev_resize(nblocks);
 
-	if (!err && (sbi.feature_compat & EROFS_FEATURE_COMPAT_SB_CHKSUM))
+	if (!err && erofs_sb_has_sb_chksum())
 		err = erofs_mkfs_superblock_csum_set();
 exit:
 	z_erofs_compress_exit();
-- 
2.17.1



More information about the Linux-erofs mailing list