[Qemu-devel] [PATCH 08/27] usb: Remove unused usb_device_add() parameter is_hotplug

2010-06-04 Thread Kevin Wolf
From: Markus Armbruster 

Unused since commit b3e461d3.

Signed-off-by: Markus Armbruster 
Signed-off-by: Kevin Wolf 
---
 vl.c |6 +++---
 1 files changed, 3 insertions(+), 3 deletions(-)

diff --git a/vl.c b/vl.c
index 9283469..76a9b25 100644
--- a/vl.c
+++ b/vl.c
@@ -1315,7 +1315,7 @@ static void smp_parse(const char *optarg)
 /***/
 /* USB devices */
 
-static int usb_device_add(const char *devname, int is_hotplug)
+static int usb_device_add(const char *devname)
 {
 const char *p;
 USBDevice *dev = NULL;
@@ -1367,7 +1367,7 @@ static int usb_device_del(const char *devname)
 static int usb_parse(const char *cmdline)
 {
 int r;
-r = usb_device_add(cmdline, 0);
+r = usb_device_add(cmdline);
 if (r < 0) {
 fprintf(stderr, "qemu: could not add USB device '%s'\n", cmdline);
 }
@@ -1377,7 +1377,7 @@ static int usb_parse(const char *cmdline)
 void do_usb_add(Monitor *mon, const QDict *qdict)
 {
 const char *devname = qdict_get_str(qdict, "devname");
-if (usb_device_add(devname, 1) < 0) {
+if (usb_device_add(devname) < 0) {
 error_report("could not add USB device '%s'", devname);
 }
 }
-- 
1.6.6.1




[Qemu-devel] [PULL 00/27] Block patches

2010-06-04 Thread Kevin Wolf
The following changes since commit 358c360feb346dff8f911e2d1dbcdd6319393f1d:
  Anthony Liguori (1):
Merge remote branch 'kwolf/for-anthony' into staging

are available in the git repository at:

  git://repo.or.cz/qemu/kevin.git for-anthony

Jes Sorensen (4):
  Cleanup: bdrv_open() no need to shift total_size just to shift back.
  Cleanup: Be consistent and use BDRV_SECTOR_SIZE instead of 512
  Cleanup: raw-posix.c: Be more consistent using BDRV_SECTOR_SIZE instead 
of 512
  Cleanup: virtio-blk.c: Be more consistent using BDRV_SECTOR_SIZE instead

Kevin Wolf (3):
  qemu-io: Fix error messages
  Fix error message in drive_init
  block: Assume raw for drives without media

Luiz Capitulino (1):
  block: Fix serial number assignment

MORITA Kazutaka (2):
  close all the block drivers before the qemu process exits
  block: call the snapshot handlers of the protocol drivers

Markus Armbruster (17):
  blockdev: Belatedly remove MAX_DRIVES
  blockdev: Belatedly remove driveopts
  usb: Remove unused usb_device_add() parameter is_hotplug
  ide: Remove useless IDEDeviceInfo members unit, drive
  ide: Remove redundant IDEState member conf
  ide: Split ide_init1() off ide_init2()
  ide: Change ide_init_drive() to require valid dinfo argument
  ide: Split non-qdev code off ide_init2()
  qdev: New qdev_prop_set_string()
  qdev: Don't leak string property value on hot unplug
  ide: Turn drive serial into a qdev property ide-drive.serial
  ide: Fix info qtree for ide-drive.ver
  scsi: Turn drive serial into a qdev property scsi-disk.serial
  scsi: Fix info qtree for scsi-disk.ver
  blockdev: Hide QEMUMachine from drive_init()
  qdev: Move declaration of qdev_init_bdrv() into qdev.h
  blockdev: Collect block device code in new blockdev.c

 Makefile.objs|2 +-
 block.c  |   91 ++---
 block.h  |1 +
 block/raw-posix.c|   20 +-
 blockdev.c   |  600 ++
 blockdev.h   |   71 ++
 hw/acpi_piix4.c  |1 +
 hw/apb_pci.c |1 +
 hw/device-hotplug.c  |4 +-
 hw/fdc.c |1 -
 hw/fdc.h |2 +-
 hw/ide/cmd646.c  |4 +-
 hw/ide/core.c|  108 +
 hw/ide/internal.h|   13 +-
 hw/ide/isa.c |2 +-
 hw/ide/macio.c   |2 +-
 hw/ide/microdrive.c  |3 +-
 hw/ide/mmio.c|2 +-
 hw/ide/piix.c|4 +-
 hw/ide/qdev.c|   21 ++-
 hw/lan9118.c |1 +
 hw/nand.c|3 +-
 hw/omap2.c   |2 +
 hw/onenand.c |3 +-
 hw/parallel.c|1 +
 hw/pc.c  |1 +
 hw/pc_piix.c |1 +
 hw/pci-hotplug.c |2 -
 hw/pcmcia.h  |2 +-
 hw/pl181.c   |1 -
 hw/qdev-properties.c |   12 +-
 hw/qdev.c|6 +
 hw/qdev.h|6 +-
 hw/scsi-bus.c|1 -
 hw/scsi-disk.c   |   26 ++-
 hw/scsi-generic.c|1 -
 hw/serial.c  |1 +
 hw/ssi-sd.c  |1 -
 hw/usb-hid.c |1 +
 hw/usb-msd.c |4 +-
 hw/virtio-blk.c  |9 +-
 hw/virtio-pci.c  |1 -
 monitor.c|  104 +-
 qemu-char.c  |1 -
 qemu-io.c|4 +-
 savevm.c |2 +-
 sysemu.h |   52 -
 vl.c |  499 +-
 48 files changed, 916 insertions(+), 785 deletions(-)
 create mode 100644 blockdev.c
 create mode 100644 blockdev.h



[Qemu-devel] Re: [PATCH v3] savevm: Really verify if a drive supports snapshots

2010-06-04 Thread Kevin Wolf
Am 03.06.2010 21:52, schrieb Miguel Di Ciurcio Filho:
> Both bdrv_can_snapshot() and bdrv_has_snapshot() does not work as advertized.
> 
> First issue: Their names implies different porpouses, but they do the same 
> thing
> and have exactly the same code. Maybe copied and pasted and forgotten?
> bdrv_has_snapshot() is called in various places for actually checking if there
> is snapshots or not.
> 
> Second issue: the way bdrv_can_snapshot() verifies if a block driver supports 
> or
> not snapshots does not catch all cases. E.g.: a raw image.
> 
> So when do_savevm() is called, first thing it does is to set a global
> BlockDriverState to save the VM memory state calling get_bs_snapshots().
> 
> static BlockDriverState *get_bs_snapshots(void)
> {
> BlockDriverState *bs;
> DriveInfo *dinfo;
> 
> if (bs_snapshots)
> return bs_snapshots;
> QTAILQ_FOREACH(dinfo, &drives, next) {
> bs = dinfo->bdrv;
> if (bdrv_can_snapshot(bs))
> goto ok;
> }
> return NULL;
>  ok:
> bs_snapshots = bs;
> return bs;
> }
> 
> bdrv_can_snapshot() may return a BlockDriverState that does not support
> snapshots and do_savevm() goes on.
> 
> Later on in do_savevm(), we find:
> 
> QTAILQ_FOREACH(dinfo, &drives, next) {
> bs1 = dinfo->bdrv;
> if (bdrv_has_snapshot(bs1)) {
> /* Write VM state size only to the image that contains the state 
> */
> sn->vm_state_size = (bs == bs1 ? vm_state_size : 0);
> ret = bdrv_snapshot_create(bs1, sn);
> if (ret < 0) {
> monitor_printf(mon, "Error while creating snapshot on '%s'\n",
>bdrv_get_device_name(bs1));
> }
> }
> }
> 
> bdrv_has_snapshot(bs1) is not checking if the device does support or has
> snapshots as explained above. Only in bdrv_snapshot_create() the device is
> actually checked for snapshot support.
> 
> So, in cases where the first device supports snapshots, and the second does 
> not,
> the snapshot on the first will happen anyways. I believe this is not a good
> behavior. It should be an all or nothing process.
> 
> This patch addresses these issues by making bdrv_can_snapshot() actually do
> what it must do and enforces better tests to avoid errors in the middle of
> do_savevm(). bdrv_has_snapshot() is removed and replaced by 
> bdrv_can_snapshot()
> where appropriate.
> 
> bdrv_can_snapshot() was moved from savevm.c to block.c. It makes more sense 
> to me.
> 
> The loadvm_state() function was updated too to enforce that when loading a VM 
> at
> least all writable devices must support snapshots too.
> 
> Signed-off-by: Miguel Di Ciurcio Filho 
> ---
>  block.c  |   11 +++
>  block.h  |1 +
>  savevm.c |   58 --
>  3 files changed, 48 insertions(+), 22 deletions(-)
> 
> diff --git a/block.c b/block.c
> index cd70730..ace3cdb 100644
> --- a/block.c
> +++ b/block.c
> @@ -1720,6 +1720,17 @@ void bdrv_debug_event(BlockDriverState *bs, 
> BlkDebugEvent event)
>  /**/
>  /* handling of snapshots */
>  
> +int bdrv_can_snapshot(BlockDriverState *bs)
> +{
> +BlockDriver *drv = bs->drv;
> +if (!drv || !drv->bdrv_snapshot_create || bdrv_is_removable(bs) ||
> +bdrv_is_read_only(bs)) {
> +return 0;
> +}
> +
> +return 1;
> +}
> +
>  int bdrv_snapshot_create(BlockDriverState *bs,
>   QEMUSnapshotInfo *sn_info)
>  {
> diff --git a/block.h b/block.h
> index 24efeb6..fbcd8af 100644
> --- a/block.h
> +++ b/block.h
> @@ -173,6 +173,7 @@ int bdrv_get_info(BlockDriverState *bs, BlockDriverInfo 
> *bdi);
>  const char *bdrv_get_encrypted_filename(BlockDriverState *bs);
>  void bdrv_get_backing_filename(BlockDriverState *bs,
> char *filename, int filename_size);
> +int bdrv_can_snapshot(BlockDriverState *bs);
>  int bdrv_snapshot_create(BlockDriverState *bs,
>   QEMUSnapshotInfo *sn_info);
>  int bdrv_snapshot_goto(BlockDriverState *bs,
> diff --git a/savevm.c b/savevm.c
> index dc20390..6549ca7 100644
> --- a/savevm.c
> +++ b/savevm.c
> @@ -1574,22 +1574,6 @@ out:
>  return ret;
>  }
>  
> -/* device can contain snapshots */
> -static int bdrv_can_snapshot(BlockDriverState *bs)
> -{
> -return (bs &&
> -!bdrv_is_removable(bs) &&
> -!bdrv_is_read_only(bs));
> -}
> -
> -/* device must be snapshots in order to have a reliable snapshot */
> -static int bdrv_has_snapshot(BlockDriverState *bs)
> -{
> -return (bs &&
> -!bdrv_is_removable(bs) &&
> -!bdrv_is_read_only(bs));
> -}
> -
>  static BlockDriverState *get_bs_snapshots(void)
>  {
>  BlockDriverState *bs;
> @@ -1599,8 +1583,9 @@ static BlockDriverState *get_bs_snapshots(void)
>  return bs_snapshots;
>  QTAILQ_FOREACH(dinfo, &drives, next) {
>  

[Qemu-devel] [PATCH 05/27] qemu-io: Fix error messages

2010-06-04 Thread Kevin Wolf
The truncate and getlength commands passed a negative error number to strerror.
They also happen to be the two functions that are lacking a newline at the end
of their error message.

Signed-off-by: Kevin Wolf 
---
 qemu-io.c |4 ++--
 1 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/qemu-io.c b/qemu-io.c
index 72a4524..7c6120b 100644
--- a/qemu-io.c
+++ b/qemu-io.c
@@ -1317,7 +1317,7 @@ truncate_f(int argc, char **argv)
 
ret = bdrv_truncate(bs, offset);
if (ret < 0) {
-   printf("truncate: %s", strerror(ret));
+   printf("truncate: %s\n", strerror(-ret));
return 0;
}
 
@@ -1342,7 +1342,7 @@ length_f(int argc, char **argv)
 
size = bdrv_getlength(bs);
if (size < 0) {
-   printf("getlength: %s", strerror(size));
+   printf("getlength: %s\n", strerror(-size));
return 0;
}
 
-- 
1.6.6.1




Re: [Qemu-devel] [PATCH 00/10] target-mips: add microMIPS ASE support, v2

2010-06-04 Thread Aurelien Jarno
On Fri, Jun 04, 2010 at 08:51:12AM -0700, Nathan Froyd wrote:
> On Mon, May 24, 2010 at 09:19:34AM -0700, Nathan Froyd wrote:
> > This patch series adds support for the microMIPS ASE.  microMIPS is a
> > new ASE similar to MIPS16, but re-encodes the entire instruction set
> > into 16-bit and 32-bit instructions--in contrast to MIPS16, which
> > re-encodes only integer instructions.  The mechanisms for going in and
> > out of microMIPS mode are identical to those for MIPS16; a given chip
> > cannot support both ASEs simultaneously.
> 
> Ping.
> 

Pong. I haven't forgotten your patches. I try to review patches more or
less in the order they arrive, and I haven't arrived yet here (though I
am close).

In general when someone else review patches, that clear helps to get them
quickly committed.

-- 
Aurelien Jarno  GPG: 1024D/F1BCDB73
aurel...@aurel32.net http://www.aurel32.net



[Qemu-devel] [PATCH 01/27] Cleanup: bdrv_open() no need to shift total_size just to shift back.

2010-06-04 Thread Kevin Wolf
From: Jes Sorensen 

In bdrv_open() there is no need to shift total_size >> 9 just to
multiply it by 512 again just a few lines later, since this is the
only place the variable is used.

Mask with BDRV_SECTOR_MASK to protect against case where we are
passed a corrupted image.

Signed-off-by: Jes Sorensen 
Signed-off-by: Kevin Wolf 
---
 block.c |4 ++--
 1 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/block.c b/block.c
index 39724c1..8385b4f 100644
--- a/block.c
+++ b/block.c
@@ -522,7 +522,7 @@ int bdrv_open(BlockDriverState *bs, const char *filename, 
int flags,
 bdrv_delete(bs1);
 return ret;
 }
-total_size = bdrv_getlength(bs1) >> BDRV_SECTOR_BITS;
+total_size = bdrv_getlength(bs1) & BDRV_SECTOR_MASK;
 
 if (bs1->drv && bs1->drv->protocol_name)
 is_protocol = 1;
@@ -541,7 +541,7 @@ int bdrv_open(BlockDriverState *bs, const char *filename, 
int flags,
 bdrv_qcow2 = bdrv_find_format("qcow2");
 options = parse_option_parameters("", bdrv_qcow2->create_options, 
NULL);
 
-set_option_parameter_int(options, BLOCK_OPT_SIZE, total_size * 512);
+set_option_parameter_int(options, BLOCK_OPT_SIZE, total_size);
 set_option_parameter(options, BLOCK_OPT_BACKING_FILE, 
backing_filename);
 if (drv) {
 set_option_parameter(options, BLOCK_OPT_BACKING_FMT,
-- 
1.6.6.1




[Qemu-devel] [PATCH 07/27] blockdev: Belatedly remove driveopts

2010-06-04 Thread Kevin Wolf
From: Markus Armbruster 

Unused since commit 9dfd7c7a.

Signed-off-by: Markus Armbruster 
Signed-off-by: Kevin Wolf 
---
 sysemu.h |1 -
 vl.c |1 -
 2 files changed, 0 insertions(+), 2 deletions(-)

diff --git a/sysemu.h b/sysemu.h
index 063319c..fd83b7d 100644
--- a/sysemu.h
+++ b/sysemu.h
@@ -178,7 +178,6 @@ typedef struct DriveInfo {
 #define MAX_SCSI_DEVS  7
 
 extern QTAILQ_HEAD(drivelist, DriveInfo) drives;
-extern QTAILQ_HEAD(driveoptlist, DriveOpt) driveopts;
 
 extern DriveInfo *drive_get(BlockInterfaceType type, int bus, int unit);
 extern DriveInfo *drive_get_by_id(const char *id);
diff --git a/vl.c b/vl.c
index f8d3034..9283469 100644
--- a/vl.c
+++ b/vl.c
@@ -173,7 +173,6 @@ int main(int argc, char **argv)
 static const char *data_dir;
 const char *bios_name = NULL;
 struct drivelist drives = QTAILQ_HEAD_INITIALIZER(drives);
-struct driveoptlist driveopts = QTAILQ_HEAD_INITIALIZER(driveopts);
 enum vga_retrace_method vga_retrace_method = VGA_RETRACE_DUMB;
 DisplayType display_type = DT_DEFAULT;
 const char* keyboard_layout = NULL;
-- 
1.6.6.1




[Qemu-devel] [PATCH 06/27] blockdev: Belatedly remove MAX_DRIVES

2010-06-04 Thread Kevin Wolf
From: Markus Armbruster 

Unused since commit 751c6a17.

Signed-off-by: Markus Armbruster 
Signed-off-by: Kevin Wolf 
---
 sysemu.h |1 -
 vl.c |2 --
 2 files changed, 0 insertions(+), 3 deletions(-)

diff --git a/sysemu.h b/sysemu.h
index 879446a..063319c 100644
--- a/sysemu.h
+++ b/sysemu.h
@@ -176,7 +176,6 @@ typedef struct DriveInfo {
 
 #define MAX_IDE_DEVS   2
 #define MAX_SCSI_DEVS  7
-#define MAX_DRIVES 32
 
 extern QTAILQ_HEAD(drivelist, DriveInfo) drives;
 extern QTAILQ_HEAD(driveoptlist, DriveOpt) driveopts;
diff --git a/vl.c b/vl.c
index 7121cd0..f8d3034 100644
--- a/vl.c
+++ b/vl.c
@@ -172,8 +172,6 @@ int main(int argc, char **argv)
 
 static const char *data_dir;
 const char *bios_name = NULL;
-/* Note: drives_table[MAX_DRIVES] is a dummy block driver if none available
-   to store the VM snapshots */
 struct drivelist drives = QTAILQ_HEAD_INITIALIZER(drives);
 struct driveoptlist driveopts = QTAILQ_HEAD_INITIALIZER(driveopts);
 enum vga_retrace_method vga_retrace_method = VGA_RETRACE_DUMB;
-- 
1.6.6.1




[Qemu-devel] [PATCH 16/27] ide: Turn drive serial into a qdev property ide-drive.serial

2010-06-04 Thread Kevin Wolf
From: Markus Armbruster 

It needs to be a qdev property, because it belongs to the drive's
guest part.

Bonus: info qtree now shows the serial number.

Signed-off-by: Markus Armbruster 
Signed-off-by: Kevin Wolf 
---
 hw/ide/core.c |   11 ++-
 hw/ide/internal.h |4 +++-
 hw/ide/qdev.c |   16 +++-
 3 files changed, 24 insertions(+), 7 deletions(-)

diff --git a/hw/ide/core.c b/hw/ide/core.c
index d3328cd..70af1b6 100644
--- a/hw/ide/core.c
+++ b/hw/ide/core.c
@@ -2596,7 +2596,8 @@ void ide_bus_reset(IDEBus *bus)
 ide_clear_hob(bus);
 }
 
-void ide_init_drive(IDEState *s, DriveInfo *dinfo, const char *version)
+void ide_init_drive(IDEState *s, DriveInfo *dinfo,
+const char *version, const char *serial)
 {
 int cylinders, heads, secs;
 uint64_t nb_sectors;
@@ -2618,9 +2619,9 @@ void ide_init_drive(IDEState *s, DriveInfo *dinfo, const 
char *version)
 s->is_cdrom = 1;
 bdrv_set_change_cb(s->bs, cdrom_change_cb, s);
 }
-strncpy(s->drive_serial_str, drive_get_serial(s->bs),
-sizeof(s->drive_serial_str));
-if (!*s->drive_serial_str) {
+if (serial && *serial) {
+strncpy(s->drive_serial_str, serial, sizeof(s->drive_serial_str));
+} else {
 snprintf(s->drive_serial_str, sizeof(s->drive_serial_str),
  "QM%05d", s->drive_serial);
 }
@@ -2669,7 +2670,7 @@ void ide_init2_with_non_qdev_drives(IDEBus *bus, 
DriveInfo *hd0,
 dinfo = i == 0 ? hd0 : hd1;
 ide_init1(bus, i);
 if (dinfo) {
-ide_init_drive(&bus->ifs[i], dinfo, NULL);
+ide_init_drive(&bus->ifs[i], dinfo, NULL, dinfo->serial);
 } else {
 ide_reset(&bus->ifs[i]);
 }
diff --git a/hw/ide/internal.h b/hw/ide/internal.h
index 6b0024d..eef1ee1 100644
--- a/hw/ide/internal.h
+++ b/hw/ide/internal.h
@@ -457,6 +457,7 @@ struct IDEDevice {
 uint32_t unit;
 BlockConf conf;
 char *version;
+char *serial;
 };
 
 typedef int (*ide_qdev_initfn)(IDEDevice *dev);
@@ -554,7 +555,8 @@ uint32_t ide_data_readw(void *opaque, uint32_t addr);
 void ide_data_writel(void *opaque, uint32_t addr, uint32_t val);
 uint32_t ide_data_readl(void *opaque, uint32_t addr);
 
-void ide_init_drive(IDEState *s, DriveInfo *dinfo, const char *version);
+void ide_init_drive(IDEState *s, DriveInfo *dinfo,
+const char *version, const char *serial);
 void ide_init2(IDEBus *bus, qemu_irq irq);
 void ide_init2_with_non_qdev_drives(IDEBus *bus, DriveInfo *hd0,
 DriveInfo *hd1, qemu_irq irq);
diff --git a/hw/ide/qdev.c b/hw/ide/qdev.c
index 9ebb906..5e549d9 100644
--- a/hw/ide/qdev.c
+++ b/hw/ide/qdev.c
@@ -99,7 +99,20 @@ typedef struct IDEDrive {
 static int ide_drive_initfn(IDEDevice *dev)
 {
 IDEBus *bus = DO_UPCAST(IDEBus, qbus, dev->qdev.parent_bus);
-ide_init_drive(bus->ifs + dev->unit, dev->conf.dinfo, dev->version);
+IDEState *s = bus->ifs + dev->unit;
+const char *serial;
+
+serial = dev->serial;
+if (!serial) {
+/* try to fall back to value set with legacy -drive serial=... */
+serial = dev->conf.dinfo->serial;
+}
+
+ide_init_drive(s, dev->conf.dinfo, dev->version, serial);
+
+if (!dev->serial) {
+dev->serial = qemu_strdup(s->drive_serial_str);
+}
 return 0;
 }
 
@@ -111,6 +124,7 @@ static IDEDeviceInfo ide_drive_info = {
 DEFINE_PROP_UINT32("unit", IDEDrive, dev.unit, -1),
 DEFINE_BLOCK_PROPERTIES(IDEDrive, dev.conf),
 DEFINE_PROP_STRING("ver",  IDEDrive, dev.version),
+DEFINE_PROP_STRING("serial",  IDEDrive, dev.serial),
 DEFINE_PROP_END_OF_LIST(),
 }
 };
-- 
1.6.6.1




[Qemu-devel] [PATCH 04/17] vl.c: Move host_main_loop_wait() to OS specific files.

2010-06-04 Thread Jes . Sorensen
From: Jes Sorensen 

Move host_main_loop_wait() to OS specific files. Create
qemu-os-posix.h and provide empty inline for the POSIX case.

Signed-off-by: Jes Sorensen 
---
 os-win32.c  |   43 +++
 qemu-os-posix.h |   33 +
 qemu-os-win32.h |1 +
 sysemu.h|4 
 vl.c|   52 +---
 5 files changed, 82 insertions(+), 51 deletions(-)
 create mode 100644 qemu-os-posix.h

diff --git a/os-win32.c b/os-win32.c
index 5a464cc..1f7e28b 100644
--- a/os-win32.c
+++ b/os-win32.c
@@ -109,3 +109,46 @@ void qemu_del_wait_object(HANDLE handle, WaitObjectFunc 
*func, void *opaque)
 if (found)
 w->num--;
 }
+
+void os_host_main_loop_wait(int *timeout)
+{
+int ret, ret2, i;
+PollingEntry *pe;
+
+/* XXX: need to suppress polling by better using win32 events */
+ret = 0;
+for(pe = first_polling_entry; pe != NULL; pe = pe->next) {
+ret |= pe->func(pe->opaque);
+}
+if (ret == 0) {
+int err;
+WaitObjects *w = &wait_objects;
+
+ret = WaitForMultipleObjects(w->num, w->events, FALSE, *timeout);
+if (WAIT_OBJECT_0 + 0 <= ret && ret <= WAIT_OBJECT_0 + w->num - 1) {
+if (w->func[ret - WAIT_OBJECT_0])
+w->func[ret - WAIT_OBJECT_0](w->opaque[ret - WAIT_OBJECT_0]);
+
+/* Check for additional signaled events */
+for(i = (ret - WAIT_OBJECT_0 + 1); i < w->num; i++) {
+
+/* Check if event is signaled */
+ret2 = WaitForSingleObject(w->events[i], 0);
+if(ret2 == WAIT_OBJECT_0) {
+if (w->func[i])
+w->func[i](w->opaque[i]);
+} else if (ret2 == WAIT_TIMEOUT) {
+} else {
+err = GetLastError();
+fprintf(stderr, "WaitForSingleObject error %d %d\n", i, 
err);
+}
+}
+} else if (ret == WAIT_TIMEOUT) {
+} else {
+err = GetLastError();
+fprintf(stderr, "WaitForMultipleObjects error %d %d\n", ret, err);
+}
+}
+
+*timeout = 0;
+}
diff --git a/qemu-os-posix.h b/qemu-os-posix.h
new file mode 100644
index 000..96d1036
--- /dev/null
+++ b/qemu-os-posix.h
@@ -0,0 +1,33 @@
+/*
+ * posix specific declarations
+ *
+ * Copyright (c) 2003-2008 Fabrice Bellard
+ * Copyright (c) 2010 Jes Sorensen 
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to 
deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
+ * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 
FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ * THE SOFTWARE.
+ */
+
+#ifndef QEMU_OS_POSIX_H
+#define QEMU_OS_POSIX_H
+
+static inline void os_host_main_loop_wait(int *timeout)
+{
+}
+
+#endif
diff --git a/qemu-os-win32.h b/qemu-os-win32.h
index be108ad..4d1cac8 100644
--- a/qemu-os-win32.h
+++ b/qemu-os-win32.h
@@ -40,4 +40,5 @@ typedef void WaitObjectFunc(void *opaque);
 int qemu_add_wait_object(HANDLE handle, WaitObjectFunc *func, void *opaque);
 void qemu_del_wait_object(HANDLE handle, WaitObjectFunc *func, void *opaque);
 
+void os_host_main_loop_wait(int *timeout);
 #endif
diff --git a/sysemu.h b/sysemu.h
index 13fc9a9..5e4feae 100644
--- a/sysemu.h
+++ b/sysemu.h
@@ -12,6 +12,10 @@
 #include "qemu-os-win32.h"
 #endif
 
+#ifdef CONFIG_POSIX
+#include "qemu-os-posix.h"
+#endif
+
 /* vl.c */
 extern const char *bios_name;
 
diff --git a/vl.c b/vl.c
index afbb26c..c655582 100644
--- a/vl.c
+++ b/vl.c
@@ -1722,56 +1722,6 @@ void qemu_system_powerdown_request(void)
 qemu_notify_event();
 }
 
-#ifdef _WIN32
-static void host_main_loop_wait(int *timeout)
-{
-int ret, ret2, i;
-PollingEntry *pe;
-
-
-/* XXX: need to suppress polling by better using win32 events */
-ret = 0;
-for(pe = first_polling_entry; pe != NULL; pe = pe->next) {
-ret |= pe->func(pe->opaque);
-}
-if (ret == 0) {
-int err;
-WaitObjects *w = &wait_objects;
-
-ret = WaitForMultipleObjects(w->num, w->events, FALSE

[Qemu-devel] [PATCH 18/27] scsi: Turn drive serial into a qdev property scsi-disk.serial

2010-06-04 Thread Kevin Wolf
From: Markus Armbruster 

It needs to be a qdev property, because it belongs to the drive's
guest part.

Bonus: info qtree now shows the serial number.

Signed-off-by: Markus Armbruster 
Signed-off-by: Kevin Wolf 
---
 hw/scsi-disk.c |   17 +
 1 files changed, 13 insertions(+), 4 deletions(-)

diff --git a/hw/scsi-disk.c b/hw/scsi-disk.c
index 4d20919..e8c066a 100644
--- a/hw/scsi-disk.c
+++ b/hw/scsi-disk.c
@@ -66,6 +66,7 @@ struct SCSIDiskState
 uint64_t max_lba;
 QEMUBH *bh;
 char *version;
+char *serial;
 };
 
 static SCSIDiskReq *scsi_new_request(SCSIDevice *d, uint32_t tag, uint32_t lun)
@@ -359,9 +360,7 @@ static int scsi_disk_emulate_inquiry(SCSIRequest *req, 
uint8_t *outbuf)
 
 case 0x80: /* Device serial number, optional */
 {
-const char *serial = req->dev->conf.dinfo->serial ?
-req->dev->conf.dinfo->serial : "0";
-int l = strlen(serial);
+int l = strlen(s->serial);
 
 if (l > req->cmd.xfer)
 l = req->cmd.xfer;
@@ -371,7 +370,7 @@ static int scsi_disk_emulate_inquiry(SCSIRequest *req, 
uint8_t *outbuf)
 DPRINTF("Inquiry EVPD[Serial number] "
 "buffer size %zd\n", req->cmd.xfer);
 outbuf[buflen++] = l;
-memcpy(outbuf+buflen, serial, l);
+memcpy(outbuf+buflen, s->serial, l);
 buflen += l;
 break;
 }
@@ -1058,6 +1057,15 @@ static int scsi_disk_initfn(SCSIDevice *dev)
 }
 s->bs = s->qdev.conf.dinfo->bdrv;
 
+if (!s->serial) {
+if (*dev->conf.dinfo->serial) {
+/* try to fall back to value set with legacy -drive serial=... */
+s->serial = qemu_strdup(dev->conf.dinfo->serial);
+} else {
+s->serial = qemu_strdup("0");
+}
+}
+
 if (bdrv_is_sg(s->bs)) {
 error_report("scsi-disk: unwanted /dev/sg*");
 return -1;
@@ -1090,6 +1098,7 @@ static SCSIDeviceInfo scsi_disk_info = {
 .qdev.props   = (Property[]) {
 DEFINE_BLOCK_PROPERTIES(SCSIDiskState, qdev.conf),
 DEFINE_PROP_STRING("ver",  SCSIDiskState, version),
+DEFINE_PROP_STRING("serial",  SCSIDiskState, serial),
 DEFINE_PROP_END_OF_LIST(),
 },
 };
-- 
1.6.6.1




[Qemu-devel] [PATCH 12/27] ide: Change ide_init_drive() to require valid dinfo argument

2010-06-04 Thread Kevin Wolf
From: Markus Armbruster 

IDEState members drive_serial_str and version are now left empty until
an actual drive is connected.  Before, they got a default value that
was overwritten when a drive got connected.  Doesn't matter, because
they're used only while a drive is connected.

Signed-off-by: Markus Armbruster 
Signed-off-by: Kevin Wolf 
---
 hw/ide/core.c |   47 +--
 1 files changed, 25 insertions(+), 22 deletions(-)

diff --git a/hw/ide/core.c b/hw/ide/core.c
index 443ff10..cb7af38 100644
--- a/hw/ide/core.c
+++ b/hw/ide/core.c
@@ -2601,30 +2601,29 @@ void ide_init_drive(IDEState *s, DriveInfo *dinfo, 
const char *version)
 int cylinders, heads, secs;
 uint64_t nb_sectors;
 
-if (dinfo && dinfo->bdrv) {
-s->bs = dinfo->bdrv;
-bdrv_get_geometry(s->bs, &nb_sectors);
-bdrv_guess_geometry(s->bs, &cylinders, &heads, &secs);
-s->cylinders = cylinders;
-s->heads = heads;
-s->sectors = secs;
-s->nb_sectors = nb_sectors;
-/* The SMART values should be preserved across power cycles
-   but they aren't.  */
-s->smart_enabled = 1;
-s->smart_autosave = 1;
-s->smart_errors = 0;
-s->smart_selftest_count = 0;
-if (bdrv_get_type_hint(s->bs) == BDRV_TYPE_CDROM) {
-s->is_cdrom = 1;
-bdrv_set_change_cb(s->bs, cdrom_change_cb, s);
-}
-strncpy(s->drive_serial_str, drive_get_serial(s->bs),
-sizeof(s->drive_serial_str));
+s->bs = dinfo->bdrv;
+bdrv_get_geometry(s->bs, &nb_sectors);
+bdrv_guess_geometry(s->bs, &cylinders, &heads, &secs);
+s->cylinders = cylinders;
+s->heads = heads;
+s->sectors = secs;
+s->nb_sectors = nb_sectors;
+/* The SMART values should be preserved across power cycles
+   but they aren't.  */
+s->smart_enabled = 1;
+s->smart_autosave = 1;
+s->smart_errors = 0;
+s->smart_selftest_count = 0;
+if (bdrv_get_type_hint(s->bs) == BDRV_TYPE_CDROM) {
+s->is_cdrom = 1;
+bdrv_set_change_cb(s->bs, cdrom_change_cb, s);
 }
-if (strlen(s->drive_serial_str) == 0)
+strncpy(s->drive_serial_str, drive_get_serial(s->bs),
+sizeof(s->drive_serial_str));
+if (!*s->drive_serial_str) {
 snprintf(s->drive_serial_str, sizeof(s->drive_serial_str),
  "QM%05d", s->drive_serial);
+}
 if (version) {
 pstrcpy(s->version, sizeof(s->version), version);
 } else {
@@ -2646,7 +2645,11 @@ static void ide_init1(IDEBus *bus, int unit, DriveInfo 
*dinfo)
 s->smart_selftest_data = qemu_blockalign(s->bs, 512);
 s->sector_write_timer = qemu_new_timer(vm_clock,
ide_sector_write_timer_cb, s);
-ide_init_drive(s, dinfo, NULL);
+if (dinfo) {
+ide_init_drive(s, dinfo, NULL);
+} else {
+ide_reset(s);
+}
 }
 
 void ide_init2(IDEBus *bus, DriveInfo *hd0, DriveInfo *hd1,
-- 
1.6.6.1




[Qemu-devel] [PATCH 19/27] scsi: Fix info qtree for scsi-disk.ver

2010-06-04 Thread Kevin Wolf
From: Markus Armbruster 

Show the actual default value instead of  when the property has
not been set.

Signed-off-by: Markus Armbruster 
Signed-off-by: Kevin Wolf 
---
 hw/scsi-disk.c |7 +--
 1 files changed, 5 insertions(+), 2 deletions(-)

diff --git a/hw/scsi-disk.c b/hw/scsi-disk.c
index e8c066a..a3559d1 100644
--- a/hw/scsi-disk.c
+++ b/hw/scsi-disk.c
@@ -462,8 +462,7 @@ static int scsi_disk_emulate_inquiry(SCSIRequest *req, 
uint8_t *outbuf)
 }
 memcpy(&outbuf[8], "QEMU", 8);
 memset(&outbuf[32], 0, 4);
-memcpy(&outbuf[32], s->version ? s->version : QEMU_VERSION,
-   MIN(4, strlen(s->version ? s->version : QEMU_VERSION)));
+memcpy(&outbuf[32], s->version, MIN(4, strlen(s->version)));
 /*
  * We claim conformance to SPC-3, which is required for guests
  * to ask for modern features like READ CAPACITY(16) or the
@@ -1066,6 +1065,10 @@ static int scsi_disk_initfn(SCSIDevice *dev)
 }
 }
 
+if (!s->version) {
+s->version = qemu_strdup(QEMU_VERSION);
+}
+
 if (bdrv_is_sg(s->bs)) {
 error_report("scsi-disk: unwanted /dev/sg*");
 return -1;
-- 
1.6.6.1




[Qemu-devel] [PATCH 10/27] ide: Remove redundant IDEState member conf

2010-06-04 Thread Kevin Wolf
From: Markus Armbruster 

Commit 428c149b added IDEState member conf to let commit 0009baf1 find
the BlockConf from there.  It exists only for qdev drives, created via
ide_drive_initfn(), not for drives created via ide_init2().

But for a qdev drive, we can just as well reach its IDEDevice, which
contains the BlockConf.  Do that, and revert the parts of commit
428c149b that add IDEState member conf.

Signed-off-by: Markus Armbruster 
Signed-off-by: Kevin Wolf 
---
 hw/ide/core.c |   16 +++-
 hw/ide/internal.h |4 +---
 hw/ide/qdev.c |3 +--
 3 files changed, 9 insertions(+), 14 deletions(-)

diff --git a/hw/ide/core.c b/hw/ide/core.c
index 066fecb..c3334b1 100644
--- a/hw/ide/core.c
+++ b/hw/ide/core.c
@@ -98,6 +98,7 @@ static void ide_identify(IDEState *s)
 {
 uint16_t *p;
 unsigned int oldsize;
+IDEDevice *dev;
 
 if (s->identify_set) {
memcpy(s->io_buffer, s->identify_data, sizeof(s->identify_data));
@@ -165,8 +166,9 @@ static void ide_identify(IDEState *s)
 put_le16(p + 101, s->nb_sectors >> 16);
 put_le16(p + 102, s->nb_sectors >> 32);
 put_le16(p + 103, s->nb_sectors >> 48);
-if (s->conf && s->conf->physical_block_size)
-put_le16(p + 106, 0x6000 | get_physical_block_exp(s->conf));
+dev = s->unit ? s->bus->slave : s->bus->master;
+if (dev && dev->conf.physical_block_size)
+put_le16(p + 106, 0x6000 | get_physical_block_exp(&dev->conf));
 
 memcpy(s->identify_data, p, sizeof(s->identify_data));
 s->identify_set = 1;
@@ -2594,8 +2596,7 @@ void ide_bus_reset(IDEBus *bus)
 ide_clear_hob(bus);
 }
 
-void ide_init_drive(IDEState *s, DriveInfo *dinfo, BlockConf *conf,
-const char *version)
+void ide_init_drive(IDEState *s, DriveInfo *dinfo, const char *version)
 {
 int cylinders, heads, secs;
 uint64_t nb_sectors;
@@ -2620,9 +2621,6 @@ void ide_init_drive(IDEState *s, DriveInfo *dinfo, 
BlockConf *conf,
 }
 strncpy(s->drive_serial_str, drive_get_serial(s->bs),
 sizeof(s->drive_serial_str));
-if (conf) {
-s->conf = conf;
-}
 }
 if (strlen(s->drive_serial_str) == 0)
 snprintf(s->drive_serial_str, sizeof(s->drive_serial_str),
@@ -2653,9 +2651,9 @@ void ide_init2(IDEBus *bus, DriveInfo *hd0, DriveInfo 
*hd1,
 s->sector_write_timer = qemu_new_timer(vm_clock,
ide_sector_write_timer_cb, s);
 if (i == 0)
-ide_init_drive(s, hd0, NULL, NULL);
+ide_init_drive(s, hd0, NULL);
 if (i == 1)
-ide_init_drive(s, hd1, NULL, NULL);
+ide_init_drive(s, hd1, NULL);
 }
 bus->irq = irq;
 }
diff --git a/hw/ide/internal.h b/hw/ide/internal.h
index b4554ce..cf71019 100644
--- a/hw/ide/internal.h
+++ b/hw/ide/internal.h
@@ -398,7 +398,6 @@ struct IDEState {
 /* set for lba48 access */
 uint8_t lba48;
 BlockDriverState *bs;
-BlockConf *conf;
 char version[9];
 /* ATAPI specific */
 uint8_t sense_key;
@@ -555,8 +554,7 @@ uint32_t ide_data_readw(void *opaque, uint32_t addr);
 void ide_data_writel(void *opaque, uint32_t addr, uint32_t val);
 uint32_t ide_data_readl(void *opaque, uint32_t addr);
 
-void ide_init_drive(IDEState *s, DriveInfo *dinfo, BlockConf *conf,
-const char *version);
+void ide_init_drive(IDEState *s, DriveInfo *dinfo, const char *version);
 void ide_init2(IDEBus *bus, DriveInfo *hd0, DriveInfo *hd1,
qemu_irq irq);
 void ide_init_ioport(IDEBus *bus, int iobase, int iobase2);
diff --git a/hw/ide/qdev.c b/hw/ide/qdev.c
index b18693d..9ebb906 100644
--- a/hw/ide/qdev.c
+++ b/hw/ide/qdev.c
@@ -99,8 +99,7 @@ typedef struct IDEDrive {
 static int ide_drive_initfn(IDEDevice *dev)
 {
 IDEBus *bus = DO_UPCAST(IDEBus, qbus, dev->qdev.parent_bus);
-ide_init_drive(bus->ifs + dev->unit, dev->conf.dinfo, &dev->conf,
-   dev->version);
+ide_init_drive(bus->ifs + dev->unit, dev->conf.dinfo, dev->version);
 return 0;
 }
 
-- 
1.6.6.1




[Qemu-devel] [PATCH 15/17] Make os_change_process_uid and os_change_root os-posix.c local

2010-06-04 Thread Jes . Sorensen
From: Jes Sorensen 

os_change_process_uid() and os_change_root() are now only called
from os-posix.c, so no need to keep win32 stubs for them.

Signed-off-by: Jes Sorensen 
---
 os-posix.c  |8 
 qemu-os-posix.h |2 --
 qemu-os-win32.h |2 --
 3 files changed, 4 insertions(+), 8 deletions(-)

diff --git a/os-posix.c b/os-posix.c
index 1672e06..3a96c91 100644
--- a/os-posix.c
+++ b/os-posix.c
@@ -169,7 +169,7 @@ void os_parse_cmd_args(int index, const char *optarg)
 return;
 }
 
-void os_change_process_uid(void)
+static void change_process_uid(void)
 {
 if (user_pwd) {
 if (setgid(user_pwd->pw_gid) < 0) {
@@ -187,7 +187,7 @@ void os_change_process_uid(void)
 }
 }
 
-void os_change_root(void)
+static void change_root(void)
 {
 if (chroot_dir) {
 if (chroot(chroot_dir) < 0) {
@@ -276,8 +276,8 @@ void os_setup_post(void)
exit(1);
 }
 
-os_change_root();
-os_change_process_uid();
+change_root();
+change_process_uid();
 
 if (daemonize) {
 dup2(fd, 0);
diff --git a/qemu-os-posix.h b/qemu-os-posix.h
index 9b07660..8be583d 100644
--- a/qemu-os-posix.h
+++ b/qemu-os-posix.h
@@ -31,8 +31,6 @@ static inline void os_host_main_loop_wait(int *timeout)
 }
 
 void os_setup_signal_handling(void);
-void os_change_process_uid(void);
-void os_change_root(void);
 void os_daemonize(void);
 void os_setup_post(void);
 
diff --git a/qemu-os-win32.h b/qemu-os-win32.h
index c4aa84a..39df333 100644
--- a/qemu-os-win32.h
+++ b/qemu-os-win32.h
@@ -43,8 +43,6 @@ void qemu_del_wait_object(HANDLE handle, WaitObjectFunc 
*func, void *opaque);
 void os_host_main_loop_wait(int *timeout);
 
 static inline void os_setup_signal_handling(void) {}
-static inline void os_change_process_uid(void) {}
-static inline void os_change_root(void) {}
 static inline void os_daemonize(void) {}
 static inline void os_setup_post(void) {}
 
-- 
1.6.5.2




[Qemu-devel] [PATCH 02/27] Cleanup: Be consistent and use BDRV_SECTOR_SIZE instead of 512

2010-06-04 Thread Kevin Wolf
From: Jes Sorensen 

Clean up block.c and use BDRV_SECTOR_SIZE rather than hard coded
numbers (512) when referring to sector size throughout the code.

Signed-off-by: Jes Sorensen 
Signed-off-by: Kevin Wolf 
---
 block.c |   13 +++--
 1 files changed, 7 insertions(+), 6 deletions(-)

diff --git a/block.c b/block.c
index 8385b4f..9c43332 100644
--- a/block.c
+++ b/block.c
@@ -684,7 +684,7 @@ int bdrv_commit(BlockDriverState *bs)
 int64_t i, total_sectors;
 int n, j, ro, open_flags;
 int ret = 0, rw_ret = 0;
-unsigned char sector[512];
+unsigned char sector[BDRV_SECTOR_SIZE];
 char filename[1024];
 BlockDriverState *bs_rw, *bs_ro;
 
@@ -824,7 +824,8 @@ static int bdrv_check_byte_request(BlockDriverState *bs, 
int64_t offset,
 static int bdrv_check_request(BlockDriverState *bs, int64_t sector_num,
   int nb_sectors)
 {
-return bdrv_check_byte_request(bs, sector_num * 512, nb_sectors * 512);
+return bdrv_check_byte_request(bs, sector_num * BDRV_SECTOR_SIZE,
+   nb_sectors * BDRV_SECTOR_SIZE);
 }
 
 /* return < 0 if error. See bdrv_write() for the return codes */
@@ -1059,7 +1060,7 @@ struct partition {
 static int guess_disk_lchs(BlockDriverState *bs,
int *pcylinders, int *pheads, int *psectors)
 {
-uint8_t buf[512];
+uint8_t buf[BDRV_SECTOR_SIZE];
 int ret, i, heads, sectors, cylinders;
 struct partition *p;
 uint32_t nr_sects;
@@ -1535,7 +1536,7 @@ static QObject* bdrv_info_stats_bs(BlockDriverState *bs)
  "} }",
  bs->rd_bytes, bs->wr_bytes,
  bs->rd_ops, bs->wr_ops,
- bs->wr_highest_sector * 512);
+ bs->wr_highest_sector * (long)BDRV_SECTOR_SIZE);
 dict  = qobject_to_qdict(res);
 
 if (*bs->device_name) {
@@ -2197,7 +2198,7 @@ static int bdrv_read_em(BlockDriverState *bs, int64_t 
sector_num,
 
 async_ret = NOT_DONE;
 iov.iov_base = (void *)buf;
-iov.iov_len = nb_sectors * 512;
+iov.iov_len = nb_sectors * BDRV_SECTOR_SIZE;
 qemu_iovec_init_external(&qiov, &iov, 1);
 acb = bdrv_aio_readv(bs, sector_num, &qiov, nb_sectors,
 bdrv_rw_em_cb, &async_ret);
@@ -2228,7 +2229,7 @@ static int bdrv_write_em(BlockDriverState *bs, int64_t 
sector_num,
 
 async_ret = NOT_DONE;
 iov.iov_base = (void *)buf;
-iov.iov_len = nb_sectors * 512;
+iov.iov_len = nb_sectors * BDRV_SECTOR_SIZE;
 qemu_iovec_init_external(&qiov, &iov, 1);
 acb = bdrv_aio_writev(bs, sector_num, &qiov, nb_sectors,
 bdrv_rw_em_cb, &async_ret);
-- 
1.6.6.1




[Qemu-devel] [PATCH 17/27] ide: Fix info qtree for ide-drive.ver

2010-06-04 Thread Kevin Wolf
From: Markus Armbruster 

Show the actual default value instead of  when the property has
not been set.

Signed-off-by: Markus Armbruster 
Signed-off-by: Kevin Wolf 
---
 hw/ide/qdev.c |3 +++
 1 files changed, 3 insertions(+), 0 deletions(-)

diff --git a/hw/ide/qdev.c b/hw/ide/qdev.c
index 5e549d9..6231d77 100644
--- a/hw/ide/qdev.c
+++ b/hw/ide/qdev.c
@@ -110,6 +110,9 @@ static int ide_drive_initfn(IDEDevice *dev)
 
 ide_init_drive(s, dev->conf.dinfo, dev->version, serial);
 
+if (!dev->version) {
+dev->version = qemu_strdup(s->version);
+}
 if (!dev->serial) {
 dev->serial = qemu_strdup(s->drive_serial_str);
 }
-- 
1.6.6.1




[Qemu-devel] [PATCH 13/27] ide: Split non-qdev code off ide_init2()

2010-06-04 Thread Kevin Wolf
From: Markus Armbruster 

Signed-off-by: Markus Armbruster 
Signed-off-by: Kevin Wolf 
---
 hw/ide/cmd646.c |4 ++--
 hw/ide/core.c   |   30 ++
 hw/ide/internal.h   |5 +++--
 hw/ide/isa.c|2 +-
 hw/ide/macio.c  |2 +-
 hw/ide/microdrive.c |3 ++-
 hw/ide/mmio.c   |2 +-
 hw/ide/piix.c   |4 ++--
 8 files changed, 34 insertions(+), 18 deletions(-)

diff --git a/hw/ide/cmd646.c b/hw/ide/cmd646.c
index cdcc9bf..559147f 100644
--- a/hw/ide/cmd646.c
+++ b/hw/ide/cmd646.c
@@ -260,8 +260,8 @@ static int pci_cmd646_ide_initfn(PCIDevice *dev)
 irq = qemu_allocate_irqs(cmd646_set_irq, d, 2);
 ide_bus_new(&d->bus[0], &d->dev.qdev);
 ide_bus_new(&d->bus[1], &d->dev.qdev);
-ide_init2(&d->bus[0], NULL, NULL, irq[0]);
-ide_init2(&d->bus[1], NULL, NULL, irq[1]);
+ide_init2(&d->bus[0], irq[0]);
+ide_init2(&d->bus[1], irq[1]);
 
 vmstate_register(0, &vmstate_ide_pci, d);
 qemu_register_reset(cmd646_reset, d);
diff --git a/hw/ide/core.c b/hw/ide/core.c
index cb7af38..d3328cd 100644
--- a/hw/ide/core.c
+++ b/hw/ide/core.c
@@ -2632,7 +2632,7 @@ void ide_init_drive(IDEState *s, DriveInfo *dinfo, const 
char *version)
 ide_reset(s);
 }
 
-static void ide_init1(IDEBus *bus, int unit, DriveInfo *dinfo)
+static void ide_init1(IDEBus *bus, int unit)
 {
 static int drive_serial = 1;
 IDEState *s = &bus->ifs[unit];
@@ -2645,20 +2645,34 @@ static void ide_init1(IDEBus *bus, int unit, DriveInfo 
*dinfo)
 s->smart_selftest_data = qemu_blockalign(s->bs, 512);
 s->sector_write_timer = qemu_new_timer(vm_clock,
ide_sector_write_timer_cb, s);
-if (dinfo) {
-ide_init_drive(s, dinfo, NULL);
-} else {
-ide_reset(s);
+}
+
+void ide_init2(IDEBus *bus, qemu_irq irq)
+{
+int i;
+
+for(i = 0; i < 2; i++) {
+ide_init1(bus, i);
+ide_reset(&bus->ifs[i]);
 }
+bus->irq = irq;
 }
 
-void ide_init2(IDEBus *bus, DriveInfo *hd0, DriveInfo *hd1,
-   qemu_irq irq)
+/* TODO convert users to qdev and remove */
+void ide_init2_with_non_qdev_drives(IDEBus *bus, DriveInfo *hd0,
+DriveInfo *hd1, qemu_irq irq)
 {
 int i;
+DriveInfo *dinfo;
 
 for(i = 0; i < 2; i++) {
-ide_init1(bus, i, i == 0 ? hd0 : hd1);
+dinfo = i == 0 ? hd0 : hd1;
+ide_init1(bus, i);
+if (dinfo) {
+ide_init_drive(&bus->ifs[i], dinfo, NULL);
+} else {
+ide_reset(&bus->ifs[i]);
+}
 }
 bus->irq = irq;
 }
diff --git a/hw/ide/internal.h b/hw/ide/internal.h
index cf71019..6b0024d 100644
--- a/hw/ide/internal.h
+++ b/hw/ide/internal.h
@@ -555,8 +555,9 @@ void ide_data_writel(void *opaque, uint32_t addr, uint32_t 
val);
 uint32_t ide_data_readl(void *opaque, uint32_t addr);
 
 void ide_init_drive(IDEState *s, DriveInfo *dinfo, const char *version);
-void ide_init2(IDEBus *bus, DriveInfo *hd0, DriveInfo *hd1,
-   qemu_irq irq);
+void ide_init2(IDEBus *bus, qemu_irq irq);
+void ide_init2_with_non_qdev_drives(IDEBus *bus, DriveInfo *hd0,
+DriveInfo *hd1, qemu_irq irq);
 void ide_init_ioport(IDEBus *bus, int iobase, int iobase2);
 
 /* hw/ide/qdev.c */
diff --git a/hw/ide/isa.c b/hw/ide/isa.c
index dff7c79..b6c6347 100644
--- a/hw/ide/isa.c
+++ b/hw/ide/isa.c
@@ -70,7 +70,7 @@ static int isa_ide_initfn(ISADevice *dev)
 ide_bus_new(&s->bus, &s->dev.qdev);
 ide_init_ioport(&s->bus, s->iobase, s->iobase2);
 isa_init_irq(dev, &s->irq, s->isairq);
-ide_init2(&s->bus, NULL, NULL, s->irq);
+ide_init2(&s->bus, s->irq);
 vmstate_register(0, &vmstate_ide_isa, s);
 return 0;
 };
diff --git a/hw/ide/macio.c b/hw/ide/macio.c
index 639f3f6..f76c0fa 100644
--- a/hw/ide/macio.c
+++ b/hw/ide/macio.c
@@ -314,7 +314,7 @@ int pmac_ide_init (DriveInfo **hd_table, qemu_irq irq,
 int pmac_ide_memory;
 
 d = qemu_mallocz(sizeof(MACIOIDEState));
-ide_init2(&d->bus, hd_table[0], hd_table[1], irq);
+ide_init2_with_non_qdev_drives(&d->bus, hd_table[0], hd_table[1], irq);
 
 if (dbdma)
 DBDMA_register_channel(dbdma, channel, dma_irq, pmac_ide_transfer, 
pmac_ide_flush, d);
diff --git a/hw/ide/microdrive.c b/hw/ide/microdrive.c
index bfdb8c8..a7beac5 100644
--- a/hw/ide/microdrive.c
+++ b/hw/ide/microdrive.c
@@ -539,7 +539,8 @@ PCMCIACardState *dscm1_init(DriveInfo *bdrv)
 md->card.cis = dscm1_cis;
 md->card.cis_len = sizeof(dscm1_cis);
 
-ide_init2(&md->bus, bdrv, NULL, qemu_allocate_irqs(md_set_irq, md, 1)[0]);
+ide_init2_with_non_qdev_drives(&md->bus, bdrv, NULL,
+   qemu_allocate_irqs(md_set_irq, md, 1)[0]);
 md->bus.ifs[0].is_cf = 1;
 md->bus.ifs[0].mdata_size = METADATA_SIZE;
 md->bus.ifs[0].mdata_storage = (uint8_t *) qemu_mallocz(METADATA_SIZE);
diff --git a/hw/ide/mmio.c b/hw/ide/mmio.c
ind

[Qemu-devel] [PATCH 06/17] Move win32 early signal handling setup to os_setup_signal_handling()

2010-06-04 Thread Jes . Sorensen
From: Jes Sorensen 

Move win32 early signal handling setup to os_setup_signal_handling()

Signed-off-by: Jes Sorensen 
---
 os-win32.c  |   29 +
 qemu-os-posix.h |2 --
 sysemu.h|2 ++
 vl.c|   30 --
 4 files changed, 31 insertions(+), 32 deletions(-)

diff --git a/os-win32.c b/os-win32.c
index 1f7e28b..dfa90bc 100644
--- a/os-win32.c
+++ b/os-win32.c
@@ -152,3 +152,32 @@ void os_host_main_loop_wait(int *timeout)
 
 *timeout = 0;
 }
+
+static BOOL WINAPI qemu_ctrl_handler(DWORD type)
+{
+exit(STATUS_CONTROL_C_EXIT);
+return TRUE;
+}
+
+void os_setup_signal_handling(void)
+{
+/* Note: cpu_interrupt() is currently not SMP safe, so we force
+   QEMU to run on a single CPU */
+HANDLE h;
+DWORD mask, smask;
+int i;
+
+SetConsoleCtrlHandler(qemu_ctrl_handler, TRUE);
+
+h = GetCurrentProcess();
+if (GetProcessAffinityMask(h, &mask, &smask)) {
+for(i = 0; i < 32; i++) {
+if (mask & (1 << i))
+break;
+}
+if (i != 32) {
+mask = 1 << i;
+SetProcessAffinityMask(h, mask);
+}
+}
+}
diff --git a/qemu-os-posix.h b/qemu-os-posix.h
index ff5adb1..96d1036 100644
--- a/qemu-os-posix.h
+++ b/qemu-os-posix.h
@@ -30,6 +30,4 @@ static inline void os_host_main_loop_wait(int *timeout)
 {
 }
 
-void os_setup_signal_handling(void);
-
 #endif
diff --git a/sysemu.h b/sysemu.h
index 5e4feae..e3643ad 100644
--- a/sysemu.h
+++ b/sysemu.h
@@ -79,6 +79,8 @@ int qemu_loadvm_state(QEMUFile *f);
 /* SLIRP */
 void do_info_slirp(Monitor *mon);
 
+void os_setup_signal_handling(void);
+
 typedef enum DisplayType
 {
 DT_DEFAULT,
diff --git a/vl.c b/vl.c
index 7a46fee..f43456a 100644
--- a/vl.c
+++ b/vl.c
@@ -1986,14 +1986,6 @@ static int balloon_parse(const char *arg)
 return -1;
 }
 
-#ifdef _WIN32
-static BOOL WINAPI qemu_ctrl_handler(DWORD type)
-{
-exit(STATUS_CONTROL_C_EXIT);
-return TRUE;
-}
-#endif
-
 #ifndef _WIN32
 
 static void termsig_handler(int signal)
@@ -2459,29 +2451,7 @@ int main(int argc, char **argv, char **envp)
 qemu_cache_utils_init(envp);
 
 QLIST_INIT (&vm_change_state_head);
-#ifndef _WIN32
 os_setup_signal_handling();
-#else
-SetConsoleCtrlHandler(qemu_ctrl_handler, TRUE);
-/* Note: cpu_interrupt() is currently not SMP safe, so we force
-   QEMU to run on a single CPU */
-{
-HANDLE h;
-DWORD mask, smask;
-int i;
-h = GetCurrentProcess();
-if (GetProcessAffinityMask(h, &mask, &smask)) {
-for(i = 0; i < 32; i++) {
-if (mask & (1 << i))
-break;
-}
-if (i != 32) {
-mask = 1 << i;
-SetProcessAffinityMask(h, mask);
-}
-}
-}
-#endif
 
 module_call_init(MODULE_INIT_MACHINE);
 machine = find_default_machine();
-- 
1.6.5.2




[Qemu-devel] [PATCH 15/27] qdev: Don't leak string property value on hot unplug

2010-06-04 Thread Kevin Wolf
From: Markus Armbruster 

parse_string() qemu_strdup()s the property value.  It is never freed.
It needs to be freed along with the device.  Otherwise, the value of
scsi-disk property "ver" gets leaked when hot-unplugging the disk, for
instance.

Call new PropertyInfo method free() from qdev_free().  Implement it
for qdev_prop_string.

Signed-off-by: Markus Armbruster 
Signed-off-by: Kevin Wolf 
---
 hw/qdev-properties.c |6 ++
 hw/qdev.c|6 ++
 hw/qdev.h|1 +
 3 files changed, 13 insertions(+), 0 deletions(-)

diff --git a/hw/qdev-properties.c b/hw/qdev-properties.c
index b6ee50f..48a6b45 100644
--- a/hw/qdev-properties.c
+++ b/hw/qdev-properties.c
@@ -260,6 +260,11 @@ static int parse_string(DeviceState *dev, Property *prop, 
const char *str)
 return 0;
 }
 
+static void free_string(DeviceState *dev, Property *prop)
+{
+qemu_free(*(char **)qdev_get_prop_ptr(dev, prop));
+}
+
 static int print_string(DeviceState *dev, Property *prop, char *dest, size_t 
len)
 {
 char **ptr = qdev_get_prop_ptr(dev, prop);
@@ -274,6 +279,7 @@ PropertyInfo qdev_prop_string = {
 .size  = sizeof(char*),
 .parse = parse_string,
 .print = print_string,
+.free  = free_string,
 };
 
 /* --- drive --- */
diff --git a/hw/qdev.c b/hw/qdev.c
index aa2ce01..29f6e9f 100644
--- a/hw/qdev.c
+++ b/hw/qdev.c
@@ -334,6 +334,7 @@ void qdev_init_nofail(DeviceState *dev)
 void qdev_free(DeviceState *dev)
 {
 BusState *bus;
+Property *prop;
 
 if (dev->state == DEV_STATE_INITIALIZED) {
 while (dev->num_child_bus) {
@@ -349,6 +350,11 @@ void qdev_free(DeviceState *dev)
 }
 qemu_unregister_reset(qdev_reset, dev);
 QLIST_REMOVE(dev, sibling);
+for (prop = dev->info->props; prop && prop->name; prop++) {
+if (prop->info->free) {
+prop->info->free(dev, prop);
+}
+}
 qemu_free(dev);
 }
 
diff --git a/hw/qdev.h b/hw/qdev.h
index 7c25a94..51a24e2 100644
--- a/hw/qdev.h
+++ b/hw/qdev.h
@@ -98,6 +98,7 @@ struct PropertyInfo {
 enum PropertyType type;
 int (*parse)(DeviceState *dev, Property *prop, const char *str);
 int (*print)(DeviceState *dev, Property *prop, char *dest, size_t len);
+void (*free)(DeviceState *dev, Property *prop);
 };
 
 typedef struct GlobalProperty {
-- 
1.6.6.1




[Qemu-devel] [PATCH 04/27] Cleanup: virtio-blk.c: Be more consistent using BDRV_SECTOR_SIZE instead

2010-06-04 Thread Kevin Wolf
From: Jes Sorensen 

Clean up virtio-blk.c to be more consistent using BDRV_SECTOR_SIZE
instead of hard coded 512 values.

Signed-off-by: Jes Sorensen 
Signed-off-by: Kevin Wolf 
---
 hw/virtio-blk.c |7 ---
 1 files changed, 4 insertions(+), 3 deletions(-)

diff --git a/hw/virtio-blk.c b/hw/virtio-blk.c
index 5d7f1a2..80d51c4 100644
--- a/hw/virtio-blk.c
+++ b/hw/virtio-blk.c
@@ -277,7 +277,7 @@ static void virtio_blk_handle_write(BlockRequest *blkreq, 
int *num_writes,
 }
 
 blkreq[*num_writes].sector = req->out->sector;
-blkreq[*num_writes].nb_sectors = req->qiov.size / 512;
+blkreq[*num_writes].nb_sectors = req->qiov.size / BDRV_SECTOR_SIZE;
 blkreq[*num_writes].qiov = &req->qiov;
 blkreq[*num_writes].cb = virtio_blk_rw_complete;
 blkreq[*num_writes].opaque = req;
@@ -296,7 +296,8 @@ static void virtio_blk_handle_read(VirtIOBlockReq *req)
 }
 
 acb = bdrv_aio_readv(req->dev->bs, req->out->sector, &req->qiov,
- req->qiov.size / 512, virtio_blk_rw_complete, req);
+ req->qiov.size / BDRV_SECTOR_SIZE,
+ virtio_blk_rw_complete, req);
 if (!acb) {
 virtio_blk_rw_complete(req, -EIO);
 }
@@ -505,7 +506,7 @@ VirtIODevice *virtio_blk_init(DeviceState *dev, BlockConf 
*conf)
 s->bs = conf->dinfo->bdrv;
 s->conf = conf;
 s->rq = NULL;
-s->sector_mask = (s->conf->logical_block_size / 512) - 1;
+s->sector_mask = (s->conf->logical_block_size / BDRV_SECTOR_SIZE) - 1;
 bdrv_guess_geometry(s->bs, &cylinders, &heads, &secs);
 
 s->vq = virtio_add_queue(&s->vdev, 128, virtio_blk_handle_output);
-- 
1.6.6.1




[Qemu-devel] [PATCH 02/17] Create qemu-os-win32.h and move WIN32 specific declarations there

2010-06-04 Thread Jes . Sorensen
From: Jes Sorensen 

Create qemu-os-win32.h for WIN32 specific declarations. Move polling
handling declaration into this file from sysemu.h

Signed-off-by: Jes Sorensen 
---
 qemu-os-win32.h |   43 +++
 sysemu.h|   17 +
 2 files changed, 44 insertions(+), 16 deletions(-)
 create mode 100644 qemu-os-win32.h

diff --git a/qemu-os-win32.h b/qemu-os-win32.h
new file mode 100644
index 000..be108ad
--- /dev/null
+++ b/qemu-os-win32.h
@@ -0,0 +1,43 @@
+/*
+ * win32 specific declarations
+ *
+ * Copyright (c) 2003-2008 Fabrice Bellard
+ * Copyright (c) 2010 Jes Sorensen 
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to 
deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
+ * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 
FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ * THE SOFTWARE.
+ */
+
+#ifndef QEMU_OS_WIN32_H
+#define QEMU_OS_WIN32_H
+
+/* Polling handling */
+
+/* return TRUE if no sleep should be done afterwards */
+typedef int PollingFunc(void *opaque);
+
+int qemu_add_polling_cb(PollingFunc *func, void *opaque);
+void qemu_del_polling_cb(PollingFunc *func, void *opaque);
+
+/* Wait objects handling */
+typedef void WaitObjectFunc(void *opaque);
+
+int qemu_add_wait_object(HANDLE handle, WaitObjectFunc *func, void *opaque);
+void qemu_del_wait_object(HANDLE handle, WaitObjectFunc *func, void *opaque);
+
+#endif
diff --git a/sysemu.h b/sysemu.h
index 879446a..13fc9a9 100644
--- a/sysemu.h
+++ b/sysemu.h
@@ -9,6 +9,7 @@
 
 #ifdef _WIN32
 #include 
+#include "qemu-os-win32.h"
 #endif
 
 /* vl.c */
@@ -71,22 +72,6 @@ int qemu_savevm_state_complete(Monitor *mon, QEMUFile *f);
 void qemu_savevm_state_cancel(Monitor *mon, QEMUFile *f);
 int qemu_loadvm_state(QEMUFile *f);
 
-#ifdef _WIN32
-/* Polling handling */
-
-/* return TRUE if no sleep should be done afterwards */
-typedef int PollingFunc(void *opaque);
-
-int qemu_add_polling_cb(PollingFunc *func, void *opaque);
-void qemu_del_polling_cb(PollingFunc *func, void *opaque);
-
-/* Wait objects handling */
-typedef void WaitObjectFunc(void *opaque);
-
-int qemu_add_wait_object(HANDLE handle, WaitObjectFunc *func, void *opaque);
-void qemu_del_wait_object(HANDLE handle, WaitObjectFunc *func, void *opaque);
-#endif
-
 /* SLIRP */
 void do_info_slirp(Monitor *mon);
 
-- 
1.6.5.2




[Qemu-devel] [PATCH 11/17] Introduce OS specific cmdline argument handling and move SMB arg to os-posix.c

2010-06-04 Thread Jes . Sorensen
From: Jes Sorensen 

Introduce OS specific cmdline argument handling by calling
os_parse_cmd_args() at the end of switch() statement. Move option
enum to qemu-options.h and have it included from os-posix.c and
os-win32.c in addition to vl.c.

In addition move SMB argument to os-posix.c

Signed-off-by: Jes Sorensen 
---
 Makefile.objs  |2 ++
 os-posix.c |   19 +++
 os-win32.c |   10 ++
 qemu-options.h |   41 +
 sysemu.h   |1 +
 vl.c   |   19 +++
 6 files changed, 76 insertions(+), 16 deletions(-)
 create mode 100644 qemu-options.h

diff --git a/Makefile.objs b/Makefile.objs
index 124afe7..27595df 100644
--- a/Makefile.objs
+++ b/Makefile.objs
@@ -259,6 +259,8 @@ vl.o: QEMU_CFLAGS+=$(GPROF_CFLAGS)
 vl.o: QEMU_CFLAGS+=$(SDL_CFLAGS)
 
 vl.o: qemu-options.def
+os-posix.o: qemu-options.def
+os-win32.o: qemu-options.def
 
 qemu-options.def: $(SRC_PATH)/qemu-options.hx
$(call quiet-command,sh $(SRC_PATH)/hxtool -h < $< > $@,"  GEN   
$(TARGET_DIR)$@")
diff --git a/os-posix.c b/os-posix.c
index 621ad06..0deddf3 100644
--- a/os-posix.c
+++ b/os-posix.c
@@ -33,6 +33,8 @@
 /* Needed early for CONFIG_BSD etc. */
 #include "config-host.h"
 #include "sysemu.h"
+#include "net/slirp.h"
+#include "qemu-options.h"
 
 void os_setup_early_signal_handling(void)
 {
@@ -130,3 +132,20 @@ char *os_find_datadir(const char *argv0)
 }
 #undef SHARE_SUFFIX
 #undef BUILD_SUFFIX
+
+/*
+ * Parse OS specific command line options.
+ * return 0 if option handled, -1 otherwise
+ */
+void os_parse_cmd_args(int index, const char *optarg)
+{
+switch (index) {
+#ifdef CONFIG_SLIRP
+case QEMU_OPTION_smb:
+if (net_slirp_smb(optarg) < 0)
+exit(1);
+break;
+#endif
+}
+return;
+}
diff --git a/os-win32.c b/os-win32.c
index 1758538..aefc535 100644
--- a/os-win32.c
+++ b/os-win32.c
@@ -31,6 +31,7 @@
 #include 
 #include "config-host.h"
 #include "sysemu.h"
+#include "qemu-options.h"
 
 /***/
 /* Polling handling */
@@ -204,3 +205,12 @@ char *os_find_datadir(const char *argv0)
 }
 return NULL;
 }
+
+/*
+ * Parse OS specific command line options.
+ * return 0 if option handled, -1 otherwise
+ */
+void os_parse_cmd_args(int index, const char *optarg)
+{
+return;
+}
diff --git a/qemu-options.h b/qemu-options.h
new file mode 100644
index 000..c96f994
--- /dev/null
+++ b/qemu-options.h
@@ -0,0 +1,41 @@
+/*
+ * qemu-options.h
+ *
+ * Defines needed for command line argument processing.
+ *
+ * Copyright (c) 2003-2008 Fabrice Bellard
+ * Copyright (c) 2010 Jes Sorensen 
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to 
deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
+ * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 
FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ * THE SOFTWARE.
+ */
+
+#ifndef _QEMU_OPTIONS_H_
+#define _QEMU_OPTIONS_H_
+
+enum {
+#define DEF(option, opt_arg, opt_enum, opt_help, arch_mask) \
+opt_enum,
+#define DEFHEADING(text)
+#include "qemu-options.def"
+#undef DEF
+#undef DEFHEADING
+#undef GEN_DOCS
+};
+
+#endif
diff --git a/sysemu.h b/sysemu.h
index 72f3734..2162b1d 100644
--- a/sysemu.h
+++ b/sysemu.h
@@ -82,6 +82,7 @@ void do_info_slirp(Monitor *mon);
 /* OS specific functions */
 void os_setup_early_signal_handling(void);
 char *os_find_datadir(const char *argv0);
+void os_parse_cmd_args(int index, const char *optarg);
 
 typedef enum DisplayType
 {
diff --git a/vl.c b/vl.c
index 8cd0f8f..7c48024 100644
--- a/vl.c
+++ b/vl.c
@@ -148,6 +148,7 @@ int main(int argc, char **argv)
 #include "qemu-option.h"
 #include "qemu-config.h"
 #include "qemu-objects.h"
+#include "qemu-options.h"
 #ifdef CONFIG_LINUX
 #include "fsdev/qemu-fsdev.h"
 #endif
@@ -1899,16 +1900,6 @@ static void help(int exitcode)
 
 #define HAS_ARG 0x0001
 
-enum {
-#define DEF(option, opt_arg, opt_enum, opt_help, arch_mask) \
-opt_enum,
-#define DEFHEADING(text)
-#include "qemu-options.def"
-#undef DEF
-#undef DEFHEADING
-#undef GEN_DOCS
-};
-
 typedef struct QEMUOp

[Qemu-devel] [PATCH 11/27] ide: Split ide_init1() off ide_init2()

2010-06-04 Thread Kevin Wolf
From: Markus Armbruster 

Signed-off-by: Markus Armbruster 
Signed-off-by: Kevin Wolf 
---
 hw/ide/core.c |   32 +---
 1 files changed, 17 insertions(+), 15 deletions(-)

diff --git a/hw/ide/core.c b/hw/ide/core.c
index c3334b1..443ff10 100644
--- a/hw/ide/core.c
+++ b/hw/ide/core.c
@@ -2633,27 +2633,29 @@ void ide_init_drive(IDEState *s, DriveInfo *dinfo, 
const char *version)
 ide_reset(s);
 }
 
+static void ide_init1(IDEBus *bus, int unit, DriveInfo *dinfo)
+{
+static int drive_serial = 1;
+IDEState *s = &bus->ifs[unit];
+
+s->bus = bus;
+s->unit = unit;
+s->drive_serial = drive_serial++;
+s->io_buffer = qemu_blockalign(s->bs, IDE_DMA_BUF_SECTORS*512 + 4);
+s->io_buffer_total_len = IDE_DMA_BUF_SECTORS*512 + 4;
+s->smart_selftest_data = qemu_blockalign(s->bs, 512);
+s->sector_write_timer = qemu_new_timer(vm_clock,
+   ide_sector_write_timer_cb, s);
+ide_init_drive(s, dinfo, NULL);
+}
+
 void ide_init2(IDEBus *bus, DriveInfo *hd0, DriveInfo *hd1,
qemu_irq irq)
 {
-IDEState *s;
-static int drive_serial = 1;
 int i;
 
 for(i = 0; i < 2; i++) {
-s = bus->ifs + i;
-s->bus = bus;
-s->unit = i;
-s->drive_serial = drive_serial++;
-s->io_buffer = qemu_blockalign(s->bs, IDE_DMA_BUF_SECTORS*512 + 4);
-s->io_buffer_total_len = IDE_DMA_BUF_SECTORS*512 + 4;
-s->smart_selftest_data = qemu_blockalign(s->bs, 512);
-s->sector_write_timer = qemu_new_timer(vm_clock,
-   ide_sector_write_timer_cb, s);
-if (i == 0)
-ide_init_drive(s, hd0, NULL);
-if (i == 1)
-ide_init_drive(s, hd1, NULL);
+ide_init1(bus, i, i == 0 ? hd0 : hd1);
 }
 bus->irq = irq;
 }
-- 
1.6.6.1




[Qemu-devel] Re: RFC: blockdev_add & friends, brief rationale, QMP docs

2010-06-04 Thread Kevin Wolf
Am 04.06.2010 17:53, schrieb Markus Armbruster:
> Kevin Wolf  writes:
> 
>> Am 04.06.2010 16:16, schrieb Markus Armbruster:
>>> Our abstraction for formats is struct BlockDriver.
>>>
>>> Our abstraction for protocols is also struct BlockDriver.  Except for
>>> the special protocol "file", but that's detail.
>>
>> See above, file isn't really special.
> 
> I got confused by this code in bdrv_open_common():
> 
> /* Open the image, either directly or using a protocol */
> if (drv->bdrv_file_open) {
> ret = drv->bdrv_file_open(bs, filename, open_flags);
> } else {
> ret = bdrv_file_open(&bs->file, filename, open_flags);
> if (ret >= 0) {
> ret = drv->bdrv_open(bs, open_flags);
> }
> }
> 
> When called by drive_init() via bdrv_open(), drv is the BlockDriver
> named by format=F.  If drv->bdrv_file_open, is drv a format or a
> protocol?  

A protocol. Formats use bdrv_open and get a BlockDriverState of the
underlying protocol as a parameter, whereas protocols use bdrv_file_open
and get the filename as a parameter.

> It's true for F in blkdebug, cow, http, https, ftp, ftps,
> tftp, nbd, file, host_device, host_floppy, host_cdrom, vvfat, so it's a
> protocol (except for cow, but Christoph tells me he's about to get that
> one off the list).  But what's the format then?

You're not supposed to use a protocol with format=F, even though
currently it works. Once cow is converted (it currently accesses the
file directly with POSIX functions instead of using the protocol) we can
make this an error so that it's not even possible to directly use a
protocol. Then the only way to get into the then branch is explicitly
calling bdrv_file_open.

To get the same behaviour as today with directly using a protocol,
you'll need to use raw as the format.

> The conditional's else seems clear: bdrv_file_open() finds the protocol
> in filename (probes the file if missing), and then opens with that
> protocol.
> 
>>> Examples:
>>>
>>> -drive file=foo.qcow2,format=qcow2
>>>
>>>  Format "qcow2", protocol "file" with argument filename "foo.img"
>>
>> Actually the protocol is guessed here. For this, not all protocols are
>> considered, it's only between file/host_device/host_cdrom/host_floppy
>> (these are the protocols implementing bdrv_probe_device, and file as the
>> default if no other protocol feels responsible)
> 
> Then we need a way to ask for this guessing, say (pseudo-)protocol
> "auto".

I agree.

>>> -drive file=nbd:unix:/tmp/my_socket,format=raw
>>>
>>>  Format "raw", protocol "nbd" with arguments domain "unix", filename
>>>  "/tmp/my_socket"
>>>
>>> -drive blkdebug:/tmp/blkdebug.cfg:fat:floppy:rw:/tmp/dir
>>>
>>>  Format not specified (system guesses one), protocol "blkdebug" with
>>>  argument filename "/tmp/blkdebug.cfg" stacked onto protocol "fat" with
>>>  arguments floppy true, dirname "/tmp/dir"
>>
>> These look right to me.
>>
>>>
>>> You see that -drive has a separate option for format, but has protocols
>>> encoded in option file, in their own mini-language.  Doesn't work for
>>> arbitrary filenames.  Besides, mini-languages to encode options in
>>> strings are quite inappropriate for QMP.
>>>
>>> So we need something cleaner for QMP.  Here's a sketch.  Instead of
>>>
>>> - "file": the disk image file to use (json-string, optional)
>>> - "format": disk format (json-string, optional)
>>> - Possible values: "raw", "qcow2", ...
>>>
>>> have
>>>
>>> - "format": disk format (json-string, optional)
>>> - Possible values: "raw", "qcow2", ...
>>> - "protocol": json-array of json-object
>>>   Each element object has a member "name"
>>> - Possible values: "file", "nbd", ...
>>>   Additional members depend on the value of "name".
>>>   For "name" = "file":
>>> - "file": file name (json-string)
>>>   For "name" = "nbd":
>>> - "domain": address family (json-string, optional)
>>> - Possible values: "inet" (default), "unix"
>>> - "file": file name (json-string), only with "domain" = "unix"
>>> - "host": host name (json-string), only with "domain" = "inet"
>>> - "port": port (json-int), only with "domain" = "inet"
>>>   ...
>>>
>>> You get the idea.
>>>
>>> Comments?
>>
>> Makes sense.
>>
>> So blkdebug would define a field "protocol" (json-object) that it uses
>> to initialize the underlying protocol and we would get the stacking this
>> way?
> 
> No, my proposal represents the stack of protocols as json-array, not by
> nesting them.  I should have given examples.  Reusing my three examples
> from above:

Ah, sorry, I missed the part with the array. That's probably even better.

> 
> * Format "qcow2", protocol "auto" with argument filename "foo.img"
> 
> "format": "qcow2",
> "protocol": [{ "name": "auto", "file": "foo.qcow2" }],
> 
> * Format "raw", protocol "nbd" with arguments domain "unix", filename
>   "/tmp/my_socket"
> 
> "format": "raw"
> "protocol": [{ "name": "nbd", "domain": "unix", "file": "/tmp/my_socket" 

Re: [Qemu-devel] [PATCH] target-i386: fix decoding of negative 4-byte displacements

2010-06-04 Thread Richard Henderson
On 06/04/2010 07:27 AM, Paolo Bonzini wrote:
> Negative four byte displacements need to be sign-extended after
> c086b783eb7a578993d6d2ab62c4c2666800b63d.  Do so.

Acked-by: Richard Henderson  


> There are quite a few other ldl's to audit after the patch
> (about 70 in target-*).  Any volunteers? :-)

I've looked over all the uses of ldl_code.  Thankfully 95% of them
are immediately stored into an explicit 32-bit variable.  I do not
see any other problematic uses of that particular identifier.


r~



[Qemu-devel] [PATCH 05/17] Introduce os-posix.c and create os_setup_signal_handling()

2010-06-04 Thread Jes . Sorensen
From: Jes Sorensen 

Introcuce os-posix.c and move posix specific signal handling
there.

Signed-off-by: Jes Sorensen 
---
 Makefile.objs   |1 +
 os-posix.c  |   41 +
 qemu-os-posix.h |2 ++
 vl.c|8 +---
 4 files changed, 45 insertions(+), 7 deletions(-)
 create mode 100644 os-posix.c

diff --git a/Makefile.objs b/Makefile.objs
index 58fdb03..2d94677 100644
--- a/Makefile.objs
+++ b/Makefile.objs
@@ -145,6 +145,7 @@ hw-obj-$(CONFIG_NAND) += nand.o
 hw-obj-$(CONFIG_PFLASH_CFI01) += pflash_cfi01.o
 hw-obj-$(CONFIG_PFLASH_CFI02) += pflash_cfi02.o
 hw-obj-$(CONFIG_WIN32) += os-win32.o
+hw-obj-$(CONFIG_POSIX) += os-posix.o
 
 hw-obj-$(CONFIG_M48T59) += m48t59.o
 hw-obj-$(CONFIG_ESCC) += escc.o
diff --git a/os-posix.c b/os-posix.c
new file mode 100644
index 000..914a4d1
--- /dev/null
+++ b/os-posix.c
@@ -0,0 +1,41 @@
+/*
+ * os-posix.c
+ *
+ * Copyright (c) 2003-2008 Fabrice Bellard
+ * Copyright (c) 2010 Red Hat, Inc.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to 
deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
+ * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 
FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ * THE SOFTWARE.
+ */
+
+#include 
+#include 
+#include 
+
+/* Needed early for CONFIG_BSD etc. */
+#include "config-host.h"
+#include "sysemu.h"
+
+void os_setup_signal_handling(void)
+{
+struct sigaction act;
+sigfillset(&act.sa_mask);
+act.sa_flags = 0;
+act.sa_handler = SIG_IGN;
+sigaction(SIGPIPE, &act, NULL);
+}
diff --git a/qemu-os-posix.h b/qemu-os-posix.h
index 96d1036..ff5adb1 100644
--- a/qemu-os-posix.h
+++ b/qemu-os-posix.h
@@ -30,4 +30,6 @@ static inline void os_host_main_loop_wait(int *timeout)
 {
 }
 
+void os_setup_signal_handling(void);
+
 #endif
diff --git a/vl.c b/vl.c
index c655582..7a46fee 100644
--- a/vl.c
+++ b/vl.c
@@ -2460,13 +2460,7 @@ int main(int argc, char **argv, char **envp)
 
 QLIST_INIT (&vm_change_state_head);
 #ifndef _WIN32
-{
-struct sigaction act;
-sigfillset(&act.sa_mask);
-act.sa_flags = 0;
-act.sa_handler = SIG_IGN;
-sigaction(SIGPIPE, &act, NULL);
-}
+os_setup_signal_handling();
 #else
 SetConsoleCtrlHandler(qemu_ctrl_handler, TRUE);
 /* Note: cpu_interrupt() is currently not SMP safe, so we force
-- 
1.6.5.2




[Qemu-devel] [PATCH 01/17] vl.c: Remove double include of netinet/in.h for Solaris

2010-06-04 Thread Jes . Sorensen
From: Jes Sorensen 

vl.c: netinet/in.h is already included once above for in the generic
POSIX section.

Signed-off-by: Jes Sorensen 
---
 vl.c |1 -
 1 files changed, 0 insertions(+), 1 deletions(-)

diff --git a/vl.c b/vl.c
index 417554f..7c4298a 100644
--- a/vl.c
+++ b/vl.c
@@ -70,7 +70,6 @@
 #include 
 #include 
 #include 
-#include 
 #include 
 #include 
 #include  // must come after ip.h
-- 
1.6.5.2




[Qemu-devel] [PATCH 14/17] Move daemonize handling to OS specific files

2010-06-04 Thread Jes . Sorensen
From: Jes Sorensen 

Move daemonize handling from vl.c to OS specific files. Provide dummy
stubs for Win32.

Signed-off-by: Jes Sorensen 
---
 os-posix.c  |  102 
 os-win32.c  |5 +++
 qemu-os-posix.h |2 +
 qemu-os-win32.h |2 +
 sysemu.h|1 +
 vl.c|  106 ++-
 6 files changed, 115 insertions(+), 103 deletions(-)

diff --git a/os-posix.c b/os-posix.c
index 6417d16..1672e06 100644
--- a/os-posix.c
+++ b/os-posix.c
@@ -39,6 +39,8 @@
 
 static struct passwd *user_pwd;
 static const char *chroot_dir;
+static int daemonize;
+static int fds[2];
 
 void os_setup_early_signal_handling(void)
 {
@@ -160,6 +162,9 @@ void os_parse_cmd_args(int index, const char *optarg)
 case QEMU_OPTION_chroot:
 chroot_dir = optarg;
 break;
+case QEMU_OPTION_daemonize:
+daemonize = 1;
+break;
 }
 return;
 }
@@ -196,3 +201,100 @@ void os_change_root(void)
 }
 
 }
+
+void os_daemonize(void)
+{
+if (daemonize) {
+   pid_t pid;
+
+   if (pipe(fds) == -1)
+   exit(1);
+
+   pid = fork();
+   if (pid > 0) {
+   uint8_t status;
+   ssize_t len;
+
+   close(fds[1]);
+
+   again:
+len = read(fds[0], &status, 1);
+if (len == -1 && (errno == EINTR))
+goto again;
+
+if (len != 1)
+exit(1);
+else if (status == 1) {
+fprintf(stderr, "Could not acquire pidfile: %s\n", 
strerror(errno));
+exit(1);
+} else
+exit(0);
+   } else if (pid < 0)
+exit(1);
+
+   close(fds[0]);
+   qemu_set_cloexec(fds[1]);
+
+   setsid();
+
+   pid = fork();
+   if (pid > 0)
+   exit(0);
+   else if (pid < 0)
+   exit(1);
+
+   umask(027);
+
+signal(SIGTSTP, SIG_IGN);
+signal(SIGTTOU, SIG_IGN);
+signal(SIGTTIN, SIG_IGN);
+}
+}
+
+void os_setup_post(void)
+{
+int fd = 0;
+
+if (daemonize) {
+   uint8_t status = 0;
+   ssize_t len;
+
+again1:
+   len = write(fds[1], &status, 1);
+   if (len == -1 && (errno == EINTR))
+   goto again1;
+
+   if (len != 1)
+   exit(1);
+
+if (chdir("/")) {
+perror("not able to chdir to /");
+exit(1);
+}
+   TFR(fd = qemu_open("/dev/null", O_RDWR));
+   if (fd == -1)
+   exit(1);
+}
+
+os_change_root();
+os_change_process_uid();
+
+if (daemonize) {
+dup2(fd, 0);
+dup2(fd, 1);
+dup2(fd, 2);
+
+close(fd);
+}
+}
+
+void os_pidfile_error(void)
+{
+if (daemonize) {
+uint8_t status = 1;
+if (write(fds[1], &status, 1) != 1) {
+perror("daemonize. Writing to pipe\n");
+}
+} else
+fprintf(stderr, "Could not acquire pid file: %s\n", strerror(errno));
+}
diff --git a/os-win32.c b/os-win32.c
index aefc535..d98fd77 100644
--- a/os-win32.c
+++ b/os-win32.c
@@ -214,3 +214,8 @@ void os_parse_cmd_args(int index, const char *optarg)
 {
 return;
 }
+
+void os_pidfile_error(void)
+{
+fprintf(stderr, "Could not acquire pid file: %s\n", strerror(errno));
+}
diff --git a/qemu-os-posix.h b/qemu-os-posix.h
index 91c7b68..9b07660 100644
--- a/qemu-os-posix.h
+++ b/qemu-os-posix.h
@@ -33,5 +33,7 @@ static inline void os_host_main_loop_wait(int *timeout)
 void os_setup_signal_handling(void);
 void os_change_process_uid(void);
 void os_change_root(void);
+void os_daemonize(void);
+void os_setup_post(void);
 
 #endif
diff --git a/qemu-os-win32.h b/qemu-os-win32.h
index e2a97d2..c4aa84a 100644
--- a/qemu-os-win32.h
+++ b/qemu-os-win32.h
@@ -45,5 +45,7 @@ void os_host_main_loop_wait(int *timeout);
 static inline void os_setup_signal_handling(void) {}
 static inline void os_change_process_uid(void) {}
 static inline void os_change_root(void) {}
+static inline void os_daemonize(void) {}
+static inline void os_setup_post(void) {}
 
 #endif
diff --git a/sysemu.h b/sysemu.h
index 2162b1d..346cccd 100644
--- a/sysemu.h
+++ b/sysemu.h
@@ -83,6 +83,7 @@ void do_info_slirp(Monitor *mon);
 void os_setup_early_signal_handling(void);
 char *os_find_datadir(const char *argv0);
 void os_parse_cmd_args(int index, const char *optarg);
+void os_pidfile_error(void);
 
 typedef enum DisplayType
 {
diff --git a/vl.c b/vl.c
index fc0e23d..c22d16f 100644
--- a/vl.c
+++ b/vl.c
@@ -216,9 +216,6 @@ int no_shutdown = 0;
 int cursor_hide = 1;
 int graphic_rotate = 0;
 uint8_t irq0override = 1;
-#ifndef _WIN32
-int daemonize = 0;
-#endif
 const char *watchdog;
 const char *option_rom[MAX_OPTION_ROMS];
 int nb_option_roms;
@@ -2301,15 +2298,9 @@ int main(int argc, char **argv, char **envp)
 const char *loadvm = NULL;
 QEMUMachine *machine;
 const char *cpu_model;
-#ifndef _WIN32
-int fds[2];
-#endif
 int 

[Qemu-devel] [PATCH 08/17] Move main signal handler setup to os specificfiles.

2010-06-04 Thread Jes . Sorensen
From: Jes Sorensen 

Move main signal handler setup to os specific files.

Signed-off-by: Jes Sorensen 
---
 os-posix.c  |   27 +++
 qemu-os-posix.h |2 ++
 qemu-os-win32.h |3 +++
 vl.c|   33 +
 4 files changed, 33 insertions(+), 32 deletions(-)

diff --git a/os-posix.c b/os-posix.c
index 948f662..01dbec2 100644
--- a/os-posix.c
+++ b/os-posix.c
@@ -26,6 +26,8 @@
 #include 
 #include 
 #include 
+#include 
+#include 
 
 /* Needed early for CONFIG_BSD etc. */
 #include "config-host.h"
@@ -39,3 +41,28 @@ void os_setup_early_signal_handling(void)
 act.sa_handler = SIG_IGN;
 sigaction(SIGPIPE, &act, NULL);
 }
+
+static void termsig_handler(int signal)
+{
+qemu_system_shutdown_request();
+}
+
+static void sigchld_handler(int signal)
+{
+waitpid(-1, NULL, WNOHANG);
+}
+
+void os_setup_signal_handling(void)
+{
+struct sigaction act;
+
+memset(&act, 0, sizeof(act));
+act.sa_handler = termsig_handler;
+sigaction(SIGINT,  &act, NULL);
+sigaction(SIGHUP,  &act, NULL);
+sigaction(SIGTERM, &act, NULL);
+
+act.sa_handler = sigchld_handler;
+act.sa_flags = SA_NOCLDSTOP;
+sigaction(SIGCHLD, &act, NULL);
+}
diff --git a/qemu-os-posix.h b/qemu-os-posix.h
index 96d1036..ff5adb1 100644
--- a/qemu-os-posix.h
+++ b/qemu-os-posix.h
@@ -30,4 +30,6 @@ static inline void os_host_main_loop_wait(int *timeout)
 {
 }
 
+void os_setup_signal_handling(void);
+
 #endif
diff --git a/qemu-os-win32.h b/qemu-os-win32.h
index 4d1cac8..e7e2ee3 100644
--- a/qemu-os-win32.h
+++ b/qemu-os-win32.h
@@ -41,4 +41,7 @@ int qemu_add_wait_object(HANDLE handle, WaitObjectFunc *func, 
void *opaque);
 void qemu_del_wait_object(HANDLE handle, WaitObjectFunc *func, void *opaque);
 
 void os_host_main_loop_wait(int *timeout);
+
+static inline void os_setup_signal_handling(void) {}
+
 #endif
diff --git a/vl.c b/vl.c
index 372f931..fc5e8d8 100644
--- a/vl.c
+++ b/vl.c
@@ -1986,35 +1986,6 @@ static int balloon_parse(const char *arg)
 return -1;
 }
 
-#ifndef _WIN32
-
-static void termsig_handler(int signal)
-{
-qemu_system_shutdown_request();
-}
-
-static void sigchld_handler(int signal)
-{
-waitpid(-1, NULL, WNOHANG);
-}
-
-static void sighandler_setup(void)
-{
-struct sigaction act;
-
-memset(&act, 0, sizeof(act));
-act.sa_handler = termsig_handler;
-sigaction(SIGINT,  &act, NULL);
-sigaction(SIGHUP,  &act, NULL);
-sigaction(SIGTERM, &act, NULL);
-
-act.sa_handler = sigchld_handler;
-act.sa_flags = SA_NOCLDSTOP;
-sigaction(SIGCHLD, &act, NULL);
-}
-
-#endif
-
 #ifdef _WIN32
 /* Look for support files in the same directory as the executable.  */
 static char *find_datadir(const char *argv0)
@@ -3556,10 +3527,8 @@ int main(int argc, char **argv, char **envp)
 
 cpu_synchronize_all_post_init();
 
-#ifndef _WIN32
 /* must be after terminal init, SDL library changes signal handlers */
-sighandler_setup();
-#endif
+os_setup_signal_handling();
 
 set_numa_modes();
 
-- 
1.6.5.2




[Qemu-devel] [PATCH 17/17] Move set_proc_name() to OS specific files.

2010-06-04 Thread Jes . Sorensen
From: Jes Sorensen 

Move handling to change process name to POSIX specific files
plus add a better error message to cover the case where the
feature isn't supported.

Signed-off-by: Jes Sorensen 
---
 os-posix.c  |   24 
 qemu-os-posix.h |1 +
 qemu-os-win32.h |1 +
 vl.c|   19 +--
 4 files changed, 27 insertions(+), 18 deletions(-)

diff --git a/os-posix.c b/os-posix.c
index 9bae8fe..d89020d 100644
--- a/os-posix.c
+++ b/os-posix.c
@@ -37,6 +37,10 @@
 #include "net/slirp.h"
 #include "qemu-options.h"
 
+#ifdef CONFIG_LINUX
+#include 
+#endif
+
 static struct passwd *user_pwd;
 static const char *chroot_dir;
 static int daemonize;
@@ -139,6 +143,26 @@ char *os_find_datadir(const char *argv0)
 #undef SHARE_SUFFIX
 #undef BUILD_SUFFIX
 
+void os_set_proc_name(const char *s)
+{
+#if defined(PR_SET_NAME)
+char name[16];
+if (!s)
+return;
+name[sizeof(name) - 1] = 0;
+strncpy(name, s, sizeof(name));
+/* Could rewrite argv[0] too, but that's a bit more complicated.
+   This simple way is enough for `top'. */
+if (prctl(PR_SET_NAME, name)) {
+perror("unable to change process name");
+exit(1);
+}
+#else
+fprintf(stderr, "Change of process name not supported by your OS\n");
+exit(1);
+#endif 
+}
+
 /*
  * Parse OS specific command line options.
  * return 0 if option handled, -1 otherwise
diff --git a/qemu-os-posix.h b/qemu-os-posix.h
index cb210ba..ed5c058 100644
--- a/qemu-os-posix.h
+++ b/qemu-os-posix.h
@@ -31,6 +31,7 @@ static inline void os_host_main_loop_wait(int *timeout)
 }
 
 void os_set_line_buffering(void);
+void os_set_proc_name(const char *s);
 void os_setup_signal_handling(void);
 void os_daemonize(void);
 void os_setup_post(void);
diff --git a/qemu-os-win32.h b/qemu-os-win32.h
index 5a97d8d..6323f7f 100644
--- a/qemu-os-win32.h
+++ b/qemu-os-win32.h
@@ -47,5 +47,6 @@ static inline void os_daemonize(void) {}
 static inline void os_setup_post(void) {}
 /* Win32 doesn't support line-buffering and requires size >= 2 */
 static inline void os_set_line_buffering(void) {}
+static inline void os_set_proc_name(const char *dummy) {}
 
 #endif
diff --git a/vl.c b/vl.c
index c3641d6..ce501e2 100644
--- a/vl.c
+++ b/vl.c
@@ -59,7 +59,6 @@
 #ifdef __linux__
 #include 
 #include 
-#include 
 
 #include 
 #include 
@@ -284,22 +283,6 @@ static int default_driver_check(QemuOpts *opts, void 
*opaque)
 }
 
 /***/
-
-static void set_proc_name(const char *s)
-{
-#if defined(__linux__) && defined(PR_SET_NAME)
-char name[16];
-if (!s)
-return;
-name[sizeof(name) - 1] = 0;
-strncpy(name, s, sizeof(name));
-/* Could rewrite argv[0] too, but that's a bit more complicated.
-   This simple way is enough for `top'. */
-prctl(PR_SET_NAME, name);
-#endif 
-}
- 
-/***/
 /* real time host monotonic timer */
 
 /* compute with 96 bit intermediate result: (a*b)/c */
@@ -2988,7 +2971,7 @@ int main(int argc, char **argv, char **envp)
exit(1);
}
p += 8;
-   set_proc_name(p);
+   os_set_proc_name(p);
 }  
 }  
 break;
-- 
1.6.5.2




[Qemu-devel] [PATCH 16/17] Move line-buffering setup to OS specific files.

2010-06-04 Thread Jes . Sorensen
From: Jes Sorensen 

Move line-buffering setup to OS specific files.

Signed-off-by: Jes Sorensen 
---
 os-posix.c  |5 +
 qemu-os-posix.h |1 +
 qemu-os-win32.h |2 ++
 vl.c|5 +
 4 files changed, 9 insertions(+), 4 deletions(-)

diff --git a/os-posix.c b/os-posix.c
index 3a96c91..9bae8fe 100644
--- a/os-posix.c
+++ b/os-posix.c
@@ -298,3 +298,8 @@ void os_pidfile_error(void)
 } else
 fprintf(stderr, "Could not acquire pid file: %s\n", strerror(errno));
 }
+
+void os_set_line_buffering(void)
+{
+setvbuf(stdout, NULL, _IOLBF, 0);
+}
diff --git a/qemu-os-posix.h b/qemu-os-posix.h
index 8be583d..cb210ba 100644
--- a/qemu-os-posix.h
+++ b/qemu-os-posix.h
@@ -30,6 +30,7 @@ static inline void os_host_main_loop_wait(int *timeout)
 {
 }
 
+void os_set_line_buffering(void);
 void os_setup_signal_handling(void);
 void os_daemonize(void);
 void os_setup_post(void);
diff --git a/qemu-os-win32.h b/qemu-os-win32.h
index 39df333..5a97d8d 100644
--- a/qemu-os-win32.h
+++ b/qemu-os-win32.h
@@ -45,5 +45,7 @@ void os_host_main_loop_wait(int *timeout);
 static inline void os_setup_signal_handling(void) {}
 static inline void os_daemonize(void) {}
 static inline void os_setup_post(void) {}
+/* Win32 doesn't support line-buffering and requires size >= 2 */
+static inline void os_set_line_buffering(void) {}
 
 #endif
diff --git a/vl.c b/vl.c
index c22d16f..c3641d6 100644
--- a/vl.c
+++ b/vl.c
@@ -3214,10 +3214,7 @@ int main(int argc, char **argv, char **envp)
 exit(1);
 }
 
-#ifndef _WIN32
-/* Win32 doesn't support line-buffering and requires size >= 2 */
-setvbuf(stdout, NULL, _IOLBF, 0);
-#endif
+os_set_line_buffering();
 
 if (init_timer_alarm() < 0) {
 fprintf(stderr, "could not initialize alarm timer\n");
-- 
1.6.5.2




[Qemu-devel] [PATCH 03/17] Introduce os-win32.c and move polling functions from vl.c

2010-06-04 Thread Jes . Sorensen
From: Jes Sorensen 

This introduces os-win32.c. It is meant to carry win32 specific
functions thata are not relevant for all of QEMU as well as win32
versions of various pieces like signal handling etc.

Move win32 polling handler helper functions from vl.c to os-win32.c

Signed-off-by: Jes Sorensen 
---
 Makefile.objs |1 +
 os-win32.c|  111 +
 vl.c  |   80 -
 3 files changed, 112 insertions(+), 80 deletions(-)
 create mode 100644 os-win32.c

diff --git a/Makefile.objs b/Makefile.objs
index 9796dcb..58fdb03 100644
--- a/Makefile.objs
+++ b/Makefile.objs
@@ -144,6 +144,7 @@ hw-obj-$(CONFIG_ECC) += ecc.o
 hw-obj-$(CONFIG_NAND) += nand.o
 hw-obj-$(CONFIG_PFLASH_CFI01) += pflash_cfi01.o
 hw-obj-$(CONFIG_PFLASH_CFI02) += pflash_cfi02.o
+hw-obj-$(CONFIG_WIN32) += os-win32.o
 
 hw-obj-$(CONFIG_M48T59) += m48t59.o
 hw-obj-$(CONFIG_ESCC) += escc.o
diff --git a/os-win32.c b/os-win32.c
new file mode 100644
index 000..5a464cc
--- /dev/null
+++ b/os-win32.c
@@ -0,0 +1,111 @@
+/*
+ * os-win32.c
+ *
+ * Copyright (c) 2003-2008 Fabrice Bellard
+ * Copyright (c) 2010 Red Hat, Inc.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to 
deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
+ * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 
FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ * THE SOFTWARE.
+ */
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include "config-host.h"
+#include "sysemu.h"
+
+/***/
+/* Polling handling */
+
+typedef struct PollingEntry {
+PollingFunc *func;
+void *opaque;
+struct PollingEntry *next;
+} PollingEntry;
+
+static PollingEntry *first_polling_entry;
+
+int qemu_add_polling_cb(PollingFunc *func, void *opaque)
+{
+PollingEntry **ppe, *pe;
+pe = qemu_mallocz(sizeof(PollingEntry));
+pe->func = func;
+pe->opaque = opaque;
+for(ppe = &first_polling_entry; *ppe != NULL; ppe = &(*ppe)->next);
+*ppe = pe;
+return 0;
+}
+
+void qemu_del_polling_cb(PollingFunc *func, void *opaque)
+{
+PollingEntry **ppe, *pe;
+for(ppe = &first_polling_entry; *ppe != NULL; ppe = &(*ppe)->next) {
+pe = *ppe;
+if (pe->func == func && pe->opaque == opaque) {
+*ppe = pe->next;
+qemu_free(pe);
+break;
+}
+}
+}
+
+/***/
+/* Wait objects support */
+typedef struct WaitObjects {
+int num;
+HANDLE events[MAXIMUM_WAIT_OBJECTS + 1];
+WaitObjectFunc *func[MAXIMUM_WAIT_OBJECTS + 1];
+void *opaque[MAXIMUM_WAIT_OBJECTS + 1];
+} WaitObjects;
+
+static WaitObjects wait_objects = {0};
+
+int qemu_add_wait_object(HANDLE handle, WaitObjectFunc *func, void *opaque)
+{
+WaitObjects *w = &wait_objects;
+
+if (w->num >= MAXIMUM_WAIT_OBJECTS)
+return -1;
+w->events[w->num] = handle;
+w->func[w->num] = func;
+w->opaque[w->num] = opaque;
+w->num++;
+return 0;
+}
+
+void qemu_del_wait_object(HANDLE handle, WaitObjectFunc *func, void *opaque)
+{
+int i, found;
+WaitObjects *w = &wait_objects;
+
+found = 0;
+for (i = 0; i < w->num; i++) {
+if (w->events[i] == handle)
+found = 1;
+if (found) {
+w->events[i] = w->events[i + 1];
+w->func[i] = w->func[i + 1];
+w->opaque[i] = w->opaque[i + 1];
+}
+}
+if (found)
+w->num--;
+}
diff --git a/vl.c b/vl.c
index 7c4298a..afbb26c 100644
--- a/vl.c
+++ b/vl.c
@@ -1497,86 +1497,6 @@ int qemu_set_fd_handler(int fd,
 return qemu_set_fd_handler2(fd, NULL, fd_read, fd_write, opaque);
 }
 
-#ifdef _WIN32
-/***/
-/* Polling handling */
-
-typedef struct PollingEntry {
-PollingFunc *func;
-void *opaque;
-struct PollingEntry *next;
-} PollingEntry;
-
-static PollingEntry *first_polling_entry;
-
-int qemu_add_polling_cb(PollingFunc *func, void *opaque)
-{
-PollingEntry **pp

[Qemu-devel] [PATCH 09/17] Move find_datadir to OS specific files.

2010-06-04 Thread Jes . Sorensen
From: Jes Sorensen 

This moves the win32 and POSIX versions of find_datadir() to OS
specific files, and removes some #ifdef clutter from vl.c

Signed-off-by: Jes Sorensen 
---
 os-posix.c |   64 +++
 os-win32.c |   23 ++
 sysemu.h   |2 +
 vl.c   |   98 ++-
 4 files changed, 93 insertions(+), 94 deletions(-)

diff --git a/os-posix.c b/os-posix.c
index 01dbec2..621ad06 100644
--- a/os-posix.c
+++ b/os-posix.c
@@ -28,6 +28,7 @@
 #include 
 #include 
 #include 
+#include 
 
 /* Needed early for CONFIG_BSD etc. */
 #include "config-host.h"
@@ -66,3 +67,66 @@ void os_setup_signal_handling(void)
 act.sa_flags = SA_NOCLDSTOP;
 sigaction(SIGCHLD, &act, NULL);
 }
+
+/* Find a likely location for support files using the location of the binary.
+   For installed binaries this will be "$bindir/../share/qemu".  When
+   running from the build tree this will be "$bindir/../pc-bios".  */
+#define SHARE_SUFFIX "/share/qemu"
+#define BUILD_SUFFIX "/pc-bios"
+char *os_find_datadir(const char *argv0)
+{
+char *dir;
+char *p = NULL;
+char *res;
+char buf[PATH_MAX];
+size_t max_len;
+
+#if defined(__linux__)
+{
+int len;
+len = readlink("/proc/self/exe", buf, sizeof(buf) - 1);
+if (len > 0) {
+buf[len] = 0;
+p = buf;
+}
+}
+#elif defined(__FreeBSD__)
+{
+static int mib[4] = {CTL_KERN, KERN_PROC, KERN_PROC_PATHNAME, -1};
+size_t len = sizeof(buf) - 1;
+
+*buf = '\0';
+if (!sysctl(mib, sizeof(mib)/sizeof(*mib), buf, &len, NULL, 0) &&
+*buf) {
+buf[sizeof(buf) - 1] = '\0';
+p = buf;
+}
+}
+#endif
+/* If we don't have any way of figuring out the actual executable
+   location then try argv[0].  */
+if (!p) {
+p = realpath(argv0, buf);
+if (!p) {
+return NULL;
+}
+}
+dir = dirname(p);
+dir = dirname(dir);
+
+max_len = strlen(dir) +
+MAX(strlen(SHARE_SUFFIX), strlen(BUILD_SUFFIX)) + 1;
+res = qemu_mallocz(max_len);
+snprintf(res, max_len, "%s%s", dir, SHARE_SUFFIX);
+if (access(res, R_OK)) {
+snprintf(res, max_len, "%s%s", dir, BUILD_SUFFIX);
+if (access(res, R_OK)) {
+qemu_free(res);
+res = NULL;
+}
+}
+
+return res;
+}
+#undef SHARE_SUFFIX
+#undef BUILD_SUFFIX
diff --git a/os-win32.c b/os-win32.c
index a936f7a..1758538 100644
--- a/os-win32.c
+++ b/os-win32.c
@@ -181,3 +181,26 @@ void os_setup_early_signal_handling(void)
 }
 }
 }
+
+/* Look for support files in the same directory as the executable.  */
+char *os_find_datadir(const char *argv0)
+{
+char *p;
+char buf[MAX_PATH];
+DWORD len;
+
+len = GetModuleFileName(NULL, buf, sizeof(buf) - 1);
+if (len == 0) {
+return NULL;
+}
+
+buf[len] = 0;
+p = buf + len - 1;
+while (p != buf && *p != '\\')
+p--;
+*p = 0;
+if (access(buf, R_OK) == 0) {
+return qemu_strdup(buf);
+}
+return NULL;
+}
diff --git a/sysemu.h b/sysemu.h
index bb05cf4..72f3734 100644
--- a/sysemu.h
+++ b/sysemu.h
@@ -79,7 +79,9 @@ int qemu_loadvm_state(QEMUFile *f);
 /* SLIRP */
 void do_info_slirp(Monitor *mon);
 
+/* OS specific functions */
 void os_setup_early_signal_handling(void);
+char *os_find_datadir(const char *argv0);
 
 typedef enum DisplayType
 {
diff --git a/vl.c b/vl.c
index fc5e8d8..7f22733 100644
--- a/vl.c
+++ b/vl.c
@@ -1986,95 +1986,6 @@ static int balloon_parse(const char *arg)
 return -1;
 }
 
-#ifdef _WIN32
-/* Look for support files in the same directory as the executable.  */
-static char *find_datadir(const char *argv0)
-{
-char *p;
-char buf[MAX_PATH];
-DWORD len;
-
-len = GetModuleFileName(NULL, buf, sizeof(buf) - 1);
-if (len == 0) {
-return NULL;
-}
-
-buf[len] = 0;
-p = buf + len - 1;
-while (p != buf && *p != '\\')
-p--;
-*p = 0;
-if (access(buf, R_OK) == 0) {
-return qemu_strdup(buf);
-}
-return NULL;
-}
-#else /* !_WIN32 */
-
-/* Find a likely location for support files using the location of the binary.
-   For installed binaries this will be "$bindir/../share/qemu".  When
-   running from the build tree this will be "$bindir/../pc-bios".  */
-#define SHARE_SUFFIX "/share/qemu"
-#define BUILD_SUFFIX "/pc-bios"
-static char *find_datadir(const char *argv0)
-{
-char *dir;
-char *p = NULL;
-char *res;
-char buf[PATH_MAX];
-size_t max_len;
-
-#if defined(__linux__)
-{
-int len;
-len = readlink("/proc/self/exe", buf, sizeof(buf) - 1);
-if (len > 0) {
-buf[len] = 0;
-p = buf;
-}
-}
-#elif defined(__FreeBSD__)
-{
-static int mib[4] = {CTL_KERN, KERN_PROC, KERN_PROC_PATHNAME, -1};
-size_t len = sizeof(buf)

[Qemu-devel] [PATCH 13/17] Move chroot handling to OS specific files.

2010-06-04 Thread Jes . Sorensen
From: Jes Sorensen 

Move chroot handling to OS specific files.

Signed-off-by: Jes Sorensen 
---
 os-posix.c  |   19 +++
 qemu-os-posix.h |1 +
 qemu-os-win32.h |1 +
 vl.c|   18 +-
 4 files changed, 22 insertions(+), 17 deletions(-)

diff --git a/os-posix.c b/os-posix.c
index 8b686a4..6417d16 100644
--- a/os-posix.c
+++ b/os-posix.c
@@ -38,6 +38,7 @@
 #include "qemu-options.h"
 
 static struct passwd *user_pwd;
+static const char *chroot_dir;
 
 void os_setup_early_signal_handling(void)
 {
@@ -156,6 +157,9 @@ void os_parse_cmd_args(int index, const char *optarg)
 exit(1);
 }
 break;
+case QEMU_OPTION_chroot:
+chroot_dir = optarg;
+break;
 }
 return;
 }
@@ -177,3 +181,18 @@ void os_change_process_uid(void)
 }
 }
 }
+
+void os_change_root(void)
+{
+if (chroot_dir) {
+if (chroot(chroot_dir) < 0) {
+fprintf(stderr, "chroot failed\n");
+exit(1);
+}
+if (chdir("/")) {
+perror("not able to chdir to /");
+exit(1);
+}
+}
+
+}
diff --git a/qemu-os-posix.h b/qemu-os-posix.h
index 6d8cf79..91c7b68 100644
--- a/qemu-os-posix.h
+++ b/qemu-os-posix.h
@@ -32,5 +32,6 @@ static inline void os_host_main_loop_wait(int *timeout)
 
 void os_setup_signal_handling(void);
 void os_change_process_uid(void);
+void os_change_root(void);
 
 #endif
diff --git a/qemu-os-win32.h b/qemu-os-win32.h
index 70fdca5..e2a97d2 100644
--- a/qemu-os-win32.h
+++ b/qemu-os-win32.h
@@ -44,5 +44,6 @@ void os_host_main_loop_wait(int *timeout);
 
 static inline void os_setup_signal_handling(void) {}
 static inline void os_change_process_uid(void) {}
+static inline void os_change_root(void) {}
 
 #endif
diff --git a/vl.c b/vl.c
index 5fa4c79..fc0e23d 100644
--- a/vl.c
+++ b/vl.c
@@ -2309,7 +2309,6 @@ int main(int argc, char **argv, char **envp)
 const char *incoming = NULL;
 #ifndef _WIN32
 int fd = 0;
-const char *chroot_dir = NULL;
 #endif
 int show_vnc_port = 0;
 int defconfig = 1;
@@ -3053,11 +3052,6 @@ int main(int argc, char **argv, char **envp)
 default_cdrom = 0;
 default_sdcard = 0;
 break;
-#ifndef _WIN32
-case QEMU_OPTION_chroot:
-chroot_dir = optarg;
-break;
-#endif
 case QEMU_OPTION_xen_domid:
 if (!(xen_available())) {
 printf("Option %s not supported for this target\n", 
popt->name);
@@ -3546,17 +3540,7 @@ int main(int argc, char **argv, char **envp)
exit(1);
 }
 
-if (chroot_dir) {
-if (chroot(chroot_dir) < 0) {
-fprintf(stderr, "chroot failed\n");
-exit(1);
-}
-if (chdir("/")) {
-perror("not able to chdir to /");
-exit(1);
-}
-}
-
+os_change_root();
 os_change_process_uid();
 
 if (daemonize) {
-- 
1.6.5.2




[Qemu-devel] [PATCH 07/17] Rename os_setup_signal_handling() to os_setup_early_signal_handling()

2010-06-04 Thread Jes . Sorensen
From: Jes Sorensen 

Rename os_setup_signal_handling() to os_setup_early_signal_handling()

Signed-off-by: Jes Sorensen 
---
 os-posix.c |2 +-
 os-win32.c |2 +-
 sysemu.h   |2 +-
 vl.c   |2 +-
 4 files changed, 4 insertions(+), 4 deletions(-)

diff --git a/os-posix.c b/os-posix.c
index 914a4d1..948f662 100644
--- a/os-posix.c
+++ b/os-posix.c
@@ -31,7 +31,7 @@
 #include "config-host.h"
 #include "sysemu.h"
 
-void os_setup_signal_handling(void)
+void os_setup_early_signal_handling(void)
 {
 struct sigaction act;
 sigfillset(&act.sa_mask);
diff --git a/os-win32.c b/os-win32.c
index dfa90bc..a936f7a 100644
--- a/os-win32.c
+++ b/os-win32.c
@@ -159,7 +159,7 @@ static BOOL WINAPI qemu_ctrl_handler(DWORD type)
 return TRUE;
 }
 
-void os_setup_signal_handling(void)
+void os_setup_early_signal_handling(void)
 {
 /* Note: cpu_interrupt() is currently not SMP safe, so we force
QEMU to run on a single CPU */
diff --git a/sysemu.h b/sysemu.h
index e3643ad..bb05cf4 100644
--- a/sysemu.h
+++ b/sysemu.h
@@ -79,7 +79,7 @@ int qemu_loadvm_state(QEMUFile *f);
 /* SLIRP */
 void do_info_slirp(Monitor *mon);
 
-void os_setup_signal_handling(void);
+void os_setup_early_signal_handling(void);
 
 typedef enum DisplayType
 {
diff --git a/vl.c b/vl.c
index f43456a..372f931 100644
--- a/vl.c
+++ b/vl.c
@@ -2451,7 +2451,7 @@ int main(int argc, char **argv, char **envp)
 qemu_cache_utils_init(envp);
 
 QLIST_INIT (&vm_change_state_head);
-os_setup_signal_handling();
+os_setup_early_signal_handling();
 
 module_call_init(MODULE_INIT_MACHINE);
 machine = find_default_machine();
-- 
1.6.5.2




[Qemu-devel] [PATCH 12/17] Move runas handling from vl.c to OS specific files.

2010-06-04 Thread Jes . Sorensen
From: Jes Sorensen 

Move code to handle runas, ie. change of user id of QEMU process
to OS specific files and provide dummy stub for Win32.

Signed-off-by: Jes Sorensen 
---
 os-posix.c  |   28 
 qemu-os-posix.h |1 +
 qemu-os-win32.h |1 +
 vl.c|   29 +
 4 files changed, 31 insertions(+), 28 deletions(-)

diff --git a/os-posix.c b/os-posix.c
index 0deddf3..8b686a4 100644
--- a/os-posix.c
+++ b/os-posix.c
@@ -28,6 +28,7 @@
 #include 
 #include 
 #include 
+#include 
 #include 
 
 /* Needed early for CONFIG_BSD etc. */
@@ -36,6 +37,8 @@
 #include "net/slirp.h"
 #include "qemu-options.h"
 
+static struct passwd *user_pwd;
+
 void os_setup_early_signal_handling(void)
 {
 struct sigaction act;
@@ -146,6 +149,31 @@ void os_parse_cmd_args(int index, const char *optarg)
 exit(1);
 break;
 #endif
+case QEMU_OPTION_runas:
+user_pwd = getpwnam(optarg);
+if (!user_pwd) {
+fprintf(stderr, "User \"%s\" doesn't exist\n", optarg);
+exit(1);
+}
+break;
 }
 return;
 }
+
+void os_change_process_uid(void)
+{
+if (user_pwd) {
+if (setgid(user_pwd->pw_gid) < 0) {
+fprintf(stderr, "Failed to setgid(%d)\n", user_pwd->pw_gid);
+exit(1);
+}
+if (setuid(user_pwd->pw_uid) < 0) {
+fprintf(stderr, "Failed to setuid(%d)\n", user_pwd->pw_uid);
+exit(1);
+}
+if (setuid(0) != -1) {
+fprintf(stderr, "Dropping privileges failed\n");
+exit(1);
+}
+}
+}
diff --git a/qemu-os-posix.h b/qemu-os-posix.h
index ff5adb1..6d8cf79 100644
--- a/qemu-os-posix.h
+++ b/qemu-os-posix.h
@@ -31,5 +31,6 @@ static inline void os_host_main_loop_wait(int *timeout)
 }
 
 void os_setup_signal_handling(void);
+void os_change_process_uid(void);
 
 #endif
diff --git a/qemu-os-win32.h b/qemu-os-win32.h
index e7e2ee3..70fdca5 100644
--- a/qemu-os-win32.h
+++ b/qemu-os-win32.h
@@ -43,5 +43,6 @@ void qemu_del_wait_object(HANDLE handle, WaitObjectFunc 
*func, void *opaque);
 void os_host_main_loop_wait(int *timeout);
 
 static inline void os_setup_signal_handling(void) {}
+static inline void os_change_process_uid(void) {}
 
 #endif
diff --git a/vl.c b/vl.c
index 7c48024..5fa4c79 100644
--- a/vl.c
+++ b/vl.c
@@ -34,7 +34,6 @@
 
 #ifndef _WIN32
 #include 
-#include 
 #include 
 #include 
 #include 
@@ -2310,9 +2309,7 @@ int main(int argc, char **argv, char **envp)
 const char *incoming = NULL;
 #ifndef _WIN32
 int fd = 0;
-struct passwd *pwd = NULL;
 const char *chroot_dir = NULL;
-const char *run_as = NULL;
 #endif
 int show_vnc_port = 0;
 int defconfig = 1;
@@ -3060,9 +3057,6 @@ int main(int argc, char **argv, char **envp)
 case QEMU_OPTION_chroot:
 chroot_dir = optarg;
 break;
-case QEMU_OPTION_runas:
-run_as = optarg;
-break;
 #endif
 case QEMU_OPTION_xen_domid:
 if (!(xen_available())) {
@@ -3552,14 +3546,6 @@ int main(int argc, char **argv, char **envp)
exit(1);
 }
 
-if (run_as) {
-pwd = getpwnam(run_as);
-if (!pwd) {
-fprintf(stderr, "User \"%s\" doesn't exist\n", run_as);
-exit(1);
-}
-}
-
 if (chroot_dir) {
 if (chroot(chroot_dir) < 0) {
 fprintf(stderr, "chroot failed\n");
@@ -3571,20 +3557,7 @@ int main(int argc, char **argv, char **envp)
 }
 }
 
-if (run_as) {
-if (setgid(pwd->pw_gid) < 0) {
-fprintf(stderr, "Failed to setgid(%d)\n", pwd->pw_gid);
-exit(1);
-}
-if (setuid(pwd->pw_uid) < 0) {
-fprintf(stderr, "Failed to setuid(%d)\n", pwd->pw_uid);
-exit(1);
-}
-if (setuid(0) != -1) {
-fprintf(stderr, "Dropping privileges failed\n");
-exit(1);
-}
-}
+os_change_process_uid();
 
 if (daemonize) {
 dup2(fd, 0);
-- 
1.6.5.2




[Qemu-devel] [PATCH 10/17] Rename qemu-options.h to qemu-options.def

2010-06-04 Thread Jes . Sorensen
From: Jes Sorensen 

Rename qemu-options.h to qemu-options.def as it is not a header file
for general use and this leaves space for a proper qemu-options.h

Signed-off-by: Jes Sorensen 
---
 Makefile.objs |4 ++--
 vl.c  |6 +++---
 2 files changed, 5 insertions(+), 5 deletions(-)

diff --git a/Makefile.objs b/Makefile.objs
index 2d94677..124afe7 100644
--- a/Makefile.objs
+++ b/Makefile.objs
@@ -258,8 +258,8 @@ vl.o: QEMU_CFLAGS+=$(GPROF_CFLAGS)
 
 vl.o: QEMU_CFLAGS+=$(SDL_CFLAGS)
 
-vl.o: qemu-options.h
+vl.o: qemu-options.def
 
-qemu-options.h: $(SRC_PATH)/qemu-options.hx
+qemu-options.def: $(SRC_PATH)/qemu-options.hx
$(call quiet-command,sh $(SRC_PATH)/hxtool -h < $< > $@,"  GEN   
$(TARGET_DIR)$@")
 
diff --git a/vl.c b/vl.c
index 7f22733..8cd0f8f 100644
--- a/vl.c
+++ b/vl.c
@@ -1875,7 +1875,7 @@ static void help(int exitcode)
 #define DEF(option, opt_arg, opt_enum, opt_help, arch_mask) \
 opt_help
 #define DEFHEADING(text) stringify(text) "\n"
-#include "qemu-options.h"
+#include "qemu-options.def"
 #undef DEF
 #undef DEFHEADING
 #undef GEN_DOCS
@@ -1903,7 +1903,7 @@ enum {
 #define DEF(option, opt_arg, opt_enum, opt_help, arch_mask) \
 opt_enum,
 #define DEFHEADING(text)
-#include "qemu-options.h"
+#include "qemu-options.def"
 #undef DEF
 #undef DEFHEADING
 #undef GEN_DOCS
@@ -1921,7 +1921,7 @@ static const QEMUOption qemu_options[] = {
 #define DEF(option, opt_arg, opt_enum, opt_help, arch_mask) \
 { option, opt_arg, opt_enum, arch_mask },
 #define DEFHEADING(text)
-#include "qemu-options.h"
+#include "qemu-options.def"
 #undef DEF
 #undef DEFHEADING
 #undef GEN_DOCS
-- 
1.6.5.2




[Qemu-devel] [PATCH v3 00/17] clean up vl.c code

2010-06-04 Thread Jes . Sorensen
From: Jes Sorensen 

Hi,

Ok third time lucky ... I hope! This fixes the missing git add on
qemu-options.h as building for win32 using mingw (thanks Paolo!).

The patches try to clean up the vl.c code by separating out OS
specific code into OS specific files. Basically it is focused on
moving things into os-posix.c for most UNIX/Linux systems, and
os-win32.c for win32 specific bits.

I have tried to be as careful as I can to not break non Linux support,
but so far the patch has only been tested on Linux.

Oh and this time without 'I am not very clever' editor backup files!

Thanks,
Jes

Jes Sorensen (17):
  vl.c: Remove double include of netinet/in.h for Solaris
  Create qemu-os-win32.h and move WIN32 specific declarations there
  Introduce os-win32.c and move polling functions from vl.c
  vl.c: Move host_main_loop_wait() to OS specific files.
  Introduce os-posix.c and create os_setup_signal_handling()
  Move win32 early signal handling setup to os_setup_signal_handling()
  Rename os_setup_signal_handling() to os_setup_early_signal_handling()
  Move main signal handler setup to os specificfiles.
  Move find_datadir to OS specific files.
  Rename qemu-options.h to qemu-options.def
  Introduce OS specific cmdline argument handling and move SMB arg to
os-posix.c
  Move runas handling from vl.c to OS specific files.
  Move chroot handling to OS specific files.
  Move daemonize handling to OS specific files
  Make os_change_process_uid and os_change_root os-posix.c local
  Move line-buffering setup to OS specific files.
  Move set_proc_name() to OS specific files.

 Makefile.objs   |8 +-
 os-posix.c  |  329 
 os-win32.c  |  221 
 qemu-options.h  |   41 +
 qemu-os-posix.h |   39 +
 qemu-os-win32.h |   52 ++
 sysemu.h|   27 ++--
 vl.c|  498 ++-
 8 files changed, 716 insertions(+), 499 deletions(-)
 create mode 100644 os-posix.c
 create mode 100644 os-win32.c
 create mode 100644 qemu-options.h
 create mode 100644 qemu-os-posix.h
 create mode 100644 qemu-os-win32.h




[Qemu-devel] dyngen tool

2010-06-04 Thread maheen butt
i want to know how dyngen tool is incorporated in QEMU source code?? does mips 
folder in TCG directory do same work for MIPS 64?? 



  

[Qemu-devel] Re: RFC: blockdev_add & friends, brief rationale, QMP docs

2010-06-04 Thread Markus Armbruster
Kevin Wolf  writes:

> Am 04.06.2010 16:16, schrieb Markus Armbruster:
>> Discussion with Christoph and Kevin uncovered yet another issue:
>> protocols.  I find it pretty confusing, but let me try to describe it
>> anyway; Christoph and Kevin, please correct my errors.
>> 
>> A host block device has a format.  A format has a name.
>> 
>> Below the format, it has a stack of protocols.  A protocol has a name
>> (with one exception), and may have protocol-specific arguments.
>> 
>> The most basic (and most commonly used) protocol is for accessing a
>> file.  Its argument is a file name.  It doesn't have a name.  Which
>> makes for ugly prose, so I'll call it "file".
>
> It does have a name, and surprisingly it's called "file" indeed (defined
> at block/raw-posix.c:744 for Linux).
>
>> Stacking protocols is somewhat exotic.  Think of stacking blkdebug on
>> top of another protocol, say nbd.
>
> Considering that file is a protocol as well as nbd, it's any blkdebug
> use that uses protocol stacking and therefore not that exotic - even
> though not the most common case, of course.
>
>> Our abstraction for formats is struct BlockDriver.
>> 
>> Our abstraction for protocols is also struct BlockDriver.  Except for
>> the special protocol "file", but that's detail.
>
> See above, file isn't really special.

I got confused by this code in bdrv_open_common():

/* Open the image, either directly or using a protocol */
if (drv->bdrv_file_open) {
ret = drv->bdrv_file_open(bs, filename, open_flags);
} else {
ret = bdrv_file_open(&bs->file, filename, open_flags);
if (ret >= 0) {
ret = drv->bdrv_open(bs, open_flags);
}
}

When called by drive_init() via bdrv_open(), drv is the BlockDriver
named by format=F.  If drv->bdrv_file_open, is drv a format or a
protocol?  It's true for F in blkdebug, cow, http, https, ftp, ftps,
tftp, nbd, file, host_device, host_floppy, host_cdrom, vvfat, so it's a
protocol (except for cow, but Christoph tells me he's about to get that
one off the list).  But what's the format then?

The conditional's else seems clear: bdrv_file_open() finds the protocol
in filename (probes the file if missing), and then opens with that
protocol.

>> Examples:
>> 
>> -drive file=foo.qcow2,format=qcow2
>> 
>>  Format "qcow2", protocol "file" with argument filename "foo.img"
>
> Actually the protocol is guessed here. For this, not all protocols are
> considered, it's only between file/host_device/host_cdrom/host_floppy
> (these are the protocols implementing bdrv_probe_device, and file as the
> default if no other protocol feels responsible)

Then we need a way to ask for this guessing, say (pseudo-)protocol
"auto".

>> -drive file=nbd:unix:/tmp/my_socket,format=raw
>> 
>>  Format "raw", protocol "nbd" with arguments domain "unix", filename
>>  "/tmp/my_socket"
>> 
>> -drive blkdebug:/tmp/blkdebug.cfg:fat:floppy:rw:/tmp/dir
>> 
>>  Format not specified (system guesses one), protocol "blkdebug" with
>>  argument filename "/tmp/blkdebug.cfg" stacked onto protocol "fat" with
>>  arguments floppy true, dirname "/tmp/dir"
>
> These look right to me.
>
>> 
>> You see that -drive has a separate option for format, but has protocols
>> encoded in option file, in their own mini-language.  Doesn't work for
>> arbitrary filenames.  Besides, mini-languages to encode options in
>> strings are quite inappropriate for QMP.
>> 
>> So we need something cleaner for QMP.  Here's a sketch.  Instead of
>> 
>> - "file": the disk image file to use (json-string, optional)
>> - "format": disk format (json-string, optional)
>> - Possible values: "raw", "qcow2", ...
>> 
>> have
>> 
>> - "format": disk format (json-string, optional)
>> - Possible values: "raw", "qcow2", ...
>> - "protocol": json-array of json-object
>>   Each element object has a member "name"
>> - Possible values: "file", "nbd", ...
>>   Additional members depend on the value of "name".
>>   For "name" = "file":
>> - "file": file name (json-string)
>>   For "name" = "nbd":
>> - "domain": address family (json-string, optional)
>> - Possible values: "inet" (default), "unix"
>> - "file": file name (json-string), only with "domain" = "unix"
>> - "host": host name (json-string), only with "domain" = "inet"
>> - "port": port (json-int), only with "domain" = "inet"
>>   ...
>> 
>> You get the idea.
>> 
>> Comments?
>
> Makes sense.
>
> So blkdebug would define a field "protocol" (json-object) that it uses
> to initialize the underlying protocol and we would get the stacking this
> way?

No, my proposal represents the stack of protocols as json-array, not by
nesting them.  I should have given examples.  Reusing my three examples
from above:

* Format "qcow2", protocol "auto" with argument filename "foo.img"

"format": "qcow2",
"protocol": [{ "name": "auto", "file": "foo.qcow2" }],

* Format "raw", protocol "nbd" with arguments domain "unix", filename
  "/tmp/my_socket"

"forma

Re: [Qemu-devel] [PATCH 00/10] target-mips: add microMIPS ASE support, v2

2010-06-04 Thread Nathan Froyd
On Mon, May 24, 2010 at 09:19:34AM -0700, Nathan Froyd wrote:
> This patch series adds support for the microMIPS ASE.  microMIPS is a
> new ASE similar to MIPS16, but re-encodes the entire instruction set
> into 16-bit and 32-bit instructions--in contrast to MIPS16, which
> re-encodes only integer instructions.  The mechanisms for going in and
> out of microMIPS mode are identical to those for MIPS16; a given chip
> cannot support both ASEs simultaneously.

Ping.

-Nathan



[Qemu-devel] [PATCH 01/17] vl.c: Remove double include of netinet/in.h for Solaris

2010-06-04 Thread Jes . Sorensen
From: Jes Sorensen 

vl.c: netinet/in.h is already included once above for the

Signed-off-by: Jes Sorensen 
---
 vl.c |1 -
 1 files changed, 0 insertions(+), 1 deletions(-)

diff --git a/vl.c b/vl.c
index 417554f..7c4298a 100644
--- a/vl.c
+++ b/vl.c
@@ -70,7 +70,6 @@
 #include 
 #include 
 #include 
-#include 
 #include 
 #include 
 #include  // must come after ip.h
-- 
1.6.5.2




[Qemu-devel] Re: [PATCH 1/3] Add virtioblk_id tool to extract drive serial numbers

2010-06-04 Thread john cooper
Ryan Harper wrote:
> * Kay Sievers  [2010-06-03 15:06]:
>> On Thu, Jun 3, 2010 at 22:01, Ryan Harper  wrote:
>>> * Kay Sievers  [2010-06-03 14:53]:
 On Thu, Jun 3, 2010 at 21:07, Ryan Harper  wrote:
> Use the 'VBID' virtio-blk ioctl to extract drive serial numbers
> to be used for building disk/by-id symlinks.  After extracting
> the serial number of the device it prints out the minimum info
> needed in a similar format to `scsi_id --export` so that the
> persistent-storage rules can process the serial information.
>
> This program depends on the virtio-blk serial device patches posted
> here[1] being applied to qemu and linux-kernel.
>
> Here is what the output looks like:
>
> % ./virtioblk_id /dev/vdb
> ID_VIRTIO=1
> ID_TYPE=disk
> ID_VIRTIO_SERIAL=QM1
 Yikes! An ioctl to copy a plain string, and an entire binary to call
 that ioctl and print it. If we don't have enough problems we make new
 ones? :)

[Jumping in the thread here as I hadn't seen the comments
until now.  This issue has been discussed ad nauseam in the
context of qemu so here is a summary]

Packaging this up this data within a mock ATA_IDENTIFY was
proposed.  However that is a large bag of largely archaic
bits most of which are dummied up normally, and would be even
more so in the case here of virtio.  Putting a proposed
identify struct mock-up in qemu made the most sense in this
scenario as that's where the disk geometry information exists,
unfortunately doing so didn't fly with the maintainer.  Locating
this mock-up in the virtio driver makes less sense as the
geometry data for mock-up would need to be packaged up in yet
another structure and passed to the driver for formatting onto
the identify data.  No one even seriously considered doing this
as it combines the worst of both worlds.

 What's the reason to drop the ATA identify, that would work out-of-the
 box without any of this stuff. It could also support WWN, which is
 what people are looking for these days.

That is the singular, very strong argument for ATA_IDENTIFY
and one which I'd made several times however it isn't the only
consideration in this multi-way trade off.

>>> http://www.mail-archive.com/qemu-devel@nongnu.org/msg24321.html
>>>
>>> 1. Virtio-blk isn't an ATA device
>>> 2. The ATA identify page is too large to fit into the virtio config
>>> space

Passing this data in PCI config made sense in the original
version of this patch when I was just shuffling 20 bytes of
id to the driver.  But when the ATA_IDENTIFY argument arose
it extended the size of the passed data to 512 bytes which caused
breakage of PCI config space due to the size now consumed to
quietly exceed the PCI specification.  Moving the identify
scheme to pass data by virtio request was proposed but by this
time the maintainer was strongly objecting to mock-up of this data
within qemu.

>>> I'm not finding the older threads where this was discussed in detail.
>>> I'll keep looking if the above isn't a sufficient explaination.
>> Well, if ATA doesn't fit, then put that string in sysfs like mmc block
>> devices are doing it. It looks really awkward to require a new binary
>> and a new ioctl to get a single string out of something that was just
>> invented.

There are two issues:

- Getting the serial/id string exported from qemu to the driver.
  This is the much less contentious portion unless we're still
  bent on using the identify scheme which will surely torpedo
  the effort once again.  Assuming we're satisfied with qemu
  exporting the serial/id string alone we should be quite close
  here.

- Presentation of the serial/id to the application by the
  virtio driver.  ATA_IDENTIFY would be nice if the above restrictions
  didn't exist, but they do.  So let's just get the job done
  once and for all.  No one wants to invent yet another ioctl
  interface but it is the best compromise available as the code
  in both the driver and application is trivial.  The other
  alternatives at their respective extremes (/sys: new but pretty
  interface, over powered for the job, more cruft in the driver;
  ATA_IDENTIFY: existing interface, ugliest possible code, even
  more cruft in the driver) have been proposed and abandoned for
  reasons cited above.
 
> John,
> 
> you mentioned that you had a sys interface in-mind earlier.  I'm not
> sure how to proceed given the virtio-blk kernel side patches are
> already upstream[1][2].  Are we looking to revert and switch?

No, we can use the interface as-is, however we have an opportunity
to make it more usage friendly.

> 1.  
> http://repo.or.cz/w/linux-2.6.git/commitdiff/234f2725a5d03f78539f1d36cb32f2c4f9b1822c

My slight modification to the above commit makes it possible
for the application to determine the data size the driver intends
to copy out, and allows the user to indicate the destination data
size for the copy operation.  Otherwise the caller needs to have
the size assumptio

[Qemu-devel] Re: [PATCH 2/5] vnc: JPEG should be disabled if the client don't set tight quality

2010-06-04 Thread Anthony Liguori

On 06/04/2010 08:16 AM, Alexander Graf wrote:

On 04.06.2010, at 15:18, Corentin Chary wrote:

   

Disable JPEG compression by default and only enable it if the
VNC client has sent the requested quality.

Signed-off-by: Corentin Chary
---
vnc.c |2 +-
1 files changed, 1 insertions(+), 1 deletions(-)

diff --git a/vnc.c b/vnc.c
index ed0e096..9cf38d1 100644
--- a/vnc.c
+++ b/vnc.c
@@ -1644,7 +1644,7 @@ static void set_encodings(VncState *vs, int32_t 
*encodings, size_t n_encodings)
 vs->features = 0;
 vs->vnc_encoding = 0;
 vs->tight_compression = 9;
-vs->tight_quality = 9;
+vs->tight_quality = -1; /* Lossless by default */
 

So what's the threshold? When do you start to be lossy?
   


When the client explicitly requests it.

Regards,

Anthony Liguori


Alex

   





[Qemu-devel] [PATCH 03/17] Introduce os-win32.c and move polling functions from vl.c

2010-06-04 Thread Jes . Sorensen
From: Jes Sorensen 

This introduces os-win32.c. It is meant to carry win32 specific
functions thata are not relevant for all of QEMU as well as win32
versions of various pieces like signal handling etc.

Move win32 polling handler helper functions from vl.c to os-win32.c

Signed-off-by: Jes Sorensen 
---
 Makefile.objs |1 +
 os-win32.c|  111 +
 vl.c  |   80 -
 3 files changed, 112 insertions(+), 80 deletions(-)
 create mode 100644 os-win32.c

diff --git a/Makefile.objs b/Makefile.objs
index 9796dcb..58fdb03 100644
--- a/Makefile.objs
+++ b/Makefile.objs
@@ -144,6 +144,7 @@ hw-obj-$(CONFIG_ECC) += ecc.o
 hw-obj-$(CONFIG_NAND) += nand.o
 hw-obj-$(CONFIG_PFLASH_CFI01) += pflash_cfi01.o
 hw-obj-$(CONFIG_PFLASH_CFI02) += pflash_cfi02.o
+hw-obj-$(CONFIG_WIN32) += os-win32.o
 
 hw-obj-$(CONFIG_M48T59) += m48t59.o
 hw-obj-$(CONFIG_ESCC) += escc.o
diff --git a/os-win32.c b/os-win32.c
new file mode 100644
index 000..5a464cc
--- /dev/null
+++ b/os-win32.c
@@ -0,0 +1,111 @@
+/*
+ * os-win32.c
+ *
+ * Copyright (c) 2003-2008 Fabrice Bellard
+ * Copyright (c) 2010 Red Hat, Inc.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to 
deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
+ * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 
FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ * THE SOFTWARE.
+ */
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include "config-host.h"
+#include "sysemu.h"
+
+/***/
+/* Polling handling */
+
+typedef struct PollingEntry {
+PollingFunc *func;
+void *opaque;
+struct PollingEntry *next;
+} PollingEntry;
+
+static PollingEntry *first_polling_entry;
+
+int qemu_add_polling_cb(PollingFunc *func, void *opaque)
+{
+PollingEntry **ppe, *pe;
+pe = qemu_mallocz(sizeof(PollingEntry));
+pe->func = func;
+pe->opaque = opaque;
+for(ppe = &first_polling_entry; *ppe != NULL; ppe = &(*ppe)->next);
+*ppe = pe;
+return 0;
+}
+
+void qemu_del_polling_cb(PollingFunc *func, void *opaque)
+{
+PollingEntry **ppe, *pe;
+for(ppe = &first_polling_entry; *ppe != NULL; ppe = &(*ppe)->next) {
+pe = *ppe;
+if (pe->func == func && pe->opaque == opaque) {
+*ppe = pe->next;
+qemu_free(pe);
+break;
+}
+}
+}
+
+/***/
+/* Wait objects support */
+typedef struct WaitObjects {
+int num;
+HANDLE events[MAXIMUM_WAIT_OBJECTS + 1];
+WaitObjectFunc *func[MAXIMUM_WAIT_OBJECTS + 1];
+void *opaque[MAXIMUM_WAIT_OBJECTS + 1];
+} WaitObjects;
+
+static WaitObjects wait_objects = {0};
+
+int qemu_add_wait_object(HANDLE handle, WaitObjectFunc *func, void *opaque)
+{
+WaitObjects *w = &wait_objects;
+
+if (w->num >= MAXIMUM_WAIT_OBJECTS)
+return -1;
+w->events[w->num] = handle;
+w->func[w->num] = func;
+w->opaque[w->num] = opaque;
+w->num++;
+return 0;
+}
+
+void qemu_del_wait_object(HANDLE handle, WaitObjectFunc *func, void *opaque)
+{
+int i, found;
+WaitObjects *w = &wait_objects;
+
+found = 0;
+for (i = 0; i < w->num; i++) {
+if (w->events[i] == handle)
+found = 1;
+if (found) {
+w->events[i] = w->events[i + 1];
+w->func[i] = w->func[i + 1];
+w->opaque[i] = w->opaque[i + 1];
+}
+}
+if (found)
+w->num--;
+}
diff --git a/vl.c b/vl.c
index 7c4298a..afbb26c 100644
--- a/vl.c
+++ b/vl.c
@@ -1497,86 +1497,6 @@ int qemu_set_fd_handler(int fd,
 return qemu_set_fd_handler2(fd, NULL, fd_read, fd_write, opaque);
 }
 
-#ifdef _WIN32
-/***/
-/* Polling handling */
-
-typedef struct PollingEntry {
-PollingFunc *func;
-void *opaque;
-struct PollingEntry *next;
-} PollingEntry;
-
-static PollingEntry *first_polling_entry;
-
-int qemu_add_polling_cb(PollingFunc *func, void *opaque)
-{
-PollingEntry **pp

[Qemu-devel] [PATCH] Fix and simplify gui timer logic.

2010-06-04 Thread Gerd Hoffmann
Kill nographic timer.  Have a global gui_timer instead.  Have the gui
timer enabled unconditionally.  We need a timer running anyway for mmio
flush, so the whole have-gui-timer-only-when-needed logic is pretty
pointless.  It also simplifies displaylisteners coming and going at
runtime, we don't need to care about the timer then as it runs anyway.

Don't allocate the timer twice in case we have two display listeners.

Signed-off-by: Gerd Hoffmann 
---
 console.h |1 -
 vl.c  |   37 +++--
 2 files changed, 11 insertions(+), 27 deletions(-)

diff --git a/console.h b/console.h
index 264a396..cdf8dee 100644
--- a/console.h
+++ b/console.h
@@ -173,7 +173,6 @@ struct DisplayAllocator {
 struct DisplayState {
 struct DisplaySurface *surface;
 void *opaque;
-struct QEMUTimer *gui_timer;
 
 struct DisplayAllocator* allocator;
 QLIST_HEAD(, DisplayChangeListener) listeners;
diff --git a/vl.c b/vl.c
index f66f420..670705c 100644
--- a/vl.c
+++ b/vl.c
@@ -236,7 +236,7 @@ int nb_numa_nodes;
 uint64_t node_mem[MAX_NODES];
 uint64_t node_cpumask[MAX_NODES];
 
-static QEMUTimer *nographic_timer;
+static QEMUTimer *gui_timer;
 
 uint8_t qemu_uuid[16];
 
@@ -1633,22 +1633,17 @@ static void gui_update(void *opaque)
 DisplayChangeListener *dcl;
 
 qemu_flush_coalesced_mmio_buffer();
-dpy_refresh(ds);
 
-QLIST_FOREACH(dcl, &ds->listeners, next) {
-if (dcl->gui_timer_interval &&
-dcl->gui_timer_interval < interval)
-interval = dcl->gui_timer_interval;
+if (ds != NULL && !QLIST_EMPTY(&ds->listeners)) {
+dpy_refresh(ds);
+QLIST_FOREACH(dcl, &ds->listeners, next) {
+if (dcl->gui_timer_interval &&
+dcl->gui_timer_interval < interval)
+interval = dcl->gui_timer_interval;
+}
 }
-qemu_mod_timer(ds->gui_timer, interval + qemu_get_clock(rt_clock));
-}
-
-static void nographic_update(void *opaque)
-{
-uint64_t interval = GUI_REFRESH_INTERVAL;
 
-qemu_flush_coalesced_mmio_buffer();
-qemu_mod_timer(nographic_timer, interval + qemu_get_clock(rt_clock));
+qemu_mod_timer(gui_timer, interval + qemu_get_clock(rt_clock));
 }
 
 struct vm_change_state_entry {
@@ -2577,7 +2572,6 @@ int main(int argc, char **argv, char **envp)
 const char *kernel_filename, *kernel_cmdline;
 char boot_devices[33] = "cad"; /* default to HD->floppy->CD-ROM */
 DisplayState *ds;
-DisplayChangeListener *dcl;
 int cyls, heads, secs, translation;
 QemuOpts *hda_opts = NULL, *opts;
 int optind;
@@ -3817,17 +3811,8 @@ int main(int argc, char **argv, char **envp)
 }
 dpy_resize(ds);
 
-QLIST_FOREACH(dcl, &ds->listeners, next) {
-if (dcl->dpy_refresh != NULL) {
-ds->gui_timer = qemu_new_timer(rt_clock, gui_update, ds);
-qemu_mod_timer(ds->gui_timer, qemu_get_clock(rt_clock));
-}
-}
-
-if (display_type == DT_NOGRAPHIC || display_type == DT_VNC) {
-nographic_timer = qemu_new_timer(rt_clock, nographic_update, NULL);
-qemu_mod_timer(nographic_timer, qemu_get_clock(rt_clock));
-}
+gui_timer = qemu_new_timer(rt_clock, gui_update, ds);
+qemu_mod_timer(gui_timer, qemu_get_clock(rt_clock));
 
 text_consoles_set_display(ds);
 
-- 
1.6.6.1




[Qemu-devel] [PATCH 11/17] Introduce OS specific cmdline argument handling and move SMB arg to os-posix.c

2010-06-04 Thread Jes . Sorensen
From: Jes Sorensen 

Introduce OS specific cmdline argument handling by calling
os_parse_cmd_args() at the end of switch() statement. Move option
enum to qemu-options.h and have it included from os-posix.c and
os-win32.c in addition to vl.c.

In addition move SMB argument to os-posix.c

Signed-off-by: Jes Sorensen 
---
 Makefile.objs |2 ++
 os-posix.c|   19 +++
 os-win32.c|   10 ++
 sysemu.h  |1 +
 vl.c  |   19 +++
 5 files changed, 35 insertions(+), 16 deletions(-)

diff --git a/Makefile.objs b/Makefile.objs
index 124afe7..27595df 100644
--- a/Makefile.objs
+++ b/Makefile.objs
@@ -259,6 +259,8 @@ vl.o: QEMU_CFLAGS+=$(GPROF_CFLAGS)
 vl.o: QEMU_CFLAGS+=$(SDL_CFLAGS)
 
 vl.o: qemu-options.def
+os-posix.o: qemu-options.def
+os-win32.o: qemu-options.def
 
 qemu-options.def: $(SRC_PATH)/qemu-options.hx
$(call quiet-command,sh $(SRC_PATH)/hxtool -h < $< > $@,"  GEN   
$(TARGET_DIR)$@")
diff --git a/os-posix.c b/os-posix.c
index 621ad06..0deddf3 100644
--- a/os-posix.c
+++ b/os-posix.c
@@ -33,6 +33,8 @@
 /* Needed early for CONFIG_BSD etc. */
 #include "config-host.h"
 #include "sysemu.h"
+#include "net/slirp.h"
+#include "qemu-options.h"
 
 void os_setup_early_signal_handling(void)
 {
@@ -130,3 +132,20 @@ char *os_find_datadir(const char *argv0)
 }
 #undef SHARE_SUFFIX
 #undef BUILD_SUFFIX
+
+/*
+ * Parse OS specific command line options.
+ * return 0 if option handled, -1 otherwise
+ */
+void os_parse_cmd_args(int index, const char *optarg)
+{
+switch (index) {
+#ifdef CONFIG_SLIRP
+case QEMU_OPTION_smb:
+if (net_slirp_smb(optarg) < 0)
+exit(1);
+break;
+#endif
+}
+return;
+}
diff --git a/os-win32.c b/os-win32.c
index 1758538..aefc535 100644
--- a/os-win32.c
+++ b/os-win32.c
@@ -31,6 +31,7 @@
 #include 
 #include "config-host.h"
 #include "sysemu.h"
+#include "qemu-options.h"
 
 /***/
 /* Polling handling */
@@ -204,3 +205,12 @@ char *os_find_datadir(const char *argv0)
 }
 return NULL;
 }
+
+/*
+ * Parse OS specific command line options.
+ * return 0 if option handled, -1 otherwise
+ */
+void os_parse_cmd_args(int index, const char *optarg)
+{
+return;
+}
diff --git a/sysemu.h b/sysemu.h
index affcbea..d7aab40 100644
--- a/sysemu.h
+++ b/sysemu.h
@@ -81,6 +81,7 @@ void do_info_slirp(Monitor *mon);
 
 /* OS specific functions */
 char *os_find_datadir(const char *argv0);
+void os_parse_cmd_args(int index, const char *optarg);
 
 typedef enum DisplayType
 {
diff --git a/vl.c b/vl.c
index 8cd0f8f..7c48024 100644
--- a/vl.c
+++ b/vl.c
@@ -148,6 +148,7 @@ int main(int argc, char **argv)
 #include "qemu-option.h"
 #include "qemu-config.h"
 #include "qemu-objects.h"
+#include "qemu-options.h"
 #ifdef CONFIG_LINUX
 #include "fsdev/qemu-fsdev.h"
 #endif
@@ -1899,16 +1900,6 @@ static void help(int exitcode)
 
 #define HAS_ARG 0x0001
 
-enum {
-#define DEF(option, opt_arg, opt_enum, opt_help, arch_mask) \
-opt_enum,
-#define DEFHEADING(text)
-#include "qemu-options.def"
-#undef DEF
-#undef DEFHEADING
-#undef GEN_DOCS
-};
-
 typedef struct QEMUOption {
 const char *name;
 int flags;
@@ -2624,12 +2615,6 @@ int main(int argc, char **argv, char **envp)
 case QEMU_OPTION_bootp:
 legacy_bootp_filename = optarg;
 break;
-#ifndef _WIN32
-case QEMU_OPTION_smb:
-if (net_slirp_smb(optarg) < 0)
-exit(1);
-break;
-#endif
 case QEMU_OPTION_redir:
 if (net_slirp_redir(optarg) < 0)
 exit(1);
@@ -3126,6 +3111,8 @@ int main(int argc, char **argv, char **envp)
 fclose(fp);
 break;
 }
+default:
+os_parse_cmd_args(popt->index, optarg);
 }
 }
 }
-- 
1.6.5.2




[Qemu-devel] Re: [PATCH 3/5] vnc: add lossless option

2010-06-04 Thread Anthony Liguori

On 06/04/2010 08:17 AM, Alexander Graf wrote:

On 04.06.2010, at 15:18, Corentin Chary wrote:

   

The lossless option can be used to force lossless compression
by disabling all lossy encodings like gradient or jpeg.
 

I think this should be reverse. Be lossless by default, but have a lossy option.
   


I agree.  I think we need to disable gradient by default.  Maybe we can 
trigger gradient too whenever jpeg is enabled by the client.


Regards,

Anthony Liguori


Alex

   





[Qemu-devel] [PATCH] [V4] 9p: readdir implementation for 9p2000.L

2010-06-04 Thread Sripathi Kodi
This patch implements the kernel part of readdir() implementation for 9p2000.L

Change from V3: Instead of inode, server now sends qids for each dirent

SYNOPSIS

size[4] Treaddir tag[2] fid[4] offset[8] count[4]
size[4] Rreaddir tag[2] count[4] data[count]

DESCRIPTION

The readdir request asks the server to read the directory specified by 'fid'
at an offset specified by 'offset' and return as many dirent structures as
possible that fit into count bytes. Each dirent structure is laid out as
follows.

qid.type[1]
  the type of the file (directory, etc.), represented as a bit
  vector corresponding to the high 8 bits of the file's mode
  word.

qid.vers[4]
  version number for given path

qid.path[8]
  the file server's unique identification for the file

offset[8]
  offset into the next dirent.

type[1]
  type of this directory entry.

name[256]
  name of this directory entry.

This patch adds v9fs_dir_readdir_dotl() as the readdir() call for 9p2000.L.
This function sends P9_TREADDIR command to the server. In response the 
server
sends a buffer filled with dirent structures. This is different from the
existing v9fs_dir_readdir() call which receives stat structures from the 
server.
This results in significant speedup of readdir() on large directories.
For example, doing 'ls >/dev/null' on a directory with 1 files on my
laptop takes 1.088 seconds with the existing code, but only takes 0.339 
seconds
with the new readdir.

Signed-off-by: Sripathi Kodi 
Reviewed-by: Aneesh Kumar K.V 
---

 fs/9p/vfs_dir.c |  134 +--
 include/net/9p/9p.h |   17 ++
 include/net/9p/client.h |   18 ++
 net/9p/client.c |   47 
 net/9p/protocol.c   |   27 +
 5 files changed, 227 insertions(+), 16 deletions(-)

diff --git a/fs/9p/vfs_dir.c b/fs/9p/vfs_dir.c
index d61e3b2..aa1852d 100644
--- a/fs/9p/vfs_dir.c
+++ b/fs/9p/vfs_dir.c
@@ -87,29 +87,19 @@ static void p9stat_init(struct p9_wstat *stbuf)
 }
 
 /**
- * v9fs_dir_readdir - read a directory
+ * v9fs_alloc_rdir_buf - Allocate buffer used for read and readdir
  * @filp: opened file structure
- * @dirent: directory structure ???
- * @filldir: function to populate directory structure ???
+ * @buflen: Length in bytes of buffer to allocate
  *
  */
 
-static int v9fs_dir_readdir(struct file *filp, void *dirent, filldir_t filldir)
+static int v9fs_alloc_rdir_buf(struct file *filp, int buflen)
 {
-   int over;
-   struct p9_wstat st;
-   int err = 0;
-   struct p9_fid *fid;
-   int buflen;
-   int reclen = 0;
struct p9_rdir *rdir;
+   struct p9_fid *fid;
+   int err = 0;
 
-   P9_DPRINTK(P9_DEBUG_VFS, "name %s\n", filp->f_path.dentry->d_name.name);
fid = filp->private_data;
-
-   buflen = fid->clnt->msize - P9_IOHDRSZ;
-
-   /* allocate rdir on demand */
if (!fid->rdir) {
rdir = kmalloc(sizeof(struct p9_rdir) + buflen, GFP_KERNEL);
 
@@ -128,6 +118,36 @@ static int v9fs_dir_readdir(struct file *filp, void 
*dirent, filldir_t filldir)
spin_unlock(&filp->f_dentry->d_lock);
kfree(rdir);
}
+exit:
+   return err;
+}
+
+/**
+ * v9fs_dir_readdir - read a directory
+ * @filp: opened file structure
+ * @dirent: directory structure ???
+ * @filldir: function to populate directory structure ???
+ *
+ */
+
+static int v9fs_dir_readdir(struct file *filp, void *dirent, filldir_t filldir)
+{
+   int over;
+   struct p9_wstat st;
+   int err = 0;
+   struct p9_fid *fid;
+   int buflen;
+   int reclen = 0;
+   struct p9_rdir *rdir;
+
+   P9_DPRINTK(P9_DEBUG_VFS, "name %s\n", filp->f_path.dentry->d_name.name);
+   fid = filp->private_data;
+
+   buflen = fid->clnt->msize - P9_IOHDRSZ;
+
+   err = v9fs_alloc_rdir_buf(filp, buflen);
+   if (err)
+   goto exit;
rdir = (struct p9_rdir *) fid->rdir;
 
err = mutex_lock_interruptible(&rdir->mutex);
@@ -176,6 +196,88 @@ exit:
return err;
 }
 
+/**
+ * v9fs_dir_readdir_dotl - read a directory
+ * @filp: opened file structure
+ * @dirent: buffer to fill dirent structures
+ * @filldir: function to populate dirent structures
+ *
+ */
+static int v9fs_dir_readdir_dotl(struct file *filp, void *dirent,
+   filldir_t filldir)
+{
+   int over;
+   int err = 0;
+   struct p9_fid *fid;
+   int buflen;
+   struct p9_rdir *rdir;
+   struct p9_dirent curdirent;
+   u64 oldoffset = 0;
+
+   P9_DPRINTK(P9_DEBUG_VFS, "name %s\n", filp->f_path.dentry->d_name.name);
+   fid = filp->private_data;
+
+   buflen = fid->clnt->msize - P9_READDIRHDRSZ;
+

Re: [Qemu-devel] [PATCH 10/16] Introduce OS specific cmdline argument handling and move SMB arg to os-posix.c

2010-06-04 Thread Jes Sorensen
On 06/04/10 16:49, Richard Henderson wrote:
> On 06/03/2010 11:47 PM, Jes Sorensen wrote:
>> The problem is that it requires qemu-options.h to be included, which
>> isn't included per default for all the files. If I put it into sysemu.h
>> at least it's going to require making every .c file build with those flags.
>>
>> I agree it's gross, but I am not sure what would be a better solution.
> 
> One possible solution is to put this whole block in "qemu-options-enum.h"
> (or whatever) and include that in the three places that you have this block.

I ended up moving qemu-options.h to qemu-options.def and then creating a
proper qemu-options.h per Paolo's suggestion.

Let me know what you think of the v2 patch set, minus the duplicates
some idiot posted because he forgot to remove the Emacs backup files :)

Cheers,
Jes



Re: [Qemu-devel] [PATCH] qdev: Reject duplicate and anti-social device IDs

2010-06-04 Thread Paul Brook
> Paul Brook  writes:
> >> Also require IDs to start with a letter to provide for possible future
> >> extensions.
> > 
> > I'd go further than that, and require that user specified IDs match
> > [A-Za-z][A-Za-z0-9_-]*
> 
> I talked with Dan (cc'ed) to make sure we don't trample on existing
> libvirt usage without need.  What about
> 
> [A-Za-z][A-Za-z0-9_-:.]*
> 
> i.e. your regexp plus ':' and '.' in the second bracket?

I was deliberately avoiding those as they're often used as separators - we 
already use ':' in other contexts so there's potential ambiguity and 
parsing/quoting issues. I'm not aware of any current issues with '.'.

Paul

P.S. Your regexp doesn't do what you think it does, but I know what you mean.



Re: [Qemu-devel] [PATCH 11/17] Introduce OS specific cmdline argument handling and move SMB arg to os-posix.c

2010-06-04 Thread Richard Henderson
On 06/04/2010 06:24 AM, jes.soren...@redhat.com wrote:
> ---
>  Makefile.objs |2 ++
>  os-posix.c|   19 +++
>  os-win32.c|   10 ++
>  sysemu.h  |1 +
>  vl.c  |   19 +++
>  5 files changed, 35 insertions(+), 16 deletions(-)

Looks like you forgot to git add qemu-options.h with this patch.
Otherwise the entire series looks good to me now.


r~



Re: [Qemu-devel] [PATCH 10/16] Introduce OS specific cmdline argument handling and move SMB arg to os-posix.c

2010-06-04 Thread Richard Henderson
On 06/03/2010 11:47 PM, Jes Sorensen wrote:
> On 06/03/10 22:58, Richard Henderson wrote:
>> On 06/03/2010 09:48 AM, jes.soren...@redhat.com wrote:
>>> +/*
>>> + * Duplicate definition from vl.c to avoid messing up the entire build
>>> + */
>>> +enum {
>>> +#define DEF(option, opt_arg, opt_enum, opt_help, arch_mask) \
>>> +opt_enum,
>>> +#define DEFHEADING(text)
>>> +#include "qemu-options.h"
>>> +#undef DEF
>>> +#undef DEFHEADING
>>> +#undef GEN_DOCS
>>> +};
>>
>> There's no header file you can put this in?  Or invent to put this in?
>> Cause this is really kinda gross...
>>
> 
> The problem is that it requires qemu-options.h to be included, which
> isn't included per default for all the files. If I put it into sysemu.h
> at least it's going to require making every .c file build with those flags.
> 
> I agree it's gross, but I am not sure what would be a better solution.

One possible solution is to put this whole block in "qemu-options-enum.h"
(or whatever) and include that in the three places that you have this block.


r~



[Qemu-devel] Re: [PATCH v2 2/2] vnc: threaded VNC server

2010-06-04 Thread Paolo Bonzini

On 06/04/2010 04:55 PM, Corentin Chary wrote:

Because it's not in a loop ? Like I said in the cover-letter (but this
should probably be in a comment here) you can't use multiple worker
on a single queue because of zlib streams. But if the issue is more a
style issue than the actual implementation, then I can use a loop and
an exit flag.


Yes, it's both a style issue and a future-proofing issue.  I think it's 
better to be boring when it comes to locking. :-)


(The cover letter hasn't arrived yet, so I haven't read it).

Paolo



[Qemu-devel] Re: [PATCH v2 2/2] vnc: threaded VNC server

2010-06-04 Thread Paolo Bonzini

+vnc_lock_queue(queue);
+if (QTAILQ_EMPTY(&queue->jobs)) {
+qemu_cond_wait(&queue->cond,&queue->mutex);
+}
+
+/* If the queue is empty, it's an exit order */
+if (QTAILQ_EMPTY(&queue->jobs)) {
+vnc_unlock_queue(queue);
+return -1;
+}
+
+job = QTAILQ_FIRST(&queue->jobs);
+vnc_unlock_queue(queue);


Wrong usage of condition variables...


+flush = (job->vs->csock != -1&&  job->vs->abording != true);


and typo still there.


+static void *vnc_worker_thread(void *arg)
+{
+VncJobQueue *queue = arg;


Also, it's better (future proof) to call qemu_thread_self here.

Thanks!

Paolo



[Qemu-devel] Re: [PATCH v2 2/2] vnc: threaded VNC server

2010-06-04 Thread Corentin Chary
On Fri, Jun 4, 2010 at 3:25 PM, Alexander Graf  wrote:
>
> On 04.06.2010, at 15:20, Corentin Chary wrote:
>
>> Implement a threaded VNC server using the producer-consumer model.
>> The main thread will push encoding jobs (a list a rectangles to update)
>> in a queue, and the VNC worker thread will consume that queue and send
>> framebuffer updates to the output buffer.
>
> Hrm, does it merge the queue? So imagine the following gets put in the queue
>
> [0,0] - [100,100]
> [100,0] - [200,10]
> [0,0] - [200,10]
>
> Would that code try and merge those three queue entries? Because by adding 
> the queue, you basically get rid of the automatic merging we get from the 
> lazy dirty bitmap fetching.

I wanted to add that later.

> Before we were processing each entry and checked the bitmap again, seeing a 
> merged bitmap of previous actions. With this I assume you push to-be-updated 
> regions into the queue and mark them as processed before they are?

I mark them as processed as soon as they are put into the queue.
refresh() is also delayed while encoding job are processing (check the
trylock part) to avoid unecessary dirty bitmap updates and locks.

-- 
Corentin Chary
http://xf.iksaif.net



[Qemu-devel] Re: [PATCH v2 2/2] vnc: threaded VNC server

2010-06-04 Thread Alexander Graf

On 04.06.2010, at 15:20, Corentin Chary wrote:

> Implement a threaded VNC server using the producer-consumer model.
> The main thread will push encoding jobs (a list a rectangles to update)
> in a queue, and the VNC worker thread will consume that queue and send
> framebuffer updates to the output buffer.
> 
> The threaded VNC server can be enabled with ./configure --enable-vnc-thread.
> 
> If you don't want it, just use ./configure --disable-vnc-thread and a 
> syncrhonous
> queue of job will be used (which as exactly the same behavior as the old 
> queue).
> If you disable the VNC thread, all thread related code will not be built and 
> there will
> be no overhead.
> 
> Signed-off-by: Corentin Chary 
> ---
> Makefile.objs  |7 +-
> configure  |   13 ++
> ui/vnc-jobs-sync.c |   65 ++
> ui/vnc-jobs.c  |  351 
> ui/vnc.c   |  169 ++
> ui/vnc.h   |   75 +++
> 6 files changed, 657 insertions(+), 23 deletions(-)
> create mode 100644 ui/vnc-jobs-sync.c
> create mode 100644 ui/vnc-jobs.c
> 
> diff --git a/Makefile.objs b/Makefile.objs
> index 22622a9..0c6334b 100644
> --- a/Makefile.objs
> +++ b/Makefile.objs
> @@ -109,10 +109,15 @@ ui-obj-y += vnc-enc-tight.o
> ui-obj-$(CONFIG_VNC_TLS) += vnc-tls.o vnc-auth-vencrypt.o
> ui-obj-$(CONFIG_VNC_SASL) += vnc-auth-sasl.o
> ui-obj-$(CONFIG_COCOA) += cocoa.o
> +ifdef CONFIG_VNC_THREAD
> +ui-obj-y += vnc-jobs.o
> +else
> +ui-obj-y += vnc-jobs-sync.o
> +endif
> common-obj-y += $(addprefix ui/, $(ui-obj-y))
> 
> common-obj-y += iov.o acl.o
> -common-obj-$(CONFIG_IOTHREAD) += qemu-thread.o
> +common-obj-$(CONFIG_THREAD) += qemu-thread.o
> common-obj-y += notify.o event_notifier.o
> common-obj-y += qemu-timer.o
> 
> diff --git a/configure b/configure
> index 679f2fc..6f2e3a7 100755
> --- a/configure
> +++ b/configure
> @@ -264,6 +264,7 @@ vde=""
> vnc_tls=""
> vnc_sasl=""
> vnc_jpeg=""
> +vnc_thread=""
> xen=""
> linux_aio=""
> vhost_net=""
> @@ -552,6 +553,10 @@ for opt do
>   ;;
>   --enable-vnc-jpeg) vnc_jpeg="yes"
>   ;;
> +  --disable-vnc-thread) vnc_thread="no"
> +  ;;
> +  --enable-vnc-thread) vnc_thread="yes"
> +  ;;
>   --disable-slirp) slirp="no"
>   ;;
>   --disable-uuid) uuid="no"
> @@ -786,6 +791,8 @@ echo "  --disable-vnc-sasl   disable SASL encryption 
> for VNC server"
> echo "  --enable-vnc-saslenable SASL encryption for VNC server"
> echo "  --disable-vnc-jpeg   disable JPEG lossy compression for VNC 
> server"
> echo "  --enable-vnc-jpegenable JPEG lossy compression for VNC server"
> +echo "  --disable-vnc-thread disable threaded VNC server"
> +echo "  --enable-vnc-thread  enable threaded VNC server"
> echo "  --disable-curses disable curses output"
> echo "  --enable-curses  enable curses output"
> echo "  --disable-curl   disable curl connectivity"
> @@ -2048,6 +2055,7 @@ echo "Mixer emulation   $mixemu"
> echo "VNC TLS support   $vnc_tls"
> echo "VNC SASL support  $vnc_sasl"
> echo "VNC JPEG support  $vnc_jpeg"
> +echo "VNC thread$vnc_thread"
> if test -n "$sparc_cpu"; then
> echo "Target Sparc Arch $sparc_cpu"
> fi
> @@ -2191,6 +2199,10 @@ if test "$vnc_jpeg" = "yes" ; then
>   echo "CONFIG_VNC_JPEG=y" >> $config_host_mak
>   echo "VNC_JPEG_CFLAGS=$vnc_jpeg_cflags" >> $config_host_mak
> fi
> +if test "$vnc_thread" = "yes" ; then

So it's disabled by default? Sounds like a pretty cool and useful feature to me 
that should be enabled by default.

> +  echo "CONFIG_VNC_THREAD=y" >> $config_host_mak
> +  echo "CONFIG_THREAD=y" >> $config_host_mak
> +fi
> if test "$fnmatch" = "yes" ; then
>   echo "CONFIG_FNMATCH=y" >> $config_host_mak
> fi
> @@ -2267,6 +2279,7 @@ if test "$xen" = "yes" ; then
> fi
> if test "$io_thread" = "yes" ; then
>   echo "CONFIG_IOTHREAD=y" >> $config_host_mak
> +  echo "CONFIG_THREAD=y" >> $config_host_mak
> fi
> if test "$linux_aio" = "yes" ; then
>   echo "CONFIG_LINUX_AIO=y" >> $config_host_mak
> diff --git a/ui/vnc-jobs-sync.c b/ui/vnc-jobs-sync.c
> new file mode 100644
> index 000..9f138f5
> --- /dev/null
> +++ b/ui/vnc-jobs-sync.c
> @@ -0,0 +1,65 @@
> +/*
> + * QEMU VNC display driver
> + *
> + * Copyright (C) 2006 Anthony Liguori 
> + * Copyright (C) 2006 Fabrice Bellard
> + * Copyright (C) 2009 Red Hat, Inc
> + * Copyright (C) 2010 Corentin Chary 
> + *
> + * Permission is hereby granted, free of charge, to any person obtaining a 
> copy
> + * of this software and associated documentation files (the "Software"), to 
> deal
> + * in the Software without restriction, including without limitation the 
> rights
> + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
> + * copies of the Software, and to permit persons to whom the Software is
> + * furnished to do so, subject to the following conditions:
> + *
> + * The above copyright notice and this permission notice shall be included in
> + * all copies or 

Re: [Qemu-devel] Re: [V9fs-developer] [PATCH] virtio-9p: getattr server implementation for 9P2000.L protocol.

2010-06-04 Thread Venkateswararao Jujjuri (JV)
Aneesh Kumar K. V wrote:
> On Thu, 3 Jun 2010 18:29:02 +0530, Sripathi Kodi  wrote:
>> On Wed, 02 Jun 2010 19:49:24 +0530
>> "Aneesh Kumar K. V"  wrote:
>>
>>> On Fri, 28 May 2010 16:08:43 +0530, Sripathi Kodi  
>>> wrote:
 From: M. Mohan Kumar 

 SYNOPSIS

   size[4] Tgetattr tag[2] fid[4]

   size[4] Rgetattr tag[2] lstat[n]

DESCRIPTION

   The getattr transaction inquires about the file identified by fid.
   The reply will contain a machine-independent directory entry,
   laid out as follows:

  qid.type[1]
 the type of the file (directory, etc.), represented as a bit
 vector corresponding to the high 8 bits of the file's mode
 word.

  qid.vers[4]
 version number for given path

  qid.path[8]
 the file server's unique identification for the file

  st_mode[4]
 Permission and flags

  st_nlink[8]
 Number of hard links

  st_uid[4]
 User id of owner

  st_gid[4]
 Group ID of owner

  st_rdev[8]
 Device ID (if special file)

  st_size[8]
 Size, in bytes

  st_blksize[8]
 Block size for file system IO
>>>
>>> So it should be scaled by iounit right ? If we say 9p block size is iounit.
>> Yes, I think it should be iounit. Currently st_blksize being returned
>> in stat structure to the user space does not use this field that comes
>> from the server. It is being calculated as follows in
>> generic_fillattr():
>>
>> stat->blksize = (1 << inode->i_blkbits);
>>
>> So there may not be a need to put st_blksize on the protocol. Further,
>> inode->i_blkbits is copied from sb->s_blocksize_bits. For 9P this value
>> is obtained as:
> 
> That is what linux kernel currently does. But from the protocol point of
> view and not looking at specific linux implementation i would suggest to
> put st_blksize on wire. 

This is part of .L protocol. Specifically for Linux systems. So, if Linux is 
already
doing it, I don't think we need to repeat it.

Thanks,
JV

> 
> 
> -aneesh
> 





[Qemu-devel] [PATCH] target-i386: fix decoding of negative 4-byte displacements

2010-06-04 Thread Paolo Bonzini
Negative four byte displacements need to be sign-extended after
c086b783eb7a578993d6d2ab62c4c2666800b63d.  Do so.

Signed-off-by: Paolo Bonzini 
---
There are quite a few other ldl's to audit after the patch
(about 70 in target-*).  Any volunteers? :-)

 target-i386/translate.c |2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)

diff --git a/target-i386/translate.c b/target-i386/translate.c
index 38c6016..708b0a1 100644
--- a/target-i386/translate.c
+++ b/target-i386/translate.c
@@ -2016,7 +2016,7 @@ static void gen_lea_modrm(DisasContext *s, int modrm, int 
*reg_ptr, int *offset_
 break;
 default:
 case 2:
-disp = ldl_code(s->pc);
+disp = (int32_t)ldl_code(s->pc);
 s->pc += 4;
 break;
 }
-- 
1.7.0.1



[Qemu-devel] [PATCH 1/3] QLIST-ify display change listeners.

2010-06-04 Thread Gerd Hoffmann

Signed-off-by: Gerd Hoffmann 
---
 console.h  |   72 +++
 hw/xenfb.c |2 +-
 vl.c   |9 ++-
 3 files changed, 42 insertions(+), 41 deletions(-)

diff --git a/console.h b/console.h
index cac959f..3a80dca 100644
--- a/console.h
+++ b/console.h
@@ -161,7 +161,7 @@ struct DisplayChangeListener {
  int w, int h, uint32_t c);
 void (*dpy_text_cursor)(struct DisplayState *s, int x, int y);
 
-struct DisplayChangeListener *next;
+QLIST_ENTRY(DisplayChangeListener) next;
 };
 
 struct DisplayAllocator {
@@ -176,7 +176,7 @@ struct DisplayState {
 struct QEMUTimer *gui_timer;
 
 struct DisplayAllocator* allocator;
-struct DisplayChangeListener* listeners;
+QLIST_HEAD(, DisplayChangeListener) listeners;
 
 void (*mouse_set)(int x, int y, int on);
 void (*cursor_define)(QEMUCursor *cursor);
@@ -224,72 +224,76 @@ static inline int is_buffer_shared(DisplaySurface 
*surface)
 
 static inline void register_displaychangelistener(DisplayState *ds, 
DisplayChangeListener *dcl)
 {
-dcl->next = ds->listeners;
-ds->listeners = dcl;
+QLIST_INSERT_HEAD(&ds->listeners, dcl, next);
 }
 
 static inline void dpy_update(DisplayState *s, int x, int y, int w, int h)
 {
-struct DisplayChangeListener *dcl = s->listeners;
-while (dcl != NULL) {
+struct DisplayChangeListener *dcl;
+QLIST_FOREACH(dcl, &s->listeners, next) {
 dcl->dpy_update(s, x, y, w, h);
-dcl = dcl->next;
 }
 }
 
 static inline void dpy_resize(DisplayState *s)
 {
-struct DisplayChangeListener *dcl = s->listeners;
-while (dcl != NULL) {
+struct DisplayChangeListener *dcl;
+QLIST_FOREACH(dcl, &s->listeners, next) {
 dcl->dpy_resize(s);
-dcl = dcl->next;
 }
 }
 
 static inline void dpy_setdata(DisplayState *s)
 {
-struct DisplayChangeListener *dcl = s->listeners;
-while (dcl != NULL) {
-if (dcl->dpy_setdata) dcl->dpy_setdata(s);
-dcl = dcl->next;
+struct DisplayChangeListener *dcl;
+QLIST_FOREACH(dcl, &s->listeners, next) {
+if (dcl->dpy_setdata) {
+dcl->dpy_setdata(s);
+}
 }
 }
 
 static inline void dpy_refresh(DisplayState *s)
 {
-struct DisplayChangeListener *dcl = s->listeners;
-while (dcl != NULL) {
-if (dcl->dpy_refresh) dcl->dpy_refresh(s);
-dcl = dcl->next;
+struct DisplayChangeListener *dcl;
+QLIST_FOREACH(dcl, &s->listeners, next) {
+if (dcl->dpy_refresh) {
+dcl->dpy_refresh(s);
+}
 }
 }
 
 static inline void dpy_copy(struct DisplayState *s, int src_x, int src_y,
- int dst_x, int dst_y, int w, int h) {
-struct DisplayChangeListener *dcl = s->listeners;
-while (dcl != NULL) {
-if (dcl->dpy_copy)
+ int dst_x, int dst_y, int w, int h)
+{
+struct DisplayChangeListener *dcl;
+QLIST_FOREACH(dcl, &s->listeners, next) {
+if (dcl->dpy_copy) {
 dcl->dpy_copy(s, src_x, src_y, dst_x, dst_y, w, h);
-else /* TODO */
+} else { /* TODO */
 dcl->dpy_update(s, dst_x, dst_y, w, h);
-dcl = dcl->next;
+}
 }
 }
 
 static inline void dpy_fill(struct DisplayState *s, int x, int y,
- int w, int h, uint32_t c) {
-struct DisplayChangeListener *dcl = s->listeners;
-while (dcl != NULL) {
-if (dcl->dpy_fill) dcl->dpy_fill(s, x, y, w, h, c);
-dcl = dcl->next;
+ int w, int h, uint32_t c)
+{
+struct DisplayChangeListener *dcl;
+QLIST_FOREACH(dcl, &s->listeners, next) {
+if (dcl->dpy_fill) {
+dcl->dpy_fill(s, x, y, w, h, c);
+}
 }
 }
 
-static inline void dpy_cursor(struct DisplayState *s, int x, int y) {
-struct DisplayChangeListener *dcl = s->listeners;
-while (dcl != NULL) {
-if (dcl->dpy_text_cursor) dcl->dpy_text_cursor(s, x, y);
-dcl = dcl->next;
+static inline void dpy_cursor(struct DisplayState *s, int x, int y)
+{
+struct DisplayChangeListener *dcl;
+QLIST_FOREACH(dcl, &s->listeners, next) {
+if (dcl->dpy_text_cursor) {
+dcl->dpy_text_cursor(s, x, y);
+}
 }
 }
 
diff --git a/hw/xenfb.c b/hw/xenfb.c
index 422cd53..472c9cb 100644
--- a/hw/xenfb.c
+++ b/hw/xenfb.c
@@ -707,7 +707,7 @@ static void xenfb_update(void *opaque)
if (xenfb_queue_full(xenfb))
return;
 
-for (l = xenfb->c.ds->listeners; l != NULL; l = l->next) {
+QLIST_FOREACH(l, &xenfb->c.ds->listeners, next) {
 if (l->idle)
 continue;
 idle = 0;
diff --git a/vl.c b/vl.c
index 527d068..9ca4e2f 100644
--- a/vl.c
+++ b/vl.c
@@ -1630,16 +1630,15 @@ static void gui_update(void *opaque)
 {
 uint64_t interval = GUI_REFRESH_INTERVAL;
 DisplayState *ds = opaque;
-DisplayChangeListener *dcl = ds->list

Re: [Qemu-devel] [PATCH] qdev: Reject duplicate and anti-social device IDs

2010-06-04 Thread Markus Armbruster
Paul Brook  writes:

>> Also require IDs to start with a letter to provide for possible future
>> extensions.
>
> I'd go further than that, and require that user specified IDs match
> [A-Za-z][A-Za-z0-9_-]*

I talked with Dan (cc'ed) to make sure we don't trample on existing
libvirt usage without need.  What about

[A-Za-z][A-Za-z0-9_-:.]*

i.e. your regexp plus ':' and '.' in the second bracket?



[Qemu-devel] Re: [PATCH v2 2/2] vnc: threaded VNC server

2010-06-04 Thread Corentin Chary
On Fri, Jun 4, 2010 at 4:41 PM, Paolo Bonzini  wrote:
>> +    vnc_lock_queue(queue);
>> +    if (QTAILQ_EMPTY(&queue->jobs)) {
>> +        qemu_cond_wait(&queue->cond,&queue->mutex);
>> +    }
>> +
>> +    /* If the queue is empty, it's an exit order */
>> +    if (QTAILQ_EMPTY(&queue->jobs)) {
>> +        vnc_unlock_queue(queue);
>> +        return -1;
>> +    }
>> +
>> +    job = QTAILQ_FIRST(&queue->jobs);
>> +    vnc_unlock_queue(queue);
>
> Wrong usage of condition variables...

Because it's not in a loop ? Like I said in the cover-letter (but this
should probably be in a comment here) you can't use multiple worker
on a single queue because of zlib streams. But if the issue is more a
style issue than the actual implementation, then I can use a loop and
an exit flag.

>> +    flush = (job->vs->csock != -1&&  job->vs->abording != true);
>
> and typo still there.

Ooops, I did it again.

>> +static void *vnc_worker_thread(void *arg)
>> +{
>> +    VncJobQueue *queue = arg;
>
> Also, it's better (future proof) to call qemu_thread_self here.

Ok,


-- 
Corentin Chary
http://xf.iksaif.net



[Qemu-devel] [PATCH 3/3] Fix and simplify gui timer logic.

2010-06-04 Thread Gerd Hoffmann
Kill nographic timer.  Have a global gui_timer instead.  Have the gui
timer enabled unconditionally.  We need a timer running anyway for mmio
flush, so the whole have-gui-timer-only-when-needed logic is pretty
pointless.  It also simplifies displaylisteners coming and going at
runtime, we don't need to care about the timer then as it runs anyway.

Don't allocate the timer twice in case we have two display listeners.

Signed-off-by: Gerd Hoffmann 
---
 console.h |1 -
 vl.c  |   37 +++--
 2 files changed, 11 insertions(+), 27 deletions(-)

diff --git a/console.h b/console.h
index a0da498..6dad8d0 100644
--- a/console.h
+++ b/console.h
@@ -173,7 +173,6 @@ struct DisplayAllocator {
 struct DisplayState {
 struct DisplaySurface *surface;
 void *opaque;
-struct QEMUTimer *gui_timer;
 
 struct DisplayAllocator* allocator;
 QLIST_HEAD(, DisplayChangeListener) listeners;
diff --git a/vl.c b/vl.c
index 9ca4e2f..703a233 100644
--- a/vl.c
+++ b/vl.c
@@ -236,7 +236,7 @@ int nb_numa_nodes;
 uint64_t node_mem[MAX_NODES];
 uint64_t node_cpumask[MAX_NODES];
 
-static QEMUTimer *nographic_timer;
+static QEMUTimer *gui_timer;
 
 uint8_t qemu_uuid[16];
 
@@ -1633,22 +1633,17 @@ static void gui_update(void *opaque)
 DisplayChangeListener *dcl;
 
 qemu_flush_coalesced_mmio_buffer();
-dpy_refresh(ds);
 
-QLIST_FOREACH(dcl, &ds->listeners, next) {
-if (dcl->gui_timer_interval &&
-dcl->gui_timer_interval < interval)
-interval = dcl->gui_timer_interval;
+if (ds != NULL && !QLIST_EMPTY(&ds->listeners)) {
+dpy_refresh(ds);
+QLIST_FOREACH(dcl, &ds->listeners, next) {
+if (dcl->gui_timer_interval &&
+dcl->gui_timer_interval < interval)
+interval = dcl->gui_timer_interval;
+}
 }
-qemu_mod_timer(ds->gui_timer, interval + qemu_get_clock(rt_clock));
-}
-
-static void nographic_update(void *opaque)
-{
-uint64_t interval = GUI_REFRESH_INTERVAL;
 
-qemu_flush_coalesced_mmio_buffer();
-qemu_mod_timer(nographic_timer, interval + qemu_get_clock(rt_clock));
+qemu_mod_timer(gui_timer, interval + qemu_get_clock(rt_clock));
 }
 
 struct vm_change_state_entry {
@@ -2577,7 +2572,6 @@ int main(int argc, char **argv, char **envp)
 const char *kernel_filename, *kernel_cmdline;
 char boot_devices[33] = "cad"; /* default to HD->floppy->CD-ROM */
 DisplayState *ds;
-DisplayChangeListener *dcl;
 int cyls, heads, secs, translation;
 QemuOpts *hda_opts = NULL, *opts;
 int optind;
@@ -3807,17 +3801,8 @@ int main(int argc, char **argv, char **envp)
 }
 dpy_resize(ds);
 
-QLIST_FOREACH(dcl, &ds->listeners, next) {
-if (dcl->dpy_refresh != NULL) {
-ds->gui_timer = qemu_new_timer(rt_clock, gui_update, ds);
-qemu_mod_timer(ds->gui_timer, qemu_get_clock(rt_clock));
-}
-}
-
-if (display_type == DT_NOGRAPHIC || display_type == DT_VNC) {
-nographic_timer = qemu_new_timer(rt_clock, nographic_update, NULL);
-qemu_mod_timer(nographic_timer, qemu_get_clock(rt_clock));
-}
+gui_timer = qemu_new_timer(rt_clock, gui_update, ds);
+qemu_mod_timer(gui_timer, qemu_get_clock(rt_clock));
 
 text_consoles_set_display(ds);
 
-- 
1.6.6.1




[Qemu-devel] [PATCH 2/3] add unregister_displaychangelistener

2010-06-04 Thread Gerd Hoffmann

Signed-off-by: Gerd Hoffmann 
---
 console.h |5 +
 1 files changed, 5 insertions(+), 0 deletions(-)

diff --git a/console.h b/console.h
index 3a80dca..a0da498 100644
--- a/console.h
+++ b/console.h
@@ -227,6 +227,11 @@ static inline void 
register_displaychangelistener(DisplayState *ds, DisplayChang
 QLIST_INSERT_HEAD(&ds->listeners, dcl, next);
 }
 
+static inline void unregister_displaychangelistener(DisplayChangeListener *dcl)
+{
+QLIST_REMOVE(dcl, next);
+}
+
 static inline void dpy_update(DisplayState *s, int x, int y, int w, int h)
 {
 struct DisplayChangeListener *dcl;
-- 
1.6.6.1




[Qemu-devel] [Bug 589315] Re: qemu: Improve error reporting when migration can't connect

2010-06-04 Thread Luiz Capitulino
** Changed in: qemu
   Status: New => Confirmed

-- 
qemu: Improve error reporting when migration can't connect
https://bugs.launchpad.net/bugs/589315
You received this bug notification because you are a member of qemu-
devel-ml, which is subscribed to QEMU.

Status in QEMU: Confirmed

Bug description:
Tested with upstream qemu as of Jun 3 2010

If the source qemu instance can't connect to the migration destination (say
there is no listening QEMU instance, or port is blocked by a firewall), all we
get is info migrate -> Migration status: failed. This is all we have to report
back to libvirt users if their firewall is misconfigured, which is crappy.

Ideally, if we can't connect, migration would fail immediately with a relevant
message and strerror(). More info from 'info migrate' would be nice too, no
idea how this will play with QMP though.

As a slightly related issue, try entering

migrate tcp:127.0.0.0:6000

We get a 'migration failed' error, and then the monitor hangs!





Re: [Qemu-devel] Re: [PATCH 1/4] Add virtio disk identification support

2010-06-04 Thread Kevin Wolf
Am 03.06.2010 21:09, schrieb Anthony Liguori:
> On 03/25/2010 12:32 AM, john cooper wrote:
>> Add virtio-blk device id (s/n) support via virtio request.
>> Remove artifacts of pci and ATA_IDENTIFY implementation
>> relative to prior versions.
>>
>> Signed-off-by: john cooper
>> ---
>>
>> diff --git a/hw/virtio-blk.c b/hw/virtio-blk.c
>> index 9915840..358b0af 100644
>> --- a/hw/virtio-blk.c
>> +++ b/hw/virtio-blk.c
>> @@ -19,6 +19,8 @@
>>   # include
>>   #endif
>>
>> +#define min(a,b) ((a)<  (b) ? (a) : (b))
>>
> 
> We already have MIN().
> 
>> +
>>   typedef struct VirtIOBlock
>>   {
>>   VirtIODevice vdev;
>> @@ -28,6 +30,7 @@ typedef struct VirtIOBlock
>>   QEMUBH *bh;
>>   BlockConf *conf;
>>   unsigned short sector_mask;
>> +char sn[BLOCK_SERIAL_STRLEN];
>>   } VirtIOBlock;
>>
>>   static VirtIOBlock *to_virtio_blk(VirtIODevice *vdev)
>> @@ -317,6 +320,12 @@ static void virtio_blk_handle_request(VirtIOBlockReq 
>> *req,
>>   virtio_blk_handle_flush(req);
>>   } else if (req->out->type&  VIRTIO_BLK_T_SCSI_CMD) {
>>   virtio_blk_handle_scsi(req);
>> +} else if (req->out->type&  VIRTIO_BLK_T_GET_ID) {
>> +VirtIOBlock *s = req->dev;
>> +
>> +memcpy(req->elem.in_sg[0].iov_base, s->sn,
>> +   min(req->elem.in_sg[0].iov_len, sizeof(s->sn)));
>> +virtio_blk_req_complete(req, VIRTIO_BLK_S_OK);
>>   } else if (req->out->type&  VIRTIO_BLK_T_OUT) {
>>   qemu_iovec_init_external(&req->qiov,&req->elem.out_sg[1],
>>req->elem.out_num - 1);
>> @@ -496,6 +505,8 @@ VirtIODevice *virtio_blk_init(DeviceState *dev, 
>> BlockConf *conf)
>>   bdrv_guess_geometry(s->bs,&cylinders,&heads,&secs);
>>   bdrv_set_geometry_hint(s->bs, cylinders, heads, secs);
>>
>> +strncpy(s->sn, drive_get_serial(s->bs), sizeof (s->sn));
>> +
>>
> 
> Friends don't let friends use strncpy().
> 
> This actually will result in a non-NULL terminated string if 
> drive_get_serial() returns a string larger than s->sn.  Use snprintf() 
> instead.

Isn't this what we have pstrcpy for?

Kevin



[Qemu-devel] Re: [PATCH 1/2] machine: package all init arguments into a QemuOpts

2010-06-04 Thread Anthony Liguori

On 06/04/2010 09:11 AM, Anthony Liguori wrote:

This patch creates a QemuOpts structure and stores all of the machine init
arguments in that structure.  It introduces a temporary list of QemuOptDescs
in vl.c such that the current common options can be validated.

The long term vision is that that list becomes a #define and that each machine
can optionally provide it's own QemuOptDescs list using the common options as
a base.  This enables per-machine options.

Signed-off-by: Anthony Liguori

diff --git a/qemu-config.c b/qemu-config.c
index 5a4e61b..3679a9f 100644
--- a/qemu-config.c
+++ b/qemu-config.c
@@ -336,6 +336,14 @@ QemuOptsList qemu_cpudef_opts = {
  },
  };

+QemuOptsList qemu_machine_opts = {
+.name = "machine",
+.head = QTAILQ_HEAD_INITIALIZER(qemu_machine_opts.head),
+.desc = {
+{ /* end of list */ }
+},
+};
+
  static QemuOptsList *vm_config_groups[] = {
  &qemu_drive_opts,
  &qemu_chardev_opts,
@@ -346,6 +354,7 @@ static QemuOptsList *vm_config_groups[] = {
  &qemu_global_opts,
  &qemu_mon_opts,
  &qemu_cpudef_opts,
+&qemu_machine_opts,
  NULL,
  };

diff --git a/qemu-config.h b/qemu-config.h
index dca69d4..6f52188 100644
--- a/qemu-config.h
+++ b/qemu-config.h
@@ -14,6 +14,7 @@ extern QemuOptsList qemu_rtc_opts;
  extern QemuOptsList qemu_global_opts;
  extern QemuOptsList qemu_mon_opts;
  extern QemuOptsList qemu_cpudef_opts;
+extern QemuOptsList qemu_machine_opts;

  QemuOptsList *qemu_find_opts(const char *group);
  int qemu_set_option(const char *str);
diff --git a/vl.c b/vl.c
index 7121cd0..d362fc0 100644
--- a/vl.c
+++ b/vl.c
@@ -2550,6 +2550,35 @@ static const QEMUOption *lookup_opt(int argc, char 
**argv,
  return popt;
  }

+/* TEMP: until we have proper -machine support */
+static QemuOptDesc common_machine_opts[] = {
+{
+.name = "ram_size",
+.type = QEMU_OPT_NUMBER,
+},
+{
+.name = "kernel",
+.type = QEMU_OPT_STRING,
+},
+{
+.name = "cmdline",
+.type = QEMU_OPT_STRING,
+},
+{
+.name = "initrd",
+.type = QEMU_OPT_STRING,
+},
+{
+.name = "boot_device",
+.type = QEMU_OPT_STRING,
+},
+{
+.name = "cpu_model",
+.type = QEMU_OPT_STRING,
+},
+{ /* end of list */ },
+};
+
  int main(int argc, char **argv, char **envp)
  {
  const char *gdbstub_dev = NULL;
@@ -3718,8 +3747,42 @@ int main(int argc, char **argv, char **envp)
  }
  qemu_add_globals();

-machine->init(ram_size, boot_devices,
-  kernel_filename, kernel_cmdline, initrd_filename, cpu_model);
+opts = qemu_opts_create(&qemu_machine_opts, NULL, 0);
+if (kernel_filename) {
+qemu_opt_set(opts, "kernel", kernel_filename);
+if (kernel_cmdline) {
+qemu_opt_set(opts, "cmdline", kernel_cmdline);
+}
+if (initrd_filename) {
+qemu_opt_set(opts, "initrd", initrd_filename);
+}
+}
+
+qemu_opt_set(opts, "boot_device", boot_devices);
+
+if (cpu_model) {
+qemu_opt_set(opts, "cpu_model", cpu_model);
+}
+
+if (ram_size) {
+char buffer[64];
+snprintf(buffer, sizeof(buffer),
+ "%" PRId64, ram_size);
+qemu_opt_set(opts, "ram_size", buffer);
+}
+
+if (qemu_opts_validate(opts, common_machine_opts)<  0) {
+exit(1);
+}
+
+machine->init(qemu_opt_get_number(opts, "ram_size"),
+  qemu_opt_get(opts, "boot_device"),
+  qemu_opt_get(opts, "kernel"),
+  qemu_opt_get(opts, "cmdline"),
+  qemu_opt_get(opts, "initrd"),
+  qemu_opt_get(opts, "cpu_model"));
   


This should be "cpu".  I've updated and will hold off on a v2 for 
additional comments.


Regards,

Anthony Liguori


+
+qemu_opts_del(opts);

  cpu_synchronize_all_post_init();

   





[Qemu-devel] Re: [PATCH 1/2] [scsi-bus]: Add PR-OUT and PR-IN case for SCSIRequest xfer and xfer_mode setup

2010-06-04 Thread Kevin Wolf
Am 31.05.2010 03:43, schrieb Nicholas A. Bellinger:
> From: Nicholas Bellinger 
> 
> This patch updates hw/scsi-bus.c to add PERSISTENT_RESERVE_OUT and 
> PERSISTENT_RESERVE_IN
> case in scsi_req_length() to extra the incoming buffer length into 
> SCSIRequest->cmd.xfer,
> and adds a second PERSISTENT_RESERVE_OUT case in scsi_req_xfer_mode() in 
> order to properly
> set SCSI_XFER_TO_DEV for WRITE data.
> 
> Tested with Linux KVM guests and Megasas 8708EM2 HBA emulation and TCM_Loop 
> target ports.
> 
> Signed-off-by: Nicholas A. Bellinger 
> ---
>  hw/scsi-bus.c |5 +
>  1 files changed, 5 insertions(+), 0 deletions(-)
> 
> diff --git a/hw/scsi-bus.c b/hw/scsi-bus.c
> index b8e4b71..75ec74e 100644
> --- a/hw/scsi-bus.c
> +++ b/hw/scsi-bus.c
> @@ -325,6 +325,10 @@ static int scsi_req_length(SCSIRequest *req, uint8_t 
> *cmd)
>  case INQUIRY:
>  req->cmd.xfer = cmd[4] | (cmd[3] << 8);
>  break;
> +case PERSISTENT_RESERVE_OUT:
> +case PERSISTENT_RESERVE_IN:
> +req->cmd.xfer = cmd[8] | (cmd[7] << 8);

Maybe I'm missing something, but isn't exactly the same value set in the
switch block above? (for cmd[0] >> 5 == 2)

Kevin



[Qemu-devel] Re: RFC: blockdev_add & friends, brief rationale, QMP docs

2010-06-04 Thread Kevin Wolf
Am 04.06.2010 16:16, schrieb Markus Armbruster:
> Discussion with Christoph and Kevin uncovered yet another issue:
> protocols.  I find it pretty confusing, but let me try to describe it
> anyway; Christoph and Kevin, please correct my errors.
> 
> A host block device has a format.  A format has a name.
> 
> Below the format, it has a stack of protocols.  A protocol has a name
> (with one exception), and may have protocol-specific arguments.
> 
> The most basic (and most commonly used) protocol is for accessing a
> file.  Its argument is a file name.  It doesn't have a name.  Which
> makes for ugly prose, so I'll call it "file".

It does have a name, and surprisingly it's called "file" indeed (defined
at block/raw-posix.c:744 for Linux).

> Stacking protocols is somewhat exotic.  Think of stacking blkdebug on
> top of another protocol, say nbd.

Considering that file is a protocol as well as nbd, it's any blkdebug
use that uses protocol stacking and therefore not that exotic - even
though not the most common case, of course.

> Our abstraction for formats is struct BlockDriver.
> 
> Our abstraction for protocols is also struct BlockDriver.  Except for
> the special protocol "file", but that's detail.

See above, file isn't really special.

> 
> Examples:
> 
> -drive file=foo.qcow2,format=qcow2
> 
>  Format "qcow2", protocol "file" with argument filename "foo.img"

Actually the protocol is guessed here. For this, not all protocols are
considered, it's only between file/host_device/host_cdrom/host_floppy
(these are the protocols implementing bdrv_probe_device, and file as the
default if no other protocol feels responsible)

> -drive file=nbd:unix:/tmp/my_socket,format=raw
> 
>  Format "raw", protocol "nbd" with arguments domain "unix", filename
>  "/tmp/my_socket"
> 
> -drive blkdebug:/tmp/blkdebug.cfg:fat:floppy:rw:/tmp/dir
> 
>  Format not specified (system guesses one), protocol "blkdebug" with
>  argument filename "/tmp/blkdebug.cfg" stacked onto protocol "fat" with
>  arguments floppy true, dirname "/tmp/dir"

These look right to me.

> 
> You see that -drive has a separate option for format, but has protocols
> encoded in option file, in their own mini-language.  Doesn't work for
> arbitrary filenames.  Besides, mini-languages to encode options in
> strings are quite inappropriate for QMP.
> 
> So we need something cleaner for QMP.  Here's a sketch.  Instead of
> 
> - "file": the disk image file to use (json-string, optional)
> - "format": disk format (json-string, optional)
> - Possible values: "raw", "qcow2", ...
> 
> have
> 
> - "format": disk format (json-string, optional)
> - Possible values: "raw", "qcow2", ...
> - "protocol": json-array of json-object
>   Each element object has a member "name"
> - Possible values: "file", "nbd", ...
>   Additional members depend on the value of "name".
>   For "name" = "file":
> - "file": file name (json-string)
>   For "name" = "nbd":
> - "domain": address family (json-string, optional)
> - Possible values: "inet" (default), "unix"
> - "file": file name (json-string), only with "domain" = "unix"
> - "host": host name (json-string), only with "domain" = "inet"
> - "port": port (json-int), only with "domain" = "inet"
>   ...
> 
> You get the idea.
> 
> Comments?

Makes sense.

So blkdebug would define a field "protocol" (json-object) that it uses
to initialize the underlying protocol and we would get the stacking this
way?

Kevin



[Qemu-devel] Re: [PATCH 2/5] vnc: JPEG should be disabled if the client don't set tight quality

2010-06-04 Thread Corentin Chary
> Phew - I didn't even know of that option until now. I guess that's a bad 
> sign? :)
>
> One way I thought of it was to start being lossy as of quality level 6 or so. 
> That way people who accidently enable jpeg still know "high quality means 
> lossless". I'm not sure Anthony agrees on this though.
>
> Alex
>
>

If client set a quality it means that we are allowed to send something
lossy. If you don't want this behavior, you can add the lossless (or
lossy) parameter :).

-- 
Corentin Chary
http://xf.iksaif.net



[Qemu-devel] Re: [PATCH v3] savevm: Really verify if a drive supports snapshots

2010-06-04 Thread Kevin Wolf
Am 03.06.2010 21:52, schrieb Miguel Di Ciurcio Filho:
> Both bdrv_can_snapshot() and bdrv_has_snapshot() does not work as advertized.
> 
> First issue: Their names implies different porpouses, but they do the same 
> thing
> and have exactly the same code. Maybe copied and pasted and forgotten?
> bdrv_has_snapshot() is called in various places for actually checking if there
> is snapshots or not.
> 
> Second issue: the way bdrv_can_snapshot() verifies if a block driver supports 
> or
> not snapshots does not catch all cases. E.g.: a raw image.
> 
> So when do_savevm() is called, first thing it does is to set a global
> BlockDriverState to save the VM memory state calling get_bs_snapshots().
> 
> static BlockDriverState *get_bs_snapshots(void)
> {
> BlockDriverState *bs;
> DriveInfo *dinfo;
> 
> if (bs_snapshots)
> return bs_snapshots;
> QTAILQ_FOREACH(dinfo, &drives, next) {
> bs = dinfo->bdrv;
> if (bdrv_can_snapshot(bs))
> goto ok;
> }
> return NULL;
>  ok:
> bs_snapshots = bs;
> return bs;
> }
> 
> bdrv_can_snapshot() may return a BlockDriverState that does not support
> snapshots and do_savevm() goes on.
> 
> Later on in do_savevm(), we find:
> 
> QTAILQ_FOREACH(dinfo, &drives, next) {
> bs1 = dinfo->bdrv;
> if (bdrv_has_snapshot(bs1)) {
> /* Write VM state size only to the image that contains the state 
> */
> sn->vm_state_size = (bs == bs1 ? vm_state_size : 0);
> ret = bdrv_snapshot_create(bs1, sn);
> if (ret < 0) {
> monitor_printf(mon, "Error while creating snapshot on '%s'\n",
>bdrv_get_device_name(bs1));
> }
> }
> }
> 
> bdrv_has_snapshot(bs1) is not checking if the device does support or has
> snapshots as explained above. Only in bdrv_snapshot_create() the device is
> actually checked for snapshot support.
> 
> So, in cases where the first device supports snapshots, and the second does 
> not,
> the snapshot on the first will happen anyways. I believe this is not a good
> behavior. It should be an all or nothing process.
> 
> This patch addresses these issues by making bdrv_can_snapshot() actually do
> what it must do and enforces better tests to avoid errors in the middle of
> do_savevm(). bdrv_has_snapshot() is removed and replaced by 
> bdrv_can_snapshot()
> where appropriate.
> 
> bdrv_can_snapshot() was moved from savevm.c to block.c. It makes more sense 
> to me.
> 
> The loadvm_state() function was updated too to enforce that when loading a VM 
> at
> least all writable devices must support snapshots too.
> 
> Signed-off-by: Miguel Di Ciurcio Filho 

Thanks, applied to the block branch.

Kevin



[Qemu-devel] Re: [PATCH v2 2/2] vnc: threaded VNC server

2010-06-04 Thread Alexander Graf

On 04.06.2010, at 15:20, Corentin Chary wrote:

> Implement a threaded VNC server using the producer-consumer model.
> The main thread will push encoding jobs (a list a rectangles to update)
> in a queue, and the VNC worker thread will consume that queue and send
> framebuffer updates to the output buffer.

Hrm, does it merge the queue? So imagine the following gets put in the queue

[0,0] - [100,100]
[100,0] - [200,10]
[0,0] - [200,10]

Would that code try and merge those three queue entries? Because by adding the 
queue, you basically get rid of the automatic merging we get from the lazy 
dirty bitmap fetching.

Before we were processing each entry and checked the bitmap again, seeing a 
merged bitmap of previous actions. With this I assume you push to-be-updated 
regions into the queue and mark them as processed before they are? Or does the 
processed marking still happen in the worker? Wouldn't that be racy? Hrm.


Alex




[Qemu-devel] Re: [PATCH 4/5] ui: move all ui components in ui/

2010-06-04 Thread Corentin Chary
On Fri, Jun 4, 2010 at 3:18 PM, Alexander Graf  wrote:
>
> On 04.06.2010, at 15:18, Corentin Chary wrote:
>
>> Move sdl, vnc, curses and cocoa UI into ui/ to cleanup
>> the root directory. Also remove some unnecessary explicit
>> targets from Makefile.
>
> There's a magic command to tell git to indicate moves as moves. I guess 
> that'd be a good idea here :)
>
> Alex
>
>

Hum .. right.


-- 
Corentin Chary
http://xf.iksaif.net



[Qemu-devel] Re: [PATCH 2/5] vnc: JPEG should be disabled if the client don't set tight quality

2010-06-04 Thread Corentin Chary
>
> The tight quality level is a slider on most clients. A user doesn't know when 
> it starts being lossy. He also can only choose 0 as the lowest (iirc). And 
> IIRC the X tightvnc client also always sent the quality level.
>
> Alex
>
>

You can use -nojpeg for that. Most vnc clients have this options.

-- 
Corentin Chary
http://xf.iksaif.net



[Qemu-devel] [RFC] QMP: Introduce query-netdevices documentation

2010-06-04 Thread Miguel Di Ciurcio Filho
This introduces the protocol specification for querying information about
network devices available on a VM and a new monitor command that show the same
information.

Signed-off-by: Miguel Di Ciurcio Filho 
---
 qemu-monitor.hx |   69 +++
 1 files changed, 69 insertions(+), 0 deletions(-)

diff --git a/qemu-monitor.hx b/qemu-monitor.hx
index f6a94f2..8600129 100644
--- a/qemu-monitor.hx
+++ b/qemu-monitor.hx
@@ -1674,6 +1674,75 @@ show the various VLANs and the associated devices
 ETEXI
 
 STEXI
+...@item info netdevices
+show information about network devices
+ETEXI
+SQMP
+query-netdevices
+
+
+Each device is represented by a json-object. The returned value is a json-array
+of all devices.
+
+Each json-object contain the following:
+
+- "device": device name (json-string)
+- "vlan": only present if the device is attached to a VLAN (json-int)
+- "info": json-object containing the following:
+  - "model": type of the device (json-string)
+  - Possible values: "tap", "socket", "xen", "slirp", "dump",
+ "vde", "ne2k_pci", "i82551", "i82557b",
+ "i82559er", "rtl8139", "e1000", "pcnet",
+ "virtio", "dp83932", "lan9118", "mcf_fec",
+ "xilinx-ethlite", "lance", "stellaris",
+ "smc91c111", "ne2k_isa", "mv88w8618",
+ "mipsnet", "fseth", "dp83932", "usb"
+  - "macaddr": MAC address, only present if the device is a NIC
+(json-string)
+  - "script": path to script used to configure the device, only present
+if "model" is "tap" (json-string)
+  - "downscript": path to script used to deconfigure the device, only
+present if "model" is "tap" (json-string)
+  - "fd": handle to the device, only present if "model" is "vde"
+(json-int)
+  - "ifname": name of the host device connected to the guest device,
+only present if "model" is "tap" (json-string)
+  - "host": IP address, only present if "model" is "socket"
+(json-string)
+  - "service": port number, only present if "model" is "socket"
+  - "family": address familyi, only present if "model" is "socket"
+(json-string)
+- Possible values: "ipv4"
+
+Example:
+
+-> { "execute": "query-netdevices" }
+<- {
+  "return": [
+ {
+"device": "tap.0",
+"vlan": 0,
+"info": {
+   "script": "/etc/kvm/kvm-ifup",
+   "downscript": "/etc/qemu-ifdown",
+   "ifname": "tap0",
+   "model": "tap"
+},
+ },
+ {
+   "device": "e1000.0",
+   "vlan": 0,
+   "info": {
+  "model": "e1000",
+  "macaddr": "52:54:00:12:34:56"
+   },
+ }
+  ]
+   }
+
+EQMP
+
+STEXI
 @item info chardev
 show the character devices
 ETEXI
-- 
1.7.1




[Qemu-devel] [PATCH 1/2] machine: package all init arguments into a QemuOpts

2010-06-04 Thread Anthony Liguori
This patch creates a QemuOpts structure and stores all of the machine init
arguments in that structure.  It introduces a temporary list of QemuOptDescs
in vl.c such that the current common options can be validated.

The long term vision is that that list becomes a #define and that each machine
can optionally provide it's own QemuOptDescs list using the common options as
a base.  This enables per-machine options.

Signed-off-by: Anthony Liguori 

diff --git a/qemu-config.c b/qemu-config.c
index 5a4e61b..3679a9f 100644
--- a/qemu-config.c
+++ b/qemu-config.c
@@ -336,6 +336,14 @@ QemuOptsList qemu_cpudef_opts = {
 },
 };
 
+QemuOptsList qemu_machine_opts = {
+.name = "machine",
+.head = QTAILQ_HEAD_INITIALIZER(qemu_machine_opts.head),
+.desc = {
+{ /* end of list */ }
+},
+};
+
 static QemuOptsList *vm_config_groups[] = {
 &qemu_drive_opts,
 &qemu_chardev_opts,
@@ -346,6 +354,7 @@ static QemuOptsList *vm_config_groups[] = {
 &qemu_global_opts,
 &qemu_mon_opts,
 &qemu_cpudef_opts,
+&qemu_machine_opts,
 NULL,
 };
 
diff --git a/qemu-config.h b/qemu-config.h
index dca69d4..6f52188 100644
--- a/qemu-config.h
+++ b/qemu-config.h
@@ -14,6 +14,7 @@ extern QemuOptsList qemu_rtc_opts;
 extern QemuOptsList qemu_global_opts;
 extern QemuOptsList qemu_mon_opts;
 extern QemuOptsList qemu_cpudef_opts;
+extern QemuOptsList qemu_machine_opts;
 
 QemuOptsList *qemu_find_opts(const char *group);
 int qemu_set_option(const char *str);
diff --git a/vl.c b/vl.c
index 7121cd0..d362fc0 100644
--- a/vl.c
+++ b/vl.c
@@ -2550,6 +2550,35 @@ static const QEMUOption *lookup_opt(int argc, char 
**argv,
 return popt;
 }
 
+/* TEMP: until we have proper -machine support */
+static QemuOptDesc common_machine_opts[] = {
+{
+.name = "ram_size",
+.type = QEMU_OPT_NUMBER,
+},
+{
+.name = "kernel",
+.type = QEMU_OPT_STRING,
+},
+{
+.name = "cmdline",
+.type = QEMU_OPT_STRING,
+},
+{
+.name = "initrd",
+.type = QEMU_OPT_STRING,
+},
+{
+.name = "boot_device",
+.type = QEMU_OPT_STRING,
+},
+{
+.name = "cpu_model",
+.type = QEMU_OPT_STRING,
+},
+{ /* end of list */ },
+};
+
 int main(int argc, char **argv, char **envp)
 {
 const char *gdbstub_dev = NULL;
@@ -3718,8 +3747,42 @@ int main(int argc, char **argv, char **envp)
 }
 qemu_add_globals();
 
-machine->init(ram_size, boot_devices,
-  kernel_filename, kernel_cmdline, initrd_filename, cpu_model);
+opts = qemu_opts_create(&qemu_machine_opts, NULL, 0);
+if (kernel_filename) {
+qemu_opt_set(opts, "kernel", kernel_filename);
+if (kernel_cmdline) {
+qemu_opt_set(opts, "cmdline", kernel_cmdline);
+}
+if (initrd_filename) {
+qemu_opt_set(opts, "initrd", initrd_filename);
+}
+}
+
+qemu_opt_set(opts, "boot_device", boot_devices);
+
+if (cpu_model) {
+qemu_opt_set(opts, "cpu_model", cpu_model);
+}
+
+if (ram_size) {
+char buffer[64];
+snprintf(buffer, sizeof(buffer),
+ "%" PRId64, ram_size);
+qemu_opt_set(opts, "ram_size", buffer);
+}
+
+if (qemu_opts_validate(opts, common_machine_opts) < 0) {
+exit(1);
+}
+
+machine->init(qemu_opt_get_number(opts, "ram_size"),
+  qemu_opt_get(opts, "boot_device"),
+  qemu_opt_get(opts, "kernel"),
+  qemu_opt_get(opts, "cmdline"),
+  qemu_opt_get(opts, "initrd"),
+  qemu_opt_get(opts, "cpu_model"));
+
+qemu_opts_del(opts);
 
 cpu_synchronize_all_post_init();
 
-- 
1.7.0.4




[Qemu-devel] Re: RFC: blockdev_add & friends, brief rationale, QMP docs

2010-06-04 Thread Markus Armbruster
Discussion with Christoph and Kevin uncovered yet another issue:
protocols.  I find it pretty confusing, but let me try to describe it
anyway; Christoph and Kevin, please correct my errors.

A host block device has a format.  A format has a name.

Below the format, it has a stack of protocols.  A protocol has a name
(with one exception), and may have protocol-specific arguments.

The most basic (and most commonly used) protocol is for accessing a
file.  Its argument is a file name.  It doesn't have a name.  Which
makes for ugly prose, so I'll call it "file".

Stacking protocols is somewhat exotic.  Think of stacking blkdebug on
top of another protocol, say nbd.

Our abstraction for formats is struct BlockDriver.

Our abstraction for protocols is also struct BlockDriver.  Except for
the special protocol "file", but that's detail.

Examples:

-drive file=foo.qcow2,format=qcow2

 Format "qcow2", protocol "file" with argument filename "foo.img"

-drive file=nbd:unix:/tmp/my_socket,format=raw

 Format "raw", protocol "nbd" with arguments domain "unix", filename
 "/tmp/my_socket"

-drive blkdebug:/tmp/blkdebug.cfg:fat:floppy:rw:/tmp/dir

 Format not specified (system guesses one), protocol "blkdebug" with
 argument filename "/tmp/blkdebug.cfg" stacked onto protocol "fat" with
 arguments floppy true, dirname "/tmp/dir"

You see that -drive has a separate option for format, but has protocols
encoded in option file, in their own mini-language.  Doesn't work for
arbitrary filenames.  Besides, mini-languages to encode options in
strings are quite inappropriate for QMP.

So we need something cleaner for QMP.  Here's a sketch.  Instead of

- "file": the disk image file to use (json-string, optional)
- "format": disk format (json-string, optional)
- Possible values: "raw", "qcow2", ...

have

- "format": disk format (json-string, optional)
- Possible values: "raw", "qcow2", ...
- "protocol": json-array of json-object
  Each element object has a member "name"
- Possible values: "file", "nbd", ...
  Additional members depend on the value of "name".
  For "name" = "file":
- "file": file name (json-string)
  For "name" = "nbd":
- "domain": address family (json-string, optional)
- Possible values: "inet" (default), "unix"
- "file": file name (json-string), only with "domain" = "unix"
- "host": host name (json-string), only with "domain" = "inet"
- "port": port (json-int), only with "domain" = "inet"
  ...

You get the idea.

Comments?



[Qemu-devel] [PATCH] [V4] 9p: readdir implementation for 9p2000.L

2010-06-04 Thread Sripathi Kodi
This patch implements the kernel part of readdir() implementation for 9p2000.L

Change from V3: Instead of inode, server now sends qids for each dirent

SYNOPSIS

size[4] Treaddir tag[2] fid[4] offset[8] count[4]
size[4] Rreaddir tag[2] count[4] data[count]

DESCRIPTION

The readdir request asks the server to read the directory specified by 'fid'
at an offset specified by 'offset' and return as many dirent structures as
possible that fit into count bytes. Each dirent structure is laid out as
follows.

qid.type[1]
  the type of the file (directory, etc.), represented as a bit
  vector corresponding to the high 8 bits of the file's mode
  word.

qid.vers[4]
  version number for given path

qid.path[8]
  the file server's unique identification for the file

offset[8]
  offset into the next dirent.

type[1]
  type of this directory entry.

name[256]
  name of this directory entry.

This patch adds v9fs_dir_readdir_dotl() as the readdir() call for 9p2000.L.
This function sends P9_TREADDIR command to the server. In response the 
server
sends a buffer filled with dirent structures. This is different from the
existing v9fs_dir_readdir() call which receives stat structures from the 
server.
This results in significant speedup of readdir() on large directories.
For example, doing 'ls >/dev/null' on a directory with 1 files on my
laptop takes 1.088 seconds with the existing code, but only takes 0.339 
seconds
with the new readdir.

Signed-off-by: Sripathi Kodi 
Reviewed-by: Aneesh Kumar K.V 
---

 fs/9p/vfs_dir.c |  134 +--
 include/net/9p/9p.h |   17 ++
 include/net/9p/client.h |   18 ++
 net/9p/client.c |   47 
 net/9p/protocol.c   |   27 +
 5 files changed, 227 insertions(+), 16 deletions(-)

diff --git a/fs/9p/vfs_dir.c b/fs/9p/vfs_dir.c
index d61e3b2..aa1852d 100644
--- a/fs/9p/vfs_dir.c
+++ b/fs/9p/vfs_dir.c
@@ -87,29 +87,19 @@ static void p9stat_init(struct p9_wstat *stbuf)
 }
 
 /**
- * v9fs_dir_readdir - read a directory
+ * v9fs_alloc_rdir_buf - Allocate buffer used for read and readdir
  * @filp: opened file structure
- * @dirent: directory structure ???
- * @filldir: function to populate directory structure ???
+ * @buflen: Length in bytes of buffer to allocate
  *
  */
 
-static int v9fs_dir_readdir(struct file *filp, void *dirent, filldir_t filldir)
+static int v9fs_alloc_rdir_buf(struct file *filp, int buflen)
 {
-   int over;
-   struct p9_wstat st;
-   int err = 0;
-   struct p9_fid *fid;
-   int buflen;
-   int reclen = 0;
struct p9_rdir *rdir;
+   struct p9_fid *fid;
+   int err = 0;
 
-   P9_DPRINTK(P9_DEBUG_VFS, "name %s\n", filp->f_path.dentry->d_name.name);
fid = filp->private_data;
-
-   buflen = fid->clnt->msize - P9_IOHDRSZ;
-
-   /* allocate rdir on demand */
if (!fid->rdir) {
rdir = kmalloc(sizeof(struct p9_rdir) + buflen, GFP_KERNEL);
 
@@ -128,6 +118,36 @@ static int v9fs_dir_readdir(struct file *filp, void 
*dirent, filldir_t filldir)
spin_unlock(&filp->f_dentry->d_lock);
kfree(rdir);
}
+exit:
+   return err;
+}
+
+/**
+ * v9fs_dir_readdir - read a directory
+ * @filp: opened file structure
+ * @dirent: directory structure ???
+ * @filldir: function to populate directory structure ???
+ *
+ */
+
+static int v9fs_dir_readdir(struct file *filp, void *dirent, filldir_t filldir)
+{
+   int over;
+   struct p9_wstat st;
+   int err = 0;
+   struct p9_fid *fid;
+   int buflen;
+   int reclen = 0;
+   struct p9_rdir *rdir;
+
+   P9_DPRINTK(P9_DEBUG_VFS, "name %s\n", filp->f_path.dentry->d_name.name);
+   fid = filp->private_data;
+
+   buflen = fid->clnt->msize - P9_IOHDRSZ;
+
+   err = v9fs_alloc_rdir_buf(filp, buflen);
+   if (err)
+   goto exit;
rdir = (struct p9_rdir *) fid->rdir;
 
err = mutex_lock_interruptible(&rdir->mutex);
@@ -176,6 +196,88 @@ exit:
return err;
 }
 
+/**
+ * v9fs_dir_readdir_dotl - read a directory
+ * @filp: opened file structure
+ * @dirent: buffer to fill dirent structures
+ * @filldir: function to populate dirent structures
+ *
+ */
+static int v9fs_dir_readdir_dotl(struct file *filp, void *dirent,
+   filldir_t filldir)
+{
+   int over;
+   int err = 0;
+   struct p9_fid *fid;
+   int buflen;
+   struct p9_rdir *rdir;
+   struct p9_dirent curdirent;
+   u64 oldoffset = 0;
+
+   P9_DPRINTK(P9_DEBUG_VFS, "name %s\n", filp->f_path.dentry->d_name.name);
+   fid = filp->private_data;
+
+   buflen = fid->clnt->msize - P9_READDIRHDRSZ;
+

[Qemu-devel] [PATCH] [V4] virtio-9p: readdir implementation for 9p2000.L

2010-06-04 Thread Sripathi Kodi
This patch implements the server part of readdir() implementation for
9p2000.L

Change from V3: Instead of inode, server now sends qids for each dirent

SYNOPSIS

size[4] Treaddir tag[2] fid[4] offset[8] count[4]
size[4] Rreaddir tag[2] count[4] data[count]

DESCRIPTION

The readdir request asks the server to read the directory specified by 'fid'
at an offset specified by 'offset' and return as many dirent structures as
possible that fit into count bytes. Each dirent structure is laid out as
follows.

qid.type[1]
  the type of the file (directory, etc.), represented as a bit
  vector corresponding to the high 8 bits of the file's mode
  word.

qid.vers[4]
  version number for given path

qid.path[8]
  the file server's unique identification for the file

offset[8]
  offset into the next dirent.

type[1]
  type of this directory entry.

name[256]
  name of this directory entry.

Signed-off-by: Sripathi Kodi 
Reviewed-by: M. Mohan Kumar 
Reviewed-by: Venkateswararao Jujjuri 
---

 hw/virtio-9p-debug.c |   13 +
 hw/virtio-9p.c   |  119 ++
 hw/virtio-9p.h   |2 +
 3 files changed, 134 insertions(+), 0 deletions(-)

diff --git a/hw/virtio-9p-debug.c b/hw/virtio-9p-debug.c
index 2fb2673..a82b771 100644
--- a/hw/virtio-9p-debug.c
+++ b/hw/virtio-9p-debug.c
@@ -328,6 +328,19 @@ void pprint_pdu(V9fsPDU *pdu)
 }
 
 switch (pdu->id) {
+case P9_TREADDIR:
+fprintf(llogfile, "TREADDIR: (");
+pprint_int32(pdu, 0, &offset, "fid");
+pprint_int64(pdu, 0, &offset, ", initial offset");
+pprint_int32(pdu, 0, &offset, ", max count");
+break;
+case P9_RREADDIR:
+fprintf(llogfile, "RREADDIR: (");
+pprint_int32(pdu, 1, &offset, "count");
+#ifdef DEBUG_DATA
+pprint_data(pdu, 1, &offset, ", data");
+#endif
+break;
 case P9_TVERSION:
 fprintf(llogfile, "TVERSION: (");
 pprint_int32(pdu, 0, &offset, "msize");
diff --git a/hw/virtio-9p.c b/hw/virtio-9p.c
index 2d1cbd5..9c7e256 100644
--- a/hw/virtio-9p.c
+++ b/hw/virtio-9p.c
@@ -1583,6 +1583,124 @@ out:
 qemu_free(vs);
 }
 
+typedef struct V9fsReadDirState {
+V9fsPDU *pdu;
+V9fsFidState *fidp;
+V9fsQID qid;
+off_t saved_dir_pos;
+struct dirent *dent;
+int32_t count;
+int32_t max_count;
+size_t offset;
+int64_t initial_offset;
+V9fsString name;
+} V9fsReadDirState;
+
+static void v9fs_readdir_post_seekdir(V9fsState *s, V9fsReadDirState *vs)
+{
+vs->offset += pdu_marshal(vs->pdu, vs->offset, "d", vs->count);
+vs->offset += vs->count;
+complete_pdu(s, vs->pdu, vs->offset);
+qemu_free(vs);
+return;
+}
+
+/* Size of each dirent on the wire: size of qid (13) + size of offset (8)
+ * size of type (1) + size of name.size (2) + strlen(name.data)
+ */
+#define V9_READDIR_DATA_SZ (24 + strlen(vs->name.data))
+
+static void v9fs_readdir_post_readdir(V9fsState *s, V9fsReadDirState *vs)
+{
+int len;
+size_t size;
+
+if (vs->dent) {
+v9fs_string_init(&vs->name);
+v9fs_string_sprintf(&vs->name, "%s", vs->dent->d_name);
+
+if ((vs->count + V9_READDIR_DATA_SZ) > vs->max_count) {
+/* Ran out of buffer. Set dir back to old position and return */
+v9fs_do_seekdir(s, vs->fidp->dir, vs->saved_dir_pos);
+v9fs_readdir_post_seekdir(s, vs);
+return;
+}
+
+/* Fill up just the path field of qid because the client uses
+ * only that. To fill the entire qid structure we will have
+ * to stat each dirent found, which is expensive
+ */
+size = MIN(sizeof(vs->dent->d_ino), sizeof(vs->qid.path));
+memcpy(&vs->qid.path, &vs->dent->d_ino, size);
+
+len = pdu_marshal(vs->pdu, vs->offset+4+vs->count, "Qqbs",
+  &vs->qid, vs->dent->d_off,
+  vs->dent->d_type, &vs->name);
+vs->count += len;
+v9fs_string_free(&vs->name);
+vs->saved_dir_pos = vs->dent->d_off;
+vs->dent = v9fs_do_readdir(s, vs->fidp->dir);
+v9fs_readdir_post_readdir(s, vs);
+return;
+}
+
+vs->offset += pdu_marshal(vs->pdu, vs->offset, "d", vs->count);
+vs->offset += vs->count;
+complete_pdu(s, vs->pdu, vs->offset);
+qemu_free(vs);
+return;
+}
+
+static void v9fs_readdir_post_telldir(V9fsState *s, V9fsReadDirState *vs)
+{
+vs->dent = v9fs_do_readdir(s, vs->fidp->dir);
+v9fs_readdir_post_readdir(s, vs);
+return;
+}
+
+static void v9fs_readdir_post_setdir(V9fsState *s, V9fsReadDirState *vs)
+{
+vs->saved_dir_pos = v9fs_do_telldir(s, vs->fidp->dir);
+v9fs_readdir_post_telldir(s, vs);
+return;
+}
+
+static void v9fs_readdir(V9

[Qemu-devel] [PATCH 13/17] Move chroot handling to OS specific files.

2010-06-04 Thread Jes . Sorensen
From: Jes Sorensen 

Move chroot handling to OS specific files.

Signed-off-by: Jes Sorensen 
---
 os-posix.c  |   19 +++
 qemu-os-posix.h |1 +
 qemu-os-win32.h |1 +
 vl.c|   18 +-
 4 files changed, 22 insertions(+), 17 deletions(-)

diff --git a/os-posix.c b/os-posix.c
index 8b686a4..6417d16 100644
--- a/os-posix.c
+++ b/os-posix.c
@@ -38,6 +38,7 @@
 #include "qemu-options.h"
 
 static struct passwd *user_pwd;
+static const char *chroot_dir;
 
 void os_setup_early_signal_handling(void)
 {
@@ -156,6 +157,9 @@ void os_parse_cmd_args(int index, const char *optarg)
 exit(1);
 }
 break;
+case QEMU_OPTION_chroot:
+chroot_dir = optarg;
+break;
 }
 return;
 }
@@ -177,3 +181,18 @@ void os_change_process_uid(void)
 }
 }
 }
+
+void os_change_root(void)
+{
+if (chroot_dir) {
+if (chroot(chroot_dir) < 0) {
+fprintf(stderr, "chroot failed\n");
+exit(1);
+}
+if (chdir("/")) {
+perror("not able to chdir to /");
+exit(1);
+}
+}
+
+}
diff --git a/qemu-os-posix.h b/qemu-os-posix.h
index ecceb5e..ae9d5a8 100644
--- a/qemu-os-posix.h
+++ b/qemu-os-posix.h
@@ -33,5 +33,6 @@ static inline void os_host_main_loop_wait(int *timeout)
 void os_setup_early_signal_handling(void);
 void os_setup_signal_handling(void);
 void os_change_process_uid(void);
+void os_change_root(void);
 
 #endif
diff --git a/qemu-os-win32.h b/qemu-os-win32.h
index eff0242..3ce72cf 100644
--- a/qemu-os-win32.h
+++ b/qemu-os-win32.h
@@ -45,5 +45,6 @@ void os_host_main_loop_wait(int *timeout);
 
 static inline void os_setup_signal_handling(void) {}
 static inline void os_change_process_uid(void) {}
+static inline void os_change_root(void) {}
 
 #endif
diff --git a/vl.c b/vl.c
index 5fa4c79..fc0e23d 100644
--- a/vl.c
+++ b/vl.c
@@ -2309,7 +2309,6 @@ int main(int argc, char **argv, char **envp)
 const char *incoming = NULL;
 #ifndef _WIN32
 int fd = 0;
-const char *chroot_dir = NULL;
 #endif
 int show_vnc_port = 0;
 int defconfig = 1;
@@ -3053,11 +3052,6 @@ int main(int argc, char **argv, char **envp)
 default_cdrom = 0;
 default_sdcard = 0;
 break;
-#ifndef _WIN32
-case QEMU_OPTION_chroot:
-chroot_dir = optarg;
-break;
-#endif
 case QEMU_OPTION_xen_domid:
 if (!(xen_available())) {
 printf("Option %s not supported for this target\n", 
popt->name);
@@ -3546,17 +3540,7 @@ int main(int argc, char **argv, char **envp)
exit(1);
 }
 
-if (chroot_dir) {
-if (chroot(chroot_dir) < 0) {
-fprintf(stderr, "chroot failed\n");
-exit(1);
-}
-if (chdir("/")) {
-perror("not able to chdir to /");
-exit(1);
-}
-}
-
+os_change_root();
 os_change_process_uid();
 
 if (daemonize) {
-- 
1.6.5.2




[Qemu-devel] [PATCH 2/2] machine: pass all init options as a single QemuOpts

2010-06-04 Thread Anthony Liguori
The current method of passing arguments to machine init functions is haphazard.
We pass some arguments as via the init function.  We pass a lot of other
arguments as global variables some that are supported by a lot of boards and
others that are only supported by one board.  It's very difficult to introduce
new parameters in the function signature because of the number of files that
have to be touched.  There is no central way to tie all of the machine options
into the configuration file.

This patch redefines the machine init signature to just take a QemuOpts.  It
also passes the machine as the first parameter to allow multiple boards to be
defined with one init function.

Signed-off-by: Anthony Liguori 

diff --git a/hw/an5206.c b/hw/an5206.c
index f584d88..dfc4cce 100644
--- a/hw/an5206.c
+++ b/hw/an5206.c
@@ -29,11 +29,11 @@ void irq_info(Monitor *mon)
 
 /* Board init.  */
 
-static void an5206_init(ram_addr_t ram_size,
- const char *boot_device,
- const char *kernel_filename, const char *kernel_cmdline,
- const char *initrd_filename, const char *cpu_model)
+static void an5206_init(QEMUMachine *machine, QemuOpts *opts)
 {
+ram_addr_t ram_size = qemu_opt_get_number(opts, "ram_size", 0);
+const char *kernel_filename = qemu_opt_get(opts, "kernel");
+const char *cpu_model = qemu_opt_get(opts, "cpu");
 CPUState *env;
 int kernel_size;
 uint64_t elf_entry;
diff --git a/hw/axis_dev88.c b/hw/axis_dev88.c
index 7d59c96..c0ce621 100644
--- a/hw/axis_dev88.c
+++ b/hw/axis_dev88.c
@@ -264,11 +264,12 @@ static uint64_t translate_kernel_address(void *opaque, 
uint64_t addr)
 }
 
 static
-void axisdev88_init (ram_addr_t ram_size,
- const char *boot_device,
- const char *kernel_filename, const char *kernel_cmdline,
- const char *initrd_filename, const char *cpu_model)
+void axisdev88_init (QEMUMachine *machine, QemuOpts *opts)
 {
+ram_addr_t ram_size = qemu_opt_get_number(opts, "ram_size", 0);
+const char *kernel_filename = qemu_opt_get(opts, "kernel");
+const char *kernel_cmdline = qemu_opt_get(opts, "cmdline");
+const char *cpu_model = qemu_opt_get(opts, "cpu");
 CPUState *env;
 DeviceState *dev;
 SysBusDevice *s;
diff --git a/hw/boards.h b/hw/boards.h
index 6f0f0d7..59b0b4d 100644
--- a/hw/boards.h
+++ b/hw/boards.h
@@ -5,14 +5,11 @@
 
 #include "qdev.h"
 
-typedef void QEMUMachineInitFunc(ram_addr_t ram_size,
- const char *boot_device,
- const char *kernel_filename,
- const char *kernel_cmdline,
- const char *initrd_filename,
- const char *cpu_model);
-
-typedef struct QEMUMachine {
+typedef struct QEMUMachine QEMUMachine;
+
+typedef void QEMUMachineInitFunc(QEMUMachine *machine, QemuOpts *opts);
+
+struct QEMUMachine {
 const char *name;
 const char *alias;
 const char *desc;
@@ -29,7 +26,7 @@ typedef struct QEMUMachine {
 int is_default;
 GlobalProperty *compat_props;
 struct QEMUMachine *next;
-} QEMUMachine;
+};
 
 int qemu_register_machine(QEMUMachine *m);
 
diff --git a/hw/dummy_m68k.c b/hw/dummy_m68k.c
index 9c9e6ff..a249aa7 100644
--- a/hw/dummy_m68k.c
+++ b/hw/dummy_m68k.c
@@ -16,11 +16,11 @@
 
 /* Board init.  */
 
-static void dummy_m68k_init(ram_addr_t ram_size,
- const char *boot_device,
- const char *kernel_filename, const char *kernel_cmdline,
- const char *initrd_filename, const char *cpu_model)
+static void dummy_m68k_init(QEMUMachine *machine, QemuOpts *opts)
 {
+ram_addr_t ram_size = qemu_opt_get_number(opts, "ram_size", 0);
+const char *kernel_filename = qemu_opt_get(opts, "kernel");
+const char *cpu_model = qemu_opt_get(opts, "cpu");
 CPUState *env;
 int kernel_size;
 uint64_t elf_entry;
diff --git a/hw/etraxfs.c b/hw/etraxfs.c
index b88d00a..a9c5cf4 100644
--- a/hw/etraxfs.c
+++ b/hw/etraxfs.c
@@ -50,11 +50,12 @@ static uint64_t translate_kernel_address(void *opaque, 
uint64_t addr)
 }
 
 static
-void bareetraxfs_init (ram_addr_t ram_size,
-   const char *boot_device,
-   const char *kernel_filename, const char *kernel_cmdline,
-   const char *initrd_filename, const char *cpu_model)
+void bareetraxfs_init (QEMUMachine *machine, QemuOpts *opts)
 {
+ram_addr_t ram_size = qemu_opt_get_number(opts, "ram_size", 0);
+const char *kernel_filename = qemu_opt_get(opts, "kernel");
+const char *kernel_cmdline = qemu_opt_get(opts, "cmdline");
+const char *cpu_model = qemu_opt_get(opts, "cpu");
 DeviceState *dev;
 SysBusDevice *s;
 CPUState *env;
diff --git a/hw/gumstix.c b/hw/gumstix.c
index b64e04e..c85d690 100644
--- a/hw/gumstix.c
+++ b/hw/gumstix.c
@@ -41,10 +41,7 @@
 
 static const

[Qemu-devel] Re: [PATCH 00/17] *** SUBJECT HERE ***

2010-06-04 Thread Jes Sorensen
On 06/04/10 15:24, jes.soren...@redhat.com wrote:
> From: Jes Sorensen 
> 
> *** BLURB HERE ***
> 

ARGH, someone needs to learn about temp files  please ignore this one :(



[Qemu-devel] [PATCH 04/17] vl.c: Move host_main_loop_wait() to OS specific files.

2010-06-04 Thread Jes . Sorensen
From: Jes Sorensen 

Move host_main_loop_wait() to OS specific files. Create
qemu-os-posix.h and provide empty inline for the POSIX case.

Signed-off-by: Jes Sorensen 
---
 os-win32.c  |   43 +++
 qemu-os-posix.h |   33 +
 qemu-os-win32.h |1 +
 sysemu.h|4 
 vl.c|   52 +---
 5 files changed, 82 insertions(+), 51 deletions(-)
 create mode 100644 qemu-os-posix.h

diff --git a/os-win32.c b/os-win32.c
index 5a464cc..1f7e28b 100644
--- a/os-win32.c
+++ b/os-win32.c
@@ -109,3 +109,46 @@ void qemu_del_wait_object(HANDLE handle, WaitObjectFunc 
*func, void *opaque)
 if (found)
 w->num--;
 }
+
+void os_host_main_loop_wait(int *timeout)
+{
+int ret, ret2, i;
+PollingEntry *pe;
+
+/* XXX: need to suppress polling by better using win32 events */
+ret = 0;
+for(pe = first_polling_entry; pe != NULL; pe = pe->next) {
+ret |= pe->func(pe->opaque);
+}
+if (ret == 0) {
+int err;
+WaitObjects *w = &wait_objects;
+
+ret = WaitForMultipleObjects(w->num, w->events, FALSE, *timeout);
+if (WAIT_OBJECT_0 + 0 <= ret && ret <= WAIT_OBJECT_0 + w->num - 1) {
+if (w->func[ret - WAIT_OBJECT_0])
+w->func[ret - WAIT_OBJECT_0](w->opaque[ret - WAIT_OBJECT_0]);
+
+/* Check for additional signaled events */
+for(i = (ret - WAIT_OBJECT_0 + 1); i < w->num; i++) {
+
+/* Check if event is signaled */
+ret2 = WaitForSingleObject(w->events[i], 0);
+if(ret2 == WAIT_OBJECT_0) {
+if (w->func[i])
+w->func[i](w->opaque[i]);
+} else if (ret2 == WAIT_TIMEOUT) {
+} else {
+err = GetLastError();
+fprintf(stderr, "WaitForSingleObject error %d %d\n", i, 
err);
+}
+}
+} else if (ret == WAIT_TIMEOUT) {
+} else {
+err = GetLastError();
+fprintf(stderr, "WaitForMultipleObjects error %d %d\n", ret, err);
+}
+}
+
+*timeout = 0;
+}
diff --git a/qemu-os-posix.h b/qemu-os-posix.h
new file mode 100644
index 000..96d1036
--- /dev/null
+++ b/qemu-os-posix.h
@@ -0,0 +1,33 @@
+/*
+ * posix specific declarations
+ *
+ * Copyright (c) 2003-2008 Fabrice Bellard
+ * Copyright (c) 2010 Jes Sorensen 
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to 
deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
+ * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 
FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ * THE SOFTWARE.
+ */
+
+#ifndef QEMU_OS_POSIX_H
+#define QEMU_OS_POSIX_H
+
+static inline void os_host_main_loop_wait(int *timeout)
+{
+}
+
+#endif
diff --git a/qemu-os-win32.h b/qemu-os-win32.h
index be108ad..4d1cac8 100644
--- a/qemu-os-win32.h
+++ b/qemu-os-win32.h
@@ -40,4 +40,5 @@ typedef void WaitObjectFunc(void *opaque);
 int qemu_add_wait_object(HANDLE handle, WaitObjectFunc *func, void *opaque);
 void qemu_del_wait_object(HANDLE handle, WaitObjectFunc *func, void *opaque);
 
+void os_host_main_loop_wait(int *timeout);
 #endif
diff --git a/sysemu.h b/sysemu.h
index 13fc9a9..5e4feae 100644
--- a/sysemu.h
+++ b/sysemu.h
@@ -12,6 +12,10 @@
 #include "qemu-os-win32.h"
 #endif
 
+#ifdef CONFIG_POSIX
+#include "qemu-os-posix.h"
+#endif
+
 /* vl.c */
 extern const char *bios_name;
 
diff --git a/vl.c b/vl.c
index afbb26c..c655582 100644
--- a/vl.c
+++ b/vl.c
@@ -1722,56 +1722,6 @@ void qemu_system_powerdown_request(void)
 qemu_notify_event();
 }
 
-#ifdef _WIN32
-static void host_main_loop_wait(int *timeout)
-{
-int ret, ret2, i;
-PollingEntry *pe;
-
-
-/* XXX: need to suppress polling by better using win32 events */
-ret = 0;
-for(pe = first_polling_entry; pe != NULL; pe = pe->next) {
-ret |= pe->func(pe->opaque);
-}
-if (ret == 0) {
-int err;
-WaitObjects *w = &wait_objects;
-
-ret = WaitForMultipleObjects(w->num, w->events, FALSE

[Qemu-devel] [PATCH 09/17] Move find_datadir to OS specific files.

2010-06-04 Thread Jes . Sorensen
From: Jes Sorensen 

This moves the win32 and POSIX versions of find_datadir() to OS
specific files, and removes some #ifdef clutter from vl.c

Signed-off-by: Jes Sorensen 
---
 os-posix.c |   64 +++
 os-win32.c |   23 ++
 sysemu.h   |3 ++
 vl.c   |   98 ++-
 4 files changed, 94 insertions(+), 94 deletions(-)

diff --git a/os-posix.c b/os-posix.c
index 01dbec2..621ad06 100644
--- a/os-posix.c
+++ b/os-posix.c
@@ -28,6 +28,7 @@
 #include 
 #include 
 #include 
+#include 
 
 /* Needed early for CONFIG_BSD etc. */
 #include "config-host.h"
@@ -66,3 +67,66 @@ void os_setup_signal_handling(void)
 act.sa_flags = SA_NOCLDSTOP;
 sigaction(SIGCHLD, &act, NULL);
 }
+
+/* Find a likely location for support files using the location of the binary.
+   For installed binaries this will be "$bindir/../share/qemu".  When
+   running from the build tree this will be "$bindir/../pc-bios".  */
+#define SHARE_SUFFIX "/share/qemu"
+#define BUILD_SUFFIX "/pc-bios"
+char *os_find_datadir(const char *argv0)
+{
+char *dir;
+char *p = NULL;
+char *res;
+char buf[PATH_MAX];
+size_t max_len;
+
+#if defined(__linux__)
+{
+int len;
+len = readlink("/proc/self/exe", buf, sizeof(buf) - 1);
+if (len > 0) {
+buf[len] = 0;
+p = buf;
+}
+}
+#elif defined(__FreeBSD__)
+{
+static int mib[4] = {CTL_KERN, KERN_PROC, KERN_PROC_PATHNAME, -1};
+size_t len = sizeof(buf) - 1;
+
+*buf = '\0';
+if (!sysctl(mib, sizeof(mib)/sizeof(*mib), buf, &len, NULL, 0) &&
+*buf) {
+buf[sizeof(buf) - 1] = '\0';
+p = buf;
+}
+}
+#endif
+/* If we don't have any way of figuring out the actual executable
+   location then try argv[0].  */
+if (!p) {
+p = realpath(argv0, buf);
+if (!p) {
+return NULL;
+}
+}
+dir = dirname(p);
+dir = dirname(dir);
+
+max_len = strlen(dir) +
+MAX(strlen(SHARE_SUFFIX), strlen(BUILD_SUFFIX)) + 1;
+res = qemu_mallocz(max_len);
+snprintf(res, max_len, "%s%s", dir, SHARE_SUFFIX);
+if (access(res, R_OK)) {
+snprintf(res, max_len, "%s%s", dir, BUILD_SUFFIX);
+if (access(res, R_OK)) {
+qemu_free(res);
+res = NULL;
+}
+}
+
+return res;
+}
+#undef SHARE_SUFFIX
+#undef BUILD_SUFFIX
diff --git a/os-win32.c b/os-win32.c
index a936f7a..1758538 100644
--- a/os-win32.c
+++ b/os-win32.c
@@ -181,3 +181,26 @@ void os_setup_early_signal_handling(void)
 }
 }
 }
+
+/* Look for support files in the same directory as the executable.  */
+char *os_find_datadir(const char *argv0)
+{
+char *p;
+char buf[MAX_PATH];
+DWORD len;
+
+len = GetModuleFileName(NULL, buf, sizeof(buf) - 1);
+if (len == 0) {
+return NULL;
+}
+
+buf[len] = 0;
+p = buf + len - 1;
+while (p != buf && *p != '\\')
+p--;
+*p = 0;
+if (access(buf, R_OK) == 0) {
+return qemu_strdup(buf);
+}
+return NULL;
+}
diff --git a/sysemu.h b/sysemu.h
index 5e4feae..affcbea 100644
--- a/sysemu.h
+++ b/sysemu.h
@@ -79,6 +79,9 @@ int qemu_loadvm_state(QEMUFile *f);
 /* SLIRP */
 void do_info_slirp(Monitor *mon);
 
+/* OS specific functions */
+char *os_find_datadir(const char *argv0);
+
 typedef enum DisplayType
 {
 DT_DEFAULT,
diff --git a/vl.c b/vl.c
index fc5e8d8..7f22733 100644
--- a/vl.c
+++ b/vl.c
@@ -1986,95 +1986,6 @@ static int balloon_parse(const char *arg)
 return -1;
 }
 
-#ifdef _WIN32
-/* Look for support files in the same directory as the executable.  */
-static char *find_datadir(const char *argv0)
-{
-char *p;
-char buf[MAX_PATH];
-DWORD len;
-
-len = GetModuleFileName(NULL, buf, sizeof(buf) - 1);
-if (len == 0) {
-return NULL;
-}
-
-buf[len] = 0;
-p = buf + len - 1;
-while (p != buf && *p != '\\')
-p--;
-*p = 0;
-if (access(buf, R_OK) == 0) {
-return qemu_strdup(buf);
-}
-return NULL;
-}
-#else /* !_WIN32 */
-
-/* Find a likely location for support files using the location of the binary.
-   For installed binaries this will be "$bindir/../share/qemu".  When
-   running from the build tree this will be "$bindir/../pc-bios".  */
-#define SHARE_SUFFIX "/share/qemu"
-#define BUILD_SUFFIX "/pc-bios"
-static char *find_datadir(const char *argv0)
-{
-char *dir;
-char *p = NULL;
-char *res;
-char buf[PATH_MAX];
-size_t max_len;
-
-#if defined(__linux__)
-{
-int len;
-len = readlink("/proc/self/exe", buf, sizeof(buf) - 1);
-if (len > 0) {
-buf[len] = 0;
-p = buf;
-}
-}
-#elif defined(__FreeBSD__)
-{
-static int mib[4] = {CTL_KERN, KERN_PROC, KERN_PROC_PATHNAME, -1};
-size_t len = sizeof(buf) - 1;
-
-*buf = '\

[Qemu-devel] [PATCH v2 2/2] vnc: threaded VNC server

2010-06-04 Thread Corentin Chary
Implement a threaded VNC server using the producer-consumer model.
The main thread will push encoding jobs (a list a rectangles to update)
in a queue, and the VNC worker thread will consume that queue and send
framebuffer updates to the output buffer.

The threaded VNC server can be enabled with ./configure --enable-vnc-thread.

If you don't want it, just use ./configure --disable-vnc-thread and a 
syncrhonous
queue of job will be used (which as exactly the same behavior as the old queue).
If you disable the VNC thread, all thread related code will not be built and 
there will
be no overhead.

Signed-off-by: Corentin Chary 
---
 Makefile.objs  |7 +-
 configure  |   13 ++
 ui/vnc-jobs-sync.c |   65 ++
 ui/vnc-jobs.c  |  351 
 ui/vnc.c   |  169 ++
 ui/vnc.h   |   75 +++
 6 files changed, 657 insertions(+), 23 deletions(-)
 create mode 100644 ui/vnc-jobs-sync.c
 create mode 100644 ui/vnc-jobs.c

diff --git a/Makefile.objs b/Makefile.objs
index 22622a9..0c6334b 100644
--- a/Makefile.objs
+++ b/Makefile.objs
@@ -109,10 +109,15 @@ ui-obj-y += vnc-enc-tight.o
 ui-obj-$(CONFIG_VNC_TLS) += vnc-tls.o vnc-auth-vencrypt.o
 ui-obj-$(CONFIG_VNC_SASL) += vnc-auth-sasl.o
 ui-obj-$(CONFIG_COCOA) += cocoa.o
+ifdef CONFIG_VNC_THREAD
+ui-obj-y += vnc-jobs.o
+else
+ui-obj-y += vnc-jobs-sync.o
+endif
 common-obj-y += $(addprefix ui/, $(ui-obj-y))
 
 common-obj-y += iov.o acl.o
-common-obj-$(CONFIG_IOTHREAD) += qemu-thread.o
+common-obj-$(CONFIG_THREAD) += qemu-thread.o
 common-obj-y += notify.o event_notifier.o
 common-obj-y += qemu-timer.o
 
diff --git a/configure b/configure
index 679f2fc..6f2e3a7 100755
--- a/configure
+++ b/configure
@@ -264,6 +264,7 @@ vde=""
 vnc_tls=""
 vnc_sasl=""
 vnc_jpeg=""
+vnc_thread=""
 xen=""
 linux_aio=""
 vhost_net=""
@@ -552,6 +553,10 @@ for opt do
   ;;
   --enable-vnc-jpeg) vnc_jpeg="yes"
   ;;
+  --disable-vnc-thread) vnc_thread="no"
+  ;;
+  --enable-vnc-thread) vnc_thread="yes"
+  ;;
   --disable-slirp) slirp="no"
   ;;
   --disable-uuid) uuid="no"
