ia64/xen-unstable

changeset 10770:ecb8ff1fcf1f

Spawn vncviewer from qemu-dm.
- add vncviewer option to qemu-dm to spawn a vncviewer process.
- add the `vncconsole' config parameter which enables qemu-dm's vncviewer
option.

Based on a patch from: Don Dugger <donald.d.dugger@intel.com>
Signed-off-by: Christian Limpach <Christian.Limpach@xensource.com>
author chris@kneesaa.uk.xensource.com
date Fri Jul 14 18:53:27 2006 +0100 (2006-07-14)
parents ccf11affc545
children bbabdebc54ad
files tools/examples/xmexample.hvm tools/ioemu/patches/series tools/ioemu/patches/vnc-start-vncviewer tools/ioemu/vl.c tools/ioemu/vl.h tools/ioemu/vnc.c tools/python/xen/xend/image.py tools/python/xen/xm/create.py
line diff
     1.1 --- a/tools/examples/xmexample.hvm	Fri Jul 14 15:59:24 2006 +0100
     1.2 +++ b/tools/examples/xmexample.hvm	Fri Jul 14 18:53:27 2006 +0100
     1.3 @@ -134,8 +134,9 @@ vnc=1
     1.4  #vncdisplay=1
     1.5  
     1.6  #----------------------------------------------------------------------------
     1.7 -# enable spawning vncviewer(only valid when vnc=1), default = 1
     1.8 -vncviewer=1
     1.9 +# enable spawning vncviewer for domain's console
    1.10 +# (only valid when vnc=1), default = 0
    1.11 +#vncconsole=0
    1.12  
    1.13  #----------------------------------------------------------------------------
    1.14  # no graphics, use serial port
     2.1 --- a/tools/ioemu/patches/series	Fri Jul 14 15:59:24 2006 +0100
     2.2 +++ b/tools/ioemu/patches/series	Fri Jul 14 18:53:27 2006 +0100
     2.3 @@ -30,3 +30,4 @@ acpi-timer-support
     2.4  acpi-poweroff-support
     2.5  vnc-cleanup
     2.6  vnc-fixes
     2.7 +vnc-start-vncviewer
     3.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     3.2 +++ b/tools/ioemu/patches/vnc-start-vncviewer	Fri Jul 14 18:53:27 2006 +0100
     3.3 @@ -0,0 +1,105 @@
     3.4 +Index: ioemu/vnc.c
     3.5 +===================================================================
     3.6 +--- ioemu.orig/vnc.c	2006-07-14 18:29:36.810169908 +0100
     3.7 ++++ ioemu/vnc.c	2006-07-14 18:30:17.437628819 +0100
     3.8 +@@ -999,3 +999,25 @@
     3.9 + 
    3.10 +     vnc_dpy_resize(vs->ds, 640, 400);
    3.11 + }
    3.12 ++
    3.13 ++int vnc_start_viewer(int port)
    3.14 ++{
    3.15 ++    int pid;
    3.16 ++    char s[16];
    3.17 ++
    3.18 ++    sprintf(s, ":%d", port);
    3.19 ++
    3.20 ++    switch (pid = fork()) {
    3.21 ++    case -1:
    3.22 ++	fprintf(stderr, "vncviewer failed fork\n");
    3.23 ++	exit(1);
    3.24 ++
    3.25 ++    case 0:	/* child */
    3.26 ++	execlp("vncviewer", "vncviewer", s, 0);
    3.27 ++	fprintf(stderr, "vncviewer execlp failed\n");
    3.28 ++	exit(1);
    3.29 ++
    3.30 ++    default:
    3.31 ++	return pid;
    3.32 ++    }
    3.33 ++}
    3.34 +Index: ioemu/vl.c
    3.35 +===================================================================
    3.36 +--- ioemu.orig/vl.c	2006-07-14 18:29:36.809170020 +0100
    3.37 ++++ ioemu/vl.c	2006-07-14 18:30:17.435629043 +0100
    3.38 +@@ -121,6 +121,7 @@
    3.39 + int bios_size;
    3.40 + static DisplayState display_state;
    3.41 + int nographic;
    3.42 ++int vncviewer;
    3.43 + const char* keyboard_layout = NULL;
    3.44 + int64_t ticks_per_sec;
    3.45 + int boot_device = 'c';
    3.46 +@@ -4801,6 +4802,7 @@
    3.47 + #endif
    3.48 +            "-loadvm file    start right away with a saved state (loadvm in monitor)\n"
    3.49 + 	   "-vnc display    start a VNC server on display\n"
    3.50 ++           "-vncviewer      start a vncviewer process for this domain\n"
    3.51 +            "-timeoffset     time offset (in seconds) from local time\n"
    3.52 +            "\n"
    3.53 +            "During emulation, the following keys are useful:\n"
    3.54 +@@ -4889,6 +4891,7 @@
    3.55 +     QEMU_OPTION_usbdevice,
    3.56 +     QEMU_OPTION_smp,
    3.57 +     QEMU_OPTION_vnc,
    3.58 ++    QEMU_OPTION_vncviewer,
    3.59 + 
    3.60 +     QEMU_OPTION_d,
    3.61 +     QEMU_OPTION_vcpus,
    3.62 +@@ -4964,6 +4967,7 @@
    3.63 +     { "usbdevice", HAS_ARG, QEMU_OPTION_usbdevice },
    3.64 +     { "smp", HAS_ARG, QEMU_OPTION_smp },
    3.65 +     { "vnc", HAS_ARG, QEMU_OPTION_vnc },
    3.66 ++    { "vncviewer", 0, QEMU_OPTION_vncviewer },
    3.67 +     
    3.68 +     /* temporary options */
    3.69 +     { "usb", 0, QEMU_OPTION_usb },
    3.70 +@@ -5294,6 +5298,7 @@
    3.71 + #endif
    3.72 +     snapshot = 0;
    3.73 +     nographic = 0;
    3.74 ++    vncviewer = 0;
    3.75 +     kernel_filename = NULL;
    3.76 +     kernel_cmdline = "";
    3.77 + #ifdef TARGET_PPC
    3.78 +@@ -5663,6 +5668,9 @@
    3.79 + 		    exit(1);
    3.80 + 		}
    3.81 + 		break;
    3.82 ++            case QEMU_OPTION_vncviewer:
    3.83 ++                vncviewer++;
    3.84 ++                break;
    3.85 +             case QEMU_OPTION_domainname:
    3.86 +                 strncat(domain_name, optarg, sizeof(domain_name) - 20);
    3.87 +                 break;
    3.88 +@@ -5881,6 +5889,8 @@
    3.89 +         dumb_display_init(ds);
    3.90 +     } else if (vnc_display != -1) {
    3.91 + 	vnc_display_init(ds, vnc_display);
    3.92 ++	if (vncviewer)
    3.93 ++	    vnc_start_viewer(vnc_display);
    3.94 +     } else {
    3.95 + #if defined(CONFIG_SDL)
    3.96 +         sdl_display_init(ds, full_screen);
    3.97 +Index: ioemu/vl.h
    3.98 +===================================================================
    3.99 +--- ioemu.orig/vl.h	2006-07-14 18:29:36.810169908 +0100
   3.100 ++++ ioemu/vl.h	2006-07-14 18:30:17.436628931 +0100
   3.101 +@@ -732,6 +732,7 @@
   3.102 + 
   3.103 + /* vnc.c */
   3.104 + void vnc_display_init(DisplayState *ds, int display);
   3.105 ++int vnc_start_viewer(int port);
   3.106 + 
   3.107 + /* ide.c */
   3.108 + #define MAX_DISKS 4
     4.1 --- a/tools/ioemu/vl.c	Fri Jul 14 15:59:24 2006 +0100
     4.2 +++ b/tools/ioemu/vl.c	Fri Jul 14 18:53:27 2006 +0100
     4.3 @@ -121,6 +121,7 @@ int vga_ram_size;
     4.4  int bios_size;
     4.5  static DisplayState display_state;
     4.6  int nographic;
     4.7 +int vncviewer;
     4.8  const char* keyboard_layout = NULL;
     4.9  int64_t ticks_per_sec;
    4.10  int boot_device = 'c';
    4.11 @@ -4801,6 +4802,7 @@ void help(void)
    4.12  #endif
    4.13             "-loadvm file    start right away with a saved state (loadvm in monitor)\n"
    4.14  	   "-vnc display    start a VNC server on display\n"
    4.15 +           "-vncviewer      start a vncviewer process for this domain\n"
    4.16             "-timeoffset     time offset (in seconds) from local time\n"
    4.17             "\n"
    4.18             "During emulation, the following keys are useful:\n"
    4.19 @@ -4889,6 +4891,7 @@ enum {
    4.20      QEMU_OPTION_usbdevice,
    4.21      QEMU_OPTION_smp,
    4.22      QEMU_OPTION_vnc,
    4.23 +    QEMU_OPTION_vncviewer,
    4.24  
    4.25      QEMU_OPTION_d,
    4.26      QEMU_OPTION_vcpus,
    4.27 @@ -4964,6 +4967,7 @@ const QEMUOption qemu_options[] = {
    4.28      { "usbdevice", HAS_ARG, QEMU_OPTION_usbdevice },
    4.29      { "smp", HAS_ARG, QEMU_OPTION_smp },
    4.30      { "vnc", HAS_ARG, QEMU_OPTION_vnc },
    4.31 +    { "vncviewer", 0, QEMU_OPTION_vncviewer },
    4.32      
    4.33      /* temporary options */
    4.34      { "usb", 0, QEMU_OPTION_usb },
    4.35 @@ -5294,6 +5298,7 @@ int main(int argc, char **argv)
    4.36  #endif
    4.37      snapshot = 0;
    4.38      nographic = 0;
    4.39 +    vncviewer = 0;
    4.40      kernel_filename = NULL;
    4.41      kernel_cmdline = "";
    4.42  #ifdef TARGET_PPC
    4.43 @@ -5663,6 +5668,9 @@ int main(int argc, char **argv)
    4.44  		    exit(1);
    4.45  		}
    4.46  		break;
    4.47 +            case QEMU_OPTION_vncviewer:
    4.48 +                vncviewer++;
    4.49 +                break;
    4.50              case QEMU_OPTION_domainname:
    4.51                  strncat(domain_name, optarg, sizeof(domain_name) - 20);
    4.52                  break;
    4.53 @@ -5881,6 +5889,8 @@ int main(int argc, char **argv)
    4.54          dumb_display_init(ds);
    4.55      } else if (vnc_display != -1) {
    4.56  	vnc_display_init(ds, vnc_display);
    4.57 +	if (vncviewer)
    4.58 +	    vnc_start_viewer(vnc_display);
    4.59      } else {
    4.60  #if defined(CONFIG_SDL)
    4.61          sdl_display_init(ds, full_screen);
     5.1 --- a/tools/ioemu/vl.h	Fri Jul 14 15:59:24 2006 +0100
     5.2 +++ b/tools/ioemu/vl.h	Fri Jul 14 18:53:27 2006 +0100
     5.3 @@ -732,6 +732,7 @@ void cocoa_display_init(DisplayState *ds
     5.4  
     5.5  /* vnc.c */
     5.6  void vnc_display_init(DisplayState *ds, int display);
     5.7 +int vnc_start_viewer(int port);
     5.8  
     5.9  /* ide.c */
    5.10  #define MAX_DISKS 4
     6.1 --- a/tools/ioemu/vnc.c	Fri Jul 14 15:59:24 2006 +0100
     6.2 +++ b/tools/ioemu/vnc.c	Fri Jul 14 18:53:27 2006 +0100
     6.3 @@ -999,3 +999,25 @@ void vnc_display_init(DisplayState *ds, 
     6.4  
     6.5      vnc_dpy_resize(vs->ds, 640, 400);
     6.6  }
     6.7 +
     6.8 +int vnc_start_viewer(int port)
     6.9 +{
    6.10 +    int pid;
    6.11 +    char s[16];
    6.12 +
    6.13 +    sprintf(s, ":%d", port);
    6.14 +
    6.15 +    switch (pid = fork()) {
    6.16 +    case -1:
    6.17 +	fprintf(stderr, "vncviewer failed fork\n");
    6.18 +	exit(1);
    6.19 +
    6.20 +    case 0:	/* child */
    6.21 +	execlp("vncviewer", "vncviewer", s, 0);
    6.22 +	fprintf(stderr, "vncviewer execlp failed\n");
    6.23 +	exit(1);
    6.24 +
    6.25 +    default:
    6.26 +	return pid;
    6.27 +    }
    6.28 +}
     7.1 --- a/tools/python/xen/xend/image.py	Fri Jul 14 15:59:24 2006 +0100
     7.2 +++ b/tools/python/xen/xend/image.py	Fri Jul 14 18:53:27 2006 +0100
     7.3 @@ -208,6 +208,7 @@ class HVMImageHandler(ImageHandler):
     7.4              raise VmError("hvm: missing device model")
     7.5          self.display = sxp.child_value(imageConfig, 'display')
     7.6          self.xauthority = sxp.child_value(imageConfig, 'xauthority')
     7.7 +        self.vncconsole = sxp.child_value(imageConfig, 'vncconsole')
     7.8  
     7.9          self.vm.storeVm(("image/dmargs", " ".join(self.dmargs)),
    7.10                          ("image/device-model", self.device_model),
    7.11 @@ -335,11 +336,7 @@ class HVMImageHandler(ImageHandler):
    7.12              return
    7.13          # Execute device model.
    7.14          #todo: Error handling
    7.15 -        # XXX RN: note that the order of args matter!
    7.16          args = [self.device_model]
    7.17 -        vnc = self.vncParams()
    7.18 -        if len(vnc):
    7.19 -            args = args + vnc
    7.20          args = args + ([ "-d",  "%d" % self.vm.getDomid(),
    7.21                    "-m", "%s" % (self.vm.getMemoryTarget() / 1024)])
    7.22          args = args + self.dmargs
    7.23 @@ -348,24 +345,12 @@ class HVMImageHandler(ImageHandler):
    7.24              env['DISPLAY'] = self.display
    7.25          if self.xauthority:
    7.26              env['XAUTHORITY'] = self.xauthority
    7.27 +        if self.vncconsole:
    7.28 +            args = args + ([ "-vncviewer" ])
    7.29          log.info("spawning device models: %s %s", self.device_model, args)
    7.30          self.pid = os.spawnve(os.P_NOWAIT, self.device_model, args, env)
    7.31          log.info("device model pid: %d", self.pid)
    7.32  
    7.33 -    def vncParams(self):
    7.34 -        # see if a vncviewer was specified
    7.35 -        # XXX RN: bit of a hack. should unify this, maybe stick in config space
    7.36 -        vncconnect=[]
    7.37 -        args = self.cmdline
    7.38 -        if args:
    7.39 -            arg_list = string.split(args)
    7.40 -            for arg in arg_list:
    7.41 -                al = string.split(arg, '=')
    7.42 -                if al[0] == "VNC_VIEWER":
    7.43 -                    vncconnect=["-vncconnect", "%s" % al[1]]
    7.44 -                    break
    7.45 -        return vncconnect
    7.46 -
    7.47      def destroy(self):
    7.48          self.unregister_shutdown_watch();
    7.49          import signal
     8.1 --- a/tools/python/xen/xm/create.py	Fri Jul 14 15:59:24 2006 +0100
     8.2 +++ b/tools/python/xen/xm/create.py	Fri Jul 14 18:53:27 2006 +0100
     8.3 @@ -112,6 +112,12 @@ gopts.var('vncviewer', val='no|yes',
     8.4            Only valid when vnc=1.
     8.5            """)
     8.6  
     8.7 +gopts.var('vncconsole', val='no|yes',
     8.8 +          fn=set_bool, default=None,
     8.9 +          use="""Spawn a vncviewer process for the domain's graphical console.
    8.10 +          Only valid when vnc=1.
    8.11 +          """)
    8.12 +
    8.13  gopts.var('name', val='NAME',
    8.14            fn=set_value, default=None,
    8.15            use="Domain name. Must be unique.")
    8.16 @@ -625,7 +631,7 @@ def configure_hvm(config_image, vals):
    8.17      """
    8.18      args = [ 'device_model', 'pae', 'vcpus', 'cdrom', 'boot', 'fda', 'fdb',
    8.19               'localtime', 'serial', 'stdvga', 'isa', 'nographic', 'audio',
    8.20 -             'vnc', 'vncdisplay', 'vncviewer', 'sdl', 'display',
    8.21 +             'vnc', 'vncdisplay', 'vncconsole', 'sdl', 'display',
    8.22               'acpi', 'apic', 'xauthority', 'usb', 'usbdevice' ]
    8.23      for a in args:
    8.24          if (vals.__dict__[a]):
    8.25 @@ -854,17 +860,18 @@ def preprocess_vnc(vals):
    8.26      """If vnc was specified, spawn a vncviewer in listen mode
    8.27      and pass its address to the domain on the kernel command line.
    8.28      """
    8.29 -    if not (vals.vnc and vals.vncviewer) or vals.dryrun: return
    8.30 -    vnc_display = choose_vnc_display()
    8.31 -    if not vnc_display:
    8.32 -        warn("No free vnc display")
    8.33 -        return
    8.34 -    print 'VNC=', vnc_display
    8.35 -    vnc_port = spawn_vnc(vnc_display)
    8.36 -    if vnc_port > 0:
    8.37 -        vnc_host = get_host_addr()
    8.38 -        vnc = 'VNC_VIEWER=%s:%d' % (vnc_host, vnc_port)
    8.39 -        vals.extra = vnc + ' ' + vals.extra
    8.40 +    if vals.dryrun: return
    8.41 +    if vals.vncviewer:
    8.42 +        vnc_display = choose_vnc_display()
    8.43 +        if not vnc_display:
    8.44 +            warn("No free vnc display")
    8.45 +            return
    8.46 +        print 'VNC=', vnc_display
    8.47 +        vnc_port = spawn_vnc(vnc_display)
    8.48 +        if vnc_port > 0:
    8.49 +            vnc_host = get_host_addr()
    8.50 +            vnc = 'VNC_VIEWER=%s:%d' % (vnc_host, vnc_port)
    8.51 +            vals.extra = vnc + ' ' + vals.extra
    8.52      
    8.53  def preprocess(vals):
    8.54      if not vals.kernel and not vals.bootloader: