Skip to content

Commit 032b3af

Browse files
committed
shared: split out ioprio related stuff into ioprio-util.[ch]
No actual code changes, just some splitting out.
1 parent 989db9b commit 032b3af

File tree

10 files changed

+56
-39
lines changed

10 files changed

+56
-39
lines changed

src/basic/ioprio-util.c

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
/* SPDX-License-Identifier: LGPL-2.1-or-later */
2+
3+
#include "ioprio-util.h"
4+
#include "parse-util.h"
5+
#include "string-table.h"
6+
7+
int ioprio_parse_priority(const char *s, int *ret) {
8+
int i, r;
9+
10+
assert(s);
11+
assert(ret);
12+
13+
r = safe_atoi(s, &i);
14+
if (r < 0)
15+
return r;
16+
17+
if (!ioprio_priority_is_valid(i))
18+
return -EINVAL;
19+
20+
*ret = i;
21+
return 0;
22+
}
23+
24+
static const char *const ioprio_class_table[] = {
25+
[IOPRIO_CLASS_NONE] = "none",
26+
[IOPRIO_CLASS_RT] = "realtime",
27+
[IOPRIO_CLASS_BE] = "best-effort",
28+
[IOPRIO_CLASS_IDLE] = "idle",
29+
};
30+
31+
DEFINE_STRING_TABLE_LOOKUP_WITH_FALLBACK(ioprio_class, int, IOPRIO_N_CLASSES);

src/basic/ioprio-util.h

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
/* SPDX-License-Identifier: LGPL-2.1-or-later */
2+
#pragma once
3+
4+
#include "macro.h"
5+
#include "missing_ioprio.h"
6+
7+
int ioprio_class_to_string_alloc(int i, char **s);
8+
int ioprio_class_from_string(const char *s);
9+
10+
static inline bool ioprio_class_is_valid(int i) {
11+
return IN_SET(i, IOPRIO_CLASS_NONE, IOPRIO_CLASS_RT, IOPRIO_CLASS_BE, IOPRIO_CLASS_IDLE);
12+
}
13+
14+
static inline bool ioprio_priority_is_valid(int i) {
15+
return i >= 0 && i < IOPRIO_BE_NR;
16+
}
17+
18+
int ioprio_parse_priority(const char *s, int *ret);

src/basic/meson.build

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,8 @@ basic_sources = files('''
8282
inotify-util.h
8383
io-util.c
8484
io-util.h
85+
ioprio-util.c
86+
ioprio-util.h
8587
limits-util.c
8688
limits-util.h
8789
linux/btrfs.h

src/basic/process-util.c

Lines changed: 0 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1132,23 +1132,6 @@ int pid_compare_func(const pid_t *a, const pid_t *b) {
11321132
return CMP(*a, *b);
11331133
}
11341134

1135-
int ioprio_parse_priority(const char *s, int *ret) {
1136-
int i, r;
1137-
1138-
assert(s);
1139-
assert(ret);
1140-
1141-
r = safe_atoi(s, &i);
1142-
if (r < 0)
1143-
return r;
1144-
1145-
if (!ioprio_priority_is_valid(i))
1146-
return -EINVAL;
1147-
1148-
*ret = i;
1149-
return 0;
1150-
}
1151-
11521135
/* The cached PID, possible values:
11531136
*
11541137
* == UNSET [0] → cache not initialized yet
@@ -1627,14 +1610,6 @@ _noreturn_ void freeze(void) {
16271610
pause();
16281611
}
16291612

1630-
static const char *const ioprio_class_table[] = {
1631-
[IOPRIO_CLASS_NONE] = "none",
1632-
[IOPRIO_CLASS_RT] = "realtime",
1633-
[IOPRIO_CLASS_BE] = "best-effort",
1634-
[IOPRIO_CLASS_IDLE] = "idle",
1635-
};
1636-
1637-
DEFINE_STRING_TABLE_LOOKUP_WITH_FALLBACK(ioprio_class, int, IOPRIO_N_CLASSES);
16381613

16391614
static const char *const sigchld_code_table[] = {
16401615
[CLD_EXITED] = "exited",

src/basic/process-util.h

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414
#include "alloc-util.h"
1515
#include "format-util.h"
1616
#include "macro.h"
17-
#include "missing_ioprio.h"
1817
#include "time-util.h"
1918

2019
#define procfs_file_alloca(pid, field) \
@@ -97,9 +96,6 @@ const char *personality_to_string(unsigned long);
9796
int safe_personality(unsigned long p);
9897
int opinionated_personality(unsigned long *ret);
9998

100-
int ioprio_class_to_string_alloc(int i, char **s);
101-
int ioprio_class_from_string(const char *s);
102-
10399
const char *sigchld_code_to_string(int i) _const_;
104100
int sigchld_code_from_string(const char *s) _pure_;
105101

@@ -130,20 +126,10 @@ static inline bool sched_priority_is_valid(int i) {
130126
return i >= 0 && i <= sched_get_priority_max(SCHED_RR);
131127
}
132128

133-
static inline bool ioprio_class_is_valid(int i) {
134-
return IN_SET(i, IOPRIO_CLASS_NONE, IOPRIO_CLASS_RT, IOPRIO_CLASS_BE, IOPRIO_CLASS_IDLE);
135-
}
136-
137-
static inline bool ioprio_priority_is_valid(int i) {
138-
return i >= 0 && i < IOPRIO_BE_NR;
139-
}
140-
141129
static inline bool pid_is_valid(pid_t p) {
142130
return p > 0;
143131
}
144132

145-
int ioprio_parse_priority(const char *s, int *ret);
146-
147133
pid_t getpid_cached(void);
148134
void reset_cached_pid(void);
149135

src/core/dbus-execute.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
#include "fileio.h"
2525
#include "hexdecoct.h"
2626
#include "io-util.h"
27+
#include "ioprio-util.h"
2728
#include "journal-file.h"
2829
#include "missing_ioprio.h"
2930
#include "mountpoint-util.h"

src/core/execute.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@
6363
#include "glob-util.h"
6464
#include "hexdecoct.h"
6565
#include "io-util.h"
66+
#include "ioprio-util.h"
6667
#include "label.h"
6768
#include "log.h"
6869
#include "macro.h"

src/core/load-fragment.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@
4040
#include "fs-util.h"
4141
#include "hexdecoct.h"
4242
#include "io-util.h"
43+
#include "ioprio-util.h"
4344
#include "ip-protocol-list.h"
4445
#include "journal-file.h"
4546
#include "limits-util.h"

src/shared/bus-unit-util.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
#include "hexdecoct.h"
2020
#include "hostname-util.h"
2121
#include "in-addr-util.h"
22+
#include "ioprio-util.h"
2223
#include "ip-protocol-list.h"
2324
#include "libmount-util.h"
2425
#include "locale-util.h"

src/test/test-process-util.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
#include "errno-list.h"
2020
#include "errno-util.h"
2121
#include "fd-util.h"
22+
#include "ioprio-util.h"
2223
#include "log.h"
2324
#include "macro.h"
2425
#include "missing_sched.h"

0 commit comments

Comments
 (0)