Skip to content

Commit 52af152

Browse files
committed
flux-filemap: use optparse_get_size_int() for size options
Problem: The flux-filemap(1) --chunksize and --small-file-threshold options take arguments in bytes, but do not support common suffixes like k, K, M, or G. This makes the options more cumbersome to use than necessary. Use optparse_get_size_int() to fetch the value of these options, which allows the argument to be specified as a floating point number with optional suffix in the set [kKMG] (up to but not including 2G).
1 parent aeb9aee commit 52af152

File tree

1 file changed

+12
-10
lines changed

1 file changed

+12
-10
lines changed

src/cmd/builtin/filemap.c

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,8 @@
2929
#include "src/common/libfilemap/filemap.h"
3030
#include "src/common/libutil/fileref.h"
3131

32-
static const int default_chunksize = 1048576;
33-
static const int default_small_file_threshold = 4096;
32+
static const char *default_chunksize = "1M";
33+
static const char *default_small_file_threshold = "4K";
3434

3535
static json_t *get_list_option (optparse_t *p,
3636
const char *name,
@@ -175,10 +175,12 @@ static int subcmd_map (optparse_t *p, int ac, char *av[])
175175
}
176176
ctx.p = p;
177177
ctx.verbose = optparse_get_int (p, "verbose", 0);
178-
ctx.chunksize = optparse_get_int (p, "chunksize", default_chunksize);
179-
ctx.threshold = optparse_get_int (p,
180-
"small-file-threshold",
181-
default_small_file_threshold);
178+
ctx.chunksize = optparse_get_size_int (p,
179+
"chunksize",
180+
default_chunksize);
181+
ctx.threshold = optparse_get_size_int (p,
182+
"small-file-threshold",
183+
default_small_file_threshold);
182184
ctx.disable_mmap = optparse_hasopt (p, "disable-mmap");
183185
ctx.tags = get_list_option (p, "tags", "main");
184186
ctx.h = builtin_get_flux_handle (p);
@@ -375,12 +377,12 @@ static struct optparse_option map_opts[] = {
375377
.usage = "Change to DIR before mapping", },
376378
{ .name = "verbose", .key = 'v', .has_arg = 2, .arginfo = "[LEVEL]",
377379
.usage = "Increase output detail.", },
378-
{ .name = "chunksize", .has_arg = 1, .arginfo = "N",
380+
{ .name = "chunksize", .has_arg = 1, .arginfo = "N[KMG]",
379381
.usage = "Limit blob size to N bytes with 0=unlimited"
380-
" (default 1048576)", },
381-
{ .name = "small-file-threshold", .has_arg = 1, .arginfo = "N",
382+
" (default 1M)", },
383+
{ .name = "small-file-threshold", .has_arg = 1, .arginfo = "N[KMG]",
382384
.usage = "Adjust the maximum size of a \"small file\" in bytes"
383-
" (default 4096)", },
385+
" (default 4K)", },
384386
{ .name = "disable-mmap", .has_arg = 0,
385387
.usage = "Never mmap(2) files into the content cache", },
386388
{ .name = "tags", .key = 'T', .has_arg = 1, .arginfo = "NAME,...",

0 commit comments

Comments
 (0)