# HG changeset patch
# User chris@xxxxxxxxxxxxxxxxxxxxxxxx
# Node ID bd04004865ba70a67fb797733ad1452d6b19b971
# Parent b16252dbcb1f99a22fcf4c87a015c47f6019cfd2
[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@xxxxxxxxxxxxx>
---
tools/examples/xmexample.hvm | 4 ++++
tools/ioemu/vl.c | 12 +++++++++++-
tools/ioemu/vl.h | 2 +-
tools/ioemu/vnc.c | 17 ++++++++++++-----
tools/python/xen/xend/image.py | 3 +++
tools/python/xen/xm/create.py | 7 ++++++-
6 files changed, 37 insertions(+), 8 deletions(-)
diff -r b16252dbcb1f -r bd04004865ba tools/examples/xmexample.hvm
--- a/tools/examples/xmexample.hvm Wed Aug 09 11:29:06 2006 +0100
+++ b/tools/examples/xmexample.hvm Wed Aug 09 15:03:38 2006 +0100
@@ -130,6 +130,10 @@ vnc=1
#vncdisplay=1
#----------------------------------------------------------------------------
+# try to find an unused port for the VNC server, default = 1
+#vncunused=1
+
+#----------------------------------------------------------------------------
# enable spawning vncviewer for domain's console
# (only valid when vnc=1), default = 0
#vncconsole=0
diff -r b16252dbcb1f -r bd04004865ba tools/ioemu/vl.c
--- a/tools/ioemu/vl.c Wed Aug 09 11:29:06 2006 +0100
+++ b/tools/ioemu/vl.c Wed Aug 09 15:03:38 2006 +0100
@@ -121,6 +121,7 @@ static DisplayState display_state;
static DisplayState display_state;
int nographic;
int vncviewer;
+int vncunused;
const char* keyboard_layout = NULL;
int64_t ticks_per_sec;
int boot_device = 'c';
@@ -5344,6 +5345,7 @@ void help(void)
"-loadvm file start right away with a saved state (loadvm in
monitor)\n"
"-vnc display start a VNC server on display\n"
"-vncviewer start a vncviewer process for this domain\n"
+ "-vncunused bind the VNC server to an unused port\n"
"-timeoffset time offset (in seconds) from local time\n"
"-acpi disable or enable ACPI of HVM domain \n"
"\n"
@@ -5435,6 +5437,7 @@ enum {
QEMU_OPTION_timeoffset,
QEMU_OPTION_acpi,
QEMU_OPTION_vncviewer,
+ QEMU_OPTION_vncunused,
};
typedef struct QEMUOption {
@@ -5512,6 +5515,7 @@ const QEMUOption qemu_options[] = {
{ "smp", HAS_ARG, QEMU_OPTION_smp },
{ "vnc", HAS_ARG, QEMU_OPTION_vnc },
{ "vncviewer", 0, QEMU_OPTION_vncviewer },
+ { "vncunused", 0, QEMU_OPTION_vncunused },
/* temporary options */
{ "usb", 0, QEMU_OPTION_usb },
@@ -5888,6 +5892,7 @@ int main(int argc, char **argv)
snapshot = 0;
nographic = 0;
vncviewer = 0;
+ vncunused = 0;
kernel_filename = NULL;
kernel_cmdline = "";
#ifndef CONFIG_DM
@@ -6295,6 +6300,11 @@ int main(int argc, char **argv)
case QEMU_OPTION_vncviewer:
vncviewer++;
break;
+ case QEMU_OPTION_vncunused:
+ vncunused++;
+ if (vnc_display == -1)
+ vnc_display = -2;
+ break;
}
}
}
@@ -6504,7 +6514,7 @@ int main(int argc, char **argv)
if (nographic) {
dumb_display_init(ds);
} else if (vnc_display != -1) {
- vnc_display_init(ds, vnc_display);
+ vnc_display = vnc_display_init(ds, vnc_display, vncunused);
if (vncviewer)
vnc_start_viewer(vnc_display);
xenstore_write_vncport(vnc_display);
diff -r b16252dbcb1f -r bd04004865ba tools/ioemu/vl.h
--- a/tools/ioemu/vl.h Wed Aug 09 11:29:06 2006 +0100
+++ b/tools/ioemu/vl.h Wed Aug 09 15:03:38 2006 +0100
@@ -784,7 +784,7 @@ void cocoa_display_init(DisplayState *ds
void cocoa_display_init(DisplayState *ds, int full_screen);
/* vnc.c */
-void vnc_display_init(DisplayState *ds, int display);
+int vnc_display_init(DisplayState *ds, int display, int find_unused);
int vnc_start_viewer(int port);
/* ide.c */
diff -r b16252dbcb1f -r bd04004865ba tools/ioemu/vnc.c
--- a/tools/ioemu/vnc.c Wed Aug 09 11:29:06 2006 +0100
+++ b/tools/ioemu/vnc.c Wed Aug 09 15:03:38 2006 +0100
@@ -1183,7 +1183,7 @@ static void vnc_listen_read(void *opaque
}
}
-void vnc_display_init(DisplayState *ds, int display)
+int vnc_display_init(DisplayState *ds, int display, int find_unused)
{
struct sockaddr_in addr;
int reuse_addr, ret;
@@ -1213,10 +1213,6 @@ void vnc_display_init(DisplayState *ds,
fprintf(stderr, "Could not create socket\n");
exit(1);
}
-
- addr.sin_family = AF_INET;
- addr.sin_port = htons(5900 + display);
- memset(&addr.sin_addr, 0, sizeof(addr.sin_addr));
reuse_addr = 1;
ret = setsockopt(vs->lsock, SOL_SOCKET, SO_REUSEADDR,
@@ -1226,7 +1222,16 @@ void vnc_display_init(DisplayState *ds,
exit(1);
}
+ retry:
+ addr.sin_family = AF_INET;
+ addr.sin_port = htons(5900 + display);
+ memset(&addr.sin_addr, 0, sizeof(addr.sin_addr));
+
if (bind(vs->lsock, (struct sockaddr *)&addr, sizeof(addr)) == -1) {
+ if (find_unused && errno == EADDRINUSE) {
+ display++;
+ goto retry;
+ }
fprintf(stderr, "bind() failed\n");
exit(1);
}
@@ -1247,6 +1252,8 @@ void vnc_display_init(DisplayState *ds,
vs->ds->dpy_refresh = vnc_dpy_refresh;
vnc_dpy_resize(vs->ds, 640, 400);
+
+ return display;
}
int vnc_start_viewer(int port)
diff -r b16252dbcb1f -r bd04004865ba tools/python/xen/xend/image.py
--- a/tools/python/xen/xend/image.py Wed Aug 09 11:29:06 2006 +0100
+++ b/tools/python/xen/xend/image.py Wed Aug 09 15:03:38 2006 +0100
@@ -307,6 +307,7 @@ class HVMImageHandler(ImageHandler):
vnc = sxp.child_value(config, 'vnc')
vncdisplay = sxp.child_value(config, 'vncdisplay',
int(self.vm.getDomid()))
+ vncunused = sxp.child_value(config, 'vncunused')
sdl = sxp.child_value(config, 'sdl')
ret = []
nographic = sxp.child_value(config, 'nographic')
@@ -315,6 +316,8 @@ class HVMImageHandler(ImageHandler):
return ret
if vnc:
ret = ret + ['-vnc', '%d' % vncdisplay, '-k', 'en-us']
+ if vncunused:
+ ret += ['-vncunused']
return ret
def createDeviceModel(self):
diff -r b16252dbcb1f -r bd04004865ba tools/python/xen/xm/create.py
--- a/tools/python/xen/xm/create.py Wed Aug 09 11:29:06 2006 +0100
+++ b/tools/python/xen/xm/create.py Wed Aug 09 15:03:38 2006 +0100
@@ -411,6 +411,11 @@ gopts.var('vncdisplay', val='',
gopts.var('vncdisplay', val='',
fn=set_value, default=None,
use="""VNC display to use""")
+
+gopts.var('vncunused', val='',
+ fn=set_bool, default=1,
+ use="""Try to find an unused port for the VNC server.
+ Only valid when vnc=1.""")
gopts.var('sdl', val='',
fn=set_value, default=None,
@@ -627,7 +632,7 @@ def configure_hvm(config_image, vals):
"""
args = [ 'device_model', 'pae', 'vcpus', 'boot', 'fda', 'fdb',
'localtime', 'serial', 'stdvga', 'isa', 'nographic', 'soundhw',
- 'vnc', 'vncdisplay', 'vncconsole', 'sdl', 'display',
+ 'vnc', 'vncdisplay', 'vncunused', 'vncconsole', 'sdl', 'display',
'acpi', 'apic', 'xauthority', 'usb', 'usbdevice' ]
for a in args:
if (vals.__dict__[a]):
_______________________________________________
Xen-changelog mailing list
Xen-changelog@xxxxxxxxxxxxxxxxxxx
http://lists.xensource.com/xen-changelog
|