X-Git-Url: http://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?a=blobdiff_plain;f=src%2Fcore%2Fload-fragment.c;h=6403e411132f39834512f3239e7d7224a9c70788;hb=9a0549093332880df47c4218209ce126b8586835;hp=da1ab2f912eacf6d7a052695ef853a47e4ea7340;hpb=95ae05c0e79868c22b3e8e6fbc53432786876730;p=elogind.git diff --git a/src/core/load-fragment.c b/src/core/load-fragment.c index da1ab2f91..6403e4111 100644 --- a/src/core/load-fragment.c +++ b/src/core/load-fragment.c @@ -2430,8 +2430,7 @@ int config_parse_cpu_shares( void *data, void *userdata) { - CGroupContext *c = data; - unsigned long lu; + unsigned long *shares = data, lu; int r; assert(filename); @@ -2439,25 +2438,21 @@ int config_parse_cpu_shares( assert(rvalue); if (isempty(rvalue)) { - c->cpu_shares = 1024; + *shares = (unsigned long) -1; return 0; } r = safe_atolu(rvalue, &lu); if (r < 0 || lu <= 0) { - log_syntax(unit, LOG_ERR, filename, line, EINVAL, - "CPU shares '%s' invalid. Ignoring.", rvalue); + log_syntax(unit, LOG_ERR, filename, line, EINVAL, "CPU shares '%s' invalid. Ignoring.", rvalue); return 0; } - c->cpu_shares = lu; - if (!c->startup_cpu_shares_set) - c->startup_cpu_shares = lu; - + *shares = lu; return 0; } -int config_parse_startup_cpu_shares( +int config_parse_cpu_quota( const char *unit, const char *filename, unsigned line, @@ -2470,75 +2465,29 @@ int config_parse_startup_cpu_shares( void *userdata) { CGroupContext *c = data; - unsigned long lu; - int r; + double percent; assert(filename); assert(lvalue); assert(rvalue); if (isempty(rvalue)) { - c->startup_cpu_shares = 1024; + c->cpu_quota_per_sec_usec = (usec_t) -1; 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); + if (!endswith(rvalue, "%")) { + + log_syntax(unit, LOG_ERR, filename, line, EINVAL, "CPU quota '%s' not ending in '%%'. 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; + if (sscanf(rvalue, "%lf%%", &percent) != 1 || percent <= 0) { + log_syntax(unit, LOG_ERR, filename, line, EINVAL, "CPU quota '%s' invalid. Ignoring.", rvalue); 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; - } + c->cpu_quota_per_sec_usec = (usec_t) (percent * USEC_PER_SEC / 100); return 0; } @@ -2648,8 +2597,7 @@ int config_parse_blockio_weight( void *data, void *userdata) { - CGroupContext *c = data; - unsigned long lu; + unsigned long *weight = data, lu; int r; assert(filename); @@ -2657,59 +2605,17 @@ int config_parse_blockio_weight( assert(rvalue); if (isempty(rvalue)) { - c->blockio_weight = 1000; + *weight = (unsigned long) -1; 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); + log_syntax(unit, LOG_ERR, filename, line, EINVAL, "Block IO weight '%s' invalid. Ignoring.", rvalue); return 0; } - 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; - + *weight = lu; return 0; } @@ -2747,8 +2653,7 @@ int config_parse_blockio_device_weight( n = strcspn(rvalue, WHITESPACE); weight = rvalue + n; if (!*weight) { - log_syntax(unit, LOG_ERR, filename, line, EINVAL, - "Expected block device and device weight. Ignoring."); + log_syntax(unit, LOG_ERR, filename, line, EINVAL, "Expected block device and device weight. Ignoring."); return 0; } @@ -2757,20 +2662,17 @@ int config_parse_blockio_device_weight( return log_oom(); if (!path_startswith(path, "/dev")) { - log_syntax(unit, LOG_ERR, filename, line, EINVAL, - "Invalid device node path '%s'. Ignoring.", path); + 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, - "Block IO weight '%s' invalid. Ignoring.", rvalue); + log_syntax(unit, LOG_ERR, filename, line, EINVAL, "Block IO weight '%s' invalid. Ignoring.", rvalue); return 0; } - w = new0(CGroupBlockIODeviceWeight, 1); if (!w) return log_oom(); @@ -3526,13 +3428,11 @@ 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" },