summaryrefslogtreecommitdiff
path: root/src/core/load-fragment.c
diff options
context:
space:
mode:
authorTejun Heo <htejun@fb.com>2016-05-18 13:50:56 -0700
committerTejun Heo <tj@kernel.org>2016-05-18 13:50:56 -0700
commit9be572497df8dd0a076c3a2c9142e25b1106aa60 (patch)
tree3e40c07f8014eef9d57554b52f85841f0f674730 /src/core/load-fragment.c
parent4e080f502a5cd6e538a03472070aae8a730c15e9 (diff)
core: introduce CGroupIOLimitType enums
Currently, there are two cgroup IO limits, bandwidth max for read and write, and they are hard-coded in various places. This is fine for two limits but IO is expected to grow more limits - low, high and max limits for bandwidth and IOPS - and hard-coding each limit won't make sense. This patch replaces hard-coded limits with an array indexed by CGroupIOLimitType and accompanying string and default value tables so that new limits can be added trivially.
Diffstat (limited to 'src/core/load-fragment.c')
-rw-r--r--src/core/load-fragment.c21
1 files changed, 9 insertions, 12 deletions
diff --git a/src/core/load-fragment.c b/src/core/load-fragment.c
index cea615132a..9626d861c5 100644
--- a/src/core/load-fragment.c
+++ b/src/core/load-fragment.c
@@ -3023,9 +3023,9 @@ int config_parse_io_limit(
_cleanup_free_ char *path = NULL;
CGroupIODeviceLimit *l = NULL, *t;
CGroupContext *c = data;
+ CGroupIOLimitType type;
const char *limit;
uint64_t num;
- bool read;
size_t n;
int r;
@@ -3033,14 +3033,12 @@ int config_parse_io_limit(
assert(lvalue);
assert(rvalue);
- read = streq("IOReadBandwidthMax", lvalue);
+ type = cgroup_io_limit_type_from_string(lvalue);
+ assert(type >= 0);
if (isempty(rvalue)) {
LIST_FOREACH(device_limits, l, c->io_device_limits)
- if (read)
- l->rbps_max = CGROUP_LIMIT_MAX;
- else
- l->wbps_max = CGROUP_LIMIT_MAX;
+ l->limits[type] = cgroup_io_limit_defaults[type];
return 0;
}
@@ -3080,22 +3078,21 @@ int config_parse_io_limit(
}
if (!l) {
+ CGroupIOLimitType ttype;
+
l = new0(CGroupIODeviceLimit, 1);
if (!l)
return log_oom();
l->path = path;
path = NULL;
- l->rbps_max = CGROUP_LIMIT_MAX;
- l->wbps_max = CGROUP_LIMIT_MAX;
+ for (ttype = 0; ttype < _CGROUP_IO_LIMIT_TYPE_MAX; ttype++)
+ l->limits[ttype] = cgroup_io_limit_defaults[ttype];
LIST_PREPEND(device_limits, c->io_device_limits, l);
}
- if (read)
- l->rbps_max = num;
- else
- l->wbps_max = num;
+ l->limits[type] = num;
return 0;
}