Commit 8c39f7a4 by Serge Hallyn Committed by Stéphane Graber

lxcapi-snapshot: don't snapshot directory-backed containers

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: 's avatarSerge Hallyn <serge.hallyn@ubuntu.com> Acked-by: 's avatarStéphane Graber <stgraber@ubuntu.com>
parent bbd23aa0
......@@ -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.
......
......@@ -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
......
......@@ -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);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment