chiark / gitweb /
systemcl: add support for setting BlockIORead/WriteBandwidth for unit
authorGao feng <gaofeng@cn.fujitsu.com>
Fri, 30 Aug 2013 02:56:02 +0000 (10:56 +0800)
committerLennart Poettering <lennart@poettering.net>
Tue, 10 Sep 2013 15:29:55 +0000 (17:29 +0200)
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"

src/systemctl/systemctl.c

index a635891bc015fc94124c71a875fc9dc86e1991d2..889d1205881c51e8472659070d1ef507c6500dba 100644 (file)
@@ -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;