]> git.ipfire.org Git - thirdparty/lxc.git/commitdiff
Revert "btrfs: simplify + bugfix"
authorChristian Brauner <christian.brauner@ubuntu.com>
Tue, 15 Aug 2017 16:14:59 +0000 (18:14 +0200)
committerChristian Brauner <christian.brauner@ubuntu.com>
Tue, 15 Aug 2017 16:45:27 +0000 (18:45 +0200)
This reverts commit 874a329ca6fd92057a3d243bfa6200906051393a.

Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
src/lxc/bdev/bdev.c
src/lxc/bdev/lxcbtrfs.c

index e41c6e8083fab21343e8f9415ed380f4261ce8df..65491f01658d165b05fefcbdadeb6cfdd952c751 100644 (file)
@@ -392,7 +392,7 @@ struct bdev *bdev_copy(struct lxc_container *c0, const char *cname,
                *needs_rdep = 1;
        }
 
-       if (strcmp(oldpath, lxcpath) && !bdevtype && !snap)
+       if (strcmp(oldpath, lxcpath) && !bdevtype)
                bdevtype = "dir";
        else if (!bdevtype)
                bdevtype = orig->type;
@@ -403,7 +403,6 @@ struct bdev *bdev_copy(struct lxc_container *c0, const char *cname,
                bdev_put(orig);
                return NULL;
        }
-       TRACE("Detected \"%s\" storage driver", new->type);
 
        if (new->ops->clone_paths(orig, new, oldname, cname, oldpath, lxcpath,
                                  snap, newsize, c0->lxc_conf) < 0) {
index 2e2b603a8dd449124f938bf7851c1a19ca0c0016..add3c2047b83abe2606d12d3bf135ba64fe6562d 100644 (file)
@@ -32,7 +32,6 @@
 #include <unistd.h>
 #include <sys/ioctl.h>
 #include <sys/stat.h>
-#include <sys/wait.h>
 #include <sys/types.h>
 #include <sys/vfs.h>
 
 #include "log.h"
 #include "lxcbtrfs.h"
 #include "lxcrsync.h"
-#include "../utils.h"
+#include "utils.h"
 
 lxc_log_define(lxcbtrfs, lxc);
 
+/* defined in lxccontainer.c: needs to become common helper */
+extern char *dir_new_path(char *src, const char *oldname, const char *name,
+                         const char *oldpath, const char *lxcpath);
+
 /*
  * Return the full path of objid under dirid.  Let's say dirid is
  * /lxc/c1/rootfs, and objid is /lxc/c1/rootfs/a/b/c.  Then we will
@@ -374,19 +377,29 @@ int btrfs_clonepaths(struct bdev *orig, struct bdev *new, const char *oldname,
        if (!orig->dest || !orig->src)
                return -1;
 
-       if (strcmp(orig->type, "btrfs") && snap) {
-               ERROR("btrfs snapshot from %s backing store is not supported",
-                     orig->type);
-               return -1;
-       }
+       if (strcmp(orig->type, "btrfs")) {
+               int len, ret;
+               if (snap) {
+                       ERROR("btrfs snapshot from %s backing store is not supported",
+                               orig->type);
+                       return -1;
+               }
 
-       new->src = lxc_string_join(
-           "/",
-           (const char *[]){"btrfs:", *lxcpath != '/' ? lxcpath : ++lxcpath,
-                            cname, "rootfs", NULL},
-           false);
-       if (!new->src)
-               return -1;
+               len = strlen(lxcpath) + strlen(cname) + strlen("rootfs") + 6 + 3;
+               new->src = malloc(len);
+               if (!new->src)
+                       return -1;
+
+               ret = snprintf(new->src, len, "btrfs:%s/%s/rootfs", lxcpath, cname);
+               if (ret < 0 || ret >= len)
+                       return -1;
+       } else {
+               /* In case rootfs is in custom path, reuse it. */
+               new->src = dir_new_path(orig->src, oldname, cname, oldpath, lxcpath);
+               if (!new->src)
+                       return -1;
+
+       }
 
        src = lxc_storage_get_path(new->src, "btrfs");
        new->dest = strdup(src);