From 8c39f7a4791cd24625b0f12d3ca279400b36bf84 Mon Sep 17 00:00:00 2001 From: Serge Hallyn Date: Mon, 10 Feb 2014 14:19:42 -0600 Subject: [PATCH] lxcapi-snapshot: don't snapshot directory-backed containers MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit 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 Acked-by: Stéphane Graber --- src/lxc/bdev.c | 13 +++++++++++++ src/lxc/bdev.h | 2 ++ src/lxc/lxccontainer.c | 7 +++++++ 3 files changed, 22 insertions(+) diff --git a/src/lxc/bdev.c b/src/lxc/bdev.c index d33c4605d..01c06e104 100644 --- a/src/lxc/bdev.c +++ b/src/lxc/bdev.c @@ -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. diff --git a/src/lxc/bdev.h b/src/lxc/bdev.h index f2d6dc08d..e5d852344 100644 --- a/src/lxc/bdev.h +++ b/src/lxc/bdev.h @@ -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 diff --git a/src/lxc/lxccontainer.c b/src/lxc/lxccontainer.c index cbd645d84..09d287bd9 100644 --- a/src/lxc/lxccontainer.c +++ b/src/lxc/lxccontainer.c @@ -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); -- 2.47.3