bdev: "detect" loop file

parent 9aa76a17
...@@ -854,12 +854,16 @@ static const struct bdev_type *get_bdev_by_name(const char *name) ...@@ -854,12 +854,16 @@ static const struct bdev_type *get_bdev_by_name(const char *name)
return NULL; 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; 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); return get_bdev_by_name(conf->rootfs.bdev_type);
}
for (i = 0; i < numbdevs; i++) { for (i = 0; i < numbdevs; i++) {
int r; int r;
...@@ -870,6 +874,9 @@ static const struct bdev_type *bdev_query(struct lxc_conf *conf, const char *src ...@@ -870,6 +874,9 @@ static const struct bdev_type *bdev_query(struct lxc_conf *conf, const char *src
if (i == numbdevs) if (i == numbdevs)
return NULL; return NULL;
DEBUG("detected rootfs type \"%s\"", bdevs[i].name);
return &bdevs[i]; return &bdevs[i];
} }
......
...@@ -28,6 +28,7 @@ ...@@ -28,6 +28,7 @@
#include <string.h> #include <string.h>
#include <unistd.h> #include <unistd.h>
#include <linux/loop.h> #include <linux/loop.h>
#include <sys/stat.h>
#include <sys/types.h> #include <sys/types.h>
#include "bdev.h" #include "bdev.h"
...@@ -157,8 +158,19 @@ int loop_destroy(struct bdev *orig) ...@@ -157,8 +158,19 @@ int loop_destroy(struct bdev *orig)
int loop_detect(const char *path) int loop_detect(const char *path)
{ {
int ret;
struct stat s;
if (strncmp(path, "loop:", 5) == 0) if (strncmp(path, "loop:", 5) == 0)
return 1; return 1;
ret = stat(path, &s);
if (ret < 0)
return 0;
if (__S_ISTYPE(s.st_mode, S_IFREG))
return 1;
return 0; return 0;
} }
...@@ -166,13 +178,19 @@ int loop_mount(struct bdev *bdev) ...@@ -166,13 +178,19 @@ int loop_mount(struct bdev *bdev)
{ {
int ret, loopfd; int ret, loopfd;
char loname[MAXPATHLEN]; char loname[MAXPATHLEN];
char *src = bdev->src;
if (strcmp(bdev->type, "loop")) if (strcmp(bdev->type, "loop"))
return -22; return -22;
if (!bdev->src || !bdev->dest) if (!bdev->src || !bdev->dest)
return -22; 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) if (loopfd < 0)
return -1; return -1;
DEBUG("prepared loop device \"%s\"", loname); DEBUG("prepared loop device \"%s\"", loname);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment