[Libvir] Add port number to <graphics> tag

Daniel P. Berrange berrange at redhat.com
Tue Aug 8 22:04:44 UTC 2006


On Mon, Aug 07, 2006 at 12:11:17PM -0400, Daniel Veillard wrote:
> The XML dump should go though the proxy too for non-root that's something

Attached is a patch which adds support for XML dump to the proxy. This 
code only works if XML doc is < 4k, but I don;t anticpate this being
a problem. While doing this I also added a tonne more #ifndef PROXY
statements around functions in xend_internal.c since there were a lot
of potentially dangerous functions being compiled into the proxy even
though they were not called. I've run 'nm' on the .o files linked by
the proxy and it looks to have cut down the list of functions quite
significantly.

Regards,
Dan.
-- 
|=- Red Hat, Engineering, Emerging Technologies, Boston.  +1 978 392 2496 -=|
|=-           Perl modules: http://search.cpan.org/~danberr/              -=|
|=-               Projects: http://freshmeat.net/~danielpb/               -=|
|=-  GnuPG: 7D3B9505   F3C9 553F A1DA 4AC2 5648 23C1 B3DF F742 7D3B 9505  -=| 
-------------- next part --------------
? COPYING
? build.log
Index: proxy/Makefile.am
===================================================================
RCS file: /data/cvs/libvirt/proxy/Makefile.am,v
retrieving revision 1.5
diff -c -r1.5 Makefile.am
*** proxy/Makefile.am	20 Jul 2006 13:59:23 -0000	1.5
--- proxy/Makefile.am	8 Aug 2006 22:53:54 -0000
***************
*** 6,16 ****
  
  
  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
  libvirt_proxy_LDFLAGS =
  libvirt_proxy_DEPENDENCIES =
  libvirt_proxy_LDADD =
--- 6,16 ----
  
  
  libexec_PROGRAMS = libvirt_proxy
  
  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/xml.c \
!             @top_srcdir@/src/xs_internal.c
  libvirt_proxy_LDFLAGS =
  libvirt_proxy_DEPENDENCIES =
  libvirt_proxy_LDADD =
Index: proxy/libvirt_proxy.c
===================================================================
RCS file: /data/cvs/libvirt/proxy/libvirt_proxy.c,v
retrieving revision 1.7
diff -c -r1.7 libvirt_proxy.c
*** proxy/libvirt_proxy.c	7 Jul 2006 18:58:35 -0000	1.7
--- proxy/libvirt_proxy.c	8 Aug 2006 22:53:55 -0000
***************
*** 21,26 ****
--- 21,27 ----
  #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,76 ****
--- 72,82 ----
          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,336 ****
--- 337,343 ----
      virProxyFullPacket request;
      virProxyPacketPtr req = (virProxyPacketPtr) &request;
      int ret;
+     char *xml;
  
  retry:
      ret = read(pollInfos[nr].fd, req, sizeof(virProxyPacket));
***************
*** 559,564 ****
--- 566,592 ----
  		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;
      }
Index: src/driver.h
===================================================================
RCS file: /data/cvs/libvirt/src/driver.h,v
retrieving revision 1.10
diff -c -r1.10 driver.h
*** src/driver.h	8 Aug 2006 22:22:55 -0000	1.10
--- src/driver.h	8 Aug 2006 22:53:55 -0000
***************
*** 104,109 ****
--- 104,112 ----
  typedef int
  	(*virDrvDomainRestore)		(virConnectPtr conn,
  					 const char *from);
+ typedef char *
+ 	(*virDrvDomainDumpXML)		(virDomainPtr dom,
+ 					 int flags);
  
  typedef int
  	(*virDrvDomainSetVcpus)		(virDomainPtr domain,
***************
*** 164,169 ****
--- 167,173 ----
  	virDrvDomainSetVcpus		domainSetVcpus;
  	virDrvDomainPinVcpu		domainPinVcpu;
  	virDrvDomainGetVcpus		domainGetVcpus;
+ 	virDrvDomainDumpXML		domainDumpXML;
  };
  
  
