[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [Xen-changelog] [xen-unstable] libxenlight: separate logically list_vm and list_domain
# HG changeset patch # User Keir Fraser <keir.fraser@xxxxxxxxxx> # Date 1263751503 0 # Node ID abc717dc6c2ad1fb371d72d20380c5b6e9f146d3 # Parent efbd58260961aef1a8fe538080013d1c258186ed 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@xxxxxxxxxxxxx> --- tools/libxl/libxl.c | 55 +++++++++++++++++++++++++++++++++++----------- tools/libxl/libxl.h | 12 +++++++++- tools/libxl/libxl_utils.c | 19 ++++++++++----- tools/libxl/libxl_utils.h | 2 - tools/libxl/xl.c | 2 - 5 files changed, 68 insertions(+), 22 deletions(-) diff -r efbd58260961 -r abc717dc6c2a tools/libxl/libxl.c --- a/tools/libxl/libxl.c Sun Jan 17 18:03:00 2010 +0000 +++ b/tools/libxl/libxl.c Sun Jan 17 18:05:03 2010 +0000 @@ -33,6 +33,8 @@ #include "libxl_utils.h" #include "libxl_internal.h" #include "flexarray.h" + +#define PAGE_TO_MEMKB(pages) ((pages) * 4) int libxl_ctx_init(struct libxl_ctx *ctx, int version) { @@ -282,21 +284,19 @@ int libxl_domain_resume(struct libxl_ctx return 0; } -struct libxl_dominfo * libxl_domain_list(struct libxl_ctx *ctx, int *nb_domain) +struct libxl_dominfo * libxl_list_domain(struct libxl_ctx *ctx, int *nb_domain) { struct libxl_dominfo *ptr; - int index, i, ret, first_domain; + int index, i, ret; xc_domaininfo_t info[1024]; int size = 1024; - first_domain = 1; - index = 0; ptr = calloc(size, sizeof(struct libxl_dominfo)); if (!ptr) return NULL; - ret = xc_domain_getinfolist(ctx->xch, first_domain, 1024, info); - for (i = 0; i < ret; i++) { + ret = xc_domain_getinfolist(ctx->xch, 0, 1024, info); + for (index = i = 0; i < ret; i++) { memcpy(&(ptr[index].uuid), info[i].handle, sizeof(xen_domain_handle_t)); ptr[index].domid = info[i].domain; @@ -306,11 +306,39 @@ struct libxl_dominfo * libxl_domain_list ptr[index].paused = 1; else if (info[i].flags & XEN_DOMINF_blocked || info[i].flags & XEN_DOMINF_running) ptr[index].running = 1; - - first_domain = info[i].domain + 1; + ptr[index].max_memkb = PAGE_TO_MEMKB(info[i].max_pages); + ptr[index].cpu_time = info[i].cpu_time; + ptr[index].vcpu_max_id = info[i].max_vcpu_id; + ptr[index].vcpu_online = info[i].nr_online_vcpus; + index++; } *nb_domain = index; + return ptr; +} + +/* this API call only list VM running on this host. a VM can be an aggregate of multiple domains. */ +struct libxl_vminfo * libxl_list_vm(struct libxl_ctx *ctx, int *nb_vm) +{ + struct libxl_vminfo *ptr; + int index, i, ret; + xc_domaininfo_t info[1024]; + int size = 1024; + + ptr = calloc(size, sizeof(struct libxl_dominfo)); + if (!ptr) + return NULL; + + ret = xc_domain_getinfolist(ctx->xch, 1, 1024, info); + for (index = i = 0; i < ret; i++) { + if (libxl_is_stubdom(ctx, info[i].domain, NULL)) + continue; + memcpy(&(ptr[index].uuid), info[i].handle, sizeof(xen_domain_handle_t)); + ptr[index].domid = info[i].domain; + + index++; + } + *nb_vm = index; return ptr; } @@ -1530,7 +1558,8 @@ static int libxl_build_xenpv_qemu_args(s libxl_device_vfb *vfb, int num_console, libxl_device_console *console, - libxl_device_model_info *info) { + libxl_device_model_info *info) +{ int i = 0, j = 0, num = 0; memset(info, 0x00, sizeof(libxl_device_model_info)); @@ -1548,8 +1577,8 @@ static int libxl_build_xenpv_qemu_args(s num++; } if (num > 0) { - uint32_t guest_domid = libxl_is_stubdom(ctx, vfb->domid); - if (guest_domid) { + uint32_t guest_domid; + if (libxl_is_stubdom(ctx, vfb->domid, &guest_domid)) { char *filename; char *name = libxl_sprintf(ctx, "qemu-dm-%s", libxl_domid_to_name(ctx, guest_domid)); libxl_create_logfile(ctx, name, &filename); @@ -1988,7 +2017,7 @@ int libxl_device_pci_add(struct libxl_ct fclose(f); } out: - if (!libxl_is_stubdom(ctx, domid)) { + if (!libxl_is_stubdom(ctx, domid, NULL)) { rc = xc_assign_device(ctx->xch, domid, pcidev->value); if (rc < 0) XL_LOG_ERRNOVAL(ctx, XL_LOG_ERROR, rc, "xc_assign_device failed"); @@ -2079,7 +2108,7 @@ out: out: libxl_device_pci_flr(ctx, pcidev->domain, pcidev->bus, pcidev->dev, pcidev->func); - if (!libxl_is_stubdom(ctx, domid)) { + if (!libxl_is_stubdom(ctx, domid, NULL)) { rc = xc_deassign_device(ctx->xch, domid, pcidev->value); if (rc < 0) XL_LOG_ERRNOVAL(ctx, XL_LOG_ERROR, rc, "xc_deassign_device failed"); diff -r efbd58260961 -r abc717dc6c2a tools/libxl/libxl.h --- a/tools/libxl/libxl.h Sun Jan 17 18:03:00 2010 +0000 +++ b/tools/libxl/libxl.h Sun Jan 17 18:05:03 2010 +0000 @@ -30,6 +30,15 @@ struct libxl_dominfo { uint8_t dying:1; uint8_t paused:1; uint8_t running:1; + uint64_t max_memkb; + uint64_t cpu_time; + uint32_t vcpu_max_id; + uint32_t vcpu_online; +}; + +struct libxl_vminfo { + uint8_t uuid[16]; + uint32_t domid; }; struct libxl_ctx { @@ -295,7 +304,8 @@ int libxl_set_memory_target(struct libxl int libxl_console_attach(struct libxl_ctx *ctx, uint32_t domid, int cons_num); -struct libxl_dominfo * libxl_domain_list(struct libxl_ctx *ctx, int *nb_domain); +struct libxl_dominfo * libxl_list_domain(struct libxl_ctx *ctx, int *nb_domain); +struct libxl_vminfo * libxl_list_vm(struct libxl_ctx *ctx, int *nb_vm); typedef struct libxl_device_model_starting libxl_device_model_starting; int libxl_create_device_model(struct libxl_ctx *ctx, diff -r efbd58260961 -r abc717dc6c2a tools/libxl/libxl_utils.c --- a/tools/libxl/libxl_utils.c Sun Jan 17 18:03:00 2010 +0000 +++ b/tools/libxl/libxl_utils.c Sun Jan 17 18:05:03 2010 +0000 @@ -60,7 +60,7 @@ int libxl_name_to_domid(struct libxl_ctx char *domname; struct libxl_dominfo *dominfo; - dominfo = libxl_domain_list(ctx, &nb_domains); + dominfo = libxl_list_domain(ctx, &nb_domains); if (!dominfo) return ERROR_NOMEM; @@ -85,13 +85,20 @@ int libxl_get_stubdom_id(struct libxl_ct return 0; } -int libxl_is_stubdom(struct libxl_ctx *ctx, int domid) +int libxl_is_stubdom(struct libxl_ctx *ctx, uint32_t domid, uint32_t *target_domid) { - char *target = libxl_xs_read(ctx, XBT_NULL, libxl_sprintf(ctx, "%s/target", libxl_xs_get_dompath(ctx, domid))); - if (target) - return atoi(target); - else + char *target, *endptr; + uint32_t value; + + target = libxl_xs_read(ctx, XBT_NULL, libxl_sprintf(ctx, "%s/target", libxl_xs_get_dompath(ctx, domid))); + if (!target) return 0; + value = strtol(target, &endptr, 10); + if (*endptr != '\0') + return 0; + if (target_domid) + *target_domid = value; + return 1; } int libxl_create_logfile(struct libxl_ctx *ctx, char *name, char **full_name) diff -r efbd58260961 -r abc717dc6c2a tools/libxl/libxl_utils.h --- a/tools/libxl/libxl_utils.h Sun Jan 17 18:03:00 2010 +0000 +++ b/tools/libxl/libxl_utils.h Sun Jan 17 18:05:03 2010 +0000 @@ -22,7 +22,7 @@ int libxl_name_to_domid(struct libxl_ctx int libxl_name_to_domid(struct libxl_ctx *ctx, char *name, uint32_t *domid); char *libxl_domid_to_name(struct libxl_ctx *ctx, uint32_t domid); int libxl_get_stubdom_id(struct libxl_ctx *ctx, int guest_domid); -int libxl_is_stubdom(struct libxl_ctx *ctx, int domid); +int libxl_is_stubdom(struct libxl_ctx *ctx, uint32_t domid, uint32_t *target_domid); int libxl_create_logfile(struct libxl_ctx *ctx, char *name, char **full_name); int libxl_string_to_phystype(struct libxl_ctx *ctx, char *s, libxl_disk_phystype *phystype); diff -r efbd58260961 -r abc717dc6c2a tools/libxl/xl.c --- a/tools/libxl/xl.c Sun Jan 17 18:03:00 2010 +0000 +++ b/tools/libxl/xl.c Sun Jan 17 18:05:03 2010 +0000 @@ -1415,7 +1415,7 @@ void list_domains(void) } libxl_ctx_set_log(&ctx, log_callback, NULL); - info = libxl_domain_list(&ctx, &nb_domain); + info = libxl_list_domain(&ctx, &nb_domain); if (info < 0) { fprintf(stderr, "libxl_domain_infolist failed.\n"); _______________________________________________ Xen-changelog mailing list Xen-changelog@xxxxxxxxxxxxxxxxxxx http://lists.xensource.com/xen-changelog
|
Lists.xenproject.org is hosted with RackSpace, monitoring our |