diff options
author | Denis Vlasenko <vda.linux@googlemail.com> | 2009-01-31 21:45:57 +0000 |
---|---|---|
committer | Denis Vlasenko <vda.linux@googlemail.com> | 2009-01-31 21:45:57 +0000 |
commit | 4acdb46ff17a3dd966ddccdc149cda5a18d51a48 (patch) | |
tree | e467e075ec91dd753eb1359d6b350c09ed52d78e | |
parent | 802cab15e5407269cc3bb3a53fe076e86b62307e (diff) | |
download | busybox-w32-4acdb46ff17a3dd966ddccdc149cda5a18d51a48.tar.gz busybox-w32-4acdb46ff17a3dd966ddccdc149cda5a18d51a48.tar.bz2 busybox-w32-4acdb46ff17a3dd966ddccdc149cda5a18d51a48.zip |
ionice: new applet, adapted from Linux kernel' example by Walter Harms
text data bss dec hex filename
1050316 924 10952 1062192 103530 busybox_old
1050758 924 10952 1062634 1036ea busybox_unstripped
-rw-r--r-- | include/applets.h | 1 | ||||
-rw-r--r-- | include/usage.h | 10 | ||||
-rw-r--r-- | miscutils/Config.in | 7 | ||||
-rw-r--r-- | miscutils/Kbuild | 1 | ||||
-rw-r--r-- | miscutils/ionice.c | 99 |
5 files changed, 117 insertions, 1 deletions
diff --git a/include/applets.h b/include/applets.h index 63cc73867..af21a0d4a 100644 --- a/include/applets.h +++ b/include/applets.h | |||
@@ -193,6 +193,7 @@ USE_INOTIFYD(APPLET(inotifyd, _BB_DIR_SBIN, _BB_SUID_NEVER)) | |||
193 | USE_INSMOD(APPLET(insmod, _BB_DIR_SBIN, _BB_SUID_NEVER)) | 193 | USE_INSMOD(APPLET(insmod, _BB_DIR_SBIN, _BB_SUID_NEVER)) |
194 | USE_MODPROBE_SMALL(APPLET_ODDNAME(insmod, modprobe, _BB_DIR_SBIN, _BB_SUID_NEVER, modprobe)) | 194 | USE_MODPROBE_SMALL(APPLET_ODDNAME(insmod, modprobe, _BB_DIR_SBIN, _BB_SUID_NEVER, modprobe)) |
195 | USE_INSTALL(APPLET(install, _BB_DIR_USR_BIN, _BB_SUID_NEVER)) | 195 | USE_INSTALL(APPLET(install, _BB_DIR_USR_BIN, _BB_SUID_NEVER)) |
196 | USE_IONICE(APPLET(ionice, _BB_DIR_BIN, _BB_SUID_NEVER)) | ||
196 | #if ENABLE_FEATURE_IP_ADDRESS \ | 197 | #if ENABLE_FEATURE_IP_ADDRESS \ |
197 | || ENABLE_FEATURE_IP_ROUTE \ | 198 | || ENABLE_FEATURE_IP_ROUTE \ |
198 | || ENABLE_FEATURE_IP_LINK \ | 199 | || ENABLE_FEATURE_IP_LINK \ |
diff --git a/include/usage.h b/include/usage.h index 9ceb3664f..cfe12c633 100644 --- a/include/usage.h +++ b/include/usage.h | |||
@@ -1932,7 +1932,7 @@ | |||
1932 | 1932 | ||
1933 | /* -v, -b, -c are ignored */ | 1933 | /* -v, -b, -c are ignored */ |
1934 | #define install_trivial_usage \ | 1934 | #define install_trivial_usage \ |
1935 | "[-cdDsp] [-o USER] [-g GRP] [-m MODE] [source] dest|directory" | 1935 | "[-cdDsp] [-o USER] [-g GRP] [-m MODE] [source] dest|directory" |
1936 | #define install_full_usage "\n\n" \ | 1936 | #define install_full_usage "\n\n" \ |
1937 | "Copy files and set attributes\n" \ | 1937 | "Copy files and set attributes\n" \ |
1938 | "\nOptions:" \ | 1938 | "\nOptions:" \ |
@@ -1948,6 +1948,14 @@ | |||
1948 | "\n -Z Set security context" \ | 1948 | "\n -Z Set security context" \ |
1949 | ) | 1949 | ) |
1950 | 1950 | ||
1951 | #define ionice_trivial_usage \ | ||
1952 | "[-c 1-3] [-n 0-7] [-p PID] [PROG]" | ||
1953 | #define ionice_full_usage "\n\n" \ | ||
1954 | "Change I/O scheduling class and priority\n" \ | ||
1955 | "\nOptions:" \ | ||
1956 | "\n -c Class. 1:realtime 2:best-effort 3:idle" \ | ||
1957 | "\n -n Priority" \ | ||
1958 | |||
1951 | /* would need to make the " | " optional depending on more than one selected: */ | 1959 | /* would need to make the " | " optional depending on more than one selected: */ |
1952 | #define ip_trivial_usage \ | 1960 | #define ip_trivial_usage \ |
1953 | "[OPTIONS] {" \ | 1961 | "[OPTIONS] {" \ |
diff --git a/miscutils/Config.in b/miscutils/Config.in index 68732e682..94174de3e 100644 --- a/miscutils/Config.in +++ b/miscutils/Config.in | |||
@@ -238,6 +238,13 @@ config FBSPLASH | |||
238 | "NN" (ASCII decimal number) - percentage to show on progress bar | 238 | "NN" (ASCII decimal number) - percentage to show on progress bar |
239 | "exit" - well you guessed it | 239 | "exit" - well you guessed it |
240 | 240 | ||
241 | config IONICE | ||
242 | bool "ionice" | ||
243 | default n | ||
244 | help | ||
245 | Set/set program io scheduling class and priority | ||
246 | Requires kernel >= 2.6.13 | ||
247 | |||
241 | config INOTIFYD | 248 | config INOTIFYD |
242 | bool "inotifyd" | 249 | bool "inotifyd" |
243 | default n | 250 | default n |
diff --git a/miscutils/Kbuild b/miscutils/Kbuild index e6e434755..7665130e5 100644 --- a/miscutils/Kbuild +++ b/miscutils/Kbuild | |||
@@ -16,6 +16,7 @@ lib-$(CONFIG_DEVFSD) += devfsd.o | |||
16 | lib-$(CONFIG_DEVMEM) += devmem.o | 16 | lib-$(CONFIG_DEVMEM) += devmem.o |
17 | lib-$(CONFIG_EJECT) += eject.o | 17 | lib-$(CONFIG_EJECT) += eject.o |
18 | lib-$(CONFIG_FBSPLASH) += fbsplash.o | 18 | lib-$(CONFIG_FBSPLASH) += fbsplash.o |
19 | lib-$(CONFIG_IONICE) += ionice.o | ||
19 | lib-$(CONFIG_HDPARM) += hdparm.o | 20 | lib-$(CONFIG_HDPARM) += hdparm.o |
20 | lib-$(CONFIG_INOTIFYD) += inotifyd.o | 21 | lib-$(CONFIG_INOTIFYD) += inotifyd.o |
21 | lib-$(CONFIG_FEATURE_LAST_SMALL)+= last.o | 22 | lib-$(CONFIG_FEATURE_LAST_SMALL)+= last.o |
diff --git a/miscutils/ionice.c b/miscutils/ionice.c new file mode 100644 index 000000000..88d771c30 --- /dev/null +++ b/miscutils/ionice.c | |||
@@ -0,0 +1,99 @@ | |||
1 | /* vi: set sw=4 ts=4: */ | ||
2 | /* | ||
3 | * ionice implementation for busybox based on linux-utils-ng 2.14 | ||
4 | * | ||
5 | * Copyright (C) 2008 by <u173034@informatik.uni-oldenburg.de> | ||
6 | * | ||
7 | * Licensed under GPLv2 or later, see file LICENSE in this tarball for details. | ||
8 | */ | ||
9 | |||
10 | #include <sys/syscall.h> | ||
11 | #include <asm/unistd.h> | ||
12 | #include "libbb.h" | ||
13 | |||
14 | static int ioprio_set(int which, int who, int ioprio) | ||
15 | { | ||
16 | return syscall(SYS_ioprio_set, which, who, ioprio); | ||
17 | } | ||
18 | |||
19 | static int ioprio_get(int which, int who) | ||
20 | { | ||
21 | return syscall(SYS_ioprio_get, which, who); | ||
22 | } | ||
23 | |||
24 | enum { | ||
25 | IOPRIO_WHO_PROCESS = 1, | ||
26 | IOPRIO_WHO_PGRP, | ||
27 | IOPRIO_WHO_USER | ||
28 | }; | ||
29 | |||
30 | enum { | ||
31 | IOPRIO_CLASS_NONE, | ||
32 | IOPRIO_CLASS_RT, | ||
33 | IOPRIO_CLASS_BE, | ||
34 | IOPRIO_CLASS_IDLE | ||
35 | }; | ||
36 | |||
37 | static const char to_prio[] = "none\0realtime\0best-effort\0idle"; | ||
38 | |||
39 | #define IOPRIO_CLASS_SHIFT 13 | ||
40 | |||
41 | int ionice_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE; | ||
42 | int ionice_main(int argc UNUSED_PARAM, char **argv) | ||
43 | { | ||
44 | /* Defaults */ | ||
45 | int ioclass = 0; | ||
46 | int pri = 0; | ||
47 | int pid = 0; /* affect own porcess */ | ||
48 | int opt; | ||
49 | enum { | ||
50 | OPT_n = 1, | ||
51 | OPT_c = 2, | ||
52 | OPT_p = 4, | ||
53 | }; | ||
54 | |||
55 | /* Numeric params */ | ||
56 | opt_complementary = "n+:c+:p+"; | ||
57 | /* '+': stop at first non-option */ | ||
58 | opt = getopt32(argv, "+n:c:p:", &pri, &ioclass, &pid); | ||
59 | argv += optind; | ||
60 | |||
61 | if (opt & OPT_c) { | ||
62 | if (ioclass > 3) | ||
63 | bb_error_msg_and_die("bad class %d", ioclass); | ||
64 | // Do we need this (compat?)? | ||
65 | // if (ioclass == IOPRIO_CLASS_NONE) | ||
66 | // ioclass = IOPRIO_CLASS_BE; | ||
67 | // if (ioclass == IOPRIO_CLASS_IDLE) { | ||
68 | // //if (opt & OPT_n) | ||
69 | // // bb_error_msg("ignoring priority for idle class"); | ||
70 | // pri = 7; | ||
71 | // } | ||
72 | } | ||
73 | |||
74 | if (!(opt & (OPT_n|OPT_c))) { | ||
75 | if (!(opt & OPT_p) && *argv) | ||
76 | pid = xatoi_u(*argv); | ||
77 | |||
78 | pri = ioprio_get(IOPRIO_WHO_PROCESS, pid); | ||
79 | if (pri == -1) | ||
80 | bb_perror_msg_and_die("ioprio_%cet", 'g'); | ||
81 | |||
82 | ioclass = (pri >> IOPRIO_CLASS_SHIFT) & 0x3; | ||
83 | pri &= 0xff; | ||
84 | printf((ioclass == IOPRIO_CLASS_IDLE) ? "%s\n" : "%s: prio %d\n", | ||
85 | nth_string(to_prio, ioclass), pri); | ||
86 | } else { | ||
87 | //printf("pri=%d class=%d val=%x\n", | ||
88 | //pri, ioclass, pri | (ioclass << IOPRIO_CLASS_SHIFT)); | ||
89 | pri |= (ioclass << IOPRIO_CLASS_SHIFT); | ||
90 | if (ioprio_set(IOPRIO_WHO_PROCESS, pid, pri) == -1) | ||
91 | bb_perror_msg_and_die("ioprio_%cet", 's'); | ||
92 | if (*argv) { | ||
93 | BB_EXECVP(*argv, argv); | ||
94 | bb_simple_perror_msg_and_die(*argv); | ||
95 | } | ||
96 | } | ||
97 | |||
98 | return EXIT_SUCCESS; | ||
99 | } | ||