]> git.ipfire.org Git - thirdparty/lxc.git/commitdiff
confile: parse storage type
authorChristian Brauner <christian.brauner@ubuntu.com>
Mon, 27 Nov 2017 12:01:22 +0000 (13:01 +0100)
committerChristian Brauner <christian.brauner@ubuntu.com>
Fri, 15 Dec 2017 11:30:49 +0000 (12:30 +0100)
Split lxc.rootfs.path = <storage type>:<container path> into <storage-type> and
<container path> to set the storage type and rootfs path value correctly.

Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
Signed-off-by: Adrian Reber <areber@redhat.com>
src/lxc/confile.c

index 5983b6e000da1d623a2d4f3f41d534c311ed451d..0149e09f6333a52ee55d888ea57b6d58a8eab508 100644 (file)
@@ -1869,7 +1869,41 @@ static int set_config_includefiles(const char *key, const char *value,
 static int set_config_rootfs_path(const char *key, const char *value,
                                  struct lxc_conf *lxc_conf, void *data)
 {
-       return set_config_path_item(&lxc_conf->rootfs.path, value);
+       int ret;
+       char *dup, *tmp;
+       const char *container_path;
+
+       if (lxc_config_value_empty(value)) {
+               free(lxc_conf->rootfs.path);
+               lxc_conf->rootfs.path = NULL;
+               return 0;
+       }
+
+       dup = strdup(value);
+       if (!dup)
+               return -1;
+
+       /* Split <storage type>:<container path> into <storage type> and
+        * <container path>. Set "rootfs.bdev_type" to <storage type> and
+        * "rootfs.path" to <container path>.
+        */
+       tmp = strchr(dup, ':');
+       if (tmp) {
+               *tmp = '\0';
+               ret = set_config_path_item(&lxc_conf->rootfs.bdev_type, dup);
+               if (ret < 0) {
+                       free(dup);
+                       return -1;
+               }
+               tmp++;
+               container_path = tmp;
+       } else {
+               container_path = value;
+       }
+
+       ret = set_config_path_item(&lxc_conf->rootfs.path, container_path);
+       free(dup);
+       return ret;
 }
 
 static int set_config_rootfs_mount(const char *key, const char *value,