wok diff busybox/stuff/busybox-1.12.0-ionice.u @ rev 5684

Up busybox (1.16.1)
author Pascal Bellard <pascal.bellard@slitaz.org>
date Fri Jun 04 17:00:07 2010 +0200 (2010-06-04)
parents
children
line diff
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/busybox/stuff/busybox-1.12.0-ionice.u	Fri Jun 04 17:00:07 2010 +0200
     1.3 @@ -0,0 +1,163 @@
     1.4 +--- busybox-1.12.0/include/applets.h	2008-12-16 22:32:03.000000000 +0100
     1.5 ++++ busybox-1.12.0/include/applets.h	2008-12-16 22:34:06.000000000 +0100
     1.6 +@@ -191,6 +191,7 @@
     1.7 + USE_INSMOD(APPLET(insmod, _BB_DIR_SBIN, _BB_SUID_NEVER))
     1.8 + USE_MODPROBE_SMALL(APPLET_ODDNAME(insmod, modprobe, _BB_DIR_SBIN, _BB_SUID_NEVER, modprobe))
     1.9 + USE_INSTALL(APPLET(install, _BB_DIR_USR_BIN, _BB_SUID_NEVER))
    1.10 ++USE_IONICE(APPLET(ionice, _BB_DIR_BIN, _BB_SUID_NEVER))
    1.11 + #if ENABLE_FEATURE_IP_ADDRESS \
    1.12 +  || ENABLE_FEATURE_IP_ROUTE \
    1.13 +  || ENABLE_FEATURE_IP_LINK \
    1.14 +
    1.15 +
    1.16 +--- busybox-1.12.0/miscutils/Config.in	2008-12-14 23:41:16.000000000 +0100
    1.17 ++++ busybox-1.12.0/miscutils/Config.in	2008-12-14 23:27:56.000000000 +0100
    1.18 +@@ -223,6 +223,13 @@
    1.19 + 	    "NN" (ASCII decimal number) - percentage to show on progress bar
    1.20 + 	    "exit" - well you guessed it
    1.21 + 
    1.22 ++config IONICE
    1.23 ++	bool "ionice"
    1.24 ++	default n
    1.25 ++	help
    1.26 ++	  get/set program io scheduling class and priority
    1.27 ++	  Requires kernel >= 2.6.13
    1.28 ++
    1.29 + config INOTIFYD
    1.30 + 	bool "inotifyd"
    1.31 + 	default n
    1.32 +
    1.33 +--- busybox-1.12.0/miscutils/Kbuild	2008-12-14 23:22:52.000000000 +0100
    1.34 ++++ busybox-1.12.0/miscutils/Kbuild	2008-12-14 23:22:27.000000000 +0100
    1.35 +@@ -16,4 +16,5 @@
    1.36 + lib-$(CONFIG_EJECT)       += eject.o
    1.37 + lib-$(CONFIG_FBSPLASH)    += fbsplash.o
    1.38 ++lib-$(CONFIG_IONICE)      += ionice.o
    1.39 + lib-$(CONFIG_HDPARM)      += hdparm.o
    1.40 + lib-$(CONFIG_INOTIFYD)    += inotifyd.o
    1.41 +
    1.42 +--- busybox-1.12.0/include/usage.h	2008-12-16 22:31:43.000000000 +0100
    1.43 ++++ busybox-1.12.0/include/usage.h	2008-12-16 22:32:14.000000000 +0100
    1.44 +@@ -1884,6 +1884,16 @@
    1.45 + 	USE_SELINUX( \
    1.46 +      "\n	-Z	Set security context of copy" \
    1.47 + 	)
    1.48 ++	
    1.49 ++#define ionice_trivial_usage \
    1.50 ++	"[-c 1-3] [-n 0-7] [-p PID] [COMMAND [ARG...]]"
    1.51 ++#define ionice_full_usage "\n\n" \
    1.52 ++       "change io scheduling class and priority\n" \
    1.53 ++     "\nOptions:" \
    1.54 ++     "\n	-c  scheduling class. 1=real time 2=best-effort, 3=idle" \
    1.55 ++     "\n	-n  Priority " \
    1.56 ++     "\n	-p   process pid " 
    1.57 ++
    1.58 + 
    1.59 + /* would need to make the " | " optional depending on more than one selected: */
    1.60 + #define ip_trivial_usage \
    1.61 +
    1.62 +diff --git busybox-1.12.0/miscutils/ionice.c busybox-1.12.0/miscutils/ionice.c
    1.63 +new file mode 100644
    1.64 +index 0000000..88d771c
    1.65 +--- busybox-1.12.0/dev/null
    1.66 ++++ busybox-1.12.0/miscutils/ionice.c
    1.67 +@@ -0,0 +1,99 @@
    1.68 ++/* vi: set sw=4 ts=4: */
    1.69 ++/*
    1.70 ++ * ionice implementation for busybox based on linux-utils-ng 2.14
    1.71 ++ *
    1.72 ++ * Copyright (C) 2008 by <u173034@informatik.uni-oldenburg.de>
    1.73 ++ *
    1.74 ++ * Licensed under GPLv2 or later, see file LICENSE in this tarball for details.
    1.75 ++ */
    1.76 ++
    1.77 ++#include <sys/syscall.h>
    1.78 ++#include <asm/unistd.h>
    1.79 ++#include "libbb.h"
    1.80 ++
    1.81 ++static int ioprio_set(int which, int who, int ioprio)
    1.82 ++{
    1.83 ++ return syscall(SYS_ioprio_set, which, who, ioprio);
    1.84 ++}
    1.85 ++
    1.86 ++static int ioprio_get(int which, int who)
    1.87 ++{
    1.88 ++ return syscall(SYS_ioprio_get, which, who);
    1.89 ++}
    1.90 ++
    1.91 ++enum {
    1.92 ++ IOPRIO_WHO_PROCESS = 1,
    1.93 ++ IOPRIO_WHO_PGRP,
    1.94 ++ IOPRIO_WHO_USER
    1.95 ++};
    1.96 ++
    1.97 ++enum {
    1.98 ++ IOPRIO_CLASS_NONE,
    1.99 ++ IOPRIO_CLASS_RT,
   1.100 ++ IOPRIO_CLASS_BE,
   1.101 ++ IOPRIO_CLASS_IDLE
   1.102 ++};
   1.103 ++
   1.104 ++static const char to_prio[] = "none\0realtime\0best-effort\0idle";
   1.105 ++
   1.106 ++#define IOPRIO_CLASS_SHIFT 13
   1.107 ++
   1.108 ++int ionice_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
   1.109 ++int ionice_main(int argc UNUSED_PARAM, char **argv)
   1.110 ++{
   1.111 ++ /* Defaults */
   1.112 ++ int ioclass = 0;
   1.113 ++ int pri = 0;
   1.114 ++ int pid = 0; /* affect own porcess */
   1.115 ++ int opt;
   1.116 ++ enum {
   1.117 ++ OPT_n = 1,
   1.118 ++ OPT_c = 2,
   1.119 ++ OPT_p = 4,
   1.120 ++ };
   1.121 ++
   1.122 ++ /* Numeric params */
   1.123 ++ opt_complementary = "n+:c+:p+";
   1.124 ++ /* '+': stop at first non-option */
   1.125 ++ opt = getopt32(argv, "+n:c:p:", &pri, &ioclass, &pid);
   1.126 ++ argv += optind;
   1.127 ++
   1.128 ++ if (opt & OPT_c) {
   1.129 ++ if (ioclass > 3)
   1.130 ++ bb_error_msg_and_die("bad class %d", ioclass);
   1.131 ++// Do we need this (compat?)?
   1.132 ++// if (ioclass == IOPRIO_CLASS_NONE)
   1.133 ++// ioclass = IOPRIO_CLASS_BE;
   1.134 ++// if (ioclass == IOPRIO_CLASS_IDLE) {
   1.135 ++// //if (opt & OPT_n)
   1.136 ++// // bb_error_msg("ignoring priority for idle class");
   1.137 ++// pri = 7;
   1.138 ++// }
   1.139 ++ }
   1.140 ++
   1.141 ++ if (!(opt & (OPT_n|OPT_c))) {
   1.142 ++ if (!(opt & OPT_p) && *argv)
   1.143 ++ pid = xatoi_u(*argv);
   1.144 ++
   1.145 ++ pri = ioprio_get(IOPRIO_WHO_PROCESS, pid);
   1.146 ++ if (pri == -1)
   1.147 ++ bb_perror_msg_and_die("ioprio_%cet", 'g');
   1.148 ++
   1.149 ++ ioclass = (pri >> IOPRIO_CLASS_SHIFT) & 0x3;
   1.150 ++ pri &= 0xff;
   1.151 ++ printf((ioclass == IOPRIO_CLASS_IDLE) ? "%s\n" : "%s: prio %d\n",
   1.152 ++ nth_string(to_prio, ioclass), pri);
   1.153 ++ } else {
   1.154 ++//printf("pri=%d class=%d val=%x\n",
   1.155 ++//pri, ioclass, pri | (ioclass << IOPRIO_CLASS_SHIFT));
   1.156 ++ pri |= (ioclass << IOPRIO_CLASS_SHIFT);
   1.157 ++ if (ioprio_set(IOPRIO_WHO_PROCESS, pid, pri) == -1)
   1.158 ++ bb_perror_msg_and_die("ioprio_%cet", 's');
   1.159 ++ if (*argv) {
   1.160 ++ BB_EXECVP(*argv, argv);
   1.161 ++ bb_simple_perror_msg_and_die(*argv);
   1.162 ++ }
   1.163 ++ }
   1.164 ++
   1.165 ++ return EXIT_SUCCESS;
   1.166 ++}