tuna: print an error message when sched_setaffinity returns EINVAL

When you attempt to move a thread that cannot be moved,
schedutils.sched_setaffinity() throws an EINVAL OSError exception. tuna
does not capture this, so the command exits with a Python traceback
instead of an error message.


tuna --cpus=0 --threads=migration/1 --move
Traceback (most recent call last):
  File "/bin/tuna", line 656, in <module>
  File "/bin/tuna", line 572, in main
    spread = spread)
  File "/usr/lib/python2.7/site-packages/tuna/tuna.py", line 265, in
    raise e
OSError: [Errno 22] Invalid argument

This change handles that situation and exits more gracefully with
an error message like this

tuna --cpus=0 --threads="migration/1" --move
thread 14 cannot be moved as requested

or with multiple threads

tuna --cpus=0 --threads="migration/*" --move
thread 28 cannot be moved as requested
thread 21 cannot be moved as requested
thread 14 cannot be moved as requested

Reported-by: Guy Streeter <streeter@redhat.com>
Signed-off-by: John Kacur <jkacur@redhat.com>
Signed-off-by: Jiri Kastner <jkastner@redhat.com>
diff --git a/tuna/tuna.py b/tuna/tuna.py
index 1de63b0..646b8df 100755
--- a/tuna/tuna.py
+++ b/tuna/tuna.py
@@ -271,6 +271,9 @@
 			if e[0] == 3:
 				# process died
+			elif e[0] == 22: # (22, EINVAL - unmovable thread)
+				print "thread %(pid)d cannot be moved as requested" %{'pid':pid}
+				continue
 			raise e
 	return changed