debuggers.hg

changeset 22088:477abe597f6d

libxl/xl: Use libxl_vcpuinfo_destroy

Replaces libxl_free_vcpu_list.

The ->cpumap field is now always a unique allocation rather than each
being an offset into the cpumap allocated in the first
libxl_device_pci in the list.

Refactor vcpulist so that the two cases can share more code.

[PATCH 15 of 16 of
libxl: autogenerate type definitions and destructor functions]

Signed-off-by: Ian Campbell <ian.campbell@citrix.com>
Signed-off-by: Ian Jackson <ian.jackson@eu.citrix.com>
author Ian Campbell <ian.campbell@citrix.com>
date Thu Aug 19 15:32:56 2010 +0100 (2010-08-19)
parents 4c9ef5ec9146
children 88f4d10e0508
files tools/libxl/libxl.c tools/libxl/libxl.h tools/libxl/xl_cmdimpl.c
line diff
     1.1 --- a/tools/libxl/libxl.c	Thu Aug 19 15:32:28 2010 +0100
     1.2 +++ b/tools/libxl/libxl.c	Thu Aug 19 15:32:56 2010 +0100
     1.3 @@ -2902,7 +2902,6 @@ libxl_vcpuinfo *libxl_list_vcpu(libxl_ct
     1.4      xc_domaininfo_t domaininfo;
     1.5      xc_vcpuinfo_t vcpuinfo;
     1.6      xc_physinfo_t physinfo = { 0 };
     1.7 -    uint64_t *cpumaps;
     1.8      unsigned num_cpuwords;
     1.9  
    1.10      if (xc_domain_getinfolist(ctx->xch, domid, 1, &domaininfo) != 1) {
    1.11 @@ -2920,9 +2919,8 @@ libxl_vcpuinfo *libxl_list_vcpu(libxl_ct
    1.12      }
    1.13  
    1.14      num_cpuwords = ((physinfo.max_cpu_id + 64) / 64);
    1.15 -    cpumaps = calloc(num_cpuwords * sizeof(*cpumaps), domaininfo.max_vcpu_id + 1);
    1.16      for (*nb_vcpu = 0; *nb_vcpu <= domaininfo.max_vcpu_id; ++*nb_vcpu, ++ptr) {
    1.17 -        ptr->cpumap = cpumaps + (num_cpuwords * *nb_vcpu);
    1.18 +        ptr->cpumap = malloc(num_cpuwords * sizeof(*ptr->cpumap));
    1.19          if (!ptr->cpumap) {
    1.20              return NULL;
    1.21          }
    1.22 @@ -2945,13 +2943,6 @@ libxl_vcpuinfo *libxl_list_vcpu(libxl_ct
    1.23      return ret;
    1.24  }
    1.25  
    1.26 -void libxl_free_vcpu_list(libxl_vcpuinfo *vcpu)
    1.27 -{
    1.28 -    if ( vcpu )
    1.29 -        free(vcpu[0].cpumap);
    1.30 -    free(vcpu);
    1.31 -}
    1.32 -
    1.33  int libxl_set_vcpuaffinity(libxl_ctx *ctx, uint32_t domid, uint32_t vcpuid,
    1.34                             uint64_t *cpumap, int nrcpus)
    1.35  {
     2.1 --- a/tools/libxl/libxl.h	Thu Aug 19 15:32:28 2010 +0100
     2.2 +++ b/tools/libxl/libxl.h	Thu Aug 19 15:32:56 2010 +0100
     2.3 @@ -432,7 +432,6 @@ int libxl_button_press(libxl_ctx *ctx, u
     2.4  int libxl_get_physinfo(libxl_ctx *ctx, libxl_physinfo *physinfo);
     2.5  libxl_vcpuinfo *libxl_list_vcpu(libxl_ctx *ctx, uint32_t domid,
     2.6                                         int *nb_vcpu, int *nrcpus);
     2.7 -void libxl_free_vcpu_list(libxl_vcpuinfo *vcpu);
     2.8  int libxl_set_vcpuaffinity(libxl_ctx *ctx, uint32_t domid, uint32_t vcpuid,
     2.9                             uint64_t *cpumap, int nrcpus);
    2.10  int libxl_set_vcpucount(libxl_ctx *ctx, uint32_t domid, uint32_t count);
     3.1 --- a/tools/libxl/xl_cmdimpl.c	Thu Aug 19 15:32:28 2010 +0100
     3.2 +++ b/tools/libxl/xl_cmdimpl.c	Thu Aug 19 15:32:56 2010 +0100
     3.3 @@ -3301,49 +3301,58 @@ static void print_vcpuinfo(uint32_t tdom
     3.4      }
     3.5  }
     3.6  
     3.7 +static void print_domain_vcpuinfo(uint32_t domid, uint32_t nr_cpus)
     3.8 +{
     3.9 +    libxl_vcpuinfo *vcpuinfo;
    3.10 +    int i, nb_vcpu, nrcpus;
    3.11 +
    3.12 +    vcpuinfo = libxl_list_vcpu(&ctx, domid, &nb_vcpu, &nrcpus);
    3.13 +
    3.14 +    if (!vcpuinfo) {
    3.15 +        fprintf(stderr, "libxl_list_vcpu failed.\n");
    3.16 +        return;
    3.17 +    }
    3.18 +
    3.19 +    for (i = 0; i < nb_vcpu; i++) {
    3.20 +        print_vcpuinfo(domid, &vcpuinfo[i], nr_cpus);
    3.21 +        libxl_vcpuinfo_destroy(&vcpuinfo[i]);
    3.22 +    }
    3.23 +
    3.24 +    free(vcpuinfo);
    3.25 +}
    3.26 +
    3.27  static void vcpulist(int argc, char **argv)
    3.28  {
    3.29 -    libxl_dominfo *dominfo, *domlist;
    3.30 -    libxl_vcpuinfo *vcpuinfo, *list = NULL;
    3.31 +    libxl_dominfo *dominfo;
    3.32      libxl_physinfo physinfo;
    3.33 -    int nb_vcpu, nb_domain, nrcpus;
    3.34 +    int i, nb_domain;
    3.35  
    3.36      if (libxl_get_physinfo(&ctx, &physinfo) != 0) {
    3.37          fprintf(stderr, "libxl_physinfo failed.\n");
    3.38          goto vcpulist_out;
    3.39      }
    3.40 +
    3.41      printf("%-32s %5s %5s %5s %5s %9s %s\n",
    3.42             "Name", "ID", "VCPU", "CPU", "State", "Time(s)", "CPU Affinity");
    3.43      if (!argc) {
    3.44 -        if (!(domlist = dominfo = libxl_list_domain(&ctx, &nb_domain))) {
    3.45 +        if (!(dominfo = libxl_list_domain(&ctx, &nb_domain))) {
    3.46              fprintf(stderr, "libxl_list_domain failed.\n");
    3.47              goto vcpulist_out;
    3.48          }
    3.49 -        for (; nb_domain > 0; --nb_domain, ++dominfo) {
    3.50 -            if (!(list = vcpuinfo = libxl_list_vcpu(&ctx, dominfo->domid, &nb_vcpu,
    3.51 -                &nrcpus))) {
    3.52 -                fprintf(stderr, "libxl_list_vcpu failed.\n");
    3.53 -                goto vcpulist_out;
    3.54 -            }
    3.55 -            for (; nb_vcpu > 0; --nb_vcpu, ++vcpuinfo) {
    3.56 -                print_vcpuinfo(dominfo->domid, vcpuinfo, physinfo.nr_cpus);
    3.57 -            }
    3.58 -            libxl_free_vcpu_list(list);
    3.59 -        }
    3.60 -        free(domlist);
    3.61 +
    3.62 +        for (i = 0; i<nb_domain; i++)
    3.63 +            print_domain_vcpuinfo(dominfo[i].domid, physinfo.nr_cpus);
    3.64 +
    3.65 +        free(dominfo);
    3.66 +
    3.67      } else {
    3.68          for (; argc > 0; ++argv, --argc) {
    3.69              if (domain_qualifier_to_domid(*argv, &domid, 0) < 0) {
    3.70                  fprintf(stderr, "%s is an invalid domain identifier\n", *argv);
    3.71 -            }
    3.72 -            if (!(list = vcpuinfo = libxl_list_vcpu(&ctx, domid, &nb_vcpu, &nrcpus))) {
    3.73 -                fprintf(stderr, "libxl_list_vcpu failed.\n");
    3.74                  goto vcpulist_out;
    3.75              }
    3.76 -            for (; nb_vcpu > 0; --nb_vcpu, ++vcpuinfo) {
    3.77 -                print_vcpuinfo(domid, vcpuinfo, physinfo.nr_cpus);
    3.78 -            }
    3.79 -            libxl_free_vcpu_list(list);
    3.80 +
    3.81 +            print_domain_vcpuinfo(domid, physinfo.nr_cpus);
    3.82          }
    3.83      }
    3.84    vcpulist_out: