From: zoolook Date: Thu, 11 Jul 2013 23:38:02 +0000 (-0300) Subject: lxc_clone.c: Allow size subfixes for -L parameter X-Git-Tag: lxc-1.0.0.alpha1~1^2~126 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=ae13ae0853a246119ddaf9c8cc6d128a21a8988c;p=thirdparty%2Flxc.git lxc_clone.c: Allow size subfixes for -L parameter lxc-clone ignores size subfixes (K, M, G) when using -L parameter. The following is a quick patch to allow, for example, lxc-clone -L 10G. Signed-off-by: Norberto Bensa Acked-by: Serge E. Hallyn Signed-off-by: Serge Hallyn --- diff --git a/src/lxc/lxc_clone.c b/src/lxc/lxc_clone.c index b29b6217d..75ef1bd32 100644 --- a/src/lxc/lxc_clone.c +++ b/src/lxc/lxc_clone.c @@ -6,6 +6,7 @@ #include #include #include +#include #include "log.h" #include "config.h" @@ -16,6 +17,27 @@ lxc_log_define(lxc_clone, lxc); +static unsigned long get_fssize(char *s) +{ + unsigned long ret; + char *end; + + ret = strtoul(s, &end, 0); + if (end == s) + return 0; + while (isblank(*end)) + end++; + if (!(*end)) + return ret; + if (*end == 'g' || *end == 'G') + ret *= 1000000000; + else if (*end == 'm' || *end == 'M') + ret *= 1000000; + else if (*end == 'k' || *end == 'K') + ret *= 1000; + return ret; +} + void usage(const char *me) { printf("Usage: %s [-s] [-B backingstore] [-L size] [-K] [-M] [-H]\n", me); @@ -73,7 +95,7 @@ int main(int argc, char *argv[]) switch (c) { case 's': snapshot = 1; break; case 'B': bdevtype = optarg; break; - case 'L': newsize = atol(optarg); break; + case 'L': newsize = get_fssize(optarg); break; case 'o': orig = optarg; break; case 'n': new = optarg; break; case 'v': vgname = optarg; break;