ia64/xen-unstable

changeset 11029:bd04004865ba

[qemu] Add vncunused option.
If the port used for the requested display number is in use, try
additional ports until a free port is found.

Signed-off-by: Christian Limpach <Christian.Limpach@xensource.com>
author chris@kneesaa.uk.xensource.com
date Wed Aug 09 15:03:38 2006 +0100 (2006-08-09)
parents b16252dbcb1f
children 15304ad81c50
files tools/examples/xmexample.hvm 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	Wed Aug 09 11:29:06 2006 +0100
     1.2 +++ b/tools/examples/xmexample.hvm	Wed Aug 09 15:03:38 2006 +0100
     1.3 @@ -130,6 +130,10 @@ vnc=1
     1.4  #vncdisplay=1
     1.5  
     1.6  #----------------------------------------------------------------------------
     1.7 +# try to find an unused port for the VNC server, default = 1
     1.8 +#vncunused=1
     1.9 +
    1.10 +#----------------------------------------------------------------------------
    1.11  # enable spawning vncviewer for domain's console
    1.12  # (only valid when vnc=1), default = 0
    1.13  #vncconsole=0
     2.1 --- a/tools/ioemu/vl.c	Wed Aug 09 11:29:06 2006 +0100
     2.2 +++ b/tools/ioemu/vl.c	Wed Aug 09 15:03:38 2006 +0100
     2.3 @@ -121,6 +121,7 @@ int bios_size;
     2.4  static DisplayState display_state;
     2.5  int nographic;
     2.6  int vncviewer;
     2.7 +int vncunused;
     2.8  const char* keyboard_layout = NULL;
     2.9  int64_t ticks_per_sec;
    2.10  int boot_device = 'c';
    2.11 @@ -5344,6 +5345,7 @@ void help(void)
    2.12             "-loadvm file    start right away with a saved state (loadvm in monitor)\n"
    2.13  	   "-vnc display    start a VNC server on display\n"
    2.14             "-vncviewer      start a vncviewer process for this domain\n"
    2.15 +           "-vncunused      bind the VNC server to an unused port\n"
    2.16             "-timeoffset     time offset (in seconds) from local time\n"
    2.17             "-acpi           disable or enable ACPI of HVM domain \n"
    2.18             "\n"
    2.19 @@ -5435,6 +5437,7 @@ enum {
    2.20      QEMU_OPTION_timeoffset,
    2.21      QEMU_OPTION_acpi,
    2.22      QEMU_OPTION_vncviewer,
    2.23 +    QEMU_OPTION_vncunused,
    2.24  };
    2.25  
    2.26  typedef struct QEMUOption {
    2.27 @@ -5512,6 +5515,7 @@ const QEMUOption qemu_options[] = {
    2.28      { "smp", HAS_ARG, QEMU_OPTION_smp },
    2.29      { "vnc", HAS_ARG, QEMU_OPTION_vnc },
    2.30      { "vncviewer", 0, QEMU_OPTION_vncviewer },
    2.31 +    { "vncunused", 0, QEMU_OPTION_vncunused },
    2.32      
    2.33      /* temporary options */
    2.34      { "usb", 0, QEMU_OPTION_usb },
    2.35 @@ -5888,6 +5892,7 @@ int main(int argc, char **argv)
    2.36      snapshot = 0;
    2.37      nographic = 0;
    2.38      vncviewer = 0;
    2.39 +    vncunused = 0;
    2.40      kernel_filename = NULL;
    2.41      kernel_cmdline = "";
    2.42  #ifndef CONFIG_DM
    2.43 @@ -6295,6 +6300,11 @@ int main(int argc, char **argv)
    2.44              case QEMU_OPTION_vncviewer:
    2.45                  vncviewer++;
    2.46                  break;
    2.47 +            case QEMU_OPTION_vncunused:
    2.48 +                vncunused++;
    2.49 +                if (vnc_display == -1)
    2.50 +                    vnc_display = -2;
    2.51 +                break;
    2.52              }
    2.53          }
    2.54      }
    2.55 @@ -6504,7 +6514,7 @@ int main(int argc, char **argv)
    2.56      if (nographic) {
    2.57          dumb_display_init(ds);
    2.58      } else if (vnc_display != -1) {
    2.59 -	vnc_display_init(ds, vnc_display);
    2.60 +	vnc_display = vnc_display_init(ds, vnc_display, vncunused);
    2.61  	if (vncviewer)
    2.62  	    vnc_start_viewer(vnc_display);
    2.63  	xenstore_write_vncport(vnc_display);
     3.1 --- a/tools/ioemu/vl.h	Wed Aug 09 11:29:06 2006 +0100
     3.2 +++ b/tools/ioemu/vl.h	Wed Aug 09 15:03:38 2006 +0100
     3.3 @@ -784,7 +784,7 @@ void sdl_display_init(DisplayState *ds, 
     3.4  void cocoa_display_init(DisplayState *ds, int full_screen);
     3.5  
     3.6  /* vnc.c */
     3.7 -void vnc_display_init(DisplayState *ds, int display);
     3.8 +int vnc_display_init(DisplayState *ds, int display, int find_unused);
     3.9  int vnc_start_viewer(int port);
    3.10  
    3.11  /* ide.c */
     4.1 --- a/tools/ioemu/vnc.c	Wed Aug 09 11:29:06 2006 +0100
     4.2 +++ b/tools/ioemu/vnc.c	Wed Aug 09 15:03:38 2006 +0100
     4.3 @@ -1183,7 +1183,7 @@ static void vnc_listen_read(void *opaque
     4.4      }
     4.5  }
     4.6  
     4.7 -void vnc_display_init(DisplayState *ds, int display)
     4.8 +int vnc_display_init(DisplayState *ds, int display, int find_unused)
     4.9  {
    4.10      struct sockaddr_in addr;
    4.11      int reuse_addr, ret;
    4.12 @@ -1214,10 +1214,6 @@ void vnc_display_init(DisplayState *ds, 
    4.13  	exit(1);
    4.14      }
    4.15  
    4.16 -    addr.sin_family = AF_INET;
    4.17 -    addr.sin_port = htons(5900 + display);
    4.18 -    memset(&addr.sin_addr, 0, sizeof(addr.sin_addr));
    4.19 -
    4.20      reuse_addr = 1;
    4.21      ret = setsockopt(vs->lsock, SOL_SOCKET, SO_REUSEADDR,
    4.22  		     (const char *)&reuse_addr, sizeof(reuse_addr));
    4.23 @@ -1226,7 +1222,16 @@ void vnc_display_init(DisplayState *ds, 
    4.24  	exit(1);
    4.25      }
    4.26  
    4.27 + retry:
    4.28 +    addr.sin_family = AF_INET;
    4.29 +    addr.sin_port = htons(5900 + display);
    4.30 +    memset(&addr.sin_addr, 0, sizeof(addr.sin_addr));
    4.31 +
    4.32      if (bind(vs->lsock, (struct sockaddr *)&addr, sizeof(addr)) == -1) {
    4.33 +	if (find_unused && errno == EADDRINUSE) {
    4.34 +	    display++;
    4.35 +	    goto retry;
    4.36 +	}
    4.37  	fprintf(stderr, "bind() failed\n");
    4.38  	exit(1);
    4.39      }
    4.40 @@ -1247,6 +1252,8 @@ void vnc_display_init(DisplayState *ds, 
    4.41      vs->ds->dpy_refresh = vnc_dpy_refresh;
    4.42  
    4.43      vnc_dpy_resize(vs->ds, 640, 400);
    4.44 +
    4.45 +    return display;
    4.46  }
    4.47  
    4.48  int vnc_start_viewer(int port)
     5.1 --- a/tools/python/xen/xend/image.py	Wed Aug 09 11:29:06 2006 +0100
     5.2 +++ b/tools/python/xen/xend/image.py	Wed Aug 09 15:03:38 2006 +0100
     5.3 @@ -307,6 +307,7 @@ class HVMImageHandler(ImageHandler):
     5.4          vnc = sxp.child_value(config, 'vnc')
     5.5          vncdisplay = sxp.child_value(config, 'vncdisplay',
     5.6                                       int(self.vm.getDomid()))
     5.7 +        vncunused = sxp.child_value(config, 'vncunused')
     5.8          sdl = sxp.child_value(config, 'sdl')
     5.9          ret = []
    5.10          nographic = sxp.child_value(config, 'nographic')
    5.11 @@ -315,6 +316,8 @@ class HVMImageHandler(ImageHandler):
    5.12              return ret
    5.13          if vnc:
    5.14              ret = ret + ['-vnc', '%d' % vncdisplay, '-k', 'en-us']
    5.15 +        if vncunused:
    5.16 +            ret += ['-vncunused']
    5.17          return ret
    5.18  
    5.19      def createDeviceModel(self):
     6.1 --- a/tools/python/xen/xm/create.py	Wed Aug 09 11:29:06 2006 +0100
     6.2 +++ b/tools/python/xen/xm/create.py	Wed Aug 09 15:03:38 2006 +0100
     6.3 @@ -412,6 +412,11 @@ gopts.var('vncdisplay', val='',
     6.4            fn=set_value, default=None,
     6.5            use="""VNC display to use""")
     6.6  
     6.7 +gopts.var('vncunused', val='',
     6.8 +          fn=set_bool, default=1,
     6.9 +          use="""Try to find an unused port for the VNC server.
    6.10 +          Only valid when vnc=1.""")
    6.11 +
    6.12  gopts.var('sdl', val='',
    6.13            fn=set_value, default=None,
    6.14            use="""Should the device model use SDL?""")
    6.15 @@ -627,7 +632,7 @@ def configure_hvm(config_image, vals):
    6.16      """
    6.17      args = [ 'device_model', 'pae', 'vcpus', 'boot', 'fda', 'fdb',
    6.18               'localtime', 'serial', 'stdvga', 'isa', 'nographic', 'soundhw',
    6.19 -             'vnc', 'vncdisplay', 'vncconsole', 'sdl', 'display',
    6.20 +             'vnc', 'vncdisplay', 'vncunused', 'vncconsole', 'sdl', 'display',
    6.21               'acpi', 'apic', 'xauthority', 'usb', 'usbdevice' ]
    6.22      for a in args:
    6.23          if (vals.__dict__[a]):