chiark / gitweb /
core: make IOSchedulingClass= and IOSchedulingPriority= settable for transient units
authorLennart Poettering <lennart@poettering.net>
Mon, 26 Jun 2017 15:40:08 +0000 (17:40 +0200)
committerSven Eden <yamakuzure@gmx.net>
Tue, 25 Jul 2017 07:46:53 +0000 (09:46 +0200)
This patch is a bit more complex thant I hoped. In particular the single
IOScheduling= property exposed on the bus is split up into
IOSchedulingClass= and IOSchedulingPriority= (though compat is
retained). Otherwise the asymmetry between setting props and getting
them is a bit too nasty.

Fixes #5613

src/basic/process-util.c
src/basic/process-util.h

index cb41fbf3199f266881ee6de908dd06f52393c56c..da825a7c3c5f6d2916980430d71f2e6d8bae870e 100644 (file)
@@ -914,6 +914,23 @@ int pid_compare_func(const void *a, const void *b) {
         return 0;
 }
 
+int ioprio_parse_priority(const char *s, int *ret) {
+        int i, r;
+
+        assert(s);
+        assert(ret);
+
+        r = safe_atoi(s, &i);
+        if (r < 0)
+                return r;
+
+        if (!ioprio_priority_is_valid(i))
+                return -EINVAL;
+
+        *ret = i;
+        return 0;
+}
+
 static const char *const ioprio_class_table[] = {
         [IOPRIO_CLASS_NONE] = "none",
         [IOPRIO_CLASS_RT] = "realtime",
index 33c6637a4b34d9c4cf6ffb79e0be0e660776338c..f73d598d81a03d4740e53b158443e8bb24b01f0a 100644 (file)
 #include <stddef.h>
 #include <stdio.h>
 #include <string.h>
-#include <sys/types.h>
 #include <sys/resource.h>
+#include <sys/types.h>
 
 #include "format-util.h"
+#include "ioprio.h"
 #include "macro.h"
 
 #define procfs_file_alloca(pid, field)                                  \
@@ -120,3 +121,13 @@ static inline bool nice_is_valid(int n) {
         return n >= PRIO_MIN && n < PRIO_MAX;
 }
 #endif // 0
+
+static inline bool ioprio_class_is_valid(int i) {
+        return IN_SET(i, IOPRIO_CLASS_NONE, IOPRIO_CLASS_RT, IOPRIO_CLASS_BE, IOPRIO_CLASS_IDLE);
+}
+
+static inline bool ioprio_priority_is_valid(int i) {
+        return i >= 0 && i < IOPRIO_BE_NR;
+}
+
+int ioprio_parse_priority(const char *s, int *ret);