naccyde / rpms / systemd

Forked from rpms/systemd a year ago
Clone
52b84b
From a016ef4ab29ed62da547db008866624f75ed6407 Mon Sep 17 00:00:00 2001
52b84b
From: Chris Down <chris@chrisdown.name>
52b84b
Date: Tue, 16 Apr 2019 18:14:09 +0100
52b84b
Subject: [PATCH] cgroup: Create UNIT_DEFINE_ANCESTOR_MEMORY_LOOKUP
52b84b
52b84b
This is in preparation for creating unit_get_ancestor_memory_min.
52b84b
52b84b
(cherry picked from commit 6264b85e92aeddb74b8d8808a08c9eae8390a6a5)
52b84b
52b84b
Related: #1763435
52b84b
---
52b84b
 src/core/cgroup.c | 55 ++++++++++++++++++++++++++---------------------
52b84b
 1 file changed, 30 insertions(+), 25 deletions(-)
52b84b
52b84b
diff --git a/src/core/cgroup.c b/src/core/cgroup.c
52b84b
index f804bf4727..46a89ff5e1 100644
52b84b
--- a/src/core/cgroup.c
52b84b
+++ b/src/core/cgroup.c
52b84b
@@ -372,31 +372,36 @@ int cgroup_add_device_allow(CGroupContext *c, const char *dev, const char *mode)
52b84b
         return 0;
52b84b
 }
52b84b
 
52b84b
-uint64_t unit_get_ancestor_memory_low(Unit *u) {
52b84b
-        CGroupContext *c;
52b84b
-
52b84b
-        /* 1. Is MemoryLow set in this unit? If so, use that.
52b84b
-         * 2. Is DefaultMemoryLow set in any ancestor? If so, use that.
52b84b
-         * 3. Otherwise, return CGROUP_LIMIT_MIN. */
52b84b
-
52b84b
-        assert(u);
52b84b
-
52b84b
-        c = unit_get_cgroup_context(u);
52b84b
-
52b84b
-        if (c->memory_low_set)
52b84b
-                return c->memory_low;
52b84b
-
52b84b
-        while (UNIT_ISSET(u->slice)) {
52b84b
-                u = UNIT_DEREF(u->slice);
52b84b
-                c = unit_get_cgroup_context(u);
52b84b
-
52b84b
-                if (c->default_memory_low_set)
52b84b
-                        return c->default_memory_low;
52b84b
-        }
52b84b
-
52b84b
-        /* We've reached the root, but nobody had DefaultMemoryLow set, so set it to the kernel default. */
52b84b
-        return CGROUP_LIMIT_MIN;
52b84b
-}
52b84b
+#define UNIT_DEFINE_ANCESTOR_MEMORY_LOOKUP(entry)                       \
52b84b
+        uint64_t unit_get_ancestor_##entry(Unit *u) {                   \
52b84b
+                CGroupContext *c;                                       \
52b84b
+                                                                        \
52b84b
+                /* 1. Is entry set in this unit? If so, use that.       \
52b84b
+                 * 2. Is the default for this entry set in any          \
52b84b
+                 *    ancestor? If so, use that.                        \
52b84b
+                 * 3. Otherwise, return CGROUP_LIMIT_MIN. */            \
52b84b
+                                                                        \
52b84b
+                assert(u);                                              \
52b84b
+                                                                        \
52b84b
+                c = unit_get_cgroup_context(u);                         \
52b84b
+                                                                        \
52b84b
+                if (c->entry##_set)                                     \
52b84b
+                        return c->entry;                                \
52b84b
+                                                                        \
52b84b
+                while (UNIT_ISSET(u->slice)) {                          \
52b84b
+                        u = UNIT_DEREF(u->slice);                       \
52b84b
+                        c = unit_get_cgroup_context(u);                 \
52b84b
+                                                                        \
52b84b
+                        if (c->default_##entry##_set)                   \
52b84b
+                                return c->default_##entry;              \
52b84b
+                }                                                       \
52b84b
+                                                                        \
52b84b
+                /* We've reached the root, but nobody had default for   \
52b84b
+                 * this entry set, so set it to the kernel default. */  \
52b84b
+                return CGROUP_LIMIT_MIN;                                \
52b84b
+}
52b84b
+
52b84b
+UNIT_DEFINE_ANCESTOR_MEMORY_LOOKUP(memory_low);
52b84b
 
52b84b
 static int lookup_block_device(const char *p, dev_t *ret) {
52b84b
         struct stat st;