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"
This commit is contained in:
committed by
Lennart Poettering
parent
f004c2ca11
commit
670612567b
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user