[lxc-devel] [PATCH 1/1] lxcapi-snapshot: don't snapshot directory-backed containers

Stéphane Graber stgraber at ubuntu.com
Mon Feb 10 21:06:44 UTC 2014


On Mon, Feb 10, 2014 at 02:19:42PM -0600, Serge Hallyn wrote:
> 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>

Acked-by: Stéphane Graber <stgraber 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
> 
> _______________________________________________
> lxc-devel mailing list
> lxc-devel at lists.linuxcontainers.org
> http://lists.linuxcontainers.org/listinfo/lxc-devel

-- 
Stéphane Graber
Ubuntu developer
http://www.ubuntu.com
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 819 bytes
Desc: Digital signature
URL: <http://lists.linuxcontainers.org/pipermail/lxc-devel/attachments/20140210/95716fb5/attachment.pgp>


More information about the lxc-devel mailing list