Skip to content

Commit

Permalink
Revert "storage: prefix all zfs paths"
Browse files Browse the repository at this point in the history
This reverts commit aa7802e.

Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
  • Loading branch information
Christian Brauner committed Aug 15, 2017
1 parent 4e30cce commit efb1059
Showing 1 changed file with 23 additions and 54 deletions.
77 changes: 23 additions & 54 deletions src/lxc/bdev/lxczfs.c
Expand Up @@ -85,23 +85,20 @@ int zfs_detect(const char *path)

int zfs_mount(struct bdev *bdev)
{
int ret;
char *mntdata, *src;
unsigned long mntflags;

if (strcmp(bdev->type, "zfs"))
return -22;

if (!bdev->src || !bdev->dest)
return -22;

char *mntdata;
unsigned long mntflags;
if (parse_mntopts(bdev->mntopts, &mntflags, &mntdata) < 0) {
free(mntdata);
return -22;
}

src = lxc_storage_get_path(bdev->src, bdev->type);
ret = mount(src, bdev->dest, "bind", MS_BIND | MS_REC | mntflags, mntdata);
int ret = mount(bdev->src, bdev->dest, "bind", MS_BIND | MS_REC | mntflags, mntdata);
free(mntdata);

return ret;
Expand Down Expand Up @@ -208,7 +205,6 @@ int zfs_clonepaths(struct bdev *orig, struct bdev *new, const char *oldname,
const char *cname, const char *oldpath, const char *lxcpath, int snap,
uint64_t newsize, struct lxc_conf *conf)
{
char *origsrc, *newsrc;
int len, ret;

if (!orig->src || !orig->dest)
Expand All @@ -219,22 +215,19 @@ int zfs_clonepaths(struct bdev *orig, struct bdev *new, const char *oldname,
return -1;
}

len = strlen(lxcpath) + strlen(cname) + strlen("rootfs") + 4 + 3;
len = strlen(lxcpath) + strlen(cname) + strlen("rootfs") + 3;
new->src = malloc(len);
if (!new->src)
return -1;

ret = snprintf(new->src, len, "zfs:%s/%s/rootfs", lxcpath, cname);
ret = snprintf(new->src, len, "%s/%s/rootfs", lxcpath, cname);
if (ret < 0 || ret >= len)
return -1;

newsrc = lxc_storage_get_path(new->src, new->type);
new->dest = strdup(newsrc);
if (!new->dest)
if ((new->dest = strdup(new->src)) == NULL)
return -1;

origsrc = lxc_storage_get_path(orig->src, orig->type);
return zfs_clone(origsrc, newsrc, oldname, cname, lxcpath, snap);
return zfs_clone(orig->src, new->src, oldname, cname, lxcpath, snap);
}

/*
Expand All @@ -246,15 +239,14 @@ int zfs_destroy(struct bdev *orig)
{
pid_t pid;
char output[MAXPATHLEN];
char *p, *src;
char *p;

if ((pid = fork()) < 0)
return -1;
if (pid)
return wait_for_pid(pid);

src = lxc_storage_get_path(orig->src, orig->type);
if (!zfs_list_entry(src, output, MAXPATHLEN)) {
if (!zfs_list_entry(orig->src, output, MAXPATHLEN)) {
ERROR("Error: zfs entry for %s not found", orig->src);
return -1;
}
Expand All @@ -268,64 +260,41 @@ int zfs_destroy(struct bdev *orig)
exit(EXIT_FAILURE);
}

struct zfs_exec_args {
char *dataset;
char *options;
};

int zfs_create_exec_wrapper(void *args)
{
struct zfs_exec_args *zfs_args = args;

execlp("zfs", "zfs", "create", zfs_args->options, zfs_args->dataset,
(char *)NULL);
return -1;
}

int zfs_create(struct bdev *bdev, const char *dest, const char *n,
struct bdev_specs *specs)
{
const char *zfsroot;
char cmd_output[MAXPATHLEN], dev[MAXPATHLEN], option[MAXPATHLEN];
char option[MAXPATHLEN];
int ret;
size_t len;
struct zfs_exec_args cmd_args;
pid_t pid;

if (!specs || !specs->zfs.zfsroot)
zfsroot = lxc_global_config_value("lxc.bdev.zfs.root");
else
zfsroot = specs->zfs.zfsroot;

bdev->dest = strdup(dest);
if (!bdev->dest) {
if (!(bdev->dest = strdup(dest))) {
ERROR("No mount target specified or out of memory");
return -1;
}

len = strlen(bdev->dest) + 1;
/* strlen("zfs:") */
len += 4;
bdev->src = malloc(len);
if (!bdev->src)
return -1;

ret = snprintf(bdev->src, len, "zfs:%s", bdev->dest);
if (ret < 0 || (size_t)ret >= len)
if (!(bdev->src = strdup(bdev->dest))) {
ERROR("out of memory");
return -1;
}

ret = snprintf(option, MAXPATHLEN, "-omountpoint=%s", bdev->dest);
if (ret < 0 || ret >= MAXPATHLEN)
return -1;
if ((pid = fork()) < 0)
return -1;
if (pid)
return wait_for_pid(pid);

char dev[MAXPATHLEN];
ret = snprintf(dev, MAXPATHLEN, "%s/%s", zfsroot, n);
if (ret < 0 || ret >= MAXPATHLEN)
return -1;
exit(EXIT_FAILURE);

cmd_args.options = option;
cmd_args.dataset = dev;
ret = run_command(cmd_output, sizeof(cmd_output),
zfs_create_exec_wrapper, (void *)&cmd_args);
if (ret < 0)
ERROR("Failed to create zfs dataset \"%s\": %s", dev, cmd_output);
return ret;
execlp("zfs", "zfs", "create", option, dev, (char *)NULL);
exit(EXIT_FAILURE);
}

0 comments on commit efb1059

Please sign in to comment.