@@ -786,6 +791,8 @@ echo "  --disable-vnc-sasl   disable SASL encryption 
for VNC server"
 echo "  --enable-vnc-saslenable SASL encryption for VNC server"
 echo "  --disable-vnc-jpeg   disable JPEG lossy compression for VNC server"
 echo "  --enable-vnc-jpegenable JPEG lossy compression for VNC server"
+echo "  --disable-vnc-thread disable threaded VNC server"
+echo "  --enable-vnc-thread  enable threaded VNC server"
 echo "  --disable-curses disable curses output"
 echo "  --enable-curses  enable curses output"
 echo "  --disable-curl   disable curl connectivity"
@@ -2048,6 +2055,7 @@ echo "Mixer emulation   $mixemu"
 echo "VNC TLS support   $vnc_tls"
 echo "VNC SASL support  $vnc_sasl"
 echo "VNC JPEG support  $vnc_jpeg"
+echo "VNC thread$vnc_thread"
 if test -n "$sparc_cpu"; then
 echo "Target Sparc Arch $sparc_cpu"
 fi
@@ -2191,6 +2199,10 @@ if test "$vnc_jpeg" = "yes" ; then
   echo "CONFIG_VNC_JPEG=y" >> $config_host_mak
   echo "VNC_JPEG_CFLAGS=$vnc_jpeg_cflags" >> $config_host_mak
 fi
