[Qemu-devel] [PATCH] pc87312: avoid define conflict on mingw32

2013-01-13 Thread Blue Swirl
Mingw32 headers define FAR, causing this warning:
/src/qemu/hw/pc87312.c:38:0: warning: FAR redefined [enabled by default]
In file included from 
/usr/local/lib/gcc/i686-mingw32msvc/4.7.0/../../../../i686-mingw32msvc/include/windows.h:48:0,
 from /src/qemu/include/sysemu/os-win32.h:29,
 from /src/qemu/include/qemu-common.h:46,
 from /src/qemu/include/exec/ioport.h:27,
 from /src/qemu/hw/isa.h:6,
 from /src/qemu/hw/pc87312.h:28,
 from /src/qemu/hw/pc87312.c:26:
/usr/local/lib/gcc/i686-mingw32msvc/4.7.0/../../../../i686-mingw32msvc/include/windef.h:34:0:
 note: this is the location of the previous definition

Avoid the warning by expanding the macros.

Signed-off-by: Blue Swirl blauwir...@gmail.com
---
 hw/pc87312.c |   38 +-
 1 files changed, 17 insertions(+), 21 deletions(-)

diff --git a/hw/pc87312.c b/hw/pc87312.c
index 6a17afd..0ef6886 100644
--- a/hw/pc87312.c
+++ b/hw/pc87312.c
@@ -34,10 +34,6 @@
 #define REG_FAR 1
 #define REG_PTR 2
 
-#define FER regs[REG_FER]
-#define FAR regs[REG_FAR]
-#define PTR regs[REG_PTR]
-
 #define FER_PARALLEL_EN   0x01
 #define FER_UART1_EN  0x02
 #define FER_UART2_EN  0x04
@@ -66,14 +62,14 @@
 
 static inline bool is_parallel_enabled(PC87312State *s)
 {
-return s-FER  FER_PARALLEL_EN;
+return s-regs[REG_FER]  FER_PARALLEL_EN;
 }
 
 static const uint32_t parallel_base[] = { 0x378, 0x3bc, 0x278, 0x00 };
 
 static inline uint32_t get_parallel_iobase(PC87312State *s)
 {
-return parallel_base[s-FAR  FAR_PARALLEL_ADDR];
+return parallel_base[s-regs[REG_FAR]  FAR_PARALLEL_ADDR];
 }
 
 static const uint32_t parallel_irq[] = { 5, 7, 5, 0 };
@@ -81,9 +77,9 @@ static const uint32_t parallel_irq[] = { 5, 7, 5, 0 };
 static inline uint32_t get_parallel_irq(PC87312State *s)
 {
 int idx;
-idx = (s-FAR  FAR_PARALLEL_ADDR);
+idx = (s-regs[REG_FAR]  FAR_PARALLEL_ADDR);
 if (idx == 0) {
-return (s-PTR  PTR_IRQ_5_7) ? 7 : 5;
+return (s-regs[REG_PTR]  PTR_IRQ_5_7) ? 7 : 5;
 } else {
 return parallel_irq[idx];
 }
@@ -91,7 +87,7 @@ static inline uint32_t get_parallel_irq(PC87312State *s)
 
 static inline bool is_parallel_epp(PC87312State *s)
 {
-return s-PTR  PTR_EPP_MODE;
+return s-regs[REG_PTR]  PTR_EPP_MODE;
 }
 
 
@@ -105,26 +101,26 @@ static const uint32_t uart_base[2][4] = {
 static inline uint32_t get_uart_iobase(PC87312State *s, int i)
 {
 int idx;
-idx = (s-FAR  (2 * i + 2))  0x3;
+idx = (s-regs[REG_FAR]  (2 * i + 2))  0x3;
 if (idx == 0) {
 return 0x3f8;
 } else if (idx == 1) {
 return 0x2f8;
 } else {
-return uart_base[idx  1][(s-FAR  FAR_UART_3_4)  6];
+return uart_base[idx  1][(s-regs[REG_FAR]  FAR_UART_3_4)  6];
 }
 }
 
 static inline uint32_t get_uart_irq(PC87312State *s, int i)
 {
 int idx;
-idx = (s-FAR  (2 * i + 2))  0x3;
+idx = (s-regs[REG_FAR]  (2 * i + 2))  0x3;
 return (idx  1) ? 3 : 4;
 }
 
 static inline bool is_uart_enabled(PC87312State *s, int i)
 {
-return s-FER  (FER_UART1_EN  i);
+return s-regs[REG_FER]  (FER_UART1_EN  i);
 }
 
 
@@ -132,12 +128,12 @@ static inline bool is_uart_enabled(PC87312State *s, int i)
 
 static inline bool is_fdc_enabled(PC87312State *s)
 {
-return s-FER  FER_FDC_EN;
+return s-regs[REG_FER]  FER_FDC_EN;
 }
 
 static inline uint32_t get_fdc_iobase(PC87312State *s)
 {
-return (s-FER  FER_FDC_ADDR) ? 0x370 : 0x3f0;
+return (s-regs[REG_FER]  FER_FDC_ADDR) ? 0x370 : 0x3f0;
 }
 
 
@@ -145,19 +141,19 @@ static inline uint32_t get_fdc_iobase(PC87312State *s)
 
 static inline bool is_ide_enabled(PC87312State *s)
 {
-return s-FER  FER_IDE_EN;
+return s-regs[REG_FER]  FER_IDE_EN;
 }
 
 static inline uint32_t get_ide_iobase(PC87312State *s)
 {
-return (s-FER  FER_IDE_ADDR) ? 0x170 : 0x1f0;
+return (s-regs[REG_FER]  FER_IDE_ADDR) ? 0x170 : 0x1f0;
 }
 
 
 static void reconfigure_devices(PC87312State *s)
 {
 error_report(pc87312: unsupported device reconfiguration (%02x %02x 
%02x),
- s-FER, s-FAR, s-PTR);
+ s-regs[REG_FER], s-regs[REG_FAR], s-regs[REG_PTR]);
 }
 
 static void pc87312_soft_reset(PC87312State *s)
@@ -184,9 +180,9 @@ static void pc87312_soft_reset(PC87312State *s)
 s-read_id_step = 0;
 s-selected_index = REG_FER;
 
-s-FER = fer_init[s-config  0x1f];
-s-FAR = far_init[s-config  0x1f];
-s-PTR = ptr_init[s-config  0x1f];
+s-regs[REG_FER] = fer_init[s-config  0x1f];
+s-regs[REG_FAR] = far_init[s-config  0x1f];
+s-regs[REG_PTR] = ptr_init[s-config  0x1f];
 }
 
 static void pc87312_hard_reset(PC87312State *s)
-- 
1.7.2.5




Re: [Qemu-devel] [PATCH] pc87312: Replace register_ioport_*() with MemoryRegion

2013-01-13 Thread Hervé Poussineau

Andreas Färber a écrit :

Prepare an instance_init function for the MemoryRegion init.

Signed-off-by: Andreas Färber andreas.faer...@web.de
Cc: Hervé Poussineau hpous...@reactos.org
---
 hw/pc87312.c |   26 ++
 hw/pc87312.h |2 ++
 2 Dateien geändert, 24 Zeilen hinzugefügt(+), 4 Zeilen entfernt(-)


Tested-by: Hervé Poussineau hpous...@reactos.org

Hervé



Re: [Qemu-devel] [PATCH] pc87312: avoid define conflict on mingw32

2013-01-13 Thread Hervé Poussineau

Blue Swirl a écrit :

Mingw32 headers define FAR, causing this warning:
/src/qemu/hw/pc87312.c:38:0: warning: FAR redefined [enabled by default]
In file included from 
/usr/local/lib/gcc/i686-mingw32msvc/4.7.0/../../../../i686-mingw32msvc/include/windows.h:48:0,
 from /src/qemu/include/sysemu/os-win32.h:29,
 from /src/qemu/include/qemu-common.h:46,
 from /src/qemu/include/exec/ioport.h:27,
 from /src/qemu/hw/isa.h:6,
 from /src/qemu/hw/pc87312.h:28,
 from /src/qemu/hw/pc87312.c:26:
/usr/local/lib/gcc/i686-mingw32msvc/4.7.0/../../../../i686-mingw32msvc/include/windef.h:34:0:
 note: this is the location of the previous definition

Avoid the warning by expanding the macros.

Signed-off-by: Blue Swirl blauwir...@gmail.com
---
 hw/pc87312.c |   38 +-
 1 files changed, 17 insertions(+), 21 deletions(-)


Acked-by: Hervé Poussineau hpous...@reactos.org

Hervé



[Qemu-devel] [PULL] pci,virtio

2013-01-13 Thread Michael S. Tsirkin
The following changes since commit 8e4a424b305e29dc0e454f52df3b35577f342975:

  Revert virtio-pci: replace byte swap hack (2013-01-06 18:30:17 +)

are available in the git repository at:

  git://git.kernel.org/pub/scm/virt/kvm/mst/qemu.git tags/for_anthony

for you to fetch changes up to feb9a2ab4b0260d8d680a7ffd25063dafc7ec628:

  pci-assign: Enable MSIX on device to match guest (2013-01-09 12:11:16 +0200)


pci,virtio

This further optimizes MSIX handling in virtio-pci.
Also included is pci cleanup by Paolo, and pci device
assignment fix by Alex.

Signed-off-by: Michael S. Tsirkin m...@redhat.com


Alex Williamson (1):
  pci-assign: Enable MSIX on device to match guest

Michael S. Tsirkin (8):
  virtio: don't waste irqfds on control vqs
  msix: add api to access msix message
  kvm: add stub for update msi route
  virtio-pci: cache msix messages
  virtio: backend virtqueue notifier masking
  virtio-net: set/clear vhost_started in reverse order
  vhost: set started flag while start is in progress
  vhost: backend masking support

Paolo Bonzini (5):
  docs: move pci-ids.txt to docs/specs/
  reorganize pci-ids.txt
  virtio-9p: use symbolic constant, add to pci-ids.txt
  ivshmem: use symbolic constant for PCI ID, add to pci-ids.txt
  pci: use constants for devices under the 1B36 device ID, document them

 docs/specs/pci-ids.txt |  50 +++
 hw/9pfs/virtio-9p-device.c |   2 +-
 hw/ivshmem.c   |   7 +-
 hw/kvm/pci-assign.c|  17 +++-
 hw/pci/msix.c  |   2 +-
 hw/pci/msix.h  |   1 +
 hw/pci/pci.h   |   8 ++
 hw/pci_bridge_dev.c|   8 +-
 hw/serial-pci.c|  12 +--
 hw/vhost.c | 112 +
 hw/vhost.h |  10 +++
 hw/vhost_net.c |  27 +-
 hw/vhost_net.h |   3 +
 hw/virtio-net.c|  22 -
 hw/virtio-pci.c| 203 +++--
 hw/virtio-pci.h|   2 +
 hw/virtio.h|  15 +++-
 kvm-stub.c |   5 ++
 pci-ids.txt|  31 ---
 19 files changed, 437 insertions(+), 100 deletions(-)
 create mode 100644 docs/specs/pci-ids.txt
 delete mode 100644 pci-ids.txt



Re: [Qemu-devel] [Bug 1033727] Re: USB passthrough doesn't work anymore with qemu-kvm 1.1.1

2013-01-13 Thread Peter Schaefer
Hello Michael,

Am 1/12/2013 1:24 PM, Michael Tokarev wrote:

 Peter, are you able to run git bisect or something like that, to try to
 pinpoint either the commit which introduced this issue or which fixed
 it?

Well, i'm no expert at git, but i made some progress, see below.

 Besides, what are the sympthoms of the device non-working?  Does it
 happen with linux guest too?  Have you tried re-running the guest again
 when the problem occur, using the same problematic version of qemu - I
 mean, is it 100% reproducible or happens at random?

In my case it's the SmartCard-Reader that's not working, i.e. the DATEV 
Software called Sicherheitspaket does not 
work. The background process called SiPaHost.exe just hangs; any client 
program trying to display SmartCard 
information does also just hang forever. That behaviour is 100% reproducible 
and persists over reboots of the Linux host 
and/or the Windows guest (Windows XP SP3). I did not try Linux guests.

Yesterday, i used git to checkout all qemu-kvm versions from kernel.org and 
build Debian packets from it (source kept 
vanilla, i just applied the two patches that rename paths from 'qemuXXX' to 
'kvmXXX').

The findings were:

- v1.0   - ok
- v1.0.1 - ok
- v1.1.0 - not ok
- v1.1.1 - not ok
- v1.1.2 - not ok
- v1.2.0 - not ok

So far, this is consistent with the findings in this bug report.

BUT: The latest HEAD from kernel.org (called v1.2.50) also does work
again!

So, i'm now learning about git bisect (however, today i won't have time
for this).

Regards,
Peter

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

Title:
  USB passthrough doesn't work anymore with qemu-kvm 1.1.1

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

Bug description:
  Hi,

  I have a Bus 006 Device 002: ID 0d46:3003 Kobil Systems GmbH mIDentity Light 
/ KAAN SIM III (kind of smart card) in an USB port which I make available to a 
Windows XP guest.
  This worked fine with every older qemu-kvm version I've used so far.

  But since 1.1.0 it doesn't work anymore.
  The device shows up in the guest, but the software can't access it anymore 
(and the guest is pretty unresponsive).

  On the host I get every 2 seconds this message:
  [ 7719.239528] usb 6-1: reset full-speed USB device number 2 using uhci_hcd

  Command line options are:
  /usr/bin/kvm
  ...
  -device usb-host,vendorid=0x0d46,productid=0x3003,bus=usb.0,port=3
  ...

  When I switch back to qemu-kvm 1.0.1 everything works fine again.
  Any idea what the problem could be?

  Thanks
  Klaus

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



[Qemu-devel] [Bug 1098729] Re: qemu-user-static for armhf: segfault in threaded code

2013-01-13 Thread Erik de Castro Lopo
At the top of function  cpu_unlink_tb() in translate-all.c:

  /* FIXME: TB unchaining isn't SMP safe.  For now just ignore the
   problem and hope the cpu will stop of its own accord.  For userspace
   emulation this often isn't actually as bad as it sounds.  Often
   signals are used primarily to interrupt blocking syscalls.  */

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

Title:
  qemu-user-static for armhf: segfault in threaded code

Status in QEMU:
  New

Bug description:
  
  Currently running QEMU from git (fedf2de31023) and running the armhf version 
of qemu-user-static which I have renamed qemu-armhf-static to follow the naming 
convention used in Debian.

  The host systems is a Debian testing x86_64-linux and I have an Debian
  testing armhf chroot which I invoke using schroot.

  Majority of program in the armhf chroot run fine, but I'm getting qemu
  segfaults in multi-threaded programs.

  As an example, I've grabbed the threads demo program here:

  https://computing.llnl.gov/tutorials/pthreads/samples/dotprod_mutex.c

  and changed NUMTHRDS from 4 to 10. I compile it as (same compile
  command on both x86_64 host and armhf guest):

  gcc -Wall -lpthread dotprod_mutex.c -o dotprod_mutex

  When compiled for x86_64 host it runs perfectly and even under
  Valgrind displays no errors whatsoever.

  However, when I compile the program in my armhs chroot and run it it
  usually (but not always) segaults or hangs or crashes. Example output:

  
  (armhf) $ ./dotprod_mutex
  Thread 1 did 10 to 20:  mysum=10.00 global 
sum=10.00
  Thread 0 did 0 to 10:  mysum=10.00 global sum=20.00
  TCG temporary leak before f6731ca0
  qemu-arm-static: 
/home/erikd/Git/qemu-posix-timer-hacking/Upstream/tcg/tcg-op.h:2371:
  tcg_gen_goto_tb: Assertion `(tcg_ctx.goto_tb_issue_mask  (1  idx)) == 
0' failed.

  
  (armhf) $ ./dotprod_mutex
  qemu: uncaught target signal 11 (Segmentation fault) - core dumped
  Segmentation fault

  (armhf) $ ./dotprod_mutex
  qemu-arm-static: 
/home/erikd/Git/qemu-posix-timer-hacking/Upstream/tcg/tcg.c:519:
  tcg_temp_free_internal: Assertion `idx = s-nb_globals  idx  
s-nb_temps' failed.

  
  (armhf) $ ./dotprod_mutex
  Thread 1 did 10 to 20:  mysum=10.00 global 
sum=10.00
  qemu: uncaught target signal 11 (Segmentation fault) - core dumped
  Segmentation fault

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



[Qemu-devel] [Bug 1087114] Re: assertion QLIST_EMPTY(bs-tracked_requests) failed

2013-01-13 Thread Aaron Jackson
I am still having this error even though I compile from the master
branch and commit a795ef8dcb8cbadffc996c41ff38927a97645234 is definitely
there.

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

Title:
  assertion QLIST_EMPTY(bs-tracked_requests) failed

Status in QEMU:
  New

Bug description:
  QEMU 1.3.0 on OpenBSD now crashes with an error as shown below and the
  command line params do not seem to matter.

  assertion QLIST_EMPTY(bs-tracked_requests) failed: file block.c,
  line 1220, function bdrv_drain_all

  #1  0x030d1bce24aa in abort () at /usr/src/lib/libc/stdlib/abort.c:70
  p = (struct atexit *) 0x30d11897000
  mask = 4294967263
  cleanup_called = 1
  #2  0x030d1bc5ff44 in __assert2 (file=Variable file is not available.
  ) at /usr/src/lib/libc/gen/assert.c:52
  No locals.
  #3  0x030b0d383a03 in bdrv_drain_all () at block.c:1220
  bs = (BlockDriverState *) 0x30d13f3b630
  busy = false
  __func__ = bdrv_drain_all
  #4  0x030b0d43acfc in bmdma_cmd_writeb (bm=0x30d0f5f56a8, val=8) at 
hw/ide/pci.c:312
  __func__ = bmdma_cmd_writeb
  #5  0x030b0d43b450 in bmdma_write (opaque=0x30d0f5f56a8, addr=0, val=8, 
size=1) at hw/ide/piix.c:76
  bm = (BMDMAState *) 0x30d0f5f56a8
  #6  0x030b0d5c2ce6 in memory_region_write_accessor (opaque=0x30d0f5f57d0, 
addr=0, value=0x30d18c288f0, size=1, shift=0, mask=255)
  at /home/ports/pobj/qemu-1.3.0-debug/qemu-1.3.0/memory.c:334
  mr = (MemoryRegion *) 0x30d0f5f57d0
  tmp = 8
  #7  0x030b0d5c2dc5 in access_with_adjusted_size (addr=0, 
value=0x30d18c288f0, size=1, access_size_min=1, access_size_max=4, 
  access=0x30b0d5c2c6b memory_region_write_accessor, 
opaque=0x30d0f5f57d0) at 
/home/ports/pobj/qemu-1.3.0-debug/qemu-1.3.0/memory.c:364
  access_mask = 255
  access_size = 1
  i = 0
  #8  0x030b0d5c3222 in memory_region_iorange_write (iorange=0x30d1d5e7400, 
offset=0, width=1, data=8)
  at /home/ports/pobj/qemu-1.3.0-debug/qemu-1.3.0/memory.c:439
  mrio = (MemoryRegionIORange *) 0x30d1d5e7400
  mr = (MemoryRegion *) 0x30d0f5f57d0
  __func__ = memory_region_iorange_write
  #9  0x030b0d5c019a in ioport_writeb_thunk (opaque=0x30d1d5e7400, 
addr=49216, data=8) at /home/ports/pobj/qemu-1.3.0-debug/qemu-1.3.0/ioport.c:212
  ioport = (IORange *) 0x30d1d5e7400
  #10 0x030b0d5bfb65 in ioport_write (index=0, address=49216, data=8) at 
/home/ports/pobj/qemu-1.3.0-debug/qemu-1.3.0/ioport.c:83
  func = (IOPortWriteFunc *) 0x30b0d5c0148 ioport_writeb_thunk
  default_func = {0x30b0d5bfbbc default_ioport_writeb, 0x30b0d5bfc61 
default_ioport_writew, 0x30b0d5bfd0c default_ioport_writel}
  #11 0x030b0d5c0704 in cpu_outb (addr=49216, val=8 '\b') at 
/home/ports/pobj/qemu-1.3.0-debug/qemu-1.3.0/ioport.c:289
  No locals.
  #12 0x030b0d6067dd in helper_outb (port=49216, data=8) at 
