File iotop-pid_alignment.patch of Package iotop

From 08211d209ae8fc7e67ea3bebb09979ff61c70f97 Mon Sep 17 00:00:00 2001
From: Guillaume Chazarain <guichaz@gmail.com>
Date: Sat, 4 Sep 2010 13:57:43 +0200
Subject: [PATCH] Instead of assuming the pid field is 4 bytes long, take its length from the header.
 This is needed for http://lkml.org/lkml/2010/2/12/167
 [PATCH] delayacct: align to 8 byte boundary on 64-bit systems

---
 THANKS        |    3 +++
 iotop/data.py |   16 ++++++++++++----
 2 files changed, 15 insertions(+), 4 deletions(-)

diff --git a/THANKS b/THANKS
index 1fc5450..4203fda 100644
--- a/THANKS
+++ b/THANKS
@@ -30,3 +30,6 @@ Gabriel Redner <gredner@gmail.com>
 
 Jiri Olsa <jolsa@redhat.com>
     Wrote the support for python2.4 with the ctypes module.
+
+Philipp Thomas <pth@suse.de>
+    Reported that iotop produced wrong numbers in openSUSE 11.3.
diff --git a/iotop/data.py b/iotop/data.py
index 5fb4acb..4f2da4b 100644
--- a/iotop/data.py
+++ b/iotop/data.py
@@ -134,6 +134,8 @@ class Stats(DumpableObject):
 
 TASKSTATS_CMD_GET = 1
 TASKSTATS_CMD_ATTR_PID = 1
+TASKSTATS_TYPE_AGGR_PID = 4
+TASKSTATS_TYPE_PID = 1
 
 class TaskStatsNetlink(object):
     # Keep in sync with format_stats() and pinfo.did_some_io()
@@ -164,11 +166,17 @@ class TaskStatsNetlink(object):
         reply_data = reply.payload[20:]
 
         reply_length, reply_type = struct.unpack('HH', reply.payload[4:8])
-        reply_version = struct.unpack('H', reply.payload[20:22])[0]
         assert reply_length >= 288
-        assert reply_type == TASKSTATS_CMD_ATTR_PID + 3
-        assert reply_version >= 4
-        return Stats(reply_data)
+        assert reply_type == TASKSTATS_TYPE_AGGR_PID
+
+        pid_length, pid_type = struct.unpack('HH', reply.payload[8:12])
+        assert pid_type == TASKSTATS_TYPE_PID
+
+        taskstats_start = 4 + 4 + pid_length + 4
+        taskstats_data = reply.payload[taskstats_start:]
+        taskstats_version = struct.unpack('H', taskstats_data[:2])[0]
+        assert taskstats_version >= 4
+        return Stats(taskstats_data)
 
 #
 # PIDs manipulations
-- 
1.6.5.GIT