+if test "$vnc_thread" = "yes" ; then
+  echo "CONFIG_VNC_THREAD=y" >> $config_host_mak
+  echo "CONFIG_THREAD=y" >> $config_host_mak
+fi
 if test "$fnmatch" = "yes" ; then
   echo "CONFIG_FNMATCH=y" >> $config_host_mak
 fi
@@ -2267,6 +2279,7 @@ if test "$xen" = "yes" ; then
 fi
 if test "$io_thread" = "yes" ; then
   echo "CONFIG_IOTHREAD=y" >> $config_host_mak
+  echo "CONFIG_THREAD=y" >> $config_host_mak
 fi
 if test "$linux_aio" = "yes" ; then
   echo "CONFIG_LINUX_AIO=y" >> $config_host_mak
diff --git a/ui/vnc-jobs-sync.c b/ui/vnc-jobs-sync.c
new file mode 100644
index 000..9f138f5
--- /dev/null
+++ b/ui/vnc-jobs-sync.c
@@ -0,0 +1,65 @@
+/*
+ * QEMU VNC display driver
+ *
+ * Copyright (C) 2006 Anthony Liguori 
+ * Copyright (C) 2006 Fabrice Bellard
+ * Copyright (C) 2009 Red Hat, Inc
+ * Copyright (C) 2010 Corentin Chary 
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to 
deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
+ * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTIO

[Qemu-devel] [PATCH] [V4] 9p: readdir implementation for 9p2000.L

2010-06-04 Thread Sripathi Kodi
This patch implements the kernel part of readdir() implementation for 9p2000.L

Change from V3: Instead of inode, server now sends qids for each dirent

SYNOPSIS

size[4] Treaddir tag[2] fid[4] offset[8] count[4]
size[4] Rreaddir tag[2] count[4] data[count]

DESCRIPTION

The readdir request asks the server to read the directory specified by 'fid'
at an offset specified by 'offset' and return as many dirent structures as
possible that fit into count bytes. Each dirent structure is laid out as
follows.

qid.type[1]
  the type of the file (directory, etc.), represented as a bit
  vector corresponding to the high 8 bits of the file's mode
  word.

qid.vers[4]
  version number for given path

qid.path[8]
  the file server's unique identification for the file

offset[8]
  offset into the next dirent.

type[1]
  type of this directory entry.

name[256]
  name of this directory entry.

This patch adds v9fs_dir_readdir_dotl() as the readdir() call for 9p2000.L.
This function sends P9_TREADDIR command to the server. In response the 
server
sends a buffer filled with dirent structures. This is different from the
existing v9fs_dir_readdir() call which receives stat structures from the 
server.
This results in significant speedup of readdir() on large directories.
For example, doing 'ls >/dev/null' on a directory with 1 files on my
laptop takes 1.088 seconds with the existing code, but only takes 0.339 
seconds
with the new readdir.

Signed-off-by: Sripathi Kodi 
Reviewed-by: Aneesh Kumar K.V 
---

 fs/9p/vfs_dir.c |  134 +--
 include/net/9p/9p.h |   17 ++
 include/net/9p/client.h |   18 ++
 net/9p/client.c |   47 
 net/9p/protocol.c   |   27 +
 5 files changed, 227 insertions(+), 16 deletions(-)

diff --git a/fs/9p/vfs_dir.c b/fs/9p/vfs_dir.c
index d61e3b2..aa1852d 100644
--- a/fs/9p/vfs_dir.c
+++ b/fs/9p/vfs_dir.c
@@ -87,29 +87,19 @@ static void p9stat_init(struct p9_wstat *stbuf)
 }
 
 /**
- * v9fs_dir_readdir - read a directory
+ * v9fs_alloc_rdir_buf - Allocate buffer used for read and readdir
  * @filp: opened file structure
- * @dirent: directory structure ???
- * @filldir: function to populate directory structure ???
+ * @buflen: Length in bytes of buffer to allocate
  *
  */
 
