]> git.ipfire.org Git - thirdparty/lxc.git/commitdiff
clone_paths: use 'rootfs' for destination directory
authorSerge Hallyn <serge.hallyn@ubuntu.com>
Thu, 29 Jan 2015 16:09:45 +0000 (16:09 +0000)
committerStéphane Graber <stgraber@ubuntu.com>
Thu, 29 Jan 2015 16:55:10 +0000 (17:55 +0100)
We were trying to be smart and use whatever the last part of
the container's rootfs path was.  However for block devices
that doesn't make much sense.  I.e. if lxc.rootfs = /dev/md-1,
chances are that /var/lib/lxc/c1/md-1 does not exist.

So always use the $lxcpath/$lxcname/rootfs, and if it does
not exist, try to create it.

With this, 'lxc-clone -s -o c1 -n c2' where c1 has an lvm backend
is fixed.  See https://bugs.launchpad.net/ubuntu/+source/lxc/+bug/1414771

Signed-off-by: Serge Hallyn <serge.hallyn@ubuntu.com>
Acked-by: Stéphane Graber <stgraber@ubuntu.com>
src/lxc/bdev.c

index 721a72b3713794cc881f2d9346acbf19cdcc9d3e..197ab55e9021f41bf2f392f406153827f05e8215 100644 (file)
@@ -3340,7 +3340,6 @@ struct bdev *bdev_copy(struct lxc_container *c0, const char *cname,
        const char *oldname = c0->name;
        const char *oldpath = c0->config_path;
        struct rsync_data data;
-       char *rootfs;
 
        /* 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
@@ -3359,25 +3358,26 @@ struct bdev *bdev_copy(struct lxc_container *c0, const char *cname,
 
        if (!orig->dest) {
                int ret;
-               orig->dest = malloc(MAXPATHLEN);
+               size_t len;
+               struct stat sb;
+
+               len = strlen(oldpath) + strlen(oldname) + strlen("/rootfs") + 2;
+               orig->dest = malloc(len);
                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) {
+               ret = snprintf(orig->dest, len, "%s/%s/rootfs", oldpath, oldname);
+               if (ret < 0 || ret >= len) {
                        ERROR("rootfs path too long");
                        bdev_put(orig);
                        return NULL;
                }
+               ret = stat(orig->dest, &sb);
+               if (ret < 0 && errno == ENOENT)
+                       if (mkdir_p(orig->dest, 0755) < 0)
+                               WARN("Error creating '%s', continuing.", orig->dest);
        }
 
        /*