Commit 3858c11b by KATOH Yasufumi Committed by Stéphane Graber

Fix clone issues

This commit fixes two issues at the time of clone: * unnecessary directory is created when clone between overlayfs/aufs * clone failed when the end of rootfs path is not "/rootfs" Signed-off-by: 's avatarKATOH Yasufumi <karma@jazz.email.ne.jp> Acked-by: 's avatarSerge E. Hallyn <serge.hallyn@ubuntu.com>
parent b73d3bbc
...@@ -3012,6 +3012,7 @@ struct bdev *bdev_copy(struct lxc_container *c0, const char *cname, ...@@ -3012,6 +3012,7 @@ struct bdev *bdev_copy(struct lxc_container *c0, const char *cname,
const char *oldname = c0->name; const char *oldname = c0->name;
const char *oldpath = c0->config_path; const char *oldpath = c0->config_path;
struct rsync_data data; struct rsync_data data;
char *rootfs;
/* if the container name doesn't show up in the rootfs path, then /* if the container name doesn't show up in the rootfs path, then
* we don't know how to come up with a new name * we don't know how to come up with a new name
...@@ -3022,12 +3023,35 @@ struct bdev *bdev_copy(struct lxc_container *c0, const char *cname, ...@@ -3022,12 +3023,35 @@ struct bdev *bdev_copy(struct lxc_container *c0, const char *cname,
return NULL; return NULL;
} }
orig = bdev_init(src, src, NULL); orig = bdev_init(src, NULL, NULL);
if (!orig) { if (!orig) {
ERROR("failed to detect blockdev type for %s", src); ERROR("failed to detect blockdev type for %s", src);
return NULL; return NULL;
} }
if (!orig->dest) {
int ret;
orig->dest = malloc(MAXPATHLEN);
if (!orig->dest) {
ERROR("out of memory");
bdev_put(orig);
return NULL;
}
rootfs = strrchr(orig->src, '/');
if (!rootfs) {
ERROR("invalid rootfs path");
bdev_put(orig);
return NULL;
}
rootfs++;
ret = snprintf(orig->dest, MAXPATHLEN, "%s/%s/%s", oldpath, oldname, rootfs);
if (ret < 0 || ret >= MAXPATHLEN) {
ERROR("rootfs path too long");
bdev_put(orig);
return NULL;
}
}
/* /*
* special case for snapshot - if caller requested maybe_snapshot and * special case for snapshot - if caller requested maybe_snapshot and
* keepbdevtype and backing store is directory, then proceed with a copy * keepbdevtype and backing store is directory, then proceed with a copy
......
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