From 27151b3d10a3adfa9befea55457b9e4e3052eff7 Mon Sep 17 00:00:00 2001 From: "Richard W.M. Jones" Date: Mon, 30 Apr 2007 16:58:26 +0000 Subject: [PATCH] Mon Apr 30 18:02:00 BST 2007 Richard W.M. Jones * src/proxy_internal.c (xenProxyGetCapabilities): Add support for virConnectGetCapabilities across Xen proxy. --- ChangeLog | 5 +++++ proxy/libvirt_proxy.c | 23 +++++++++++++++++++ src/proxy_internal.c | 52 ++++++++++++++++++++++++++++++++++++++++++- src/proxy_internal.h | 3 ++- 4 files changed, 81 insertions(+), 2 deletions(-) diff --git a/ChangeLog b/ChangeLog index 05df555485..56a9108582 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +Mon Apr 30 18:02:00 BST 2007 Richard W.M. Jones + + * src/proxy_internal.c (xenProxyGetCapabilities): Add support + for virConnectGetCapabilities across Xen proxy. + Mon Apr 30 18:00:00 BST 2007 Richard W.M. Jones * src/xen_unified.c: In the non-root case keep track of the diff --git a/proxy/libvirt_proxy.c b/proxy/libvirt_proxy.c index c21c34f945..21424d05c1 100644 --- a/proxy/libvirt_proxy.c +++ b/proxy/libvirt_proxy.c @@ -587,6 +587,29 @@ retry2: req->len = sizeof(virProxyPacket) + sizeof(virNodeInfo); } break; + + case VIR_PROXY_GET_CAPABILITIES: + if (req->len != sizeof(virProxyPacket)) + goto comm_error; + + xml = xenHypervisorGetCapabilities (conn); + if (!xml) { + req->data.arg = -1; + req->len = sizeof (virProxyPacket); + } else { + int xmllen = strlen (xml); + if (xmllen > (int) sizeof (request.extra.str)) { + req->data.arg = -2; + req->len = sizeof (virProxyPacket); + } else { + req->data.arg = 0; + memmove (request.extra.str, xml, xmllen); + req->len = sizeof (virProxyPacket) + xmllen; + } + free (xml); + } + break; + case VIR_PROXY_DOMAIN_XML: if (req->len != sizeof(virProxyPacket)) goto comm_error; diff --git a/src/proxy_internal.c b/src/proxy_internal.c index 5767f30fa7..fdf16f0269 100644 --- a/src/proxy_internal.c +++ b/src/proxy_internal.c @@ -31,6 +31,7 @@ static int xenProxyClose(virConnectPtr conn); static int xenProxyOpen(virConnectPtr conn, const char *name, int flags); static int xenProxyGetVersion(virConnectPtr conn, unsigned long *hvVer); static int xenProxyNodeGetInfo(virConnectPtr conn, virNodeInfoPtr info); +static char *xenProxyGetCapabilities(virConnectPtr conn); static int xenProxyListDomains(virConnectPtr conn, int *ids, int maxids); static int xenProxyNumOfDomains(virConnectPtr conn); static virDomainPtr xenProxyLookupByID(virConnectPtr conn, int id); @@ -53,7 +54,7 @@ virDriver xenProxyDriver = { xenProxyGetVersion, /* version */ NULL, /* getMaxVcpus */ xenProxyNodeGetInfo, /* nodeGetInfo */ - NULL, /* getCapabilities */ + xenProxyGetCapabilities, /* getCapabilities */ xenProxyListDomains, /* listDomains */ xenProxyNumOfDomains, /* numOfDomains */ NULL, /* domainCreateLinux */ @@ -976,6 +977,55 @@ xenProxyNodeGetInfo(virConnectPtr conn, virNodeInfoPtr info) { return(0); } +/** + * xenProxyGetCapabilities: + * @conn: pointer to the Xen Daemon block + * + * Extract capabilities of the hypervisor. + * + * Returns capabilities in case of success (freed by caller) + * and NULL in case of failure. + */ +static char * +xenProxyGetCapabilities (virConnectPtr conn) +{ + virProxyPacket req; + virProxyFullPacket ans; + int ret, xmllen; + char *xml; + + if (!VIR_IS_CONNECT(conn)) { + virProxyError(conn, VIR_ERR_INVALID_CONN, __FUNCTION__); + return NULL; + } + memset(&req, 0, sizeof(req)); + req.command = VIR_PROXY_GET_CAPABILITIES; + req.data.arg = 0; + req.len = sizeof(req); + ret = xenProxyCommand(conn, &req, &ans, 0); + if (ret < 0) { + xenProxyClose(conn); + return NULL; + } + if (ans.data.arg == -1) + return NULL; + if (ans.len <= sizeof(virProxyPacket)) { + virProxyError(conn, VIR_ERR_OPERATION_FAILED, __FUNCTION__); + return NULL; + } + + xmllen = ans.len - sizeof (virProxyPacket); + xml = malloc (xmllen+1); + if (!xml) { + virProxyError (conn, VIR_ERR_NO_MEMORY, __FUNCTION__); + return NULL; + } + memmove (xml, ans.extra.str, xmllen); + xml[xmllen] = '\0'; + + return xml; +} + /** * xenProxyDomainDumpXML: * @domain: a domain object diff --git a/src/proxy_internal.h b/src/proxy_internal.h index 492414471a..f857bd5520 100644 --- a/src/proxy_internal.h +++ b/src/proxy_internal.h @@ -36,7 +36,8 @@ typedef enum { VIR_PROXY_MAX_MEMORY = 8, VIR_PROXY_DOMAIN_INFO = 9, VIR_PROXY_DOMAIN_XML = 10, - VIR_PROXY_DOMAIN_OSTYPE = 11 + VIR_PROXY_DOMAIN_OSTYPE = 11, + VIR_PROXY_GET_CAPABILITIES = 12 } virProxyCommand; /*