For example, when we enables compression of the entire mounted directory,
and the mounted directory used by applications, the applications may write
some
files that have been compressed, such as tar files and zip files, we want
avoid duplicate compressions for these.

As for the complex, ambiguous cases you point out, we might add some
legitimacy checks.

-----邮件原件-----
发件人: Chao Yu <[email protected]> 
发送时间: 2021年4月15日 9:32
收件人: Fengnan Chang <[email protected]>
抄送: [email protected]; [email protected];
[email protected]
主题: Re: [f2fs-dev] [RFC PATCH] f2fs: add no compress extensions support

Hi Fengnan,

On 2021/4/14 17:47, Fengnan Chang wrote:
> When we create a directory with enable compression, all file write 
> into directory will try to compress.But sometimes we may know, new 
> file cannot meet compression ratio requirements.
> We need a nocompress extension to skip those files to avoid 
> unnecessary compress page test.

Could you please elaborate your detail usage scenario? something like in
which directory, what kind of specified extension do you want to disable?

It's a bit complicated for below cases:
compress_extension = "abc" and nocompress_extension = "abc" or
compress_extension = "*" and nocompress_extension = "abc" or
compress_extension = "abc" and nocompress_extension = "*"

Thanks,

> 
> Signed-off-by: Fengnan Chang <[email protected]>
> ---
>   fs/f2fs/f2fs.h  |  2 ++
>   fs/f2fs/namei.c | 12 +++++++++++-
>   fs/f2fs/super.c | 35 +++++++++++++++++++++++++++++++++--
>   3 files changed, 46 insertions(+), 3 deletions(-)
> 
> diff --git a/fs/f2fs/f2fs.h b/fs/f2fs/f2fs.h index 
> 87d734f5589d..3d5d28a2568f 100644
> --- a/fs/f2fs/f2fs.h
> +++ b/fs/f2fs/f2fs.h
> @@ -150,8 +150,10 @@ struct f2fs_mount_info {
>       unsigned char compress_level;           /* compress level */
>       bool compress_chksum;                   /* compressed data chksum */
>       unsigned char compress_ext_cnt;         /* extension count */
> +     unsigned char nocompress_ext_cnt;               /* nocompress
extension count */
>       int compress_mode;                      /* compression mode */
>       unsigned char extensions[COMPRESS_EXT_NUM][F2FS_EXTENSION_LEN]; /*
extensions */
> +     unsigned char noextensions[COMPRESS_EXT_NUM][F2FS_EXTENSION_LEN]; /*

> +extensions */
>   };
> 
>   #define F2FS_FEATURE_ENCRYPT                0x0001
> diff --git a/fs/f2fs/namei.c b/fs/f2fs/namei.c index 
> 405d85dbf9f1..09b76a7f048a 100644
> --- a/fs/f2fs/namei.c
> +++ b/fs/f2fs/namei.c
> @@ -280,15 +280,25 @@ static void set_compress_inode(struct f2fs_sb_info
*sbi, struct inode *inode,
>   {
>       __u8 (*extlist)[F2FS_EXTENSION_LEN] =
sbi->raw_super->extension_list;
>       unsigned char (*ext)[F2FS_EXTENSION_LEN];
> +     unsigned char (*noext)[F2FS_EXTENSION_LEN];
>       unsigned int ext_cnt = F2FS_OPTION(sbi).compress_ext_cnt;
> +     unsigned int noext_cnt = F2FS_OPTION(sbi).nocompress_ext_cnt;
>       int i, cold_count, hot_count;
> 
>       if (!f2fs_sb_has_compression(sbi) ||
> -                     is_inode_flag_set(inode, FI_COMPRESSED_FILE) ||
>                       F2FS_I(inode)->i_flags & F2FS_NOCOMP_FL ||
>                       !f2fs_may_compress(inode))
>               return;
> 
> +     if (is_inode_flag_set(inode, FI_COMPRESSED_FILE)) {
> +             noext = F2FS_OPTION(sbi).noextensions;
> +             for (i = 0; i < noext_cnt; i++) {
> +                     if (is_extension_exist(name, noext[i]))
> +                             f2fs_disable_compressed_file(inode);
> +             }
> +             return;
> +     }
> +
>       down_read(&sbi->sb_lock);
> 
>       cold_count = le32_to_cpu(sbi->raw_super->extension_count);
> diff --git a/fs/f2fs/super.c b/fs/f2fs/super.c index 
> 5020152aa8fc..b5a9ba8ea869 100644
> --- a/fs/f2fs/super.c
> +++ b/fs/f2fs/super.c
> @@ -153,6 +153,7 @@ enum {
>       Opt_atgc,
>       Opt_gc_merge,
>       Opt_nogc_merge,
> +     Opt_nocompress_extension,
>       Opt_err,
>   };
> 
> @@ -227,6 +228,7 @@ static match_table_t f2fs_tokens = {
>       {Opt_atgc, "atgc"},
>       {Opt_gc_merge, "gc_merge"},
>       {Opt_nogc_merge, "nogc_merge"},
> +     {Opt_nocompress_extension, "nocompress_extension=%s"},
>       {Opt_err, NULL},
>   };
> 
> @@ -546,7 +548,8 @@ static int parse_options(struct super_block *sb, char
*options, bool is_remount)
>       substring_t args[MAX_OPT_ARGS];
>   #ifdef CONFIG_F2FS_FS_COMPRESSION
>       unsigned char (*ext)[F2FS_EXTENSION_LEN];
> -     int ext_cnt;
> +     unsigned char (*noext)[F2FS_EXTENSION_LEN];
> +     int ext_cnt, noext_cnt;
>   #endif
>       char *p, *name;
>       int arg = 0;
> @@ -1049,6 +1052,30 @@ static int parse_options(struct super_block *sb,
char *options, bool is_remount)
>                       F2FS_OPTION(sbi).compress_ext_cnt++;
>                       kfree(name);
>                       break;
> +             case Opt_nocompress_extension:
> +                     if (!f2fs_sb_has_compression(sbi)) {
> +                             f2fs_info(sbi, "Image doesn't support
compression");
> +                             break;
> +                     }
> +                     name = match_strdup(&args[0]);
> +                     if (!name)
> +                             return -ENOMEM;
> +
> +                     noext = F2FS_OPTION(sbi).noextensions;
> +                     noext_cnt = F2FS_OPTION(sbi).nocompress_ext_cnt;
> +
> +                     if (strlen(name) >= F2FS_EXTENSION_LEN ||
> +                             noext_cnt >= COMPRESS_EXT_NUM) {
> +                             f2fs_err(sbi,
> +                                     "invalid extension length/number");
> +                             kfree(name);
> +                             return -EINVAL;
> +                     }
> +
> +                     strcpy(noext[noext_cnt], name);
> +                     F2FS_OPTION(sbi).nocompress_ext_cnt++;
> +                     kfree(name);
> +                     break;
>               case Opt_compress_chksum:
>                       F2FS_OPTION(sbi).compress_chksum = true;
>                       break;
> @@ -1072,6 +1099,7 @@ static int parse_options(struct super_block *sb,
char *options, bool is_remount)
>               case Opt_compress_extension:
>               case Opt_compress_chksum:
>               case Opt_compress_mode:
> +             case Opt_nocompress_extension:
>                       f2fs_info(sbi, "compression options not supported");
>                       break;
>   #endif
> @@ -1664,7 +1692,10 @@ static inline void
f2fs_show_compress_options(struct seq_file *seq,
>               seq_printf(seq, ",compress_extension=%s",
>                       F2FS_OPTION(sbi).extensions[i]);
>       }
> -
> +     for (i = 0; i < F2FS_OPTION(sbi).nocompress_ext_cnt; i++) {
> +             seq_printf(seq, ",nocompress_extension=%s",
> +                     F2FS_OPTION(sbi).noextensions[i]);
> +     }
>       if (F2FS_OPTION(sbi).compress_chksum)
>               seq_puts(seq, ",compress_chksum");
> 
> --
> 2.29.0
> 
> 
> 
> _______________________________________________
> Linux-f2fs-devel mailing list
> [email protected]
> https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel
> .
> 




_______________________________________________
Linux-f2fs-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel

Reply via email to