debuggers.hg

changeset 21188:cd05b6aa8c0a

xl, libxl: xl list -v shows the uuid too

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>
author Keir Fraser <keir.fraser@citrix.com>
date Mon Apr 12 17:42:57 2010 +0100 (2010-04-12)
parents e226618aa715
children fd0fd3612eb8
files tools/libxl/libxl.c tools/libxl/libxl.h tools/libxl/libxl_dom.c tools/libxl/xl.c
line diff
     1.1 --- a/tools/libxl/libxl.c	Mon Apr 12 17:42:29 2010 +0100
     1.2 +++ b/tools/libxl/libxl.c	Mon Apr 12 17:42:57 2010 +0100
     1.3 @@ -93,11 +93,8 @@ int libxl_domain_make(struct libxl_ctx *
     1.4      xs_transaction_t t;
     1.5      xen_domain_handle_t handle;
     1.6  
     1.7 -    uuid_string = string_of_uuid(ctx, info->uuid);
     1.8 -    if (!uuid_string) {
     1.9 -        XL_LOG(ctx, XL_LOG_ERROR, "cannot allocate uuid string");
    1.10 -        return ERROR_FAIL;
    1.11 -    }
    1.12 +    uuid_string = libxl_uuid2string(ctx, info->uuid);
    1.13 +    if (!uuid_string) return ERROR_NOMEM;
    1.14  
    1.15      flags = info->hvm ? XEN_DOMCTL_CDF_hvm_guest : 0;
    1.16      flags |= info->hap ? XEN_DOMCTL_CDF_hap : 0;
     2.1 --- a/tools/libxl/libxl.h	Mon Apr 12 17:42:29 2010 +0100
     2.2 +++ b/tools/libxl/libxl.h	Mon Apr 12 17:42:57 2010 +0100
     2.3 @@ -264,6 +264,9 @@ int libxl_domain_resume(struct libxl_ctx
     2.4  int libxl_domain_shutdown(struct libxl_ctx *ctx, uint32_t domid, int req);
     2.5  int libxl_domain_destroy(struct libxl_ctx *ctx, uint32_t domid, int force);
     2.6  
     2.7 +char *libxl_uuid2string(struct libxl_ctx *ctx, uint8_t uuid[16]);
     2.8 +  /* 0 means ERROR_ENOMEM, which we have logged */
     2.9 +
    2.10  /* events handling */
    2.11  
    2.12  typedef enum {
     3.1 --- a/tools/libxl/libxl_dom.c	Mon Apr 12 17:42:29 2010 +0100
     3.2 +++ b/tools/libxl/libxl_dom.c	Mon Apr 12 17:42:57 2010 +0100
     3.3 @@ -350,3 +350,9 @@ int save_device_model(struct libxl_ctx *
     3.4      unlink(filename);
     3.5      return 0;
     3.6  }
     3.7 +
     3.8 +char *libxl_uuid2string(struct libxl_ctx *ctx, uint8_t uuid[16]) {
     3.9 +    char *s = string_of_uuid(ctx, uuid);
    3.10 +    if (!s) XL_LOG(ctx, XL_LOG_ERROR, "cannot allocate for uuid");
    3.11 +    return s;
    3.12 +}
     4.1 --- a/tools/libxl/xl.c	Mon Apr 12 17:42:29 2010 +0100
     4.2 +++ b/tools/libxl/xl.c	Mon Apr 12 17:42:57 2010 +0100
     4.3 @@ -891,7 +891,7 @@ static void help(char *command)
     4.4          printf("-d                     Enable debug messages.\n");
     4.5          printf("-e                     Do not wait in the background for the death of the domain.\n");
     4.6      } else if(!strcmp(command, "list")) {
     4.7 -        printf("Usage: xl list [Domain]\n\n");
     4.8 +        printf("Usage: xl list [-v] [Domain]\n\n");
     4.9          printf("List information about all/some domains.\n\n");
    4.10      } else if(!strcmp(command, "pci-attach")) {
    4.11          printf("Usage: xl pci-attach <Domain> <BDF> [Virtual Slot]\n\n");
    4.12 @@ -1368,7 +1368,7 @@ void destroy_domain(char *p)
    4.13      libxl_domain_destroy(&ctx, domid, 0);
    4.14  }
    4.15  
    4.16 -void list_domains(void)
    4.17 +void list_domains(int verbose)
    4.18  {
    4.19      struct libxl_ctx ctx;
    4.20      struct libxl_dominfo *info;
    4.21 @@ -1388,7 +1388,7 @@ void list_domains(void)
    4.22      }
    4.23      printf("Name                                        ID   Mem VCPUs\tState\tTime(s)\n");
    4.24      for (i = 0; i < nb_domain; i++) {
    4.25 -        printf("%-40s %5d %5lu %5d        %c%c%c %8.1f\n",
    4.26 +        printf("%-40s %5d %5lu %5d        %c%c%c %8.1f",
    4.27                  libxl_domid_to_name(&ctx, info[i].domid),
    4.28                  info[i].domid,
    4.29                  (unsigned long) (info[i].max_memkb / 1024),
    4.30 @@ -1397,6 +1397,11 @@ void list_domains(void)
    4.31                  info[i].paused ? 'p' : '-',
    4.32                  info[i].dying ? 'd' : '-',
    4.33                  ((float)info[i].cpu_time / 1e9));
    4.34 +        if (verbose) {
    4.35 +            char *uuid = libxl_uuid2string(&ctx, info[i].uuid);
    4.36 +            printf(" %s", uuid);
    4.37 +        }
    4.38 +        putchar('\n');
    4.39      }
    4.40      free(info);
    4.41  }
    4.42 @@ -1614,20 +1619,23 @@ int main_destroy(int argc, char **argv)
    4.43  
    4.44  int main_list(int argc, char **argv)
    4.45  {
    4.46 -    int opt;
    4.47 +    int opt, verbose = 0;
    4.48  
    4.49 -    while ((opt = getopt(argc, argv, "h")) != -1) {
    4.50 +    while ((opt = getopt(argc, argv, "hv")) != -1) {
    4.51          switch (opt) {
    4.52          case 'h':
    4.53              help("list");
    4.54              exit(0);
    4.55 +        case 'v':
    4.56 +            verbose = 1;
    4.57 +            break;
    4.58          default:
    4.59              fprintf(stderr, "option not supported\n");
    4.60              break;
    4.61          }
    4.62      }
    4.63  
    4.64 -    list_domains();
    4.65 +    list_domains(verbose);
    4.66      exit(0);
    4.67  }
    4.68