From: Jaegeuk Kim <jaegeuk@kernel.org>
To: Yangtao Li <frank.li@vivo.com>
Cc: Nick Terrell <terrelln@fb.com>,
linux-kernel@vger.kernel.org,
linux-f2fs-devel@lists.sourceforge.net
Subject: Re: [f2fs-dev] [PATCH v3] f2fs: add sanity compress level check for compressed file
Date: Mon, 12 Jun 2023 11:28:42 -0700 [thread overview]
Message-ID: <ZIdj2jAFDvkZ3eJW@google.com> (raw)
In-Reply-To: <20230407183148.23231-1-frank.li@vivo.com>
On 04/08, Yangtao Li wrote:
> Commit 3fde13f817e2 ("f2fs: compress: support compress level")
> forgot to do basic compress level check, let's add it.
>
> Signed-off-by: Yangtao Li <frank.li@vivo.com>
> ---
> fs/f2fs/inode.c | 106 +++++++++++++++++++++++++++++++++++-------------
> 1 file changed, 77 insertions(+), 29 deletions(-)
>
> diff --git a/fs/f2fs/inode.c b/fs/f2fs/inode.c
> index bb5b365a195d..c2460f51bf80 100644
> --- a/fs/f2fs/inode.c
> +++ b/fs/f2fs/inode.c
> @@ -10,6 +10,8 @@
> #include <linux/buffer_head.h>
> #include <linux/writeback.h>
> #include <linux/sched/mm.h>
> +#include <linux/lz4.h>
> +#include <linux/zstd.h>
>
> #include "f2fs.h"
> #include "node.h"
> @@ -202,6 +204,79 @@ void f2fs_inode_chksum_set(struct f2fs_sb_info *sbi, struct page *page)
> ri->i_inode_checksum = cpu_to_le32(f2fs_inode_chksum(sbi, page));
> }
>
> +static bool sanity_check_compress_inode(struct inode *inode,
> + struct f2fs_inode *ri)
> +{
> + struct f2fs_sb_info *sbi = F2FS_I_SB(inode);
> + unsigned char compress_level;
> +
> + if (ri->i_compress_algorithm >= COMPRESS_MAX) {
> + f2fs_warn(sbi,
> + "%s: inode (ino=%lx) has unsupported compress algorithm: %u, run fsck to fix",
> + __func__, inode->i_ino, ri->i_compress_algorithm);
> + goto err;
> + }
> + if (le64_to_cpu(ri->i_compr_blocks) >
> + SECTOR_TO_BLOCK(inode->i_blocks)) {
> + f2fs_warn(sbi,
> + "%s: inode (ino=%lx) has inconsistent i_compr_blocks:%llu, i_blocks:%llu, run fsck to fix",
> + __func__, inode->i_ino, le64_to_cpu(ri->i_compr_blocks),
> + SECTOR_TO_BLOCK(inode->i_blocks));
> + goto err;
> + }
> + if (ri->i_log_cluster_size < MIN_COMPRESS_LOG_SIZE ||
> + ri->i_log_cluster_size > MAX_COMPRESS_LOG_SIZE) {
> + f2fs_warn(sbi,
> + "%s: inode (ino=%lx) has unsupported log cluster size: %u, run fsck to fix",
> + __func__, inode->i_ino, ri->i_log_cluster_size);
> + goto err;
> + }
> +
> + compress_level = le16_to_cpu(ri->i_compress_flag) >>
> + COMPRESS_LEVEL_OFFSET;
> + switch (ri->i_compress_algorithm) {
> + case COMPRESS_LZO:
> +#ifdef CONFIG_F2FS_FS_LZO
> + if (compress_level)
> + goto err_level;
> +#endif
> + break;
> + case COMPRESS_LZORLE:
> +#ifdef CONFIG_F2FS_FS_LZORLE
> + if (compress_level)
> + goto err_level;
> +#endif
> + break;
> + case COMPRESS_LZ4:
> +#ifdef CONFIG_F2FS_FS_LZ4
> +#ifdef CONFIG_F2FS_FS_LZ4HC
> + if ((compress_level && compress_level < LZ4HC_MIN_CLEVEL) ||
> + compress_level > LZ4HC_MAX_CLEVEL)
> +#else
> + if (compress_level)
> +#endif
> + goto err_level;
> +#endif
> + break;
> + case COMPRESS_ZSTD:
> +#ifdef CONFIG_F2FS_FS_ZSTD
> + if (!compress_level || compress_level > zstd_max_clevel())
I think compress_level=0 is wrong, since that'll be changed to the default level later.
I'll modify to assign the correct level, so please revisit this patch later.
> + goto err_level;
> +#endif
> + break;
> + default:
> + goto err_level;
> + }
> +
> + return true;
> +err_level:
> + f2fs_warn(sbi, "%s: inode (ino=%lx) has unsupported compress level: %u, run fsck to fix",
> + __func__, inode->i_ino, compress_level);
> +err:
> + set_sbi_flag(sbi, SBI_NEED_FSCK);
> + return false;
> +}
> +
> static bool sanity_check_inode(struct inode *inode, struct page *node_page)
> {
> struct f2fs_sb_info *sbi = F2FS_I_SB(inode);
> @@ -286,35 +361,8 @@ static bool sanity_check_inode(struct inode *inode, struct page *node_page)
> if (f2fs_has_extra_attr(inode) && f2fs_sb_has_compression(sbi) &&
> fi->i_flags & F2FS_COMPR_FL &&
> F2FS_FITS_IN_INODE(ri, fi->i_extra_isize,
> - i_log_cluster_size)) {
> - if (ri->i_compress_algorithm >= COMPRESS_MAX) {
> - set_sbi_flag(sbi, SBI_NEED_FSCK);
> - f2fs_warn(sbi, "%s: inode (ino=%lx) has unsupported "
> - "compress algorithm: %u, run fsck to fix",
> - __func__, inode->i_ino,
> - ri->i_compress_algorithm);
> - return false;
> - }
> - if (le64_to_cpu(ri->i_compr_blocks) >
> - SECTOR_TO_BLOCK(inode->i_blocks)) {
> - set_sbi_flag(sbi, SBI_NEED_FSCK);
> - f2fs_warn(sbi, "%s: inode (ino=%lx) has inconsistent "
> - "i_compr_blocks:%llu, i_blocks:%llu, run fsck to fix",
> - __func__, inode->i_ino,
> - le64_to_cpu(ri->i_compr_blocks),
> - SECTOR_TO_BLOCK(inode->i_blocks));
> - return false;
> - }
> - if (ri->i_log_cluster_size < MIN_COMPRESS_LOG_SIZE ||
> - ri->i_log_cluster_size > MAX_COMPRESS_LOG_SIZE) {
> - set_sbi_flag(sbi, SBI_NEED_FSCK);
> - f2fs_warn(sbi, "%s: inode (ino=%lx) has unsupported "
> - "log cluster size: %u, run fsck to fix",
> - __func__, inode->i_ino,
> - ri->i_log_cluster_size);
> - return false;
> - }
> - }
> + i_log_cluster_size))
> + return sanity_check_compress_inode(inode, ri);
>
> return true;
> }
> --
> 2.35.1
_______________________________________________
Linux-f2fs-devel mailing list
Linux-f2fs-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel
WARNING: multiple messages have this Message-ID (diff)
From: Jaegeuk Kim <jaegeuk@kernel.org>
To: Yangtao Li <frank.li@vivo.com>
Cc: Chao Yu <chao@kernel.org>, Nick Terrell <terrelln@fb.com>,
linux-f2fs-devel@lists.sourceforge.net,
linux-kernel@vger.kernel.org
Subject: Re: [PATCH v3] f2fs: add sanity compress level check for compressed file
Date: Mon, 12 Jun 2023 11:28:42 -0700 [thread overview]
Message-ID: <ZIdj2jAFDvkZ3eJW@google.com> (raw)
In-Reply-To: <20230407183148.23231-1-frank.li@vivo.com>
On 04/08, Yangtao Li wrote:
> Commit 3fde13f817e2 ("f2fs: compress: support compress level")
> forgot to do basic compress level check, let's add it.
>
> Signed-off-by: Yangtao Li <frank.li@vivo.com>
> ---
> fs/f2fs/inode.c | 106 +++++++++++++++++++++++++++++++++++-------------
> 1 file changed, 77 insertions(+), 29 deletions(-)
>
> diff --git a/fs/f2fs/inode.c b/fs/f2fs/inode.c
> index bb5b365a195d..c2460f51bf80 100644
> --- a/fs/f2fs/inode.c
> +++ b/fs/f2fs/inode.c
> @@ -10,6 +10,8 @@
> #include <linux/buffer_head.h>
> #include <linux/writeback.h>
> #include <linux/sched/mm.h>
> +#include <linux/lz4.h>
> +#include <linux/zstd.h>
>
> #include "f2fs.h"
> #include "node.h"
> @@ -202,6 +204,79 @@ void f2fs_inode_chksum_set(struct f2fs_sb_info *sbi, struct page *page)
> ri->i_inode_checksum = cpu_to_le32(f2fs_inode_chksum(sbi, page));
> }
>
> +static bool sanity_check_compress_inode(struct inode *inode,
> + struct f2fs_inode *ri)
> +{
> + struct f2fs_sb_info *sbi = F2FS_I_SB(inode);
> + unsigned char compress_level;
> +
> + if (ri->i_compress_algorithm >= COMPRESS_MAX) {
> + f2fs_warn(sbi,
> + "%s: inode (ino=%lx) has unsupported compress algorithm: %u, run fsck to fix",
> + __func__, inode->i_ino, ri->i_compress_algorithm);
> + goto err;
> + }
> + if (le64_to_cpu(ri->i_compr_blocks) >
> + SECTOR_TO_BLOCK(inode->i_blocks)) {
> + f2fs_warn(sbi,
> + "%s: inode (ino=%lx) has inconsistent i_compr_blocks:%llu, i_blocks:%llu, run fsck to fix",
> + __func__, inode->i_ino, le64_to_cpu(ri->i_compr_blocks),
> + SECTOR_TO_BLOCK(inode->i_blocks));
> + goto err;
> + }
> + if (ri->i_log_cluster_size < MIN_COMPRESS_LOG_SIZE ||
> + ri->i_log_cluster_size > MAX_COMPRESS_LOG_SIZE) {
> + f2fs_warn(sbi,
> + "%s: inode (ino=%lx) has unsupported log cluster size: %u, run fsck to fix",
> + __func__, inode->i_ino, ri->i_log_cluster_size);
> + goto err;
> + }
> +
> + compress_level = le16_to_cpu(ri->i_compress_flag) >>
> + COMPRESS_LEVEL_OFFSET;
> + switch (ri->i_compress_algorithm) {
> + case COMPRESS_LZO:
> +#ifdef CONFIG_F2FS_FS_LZO
> + if (compress_level)
> + goto err_level;
> +#endif
> + break;
> + case COMPRESS_LZORLE:
> +#ifdef CONFIG_F2FS_FS_LZORLE
> + if (compress_level)
> + goto err_level;
> +#endif
> + break;
> + case COMPRESS_LZ4:
> +#ifdef CONFIG_F2FS_FS_LZ4
> +#ifdef CONFIG_F2FS_FS_LZ4HC
> + if ((compress_level && compress_level < LZ4HC_MIN_CLEVEL) ||
> + compress_level > LZ4HC_MAX_CLEVEL)
> +#else
> + if (compress_level)
> +#endif
> + goto err_level;
> +#endif
> + break;
> + case COMPRESS_ZSTD:
> +#ifdef CONFIG_F2FS_FS_ZSTD
> + if (!compress_level || compress_level > zstd_max_clevel())
I think compress_level=0 is wrong, since that'll be changed to the default level later.
I'll modify to assign the correct level, so please revisit this patch later.
> + goto err_level;
> +#endif
> + break;
> + default:
> + goto err_level;
> + }
> +
> + return true;
> +err_level:
> + f2fs_warn(sbi, "%s: inode (ino=%lx) has unsupported compress level: %u, run fsck to fix",
> + __func__, inode->i_ino, compress_level);
> +err:
> + set_sbi_flag(sbi, SBI_NEED_FSCK);
> + return false;
> +}
> +
> static bool sanity_check_inode(struct inode *inode, struct page *node_page)
> {
> struct f2fs_sb_info *sbi = F2FS_I_SB(inode);
> @@ -286,35 +361,8 @@ static bool sanity_check_inode(struct inode *inode, struct page *node_page)
> if (f2fs_has_extra_attr(inode) && f2fs_sb_has_compression(sbi) &&
> fi->i_flags & F2FS_COMPR_FL &&
> F2FS_FITS_IN_INODE(ri, fi->i_extra_isize,
> - i_log_cluster_size)) {
> - if (ri->i_compress_algorithm >= COMPRESS_MAX) {
> - set_sbi_flag(sbi, SBI_NEED_FSCK);
> - f2fs_warn(sbi, "%s: inode (ino=%lx) has unsupported "
> - "compress algorithm: %u, run fsck to fix",
> - __func__, inode->i_ino,
> - ri->i_compress_algorithm);
> - return false;
> - }
> - if (le64_to_cpu(ri->i_compr_blocks) >
> - SECTOR_TO_BLOCK(inode->i_blocks)) {
> - set_sbi_flag(sbi, SBI_NEED_FSCK);
> - f2fs_warn(sbi, "%s: inode (ino=%lx) has inconsistent "
> - "i_compr_blocks:%llu, i_blocks:%llu, run fsck to fix",
> - __func__, inode->i_ino,
> - le64_to_cpu(ri->i_compr_blocks),
> - SECTOR_TO_BLOCK(inode->i_blocks));
> - return false;
> - }
> - if (ri->i_log_cluster_size < MIN_COMPRESS_LOG_SIZE ||
> - ri->i_log_cluster_size > MAX_COMPRESS_LOG_SIZE) {
> - set_sbi_flag(sbi, SBI_NEED_FSCK);
> - f2fs_warn(sbi, "%s: inode (ino=%lx) has unsupported "
> - "log cluster size: %u, run fsck to fix",
> - __func__, inode->i_ino,
> - ri->i_log_cluster_size);
> - return false;
> - }
> - }
> + i_log_cluster_size))
> + return sanity_check_compress_inode(inode, ri);
>
> return true;
> }
> --
> 2.35.1
next prev parent reply other threads:[~2023-06-12 18:28 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-04-07 18:31 [f2fs-dev] [PATCH v3] f2fs: add sanity compress level check for compressed file Yangtao Li via Linux-f2fs-devel
2023-04-07 18:31 ` Yangtao Li
2023-05-06 15:39 ` [f2fs-dev] " Yangtao Li via Linux-f2fs-devel
2023-05-06 15:39 ` Yangtao Li
2023-05-18 1:50 ` [f2fs-dev] " patchwork-bot+f2fs
2023-05-18 1:50 ` patchwork-bot+f2fs
2023-06-12 18:28 ` Jaegeuk Kim [this message]
2023-06-12 18:28 ` Jaegeuk Kim
Reply instructions:
You may reply publicly 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=ZIdj2jAFDvkZ3eJW@google.com \
--to=jaegeuk@kernel.org \
--cc=frank.li@vivo.com \
--cc=linux-f2fs-devel@lists.sourceforge.net \
--cc=linux-kernel@vger.kernel.org \
--cc=terrelln@fb.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
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.