f2fs-tools: support to set and recognize CP_TRIMMED_FLAG
authorChao Yu <yuchao0@huawei.com>
Fri, 28 Apr 2017 09:16:31 +0000 (17:16 +0800)
committerJaegeuk Kim <jaegeuk@kernel.org>
Fri, 28 Apr 2017 19:04:21 +0000 (12:04 -0700)
During mkfs, once we have issued discard for all device, we can set
CP_TRIMMED_FLAG in cp pack, this can make kernel module to record
undiscard blocks correctly, it will help to avoid unneeded discard.

Also this patch makes f2fs-tools be with the ability of recognizing
that new flag.

Signed-off-by: Chao Yu <yuchao0@huawei.com>
Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
fsck/mount.c
include/f2fs_fs.h
lib/libf2fs.c
mkfs/f2fs_format.c
mkfs/f2fs_format_utils.c

index 6350ad6..a0b0bea 100644 (file)
@@ -259,6 +259,8 @@ void print_cp_state(u32 flag)
                MSG(0, "%s", " fastboot");
        if (flag & CP_NAT_BITS_FLAG)
                MSG(0, "%s", " nat_bits");
+       if (flag & CP_TRIMMED_FLAG)
+               MSG(0, "%s", " trimmed");
        if (flag & CP_UMOUNT_FLAG)
                MSG(0, "%s", " unmount");
        else
index fa9d536..43760d4 100644 (file)
@@ -287,6 +287,7 @@ struct f2fs_configuration {
        int dbg_lv;
        int show_dentry;
        int trim;
+       int trimmed;
        int func;
        void *private;
        int fix_on;
@@ -515,6 +516,7 @@ struct f2fs_super_block {
 /*
  * For checkpoint
  */
+#define CP_TRIMMED_FLAG                0x00000100
 #define CP_NAT_BITS_FLAG       0x00000080
 #define CP_CRC_RECOVERY_FLAG   0x00000040
 #define CP_FASTBOOT_FLAG       0x00000020
index 7352837..c96506a 100644 (file)
@@ -571,6 +571,7 @@ void f2fs_init_configuration(void)
        c.heap = 0;
        c.vol_label = "";
        c.trim = 1;
+       c.trimmed = 0;
        c.ro = 0;
        c.kd = -1;
 }
index d354c88..2e9c19a 100644 (file)
@@ -579,6 +579,10 @@ static int f2fs_write_check_point_pack(void)
        if (get_cp(cp_pack_total_block_count) <=
                        (1 << get_sb(log_blocks_per_seg)) - nat_bits_blocks)
                flags |= CP_NAT_BITS_FLAG;
+
+       if (c.trimmed)
+               flags |= CP_TRIMMED_FLAG;
+
        set_cp(ckpt_flags, flags);
        set_cp(cp_pack_start_sum, 1 + get_sb(cp_payload));
        set_cp(valid_node_count, 1);
index fc80ec6..558684d 100644 (file)
@@ -90,5 +90,6 @@ int f2fs_trim_devices(void)
        for (i = 0; i < c.ndevs; i++)
                if (trim_device(i))
                        return -1;
+       c.trimmed = 1;
        return 0;
 }