[Lxc-users] [PATCH] lxc_clone.c (was: lxc-clone -B lvm -L, bug?)

zoolook nbensa+lxcusers at gmail.com
Thu Jul 11 02:17:52 UTC 2013


Hello Serge,

On Wed, Jul 10, 2013 at 12:09 PM, zoolook <nbensa+lxcusers at gmail.com> wrote:
>>> "lxc-clone -L" accepts size _only_ in B. In other words, ignores G.
>>
>> Yup.  You can see the local functions for parsing the fssize in
>> lxc_clone.c and lxc_create.c.  Patch to commonize and improve them
>> would be very welcome.
>
> Thanks. I'll take a look when I get back home.

For now, I copied get_fssize from lxc_create.c to lxc_clone.c (patch
bellow), but my intention is to move the function to utils.c or some
other file and support both SI a binary sizes (GB vs GiB). 2G would be
2GB (2*1000**3 bytes, current behavior) and 2g would be 2GiB
(2*1024**3). Is this ok for everyone?

Thanks!

--- lxc.orig/lxc-0.9.0.0~staging~20130708-2041/src/lxc/lxc_clone.c
 2013-07-08 17:46:33.000000000 -0300
+++ lxc.new/lxc-0.9.0.0~staging~20130708-2041/src/lxc/lxc_clone.c
 2013-07-10 23:06:07.156501219 -0300
@@ -6,6 +6,7 @@
 #include <sys/wait.h>
 #include <stdlib.h>
 #include <errno.h>
+#include <ctype.h>

 #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 @@
                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;




More information about the lxc-users mailing list