summaryrefslogtreecommitdiff
path: root/src/core/dbus-cgroup.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/dbus-cgroup.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/dbus-cgroup.c')
-rw-r--r--src/core/dbus-cgroup.c50
1 files changed, 16 insertions, 34 deletions
diff --git a/src/core/dbus-cgroup.c b/src/core/dbus-cgroup.c
index a2a4a6249c..4372828e30 100644
--- a/src/core/dbus-cgroup.c
+++ b/src/core/dbus-cgroup.c
@@ -80,17 +80,13 @@ static int property_get_io_device_limits(
return r;
LIST_FOREACH(device_limits, l, c->io_device_limits) {
- uint64_t v;
+ CGroupIOLimitType type;
- if (streq(property, "IOReadBandwidthMax"))
- v = l->rbps_max;
- else
- v = l->wbps_max;
-
- if (v == CGROUP_LIMIT_MAX)
+ type = cgroup_io_limit_type_from_string(property);
+ if (type < 0 || l->limits[type] == cgroup_io_limit_defaults[type])
continue;
- r = sd_bus_message_append(reply, "(st)", l->path, v);
+ r = sd_bus_message_append(reply, "(st)", l->path, l->limits[type]);
if (r < 0)
return r;
}
@@ -273,6 +269,7 @@ int bus_cgroup_set_property(
UnitSetPropertiesMode mode,
sd_bus_error *error) {
+ CGroupIOLimitType iol_type;
int r;
assert(u);
@@ -416,15 +413,11 @@ int bus_cgroup_set_property(
return 1;
- } else if (streq(name, "IOReadBandwidthMax") || streq(name, "IOWriteBandwidthMax")) {
+ } else if ((iol_type = cgroup_io_limit_type_from_string(name)) >= 0) {
const char *path;
- bool read = true;
unsigned n = 0;
uint64_t u64;
- if (streq(name, "IOWriteBandwidthMax"))
- read = false;
-
r = sd_bus_message_enter_container(message, 'a', "(st)");
if (r < 0)
return r;
@@ -442,6 +435,8 @@ int bus_cgroup_set_property(
}
if (!a) {
+ CGroupIOLimitType type;
+
a = new0(CGroupIODeviceLimit, 1);
if (!a)
return -ENOMEM;
@@ -452,16 +447,13 @@ int bus_cgroup_set_property(
return -ENOMEM;
}
- a->rbps_max = CGROUP_LIMIT_MAX;
- a->wbps_max = CGROUP_LIMIT_MAX;
+ for (type = 0; type < _CGROUP_IO_LIMIT_TYPE_MAX; type++)
+ a->limits[type] = cgroup_io_limit_defaults[type];
LIST_PREPEND(device_limits, c->io_device_limits, a);
}
- if (read)
- a->rbps_max = u64;
- else
- a->wbps_max = u64;
+ a->limits[iol_type] = u64;
}
n++;
@@ -481,10 +473,7 @@ int bus_cgroup_set_property(
if (n == 0) {
LIST_FOREACH(device_limits, a, c->io_device_limits)
- if (read)
- a->rbps_max = CGROUP_LIMIT_MAX;
- else
- a->wbps_max = CGROUP_LIMIT_MAX;
+ a->limits[iol_type] = cgroup_io_limit_defaults[iol_type];
}
unit_invalidate_cgroup(u, CGROUP_MASK_IO);
@@ -493,17 +482,10 @@ int bus_cgroup_set_property(
if (!f)
return -ENOMEM;
- if (read) {
- fputs("IOReadBandwidthMax=\n", f);
- LIST_FOREACH(device_limits, a, c->io_device_limits)
- if (a->rbps_max != CGROUP_LIMIT_MAX)
- fprintf(f, "IOReadBandwidthMax=%s %" PRIu64 "\n", a->path, a->rbps_max);
- } else {
- fputs("IOWriteBandwidthMax=\n", f);
- LIST_FOREACH(device_limits, a, c->io_device_limits)
- if (a->wbps_max != CGROUP_LIMIT_MAX)
- fprintf(f, "IOWriteBandwidthMax=%s %" PRIu64 "\n", a->path, a->wbps_max);
- }
+ fprintf(f, "%s=\n", name);
+ LIST_FOREACH(device_limits, a, c->io_device_limits)
+ if (a->limits[iol_type] != cgroup_io_limit_defaults[iol_type])
+ fprintf(f, "%s=%s %" PRIu64 "\n", name, a->path, a->limits[iol_type]);
r = fflush_and_check(f);
if (r < 0)