libxl: New function libxl_domain_info
authorKeir Fraser <keir.fraser@citrix.com>
Mon, 12 Apr 2010 16:43:25 +0000 (17:43 +0100)
committerKeir Fraser <keir.fraser@citrix.com>
Mon, 12 Apr 2010 16:43:25 +0000 (17:43 +0100)
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>
tools/libxl/libxl.c
tools/libxl/libxl.h

index 663cbc19cf3d021a8249a031cd6695b11efd025e..d3d73be90d2d6a40f012b16953c47b075784f982 100644 (file)
@@ -373,6 +373,24 @@ int libxl_domain_resume(struct libxl_ctx *ctx, uint32_t domid)
     return 0;
 }
 
+static void xcinfo2xlinfo(const xc_domaininfo_t *xcinfo,
+                          struct libxl_dominfo *xlinfo) {
+    memcpy(&(xlinfo->uuid), xcinfo->handle, sizeof(xen_domain_handle_t));
+    xlinfo->domid = xcinfo->domain;
+
+    if (xcinfo->flags & XEN_DOMINF_dying)
+        xlinfo->dying = 1;
+    else if (xcinfo->flags & XEN_DOMINF_paused)
+        xlinfo->paused = 1;
+    else if (xcinfo->flags & XEN_DOMINF_blocked ||
+             xcinfo->flags & XEN_DOMINF_running)
+        xlinfo->running = 1;
+    xlinfo->max_memkb = PAGE_TO_MEMKB(xcinfo->tot_pages);
+    xlinfo->cpu_time = xcinfo->cpu_time;
+    xlinfo->vcpu_max_id = xcinfo->max_vcpu_id;
+    xlinfo->vcpu_online = xcinfo->nr_online_vcpus;
+}
+
 struct libxl_dominfo * libxl_list_domain(struct libxl_ctx *ctx, int *nb_domain)
 {
     struct libxl_dominfo *ptr;
@@ -381,29 +399,31 @@ struct libxl_dominfo * libxl_list_domain(struct libxl_ctx *ctx, int *nb_domain)
     int size = 1024;
 
     ptr = calloc(size, sizeof(struct libxl_dominfo));
-    if (!ptr)
-        return NULL;
+    if (!ptr) return NULL;
 
     ret = xc_domain_getinfolist(ctx->xch, 0, 1024, info);
+    if (ret<0) return NULL;
+
     for (i = 0; i < ret; i++) {
-        memcpy(&(ptr[i].uuid), info[i].handle, sizeof(xen_domain_handle_t));
-        ptr[i].domid = info[i].domain;
-
-        if (info[i].flags & XEN_DOMINF_dying)
-            ptr[i].dying = 1;
-        else if (info[i].flags & XEN_DOMINF_paused)
-            ptr[i].paused = 1;
-        else if (info[i].flags & XEN_DOMINF_blocked || info[i].flags & XEN_DOMINF_running)
-            ptr[i].running = 1;
-        ptr[i].max_memkb = PAGE_TO_MEMKB(info[i].tot_pages);
-        ptr[i].cpu_time = info[i].cpu_time;
-        ptr[i].vcpu_max_id = info[i].max_vcpu_id;
-        ptr[i].vcpu_online = info[i].nr_online_vcpus;
+        xcinfo2xlinfo(&info[i], &ptr[i]);
     }
     *nb_domain = ret;
     return ptr;
 }
 
+int libxl_domain_info(struct libxl_ctx *ctx, struct libxl_dominfo *info_r,
+                      uint32_t domid) {
+    xc_domaininfo_t xcinfo;
+    int ret;
+
+    ret = xc_domain_getinfolist(ctx->xch, domid, 1, &xcinfo);
+    if (ret<0) return ERROR_FAIL;
+    if (ret==0 || xcinfo.domain != domid) return ERROR_INVAL;
+
+    xcinfo2xlinfo(&xcinfo, info_r);
+    return 0;
+}
+
 /* 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)
 {
index 2ef8640010777d93f3248ff85ff35496672e59de..43db1f60722a64410bb49dfdee86e34f759f456f 100644 (file)
@@ -315,7 +315,9 @@ int libxl_set_memory_target(struct libxl_ctx *ctx, uint32_t domid, uint32_t targ
 
 int libxl_console_attach(struct libxl_ctx *ctx, uint32_t domid, int cons_num);
 
-struct libxl_dominfo * libxl_list_domain(struct libxl_ctx *ctx, int *nb_domain);
+int libxl_domain_info(struct libxl_ctx*, struct libxl_dominfo *info_r,
+                      uint32_t domid);
+struct libxl_dominfo * libxl_list_domain(struct libxl_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;