Unverified Commit 276fb978 by Christian Brauner Committed by Stéphane Graber

storage: prefix all dir paths

parent ef72d7d6
...@@ -306,6 +306,7 @@ struct bdev *bdev_copy(struct lxc_container *c0, const char *cname, ...@@ -306,6 +306,7 @@ struct bdev *bdev_copy(struct lxc_container *c0, const char *cname,
struct bdev *orig, *new; struct bdev *orig, *new;
pid_t pid; pid_t pid;
int ret; int ret;
char *src_no_prefix;
bool snap = flags & LXC_CLONE_SNAPSHOT; bool snap = flags & LXC_CLONE_SNAPSHOT;
bool maybe_snap = flags & LXC_CLONE_MAYBE_SNAPSHOT; bool maybe_snap = flags & LXC_CLONE_MAYBE_SNAPSHOT;
bool keepbdevtype = flags & LXC_CLONE_KEEPBDEVTYPE; bool keepbdevtype = flags & LXC_CLONE_KEEPBDEVTYPE;
...@@ -402,7 +403,9 @@ struct bdev *bdev_copy(struct lxc_container *c0, const char *cname, ...@@ -402,7 +403,9 @@ struct bdev *bdev_copy(struct lxc_container *c0, const char *cname,
goto err; goto err;
} }
if (am_unpriv() && chown_mapped_root(new->src, c0->lxc_conf) < 0) src_no_prefix = lxc_storage_get_path(new->src, new->type);
if (am_unpriv() && chown_mapped_root(src_no_prefix, c0->lxc_conf) < 0)
WARN("Failed to update ownership of %s", new->dest); WARN("Failed to update ownership of %s", new->dest);
if (snap) if (snap)
...@@ -456,6 +459,8 @@ struct bdev *bdev_copy(struct lxc_container *c0, const char *cname, ...@@ -456,6 +459,8 @@ struct bdev *bdev_copy(struct lxc_container *c0, const char *cname,
"rsync_rootfs_wrapper"); "rsync_rootfs_wrapper");
else else
ret = rsync_rootfs(&data); ret = rsync_rootfs(&data);
if (ret < 0)
ERROR("Failed to rsync");
exit(ret == 0 ? 0 : 1); exit(ret == 0 ? 0 : 1);
......
...@@ -39,7 +39,8 @@ int dir_clonepaths(struct bdev *orig, struct bdev *new, const char *oldname, ...@@ -39,7 +39,8 @@ int dir_clonepaths(struct bdev *orig, struct bdev *new, const char *oldname,
const char *cname, const char *oldpath, const char *lxcpath, const char *cname, const char *oldpath, const char *lxcpath,
int snap, uint64_t newsize, struct lxc_conf *conf) int snap, uint64_t newsize, struct lxc_conf *conf)
{ {
int len, ret; int ret;
size_t len;
if (snap) { if (snap) {
ERROR("directories cannot be snapshotted. Try aufs or overlayfs."); ERROR("directories cannot be snapshotted. Try aufs or overlayfs.");
...@@ -49,38 +50,58 @@ int dir_clonepaths(struct bdev *orig, struct bdev *new, const char *oldname, ...@@ -49,38 +50,58 @@ int dir_clonepaths(struct bdev *orig, struct bdev *new, const char *oldname,
if (!orig->dest || !orig->src) if (!orig->dest || !orig->src)
return -1; return -1;
len = strlen(lxcpath) + strlen(cname) + strlen("rootfs") + 3; len = strlen(lxcpath) + strlen(cname) + strlen("rootfs") + 4 + 3;
new->src = malloc(len); new->src = malloc(len);
if (!new->src) if (!new->src)
return -1; return -1;
ret = snprintf(new->src, len, "%s/%s/rootfs", lxcpath, cname);
if (ret < 0 || ret >= len) ret = snprintf(new->src, len, "dir:%s/%s/rootfs", lxcpath, cname);
if (ret < 0 || (size_t)ret >= len)
return -1; return -1;
if ((new->dest = strdup(new->src)) == NULL)
new->dest = strdup(new->src + 4);
if (!new->dest)
return -1; return -1;
return 0; return 0;
} }
int dir_create(struct bdev *bdev, const char *dest, const char *n, int dir_create(struct bdev *bdev, const char *dest, const char *n,
struct bdev_specs *specs) struct bdev_specs *specs)
{ {
int ret;
const char *src;
size_t len;
/* strlen("dir:") */
len = 4;
if (specs && specs->dir) if (specs && specs->dir)
bdev->src = strdup(specs->dir); src = specs->dir;
else else
bdev->src = strdup(dest); src = dest;
len += strlen(src) + 1;
bdev->src = malloc(len);
if (!bdev->src)
return -1;
ret = snprintf(bdev->src, len, "dir:%s", src);
if (ret < 0 || (size_t)ret >= len)
return -1;
bdev->dest = strdup(dest); bdev->dest = strdup(dest);
if (!bdev->src || !bdev->dest) { if (!bdev->dest)
ERROR("Out of memory");
return -1; return -1;
}
if (mkdir_p(bdev->src, 0755) < 0) { ret = mkdir_p(src, 0755);
ERROR("Error creating %s", bdev->src); if (ret < 0) {
ERROR("Failed to create %s", src);
return -1; return -1;
} }
if (mkdir_p(bdev->dest, 0755) < 0) {
ERROR("Error creating %s", bdev->dest); ret = mkdir_p(bdev->dest, 0755);
if (ret < 0) {
ERROR("Failed to create %s", bdev->dest);
return -1; return -1;
} }
...@@ -89,8 +110,13 @@ int dir_create(struct bdev *bdev, const char *dest, const char *n, ...@@ -89,8 +110,13 @@ int dir_create(struct bdev *bdev, const char *dest, const char *n,
int dir_destroy(struct bdev *orig) int dir_destroy(struct bdev *orig)
{ {
if (lxc_rmdir_onedev(orig->src, NULL) < 0) char *src;
src = lxc_storage_get_path(orig->src, orig->src);
if (lxc_rmdir_onedev(src, NULL) < 0)
return -1; return -1;
return 0; return 0;
} }
...@@ -100,17 +126,19 @@ int dir_detect(const char *path) ...@@ -100,17 +126,19 @@ int dir_detect(const char *path)
return 1; // take their word for it return 1; // take their word for it
if (is_dir(path)) if (is_dir(path))
return 1; return 1;
return 0; return 0;
} }
int dir_mount(struct bdev *bdev) int dir_mount(struct bdev *bdev)
{ {
unsigned long mntflags; unsigned long mntflags;
char *mntdata; char *src, *mntdata;
int ret; int ret;
if (strcmp(bdev->type, "dir")) if (strcmp(bdev->type, "dir"))
return -22; return -22;
if (!bdev->src || !bdev->dest) if (!bdev->src || !bdev->dest)
return -22; return -22;
...@@ -119,7 +147,9 @@ int dir_mount(struct bdev *bdev) ...@@ -119,7 +147,9 @@ int dir_mount(struct bdev *bdev)
return -22; return -22;
} }
ret = mount(bdev->src, bdev->dest, "bind", MS_BIND | MS_REC | mntflags, mntdata); src = lxc_storage_get_path(bdev->src, bdev->type);
ret = mount(src, bdev->dest, "bind", MS_BIND | MS_REC | mntflags, mntdata);
free(mntdata); free(mntdata);
return ret; return ret;
} }
...@@ -128,7 +158,9 @@ int dir_umount(struct bdev *bdev) ...@@ -128,7 +158,9 @@ int dir_umount(struct bdev *bdev)
{ {
if (strcmp(bdev->type, "dir")) if (strcmp(bdev->type, "dir"))
return -22; return -22;
if (!bdev->src || !bdev->dest) if (!bdev->src || !bdev->dest)
return -22; return -22;
return umount(bdev->dest); return umount(bdev->dest);
} }
...@@ -139,4 +139,3 @@ int rsync_rootfs_wrapper(void *data) ...@@ -139,4 +139,3 @@ int rsync_rootfs_wrapper(void *data)
struct rsync_data *arg = data; struct rsync_data *arg = data;
return rsync_rootfs(arg); return rsync_rootfs(arg);
} }
...@@ -1265,8 +1265,10 @@ static bool create_run_template(struct lxc_container *c, char *tpath, bool need_ ...@@ -1265,8 +1265,10 @@ static bool create_run_template(struct lxc_container *c, char *tpath, bool need_
exit(1); exit(1);
} }
} else { // TODO come up with a better way here! } else { // TODO come up with a better way here!
char *src;
free(bdev->dest); free(bdev->dest);
bdev->dest = strdup(bdev->src); src = lxc_storage_get_path(bdev->src, bdev->type);
bdev->dest = strdup(src);
} }
/* /*
...@@ -1431,7 +1433,7 @@ static bool create_run_template(struct lxc_container *c, char *tpath, bool need_ ...@@ -1431,7 +1433,7 @@ static bool create_run_template(struct lxc_container *c, char *tpath, bool need_
} }
/* execute */ /* execute */
execvp(tpath, newargv); execvp(tpath, newargv);
SYSERROR("failed to execute template %s", tpath); SYSERROR("Failed to execute template %s", tpath);
exit(1); exit(1);
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment