]> git.ipfire.org Git - thirdparty/lxc.git/commitdiff
Do not allow snapshots of LVM backed containers
authorSerge Hallyn <serge.hallyn@ubuntu.com>
Fri, 8 Aug 2014 15:00:18 +0000 (15:00 +0000)
committerStéphane Graber <stgraber@ubuntu.com>
Fri, 8 Aug 2014 15:40:06 +0000 (11:40 -0400)
They don't work right now, so until we fix that, don't allow it.

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 9f2499469fb568b114426f7d2ec1225bad1e8855..2d5bfea28eb012e9ca2765fcad91eff56b635ff6 100644 (file)
@@ -521,6 +521,7 @@ static const struct bdev_ops dir_ops = {
        .destroy = &dir_destroy,
        .create = &dir_create,
        .can_snapshot = false,
+       .can_backup = true,
 };
 
 
@@ -785,6 +786,7 @@ static const struct bdev_ops zfs_ops = {
        .destroy = &zfs_destroy,
        .create = &zfs_create,
        .can_snapshot = true,
+       .can_backup = true,
 };
 
 //
@@ -1180,6 +1182,7 @@ static const struct bdev_ops lvm_ops = {
        .destroy = &lvm_destroy,
        .create = &lvm_create,
        .can_snapshot = true,
+       .can_backup = false,
 };
 
 /*
@@ -1859,6 +1862,7 @@ static const struct bdev_ops btrfs_ops = {
        .destroy = &btrfs_destroy,
        .create = &btrfs_create,
        .can_snapshot = true,
+       .can_backup = true,
 };
 
 //
@@ -2130,6 +2134,7 @@ static const struct bdev_ops loop_ops = {
        .destroy = &loop_destroy,
        .create = &loop_create,
        .can_snapshot = false,
+       .can_backup = true,
 };
 
 //
@@ -2427,6 +2432,7 @@ static const struct bdev_ops overlayfs_ops = {
        .destroy = &overlayfs_destroy,
        .create = &overlayfs_create,
        .can_snapshot = true,
+       .can_backup = true,
 };
 
 //
@@ -2704,6 +2710,7 @@ static const struct bdev_ops aufs_ops = {
        .destroy = &aufs_destroy,
        .create = &aufs_create,
        .can_snapshot = true,
+       .can_backup = true,
 };
 
 //
@@ -3013,6 +3020,7 @@ static const struct bdev_ops nbd_ops = {
        .destroy = &nbd_destroy,
        .create = &nbd_create,
        .can_snapshot = true,
+       .can_backup = false,
 };
 
 static const struct bdev_type bdevs[] = {
@@ -3079,6 +3087,12 @@ struct bdev *bdev_init(struct lxc_conf *conf, const char *src, const char *dst,
        struct bdev *bdev;
        const struct bdev_type *q;
 
+       if (!src)
+               src = conf->rootfs.path;
+
+       if (!src)
+               return NULL;
+
        q = bdev_query(src);
        if (!q)
                return NULL;
@@ -3167,6 +3181,18 @@ bool bdev_is_dir(struct lxc_conf *conf, const char *path)
        return ret;
 }
 
+bool bdev_can_backup(struct lxc_conf *conf)
+{
+       struct bdev *bdev = bdev_init(conf, NULL, NULL, NULL);
+       bool ret;
+
+       if (!bdev)
+               return false;
+       ret = bdev->ops->can_backup;
+       bdev_put(bdev);
+       return ret;
+}
+
 /*
  * is an unprivileged user allowed to make this kind of snapshot
  */
index 651f7f316ab7d52a8b6fd23fcd343a7af8e1836d..d97b9df42fe38d53b23c3a6f6e05d9e2b0564d01 100644 (file)
@@ -47,6 +47,7 @@ struct bdev_ops {
                        const char *cname, const char *oldpath, const char *lxcpath,
                        int snap, uint64_t newsize, struct lxc_conf *conf);
        bool can_snapshot;
+       bool can_backup;
 };
 
 /*
@@ -72,6 +73,7 @@ struct bdev {
 char *overlay_getlower(char *p);
 
 bool bdev_is_dir(struct lxc_conf *conf, const char *path);
+bool bdev_can_backup(struct lxc_conf *conf);
 
 /*
  * Instantiate a bdev object.  The src is used to determine which blockdev
index 814aeb1f719a28984629e4fc2155932e9eeb2ff6..553f026d6f4537399f40fa6dcc506f3de2e2598b 100644 (file)
@@ -2987,6 +2987,12 @@ static int lxcapi_snapshot(struct lxc_container *c, const char *commentfile)
        if (!c || !lxcapi_is_defined(c))
                return -1;
 
+       if (!bdev_can_backup(c->lxc_conf)) {
+               ERROR("%s's backing store cannot be backed up.", c->name);
+               ERROR("Your container must use another backing store type.");
+               return -1;
+       }
+
        if (!get_snappath_dir(c, snappath))
                return -1;