-static int v9fs_dir_readdir(struct file *filp, void *dirent, filldir_t filldir)
+static int v9fs_alloc_rdir_buf(struct file *filp, int buflen)
 {
-   int over;
-   struct p9_wstat st;
-   int err = 0;
-   struct p9_fid *fid;
-   int buflen;
-   int reclen = 0;
struct p9_rdir *rdir;
+   struct p9_fid *fid;
+   int err = 0;
 
-   P9_DPRINTK(P9_DEBUG_VFS, "name %s\n", filp->f_path.dentry->d_name.name);
fid = filp->private_data;
-
-   buflen = fid->clnt->msize - P9_IOHDRSZ;
-
-   /* allocate rdir on demand */
if (!fid->rdir) {
rdir = kmalloc(sizeof(struct p9_rdir) + buflen, GFP_KERNEL);
 
@@ -128,6 +118,36 @@ static int v9fs_dir_readdir(struct file *filp, void 
*dirent, filldir_t filldir)
spin_unlock(&filp->f_dentry->d_lock);
kfree(rdir);
}
+exit:
+   return err;
+}
+
+/**
+ * v9fs_dir_readdir - read a directory
+ * @filp: opened file structure
+ * @dirent: directory structure ???
+ * @filldir: function to populate directory structure ???
+ *
+ */
+
+static int v9fs_dir_readdir(struct file *filp, void *dirent, filldir_t filldir)
+{
+   int over;
+   struct p9_wstat st;
+   int err = 0;
+   struct p9_fid *fid;
+   int buflen;
+   int reclen = 0;
+   struct p9_rdir *rdir;
+
+   P9_DPRINTK(P9_DEBUG_VFS, "name %s\n", filp->f_path.dentry->d_name.name);
+   fid = filp->private_data;
+
+   buflen = fid->clnt->msize - P9_IOHDRSZ;
+
+   err = v9fs_alloc_rdir_buf(filp, buflen);
+   if (err)
+   goto exit;
rdir = (struct p9_rdir *) fid->rdir;
 
err = mutex_lock_interruptible(&rdir->mutex);
@@ -176,6 +196,88 @@ exit:
return err;
 }
 
+/**
+ * v9fs_dir_readdir_dotl - read a directory
+ * @filp: opened file structure
+ * @dirent: buffer to fill dirent structures
+ * @filldir: function to populate dirent structures
+ *
+ */
+static int v9fs_dir_readdir_dotl(struct file *filp, void *dirent,
+   filldir_t filldir)
+{
+   int over;
+   int err = 0;
+   struct p9_fid *fid;
+   int buflen;
+   struct p9_rdir *rdir;
+   struct p9_dirent curdirent;
+   u64 oldoffset = 0;
+
+   P9_DPRINTK(P9_DEBUG_VFS, "name %s\n", filp->f_path.dentry->d_name.name);
+   fid = filp->private_data;
+
+   buflen = fid->clnt->msize - P9_READDIRHDRSZ;
+

[Qemu-devel] [PATCH 17/17] Move set_proc_name() to OS specific files.

2010-06-04 Thread Jes . Sorensen
From: Jes Sorensen 

Move handling to change process name to POSIX specific files
plus add a better error message to cover the case where the
feature isn't supported.

Signed-off-by: Jes Sorensen 
---
 os-posix.c  |   24 
 qemu-os-posix.h |1 +
 qemu-os-win32.h |1 +
 vl.c|   19 +--
 4 files changed, 27 insertions(+), 18 deletions(-)

diff --git a/os-posix.c b/os-posix.c
index 9bae8fe..d89020d 100644
--- a/os-posix.c
+++ b/os-posix.c
@@ -37,6 +37,10 @@
 #include "net/slirp.h"
 #include "qemu-options.h"
 
+#ifdef CONFIG_LINUX
+#include 
+#endif
+
 static struct passwd *user_pwd;
 static const char *chroot_dir;
 static int daemonize;
@@ -139,6 +143,26 @@ char *os_find_datadir(const char *argv0)
 #undef SHARE_SUFFIX
 #undef BUILD_SUFFIX
 
+void os_set_proc_name(const char *s)
+{
+#if defined(PR_SET_NAME)
+char name[16];
+if (!s)
+return;
+name[sizeof(name) - 1] = 0;
+strncpy(name, s, sizeof(name));
+/* Could rewrite argv[0] too, but that's a bit more complicated.
+   This simple way is enough for `top'. */
+if (prctl(PR_SET_NAME, name)) {
+perror("unable to change process name");
+exit(1);
+}
+#else
+fprintf(stderr, "Change of process name not supported by your OS\n");
+exit(1);
+#endif 
+}
+
 /*
  * Parse OS specific command line options.
  * return 0 if option handled, -1 otherwise
diff --git a/qemu-os-posix.h b/qemu-os-posix.h
index 322fcbe..9387669 100644
--- a/qemu-os-posix.h
+++ b/qemu-os-posix.h
@@ -31,6 +31,7 @@ static inline void os_host_main_loop_wait(int *timeout)
 }
 
 void os_set_line_buffering(void);
+void os_set_proc_name(const char *s);
 void os_setup_early_signal_handling(void);
 void os_setup_signal_handling(void);
 void os_daemonize(void);
diff --git a/qemu-os-win32.h b/qemu-os-win32.h
index b65ddda..7fa79f2 100644
--- a/qemu-os-win32.h
+++ b/qemu-os-win32.h
@@ -48,5 +48,6 @@ static inline void os_daemonize(void) {}
 static inline void os_setup_post(void) {}
 /* Win32 doesn't support line-buffering and requires size >= 2 */
 static inline void os_set_line_buffering(void) {}
+static inline void os_set_proc_name(const char *dummy) {}
 
 #endif
diff --git a/vl.c b/vl.c
index c3641d6..ce501e2 100644
--- a/vl.c
+++ b/vl.c
@@ -59,7 +59,6 @@
 #ifdef __linux__
 #include 
 #include 
-#include 
 
 #include 
 #include 
@@ -284,22 +283,6 @@ static int default_driver_check(QemuOpts *opts, void 
*opaque)
 }
 
 /***/
