[lxc-devel] [lxc/master] 2016 04 02/bdev
hallyn on Github
lxc-bot at linuxcontainers.org
Sat Apr 2 20:49:03 UTC 2016
A non-text attachment was scrubbed...
Name: not available
Type: text/x-mailbox
Size: 300 bytes
Desc: not available
URL: <http://lists.linuxcontainers.org/pipermail/lxc-devel/attachments/20160402/2fb50120/attachment.bin>
-------------- next part --------------
From bfd77214f696cebdc92082052af6e174785bb1f9 Mon Sep 17 00:00:00 2001
From: Serge Hallyn <serge.hallyn at ubuntu.com>
Date: Sat, 2 Apr 2016 15:41:24 -0500
Subject: [PATCH 1/2] add a lxc.rootfs.bdev option (not yet honored)
Signed-off-by: Serge Hallyn <serge.hallyn at ubuntu.com>
---
src/lxc/bdev/bdev.c | 15 +++++++++++++++
src/lxc/bdev/bdev.h | 2 ++
src/lxc/conf.c | 1 +
src/lxc/conf.h | 2 ++
src/lxc/confile.c | 14 ++++++++++++++
5 files changed, 34 insertions(+)
diff --git a/src/lxc/bdev/bdev.c b/src/lxc/bdev/bdev.c
index 090b685..7514aae 100644
--- a/src/lxc/bdev/bdev.c
+++ b/src/lxc/bdev/bdev.c
@@ -954,3 +954,18 @@ static bool unpriv_snap_allowed(struct bdev *b, const char *t, bool snap,
return true;
return false;
}
+
+bool is_valid_bdev_type(const char *type)
+{
+ if (strcmp(type, "dir") == 0 ||
+ strcmp(type, "btrfs") == 0 ||
+ strcmp(type, "aufs") == 0 ||
+ strcmp(type, "loop") == 0 ||
+ strcmp(type, "lvm") == 0 ||
+ strcmp(type, "nbd") == 0 ||
+ strcmp(type, "ovl") == 0 ||
+ strcmp(type, "rbd") == 0 ||
+ strcmp(type, "zfs") == 0)
+ return true;
+ return false;
+}
diff --git a/src/lxc/bdev/bdev.h b/src/lxc/bdev/bdev.h
index 91b9c8d..3f21e84 100644
--- a/src/lxc/bdev/bdev.h
+++ b/src/lxc/bdev/bdev.h
@@ -146,4 +146,6 @@ bool rootfs_is_blockdev(struct lxc_conf *conf);
bool attach_block_device(struct lxc_conf *conf);
void detach_block_device(struct lxc_conf *conf);
+bool is_valid_bdev_type(const char *type);
+
#endif // __LXC_BDEV_H
diff --git a/src/lxc/conf.c b/src/lxc/conf.c
index 2f8338d..98cd384 100644
--- a/src/lxc/conf.c
+++ b/src/lxc/conf.c
@@ -4142,6 +4142,7 @@ void lxc_conf_free(struct lxc_conf *conf)
free(conf->console.log_path);
free(conf->console.path);
free(conf->rootfs.mount);
+ free(conf->rootfs.bdev);
free(conf->rootfs.options);
free(conf->rootfs.path);
free(conf->logfile);
diff --git a/src/lxc/conf.h b/src/lxc/conf.h
index d3cd0b3..50516fd 100644
--- a/src/lxc/conf.h
+++ b/src/lxc/conf.h
@@ -220,11 +220,13 @@ struct lxc_console {
* @path : the rootfs source (directory or device)
* @mount : where it is mounted
* @options : mount options
+ * @bev : optional backing store type
*/
struct lxc_rootfs {
char *path;
char *mount;
char *options;
+ char *bdev;
};
/*
diff --git a/src/lxc/confile.c b/src/lxc/confile.c
index 6fcfb12..15f2e7b 100644
--- a/src/lxc/confile.c
+++ b/src/lxc/confile.c
@@ -42,6 +42,7 @@
#include "parse.h"
#include "config.h"
#include "confile.h"
+#include "bdev/bdev.h"
#include "utils.h"
#include "log.h"
#include "conf.h"
@@ -72,6 +73,7 @@ static int config_fstab(const char *, const char *, struct lxc_conf *);
static int config_rootfs(const char *, const char *, struct lxc_conf *);
static int config_rootfs_mount(const char *, const char *, struct lxc_conf *);
static int config_rootfs_options(const char *, const char *, struct lxc_conf *);
+static int config_rootfs_bdev(const char *, const char *, struct lxc_conf *);
static int config_pivotdir(const char *, const char *, struct lxc_conf *);
static int config_utsname(const char *, const char *, struct lxc_conf *);
static int config_hook(const char *, const char *, struct lxc_conf *lxc_conf);
@@ -130,6 +132,7 @@ static struct lxc_config_t config[] = {
{ "lxc.mount", config_fstab },
{ "lxc.rootfs.mount", config_rootfs_mount },
{ "lxc.rootfs.options", config_rootfs_options },
+ { "lxc.rootfs.bdev", config_rootfs_bdev },
{ "lxc.rootfs", config_rootfs },
{ "lxc.pivotdir", config_pivotdir },
{ "lxc.utsname", config_utsname },
@@ -1853,6 +1856,17 @@ static int config_rootfs_options(const char *key, const char *value,
return config_string_item(&lxc_conf->rootfs.options, value);
}
+static int config_rootfs_bdev(const char *key, const char *value,
+ struct lxc_conf *lxc_conf)
+{
+ if (!is_valid_bdev_type(value)) {
+ ERROR("Bad bdev type for %s: %s", key, value);
+ return -1;
+ }
+
+ return config_string_item(&lxc_conf->rootfs.bdev, value);
+}
+
static int config_pivotdir(const char *key, const char *value,
struct lxc_conf *lxc_conf)
{
From 984bd6203a6ee88653ca80d0c12650162c635b1b Mon Sep 17 00:00:00 2001
From: Serge Hallyn <serge.hallyn at ubuntu.com>
Date: Sat, 2 Apr 2016 15:47:43 -0500
Subject: [PATCH 2/2] honor lxc.rootfs.bdev
If that is specified, then we only use the specified backing store type.
This can be useful if you know that lxc.rootfs is a directory type and
you do not want lxc to waste time searching for zfs, btrfs, etc.
Signed-off-by: Serge Hallyn <serge.hallyn at ubuntu.com>
---
src/lxc/bdev/bdev.c | 25 +++++++++++++++++++++----
1 file changed, 21 insertions(+), 4 deletions(-)
diff --git a/src/lxc/bdev/bdev.c b/src/lxc/bdev/bdev.c
index 7514aae..d57386c 100644
--- a/src/lxc/bdev/bdev.c
+++ b/src/lxc/bdev/bdev.c
@@ -201,7 +201,7 @@ static const struct bdev_type bdevs[] = {
static const size_t numbdevs = sizeof(bdevs) / sizeof(struct bdev_type);
/* helpers */
-static const struct bdev_type *bdev_query(const char *src);
+static const struct bdev_type *bdev_query(struct lxc_conf *conf, const char *src);
static struct bdev *bdev_get(const char *type);
static struct bdev *do_bdev_create(const char *dest, const char *type,
const char *cname, struct bdev_specs *specs);
@@ -542,7 +542,7 @@ struct bdev *bdev_init(struct lxc_conf *conf, const char *src, const char *dst,
if (!src)
return NULL;
- q = bdev_query(src);
+ q = bdev_query(conf, src);
if (!q)
return NULL;
@@ -794,7 +794,7 @@ bool rootfs_is_blockdev(struct lxc_conf *conf)
ret = stat(conf->rootfs.path, &st);
if (ret == 0 && S_ISBLK(st.st_mode))
return true;
- q = bdev_query(conf->rootfs.path);
+ q = bdev_query(conf, conf->rootfs.path);
if (!q)
return false;
if (strcmp(q->name, "lvm") == 0 ||
@@ -841,9 +841,26 @@ static struct bdev *bdev_get(const char *type)
return bdev;
}
-static const struct bdev_type *bdev_query(const char *src)
+static const struct bdev_type *get_bdev_by_name(const char *name)
{
int i;
+
+ for (i = 0; i < numbdevs; i++) {
+ if (strcmp(bdevs[i].name, name) == 0)
+ return &bdevs[i];
+ }
+
+ ERROR("Backing store %s unknown but not caught earlier\n", name);
+ return NULL;
+}
+
+static const struct bdev_type *bdev_query(struct lxc_conf *conf, const char *src)
+{
+ int i;
+
+ if (conf->rootfs.bdev)
+ return get_bdev_by_name(conf->rootfs.bdev);
+
for (i = 0; i < numbdevs; i++) {
int r;
r = bdevs[i].ops->detect(src);
More information about the lxc-devel
mailing list