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>
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");
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");
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);
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)
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;
return -1;
}
- fstype = specs->u.lvm.fstype;
+ fstype = specs->fstype;
if (!fstype)
fstype = DEFAULT_FSTYPE;
if (do_mkfs(bdev->src, fstype) < 0) {
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;
* 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 {
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;
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);
}