[PATCH] ionice: add -t option

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



From: Lubomir Kundrak <lkundrak@xxxxxxxxxx>

This patch allows "tolerant" behavior, i.e. proceeding even if
priority could not be set. This might be of use in case something
(selinux, old kernel, etc.) does not allow the requested scheduling
priority to be set.

This could be to some extend done as follows:

	ionice -c3 command || command

but the downside is that one could not really tell if what failed was
setting priority or command itself, which could result in duplicate
command run.

This patch solves the situation, so that user can do

	ionice -t -c3 command

Addresses-Red-Hat-Bugzilla: #443842
Signed-off-by: Lubomir Kundrak <lkundrak@xxxxxxxxxx>
Signed-off-by: Karel Zak <kzak@xxxxxxxxxx>
---
 schedutils/ionice.1 |    5 +++++
 schedutils/ionice.c |   14 ++++++++++----
 2 files changed, 15 insertions(+), 4 deletions(-)

diff --git a/schedutils/ionice.1 b/schedutils/ionice.1
index 93aabe8..a17dd4f 100644
--- a/schedutils/ionice.1
+++ b/schedutils/ionice.1
@@ -50,6 +50,11 @@ data.
 Pass in a process pid to change an already running process. If this argument
 is not given, \fBionice\fP will run the listed program with the given
 parameters.
+.TP 7
+\fB-t\fP
+Ignore failure to set requested priority. If COMMAND is specified, run it
+even in case it was not possible to set desired scheduling priority, what
+can happen due to insufficient privilegies or old kernel version.
 
 .SH EXAMPLES
 .LP
diff --git a/schedutils/ionice.c b/schedutils/ionice.c
index 679014a..f5c02db 100644
--- a/schedutils/ionice.c
+++ b/schedutils/ionice.c
@@ -50,16 +50,17 @@ static void usage(void)
 	printf("\t-c\tScheduling class\n");
 	printf("\t\t\t1: realtime, 2: best-effort, 3: idle\n");
 	printf("\t-p\tProcess pid\n");
+	printf("\t-t\tIgnore failures to set priority, run command unconditionally\n");
 	printf("\t-h\tThis help page\n");
 	printf("\nJens Axboe <axboe@xxxxxxx> (C) 2005\n");
 }
 
 int main(int argc, char *argv[])
 {
-	int ioprio = 4, set = 0, ioprio_class = IOPRIO_CLASS_BE;
+	int ioprio = 4, set = 0, tolerant = 0, ioprio_class = IOPRIO_CLASS_BE;
 	int c, pid = 0;
 
-	while ((c = getopt(argc, argv, "+n:c:p:h")) != EOF) {
+	while ((c = getopt(argc, argv, "+n:c:p:th")) != EOF) {
 		switch (c) {
 		case 'n':
 			ioprio = strtol(optarg, NULL, 10);
@@ -72,6 +73,9 @@ int main(int argc, char *argv[])
 		case 'p':
 			pid = strtol(optarg, NULL, 10);
 			break;
+		case 't':
+			tolerant = 1;
+			break;
 		case 'h':
 		default:
 			usage();
@@ -115,8 +119,10 @@ int main(int argc, char *argv[])
 		}
 	} else {
 		if (ioprio_set(IOPRIO_WHO_PROCESS, pid, ioprio | ioprio_class << IOPRIO_CLASS_SHIFT) == -1) {
-			perror("ioprio_set");
-			exit(EXIT_FAILURE);
+			if (!tolerant) {
+				perror("ioprio_set");
+				exit(EXIT_FAILURE);
+			}
 		}
 
 		if (argv[optind]) {
-- 
1.5.4.1

--
To unsubscribe from this list: send the line "unsubscribe util-linux-ng" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html

[Index of Archives]     [Netdev]     [Ethernet Bridging]     [Linux Wireless]     [Kernel Newbies]     [Security]     [Linux for Hams]     [Netfilter]     [Bugtraq]     [Yosemite News]     [MIPS Linux]     [ARM Linux]     [Linux RAID]     [Linux Admin]     [Samba]

  Powered by Linux