]> git.ipfire.org Git - thirdparty/lxc.git/commitdiff
lxcapi-snapshot: don't snapshot directory-backed containers
authorSerge Hallyn <serge.hallyn@ubuntu.com>
Mon, 10 Feb 2014 20:19:42 +0000 (14:19 -0600)
committerStéphane Graber <stgraber@ubuntu.com>
Tue, 11 Feb 2014 02:20:12 +0000 (21:20 -0500)
Instead force a copy clone.  Else if the user makes a change
to the original container, the snapshot will be affected.
The user should first create a snapshot clone, then use
and snapshot that clone while leaving the original container
untouched.

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

index d33c4605dac37a116f0341a248f728fd14e1402a..01c06e1040717b1cc08f72d8a65316cfe947914c 100644 (file)
@@ -2116,6 +2116,19 @@ static int rsync_rootfs_wrapper(void *data)
        struct rsync_data *arg = data;
        return rsync_rootfs(arg);
 }
+
+bool bdev_is_dir(const char *path)
+{
+       struct bdev *orig = bdev_init(path, NULL, NULL);
+       bool ret = false;
+       if (!orig)
+               return ret;
+       if (strcmp(orig->type, "dir") == 0)
+               ret = true;
+       bdev_put(orig);
+       return ret;
+}
+
 /*
  * If we're not snaphotting, then bdev_copy becomes a simple case of mount
  * the original, mount the new, and rsync the contents.
index f2d6dc08d16cc61333cd6d3122842ad124f26b4d..e5d8523443768f9cc57edcf5a73606df0625288b 100644 (file)
@@ -86,6 +86,8 @@ struct bdev {
 
 char *overlayfs_getlower(char *p);
 
+bool bdev_is_dir(const char *path);
+
 /*
  * Instantiate a bdev object.  The src is used to determine which blockdev
  * type this should be.  The dst and data are optional, and will be used
index cbd645d84e6f6413bd37acac5bb285c42ad4b8bc..09d287bd944b3ce117e6cf26abd7c75e57175cc9 100644 (file)
@@ -2827,6 +2827,13 @@ static int lxcapi_snapshot(struct lxc_container *c, const char *commentfile)
         */
        flags = LXC_CLONE_SNAPSHOT | LXC_CLONE_KEEPMACADDR | LXC_CLONE_KEEPNAME |
                LXC_CLONE_KEEPBDEVTYPE | LXC_CLONE_MAYBE_SNAPSHOT;
+       if (bdev_is_dir(c->lxc_conf->rootfs.path)) {
+               ERROR("Snapshot of directory-backed container requested.");
+               ERROR("Making a copy-clone.  If you do want snapshots, then");
+               ERROR("please create an overlayfs clone first, snapshot that");
+               ERROR("and keep the original container pristine.");
+               flags &= ~LXC_CLONE_SNAPSHOT | LXC_CLONE_MAYBE_SNAPSHOT;
+       }
        c2 = c->clone(c, newname, snappath, flags, NULL, NULL, 0, NULL);
        if (!c2) {
                ERROR("clone of %s:%s failed", c->config_path, c->name);