Use parse_size_suffix in snapshot
authorSimon Marchi <simon.marchi@polymtl.ca>
Tue, 13 Aug 2013 18:22:31 +0000 (14:22 -0400)
committerDavid Goulet <dgoulet@efficios.com>
Fri, 23 Aug 2013 19:48:09 +0000 (15:48 -0400)
Signed-off-by: Simon Marchi <simon.marchi@polymtl.ca>
Signed-off-by: David Goulet <dgoulet@efficios.com>
doc/man/lttng.1
src/bin/lttng/commands/snapshot.c

index 0a74f9c505b5230a47257d835d6cc61e9acfe4a1..57c89f0fa96b99851d8e9093e0f8c42af6fc293b 100644 (file)
@@ -761,8 +761,9 @@ Apply to session name.
 Name of the snapshot's output.
 .TP
 .BR "\-m, \-\-max-size SIZE"
-Maximum size in bytes of the snapshot. The maxium size does not include
-the metadata file.
+Maximum size in bytes of the snapshot. The maxium size does not include the
+metadata file. Human readable format is accepted: {+k,+M,+G}. For instance,
+\-\-max-size 5M
 .TP
 .BR "\-C, \-\-ctrl-url URL"
 Set control path URL. (Must use -D also)
index 56acca8666cd7ee9910a0dcf70cbf0243e5d4c61..dd1137baa157c0c051256f4a71934a1de1ba3301 100644 (file)
@@ -26,6 +26,7 @@
 #include <sys/types.h>
 #include <unistd.h>
 
+#include <common/utils.h>
 #include <lttng/snapshot.h>
 
 #include "../command.h"
@@ -58,7 +59,7 @@ static struct poptOption snapshot_opts[] = {
        {"ctrl-url",     'C', POPT_ARG_STRING, &opt_ctrl_url, 0, 0, 0},
        {"data-url",     'D', POPT_ARG_STRING, &opt_data_url, 0, 0, 0},
        {"name",         'n', POPT_ARG_STRING, &opt_output_name, 0, 0, 0},
-       {"max-size",     'm', POPT_ARG_DOUBLE, 0, OPT_MAX_SIZE, 0, 0},
+       {"max-size",     'm', POPT_ARG_STRING, 0, OPT_MAX_SIZE, 0, 0},
        {"list-options",   0, POPT_ARG_NONE, NULL, OPT_LIST_OPTIONS, NULL, NULL},
        {0, 0, 0, 0, 0, 0, 0}
 };
@@ -100,7 +101,7 @@ static void usage(FILE *ofp)
        fprintf(ofp, "      --list-options   Simple listing of options\n");
        fprintf(ofp, "  -s, --session NAME   Apply to session name\n");
        fprintf(ofp, "  -n, --name NAME      Name of the output or snapshot\n");
-       fprintf(ofp, "  -m, --max-size SIZE  Maximum bytes size of the snapshot\n");
+       fprintf(ofp, "  -m, --max-size SIZE  Maximum bytes size of the snapshot {+k,+M,+G}\n");
        fprintf(ofp, "  -C, --ctrl-url URL   Set control path URL. (Must use -D also)\n");
        fprintf(ofp, "  -D, --data-url URL   Set data path URL. (Must use -C also)\n");
        fprintf(ofp, "\n");
@@ -441,25 +442,15 @@ int cmd_snapshot(int argc, const char **argv)
                        goto end;
                case OPT_MAX_SIZE:
                {
-                       long long int val;
-                       char *endptr;
+                       uint64_t val;
                        const char *opt = poptGetOptArg(pc);
 
-                       /* Documented by the man page of strtoll(3). */
-                       errno = 0;
-                       val = strtoll(opt, &endptr, 10);
-                       if ((errno == ERANGE && (val == LLONG_MAX || val == LONG_MIN))
-                                       || (errno != 0 && val == 0)) {
+                       if (utils_parse_size_suffix((char *) opt, &val) < 0) {
                                ERR("Unable to handle max-size value %s", opt);
                                ret = CMD_ERROR;
                                goto end;
                        }
 
-                       if (endptr == opt) {
-                               ERR("No digits were found in %s", opt);
-                               ret = CMD_ERROR;
-                               goto end;
-                       }
                        opt_max_size = val;
 
                        break;
This page took 0.028536 seconds and 5 git commands to generate.