/home/ports/pobj/qemu-1.3.0-debug/qemu-1.3.0/target-i386/misc_helper.c:72
  No locals.

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



[Qemu-devel] [PATCH] bswap: improve gluing

2013-01-13 Thread Blue Swirl
OpenBSD system compiler (gcc 4.2.1) has problems with concatenation
of macro arguments in macro functions:
  CCaes.o
In file included from /src/qemu/include/qemu-common.h:126,
 from /src/qemu/aes.c:30:
/src/qemu/include/qemu/bswap.h: In function 'leul_to_cpu':
/src/qemu/include/qemu/bswap.h:461: warning: implicit declaration of function 
'bswapHOST_LONG_BITS'
/src/qemu/include/qemu/bswap.h:461: warning: nested extern declaration of 
'bswapHOST_LONG_BITS'

Function leul_to_cpu() is only used in kvm-all.c, so the warnings
are not fatal on OpenBSD without -Werror.

Fix by applying glue(). Also add do {} while(0) wrapping and fix
semicolon use while at it.

Signed-off-by: Blue Swirl blauwir...@gmail.com
---
 include/qemu/bswap.h |   20 ++--
 1 files changed, 10 insertions(+), 10 deletions(-)

diff --git a/include/qemu/bswap.h b/include/qemu/bswap.h
index be9b035..e6d4798 100644
--- a/include/qemu/bswap.h
+++ b/include/qemu/bswap.h
@@ -72,45 +72,45 @@ static inline void bswap64s(uint64_t *s)
 
 #if defined(HOST_WORDS_BIGENDIAN)
 #define be_bswap(v, size) (v)
-#define le_bswap(v, size) bswap ## size(v)
+#define le_bswap(v, size) glue(bswap, size)(v)
 #define be_bswaps(v, size)
-#define le_bswaps(p, size) *p = bswap ## size(*p);
+#define le_bswaps(p, size) do { *p = glue(bswap, size)(*p); } while(0)
 #else
 #define le_bswap(v, size) (v)
-#define be_bswap(v, size) bswap ## size(v)
+#define be_bswap(v, size) glue(bswap, size)(v)
 #define le_bswaps(v, size)
-#define be_bswaps(p, size) *p = bswap ## size(*p);
+#define be_bswaps(p, size) do { *p = glue(bswap, size)(*p); } while(0)
 #endif
 
 #define CPU_CONVERT(endian, size, type)\
 static inline type endian ## size ## _to_cpu(type v)\
 {\
-return endian ## _bswap(v, size);\
+return glue(endian, _bswap)(v, size);\
 }\
 \
 static inline type cpu_to_ ## endian ## size(type v)\
 {\
-return endian ## _bswap(v, size);\
+return glue(endian, _bswap)(v, size);\
 }\
 \
 static inline void endian ## size ## _to_cpus(type *p)\
 {\
-endian ## _bswaps(p, size)\
+glue(endian, _bswaps)(p, size);\
 }\
 \
 static inline void cpu_to_ ## endian ## size ## s(type *p)\
 {\
-endian ## _bswaps(p, size)\
+glue(endian, _bswaps)(p, size);\
 }\
 \
 static inline type endian ## size ## _to_cpup(const type *p)\
 {\
-return endian ## size ## _to_cpu(*p);\
+return glue(glue(endian, size), _to_cpu)(*p);\
 }\
 \
 static inline void cpu_to_ ## endian ## size ## w(type *p, type v)\
 {\
- *p = cpu_to_ ## endian ## size(v);\
+*p = glue(glue(cpu_to_, endian), size)(v);\
 }
 
 CPU_CONVERT(be, 16, uint16_t)
-- 
1.7.2.5




[Qemu-devel] [Bug 668799] Re: qemu-arm segfaults executing msgmerge (gettext)

2013-01-13 Thread Erik de Castro Lopo
The test I'm using in  LP:1098729 hangs or segfaults nearly every single
run.

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

Title:
  qemu-arm segfaults executing msgmerge (gettext)

Status in QEMU:
  New
Status in Linaro QEMU:
  New

Bug description:
  upstream qemu.git revision b45e9c05dbacba8e992f0bffeca04c6379c3ad45

  Starting program: /usr/bin/qemu-arm msgmerge-static ar.po anjuta.pot

  [Thread debugging using libthread_db enabled]
  [New Thread 0x74bc3ff0 (LWP 26108)]
  [New Thread 0x74b8aff0 (LWP 26109)]
  [New Thread 0x74b51ff0 (LWP 26110)]
  [New Thread 0x74b18ff0 (LWP 26111)]
  [New Thread 0x74adfff0 (LWP 26112)]
  [New Thread 0x74aa6ff0 (LWP 26113)]
  [New Thread 0x74a6dff0 (LWP 26114)]
  [New Thread 0x74a34ff0 (LWP 26115)]
  [New Thread 0x749fbff0 (LWP 26116)]
  [New Thread 0x749c2ff0 (LWP 26117)]
  [New Thread 0x74989ff0 (LWP 26118)]
  [New Thread 0x74950ff0 (LWP 26119)]
  [New Thread 0x74917ff0 (LWP 26120)]
  [New Thread 0x748deff0 (LWP 26121)]
  [New Thread 0x748a5ff0 (LWP 26122)]
  [New Thread 0x7486cff0 (LWP 26123)]
  [New Thread 0x74833ff0 (LWP 26124)]
  [New Thread 0x747faff0 (LWP 26125)]
  [New Thread 0x747c1ff0 (LWP 26126)]
  [New Thread 0x74788ff0 (LWP 26127)]
  [New Thread 0x7474fff0 (LWP 26128)]
  [New Thread 0x74716ff0 (LWP 26129)]
  [New Thread 0x746ddff0 (LWP 26130)]
  .
  Program received signal SIGSEGV, Segmentation fault.
  [Switching to Thread 0x74aa6ff0 (LWP 26113)]
  0x600480d4 in tb_reset_jump_recursive2 (tb=0x74c63540, n=0)
  at /home/user/git/qemu/exec.c:1333
  1333tb1 = tb1-jmp_next[n1];

  (gdb) bt
  #0  0x600480d4 in tb_reset_jump_recursive2 (tb=0x74c63540, n=0)
  at /home/user/git/qemu/exec.c:1333
  #1  0x600481c0 in tb_reset_jump_recursive (tb=0x74c63540)
  at /home/user/git/qemu/exec.c:1361
  #2  0x60048160 in tb_reset_jump_recursive2 (tb=0x74c634d8, n=0)
  at /home/user/git/qemu/exec.c:1355
  #3  0x600481c0 in tb_reset_jump_recursive (tb=0x74c634d8)
  at /home/user/git/qemu/exec.c:1361
  #4  0x60048160 in tb_reset_jump_recursive2 (tb=0x74c63470, n=0)
  at /home/user/git/qemu/exec.c:1355
  #5  0x600481c0 in tb_reset_jump_recursive (tb=0x74c63470)
  at /home/user/git/qemu/exec.c:1361
  #6  0x60048160 in tb_reset_jump_recursive2 (tb=0x74c63408, n=1)
  at /home/user/git/qemu/exec.c:1355
  #7  0x600481d1 in tb_reset_jump_recursive (tb=0x74c63408)
  at /home/user/git/qemu/exec.c:1362
  #8  0x60048160 in tb_reset_jump_recursive2 (tb=0x74c633a0, n=0)
  at /home/user/git/qemu/exec.c:1355
  #9  0x600481c0 in tb_reset_jump_recursive (tb=0x74c633a0)
  at /home/user/git/qemu/exec.c:1361
  #10 0x60048160 in tb_reset_jump_recursive2 (tb=0x74c63338, n=0)
  at /home/user/git/qemu/exec.c:1355
  #11 0x600481c0 in tb_reset_jump_recursive (tb=0x74c63338)
  at /home/user/git/qemu/exec.c:1361
  #12 0x60048160 in tb_reset_jump_recursive2 (tb=0x74c632d0, n=0)
  at /home/user/git/qemu/exec.c:1355
  ---Type return to continue, or q return to quit---
  #13 0x600481c0 in tb_reset_jump_recursive (tb=0x74c632d0)
  at /home/user/git/qemu/exec.c:1361
  #14 0x60048160 in tb_reset_jump_recursive2 (tb=0x74c63268, n=1)
  at /home/user/git/qemu/exec.c:1355
  #15 0x600481d1 in tb_reset_jump_recursive (tb=0x74c63268)
  at /home/user/git/qemu/exec.c:1362
  #16 0x60048160 in tb_reset_jump_recursive2 (tb=0x74c63200, n=0)
  at /home/user/git/qemu/exec.c:1355
  #17 0x600481c0 in tb_reset_jump_recursive (tb=0x74c63200)
  at /home/user/git/qemu/exec.c:1361
  #18 0x600487c5 in cpu_unlink_tb (env=0x62385400) at 
/home/user/git/qemu/exec.c:1617
  #19 0x600488e8 in cpu_exit (env=0x62385400) at 
/home/user/git/qemu/exec.c:1662
  #20 0x6798 in start_exclusive () at 
/home/user/git/qemu/linux-user/main.c:152
  #21 0x6a4b in do_kernel_trap (env=0x62359940)
  at /home/user/git/qemu/linux-user/main.c:493
  #22 0x600023f3 in cpu_loop (env=0x62359940) at 
/home/user/git/qemu/linux-user/main.c:797
  #23 0x600123df in clone_func (arg=0x7ffd76e0)
  at /home/user/git/qemu/linux-user/syscall.c:3561
  #24 0x600b382d in start_thread (arg=value optimized out) at 
pthread_create.c:297
  #25 0x600f1809 in clone () at 
../sysdeps/unix/sysv/linux/x86_64/clone.S:112
  #26 0x in ?? ()
  (gdb) 


  Its interesting to see this :
  #0  0x600480d4 in tb_reset_jump_recursive2 (tb=0x74c63540, n=0)
  at /home/user/git/qemu/exec.c:1333
  tb1 = 0x0  

Re: [Qemu-devel] [Bug 1033727] Re: USB passthrough doesn't work anymore with qemu-kvm 1.1.1

2013-01-13 Thread Peter Schaefer
Hi,

well - it's probably only for historic interest, but if i made no bisecting 
mistake, this commit has fixed it (note that 
the meaning of 'good' and 'bad' is swapped due to how git bisect works):

root@debian:~/qemu_git/qemu-kvm# git bisect good
Bisecting: 87 revisions left to test after this (roughly 7 steps)
[c26032b2c91721245bfec542d94f37a0238e986e] target-xtensa: don't emit extra 
tcg_gen_goto_tb
root@debian:~/qemu_git/qemu-kvm# git bisect good
Bisecting: 43 revisions left to test after this (roughly 6 steps)
[1fd959466574c3d46f4898f2e27cd3b1060338e4] tcg-sparc: Mask shift immediates to 
avoid illegal insns.
root@debian:~/qemu_git/qemu-kvm# git bisect bad
Bisecting: 24 revisions left to test after this (roughly 5 steps)
[e55f523d7977480462151d8abb0ebb4b1747eabf] tcg-hppa: Fix broken load/store 
helpers
root@debian:~/qemu_git/qemu-kvm# git bisect good
Bisecting: 12 revisions left to test after this (roughly 4 steps)
[09054d19e72f6991cd359d41c479badd92f62a06] usb-redir: Add chardev open / close 
debug logging
root@debian:~/qemu_git/qemu-kvm# git bisect good
Bisecting: 6 revisions left to test after this (roughly 3 steps)
[a221ae3fcc55fcc3911587bc572af88eed3342dd] tcg-sparc: Fix ADDX opcode.
root@debian:~/qemu_git/qemu-kvm# git bisect bad
Bisecting: 2 revisions left to test after this (roughly 2 steps)
[cfb75cb9807463ebe18b127096b48b5d0db1ce03] Merge branch 'usb.65' of 
git://git.kraxel.org/qemu
root@debian:~/qemu_git/qemu-kvm# git bisect bad
Bisecting: 0 revisions left to test after this (roughly 1 step)
[72a04d0c178f01908d74539230d9de64ffc6da19] uhci: Don't queue up packets after 
one with the SPD flag set
root@debian:~/qemu_git/qemu-kvm# git bisect bad
Bisecting: 0 revisions left to test after this (roughly 0 steps)
[35efba2cc6812dc980c336d7b9bf81dbfb5daf00] usb-redir: Revert usb-redir part of 
commit 93bfef4c
root@debian:~/qemu_git/qemu-kvm# git bisect good
72a04d0c178f01908d74539230d9de64ffc6da19 is the first bad commit
commit 72a04d0c178f01908d74539230d9de64ffc6da19
Author: Hans de Goede hdego...@redhat.com
Date:   Wed Sep 12 15:08:40 2012 +0200

 uhci: Don't queue up packets after one with the SPD flag set

 Don't queue up packets after a packet with the SPD (short packet detect)
 flag set. Since we won't know if the packet will actually be short until it
 has completed, and if it is short we should stop the queue.

 This fixes a miniature photoframe emulating a USB cdrom with the windows
 software for it not working.

 Signed-off-by: Hans de Goede hdego...@redhat.com
 Signed-off-by: Gerd Hoffmann kra...@redhat.com

:04 04 18e7490171762dec04cb8ce49fd21e0b685b53b2 
86f7cb33d8b77828e671c5fb39c9d137d39eca06 M  hw
root@debian:~/qemu_git/qemu-kvm#

HTH.

Regards,
  Peter

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

Title:
  USB passthrough doesn't work anymore with qemu-kvm 1.1.1

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

Bug description:
  Hi,

  I have a Bus 006 Device 002: ID 0d46:3003 Kobil Systems GmbH mIDentity Light 
/ KAAN SIM III (kind of smart card) in an USB port which I make available to a 
Windows XP guest.
  This worked fine with every older qemu-kvm version I've used so far.

  But since 1.1.0 it doesn't work anymore.
  The device shows up in the guest, but the software can't access it anymore 
(and the guest is pretty unresponsive).

  On the host I get every 2 seconds this message:
  [ 7719.239528] usb 6-1: reset full-speed USB device number 2 using uhci_hcd

  Command line options are:
  /usr/bin/kvm
  ...
  -device usb-host,vendorid=0x0d46,productid=0x3003,bus=usb.0,port=3
  ...

  When I switch back to qemu-kvm 1.0.1 everything works fine again.
  Any idea what the problem could be?

  Thanks
  Klaus

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



[Qemu-devel] [RFC ppc-next v3 00/10] target-ppc: MacIO QOM'ification

2013-01-13 Thread Andreas Färber
Hello,

As requested by Markus, here's a conversion of MacIO IDE to QOM.
There's more work to be done, but in light of the approaching Soft Freeze
here's my current state of affairs, lightly tested.

Patch 1 is a generic QOM API fix and could be applied independent of the
ppc device conversion.

Patch 2 goes on to move PowerMac machines to hw/ppc/ as discussed with Alex.
The intent would be to do the same for PReP once applied.

The remainder revives an old patch from the time of QOM introduction to split
MacIO in two, allowing to move more logic into the device from the machine.
This time it adopts new QOM concepts for embedding the sub-devices converted
in the following patches. TODO: finalization support / object_unref().

ADB is still being worked on. DBDMA still TODO (but then again so is x86 DMA).
ESCC would affect sparc as well.
The PICs pose cyclic dependency issues (mapped inside MacIO but MacIO as a
PCIDevice needing a PCIBus, the Grackle/UniNorth PHBs needing a PIC IRQ).

Regards,
Andreas

v2 - v3:
* Redone using QOM, split up into three patches for better reviewability.
* Added QOM'ification patches for NVRAM, IDE and CUDA.

v1 - v2:
 * qdev'ification patch was ignored for QOM 2nd series: Rebased onto Anthony's.

Cc: Alexander Graf ag...@suse.de
Cc: qemu-ppc qemu-...@nongnu.org

Cc: Markus Armbruster arm...@redhat.com
Cc: Kevin Wolf kw...@redhat.com
Cc: Blue Swirl blauwir...@gmail.com
Cc: Hervé Poussineau hpous...@reactos.org

Andreas Färber (10):
  qom: Make object_resolve_path_component() path argument const
  ppc: Move Mac machines to hw/ppc/
  macio: QOM'ify some more
  macio: Delay qdev init until all fields are initialized
  macio: Split MacIO in two
  mac_nvram: Clean up public API
  mac_nvram: Mark as Big Endian
  mac_nvram: QOM'ify MacIO NVRAM
  ide/macio: QOM'ify MacIO IDE
  cuda: QOM'ify CUDA

 hw/cuda.c |  100 +-
 hw/grackle_pci.c  |2 +-
 hw/heathrow_pic.c |2 +-
 hw/ide.h  |4 -
 hw/ide/macio.c|   87 ++---
 hw/mac_nvram.c|   82 
 hw/macio.c|  289 ++---
 hw/openpic.c  |2 +-
 hw/ppc/Makefile.objs  |9 +-
 hw/ppc/mac.h  |  179 ++
 hw/{ppc_newworld.c = ppc/mac_newworld.c} |   65 ---
 hw/{ppc_oldworld.c = ppc/mac_oldworld.c} |   56 +++---
 hw/ppc_mac.h  |   81 
 hw/unin_pci.c |2 +-
 include/qom/object.h  |2 +-
 qom/object.c  |2 +-
 16 Dateien geändert, 636 Zeilen hinzugefügt(+), 328 Zeilen entfernt(-)
 create mode 100644 hw/ppc/mac.h
 rename hw/{ppc_newworld.c = ppc/mac_newworld.c} (91%)
 rename hw/{ppc_oldworld.c = ppc/mac_oldworld.c} (92%)
 delete mode 100644 hw/ppc_mac.h

-- 
1.7.10.4




[Qemu-devel] [RFC ppc-next v3 08/10] mac_nvram: QOM'ify MacIO NVRAM

2013-01-13 Thread Andreas Färber
It was not qdev'ified before, turn it into a SysBusDevice and
initialize it via static properties.

Prepare Old World specific MacIO state and embed the NVRAM state there.

Drop macio_nvram_setup_bar() in favor of sysbus_mmio_map() or
direct use of Memory API.

Signed-off-by: Andreas Färber afaer...@suse.de
---
 hw/mac_nvram.c|   57 ++---
 hw/macio.c|   41 ++-
 hw/ppc/mac.h  |   23 ++--
 hw/ppc/mac_newworld.c |   10 ++---
 hw/ppc/mac_oldworld.c |6 +-
 5 Dateien geändert, 96 Zeilen hinzugefügt(+), 41 Zeilen entfernt(-)

diff --git a/hw/mac_nvram.c b/hw/mac_nvram.c
index 0a22e66..a832dda 100644
--- a/hw/mac_nvram.c
+++ b/hw/mac_nvram.c
@@ -37,13 +37,6 @@
 #define NVR_DPRINTF(fmt, ...)
 #endif
 
-struct MacIONVRAMState {
-uint32_t size;
-MemoryRegion mem;
-unsigned int it_shift;
-uint8_t *data;
-};
-
 #define DEF_SYSTEM_SIZE 0xc10
 
 /* Direct access to NVRAM */
@@ -111,32 +104,50 @@ static const VMStateDescription vmstate_macio_nvram = {
 };
 
 
-static void macio_nvram_reset(void *opaque)
+static void macio_nvram_reset(DeviceState *dev)
 {
 }
 
-MacIONVRAMState *macio_nvram_init (hwaddr size,
-   unsigned int it_shift)
+static int macio_nvram_initfn(SysBusDevice *d)
 {
-MacIONVRAMState *s;
+MacIONVRAMState *s = MACIO_NVRAM(d);
 
-s = g_malloc0(sizeof(MacIONVRAMState));
-s-data = g_malloc0(size);
-s-size = size;
-s-it_shift = it_shift;
+s-data = g_malloc0(s-size);
 
 memory_region_init_io(s-mem, macio_nvram_ops, s, macio-nvram,
-  size  it_shift);
-vmstate_register(NULL, -1, vmstate_macio_nvram, s);
-qemu_register_reset(macio_nvram_reset, s);
+  s-size  s-it_shift);
+sysbus_init_mmio(d, s-mem);
 
-return s;
+return 0;
 }
 
