Re: [Qemu-devel] [PATCH 09/19] sockets: Chardev open error reporting, sockets part

2012-02-23 Thread Markus Armbruster
Anthony Liguori anth...@codemonkey.ws writes:

 On 02/15/2012 07:33 AM, Markus Armbruster wrote:
 Anthony Liguorianth...@codemonkey.ws  writes:

 On 02/14/2012 11:24 AM, Markus Armbruster wrote:
 Markus Armbrusterarm...@redhat.com   writes:

 Anthony Liguorialigu...@us.ibm.com   writes:
 [Anthony asking for error_set() instead of error_report()...]
 Basically, same thing here and the remaining functions.  Let's not
 introduce additional uses of error_report().

 That said, I imagine you don't want to introduce a bunch of error
 types for these different things and that's probably not productive
 anyway.
 [...]
 So let's compromise and introduce a generic QERR_INTERNAL_ERROR that
 takes a single human readable string as an argument.  We can have a
 wrapper for it that also records location information in the error
 object.

 This series goes from stderr to error_report().  That's a relatively
 simple step, which makes it relatively easy to review.  I'm afraid
 moving all the way to error.h in one step wouldn't be as easy.  Kevin
 suggests to do it in a follow-up series, and I agree.

 The trouble I have is not about doing things incrementally, but rather
 touching a lot of code incrementally.  Most of the code you touch
 could be done incrementally with error_set().

 For instance, you could touch inet_listen_opts() and just add an Error
 ** as the last argument.  You can change all callers to simply do:

 Error *err = NULL;

 ...
 inet_listen_opts(...,err);
 if (err) {
 error_report_err(err);
 return -1;
 }

 And it's not really all that different from the series as it stands
 today.  I agree that aggressively refactoring error propagation is
 probably not necessary as a first step, but if we're going to touch a
 lot of code, we should do it in a way that we don't have to
 immediately touch it again next.

 Well, the series adds 47 calls of error_report() to five files out of
 1850.

 Can you point to an existing conversion from error_report() to error.h,
 to give us an idea how it's supposed to be done?

 Ping?

 Sorry, I mentally responded bug neglected to actually respond.

 All of the QMP work that Luiz is doing effectively does this so there
 are ample examples right now.  The change command is probably a good
 place to start.

 Thanks.

 Unfortunately, I'm out of time on this one, so if you're unwilling to
 accept this admittedly incremental improvement without substantial
 rework, I'll have to let it rot in peace.

 We might want a QMP commands to add character devices some day.  Perhaps
 the person doing it will still be able to find these patches, and get
 some use out of them.

 Patches 01-08,14 don't add error_report() calls.  What about committing
 them?  The commit messages would need to be reworded not to promise
 goodies from the other patches, though.

 I'm sorry to hear that you can't continue working on this.

Can't be helped.

 I'll focus on applying the patches you mentioned.

Suggest to reword the commit messages not to promise the parts you don't
apply.

 While I admit that it seems counter intuitive to not want to improve
 error messages (and I fully admit, that this is an improvement), I'm
 more concerned that this digs us deeper into the
 qerror_report/error_report hole that we're trying to dig our way out
 of.

 If you want to add chardevs dynamically, then I assume your next patch

Not a priority at this time, I'm afraid.  If it becomes one, I might be
able to work on it.

 would be switching error_report to qerror_report such that the errors
 appeared in the monitor.  But this is wrong.  New QMP functions are
 not allowed to use qerror_report anymore.  So all of this code would
 need to get changed again anyway.

No, the next step for errors would be error_report() - error_set(),
precisely because qerror_report() can't be used anymore.

Yes, that means the five files that report chardev open errors will need
to be touched again.  But that'll be a bog-standard error_report() -
error_set() conversion.  Easier to code, test and review than combined
track down all the error paths that fail to report errors, or report
non-sensical errors + convert from fprintf() to error_set() in one
go.

In my opinion, the have to touch five files again developer burden
compares quite favorably with have to check all the error paths again
developer burden.  And in any case it's dwarved by the have to use a
debugger to find out what's wrong user burden.

[...]



[Qemu-devel] qemu -device ? segfaults

2012-02-23 Thread Gerd Hoffmann
  Hi,

$subject says all, which pretty much breaks libvirt-managed qemu ...

cheers,
  Gerd



Re: [Qemu-devel] qemu -device ? segfaults

2012-02-23 Thread Gerd Hoffmann
On 02/23/12 09:20, Gerd Hoffmann wrote:
   Hi,
 
 $subject says all, which pretty much breaks libvirt-managed qemu ...

Even just qemu segfaults, right here:

(gdb) bt
#0  qemu_opt_get (opts=0x0, name=0x77f7478f kernel)
at /home/kraxel/projects/qemu/qemu-option.c:545
#1  0x77deb1b0 in main (argc=value optimized out, argv=value
optimized out,
envp=value optimized out) at /home/kraxel/projects/qemu/vl.c:3250

cheers,
  Gerd



Re: [Qemu-devel] qemu -device ? segfaults

2012-02-23 Thread Peter Maydell
On 23 February 2012 08:20, Gerd Hoffmann kra...@redhat.com wrote:
 $subject says all, which pretty much breaks libvirt-managed qemu ...

Does http://patchwork.ozlabs.org/patch/142548/ fix this for you?

-- PMM



[Qemu-devel] effect of cluster_size on qcow2 performance during expansion

2012-02-23 Thread PANKAJ RAWAT
Hi all

I have been working on the qcow2 image format ,

In theory regarding  cluster size it is written that as the size of cluster
increase performance should increase.



But something surprising happen The performance is degrading as the size of
cluster increased from *64K* to *1M* or *2M*  ( during expansion of qcow2
image)



By expansion i mean that initially qcow2 image is small in size and size
increases when we perform any write operation on it.


Here are the reading taken through fio tool during write operation


*Cluster size : 32K587Mb/sec (aggrb MB/sec)
*

*
*
*Cluster size : 64K697Mb/sec** (aggrb MB/sec)*
*
Cluster size : 1M 440Mb/sec*  *(aggrb MB/sec)*

*
*
* Cluster size : 2M 289Mb/sec**  (aggrb MB/sec)*

as in above it can bee seen that the 64k is performing better

can any one tell why ?




-- 
*Pankaj Rawat*


Re: [Qemu-devel] qemu -device ? segfaults

2012-02-23 Thread andrzej zaborowski
On 23 February 2012 09:20, Gerd Hoffmann kra...@redhat.com wrote:
 $subject says all, which pretty much breaks libvirt-managed qemu ...

Also device_add nonexistent-device in the monitor gives a rather
unhelpful message:

Parameter 'driver' expects device type

Cheers



Re: [Qemu-devel] qemu -device ? segfaults

2012-02-23 Thread Markus Armbruster
andrzej zaborowski balr...@gmail.com writes:

 On 23 February 2012 09:20, Gerd Hoffmann kra...@redhat.com wrote:
 $subject says all, which pretty much breaks libvirt-managed qemu ...

 Also device_add nonexistent-device in the monitor gives a rather
 unhelpful message:

 Parameter 'driver' expects device type

-device foo is really shorthand for -device driver=foo.  And deep
down in the bowels of qdev, where the error get reported, the value of
parameter driver gets treated like any other parameter's value: if
it's not within ACCEPTABLE-SET, complain Parameter 'NAME' expected
ACCEPTABLE-SET.

Overuse of syntactic sugar considered harmful.



Re: [Qemu-devel] qemu -device ? segfaults

2012-02-23 Thread Gerd Hoffmann
On 02/23/12 09:23, Peter Maydell wrote:
 On 23 February 2012 08:20, Gerd Hoffmann kra...@redhat.com wrote:
 $subject says all, which pretty much breaks libvirt-managed qemu ...
 
 Does http://patchwork.ozlabs.org/patch/142548/ fix this for you?

Yes.

thanks,
  Gerd




Re: [Qemu-devel] qemu -device ? segfaults

2012-02-23 Thread andrzej zaborowski
On 23 February 2012 09:48, Markus Armbruster arm...@redhat.com wrote:
 andrzej zaborowski balr...@gmail.com writes:

 On 23 February 2012 09:20, Gerd Hoffmann kra...@redhat.com wrote:
 $subject says all, which pretty much breaks libvirt-managed qemu ...

 Also device_add nonexistent-device in the monitor gives a rather
 unhelpful message:

 Parameter 'driver' expects device type

 -device foo is really shorthand for -device driver=foo.  And deep
 down in the bowels of qdev, where the error get reported, the value of
 parameter driver gets treated like any other parameter's value: if
 it's not within ACCEPTABLE-SET, complain Parameter 'NAME' expected
 ACCEPTABLE-SET.

Yeah, I looked at this code, perhaps 'INPUT' is not a valid
'ACCEPTABLE-SET' would be more helpful.  In my message I was talking
about the monitor command though.  Something like you typoed in the
device name should be reported by the human readable monitor.

Cheers



Re: [Qemu-devel] [Qemu-trivial] [PATCH] vl.c: Increase width of machine name column in -M ? output

2012-02-23 Thread Stefan Hajnoczi
On Wed, Feb 22, 2012 at 10:13:11PM +, Peter Maydell wrote:
 Increase the width of the column used for the machine name in
 the -M ? output from 10 to 20 spaces. This fixes the formatting
 so it looks nice for architectures where a few of the machines
 have overly long names. (Our current longest machine name is
 petalogix-s3adsp1800 with realview-eb-mpcore not far behind.)
 
 Signed-off-by: Peter Maydell peter.mayd...@linaro.org
 ---
  vl.c |4 ++--
  1 files changed, 2 insertions(+), 2 deletions(-)

Confirmed that libvirt does not depend on the spacing.

Thanks, applied to the trivial patches tree:
https://github.com/stefanha/qemu/commits/trivial-patches

Stefan



Re: [Qemu-devel] [Bug 939027] [NEW] Combining direct_io and non-direct_io leads to hang

2012-02-23 Thread Stefan Hajnoczi
On Wed, Feb 22, 2012 at 09:49:59PM -, Avleen Vig wrote:
 Version 0.12.2 - I know this isn't the latest but I looked through the
 changelogs and couldn't find any references to this being fixed.

 This is related to issues that many apps have, and is described in more 
 detail here:
 http://oss.sgi.com/archives/xfs/2010-07/msg00163.html
 and:
 https://bugs.launchpad.net/percona-xtrabackup/+bug/606981
 
 When using both direct io and buffered io on the same file, you can cause 
 corruption on the filesystem and other issues.
 XFS out right hangs, but the problem exists on ext3 and other filesystems 
 which silently carry on.
 
 **this is a data corruption issue**.
 
 This is the full stack trace we got from a recent hang:

I only see qemu-kvm in the backtrace.  QEMU normally only access the
image file either with or without O_DIRECT - not both at the same time.
Were you running another program that accesses the image file at the
same time?

Stefan



Re: [Qemu-devel] Cluster_size parameter issue on qcow2 image format

2012-02-23 Thread Stefan Hajnoczi
On Thu, Feb 23, 2012 at 11:01:46AM +0530, PANKAJ RAWAT wrote:
 I theory regarding  cluster size it is written that as the size of cluster
 increase performance should increase.
 
 But something surprising happen The performance is degrading as the size of
 cluster increased from 64K to 1M  ( during expansion of qcow2 image)

It's not true that performance should increase by raising the cluster
size, otherwise the default would be infinity.  It's an algorithms/data
structure trade-off.

Most importantly is the relative latency between a small guest I/O
request (e.g. 4 KB) and the cluster size (e.g. 64 KB).  If the cluster
size latency is orders of magnitude larger than a small guest I/O
request, then be prepared to see extreme effects described below:

 * Bigger clusters decrease the frequency of metadata operations and
   increase metadata cache hit rates.  Bigger clusters means less
   metadata so qcow2 performs fewer metadata operations overall.

   Performance boost.

 * Bigger clusters increase the cost of allocating a new cluster.  For
   example, a 8 KB write to a new cluster will incur a 1 MB write to the
   image file (the untouched regions are filled with zeros).  This can
   be optimized in some cases but not everywhere (e.g. reallocating a
   data cluster versus extending the image file size and relying on the
   file system to provide zeroed space).  This is especially expensive
   when a backing file is in use because up to 1 MB of the backing file
   needs to be read to populate the newly allocated cluster!

   Performance loss.

 * Bigger clusters can reduce fragmentation of data on the physical
   disk.  The file system sees fewer, bigger allocating writes and is
   therefore able to allocate more contiguous data - less fragmentation.

   Performance boost.

 * Bigger clusters reduce the compactness of sparse files. you use more
   image file space on the host file system when the cluster size is
   large.

   Space efficiency loss.

Here's a scenario where a 1 MB cluster size is great compared to a large
cluster size:

You have a fully allocated qcow2 image, you will never need to do any
allocating writes.

Here's a scenario where a 1 MB cluster size is terrible compared to a
small cluster size:

You have an empty qcow2 file and perform 4 KB writes to the first sector
of each 1 MB chunk, and there is a backing file.

So it depends on the application.

Stefan



Re: [Qemu-devel] effect of cluster_size on qcow2 performance during expansion

2012-02-23 Thread Stefan Hajnoczi
On Thu, Feb 23, 2012 at 8:24 AM, PANKAJ RAWAT pankajr...@gmail.com wrote:
 Here are the reading taken through fio tool during write operation


 Cluster size : 32K    587Mb/sec (aggrb MB/sec)


 Cluster size : 64K    697Mb/sec (aggrb MB/sec)

 Cluster size : 1M     440Mb/sec  (aggrb MB/sec)


 Cluster size : 2M     289Mb/sec  (aggrb MB/sec)

 as in above it can bee seen that the 64k is performing better

 can any one tell why ?

Yes.  Please see the other email thread you created on this topic.

Stefan



[Qemu-devel] [PATCH 2/2] optimize screendump for the common non-switch case

2012-02-23 Thread Gerd Hoffmann
switch console only if needed, also pass down whenever the console was
switched or not because a displaysurface redraw is only needed in case
the console was switched.

Signed-off-by: Gerd Hoffmann kra...@redhat.com
---
 console.c   |   10 +++---
 console.h   |2 +-
 hw/qxl.c|4 ++--
 hw/vga.c|   10 ++
 hw/vmware_vga.c |4 ++--
 5 files changed, 18 insertions(+), 12 deletions(-)