-
-static void set_proc_name(const char *s)
-{
-#if defined(__linux__) && defined(PR_SET_NAME)
-char name[16];
-if (!s)
-return;
-name[sizeof(name) - 1] = 0;
-strncpy(name, s, sizeof(name));
-/* Could rewrite argv[0] too, but that's a bit more complicated.
-   This simple way is enough for `top'. */
-prctl(PR_SET_NAME, name);
-#endif 
-}
- 
-/***/
 /* real time host monotonic timer */
 
 /* compute with 96 bit intermediate result: (a*b)/c */
@@ -2988,7 +2971,7 @@ int main(int argc, char **argv, char **envp)
exit(1);
}
p += 8;
-   set_proc_name(p);
+   os_set_proc_name(p);
 }  
 }  
 break;
-- 
1.6.5.2




[Qemu-devel] [PATCH 06/17] Move win32 early signal handling setup to os_setup_signal_handling()

2010-06-04 Thread Jes . Sorensen
From: Jes Sorensen 

Move win32 early signal handling setup to os_setup_signal_handling()

Signed-off-by: Jes Sorensen 
---
 os-win32.c |   29 +
 vl.c   |   30 --
 2 files changed, 29 insertions(+), 30 deletions(-)

diff --git a/os-win32.c b/os-win32.c
index 1f7e28b..dfa90bc 100644
--- a/os-win32.c
+++ b/os-win32.c
@@ -152,3 +152,32 @@ void os_host_main_loop_wait(int *timeout)
 
 *timeout = 0;
 }
