From: Sasha Levin Subject: [PATCH 4/5] kvm tools: Add 'kvm list' command Date: Sun, 3 Jul 2011 18:38:09 +0300 Message-ID: <1309707490-14946-4-git-send-email-levinsasha928@gmail.com> References: <1309707490-14946-1-git-send-email-levinsasha928@gmail.com> Cc: mingo@elte.hu, asias.hejun@gmail.com, prasadjoshi124@gmail.com, gorcunov@gmail.com, kvm@vger.kernel.org, Sasha Levin To: penberg@kernel.org Return-path: Received: from mail-wy0-f174.google.com ([74.125.82.174]:33773 "EHLO mail-wy0-f174.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1755347Ab1GCPik (ORCPT ); Sun, 3 Jul 2011 11:38:40 -0400 Received: by wyg8 with SMTP id 8so2989616wyg.19 for ; Sun, 03 Jul 2011 08:38:39 -0700 (PDT) In-Reply-To: <1309707490-14946-1-git-send-email-levinsasha928@gmail.com> Sender: kvm-owner@vger.kernel.org List-ID: Use 'kvm list' to list running virtual guest. Signed-off-by: Sasha Levin --- tools/kvm/Makefile | 5 +++-- tools/kvm/include/kvm/kvm-list.h | 6 ++++++ tools/kvm/include/kvm/kvm.h | 1 + tools/kvm/kvm-cmd.c | 2 ++ tools/kvm/kvm-list.c | 20 ++++++++++++++++++++ 5 files changed, 32 insertions(+), 2 deletions(-) create mode 100644 tools/kvm/include/kvm/kvm-list.h create mode 100644 tools/kvm/kvm-list.c diff --git a/tools/kvm/Makefile b/tools/kvm/Makefile index 90ad708..51a3d1a 100644 --- a/tools/kvm/Makefile +++ b/tools/kvm/Makefile @@ -57,8 +57,9 @@ OBJS += uip/csum.o OBJS += kvm-cmd.o OBJS += kvm-debug.o OBJS += kvm-help.o -OBJS += kvm-pause.o -OBJS += kvm-balloon.o +OBJS += kvm-pause.o +OBJS += kvm-balloon.o +OBJS += kvm-list.o OBJS += kvm-run.o OBJS += mptable.o OBJS += rbtree.o diff --git a/tools/kvm/include/kvm/kvm-list.h b/tools/kvm/include/kvm/kvm-list.h new file mode 100644 index 0000000..eba9cfd --- /dev/null +++ b/tools/kvm/include/kvm/kvm-list.h @@ -0,0 +1,6 @@ +#ifndef KVM__LIST_H +#define KVM__LIST_H + +int kvm_cmd_list(int argc, const char **argv, const char *prefix); + +#endif diff --git a/tools/kvm/include/kvm/kvm.h b/tools/kvm/include/kvm/kvm.h index 1fdfcf7..da9e12c 100644 --- a/tools/kvm/include/kvm/kvm.h +++ b/tools/kvm/include/kvm/kvm.h @@ -67,6 +67,7 @@ void kvm__pause(void); void kvm__continue(void); void kvm__notify_paused(void); int kvm__get_pid_by_instance(const char *name); +int kvm__enumerate_instances(void (*callback)(const char *name, int pid)); /* * Debugging diff --git a/tools/kvm/kvm-cmd.c b/tools/kvm/kvm-cmd.c index 1598781..cecf0d0 100644 --- a/tools/kvm/kvm-cmd.c +++ b/tools/kvm/kvm-cmd.c @@ -8,6 +8,7 @@ #include "kvm/kvm-debug.h" #include "kvm/kvm-pause.h" #include "kvm/kvm-balloon.h" +#include "kvm/kvm-list.h" #include "kvm/kvm-help.h" #include "kvm/kvm-cmd.h" #include "kvm/kvm-run.h" @@ -16,6 +17,7 @@ struct cmd_struct kvm_commands[] = { { "pause", kvm_cmd_pause, NULL, 0 }, { "debug", kvm_cmd_debug, NULL, 0 }, { "balloon", kvm_cmd_balloon, NULL, 0 }, + { "list", kvm_cmd_list, NULL, 0 }, { "help", kvm_cmd_help, NULL, 0 }, { "run", kvm_cmd_run, kvm_run_help, 0 }, { NULL, NULL, NULL, 0 }, diff --git a/tools/kvm/kvm-list.c b/tools/kvm/kvm-list.c new file mode 100644 index 0000000..696c355 --- /dev/null +++ b/tools/kvm/kvm-list.c @@ -0,0 +1,20 @@ +#include +#include +#include +#include + +#include +#include +#include + +static void print_guest(const char *name, int pid) +{ + printf("%s (PID: %d)\n", name, pid); +} + +int kvm_cmd_list(int argc, const char **argv, const char *prefix) +{ + kvm__enumerate_instances(print_guest); + + return 0; +} -- 1.7.6