]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
Get rid of ioprio.h and add a minimalistic reimplementation of the api 20736/head
authorZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>
Tue, 14 Sep 2021 14:45:07 +0000 (16:45 +0200)
committerZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>
Wed, 22 Sep 2021 10:58:47 +0000 (12:58 +0200)
src/basic/ioprio.h [deleted file]
src/basic/meson.build
src/basic/missing_ioprio.h [new file with mode: 0644]
src/basic/process-util.c
src/basic/process-util.h
src/core/dbus-execute.c
src/core/execute.c
src/core/load-fragment.c

diff --git a/src/basic/ioprio.h b/src/basic/ioprio.h
deleted file mode 100644 (file)
index 3fb168d..0000000
+++ /dev/null
@@ -1,56 +0,0 @@
-#ifndef IOPRIO_H
-#define IOPRIO_H
-
-/* This is minimal version of Linux' linux/ioprio.h header file, which
- * is licensed GPL2 */
-
-#include <sys/syscall.h>
-#include <unistd.h>
-
-/*
- * Gives us 8 prio classes with 13-bits of data for each class
- */
-#define IOPRIO_BITS             16
-#define IOPRIO_N_CLASSES        8
-#define IOPRIO_CLASS_SHIFT      13
-#define IOPRIO_PRIO_MASK        ((1UL << IOPRIO_CLASS_SHIFT) - 1)
-
-#define IOPRIO_PRIO_CLASS(mask) ((mask) >> IOPRIO_CLASS_SHIFT)
-#define IOPRIO_PRIO_DATA(mask)  ((mask) & IOPRIO_PRIO_MASK)
-#define IOPRIO_PRIO_VALUE(class, data)  (((class) << IOPRIO_CLASS_SHIFT) | data)
-
-#define ioprio_valid(mask)      (IOPRIO_PRIO_CLASS((mask)) != IOPRIO_CLASS_NONE)
-
-/*
- * These are the io priority groups as implemented by CFQ. RT is the realtime
- * class, it always gets premium service. BE is the best-effort scheduling
- * class, the default for any process. IDLE is the idle scheduling class, it
- * is only served when no one else is using the disk.
- */
-enum {
-        IOPRIO_CLASS_NONE,
-        IOPRIO_CLASS_RT,
-        IOPRIO_CLASS_BE,
-        IOPRIO_CLASS_IDLE,
-};
-
-/*
- * 8 best effort priority levels are supported
- */
-#define IOPRIO_BE_NR    (8)
-
-enum {
-        IOPRIO_WHO_PROCESS = 1,
-        IOPRIO_WHO_PGRP,
-        IOPRIO_WHO_USER,
-};
-
-static inline int ioprio_set(int which, int who, int ioprio) {
-        return syscall(__NR_ioprio_set, which, who, ioprio);
-}
-
-static inline int ioprio_get(int which, int who) {
-        return syscall(__NR_ioprio_get, which, who);
-}
-
-#endif
index 8fe53b20936ea21540f16174c885d7822e81eba2..137609f86e5ff38ff1d378ecf9d6a7f657c50177 100644 (file)
@@ -72,7 +72,6 @@ basic_sources = files('''
         in-addr-util.h
         io-util.c
         io-util.h
-        ioprio.h
         khash.c
         khash.h
         limits-util.c
@@ -131,6 +130,7 @@ basic_sources = files('''
         missing_fcntl.h
         missing_fs.h
         missing_input.h
+        missing_ioprio.h
         missing_keyctl.h
         missing_magic.h
         missing_mman.h
diff --git a/src/basic/missing_ioprio.h b/src/basic/missing_ioprio.h
new file mode 100644 (file)
index 0000000..9cbd172
--- /dev/null
@@ -0,0 +1,59 @@
+/* SPDX-License-Identifier: LGPL-2.1-or-later */
+#pragma once
+
+#include <sched.h>
+
+/* Match values uses by the kernel internally, as no public header seems to exist. */
+
+#ifndef IOPRIO_N_CLASSES
+#  define IOPRIO_N_CLASSES 8
+#endif
+
+#ifndef IOPRIO_BE_NR
+#  define IOPRIO_BE_NR 8
+#endif
+
+#ifndef IOPRIO_CLASS_NONE
+#  define IOPRIO_CLASS_NONE 0
+#endif
+#ifndef IOPRIO_CLASS_RT
+#  define IOPRIO_CLASS_RT   1
+#endif
+#ifndef IOPRIO_CLASS_BE
+#  define IOPRIO_CLASS_BE   2
+#endif
+#ifndef IOPRIO_CLASS_IDLE
+#  define IOPRIO_CLASS_IDLE 3
+#endif
+
+#ifndef IOPRIO_WHO_PROCESS
+#  define IOPRIO_WHO_PROCESS 1
+#endif
+#ifndef IOPRIO_WHO_PGRP
+#  define IOPRIO_WHO_PGRP    2
+#endif
+#ifndef IOPRIO_WHO_USER
+#  define IOPRIO_WHO_USER    3
+#endif
+
+#ifndef IOPRIO_BITS
+#  define IOPRIO_BITS        16
+#endif
+#ifndef IOPRIO_N_CLASSES
+#  define IOPRIO_N_CLASSES    8
+#endif
+#ifndef IOPRIO_CLASS_SHIFT
+#  define IOPRIO_CLASS_SHIFT 13
+#endif
+
+static inline int ioprio_prio_class(int value) {
+        return value >> IOPRIO_CLASS_SHIFT;
+}
+
+static inline int ioprio_prio_data(int value) {
+        return value & ((1 << IOPRIO_CLASS_SHIFT) - 1);
+}
+
+static inline int ioprio_prio_value(int class, int data) {
+        return (class << IOPRIO_CLASS_SHIFT) | data;
+}
index 5855ac3d5793898be782f9a5cb61552fd2ab6191..c424f62ef3822c1fcfb9de34108a9899a72a905d 100644 (file)
@@ -27,7 +27,6 @@
 #include "fd-util.h"
 #include "fileio.h"
 #include "fs-util.h"
-#include "ioprio.h"
 #include "locale-util.h"
 #include "log.h"
 #include "macro.h"
index c9536495023855d5e9a363818d2eeac87ba9f160..551b236c01156590d72c71931b2abd6b3a85f0c2 100644 (file)
@@ -13,8 +13,8 @@
 
 #include "alloc-util.h"
 #include "format-util.h"
-#include "ioprio.h"
 #include "macro.h"
+#include "missing_ioprio.h"
 #include "time-util.h"
 
 #define procfs_file_alloca(pid, field)                                  \
index 5ea97b919403146c94d5ee06f489cba813cf62f5..13a64809e0c4a7b2d260e055f4ccda99f9fa6846 100644 (file)
@@ -24,8 +24,8 @@
 #include "fileio.h"
 #include "hexdecoct.h"
 #include "io-util.h"
-#include "ioprio.h"
 #include "journal-file.h"
+#include "missing_ioprio.h"
 #include "mountpoint-util.h"
 #include "namespace.h"
 #include "parse-util.h"
@@ -55,8 +55,8 @@ static BUS_DEFINE_PROPERTY_GET_ENUM(property_get_protect_system, protect_system,
 static BUS_DEFINE_PROPERTY_GET_ENUM(property_get_personality, personality, unsigned long);
 static BUS_DEFINE_PROPERTY_GET(property_get_ioprio, "i", ExecContext, exec_context_get_effective_ioprio);
 static BUS_DEFINE_PROPERTY_GET(property_get_mount_apivfs, "b", ExecContext, exec_context_get_effective_mount_apivfs);
-static BUS_DEFINE_PROPERTY_GET2(property_get_ioprio_class, "i", ExecContext, exec_context_get_effective_ioprio, IOPRIO_PRIO_CLASS);
-static BUS_DEFINE_PROPERTY_GET2(property_get_ioprio_priority, "i", ExecContext, exec_context_get_effective_ioprio, IOPRIO_PRIO_DATA);
+static BUS_DEFINE_PROPERTY_GET2(property_get_ioprio_class, "i", ExecContext, exec_context_get_effective_ioprio, ioprio_prio_class);
+static BUS_DEFINE_PROPERTY_GET2(property_get_ioprio_priority, "i", ExecContext, exec_context_get_effective_ioprio, ioprio_prio_data);
 static BUS_DEFINE_PROPERTY_GET_GLOBAL(property_get_empty_string, "s", NULL);
 static BUS_DEFINE_PROPERTY_GET_REF(property_get_syslog_level, "i", int, LOG_PRI);
 static BUS_DEFINE_PROPERTY_GET_REF(property_get_syslog_facility, "i", int, LOG_FAC);
@@ -2637,7 +2637,7 @@ int bus_exec_context_set_transient_property(
                         if (r < 0)
                                 return r;
 
-                        c->ioprio = IOPRIO_PRIO_VALUE(q, IOPRIO_PRIO_DATA(c->ioprio));
+                        c->ioprio = ioprio_prio_value(q, ioprio_prio_data(c->ioprio));
                         c->ioprio_set = true;
 
                         unit_write_settingf(u, flags, name, "IOSchedulingClass=%s", s);
@@ -2656,7 +2656,7 @@ int bus_exec_context_set_transient_property(
                         return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS, "Invalid IO scheduling priority: %i", p);
 
                 if (!UNIT_WRITE_FLAGS_NOOP(flags)) {
-                        c->ioprio = IOPRIO_PRIO_VALUE(IOPRIO_PRIO_CLASS(c->ioprio), p);
+                        c->ioprio = ioprio_prio_value(ioprio_prio_class(c->ioprio), p);
                         c->ioprio_set = true;
 
                         unit_write_settingf(u, flags, name, "IOSchedulingPriority=%i", p);
index c1fad61554825ae48f3f4b8212f55f0b1112ced7..007aab7b0593872b03cede5946898f376d39970e 100644 (file)
@@ -62,7 +62,6 @@
 #include "glob-util.h"
 #include "hexdecoct.h"
 #include "io-util.h"
-#include "ioprio.h"
 #include "label.h"
 #include "log.h"
 #include "macro.h"
@@ -70,6 +69,7 @@
 #include "manager-dump.h"
 #include "memory-util.h"
 #include "missing_fs.h"
+#include "missing_ioprio.h"
 #include "mkdir.h"
 #include "mount-util.h"
 #include "mountpoint-util.h"
@@ -4865,7 +4865,7 @@ void exec_context_init(ExecContext *c) {
         assert(c);
 
         c->umask = 0022;
-        c->ioprio = IOPRIO_PRIO_VALUE(IOPRIO_CLASS_BE, 0);
+        c->ioprio = ioprio_prio_value(IOPRIO_CLASS_BE, 0);
         c->cpu_sched_policy = SCHED_OTHER;
         c->syslog_priority = LOG_DAEMON|LOG_INFO;
         c->syslog_level_prefix = true;
@@ -5427,11 +5427,11 @@ void exec_context_dump(const ExecContext *c, FILE* f, const char *prefix) {
         if (c->ioprio_set) {
                 _cleanup_free_ char *class_str = NULL;
 
-                r = ioprio_class_to_string_alloc(IOPRIO_PRIO_CLASS(c->ioprio), &class_str);
+                r = ioprio_class_to_string_alloc(ioprio_prio_class(c->ioprio), &class_str);
                 if (r >= 0)
                         fprintf(f, "%sIOSchedulingClass: %s\n", prefix, class_str);
 
-                fprintf(f, "%sIOPriority: %lu\n", prefix, IOPRIO_PRIO_DATA(c->ioprio));
+                fprintf(f, "%sIOPriority: %d\n", prefix, ioprio_prio_data(c->ioprio));
         }
 
         if (c->cpu_sched_set) {
@@ -5784,7 +5784,7 @@ int exec_context_get_effective_ioprio(const ExecContext *c) {
 
         p = ioprio_get(IOPRIO_WHO_PROCESS, 0);
         if (p < 0)
-                return IOPRIO_PRIO_VALUE(IOPRIO_CLASS_BE, 4);
+                return ioprio_prio_value(IOPRIO_CLASS_BE, 4);
 
         return p;
 }
index 220f11f8259cf3587d83986355aecddeb2db17de..4f74f44c7dc80e5c78ae114a6d60ef69cba8327f 100644 (file)
 #include "fs-util.h"
 #include "hexdecoct.h"
 #include "io-util.h"
-#include "ioprio.h"
 #include "ip-protocol-list.h"
 #include "journal-file.h"
 #include "limits-util.h"
 #include "load-fragment.h"
 #include "log.h"
+#include "missing_ioprio.h"
 #include "mountpoint-util.h"
 #include "nulstr-util.h"
 #include "parse-socket-bind-item.h"
@@ -1266,7 +1266,7 @@ int config_parse_exec_io_class(const char *unit,
 
         if (isempty(rvalue)) {
                 c->ioprio_set = false;
-                c->ioprio = IOPRIO_PRIO_VALUE(IOPRIO_CLASS_BE, 0);
+                c->ioprio = ioprio_prio_value(IOPRIO_CLASS_BE, 0);
                 return 0;
         }
 
@@ -1276,7 +1276,7 @@ int config_parse_exec_io_class(const char *unit,
                 return 0;
         }
 
-        c->ioprio = IOPRIO_PRIO_VALUE(x, IOPRIO_PRIO_DATA(c->ioprio));
+        c->ioprio = ioprio_prio_value(x, ioprio_prio_data(c->ioprio));
         c->ioprio_set = true;
 
         return 0;
@@ -1303,7 +1303,7 @@ int config_parse_exec_io_priority(const char *unit,
 
         if (isempty(rvalue)) {
                 c->ioprio_set = false;
-                c->ioprio = IOPRIO_PRIO_VALUE(IOPRIO_CLASS_BE, 0);
+                c->ioprio = ioprio_prio_value(IOPRIO_CLASS_BE, 0);
                 return 0;
         }
 
@@ -1313,7 +1313,7 @@ int config_parse_exec_io_priority(const char *unit,
                 return 0;
         }
 
-        c->ioprio = IOPRIO_PRIO_VALUE(IOPRIO_PRIO_CLASS(c->ioprio), i);
+        c->ioprio = ioprio_prio_value(ioprio_prio_class(c->ioprio), i);
         c->ioprio_set = true;
 
         return 0;