]> git.karo-electronics.de Git - karo-tx-linux.git/commitdiff
kvm tools: Beautify kvm list output
authorOsier Yang <jyang@redhat.com>
Wed, 26 Oct 2011 06:02:11 +0000 (14:02 +0800)
committerPekka Enberg <penberg@kernel.org>
Thu, 27 Oct 2011 07:19:02 +0000 (10:19 +0300)
With the patch, output of "kvm list" will be:

% ./kvm list
   PID NAME                 STATE
------------------------------------
 5270 test                 running
      test                 shut off
      default              shut off

"not running" is changed into "shut off", as it might
be other states which are "not running" in future? such
as "paused".

Signed-off-by: Osier Yang <jyang@redhat.com>
Signed-off-by: Pekka Enberg <penberg@kernel.org>
tools/kvm/builtin-list.c

index 2ff347275706490a010252775cd932c1666ebd8d..4cabd599c48f08b1d4d35cda83cb288632ea49d5 100644 (file)
@@ -33,6 +33,9 @@ static const struct option list_options[] = {
        OPT_END()
 };
 
+#define KVM_INSTANCE_RUNNING   "running"
+#define KVM_INSTANCE_SHUTOFF   "shut off"
+
 void kvm_list_help(void)
 {
        usage_with_options(list_usage, list_options);
@@ -71,7 +74,7 @@ static int print_guest(const char *name, int sock)
        if (strncmp(comm, PROCESS_NAME, strlen(PROCESS_NAME)))
                goto cleanup;
 
-       printf("%5d %s\n", pid, name);
+       printf("%5d %-20s %s\n", pid, name, KVM_INSTANCE_RUNNING);
 
        free(comm);
 
@@ -109,7 +112,7 @@ static int kvm_list_rootfs(void)
                if (dirent->d_type == DT_DIR &&
                        strcmp(dirent->d_name, ".") &&
                        strcmp(dirent->d_name, ".."))
-                       printf("      %s (not running)\n", dirent->d_name);
+                       printf("%5s %-20s %s\n", "", dirent->d_name, KVM_INSTANCE_SHUTOFF);
        }
 
        return 0;
@@ -134,7 +137,8 @@ int kvm_cmd_list(int argc, const char **argv, const char *prefix)
        if (!run && !rootfs)
                run = rootfs = true;
 
-       printf("  PID GUEST\n");
+       printf("%6s %-20s %s\n", "PID", "NAME", "STATE");
+       printf("------------------------------------\n");
 
        if (run) {
                r = kvm_list_running_instances();