Bug #206773 - Add a new PORTAGE_IONICE_COMMAND variable that emerge uses
authorZac Medico <zmedico@gentoo.org>
Thu, 24 Jul 2008 14:43:37 +0000 (14:43 -0000)
committerZac Medico <zmedico@gentoo.org>
Thu, 24 Jul 2008 14:43:37 +0000 (14:43 -0000)
to adjust ionice priority, similar to PORTAGE_NICENESS but used more like
FETCHCOMMAND since so that portage doesn't have to know anything about
ionice options. The command should include a \${PID} place-holder to be
substituted with an integer pid.

svn path=/main/trunk/; revision=11182

cnf/make.globals
man/make.conf.5
pym/_emerge/__init__.py
pym/portage/__init__.py

index 594278f19c85478aacc7e2e4948ad587c3bd66c5..0b29536fe2194bbcd56409e6eee2675d150944c6 100644 (file)
@@ -62,6 +62,9 @@ PORTAGE_FETCH_CHECKSUM_TRY_MIRRORS="5"
 # Minimum size of existing file for RESUMECOMMAND to be called.
 PORTAGE_FETCH_RESUME_MIN_SIZE="350K"
 
+# Command called to adjust the io priority of portage and it's subprocesses.
+PORTAGE_IONICE_COMMAND="ionice -c 2 -n 7 -p \${PID}"
+
 # Number of times 'emerge --sync' will run before giving up.
 PORTAGE_RSYNC_RETRIES="3"
 
index b3dc3c49d5dd2d8072760edb5d9cc54b7498cedc..36db9d5365887e0f38ea1368fdac8aa3643b9424 100644 (file)
@@ -459,6 +459,14 @@ that small garbage files such as html 404 pages are properly discarded. The
 variable should contain an integer number of bytes and may have a suffix such
 as K, M, or G.
 .TP
+\fBPORTAGE_IONICE_COMMAND\fR = \fI[ionice command string]\fR
+This variable should contain a command for portage to call in order
+to adjust the io priority of portage and it's subprocesses. The command
+string should contain a \\${PID} place-holder that will be substituted
+with an integer pid. For more information about ionice, see \fBionice\fR(1).
+.br
+Defaults to "ionice -c 2 -n 7 -p \\${PID}".
+.TP
 \fBPORTAGE_NICENESS\fR = \fI[number]\fR
 The value of this variable will be added to the current nice level that
 emerge is running at.  In other words, this will not set the nice level,
index 50462940d6e7912ed7409c283f7dbac73ad8c30c..6c25bafd3e67e2a4701ed12d22fa837edf9e2f0f 100644 (file)
@@ -12846,6 +12846,29 @@ def adjust_config(myopts, settings):
                settings["NOCOLOR"] = "true"
                settings.backup_changes("NOCOLOR")
 
+def ionice(settings):
+
+       ionice_cmd = settings.get("PORTAGE_IONICE_COMMAND")
+       if ionice_cmd:
+               ionice_cmd = shlex.split(ionice_cmd)
+       if not ionice_cmd:
+               return
+
+       from portage.util import varexpand
+       variables = {"PID" : str(os.getpid())}
+       cmd = [varexpand(x, mydict=variables) for x in ionice_cmd]
+
+       try:
+               rval = portage.process.spawn(cmd, env=os.environ)
+       except portage.exception.CommandNotFound:
+               # The OS kernel probably doesn't support ionice,
+               # so return silently.
+               return
+
+       if rval != os.EX_OK:
+               out = portage.output.EOutput()
+               out.eerror("PORTAGE_IONICE_COMMAND returned %d" % (rval,))
+
 def emerge_main():
        global portage  # NFC why this is necessary now - genone
        portage._disable_legacy_globals()
@@ -12867,6 +12890,8 @@ def emerge_main():
        settings, trees, mtimedb = load_emerge_config()
        portdb = trees[settings["ROOT"]]["porttree"].dbapi
 
+       ionice(settings)
+
        try:
                os.nice(int(settings.get("PORTAGE_NICENESS", "0")))
        except (OSError, ValueError), e:
index 66e3377acaea4493112b26d5e59aec18bdb74eba..e4fe13eede18401825a22ff7ecd26d55f6e45c13 100644 (file)
@@ -996,7 +996,8 @@ class config(object):
                "PORTAGE_ELOG_MAILURI", "PORTAGE_ELOG_SYSTEM",
                "PORTAGE_FETCH_CHECKSUM_TRY_MIRRORS", "PORTAGE_FETCH_RESUME_MIN_SIZE",
                "PORTAGE_GPG_DIR",
-               "PORTAGE_GPG_KEY", "PORTAGE_PACKAGE_EMPTY_ABORT",
+               "PORTAGE_GPG_KEY", "PORTAGE_IONICE_COMMAND",
+               "PORTAGE_PACKAGE_EMPTY_ABORT",
                "PORTAGE_RO_DISTDIRS",
                "PORTAGE_RSYNC_EXTRA_OPTS", "PORTAGE_RSYNC_OPTS",
                "PORTAGE_RSYNC_RETRIES", "PORTAGE_USE", "PORT_LOGDIR",