[lxc-devel] [PATCH 1/1] lxcapi-snapshot: don't snapshot directory-backed containers
Serge Hallyn
serge.hallyn at ubuntu.com
Mon Feb 10 20:19:42 UTC 2014
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 at ubuntu.com>
---
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 d33c460..01c06e1 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 f2d6dc0..e5d8523 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 cbd645d..09d287b 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);
--
1.9.rc1
More information about the lxc-devel
mailing list