+
+static BOOL WINAPI qemu_ctrl_handler(DWORD type)
+{
+exit(STATUS_CONTROL_C_EXIT);
+return TRUE;
+}
+
+void os_setup_signal_handling(void)
+{
+/* Note: cpu_interrupt() is currently not SMP safe, so we force
+   QEMU to run on a single CPU */
+HANDLE h;
+DWORD mask, smask;
+int i;
+
+SetConsoleCtrlHandler(qemu_ctrl_handler, TRUE);
+
+h = GetCurrentProcess();
+if (GetProcessAffinityMask(h, &mask, &smask)) {
+for(i = 0; i < 32; i++) {
+if (mask & (1 << i))
+break;
+}
+if (i != 32) {
+mask = 1 << i;
+SetProcessAffinityMask(h, mask);
+}
+}
+}
diff --git a/vl.c b/vl.c
index 7a46fee..f43456a 100644
--- a/vl.c
+++ b/vl.c
@@ -1986,14 +1986,6 @@ static int balloon_parse(const char *arg)
 return -1;
 }
 
-#ifdef _WIN32
-static BOOL WINAPI qemu_ctrl_handler(DWORD type)
-{
-exit(STATUS_CONTROL_C_EXIT);
-return TRUE;
-}
-#endif
-
 #ifndef _WIN32
 
 static void termsig_handler(int signal)
