libf2fs,mkfs.f2fs: add wanted_sector_size for wanted_total_sectors
authorkatao <katao@xiaomi.com>
Tue, 27 Mar 2018 05:25:46 +0000 (13:25 +0800)
committerJaegeuk Kim <jaegeuk@kernel.org>
Tue, 3 Apr 2018 05:57:31 +0000 (22:57 -0700)
The wanted_total_sectors was determined by device sector size, but sometimes
we don't know precise sector_size by default. So, let's give wanted_sector_size
in such the ambiguous situation.

Signed-off-by: katao <katao@xiaomi.com>
Signed-off-by: Junling Zheng <zhengjunling@huawei.com>
Reviewed-by: Chao Yu <yuchao0@huawei.com>
Signed-off-by: Jaegeuk Kim <jaegeuk@google.com>
include/f2fs_fs.h
lib/libf2fs.c
man/mkfs.f2fs.8
mkfs/f2fs_format_main.c

index 053ccbe..2d75d39 100644 (file)
@@ -335,6 +335,7 @@ struct f2fs_configuration {
        u_int64_t device_size;
        u_int64_t total_sectors;
        u_int64_t wanted_total_sectors;
+       u_int64_t wanted_sector_size;
        u_int64_t target_sectors;
        u_int32_t sectors_per_blk;
        u_int32_t blks_per_seg;
index ffdbccb..bb7fe2e 100644 (file)
@@ -593,6 +593,7 @@ void f2fs_init_configuration(void)
        c.blks_per_seg = DEFAULT_BLOCKS_PER_SEGMENT;
        c.rootdev_name = get_rootdev();
        c.wanted_total_sectors = -1;
+       c.wanted_sector_size = -1;
        c.zoned_mode = 0;
        c.zoned_model = 0;
        c.zone_blocks = 0;
@@ -900,6 +901,18 @@ int get_device_info(int i)
                                dev->zone_blocks);
        }
 #endif
+       /* adjust wanted_total_sectors */
+       if (c.wanted_total_sectors != -1) {
+               MSG(0, "Info: wanted sectors = %"PRIu64" (in %"PRIu64" bytes)\n",
+                               c.wanted_total_sectors, c.wanted_sector_size);
+               if (c.wanted_sector_size == -1) {
+                       c.wanted_sector_size = dev->sector_size;
+               } else if (dev->sector_size != c.wanted_sector_size) {
+                       c.wanted_total_sectors *= c.wanted_sector_size;
+                       c.wanted_total_sectors /= dev->sector_size;
+               }
+       }
+
        c.total_sectors += dev->total_sectors;
        return 0;
 }
index c2f9c86..442c0ea 100644 (file)
@@ -53,6 +53,10 @@ mkfs.f2fs \- create an F2FS file system
 .I nodiscard/discard
 ]
 [
+.B \-w
+.I specific sector_size for target sectors
+]
+[
 .B \-z
 .I #-of-sections-per-zone
 ]
@@ -125,6 +129,10 @@ Specify 1 or 0 to enable/disable discard policy.
 If the value is equal to 1, discard policy is enabled, otherwise is disable.
 The default value is 1.
 .TP
+.BI \-w "sector-size"
+Specify the sector size in bytes along with given target sectors.
+Without it, the sectors will be calculated by device sector size.
+.TP
 .BI \-z " #-of-sections-per-zone"
 Specify the number of sections per zone. A zone consists of multiple sections.
 F2FS allocates segments for active logs with separated zones as much as possible.
index e522b2f..19f0854 100644 (file)
@@ -54,6 +54,7 @@ static void mkfs_usage()
        MSG(0, "  -s # of segments per section [default:1]\n");
        MSG(0, "  -S sparse mode\n");
        MSG(0, "  -t 0: nodiscard, 1: discard [default:1]\n");
+       MSG(0, "  -w wanted sector size\n");
        MSG(0, "  -z # of sections per zone [default:1]\n");
        MSG(0, "sectors: number of sectors. [default: determined by device size]\n");
        exit(1);
@@ -102,7 +103,7 @@ static void parse_feature(const char *features)
 
 static void f2fs_parse_options(int argc, char *argv[])
 {
-       static const char *option_string = "qa:c:d:e:l:mo:O:s:S:z:t:f";
+       static const char *option_string = "qa:c:d:e:l:mo:O:s:S:z:t:fw:";
        int32_t option=0;
 
        while ((option = getopt(argc,argv,option_string)) != EOF) {
@@ -166,6 +167,9 @@ static void f2fs_parse_options(int argc, char *argv[])
                case 'f':
                        force_overwrite = 1;
                        break;
+               case 'w':
+                       c.wanted_sector_size = atoi(optarg);
+                       break;
                default:
                        MSG(0, "\tError: Unknown option %c\n",option);
                        mkfs_usage();