]> git.ipfire.org Git - thirdparty/lxc.git/commitdiff
cgroups: fix cgroup settings sorting
authorChristian Brauner <christian.brauner@ubuntu.com>
Fri, 27 Aug 2021 08:17:01 +0000 (10:17 +0200)
committerChristian Brauner <christian.brauner@ubuntu.com>
Fri, 27 Aug 2021 08:17:01 +0000 (10:17 +0200)
Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
src/lxc/cgroups/cgfsng.c
src/lxc/conf.c
src/lxc/conf.h

index e4d8243a169061357264e9e050fd20fe71e99364..d51fd838fcbb9fe67c5e8595fb2950cbd6e53275 100644 (file)
@@ -2703,6 +2703,32 @@ static int cg_legacy_set_data(struct cgroup_ops *ops, const char *filename,
        return lxc_write_openat(h->path_lim, filename, value, strlen(value));
 }
 
+/*
+ * Return the list of cgroup_settings sorted according to the following rules
+ * 1. Put memory.limit_in_bytes before memory.memsw.limit_in_bytes
+ */
+static void sort_cgroup_settings(struct lxc_conf *conf)
+{
+       LIST_HEAD(memsw_list);
+       struct lxc_cgroup *cgroup, *ncgroup;
+
+       /* Iterate over the cgroup settings and copy them to the output list. */
+       list_for_each_entry_safe(cgroup, ncgroup, &conf->cgroup, head) {
+               if (!strequal(cgroup->subsystem, "memory.memsw.limit_in_bytes"))
+                       continue;
+
+               /* Move the memsw entry from the cgroup settings list. */
+               list_move_tail(&cgroup->head, &memsw_list);
+       }
+
+       /*
+        * Append all the memsw entries to the end of the cgroup settings list
+        * to make sure they are applied after all memory limit settings.
+        */
+       list_splice_tail(&memsw_list, &conf->cgroup);
+
+}
+
 __cgfsng_ops static bool cgfsng_setup_limits_legacy(struct cgroup_ops *ops,
                                                    struct lxc_conf *conf,
                                                    bool do_devices)
index 59cfbc94052e3da377b0550491078dc4579fc6e8..8aaefa16fbac59aa3c038ccbef6cc0aa77d95f4c 100644 (file)
@@ -5679,29 +5679,6 @@ void suggest_default_idmap(void)
        ERROR("lxc.idmap = g 0 %u %u", gid, grange);
 }
 
-/* Return the list of cgroup_settings sorted according to the following rules
- * 1. Put memory.limit_in_bytes before memory.memsw.limit_in_bytes
- */
-void sort_cgroup_settings(struct lxc_conf *conf)
-{
-       struct lxc_cgroup *cgroup, *memsw_limit, *ncgroup;
-
-       /* Iterate over the cgroup settings and copy them to the output list. */
-       list_for_each_entry_safe(cgroup, ncgroup, &conf->cgroup, head) {
-               if (strequal(cgroup->subsystem, "memory.memsw.limit_in_bytes")) {
-                       /* Store the memsw_limit location */
-                       memsw_limit = cgroup;
-               } else if (memsw_limit && strequal(cgroup->subsystem, "memory.limit_in_bytes")) {
-                       /*
-                        * lxc.cgroup.memory.memsw.limit_in_bytes is found
-                        * before lxc.cgroup.memory.limit_in_bytes, swap these
-                        * two items.
-                        */
-                       list_swap(&memsw_limit->head, &cgroup->head);
-               }
-       }
-}
-
 int lxc_set_environment(const struct lxc_conf *conf)
 {
        struct environment_entry *env;
index 7cc41afd26faa83236e7544e0a65b95b1dca5ab8..270b7f8d22c0bf91f603d8543adf049785f0aed9 100644 (file)
@@ -568,7 +568,6 @@ __hidden extern int parse_mount_attrs(struct lxc_mount_options *opts, const char
 __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 void sort_cgroup_settings(struct lxc_conf *conf);
 __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);