]> git.proxmox.com Git - mirror_lxc.git/commitdiff
conf: port mounts to new list type
authorChristian Brauner <christian.brauner@ubuntu.com>
Fri, 27 Aug 2021 11:08:09 +0000 (13:08 +0200)
committerChristian Brauner <christian.brauner@ubuntu.com>
Fri, 27 Aug 2021 11:08:09 +0000 (13:08 +0200)
Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
src/lxc/conf.c
src/lxc/conf.h
src/lxc/confile.c
src/lxc/criu.c
src/lxc/storage/overlay.c
src/lxc/storage/overlay.h

index 8aaefa16fbac59aa3c038ccbef6cc0aa77d95f4c..5937b0c76209fdaf862223170af406c0afd37cf5 100644 (file)
@@ -2775,14 +2775,13 @@ static const char nesting_helpers[] =
 "proc dev/.lxc/proc proc create=dir,optional 0 0\n"
 "sys dev/.lxc/sys sysfs create=dir,optional 0 0\n";
 
-FILE *make_anonymous_mount_file(struct lxc_list *mount,
+FILE *make_anonymous_mount_file(const struct list_head *mount_entries,
                                bool include_nesting_helpers)
 {
        __do_close int fd = -EBADF;
        FILE *f;
        int ret;
-       char *mount_entry;
-       struct lxc_list *iterator;
+       struct string_entry *entry;
 
        fd = memfd_create(".lxc_mount_file", MFD_CLOEXEC);
        if (fd < 0) {
@@ -2798,13 +2797,12 @@ FILE *make_anonymous_mount_file(struct lxc_list *mount,
                TRACE("Created temporary mount file");
        }
 
-       lxc_list_for_each (iterator, mount) {
+       list_for_each_entry(entry, mount_entries, head) {
                size_t len;
 
-               mount_entry = iterator->elem;
-               len = strlen(mount_entry);
+               len = strlen(entry->val);
 
-               ret = lxc_write_nointr(fd, mount_entry, len);
+               ret = lxc_write_nointr(fd, entry->val, len);
                if (ret != len)
                        return NULL;
 
@@ -2831,12 +2829,12 @@ FILE *make_anonymous_mount_file(struct lxc_list *mount,
 }
 
 static int setup_mount_entries(const struct lxc_conf *conf,
-                              struct lxc_rootfs *rootfs, struct lxc_list *mount,
+                              struct lxc_rootfs *rootfs,
                               const char *lxc_name, const char *lxc_path)
 {
        __do_fclose FILE *f = NULL;
 
-       f = make_anonymous_mount_file(mount, conf->lsm_aa_allow_nesting);
+       f = make_anonymous_mount_file(&conf->mount_entries, conf->lsm_aa_allow_nesting);
        if (!f)
                return -1;
 
@@ -3057,10 +3055,10 @@ static int lxc_idmapped_mounts_child(struct lxc_handler *handler)
        int fret = -1;
        struct lxc_conf *conf = handler->conf;
        const char *fstab = conf->fstab;
-       struct lxc_list *mount = &conf->mount_list;
        int ret;
 
-       f_entries = make_anonymous_mount_file(mount, conf->lsm_aa_allow_nesting);
+       f_entries = make_anonymous_mount_file(&conf->mount_entries,
+                                             conf->lsm_aa_allow_nesting);
        if (!f_entries) {
                SYSERROR("Failed to create anonymous mount file");
                goto out;
@@ -3365,7 +3363,7 @@ struct lxc_conf *lxc_conf_init(void)
        /* Block ("allowlist") all devices by default. */
        new->bpf_devices.list_type = LXC_BPF_DEVICE_CGROUP_ALLOWLIST;
        INIT_LIST_HEAD(&(new->bpf_devices).devices);
-       lxc_list_init(&new->mount_list);
+       INIT_LIST_HEAD(&new->mount_entries);
        INIT_LIST_HEAD(&new->caps.list);
        INIT_LIST_HEAD(&new->id_map);
        new->root_nsuid_map = NULL;
@@ -4322,9 +4320,8 @@ int lxc_setup(struct lxc_handler *handler)
        if (ret < 0)
                return log_error(-1, "Failed to setup mounts");
 
-       if (!lxc_list_empty(&lxc_conf->mount_list)) {
-               ret = setup_mount_entries(lxc_conf, &lxc_conf->rootfs,
-                                         &lxc_conf->mount_list, name, lxcpath);
+       if (!list_empty(&lxc_conf->mount_entries)) {
+               ret = setup_mount_entries(lxc_conf, &lxc_conf->rootfs, name, lxcpath);
                if (ret < 0)
                        return log_error(-1, "Failed to setup mount entries");
        }
@@ -4667,15 +4664,15 @@ int lxc_clear_environment(struct lxc_conf *c)
 
 int lxc_clear_mount_entries(struct lxc_conf *c)
 {
-       struct lxc_list *it, *next;
+       struct string_entry *entry, *nentry;
 
-       lxc_list_for_each_safe (it, &c->mount_list, next) {
-               lxc_list_del(it);
-               free(it->elem);
-               free(it);
+       list_for_each_entry_safe(entry, nentry, &c->mount_entries, head) {
+               list_del(&entry->head);
+               free(entry->val);
+               free(entry);
        }
 
-       lxc_list_init(&c->mount_list);
+       INIT_LIST_HEAD(&c->mount_entries);
        return 0;
 }
 
index 270b7f8d22c0bf91f603d8543adf049785f0aed9..53075b3f8c351125f98c0e81caec9ca87a5a66c1 100644 (file)
@@ -354,6 +354,11 @@ struct caps {
        struct list_head list;
 };
 
+struct string_entry {
+       char *val;
+       struct list_head head;
+};
+
 struct lxc_conf {
        /* Pointer to the name of the container. Do not free! */
        const char *name;
@@ -389,7 +394,7 @@ struct lxc_conf {
        struct {
                char *fstab;
                int auto_mounts;
-               struct lxc_list mount_list;
+               struct list_head mount_entries;
        };
 
        struct caps caps;
@@ -567,7 +572,8 @@ __hidden extern int parse_lxc_mount_attrs(struct lxc_mount_options *opts, char *
 __hidden extern int parse_mount_attrs(struct lxc_mount_options *opts, const char *mntopts);
 __hidden extern void tmp_proc_unmount(struct lxc_conf *lxc_conf);
 __hidden extern void suggest_default_idmap(void);
-__hidden extern FILE *make_anonymous_mount_file(struct lxc_list *mount, bool include_nesting_helpers);
+__hidden extern FILE *make_anonymous_mount_file(const struct list_head *mount,
+                                               bool include_nesting_helpers);
 __hidden extern int run_script(const char *name, const char *section, const char *script, ...);
 __hidden extern int run_script_argv(const char *name, unsigned int hook_version, const char *section,
                                    const char *script, const char *hookname, char **argsin);
index 8aad86d1680a703edd76777e2d17f4e2a37e210b..03bdef07793e7cab46ae20a33333fcbbfe76041f 100644 (file)
@@ -2348,21 +2348,22 @@ static int set_config_mount(const char *key, const char *value,
                            struct lxc_conf *lxc_conf, void *data)
 {
        __do_free char *mntelem = NULL;
-       __do_free struct lxc_list *mntlist = NULL;
+       __do_free struct string_entry *entry = NULL;
 
        if (lxc_config_value_empty(value))
                return lxc_clear_mount_entries(lxc_conf);
 
-       mntlist = lxc_list_new();
-       if (!mntlist)
+       entry = zalloc(sizeof(struct string_entry));
+       if (!entry)
                return ret_errno(ENOMEM);
 
        mntelem = strdup(value);
        if (!mntelem)
                return ret_errno(ENOMEM);
 
-       mntlist->elem = move_ptr(mntelem);
-       lxc_list_add_tail(&lxc_conf->mount_list, move_ptr(mntlist));
+       entry->val = move_ptr(mntelem);
+       list_add_tail(&entry->head, &lxc_conf->mount_entries);
+       move_ptr(entry);
 
        return 0;
 }
@@ -4136,15 +4137,15 @@ static int get_config_mount(const char *key, char *retv, int inlen,
                            struct lxc_conf *c, void *data)
 {
        int len, fulllen = 0;
-       struct lxc_list *it;
+       struct string_entry *entry;
 
        if (!retv)
                inlen = 0;
        else
                memset(retv, 0, inlen);
 
-       lxc_list_for_each(it, &c->mount_list) {
-               strprint(retv, inlen, "%s\n", (char *)it->elem);
+       list_for_each_entry(entry, &c->mount_entries, head) {
+               strprint(retv, inlen, "%s\n", entry->val);
        }
 
        return fulllen;
index f936bea1441889d3e9b17c1264bce4b1b95e70c6..569940b4db06ea6d89e5125e7643016f71a30781 100644 (file)
@@ -246,7 +246,7 @@ static int exec_criu(struct cgroup_ops *cgroup_ops, struct lxc_conf *conf,
        if (opts->user->action_script)
                static_args += 2;
 
-       static_args += 2 * lxc_list_len(&opts->c->lxc_conf->mount_list);
+       static_args += 2 * list_len(&opts->c->lxc_conf->mount_entries);
 
        ret = strnprintf(log, sizeof(log), "%s/%s.log", opts->user->directory, opts->action);
        if (ret < 0)
@@ -348,7 +348,7 @@ static int exec_criu(struct cgroup_ops *cgroup_ops, struct lxc_conf *conf,
                DECLARE_ARG(opts->user->action_script);
        }
 
-       f_mnt = make_anonymous_mount_file(&opts->c->lxc_conf->mount_list,
+       f_mnt = make_anonymous_mount_file(&opts->c->lxc_conf->mount_entries,
                                         opts->c->lxc_conf->lsm_aa_allow_nesting);
        if (!f_mnt)
                return log_error_errno(-ENOENT, ENOENT, "Failed to create anonymous mount file");
index 1479a9ce899d728ada95fd6fecdab4241172b900..410b4ff5a4c72df4aa2ed2e0afb24646b4e8c432 100644 (file)
@@ -656,7 +656,7 @@ err:
 /* To be called from lxcapi_clone() in lxccontainer.c: When we clone a container
  * with overlay lxc.mount.entry entries we need to update absolute paths for
  * upper- and workdir. This update is done in two locations:
- * lxc_conf->unexpanded_config and lxc_conf->mount_list. Both updates are done
+ * lxc_conf->unexpanded_config and lxc_conf->mount_entries. Both updates are done
  * independent of each other since lxc_conf->mountlist may contain more mount
  * entries (e.g. from other included files) than lxc_conf->unexpanded_config.
  */
@@ -667,7 +667,7 @@ int ovl_update_abs_paths(struct lxc_conf *lxc_conf, const char *lxc_path,
        char new_upper[PATH_MAX], new_work[PATH_MAX], old_upper[PATH_MAX],
            old_work[PATH_MAX];
        size_t i;
-       struct lxc_list *iterator;
+       struct string_entry *entry;
        char *cleanpath = NULL;
        int fret = -1;
        int ret = 0;
@@ -681,7 +681,7 @@ int ovl_update_abs_paths(struct lxc_conf *lxc_conf, const char *lxc_path,
 
        /*
         * We have to update lxc_conf->unexpanded_config separately from
-        * lxc_conf->mount_list.
+        * lxc_conf->mount_entries.
         */
        for (i = 0; i < sizeof(ovl_dirs) / sizeof(ovl_dirs[0]); i++) {
                if (!clone_update_unexp_ovl_paths(lxc_conf, lxc_path, newpath,
@@ -700,11 +700,11 @@ int ovl_update_abs_paths(struct lxc_conf *lxc_conf, const char *lxc_path,
        if (ret < 0 || ret >= PATH_MAX)
                goto err;
 
-       lxc_list_for_each(iterator, &lxc_conf->mount_list) {
+       list_for_each_entry(entry, &lxc_conf->mount_entries, head) {
                char *mnt_entry = NULL, *new_mnt_entry = NULL, *tmp = NULL,
                     *tmp_mnt_entry = NULL;
 
-               mnt_entry = iterator->elem;
+               mnt_entry = entry->val;
 
                if (strstr(mnt_entry, "overlay"))
                        tmp = "upperdir";
@@ -721,26 +721,26 @@ int ovl_update_abs_paths(struct lxc_conf *lxc_conf, const char *lxc_path,
                if (ret < 0 || ret >= PATH_MAX)
                        goto err;
 
-               if (strstr(mnt_entry, old_upper)) {
-                       tmp_mnt_entry =
-                           lxc_string_replace(old_upper, new_upper, mnt_entry);
-               }
+               if (strstr(mnt_entry, old_upper))
+                       tmp_mnt_entry = lxc_string_replace(old_upper, new_upper, mnt_entry);
 
                if (strstr(mnt_entry, old_work)) {
                        if (tmp_mnt_entry)
-                               new_mnt_entry = lxc_string_replace(
-                                   old_work, new_work, tmp_mnt_entry);
+                               new_mnt_entry = lxc_string_replace(old_work,
+                                                                  new_work,
+                                                                  tmp_mnt_entry);
                        else
-                               new_mnt_entry = lxc_string_replace(
-                                   old_work, new_work, mnt_entry);
+                               new_mnt_entry = lxc_string_replace(old_work,
+                                                                  new_work,
+                                                                  mnt_entry);
                }
 
                if (new_mnt_entry) {
-                       free(iterator->elem);
-                       iterator->elem = strdup(new_mnt_entry);
+                       free(entry->val);
+                       entry->val = strdup(new_mnt_entry);
                } else if (tmp_mnt_entry) {
-                       free(iterator->elem);
-                       iterator->elem = strdup(tmp_mnt_entry);
+                       free(entry->val);
+                       entry->val = strdup(tmp_mnt_entry);
                }
 
                free(new_mnt_entry);
index d4c780ff42797e7bc57aaf83ffd5fc10be014d71..bed876e80713bda6cf1a68b73fd49bd1e03cbb52 100644 (file)
@@ -35,9 +35,10 @@ __hidden extern int ovl_umount(struct lxc_storage *bdev);
 /* To be called from lxcapi_clone() in lxccontainer.c: When we clone a container
  * with overlay lxc.mount.entry entries we need to update absolute paths for
  * upper- and workdir. This update is done in two locations:
- * lxc_conf->unexpanded_config and lxc_conf->mount_list. Both updates are done
- * independent of each other since lxc_conf->mountlist may container more mount
- * entries (e.g. from other included files) than lxc_conf->unexpanded_config .
+ * lxc_conf->unexpanded_config and lxc_conf->mount_entries. Both updates are
+ * done independent of each other since lxc_conf->mountlist may container more
+ * mount entries (e.g. from other included files) than
+ * lxc_conf->unexpanded_config .
  */
 __hidden extern int ovl_update_abs_paths(struct lxc_conf *lxc_conf, const char *lxc_path,
                                         const char *lxc_name, const char *newpath,