From: Lennart Poettering Date: Wed, 24 Nov 2021 14:24:55 +0000 (+0100) Subject: shared: split out ioprio related stuff into ioprio-util.[ch] X-Git-Tag: v250-rc1~163^2~6 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=032b3afbf4abe3cf760469d9d1cd2e4162829441;p=thirdparty%2Fsystemd.git shared: split out ioprio related stuff into ioprio-util.[ch] No actual code changes, just some splitting out. --- diff --git a/src/basic/ioprio-util.c b/src/basic/ioprio-util.c new file mode 100644 index 00000000000..b63650b80b2 --- /dev/null +++ b/src/basic/ioprio-util.c @@ -0,0 +1,31 @@ +/* SPDX-License-Identifier: LGPL-2.1-or-later */ + +#include "ioprio-util.h" +#include "parse-util.h" +#include "string-table.h" + +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", + [IOPRIO_CLASS_BE] = "best-effort", + [IOPRIO_CLASS_IDLE] = "idle", +}; + +DEFINE_STRING_TABLE_LOOKUP_WITH_FALLBACK(ioprio_class, int, IOPRIO_N_CLASSES); diff --git a/src/basic/ioprio-util.h b/src/basic/ioprio-util.h new file mode 100644 index 00000000000..ffb3e9c8901 --- /dev/null +++ b/src/basic/ioprio-util.h @@ -0,0 +1,18 @@ +/* SPDX-License-Identifier: LGPL-2.1-or-later */ +#pragma once + +#include "macro.h" +#include "missing_ioprio.h" + +int ioprio_class_to_string_alloc(int i, char **s); +int ioprio_class_from_string(const char *s); + +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); diff --git a/src/basic/meson.build b/src/basic/meson.build index f0d5a1d2eab..bc90100c345 100644 --- a/src/basic/meson.build +++ b/src/basic/meson.build @@ -82,6 +82,8 @@ basic_sources = files(''' inotify-util.h io-util.c io-util.h + ioprio-util.c + ioprio-util.h limits-util.c limits-util.h linux/btrfs.h diff --git a/src/basic/process-util.c b/src/basic/process-util.c index bea53ccb7d5..1dd2414bb21 100644 --- a/src/basic/process-util.c +++ b/src/basic/process-util.c @@ -1132,23 +1132,6 @@ int pid_compare_func(const pid_t *a, const pid_t *b) { return CMP(*a, *b); } -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; -} - /* The cached PID, possible values: * * == UNSET [0] → cache not initialized yet @@ -1627,14 +1610,6 @@ _noreturn_ void freeze(void) { pause(); } -static const char *const ioprio_class_table[] = { - [IOPRIO_CLASS_NONE] = "none", - [IOPRIO_CLASS_RT] = "realtime", - [IOPRIO_CLASS_BE] = "best-effort", - [IOPRIO_CLASS_IDLE] = "idle", -}; - -DEFINE_STRING_TABLE_LOOKUP_WITH_FALLBACK(ioprio_class, int, IOPRIO_N_CLASSES); static const char *const sigchld_code_table[] = { [CLD_EXITED] = "exited", diff --git a/src/basic/process-util.h b/src/basic/process-util.h index 25dea35ce6c..c312e05d9cf 100644 --- a/src/basic/process-util.h +++ b/src/basic/process-util.h @@ -14,7 +14,6 @@ #include "alloc-util.h" #include "format-util.h" #include "macro.h" -#include "missing_ioprio.h" #include "time-util.h" #define procfs_file_alloca(pid, field) \ @@ -97,9 +96,6 @@ const char *personality_to_string(unsigned long); int safe_personality(unsigned long p); int opinionated_personality(unsigned long *ret); -int ioprio_class_to_string_alloc(int i, char **s); -int ioprio_class_from_string(const char *s); - const char *sigchld_code_to_string(int i) _const_; int sigchld_code_from_string(const char *s) _pure_; @@ -130,20 +126,10 @@ static inline bool sched_priority_is_valid(int i) { return i >= 0 && i <= sched_get_priority_max(SCHED_RR); } -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; -} - static inline bool pid_is_valid(pid_t p) { return p > 0; } -int ioprio_parse_priority(const char *s, int *ret); - pid_t getpid_cached(void); void reset_cached_pid(void); diff --git a/src/core/dbus-execute.c b/src/core/dbus-execute.c index afb2d8f10f2..c8323d84baa 100644 --- a/src/core/dbus-execute.c +++ b/src/core/dbus-execute.c @@ -24,6 +24,7 @@ #include "fileio.h" #include "hexdecoct.h" #include "io-util.h" +#include "ioprio-util.h" #include "journal-file.h" #include "missing_ioprio.h" #include "mountpoint-util.h" diff --git a/src/core/execute.c b/src/core/execute.c index ba66b9e6ece..e578bace6ff 100644 --- a/src/core/execute.c +++ b/src/core/execute.c @@ -63,6 +63,7 @@ #include "glob-util.h" #include "hexdecoct.h" #include "io-util.h" +#include "ioprio-util.h" #include "label.h" #include "log.h" #include "macro.h" diff --git a/src/core/load-fragment.c b/src/core/load-fragment.c index 6efcba3265a..0e93ddfbc04 100644 --- a/src/core/load-fragment.c +++ b/src/core/load-fragment.c @@ -40,6 +40,7 @@ #include "fs-util.h" #include "hexdecoct.h" #include "io-util.h" +#include "ioprio-util.h" #include "ip-protocol-list.h" #include "journal-file.h" #include "limits-util.h" diff --git a/src/shared/bus-unit-util.c b/src/shared/bus-unit-util.c index b8fd85a1914..c58394e63eb 100644 --- a/src/shared/bus-unit-util.c +++ b/src/shared/bus-unit-util.c @@ -19,6 +19,7 @@ #include "hexdecoct.h" #include "hostname-util.h" #include "in-addr-util.h" +#include "ioprio-util.h" #include "ip-protocol-list.h" #include "libmount-util.h" #include "locale-util.h" diff --git a/src/test/test-process-util.c b/src/test/test-process-util.c index b87a24b3420..dc45712937a 100644 --- a/src/test/test-process-util.c +++ b/src/test/test-process-util.c @@ -19,6 +19,7 @@ #include "errno-list.h" #include "errno-util.h" #include "fd-util.h" +#include "ioprio-util.h" #include "log.h" #include "macro.h" #include "missing_sched.h"