@@ -2459,29 +2451,7 @@ int main(int argc, char **argv, char **envp)
 qemu_cache_utils_init(envp);
 
 QLIST_INIT (&vm_change_state_head);
-#ifndef _WIN32
 os_setup_signal_handling();
-#else
-SetConsoleCtrlHandler(qemu_ctrl_handler, TRUE);
-/* Note: cpu_interrupt() is currently not SMP safe, so we force
-   QEMU to run on a single CPU */
-{
-HANDLE h;
-DWORD mask, smask;
-int i;
-h = GetCurrentProcess();
-if (GetProcessAffinityMask(h, &mask, &smask)) {
-for(i = 0; i < 32; i++) {
-if (mask & (1 << i))
-break;
-}
-if (i != 32) {
-mask = 1 << i;
-SetProcessAffinityMask(h, mask);
-}
-}
-}
-#endif
 
 module_call_init(MODULE_INIT_MACHINE);
 machine = find_default_machine();
-- 
1.6.5.2




Re: [Qemu-devel] Re: [PATCH V3 1/3] qemu: Add qemu-wrappers for pthread_attr_t

2010-06-04 Thread Paolo Bonzini

On 06/04/2010 03:19 PM, Corentin Chary wrote:

The point of these wrappers AFAIU is not only to add error_exit, but also
to be portable to Windows in the future.


This is historical because the code was largely inspired by glibc's
implementation of posix-aio.  It doesn't need to be detached and since
Corentin wants to be able to join a worker, it makes sense to just avoid
detaching and pay the overhead of making the threads joinable.


Actually, I want to know if the queue is empty and if no job are
currently being processed: all worker are idle or stopped. I don't
really need pthread_join() for that, since worker can be idle (we
don't want to always start and stop the thread :) ).


Then it's also fine to have all qemu_threads detached (like in my patch 
to create all qemu_threads with blocked signals).  I just want to avoid 
implementing pthreads one day for qemu-threads-win32.c.


Paolo



[Qemu-devel] [PATCH 05/17] Introduce os-posix.c and create os_setup_signal_handling()

2010-06-04 Thread Jes . Sorensen
From: Jes Sorensen 

Introcuce os-posix.c and move posix specific signal handling
there. Add dummy stub for win32.

Signed-off-by: Jes Sorensen 
---
 Makefile.objs   |1 +
 os-posix.c  |   41 +
 qemu-os-posix.h |2 ++
 qemu-os-win32.h |1 +
 vl.c|8 +---
 5 files changed, 46 insertions(+), 7 deletions(-)
 create mode 100644 os-posix.c

diff --git a/Makefile.objs b/Makefile.objs
index 58fdb03..2d94677 100644
--- a/Makefile.objs
+++ b/Makefile.objs
@@ -145,6 +145,7 @@ hw-obj-$(CONFIG_NAND) += nand.o
 hw-obj-$(CONFIG_PFLASH_CFI01) += pflash_cfi01.o
 hw-obj-$(CONFIG_PFLASH_CFI02) += pflash_cfi02.o
 hw-obj-$(CONFIG_WIN32) += os-win32.o
+hw-obj-$(CONFIG_POSIX) += os-posix.o
 
 hw-obj-$(CONFIG_M48T59) += m48t59.o
 hw-obj-$(CONFIG_ESCC) += escc.o
diff --git a/os-posix.c b/os-posix.c
new file mode 100644
index 000..914a4d1
--- /dev/null
+++ b/os-posix.c
@@ -0,0 +1,41 @@
+/*
+ * os-posix.c
+ *
+ * Copyright (c) 2003-2008 Fabrice Bellard
+ * Copyright (c) 2010 Red Hat, Inc.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to 
deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
+ * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 
FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ * THE SOFTWARE.
+ */
+
+#include 
+#include 
+#include 
+
+/* Needed early for CONFIG_BSD etc. */
+#include "config-host.h"
+#include "sysemu.h"
+
+void os_setup_signal_handling(void)
+{
+struct sigaction act;
+sigfillset(&act.sa_mask);
+act.sa_flags = 0;
+act.sa_handler = SIG_IGN;
+sigaction(SIGPIPE, &act, NULL);
+}
diff --git a/qemu-os-posix.h b/qemu-os-posix.h
index 96d1036..ff5adb1 100644
--- a/qemu-os-posix.h
+++ b/qemu-os-posix.h
@@ -30,4 +30,6 @@ static inline void os_host_main_loop_wait(int *timeout)
 {
 }
 
+void os_setup_signal_handling(void);
+
 #endif
diff --git a/qemu-os-win32.h b/qemu-os-win32.h
index 4d1cac8..74c7b4d 100644
--- a/qemu-os-win32.h
+++ b/qemu-os-win32.h
@@ -40,5 +40,6 @@ typedef void WaitObjectFunc(void *opaque);
 int qemu_add_wait_object(HANDLE handle, WaitObjectFunc *func, void *opaque);
 void qemu_del_wait_object(HANDLE handle, WaitObjectFunc *func, void *opaque);
 
+static inline void os_setup_signal_handling(void) {}
 void os_host_main_loop_wait(int *timeout);
 #endif
diff --git a/vl.c b/vl.c
index c655582..7a46fee 100644
--- a/vl.c
+++ b/vl.c
@@ -2460,13 +2460,7 @@ int main(int argc, char **argv, char **envp)
 
 QLIST_INIT (&vm_change_state_head);
 #ifndef _WIN32
-{
-struct sigaction act;
-sigfillset(&act.sa_mask);
-act.sa_flags = 0;
-act.sa_handler = SIG_IGN;
-sigaction(SIGPIPE, &act, NULL);
-}
+os_setup_signal_handling();
 #else
 SetConsoleCtrlHandler(qemu_ctrl_handler, TRUE);
 /* Note: cpu_interrupt() is currently not SMP safe, so we force
-- 
1.6.5.2




[Qemu-devel] [PATCH 12/17] Move runas handling from vl.c to OS specific files.

2010-06-04 Thread Jes . Sorensen
From: Jes Sorensen 

Move code to handle runas, ie. change of user id of QEMU process
to OS specific files and provide dummy stub for Win32.

Signed-off-by: Jes Sorensen 
---
 os-posix.c  |   28 
 qemu-os-posix.h |1 +
 qemu-os-win32.h |1 +
 vl.c|   29 +
 4 files changed, 31 insertions(+), 28 deletions(-)

diff --git a/os-posix.c b/os-posix.c
index 0deddf3..8b686a4 100644
--- a/os-posix.c
+++ b/os-posix.c
@@ -28,6 +28,7 @@
 #include 
 #include 
 #include 
+#include 
 #include 
 
 /* Needed early for CONFIG_BSD etc. */
@@ -36,6 +37,8 @@
 #include "net/slirp.h"
 #include "qemu-options.h"
 
+static struct passwd *user_pwd;
+
 void os_setup_early_signal_handling(void)
 {
 struct sigaction act;
@@ -146,6 +149,31 @@ void os_parse_cmd_args(int index, const char *optarg)
 exit(1);
 break;
 #endif
+case QEMU_OPTION_runas:
+user_pwd = getpwnam(optarg);
+if (!user_pwd) {
+fprintf(stderr, "User \"%s\" doesn't exist\n", optarg);
+exit(1);
+}
+break;
 }
 return;
 }
+
+void os_change_process_uid(void)
+{
+if (user_pwd) {
+if (setgid(user_pwd->pw_gid) < 0) {
+fprintf(stderr, "Failed to setgid(%d)\n", user_pwd->pw_gid);
+exit(1);
+}
+if (setuid(user_pwd->pw_uid) < 0) {
+fprintf(stderr, "Failed to setuid(%d)\n", user_pwd->pw_uid);
+exit(1);
+}
+if (setuid(0) != -1) {
+fprintf(stderr, "Dropping privileges failed\n");
+exit(1);
+}
+}
+}
diff --git a/qemu-os-posix.h b/qemu-os-posix.h
index 41a4360..ecceb5e 100644
--- a/qemu-os-posix.h
+++ b/qemu-os-posix.h
@@ -32,5 +32,6 @@ static inline void os_host_main_loop_wait(int *timeout)
 
 void os_setup_early_signal_handling(void);
 void os_setup_signal_handling(void);
+void os_change_process_uid(void);
 
 #endif
diff --git a/qemu-os-win32.h b/qemu-os-win32.h
index ee30ea9..eff0242 100644
--- a/qemu-os-win32.h
+++ b/qemu-os-win32.h
@@ -44,5 +44,6 @@ static inline void os_setup_early_signal_handling(void) {}
 void os_host_main_loop_wait(int *timeout);
 
 static inline void os_setup_signal_handling(void) {}
+static inline void os_change_process_uid(void) {}
 
 #endif
diff --git a/vl.c b/vl.c
index 7c48024..5fa4c79 100644
--- a/vl.c
+++ b/vl.c
@@ -34,7 +34,6 @@
 
 #ifndef _WIN32
 #include 
-#include 
 #include 
 #include 
 #include 
@@ -2310,9 +2309,7 @@ int main(int argc, char **argv, char **envp)
 const char *incoming = NULL;
 #ifndef _WIN32
 int fd = 0;
-struct passwd *pwd = NULL;
 const char *chroot_dir = NULL;
-const char *run_as = NULL;
 #endif
 int show_vnc_port = 0;
 int defconfig = 1;
@@ -3060,9 +3057,6 @@ int main(int argc, char **argv, char **envp)
 case QEMU_OPTION_chroot:
 chroot_dir = optarg;
 break;
-case QEMU_OPTION_runas:
-run_as = optarg;
-break;
 #endif
 case QEMU_OPTION_xen_domid:
 if (!(xen_available())) {
@@ -3552,14 +3546,6 @@ int main(int argc, char **argv, char **envp)
exit(1);
 }
 
-if (run_as) {
-pwd = getpwnam(run_as);
-if (!pwd) {
-fprintf(stderr, "User \"%s\" doesn't exist\n", run_as);
-exit(1);
-}
-}
-
 if (chroot_dir) {
 if (chroot(chroot_dir) < 0) {
 fprintf(stderr, "chroot failed\n");
@@ -3571,20 +3557,7 @@ int main(int argc, char **argv, char **envp)
 }
 }
 
-if (run_as) {
-if (setgid(pwd->pw_gid) < 0) {
-fprintf(stderr, "Failed to setgid(%d)\n", pwd->pw_gid);
-exit(1);
-}
-if (setuid(pwd->pw_uid) < 0) {
-fprintf(stderr, "Failed to setuid(%d)\n", pwd->pw_uid);
-exit(1);
-}
-if (setuid(0) != -1) {
-fprintf(stderr, "Dropping privileges failed\n");
-exit(1);
-}
-}
+os_change_process_uid();
 
 if (daemonize) {
 dup2(fd, 0);
-- 
1.6.5.2




[Qemu-devel] Re: [PATCH] Fix and simplify gui timer logic.

2010-06-04 Thread Gerd Hoffmann

On 06/04/10 15:44, Gerd Hoffmann wrote:

Kill nographic timer.  Have a global gui_timer instead.  Have the gui
timer enabled unconditionally.  We need a timer running anyway for mmio
flush, so the whole have-gui-timer-only-when-needed logic is pretty
pointless.  It also simplifies displaylisteners coming and going at
runtime, we don't need to care about the timer then as it runs anyway.


Oops, scratch that.  Doesn't apply cleanly on master due to dependencies 
on other local patches.


/me goes preparing a patch series ...

cheers,
  Gerd




[Qemu-devel] Re: [PATCH 2/5] vnc: JPEG should be disabled if the client don't set tight quality

2010-06-04 Thread Alexander Graf

On 04.06.2010, at 15:48, Corentin Chary wrote:

>> 
>> The tight quality level is a slider on most clients. A user doesn't know 
>> when it starts being lossy. He also can only choose 0 as the lowest (iirc). 
>> And IIRC the X tightvnc client also always sent the quality level.
>> 
>> Alex
>> 
>> 
> 
> You can use -nojpeg for that. Most vnc clients have this options.

Phew - I didn't even know of that option until now. I guess that's a bad sign? 
:)

One way I thought of it was to start being lossy as of quality level 6 or so. 
That way people who accidently enable jpeg still know "high quality means 
lossless". I'm not sure Anthony agrees on this though.

Alex




[Qemu-devel] [PATCH 16/17] Move line-buffering setup to OS specific files.

2010-06-04 Thread Jes . Sorensen
From: Jes Sorensen 

Move line-buffering setup to OS specific files.

Signed-off-by: Jes Sorensen 
---
 os-posix.c  |5 +
 qemu-os-posix.h |1 +
 qemu-os-win32.h |2 ++
 vl.c|5 +
 4 files changed, 9 insertions(+), 4 deletions(-)

diff --git a/os-posix.c b/os-posix.c
index 3a96c91..9bae8fe 100644
--- a/os-posix.c
+++ b/os-posix.c
@@ -298,3 +298,8 @@ void os_pidfile_error(void)
 } else
 fprintf(stderr, "Could not acquire pid file: %s\n", strerror(errno));
 }
+
+void os_set_line_buffering(void)
+{
+setvbuf(stdout, NULL, _IOLBF, 0);
+}
diff --git a/qemu-os-posix.h b/qemu-os-posix.h
index a791a36..322fcbe 100644
--- a/qemu-os-posix.h
+++ b/qemu-os-posix.h
@@ -30,6 +30,7 @@ static inline void os_host_main_loop_wait(int *timeout)
 {
 }
 
+void os_set_line_buffering(void);
 void os_setup_early_signal_handling(void);
 void os_setup_signal_handling(void);
 void os_daemonize(void);
diff --git a/qemu-os-win32.h b/qemu-os-win32.h
index 0a263c4..b65ddda 100644
--- a/qemu-os-win32.h
+++ b/qemu-os-win32.h
@@ -46,5 +46,7 @@ void os_host_main_loop_wait(int *timeout);
 static inline void os_setup_signal_handling(void) {}
 static inline void os_daemonize(void) {}
 static inline void os_setup_post(void) {}
+/* Win32 doesn't support line-buffering and requires size >= 2 */
+static inline void os_set_line_buffering(void) {}
 
 #endif
diff --git a/vl.c b/vl.c
index c22d16f..c3641d6 100644
--- a/vl.c
+++ b/vl.c
@@ -3214,10 +3214,7 @@ int main(int argc, char **argv, char **envp)
 exit(1);
 }
 
-#ifndef _WIN32
-/* Win32 doesn't support line-buffering and requires size >= 2 */
-setvbuf(stdout, NULL, _IOLBF, 0);
-#endif
+os_set_line_buffering();
 
 if (init_timer_alarm() < 0) {
 fprintf(stderr, "could not initialize alarm timer\n");
-- 
1.6.5.2




[Qemu-devel] [PATCH 15/17] Make os_change_process_uid and os_change_root os-posix.c local

2010-06-04 Thread Jes . Sorensen
From: Jes Sorensen 

os_change_process_uid() and os_change_root() are now only called
from os-posix.c, so no need to keep win32 stubs for them.

Signed-off-by: Jes Sorensen 
---
 os-posix.c  |8 
 qemu-os-posix.h |2 --
 qemu-os-win32.h |2 --
 3 files changed, 4 insertions(+), 8 deletions(-)

diff --git a/os-posix.c b/os-posix.c
index 1672e06..3a96c91 100644
--- a/os-posix.c
+++ b/os-posix.c
@@ -169,7 +169,7 @@ void os_parse_cmd_args(int index, const char *optarg)
 return;
 }
 
-void os_change_process_uid(void)
+static void change_process_uid(void)
 {
 if (user_pwd) {
 if (setgid(user_pwd->pw_gid) < 0) {
@@ -187,7 +187,7 @@ void os_change_process_uid(void)
 }
 }
 
-void os_change_root(void)
+static void change_root(void)
 {
 if (chroot_dir) {
 if (chroot(chroot_dir) < 0) {
@@ -276,8 +276,8 @@ void os_setup_post(void)
exit(1);
 }
 
-os_change_root();
-os_change_process_uid();
+change_root();
+change_process_uid();
 
 if (daemonize) {
 dup2(fd, 0);
diff --git a/qemu-os-posix.h b/qemu-os-posix.h
index 96a1831..a791a36 100644
--- a/qemu-os-posix.h
+++ b/qemu-os-posix.h
@@ -32,8 +32,6 @@ static inline void os_host_main_loop_wait(int *timeout)
 
 void os_setup_early_signal_handling(void);
 void os_setup_signal_handling(void);
-void os_change_process_uid(void);
-void os_change_root(void);
 void os_daemonize(void);
 void os_setup_post(void);
 
diff --git a/qemu-os-win32.h b/qemu-os-win32.h
index 0e712d4..0a263c4 100644
--- a/qemu-os-win32.h
+++ b/qemu-os-win32.h
@@ -44,8 +44,6 @@ static inline void os_setup_early_signal_handling(void) {}
 void os_host_main_loop_wait(int *timeout);
 
 static inline void os_setup_signal_handling(void) {}
-static inline void os_change_process_uid(void) {}
-static inline void os_change_root(void) {}
 static inline void os_daemonize(void) {}
 static inline void os_setup_post(void) {}
 
-- 
1.6.5.2




[Qemu-devel] [PATCH 14/17] Move daemonize handling to OS specific files

2010-06-04 Thread Jes . Sorensen
From: Jes Sorensen 

Move daemonize handling from vl.c to OS specific files. Provide dummy
stubs for Win32.

Signed-off-by: Jes Sorensen 
---
 os-posix.c  |  102 
 os-win32.c  |5 +++
 qemu-os-posix.h |2 +
 qemu-os-win32.h |2 +
 sysemu.h|1 +
 vl.c|  106 ++-
 6 files changed, 115 insertions(+), 103 deletions(-)

diff --git a/os-posix.c b/os-posix.c
index 6417d16..1672e06 100644
--- a/os-posix.c
+++ b/os-posix.c
@@ -39,6 +39,8 @@
 
 static struct passwd *user_pwd;
 static const char *chroot_dir;
+static int daemonize;
+static int fds[2];
 
 void os_setup_early_signal_handling(void)
 {
@@ -160,6 +162,9 @@ void os_parse_cmd_args(int index, const char *optarg)
 case QEMU_OPTION_chroot:
 chroot_dir = optarg;
 break;
+case QEMU_OPTION_daemonize:
+daemonize = 1;
+break;
 }
 return;
 }
@@ -196,3 +201,100 @@ void os_change_root(void)
 }
 
 }
+
+void os_daemonize(void)
+{
+if (daemonize) {
+   pid_t pid;
+
+   if (pipe(fds) == -1)
+   exit(1);
+
+   pid = fork();
+   if (pid > 0) {
+   uint8_t status;
+   ssize_t len;
+
+   close(fds[1]);
+
+   again:
+len = read(fds[0], &status, 1);
+if (len == -1 && (errno == EINTR))
+goto again;
+
+if (len != 1)
+exit(1);
+else if (status == 1) {
+fprintf(stderr, "Could not acquire pidfile: %s\n", 
strerror(errno));
+exit(1);
+} else
+exit(0);
+   } else if (pid < 0)
+exit(1);
+
+   close(fds[0]);
+   qemu_set_cloexec(fds[1]);
+
+   setsid();
+
+   pid = fork();
+   if (pid > 0)
+   exit(0);
+   else if (pid < 0)
+   exit(1);
+
+   umask(027);
+
+signal(SIGTSTP, SIG_IGN);
+signal(SIGTTOU, SIG_IGN);
+signal(SIGTTIN, SIG_IGN);
+}
+}
+
+void os_setup_post(void)
+{
+int fd = 0;
+
+if (daemonize) {
+   uint8_t status = 0;
+   ssize_t len;
+
+again1:
+   len = write(fds[1], &status, 1);
+   if (len == -1 && (errno == EINTR))
+   goto again1;
+
+   if (len != 1)
+   exit(1);
+
+if (chdir("/")) {
+perror("not able to chdir to /");
+exit(1);
+}
+   TFR(fd = qemu_open("/dev/null", O_RDWR));
+   if (fd == -1)
+   exit(1);
+}
+
+os_change_root();
+os_change_process_uid();
+
+if (daemonize) {
+dup2(fd, 0);
+dup2(fd, 1);
+dup2(fd, 2);
+
+close(fd);
+}
+}
+
+void os_pidfile_error(void)
+{
+if (daemonize) {
+uint8_t status = 1;
+if (write(fds[1], &status, 1) != 1) {
+perror("daemonize. Writing to pipe\n");
+}
+} else
+fprintf(stderr, "Could not acquire pid file: %s\n", strerror(errno));
+}
diff --git a/os-win32.c b/os-win32.c
index aefc535..d98fd77 100644
--- a/os-win32.c
+++ b/os-win32.c
@@ -214,3 +214,8 @@ void os_parse_cmd_args(int index, const char *optarg)
 {
 return;
 }
+
+void os_pidfile_error(void)
+{
+fprintf(stderr, "Could not acquire pid file: %s\n", strerror(errno));
+}
diff --git a/qemu-os-posix.h b/qemu-os-posix.h
index ae9d5a8..96a1831 100644
--- a/qemu-os-posix.h
+++ b/qemu-os-posix.h
@@ -34,5 +34,7 @@ void os_setup_early_signal_handling(void);
 void os_setup_signal_handling(void);
 void os_change_process_uid(void);
 void os_change_root(void);
+void os_daemonize(void);
+void os_setup_post(void);
 
 #endif
diff --git a/qemu-os-win32.h b/qemu-os-win32.h
index 3ce72cf..0e712d4 100644
--- a/qemu-os-win32.h
+++ b/qemu-os-win32.h
@@ -46,5 +46,7 @@ void os_host_main_loop_wait(int *timeout);
 static inline void os_setup_signal_handling(void) {}
 static inline void os_change_process_uid(void) {}
 static inline void os_change_root(void) {}
+static inline void os_daemonize(void) {}
+static inline void os_setup_post(void) {}
 
 #endif
diff --git a/sysemu.h b/sysemu.h
index d7aab40..a93572c 100644
--- a/sysemu.h
+++ b/sysemu.h
@@ -82,6 +82,7 @@ void do_info_slirp(Monitor *mon);
 /* OS specific functions */
 char *os_find_datadir(const char *argv0);
 void os_parse_cmd_args(int index, const char *optarg);
+void os_pidfile_error(void);
 
 typedef enum DisplayType
 {
diff --git a/vl.c b/vl.c
index fc0e23d..c22d16f 100644
--- a/vl.c
+++ b/vl.c
@@ -216,9 +216,6 @@ int no_shutdown = 0;
 int cursor_hide = 1;
 int graphic_rotate = 0;
 uint8_t irq0override = 1;
-#ifndef _WIN32
-int daemonize = 0;
-#endif
 const char *watchdog;
 const char *option_rom[MAX_OPTION_ROMS];
 int nb_option_roms;
@@ -2301,15 +2298,9 @@ int main(int argc, char **argv, char **envp)
 const char *loadvm = NULL;
 QEMUMachine *machine;
 const char *cpu_model;
-#ifndef _WIN32
-int fds[2];
-#endif
 int tb_size;
 const char *pi

[Qemu-devel] [PATCH 10/17] Rename qemu-options.h to qemu-options.def

2010-06-04 Thread Jes . Sorensen
From: Jes Sorensen 

Rename qemu-options.h to qemu-options.def as it is not a header file
for general use and this leaves space for a proper qemu-options.h

Signed-off-by: Jes Sorensen 
---
 Makefile.objs |4 ++--
 vl.c  |6 +++---
 2 files changed, 5 insertions(+), 5 deletions(-)

diff --git a/Makefile.objs b/Makefile.objs
index 2d94677..124afe7 100644
--- a/Makefile.objs
+++ b/Makefile.objs
@@ -258,8 +258,8 @@ vl.o: QEMU_CFLAGS+=$(GPROF_CFLAGS)
 
 vl.o: QEMU_CFLAGS+=$(SDL_CFLAGS)
 
-vl.o: qemu-options.h
+vl.o: qemu-options.def
 
-qemu-options.h: $(SRC_PATH)/qemu-options.hx
+qemu-options.def: $(SRC_PATH)/qemu-options.hx
$(call quiet-command,sh $(SRC_PATH)/hxtool -h < $< > $@,"  GEN   
$(TARGET_DIR)$@")
 
diff --git a/vl.c b/vl.c
index 7f22733..8cd0f8f 100644
--- a/vl.c
+++ b/vl.c
@@ -1875,7 +1875,7 @@ static void help(int exitcode)
 #define DEF(option, opt_arg, opt_enum, opt_help, arch_mask) \
 opt_help
 #define DEFHEADING(text) stringify(text) "\n"
-#include "qemu-options.h"
+#include "qemu-options.def"
 #undef DEF
 #undef DEFHEADING
 #undef GEN_DOCS
@@ -1903,7 +1903,7 @@ enum {
 #define DEF(option, opt_arg, opt_enum, opt_help, arch_mask) \
 opt_enum,
 #define DEFHEADING(text)
-#include "qemu-options.h"
+#include "qemu-options.def"
 #undef DEF
 #undef DEFHEADING
 #undef GEN_DOCS
@@ -1921,7 +1921,7 @@ static const QEMUOption qemu_options[] = {
 #define DEF(option, opt_arg, opt_enum, opt_help, arch_mask) \
 { option, opt_arg, opt_enum, arch_mask },
 #define DEFHEADING(text)
-#include "qemu-options.h"
+#include "qemu-options.def"
 #undef DEF
 #undef DEFHEADING
 #undef GEN_DOCS
-- 
1.6.5.2




[Qemu-devel] [PATCH 00/17] *** SUBJECT HERE ***

2010-06-04 Thread Jes . Sorensen
From: Jes Sorensen 

*** BLURB HERE ***

Jes Sorensen (17):
  vl.c: Remove double include of netinet/in.h for Solaris
  Create qemu-os-win32.h and move WIN32 specific declarations there
  Introduce os-win32.c and move polling functions from vl.c
  vl.c: Move host_main_loop_wait() to OS specific files.
  Introduce os-posix.c and create os_setup_signal_handling()
  Move win32 early signal handling setup to os_setup_signal_handling()
  Rename os_setup_signal_handling() to os_setup_early_signal_handling()
  Move main signal handler setup to os specificfiles.
  Move find_datadir to OS specific files.
  Rename qemu-options.h to qemu-options.def
  Introduce OS specific cmdline argument handling and move SMB arg to
os-posix.c
  Move runas handling from vl.c to OS specific files.
  Move chroot handling to OS specific files.
  Move daemonize handling to OS specific files
  Make os_change_process_uid and os_change_root os-posix.c local
  Move line-buffering setup to OS specific files.
  Move set_proc_name() to OS specific files.

 Makefile.objs   |8 +-
 os-posix.c  |  329 
 os-win32.c  |  221 
 qemu-os-posix.h |   40 +
 qemu-os-win32.h |   53 ++
 sysemu.h|   26 +--
 vl.c|  498 ++-
 7 files changed, 676 insertions(+), 499 deletions(-)
 create mode 100644 os-posix.c
 create mode 100644 os-win32.c
 create mode 100644 qemu-os-posix.h
 create mode 100644 qemu-os-win32.h




[Qemu-devel] [PATCH 08/17] Move main signal handler setup to os specificfiles.

2010-06-04 Thread Jes . Sorensen
From: Jes Sorensen 

Move main signal handler setup to os specific files.

Signed-off-by: Jes Sorensen 
---
 os-posix.c  |   27 +++
 qemu-os-posix.h |1 +
 qemu-os-win32.h |3 +++
 vl.c|   33 +
 4 files changed, 32 insertions(+), 32 deletions(-)

diff --git a/os-posix.c b/os-posix.c
index 948f662..01dbec2 100644
--- a/os-posix.c
+++ b/os-posix.c
@@ -26,6 +26,8 @@
 #include 
 #include 
 #include 
+#include 
+#include 
 
 /* Needed early for CONFIG_BSD etc. */
 #include "config-host.h"
@@ -39,3 +41,28 @@ void os_setup_early_signal_handling(void)
 act.sa_handler = SIG_IGN;
 sigaction(SIGPIPE, &act, NULL);
 }
+
+static void termsig_handler(int signal)
+{
+qemu_system_shutdown_request();
+}
+
+static void sigchld_handler(int signal)
+{
+waitpid(-1, NULL, WNOHANG);
+}
+
+void os_setup_signal_handling(void)
+{
+struct sigaction act;
+
+memset(&act, 0, sizeof(act));
+act.sa_handler = termsig_handler;
+sigaction(SIGINT,  &act, NULL);
+sigaction(SIGHUP,  &act, NULL);
+sigaction(SIGTERM, &act, NULL);
+
+act.sa_handler = sigchld_handler;
+act.sa_flags = SA_NOCLDSTOP;
+sigaction(SIGCHLD, &act, NULL);
+}
diff --git a/qemu-os-posix.h b/qemu-os-posix.h
index 2f54d40..41a4360 100644
--- a/qemu-os-posix.h
+++ b/qemu-os-posix.h
@@ -31,5 +31,6 @@ static inline void os_host_main_loop_wait(int *timeout)
 }
 
 void os_setup_early_signal_handling(void);
+void os_setup_signal_handling(void);
 
 #endif
diff --git a/qemu-os-win32.h b/qemu-os-win32.h
index 65e3a9d..ee30ea9 100644
--- a/qemu-os-win32.h
+++ b/qemu-os-win32.h
@@ -42,4 +42,7 @@ void qemu_del_wait_object(HANDLE handle, WaitObjectFunc 
*func, void *opaque);
 
 static inline void os_setup_early_signal_handling(void) {}
 void os_host_main_loop_wait(int *timeout);
+
+static inline void os_setup_signal_handling(void) {}
+
 #endif
diff --git a/vl.c b/vl.c
index 372f931..fc5e8d8 100644
--- a/vl.c
+++ b/vl.c
@@ -1986,35 +1986,6 @@ static int balloon_parse(const char *arg)
 return -1;
 }
 
-#ifndef _WIN32
-
-static void termsig_handler(int signal)
-{
-qemu_system_shutdown_request();
-}
-
-static void sigchld_handler(int signal)
-{
-waitpid(-1, NULL, WNOHANG);
-}
-
-static void sighandler_setup(void)
-{
-struct sigaction act;
-
-memset(&act, 0, sizeof(act));
-act.sa_handler = termsig_handler;
-sigaction(SIGINT,  &act, NULL);
-sigaction(SIGHUP,  &act, NULL);
-sigaction(SIGTERM, &act, NULL);
-
-act.sa_handler = sigchld_handler;
-act.sa_flags = SA_NOCLDSTOP;
-sigaction(SIGCHLD, &act, NULL);
-}
-
-#endif
-
 #ifdef _WIN32
 /* Look for support files in the same directory as the executable.  */
 static char *find_datadir(const char *argv0)
@@ -3556,10 +3527,8 @@ int main(int argc, char **argv, char **envp)
 
 cpu_synchronize_all_post_init();
 
-#ifndef _WIN32
 /* must be after terminal init, SDL library changes signal handlers */
-sighandler_setup();
-#endif
+os_setup_signal_handling();
 
 set_numa_modes();
 
-- 
1.6.5.2




<    1   2   3   >