Index: src/libvirt.c
===================================================================
RCS file: /data/cvs/libvirt/src/libvirt.c,v
retrieving revision 1.40
diff -c -r1.40 libvirt.c
*** src/libvirt.c	8 Aug 2006 22:22:55 -0000	1.40
--- src/libvirt.c	8 Aug 2006 22:53:56 -0000
***************
*** 1442,1447 ****
--- 1442,1449 ----
  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,1457 ****
          return (NULL);
      }
  
!     return (xenDaemonDomainDumpXML(domain));
  }
  
  /**
--- 1453,1471 ----
          return (NULL);
      }
  
!     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);
  }
  
  /**
Index: src/proxy_internal.c
===================================================================
RCS file: /data/cvs/libvirt/src/proxy_internal.c,v
retrieving revision 1.7
diff -c -r1.7 proxy_internal.c
*** src/proxy_internal.c	8 Aug 2006 22:22:55 -0000	1.7
--- src/proxy_internal.c	8 Aug 2006 22:53:56 -0000
***************
*** 39,44 ****
--- 39,45 ----
  					       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,80 ****
      NULL, /* domainRestore */
      NULL, /* domainSetVcpus */
      NULL, /* domainPinVcpu */
!     NULL /* domainGetVcpus */
  };
  
  /**
--- 75,82 ----
      NULL, /* domainRestore */
      NULL, /* domainSetVcpus */
      NULL, /* domainPinVcpu */
!     NULL, /* domainGetVcpus */
!     xenProxyDomainDumpXML, /* domainDumpXML */
  };
  
  /**
***************
*** 927,929 ****
--- 929,978 ----
      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);
+ }
Index: src/proxy_internal.h
===================================================================
RCS file: /data/cvs/libvirt/src/proxy_internal.h,v
retrieving revision 1.3
diff -c -r1.3 proxy_internal.h
*** src/proxy_internal.h	19 Jul 2006 22:24:37 -0000	1.3
--- src/proxy_internal.h	8 Aug 2006 22:53:56 -0000
***************
*** 34,40 ****
  	VIR_PROXY_LOOKUP_UUID = 6,
  	VIR_PROXY_LOOKUP_NAME = 7,
  	VIR_PROXY_MAX_MEMORY = 8,
! 	VIR_PROXY_DOMAIN_INFO = 9
  } virProxyCommand;
  
  /*
--- 34,41 ----
  	VIR_PROXY_LOOKUP_UUID = 6,
  	VIR_PROXY_LOOKUP_NAME = 7,
  	VIR_PROXY_MAX_MEMORY = 8,
! 	VIR_PROXY_DOMAIN_INFO = 9,
! 	VIR_PROXY_DOMAIN_XML = 10,
  } virProxyCommand;
  
  /*
Index: src/test.c
===================================================================
RCS file: /data/cvs/libvirt/src/test.c,v
retrieving revision 1.5
diff -c -r1.5 test.c
*** src/test.c	8 Aug 2006 22:22:55 -0000	1.5
--- src/test.c	8 Aug 2006 22:53:56 -0000
***************
*** 50,56 ****
    NULL, /* domainRestore */
    NULL, /* domainSetVcpus */
    NULL, /* domainPinVcpu */
!   NULL /* domainGetVcpus */
  };
  
  /* Amount of time it takes to shutdown */
--- 50,57 ----
    NULL, /* domainRestore */
    NULL, /* domainSetVcpus */
    NULL, /* domainPinVcpu */
!   NULL, /* domainGetVcpus */
!   NULL, /* domainDumpXML */
  };
  
  /* Amount of time it takes to shutdown */
Index: src/xen_internal.c
===================================================================
RCS file: /data/cvs/libvirt/src/xen_internal.c,v
retrieving revision 1.31
diff -c -r1.31 xen_internal.c
*** src/xen_internal.c	8 Aug 2006 22:22:55 -0000	1.31
--- src/xen_internal.c	8 Aug 2006 22:53:57 -0000
***************
*** 92,98 ****
      NULL, /* domainRestore */
      xenHypervisorSetVcpus, /* domainSetVcpus */
      xenHypervisorPinVcpu, /* domainPinVcpu */
!     xenHypervisorGetVcpus /* domainGetVcpus */
  };
  #endif /* !PROXY */
  
--- 92,99 ----
      NULL, /* domainRestore */
      xenHypervisorSetVcpus, /* domainSetVcpus */
      xenHypervisorPinVcpu, /* domainPinVcpu */
!     xenHypervisorGetVcpus, /* domainGetVcpus */
!     NULL, /* domainDumpXML */
  };
  #endif /* !PROXY */
  
***************
*** 686,691 ****
--- 687,693 ----
  
  }
  
+ #ifndef PROXY
  /**
   * xenHypervisorPauseDomain:
   * @domain: pointer to the domain block
***************
*** 799,804 ****
--- 801,807 ----
          return (-1);
      return (0);
  }
+ #endif /* PROXY */
  
  /**
   * xenHypervisorCheckID:
***************
*** 848,853 ****
--- 851,857 ----
      return (0);
  }
  
+ #ifndef PROXY
  /**
   * xenHypervisorSetVcpus:
   * @domain: pointer to domain object
***************
*** 908,913 ****
--- 912,918 ----
          return (-1);
      return 0;
  }
+ #endif
  
  /**
   * virDomainGetVcpus:
Index: src/xend_internal.c
===================================================================
RCS file: /data/cvs/libvirt/src/xend_internal.c,v
retrieving revision 1.51
diff -c -r1.51 xend_internal.c
*** src/xend_internal.c	8 Aug 2006 22:22:55 -0000	1.51
--- src/xend_internal.c	8 Aug 2006 22:53:58 -0000
***************
*** 47,53 ****
  static virDomainPtr xenDaemonCreateLinux(virConnectPtr conn,
                                           const char *xmlDesc,
  					 unsigned int flags);
! #endif
  
  #ifndef PROXY
  static virDriver xenDaemonDriver = {
--- 47,53 ----
  static virDomainPtr xenDaemonCreateLinux(virConnectPtr conn,
                                           const char *xmlDesc,
  					 unsigned int flags);
! #endif /* PROXY */
  
  #ifndef PROXY
  static virDriver xenDaemonDriver = {
***************
*** 86,92 ****
      xenDaemonDomainRestore, /* domainRestore */
      xenDaemonDomainSetVcpus, /* domainSetVcpus */
      xenDaemonDomainPinVcpu, /* domainPinVcpu */
!     xenDaemonDomainGetVcpus /* domainGetVcpus */
  };
  
  /**
--- 86,93 ----
      xenDaemonDomainRestore, /* domainRestore */
      xenDaemonDomainSetVcpus, /* domainSetVcpus */
      xenDaemonDomainPinVcpu, /* domainPinVcpu */
!     xenDaemonDomainGetVcpus, /* domainGetVcpus */
!     xenDaemonDomainDumpXML, /* domainDumpXML */
  };
  
  /**
***************
*** 445,450 ****
--- 446,452 ----
      return ret;
  }
  
+ #ifndef PROXY
  /**
   * xend_post:
   * @xend: pointer to the Xen Daemon structure
***************
*** 495,500 ****
--- 497,504 ----
  
      return ret;
  }
+ #endif /* ! PROXY */
+ 
  
  /**
   * http2unix:
***************
*** 525,530 ****
--- 529,535 ----
      return -1;
  }
  
+ #ifndef PROXY
  /**
   * xend_op_ext2:
   * @xend: pointer to the Xen Daemon structure
***************
*** 562,567 ****
--- 567,573 ----
      return http2unix(xend_post(xend, path, ops, error, n_error));
  }
  
+ 
  /**
   * xend_node_op:
   * @xend: pointer to the Xen Daemon structure
***************
*** 587,592 ****
--- 593,599 ----
      return ret;
  }
  
+ 
  /**
   * xend_node_op:
   * @xend: pointer to the Xen Daemon structure
***************
*** 620,625 ****
--- 627,633 ----
  }
  
  #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,824 ****
--- 827,833 ----
  }
  
  
+ #ifndef PROXY
  /**
   * urlencode:
   * @string: the input URL
***************
*** 854,859 ****
--- 863,869 ----
  
      return buffer;
  }
+ #endif /* ! PROXY */
  
  /* PUBLIC FUNCTIONS */
  
***************
*** 890,895 ****
--- 900,906 ----
      return (0);
  }
  
+ #ifndef PROXY
  /**
   * xenDaemonOpen_tcp:
   * @conn: an existing virtual connection block
***************
*** 932,937 ****
--- 943,949 ----
      return (0);
  }
  
+ 
  /**
   * xend_wait_for_devices:
   * @xend: pointer to the Xem Daemon block
***************
*** 948,953 ****
--- 960,966 ----
      return xend_op(xend, name, "op", "wait_for_devices", NULL);
  }
  
+ 
  /**
   * xend_rename:
   * @xend: pointer to the Xem Daemon block
***************
*** 969,974 ****
--- 982,988 ----
      return xend_op(xend, old, "op", "rename", "name", new, NULL);
  }
  
+ 
  /**
   * xend_sysrq:
   * @xend: pointer to the Xem Daemon block
***************
*** 989,994 ****
--- 1003,1010 ----
      }
      return xend_op(xend, name, "op", "sysrq", "key", key, NULL);
  }
+ #endif /* PROXY */
+ 
  
  /**
   * xenDaemonListDomainsOld:
***************
*** 1047,1052 ****
--- 1063,1069 ----
      return ret;
  }
  
+ #ifndef PROXY
  /**
   * xenDaemonDomainCreateLinux:
   * @xend: A xend instance
***************
*** 1083,1088 ****
--- 1100,1106 ----
  
      return ret;
  }
+ #endif /* ! PROXY */
  
  /**
   * xenDaemonDomainLookupByName_ids:
***************
*** 1275,1280 ****
--- 1293,1299 ----
      return node;
  }
  
+ #ifndef PROXY
  /**
   * xend_node_shutdown:
   * @xend: A xend instance
***************
*** 1303,1308 ****
--- 1322,1328 ----
      return xend_node_op(xend, "/xend/node/", "op", "restart", NULL);
  }
  
+ 
  /**
   * xend_dmesg:
   * @xend: A xend instance
***************
*** 1351,1356 ****
--- 1371,1377 ----
  {
      return http2unix(xend_get(xend, "/xend/node/log", buffer, n_buffer));
  }
+ #endif /* PROXY */
  
  /*****************************************************************
   ******
***************
*** 1363,1369 ****
   ******
   ******
   *****************************************************************/
- #ifndef PROXY
  
  /**
   * xend_parse_sexp_desc_os:
--- 1384,1389 ----
***************
*** 1448,1454 ****
   *         the caller must free() the returned value.
   */
  static char *
