summaryrefslogtreecommitdiff
path: root/src/core
diff options
context:
space:
mode:
authorLennart Poettering <lennart@poettering.net>2013-07-11 20:40:18 +0200
committerLennart Poettering <lennart@poettering.net>2013-07-11 20:40:18 +0200
commit8e7076caae32a560a11c1643b53fc4f12db4a6b1 (patch)
tree3d9f831985cd2042d40c3e29cd43b7d175229809 /src/core
parent554604b3073467af75dc94fac9e2343148603289 (diff)
cgroup: split out per-device BlockIOWeight= setting into BlockIODeviceWeight=
This way we can nicely map the configuration directive to properties and back, without requiring two different signatures for the same property.
Diffstat (limited to 'src/core')
-rw-r--r--src/core/cgroup.c2
-rw-r--r--src/core/load-fragment-gperf.gperf.m41
-rw-r--r--src/core/load-fragment.c87
-rw-r--r--src/core/load-fragment.h1
4 files changed, 61 insertions, 30 deletions
diff --git a/src/core/cgroup.c b/src/core/cgroup.c
index d0f36cb18e..5a1c3adacd 100644
--- a/src/core/cgroup.c
+++ b/src/core/cgroup.c
@@ -114,7 +114,7 @@ void cgroup_context_dump(CGroupContext *c, FILE* f, const char *prefix) {
LIST_FOREACH(device_weights, w, c->blockio_device_weights)
fprintf(f,
- "%sBlockIOWeight=%s %lu",
+ "%sBlockIODeviceWeight=%s %lu",
prefix,
w->path,
w->weight);
diff --git a/src/core/load-fragment-gperf.gperf.m4 b/src/core/load-fragment-gperf.gperf.m4
index 76fc9c48ac..0c337bca9c 100644
--- a/src/core/load-fragment-gperf.gperf.m4
+++ b/src/core/load-fragment-gperf.gperf.m4
@@ -93,6 +93,7 @@ $1.DeviceAllow, config_parse_device_allow, 0,
$1.DevicePolicy, config_parse_device_policy, 0, offsetof($1, cgroup_context.device_policy)
$1.BlockIOAccounting, config_parse_bool, 0, offsetof($1, cgroup_context.blockio_accounting)
$1.BlockIOWeight, config_parse_blockio_weight, 0, offsetof($1, cgroup_context)
+$1.BlockIODeviceWeight, config_parse_blockio_device_weight, 0, offsetof($1, cgroup_context)
$1.BlockIOReadBandwidth, config_parse_blockio_bandwidth, 0, offsetof($1, cgroup_context)
$1.BlockIOWriteBandwidth, config_parse_blockio_bandwidth, 0, offsetof($1, cgroup_context)'
)m4_dnl
diff --git a/src/core/load-fragment.c b/src/core/load-fragment.c
index 2b10d72ab3..cf92f0df73 100644
--- a/src/core/load-fragment.c
+++ b/src/core/load-fragment.c
@@ -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;
}
diff --git a/src/core/load-fragment.h b/src/core/load-fragment.h
index 5e36f3538a..90e5e3a5c9 100644
--- a/src/core/load-fragment.h
+++ b/src/core/load-fragment.h
@@ -81,6 +81,7 @@ int config_parse_memory_limit(const char *unit, const char *filename, unsigned l
int config_parse_device_policy(const char *unit, const char *filename, unsigned line, const char *section, const char *lvalue, int ltype, const char *rvalue, void *data, void *userdata);
int config_parse_device_allow(const char *unit, const char *filename, unsigned line, const char *section, const char *lvalue, int ltype, const char *rvalue, void *data, void *userdata);
int config_parse_blockio_weight(const char *unit, const char *filename, unsigned line, const char *section, const char *lvalue, int ltype, const char *rvalue, void *data, void *userdata);
+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);
int config_parse_blockio_bandwidth(const char *unit, const char *filename, unsigned line, const char *section, const char *lvalue, int ltype, const char *rvalue, void *data, void *userdata);
/* gperf prototypes */