[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[PATCH] tools/ctrl: add xc_domain_hvm_getcontext_size



Current users of xc_domain_hvm_getcontext_partial rely on knowing ahead of time
the size of the requested HVM context. This isn't exactly prudent as the size
may change across Xen versions, requiring callers to re-compile in lockstep
with the Xen headers. This isn't an issue for in-tree tools and libraries,
but out-of-tree tools that supposed to work across all Xen versions, like
LibVMI, would fail to work after a size change to any of the HVM contexts.

Add xc_domain_hvm_getcontext_size so that external callers can at least be
backwards compatible with various HVM context sizes by maintaining their
own internal definitions of them and not relying on the current Xen header. It
is preferred to know the exact size Xen is going to return instead of guessing
by associating the HVM context sizes with Xen releases. The underlying domctl
has supported returning the context size to begin with, so with this change
we are just exposing that functionality to the users of libxc.

Signed-off-by: Tamas K Lengyel <tamas@xxxxxxxxxxxxx>
---
 tools/include/xenctrl.h     | 12 ++++++++++++
 tools/libs/ctrl/xc_domain.c | 21 +++++++++++++++++++++
 2 files changed, 33 insertions(+)

diff --git a/tools/include/xenctrl.h b/tools/include/xenctrl.h
index 95bd5eca67..ee5095a892 100644
--- a/tools/include/xenctrl.h
+++ b/tools/include/xenctrl.h
@@ -787,6 +787,18 @@ int xc_domain_hvm_getcontext_partial(xc_interface *xch,
                                      uint16_t instance,
                                      void *ctxt_buf,
                                      uint32_t size);
+/**
+ * This function returns the size of the specified context of a hvm domain
+ * @parm xch a handle to an open hypervisor interface
+ * @parm domid the domain to get information from
+ * @parm typecode which type of elemnt required
+ * @parm instance which instance of the type
+ * @return size on success, 0 on failure
+ */
+unsigned long xc_domain_hvm_getcontext_size(xc_interface *xch,
+                                            uint32_t domid,
+                                            uint16_t typecode,
+                                            uint16_t instance);
 
 /**
  * This function will set the context for hvm domain
diff --git a/tools/libs/ctrl/xc_domain.c b/tools/libs/ctrl/xc_domain.c
index ef62f66009..f52d089999 100644
--- a/tools/libs/ctrl/xc_domain.c
+++ b/tools/libs/ctrl/xc_domain.c
@@ -510,6 +510,27 @@ int xc_domain_hvm_getcontext_partial(xc_interface *xch,
     return ret ? -1 : 0;
 }
 
+unsigned long xc_domain_hvm_getcontext_size(xc_interface *xch,
+                                            uint32_t domid,
+                                            uint16_t typecode,
+                                            uint16_t instance)
+{
+    int ret;
+    void *p = NULL;
+    DECLARE_DOMCTL;
+    DECLARE_HYPERCALL_BOUNCE(p, 0, XC_HYPERCALL_BUFFER_BOUNCE_OUT);
+
+    domctl.cmd = XEN_DOMCTL_gethvmcontext_partial;
+    domctl.domain = domid;
+    domctl.u.hvmcontext_partial.type = typecode;
+    domctl.u.hvmcontext_partial.instance = instance;
+    set_xen_guest_handle(domctl.u.hvmcontext_partial.buffer, p);
+
+    ret = do_domctl(xch, &domctl);
+
+    return ret ? 0 : domctl.u.hvmcontext_partial.bufsz;
+}
+
 /* set info to hvm guest for restore */
 int xc_domain_hvm_setcontext(xc_interface *xch,
                              uint32_t domid,
-- 
2.32.0




 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.