* [PATCH] erofs-utils: wrap up sb feature operations
@ 2019-12-31 8:22 Gao Xiang
2020-01-01 10:40 ` Li Guifu
0 siblings, 1 reply; 2+ messages in thread
From: Gao Xiang @ 2019-12-31 8:22 UTC (permalink / raw)
To: Li Guifu, linux-erofs; +Cc: Miao Xie
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
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [PATCH] erofs-utils: wrap up sb feature operations
2019-12-31 8:22 [PATCH] erofs-utils: wrap up sb feature operations Gao Xiang
@ 2020-01-01 10:40 ` Li Guifu
0 siblings, 0 replies; 2+ messages in thread
From: Li Guifu @ 2020-01-01 10:40 UTC (permalink / raw)
To: Gao Xiang, Li Guifu, linux-erofs; +Cc: Miao Xie
> Add some helpers for shorter lines. No logic change.
>
> Signed-off-by: Gao Xiang <gaoxiang25@huawei.com>
>
It looks good
Reviewed-by: Li Guifu <blucer.lee@foxmail.com>
Because the pre email Li Guifu <blucerlee@gmail.com> is not work at
chinese mainland, so replace it with Li Guifu <blucer.lee@foxmail.com>
Thanks,
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2020-01-01 10:42 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-12-31 8:22 [PATCH] erofs-utils: wrap up sb feature operations Gao Xiang
2020-01-01 10:40 ` Li Guifu
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).