]> git.ipfire.org Git - thirdparty/lxc.git/commitdiff
btrfs: enable unprivileged snapshots
authorChristian Brauner <christian.brauner@ubuntu.com>
Sun, 16 Jul 2017 15:57:06 +0000 (17:57 +0200)
committerChristian Brauner <christian.brauner@ubuntu.com>
Mon, 31 Jul 2017 21:34:14 +0000 (23:34 +0200)
Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
src/lxc/bdev/bdev.c

index 8f1d0145c2ad0ff01c23bdae5eafa7bd1214a5ee..e1c78141ca79ea338af77602ed1b9c3a93c45ea3 100644 (file)
@@ -432,17 +432,28 @@ struct bdev *bdev_copy(struct lxc_container *c0, const char *cname,
        if (bdevtype && strcmp(orig->type, "btrfs") == 0 &&
            strcmp(new->type, "btrfs") == 0 &&
            btrfs_same_fs(orig->dest, new->dest) == 0) {
+               struct rsync_data_char arg;
+
                if (btrfs_destroy(new) < 0) {
                        ERROR("Error destroying %s subvolume", new->dest);
                        goto err;
                }
+
                if (mkdir_p(new->dest, 0755) < 0) {
                        ERROR("Error creating %s directory", new->dest);
                        goto err;
                }
-               if (btrfs_snapshot(orig->dest, new->dest) < 0) {
-                       ERROR("Error restoring %s to %s", orig->dest,
-                             new->dest);
+
+               arg.src = orig->dest;
+               arg.dest = new->dest;
+               if (am_unpriv())
+                       ret = userns_exec_1(c0->lxc_conf, btrfs_snapshot_wrapper,
+                                         &arg, "btrfs_snapshot_wrapper");
+               else
+                       ret = btrfs_snapshot(orig->dest, new->dest);
+               if (ret < 0) {
+                       SYSERROR("Failed to create btrfs snapshot \"%s\" of \"%s\"",
+                                new->dest, orig->dest);
                        goto err;
                }
                bdev_put(orig);