-void macio_nvram_setup_bar(MacIONVRAMState *s, MemoryRegion *bar,
-   hwaddr mem_base)
+static Property macio_nvram_properties[] = {
+DEFINE_PROP_UINT32(size, MacIONVRAMState, size, 0),
+DEFINE_PROP_UINT32(it_shift, MacIONVRAMState, it_shift, 0),
+DEFINE_PROP_END_OF_LIST()
+};
+
+static void macio_nvram_class_init(ObjectClass *oc, void *data)
 {
-memory_region_add_subregion(bar, mem_base, s-mem);
+DeviceClass *dc = DEVICE_CLASS(oc);
+SysBusDeviceClass *sdc = SYS_BUS_DEVICE_CLASS(oc);
+
+sdc-init = macio_nvram_initfn;
+dc-reset = macio_nvram_reset;
+dc-vmsd = vmstate_macio_nvram;
+dc-props = macio_nvram_properties;
+}
+
+static const TypeInfo macio_nvram_type_info = {
+.name = TYPE_MACIO_NVRAM,
+.parent = TYPE_SYS_BUS_DEVICE,
+.instance_size = sizeof(MacIONVRAMState),
+.class_init = macio_nvram_class_init,
+};
+
+static void macio_nvram_register_types(void)
+{
+type_register_static(macio_nvram_type_info);
 }
 
 /* Set up a system OpenBIOS NVRAM partition */
@@ -175,3 +186,5 @@ void pmac_format_nvram_partition (MacIONVRAMState *nvr, int 
len)
 end = len;
 OpenBIOS_finish_partition(part_header, end - start);
 }
+
+type_init(macio_nvram_register_types)
diff --git a/hw/macio.c b/hw/macio.c
index 0e6fc8d..32f359c 100644
--- a/hw/macio.c
+++ b/hw/macio.c
@@ -41,11 +41,21 @@ typedef struct MacIOState
 MemoryRegion *dbdma_mem;
 MemoryRegion *cuda_mem;
 MemoryRegion *escc_mem;
-void *nvram;
 int nb_ide;
 MemoryRegion *ide_mem[4];
 } MacIOState;
 
+#define OLDWORLD_MACIO(obj) \
+OBJECT_CHECK(OldWorldMacIOState, (obj), TYPE_OLDWORLD_MACIO)
+
+typedef struct OldWorldMacIOState {
+/* private */
+MacIOState parent_obj;
+/* public */
+
+MacIONVRAMState nvram;
+} OldWorldMacIOState;
+
 static void macio_bar_setup(MacIOState *macio_state)
 {
 int i;
@@ -66,8 +76,6 @@ static void macio_bar_setup(MacIOState *macio_state)
 macio_state-ide_mem[i]);
 }
 }
-if (macio_state-nvram != NULL)
-macio_nvram_setup_bar(macio_state-nvram, bar, 0x6);
 }
 
 static int macio_common_initfn(PCIDevice *d)
