xl, libxl: xl list -v shows the uuid too
authorKeir Fraser <keir.fraser@citrix.com>
Mon, 12 Apr 2010 16:42:57 +0000 (17:42 +0100)
committerKeir Fraser <keir.fraser@citrix.com>
Mon, 12 Apr 2010 16:42:57 +0000 (17:42 +0100)
Break uuid to string conversion (including logging) out into a new
function libxl_uuid2string for reuse, and expose it for the
convenience of callers.

Provide a new -v option to xl list which shows the domain's uuid.

Signed-off-by: Ian Jackson <Ian.Jackson@eu.citrix.com>
tools/libxl/libxl.c
tools/libxl/libxl.h
tools/libxl/libxl_dom.c
tools/libxl/xl.c

index f96b3ae035192c3abfbf415f5f90863237edba8a..663cbc19cf3d021a8249a031cd6695b11efd025e 100644 (file)
@@ -93,11 +93,8 @@ int libxl_domain_make(struct libxl_ctx *ctx, libxl_domain_create_info *info,
     xs_transaction_t t;
     xen_domain_handle_t handle;
 
-    uuid_string = string_of_uuid(ctx, info->uuid);
-    if (!uuid_string) {
-        XL_LOG(ctx, XL_LOG_ERROR, "cannot allocate uuid string");
-        return ERROR_FAIL;
-    }
+    uuid_string = libxl_uuid2string(ctx, info->uuid);
+    if (!uuid_string) return ERROR_NOMEM;
 
     flags = info->hvm ? XEN_DOMCTL_CDF_hvm_guest : 0;
     flags |= info->hap ? XEN_DOMCTL_CDF_hap : 0;
index 02bdd219439e4e45acad2d34b044471d5f82bdbc..2ef8640010777d93f3248ff85ff35496672e59de 100644 (file)
@@ -264,6 +264,9 @@ int libxl_domain_resume(struct libxl_ctx *ctx, uint32_t domid);
 int libxl_domain_shutdown(struct libxl_ctx *ctx, uint32_t domid, int req);
 int libxl_domain_destroy(struct libxl_ctx *ctx, uint32_t domid, int force);
 
+char *libxl_uuid2string(struct libxl_ctx *ctx, uint8_t uuid[16]);
+  /* 0 means ERROR_ENOMEM, which we have logged */
+
 /* events handling */
 
 typedef enum {
index c2137929dda14e8bec30bbd7f6243c87351f4c02..57b800a204fa7d89856756ebabe8b0eecdb7dbdf 100644 (file)
@@ -350,3 +350,9 @@ int save_device_model(struct libxl_ctx *ctx, uint32_t domid, int fd)
     unlink(filename);
     return 0;
 }
+
+char *libxl_uuid2string(struct libxl_ctx *ctx, uint8_t uuid[16]) {
+    char *s = string_of_uuid(ctx, uuid);
+    if (!s) XL_LOG(ctx, XL_LOG_ERROR, "cannot allocate for uuid");
+    return s;
+}
index d99e6376e6575d6fc27c86ad08180d94ff2d2c59..41dada7d2af11262a11bb40407684fa58b173549 100644 (file)
@@ -891,7 +891,7 @@ static void help(char *command)
         printf("-d                     Enable debug messages.\n");
         printf("-e                     Do not wait in the background for the death of the domain.\n");
     } else if(!strcmp(command, "list")) {
-        printf("Usage: xl list [Domain]\n\n");
+        printf("Usage: xl list [-v] [Domain]\n\n");
         printf("List information about all/some domains.\n\n");
     } else if(!strcmp(command, "pci-attach")) {
         printf("Usage: xl pci-attach <Domain> <BDF> [Virtual Slot]\n\n");
@@ -1368,7 +1368,7 @@ void destroy_domain(char *p)
     libxl_domain_destroy(&ctx, domid, 0);
 }
 
-void list_domains(void)
+void list_domains(int verbose)
 {
     struct libxl_ctx ctx;
     struct libxl_dominfo *info;
@@ -1388,7 +1388,7 @@ void list_domains(void)
     }
     printf("Name                                        ID   Mem VCPUs\tState\tTime(s)\n");
     for (i = 0; i < nb_domain; i++) {
-        printf("%-40s %5d %5lu %5d        %c%c%c %8.1f\n",
+        printf("%-40s %5d %5lu %5d        %c%c%c %8.1f",
                 libxl_domid_to_name(&ctx, info[i].domid),
                 info[i].domid,
                 (unsigned long) (info[i].max_memkb / 1024),
@@ -1397,6 +1397,11 @@ void list_domains(void)
                 info[i].paused ? 'p' : '-',
                 info[i].dying ? 'd' : '-',
                 ((float)info[i].cpu_time / 1e9));
+        if (verbose) {
+            char *uuid = libxl_uuid2string(&ctx, info[i].uuid);
+            printf(" %s", uuid);
+        }
+        putchar('\n');
     }
     free(info);
 }
@@ -1614,20 +1619,23 @@ int main_destroy(int argc, char **argv)
 
 int main_list(int argc, char **argv)
 {
-    int opt;
+    int opt, verbose = 0;
 
-    while ((opt = getopt(argc, argv, "h")) != -1) {
+    while ((opt = getopt(argc, argv, "hv")) != -1) {
         switch (opt) {
         case 'h':
             help("list");
             exit(0);
+        case 'v':
+            verbose = 1;
+            break;
         default:
             fprintf(stderr, "option not supported\n");
             break;
         }
     }
 
-    list_domains();
+    list_domains(verbose);
     exit(0);
 }