Re: Add port number to <graphics> tag

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

 



On Mon, Aug 07, 2006 at 10:40:11PM +0100, Daniel P. Berrange wrote:
> > > This is the same problem we so far prevented me adding the path to the
> > > serial console Psuedo-TTY to the XML for a domain. I'd rather like to have
> > > this in 0.1.4 release of libvirt too, so any suggestions on how to approach
> > > implementation when some of the data for the XML needs to come from XS ?
> > 
> >   I would make a wrapper function for the 2 special xs_read calls, to only
> > export relatively high level interface from xs_internal.h for example
> > 
> >    int xenStoreDomainVncPort(virDomainPtr domain);
> > 
> > returning -1 in case of error. Similar for the TTY.
> > 
> >   Make sense ?
> 
> Yeah sounds resonable to me. I'll take a crack at implementing these two
> additions to the XML doc and post a patch for review when I have something
> reasonable working.

See attached patch which looks up port number in xenstore & also pulls
out the serial console tty. The example XML from a HVM domain now looks
like:

<domain type='xen' id='7'>
  <name>twit</name>
  <uuid>12cf7ed6915818803eaa98ad00bd3fc5</uuid>
  <os>
    <type>hvm</type>
    <loader>/usr/lib/xen/boot/hvmloader</loader>
    <boot dev='/dev/cdrom'/>
  </os>
  <memory>512000</memory>
  <vcpu>1</vcpu>
  <on_poweroff>destroy</on_poweroff>
  <on_reboot>restart</on_reboot>
  <on_crash>restart</on_crash>
  <devices>
    <emulator>/usr/lib64/xen/bin/qemu-dm</emulator>
    <interface type='bridge'>
      <source bridge='xenbr0'/>
      <mac address='00:16:3e:52:b2:82'/>
      <script path='vif-bridge'/>
    </interface>
    <disk type='file'>
      <source file='/root/rhel3.img'/>
      <target dev='ioemu:hda'/>
    </disk>
    <graphics type='vnc' port='5934'/>
    <console tty='/dev/pts/7'/>
  </devices>
</domain>


The '<console>' element is actually available for both HVM and PV
domains. I also updated format.html with details of these XML
elements / attributes.

NB, the version of xenstore I'm running doesn't actually include
the changeset 155385a02d0b which writes the vnc-port. Thus to test
it I manually wrote an entry in the same location.

 xenstore-write /local/domain/7/console/vnc-port 5934
 

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  -=| 
? COPYING
Index: ChangeLog
===================================================================
RCS file: /data/cvs/libvirt/ChangeLog,v
retrieving revision 1.205
diff -c -r1.205 ChangeLog
*** ChangeLog	7 Aug 2006 20:55:03 -0000	1.205
--- ChangeLog	7 Aug 2006 23:33:13 -0000
***************
*** 1,3 ****
--- 1,13 ----
+ Mon Aug  7 18:33:45 EDT 2006 Daniel Berrange <berrange@xxxxxxxxxx>
+ 
+ 	* src/xend_internal.c: Added details of serial console TTY to XML 
+ 	representation of domain. Fetch VNC port from xenstore if it is
+ 	available (only in xen 3.0.3 or later).
+ 	* src/xs_internal.c, src/xs_internal.h: Added APIs for retrieving
+ 	the serial console TTY and VNC server port from xenstore.
+ 	* docs/format.html: Document 'port' attribute for VNC graphics,
+ 	and '<console>' element for serial console.
+ 	
  Mon Aug  7 21:57:41 CEST 2006 Daniel Veillard <veillard@xxxxxxxxxx>
  
  	* TODO: updated with new items
Index: docs/format.html
===================================================================
RCS file: /data/cvs/libvirt/docs/format.html,v
retrieving revision 1.9
diff -c -r1.9 format.html
*** docs/format.html	11 Jul 2006 16:57:03 -0000	1.9
--- docs/format.html	7 Aug 2006 23:33:14 -0000
***************
*** 28,33 ****
--- 28,34 ----
        &lt;mac address='</span><span style="color: #0000FF; background-color: #FFFFFF"></span><span style="color: #0000FF; background-color: #FFFFFF">aa:00:00:00:00:11'/&gt;
        &lt;script path='/etc/xen/scripts/vif-bridge'/&gt;
      &lt;/interface&gt;</span>
+     <span style="color: #FF8000; background-color: #FFFFFF">&lt;console tty='/dev/pts/5'/&gt;</span>
    &lt;/devices&gt;
  &lt;/domain&gt;</pre><p>The root element must be called <code>domain</code> with no namespace, the
  <code>type</code> attribute indicates the kind of hypervisor used, 'xen' is
***************
*** 47,56 ****
        <li>root: the root filesystem from the guest viewpoint, it may be
          passed as part of the cmdline content too</li>
      </ul></li>
!   <li>devices: a list of <code>disk</code> and <code>interface</code>
      descriptions in no special order</li>
  </ul><p>The format of the devices and their type may grow over time, but the