! xend_parse_sexp_desc(virDomainPtr domain, struct sexpr *root)
  {
      char *ret;
      struct sexpr *cur, *node;
--- 1468,1474 ----
   *         the caller must free() the returned value.
   */
  static char *
! xend_parse_sexp_desc(virConnectPtr conn, struct sexpr *root)
  {
      char *ret;
      struct sexpr *cur, *node;
***************
*** 1456,1461 ****
--- 1476,1482 ----
      char *tty;
      virBuffer buf;
      int hvm = 0;
+     int domid = -1;
  
      if (root == NULL) {
          /* ERROR */
***************
*** 1468,1475 ****
      buf.size = 1000;
      buf.use = 0;
  
!     virBufferVSprintf(&buf, "<domain type='xen' id='%d'>\n",
!                       sexpr_int(root, "domain/domid"));
      tmp = sexpr_node(root, "domain/name");
      if (tmp == NULL) {
          virXendError(NULL, VIR_ERR_INTERNAL_ERROR,
--- 1489,1497 ----
      buf.size = 1000;
      buf.use = 0;
  
!     domid = sexpr_int(root, "domain/domid");
!     virBufferVSprintf(&buf, "<domain type='xen' id='%d'>\n", domid);
!                       
      tmp = sexpr_node(root, "domain/name");
      if (tmp == NULL) {
          virXendError(NULL, VIR_ERR_INTERNAL_ERROR,
***************
*** 1607,1615 ****
          tmp = sexpr_node(root, "domain/image/hvm/vnc");
          if (tmp != NULL) {
              if (tmp[0] == '1') {
!                 int port = xenStoreDomainGetVNCPort(domain);
                  if (port == -1) 
!                     port = 5900 + sexpr_int(root, "domain/domid");
                  virBufferVSprintf(&buf, "    <graphics type='vnc' port='%d'/>\n", port);
              }
          }
--- 1629,1637 ----
          tmp = sexpr_node(root, "domain/image/hvm/vnc");
          if (tmp != NULL) {
              if (tmp[0] == '1') {
!                 int port = xenStoreDomainGetVNCPort(conn, domid);
                  if (port == -1) 
!                     port = 5900 + domid;
                  virBufferVSprintf(&buf, "    <graphics type='vnc' port='%d'/>\n", port);
              }
          }
***************
*** 1626,1632 ****
           */
      }
      
!     tty = xenStoreDomainGetConsolePath(domain);
      if (tty) {
          virBufferVSprintf(&buf, "    <console tty='%s'/>\n", tty);
          free(tty);
--- 1648,1654 ----
           */
      }
      
!     tty = xenStoreDomainGetConsolePath(conn, domid);
      if (tty) {
          virBufferVSprintf(&buf, "    <console tty='%s'/>\n", tty);
          free(tty);
***************
*** 1643,1649 ****
          free(ret);
      return (NULL);
  }
! #endif /* !PROXY */
  
  /**
   * sexpr_to_xend_domain_info:
--- 1665,1671 ----
          free(ret);
      return (NULL);
  }
! 
  
  /**
   * sexpr_to_xend_domain_info:
***************
*** 1873,1879 ****
          xmlFreeURI(uri);
      return(-1);
  }
! #endif /* !PROXY */
  
  /**
   * xenDaemonClose:
--- 1895,1901 ----
          xmlFreeURI(uri);
      return(-1);
  }
! 
  
  /**
   * xenDaemonClose:
***************
*** 2044,2049 ****
--- 2066,2072 ----
      }
      return xend_op(conn, "", "op", "restore", "file", filename, NULL);
  }
+ #endif /* !PROXY */
  
  /**
   * xenDaemonDomainGetMaxMemory:
***************
*** 2076,2081 ****
--- 2099,2105 ----
      return(ret);
  }
  
+ #ifndef PROXY
  /**
   * xenDaemonDomainSetMaxMemory:
   * @domain: pointer to the Domain block
***************
*** 2133,2138 ****
--- 2157,2181 ----
                     "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,2168 ****
   *         the caller must free() the returned value.
   */
  char *
! xenDaemonDomainDumpXML(virDomainPtr domain)
  {
-     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);
  }
  #endif /* !PROXY */
  
--- 2187,2201 ----
   *         the caller must free() the returned value.
   */
  char *
! xenDaemonDomainDumpXML(virDomainPtr domain, int flags)
  {
      if ((domain == NULL) || (domain->conn == NULL) || (domain->name == NULL)) {
          virXendError((domain ? domain->conn : NULL), VIR_ERR_INVALID_ARG,
  	             __FUNCTION__);
          return(NULL);
      }
  
!     return xenDaemonDomainDumpXMLByID(domain->conn, domain->handle);
  }
  #endif /* !PROXY */
  
***************
*** 2231,2237 ****
      sexpr_free(root);
      return(ret);
  }
! #endif
  
  /**
   * xenDaemonNodeGetInfo:
--- 2264,2270 ----
      sexpr_free(root);
      return(ret);
  }
! #endif /* ! PROXY */
  
  /**
   * xenDaemonNodeGetInfo:
***************
*** 2285,2291 ****
      }
      return("XenDaemon");
  }
! #endif
  
  /**
   * xenDaemonGetVersion:
--- 2318,2324 ----
      }
      return("XenDaemon");
  }
! #endif /* ! PROXY */
  
  /**
   * xenDaemonGetVersion:
***************
*** 2414,2420 ****
  	sexpr_free(root);
      return(ret);
  }
! #endif
  
  #ifndef PROXY
  /**
--- 2447,2453 ----
  	sexpr_free(root);
      return(ret);
  }
! #endif /* ! PROXY */
  
  #ifndef PROXY
  /**
***************
*** 2734,2739 ****
          free(name);
      return (NULL);
  }
! 
! #endif
  
--- 2767,2771 ----
          free(name);
      return (NULL);
  }
! #endif /* ! PROXY */
  
Index: src/xend_internal.h
===================================================================
RCS file: /data/cvs/libvirt/src/xend_internal.h,v
retrieving revision 1.23
diff -c -r1.23 xend_internal.h
*** src/xend_internal.h	8 Aug 2006 22:22:55 -0000	1.23
--- src/xend_internal.h	8 Aug 2006 22:53:58 -0000
***************
*** 548,553 ****
--- 548,556 ----
  			      char **name, unsigned char *uuid);
  
  
+ char *xenDaemonDomainDumpXMLByID(virConnectPtr xend,
+ 				 int domid);
+ 
  /**
   * \brief Lookup information about the host machine
   * \param xend A xend instance
***************
*** 626,632 ****
  int xenDaemonDomainSetMemory(virDomainPtr domain, unsigned long memory);
  int xenDaemonDomainSetMaxMemory(virDomainPtr domain, unsigned long memory);
  int xenDaemonDomainGetInfo(virDomainPtr domain, virDomainInfoPtr info);
! char *xenDaemonDomainDumpXML(virDomainPtr domain);
  virDomainPtr xenDaemonDomainLookupByName(virConnectPtr conn, const char *domname);
  unsigned long xenDaemonDomainGetMaxMemory(virDomainPtr domain);
  char **xenDaemonListDomainsOld(virConnectPtr xend);
--- 629,635 ----
  int xenDaemonDomainSetMemory(virDomainPtr domain, unsigned long memory);
  int xenDaemonDomainSetMaxMemory(virDomainPtr domain, unsigned long memory);
  int xenDaemonDomainGetInfo(virDomainPtr domain, virDomainInfoPtr info);
! char *xenDaemonDomainDumpXML(virDomainPtr domain, int flags);
  virDomainPtr xenDaemonDomainLookupByName(virConnectPtr conn, const char *domname);
  unsigned long xenDaemonDomainGetMaxMemory(virDomainPtr domain);
  char **xenDaemonListDomainsOld(virConnectPtr xend);
Index: src/xml.c
===================================================================
RCS file: /data/cvs/libvirt/src/xml.c,v
retrieving revision 1.29
diff -c -r1.29 xml.c
*** src/xml.c	8 Aug 2006 22:22:55 -0000	1.29
--- src/xml.c	8 Aug 2006 22:53:59 -0000
***************
*** 562,567 ****
--- 562,568 ----
  
  #endif
  
+ #ifndef PROXY
  /**
   * virDomainParseXMLOSDescHVM:
   * @node: node containing HVM OS description
***************
*** 1140,1142 ****
--- 1141,1145 ----
          free(ret);
      return (NULL);
  }
+ 
+ #endif /* !PROXY */
Index: src/xs_internal.c
===================================================================
RCS file: /data/cvs/libvirt/src/xs_internal.c,v
retrieving revision 1.14
diff -c -r1.14 xs_internal.c
*** src/xs_internal.c	8 Aug 2006 22:22:55 -0000	1.14
--- src/xs_internal.c	8 Aug 2006 22:53:59 -0000
***************
*** 31,36 ****
--- 31,37 ----
  
  #define XEN_HYPERVISOR_SOCKET "/proc/xen/privcmd"
  
+ #ifndef PROXY
  static virDriver xenStoreDriver = {
      VIR_DRV_XEN_STORE,
      "XenStore",
***************
*** 67,73 ****
      NULL, /* domainRestore */
      NULL, /* domainSetVcpus */
      NULL, /* domainPinVcpu */
!     NULL /* domainGetVcpus */
  };
  
  /**
--- 68,75 ----
      NULL, /* domainRestore */
      NULL, /* domainSetVcpus */
      NULL, /* domainPinVcpu */
!     NULL, /* domainGetVcpus */
!     NULL, /* domainDumpXML */
  };
  
  /**
***************
*** 79,84 ****
--- 81,87 ----
  {
      virRegisterDriver(&xenStoreDriver);
  }
+ #endif /* ! PROXY */
  
  /**
   * virXenStoreError:
***************
*** 106,111 ****
--- 109,115 ----
   *		Helper internal APIs					*
   *									*
   ************************************************************************/
+ #ifndef PROXY
  /**
   * virConnectDoStoreList:
   * @conn: pointer to the hypervisor connection
***************
*** 126,135 ****
  
      return xs_directory(conn->xshandle, 0, path, nb);
  }
  
  /**
   * virDomainDoStoreQuery:
!  * @domain: a domain object
   * @path: the relative path of the data in the store to retrieve
   *
   * Internal API querying the Xenstore for a string value.
--- 130,141 ----
  
      return xs_directory(conn->xshandle, 0, path, nb);
  }
+ #endif /* ! PROXY */
  
  /**
   * virDomainDoStoreQuery:
!  * @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,159 ****
   * Returns a string which must be freed by the caller or NULL in case of error
   */
  static char *
! virDomainDoStoreQuery(virDomainPtr domain, const char *path)
  {
      char s[256];
      unsigned int len = 0;
  
!     if (!VIR_IS_CONNECTED_DOMAIN(domain))
!         return (NULL);
!     if (domain->conn->xshandle == NULL)
          return (NULL);
  
!     snprintf(s, 255, "/local/domain/%d/%s", domain->handle, path);
      s[255] = 0;
  
!     return xs_read(domain->conn->xshandle, 0, &s[0], &len);
  }
  
! 
  /**
   * virDomainDoStoreWrite:
   * @domain: a domain object
--- 143,163 ----
   * Returns a string which must be freed by the caller or NULL in case of error
   */
  static char *
! virDomainDoStoreQuery(virConnectPtr conn, int domid, const char *path)
  {
      char s[256];
      unsigned int len = 0;
  
!     if (conn->xshandle == NULL)
          return (NULL);
  
!     snprintf(s, 255, "/local/domain/%d/%s", domid, path);
      s[255] = 0;
  
!     return xs_read(conn->xshandle, 0, &s[0], &len);
  }
  
! #ifndef PROXY
  /**
   * virDomainDoStoreWrite:
   * @domain: a domain object
***************
*** 269,274 ****
--- 273,279 ----
      }
      return (0);
  }
+ #endif /* ! PROXY */
  
  /************************************************************************
   *									*
***************
*** 291,300 ****
--- 296,309 ----
      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,332 ****
--- 336,342 ----
      return (0);
  }
  
+ #ifndef PROXY
  /**
   * xenStoreGetDomainInfo:
   * @domain: pointer to the domain block
***************
*** 343,348 ****
--- 353,361 ----
      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,357 ****
      if (domain->conn->xshandle == NULL)
          return(-1);
  
!     tmp = virDomainDoStoreQuery(domain, "running");
      if (tmp != NULL) {
          if (tmp[0] == '1')
              info->state = VIR_DOMAIN_RUNNING;
--- 364,370 ----
      if (domain->conn->xshandle == NULL)
          return(-1);
  
!     tmp = virDomainDoStoreQuery(domain->conn, domain->handle, "running");
      if (tmp != NULL) {
          if (tmp[0] == '1')
              info->state = VIR_DOMAIN_RUNNING;
***************
*** 359,365 ****
      } else {
          info->state = VIR_DOMAIN_NONE;
      }
!     tmp = virDomainDoStoreQuery(domain, "memory/target");
      if (tmp != NULL) {
          info->memory = atol(tmp);
          info->maxMem = atol(tmp);
--- 372,378 ----
      } else {
          info->state = VIR_DOMAIN_NONE;
      }
!     tmp = virDomainDoStoreQuery(domain->conn, domain->handle, "memory/target");
      if (tmp != NULL) {
          info->memory = atol(tmp);
          info->maxMem = atol(tmp);
***************
*** 370,376 ****
      }
  #if 0
      /* doesn't seems to work */
!     tmp = virDomainDoStoreQuery(domain, "cpu_time");
      if (tmp != NULL) {
          info->cpuTime = atol(tmp);
          free(tmp);
--- 383,389 ----
      }
  #if 0
      /* doesn't seems to work */
!     tmp = virDomainDoStoreQuery(domain->conn, domain->handle, "cpu_time");
      if (tmp != NULL) {
          info->cpuTime = atol(tmp);
          free(tmp);
***************
*** 430,436 ****
      char *tmp;
      unsigned long ret = 0;
  
!     tmp = virDomainDoStoreQuery(domain, "memory/target");
      if (tmp != NULL) {
  	ret = (unsigned long) atol(tmp);
  	free(tmp);
--- 443,452 ----
      char *tmp;
      unsigned long ret = 0;
  
!     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,649 ****
       */
      return(virDomainDoStoreWrite(domain, "control/shutdown", "reboot"));
  }
  
  /**
   * xenStoreDomainGetVNCPort:
!  * @domain: pointer to the domain block
   *
   * 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) {
      char *tmp;
      int ret = -1;
  
!     tmp = virDomainDoStoreQuery(domain, "console/vnc-port");
      if (tmp != NULL) {
          char *end;
          ret = strtol(tmp, &end, 10);
--- 645,667 ----
       */
      return(virDomainDoStoreWrite(domain, "control/shutdown", "reboot"));
  }
+ #endif /* ! PROXY */
  
  /**
   * xenStoreDomainGetVNCPort:
!  * @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(virConnectPtr conn, int domid) {
      char *tmp;
      int ret = -1;
  
!     tmp = virDomainDoStoreQuery(conn, domid, "console/vnc-port");
      if (tmp != NULL) {
          char *end;
          ret = strtol(tmp, &end, 10);
***************
*** 656,662 ****
  
  /**
   * xenStoreDomainGetConsolePath:
!  * @domain: pointer to the domain block
   *
   * Return the path to the psuedo TTY on which the guest domain's
   * serial console is attached.
--- 674,681 ----
  
  /**
   * xenStoreDomainGetConsolePath:
!  * @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,670 ****
   * responsibilty to free() the return string. Returns NULL
   * on error
   */
! char *          xenStoreDomainGetConsolePath(virDomainPtr domain) {
!     return virDomainDoStoreQuery(domain, "console/tty");
  }
--- 684,689 ----
   * responsibilty to free() the return string. Returns NULL
   * on error
   */
! char *          xenStoreDomainGetConsolePath(virConnectPtr conn, int domid) {
!   return virDomainDoStoreQuery(conn, domid, "console/tty");
  }
Index: src/xs_internal.h
===================================================================
RCS file: /data/cvs/libvirt/src/xs_internal.h,v
retrieving revision 1.5
diff -c -r1.5 xs_internal.h
*** src/xs_internal.h	8 Aug 2006 20:14:40 -0000	1.5
--- src/xs_internal.h	8 Aug 2006 22:53:59 -0000
***************
*** 35,42 ****
  int 		xenStoreDomainShutdown	(virDomainPtr domain);
  int 		xenStoreDomainReboot	(virDomainPtr domain,
  					 unsigned int flags);
! int             xenStoreDomainGetVNCPort(virDomainPtr domain);
! char *          xenStoreDomainGetConsolePath(virDomainPtr domain);
  
  #ifdef __cplusplus
  }
--- 35,43 ----
  int 		xenStoreDomainShutdown	(virDomainPtr domain);
  int 		xenStoreDomainReboot	(virDomainPtr domain,
  					 unsigned int flags);
! 
! int             xenStoreDomainGetVNCPort(virConnectPtr conn, int domid);
! char *          xenStoreDomainGetConsolePath(virConnectPtr conn, int domid);
  
  #ifdef __cplusplus
  }


More information about the libvir-list mailing list