]> git.ipfire.org Git - thirdparty/lxc.git/commitdiff
storage: deprecate lxc.rootfs.backend
authorChristian Brauner <christian.brauner@ubuntu.com>
Sat, 1 Jul 2017 15:02:13 +0000 (17:02 +0200)
committerChristian Brauner <christian.brauner@ubuntu.com>
Sun, 2 Jul 2017 12:40:04 +0000 (14:40 +0200)
Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
12 files changed:
src/lxc/bdev/bdev.c
src/lxc/bdev/lxcaufs.c
src/lxc/bdev/lxcbtrfs.c
src/lxc/bdev/lxcdir.c
src/lxc/bdev/lxcloop.c
src/lxc/bdev/lxclvm.c
src/lxc/bdev/lxcnbd.c
src/lxc/bdev/lxcoverlay.c
src/lxc/bdev/lxcrbd.c
src/lxc/bdev/lxczfs.c
src/lxc/confile.c
src/lxc/lxccontainer.c

index 44c4e0423cf267f99c877957cee17be4c2cf3e6e..55abefa389d1e86e1cad5ceddf6f8c0eb54a4aad 100644 (file)
@@ -187,11 +187,11 @@ struct bdev_type {
 };
 
 static const struct bdev_type bdevs[] = {
+       { .name = "dir",       .ops = &dir_ops,   },
        { .name = "zfs",       .ops = &zfs_ops,   },
        { .name = "lvm",       .ops = &lvm_ops,   },
        { .name = "rbd",       .ops = &rbd_ops,   },
        { .name = "btrfs",     .ops = &btrfs_ops, },
-       { .name = "dir",       .ops = &dir_ops,   },
        { .name = "aufs",      .ops = &aufs_ops,  },
        { .name = "overlayfs", .ops = &ovl_ops,   },
        { .name = "loop",      .ops = &loop_ops,  },
@@ -890,40 +890,41 @@ static struct bdev *bdev_get(const char *type)
 
 static const struct bdev_type *get_bdev_by_name(const char *name)
 {
-       size_t i;
+       size_t i, cmplen;
 
-       for (i = 0; i < numbdevs; i++) {
-               if (strcmp(bdevs[i].name, name) == 0)
-                       return &bdevs[i];
-       }
+       cmplen = strcspn(name, ":");
+       if (cmplen == 0)
+               return NULL;
 
-       ERROR("Backing store %s unknown but not caught earlier\n", name);
-       return NULL;
+       for (i = 0; i < numbdevs; i++)
+               if (strncmp(bdevs[i].name, name, cmplen) == 0)
+                       break;
+
+       if (i == numbdevs)
+               return NULL;
+
+       DEBUG("Detected rootfs type \"%s\"", bdevs[i].name);
+       return &bdevs[i];
 }
 
 static const struct bdev_type *bdev_query(struct lxc_conf *conf,
                                          const char *src)
 {
        size_t i;
+       const struct bdev_type *bdev;
 
-       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);
-       }
+       bdev = get_bdev_by_name(src);
+       if (bdev)
+               return bdev;
 
-       for (i = 0; i < numbdevs; i++) {
-               int r;
-               r = bdevs[i].ops->detect(src);
-               if (r)
+       for (i = 0; i < numbdevs; i++)
+               if (bdevs[i].ops->detect(src))
                        break;
-       }
 
        if (i == numbdevs)
                return NULL;
 
-       DEBUG("detected rootfs type \"%s\"", bdevs[i].name);
-
+       DEBUG("Detected rootfs type \"%s\"", bdevs[i].name);
        return &bdevs[i];
 }
 
index fd5e97503cb9d60eb60ce03c9505376f9c0fd64f..481b62ffe0a4f97e59e96091c3eb03c47867ca63 100644 (file)
@@ -229,8 +229,9 @@ int aufs_destroy(struct bdev *orig)
 
 int aufs_detect(const char *path)
 {
-       if (strncmp(path, "aufs:", 5) == 0)
-               return 1; // take their word for it
+       if (!strncmp(path, "aufs:", 5))
+               return 1;
+
        return 0;
 }
 
index 9eaec4a2a62523030e1a9e204e49dfdf1d1686f6..bc0e805022002f48b3329c34d7e0fe51cb25c7e0 100644 (file)
@@ -174,10 +174,13 @@ int btrfs_detect(const char *path)
        struct stat st;
        int ret;
 
+       if (!strncmp(path, "btrfs:", 6))
+               return 1;
+
        if (!is_btrfs_fs(path))
                return 0;
 
-       // and make sure it's a subvolume.
+       /* make sure it's a subvolume */
        ret = stat(path, &st);
        if (ret < 0)
                return 0;