diff --git a/console.c b/console.c
index 135394f..b3bd14a 100644
--- a/console.c
+++ b/console.c
@@ -176,17 +176,21 @@ void vga_hw_invalidate(void)
 void vga_hw_screen_dump(const char *filename)
 {
 TextConsole *previous_active_console;
+bool cswitch;
 
 previous_active_console = active_console;
+cswitch = previous_active_console  previous_active_console-index != 0;
 
 /* There is currently no way of specifying which screen we want to dump,
so always dump the first one.  */
-console_select(0);
+if (cswitch) {
+console_select(0);
+}
 if (consoles[0]  consoles[0]-hw_screen_dump) {
-consoles[0]-hw_screen_dump(consoles[0]-hw, filename);
+consoles[0]-hw_screen_dump(consoles[0]-hw, filename, cswitch);
 }
 
-if (previous_active_console) {
+if (cswitch) {
 console_select(previous_active_console-index);
 }
 }
diff --git a/console.h b/console.h
index 6ba0d5d..1fc8ea3 100644
--- a/console.h
+++ b/console.h
@@ -340,7 +340,7 @@ static inline void console_write_ch(console_ch_t *dest, 
uint32_t ch)
 
 typedef void (*vga_hw_update_ptr)(void *);
 typedef void (*vga_hw_invalidate_ptr)(void *);
-typedef void (*vga_hw_screen_dump_ptr)(void *, const char *);
+typedef void (*vga_hw_screen_dump_ptr)(void *, const char *, bool cswitch);
 typedef void (*vga_hw_text_update_ptr)(void *, console_ch_t *);
 
 DisplayState *graphic_console_init(vga_hw_update_ptr update,
diff --git a/hw/qxl.c b/hw/qxl.c
index e38bb29..f4c68ab 100644
--- a/hw/qxl.c
+++ b/hw/qxl.c
@@ -1438,7 +1438,7 @@ static void qxl_hw_invalidate(void *opaque)
 vga-invalidate(vga);
 }
 
-static void qxl_hw_screen_dump(void *opaque, const char *filename)
+static void qxl_hw_screen_dump(void *opaque, const char *filename, bool 
cswitch)
 {
 PCIQXLDevice *qxl = opaque;
 VGACommonState *vga = qxl-vga;
@@ -1450,7 +1450,7 @@ static void qxl_hw_screen_dump(void *opaque, const char 
*filename)
 ppm_save(filename, qxl-ssd.ds-surface);
 break;
 case QXL_MODE_VGA:
-vga-screen_dump(vga, filename);
+vga-screen_dump(vga, filename, cswitch);
 break;
 default:
 break;
diff --git a/hw/vga.c b/hw/vga.c
index f8f30f8..5994f43 100644
--- a/hw/vga.c
+++ b/hw/vga.c
@@ -162,7 +162,7 @@ static uint32_t expand4[256];
 static uint16_t expand2[256];
 static uint8_t expand4to8[16];
 
-static void vga_screen_dump(void *opaque, const char *filename);
+static void vga_screen_dump(void *opaque, const char *filename, bool cswitch);
 
 static void vga_update_memory_access(VGACommonState *s)
 {
@@ -2407,11 +2407,13 @@ int ppm_save(const char *filename, struct 
DisplaySurface *ds)
 
 /* save the vga display in a PPM image even if no display is
available */
-static void vga_screen_dump(void *opaque, const char *filename)
+static void vga_screen_dump(void *opaque, const char *filename, bool cswitch)
 {
 VGACommonState *s = opaque;
 
-vga_invalidate_display(s);
-vga_hw_update();
+if (cswitch) {
+vga_invalidate_display(s);
+vga_hw_update();
+}
 ppm_save(filename, s-ds-surface);
 }
diff --git a/hw/vmware_vga.c b/hw/vmware_vga.c
index f8afa3c..142d9f4 100644
--- a/hw/vmware_vga.c
+++ b/hw/vmware_vga.c
@@ -1003,11 +1003,11 @@ static void vmsvga_invalidate_display(void *opaque)
 
 /* save the vga display in a PPM image even if no display is
available */
-static void vmsvga_screen_dump(void *opaque, const char *filename)
+static void vmsvga_screen_dump(void *opaque, const char *filename, bool 
cswitch)
 {
 struct vmsvga_state_s *s = opaque;
 if (!s-enable) {
-s-vga.screen_dump(s-vga, filename);
+s-vga.screen_dump(s-vga, filename, cswitch);
 return;
 }
 
-- 
1.7.1




[Qemu-devel] [PATCH 0/2] screendump fixups

2012-02-23 Thread Gerd Hoffmann
  Hi,

After checking again I figured the displaychangelistener for screendumps
isn't needed.  Sorry alon.  So lets just zap it.  Also the console
switching can be optimized further, when no switching was needed (the
common case) we can just go ahead and write out the dump without a full
displaysurface redraw.

cheers,
  Gerd

Gerd Hoffmann (2):
  vga: simplify screendump
  optimize screendump for the common non-switch case

 console.c   |   10 +++---
 console.h   |2 +-
 hw/qxl.c|4 ++--
 hw/vga.c|   46 +++---
 hw/vmware_vga.c |4 ++--
 5 files changed, 19 insertions(+), 47 deletions(-)




[Qemu-devel] [PATCH 1/2] vga: simplify screendump

2012-02-23 Thread Gerd Hoffmann
The displaychangelistener isn't needed at all, we can simply save the
image when vga_hw_update is done instead of hooking into the update
process.
---
 hw/vga.c |   36 +---
 1 files changed, 1 insertions(+), 35 deletions(-)

diff --git a/hw/vga.c b/hw/vga.c
index c1029db..f8f30f8 100644
--- a/hw/vga.c
+++ b/hw/vga.c
@@ -163,8 +163,6 @@ static uint16_t expand2[256];
 static uint8_t expand4to8[16];
 
 static void vga_screen_dump(void *opaque, const char *filename);
-static const char *screen_dump_filename;
-static DisplayChangeListener *screen_dump_dcl;
 
 static void vga_update_memory_access(VGACommonState *s)
 {
@@ -2364,22 +2362,6 @@ void vga_init_vbe(VGACommonState *s, MemoryRegion 
*system_memory)
 //
 /* vga screen dump */
 
-static void vga_save_dpy_update(DisplayState *ds,
-int x, int y, int w, int h)
-{
-if (screen_dump_filename) {
-ppm_save(screen_dump_filename, ds-surface);
-}
-}
-
-static void vga_save_dpy_resize(DisplayState *s)
-{
-}
-
-static void vga_save_dpy_refresh(DisplayState *s)
-{
-}
-
 int ppm_save(const char *filename, struct DisplaySurface *ds)
 {
 FILE *f;
@@ -2423,29 +2405,13 @@ int ppm_save(const char *filename, struct 
DisplaySurface *ds)
 return 0;
 }
 
-static DisplayChangeListener* vga_screen_dump_init(DisplayState *ds)
-{
-DisplayChangeListener *dcl;
-
-dcl = g_malloc0(sizeof(DisplayChangeListener));
-dcl-dpy_update = vga_save_dpy_update;
-dcl-dpy_resize = vga_save_dpy_resize;
-dcl-dpy_refresh = vga_save_dpy_refresh;
-register_displaychangelistener(ds, dcl);
-return dcl;
-}
-
 /* save the vga display in a PPM image even if no display is
available */
 static void vga_screen_dump(void *opaque, const char *filename)
 {
 VGACommonState *s = opaque;
 
-if (!screen_dump_dcl)
-screen_dump_dcl = vga_screen_dump_init(s-ds);
-
-screen_dump_filename = filename;
 vga_invalidate_display(s);
 vga_hw_update();
-screen_dump_filename = NULL;
+ppm_save(filename, s-ds-surface);
 }
-- 
1.7.1




Re: [Qemu-devel] [PATCH v5 0/9] qxl: fix hangs caused by qxl_render_update

2012-02-23 Thread Gerd Hoffmann
  Hi,

   vga: stop after the first ppm_save
- single liner to ensure a single ppm_save for a single screendump
  monitor command.

That needs a refinement.  /me somehow looked at a old vga.c checkout and
missed commit 2313e998d7bf55d02499ee162fb4558af4fbb3f5.  See the small
patch series just send.  The qxl bits look fine now.

cheers,
  Gerd



Re: [Qemu-devel] [PATCH 3/3] Add nocreate option to snapshot_blkdev

2012-02-23 Thread Federico Simoncelli
- Original Message -
 From: Paolo Bonzini pbonz...@redhat.com
 Cc: Federico Simoncelli fsimo...@redhat.com, kw...@redhat.com, 
 mtosa...@redhat.com, qemu-devel@nongnu.org
 Sent: Thursday, February 23, 2012 8:38:55 AM
 Subject: Re: [PATCH 3/3] Add nocreate option to snapshot_blkdev
 
 On 02/23/2012 08:19 AM, Paolo Bonzini wrote:
   Signed-off-by: Federico Simoncelli fsimo...@redhat.com
  What is the usecase, and how can this be tested?
 
 Oops, you explained it in part 0.
 
  Step 5 - Final Switch to Destination
  
  VM1 is now able to switch to the destination for both read and
  write
  operations.
  
  [src/hd0base] - [src/hd0snap1] = VM1(read-write)
  
  (qemu) snapshot_blkdev -n ide0-hd0 /tmp/dst/hd0snap1.qcow2
 
 It seems to me that reusing the snapshot_blkdev command is a bit of a
 misnomer.  It also forces you to use format autodetection for the
 destination in the blkmirror phase.
 
 I see two possibilities:
 
 1) you can make a new command block_reopen; this fixes only the
 naming
 problem.
 
 2) you can hide the new format behind a new command to be used like
 this:
 
block_migrate --mirror ide-hd0 /tmp/dst/hd0snap1.qcow2
...
block_migrate --switch ide-hd0
 
 This leave the possibility to specify the format in the future:
 
block_migrate --mirror ide-hd0 /tmp/dst/hd0snap1.qcow2 qcow2
 
 And we could have another sub-command
 
block_mirror --stream ide-hd0 /tmp/dst/hd0.raw
 
 to migrate block devices without shared storage and without an
 intermediate snapshot.

I agree on the fact that using snapshot_blkdev is a misnomer but at
the same time I like very much how blkmirror is modular and it can
be used as a regular image filename.
I'm worried that making it explicit with a --mirror option would
take away its flexibility.
What about adding block_reopen and extending the blkmirror string:

 (qemu) block_reopen ide-hd0 \
 blkmirror:qcow2:/tmp/src/hd0snap1.qcow2:/tmp/dst/hd0snap1.qcow2

so that the format is passed as first argument (and if it's empty we
would use the auto-detection).

-- 
Federico



[Qemu-devel] qemu-ga error reporting

2012-02-23 Thread Michal Privoznik
Hi guys,

I ran into weird issue. Issuing unknown-command on qemu monitor gives this:

{error: {class: CommandNotFound, desc: The command
unknown-command has not been found, data: {name: unknown-command}}}


However, issuing the very same on GA socket gets me:

{error: {class: CommandNotFound, data: {name: unknown-command}}}

which is missing the 'desc'; Can this be fixed, so GA report the 'desc'
field? Libvirt uses that for error reporting as it usually is perfectly
suitable.

Michal



Re: [Qemu-devel] [PATCH 2/3] Update the blkmirror block driver

2012-02-23 Thread Federico Simoncelli
- Original Message -
 From: Paolo Bonzini pbonz...@redhat.com
 To: Federico Simoncelli fsimo...@redhat.com
 Cc: qemu-devel@nongnu.org, kw...@redhat.com, mtosa...@redhat.com
 Sent: Thursday, February 23, 2012 8:18:28 AM
 Subject: Re: [PATCH 2/3] Update the blkmirror block driver
 
 On 02/22/2012 06:13 PM, Federico Simoncelli wrote:
  @@ -46,7 +46,7 @@ static int blkmirror_open(BlockDriverState *bs,
  const char *filename, int flags)
   filename += strlen(blkmirror:);
   
   /* Parse the raw image filename */
  -filename2 = qemu_malloc(strlen(filename)+1);
  +filename2 = qemu_vmalloc(strlen(filename)+1);
   escape = 0;
   for (i = n = 0; i  strlen(filename); i++) {
   if (!escape  filename[i] == ':') {
  @@ -66,11 +66,11 @@ static int blkmirror_open(BlockDriverState *bs,
  const char *filename, int flags)
   
   m-bs[0] = bdrv_new();
   if (m-bs[0] == NULL) {
  -free(filename2);
  +qemu_vfree(filename2);
   return -ENOMEM;
   }
   ret = bdrv_open(m-bs[0], filename2, flags, NULL);
  -free(filename2);
  +qemu_vfree(filename2);
   if (ret  0) {
   return ret;
   }
 
 These should be g_malloc and g_free.

Thanks!

 Also, please squash this patch in part 1.

Yes, I sent it as a separate patch to make it easier to review my
changes (if someone already reviewed Marcelo's patch).
Any comment on the BDRV_O_NO_BACKING flag I added? That's the real
trick I'm pulling here. It basically allows to open the second image
only for writing and it doesn't complain if the backing file is not
there yet (it will be copied during step 4).

-- 
Federico



[Qemu-devel] [PULL] Merge qemu-iotests into qemu.git

2012-02-23 Thread Kevin Wolf
The following changes since commit 235fe3bfd46b1104575b540d0bc3fdf584030b99:

  qom: add test tools (2012-02-22 12:18:26 -0600)

are available in the git repository at:
  git://repo.or.cz/qemu/kevin.git for-anthony

Christoph Hellwig (10):
  qemu-iotests: Initial import into the public repository.
  qemu-iotests: skip test 005 for vpc format images
  qemu-iotests: add support for the vdi image format
  qemu-iotests: remove test image after 015 is done
  qemu-iotests: make a few more tests generic
  qemu-iotests: test I/O after EOF for growable files
  qemu-iotests: replace FSF postal addresses with www.gnu.org links
  qemu-iotests: test invalid pattern argument handling in qemu-io
  qemu-iotests: filter TEST_DIR correctly in 019
  qemu-iotests: only run 016 for file and sheepdog protocols

Josh Durgin (1):
  qemu-iotests: Update rbd support

Kevin Wolf (21):
  qemu-iotests: add test for refcount table growth and snapshots
  qemu-iotests: simple backing file test
  qemu-iotests: test merge of backing file when converting
  qemu-iotests: test qemu-img convert with backing file for the output image
  qemu-iotests: test commiting changes to backing file
  qemu-iotests: common.pattern: allow spaces in io() operation
  qemu-iotests: test bdrv_load/save_vmstate
  qemu-iotests: fix expected result for 019 after qemu-io change
  qemu-iotests: align test requests according to cluster size
  qemu-iotests: 019: Make cluster size dynamic
  qemu-iotests: test larger clusters sizes on qcow2
  qemu-iotests: test qemu-img rebase
  qemu-iotests: improve rebase test
  qemu-iotests: qcow2 error path tests
  qemu-iotests: consider more cases in parsing qemu-io output
  qemu-iotests: improve test for qemu-img convert with backing file
  qemu-iotests: update expected results after qemu-img changes
  qemu-iotests: fix 019 golden output
  qemu-iotests: Update filter for default cluster size
  qemu-iotests: test loading internal snapshots
  Merge qemu-iotests into for-anthony

Lucas Meneghel Rodrigues (2):
  qemu-iotests: check: print relevant path information
  qemu-iotests: common.config: Allow use of arbitrary qemu* paths

MORITA Kazutaka (1):
  qemu-iotests: add support for rbd and sheepdog protocols

Mitnick Lyu (1):
  qemu-iotests: common.config: Fix no $TEST_DIR directory

Stefan Hajnoczi (8):
  qemu-iotests: explicitly use bash interpreter
  qemu-iotests: test bdrv_truncate
  qemu-iotests: add sub-cluster allocating write test for sparse image 
formats
  qemu-iotests: add read/write from smaller backing image test
  qemu-iotests: add support for qed format
  qemu-iotests: filter IMGFMT correctly in 019
  qemu-iotests: Use zero-based offsets for IO patterns
  qemu-iotests: add qed support to 025 image resize test

Stefan Weil (3):
  qemu-iotests: fix pattern for write test
  qemu-iotests: add support for vdi format static option
  qemu-iotests: README: Fix spelling

 tests/qemu-iotests/.gitignore |7 +
 tests/qemu-iotests/001|   65 +
 tests/qemu-iotests/001.out|   15 +
 tests/qemu-iotests/002|   72 +
 tests/qemu-iotests/002.out|   23 +
 tests/qemu-iotests/003|   78 +
 tests/qemu-iotests/003.out|   23 +
 tests/qemu-iotests/004|  104 +
 tests/qemu-iotests/004.out|   41 +
 tests/qemu-iotests/005|   73 +
 tests/qemu-iotests/005.out|   13 +
 tests/qemu-iotests/006|   54 +
 tests/qemu-iotests/006.out|6 +
 tests/qemu-iotests/007|   67 +
 tests/qemu-iotests/007.out|   18 +
 tests/qemu-iotests/008|   65 +
 tests/qemu-iotests/008.out|   15 +
 tests/qemu-iotests/009|   69 +
 tests/qemu-iotests/009.out|   18 +
 tests/qemu-iotests/010|   71 +
 tests/qemu-iotests/010.out|   22 +
 tests/qemu-iotests/011|   75 +
 tests/qemu-iotests/011.out|   50 +
 tests/qemu-iotests/012|   62 +
 tests/qemu-iotests/012.out|9 +
 tests/qemu-iotests/013|   98 +
 tests/qemu-iotests/013.out|43983 +
 tests/qemu-iotests/014|   77 +
 tests/qemu-iotests/014.out|64074 +
 tests/qemu-iotests/015|   85 +
 tests/qemu-iotests/015.out|   20 +
 tests/qemu-iotests/016|   70 +
 tests/qemu-iotests/016.out|   23 +
 tests/qemu-iotests/017|  101 +
 tests/qemu-iotests/017.out| 1077 +
 tests/qemu-iotests/018|  104 +
 tests/qemu-iotests/018.out| 1077 +
 tests/qemu-iotests/019|  129 +
 tests/qemu-iotests/019.out| 1628 +
 tests/qemu-iotests/020|  106 +
 tests/qemu-iotests/020.out| 1078 +
 tests/qemu-iotests/021|   63 +
 

Re: [Qemu-devel] [PATCH 2/3] Update the blkmirror block driver

2012-02-23 Thread Paolo Bonzini
On 02/23/2012 10:44 AM, Federico Simoncelli wrote:
 Any comment on the BDRV_O_NO_BACKING flag I added? That's the real
 trick I'm pulling here. It basically allows to open the second image
 only for writing and it doesn't complain if the backing file is not
 there yet (it will be copied during step 4).

Yes, it makes sense to me.

Paolo



Re: [Qemu-devel] [PATCH 3/3] Add nocreate option to snapshot_blkdev

2012-02-23 Thread Paolo Bonzini
On 02/23/2012 10:39 AM, Federico Simoncelli wrote:
 I agree on the fact that using snapshot_blkdev is a misnomer but at
 the same time I like very much how blkmirror is modular and it can
 be used as a regular image filename.

True, on the other hand if we add this we will have to keep it forever.

I'm worried that blkmirror does not satisfy _all_ mirroring needs, for
example you cannot use block_stream to copy from the source to the
destination, so perhaps in the future we want to change it to something
else.

So while I appreciate the easier debugging, I'm afraid that we'll regret
adding a command-line-visible feature.

 I'm worried that making it explicit with a --mirror option would
 take away its flexibility.
 What about adding block_reopen and extending the blkmirror string:
 
  (qemu) block_reopen ide-hd0 \
  blkmirror:qcow2:/tmp/src/hd0snap1.qcow2:/tmp/dst/hd0snap1.qcow2
 
 so that the format is passed as first argument (and if it's empty we
 would use the auto-detection).

No, the format of the source and destination should be independent.  It
would be nice to have something like this:

blkmirror:src=...,dst=...,srcformat=...,dstformat=...

but commas are a pain because they need escaping.

Paolo



Re: [Qemu-devel] [PATCH 1/2] vga: simplify screendump

2012-02-23 Thread Alon Levy
On Thu, Feb 23, 2012 at 10:22:37AM +0100, Gerd Hoffmann wrote:
 The displaychangelistener isn't needed at all, we can simply save the
 image when vga_hw_update is done instead of hooking into the update
 process.

ACK.

 ---
  hw/vga.c |   36 +---
  1 files changed, 1 insertions(+), 35 deletions(-)
 
 diff --git a/hw/vga.c b/hw/vga.c
 index c1029db..f8f30f8 100644
 --- a/hw/vga.c
 +++ b/hw/vga.c
 @@ -163,8 +163,6 @@ static uint16_t expand2[256];
  static uint8_t expand4to8[16];
  
  static void vga_screen_dump(void *opaque, const char *filename);
 -static const char *screen_dump_filename;
 -static DisplayChangeListener *screen_dump_dcl;
  
  static void vga_update_memory_access(VGACommonState *s)
  {
 @@ -2364,22 +2362,6 @@ void vga_init_vbe(VGACommonState *s, MemoryRegion 
 *system_memory)
  //
  /* vga screen dump */
  
 -static void vga_save_dpy_update(DisplayState *ds,
 -int x, int y, int w, int h)
 -{
 -if (screen_dump_filename) {
 -ppm_save(screen_dump_filename, ds-surface);
 -}
 -}
 -
 -static void vga_save_dpy_resize(DisplayState *s)
 -{
 -}
 -
 -static void vga_save_dpy_refresh(DisplayState *s)
 -{
 -}
 -
  int ppm_save(const char *filename, struct DisplaySurface *ds)
  {
  FILE *f;
 @@ -2423,29 +2405,13 @@ int ppm_save(const char *filename, struct 
 DisplaySurface *ds)
  return 0;
  }
  
 -static DisplayChangeListener* vga_screen_dump_init(DisplayState *ds)
 -{
 -DisplayChangeListener *dcl;
 -
 -dcl = g_malloc0(sizeof(DisplayChangeListener));
 -dcl-dpy_update = vga_save_dpy_update;
 -dcl-dpy_resize = vga_save_dpy_resize;
 -dcl-dpy_refresh = vga_save_dpy_refresh;
 -register_displaychangelistener(ds, dcl);
 -return dcl;
 -}
 -
  /* save the vga display in a PPM image even if no display is
 available */
  static void vga_screen_dump(void *opaque, const char *filename)
  {
  VGACommonState *s = opaque;
  
 -if (!screen_dump_dcl)
 -screen_dump_dcl = vga_screen_dump_init(s-ds);
 -
 -screen_dump_filename = filename;
  vga_invalidate_display(s);
  vga_hw_update();
 -screen_dump_filename = NULL;
 +ppm_save(filename, s-ds-surface);
  }
 -- 
 1.7.1
 
 



Re: [Qemu-devel] Cluster_size parameter issue on qcow2 image format

2012-02-23 Thread PANKAJ RAWAT
Thanks for the reply .
i am not using a backing file.
My concern is growing file system.
The performance of 64K is better than 1M , 2M or 32K

Is the degrade in performance is only due to allocation of large cluster
during expansion of qcow2 image ?

But the trend is same in case of
Sequential write
Random write  of 1 GB data

In random i can understand the sparseness of data
But in sequential write I don't understand as the write is performed on
sequential bases

is there is any reason behind it or i am not getting it right ?

On Thu, Feb 23, 2012 at 2:02 PM, Stefan Hajnoczi stefa...@gmail.com wrote:

 On Thu, Feb 23, 2012 at 11:01:46AM +0530, PANKAJ RAWAT wrote:
  I theory regarding  cluster size it is written that as the size of
 cluster
  increase performance should increase.
 
  But something surprising happen The performance is degrading as the size
 of
  cluster increased from 64K to 1M  ( during expansion of qcow2 image)

 It's not true that performance should increase by raising the cluster
 size, otherwise the default would be infinity.  It's an algorithms/data
 structure trade-off.

 Most importantly is the relative latency between a small guest I/O
 request (e.g. 4 KB) and the cluster size (e.g. 64 KB).  If the cluster
 size latency is orders of magnitude larger than a small guest I/O
 request, then be prepared to see extreme effects described below:

  * Bigger clusters decrease the frequency of metadata operations and
   increase metadata cache hit rates.  Bigger clusters means less
   metadata so qcow2 performs fewer metadata operations overall.

   Performance boost.

  * Bigger clusters increase the cost of allocating a new cluster.  For
   example, a 8 KB write to a new cluster will incur a 1 MB write to the
   image file (the untouched regions are filled with zeros).  This can
   be optimized in some cases but not everywhere (e.g. reallocating a
   data cluster versus extending the image file size and relying on the
   file system to provide zeroed space).  This is especially expensive
   when a backing file is in use because up to 1 MB of the backing file
   needs to be read to populate the newly allocated cluster!

   Performance loss.

  * Bigger clusters can reduce fragmentation of data on the physical
   disk.  The file system sees fewer, bigger allocating writes and is
   therefore able to allocate more contiguous data - less fragmentation.

   Performance boost.

  * Bigger clusters reduce the compactness of sparse files. you use more
   image file space on the host file system when the cluster size is
   large.

   Space efficiency loss.

 Here's a scenario where a 1 MB cluster size is great compared to a large
 cluster size:

 You have a fully allocated qcow2 image, you will never need to do any
 allocating writes.

 Here's a scenario where a 1 MB cluster size is terrible compared to a
 small cluster size:

 You have an empty qcow2 file and perform 4 KB writes to the first sector
 of each 1 MB chunk, and there is a backing file.

 So it depends on the application.

 Stefan




-- 
*Pankaj Rawat*


Re: [Qemu-devel] [PATCH 2/2] optimize screendump for the common non-switch case

2012-02-23 Thread Alon Levy
On Thu, Feb 23, 2012 at 10:22:38AM +0100, Gerd Hoffmann wrote:
 switch console only if needed, also pass down whenever the console was
 switched or not because a displaysurface redraw is only needed in case
 the console was switched.
 

You've missed some implementations of the vga_hw_screen_dump_ptr, see

$ git grep -A3 graphic_console_init | grep screen | grep -v -w screen_dump
hw/blizzard.c- blizzard_screen_dump, NULL, s);
hw/g364fb.c- g364fb_screen_dump, NULL, s);
hw/jazz_led.c- jazz_led_screen_dump,
hw/omap_dss.c-omap_invalidate_display, 
omap_screen_dump, s);
hw/omap_lcdc.c-omap_screen_dump, NULL, s);
hw/pxa2xx_lcd.c- pxa2xx_screen_dump, NULL, s);
hw/qxl.c-   qxl_hw_screen_dump, 
qxl_hw_text_update, qxl);
hw/tcx.c- tcx24_screen_dump, NULL, s);
hw/tcx.c- tcx_screen_dump, NULL, s);
hw/vmware_vga.c- vmsvga_screen_dump,

 Signed-off-by: Gerd Hoffmann kra...@redhat.com
 ---
  console.c   |   10 +++---
  console.h   |2 +-
  hw/qxl.c|4 ++--
  hw/vga.c|   10 ++
  hw/vmware_vga.c |4 ++--
  5 files changed, 18 insertions(+), 12 deletions(-)
 
 diff --git a/console.c b/console.c
 index 135394f..b3bd14a 100644
 --- a/console.c
 +++ b/console.c
 @@ -176,17 +176,21 @@ void vga_hw_invalidate(void)
  void vga_hw_screen_dump(const char *filename)
  {
  TextConsole *previous_active_console;
 +bool cswitch;
  
  previous_active_console = active_console;
 +cswitch = previous_active_console  previous_active_console-index != 0;
  
  /* There is currently no way of specifying which screen we want to dump,
 so always dump the first one.  */
 -console_select(0);
 +if (cswitch) {
 +console_select(0);
 +}
  if (consoles[0]  consoles[0]-hw_screen_dump) {
 -consoles[0]-hw_screen_dump(consoles[0]-hw, filename);
 +consoles[0]-hw_screen_dump(consoles[0]-hw, filename, cswitch);
  }
  
 -if (previous_active_console) {
 +if (cswitch) {
  console_select(previous_active_console-index);
  }
  }
 diff --git a/console.h b/console.h
 index 6ba0d5d..1fc8ea3 100644
 --- a/console.h
 +++ b/console.h
 @@ -340,7 +340,7 @@ static inline void console_write_ch(console_ch_t *dest, 
 uint32_t ch)
  
  typedef void (*vga_hw_update_ptr)(void *);
  typedef void (*vga_hw_invalidate_ptr)(void *);
 -typedef void (*vga_hw_screen_dump_ptr)(void *, const char *);
 +typedef void (*vga_hw_screen_dump_ptr)(void *, const char *, bool cswitch);
  typedef void (*vga_hw_text_update_ptr)(void *, console_ch_t *);
  
  DisplayState *graphic_console_init(vga_hw_update_ptr update,
 diff --git a/hw/qxl.c b/hw/qxl.c
 index e38bb29..f4c68ab 100644
 --- a/hw/qxl.c
 +++ b/hw/qxl.c
 @@ -1438,7 +1438,7 @@ static void qxl_hw_invalidate(void *opaque)
  vga-invalidate(vga);
  }
  
 -static void qxl_hw_screen_dump(void *opaque, const char *filename)
 +static void qxl_hw_screen_dump(void *opaque, const char *filename, bool 
 cswitch)
  {
  PCIQXLDevice *qxl = opaque;
  VGACommonState *vga = qxl-vga;
 @@ -1450,7 +1450,7 @@ static void qxl_hw_screen_dump(void *opaque, const char 
 *filename)
  ppm_save(filename, qxl-ssd.ds-surface);
  break;
  case QXL_MODE_VGA:
 -vga-screen_dump(vga, filename);
 +vga-screen_dump(vga, filename, cswitch);
  break;
  default:
  break;
 diff --git a/hw/vga.c b/hw/vga.c
 index f8f30f8..5994f43 100644
 --- a/hw/vga.c
 +++ b/hw/vga.c
 @@ -162,7 +162,7 @@ static uint32_t expand4[256];
  static uint16_t expand2[256];
  static uint8_t expand4to8[16];
  
 -static void vga_screen_dump(void *opaque, const char *filename);
 +static void vga_screen_dump(void *opaque, const char *filename, bool 
 cswitch);
  
  static void vga_update_memory_access(VGACommonState *s)
  {
 @@ -2407,11 +2407,13 @@ int ppm_save(const char *filename, struct 
 DisplaySurface *ds)
  
  /* save the vga display in a PPM image even if no display is
 available */
 -static void vga_screen_dump(void *opaque, const char *filename)
 +static void vga_screen_dump(void *opaque, const char *filename, bool cswitch)
  {
  VGACommonState *s = opaque;
  
 -vga_invalidate_display(s);
 -vga_hw_update();
 +if (cswitch) {
 +vga_invalidate_display(s);
 +vga_hw_update();
 +}
  ppm_save(filename, s-ds-surface);
  }
 diff --git a/hw/vmware_vga.c b/hw/vmware_vga.c
 index f8afa3c..142d9f4 100644
 --- a/hw/vmware_vga.c
 +++ b/hw/vmware_vga.c
 @@ -1003,11 +1003,11 @@ static void vmsvga_invalidate_display(void *opaque)
  
  /* save the vga display in a PPM image even if no display is
 available */
 -static void 

Re: [Qemu-devel] Cluster_size parameter issue on qcow2 image format

2012-02-23 Thread Stefan Hajnoczi
On Thu, Feb 23, 2012 at 10:02 AM, PANKAJ RAWAT pankajr...@gmail.com wrote:
 Is the degrade in performance is only due to allocation of large cluster
 during expansion of qcow2 image ?

 But the trend is same in case of
 Sequential write
 Random write  of 1 GB data

 In random i can understand the sparseness of data
 But in sequential write I don't understand as the write is performed on
 sequential bases

 is there is any reason behind it or i am not getting it right ?

Sequential writes still require qcow2 to allocate clusters.

The first write request that touches a new cluster causes qcow2 to
allocate the full 1 MB.  Then the next few sequential write requests
overwrite in-place (these requests do not suffer allocation overhead).

Now if you imagine doing 4 KB requests in the guest with 1 MB cluster
size, you should find that the host is doing n * 4 KB / 1 MB - n * 4
KB extra I/O to the image file because it is zeroing each allocated
cluster!

Linux I/O requests tend to be 128 or 256 KB maximum with virtio-blk.
So even if your request size in guest userspace is 1 MB you're
probably doing multiple virtio-blk requests underneath.  Therefore you
are hitting the sequential allocating write pattern I described above.

The exact overhead depends on your application's I/O request pattern
but it's unsuprising that you experience a performance impact.

Stefan



Re: [Qemu-devel] [PATCH 3/3] Add nocreate option to snapshot_blkdev

2012-02-23 Thread Federico Simoncelli
- Original Message -
 From: Paolo Bonzini pbonz...@redhat.com
 To: Federico Simoncelli fsimo...@redhat.com
 Cc: kw...@redhat.com, mtosa...@redhat.com, qemu-devel@nongnu.org
 Sent: Thursday, February 23, 2012 10:48:59 AM
 Subject: Re: [PATCH 3/3] Add nocreate option to snapshot_blkdev
 
 On 02/23/2012 10:39 AM, Federico Simoncelli wrote:
  I agree on the fact that using snapshot_blkdev is a misnomer but at
  the same time I like very much how blkmirror is modular and it can
  be used as a regular image filename.
 
 True, on the other hand if we add this we will have to keep it
 forever.
 
 I'm worried that blkmirror does not satisfy _all_ mirroring needs,
 for
 example you cannot use block_stream to copy from the source to the
 destination, so perhaps in the future we want to change it to
 something
 else.

Are you talking about a mirroring where you block_stream the missing
clusters in the destination from the source?
I believe that it could be done without losing the blkmirror
modularity probably extending the BlockDriver structure with some
additional concepts.

 So while I appreciate the easier debugging, I'm afraid that we'll
 regret
 adding a command-line-visible feature.
 
  I'm worried that making it explicit with a --mirror option would
  take away its flexibility.
  What about adding block_reopen and extending the blkmirror string:
  
   (qemu) block_reopen ide-hd0 \
   blkmirror:qcow2:/tmp/src/hd0snap1.qcow2:/tmp/dst/hd0snap1.qcow2
  
  so that the format is passed as first argument (and if it's empty
  we
  would use the auto-detection).
 
 No, the format of the source and destination should be independent.
  It
 would be nice to have something like this:
 
 blkmirror:src=...,dst=...,srcformat=...,dstformat=...
 
 but commas are a pain because they need escaping.

I like that, one limitation we need to keep in mind is that it should
fit into the hard-coded filename limit of 1024 characters that (sadly) we
have in multiple places. Another thing is that at this stage the mirroring
is more an original/copy concept rather than source/destination.
What about:

blkmirror:...,copy=...,fmt=... (both images uses the same fmt)
blkmirror:...,copy=...,fmt=...,copyfmt=...

Or, eventually if you feel like that source/destination is more appropriate
for the future, then:

blkmirror:...,dst=...,fmt=...,dstfmt=...

-- 
Federico



[Qemu-devel] [PATCH 4/6 v2] virtio-serial: Call .guest_ready when new space is available in the queue.

2012-02-23 Thread Andrzej Zaborowski
Without that it's impossible to write a virtio-serial port driver that
sends any buffers bigger than a couple kilobytes, other than by
polling to check when space in the queue becomes available.

Signed-off-by: Andrzej Zaborowski andrew.zaborow...@intel.com
---
v2: rebase after QOM.
---
 hw/virtio-serial-bus.c |8 
 1 files changed, 8 insertions(+), 0 deletions(-)

diff --git a/hw/virtio-serial-bus.c b/hw/virtio-serial-bus.c
index e22940e..fe350a1 100644
--- a/hw/virtio-serial-bus.c
+++ b/hw/virtio-serial-bus.c
@@ -498,6 +498,14 @@ static void handle_output(VirtIODevice *vdev, VirtQueue 
*vq)
 
 static void handle_input(VirtIODevice *vdev, VirtQueue *vq)
 {
+VirtIOSerial *vser = DO_UPCAST(VirtIOSerial, vdev, vdev);
+VirtIOSerialPort *port = find_port_by_vq(vser, vq);
+VirtIOSerialPortClass *info =
+port ? VIRTIO_SERIAL_PORT_GET_CLASS(port) : NULL;
+
+if (info  info-guest_ready) {
+info-guest_ready(port);
+}
 }
 
 static uint32_t get_features(VirtIODevice *vdev, uint32_t features)
-- 
1.7.4.4




[Qemu-devel] [PATCH 5/6 v2] gl: virtio-serial port driver for OpenGL passthrough.

2012-02-23 Thread Andrzej Zaborowski
This is a relatively simple to use OpenGL passthrough transport
because it doesn't need any guest kernel changes, but it's not
blazing fast.  Still faster than software rendering.

The main problems are:
* transfers are split in very small chunks by virtio queues, some
  OpenGL calls (think textures etc.) will take thousands of context
  switches, vmenters/vmexits, sysenters/sysexits and buffer copying.
  This should really be a single big zerocopy transfer.
* Linux virtio-serial allows only one process to have the port opened,
  so applications on the guest have to fight over the port access
  and open/close the device at every command buffer.
* host cannot know for sure when a guest process has died unexpectedly.

Signed-off-by: Andrzej Zaborowski andrew.zaborow...@intel.com
---
v2: rebase after QOM.
---
 Makefile.target |3 +-
 hw/virtio-gl-port.c |  220 +++
 2 files changed, 222 insertions(+), 1 deletions(-)
 create mode 100644 hw/virtio-gl-port.c

diff --git a/Makefile.target b/Makefile.target
index 90e2739..3fae6ec 100644
--- a/Makefile.target
+++ b/Makefile.target
@@ -199,7 +199,8 @@ obj-y = arch_init.o cpus.o monitor.o machine.o gdbstub.o 
balloon.o ioport.o
 # virtio has to be here due to weird dependency between PCI and virtio-net.
 # need to fix this properly
 obj-$(CONFIG_NO_PCI) += pci-stub.o
-obj-$(CONFIG_VIRTIO) += virtio.o virtio-blk.o virtio-balloon.o virtio-net.o 
virtio-serial-bus.o
+obj-virtio-$(CONFIG_GL) += virtio-gl-port.o
+obj-$(CONFIG_VIRTIO) += virtio.o virtio-blk.o virtio-balloon.o virtio-net.o 
virtio-serial-bus.o $(obj-virtio-y)
 obj-y += vhost_net.o
 obj-$(CONFIG_VHOST_NET) += vhost.o
 obj-$(CONFIG_REALLY_VIRTFS) += 9pfs/virtio-9p-device.o
diff --git a/hw/virtio-gl-port.c b/hw/virtio-gl-port.c
new file mode 100644
index 000..dbeaa2e
--- /dev/null
+++ b/hw/virtio-gl-port.c
@@ -0,0 +1,220 @@
+/*
+ * GL passthrough virtio-serial-based transport
+ *
+ * Copyright (c) 2011 Intel Corporation
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License as
+ * published by the Free Software Foundation; either version 2 or
+ * (at your option) any later version of the License.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, see http://www.gnu.org/licenses/.
+ */
+
+#include hw.h
+#include qemu-error.h
+#include virtio-serial.h
+
+#include gl/vmgl.h
+
+#define CMD_HEADER_SIZE 12
+
+static uint8_t *cmd_buffer;
+static size_t cmd_buffer_bytes;
+static size_t cmd_buffer_size;
+static const uint8_t *ret_buffer;
+static size_t ret_buffer_bytes;
+
+static size_t virtio_gl_get_cmd_size(const uint8_t *buf)
+{
+#ifdef TARGET_WORDS_BIGENDIAN
+return be32_to_cpup((const uint32_t *) buf);
+#else
+return le32_to_cpup((const uint32_t *) buf);
+#endif
+}
+
+static size_t virtio_gl_get_buffer_size(const uint8_t *buf)
+{
+return virtio_gl_get_cmd_size(buf + 4);
+}
+
+static void virtio_gl_guest_ready(VirtIOSerialPort *port)
+{
+ssize_t ret;
+
+if (!ret_buffer_bytes) {
+return;
+}
+
+ret = virtio_serial_write(port, ret_buffer, ret_buffer_bytes);
+if (ret  0) {
+error_report(%s: virtio_serial_write: error %i\n, __func__,
+(int) -ret);
+return;
+}
+ret_buffer += ret;
+ret_buffer_bytes -= ret;
+}
+
+static void virtio_gl_handle_cmd(VirtIOSerialPort *port, const uint8_t *cmd)
+{
+int pid = le32_to_cpup((const uint32_t *) cmd);
+int in_size = virtio_gl_get_cmd_size(cmd + 4);
+int ret;
+ProcessStruct *process = vmgl_get_process(pid);
+
+ret_buffer_bytes = virtio_gl_get_cmd_size(cmd + 8);
+if (cmd_buffer_size  ret_buffer_bytes) {
+cmd_buffer_size = ret_buffer_bytes;
+cmd_buffer = g_realloc(cmd_buffer, cmd_buffer_size);
+}
+ret_buffer = cmd_buffer;
+
+ret = vmgl_decode_call(process, cmd + CMD_HEADER_SIZE,
+in_size - CMD_HEADER_SIZE, cmd_buffer + 4);
+if (!ret) {
+vmgl_disconnect(process);
+return;
+}
+
+#ifdef TARGET_WORDS_BIGENDIAN
+cpu_to_be32wu((uint32_t *) ret_buffer, ret);
+#else
+cpu_to_le32wu((uint32_t *) ret_buffer, ret);
+#endif
+/* FIXME: passing the buffer to decode_call_int and calling
+ * virtio_serial_write precludes zero-copy, figure out something
+ * better.  */
+virtio_gl_guest_ready(port);
+}
+
+static void virtio_gl_guest_close(VirtIOSerialPort *port)
+{
+cmd_buffer_bytes = 0;
+ret_buffer_bytes = 0;
+}
+
+/* Callback function that's called when the guest sends us data */
+static ssize_t virtio_gl_have_data(VirtIOSerialPort *port,
+  

[Qemu-devel] [PATCH 6/6 v2] gl: -enable-gl switch to enable the OpenGL virtio port.

2012-02-23 Thread Andrzej Zaborowski
Signed-off-by: Andrzej Zaborowski andrew.zaborow...@intel.com
---
 qemu-options.hx |   24 
 vl.c|   36 
 2 files changed, 60 insertions(+), 0 deletions(-)

diff --git a/qemu-options.hx b/qemu-options.hx
index b129996..8a5784c 100644
--- a/qemu-options.hx
+++ b/qemu-options.hx
@@ -1114,6 +1114,30 @@ spec but is traditional qemu behavior.
 @end table
 ETEXI
 
+DEF(enable-gl, 0, QEMU_OPTION_enable_gl, \
+-enable-gl enable OpenGL passthrough support\n, QEMU_ARCH_ALL)
+STEXI
+@item -enable-gl
+@findex -enable-gl
+Enable OpenGL passthrough support in QEMU.  Requires corresponding client
+software in the guest OS.  Requires hardware graphics acceleration
+on host system.  Only virtio-capable target machines supported.  Does
+not support vmsave/vmload or migration.
+
+@strong{NOTE}: this feature has not been security reviewed and assumes that
+the emulator runs a trusted guest system.  Enabling this option may allow
+rogue software in the emulator to crash or control QEMU.  Do not use this
+option if unsure.
+
+This option allows the emulated system to take advantage of hardware-
+accelerated OpenGL support of the host machine to speed up applications
+that make heavy use of OpenGL graphics (3D or otherwise) - useful during
+the development of such applications.  For Linux guests running X.org, the
+client software can be installed from
+@url{http://meego.gitorious.org/meego-developer-tools/meego-emulator-libgl-x86}
+or distribution packages if available.
+ETEXI
+
 STEXI
 @end table
 ETEXI
diff --git a/vl.c b/vl.c
index 37f2f96..a2f1c84 100644
--- a/vl.c
+++ b/vl.c
@@ -228,6 +228,7 @@ int ctrl_grab = 0;
 unsigned int nb_prom_envs = 0;
 const char *prom_envs[MAX_PROM_ENVS];
 int boot_menu;
+int enable_gl;
 uint8_t *boot_splash_filedata;
 int boot_splash_filedata_size;
 uint8_t qemu_extra_params_fw[2];
@@ -312,6 +313,21 @@ static int default_driver_check(QemuOpts *opts, void 
*opaque)
 return 0;
 }
 
+typedef struct {
+const char *device_name;
+int found;
+} device_opt_search_t;
+
+static int find_device_opt(QemuOpts *opts, void *opaque)
+{
+device_opt_search_t *devp = (device_opt_search_t *) opaque;
+
+devp-found = devp-found ||
+!strcmp(qemu_opt_get(opts, driver), devp-device_name);
+
+return 0;
+}
+
 /***/
 /* QEMU state */
 
@@ -2896,6 +2912,11 @@ int main(int argc, char **argv, char **envp)
 machine = machine_parse(optarg);
 }
 break;
+#ifdef CONFIG_GL
+case QEMU_OPTION_enable_gl:
+enable_gl = 1;
+break;
+#endif
 case QEMU_OPTION_usb:
 usb_enabled = 1;
 break;
@@ -3133,6 +3154,21 @@ int main(int argc, char **argv, char **envp)
 exit(1);
 }
 
+if (enable_gl) {
+QemuOptsList *device = qemu_find_opts(device);
+QemuOpts *bus_opts, *dev_opts;
+device_opt_search_t devp = { virtio-serial, 0 };
+
+qemu_opts_foreach(device, find_device_opt, devp, 0);
+if (devp.found == 0) {
+bus_opts = qemu_opts_create(device, NULL, 0);
+qemu_opt_set(bus_opts, driver, virtio-serial);
+}
+
+dev_opts = qemu_opts_create(device, NULL, 0);
+qemu_opt_set(dev_opts, driver, virtio-gl-port);
+}
+
 /* If no data_dir is specified then try to find it relative to the
executable path.  */
 if (!data_dir) {
-- 
1.7.4.4




Re: [Qemu-devel] Cluster_size parameter issue on qcow2 image format

2012-02-23 Thread PANKAJ RAWAT
Thanks for the reply

On Thu, Feb 23, 2012 at 3:46 PM, Stefan Hajnoczi stefa...@gmail.com wrote:

 On Thu, Feb 23, 2012 at 10:02 AM, PANKAJ RAWAT pankajr...@gmail.com
 wrote:
  Is the degrade in performance is only due to allocation of large cluster
  during expansion of qcow2 image ?
 
  But the trend is same in case of
  Sequential write
  Random write  of 1 GB data
 
  In random i can understand the sparseness of data
  But in sequential write I don't understand as the write is performed on
  sequential bases
 
  is there is any reason behind it or i am not getting it right ?

 Sequential writes still require qcow2 to allocate clusters.

 The first write request that touches a new cluster causes qcow2 to
 allocate the full 1 MB.  Then the next few sequential write requests
 overwrite in-place (these requests do not suffer allocation overhead).

 Now if you imagine doing 4 KB requests in the guest with 1 MB cluster
 size, you should find that the host is doing n * 4 KB / 1 MB - n * 4
 KB extra I/O to the image file because it is zeroing each allocated
 cluster!

 Linux I/O requests tend to be 128 or 256 KB maximum with virtio-blk.
 So even if your request size in guest userspace is 1 MB you're
 probably doing multiple virtio-blk requests underneath.  Therefore you
 are hitting the sequential allocating write pattern I described above.

 The exact overhead depends on your application's I/O request pattern
 but it's unsuprising that you experience a performance impact.

 Stefan




-- 
*Pankaj Rawat*


Re: [Qemu-devel] [PATCH 3/3] Add nocreate option to snapshot_blkdev

2012-02-23 Thread Paolo Bonzini
On 02/23/2012 11:19 AM, Federico Simoncelli wrote:
 I'm worried that blkmirror does not satisfy _all_ mirroring
 needs, for example you cannot use block_stream to copy from the
 source to the destination, so perhaps in the future we want to
 change it to something else.
 
 Are you talking about a mirroring where you block_stream the missing 
 clusters in the destination from the source? I believe that it could
 be done without losing the blkmirror modularity probably extending
 the BlockDriver structure with some additional concepts.

Yes, agreed.  It's not the idea of a driver that I don't like; it is
making it available through the command-line that worries me.  This
would be unlike all other filtering options (copy-on-read, I/O limits,
dirty sector tracking).  True, there are blkdebug and blkverify but
those are for debugging only.

Paolo



[Qemu-devel] qemu assertion failed with usb on current git master!

2012-02-23 Thread Erik Rull
 When running qemu with -device usb-host an assertion failed caused by
attaching a new usb device to the host that gets routed to the guest.

The assertion that fails is:

qemu-system-x86_64: /home/erik/qemu/hw/usb.c:358 usb_packet_complete:
Assertion 'p-state == USB_PACKET_QUEUED' failed.

It was working with the master ~1-2 weeks ago.

Best regards,

Erik



Re: [Qemu-devel] arm-linux-user, i386-linux-user: Make QEMU act as TCG compiler

2012-02-23 Thread Rajat Goyal
QEMU as a dynamic translator is already available. This adds extra
functionality to QEMU. I needed to do this since I wanted to explore the
ARM memory model over TCG micro-operations; so I needed translation of the
whole binary and not just the parts which QEMU needs to execute. Don't know
if others would find this feature useful.

Rajat.

On Thu, Feb 23, 2012 at 3:57 AM, 陳韋任 che...@iis.sinica.edu.tw wrote:

 Hi Rajat,

  Great work! It seems this is a kind of like static compilation, right? I
 think
 people are more interested in using QEMU as a dynamic translator as a
 library.
 Would you mind to tell me what scenario your work aims to?

 Regards,
 chenwj

 --
 Wei-Ren Chen (陳韋任)
 Computer Systems Lab, Institute of Information Science,
 Academia Sinica, Taiwan (R.O.C.)
 Tel:886-2-2788-3799 #1667
 Homepage: http://people.cs.nctu.edu.tw/~chenwj



[Qemu-devel] [Bug 939437] [NEW] spice is not supported by this qemu build.(ubuntu 12.04)

2012-02-23 Thread qpine
Public bug reported:

$ kvm -spice port=5900,addr=127.0.0.1,disable-ticketing
kvm: -spice port=5900,addr=127.0.0.1,disable-ticketing: there is no option 
group spice
spice is not supported by this qemu build.

$ kvm -version
QEMU emulator version 1.0 (qemu-kvm-1.0), Copyright (c) 2003-2008 Fabrice 
Bellard

** Affects: qemu
 Importance: Undecided
 Status: New

-- 
You received this bug notification because you are a member of qemu-
devel-ml, which is subscribed to QEMU.
https://bugs.launchpad.net/bugs/939437

Title:
  spice is not supported by this qemu build.(ubuntu 12.04)

Status in QEMU:
  New

Bug description:
  $ kvm -spice port=5900,addr=127.0.0.1,disable-ticketing
  kvm: -spice port=5900,addr=127.0.0.1,disable-ticketing: there is no option 
group spice
  spice is not supported by this qemu build.

  $ kvm -version
  QEMU emulator version 1.0 (qemu-kvm-1.0), Copyright (c) 2003-2008 Fabrice 
Bellard

To manage notifications about this bug go to:
https://bugs.launchpad.net/qemu/+bug/939437/+subscriptions



[Qemu-devel] [Bug 939443] [NEW] qemu-system-x86_64 can no support 1366x768

2012-02-23 Thread qpine
Public bug reported:

My laptop resolution is 1366x768, but can not support at -vga vmware the
-vga std.

$ kvm -version
QEMU emulator version 1.0 (qemu-kvm-1.0), Copyright (c) 2003-2008 Fabrice 
Bellard

** Affects: qemu
 Importance: Undecided
 Status: New

-- 
You received this bug notification because you are a member of qemu-
devel-ml, which is subscribed to QEMU.
https://bugs.launchpad.net/bugs/939443

Title:
  qemu-system-x86_64 can no support 1366x768

Status in QEMU:
  New

Bug description:
  My laptop resolution is 1366x768, but can not support at -vga vmware
  the -vga std.

  $ kvm -version
  QEMU emulator version 1.0 (qemu-kvm-1.0), Copyright (c) 2003-2008 Fabrice 
Bellard

To manage notifications about this bug go to:
https://bugs.launchpad.net/qemu/+bug/939443/+subscriptions



Re: [Qemu-devel] [PATCH 5/5] qmp: add DEVICE_TRAY_MOVED event

2012-02-23 Thread Luiz Capitulino
On Thu, 23 Feb 2012 08:50:08 +0100
Markus Armbruster arm...@redhat.com wrote:

 Kevin Wolf kw...@redhat.com writes:
 
  Am 17.02.2012 20:21, schrieb Luiz Capitulino:
  It's emitted whenever the tray is moved by the guest or by HMP/QMP
  commands.
  
  Signed-off-by: Luiz Capitulino lcapitul...@redhat.com
  ---
   QMP/qmp-events.txt |   18 ++
   block.c|   24 
   monitor.c  |3 +++
   monitor.h  |1 +
   4 files changed, 46 insertions(+), 0 deletions(-)
  
  diff --git a/QMP/qmp-events.txt b/QMP/qmp-events.txt
  index 06cb404..9286af5 100644
  --- a/QMP/qmp-events.txt
  +++ b/QMP/qmp-events.txt
  @@ -26,6 +26,24 @@ Example:
   Note: If action is stop, a STOP event will eventually follow the
   BLOCK_IO_ERROR event.
   
  +DEVICE_TRAY_MOVED
  +-
  +
  +It's emitted whenever the tray of a removable device is moved by the guest
  +or by HMP/QMP commands.
  +
  +Data:
  +
  +- device: device name (json-string)
 
  For me, a device name is something related to qdev. 'device' is a
  misnomer consistently used in all QMP commands so far and we can't fix
  it any more, but at least the documentation should clarify what is meant
  (that's for a follow-up patch).
 
 We can fix it if we really want to: rename, then add the old name as
 alias for backward compatibility.  Pick your favourite flavor of cruft.

I like it, new events won't have the cruft.



[Qemu-devel] git bisect results was: qemu assertion failed with usb on current git master!

2012-02-23 Thread Erik Rull
 Here the bisect results:


db4be873d312576c6971da15a38e056017a406b8 is the first bad commit
commit db4be873d312576c6971da15a38e056017a406b8
Author: Gerd Hoffmann kra...@redhat.com
Date:   Thu Jan 12 14:26:13 2012 +0100

usb: maintain async packet list per endpoint

Maintain a list of async packets per endpoint.  With the current code
the list will never receive more than a single item.  I think you can
guess what the future plan is though ;)

Signed-off-by: Gerd Hoffmann kra...@redhat.com

:04 04 3e8b1d868bd062aba0d2c10afa98e49a21eac26c
72c241e197c58e611a6fbab7cad50924dabfe4cc M  hw


git bisect start
# good: [ce3e14175ea36d851aede808fc8891313b91ec27] Fix vnc memory
corruption with width = 1400
git bisect good ce3e14175ea36d851aede808fc8891313b91ec27
# bad: [235fe3bfd46b1104575b540d0bc3fdf584030b99] qom: add test tools
git bisect bad 235fe3bfd46b1104575b540d0bc3fdf584030b99
# bad: [5d782e0805b4d216909b21883dcd513c3061aa3d] hw/a15mpcore.c: Add
Cortex-A15 private peripheral model
git bisect bad 5d782e0805b4d216909b21883dcd513c3061aa3d
# bad: [7718564ba1295f35188a5fb3ac8633c29d43b166] Merge remote-tracking
branch 'kraxel/usb.38' into staging
git bisect bad 7718564ba1295f35188a5fb3ac8633c29d43b166
# bad: [8c735e431d384663137a709c8207f4ada3146205] xhci: remote wakeup
support
git bisect bad 8c735e431d384663137a709c8207f4ada3146205
# good: [87e043f17e9b3781b3c29c02ff32abc23ac15708] usb-musb: switch to
usb_find_device()
git bisect good 87e043f17e9b3781b3c29c02ff32abc23ac15708
# bad: [db4be873d312576c6971da15a38e056017a406b8] usb: maintain async
packet list per endpoint
git bisect bad db4be873d312576c6971da15a38e056017a406b8
# good: [1977f93dacf60466cd23b562ae498446b77d3b48] usb: fold
usb_generic_handle_packet into usb_handle_packet
git bisect good 1977f93dacf60466cd23b562ae498446b77d3b48
# good: [63095ab54c1ce554b1fc825fc678394ccb129e5b] usb: add
USBEndpoint-{nr,pid}
git bisect good 63095ab54c1ce554b1fc825fc678394ccb129e5b
# good: [079d0b7f1eedcc634c371fe05b617fdc55c8b762] usb: Set USBEndpoint in
usb_packet_setup().
git bisect good 079d0b7f1eedcc634c371fe05b617fdc55c8b762

Best regards,

Erik



[Qemu-devel] [PATCH v6 01/12] acpi: move around structs

2012-02-23 Thread Gerd Hoffmann
Group all structs at the top of hw/acpi.h.
Just moving around lines, no code changes.

Signed-off-by: Gerd Hoffmann kra...@redhat.com
---
 hw/acpi.h |   48 +++-
 1 files changed, 23 insertions(+), 25 deletions(-)

diff --git a/hw/acpi.h b/hw/acpi.h
index c141e65..5c43b7d 100644
--- a/hw/acpi.h
+++ b/hw/acpi.h
@@ -73,9 +73,11 @@
 /* PM2_CNT */
 #define ACPI_BITMASK_ARB_DISABLE0x0001
 
-/* PM_TMR */
-struct ACPIPMTimer;
+/* structs */
 typedef struct ACPIPMTimer ACPIPMTimer;
+typedef struct ACPIPM1EVT ACPIPM1EVT;
+typedef struct ACPIPM1CNT ACPIPM1CNT;
+typedef struct ACPIGPE ACPIGPE;
 
 typedef void (*acpi_update_sci_fn)(ACPIPMTimer *tmr);
 
@@ -86,6 +88,25 @@ struct ACPIPMTimer {
 acpi_update_sci_fn update_sci;
 };
 
+struct ACPIPM1EVT {
+uint16_t sts;
+uint16_t en;
+};
+
+struct ACPIPM1CNT {
+uint16_t cnt;
+qemu_irq cmos_s3;
+};
+
+struct ACPIGPE {
+uint32_t blk;
+uint8_t len;
+
+uint8_t *sts;
+uint8_t *en;
+};
+
+/* PM_TMR */
 void acpi_pm_tmr_update(ACPIPMTimer *tmr, bool enable);
 void acpi_pm_tmr_calc_overflow_time(ACPIPMTimer *tmr);
 uint32_t acpi_pm_tmr_get(ACPIPMTimer *tmr);
@@ -100,26 +121,12 @@ static inline int64_t acpi_pm_tmr_get_clock(void)
 }
 
 /* PM1a_EVT: piix and ich9 don't implement PM1b. */
-struct ACPIPM1EVT
-{
-uint16_t sts;
-uint16_t en;
-};
-typedef struct ACPIPM1EVT ACPIPM1EVT;
-
 uint16_t acpi_pm1_evt_get_sts(ACPIPM1EVT *pm1, int64_t overflow_time);
 void acpi_pm1_evt_write_sts(ACPIPM1EVT *pm1, ACPIPMTimer *tmr, uint16_t val);
 void acpi_pm1_evt_power_down(ACPIPM1EVT *pm1, ACPIPMTimer *tmr);
 void acpi_pm1_evt_reset(ACPIPM1EVT *pm1);
 
 /* PM1a_CNT: piix and ich9 don't implement PM1b CNT. */
-struct ACPIPM1CNT {
-uint16_t cnt;
-
-qemu_irq cmos_s3;
-};
-typedef struct ACPIPM1CNT ACPIPM1CNT;
-
 void acpi_pm1_cnt_init(ACPIPM1CNT *pm1_cnt, qemu_irq cmos_s3);
 void acpi_pm1_cnt_write(ACPIPM1EVT *pm1a, ACPIPM1CNT *pm1_cnt, uint16_t val);
 void acpi_pm1_cnt_update(ACPIPM1CNT *pm1_cnt,
@@ -127,15 +134,6 @@ void acpi_pm1_cnt_update(ACPIPM1CNT *pm1_cnt,
 void acpi_pm1_cnt_reset(ACPIPM1CNT *pm1_cnt);
 
 /* GPE0 */
-struct ACPIGPE {
-uint32_t blk;
-uint8_t len;
-
-uint8_t *sts;
-uint8_t *en;
-};
-typedef struct ACPIGPE ACPIGPE;
-
 void acpi_gpe_init(ACPIGPE *gpe, uint8_t len);
 void acpi_gpe_blk(ACPIGPE *gpe, uint32_t blk);
 void acpi_gpe_reset(ACPIGPE *gpe);
-- 
1.7.1




[Qemu-devel] [PATCH v6 00/12] initial suspend support

2012-02-23 Thread Gerd Hoffmann
  Hi,

Next round, dropping the wakeup reason from the wakeup qmp event and
improving monitor command description in the josn schema.

cheers,
  Gerd

The following changes since commit 235fe3bfd46b1104575b540d0bc3fdf584030b99:

  qom: add test tools (2012-02-22 12:18:26 -0600)

are available in the git repository at:
  git://git.kraxel.org/qemu suspend.2

Gerd Hoffmann (12):
  acpi: move around structs
  acpi: add ACPIREGS
  acpi: don't pass overflow_time to acpi_pm1_evt_get_sts
  acpi: add acpi_pm1_evt_write_en
  suspend: add infrastructure
  suspend: switch acpi s3 to new infrastructure.
  suspend: add system_wakeup monitor command
  suspend: make ps/2 devices wakeup the guest
  suspend: make serial ports wakeup the guest.
  suspend: make rtc alarm wakeup the guest.
  suspend: make acpi timer wakeup the guest.
  suspend: add qmp events

 hmp-commands.hx  |   14 +
 hmp.c|5 ++
 hmp.h|1 +
 hw/acpi.c|  172 +++---
 hw/acpi.h|   93 -
 hw/acpi_piix4.c  |   70 ++
 hw/mc146818rtc.c |   13 
 hw/mips_malta.c  |2 +-
 hw/pc.c  |   11 
 hw/pc.h  |3 +-
 hw/pc_piix.c |8 +--
 hw/ps2.c |6 ++
 hw/serial.c  |6 ++
 hw/vt82c686.c|   42 ++---
 monitor.c|6 ++
 monitor.h|2 +
 qapi-schema.json |   11 
 qmp-commands.hx  |   21 +++
 qmp.c|5 ++
 sysemu.h |   11 
 vl.c |   69 ++
 xen-all.c|   11 ++--
 22 files changed, 383 insertions(+), 199 deletions(-)



[Qemu-devel] [PATCH v6 04/12] acpi: add acpi_pm1_evt_write_en

2012-02-23 Thread Gerd Hoffmann
Do APCIREGS-pm1.evt.en updates using the new acpi_pm1_evt_write_en
function, so the acpi code will see those updates.

Signed-off-by: Gerd Hoffmann kra...@redhat.com
---
 hw/acpi.c   |5 +
 hw/acpi.h   |1 +
 hw/acpi_piix4.c |2 +-
 hw/vt82c686.c   |2 +-
 4 files changed, 8 insertions(+), 2 deletions(-)

diff --git a/hw/acpi.c b/hw/acpi.c
index 1129335..407949b 100644
--- a/hw/acpi.c
+++ b/hw/acpi.c
@@ -268,6 +268,11 @@ void acpi_pm1_evt_write_sts(ACPIREGS *ar, uint16_t val)
 ar-pm1.evt.sts = ~val;
 }
 
+void acpi_pm1_evt_write_en(ACPIREGS *ar, uint16_t val)
+{
+ar-pm1.evt.en = val;
+}
+
 void acpi_pm1_evt_power_down(ACPIREGS *ar)
 {
 if (ar-pm1.evt.en  ACPI_BITMASK_POWER_BUTTON_ENABLE) {
diff --git a/hw/acpi.h b/hw/acpi.h
index e1d5e3b..88f8051 100644
--- a/hw/acpi.h
+++ b/hw/acpi.h
@@ -133,6 +133,7 @@ static inline int64_t acpi_pm_tmr_get_clock(void)
 /* PM1a_EVT: piix and ich9 don't implement PM1b. */
 uint16_t acpi_pm1_evt_get_sts(ACPIREGS *ar);
 void acpi_pm1_evt_write_sts(ACPIREGS *ar, uint16_t val);
+void acpi_pm1_evt_write_en(ACPIREGS *ar, uint16_t val);
 void acpi_pm1_evt_power_down(ACPIREGS *ar);
 void acpi_pm1_evt_reset(ACPIREGS *ar);
 
diff --git a/hw/acpi_piix4.c b/hw/acpi_piix4.c
index 5b16d20..1641229 100644
--- a/hw/acpi_piix4.c
+++ b/hw/acpi_piix4.c
@@ -117,7 +117,7 @@ static void pm_ioport_write(IORange *ioport, uint64_t addr, 
unsigned width,
 pm_update_sci(s);
 break;
 case 0x02:
-s-ar.pm1.evt.en = val;
+acpi_pm1_evt_write_en(s-ar, val);
 pm_update_sci(s);
 break;
 case 0x04:
diff --git a/hw/vt82c686.c b/hw/vt82c686.c
index 1b083de..a53bd8a 100644
--- a/hw/vt82c686.c
+++ b/hw/vt82c686.c
@@ -206,7 +206,7 @@ static void pm_ioport_writew(void *opaque, uint32_t addr, 
uint32_t val)
 pm_update_sci(s);
 break;
 case 0x02:
-s-ar.pm1.evt.en = val;
+acpi_pm1_evt_write_en(s-ar, val);
 pm_update_sci(s);
 break;
 case 0x04:
-- 
1.7.1




[Qemu-devel] [PATCH v6 06/12] suspend: switch acpi s3 to new infrastructure.

2012-02-23 Thread Gerd Hoffmann
This patch switches pc s3 suspend over to the new infrastructure.
The cmos_s3 qemu_irq is killed, the new notifier is used instead.
The xen hack goes away with that too, the hypercall can simply be
done in a notifier function now.

This patch also makes the guest actually stay suspended instead
of leaving suspend instantly, so it is useful for more than just
testing whenever the suspend/resume cycle actually works.

Signed-off-by: Gerd Hoffmann kra...@redhat.com
---
 hw/acpi.c|   32 +---
 hw/acpi.h|4 ++--
 hw/acpi_piix4.c  |4 ++--
 hw/mc146818rtc.c |   12 
 hw/mips_malta.c  |2 +-
 hw/pc.c  |   11 ---
 hw/pc.h  |3 +--
 hw/pc_piix.c |8 +---
 hw/vt82c686.c|2 +-
 xen-all.c|   11 ++-
 10 files changed, 47 insertions(+), 42 deletions(-)

diff --git a/hw/acpi.c b/hw/acpi.c
index 407949b..7b16716 100644
--- a/hw/acpi.c
+++ b/hw/acpi.c
@@ -248,6 +248,22 @@ int acpi_table_add(const char *t)
 
 }
 
+static void acpi_notify_wakeup(Notifier *notifier, void *data)
+{
+ACPIREGS *ar = container_of(notifier, ACPIREGS, wakeup);
+WakeupReason *reason = data;
+
+switch (*reason) {
+case QEMU_WAKEUP_REASON_OTHER:
+default:
+/* ACPI_BITMASK_WAKE_STATUS should be set on resume.
+   Pretend that resume was caused by power button */
+ar-pm1.evt.sts |=
+(ACPI_BITMASK_WAKE_STATUS | ACPI_BITMASK_POWER_BUTTON_STATUS);
+break;
+}
+}
+
 /* ACPI PM1a EVT */
 uint16_t acpi_pm1_evt_get_sts(ACPIREGS *ar)
 {
@@ -333,9 +349,10 @@ void acpi_pm_tmr_reset(ACPIREGS *ar)
 }
 
 /* ACPI PM1aCNT */
-void acpi_pm1_cnt_init(ACPIREGS *ar, qemu_irq cmos_s3)
+void acpi_pm1_cnt_init(ACPIREGS *ar)
 {
-ar-pm1.cnt.cmos_s3 = cmos_s3;
+ar-wakeup.notify = acpi_notify_wakeup;
+qemu_register_wakeup_notifier(ar-wakeup);
 }
 
 void acpi_pm1_cnt_write(ACPIREGS *ar, uint16_t val)
@@ -350,12 +367,8 @@ void acpi_pm1_cnt_write(ACPIREGS *ar, uint16_t val)
 qemu_system_shutdown_request();
 break;
 case 1:
-/* ACPI_BITMASK_WAKE_STATUS should be set on resume.
-   Pretend that resume was caused by power button */
-ar-pm1.evt.sts |=
-(ACPI_BITMASK_WAKE_STATUS | ACPI_BITMASK_POWER_BUTTON_STATUS);
-qemu_system_reset_request();
-qemu_irq_raise(ar-pm1.cnt.cmos_s3);
+qemu_system_suspend_request();
+break;
 default:
 break;
 }
@@ -376,9 +389,6 @@ void acpi_pm1_cnt_update(ACPIREGS *ar,
 void acpi_pm1_cnt_reset(ACPIREGS *ar)
 {
 ar-pm1.cnt.cnt = 0;
-if (ar-pm1.cnt.cmos_s3) {
-qemu_irq_lower(ar-pm1.cnt.cmos_s3);
-}
 }
 
 /* ACPI GPE */
diff --git a/hw/acpi.h b/hw/acpi.h
index 88f8051..fe8cdb4 100644
--- a/hw/acpi.h
+++ b/hw/acpi.h
@@ -96,7 +96,6 @@ struct ACPIPM1EVT {
 
 struct ACPIPM1CNT {
 uint16_t cnt;
-qemu_irq cmos_s3;
 };
 
 struct ACPIGPE {
@@ -114,6 +113,7 @@ struct ACPIREGS {
 ACPIPM1EVT  evt;
 ACPIPM1CNT  cnt;
 } pm1;
+Notifier wakeup;
 };
 
 /* PM_TMR */
@@ -138,7 +138,7 @@ void acpi_pm1_evt_power_down(ACPIREGS *ar);
 void acpi_pm1_evt_reset(ACPIREGS *ar);
 
 /* PM1a_CNT: piix and ich9 don't implement PM1b CNT. */
-void acpi_pm1_cnt_init(ACPIREGS *ar, qemu_irq cmos_s3);
+void acpi_pm1_cnt_init(ACPIREGS *ar);
 void acpi_pm1_cnt_write(ACPIREGS *ar, uint16_t val);
 void acpi_pm1_cnt_update(ACPIREGS *ar,
  bool sci_enable, bool sci_disable);
diff --git a/hw/acpi_piix4.c b/hw/acpi_piix4.c
index 1641229..797ed24 100644
--- a/hw/acpi_piix4.c
+++ b/hw/acpi_piix4.c
@@ -372,7 +372,7 @@ static int piix4_pm_initfn(PCIDevice *dev)
 }
 
 i2c_bus *piix4_pm_init(PCIBus *bus, int devfn, uint32_t smb_io_base,
-   qemu_irq sci_irq, qemu_irq cmos_s3, qemu_irq smi_irq,
+   qemu_irq sci_irq, qemu_irq smi_irq,
int kvm_enabled)
 {
 PCIDevice *dev;
@@ -383,7 +383,7 @@ i2c_bus *piix4_pm_init(PCIBus *bus, int devfn, uint32_t 
smb_io_base,
 
 s = DO_UPCAST(PIIX4PMState, dev, dev);
 s-irq = sci_irq;
-acpi_pm1_cnt_init(s-ar, cmos_s3);
+acpi_pm1_cnt_init(s-ar);
 s-smi_irq = smi_irq;
 s-kvm_enabled = kvm_enabled;
 
diff --git a/hw/mc146818rtc.c b/hw/mc146818rtc.c
index 6c1ad38..ee7a02f 100644
--- a/hw/mc146818rtc.c
+++ b/hw/mc146818rtc.c
@@ -102,6 +102,7 @@ typedef struct RTCState {
 QEMUTimer *second_timer2;
 Notifier clock_reset_notifier;
 LostTickPolicy lost_tick_policy;
+Notifier suspend_notifier;
 } RTCState;
 
 static void rtc_set_time(RTCState *s);
@@ -596,6 +597,14 @@ static void rtc_notify_clock_reset(Notifier *notifier, 
void *data)
 #endif
 }
 
+/* set CMOS shutdown status register (index 0xF) as S3_resume(0xFE)
+   BIOS will read it and start S3 resume at POST Entry */
+static void rtc_notify_suspend(Notifier *notifier, void *data)
+{
+

[Qemu-devel] [PATCH v6 08/12] suspend: make ps/2 devices wakeup the guest

2012-02-23 Thread Gerd Hoffmann
This patch adds wakeup support to ps/2 emulation.  Any key press on the
ps/2 keyboard will wakeup the guest.  Likewise any mouse button press
will wakeup the guest.  Mouse moves are ignored, so the guest will not
wakeup in case your mouse crosses the vnc window of a suspended guest by
accident.

Signed-off-by: Gerd Hoffmann kra...@redhat.com
---
 hw/ps2.c |6 ++
 1 files changed, 6 insertions(+), 0 deletions(-)

diff --git a/hw/ps2.c b/hw/ps2.c
index 1d9057b..b1a67bc 100644
--- a/hw/ps2.c
+++ b/hw/ps2.c
@@ -24,6 +24,7 @@
 #include hw.h
 #include ps2.h
 #include console.h
+#include sysemu.h
 
 /* debug PC keyboard */
 //#define DEBUG_KBD
@@ -154,6 +155,7 @@ static void ps2_put_keycode(void *opaque, int keycode)
 {
 PS2KbdState *s = opaque;
 
+qemu_system_wakeup_request(QEMU_WAKEUP_REASON_OTHER);
 /* XXX: add support for scancode set 1 */
 if (!s-translate  keycode  0xe0  s-scancode_set  1) {
 if (keycode  0x80) {
@@ -368,6 +370,10 @@ static void ps2_mouse_event(void *opaque,
return;
 s-mouse_buttons = buttons_state;
 
+if (buttons_state) {
+qemu_system_wakeup_request(QEMU_WAKEUP_REASON_OTHER);
+}
+
 if (!(s-mouse_status  MOUSE_STATUS_REMOTE) 
 (s-common.queue.count  (PS2_QUEUE_SIZE - 16))) {
 for(;;) {
-- 
1.7.1




[Qemu-devel] [PATCH v6 07/12] suspend: add system_wakeup monitor command

2012-02-23 Thread Gerd Hoffmann
This patch adds the system_wakeup monitor command which will simply
wake up suspended guests.

Signed-off-by: Gerd Hoffmann kra...@redhat.com
---
 hmp-commands.hx  |   14 ++
 hmp.c|5 +
 hmp.h|1 +
 qapi-schema.json |   11 +++
 qmp-commands.hx  |   21 +
 qmp.c|5 +
 6 files changed, 57 insertions(+), 0 deletions(-)

diff --git a/hmp-commands.hx b/hmp-commands.hx
index 573b823..64b3656 100644
--- a/hmp-commands.hx
+++ b/hmp-commands.hx
@@ -352,6 +352,20 @@ Resume emulation.
 ETEXI
 
 {
+.name   = system_wakeup,
+.args_type  = ,
+.params = ,
+.help   = wakeup guest from suspend,
+.mhandler.cmd = hmp_system_wakeup,
+},
+
+STEXI
+@item system_wakeup
+@findex system_wakeup
+Wakeup guest from suspend.
+ETEXI
+
+{
 .name   = gdbserver,
 .args_type  = device:s?,
 .params = [device],
diff --git a/hmp.c b/hmp.c
index 8ff8c94..3a54455 100644
--- a/hmp.c
+++ b/hmp.c
@@ -632,6 +632,11 @@ void hmp_cont(Monitor *mon, const QDict *qdict)
 }
 }
 
+void hmp_system_wakeup(Monitor *mon, const QDict *qdict)
+{
+qmp_system_wakeup(NULL);
+}
+
 void hmp_inject_nmi(Monitor *mon, const QDict *qdict)
 {
 Error *errp = NULL;
diff --git a/hmp.h b/hmp.h
index 18eecbd..5409464 100644
--- a/hmp.h
+++ b/hmp.h
@@ -41,6 +41,7 @@ void hmp_cpu(Monitor *mon, const QDict *qdict);
 void hmp_memsave(Monitor *mon, const QDict *qdict);
 void hmp_pmemsave(Monitor *mon, const QDict *qdict);
 void hmp_cont(Monitor *mon, const QDict *qdict);
+void hmp_system_wakeup(Monitor *mon, const QDict *qdict);
 void hmp_inject_nmi(Monitor *mon, const QDict *qdict);
 void hmp_set_link(Monitor *mon, const QDict *qdict);
 void hmp_block_passwd(Monitor *mon, const QDict *qdict);
diff --git a/qapi-schema.json b/qapi-schema.json
index d02ee86..d0b6792 100644
--- a/qapi-schema.json
+++ b/qapi-schema.json
@@ -999,6 +999,17 @@
 { 'command': 'cont' }
 
 ##
+# @system_wakeup:
+#
+# Wakeup guest from suspend.  Does nothing in case the guest isn't suspended.
+#
+# Since:  1.1
+#
+# Returns:  nothing.
+##
+{ 'command': 'system_wakeup' }
+
+##
 # @inject-nmi:
 #
 # Injects an Non-Maskable Interrupt into all guest's VCPUs.
diff --git a/qmp-commands.hx b/qmp-commands.hx
index dee95f1..705f704 100644
--- a/qmp-commands.hx
+++ b/qmp-commands.hx
@@ -212,6 +212,27 @@ Example:
 EQMP
 
 {
+.name   = system_wakeup,
+.args_type  = ,
+.mhandler.cmd_new = qmp_marshal_input_system_wakeup,
+},
+
+SQMP
+system_wakeup
+-
+
+Wakeup guest from suspend.
+
+Arguments: None.
+
+Example:
+
+- { execute: system_wakeup }
+- { return: {} }
+
+EQMP
+
+{
 .name   = system_reset,
 .args_type  = ,
 .mhandler.cmd_new = qmp_marshal_input_system_reset,
diff --git a/qmp.c b/qmp.c
index 1f64844..a182b51 100644
--- a/qmp.c
+++ b/qmp.c
@@ -163,6 +163,11 @@ void qmp_cont(Error **errp)
 vm_start();
 }
 
+void qmp_system_wakeup(Error **errp)
+{
+qemu_system_wakeup_request(QEMU_WAKEUP_REASON_OTHER);
+}
+
 ObjectPropertyInfoList *qmp_qom_list(const char *path, Error **errp)
 {
 Object *obj;
-- 
1.7.1




[Qemu-devel] [PATCH v6 09/12] suspend: make serial ports wakeup the guest.

2012-02-23 Thread Gerd Hoffmann
Add a 'wakeup' property to the serial port.  It is off by default.  When
enabled any incoming character on the serial line will wake up the
guest.  Useful for guests which have a serial console configured.

Signed-off-by: Gerd Hoffmann kra...@redhat.com
---
 hw/serial.c |6 ++
 1 files changed, 6 insertions(+), 0 deletions(-)

diff --git a/hw/serial.c b/hw/serial.c
index 144d1b3..c0ee55d 100644
--- a/hw/serial.c
+++ b/hw/serial.c
@@ -139,6 +139,7 @@ struct SerialState {
 int it_shift;
 int baudbase;
 int tsr_retry;
+uint32_t wakeup;
 
 uint64_t last_xmit_ts;  /* Time when the last byte was 
successfully sent out of the tsr */
 SerialFIFO recv_fifo;
@@ -635,6 +636,10 @@ static int serial_can_receive1(void *opaque)
 static void serial_receive1(void *opaque, const uint8_t *buf, int size)
 {
 SerialState *s = opaque;
+
+if (s-wakeup) {
+qemu_system_wakeup_request(QEMU_WAKEUP_REASON_OTHER);
+}
 if(s-fcr  UART_FCR_FE) {
 int i;
 for (i = 0; i  size; i++) {
@@ -884,6 +889,7 @@ static Property serial_isa_properties[] = {
 DEFINE_PROP_HEX32(iobase, ISASerialState, iobase,  -1),
 DEFINE_PROP_UINT32(irq,   ISASerialState, isairq,  -1),
 DEFINE_PROP_CHR(chardev,  ISASerialState, state.chr),
+DEFINE_PROP_UINT32(wakeup, ISASerialState, state.wakeup, 0),
 DEFINE_PROP_END_OF_LIST(),
 };
 
-- 
1.7.1




[Qemu-devel] [PATCH v6 12/12] suspend: add qmp events

2012-02-23 Thread Gerd Hoffmann
Send qmp events on suspend and wakeup so libvirt
has a chance to track the vm state.

Signed-off-by: Gerd Hoffmann kra...@redhat.com
---
 monitor.c |6 ++
 monitor.h |2 ++
 vl.c  |2 ++
 3 files changed, 10 insertions(+), 0 deletions(-)

diff --git a/monitor.c b/monitor.c
index 0d4daad..248ef2a 100644
--- a/monitor.c
+++ b/monitor.c
@@ -485,6 +485,12 @@ void monitor_protocol_event(MonitorEvent event, QObject 
*data)
 case QEVENT_BLOCK_JOB_CANCELLED:
 event_name = BLOCK_JOB_CANCELLED;
 break;
+case QEVENT_SUSPEND:
+event_name = SUSPEND;
+break;
+case QEVENT_WAKEUP:
+event_name = WAKEUP;
+break;
 default:
 abort();
 break;
diff --git a/monitor.h b/monitor.h
index b72ea07..9df3bab 100644
--- a/monitor.h
+++ b/monitor.h
@@ -38,6 +38,8 @@ typedef enum MonitorEvent {
 QEVENT_SPICE_DISCONNECTED,
 QEVENT_BLOCK_JOB_COMPLETED,
 QEVENT_BLOCK_JOB_CANCELLED,
+QEVENT_SUSPEND,
+QEVENT_WAKEUP,
 QEVENT_MAX,
 } MonitorEvent;
 
diff --git a/vl.c b/vl.c
index ffc9a72..9ad44fd 100644
--- a/vl.c
+++ b/vl.c
@@ -1416,6 +1416,7 @@ static void qemu_system_suspend(void)
 {
 pause_all_vcpus();
 notifier_list_notify(suspend_notifiers, NULL);
+monitor_protocol_event(QEVENT_SUSPEND, NULL);
 is_suspended = true;
 }
 
@@ -1442,6 +1443,7 @@ void qemu_system_wakeup_request(WakeupReason reason)
 if (!(wakeup_reason_mask  (1  reason))) {
 return;
 }
+monitor_protocol_event(QEVENT_WAKEUP, NULL);
 notifier_list_notify(wakeup_notifiers, reason);
 reset_requested = 1;
 qemu_notify_event();
-- 
1.7.1




[Qemu-devel] [PATCH] ehci: fix reset

2012-02-23 Thread Gerd Hoffmann
Two reset fixes:
  * pick up s-usbcmd value after ehci_reset call to make sure it
keeps the reset value and doesn't get rubbish filled in when
val is written back to the mmio register array later on.
  * make sure the frame timer is zapped on reset.

Signed-off-by: Gerd Hoffmann kra...@redhat.com
---
 hw/usb-ehci.c |3 ++-
 1 files changed, 2 insertions(+), 1 deletions(-)

diff --git a/hw/usb-ehci.c b/hw/usb-ehci.c
index 6c01ca9..b908732 100644
--- a/hw/usb-ehci.c
+++ b/hw/usb-ehci.c
@@ -912,6 +912,7 @@ static void ehci_reset(void *opaque)
 }
 }
 ehci_queues_rip_all(s);
+qemu_del_timer(s-frame_timer);
 }
 
 static uint32_t ehci_mem_readb(void *ptr, target_phys_addr_t addr)
@@ -1070,7 +1071,7 @@ static void ehci_mem_writel(void *ptr, target_phys_addr_t 
addr, uint32_t val)
 
 if (val  USBCMD_HCRESET) {
 ehci_reset(s);
-val = ~USBCMD_HCRESET;
+val = s-usbcmd;
 }
 
 /* not supporting dynamic frame list size at the moment */
-- 
1.7.1




Re: [Qemu-devel] [PATCH 2/2] build: replace librt check function

2012-02-23 Thread Roger Pau Monné
2012/2/22 Anthony Liguori anth...@codemonkey.ws:
 On 02/20/2012 06:11 AM, Roger Pau Monne wrote:

 Replace clock_gettime with timer_gettime, since at least under
 uclibc 0.9.33 the clock_getttime function can be used without linking
 against librt (although the manual page states the opposite).

 Signed-off-by: Roger Pau Monneroger@entel.upc.edu


 I don't think this is against qemu.git.  Please do not send patches to
 qemu-devel that are not against qemu.git without clearly indicating this.

Sorry, this is against qemu-xen-upstream, should I add a tag to my
patches and resend them to qemu-devel?

Thanks, Roger.

 Regards,

 Anthony Liguori


 ---
  configure |    3 ++-
  1 files changed, 2 insertions(+), 1 deletions(-)

 diff --git a/configure b/configure
 index 7bcd547..fb99632 100755
 --- a/configure
 +++ b/configure
 @@ -2438,7 +2438,8 @@ fi
  cat  $TMPCEOF
  #includesignal.h
  #includetime.h
 -int main(void) { clockid_t id; return clock_gettime(id, NULL); }
 +int main(void) { timer_t tid; struct itimerspec it; \
 +                 return timer_gettime(tid,it); }
  EOF

  if compile_prog   ; then





[Qemu-devel] [PATCH v6 03/12] acpi: don't pass overflow_time to acpi_pm1_evt_get_sts

2012-02-23 Thread Gerd Hoffmann
Pretty pointless, can easily be reached via ACPIREGS now.

Signed-off-by: Gerd Hoffmann kra...@redhat.com
---
 hw/acpi.c   |6 +++---
 hw/acpi.h   |2 +-
 hw/acpi_piix4.c |4 ++--
 hw/vt82c686.c   |4 ++--
 4 files changed, 8 insertions(+), 8 deletions(-)

diff --git a/hw/acpi.c b/hw/acpi.c
index 1922e53..1129335 100644
--- a/hw/acpi.c
+++ b/hw/acpi.c
@@ -249,10 +249,10 @@ int acpi_table_add(const char *t)
 }
 
 /* ACPI PM1a EVT */
-uint16_t acpi_pm1_evt_get_sts(ACPIREGS *ar, int64_t overflow_time)
+uint16_t acpi_pm1_evt_get_sts(ACPIREGS *ar)
 {
 int64_t d = acpi_pm_tmr_get_clock();
-if (d = overflow_time) {
+if (d = ar-tmr.overflow_time) {
 ar-pm1.evt.sts |= ACPI_BITMASK_TIMER_STATUS;
 }
 return ar-pm1.evt.sts;
@@ -260,7 +260,7 @@ uint16_t acpi_pm1_evt_get_sts(ACPIREGS *ar, int64_t 
overflow_time)
 
 void acpi_pm1_evt_write_sts(ACPIREGS *ar, uint16_t val)
 {
-uint16_t pm1_sts = acpi_pm1_evt_get_sts(ar, ar-tmr.overflow_time);
+uint16_t pm1_sts = acpi_pm1_evt_get_sts(ar);
 if (pm1_sts  val  ACPI_BITMASK_TIMER_STATUS) {
 /* if TMRSTS is reset, then compute the new overflow time */
 acpi_pm_tmr_calc_overflow_time(ar);
diff --git a/hw/acpi.h b/hw/acpi.h
index 530c86a..e1d5e3b 100644
--- a/hw/acpi.h
+++ b/hw/acpi.h
@@ -131,7 +131,7 @@ static inline int64_t acpi_pm_tmr_get_clock(void)
 }
 
 /* PM1a_EVT: piix and ich9 don't implement PM1b. */
-uint16_t acpi_pm1_evt_get_sts(ACPIREGS *ar, int64_t overflow_time);
+uint16_t acpi_pm1_evt_get_sts(ACPIREGS *ar);
 void acpi_pm1_evt_write_sts(ACPIREGS *ar, uint16_t val);
 void acpi_pm1_evt_power_down(ACPIREGS *ar);
 void acpi_pm1_evt_reset(ACPIREGS *ar);
diff --git a/hw/acpi_piix4.c b/hw/acpi_piix4.c
index 68d5eab..5b16d20 100644
--- a/hw/acpi_piix4.c
+++ b/hw/acpi_piix4.c
@@ -80,7 +80,7 @@ static void pm_update_sci(PIIX4PMState *s)
 {
 int sci_level, pmsts;
 
-pmsts = acpi_pm1_evt_get_sts(s-ar, s-ar.tmr.overflow_time);
+pmsts = acpi_pm1_evt_get_sts(s-ar);
 sci_level = (((pmsts  s-ar.pm1.evt.en) 
   (ACPI_BITMASK_RT_CLOCK_ENABLE |
ACPI_BITMASK_POWER_BUTTON_ENABLE |
@@ -138,7 +138,7 @@ static void pm_ioport_read(IORange *ioport, uint64_t addr, 
unsigned width,
 
 switch(addr) {
 case 0x00:
-val = acpi_pm1_evt_get_sts(s-ar, s-ar.tmr.overflow_time);
+val = acpi_pm1_evt_get_sts(s-ar);
 break;
 case 0x02:
 val = s-ar.pm1.evt.en;
diff --git a/hw/vt82c686.c b/hw/vt82c686.c
index c659283..1b083de 100644
--- a/hw/vt82c686.c
+++ b/hw/vt82c686.c
@@ -177,7 +177,7 @@ static void pm_update_sci(VT686PMState *s)
 {
 int sci_level, pmsts;
 
-pmsts = acpi_pm1_evt_get_sts(s-ar, s-ar.tmr.overflow_time);
+pmsts = acpi_pm1_evt_get_sts(s-ar);
 sci_level = (((pmsts  s-ar.pm1.evt.en) 
   (ACPI_BITMASK_RT_CLOCK_ENABLE |
ACPI_BITMASK_POWER_BUTTON_ENABLE |
@@ -226,7 +226,7 @@ static uint32_t pm_ioport_readw(void *opaque, uint32_t addr)
 addr = 0x0f;
 switch (addr) {
 case 0x00:
-val = acpi_pm1_evt_get_sts(s-ar, s-ar.tmr.overflow_time);
+val = acpi_pm1_evt_get_sts(s-ar);
 break;
 case 0x02:
 val = s-ar.pm1.evt.en;
-- 
1.7.1




[Qemu-devel] [PATCH v6 10/12] suspend: make rtc alarm wakeup the guest.

2012-02-23 Thread Gerd Hoffmann
Make the rtc wake up the guest when the alarm fires.
Add acpi windup to property support RTC_EN, so guests
can enable and disable this.

Signed-off-by: Gerd Hoffmann kra...@redhat.com
---
 hw/acpi.c|7 +++
 hw/mc146818rtc.c |1 +
 sysemu.h |1 +
 3 files changed, 9 insertions(+), 0 deletions(-)

diff --git a/hw/acpi.c b/hw/acpi.c
index 7b16716..c05dde6 100644
--- a/hw/acpi.c
+++ b/hw/acpi.c
@@ -254,6 +254,10 @@ static void acpi_notify_wakeup(Notifier *notifier, void 
*data)
 WakeupReason *reason = data;
 
 switch (*reason) {
+case QEMU_WAKEUP_REASON_RTC:
+ar-pm1.evt.sts |=
+(ACPI_BITMASK_WAKE_STATUS | ACPI_BITMASK_RT_CLOCK_STATUS);
+break;
 case QEMU_WAKEUP_REASON_OTHER:
 default:
 /* ACPI_BITMASK_WAKE_STATUS should be set on resume.
@@ -287,6 +291,8 @@ void acpi_pm1_evt_write_sts(ACPIREGS *ar, uint16_t val)
 void acpi_pm1_evt_write_en(ACPIREGS *ar, uint16_t val)
 {
 ar-pm1.evt.en = val;
+qemu_system_wakeup_enable(QEMU_WAKEUP_REASON_RTC,
+  val  ACPI_BITMASK_RT_CLOCK_ENABLE);
 }
 
 void acpi_pm1_evt_power_down(ACPIREGS *ar)
@@ -301,6 +307,7 @@ void acpi_pm1_evt_reset(ACPIREGS *ar)
 {
 ar-pm1.evt.sts = 0;
 ar-pm1.evt.en = 0;
+qemu_system_wakeup_enable(QEMU_WAKEUP_REASON_RTC, 0);
 }
 
 /* ACPI PM_TMR */
diff --git a/hw/mc146818rtc.c b/hw/mc146818rtc.c
index ee7a02f..a46fdfc 100644
--- a/hw/mc146818rtc.c
+++ b/hw/mc146818rtc.c
@@ -437,6 +437,7 @@ static void rtc_update_second2(void *opaque)
 
 s-cmos_data[RTC_REG_C] |= REG_C_AF;
 if (s-cmos_data[RTC_REG_B]  REG_B_AIE) {
+qemu_system_wakeup_request(QEMU_WAKEUP_REASON_RTC);
 qemu_irq_raise(s-irq);
 s-cmos_data[RTC_REG_C] |= REG_C_IRQF;
 }
diff --git a/sysemu.h b/sysemu.h
index af73813..781bdaf 100644
--- a/sysemu.h
+++ b/sysemu.h
@@ -40,6 +40,7 @@ void vm_stop_force_state(RunState state);
 
 typedef enum WakeupReason {
 QEMU_WAKEUP_REASON_OTHER = 0,
+QEMU_WAKEUP_REASON_RTC,
 } WakeupReason;
 
 void qemu_system_reset_request(void);
-- 
1.7.1




[Qemu-devel] [PATCH v6 11/12] suspend: make acpi timer wakeup the guest.

2012-02-23 Thread Gerd Hoffmann
Make the acpi timer wake up the guest.
Guests can enable/disable this via acpi too.

Signed-off-by: Gerd Hoffmann kra...@redhat.com
---
 hw/acpi.c |8 
 sysemu.h  |1 +
 2 files changed, 9 insertions(+), 0 deletions(-)

diff --git a/hw/acpi.c b/hw/acpi.c
index c05dde6..5d521e5 100644
--- a/hw/acpi.c
+++ b/hw/acpi.c
@@ -258,6 +258,10 @@ static void acpi_notify_wakeup(Notifier *notifier, void 
*data)
 ar-pm1.evt.sts |=
 (ACPI_BITMASK_WAKE_STATUS | ACPI_BITMASK_RT_CLOCK_STATUS);
 break;
+case QEMU_WAKEUP_REASON_PMTIMER:
+ar-pm1.evt.sts |=
+(ACPI_BITMASK_WAKE_STATUS | ACPI_BITMASK_TIMER_STATUS);
+break;
 case QEMU_WAKEUP_REASON_OTHER:
 default:
 /* ACPI_BITMASK_WAKE_STATUS should be set on resume.
@@ -293,6 +297,8 @@ void acpi_pm1_evt_write_en(ACPIREGS *ar, uint16_t val)
 ar-pm1.evt.en = val;
 qemu_system_wakeup_enable(QEMU_WAKEUP_REASON_RTC,
   val  ACPI_BITMASK_RT_CLOCK_ENABLE);
+qemu_system_wakeup_enable(QEMU_WAKEUP_REASON_PMTIMER,
+  val  ACPI_BITMASK_TIMER_ENABLE);
 }
 
 void acpi_pm1_evt_power_down(ACPIREGS *ar)
@@ -308,6 +314,7 @@ void acpi_pm1_evt_reset(ACPIREGS *ar)
 ar-pm1.evt.sts = 0;
 ar-pm1.evt.en = 0;
 qemu_system_wakeup_enable(QEMU_WAKEUP_REASON_RTC, 0);
+qemu_system_wakeup_enable(QEMU_WAKEUP_REASON_PMTIMER, 0);
 }
 
 /* ACPI PM_TMR */
@@ -340,6 +347,7 @@ uint32_t acpi_pm_tmr_get(ACPIREGS *ar)
 static void acpi_pm_tmr_timer(void *opaque)
 {
 ACPIREGS *ar = opaque;
+qemu_system_wakeup_request(QEMU_WAKEUP_REASON_PMTIMER);
 ar-tmr.update_sci(ar);
 }
 
diff --git a/sysemu.h b/sysemu.h
index 781bdaf..98118cc 100644
--- a/sysemu.h
+++ b/sysemu.h
@@ -41,6 +41,7 @@ void vm_stop_force_state(RunState state);
 typedef enum WakeupReason {
 QEMU_WAKEUP_REASON_OTHER = 0,
 QEMU_WAKEUP_REASON_RTC,
+QEMU_WAKEUP_REASON_PMTIMER,
 } WakeupReason;
 
 void qemu_system_reset_request(void);
-- 
1.7.1




[Qemu-devel] [PATCH v6 02/12] acpi: add ACPIREGS

2012-02-23 Thread Gerd Hoffmann
All those acpi structs are not independent from each other.
Various acpi functions expecting multiple acpi structs passed
in are a clean indicator for that ;)

So this patch bundles all acpi structs in the new ACPIREGS
struct, then use it everythere pass around acpi state.

Signed-off-by: Gerd Hoffmann kra...@redhat.com
---
 hw/acpi.c   |  130 +++
 hw/acpi.h   |   48 
 hw/acpi_piix4.c |   68 +---
 hw/vt82c686.c   |   42 -
 4 files changed, 145 insertions(+), 143 deletions(-)

diff --git a/hw/acpi.c b/hw/acpi.c
index 79b179b..1922e53 100644
--- a/hw/acpi.c
+++ b/hw/acpi.c
@@ -249,63 +249,61 @@ int acpi_table_add(const char *t)
 }
 
 /* ACPI PM1a EVT */
-uint16_t acpi_pm1_evt_get_sts(ACPIPM1EVT *pm1, int64_t overflow_time)
+uint16_t acpi_pm1_evt_get_sts(ACPIREGS *ar, int64_t overflow_time)
 {
 int64_t d = acpi_pm_tmr_get_clock();
 if (d = overflow_time) {
-pm1-sts |= ACPI_BITMASK_TIMER_STATUS;
+ar-pm1.evt.sts |= ACPI_BITMASK_TIMER_STATUS;
 }
-return pm1-sts;
+return ar-pm1.evt.sts;
 }
 
-void acpi_pm1_evt_write_sts(ACPIPM1EVT *pm1, ACPIPMTimer *tmr, uint16_t val)
+void acpi_pm1_evt_write_sts(ACPIREGS *ar, uint16_t val)
 {
-uint16_t pm1_sts = acpi_pm1_evt_get_sts(pm1, tmr-overflow_time);
+uint16_t pm1_sts = acpi_pm1_evt_get_sts(ar, ar-tmr.overflow_time);
 if (pm1_sts  val  ACPI_BITMASK_TIMER_STATUS) {
 /* if TMRSTS is reset, then compute the new overflow time */
-acpi_pm_tmr_calc_overflow_time(tmr);
+acpi_pm_tmr_calc_overflow_time(ar);
 }
-pm1-sts = ~val;
+ar-pm1.evt.sts = ~val;
 }
 
-void acpi_pm1_evt_power_down(ACPIPM1EVT *pm1, ACPIPMTimer *tmr)
+void acpi_pm1_evt_power_down(ACPIREGS *ar)
 {
-if (!pm1) {
-qemu_system_shutdown_request();
-} else if (pm1-en  ACPI_BITMASK_POWER_BUTTON_ENABLE) {
-pm1-sts |= ACPI_BITMASK_POWER_BUTTON_STATUS;
-tmr-update_sci(tmr);
+if (ar-pm1.evt.en  ACPI_BITMASK_POWER_BUTTON_ENABLE) {
+ar-pm1.evt.sts |= ACPI_BITMASK_POWER_BUTTON_STATUS;
+ar-tmr.update_sci(ar);
 }
 }
 
-void acpi_pm1_evt_reset(ACPIPM1EVT *pm1)
+void acpi_pm1_evt_reset(ACPIREGS *ar)
 {
-pm1-sts = 0;
-pm1-en = 0;
+ar-pm1.evt.sts = 0;
+ar-pm1.evt.en = 0;
 }
 
 /* ACPI PM_TMR */
-void acpi_pm_tmr_update(ACPIPMTimer *tmr, bool enable)
+void acpi_pm_tmr_update(ACPIREGS *ar, bool enable)
 {
 int64_t expire_time;
 
 /* schedule a timer interruption if needed */
 if (enable) {
-expire_time = muldiv64(tmr-overflow_time, get_ticks_per_sec(),
+expire_time = muldiv64(ar-tmr.overflow_time, get_ticks_per_sec(),
PM_TIMER_FREQUENCY);
-qemu_mod_timer(tmr-timer, expire_time);
+qemu_mod_timer(ar-tmr.timer, expire_time);
 } else {
-qemu_del_timer(tmr-timer);
+qemu_del_timer(ar-tmr.timer);
 }
 }
 
-void acpi_pm_tmr_calc_overflow_time(ACPIPMTimer *tmr)
+void acpi_pm_tmr_calc_overflow_time(ACPIREGS *ar)
 {
 int64_t d = acpi_pm_tmr_get_clock();
-tmr-overflow_time = (d + 0x80LL)  ~0x7fLL;
+ar-tmr.overflow_time = (d + 0x80LL)  ~0x7fLL;
 }
 
-uint32_t acpi_pm_tmr_get(ACPIPMTimer *tmr)
+uint32_t acpi_pm_tmr_get(ACPIREGS *ar)
 {
 uint32_t d = acpi_pm_tmr_get_clock();
 return d  0xff;
@@ -313,31 +311,31 @@ uint32_t acpi_pm_tmr_get(ACPIPMTimer *tmr)
 
 static void acpi_pm_tmr_timer(void *opaque)
 {
-ACPIPMTimer *tmr = opaque;
-tmr-update_sci(tmr);
+ACPIREGS *ar = opaque;
+ar-tmr.update_sci(ar);
 }
 
-void acpi_pm_tmr_init(ACPIPMTimer *tmr, acpi_update_sci_fn update_sci)
+void acpi_pm_tmr_init(ACPIREGS *ar, acpi_update_sci_fn update_sci)
 {
-tmr-update_sci = update_sci;
-tmr-timer = qemu_new_timer_ns(vm_clock, acpi_pm_tmr_timer, tmr);
+ar-tmr.update_sci = update_sci;
+ar-tmr.timer = qemu_new_timer_ns(vm_clock, acpi_pm_tmr_timer, ar);
 }
 
-void acpi_pm_tmr_reset(ACPIPMTimer *tmr)
+void acpi_pm_tmr_reset(ACPIREGS *ar)
 {
-tmr-overflow_time = 0;
-qemu_del_timer(tmr-timer);
+ar-tmr.overflow_time = 0;
+qemu_del_timer(ar-tmr.timer);
 }
 
 /* ACPI PM1aCNT */
-void acpi_pm1_cnt_init(ACPIPM1CNT *pm1_cnt, qemu_irq cmos_s3)
+void acpi_pm1_cnt_init(ACPIREGS *ar, qemu_irq cmos_s3)
 {
-pm1_cnt-cmos_s3 = cmos_s3;
+ar-pm1.cnt.cmos_s3 = cmos_s3;
 }
 
-void acpi_pm1_cnt_write(ACPIPM1EVT *pm1a, ACPIPM1CNT *pm1_cnt, uint16_t val)
+void acpi_pm1_cnt_write(ACPIREGS *ar, uint16_t val)
 {
-pm1_cnt-cnt = val  ~(ACPI_BITMASK_SLEEP_ENABLE);
+ar-pm1.cnt.cnt = val  ~(ACPI_BITMASK_SLEEP_ENABLE);
 
 if (val  ACPI_BITMASK_SLEEP_ENABLE) {
 /* change suspend type */
@@ -349,62 +347,62 @@ void acpi_pm1_cnt_write(ACPIPM1EVT *pm1a, ACPIPM1CNT 
*pm1_cnt, uint16_t val)
 case 1:
 /* ACPI_BITMASK_WAKE_STATUS should be set on resume.
Pretend that resume was caused by 

[Qemu-devel] [PATCH v1 1/1] ppc: Correctly define POWERPC_INSNS2_DEFAULT

2012-02-23 Thread Meador Inge
'POWERPC_INSNS2_DEFAULT' was defined incorrectly which was causing the
opcode table creation code to erroneously register 'eieio' and 'mbar'
for the default processor:

   ** ERROR: opcode 1a already assigned in opcode table 16
   *** ERROR: unable to insert opcode [1f-16-1a]
   *** ERROR initializing PowerPC instruction 0x1f 0x16 0x1a

Signed-off-by: Meador Inge mead...@codesourcery.com
---
 target-ppc/translate_init.c |4 ++--
 1 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/target-ppc/translate_init.c b/target-ppc/translate_init.c
index 6253076..6cb5fad 100644
--- a/target-ppc/translate_init.c
+++ b/target-ppc/translate_init.c
@@ -6713,7 +6713,7 @@ static void init_proc_620 (CPUPPCState *env)
 #if defined (TARGET_PPC64)  0 // XXX: TODO
 #define CPU_POWERPC_DEFAULTCPU_POWERPC_PPC64
 #define POWERPC_INSNS_DEFAULT  POWERPC_INSNS_PPC64
-#define POWERPC_INSNS2_DEFAULT POWERPC_INSNS_PPC64
+#define POWERPC_INSNS2_DEFAULT POWERPC_INSNS2_PPC64
 #define POWERPC_MSRM_DEFAULT   POWERPC_MSRM_PPC64
 #define POWERPC_MMU_DEFAULTPOWERPC_MMU_PPC64
 #define POWERPC_EXCP_DEFAULT   POWERPC_EXCP_PPC64
@@ -6725,7 +6725,7 @@ static void init_proc_620 (CPUPPCState *env)
 #else
 #define CPU_POWERPC_DEFAULTCPU_POWERPC_PPC32
 #define POWERPC_INSNS_DEFAULT  POWERPC_INSNS_PPC32
-#define POWERPC_INSNS2_DEFAULT POWERPC_INSNS_PPC32
+#define POWERPC_INSNS2_DEFAULT POWERPC_INSNS2_PPC32
 #define POWERPC_MSRM_DEFAULT   POWERPC_MSRM_PPC32
 #define POWERPC_MMU_DEFAULTPOWERPC_MMU_PPC32
 #define POWERPC_EXCP_DEFAULT   POWERPC_EXCP_PPC32
-- 
1.7.7.6




[Qemu-devel] [PATCH v6 05/12] suspend: add infrastructure

2012-02-23 Thread Gerd Hoffmann
This patch adds some infrastructure to handle suspend and resume to
qemu.  First there are two functions to switch state and second there
is a suspend notifier:

 * qemu_system_suspend_request is supposed to be called when the
   guest asks for being be suspended, for example via ACPI.

 * qemu_system_wakeup_request is supposed to be called on events
   which should wake up the guest.

 * qemu_register_suspend_notifier can be used to register a notifier
   which will be called when the guest is suspended.  Machine types
   and device models can hook in there to modify state if needed.

 * qemu_register_wakeup_notifier can be used to register a notifier
   which will be called when the guest is woken up.  Machine types
   and device models can hook in there to modify state if needed.

 * qemu_system_wakeup_enable can be used to enable/disable wakeup
   events.

Signed-off-by: Gerd Hoffmann kra...@redhat.com
---
 sysemu.h |9 
 vl.c |   67 ++
 2 files changed, 76 insertions(+), 0 deletions(-)

diff --git a/sysemu.h b/sysemu.h
index 9d5ce33..af73813 100644
--- a/sysemu.h
+++ b/sysemu.h
@@ -38,7 +38,16 @@ void vm_start(void);
 void vm_stop(RunState state);
 void vm_stop_force_state(RunState state);
 
+typedef enum WakeupReason {
+QEMU_WAKEUP_REASON_OTHER = 0,
+} WakeupReason;
+
 void qemu_system_reset_request(void);
+void qemu_system_suspend_request(void);
+void qemu_register_suspend_notifier(Notifier *notifier);
+void qemu_system_wakeup_request(WakeupReason reason);
+void qemu_system_wakeup_enable(WakeupReason reason, bool enabled);
+void qemu_register_wakeup_notifier(Notifier *notifier);
 void qemu_system_shutdown_request(void);
 void qemu_system_powerdown_request(void);
 void qemu_system_debug_request(void);
diff --git a/vl.c b/vl.c
index 7a8cc08..ffc9a72 100644
--- a/vl.c
+++ b/vl.c
@@ -1283,6 +1283,13 @@ static int shutdown_requested, shutdown_signal = -1;
 static pid_t shutdown_pid;
 static int powerdown_requested;
 static int debug_requested;
+static int suspend_requested;
+static bool is_suspended;
+static NotifierList suspend_notifiers =
+NOTIFIER_LIST_INITIALIZER(suspend_notifiers);
+static NotifierList wakeup_notifiers =
+NOTIFIER_LIST_INITIALIZER(wakeup_notifiers);
+static uint32_t wakeup_reason_mask = ~0;
 static RunState vmstop_requested = RUN_STATE_MAX;
 
 int qemu_shutdown_requested_get(void)
@@ -1325,6 +1332,13 @@ int qemu_reset_requested(void)
 return r;
 }
 
+static int qemu_suspend_requested(void)
+{
+int r = suspend_requested;
+suspend_requested = 0;
+return r;
+}
+
 int qemu_powerdown_requested(void)
 {
 int r = powerdown_requested;
@@ -1398,6 +1412,56 @@ void qemu_system_reset_request(void)
 qemu_notify_event();
 }
 
+static void qemu_system_suspend(void)
+{
+pause_all_vcpus();
+notifier_list_notify(suspend_notifiers, NULL);
+is_suspended = true;
+}
+
+void qemu_system_suspend_request(void)
+{
+if (is_suspended) {
+return;
+}
+suspend_requested = 1;
+cpu_stop_current();
+qemu_notify_event();
+}
+
+void qemu_register_suspend_notifier(Notifier *notifier)
+{
+notifier_list_add(suspend_notifiers, notifier);
+}
+
+void qemu_system_wakeup_request(WakeupReason reason)
+{
+if (!is_suspended) {
+return;
+}
+if (!(wakeup_reason_mask  (1  reason))) {
+return;
+}
+notifier_list_notify(wakeup_notifiers, reason);
+reset_requested = 1;
+qemu_notify_event();
+is_suspended = false;
+}
+
+void qemu_system_wakeup_enable(WakeupReason reason, bool enabled)
+{
+if (enabled) {
+wakeup_reason_mask |= (1  reason);
+} else {
+wakeup_reason_mask = ~(1  reason);
+}
+}
+
+void qemu_register_wakeup_notifier(Notifier *notifier)
+{
+notifier_list_add(wakeup_notifiers, notifier);
+}
+
 void qemu_system_killed(int signal, pid_t pid)
 {
 shutdown_signal = signal;
@@ -1438,6 +1502,9 @@ static bool main_loop_should_exit(void)
 if (qemu_debug_requested()) {
 vm_stop(RUN_STATE_DEBUG);
 }
+if (qemu_suspend_requested()) {
+qemu_system_suspend();
+}
 if (qemu_shutdown_requested()) {
 qemu_kill_report();
 monitor_protocol_event(QEVENT_SHUTDOWN, NULL);
-- 
1.7.1




Re: [Qemu-devel] [PATCH 0/5] VMState cleanups

2012-02-23 Thread Juan Quintela
Alexander Graf ag...@suse.de wrote:
 On 22.02.2012, at 17:09, Peter Maydell wrote:

 On 22 February 2012 16:04, Andreas Färber afaer...@suse.de wrote:
 Am 22.02.2012 16:42, schrieb Peter Maydell:
 On 22 February 2012 15:37, Andreas Färber afaer...@suse.de wrote:
 NB: Your cpu-vmstate patches were not applied so far and they appear to
 conflict with the plans we've made for redesigning cp15 on ARM: We want
 to convert today's static fields to some list and were hoping to have a
 mapping function for backwards compatibility. That works easiest in
 imperative code.
 
 I thought the idea for cp15 for vmstate was (like ppc) to basically
 have a uint32_t cp15_regs[512] which we save/load the whole of, and
 then the mapping function just assigns semantics to some subset
 of that array? vmstate can do a plain array without problems.
 
 I thought we had concluded that the (3+3+4+4)² or so registers were too
 large for that so that Alex suggested to leave the old load/save in
 place (but getting/setting through a mapping function) and dynamically
 appending only the new cp15 registers we don't have fields for yet when
 some arrive. Or so I've understood.
 
 So what I thought Alex was suggesting was to nuke the existing
 save/load, and instead we have this generic array. All the
 current env-cp15.c1_scr co turn from being uint32_t to uint32_t*,
 and there's an init function per CPU which maps those to point at
 slots in the cp15_regs[] array. Indexes into cp15_regs[] are
 just arbitrary (though they can't change for a particular CPU
 variant or you'd break migration).

 Yup. A nice side effect of this is that you have a known-small size of
 cp15_regs[]. But I suggested a lot of things during that discussion,
 so I quite frankly don't remember if that was the conclusion or just
 one idea ;)

I have to search that discussion, but I would like to send things as:

{ register_name, register value} array, otherwise inter-version
migration is just impossible (or very painful, that is similar).

Notice that this would also be very useful for x86 and MSR's.  Just now
we send every MSR ad-hock with a new position.

Later, Juan.



Re: [Qemu-devel] [PATCH 5/5] qmp: add DEVICE_TRAY_MOVED event

2012-02-23 Thread Markus Armbruster
Luiz Capitulino lcapitul...@redhat.com writes:

 On Thu, 23 Feb 2012 08:50:08 +0100
 Markus Armbruster arm...@redhat.com wrote:

 Kevin Wolf kw...@redhat.com writes:
 
  Am 17.02.2012 20:21, schrieb Luiz Capitulino:
  It's emitted whenever the tray is moved by the guest or by HMP/QMP
  commands.
  
  Signed-off-by: Luiz Capitulino lcapitul...@redhat.com
  ---
   QMP/qmp-events.txt |   18 ++
   block.c|   24 
   monitor.c  |3 +++
   monitor.h  |1 +
   4 files changed, 46 insertions(+), 0 deletions(-)
  
  diff --git a/QMP/qmp-events.txt b/QMP/qmp-events.txt
  index 06cb404..9286af5 100644
  --- a/QMP/qmp-events.txt
  +++ b/QMP/qmp-events.txt
  @@ -26,6 +26,24 @@ Example:
   Note: If action is stop, a STOP event will eventually follow the
   BLOCK_IO_ERROR event.
   
  +DEVICE_TRAY_MOVED
  +-
  +
  +It's emitted whenever the tray of a removable device is moved by the 
  guest
  +or by HMP/QMP commands.
  +
  +Data:
  +
  +- device: device name (json-string)
 
  For me, a device name is something related to qdev. 'device' is a
  misnomer consistently used in all QMP commands so far and we can't fix
  it any more, but at least the documentation should clarify what is meant
  (that's for a follow-up patch).
 
 We can fix it if we really want to: rename, then add the old name as
 alias for backward compatibility.  Pick your favourite flavor of cruft.

 I like it, new events won't have the cruft.

If we reserve device for device models, we need sensible names for
device backends.  One each for block, net and char.  There's some
precedence for blockdev, netdev, chardev, but they contain dev,
so there's still some overloading of the name device.  Better ideas?



Re: [Qemu-devel] [PATCH v4] qemu-ga: Add guest-network-info command

2012-02-23 Thread Luiz Capitulino
On Sun, 19 Feb 2012 12:15:43 +0100
Michal Privoznik mpriv...@redhat.com wrote:

 This command returns an array of:
 
  [ifname, ipaddr, ipaddr_family, prefix, hwaddr]
 
 for each interface in the system that has an IP address.
 Currently, only IPv4 and IPv6 are supported.
 
 Signed-off-by: Michal Privoznik mpriv...@redhat.com
 ---
 diff to v3:
 -use ctpop32() instead of separate count_one_bits()
 
 diff to v2:
 -Properly set IP addr family for IPv6
 
 diff to v1:
 -move from guest-getip to guest-network-info
 -replace black boxed algorithm for population count
 -several coding styles improvements
  qapi-schema-guest.json |   29 
  qga/guest-agent-commands.c |  157 
 
  2 files changed, 186 insertions(+), 0 deletions(-)
 
 diff --git a/qapi-schema-guest.json b/qapi-schema-guest.json
 index 5f8a18d..ca4fdc5 100644
 --- a/qapi-schema-guest.json
 +++ b/qapi-schema-guest.json
 @@ -219,3 +219,32 @@
  ##
  { 'command': 'guest-fsfreeze-thaw',
'returns': 'int' }
 +
 +##
 +# @guest-network-info:
 +#
 +# Get list of guest IP addresses, MAC addresses
 +# and netmasks.
 +#
 +# @name: The name of interface for which info are being delivered
 +#
 +# @ipaddr: IP address assigned to @name
 +#
 +# @ipaddrtype: Type of @ipaddr (e.g. ipv4, ipv6)
 +#
 +# @prefix: Network prefix length
 +#
 +# @hwaddr: Hardware address of @name
 +#
 +# Returns: List of GuestNetworkInfo on success.
 +#
 +# Since: 1.1
 +##
 +{ 'enum': 'GuestIpAddrType',
 +  'data': [ 'ipv4', 'ipv6' ] }
 +{ 'type': 'GuestNetworkInfo',
 +  'data': {'iface': {'name': 'str', 'ipaddr': 'str',
 + 'ipaddrtype': 'GuestIpAddrType',
 + 'prefix': 'int', 'hwaddr': 'str'} } }
 +{ 'command': 'guest-network-info',
 +  'returns': ['GuestNetworkInfo'] }

No need for short names like 'ipaddr', longer names like 'ip-address' are 
better.

Also, please, document the enum, the type and the command separately. You can 
look
for examples in the qapi-schema.json file (yes, we're not doing it in this 
file, but
we should).

Do we really need the 'iface' dict, btw?

 diff --git a/qga/guest-agent-commands.c b/qga/guest-agent-commands.c
 index a09c8ca..1371f8b 100644
 --- a/qga/guest-agent-commands.c
 +++ b/qga/guest-agent-commands.c
 @@ -5,6 +5,7 @@
   *
   * Authors:
   *  Michael Roth  mdr...@linux.vnet.ibm.com
 + *  Michal Privoznik  mpriv...@redhat.com
   *
   * This work is licensed under the terms of the GNU GPL, version 2 or later.
   * See the COPYING file in the top-level directory.
 @@ -23,10 +24,15 @@
  
  #include sys/types.h
  #include sys/ioctl.h
 +#include ifaddrs.h
 +#include arpa/inet.h
 +#include sys/socket.h
 +#include net/if.h
  #include qga/guest-agent-core.h
  #include qga-qmp-commands.h
  #include qerror.h
  #include qemu-queue.h
 +#include host-utils.h
  
  static GAState *ga_state;
  
 @@ -583,3 +589,154 @@ void ga_command_state_init(GAState *s, GACommandState 
 *cs)
  #endif
  ga_command_state_add(cs, guest_file_init, NULL);
  }
 +
 +/*
 + * Get the list of interfaces among with their
 + * IP/MAC addresses, prefixes and IP versions
 + */
 +GuestNetworkInfoList *qmp_guest_network_info(Error **err)
 +{
 +GuestNetworkInfoList *head = NULL, *cur_item = NULL;
 +struct ifaddrs *ifap = NULL, *ifa = NULL;
 +char err_msg[512];
 +
 +g_debug(guest-network-info called);
 +
 +if (getifaddrs(ifap)  0) {
 +snprintf(err_msg, sizeof(err_msg),
 + getifaddrs failed : %s, strerror(errno));
 +error_set(err, QERR_QGA_COMMAND_FAILED, err_msg);
 +goto error;
 +}

Generic errors are bad for the user. The best thing to do would be to have a 
QERR_
for the possible errors getifaddrs() can return. However, getifaddrs() can 
return
errors from several functions, so I don't know what's the best thing to do here.

Ideas, Michael?

 +
 +ifa = ifap;
 +while (ifa) {
 +GuestNetworkInfoList *info = NULL;
 +char addr4[INET_ADDRSTRLEN];
 +char addr6[INET6_ADDRSTRLEN];
 +unsigned char *mac_addr;
 +void *tmp_addr_ptr = NULL;

I'd call this just *p.

 +int sock, family;
 +int mac_supported;
 +struct ifreq ifr;
 +
 +/* Step over interfaces without an address */
 +if (!ifa-ifa_addr) {
 +ifa = ifa-ifa_next;
 +continue;
 +}

This matches the documentation, but wouldn't it be better to return information
about _interfaces_ (vs. _ip addresses_)? We could make the ip-address field
optional then.

 +
 +g_debug(Processing %s interface, ifa-ifa_name);
 +
 +family = ifa-ifa_addr-sa_family;
 +
 +if (family == AF_INET) {
 +/* interface with IPv4 address */
 +tmp_addr_ptr = ((struct sockaddr_in *)ifa-ifa_addr)-sin_addr;
 +inet_ntop(AF_INET, tmp_addr_ptr, addr4, sizeof(addr4));

inet_ntop() can fail.

 +
 +info = g_malloc0(sizeof(*info));
 +

[Qemu-devel] [PATCH] usb-hid: fix tablet activation

2012-02-23 Thread Gerd Hoffmann
Activate usb hid pointer devices (mouse+tablet) unconditionally
on polls, even if we NAK the poll due to lack of new events.

Signed-off-by: Gerd Hoffmann kra...@redhat.com
---
 hw/usb-hid.c |3 +++
 1 files changed, 3 insertions(+), 0 deletions(-)

diff --git a/hw/usb-hid.c b/hw/usb-hid.c
index 53353d3..36730ce 100644
--- a/hw/usb-hid.c
+++ b/hw/usb-hid.c
@@ -466,6 +466,9 @@ static int usb_hid_handle_data(USBDevice *dev, USBPacket *p)
 case USB_TOKEN_IN:
 if (p-ep-nr == 1) {
 int64_t curtime = qemu_get_clock_ns(vm_clock);
+if (hs-kind == HID_MOUSE || hs-kind == HID_TABLET) {
+hid_pointer_activate(hs);
+}
 if (!hid_has_events(hs) 
 (!hs-idle || hs-next_idle_clock - curtime  0)) {
 return USB_RET_NAK;
-- 
1.7.1




[Qemu-devel] [PULL 0/5]: QMP queue

2012-02-23 Thread Luiz Capitulino
Contains only the DEVICE_TRAY_MOVED event series.

The changes (since 235fe3bfd46b1104575b540d0bc3fdf584030b99) are available
in the following repository:

git://repo.or.cz/qemu/qmp-unstable.git queue/qmp

Luiz Capitulino (5):
  block: Rename bdrv_mon_event()  BlockMonEventAction
  block: bdrv_eject(): Make eject_flag a real bool
  block: Don't call bdrv_eject() if the tray state didn't change
  ide: drop ide_tray_state_post_load()
  qmp: add DEVICE_TRAY_MOVED event

 QMP/qmp-events.txt |   18 +++
 block.c|   84 +--
 block.h|8 ++--
 block/raw-posix.c  |6 ++--
 block/raw.c|2 +-
 block_int.h|2 +-
 hw/ide/atapi.c |7 +++-
 hw/ide/core.c  |   16 ++
 hw/scsi-disk.c |   13 +---
 hw/virtio-blk.c|6 ++--
 monitor.c  |3 ++
 monitor.h  |1 +
 12 files changed, 104 insertions(+), 62 deletions(-)




[Qemu-devel] [PATCH 4/5] ide: drop ide_tray_state_post_load()

2012-02-23 Thread Luiz Capitulino
This is used to sync the physical tray state after migration when
using CD-ROM passthrough. However, migrating when using passthrough
is broken anyway and shouldn't be supported...

So, drop this function as it causes a problem with the DEVICE_TRAY_MOVED
event, which is going to be introduced by the next commit.

Signed-off-by: Luiz Capitulino lcapitul...@redhat.com
Reviewed-by: Markus Armbruster arm...@redhat.com
Acked-by: Kevin Wolf kw...@redhat.com
---
 hw/ide/core.c |   10 --
 1 files changed, 0 insertions(+), 10 deletions(-)

diff --git a/hw/ide/core.c b/hw/ide/core.c
index 0856385..ce570a7 100644
--- a/hw/ide/core.c
+++ b/hw/ide/core.c
@@ -2077,15 +2077,6 @@ static bool ide_drive_pio_state_needed(void *opaque)
 || (s-bus-error_status  BM_STATUS_PIO_RETRY);
 }
 
-static int ide_tray_state_post_load(void *opaque, int version_id)
-{
-IDEState *s = opaque;
-
-bdrv_eject(s-bs, s-tray_open);
-bdrv_lock_medium(s-bs, s-tray_locked);
-return 0;
-}
-
 static bool ide_tray_state_needed(void *opaque)
 {
 IDEState *s = opaque;
@@ -2125,7 +2116,6 @@ static const VMStateDescription vmstate_ide_tray_state = {
 .version_id = 1,
 .minimum_version_id = 1,
 .minimum_version_id_old = 1,
-.post_load = ide_tray_state_post_load,
 .fields = (VMStateField[]) {
 VMSTATE_BOOL(tray_open, IDEState),
 VMSTATE_BOOL(tray_locked, IDEState),
-- 
1.7.9.111.gf3fb0.dirty




[Qemu-devel] [PATCH 2/5] block: bdrv_eject(): Make eject_flag a real bool

2012-02-23 Thread Luiz Capitulino
Signed-off-by: Luiz Capitulino lcapitul...@redhat.com
Reviewed-by: Markus Armbruster arm...@redhat.com
Acked-by: Kevin Wolf kw...@redhat.com
---
 block.c   |2 +-
 block.h   |2 +-
 block/raw-posix.c |6 +++---
 block/raw.c   |2 +-
 block_int.h   |2 +-
 5 files changed, 7 insertions(+), 7 deletions(-)

diff --git a/block.c b/block.c
index 8d4cfea..bfb0dec 100644
--- a/block.c
+++ b/block.c
@@ -3609,7 +3609,7 @@ int bdrv_media_changed(BlockDriverState *bs)
 /**
  * If eject_flag is TRUE, eject the media. Otherwise, close the tray
  */
-void bdrv_eject(BlockDriverState *bs, int eject_flag)
+void bdrv_eject(BlockDriverState *bs, bool eject_flag)
 {
 BlockDriver *drv = bs-drv;
 
diff --git a/block.h b/block.h
index ec0a6c8..49bca5a 100644
--- a/block.h
+++ b/block.h
@@ -265,7 +265,7 @@ int bdrv_enable_write_cache(BlockDriverState *bs);
 int bdrv_is_inserted(BlockDriverState *bs);
 int bdrv_media_changed(BlockDriverState *bs);
 void bdrv_lock_medium(BlockDriverState *bs, bool locked);
-void bdrv_eject(BlockDriverState *bs, int eject_flag);
+void bdrv_eject(BlockDriverState *bs, bool eject_flag);
 void bdrv_get_format(BlockDriverState *bs, char *buf, int buf_size);
 BlockDriverState *bdrv_find(const char *name);
 BlockDriverState *bdrv_next(BlockDriverState *bs);
diff --git a/block/raw-posix.c b/block/raw-posix.c
index 2ee5d69..2d1bc13 100644
--- a/block/raw-posix.c
+++ b/block/raw-posix.c
@@ -994,7 +994,7 @@ static int floppy_media_changed(BlockDriverState *bs)
 return ret;
 }
 
-static void floppy_eject(BlockDriverState *bs, int eject_flag)
+static void floppy_eject(BlockDriverState *bs, bool eject_flag)
 {
 BDRVRawState *s = bs-opaque;
 int fd;
@@ -1084,7 +1084,7 @@ static int cdrom_is_inserted(BlockDriverState *bs)
 return 0;
 }
 
-static void cdrom_eject(BlockDriverState *bs, int eject_flag)
+static void cdrom_eject(BlockDriverState *bs, bool eject_flag)
 {
 BDRVRawState *s = bs-opaque;
 
@@ -1194,7 +1194,7 @@ static int cdrom_is_inserted(BlockDriverState *bs)
 return raw_getlength(bs)  0;
 }
 
-static void cdrom_eject(BlockDriverState *bs, int eject_flag)
+static void cdrom_eject(BlockDriverState *bs, bool eject_flag)
 {
 BDRVRawState *s = bs-opaque;
 
diff --git a/block/raw.c b/block/raw.c
index 6098070..1cdac0c 100644
--- a/block/raw.c
+++ b/block/raw.c
@@ -61,7 +61,7 @@ static int raw_media_changed(BlockDriverState *bs)
 return bdrv_media_changed(bs-file);
 }
 
-static void raw_eject(BlockDriverState *bs, int eject_flag)
+static void raw_eject(BlockDriverState *bs, bool eject_flag)
 {
 bdrv_eject(bs-file, eject_flag);
 }
diff --git a/block_int.h b/block_int.h
index 7946cf6..04f4b83 100644
--- a/block_int.h
+++ b/block_int.h
@@ -197,7 +197,7 @@ struct BlockDriver {
 /* removable device specific */
 int (*bdrv_is_inserted)(BlockDriverState *bs);
 int (*bdrv_media_changed)(BlockDriverState *bs);
-void (*bdrv_eject)(BlockDriverState *bs, int eject_flag);
+void (*bdrv_eject)(BlockDriverState *bs, bool eject_flag);
 void (*bdrv_lock_medium)(BlockDriverState *bs, bool locked);
 
 /* to control generic scsi devices */
-- 
1.7.9.111.gf3fb0.dirty




[Qemu-devel] [PATCH 1/5] block: Rename bdrv_mon_event() BlockMonEventAction

2012-02-23 Thread Luiz Capitulino
They are QMP events, not monitor events. Rename them accordingly.

Also, move bdrv_emit_qmp_error_event() up in the file. A new event will
be added soon and it's good to have them next each other.

Signed-off-by: Luiz Capitulino lcapitul...@redhat.com
Reviewed-by: Markus Armbruster arm...@redhat.com
Acked-by: Kevin Wolf kw...@redhat.com
---
 block.c |   58 +++---
 block.h |6 ++--
 hw/ide/core.c   |6 ++--
 hw/scsi-disk.c  |6 ++--
 hw/virtio-blk.c |6 ++--
 5 files changed, 41 insertions(+), 41 deletions(-)

diff --git a/block.c b/block.c
index ae297bb..8d4cfea 100644
--- a/block.c
+++ b/block.c
@@ -943,6 +943,35 @@ void bdrv_set_dev_ops(BlockDriverState *bs, const 
BlockDevOps *ops,
 }
 }
 
+void bdrv_emit_qmp_error_event(const BlockDriverState *bdrv,
+   BlockQMPEventAction action, int is_read)
+{
+QObject *data;
+const char *action_str;
+
+switch (action) {
+case BDRV_ACTION_REPORT:
+action_str = report;
+break;
+case BDRV_ACTION_IGNORE:
+action_str = ignore;
+break;
+case BDRV_ACTION_STOP:
+action_str = stop;
+break;
+default:
+abort();
+}
+
+data = qobject_from_jsonf({ 'device': %s, 'action': %s, 'operation': %s 
},
+  bdrv-device_name,
+  action_str,
+  is_read ? read : write);
+monitor_protocol_event(QEVENT_BLOCK_IO_ERROR, data);
+
+qobject_decref(data);
+}
+
 static void bdrv_dev_change_media_cb(BlockDriverState *bs, bool load)
 {
 if (bs-dev_ops  bs-dev_ops-change_media_cb) {
@@ -2293,35 +2322,6 @@ int bdrv_is_allocated(BlockDriverState *bs, int64_t 
sector_num, int nb_sectors,
 return data.ret;
 }
 
-void bdrv_mon_event(const BlockDriverState *bdrv,
-BlockMonEventAction action, int is_read)
-{
-QObject *data;
-const char *action_str;
-
-switch (action) {
-case BDRV_ACTION_REPORT:
-action_str = report;
-break;
-case BDRV_ACTION_IGNORE:
-action_str = ignore;
-break;
-case BDRV_ACTION_STOP:
-action_str = stop;
-break;
-default:
-abort();
-}
-
-data = qobject_from_jsonf({ 'device': %s, 'action': %s, 'operation': %s 
},
-  bdrv-device_name,
-  action_str,
-  is_read ? read : write);
-monitor_protocol_event(QEVENT_BLOCK_IO_ERROR, data);
-
-qobject_decref(data);
-}
-
 BlockInfoList *qmp_query_block(Error **errp)
 {
 BlockInfoList *head = NULL, *cur_item = NULL;
diff --git a/block.h b/block.h
index 60ea730..ec0a6c8 100644
--- a/block.h
+++ b/block.h
@@ -85,15 +85,15 @@ typedef enum {
 
 typedef enum {
 BDRV_ACTION_REPORT, BDRV_ACTION_IGNORE, BDRV_ACTION_STOP
-} BlockMonEventAction;
+} BlockQMPEventAction;
 
 void bdrv_iostatus_enable(BlockDriverState *bs);
 void bdrv_iostatus_reset(BlockDriverState *bs);
 void bdrv_iostatus_disable(BlockDriverState *bs);
 bool bdrv_iostatus_is_enabled(const BlockDriverState *bs);
 void bdrv_iostatus_set_err(BlockDriverState *bs, int error);
-void bdrv_mon_event(const BlockDriverState *bdrv,
-BlockMonEventAction action, int is_read);
+void bdrv_emit_qmp_error_event(const BlockDriverState *bdrv,
+   BlockQMPEventAction action, int is_read);
 void bdrv_info_print(Monitor *mon, const QObject *data);
 void bdrv_info(Monitor *mon, QObject **ret_data);
 void bdrv_stats_print(Monitor *mon, const QObject *data);
diff --git a/hw/ide/core.c b/hw/ide/core.c
index 56b219b..0856385 100644
--- a/hw/ide/core.c
+++ b/hw/ide/core.c
@@ -519,7 +519,7 @@ static int ide_handle_rw_error(IDEState *s, int error, int 
op)
 BlockErrorAction action = bdrv_get_on_error(s-bs, is_read);
 
 if (action == BLOCK_ERR_IGNORE) {
-bdrv_mon_event(s-bs, BDRV_ACTION_IGNORE, is_read);
+bdrv_emit_qmp_error_event(s-bs, BDRV_ACTION_IGNORE, is_read);
 return 0;
 }
 
@@ -527,7 +527,7 @@ static int ide_handle_rw_error(IDEState *s, int error, int 
op)
 || action == BLOCK_ERR_STOP_ANY) {
 s-bus-dma-ops-set_unit(s-bus-dma, s-unit);
 s-bus-error_status = op;
-bdrv_mon_event(s-bs, BDRV_ACTION_STOP, is_read);
+bdrv_emit_qmp_error_event(s-bs, BDRV_ACTION_STOP, is_read);
 vm_stop(RUN_STATE_IO_ERROR);
 bdrv_iostatus_set_err(s-bs, error);
 } else {
@@ -537,7 +537,7 @@ static int ide_handle_rw_error(IDEState *s, int error, int 
op)
 } else {
 ide_rw_error(s);
 }
-bdrv_mon_event(s-bs, BDRV_ACTION_REPORT, is_read);
+bdrv_emit_qmp_error_event(s-bs, BDRV_ACTION_REPORT, is_read);
 }
 
 return 1;
diff --git a/hw/scsi-disk.c b/hw/scsi-disk.c
index c12e3a6..a5d2fd1 100644
--- a/hw/scsi-disk.c
+++ b/hw/scsi-disk.c
@@ -233,14 +233,14 @@ 

[Qemu-devel] [PATCH 5/5] qmp: add DEVICE_TRAY_MOVED event

2012-02-23 Thread Luiz Capitulino
It's emitted whenever the tray is moved by the guest or by HMP/QMP
commands.

Signed-off-by: Luiz Capitulino lcapitul...@redhat.com
Reviewed-by: Markus Armbruster arm...@redhat.com
Acked-by: Kevin Wolf kw...@redhat.com
---
 QMP/qmp-events.txt |   18 ++
 block.c|   24 
 monitor.c  |3 +++
 monitor.h  |1 +
 4 files changed, 46 insertions(+), 0 deletions(-)

diff --git a/QMP/qmp-events.txt b/QMP/qmp-events.txt
index 06cb404..9286af5 100644
--- a/QMP/qmp-events.txt
+++ b/QMP/qmp-events.txt
@@ -26,6 +26,24 @@ Example:
 Note: If action is stop, a STOP event will eventually follow the
 BLOCK_IO_ERROR event.
 
+DEVICE_TRAY_MOVED
+-
+
+It's emitted whenever the tray of a removable device is moved by the guest
+or by HMP/QMP commands.
+
+Data:
+
+- device: device name (json-string)
+- tray-open: true if the tray has been opened or false if it has been closed
+   (json-bool)
+
+{ event: DEVICE_TRAY_MOVED,
+  data: { device: ide1-cd0,
+tray-open: true
+  },
+  timestamp: { seconds: 1265044230, microseconds: 450486 } }
+
 RESET
 -
 
diff --git a/block.c b/block.c
index bfb0dec..e27d528 100644
--- a/block.c
+++ b/block.c
@@ -972,10 +972,30 @@ void bdrv_emit_qmp_error_event(const BlockDriverState 
*bdrv,
 qobject_decref(data);
 }
 
+static void bdrv_emit_qmp_eject_event(BlockDriverState *bs, bool ejected)
+{
+QObject *data;
+
+data = qobject_from_jsonf({ 'device': %s, 'tray-open': %i },
+  bdrv_get_device_name(bs), ejected);
+monitor_protocol_event(QEVENT_DEVICE_TRAY_MOVED, data);
+
+qobject_decref(data);
+}
+
 static void bdrv_dev_change_media_cb(BlockDriverState *bs, bool load)
 {
 if (bs-dev_ops  bs-dev_ops-change_media_cb) {
+bool tray_was_closed = !bdrv_dev_is_tray_open(bs);
 bs-dev_ops-change_media_cb(bs-dev_opaque, load);
+if (tray_was_closed) {
+/* tray open */
+bdrv_emit_qmp_eject_event(bs, true);
+}
+if (load) {
+/* tray close */
+bdrv_emit_qmp_eject_event(bs, false);
+}
 }
 }
 
@@ -3616,6 +3636,10 @@ void bdrv_eject(BlockDriverState *bs, bool eject_flag)
 if (drv  drv-bdrv_eject) {
 drv-bdrv_eject(bs, eject_flag);
 }
+
+if (bs-device_name[0] != '\0') {
+bdrv_emit_qmp_eject_event(bs, eject_flag);
+}
 }
 
 /**
diff --git a/monitor.c b/monitor.c
index 0d4daad..03beab3 100644
--- a/monitor.c
+++ b/monitor.c
@@ -485,6 +485,9 @@ void monitor_protocol_event(MonitorEvent event, QObject 
*data)
 case QEVENT_BLOCK_JOB_CANCELLED:
 event_name = BLOCK_JOB_CANCELLED;
 break;
+case QEVENT_DEVICE_TRAY_MOVED:
+ event_name = DEVICE_TRAY_MOVED;
+break;
 default:
 abort();
 break;
diff --git a/monitor.h b/monitor.h
index b72ea07..b6f700f 100644
--- a/monitor.h
+++ b/monitor.h
@@ -38,6 +38,7 @@ typedef enum MonitorEvent {
 QEVENT_SPICE_DISCONNECTED,
 QEVENT_BLOCK_JOB_COMPLETED,
 QEVENT_BLOCK_JOB_CANCELLED,
+QEVENT_DEVICE_TRAY_MOVED,
 QEVENT_MAX,
 } MonitorEvent;
 
-- 
1.7.9.111.gf3fb0.dirty




[Qemu-devel] [PATCH 3/5] block: Don't call bdrv_eject() if the tray state didn't change

2012-02-23 Thread Luiz Capitulino
It's not needed. Besides we can then assume that bdrv_eject() is
only called when there's a tray state change, which is useful to
the DEVICE_TRAY_MOVED event (going to be added in a future
commit).

Signed-off-by: Luiz Capitulino lcapitul...@redhat.com
Reviewed-by: Markus Armbruster arm...@redhat.com
Acked-by: Kevin Wolf kw...@redhat.com
---
 hw/ide/atapi.c |7 +--
 hw/scsi-disk.c |7 +--
 2 files changed, 10 insertions(+), 4 deletions(-)

diff --git a/hw/ide/atapi.c b/hw/ide/atapi.c
index 0adb27b..5919cf5 100644
--- a/hw/ide/atapi.c
+++ b/hw/ide/atapi.c
@@ -883,8 +883,11 @@ static void cmd_start_stop_unit(IDEState *s, uint8_t* buf)
 ide_atapi_cmd_error(s, sense, ASC_MEDIA_REMOVAL_PREVENTED);
 return;
 }
-bdrv_eject(s-bs, !start);
-s-tray_open = !start;
+
+if (s-tray_open != !start) {
+bdrv_eject(s-bs, !start);
+s-tray_open = !start;
+}
 }
 
 ide_atapi_cmd_ok(s);
diff --git a/hw/scsi-disk.c b/hw/scsi-disk.c
index a5d2fd1..091ecdc 100644
--- a/hw/scsi-disk.c
+++ b/hw/scsi-disk.c
@@ -1050,8 +1050,11 @@ static int scsi_disk_emulate_start_stop(SCSIDiskReq *r)
  : SENSE_CODE(NOT_READY_REMOVAL_PREVENTED));
 return -1;
 }
-bdrv_eject(s-qdev.conf.bs, !start);
-s-tray_open = !start;
+
+if (s-tray_open != !start) {
+bdrv_eject(s-qdev.conf.bs, !start);
+s-tray_open = !start;
+}
 }
 return 0;
 }
-- 
1.7.9.111.gf3fb0.dirty




Re: [Qemu-devel] qemu assertion failed with usb on current git master!

2012-02-23 Thread Gerd Hoffmann
On 02/23/12 12:38, Erik Rull wrote:
  When running qemu with -device usb-host an assertion failed caused by
 attaching a new usb device to the host that gets routed to the guest.
 
 The assertion that fails is:
 
 qemu-system-x86_64: /home/erik/qemu/hw/usb.c:358 usb_packet_complete:
 Assertion 'p-state == USB_PACKET_QUEUED' failed.

Stacktrace?
What kind of device?

Can you enable the debug logging code in usb_packet_set_state() and send
a log?

thanks,
  Gerd




Re: [Qemu-devel] [Bug 938945] [NEW] Slirp cannot be forward and makes segmentation faults

2012-02-23 Thread Andreas Färber
Am 22.02.2012 20:50, schrieb Vincent Autefage:
 $ qemu -enable-kvm -name opeth -hda debian1.img -k fr -localtime -m 512

The qemu executable has been renamed to qemu-system-i386 some time ago.
Are you sure you're executing the right one, and which version are you
using? Did you check qemu.git master?

Andreas

-- 
SUSE LINUX Products GmbH, Maxfeldstr. 5, 90409 Nürnberg, Germany
GF: Jeff Hawn, Jennifer Guild, Felix Imendörffer; HRB 16746 AG Nürnberg



[Qemu-devel] [Bug 883136] Re: qemu on ARM hosts aborts on startup because makecontext() always fails

2012-02-23 Thread Peter Maydell
Michael Hope pointed out that glibc defines a macro __stub_makecontext
when the makecontext() implementation is a stub, so we can just add this
to the qemu configure test to make it automatically fall back to the
pthreads version as required.

-- 
You received this bug notification because you are a member of qemu-
devel-ml, which is subscribed to QEMU.
https://bugs.launchpad.net/bugs/883136

Title:
  qemu on ARM hosts aborts on startup because makecontext() always fails

Status in QEMU:
  New
Status in Linaro QEMU:
  In Progress

Bug description:
  qemu has recently grown a coroutines implementation. There are two
  versions, one using the makecontext/setcontext/swapcontext functions
  from ucontext.h, and one falling back to implementing coroutines as
  separate glib threads. configure chooses the former if the platform
  has a makecontext().

  Unfortunately ARM eglibc provides a makecontext() which always fails
  ENOSYS, which means the configure check passes but when qemu starts it
  abort()s.

  The best fix for this is probably going to involve making the
  coroutine implementation runtime-selectable.

To manage notifications about this bug go to:
https://bugs.launchpad.net/qemu/+bug/883136/+subscriptions



[Qemu-devel] linux guests and ksm performance

2012-02-23 Thread Peter Lieven
Hi,

i have recently been playing with an old idea (originally in grsecurity
for security reasons) to change
the policy from zero on allocate to zero after free in the linux page
allocator. My concern is that linux
leaves a lot of waste in the physical memory unlike Windows which per
default zeros pages after
they are freed.

I have run some tests and I can confirm some old results that a hardware
Linux machine
is approximately 2-3% slower with zero after free on big compilation jobs.
This might be due
to either the fact that pages are only zeroed on allocate if GFP_ZERO is
set or due to caching
benefits.

However, in a virtual machine I have not observed the above slow down to
that extend
while the benefit of zero after free in a virtualisation environment is
obvious:

1) zero pages can easily be merged by ksm or other technique.
2) zero (dup) pages are a lot faster to transfer in case of migration.

Therefore I would like to hear your thoughts if it would be a good idea to
change
the strategy in the Linux kernel from zero on allocate to zero after free
automatically
if the 'hypervisor' cpu feature is set? Or even have another technique to
tell a linux
guest that ksm is running on the host.

If this is not feasible can someone think of a kernel module / userspace
program that
zeroes out unused pages periodically.

Peter





Re: [Qemu-devel] Live Block Migration using Mirroring

2012-02-23 Thread Stefan Hajnoczi
On Wed, Feb 22, 2012 at 5:13 PM, Federico Simoncelli
fsimo...@redhat.com wrote:
 Preparation
 ===

 $ mkdir /tmp/{src/dst}
 $ qemu-img create -f qcow2 /tmp/src/hd0base.qcow2 20G
 Formatting '/tmp/src/hd0base.qcow2', fmt=qcow2 size=21474836480
 encryption=off cluster_size=65536

 Step 1 - Initital Scenario
 ==
 VM1 is running on the src/hd0base. (Where = stands for uses)

 [src/hd0base] = VM1(read-write)

 $ qemu-system-x86_64 -hda /tmp/src/hd0base.qcow2 -monitor stdio
 QEMU 1.0.50 monitor - type 'help' for more information
 (qemu)

 Step 3 - Mirrored Live Snapshot
 ===
 A mirrored live snapshot is issued using src/hd0snap1 and dst/hd0snap1 as
 image files. (Where - stands for has backing file)

 [src/hd0base] - [src/hd0snap1] = VM1(read-write)
     ...      - [dst/hd0snap1] = VM1(write-only)

 $ qemu-img create -f qcow2 \
           -b /tmp/src/hd0base.qcow2 /tmp/src/hd0snap1.qcow2 20G
 Formatting '/tmp/src/hd0snap1.qcow2', fmt=qcow2 size=21474836480
 backing_file='/tmp/src/hd0base.qcow2' encryption=off cluster_size=65536

 $ qemu-img create -f qcow2 \
           -b /tmp/dst/hd0base.qcow2 /tmp/dst/hd0snap1.qcow2 20G
 Formatting '/tmp/dst/hd0snap1.qcow2', fmt=qcow2 size=21474836480
 backing_file='/tmp/src/hd0base.qcow2' encryption=off cluster_size=65536

At this stage /tmp/dst/hd0base.qcow2 does not exist yet.  The qemu-img
output you pasted shows /tmp/src/hd0base.qcow2 was actually used.
Typo?

 (qemu) snapshot_blkdev -n ide0-hd0 \
         blkmirror:/tmp/src/hd0snap1.qcow2:/tmp/dst/hd0snap1.qcow2 blkmirror

 Step 4 - Backing File Copy
 ==
 An external manager copies src/hd0base to the destination dst/hd0base.

 [src/hd0base] - [src/hd0snap1] = VM1(read-write)
 [dst/hd0base] - [dst/hd0snap1] = VM1(write-only)

 $ cp -a /tmp/src/hd0base.qcow2 /tmp/dst/hd0base.qcow2

Are we missing a fixup step that changes backing_file in
dst/hd0snap1.qcow2 to point at dst/hd0base.qcow2?

 Step 5 - Final Switch to Destination
 
 VM1 is now able to switch to the destination for both read and write
 operations.

 [src/hd0base] - [src/hd0snap1] = VM1(read-write)

 (qemu) snapshot_blkdev -n ide0-hd0 /tmp/dst/hd0snap1.qcow2

 --
 Federico





Re: [Qemu-devel] FLR capability hidden in VF config space

2012-02-23 Thread Alex Williamson
On Thu, 2012-02-23 at 09:25 +0530, rukhsana ansari wrote:
 Hello,
 
 Was wondering whether someone could shed some light on the issue below.
 Without FLR exposed in the VF, VF reset via FLR cannot be initiated from
 the guest.
 Appreciate any pointers.

The device state needs to be restored after an FLR.  A guest is not able
to do this by this by itself as much of the config space is virtualized.
That means qemu needs to be involved in the FLR.  It's possible we could
trap FLR and call reset_assign_device().  Patches welcome.  Why do want
to reset the device?

 On Wed, Feb 15, 2012 at 2:54 PM, rukhsana ansari ruk.ans...@gmail.comwrote:
 
  Hi,
 
  The following code snippet (line 1457,
  function:assigned_device_pci_cap_init()  file: hw/device-assignment.c)
  from the latest qemu-kvm git (qemu-kvm-devel: 1.0.50)  implies that FLR
  capability is unset for VF that is assigned to a guest:
 
  /* device capabilities: hide FLR */
  devcap = pci_get_long(pci_dev-config + pos + PCI_EXP_DEVCAP);
  devcap = ~PCI_EXP_DEVCAP_FLR;
  pci_set_long(pci_dev-config + pos + PCI_EXP_DEVCAP, devcap);
 
 
  However the SR-IOV spec mandates VF FLR.

The SR-IOV spec mandates that the VF supports FLR.  That doesn't mean it
has to be exposed though to a guest.  Thanks,

Alex




Re: [Qemu-devel] Live Block Migration using Mirroring

2012-02-23 Thread Federico Simoncelli
- Original Message -
 From: Stefan Hajnoczi stefa...@gmail.com
 To: Federico Simoncelli fsimo...@redhat.com
 Cc: qemu-devel@nongnu.org, kw...@redhat.com, mtosa...@redhat.com
 Sent: Thursday, February 23, 2012 4:47:38 PM
 Subject: Re: [Qemu-devel] Live Block Migration using Mirroring

 On Wed, Feb 22, 2012 at 5:13 PM, Federico Simoncelli
 fsimo...@redhat.com wrote:
  Step 3 - Mirrored Live Snapshot
  ===
  A mirrored live snapshot is issued using src/hd0snap1 and
  dst/hd0snap1 as
  image files. (Where - stands for has backing file)
 
  [src/hd0base] - [src/hd0snap1] = VM1(read-write)
      ...      - [dst/hd0snap1] = VM1(write-only)
 
  $ qemu-img create -f qcow2 \
            -b /tmp/src/hd0base.qcow2 /tmp/src/hd0snap1.qcow2 20G
  Formatting '/tmp/src/hd0snap1.qcow2', fmt=qcow2 size=21474836480
  backing_file='/tmp/src/hd0base.qcow2' encryption=off
  cluster_size=65536
 
  $ qemu-img create -f qcow2 \
            -b /tmp/dst/hd0base.qcow2 /tmp/dst/hd0snap1.qcow2 20G
  Formatting '/tmp/dst/hd0snap1.qcow2', fmt=qcow2 size=21474836480
  backing_file='/tmp/src/hd0base.qcow2' encryption=off
  cluster_size=65536

 At this stage /tmp/dst/hd0base.qcow2 does not exist yet.  The
 qemu-img
 output you pasted shows /tmp/src/hd0base.qcow2 was actually used.
 Typo?

No that's part of the flag used in [PATCH 2/3] (Update the blkmirror
block driver): BDRV_O_NO_BACKING

It's also documented in the design:

http://www.ovirt.org/wiki/File:StorageLiveMigration2.png

  (qemu) snapshot_blkdev -n ide0-hd0 \
          blkmirror:/tmp/src/hd0snap1.qcow2:/tmp/dst/hd0snap1.qcow2
          blkmirror
 
  Step 4 - Backing File Copy
  ==
  An external manager copies src/hd0base to the destination
  dst/hd0base.
 
  [src/hd0base] - [src/hd0snap1] = VM1(read-write)
  [dst/hd0base] - [dst/hd0snap1] = VM1(write-only)
 
  $ cp -a /tmp/src/hd0base.qcow2 /tmp/dst/hd0base.qcow2

 Are we missing a fixup step that changes backing_file in
 dst/hd0snap1.qcow2 to point at dst/hd0base.qcow2?

See above.

--
Federico



Re: [Qemu-devel] [PATCH 1/3] Add blkmirror block driver

2012-02-23 Thread Stefan Hajnoczi
On Wed, Feb 22, 2012 at 5:13 PM, Federico Simoncelli
fsimo...@redhat.com wrote:
 From: Marcelo Tosatti mtosa...@redhat.com

 Mirrored writes are used by live block copy.

I think the right approach is to create a single blkmirror driver that
also includes blkverify functionality.  The code is basically the same
except blkverify also compares reads - just use a flag to
enable/disable that behavior.

Feel free to rename the blkverify driver to blkmirror if you wish.

By the way, this code does not build against qemu.git/master.  It uses
interfaces which have been dropped.

Stefan



[Qemu-devel] [PATCH] configure: Detect when glibc implements makecontext() to always fail

2012-02-23 Thread Peter Maydell
Improve the configure test for presence of ucontext functions by
making linker warnings fatal; this allows us to detect when we are
linked with a glibc which implements makecontext() to always return
ENOSYS.

Signed-off-by: Peter Maydell peter.mayd...@linaro.org
---
Compiling on an Ubuntu Natty ARM host will hit this.
(Anybody think we should clean up our configure tests so we can
enable -Werror and -Wl,--fatal-warnings on all of them?)

 configure |7 +--
 1 files changed, 5 insertions(+), 2 deletions(-)

diff --git a/configure b/configure
index 9b4fe34..4d9d9e0 100755
--- a/configure
+++ b/configure
@@ -2549,9 +2549,12 @@ ucontext_coroutine=no
 if test $darwin != yes; then
   cat  $TMPC  EOF
 #include ucontext.h
-int main(void) { makecontext(0, 0, 0); }
+int main(void) { makecontext(0, 0, 0); return 0; }
 EOF
-  if compile_prog   ; then
+  # Note that we enable fatal linker warnings to catch the
+  # glibc makecontext is not implemented and will always fail
+  # linker warning.
+  if compile_prog -Wl,--fatal-warnings  ; then
   ucontext_coroutine=yes
   fi
 fi
-- 
1.7.4.1




Re: [Qemu-devel] [PATCH 1/3] Add blkmirror block driver

2012-02-23 Thread Stefan Hajnoczi
On Thu, Feb 23, 2012 at 4:14 PM, Stefan Hajnoczi stefa...@gmail.com wrote:
 By the way, this code does not build against qemu.git/master.  It uses
 interfaces which have been dropped.

Ah, I see you changed that in Patch 2/3.  Please don't do that, it's
hard to review and breaks git-bisect.

Stefan



Re: [Qemu-devel] [PATCH 1/3] Add blkmirror block driver

2012-02-23 Thread Federico Simoncelli
- Original Message -
 From: Stefan Hajnoczi stefa...@gmail.com
 To: Federico Simoncelli fsimo...@redhat.com
 Cc: qemu-devel@nongnu.org, kw...@redhat.com, mtosa...@redhat.com
 Sent: Thursday, February 23, 2012 5:14:09 PM
 Subject: Re: [Qemu-devel] [PATCH 1/3] Add blkmirror block driver
 
 On Wed, Feb 22, 2012 at 5:13 PM, Federico Simoncelli
 fsimo...@redhat.com wrote:
  From: Marcelo Tosatti mtosa...@redhat.com
 
  Mirrored writes are used by live block copy.
 
 I think the right approach is to create a single blkmirror driver
 that
 also includes blkverify functionality.  The code is basically the
 same
 except blkverify also compares reads - just use a flag to
 enable/disable that behavior.
 
 Feel free to rename the blkverify driver to blkmirror if you wish.
 
 By the way, this code does not build against qemu.git/master.  It
 uses
 interfaces which have been dropped.

Yes you also need:

[PATCH 2/3] Update the blkmirror block driver

Which was sent separately to facilitate the review for people who
already reviewed this.

-- 
Federico



Re: [Qemu-devel] [PATCH] configure: Detect when glibc implements makecontext() to always fail

2012-02-23 Thread Peter Maydell
On 23 February 2012 16:16, Peter Maydell peter.mayd...@linaro.org wrote:
 Improve the configure test for presence of ucontext functions by
 making linker warnings fatal; this allows us to detect when we are
 linked with a glibc which implements makecontext() to always return
 ENOSYS.

Er, ignore this, emailed wrong patch by mistake!

-- PMM



[Qemu-devel] [PATCH] configure: Check whether makecontext() is a glibc stub function

2012-02-23 Thread Peter Maydell
On some systems (notably ARM Linux) glibc provides implementations
of makecontext(), getcontext() and friends which are stubs which
always return failure. Make the configure test for makecontext()
also check for the presence of the __stub_makecontext macro which
indicates the presence of these stubs, so we can avoid trying to use
them and fall back to a different coroutine implementation instead.

Signed-off-by: Peter Maydell peter.mayd...@linaro.org
---
I think this fixes the last of the bugs which meant we had to declare
ARM hosts as officially unsupported in QEMU 1.0...

 configure |4 
 1 files changed, 4 insertions(+), 0 deletions(-)

diff --git a/configure b/configure
index 037f7f7..9fbf88a 100755
--- a/configure
+++ b/configure
@@ -2712,11 +2712,15 @@ fi
 
 ##
 # check if we have makecontext
+# (and that it's not a glibc stub which always returns -1)
 
 ucontext_coroutine=no
 if test $darwin != yes; then
   cat  $TMPC  EOF
 #include ucontext.h
+#ifdef __stub_makecontext
+#error Ignoring glibc stub makecontext which will always fail
+#endif
 int main(void) { makecontext(0, 0, 0); return 0; }
 EOF
   if compile_prog   ; then
-- 
1.7.1




Re: [Qemu-devel] [PATCH 1/3] Add blkmirror block driver

2012-02-23 Thread Federico Simoncelli
- Original Message -
 From: Stefan Hajnoczi stefa...@gmail.com
 To: Federico Simoncelli fsimo...@redhat.com
 Cc: qemu-devel@nongnu.org, kw...@redhat.com, mtosa...@redhat.com
 Sent: Thursday, February 23, 2012 5:18:41 PM
 Subject: Re: [Qemu-devel] [PATCH 1/3] Add blkmirror block driver

 On Thu, Feb 23, 2012 at 4:14 PM, Stefan Hajnoczi stefa...@gmail.com
 wrote:
  By the way, this code does not build against qemu.git/master.  It
  uses
  interfaces which have been dropped.

 Ah, I see you changed that in Patch 2/3.  Please don't do that, it's
 hard to review and breaks git-bisect.

Squashing is easy (anyone could do it at the commit phase), reviewing
is hard (if you hide your changes in someone else's code).

--
Federico



Re: [Qemu-devel] [PATCH] qom: Make object_unref() free the object's memory when refcount goes to 0.

2012-02-23 Thread Alexander Barabash

On 02/22/2012 09:12 PM, Anthony Liguori wrote:

On 02/22/2012 12:00 PM, alexander_barab...@mentor.com wrote:

From: Alexander Barabashalexander_barab...@mentor.com

In the existing implementation, object_delete()
calls object_unref(), then frees the object's storage.
Running object_delete() on an object with reference count
different from 1 causes program failure.

In the existing implementation, object_unref()
finalizes the object when its reference count becomes 0.

In the new implementation, object_unref()
finalizes and frees the object's storage when the reference count 
becomes 0.


In the new implementation, object_delete()
just calls object_unref().
Running object_delete() on an object with reference count
different from 1 still causes program failure.


This isn't correct.  QOM objects don't necessarily have heap allocated 
objects.


I've been thinking about this general problem and I think the right 
way to solve it is to have a delete notifier list.  That way, 
object_new() can register a delete notifier that calls g_free() 
whenever refcount=0.  That way an explicit object_delete() isn't 
needed anymore.


Why do you want to have a delete notifier list, rather than just a 
delete callback.

At the point where refcount == 0, the destructor has been called already,
so there is not much to be done, except for reclaim the memory.

Regards,
Alex



Although I think we should keep the call around as it's convenient for 
replacing occurrences of qdev_free() where you really want the assert.


Regards,

Anthony Liguori



Signed-off-by: Alexander Barabashalexander_barab...@mentor.com
---
  qom/object.c |4 ++--
  1 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/qom/object.c b/qom/object.c
index e6591e1..8d36a9c 100644
--- a/qom/object.c
+++ b/qom/object.c
@@ -373,9 +373,8 @@ Object *object_new(const char *typename)

  void object_delete(Object *obj)
  {
+g_assert(obj-ref == 1);
  object_unref(obj);
-g_assert(obj-ref == 0);
-g_free(obj);
  }

  static bool type_is_ancestor(TypeImpl *type, TypeImpl *target_type)
@@ -585,6 +584,7 @@ void object_unref(Object *obj)
  /* parent always holds a reference to its children */
  if (obj-ref == 0) {
  object_finalize(obj);
+g_free(obj);
  }
  }








Re: [Qemu-devel] [PATCH 1/3] Add blkmirror block driver

2012-02-23 Thread Stefan Hajnoczi
On Thu, Feb 23, 2012 at 4:20 PM, Federico Simoncelli
fsimo...@redhat.com wrote:
 - Original Message -
 From: Stefan Hajnoczi stefa...@gmail.com
 To: Federico Simoncelli fsimo...@redhat.com
 Cc: qemu-devel@nongnu.org, kw...@redhat.com, mtosa...@redhat.com
 Sent: Thursday, February 23, 2012 5:18:41 PM
 Subject: Re: [Qemu-devel] [PATCH 1/3] Add blkmirror block driver

 On Thu, Feb 23, 2012 at 4:14 PM, Stefan Hajnoczi stefa...@gmail.com
 wrote:
  By the way, this code does not build against qemu.git/master.  It
  uses
  interfaces which have been dropped.

 Ah, I see you changed that in Patch 2/3.  Please don't do that, it's
 hard to review and breaks git-bisect.

 Squashing is easy (anyone could do it at the commit phase), reviewing
 is hard (if you hide your changes in someone else's code).

I don't care if you or Marcelo wrote it, I want to see a coherent piece of code.

The way to do it is to merge the g_malloc() and BlockDriver interface
changes into this path.  Then you have not snuck any significant
changes into Marcelo's code.

Keep the BDRV_O_NO_BACKING separate.

Stefan



Re: [Qemu-devel] Live Block Migration using Mirroring

2012-02-23 Thread Stefan Hajnoczi
On Wed, Feb 22, 2012 at 5:13 PM, Federico Simoncelli
fsimo...@redhat.com wrote:
  recently I've been working on live block migration combining the live
 snapshots and the blkmirror patch sent by Marcelo Tosatti few months ago.

 The design is summarized at this url as Mirrored-Snapshot:

 http://www.ovirt.org/wiki/Features/Design/StorageLiveMigration

After mirrored-snapshot completes we're left with the base and the
snapshot.  Is the idea to implement live snapshot merge next?  Or do
you have something else planned to avoid growing the backing file
chain each time mirrored-snapshot is used?

Stefan



Re: [Qemu-devel] linux guests and ksm performance

2012-02-23 Thread Stefan Hajnoczi
On Thu, Feb 23, 2012 at 3:40 PM, Peter Lieven p...@dlh.net wrote:
 However, in a virtual machine I have not observed the above slow down to
 that extend
 while the benefit of zero after free in a virtualisation environment is
 obvious:

 1) zero pages can easily be merged by ksm or other technique.
 2) zero (dup) pages are a lot faster to transfer in case of migration.

The other approach is a memory page discard mechanism - which
obviously requires more code changes than zeroing freed pages.

The advantage is that we don't take the brute-force and CPU intensive
approach of zeroing pages.  It would be like a fine-grained ballooning
feature.

I hope someone will follow up saying this has already been done or
prototyped :).

Stefan



Re: [Qemu-devel] [PATCH 1/3] Add blkmirror block driver

2012-02-23 Thread Federico Simoncelli
- Original Message -
 From: Stefan Hajnoczi stefa...@gmail.com
 To: Federico Simoncelli fsimo...@redhat.com
 Cc: qemu-devel@nongnu.org, kw...@redhat.com, mtosa...@redhat.com
 Sent: Thursday, February 23, 2012 5:28:23 PM
 Subject: Re: [Qemu-devel] [PATCH 1/3] Add blkmirror block driver

 On Thu, Feb 23, 2012 at 4:20 PM, Federico Simoncelli
 fsimo...@redhat.com wrote:
  - Original Message -
  From: Stefan Hajnoczi stefa...@gmail.com
  To: Federico Simoncelli fsimo...@redhat.com
  Cc: qemu-devel@nongnu.org, kw...@redhat.com, mtosa...@redhat.com
  Sent: Thursday, February 23, 2012 5:18:41 PM
  Subject: Re: [Qemu-devel] [PATCH 1/3] Add blkmirror block driver
 
  On Thu, Feb 23, 2012 at 4:14 PM, Stefan Hajnoczi
  stefa...@gmail.com
  wrote:
   By the way, this code does not build against qemu.git/master.
    It
   uses
   interfaces which have been dropped.
 
  Ah, I see you changed that in Patch 2/3.  Please don't do that,
  it's
  hard to review and breaks git-bisect.
 
  Squashing is easy (anyone could do it at the commit phase),
  reviewing
  is hard (if you hide your changes in someone else's code).

 I don't care if you or Marcelo wrote it, I want to see a coherent
 piece of code.

 The way to do it is to merge the g_malloc() and BlockDriver interface
 changes into this path.  Then you have not snuck any significant
 changes into Marcelo's code.

Well for example I'd have snuck the qemu_vmalloc/qemu_vfree mistake.

 Keep the BDRV_O_NO_BACKING separate.

Ok, thanks.

--
Federico



[Qemu-devel] [Bug 918791] Re: qemu-kvm dies when using vmvga driver and unity in the guest

2012-02-23 Thread Serge Hallyn
@Jamie,

if you feel the priority if this needs to be raised, please do raise it
or comment here.

-- 
You received this bug notification because you are a member of qemu-
devel-ml, which is subscribed to QEMU.
https://bugs.launchpad.net/bugs/918791

Title:
  qemu-kvm dies when using vmvga driver and unity in the guest

Status in QEMU:
  New
Status in “qemu-kvm” package in Ubuntu:
  Confirmed
Status in “qemu-kvm” source package in Precise:
  Confirmed

Bug description:
  12.04's qemu-kvm has been unstable for me and Marc Deslauriers and I
  figured out it has something to do with the interaction of qemu-kvm,
  unity and the vmvga driver. This is a regression over qemu-kvm in
  11.10.

  TEST CASE:
  1. start a VM that uses unity (eg, 11.04, 11.10 or 12.04). My tests use 
unity-2d on an amd64 host and amd64 guests
  2. on 11.04 and 11.10, open empathy via the messaging indicator and click 
'Chat'. On 12.04, open empathy via the messaging indicator and click 'Chat', 
close the empathy wizard, move the empathy window over the unity luancher (so 
it autohides), then do 'ctrl+alt+t' to open a terminal

  When the launcher tries to auto(un)hide, qemu-kvm dies with this:
  [10574.958149] do_general_protection: 132 callbacks suppressed
  [10574.958154] kvm[13192] general protection ip:7fab9680ea0f sp:74440148 
error:0 in qemu-system-x86_64[7fab966c4000+2c9000]

  Relevant libvirt xml:
  video
model type='vmvga' vram='9216' heads='1'/
address type='pci' domain='0x' bus='0x00' slot='0x02' 
function='0x0'/
  /video

  If I change to using 'cirrus', then qemu-kvm no longer crashes. Eg:
  video
model type='cirrus' vram='9216' heads='1'/
alias name='video0'/
address type='pci' domain='0x' bus='0x00' slot='0x02' 
function='0x0'/
  /video

  The workaround is therefore to use the cirrus driver instead of vmvga,
  however being able to kill qemu-kvm in this manner is not ideal. Also,
  unfortunately unity-2d does not run with with cirrus driver under
  11.04, so the security and SRU teams are unable to properly test
  updates in GUI applications under unity when using the current 12.04
  qemu-kvm.

  I tried to report this via apport, but apport complained about a CRC
  error, so I could not.

To manage notifications about this bug go to:
https://bugs.launchpad.net/qemu/+bug/918791/+subscriptions



Re: [Qemu-devel] Live Block Migration using Mirroring

2012-02-23 Thread Federico Simoncelli
- Original Message -
 From: Stefan Hajnoczi stefa...@gmail.com
 To: Federico Simoncelli fsimo...@redhat.com
 Cc: qemu-devel@nongnu.org, kw...@redhat.com, mtosa...@redhat.com
 Sent: Thursday, February 23, 2012 5:35:23 PM
 Subject: Re: [Qemu-devel] Live Block Migration using Mirroring

 On Wed, Feb 22, 2012 at 5:13 PM, Federico Simoncelli
 fsimo...@redhat.com wrote:
   recently I've been working on live block migration combining the
   live
  snapshots and the blkmirror patch sent by Marcelo Tosatti few
  months ago.
 
  The design is summarized at this url as Mirrored-Snapshot:
 
  http://www.ovirt.org/wiki/Features/Design/StorageLiveMigration

 After mirrored-snapshot completes we're left with the base and the
 snapshot.  Is the idea to implement live snapshot merge next?  Or do
 you have something else planned to avoid growing the backing file
 chain each time mirrored-snapshot is used?

The general idea is that I don't expect the need to migrate to a new
storage to be very frequent. Being able to live merge the new snapshot
would be great.

--
Federico



Re: [Qemu-devel] VirtIO 9p mount_tag (bogus?) limit of 32 bytes

2012-02-23 Thread Aneesh Kumar K.V
On Tue, 21 Feb 2012 21:58:39 -0600, C Anthony Risinger anth...@xtfx.me wrote:
 On Sat, Feb 18, 2012 at 11:38 AM, Aneesh Kumar K.V
 aneesh.ku...@linux.vnet.ibm.com wrote:
  On Thu, 16 Feb 2012 06:20:21 -0600, C Anthony Risinger anth...@xtfx.me 
  wrote:
  a) mapped FS security policy (xattrs) causes `ldconfig` to abort()?
  root or normal user ...
 
  somehow `ldconfig` gets a duplicate inode while constructing the
  cache, even though it already de-duped (confirmed via gdb and grep --
  only a single abort() in the source)
 

I will try to reproduce this to get more info.


  b) unable to run `locale-gen` on *any* virtfs configuration? (strace)
 
  [...]
  mmap(NULL, 536870912, PROT_NONE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) =
  0x7fb3aac63000
  mmap(0x7fb3aac63000, 103860, PROT_READ|PROT_WRITE,
  MAP_SHARED|MAP_FIXED, 3, 0) = -1 EINVAL (Invalid argument)
  cannot map archive header: Invalid argument
 

For writable mmap to work you need to mount with -o cache=loose. Did
you try local-gen with that mount option ?


  c) package files containing device nodes fail (maybe this is expected
  ...); specifically `/lib/udev/devices/loop0`
 
 

Does this mean mknod fails for you. Or is something else in package
manager causing the failure ? 


  Is this with 9p2000.L ?. What is the guest kernel version ?
 
 (not sure if list will accept this ... too much traffic! had to remove myself)
 
 yes this is with 9p2000.L, both host and guests run kernel 3.2.5.  i'm
 happy to provide/try additional information/tests if useful.
 

One quick thing you could do is to try latest linus kernel as the guest
kernel. 

 ... is there really no chance of upping the max path?  seems like
 config space will be a big constraint, forever :-(
 
 and i'm very much willing to do additional testing for the other
 issues as well (i had to revert to qemu-as-root to get passthru
 working 100% on rootfs ... ldconfig is kind of critical :-).  are
 these known issues?
 

I don't have much suggestion on what could be going wrong there. I will
try to reproduce the ldconfig issue here.

-aneesh




Re: [Qemu-devel] qemu assertion failed with usb on current git master!

2012-02-23 Thread Erik Rull

Gerd Hoffmann wrote:

On 02/23/12 12:38, Erik Rull wrote:

  When running qemu with -device usb-host an assertion failed caused by
attaching a new usb device to the host that gets routed to the guest.

The assertion that fails is:

qemu-system-x86_64: /home/erik/qemu/hw/usb.c:358 usb_packet_complete:
Assertion 'p-state == USB_PACKET_QUEUED' failed.


Stacktrace?
What kind of device?

Can you enable the debug logging code in usb_packet_set_state() and send
a log?

thanks,
   Gerd




I don't have gdb installed on my target system. May take some time until I 
have the backtrace, maybe remote debugging will work.
I just plugged in a USB key with 8 Gig, but happens with another USB key 
with 2 Gig from another manufacturer as well. Both are USB 2.0 devices.


Best regards,

Erik



Re: [Qemu-devel] linux guests and ksm performance

2012-02-23 Thread Javier Guerra Giraldez
On Thu, Feb 23, 2012 at 11:42 AM, Stefan Hajnoczi stefa...@gmail.com wrote:
 The other approach is a memory page discard mechanism - which
 obviously requires more code changes than zeroing freed pages.

 The advantage is that we don't take the brute-force and CPU intensive
 approach of zeroing pages.  It would be like a fine-grained ballooning
 feature.

(disclaimer: i don't know the code, i'm just guessing)

does KVM emulate the MMU? if so, is there any 'unmap page' primitive?

-- 
Javier



Re: [Qemu-devel] linux guests and ksm performance

2012-02-23 Thread peter.lie...@gmail.com




Stefan Hajnoczi stefa...@gmail.com schrieb:

On Thu, Feb 23, 2012 at 3:40 PM, Peter Lieven p...@dlh.net wrote:
 However, in a virtual machine I have not observed the above slow down
to
 that extend
 while the benefit of zero after free in a virtualisation environment
is
 obvious:

 1) zero pages can easily be merged by ksm or other technique.
 2) zero (dup) pages are a lot faster to transfer in case of
migration.

The other approach is a memory page discard mechanism - which
obviously requires more code changes than zeroing freed pages.

The advantage is that we don't take the brute-force and CPU intensive
approach of zeroing pages.  It would be like a fine-grained ballooning
feature.


I dont think that it is cpu intense. All user pages are zeroed anyway, but at 
allocation time it shouldnt be a big difference in terms of cpu power.

I hope someone will follow up saying this has already been done or
prototyped :).

Stefan

-- 
Diese Nachricht wurde von meinem Android-Mobiltelefon mit K-9 Mail gesendet.



Re: [Qemu-devel] arm-linux-user, i386-linux-user: Make QEMU act as TCG compiler

2012-02-23 Thread Rajat Goyal
Hi Peter,

Would QEMU developers be interested in integrating this TCG compilation
functionality that I have been working on into later releases of QEMU? The
patch I have right now breaks the original emulation but if there is some
interest in supporting static compilation into TCG in the future, I can
submit a clean patch which does not break emulation but instead adds a
run-time option to generate TCG compilation. I would be grateful if you
could let me know.

Many thanks in anticipation.

With warm regards,
Rajat.

2012/2/23 Rajat Goyal rajat.go...@cl.cam.ac.uk

 QEMU as a dynamic translator is already available. This adds extra
 functionality to QEMU. I needed to do this since I wanted to explore the
 ARM memory model over TCG micro-operations; so I needed translation of the
 whole binary and not just the parts which QEMU needs to execute. Don't know
 if others would find this feature useful.

 Rajat.


 On Thu, Feb 23, 2012 at 3:57 AM, 陳韋任 che...@iis.sinica.edu.tw wrote:

 Hi Rajat,

  Great work! It seems this is a kind of like static compilation, right? I
 think
 people are more interested in using QEMU as a dynamic translator as a
 library.
 Would you mind to tell me what scenario your work aims to?

 Regards,
 chenwj

 --
 Wei-Ren Chen (陳韋任)
 Computer Systems Lab, Institute of Information Science,
 Academia Sinica, Taiwan (R.O.C.)
 Tel:886-2-2788-3799 #1667
 Homepage: http://people.cs.nctu.edu.tw/~chenwj





Re: [Qemu-devel] PCI: Add PCI_EXP_TYPE_PCIE_BRIDGE value

2012-02-23 Thread Jesse Barnes
On Tue, 21 Feb 2012 16:22:10 +
Anthony PERARD anthony.per...@citrix.com wrote:

 Signed-off-by: Anthony PERARD anthony.per...@citrix.com
 
 ---
  include/linux/pci_regs.h |1 +
  1 files changed, 1 insertions(+), 0 deletions(-)
 
 diff --git a/include/linux/pci_regs.h b/include/linux/pci_regs.h
 index e41a10f..4b608f5 100644
 --- a/include/linux/pci_regs.h
 +++ b/include/linux/pci_regs.h
 @@ -391,6 +391,7 @@
  #define  PCI_EXP_TYPE_UPSTREAM   0x5 /* Upstream Port */
  #define  PCI_EXP_TYPE_DOWNSTREAM 0x6 /* Downstream Port */
  #define  PCI_EXP_TYPE_PCI_BRIDGE 0x7 /* PCI/PCI-X Bridge */
 +#define  PCI_EXP_TYPE_PCIE_BRIDGE 0x8/* PCI/PCI-X to PCIE Bridge */
  #define  PCI_EXP_TYPE_RC_END 0x9 /* Root Complex Integrated Endpoint */
  #define  PCI_EXP_TYPE_RC_EC  0xa /* Root Complex Event Collector */
  #define PCI_EXP_FLAGS_SLOT   0x0100  /* Slot implemented */

Applied, thanks.

-- 
Jesse Barnes, Intel Open Source Technology Center


signature.asc
Description: PGP signature


Re: [Qemu-devel] [PATCH V7 03/11] pci_regs: Add PCI_EXP_TYPE_PCIE_BRIDGE

2012-02-23 Thread Michael S. Tsirkin
On Fri, Feb 17, 2012 at 05:08:37PM +, Anthony PERARD wrote:
 Signed-off-by: Anthony PERARD anthony.per...@citrix.com

Applied, thanks.

 ---
  hw/pci_regs.h |1 +
  1 files changed, 1 insertions(+), 0 deletions(-)
 
 diff --git a/hw/pci_regs.h b/hw/pci_regs.h
 index 6b42515..56a404b 100644
 --- a/hw/pci_regs.h
 +++ b/hw/pci_regs.h
 @@ -392,6 +392,7 @@
  #define  PCI_EXP_TYPE_UPSTREAM   0x5 /* Upstream Port */
  #define  PCI_EXP_TYPE_DOWNSTREAM 0x6 /* Downstream Port */
  #define  PCI_EXP_TYPE_PCI_BRIDGE 0x7 /* PCI/PCI-X Bridge */
 +#define  PCI_EXP_TYPE_PCIE_BRIDGE 0x8   /* PCI/PCI-X to PCIE Bridge */
  #define  PCI_EXP_TYPE_RC_END 0x9 /* Root Complex Integrated Endpoint */
  #define  PCI_EXP_TYPE_RC_EC 0xa /* Root Complex Event Collector */
  #define PCI_EXP_FLAGS_SLOT   0x0100  /* Slot implemented */
 -- 
 Anthony PERARD
 



[Qemu-devel] [PATCH v2 0/6] add fixed-width visitors and serialization tests

2012-02-23 Thread Michael Roth
These patches apply on top of qemu.git master, and can also be obtained from:
git://github.com/mdroth/qemu.git visitor-fixed-width-v2

CHANGES SINCE V1:
 - unit tests: covert QmpOutputVisitor qobject to json before passing it to
   QmpInputVisitor*. I.e., actually do the serialization :)
 - QmpInputVisitor, add handling for when a serialized QFloat gets read back
   as a QInt
 - unit tests: add coverage for String visitor
 - StringOutputVisitor: use %f for float representation

These patches add fixed-width visitor types and switches all qdev users over to
them.

We also add a test suite which covers these, as well as does some sanity
checking on Visitors to verify their usability/capabilities for data
serialization.




[Qemu-devel] [PATCH v2 1/6] qapi: add Visitor interfaces for uint*_t and int*_t

2012-02-23 Thread Michael Roth
This adds visitor interfaces for fixed-width integers types.
Implementing these in visitors is optional, otherwise we fall back to
visit_type_int() (int64_t) with some additional bounds checking to avoid
integer overflows for cases where the value fetched exceeds the bounds
of our target C type.

Signed-off-by: Michael Roth mdr...@linux.vnet.ibm.com
---
 hw/mc146818rtc.c   |7 ---
 qapi/qapi-visit-core.c |  139 
 qapi/qapi-visit-core.h |   16 ++
 3 files changed, 155 insertions(+), 7 deletions(-)

diff --git a/hw/mc146818rtc.c b/hw/mc146818rtc.c
index 6c1ad38..a5d45d4 100644
--- a/hw/mc146818rtc.c
+++ b/hw/mc146818rtc.c
@@ -621,13 +621,6 @@ static const MemoryRegionOps cmos_ops = {
 .old_portio = cmos_portio
 };
 
-// FIXME add int32 visitor
-static void visit_type_int32(Visitor *v, int *value, const char *name, Error 
**errp)
-{
-int64_t val = *value;
-visit_type_int(v, val, name, errp);
-}
-
 static void rtc_get_date(Object *obj, Visitor *v, void *opaque,
  const char *name, Error **errp)
 {
diff --git a/qapi/qapi-visit-core.c b/qapi/qapi-visit-core.c
index a4e088c..6823e84 100644
--- a/qapi/qapi-visit-core.c
+++ b/qapi/qapi-visit-core.c
@@ -97,6 +97,145 @@ void visit_type_int(Visitor *v, int64_t *obj, const char 
*name, Error **errp)
 }
 }
 
+void visit_type_uint8(Visitor *v, uint8_t *obj, const char *name, Error **errp)
+{
+int64_t value;
+if (!error_is_set(errp)) {
+if (v-type_uint8) {
+v-type_uint8(v, obj, name, errp);
+} else {
+value = *obj;
+v-type_int(v, value, name, errp);
+if (value  UINT8_MAX) {
+error_set(errp, QERR_INVALID_PARAMETER_VALUE, name ? name : 
null,
+  uint8_t);
+return;
+}
+*obj = value;
+}
+}
+}
+
+void visit_type_uint16(Visitor *v, uint16_t *obj, const char *name, Error 
**errp)
+{
+int64_t value;
+if (!error_is_set(errp)) {
+if (v-type_uint16) {
+v-type_uint16(v, obj, name, errp);
+} else {
+value = *obj;
+v-type_int(v, value, name, errp);
+if (value  UINT16_MAX) {
+error_set(errp, QERR_INVALID_PARAMETER_VALUE, name ? name : 
null,
+  uint16_t);
+return;
+}
+*obj = value;
+}
+}
+}
+
+void visit_type_uint32(Visitor *v, uint32_t *obj, const char *name, Error 
**errp)
+{
+int64_t value;
+if (!error_is_set(errp)) {
+if (v-type_uint32) {
+v-type_uint32(v, obj, name, errp);
+} else {
+value = *obj;
+v-type_int(v, value, name, errp);
+if (value  UINT32_MAX) {
+error_set(errp, QERR_INVALID_PARAMETER_VALUE, name ? name : 
null,
+  uint32_t);
+return;
+}
+*obj = value;
+}
+}
+}
+
+void visit_type_uint64(Visitor *v, uint64_t *obj, const char *name, Error 
**errp)
+{
+int64_t value;
+if (!error_is_set(errp)) {
+if (v-type_uint64) {
+v-type_uint64(v, obj, name, errp);
+} else {
+value = *obj;
+v-type_int(v, value, name, errp);
+*obj = value;
+}
+}
+}
+
+void visit_type_int8(Visitor *v, int8_t *obj, const char *name, Error **errp)
+{
+int64_t value;
+if (!error_is_set(errp)) {
+if (v-type_int8) {
+v-type_int8(v, obj, name, errp);
+} else {
+value = *obj;
+v-type_int(v, value, name, errp);
+if (value  INT8_MIN || value  INT8_MAX) {
+error_set(errp, QERR_INVALID_PARAMETER_VALUE, name ? name : 
null,
+  int8_t);
+return;
+}
+*obj = value;
+}
+}
+}
+
+void visit_type_int16(Visitor *v, int16_t *obj, const char *name, Error **errp)
+{
+int64_t value;
+if (!error_is_set(errp)) {
+if (v-type_int16) {
+v-type_int16(v, obj, name, errp);
+} else {
+value = *obj;
+v-type_int(v, value, name, errp);
+if (value  INT16_MIN || value  INT16_MAX) {
+error_set(errp, QERR_INVALID_PARAMETER_VALUE, name ? name : 
null,
+  int16_t);
+return;
+}
+*obj = value;
+}
+}
+}
+
+void visit_type_int32(Visitor *v, int32_t *obj, const char *name, Error **errp)
+{
+int64_t value;
+if (!error_is_set(errp)) {
+if (v-type_int32) {
+v-type_int32(v, obj, name, errp);
+} else {
+value = *obj;
+v-type_int(v, value, name, errp);
+if (value  INT32_MIN || value  INT32_MAX) {
+error_set(errp, QERR_INVALID_PARAMETER_VALUE, name ? name : 
null,
+   

[Qemu-devel] [PATCH v2 4/6] qapi: add String visitor coverage to serialization unit tests

2012-02-23 Thread Michael Roth

Signed-off-by: Michael Roth mdr...@linux.vnet.ibm.com
---
 test-visitor-serialization.c |   40 
 1 files changed, 40 insertions(+), 0 deletions(-)

diff --git a/test-visitor-serialization.c b/test-visitor-serialization.c
index 6ef57d0..b8ad16f 100644
--- a/test-visitor-serialization.c
+++ b/test-visitor-serialization.c
@@ -19,6 +19,8 @@
 #include qemu-objects.h
 #include qapi/qmp-input-visitor.h
 #include qapi/qmp-output-visitor.h
+#include qapi/string-input-visitor.h
+#include qapi/string-output-visitor.h
 
 typedef struct PrimitiveType {
 union {
@@ -666,6 +668,37 @@ static void qmp_cleanup(void *datap)
 qmp_input_visitor_cleanup(d-qiv);
 }
 
+typedef struct StringSerializeData {
+StringOutputVisitor *sov;
+StringInputVisitor *siv;
+} StringSerializeData;
+
+static void string_serialize(void *native_in, void **datap,
+ VisitorFunc visit, Error **errp)
+{
+StringSerializeData *d = g_malloc0(sizeof(*d));
+
+d-sov = string_output_visitor_new();
+visit(string_output_get_visitor(d-sov), native_in, errp);
+*datap = d;
+}
+
+static void string_deserialize(void **native_out, void *datap,
+   VisitorFunc visit, Error **errp)
+{
+StringSerializeData *d = datap;
+
+d-siv = string_input_visitor_new(string_output_get_string(d-sov));
+visit(string_input_get_visitor(d-siv), native_out, errp);
+}
+
+static void string_cleanup(void *datap)
+{
+StringSerializeData *d = datap;
+string_output_visitor_cleanup(d-sov);
+string_input_visitor_cleanup(d-siv);
+}
+
 /* visitor registration, test harness */
 
 /* note: to function interchangeably as a serialization mechanism your
@@ -680,6 +713,13 @@ static const SerializeOps visitors[] = {
 .cleanup = qmp_cleanup,
 .caps = VCAP_PRIMITIVES | VCAP_STRUCTURES | VCAP_LISTS
 },
+{
+.type = String,
+.serialize = string_serialize,
+.deserialize = string_deserialize,
+.cleanup = string_cleanup,
+.caps = VCAP_PRIMITIVES
+},
 { NULL }
 };
 
-- 
1.7.4.1




[Qemu-devel] [PATCH v2 6/6] qdev: switch property accessors to fixed-width visitor interfaces

2012-02-23 Thread Michael Roth

Signed-off-by: Michael Roth mdr...@linux.vnet.ibm.com
---
 hw/qdev-addr.c   |4 ++--
 hw/qdev-properties.c |   42 +-
 2 files changed, 19 insertions(+), 27 deletions(-)

diff --git a/hw/qdev-addr.c b/hw/qdev-addr.c
index 0bb16c7..b711b6b 100644
--- a/hw/qdev-addr.c
+++ b/hw/qdev-addr.c
@@ -27,7 +27,7 @@ static void get_taddr(Object *obj, Visitor *v, void *opaque,
 int64_t value;
 
 value = *ptr;
-visit_type_int(v, value, name, errp);
+visit_type_int64(v, value, name, errp);
 }
 
 static void set_taddr(Object *obj, Visitor *v, void *opaque,
@@ -44,7 +44,7 @@ static void set_taddr(Object *obj, Visitor *v, void *opaque,
 return;
 }
 
-visit_type_int(v, value, name, local_err);
+visit_type_int64(v, value, name, local_err);
 if (local_err) {
 error_propagate(errp, local_err);
 return;
diff --git a/hw/qdev-properties.c b/hw/qdev-properties.c
index 0423af1..98d95fb 100644
--- a/hw/qdev-properties.c
+++ b/hw/qdev-properties.c
@@ -82,10 +82,8 @@ static void get_int8(Object *obj, Visitor *v, void *opaque,
 DeviceState *dev = DEVICE(obj);
 Property *prop = opaque;
 int8_t *ptr = qdev_get_prop_ptr(dev, prop);
-int64_t value;
 
-value = *ptr;
-visit_type_int(v, value, name, errp);
+visit_type_int8(v, ptr, name, errp);
 }
 
 static void set_int8(Object *obj, Visitor *v, void *opaque,
@@ -93,16 +91,15 @@ static void set_int8(Object *obj, Visitor *v, void *opaque,
 {
 DeviceState *dev = DEVICE(obj);
 Property *prop = opaque;
-int8_t *ptr = qdev_get_prop_ptr(dev, prop);
+int8_t value, *ptr = qdev_get_prop_ptr(dev, prop);
 Error *local_err = NULL;
-int64_t value;
 
 if (dev-state != DEV_STATE_CREATED) {
 error_set(errp, QERR_PERMISSION_DENIED);
 return;
 }
 
-visit_type_int(v, value, name, local_err);
+visit_type_int8(v, value, name, local_err);
 if (local_err) {
 error_propagate(errp, local_err);
 return;
@@ -111,7 +108,7 @@ static void set_int8(Object *obj, Visitor *v, void *opaque,
 *ptr = value;
 } else {
 error_set(errp, QERR_PROPERTY_VALUE_OUT_OF_RANGE,
-  dev-id?:, name, value, prop-info-min,
+  dev-id?:, name, (int64_t)value, prop-info-min,
   prop-info-max);
 }
 }
@@ -168,10 +165,8 @@ static void get_int16(Object *obj, Visitor *v, void 
*opaque,
 DeviceState *dev = DEVICE(obj);
 Property *prop = opaque;
 int16_t *ptr = qdev_get_prop_ptr(dev, prop);
-int64_t value;
 
-value = *ptr;
-visit_type_int(v, value, name, errp);
+visit_type_int16(v, ptr, name, errp);
 }
 
 static void set_int16(Object *obj, Visitor *v, void *opaque,
@@ -179,16 +174,15 @@ static void set_int16(Object *obj, Visitor *v, void 
*opaque,
 {
 DeviceState *dev = DEVICE(obj);
 Property *prop = opaque;
-int16_t *ptr = qdev_get_prop_ptr(dev, prop);
+int16_t value, *ptr = qdev_get_prop_ptr(dev, prop);
 Error *local_err = NULL;
-int64_t value;
 
 if (dev-state != DEV_STATE_CREATED) {
 error_set(errp, QERR_PERMISSION_DENIED);
 return;
 }
 
-visit_type_int(v, value, name, local_err);
+visit_type_int16(v, value, name, local_err);
 if (local_err) {
 error_propagate(errp, local_err);
 return;
@@ -197,7 +191,7 @@ static void set_int16(Object *obj, Visitor *v, void *opaque,
 *ptr = value;
 } else {
 error_set(errp, QERR_PROPERTY_VALUE_OUT_OF_RANGE,
-  dev-id?:, name, value, prop-info-min,
+  dev-id?:, name, (int64_t)value, prop-info-min,
   prop-info-max);
 }
 }
@@ -217,11 +211,10 @@ static void get_int32(Object *obj, Visitor *v, void 
*opaque,
 {
 DeviceState *dev = DEVICE(obj);
 Property *prop = opaque;
-int32_t *ptr = qdev_get_prop_ptr(dev, prop);
-int64_t value;
+int32_t value, *ptr = qdev_get_prop_ptr(dev, prop);
 
 value = *ptr;
-visit_type_int(v, value, name, errp);
+visit_type_int32(v, value, name, errp);
 }
 
 static void set_int32(Object *obj, Visitor *v, void *opaque,
@@ -229,16 +222,15 @@ static void set_int32(Object *obj, Visitor *v, void 
*opaque,
 {
 DeviceState *dev = DEVICE(obj);
 Property *prop = opaque;
-int32_t *ptr = qdev_get_prop_ptr(dev, prop);
+int32_t value, *ptr = qdev_get_prop_ptr(dev, prop);
 Error *local_err = NULL;
-int64_t value;
 
 if (dev-state != DEV_STATE_CREATED) {
 error_set(errp, QERR_PERMISSION_DENIED);
 return;
 }
 
-visit_type_int(v, value, name, local_err);
+visit_type_int32(v, value, name, local_err);
 if (local_err) {
 error_propagate(errp, local_err);
 return;
@@ -247,7 +239,7 @@ static void set_int32(Object *obj, Visitor *v, void *opaque,
 *ptr = value;
 } else {
 error_set(errp, QERR_PROPERTY_VALUE_OUT_OF_RANGE,
-  dev-id?:, 

[Qemu-devel] [PATCH v2 3/6] qapi: QMP input visitor, handle floats parsed as ints

2012-02-23 Thread Michael Roth
JSON numbers can be interpreted as either integers or floating point
values depending on their representation. As a result, QMP input visitor
might visit a QInt when it was expecting a QFloat, so add handling to
account for this.

Signed-off-by: Michael Roth mdr...@linux.vnet.ibm.com
---
 qapi/qmp-input-visitor.c |9 +++--
 1 files changed, 7 insertions(+), 2 deletions(-)

diff --git a/qapi/qmp-input-visitor.c b/qapi/qmp-input-visitor.c
index e6b6152..f7ffb59 100644
--- a/qapi/qmp-input-visitor.c
+++ b/qapi/qmp-input-visitor.c
@@ -209,13 +209,18 @@ static void qmp_input_type_number(Visitor *v, double 
*obj, const char *name,
 QmpInputVisitor *qiv = to_qiv(v);
 const QObject *qobj = qmp_input_get_object(qiv, name);
 
-if (!qobj || qobject_type(qobj) != QTYPE_QFLOAT) {
+if (!qobj || (qobject_type(qobj) != QTYPE_QFLOAT 
+qobject_type(qobj) != QTYPE_QINT)) {
 error_set(errp, QERR_INVALID_PARAMETER_TYPE, name ? name : null,
   double);
 return;
 }
 
-*obj = qfloat_get_double(qobject_to_qfloat(qobj));
+if (qobject_type(qobj) == QTYPE_QINT) {
+*obj = qint_get_int(qobject_to_qint(qobj));
+} else {
+*obj = qfloat_get_double(qobject_to_qfloat(qobj));
+}
 }
 
 static void qmp_input_start_optional(Visitor *v, bool *present,
-- 
1.7.4.1




Re: [Qemu-devel] [PATCH V14 2/7] Add TPM (frontend) hardware interface (TPM TIS) to Qemu

2012-02-23 Thread Stefan Berger

On 02/20/2012 10:48 AM, Stefan Berger wrote:

On 02/20/2012 03:51 AM, Michael S. Tsirkin wrote:



+static const MemoryRegionOps tpm_tis_memory_ops = {
+.read = tpm_tis_mmio_read,
+.write = tpm_tis_mmio_write,
+.endianness = DEVICE_NATIVE_ENDIAN,

Are you sure? Most devices are BIG or LITTLE.



Right, it should be BIG endian. I'll fix it. Luckily there are only a 
few 32bit accesses (and no 16bit access) also in 


Replace that with 'LITTLE endian'.

   Stefan




[Qemu-devel] [PATCH v2 2/6] qapi: unit tests for visitor-based serialization

2012-02-23 Thread Michael Roth
Currently we test our visitors individually, and seperately for input
vs. output. This is useful for validating internal representations
against the native C types and vice-versa, and other visitor-specific
testing, but it doesn't cover the potential use-case of using visitor
pairs for serialization/deserialization very well, and makes it
hard to easily extend the coverage for different C types / boundary
conditions.

To cover that we add a set of unit tests that takes a number of native C
values, passes them into an output visitor, extracts the values with an
input visitor, then compares the result to the original.

Plugging in new visitors to the test harness only requires a user to
implement the SerializeOps interface and add it to a list.

Signed-off-by: Michael Roth mdr...@linux.vnet.ibm.com
---
 test-visitor-serialization.c |  744 ++
 tests/Makefile   |6 +-
 2 files changed, 749 insertions(+), 1 deletions(-)
 create mode 100644 test-visitor-serialization.c

diff --git a/test-visitor-serialization.c b/test-visitor-serialization.c
new file mode 100644
index 000..6ef57d0
--- /dev/null
+++ b/test-visitor-serialization.c
@@ -0,0 +1,744 @@
+/*
+ * Unit-tests for visitor-based serialization
+ *
+ * Copyright IBM, Corp. 2012
+ *
+ * Authors:
+ *  Michael Roth mdr...@linux.vnet.ibm.com
+ *
+ * This work is licensed under the terms of the GNU GPL, version 2 or later.
+ * See the COPYING file in the top-level directory.
+ */
+
+#include glib.h
+#include stdlib.h
+#include stdint.h
+#include float.h
+#include test-qapi-types.h
+#include test-qapi-visit.h
+#include qemu-objects.h
+#include qapi/qmp-input-visitor.h
+#include qapi/qmp-output-visitor.h
+
+typedef struct PrimitiveType {
+union {
+const char *string;
+bool boolean;
+double number;
+int64_t integer;
+uint8_t u8;
+uint16_t u16;
+uint32_t u32;
+uint64_t u64;
+int8_t s8;
+int16_t s16;
+int32_t s32;
+int64_t s64;
+intmax_t max;
+} value;
+enum {
+PTYPE_STRING = 0,
+PTYPE_BOOLEAN,
+PTYPE_NUMBER,
+PTYPE_INTEGER,
+PTYPE_U8,
+PTYPE_U16,
+PTYPE_U32,
+PTYPE_U64,
+PTYPE_S8,
+PTYPE_S16,
+PTYPE_S32,
+PTYPE_S64,
+PTYPE_EOL,
+} type;
+const char *description;
+} PrimitiveType;
+
+/* test helpers */
+
+static void visit_primitive_type(Visitor *v, void **native, Error **errp)
+{
+PrimitiveType *pt = *native;
+switch(pt-type) {
+case PTYPE_STRING:
+visit_type_str(v, (char **)pt-value.string, NULL, errp);
+break;
+case PTYPE_BOOLEAN:
+visit_type_bool(v, pt-value.boolean, NULL, errp);
+break;
+case PTYPE_NUMBER:
+visit_type_number(v, pt-value.number, NULL, errp);
+break;
+case PTYPE_INTEGER:
+visit_type_int(v, pt-value.integer, NULL, errp);
+break;
+case PTYPE_U8:
+visit_type_uint8(v, pt-value.u8, NULL, errp);
+break;
+case PTYPE_U16:
+visit_type_uint16(v, pt-value.u16, NULL, errp);
+break;
+case PTYPE_U32:
+visit_type_uint32(v, pt-value.u32, NULL, errp);
+break;
+case PTYPE_U64:
+visit_type_uint64(v, pt-value.u64, NULL, errp);
+break;
+case PTYPE_S8:
+visit_type_int8(v, pt-value.s8, NULL, errp);
+break;
+case PTYPE_S16:
+visit_type_int16(v, pt-value.s16, NULL, errp);
+break;
+case PTYPE_S32:
+visit_type_int32(v, pt-value.s32, NULL, errp);
+break;
+case PTYPE_S64:
+visit_type_int64(v, pt-value.s64, NULL, errp);
+break;
+case PTYPE_EOL:
+g_assert(false);
+}
+}
+
+typedef struct TestStruct
+{
+int64_t integer;
+bool boolean;
+char *string;
+} TestStruct;
+
+static void visit_type_TestStruct(Visitor *v, TestStruct **obj,
+  const char *name, Error **errp)
+{
+visit_start_struct(v, (void **)obj, NULL, name, sizeof(TestStruct), errp);
+
+visit_type_int(v, (*obj)-integer, integer, errp);
+visit_type_bool(v, (*obj)-boolean, boolean, errp);
+visit_type_str(v, (*obj)-string, string, errp);
+
+visit_end_struct(v, errp);
+}
+
+static TestStruct *struct_create(void)
+{
+TestStruct *ts = g_malloc0(sizeof(*ts));
+ts-integer = -42;
+ts-boolean = true;
+ts-string = strdup(test string);
+return ts;
+}
+
+static void struct_compare(TestStruct *ts1, TestStruct *ts2)
+{
+g_assert(ts1);
+g_assert(ts2);
+g_assert_cmpint(ts1-integer, ==, ts2-integer);
+g_assert(ts1-boolean == ts2-boolean);
+g_assert_cmpstr(ts1-string, ==, ts2-string);
+}
+
+static void struct_cleanup(TestStruct *ts)
+{
+g_free(ts-string);
+g_free(ts);
+}
+
+static void visit_struct(Visitor *v, void **native, Error **errp)
+{
+visit_type_TestStruct(v, (TestStruct 

  1   2   >