Linux-EROFS Archive on lore.kernel.org
 help / color / Atom feed
From: Gao Xiang <gaoxiang25@huawei.com>
To: Li Guifu <bluce.liguifu@huawei.com>, <linux-erofs@lists.ozlabs.org>
Cc: Miao Xie <miaoxie@huawei.com>
Subject: [PATCH] erofs-utils: wrap up sb feature operations
Date: Tue, 31 Dec 2019 16:22:00 +0800
Message-ID: <20191231082200.152744-1-gaoxiang25@huawei.com> (raw)

Add some helpers for shorter lines. No logic change.

Signed-off-by: Gao Xiang <gaoxiang25@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


             reply index

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-12-31  8:22 Gao Xiang [this message]
2020-01-01 10:40 ` Li Guifu

Reply instructions:

You may reply publically to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20191231082200.152744-1-gaoxiang25@huawei.com \
    --to=gaoxiang25@huawei.com \
    --cc=bluce.liguifu@huawei.com \
    --cc=linux-erofs@lists.ozlabs.org \
    --cc=miaoxie@huawei.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link

Linux-EROFS Archive on lore.kernel.org

Archives are clonable:
	git clone --mirror https://lore.kernel.org/linux-erofs/0 linux-erofs/git/0.git

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V2 linux-erofs linux-erofs/ https://lore.kernel.org/linux-erofs \
		linux-erofs@lists.ozlabs.org linux-erofs@ozlabs.org
	public-inbox-index linux-erofs

Example config snippet for mirrors

Newsgroup available over NNTP:
	nntp://nntp.lore.kernel.org/org.ozlabs.lists.linux-erofs


AGPL code for this site: git clone https://public-inbox.org/public-inbox.git