--- /usr/bin/emerge 2008-05-03 21:49:13.000000000 +0200 +++ /usr/bin/emerge 2008-05-03 21:48:03.000000000 +0200 @@ -6617,6 +6617,34 @@ settings["NOCOLOR"] = "true" settings.backup_changes("NOCOLOR") +def ionice(io_class, io_prio, pid = -1): + """Execute the program ionice to adapt io performance""" + + # Only the root user can use ionice + if os.getuid() != 0: + return False # Failed not root + + # Determine the process id to change + if pid == -1: + npid = os.getpid() + else: + npid = pid + + # Search ionice executable in PATH + ionice_bin = None + for path in os.environ["PATH"].split(":"): + file = os.path.join(path, "ionice") + if os.path.exists(file): + ionice_bin = file + break + if ionice_bin is None: + return False # Failed binary not installed + + # Execute the ionice program + rv = os.system("%s -c%d -n%d -p%d >/dev/null 2>&1" % \ + (ionice_bin, io_class, io_prio, npid)) + return rv == 0 + def emerge_main(): # Disable color until we're sure that it should be enabled (after # EMERGE_DEFAULT_OPTS has been parsed). @@ -6636,6 +6664,23 @@ settings, trees, mtimedb = load_emerge_config() portdb = trees[settings["ROOT"]]["porttree"].dbapi + # Use ionice to amend the performance or responsivness of the system + io_class_dict = {"realtime":1, "besteffort":2, "idle":3, "1":1, "2":2, "3":3, "none":-1} + try: + io_class = io_class_dict[settings.get("PORTAGE_IONICE_CLASS", "none")] + io_prio = int(settings.get("PORTAGE_IONICE_PRIO", "4")) + if io_prio < 0: raise ValueError + if io_prio > 7: raise ValueError + except (KeyError, ValueError), e: + portage.writemsg("!!! Invalid value in PORTAGE_IONICE_CLASS or PORTAGE_IONICE_PRIO\n") + portage.writemsg("!!! PORTAGE_IONICE_CLASS=\n") + portage.writemsg("!!! PORTAGE_IONICE_PRIO=<0..7>\n") + io_class = -1 + io_prio = -1 + del e + if io_class != -1 and io_prio != -1: + ionice(io_class, io_prio) + try: os.nice(int(settings.get("PORTAGE_NICENESS", "0"))) except (OSError, ValueError), e: