[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Xen-devel] [PATCH 2/2] xl: support "xl list <domain>"



xm list takes an optional domain argument; make xl list do likewise.
This also gets rid of a small amount of code which was duplicated
between list_domains and list_domains_details.

Signed-off-by: Ian Jackson <Ian.Jackson@xxxxxxxxxxxxx>
---
 tools/libxl/xl_cmdimpl.c |   56 ++++++++++++++++++++++++++++------------------
 1 files changed, 34 insertions(+), 22 deletions(-)

diff --git a/tools/libxl/xl_cmdimpl.c b/tools/libxl/xl_cmdimpl.c
index 6a1ae0a..1fc9c14 100644
--- a/tools/libxl/xl_cmdimpl.c
+++ b/tools/libxl/xl_cmdimpl.c
@@ -2094,22 +2094,15 @@ void reboot_domain(char *p)
     if (rc) { fprintf(stderr,"reboot failed (rc=%d)\n.",rc);exit(-1); }
 }
 
-void list_domains_details(void)
+void list_domains_details(const libxl_dominfo *info, int nb_domain)
 {
-    libxl_dominfo *info;
     struct domain_config d_config;
 
     char *config_file;
     uint8_t *data;
-    int nb_domain, i, len, rc;
+    int i, len, rc;
     libxl_device_model_info dm_info;
 
-    info = libxl_list_domain(&ctx, &nb_domain);
-
-    if (!info) {
-        fprintf(stderr, "libxl_domain_infolist failed.\n");
-        exit(1);
-    }
     for (i = 0; i < nb_domain; i++) {
         rc = libxl_userdata_retrieve(&ctx, info[i].domid, "xl", &data, &len);
         if (rc)
@@ -2121,20 +2114,12 @@ void list_domains_details(void)
         free(data);
         free(config_file);
     }
-    free(info);
 }
 
-void list_domains(int verbose)
+void list_domains(int verbose, const libxl_dominfo *info, int nb_domain)
 {
-    libxl_dominfo *info;
-    int nb_domain, i;
-
-    info = libxl_list_domain(&ctx, &nb_domain);
+    int i;
 
-    if (!info) {
-        fprintf(stderr, "libxl_domain_infolist failed.\n");
-        exit(1);
-    }
     printf("Name                                        ID   Mem 
VCPUs\tState\tTime(s)\n");
     for (i = 0; i < nb_domain; i++) {
         printf("%-40s %5d %5lu %5d     %c%c%c%c%c%c  %8.1f",
@@ -2155,7 +2140,6 @@ void list_domains(int verbose)
         }
         putchar('\n');
     }
-    free(info);
 }
 
 void list_vm(void)
@@ -2960,6 +2944,10 @@ int main_list(int argc, char **argv)
         {0, 0, 0, 0}
     };
 
+    libxl_dominfo info_buf;
+    libxl_dominfo *info, *info_free=0;
+    int nb_domain, rc;
+
     while (1) {
         opt = getopt_long(argc, argv, "lvh", long_options, &option_index);
         if (opt == -1)
@@ -2981,10 +2969,34 @@ int main_list(int argc, char **argv)
         }
     }
 
+    if (optind >= argc) {
+        info = libxl_list_domain(&ctx, &nb_domain);
+        if (!info) {
+            fprintf(stderr, "libxl_domain_infolist failed.\n");
+            exit(1);
+        }
+        info_free = info;
+    } else if (optind == argc-1) {
+        find_domain(argv[optind]);
+        rc = libxl_domain_info(&ctx, &info_buf, domid);
+        if (rc) {
+            fprintf(stderr, "libxl_domain_info failed (code %d).\n", rc);
+            exit(-rc);
+        }
+        info = &info_buf;
+        nb_domain = 1;
+    } else {
+        help("list");
+        exit(2);
+    }
+
     if (details)
-        list_domains_details();
+        list_domains_details(info, nb_domain);
     else
-        list_domains(verbose);
+        list_domains(verbose, info, nb_domain);
+
+    free(info_free);
+
     exit(0);
 }
 
-- 
1.5.6.5


_______________________________________________
Xen-devel mailing list
Xen-devel@xxxxxxxxxxxxxxxxxxx
http://lists.xensource.com/xen-devel


 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.