ia64/xen-unstable

changeset 11031:fc6c3d866477

merge with xen-unstable.hg
author awilliam@xenbuild.aw
date Wed Aug 09 10:32:23 2006 -0600 (2006-08-09)
parents 111936ef4291 15304ad81c50
children 9105cc8a738c 9fc1979e9b00
files
line diff
     1.1 --- a/tools/examples/xmexample.hvm	Wed Aug 09 10:04:43 2006 -0600
     1.2 +++ b/tools/examples/xmexample.hvm	Wed Aug 09 10:32:23 2006 -0600
     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/patches/domain-timeoffset	Wed Aug 09 10:04:43 2006 -0600
     2.2 +++ b/tools/ioemu/patches/domain-timeoffset	Wed Aug 09 10:32:23 2006 -0600
     2.3 @@ -1,7 +1,7 @@
     2.4  Index: ioemu/hw/mc146818rtc.c
     2.5  ===================================================================
     2.6 ---- ioemu.orig/hw/mc146818rtc.c	2006-08-08 11:27:33.924822567 +0100
     2.7 -+++ ioemu/hw/mc146818rtc.c	2006-08-08 11:28:01.929698228 +0100
     2.8 +--- ioemu.orig/hw/mc146818rtc.c	2006-08-09 15:04:17.857242121 +0100
     2.9 ++++ ioemu/hw/mc146818rtc.c	2006-08-09 15:04:24.588603423 +0100
    2.10  @@ -178,10 +178,27 @@
    2.11       }
    2.12   }
    2.13 @@ -46,8 +46,8 @@ Index: ioemu/hw/mc146818rtc.c
    2.14   static void rtc_copy_date(RTCState *s)
    2.15  Index: ioemu/hw/pc.c
    2.16  ===================================================================
    2.17 ---- ioemu.orig/hw/pc.c	2006-08-08 11:27:58.117123572 +0100
    2.18 -+++ ioemu/hw/pc.c	2006-08-08 11:28:01.930698117 +0100
    2.19 +--- ioemu.orig/hw/pc.c	2006-08-09 15:04:24.316629266 +0100
    2.20 ++++ ioemu/hw/pc.c	2006-08-09 15:04:24.589603328 +0100
    2.21  @@ -159,7 +159,7 @@
    2.22   }
    2.23   
    2.24 @@ -117,8 +117,8 @@ Index: ioemu/hw/pc.c
    2.25   QEMUMachine pc_machine = {
    2.26  Index: ioemu/vl.c
    2.27  ===================================================================
    2.28 ---- ioemu.orig/vl.c	2006-08-08 11:28:01.787714069 +0100
    2.29 -+++ ioemu/vl.c	2006-08-08 11:28:01.933697782 +0100
    2.30 +--- ioemu.orig/vl.c	2006-08-09 15:04:24.457615869 +0100
    2.31 ++++ ioemu/vl.c	2006-08-09 15:04:24.592603043 +0100
    2.32  @@ -163,6 +163,8 @@
    2.33   
    2.34   int xc_handle;
    2.35 @@ -174,8 +174,8 @@ Index: ioemu/vl.c
    2.36       if (usb_enabled) {
    2.37  Index: ioemu/vl.h
    2.38  ===================================================================
    2.39 ---- ioemu.orig/vl.h	2006-08-08 11:28:01.517744187 +0100
    2.40 -+++ ioemu/vl.h	2006-08-08 11:28:01.934697671 +0100
    2.41 +--- ioemu.orig/vl.h	2006-08-09 15:04:24.321628791 +0100
    2.42 ++++ ioemu/vl.h	2006-08-09 15:04:24.593602948 +0100
    2.43  @@ -575,7 +575,7 @@
    2.44                                    int boot_device,
    2.45                DisplayState *ds, const char **fd_filename, int snapshot,
     3.1 --- a/tools/ioemu/patches/series	Wed Aug 09 10:04:43 2006 -0600
     3.2 +++ b/tools/ioemu/patches/series	Wed Aug 09 10:32:23 2006 -0600
     3.3 @@ -34,6 +34,7 @@ vnc-fixes
     3.4  vnc-start-vncviewer
     3.5  vnc-title-domain-name
     3.6  vnc-access-monitor-vt
     3.7 +vnc-display-find-unused
     3.8  xenstore-block-device-config
     3.9  xenstore-write-vnc-port
    3.10  qemu-allow-disable-sdl
     4.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     4.2 +++ b/tools/ioemu/patches/vnc-display-find-unused	Wed Aug 09 10:32:23 2006 -0600
     4.3 @@ -0,0 +1,128 @@
     4.4 +Index: ioemu/vnc.c
     4.5 +===================================================================
     4.6 +--- ioemu.orig/vnc.c	2006-08-09 14:44:44.721942535 +0100
     4.7 ++++ ioemu/vnc.c	2006-08-09 14:52:37.262165292 +0100
     4.8 +@@ -1183,7 +1183,7 @@
     4.9 +     }
    4.10 + }
    4.11 + 
    4.12 +-void vnc_display_init(DisplayState *ds, int display)
    4.13 ++int vnc_display_init(DisplayState *ds, int display, int find_unused)
    4.14 + {
    4.15 +     struct sockaddr_in addr;
    4.16 +     int reuse_addr, ret;
    4.17 +@@ -1214,10 +1214,6 @@
    4.18 + 	exit(1);
    4.19 +     }
    4.20 + 
    4.21 +-    addr.sin_family = AF_INET;
    4.22 +-    addr.sin_port = htons(5900 + display);
    4.23 +-    memset(&addr.sin_addr, 0, sizeof(addr.sin_addr));
    4.24 +-
    4.25 +     reuse_addr = 1;
    4.26 +     ret = setsockopt(vs->lsock, SOL_SOCKET, SO_REUSEADDR,
    4.27 + 		     (const char *)&reuse_addr, sizeof(reuse_addr));
    4.28 +@@ -1226,7 +1222,16 @@
    4.29 + 	exit(1);
    4.30 +     }
    4.31 + 
    4.32 ++ retry:
    4.33 ++    addr.sin_family = AF_INET;
    4.34 ++    addr.sin_port = htons(5900 + display);
    4.35 ++    memset(&addr.sin_addr, 0, sizeof(addr.sin_addr));
    4.36 ++
    4.37 +     if (bind(vs->lsock, (struct sockaddr *)&addr, sizeof(addr)) == -1) {
    4.38 ++	if (find_unused && errno == EADDRINUSE) {
    4.39 ++	    display++;
    4.40 ++	    goto retry;
    4.41 ++	}
    4.42 + 	fprintf(stderr, "bind() failed\n");
    4.43 + 	exit(1);
    4.44 +     }
    4.45 +@@ -1247,6 +1252,8 @@
    4.46 +     vs->ds->dpy_refresh = vnc_dpy_refresh;
    4.47 + 
    4.48 +     vnc_dpy_resize(vs->ds, 640, 400);
    4.49 ++
    4.50 ++    return display;
    4.51 + }
    4.52 + 
    4.53 + int vnc_start_viewer(int port)
    4.54 +Index: ioemu/vl.c
    4.55 +===================================================================
    4.56 +--- ioemu.orig/vl.c	2006-08-09 14:44:44.721942535 +0100
    4.57 ++++ ioemu/vl.c	2006-08-09 14:52:06.783905832 +0100
    4.58 +@@ -121,6 +121,7 @@
    4.59 + static DisplayState display_state;
    4.60 + int nographic;
    4.61 + int vncviewer;
    4.62 ++int vncunused;
    4.63 + const char* keyboard_layout = NULL;
    4.64 + int64_t ticks_per_sec;
    4.65 + int boot_device = 'c';
    4.66 +@@ -5342,6 +5343,7 @@
    4.67 +            "-loadvm file    start right away with a saved state (loadvm in monitor)\n"
    4.68 + 	   "-vnc display    start a VNC server on display\n"
    4.69 +            "-vncviewer      start a vncviewer process for this domain\n"
    4.70 ++           "-vncunused      bind the VNC server to an unused port\n"
    4.71 +            "-timeoffset     time offset (in seconds) from local time\n"
    4.72 +            "-acpi           disable or enable ACPI of HVM domain \n"
    4.73 +            "\n"
    4.74 +@@ -5431,6 +5433,7 @@
    4.75 +     QEMU_OPTION_timeoffset,
    4.76 +     QEMU_OPTION_acpi,
    4.77 +     QEMU_OPTION_vncviewer,
    4.78 ++    QEMU_OPTION_vncunused,
    4.79 + };
    4.80 + 
    4.81 + typedef struct QEMUOption {
    4.82 +@@ -5506,6 +5509,7 @@
    4.83 +     { "smp", HAS_ARG, QEMU_OPTION_smp },
    4.84 +     { "vnc", HAS_ARG, QEMU_OPTION_vnc },
    4.85 +     { "vncviewer", 0, QEMU_OPTION_vncviewer },
    4.86 ++    { "vncunused", 0, QEMU_OPTION_vncunused },
    4.87 +     
    4.88 +     /* temporary options */
    4.89 +     { "usb", 0, QEMU_OPTION_usb },
    4.90 +@@ -5873,6 +5877,7 @@
    4.91 +     snapshot = 0;
    4.92 +     nographic = 0;
    4.93 +     vncviewer = 0;
    4.94 ++    vncunused = 0;
    4.95 +     kernel_filename = NULL;
    4.96 +     kernel_cmdline = "";
    4.97 + #ifdef TARGET_PPC
    4.98 +@@ -6270,6 +6275,11 @@
    4.99 +             case QEMU_OPTION_vncviewer:
   4.100 +                 vncviewer++;
   4.101 +                 break;
   4.102 ++            case QEMU_OPTION_vncunused:
   4.103 ++                vncunused++;
   4.104 ++                if (vnc_display == -1)
   4.105 ++                    vnc_display = -2;
   4.106 ++                break;
   4.107 +             }
   4.108 +         }
   4.109 +     }
   4.110 +@@ -6465,7 +6475,7 @@
   4.111 +     if (nographic) {
   4.112 +         dumb_display_init(ds);
   4.113 +     } else if (vnc_display != -1) {
   4.114 +-	vnc_display_init(ds, vnc_display);
   4.115 ++	vnc_display = vnc_display_init(ds, vnc_display, vncunused);
   4.116 + 	if (vncviewer)
   4.117 + 	    vnc_start_viewer(vnc_display);
   4.118 +     } else {
   4.119 +Index: ioemu/vl.h
   4.120 +===================================================================
   4.121 +--- ioemu.orig/vl.h	2006-08-09 14:44:44.721942535 +0100
   4.122 ++++ ioemu/vl.h	2006-08-09 14:52:06.783905832 +0100
   4.123 +@@ -784,7 +784,7 @@
   4.124 + void cocoa_display_init(DisplayState *ds, int full_screen);
   4.125 + 
   4.126 + /* vnc.c */
   4.127 +-void vnc_display_init(DisplayState *ds, int display);
   4.128 ++int vnc_display_init(DisplayState *ds, int display, int find_unused);
   4.129 + int vnc_start_viewer(int port);
   4.130 + 
   4.131 + /* ide.c */
     5.1 --- a/tools/ioemu/patches/xen-support-buffered-ioreqs	Wed Aug 09 10:04:43 2006 -0600
     5.2 +++ b/tools/ioemu/patches/xen-support-buffered-ioreqs	Wed Aug 09 10:32:23 2006 -0600
     5.3 @@ -1,8 +1,8 @@
     5.4  Index: ioemu/vl.c
     5.5  ===================================================================
     5.6 ---- ioemu.orig/vl.c	2006-08-08 14:33:30.000000000 +0100
     5.7 -+++ ioemu/vl.c	2006-08-08 14:43:34.000000000 +0100
     5.8 -@@ -5834,6 +5834,7 @@
     5.9 +--- ioemu.orig/vl.c	2006-08-09 15:04:25.583508863 +0100
    5.10 ++++ ioemu/vl.c	2006-08-09 15:04:26.034465993 +0100
    5.11 +@@ -5838,6 +5838,7 @@
    5.12       unsigned long nr_pages;
    5.13       xen_pfn_t *page_array;
    5.14       extern void *shared_page;
    5.15 @@ -10,7 +10,7 @@ Index: ioemu/vl.c
    5.16   
    5.17       char qemu_dm_logfilename[64];
    5.18   
    5.19 -@@ -6378,12 +6379,17 @@
    5.20 +@@ -6388,12 +6389,17 @@
    5.21   
    5.22       phys_ram_base = xc_map_foreign_batch(xc_handle, domid,
    5.23                                            PROT_READ|PROT_WRITE, page_array,
    5.24 @@ -31,8 +31,8 @@ Index: ioemu/vl.c
    5.25                                          page_array[nr_pages - 1]);
    5.26  Index: ioemu/target-i386-dm/helper2.c
    5.27  ===================================================================
    5.28 ---- ioemu.orig/target-i386-dm/helper2.c	2006-08-08 14:33:30.000000000 +0100
    5.29 -+++ ioemu/target-i386-dm/helper2.c	2006-08-09 10:03:40.558744653 +0100
    5.30 +--- ioemu.orig/target-i386-dm/helper2.c	2006-08-09 15:04:24.105649313 +0100
    5.31 ++++ ioemu/target-i386-dm/helper2.c	2006-08-09 15:04:26.040465422 +0100
    5.32  @@ -76,6 +76,10 @@
    5.33   
    5.34   shared_iopage_t *shared_page = NULL;
     6.1 --- a/tools/ioemu/patches/xenstore-block-device-config	Wed Aug 09 10:04:43 2006 -0600
     6.2 +++ b/tools/ioemu/patches/xenstore-block-device-config	Wed Aug 09 10:32:23 2006 -0600
     6.3 @@ -1,7 +1,7 @@
     6.4  Index: ioemu/Makefile.target
     6.5  ===================================================================
     6.6 ---- ioemu.orig/Makefile.target	2006-08-07 17:42:27.802386071 +0100
     6.7 -+++ ioemu/Makefile.target	2006-08-07 17:42:28.683289358 +0100
     6.8 +--- ioemu.orig/Makefile.target	2006-08-09 15:04:24.795583755 +0100
     6.9 ++++ ioemu/Makefile.target	2006-08-09 15:04:25.373528824 +0100
    6.10  @@ -358,6 +358,7 @@
    6.11   VL_OBJS+= cirrus_vga.o mixeng.o parallel.o acpi.o piix_pci.o
    6.12   VL_OBJS+= usb-uhci.o
    6.13 @@ -13,7 +13,7 @@ Index: ioemu/Makefile.target
    6.14  Index: ioemu/xenstore.c
    6.15  ===================================================================
    6.16  --- /dev/null	1970-01-01 00:00:00.000000000 +0000
    6.17 -+++ ioemu/xenstore.c	2006-08-07 17:42:28.684289249 +0100
    6.18 ++++ ioemu/xenstore.c	2006-08-09 15:04:25.374528729 +0100
    6.19  @@ -0,0 +1,187 @@
    6.20  +/*
    6.21  + * This file is subject to the terms and conditions of the GNU General
    6.22 @@ -204,9 +204,9 @@ Index: ioemu/xenstore.c
    6.23  +}
    6.24  Index: ioemu/vl.c
    6.25  ===================================================================
    6.26 ---- ioemu.orig/vl.c	2006-08-07 17:42:28.393320909 +0100
    6.27 -+++ ioemu/vl.c	2006-08-07 17:42:28.687288922 +0100
    6.28 -@@ -5242,9 +5242,11 @@
    6.29 +--- ioemu.orig/vl.c	2006-08-09 15:04:25.312534622 +0100
    6.30 ++++ ioemu/vl.c	2006-08-09 15:04:25.377528443 +0100
    6.31 +@@ -5243,9 +5243,11 @@
    6.32              "Standard options:\n"
    6.33              "-M machine      select emulated machine (-M ? for list)\n"
    6.34              "-fda/-fdb file  use 'file' as floppy disk 0/1 image\n"
    6.35 @@ -218,7 +218,7 @@ Index: ioemu/vl.c
    6.36              "-boot [a|c|d]   boot on floppy (a), hard disk (c) or CD-ROM (d)\n"
    6.37   	   "-snapshot       write to temporary files instead of disk image files\n"
    6.38   #ifdef TARGET_I386
    6.39 -@@ -5370,11 +5372,13 @@
    6.40 +@@ -5372,11 +5374,13 @@
    6.41       QEMU_OPTION_M,
    6.42       QEMU_OPTION_fda,
    6.43       QEMU_OPTION_fdb,
    6.44 @@ -232,7 +232,7 @@ Index: ioemu/vl.c
    6.45       QEMU_OPTION_boot,
    6.46       QEMU_OPTION_snapshot,
    6.47   #ifdef TARGET_I386
    6.48 -@@ -5445,11 +5449,13 @@
    6.49 +@@ -5448,11 +5452,13 @@
    6.50       { "M", HAS_ARG, QEMU_OPTION_M },
    6.51       { "fda", HAS_ARG, QEMU_OPTION_fda },
    6.52       { "fdb", HAS_ARG, QEMU_OPTION_fdb },
    6.53 @@ -246,7 +246,7 @@ Index: ioemu/vl.c
    6.54       { "boot", HAS_ARG, QEMU_OPTION_boot },
    6.55       { "snapshot", 0, QEMU_OPTION_snapshot },
    6.56   #ifdef TARGET_I386
    6.57 -@@ -5797,10 +5803,16 @@
    6.58 +@@ -5801,10 +5807,16 @@
    6.59   #ifdef CONFIG_GDBSTUB
    6.60       int use_gdbstub, gdbstub_port;
    6.61   #endif
    6.62 @@ -265,7 +265,7 @@ Index: ioemu/vl.c
    6.63       const char *kernel_filename, *kernel_cmdline;
    6.64       DisplayState *ds = &display_state;
    6.65       int cyls, heads, secs, translation;
    6.66 -@@ -5861,8 +5873,10 @@
    6.67 +@@ -5865,8 +5877,10 @@
    6.68       initrd_filename = NULL;
    6.69       for(i = 0; i < MAX_FD; i++)
    6.70           fd_filename[i] = NULL;
    6.71 @@ -276,8 +276,8 @@ Index: ioemu/vl.c
    6.72       ram_size = DEFAULT_RAM_SIZE * 1024 * 1024;
    6.73       vga_ram_size = VGA_RAM_SIZE;
    6.74       bios_size = BIOS_SIZE;
    6.75 -@@ -5875,11 +5889,13 @@
    6.76 -     vncviewer = 0;
    6.77 +@@ -5880,11 +5894,13 @@
    6.78 +     vncunused = 0;
    6.79       kernel_filename = NULL;
    6.80       kernel_cmdline = "";
    6.81  +#ifndef CONFIG_DM
    6.82 @@ -290,7 +290,7 @@ Index: ioemu/vl.c
    6.83       cyls = heads = secs = 0;
    6.84       translation = BIOS_ATA_TRANSLATION_AUTO;
    6.85       pstrcpy(monitor_device, sizeof(monitor_device), "vc");
    6.86 -@@ -5912,7 +5928,11 @@
    6.87 +@@ -5917,7 +5933,11 @@
    6.88               break;
    6.89           r = argv[optind];
    6.90           if (r[0] != '-') {
    6.91 @@ -302,7 +302,7 @@ Index: ioemu/vl.c
    6.92           } else {
    6.93               const QEMUOption *popt;
    6.94   
    6.95 -@@ -5956,6 +5976,7 @@
    6.96 +@@ -5961,6 +5981,7 @@
    6.97               case QEMU_OPTION_initrd:
    6.98                   initrd_filename = optarg;
    6.99                   break;
   6.100 @@ -310,7 +310,7 @@ Index: ioemu/vl.c
   6.101               case QEMU_OPTION_hda:
   6.102               case QEMU_OPTION_hdb:
   6.103               case QEMU_OPTION_hdc:
   6.104 -@@ -5968,6 +5989,7 @@
   6.105 +@@ -5973,6 +5994,7 @@
   6.106                           cdrom_index = -1;
   6.107                   }
   6.108                   break;
   6.109 @@ -318,7 +318,7 @@ Index: ioemu/vl.c
   6.110               case QEMU_OPTION_snapshot:
   6.111                   snapshot = 1;
   6.112                   break;
   6.113 -@@ -6020,11 +6042,13 @@
   6.114 +@@ -6025,11 +6047,13 @@
   6.115               case QEMU_OPTION_append:
   6.116                   kernel_cmdline = optarg;
   6.117                   break;
   6.118 @@ -332,7 +332,7 @@ Index: ioemu/vl.c
   6.119               case QEMU_OPTION_boot:
   6.120                   boot_device = optarg[0];
   6.121                   if (boot_device != 'a' && 
   6.122 -@@ -6274,12 +6298,18 @@
   6.123 +@@ -6284,12 +6308,18 @@
   6.124           }
   6.125       }
   6.126   
   6.127 @@ -351,7 +351,7 @@ Index: ioemu/vl.c
   6.128       if (!linux_boot && 
   6.129           hd_filename[0] == '\0' && 
   6.130           (cdrom_index >= 0 && hd_filename[cdrom_index] == '\0') &&
   6.131 -@@ -6293,6 +6323,7 @@
   6.132 +@@ -6303,6 +6333,7 @@
   6.133           else
   6.134               boot_device = 'd';
   6.135       }
   6.136 @@ -359,7 +359,7 @@ Index: ioemu/vl.c
   6.137   
   6.138       setvbuf(stdout, NULL, _IOLBF, 0);
   6.139       
   6.140 -@@ -6407,6 +6438,7 @@
   6.141 +@@ -6417,6 +6448,7 @@
   6.142   
   6.143   #endif /* !CONFIG_DM */
   6.144   
   6.145 @@ -367,7 +367,7 @@ Index: ioemu/vl.c
   6.146       /* we always create the cdrom drive, even if no disk is there */
   6.147       bdrv_init();
   6.148       if (cdrom_index >= 0) {
   6.149 -@@ -6433,6 +6465,7 @@
   6.150 +@@ -6443,6 +6475,7 @@
   6.151               }
   6.152           }
   6.153       }
   6.154 @@ -375,7 +375,7 @@ Index: ioemu/vl.c
   6.155   
   6.156       /* we always create at least one floppy disk */
   6.157       fd_table[0] = bdrv_new("fda");
   6.158 -@@ -6511,6 +6544,8 @@
   6.159 +@@ -6521,6 +6554,8 @@
   6.160           }
   6.161       }
   6.162   
   6.163 @@ -386,8 +386,8 @@ Index: ioemu/vl.c
   6.164                     kernel_filename, kernel_cmdline, initrd_filename,
   6.165  Index: ioemu/monitor.c
   6.166  ===================================================================
   6.167 ---- ioemu.orig/monitor.c	2006-08-07 17:42:27.132461888 +0100
   6.168 -+++ ioemu/monitor.c	2006-08-07 17:42:28.688288814 +0100
   6.169 +--- ioemu.orig/monitor.c	2006-08-09 15:04:24.105649313 +0100
   6.170 ++++ ioemu/monitor.c	2006-08-09 15:04:25.379528253 +0100
   6.171  @@ -24,6 +24,7 @@
   6.172   #include "vl.h"
   6.173   #include "disas.h"
   6.174 @@ -416,8 +416,8 @@ Index: ioemu/monitor.c
   6.175       int i;
   6.176  Index: ioemu/block.c
   6.177  ===================================================================
   6.178 ---- ioemu.orig/block.c	2006-08-07 17:42:21.704076241 +0100
   6.179 -+++ ioemu/block.c	2006-08-07 17:42:28.689288705 +0100
   6.180 +--- ioemu.orig/block.c	2006-08-09 15:04:17.487277167 +0100
   6.181 ++++ ioemu/block.c	2006-08-09 15:04:25.379528253 +0100
   6.182  @@ -758,6 +758,7 @@
   6.183   static void raw_close(BlockDriverState *bs)
   6.184   {
   6.185 @@ -428,8 +428,8 @@ Index: ioemu/block.c
   6.186   
   6.187  Index: ioemu/vl.h
   6.188  ===================================================================
   6.189 ---- ioemu.orig/vl.h	2006-08-07 17:42:28.394320800 +0100
   6.190 -+++ ioemu/vl.h	2006-08-07 17:42:28.689288705 +0100
   6.191 +--- ioemu.orig/vl.h	2006-08-09 15:04:25.313534527 +0100
   6.192 ++++ ioemu/vl.h	2006-08-09 15:04:25.380528158 +0100
   6.193  @@ -1184,6 +1184,8 @@
   6.194   void term_print_help(void);
   6.195   void monitor_readline(const char *prompt, int is_password,
   6.196 @@ -455,8 +455,8 @@ Index: ioemu/vl.h
   6.197   extern char domain_name[];
   6.198  Index: ioemu/hw/ide.c
   6.199  ===================================================================
   6.200 ---- ioemu.orig/hw/ide.c	2006-08-07 17:42:27.552414361 +0100
   6.201 -+++ ioemu/hw/ide.c	2006-08-07 17:42:28.691288487 +0100
   6.202 +--- ioemu.orig/hw/ide.c	2006-08-09 15:04:24.524609503 +0100
   6.203 ++++ ioemu/hw/ide.c	2006-08-09 15:04:25.381528063 +0100
   6.204  @@ -1158,6 +1158,7 @@
   6.205           } else {
   6.206               ide_atapi_cmd_error(s, SENSE_NOT_READY, 
     7.1 --- a/tools/ioemu/patches/xenstore-write-vnc-port	Wed Aug 09 10:04:43 2006 -0600
     7.2 +++ b/tools/ioemu/patches/xenstore-write-vnc-port	Wed Aug 09 10:32:23 2006 -0600
     7.3 @@ -1,7 +1,7 @@
     7.4  Index: ioemu/xenstore.c
     7.5  ===================================================================
     7.6 ---- ioemu.orig/xenstore.c	2006-08-07 17:42:28.684289249 +0100
     7.7 -+++ ioemu/xenstore.c	2006-08-07 17:42:28.891266728 +0100
     7.8 +--- ioemu.orig/xenstore.c	2006-08-09 15:04:25.374528729 +0100
     7.9 ++++ ioemu/xenstore.c	2006-08-09 15:04:25.579509243 +0100
    7.10  @@ -185,3 +185,31 @@
    7.11       free(image);
    7.12       free(vec);
    7.13 @@ -36,10 +36,10 @@ Index: ioemu/xenstore.c
    7.14  +}
    7.15  Index: ioemu/vl.c
    7.16  ===================================================================
    7.17 ---- ioemu.orig/vl.c	2006-08-07 17:42:28.687288922 +0100
    7.18 -+++ ioemu/vl.c	2006-08-07 17:42:28.894266401 +0100
    7.19 -@@ -6501,6 +6501,7 @@
    7.20 - 	vnc_display_init(ds, vnc_display);
    7.21 +--- ioemu.orig/vl.c	2006-08-09 15:04:25.377528443 +0100
    7.22 ++++ ioemu/vl.c	2006-08-09 15:04:25.583508863 +0100
    7.23 +@@ -6511,6 +6511,7 @@
    7.24 + 	vnc_display = vnc_display_init(ds, vnc_display, vncunused);
    7.25   	if (vncviewer)
    7.26   	    vnc_start_viewer(vnc_display);
    7.27  +	xenstore_write_vncport(vnc_display);
    7.28 @@ -48,8 +48,8 @@ Index: ioemu/vl.c
    7.29           sdl_display_init(ds, full_screen);
    7.30  Index: ioemu/vl.h
    7.31  ===================================================================
    7.32 ---- ioemu.orig/vl.h	2006-08-07 17:42:28.689288705 +0100
    7.33 -+++ ioemu/vl.h	2006-08-07 17:42:28.895266293 +0100
    7.34 +--- ioemu.orig/vl.h	2006-08-09 15:04:25.380528158 +0100
    7.35 ++++ ioemu/vl.h	2006-08-09 15:04:25.584508768 +0100
    7.36  @@ -1203,6 +1203,7 @@
    7.37   int xenstore_fd(void);
    7.38   void xenstore_process_event(void *opaque);
     8.1 --- a/tools/ioemu/vl.c	Wed Aug 09 10:04:43 2006 -0600
     8.2 +++ b/tools/ioemu/vl.c	Wed Aug 09 10:32:23 2006 -0600
     8.3 @@ -121,6 +121,7 @@ int bios_size;
     8.4  static DisplayState display_state;
     8.5  int nographic;
     8.6  int vncviewer;
     8.7 +int vncunused;
     8.8  const char* keyboard_layout = NULL;
     8.9  int64_t ticks_per_sec;
    8.10  int boot_device = 'c';
    8.11 @@ -5344,6 +5345,7 @@ void help(void)
    8.12             "-loadvm file    start right away with a saved state (loadvm in monitor)\n"
    8.13  	   "-vnc display    start a VNC server on display\n"
    8.14             "-vncviewer      start a vncviewer process for this domain\n"
    8.15 +           "-vncunused      bind the VNC server to an unused port\n"
    8.16             "-timeoffset     time offset (in seconds) from local time\n"
    8.17             "-acpi           disable or enable ACPI of HVM domain \n"
    8.18             "\n"
    8.19 @@ -5435,6 +5437,7 @@ enum {
    8.20      QEMU_OPTION_timeoffset,
    8.21      QEMU_OPTION_acpi,
    8.22      QEMU_OPTION_vncviewer,
    8.23 +    QEMU_OPTION_vncunused,
    8.24  };
    8.25  
    8.26  typedef struct QEMUOption {
    8.27 @@ -5512,6 +5515,7 @@ const QEMUOption qemu_options[] = {
    8.28      { "smp", HAS_ARG, QEMU_OPTION_smp },
    8.29      { "vnc", HAS_ARG, QEMU_OPTION_vnc },
    8.30      { "vncviewer", 0, QEMU_OPTION_vncviewer },
    8.31 +    { "vncunused", 0, QEMU_OPTION_vncunused },
    8.32      
    8.33      /* temporary options */
    8.34      { "usb", 0, QEMU_OPTION_usb },
    8.35 @@ -5888,6 +5892,7 @@ int main(int argc, char **argv)
    8.36      snapshot = 0;
    8.37      nographic = 0;
    8.38      vncviewer = 0;
    8.39 +    vncunused = 0;
    8.40      kernel_filename = NULL;
    8.41      kernel_cmdline = "";
    8.42  #ifndef CONFIG_DM
    8.43 @@ -6295,6 +6300,11 @@ int main(int argc, char **argv)
    8.44              case QEMU_OPTION_vncviewer:
    8.45                  vncviewer++;
    8.46                  break;
    8.47 +            case QEMU_OPTION_vncunused:
    8.48 +                vncunused++;
    8.49 +                if (vnc_display == -1)
    8.50 +                    vnc_display = -2;
    8.51 +                break;
    8.52              }
    8.53          }
    8.54      }
    8.55 @@ -6504,7 +6514,7 @@ int main(int argc, char **argv)
    8.56      if (nographic) {
    8.57          dumb_display_init(ds);
    8.58      } else if (vnc_display != -1) {
    8.59 -	vnc_display_init(ds, vnc_display);
    8.60 +	vnc_display = vnc_display_init(ds, vnc_display, vncunused);
    8.61  	if (vncviewer)
    8.62  	    vnc_start_viewer(vnc_display);
    8.63  	xenstore_write_vncport(vnc_display);
     9.1 --- a/tools/ioemu/vl.h	Wed Aug 09 10:04:43 2006 -0600
     9.2 +++ b/tools/ioemu/vl.h	Wed Aug 09 10:32:23 2006 -0600
     9.3 @@ -784,7 +784,7 @@ void sdl_display_init(DisplayState *ds, 
     9.4  void cocoa_display_init(DisplayState *ds, int full_screen);
     9.5  
     9.6  /* vnc.c */
     9.7 -void vnc_display_init(DisplayState *ds, int display);
     9.8 +int vnc_display_init(DisplayState *ds, int display, int find_unused);
     9.9  int vnc_start_viewer(int port);
    9.10  
    9.11  /* ide.c */
    10.1 --- a/tools/ioemu/vnc.c	Wed Aug 09 10:04:43 2006 -0600
    10.2 +++ b/tools/ioemu/vnc.c	Wed Aug 09 10:32:23 2006 -0600
    10.3 @@ -1183,7 +1183,7 @@ static void vnc_listen_read(void *opaque
    10.4      }
    10.5  }
    10.6  
    10.7 -void vnc_display_init(DisplayState *ds, int display)
    10.8 +int vnc_display_init(DisplayState *ds, int display, int find_unused)
    10.9  {
   10.10      struct sockaddr_in addr;
   10.11      int reuse_addr, ret;
   10.12 @@ -1214,10 +1214,6 @@ void vnc_display_init(DisplayState *ds, 
   10.13  	exit(1);
   10.14      }
   10.15  
   10.16 -    addr.sin_family = AF_INET;
   10.17 -    addr.sin_port = htons(5900 + display);
   10.18 -    memset(&addr.sin_addr, 0, sizeof(addr.sin_addr));
   10.19 -
   10.20      reuse_addr = 1;
   10.21      ret = setsockopt(vs->lsock, SOL_SOCKET, SO_REUSEADDR,
   10.22  		     (const char *)&reuse_addr, sizeof(reuse_addr));
   10.23 @@ -1226,7 +1222,16 @@ void vnc_display_init(DisplayState *ds, 
   10.24  	exit(1);
   10.25      }
   10.26  
   10.27 + retry:
   10.28 +    addr.sin_family = AF_INET;
   10.29 +    addr.sin_port = htons(5900 + display);
   10.30 +    memset(&addr.sin_addr, 0, sizeof(addr.sin_addr));
   10.31 +
   10.32      if (bind(vs->lsock, (struct sockaddr *)&addr, sizeof(addr)) == -1) {
   10.33 +	if (find_unused && errno == EADDRINUSE) {
   10.34 +	    display++;
   10.35 +	    goto retry;
   10.36 +	}
   10.37  	fprintf(stderr, "bind() failed\n");
   10.38  	exit(1);
   10.39      }
   10.40 @@ -1247,6 +1252,8 @@ void vnc_display_init(DisplayState *ds, 
   10.41      vs->ds->dpy_refresh = vnc_dpy_refresh;
   10.42  
   10.43      vnc_dpy_resize(vs->ds, 640, 400);
   10.44 +
   10.45 +    return display;
   10.46  }
   10.47  
   10.48  int vnc_start_viewer(int port)
    11.1 --- a/tools/python/xen/xend/image.py	Wed Aug 09 10:04:43 2006 -0600
    11.2 +++ b/tools/python/xen/xend/image.py	Wed Aug 09 10:32:23 2006 -0600
    11.3 @@ -307,6 +307,7 @@ class HVMImageHandler(ImageHandler):
    11.4          vnc = sxp.child_value(config, 'vnc')
    11.5          vncdisplay = sxp.child_value(config, 'vncdisplay',
    11.6                                       int(self.vm.getDomid()))
    11.7 +        vncunused = sxp.child_value(config, 'vncunused')
    11.8          sdl = sxp.child_value(config, 'sdl')
    11.9          ret = []
   11.10          nographic = sxp.child_value(config, 'nographic')
   11.11 @@ -315,6 +316,8 @@ class HVMImageHandler(ImageHandler):
   11.12              return ret
   11.13          if vnc:
   11.14              ret = ret + ['-vnc', '%d' % vncdisplay, '-k', 'en-us']
   11.15 +        if vncunused:
   11.16 +            ret += ['-vncunused']
   11.17          return ret
   11.18  
   11.19      def createDeviceModel(self):
    12.1 --- a/tools/python/xen/xm/create.py	Wed Aug 09 10:04:43 2006 -0600
    12.2 +++ b/tools/python/xen/xm/create.py	Wed Aug 09 10:32:23 2006 -0600
    12.3 @@ -412,6 +412,11 @@ gopts.var('vncdisplay', val='',
    12.4            fn=set_value, default=None,
    12.5            use="""VNC display to use""")
    12.6  
    12.7 +gopts.var('vncunused', val='',
    12.8 +          fn=set_bool, default=1,
    12.9 +          use="""Try to find an unused port for the VNC server.
   12.10 +          Only valid when vnc=1.""")
   12.11 +
   12.12  gopts.var('sdl', val='',
   12.13            fn=set_value, default=None,
   12.14            use="""Should the device model use SDL?""")
   12.15 @@ -627,7 +632,7 @@ def configure_hvm(config_image, vals):
   12.16      """
   12.17      args = [ 'device_model', 'pae', 'vcpus', 'boot', 'fda', 'fdb',
   12.18               'localtime', 'serial', 'stdvga', 'isa', 'nographic', 'soundhw',
   12.19 -             'vnc', 'vncdisplay', 'vncconsole', 'sdl', 'display',
   12.20 +             'vnc', 'vncdisplay', 'vncunused', 'vncconsole', 'sdl', 'display',
   12.21               'acpi', 'apic', 'xauthority', 'usb', 'usbdevice' ]
   12.22      for a in args:
   12.23          if (vals.__dict__[a]):