Use 'kvm list' to list running virtual guest. Signed-off-by: Sasha Levin <levinsasha928@xxxxxxxxx> --- 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 <kvm/util.h> +#include <kvm/kvm-cmd.h> +#include <kvm/kvm-list.h> +#include <kvm/kvm.h> + +#include <stdio.h> +#include <string.h> +#include <signal.h> + +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 -- To unsubscribe from this list: send the line "unsubscribe kvm" in the body of a message to majordomo@xxxxxxxxxxxxxxx More majordomo info at http://vger.kernel.org/majordomo-info.html