]> git.ipfire.org Git - thirdparty/lxc.git/commitdiff
Pass through all options with -Bbest.
authorSidnei da Silva <sidnei.da.silva@canonical.com>
Tue, 22 Oct 2013 21:52:30 +0000 (19:52 -0200)
committerSerge Hallyn <serge.hallyn@ubuntu.com>
Tue, 22 Oct 2013 22:10:14 +0000 (17:10 -0500)
Remove the union in bdev_specs and store all options if -Bbest is passed. Fixes issue #31.

Signed-off-by: Sidnei da Silva <sidnei.da.silva@canonical.com>
Signed-off-by: Serge Hallyn <serge.hallyn@ubuntu.com>
src/lxc/bdev.c
src/lxc/bdev.h
src/lxc/lxc_create.c

index 62d3803a1c0c0544808379b86277bb0ecf5e678b..cfb7cff8235b511993e616e28643ee3e7e39e8f4 100644 (file)
@@ -707,10 +707,10 @@ static int zfs_create(struct bdev *bdev, const char *dest, const char *n,
        int ret;
        pid_t pid;
 
-       if (!specs || !specs->u.zfs.zfsroot)
+       if (!specs || !specs->zfs.zfsroot)
                zfsroot = default_zfs_root();
        else
-               zfsroot = specs->u.zfs.zfsroot;
+               zfsroot = specs->zfs.zfsroot;
 
        if (!(bdev->dest = strdup(dest))) {
                ERROR("No mount target specified or out of memory");
@@ -873,7 +873,7 @@ static int lvm_is_thin_pool(const char *path)
 static int do_lvm_create(const char *path, unsigned long size, const char *thinpool)
 {
        int ret, pid, len;
-       char sz[24], *pathdup, *vg, *lv, *tp;
+       char sz[24], *pathdup, *vg, *lv, *tp = NULL;
 
        if ((pid = fork()) < 0) {
                SYSERROR("failed fork");
@@ -901,33 +901,37 @@ static int do_lvm_create(const char *path, unsigned long size, const char *thinp
        lv++;
 
        vg = strrchr(pathdup, '/');
-       if (!vg)
+       if (!vg) {
+               free(pathdup);
                exit(1);
+       }
        vg++;
 
        if (thinpool) {
                len = strlen(pathdup) + strlen(thinpool) + 2;
                tp = alloca(len);
 
-               INFO("checking for thin pool at path: %s", tp);
                ret = snprintf(tp, len, "%s/%s", pathdup, thinpool);
-               if (ret < 0 || ret >= len)
-                       return -1;
+               if (ret < 0 || ret >= len) {
+                       free(pathdup);
+                       exit(1);
+               }
 
                ret = lvm_is_thin_pool(tp);
                INFO("got %d for thin pool at path: %s", ret, tp);
-               if (ret < 0)
-                       return ret;
+               if (ret < 0) {
+                       free(pathdup);
+                       exit(1);
+               }
 
                if (!ret)
-                       thinpool = NULL;
+                       tp = NULL;
        }
 
-
-       if (!thinpool) {
+       if (!tp) {
            execlp("lvcreate", "lvcreate", "-L", sz, vg, "-n", lv, (char *)NULL);
        } else {
-           execlp("lvcreate", "lvcreate", "--thinpool", thinpool, "-V", sz, vg, "-n", lv, (char *)NULL);
+           execlp("lvcreate", "lvcreate", "--thinpool", tp, "-V", sz, vg, "-n", lv, (char *)NULL);
        }
 
        free(pathdup);
@@ -1097,17 +1101,18 @@ static int lvm_create(struct bdev *bdev, const char *dest, const char *n,
        if (!specs)
                return -1;
 
-       vg = specs->u.lvm.vg;
+       vg = specs->lvm.vg;
        if (!vg)
                vg = default_lvm_vg();
 
-       thinpool = specs->u.lvm.thinpool;
+       thinpool = specs->lvm.thinpool;
        if (!thinpool)
                thinpool = default_lvm_thin_pool();
 
        /* /dev/$vg/$lv */
-       if (specs->u.lvm.lv)
-               lv = specs->u.lvm.lv;
+       if (specs->lvm.lv)
+               lv = specs->lvm.lv;
+
        len = strlen(vg) + strlen(lv) + 7;
        bdev->src = malloc(len);
        if (!bdev->src)
@@ -1117,8 +1122,8 @@ static int lvm_create(struct bdev *bdev, const char *dest, const char *n,
        if (ret < 0 || ret >= len)
                return -1;
 
-       // lvm.fssize is in bytes.
-       sz = specs->u.lvm.fssize;
+       // fssize is in bytes.
+       sz = specs->fssize;
        if (!sz)
                sz = DEFAULT_FS_SIZE;
 
@@ -1127,7 +1132,7 @@ static int lvm_create(struct bdev *bdev, const char *dest, const char *n,
                return -1;
        }
 
-       fstype = specs->u.lvm.fstype;
+       fstype = specs->fstype;
        if (!fstype)
                fstype = DEFAULT_FSTYPE;
        if (do_mkfs(bdev->src, fstype) < 0) {
@@ -1721,11 +1726,11 @@ static int loop_create(struct bdev *bdev, const char *dest, const char *n,
        if (ret < 0 || ret >= len + 5)
                return -1;
 
-       sz = specs->u.loop.fssize;
+       sz = specs->fssize;
        if (!sz)
                sz = DEFAULT_FS_SIZE;
 
-       fstype = specs->u.loop.fstype;
+       fstype = specs->fstype;
        if (!fstype)
                fstype = DEFAULT_FSTYPE;
 
index e10ea8e1c1406f465c7cf79c3050b3b50700c241..8c17117b4788d0cd4eb6ac877ab5240cf32ec39e 100644 (file)
@@ -37,22 +37,16 @@ struct bdev;
  * specifications for how to create a new backing store
  */
 struct bdev_specs {
-       union {
-               struct {
-                       char *zfsroot;
-               } zfs;
-               struct {
-                       char *vg;
-                       char *lv;
-                       char *fstype;
-                       unsigned long fssize;  // fs size in bytes
-                       char *thinpool; // lvm thin pool to use, if any
-               } lvm;
-               struct {
-                       char *fstype;
-                       unsigned long fssize; // fs size in bytes
-               } loop;
-       } u;
+       char *fstype;
+       unsigned long fssize;  // fs size in bytes
+       struct {
+               char *zfsroot;
+       } zfs;
+       struct {
+               char *vg;
+               char *lv;
+               char *thinpool; // lvm thin pool to use, if any
+       } lvm;
 };
 
 struct bdev_ops {
index f831da4c6880d69774df407e4b1d1d486d7e55c2..2345d97919bd8da91b2d2b6a2c8c394b6da3baf9 100644 (file)
@@ -147,23 +147,25 @@ Options :\n\
 
 bool validate_bdev_args(struct lxc_arguments *a)
 {
-       if (a->fstype || a->fssize) {
-               if (strcmp(a->bdevtype, "lvm") != 0 &&
-                   strcmp(a->bdevtype, "loop") != 0) {
-                       fprintf(stderr, "filesystem type and size are only valid with block devices\n");
-                       return false;
+       if (strcmp(a->bdevtype, "best") != 0) {
+               if (a->fstype || a->fssize) {
+                       if (strcmp(a->bdevtype, "lvm") != 0 &&
+                           strcmp(a->bdevtype, "loop") != 0) {
+                               fprintf(stderr, "filesystem type and size are only valid with block devices\n");
+                               return false;
+                       }
                }
-       }
-       if (strcmp(a->bdevtype, "lvm") != 0) {
-               if (a->lvname || a->vgname || a->thinpool) {
-                       fprintf(stderr, "--lvname, --vgname and --thinpool are only valid with -B lvm\n");
-                       return false;
+               if (strcmp(a->bdevtype, "lvm") != 0) {
+                       if (a->lvname || a->vgname || a->thinpool) {
+                               fprintf(stderr, "--lvname, --vgname and --thinpool are only valid with -B lvm\n");
+                               return false;
+                       }
                }
-       }
-       if (strcmp(a->bdevtype, "zfs") != 0) {
-               if (a->zfsroot) {
-                       fprintf(stderr, "zfsroot is only valid with -B zfs\n");
-                       return false;
+               if (strcmp(a->bdevtype, "zfs") != 0) {
+                       if (a->zfsroot) {
+                               fprintf(stderr, "zfsroot is only valid with -B zfs\n");
+                               return false;
+                       }
                }
        }
        return true;
@@ -217,26 +219,24 @@ int main(int argc, char *argv[])
        else
                c->load_config(c, LXC_DEFAULT_CONFIG);
 
-       if (strcmp(my_args.bdevtype, "zfs") == 0) {
+       if (my_args.fstype)
+               spec.fstype = my_args.fstype;
+       if (my_args.fssize)
+               spec.fssize = my_args.fssize;
+
+       if (strcmp(my_args.bdevtype, "zfs") == 0 || strcmp(my_args.bdevtype, "best") == 0) {
                if (my_args.zfsroot)
-                       spec.u.zfs.zfsroot = my_args.zfsroot;
-       } else if (strcmp(my_args.bdevtype, "lvm") == 0) {
+                       spec.zfs.zfsroot = my_args.zfsroot;
+       }
+       if (strcmp(my_args.bdevtype, "lvm") == 0 || strcmp(my_args.bdevtype, "best") == 0) {
                if (my_args.lvname)
-                       spec.u.lvm.lv = my_args.lvname;
+                       spec.lvm.lv = my_args.lvname;
                if (my_args.vgname)
-                       spec.u.lvm.vg = my_args.vgname;
+                       spec.lvm.vg = my_args.vgname;
                if (my_args.thinpool)
-                       spec.u.lvm.thinpool = my_args.thinpool;
-               if (my_args.fstype)
-                       spec.u.lvm.fstype = my_args.fstype;
-               if (my_args.fssize)
-                       spec.u.lvm.fssize = my_args.fssize;
-       } else if (strcmp(my_args.bdevtype, "loop") == 0) {
-               if (my_args.fstype)
-                       spec.u.loop.fstype = my_args.fstype;
-               if (my_args.fssize)
-                       spec.u.loop.fssize = my_args.fssize;
-       } else if (my_args.dir) {
+                       spec.lvm.thinpool = my_args.thinpool;
+       }
+       if (my_args.dir) {
                ERROR("--dir is not yet supported");
                exit(1);
        }