diff options
author | Gao feng <gaofeng@cn.fujitsu.com> | 2013-08-27 13:36:54 +0800 |
---|---|---|
committer | Lennart Poettering <lennart@poettering.net> | 2013-09-10 18:31:43 +0200 |
commit | 7239c1707a69aff63425e8b6570cfabbd7386f61 (patch) | |
tree | a264c3067d5da2c90cab89e6c793188221ce13e0 | |
parent | 6f68ecb450970cafea6d1893f63c0b6385518822 (diff) |
systemcl: add support for setting BlockIODeviceWeight for unit
This patch allows user to set up BlockIODeviceWeight for unit
through systemctl. Such as
systemctl set-property sshd.service BlockIODeviceWeight="/dev/sda 100"
-rw-r--r-- | src/systemctl/systemctl.c | 42 |
1 files changed, 42 insertions, 0 deletions
diff --git a/src/systemctl/systemctl.c b/src/systemctl/systemctl.c index 889d120588..0aeae91b35 100644 --- a/src/systemctl/systemctl.c +++ b/src/systemctl/systemctl.c @@ -3746,6 +3746,48 @@ static int append_assignment(DBusMessageIter *iter, const char *assignment) { if (!dbus_message_iter_close_container(&sub, &sub2)) return log_oom(); + } else if (streq(field, "BlockIODeviceWeight")) { + 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, *weight; + DBusMessageIter sub3; + uint64_t u; + char *e; + + e = strchr(eq, ' '); + if (e) { + path = strndupa(eq, e - eq); + weight = 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 = safe_atou64(weight, &u); + if (r < 0) { + log_error("Failed to parse %s value %s.", field, weight); + 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_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; |