From e69d89c1c07ea7b79160a37c36b7cc02dd5eecbd Mon Sep 17 00:00:00 2001 From: "Richard W.M. Jones" Date: Thu, 1 Jan 1970 00:00:00 +0000 Subject: [PATCH] Print swapper task details. --- ps/.depend | 6 ++++-- ps/virt_ps.ml | 37 +++++++++++++++++++++++++++++++++++-- 2 files changed, 39 insertions(+), 4 deletions(-) diff --git a/ps/.depend b/ps/.depend index 0614d06..11d70ae 100644 --- a/ps/.depend +++ b/ps/.depend @@ -1,4 +1,6 @@ virt_ps.cmo: ../lib/virt_mem_utils.cmo ../lib/virt_mem_types.cmi \ - ../lib/virt_mem_gettext.cmo ../lib/virt_mem.cmi + ../lib/virt_mem_mmap.cmi ../lib/virt_mem_gettext.cmo ../lib/virt_mem.cmi \ + ../lib/kernel_task_struct.cmi virt_ps.cmx: ../lib/virt_mem_utils.cmx ../lib/virt_mem_types.cmx \ - ../lib/virt_mem_gettext.cmx ../lib/virt_mem.cmx + ../lib/virt_mem_mmap.cmx ../lib/virt_mem_gettext.cmx ../lib/virt_mem.cmx \ + ../lib/kernel_task_struct.cmx diff --git a/ps/virt_ps.ml b/ps/virt_ps.ml index 41e8af7..7d8534c 100644 --- a/ps/virt_ps.ml +++ b/ps/virt_ps.ml @@ -24,9 +24,42 @@ open Virt_mem_utils open Virt_mem_types +let run debug ({ domname = domname; mem = mem }, ksymmap, utsname) = + try + let kernel_version = + match utsname with + | None -> + eprintf (f_"%s: could not guess kernel version\n") domname; + raise Exit + | Some { kernel_release = v } -> v in -let run debug ({ mem = mem }, ksymmap, _) = - () + if not (Kernel_task_struct.known kernel_version) then ( + eprintf (f_"%s: %s: unknown kernel version +Try a newer version of virt-mem, or if the guest is not from a +supported Linux distribution, see this page about adding support: + http://et.redhat.com/~rjones/virt-mem/faq.html\n") domname kernel_version; + raise Exit + ); + + let init_task = + let addr = + try Ksymmap.find "init_task" ksymmap + with Not_found -> + eprintf (f_"%s: could not find init_task in kernel image\n") domname; + raise Exit in + let addr = + (Virt_mem_mmap.unsafe_typed_addr_of_addr addr : + [ `task_struct ] Virt_mem_mmap.typed_addr) in + Kernel_task_struct.get kernel_version mem addr in + + printf "comm = %S prio = %Ld state = %Ld static_prio = %Ld tasks'next = %Lx\n" + init_task.Kernel_task_struct.comm + init_task.Kernel_task_struct.prio + init_task.Kernel_task_struct.state + init_task.Kernel_task_struct.static_prio + (Virt_mem_mmap.unsafe_addr_of_typed_addr init_task.Kernel_task_struct.tasks'next); + + with Exit -> () let summary = s_"list processes in virtual machine" let description = s_"\ -- 1.8.3.1