index fb258405e59c980cde5149a93a867b5f326ab743..be897bb77acce6c77dbabf5caaf5e3db0bbda0f2 100644 (file)
@@ -96,8 +96,9 @@ int dir_destroy(struct bdev *orig)
 
 int dir_detect(const char *path)
 {
-       if (strncmp(path, "dir:", 4) == 0)
-               return 1; // take their word for it
+       if (!strncmp(path, "dir:", 4))
+               return 1;
+
        if (is_dir(path))
                return 1;
        return 0;
index 65d49525debd8fffa05024e778cc2dcac077fa2d..9cd63b01aed5ce8d24329e2ca1f8ac55d0e7f278 100644 (file)
@@ -161,7 +161,7 @@ int loop_detect(const char *path)
        int ret;
        struct stat s;
 
-       if (strncmp(path, "loop:", 5) == 0)
+       if (!strncmp(path, "loop:", 5))
                return 1;
 
        ret = stat(path, &s);
index 35c5c92f3ae35cf032312050044c8b7b231c7fb1..407c55ff81cbcdb187eed7635c0dfa8e39bf988f 100644 (file)
@@ -134,8 +134,8 @@ int lvm_detect(const char *path)
        int ret;
        struct stat statbuf;
 
-       if (strncmp(path, "lvm:", 4) == 0)
-               return 1; // take their word for it
+       if (!strncmp(path, "lvm:", 4))
+               return 1;
 
        ret = stat(path, &statbuf);
        if (ret != 0)
index 8a320d2097109d9cbb9843348e09814c1b3067a0..a9bf4f186a5a529dec1391bfb99b3517a6cd9c0f 100644 (file)
@@ -107,8 +107,9 @@ int nbd_destroy(struct bdev *orig)
 
 int nbd_detect(const char *path)
 {
-       if (strncmp(path, "nbd:", 4) == 0)
+       if (!strncmp(path, "nbd:", 4))
                return 1;
+
        return 0;
 }
 
index 65daed8dbb76434b315bc4b27c0b0f08ef5f8ae0..377cf926359555e8ef1cb93420fde9201156b091 100644 (file)
@@ -298,8 +298,12 @@ int ovl_destroy(struct bdev *orig)
 
 int ovl_detect(const char *path)
 {
-       if (strncmp(path, "overlayfs:", 10) == 0)
-               return 1; // take their word for it
+       if (!strncmp(path, "overlayfs:", 10))
+               return 1;
+
+       if (!strncmp(path, "overlay:", 8))
+               return 1;
+
        return 0;
 }
 
index b6abb75e49a55958db1ba440bdcf326c25dd4dec..133b67e52ab530ddbb8d8161600ee69605f4233b 100644 (file)
@@ -154,8 +154,12 @@ int rbd_destroy(struct bdev *orig)
 
 int rbd_detect(const char *path)
 {
-       if ( memcmp(path, "/dev/rbd/", 9) == 0)
+       if (!strncmp(path, "rbd:", 4))
                return 1;
+
+       if (!strncmp(path, "/dev/rbd/", 9))
+               return 1;
+
        return 0;
 }
 
index 64129456088a3dde3861281ae0ce49a4c486e98b..b8f3c140583622d9321af2f34ed1f71c5331af2a 100644 (file)
@@ -70,6 +70,9 @@ int zfs_list_entry(const char *path, char *output, size_t inlen)
 
 int zfs_detect(const char *path)
 {
+       if (!strncmp(path, "zfs:", 4))
+               return 1;
+
        char *output = malloc(LXC_LOG_BUFFER_SIZE);
 
        if (!output) {
index 3c0b3b1d082f9a5fe22f3e29cd7cc73635f951ad..7fc97f386912808cf818ec555f5aa094e98229c2 100644 (file)
@@ -162,7 +162,12 @@ static struct lxc_config_t config[] = {
        { "lxc.mount",                     set_config_fstab,                       get_config_fstab,                       clr_config_fstab,                     },
        { "lxc.rootfs.mount",              set_config_rootfs_mount,                get_config_rootfs_mount,                clr_config_rootfs_mount,              },
        { "lxc.rootfs.options",            set_config_rootfs_options,              get_config_rootfs_options,              clr_config_rootfs_options,            },
+
+       /* REMOVE IN LXC 3.0
+          legacy rootfs.backend key
+        */
        { "lxc.rootfs.backend",            set_config_rootfs_backend,              get_config_rootfs_backend,              clr_config_rootfs_backend,            },
+
        { "lxc.rootfs",                    set_config_rootfs,                      get_config_rootfs,                      clr_config_rootfs,                    },
 
        /* REMOVE IN LXC 3.0
@@ -2051,18 +2056,7 @@ static int set_config_rootfs_options(const char *key, const char *value,
 static int set_config_rootfs_backend(const char *key, const char *value,
                                     struct lxc_conf *lxc_conf, void *data)
 {
-       if (lxc_config_value_empty(value)) {
-               free(lxc_conf->rootfs.bdev_type);
-               lxc_conf->rootfs.bdev_type = NULL;
-               return 0;
-       }
-
-       if (!is_valid_bdev_type(value)) {
-               ERROR("Bad rootfs.backend: '%s'", value);
-               return -1;
-       }
-
-       return set_config_string_item(&lxc_conf->rootfs.bdev_type, value);
+       return 0;
 }
 
 static int set_config_uts_name(const char *key, const char *value,
@@ -3053,7 +3047,7 @@ static int get_config_rootfs_options(const char *key, char *retv, int inlen,
 static int get_config_rootfs_backend(const char *key, char *retv, int inlen,
                                     struct lxc_conf *c, void *data)
 {
-       return lxc_get_conf_str(retv, inlen, c->rootfs.bdev_type);
+       return 0;
 }
 
 static int get_config_uts_name(const char *key, char *retv, int inlen,
@@ -3473,8 +3467,6 @@ static inline int clr_config_rootfs_options(const char *key, struct lxc_conf *c,
 static inline int clr_config_rootfs_backend(const char *key, struct lxc_conf *c,
                                            void *data)
 {
-       free(c->rootfs.bdev_type);
-       c->rootfs.bdev_type = NULL;
        return 0;
 }
 
index ae0e708d2058abe5796b8c1358d324e043dcf706..26ae254107da886d7ba4f57aaa9effa2d892767c 100644 (file)
@@ -1043,7 +1043,7 @@ static bool create_container_dir(struct lxc_container *c)
  * it returns a mounted bdev on success, NULL on error.
  */
 static struct bdev *do_bdev_create(struct lxc_container *c, const char *type,
-                        struct bdev_specs *specs)
+                                  struct bdev_specs *specs)
 {
        char *dest;
        size_t len;
@@ -1051,7 +1051,7 @@ static struct bdev *do_bdev_create(struct lxc_container *c, const char *type,
        int ret;
 
        /* rootfs.path or lxcpath/lxcname/rootfs */
-       if (c->lxc_conf->rootfs.path && access(c->lxc_conf->rootfs.path, F_OK) == 0) {
+       if (c->lxc_conf->rootfs.path && !access(c->lxc_conf->rootfs.path, F_OK)) {
                const char *rpath = c->lxc_conf->rootfs.path;
                len = strlen(rpath) + 1;
                dest = alloca(len);
@@ -1071,12 +1071,15 @@ static struct bdev *do_bdev_create(struct lxc_container *c, const char *type,
                return NULL;
        }
 
-       do_lxcapi_set_config_item(c, "lxc.rootfs", bdev->src);
-       do_lxcapi_set_config_item(c, "lxc.rootfs.backend", bdev->type);
-
-       /* if we are not root, chown the rootfs dir to root in the
-        * target uidmap */
+       if (!c->set_config_item(c, "lxc.rootfs", bdev->src)) {
+               ERROR("Failed to set config item \"lxc.rootfs\" to \"%s\"",
+                     bdev->src);
+               return NULL;
+       }
 
+       /* If we are not root, chown the rootfs dir to root in the
+        * target uidmap.
+        */
        if (geteuid() != 0 || (c->lxc_conf && !lxc_list_empty(&c->lxc_conf->id_map))) {
                if (chown_mapped_root(bdev->dest, c->lxc_conf) < 0) {
                        ERROR("Error chowning %s to container root", bdev->dest);
@@ -2924,20 +2927,12 @@ static int copy_storage(struct lxc_container *c0, struct lxc_container *c,
        /* Set new rootfs. */
        free(c->lxc_conf->rootfs.path);
        c->lxc_conf->rootfs.path = strdup(bdev->src);
-
-       /* Set new bdev type. */
-       free(c->lxc_conf->rootfs.bdev_type);
-       c->lxc_conf->rootfs.bdev_type = strdup(bdev->type);
        bdev_put(bdev);
 
        if (!c->lxc_conf->rootfs.path) {
                ERROR("Out of memory while setting storage path.");
                return -1;
        }
-       if (!c->lxc_conf->rootfs.bdev_type) {
-               ERROR("Out of memory while setting rootfs backend.");
-               return -1;
-       }
 
        /* Append a new lxc.rootfs entry to the unexpanded config. */
        clear_unexp_config_line(c->lxc_conf, "lxc.rootfs", false);
@@ -2949,11 +2944,6 @@ static int copy_storage(struct lxc_container *c0, struct lxc_container *c,
 
        /* Append a new lxc.rootfs.backend entry to the unexpanded config. */
        clear_unexp_config_line(c->lxc_conf, "lxc.rootfs.backend", false);
-       if (!do_append_unexp_config_line(c->lxc_conf, "lxc.rootfs.backend",
-                                        c->lxc_conf->rootfs.bdev_type)) {
-               ERROR("Error saving new rootfs backend to cloned config.");
-               return -1;
-       }
 
        if (flags & LXC_CLONE_SNAPSHOT)
                copy_rdepends(c, c0);