]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
ionice: allow to use names for -c <class>
authorKarel Zak <kzak@redhat.com>
Fri, 22 Jul 2011 09:39:06 +0000 (11:39 +0200)
committerKarel Zak <kzak@redhat.com>
Fri, 22 Jul 2011 09:39:06 +0000 (11:39 +0200)
 for example:

   $ ionice -c best-effort bash

Signed-off-by: Karel Zak <kzak@redhat.com>
schedutils/ionice.1
schedutils/ionice.c

index 4f9cd5041eee5f6cc5e2f85d7877c883604969b1..f2219535e91dc9ac7e91d955116872a28ce82e89 100644 (file)
@@ -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/.
index f1db216ef10b2598da2139c1a0f9e5d62fa678d3..26dc2d3a822757b2ae41786f0b93927994669ba1 100644 (file)
@@ -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':