Re: [Qemu-devel] [PATCH] virtio-9p: fix QEMU build break

2011-10-11 Thread Zhi Yong Wu
On Tue, Oct 11, 2011 at 12:49 AM, Aneesh Kumar K.V
aneesh.ku...@linux.vnet.ibm.com wrote:
 On Mon, 10 Oct 2011 22:05:21 +0530, Aneesh Kumar K.V 
 aneesh.ku...@linux.vnet.ibm.com wrote:
 On Mon, 10 Oct 2011 18:30:28 +0800, Zhi Yong Wu wu...@linux.vnet.ibm.com 
 wrote:
  qemu build break due to the redefinition of struct file_handle. My 
  qemu.git/HEAD is 8acbc9b21d757a6be4f8492e547b8159703a0547
 
  Below is the log:
  [root@f15 qemu]# make
    CC    qapi-generated/qga-qapi-types.o
    LINK  qemu-ga
    CC    libhw64/9pfs/virtio-9p-handle.o
  /home/zwu/work/virt/qemu/hw/9pfs/virtio-9p-handle.c:31:8: error: 
  redefinition of struct file_handle
  /usr/include/bits/fcntl.h:254:8: note: originally defined here
  make[1]: *** [9pfs/virtio-9p-handle.o] Error 1
  make: *** [subdir-libhw64] Error 2
 
  [root@f15 qemu]# rpm -qf /usr/include/bits/fcntl.h
  glibc-headers-2.13.90-9.x86_64
 

 Is this a backported glibc ? On my ubuntu system glibc 2.13 doesn't
 provide struct file_handle. I also checked glib repo at
 http://repo.or.cz/w/glibc.git. The commit introducing struct file_handle
 is

 $ git describe --contains 158648c0bdda281e252a27c0200dd0ea6f4e0215
 glibc-2.14~200



 How about the below patch. This means that handle driver will only work
 with latest glibc. Even if i have latest kernel, with an older glibc
 handle fs driver backed will be disabled.

 diff --git a/configure b/configure
 index 24b8df4..0216c53 100755
 --- a/configure
 +++ b/configure
 @@ -2551,6 +2551,18 @@ EOF
  fi

  ##
 +# check if we have open_by_handle_at
 +
 +open_by_hande_at=no
 +cat  $TMPC  EOF
 +#include fcntl.h
 +int main(void) { struct file_handle *fh; open_by_handle_at(0, fh, 0); }
 +EOF
 +if compile_prog   ; then
 +    open_by_handle_at=yes
 +fi
 +
 +##
  # End of CC checks
  # After here, no more $cc or $ld runs

 @@ -3029,6 +3041,10 @@ if test $ucontext_coroutine = yes ; then
   echo CONFIG_UCONTEXT_COROUTINE=y  $config_host_mak
  fi

 +if test $open_by_handle_at = yes ; then
 +  echo CONFIG_OPEN_BY_HANDLE=y  $config_host_mak
 +fi
 +
  # USB host support
  case $usb in
  linux)
 diff --git a/hw/9pfs/virtio-9p-handle.c b/hw/9pfs/virtio-9p-handle.c
 index 68e1d9b..bd73d31 100644
 --- a/hw/9pfs/virtio-9p-handle.c
 +++ b/hw/9pfs/virtio-9p-handle.c
 @@ -30,13 +30,24 @@ struct handle_data {
     int handle_bytes;
  };

 -#if __GLIBC__ = 2  __GLIBC_MINOR__  14
 +#ifdef CONFIG_OPEN_BY_HANDLE
 +static inline int name_to_handle(int dirfd, const char *name,
 +                                 struct file_handle *fh, int *mnt_id, int 
 flags)
 +{
 +    return name_to_handle_at(dirfd, name, fh, mnt_id, flags);
 +}
 +
 +static inline int open_by_handle(int mountfd, const char *fh, int flags)
 +{
 +    return open_by_handle_at(mountfd, fh, flags);
 +}
 +#else
 +
  struct file_handle {
 -        unsigned int handle_bytes;
 -        int handle_type;
 -        unsigned char handle[0];
 +    unsigned int handle_bytes;
 +    int handle_type;
 +    unsigned char handle[0];
  };
 -#endif

  #ifndef AT_EMPTY_PATH
  #define AT_EMPTY_PATH   0x1000  /* Allow empty relative pathname */
 @@ -45,28 +56,6 @@ struct file_handle {
  #define O_PATH    01000
  #endif

 -#ifndef __NR_name_to_handle_at
 -#if defined(__i386__)
 -#define __NR_name_to_handle_at  341
 -#define __NR_open_by_handle_at  342
 -#elif defined(__x86_64__)
 -#define __NR_name_to_handle_at  303
 -#define __NR_open_by_handle_at  304
 -#endif
 -#endif
 -
 -#ifdef __NR_name_to_handle_at
 -static inline int name_to_handle(int dirfd, const char *name,
 -                                 struct file_handle *fh, int *mnt_id, int 
 flags)
 -{
 -    return syscall(__NR_name_to_handle_at, dirfd, name, fh, mnt_id, flags);
 -}
 -
 -static inline int open_by_handle(int mountfd, const char *fh, int flags)
 -{
 -    return syscall(__NR_open_by_handle_at, mountfd, fh, flags);
 -}
 -#else
  static inline int name_to_handle(int dirfd, const char *name,
                                  struct file_handle *fh, int *mnt_id, int 
 flags)
  {

It doesn't work for me.

  CClibhw64/9pfs/virtio-9p-handle.o
/home/zwu/work/virt/qemu/hw/9pfs/virtio-9p-handle.c: In function
\u2018open_by_handle\u2019:
/home/zwu/work/virt/qemu/hw/9pfs/virtio-9p-handle.c:39:5: error:
passing argument 2 of \u2018open_by_handle_at\u2019 from incompatible
pointer type [-Werror]
/usr/include/bits/fcntl.h:335:12: note: expected \u2018struct
file_handle *\u2019 but argument is of type \u2018const char *\u2019
/home/zwu/work/virt/qemu/hw/9pfs/virtio-9p-handle.c: At top level:
/home/zwu/work/virt/qemu/hw/9pfs/virtio-9p-handle.c:30:0: error:
unterminated #else
cc1: all warnings being treated as errors

make[1]: *** [9pfs/virtio-9p-handle.o] Error 1
make: *** [subdir-libhw64] Error 2


-- 
Regards,

Zhi Yong Wu



Re: [Qemu-devel] [PATCH 3/6] block: switch bdrv_read()/bdrv_write() to coroutines

2011-10-11 Thread Zhi Yong Wu
On Thu, Oct 6, 2011 at 12:17 AM, Stefan Hajnoczi
stefa...@linux.vnet.ibm.com wrote:
 The bdrv_read()/bdrv_write() functions call .bdrv_read()/.bdrv_write().
 They should go through bdrv_co_do_readv() and bdrv_co_do_writev()
 instead in order to unify request processing code across sync, aio, and
 coroutine interfaces.  This is also an important step towards removing
 BlockDriverState .bdrv_read()/.bdrv_write() in the future.

 Signed-off-by: Stefan Hajnoczi stefa...@linux.vnet.ibm.com
 ---
  block.c |  112 
 +++
  1 files changed, 62 insertions(+), 50 deletions(-)

 diff --git a/block.c b/block.c
 index d15784e..90c29db 100644
 --- a/block.c
 +++ b/block.c
 @@ -44,6 +44,8 @@
  #include windows.h
  #endif

 +#define NOT_DONE 0x7fff /* used while emulated sync operation in 
 progress */
 +
  static void bdrv_dev_change_media_cb(BlockDriverState *bs, bool load);
  static BlockDriverAIOCB *bdrv_aio_readv_em(BlockDriverState *bs,
         int64_t sector_num, QEMUIOVector *qiov, int nb_sectors,
 @@ -74,6 +76,8 @@ static int coroutine_fn bdrv_co_writev_em(BlockDriverState 
 *bs,
  static int coroutine_fn bdrv_co_flush_em(BlockDriverState *bs);
  static int coroutine_fn bdrv_co_do_readv(BlockDriverState *bs,
     int64_t sector_num, int nb_sectors, QEMUIOVector *qiov);
 +static int coroutine_fn bdrv_co_do_writev(BlockDriverState *bs,
 +    int64_t sector_num, int nb_sectors, QEMUIOVector *qiov);

  static QTAILQ_HEAD(, BlockDriverState) bdrv_states =
     QTAILQ_HEAD_INITIALIZER(bdrv_states);
 @@ -1038,30 +1042,69 @@ static inline bool bdrv_has_async_flush(BlockDriver 
 *drv)
     return drv-bdrv_aio_flush != bdrv_aio_flush_em;
  }

 -/* return  0 if error. See bdrv_write() for the return codes */
 -int bdrv_read(BlockDriverState *bs, int64_t sector_num,
 -              uint8_t *buf, int nb_sectors)
 +typedef struct RwCo {
 +    BlockDriverState *bs;
 +    int64_t sector_num;
 +    int nb_sectors;
 +    QEMUIOVector *qiov;
 +    bool is_write;
 +    int ret;
 +} RwCo;
 +
 +static void coroutine_fn bdrv_rw_co_entry(void *opaque)
  {
 -    BlockDriver *drv = bs-drv;
 +    RwCo *rwco = opaque;

 -    if (!drv)
 -        return -ENOMEDIUM;
 +    if (!rwco-is_write) {
 +        rwco-ret = bdrv_co_do_readv(rwco-bs, rwco-sector_num,
 +                                     rwco-nb_sectors, rwco-qiov);
 +    } else {
 +        rwco-ret = bdrv_co_do_writev(rwco-bs, rwco-sector_num,
 +                                      rwco-nb_sectors, rwco-qiov);
 +    }
 +}

 -    if (bdrv_has_async_rw(drv)  qemu_in_coroutine()) {
 -        QEMUIOVector qiov;
 -        struct iovec iov = {
 -            .iov_base = (void *)buf,
 -            .iov_len = nb_sectors * BDRV_SECTOR_SIZE,
 -        };
 +/*
 + * Process a synchronous request using coroutines
 + */
 +static int bdrv_rw_co(BlockDriverState *bs, int64_t sector_num, uint8_t *buf,
 +                      int nb_sectors, bool is_write)
 +{
 +    QEMUIOVector qiov;
 +    struct iovec iov = {
 +        .iov_base = (void *)buf,
 +        .iov_len = nb_sectors * BDRV_SECTOR_SIZE,
 +    };
 +    Coroutine *co;
 +    RwCo rwco = {
 +        .bs = bs,
 +        .sector_num = sector_num,
 +        .nb_sectors = nb_sectors,
 +        .qiov = qiov,
 +        .is_write = is_write,
 +        .ret = NOT_DONE,
 +    };

 -        qemu_iovec_init_external(qiov, iov, 1);
 -        return bdrv_co_readv(bs, sector_num, nb_sectors, qiov);
 -    }
 +    qemu_iovec_init_external(qiov, iov, 1);

 -    if (bdrv_check_request(bs, sector_num, nb_sectors))
 -        return -EIO;
 +    if (qemu_in_coroutine()) {
 +        /* Fast-path if already in coroutine context */
 +        bdrv_rw_co_entry(rwco);
 +    } else {
 +        co = qemu_coroutine_create(bdrv_rw_co_entry);
 +        qemu_coroutine_enter(co, rwco);
 +        while (rwco.ret == NOT_DONE) {
 +            qemu_aio_wait();
 +        }
 +    }
 +    return rwco.ret;
 +}

 -    return drv-bdrv_read(bs, sector_num, buf, nb_sectors);
 +/* return  0 if error. See bdrv_write() for the return codes */
 +int bdrv_read(BlockDriverState *bs, int64_t sector_num,
 +              uint8_t *buf, int nb_sectors)
 +{
 +    return bdrv_rw_co(bs, sector_num, buf, nb_sectors, false);
  }

  static void set_dirty_bitmap(BlockDriverState *bs, int64_t sector_num,
 @@ -1101,36 +1144,7 @@ static void set_dirty_bitmap(BlockDriverState *bs, 
 int64_t sector_num,
  int bdrv_write(BlockDriverState *bs, int64_t sector_num,
                const uint8_t *buf, int nb_sectors)
  {
 -    BlockDriver *drv = bs-drv;
 -
 -    if (!bs-drv)
 -        return -ENOMEDIUM;
 -
 -    if (bdrv_has_async_rw(drv)  qemu_in_coroutine()) {
 -        QEMUIOVector qiov;
 -        struct iovec iov = {
 -            .iov_base = (void *)buf,
 -            .iov_len = nb_sectors * BDRV_SECTOR_SIZE,
 -        };
 -
 -        qemu_iovec_init_external(qiov, iov, 1);
 -        return bdrv_co_writev(bs, sector_num, nb_sectors, qiov);
 -    }
 -
 - 

Re: [Qemu-devel] [PATCH 6/6] block: switch bdrv_aio_writev() to coroutines

2011-10-11 Thread Zhi Yong Wu
On Thu, Oct 6, 2011 at 12:17 AM, Stefan Hajnoczi
stefa...@linux.vnet.ibm.com wrote:
 More sync, aio, and coroutine unification.  Make bdrv_aio_writev() go
 through coroutine request processing.

 Remove the dirty block callback mechanism which was needed only for aio
 processing and can be done more naturally in coroutine context.

 Signed-off-by: Stefan Hajnoczi stefa...@linux.vnet.ibm.com
 ---
  block.c |   66 +-
  1 files changed, 2 insertions(+), 64 deletions(-)

 diff --git a/block.c b/block.c
 index 5d6e17f..e80121b 100644
 --- a/block.c
 +++ b/block.c
 @@ -2364,76 +2364,14 @@ BlockDriverAIOCB *bdrv_aio_readv(BlockDriverState 
 *bs, int64_t sector_num,
                                  cb, opaque, false, bdrv_co_do_rw);
  }

 -typedef struct BlockCompleteData {
 -    BlockDriverCompletionFunc *cb;
 -    void *opaque;
 -    BlockDriverState *bs;
 -    int64_t sector_num;
 -    int nb_sectors;
 -} BlockCompleteData;
 -
 -static void block_complete_cb(void *opaque, int ret)
 -{
 -    BlockCompleteData *b = opaque;
 -
 -    if (b-bs-dirty_bitmap) {
 -        set_dirty_bitmap(b-bs, b-sector_num, b-nb_sectors, 1);
 -    }
 -    b-cb(b-opaque, ret);
 -    g_free(b);
 -}
 -
 -static BlockCompleteData *blk_dirty_cb_alloc(BlockDriverState *bs,
 -                                             int64_t sector_num,
 -                                             int nb_sectors,
 -                                             BlockDriverCompletionFunc *cb,
 -                                             void *opaque)
 -{
 -    BlockCompleteData *blkdata = g_malloc0(sizeof(BlockCompleteData));
 -
 -    blkdata-bs = bs;
 -    blkdata-cb = cb;
 -    blkdata-opaque = opaque;
 -    blkdata-sector_num = sector_num;
 -    blkdata-nb_sectors = nb_sectors;
 -
 -    return blkdata;
 -}
 -
  BlockDriverAIOCB *bdrv_aio_writev(BlockDriverState *bs, int64_t sector_num,
                                   QEMUIOVector *qiov, int nb_sectors,
                                   BlockDriverCompletionFunc *cb, void *opaque)
  {
 -    BlockDriver *drv = bs-drv;
 -    BlockDriverAIOCB *ret;
 -    BlockCompleteData *blk_cb_data;
 -
     trace_bdrv_aio_writev(bs, sector_num, nb_sectors, opaque);

 -    if (!drv)
 -        return NULL;
 -    if (bs-read_only)
 -        return NULL;
 -    if (bdrv_check_request(bs, sector_num, nb_sectors))
 -        return NULL;
 -
 -    if (bs-dirty_bitmap) {
 -        blk_cb_data = blk_dirty_cb_alloc(bs, sector_num, nb_sectors, cb,
 -                                         opaque);
 -        cb = block_complete_cb;
 -        opaque = blk_cb_data;
 -    }
 -
 -    ret = drv-bdrv_aio_writev(bs, sector_num, qiov, nb_sectors,
 -                               cb, opaque);
 -
 -    if (ret) {
 -        if (bs-wr_highest_sector  sector_num + nb_sectors - 1) {
 -            bs-wr_highest_sector = sector_num + nb_sectors - 1;
 -        }
 -    }
As what is said in patch #3.
 -
 -    return ret;
 +    return bdrv_co_aio_rw_vector(bs, sector_num, qiov, nb_sectors,
 +                                 cb, opaque, true, bdrv_co_do_rw);
  }


 --
 1.7.6.3






-- 
Regards,

Zhi Yong Wu



Re: [Qemu-devel] [PATCH 0/6] block: do request processing in a coroutine

2011-10-11 Thread Zhi Yong Wu
On Thu, Oct 6, 2011 at 12:17 AM, Stefan Hajnoczi
stefa...@linux.vnet.ibm.com wrote:
 Block layer features like dirty block tracing, I/O throttling, and live block
 copy are forced to duplicate code due to the three different interfaces:
 synchronous, asynchronous, and coroutines.

 Since there are bdrv_read(), bdrv_aio_readv(), and bdrv_co_readv() interfaces
 for read (and similar for write), per-request processing needs to be 
 duplicated
 for each of these execution contexts.  For example, dirty block tracking code
 is duplicated across these three interfaces.

 This patch series unifies request processing so that there is only one code
 path.  I see this as a prerequisite to the live block copy (image streaming)
 code I am working on, so I'm pushing it now.

 The short-term win from this series is that it becomes easy to add live block
 copy and other features.  We now have a single code path where the 
 perf-request
 processing is done.

 The longer-term win will be dropping the BlockDriver .bdrv_read(),
 .bdrv_write(), .bdrv_aio_readv(), and .bdrv_aio_writev() interfaces.  By doing
 that we can bring all BlockDrivers onto a common interface, namely
 .bdrv_co_readv() and .bdrv_co_writev().  It will also allow us to drop most of
 the sync and aio emulation code.

 A consequence of this patch series is that every I/O request goes through at
 least one coroutine.  There is no longer a direct .bdrv_read(), .bdrv_write(),
 .bdrv_aio_readv(), or .bdrv_aio_writev() call - we're trying to phase out 
 those
 interfaces.  I have not noticed performance degradation in correctness tests
 but we need to confirm that there has not been a performance regression.

 Stefan Hajnoczi (6):
  block: directly invoke .bdrv_aio_*() in bdrv_co_io_em()
  block: split out bdrv_co_do_readv() and bdrv_co_do_writev()
  block: switch bdrv_read()/bdrv_write() to coroutines
  block: switch bdrv_aio_readv() to coroutines
  block: mark blocks dirty on coroutine write completion
  block: switch bdrv_aio_writev() to coroutines

  block.c |  273 
 +++
  1 files changed, 134 insertions(+), 139 deletions(-)
OK. When i am available, i will play with it.

 --
 1.7.6.3






-- 
Regards,

Zhi Yong Wu



Re: [Qemu-devel] [Question] dump memory when host pci device is used by guest

2011-10-11 Thread Jan Kiszka
On 2011-10-11 04:20, Wen Congyang wrote:
 The other reason why it would be good, is that we would then have a clearly
 defined standard QEMU dump format, instead of libvirt dump format for 
 QEMU

 A core file would be that format - for direct gdb processing. No
 proprietary re-inventions please.

 I have no personal attachment to any particular format, so if the standard
 core file format is possible, then we should definitely try to use it in
 QEMU.
 
 I do not know whether there is such standard format. But IIRC, the format of 
 kdump,
 netdump, and diskdump is very similar.
 
 If we want to use such format in qemu, I think we can not do live dump in 
 libvirt.

You said you wanted to perform crash dumps - so there hardly anything
alive at this point.

Jan



signature.asc
Description: OpenPGP digital signature


Re: [Qemu-devel] [PATCH 0/2] usb-ohci: fixes to allow usb-net to work

2011-10-11 Thread Gerd Hoffmann

On 10/10/11 18:44, Peter Maydell wrote:

On 14 September 2011 18:48, Peter Maydellpeter.mayd...@linaro.org  wrote:

This patchset contains a couple of fixes to usb-ohci which I had to make
in the course of getting usb-net to work on the Beagle (which uses OHCI
rather than UHCI). The main one is making the usb-ohci controller model
honour the endpoint maximum packet size setting -- usb-net.c will just
ignore any attempt by the controller to give it a packet larger than
64 bytes. The fix to OHCI_TD_T1 is probably not strictly required but
I noticed it in passing.

Peter Maydell (2):
  hw/usb-ohci: Honour endpoint maximum packet size
  hw/usb-ohci: Fix OHCI_TD_T1 bit position definition


Ping. Gerd, I got acks from you for both of these patches but they
don't seem to have made it into master yet?


Was on vacation two weeks which delayed things a bit (and I'm busy with 
the backlog now ...)


The patches are sitting in my local queue and will go upstream with the 
next usb pull request.


cheers,
  Gerd




Re: [Qemu-devel] [Question] dump memory when host pci device is used by guest

2011-10-11 Thread Wen Congyang
At 10/11/2011 02:58 PM, Jan Kiszka Write:
 On 2011-10-11 04:20, Wen Congyang wrote:
 The other reason why it would be good, is that we would then have a 
 clearly
 defined standard QEMU dump format, instead of libvirt dump format for 
 QEMU

 A core file would be that format - for direct gdb processing. No
 proprietary re-inventions please.

 I have no personal attachment to any particular format, so if the standard
 core file format is possible, then we should definitely try to use it in
 QEMU.

 I do not know whether there is such standard format. But IIRC, the format of 
 kdump,
 netdump, and diskdump is very similar.

 If we want to use such format in qemu, I think we can not do live dump in 
 libvirt.
 
 You said you wanted to perform crash dumps - so there hardly anything
 alive at this point.

The purpose of 'virsh dump' is for crash dumps, but we can not prevent the user 
doing
it when the kernel is alive.

Thanks
Wen Congyang

 
 Jan
 




[Qemu-devel] [PATCH v2] Sort the help info shown in monitor at runtime

2011-10-11 Thread Wayne Xia
Introduced two queues to save sorted command list in it. As a result, command
help and help info would show a more friendly sorted command list.
For eg:
(qemu)help
acl_add
acl_policy
acl_remove
acl_reset
acl_show
balloon
block_passwd
...
the command list is sorted.

v2: write sorted command list back to original array.

Signed-off-by: Wayne Xia xiaw...@linux.vnet.ibm.com
---
 monitor.c |  113 ++--
 1 files changed, 109 insertions(+), 4 deletions(-)

diff --git a/monitor.c b/monitor.c
index 31b212a..122f950 100644
--- a/monitor.c
+++ b/monitor.c
@@ -66,6 +66,7 @@
 #include memory.h
 #include qmp-commands.h
 #include hmp.h
+#include qemu-queue.h
 
 //#define DEBUG
 //#define DEBUG_COMPLETION
@@ -128,6 +129,18 @@ typedef struct mon_cmd_t {
 int flags;
 } mon_cmd_t;
 
+/* queue structure used for runtime sorting */
+struct HelpCmdElem {
+QTAILQ_ENTRY(HelpCmdElem) entry;
+mon_cmd_t cmd_copy;
+};
+
+typedef struct HelpCmdElem HelpCmdElem;
+
+QTAILQ_HEAD(HelpCmdQueue, HelpCmdElem);
+
+typedef struct HelpCmdQueue HelpCmdQueue;
+
 /* file descriptors passed via SCM_RIGHTS */
 typedef struct mon_fd_t mon_fd_t;
 struct mon_fd_t {
@@ -195,8 +208,8 @@ static inline int mon_print_count_get(const Monitor *mon) { 
return 0; }
 
 static QLIST_HEAD(mon_list, Monitor) mon_list;
 
-static const mon_cmd_t mon_cmds[];
-static const mon_cmd_t info_cmds[];
+static mon_cmd_t mon_cmds[];
+static mon_cmd_t info_cmds[];
 
 static const mon_cmd_t qmp_cmds[];
 static const mon_cmd_t qmp_query_cmds[];
@@ -2726,13 +2739,14 @@ int monitor_get_fd(Monitor *mon, const char *fdname)
 return -1;
 }
 
-static const mon_cmd_t mon_cmds[] = {
+/* mon_cmds and info_cmds would be sorted at runtime */
+static mon_cmd_t mon_cmds[] = {
 #include hmp-commands.h
 { NULL, NULL, },
 };
 
 /* Please update hmp-commands.hx when adding or changing commands */
-static const mon_cmd_t info_cmds[] = {
+static mon_cmd_t info_cmds[] = {
 {
 .name   = version,
 .args_type  = ,
@@ -5068,6 +5082,94 @@ static void monitor_event(void *opaque, int event)
 }
 }
 
+static int cmdlist_sortto_queue(const mon_cmd_t *cmdlist,
+HelpCmdQueue **pqueue)
+{
+const mon_cmd_t *cmd = NULL;
+HelpCmdElem *elem = NULL;
+HelpCmdElem *newelem = NULL;
+HelpCmdElem *next = NULL;
+HelpCmdQueue *cmdqueue = NULL;
+int cmpret1, cmpret2;
+
+cmdqueue = g_malloc(sizeof(HelpCmdQueue));
+if (cmdqueue == NULL) {
+return -1;
+}
+
+for (cmd = cmdlist; cmd-name != NULL; cmd++) {
+newelem = NULL;
+newelem = g_malloc(sizeof(HelpCmdElem));
+if (newelem == NULL) {
+return -1;
+}
+newelem-cmd_copy = *cmd;
+
+if (QTAILQ_EMPTY(cmdqueue)) {
+QTAILQ_INSERT_HEAD(cmdqueue, newelem, entry);
+continue;
+}
+QTAILQ_FOREACH_SAFE(elem, cmdqueue, entry, next) {
+/* search for proper postion */
+cmpret1 = strcmp(cmd-name, elem-cmd_copy.name);
+if (next == NULL) {
+if (cmpret1 = 0) {
+QTAILQ_INSERT_TAIL(cmdqueue, newelem, entry);
+} else {
+QTAILQ_INSERT_HEAD(cmdqueue, newelem, entry);
+}
+break;
+} else {
+cmpret2 = strcmp(cmd-name, next-cmd_copy.name);
+}
+if ((cmpret1 = 0)  (cmpret2 = 0)) {
+QTAILQ_INSERT_AFTER(cmdqueue, elem, newelem, entry);
+break;
+}
+}
+}
+*pqueue = cmdqueue;
+return 1;
+}
+
+static void queue_to_cmdlist(HelpCmdQueue **pqueue,
+mon_cmd_t *cmdlist)
+{
+HelpCmdElem *elem = NULL;
+HelpCmdElem *next = NULL;
+HelpCmdQueue *cmdqueue = *pqueue;
+mon_cmd_t *pcmdlist = cmdlist;
+
+QTAILQ_FOREACH_SAFE(elem, cmdqueue, entry, next) {
+*(pcmdlist++) = elem-cmd_copy;
+QTAILQ_REMOVE(cmdqueue, elem, entry);
+g_free(elem);
+}
+g_free(cmdqueue);
+*pqueue = NULL;
+}
+
+static void sortcmdlist(void)
+{
+HelpCmdQueue *mon_cmds_queue = NULL;
+HelpCmdQueue *info_cmds_queue = NULL;
+int ret;
+
+ret = cmdlist_sortto_queue(mon_cmds, mon_cmds_queue);
+if (ret  0) {
+printf(error in initilize mon cmd queue, return is %d.\n, ret);
+return;
+}
+queue_to_cmdlist(mon_cmds_queue, mon_cmds);
+
+ret = cmdlist_sortto_queue(info_cmds, info_cmds_queue);
+if (ret  0) {
+printf(error in initilize info cmd queue, return is %d.\n, ret);
+return;
+}
+queue_to_cmdlist(info_cmds_queue, info_cmds);
+}
+
 
 /*
  * Local variables:
@@ -5110,6 +5212,9 @@ void monitor_init(CharDriverState *chr, int flags)
 QLIST_INSERT_HEAD(mon_list, mon, entry);
 if (!default_mon || (flags  MONITOR_IS_DEFAULT))
 default_mon = mon;
+
+sortcmdlist();
+
 

Re: [Qemu-devel] [PATCH 0/1] Make the help info more friendly in monitor

2011-10-11 Thread Wayne Xia

于 2011-10-4 21:55, Luiz Capitulino 写道:

On Wed, 28 Sep 2011 10:16:19 +0100
Stefan Hajnoczistefa...@gmail.com  wrote:


On Wed, Sep 28, 2011 at 10:00 AM, Wayne Xiaxiaw...@linux.vnet.ibm.com  wrote:

During my test, I found it inconvenient when I type help or help info,
because the information was shown without orderliness. This patch would just
show the help information in sorted order.

For eg:
(qemu)help
acl_add
acl_policy
acl_remove
acl_reset
acl_show
balloon
block_passwd
...
the command list is sorted.

Wayne Xia (1):
  Sort the help info shown in monitor

  monitor.c |   97 ++--
  1 files changed, 93 insertions(+), 4 deletions(-)


This is a nice idea.  We could keep hmp/qmp-commands.hx in sorted
order but that prevents us from keeping related commands together in
those files (and the generated documentation?).  So sorting at
run-time makes sense.


The info help command reads from hmp-commands.hx and the info_cmds array,
I would prefer to get those sorted.


thanks, sorting info_cmds array seems more reasonable for that related
things would be kept here in one place not another queue, would change
in next patch.


--
Best Regards

Wayne Xia
mail:xiaw...@linux.vnet.ibm.com
tel:86-010-82450803




[Qemu-devel] [PATCH v2] runstate: add more valid transitions

2011-10-11 Thread Paolo Bonzini
This patch adds more valid transitions to the table, and avoids
that the VM remains stuck in RSTATE_SAVEVM state when savevm is
done on a paused virtual machine.

Signed-off-by: Paolo Bonzini pbonz...@redhat.com
---
 savevm.c |9 +++--
 vl.c |5 +
 2 files changed, 12 insertions(+), 2 deletions(-)

diff --git a/savevm.c b/savevm.c
index bf4d0e7..ac45db8 100644
--- a/savevm.c
+++ b/savevm.c
@@ -1626,8 +1626,13 @@ out:
 if (qemu_file_has_error(f))
 ret = -EIO;
 
-if (!ret  saved_vm_running)
-vm_start();
+if (!ret) {
+if (saved_vm_running) {
+vm_start();
+   } else {
+   runstate_set(RSTATE_PAUSED);
+   }
+}
 
 return ret;
 }
diff --git a/vl.c b/vl.c
index dbf7778..6614aac 100644
--- a/vl.c
+++ b/vl.c
@@ -343,8 +343,12 @@ static const RunStateTransition runstate_transitions_def[] 
= {
 { RUN_STATE_IO_ERROR, RUN_STATE_RUNNING },
 
 { RUN_STATE_PAUSED, RUN_STATE_RUNNING },
+{ RUN_STATE_PAUSED, RUN_STATE_FINISH_MIGRATE },
+{ RUN_STATE_PAUSED, RUN_STATE_SAVE_VM },
 
 { RUN_STATE_POSTMIGRATE, RUN_STATE_RUNNING },
+{ RUN_STATE_POSTMIGRATE, RUN_STATE_FINISH_MIGRATE },
+{ RUN_STATE_POSTMIGRATE, RUN_STATE_SAVE_VM },
 
 { RUN_STATE_PRELAUNCH, RUN_STATE_RUNNING },
 { RUN_STATE_PRELAUNCH, RUN_STATE_INMIGRATE },
@@ -366,6 +370,7 @@ static const RunStateTransition runstate_transitions_def[] 
= {
 { RUN_STATE_RUNNING, RUN_STATE_WATCHDOG },
 
 { RUN_STATE_SAVE_VM, RUN_STATE_RUNNING },
+{ RUN_STATE_SAVE_VM, RUN_STATE_PAUSED },
 
 { RUN_STATE_SHUTDOWN, RUN_STATE_PAUSED },
 
-- 
1.7.6




Re: [Qemu-devel] [BUG] USB assertion triggers in usb_packet_complete()

2011-10-11 Thread Thomas Huth
Am Mon, 10 Oct 2011 15:03:41 +0200
schrieb Thomas Huth th...@linux.vnet.ibm.com:
 
 I am currently facing a problem when running QEMU (up-to-date git
 version) with OHCI and a lot of virtual USB devices.
 The emulator dies with the following assertion:
 
 qemu-system-arm: hw/usb.c:337: usb_packet_complete:
 Assertion `p-owner != ((void *)0)' failed.

Not sure whether this is the right solution, but this patch fixes the
problem for me:

diff --git a/hw/usb.c b/hw/usb.c
index fa90204..7cef9e2 100644
--- a/hw/usb.c
+++ b/hw/usb.c
@@ -25,6 +25,7 @@
  */
 #include qemu-common.h
 #include usb.h
+#include usb-desc.h
 #include iov.h
 
 void usb_attach(USBPort *port)
@@ -334,7 +335,9 @@ int usb_handle_packet(USBDevice *dev, USBPacket *p)
 void usb_packet_complete(USBDevice *dev, USBPacket *p)
 {
 /* Note: p-owner != dev is possible in case dev is a hub */
-assert(p-owner != NULL);
+if (dev-device-bDeviceClass != USB_CLASS_HUB) {
+assert(p-owner != NULL);
+}
 p-owner = NULL;
 dev-port-ops-complete(dev-port, p);
 }


 Thomas



Re: [Qemu-devel] [PATCH v3 0/6]: block: Add I/O status support

2011-10-11 Thread Kevin Wolf
Am 10.10.2011 22:25, schrieb Luiz Capitulino:
 On Mon, 10 Oct 2011 19:30:32 +0200
 Kevin Wolf kw...@redhat.com wrote:
 
 Am 26.09.2011 22:43, schrieb Luiz Capitulino:
 This series adds support to the block layer to keep track of devices'
 I/O status. That information is also made available in QMP and HMP.

 The goal here is to allow management applications that miss the
 BLOCK_IO_ERROR event to able to query the VM to determine if any device has
 caused the VM to stop and which device caused it.

 Here's an HMP example:

   (qemu) info status 
   VM status: paused (io-error)
   (qemu) info block
   ide0-hd0: removable=0 io-status=ok file=disks/test2.img ro=0 drv=qcow2 
 encrypted=0
   ide0-hd1: removable=0 io-status=nospace file=/dev/vg_doriath/kvmtest ro=0 
 drv=qcow2 encrypted=0
   ide1-cd0: removable=1 locked=0 io-status=ok [not inserted]
   floppy0: removable=1 locked=0 [not inserted]
   sd0: removable=1 locked=0 [not inserted]

 The session above shows that the VM is stopped due to an I/O error. By using
 the info block command it's possible to determine that the 'ide0-hd1' device
 caused the error, which turns out to be due to no space.

 Thanks, applied all to the block branch.
 
 This series will conflict with my first round of qapi conversions series.
 
 It seems to me that the conflicts are rather simple, just doing
 s/RSTATE_/RUN_STATE should fix them, but I can resend the series if you think
 that's better.

Thanks for the heads-up. It seems to be a trivial conflict indeed and I
resolved it myself.

Kevin



[Qemu-devel] [PATCH] remove hpet.h

2011-10-11 Thread Paolo Bonzini
It is unused since the HPET and RTC timers were removed (commit
25f3151, 2011-05-31).

Signed-off-by: Paolo Bonzini pbonz...@redhat.com
---
 hpet.h |   22 --
 1 files changed, 0 insertions(+), 22 deletions(-)
 delete mode 100644 hpet.h

diff --git a/hpet.h b/hpet.h
deleted file mode 100644
index 754051a..000
--- a/hpet.h
+++ /dev/null
@@ -1,22 +0,0 @@
-#ifndef__HPET__
-#define__HPET__ 1
-
-
-
-struct hpet_info {
-   unsigned long hi_ireqfreq;  /* Hz */
-   unsigned long hi_flags; /* information */
-   unsigned short hi_hpet;
-   unsigned short hi_timer;
-};
-
-#defineHPET_INFO_PERIODIC  0x0001  /* timer is periodic */
-
-#defineHPET_IE_ON  _IO('h', 0x01)  /* interrupt on */
-#defineHPET_IE_OFF _IO('h', 0x02)  /* interrupt off */
-#defineHPET_INFO   _IOR('h', 0x03, struct hpet_info)
-#defineHPET_EPI_IO('h', 0x04)  /* enable periodic */
-#defineHPET_DPI_IO('h', 0x05)  /* disable periodic */
-#defineHPET_IRQFREQ_IOW('h', 0x6, unsigned long)   /* IRQFREQ usec 
*/
-
-#endif /* !__HPET__ */
-- 
1.7.6




Re: [Qemu-devel] [PATCH 00/15] NBD server improvements

2011-10-11 Thread Paolo Bonzini

On 10/10/2011 11:37 AM, Paolo Bonzini wrote:

This series adds asynchronous operation support for the NBD server.
The first 9 patches are a general refactoring that can be applied now.
The others require the main loop in tools series.


They also need rebasing after the QMP changes.  Kevin, is it okay for 
you to apply only the first part?


Paolo




[Qemu-devel] Slow kernel/initrd loading via fw_cfg; Was Re: Hack integrating SeaBios / LinuxBoot option rom with QEMU trace backends

2011-10-11 Thread Daniel P. Berrange
On Mon, Oct 10, 2011 at 09:01:52PM +0200, Alexander Graf wrote:
 
 On 10.10.2011, at 20:53, Anthony Liguori wrote:
 
  On 10/10/2011 12:08 PM, Daniel P. Berrange wrote:
  With the attached patches applied to QEMU and SeaBios, the attached
  systemtap script can be used to debug timings in QEMU startup.
  
  For example, one execution of QEMU produced the following log:
  
$ stap qemu-timing.stp
0.000 Start
0.036 Run
0.038 BIOS post
0.180 BIOS int 19
0.181 BIOS boot OS
0.181 LinuxBoot copy kernel
1.371 LinuxBoot copy initrd
  
  Yeah, there was a thread a bit ago about the performance
  of the interface to read the kernel/initrd.  I think at it
  was using single byte access instructions and there were
  patches to use string accessors instead?  I can't remember
  where that threaded ended up.

There was initially a huge performance problem, which was
fixed during the course of the thread, getting to the current
state where it still takes a few seconds to load large blobs.
The thread continued with many proposals  counter proposals
but nothing further really came out of it.

   https://lists.gnu.org/archive/html/qemu-devel/2010-08/msg00133.html

One core point to take away though, is that -kernel/-initrd is
*not* just for ad-hoc testing by qemu/kernel developers. It is
critical functionality widely used by users of QEMU in production
scenarios and performance of it does matter, in some cases, alot.

 IIRC we're already using string accessors, but are still
 slow. Richard had a nice patch cooked up to basically have
 the fw_cfg interface be able to DMA its data to the guest.
 I like the idea. Avi did not.

That's here:

  https://lists.gnu.org/archive/html/qemu-devel/2010-07/msg01037.html

 And yes, bad -kernel performance does hurt in some workloads. A lot.

Let me recap the 3 usage scenarios I believe are most common:

 - Most Linux distro installs done with libvirt + virt-manager/virt-install
   are done by directly booting the distro's PXE kernel/initrd files.
   The kernel images are typically  5 MB, while the initrd images may
   be as large as 150 MB.  Both are compressed already. An uncompressed
   initrd image would be more like 300 MB,  so these are avoided for
   obvious reasons.

   Performance is not really an issue, within reason, since the overall
   distro installation time will easily dominate, but loading should
   still be measured in seconds, not minutes.

   The reason for using a kernel/initrd instead of a bootable ISO is
   to be able to set kernel command line arguments for the installer.

 - libguestfs directly boots its appliance using the regular host's
   kernel image and a custom built initrd image. The initrd does
   not contain the entire appliance, just enough to boot up and
   dynamically read files in from the host OS on demand. This is
   a so called supermin appliance.

   The kernel is  5 MB, while the initrd is approx 100MB. The initrd
   image is used uncompressed, because decompression time needs to be
   eliminated from bootup.  Performance is very critical for libguestfs.
   100's of milliseconds really do make a big difference for it.

   The reason for using a kernel/initrd instead of bootable ISO is to
   avoid the time required to actually build the ISO, and to avoid
   having more disks visible in the guest, which could confuse apps
   using libguestfs which enumerate disks.

 - Application sandbox, directly boots the regular host's kernel and
   a custom initrd image. The initrd does not contain any files except
   for the 9p kernel modules and a custom init binary, which mounts
   the guest root FS from a 9p filesystem export.

   The kernel is  5 MB, while the initrd is approx 700 KB compressed,
   or 1.4 MB compressed. Performance for the sandbox is even more
   critical than for libguestfs. Even 10's of milliseconds make a
   difference here. The commands being run in the sandbox can be
   very short lived processes, executed reasonably frequently. The
   goal is to have end-to-end runtime overhead of  2 seconds. This
   includes libvirt guest startup, qemu startup/shutdown, bios time,
   option ROM time, kernel boot  shutdown time.

   The reason for using a kerenl/initrd instead of a bootable ISO,
   is that building an ISO requires time itself, and we need to be
   able to easily pass kernel boot arguments via -append.


I'm focusing on the last use case, and if the phase of the moon
is correct, I can currently executed a sandbox command with a total
overhead of 3.5 seconds (if using a compressed initrd) of which
the QEMU execution time is 2.5 seconds.

Of this, 1.4 seconds is the time required by LinuxBoot to copy the
kernel+initrd. If I used an uncompressed initrd, which I really want
to, to avoid decompression overhead, this increases to ~1.7 seconds.
So the LinuxBoot ROM is ~60% of total QEMU execution time, or 40%
of total sandbox execution overhead.

For comparison I also did a test building a bootable ISO using 

Re: [Qemu-devel] Hang when using 9p mounts after last Seabios update

2011-10-11 Thread Daniel P. Berrange
On Sat, Oct 01, 2011 at 12:50:43PM -0400, Kevin O'Connor wrote:
 On Thu, Sep 22, 2011 at 12:45:11PM +0100, Daniel P. Berrange wrote:
  On 0.14, 0.15 releaes, this all works just fine. On current GIT master,
  the guest OS will hang during boot.
 [...]
  To reproduce this you will need my custom initrd for mounting 9p filesystems
  as the root FS. You can get that here:
  
http://berrange.com/~dan/qemu-serial-hang-demo.tar.gz
 
 Thanks for the detailed report.
 
 I've confirmed the issue and tracked it down.  The current SeaBIOS
 code gets confused during alignment checking if there are no prefmem
 regions found.
 
 The patch below should fix the issue.

Thanks, I have tested Seabios 1.6.3 which includes that patch, and
can confirm that it does fix the hang I saw.

Anthony/Gerd: we can get QEMU master updated to Seabios 1.6.3 before
the 1.0 release ?

 Author: Kevin O'Connor ke...@koconnor.net
 Date:   Sat Oct 1 12:35:32 2011 -0400
 
 Fix alignment bug in pci_bios_init_root_regions().
 
 If there are no memory allocations for a given type then the max bar
 size is zero.  However, ALIGN_DOWN does not handle an alignment of
 zero properly.  Catch and handle the zero case.
 
 Signed-off-by: Kevin O'Connor ke...@koconnor.net
 
 diff --git a/src/pciinit.c b/src/pciinit.c
 index a857da0..0d8758e 100644
 --- a/src/pciinit.c
 +++ b/src/pciinit.c
 @@ -536,7 +536,7 @@ static void pci_bios_init_bus_bases(struct pci_bus *bus)
  }
  }
  
 -#define ROOT_BASE(top, sum, align) ALIGN_DOWN((top)-(sum),(align))
 +#define ROOT_BASE(top, sum, max) ALIGN_DOWN((top)-(sum),(max) ?: 1)
  
  static int pci_bios_init_root_regions(u32 start, u32 end)
  {

Regards,
Daniel
-- 
|: http://berrange.com  -o-http://www.flickr.com/photos/dberrange/ :|
|: http://libvirt.org  -o- http://virt-manager.org :|
|: http://autobuild.org   -o- http://search.cpan.org/~danberr/ :|
|: http://entangle-photo.org   -o-   http://live.gnome.org/gtk-vnc :|



Re: [Qemu-devel] Slow kernel/initrd loading via fw_cfg; Was Re: Hack integrating SeaBios / LinuxBoot option rom with QEMU trace backends

2011-10-11 Thread Richard W.M. Jones
On Tue, Oct 11, 2011 at 09:23:15AM +0100, Daniel P. Berrange wrote:
  - libguestfs directly boots its appliance using the regular host's
kernel image and a custom built initrd image. The initrd does
not contain the entire appliance, just enough to boot up and
dynamically read files in from the host OS on demand. This is
a so called supermin appliance.
 
The kernel is  5 MB, while the initrd is approx 100MB.
[...]

Actually this is how libguestfs used to work, but the performance of
such a large initrd against the poor qemu implementation meant we had
to abandon this approach.

We now use -kernel ~5MB, a small -initrd ~1.1MB and a large ext2
format root disk (of course loaded on demand, which is better anyway).

Nevertheless any improvement in -kernel and -initrd load times would
help us a gain a few 1/10ths of seconds, which is still very important
for us.  Overall boot time is 3-4 seconds and we are often in a
situation where we need to repeatedly boot the appliance.

Rich.

-- 
Richard Jones, Virtualization Group, Red Hat http://people.redhat.com/~rjones
Read my programming blog: http://rwmj.wordpress.com
Fedora now supports 80 OCaml packages (the OPEN alternative to F#)
http://cocan.org/getting_started_with_ocaml_on_red_hat_and_fedora



Re: [Qemu-devel] [PATCH 07/11] audio/spice: add support for volume control

2011-10-11 Thread Gerd Hoffmann

  Hi,


+#else
+#warning Spice playback volume unsupported
+#endif



+#else
+#warning Spice record volume unsupported
+#endif


One warning is enougth.  But given that qemu builds with -Werror by 
default printing a warning just because of an older spice-server version 
is a bad idea IMHO.



@@ -337,6 +379,7 @@ struct audio_driver spice_audio_driver = {
  .max_voices_in  = 1,
  .voice_size_out = sizeof (SpiceVoiceOut),
  .voice_size_in  = sizeof (SpiceVoiceIn),
+.ctl_caps   = VOICE_VOLUME_CAP


This should be #ifdef'ed too I guess?

cheers,
  Gerd




Re: [Qemu-devel] [PATCH 00/11] RFC: apply volume on client stream

2011-10-11 Thread Gerd Hoffmann

On 09/21/11 18:10, Marc-André Lureau wrote:

Hi,

The qemu volume control experience could be improved. Without mixemu,
the volume control has no effect. A volume applet will just feel
broken (except in some cases where software volume is applied on guest
side, with HDA/Windows7 for example).


Series looks good to me with a few minor nits on the spice bits (see 
reply to patch).


cheers,
  Gerd



Re: [Qemu-devel] Hack integrating SeaBios / LinuxBoot option rom with QEMU trace backends

2011-10-11 Thread Avi Kivity

On 10/10/2011 09:01 PM, Alexander Graf wrote:

  For example, one execution of QEMU produced the following log:

$ stap qemu-timing.stp
0.000 Start
0.036 Run
0.038 BIOS post
0.180 BIOS int 19
0.181 BIOS boot OS
0.181 LinuxBoot copy kernel
1.371 LinuxBoot copy initrd

  Yeah, there was a thread a bit ago about the performance of the interface to 
read the kernel/initrd.  I think at it was using single byte access instructions 
and there were patches to use string accessors instead?  I can't remember where 
that threaded ended up.

IIRC we're already using string accessors, but are still slow. Richard had a 
nice patch cooked up to basically have the fw_cfg interface be able to DMA its 
data to the guest. I like the idea. Avi did not.

And yes, bad -kernel performance does hurt in some workloads. A lot.




The rep/ins implementation is still slow, optimizing it can help.

What does 'perf top' say when running this workload?

--
error compiling committee.c: too many arguments to function




Re: [Qemu-devel] [PATCH v2] Sort the help info shown in monitor at runtime

2011-10-11 Thread Markus Armbruster
Wayne Xia xiaw...@linux.vnet.ibm.com writes:

 Introduced two queues to save sorted command list in it. As a result, command
 help and help info would show a more friendly sorted command list.
 For eg:
 (qemu)help
 acl_add
 acl_policy
 acl_remove
 acl_reset
 acl_show
 balloon
 block_passwd
 ...
 the command list is sorted.

 v2: write sorted command list back to original array.

 Signed-off-by: Wayne Xia xiaw...@linux.vnet.ibm.com
 ---
  monitor.c |  113 ++--
  1 files changed, 109 insertions(+), 4 deletions(-)

 diff --git a/monitor.c b/monitor.c
 index 31b212a..122f950 100644
 --- a/monitor.c
 +++ b/monitor.c
 @@ -66,6 +66,7 @@
  #include memory.h
  #include qmp-commands.h
  #include hmp.h
 +#include qemu-queue.h
  
  //#define DEBUG
  //#define DEBUG_COMPLETION
 @@ -128,6 +129,18 @@ typedef struct mon_cmd_t {
  int flags;
  } mon_cmd_t;
  
 +/* queue structure used for runtime sorting */
 +struct HelpCmdElem {
 +QTAILQ_ENTRY(HelpCmdElem) entry;
 +mon_cmd_t cmd_copy;
 +};
 +
 +typedef struct HelpCmdElem HelpCmdElem;
 +
 +QTAILQ_HEAD(HelpCmdQueue, HelpCmdElem);
 +
 +typedef struct HelpCmdQueue HelpCmdQueue;
 +
  /* file descriptors passed via SCM_RIGHTS */
  typedef struct mon_fd_t mon_fd_t;
  struct mon_fd_t {
 @@ -195,8 +208,8 @@ static inline int mon_print_count_get(const Monitor *mon) 
 { return 0; }
  
  static QLIST_HEAD(mon_list, Monitor) mon_list;
  
 -static const mon_cmd_t mon_cmds[];
 -static const mon_cmd_t info_cmds[];
 +static mon_cmd_t mon_cmds[];
 +static mon_cmd_t info_cmds[];
  
  static const mon_cmd_t qmp_cmds[];
  static const mon_cmd_t qmp_query_cmds[];
 @@ -2726,13 +2739,14 @@ int monitor_get_fd(Monitor *mon, const char *fdname)
  return -1;
  }
  
 -static const mon_cmd_t mon_cmds[] = {
 +/* mon_cmds and info_cmds would be sorted at runtime */
 +static mon_cmd_t mon_cmds[] = {
  #include hmp-commands.h
  { NULL, NULL, },
  };
  
  /* Please update hmp-commands.hx when adding or changing commands */
 -static const mon_cmd_t info_cmds[] = {
 +static mon_cmd_t info_cmds[] = {
  {
  .name   = version,
  .args_type  = ,
 @@ -5068,6 +5082,94 @@ static void monitor_event(void *opaque, int event)
  }
  }
  
 +static int cmdlist_sortto_queue(const mon_cmd_t *cmdlist,
 +HelpCmdQueue **pqueue)
 +{
 +const mon_cmd_t *cmd = NULL;
 +HelpCmdElem *elem = NULL;
 +HelpCmdElem *newelem = NULL;
 +HelpCmdElem *next = NULL;
 +HelpCmdQueue *cmdqueue = NULL;
 +int cmpret1, cmpret2;
 +
 +cmdqueue = g_malloc(sizeof(HelpCmdQueue));

Are you sure this can fail?

 +if (cmdqueue == NULL) {
 +return -1;
 +}
 +
 +for (cmd = cmdlist; cmd-name != NULL; cmd++) {
 +newelem = NULL;
 +newelem = g_malloc(sizeof(HelpCmdElem));
 +if (newelem == NULL) {
 +return -1;
 +}
 +newelem-cmd_copy = *cmd;
 +
 +if (QTAILQ_EMPTY(cmdqueue)) {
 +QTAILQ_INSERT_HEAD(cmdqueue, newelem, entry);
 +continue;
 +}
 +QTAILQ_FOREACH_SAFE(elem, cmdqueue, entry, next) {
 +/* search for proper postion */
 +cmpret1 = strcmp(cmd-name, elem-cmd_copy.name);
 +if (next == NULL) {
 +if (cmpret1 = 0) {
 +QTAILQ_INSERT_TAIL(cmdqueue, newelem, entry);
 +} else {
 +QTAILQ_INSERT_HEAD(cmdqueue, newelem, entry);
 +}
 +break;
 +} else {
 +cmpret2 = strcmp(cmd-name, next-cmd_copy.name);
 +}
 +if ((cmpret1 = 0)  (cmpret2 = 0)) {
 +QTAILQ_INSERT_AFTER(cmdqueue, elem, newelem, entry);
 +break;
 +}
 +}
 +}
 +*pqueue = cmdqueue;
 +return 1;
 +}
 +
 +static void queue_to_cmdlist(HelpCmdQueue **pqueue,
 +mon_cmd_t *cmdlist)
 +{
 +HelpCmdElem *elem = NULL;
 +HelpCmdElem *next = NULL;
 +HelpCmdQueue *cmdqueue = *pqueue;
 +mon_cmd_t *pcmdlist = cmdlist;
 +
 +QTAILQ_FOREACH_SAFE(elem, cmdqueue, entry, next) {
 +*(pcmdlist++) = elem-cmd_copy;
 +QTAILQ_REMOVE(cmdqueue, elem, entry);
 +g_free(elem);
 +}
 +g_free(cmdqueue);
 +*pqueue = NULL;
 +}
 +
 +static void sortcmdlist(void)
 +{
 +HelpCmdQueue *mon_cmds_queue = NULL;
 +HelpCmdQueue *info_cmds_queue = NULL;
 +int ret;
 +
 +ret = cmdlist_sortto_queue(mon_cmds, mon_cmds_queue);
 +if (ret  0) {
 +printf(error in initilize mon cmd queue, return is %d.\n, ret);

initialize

Error messages go to stderr.  Best use error_report().

 +return;
 +}
 +queue_to_cmdlist(mon_cmds_queue, mon_cmds);
 +
 +ret = cmdlist_sortto_queue(info_cmds, info_cmds_queue);
 +if (ret  0) {
 +printf(error in initilize info cmd queue, return is %d.\n, ret);
 +return;
 +

Re: [Qemu-devel] Slow kernel/initrd loading via fw_cfg; Was Re: Hack integrating SeaBios / LinuxBoot option rom with QEMU trace backends

2011-10-11 Thread Avi Kivity

On 10/11/2011 10:23 AM, Daniel P. Berrange wrote:

  - Application sandbox, directly boots the regular host's kernel and
a custom initrd image. The initrd does not contain any files except
for the 9p kernel modules and a custom init binary, which mounts
the guest root FS from a 9p filesystem export.

The kernel is  5 MB, while the initrd is approx 700 KB compressed,
or 1.4 MB compressed. Performance for the sandbox is even more
critical than for libguestfs. Even 10's of milliseconds make a
difference here. The commands being run in the sandbox can be
very short lived processes, executed reasonably frequently. The
goal is to have end-to-end runtime overhead of  2 seconds. This
includes libvirt guest startup, qemu startup/shutdown, bios time,
option ROM time, kernel boot  shutdown time.

The reason for using a kerenl/initrd instead of a bootable ISO,
is that building an ISO requires time itself, and we need to be
able to easily pass kernel boot arguments via -append.


I'm focusing on the last use case, and if the phase of the moon
is correct, I can currently executed a sandbox command with a total
overhead of 3.5 seconds (if using a compressed initrd) of which
the QEMU execution time is 2.5 seconds.

Of this, 1.4 seconds is the time required by LinuxBoot to copy the
kernel+initrd. If I used an uncompressed initrd, which I really want
to, to avoid decompression overhead, this increases to ~1.7 seconds.
So the LinuxBoot ROM is ~60% of total QEMU execution time, or 40%
of total sandbox execution overhead.


One thing we can do is boot a guest and immediately snapshot it, before 
it runs any application specific code.  Subsequent invocations will 
MAP_PRIVATE the memory image and COW their way.  This avoids the kernel 
initialization time as well.




For comparison I also did a test building a bootable ISO using ISOLinux.
This required 700 ms for the boot time, which is appoximately 1/2 the
time reqiured for direct kernel/initrd boot. But you have to then add
on time required to build the ISO on every boot, to add custom kernel
command line args. So while ISO is faster than LinuxBoot currently
there is still non-negligable overhead here that I want to avoid.


You can accept parameters from virtio-serial or some other channel.  Is 
there any reason you need them specifically as *kernel* command line 
parameters?



For further comparison I tested with Rich Jones' patches which add a
DMA-like inteface to fw_cfg. With this the time spent in the LinuxBoot
option ROM was as close to zero as matters.

So obviously, my preference is for -kernel/-initrd to be made very fast
using the DMA-like patches, or any other patches which could achieve
similarly high performance for -kernel/-initd.




--
error compiling committee.c: too many arguments to function




Re: [Qemu-devel] Hack integrating SeaBios / LinuxBoot option rom with QEMU trace backends

2011-10-11 Thread Daniel P. Berrange
On Tue, Oct 11, 2011 at 11:08:33AM +0200, Avi Kivity wrote:
 On 10/10/2011 09:01 PM, Alexander Graf wrote:
   For example, one execution of QEMU produced the following log:
 
 $ stap qemu-timing.stp
 0.000 Start
 0.036 Run
 0.038 BIOS post
 0.180 BIOS int 19
 0.181 BIOS boot OS
 0.181 LinuxBoot copy kernel
 1.371 LinuxBoot copy initrd
 
   Yeah, there was a thread a bit ago about the performance of the interface 
  to read the kernel/initrd.  I think at it was using single byte access 
  instructions and there were patches to use string accessors instead?  I 
  can't remember where that threaded ended up.
 
 IIRC we're already using string accessors, but are still slow. Richard had a 
 nice patch cooked up to basically have the fw_cfg interface be able to DMA 
 its data to the guest. I like the idea. Avi did not.
 
 And yes, bad -kernel performance does hurt in some workloads. A lot.
 
 
 
 The rep/ins implementation is still slow, optimizing it can help.
 
 What does 'perf top' say when running this workload?

To ensure it only recorded the LinuxBoot code, I created a 100 MB
kernel image which takes approx 30 seconds to copy. Here is the
perf output for approx 15 seconds of that copy:

 1906.00 15.0% read_hpet   [kernel]
 1029.00  8.1% x86_emulate_insn[kvm]   
  863.00  6.8% test_cc [kvm]   
  661.00  5.2% emulator_get_segment[kvm]   
  631.00  5.0% kvm_mmu_pte_write   [kvm]   
  535.00  4.2% __linearize [kvm]   
  431.00  3.4% do_raw_spin_lock[kernel]
  356.00  2.8% vmx_get_segment [kvm_intel] 
  330.00  2.6% vmx_segment_cache_test_set  [kvm_intel] 
  308.00  2.4% segmented_write [kvm]   
  291.00  2.3% vread_hpet  [kernel].vsyscall_fn
  251.00  2.0% vmx_get_cpl [kvm_intel] 
  230.00  1.8% trace_kvm_mmu_audit [kvm]   
  207.00  1.6% kvm_write_guest [kvm]   
  199.00  1.6% emulator_write_emulated [kvm]   
  187.00  1.5% emulator_write_emulated_onepage [kvm]   
  185.00  1.5% kvm_write_guest_page[kvm]   
  177.00  1.4% vmx_get_segment_base[kvm_intel] 
  158.00  1.2% fw_cfg_io_readb qemu-system-x86_64  
  148.00  1.2% register_address_increment  [kvm]   
  142.00  1.1% emulator_write_phys [kvm]   
  134.00  1.1% acpi_os_read_port   [kernel]


Daniel
-- 
|: http://berrange.com  -o-http://www.flickr.com/photos/dberrange/ :|
|: http://libvirt.org  -o- http://virt-manager.org :|
|: http://autobuild.org   -o- http://search.cpan.org/~danberr/ :|
|: http://entangle-photo.org   -o-   http://live.gnome.org/gtk-vnc :|



Re: [Qemu-devel] Slow kernel/initrd loading via fw_cfg; Was Re: Hack integrating SeaBios / LinuxBoot option rom with QEMU trace backends

2011-10-11 Thread Alexander Graf

On 11.10.2011, at 11:15, Avi Kivity wrote:

 On 10/11/2011 10:23 AM, Daniel P. Berrange wrote:
  - Application sandbox, directly boots the regular host's kernel and
a custom initrd image. The initrd does not contain any files except
for the 9p kernel modules and a custom init binary, which mounts
the guest root FS from a 9p filesystem export.
 
The kernel is  5 MB, while the initrd is approx 700 KB compressed,
or 1.4 MB compressed. Performance for the sandbox is even more
critical than for libguestfs. Even 10's of milliseconds make a
difference here. The commands being run in the sandbox can be
very short lived processes, executed reasonably frequently. The
goal is to have end-to-end runtime overhead of  2 seconds. This
includes libvirt guest startup, qemu startup/shutdown, bios time,
option ROM time, kernel boot  shutdown time.
 
The reason for using a kerenl/initrd instead of a bootable ISO,
is that building an ISO requires time itself, and we need to be
able to easily pass kernel boot arguments via -append.
 
 
 I'm focusing on the last use case, and if the phase of the moon
 is correct, I can currently executed a sandbox command with a total
 overhead of 3.5 seconds (if using a compressed initrd) of which
 the QEMU execution time is 2.5 seconds.
 
 Of this, 1.4 seconds is the time required by LinuxBoot to copy the
 kernel+initrd. If I used an uncompressed initrd, which I really want
 to, to avoid decompression overhead, this increases to ~1.7 seconds.
 So the LinuxBoot ROM is ~60% of total QEMU execution time, or 40%
 of total sandbox execution overhead.
 
 One thing we can do is boot a guest and immediately snapshot it, before it 
 runs any application specific code.  Subsequent invocations will MAP_PRIVATE 
 the memory image and COW their way.  This avoids the kernel initialization 
 time as well.

That doesn't allow modification of -append and gets you in a pretty bizarre 
state when doing updates of your host files, since then you have 2 different 
paths: full boot and restore. That's yet another potential source for bugs.

 
 
 For comparison I also did a test building a bootable ISO using ISOLinux.
 This required 700 ms for the boot time, which is appoximately 1/2 the
 time reqiured for direct kernel/initrd boot. But you have to then add
 on time required to build the ISO on every boot, to add custom kernel
 command line args. So while ISO is faster than LinuxBoot currently
 there is still non-negligable overhead here that I want to avoid.
 
 You can accept parameters from virtio-serial or some other channel.  Is there 
 any reason you need them specifically as *kernel* command line parameters?

That doesn't work for kernel parameters. It also means things would have to be 
rewritten needlessly. Some times we can't easily change the way parameters are 
passed into the guest either, for example when running a random (read: old, 
think of RHEL5) distro installation initrd.

And I don't see the point why we would have to shoot yet another hole into the 
guest just because we're too unwilling to make an interface that's perfectly 
valid horribly slow.


Alex




Re: [Qemu-devel] [PATCH RFC] qemu-file: output data directly if possible

2011-10-11 Thread Juan Quintela
Michael S. Tsirkin m...@redhat.com wrote:
 On Mon, Oct 10, 2011 at 09:42:51AM +0200, Paolo Bonzini wrote:
 On 10/10/2011 01:56 AM, Michael S. Tsirkin wrote:
 qemu file currently always buffers up data before writing it out.
 At least for memory this is probably not a good idea:
 writing out to file would be cheaper. Let's do
 that if we can, which should be the common case. If we can't, buffer.
 
 Signed-off-by: Michael S. Tsirkinm...@redhat.com
 
 ---
 
 Completely untested, this is just thinking aloud.
 Shouldn't the below save us a data copy in the
 common case, helping speed up migration?
 
 The problem here is qemu_put_byte and friends, where the indirection
 of a function call would probably slow things down.  In the common
 case, qemu_put_byte is called a lot and f-buf_index would not be
 zero.

 True, maybe the right thing to do is use a size cutoff,
 avoid a copy if buffer is large enough.
 I note the buffer in qemu file is 32K - is that
 based on some specific measurements or just
 a random large number? Any objections to making
 it smaller, like 4K?

We can't until we move to a thread or similar.  Basically we have to be
able to end a section write, there is no way to stop in the midle of a
section, we can only split on whole sections.

I think that for this, it should be easier to just make ram_save_live to
bypass QEMUFile layering and just write directly to the fd (header is
really small (between 4bytes and something less that 256 if we have bad
luck).


  The way to go would probably be to merge QEMUFile and
 QEMUBufferedFile's two buffering layers, which also removes a copy.
 
 Paolo

 Yes, it does look sane. QEMUFile doesn't seem to ever be used without
 QEMUBufferedFile - is that true?

As Paolo says, savevm uses QEMUFile directly.  I think that the way to
go is to make savevm to also use QEMUBufferedFile, and then do same
trick to avoid the buffering.  It is on my ToDo list, but there are 4-5
things before that.

Later, Juan.



Re: [Qemu-devel] Slow kernel/initrd loading via fw_cfg; Was Re: Hack integrating SeaBios / LinuxBoot option rom with QEMU trace backends

2011-10-11 Thread Avi Kivity

On 10/11/2011 11:19 AM, Alexander Graf wrote:


  Of this, 1.4 seconds is the time required by LinuxBoot to copy the
  kernel+initrd. If I used an uncompressed initrd, which I really want
  to, to avoid decompression overhead, this increases to ~1.7 seconds.
  So the LinuxBoot ROM is ~60% of total QEMU execution time, or 40%
  of total sandbox execution overhead.

  One thing we can do is boot a guest and immediately snapshot it, before it 
runs any application specific code.  Subsequent invocations will MAP_PRIVATE the 
memory image and COW their way.  This avoids the kernel initialization time as 
well.

That doesn't allow modification of -append


Is it really needed?


and gets you in a pretty bizarre state when doing updates of your host files, 
since then you have 2 different paths: full boot and restore. That's yet 
another potential source for bugs.


Typically you'd check the timestamps to make sure you're running an 
up-to-date version.






  For comparison I also did a test building a bootable ISO using ISOLinux.
  This required 700 ms for the boot time, which is appoximately 1/2 the
  time reqiured for direct kernel/initrd boot. But you have to then add
  on time required to build the ISO on every boot, to add custom kernel
  command line args. So while ISO is faster than LinuxBoot currently
  there is still non-negligable overhead here that I want to avoid.

  You can accept parameters from virtio-serial or some other channel.  Is 
there any reason you need them specifically as *kernel* command line parameters?

That doesn't work for kernel parameters. It also means things would have to be 
rewritten needlessly. Some times we can't easily change the way parameters are 
passed into the guest either, for example when running a random (read: old, 
think of RHEL5) distro installation initrd.


This use case is not installation, it's for app sandboxing.


And I don't see the point why we would have to shoot yet another hole into the 
guest just because we're too unwilling to make an interface that's perfectly 
valid horribly slow.


rep/ins is exactly like dma+wait for this use case: provide an address, 
get a memory image in return.  There's no need to add another interface, 
we should just optimize the existing one.


--
error compiling committee.c: too many arguments to function




Re: [Qemu-devel] Slow kernel/initrd loading via fw_cfg; Was Re: Hack integrating SeaBios / LinuxBoot option rom with QEMU trace backends

2011-10-11 Thread Daniel P. Berrange
On Tue, Oct 11, 2011 at 11:15:05AM +0200, Avi Kivity wrote:
 On 10/11/2011 10:23 AM, Daniel P. Berrange wrote:
   - Application sandbox, directly boots the regular host's kernel and
 a custom initrd image. The initrd does not contain any files except
 for the 9p kernel modules and a custom init binary, which mounts
 the guest root FS from a 9p filesystem export.
 
 The kernel is  5 MB, while the initrd is approx 700 KB compressed,
 or 1.4 MB compressed. Performance for the sandbox is even more
 critical than for libguestfs. Even 10's of milliseconds make a
 difference here. The commands being run in the sandbox can be
 very short lived processes, executed reasonably frequently. The
 goal is to have end-to-end runtime overhead of  2 seconds. This
 includes libvirt guest startup, qemu startup/shutdown, bios time,
 option ROM time, kernel boot  shutdown time.
 
 The reason for using a kerenl/initrd instead of a bootable ISO,
 is that building an ISO requires time itself, and we need to be
 able to easily pass kernel boot arguments via -append.
 
 
 I'm focusing on the last use case, and if the phase of the moon
 is correct, I can currently executed a sandbox command with a total
 overhead of 3.5 seconds (if using a compressed initrd) of which
 the QEMU execution time is 2.5 seconds.
 
 Of this, 1.4 seconds is the time required by LinuxBoot to copy the
 kernel+initrd. If I used an uncompressed initrd, which I really want
 to, to avoid decompression overhead, this increases to ~1.7 seconds.
 So the LinuxBoot ROM is ~60% of total QEMU execution time, or 40%
 of total sandbox execution overhead.
 
 One thing we can do is boot a guest and immediately snapshot it,
 before it runs any application specific code.  Subsequent
 invocations will MAP_PRIVATE the memory image and COW their way.
 This avoids the kernel initialization time as well.

This is adding an awful lot of complexity to the process, just
to avoid fixing a performance problem in QEMU. You can't even
reliably snapshot in between the time of booting the kerenl and
running the app code, without having to write some kind of handshake
betwen guest  the host app. You now also have the problem of
figuring out when the snapshot has become invalid due to host OS
software updates, which I explicitly wanted to avoid by *always*
running the current software directly.

 For comparison I also did a test building a bootable ISO using ISOLinux.
 This required 700 ms for the boot time, which is appoximately 1/2 the
 time reqiured for direct kernel/initrd boot. But you have to then add
 on time required to build the ISO on every boot, to add custom kernel
 command line args. So while ISO is faster than LinuxBoot currently
 there is still non-negligable overhead here that I want to avoid.
 
 You can accept parameters from virtio-serial or some other channel.
 Is there any reason you need them specifically as *kernel* command
 line parameters?

Well some of the parameters are actually kernel parameters :-) The rest
are things I pass to the 'init' process which runs in the initrd. When
this process first starts the only things it can easily access are those
builtin to the kernel image, so data available from /proc or /sys like
the /proc/cmdline file. It hasn't even loaded things like the virtio-serial
or virtio-9pfs kernel modules at this point.

Daniel
-- 
|: http://berrange.com  -o-http://www.flickr.com/photos/dberrange/ :|
|: http://libvirt.org  -o- http://virt-manager.org :|
|: http://autobuild.org   -o- http://search.cpan.org/~danberr/ :|
|: http://entangle-photo.org   -o-   http://live.gnome.org/gtk-vnc :|



Re: [Qemu-devel] Hack integrating SeaBios / LinuxBoot option rom with QEMU trace backends

2011-10-11 Thread Avi Kivity

On 10/11/2011 11:18 AM, Daniel P. Berrange wrote:


  The rep/ins implementation is still slow, optimizing it can help.

  What does 'perf top' say when running this workload?

To ensure it only recorded the LinuxBoot code, I created a 100 MB
kernel image which takes approx 30 seconds to copy. Here is the
perf output for approx 15 seconds of that copy:

  1906.00 15.0% read_hpet   [kernel]


Recent kernels are very clock intensive...


  1029.00  8.1% x86_emulate_insn[kvm]
   863.00  6.8% test_cc [kvm]


test_cc() is wierd - not called on this path at all.


   661.00  5.2% emulator_get_segment[kvm]
   631.00  5.0% kvm_mmu_pte_write   [kvm]
   535.00  4.2% __linearize [kvm]
   431.00  3.4% do_raw_spin_lock[kernel]
   356.00  2.8% vmx_get_segment [kvm_intel]
   330.00  2.6% vmx_segment_cache_test_set  [kvm_intel]
   308.00  2.4% segmented_write [kvm]
   291.00  2.3% vread_hpet  [kernel].vsyscall_fn
   251.00  2.0% vmx_get_cpl [kvm_intel]
   230.00  1.8% trace_kvm_mmu_audit [kvm]
   207.00  1.6% kvm_write_guest [kvm]
   199.00  1.6% emulator_write_emulated [kvm]
   187.00  1.5% emulator_write_emulated_onepage [kvm]
   185.00  1.5% kvm_write_guest_page[kvm]
   177.00  1.4% vmx_get_segment_base[kvm_intel]
   158.00  1.2% fw_cfg_io_readb qemu-system-x86_64


This is where something gets done.


   148.00  1.2% register_address_increment  [kvm]
   142.00  1.1% emulator_write_phys [kvm]


And here too.  So 97.7% overhead, which could be reduced by a factor of 
4096 if the code is made more rep-aware.




--
error compiling committee.c: too many arguments to function




[Qemu-devel] console: Properly switch consoles for screen dumps breaks qxl screen dump

2011-10-11 Thread Alon Levy
Hi Jan,

 I've recently found the $SUBJECT, it's commit
  f81bdefb63243e82d16ce49332f7cf74d10b8f27.

 I'd like to fix it without breaking anything, can you provide me with
 the test that your original patch fixed?

Alon

p.s. for a simple command line with a single console (not even sure how
to get multiple) the following fixes my problem, I expect it doesn't
introduce any problems?


diff --git a/console.c b/console.c
index 6dfcc47..5a709fe 100644
--- a/console.c
+++ b/console.c
@@ -1067,6 +1067,10 @@ void console_select(unsigned int index)
 
 if (index = MAX_CONSOLES)
 return;
+if (active_console == consoles[index]) {
+fprintf(stderr, not changing console, not required\n);
+return;
+}
 if (active_console) {
 active_console-g_width = ds_get_width(active_console-ds);
 active_console-g_height = ds_get_height(active_console-ds);



Re: [Qemu-devel] Slow kernel/initrd loading via fw_cfg; Was Re: Hack integrating SeaBios / LinuxBoot option rom with QEMU trace backends

2011-10-11 Thread Alexander Graf

On 11.10.2011, at 11:26, Avi Kivity wrote:

 On 10/11/2011 11:19 AM, Alexander Graf wrote:
 
   Of this, 1.4 seconds is the time required by LinuxBoot to copy the
   kernel+initrd. If I used an uncompressed initrd, which I really want
   to, to avoid decompression overhead, this increases to ~1.7 seconds.
   So the LinuxBoot ROM is ~60% of total QEMU execution time, or 40%
   of total sandbox execution overhead.
 
   One thing we can do is boot a guest and immediately snapshot it, before 
  it runs any application specific code.  Subsequent invocations will 
  MAP_PRIVATE the memory image and COW their way.  This avoids the kernel 
  initialization time as well.
 
 That doesn't allow modification of -append
 
 Is it really needed?

For our use case for example yes. We pass the cifs user/pass using the kernel 
cmdline, so we can reuse existing initrd code and just mount it as root.

 
 and gets you in a pretty bizarre state when doing updates of your host 
 files, since then you have 2 different paths: full boot and restore. That's 
 yet another potential source for bugs.
 
 Typically you'd check the timestamps to make sure you're running an 
 up-to-date version.

Yes. That's why I said you end up with 2 different boot cases. Now imagine you 
get a bug once every 1 bootups and try to trace that down that it only 
happens when running in the non-resume case.

 
 
 
 
   For comparison I also did a test building a bootable ISO using ISOLinux.
   This required 700 ms for the boot time, which is appoximately 1/2 the
   time reqiured for direct kernel/initrd boot. But you have to then add
   on time required to build the ISO on every boot, to add custom kernel
   command line args. So while ISO is faster than LinuxBoot currently
   there is still non-negligable overhead here that I want to avoid.
 
   You can accept parameters from virtio-serial or some other channel.  Is 
  there any reason you need them specifically as *kernel* command line 
  parameters?
 
 That doesn't work for kernel parameters. It also means things would have to 
 be rewritten needlessly. Some times we can't easily change the way 
 parameters are passed into the guest either, for example when running a 
 random (read: old, think of RHEL5) distro installation initrd.
 
 This use case is not installation, it's for app sandboxing.

I thought we were talking about plenty different use cases here? I'm pretty 
sure there are even more out there that we haven't even thought about.

 
 And I don't see the point why we would have to shoot yet another hole into 
 the guest just because we're too unwilling to make an interface that's 
 perfectly valid horribly slow.
 
 rep/ins is exactly like dma+wait for this use case: provide an address, get a 
 memory image in return.  There's no need to add another interface, we should 
 just optimize the existing one.

Whatever we do, the interface will never be as fast as DMA. We will always have 
to do sanity / permission checks for every IO operation, can batch up only so 
many IO requests and in QEMU again have to call our callbacks in a loop.

I don't see where the problem is in admitting that we were wrong back then. The 
fw_cfg interface as it is is great for small config variables, but nobody sane 
would even consider using IDE without DMA these days for example, because 
you're transferring bulk data. And that's exactly what we do in this case. We 
transfer bulk data.

However, I'll gladly see myself proven wrong with an awesomely fast rep/ins 
implementation that loads 100MB in  1/10th of a second.


Alex




Re: [Qemu-devel] Slow kernel/initrd loading via fw_cfg; Was Re: Hack integrating SeaBios / LinuxBoot option rom with QEMU trace backends

2011-10-11 Thread Avi Kivity

On 10/11/2011 11:27 AM, Daniel P. Berrange wrote:


  One thing we can do is boot a guest and immediately snapshot it,
  before it runs any application specific code.  Subsequent
  invocations will MAP_PRIVATE the memory image and COW their way.
  This avoids the kernel initialization time as well.

This is adding an awful lot of complexity to the process, just
to avoid fixing a performance problem in QEMU.


The performance problem is in the host kernel, not qemu, and I'm 
certainly not against fixing it.  I'm trying to see if we can optimize 
it even further to make it instantaneous.



  You can't even
reliably snapshot in between the time of booting the kerenl and
running the app code, without having to write some kind of handshake
betwen guest  the host app. You now also have the problem of
figuring out when the snapshot has become invalid due to host OS
software updates, which I explicitly wanted to avoid by *always*
running the current software directly.


Sure, it adds complexity, but the improvement may be worth it.



  For comparison I also did a test building a bootable ISO using ISOLinux.
  This required 700 ms for the boot time, which is appoximately 1/2 the
  time reqiured for direct kernel/initrd boot. But you have to then add
  on time required to build the ISO on every boot, to add custom kernel
  command line args. So while ISO is faster than LinuxBoot currently
  there is still non-negligable overhead here that I want to avoid.

  You can accept parameters from virtio-serial or some other channel.
  Is there any reason you need them specifically as *kernel* command
  line parameters?

Well some of the parameters are actually kernel parameters :-) The rest
are things I pass to the 'init' process which runs in the initrd. When
this process first starts the only things it can easily access are those
builtin to the kernel image, so data available from /proc or /sys like
the /proc/cmdline file. It hasn't even loaded things like the virtio-serial
or virtio-9pfs kernel modules at this point.



It could, if it wanted to.  It's completely custom, yes?

--
error compiling committee.c: too many arguments to function




Re: [Qemu-devel] Slow kernel/initrd loading via fw_cfg; Was Re: Hack integrating SeaBios / LinuxBoot option rom with QEMU trace backends

2011-10-11 Thread Daniel P. Berrange
On Tue, Oct 11, 2011 at 11:39:36AM +0200, Avi Kivity wrote:
 On 10/11/2011 11:27 AM, Daniel P. Berrange wrote:
   For comparison I also did a test building a bootable ISO using ISOLinux.
   This required 700 ms for the boot time, which is appoximately 1/2 the
   time reqiured for direct kernel/initrd boot. But you have to then add
   on time required to build the ISO on every boot, to add custom kernel
   command line args. So while ISO is faster than LinuxBoot currently
   there is still non-negligable overhead here that I want to avoid.
 
   You can accept parameters from virtio-serial or some other channel.
   Is there any reason you need them specifically as *kernel* command
   line parameters?
 
 Well some of the parameters are actually kernel parameters :-) The rest
 are things I pass to the 'init' process which runs in the initrd. When
 this process first starts the only things it can easily access are those
 builtin to the kernel image, so data available from /proc or /sys like
 the /proc/cmdline file. It hasn't even loaded things like the virtio-serial
 or virtio-9pfs kernel modules at this point.
 
 
 It could, if it wanted to.  It's completely custom, yes?

I'm thinking primarily about debug related parameters, which need to be
used as soon the process starts, not delayed until after we've loaded
kernel modules at which point the step we wanted to debug is already
past.


Daniel
-- 
|: http://berrange.com  -o-http://www.flickr.com/photos/dberrange/ :|
|: http://libvirt.org  -o- http://virt-manager.org :|
|: http://autobuild.org   -o- http://search.cpan.org/~danberr/ :|
|: http://entangle-photo.org   -o-   http://live.gnome.org/gtk-vnc :|



Re: [Qemu-devel] Slow kernel/initrd loading via fw_cfg; Was Re: Hack integrating SeaBios / LinuxBoot option rom with QEMU trace backends

2011-10-11 Thread Avi Kivity

On 10/11/2011 11:38 AM, Alexander Graf wrote:


  and gets you in a pretty bizarre state when doing updates of your host 
files, since then you have 2 different paths: full boot and restore. That's yet 
another potential source for bugs.

  Typically you'd check the timestamps to make sure you're running an 
up-to-date version.

Yes. That's why I said you end up with 2 different boot cases. Now imagine you 
get a bug once every 1 bootups and try to trace that down that it only 
happens when running in the non-resume case.


That's life in virt land.  If you want nice repeatable bugs write single 
threaded Python.





  
  
 For comparison I also did a test building a bootable ISO using 
ISOLinux.
 This required 700 ms for the boot time, which is appoximately 1/2 the
 time reqiured for direct kernel/initrd boot. But you have to then add
 on time required to build the ISO on every boot, to add custom kernel
 command line args. So while ISO is faster than LinuxBoot currently
 there is still non-negligable overhead here that I want to avoid.
  
 You can accept parameters from virtio-serial or some other channel.  Is 
there any reason you need them specifically as *kernel* command line parameters?

  That doesn't work for kernel parameters. It also means things would have to 
be rewritten needlessly. Some times we can't easily change the way parameters are 
passed into the guest either, for example when running a random (read: old, think of 
RHEL5) distro installation initrd.

  This use case is not installation, it's for app sandboxing.

I thought we were talking about plenty different use cases here? I'm pretty 
sure there are even more out there that we haven't even thought about.


I'm talking about the case he mentioned, not every possible use case.  
Usually booting an ISO image is best since it only loads on demand.





  And I don't see the point why we would have to shoot yet another hole into 
the guest just because we're too unwilling to make an interface that's perfectly 
valid horribly slow.

  rep/ins is exactly like dma+wait for this use case: provide an address, get 
a memory image in return.  There's no need to add another interface, we should 
just optimize the existing one.

Whatever we do, the interface will never be as fast as DMA. We will always have 
to do sanity / permission checks for every IO operation, can batch up only so 
many IO requests and in QEMU again have to call our callbacks in a loop.


We can batch per page, which makes the overhead negligible.


I don't see where the problem is in admitting that we were wrong back then. The 
fw_cfg interface as it is is great for small config variables, but nobody sane 
would even consider using IDE without DMA these days for example, because 
you're transferring bulk data. And that's exactly what we do in this case. We 
transfer bulk data.

However, I'll gladly see myself proven wrong with an awesomely fast rep/ins 
implementation that loads 100MB in  1/10th of a second.



100 MB in 100 ms gives us 1 GB/s, or 4 us per page.  I'm not sure we can 
get exactly there, but pretty close.



--
error compiling committee.c: too many arguments to function




Re: [Qemu-devel] Slow kernel/initrd loading via fw_cfg; Was Re: Hack integrating SeaBios / LinuxBoot option rom with QEMU trace backends

2011-10-11 Thread Avi Kivity

On 10/11/2011 11:49 AM, Daniel P. Berrange wrote:

On Tue, Oct 11, 2011 at 11:39:36AM +0200, Avi Kivity wrote:
  On 10/11/2011 11:27 AM, Daniel P. Berrange wrote:
 For comparison I also did a test building a bootable ISO using 
ISOLinux.
 This required 700 ms for the boot time, which is appoximately 1/2 the
 time reqiured for direct kernel/initrd boot. But you have to then add
 on time required to build the ISO on every boot, to add custom kernel
 command line args. So while ISO is faster than LinuxBoot currently
 there is still non-negligable overhead here that I want to avoid.
  
 You can accept parameters from virtio-serial or some other channel.
 Is there any reason you need them specifically as *kernel* command
 line parameters?
  
  Well some of the parameters are actually kernel parameters :-) The rest
  are things I pass to the 'init' process which runs in the initrd. When
  this process first starts the only things it can easily access are those
  builtin to the kernel image, so data available from /proc or /sys like
  the /proc/cmdline file. It hasn't even loaded things like the virtio-serial
  or virtio-9pfs kernel modules at this point.
  

  It could, if it wanted to.  It's completely custom, yes?

I'm thinking primarily about debug related parameters, which need to be
used as soon the process starts, not delayed until after we've loaded
kernel modules at which point the step we wanted to debug is already
past.


Ah, so there's no issue in regenerating the image if you want to debug.

--
error compiling committee.c: too many arguments to function




Re: [Qemu-devel] Slow kernel/initrd loading via fw_cfg; Was Re: Hack integrating SeaBios / LinuxBoot option rom with QEMU trace backends

2011-10-11 Thread Gleb Natapov
On Tue, Oct 11, 2011 at 11:26:14AM +0200, Avi Kivity wrote:
 rep/ins is exactly like dma+wait for this use case: provide an
 address, get a memory image in return.  There's no need to add
 another interface, we should just optimize the existing one.
 
rep/ins cannot be optimized to be as efficient as dma and remain to
be correct at the same time. There are various corner cases that
simplified fast implementation will likely miss. Like DF flag
settings, delaying interrupts for too much, doing ins/outs to/from
iomem (this is may be not a big problem unless userspace finds a way
to trigger it). There are ways that current implementation can be
optimized still though. 

But loading MBs of data through fw_cfg interface is just abusing it.
You wouldn't use pio on real HW to move megabytes of data and expect
good performance. 


--
Gleb.



Re: [Qemu-devel] Slow kernel/initrd loading via fw_cfg; Was Re: Hack integrating SeaBios / LinuxBoot option rom with QEMU trace backends

2011-10-11 Thread Avi Kivity

On 10/11/2011 11:50 AM, Gleb Natapov wrote:

On Tue, Oct 11, 2011 at 11:26:14AM +0200, Avi Kivity wrote:
  rep/ins is exactly like dma+wait for this use case: provide an
  address, get a memory image in return.  There's no need to add
  another interface, we should just optimize the existing one.

rep/ins cannot be optimized to be as efficient as dma and remain to
be correct at the same time. There are various corner cases that
simplified fast implementation will likely miss. Like DF flag
settings, delaying interrupts for too much, doing ins/outs to/from
iomem (this is may be not a big problem unless userspace finds a way
to trigger it). There are ways that current implementation can be
optimized still though.


These can all go through the slow path, except interrupts, which need to 
be checked after every access.



But loading MBs of data through fw_cfg interface is just abusing it.
You wouldn't use pio on real HW to move megabytes of data and expect
good performance.


True, this is a point in favour of a true dma interface.

--
error compiling committee.c: too many arguments to function




Re: [Qemu-devel] Slow kernel/initrd loading via fw_cfg; Was Re: Hack integrating SeaBios / LinuxBoot option rom with QEMU trace backends

2011-10-11 Thread Gleb Natapov
On Tue, Oct 11, 2011 at 11:49:16AM +0200, Avi Kivity wrote:
 Whatever we do, the interface will never be as fast as DMA. We will always 
 have to do sanity / permission checks for every IO operation, can batch up 
 only so many IO requests and in QEMU again have to call our callbacks in a 
 loop.
 
 We can batch per page, which makes the overhead negligible.
 
Current code batch userspace exit per 1024 bytes IIRC and changing it to
page didn't show significant improvement (also IIRC). But after io data
is copied into the kernel emulator process it byte by byte. Possible
optimization, which I didn't tried, is to check that destination memory is
not mmio and write back the whole buffer if it is the case.

--
Gleb.



Re: [Qemu-devel] Slow kernel/initrd loading via fw_cfg; Was Re: Hack integrating SeaBios / LinuxBoot option rom with QEMU trace backends

2011-10-11 Thread Avi Kivity

On 10/11/2011 11:56 AM, Gleb Natapov wrote:

On Tue, Oct 11, 2011 at 11:49:16AM +0200, Avi Kivity wrote:
  Whatever we do, the interface will never be as fast as DMA. We will always 
have to do sanity / permission checks for every IO operation, can batch up only so 
many IO requests and in QEMU again have to call our callbacks in a loop.

  We can batch per page, which makes the overhead negligible.

Current code batch userspace exit per 1024 bytes IIRC and changing it to
page didn't show significant improvement (also IIRC). But after io data
is copied into the kernel emulator process it byte by byte. Possible
optimization, which I didn't tried, is to check that destination memory is
not mmio and write back the whole buffer if it is the case.



All the permission checks, segment checks, register_address_increment, 
page table walking, can be done per page.  Right now they are done per byte.


btw Intel also made this optimization, current processors copy complete 
cache lines instead of bytes, so they probably also do the checks just once.


--
error compiling committee.c: too many arguments to function




[Qemu-devel] [PATCH v4 00/36] Migration errors cleanup (the integrated version)

2011-10-11 Thread Juan Quintela
Hi

v4:

- rebase on top of new qemu and new migration-errors series
- integrate back erros  cleanup series
- s/MIG_STATE_NONE/MIG_STATE_SETUP/ (Orit suggestion)
- s/migrate_create_state/migrate_new/ (Anthony suggestion)
- Add migrate_get_current() accessor.
- make has_error contain the errno instead of a bool
- rename qemu_file_has_error() - qemu_file_get_error()
- rename has_error field into last_error
- migration_state_notifiers now pass MigrationState pointer


v3:
this patch applies on top of my previous migration error
patches.  All error handling has been moved to that series,
except for propagate error correctly, without this
refactoring, it is quite complicated to apply it.

Please, review.

Later, Juan.

v3:
- more checkpatch.pl happines
- split error handling in a previous series
- make Anthony happy.  current_migration is still a pointer, but points to
  a static variable.  We can change current_migration when we integrate
  kemari.

v2:
- make Jan^Wcheckpatch.pl happy
- Yoshiaki Tamura suggestions:
  - include its two patches to clean things
  - MAX_THROTTLE define
  - migration_state enum
- I removed spurious differences between migration-{tcp,unix}
- better error propagation, after this patch:
   migrate -d tcp:name_don_exist:port
   migrate -d tcp:name:port_dont_exist
   migrate -d exec: prog_dont_exist
   migrate -d exec: gzip  /path/dont/exist
 fail as expected.  Last two used to enter an infinite loop.

The fixes part should be backported to 0.14, waiting for the review to do that.

Later, Juan.

v1:
This series:
- Fold MigrationState into FdMigrationState (and then rename)
- Factorize migration statec creation in a single place
- Make use of MIG_STATE_*, setup through helpers and make them local
- remove relase  cancel callbacks (where used only one in same
  file than defined)
- get_status() is no more, just access directly to .state
- current_migration use cleanup, and make variable static
- max_throotle is gone, now inside current_migration
- change get_migration_status() to migration_has_finished()
  and actualize single user.

Please review.

Later, Juan.


Juan Quintela (35):
  ds1225y: Use stdio instead of QEMUFile
  migration: simplify state assignmente
  migration: Check that migration is active before cancel it
  migration: return real error code
  migration: If there is one error, it makes no sense to continue
  buffered_file: Use right opaque
  buffered_file: reuse QEMUFile has_error field
  migration: don't write when migration is not active
  migration: set error if select return one error
  migration: change has_error to contain errno values
  migration: rename qemu_file_has_error to qemu_file_get_error
  savevm: Rename has_error to last_error field
  migration: use qemu_file_get_error() return value when possible
  migration: Make *start_outgoing_migration return FdMigrationState
  migration: Use FdMigrationState instead of MigrationState when
possible
  migration: Fold MigrationState into FdMigrationState
  migration: Rename FdMigrationState MigrationState
  migration: Refactor MigrationState creation
  migration: Make all posible migration functions static
  migration: move migrate_new to do_migrate
  migration: Introduce MIG_STATE_SETUP
  migration: Refactor and simplify error checking in
migrate_fd_put_ready
  migration: Introduce migrate_fd_completed() for consistency
  migration: Our release callback was just free
  migration: Remove get_status() accessor
  migration: Remove migration cancel() callback
  migration: Move exported functions to the end of the file
  migration: create accessor for current_migration
  migration: Use bandwidth_limit directly
  migration: Pass MigrationState in migration notifiers
  migration: Export a function that tells if the migration has finished
correctly
  migration: Make state definitions local
  migration: Don't use callback on file defining it
  migration: propagate error correctly
  migration: make migration-{tcp,unix} consistent

Yoshiaki Tamura (1):
  migration: add error handling to migrate_fd_put_notify().

 arch_init.c   |8 +-
 block-migration.c |   19 ++-
 buffered_file.c   |   34 +++--
 hw/ds1225y.c  |   28 ++--
 hw/hw.h   |4 +-
 migration-exec.c  |   39 +
 migration-fd.c|   42 +
 migration-tcp.c   |   76 --
 migration-unix.c  |  113 ++-
 migration.c   |  439 +++--
 migration.h   |   85 ++-
 savevm.c  |   58 
 ui/spice-core.c   |4 +-
 13 files changed, 412 insertions(+), 537 deletions(-)

-- 
1.7.6.4




[Qemu-devel] [PATCH 03/36] migration: Check that migration is active before cancel it

2011-10-11 Thread Juan Quintela
Signed-off-by: Juan Quintela quint...@redhat.com
---
 migration.c |4 ++--
 1 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/migration.c b/migration.c
index 7fd6c23..71b8aad 100644
--- a/migration.c
+++ b/migration.c
@@ -133,9 +133,9 @@ int do_migrate_cancel(Monitor *mon, const QDict *qdict, 
QObject **ret_data)
 {
 MigrationState *s = current_migration;

-if (s)
+if (s  s-get_status(s) == MIG_STATE_ACTIVE) {
 s-cancel(s);
-
+}
 return 0;
 }

-- 
1.7.6.4





[Qemu-devel] [PATCH 01/36] ds1225y: Use stdio instead of QEMUFile

2011-10-11 Thread Juan Quintela
QEMUFile * is only intended for migration nowadays.  Using it for
anything else just adds pain and a layer of buffers for no good
reason.

Signed-off-by: Juan Quintela quint...@redhat.com
---
 hw/ds1225y.c |   28 
 1 files changed, 16 insertions(+), 12 deletions(-)

diff --git a/hw/ds1225y.c b/hw/ds1225y.c
index 9875c44..6852a61 100644
--- a/hw/ds1225y.c
+++ b/hw/ds1225y.c
@@ -29,7 +29,7 @@ typedef struct {
 DeviceState qdev;
 uint32_t chip_size;
 char *filename;
-QEMUFile *file;
+FILE *file;
 uint8_t *contents;
 } NvRamState;

@@ -70,9 +70,9 @@ static void nvram_writeb (void *opaque, target_phys_addr_t 
addr, uint32_t val)

 s-contents[addr] = val;
 if (s-file) {
-qemu_fseek(s-file, addr, SEEK_SET);
-qemu_put_byte(s-file, (int)val);
-qemu_fflush(s-file);
+fseek(s-file, addr, SEEK_SET);
+fputc(val, s-file);
+fflush(s-file);
 }
 }

@@ -108,15 +108,17 @@ static int nvram_post_load(void *opaque, int version_id)

 /* Close file, as filename may has changed in load/store process */
 if (s-file) {
-qemu_fclose(s-file);
+fclose(s-file);
 }

 /* Write back nvram contents */
-s-file = qemu_fopen(s-filename, wb);
+s-file = fopen(s-filename, wb);
 if (s-file) {
 /* Write back contents, as 'wb' mode cleaned the file */
-qemu_put_buffer(s-file, s-contents, s-chip_size);
-qemu_fflush(s-file);
+if (fwrite(s-contents, s-chip_size, 1, s-file) != 1) {
+printf(nvram_post_load: short write\n);
+}
+fflush(s-file);
 }

 return 0;
@@ -143,7 +145,7 @@ typedef struct {
 static int nvram_sysbus_initfn(SysBusDevice *dev)
 {
 NvRamState *s = FROM_SYSBUS(SysBusNvRamState, dev)-nvram;
-QEMUFile *file;
+FILE *file;
 int s_io;

 s-contents = g_malloc0(s-chip_size);
@@ -153,11 +155,13 @@ static int nvram_sysbus_initfn(SysBusDevice *dev)
 sysbus_init_mmio(dev, s-chip_size, s_io);

 /* Read current file */
-file = qemu_fopen(s-filename, rb);
+file = fopen(s-filename, rb);
 if (file) {
 /* Read nvram contents */
-qemu_get_buffer(file, s-contents, s-chip_size);
-qemu_fclose(file);
+if (fread(s-contents, s-chip_size, 1, file) != 1) {
+printf(nvram_sysbus_initfn: short read\n);
+}
+fclose(file);
 }
 nvram_post_load(s, 0);

-- 
1.7.6.4




[Qemu-devel] [PATCH 11/36] migration: change has_error to contain errno values

2011-10-11 Thread Juan Quintela
We normally already have an errno value.  When not, abuse EINVAL.

Signed-off-by: Juan Quintela quint...@redhat.com
---
 arch_init.c   |2 +-
 block-migration.c |6 +++---
 buffered_file.c   |4 ++--
 hw/hw.h   |2 +-
 migration.c   |2 +-
 savevm.c  |8 
 6 files changed, 12 insertions(+), 12 deletions(-)

diff --git a/arch_init.c b/arch_init.c
index a6c69c7..941d585 100644
--- a/arch_init.c
+++ b/arch_init.c
@@ -263,7 +263,7 @@ int ram_save_live(Monitor *mon, QEMUFile *f, int stage, 
void *opaque)
 }

 if (cpu_physical_sync_dirty_bitmap(0, TARGET_PHYS_ADDR_MAX) != 0) {
-qemu_file_set_error(f);
+qemu_file_set_error(f, -EINVAL);
 return 0;
 }

diff --git a/block-migration.c b/block-migration.c
index e2775ee..2638f51 100644
--- a/block-migration.c
+++ b/block-migration.c
@@ -263,7 +263,7 @@ static int mig_save_device_bulk(Monitor *mon, QEMUFile *f,

 error:
 monitor_printf(mon, Error reading sector % PRId64 \n, cur_sector);
-qemu_file_set_error(f);
+qemu_file_set_error(f, -EINVAL);
 g_free(blk-buf);
 g_free(blk);
 return 0;
@@ -439,7 +439,7 @@ static int mig_save_device_dirty(Monitor *mon, QEMUFile *f,

 error:
 monitor_printf(mon, Error reading sector % PRId64 \n, sector);
-qemu_file_set_error(f);
+qemu_file_set_error(f, -EINVAL);
 g_free(blk-buf);
 g_free(blk);
 return 0;
@@ -473,7 +473,7 @@ static void flush_blks(QEMUFile* f)
 break;
 }
 if (blk-ret  0) {
-qemu_file_set_error(f);
+qemu_file_set_error(f, -EINVAL);
 break;
 }
 blk_send(f, blk);
diff --git a/buffered_file.c b/buffered_file.c
index 3dadec0..3e5333c 100644
--- a/buffered_file.c
+++ b/buffered_file.c
@@ -92,7 +92,7 @@ static void buffered_flush(QEMUFileBuffered *s)

 if (ret = 0) {
 DPRINTF(error flushing data, %zd\n, ret);
-qemu_file_set_error(s-file);
+qemu_file_set_error(s-file, ret);
 break;
 } else {
 DPRINTF(flushed %zd byte(s)\n, ret);
@@ -138,7 +138,7 @@ static int buffered_put_buffer(void *opaque, const uint8_t 
*buf, int64_t pos, in

 if (ret = 0) {
 DPRINTF(error putting\n);
-qemu_file_set_error(s-file);
+qemu_file_set_error(s-file, ret);
 offset = -EINVAL;
 break;
 }
diff --git a/hw/hw.h b/hw/hw.h
index a124da9..6cf8cd2 100644
--- a/hw/hw.h
+++ b/hw/hw.h
@@ -86,7 +86,7 @@ int qemu_file_rate_limit(QEMUFile *f);
 int64_t qemu_file_set_rate_limit(QEMUFile *f, int64_t new_rate);
 int64_t qemu_file_get_rate_limit(QEMUFile *f);
 int qemu_file_has_error(QEMUFile *f);
-void qemu_file_set_error(QEMUFile *f);
+void qemu_file_set_error(QEMUFile *f, int error);

 /* Try to send any outstanding data.  This function is useful when output is
  * halted due to rate limiting or EAGAIN errors occur as it can be used to
diff --git a/migration.c b/migration.c
index 56c2b1c..541da98 100644
--- a/migration.c
+++ b/migration.c
@@ -459,7 +459,7 @@ void migrate_fd_wait_for_unfreeze(void *opaque)
 } while (ret == -1  (s-get_error(s)) == EINTR);

 if (ret == -1) {
-qemu_file_set_error(s-file);
+qemu_file_set_error(s-file, s-get_error(s));
 }
 }

diff --git a/savevm.c b/savevm.c
index 15c9c52..8bc7272 100644
--- a/savevm.c
+++ b/savevm.c
@@ -430,9 +430,9 @@ int qemu_file_has_error(QEMUFile *f)
 return f-has_error;
 }

-void qemu_file_set_error(QEMUFile *f)
+void qemu_file_set_error(QEMUFile *f, int ret)
 {
-f-has_error = 1;
+f-has_error = ret;
 }

 void qemu_fflush(QEMUFile *f)
@@ -447,7 +447,7 @@ void qemu_fflush(QEMUFile *f)
 if (len  0)
 f-buf_offset += f-buf_index;
 else
-f-has_error = 1;
+f-has_error = -EINVAL;
 f-buf_index = 0;
 }
 }
@@ -468,7 +468,7 @@ static void qemu_fill_buffer(QEMUFile *f)
 f-buf_size = len;
 f-buf_offset += len;
 } else if (len != -EAGAIN)
-f-has_error = 1;
+f-has_error = len;
 }

 int qemu_fclose(QEMUFile *f)
-- 
1.7.6.4




[Qemu-devel] [PATCH 12/36] migration: rename qemu_file_has_error to qemu_file_get_error

2011-10-11 Thread Juan Quintela
Now the function returned errno, so it is better the new name.

Signed-off-by: Juan Quintela quint...@redhat.com
---
 arch_init.c   |2 +-
 block-migration.c |8 
 buffered_file.c   |   14 +++---
 hw/hw.h   |2 +-
 migration.c   |2 +-
 savevm.c  |   13 +++--
 6 files changed, 21 insertions(+), 20 deletions(-)

diff --git a/arch_init.c b/arch_init.c
index 941d585..9128be0 100644
--- a/arch_init.c
+++ b/arch_init.c
@@ -451,7 +451,7 @@ int ram_load(QEMUFile *f, void *opaque, int version_id)

 qemu_get_buffer(f, host, TARGET_PAGE_SIZE);
 }
-if (qemu_file_has_error(f)) {
+if (qemu_file_get_error(f)) {
 return -EIO;
 }
 } while (!(flags  RAM_SAVE_FLAG_EOS));
diff --git a/block-migration.c b/block-migration.c
index 2638f51..8308753 100644
--- a/block-migration.c
+++ b/block-migration.c
@@ -579,7 +579,7 @@ static int block_save_live(Monitor *mon, QEMUFile *f, int 
stage, void *opaque)

 flush_blks(f);

-if (qemu_file_has_error(f)) {
+if (qemu_file_get_error(f)) {
 blk_mig_cleanup(mon);
 return 0;
 }
@@ -607,7 +607,7 @@ static int block_save_live(Monitor *mon, QEMUFile *f, int 
stage, void *opaque)

 flush_blks(f);

-if (qemu_file_has_error(f)) {
+if (qemu_file_get_error(f)) {
 blk_mig_cleanup(mon);
 return 0;
 }
@@ -624,7 +624,7 @@ static int block_save_live(Monitor *mon, QEMUFile *f, int 
stage, void *opaque)
 /* report completion */
 qemu_put_be64(f, (100  BDRV_SECTOR_BITS) | BLK_MIG_FLAG_PROGRESS);

-if (qemu_file_has_error(f)) {
+if (qemu_file_get_error(f)) {
 return 0;
 }

@@ -704,7 +704,7 @@ static int block_load(QEMUFile *f, void *opaque, int 
version_id)
 fprintf(stderr, Unknown flags\n);
 return -EINVAL;
 }
-if (qemu_file_has_error(f)) {
+if (qemu_file_get_error(f)) {
 return -EIO;
 }
 } while (!(flags  BLK_MIG_FLAG_EOS));
diff --git a/buffered_file.c b/buffered_file.c
index 3e5333c..82f4001 100644
--- a/buffered_file.c
+++ b/buffered_file.c
@@ -72,7 +72,7 @@ static void buffered_flush(QEMUFileBuffered *s)
 {
 size_t offset = 0;

-if (qemu_file_has_error(s-file)) {
+if (qemu_file_get_error(s-file)) {
 DPRINTF(flush when error, bailing\n);
 return;
 }
@@ -113,7 +113,7 @@ static int buffered_put_buffer(void *opaque, const uint8_t 
*buf, int64_t pos, in

 DPRINTF(putting %d bytes at % PRId64 \n, size, pos);

-if (qemu_file_has_error(s-file)) {
+if (qemu_file_get_error(s-file)) {
 DPRINTF(flush when error, bailing\n);
 return -EINVAL;
 }
@@ -172,7 +172,7 @@ static int buffered_close(void *opaque)

 DPRINTF(closing\n);

-while (!qemu_file_has_error(s-file)  s-buffer_size) {
+while (!qemu_file_get_error(s-file)  s-buffer_size) {
 buffered_flush(s);
 if (s-freeze_output)
 s-wait_for_unfreeze(s-opaque);
@@ -192,7 +192,7 @@ static int buffered_rate_limit(void *opaque)
 {
 QEMUFileBuffered *s = opaque;

-if (qemu_file_has_error(s-file)) {
+if (qemu_file_get_error(s-file)) {
 return 1;
 }
 if (s-freeze_output)
@@ -207,9 +207,9 @@ static int buffered_rate_limit(void *opaque)
 static int64_t buffered_set_rate_limit(void *opaque, int64_t new_rate)
 {
 QEMUFileBuffered *s = opaque;
-if (qemu_file_has_error(s-file))
+if (qemu_file_get_error(s-file)) {
 goto out;
-
+}
 if (new_rate  SIZE_MAX) {
 new_rate = SIZE_MAX;
 }
@@ -231,7 +231,7 @@ static void buffered_rate_tick(void *opaque)
 {
 QEMUFileBuffered *s = opaque;

-if (qemu_file_has_error(s-file)) {
+if (qemu_file_get_error(s-file)) {
 buffered_close(s);
 return;
 }
diff --git a/hw/hw.h b/hw/hw.h
index 6cf8cd2..ed20f5a 100644
--- a/hw/hw.h
+++ b/hw/hw.h
@@ -85,7 +85,7 @@ uint64_t qemu_get_be64(QEMUFile *f);
 int qemu_file_rate_limit(QEMUFile *f);
 int64_t qemu_file_set_rate_limit(QEMUFile *f, int64_t new_rate);
 int64_t qemu_file_get_rate_limit(QEMUFile *f);
-int qemu_file_has_error(QEMUFile *f);
+int qemu_file_get_error(QEMUFile *f);
 void qemu_file_set_error(QEMUFile *f, int error);

 /* Try to send any outstanding data.  This function is useful when output is
diff --git a/migration.c b/migration.c
index 541da98..6bac734 100644
--- a/migration.c
+++ b/migration.c
@@ -313,7 +313,7 @@ void migrate_fd_put_notify(void *opaque)

 qemu_set_fd_handler2(s-fd, NULL, NULL, NULL, NULL);
 qemu_file_put_notify(s-file);
-if (qemu_file_has_error(s-file)) {
+if (qemu_file_get_error(s-file)) {
 migrate_fd_error(s);
 }
 }
diff --git a/savevm.c b/savevm.c
index 8bc7272..c037eb3 100644
--- a/savevm.c
+++ b/savevm.c
@@ -425,7 +425,7 @@ QEMUFile *qemu_fopen_ops(void *opaque, 
QEMUFilePutBufferFunc *put_buffer,
 return f;
 }

-int 

[Qemu-devel] [PATCH 22/36] migration: Introduce MIG_STATE_SETUP

2011-10-11 Thread Juan Quintela
Use MIG_STATE_ACTIVE only when migration has really started.  Use this
new state to setup migration parameters.

Signed-off-by: Juan Quintela quint...@redhat.com
---
 migration.c |6 +-
 migration.h |   11 +++
 2 files changed, 12 insertions(+), 5 deletions(-)

diff --git a/migration.c b/migration.c
index e93f3f7..a01bf4f 100644
--- a/migration.c
+++ b/migration.c
@@ -239,6 +239,9 @@ void do_info_migrate(Monitor *mon, QObject **ret_data)
 MigrationState *s = current_migration;

 switch (s-get_status(current_migration)) {
+case MIG_STATE_SETUP:
+/* no migration has happened ever */
+break;
 case MIG_STATE_ACTIVE:
 qdict = qdict_new();
 qdict_put(qdict, status, qstring_from_str(active));
@@ -478,6 +481,7 @@ void migrate_fd_connect(MigrationState *s)
 {
 int ret;

+s-state = MIG_STATE_ACTIVE;
 s-file = qemu_fopen_ops_buffered(s,
   s-bandwidth_limit,
   migrate_fd_put_buffer,
@@ -507,7 +511,7 @@ static MigrationState *migrate_new(Monitor *mon, int64_t 
bandwidth_limit,
 s-shared = inc;
 s-mon = NULL;
 s-bandwidth_limit = bandwidth_limit;
-s-state = MIG_STATE_ACTIVE;
+s-state = MIG_STATE_SETUP;

 if (!detach) {
 migrate_fd_monitor_suspend(s, mon);
diff --git a/migration.h b/migration.h
index 14c3ebc..3165140 100644
--- a/migration.h
+++ b/migration.h
@@ -18,10 +18,13 @@
 #include qemu-common.h
 #include notify.h

-#define MIG_STATE_ERROR-1
-#define MIG_STATE_COMPLETED0
-#define MIG_STATE_CANCELLED1
-#define MIG_STATE_ACTIVE   2
+enum migration_state {
+MIG_STATE_ERROR,
+MIG_STATE_SETUP,
+MIG_STATE_CANCELLED,
+MIG_STATE_ACTIVE,
+MIG_STATE_COMPLETED,
+};

 typedef struct MigrationState MigrationState;

-- 
1.7.6.4




[Qemu-devel] [PATCH 28/36] migration: Move exported functions to the end of the file

2011-10-11 Thread Juan Quintela
This means we can remove the two forward declarations.

Signed-off-by: Juan Quintela quint...@redhat.com
Reviewed-by: Anthony Liguori aligu...@us.ibm.com
---
 migration.c |  187 +--
 1 files changed, 91 insertions(+), 96 deletions(-)

diff --git a/migration.c b/migration.c
index 33e89a2..73d66d9 100644
--- a/migration.c
+++ b/migration.c
@@ -77,90 +77,6 @@ void process_incoming_migration(QEMUFile *f)
 }
 }

-static MigrationState *migrate_new(Monitor *mon, int64_t bandwidth_limit,
-   int detach, int blk, int inc);
-
-int do_migrate(Monitor *mon, const QDict *qdict, QObject **ret_data)
-{
-MigrationState *s = NULL;
-const char *p;
-int detach = qdict_get_try_bool(qdict, detach, 0);
-int blk = qdict_get_try_bool(qdict, blk, 0);
-int inc = qdict_get_try_bool(qdict, inc, 0);
-const char *uri = qdict_get_str(qdict, uri);
-int ret;
-
-if (current_migration 
-current_migration-state == MIG_STATE_ACTIVE) {
-monitor_printf(mon, migration already in progress\n);
-return -1;
-}
-
-if (qemu_savevm_state_blocked(mon)) {
-return -1;
-}
-
-s = migrate_new(mon, max_throttle, detach, blk, inc);
-
-if (strstart(uri, tcp:, p)) {
-ret = tcp_start_outgoing_migration(s, p);
-#if !defined(WIN32)
-} else if (strstart(uri, exec:, p)) {
-ret = exec_start_outgoing_migration(s, p);
-} else if (strstart(uri, unix:, p)) {
-ret = unix_start_outgoing_migration(s, p);
-} else if (strstart(uri, fd:, p)) {
-ret = fd_start_outgoing_migration(s, p);
-#endif
-} else {
-monitor_printf(mon, unknown migration protocol: %s\n, uri);
-ret  = -EINVAL;
-goto free_migrate_state;
-}
-
-if (ret  0) {
-monitor_printf(mon, migration failed\n);
-goto free_migrate_state;
-}
-
-g_free(current_migration);
-current_migration = s;
-notifier_list_notify(migration_state_notifiers, NULL);
-return 0;
-free_migrate_state:
-g_free(s);
-return -1;
-}
-
-static void migrate_fd_cancel(MigrationState *s);
-
-int do_migrate_cancel(Monitor *mon, const QDict *qdict, QObject **ret_data)
-{
-if (current_migration) {
-migrate_fd_cancel(current_migration);
-}
-return 0;
-}
-
-int do_migrate_set_speed(Monitor *mon, const QDict *qdict, QObject **ret_data)
-{
-int64_t d;
-MigrationState *s;
-
-d = qdict_get_int(qdict, value);
-if (d  0) {
-d = 0;
-}
-max_throttle = d;
-
-s = current_migration;
-if (s  s-file) {
-qemu_file_set_rate_limit(s-file, max_throttle);
-}
-
-return 0;
-}
-
 /* amount of nanoseconds we are willing to wait for migration to be down.
  * the choice of nanoseconds is because it is the maximum resolution that
  * get_clock() can achieve. It is an internal measure. All user-visible
@@ -172,18 +88,6 @@ uint64_t migrate_max_downtime(void)
 return max_downtime;
 }

-int do_migrate_set_downtime(Monitor *mon, const QDict *qdict,
-QObject **ret_data)
-{
-double d;
-
-d = qdict_get_double(qdict, value) * 1e9;
-d = MAX(0, MIN(UINT64_MAX, d));
-max_downtime = (uint64_t)d;
-
-return 0;
-}
-
 static void migrate_print_status(Monitor *mon, const char *name,
  const QDict *status_dict)
 {
@@ -500,3 +404,94 @@ static MigrationState *migrate_new(Monitor *mon, int64_t 
bandwidth_limit,

 return s;
 }
+
+int do_migrate(Monitor *mon, const QDict *qdict, QObject **ret_data)
+{
+MigrationState *s = NULL;
+const char *p;
+int detach = qdict_get_try_bool(qdict, detach, 0);
+int blk = qdict_get_try_bool(qdict, blk, 0);
+int inc = qdict_get_try_bool(qdict, inc, 0);
+const char *uri = qdict_get_str(qdict, uri);
+int ret;
+
+if (current_migration 
+current_migration-state == MIG_STATE_ACTIVE) {
+monitor_printf(mon, migration already in progress\n);
+return -1;
+}
+
+if (qemu_savevm_state_blocked(mon)) {
+return -1;
+}
+
+s = migrate_new(mon, max_throttle, detach, blk, inc);
+
+if (strstart(uri, tcp:, p)) {
+ret = tcp_start_outgoing_migration(s, p);
+#if !defined(WIN32)
+} else if (strstart(uri, exec:, p)) {
+ret = exec_start_outgoing_migration(s, p);
+} else if (strstart(uri, unix:, p)) {
+ret = unix_start_outgoing_migration(s, p);
+} else if (strstart(uri, fd:, p)) {
+ret = fd_start_outgoing_migration(s, p);
+#endif
+} else {
+monitor_printf(mon, unknown migration protocol: %s\n, uri);
+ret  = -EINVAL;
+goto free_migrate_state;
+}
+
+if (ret  0) {
+monitor_printf(mon, migration failed\n);
+goto free_migrate_state;
+}
+
+g_free(current_migration);
+current_migration = s;
+notifier_list_notify(migration_state_notifiers, NULL);
+return 0;

[Qemu-devel] [PATCH 34/36] migration: Don't use callback on file defining it

2011-10-11 Thread Juan Quintela
Signed-off-by: Juan Quintela quint...@redhat.com
---
 migration-tcp.c  |4 ++--
 migration-unix.c |6 +++---
 2 files changed, 5 insertions(+), 5 deletions(-)

diff --git a/migration-tcp.c b/migration-tcp.c
index f6b2288..bd3aa3a 100644
--- a/migration-tcp.c
+++ b/migration-tcp.c
@@ -58,7 +58,7 @@ static void tcp_wait_for_connect(void *opaque)
 DPRINTF(connect completed\n);
 do {
 ret = getsockopt(s-fd, SOL_SOCKET, SO_ERROR, (void *) val, valsize);
-} while (ret == -1  (s-get_error(s)) == EINTR);
+} while (ret == -1  (socket_error()) == EINTR);

 if (ret  0) {
 migrate_fd_error(s);
@@ -98,7 +98,7 @@ int tcp_start_outgoing_migration(MigrationState *s, const 
char *host_port)
 do {
 ret = connect(s-fd, (struct sockaddr *)addr, sizeof(addr));
 if (ret == -1)
-ret = -(s-get_error(s));
+ret = -(socket_error());

 if (ret == -EINPROGRESS || ret == -EWOULDBLOCK)
 qemu_set_fd_handler2(s-fd, NULL, NULL, tcp_wait_for_connect, s);
diff --git a/migration-unix.c b/migration-unix.c
index bd8d40f..ca66851 100644
--- a/migration-unix.c
+++ b/migration-unix.c
@@ -57,7 +57,7 @@ static void unix_wait_for_connect(void *opaque)
 DPRINTF(connect completed\n);
 do {
 ret = getsockopt(s-fd, SOL_SOCKET, SO_ERROR, (void *) val, valsize);
-} while (ret == -1  (s-get_error(s)) == EINTR);
+} while (ret == -1  errno == EINTR);

 if (ret  0) {
 migrate_fd_error(s);
@@ -96,7 +96,7 @@ int unix_start_outgoing_migration(MigrationState *s, const 
char *path)
 do {
 ret = connect(s-fd, (struct sockaddr *)addr, sizeof(addr));
 if (ret == -1)
-   ret = -(s-get_error(s));
+ret = -errno;

 if (ret == -EINPROGRESS || ret == -EWOULDBLOCK)
qemu_set_fd_handler2(s-fd, NULL, NULL, unix_wait_for_connect, s);
@@ -129,7 +129,7 @@ static void unix_accept_incoming_migration(void *opaque)

 do {
 c = qemu_accept(s, (struct sockaddr *)addr, addrlen);
-} while (c == -1  socket_error() == EINTR);
+} while (c == -1  errno == EINTR);

 DPRINTF(accepted migration\n);

-- 
1.7.6.4




[Qemu-devel] [PATCH 35/36] migration: propagate error correctly

2011-10-11 Thread Juan Quintela
unix and tcp outgoing migration have error values, but didn't returned
it.  Make them return the error.  Notice that EINPROGRESS  EWOULDBLOCK
are not considered errors as call will be retry later.

Signed-off-by: Juan Quintela quint...@redhat.com
Reviewed-by: Anthony Liguori aligu...@us.ibm.com
---
 migration-tcp.c  |   20 +++-
 migration-unix.c |   26 ++
 2 files changed, 21 insertions(+), 25 deletions(-)

diff --git a/migration-tcp.c b/migration-tcp.c
index bd3aa3a..619df21 100644
--- a/migration-tcp.c
+++ b/migration-tcp.c
@@ -90,26 +90,28 @@ int tcp_start_outgoing_migration(MigrationState *s, const 
char *host_port)

 s-fd = qemu_socket(PF_INET, SOCK_STREAM, 0);
 if (s-fd == -1) {
-return -1;
+return -socket_error();
 }

 socket_set_nonblock(s-fd);

 do {
 ret = connect(s-fd, (struct sockaddr *)addr, sizeof(addr));
-if (ret == -1)
-ret = -(socket_error());
-
-if (ret == -EINPROGRESS || ret == -EWOULDBLOCK)
+if (ret == -1) {
+ret = -socket_error();
+}
+if (ret == -EINPROGRESS || ret == -EWOULDBLOCK) {
 qemu_set_fd_handler2(s-fd, NULL, NULL, tcp_wait_for_connect, s);
+return 0;
+}
 } while (ret == -EINTR);

-if (ret  0  ret != -EINPROGRESS  ret != -EWOULDBLOCK) {
+if (ret  0) {
 DPRINTF(connect failed\n);
 migrate_fd_error(s);
-} else if (ret = 0)
-migrate_fd_connect(s);
-
+return ret;
+}
+migrate_fd_connect(s);
 return 0;
 }

diff --git a/migration-unix.c b/migration-unix.c
index ca66851..f979b5f 100644
--- a/migration-unix.c
+++ b/migration-unix.c
@@ -88,35 +88,29 @@ int unix_start_outgoing_migration(MigrationState *s, const 
char *path)
 s-fd = qemu_socket(PF_UNIX, SOCK_STREAM, 0);
 if (s-fd  0) {
 DPRINTF(Unable to open socket);
-goto err_after_socket;
+return -errno;
 }

 socket_set_nonblock(s-fd);

 do {
 ret = connect(s-fd, (struct sockaddr *)addr, sizeof(addr));
-if (ret == -1)
+if (ret == -1) {
 ret = -errno;
-
-if (ret == -EINPROGRESS || ret == -EWOULDBLOCK)
+}
+if (ret == -EINPROGRESS || ret == -EWOULDBLOCK) {
qemu_set_fd_handler2(s-fd, NULL, NULL, unix_wait_for_connect, s);
+return 0;
+}
 } while (ret == -EINTR);

-if (ret  0  ret != -EINPROGRESS  ret != -EWOULDBLOCK) {
+if (ret  0) {
 DPRINTF(connect failed\n);
-goto err_after_open;
+migrate_fd_error(s);
+return ret;
 }
-
-if (ret = 0)
-migrate_fd_connect(s);
-
+migrate_fd_connect(s);
 return 0;
-
-err_after_open:
-close(s-fd);
-
-err_after_socket:
-return -1;
 }

 static void unix_accept_incoming_migration(void *opaque)
-- 
1.7.6.4




[Qemu-devel] [PATCH 36/36] migration: make migration-{tcp, unix} consistent

2011-10-11 Thread Juan Quintela
Files are almost identical in functionality, just remove the
differences that make no sense.

Signed-off-by: Juan Quintela quint...@redhat.com
Reviewed-by: Anthony Liguori aligu...@us.ibm.com
---
 migration-tcp.c  |   15 ++-
 migration-unix.c |   46 +-
 2 files changed, 35 insertions(+), 26 deletions(-)

diff --git a/migration-tcp.c b/migration-tcp.c
index 619df21..5aa742c 100644
--- a/migration-tcp.c
+++ b/migration-tcp.c
@@ -48,7 +48,6 @@ static int tcp_close(MigrationState *s)
 return 0;
 }

-
 static void tcp_wait_for_connect(void *opaque)
 {
 MigrationState *s = opaque;
@@ -84,12 +83,14 @@ int tcp_start_outgoing_migration(MigrationState *s, const 
char *host_port)
 if (ret  0) {
 return ret;
 }
+
 s-get_error = socket_errno;
 s-write = socket_write;
 s-close = tcp_close;

 s-fd = qemu_socket(PF_INET, SOCK_STREAM, 0);
 if (s-fd == -1) {
+DPRINTF(Unable to open socket);
 return -socket_error();
 }

@@ -155,23 +156,27 @@ int tcp_start_incoming_migration(const char *host_port)
 int val;
 int s;

+DPRINTF(Attempting to start an incoming migration\n);
+
 if (parse_host_port(addr, host_port)  0) {
 fprintf(stderr, invalid host/port combination: %s\n, host_port);
 return -EINVAL;
 }

 s = qemu_socket(PF_INET, SOCK_STREAM, 0);
-if (s == -1)
+if (s == -1) {
 return -socket_error();
+}

 val = 1;
 setsockopt(s, SOL_SOCKET, SO_REUSEADDR, (const char *)val, sizeof(val));

-if (bind(s, (struct sockaddr *)addr, sizeof(addr)) == -1)
+if (bind(s, (struct sockaddr *)addr, sizeof(addr)) == -1) {
 goto err;
-
-if (listen(s, 1) == -1)
+}
+if (listen(s, 1) == -1) {
 goto err;
+}

 qemu_set_fd_handler2(s, NULL, tcp_accept_incoming_migration, NULL,
  (void *)(intptr_t)s);
diff --git a/migration-unix.c b/migration-unix.c
index f979b5f..8596353 100644
--- a/migration-unix.c
+++ b/migration-unix.c
@@ -86,7 +86,7 @@ int unix_start_outgoing_migration(MigrationState *s, const 
char *path)
 s-close = unix_close;

 s-fd = qemu_socket(PF_UNIX, SOCK_STREAM, 0);
-if (s-fd  0) {
+if (s-fd == -1) {
 DPRINTF(Unable to open socket);
 return -errno;
 }
@@ -129,7 +129,7 @@ static void unix_accept_incoming_migration(void *opaque)

 if (c == -1) {
 fprintf(stderr, could not accept migration connection\n);
-return;
+goto out2;
 }

 f = qemu_fopen_socket(c);
@@ -141,45 +141,49 @@ static void unix_accept_incoming_migration(void *opaque)
 process_incoming_migration(f);
 qemu_fclose(f);
 out:
+close(c);
+out2:
 qemu_set_fd_handler2(s, NULL, NULL, NULL, NULL);
 close(s);
-close(c);
 }

 int unix_start_incoming_migration(const char *path)
 {
-struct sockaddr_un un;
-int sock;
+struct sockaddr_un addr;
+int s;
+int ret;

 DPRINTF(Attempting to start an incoming migration\n);

-sock = qemu_socket(PF_UNIX, SOCK_STREAM, 0);
-if (sock  0) {
+s = qemu_socket(PF_UNIX, SOCK_STREAM, 0);
+if (s == -1) {
 fprintf(stderr, Could not open unix socket: %s\n, strerror(errno));
-return -EINVAL;
+return -errno;
 }

-memset(un, 0, sizeof(un));
-un.sun_family = AF_UNIX;
-snprintf(un.sun_path, sizeof(un.sun_path), %s, path);
+memset(addr, 0, sizeof(addr));
+addr.sun_family = AF_UNIX;
+snprintf(addr.sun_path, sizeof(addr.sun_path), %s, path);

-unlink(un.sun_path);
-if (bind(sock, (struct sockaddr*) un, sizeof(un))  0) {
-fprintf(stderr, bind(unix:%s): %s\n, un.sun_path, strerror(errno));
+unlink(addr.sun_path);
+if (bind(s, (struct sockaddr *) addr, sizeof(addr))  0) {
+ret = -errno;
+fprintf(stderr, bind(unix:%s): %s\n, addr.sun_path, strerror(errno));
 goto err;
 }
-if (listen(sock, 1)  0) {
-fprintf(stderr, listen(unix:%s): %s\n, un.sun_path, strerror(errno));
+if (listen(s, 1) == -1) {
+fprintf(stderr, listen(unix:%s): %s\n, addr.sun_path,
+strerror(errno));
+ret = -errno;
 goto err;
 }

-qemu_set_fd_handler2(sock, NULL, unix_accept_incoming_migration, NULL,
-(void *)(intptr_t)sock);
+qemu_set_fd_handler2(s, NULL, unix_accept_incoming_migration, NULL,
+ (void *)(intptr_t)s);

 return 0;

 err:
-close(sock);
-
-return -EINVAL;
+close(s);
+return ret;
 }
-- 
1.7.6.4




[Qemu-devel] [PATCH 17/36] migration: Fold MigrationState into FdMigrationState

2011-10-11 Thread Juan Quintela
Signed-off-by: Juan Quintela quint...@redhat.com
Reviewed-by: Anthony Liguori aligu...@us.ibm.com
---
 migration-exec.c |   10 +-
 migration-fd.c   |   10 +-
 migration-tcp.c  |   10 +-
 migration-unix.c |   10 +-
 migration.c  |   14 ++
 migration.h  |   23 +--
 6 files changed, 31 insertions(+), 46 deletions(-)

diff --git a/migration-exec.c b/migration-exec.c
index 759aa79..39fd416 100644
--- a/migration-exec.c
+++ b/migration-exec.c
@@ -92,12 +92,12 @@ FdMigrationState *exec_start_outgoing_migration(Monitor 
*mon,
 s-close = exec_close;
 s-get_error = file_errno;
 s-write = file_write;
-s-mig_state.cancel = migrate_fd_cancel;
-s-mig_state.get_status = migrate_fd_get_status;
-s-mig_state.release = migrate_fd_release;
+s-cancel = migrate_fd_cancel;
+s-get_status = migrate_fd_get_status;
+s-release = migrate_fd_release;

-s-mig_state.blk = blk;
-s-mig_state.shared = inc;
+s-blk = blk;
+s-shared = inc;

 s-state = MIG_STATE_ACTIVE;
 s-mon = NULL;
diff --git a/migration-fd.c b/migration-fd.c
index 8036a27..c3c7b0e 100644
--- a/migration-fd.c
+++ b/migration-fd.c
@@ -75,12 +75,12 @@ FdMigrationState *fd_start_outgoing_migration(Monitor *mon,
 s-get_error = fd_errno;
 s-write = fd_write;
 s-close = fd_close;
-s-mig_state.cancel = migrate_fd_cancel;
-s-mig_state.get_status = migrate_fd_get_status;
-s-mig_state.release = migrate_fd_release;
+s-cancel = migrate_fd_cancel;
+s-get_status = migrate_fd_get_status;
+s-release = migrate_fd_release;

-s-mig_state.blk = blk;
-s-mig_state.shared = inc;
+s-blk = blk;
+s-shared = inc;

 s-state = MIG_STATE_ACTIVE;
 s-mon = NULL;
diff --git a/migration-tcp.c b/migration-tcp.c
index 05a121f..5ce93d9 100644
--- a/migration-tcp.c
+++ b/migration-tcp.c
@@ -94,12 +94,12 @@ FdMigrationState *tcp_start_outgoing_migration(Monitor *mon,
 s-get_error = socket_errno;
 s-write = socket_write;
 s-close = tcp_close;
-s-mig_state.cancel = migrate_fd_cancel;
-s-mig_state.get_status = migrate_fd_get_status;
-s-mig_state.release = migrate_fd_release;
+s-cancel = migrate_fd_cancel;
+s-get_status = migrate_fd_get_status;
+s-release = migrate_fd_release;

-s-mig_state.blk = blk;
-s-mig_state.shared = inc;
+s-blk = blk;
+s-shared = inc;

 s-state = MIG_STATE_ACTIVE;
 s-mon = NULL;
diff --git a/migration-unix.c b/migration-unix.c
index 0eeedde..00a6ed5 100644
--- a/migration-unix.c
+++ b/migration-unix.c
@@ -93,12 +93,12 @@ FdMigrationState *unix_start_outgoing_migration(Monitor 
*mon,
 s-get_error = unix_errno;
 s-write = unix_write;
 s-close = unix_close;
-s-mig_state.cancel = migrate_fd_cancel;
-s-mig_state.get_status = migrate_fd_get_status;
-s-mig_state.release = migrate_fd_release;
+s-cancel = migrate_fd_cancel;
+s-get_status = migrate_fd_get_status;
+s-release = migrate_fd_release;

-s-mig_state.blk = blk;
-s-mig_state.shared = inc;
+s-blk = blk;
+s-shared = inc;

 s-state = MIG_STATE_ACTIVE;
 s-mon = NULL;
diff --git a/migration.c b/migration.c
index f8eefa6..d51f737 100644
--- a/migration.c
+++ b/migration.c
@@ -87,8 +87,7 @@ int do_migrate(Monitor *mon, const QDict *qdict, QObject 
**ret_data)
 const char *uri = qdict_get_str(qdict, uri);

 if (current_migration 
-current_migration-mig_state.get_status(current_migration) ==
-MIG_STATE_ACTIVE) {
+current_migration-get_status(current_migration) == MIG_STATE_ACTIVE) {
 monitor_printf(mon, migration already in progress\n);
 return -1;
 }
@@ -122,7 +121,7 @@ int do_migrate(Monitor *mon, const QDict *qdict, QObject 
**ret_data)
 }

 if (current_migration) {
-current_migration-mig_state.release(current_migration);
+current_migration-release(current_migration);
 }

 current_migration = s;
@@ -134,8 +133,8 @@ int do_migrate_cancel(Monitor *mon, const QDict *qdict, 
QObject **ret_data)
 {
 FdMigrationState *s = current_migration;

-if (s  s-mig_state.get_status(s) == MIG_STATE_ACTIVE) {
-s-mig_state.cancel(s);
+if (s  s-get_status(s) == MIG_STATE_ACTIVE) {
+s-cancel(s);
 }
 return 0;
 }
@@ -231,7 +230,7 @@ void do_info_migrate(Monitor *mon, QObject **ret_data)
 QDict *qdict;

 if (current_migration) {
-MigrationState *s = current_migration-mig_state;
+FdMigrationState *s = current_migration;

 switch (s-get_status(current_migration)) {
 case MIG_STATE_ACTIVE:
@@ -355,8 +354,7 @@ void migrate_fd_connect(FdMigrationState *s)
   migrate_fd_close);

 DPRINTF(beginning savevm\n);
-ret = qemu_savevm_state_begin(s-mon, s-file, s-mig_state.blk,
-  s-mig_state.shared);
+ret = qemu_savevm_state_begin(s-mon, 

Re: [Qemu-devel] Slow kernel/initrd loading via fw_cfg; Was Re: Hack integrating SeaBios / LinuxBoot option rom with QEMU trace backends

2011-10-11 Thread Daniel P. Berrange
On Tue, Oct 11, 2011 at 11:50:01AM +0200, Avi Kivity wrote:
 On 10/11/2011 11:49 AM, Daniel P. Berrange wrote:
 On Tue, Oct 11, 2011 at 11:39:36AM +0200, Avi Kivity wrote:
   On 10/11/2011 11:27 AM, Daniel P. Berrange wrote:
  For comparison I also did a test building a bootable ISO using 
  ISOLinux.
  This required 700 ms for the boot time, which is appoximately 1/2 
  the
  time reqiured for direct kernel/initrd boot. But you have to then 
  add
  on time required to build the ISO on every boot, to add custom 
  kernel
  command line args. So while ISO is faster than LinuxBoot currently
  there is still non-negligable overhead here that I want to avoid.
   
  You can accept parameters from virtio-serial or some other channel.
  Is there any reason you need them specifically as *kernel* command
  line parameters?
   
   Well some of the parameters are actually kernel parameters :-) The rest
   are things I pass to the 'init' process which runs in the initrd. When
   this process first starts the only things it can easily access are those
   builtin to the kernel image, so data available from /proc or /sys like
   the /proc/cmdline file. It hasn't even loaded things like the 
  virtio-serial
   or virtio-9pfs kernel modules at this point.
   
 
   It could, if it wanted to.  It's completely custom, yes?
 
 I'm thinking primarily about debug related parameters, which need to be
 used as soon the process starts, not delayed until after we've loaded
 kernel modules at which point the step we wanted to debug is already
 past.
 
 Ah, so there's no issue in regenerating the image if you want to debug.

Compared to just altering the -append arg to QEMU, rebuilding the initrd
image and init program is a PITA.

Daniel
-- 
|: http://berrange.com  -o-http://www.flickr.com/photos/dberrange/ :|
|: http://libvirt.org  -o- http://virt-manager.org :|
|: http://autobuild.org   -o- http://search.cpan.org/~danberr/ :|
|: http://entangle-photo.org   -o-   http://live.gnome.org/gtk-vnc :|



[Qemu-devel] [PATCH 07/36] buffered_file: Use right opaque

2011-10-11 Thread Juan Quintela
buffered_close 's' variable is of type QEMUFileBuffered, and
wait_for_unfreeze() expect to receive a MigrationState, that
'coincidentaly' is s-opaque.

Signed-off-by: Juan Quintela quint...@redhat.com
---
 buffered_file.c |2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)

diff --git a/buffered_file.c b/buffered_file.c
index bcdf04f..701b440 100644
--- a/buffered_file.c
+++ b/buffered_file.c
@@ -176,7 +176,7 @@ static int buffered_close(void *opaque)
 while (!s-has_error  s-buffer_size) {
 buffered_flush(s);
 if (s-freeze_output)
-s-wait_for_unfreeze(s);
+s-wait_for_unfreeze(s-opaque);
 }

 ret = s-close(s-opaque);
-- 
1.7.6.4




[Qemu-devel] [PATCH 06/36] migration: If there is one error, it makes no sense to continue

2011-10-11 Thread Juan Quintela
Signed-off-by: Juan Quintela quint...@redhat.com
---
 buffered_file.c |6 +++---
 1 files changed, 3 insertions(+), 3 deletions(-)

diff --git a/buffered_file.c b/buffered_file.c
index 486af57..bcdf04f 100644
--- a/buffered_file.c
+++ b/buffered_file.c
@@ -193,9 +193,9 @@ static int buffered_rate_limit(void *opaque)
 {
 QEMUFileBuffered *s = opaque;

-if (s-has_error)
-return 0;
-
+if (s-has_error) {
+return 1;
+}
 if (s-freeze_output)
 return 1;

-- 
1.7.6.4




[Qemu-devel] [PATCH 18/36] migration: Rename FdMigrationState MigrationState

2011-10-11 Thread Juan Quintela
Signed-off-by: Juan Quintela quint...@redhat.com
Reviewed-by: Anthony Liguori aligu...@us.ibm.com
---
 migration-exec.c |   10 +-
 migration-fd.c   |   10 +-
 migration-tcp.c  |   12 ++--
 migration-unix.c |   12 ++--
 migration.c  |   34 +-
 migration.h  |   38 +++---
 6 files changed, 58 insertions(+), 58 deletions(-)

diff --git a/migration-exec.c b/migration-exec.c
index 39fd416..0ed5976 100644
--- a/migration-exec.c
+++ b/migration-exec.c
@@ -32,17 +32,17 @@
 do { } while (0)
 #endif

-static int file_errno(FdMigrationState *s)
+static int file_errno(MigrationState *s)
 {
 return errno;
 }

-static int file_write(FdMigrationState *s, const void * buf, size_t size)
+static int file_write(MigrationState *s, const void * buf, size_t size)
 {
 return write(s-fd, buf, size);
 }

-static int exec_close(FdMigrationState *s)
+static int exec_close(MigrationState *s)
 {
 int ret = 0;
 DPRINTF(exec_close\n);
@@ -61,14 +61,14 @@ static int exec_close(FdMigrationState *s)
 return ret;
 }

-FdMigrationState *exec_start_outgoing_migration(Monitor *mon,
+MigrationState *exec_start_outgoing_migration(Monitor *mon,
   const char *command,
  int64_t bandwidth_limit,
  int detach,
  int blk,
  int inc)
 {
-FdMigrationState *s;
+MigrationState *s;
 FILE *f;

 s = g_malloc0(sizeof(*s));
diff --git a/migration-fd.c b/migration-fd.c
index c3c7b0e..e78fd4e 100644
--- a/migration-fd.c
+++ b/migration-fd.c
@@ -30,17 +30,17 @@
 do { } while (0)
 #endif

-static int fd_errno(FdMigrationState *s)
+static int fd_errno(MigrationState *s)
 {
 return errno;
 }

-static int fd_write(FdMigrationState *s, const void * buf, size_t size)
+static int fd_write(MigrationState *s, const void * buf, size_t size)
 {
 return write(s-fd, buf, size);
 }

-static int fd_close(FdMigrationState *s)
+static int fd_close(MigrationState *s)
 {
 DPRINTF(fd_close\n);
 if (s-fd != -1) {
@@ -50,14 +50,14 @@ static int fd_close(FdMigrationState *s)
 return 0;
 }

-FdMigrationState *fd_start_outgoing_migration(Monitor *mon,
+MigrationState *fd_start_outgoing_migration(Monitor *mon,
const char *fdname,
int64_t bandwidth_limit,
int detach,
int blk,
int inc)
 {
-FdMigrationState *s;
+MigrationState *s;

 s = g_malloc0(sizeof(*s));

diff --git a/migration-tcp.c b/migration-tcp.c
index 5ce93d9..d6feb23 100644
--- a/migration-tcp.c
+++ b/migration-tcp.c
@@ -28,17 +28,17 @@
 do { } while (0)
 #endif

-static int socket_errno(FdMigrationState *s)
+static int socket_errno(MigrationState *s)
 {
 return socket_error();
 }

-static int socket_write(FdMigrationState *s, const void * buf, size_t size)
+static int socket_write(MigrationState *s, const void * buf, size_t size)
 {
 return send(s-fd, buf, size, 0);
 }

-static int tcp_close(FdMigrationState *s)
+static int tcp_close(MigrationState *s)
 {
 DPRINTF(tcp_close\n);
 if (s-fd != -1) {
@@ -51,7 +51,7 @@ static int tcp_close(FdMigrationState *s)

 static void tcp_wait_for_connect(void *opaque)
 {
-FdMigrationState *s = opaque;
+MigrationState *s = opaque;
 int val, ret;
 socklen_t valsize = sizeof(val);

@@ -75,7 +75,7 @@ static void tcp_wait_for_connect(void *opaque)
 }
 }

-FdMigrationState *tcp_start_outgoing_migration(Monitor *mon,
+MigrationState *tcp_start_outgoing_migration(Monitor *mon,
  const char *host_port,
  int64_t bandwidth_limit,
  int detach,
@@ -83,7 +83,7 @@ FdMigrationState *tcp_start_outgoing_migration(Monitor *mon,
 int inc)
 {
 struct sockaddr_in addr;
-FdMigrationState *s;
+MigrationState *s;
 int ret;

 if (parse_host_port(addr, host_port)  0)
diff --git a/migration-unix.c b/migration-unix.c
index 00a6ed5..3b9017b 100644
--- a/migration-unix.c
+++ b/migration-unix.c
@@ -28,17 +28,17 @@
 do { } while (0)
 #endif

-static int unix_errno(FdMigrationState *s)
+static int unix_errno(MigrationState *s)
 {
 return errno;
 }

-static int unix_write(FdMigrationState *s, const void * buf, size_t size)
+static int unix_write(MigrationState *s, const void * buf, size_t size)
 {
 return write(s-fd, buf, size);
 }

-static int unix_close(FdMigrationState *s)
+static int unix_close(MigrationState *s)
 {
 DPRINTF(unix_close\n);
 if (s-fd != -1) {
@@ 

[Qemu-devel] [PATCH 10/36] migration: set error if select return one error

2011-10-11 Thread Juan Quintela
Signed-off-by: Juan Quintela quint...@redhat.com
---
 migration.c |4 
 1 files changed, 4 insertions(+), 0 deletions(-)

diff --git a/migration.c b/migration.c
index 090c925..56c2b1c 100644
--- a/migration.c
+++ b/migration.c
@@ -457,6 +457,10 @@ void migrate_fd_wait_for_unfreeze(void *opaque)

 ret = select(s-fd + 1, NULL, wfds, NULL, NULL);
 } while (ret == -1  (s-get_error(s)) == EINTR);
+
+if (ret == -1) {
+qemu_file_set_error(s-file);
+}
 }

 int migrate_fd_close(void *opaque)
-- 
1.7.6.4




Re: [Qemu-devel] Slow kernel/initrd loading via fw_cfg; Was Re: Hack integrating SeaBios / LinuxBoot option rom with QEMU trace backends

2011-10-11 Thread Gleb Natapov
On Tue, Oct 11, 2011 at 11:59:45AM +0200, Avi Kivity wrote:
 On 10/11/2011 11:56 AM, Gleb Natapov wrote:
 On Tue, Oct 11, 2011 at 11:49:16AM +0200, Avi Kivity wrote:
   Whatever we do, the interface will never be as fast as DMA. We will 
  always have to do sanity / permission checks for every IO operation, can 
  batch up only so many IO requests and in QEMU again have to call our 
  callbacks in a loop.
 
   We can batch per page, which makes the overhead negligible.
 
 Current code batch userspace exit per 1024 bytes IIRC and changing it to
 page didn't show significant improvement (also IIRC). But after io data
 is copied into the kernel emulator process it byte by byte. Possible
 optimization, which I didn't tried, is to check that destination memory is
 not mmio and write back the whole buffer if it is the case.
 
 
 All the permission checks, segment checks,
 register_address_increment, page table walking, can be done per
 page.  Right now they are done per byte.
 
Permission checking result is cached in ctxt-perm_ok. I see that
current code check it after several function calls, but this was not the
case before. All others are done for each iteration currently. By writing
back a whole buffer at once we eliminate others too. Interesting how
much it will improve the situation.


 btw Intel also made this optimization, current processors copy
 complete cache lines instead of bytes, so they probably also do the
 checks just once.
 
 -- 
 error compiling committee.c: too many arguments to function

--
Gleb.



[Qemu-devel] [PATCH 08/36] buffered_file: reuse QEMUFile has_error field

2011-10-11 Thread Juan Quintela
Instead of having two has_error fields in QEMUFile  QEMUBufferedFile,
reuse the 1st one.  Notice that the one in buffered_file is only set
after a file operation.

Signed-off-by: Juan Quintela quint...@redhat.com
---
 buffered_file.c |   17 -
 1 files changed, 8 insertions(+), 9 deletions(-)

diff --git a/buffered_file.c b/buffered_file.c
index 701b440..3dadec0 100644
--- a/buffered_file.c
+++ b/buffered_file.c
@@ -27,7 +27,6 @@ typedef struct QEMUFileBuffered
 BufferedCloseFunc *close;
 void *opaque;
 QEMUFile *file;
-int has_error;
 int freeze_output;
 size_t bytes_xfer;
 size_t xfer_limit;
@@ -73,7 +72,7 @@ static void buffered_flush(QEMUFileBuffered *s)
 {
 size_t offset = 0;

-if (s-has_error) {
+if (qemu_file_has_error(s-file)) {
 DPRINTF(flush when error, bailing\n);
 return;
 }
@@ -93,7 +92,7 @@ static void buffered_flush(QEMUFileBuffered *s)

 if (ret = 0) {
 DPRINTF(error flushing data, %zd\n, ret);
-s-has_error = 1;
+qemu_file_set_error(s-file);
 break;
 } else {
 DPRINTF(flushed %zd byte(s)\n, ret);
@@ -114,7 +113,7 @@ static int buffered_put_buffer(void *opaque, const uint8_t 
*buf, int64_t pos, in

 DPRINTF(putting %d bytes at % PRId64 \n, size, pos);

-if (s-has_error) {
+if (qemu_file_has_error(s-file)) {
 DPRINTF(flush when error, bailing\n);
 return -EINVAL;
 }
@@ -139,7 +138,7 @@ static int buffered_put_buffer(void *opaque, const uint8_t 
*buf, int64_t pos, in

 if (ret = 0) {
 DPRINTF(error putting\n);
-s-has_error = 1;
+qemu_file_set_error(s-file);
 offset = -EINVAL;
 break;
 }
@@ -173,7 +172,7 @@ static int buffered_close(void *opaque)

 DPRINTF(closing\n);

-while (!s-has_error  s-buffer_size) {
+while (!qemu_file_has_error(s-file)  s-buffer_size) {
 buffered_flush(s);
 if (s-freeze_output)
 s-wait_for_unfreeze(s-opaque);
@@ -193,7 +192,7 @@ static int buffered_rate_limit(void *opaque)
 {
 QEMUFileBuffered *s = opaque;

-if (s-has_error) {
+if (qemu_file_has_error(s-file)) {
 return 1;
 }
 if (s-freeze_output)
@@ -208,7 +207,7 @@ static int buffered_rate_limit(void *opaque)
 static int64_t buffered_set_rate_limit(void *opaque, int64_t new_rate)
 {
 QEMUFileBuffered *s = opaque;
-if (s-has_error)
+if (qemu_file_has_error(s-file))
 goto out;

 if (new_rate  SIZE_MAX) {
@@ -232,7 +231,7 @@ static void buffered_rate_tick(void *opaque)
 {
 QEMUFileBuffered *s = opaque;

-if (s-has_error) {
+if (qemu_file_has_error(s-file)) {
 buffered_close(s);
 return;
 }
-- 
1.7.6.4




[Qemu-devel] [PATCH 26/36] migration: Remove get_status() accessor

2011-10-11 Thread Juan Quintela
It is only used inside migration.c, and fields on that struct are
accessed all around the place on that file.

Signed-off-by: Juan Quintela quint...@redhat.com
---
 migration.c |   16 +---
 migration.h |1 -
 2 files changed, 5 insertions(+), 12 deletions(-)

diff --git a/migration.c b/migration.c
index 689464d..0b7ffa7 100644
--- a/migration.c
+++ b/migration.c
@@ -91,7 +91,7 @@ int do_migrate(Monitor *mon, const QDict *qdict, QObject 
**ret_data)
 int ret;

 if (current_migration 
-current_migration-get_status(current_migration) == MIG_STATE_ACTIVE) {
+current_migration-state == MIG_STATE_ACTIVE) {
 monitor_printf(mon, migration already in progress\n);
 return -1;
 }
@@ -136,7 +136,7 @@ int do_migrate_cancel(Monitor *mon, const QDict *qdict, 
QObject **ret_data)
 {
 MigrationState *s = current_migration;

-if (s  s-get_status(s) == MIG_STATE_ACTIVE) {
+if (s  s-state == MIG_STATE_ACTIVE) {
 s-cancel(s);
 }
 return 0;
@@ -235,7 +235,7 @@ void do_info_migrate(Monitor *mon, QObject **ret_data)
 if (current_migration) {
 MigrationState *s = current_migration;

-switch (s-get_status(current_migration)) {
+switch (s-state) {
 case MIG_STATE_SETUP:
 /* no migration has happened ever */
 break;
@@ -386,7 +386,7 @@ static void migrate_fd_put_ready(void *opaque)
 } else {
 migrate_fd_completed(s);
 }
-if (s-get_status(s) != MIG_STATE_COMPLETED) {
+if (s-state != MIG_STATE_COMPLETED) {
 if (old_vm_running) {
 vm_start();
 }
@@ -394,11 +394,6 @@ static void migrate_fd_put_ready(void *opaque)
 }
 }

-static int migrate_fd_get_status(MigrationState *s)
-{
-return s-state;
-}
-
 static void migrate_fd_cancel(MigrationState *s)
 {
 if (s-state != MIG_STATE_ACTIVE)
@@ -460,7 +455,7 @@ void remove_migration_state_change_notifier(Notifier 
*notify)
 int get_migration_state(void)
 {
 if (current_migration) {
-return migrate_fd_get_status(current_migration);
+return current_migration-state;
 } else {
 return MIG_STATE_ERROR;
 }
@@ -494,7 +489,6 @@ static MigrationState *migrate_new(Monitor *mon, int64_t 
bandwidth_limit,
 MigrationState *s = g_malloc0(sizeof(*s));

 s-cancel = migrate_fd_cancel;
-s-get_status = migrate_fd_get_status;
 s-blk = blk;
 s-shared = inc;
 s-mon = NULL;
diff --git a/migration.h b/migration.h
index 1cdb539..b634994 100644
--- a/migration.h
+++ b/migration.h
@@ -39,7 +39,6 @@ struct MigrationState
 int (*close)(MigrationState *s);
 int (*write)(MigrationState *s, const void *buff, size_t size);
 void (*cancel)(MigrationState *s);
-int (*get_status)(MigrationState *s);
 void *opaque;
 int blk;
 int shared;
-- 
1.7.6.4




[Qemu-devel] [PATCH 27/36] migration: Remove migration cancel() callback

2011-10-11 Thread Juan Quintela
It is used only in one place

Signed-off-by: Juan Quintela quint...@redhat.com
---
 migration.c |9 -
 migration.h |1 -
 2 files changed, 4 insertions(+), 6 deletions(-)

diff --git a/migration.c b/migration.c
index 0b7ffa7..33e89a2 100644
--- a/migration.c
+++ b/migration.c
@@ -132,12 +132,12 @@ free_migrate_state:
 return -1;
 }

+static void migrate_fd_cancel(MigrationState *s);
+
 int do_migrate_cancel(Monitor *mon, const QDict *qdict, QObject **ret_data)
 {
-MigrationState *s = current_migration;
-
-if (s  s-state == MIG_STATE_ACTIVE) {
-s-cancel(s);
+if (current_migration) {
+migrate_fd_cancel(current_migration);
 }
 return 0;
 }
@@ -488,7 +488,6 @@ static MigrationState *migrate_new(Monitor *mon, int64_t 
bandwidth_limit,
 {
 MigrationState *s = g_malloc0(sizeof(*s));

-s-cancel = migrate_fd_cancel;
 s-blk = blk;
 s-shared = inc;
 s-mon = NULL;
diff --git a/migration.h b/migration.h
index b634994..f059183 100644
--- a/migration.h
+++ b/migration.h
@@ -38,7 +38,6 @@ struct MigrationState
 int (*get_error)(MigrationState *s);
 int (*close)(MigrationState *s);
 int (*write)(MigrationState *s, const void *buff, size_t size);
-void (*cancel)(MigrationState *s);
 void *opaque;
 int blk;
 int shared;
-- 
1.7.6.4




[Qemu-devel] [PATCH -V2 01/13] hw/9pfs: Use ioeventfd for 9p

2011-10-11 Thread Aneesh Kumar K.V
From: Aneesh Kumar K.V aneesh.ku...@linux.vnet.ibm.com

With ioeventfd:
[root@qemu-img-64 storage]# dd if=/dev/zero of=/storage/testx bs=8k 
count=131072 oflag=direct
131072+0 records in
131072+0 records out
1073741824 bytes (1.1 GB) copied, 26.767 s, 40.1 MB/s

Without:
[root@qemu-img-64 storage]# dd if=/dev/zero of=/storage/testx bs=8k 
count=131072 oflag=direct
131072+0 records in
131072+0 records out
1073741824 bytes (1.1 GB) copied, 65.3361 s, 16.4 MB/s

Reviewed-by: Stefan Hajnoczi stefa...@linux.vnet.ibm.com
Signed-off-by: Aneesh Kumar K.V aneesh.ku...@linux.vnet.ibm.com
---
 hw/9pfs/virtio-9p-device.c |2 ++
 hw/virtio-pci.c|5 -
 hw/virtio-pci.h|5 +
 3 files changed, 7 insertions(+), 5 deletions(-)

diff --git a/hw/9pfs/virtio-9p-device.c b/hw/9pfs/virtio-9p-device.c
index 513e181..e5b68da 100644
--- a/hw/9pfs/virtio-9p-device.c
+++ b/hw/9pfs/virtio-9p-device.c
@@ -169,6 +169,8 @@ static PCIDeviceInfo virtio_9p_info = {
 .revision  = VIRTIO_PCI_ABI_VERSION,
 .class_id  = 0x2,
 .qdev.props = (Property[]) {
+DEFINE_PROP_BIT(ioeventfd, VirtIOPCIProxy, flags,
+VIRTIO_PCI_FLAG_USE_IOEVENTFD_BIT, true),
 DEFINE_PROP_UINT32(vectors, VirtIOPCIProxy, nvectors, 2),
 DEFINE_VIRTIO_COMMON_FEATURES(VirtIOPCIProxy, host_features),
 DEFINE_PROP_STRING(mount_tag, VirtIOPCIProxy, fsconf.tag),
diff --git a/hw/virtio-pci.c b/hw/virtio-pci.c
index df27c19..ca5923c 100644
--- a/hw/virtio-pci.c
+++ b/hw/virtio-pci.c
@@ -83,11 +83,6 @@
 /* Flags track per-device state like workarounds for quirks in older guests. */
 #define VIRTIO_PCI_FLAG_BUS_MASTER_BUG  (1  0)
 
-/* Performance improves when virtqueue kick processing is decoupled from the
- * vcpu thread using ioeventfd for some devices. */
-#define VIRTIO_PCI_FLAG_USE_IOEVENTFD_BIT 1
-#define VIRTIO_PCI_FLAG_USE_IOEVENTFD   (1  
VIRTIO_PCI_FLAG_USE_IOEVENTFD_BIT)
-
 /* QEMU doesn't strictly need write barriers since everything runs in
  * lock-step.  We'll leave the calls to wmb() in though to make it obvious for
  * KVM or if kqemu gets SMP support.
diff --git a/hw/virtio-pci.h b/hw/virtio-pci.h
index 14c10f7..f8404de 100644
--- a/hw/virtio-pci.h
+++ b/hw/virtio-pci.h
@@ -18,6 +18,11 @@
 #include virtio-net.h
 #include virtio-serial.h
 
+/* Performance improves when virtqueue kick processing is decoupled from the
+ * vcpu thread using ioeventfd for some devices. */
+#define VIRTIO_PCI_FLAG_USE_IOEVENTFD_BIT 1
+#define VIRTIO_PCI_FLAG_USE_IOEVENTFD   (1  
VIRTIO_PCI_FLAG_USE_IOEVENTFD_BIT)
+
 typedef struct {
 PCIDevice pci_dev;
 VirtIODevice *vdev;
-- 
1.7.5.4




[Qemu-devel] [PATCH -V2 08/13] hw/9pfs: Add st_gen support in getattr reply

2011-10-11 Thread Aneesh Kumar K.V
From: Harsh Prateek Bora ha...@linux.vnet.ibm.com

This patch use file system specific ioctl for getting i_generation
value. Not all file system support the ioctl. So we add an export
specific extended operation and assign right callback for the
file system that support i_generation ioctl

[M. Mohan Kumar mo...@in.ibm.com we can do ioctl only for
regular files and directories on the server]

Signed-off-by: Harsh Prateek Bora ha...@linux.vnet.ibm.com
Signed-off-by: Aneesh Kumar K.V aneesh.ku...@linux.vnet.ibm.com
---
 configure  |   17 +
 fsdev/file-op-9p.h |8 ++
 hw/9pfs/cofile.c   |   24 +++
 hw/9pfs/virtio-9p-coth.h   |3 ++
 hw/9pfs/virtio-9p-device.c |2 +
 hw/9pfs/virtio-9p-local.c  |   54 +++-
 hw/9pfs/virtio-9p.c|9 +++
 7 files changed, 116 insertions(+), 1 deletions(-)

diff --git a/configure b/configure
index 0216c53..4ce4f1f 100755
--- a/configure
+++ b/configure
@@ -2562,6 +2562,19 @@ if compile_prog   ; then
 open_by_handle_at=yes
 fi
 
+
+# check if we have linux/magic.h
+
+linux_magic_h=no
+cat  $TMPC  EOF
+#include linux/magic.h
+int main(void) {
+}
+EOF
+if compile_prog   ; then
+linux_magic_h=yes
+fi
+
 ##
 # End of CC checks
 # After here, no more $cc or $ld runs
@@ -3045,6 +3058,10 @@ if test $open_by_handle_at = yes ; then
   echo CONFIG_OPEN_BY_HANDLE=y  $config_host_mak
 fi
 
+if test $linux_magic_h = yes ; then
+  echo CONFIG_LINUX_MAGIC_H=y  $config_host_mak
+fi
+
 # USB host support
 case $usb in
 linux)
diff --git a/fsdev/file-op-9p.h b/fsdev/file-op-9p.h
index 84ec9e0..33fb07f 100644
--- a/fsdev/file-op-9p.h
+++ b/fsdev/file-op-9p.h
@@ -49,6 +49,13 @@ typedef struct FsCred
 } FsCred;
 
 struct xattr_operations;
+struct FsContext;
+struct V9fsPath;
+
+typedef struct extended_ops {
+int (*get_st_gen)(struct FsContext *, struct V9fsPath *,
+  mode_t, uint64_t *);
+} extended_ops;
 
 /* FsContext flag values */
 #define PATHNAME_FSCONTEXT 0x1
@@ -64,6 +71,7 @@ typedef struct FsContext
 uid_t uid;
 int cache_flags;
 struct xattr_operations **xops;
+struct extended_ops exops;
 /* fs driver specific data */
 void *private;
 } FsContext;
diff --git a/hw/9pfs/cofile.c b/hw/9pfs/cofile.c
index 7ad4bec..692811e 100644
--- a/hw/9pfs/cofile.c
+++ b/hw/9pfs/cofile.c
@@ -17,6 +17,30 @@
 #include qemu-coroutine.h
 #include virtio-9p-coth.h
 
+int v9fs_co_st_gen(V9fsPDU *pdu, V9fsPath *path, mode_t st_mode,
+   V9fsStatDotl *v9stat)
+{
+int err = 0;
+V9fsState *s = pdu-s;
+
+if (v9fs_request_cancelled(pdu)) {
+return -EINTR;
+}
+if (s-ctx.exops.get_st_gen) {
+v9fs_path_read_lock(s);
+v9fs_co_run_in_worker(
+{
+err = s-ctx.exops.get_st_gen(s-ctx, path, st_mode,
+  v9stat-st_gen);
+if (err  0) {
+err = -errno;
+}
+});
+v9fs_path_unlock(s);
+}
+return err;
+}
+
 int v9fs_co_lstat(V9fsPDU *pdu, V9fsPath *path, struct stat *stbuf)
 {
 int err;
diff --git a/hw/9pfs/virtio-9p-coth.h b/hw/9pfs/virtio-9p-coth.h
index 4630080..ca96b9c 100644
--- a/hw/9pfs/virtio-9p-coth.h
+++ b/hw/9pfs/virtio-9p-coth.h
@@ -101,4 +101,7 @@ extern int v9fs_co_preadv(V9fsPDU *, V9fsFidState *,
   struct iovec *, int, int64_t);
 extern int v9fs_co_name_to_path(V9fsPDU *, V9fsPath *,
 const char *, V9fsPath *);
+extern int v9fs_co_st_gen(V9fsPDU *pdu, V9fsPath *path, mode_t,
+  V9fsStatDotl *v9stat);
+
 #endif
diff --git a/hw/9pfs/virtio-9p-device.c b/hw/9pfs/virtio-9p-device.c
index 0930d22..bc25af5 100644
--- a/hw/9pfs/virtio-9p-device.c
+++ b/hw/9pfs/virtio-9p-device.c
@@ -117,6 +117,8 @@ VirtIODevice *virtio_9p_init(DeviceState *dev, V9fsConf 
*conf)
 
 s-ctx.cache_flags = fse-cache_flags;
 s-ctx.fs_root = g_strdup(fse-path);
+s-ctx.exops.get_st_gen = NULL;
+
 len = strlen(conf-tag);
 if (len  MAX_TAG_LEN) {
 fprintf(stderr, mount tag '%s' (%d bytes) is longer than 
diff --git a/hw/9pfs/virtio-9p-local.c b/hw/9pfs/virtio-9p-local.c
index 5745d14..aca4706 100644
--- a/hw/9pfs/virtio-9p-local.c
+++ b/hw/9pfs/virtio-9p-local.c
@@ -20,6 +20,24 @@
 #include sys/socket.h
 #include sys/un.h
 #include attr/xattr.h
+#include linux/fs.h
+#ifdef CONFIG_LINUX_MAGIC_H
+#include linux/magic.h
+#endif
+#include sys/ioctl.h
+
+#ifndef XFS_SUPER_MAGIC
+#define XFS_SUPER_MAGIC  0x58465342
+#endif
+#ifndef EXT2_SUPER_MAGIC
+#define EXT2_SUPER_MAGIC 0xEF53
+#endif
+#ifndef REISERFS_SUPER_MAGIC
+#define REISERFS_SUPER_MAGIC 0x52654973
+#endif
+#ifndef BTRFS_SUPER_MAGIC
+#define BTRFS_SUPER_MAGIC 0x9123683E
+#endif
 
 static int local_lstat(FsContext *fs_ctx, 

[Qemu-devel] [PATCH -V2 09/13] hw/9pfs: Add st_gen support for handle based fs driver

2011-10-11 Thread Aneesh Kumar K.V
From: Harsh Prateek Bora ha...@linux.vnet.ibm.com

Signed-off-by: Harsh Prateek Bora ha...@linux.vnet.ibm.com
Signed-off-by: Aneesh Kumar K.V aneesh.ku...@linux.vnet.ibm.com
---
 hw/9pfs/virtio-9p-handle.c |   51 
 1 files changed, 51 insertions(+), 0 deletions(-)

diff --git a/hw/9pfs/virtio-9p-handle.c b/hw/9pfs/virtio-9p-handle.c
index fbe3e62..525c91a 100644
--- a/hw/9pfs/virtio-9p-handle.c
+++ b/hw/9pfs/virtio-9p-handle.c
@@ -21,6 +21,24 @@
 #include sys/un.h
 #include attr/xattr.h
 #include unistd.h
+#include linux/fs.h
+#ifdef CONFIG_LINUX_MAGIC_H
+#include linux/magic.h
+#endif
+#include sys/ioctl.h
+
+#ifndef XFS_SUPER_MAGIC
+#define XFS_SUPER_MAGIC  0x58465342
+#endif
+#ifndef EXT2_SUPER_MAGIC
+#define EXT2_SUPER_MAGIC 0xEF53
+#endif
+#ifndef REISERFS_SUPER_MAGIC
+#define REISERFS_SUPER_MAGIC 0x52654973
+#endif
+#ifndef BTRFS_SUPER_MAGIC
+#define BTRFS_SUPER_MAGIC 0x9123683E
+#endif
 
 struct handle_data {
 int mountfd;
@@ -550,9 +568,31 @@ static int handle_unlinkat(FsContext *ctx, V9fsPath *dir,
 return ret;
 }
 
+static int handle_ioc_getversion(FsContext *ctx, V9fsPath *path,
+ mode_t st_mode, uint64_t *st_gen)
+{
+int err, fd;
+
+/*
+ * Do not try to open special files like device nodes, fifos etc
+ * We can get fd for regular files and directories only
+ */
+if (!S_ISREG(st_mode)  !S_ISDIR(st_mode)) {
+return 0;
+}
+fd = handle_open(ctx, path, O_RDONLY);
+if (fd  0) {
+return fd;
+}
+err = ioctl(fd, FS_IOC_GETVERSION, st_gen);
+handle_close(ctx, fd);
+return err;
+}
+
 static int handle_init(FsContext *ctx)
 {
 int ret, mnt_id;
+struct statfs stbuf;
 struct file_handle fh;
 struct handle_data *data = g_malloc(sizeof(struct handle_data));
 
@@ -561,6 +601,17 @@ static int handle_init(FsContext *ctx)
 ret = data-mountfd;
 goto err_out;
 }
+ret = statfs(ctx-fs_root, stbuf);
+if (!ret) {
+switch (stbuf.f_type) {
+case EXT2_SUPER_MAGIC:
+case BTRFS_SUPER_MAGIC:
+case REISERFS_SUPER_MAGIC:
+case XFS_SUPER_MAGIC:
+ctx-exops.get_st_gen = handle_ioc_getversion;
+break;
+}
+}
 memset(fh, 0, sizeof(struct file_handle));
 ret = name_to_handle(data-mountfd, ., fh, mnt_id, 0);
 if (ret  errno == EOVERFLOW) {
-- 
1.7.5.4




[Qemu-devel] [PATCH -V2 11/13] hw/9pfs: Remove virtio-9p-debug.* infra to be replaced by Qemu Tracing.

2011-10-11 Thread Aneesh Kumar K.V
From: Harsh Prateek Bora ha...@linux.vnet.ibm.com

Removing the existing debug infrastrucure as proposed to be replaced by
Qemu Tracing infrastructure.

Reviewed-by: Stefan Hajnoczi stefa...@linux.vnet.ibm.com
Signed-off-by: Harsh Prateek Bora ha...@linux.vnet.ibm.com
Signed-off-by: Aneesh Kumar K.V aneesh.ku...@linux.vnet.ibm.com
---
 Makefile.objs |2 +-
 hw/9pfs/virtio-9p-debug.c |  646 -
 hw/9pfs/virtio-9p-debug.h |6 -
 hw/9pfs/virtio-9p.c   |8 -
 4 files changed, 1 insertions(+), 661 deletions(-)
 delete mode 100644 hw/9pfs/virtio-9p-debug.c
 delete mode 100644 hw/9pfs/virtio-9p-debug.h

diff --git a/Makefile.objs b/Makefile.objs
index 8d23fbb..35ac098 100644
--- a/Makefile.objs
+++ b/Makefile.objs
@@ -304,7 +304,7 @@ sound-obj-$(CONFIG_HDA) += intel-hda.o hda-audio.o
 adlib.o fmopl.o: QEMU_CFLAGS += -DBUILD_Y8950=0
 hw-obj-$(CONFIG_SOUND) += $(sound-obj-y)
 
-9pfs-nested-$(CONFIG_VIRTFS)  = virtio-9p.o virtio-9p-debug.o
+9pfs-nested-$(CONFIG_VIRTFS)  = virtio-9p.o
 9pfs-nested-$(CONFIG_VIRTFS) += virtio-9p-local.o virtio-9p-xattr.o
 9pfs-nested-$(CONFIG_VIRTFS) += virtio-9p-xattr-user.o virtio-9p-posix-acl.o
 9pfs-nested-$(CONFIG_VIRTFS) += virtio-9p-coth.o cofs.o codir.o cofile.o
diff --git a/hw/9pfs/virtio-9p-debug.c b/hw/9pfs/virtio-9p-debug.c
deleted file mode 100644
index 96925f0..000
--- a/hw/9pfs/virtio-9p-debug.c
+++ /dev/null
@@ -1,646 +0,0 @@
-/*
- * Virtio 9p PDU debug
- *
- * Copyright IBM, Corp. 2010
- *
- * Authors:
- *  Anthony Liguori   aligu...@us.ibm.com
- *
- * This work is licensed under the terms of the GNU GPL, version 2.  See
- * the COPYING file in the top-level directory.
- *
- */
-
-#include hw/virtio.h
-#include hw/pc.h
-#include virtio-9p.h
-#include virtio-9p-debug.h
-
-#define BUG_ON(cond) assert(!(cond))
-
-static FILE *llogfile;
-
-static struct iovec *get_sg(V9fsPDU *pdu, int rx)
-{
-if (rx) {
-return pdu-elem.in_sg;
-}
-return pdu-elem.out_sg;
-}
-
-static int get_sg_count(V9fsPDU *pdu, int rx)
-{
-if (rx) {
-return pdu-elem.in_num;
-}
-return pdu-elem.out_num;
-
-}
-
-static void pprint_int8(V9fsPDU *pdu, int rx, size_t *offsetp,
-const char *name)
-{
-size_t copied;
-int count = get_sg_count(pdu, rx);
-size_t offset = *offsetp;
-struct iovec *sg = get_sg(pdu, rx);
-int8_t value;
-
-copied = do_pdu_unpack(value, sg, count, offset, sizeof(value));
-
-BUG_ON(copied != sizeof(value));
-offset += sizeof(value);
-fprintf(llogfile, %s=0x%x, name, value);
-*offsetp = offset;
-}
-
-static void pprint_int16(V9fsPDU *pdu, int rx, size_t *offsetp,
-const char *name)
-{
-size_t copied;
-int count = get_sg_count(pdu, rx);
-struct iovec *sg = get_sg(pdu, rx);
-size_t offset = *offsetp;
-int16_t value;
-
-
-copied = do_pdu_unpack(value, sg, count, offset, sizeof(value));
-
-BUG_ON(copied != sizeof(value));
-offset += sizeof(value);
-fprintf(llogfile, %s=0x%x, name, value);
-*offsetp = offset;
-}
-
-static void pprint_int32(V9fsPDU *pdu, int rx, size_t *offsetp,
-const char *name)
-{
-size_t copied;
-int count = get_sg_count(pdu, rx);
-struct iovec *sg = get_sg(pdu, rx);
-size_t offset = *offsetp;
-int32_t value;
-
-
-copied = do_pdu_unpack(value, sg, count, offset, sizeof(value));
-
-BUG_ON(copied != sizeof(value));
-offset += sizeof(value);
-fprintf(llogfile, %s=0x%x, name, value);
-*offsetp = offset;
-}
-
-static void pprint_int64(V9fsPDU *pdu, int rx, size_t *offsetp,
-const char *name)
-{
-size_t copied;
-int count = get_sg_count(pdu, rx);
-struct iovec *sg = get_sg(pdu, rx);
-size_t offset = *offsetp;
-int64_t value;
-
-
-copied = do_pdu_unpack(value, sg, count, offset, sizeof(value));
-
-BUG_ON(copied != sizeof(value));
-offset += sizeof(value);
-fprintf(llogfile, %s=0x% PRIx64, name, value);
-*offsetp = offset;
-}
-
-static void pprint_str(V9fsPDU *pdu, int rx, size_t *offsetp, const char *name)
-{
-int sg_count = get_sg_count(pdu, rx);
-struct iovec *sg = get_sg(pdu, rx);
-size_t offset = *offsetp;
-uint16_t tmp_size, size;
-size_t result;
-size_t copied = 0;
-int i = 0;
-
-/* get the size */
-copied = do_pdu_unpack(tmp_size, sg, sg_count, offset, sizeof(tmp_size));
-BUG_ON(copied != sizeof(tmp_size));
-size = le16_to_cpupu(tmp_size);
-offset += copied;
-
-fprintf(llogfile, %s=, name);
-for (i = 0; size  i  sg_count; i++) {
-size_t len;
-if (offset = sg[i].iov_len) {
-/* skip this sg */
-offset -= sg[i].iov_len;
-continue;
-} else {
-len = MIN(sg[i].iov_len - offset, size);
-result = fwrite(sg[i].iov_base + offset, 1, len, llogfile);
-BUG_ON(result != len);
- 

[Qemu-devel] [PATCH -V2 12/13] scripts: Simpletrace log analysis script for pretty-printing 9p log.

2011-10-11 Thread Aneesh Kumar K.V
From: Harsh Prateek Bora ha...@linux.vnet.ibm.com

This python script allows to pretty print 9p simpletrace logs and can be
further enhanced to filter 9p logs based on command line arguments.

Sample output:
 TGETATTR (tag = 1 , fid = 0 , request_mask = 0x7ff )
 RGETATTR (tag = 1 , result_mask = 0x7ff , mode = 040777 , uid = 500 , gid = 
500 )
 TXATTRWALK (tag = 1 , fid = 0 , newfid = 1 , xattr name = 36832096 )
 RXATTRWALK (tag = 1 , xattrsize  = 18446744073709551555 )
 TXATTRWALK (tag = 1 , fid = 0 , newfid = 1 , xattr name = 36744768 )
 RXATTRWALK (tag = 1 , xattrsize  = 18446744073709551555 )
 TGETATTR (tag = 1 , fid = 1 , request_mask = 0x3fff )
 RGETATTR (tag = 1 , result_mask = 0x17ff , mode = 040777 , uid = 500 , gid = 
500 )
 TWALK (tag = 1 , fid = 1 , newfid = 2 , nwnames = 1 )
 RWALK (tag = 1 , nwnames = 1 , qids = 0x230aea0 )

Signed-off-by: Harsh Prateek Bora ha...@linux.vnet.ibm.com
Signed-off-by: Aneesh Kumar K.V aneesh.ku...@linux.vnet.ibm.com
---
 scripts/analyse-9p-simpletrace.py |  142 +
 1 files changed, 142 insertions(+), 0 deletions(-)
 create mode 100755 scripts/analyse-9p-simpletrace.py

diff --git a/scripts/analyse-9p-simpletrace.py 
b/scripts/analyse-9p-simpletrace.py
new file mode 100755
index 000..4358d6b
--- /dev/null
+++ b/scripts/analyse-9p-simpletrace.py
@@ -0,0 +1,142 @@
+#!/usr/bin/env python
+# Pretty print 9p simpletrace log
+# Usage: ./analyse-9p-simpletrace trace-events trace-pid
+#
+# Author: Harsh Prateek Bora
+
+import simpletrace
+
+class VirtFSRequestTracker(simpletrace.Analyzer):
+   def begin(self):
+   print Pretty printing 9p simpletrace log ...
+
+def complete_pdu(self, tag, id, err):
+print ERROR (tag =, tag, , id =, id, ,err =, err, )
+
+def v9fs_version(self, tag, id, msize, version):
+print TVERSION (tag =, tag, , msize =, msize, , version 
=, version, )
+
+def v9fs_version_return(self, tag, id, msize, version):
+print RVERSION (tag =, tag, , msize =, msize, , version 
=, version, )
+
+def v9fs_attach(self, tag, id, fid, afid, uname, aname):
+print TATTACH (tag =, tag, , fid =, fid, , afid =, afid, 
, uname =, uname, , aname =, aname, )
+
+   def v9fs_attach_return(self, tag, id, type, verison, path):
+   print RATTACH (tag =, tag, , qid={type =, type, , version 
=, version, , path =, path, })
+
+   def v9fs_stat(self, tag, id, fid):
+   print TSTAT (tag =, tag, , fid =, fid, )
+
+   def v9fs_stat_return(self, tag, id, mode, atime, mtime, length):
+   print RSTAT (tag =, tag, , mode =, mode, , atime =, 
atime, , mtime =, mtime, , length =, length, )
+
+   def v9fs_getattr(self, tag, id, fid, request_mask):
+   print TGETATTR (tag =, tag, , fid =, fid, , request_mask 
=, hex(request_mask), )
+
+   def v9fs_getattr_return(self, tag, id, result_mask, mode, uid, gid):
+   print RGETATTR (tag =, tag, , result_mask =, 
hex(result_mask), , mode =, oct(mode), , uid =, uid, , gid =, gid, )
+
+   def v9fs_walk(self, tag, id, fid, newfid, nwnames):
+   print TWALK (tag =, tag, , fid =, fid, , newfid =, 
newfid, , nwnames =, nwnames, )
+
+   def v9fs_walk_return(self, tag, id, nwnames, qids):
+   print RWALK (tag =, tag, , nwnames =, nwnames, , qids =, 
hex(qids), )
+
+   def v9fs_open(self, tag, id, fid, mode):
+   print TOPEN (tag =, tag, , fid =, fid, , mode =, 
oct(mode), )
+
+   def v9fs_open_return(self, tag, id, type, version, path, iounit):
+   print ROPEN (tag =, tag,  , qid={type =, type, , version 
=, version, , path =, path, }, iounit =, iounit, )
+
+   def v9fs_lcreate(self, tag, id, dfid, flags, mode, gid):
+   print TLCREATE (tag =, tag, , dfid =, dfid, , flags =, 
oct(flags), , mode =, oct(mode), , gid =, gid, )
+
+   def v9fs_lcreate_return(self, id, type, version, path, iounit):
+   print RLCREATE (tag =, tag,  , qid={type =, type, , 
version =, version, , path =, path, }, iounit =, iounit, )
+
+   def v9fs_fsync(self, tag, id, fid, datasync):
+   print TFSYNC (tag =, tag, , fid =, fid, , datasync =, 
datasync, )
+
+   def v9fs_clunk(self, tag, id, fid):
+   print TCLUNK (tag =, tag, , fid =, fid, )
+
+   def v9fs_read(self, tag, id, fid, off, max_count):
+   print TREAD (tag =, tag, , fid =, fid, , off =, off, , 
max_count =, max_count, )
+
+   def v9fs_read_return(self, tag, id, count, err):
+   print RREAD (tag =, tag, , count =, count, , err =, err, 
)
+
+   def v9fs_readdir(self, tag, id, fid, offset, max_count):
+   print TREADDIR (tag =, tag, , fid =, fid, , offset =, 
offset, , max_count =, max_count, )
+
+   def v9fs_readdir_return(self, tag, id, count, retval):
+   print RREADDIR (tag =, tag, , count =, count, , retval =, 

[Qemu-devel] [PATCH -V2 03/13] qemu-options.hx: Update virtfs command documentation

2011-10-11 Thread Aneesh Kumar K.V
From: Aneesh Kumar K.V aneesh.ku...@linux.vnet.ibm.com

Clarify the virtfs option better
Updates from:Sripathi Kodi sripat...@in.ibm.com

Signed-off-by: Aneesh Kumar K.V aneesh.ku...@linux.vnet.ibm.com
---
 qemu-options.hx |  119 ---
 1 files changed, 69 insertions(+), 50 deletions(-)

diff --git a/qemu-options.hx b/qemu-options.hx
index 38f0aef..6c744e0 100644
--- a/qemu-options.hx
+++ b/qemu-options.hx
@@ -522,43 +522,61 @@ possible drivers and properties, use @code{-device ?} and
 @code{-device @var{driver},?}.
 ETEXI
 
+DEFHEADING()
+
 DEFHEADING(File system options:)
 
 DEF(fsdev, HAS_ARG, QEMU_OPTION_fsdev,
--fsdev local,id=id,path=path,security_model=[mapped|passthrough|none]\n
+-fsdev 
fsdriver,id=id,path=path,security_model=[mapped|passthrough|none]\n
[,cache=writethrough]\n,
 QEMU_ARCH_ALL)
 
 STEXI
 
-The general form of a File system device option is:
-@table @option
-
-@item -fsdev @var{fstype} ,id=@var{id} [,@var{options}]
+@item -fsdev 
@var{fsdriver},id=@var{id},path=@var{path},security_model=@var{security_model}[,cache=@var{cache}]
 @findex -fsdev
-Fstype is one of:
-@option{local},
-The specific Fstype will determine the applicable options.
-
-Options to each backend are described below.
-
-@item -fsdev local ,id=@var{id} ,path=@var{path} 
,security_model=@var{security_model}[,cache=@var{cache}]
-
-Create a file-system-device for local-filesystem.
-
-@option{local} is only available on Linux.
-
-@option{path} specifies the path to be exported. @option{path} is required.
-
-@option{security_model} specifies the security model to be followed.
-@option{security_model} is required.
-
-@option{cache} specifies whether to skip the host page cache.
-@option{cache} is an optional argument.
+Define a new file system device. Valid options are:
+@table @option
+@item @var{fsdriver}
+This option specifies the fs driver backend to use.
+Currently local and handle file system drivers are supported.
+@item id=@var{id}
+Specifies identifier for this device
+@item path=@var{path}
+Specifies the export path for the file system device. Files under
+this path will be available to the 9p client on the guest.
+@item security_model=@var{security_model}
+Specifies the security model to be used for this export path.
+Supported security models are passthrough, mapped and none.
+In passthrough security model, files are stored using the same
+credentials as they are created on the guest. This requires qemu
+to run as root. In mapped security model, some of the file
+attributes like uid, gid, mode bits and link target are stored as
+file attributes. Directories exported by this security model cannot
+interact with other unix tools. none security model is same as
+passthrough except the sever won't report failures if it fails to
+set file attributes like ownership.
+@item cache=@var{cache}
+This is an optional argument. The only supported value is writethrough.
+This means that host page cache will be used to read and write data but
+write notification will be sent to the guest only when the data has been
+reported as written by the storage subsystem.
+@end table
 
+-fsdev option is used along with -device driver virtio-9p-pci.
+@item -device virtio-9p-pci,fsdev=@var{id},mount_tag=@var{mount_tag}
+Options for virtio-9p-pci driver are:
+@table @option
+@item fsdev=@var{id}
+Specifies the id value specified along with -fsdev option
+@item mount_tag=@var{mount_tag}
+Specifies the tag name to be used by the guest to mount this export point
 @end table
+
 ETEXI
 
+DEFHEADING()
+
 DEFHEADING(Virtual File system pass-through options:)
 
 DEF(virtfs, HAS_ARG, QEMU_OPTION_virtfs,
@@ -568,34 +586,35 @@ DEF(virtfs, HAS_ARG, QEMU_OPTION_virtfs,
 
 STEXI
 
-The general form of a Virtual File system pass-through option is:
-@table @option
-
-@item -virtfs @var{fstype} [,@var{options}]
+@item -virtfs 
@var{fsdriver},path=@var{path},mount_tag=@var{mount_tag},security_model=@var{security_model}[,cache=@var{cache}]
 @findex -virtfs
-Fstype is one of:
-@option{local},
-The specific Fstype will determine the applicable options.
-
-Options to each backend are described below.
-
-@item -virtfs local ,path=@var{path} ,mount_tag=@var{mount_tag} 
,security_model=@var{security_model}[,cache=@var{cache}]
-
-Create a Virtual file-system-pass through for local-filesystem.
-
-@option{local} is only available on Linux.
-
-@option{path} specifies the path to be exported. @option{path} is required.
-
-@option{security_model} specifies the security model to be followed.
-@option{security_model} is required.
-
-@option{mount_tag} specifies the tag with which the exported file is mounted.
-@option{mount_tag} is required.
-
-@option{cache} specifies whether to skip the host page cache.
-@option{cache} is an optional argument.
 
+The general form of a Virtual File system pass-through options are:
+@table @option
+@item @var{fsdriver}
+This option specifies the fs driver backend 

[Qemu-devel] [PATCH 16/36] migration: Use FdMigrationState instead of MigrationState when possible

2011-10-11 Thread Juan Quintela
Signed-off-by: Juan Quintela quint...@redhat.com
Reviewed-by: Anthony Liguori aligu...@us.ibm.com
---
 migration.c |   34 --
 migration.h |   16 
 2 files changed, 24 insertions(+), 26 deletions(-)

diff --git a/migration.c b/migration.c
index 4449594..f8eefa6 100644
--- a/migration.c
+++ b/migration.c
@@ -34,7 +34,7 @@
 /* Migration speed throttling */
 static int64_t max_throttle = (32  20);

-static MigrationState *current_migration;
+static FdMigrationState *current_migration;

 static NotifierList migration_state_notifiers =
 NOTIFIER_LIST_INITIALIZER(migration_state_notifiers);
@@ -87,7 +87,8 @@ int do_migrate(Monitor *mon, const QDict *qdict, QObject 
**ret_data)
 const char *uri = qdict_get_str(qdict, uri);

 if (current_migration 
-current_migration-get_status(current_migration) == MIG_STATE_ACTIVE) {
+current_migration-mig_state.get_status(current_migration) ==
+MIG_STATE_ACTIVE) {
 monitor_printf(mon, migration already in progress\n);
 return -1;
 }
@@ -121,20 +122,20 @@ int do_migrate(Monitor *mon, const QDict *qdict, QObject 
**ret_data)
 }

 if (current_migration) {
-current_migration-release(current_migration);
+current_migration-mig_state.release(current_migration);
 }

-current_migration = s-mig_state;
+current_migration = s;
 notifier_list_notify(migration_state_notifiers, NULL);
 return 0;
 }

 int do_migrate_cancel(Monitor *mon, const QDict *qdict, QObject **ret_data)
 {
-MigrationState *s = current_migration;
+FdMigrationState *s = current_migration;

-if (s  s-get_status(s) == MIG_STATE_ACTIVE) {
-s-cancel(s);
+if (s  s-mig_state.get_status(s) == MIG_STATE_ACTIVE) {
+s-mig_state.cancel(s);
 }
 return 0;
 }
@@ -150,7 +151,7 @@ int do_migrate_set_speed(Monitor *mon, const QDict *qdict, 
QObject **ret_data)
 }
 max_throttle = d;

-s = migrate_to_fms(current_migration);
+s = current_migration;
 if (s  s-file) {
 qemu_file_set_rate_limit(s-file, max_throttle);
 }
@@ -228,10 +229,11 @@ static void migrate_put_status(QDict *qdict, const char 
*name,
 void do_info_migrate(Monitor *mon, QObject **ret_data)
 {
 QDict *qdict;
-MigrationState *s = current_migration;

-if (s) {
-switch (s-get_status(s)) {
+if (current_migration) {
+MigrationState *s = current_migration-mig_state;
+
+switch (s-get_status(current_migration)) {
 case MIG_STATE_ACTIVE:
 qdict = qdict_new();
 qdict_put(qdict, status, qstring_from_str(active));
@@ -404,16 +406,13 @@ void migrate_fd_put_ready(void *opaque)
 }
 }

-int migrate_fd_get_status(MigrationState *mig_state)
+int migrate_fd_get_status(FdMigrationState *s)
 {
-FdMigrationState *s = migrate_to_fms(mig_state);
 return s-state;
 }

-void migrate_fd_cancel(MigrationState *mig_state)
+void migrate_fd_cancel(FdMigrationState *s)
 {
-FdMigrationState *s = migrate_to_fms(mig_state);
-
 if (s-state != MIG_STATE_ACTIVE)
 return;

@@ -426,9 +425,8 @@ void migrate_fd_cancel(MigrationState *mig_state)
 migrate_fd_cleanup(s);
 }

-void migrate_fd_release(MigrationState *mig_state)
+void migrate_fd_release(FdMigrationState *s)
 {
-FdMigrationState *s = migrate_to_fms(mig_state);

 DPRINTF(releasing state\n);

diff --git a/migration.h b/migration.h
index 58354c7..b10bb6e 100644
--- a/migration.h
+++ b/migration.h
@@ -25,18 +25,18 @@

 typedef struct MigrationState MigrationState;

+typedef struct FdMigrationState FdMigrationState;
+
 struct MigrationState
 {
 /* FIXME: add more accessors to print migration info */
-void (*cancel)(MigrationState *s);
-int (*get_status)(MigrationState *s);
-void (*release)(MigrationState *s);
+void (*cancel)(FdMigrationState *s);
+int (*get_status)(FdMigrationState *s);
+void (*release)(FdMigrationState *s);
 int blk;
 int shared;
 };

-typedef struct FdMigrationState FdMigrationState;
-
 struct FdMigrationState
 {
 MigrationState mig_state;
@@ -120,11 +120,11 @@ void migrate_fd_connect(FdMigrationState *s);

 void migrate_fd_put_ready(void *opaque);

-int migrate_fd_get_status(MigrationState *mig_state);
+int migrate_fd_get_status(FdMigrationState *mig_state);

-void migrate_fd_cancel(MigrationState *mig_state);
+void migrate_fd_cancel(FdMigrationState *mig_state);

-void migrate_fd_release(MigrationState *mig_state);
+void migrate_fd_release(FdMigrationState *mig_state);

 void migrate_fd_wait_for_unfreeze(void *opaque);

-- 
1.7.6.4




[Qemu-devel] [PATCH 14/36] migration: use qemu_file_get_error() return value when possible

2011-10-11 Thread Juan Quintela
Signed-off-by: Juan Quintela quint...@redhat.com
---
 arch_init.c   |6 --
 block-migration.c |7 ---
 buffered_file.c   |   13 -
 savevm.c  |4 ++--
 4 files changed, 18 insertions(+), 12 deletions(-)

diff --git a/arch_init.c b/arch_init.c
index 9128be0..98daaf3 100644
--- a/arch_init.c
+++ b/arch_init.c
@@ -371,6 +371,7 @@ int ram_load(QEMUFile *f, void *opaque, int version_id)
 {
 ram_addr_t addr;
 int flags;
+int error;

 if (version_id  3 || version_id  4) {
 return -EINVAL;
@@ -451,8 +452,9 @@ int ram_load(QEMUFile *f, void *opaque, int version_id)

 qemu_get_buffer(f, host, TARGET_PAGE_SIZE);
 }
-if (qemu_file_get_error(f)) {
-return -EIO;
+error = qemu_file_get_error(f);
+if (error) {
+return error;
 }
 } while (!(flags  RAM_SAVE_FLAG_EOS));

diff --git a/block-migration.c b/block-migration.c
index 8308753..e36f2e3 100644
--- a/block-migration.c
+++ b/block-migration.c
@@ -646,6 +646,7 @@ static int block_load(QEMUFile *f, void *opaque, int 
version_id)
 uint8_t *buf;
 int64_t total_sectors = 0;
 int nr_sectors;
+int ret;

 do {
 addr = qemu_get_be64(f);
@@ -654,7 +655,6 @@ static int block_load(QEMUFile *f, void *opaque, int 
version_id)
 addr = BDRV_SECTOR_BITS;

 if (flags  BLK_MIG_FLAG_DEVICE_BLOCK) {
-int ret;
 /* get device name */
 len = qemu_get_byte(f);
 qemu_get_buffer(f, (uint8_t *)device_name, len);
@@ -704,8 +704,9 @@ static int block_load(QEMUFile *f, void *opaque, int 
version_id)
 fprintf(stderr, Unknown flags\n);
 return -EINVAL;
 }
-if (qemu_file_get_error(f)) {
-return -EIO;
+ret = qemu_file_get_error(f);
+if (ret != 0) {
+return ret;
 }
 } while (!(flags  BLK_MIG_FLAG_EOS));

diff --git a/buffered_file.c b/buffered_file.c
index 82f4001..42bbbd3 100644
--- a/buffered_file.c
+++ b/buffered_file.c
@@ -71,9 +71,11 @@ static void buffered_append(QEMUFileBuffered *s,
 static void buffered_flush(QEMUFileBuffered *s)
 {
 size_t offset = 0;
+int error;

-if (qemu_file_get_error(s-file)) {
-DPRINTF(flush when error, bailing\n);
+error = qemu_file_get_error(s-file);
+if (error != 0) {
+DPRINTF(flush when error, bailing: %s\n, strerror(-error));
 return;
 }

@@ -108,13 +110,14 @@ static void buffered_flush(QEMUFileBuffered *s)
 static int buffered_put_buffer(void *opaque, const uint8_t *buf, int64_t pos, 
int size)
 {
 QEMUFileBuffered *s = opaque;
-int offset = 0;
+int offset = 0, error;
 ssize_t ret;

 DPRINTF(putting %d bytes at % PRId64 \n, size, pos);

-if (qemu_file_get_error(s-file)) {
-DPRINTF(flush when error, bailing\n);
+error = qemu_file_get_error(s-file);
+if (error) {
+DPRINTF(flush when error, bailing: %s\n, strerror(-error));
 return -EINVAL;
 }

diff --git a/savevm.c b/savevm.c
index 69a2ccd..3042ae5 100644
--- a/savevm.c
+++ b/savevm.c
@@ -1835,8 +1835,8 @@ out:
 g_free(le);
 }

-if (qemu_file_get_error(f)) {
-ret = -EIO;
+if (ret == 0) {
+ret = qemu_file_get_error(f);
 }

 return ret;
-- 
1.7.6.4




[Qemu-devel] [PATCH 23/36] migration: Refactor and simplify error checking in migrate_fd_put_ready

2011-10-11 Thread Juan Quintela
Signed-off-by: Juan Quintela quint...@redhat.com
---
 migration.c |   21 ++---
 1 files changed, 10 insertions(+), 11 deletions(-)

diff --git a/migration.c b/migration.c
index a01bf4f..432afe6 100644
--- a/migration.c
+++ b/migration.c
@@ -372,23 +372,22 @@ static void migrate_fd_put_ready(void *opaque)
 DPRINTF(done iterating\n);
 vm_stop(RUN_STATE_FINISH_MIGRATE);

-if ((qemu_savevm_state_complete(s-mon, s-file))  0) {
-if (old_vm_running) {
-vm_start();
+if (qemu_savevm_state_complete(s-mon, s-file)  0) {
+migrate_fd_error(s);
+} else {
+if (migrate_fd_cleanup(s)  0) {
+migrate_fd_error(s);
+} else {
+s-state = MIG_STATE_COMPLETED;
+runstate_set(RUN_STATE_POSTMIGRATE);
+notifier_list_notify(migration_state_notifiers, NULL);
 }
-s-state = MIG_STATE_ERROR;
 }
-if (migrate_fd_cleanup(s)  0) {
+if (s-get_status(s) != MIG_STATE_COMPLETED) {
 if (old_vm_running) {
 vm_start();
 }
-s-state = MIG_STATE_ERROR;
 }
-if (s-state == MIG_STATE_ACTIVE) {
-s-state = MIG_STATE_COMPLETED;
-runstate_set(RUN_STATE_POSTMIGRATE);
-}
-notifier_list_notify(migration_state_notifiers, NULL);
 }
 }

-- 
1.7.6.4




[Qemu-devel] [PATCH 09/36] migration: don't write when migration is not active

2011-10-11 Thread Juan Quintela
If migration is not active, just ignore writes.

Signed-off-by: Juan Quintela quint...@redhat.com
---
 migration.c |4 
 1 files changed, 4 insertions(+), 0 deletions(-)

diff --git a/migration.c b/migration.c
index 7ac1fc2..090c925 100644
--- a/migration.c
+++ b/migration.c
@@ -323,6 +323,10 @@ ssize_t migrate_fd_put_buffer(void *opaque, const void 
*data, size_t size)
 FdMigrationState *s = opaque;
 ssize_t ret;

+if (s-state != MIG_STATE_ACTIVE) {
+return -EIO;
+}
+
 do {
 ret = s-write(s, data, size);
 } while (ret == -1  ((s-get_error(s)) == EINTR));
-- 
1.7.6.4




[Qemu-devel] [PATCH -V2 05/13] virtio-9p: Use 9P specific Lock constants

2011-10-11 Thread Aneesh Kumar K.V
From: M. Mohan Kumar mo...@in.ibm.com

Use 9P specific lock constants instead of arch specific lock constants.

Signed-off-by: M. Mohan Kumar mo...@in.ibm.com
Signed-off-by: Aneesh Kumar K.V aneesh.ku...@linux.vnet.ibm.com
---
 hw/9pfs/virtio-9p.c |2 +-
 hw/9pfs/virtio-9p.h |5 +
 2 files changed, 6 insertions(+), 1 deletions(-)

diff --git a/hw/9pfs/virtio-9p.c b/hw/9pfs/virtio-9p.c
index 3958788..d476485 100644
--- a/hw/9pfs/virtio-9p.c
+++ b/hw/9pfs/virtio-9p.c
@@ -2930,7 +2930,7 @@ static void v9fs_getlock(void *opaque)
 if (err  0) {
 goto out;
 }
-glock-type = F_UNLCK;
+glock-type = P9_LOCK_TYPE_UNLCK;
 offset += pdu_marshal(pdu, offset, bqqds, glock-type,
   glock-start, glock-length, glock-proc_id,
   glock-client_id);
diff --git a/hw/9pfs/virtio-9p.h b/hw/9pfs/virtio-9p.h
index 60b8a56..e5cf78c 100644
--- a/hw/9pfs/virtio-9p.h
+++ b/hw/9pfs/virtio-9p.h
@@ -352,6 +352,11 @@ typedef struct V9fsMkState {
 V9fsString fullname;
 } V9fsMkState;
 
+/* 9P2000.L lock type */
+#define P9_LOCK_TYPE_RDLCK 0
+#define P9_LOCK_TYPE_WRLCK 1
+#define P9_LOCK_TYPE_UNLCK 2
+
 #define P9_LOCK_SUCCESS 0
 #define P9_LOCK_BLOCKED 1
 #define P9_LOCK_ERROR 2
-- 
1.7.5.4




[Qemu-devel] [PATCH -V2 04/13] hw/9pfs: Fix build error on platform that don't support futimens

2011-10-11 Thread Aneesh Kumar K.V
From: Aneesh Kumar K.V aneesh.ku...@linux.vnet.ibm.com

Also don't do glibc version check to find handle support. Instead
do handle syscall support in configure.

Signed-off-by: Aneesh Kumar K.V aneesh.ku...@linux.vnet.ibm.com
---
 configure  |   16 +
 hw/9pfs/virtio-9p-handle.c |   52 ---
 2 files changed, 40 insertions(+), 28 deletions(-)

diff --git a/configure b/configure
index 24b8df4..0216c53 100755
--- a/configure
+++ b/configure
@@ -2551,6 +2551,18 @@ EOF
 fi
 
 ##
+# check if we have open_by_handle_at
+
+open_by_hande_at=no
+cat  $TMPC  EOF
+#include fcntl.h
+int main(void) { struct file_handle *fh; open_by_handle_at(0, fh, 0); }
+EOF
+if compile_prog   ; then
+open_by_handle_at=yes
+fi
+
+##
 # End of CC checks
 # After here, no more $cc or $ld runs
 
@@ -3029,6 +3041,10 @@ if test $ucontext_coroutine = yes ; then
   echo CONFIG_UCONTEXT_COROUTINE=y  $config_host_mak
 fi
 
+if test $open_by_handle_at = yes ; then
+  echo CONFIG_OPEN_BY_HANDLE=y  $config_host_mak
+fi
+
 # USB host support
 case $usb in
 linux)
diff --git a/hw/9pfs/virtio-9p-handle.c b/hw/9pfs/virtio-9p-handle.c
index 441a37f..fbe3e62 100644
--- a/hw/9pfs/virtio-9p-handle.c
+++ b/hw/9pfs/virtio-9p-handle.c
@@ -27,13 +27,24 @@ struct handle_data {
 int handle_bytes;
 };
 
-#if __GLIBC__ = 2  __GLIBC_MINOR__  14
+#ifdef CONFIG_OPEN_BY_HANDLE
+static inline int name_to_handle(int dirfd, const char *name,
+ struct file_handle *fh, int *mnt_id, int 
flags)
+{
+return name_to_handle_at(dirfd, name, fh, mnt_id, flags);
+}
+
+static inline int open_by_handle(int mountfd, const char *fh, int flags)
+{
+return open_by_handle_at(mountfd, (struct file_handle *)fh, flags);
+}
+#else
+
 struct file_handle {
-unsigned int handle_bytes;
-int handle_type;
-unsigned char handle[0];
+unsigned int handle_bytes;
+int handle_type;
+unsigned char handle[0];
 };
-#endif
 
 #ifndef AT_EMPTY_PATH
 #define AT_EMPTY_PATH   0x1000  /* Allow empty relative pathname */
@@ -42,28 +53,6 @@ struct file_handle {
 #define O_PATH01000
 #endif
 
-#ifndef __NR_name_to_handle_at
-#if defined(__i386__)
-#define __NR_name_to_handle_at  341
-#define __NR_open_by_handle_at  342
-#elif defined(__x86_64__)
-#define __NR_name_to_handle_at  303
-#define __NR_open_by_handle_at  304
-#endif
-#endif
-
-#ifdef __NR_name_to_handle_at
-static inline int name_to_handle(int dirfd, const char *name,
- struct file_handle *fh, int *mnt_id, int 
flags)
-{
-return syscall(__NR_name_to_handle_at, dirfd, name, fh, mnt_id, flags);
-}
-
-static inline int open_by_handle(int mountfd, const char *fh, int flags)
-{
-return syscall(__NR_open_by_handle_at, mountfd, fh, flags);
-}
-#else
 static inline int name_to_handle(int dirfd, const char *name,
  struct file_handle *fh, int *mnt_id, int 
flags)
 {
@@ -376,7 +365,9 @@ static int handle_chown(FsContext *fs_ctx, V9fsPath 
*fs_path, FsCred *credp)
 static int handle_utimensat(FsContext *ctx, V9fsPath *fs_path,
 const struct timespec *buf)
 {
-int fd, ret;
+int ret;
+#ifdef CONFIG_UTIMENSAT
+int fd;
 struct handle_data *data = (struct handle_data *)ctx-private;
 
 fd = open_by_handle(data-mountfd, fs_path-data, O_NONBLOCK);
@@ -385,6 +376,10 @@ static int handle_utimensat(FsContext *ctx, V9fsPath 
*fs_path,
 }
 ret = futimens(fd, buf);
 close(fd);
+#else
+ret = -1;
+errno = ENOSYS;
+#endif
 return ret;
 }
 
@@ -560,6 +555,7 @@ static int handle_init(FsContext *ctx)
 int ret, mnt_id;
 struct file_handle fh;
 struct handle_data *data = g_malloc(sizeof(struct handle_data));
+
 data-mountfd = open(ctx-fs_root, O_DIRECTORY);
 if (data-mountfd  0) {
 ret = data-mountfd;
-- 
1.7.5.4




[Qemu-devel] [PATCH 02/36] migration: simplify state assignmente

2011-10-11 Thread Juan Quintela
Once there, make sure that if we already know that there is one error,
just call migration_fd_cleanup() with the ERROR state.

Signed-off-by: Juan Quintela quint...@redhat.com
---
 migration.c |   11 ---
 1 files changed, 4 insertions(+), 7 deletions(-)

diff --git a/migration.c b/migration.c
index 77a51ad..7fd6c23 100644
--- a/migration.c
+++ b/migration.c
@@ -371,7 +371,6 @@ void migrate_fd_put_ready(void *opaque)

 DPRINTF(iterate\n);
 if (qemu_savevm_state_iterate(s-mon, s-file) == 1) {
-int state;
 int old_vm_running = runstate_is_running();

 DPRINTF(done iterating\n);
@@ -381,20 +380,18 @@ void migrate_fd_put_ready(void *opaque)
 if (old_vm_running) {
 vm_start();
 }
-state = MIG_STATE_ERROR;
-} else {
-state = MIG_STATE_COMPLETED;
+s-state = MIG_STATE_ERROR;
 }
 if (migrate_fd_cleanup(s)  0) {
 if (old_vm_running) {
 vm_start();
 }
-state = MIG_STATE_ERROR;
+s-state = MIG_STATE_ERROR;
 }
-if (state == MIG_STATE_COMPLETED) {
+if (s-state == MIG_STATE_ACTIVE) {
+s-state = MIG_STATE_COMPLETED;
 runstate_set(RUN_STATE_POSTMIGRATE);
 }
-s-state = state;
 notifier_list_notify(migration_state_notifiers, NULL);
 }
 }
-- 
1.7.6.4




[Qemu-devel] [PATCH 05/36] migration: add error handling to migrate_fd_put_notify().

2011-10-11 Thread Juan Quintela
From: Yoshiaki Tamura tamura.yoshi...@lab.ntt.co.jp

Although migrate_fd_put_buffer() sets MIG_STATE_ERROR if it failed,
since migrate_fd_put_notify() isn't checking error of underlying
QEMUFile, those resources are kept open.  This patch checks it and
calls migrate_fd_error() in case of error.

Signed-off-by: Yoshiaki Tamura tamura.yoshi...@lab.ntt.co.jp
Signed-off-by: Juan Quintela quint...@redhat.com
---
 migration.c |6 +++---
 1 files changed, 3 insertions(+), 3 deletions(-)

diff --git a/migration.c b/migration.c
index 2d3a55b..7ac1fc2 100644
--- a/migration.c
+++ b/migration.c
@@ -313,6 +313,9 @@ void migrate_fd_put_notify(void *opaque)

 qemu_set_fd_handler2(s-fd, NULL, NULL, NULL, NULL);
 qemu_file_put_notify(s-file);
+if (qemu_file_has_error(s-file)) {
+migrate_fd_error(s);
+}
 }

 ssize_t migrate_fd_put_buffer(void *opaque, const void *data, size_t size)
@@ -329,9 +332,6 @@ ssize_t migrate_fd_put_buffer(void *opaque, const void 
*data, size_t size)

 if (ret == -EAGAIN) {
 qemu_set_fd_handler2(s-fd, NULL, NULL, migrate_fd_put_notify, s);
-} else if (ret  0) {
-s-state = MIG_STATE_ERROR;
-notifier_list_notify(migration_state_notifiers, NULL);
 }

 return ret;
-- 
1.7.6.4




[Qemu-devel] [PATCH 31/36] migration: Pass MigrationState in migration notifiers

2011-10-11 Thread Juan Quintela
Signed-off-by: Juan Quintela quint...@redhat.com
---
 migration.c |8 
 1 files changed, 4 insertions(+), 4 deletions(-)

diff --git a/migration.c b/migration.c
index 4f308ce..6129cb5 100644
--- a/migration.c
+++ b/migration.c
@@ -222,7 +222,7 @@ void migrate_fd_error(MigrationState *s)
 {
 DPRINTF(setting error state\n);
 s-state = MIG_STATE_ERROR;
-notifier_list_notify(migration_state_notifiers, NULL);
+notifier_list_notify(migration_state_notifiers, s);
 migrate_fd_cleanup(s);
 }

@@ -235,7 +235,7 @@ static void migrate_fd_completed(MigrationState *s)
 s-state = MIG_STATE_COMPLETED;
 runstate_set(RUN_STATE_POSTMIGRATE);
 }
-notifier_list_notify(migration_state_notifiers, NULL);
+notifier_list_notify(migration_state_notifiers, s);
 }

 static void migrate_fd_put_notify(void *opaque)
@@ -314,7 +314,7 @@ static void migrate_fd_cancel(MigrationState *s)
 DPRINTF(cancelling migration\n);

 s-state = MIG_STATE_CANCELLED;
-notifier_list_notify(migration_state_notifiers, NULL);
+notifier_list_notify(migration_state_notifiers, s);
 qemu_savevm_state_cancel(s-mon, s-file);

 migrate_fd_cleanup(s);
@@ -452,7 +452,7 @@ int do_migrate(Monitor *mon, const QDict *qdict, QObject 
**ret_data)
 return ret;
 }

-notifier_list_notify(migration_state_notifiers, NULL);
+notifier_list_notify(migration_state_notifiers, s);
 return 0;
 }

-- 
1.7.6.4




[Qemu-devel] [PATCH 33/36] migration: Make state definitions local

2011-10-11 Thread Juan Quintela
Signed-off-by: Juan Quintela quint...@redhat.com
---
 migration.c |8 
 migration.h |8 
 2 files changed, 8 insertions(+), 8 deletions(-)

diff --git a/migration.c b/migration.c
index c4e2ba6..e9237f3 100644
--- a/migration.c
+++ b/migration.c
@@ -31,6 +31,14 @@
 do { } while (0)
 #endif

+enum migration_state {
+MIG_STATE_ERROR,
+MIG_STATE_SETUP,
+MIG_STATE_CANCELLED,
+MIG_STATE_ACTIVE,
+MIG_STATE_COMPLETED,
+};
+
 #define MAX_THROTTLE  (32  20)  /* Migration speed throttling */

 static NotifierList migration_state_notifiers =
diff --git a/migration.h b/migration.h
index 7ae127f..a1f80d0 100644
--- a/migration.h
+++ b/migration.h
@@ -18,14 +18,6 @@
 #include qemu-common.h
 #include notify.h

-enum migration_state {
-MIG_STATE_ERROR,
-MIG_STATE_SETUP,
-MIG_STATE_CANCELLED,
-MIG_STATE_ACTIVE,
-MIG_STATE_COMPLETED,
-};
-
 typedef struct MigrationState MigrationState;

 struct MigrationState
-- 
1.7.6.4




[Qemu-devel] [PATCH 15/36] migration: Make *start_outgoing_migration return FdMigrationState

2011-10-11 Thread Juan Quintela
Signed-off-by: Juan Quintela quint...@redhat.com
---
 migration-exec.c |4 ++--
 migration-fd.c   |4 ++--
 migration-tcp.c  |4 ++--
 migration-unix.c |4 ++--
 migration.c  |4 ++--
 migration.h  |8 
 6 files changed, 14 insertions(+), 14 deletions(-)

diff --git a/migration-exec.c b/migration-exec.c
index 2cfb6f2..759aa79 100644
--- a/migration-exec.c
+++ b/migration-exec.c
@@ -61,7 +61,7 @@ static int exec_close(FdMigrationState *s)
 return ret;
 }

-MigrationState *exec_start_outgoing_migration(Monitor *mon,
+FdMigrationState *exec_start_outgoing_migration(Monitor *mon,
   const char *command,
  int64_t bandwidth_limit,
  int detach,
@@ -108,7 +108,7 @@ MigrationState *exec_start_outgoing_migration(Monitor *mon,
 }

 migrate_fd_connect(s);
-return s-mig_state;
+return s;

 err_after_open:
 pclose(f);
diff --git a/migration-fd.c b/migration-fd.c
index aee690a..8036a27 100644
--- a/migration-fd.c
+++ b/migration-fd.c
@@ -50,7 +50,7 @@ static int fd_close(FdMigrationState *s)
 return 0;
 }

-MigrationState *fd_start_outgoing_migration(Monitor *mon,
+FdMigrationState *fd_start_outgoing_migration(Monitor *mon,
const char *fdname,
int64_t bandwidth_limit,
int detach,
@@ -91,7 +91,7 @@ MigrationState *fd_start_outgoing_migration(Monitor *mon,
 }

 migrate_fd_connect(s);
-return s-mig_state;
+return s;

 err_after_open:
 close(s-fd);
diff --git a/migration-tcp.c b/migration-tcp.c
index c431e03..05a121f 100644
--- a/migration-tcp.c
+++ b/migration-tcp.c
@@ -75,7 +75,7 @@ static void tcp_wait_for_connect(void *opaque)
 }
 }

-MigrationState *tcp_start_outgoing_migration(Monitor *mon,
+FdMigrationState *tcp_start_outgoing_migration(Monitor *mon,
  const char *host_port,
  int64_t bandwidth_limit,
  int detach,
@@ -131,7 +131,7 @@ MigrationState *tcp_start_outgoing_migration(Monitor *mon,
 } else if (ret = 0)
 migrate_fd_connect(s);

-return s-mig_state;
+return s;
 }

 static void tcp_accept_incoming_migration(void *opaque)
diff --git a/migration-unix.c b/migration-unix.c
index 6dc985d..0eeedde 100644
--- a/migration-unix.c
+++ b/migration-unix.c
@@ -74,7 +74,7 @@ static void unix_wait_for_connect(void *opaque)
 }
 }

-MigrationState *unix_start_outgoing_migration(Monitor *mon,
+FdMigrationState *unix_start_outgoing_migration(Monitor *mon,
   const char *path,
  int64_t bandwidth_limit,
  int detach,
@@ -132,7 +132,7 @@ MigrationState *unix_start_outgoing_migration(Monitor *mon,
 if (ret = 0)
 migrate_fd_connect(s);

-return s-mig_state;
+return s;

 err_after_open:
 close(s-fd);
diff --git a/migration.c b/migration.c
index 6bac734..4449594 100644
--- a/migration.c
+++ b/migration.c
@@ -79,7 +79,7 @@ void process_incoming_migration(QEMUFile *f)

 int do_migrate(Monitor *mon, const QDict *qdict, QObject **ret_data)
 {
-MigrationState *s = NULL;
+FdMigrationState *s = NULL;
 const char *p;
 int detach = qdict_get_try_bool(qdict, detach, 0);
 int blk = qdict_get_try_bool(qdict, blk, 0);
@@ -124,7 +124,7 @@ int do_migrate(Monitor *mon, const QDict *qdict, QObject 
**ret_data)
 current_migration-release(current_migration);
 }

-current_migration = s;
+current_migration = s-mig_state;
 notifier_list_notify(migration_state_notifiers, NULL);
 return 0;
 }
diff --git a/migration.h b/migration.h
index 050c56c..58354c7 100644
--- a/migration.h
+++ b/migration.h
@@ -72,7 +72,7 @@ void do_info_migrate(Monitor *mon, QObject **ret_data);

 int exec_start_incoming_migration(const char *host_port);

-MigrationState *exec_start_outgoing_migration(Monitor *mon,
+FdMigrationState *exec_start_outgoing_migration(Monitor *mon,
   const char *host_port,
  int64_t bandwidth_limit,
  int detach,
@@ -81,7 +81,7 @@ MigrationState *exec_start_outgoing_migration(Monitor *mon,

 int tcp_start_incoming_migration(const char *host_port);

-MigrationState *tcp_start_outgoing_migration(Monitor *mon,
+FdMigrationState *tcp_start_outgoing_migration(Monitor *mon,
  const char *host_port,
 int64_t bandwidth_limit,
 int detach,
@@ -90,7 +90,7 @@ MigrationState 

[Qemu-devel] [PATCH -V2 07/13] hw/9pfs: Add open flag mapping

2011-10-11 Thread Aneesh Kumar K.V
From: M. Mohan Kumar mo...@in.ibm.com

Some of the flags are OS/arch dependent we need to use
9P defined value on wire,

Based on the original patch from Venkateswararao Jujjuri 
jv...@linux.vnet.ibm.com

Signed-off-by: M. Mohan Kumar mo...@in.ibm.com
Signed-off-by: Aneesh Kumar K.V aneesh.ku...@linux.vnet.ibm.com
---
 hw/9pfs/virtio-9p.c |   53 ++-
 hw/9pfs/virtio-9p.h |   24 +++
 2 files changed, 76 insertions(+), 1 deletions(-)

diff --git a/hw/9pfs/virtio-9p.c b/hw/9pfs/virtio-9p.c
index d476485..dcbcdb0 100644
--- a/hw/9pfs/virtio-9p.c
+++ b/hw/9pfs/virtio-9p.c
@@ -72,6 +72,55 @@ static int omode_to_uflags(int8_t mode)
 return ret;
 }
 
+static int dotl_to_at_flags(int flags)
+{
+int rflags = 0;
+if (flags  P9_DOTL_AT_REMOVEDIR) {
+rflags |= AT_REMOVEDIR;
+}
+return rflags;
+}
+
+struct dotl_openflag_map {
+int dotl_flag;
+int open_flag;
+};
+
+static int dotl_to_open_flags(int flags)
+{
+int i;
+/*
+ * We have same bits for P9_DOTL_READONLY, P9_DOTL_WRONLY
+ * and P9_DOTL_NOACCESS
+ */
+int oflags = flags  O_ACCMODE;
+
+struct dotl_openflag_map dotl_oflag_map[] = {
+{ P9_DOTL_CREATE, O_CREAT },
+{ P9_DOTL_EXCL, O_EXCL },
+{ P9_DOTL_NOCTTY , O_NOCTTY },
+{ P9_DOTL_TRUNC, O_TRUNC },
+{ P9_DOTL_APPEND, O_APPEND },
+{ P9_DOTL_NONBLOCK, O_NONBLOCK } ,
+{ P9_DOTL_DSYNC, O_DSYNC },
+{ P9_DOTL_FASYNC, FASYNC },
+{ P9_DOTL_DIRECT, O_DIRECT },
+{ P9_DOTL_LARGEFILE, O_LARGEFILE },
+{ P9_DOTL_DIRECTORY, O_DIRECTORY },
+{ P9_DOTL_NOFOLLOW, O_NOFOLLOW },
+{ P9_DOTL_NOATIME, O_NOATIME },
+{ P9_DOTL_SYNC, O_SYNC },
+};
+
+for (i = 0; i  ARRAY_SIZE(dotl_oflag_map); i++) {
+if (flags  dotl_oflag_map[i].dotl_flag) {
+oflags |= dotl_oflag_map[i].open_flag;
+}
+}
+
+return oflags;
+}
+
 void cred_init(FsCred *credp)
 {
 credp-fc_uid = -1;
@@ -86,7 +135,8 @@ static int get_dotl_openflags(V9fsState *s, int oflags)
 /*
  * Filter the client open flags
  */
-flags = oflags  ~(O_NOCTTY | O_ASYNC | O_CREAT);
+flags = dotl_to_open_flags(oflags);
+flags = ~(O_NOCTTY | O_ASYNC | O_CREAT);
 /*
  * Ignore direct disk access hint until the server supports it.
  */
@@ -2427,6 +2477,7 @@ static void v9fs_unlinkat(void *opaque)
 V9fsPDU *pdu = opaque;
 
 pdu_unmarshal(pdu, offset, dsd, dfid, name, flags);
+flags = dotl_to_at_flags(flags);
 
 dfidp = get_fid(pdu, dfid);
 if (dfidp == NULL) {
diff --git a/hw/9pfs/virtio-9p.h b/hw/9pfs/virtio-9p.h
index e5cf78c..e94041e 100644
--- a/hw/9pfs/virtio-9p.h
+++ b/hw/9pfs/virtio-9p.h
@@ -352,6 +352,30 @@ typedef struct V9fsMkState {
 V9fsString fullname;
 } V9fsMkState;
 
+/* 9p2000.L open flags */
+#define P9_DOTL_RDONLY
+#define P9_DOTL_WRONLY0001
+#define P9_DOTL_RDWR  0002
+#define P9_DOTL_NOACCESS  0003
+#define P9_DOTL_CREATE0100
+#define P9_DOTL_EXCL  0200
+#define P9_DOTL_NOCTTY0400
+#define P9_DOTL_TRUNC 1000
+#define P9_DOTL_APPEND2000
+#define P9_DOTL_NONBLOCK  4000
+#define P9_DOTL_DSYNC 0001
+#define P9_DOTL_FASYNC0002
+#define P9_DOTL_DIRECT0004
+#define P9_DOTL_LARGEFILE 0010
+#define P9_DOTL_DIRECTORY 0020
+#define P9_DOTL_NOFOLLOW  0040
+#define P9_DOTL_NOATIME   0100
+#define P9_DOTL_CLOEXEC   0200
+#define P9_DOTL_SYNC  0400
+
+/* 9p2000.L at flags */
+#define P9_DOTL_AT_REMOVEDIR 0x200
+
 /* 9P2000.L lock type */
 #define P9_LOCK_TYPE_RDLCK 0
 #define P9_LOCK_TYPE_WRLCK 1
-- 
1.7.5.4




[Qemu-devel] [PATCH V2 00/13] VirtFS update

2011-10-11 Thread Aneesh Kumar K.V
Pending patches in VirtFS tree for which i will be sending a pull request
after this review.

-aneesh




[Qemu-devel] [PATCH 24/36] migration: Introduce migrate_fd_completed() for consistency

2011-10-11 Thread Juan Quintela
This function is a bit different of the others that change the state,
in the sense that if migrate_fd_cleanup() returns an error, it set the
status to error, not completed.

Signed-off-by: Juan Quintela quint...@redhat.com
---
 migration.c |   20 +---
 1 files changed, 13 insertions(+), 7 deletions(-)

diff --git a/migration.c b/migration.c
index 432afe6..a8e936e 100644
--- a/migration.c
+++ b/migration.c
@@ -317,6 +317,18 @@ void migrate_fd_error(MigrationState *s)
 migrate_fd_cleanup(s);
 }

+static void migrate_fd_completed(MigrationState *s)
+{
+DPRINTF(setting completed state\n);
+if (migrate_fd_cleanup(s)  0) {
+s-state = MIG_STATE_ERROR;
+} else {
+s-state = MIG_STATE_COMPLETED;
+runstate_set(RUN_STATE_POSTMIGRATE);
+}
+notifier_list_notify(migration_state_notifiers, NULL);
+}
+
 static void migrate_fd_put_notify(void *opaque)
 {
 MigrationState *s = opaque;
@@ -375,13 +387,7 @@ static void migrate_fd_put_ready(void *opaque)
 if (qemu_savevm_state_complete(s-mon, s-file)  0) {
 migrate_fd_error(s);
 } else {
-if (migrate_fd_cleanup(s)  0) {
-migrate_fd_error(s);
-} else {
-s-state = MIG_STATE_COMPLETED;
-runstate_set(RUN_STATE_POSTMIGRATE);
-notifier_list_notify(migration_state_notifiers, NULL);
-}
+migrate_fd_completed(s);
 }
 if (s-get_status(s) != MIG_STATE_COMPLETED) {
 if (old_vm_running) {
-- 
1.7.6.4




[Qemu-devel] [PATCH -V2 06/13] hw/9pfs: Ensure an error is reported to user if 9pfs mount tag is too long

2011-10-11 Thread Aneesh Kumar K.V
From: Daniel P. Berrange berra...@redhat.com

If the 9pfs mount tag is longer than MAX_TAG_LEN bytes, rather than
silently truncating the tag which will likely break the guest OS,
report an immediate error and exit QEMU

* hw/9pfs/virtio-9p-device.c: Report error  exit if mount tag is
  too long

Signed-off-by: Daniel P. Berrange berra...@redhat.com
Signed-off-by: Aneesh Kumar K.V aneesh.ku...@linux.vnet.ibm.com
---
 hw/9pfs/virtio-9p-device.c |4 +++-
 1 files changed, 3 insertions(+), 1 deletions(-)

diff --git a/hw/9pfs/virtio-9p-device.c b/hw/9pfs/virtio-9p-device.c
index b23e8a4..0930d22 100644
--- a/hw/9pfs/virtio-9p-device.c
+++ b/hw/9pfs/virtio-9p-device.c
@@ -119,7 +119,9 @@ VirtIODevice *virtio_9p_init(DeviceState *dev, V9fsConf 
*conf)
 s-ctx.fs_root = g_strdup(fse-path);
 len = strlen(conf-tag);
 if (len  MAX_TAG_LEN) {
-len = MAX_TAG_LEN;
+fprintf(stderr, mount tag '%s' (%d bytes) is longer than 
+maximum (%d bytes), conf-tag, len, MAX_TAG_LEN);
+exit(1);
 }
 /* s-tag is non-NULL terminated string */
 s-tag = g_malloc(len);
-- 
1.7.5.4




Re: [Qemu-devel] [Spice-devel] viewing continuous guest virtual memory as continuous in qemu

2011-10-11 Thread Gerd Hoffmann

  Hi,


AFAIU this works only when the guest allocates a continuous range of
physical pages. This is a large requirement from the guest, which I'd
like to drop.


Is it?  The world is moving to huge pages, with all the stuff needed for 
it like moving around userspace pages to compact memory and make huge 
page allocation easier.  I think these days it is alot easier to 
allocate 2M of continuous physical memory than it used to be a few years 
ago.  At least on linux, dunno about windows.


When allocating stuff at boot time (say qxl kms driver) allocating even 
larger chunks shouldn't be a big issue.  And having a single big guest 
memory chunk, then register that as qxl memory slot is what works best 
with the existing interfaces I guess.


Another option we can think about is a 64bit PCI bar for the surfaces 
which can be moved out of the low 4G.



So I would like to have the guest use a regular
allocator, generating for instance two sequential pages in virtual
memory that are scattered in physical memory. Those two physical
guest page addresses (gp1 and gp2) correspond to two host virtual
memory addresses (hv1, hv2). I would now like to provide to
spice-server a single virtual address p that maps to those two pages
in sequence.


Playing mapping tricks like this doesn't come for free.  When doing it 
this way we probaby still want to register a big chunk of memory as qxl 
memory slot so we have the mapping cost only once, not for each and 
every surface we create and destroy.


cheers,
  Gerd




[Qemu-devel] [PATCH 30/36] migration: Use bandwidth_limit directly

2011-10-11 Thread Juan Quintela
Now that current_migration always exist, there is no reason for
max_throotle variable.

Signed-off-by: Juan Quintela quint...@redhat.com
---
 migration.c |   15 ---
 1 files changed, 8 insertions(+), 7 deletions(-)

diff --git a/migration.c b/migration.c
index 8422ec3..4f308ce 100644
--- a/migration.c
+++ b/migration.c
@@ -31,8 +31,7 @@
 do { } while (0)
 #endif

-/* Migration speed throttling */
-static int64_t max_throttle = (32  20);
+#define MAX_THROTTLE  (32  20)  /* Migration speed throttling */

 static NotifierList migration_state_notifiers =
 NOTIFIER_LIST_INITIALIZER(migration_state_notifiers);
@@ -45,6 +44,7 @@ static MigrationState *migrate_get_current(void)
 {
 static MigrationState current_migration = {
 .state = MIG_STATE_SETUP,
+.bandwidth_limit = MAX_THROTTLE,
 };

 return current_migration;
@@ -391,12 +391,13 @@ void migrate_fd_connect(MigrationState *s)
 migrate_fd_put_ready(s);
 }

-static MigrationState *migrate_init(Monitor *mon, int64_t bandwidth_limit,
-int detach, int blk, int inc)
+static MigrationState *migrate_init(Monitor *mon, int detach, int blk, int inc)
 {
 MigrationState *s = migrate_get_current();
+int64_t bandwidth_limit = s-bandwidth_limit;

 memset(s, 0, sizeof(*s));
+s-bandwidth_limit = bandwidth_limit;
 s-blk = blk;
 s-shared = inc;
 s-mon = NULL;
@@ -429,7 +430,7 @@ int do_migrate(Monitor *mon, const QDict *qdict, QObject 
**ret_data)
 return -1;
 }

-s = migrate_init(mon, max_throttle, detach, blk, inc);
+s = migrate_init(mon, detach, blk, inc);

 if (strstart(uri, tcp:, p)) {
 ret = tcp_start_outgoing_migration(s, p);
@@ -470,10 +471,10 @@ int do_migrate_set_speed(Monitor *mon, const QDict 
*qdict, QObject **ret_data)
 if (d  0) {
 d = 0;
 }
-max_throttle = d;

 s = migrate_get_current();
-qemu_file_set_rate_limit(s-file, max_throttle);
+s-bandwidth_limit = d;
+qemu_file_set_rate_limit(s-file, s-bandwidth_limit);

 return 0;
 }
-- 
1.7.6.4




[Qemu-devel] [PATCH 13/36] savevm: Rename has_error to last_error field

2011-10-11 Thread Juan Quintela
Now the field contains the last error name, so rename acordingly.

Signed-off-by: Juan Quintela quint...@redhat.com
---
 savevm.c |   16 
 1 files changed, 8 insertions(+), 8 deletions(-)

diff --git a/savevm.c b/savevm.c
index c037eb3..69a2ccd 100644
--- a/savevm.c
+++ b/savevm.c
@@ -173,7 +173,7 @@ struct QEMUFile {
 int buf_size; /* 0 when writing */
 uint8_t buf[IO_BUF_SIZE];

-int has_error;
+int last_error;
 };

 typedef struct QEMUFileStdio
@@ -427,12 +427,12 @@ QEMUFile *qemu_fopen_ops(void *opaque, 
QEMUFilePutBufferFunc *put_buffer,

 int qemu_file_get_error(QEMUFile *f)
 {
-return f-has_error;
+return f-last_error;
 }

 void qemu_file_set_error(QEMUFile *f, int ret)
 {
-f-has_error = ret;
+f-last_error = ret;
 }

 void qemu_fflush(QEMUFile *f)
@@ -447,7 +447,7 @@ void qemu_fflush(QEMUFile *f)
 if (len  0)
 f-buf_offset += f-buf_index;
 else
-f-has_error = -EINVAL;
+f-last_error = -EINVAL;
 f-buf_index = 0;
 }
 }
@@ -468,7 +468,7 @@ static void qemu_fill_buffer(QEMUFile *f)
 f-buf_size = len;
 f-buf_offset += len;
 } else if (len != -EAGAIN)
-f-has_error = len;
+f-last_error = len;
 }

 int qemu_fclose(QEMUFile *f)
@@ -490,13 +490,13 @@ void qemu_put_buffer(QEMUFile *f, const uint8_t *buf, int 
size)
 {
 int l;

-if (!f-has_error  f-is_write == 0  f-buf_index  0) {
+if (!f-last_error  f-is_write == 0  f-buf_index  0) {
 fprintf(stderr,
 Attempted to write to buffer while read buffer is not 
empty\n);
 abort();
 }

-while (!f-has_error  size  0) {
+while (!f-last_error  size  0) {
 l = IO_BUF_SIZE - f-buf_index;
 if (l  size)
 l = size;
@@ -512,7 +512,7 @@ void qemu_put_buffer(QEMUFile *f, const uint8_t *buf, int 
size)

 void qemu_put_byte(QEMUFile *f, int v)
 {
-if (!f-has_error  f-is_write == 0  f-buf_index  0) {
+if (!f-last_error  f-is_write == 0  f-buf_index  0) {
 fprintf(stderr,
 Attempted to write to buffer while read buffer is not 
empty\n);
 abort();
-- 
1.7.6.4




[Qemu-devel] [PATCH 01/13] remove unused function

2011-10-11 Thread Paolo Bonzini
Signed-off-by: Paolo Bonzini pbonz...@redhat.com
---
 hw/mac_dbdma.c |5 -
 hw/mac_dbdma.h |1 -
 2 files changed, 0 insertions(+), 6 deletions(-)

diff --git a/hw/mac_dbdma.c b/hw/mac_dbdma.c
index 5affdd1..1791ec1 100644
--- a/hw/mac_dbdma.c
+++ b/hw/mac_dbdma.c
@@ -661,11 +661,6 @@ void DBDMA_register_channel(void *dbdma, int nchan, 
qemu_irq irq,
 ch-io.channel = ch;
 }
 
-void DBDMA_schedule(void)
-{
-qemu_notify_event();
-}
-
 static void
 dbdma_control_write(DBDMA_channel *ch)
 {
diff --git a/hw/mac_dbdma.h b/hw/mac_dbdma.h
index 933e17c..6d1abe6 100644
--- a/hw/mac_dbdma.h
+++ b/hw/mac_dbdma.h
@@ -41,5 +41,4 @@ struct DBDMA_io {
 void DBDMA_register_channel(void *dbdma, int nchan, qemu_irq irq,
 DBDMA_rw rw, DBDMA_flush flush,
 void *opaque);
-void DBDMA_schedule(void);
 void* DBDMA_init (MemoryRegion **dbdma_mem);
-- 
1.7.6





[Qemu-devel] [PATCH -V2 13/13] hw/9pfs: Use fs driver specific lstat

2011-10-11 Thread Aneesh Kumar K.V
From: M. Mohan Kumar mo...@in.ibm.com

Use file system driver specific lstat instead of generic lstat.

Signed-off-by: M. Mohan Kumar mo...@in.ibm.com
Signed-off-by: Aneesh Kumar K.V aneesh.ku...@linux.vnet.ibm.com
---
 hw/9pfs/virtio-9p-device.c |   33 +++--
 1 files changed, 23 insertions(+), 10 deletions(-)

diff --git a/hw/9pfs/virtio-9p-device.c b/hw/9pfs/virtio-9p-device.c
index bc25af5..aac58ad 100644
--- a/hw/9pfs/virtio-9p-device.c
+++ b/hw/9pfs/virtio-9p-device.c
@@ -50,6 +50,7 @@ VirtIODevice *virtio_9p_init(DeviceState *dev, V9fsConf *conf)
 int i, len;
 struct stat stat;
 FsTypeEntry *fse;
+V9fsPath path;
 
 s = (V9fsState *)virtio_common_init(virtio-9p,
 VIRTIO_ID_9P,
@@ -107,14 +108,6 @@ VirtIODevice *virtio_9p_init(DeviceState *dev, V9fsConf 
*conf)
 s-ctx.xops = none_xattr_ops;
 }
 
-if (lstat(fse-path, stat)) {
-fprintf(stderr, share path %s does not exist\n, fse-path);
-exit(1);
-} else if (!S_ISDIR(stat.st_mode)) {
-fprintf(stderr, share path %s is not a directory\n, fse-path);
-exit(1);
-}
-
 s-ctx.cache_flags = fse-cache_flags;
 s-ctx.fs_root = g_strdup(fse-path);
 s-ctx.exops.get_st_gen = NULL;
@@ -134,8 +127,7 @@ VirtIODevice *virtio_9p_init(DeviceState *dev, V9fsConf 
*conf)
 
 s-ops = fse-ops;
 s-vdev.get_features = virtio_9p_get_features;
-s-config_size = sizeof(struct virtio_9p_config) +
-s-tag_len;
+s-config_size = sizeof(struct virtio_9p_config) + s-tag_len;
 s-vdev.get_config = virtio_9p_get_config;
 s-fid_list = NULL;
 qemu_co_rwlock_init(s-rename_lock);
@@ -149,6 +141,27 @@ VirtIODevice *virtio_9p_init(DeviceState *dev, V9fsConf 
*conf)
 fprintf(stderr, worker thread initialization failed\n);
 exit(1);
 }
+
+/*
+ * Check details of export path, We need to use fs driver
+ * call back to do that. Since we are in the init path, we don't
+ * use co-routines here.
+ */
+v9fs_path_init(path);
+if (s-ops-name_to_path(s-ctx, NULL, /, path)  0) {
+fprintf(stderr,
+error in converting name to path %s, strerror(errno));
+exit(1);
+}
+if (s-ops-lstat(s-ctx, path, stat)) {
+fprintf(stderr, share path %s does not exist\n, fse-path);
+exit(1);
+} else if (!S_ISDIR(stat.st_mode)) {
+fprintf(stderr, share path %s is not a directory\n, fse-path);
+exit(1);
+}
+v9fs_path_free(path);
+
 return s-vdev;
 }
 
-- 
1.7.5.4




[Qemu-devel] [PATCH 06/13] qemu-timer: do not refer to runstate_is_running()

2011-10-11 Thread Paolo Bonzini
Signed-off-by: Paolo Bonzini pbonz...@redhat.com
---
 cpus.c   |1 +
 qemu-timer.c |5 +
 2 files changed, 2 insertions(+), 4 deletions(-)

diff --git a/cpus.c b/cpus.c
index 986c900..64b6943 100644
--- a/cpus.c
+++ b/cpus.c
@@ -1059,6 +1059,7 @@ void pause_all_vcpus(void)
 {
 CPUState *penv = first_cpu;
 
+qemu_clock_enable(vm_clock, false);
 while (penv) {
 penv-stop = 1;
 qemu_cpu_kick(penv);
diff --git a/qemu-timer.c b/qemu-timer.c
index 8129af6..d8507e3 100644
--- a/qemu-timer.c
+++ b/qemu-timer.c
@@ -504,10 +504,7 @@ void qemu_run_all_timers(void)
 }
 
 /* vm time timers */
-if (runstate_is_running()) {
-qemu_run_timers(vm_clock);
-}
-
+qemu_run_timers(vm_clock);
 qemu_run_timers(rt_clock);
 qemu_run_timers(host_clock);
 }
-- 
1.7.6





[Qemu-devel] [PATCH 08/13] qemu-timer: move more stuff out of qemu-timer.c

2011-10-11 Thread Paolo Bonzini
Signed-off-by: Paolo Bonzini pbonz...@redhat.com
---
 qemu-timer.c |   35 ---
 qemu-timer.h |2 ++
 savevm.c |   25 +
 vl.c |1 +
 4 files changed, 32 insertions(+), 31 deletions(-)

diff --git a/qemu-timer.c b/qemu-timer.c
index 7fa81e1..58926dd 100644
--- a/qemu-timer.c
+++ b/qemu-timer.c
@@ -266,11 +266,8 @@ static QEMUClock *qemu_new_clock(int type)
 clock = g_malloc0(sizeof(QEMUClock));
 clock-type = type;
 clock-enabled = 1;
+clock-last = INT64_MIN;
 notifier_list_init(clock-reset_notifiers);
-/* required to detect  report backward jumps */
-if (type == QEMU_CLOCK_HOST) {
-clock-last = get_clock_realtime();
-}
 return clock;
 }
 
@@ -344,7 +341,7 @@ void qemu_del_timer(QEMUTimer *ts)
 
 /* modify the current timer so that it will be fired when current_time
= expire_time. The corresponding callback will be called. */
-static void qemu_mod_timer_ns(QEMUTimer *ts, int64_t expire_time)
+void qemu_mod_timer_ns(QEMUTimer *ts, int64_t expire_time)
 {
 QEMUTimer **pt, *t;
 
@@ -378,8 +375,6 @@ static void qemu_mod_timer_ns(QEMUTimer *ts, int64_t 
expire_time)
 }
 }
 
-/* modify the current timer so that it will be fired when current_time
-   = expire_time. The corresponding callback will be called. */
 void qemu_mod_timer(QEMUTimer *ts, int64_t expire_time)
 {
 qemu_mod_timer_ns(ts, expire_time * ts-scale);
@@ -464,33 +459,11 @@ void init_clocks(void)
 rt_clock = qemu_new_clock(QEMU_CLOCK_REALTIME);
 vm_clock = qemu_new_clock(QEMU_CLOCK_VIRTUAL);
 host_clock = qemu_new_clock(QEMU_CLOCK_HOST);
-
-rtc_clock = host_clock;
 }
 
-/* save a timer */
-void qemu_put_timer(QEMUFile *f, QEMUTimer *ts)
+uint64_t qemu_timer_expire_time_ns(QEMUTimer *ts)
 {
-uint64_t expire_time;
-
-if (qemu_timer_pending(ts)) {
-expire_time = ts-expire_time;
-} else {
-expire_time = -1;
-}
-qemu_put_be64(f, expire_time);
-}
-
-void qemu_get_timer(QEMUFile *f, QEMUTimer *ts)
-{
-uint64_t expire_time;
-
-expire_time = qemu_get_be64(f);
-if (expire_time != -1) {
-qemu_mod_timer_ns(ts, expire_time);
-} else {
-qemu_del_timer(ts);
-}
+return qemu_timer_pending(ts) ? ts-expire_time : -1;
 }
 
 void qemu_run_all_timers(void)
diff --git a/qemu-timer.h b/qemu-timer.h
index b4ea201..9f4ffed 100644
--- a/qemu-timer.h
+++ b/qemu-timer.h
@@ -52,9 +52,11 @@ QEMUTimer *qemu_new_timer(QEMUClock *clock, int scale,
   QEMUTimerCB *cb, void *opaque);
 void qemu_free_timer(QEMUTimer *ts);
 void qemu_del_timer(QEMUTimer *ts);
+void qemu_mod_timer_ns(QEMUTimer *ts, int64_t expire_time);
 void qemu_mod_timer(QEMUTimer *ts, int64_t expire_time);
 int qemu_timer_pending(QEMUTimer *ts);
 int qemu_timer_expired(QEMUTimer *timer_head, int64_t current_time);
+uint64_t qemu_timer_expire_time_ns(QEMUTimer *ts);
 
 void qemu_run_all_timers(void);
 int qemu_alarm_pending(void);
diff --git a/savevm.c b/savevm.c
index bf4d0e7..58f123e 100644
--- a/savevm.c
+++ b/savevm.c
@@ -81,6 +81,7 @@
 #include migration.h
 #include qemu_socket.h
 #include qemu-queue.h
+#include qemu-timer.h
 #include cpus.h
 
 #define SELF_ANNOUNCE_ROUNDS 5
@@ -674,6 +675,30 @@ uint64_t qemu_get_be64(QEMUFile *f)
 return v;
 }
 
+
+/* timer */
+
+void qemu_put_timer(QEMUFile *f, QEMUTimer *ts)
+{
+uint64_t expire_time;
+
+expire_time = qemu_timer_expire_time_ns(ts);
+qemu_put_be64(f, expire_time);
+}
+
+void qemu_get_timer(QEMUFile *f, QEMUTimer *ts)
+{
+uint64_t expire_time;
+
+expire_time = qemu_get_be64(f);
+if (expire_time != -1) {
+qemu_mod_timer_ns(ts, expire_time);
+} else {
+qemu_del_timer(ts);
+}
+}
+
+
 /* bool */
 
 static int get_bool(QEMUFile *f, void *pv, size_t size)
diff --git a/vl.c b/vl.c
index 99f8ced..3726b74 100644
--- a/vl.c
+++ b/vl.c
@@ -2313,6 +2313,7 @@ int main(int argc, char **argv, char **envp)
 runstate_init();
 
 init_clocks();
+rtc_clock = host_clock;
 
 qemu_cache_utils_init(envp);
 
-- 
1.7.6





[Qemu-devel] [PATCH 05/13] qemu-timer: move icount to cpus.c

2011-10-11 Thread Paolo Bonzini
None of this is needed by tools, and most of it can even be made static
inside cpus.c.

Signed-off-by: Paolo Bonzini pbonz...@redhat.com
---
 cpus.c|  295 +
 exec-all.h|   14 +++
 exec.c|3 -
 qemu-common.h |4 +
 qemu-timer.c  |  279 -
 qemu-timer.h  |   24 +-
 6 files changed, 296 insertions(+), 323 deletions(-)

diff --git a/cpus.c b/cpus.c
index 8978779..986c900 100644
--- a/cpus.c
+++ b/cpus.c
@@ -65,6 +65,281 @@
 static CPUState *next_cpu;
 
 /***/
+/* guest cycle counter */
+
+/* Conversion factor from emulated instructions to virtual clock ticks.  */
+static int icount_time_shift;
+/* Arbitrarily pick 1MIPS as the minimum allowable speed.  */
+#define MAX_ICOUNT_SHIFT 10
+/* Compensate for varying guest execution speed.  */
+static int64_t qemu_icount_bias;
+static QEMUTimer *icount_rt_timer;
+static QEMUTimer *icount_vm_timer;
+static QEMUTimer *icount_warp_timer;
+static int64_t vm_clock_warp_start;
+static int64_t qemu_icount;
+
+typedef struct TimersState {
+int64_t cpu_ticks_prev;
+int64_t cpu_ticks_offset;
+int64_t cpu_clock_offset;
+int32_t cpu_ticks_enabled;
+int64_t dummy;
+} TimersState;
+
+TimersState timers_state;
+
+/* Return the virtual CPU time, based on the instruction counter.  */
+int64_t cpu_get_icount(void)
+{
+int64_t icount;
+CPUState *env = cpu_single_env;;
+
+icount = qemu_icount;
+if (env) {
+if (!can_do_io(env)) {
+fprintf(stderr, Bad clock read\n);
+}
+icount -= (env-icount_decr.u16.low + env-icount_extra);
+}
+return qemu_icount_bias + (icount  icount_time_shift);
+}
+
+/* return the host CPU cycle counter and handle stop/restart */
+int64_t cpu_get_ticks(void)
+{
+if (use_icount) {
+return cpu_get_icount();
+}
+if (!timers_state.cpu_ticks_enabled) {
+return timers_state.cpu_ticks_offset;
+} else {
+int64_t ticks;
+ticks = cpu_get_real_ticks();
+if (timers_state.cpu_ticks_prev  ticks) {
+/* Note: non increasing ticks may happen if the host uses
+   software suspend */
+timers_state.cpu_ticks_offset += timers_state.cpu_ticks_prev - 
ticks;
+}
+timers_state.cpu_ticks_prev = ticks;
+return ticks + timers_state.cpu_ticks_offset;
+}
+}
+
+/* return the host CPU monotonic timer and handle stop/restart */
+int64_t cpu_get_clock(void)
+{
+int64_t ti;
+if (!timers_state.cpu_ticks_enabled) {
+return timers_state.cpu_clock_offset;
+} else {
+ti = get_clock();
+return ti + timers_state.cpu_clock_offset;
+}
+}
+
+/* enable cpu_get_ticks() */
+void cpu_enable_ticks(void)
+{
+if (!timers_state.cpu_ticks_enabled) {
+timers_state.cpu_ticks_offset -= cpu_get_real_ticks();
+timers_state.cpu_clock_offset -= get_clock();
+timers_state.cpu_ticks_enabled = 1;
+}
+}
+
+/* disable cpu_get_ticks() : the clock is stopped. You must not call
+   cpu_get_ticks() after that.  */
+void cpu_disable_ticks(void)
+{
+if (timers_state.cpu_ticks_enabled) {
+timers_state.cpu_ticks_offset = cpu_get_ticks();
+timers_state.cpu_clock_offset = cpu_get_clock();
+timers_state.cpu_ticks_enabled = 0;
+}
+}
+
+/* Correlation between real and virtual time is always going to be
+   fairly approximate, so ignore small variation.
+   When the guest is idle real and virtual time will be aligned in
+   the IO wait loop.  */
+#define ICOUNT_WOBBLE (get_ticks_per_sec() / 10)
+
+static void icount_adjust(void)
+{
+int64_t cur_time;
+int64_t cur_icount;
+int64_t delta;
+static int64_t last_delta;
+/* If the VM is not running, then do nothing.  */
+if (!runstate_is_running()) {
+return;
+}
+cur_time = cpu_get_clock();
+cur_icount = qemu_get_clock_ns(vm_clock);
+delta = cur_icount - cur_time;
+/* FIXME: This is a very crude algorithm, somewhat prone to oscillation.  
*/
+if (delta  0
+ last_delta + ICOUNT_WOBBLE  delta * 2
+ icount_time_shift  0) {
+/* The guest is getting too far ahead.  Slow time down.  */
+icount_time_shift--;
+}
+if (delta  0
+ last_delta - ICOUNT_WOBBLE  delta * 2
+ icount_time_shift  MAX_ICOUNT_SHIFT) {
+/* The guest is getting too far behind.  Speed time up.  */
+icount_time_shift++;
+}
+last_delta = delta;
+qemu_icount_bias = cur_icount - (qemu_icount  icount_time_shift);
+}
+
+static void icount_adjust_rt(void *opaque)
+{
+qemu_mod_timer(icount_rt_timer,
+   qemu_get_clock_ms(rt_clock) + 1000);
+icount_adjust();
+}
+
+static void icount_adjust_vm(void *opaque)
+{
+qemu_mod_timer(icount_vm_timer,
+   qemu_get_clock_ns(vm_clock) + 

[Qemu-devel] [PATCH 10/13] create main-loop.h

2011-10-11 Thread Paolo Bonzini
Signed-off-by: Paolo Bonzini pbonz...@redhat.com
---
 async.c   |1 +
 cpus.c|7 +
 cpus.h|1 -
 main-loop.h   |   73 +
 qemu-char.h   |   12 +
 qemu-common.h |   11 
 sysemu.h  |3 +-
 vl.c  |1 +
 8 files changed, 78 insertions(+), 31 deletions(-)
 create mode 100644 main-loop.h

diff --git a/async.c b/async.c
index ca13962..332d511 100644
--- a/async.c
+++ b/async.c
@@ -24,6 +24,7 @@
 
 #include qemu-common.h
 #include qemu-aio.h
+#include main-loop.h
 
 /* Anchor of the list of Bottom Halves belonging to the context */
 static struct QEMUBH *first_bh;
diff --git a/cpus.c b/cpus.c
index 64b6943..aabb7c1 100644
--- a/cpus.c
+++ b/cpus.c
@@ -33,17 +33,12 @@
 
 #include qemu-thread.h
 #include cpus.h
+#include main-loop.h
 
 #ifndef _WIN32
 #include compatfd.h
 #endif
 
-#ifdef SIGRTMIN
-#define SIG_IPI (SIGRTMIN+4)
-#else
-#define SIG_IPI SIGUSR1
-#endif
-
 #ifdef CONFIG_LINUX
 
 #include sys/prctl.h
diff --git a/cpus.h b/cpus.h
index 5885885..4ccf986 100644
--- a/cpus.h
+++ b/cpus.h
@@ -2,7 +2,6 @@
 #define QEMU_CPUS_H
 
 /* cpus.c */
-int qemu_init_main_loop(void);
 void qemu_main_loop_start(void);
 void resume_all_vcpus(void);
 void pause_all_vcpus(void);
diff --git a/main-loop.h b/main-loop.h
new file mode 100644
index 000..7b2e675
--- /dev/null
+++ b/main-loop.h
@@ -0,0 +1,73 @@
+/*
+ * QEMU System Emulator
+ *
+ * Copyright (c) 2003-2008 Fabrice Bellard
+ *
+ * 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_MAIN_LOOP_H
+#define QEMU_MAIN_LOOP_H 1
+
+#ifdef SIGRTMIN
+#define SIG_IPI (SIGRTMIN+4)
+#else
+#define SIG_IPI SIGUSR1
+#endif
+
+int qemu_init_main_loop(void);
+int main_loop_wait(int nonblocking);
+
+/* Force QEMU to process pending events */
+void qemu_notify_event(void);
+
+#ifdef _WIN32
+/* 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
+
+/* async I/O support */
+
+typedef void IOReadHandler(void *opaque, const uint8_t *buf, int size);
+typedef int IOCanReadHandler(void *opaque);
+typedef void IOHandler(void *opaque);
+
+void qemu_iohandler_fill(int *pnfds, fd_set *readfds, fd_set *writefds, fd_set 
*xfds);
+void qemu_iohandler_poll(fd_set *readfds, fd_set *writefds, fd_set *xfds, int 
rc);
+
+int qemu_set_fd_handler2(int fd,
+ IOCanReadHandler *fd_read_poll,
+ IOHandler *fd_read,
+ IOHandler *fd_write,
+ void *opaque);
+int qemu_set_fd_handler(int fd,
+IOHandler *fd_read,
+IOHandler *fd_write,
+void *opaque);
+
+#endif
diff --git a/qemu-char.h b/qemu-char.h
index eebbdd8..7efcf99 100644
--- a/qemu-char.h
+++ b/qemu-char.h
@@ -7,6 +7,7 @@
 #include qemu-config.h
 #include qobject.h
 #include qstring.h
+#include main-loop.h
 
 /* character device */
 
@@ -237,15 +238,4 @@ void qemu_chr_close_mem(CharDriverState *chr);
 QString *qemu_chr_mem_to_qs(CharDriverState *chr);
 size_t qemu_chr_mem_osize(const CharDriverState *chr);
 
-/* async I/O support */
-
-int qemu_set_fd_handler2(int fd,
- IOCanReadHandler *fd_read_poll,
- IOHandler *fd_read,
- IOHandler *fd_write,
- void *opaque);
-int qemu_set_fd_handler(int fd,
-IOHandler *fd_read,
-IOHandler *fd_write,
-void *opaque);
 #endif
diff --git 

[Qemu-devel] [PATCH -V2 10/13] hw/9pfs: Introduce tracing for 9p pdu handlers

2011-10-11 Thread Aneesh Kumar K.V
From: Harsh Prateek Bora ha...@linux.vnet.ibm.com

Plan is to replace the existing debug infrastructure with Qemu tracing
infrastructure so that user can dynamically enable/disable trace events and
therefore a meaningful trace log can be generated which can be further
filtered using an analysis script.

Note: Because of current simpletrace limitations, the trace events are
logging at max 6 args, however, once the more args are supported, we can
change trace events to log more info as well. Also, This initial patch only
provides a replacement for existing debug infra. More trace events to be
added later for newly added handlers and sub-routines.

Reviewed-by: Stefan Hajnoczi stefa...@linux.vnet.ibm.com
Signed-off-by: Harsh Prateek Bora ha...@linux.vnet.ibm.com
Signed-off-by: Aneesh Kumar K.V aneesh.ku...@linux.vnet.ibm.com
---
 hw/9pfs/virtio-9p.c |   72 +++
 trace-events|   47 +
 2 files changed, 119 insertions(+), 0 deletions(-)

diff --git a/hw/9pfs/virtio-9p.c b/hw/9pfs/virtio-9p.c
index 2ad8f84..288bfc2 100644
--- a/hw/9pfs/virtio-9p.c
+++ b/hw/9pfs/virtio-9p.c
@@ -20,6 +20,7 @@
 #include virtio-9p-debug.h
 #include virtio-9p-xattr.h
 #include virtio-9p-coth.h
+#include trace.h
 
 int debug_9p_pdu;
 int open_fd_hw;
@@ -973,6 +974,7 @@ static void complete_pdu(V9fsState *s, V9fsPDU *pdu, 
ssize_t len)
 if (s-proto_version == V9FS_PROTO_2000L) {
 id = P9_RLERROR;
 }
+trace_complete_pdu(pdu-tag, pdu-id, err); /* Trace ERROR */
 }
 
 /* fill out the header */
@@ -1282,6 +1284,7 @@ static void v9fs_version(void *opaque)
 size_t offset = 7;
 
 pdu_unmarshal(pdu, offset, ds, s-msize, version);
+trace_v9fs_version(pdu-tag, pdu-id, s-msize, version.data);
 
 if (!strcmp(version.data, 9P2000.u)) {
 s-proto_version = V9FS_PROTO_2000U;
@@ -1292,6 +1295,8 @@ static void v9fs_version(void *opaque)
 }
 
 offset += pdu_marshal(pdu, offset, ds, s-msize, version);
+trace_v9fs_version_return(pdu-tag, pdu-id, s-msize, version.data);
+
 complete_pdu(s, pdu, offset);
 
 v9fs_string_free(version);
@@ -1310,6 +1315,7 @@ static void v9fs_attach(void *opaque)
 ssize_t err;
 
 pdu_unmarshal(pdu, offset, ddssd, fid, afid, uname, aname, n_uname);
+trace_v9fs_attach(pdu-tag, pdu-id, fid, afid, uname.data, aname.data);
 
 fidp = alloc_fid(s, fid);
 if (fidp == NULL) {
@@ -1334,6 +1340,8 @@ static void v9fs_attach(void *opaque)
 out:
 put_fid(pdu, fidp);
 out_nofid:
+trace_v9fs_attach_return(pdu-tag, pdu-id,
+ qid.type, qid.version, qid.path);
 complete_pdu(s, pdu, err);
 v9fs_string_free(uname);
 v9fs_string_free(aname);
@@ -1351,6 +1359,7 @@ static void v9fs_stat(void *opaque)
 V9fsState *s = pdu-s;
 
 pdu_unmarshal(pdu, offset, d, fid);
+trace_v9fs_stat(pdu-tag, pdu-id, fid);
 
 fidp = get_fid(pdu, fid);
 if (fidp == NULL) {
@@ -1371,6 +1380,9 @@ static void v9fs_stat(void *opaque)
 out:
 put_fid(pdu, fidp);
 out_nofid:
+trace_v9fs_stat_return(pdu-tag, pdu-id, v9stat.mode,
+   v9stat.atime, v9stat.mtime, v9stat.length);
+
 complete_pdu(s, pdu, err);
 }
 
@@ -1387,6 +1399,7 @@ static void v9fs_getattr(void *opaque)
 V9fsState *s = pdu-s;
 
 pdu_unmarshal(pdu, offset, dq, fid, request_mask);
+trace_v9fs_getattr(pdu-tag, pdu-id, fid, request_mask);
 
 fidp = get_fid(pdu, fid);
 if (fidp == NULL) {
@@ -1416,6 +1429,10 @@ static void v9fs_getattr(void *opaque)
 out:
 put_fid(pdu, fidp);
 out_nofid:
+trace_v9fs_getattr_return(pdu-tag, pdu-id, v9stat_dotl.st_result_mask,
+  v9stat_dotl.st_mode, v9stat_dotl.st_uid,
+  v9stat_dotl.st_gid);
+
 complete_pdu(s, pdu, retval);
 }
 
@@ -1543,6 +1560,8 @@ static void v9fs_walk(void *opaque)
 offset += pdu_unmarshal(pdu, offset, ddw, fid,
 newfid, nwnames);
 
+trace_v9fs_walk(pdu-tag, pdu-id, fid, newfid, nwnames);
+
 if (nwnames  nwnames = P9_MAXWELEM) {
 wnames = g_malloc0(sizeof(wnames[0]) * nwnames);
 qids   = g_malloc0(sizeof(qids[0]) * nwnames);
@@ -1599,6 +1618,7 @@ out:
 v9fs_path_free(dpath);
 v9fs_path_free(path);
 out_nofid:
+trace_v9fs_walk_return(pdu-tag, pdu-id, nwnames, qids);
 complete_pdu(s, pdu, err);
 if (nwnames  nwnames = P9_MAXWELEM) {
 for (name_idx = 0; name_idx  nwnames; name_idx++) {
@@ -1649,6 +1669,8 @@ static void v9fs_open(void *opaque)
 } else {
 pdu_unmarshal(pdu, offset, db, fid, mode);
 }
+trace_v9fs_open(pdu-tag, pdu-id, fid, mode);
+
 fidp = get_fid(pdu, fid);
 if (fidp == NULL) {
 err = -ENOENT;
@@ -1695,6 +1717,8 @@ static void v9fs_open(void *opaque)
 out:
 put_fid(pdu, fidp);
 out_nofid:
+trace_v9fs_open_return(pdu-tag, pdu-id,
+   

[Qemu-devel] [PATCH 07/13] qemu-timer: use atexit for quit_timers

2011-10-11 Thread Paolo Bonzini
Signed-off-by: Paolo Bonzini pbonz...@redhat.com
---
 qemu-timer.c |   15 ---
 qemu-timer.h |1 -
 vl.c |1 -
 3 files changed, 8 insertions(+), 9 deletions(-)

diff --git a/qemu-timer.c b/qemu-timer.c
index d8507e3..7fa81e1 100644
--- a/qemu-timer.c
+++ b/qemu-timer.c
@@ -840,6 +840,13 @@ static void alarm_timer_on_change_state_rearm(void 
*opaque, int running,
 qemu_rearm_alarm_timer((struct qemu_alarm_timer *) opaque);
 }
 
+static void quit_timers(void)
+{
+struct qemu_alarm_timer *t = alarm_timer;
+alarm_timer = NULL;
+t-stop(t);
+}
+
 int init_timer_alarm(void)
 {
 struct qemu_alarm_timer *t = NULL;
@@ -859,6 +866,7 @@ int init_timer_alarm(void)
 }
 
 /* first event is at time 0 */
+atexit(quit_timers);
 t-pending = 1;
 alarm_timer = t;
 qemu_add_vm_change_state_handler(alarm_timer_on_change_state_rearm, t);
@@ -869,13 +877,6 @@ fail:
 return err;
 }
 
-void quit_timers(void)
-{
-struct qemu_alarm_timer *t = alarm_timer;
-alarm_timer = NULL;
-t-stop(t);
-}
-
 int qemu_calculate_timeout(void)
 {
 return 1000;
diff --git a/qemu-timer.h b/qemu-timer.h
index ce576b9..b4ea201 100644
--- a/qemu-timer.h
+++ b/qemu-timer.h
@@ -62,7 +62,6 @@ void configure_alarms(char const *opt);
 int qemu_calculate_timeout(void);
 void init_clocks(void);
 int init_timer_alarm(void);
-void quit_timers(void);
 
 int64_t cpu_get_ticks(void);
 void cpu_enable_ticks(void);
diff --git a/vl.c b/vl.c
index dbf7778..99f8ced 100644
--- a/vl.c
+++ b/vl.c
@@ -3561,7 +3561,6 @@ int main(int argc, char **argv, char **envp)
 os_setup_post();
 
 main_loop();
-quit_timers();
 net_cleanup();
 res_free();
 
-- 
1.7.6





Re: [Qemu-devel] KVM call agenda for October 11th

2011-10-11 Thread Paolo Bonzini

On 10/10/2011 01:35 PM, Juan Quintela wrote:


Hi

Please send in any agenda items you are interested in covering.


Planning the feature freeze:

- what is left to merge?

- test day?

Paolo



[Qemu-devel] [PATCH 32/36] migration: Export a function that tells if the migration has finished correctly

2011-10-11 Thread Juan Quintela
This will allow us to hide the state values.

Signed-off-by: Juan Quintela quint...@redhat.com
---
 migration.c |4 ++--
 migration.h |2 +-
 ui/spice-core.c |4 ++--
 3 files changed, 5 insertions(+), 5 deletions(-)

diff --git a/migration.c b/migration.c
index 6129cb5..c4e2ba6 100644
--- a/migration.c
+++ b/migration.c
@@ -364,9 +364,9 @@ void remove_migration_state_change_notifier(Notifier 
*notify)
 notifier_list_remove(migration_state_notifiers, notify);
 }

-int get_migration_state(void)
+bool migration_has_finished(MigrationState *s)
 {
-return migrate_get_current()-state;
+return s-state == MIG_STATE_COMPLETED;
 }

 void migrate_fd_connect(MigrationState *s)
diff --git a/migration.h b/migration.h
index f059183..7ae127f 100644
--- a/migration.h
+++ b/migration.h
@@ -84,7 +84,7 @@ void migrate_fd_connect(MigrationState *s);

 void add_migration_state_change_notifier(Notifier *notify);
 void remove_migration_state_change_notifier(Notifier *notify);
-int get_migration_state(void);
+bool migration_has_finished(MigrationState *);

 uint64_t ram_bytes_remaining(void);
 uint64_t ram_bytes_transferred(void);
diff --git a/ui/spice-core.c b/ui/spice-core.c
index 3cbc721..b33366e 100644
--- a/ui/spice-core.c
+++ b/ui/spice-core.c
@@ -447,9 +447,9 @@ void do_info_spice(Monitor *mon, QObject **ret_data)

 static void migration_state_notifier(Notifier *notifier, void *data)
 {
-int state = get_migration_state();
+MigrationState *s = data;

-if (state == MIG_STATE_COMPLETED) {
+if (migration_has_finished(s)) {
 #if SPICE_SERVER_VERSION = 0x000701 /* 0.7.1 */
 spice_server_migrate_switch(spice_server);
 #endif
-- 
1.7.6.4




[Qemu-devel] [PATCH 25/36] migration: Our release callback was just free

2011-10-11 Thread Juan Quintela
We called it from a single place, and always with state !=
MIG_STATE_ACTIVE.  Just remove the whole callback.  For users of the
notifier, notice that this is exactly the case where they don't care,
we are just freeing the state from previous failed migration (it can't
be a sucessful one, otherwise we would not be running on that machine
in the first place).

Signed-off-by: Juan Quintela quint...@redhat.com
---
 migration.c |   19 +--
 migration.h |1 -
 2 files changed, 1 insertions(+), 19 deletions(-)

diff --git a/migration.c b/migration.c
index a8e936e..689464d 100644
--- a/migration.c
+++ b/migration.c
@@ -123,10 +123,7 @@ int do_migrate(Monitor *mon, const QDict *qdict, QObject 
**ret_data)
 goto free_migrate_state;
 }

-if (current_migration) {
-current_migration-release(current_migration);
-}
-
+g_free(current_migration);
 current_migration = s;
 notifier_list_notify(migration_state_notifiers, NULL);
 return 0;
@@ -416,19 +413,6 @@ static void migrate_fd_cancel(MigrationState *s)
 migrate_fd_cleanup(s);
 }

-static void migrate_fd_release(MigrationState *s)
-{
-
-DPRINTF(releasing state\n);
-   
-if (s-state == MIG_STATE_ACTIVE) {
-s-state = MIG_STATE_CANCELLED;
-notifier_list_notify(migration_state_notifiers, NULL);
-migrate_fd_cleanup(s);
-}
-g_free(s);
-}
-
 static void migrate_fd_wait_for_unfreeze(void *opaque)
 {
 MigrationState *s = opaque;
@@ -511,7 +495,6 @@ static MigrationState *migrate_new(Monitor *mon, int64_t 
bandwidth_limit,

 s-cancel = migrate_fd_cancel;
 s-get_status = migrate_fd_get_status;
-s-release = migrate_fd_release;
 s-blk = blk;
 s-shared = inc;
 s-mon = NULL;
diff --git a/migration.h b/migration.h
index 3165140..1cdb539 100644
--- a/migration.h
+++ b/migration.h
@@ -40,7 +40,6 @@ struct MigrationState
 int (*write)(MigrationState *s, const void *buff, size_t size);
 void (*cancel)(MigrationState *s);
 int (*get_status)(MigrationState *s);
-void (*release)(MigrationState *s);
 void *opaque;
 int blk;
 int shared;
-- 
1.7.6.4




[Qemu-devel] [PATCH -V2 02/13] hw/9pfs: Add new virtfs option cache=writethrough to skip host page cache

2011-10-11 Thread Aneesh Kumar K.V
From: Aneesh Kumar K.V aneesh.ku...@linux.vnet.ibm.com

cache=writethrough implies the file are opened in the host with O_SYNC open flag

Signed-off-by: Aneesh Kumar K.V aneesh.ku...@linux.vnet.ibm.com
---
 fsdev/file-op-9p.h |4 
 fsdev/qemu-fsdev.c |   10 --
 fsdev/qemu-fsdev.h |1 +
 hw/9pfs/virtio-9p-device.c |1 +
 hw/9pfs/virtio-9p-handle.c |9 +
 hw/9pfs/virtio-9p-local.c  |9 +
 hw/9pfs/virtio-9p.c|   22 --
 qemu-config.c  |6 ++
 qemu-options.hx|   17 -
 vl.c   |6 ++
 10 files changed, 72 insertions(+), 13 deletions(-)

diff --git a/fsdev/file-op-9p.h b/fsdev/file-op-9p.h
index 8de8abf..84ec9e0 100644
--- a/fsdev/file-op-9p.h
+++ b/fsdev/file-op-9p.h
@@ -53,12 +53,16 @@ struct xattr_operations;
 /* FsContext flag values */
 #define PATHNAME_FSCONTEXT 0x1
 
+/* cache flags */
+#define V9FS_WRITETHROUGH_CACHE 0x1
+
 typedef struct FsContext
 {
 int flags;
 char *fs_root;
 SecModel fs_sm;
 uid_t uid;
+int cache_flags;
 struct xattr_operations **xops;
 /* fs driver specific data */
 void *private;
diff --git a/fsdev/qemu-fsdev.c b/fsdev/qemu-fsdev.c
index 768819f..36db127 100644
--- a/fsdev/qemu-fsdev.c
+++ b/fsdev/qemu-fsdev.c
@@ -34,6 +34,8 @@ int qemu_fsdev_add(QemuOpts *opts)
 const char *fstype = qemu_opt_get(opts, fstype);
 const char *path = qemu_opt_get(opts, path);
 const char *sec_model = qemu_opt_get(opts, security_model);
+const char *cache = qemu_opt_get(opts, cache);
+
 
 if (!fsdev_id) {
 fprintf(stderr, fsdev: No id specified\n);
@@ -72,10 +74,14 @@ int qemu_fsdev_add(QemuOpts *opts)
 fsle-fse.path = g_strdup(path);
 fsle-fse.security_model = g_strdup(sec_model);
 fsle-fse.ops = FsTypes[i].ops;
-
+fsle-fse.cache_flags = 0;
+if (cache) {
+if (!strcmp(cache, writethrough)) {
+fsle-fse.cache_flags = V9FS_WRITETHROUGH_CACHE;
+}
+}
 QTAILQ_INSERT_TAIL(fstype_entries, fsle, next);
 return 0;
-
 }
 
 FsTypeEntry *get_fsdev_fsentry(char *id)
diff --git a/fsdev/qemu-fsdev.h b/fsdev/qemu-fsdev.h
index e04931a..9c440f2 100644
--- a/fsdev/qemu-fsdev.h
+++ b/fsdev/qemu-fsdev.h
@@ -41,6 +41,7 @@ typedef struct FsTypeEntry {
 char *fsdev_id;
 char *path;
 char *security_model;
+int cache_flags;
 FileOperations *ops;
 } FsTypeEntry;
 
diff --git a/hw/9pfs/virtio-9p-device.c b/hw/9pfs/virtio-9p-device.c
index e5b68da..b23e8a4 100644
--- a/hw/9pfs/virtio-9p-device.c
+++ b/hw/9pfs/virtio-9p-device.c
@@ -115,6 +115,7 @@ VirtIODevice *virtio_9p_init(DeviceState *dev, V9fsConf 
*conf)
 exit(1);
 }
 
+s-ctx.cache_flags = fse-cache_flags;
 s-ctx.fs_root = g_strdup(fse-path);
 len = strlen(conf-tag);
 if (len  MAX_TAG_LEN) {
diff --git a/hw/9pfs/virtio-9p-handle.c b/hw/9pfs/virtio-9p-handle.c
index 5c8b5ed..441a37f 100644
--- a/hw/9pfs/virtio-9p-handle.c
+++ b/hw/9pfs/virtio-9p-handle.c
@@ -202,6 +202,15 @@ static ssize_t handle_pwritev(FsContext *ctx, int fd, 
const struct iovec *iov,
 return writev(fd, iov, iovcnt);
 }
 #endif
+if (ctx-cache_flags  V9FS_WRITETHROUGH_CACHE) {
+/*
+ * Initiate a writeback. This is not a data integrity sync.
+ * We want to ensure that we don't leave dirty pages in the cache
+ * after write when cache=writethrough is sepcified.
+ */
+sync_file_range(fd, offset, 0,
+SYNC_FILE_RANGE_WAIT_BEFORE | SYNC_FILE_RANGE_WRITE);
+}
 }
 
 static int handle_chmod(FsContext *fs_ctx, V9fsPath *fs_path, FsCred *credp)
diff --git a/hw/9pfs/virtio-9p-local.c b/hw/9pfs/virtio-9p-local.c
index 9559ff6..5745d14 100644
--- a/hw/9pfs/virtio-9p-local.c
+++ b/hw/9pfs/virtio-9p-local.c
@@ -213,6 +213,15 @@ static ssize_t local_pwritev(FsContext *ctx, int fd, const 
struct iovec *iov,
 return writev(fd, iov, iovcnt);
 }
 #endif
+if (ctx-cache_flags  V9FS_WRITETHROUGH_CACHE) {
+/*
+ * Initiate a writeback. This is not a data integrity sync.
+ * We want to ensure that we don't leave dirty pages in the cache
+ * after write when cache=writethrough is sepcified.
+ */
+sync_file_range(fd, offset, 0,
+SYNC_FILE_RANGE_WAIT_BEFORE | SYNC_FILE_RANGE_WRITE);
+}
 }
 
 static int local_chmod(FsContext *fs_ctx, V9fsPath *fs_path, FsCred *credp)
diff --git a/hw/9pfs/virtio-9p.c b/hw/9pfs/virtio-9p.c
index c01c31a..3958788 100644
--- a/hw/9pfs/virtio-9p.c
+++ b/hw/9pfs/virtio-9p.c
@@ -80,6 +80,20 @@ void cred_init(FsCred *credp)
 credp-fc_rdev = -1;
 }
 
+static int get_dotl_openflags(V9fsState *s, int oflags)
+{
+int flags;
+/*
+ * Filter the client open flags
+ */
+flags = oflags  ~(O_NOCTTY | O_ASYNC | O_CREAT);
+/*
+ * Ignore direct disk access hint until the server 

[Qemu-devel] [PATCH 03/13] qemu-timer: move common code to qemu_rearm_alarm_timer

2011-10-11 Thread Paolo Bonzini
Signed-off-by: Paolo Bonzini pbonz...@redhat.com
---
 qemu-timer.c |  129 --
 1 files changed, 53 insertions(+), 76 deletions(-)

diff --git a/qemu-timer.c b/qemu-timer.c
index acf7a15..e2551f3 100644
--- a/qemu-timer.c
+++ b/qemu-timer.c
@@ -153,7 +153,7 @@ struct qemu_alarm_timer {
 char const *name;
 int (*start)(struct qemu_alarm_timer *t);
 void (*stop)(struct qemu_alarm_timer *t);
-void (*rearm)(struct qemu_alarm_timer *t);
+void (*rearm)(struct qemu_alarm_timer *t, int64_t nearest_delta_ns);
 #if defined(__linux__)
 int fd;
 timer_t timer;
@@ -181,12 +181,46 @@ static inline int alarm_has_dynticks(struct 
qemu_alarm_timer *t)
 return !!t-rearm;
 }
 
+static int64_t qemu_next_alarm_deadline(void)
+{
+int64_t delta;
+int64_t rtdelta;
+
+if (!use_icount  vm_clock-active_timers) {
+delta = vm_clock-active_timers-expire_time -
+ qemu_get_clock_ns(vm_clock);
+} else {
+delta = INT32_MAX;
+}
+if (host_clock-active_timers) {
+int64_t hdelta = host_clock-active_timers-expire_time -
+ qemu_get_clock_ns(host_clock);
+if (hdelta  delta) {
+delta = hdelta;
+}
+}
+if (rt_clock-active_timers) {
+rtdelta = (rt_clock-active_timers-expire_time -
+ qemu_get_clock_ns(rt_clock));
+if (rtdelta  delta) {
+delta = rtdelta;
+}
+}
+
+return delta;
+}
+
 static void qemu_rearm_alarm_timer(struct qemu_alarm_timer *t)
 {
-if (!alarm_has_dynticks(t))
+int64_t nearest_delta_ns;
+assert(alarm_has_dynticks(t));
+if (!rt_clock-active_timers 
+!vm_clock-active_timers 
+!host_clock-active_timers) {
 return;
-
-t-rearm(t);
+}
+nearest_delta_ns = qemu_next_alarm_deadline();
+t-rearm(t, nearest_delta_ns);
 }
 
 /* TODO: MIN_TIMER_REARM_NS should be optimized */
@@ -196,23 +230,23 @@ static void qemu_rearm_alarm_timer(struct 
qemu_alarm_timer *t)
 
 static int mm_start_timer(struct qemu_alarm_timer *t);
 static void mm_stop_timer(struct qemu_alarm_timer *t);
-static void mm_rearm_timer(struct qemu_alarm_timer *t);
+static void mm_rearm_timer(struct qemu_alarm_timer *t, int64_t delta);
 
 static int win32_start_timer(struct qemu_alarm_timer *t);
 static void win32_stop_timer(struct qemu_alarm_timer *t);
-static void win32_rearm_timer(struct qemu_alarm_timer *t);
+static void win32_rearm_timer(struct qemu_alarm_timer *t, int64_t delta);
 
 #else
 
 static int unix_start_timer(struct qemu_alarm_timer *t);
 static void unix_stop_timer(struct qemu_alarm_timer *t);
-static void unix_rearm_timer(struct qemu_alarm_timer *t);
+static void unix_rearm_timer(struct qemu_alarm_timer *t, int64_t delta);
 
 #ifdef __linux__
 
 static int dynticks_start_timer(struct qemu_alarm_timer *t);
 static void dynticks_stop_timer(struct qemu_alarm_timer *t);
-static void dynticks_rearm_timer(struct qemu_alarm_timer *t);
+static void dynticks_rearm_timer(struct qemu_alarm_timer *t, int64_t delta);
 
 #endif /* __linux__ */
 
@@ -715,8 +749,6 @@ void qemu_run_all_timers(void)
 qemu_run_timers(host_clock);
 }
 
-static int64_t qemu_next_alarm_deadline(void);
-
 #ifdef _WIN32
 static void CALLBACK host_alarm_handler(PVOID lpParam, BOOLEAN unused)
 #else
@@ -781,33 +813,6 @@ int64_t qemu_next_icount_deadline(void)
 return delta;
 }
 
-static int64_t qemu_next_alarm_deadline(void)
-{
-int64_t delta;
-int64_t rtdelta;
-
-if (!use_icount  vm_clock-active_timers) {
-delta = vm_clock-active_timers-expire_time -
- qemu_get_clock_ns(vm_clock);
-} else {
-delta = INT32_MAX;
-}
-if (host_clock-active_timers) {
-int64_t hdelta = host_clock-active_timers-expire_time -
- qemu_get_clock_ns(host_clock);
-if (hdelta  delta)
-delta = hdelta;
-}
-if (rt_clock-active_timers) {
-rtdelta = (rt_clock-active_timers-expire_time -
- qemu_get_clock_ns(rt_clock));
-if (rtdelta  delta)
-delta = rtdelta;
-}
-
-return delta;
-}
-
 #if defined(__linux__)
 
 #include compatfd.h
@@ -860,20 +865,13 @@ static void dynticks_stop_timer(struct qemu_alarm_timer 
*t)
 timer_delete(host_timer);
 }
 
-static void dynticks_rearm_timer(struct qemu_alarm_timer *t)
+static void dynticks_rearm_timer(struct qemu_alarm_timer *t,
+ int64_t nearest_delta_ns)
 {
 timer_t host_timer = t-timer;
 struct itimerspec timeout;
-int64_t nearest_delta_ns = INT64_MAX;
 int64_t current_ns;
 
-assert(alarm_has_dynticks(t));
-if (!rt_clock-active_timers 
-!vm_clock-active_timers 
-!host_clock-active_timers)
-return;
-
-nearest_delta_ns = qemu_next_alarm_deadline();
 if (nearest_delta_ns  MIN_TIMER_REARM_NS)
 nearest_delta_ns = MIN_TIMER_REARM_NS;

[Qemu-devel] [PATCH 21/36] migration: move migrate_new to do_migrate

2011-10-11 Thread Juan Quintela
Once there, remove all parameters that don't need to be passed to
*start_outgoing_migration() functions

Signed-off-by: Juan Quintela quint...@redhat.com
---
 migration-exec.c |   19 +--
 migration-fd.c   |   22 ++
 migration-tcp.c  |   22 +++---
 migration-unix.c |   20 +---
 migration.c  |   32 +++-
 migration.h  |   31 ---
 6 files changed, 46 insertions(+), 100 deletions(-)

diff --git a/migration-exec.c b/migration-exec.c
index d0119c6..b7b1055 100644
--- a/migration-exec.c
+++ b/migration-exec.c
@@ -61,22 +61,14 @@ static int exec_close(MigrationState *s)
 return ret;
 }

-MigrationState *exec_start_outgoing_migration(Monitor *mon,
-  const char *command,
- int64_t bandwidth_limit,
- int detach,
- int blk,
- int inc)
+int exec_start_outgoing_migration(MigrationState *s, const char *command)
 {
-MigrationState *s;
 FILE *f;

-s = migrate_new(mon, bandwidth_limit, detach, blk, inc);
-
 f = popen(command, w);
 if (f == NULL) {
 DPRINTF(Unable to popen exec target\n);
-goto err_after_alloc;
+goto err_after_popen;
 }

 s-fd = fileno(f);
@@ -94,13 +86,12 @@ MigrationState *exec_start_outgoing_migration(Monitor *mon,
 s-write = file_write;

 migrate_fd_connect(s);
-return s;
+return 0;

 err_after_open:
 pclose(f);
-err_after_alloc:
-g_free(s);
-return NULL;
+err_after_popen:
+return -1;
 }

 static void exec_accept_incoming_migration(void *opaque)
diff --git a/migration-fd.c b/migration-fd.c
index 9d3ca42..d0aec89 100644
--- a/migration-fd.c
+++ b/migration-fd.c
@@ -50,21 +50,12 @@ static int fd_close(MigrationState *s)
 return 0;
 }

-MigrationState *fd_start_outgoing_migration(Monitor *mon,
-   const char *fdname,
-   int64_t bandwidth_limit,
-   int detach,
-   int blk,
-   int inc)
+int fd_start_outgoing_migration(MigrationState *s, const char *fdname)
 {
-MigrationState *s;
-
-s = migrate_new(mon, bandwidth_limit, detach, blk, inc);
-
-s-fd = monitor_get_fd(mon, fdname);
+s-fd = monitor_get_fd(s-mon, fdname);
 if (s-fd == -1) {
 DPRINTF(fd_migration: invalid file descriptor identifier\n);
-goto err_after_alloc;
+goto err_after_get_fd;
 }

 if (fcntl(s-fd, F_SETFL, O_NONBLOCK) == -1) {
@@ -77,13 +68,12 @@ MigrationState *fd_start_outgoing_migration(Monitor *mon,
 s-close = fd_close;

 migrate_fd_connect(s);
-return s;
+return 0;

 err_after_open:
 close(s-fd);
-err_after_alloc:
-g_free(s);
-return NULL;
+err_after_get_fd:
+return -1;
 }

 static void fd_accept_incoming_migration(void *opaque)
diff --git a/migration-tcp.c b/migration-tcp.c
index 999d4c9..f6b2288 100644
--- a/migration-tcp.c
+++ b/migration-tcp.c
@@ -75,30 +75,22 @@ static void tcp_wait_for_connect(void *opaque)
 }
 }

-MigrationState *tcp_start_outgoing_migration(Monitor *mon,
- const char *host_port,
- int64_t bandwidth_limit,
- int detach,
-int blk,
-int inc)
+int tcp_start_outgoing_migration(MigrationState *s, const char *host_port)
 {
 struct sockaddr_in addr;
-MigrationState *s;
 int ret;

-if (parse_host_port(addr, host_port)  0)
-return NULL;
-
-s = migrate_new(mon, bandwidth_limit, detach, blk, inc);
-
+ret = parse_host_port(addr, host_port);
+if (ret  0) {
+return ret;
+}
 s-get_error = socket_errno;
 s-write = socket_write;
 s-close = tcp_close;

 s-fd = qemu_socket(PF_INET, SOCK_STREAM, 0);
 if (s-fd == -1) {
-g_free(s);
-return NULL;
+return -1;
 }

 socket_set_nonblock(s-fd);
@@ -118,7 +110,7 @@ MigrationState *tcp_start_outgoing_migration(Monitor *mon,
 } else if (ret = 0)
 migrate_fd_connect(s);

-return s;
+return 0;
 }

 static void tcp_accept_incoming_migration(void *opaque)
diff --git a/migration-unix.c b/migration-unix.c
index bee71d9..bd8d40f 100644
--- a/migration-unix.c
+++ b/migration-unix.c
@@ -74,22 +74,13 @@ static void unix_wait_for_connect(void *opaque)
 }
 }

-MigrationState *unix_start_outgoing_migration(Monitor *mon,
-  const char *path,
- int64_t 

[Qemu-devel] [PATCH 11/13] create main-loop.c

2011-10-11 Thread Paolo Bonzini
Signed-off-by: Paolo Bonzini pbonz...@redhat.com
---
 Makefile.objs|2 +-
 cpus.c   |  188 +
 cpus.h   |1 +
 main-loop.c  |  494 ++
 os-win32.c   |  123 --
 qemu-os-posix.h  |4 -
 qemu-os-win32.h  |   15 +--
 slirp/libslirp.h |   11 --
 vl.c |  123 +--
 9 files changed, 499 insertions(+), 462 deletions(-)
 create mode 100644 main-loop.c

diff --git a/Makefile.objs b/Makefile.objs
index 09527cb..7ee7dc5 100644
--- a/Makefile.objs
+++ b/Makefile.objs
@@ -81,7 +81,7 @@ common-obj-y += $(oslib-obj-y)
 common-obj-$(CONFIG_WIN32) += os-win32.o
 common-obj-$(CONFIG_POSIX) += os-posix.o
 
-common-obj-y += tcg-runtime.o host-utils.o
+common-obj-y += tcg-runtime.o host-utils.o main-loop.o
 common-obj-y += irq.o ioport.o input.o
 common-obj-$(CONFIG_PTIMER) += ptimer.o
 common-obj-$(CONFIG_MAX7310) += max7310.o
diff --git a/cpus.c b/cpus.c
index aabb7c1..ead18af 100644
--- a/cpus.c
+++ b/cpus.c
@@ -542,143 +542,10 @@ static void qemu_kvm_eat_signals(CPUState *env)
 #endif /* !CONFIG_LINUX */
 
 #ifndef _WIN32
-static int io_thread_fd = -1;
-
-static void qemu_event_increment(void)
-{
-/* Write 8 bytes to be compatible with eventfd.  */
-static const uint64_t val = 1;
-ssize_t ret;
-
-if (io_thread_fd == -1) {
-return;
-}
-do {
-ret = write(io_thread_fd, val, sizeof(val));
-} while (ret  0  errno == EINTR);
-
-/* EAGAIN is fine, a read must be pending.  */
-if (ret  0  errno != EAGAIN) {
-fprintf(stderr, qemu_event_increment: write() failed: %s\n,
-strerror(errno));
-exit (1);
-}
-}
-
-static void qemu_event_read(void *opaque)
-{
-int fd = (intptr_t)opaque;
-ssize_t len;
-char buffer[512];
-
-/* Drain the notify pipe.  For eventfd, only 8 bytes will be read.  */
-do {
-len = read(fd, buffer, sizeof(buffer));
-} while ((len == -1  errno == EINTR) || len == sizeof(buffer));
-}
-
-static int qemu_event_init(void)
-{
-int err;
-int fds[2];
-
-err = qemu_eventfd(fds);
-if (err == -1) {
-return -errno;
-}
-err = fcntl_setfl(fds[0], O_NONBLOCK);
-if (err  0) {
-goto fail;
-}
-err = fcntl_setfl(fds[1], O_NONBLOCK);
-if (err  0) {
-goto fail;
-}
-qemu_set_fd_handler2(fds[0], NULL, qemu_event_read, NULL,
- (void *)(intptr_t)fds[0]);
-
-io_thread_fd = fds[1];
-return 0;
-
-fail:
-close(fds[0]);
-close(fds[1]);
-return err;
-}
-
 static void dummy_signal(int sig)
 {
 }
 
-/* If we have signalfd, we mask out the signals we want to handle and then
- * use signalfd to listen for them.  We rely on whatever the current signal
- * handler is to dispatch the signals when we receive them.
- */
-static void sigfd_handler(void *opaque)
-{
-int fd = (intptr_t)opaque;
-struct qemu_signalfd_siginfo info;
-struct sigaction action;
-ssize_t len;
-
-while (1) {
-do {
-len = read(fd, info, sizeof(info));
-} while (len == -1  errno == EINTR);
-
-if (len == -1  errno == EAGAIN) {
-break;
-}
-
-if (len != sizeof(info)) {
-printf(read from sigfd returned %zd: %m\n, len);
-return;
-}
-
-sigaction(info.ssi_signo, NULL, action);
-if ((action.sa_flags  SA_SIGINFO)  action.sa_sigaction) {
-action.sa_sigaction(info.ssi_signo,
-(siginfo_t *)info, NULL);
-} else if (action.sa_handler) {
-action.sa_handler(info.ssi_signo);
-}
-}
-}
-
-static int qemu_signal_init(void)
-{
-int sigfd;
-sigset_t set;
-
-/*
- * SIG_IPI must be blocked in the main thread and must not be caught
- * by sigwait() in the signal thread. Otherwise, the cpu thread will
- * not catch it reliably.
- */
-sigemptyset(set);
-sigaddset(set, SIG_IPI);
-pthread_sigmask(SIG_BLOCK, set, NULL);
-
-sigemptyset(set);
-sigaddset(set, SIGIO);
-sigaddset(set, SIGALRM);
-sigaddset(set, SIGBUS);
-pthread_sigmask(SIG_BLOCK, set, NULL);
-
-sigfd = qemu_signalfd(set);
-if (sigfd == -1) {
-fprintf(stderr, failed to create signalfd\n);
-return -errno;
-}
-
-fcntl_setfl(sigfd, O_NONBLOCK);
-
-qemu_set_fd_handler2(sigfd, NULL, sigfd_handler, NULL,
- (void *)(intptr_t)sigfd);
-
-return 0;
-}
-
 static void qemu_kvm_init_cpu_signals(CPUState *env)
 {
 int r;
@@ -722,38 +589,6 @@ static void qemu_tcg_init_cpu_signals(void)
 }
 
 #else /* _WIN32 */
-
-HANDLE qemu_event_handle;
-
-static void dummy_event_handler(void *opaque)
-{
-}
-
-static int qemu_event_init(void)
-{
-qemu_event_handle = CreateEvent(NULL, FALSE, FALSE, NULL);
-if (!qemu_event_handle) {
-fprintf(stderr, Failed CreateEvent: 

Re: [Qemu-devel] KVM call agenda for October 11th

2011-10-11 Thread Avi Kivity

On 10/10/2011 01:35 PM, Juan Quintela wrote:

Hi

Please send in any agenda items you are interested in covering.



Subsections, version numbers, migration to older releases.

--
error compiling committee.c: too many arguments to function




[Qemu-devel] [PATCH 12/13] Revert to a hand-made select loop

2011-10-11 Thread Paolo Bonzini
This reverts commit c82dc29a9112f34e0a51cad9a412cf6d9d05dfb2
and 4d88a2ac8643265108ef1fb47ceee5d7b28e19f2.

Signed-off-by: Paolo Bonzini pbonz...@redhat.com
---
 iohandler.c |   54 +-
 1 files changed, 1 insertions(+), 53 deletions(-)

diff --git a/iohandler.c b/iohandler.c
index 4cc1c5a..4deae1e 100644
--- a/iohandler.c
+++ b/iohandler.c
@@ -80,64 +80,12 @@ int qemu_set_fd_handler2(int fd,
 return 0;
 }
 
-typedef struct IOTrampoline
-{
-GIOChannel *chan;
-IOHandler *fd_read;
-IOHandler *fd_write;
-void *opaque;
-guint tag;
-} IOTrampoline;
-
-static gboolean fd_trampoline(GIOChannel *chan, GIOCondition cond, gpointer 
opaque)
-{
-IOTrampoline *tramp = opaque;
-
-if ((cond  G_IO_IN)  tramp-fd_read) {
-tramp-fd_read(tramp-opaque);
-}
-
-if ((cond  G_IO_OUT)  tramp-fd_write) {
-tramp-fd_write(tramp-opaque);
-}
-
-return TRUE;
-}
-
 int qemu_set_fd_handler(int fd,
 IOHandler *fd_read,
 IOHandler *fd_write,
 void *opaque)
 {
-static IOTrampoline fd_trampolines[FD_SETSIZE];
-IOTrampoline *tramp = fd_trampolines[fd];
-
-if (tramp-tag != 0) {
-g_io_channel_unref(tramp-chan);
-g_source_remove(tramp-tag);
-tramp-tag = 0;
-}
-
-if (fd_read || fd_write || opaque) {
-GIOCondition cond = 0;
-
-tramp-fd_read = fd_read;
-tramp-fd_write = fd_write;
-tramp-opaque = opaque;
-
-if (fd_read) {
-cond |= G_IO_IN | G_IO_ERR;
-}
-
-if (fd_write) {
-cond |= G_IO_OUT | G_IO_ERR;
-}
-
-tramp-chan = g_io_channel_unix_new(fd);
-tramp-tag = g_io_add_watch(tramp-chan, cond, fd_trampoline, tramp);
-}
-
-return 0;
+return qemu_set_fd_handler2(fd, NULL, fd_read, fd_write, opaque);
 }
 
 void qemu_iohandler_fill(int *pnfds, fd_set *readfds, fd_set *writefds, fd_set 
*xfds)
-- 
1.7.6





[Qemu-devel] [PATCH 04/36] migration: return real error code

2011-10-11 Thread Juan Quintela
make functions propagate errno, instead of just using -EIO.

Signed-off-by: Juan Quintela quint...@redhat.com
---
 migration.c |6 +-
 savevm.c|   33 +++--
 2 files changed, 20 insertions(+), 19 deletions(-)

diff --git a/migration.c b/migration.c
index 71b8aad..2d3a55b 100644
--- a/migration.c
+++ b/migration.c
@@ -363,6 +363,7 @@ void migrate_fd_connect(FdMigrationState *s)
 void migrate_fd_put_ready(void *opaque)
 {
 FdMigrationState *s = opaque;
+int ret;

 if (s-state != MIG_STATE_ACTIVE) {
 DPRINTF(put_ready returning because of non-active state\n);
@@ -370,7 +371,10 @@ void migrate_fd_put_ready(void *opaque)
 }

 DPRINTF(iterate\n);
-if (qemu_savevm_state_iterate(s-mon, s-file) == 1) {
+ret = qemu_savevm_state_iterate(s-mon, s-file);
+if (ret  0) {
+migrate_fd_error(s);
+} else if (ret == 1) {
 int old_vm_running = runstate_is_running();

 DPRINTF(done iterating\n);
diff --git a/savevm.c b/savevm.c
index bf4d0e7..15c9c52 100644
--- a/savevm.c
+++ b/savevm.c
@@ -1466,6 +1466,7 @@ int qemu_savevm_state_begin(Monitor *mon, QEMUFile *f, 
int blk_enable,
 int shared)
 {
 SaveStateEntry *se;
+int ret;

 QTAILQ_FOREACH(se, savevm_handlers, entry) {
 if(se-set_params == NULL) {
@@ -1497,13 +1498,13 @@ int qemu_savevm_state_begin(Monitor *mon, QEMUFile *f, 
int blk_enable,

 se-save_live_state(mon, f, QEMU_VM_SECTION_START, se-opaque);
 }
-
-if (qemu_file_has_error(f)) {
+ret = qemu_file_has_error(f);
+if (ret != 0) {
 qemu_savevm_state_cancel(mon, f);
-return -EIO;
 }

-return 0;
+return ret;
+
 }

 int qemu_savevm_state_iterate(Monitor *mon, QEMUFile *f)
@@ -1528,16 +1529,14 @@ int qemu_savevm_state_iterate(Monitor *mon, QEMUFile *f)
 break;
 }
 }
-
-if (ret)
-return 1;
-
-if (qemu_file_has_error(f)) {
+if (ret != 0) {
+return ret;
+}
+ret = qemu_file_has_error(f);
+if (ret != 0) {
 qemu_savevm_state_cancel(mon, f);
-return -EIO;
 }
-
-return 0;
+return ret;
 }

 int qemu_savevm_state_complete(Monitor *mon, QEMUFile *f)
@@ -1580,10 +1579,7 @@ int qemu_savevm_state_complete(Monitor *mon, QEMUFile *f)

 qemu_put_byte(f, QEMU_VM_EOF);

-if (qemu_file_has_error(f))
-return -EIO;
-
-return 0;
+return qemu_file_has_error(f);
 }

 void qemu_savevm_state_cancel(Monitor *mon, QEMUFile *f)
@@ -1623,8 +1619,9 @@ static int qemu_savevm_state(Monitor *mon, QEMUFile *f)
 ret = qemu_savevm_state_complete(mon, f);

 out:
-if (qemu_file_has_error(f))
-ret = -EIO;
+if (ret == 0) {
+ret = qemu_file_has_error(f);
+}

 if (!ret  saved_vm_running)
 vm_start();
-- 
1.7.6.4




  1   2   >