]> git.ipfire.org Git - thirdparty/lxc.git/commitdiff
Add bdev_destroy() and bdev_destroy_wrapper()
authorChristian Brauner <christianvanbrauner@gmail.com>
Tue, 8 Sep 2015 20:37:14 +0000 (22:37 +0200)
committerStéphane Graber <stgraber@ubuntu.com>
Mon, 21 Sep 2015 15:40:06 +0000 (11:40 -0400)
static do_bdev_destroy() and bdev_destroy_wrapper() from lxccontainer.c become
public bdev_destroy() and bdev_destroy_wrapper() in bdev.c and bdev.h

Signed-off-by: Christian Brauner <christianvanbrauner@gmail.com>
Acked-by: Serge E. Hallyn <serge.hallyn@ubuntu.com>
src/lxc/bdev.c
src/lxc/bdev.h

index 1694adbcb1f4203ab6fa0632e3ac68f24ede3ed9..64e88322a9bc5580ca056f6640babc777fa95e22 100644 (file)
@@ -3670,3 +3670,40 @@ bool rootfs_is_blockdev(struct lxc_conf *conf)
                return true;
        return false;
 }
+
+bool bdev_destroy(struct lxc_conf *conf)
+{
+       struct bdev *r;
+       bool ret = false;
+
+       r = bdev_init(conf, conf->rootfs.path, conf->rootfs.mount, NULL);
+       if (!r)
+               return ret;
+
+       if (r->ops->destroy(r) == 0)
+               ret = true;
+       bdev_put(r);
+
+       return ret;
+}
+
+int bdev_destroy_wrapper(void *data)
+{
+       struct lxc_conf *conf = data;
+
+       if (setgid(0) < 0) {
+               ERROR("Failed to setgid to 0");
+               return -1;
+       }
+       if (setgroups(0, NULL) < 0)
+               WARN("Failed to clear groups");
+       if (setuid(0) < 0) {
+               ERROR("Failed to setuid to 0");
+               return -1;
+       }
+       if (!bdev_destroy(conf))
+               return -1;
+       else
+               return 0;
+}
+
index 428b3b735580205bd7dc57f90a5c3636ab8d5de2..f7b3fcae0555940a5580ff0fb2f881c4bc1405b6 100644 (file)
@@ -123,6 +123,9 @@ struct bdev *bdev_copy(struct lxc_container *c0, const char *cname,
 struct bdev *bdev_create(const char *dest, const char *type,
                        const char *cname, struct bdev_specs *specs);
 void bdev_put(struct bdev *bdev);
+bool bdev_destroy(struct lxc_conf *conf);
+/* callback function to be used with userns_exec_1() */
+int bdev_destroy_wrapper(void *data);
 
 /*
  * these are really for qemu-nbd support, as container shutdown