@@ -85,11 +93,22 @@ static int macio_common_initfn(PCIDevice *d)
 static int macio_oldworld_initfn(PCIDevice *d)
 {
 MacIOState *s = MACIO(d);
+OldWorldMacIOState *os = OLDWORLD_MACIO(d);
+SysBusDevice *sysbus_dev;
 int ret = macio_common_initfn(d);
 if (ret  0) {
 return ret;
 }
 
+ret = qdev_init(DEVICE(os-nvram));
+if (ret  0) {
+return ret;
+}
+sysbus_dev = SYS_BUS_DEVICE(os-nvram);
+memory_region_add_subregion(s-bar, 0x6,
+sysbus_mmio_get_region(sysbus_dev, 0));
+pmac_format_nvram_partition(os-nvram, os-nvram.size);
+
 if (s-pic_mem) {
 /* Heathrow PIC */
 memory_region_add_subregion(s-bar, 0x0, s-pic_mem);
@@ -98,6 +117,17 @@ static int macio_oldworld_initfn(PCIDevice *d)
 return 0;
 }
 
+static void 

[Qemu-devel] [RFC ppc-next v3 04/10] macio: Delay qdev init until all fields are initialized

2013-01-13 Thread Andreas Färber
This turns macio_bar_setup() into an implementation detail of the qdev
initfn, to be removed step by step.

Signed-off-by: Andreas Färber afaer...@suse.de
---
 hw/macio.c |   11 ---
 1 Datei geändert, 8 Zeilen hinzugefügt(+), 3 Zeilen entfernt(-)

diff --git a/hw/macio.c b/hw/macio.c
index 770e3bd..8b4b48d 100644
--- a/hw/macio.c
+++ b/hw/macio.c
@@ -82,7 +82,13 @@ static void macio_bar_setup(MacIOState *macio_state)
 
 static int macio_initfn(PCIDevice *d)
 {
+MacIOState *s = MACIO(d);
+
 d-config[0x3d] = 0x01; // interrupt on pin 1
+
+macio_bar_setup(s);
+pci_register_bar(d, 0, PCI_BASE_ADDRESS_SPACE_MEMORY, s-bar);
+
 return 0;
 }
 
@@ -127,7 +133,7 @@ void macio_init (PCIBus *bus, int device_id, int 
is_oldworld,
 MacIOState *macio_state;
 int i;
 
-d = pci_create_simple(bus, -1, TYPE_MACIO);
+d = pci_create(bus, -1, TYPE_MACIO);
 
 macio_state = MACIO(d);
 macio_state-is_oldworld = is_oldworld;
@@ -148,6 +154,5 @@ void macio_init (PCIBus *bus, int device_id, int 
is_oldworld,
 
 pci_config_set_device_id(d-config, device_id);
 
-macio_bar_setup(macio_state);
-pci_register_bar(d, 0, PCI_BASE_ADDRESS_SPACE_MEMORY, macio_state-bar);
+qdev_init_nofail(DEVICE(d));
 }
-- 
1.7.10.4




[Qemu-devel] [RFC ppc-next v3 07/10] mac_nvram: Mark as Big Endian

2013-01-13 Thread Andreas Färber
Signed-off-by: Andreas Färber afaer...@suse.de
---
 hw/mac_nvram.c |2 +-
 1 Datei geändert, 1 Zeile hinzugefügt(+), 1 Zeile entfernt(-)

diff --git a/hw/mac_nvram.c b/hw/mac_nvram.c
index bcde07d..0a22e66 100644
--- a/hw/mac_nvram.c
+++ b/hw/mac_nvram.c
@@ -96,7 +96,7 @@ static uint64_t macio_nvram_readb(void *opaque, hwaddr addr,
 static const MemoryRegionOps macio_nvram_ops = {
 .read = macio_nvram_readb,
 .write = macio_nvram_writeb,
-.endianness = DEVICE_NATIVE_ENDIAN,
+.endianness = DEVICE_BIG_ENDIAN,
 };
 
 static const VMStateDescription vmstate_macio_nvram = {
-- 
1.7.10.4




[Qemu-devel] [RFC ppc-next v3 03/10] macio: QOM'ify some more

2013-01-13 Thread Andreas Färber
Move bar MemoryRegion initialization to an instance_init.

Signed-off-by: Andreas Färber afaer...@suse.de
---
 hw/macio.c |   25 +++--
 1 Datei geändert, 19 Zeilen hinzugefügt(+), 6 Zeilen entfernt(-)

diff --git a/hw/macio.c b/hw/macio.c
index f01fc57..770e3bd 100644
--- a/hw/macio.c
+++ b/hw/macio.c
@@ -27,9 +27,15 @@
 #include pci/pci.h
 #include escc.h
 
+#define TYPE_MACIO macio
+#define MACIO(obj) OBJECT_CHECK(MacIOState, (obj), TYPE_MACIO)
+
 typedef struct MacIOState
 {
+/* private */
 PCIDevice parent;
+/* public */
+
 int is_oldworld;
 MemoryRegion bar;
 MemoryRegion *pic_mem;
@@ -46,7 +52,6 @@ static void macio_bar_setup(MacIOState *macio_state)
 int i;
 MemoryRegion *bar = macio_state-bar;
 
-memory_region_init(bar, macio, 0x8);
 if (macio_state-pic_mem) {
 if (macio_state-is_oldworld) {
 /* Heathrow PIC */
@@ -81,6 +86,13 @@ static int macio_initfn(PCIDevice *d)
 return 0;
 }
 
+static void macio_instance_init(Object *obj)
+{
+MacIOState *s = MACIO(obj);
+
+memory_region_init(s-bar, macio, 0x8);
+}
+
 static void macio_class_init(ObjectClass *klass, void *data)
 {
 PCIDeviceClass *k = PCI_DEVICE_CLASS(klass);
@@ -90,16 +102,17 @@ static void macio_class_init(ObjectClass *klass, void 
*data)
 k-class_id = PCI_CLASS_OTHERS  8;
 }
 
-static const TypeInfo macio_info = {
-.name  = macio,
+static const TypeInfo macio_type_info = {
+.name  = TYPE_MACIO,
 .parent= TYPE_PCI_DEVICE,
 .instance_size = sizeof(MacIOState),
+.instance_init = macio_instance_init,
 .class_init= macio_class_init,
 };
 
 static void macio_register_types(void)
 {
-type_register_static(macio_info);
+type_register_static(macio_type_info);
 }
 
 type_init(macio_register_types)
@@ -114,9 +127,9 @@ void macio_init (PCIBus *bus, int device_id, int 
is_oldworld,
 MacIOState *macio_state;
 int i;
 
-d = pci_create_simple(bus, -1, macio);
+d = pci_create_simple(bus, -1, TYPE_MACIO);
 
-macio_state = DO_UPCAST(MacIOState, parent, d);
+macio_state = MACIO(d);
 macio_state-is_oldworld = is_oldworld;
 macio_state-pic_mem = pic_mem;
 macio_state-dbdma_mem = dbdma_mem;
-- 
1.7.10.4




[Qemu-devel] [RFC ppc-next v3 02/10] ppc: Move Mac machines to hw/ppc/

2013-01-13 Thread Andreas Färber
Signed-off-by: Andreas Färber afaer...@suse.de
---
 hw/cuda.c |2 +-
 hw/grackle_pci.c  |2 +-
 hw/heathrow_pic.c |2 +-
 hw/ide/macio.c|6 +++---
 hw/mac_nvram.c|2 +-
 hw/macio.c|2 +-
 hw/openpic.c  |2 +-
 hw/ppc/Makefile.objs  |9 +
 hw/{ppc_mac.h = ppc/mac.h}   |0
 hw/{ppc_newworld.c = ppc/mac_newworld.c} |   28 ++--
 hw/{ppc_oldworld.c = ppc/mac_oldworld.c} |   26 +-
 hw/unin_pci.c |2 +-
 12 Dateien geändert, 42 Zeilen hinzugefügt(+), 41 Zeilen entfernt(-)
 rename hw/{ppc_mac.h = ppc/mac.h} (100%)
 rename hw/{ppc_newworld.c = ppc/mac_newworld.c} (98%)
 rename hw/{ppc_oldworld.c = ppc/mac_oldworld.c} (97%)

diff --git a/hw/cuda.c b/hw/cuda.c
index d59e0ae..bbd1fda 100644
--- a/hw/cuda.c
+++ b/hw/cuda.c
@@ -23,7 +23,7 @@
  * THE SOFTWARE.
  */
 #include hw.h
-#include ppc_mac.h
+#include ppc/mac.h
 #include adb.h
 #include qemu/timer.h
 #include sysemu/sysemu.h
diff --git a/hw/grackle_pci.c b/hw/grackle_pci.c
index 9484166..95639d5 100644
--- a/hw/grackle_pci.c
+++ b/hw/grackle_pci.c
@@ -24,7 +24,7 @@
  */
 
 #include pci/pci_host.h
-#include ppc_mac.h
+#include ppc/mac.h
 #include pci/pci.h
 
 /* debug Grackle */
diff --git a/hw/heathrow_pic.c b/hw/heathrow_pic.c
index b9ec8e7..c0a71c3 100644
--- a/hw/heathrow_pic.c
+++ b/hw/heathrow_pic.c
@@ -23,7 +23,7 @@
  * THE SOFTWARE.
  */
 #include hw.h
-#include ppc_mac.h
+#include ppc/mac.h
 
 /* debug PIC */
 //#define DEBUG_PIC
diff --git a/hw/ide/macio.c b/hw/ide/macio.c
index d8f9b4b..e0f04dc 100644
--- a/hw/ide/macio.c
+++ b/hw/ide/macio.c
@@ -22,9 +22,9 @@
  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  * THE SOFTWARE.
  */
-#include hw/hw.h
-#include hw/ppc_mac.h
-#include hw/mac_dbdma.h
+#include hw/hw.h
+#include hw/ppc/mac.h
+#include hw/mac_dbdma.h
 #include block/block.h
 #include sysemu/dma.h
 
diff --git a/hw/mac_nvram.c b/hw/mac_nvram.c
index 71093c2..eec7ca4 100644
--- a/hw/mac_nvram.c
+++ b/hw/mac_nvram.c
@@ -25,7 +25,7 @@
 #include hw.h
 #include firmware_abi.h
 #include sysemu/sysemu.h
-#include ppc_mac.h
+#include ppc/mac.h
 
 /* debug NVR */
 //#define DEBUG_NVR
diff --git a/hw/macio.c b/hw/macio.c
index 675a71c..f01fc57 100644
--- a/hw/macio.c
+++ b/hw/macio.c
@@ -23,7 +23,7 @@
  * THE SOFTWARE.
  */
 #include hw.h
-#include ppc_mac.h
+#include ppc/mac.h
 #include pci/pci.h
 #include escc.h
 
diff --git a/hw/openpic.c b/hw/openpic.c
index 23fa8f9..7423685 100644
--- a/hw/openpic.c
+++ b/hw/openpic.c
@@ -34,7 +34,7 @@
  *
  */
 #include hw.h
-#include ppc_mac.h
+#include ppc/mac.h
 #include pci/pci.h
 #include openpic.h
 #include sysbus.h
diff --git a/hw/ppc/Makefile.objs b/hw/ppc/Makefile.objs
index afdcc0e..462146b 100644
--- a/hw/ppc/Makefile.objs
+++ b/hw/ppc/Makefile.objs
@@ -3,10 +3,6 @@ obj-y = ppc.o ppc_booke.o
 # PREP target
 obj-y += mc146818rtc.o
 obj-y += ppc_prep.o
-# OldWorld PowerMac
-obj-y += ppc_oldworld.o
-# NewWorld PowerMac
-obj-y += ppc_newworld.o
 # IBM pSeries (sPAPR)
 obj-$(CONFIG_PSERIES) += spapr.o spapr_hcall.o spapr_rtas.o spapr_vio.o
 obj-$(CONFIG_PSERIES) += xics.o spapr_vty.o spapr_llan.o spapr_vscsi.o
@@ -28,4 +24,9 @@ obj-y += xilinx_ethlite.o
 
 obj-y := $(addprefix ../,$(obj-y))
 
+# OldWorld PowerMac
+obj-y += mac_oldworld.o
+# NewWorld PowerMac
+obj-y += mac_newworld.o
+# e500
 obj-$(CONFIG_FDT) += e500.o mpc8544ds.o e500plat.o
diff --git a/hw/ppc_mac.h b/hw/ppc/mac.h
similarity index 100%
rename from hw/ppc_mac.h
rename to hw/ppc/mac.h
diff --git a/hw/ppc_newworld.c b/hw/ppc/mac_newworld.c
similarity index 98%
rename from hw/ppc_newworld.c
rename to hw/ppc/mac_newworld.c
index fabcc08..adf111c 100644
--- a/hw/ppc_newworld.c
+++ b/hw/ppc/mac_newworld.c
@@ -46,28 +46,28 @@
  * 0001:05:0c.0 IDE interface [0101]: Broadcom K2 SATA [1166:0240]
  *
  */
-#include hw.h
-#include ppc.h
-#include ppc_mac.h
-#include adb.h
-#include mac_dbdma.h
-#include nvram.h
-#include pci/pci.h
+#include hw/hw.h
+#include hw/ppc.h
+#include hw/ppc/mac.h
+#include hw/adb.h
+#include hw/mac_dbdma.h
+#include hw/nvram.h
+#include hw/pci/pci.h
 #include net/net.h
 #include sysemu/sysemu.h
-#include boards.h
-#include fw_cfg.h
-#include escc.h
-#include openpic.h
-#include ide.h
-#include loader.h
+#include hw/boards.h
+#include hw/fw_cfg.h
+#include hw/escc.h
+#include hw/openpic.h
+#include hw/ide.h
+#include hw/loader.h
 #include elf.h
 #include sysemu/kvm.h
 #include kvm_ppc.h
 #include hw/usb.h
 #include sysemu/blockdev.h
 #include exec/address-spaces.h
-#include sysbus.h
+#include hw/sysbus.h
 
 #define MAX_IDE_BUS 2
 #define CFG_ADDR 0xf510
diff --git a/hw/ppc_oldworld.c b/hw/ppc/mac_oldworld.c
similarity index 97%
rename from hw/ppc_oldworld.c

[Qemu-devel] [RFC ppc-next v3 05/10] macio: Split MacIO in two

2013-01-13 Thread Andreas Färber
Let the machines create two different types. This prepares to move
knowledge about sub-devices from the machines into the devices.

Signed-off-by: Andreas Färber afaer...@suse.de
---
 hw/macio.c|   97 +++--
 hw/ppc/mac.h  |   10 +++--
 hw/ppc/mac_newworld.c |4 +-
 hw/ppc/mac_oldworld.c |4 +-
 4 Dateien geändert, 82 Zeilen hinzugefügt(+), 33 Zeilen entfernt(-)

diff --git a/hw/macio.c b/hw/macio.c
index 8b4b48d..0e6fc8d 100644
--- a/hw/macio.c
+++ b/hw/macio.c
@@ -36,7 +36,6 @@ typedef struct MacIOState
 PCIDevice parent;
 /* public */
 
-int is_oldworld;
 MemoryRegion bar;
 MemoryRegion *pic_mem;
 MemoryRegion *dbdma_mem;
@@ -52,15 +51,6 @@ static void macio_bar_setup(MacIOState *macio_state)
 int i;
 MemoryRegion *bar = macio_state-bar;
 
-if (macio_state-pic_mem) {
-if (macio_state-is_oldworld) {
-/* Heathrow PIC */
-memory_region_add_subregion(bar, 0x0, macio_state-pic_mem);
-} else {
-/* OpenPIC */
-memory_region_add_subregion(bar, 0x4, macio_state-pic_mem);
-}
-}
 if (macio_state-dbdma_mem) {
 memory_region_add_subregion(bar, 0x08000, macio_state-dbdma_mem);
 }
@@ -80,7 +70,7 @@ static void macio_bar_setup(MacIOState *macio_state)
 macio_nvram_setup_bar(macio_state-nvram, bar, 0x6);
 }
 
-static int macio_initfn(PCIDevice *d)
+static int macio_common_initfn(PCIDevice *d)
 {
 MacIOState *s = MACIO(d);
 
@@ -92,6 +82,38 @@ static int macio_initfn(PCIDevice *d)
 return 0;
 }
 
+static int macio_oldworld_initfn(PCIDevice *d)
+{
+MacIOState *s = MACIO(d);
+int ret = macio_common_initfn(d);
+if (ret  0) {
+return ret;
+}
+
+if (s-pic_mem) {
+/* Heathrow PIC */
+memory_region_add_subregion(s-bar, 0x0, s-pic_mem);
+}
+
+return 0;
+}
+
+static int macio_newworld_initfn(PCIDevice *d)
+{
+MacIOState *s = MACIO(d);
+int ret = macio_common_initfn(d);
+if (ret  0) {
+return ret;
+}
+
+if (s-pic_mem) {
+/* OpenPIC */
+memory_region_add_subregion(s-bar, 0x4, s-pic_mem);
+}
+
+return 0;
+}
+
 static void macio_instance_init(Object *obj)
 {
 MacIOState *s = MACIO(obj);
@@ -99,44 +121,69 @@ static void macio_instance_init(Object *obj)
 memory_region_init(s-bar, macio, 0x8);
 }
 
+static void macio_oldworld_class_init(ObjectClass *oc, void *data)
+{
+PCIDeviceClass *pdc = PCI_DEVICE_CLASS(oc);
+
+pdc-init = macio_oldworld_initfn;
+pdc-device_id = PCI_DEVICE_ID_APPLE_343S1201;
+}
+
+static void macio_newworld_class_init(ObjectClass *oc, void *data)
+{
+PCIDeviceClass *pdc = PCI_DEVICE_CLASS(oc);
+
+pdc-init = macio_newworld_initfn;
+pdc-device_id = PCI_DEVICE_ID_APPLE_UNI_N_KEYL;
+}
+
 static void macio_class_init(ObjectClass *klass, void *data)
 {
 PCIDeviceClass *k = PCI_DEVICE_CLASS(klass);
 
-k-init = macio_initfn;
 k-vendor_id = PCI_VENDOR_ID_APPLE;
 k-class_id = PCI_CLASS_OTHERS  8;
 }
 
+static const TypeInfo macio_oldworld_type_info = {
+.name  = TYPE_OLDWORLD_MACIO,
+.parent= TYPE_MACIO,
+.class_init= macio_oldworld_class_init,
+};
+
+static const TypeInfo macio_newworld_type_info = {
+.name  = TYPE_NEWWORLD_MACIO,
+.parent= TYPE_MACIO,
+.class_init= macio_newworld_class_init,
+};
+
 static const TypeInfo macio_type_info = {
 .name  = TYPE_MACIO,
 .parent= TYPE_PCI_DEVICE,
 .instance_size = sizeof(MacIOState),
 .instance_init = macio_instance_init,
+.abstract  = true,
 .class_init= macio_class_init,
 };
 
 static void macio_register_types(void)
 {
 type_register_static(macio_type_info);
+type_register_static(macio_oldworld_type_info);
+type_register_static(macio_newworld_type_info);
 }
 
 type_init(macio_register_types)
 
-void macio_init (PCIBus *bus, int device_id, int is_oldworld,
- MemoryRegion *pic_mem, MemoryRegion *dbdma_mem,
- MemoryRegion *cuda_mem, void *nvram,
- int nb_ide, MemoryRegion **ide_mem,
- MemoryRegion *escc_mem)
+void macio_init(PCIDevice *d,
+MemoryRegion *pic_mem, MemoryRegion *dbdma_mem,
+MemoryRegion *cuda_mem, void *nvram,
+int nb_ide, MemoryRegion **ide_mem,
+MemoryRegion *escc_mem)
 {
-PCIDevice *d;
-MacIOState *macio_state;
+MacIOState *macio_state = MACIO(d);
 int i;
 
-d = pci_create(bus, -1, TYPE_MACIO);
-
-macio_state = MACIO(d);
-macio_state-is_oldworld = is_oldworld;
 macio_state-pic_mem = pic_mem;
 macio_state-dbdma_mem = dbdma_mem;
 macio_state-cuda_mem = cuda_mem;
@@ -147,12 +194,8 @@ void macio_init (PCIBus *bus, int device_id, int 
is_oldworld,
 macio_state-nb_ide = nb_ide;
 for (i = 0; i  

[Qemu-devel] [RFC ppc-next v3 10/10] cuda: QOM'ify CUDA

2013-01-13 Thread Andreas Färber
It was not qdev'ified before, turn it into a SysBusDevice and embed it
in MacIO.

Signed-off-by: Andreas Färber afaer...@suse.de
---
 hw/cuda.c |   98 ++---
 hw/macio.c|   43 +++---
 hw/ppc/mac.h  |   68 +-
 hw/ppc/mac_newworld.c |   21 +--
 hw/ppc/mac_oldworld.c |   18 -
 5 Dateien geändert, 157 Zeilen hinzugefügt(+), 91 Zeilen entfernt(-)

diff --git a/hw/cuda.c b/hw/cuda.c
index bbd1fda..26c96cc 100644
--- a/hw/cuda.c
+++ b/hw/cuda.c
@@ -108,48 +108,6 @@
 /* CUDA returns time_t's offset from Jan 1, 1904, not 1970 */
 #define RTC_OFFSET  2082844800
 
-typedef struct CUDATimer {
-int index;
-uint16_t latch;
-uint16_t counter_value; /* counter value at load time */
-int64_t load_time;
-int64_t next_irq_time;
-QEMUTimer *timer;
-} CUDATimer;
-
-typedef struct CUDAState {
-MemoryRegion mem;
-/* cuda registers */
-uint8_t b;  /* B-side data */
-uint8_t a;  /* A-side data */
-uint8_t dirb;   /* B-side direction (1=output) */
-uint8_t dira;   /* A-side direction (1=output) */
-uint8_t sr; /* Shift register */
-uint8_t acr;/* Auxiliary control register */
-uint8_t pcr;/* Peripheral control register */
-uint8_t ifr;/* Interrupt flag register */
-uint8_t ier;/* Interrupt enable register */
-uint8_t anh;/* A-side data, no handshake */
-
-CUDATimer timers[2];
-
-uint32_t tick_offset;
-
-uint8_t last_b; /* last value of B register */
-uint8_t last_acr; /* last value of B register */
-
-int data_in_size;
-int data_in_index;
-int data_out_index;
-
-qemu_irq irq;
-uint8_t autopoll;
-uint8_t data_in[128];
-uint8_t data_out[16];
-QEMUTimer *adb_poll_timer;
-} CUDAState;
-
-static CUDAState cuda_state;
 ADBBusState adb_bus;
 
 static void cuda_update(CUDAState *s);
@@ -701,9 +659,9 @@ static const VMStateDescription vmstate_cuda = {
 }
 };
 
-static void cuda_reset(void *opaque)
+static void cuda_reset(DeviceState *dev)
 {
-CUDAState *s = opaque;
+CUDAState *s = CUDA(dev);
 
 s-b = 0;
 s-a = 0;
@@ -728,25 +686,57 @@ static void cuda_reset(void *opaque)
 set_counter(s, s-timers[1], 0x);
 }
 
-void cuda_init (MemoryRegion **cuda_mem, qemu_irq irq)
+static int cuda_initfn(SysBusDevice *d)
 {
+CUDAState *s = CUDA(d);
 struct tm tm;
-CUDAState *s = cuda_state;
-
-s-irq = irq;
 
-s-timers[0].index = 0;
 s-timers[0].timer = qemu_new_timer_ns(vm_clock, cuda_timer1, s);
 
-s-timers[1].index = 1;
-
 qemu_get_timedate(tm, 0);
 s-tick_offset = (uint32_t)mktimegm(tm) + RTC_OFFSET;
 
 s-adb_poll_timer = qemu_new_timer_ns(vm_clock, cuda_adb_poll, s);
+
+return 0;
+}
+
+static void cuda_init(Object *obj)
+{
+SysBusDevice *d = SYS_BUS_DEVICE(obj);
+CUDAState *s = CUDA(obj);
+int i;
+
 memory_region_init_io(s-mem, cuda_ops, s, cuda, 0x2000);
+sysbus_init_mmio(d, s-mem);
+sysbus_init_irq(d, s-irq);
+
+for (i = 0; i  2; i++) {
+s-timers[i].index = i;
+}
+}
+
+static void cuda_class_init(ObjectClass *oc, void *data)
+{
+DeviceClass *dc = DEVICE_CLASS(oc);
+SysBusDeviceClass *sdc = SYS_BUS_DEVICE_CLASS(oc);
+
+sdc-init = cuda_initfn;
+dc-reset = cuda_reset;
+dc-vmsd = vmstate_cuda;
+}
+
+static const TypeInfo cuda_type_info = {
+.name = TYPE_CUDA,
+.parent = TYPE_SYS_BUS_DEVICE,
+.instance_size = sizeof(CUDAState),
+.instance_init = cuda_init,
+.class_init = cuda_class_init,
+};
 
-*cuda_mem = s-mem;
-vmstate_register(NULL, -1, vmstate_cuda, s);
-qemu_register_reset(cuda_reset, s);
+static void cuda_register_types(void)
+{
+type_register_static(cuda_type_info);
 }
+
+type_init(cuda_register_types)
diff --git a/hw/macio.c b/hw/macio.c
index 36c00e3..74bdcd1 100644
--- a/hw/macio.c
+++ b/hw/macio.c
@@ -38,9 +38,9 @@ typedef struct MacIOState
 /* public */
 
 MemoryRegion bar;
+CUDAState cuda;
 void *dbdma;
 MemoryRegion *pic_mem;
-MemoryRegion *cuda_mem;
 MemoryRegion *escc_mem;
 } MacIOState;
 
@@ -52,7 +52,7 @@ typedef struct OldWorldMacIOState {
 MacIOState parent_obj;
 /* public */
 
-qemu_irq irqs[2];
+qemu_irq irqs[3];
 
 MacIONVRAMState nvram;
 MACIOIDEState ide;
@@ -65,7 +65,7 @@ typedef struct NewWorldMacIOState {
 /* private */
 MacIOState parent_obj;
 /* public */
-qemu_irq irqs[4];
+qemu_irq irqs[5];
 MACIOIDEState ide[2];
 } NewWorldMacIOState;
 
@@ -76,17 +76,24 @@ static void macio_bar_setup(MacIOState *macio_state)
 if (macio_state-escc_mem) {
 memory_region_add_subregion(bar, 0x13000, macio_state-escc_mem);
 }
-if (macio_state-cuda_mem) {
-memory_region_add_subregion(bar, 0x16000, macio_state-cuda_mem);
-}
 }
 
 static int macio_common_initfn(PCIDevice 

[Qemu-devel] [PATCH 01/10] qom: Make object_resolve_path_component() path argument const

2013-01-13 Thread Andreas Färber
This allows to navigate partial well-known paths from an object.

Signed-off-by: Andreas Färber afaer...@suse.de
Cc: Anthony Liguori anth...@codemonkey.ws
---
 include/qom/object.h |2 +-
 qom/object.c |2 +-
 2 Dateien geändert, 2 Zeilen hinzugefügt(+), 2 Zeilen entfernt(-)

diff --git a/include/qom/object.h b/include/qom/object.h
index d43b289..1ef2f0e 100644
--- a/include/qom/object.h
+++ b/include/qom/object.h
@@ -900,7 +900,7 @@ Object *object_resolve_path_type(const char *path, const 
char *typename,
  *
  * Returns: The resolved object or NULL on path lookup failure.
  */
-Object *object_resolve_path_component(Object *parent, gchar *part);
+Object *object_resolve_path_component(Object *parent, const gchar *part);
 
 /**
  * object_property_add_child:
diff --git a/qom/object.c b/qom/object.c
index 351b88c..03e6f24 100644
--- a/qom/object.c
+++ b/qom/object.c
@@ -1017,7 +1017,7 @@ gchar *object_get_canonical_path(Object *obj)
 return newpath;
 }
 
-Object *object_resolve_path_component(Object *parent, gchar *part)
+Object *object_resolve_path_component(Object *parent, const gchar *part)
 {
 ObjectProperty *prop = object_property_find(parent, part, NULL);
 if (prop == NULL) {
-- 
1.7.10.4




[Qemu-devel] [RFC ppc-next v3 09/10] ide/macio: QOM'ify MacIO IDE

2013-01-13 Thread Andreas Färber
It was not qdev'ified before, turn it into a SysBusDevice.
Embed them into the MacIO devices.

Signed-off-by: Andreas Färber afaer...@suse.de
Cc: Markus Armbruster arm...@redhat.com
---
 hw/ide.h  |4 --
 hw/ide/macio.c|   81 ---
 hw/macio.c|  102 ++---
 hw/ppc/mac.h  |   25 +++-
 hw/ppc/mac_newworld.c |   28 --
 hw/ppc/mac_oldworld.c |   36 -
 6 Dateien geändert, 198 Zeilen hinzugefügt(+), 78 Zeilen entfernt(-)

diff --git a/hw/ide.h b/hw/ide.h
index 7e23cda..9b357c0 100644
--- a/hw/ide.h
+++ b/hw/ide.h
@@ -19,10 +19,6 @@ PCIDevice *pci_piix3_ide_init(PCIBus *bus, DriveInfo 
**hd_table, int devfn);
 PCIDevice *pci_piix4_ide_init(PCIBus *bus, DriveInfo **hd_table, int devfn);
 void vt82c686b_ide_init(PCIBus *bus, DriveInfo **hd_table, int devfn);
 
-/* ide-macio.c */
-MemoryRegion *pmac_ide_init (DriveInfo **hd_table, qemu_irq irq,
-  void *dbdma, int channel, qemu_irq dma_irq);
-
 /* ide-mmio.c */
 void mmio_ide_init (hwaddr membase, hwaddr membase2,
 MemoryRegion *address_space,
diff --git a/hw/ide/macio.c b/hw/ide/macio.c
index e0f04dc..ca018f6 100644
--- a/hw/ide/macio.c
+++ b/hw/ide/macio.c
@@ -33,12 +33,6 @@
 /***/
 /* MacIO based PowerPC IDE */
 
-typedef struct MACIOIDEState {
-MemoryRegion mem;
-IDEBus bus;
-BlockDriverAIOCB *aiocb;
-} MACIOIDEState;
-
 #define MACIO_PAGE_SIZE 4096
 
 static void pmac_ide_atapi_transfer_cb(void *opaque, int ret)
@@ -321,30 +315,73 @@ static const VMStateDescription vmstate_pmac = {
 }
 };
 
-static void pmac_ide_reset(void *opaque)
+static void macio_ide_reset(DeviceState *dev)
 {
-MACIOIDEState *d = opaque;
+MACIOIDEState *d = MACIO_IDE(dev);
 
 ide_bus_reset(d-bus);
 }
 
-/* hd_table must contain 4 block drivers */
-/* PowerMac uses memory mapped registers, not I/O. Return the memory
-   I/O index to access the ide. */
-MemoryRegion *pmac_ide_init (DriveInfo **hd_table, qemu_irq irq,
- void *dbdma, int channel, qemu_irq dma_irq)
+static int macio_ide_initfn(SysBusDevice *d)
 {
-MACIOIDEState *d;
+MACIOIDEState *s = MACIO_IDE(d);
 
-d = g_malloc0(sizeof(MACIOIDEState));
-ide_init2_with_non_qdev_drives(d-bus, hd_table[0], hd_table[1], irq);
+ide_init2(s-bus, s-irq);
 
-if (dbdma)
-DBDMA_register_channel(dbdma, channel, dma_irq, pmac_ide_transfer, 
pmac_ide_flush, d);
+return 0;
+}
+
+static void macio_ide_init(Object *obj)
+{
+SysBusDevice *d = SYS_BUS_DEVICE(obj);
+MACIOIDEState *s = MACIO_IDE(obj);
+
+ide_bus_new(s-bus, DEVICE(obj), 0);
+memory_region_init_io(s-mem, pmac_ide_ops, s, pmac-ide, 0x1000);
+sysbus_init_mmio(d, s-mem);
+sysbus_init_irq(d, s-irq);
+sysbus_init_irq(d, s-dma_irq);
+}
 
-memory_region_init_io(d-mem, pmac_ide_ops, d, pmac-ide, 0x1000);
-vmstate_register(NULL, 0, vmstate_pmac, d);
-qemu_register_reset(pmac_ide_reset, d);
+static void macio_ide_class_init(ObjectClass *oc, void *data)
+{
+DeviceClass *dc = DEVICE_CLASS(oc);
+SysBusDeviceClass *sdc = SYS_BUS_DEVICE_CLASS(oc);
 
-return d-mem;
+dc-reset = macio_ide_reset;
+dc-vmsd = vmstate_pmac;
+sdc-init = macio_ide_initfn;
 }
+
+static const TypeInfo macio_ide_type_info = {
+.name = TYPE_MACIO_IDE,
+.parent = TYPE_SYS_BUS_DEVICE,
+.instance_size = sizeof(MACIOIDEState),
+.instance_init = macio_ide_init,
+.class_init = macio_ide_class_init,
+};
+
+static void macio_ide_register_types(void)
+{
+type_register_static(macio_ide_type_info);
+}
+
+/* hd_table must contain 4 block drivers */
+void macio_ide_init_drives(MACIOIDEState *s, DriveInfo **hd_table)
+{
+int i;
+
+for (i = 0; i  2; i++) {
+if (hd_table[i]) {
+ide_create_drive(s-bus, i, hd_table[i]);
+}
+}
+}
+
+void macio_ide_register_dma(MACIOIDEState *s, void *dbdma, int channel)
+{
+DBDMA_register_channel(dbdma, channel, s-dma_irq,
+   pmac_ide_transfer, pmac_ide_flush, s);
+}
+
+type_init(macio_ide_register_types)
diff --git a/hw/macio.c b/hw/macio.c
index 32f359c..36c00e3 100644
--- a/hw/macio.c
+++ b/hw/macio.c
@@ -25,6 +25,7 @@
 #include hw.h
 #include ppc/mac.h
 #include pci/pci.h
+#include mac_dbdma.h
 #include escc.h
 
 #define TYPE_MACIO macio
@@ -37,12 +38,10 @@ typedef struct MacIOState
 /* public */
 
 MemoryRegion bar;
+void *dbdma;
 MemoryRegion *pic_mem;
-MemoryRegion *dbdma_mem;
 MemoryRegion *cuda_mem;
 MemoryRegion *escc_mem;
-int nb_ide;
-MemoryRegion *ide_mem[4];
 } MacIOState;
 
 #define OLDWORLD_MACIO(obj) \
@@ -53,29 +52,33 @@ typedef struct OldWorldMacIOState {
 MacIOState parent_obj;
 /* public */
 
+qemu_irq irqs[2];
+
 MacIONVRAMState nvram;
+MACIOIDEState ide;
 } 

[Qemu-devel] [RFC ppc-next v3 06/10] mac_nvram: Clean up public API

2013-01-13 Thread Andreas Färber
The state data field is accessed in uint8_t quantities, so switch from
uint32_t argument and return value to uint8_t.

Fix debug format specifiers while at it.

Signed-off-by: Andreas Färber afaer...@suse.de
---
 hw/mac_nvram.c |   21 ++---
 hw/ppc/mac.h   |4 ++--
 2 Dateien geändert, 12 Zeilen hinzugefügt(+), 13 Zeilen entfernt(-)

diff --git a/hw/mac_nvram.c b/hw/mac_nvram.c
index eec7ca4..bcde07d 100644
--- a/hw/mac_nvram.c
+++ b/hw/mac_nvram.c
@@ -47,27 +47,26 @@ struct MacIONVRAMState {
 #define DEF_SYSTEM_SIZE 0xc10
 
 /* Direct access to NVRAM */
-uint32_t macio_nvram_read (void *opaque, uint32_t addr)
+uint8_t macio_nvram_read(MacIONVRAMState *s, uint32_t addr)
 {
-MacIONVRAMState *s = opaque;
 uint32_t ret;
 
-if (addr  s-size)
+if (addr  s-size) {
 ret = s-data[addr];
-else
+} else {
 ret = -1;
-NVR_DPRINTF(read addr %04x val %x\n, addr, ret);
+}
+NVR_DPRINTF(read addr %04 PRIx32  val % PRIx8 \n, addr, ret);
 
 return ret;
 }
 
-void macio_nvram_write (void *opaque, uint32_t addr, uint32_t val)
+void macio_nvram_write(MacIONVRAMState *s, uint32_t addr, uint8_t val)
 {
-MacIONVRAMState *s = opaque;
-
-NVR_DPRINTF(write addr %04x val %x\n, addr, val);
-if (addr  s-size)
+NVR_DPRINTF(write addr %04 PRIx32  val % PRIx8 \n, addr, val);
+if (addr  s-size) {
 s-data[addr] = val;
+}
 }
 
 /* macio style NVRAM device */
@@ -78,7 +77,7 @@ static void macio_nvram_writeb(void *opaque, hwaddr addr,
 
 addr = (addr  s-it_shift)  (s-size - 1);
 s-data[addr] = value;
-NVR_DPRINTF(writeb addr %04x val %x\n, (int)addr, value);
+NVR_DPRINTF(writeb addr %04 PHYS_PRIx  val % PRIx64 \n, addr, value);
 }
 
 static uint64_t macio_nvram_readb(void *opaque, hwaddr addr,
diff --git a/hw/ppc/mac.h b/hw/ppc/mac.h
index 864a610..6441794 100644
--- a/hw/ppc/mac.h
+++ b/hw/ppc/mac.h
@@ -78,6 +78,6 @@ MacIONVRAMState *macio_nvram_init (hwaddr size,
 void macio_nvram_setup_bar(MacIONVRAMState *s, MemoryRegion *bar,
hwaddr mem_base);
 void pmac_format_nvram_partition (MacIONVRAMState *nvr, int len);
-uint32_t macio_nvram_read (void *opaque, uint32_t addr);
-void macio_nvram_write (void *opaque, uint32_t addr, uint32_t val);
+uint8_t macio_nvram_read(MacIONVRAMState *s, uint32_t addr);
+void macio_nvram_write(MacIONVRAMState *s, uint32_t addr, uint8_t val);
 #endif /* !defined(__PPC_MAC_H__) */
-- 
1.7.10.4




Re: [Qemu-devel] [PATCH] reading files from qcow2-formated image disk for windows system

2013-01-13 Thread Wanlong Gao
On 01/12/2013 08:00 PM, Blue Swirl wrote:
 On Fri, Jan 11, 2013 at 7:27 AM, 马磊 aware@gmail.com wrote:


 On Fri, Jan 11, 2013 at 2:28 PM, Wanlong Gao gaowanl...@cn.fujitsu.com
 wrote:

 On 01/11/2013 11:39 AM, 马磊 wrote:


 On Thu, Jan 10, 2013 at 8:20 PM, Daniel P. Berrange berra...@redhat.com
 mailto:berra...@redhat.com wrote:

 On Wed, Jan 09, 2013 at 09:37:54PM +, Blue Swirl wrote:
  On Wed, Jan 9, 2013 at 7:31 AM, 马磊 aware@gmail.com
 mailto:aware@gmail.com wrote:
  
  
   Hi,
   The final effect is as follows:
  
  
   [malei@xentest-4-1 Fri Dec 28 ~/honeypot/xen/xen-4.1.2]$
 qemu-img-xen cat
   -f /1/boot.ini ~/vm-check.img
   [boot loader]
   timeout=30
   default=multi(0)disk(0)rdisk(0)partition(1)\WINDOWS
   [operating systems]
   multi(0)disk(0)rdisk(0)partition(1)\WINDOWS=Microsoft Windows
 XP
   Professional /noexecute=optin /fastdetect
  
   [malei@xentest-4-1 Fri Dec 28 ~/honeypot/xen/xen-4.1.2]$
 qemu-img-xen ls
   -l -d /1/ ~/vm-check.img
   【name size(bytes) dir?  date
   create-time】
   AUTOEXEC.BAT 0file 2010-12-2217:30:37
   boot.ini   211file 2010-12-23
 01:24:41
   bootfont.bin  322730file 2004-11-23
 20:00:00
  
  
  
   As you see above, the patch add two sub-commands for
 qemu-img-xen:cat and
   ls.
  
   For details in the patch, please check the attachment.
  
  
  
   Does anyone prefer this feature?!
 
  Nice feature, but this approach would just clutter QEMU and give
 only
  readonly FAT or NTFS support. I think a more generally useful
 approach
  would be to use NBD or iSCSI to export the block device data from
 the
  image file (qemu-nbd already exists) and then make a tool that
 uses
  some combination of NBD/iSCSI client, all GRUB file systems and
 FUSE
  or other user space methods to access the contents of the
 filesystem.
  Probably also UML with a simple guest agent could provide
 read/write
  access to any file system that Linux supports.

 The latter is what libguestfs already provides. It boots a Linux
 kernel
 and mini initrd containing a guest agent, to provide APIs to do
 arbitrary
 manipulation of guest OS images.

 The reason libguestfs used a linux guest was precisely to avoid
 having
 to re-implement drivers for every filesystem in existance like this
 patch is trying todo.

 I don't think QEMU wants to be in the business of maintaining
 filesystem
 drivers, so I'd reject this proposed patch.

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



 This feature could be configured to be optional in make file
 configuration according to individual preference.
 _In addition, the fat32 and ntfs filesystem driver will not change for a
 long time so it needs no much maintainence  once implemented._

 As Daniel and Stefan said, you can try to use libguestfs [libguestfs.org]
 and qemu-nbd.
 In libguestfs, we provide virt-cat, virt-ls, etc. And support all the disk
 type which QEMU supported.

 Thanks,
 Wanlong Gao


 I used libguest, it's startup takes too long to meet specific requirements
 under some time-sensitive circumstance.
 
 For maximum speed, the backing formats (QCOW etc) should be
 implemented in the kernel directly, somewhat like device mapper or
 /dev/loop device.
 
 A very simple and fast approach without any changes would be to
 convince the guest to not to use partitions and instead use one file
 system for an entire block device, then the backing file (in raw
 format, no QCOW etc) could be manipulated by mounting it with the
 loopback device.
 
 Alternatively, we could implement in QEMU a way to concatenate several
 separate files into one, each of the files containing a partition or
 some space for partition table. Then the files could be again accessed
 with loopback mount. The partition table could be also synthesized.
 
 I don't know why the loopback mount in the kernel does not support
 partitions, that would also solve the problem when using raw files.

AFAIK, the loopback mount can recognize partitions like this:
# dd if=/dev/zero of=test_part.img bs=1M count=100
100+0 records in
100+0 records out
104857600 bytes (105 MB) copied, 0.0593102 s, 1.8 GB/s
# losetup /dev/loop0 test_part.img 
# parted -s /dev/loop0 mklabel msdos
# parted -s /dev/loop0 mkpart primary 1 16
# parted -s /dev/loop0 mkpart extended 17 64
# parted -s /dev/loop0 mkpart logical 18 32
Warning: The resulting partition is not properly aligned for best performance.
# kpartx  

Re: [Qemu-devel] [PATCH V2 00/10] snapshot: take block snapshots in unified way

2013-01-13 Thread Wenchao Xia

于 2013-1-11 21:56, Luiz Capitulino 写道:

On Thu, 10 Jan 2013 14:01:27 +0800
Wenchao Xia xiaw...@linux.vnet.ibm.com wrote:


于 2013-1-10 6:34, Eric Blake 写道:

On 01/07/2013 12:27 AM, Wenchao Xia wrote:

These patch added a seperated layer to take internal or external snapshots
in a unified way, the granularity is block device, so other functions can
just combine the request and submit, such as group snapshot, savevm.

Total goal are:
Live back up vm in external or internal image, which need three functions:
1 live snapshot block device internal/external.
2 live save vmstate internal/external.
3 combination of the function unit.

This serial provide part one.



The design on this series needs to be coordinated with Pavel's
attempts[1] to convert the existing HMP snapshot commands into QMP.  I
don't want to spend too much time reviewing two different divergent
designs that both have the same goal of finally managing snapshots under
QMP.

[1] https://lists.gnu.org/archive/html/qemu-devel/2013-01/msg01326.html


A bit difference: This serial are taking internal/external block
snapshots but Pavel's are focusing are vm whole internal snapshots. It


Pavel's work makes savevm, loadvm and delvm available in QMP. Also note
that we do have blockdev-snapshot-sync. How does this series relate to it?

I don't know if it's just me but, honestly speaking, I'm getting confused
about the various proposals and APIs for snapshots.

IMHO, it's time to go back a bit from code and discuss the status of the
current APIs, what's missing and what the proposals are.

This should also include writing a wiki page, as Anthony has done for
previous ideas (which worked quite well).


  I agree, can you help create an account on qemu wiki for me?

--
Best Regards

Wenchao Xia




Re: [Qemu-devel] [PATCH V5 4/6] HMP: filter out space before check of sub-command

2013-01-13 Thread Wenchao Xia

于 2013-1-12 4:12, Luiz Capitulino 写道:

On Fri, 11 Jan 2013 17:14:03 +0800
Wenchao Xia xiaw...@linux.vnet.ibm.com wrote:


   This fix the case when user input @command . Original
it will return NULL for monitor_parse_command(), now
it will return the @command related instance.

Signed-off-by: Wenchao Xia xiaw...@linux.vnet.ibm.com
---
  monitor.c |3 +++
  1 files changed, 3 insertions(+), 0 deletions(-)

diff --git a/monitor.c b/monitor.c
index 5435dc3..7b752a2 100644
--- a/monitor.c
+++ b/monitor.c
@@ -3588,6 +3588,9 @@ static const mon_cmd_t *monitor_parse_command(Monitor 
*mon,
  if (cmd-sub_table != NULL) {
  p1 = p;
  /* check if user set additional command */
+while (qemu_isspace(*p1)) {
+p1++;
+}


Is there a reason for this to be in a different patch? I mean, why don't
you squash this into the previous patch?


  Markus suggest to do it and I think this make things clear. I am OK
to merge it and drop p1.


Actually, I guess that you could skip the spaces after the
search_dispatch_table() call (using p) and drop p1. But please test it
before doing so :)

Otherwise series looks good to me.


  if (*p1 == '\0') {
  return cmd;
  }





--
Best Regards

Wenchao Xia




[Qemu-devel] [Bug 1033727] Re: USB passthrough doesn't work anymore with qemu-kvm 1.1.1

2013-01-13 Thread Nikolaus Rath
Thanks a lot Peter! I can confirm that this patch fixes the problems
when added on top of Debian's qemu-kvm 1.1.2+dfsg-4 package. I have
attached a patch against the Debian git tree.

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

Title:
  USB passthrough doesn't work anymore with qemu-kvm 1.1.1

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

Bug description:
  Hi,

  I have a Bus 006 Device 002: ID 0d46:3003 Kobil Systems GmbH mIDentity Light 
/ KAAN SIM III (kind of smart card) in an USB port which I make available to a 
Windows XP guest.
  This worked fine with every older qemu-kvm version I've used so far.

  But since 1.1.0 it doesn't work anymore.
  The device shows up in the guest, but the software can't access it anymore 
(and the guest is pretty unresponsive).

  On the host I get every 2 seconds this message:
  [ 7719.239528] usb 6-1: reset full-speed USB device number 2 using uhci_hcd

  Command line options are:
  /usr/bin/kvm
  ...
  -device usb-host,vendorid=0x0d46,productid=0x3003,bus=usb.0,port=3
  ...

  When I switch back to qemu-kvm 1.0.1 everything works fine again.
  Any idea what the problem could be?

  Thanks
  Klaus

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



[Qemu-devel] [Bug 1033727] Re: USB passthrough doesn't work anymore with qemu-kvm 1.1.1

2013-01-13 Thread Nikolaus Rath
** Patch added: Patch against debian package
   
https://bugs.launchpad.net/qemu/+bug/1033727/+attachment/3482404/+files/qemu-debian.diff

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

Title:
  USB passthrough doesn't work anymore with qemu-kvm 1.1.1

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

Bug description:
  Hi,

  I have a Bus 006 Device 002: ID 0d46:3003 Kobil Systems GmbH mIDentity Light 
/ KAAN SIM III (kind of smart card) in an USB port which I make available to a 
Windows XP guest.
  This worked fine with every older qemu-kvm version I've used so far.

  But since 1.1.0 it doesn't work anymore.
  The device shows up in the guest, but the software can't access it anymore 
(and the guest is pretty unresponsive).

  On the host I get every 2 seconds this message:
  [ 7719.239528] usb 6-1: reset full-speed USB device number 2 using uhci_hcd

  Command line options are:
  /usr/bin/kvm
  ...
  -device usb-host,vendorid=0x0d46,productid=0x3003,bus=usb.0,port=3
  ...

  When I switch back to qemu-kvm 1.0.1 everything works fine again.
  Any idea what the problem could be?

  Thanks
  Klaus

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



Re: [Qemu-devel] [PATCH v4 1/3] target-i386:define name of breakpoint bit in dr7

2013-01-13 Thread li guang
在 2013-01-11五的 17:10 +0100,Andreas Färber写道:
 Am 10.12.2012 03:22, schrieb liguang:
  Signed-off-by: liguang lig.f...@cn.fujitsu.com
 
 For a patch series consisting of more than 1 patch, please use a cover
 letter (e.g., --cover-letter) that details the change history of the
 versions. That also facilitates commenting on the series vs. a single patch.
 
  ---
   target-i386/cpu.h |7 +++
   1 files changed, 7 insertions(+), 0 deletions(-)
  
  diff --git a/target-i386/cpu.h b/target-i386/cpu.h
  index 90ef1ff..29245d1 100644
  --- a/target-i386/cpu.h
  +++ b/target-i386/cpu.h
  @@ -231,6 +231,13 @@
   #define DR7_TYPE_SHIFT  16
   #define DR7_LEN_SHIFT   18
   #define DR7_FIXED_1 0x0400
  +#define DR7_LOCAL_BP_MASK   0x55
  +#define DR7_MAX_BP  4
  +#define DR7_TYPE_BP_INST 0x0
  +#define DR7_TYPE_DATA_WR 0x1
  +#define DR7_TYPE_IO_RW   0x2
  +#define DR7_TYPE_DATA_RW 0x3
  +
   
   #define PG_PRESENT_BIT 0
   #define PG_RW_BIT  1
 
 These defines are being introduced but not used in this patch yet. If
 you were to replace, e.g., 4 - DR7_MAX_BP in this patch instead of
 patch 3/3, I would see a value in cherry-picking it. Assuming there is
 agreement on that name, of course.
 
 Andreas
 


OK, I will squash them into one patch.
 
-- 
regards!
li guang




Re: [Qemu-devel] [PATCH V2 07/10] snapshot: qmp use new internal API for external snapshot transaction

2013-01-13 Thread Wenchao Xia

于 2013-1-11 17:12, Stefan Hajnoczi 写道:

On Fri, Jan 11, 2013 at 02:22:28PM +0800, Wenchao Xia wrote:

于 2013-1-10 20:41, Stefan Hajnoczi 写道:

On Thu, Jan 10, 2013 at 11:21:22AM +0800, Wenchao Xia wrote:

于 2013-1-9 20:44, Stefan Hajnoczi 写道:

On Mon, Jan 07, 2013 at 03:28:06PM +0800, Wenchao Xia wrote:

   This patch switch to internal common API to take group external
snapshots from qmp_transaction interface. qmp layer simply does
a translation from user input.

Signed-off-by: Wenchao Xia xiaw...@linux.vnet.ibm.com
---
  blockdev.c |  215 
  1 files changed, 87 insertions(+), 128 deletions(-)


An internal API for snapshots is not necessary.  qmp_transaction() is
already usable both from the monitor and C code.

The QAPI code generator creates structs that can be accessed directly

from C.  qmp_transaction(), BlockdevAction, and BlockdevActionList *is*

the snapshot API.  It just doesn't support internal snapshots yet, which
is what you are trying to add.

To add internal snapshot support, define a BlockdevInternalSnapshot type
in qapi-schema.json and add internal snapshot support in
qmp_transaction().

qmp_transaction() was designed with this in mind from the beginning and
dispatches based on BlockdevAction-kind.

The patch series will become much smaller while still adding internal
snapshot support.

Stefan



   As API, qmp_transaction have following disadvantages:
1) interface is based on string not data type inside qemu, that means
other function calling it result in: bdrv-string-bdrv


Use bdrv_get_device_name().  You already need to fill in filename or
snapshot name strings.  This is not a big disadvantage.


   Yes, not a big disadvantage, but why not save string operation but
use (bdrv*) as much as possible?

what happens will be:

hmp-snapshot
 |
qmp-snapshot
 |-
  |
 qmp-transactionsavevm(may be other..)
  |--|
 |
   internal transaction layer


Saving the string operation is not worth duplicating the API.


  I agree with you for this line:), but,  it is a weight on the balance
of choice, pls consider it together with issues below.


2) all capability are forced to be exposed.


Is there something you cannot expose?


   As other component in qemu can use it, some option may
be used only in qemu not to user. For eg, vm-state-size.


When we hit a limitation of QAPI then it needs to be extended.  I'm sure
there's a solution for splitting or hiding parts of the QAPI generated
API.


  I can't think it out now, it seems to be a bit tricky.


3) need structure to record each transaction state, such as
BlkTransactionStates. Extending it is equal to add an internal layer.


I agree that extending it is equal coding effort to adding an internal
layer because you'll need to refactor qmp_transaction() a bit to really
support additional action types.

But it's the right thing to do.  Don't add unnecessary layers just
because writing new code is more fun than extending existing code.


  If this layer is not added but depending only qmp_transaction, there
will be many if else fragment. I have tried that and the code
is awkful, this layer did not bring extra burden only make what
happens inside qmp_transaction clearer, I did not add this layer just
for fun.



   Actually I started up by use qmp_transaction as API, but soon
found that work is almost done around BlkTransactionStates, so
added a layer around it clearly.


The qmp_transaction() implementation can be changed, I'm not saying you
have to hack in more if statements.  It's cleanest to introduce a
BdrvActionOps abstraction:

typedef struct BdrvActionOps BdrvActionOps;
typedef struct BdrvTransactionState {
 const BdrvActionOps *ops;
 QLIST_ENTRY(BdrvTransactionState);
} BdrvTransactionState;

struct BdrvActionOps {
 int (*prepare)(BdrvTransactionState *s, ...);
 int (*commit)(BdrvTransactionState *s, ...);
 int (*rollback)(BdrvTransactionState *s, ...);
};

BdrvTransactionState *bdrv_transaction_create(BlockdevAction *action);

Then qmp_transaction() can be generic code that steps through the
transactions.

  With internal API, qmp_transaction can still be generic code with
a translate from bdrv* to char* at caller level.

  This is similar to what your series does and I think it's

the right direction.

But please don't duplicate the qmp_transaction() and
BlockdevAction/BlockdevActionList APIs.  In other words, change the
engine, not the whole car.

Stefan



  If my understanding is correct, the BdrvActionOps need to be extended
as following:
struct BdrvActionOps {
 /* need following for callback functions */
 const char *sn_name;
 BlockDriverState *bs;
 ...
 int (*prepare)(BdrvTransactionState *s, ...);
 int (*commit)(BdrvTransactionState *s, ...);
 int (*rollback)(BdrvTransactionState *s, ...);
};
Or an opaque* should 

Re: [Qemu-devel] [PATCH 1/3] qga: add support to get host time

2013-01-13 Thread Lei Li

On 01/11/2013 11:37 PM, Eric Blake wrote:

On 01/11/2013 12:18 AM, Lei Li wrote:

For this version, it's a one-hour offset represented as:±[hh].
Negative values are west, andpositive values are east of UTC.

Won't work.  There are timezones with a half-hour offset.  You need to
express offset at least in terms of minutes, not just hours.


Yes, I have thought about this. For the timezones with a half-hour offset,
it can just represented as +0.5 for example.



--
Lei




[Qemu-devel] [Bug 1033727] Re: USB passthrough doesn't work anymore with qemu-kvm 1.1.1

2013-01-13 Thread Ubuntu Foundations Team Bug Bot
The attachment Patch against debian package of this bug report has
been identified as being a patch in the form of a debdiff.  The ubuntu-
sponsors team has been subscribed to the bug report so that they can
review and hopefully sponsor the debdiff.  In the event that this is in
fact not a patch you can resolve this situation by removing the tag
'patch' from the bug report and editing the attachment so that it is not
flagged as a patch.  Additionally, if you are member of the ubuntu-
sponsors team please also unsubscribe the team from this bug report.

[This is an automated message performed by a Launchpad user owned by
Brian Murray.  Please contact him regarding any issues with the action
taken in this bug report.]

** Tags added: patch

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

Title:
  USB passthrough doesn't work anymore with qemu-kvm 1.1.1

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

Bug description:
  Hi,

  I have a Bus 006 Device 002: ID 0d46:3003 Kobil Systems GmbH mIDentity Light 
/ KAAN SIM III (kind of smart card) in an USB port which I make available to a 
Windows XP guest.
  This worked fine with every older qemu-kvm version I've used so far.

  But since 1.1.0 it doesn't work anymore.
  The device shows up in the guest, but the software can't access it anymore 
(and the guest is pretty unresponsive).

  On the host I get every 2 seconds this message:
  [ 7719.239528] usb 6-1: reset full-speed USB device number 2 using uhci_hcd

  Command line options are:
  /usr/bin/kvm
  ...
  -device usb-host,vendorid=0x0d46,productid=0x3003,bus=usb.0,port=3
  ...

  When I switch back to qemu-kvm 1.0.1 everything works fine again.
  Any idea what the problem could be?

  Thanks
  Klaus

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



[Qemu-devel] [PATCH 1/2] sheepdog: multiplex the rw FD to flush cache

2013-01-13 Thread Liu Yuan
From: Liu Yuan tailai...@taobao.com

This will reduce sockfds connected to the sheep server to one, which simply the
future hacks.

Cc: MORITA Kazutaka morita.kazut...@lab.ntt.co.jp
Cc: Kevin Wolf kw...@redhat.com
Cc: Stefan Hajnoczi stefa...@redhat.com
Signed-off-by: Liu Yuan tailai...@taobao.com
---
 block/sheepdog.c |   64 +++---
 1 file changed, 27 insertions(+), 37 deletions(-)

diff --git a/block/sheepdog.c b/block/sheepdog.c
index 462c4b2..4e38670 100644
--- a/block/sheepdog.c
+++ b/block/sheepdog.c
@@ -266,6 +266,7 @@ typedef struct AIOReq {
 enum AIOCBState {
 AIOCB_WRITE_UDATA,
 AIOCB_READ_UDATA,
+AIOCB_FLUSH_CACHE,
 };
 
 struct SheepdogAIOCB {
@@ -299,7 +300,6 @@ typedef struct BDRVSheepdogState {
 char *addr;
 char *port;
 int fd;
-int flush_fd;
 
 CoMutex lock;
 Coroutine *co_send;
@@ -736,6 +736,13 @@ static void coroutine_fn aio_read_response(void *opaque)
 goto out;
 }
 break;
+case AIOCB_FLUSH_CACHE:
+if (rsp.result == SD_RES_INVALID_PARMS) {
+dprintf(disable cache since the server doesn't support it\n);
+s-cache_flags = SD_FLAG_CMD_DIRECT;
+rsp.result = SD_RES_SUCCESS;
+}
+break;
 }
 
 if (rsp.result != SD_RES_SUCCESS) {
@@ -964,7 +971,10 @@ static int coroutine_fn add_aio_request(BDRVSheepdogState 
*s, AIOReq *aio_req,
 
 memset(hdr, 0, sizeof(hdr));
 
-if (aiocb_type == AIOCB_READ_UDATA) {
+if (aiocb_type == AIOCB_FLUSH_CACHE) {
+wlen = 0;
+hdr.opcode = SD_OP_FLUSH_VDI;
+} else if (aiocb_type == AIOCB_READ_UDATA) {
 wlen = 0;
 hdr.opcode = SD_OP_READ_OBJ;
 hdr.flags = flags;
@@ -1127,15 +1137,6 @@ static int sd_open(BlockDriverState *bs, const char 
*filename, int flags)
 s-cache_flags = SD_FLAG_CMD_DIRECT;
 }
 
-if (s-cache_flags == SD_FLAG_CMD_CACHE) {
-s-flush_fd = connect_to_sdog(s-addr, s-port);
-if (s-flush_fd  0) {
-error_report(failed to connect);
-ret = s-flush_fd;
-goto out;
-}
-}
-
 if (snapid || tag[0] != '\0') {
 dprintf(% PRIx32  snapshot inode was open.\n, vid);
 s-is_snapshot = true;
@@ -1397,9 +1398,6 @@ static void sd_close(BlockDriverState *bs)
 
 qemu_aio_set_fd_handler(s-fd, NULL, NULL, NULL, NULL);
 closesocket(s-fd);
-if (s-cache_flags) {
-closesocket(s-flush_fd);
-}
 g_free(s-addr);
 }
 
@@ -1711,39 +1709,31 @@ static coroutine_fn int sd_co_readv(BlockDriverState 
*bs, int64_t sector_num,
 static int coroutine_fn sd_co_flush_to_disk(BlockDriverState *bs)
 {
 BDRVSheepdogState *s = bs-opaque;
-SheepdogObjReq hdr = { 0 };
-SheepdogObjRsp *rsp = (SheepdogObjRsp *)hdr;
-SheepdogInode *inode = s-inode;
+SheepdogAIOCB *acb;
+AIOReq *aio_req;
 int ret;
-unsigned int wlen = 0, rlen = 0;
 
 if (s-cache_flags != SD_FLAG_CMD_CACHE) {
 return 0;
 }
 
-hdr.opcode = SD_OP_FLUSH_VDI;
-hdr.oid = vid_to_vdi_oid(inode-vdi_id);
+acb = sd_aio_setup(bs, NULL, 0, 0, NULL, NULL);
+acb-aiocb_type = AIOCB_FLUSH_CACHE;
+acb-aio_done_func = sd_finish_aiocb;
 
-ret = do_req(s-flush_fd, (SheepdogReq *)hdr, NULL, wlen, rlen);
-if (ret) {
-error_report(failed to send a request to the sheep);
+aio_req = alloc_aio_req(s, acb, vid_to_vdi_oid(s-inode.vdi_id),
+0, 0, 0, 0, 0);
+QLIST_INSERT_HEAD(s-inflight_aio_head, aio_req, aio_siblings);
+ret = add_aio_request(s, aio_req, NULL, 0, false, acb-aiocb_type);
+if (ret  0) {
+error_report(add_aio_request is failed);
+free_aio_req(s, aio_req);
+qemu_aio_release(acb);
 return ret;
 }
 
-if (rsp-result == SD_RES_INVALID_PARMS) {
-dprintf(disable write cache since the server doesn't support it\n);
-
-s-cache_flags = SD_FLAG_CMD_DIRECT;
-closesocket(s-flush_fd);
-return 0;
-}
-
-if (rsp-result != SD_RES_SUCCESS) {
-error_report(%s, sd_strerror(rsp-result));
-return -EIO;
-}
-
-return 0;
+qemu_coroutine_yield();
+return acb-ret;
 }
 
 static int sd_snapshot_create(BlockDriverState *bs, QEMUSnapshotInfo *sn_info)
-- 
1.7.9.5




[Qemu-devel] [PATCH 2/2] sheepdog: clean up sd_aio_setup()

2013-01-13 Thread Liu Yuan
From: Liu Yuan tailai...@taobao.com

The last two parameters of sd_aio_setup() are never used, so remove them.

Cc: MORITA Kazutaka morita.kazut...@lab.ntt.co.jp
Cc: Kevin Wolf kw...@redhat.com
Cc: Stefan Hajnoczi stefa...@redhat.com
Signed-off-by: Liu Yuan tailai...@taobao.com
---
 block/sheepdog.c |   11 +--
 1 file changed, 5 insertions(+), 6 deletions(-)

diff --git a/block/sheepdog.c b/block/sheepdog.c
index 4e38670..db33f58 100644
--- a/block/sheepdog.c
+++ b/block/sheepdog.c
@@ -427,12 +427,11 @@ static const AIOCBInfo sd_aiocb_info = {
 };
 
 static SheepdogAIOCB *sd_aio_setup(BlockDriverState *bs, QEMUIOVector *qiov,
-   int64_t sector_num, int nb_sectors,
-   BlockDriverCompletionFunc *cb, void *opaque)
+   int64_t sector_num, int nb_sectors)
 {
 SheepdogAIOCB *acb;
 
-acb = qemu_aio_get(sd_aiocb_info, bs, cb, opaque);
+acb = qemu_aio_get(sd_aiocb_info, bs, NULL, NULL);
 
 acb-qiov = qiov;
 
@@ -1670,7 +1669,7 @@ static coroutine_fn int sd_co_writev(BlockDriverState 
*bs, int64_t sector_num,
 bs-total_sectors = sector_num + nb_sectors;
 }
 
-acb = sd_aio_setup(bs, qiov, sector_num, nb_sectors, NULL, NULL);
+acb = sd_aio_setup(bs, qiov, sector_num, nb_sectors);
 acb-aio_done_func = sd_write_done;
 acb-aiocb_type = AIOCB_WRITE_UDATA;
 
@@ -1691,7 +1690,7 @@ static coroutine_fn int sd_co_readv(BlockDriverState *bs, 
int64_t sector_num,
 SheepdogAIOCB *acb;
 int ret;
 
-acb = sd_aio_setup(bs, qiov, sector_num, nb_sectors, NULL, NULL);
+acb = sd_aio_setup(bs, qiov, sector_num, nb_sectors);
 acb-aiocb_type = AIOCB_READ_UDATA;
 acb-aio_done_func = sd_finish_aiocb;
 
@@ -1717,7 +1716,7 @@ static int coroutine_fn 
sd_co_flush_to_disk(BlockDriverState *bs)
 return 0;
 }
 
-acb = sd_aio_setup(bs, NULL, 0, 0, NULL, NULL);
+acb = sd_aio_setup(bs, NULL, 0, 0);
 acb-aiocb_type = AIOCB_FLUSH_CACHE;
 acb-aio_done_func = sd_finish_aiocb;
 
-- 
1.7.9.5




[Qemu-devel] [PATCH V6 0/5] HMP: allow parsing for sub command

2013-01-13 Thread Wenchao Xia
  These patches enhance HMP to allow it parse 2nd level of commands, such
as info sub command list, which means foldered command with parameter is
possible now.

V2:
  Follow the way supposed by Markus, which make the infrastructure knows
there is possible a 2nd level of command exist, instead of a hack. In this
way extention of command folder level is easy.
  Moved function declaration and better doc according to comments.
  Removed the patch about info snapshots, which will goto another serial.
V3:
  Split out code moving patch.
V4:
  Removed change of qmp_find_cmd().
  Removed name change of monitor_parse_command().
v5:
  Eliminate 'info' in mhandler for that it have same format with 'cmd' and info
is not a special case but a sub-command now.
  Split out patch that checking for space before check for sub-command.
  Better comments for monitor_parse_command().
  Add parameter start for better error tips in sub-command case.
  Add comments about how sub_table and mhandler interact.
  Better commit message and tips that info unknowns show error now.
v6:
  Filter out space before checking of sub command in montior_parse_command(),
and discard *p1 in it.
  Merged patch filter out space into infrastructure patch.

Wenchao Xia (5):
  HMP: add QDict to info callback handler
  HMP: delete info handler
  HMP: add infrastructure for sub command
  HMP: move define of mon_cmds
  HMP: add sub command table to info

 hmp-commands.hx |3 +-
 hmp.c   |   36 
 hmp.h   |   36 
 hw/i8259.c  |4 +-
 hw/lm32_pic.c   |4 +-
 hw/lm32_pic.h   |4 +-
 hw/loader.c |2 +-
 hw/loader.h |3 +-
 hw/pc.h |4 +-
 hw/pcmcia.h |2 +-
 hw/qdev-monitor.c   |4 +-
 hw/qdev-monitor.h   |4 +-
 hw/sun4m.c  |4 +-
 hw/sun4m.h  |4 +-
 hw/usb.h|2 +-
 hw/usb/bus.c|2 +-
 hw/usb/host-bsd.c   |2 +-
 hw/usb/host-linux.c |2 +-
 include/net/net.h   |2 +-
 include/net/slirp.h |2 +-
 include/sysemu/sysemu.h |4 +-
 monitor.c   |  200 --
 net/net.c   |2 +-
 net/slirp.c |2 +-
 savevm.c|2 +-
 vl.c|2 +-
 26 files changed, 174 insertions(+), 164 deletions(-)





[Qemu-devel] [PATCH V6 1/5] HMP: add QDict to info callback handler

2013-01-13 Thread Wenchao Xia
  This patch change all info call back function to take
additional QDict * parameter, which allow those command
take parameter. Now it is set to NULL at default case.

Signed-off-by: Wenchao Xia xiaw...@linux.vnet.ibm.com
---
 hmp.c   |   36 ++--
 hmp.h   |   36 ++--
 hw/i8259.c  |4 ++--
 hw/lm32_pic.c   |4 ++--
 hw/lm32_pic.h   |4 ++--
 hw/loader.c |2 +-
 hw/loader.h |3 ++-
 hw/pc.h |4 ++--
 hw/pcmcia.h |2 +-
 hw/qdev-monitor.c   |4 ++--
 hw/qdev-monitor.h   |4 ++--
 hw/sun4m.c  |4 ++--
 hw/sun4m.h  |4 ++--
 hw/usb.h|2 +-
 hw/usb/bus.c|2 +-
 hw/usb/host-bsd.c   |2 +-
 hw/usb/host-linux.c |2 +-
 include/net/net.h   |2 +-
 include/net/slirp.h |2 +-
 include/sysemu/sysemu.h |4 ++--
 monitor.c   |   32 
 net/net.c   |2 +-
 net/slirp.c |2 +-
 savevm.c|2 +-
 vl.c|2 +-
 25 files changed, 84 insertions(+), 83 deletions(-)

diff --git a/hmp.c b/hmp.c
index 9e9e624..2465d9b 100644
--- a/hmp.c
+++ b/hmp.c
@@ -31,7 +31,7 @@ static void hmp_handle_error(Monitor *mon, Error **errp)
 }
 }
 
-void hmp_info_name(Monitor *mon)
+void hmp_info_name(Monitor *mon, const QDict *qdict)
 {
 NameInfo *info;
 
@@ -42,7 +42,7 @@ void hmp_info_name(Monitor *mon)
 qapi_free_NameInfo(info);
 }
 
-void hmp_info_version(Monitor *mon)
+void hmp_info_version(Monitor *mon, const QDict *qdict)
 {
 VersionInfo *info;
 
@@ -55,7 +55,7 @@ void hmp_info_version(Monitor *mon)
 qapi_free_VersionInfo(info);
 }
 
-void hmp_info_kvm(Monitor *mon)
+void hmp_info_kvm(Monitor *mon, const QDict *qdict)
 {
 KvmInfo *info;
 
@@ -70,7 +70,7 @@ void hmp_info_kvm(Monitor *mon)
 qapi_free_KvmInfo(info);
 }
 
-void hmp_info_status(Monitor *mon)
+void hmp_info_status(Monitor *mon, const QDict *qdict)
 {
 StatusInfo *info;
 
@@ -89,7 +89,7 @@ void hmp_info_status(Monitor *mon)
 qapi_free_StatusInfo(info);
 }
 
-void hmp_info_uuid(Monitor *mon)
+void hmp_info_uuid(Monitor *mon, const QDict *qdict)
 {
 UuidInfo *info;
 
@@ -98,7 +98,7 @@ void hmp_info_uuid(Monitor *mon)
 qapi_free_UuidInfo(info);
 }
 
-void hmp_info_chardev(Monitor *mon)
+void hmp_info_chardev(Monitor *mon, const QDict *qdict)
 {
 ChardevInfoList *char_info, *info;
 
@@ -111,7 +111,7 @@ void hmp_info_chardev(Monitor *mon)
 qapi_free_ChardevInfoList(char_info);
 }
 
-void hmp_info_mice(Monitor *mon)
+void hmp_info_mice(Monitor *mon, const QDict *qdict)
 {
 MouseInfoList *mice_list, *mouse;
 
@@ -131,7 +131,7 @@ void hmp_info_mice(Monitor *mon)
 qapi_free_MouseInfoList(mice_list);
 }
 
-void hmp_info_migrate(Monitor *mon)
+void hmp_info_migrate(Monitor *mon, const QDict *qdict)
 {
 MigrationInfo *info;
 MigrationCapabilityStatusList *caps, *cap;
@@ -209,7 +209,7 @@ void hmp_info_migrate(Monitor *mon)
 qapi_free_MigrationCapabilityStatusList(caps);
 }
 
-void hmp_info_migrate_capabilities(Monitor *mon)
+void hmp_info_migrate_capabilities(Monitor *mon, const QDict *qdict)
 {
 MigrationCapabilityStatusList *caps, *cap;
 
@@ -228,13 +228,13 @@ void hmp_info_migrate_capabilities(Monitor *mon)
 qapi_free_MigrationCapabilityStatusList(caps);
 }
 
-void hmp_info_migrate_cache_size(Monitor *mon)
+void hmp_info_migrate_cache_size(Monitor *mon, const QDict *qdict)
 {
 monitor_printf(mon, xbzrel cache size: % PRId64  kbytes\n,
qmp_query_migrate_cache_size(NULL)  10);
 }
 
-void hmp_info_cpus(Monitor *mon)
+void hmp_info_cpus(Monitor *mon, const QDict *qdict)
 {
 CpuInfoList *cpu_list, *cpu;
 
@@ -272,7 +272,7 @@ void hmp_info_cpus(Monitor *mon)
 qapi_free_CpuInfoList(cpu_list);
 }
 
-void hmp_info_block(Monitor *mon)
+void hmp_info_block(Monitor *mon, const QDict *qdict)
 {
 BlockInfoList *block_list, *info;
 
@@ -326,7 +326,7 @@ void hmp_info_block(Monitor *mon)
 qapi_free_BlockInfoList(block_list);
 }
 
-void hmp_info_blockstats(Monitor *mon)
+void hmp_info_blockstats(Monitor *mon, const QDict *qdict)
 {
 BlockStatsList *stats_list, *stats;
 
@@ -360,7 +360,7 @@ void hmp_info_blockstats(Monitor *mon)
 qapi_free_BlockStatsList(stats_list);
 }
 
-void hmp_info_vnc(Monitor *mon)
+void hmp_info_vnc(Monitor *mon, const QDict *qdict)
 {
 VncInfo *info;
 Error *err = NULL;
@@ -406,7 +406,7 @@ out:
 qapi_free_VncInfo(info);
 }
 
-void hmp_info_spice(Monitor *mon)
+void hmp_info_spice(Monitor *mon, const QDict *qdict)
 {
 SpiceChannelList *chan;
 SpiceInfo *info;
@@ -453,7 +453,7 @@ out:
 qapi_free_SpiceInfo(info);
 }
 
-void hmp_info_balloon(Monitor *mon)
+void hmp_info_balloon(Monitor *mon, const QDict *qdict)
 {
 BalloonInfo 

[Qemu-devel] [PATCH V6 4/5] HMP: move define of mon_cmds

2013-01-13 Thread Wenchao Xia
  Because mon_cmds may use info_cmds, so adjust the declare sequence
of them.

Signed-off-by: Wenchao Xia xiaw...@linux.vnet.ibm.com
---
 monitor.c |   12 ++--
 1 files changed, 6 insertions(+), 6 deletions(-)

diff --git a/monitor.c b/monitor.c
index 6f470bf..d3225c2 100644
--- a/monitor.c
+++ b/monitor.c
@@ -2425,12 +2425,6 @@ int monitor_handle_fd_param(Monitor *mon, const char 
*fdname)
 return fd;
 }
 
-/* mon_cmds and info_cmds would be sorted at runtime */
-static mon_cmd_t mon_cmds[] = {
-#include hmp-commands.h
-{ NULL, NULL, },
-};
-
 /* Please update hmp-commands.hx when adding or changing commands */
 static mon_cmd_t info_cmds[] = {
 {
@@ -2744,6 +2738,12 @@ static mon_cmd_t info_cmds[] = {
 },
 };
 
+/* mon_cmds and info_cmds would be sorted at runtime */
+static mon_cmd_t mon_cmds[] = {
+#include hmp-commands.h
+{ NULL, NULL, },
+};
+
 static const mon_cmd_t qmp_cmds[] = {
 #include qmp-commands-old.h
 { /* NULL */ },
-- 
1.7.1





[Qemu-devel] [PATCH V6 3/5] HMP: add infrastructure for sub command

2013-01-13 Thread Wenchao Xia
  This patch make parsing of hmp command aware of that it may
have sub command. Also discard simple encapsulation function
monitor_find_command(). For case @command , space after
@command is filtered out.

Signed-off-by: Wenchao Xia xiaw...@linux.vnet.ibm.com
---
 monitor.c |   49 +++--
 1 files changed, 39 insertions(+), 10 deletions(-)

diff --git a/monitor.c b/monitor.c
index 359f333..6f470bf 100644
--- a/monitor.c
+++ b/monitor.c
@@ -129,6 +129,11 @@ typedef struct mon_cmd_t {
   MonitorCompletion *cb, void *opaque);
 } mhandler;
 int flags;
+/* @sub_table is a list of 2nd level of commands. If it do not exist,
+ * mhandler should be used. If it exist, sub_table[?].mhandler should be
+ * used, and mhandler of 1st level plays the role of help function.
+ */
+struct mon_cmd_t *sub_table;
 } mon_cmd_t;
 
 /* file descriptors passed via SCM_RIGHTS */
@@ -3533,18 +3538,27 @@ static const mon_cmd_t *search_dispatch_table(const 
mon_cmd_t *disp_table,
 return NULL;
 }
 
-static const mon_cmd_t *monitor_find_command(const char *cmdname)
-{
-return search_dispatch_table(mon_cmds, cmdname);
-}
-
 static const mon_cmd_t *qmp_find_cmd(const char *cmdname)
 {
 return search_dispatch_table(qmp_cmds, cmdname);
 }
 
+/*
+ * Parse @cmdline according to command table @table.
+ * If @cmdline is blank, return NULL.
+ * If it can't be parsed, report to @mon, and return NULL.
+ * Else, insert command arguments into @qdict, and return the command.
+ * If sub-command table exist, and if @cmdline contains addtional string for
+ * sub-command, this function will try search sub-command table. if no
+ * addtional string for sub-command exist, this function will return the found
+ * one in @table.
+ * Do not assume the returned command points into @table!  It doesn't
+ * when the command is a sub-command.
+ */
 static const mon_cmd_t *monitor_parse_command(Monitor *mon,
   const char *cmdline,
+  int start,
+  mon_cmd_t *table,
   QDict *qdict)
 {
 const char *p, *typestr;
@@ -3555,20 +3569,35 @@ static const mon_cmd_t *monitor_parse_command(Monitor 
*mon,
 char *key;
 
 #ifdef DEBUG
-monitor_printf(mon, command='%s'\n, cmdline);
+monitor_printf(mon, command='%s', start='%d'\n, cmdline, start);
 #endif
 
 /* extract the command name */
-p = get_command_name(cmdline, cmdname, sizeof(cmdname));
+p = get_command_name(cmdline + start, cmdname, sizeof(cmdname));
 if (!p)
 return NULL;
 
-cmd = monitor_find_command(cmdname);
+cmd = search_dispatch_table(table, cmdname);
 if (!cmd) {
-monitor_printf(mon, unknown command: '%s'\n, cmdname);
+monitor_printf(mon, unknown command: '%.*s'\n,
+   (int)(p - cmdline), cmdline);
 return NULL;
 }
 
+/* filter out following useless space */
+while (qemu_isspace(*p)) {
+p++;
+}
+/* search sub command */
+if (cmd-sub_table != NULL) {
+/* check if user set additional command */
+if (*p == '\0') {
+return cmd;
+}
+return monitor_parse_command(mon, cmdline, p - cmdline,
+ cmd-sub_table, qdict);
+}
+
 /* parse the parameters */
 typestr = cmd-args_type;
 for(;;) {
@@ -3924,7 +3953,7 @@ static void handle_user_command(Monitor *mon, const char 
*cmdline)
 
 qdict = qdict_new();
 
-cmd = monitor_parse_command(mon, cmdline, qdict);
+cmd = monitor_parse_command(mon, cmdline, 0, mon_cmds, qdict);
 if (!cmd)
 goto out;
 
-- 
1.7.1





[Qemu-devel] [PATCH V6 2/5] HMP: delete info handler

2013-01-13 Thread Wenchao Xia
  Now cmd and info handler have same format, so delete info handler.

Signed-off-by: Wenchao Xia xiaw...@linux.vnet.ibm.com
---
 monitor.c |   91 ++---
 1 files changed, 45 insertions(+), 46 deletions(-)

diff --git a/monitor.c b/monitor.c
index c7b3014..359f333 100644
--- a/monitor.c
+++ b/monitor.c
@@ -123,7 +123,6 @@ typedef struct mon_cmd_t {
 const char *help;
 void (*user_print)(Monitor *mon, const QObject *data);
 union {
-void (*info)(Monitor *mon, const QDict *qdict);
 void (*cmd)(Monitor *mon, const QDict *qdict);
 int  (*cmd_new)(Monitor *mon, const QDict *params, QObject **ret_data);
 int  (*cmd_async)(Monitor *mon, const QDict *params,
@@ -824,7 +823,7 @@ static void do_info(Monitor *mon, const QDict *qdict)
 goto help;
 }
 
-cmd-mhandler.info(mon, NULL);
+cmd-mhandler.cmd(mon, NULL);
 return;
 
 help:
@@ -2434,63 +2433,63 @@ static mon_cmd_t info_cmds[] = {
 .args_type  = ,
 .params = ,
 .help   = show the version of QEMU,
-.mhandler.info = hmp_info_version,
+.mhandler.cmd = hmp_info_version,
 },
 {
 .name   = network,
 .args_type  = ,
 .params = ,
 .help   = show the network state,
-.mhandler.info = do_info_network,
+.mhandler.cmd = do_info_network,
 },
 {
 .name   = chardev,
 .args_type  = ,
 .params = ,
 .help   = show the character devices,
-.mhandler.info = hmp_info_chardev,
+.mhandler.cmd = hmp_info_chardev,
 },
 {
 .name   = block,
 .args_type  = ,
 .params = ,
 .help   = show the block devices,
-.mhandler.info = hmp_info_block,
+.mhandler.cmd = hmp_info_block,
 },
 {
 .name   = blockstats,
 .args_type  = ,
 .params = ,
 .help   = show block device statistics,
-.mhandler.info = hmp_info_blockstats,
+.mhandler.cmd = hmp_info_blockstats,
 },
 {
 .name   = block-jobs,
 .args_type  = ,
 .params = ,
 .help   = show progress of ongoing block device operations,
-.mhandler.info = hmp_info_block_jobs,
+.mhandler.cmd = hmp_info_block_jobs,
 },
 {
 .name   = registers,
 .args_type  = ,
 .params = ,
 .help   = show the cpu registers,
-.mhandler.info = do_info_registers,
+.mhandler.cmd = do_info_registers,
 },
 {
 .name   = cpus,
 .args_type  = ,
 .params = ,
 .help   = show infos for each CPU,
-.mhandler.info = hmp_info_cpus,
+.mhandler.cmd = hmp_info_cpus,
 },
 {
 .name   = history,
 .args_type  = ,
 .params = ,
 .help   = show the command line history,
-.mhandler.info = do_info_history,
+.mhandler.cmd = do_info_history,
 },
 #if defined(TARGET_I386) || defined(TARGET_PPC) || defined(TARGET_MIPS) || \
 defined(TARGET_LM32) || (defined(TARGET_SPARC)  !defined(TARGET_SPARC64))
@@ -2500,11 +2499,11 @@ static mon_cmd_t info_cmds[] = {
 .params = ,
 .help   = show the interrupts statistics (if available),
 #ifdef TARGET_SPARC
-.mhandler.info = sun4m_irq_info,
+.mhandler.cmd = sun4m_irq_info,
 #elif defined(TARGET_LM32)
-.mhandler.info = lm32_irq_info,
+.mhandler.cmd = lm32_irq_info,
 #else
-.mhandler.info = irq_info,
+.mhandler.cmd = irq_info,
 #endif
 },
 {
@@ -2513,11 +2512,11 @@ static mon_cmd_t info_cmds[] = {
 .params = ,
 .help   = show i8259 (PIC) state,
 #ifdef TARGET_SPARC
-.mhandler.info = sun4m_pic_info,
+.mhandler.cmd = sun4m_pic_info,
 #elif defined(TARGET_LM32)
-.mhandler.info = lm32_do_pic_info,
+.mhandler.cmd = lm32_do_pic_info,
 #else
-.mhandler.info = pic_info,
+.mhandler.cmd = pic_info,
 #endif
 },
 #endif
@@ -2526,7 +2525,7 @@ static mon_cmd_t info_cmds[] = {
 .args_type  = ,
 .params = ,
 .help   = show PCI info,
-.mhandler.info = hmp_info_pci,
+.mhandler.cmd = hmp_info_pci,
 },
 #if defined(TARGET_I386) || defined(TARGET_SH4) || defined(TARGET_SPARC) || \
 defined(TARGET_PPC) || defined(TARGET_XTENSA)
@@ -2535,7 +2534,7 @@ static mon_cmd_t info_cmds[] = {
 .args_type  = ,
 .params = ,
 .help   = show virtual to physical memory mappings,
-.mhandler.info = tlb_info,
+.mhandler.cmd = tlb_info,
 },
 #endif
 #if defined(TARGET_I386)
@@ -2544,7 +2543,7 @@ static mon_cmd_t info_cmds[] = {
 .args_type  = ,
 .params = ,
 .help   = show the active virtual memory mappings,
-

[Qemu-devel] [PATCH V6 5/5] HMP: add sub command table to info

2013-01-13 Thread Wenchao Xia
  Now info command takes a table of sub info commands,
and changed do_info() to do_info_help() to do help funtion
only.
 Note that now info unknown-topic returns error instead
of list of info topics.

Signed-off-by: Wenchao Xia xiaw...@linux.vnet.ibm.com
---
 hmp-commands.hx |3 ++-
 monitor.c   |   22 +-
 2 files changed, 3 insertions(+), 22 deletions(-)

diff --git a/hmp-commands.hx b/hmp-commands.hx
index 010b8c9..87a411a 100644
--- a/hmp-commands.hx
+++ b/hmp-commands.hx
@@ -1489,7 +1489,8 @@ ETEXI
 .args_type  = item:s?,
 .params = [subcommand],
 .help   = show various information about the system state,
-.mhandler.cmd = do_info,
+.mhandler.cmd = do_info_help,
+.sub_table = info_cmds,
 },
 
 STEXI
diff --git a/monitor.c b/monitor.c
index d3225c2..99e5ba1 100644
--- a/monitor.c
+++ b/monitor.c
@@ -810,28 +810,8 @@ static void user_async_cmd_handler(Monitor *mon, const 
mon_cmd_t *cmd,
 }
 }
 
-static void do_info(Monitor *mon, const QDict *qdict)
+static void do_info_help(Monitor *mon, const QDict *qdict)
 {
-const mon_cmd_t *cmd;
-const char *item = qdict_get_try_str(qdict, item);
-
-if (!item) {
-goto help;
-}
-
-for (cmd = info_cmds; cmd-name != NULL; cmd++) {
-if (compare_cmd(item, cmd-name))
-break;
-}
-
-if (cmd-name == NULL) {
-goto help;
-}
-
-cmd-mhandler.cmd(mon, NULL);
-return;
-
-help:
 help_cmd(mon, info);
 }
 
-- 
1.7.1





[Qemu-devel] [PATCH V3 01/11] qemu-img: remove unused parameter in collect_image_info()

2013-01-13 Thread Wenchao Xia
  Parameter *fmt was not used, so remove it.

Reviewed-by: Eric Blake ebl...@redhat.com
Signed-off-by: Wenchao Xia xiaw...@linux.vnet.ibm.com
---
 qemu-img.c |5 ++---
 1 files changed, 2 insertions(+), 3 deletions(-)

diff --git a/qemu-img.c b/qemu-img.c
index 85d3740..9dab48f 100644
--- a/qemu-img.c
+++ b/qemu-img.c
@@ -1186,8 +1186,7 @@ static void dump_json_image_info(ImageInfo *info)
 
 static void collect_image_info(BlockDriverState *bs,
ImageInfo *info,
-   const char *filename,
-   const char *fmt)
+   const char *filename)
 {
 uint64_t total_sectors;
 char backing_filename[1024];
@@ -1361,7 +1360,7 @@ static ImageInfoList *collect_image_info_list(const char 
*filename,
 }
 
 info = g_new0(ImageInfo, 1);
-collect_image_info(bs, info, filename, fmt);
+collect_image_info(bs, info, filename);
 collect_snapshots(bs, info);
 
 elem = g_new0(ImageInfoList, 1);
-- 
1.7.1





[Qemu-devel] [PATCH V3 08/11] qmp: add interface query-snapshots

2013-01-13 Thread Wenchao Xia
  This interface now return valid internal snapshots.

Signed-off-by: Wenchao Xia xiaw...@linux.vnet.ibm.com
---
 block.c  |   32 
 qapi-schema.json |   13 +
 qmp-commands.hx  |   53 +
 3 files changed, 98 insertions(+), 0 deletions(-)

diff --git a/block.c b/block.c
index b7d2f03..990a07f 100644
--- a/block.c
+++ b/block.c
@@ -2892,6 +2892,38 @@ SnapshotInfoList 
*bdrv_query_snapshot_infolist(BlockDriverState *bs,
 return head;
 }
 
+/* check if sn exist on all block devices, 0 means valid */
+static int snapshot_filter_vm(const QEMUSnapshotInfo *sn, void *opaque)
+{
+BlockDriverState *bs = (BlockDriverState *)opaque, *bs1 = NULL;
+QEMUSnapshotInfo s, *sn_info = s;
+int ret = 0;
+
+while ((bs1 = bdrv_next(bs1))) {
+if (bdrv_can_snapshot(bs1)  bs1 != bs) {
+ret = bdrv_snapshot_find(bs1, sn_info, sn-id_str);
+if (ret  0) {
+ret = -1;
+break;
+}
+}
+}
+return ret;
+}
+
+SnapshotInfoList *qmp_query_snapshots(Error **errp)
+{
+BlockDriverState *bs;
+
+bs = bdrv_snapshots();
+if (!bs) {
+error_setg(errp, No available block device supports snapshots\n);
+return NULL;
+}
+
+return bdrv_query_snapshot_infolist(bs, snapshot_filter_vm, bs, errp);
+}
+
 /* collect all internal snapshot info in a image for ImageInfo */
 static void collect_snapshots_info(BlockDriverState *bs,
ImageInfo *info,
diff --git a/qapi-schema.json b/qapi-schema.json
index 565737c..012da03 100644
--- a/qapi-schema.json
+++ b/qapi-schema.json
@@ -747,6 +747,19 @@
 { 'command': 'query-images', 'returns': ['DeviceImageInfo'] }
 
 ##
+# @query-snapshots:
+#
+# Get a list of valid snapshots of virtual machine. Note that only valid
+# internal snapshot will be returned, inconsistent ones will not be returned.
+#
+# Returns: a list of @SnapshotInfo describing all consistent virtual machine
+#  snapshots.
+#
+# Since: 1.4
+##
+{ 'command': 'query-snapshots', 'returns': ['SnapshotInfo'] }
+
+##
 # @BlockDeviceStats:
 #
 # Statistics of a virtual block device or a block backing device.
diff --git a/qmp-commands.hx b/qmp-commands.hx
index c31a142..ab8e869 100644
--- a/qmp-commands.hx
+++ b/qmp-commands.hx
@@ -1744,6 +1744,59 @@ EQMP
 },
 
 SQMP
+query-snapshots
+---
+
+Show the internal consistent snapshot information.
+
+Each snapshot information is stored in a json-object and the returned value
+is a json-array of all snapshots.
+
+Each json-object contain the following:
+
+- id: unique snapshot id (json-string)
+- name: internal snapshot name (json-string)
+- vm-state-size: size of the VM state in bytes (json-int)
+- date-sec: UTC date of the snapshot in seconds (json-int)
+- date-nsec: fractional part in nano seconds to be used with 
date-sec(json-int)
+- vm-clock-sec: VM clock relative to boot in seconds (json-int)
+- vm-clock-nsec: fractional part in nano seconds to be used with 
vm-clock-sec (json-int)
+
+Example:
+
+- { execute: query-snapshots }
+- {
+  return:[
+ {
+id: 1,
+name: snapshot1,
+vm-state-size: 0,
+date-sec: 1200,
+date-nsec: 12,
+vm-clock-sec: 206,
+vm-clock-nsec: 30
+ },
+ {
+id: 2,
+name: snapshot2,
+vm-state-size: 3400,
+date-sec: 13000200,
+date-nsec: 32,
+vm-clock-sec: 406,
+vm-clock-nsec: 31
+ }
+  ]
+   }
+
+EQMP
+
+{
+.name   = query-snapshots,
+.args_type  = ,
+.mhandler.cmd_new = qmp_marshal_input_query_snapshots,
+},
+
+SQMP
 query-blockstats
 
 
-- 
1.7.1





[Qemu-devel] [PATCH V3 06/11] qmp: add interface query-images.

2013-01-13 Thread Wenchao Xia
  This mirror function will return all image info including
snapshots. Now Qemu have both query-images and query-block
interfaces.

Signed-off-by: Wenchao Xia xiaw...@linux.vnet.ibm.com
---
 block.c  |   19 +
 qapi-schema.json |   27 +++
 qmp-commands.hx  |   76 ++
 3 files changed, 122 insertions(+), 0 deletions(-)

diff --git a/block.c b/block.c
index 502c06e..8192d8e 100644
--- a/block.c
+++ b/block.c
@@ -2963,6 +2963,25 @@ ImageInfo *bdrv_query_image_info(BlockDriverState *bs, 
Error **errp)
 return info;
 }
 
+DeviceImageInfoList *qmp_query_images(Error **errp)
+{
+DeviceImageInfoList *head = NULL, **p_next = head;
+BlockDriverState *bs;
+
+QTAILQ_FOREACH(bs, bdrv_states, list) {
+DeviceImageInfo *dii = g_malloc0(sizeof(*dii));
+dii-device = g_strdup(bs-device_name);
+dii-info = bdrv_query_image_info(bs, NULL);
+DeviceImageInfoList *diil = g_malloc0(sizeof(*diil));
+diil-value = dii;
+
+*p_next = diil;
+p_next = diil-next;
+}
+
+return head;
+}
+
 BlockInfo *bdrv_query_block_info(BlockDriverState *bs)
 {
 BlockInfo *info = g_malloc0(sizeof(*info));
diff --git a/qapi-schema.json b/qapi-schema.json
index 5dfa052..565737c 100644
--- a/qapi-schema.json
+++ b/qapi-schema.json
@@ -245,6 +245,22 @@
'*backing-filename-format': 'str', '*snapshots': ['SnapshotInfo'] } 
}
 
 ##
+# @DeviceImageInfo:
+#
+# Information about an image used by QEMU block device
+#
+# @device: name of the block device
+#
+# @info: info of the image used.
+#
+# Since: 1.4
+#
+##
+
+{ 'type': 'DeviceImageInfo',
+  'data': {'device': 'str', 'info': 'ImageInfo' } }
+
+##
 # @StatusInfo:
 #
 # Information about VCPU run state
@@ -720,6 +736,17 @@
 { 'command': 'query-block', 'returns': ['BlockInfo'] }
 
 ##
+# @query-images:
+#
+# Get a list of DeviceImageInfo for all virtual block devices.
+#
+# Returns: a list of @DeviceImageInfo describing each virtual block device
+#
+# Since: 1.4
+##
+{ 'command': 'query-images', 'returns': ['DeviceImageInfo'] }
+
+##
 # @BlockDeviceStats:
 #
 # Statistics of a virtual block device or a block backing device.
diff --git a/qmp-commands.hx b/qmp-commands.hx
index 5c692d0..c31a142 100644
--- a/qmp-commands.hx
+++ b/qmp-commands.hx
@@ -1668,6 +1668,82 @@ EQMP
 },
 
 SQMP
+query-images
+---
+
+Show the block devices' images.
+
+Each block image information is stored in a json-object and the returned value
+is a json-array of all devices' images.
+
+Each json-object contain the following:
+
+- device: device name (json-string)
+- info: related image information, it is a json-object containing the 
following:
+ - filename: image file name (json-string)
+ - format: image format (json-string)
+ - virtual-size: maximum capacity in bytes of the image (json-int)
+ - dirty-flag: true if image is not cleanly closed (json-bool, 
optional)
+ - actual-size: actual size on disk in bytes of the image (json-int, 
optional)
+ - cluster-size: size of a cluster in bytes (json-int, optional)
+ - encrypted: true if the image is encrypted (json-bool, optional)
+ - backing_file: backing file name (json-string, optional)
+ - full-backing-filename: full path of the backing file 
(json-string, optional)
+ - backing-filename-format: the format of the backing file 
(json-string, optional)
+ - snapshots: the internal snapshot info, it is an optional list of 
json-object
+containing the following:
+ - id: unique snapshot id (json-string)
+ - name: internal snapshot name (json-string)
+ - vm-state-size: size of the VM state in bytes (json-int)
+ - date-sec: UTC date of the snapshot in seconds (json-int)
+ - date-nsec: fractional part in nano seconds to be used with 
date-sec(json-int)
+ - vm-clock-sec: VM clock relative to boot in seconds (json-int)
+ - vm-clock-nsec: fractional part in nano seconds to be used 
with vm-clock-sec (json-int)
+
+Example:
+
+- { execute: query-images }
+- {
+  return:[
+ {
+device:ide0-hd0,
+info:{
+   filename:disks/test0.img,
+   format:qcow2,
+   virtual-size:1024000
+}
+ },
+ {
+device:ide0-hd1,
+info:{
+   filename:disks/test1.img,
+   format:qcow2,
+   virtual-size:2048000,
+   snapshots:[
+  {
+ id: 1,
+ name: snapshot1,
+ vm-state-size: 0,
+ date-sec: 1200,
+ date-nsec: 12,
+ vm-clock-sec: 206,
+ vm-clock-nsec: 30
+  }
+   ]
+}
+ }
+  ]
+   }
+

[Qemu-devel] [PATCH V3 09/11] hmp: export function hmp_handle_error()

2013-01-13 Thread Wenchao Xia
Signed-off-by: Wenchao Xia xiaw...@linux.vnet.ibm.com
---
 hmp.c |2 +-
 hmp.h |2 ++
 2 files changed, 3 insertions(+), 1 deletions(-)

diff --git a/hmp.c b/hmp.c
index 2465d9b..89a1a8c 100644
--- a/hmp.c
+++ b/hmp.c
@@ -23,7 +23,7 @@
 #include monitor/monitor.h
 #include ui/console.h
 
-static void hmp_handle_error(Monitor *mon, Error **errp)
+void hmp_handle_error(Monitor *mon, Error **errp)
 {
 if (error_is_set(errp)) {
 monitor_printf(mon, %s\n, error_get_pretty(*errp));
diff --git a/hmp.h b/hmp.h
index 5cab9c0..da1a35c 100644
--- a/hmp.h
+++ b/hmp.h
@@ -17,7 +17,9 @@
 #include qemu-common.h
 #include qapi-types.h
 #include qapi/qmp/qdict.h
+#include qapi/error.h
 
+void hmp_handle_error(Monitor *mon, Error **errp);
 void hmp_info_name(Monitor *mon, const QDict *qdict);
 void hmp_info_version(Monitor *mon, const QDict *qdict);
 void hmp_info_kvm(Monitor *mon, const QDict *qdict);
-- 
1.7.1





[Qemu-devel] [PATCH V3 11/11] hmp: show snapshot on single block device

2013-01-13 Thread Wenchao Xia
  This patch use block layer API to qmp snapshot info on a block
device, then use the same code dumping vm snapshot info, to print
in monitor.

Signed-off-by: Wenchao Xia xiaw...@linux.vnet.ibm.com
---
Note:
  This patch need previous hmp extention patch which enable
info sub command take qdict * as paramter.

---
 monitor.c |6 +++---
 savevm.c  |   43 ++-
 2 files changed, 45 insertions(+), 4 deletions(-)

diff --git a/monitor.c b/monitor.c
index d186532..cba75a2 100644
--- a/monitor.c
+++ b/monitor.c
@@ -2583,9 +2583,9 @@ static mon_cmd_t info_cmds[] = {
 },
 {
 .name   = snapshots,
-.args_type  = ,
-.params = ,
-.help   = show the currently saved VM snapshots,
+.args_type  = device:B?,
+.params = [device],
+.help   = show snapshots of whole vm or a single device,
 .mhandler.cmd = do_info_snapshots,
 },
 {
diff --git a/savevm.c b/savevm.c
index cabdcb6..cd474e9 100644
--- a/savevm.c
+++ b/savevm.c
@@ -2354,9 +2354,50 @@ static void do_info_snapshots_vm(Monitor *mon)
 return;
 }
 
+static void do_info_snapshots_blk(Monitor *mon, const char *device)
+{
+Error *err = NULL;
+SnapshotInfoList *list;
+BlockDriverState *bs;
+
+/* find the target bs */
+bs = bdrv_find(device);
+if (!bs) {
+monitor_printf(mon, Device '%s' not found.\n, device);
+return ;
+}
+
+if (!bdrv_can_snapshot(bs)) {
+monitor_printf(mon, Device '%s' can't have snapshot.\n, device);
+return ;
+}
+
+list = bdrv_query_snapshot_infolist(bs, NULL, NULL, err);
+if (error_is_set(err)) {
+hmp_handle_error(mon, err);
+return;
+}
+
+if (list == NULL) {
+monitor_printf(mon, There is no snapshot available.\n);
+return;
+}
+
+monitor_printf(mon, Device '%s':\n, device);
+monitor_dump_snapshotinfolist(mon, list);
+qapi_free_SnapshotInfoList(list);
+return;
+}
+
 void do_info_snapshots(Monitor *mon, const QDict *qdict)
 {
-do_info_snapshots_vm(mon);
+const char *device = qdict_get_try_str(qdict, device);
+if (!device) {
+do_info_snapshots_vm(mon);
+} else {
+do_info_snapshots_blk(mon, device);
+}
+return;
 }
 
 void vmstate_register_ram(MemoryRegion *mr, DeviceState *dev)
-- 
1.7.1





[Qemu-devel] [PATCH V3 00/11] add qmp/hmp interfaces for snapshot info

2013-01-13 Thread Wenchao Xia
  This serial of patches does two things: merge some info code
in qemu-img, and add following interfaces:
1) qmp: query-images
2) qmp: query-snapshots
3) hmp: show snapshot info on a single block device
  These patches follows the rule that use qmp to retieve information,
hmp layer just do a translation from qmp object it got, so almost
every hmp interface may have a correlated qmp interface.
  To make code graceful, snapshot retrieving code in qemu and qemu-img
are merged into block.c, and some function name was adjusted to make it
tips better. Now it works as:

   qemu  qemu-img

dump_monitordump_stdout
 |--| 
|
   qmp
|
  block

Note:
  Last two patches need previous sent patches which extend hmp sub command, at:
http://lists.nongnu.org/archive/html/qemu-devel/2012-12/msg03487.html

v2:
  Rename and adjusted qmp interface according to comments from Eric.
  Spelling fix.
  Information retrieving function in block layer goes to seperated patch.
  Free qmp object after usage in hmp.
  Added counterpart in qmp-commands.hx.
  Better tips in qmp-schema.json.

v3:
  Spelling fix in commit message, patch 03/11.
  Spelling fix in code, patch 06/11.
  Add comments that vm-state-size is in bytes, and change size of it in
example to a reasonable number, patch 08/11.

Wenchao Xia (11):
  qemu-img: remove unused parameter in collect_image_info()
  block: add bdrv_get_filename() function
  block: add snapshot and image info query function
  qemu-img: switch image retrieving function
  block: rename bdrv_query_info to bdrv_query_block_info
  qmp: add interface query-images.
  block: export function bdrv_find_snapshot()
  qmp: add interface query-snapshots
  hmp: export function hmp_handle_error()
  hmp: retrieve info from qmp for snapshot info
  hmp: show snapshot on single block device

 block.c   |  200 -
 hmp.c |2 +-
 hmp.h |2 +
 include/block/block.h |   14 +++-
 monitor.c |6 +-
 qapi-schema.json  |   40 ++
 qemu-img.c|   87 +-
 qmp-commands.hx   |  129 +++
 savevm.c  |  137 +
 9 files changed, 458 insertions(+), 159 deletions(-)





[Qemu-devel] [PATCH V3 03/11] block: add snapshot and image info query function

2013-01-13 Thread Wenchao Xia
  This patch added function bdrv_query_image_info() and
bdrv_query_snapshot_infolist(), which will return info in qmp object
format. The implementation code are mostly copied from collect_image_info()
and collect_snapshot() in qemu-img.c.
  To help filter out snapshot info not needed, a call back function is
added in bdrv_query_snapshot_infolist().

Signed-off-by: Wenchao Xia xiaw...@linux.vnet.ibm.com
Reviewed-by: Eric Blake ebl...@redhat.com
---
 block.c   |  117 +
 include/block/block.h |9 
 2 files changed, 126 insertions(+), 0 deletions(-)

diff --git a/block.c b/block.c
index 5f95da5..81765a3 100644
--- a/block.c
+++ b/block.c
@@ -2846,6 +2846,123 @@ int coroutine_fn 
bdrv_co_is_allocated_above(BlockDriverState *top,
 return 0;
 }
 
+SnapshotInfoList *bdrv_query_snapshot_infolist(BlockDriverState *bs,
+   SnapshotFilterFunc filter,
+   void *opaque,
+   Error **errp)
+{
+int i, sn_count;
+QEMUSnapshotInfo *sn_tab = NULL;
+SnapshotInfoList *info_list, *cur_item = NULL, *head = NULL;
+sn_count = bdrv_snapshot_list(bs, sn_tab);
+if (sn_count  0) {
+if (errp != NULL) {
+error_setg(errp, bdrv_snapshot_list: error %d\n, sn_count);
+}
+return NULL;
+}
+
+for (i = 0; i  sn_count; i++) {
+if (filter  filter(sn_tab[i], opaque) != 0) {
+continue;
+}
+
+info_list = g_new0(SnapshotInfoList, 1);
+
+info_list-value= g_new0(SnapshotInfo, 1);
+info_list-value-id= g_strdup(sn_tab[i].id_str);
+info_list-value-name  = g_strdup(sn_tab[i].name);
+info_list-value-vm_state_size = sn_tab[i].vm_state_size;
+info_list-value-date_sec  = sn_tab[i].date_sec;
+info_list-value-date_nsec = sn_tab[i].date_nsec;
+info_list-value-vm_clock_sec  = sn_tab[i].vm_clock_nsec / 10;
+info_list-value-vm_clock_nsec = sn_tab[i].vm_clock_nsec % 10;
+
+/* XXX: waiting for the qapi to support qemu-queue.h types */
+if (!cur_item) {
+head = cur_item = info_list;
+} else {
+cur_item-next = info_list;
+cur_item = info_list;
+}
+
+}
+
+g_free(sn_tab);
+return head;
+}
+
+/* collect all internal snapshot info in a image for ImageInfo */
+static void collect_snapshots_info(BlockDriverState *bs,
+   ImageInfo *info,
+   Error **errp)
+{
+SnapshotInfoList *info_list;
+
+info_list = bdrv_query_snapshot_infolist(bs, NULL, NULL, errp);
+if (info_list != NULL) {
+info-has_snapshots = true;
+info-snapshots = info_list;
+}
+return;
+}
+
+static void collect_image_info(BlockDriverState *bs,
+   ImageInfo *info)
+{
+uint64_t total_sectors;
+char backing_filename[1024];
+char backing_filename2[1024];
+BlockDriverInfo bdi;
+const char *filename;
+
+filename = bdrv_get_filename(bs);
+bdrv_get_geometry(bs, total_sectors);
+
+info-filename= g_strdup(filename);
+info-format  = g_strdup(bdrv_get_format_name(bs));
+info-virtual_size= total_sectors * 512;
+info-actual_size = bdrv_get_allocated_file_size(bs);
+info-has_actual_size = info-actual_size = 0;
+if (bdrv_is_encrypted(bs)) {
+info-encrypted = true;
+info-has_encrypted = true;
+}
+if (bdrv_get_info(bs, bdi) = 0) {
+if (bdi.cluster_size != 0) {
+info-cluster_size = bdi.cluster_size;
+info-has_cluster_size = true;
+}
+info-dirty_flag = bdi.is_dirty;
+info-has_dirty_flag = true;
+}
+bdrv_get_backing_filename(bs, backing_filename, sizeof(backing_filename));
+if (backing_filename[0] != '\0') {
+info-backing_filename = g_strdup(backing_filename);
+info-has_backing_filename = true;
+bdrv_get_full_backing_filename(bs, backing_filename2,
+   sizeof(backing_filename2));
+
+if (strcmp(backing_filename, backing_filename2) != 0) {
+info-full_backing_filename = g_strdup(backing_filename2);
+info-has_full_backing_filename = true;
+}
+
+if (bs-backing_format[0]) {
+info-backing_filename_format = g_strdup(bs-backing_format);
+info-has_backing_filename_format = true;
+}
+}
+}
+
+ImageInfo *bdrv_query_image_info(BlockDriverState *bs, Error **errp)
+{
+ImageInfo *info = g_new0(ImageInfo, 1);
+collect_image_info(bs, info);
+collect_snapshots_info(bs, info, errp);
+return info;
+}
+
 BlockInfo *bdrv_query_info(BlockDriverState *bs)
 {
 BlockInfo *info = g_malloc0(sizeof(*info));
diff 

[Qemu-devel] [PATCH V3 02/11] block: add bdrv_get_filename() function

2013-01-13 Thread Wenchao Xia
  This function will simply return the uri or filename used
to open the image.

Reviewed-by: Eric Blake ebl...@redhat.com
Signed-off-by: Wenchao Xia xiaw...@linux.vnet.ibm.com
---
 block.c   |5 +
 include/block/block.h |1 +
 2 files changed, 6 insertions(+), 0 deletions(-)

diff --git a/block.c b/block.c
index 4e28c55..5f95da5 100644
--- a/block.c
+++ b/block.c
@@ -2967,6 +2967,11 @@ BlockStatsList *qmp_query_blockstats(Error **errp)
 return head;
 }
 
+const char *bdrv_get_filename(BlockDriverState *bs)
+{
+return bs-filename;
+}
+
 const char *bdrv_get_encrypted_filename(BlockDriverState *bs)
 {
 if (bs-backing_hd  bs-backing_hd-encrypted)
diff --git a/include/block/block.h b/include/block/block.h
index 0719339..a0fc2a6 100644
--- a/include/block/block.h
+++ b/include/block/block.h
@@ -310,6 +310,7 @@ int bdrv_write_compressed(BlockDriverState *bs, int64_t 
sector_num,
   const uint8_t *buf, int nb_sectors);
 int bdrv_get_info(BlockDriverState *bs, BlockDriverInfo *bdi);
 
+const char *bdrv_get_filename(BlockDriverState *bs);
 const char *bdrv_get_encrypted_filename(BlockDriverState *bs);
 void bdrv_get_backing_filename(BlockDriverState *bs,
char *filename, int filename_size);
-- 
1.7.1





[Qemu-devel] [PATCH V3 05/11] block: rename bdrv_query_info to bdrv_query_block_info

2013-01-13 Thread Wenchao Xia
  Now that we have bdrv_query_image_info, rename this function to make it
more obvious what it is doing.

Reviewed-by: Eric Blake ebl...@redhat.com
Signed-off-by: Wenchao Xia xiaw...@linux.vnet.ibm.com
---
 block.c   |4 ++--
 include/block/block.h |2 +-
 2 files changed, 3 insertions(+), 3 deletions(-)

diff --git a/block.c b/block.c
index 81765a3..502c06e 100644
--- a/block.c
+++ b/block.c
@@ -2963,7 +2963,7 @@ ImageInfo *bdrv_query_image_info(BlockDriverState *bs, 
Error **errp)
 return info;
 }
 
-BlockInfo *bdrv_query_info(BlockDriverState *bs)
+BlockInfo *bdrv_query_block_info(BlockDriverState *bs)
 {
 BlockInfo *info = g_malloc0(sizeof(*info));
 info-device = g_strdup(bs-device_name);
@@ -3029,7 +3029,7 @@ BlockInfoList *qmp_query_block(Error **errp)
 
 QTAILQ_FOREACH(bs, bdrv_states, list) {
 BlockInfoList *info = g_malloc0(sizeof(*info));
-info-value = bdrv_query_info(bs);
+info-value = bdrv_query_block_info(bs);
 
 *p_next = info;
 p_next = info-next;
diff --git a/include/block/block.h b/include/block/block.h
index 67f0d13..5ce817a 100644
--- a/include/block/block.h
+++ b/include/block/block.h
@@ -324,7 +324,7 @@ SnapshotInfoList 
*bdrv_query_snapshot_infolist(BlockDriverState *bs,
void *opaque,
Error **errp);
 ImageInfo *bdrv_query_image_info(BlockDriverState *bs, Error **errp);
-BlockInfo *bdrv_query_info(BlockDriverState *s);
+BlockInfo *bdrv_query_block_info(BlockDriverState *bs);
 BlockStats *bdrv_query_stats(const BlockDriverState *bs);
 
 int bdrv_can_snapshot(BlockDriverState *bs);
-- 
1.7.1





[Qemu-devel] [PATCH V3 10/11] hmp: retrieve info from qmp for snapshot info

2013-01-13 Thread Wenchao Xia
  With this patch, hmp command info snapshot simply call a block
layer funtion which will return a qmp object, and then translate
it in monitor console. Now snapshot info retrieving code in qemu
and qemu-tool are merged by calling same block layer function,
and then they just translate the qmp to stdout or monitor.

Signed-off-by: Wenchao Xia xiaw...@linux.vnet.ibm.com

---
Note:
  This patch need previous hmp extention patch which enable
info sub command take qdict * as paramter.
---
 savevm.c |   84 +-
 1 files changed, 34 insertions(+), 50 deletions(-)

diff --git a/savevm.c b/savevm.c
index 9af2605..cabdcb6 100644
--- a/savevm.c
+++ b/savevm.c
@@ -48,6 +48,7 @@
 #include qmp-commands.h
 #include trace.h
 #include qemu/bitops.h
+#include hmp.h
 
 #define SELF_ANNOUNCE_ROUNDS 5
 
@@ -2311,68 +2312,51 @@ void do_delvm(Monitor *mon, const QDict *qdict)
 }
 }
 
-void do_info_snapshots(Monitor *mon, const QDict *qdict)
+/* assume list is valid */
+static void monitor_dump_snapshotinfolist(Monitor *mon, SnapshotInfoList *list)
 {
-BlockDriverState *bs, *bs1;
-QEMUSnapshotInfo *sn_tab, *sn, s, *sn_info = s;
-int nb_sns, i, ret, available;
-int total;
-int *available_snapshots;
+SnapshotInfoList *elem;
 char buf[256];
 
-bs = bdrv_snapshots();
-if (!bs) {
-monitor_printf(mon, No available block device supports snapshots\n);
-return;
-}
-
-nb_sns = bdrv_snapshot_list(bs, sn_tab);
-if (nb_sns  0) {
-monitor_printf(mon, bdrv_snapshot_list: error %d\n, nb_sns);
-return;
-}
+monitor_printf(mon, %s\n, bdrv_snapshot_dump(buf, sizeof(buf), NULL));
 
-if (nb_sns == 0) {
-monitor_printf(mon, There is no snapshot available.\n);
-return;
+for (elem = list; elem; elem = elem-next) {
+QEMUSnapshotInfo sn = {
+.vm_state_size = elem-value-vm_state_size,
+.date_sec = elem-value-date_sec,
+.date_nsec = elem-value-date_nsec,
+.vm_clock_nsec = elem-value-vm_clock_sec * 10ULL +
+ elem-value-vm_clock_nsec,
+};
+pstrcpy(sn.id_str, sizeof(sn.id_str), elem-value-id);
+pstrcpy(sn.name, sizeof(sn.name), elem-value-name);
+monitor_printf(mon, %s\n, bdrv_snapshot_dump(buf, sizeof(buf), sn));
 }
+}
 
-available_snapshots = g_malloc0(sizeof(int) * nb_sns);
-total = 0;
-for (i = 0; i  nb_sns; i++) {
-sn = sn_tab[i];
-available = 1;
-bs1 = NULL;
-
-while ((bs1 = bdrv_next(bs1))) {
-if (bdrv_can_snapshot(bs1)  bs1 != bs) {
-ret = bdrv_snapshot_find(bs1, sn_info, sn-id_str);
-if (ret  0) {
-available = 0;
-break;
-}
-}
-}
+static void do_info_snapshots_vm(Monitor *mon)
+{
+Error *err = NULL;
+SnapshotInfoList *list;
 
-if (available) {
-available_snapshots[total] = i;
-total++;
-}
+list = qmp_query_snapshots(err);
+if (error_is_set(err)) {
+hmp_handle_error(mon, err);
+return;
 }
-
-if (total  0) {
-monitor_printf(mon, %s\n, bdrv_snapshot_dump(buf, sizeof(buf), 
NULL));
-for (i = 0; i  total; i++) {
-sn = sn_tab[available_snapshots[i]];
-monitor_printf(mon, %s\n, bdrv_snapshot_dump(buf, sizeof(buf), 
sn));
-}
-} else {
+if (list == NULL) {
 monitor_printf(mon, There is no suitable snapshot available\n);
+return;
 }
 
-g_free(sn_tab);
-g_free(available_snapshots);
+monitor_dump_snapshotinfolist(mon, list);
+qapi_free_SnapshotInfoList(list);
+return;
+}
 
+void do_info_snapshots(Monitor *mon, const QDict *qdict)
+{
+do_info_snapshots_vm(mon);
 }
 
 void vmstate_register_ram(MemoryRegion *mr, DeviceState *dev)
-- 
1.7.1