]> git.ipfire.org Git - thirdparty/lxc.git/commitdiff
bdev: "detect" loop file
authorChristian Brauner <christian.brauner@ubuntu.com>
Sun, 4 Jun 2017 11:59:34 +0000 (13:59 +0200)
committerChristian Brauner <christian.brauner@ubuntu.com>
Sun, 4 Jun 2017 16:02:50 +0000 (18:02 +0200)
Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
src/lxc/bdev/bdev.c
src/lxc/bdev/lxcloop.c

index b1193f57aeab6e766aef6d7d2e9f341c7fb4893b..f5d0f0eb3b65c3724f9fc9af42f5a25c3a683adb 100644 (file)
@@ -854,12 +854,16 @@ static const struct bdev_type *get_bdev_by_name(const char *name)
        return NULL;
 }
 
-static const struct bdev_type *bdev_query(struct lxc_conf *conf, const char *src)
+static const struct bdev_type *bdev_query(struct lxc_conf *conf,
+                                         const char *src)
 {
        size_t i;
 
-       if (conf->rootfs.bdev_type)
+       if (conf->rootfs.bdev_type) {
+               DEBUG("config file specified rootfs type \"%s\"",
+                     conf->rootfs.bdev_type);
                return get_bdev_by_name(conf->rootfs.bdev_type);
+       }
 
        for (i = 0; i < numbdevs; i++) {
                int r;
@@ -870,6 +874,9 @@ static const struct bdev_type *bdev_query(struct lxc_conf *conf, const char *src
 
        if (i == numbdevs)
                return NULL;
+
+       DEBUG("detected rootfs type \"%s\"", bdevs[i].name);
+
        return &bdevs[i];
 }
 
index a4633e405e89c431f80c81abd56f0fa53175a084..32f2f78cf39ae101a505243b36ca7a680b9a0328 100644 (file)
@@ -28,6 +28,7 @@
 #include <string.h>
 #include <unistd.h>
 #include <linux/loop.h>
+#include <sys/stat.h>
 #include <sys/types.h>
 
 #include "bdev.h"
@@ -157,8 +158,19 @@ int loop_destroy(struct bdev *orig)
 
 int loop_detect(const char *path)
 {
+       int ret;
+       struct stat s;
+
        if (strncmp(path, "loop:", 5) == 0)
                return 1;
+
+       ret = stat(path, &s);
+       if (ret < 0)
+               return 0;
+
+       if (__S_ISTYPE(s.st_mode, S_IFREG))
+               return 1;
+
        return 0;
 }
 
@@ -166,13 +178,19 @@ int loop_mount(struct bdev *bdev)
 {
        int ret, loopfd;
        char loname[MAXPATHLEN];
+       char *src = bdev->src;
 
        if (strcmp(bdev->type, "loop"))
                return -22;
+
        if (!bdev->src || !bdev->dest)
                return -22;
 
-       loopfd = lxc_prepare_loop_dev(bdev->src + 5, loname, LO_FLAGS_AUTOCLEAR);
+       /* skip prefix */
+       if (!strncmp(bdev->src, "loop:", 5))
+               src += 5;
+
+       loopfd = lxc_prepare_loop_dev(src, loname, LO_FLAGS_AUTOCLEAR);
        if (loopfd < 0)
                return -1;
        DEBUG("prepared loop device \"%s\"", loname);