]> git.ipfire.org Git - thirdparty/lxc.git/commitdiff
copy_storage: try to use snapshot for btrfs 760/head
authorSerge Hallyn <serge.hallyn@ubuntu.com>
Mon, 11 Jan 2016 21:07:05 +0000 (13:07 -0800)
committerSerge Hallyn <serge.hallyn@ubuntu.com>
Mon, 11 Jan 2016 22:22:43 +0000 (14:22 -0800)
Signed-off-by: Serge Hallyn <serge.hallyn@ubuntu.com>
src/lxc/lxccontainer.c

index 802a930120e4d8b080cdc934ca3699b3d0a1e939..490a59ddd74b6074dcaa7423a8604105773c7dc3 100644 (file)
@@ -41,6 +41,7 @@
 #include "attach.h"
 #include "bdev/bdev.h"
 #include "bdev/lxcoverlay.h"
+#include "bdev/lxcbtrfs.h"
 #include "cgroup.h"
 #include "conf.h"
 #include "config.h"
@@ -2817,12 +2818,33 @@ static bool add_rdepends(struct lxc_container *c, struct lxc_container *c0)
        return bret;
 }
 
+/*
+ * If the fs natively supports snapshot clones with no penalty,
+ * then default to those even if not requested.
+ * Currently we only do this for btrfs.
+ */
+bool should_default_to_snapshot(struct lxc_container *c0,
+                               struct lxc_container *c1)
+{
+       size_t l0 = strlen(c0->config_path) + strlen(c0->name) + 2;
+       size_t l1 = strlen(c1->config_path) + strlen(c1->name) + 2;
+       char *p0 = alloca(l0 + 1);
+       char *p1 = alloca(l1 + 1);
+
+       snprintf(p0, l0, "%s/%s", c0->config_path, c0->name);
+       snprintf(p1, l1, "%s/%s", c1->config_path, c1->name);
+       return btrfs_same_fs(p0, p1) == 0;
+}
+
 static int copy_storage(struct lxc_container *c0, struct lxc_container *c,
                const char *newtype, int flags, const char *bdevdata, uint64_t newsize)
 {
        struct bdev *bdev;
        int need_rdep;
 
+       if (should_default_to_snapshot(c0, c))
+               flags |= LXC_CLONE_SNAPSHOT;
+
        bdev = bdev_copy(c0, c->name, c->config_path, newtype, flags,
                        bdevdata, newsize, &need_rdep);
        if (!bdev) {