debuggers.hg

changeset 20860:abc717dc6c2a

libxenlight: separate logically list_vm and list_domain

previously list_domain was something between listing VM and domains.
provide 2 separates API calls to list domains and list vms. the list
vms API filters utility domains like stubdomains, and domain 0

change is_stubdom to properly check the integer and also return a
boolean value.

Signed-off-by: Vincent Hanquez <vincent.hanquez@eu.citrix.com>
author Keir Fraser <keir.fraser@citrix.com>
date Sun Jan 17 18:05:03 2010 +0000 (2010-01-17)
parents efbd58260961
children ff2d29e6ab9c
files tools/libxl/libxl.c tools/libxl/libxl.h tools/libxl/libxl_utils.c tools/libxl/libxl_utils.h tools/libxl/xl.c
line diff
     1.1 --- a/tools/libxl/libxl.c	Sun Jan 17 18:03:00 2010 +0000
     1.2 +++ b/tools/libxl/libxl.c	Sun Jan 17 18:05:03 2010 +0000
     1.3 @@ -34,6 +34,8 @@
     1.4  #include "libxl_internal.h"
     1.5  #include "flexarray.h"
     1.6  
     1.7 +#define PAGE_TO_MEMKB(pages) ((pages) * 4)
     1.8 +
     1.9  int libxl_ctx_init(struct libxl_ctx *ctx, int version)
    1.10  {
    1.11      if (version != LIBXL_VERSION)
    1.12 @@ -282,21 +284,19 @@ int libxl_domain_resume(struct libxl_ctx
    1.13      return 0;
    1.14  }
    1.15  
    1.16 -struct libxl_dominfo * libxl_domain_list(struct libxl_ctx *ctx, int *nb_domain)
    1.17 +struct libxl_dominfo * libxl_list_domain(struct libxl_ctx *ctx, int *nb_domain)
    1.18  {
    1.19      struct libxl_dominfo *ptr;
    1.20 -    int index, i, ret, first_domain;
    1.21 +    int index, i, ret;
    1.22      xc_domaininfo_t info[1024];
    1.23      int size = 1024;
    1.24  
    1.25 -    first_domain = 1;
    1.26 -    index = 0;
    1.27      ptr = calloc(size, sizeof(struct libxl_dominfo));
    1.28      if (!ptr)
    1.29          return NULL;
    1.30  
    1.31 -    ret = xc_domain_getinfolist(ctx->xch, first_domain, 1024, info);
    1.32 -    for (i = 0; i < ret; i++) {
    1.33 +    ret = xc_domain_getinfolist(ctx->xch, 0, 1024, info);
    1.34 +    for (index = i = 0; i < ret; i++) {
    1.35          memcpy(&(ptr[index].uuid), info[i].handle, sizeof(xen_domain_handle_t));
    1.36          ptr[index].domid = info[i].domain;
    1.37  
    1.38 @@ -306,14 +306,42 @@ struct libxl_dominfo * libxl_domain_list
    1.39              ptr[index].paused = 1;
    1.40          else if (info[i].flags & XEN_DOMINF_blocked || info[i].flags & XEN_DOMINF_running)
    1.41              ptr[index].running = 1;
    1.42 +        ptr[index].max_memkb = PAGE_TO_MEMKB(info[i].max_pages);
    1.43 +        ptr[index].cpu_time = info[i].cpu_time;
    1.44 +        ptr[index].vcpu_max_id = info[i].max_vcpu_id;
    1.45 +        ptr[index].vcpu_online = info[i].nr_online_vcpus;
    1.46  
    1.47 -        first_domain = info[i].domain + 1;
    1.48          index++;
    1.49      }
    1.50      *nb_domain = index;
    1.51      return ptr;
    1.52  }
    1.53  
    1.54 +/* this API call only list VM running on this host. a VM can be an aggregate of multiple domains. */
    1.55 +struct libxl_vminfo * libxl_list_vm(struct libxl_ctx *ctx, int *nb_vm)
    1.56 +{
    1.57 +    struct libxl_vminfo *ptr;
    1.58 +    int index, i, ret;
    1.59 +    xc_domaininfo_t info[1024];
    1.60 +    int size = 1024;
    1.61 +
    1.62 +    ptr = calloc(size, sizeof(struct libxl_dominfo));
    1.63 +    if (!ptr)
    1.64 +        return NULL;
    1.65 +
    1.66 +    ret = xc_domain_getinfolist(ctx->xch, 1, 1024, info);
    1.67 +    for (index = i = 0; i < ret; i++) {
    1.68 +        if (libxl_is_stubdom(ctx, info[i].domain, NULL))
    1.69 +            continue;
    1.70 +        memcpy(&(ptr[index].uuid), info[i].handle, sizeof(xen_domain_handle_t));
    1.71 +        ptr[index].domid = info[i].domain;
    1.72 +
    1.73 +        index++;
    1.74 +    }
    1.75 +    *nb_vm = index;
    1.76 +    return ptr;
    1.77 +}
    1.78 +
    1.79  int libxl_domain_suspend(struct libxl_ctx *ctx, libxl_domain_suspend_info *info,
    1.80                           uint32_t domid, int fd)
    1.81  {
    1.82 @@ -1530,7 +1558,8 @@ static int libxl_build_xenpv_qemu_args(s
    1.83                                         libxl_device_vfb *vfb,
    1.84                                         int num_console,
    1.85                                         libxl_device_console *console,
    1.86 -                                       libxl_device_model_info *info) {
    1.87 +                                       libxl_device_model_info *info)
    1.88 +{
    1.89      int i = 0, j = 0, num = 0;
    1.90      memset(info, 0x00, sizeof(libxl_device_model_info));
    1.91  
    1.92 @@ -1548,8 +1577,8 @@ static int libxl_build_xenpv_qemu_args(s
    1.93              num++;
    1.94      }
    1.95      if (num > 0) {
    1.96 -        uint32_t guest_domid = libxl_is_stubdom(ctx, vfb->domid);
    1.97 -        if (guest_domid) {
    1.98 +        uint32_t guest_domid;
    1.99 +        if (libxl_is_stubdom(ctx, vfb->domid, &guest_domid)) {
   1.100              char *filename;
   1.101              char *name = libxl_sprintf(ctx, "qemu-dm-%s", libxl_domid_to_name(ctx, guest_domid));
   1.102              libxl_create_logfile(ctx, name, &filename);
   1.103 @@ -1988,7 +2017,7 @@ int libxl_device_pci_add(struct libxl_ct
   1.104          fclose(f);
   1.105      }
   1.106  out:
   1.107 -    if (!libxl_is_stubdom(ctx, domid)) {
   1.108 +    if (!libxl_is_stubdom(ctx, domid, NULL)) {
   1.109          rc = xc_assign_device(ctx->xch, domid, pcidev->value);
   1.110          if (rc < 0)
   1.111              XL_LOG_ERRNOVAL(ctx, XL_LOG_ERROR, rc, "xc_assign_device failed");
   1.112 @@ -2079,7 +2108,7 @@ skip1:
   1.113  out:
   1.114      libxl_device_pci_flr(ctx, pcidev->domain, pcidev->bus, pcidev->dev, pcidev->func);
   1.115  
   1.116 -    if (!libxl_is_stubdom(ctx, domid)) {
   1.117 +    if (!libxl_is_stubdom(ctx, domid, NULL)) {
   1.118          rc = xc_deassign_device(ctx->xch, domid, pcidev->value);
   1.119          if (rc < 0)
   1.120              XL_LOG_ERRNOVAL(ctx, XL_LOG_ERROR, rc, "xc_deassign_device failed");
     2.1 --- a/tools/libxl/libxl.h	Sun Jan 17 18:03:00 2010 +0000
     2.2 +++ b/tools/libxl/libxl.h	Sun Jan 17 18:05:03 2010 +0000
     2.3 @@ -30,6 +30,15 @@ struct libxl_dominfo {
     2.4      uint8_t dying:1;
     2.5      uint8_t paused:1;
     2.6      uint8_t running:1;
     2.7 +    uint64_t max_memkb;
     2.8 +    uint64_t cpu_time;
     2.9 +    uint32_t vcpu_max_id;
    2.10 +    uint32_t vcpu_online;
    2.11 +};
    2.12 +
    2.13 +struct libxl_vminfo {
    2.14 +    uint8_t uuid[16];
    2.15 +    uint32_t domid;
    2.16  };
    2.17  
    2.18  struct libxl_ctx {
    2.19 @@ -295,7 +304,8 @@ int libxl_set_memory_target(struct libxl
    2.20  
    2.21  int libxl_console_attach(struct libxl_ctx *ctx, uint32_t domid, int cons_num);
    2.22  
    2.23 -struct libxl_dominfo * libxl_domain_list(struct libxl_ctx *ctx, int *nb_domain);
    2.24 +struct libxl_dominfo * libxl_list_domain(struct libxl_ctx *ctx, int *nb_domain);
    2.25 +struct libxl_vminfo * libxl_list_vm(struct libxl_ctx *ctx, int *nb_vm);
    2.26  
    2.27  typedef struct libxl_device_model_starting libxl_device_model_starting;
    2.28  int libxl_create_device_model(struct libxl_ctx *ctx,
     3.1 --- a/tools/libxl/libxl_utils.c	Sun Jan 17 18:03:00 2010 +0000
     3.2 +++ b/tools/libxl/libxl_utils.c	Sun Jan 17 18:05:03 2010 +0000
     3.3 @@ -60,7 +60,7 @@ int libxl_name_to_domid(struct libxl_ctx
     3.4      char *domname;
     3.5      struct libxl_dominfo *dominfo;
     3.6  
     3.7 -    dominfo = libxl_domain_list(ctx, &nb_domains);
     3.8 +    dominfo = libxl_list_domain(ctx, &nb_domains);
     3.9      if (!dominfo)
    3.10          return ERROR_NOMEM;
    3.11  
    3.12 @@ -85,13 +85,20 @@ int libxl_get_stubdom_id(struct libxl_ct
    3.13          return 0;
    3.14  }
    3.15  
    3.16 -int libxl_is_stubdom(struct libxl_ctx *ctx, int domid)
    3.17 +int libxl_is_stubdom(struct libxl_ctx *ctx, uint32_t domid, uint32_t *target_domid)
    3.18  {
    3.19 -    char *target = libxl_xs_read(ctx, XBT_NULL, libxl_sprintf(ctx, "%s/target", libxl_xs_get_dompath(ctx, domid)));
    3.20 -    if (target)
    3.21 -        return atoi(target);
    3.22 -    else
    3.23 +    char *target, *endptr;
    3.24 +    uint32_t value;
    3.25 +
    3.26 +    target = libxl_xs_read(ctx, XBT_NULL, libxl_sprintf(ctx, "%s/target", libxl_xs_get_dompath(ctx, domid)));
    3.27 +    if (!target)
    3.28          return 0;
    3.29 +    value = strtol(target, &endptr, 10);
    3.30 +    if (*endptr != '\0')
    3.31 +        return 0;
    3.32 +    if (target_domid)
    3.33 +        *target_domid = value;
    3.34 +    return 1;
    3.35  }
    3.36  
    3.37  int libxl_create_logfile(struct libxl_ctx *ctx, char *name, char **full_name)
     4.1 --- a/tools/libxl/libxl_utils.h	Sun Jan 17 18:03:00 2010 +0000
     4.2 +++ b/tools/libxl/libxl_utils.h	Sun Jan 17 18:05:03 2010 +0000
     4.3 @@ -22,7 +22,7 @@ unsigned long libxl_get_required_shadow_
     4.4  int libxl_name_to_domid(struct libxl_ctx *ctx, char *name, uint32_t *domid);
     4.5  char *libxl_domid_to_name(struct libxl_ctx *ctx, uint32_t domid);
     4.6  int libxl_get_stubdom_id(struct libxl_ctx *ctx, int guest_domid);
     4.7 -int libxl_is_stubdom(struct libxl_ctx *ctx, int domid);
     4.8 +int libxl_is_stubdom(struct libxl_ctx *ctx, uint32_t domid, uint32_t *target_domid);
     4.9  int libxl_create_logfile(struct libxl_ctx *ctx, char *name, char **full_name);
    4.10  int libxl_string_to_phystype(struct libxl_ctx *ctx, char *s, libxl_disk_phystype *phystype);
    4.11  
     5.1 --- a/tools/libxl/xl.c	Sun Jan 17 18:03:00 2010 +0000
     5.2 +++ b/tools/libxl/xl.c	Sun Jan 17 18:05:03 2010 +0000
     5.3 @@ -1415,7 +1415,7 @@ void list_domains(void)
     5.4      }
     5.5      libxl_ctx_set_log(&ctx, log_callback, NULL);
     5.6  
     5.7 -    info = libxl_domain_list(&ctx, &nb_domain);
     5.8 +    info = libxl_list_domain(&ctx, &nb_domain);
     5.9  
    5.10      if (info < 0) {
    5.11          fprintf(stderr, "libxl_domain_infolist failed.\n");