debuggers.hg
changeset 21189:fd0fd3612eb8
libxl: New function libxl_domain_info
libxl_domain_info provides a way to get the struct libxl_dominfo
for a single domain given its domid.
Signed-off-by: Ian Jackson <Ian.Jackson@eu.citrix.com>
libxl_domain_info provides a way to get the struct libxl_dominfo
for a single domain given its domid.
Signed-off-by: Ian Jackson <Ian.Jackson@eu.citrix.com>
author | Keir Fraser <keir.fraser@citrix.com> |
---|---|
date | Mon Apr 12 17:43:25 2010 +0100 (2010-04-12) |
parents | cd05b6aa8c0a |
children | 5d96ac36d97e |
files | tools/libxl/libxl.c tools/libxl/libxl.h |
line diff
1.1 --- a/tools/libxl/libxl.c Mon Apr 12 17:42:57 2010 +0100 1.2 +++ b/tools/libxl/libxl.c Mon Apr 12 17:43:25 2010 +0100 1.3 @@ -373,6 +373,24 @@ int libxl_domain_resume(struct libxl_ctx 1.4 return 0; 1.5 } 1.6 1.7 +static void xcinfo2xlinfo(const xc_domaininfo_t *xcinfo, 1.8 + struct libxl_dominfo *xlinfo) { 1.9 + memcpy(&(xlinfo->uuid), xcinfo->handle, sizeof(xen_domain_handle_t)); 1.10 + xlinfo->domid = xcinfo->domain; 1.11 + 1.12 + if (xcinfo->flags & XEN_DOMINF_dying) 1.13 + xlinfo->dying = 1; 1.14 + else if (xcinfo->flags & XEN_DOMINF_paused) 1.15 + xlinfo->paused = 1; 1.16 + else if (xcinfo->flags & XEN_DOMINF_blocked || 1.17 + xcinfo->flags & XEN_DOMINF_running) 1.18 + xlinfo->running = 1; 1.19 + xlinfo->max_memkb = PAGE_TO_MEMKB(xcinfo->tot_pages); 1.20 + xlinfo->cpu_time = xcinfo->cpu_time; 1.21 + xlinfo->vcpu_max_id = xcinfo->max_vcpu_id; 1.22 + xlinfo->vcpu_online = xcinfo->nr_online_vcpus; 1.23 +} 1.24 + 1.25 struct libxl_dominfo * libxl_list_domain(struct libxl_ctx *ctx, int *nb_domain) 1.26 { 1.27 struct libxl_dominfo *ptr; 1.28 @@ -381,29 +399,31 @@ struct libxl_dominfo * libxl_list_domain 1.29 int size = 1024; 1.30 1.31 ptr = calloc(size, sizeof(struct libxl_dominfo)); 1.32 - if (!ptr) 1.33 - return NULL; 1.34 + if (!ptr) return NULL; 1.35 1.36 ret = xc_domain_getinfolist(ctx->xch, 0, 1024, info); 1.37 - for (i = 0; i < ret; i++) { 1.38 - memcpy(&(ptr[i].uuid), info[i].handle, sizeof(xen_domain_handle_t)); 1.39 - ptr[i].domid = info[i].domain; 1.40 + if (ret<0) return NULL; 1.41 1.42 - if (info[i].flags & XEN_DOMINF_dying) 1.43 - ptr[i].dying = 1; 1.44 - else if (info[i].flags & XEN_DOMINF_paused) 1.45 - ptr[i].paused = 1; 1.46 - else if (info[i].flags & XEN_DOMINF_blocked || info[i].flags & XEN_DOMINF_running) 1.47 - ptr[i].running = 1; 1.48 - ptr[i].max_memkb = PAGE_TO_MEMKB(info[i].tot_pages); 1.49 - ptr[i].cpu_time = info[i].cpu_time; 1.50 - ptr[i].vcpu_max_id = info[i].max_vcpu_id; 1.51 - ptr[i].vcpu_online = info[i].nr_online_vcpus; 1.52 + for (i = 0; i < ret; i++) { 1.53 + xcinfo2xlinfo(&info[i], &ptr[i]); 1.54 } 1.55 *nb_domain = ret; 1.56 return ptr; 1.57 } 1.58 1.59 +int libxl_domain_info(struct libxl_ctx *ctx, struct libxl_dominfo *info_r, 1.60 + uint32_t domid) { 1.61 + xc_domaininfo_t xcinfo; 1.62 + int ret; 1.63 + 1.64 + ret = xc_domain_getinfolist(ctx->xch, domid, 1, &xcinfo); 1.65 + if (ret<0) return ERROR_FAIL; 1.66 + if (ret==0 || xcinfo.domain != domid) return ERROR_INVAL; 1.67 + 1.68 + xcinfo2xlinfo(&xcinfo, info_r); 1.69 + return 0; 1.70 +} 1.71 + 1.72 /* this API call only list VM running on this host. a VM can be an aggregate of multiple domains. */ 1.73 struct libxl_vminfo * libxl_list_vm(struct libxl_ctx *ctx, int *nb_vm) 1.74 {
2.1 --- a/tools/libxl/libxl.h Mon Apr 12 17:42:57 2010 +0100 2.2 +++ b/tools/libxl/libxl.h Mon Apr 12 17:43:25 2010 +0100 2.3 @@ -315,7 +315,9 @@ int libxl_set_memory_target(struct libxl 2.4 2.5 int libxl_console_attach(struct libxl_ctx *ctx, uint32_t domid, int cons_num); 2.6 2.7 -struct libxl_dominfo * libxl_list_domain(struct libxl_ctx *ctx, int *nb_domain); 2.8 +int libxl_domain_info(struct libxl_ctx*, struct libxl_dominfo *info_r, 2.9 + uint32_t domid); 2.10 +struct libxl_dominfo * libxl_list_domain(struct libxl_ctx*, int *nb_domain); 2.11 struct libxl_vminfo * libxl_list_vm(struct libxl_ctx *ctx, int *nb_vm); 2.12 2.13 typedef struct libxl_device_model_starting libxl_device_model_starting;