Blame SOURCES/libcgroup-0.41-api.c-fix-order-of-memory-subsystem-parameters.patch

973139
From 72a9e0c3d4f8daca9f7dc389edbc1013d7c0d808 Mon Sep 17 00:00:00 2001
973139
From: =?UTF-8?q?Nikola=20Forr=C3=B3?= <nforro@redhat.com>
973139
Date: Fri, 8 Apr 2016 17:00:19 +0200
973139
Subject: [PATCH] api.c: fix order of memory subsystem parameters generated by
973139
 cgsnapshot
973139
MIME-Version: 1.0
973139
Content-Type: text/plain; charset=UTF-8
973139
Content-Transfer-Encoding: 8bit
973139
973139
Order of parameters usually doesn't matter, but that's not the case with
973139
memory.limit_in_bytes and memory.memsw.limit_in_bytes. When the latter
973139
is first in the list of parameters, the resulting configuration is not
973139
loadable with cgconfigparser.
973139
973139
This happens because when a cgroup is created, both memory.limit_in_bytes
973139
and memory.memsw.limit_in_bytes parameters are initialized to highest
973139
value possible (RESOURCE_MAX). And because memory.memsw.limit_in_bytes
973139
must be always higher or equal to memory.limit_in_bytes, it's impossible
973139
to change its value first.
973139
973139
Make sure that after constructing parameter list of memory subsystem,
973139
the mentioned parameters are in correct order.
973139
973139
Signed-off-by: Nikola Forró <nforro@redhat.com>
973139
---
973139
 src/api.c | 24 ++++++++++++++++++++++++
973139
 1 file changed, 24 insertions(+)
973139
973139
diff --git a/src/api.c b/src/api.c
973139
index 0bf0615..f5da553 100644
973139
--- a/src/api.c
973139
+++ b/src/api.c
973139
@@ -2651,6 +2651,30 @@ int cgroup_get_cgroup(struct cgroup *cgroup)
973139
 			}
973139
 		}
973139
 		closedir(dir);
973139
+
973139
+		if (! strcmp(cgc->name, "memory")) {
973139
+			/*
973139
+			 * Make sure that memory.limit_in_bytes is placed before
973139
+			 * memory.memsw.limit_in_bytes in the list of values
973139
+			 */
973139
+			int memsw_limit = -1;
973139
+			int mem_limit = -1;
973139
+
973139
+			for (j = 0; j < cgc->index; j++) {
973139
+				if (! strcmp(cgc->values[j]->name,
973139
+								"memory.memsw.limit_in_bytes"))
973139
+					memsw_limit = j;
973139
+				else if (! strcmp(cgc->values[j]->name,
973139
+									"memory.limit_in_bytes"))
973139
+					mem_limit = j;
973139
+			}
973139
+
973139
+			if (memsw_limit >= 0 && memsw_limit < mem_limit) {
973139
+				struct control_value *val = cgc->values[memsw_limit];
973139
+				cgc->values[memsw_limit] = cgc->values[mem_limit];
973139
+				cgc->values[mem_limit] = val;
973139
+			}
973139
+		}
973139
 	}
973139
 
973139
 	/* Check if the group really exists or not */
973139
-- 
973139
2.4.11
973139