diff --git a/ChangeLog b/ChangeLog index 9029ef5e95..493d503b38 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,22 @@ +Wed Aug 9 10:17:03 EDT 2006 Daniel Berrange + + * src/driver.h, src/libvirt.c: Made the virDomainGetXMLDesc + method use the driver backends. + * src/xend_internal.c: Surround all functions which are not + needed for proxy with #ifndef PROXY. Refactor XML generator + functions to allow calling from proxy based on domain id + instead of virDomainPtr object + * src/xs_internal.c, src/xs_internal.h: Change signature + of method for extracting VNC port & console TTY to use domain + id instead of virDomainPtr. Surround functions not used by + proxy in #ifndef PROXY + * src/xml.c:Surround functions not used by proxy in #ifndef PROXY + * src/test.c, src/xen_internal.c: Added NULL entry for new + driver method for fetching XML + * src/proxy_internal.c, src/proxy_internal.h, proxy/libvirt_proxy.c: + Added implmentation of virDomainGetXMLDesc driver method which + goes via proxy. + Tue Aug 8 23:24:51 CEST 2006 Daniel Veillard * src/driver.h src/libvirt.c src/proxy_internal.c src/test.c diff --git a/proxy/Makefile.am b/proxy/Makefile.am index e6741a3c29..ec2730e651 100644 --- a/proxy/Makefile.am +++ b/proxy/Makefile.am @@ -6,11 +6,11 @@ INCLUDES = -I$(top_builddir)/include -I@top_srcdir@/include \ libexec_PROGRAMS = libvirt_proxy -LIBS= libvirt_proxy_SOURCES = libvirt_proxy.c @top_srcdir@/src/xend_internal.c \ @top_srcdir@/src/xen_internal.c @top_srcdir@/src/virterror.c \ - @top_srcdir@/src/sexpr.c + @top_srcdir@/src/sexpr.c @top_srcdir@/src/xml.c \ + @top_srcdir@/src/xs_internal.c libvirt_proxy_LDFLAGS = libvirt_proxy_DEPENDENCIES = libvirt_proxy_LDADD = diff --git a/proxy/libvirt_proxy.c b/proxy/libvirt_proxy.c index 8908bc0254..0b077d1027 100644 --- a/proxy/libvirt_proxy.c +++ b/proxy/libvirt_proxy.c @@ -21,6 +21,7 @@ #include "proxy_internal.h" #include "xen_internal.h" #include "xend_internal.h" +#include "xs_internal.h" static int fdServer = -1; static int debug = 0; @@ -71,6 +72,11 @@ proxyInitXen(void) { fprintf(stderr, "Failed to connect to Xen daemon\n"); return(-1); } + ret = xenStoreOpen(conn, NULL, VIR_DRV_OPEN_QUIET | VIR_DRV_OPEN_RO); + if (ret < 0) { + fprintf(stderr, "Failed to open XenStore connection"); + return (-1); + } ret = xenDaemonGetVersion(conn, &xenVersion2); if (ret != 0) { fprintf(stderr, "Failed to get Xen daemon version\n"); @@ -331,6 +337,7 @@ proxyReadClientSocket(int nr) { virProxyFullPacket request; virProxyPacketPtr req = (virProxyPacketPtr) &request; int ret; + char *xml; retry: ret = read(pollInfos[nr].fd, req, sizeof(virProxyPacket)); @@ -559,6 +566,27 @@ retry2: req->len = sizeof(virProxyPacket) + sizeof(virNodeInfo); } break; + case VIR_PROXY_DOMAIN_XML: + if (req->len != sizeof(virProxyPacket)) + goto comm_error; + + xml = xenDaemonDomainDumpXMLByID(conn, request.data.arg); + if (!xml) { + req->data.arg = -1; + req->len = sizeof(virProxyPacket); + } else { + int xmllen = strlen(xml); + if (xmllen > sizeof(request.extra.str)) { + req->data.arg = -2; + req->len = sizeof(virProxyPacket); + } else { + req->data.arg = 0; + memmove(&request.extra.str[0], xml, xmllen); + req->len = sizeof(virProxyPacket) + xmllen; + } + free(xml); + } + break; default: goto comm_error; } diff --git a/src/driver.h b/src/driver.h index 8b7ad66b70..260914ecbc 100644 --- a/src/driver.h +++ b/src/driver.h @@ -104,6 +104,9 @@ typedef int typedef int (*virDrvDomainRestore) (virConnectPtr conn, const char *from); +typedef char * + (*virDrvDomainDumpXML) (virDomainPtr dom, + int flags); typedef int (*virDrvDomainSetVcpus) (virDomainPtr domain, @@ -164,6 +167,7 @@ struct _virDriver { virDrvDomainSetVcpus domainSetVcpus; virDrvDomainPinVcpu domainPinVcpu; virDrvDomainGetVcpus domainGetVcpus; + virDrvDomainDumpXML domainDumpXML; }; diff --git a/src/libvirt.c b/src/libvirt.c index 66580e89d9..47b3267902 100644 --- a/src/libvirt.c +++ b/src/libvirt.c @@ -1442,6 +1442,8 @@ virDomainGetInfo(virDomainPtr domain, virDomainInfoPtr info) char * virDomainGetXMLDesc(virDomainPtr domain, int flags) { + int i; + char *ret = NULL; if (!VIR_IS_DOMAIN(domain)) { virLibDomainError(domain, VIR_ERR_INVALID_DOMAIN, __FUNCTION__); return (NULL); @@ -1451,7 +1453,19 @@ virDomainGetXMLDesc(virDomainPtr domain, int flags) return (NULL); } - return (xenDaemonDomainDumpXML(domain)); + for (i = 0;i < domain->conn->nb_drivers;i++) { + if ((domain->conn->drivers[i] != NULL) && + (domain->conn->drivers[i]->domainDumpXML != NULL)) { + ret = domain->conn->drivers[i]->domainDumpXML(domain, flags); + if (ret) + break; + } + } + if (!ret) { + virLibConnError(domain->conn, VIR_ERR_CALL_FAILED, __FUNCTION__); + return (NULL); + } + return(ret); } /** diff --git a/src/proxy_internal.c b/src/proxy_internal.c index ad9d123c4f..df34c6fc59 100644 --- a/src/proxy_internal.c +++ b/src/proxy_internal.c @@ -39,6 +39,7 @@ static virDomainPtr xenProxyDomainLookupByName(virConnectPtr conn, const char *domname); static unsigned long xenProxyDomainGetMaxMemory(virDomainPtr domain); static int xenProxyDomainGetInfo(virDomainPtr domain, virDomainInfoPtr info); +static char *xenProxyDomainDumpXML(virDomainPtr domain, int flags); static virDriver xenProxyDriver = { VIR_DRV_XEN_PROXY, @@ -74,7 +75,8 @@ static virDriver xenProxyDriver = { NULL, /* domainRestore */ NULL, /* domainSetVcpus */ NULL, /* domainPinVcpu */ - NULL /* domainGetVcpus */ + NULL, /* domainGetVcpus */ + xenProxyDomainDumpXML, /* domainDumpXML */ }; /** @@ -927,3 +929,50 @@ xenProxyNodeGetInfo(virConnectPtr conn, virNodeInfoPtr info) { return(0); } +/** + * xenProxyDomainDumpXML: + * @domain: a domain object + * @flags: xml generation flags + * + * This method generates an XML description of a domain. + * + * Returns the XML document on success, NULL otherwise. + */ +static char * +xenProxyDomainDumpXML(virDomainPtr domain, int flags) +{ + virProxyPacket req; + virProxyFullPacket ans; + int ret; + int xmllen; + char *xml; + + if (!VIR_IS_CONNECTED_DOMAIN(domain)) { + if (domain == NULL) + virProxyError(NULL, VIR_ERR_INVALID_DOMAIN, __FUNCTION__); + else + virProxyError(domain->conn, VIR_ERR_INVALID_DOMAIN, __FUNCTION__); + return (NULL); + } + memset(&req, 0, sizeof(req)); + req.command = VIR_PROXY_DOMAIN_XML; + req.data.arg = domain->handle; + req.len = sizeof(req); + ret = xenProxyCommand(domain->conn, &req, &ans, 0); + if (ret < 0) { + xenProxyClose(domain->conn); + return(NULL); + } + if (ans.len <= sizeof(virProxyPacket)) { + virProxyError(domain->conn, VIR_ERR_OPERATION_FAILED, __FUNCTION__); + return (NULL); + } + xmllen = ans.len - sizeof(virProxyPacket); + if (!(xml = malloc(xmllen+1))) { + return NULL; + } + memmove(xml, &ans.extra.dinfo, xmllen); + xml[xmllen] = '\0'; + + return(xml); +} diff --git a/src/proxy_internal.h b/src/proxy_internal.h index bc8e5d8796..1e5940e259 100644 --- a/src/proxy_internal.h +++ b/src/proxy_internal.h @@ -34,7 +34,8 @@ typedef enum { VIR_PROXY_LOOKUP_UUID = 6, VIR_PROXY_LOOKUP_NAME = 7, VIR_PROXY_MAX_MEMORY = 8, - VIR_PROXY_DOMAIN_INFO = 9 + VIR_PROXY_DOMAIN_INFO = 9, + VIR_PROXY_DOMAIN_XML = 10, } virProxyCommand; /* diff --git a/src/test.c b/src/test.c index 7045269096..215d323d5a 100644 --- a/src/test.c +++ b/src/test.c @@ -50,7 +50,8 @@ static virDriver testDriver = { NULL, /* domainRestore */ NULL, /* domainSetVcpus */ NULL, /* domainPinVcpu */ - NULL /* domainGetVcpus */ + NULL, /* domainGetVcpus */ + NULL, /* domainDumpXML */ }; /* Amount of time it takes to shutdown */ diff --git a/src/xen_internal.c b/src/xen_internal.c index 68c3eabd8d..88cc1658b7 100644 --- a/src/xen_internal.c +++ b/src/xen_internal.c @@ -92,7 +92,8 @@ static virDriver xenHypervisorDriver = { NULL, /* domainRestore */ xenHypervisorSetVcpus, /* domainSetVcpus */ xenHypervisorPinVcpu, /* domainPinVcpu */ - xenHypervisorGetVcpus /* domainGetVcpus */ + xenHypervisorGetVcpus, /* domainGetVcpus */ + NULL, /* domainDumpXML */ }; #endif /* !PROXY */ @@ -686,6 +687,7 @@ xenHypervisorGetDomainInfo(virDomainPtr domain, virDomainInfoPtr info) } +#ifndef PROXY /** * xenHypervisorPauseDomain: * @domain: pointer to the domain block @@ -799,6 +801,7 @@ xenHypervisorSetMaxMemory(virDomainPtr domain, unsigned long memory) return (-1); return (0); } +#endif /* PROXY */ /** * xenHypervisorCheckID: @@ -848,6 +851,7 @@ xenHypervisorCheckID(virConnectPtr conn, int id) return (0); } +#ifndef PROXY /** * xenHypervisorSetVcpus: * @domain: pointer to domain object @@ -908,6 +912,7 @@ xenHypervisorPinVcpu(virDomainPtr domain, unsigned int vcpu, return (-1); return 0; } +#endif /** * virDomainGetVcpus: diff --git a/src/xend_internal.c b/src/xend_internal.c index 0e07054c92..bfe8f22636 100644 --- a/src/xend_internal.c +++ b/src/xend_internal.c @@ -47,7 +47,7 @@ static virDomainPtr xenDaemonLookupByUUID(virConnectPtr conn, static virDomainPtr xenDaemonCreateLinux(virConnectPtr conn, const char *xmlDesc, unsigned int flags); -#endif +#endif /* PROXY */ #ifndef PROXY static virDriver xenDaemonDriver = { @@ -86,7 +86,8 @@ static virDriver xenDaemonDriver = { xenDaemonDomainRestore, /* domainRestore */ xenDaemonDomainSetVcpus, /* domainSetVcpus */ xenDaemonDomainPinVcpu, /* domainPinVcpu */ - xenDaemonDomainGetVcpus /* domainGetVcpus */ + xenDaemonDomainGetVcpus, /* domainGetVcpus */ + xenDaemonDomainDumpXML, /* domainDumpXML */ }; /** @@ -445,6 +446,7 @@ xend_get(virConnectPtr xend, const char *path, return ret; } +#ifndef PROXY /** * xend_post: * @xend: pointer to the Xen Daemon structure @@ -495,6 +497,8 @@ xend_post(virConnectPtr xend, const char *path, const char *ops, return ret; } +#endif /* ! PROXY */ + /** * http2unix: @@ -525,6 +529,7 @@ http2unix(int ret) return -1; } +#ifndef PROXY /** * xend_op_ext2: * @xend: pointer to the Xen Daemon structure @@ -562,6 +567,7 @@ xend_op_ext2(virConnectPtr xend, const char *path, char *error, return http2unix(xend_post(xend, path, ops, error, n_error)); } + /** * xend_node_op: * @xend: pointer to the Xen Daemon structure @@ -587,6 +593,7 @@ xend_node_op(virConnectPtr xend, const char *path, const char *key, ...) return ret; } + /** * xend_node_op: * @xend: pointer to the Xen Daemon structure @@ -620,6 +627,7 @@ xend_op_ext(virConnectPtr xend, const char *name, char *error, } #define xend_op(xend, name, key, ...) ({char error[1024]; xend_op_ext(xend, name, error, sizeof(error), key, __VA_ARGS__);}) +#endif /* ! PROXY */ /** * sexpr_get: @@ -819,6 +827,7 @@ sexpr_uuid(char **ptr, struct sexpr *node, const char *path) } +#ifndef PROXY /** * urlencode: * @string: the input URL @@ -854,6 +863,7 @@ urlencode(const char *string) return buffer; } +#endif /* ! PROXY */ /* PUBLIC FUNCTIONS */ @@ -890,6 +900,7 @@ xenDaemonOpen_unix(virConnectPtr conn, const char *path) return (0); } +#ifndef PROXY /** * xenDaemonOpen_tcp: * @conn: an existing virtual connection block @@ -932,6 +943,7 @@ xenDaemonOpen_tcp(virConnectPtr conn, const char *host, int port) return (0); } + /** * xend_wait_for_devices: * @xend: pointer to the Xem Daemon block @@ -948,6 +960,7 @@ xend_wait_for_devices(virConnectPtr xend, const char *name) return xend_op(xend, name, "op", "wait_for_devices", NULL); } + /** * xend_rename: * @xend: pointer to the Xem Daemon block @@ -969,6 +982,7 @@ xend_rename(virConnectPtr xend, const char *old, const char *new) return xend_op(xend, old, "op", "rename", "name", new, NULL); } + /** * xend_sysrq: * @xend: pointer to the Xem Daemon block @@ -989,6 +1003,8 @@ xend_sysrq(virConnectPtr xend, const char *name, const char *key) } return xend_op(xend, name, "op", "sysrq", "key", key, NULL); } +#endif /* PROXY */ + /** * xenDaemonListDomainsOld: @@ -1047,6 +1063,7 @@ xenDaemonListDomainsOld(virConnectPtr xend) return ret; } +#ifndef PROXY /** * xenDaemonDomainCreateLinux: * @xend: A xend instance @@ -1083,6 +1100,7 @@ xenDaemonDomainCreateLinux(virConnectPtr xend, const char *sexpr) return ret; } +#endif /* ! PROXY */ /** * xenDaemonDomainLookupByName_ids: @@ -1275,6 +1293,7 @@ xend_get_node(virConnectPtr xend) return node; } +#ifndef PROXY /** * xend_node_shutdown: * @xend: A xend instance @@ -1303,6 +1322,7 @@ xend_node_restart(virConnectPtr xend) return xend_node_op(xend, "/xend/node/", "op", "restart", NULL); } + /** * xend_dmesg: * @xend: A xend instance @@ -1351,6 +1371,7 @@ xend_log(virConnectPtr xend, char *buffer, size_t n_buffer) { return http2unix(xend_get(xend, "/xend/node/log", buffer, n_buffer)); } +#endif /* PROXY */ /***************************************************************** ****** @@ -1363,7 +1384,6 @@ xend_log(virConnectPtr xend, char *buffer, size_t n_buffer) ****** ****** *****************************************************************/ -#ifndef PROXY /** * xend_parse_sexp_desc_os: @@ -1448,7 +1468,7 @@ xend_parse_sexp_desc_os(struct sexpr *node, virBufferPtr buf, int hvm) * the caller must free() the returned value. */ static char * -xend_parse_sexp_desc(virDomainPtr domain, struct sexpr *root) +xend_parse_sexp_desc(virConnectPtr conn, struct sexpr *root) { char *ret; struct sexpr *cur, *node; @@ -1456,6 +1476,7 @@ xend_parse_sexp_desc(virDomainPtr domain, struct sexpr *root) char *tty; virBuffer buf; int hvm = 0; + int domid = -1; if (root == NULL) { /* ERROR */ @@ -1468,8 +1489,9 @@ xend_parse_sexp_desc(virDomainPtr domain, struct sexpr *root) buf.size = 1000; buf.use = 0; - virBufferVSprintf(&buf, "\n", - sexpr_int(root, "domain/domid")); + domid = sexpr_int(root, "domain/domid"); + virBufferVSprintf(&buf, "\n", domid); + tmp = sexpr_node(root, "domain/name"); if (tmp == NULL) { virXendError(NULL, VIR_ERR_INTERNAL_ERROR, @@ -1607,9 +1629,9 @@ xend_parse_sexp_desc(virDomainPtr domain, struct sexpr *root) tmp = sexpr_node(root, "domain/image/hvm/vnc"); if (tmp != NULL) { if (tmp[0] == '1') { - int port = xenStoreDomainGetVNCPort(domain); + int port = xenStoreDomainGetVNCPort(conn, domid); if (port == -1) - port = 5900 + sexpr_int(root, "domain/domid"); + port = 5900 + domid; virBufferVSprintf(&buf, " \n", port); } } @@ -1626,7 +1648,7 @@ xend_parse_sexp_desc(virDomainPtr domain, struct sexpr *root) */ } - tty = xenStoreDomainGetConsolePath(domain); + tty = xenStoreDomainGetConsolePath(conn, domid); if (tty) { virBufferVSprintf(&buf, " \n", tty); free(tty); @@ -1643,7 +1665,7 @@ xend_parse_sexp_desc(virDomainPtr domain, struct sexpr *root) free(ret); return (NULL); } -#endif /* !PROXY */ + /** * sexpr_to_xend_domain_info: @@ -1873,7 +1895,7 @@ failed: xmlFreeURI(uri); return(-1); } -#endif /* !PROXY */ + /** * xenDaemonClose: @@ -2044,6 +2066,7 @@ xenDaemonDomainRestore(virConnectPtr conn, const char *filename) } return xend_op(conn, "", "op", "restore", "file", filename, NULL); } +#endif /* !PROXY */ /** * xenDaemonDomainGetMaxMemory: @@ -2076,6 +2099,7 @@ xenDaemonDomainGetMaxMemory(virDomainPtr domain) return(ret); } +#ifndef PROXY /** * xenDaemonDomainSetMaxMemory: * @domain: pointer to the Domain block @@ -2133,6 +2157,25 @@ xenDaemonDomainSetMemory(virDomainPtr domain, unsigned long memory) "target", buf, NULL); } +#endif /* ! PROXY */ + +char * +xenDaemonDomainDumpXMLByID(virConnectPtr conn, int domid) +{ + char *ret = NULL; + struct sexpr *root; + + root = sexpr_get(conn, "/xend/domain/%d?detail=1", domid); + if (root == NULL) + return (NULL); + + ret = xend_parse_sexp_desc(conn, root); + sexpr_free(root); + + return (ret); +} + + #ifndef PROXY /** * xenDaemonDomainDumpXML: @@ -2144,25 +2187,15 @@ xenDaemonDomainSetMemory(virDomainPtr domain, unsigned long memory) * the caller must free() the returned value. */ char * -xenDaemonDomainDumpXML(virDomainPtr domain) +xenDaemonDomainDumpXML(virDomainPtr domain, int flags) { - char *ret = NULL; - struct sexpr *root; - if ((domain == NULL) || (domain->conn == NULL) || (domain->name == NULL)) { virXendError((domain ? domain->conn : NULL), VIR_ERR_INVALID_ARG, __FUNCTION__); return(NULL); } - root = sexpr_get(domain->conn, "/xend/domain/%s?detail=1", domain->name); - if (root == NULL) - return (NULL); - - ret = xend_parse_sexp_desc(domain, root); - sexpr_free(root); - - return (ret); + return xenDaemonDomainDumpXMLByID(domain->conn, domain->handle); } #endif /* !PROXY */ @@ -2231,7 +2264,7 @@ error: sexpr_free(root); return(ret); } -#endif +#endif /* ! PROXY */ /** * xenDaemonNodeGetInfo: @@ -2285,7 +2318,7 @@ xenDaemonGetType(virConnectPtr conn) } return("XenDaemon"); } -#endif +#endif /* ! PROXY */ /** * xenDaemonGetVersion: @@ -2414,7 +2447,7 @@ error: sexpr_free(root); return(ret); } -#endif +#endif /* ! PROXY */ #ifndef PROXY /** @@ -2734,6 +2767,5 @@ xenDaemonCreateLinux(virConnectPtr conn, const char *xmlDesc, free(name); return (NULL); } - -#endif +#endif /* ! PROXY */ diff --git a/src/xend_internal.h b/src/xend_internal.h index 2103ded214..5b7f05df3c 100644 --- a/src/xend_internal.h +++ b/src/xend_internal.h @@ -548,6 +548,9 @@ int xenDaemonDomainLookupByID(virConnectPtr xend, char **name, unsigned char *uuid); +char *xenDaemonDomainDumpXMLByID(virConnectPtr xend, + int domid); + /** * \brief Lookup information about the host machine * \param xend A xend instance @@ -626,7 +629,7 @@ int xenDaemonDomainRestore(virConnectPtr conn, const char *filename); int xenDaemonDomainSetMemory(virDomainPtr domain, unsigned long memory); int xenDaemonDomainSetMaxMemory(virDomainPtr domain, unsigned long memory); int xenDaemonDomainGetInfo(virDomainPtr domain, virDomainInfoPtr info); -char *xenDaemonDomainDumpXML(virDomainPtr domain); +char *xenDaemonDomainDumpXML(virDomainPtr domain, int flags); virDomainPtr xenDaemonDomainLookupByName(virConnectPtr conn, const char *domname); unsigned long xenDaemonDomainGetMaxMemory(virDomainPtr domain); char **xenDaemonListDomainsOld(virConnectPtr xend); diff --git a/src/xml.c b/src/xml.c index f01ec77409..e4fccd1a75 100644 --- a/src/xml.c +++ b/src/xml.c @@ -562,6 +562,7 @@ virDomainGetXMLDesc(virDomainPtr domain, int flags) #endif +#ifndef PROXY /** * virDomainParseXMLOSDescHVM: * @node: node containing HVM OS description @@ -1140,3 +1141,5 @@ virDomainParseXMLDesc(const char *xmldesc, char **name) free(ret); return (NULL); } + +#endif /* !PROXY */ diff --git a/src/xs_internal.c b/src/xs_internal.c index b0c3d67b37..6a5ea03829 100644 --- a/src/xs_internal.c +++ b/src/xs_internal.c @@ -31,6 +31,7 @@ #define XEN_HYPERVISOR_SOCKET "/proc/xen/privcmd" +#ifndef PROXY static virDriver xenStoreDriver = { VIR_DRV_XEN_STORE, "XenStore", @@ -67,7 +68,8 @@ static virDriver xenStoreDriver = { NULL, /* domainRestore */ NULL, /* domainSetVcpus */ NULL, /* domainPinVcpu */ - NULL /* domainGetVcpus */ + NULL, /* domainGetVcpus */ + NULL, /* domainDumpXML */ }; /** @@ -79,6 +81,7 @@ void xenStoreRegister(void) { virRegisterDriver(&xenStoreDriver); } +#endif /* ! PROXY */ /** * virXenStoreError: @@ -106,6 +109,7 @@ virXenStoreError(virConnectPtr conn, virErrorNumber error, const char *info) * Helper internal APIs * * * ************************************************************************/ +#ifndef PROXY /** * virConnectDoStoreList: * @conn: pointer to the hypervisor connection @@ -126,10 +130,12 @@ virConnectDoStoreList(virConnectPtr conn, const char *path, return xs_directory(conn->xshandle, 0, path, nb); } +#endif /* ! PROXY */ /** * virDomainDoStoreQuery: - * @domain: a domain object + * @conn: pointer to the hypervisor connection + * @domid: id of the domain * @path: the relative path of the data in the store to retrieve * * Internal API querying the Xenstore for a string value. @@ -137,23 +143,21 @@ virConnectDoStoreList(virConnectPtr conn, const char *path, * Returns a string which must be freed by the caller or NULL in case of error */ static char * -virDomainDoStoreQuery(virDomainPtr domain, const char *path) +virDomainDoStoreQuery(virConnectPtr conn, int domid, const char *path) { char s[256]; unsigned int len = 0; - if (!VIR_IS_CONNECTED_DOMAIN(domain)) - return (NULL); - if (domain->conn->xshandle == NULL) + if (conn->xshandle == NULL) return (NULL); - snprintf(s, 255, "/local/domain/%d/%s", domain->handle, path); + snprintf(s, 255, "/local/domain/%d/%s", domid, path); s[255] = 0; - return xs_read(domain->conn->xshandle, 0, &s[0], &len); + return xs_read(conn->xshandle, 0, &s[0], &len); } - +#ifndef PROXY /** * virDomainDoStoreWrite: * @domain: a domain object @@ -269,6 +273,7 @@ virConnectCheckStoreID(virConnectPtr conn, int id) } return (0); } +#endif /* ! PROXY */ /************************************************************************ * * @@ -291,10 +296,14 @@ xenStoreOpen(virConnectPtr conn, const char *name, int flags) if ((name != NULL) && (strcasecmp(name, "xen"))) return(-1); +#ifdef PROXY + conn->xshandle = xs_daemon_open_readonly(); +#else if (flags & VIR_DRV_OPEN_RO) conn->xshandle = xs_daemon_open_readonly(); else conn->xshandle = xs_daemon_open(); +#endif /* ! PROXY */ if (conn->xshandle == NULL) { if (!(flags & VIR_DRV_OPEN_QUIET)) @@ -327,6 +336,7 @@ xenStoreClose(virConnectPtr conn) return (0); } +#ifndef PROXY /** * xenStoreGetDomainInfo: * @domain: pointer to the domain block @@ -343,6 +353,9 @@ xenStoreGetDomainInfo(virDomainPtr domain, virDomainInfoPtr info) unsigned int nb_vcpus; char request[200]; + if (!VIR_IS_CONNECTED_DOMAIN(domain)) + return (-1); + if ((domain == NULL) || (domain->conn == NULL) || (info == NULL)) { virXenStoreError(domain ? domain->conn : NULL, VIR_ERR_INVALID_ARG, __FUNCTION__); @@ -351,7 +364,7 @@ xenStoreGetDomainInfo(virDomainPtr domain, virDomainInfoPtr info) if (domain->conn->xshandle == NULL) return(-1); - tmp = virDomainDoStoreQuery(domain, "running"); + tmp = virDomainDoStoreQuery(domain->conn, domain->handle, "running"); if (tmp != NULL) { if (tmp[0] == '1') info->state = VIR_DOMAIN_RUNNING; @@ -359,7 +372,7 @@ xenStoreGetDomainInfo(virDomainPtr domain, virDomainInfoPtr info) } else { info->state = VIR_DOMAIN_NONE; } - tmp = virDomainDoStoreQuery(domain, "memory/target"); + tmp = virDomainDoStoreQuery(domain->conn, domain->handle, "memory/target"); if (tmp != NULL) { info->memory = atol(tmp); info->maxMem = atol(tmp); @@ -370,7 +383,7 @@ xenStoreGetDomainInfo(virDomainPtr domain, virDomainInfoPtr info) } #if 0 /* doesn't seems to work */ - tmp = virDomainDoStoreQuery(domain, "cpu_time"); + tmp = virDomainDoStoreQuery(domain->conn, domain->handle, "cpu_time"); if (tmp != NULL) { info->cpuTime = atol(tmp); free(tmp); @@ -430,7 +443,10 @@ xenStoreDomainGetMaxMemory(virDomainPtr domain) char *tmp; unsigned long ret = 0; - tmp = virDomainDoStoreQuery(domain, "memory/target"); + if (!VIR_IS_CONNECTED_DOMAIN(domain)) + return (ret); + + tmp = virDomainDoStoreQuery(domain->conn, domain->handle, "memory/target"); if (tmp != NULL) { ret = (unsigned long) atol(tmp); free(tmp); @@ -629,21 +645,23 @@ xenStoreDomainReboot(virDomainPtr domain, unsigned int flags ATTRIBUTE_UNUSED) */ return(virDomainDoStoreWrite(domain, "control/shutdown", "reboot")); } +#endif /* ! PROXY */ /** * xenStoreDomainGetVNCPort: - * @domain: pointer to the domain block + * @conn: the hypervisor connection + * @domid: id of the domain * * Return the port number on which the domain is listening for VNC * connections. * * Returns the port number, -1 in case of error */ -int xenStoreDomainGetVNCPort(virDomainPtr domain) { +int xenStoreDomainGetVNCPort(virConnectPtr conn, int domid) { char *tmp; int ret = -1; - tmp = virDomainDoStoreQuery(domain, "console/vnc-port"); + tmp = virDomainDoStoreQuery(conn, domid, "console/vnc-port"); if (tmp != NULL) { char *end; ret = strtol(tmp, &end, 10); @@ -656,7 +674,8 @@ int xenStoreDomainGetVNCPort(virDomainPtr domain) { /** * xenStoreDomainGetConsolePath: - * @domain: pointer to the domain block + * @conn: the hypervisor connection + * @domid: id of the domain * * Return the path to the psuedo TTY on which the guest domain's * serial console is attached. @@ -665,6 +684,6 @@ int xenStoreDomainGetVNCPort(virDomainPtr domain) { * responsibilty to free() the return string. Returns NULL * on error */ -char * xenStoreDomainGetConsolePath(virDomainPtr domain) { - return virDomainDoStoreQuery(domain, "console/tty"); +char * xenStoreDomainGetConsolePath(virConnectPtr conn, int domid) { + return virDomainDoStoreQuery(conn, domid, "console/tty"); } diff --git a/src/xs_internal.h b/src/xs_internal.h index 2e4f4a4802..ff33357c1c 100644 --- a/src/xs_internal.h +++ b/src/xs_internal.h @@ -35,8 +35,9 @@ unsigned long xenStoreDomainGetMaxMemory(virDomainPtr domain); int xenStoreDomainShutdown (virDomainPtr domain); int xenStoreDomainReboot (virDomainPtr domain, unsigned int flags); -int xenStoreDomainGetVNCPort(virDomainPtr domain); -char * xenStoreDomainGetConsolePath(virDomainPtr domain); + +int xenStoreDomainGetVNCPort(virConnectPtr conn, int domid); +char * xenStoreDomainGetConsolePath(virConnectPtr conn, int domid); #ifdef __cplusplus }