summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKarel Zak2011-07-22 11:39:06 +0200
committerKarel Zak2011-07-22 11:39:06 +0200
commitfe040397f9f935188f97676ce0180ad0e76bb764 (patch)
tree414bb0dff847985791a5d8fe70131ad22aa2d820
parentionice: improve command line interpretation (diff)
downloadkernel-qcow2-util-linux-fe040397f9f935188f97676ce0180ad0e76bb764.tar.gz
kernel-qcow2-util-linux-fe040397f9f935188f97676ce0180ad0e76bb764.tar.xz
kernel-qcow2-util-linux-fe040397f9f935188f97676ce0180ad0e76bb764.zip
ionice: allow to use names for -c <class>
for example: $ ionice -c best-effort bash Signed-off-by: Karel Zak <kzak@redhat.com>
-rw-r--r--schedutils/ionice.113
-rw-r--r--schedutils/ionice.c38
2 files changed, 37 insertions, 14 deletions
diff --git a/schedutils/ionice.1 b/schedutils/ionice.1
index 4f9cd5041..f2219535e 100644
--- a/schedutils/ionice.1
+++ b/schedutils/ionice.1
@@ -27,7 +27,7 @@ io scheduling class and priority for that process.
If no class is given than
.I COMMAND
-will be executed with "best effort" scheduling class. The default
+will be executed with "best-effort" scheduling class. The default
priority argument is 4.
As of this writing, a process can be in one of three scheduling classes:
@@ -37,7 +37,7 @@ program has asked for disk io for a defined grace period. The impact of idle
io processes on normal system activity should be zero. This scheduling
class does not take a priority argument. Presently, this scheduling class
is permitted for an ordinary user (since kernel 2.6.25).
-.IP "\fBBest effort\fP"
+.IP "\fBBest-effort\fP"
This is the effective scheduling class for any process that has not asked for
a specific io priority.
This class takes a priority argument from \fI0-7\fR, with lower
@@ -54,7 +54,7 @@ For kernels after 2.6.26 with CFQ io scheduler a process that has not asked for
an io priority inherits CPU scheduling class. The io priority is derived from
the cpu nice level of the process (same as before kernel 2.6.26).
-.IP "\fBReal time\fP"
+.IP "\fBRealtime\fP"
The RT scheduling class is given first access to the disk, regardless of
what else is going on in the system. Thus the RT class needs to be used with
some care, as it can starve other processes. As with the best effort class,
@@ -63,8 +63,8 @@ will receive on each scheduling window. This scheduling class is not
permitted for an ordinary (i.e., non-root) user.
.SH OPTIONS
.TP
-\fB\-c\fR, \fB\-\-class\fR \fINUM\fR
-The scheduling class. \fI0\fR for none, \fI1\fR for real time, \fI2\fR for
+\fB\-c\fR, \fB\-\-class\fR \fICLASS\fR
+The scheduling class name or number. \fI0\fR for none, \fI1\fR for realtime, \fI2\fR for
best-effort, \fI3\fR for idle.
.TP
\fB\-n\fR, \fB\-\-classdata\fR \fINUM\fR
@@ -105,7 +105,10 @@ Prints the class and priority of the processes with PID 89 and 91.
Linux supports io scheduling priorities and classes since 2.6.13 with the CFQ
io scheduler.
.SH AUTHORS
+.nf
Jens Axboe <jens@axboe.dk>
+Karel Zak <kzak@redhat.com>
+.fi
.SH AVAILABILITY
The ionice command is part of the util-linux package and is available from
ftp://ftp.kernel.org/pub/linux/utils/util-linux/.
diff --git a/schedutils/ionice.c b/schedutils/ionice.c
index f1db216ef..26dc2d3a8 100644
--- a/schedutils/ionice.c
+++ b/schedutils/ionice.c
@@ -12,6 +12,7 @@
#include <getopt.h>
#include <unistd.h>
#include <sys/syscall.h>
+#include <ctype.h>
#include "nls.h"
#include "strutils.h"
@@ -56,6 +57,16 @@ const char *to_prio[] = {
[IOPRIO_CLASS_IDLE] = "idle"
};
+static int parse_ioclass(const char *str)
+{
+ int i;
+
+ for (i = 0; i < ARRAY_SIZE(to_prio); i++)
+ if (!strcasecmp(str, to_prio[i]))
+ return i;
+ return -1;
+}
+
static void ioprio_print(int pid)
{
int ioprio = ioprio_get(IOPRIO_WHO_PROCESS, pid);
@@ -93,14 +104,14 @@ static void __attribute__ ((__noreturn__)) usage(FILE * out)
" %1$s [OPTION] COMMAND\n"
"\n"
"Options:\n"
- " -c, --class=NUM scheduling class\n"
- " 0: none, 1: realtime, 2: best-effort, 3: idle\n"
- " -n, --classdata=NUM scheduling class data\n"
- " 0-7 for realtime and best-effort classes\n"
- " -p, --pid=PID view or modify already running process\n"
- " -t, --ignore ignore failures\n"
- " -V, --version output version information and exit\n"
- " -h, --help display this help and exit\n\n"),
+ " -c, --class <class> scheduling class name or number\n"
+ " 0: none, 1: realtime, 2: best-effort, 3: idle\n"
+ " -n, --classdata <num> scheduling class data\n"
+ " 0-7 for realtime and best-effort classes\n"
+ " -p, --pid=PID view or modify already running process\n"
+ " -t, --ignore ignore failures\n"
+ " -V, --version output version information and exit\n"
+ " -h, --help display this help and exit\n\n"),
program_invocation_short_name);
exit(out == stderr ? EXIT_FAILURE : EXIT_SUCCESS);
@@ -132,7 +143,16 @@ int main(int argc, char **argv)
set |= 1;
break;
case 'c':
- ioclass = strtol_or_err(optarg, _("failed to parse class"));
+ if (isdigit(*optarg))
+ ioclass = strtol_or_err(optarg,
+ _("failed to parse class"));
+ else {
+ ioclass = parse_ioclass(optarg);
+ if (ioclass < 0)
+ errx(EXIT_FAILURE,
+ _("unknown scheduling class: '%s'"),
+ optarg);
+ }
set |= 2;
break;
case 'p':