! following should be sufficient for basic use:</p><p>A disk device indicates a block device, it can have two values for the
  type attribute either 'file' or 'block' corresponding to the 2 options
  availble at the Xen layer. It has two mandatory children, and one optional
  one in no specific order:</p><ul><li>source with a file attribute containing the path in Domain 0 to the
--- 48,57 ----
        <li>root: the root filesystem from the guest viewpoint, it may be
          passed as part of the cmdline content too</li>
      </ul></li>
!   <li>devices: a list of <code>disk</code>, <code>interface</code> and <code>console</code>
      descriptions in no special order</li>
  </ul><p>The format of the devices and their type may grow over time, but the
! following should be sufficient for basic use:</p><p>A <code>disk</code> device indicates a block device, it can have two values for the
  type attribute either 'file' or 'block' corresponding to the 2 options
  availble at the Xen layer. It has two mandatory children, and one optional
  one in no specific order:</p><ul><li>source with a file attribute containing the path in Domain 0 to the
***************
*** 60,72 ****
      the guest</li>
    <li>readonly an optional empty element indicating the device is
    read-only</li>
! </ul><p>An interface element describes a network device mapped on the guest, it
  also has a type whose value is currently 'bridge', it also have a number of
  children in no specific order:</p><ul><li>source: indicating the bridge name</li>
    <li>mac: the optional mac address provided in the address attribute</li>
    <li>ip: the optional IP address provided in the address attribute</li>
    <li>script: the script used to bridge the interfcae in the Domain 0</li>
    <li>target: and optional target indicating the device name.</li>
  </ul><p>Life cycle actions for the domain can also be expressed in the XML format,
  they drive what should be happening if the domain crashes, is rebooted or is
  poweroff. There is various actions possible when this happen:</p><ul><li>destroy: The domain is cleaned up (that's the default normal processing
--- 61,76 ----
      the guest</li>
    <li>readonly an optional empty element indicating the device is
    read-only</li>
! </ul><p>An <code>interface</code> element describes a network device mapped on the guest, it
  also has a type whose value is currently 'bridge', it also have a number of
  children in no specific order:</p><ul><li>source: indicating the bridge name</li>
    <li>mac: the optional mac address provided in the address attribute</li>
    <li>ip: the optional IP address provided in the address attribute</li>
    <li>script: the script used to bridge the interfcae in the Domain 0</li>
    <li>target: and optional target indicating the device name.</li>
+ </ul><p>A <code>console</code> element describes a serial console connection to the
+ guest. It has no children, and a single attribute:</p><ul>
+   <li>tty: the path to the Pseudo TTY on which the guest console can be accessed</li>
  </ul><p>Life cycle actions for the domain can also be expressed in the XML format,
  they drive what should be happening if the domain crashes, is rebooted or is
  poweroff. There is various actions possible when this happen:</p><ul><li>destroy: The domain is cleaned up (that's the default normal processing
***************
*** 113,119 ****
        &lt;source file='/root/fv0'/&gt;
        &lt;target <span style="color: #0000E5; background-color: #FFFFFF">dev='ioemu:hda'</span>/&gt;
      &lt;/disk&gt;
!     <span style="color: #0000E5; background-color: #FFFFFF">&lt;graphics type='vnc'/&gt;</span>
    &lt;/devices&gt;
  &lt;/domain&gt;</pre><p>There is a few things to notice specifically for HVM domains:</p><ul><li>the &lt;os&gt; block description is very different, first it indicates
      that the type is 'hvm' for hardware virtualization, then instead of a
--- 117,123 ----
        &lt;source file='/root/fv0'/&gt;
        &lt;target <span style="color: #0000E5; background-color: #FFFFFF">dev='ioemu:hda'</span>/&gt;
      &lt;/disk&gt;
!     <span style="color: #0000E5; background-color: #FFFFFF">&lt;graphics type='vnc' port='5904'/&gt;</span>
    &lt;/devices&gt;
  &lt;/domain&gt;</pre><p>There is a few things to notice specifically for HVM domains:</p><ul><li>the &lt;os&gt; block description is very different, first it indicates
      that the type is 'hvm' for hardware virtualization, then instead of a
***************
*** 126,132 ****
      for the drive is the first IDE disk device hda</li>
    <li>the &lt;devices&gt; section also include at least one entry for the
      graphic device used to render the os. Currently there is just 2 types
!     possible 'vnc' or 'sdl'</li>
  </ul><p>It is likely that the HVM description gets additional optional elements
  and attributes as the support for fully virtualized domain expands,
  especially for the variety of devices emulated and the graphic support
--- 130,138 ----
      for the drive is the first IDE disk device hda</li>
    <li>the &lt;devices&gt; section also include at least one entry for the
      graphic device used to render the os. Currently there is just 2 types
!     possible 'vnc' or 'sdl'. If the type is 'vnc', there will be an additional
!     attribute 'port' detailed the TCP port on which the VNC server accepts
!     client connections.</li>
  </ul><p>It is likely that the HVM description gets additional optional elements
  and attributes as the support for fully virtualized domain expands,
  especially for the variety of devices emulated and the graphic support
Index: src/xend_internal.c
===================================================================
RCS file: /data/cvs/libvirt/src/xend_internal.c,v
retrieving revision 1.49
diff -c -r1.49 xend_internal.c
*** src/xend_internal.c	7 Aug 2006 19:56:37 -0000	1.49
--- src/xend_internal.c	7 Aug 2006 23:33:15 -0000
***************
*** 35,40 ****
--- 35,41 ----
  #include "xml.h"
  #include "xend_internal.h"
  #include "xen_internal.h" /* for DOM0_INTERFACE_VERSION */
+ #include "xs_internal.h" /* To extract VNC port & Serial console TTY */
  
  #ifndef PROXY
  static const char * xenDaemonGetType(virConnectPtr conn);
***************
*** 1434,1439 ****
--- 1435,1441 ----
  
  /**
   * xend_parse_sexp_desc:
+  * @domain: the domain associated with the XML
   * @root: the root of the parsed S-Expression
   *
   * Parse the xend sexp description and turn it into the XML format similar
***************
*** 1443,1453 ****
   *         the caller must free() the returned value.
   */
  static char *
! xend_parse_sexp_desc(struct sexpr *root)
  {
      char *ret;
      struct sexpr *cur, *node;
      const char *tmp;
      virBuffer buf;
      int hvm = 0;
  
--- 1445,1456 ----
   *         the caller must free() the returned value.
   */
  static char *
! xend_parse_sexp_desc(virDomainPtr domain, struct sexpr *root)
  {
      char *ret;
      struct sexpr *cur, *node;
      const char *tmp;
+     char *tty;
      virBuffer buf;
      int hvm = 0;
  
***************
*** 1599,1609 ****
      if (hvm) {
          /* Graphics device */
          tmp = sexpr_node(root, "domain/image/hvm/vnc");
- 	/* XXX extract VNC port from XenStore if its available */
          if (tmp != NULL) {
!             if (tmp[0] == '1')
!                 virBufferVSprintf(&buf, "    <graphics type='vnc' port='%d'/>\n", 
!                                   5900 + sexpr_int(root, "domain/domid"));
          }
          
          tmp = sexpr_node(root, "domain/image/hvm/sdl");
--- 1602,1614 ----
      if (hvm) {
          /* Graphics device */
          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);
!             }
          }
          
          tmp = sexpr_node(root, "domain/image/hvm/sdl");
***************
*** 1618,1623 ****
--- 1623,1634 ----
           */
      }
      
+     tty = xenStoreDomainGetConsolePath(domain);
+     if (tty) {
+         virBufferVSprintf(&buf, "    <console tty='%s'/>\n", tty);
+         free(tty);
+     }
+ 
      virBufferAdd(&buf, "  </devices>\n", 13);
      virBufferAdd(&buf, "</domain>\n", 10);
  
***************
*** 2145,2151 ****
      if (root == NULL)
          return (NULL);
  
!     ret = xend_parse_sexp_desc(root);
      sexpr_free(root);
  
      return (ret);
--- 2156,2162 ----
      if (root == NULL)
          return (NULL);
  
!     ret = xend_parse_sexp_desc(domain, root);
      sexpr_free(root);
  
      return (ret);
Index: src/xs_internal.c
===================================================================
RCS file: /data/cvs/libvirt/src/xs_internal.c,v
retrieving revision 1.12
diff -c -r1.12 xs_internal.c
*** src/xs_internal.c	19 Jul 2006 22:24:37 -0000	1.12
--- src/xs_internal.c	7 Aug 2006 23:33:15 -0000
***************
*** 627,629 ****
--- 627,664 ----
      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) {
+         ret = atoi(tmp);
+         free(tmp);
+     }
+     return(ret);
+ }
+ 
+ /**
+  * xenStoreDomainGetConsolePath:
+  * @domain: pointer to the domain block
+  *
+  * Return the path to the psuedo TTY on which the guest domain's
+  * serial console is attached.
+  *
+  * Returns the path to the serial console. It is the callers
+  * responsibilty to free() the return string. Returns NULL
+  * on error
+  */
+ char *          xenStoreDomainGetConsolePath(virDomainPtr domain) {
+     return virDomainDoStoreQuery(domain, "console/tty");
+ }
Index: src/xs_internal.h
===================================================================
RCS file: /data/cvs/libvirt/src/xs_internal.h,v
retrieving revision 1.4
diff -c -r1.4 xs_internal.h
*** src/xs_internal.h	13 Apr 2006 17:18:49 -0000	1.4
--- src/xs_internal.h	7 Aug 2006 23:33:15 -0000
***************
*** 35,40 ****
--- 35,43 ----
  int 		xenStoreDomainShutdown	(virDomainPtr domain);
  int 		xenStoreDomainReboot	(virDomainPtr domain,
  					 unsigned int flags);
+ int             xenStoreDomainGetVNCPort(virDomainPtr domain);
+ char *          xenStoreDomainGetConsolePath(virDomainPtr domain);
+ 
  #ifdef __cplusplus
  }
  #endif

[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]