diff options
author | Gao feng <gaofeng@cn.fujitsu.com> | 2013-08-30 10:56:02 +0800 |
---|---|---|
committer | Lennart Poettering <lennart@poettering.net> | 2013-09-10 17:29:55 +0200 |
commit | 670612567ba54808fea06c445c6f2a7ee2d58197 (patch) | |
tree | 59bdbee4ee36945ce4b215681996dc8b8fd65f22 /src/systemctl | |
parent | f004c2ca11b1700fb8539a667194e8cd86cef7be (diff) |
systemcl: add support for setting BlockIORead/WriteBandwidth for unit
This patch allows user to set up BlockIOReadBandwidth and BlockIOWriteBandwidth
for unit through systemctl. Such as
systemctl set-property sshd.service BlockIOReadBandwidth="/dev/sda 100000"
systemctl set-property sshd.service BlockIOWriteBandwidth="/dev/sda 200000"
Diffstat (limited to 'src/systemctl')
-rw-r--r-- | src/systemctl/systemctl.c | 51 |
1 files changed, 51 insertions, 0 deletions
diff --git a/src/systemctl/systemctl.c b/src/systemctl/systemctl.c index a635891bc0..889d120588 100644 --- a/src/systemctl/systemctl.c +++ b/src/systemctl/systemctl.c @@ -3685,6 +3685,11 @@ static int append_assignment(DBusMessageIter *iter, const char *assignment) { rwm = ""; } + if (!path_startswith(path, "/dev")) { + log_error("%s is not a device file in /dev.", path); + return -EINVAL; + } + if (!dbus_message_iter_open_container(&sub2, DBUS_TYPE_STRUCT, NULL, &sub3) || !dbus_message_iter_append_basic(&sub3, DBUS_TYPE_STRING, &path) || !dbus_message_iter_append_basic(&sub3, DBUS_TYPE_STRING, &rwm) || @@ -3695,6 +3700,52 @@ static int append_assignment(DBusMessageIter *iter, const char *assignment) { if (!dbus_message_iter_close_container(&sub, &sub2)) return log_oom(); + } else if (streq(field, "BlockIOReadBandwidth") || streq(field, "BlockIOWriteBandwidth")) { + DBusMessageIter sub2; + + if (!dbus_message_iter_open_container(iter, DBUS_TYPE_VARIANT, "a(st)", &sub) || + !dbus_message_iter_open_container(&sub, DBUS_TYPE_ARRAY, "(st)", &sub2)) + return log_oom(); + + if (!isempty(eq)) { + const char *path, *bandwidth; + DBusMessageIter sub3; + uint64_t u; + off_t bytes; + char *e; + + e = strchr(eq, ' '); + if (e) { + path = strndupa(eq, e - eq); + bandwidth = e+1; + } else { + log_error("Failed to parse %s value %s.", field, eq); + return -EINVAL; + } + + if (!path_startswith(path, "/dev")) { + log_error("%s is not a device file in /dev.", path); + return -EINVAL; + } + + r = parse_bytes(bandwidth, &bytes); + if (r < 0) { + log_error("Failed to parse byte value %s.", bandwidth); + return -EINVAL; + } + + u = (uint64_t) bytes; + + if (!dbus_message_iter_open_container(&sub2, DBUS_TYPE_STRUCT, NULL, &sub3) || + !dbus_message_iter_append_basic(&sub3, DBUS_TYPE_STRING, &path) || + !dbus_message_iter_append_basic(&sub3, DBUS_TYPE_UINT64, &u) || + !dbus_message_iter_close_container(&sub2, &sub3)) + return log_oom(); + } + + if (!dbus_message_iter_close_container(&sub, &sub2)) + return log_oom(); + } else { log_error("Unknown assignment %s.", assignment); return -EINVAL; |