debuggers.hg

changeset 21943:84f8ad68bc58

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@eu.citrix.com>
Acked-by: Ian Campbell <ian.campbell@citrix.com>
Committed-by: Ian Jackson <ian.jackson@eu.citrix.com>
author Ian Jackson <Ian.Jackson@eu.citrix.com>
date Fri Jul 30 15:12:56 2010 +0100 (2010-07-30)
parents 64fa1a9c723c
children bb187c5a7fbc
files tools/libxl/xl_cmdimpl.c
line diff
     1.1 --- a/tools/libxl/xl_cmdimpl.c	Fri Jul 30 15:12:10 2010 +0100
     1.2 +++ b/tools/libxl/xl_cmdimpl.c	Fri Jul 30 15:12:56 2010 +0100
     1.3 @@ -2126,22 +2126,15 @@ void reboot_domain(char *p)
     1.4      if (rc) { fprintf(stderr,"reboot failed (rc=%d)\n.",rc);exit(-1); }
     1.5  }
     1.6  
     1.7 -void list_domains_details(void)
     1.8 +void list_domains_details(const libxl_dominfo *info, int nb_domain)
     1.9  {
    1.10 -    libxl_dominfo *info;
    1.11      struct domain_config d_config;
    1.12  
    1.13      char *config_file;
    1.14      uint8_t *data;
    1.15 -    int nb_domain, i, len, rc;
    1.16 +    int i, len, rc;
    1.17      libxl_device_model_info dm_info;
    1.18  
    1.19 -    info = libxl_list_domain(&ctx, &nb_domain);
    1.20 -
    1.21 -    if (!info) {
    1.22 -        fprintf(stderr, "libxl_domain_infolist failed.\n");
    1.23 -        exit(1);
    1.24 -    }
    1.25      for (i = 0; i < nb_domain; i++) {
    1.26          rc = libxl_userdata_retrieve(&ctx, info[i].domid, "xl", &data, &len);
    1.27          if (rc)
    1.28 @@ -2153,20 +2146,12 @@ void list_domains_details(void)
    1.29          free(data);
    1.30          free(config_file);
    1.31      }
    1.32 -    free(info);
    1.33  }
    1.34  
    1.35 -void list_domains(int verbose)
    1.36 +void list_domains(int verbose, const libxl_dominfo *info, int nb_domain)
    1.37  {
    1.38 -    libxl_dominfo *info;
    1.39 -    int nb_domain, i;
    1.40 -
    1.41 -    info = libxl_list_domain(&ctx, &nb_domain);
    1.42 -
    1.43 -    if (!info) {
    1.44 -        fprintf(stderr, "libxl_domain_infolist failed.\n");
    1.45 -        exit(1);
    1.46 -    }
    1.47 +    int i;
    1.48 +
    1.49      printf("Name                                        ID   Mem VCPUs\tState\tTime(s)\n");
    1.50      for (i = 0; i < nb_domain; i++) {
    1.51          printf("%-40s %5d %5lu %5d     %c%c%c%c%c%c  %8.1f",
    1.52 @@ -2187,7 +2172,6 @@ void list_domains(int verbose)
    1.53          }
    1.54          putchar('\n');
    1.55      }
    1.56 -    free(info);
    1.57  }
    1.58  
    1.59  void list_vm(void)
    1.60 @@ -2992,6 +2976,10 @@ int main_list(int argc, char **argv)
    1.61          {0, 0, 0, 0}
    1.62      };
    1.63  
    1.64 +    libxl_dominfo info_buf;
    1.65 +    libxl_dominfo *info, *info_free=0;
    1.66 +    int nb_domain, rc;
    1.67 +
    1.68      while (1) {
    1.69          opt = getopt_long(argc, argv, "lvh", long_options, &option_index);
    1.70          if (opt == -1)
    1.71 @@ -3013,10 +3001,34 @@ int main_list(int argc, char **argv)
    1.72          }
    1.73      }
    1.74  
    1.75 +    if (optind >= argc) {
    1.76 +        info = libxl_list_domain(&ctx, &nb_domain);
    1.77 +        if (!info) {
    1.78 +            fprintf(stderr, "libxl_domain_infolist failed.\n");
    1.79 +            exit(1);
    1.80 +        }
    1.81 +        info_free = info;
    1.82 +    } else if (optind == argc-1) {
    1.83 +        find_domain(argv[optind]);
    1.84 +        rc = libxl_domain_info(&ctx, &info_buf, domid);
    1.85 +        if (rc) {
    1.86 +            fprintf(stderr, "libxl_domain_info failed (code %d).\n", rc);
    1.87 +            exit(-rc);
    1.88 +        }
    1.89 +        info = &info_buf;
    1.90 +        nb_domain = 1;
    1.91 +    } else {
    1.92 +        help("list");
    1.93 +        exit(2);
    1.94 +    }
    1.95 +
    1.96      if (details)
    1.97 -        list_domains_details();
    1.98 +        list_domains_details(info, nb_domain);
    1.99      else
   1.100 -        list_domains(verbose);
   1.101 +        list_domains(verbose, info, nb_domain);
   1.102 +
   1.103 +    free(info_free);
   1.104 +
   1.105      exit(0);
   1.106  }
   1.107