chiark / gitweb /
cgroup: split out per-device BlockIOWeight= setting into BlockIODeviceWeight=
[elogind.git] / src / core / load-fragment.c
index 57c8156fdd4e6905fe6d60bf2583631112ed732c..cf92f0df734f3eee57ee54d3bca050f6549c4e2a 100644 (file)
@@ -2094,7 +2094,44 @@ int config_parse_blockio_weight(
                 void *data,
                 void *userdata) {
 
+        CGroupContext *c = data;
+        unsigned long lu;
+        int r;
+
+        assert(filename);
+        assert(lvalue);
+        assert(rvalue);
+
+        if (isempty(rvalue)) {
+                c->blockio_weight = 1000;
+                return 0;
+        }
+
+        r = safe_atolu(rvalue, &lu);
+        if (r < 0 || lu < 10 || lu > 1000) {
+                log_syntax(unit, LOG_ERR, filename, line, EINVAL,
+                           "Block IO weight '%s' invalid. Ignoring.", rvalue);
+                return 0;
+        }
+
+        c->blockio_weight = lu;
+
+        return 0;
+}
+
+int config_parse_blockio_device_weight(
+                const char *unit,
+                const char *filename,
+                unsigned line,
+                const char *section,
+                const char *lvalue,
+                int ltype,
+                const char *rvalue,
+                void *data,
+                void *userdata) {
+
         _cleanup_free_ char *path = NULL;
+        CGroupBlockIODeviceWeight *w;
         CGroupContext *c = data;
         unsigned long lu;
         const char *weight;
@@ -2106,8 +2143,6 @@ int config_parse_blockio_weight(
         assert(rvalue);
 
         if (isempty(rvalue)) {
-                c->blockio_weight = 1000;
-
                 while (c->blockio_device_weights)
                         cgroup_context_free_blockio_device_weight(c, c->blockio_device_weights);
 
@@ -2116,23 +2151,23 @@ int config_parse_blockio_weight(
 
         n = strcspn(rvalue, WHITESPACE);
         weight = rvalue + n;
-        if (*weight) {
-                /* Two params, first device name, then weight */
-                path = strndup(rvalue, n);
-                if (!path)
-                        return log_oom();
+        if (!*weight) {
+                log_syntax(unit, LOG_ERR, filename, line, EINVAL,
+                           "Expected block device and device weight. Ignoring.");
+                return 0;
+        }
 
-                if (!path_startswith(path, "/dev")) {
-                        log_syntax(unit, LOG_ERR, filename, line, EINVAL,
-                                   "Invalid device node path '%s'. Ignoring.", path);
-                        return 0;
-                }
+        path = strndup(rvalue, n);
+        if (!path)
+                return log_oom();
 
-                weight += strspn(weight, WHITESPACE);
-        } else
-                /* One param, only weight */
-                weight = rvalue;
+        if (!path_startswith(path, "/dev")) {
+                log_syntax(unit, LOG_ERR, filename, line, EINVAL,
+                           "Invalid device node path '%s'. Ignoring.", path);
+                return 0;
+        }
 
+        weight += strspn(weight, WHITESPACE);
         r = safe_atolu(weight, &lu);
         if (r < 0 || lu < 10 || lu > 1000) {
                 log_syntax(unit, LOG_ERR, filename, line, EINVAL,
@@ -2140,23 +2175,17 @@ int config_parse_blockio_weight(
                 return 0;
         }
 
-        if (!path)
-                c->blockio_weight = lu;
-        else {
-                CGroupBlockIODeviceWeight *w;
-
-                w = new0(CGroupBlockIODeviceWeight, 1);
-                if (!w)
-                        return log_oom();
 
-                w->path = path;
-                path = NULL;
+        w = new0(CGroupBlockIODeviceWeight, 1);
+        if (!w)
+                return log_oom();
 
-                w->weight = lu;
+        w->path = path;
+        path = NULL;
 
-                LIST_PREPEND(CGroupBlockIODeviceWeight, device_weights, c->blockio_device_weights, w);
-        }
+        w->weight = lu;
 
+        LIST_PREPEND(CGroupBlockIODeviceWeight, device_weights, c->blockio_device_weights, w);
         return 0;
 }
 
@@ -2439,14 +2468,14 @@ static int load_from_path(Unit *u, const char *path) {
         if (null_or_empty(&st))
                 u->load_state = UNIT_MASKED;
         else {
+                u->load_state = UNIT_LOADED;
+
                 /* Now, parse the file contents */
                 r = config_parse(u->id, filename, f, UNIT_VTABLE(u)->sections,
                                  config_item_perf_lookup,
                                  (void*) load_fragment_gperf_lookup, false, true, u);
                 if (r < 0)
                         goto finish;
-
-                u->load_state = UNIT_LOADED;
         }
 
         free(u->fragment_path);