chiark / gitweb /
core: add startup resource control option
[elogind.git] / src / core / load-fragment.c
index 6c92935d0a7bf23b9017c593ce69b0524de4f772..da1ab2f912eacf6d7a052695ef853a47e4ea7340 100644 (file)
@@ -97,9 +97,8 @@ int config_parse_unit_deps(const char* unit,
 
         UnitDependency d = ltype;
         Unit *u = userdata;
-        char *w;
+        char *w, *state;
         size_t l;
-        char *state;
 
         assert(filename);
         assert(lvalue);
@@ -2452,6 +2451,95 @@ int config_parse_cpu_shares(
         }
 
         c->cpu_shares = lu;
+        if (!c->startup_cpu_shares_set)
+                c->startup_cpu_shares = lu;
+
+        return 0;
+}
+
+int config_parse_startup_cpu_shares(
+                const char *unit,
+                const char *filename,
+                unsigned line,
+                const char *section,
+                unsigned section_line,
+                const char *lvalue,
+                int ltype,
+                const char *rvalue,
+                void *data,
+                void *userdata) {
+
+        CGroupContext *c = data;
+        unsigned long lu;
+        int r;
+
+        assert(filename);
+        assert(lvalue);
+        assert(rvalue);
+
+        if (isempty(rvalue)) {
+                c->startup_cpu_shares = 1024;
+                return 0;
+        }
+
+        r = safe_atolu(rvalue, &lu);
+        if (r < 0 || lu <= 0) {
+                log_syntax(unit, LOG_ERR, filename, line, EINVAL,
+                           "Startup CPU shares '%s' invalid. Ignoring.", rvalue);
+                return 0;
+        }
+
+        c->startup_cpu_shares = lu;
+        c->startup_cpu_shares_set = true;
+
+        return 0;
+}
+
+int config_parse_cpu_quota(
+                const char *unit,
+                const char *filename,
+                unsigned line,
+                const char *section,
+                unsigned section_line,
+                const char *lvalue,
+                int ltype,
+                const char *rvalue,
+                void *data,
+                void *userdata) {
+
+        CGroupContext *c = data;
+        int r;
+
+        assert(filename);
+        assert(lvalue);
+        assert(rvalue);
+
+        if (isempty(rvalue)) {
+                c->cpu_quota_per_sec_usec = (usec_t) -1;
+                c->cpu_quota_usec = (usec_t) -1;
+                return 0;
+        }
+
+        if (endswith(rvalue, "%")) {
+                double percent;
+
+                if (sscanf(rvalue, "%lf%%", &percent) != 1 || percent <= 0) {
+                        log_syntax(unit, LOG_ERR, filename, line, EINVAL, "CPU quota '%s' invalid. Ignoring.", rvalue);
+                        return 0;
+                }
+
+                c->cpu_quota_per_sec_usec = (usec_t) (percent * USEC_PER_SEC / 100);
+                c->cpu_quota_usec = (usec_t) -1;
+        } else {
+                r = parse_sec(rvalue, &c->cpu_quota_usec);
+                if (r < 0) {
+                        log_syntax(unit, LOG_ERR, filename, line, EINVAL, "CPU quota '%s' invalid. Ignoring.", rvalue);
+                        return 0;
+                }
+
+                c->cpu_quota_per_sec_usec = (usec_t) -1;
+        }
+
         return 0;
 }
 
@@ -2581,6 +2669,46 @@ int config_parse_blockio_weight(
         }
 
         c->blockio_weight = lu;
+        if (!c->startup_blockio_weight_set)
+                c->startup_blockio_weight = lu;
+
+        return 0;
+}
+
+int config_parse_startup_blockio_weight(
+                const char *unit,
+                const char *filename,
+                unsigned line,
+                const char *section,
+                unsigned section_line,
+                const char *lvalue,
+                int ltype,
+                const char *rvalue,
+                void *data,
+                void *userdata) {
+
+        CGroupContext *c = data;
+        unsigned long lu;
+        int r;
+
+        assert(filename);
+        assert(lvalue);
+        assert(rvalue);
+
+        if (isempty(rvalue)) {
+                c->startup_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,
+                           "Startup Block IO weight '%s' invalid. Ignoring.", rvalue);
+                return 0;
+        }
+
+        c->startup_blockio_weight = lu;
+        c->startup_blockio_weight_set = true;
 
         return 0;
 }
@@ -2982,7 +3110,7 @@ int config_parse_namespace_path_strv(
         return 0;
 }
 
-int config_parse_no_new_priviliges(
+int config_parse_no_new_privileges(
                 const char* unit,
                 const char *filename,
                 unsigned line,
@@ -3398,11 +3526,13 @@ void unit_dump_config_items(FILE *f) {
                 { config_parse_address_families,      "FAMILIES" },
 #endif
                 { config_parse_cpu_shares,            "SHARES" },
+                { config_parse_startup_cpu_shares,    "STARTUPSHARES" },
                 { config_parse_memory_limit,          "LIMIT" },
                 { config_parse_device_allow,          "DEVICE" },
                 { config_parse_device_policy,         "POLICY" },
                 { config_parse_blockio_bandwidth,     "BANDWIDTH" },
                 { config_parse_blockio_weight,        "WEIGHT" },
+                { config_parse_startup_blockio_weight, "STARTUPWEIGHT" },
                 { config_parse_blockio_device_weight, "DEVICEWEIGHT" },
                 { config_parse_long,                  "LONG" },
                 { config_parse_socket_service,        "SERVICE" },