Re: [Qemu-devel] [RFC/PATCH] i386: Atomically update PTEs with mttcg

2018-12-13 Thread Richard Henderson
On 12/13/18 5:39 PM, Benjamin Herrenschmidt wrote:
> At this point I'd rather not take chances and introduce more bugs, so
> I'll post an updated variant with a few fixes but will postpone more
> refactoring unless you really really want them now :)

No, that's quite all right.  Thanks for the investigation.

r~



Re: [Qemu-devel] [PATCH v1 1/1] tcg: mips: Improve the add2/sub2 command to use TCG_TARGET_REG_BITS

2018-12-13 Thread Richard Henderson
On 12/12/18 2:58 PM, Alistair Francis wrote:
> Instead of hard coding 31 for the shift right use
> TCG_TARGET_REG_BITS - 1.
> 
> Signed-off-by: Alistair Francis 
> ---
>  tcg/mips/tcg-target.inc.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)

Queued.


r~



Re: [Qemu-devel] [RFC/PATCH] i386: Atomically update PTEs with mttcg

2018-12-13 Thread Benjamin Herrenschmidt
On Thu, 2018-11-29 at 11:04 -0800, Richard Henderson wrote:
> 
> While I know the existing code just updates the low 32-bits, I'd rather update
> the whole entry, and make use of the old value returned from the cmpxchg.

So I had to put this on the back burner for a bit, but I'm back to it
now.

I've tried the above but it gets messy again. The i386 code can have
either 32 or 64 bits PDE/PTEs. The udpate code for the PTE is designed
so a single code path can work with either by exploiting that LE trick,
so changing that would involve more re-factoring and I'd rather avoid
changing more than strictly needed in there.

As for this:

>pdpe = x86_ldq_phys(cs, pdpe_addr);
> do {
> if (!(pdpe & PG_PRESENT_MASK)) {
> goto do_fault;
> }
> if (pdpe & rsvd_mask) {
> goto do_fault_rsvd;
> }
> if (pdpe & PG_ACCESSED_MASK) {
> break;
> }
> } while (!update_entry(cs, pdpe_addr, , PG_ACCESSED_MASK));
> ptep &= pdpe ^ PG_NX_MASK;

While that form of construct is nicer than the current goto restart in
my patch, in a similar way, it works for the intermediary cases but
would require some serious refactoring of the whole function for the
final PTE case.

At this point I'd rather not take chances and introduce more bugs, so
I'll post an updated variant with a few fixes but will postpone more
refactoring unless you really really want them now :)

Cheers,
Ben.




Re: [Qemu-devel] [PATCH v2 4/8] qcow2-threads: split out generic path

2018-12-13 Thread Paolo Bonzini
On 11/12/18 17:43, Vladimir Sementsov-Ogievskiy wrote:
> +ThreadPool *pool = aio_get_thread_pool(bdrv_get_aio_context(bs));
> +
> +while (s->nb_threads >= QCOW2_MAX_THREADS) {
> +qemu_co_queue_wait(>thread_task_queue, NULL);
> +}
> +
> +s->nb_threads++;
> +ret = thread_pool_submit_co(pool, func, arg);
> +s->nb_threads--;
> +
> +qemu_co_queue_next(>thread_task_queue);

What lock is protecting this manipulation?  I'd rather avoid adding more
users of the AioContext lock, especially manipulation of CoQueues.

One possibility is to do the s->lock unlock/lock here, and then also
rely on that in patch 8.

Paolo



Re: [Qemu-devel] [PATCH v1 2/2] target/arm: defer setting up of aarch64 gdb until arm_cpu_realize

2018-12-13 Thread Richard Henderson
On 12/13/18 5:55 AM, Alex Bennée wrote:
> If we setup earlier we miss the parsing of the aarch64 state of the
> CPU. If the user has booted up with:
> 
>   qemu-system-aarch64 -cpu host,aarch64=off -enable-kvm
> 
> we end up presenting an aarch64 view of the world via the gdbstub and
> hilarity ensues.
> 
> Reported-by: Ard Biesheuvel 
> Signed-off-by: Alex Bennée 
> Cc: Omair Javaid 
> ---
>  include/hw/arm/arm.h |  2 ++
>  target/arm/cpu.c |  4 
>  target/arm/cpu64.c   | 20 +++-
>  3 files changed, 21 insertions(+), 5 deletions(-)

Reviewed-by: Richard Henderson 


r~



Re: [Qemu-devel] [PATCH 2/2] avoid TABs in files that only contain a few

2018-12-13 Thread Richard Henderson
On 12/13/18 4:37 PM, Paolo Bonzini wrote:
> Most files that have TABs only contain a handful of them.  Change
> them to spaces so that we don't confuse people.


Acked-by: Richard Henderson 


r~




Re: [Qemu-devel] [PATCH 1/2] remove space-tab sequences

2018-12-13 Thread Richard Henderson
On 12/13/18 4:37 PM, Paolo Bonzini wrote:
> There are not many, and they are all simple mistakes that ended up
> being committed.  Remove them.
> 
> Signed-off-by: Paolo Bonzini 

Acked-by: Richard Henderson 


r~



[Qemu-devel] [PATCH 1/2] remove space-tab sequences

2018-12-13 Thread Paolo Bonzini
There are not many, and they are all simple mistakes that ended up
being committed.  Remove them.

Signed-off-by: Paolo Bonzini 
---
 bsd-user/x86_64/target_syscall.h   |  2 +-
 crypto/aes.c   | 28 ++--
 disas/alpha.c  |  8 
 disas/arm.c|  2 +-
 disas/i386.c   |  4 ++--
 disas/m68k.c   |  4 ++--
 hw/usb/hcd-uhci.c  |  4 ++--
 include/hw/elf_ops.h   |  2 +-
 linux-user/linuxload.c |  2 +-
 linux-user/syscall.c   |  2 +-
 linux-user/syscall_defs.h  |  4 ++--
 linux-user/x86_64/target_syscall.h |  2 +-
 slirp/ip_input.c   |  4 ++--
 slirp/tcp_input.c  | 10 +-
 slirp/tcp_output.c |  4 ++--
 slirp/tcp_timer.c  |  2 +-
 slirp/udp.c|  2 +-
 tests/tcg/arm/hello-arm.c  | 10 +-
 18 files changed, 48 insertions(+), 48 deletions(-)

diff --git a/bsd-user/x86_64/target_syscall.h b/bsd-user/x86_64/target_syscall.h
index 211ce29e90..a5d779884f 100644
--- a/bsd-user/x86_64/target_syscall.h
+++ b/bsd-user/x86_64/target_syscall.h
@@ -12,7 +12,7 @@ struct target_pt_regs {
abi_ulong rbp;
abi_ulong rbx;
 /* arguments: non interrupts/non tracing syscalls only save up to here */
-   abi_ulong r11;
+   abi_ulong r11;
abi_ulong r10;
abi_ulong r9;
abi_ulong r8;
diff --git a/crypto/aes.c b/crypto/aes.c
index 3456eacd08..773d246b00 100644
--- a/crypto/aes.c
+++ b/crypto/aes.c
@@ -1071,7 +1071,7 @@ int AES_set_encrypt_key(const unsigned char *userKey, 
const int bits,
AES_KEY *key) {
 
u32 *rk;
-   int i = 0;
+   int i = 0;
u32 temp;
 
if (!userKey || !key)
@@ -1160,7 +1160,7 @@ int AES_set_encrypt_key(const unsigned char *userKey, 
const int bits,
rk[15] = rk[ 7] ^ rk[14];
 
rk += 8;
-   }
+   }
}
 abort();
 }
@@ -1247,7 +1247,7 @@ void AES_encrypt(const unsigned char *in, unsigned char 
*out,
 t1 = AES_Te0[s1 >> 24] ^ AES_Te1[(s2 >> 16) & 0xff] ^ AES_Te2[(s3 >>  
8) & 0xff] ^ AES_Te3[s0 & 0xff] ^ rk[ 5];
 t2 = AES_Te0[s2 >> 24] ^ AES_Te1[(s3 >> 16) & 0xff] ^ AES_Te2[(s0 >>  
8) & 0xff] ^ AES_Te3[s1 & 0xff] ^ rk[ 6];
 t3 = AES_Te0[s3 >> 24] ^ AES_Te1[(s0 >> 16) & 0xff] ^ AES_Te2[(s1 >>  
8) & 0xff] ^ AES_Te3[s2 & 0xff] ^ rk[ 7];
-   /* round 2: */
+   /* round 2: */
 s0 = AES_Te0[t0 >> 24] ^ AES_Te1[(t1 >> 16) & 0xff] ^ AES_Te2[(t2 >>  
8) & 0xff] ^ AES_Te3[t3 & 0xff] ^ rk[ 8];
 s1 = AES_Te0[t1 >> 24] ^ AES_Te1[(t2 >> 16) & 0xff] ^ AES_Te2[(t3 >>  
8) & 0xff] ^ AES_Te3[t0 & 0xff] ^ rk[ 9];
 s2 = AES_Te0[t2 >> 24] ^ AES_Te1[(t3 >> 16) & 0xff] ^ AES_Te2[(t0 >>  
8) & 0xff] ^ AES_Te3[t1 & 0xff] ^ rk[10];
@@ -1257,7 +1257,7 @@ void AES_encrypt(const unsigned char *in, unsigned char 
*out,
 t1 = AES_Te0[s1 >> 24] ^ AES_Te1[(s2 >> 16) & 0xff] ^ AES_Te2[(s3 >>  
8) & 0xff] ^ AES_Te3[s0 & 0xff] ^ rk[13];
 t2 = AES_Te0[s2 >> 24] ^ AES_Te1[(s3 >> 16) & 0xff] ^ AES_Te2[(s0 >>  
8) & 0xff] ^ AES_Te3[s1 & 0xff] ^ rk[14];
 t3 = AES_Te0[s3 >> 24] ^ AES_Te1[(s0 >> 16) & 0xff] ^ AES_Te2[(s1 >>  
8) & 0xff] ^ AES_Te3[s2 & 0xff] ^ rk[15];
-   /* round 4: */
+   /* round 4: */
 s0 = AES_Te0[t0 >> 24] ^ AES_Te1[(t1 >> 16) & 0xff] ^ AES_Te2[(t2 >>  
8) & 0xff] ^ AES_Te3[t3 & 0xff] ^ rk[16];
 s1 = AES_Te0[t1 >> 24] ^ AES_Te1[(t2 >> 16) & 0xff] ^ AES_Te2[(t3 >>  
8) & 0xff] ^ AES_Te3[t0 & 0xff] ^ rk[17];
 s2 = AES_Te0[t2 >> 24] ^ AES_Te1[(t3 >> 16) & 0xff] ^ AES_Te2[(t0 >>  
8) & 0xff] ^ AES_Te3[t1 & 0xff] ^ rk[18];
@@ -1267,7 +1267,7 @@ void AES_encrypt(const unsigned char *in, unsigned char 
*out,
 t1 = AES_Te0[s1 >> 24] ^ AES_Te1[(s2 >> 16) & 0xff] ^ AES_Te2[(s3 >>  
8) & 0xff] ^ AES_Te3[s0 & 0xff] ^ rk[21];
 t2 = AES_Te0[s2 >> 24] ^ AES_Te1[(s3 >> 16) & 0xff] ^ AES_Te2[(s0 >>  
8) & 0xff] ^ AES_Te3[s1 & 0xff] ^ rk[22];
 t3 = AES_Te0[s3 >> 24] ^ AES_Te1[(s0 >> 16) & 0xff] ^ AES_Te2[(s1 >>  
8) & 0xff] ^ AES_Te3[s2 & 0xff] ^ rk[23];
-   /* round 6: */
+   /* round 6: */
 s0 = AES_Te0[t0 >> 24] ^ AES_Te1[(t1 >> 16) & 0xff] ^ AES_Te2[(t2 >>  
8) & 0xff] ^ AES_Te3[t3 & 0xff] ^ rk[24];
 s1 = AES_Te0[t1 >> 24] ^ AES_Te1[(t2 >> 16) & 0xff] ^ AES_Te2[(t3 >>  
8) & 0xff] ^ AES_Te3[t0 & 0xff] ^ rk[25];
 s2 = AES_Te0[t2 >> 24] ^ AES_Te1[(t3 >> 16) & 0xff] ^ AES_Te2[(t0 >>  
8) & 0xff] ^ AES_Te3[t1 & 0xff] ^ rk[26];
@@ -1277,7 +1277,7 @@ void AES_encrypt(const unsigned char *in, unsigned char 
*out,
 t1 = AES_Te0[s1 >> 24] ^ AES_Te1[(s2 >> 16) & 0xff] ^ AES_Te2[(s3 >>  
8) & 0xff] ^ AES_Te3[s0 & 0xff] ^ rk[29];
 t2 = AES_Te0[s2 >> 24] ^ AES_Te1[(s3 >> 16) & 0xff] ^ AES_Te2[(s0 >>  
8) & 0xff] ^ 

[Qemu-devel] [PATCH 2/2] avoid TABs in files that only contain a few

2018-12-13 Thread Paolo Bonzini
Most files that have TABs only contain a handful of them.  Change
them to spaces so that we don't confuse people.

disas, standard-headers, linux-headers and libdecnumber are imported
from other projects and probably should be exempted from the check.
Outside those, after this patch the following files still contain both
8-space and TAB sequences at the beginning of the line.  Many of them
have a majority of TABs, or were initially committed with all tabs.

bsd-user/i386/target_syscall.h
bsd-user/x86_64/target_syscall.h
crypto/aes.c
hw/audio/fmopl.c
hw/audio/fmopl.h
hw/block/tc58128.c
hw/display/cirrus_vga.c
hw/display/xenfb.c
hw/dma/etraxfs_dma.c
hw/intc/sh_intc.c
hw/misc/mst_fpga.c
hw/net/pcnet.c
hw/sh4/sh7750.c
hw/timer/m48t59.c
hw/timer/sh_timer.c
include/crypto/aes.h
include/disas/bfd.h
include/hw/sh4/sh.h
libdecnumber/decNumber.c
linux-headers/asm-generic/unistd.h
linux-headers/linux/kvm.h
linux-user/alpha/target_syscall.h
linux-user/arm/nwfpe/double_cpdo.c
linux-user/arm/nwfpe/fpa11_cpdt.c
linux-user/arm/nwfpe/fpa11_cprt.c
linux-user/arm/nwfpe/fpa11.h
linux-user/flat.h
linux-user/flatload.c
linux-user/i386/target_syscall.h
linux-user/ppc/target_syscall.h
linux-user/sparc/target_syscall.h
linux-user/syscall.c
linux-user/syscall_defs.h
linux-user/x86_64/target_syscall.h
slirp/cksum.c
slirp/if.c
slirp/ip.h
slirp/ip_icmp.c
slirp/ip_icmp.h
slirp/ip_input.c
slirp/ip_output.c
slirp/mbuf.c
slirp/misc.c
slirp/sbuf.c
slirp/socket.c
slirp/socket.h
slirp/tcp_input.c
slirp/tcpip.h
slirp/tcp_output.c
slirp/tcp_subr.c
slirp/tcp_timer.c
slirp/tftp.c
slirp/udp.c
slirp/udp.h
target/cris/cpu.h
target/cris/mmu.c
target/cris/op_helper.c
target/sh4/helper.c
target/sh4/op_helper.c
target/sh4/translate.c
tcg/sparc/tcg-target.inc.c
tests/tcg/cris/check_addo.c
tests/tcg/cris/check_moveq.c
tests/tcg/cris/check_swap.c
tests/tcg/multiarch/test-mmap.c
ui/vnc-enc-hextile-template.h
ui/vnc-enc-zywrle.h
util/envlist.c
util/readline.c

The following have only TABs:

bsd-user/i386/target_signal.h
bsd-user/sparc64/target_signal.h
bsd-user/sparc64/target_syscall.h
bsd-user/sparc/target_signal.h
bsd-user/sparc/target_syscall.h
bsd-user/x86_64/target_signal.h
crypto/desrfb.c
hw/audio/intel-hda-defs.h
hw/core/uboot_image.h
hw/sh4/sh7750_regnames.c
hw/sh4/sh7750_regs.h
include/hw/cris/etraxfs_dma.h
linux-user/alpha/termbits.h
linux-user/arm/nwfpe/fpopcode.h
linux-user/arm/nwfpe/fpsr.h
linux-user/arm/syscall_nr.h
linux-user/arm/target_signal.h
linux-user/cris/target_signal.h
linux-user/i386/target_signal.h
linux-user/linux_loop.h
linux-user/m68k/target_signal.h
linux-user/microblaze/target_signal.h
linux-user/mips64/target_signal.h
linux-user/mips/target_signal.h
linux-user/mips/target_syscall.h
linux-user/mips/termbits.h
linux-user/ppc/target_signal.h
linux-user/sh4/target_signal.h
linux-user/sh4/termbits.h
linux-user/sparc64/target_syscall.h
linux-user/sparc/target_signal.h
linux-user/x86_64/target_signal.h
linux-user/x86_64/termbits.h
pc-bios/optionrom/optionrom.h
slirp/mbuf.h
slirp/misc.h
slirp/sbuf.h
slirp/tcp.h
slirp/tcp_timer.h
slirp/tcp_var.h
target/i386/svm.h
target/sparc/asi.h
target/xtensa/core-dc232b/xtensa-modules.inc.c
target/xtensa/core-dc233c/xtensa-modules.inc.c
target/xtensa/core-de212/core-isa.h
target/xtensa/core-de212/xtensa-modules.inc.c
target/xtensa/core-fsf/xtensa-modules.inc.c
target/xtensa/core-sample_controller/core-isa.h
target/xtensa/core-sample_controller/xtensa-modules.inc.c
target/xtensa/core-test_kc705_be/core-isa.h
target/xtensa/core-test_kc705_be/xtensa-modules.inc.c
tests/tcg/cris/check_abs.c
tests/tcg/cris/check_addc.c
tests/tcg/cris/check_addcm.c
tests/tcg/cris/check_addoq.c
tests/tcg/cris/check_bound.c
tests/tcg/cris/check_ftag.c
tests/tcg/cris/check_int64.c
tests/tcg/cris/check_lz.c
tests/tcg/cris/check_openpf5.c
tests/tcg/cris/check_sigalrm.c
tests/tcg/cris/crisutils.h
tests/tcg/cris/sys.c
tests/tcg/i386/test-i386-ssse3.c
ui/vgafont.h

Signed-off-by: Paolo Bonzini 
---
 block/bochs.c  | 22 ++---
 block/file-posix.c |  2 +-
 block/file-win32.c |  8 +-
 block/linux-aio.c  |  4 +-
 block/qcow2-cluster.c  |  2 +-
 block/vpc.c|  2 +-
 bsd-user/elfload.c |  2 +-
 contrib/elf2dmp/main.c |  2 +-
 hw/alpha/typhoon.c | 12 +--
 hw/arm/stellaris.c   

[Qemu-devel] [PATCH 0/2] Fix TABs in many files

2018-12-13 Thread Paolo Bonzini
Space-tab sequences at the beginning of the line are always a mistake,
so patch 1 fixes them.  I am not touching space-tab in the middle of
the line, many of which are in #define lines.

In addition, about a third of the files with TABs have only a few of
them and it's worth converting them for consistency.  Of the files
touched by patch 2, hw/ide/core.c is the worst in absolute terms, with
over 50 occurrences in a 3000 lines file; hw/char/xen_console.c has
about a third TABs and two-thirds spaces but it is small so I included it.

The files were selected by hand starting from a list of .c and .h
files in the tree, sorted by number of occurrences.  I left out
files that for example were using TABs consistently for structs,
on the grounds that those were probably copied from Linux.  I also
left out slirp from patch 2 because I did not want to complicate the
ongoing surgery to extract it from QEMU.

Thanks,

Paolo

Paolo Bonzini (2):
  remove space-tab sequences
  avoid TABs in files that only contain a few

 block/bochs.c  | 22 ++---
 block/file-posix.c |  2 +-
 block/file-win32.c |  8 +-
 block/linux-aio.c  |  4 +-
 block/qcow2-cluster.c  |  2 +-
 block/vpc.c|  2 +-
 bsd-user/elfload.c |  2 +-
 bsd-user/x86_64/target_syscall.h   |  2 +-
 contrib/elf2dmp/main.c |  2 +-
 crypto/aes.c   | 28 +++
 disas/alpha.c  |  8 +-
 disas/arm.c|  2 +-
 disas/i386.c   |  4 +-
 disas/m68k.c   |  4 +-
 hw/alpha/typhoon.c | 12 +--
 hw/arm/stellaris.c |  2 +-
 hw/arm/virt.c  |  2 +-
 hw/char/sh_serial.c| 18 ++---
 hw/char/virtio-serial-bus.c|  2 +-
 hw/char/xen_console.c  | 58 ++---
 hw/core/loader.c   | 28 +++
 hw/display/tc6393xb.c  |  6 +-
 hw/display/vga.c   |  8 +-
 hw/display/virtio-gpu-3d.c |  6 +-
 hw/dma/pxa2xx_dma.c|  4 +-
 hw/dma/soc_dma.c   |  2 +-
 hw/gpio/max7310.c  |  2 +-
 hw/i386/xen/xen-hvm.c  |  4 +-
 hw/ide/core.c  | 94 +++---
 hw/input/lm832x.c  |  2 +-
 hw/input/pckbd.c   |  2 +-
 hw/input/tsc210x.c |  2 +-
 hw/intc/apic.c |  2 +-
 hw/mips/gt64xxx_pci.c  |  6 +-
 hw/mips/mips_r4k.c |  4 +-
 hw/misc/max111x.c  |  6 +-
 hw/misc/omap_l4.c  |  4 +-
 hw/net/mipsnet.c   | 16 ++--
 hw/net/ne2000.c| 44 +-
 hw/net/rocker/rocker.c |  2 +-
 hw/net/virtio-net.c|  4 +-
 hw/net/vmxnet3.c   |  6 +-
 hw/pci/msix.c  |  2 +-
 hw/pci/pci.c   | 44 +-
 hw/pci/pci_bridge.c|  2 +-
 hw/ppc/ppc405_uc.c |  2 +-
 hw/ppc/prep.c  |  4 +-
 hw/scsi/lsi53c895a.c   |  6 +-
 hw/sh4/r2d.c   | 16 ++--
 hw/usb/dev-bluetooth.c |  2 +-
 hw/usb/dev-hid.c   |  6 +-
 hw/usb/dev-hub.c   | 14 ++--
 hw/usb/hcd-uhci.c  |  4 +-
 hw/xen/xen_devconfig.c |  2 +-
 hw/xenpv/xen_domainbuild.c |  8 +-
 include/elf.h  | 10 +--
 include/hw/acpi/acpi.h | 14 ++--
 include/hw/elf_ops.h   |  2 +-
 include/hw/ide/internal.h  |  2 +-
 include/hw/sh4/sh_intc.h   | 20 ++---
 include/hw/xen/io/ring.h   |  4 +-
 include/qemu/acl.h | 14 ++--
 include/qemu/iov.h |  2 +-
 include/scsi/constants.h   |  2 +-
 include/sysemu/balloon.h   |  2 +-
 linux-user/linuxload.c | 14 ++--
 linux-user/main.c  |  4 +-
 linux-user/mmap.c  | 10 +--
 linux-user/qemu.h  |  4 +-
 linux-user/signal.c| 16 ++--
 linux-user/strace.c|  4 +-
 linux-user/syscall.c   |  2 +-
 linux-user/syscall_defs.h  |  4 +-
 linux-user/uaccess.c   |  2 +-
 linux-user/vm86.c  | 

[Qemu-devel] [PATCH] usb-mtp: Limit filename to object information size

2018-12-13 Thread Michael Hanselmann
The filename length in MTP metadata is specified by the guest. By
trusting it directly it'd theoretically be possible to get the host to
write memory parts outside the filename buffer into a filename. In
practice though there are usually NUL bytes stopping the string
operations.

Also use the opportunity to not assign the filename member twice.

Signed-off-by: Michael Hanselmann 
---
 hw/usb/dev-mtp.c | 8 
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/hw/usb/dev-mtp.c b/hw/usb/dev-mtp.c
index 100b7171f4..360ca65ee4 100644
--- a/hw/usb/dev-mtp.c
+++ b/hw/usb/dev-mtp.c
@@ -1705,7 +1705,7 @@ free:
 s->write_pending = false;
 }
 
-static void usb_mtp_write_metadata(MTPState *s)
+static void usb_mtp_write_metadata(MTPState *s, uint64_t dlen)
 {
 MTPData *d = s->data_out;
 ObjectInfo *dataset = (ObjectInfo *)d->data;
@@ -1717,7 +1717,8 @@ static void usb_mtp_write_metadata(MTPState *s)
 assert(!s->write_pending);
 assert(p != NULL);
 
-filename = utf16_to_str(dataset->length, dataset->filename);
+filename = utf16_to_str(MIN(dataset->length, dlen - offsetof(ObjectInfo, 
filename)),
+dataset->filename);
 
 if (strchr(filename, '/')) {
 usb_mtp_queue_result(s, RES_PARAMETER_NOT_SUPPORTED, d->trans,
@@ -1733,7 +1734,6 @@ static void usb_mtp_write_metadata(MTPState *s)
 s->dataset.filename = filename;
 s->dataset.format = dataset->format;
 s->dataset.size = dataset->size;
-s->dataset.filename = filename;
 s->write_pending = true;
 
 if (s->dataset.format == FMT_ASSOCIATION) {
@@ -1802,7 +1802,7 @@ static void usb_mtp_get_data(MTPState *s, mtp_container 
*container,
 if (d->offset == d->length) {
 /* The operation might have already failed */
 if (!s->result) {
-usb_mtp_write_metadata(s);
+usb_mtp_write_metadata(s, dlen);
 }
 usb_mtp_data_free(s->data_out);
 s->data_out = NULL;
-- 
2.11.0




Re: [Qemu-devel] [PATCH v3] log: Make glib logging go through QEMU

2018-12-13 Thread no-reply
Patchew URL: https://patchew.org/QEMU/20181213142719.592-1-cferg...@redhat.com/



Hi,

This series seems to have some coding style problems. See output below for
more information:

Type: series
Message-id: 20181213142719.592-1-cferg...@redhat.com
Subject: [Qemu-devel] [PATCH v3] log: Make glib logging go through QEMU

=== TEST SCRIPT BEGIN ===
#!/bin/bash

BASE=base
n=1
total=$(git log --oneline $BASE.. | wc -l)
failed=0

git config --local diff.renamelimit 0
git config --local diff.renames True
git config --local diff.algorithm histogram

commits="$(git log --format=%H --reverse $BASE..)"
for c in $commits; do
echo "Checking PATCH $n/$total: $(git log -n 1 --format=%s $c)..."
if ! git show $c --format=email | ./scripts/checkpatch.pl --mailback -; then
failed=1
echo
fi
n=$((n+1))
done

exit $failed
=== TEST SCRIPT END ===

Updating 3c8cf5a9c21ff8782164d1def7f44bd888713384
Switched to a new branch 'test'
4da29cf log: Make glib logging go through QEMU

=== OUTPUT BEGIN ===
Checking PATCH 1/1: log: Make glib logging go through QEMU...
ERROR: space prohibited between function name and open parenthesis '('
#133: FILE: util/qemu-error.c:364:
+if (strcmp (qemu_glog_domains, "all") != 0 &&

ERROR: space prohibited between function name and open parenthesis '('
#134: FILE: util/qemu-error.c:365:
+  (log_domain == NULL || !strstr (qemu_glog_domains, log_domain))) {

total: 2 errors, 0 warnings, 107 lines checked

Your patch has style problems, please review.  If any of these errors
are false positives report them to the maintainer, see
CHECKPATCH in MAINTAINERS.

=== OUTPUT END ===

Test command exited with code: 1


The full log is available at
http://patchew.org/logs/20181213142719.592-1-cferg...@redhat.com/testing.checkpatch/?type=message.
---
Email generated automatically by Patchew [http://patchew.org/].
Please send your feedback to patchew-de...@redhat.com

Re: [Qemu-devel] [PATCH v1 1/2] target/arm: kvm64 make guest debug AA32 break point aware

2018-12-13 Thread Richard Henderson
On 12/13/18 8:55 AM, Alex Bennée wrote:
> 
> Ard Biesheuvel  writes:
> 
>> Hi Alex,
>>
>> Thanks again for looking into this.
>>
>> On Thu, 13 Dec 2018 at 12:55, Alex Bennée  wrote:
> 
>>
>>>
>>>  int kvm_arch_insert_sw_breakpoint(CPUState *cs, struct kvm_sw_breakpoint 
>>> *bp)
>>>  {
>>> +CPUARMState *env = _CPU(cs)->env;
>>> +int el = arm_current_el(env);
>>> +bool is_aa64 = arm_el_is_aa64(env, el);
>>> +const uint32_t *bpi = is_aa64 ? _insn : _insn;
>>> +
>>>  if (have_guest_debug) {
>>>  if (cpu_memory_rw_debug(cs, bp->pc, (uint8_t *)>saved_insn, 4, 
>>> 0) ||
>>> -cpu_memory_rw_debug(cs, bp->pc, (uint8_t *)_insn, 4, 1)) {
>>> +cpu_memory_rw_debug(cs, bp->pc, (uint8_t *)bpi, 4, 1)) {
>>
>> Should we be dealing with endianness here?
>>
> 
> 
> I don't think so - everything eventually ends up (ld|st)n_p which deals
> with the endianness details.

I think Ard is right.  You need to consider dynamic endianness with

bswap_code(arm_sctlr_b(env))


r~
r~




Re: [Qemu-devel] [PATCH 0/1] checkpatch: checker for comment block

2018-12-13 Thread Paolo Bonzini
On 13/12/18 19:21, Peter Maydell wrote:
> On Thu, 13 Dec 2018 at 18:07, Paolo Bonzini  wrote:
>> On 13/12/18 19:01, Peter Maydell wrote:
>>> I sent a patch to do this a little while back:
>>>  https://patchwork.kernel.org/patch/10561557/
>>>
>>> It didn't get applied because Paolo disagreed with having
>>> our tools enforcing what our style guide says.
>>
>> I didn't disagree with that---I disagreed with having a single style in
>> the style guide, because unlike most other blatant violations of the
>> coding style (eg. braces), this one is pervasive in maintained code and
>> I don't want code that I maintain to mix two comment styles.
>>
>> So I proposed two alternatives:
>>
>> - someone fixes all the comment blocks which are "starred" but don't
>> have a lone "/*" at the beginning, and then we can commit that patch;
>>
>> - we allow "/* foo" on the first line, except for doc comments and for
>> the first line of the file (author/license block), and fix the style
>> guide accordingly.
> 
> We came to a consensus on the comment style when we discussed
> the patch which updated CODING_STYLE. I'm not personally
> a fan of the result (I used to use "/* foo"), but what we have in the
> doc is what we achieved consensus for. I'm not going to reopen
> the "what should block comments look like" style debate.

Sure, I don't want to do that either.  I accept the result of the
discussion; I don't accept introducing a new warning that will cause
over 700 files to become inconsistent sooner or later.  Therefore, the
only way to enforce the result of the discussion is to change the
existing comments, for example by having a script that maintainers can
use to change the existing comments in their files.  Having each of us
come up with their own script or doing it by hand is probably not a good
use of everyone's time.

Alternatively, fixing the style guide can also mean "explain why /* foo
is allowed by checkpatch even though it does not match the coding
style", without rehashing the discussion.

(BTW it may actually be a good idea to fix _some_ instances of bad
coding style, in particular the space-tab sequences and the files where
there are maybe 2 or 3 tabs that ended up there by mistake.  That's a
different topic).

Paolo



Re: [Qemu-devel] [PATCH v1 1/2] target/arm: kvm64 make guest debug AA32 break point aware

2018-12-13 Thread Richard Henderson
On 12/13/18 5:55 AM, Alex Bennée wrote:
>  int kvm_arch_insert_sw_breakpoint(CPUState *cs, struct kvm_sw_breakpoint *bp)
>  {
> +CPUARMState *env = _CPU(cs)->env;
> +int el = arm_current_el(env);
> +bool is_aa64 = arm_el_is_aa64(env, el);

This will assert for el == 0; for that you need is_a64(env).


r~



Re: [Qemu-devel] [Qemu-block] [PATCH RFC] qemu-io: Prefer stderr for error messages

2018-12-13 Thread Nir Soffer
On Thu, Dec 13, 2018 at 11:27 PM Eric Blake  wrote:

> On 12/13/18 11:44 AM, Nir Soffer wrote:
>
> >> The things is, qemu-io was never meant to be used by other
> >> applications that need to process the results, it's a tool for testing
> >> and debugging. If we had meant it to be used by other programs, we would
> >> have given it a machine-friendly interface.
> >>
> >> The machine-friendly interface to the QEMU block layer is qemu-nbd.
> >>
> >
> > nbd is awesome, but much more complicated to use for testing. You need
> to:
> >
> > 1. start qemu-nbd
> > 2. wait until it is ready
> > 3. use nbd client (we have one now), or connect the qemu-nbd to
> /dev/ndbX,
> > which on
> >Fedora 28 leaves stale /dev/nbdX devices after disconnection
> >(I reported this few month ago here).
>
> Is that true even when you use 'qemu-nbd -d /dev/nbdX' after you are done?
>

It was true when I reported this here:
http://lists.nongnu.org/archive/html/qemu-block/2018-07/msg00168.html


Re: [Qemu-devel] [PATCH v2] Add getsockopt for settable SOL_IPV6 options

2018-12-13 Thread no-reply
Patchew URL: 
https://patchew.org/QEMU/20181213133733.8110-1-tom.des...@gmail.com/



Hi,

This series seems to have some coding style problems. See output below for
more information:

Type: series
Message-id: 20181213133733.8110-1-tom.des...@gmail.com
Subject: [Qemu-devel] [PATCH v2] Add getsockopt for settable SOL_IPV6 options

=== TEST SCRIPT BEGIN ===
#!/bin/bash

BASE=base
n=1
total=$(git log --oneline $BASE.. | wc -l)
failed=0

git config --local diff.renamelimit 0
git config --local diff.renames True
git config --local diff.algorithm histogram

commits="$(git log --format=%H --reverse $BASE..)"
for c in $commits; do
echo "Checking PATCH $n/$total: $(git log -n 1 --format=%s $c)..."
if ! git show $c --format=email | ./scripts/checkpatch.pl --mailback -; then
failed=1
echo
fi
n=$((n+1))
done

exit $failed
=== TEST SCRIPT END ===

Updating 3c8cf5a9c21ff8782164d1def7f44bd888713384
Switched to a new branch 'test'
c7f204a Add getsockopt for settable SOL_IPV6 options

=== OUTPUT BEGIN ===
Checking PATCH 1/1: Add getsockopt for settable SOL_IPV6 options...
ERROR: braces {} are necessary for all arms of this statement
#30: FILE: linux-user/syscall.c:2368:
+if (get_user_u32(len, optlen))
[...]

ERROR: braces {} are necessary for all arms of this statement
#32: FILE: linux-user/syscall.c:2370:
+if (len < 0)
[...]

ERROR: braces {} are necessary for all arms of this statement
#36: FILE: linux-user/syscall.c:2374:
+if (ret < 0)
[...]

ERROR: braces {} are necessary for all arms of this statement
#44: FILE: linux-user/syscall.c:2382:
+if (len > sizeof(int))
[...]

total: 4 errors, 0 warnings, 44 lines checked

Your patch has style problems, please review.  If any of these errors
are false positives report them to the maintainer, see
CHECKPATCH in MAINTAINERS.

=== OUTPUT END ===

Test command exited with code: 1


The full log is available at
http://patchew.org/logs/20181213133733.8110-1-tom.des...@gmail.com/testing.checkpatch/?type=message.
---
Email generated automatically by Patchew [http://patchew.org/].
Please send your feedback to patchew-de...@redhat.com

Re: [Qemu-devel] [PATCH] hw/misc/tz-mpc: Fix value of BLK_MAX register

2018-12-13 Thread Richard Henderson
On 12/13/18 12:32 PM, Peter Maydell wrote:
> In the TZ Memory Protection Controller, the BLK_MAX register is supposed
> to return the maximum permitted value of the BLK_IDX register. Our
> implementation incorrectly returned max+1 (ie the total number of
> valid index values, since BLK_IDX is zero-based).
> 
> Correct this off-by-one error. Since we consistently initialize
> and use s->blk_max throughout the implementation as the 'size'
> of the LUT, just adjust the value we return when the guest reads
> the BLK_MAX register, rather than trying to change the semantics
> of the s->blk_max internal struct field.
> 
> Fixes: https://bugs.launchpad.net/qemu/+bug/1806824
> Signed-off-by: Peter Maydell 
> ---
>  hw/misc/tz-mpc.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)

Reviewed-by: Richard Henderson 


r~



Re: [Qemu-devel] [PATCH 0/3] Update deprecation notes for QMP 'cpu-add' & HMP 'cpu_add'

2018-12-13 Thread Eduardo Habkost
Queued.  Thanks, and sorry for making the original series miss
the 3.1 release.

-- 
Eduardo



Re: [Qemu-devel] [PATCH 2/3] Update that HMP 'cpu_add' is deprecated in 4.0

2018-12-13 Thread Eduardo Habkost
On Thu, Dec 13, 2018 at 09:03:23PM +0100, Thomas Huth wrote:
> On 2018-12-13 13:42, Kashyap Chamarthy wrote:
> > Also fix the wrong spelling of it: s/cpu-add/cpu_add/
> > 
> > Signed-off-by: Kashyap Chamarthy 
> > ---
> >  qemu-deprecated.texi | 4 ++--
> >  1 file changed, 2 insertions(+), 2 deletions(-)
> > 
> > diff --git a/qemu-deprecated.texi b/qemu-deprecated.texi
> > index 46bec688db..79743ab8bd 100644
> > --- a/qemu-deprecated.texi
> > +++ b/qemu-deprecated.texi
> > @@ -121,9 +121,9 @@ replaced by the ``target'' output member.
> >  The @option{[hub_id name]} parameter tuple of the 'hostfwd_add' and
> >  'hostfwd_remove' HMP commands has been replaced by @option{netdev_id}.
> >  
> > -@subsection cpu-add (since 3.1)
> > +@subsection cpu_add (since 4.0)
> >  
> > -Use ``device_add'' for hotplugging vCPUs instead of ``cpu-add''.  See
> > +Use ``device_add'' for hotplugging vCPUs instead of ``cpu_add''.  See
> 
> AFAIK the spelling was right. It's "cpu-add" ... only device_add is
> using the underscore. Welcome to the wonderful world of QEMU
> inconsistencies...

Thanks for noting.  I have fixed it while committing.

-- 
Eduardo



Re: [Qemu-devel] [Qemu-block] Request for clarification on qemu-img convert behavior zeroing target host_device

2018-12-13 Thread Nir Soffer
On Thu, Dec 13, 2018 at 11:14 PM De Backer, Fred (Nokia - BE/Antwerp) <
fred.de_bac...@nokia.com> wrote:

> > Indeed, performance traces are important for issues like this.
> See strace of both FC27 and FC29 attached
>

Looks like you traced only the main thread. All the I/O is done in other
threads.
These flags would be useful:

strace -o log -f -T -tt

Nir


Re: [Qemu-devel] [PULL 27/32] qapi: add #if conditions to generated code members

2018-12-13 Thread Eric Blake

On 12/13/18 12:43 PM, Markus Armbruster wrote:

From: Marc-André Lureau 

Wrap generated enum and struct members and their supporting code with



Git ate the line because it started with #.  Not sure if you can sneak 
in a v2 pull request that puts something sane here...



We do enum and struct in a single patch because union tag enum and the
associated variants tie them together, and dealing with that to split
the patch doesn't seem worthwhile.


--
Eric Blake, Principal Software Engineer
Red Hat, Inc.   +1-919-301-3266
Virtualization:  qemu.org | libvirt.org



Re: [Qemu-devel] Loading snapshot with readonly qcow2 image

2018-12-13 Thread Eric Blake

On 12/13/18 12:33 PM, Michael Spradling wrote:


My question is has anyone looked into loading snapshots from a backing
file?  I have attempted to look through the code and this looks to be
difficult.  If I attempt to add support for this is there any general
advice to follow?  Any other ideas?


'qemu-nbd -l' can serve snapshots from a qcow2 file; perhaps that can be
used to cobble together something that works for your needs?





I looked at "qemu-nbd -l" and this seems to only export a readonly
interface.  Really, what I need is a writable temp file that can load a
snapshot snapshot.


Can you combine -s (create a writable temp file) with -l to get what you 
want?


/me tries:

$ qemu-img create -f qcow2 a 1M
Formatting 'a', fmt=qcow2 size=1048576 cluster_size=65536 
lazy_refcounts=off refcount_bits=16

$ qemu-io -c 'w -P 1 0 512' a
wrote 512/512 bytes at offset 0
512 bytes, 1 ops; 0.0487 sec (10.257 KiB/sec and 20.5137 ops/sec)
$ qemu-img snapshot -c snap a
$ qemu-io -c 'w -P 2 0 512' a
wrote 512/512 bytes at offset 0
512 bytes, 1 ops; 0.0752 sec (6.645 KiB/sec and 13.2903 ops/sec)
$ qemu-nbd -l snap -s a
Failed to load snapshot: Can't find snapshot

I can confirm that 'qemu-nbd -s a' lets me write data that is discarded 
on disconnect (lsof says a temp file in /var/tmp/vl.XX was created); 
and that 'qemu-nbd -l snap a' lets me read the snapshot data. But mixing 
the two fails, and it would be a nice bug to fix.




Please excuse and correct me if I get some of the terminology of the
sections below wrong.

I went down the path of hacking up some of the qemu qcow2 file system
code to see if I can achieve the ability to restore a snapshot from a
backing file to the temporarily created "-snapshot" qcow2 image.  The
backing file has been marked readonly by the filesystem and the active
image file was created with the "-snapshot" option.  I spend some time
reading the qcow2 documentation and it seems I have to copy the l1 and
l2 table values(are these actual host clusters) from the backing file
snapshot to the active images l1 and l2 tables.  Is there anything else
that may need updated that I have not yet stumbled upon?


Mucking with the l1 and l2 tables implies that you are directly 
manipulating qcow2 contents.  It's much nicer if you can come up with a 
solution where qemu-img does all the qcow2 work for you, and you just 
worry about guest-visible data.  Or are you actually patching the code 
compiled into qemu-img?




I still don't have this working yet and I believe my area of problems is
qcow2_update_snapshot_refcount.  Can anyone explain what this does
exactly.  It seems the function does three different things based on the
value of addend, either -1, 0, 1, but its somewhat unclear.


Every cluster of qcow2 is reference-counted, to track which portions of 
the file are (supposed to be) in use according to following the metadata 
trails.  When internal snapshots are used, this is implemented by 
incrementing the refcount for each cluster that is reachable both from 
the snapshot and from the current L1 table (update_snapshot_refcount 
+1), then when writing to the cluster we break the reference count by 
writing the new data to a new allocation and decrementing the reference 
count of the old cluster. When trimming clusters, we decrement the 
refcount, and if it goes to 0 the cluster can be reused for something else.


--
Eric Blake, Principal Software Engineer
Red Hat, Inc.   +1-919-301-3266
Virtualization:  qemu.org | libvirt.org



Re: [Qemu-devel] [PATCH] Add getsockopt for settable SOL_IPV6 options

2018-12-13 Thread no-reply
Patchew URL: 
https://patchew.org/QEMU/20181213130611.7496-1-tom.des...@gmail.com/



Hi,

This series seems to have some coding style problems. See output below for
more information:

Type: series
Message-id: 20181213130611.7496-1-tom.des...@gmail.com
Subject: [Qemu-devel] [PATCH] Add getsockopt for settable SOL_IPV6 options

=== TEST SCRIPT BEGIN ===
#!/bin/bash

BASE=base
n=1
total=$(git log --oneline $BASE.. | wc -l)
failed=0

git config --local diff.renamelimit 0
git config --local diff.renames True
git config --local diff.algorithm histogram

commits="$(git log --format=%H --reverse $BASE..)"
for c in $commits; do
echo "Checking PATCH $n/$total: $(git log -n 1 --format=%s $c)..."
if ! git show $c --format=email | ./scripts/checkpatch.pl --mailback -; then
failed=1
echo
fi
n=$((n+1))
done

exit $failed
=== TEST SCRIPT END ===

Updating 3c8cf5a9c21ff8782164d1def7f44bd888713384
From https://github.com/patchew-project/qemu
 * [new tag] patchew/20181213210057.3676-1-quint...@redhat.com -> 
patchew/20181213210057.3676-1-quint...@redhat.com
Switched to a new branch 'test'
851c863 Add getsockopt for settable SOL_IPV6 options

=== OUTPUT BEGIN ===
Checking PATCH 1/1: Add getsockopt for settable SOL_IPV6 options...
ERROR: braces {} are necessary for all arms of this statement
#30: FILE: linux-user/syscall.c:2368:
+if (get_user_u32(len, optlen))
[...]

ERROR: braces {} are necessary for all arms of this statement
#32: FILE: linux-user/syscall.c:2370:
+if (len < 0)
[...]

ERROR: braces {} are necessary for all arms of this statement
#36: FILE: linux-user/syscall.c:2374:
+if (ret < 0)
[...]

ERROR: braces {} are necessary for all arms of this statement
#44: FILE: linux-user/syscall.c:2382:
+if (len > sizeof(int))
[...]

total: 4 errors, 0 warnings, 45 lines checked

Your patch has style problems, please review.  If any of these errors
are false positives report them to the maintainer, see
CHECKPATCH in MAINTAINERS.

=== OUTPUT END ===

Test command exited with code: 1


The full log is available at
http://patchew.org/logs/20181213130611.7496-1-tom.des...@gmail.com/testing.checkpatch/?type=message.
---
Email generated automatically by Patchew [http://patchew.org/].
Please send your feedback to patchew-de...@redhat.com

Re: [Qemu-devel] [PATCH] block: Replace qdict_put() by qdict_put_obj() where appropriate

2018-12-13 Thread Eric Blake

On 12/13/18 11:51 AM, Markus Armbruster wrote:

Patch created mechanically by rerunning:

   $  spatch --sp-file scripts/coccinelle/qobject.cocci \
--macro-file scripts/cocci-macro-file.h \
--dir block --in-place

Signed-off-by: Markus Armbruster 
---
  block/blklogwrites.c | 5 ++---
  1 file changed, 2 insertions(+), 3 deletions(-)


Reviewed-by: Eric Blake 

--
Eric Blake, Principal Software Engineer
Red Hat, Inc.   +1-919-301-3266
Virtualization:  qemu.org | libvirt.org



Re: [Qemu-devel] [PATCH] vl: Use error_fatal to simplify obvious fatal errors (again)

2018-12-13 Thread Eric Blake

On 12/13/18 11:58 AM, Markus Armbruster wrote:

Patch created mechanically by rerunning:

 $ spatch --in-place --sp-file scripts/coccinelle/use-error_fatal.cocci \
  --macro-file scripts/cocci-macro-file.h vl.c

Signed-off-by: Markus Armbruster 
---
  vl.c | 7 ++-
  1 file changed, 2 insertions(+), 5 deletions(-)



Reviewed-by: Eric Blake 

--
Eric Blake, Principal Software Engineer
Red Hat, Inc.   +1-919-301-3266
Virtualization:  qemu.org | libvirt.org



Re: [Qemu-devel] [Qemu-block] [PATCH RFC] qemu-io: Prefer stderr for error messages

2018-12-13 Thread Eric Blake

On 12/13/18 11:44 AM, Nir Soffer wrote:


The things is, qemu-io was never meant to be used by other
applications that need to process the results, it's a tool for testing
and debugging. If we had meant it to be used by other programs, we would
have given it a machine-friendly interface.

The machine-friendly interface to the QEMU block layer is qemu-nbd.



nbd is awesome, but much more complicated to use for testing. You need to:

1. start qemu-nbd
2. wait until it is ready
3. use nbd client (we have one now), or connect the qemu-nbd to /dev/ndbX,
which on
   Fedora 28 leaves stale /dev/nbdX devices after disconnection
   (I reported this few month ago here).


Is that true even when you use 'qemu-nbd -d /dev/nbdX' after you are done?


4. finally disconnect and wait until qemu-nbd terminates

qemu-io is so much easier to use, we need to make it more machine friendly.


Or rather, if there is something that a machine needs to drive, we 
should figure out if qemu-img can be taught to do it instead of hacking 
around the issue with qemu-io.  When it comes to extracting portions of 
a disk, qemu-img convert coupled with the raw driver's offset/length 
gets us quite a bit of functionality - even if it's clunky to come up 
with the command line, it can be programmed, and doesn't suffer from 
having to post-process arbitrary qemu-io output changes.



The human interface of qemu-io is honestly just not the right tool for
the job, and adding one-off tweaks to make it a little bit less horrible
to use for machines isn't the right approach because it's still not a
proper machine protocol.



Add --output json?


Who's volunteering to do it? I've got too much else going on to spend 
time on such a project.


--
Eric Blake, Principal Software Engineer
Red Hat, Inc.   +1-919-301-3266
Virtualization:  qemu.org | libvirt.org



Re: [Qemu-devel] [PATCH] error: Remove NULL checks on error_propagate() calls

2018-12-13 Thread Eric Blake

On 12/13/18 11:31 AM, Markus Armbruster wrote:

Patch created mechanically by rerunning:

   $  spatch --sp-file scripts/coccinelle/error_propagate_null.cocci \
 --macro-file scripts/cocci-macro-file.h \
 --dir . --in-place

Whitespace tidied up manually.

Signed-off-by: Markus Armbruster 
---
  blockdev.c  | 4 +---
  hw/s390x/s390-pci-bus.c | 4 +---
  qga/commands-posix.c| 7 ++-
  3 files changed, 4 insertions(+), 11 deletions(-)



Reviewed-by: Eric Blake 

--
Eric Blake, Principal Software Engineer
Red Hat, Inc.   +1-919-301-3266
Virtualization:  qemu.org | libvirt.org



[Qemu-devel] [PATCH v3 13/16] virtio: split virtio serial bits rom virtio-pci

2018-12-13 Thread Juan Quintela
Virtio console and qga tests also depend on CONFIG_VIRTIO_SERIAL.

Reviewed-by: Thomas Huth 
Reviewed-by: Laurent Vivier 
Signed-off-by: Juan Quintela 
---
 hw/virtio/Makefile.objs   |   1 +
 hw/virtio/virtio-pci.c|  75 ---
 hw/virtio/virtio-pci.h|  14 -
 hw/virtio/virtio-serial-pci.c | 112 ++
 tests/Makefile.include|   6 +-
 5 files changed, 116 insertions(+), 92 deletions(-)
 create mode 100644 hw/virtio/virtio-serial-pci.c

diff --git a/hw/virtio/Makefile.objs b/hw/virtio/Makefile.objs
index 4c31acb017..ea7913d532 100644
--- a/hw/virtio/Makefile.objs
+++ b/hw/virtio/Makefile.objs
@@ -24,6 +24,7 @@ obj-$(CONFIG_VIRTIO_9P) += virtio-9p-pci.o
 obj-$(CONFIG_VIRTIO_SCSI) += virtio-scsi-pci.o
 obj-$(CONFIG_VIRTIO_BLK) += virtio-blk-pci.o
 obj-$(CONFIG_VIRTIO_NET) += virtio-net-pci.o
+obj-$(CONFIG_VIRTIO_SERIAL) += virtio-serial-pci.o
 endif
 endif
 
diff --git a/hw/virtio/virtio-pci.c b/hw/virtio/virtio-pci.c
index cb03bfa597..5a54b144a5 100644
--- a/hw/virtio/virtio-pci.c
+++ b/hw/virtio/virtio-pci.c
@@ -19,7 +19,6 @@
 
 #include "standard-headers/linux/virtio_pci.h"
 #include "hw/virtio/virtio.h"
-#include "hw/virtio/virtio-serial.h"
 #include "hw/pci/pci.h"
 #include "qapi/error.h"
 #include "qemu/error-report.h"
@@ -1892,79 +1891,6 @@ static const TypeInfo virtio_pci_info = {
 },
 };
 
-/* virtio-serial-pci */
-
-static void virtio_serial_pci_realize(VirtIOPCIProxy *vpci_dev, Error **errp)
-{
-VirtIOSerialPCI *dev = VIRTIO_SERIAL_PCI(vpci_dev);
-DeviceState *vdev = DEVICE(>vdev);
-DeviceState *proxy = DEVICE(vpci_dev);
-char *bus_name;
-
-if (vpci_dev->class_code != PCI_CLASS_COMMUNICATION_OTHER &&
-vpci_dev->class_code != PCI_CLASS_DISPLAY_OTHER && /* qemu 0.10 */
-vpci_dev->class_code != PCI_CLASS_OTHERS) {/* qemu-kvm  */
-vpci_dev->class_code = PCI_CLASS_COMMUNICATION_OTHER;
-}
-
-/* backwards-compatibility with machines that were created with
-   DEV_NVECTORS_UNSPECIFIED */
-if (vpci_dev->nvectors == DEV_NVECTORS_UNSPECIFIED) {
-vpci_dev->nvectors = dev->vdev.serial.max_virtserial_ports + 1;
-}
-
-/*
- * For command line compatibility, this sets the virtio-serial-device bus
- * name as before.
- */
-if (proxy->id) {
-bus_name = g_strdup_printf("%s.0", proxy->id);
-virtio_device_set_child_bus_name(VIRTIO_DEVICE(vdev), bus_name);
-g_free(bus_name);
-}
-
-qdev_set_parent_bus(vdev, BUS(_dev->bus));
-object_property_set_bool(OBJECT(vdev), true, "realized", errp);
-}
-
-static Property virtio_serial_pci_properties[] = {
-DEFINE_PROP_BIT("ioeventfd", VirtIOPCIProxy, flags,
-VIRTIO_PCI_FLAG_USE_IOEVENTFD_BIT, true),
-DEFINE_PROP_UINT32("vectors", VirtIOPCIProxy, nvectors, 2),
-DEFINE_PROP_UINT32("class", VirtIOPCIProxy, class_code, 0),
-DEFINE_PROP_END_OF_LIST(),
-};
-
-static void virtio_serial_pci_class_init(ObjectClass *klass, void *data)
-{
-DeviceClass *dc = DEVICE_CLASS(klass);
-VirtioPCIClass *k = VIRTIO_PCI_CLASS(klass);
-PCIDeviceClass *pcidev_k = PCI_DEVICE_CLASS(klass);
-k->realize = virtio_serial_pci_realize;
-set_bit(DEVICE_CATEGORY_INPUT, dc->categories);
-dc->props = virtio_serial_pci_properties;
-pcidev_k->vendor_id = PCI_VENDOR_ID_REDHAT_QUMRANET;
-pcidev_k->device_id = PCI_DEVICE_ID_VIRTIO_CONSOLE;
-pcidev_k->revision = VIRTIO_PCI_ABI_VERSION;
-pcidev_k->class_id = PCI_CLASS_COMMUNICATION_OTHER;
-}
-
-static void virtio_serial_pci_instance_init(Object *obj)
-{
-VirtIOSerialPCI *dev = VIRTIO_SERIAL_PCI(obj);
-
-virtio_instance_init_common(obj, >vdev, sizeof(dev->vdev),
-TYPE_VIRTIO_SERIAL);
-}
-
-static const TypeInfo virtio_serial_pci_info = {
-.name  = TYPE_VIRTIO_SERIAL_PCI,
-.parent= TYPE_VIRTIO_PCI,
-.instance_size = sizeof(VirtIOSerialPCI),
-.instance_init = virtio_serial_pci_instance_init,
-.class_init= virtio_serial_pci_class_init,
-};
-
 /* virtio-pci-bus */
 
 static void virtio_pci_bus_new(VirtioBusState *bus, size_t bus_size,
@@ -2014,7 +1940,6 @@ static void virtio_pci_register_types(void)
 {
 type_register_static(_pci_bus_info);
 type_register_static(_pci_info);
-type_register_static(_serial_pci_info);
 }
 
 type_init(virtio_pci_register_types)
diff --git a/hw/virtio/virtio-pci.h b/hw/virtio/virtio-pci.h
index ab0c7907e4..59016d553b 100644
--- a/hw/virtio/virtio-pci.h
+++ b/hw/virtio/virtio-pci.h
@@ -16,13 +16,11 @@
 #define QEMU_VIRTIO_PCI_H
 
 #include "hw/pci/msi.h"
-#include "hw/virtio/virtio-serial.h"
 #include "hw/virtio/virtio-bus.h"
 #include "hw/virtio/virtio-gpu.h"
 #include "hw/virtio/virtio-crypto.h"
 
 typedef struct VirtIOPCIProxy VirtIOPCIProxy;
-typedef struct VirtIOSerialPCI VirtIOSerialPCI;
 typedef struct VirtIOGPUPCI VirtIOGPUPCI;
 typedef struct VirtIOCryptoPCI 

[Qemu-devel] [PATCH v3 15/16] virtio: split virtio crypto bits rom virtio-pci.h

2018-12-13 Thread Juan Quintela
Reviewed-by: Laurent Vivier 
Signed-off-by: Juan Quintela 
---
 hw/virtio/virtio-crypto-pci.c | 14 ++
 hw/virtio/virtio-pci.h| 14 --
 2 files changed, 14 insertions(+), 14 deletions(-)

diff --git a/hw/virtio/virtio-crypto-pci.c b/hw/virtio/virtio-crypto-pci.c
index bf64996e48..1b242d3037 100644
--- a/hw/virtio/virtio-crypto-pci.c
+++ b/hw/virtio/virtio-crypto-pci.c
@@ -19,6 +19,20 @@
 #include "hw/virtio/virtio-crypto.h"
 #include "qapi/error.h"
 
+typedef struct VirtIOCryptoPCI VirtIOCryptoPCI;
+
+/*
+ * virtio-crypto-pci: This extends VirtioPCIProxy.
+ */
+#define TYPE_VIRTIO_CRYPTO_PCI "virtio-crypto-pci"
+#define VIRTIO_CRYPTO_PCI(obj) \
+OBJECT_CHECK(VirtIOCryptoPCI, (obj), TYPE_VIRTIO_CRYPTO_PCI)
+
+struct VirtIOCryptoPCI {
+VirtIOPCIProxy parent_obj;
+VirtIOCrypto vdev;
+};
+
 static Property virtio_crypto_pci_properties[] = {
 DEFINE_PROP_BIT("ioeventfd", VirtIOPCIProxy, flags,
 VIRTIO_PCI_FLAG_USE_IOEVENTFD_BIT, true),
diff --git a/hw/virtio/virtio-pci.h b/hw/virtio/virtio-pci.h
index 91981b39f9..bead9e5fa5 100644
--- a/hw/virtio/virtio-pci.h
+++ b/hw/virtio/virtio-pci.h
@@ -17,10 +17,8 @@
 
 #include "hw/pci/msi.h"
 #include "hw/virtio/virtio-bus.h"
-#include "hw/virtio/virtio-crypto.h"
 
 typedef struct VirtIOPCIProxy VirtIOPCIProxy;
-typedef struct VirtIOCryptoPCI VirtIOCryptoPCI;
 
 /* virtio-pci-bus */
 
@@ -182,18 +180,6 @@ static inline void 
virtio_pci_disable_modern(VirtIOPCIProxy *proxy)
  */
 #define TYPE_VIRTIO_INPUT_PCI "virtio-input-pci"
 
-/*
- * virtio-crypto-pci: This extends VirtioPCIProxy.
- */
-#define TYPE_VIRTIO_CRYPTO_PCI "virtio-crypto-pci"
-#define VIRTIO_CRYPTO_PCI(obj) \
-OBJECT_CHECK(VirtIOCryptoPCI, (obj), TYPE_VIRTIO_CRYPTO_PCI)
-
-struct VirtIOCryptoPCI {
-VirtIOPCIProxy parent_obj;
-VirtIOCrypto vdev;
-};
-
 /* Virtio ABI version, if we increment this, we break the guest driver. */
 #define VIRTIO_PCI_ABI_VERSION  0
 
-- 
2.19.2




[Qemu-devel] [PATCH v3 07/16] virtio: split vhost user blk bits from virtio-pci

2018-12-13 Thread Juan Quintela
Reviewed-by: Thomas Huth 
Reviewed-by: Laurent Vivier 
Signed-off-by: Juan Quintela 
---
 hw/virtio/Makefile.objs|   1 +
 hw/virtio/vhost-user-blk-pci.c | 101 +
 hw/virtio/virtio-pci.c |  60 
 hw/virtio/virtio-pci.h |  18 --
 4 files changed, 102 insertions(+), 78 deletions(-)
 create mode 100644 hw/virtio/vhost-user-blk-pci.c

diff --git a/hw/virtio/Makefile.objs b/hw/virtio/Makefile.objs
index 3e655fdce6..35b7698446 100644
--- a/hw/virtio/Makefile.objs
+++ b/hw/virtio/Makefile.objs
@@ -13,6 +13,7 @@ obj-$(CONFIG_LINUX) += vhost.o vhost-backend.o vhost-user.o
 obj-$(CONFIG_VHOST_VSOCK) += vhost-vsock.o
 ifeq ($(CONFIG_PCI),y)
 obj-$(CONFIG_VHOST_VSOCK) += vhost-vsock-pci.o
+obj-$(CONFIG_VHOST_USER_BLK) += vhost-user-blk-pci.o
 obj-$(CONFIG_VIRTIO_INPUT_HOST) += virtio-input-host-pci.o
 obj-$(CONFIG_VIRTIO_INPUT) += virtio-input-pci.o
 obj-$(CONFIG_VIRTIO_RNG) += virtio-rng-pci.o
diff --git a/hw/virtio/vhost-user-blk-pci.c b/hw/virtio/vhost-user-blk-pci.c
new file mode 100644
index 00..29ffcc4361
--- /dev/null
+++ b/hw/virtio/vhost-user-blk-pci.c
@@ -0,0 +1,101 @@
+/*
+ * Vhost user blk PCI Bindings
+ *
+ * Copyright(C) 2017 Intel Corporation.
+ *
+ * Authors:
+ *  Changpeng Liu 
+ *
+ * Largely based on the "vhost-user-scsi.c" and "vhost-scsi.c" implemented by:
+ * Felipe Franciosi 
+ * Stefan Hajnoczi 
+ * Nicholas Bellinger 
+ *
+ * This work is licensed under the terms of the GNU LGPL, version 2 or later.
+ * See the COPYING.LIB file in the top-level directory.
+ *
+ */
+
+#include "qemu/osdep.h"
+
+#include "standard-headers/linux/virtio_pci.h"
+#include "hw/virtio/virtio.h"
+#include "hw/virtio/vhost-user-blk.h"
+#include "hw/pci/pci.h"
+#include "qapi/error.h"
+#include "qemu/error-report.h"
+#include "virtio-pci.h"
+
+typedef struct VHostUserBlkPCI VHostUserBlkPCI;
+
+/*
+ * vhost-user-blk-pci: This extends VirtioPCIProxy.
+ */
+#define TYPE_VHOST_USER_BLK_PCI "vhost-user-blk-pci"
+#define VHOST_USER_BLK_PCI(obj) \
+OBJECT_CHECK(VHostUserBlkPCI, (obj), TYPE_VHOST_USER_BLK_PCI)
+
+struct VHostUserBlkPCI {
+VirtIOPCIProxy parent_obj;
+VHostUserBlk vdev;
+};
+
+static Property vhost_user_blk_pci_properties[] = {
+DEFINE_PROP_UINT32("class", VirtIOPCIProxy, class_code, 0),
+DEFINE_PROP_UINT32("vectors", VirtIOPCIProxy, nvectors,
+   DEV_NVECTORS_UNSPECIFIED),
+DEFINE_PROP_END_OF_LIST(),
+};
+
+static void vhost_user_blk_pci_realize(VirtIOPCIProxy *vpci_dev, Error **errp)
+{
+VHostUserBlkPCI *dev = VHOST_USER_BLK_PCI(vpci_dev);
+DeviceState *vdev = DEVICE(>vdev);
+
+if (vpci_dev->nvectors == DEV_NVECTORS_UNSPECIFIED) {
+vpci_dev->nvectors = dev->vdev.num_queues + 1;
+}
+
+qdev_set_parent_bus(vdev, BUS(_dev->bus));
+object_property_set_bool(OBJECT(vdev), true, "realized", errp);
+}
+
+static void vhost_user_blk_pci_class_init(ObjectClass *klass, void *data)
+{
+DeviceClass *dc = DEVICE_CLASS(klass);
+VirtioPCIClass *k = VIRTIO_PCI_CLASS(klass);
+PCIDeviceClass *pcidev_k = PCI_DEVICE_CLASS(klass);
+
+set_bit(DEVICE_CATEGORY_STORAGE, dc->categories);
+dc->props = vhost_user_blk_pci_properties;
+k->realize = vhost_user_blk_pci_realize;
+pcidev_k->vendor_id = PCI_VENDOR_ID_REDHAT_QUMRANET;
+pcidev_k->device_id = PCI_DEVICE_ID_VIRTIO_BLOCK;
+pcidev_k->revision = VIRTIO_PCI_ABI_VERSION;
+pcidev_k->class_id = PCI_CLASS_STORAGE_SCSI;
+}
+
+static void vhost_user_blk_pci_instance_init(Object *obj)
+{
+VHostUserBlkPCI *dev = VHOST_USER_BLK_PCI(obj);
+
+virtio_instance_init_common(obj, >vdev, sizeof(dev->vdev),
+TYPE_VHOST_USER_BLK);
+object_property_add_alias(obj, "bootindex", OBJECT(>vdev),
+  "bootindex", _abort);
+}
+
+static const TypeInfo vhost_user_blk_pci_info = {
+.name   = TYPE_VHOST_USER_BLK_PCI,
+.parent = TYPE_VIRTIO_PCI,
+.instance_size  = sizeof(VHostUserBlkPCI),
+.instance_init  = vhost_user_blk_pci_instance_init,
+.class_init = vhost_user_blk_pci_class_init,
+};
+
+static void vhost_user_blk_pci_register(void)
+{
+type_register_static(_user_blk_pci_info);
+}
+
+type_init(vhost_user_blk_pci_register)
diff --git a/hw/virtio/virtio-pci.c b/hw/virtio/virtio-pci.c
index bad9279f19..e9c562b1c0 100644
--- a/hw/virtio/virtio-pci.c
+++ b/hw/virtio/virtio-pci.c
@@ -1952,63 +1952,6 @@ static const TypeInfo virtio_blk_pci_info = {
 .class_init= virtio_blk_pci_class_init,
 };
 
-#if defined(CONFIG_VHOST_USER) && defined(CONFIG_LINUX)
-/* vhost-user-blk */
-
-static Property vhost_user_blk_pci_properties[] = {
-DEFINE_PROP_UINT32("class", VirtIOPCIProxy, class_code, 0),
-DEFINE_PROP_UINT32("vectors", VirtIOPCIProxy, nvectors,
-   DEV_NVECTORS_UNSPECIFIED),
-DEFINE_PROP_END_OF_LIST(),
-};
-
-static void vhost_user_blk_pci_realize(VirtIOPCIProxy *vpci_dev, 

[Qemu-devel] [PATCH v3 11/16] virtio: split virtio blk bits rom virtio-pci

2018-12-13 Thread Juan Quintela
Reviewed-by: Thomas Huth 
Reviewed-by: Laurent Vivier 
Signed-off-by: Juan Quintela 
---
 hw/virtio/Makefile.objs|  1 +
 hw/virtio/virtio-blk-pci.c | 97 ++
 hw/virtio/virtio-pci.c | 59 ---
 hw/virtio/virtio-pci.h | 14 --
 tests/Makefile.include |  4 +-
 5 files changed, 100 insertions(+), 75 deletions(-)
 create mode 100644 hw/virtio/virtio-blk-pci.c

diff --git a/hw/virtio/Makefile.objs b/hw/virtio/Makefile.objs
index 012b6f74a7..557ad06231 100644
--- a/hw/virtio/Makefile.objs
+++ b/hw/virtio/Makefile.objs
@@ -22,6 +22,7 @@ obj-$(CONFIG_VIRTIO_RNG) += virtio-rng-pci.o
 obj-$(CONFIG_VIRTIO_BALLOON) += virtio-balloon-pci.o
 obj-$(CONFIG_VIRTIO_9P) += virtio-9p-pci.o
 obj-$(CONFIG_VIRTIO_SCSI) += virtio-scsi-pci.o
+obj-$(CONFIG_VIRTIO_BLK) += virtio-blk-pci.o
 endif
 endif
 
diff --git a/hw/virtio/virtio-blk-pci.c b/hw/virtio/virtio-blk-pci.c
new file mode 100644
index 00..c1c41ad3f0
--- /dev/null
+++ b/hw/virtio/virtio-blk-pci.c
@@ -0,0 +1,97 @@
+/*
+ * Virtio blk PCI Bindings
+ *
+ * Copyright IBM, Corp. 2007
+ * Copyright (c) 2009 CodeSourcery
+ *
+ * Authors:
+ *  Anthony Liguori   
+ *  Paul Brook
+ *
+ * This work is licensed under the terms of the GNU GPL, version 2.  See
+ * the COPYING file in the top-level directory.
+ *
+ * Contributions after 2012-01-13 are licensed under the terms of the
+ * GNU GPL, version 2 or (at your option) any later version.
+ */
+
+#include "qemu/osdep.h"
+
+#include "hw/virtio/virtio-blk.h"
+#include "virtio-pci.h"
+#include "qapi/error.h"
+
+typedef struct VirtIOBlkPCI VirtIOBlkPCI;
+
+/*
+ * virtio-blk-pci: This extends VirtioPCIProxy.
+ */
+#define TYPE_VIRTIO_BLK_PCI "virtio-blk-pci"
+#define VIRTIO_BLK_PCI(obj) \
+OBJECT_CHECK(VirtIOBlkPCI, (obj), TYPE_VIRTIO_BLK_PCI)
+
+struct VirtIOBlkPCI {
+VirtIOPCIProxy parent_obj;
+VirtIOBlock vdev;
+};
+
+static Property virtio_blk_pci_properties[] = {
+DEFINE_PROP_UINT32("class", VirtIOPCIProxy, class_code, 0),
+DEFINE_PROP_BIT("ioeventfd", VirtIOPCIProxy, flags,
+VIRTIO_PCI_FLAG_USE_IOEVENTFD_BIT, true),
+DEFINE_PROP_UINT32("vectors", VirtIOPCIProxy, nvectors,
+   DEV_NVECTORS_UNSPECIFIED),
+DEFINE_PROP_END_OF_LIST(),
+};
+
+static void virtio_blk_pci_realize(VirtIOPCIProxy *vpci_dev, Error **errp)
+{
+VirtIOBlkPCI *dev = VIRTIO_BLK_PCI(vpci_dev);
+DeviceState *vdev = DEVICE(>vdev);
+
+if (vpci_dev->nvectors == DEV_NVECTORS_UNSPECIFIED) {
+vpci_dev->nvectors = dev->vdev.conf.num_queues + 1;
+}
+
+qdev_set_parent_bus(vdev, BUS(_dev->bus));
+object_property_set_bool(OBJECT(vdev), true, "realized", errp);
+}
+
+static void virtio_blk_pci_class_init(ObjectClass *klass, void *data)
+{
+DeviceClass *dc = DEVICE_CLASS(klass);
+VirtioPCIClass *k = VIRTIO_PCI_CLASS(klass);
+PCIDeviceClass *pcidev_k = PCI_DEVICE_CLASS(klass);
+
+set_bit(DEVICE_CATEGORY_STORAGE, dc->categories);
+dc->props = virtio_blk_pci_properties;
+k->realize = virtio_blk_pci_realize;
+pcidev_k->vendor_id = PCI_VENDOR_ID_REDHAT_QUMRANET;
+pcidev_k->device_id = PCI_DEVICE_ID_VIRTIO_BLOCK;
+pcidev_k->revision = VIRTIO_PCI_ABI_VERSION;
+pcidev_k->class_id = PCI_CLASS_STORAGE_SCSI;
+}
+
+static void virtio_blk_pci_instance_init(Object *obj)
+{
+VirtIOBlkPCI *dev = VIRTIO_BLK_PCI(obj);
+
+virtio_instance_init_common(obj, >vdev, sizeof(dev->vdev),
+TYPE_VIRTIO_BLK);
+object_property_add_alias(obj, "bootindex", OBJECT(>vdev),
+  "bootindex", _abort);
+}
+
+static const TypeInfo virtio_blk_pci_info = {
+.name  = TYPE_VIRTIO_BLK_PCI,
+.parent= TYPE_VIRTIO_PCI,
+.instance_size = sizeof(VirtIOBlkPCI),
+.instance_init = virtio_blk_pci_instance_init,
+.class_init= virtio_blk_pci_class_init,
+};
+static void virtio_blk_pci_register(void)
+{
+type_register_static(_blk_pci_info);
+}
+
+type_init(virtio_blk_pci_register)
diff --git a/hw/virtio/virtio-pci.c b/hw/virtio/virtio-pci.c
index debd764523..4fe71a56c8 100644
--- a/hw/virtio/virtio-pci.c
+++ b/hw/virtio/virtio-pci.c
@@ -19,7 +19,6 @@
 
 #include "standard-headers/linux/virtio_pci.h"
 #include "hw/virtio/virtio.h"
-#include "hw/virtio/virtio-blk.h"
 #include "hw/virtio/virtio-net.h"
 #include "hw/virtio/virtio-serial.h"
 #include "hw/pci/pci.h"
@@ -1894,63 +1893,6 @@ static const TypeInfo virtio_pci_info = {
 },
 };
 
-/* virtio-blk-pci */
-
-static Property virtio_blk_pci_properties[] = {
-DEFINE_PROP_UINT32("class", VirtIOPCIProxy, class_code, 0),
-DEFINE_PROP_BIT("ioeventfd", VirtIOPCIProxy, flags,
-VIRTIO_PCI_FLAG_USE_IOEVENTFD_BIT, true),
-DEFINE_PROP_UINT32("vectors", VirtIOPCIProxy, nvectors,
-   DEV_NVECTORS_UNSPECIFIED),
-DEFINE_PROP_END_OF_LIST(),
-};
-
-static void virtio_blk_pci_realize(VirtIOPCIProxy 

[Qemu-devel] [PATCH v3 12/16] virtio: split virtio net bits rom virtio-pci

2018-12-13 Thread Juan Quintela
Reviewed-by: Thomas Huth 
Reviewed-by: Laurent Vivier 
Signed-off-by: Juan Quintela 
---
 hw/virtio/Makefile.objs|  1 +
 hw/virtio/virtio-net-pci.c | 96 ++
 hw/virtio/virtio-pci.c | 57 --
 hw/virtio/virtio-pci.h | 14 --
 tests/Makefile.include |  2 +-
 5 files changed, 98 insertions(+), 72 deletions(-)
 create mode 100644 hw/virtio/virtio-net-pci.c

diff --git a/hw/virtio/Makefile.objs b/hw/virtio/Makefile.objs
index 557ad06231..4c31acb017 100644
--- a/hw/virtio/Makefile.objs
+++ b/hw/virtio/Makefile.objs
@@ -23,6 +23,7 @@ obj-$(CONFIG_VIRTIO_BALLOON) += virtio-balloon-pci.o
 obj-$(CONFIG_VIRTIO_9P) += virtio-9p-pci.o
 obj-$(CONFIG_VIRTIO_SCSI) += virtio-scsi-pci.o
 obj-$(CONFIG_VIRTIO_BLK) += virtio-blk-pci.o
+obj-$(CONFIG_VIRTIO_NET) += virtio-net-pci.o
 endif
 endif
 
diff --git a/hw/virtio/virtio-net-pci.c b/hw/virtio/virtio-net-pci.c
new file mode 100644
index 00..0b676f078d
--- /dev/null
+++ b/hw/virtio/virtio-net-pci.c
@@ -0,0 +1,96 @@
+/*
+ * Virtio net PCI Bindings
+ *
+ * Copyright IBM, Corp. 2007
+ * Copyright (c) 2009 CodeSourcery
+ *
+ * Authors:
+ *  Anthony Liguori   
+ *  Paul Brook
+ *
+ * This work is licensed under the terms of the GNU GPL, version 2.  See
+ * the COPYING file in the top-level directory.
+ *
+ * Contributions after 2012-01-13 are licensed under the terms of the
+ * GNU GPL, version 2 or (at your option) any later version.
+ */
+
+#include "qemu/osdep.h"
+
+#include "hw/virtio/virtio-net.h"
+#include "virtio-pci.h"
+#include "qapi/error.h"
+
+typedef struct VirtIONetPCI VirtIONetPCI;
+
+/*
+ * virtio-net-pci: This extends VirtioPCIProxy.
+ */
+#define TYPE_VIRTIO_NET_PCI "virtio-net-pci"
+#define VIRTIO_NET_PCI(obj) \
+OBJECT_CHECK(VirtIONetPCI, (obj), TYPE_VIRTIO_NET_PCI)
+
+struct VirtIONetPCI {
+VirtIOPCIProxy parent_obj;
+VirtIONet vdev;
+};
+
+static Property virtio_net_properties[] = {
+DEFINE_PROP_BIT("ioeventfd", VirtIOPCIProxy, flags,
+VIRTIO_PCI_FLAG_USE_IOEVENTFD_BIT, true),
+DEFINE_PROP_UINT32("vectors", VirtIOPCIProxy, nvectors, 3),
+DEFINE_PROP_END_OF_LIST(),
+};
+
+static void virtio_net_pci_realize(VirtIOPCIProxy *vpci_dev, Error **errp)
+{
+DeviceState *qdev = DEVICE(vpci_dev);
+VirtIONetPCI *dev = VIRTIO_NET_PCI(vpci_dev);
+DeviceState *vdev = DEVICE(>vdev);
+
+virtio_net_set_netclient_name(>vdev, qdev->id,
+  object_get_typename(OBJECT(qdev)));
+qdev_set_parent_bus(vdev, BUS(_dev->bus));
+object_property_set_bool(OBJECT(vdev), true, "realized", errp);
+}
+
+static void virtio_net_pci_class_init(ObjectClass *klass, void *data)
+{
+DeviceClass *dc = DEVICE_CLASS(klass);
+PCIDeviceClass *k = PCI_DEVICE_CLASS(klass);
+VirtioPCIClass *vpciklass = VIRTIO_PCI_CLASS(klass);
+
+k->romfile = "efi-virtio.rom";
+k->vendor_id = PCI_VENDOR_ID_REDHAT_QUMRANET;
+k->device_id = PCI_DEVICE_ID_VIRTIO_NET;
+k->revision = VIRTIO_PCI_ABI_VERSION;
+k->class_id = PCI_CLASS_NETWORK_ETHERNET;
+set_bit(DEVICE_CATEGORY_NETWORK, dc->categories);
+dc->props = virtio_net_properties;
+vpciklass->realize = virtio_net_pci_realize;
+}
+
+static void virtio_net_pci_instance_init(Object *obj)
+{
+VirtIONetPCI *dev = VIRTIO_NET_PCI(obj);
+
+virtio_instance_init_common(obj, >vdev, sizeof(dev->vdev),
+TYPE_VIRTIO_NET);
+object_property_add_alias(obj, "bootindex", OBJECT(>vdev),
+  "bootindex", _abort);
+}
+
+static const TypeInfo virtio_net_pci_info = {
+.name  = TYPE_VIRTIO_NET_PCI,
+.parent= TYPE_VIRTIO_PCI,
+.instance_size = sizeof(VirtIONetPCI),
+.instance_init = virtio_net_pci_instance_init,
+.class_init= virtio_net_pci_class_init,
+};
+
+static void virtio_net_pci_register(void)
+{
+type_register_static(_net_pci_info);
+}
+
+type_init(virtio_net_pci_register)
diff --git a/hw/virtio/virtio-pci.c b/hw/virtio/virtio-pci.c
index 4fe71a56c8..cb03bfa597 100644
--- a/hw/virtio/virtio-pci.c
+++ b/hw/virtio/virtio-pci.c
@@ -19,7 +19,6 @@
 
 #include "standard-headers/linux/virtio_pci.h"
 #include "hw/virtio/virtio.h"
-#include "hw/virtio/virtio-net.h"
 #include "hw/virtio/virtio-serial.h"
 #include "hw/pci/pci.h"
 #include "qapi/error.h"
@@ -1966,61 +1965,6 @@ static const TypeInfo virtio_serial_pci_info = {
 .class_init= virtio_serial_pci_class_init,
 };
 
-/* virtio-net-pci */
-
-static Property virtio_net_properties[] = {
-DEFINE_PROP_BIT("ioeventfd", VirtIOPCIProxy, flags,
-VIRTIO_PCI_FLAG_USE_IOEVENTFD_BIT, true),
-DEFINE_PROP_UINT32("vectors", VirtIOPCIProxy, nvectors, 3),
-DEFINE_PROP_END_OF_LIST(),
-};
-
-static void virtio_net_pci_realize(VirtIOPCIProxy *vpci_dev, Error **errp)
-{
-DeviceState *qdev = DEVICE(vpci_dev);
-VirtIONetPCI *dev = VIRTIO_NET_PCI(vpci_dev);
-DeviceState *vdev = 

[Qemu-devel] [PATCH v3 09/16] virtio: split vhost scsi bits from virtio-pci

2018-12-13 Thread Juan Quintela
Reviewed-by: Laurent Vivier 
Signed-off-by: Juan Quintela 
---
 hw/virtio/Makefile.objs|  1 +
 hw/virtio/vhost-scsi-pci.c | 95 ++
 hw/virtio/virtio-pci.c | 59 ---
 hw/virtio/virtio-pci.h | 19 
 4 files changed, 96 insertions(+), 78 deletions(-)
 create mode 100644 hw/virtio/vhost-scsi-pci.c

diff --git a/hw/virtio/Makefile.objs b/hw/virtio/Makefile.objs
index f851a6f2b5..0a56946c1a 100644
--- a/hw/virtio/Makefile.objs
+++ b/hw/virtio/Makefile.objs
@@ -15,6 +15,7 @@ ifeq ($(CONFIG_PCI),y)
 obj-$(CONFIG_VHOST_VSOCK) += vhost-vsock-pci.o
 obj-$(CONFIG_VHOST_USER_BLK) += vhost-user-blk-pci.o
 obj-$(CONFIG_VHOST_USER_SCSI) += vhost-user-scsi-pci.o
+obj-$(CONFIG_VHOST_SCSI) += vhost-scsi-pci.o
 obj-$(CONFIG_VIRTIO_INPUT_HOST) += virtio-input-host-pci.o
 obj-$(CONFIG_VIRTIO_INPUT) += virtio-input-pci.o
 obj-$(CONFIG_VIRTIO_RNG) += virtio-rng-pci.o
diff --git a/hw/virtio/vhost-scsi-pci.c b/hw/virtio/vhost-scsi-pci.c
new file mode 100644
index 00..2be2c567ea
--- /dev/null
+++ b/hw/virtio/vhost-scsi-pci.c
@@ -0,0 +1,95 @@
+/*
+ * Vhost scsi PCI bindings
+ *
+ * Copyright IBM, Corp. 2011
+ *
+ * Authors:
+ *  Stefan Hajnoczi   
+ *
+ * Changes for QEMU mainline + tcm_vhost kernel upstream:
+ *  Nicholas Bellinger 
+ *
+ * This work is licensed under the terms of the GNU LGPL, version 2 or later.
+ * See the COPYING.LIB file in the top-level directory.
+ *
+ */
+
+#include "qemu/osdep.h"
+
+#include "standard-headers/linux/virtio_pci.h"
+#include "hw/virtio/vhost-scsi.h"
+#include "qapi/error.h"
+#include "virtio-pci.h"
+
+typedef struct VHostSCSIPCI VHostSCSIPCI;
+
+/*
+ * vhost-scsi-pci: This extends VirtioPCIProxy.
+ */
+#define TYPE_VHOST_SCSI_PCI "vhost-scsi-pci"
+#define VHOST_SCSI_PCI(obj) \
+OBJECT_CHECK(VHostSCSIPCI, (obj), TYPE_VHOST_SCSI_PCI)
+
+struct VHostSCSIPCI {
+VirtIOPCIProxy parent_obj;
+VHostSCSI vdev;
+};
+
+static Property vhost_scsi_pci_properties[] = {
+DEFINE_PROP_UINT32("vectors", VirtIOPCIProxy, nvectors,
+   DEV_NVECTORS_UNSPECIFIED),
+DEFINE_PROP_END_OF_LIST(),
+};
+
+static void vhost_scsi_pci_realize(VirtIOPCIProxy *vpci_dev, Error **errp)
+{
+VHostSCSIPCI *dev = VHOST_SCSI_PCI(vpci_dev);
+DeviceState *vdev = DEVICE(>vdev);
+VirtIOSCSICommon *vs = VIRTIO_SCSI_COMMON(vdev);
+
+if (vpci_dev->nvectors == DEV_NVECTORS_UNSPECIFIED) {
+vpci_dev->nvectors = vs->conf.num_queues + 3;
+}
+
+qdev_set_parent_bus(vdev, BUS(_dev->bus));
+object_property_set_bool(OBJECT(vdev), true, "realized", errp);
+}
+
+static void vhost_scsi_pci_class_init(ObjectClass *klass, void *data)
+{
+DeviceClass *dc = DEVICE_CLASS(klass);
+VirtioPCIClass *k = VIRTIO_PCI_CLASS(klass);
+PCIDeviceClass *pcidev_k = PCI_DEVICE_CLASS(klass);
+k->realize = vhost_scsi_pci_realize;
+set_bit(DEVICE_CATEGORY_STORAGE, dc->categories);
+dc->props = vhost_scsi_pci_properties;
+pcidev_k->vendor_id = PCI_VENDOR_ID_REDHAT_QUMRANET;
+pcidev_k->device_id = PCI_DEVICE_ID_VIRTIO_SCSI;
+pcidev_k->revision = 0x00;
+pcidev_k->class_id = PCI_CLASS_STORAGE_SCSI;
+}
+
+static void vhost_scsi_pci_instance_init(Object *obj)
+{
+VHostSCSIPCI *dev = VHOST_SCSI_PCI(obj);
+
+virtio_instance_init_common(obj, >vdev, sizeof(dev->vdev),
+TYPE_VHOST_SCSI);
+object_property_add_alias(obj, "bootindex", OBJECT(>vdev),
+  "bootindex", _abort);
+}
+
+static const TypeInfo vhost_scsi_pci_info = {
+.name  = TYPE_VHOST_SCSI_PCI,
+.parent= TYPE_VIRTIO_PCI,
+.instance_size = sizeof(VHostSCSIPCI),
+.instance_init = vhost_scsi_pci_instance_init,
+.class_init= vhost_scsi_pci_class_init,
+};
+
+static void vhost_scsi_pci_register(void)
+{
+type_register_static(_scsi_pci_info);
+}
+
+type_init(vhost_scsi_pci_register)
diff --git a/hw/virtio/virtio-pci.c b/hw/virtio/virtio-pci.c
index 7c99d9385a..6c42074d37 100644
--- a/hw/virtio/virtio-pci.c
+++ b/hw/virtio/virtio-pci.c
@@ -2019,62 +2019,6 @@ static const TypeInfo virtio_scsi_pci_info = {
 .class_init= virtio_scsi_pci_class_init,
 };
 
-/* vhost-scsi-pci */
-
-#ifdef CONFIG_VHOST_SCSI
-static Property vhost_scsi_pci_properties[] = {
-DEFINE_PROP_UINT32("vectors", VirtIOPCIProxy, nvectors,
-   DEV_NVECTORS_UNSPECIFIED),
-DEFINE_PROP_END_OF_LIST(),
-};
-
-static void vhost_scsi_pci_realize(VirtIOPCIProxy *vpci_dev, Error **errp)
-{
-VHostSCSIPCI *dev = VHOST_SCSI_PCI(vpci_dev);
-DeviceState *vdev = DEVICE(>vdev);
-VirtIOSCSICommon *vs = VIRTIO_SCSI_COMMON(vdev);
-
-if (vpci_dev->nvectors == DEV_NVECTORS_UNSPECIFIED) {
-vpci_dev->nvectors = vs->conf.num_queues + 3;
-}
-
-qdev_set_parent_bus(vdev, BUS(_dev->bus));
-object_property_set_bool(OBJECT(vdev), true, "realized", errp);
-}
-
-static void vhost_scsi_pci_class_init(ObjectClass *klass, 

[Qemu-devel] [PATCH v3 16/16] virtio: virtio 9p really requires CONFIG_VIRTFS to work

2018-12-13 Thread Juan Quintela
Signed-off-by: Juan Quintela 
---
 default-configs/virtio.mak | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/default-configs/virtio.mak b/default-configs/virtio.mak
index 5ae4a61018..ecb4420e74 100644
--- a/default-configs/virtio.mak
+++ b/default-configs/virtio.mak
@@ -1,7 +1,7 @@
 CONFIG_VHOST_USER_SCSI=$(call land,$(CONFIG_VHOST_USER),$(CONFIG_LINUX))
 CONFIG_VHOST_USER_BLK=$(call land,$(CONFIG_VHOST_USER),$(CONFIG_LINUX))
 CONFIG_VIRTIO=y
-CONFIG_VIRTIO_9P=y
+CONFIG_VIRTIO_9P=$(CONFIG_VIRTFS)
 CONFIG_VIRTIO_BALLOON=y
 CONFIG_VIRTIO_BLK=y
 CONFIG_VIRTIO_CRYPTO=y
-- 
2.19.2




[Qemu-devel] [PATCH v3 10/16] virtio: split virtio scsi bits from virtio-pci

2018-12-13 Thread Juan Quintela
Notice that we can't still run tests with it disabled.  Both cdrom-test and
drive_del-test use virtio-scsi without checking if it is enabled.

Reviewed-by: Thomas Huth 
Reviewed-by: Laurent Vivier 
Signed-off-by: Juan Quintela 
---
 hw/virtio/Makefile.objs |   1 +
 hw/virtio/virtio-pci.c  |  69 ---
 hw/virtio/virtio-pci.h  |  14 -
 hw/virtio/virtio-scsi-pci.c | 106 
 tests/Makefile.include  |   2 +-
 5 files changed, 108 insertions(+), 84 deletions(-)
 create mode 100644 hw/virtio/virtio-scsi-pci.c

diff --git a/hw/virtio/Makefile.objs b/hw/virtio/Makefile.objs
index 0a56946c1a..012b6f74a7 100644
--- a/hw/virtio/Makefile.objs
+++ b/hw/virtio/Makefile.objs
@@ -21,6 +21,7 @@ obj-$(CONFIG_VIRTIO_INPUT) += virtio-input-pci.o
 obj-$(CONFIG_VIRTIO_RNG) += virtio-rng-pci.o
 obj-$(CONFIG_VIRTIO_BALLOON) += virtio-balloon-pci.o
 obj-$(CONFIG_VIRTIO_9P) += virtio-9p-pci.o
+obj-$(CONFIG_VIRTIO_SCSI) += virtio-scsi-pci.o
 endif
 endif
 
diff --git a/hw/virtio/virtio-pci.c b/hw/virtio/virtio-pci.c
index 6c42074d37..debd764523 100644
--- a/hw/virtio/virtio-pci.c
+++ b/hw/virtio/virtio-pci.c
@@ -22,7 +22,6 @@
 #include "hw/virtio/virtio-blk.h"
 #include "hw/virtio/virtio-net.h"
 #include "hw/virtio/virtio-serial.h"
-#include "hw/virtio/virtio-scsi.h"
 #include "hw/pci/pci.h"
 #include "qapi/error.h"
 #include "qemu/error-report.h"
@@ -1952,73 +1951,6 @@ static const TypeInfo virtio_blk_pci_info = {
 .class_init= virtio_blk_pci_class_init,
 };
 
-/* virtio-scsi-pci */
-
-static Property virtio_scsi_pci_properties[] = {
-DEFINE_PROP_BIT("ioeventfd", VirtIOPCIProxy, flags,
-VIRTIO_PCI_FLAG_USE_IOEVENTFD_BIT, true),
-DEFINE_PROP_UINT32("vectors", VirtIOPCIProxy, nvectors,
-   DEV_NVECTORS_UNSPECIFIED),
-DEFINE_PROP_END_OF_LIST(),
-};
-
-static void virtio_scsi_pci_realize(VirtIOPCIProxy *vpci_dev, Error **errp)
-{
-VirtIOSCSIPCI *dev = VIRTIO_SCSI_PCI(vpci_dev);
-DeviceState *vdev = DEVICE(>vdev);
-VirtIOSCSICommon *vs = VIRTIO_SCSI_COMMON(vdev);
-DeviceState *proxy = DEVICE(vpci_dev);
-char *bus_name;
-
-if (vpci_dev->nvectors == DEV_NVECTORS_UNSPECIFIED) {
-vpci_dev->nvectors = vs->conf.num_queues + 3;
-}
-
-/*
- * For command line compatibility, this sets the virtio-scsi-device bus
- * name as before.
- */
-if (proxy->id) {
-bus_name = g_strdup_printf("%s.0", proxy->id);
-virtio_device_set_child_bus_name(VIRTIO_DEVICE(vdev), bus_name);
-g_free(bus_name);
-}
-
-qdev_set_parent_bus(vdev, BUS(_dev->bus));
-object_property_set_bool(OBJECT(vdev), true, "realized", errp);
-}
-
-static void virtio_scsi_pci_class_init(ObjectClass *klass, void *data)
-{
-DeviceClass *dc = DEVICE_CLASS(klass);
-VirtioPCIClass *k = VIRTIO_PCI_CLASS(klass);
-PCIDeviceClass *pcidev_k = PCI_DEVICE_CLASS(klass);
-
-k->realize = virtio_scsi_pci_realize;
-set_bit(DEVICE_CATEGORY_STORAGE, dc->categories);
-dc->props = virtio_scsi_pci_properties;
-pcidev_k->vendor_id = PCI_VENDOR_ID_REDHAT_QUMRANET;
-pcidev_k->device_id = PCI_DEVICE_ID_VIRTIO_SCSI;
-pcidev_k->revision = 0x00;
-pcidev_k->class_id = PCI_CLASS_STORAGE_SCSI;
-}
-
-static void virtio_scsi_pci_instance_init(Object *obj)
-{
-VirtIOSCSIPCI *dev = VIRTIO_SCSI_PCI(obj);
-
-virtio_instance_init_common(obj, >vdev, sizeof(dev->vdev),
-TYPE_VIRTIO_SCSI);
-}
-
-static const TypeInfo virtio_scsi_pci_info = {
-.name  = TYPE_VIRTIO_SCSI_PCI,
-.parent= TYPE_VIRTIO_PCI,
-.instance_size = sizeof(VirtIOSCSIPCI),
-.instance_init = virtio_scsi_pci_instance_init,
-.class_init= virtio_scsi_pci_class_init,
-};
-
 /* virtio-serial-pci */
 
 static void virtio_serial_pci_realize(VirtIOPCIProxy *vpci_dev, Error **errp)
@@ -2197,7 +2129,6 @@ static void virtio_pci_register_types(void)
 type_register_static(_pci_bus_info);
 type_register_static(_pci_info);
 type_register_static(_blk_pci_info);
-type_register_static(_scsi_pci_info);
 type_register_static(_serial_pci_info);
 type_register_static(_net_pci_info);
 }
diff --git a/hw/virtio/virtio-pci.h b/hw/virtio/virtio-pci.h
index eb7cdbad25..5e13d87110 100644
--- a/hw/virtio/virtio-pci.h
+++ b/hw/virtio/virtio-pci.h
@@ -19,14 +19,12 @@
 #include "hw/virtio/virtio-blk.h"
 #include "hw/virtio/virtio-net.h"
 #include "hw/virtio/virtio-serial.h"
-#include "hw/virtio/virtio-scsi.h"
 #include "hw/virtio/virtio-bus.h"
 #include "hw/virtio/virtio-gpu.h"
 #include "hw/virtio/virtio-crypto.h"
 
 typedef struct VirtIOPCIProxy VirtIOPCIProxy;
 typedef struct VirtIOBlkPCI VirtIOBlkPCI;
-typedef struct VirtIOSCSIPCI VirtIOSCSIPCI;
 typedef struct VirtIOSerialPCI VirtIOSerialPCI;
 typedef struct VirtIONetPCI VirtIONetPCI;
 typedef struct VirtIOGPUPCI VirtIOGPUPCI;
@@ -187,18 +185,6 @@ static inline void 

[Qemu-devel] [PATCH v3 04/16] virtio: split virtio rng bits from virtio-pci

2018-12-13 Thread Juan Quintela
Reviewed-by: Laurent Vivier 
Signed-off-by: Juan Quintela 

---

Remove the "contributions after" clause.  This is based on

commit 59ccd20a9ac719cff82180429458728f03ec612f
Author: KONRAD Frederic 
Date:   Wed Apr 24 10:07:56 2013 +0200

Fix duplicated test entry (lvivier)
---
 hw/virtio/Makefile.objs|  1 +
 hw/virtio/virtio-pci.c | 52 ---
 hw/virtio/virtio-pci.h | 14 ---
 hw/virtio/virtio-rng-pci.c | 86 ++
 tests/Makefile.include |  2 +-
 5 files changed, 88 insertions(+), 67 deletions(-)
 create mode 100644 hw/virtio/virtio-rng-pci.c

diff --git a/hw/virtio/Makefile.objs b/hw/virtio/Makefile.objs
index c61bcd106b..032ba2ff0e 100644
--- a/hw/virtio/Makefile.objs
+++ b/hw/virtio/Makefile.objs
@@ -15,6 +15,7 @@ ifeq ($(CONFIG_PCI),y)
 obj-$(CONFIG_VHOST_VSOCK) += vhost-vsock-pci.o
 obj-$(CONFIG_VIRTIO_INPUT_HOST) += virtio-input-host-pci.o
 obj-$(CONFIG_VIRTIO_INPUT) += virtio-input-pci.o
+obj-$(CONFIG_VIRTIO_RNG) += virtio-rng-pci.o
 endif
 endif
 
diff --git a/hw/virtio/virtio-pci.c b/hw/virtio/virtio-pci.c
index bb1d2db032..433ece611d 100644
--- a/hw/virtio/virtio-pci.c
+++ b/hw/virtio/virtio-pci.c
@@ -2421,57 +2421,6 @@ static const TypeInfo virtio_net_pci_info = {
 .class_init= virtio_net_pci_class_init,
 };
 
-/* virtio-rng-pci */
-
-static void virtio_rng_pci_realize(VirtIOPCIProxy *vpci_dev, Error **errp)
-{
-VirtIORngPCI *vrng = VIRTIO_RNG_PCI(vpci_dev);
-DeviceState *vdev = DEVICE(>vdev);
-Error *err = NULL;
-
-qdev_set_parent_bus(vdev, BUS(_dev->bus));
-object_property_set_bool(OBJECT(vdev), true, "realized", );
-if (err) {
-error_propagate(errp, err);
-return;
-}
-
-object_property_set_link(OBJECT(vrng),
- OBJECT(vrng->vdev.conf.rng), "rng",
- NULL);
-}
-
-static void virtio_rng_pci_class_init(ObjectClass *klass, void *data)
-{
-DeviceClass *dc = DEVICE_CLASS(klass);
-VirtioPCIClass *k = VIRTIO_PCI_CLASS(klass);
-PCIDeviceClass *pcidev_k = PCI_DEVICE_CLASS(klass);
-
-k->realize = virtio_rng_pci_realize;
-set_bit(DEVICE_CATEGORY_MISC, dc->categories);
-
-pcidev_k->vendor_id = PCI_VENDOR_ID_REDHAT_QUMRANET;
-pcidev_k->device_id = PCI_DEVICE_ID_VIRTIO_RNG;
-pcidev_k->revision = VIRTIO_PCI_ABI_VERSION;
-pcidev_k->class_id = PCI_CLASS_OTHERS;
-}
-
-static void virtio_rng_initfn(Object *obj)
-{
-VirtIORngPCI *dev = VIRTIO_RNG_PCI(obj);
-
-virtio_instance_init_common(obj, >vdev, sizeof(dev->vdev),
-TYPE_VIRTIO_RNG);
-}
-
-static const TypeInfo virtio_rng_pci_info = {
-.name  = TYPE_VIRTIO_RNG_PCI,
-.parent= TYPE_VIRTIO_PCI,
-.instance_size = sizeof(VirtIORngPCI),
-.instance_init = virtio_rng_initfn,
-.class_init= virtio_rng_pci_class_init,
-};
-
 /* virtio-pci-bus */
 
 static void virtio_pci_bus_new(VirtioBusState *bus, size_t bus_size,
@@ -2519,7 +2468,6 @@ static const TypeInfo virtio_pci_bus_info = {
 
 static void virtio_pci_register_types(void)
 {
-type_register_static(_rng_pci_info);
 type_register_static(_pci_bus_info);
 type_register_static(_pci_info);
 #ifdef CONFIG_VIRTFS
diff --git a/hw/virtio/virtio-pci.h b/hw/virtio/virtio-pci.h
index 32d5f0fbff..2415eb6a4d 100644
--- a/hw/virtio/virtio-pci.h
+++ b/hw/virtio/virtio-pci.h
@@ -18,7 +18,6 @@
 #include "hw/pci/msi.h"
 #include "hw/virtio/virtio-blk.h"
 #include "hw/virtio/virtio-net.h"
-#include "hw/virtio/virtio-rng.h"
 #include "hw/virtio/virtio-serial.h"
 #include "hw/virtio/virtio-scsi.h"
 #include "hw/virtio/virtio-balloon.h"
@@ -46,7 +45,6 @@ typedef struct VirtIONetPCI VirtIONetPCI;
 typedef struct VHostSCSIPCI VHostSCSIPCI;
 typedef struct VHostUserSCSIPCI VHostUserSCSIPCI;
 typedef struct VHostUserBlkPCI VHostUserBlkPCI;
-typedef struct VirtIORngPCI VirtIORngPCI;
 typedef struct VirtIOGPUPCI VirtIOGPUPCI;
 typedef struct VirtIOCryptoPCI VirtIOCryptoPCI;
 
@@ -319,18 +317,6 @@ typedef struct V9fsPCIState {
 
 #endif
 
-/*
- * virtio-rng-pci: This extends VirtioPCIProxy.
- */
-#define TYPE_VIRTIO_RNG_PCI "virtio-rng-pci"
-#define VIRTIO_RNG_PCI(obj) \
-OBJECT_CHECK(VirtIORngPCI, (obj), TYPE_VIRTIO_RNG_PCI)
-
-struct VirtIORngPCI {
-VirtIOPCIProxy parent_obj;
-VirtIORNG vdev;
-};
-
 /*
  * virtio-input-pci: This extends VirtioPCIProxy.
  */
diff --git a/hw/virtio/virtio-rng-pci.c b/hw/virtio/virtio-rng-pci.c
new file mode 100644
index 00..60688fbea9
--- /dev/null
+++ b/hw/virtio/virtio-rng-pci.c
@@ -0,0 +1,86 @@
+/*
+ * Virtio rng PCI Bindings
+ *
+ * Copyright 2012 Red Hat, Inc.
+ * Copyright 2012 Amit Shah 
+ *
+ * This work is licensed under the terms of the GNU GPL, version 2 or
+ * (at your option) any later version.  See the COPYING file in the
+ * top-level directory.
+ */
+
+#include "qemu/osdep.h"
+
+#include "virtio-pci.h"
+#include "hw/virtio/virtio-rng.h"
+#include "qapi/error.h"
+
+typedef 

[Qemu-devel] [PATCH v3 14/16] virtio: split virtio gpu bits rom virtio-pci.h

2018-12-13 Thread Juan Quintela
Reviewed-by: Laurent Vivier 
Signed-off-by: Juan Quintela 
---
 hw/display/virtio-gpu-pci.c | 14 ++
 hw/display/virtio-vga.c |  1 +
 hw/virtio/virtio-pci.h  | 14 --
 3 files changed, 15 insertions(+), 14 deletions(-)

diff --git a/hw/display/virtio-gpu-pci.c b/hw/display/virtio-gpu-pci.c
index cece4aa495..fa126cf3e4 100644
--- a/hw/display/virtio-gpu-pci.c
+++ b/hw/display/virtio-gpu-pci.c
@@ -19,6 +19,20 @@
 #include "hw/virtio/virtio-pci.h"
 #include "hw/virtio/virtio-gpu.h"
 
+typedef struct VirtIOGPUPCI VirtIOGPUPCI;
+
+/*
+ * virtio-gpu-pci: This extends VirtioPCIProxy.
+ */
+#define TYPE_VIRTIO_GPU_PCI "virtio-gpu-pci"
+#define VIRTIO_GPU_PCI(obj) \
+OBJECT_CHECK(VirtIOGPUPCI, (obj), TYPE_VIRTIO_GPU_PCI)
+
+struct VirtIOGPUPCI {
+VirtIOPCIProxy parent_obj;
+VirtIOGPU vdev;
+};
+
 static Property virtio_gpu_pci_properties[] = {
 DEFINE_VIRTIO_GPU_PCI_PROPERTIES(VirtIOPCIProxy),
 DEFINE_PROP_END_OF_LIST(),
diff --git a/hw/display/virtio-vga.c b/hw/display/virtio-vga.c
index ab2e369b28..797994cf00 100644
--- a/hw/display/virtio-vga.c
+++ b/hw/display/virtio-vga.c
@@ -3,6 +3,7 @@
 #include "hw/pci/pci.h"
 #include "vga_int.h"
 #include "hw/virtio/virtio-pci.h"
+#include "hw/virtio/virtio-gpu.h"
 #include "qapi/error.h"
 
 /*
diff --git a/hw/virtio/virtio-pci.h b/hw/virtio/virtio-pci.h
index 59016d553b..91981b39f9 100644
--- a/hw/virtio/virtio-pci.h
+++ b/hw/virtio/virtio-pci.h
@@ -17,11 +17,9 @@
 
 #include "hw/pci/msi.h"
 #include "hw/virtio/virtio-bus.h"
-#include "hw/virtio/virtio-gpu.h"
 #include "hw/virtio/virtio-crypto.h"
 
 typedef struct VirtIOPCIProxy VirtIOPCIProxy;
-typedef struct VirtIOGPUPCI VirtIOGPUPCI;
 typedef struct VirtIOCryptoPCI VirtIOCryptoPCI;
 
 /* virtio-pci-bus */
@@ -184,18 +182,6 @@ static inline void 
virtio_pci_disable_modern(VirtIOPCIProxy *proxy)
  */
 #define TYPE_VIRTIO_INPUT_PCI "virtio-input-pci"
 
-/*
- * virtio-gpu-pci: This extends VirtioPCIProxy.
- */
-#define TYPE_VIRTIO_GPU_PCI "virtio-gpu-pci"
-#define VIRTIO_GPU_PCI(obj) \
-OBJECT_CHECK(VirtIOGPUPCI, (obj), TYPE_VIRTIO_GPU_PCI)
-
-struct VirtIOGPUPCI {
-VirtIOPCIProxy parent_obj;
-VirtIOGPU vdev;
-};
-
 /*
  * virtio-crypto-pci: This extends VirtioPCIProxy.
  */
-- 
2.19.2




[Qemu-devel] [PATCH v3 05/16] virtio: split virtio balloon bits from virtio-pci

2018-12-13 Thread Juan Quintela
Reviewed-by: Thomas Huth 
Reviewed-by: Laurent Vivier 
Signed-off-by: Juan Quintela 
---
 hw/virtio/Makefile.objs|  1 +
 hw/virtio/virtio-balloon-pci.c | 94 ++
 hw/virtio/virtio-pci.c | 58 -
 hw/virtio/virtio-pci.h | 14 -
 tests/Makefile.include |  2 +-
 5 files changed, 96 insertions(+), 73 deletions(-)
 create mode 100644 hw/virtio/virtio-balloon-pci.c

diff --git a/hw/virtio/Makefile.objs b/hw/virtio/Makefile.objs
index 032ba2ff0e..9e33104ce6 100644
--- a/hw/virtio/Makefile.objs
+++ b/hw/virtio/Makefile.objs
@@ -16,6 +16,7 @@ obj-$(CONFIG_VHOST_VSOCK) += vhost-vsock-pci.o
 obj-$(CONFIG_VIRTIO_INPUT_HOST) += virtio-input-host-pci.o
 obj-$(CONFIG_VIRTIO_INPUT) += virtio-input-pci.o
 obj-$(CONFIG_VIRTIO_RNG) += virtio-rng-pci.o
+obj-$(CONFIG_VIRTIO_BALLOON) += virtio-balloon-pci.o
 endif
 endif
 
diff --git a/hw/virtio/virtio-balloon-pci.c b/hw/virtio/virtio-balloon-pci.c
new file mode 100644
index 00..2e9d92990b
--- /dev/null
+++ b/hw/virtio/virtio-balloon-pci.c
@@ -0,0 +1,94 @@
+/*
+ * Virtio balloon PCI Bindings
+ *
+ * Copyright IBM, Corp. 2007
+ * Copyright (c) 2009 CodeSourcery
+ *
+ * Authors:
+ *  Anthony Liguori   
+ *  Paul Brook
+ *
+ * Contributions after 2012-01-13 are licensed under the terms of the
+ * GNU GPL, version 2 or (at your option) any later version.
+ */
+
+#include "qemu/osdep.h"
+
+#include "virtio-pci.h"
+#include "hw/virtio/virtio-balloon.h"
+#include "qapi/error.h"
+
+typedef struct VirtIOBalloonPCI VirtIOBalloonPCI;
+
+/*
+ * virtio-balloon-pci: This extends VirtioPCIProxy.
+ */
+#define TYPE_VIRTIO_BALLOON_PCI "virtio-balloon-pci"
+#define VIRTIO_BALLOON_PCI(obj) \
+OBJECT_CHECK(VirtIOBalloonPCI, (obj), TYPE_VIRTIO_BALLOON_PCI)
+
+struct VirtIOBalloonPCI {
+VirtIOPCIProxy parent_obj;
+VirtIOBalloon vdev;
+};
+
+static Property virtio_balloon_pci_properties[] = {
+DEFINE_PROP_UINT32("class", VirtIOPCIProxy, class_code, 0),
+DEFINE_PROP_END_OF_LIST(),
+};
+
+static void virtio_balloon_pci_realize(VirtIOPCIProxy *vpci_dev, Error **errp)
+{
+VirtIOBalloonPCI *dev = VIRTIO_BALLOON_PCI(vpci_dev);
+DeviceState *vdev = DEVICE(>vdev);
+
+if (vpci_dev->class_code != PCI_CLASS_OTHERS &&
+vpci_dev->class_code != PCI_CLASS_MEMORY_RAM) { /* qemu < 1.1 */
+vpci_dev->class_code = PCI_CLASS_OTHERS;
+}
+
+qdev_set_parent_bus(vdev, BUS(_dev->bus));
+object_property_set_bool(OBJECT(vdev), true, "realized", errp);
+}
+
+static void virtio_balloon_pci_class_init(ObjectClass *klass, void *data)
+{
+DeviceClass *dc = DEVICE_CLASS(klass);
+VirtioPCIClass *k = VIRTIO_PCI_CLASS(klass);
+PCIDeviceClass *pcidev_k = PCI_DEVICE_CLASS(klass);
+k->realize = virtio_balloon_pci_realize;
+set_bit(DEVICE_CATEGORY_MISC, dc->categories);
+dc->props = virtio_balloon_pci_properties;
+pcidev_k->vendor_id = PCI_VENDOR_ID_REDHAT_QUMRANET;
+pcidev_k->device_id = PCI_DEVICE_ID_VIRTIO_BALLOON;
+pcidev_k->revision = VIRTIO_PCI_ABI_VERSION;
+pcidev_k->class_id = PCI_CLASS_OTHERS;
+}
+
+static void virtio_balloon_pci_instance_init(Object *obj)
+{
+VirtIOBalloonPCI *dev = VIRTIO_BALLOON_PCI(obj);
+
+virtio_instance_init_common(obj, >vdev, sizeof(dev->vdev),
+TYPE_VIRTIO_BALLOON);
+object_property_add_alias(obj, "guest-stats", OBJECT(>vdev),
+  "guest-stats", _abort);
+object_property_add_alias(obj, "guest-stats-polling-interval",
+  OBJECT(>vdev),
+  "guest-stats-polling-interval", _abort);
+}
+
+static const TypeInfo virtio_balloon_pci_info = {
+.name  = TYPE_VIRTIO_BALLOON_PCI,
+.parent= TYPE_VIRTIO_PCI,
+.instance_size = sizeof(VirtIOBalloonPCI),
+.instance_init = virtio_balloon_pci_instance_init,
+.class_init= virtio_balloon_pci_class_init,
+};
+
+static void virtio_balloon_pci_register(void)
+{
+type_register_static(_balloon_pci_info);
+}
+
+type_init(virtio_balloon_pci_register)
diff --git a/hw/virtio/virtio-pci.c b/hw/virtio/virtio-pci.c
index 433ece611d..855a7fdd40 100644
--- a/hw/virtio/virtio-pci.c
+++ b/hw/virtio/virtio-pci.c
@@ -23,7 +23,6 @@
 #include "hw/virtio/virtio-net.h"
 #include "hw/virtio/virtio-serial.h"
 #include "hw/virtio/virtio-scsi.h"
-#include "hw/virtio/virtio-balloon.h"
 #include "hw/pci/pci.h"
 #include "qapi/error.h"
 #include "qemu/error-report.h"
@@ -2237,62 +2236,6 @@ static const TypeInfo vhost_user_scsi_pci_info = {
 };
 #endif
 
-/* virtio-balloon-pci */
-
-static Property virtio_balloon_pci_properties[] = {
-DEFINE_PROP_UINT32("class", VirtIOPCIProxy, class_code, 0),
-DEFINE_PROP_END_OF_LIST(),
-};
-
-static void virtio_balloon_pci_realize(VirtIOPCIProxy *vpci_dev, Error **errp)
-{
-VirtIOBalloonPCI *dev = VIRTIO_BALLOON_PCI(vpci_dev);
-DeviceState *vdev = DEVICE(>vdev);
-
-if 

[Qemu-devel] [PATCH v3 08/16] virtio: split vhost user scsi bits from virtio-pci

2018-12-13 Thread Juan Quintela
Reviewed-by: Laurent Vivier 
Signed-off-by: Juan Quintela 
---
 hw/virtio/Makefile.objs |   1 +
 hw/virtio/vhost-user-scsi-pci.c | 101 
 hw/virtio/virtio-pci.c  |  58 --
 hw/virtio/virtio-pci.h  |  11 
 4 files changed, 102 insertions(+), 69 deletions(-)
 create mode 100644 hw/virtio/vhost-user-scsi-pci.c

diff --git a/hw/virtio/Makefile.objs b/hw/virtio/Makefile.objs
index 35b7698446..f851a6f2b5 100644
--- a/hw/virtio/Makefile.objs
+++ b/hw/virtio/Makefile.objs
@@ -14,6 +14,7 @@ obj-$(CONFIG_VHOST_VSOCK) += vhost-vsock.o
 ifeq ($(CONFIG_PCI),y)
 obj-$(CONFIG_VHOST_VSOCK) += vhost-vsock-pci.o
 obj-$(CONFIG_VHOST_USER_BLK) += vhost-user-blk-pci.o
+obj-$(CONFIG_VHOST_USER_SCSI) += vhost-user-scsi-pci.o
 obj-$(CONFIG_VIRTIO_INPUT_HOST) += virtio-input-host-pci.o
 obj-$(CONFIG_VIRTIO_INPUT) += virtio-input-pci.o
 obj-$(CONFIG_VIRTIO_RNG) += virtio-rng-pci.o
diff --git a/hw/virtio/vhost-user-scsi-pci.c b/hw/virtio/vhost-user-scsi-pci.c
new file mode 100644
index 00..5baec9c356
--- /dev/null
+++ b/hw/virtio/vhost-user-scsi-pci.c
@@ -0,0 +1,101 @@
+/*
+ * Vhost user scsi PCI Bindings
+ *
+ * Copyright (c) 2016 Nutanix Inc. All rights reserved.
+ *
+ * Author:
+ *  Felipe Franciosi 
+ *
+ * This work is largely based on the "vhost-scsi" implementation by:
+ *  Stefan Hajnoczi
+ *  Nicholas Bellinger 
+ *
+ * This work is licensed under the terms of the GNU LGPL, version 2 or later.
+ * See the COPYING.LIB file in the top-level directory.
+ *
+ */
+
+#include "qemu/osdep.h"
+
+#include "standard-headers/linux/virtio_pci.h"
+#include "hw/virtio/vhost-user-scsi.h"
+#include "hw/virtio/virtio.h"
+#include "hw/virtio/virtio-scsi.h"
+#include "hw/pci/pci.h"
+#include "qapi/error.h"
+#include "qemu/error-report.h"
+#include "hw/pci/msi.h"
+#include "hw/pci/msix.h"
+#include "hw/loader.h"
+#include "sysemu/kvm.h"
+#include "virtio-pci.h"
+
+typedef struct VHostUserSCSIPCI VHostUserSCSIPCI;
+
+#define TYPE_VHOST_USER_SCSI_PCI "vhost-user-scsi-pci"
+#define VHOST_USER_SCSI_PCI(obj) \
+OBJECT_CHECK(VHostUserSCSIPCI, (obj), TYPE_VHOST_USER_SCSI_PCI)
+
+struct VHostUserSCSIPCI {
+VirtIOPCIProxy parent_obj;
+VHostUserSCSI vdev;
+};
+
+static Property vhost_user_scsi_pci_properties[] = {
+DEFINE_PROP_UINT32("vectors", VirtIOPCIProxy, nvectors,
+   DEV_NVECTORS_UNSPECIFIED),
+DEFINE_PROP_END_OF_LIST(),
+};
+
+static void vhost_user_scsi_pci_realize(VirtIOPCIProxy *vpci_dev, Error **errp)
+{
+VHostUserSCSIPCI *dev = VHOST_USER_SCSI_PCI(vpci_dev);
+DeviceState *vdev = DEVICE(>vdev);
+VirtIOSCSICommon *vs = VIRTIO_SCSI_COMMON(vdev);
+
+if (vpci_dev->nvectors == DEV_NVECTORS_UNSPECIFIED) {
+vpci_dev->nvectors = vs->conf.num_queues + 3;
+}
+
+qdev_set_parent_bus(vdev, BUS(_dev->bus));
+object_property_set_bool(OBJECT(vdev), true, "realized", errp);
+}
+
+static void vhost_user_scsi_pci_class_init(ObjectClass *klass, void *data)
+{
+DeviceClass *dc = DEVICE_CLASS(klass);
+VirtioPCIClass *k = VIRTIO_PCI_CLASS(klass);
+PCIDeviceClass *pcidev_k = PCI_DEVICE_CLASS(klass);
+k->realize = vhost_user_scsi_pci_realize;
+set_bit(DEVICE_CATEGORY_STORAGE, dc->categories);
+dc->props = vhost_user_scsi_pci_properties;
+pcidev_k->vendor_id = PCI_VENDOR_ID_REDHAT_QUMRANET;
+pcidev_k->device_id = PCI_DEVICE_ID_VIRTIO_SCSI;
+pcidev_k->revision = 0x00;
+pcidev_k->class_id = PCI_CLASS_STORAGE_SCSI;
+}
+
+static void vhost_user_scsi_pci_instance_init(Object *obj)
+{
+VHostUserSCSIPCI *dev = VHOST_USER_SCSI_PCI(obj);
+
+virtio_instance_init_common(obj, >vdev, sizeof(dev->vdev),
+TYPE_VHOST_USER_SCSI);
+object_property_add_alias(obj, "bootindex", OBJECT(>vdev),
+  "bootindex", _abort);
+}
+
+static const TypeInfo vhost_user_scsi_pci_info = {
+.name  = TYPE_VHOST_USER_SCSI_PCI,
+.parent= TYPE_VIRTIO_PCI,
+.instance_size = sizeof(VHostUserSCSIPCI),
+.instance_init = vhost_user_scsi_pci_instance_init,
+.class_init= vhost_user_scsi_pci_class_init,
+};
+
+static void vhost_user_scsi_pci_register(void)
+{
+type_register_static(_user_scsi_pci_info);
+}
+
+type_init(vhost_user_scsi_pci_register)
diff --git a/hw/virtio/virtio-pci.c b/hw/virtio/virtio-pci.c
index e9c562b1c0..7c99d9385a 100644
--- a/hw/virtio/virtio-pci.c
+++ b/hw/virtio/virtio-pci.c
@@ -2075,61 +2075,6 @@ static const TypeInfo vhost_scsi_pci_info = {
 };
 #endif
 
-#if defined(CONFIG_VHOST_USER) && defined(CONFIG_LINUX)
-/* vhost-user-scsi-pci */
-static Property vhost_user_scsi_pci_properties[] = {
-DEFINE_PROP_UINT32("vectors", VirtIOPCIProxy, nvectors,
-   DEV_NVECTORS_UNSPECIFIED),
-DEFINE_PROP_END_OF_LIST(),
-};
-
-static void vhost_user_scsi_pci_realize(VirtIOPCIProxy *vpci_dev, Error **errp)
-{
-VHostUserSCSIPCI *dev = 

[Qemu-devel] [PATCH v3 06/16] virtio: split virtio 9p bits from virtio-pci

2018-12-13 Thread Juan Quintela
Reviewed-by: Laurent Vivier 
Signed-off-by: Juan Quintela 

---

Also disable virtio9p test (lvivier)
---
 hw/virtio/Makefile.objs   |  1 +
 hw/virtio/virtio-9p-pci.c | 86 +++
 hw/virtio/virtio-pci.c| 52 ---
 hw/virtio/virtio-pci.h| 20 -
 tests/Makefile.include|  2 +-
 5 files changed, 88 insertions(+), 73 deletions(-)
 create mode 100644 hw/virtio/virtio-9p-pci.c

diff --git a/hw/virtio/Makefile.objs b/hw/virtio/Makefile.objs
index 9e33104ce6..3e655fdce6 100644
--- a/hw/virtio/Makefile.objs
+++ b/hw/virtio/Makefile.objs
@@ -17,6 +17,7 @@ obj-$(CONFIG_VIRTIO_INPUT_HOST) += virtio-input-host-pci.o
 obj-$(CONFIG_VIRTIO_INPUT) += virtio-input-pci.o
 obj-$(CONFIG_VIRTIO_RNG) += virtio-rng-pci.o
 obj-$(CONFIG_VIRTIO_BALLOON) += virtio-balloon-pci.o
+obj-$(CONFIG_VIRTIO_9P) += virtio-9p-pci.o
 endif
 endif
 
diff --git a/hw/virtio/virtio-9p-pci.c b/hw/virtio/virtio-9p-pci.c
new file mode 100644
index 00..74c6ca2ddb
--- /dev/null
+++ b/hw/virtio/virtio-9p-pci.c
@@ -0,0 +1,86 @@
+/*
+ * Virtio 9p PCI Bindings
+ *
+ * Copyright IBM, Corp. 2010
+ *
+ * Authors:
+ *  Anthony Liguori   
+ *
+ * This work is licensed under the terms of the GNU GPL, version 2.  See
+ * the COPYING file in the top-level directory.
+ *
+ * Contributions after 2012-01-13 are licensed under the terms of the
+ * GNU GPL, version 2 or (at your option) any later version.
+ */
+
+#include "qemu/osdep.h"
+
+#include "virtio-pci.h"
+#include "hw/9pfs/virtio-9p.h"
+
+/*
+ * virtio-9p-pci: This extends VirtioPCIProxy.
+ */
+
+#define TYPE_VIRTIO_9P_PCI "virtio-9p-pci"
+#define VIRTIO_9P_PCI(obj) \
+OBJECT_CHECK(V9fsPCIState, (obj), TYPE_VIRTIO_9P_PCI)
+
+typedef struct V9fsPCIState {
+VirtIOPCIProxy parent_obj;
+V9fsVirtioState vdev;
+} V9fsPCIState;
+
+static void virtio_9p_pci_realize(VirtIOPCIProxy *vpci_dev, Error **errp)
+{
+V9fsPCIState *dev = VIRTIO_9P_PCI(vpci_dev);
+DeviceState *vdev = DEVICE(>vdev);
+
+qdev_set_parent_bus(vdev, BUS(_dev->bus));
+object_property_set_bool(OBJECT(vdev), true, "realized", errp);
+}
+
+static Property virtio_9p_pci_properties[] = {
+DEFINE_PROP_BIT("ioeventfd", VirtIOPCIProxy, flags,
+VIRTIO_PCI_FLAG_USE_IOEVENTFD_BIT, true),
+DEFINE_PROP_UINT32("vectors", VirtIOPCIProxy, nvectors, 2),
+DEFINE_PROP_END_OF_LIST(),
+};
+
+static void virtio_9p_pci_class_init(ObjectClass *klass, void *data)
+{
+DeviceClass *dc = DEVICE_CLASS(klass);
+PCIDeviceClass *pcidev_k = PCI_DEVICE_CLASS(klass);
+VirtioPCIClass *k = VIRTIO_PCI_CLASS(klass);
+
+k->realize = virtio_9p_pci_realize;
+pcidev_k->vendor_id = PCI_VENDOR_ID_REDHAT_QUMRANET;
+pcidev_k->device_id = PCI_DEVICE_ID_VIRTIO_9P;
+pcidev_k->revision = VIRTIO_PCI_ABI_VERSION;
+pcidev_k->class_id = 0x2;
+set_bit(DEVICE_CATEGORY_STORAGE, dc->categories);
+dc->props = virtio_9p_pci_properties;
+}
+
+static void virtio_9p_pci_instance_init(Object *obj)
+{
+V9fsPCIState *dev = VIRTIO_9P_PCI(obj);
+
+virtio_instance_init_common(obj, >vdev, sizeof(dev->vdev),
+TYPE_VIRTIO_9P);
+}
+
+static const TypeInfo virtio_9p_pci_info = {
+.name  = TYPE_VIRTIO_9P_PCI,
+.parent= TYPE_VIRTIO_PCI,
+.instance_size = sizeof(V9fsPCIState),
+.instance_init = virtio_9p_pci_instance_init,
+.class_init= virtio_9p_pci_class_init,
+};
+
+static void virtio_9p_pci_register(void)
+{
+type_register_static(_9p_pci_info);
+}
+
+type_init(virtio_9p_pci_register)
diff --git a/hw/virtio/virtio-pci.c b/hw/virtio/virtio-pci.c
index 855a7fdd40..bad9279f19 100644
--- a/hw/virtio/virtio-pci.c
+++ b/hw/virtio/virtio-pci.c
@@ -1077,55 +1077,6 @@ static void virtio_pci_vmstate_change(DeviceState *d, 
bool running)
 }
 }
 
-#ifdef CONFIG_VIRTFS
-static void virtio_9p_pci_realize(VirtIOPCIProxy *vpci_dev, Error **errp)
-{
-V9fsPCIState *dev = VIRTIO_9P_PCI(vpci_dev);
-DeviceState *vdev = DEVICE(>vdev);
-
-qdev_set_parent_bus(vdev, BUS(_dev->bus));
-object_property_set_bool(OBJECT(vdev), true, "realized", errp);
-}
-
-static Property virtio_9p_pci_properties[] = {
-DEFINE_PROP_BIT("ioeventfd", VirtIOPCIProxy, flags,
-VIRTIO_PCI_FLAG_USE_IOEVENTFD_BIT, true),
-DEFINE_PROP_UINT32("vectors", VirtIOPCIProxy, nvectors, 2),
-DEFINE_PROP_END_OF_LIST(),
-};
-
-static void virtio_9p_pci_class_init(ObjectClass *klass, void *data)
-{
-DeviceClass *dc = DEVICE_CLASS(klass);
-PCIDeviceClass *pcidev_k = PCI_DEVICE_CLASS(klass);
-VirtioPCIClass *k = VIRTIO_PCI_CLASS(klass);
-
-k->realize = virtio_9p_pci_realize;
-pcidev_k->vendor_id = PCI_VENDOR_ID_REDHAT_QUMRANET;
-pcidev_k->device_id = PCI_DEVICE_ID_VIRTIO_9P;
-pcidev_k->revision = VIRTIO_PCI_ABI_VERSION;
-pcidev_k->class_id = 0x2;
-set_bit(DEVICE_CATEGORY_STORAGE, dc->categories);
-dc->props = virtio_9p_pci_properties;
-}
-

[Qemu-devel] [PATCH v3 00/16] Virtio devices split from virtio-pci

2018-12-13 Thread Juan Quintela
Hi

v3:
- rebase to master
- only compile them if CONFIG_PCI is set (thomas)

Please review.

Later, Juan.

V2:

- Rebase on top of master

Please review.

Later, Juan.

[v1]
>From previous verision (in the middle of make check tests):
- split also the bits of virtio-pci.h (mst suggestion)
- add gpu, crypt and gpg bits
- more cleanups
- fix all the copyrights (the ones not changed have been there
  foverever)
- be consistent with naming, vhost-* or virtio-*

Please review, Juan.

Juan Quintela (16):
  virtio: split vhost vsock bits from virtio-pci
  virtio: split virtio input host bits from virtio-pci
  virtio: split virtio input bits from virtio-pci
  virtio: split virtio rng bits from virtio-pci
  virtio: split virtio balloon bits from virtio-pci
  virtio: split virtio 9p bits from virtio-pci
  virtio: split vhost user blk bits from virtio-pci
  virtio: split vhost user scsi bits from virtio-pci
  virtio: split vhost scsi bits from virtio-pci
  virtio: split virtio scsi bits from virtio-pci
  virtio: split virtio blk bits rom virtio-pci
  virtio: split virtio net bits rom virtio-pci
  virtio: split virtio serial bits rom virtio-pci
  virtio: split virtio gpu bits rom virtio-pci.h
  virtio: split virtio crypto bits rom virtio-pci.h
  virtio: virtio 9p really requires CONFIG_VIRTFS to work

 default-configs/virtio.mak|   3 +-
 hw/display/virtio-gpu-pci.c   |  14 +
 hw/display/virtio-vga.c   |   1 +
 hw/virtio/Makefile.objs   |  15 +
 hw/virtio/vhost-scsi-pci.c|  95 
 hw/virtio/vhost-user-blk-pci.c| 101 
 hw/virtio/vhost-user-scsi-pci.c   | 101 
 hw/virtio/vhost-vsock-pci.c   |  82 
 hw/virtio/virtio-9p-pci.c |  86 
 hw/virtio/virtio-balloon-pci.c|  94 
 hw/virtio/virtio-blk-pci.c|  97 
 hw/virtio/virtio-crypto-pci.c |  14 +
 hw/virtio/virtio-input-host-pci.c |  45 ++
 hw/virtio/virtio-input-pci.c  | 154 ++
 hw/virtio/virtio-net-pci.c|  96 
 hw/virtio/virtio-pci.c| 783 --
 hw/virtio/virtio-pci.h| 234 -
 hw/virtio/virtio-rng-pci.c|  86 
 hw/virtio/virtio-scsi-pci.c   | 106 
 hw/virtio/virtio-serial-pci.c | 112 +
 tests/Makefile.include|  20 +-
 21 files changed, 1311 insertions(+), 1028 deletions(-)
 create mode 100644 hw/virtio/vhost-scsi-pci.c
 create mode 100644 hw/virtio/vhost-user-blk-pci.c
 create mode 100644 hw/virtio/vhost-user-scsi-pci.c
 create mode 100644 hw/virtio/vhost-vsock-pci.c
 create mode 100644 hw/virtio/virtio-9p-pci.c
 create mode 100644 hw/virtio/virtio-balloon-pci.c
 create mode 100644 hw/virtio/virtio-blk-pci.c
 create mode 100644 hw/virtio/virtio-input-host-pci.c
 create mode 100644 hw/virtio/virtio-input-pci.c
 create mode 100644 hw/virtio/virtio-net-pci.c
 create mode 100644 hw/virtio/virtio-rng-pci.c
 create mode 100644 hw/virtio/virtio-scsi-pci.c
 create mode 100644 hw/virtio/virtio-serial-pci.c

-- 
2.19.2




[Qemu-devel] [PATCH v3 02/16] virtio: split virtio input host bits from virtio-pci

2018-12-13 Thread Juan Quintela
For consistency with other devices, rename
virtio_host_{initfn,pci_info} to virtio_input_host_{initfn,info}.

Reviewed-by: Laurent Vivier 
Signed-off-by: Juan Quintela 
---
 default-configs/virtio.mak|  1 +
 hw/virtio/Makefile.objs   |  1 +
 hw/virtio/virtio-input-host-pci.c | 45 +++
 hw/virtio/virtio-pci.c| 20 --
 hw/virtio/virtio-pci.h| 14 --
 5 files changed, 47 insertions(+), 34 deletions(-)
 create mode 100644 hw/virtio/virtio-input-host-pci.c

diff --git a/default-configs/virtio.mak b/default-configs/virtio.mak
index 1304849018..5ae4a61018 100644
--- a/default-configs/virtio.mak
+++ b/default-configs/virtio.mak
@@ -12,3 +12,4 @@ CONFIG_VIRTIO_RNG=y
 CONFIG_SCSI=y
 CONFIG_VIRTIO_SCSI=y
 CONFIG_VIRTIO_SERIAL=y
+CONFIG_VIRTIO_INPUT_HOST=$(CONFIG_LINUX)
diff --git a/hw/virtio/Makefile.objs b/hw/virtio/Makefile.objs
index 39884c5f7b..a6b850ed09 100644
--- a/hw/virtio/Makefile.objs
+++ b/hw/virtio/Makefile.objs
@@ -13,6 +13,7 @@ obj-$(CONFIG_LINUX) += vhost.o vhost-backend.o vhost-user.o
 obj-$(CONFIG_VHOST_VSOCK) += vhost-vsock.o
 ifeq ($(CONFIG_PCI),y)
 obj-$(CONFIG_VHOST_VSOCK) += vhost-vsock-pci.o
+obj-$(CONFIG_VIRTIO_INPUT_HOST) += virtio-input-host-pci.o
 endif
 endif
 
diff --git a/hw/virtio/virtio-input-host-pci.c 
b/hw/virtio/virtio-input-host-pci.c
new file mode 100644
index 00..4048e2f01e
--- /dev/null
+++ b/hw/virtio/virtio-input-host-pci.c
@@ -0,0 +1,45 @@
+/*
+ * Virtio input host PCI Bindings
+ *
+ * This work is licensed under the terms of the GNU GPL, version 2 or
+ * (at your option) any later version.  See the COPYING file in the
+ * top-level directory.
+ */
+
+#include "qemu/osdep.h"
+
+#include "virtio-pci.h"
+#include "hw/virtio/virtio-input.h"
+
+typedef struct VirtIOInputHostPCI VirtIOInputHostPCI;
+
+#define TYPE_VIRTIO_INPUT_HOST_PCI "virtio-input-host-pci"
+#define VIRTIO_INPUT_HOST_PCI(obj) \
+OBJECT_CHECK(VirtIOInputHostPCI, (obj), TYPE_VIRTIO_INPUT_HOST_PCI)
+
+struct VirtIOInputHostPCI {
+VirtIOPCIProxy parent_obj;
+VirtIOInputHost vdev;
+};
+
+static void virtio_input_host_initfn(Object *obj)
+{
+VirtIOInputHostPCI *dev = VIRTIO_INPUT_HOST_PCI(obj);
+
+virtio_instance_init_common(obj, >vdev, sizeof(dev->vdev),
+TYPE_VIRTIO_INPUT_HOST);
+}
+
+static const TypeInfo virtio_input_host_pci_info = {
+.name  = TYPE_VIRTIO_INPUT_HOST_PCI,
+.parent= TYPE_VIRTIO_INPUT_PCI,
+.instance_size = sizeof(VirtIOInputHostPCI),
+.instance_init = virtio_input_host_initfn,
+};
+
+static void virtio_input_host_pci_register(void)
+{
+type_register_static(_input_host_pci_info);
+}
+
+type_init(virtio_input_host_pci_register)
diff --git a/hw/virtio/virtio-pci.c b/hw/virtio/virtio-pci.c
index 56b39a3699..97e40da9e8 100644
--- a/hw/virtio/virtio-pci.c
+++ b/hw/virtio/virtio-pci.c
@@ -2580,23 +2580,6 @@ static const TypeInfo virtio_tablet_pci_info = {
 .instance_init = virtio_tablet_initfn,
 };
 
-#ifdef CONFIG_LINUX
-static void virtio_host_initfn(Object *obj)
-{
-VirtIOInputHostPCI *dev = VIRTIO_INPUT_HOST_PCI(obj);
-
-virtio_instance_init_common(obj, >vdev, sizeof(dev->vdev),
-TYPE_VIRTIO_INPUT_HOST);
-}
-
-static const TypeInfo virtio_host_pci_info = {
-.name  = TYPE_VIRTIO_INPUT_HOST_PCI,
-.parent= TYPE_VIRTIO_INPUT_PCI,
-.instance_size = sizeof(VirtIOInputHostPCI),
-.instance_init = virtio_host_initfn,
-};
-#endif
-
 /* virtio-pci-bus */
 
 static void virtio_pci_bus_new(VirtioBusState *bus, size_t bus_size,
@@ -2650,9 +2633,6 @@ static void virtio_pci_register_types(void)
 type_register_static(_keyboard_pci_info);
 type_register_static(_mouse_pci_info);
 type_register_static(_tablet_pci_info);
-#ifdef CONFIG_LINUX
-type_register_static(_host_pci_info);
-#endif
 type_register_static(_pci_bus_info);
 type_register_static(_pci_info);
 #ifdef CONFIG_VIRTFS
diff --git a/hw/virtio/virtio-pci.h b/hw/virtio/virtio-pci.h
index 25d225bc7d..cf4cbecfab 100644
--- a/hw/virtio/virtio-pci.h
+++ b/hw/virtio/virtio-pci.h
@@ -50,7 +50,6 @@ typedef struct VHostUserBlkPCI VHostUserBlkPCI;
 typedef struct VirtIORngPCI VirtIORngPCI;
 typedef struct VirtIOInputPCI VirtIOInputPCI;
 typedef struct VirtIOInputHIDPCI VirtIOInputHIDPCI;
-typedef struct VirtIOInputHostPCI VirtIOInputHostPCI;
 typedef struct VirtIOGPUPCI VirtIOGPUPCI;
 typedef struct VirtIOCryptoPCI VirtIOCryptoPCI;
 
@@ -359,19 +358,6 @@ struct VirtIOInputHIDPCI {
 VirtIOInputHID vdev;
 };
 
-#ifdef CONFIG_LINUX
-
-#define TYPE_VIRTIO_INPUT_HOST_PCI "virtio-input-host-pci"
-#define VIRTIO_INPUT_HOST_PCI(obj) \
-OBJECT_CHECK(VirtIOInputHostPCI, (obj), TYPE_VIRTIO_INPUT_HOST_PCI)
-
-struct VirtIOInputHostPCI {
-VirtIOPCIProxy parent_obj;
-VirtIOInputHost vdev;
-};
-
-#endif
-
 /*
  * virtio-gpu-pci: This extends VirtioPCIProxy.
  */
-- 
2.19.2




[Qemu-devel] [PATCH v3 01/16] virtio: split vhost vsock bits from virtio-pci

2018-12-13 Thread Juan Quintela
Reviewed-by: Laurent Vivier 
Signed-off-by: Juan Quintela 

---

Updated copyright info
Also split virtio-pci.h bits
---
 hw/virtio/Makefile.objs |  3 ++
 hw/virtio/vhost-vsock-pci.c | 82 +
 hw/virtio/virtio-pci.c  | 51 ---
 hw/virtio/virtio-pci.h  | 18 
 4 files changed, 85 insertions(+), 69 deletions(-)
 create mode 100644 hw/virtio/vhost-vsock-pci.c

diff --git a/hw/virtio/Makefile.objs b/hw/virtio/Makefile.objs
index 1b2799cfd8..39884c5f7b 100644
--- a/hw/virtio/Makefile.objs
+++ b/hw/virtio/Makefile.objs
@@ -11,6 +11,9 @@ obj-$(call land,$(CONFIG_VIRTIO_CRYPTO),$(CONFIG_VIRTIO_PCI)) 
+= virtio-crypto-p
 
 obj-$(CONFIG_LINUX) += vhost.o vhost-backend.o vhost-user.o
 obj-$(CONFIG_VHOST_VSOCK) += vhost-vsock.o
+ifeq ($(CONFIG_PCI),y)
+obj-$(CONFIG_VHOST_VSOCK) += vhost-vsock-pci.o
+endif
 endif
 
 common-obj-$(call lnot,$(call land,$(CONFIG_VIRTIO),$(CONFIG_LINUX))) += 
vhost-stub.o
diff --git a/hw/virtio/vhost-vsock-pci.c b/hw/virtio/vhost-vsock-pci.c
new file mode 100644
index 00..5cafa8335c
--- /dev/null
+++ b/hw/virtio/vhost-vsock-pci.c
@@ -0,0 +1,82 @@
+/*
+ * Vhost vsock PCI Bindings
+ *
+ * Copyright 2015 Red Hat, Inc.
+ *
+ * Authors:
+ *  Stefan Hajnoczi 
+ *
+ * This work is licensed under the terms of the GNU GPL, version 2 or
+ * (at your option) any later version.  See the COPYING file in the
+ * top-level directory.
+ */
+
+#include "qemu/osdep.h"
+
+#include "virtio-pci.h"
+#include "hw/virtio/vhost-vsock.h"
+
+typedef struct VHostVSockPCI VHostVSockPCI;
+
+/*
+ * vhost-vsock-pci: This extends VirtioPCIProxy.
+ */
+#define TYPE_VHOST_VSOCK_PCI "vhost-vsock-pci"
+#define VHOST_VSOCK_PCI(obj) \
+OBJECT_CHECK(VHostVSockPCI, (obj), TYPE_VHOST_VSOCK_PCI)
+
+struct VHostVSockPCI {
+VirtIOPCIProxy parent_obj;
+VHostVSock vdev;
+};
+
+static Property vhost_vsock_pci_properties[] = {
+DEFINE_PROP_UINT32("vectors", VirtIOPCIProxy, nvectors, 3),
+DEFINE_PROP_END_OF_LIST(),
+};
+
+static void vhost_vsock_pci_realize(VirtIOPCIProxy *vpci_dev, Error **errp)
+{
+VHostVSockPCI *dev = VHOST_VSOCK_PCI(vpci_dev);
+DeviceState *vdev = DEVICE(>vdev);
+
+qdev_set_parent_bus(vdev, BUS(_dev->bus));
+object_property_set_bool(OBJECT(vdev), true, "realized", errp);
+}
+
+static void vhost_vsock_pci_class_init(ObjectClass *klass, void *data)
+{
+DeviceClass *dc = DEVICE_CLASS(klass);
+VirtioPCIClass *k = VIRTIO_PCI_CLASS(klass);
+PCIDeviceClass *pcidev_k = PCI_DEVICE_CLASS(klass);
+k->realize = vhost_vsock_pci_realize;
+set_bit(DEVICE_CATEGORY_MISC, dc->categories);
+dc->props = vhost_vsock_pci_properties;
+pcidev_k->vendor_id = PCI_VENDOR_ID_REDHAT_QUMRANET;
+pcidev_k->device_id = PCI_DEVICE_ID_VIRTIO_VSOCK;
+pcidev_k->revision = 0x00;
+pcidev_k->class_id = PCI_CLASS_COMMUNICATION_OTHER;
+}
+
+static void vhost_vsock_pci_instance_init(Object *obj)
+{
+VHostVSockPCI *dev = VHOST_VSOCK_PCI(obj);
+
+virtio_instance_init_common(obj, >vdev, sizeof(dev->vdev),
+TYPE_VHOST_VSOCK);
+}
+
+static const TypeInfo vhost_vsock_pci_info = {
+.name  = TYPE_VHOST_VSOCK_PCI,
+.parent= TYPE_VIRTIO_PCI,
+.instance_size = sizeof(VHostVSockPCI),
+.instance_init = vhost_vsock_pci_instance_init,
+.class_init= vhost_vsock_pci_class_init,
+};
+
+static void virtio_pci_vhost_register(void)
+{
+type_register_static(_vsock_pci_info);
+}
+
+type_init(virtio_pci_vhost_register)
diff --git a/hw/virtio/virtio-pci.c b/hw/virtio/virtio-pci.c
index a954799267..56b39a3699 100644
--- a/hw/virtio/virtio-pci.c
+++ b/hw/virtio/virtio-pci.c
@@ -2238,54 +2238,6 @@ static const TypeInfo vhost_user_scsi_pci_info = {
 };
 #endif
 
-/* vhost-vsock-pci */
-
-#ifdef CONFIG_VHOST_VSOCK
-static Property vhost_vsock_pci_properties[] = {
-DEFINE_PROP_UINT32("vectors", VirtIOPCIProxy, nvectors, 3),
-DEFINE_PROP_END_OF_LIST(),
-};
-
-static void vhost_vsock_pci_realize(VirtIOPCIProxy *vpci_dev, Error **errp)
-{
-VHostVSockPCI *dev = VHOST_VSOCK_PCI(vpci_dev);
-DeviceState *vdev = DEVICE(>vdev);
-
-qdev_set_parent_bus(vdev, BUS(_dev->bus));
-object_property_set_bool(OBJECT(vdev), true, "realized", errp);
-}
-
-static void vhost_vsock_pci_class_init(ObjectClass *klass, void *data)
-{
-DeviceClass *dc = DEVICE_CLASS(klass);
-VirtioPCIClass *k = VIRTIO_PCI_CLASS(klass);
-PCIDeviceClass *pcidev_k = PCI_DEVICE_CLASS(klass);
-k->realize = vhost_vsock_pci_realize;
-set_bit(DEVICE_CATEGORY_MISC, dc->categories);
-dc->props = vhost_vsock_pci_properties;
-pcidev_k->vendor_id = PCI_VENDOR_ID_REDHAT_QUMRANET;
-pcidev_k->device_id = PCI_DEVICE_ID_VIRTIO_VSOCK;
-pcidev_k->revision = 0x00;
-pcidev_k->class_id = PCI_CLASS_COMMUNICATION_OTHER;
-}
-
-static void vhost_vsock_pci_instance_init(Object *obj)
-{
-VHostVSockPCI *dev = VHOST_VSOCK_PCI(obj);
-
-

[Qemu-devel] [PATCH v3 03/16] virtio: split virtio input bits from virtio-pci

2018-12-13 Thread Juan Quintela
Reviewed-by: Laurent Vivier 
Signed-off-by: Juan Quintela 
---
 hw/virtio/Makefile.objs  |   1 +
 hw/virtio/virtio-input-pci.c | 154 +++
 hw/virtio/virtio-pci.c   | 113 -
 hw/virtio/virtio-pci.h   |  22 -
 4 files changed, 155 insertions(+), 135 deletions(-)
 create mode 100644 hw/virtio/virtio-input-pci.c

diff --git a/hw/virtio/Makefile.objs b/hw/virtio/Makefile.objs
index a6b850ed09..c61bcd106b 100644
--- a/hw/virtio/Makefile.objs
+++ b/hw/virtio/Makefile.objs
@@ -14,6 +14,7 @@ obj-$(CONFIG_VHOST_VSOCK) += vhost-vsock.o
 ifeq ($(CONFIG_PCI),y)
 obj-$(CONFIG_VHOST_VSOCK) += vhost-vsock-pci.o
 obj-$(CONFIG_VIRTIO_INPUT_HOST) += virtio-input-host-pci.o
+obj-$(CONFIG_VIRTIO_INPUT) += virtio-input-pci.o
 endif
 endif
 
diff --git a/hw/virtio/virtio-input-pci.c b/hw/virtio/virtio-input-pci.c
new file mode 100644
index 00..12fc46043e
--- /dev/null
+++ b/hw/virtio/virtio-input-pci.c
@@ -0,0 +1,154 @@
+/*
+ * Virtio input PCI Bindings
+ *
+ * This work is licensed under the terms of the GNU GPL, version 2 or
+ * (at your option) any later version.  See the COPYING file in the
+ * top-level directory.
+ */
+
+#include "qemu/osdep.h"
+
+#include "virtio-pci.h"
+#include "hw/virtio/virtio-input.h"
+
+typedef struct VirtIOInputPCI VirtIOInputPCI;
+typedef struct VirtIOInputHIDPCI VirtIOInputHIDPCI;
+
+/*
+ * virtio-input-pci: This extends VirtioPCIProxy.
+ */
+#define VIRTIO_INPUT_PCI(obj) \
+OBJECT_CHECK(VirtIOInputPCI, (obj), TYPE_VIRTIO_INPUT_PCI)
+
+struct VirtIOInputPCI {
+VirtIOPCIProxy parent_obj;
+VirtIOInput vdev;
+};
+
+#define TYPE_VIRTIO_INPUT_HID_PCI "virtio-input-hid-pci"
+#define TYPE_VIRTIO_KEYBOARD_PCI  "virtio-keyboard-pci"
+#define TYPE_VIRTIO_MOUSE_PCI "virtio-mouse-pci"
+#define TYPE_VIRTIO_TABLET_PCI"virtio-tablet-pci"
+#define VIRTIO_INPUT_HID_PCI(obj) \
+OBJECT_CHECK(VirtIOInputHIDPCI, (obj), TYPE_VIRTIO_INPUT_HID_PCI)
+
+struct VirtIOInputHIDPCI {
+VirtIOPCIProxy parent_obj;
+VirtIOInputHID vdev;
+};
+
+static Property virtio_input_pci_properties[] = {
+DEFINE_PROP_UINT32("vectors", VirtIOPCIProxy, nvectors, 2),
+DEFINE_PROP_END_OF_LIST(),
+};
+
+static void virtio_input_pci_realize(VirtIOPCIProxy *vpci_dev, Error **errp)
+{
+VirtIOInputPCI *vinput = VIRTIO_INPUT_PCI(vpci_dev);
+DeviceState *vdev = DEVICE(>vdev);
+
+qdev_set_parent_bus(vdev, BUS(_dev->bus));
+virtio_pci_force_virtio_1(vpci_dev);
+object_property_set_bool(OBJECT(vdev), true, "realized", errp);
+}
+
+static void virtio_input_pci_class_init(ObjectClass *klass, void *data)
+{
+DeviceClass *dc = DEVICE_CLASS(klass);
+VirtioPCIClass *k = VIRTIO_PCI_CLASS(klass);
+PCIDeviceClass *pcidev_k = PCI_DEVICE_CLASS(klass);
+
+dc->props = virtio_input_pci_properties;
+k->realize = virtio_input_pci_realize;
+set_bit(DEVICE_CATEGORY_INPUT, dc->categories);
+
+pcidev_k->class_id = PCI_CLASS_INPUT_OTHER;
+}
+
+static void virtio_input_hid_kbd_pci_class_init(ObjectClass *klass, void *data)
+{
+PCIDeviceClass *pcidev_k = PCI_DEVICE_CLASS(klass);
+
+pcidev_k->class_id = PCI_CLASS_INPUT_KEYBOARD;
+}
+
+static void virtio_input_hid_mouse_pci_class_init(ObjectClass *klass,
+  void *data)
+{
+PCIDeviceClass *pcidev_k = PCI_DEVICE_CLASS(klass);
+
+pcidev_k->class_id = PCI_CLASS_INPUT_MOUSE;
+}
+
+static void virtio_keyboard_initfn(Object *obj)
+{
+VirtIOInputHIDPCI *dev = VIRTIO_INPUT_HID_PCI(obj);
+
+virtio_instance_init_common(obj, >vdev, sizeof(dev->vdev),
+TYPE_VIRTIO_KEYBOARD);
+}
+
+static void virtio_mouse_initfn(Object *obj)
+{
+VirtIOInputHIDPCI *dev = VIRTIO_INPUT_HID_PCI(obj);
+
+virtio_instance_init_common(obj, >vdev, sizeof(dev->vdev),
+TYPE_VIRTIO_MOUSE);
+}
+
+static void virtio_tablet_initfn(Object *obj)
+{
+VirtIOInputHIDPCI *dev = VIRTIO_INPUT_HID_PCI(obj);
+
+virtio_instance_init_common(obj, >vdev, sizeof(dev->vdev),
+TYPE_VIRTIO_TABLET);
+}
+
+static const TypeInfo virtio_input_pci_info = {
+.name  = TYPE_VIRTIO_INPUT_PCI,
+.parent= TYPE_VIRTIO_PCI,
+.instance_size = sizeof(VirtIOInputPCI),
+.class_init= virtio_input_pci_class_init,
+.abstract  = true,
+};
+
+static const TypeInfo virtio_input_hid_pci_info = {
+.name  = TYPE_VIRTIO_INPUT_HID_PCI,
+.parent= TYPE_VIRTIO_INPUT_PCI,
+.instance_size = sizeof(VirtIOInputHIDPCI),
+.abstract  = true,
+};
+
+static const TypeInfo virtio_keyboard_pci_info = {
+.name  = TYPE_VIRTIO_KEYBOARD_PCI,
+.parent= TYPE_VIRTIO_INPUT_HID_PCI,
+.class_init= virtio_input_hid_kbd_pci_class_init,
+.instance_size = sizeof(VirtIOInputHIDPCI),
+.instance_init = virtio_keyboard_initfn,
+};
+
+static const TypeInfo virtio_mouse_pci_info = {

Re: [Qemu-devel] [PATCH v2] hw/s390/ccw.c: Don't take address of packed members

2018-12-13 Thread Thomas Huth
On 2018-12-13 13:02, Peter Maydell wrote:
> Taking the address of a field in a packed struct is a bad idea, because
> it might not be actually aligned enough for that pointer type (and
> thus cause a crash on dereference on some host architectures). Newer
> versions of clang warn about this.
> 
> Avoid the problem by using local copies of the PMCW and SCSW
> struct fields in copy_schib_from_guest() and copy_schib_to_guest().
> 
> Signed-off-by: Peter Maydell 
> ---
> v1->v2 changes:
>  * add comment about why we're using locals

Thanks!

Reviewed-by: Thomas Huth 



Re: [Qemu-devel] ping2 Re: [PATCH v4 0/8] dirty-bitmap: rewrite bdrv_dirty_iter_next_area

2018-12-13 Thread Denis Lunev
On 12/13/18 9:18 PM, John Snow wrote:
>
> On 12/13/18 6:07 AM, Vladimir Sementsov-Ogievskiy wrote:
>> 12.12.2018 23:41, John Snow wrote:
>>>
>>> On 12/12/18 4:27 AM, Vladimir Sementsov-Ogievskiy wrote:
 ping. No dependencies, apply to master.

>>> Sure thing.
>>>
>>> Staged to jsnow/bitmaps.
>>
>> Thank you!
>>
>> Oops, I've missed your email about s/firt_dirty_off/first_dirty_off
>>
>> I can resend, or you can fix in your branch, as you prefer.
>> The variable touches two commits in jsnow/bitmaps:
>>
> Whoops, I forgot too. I just remember that I was waiting on a requisite
> and it got lost so I was in a hurry to stage it for you. I'll just
> squash any fixes in.
>
> I'll try to send the PR when the qemu-img bitmap info patch is ready,
> alongside my series to drop the x-prefix (and adjust the merge API.)
>
> Anything else urgent for the start of the 4.0 window before we all
> disappear on holiday break?
>
> --js

JFYI: Holidays in Russia are AFTER New Year, not before :)
We will be on vacations from 01 till 08.

Den


Re: [Qemu-devel] [PATCH 3/3] Mention that QMP 'cpu-add' will be deprecated

2018-12-13 Thread Thomas Huth
On 2018-12-13 13:42, Kashyap Chamarthy wrote:
> Signed-off-by: Kashyap Chamarthy 
> ---
>  qemu-deprecated.texi | 6 ++
>  1 file changed, 6 insertions(+)
> 
> diff --git a/qemu-deprecated.texi b/qemu-deprecated.texi
> index 79743ab8bd..2505e1f47f 100644
> --- a/qemu-deprecated.texi
> +++ b/qemu-deprecated.texi
> @@ -114,6 +114,12 @@ The ``query-cpus'' command is replaced by the 
> ``query-cpus-fast'' command.
>  The ``arch'' output member of the ``query-cpus-fast'' command is
>  replaced by the ``target'' output member.
>  
> +@subsection cpu-add (since 4.0)
> +
> +Use ``device_add'' for hotplugging vCPUs instead of ``cpu-add''.  See
> +documentation of ``query-hotpluggable-cpus'' for additional
> +details.
> +
>  @section Human Monitor Protocol (HMP) commands
>  
>  @subsection The hub_id parameter of 'hostfwd_add' / 'hostfwd_remove' (since 
> 3.1)
> 

Reviewed-by: Thomas Huth 



Re: [Qemu-devel] [PATCH 2/3] Update that HMP 'cpu_add' is deprecated in 4.0

2018-12-13 Thread Thomas Huth
On 2018-12-13 13:42, Kashyap Chamarthy wrote:
> Also fix the wrong spelling of it: s/cpu-add/cpu_add/
> 
> Signed-off-by: Kashyap Chamarthy 
> ---
>  qemu-deprecated.texi | 4 ++--
>  1 file changed, 2 insertions(+), 2 deletions(-)
> 
> diff --git a/qemu-deprecated.texi b/qemu-deprecated.texi
> index 46bec688db..79743ab8bd 100644
> --- a/qemu-deprecated.texi
> +++ b/qemu-deprecated.texi
> @@ -121,9 +121,9 @@ replaced by the ``target'' output member.
>  The @option{[hub_id name]} parameter tuple of the 'hostfwd_add' and
>  'hostfwd_remove' HMP commands has been replaced by @option{netdev_id}.
>  
> -@subsection cpu-add (since 3.1)
> +@subsection cpu_add (since 4.0)
>  
> -Use ``device_add'' for hotplugging vCPUs instead of ``cpu-add''.  See
> +Use ``device_add'' for hotplugging vCPUs instead of ``cpu_add''.  See

AFAIK the spelling was right. It's "cpu-add" ... only device_add is
using the underscore. Welcome to the wonderful world of QEMU
inconsistencies...

 Thomas



Re: [Qemu-devel] [PATCH 1/3] qemu-deprecated.texi: Rename the HMP section

2018-12-13 Thread Thomas Huth
On 2018-12-13 13:42, Kashyap Chamarthy wrote:
> So that it is consistent with the naming of QMP's
> 
> Signed-off-by: Kashyap Chamarthy 
> ---
>  qemu-deprecated.texi | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/qemu-deprecated.texi b/qemu-deprecated.texi
> index 72b8191d60..46bec688db 100644
> --- a/qemu-deprecated.texi
> +++ b/qemu-deprecated.texi
> @@ -114,7 +114,7 @@ The ``query-cpus'' command is replaced by the 
> ``query-cpus-fast'' command.
>  The ``arch'' output member of the ``query-cpus-fast'' command is
>  replaced by the ``target'' output member.
>  
> -@section System emulator human monitor commands
> +@section Human Monitor Protocol (HMP) commands

Reviewed-by: Thomas Huth 



[Qemu-devel] [PULL 24/32] qapi: Add 'if' to implicit struct members

2018-12-13 Thread Markus Armbruster
From: Marc-André Lureau 

The generated code is for now *unconditional*.  Later patches generate
the conditionals.

Note that union discriminators may not have 'if' conditionals.

Signed-off-by: Marc-André Lureau 
Reviewed-by: Markus Armbruster 
Message-Id: <20181213123724.4866-14-marcandre.lur...@redhat.com>
Message-Id: <20181213123724.4866-15-marcandre.lur...@redhat.com>
[Patches squashed, commit message tweaked]
Signed-off-by: Markus Armbruster 
---
 docs/devel/qapi-code-gen.txt   | 10 ++
 scripts/qapi/common.py | 18 +++---
 tests/Makefile.include |  1 +
 .../flat-union-invalid-if-discriminator.err|  1 +
 .../flat-union-invalid-if-discriminator.exit   |  1 +
 .../flat-union-invalid-if-discriminator.json   | 17 +
 .../flat-union-invalid-if-discriminator.out|  0
 tests/qapi-schema/qapi-schema-test.json| 12 +---
 tests/qapi-schema/qapi-schema-test.out |  5 +
 tests/qapi-schema/test-qapi.py |  1 +
 10 files changed, 56 insertions(+), 10 deletions(-)
 create mode 100644 tests/qapi-schema/flat-union-invalid-if-discriminator.err
 create mode 100644 tests/qapi-schema/flat-union-invalid-if-discriminator.exit
 create mode 100644 tests/qapi-schema/flat-union-invalid-if-discriminator.json
 create mode 100644 tests/qapi-schema/flat-union-invalid-if-discriminator.out

diff --git a/docs/devel/qapi-code-gen.txt b/docs/devel/qapi-code-gen.txt
index 7ba9066eac..3895808b4a 100644
--- a/docs/devel/qapi-code-gen.txt
+++ b/docs/devel/qapi-code-gen.txt
@@ -752,6 +752,16 @@ gets its generated code guarded like this:
  #endif /* defined(HAVE_BAR) */
  #endif /* defined(CONFIG_FOO) */
 
+Where a member can be defined with a single string value for its type,
+it is also possible to supply a dictionary instead with both 'type'
+and 'if' keys. (TODO: union and alternate)
+
+Example: a conditional 'bar' member
+
+{ 'struct': 'IfStruct', 'data':
+  { 'foo': 'int',
+'bar': { 'type': 'int', 'if': 'defined(IFCOND)'} } }
+
 An enum value can be replaced by a dictionary with a 'name' and a 'if'
 key.
 
diff --git a/scripts/qapi/common.py b/scripts/qapi/common.py
index cdfe2bf2a5..98e9d6f109 100644
--- a/scripts/qapi/common.py
+++ b/scripts/qapi/common.py
@@ -705,7 +705,7 @@ def check_type(info, source, value, allow_array=False,
 # Todo: allow dictionaries to represent default values of
 # an optional argument.
 check_known_keys(info, "member '%s' of %s" % (key, source),
- arg, ['type'], [])
+ arg, ['type'], ['if'])
 check_type(info, "Member '%s' of %s" % (key, source),
arg['type'], allow_array=True,
allow_metas=['built-in', 'union', 'alternate', 'struct',
@@ -784,6 +784,10 @@ def check_union(expr, info):
"Discriminator '%s' is not a member of base "
"struct '%s'"
% (discriminator, base))
+if discriminator_value.get('if'):
+raise QAPISemError(info, 'The discriminator %s.%s for union %s '
+   'must not be conditional' %
+   (base, discriminator, name))
 enum_define = enum_types.get(discriminator_value['type'])
 allow_metas = ['struct']
 # Do not allow string discriminator
@@ -1412,8 +1416,8 @@ class QAPISchemaMember(object):
 
 
 class QAPISchemaObjectTypeMember(QAPISchemaMember):
-def __init__(self, name, typ, optional):
-QAPISchemaMember.__init__(self, name)
+def __init__(self, name, typ, optional, ifcond=None):
+QAPISchemaMember.__init__(self, name, ifcond)
 assert isinstance(typ, str)
 assert isinstance(optional, bool)
 self._type_name = typ
@@ -1727,7 +1731,7 @@ class QAPISchema(object):
 name, info, doc, ifcond,
 self._make_enum_members(data), prefix))
 
-def _make_member(self, name, typ, info):
+def _make_member(self, name, typ, ifcond, info):
 optional = False
 if name.startswith('*'):
 name = name[1:]
@@ -1735,10 +1739,10 @@ class QAPISchema(object):
 if isinstance(typ, list):
 assert len(typ) == 1
 typ = self._make_array_type(typ[0], info)
-return QAPISchemaObjectTypeMember(name, typ, optional)
+return QAPISchemaObjectTypeMember(name, typ, optional, ifcond)
 
 def _make_members(self, data, info):
-return [self._make_member(key, value['type'], info)
+return [self._make_member(key, value['type'], value.get('if'), info)
 for (key, value) in data.items()]
 
 def _def_struct_type(self, expr, info, doc):
@@ -1759,7 +1763,7 @@ class QAPISchema(object):
 typ = self._make_array_type(typ[0], info)
 typ = self._make_implicit_object_type(
 typ, info, 

[Qemu-devel] [PULL 26/32] qapi: add 'if' to alternate members

2018-12-13 Thread Markus Armbruster
From: Marc-André Lureau 

Add 'if' key to alternate members:

{ 'alternate': 'TestIfAlternate', 'data':
  { 'alt': { 'type': 'TestStruct', 'if': 'COND' } } }

Generated code is not changed by this patch but with "qapi: add #if
conditions to generated code".

Signed-off-by: Marc-André Lureau 
Reviewed-by: Markus Armbruster 
Message-Id: <20181213123724.4866-17-marcandre.lur...@redhat.com>
Signed-off-by: Markus Armbruster 
---
 docs/devel/qapi-code-gen.txt|  2 +-
 scripts/qapi/common.py  | 10 +-
 tests/qapi-schema/qapi-schema-test.json |  4 +++-
 tests/qapi-schema/qapi-schema-test.out  |  1 +
 4 files changed, 10 insertions(+), 7 deletions(-)

diff --git a/docs/devel/qapi-code-gen.txt b/docs/devel/qapi-code-gen.txt
index 0a0e53ede5..43bd853e69 100644
--- a/docs/devel/qapi-code-gen.txt
+++ b/docs/devel/qapi-code-gen.txt
@@ -754,7 +754,7 @@ gets its generated code guarded like this:
 
 Where a member can be defined with a single string value for its type,
 it is also possible to supply a dictionary instead with both 'type'
-and 'if' keys. (TODO: alternate)
+and 'if' keys.
 
 Example: a conditional 'bar' member
 
diff --git a/scripts/qapi/common.py b/scripts/qapi/common.py
index 44fe8868ed..17707b6de7 100644
--- a/scripts/qapi/common.py
+++ b/scripts/qapi/common.py
@@ -833,7 +833,7 @@ def check_alternate(expr, info):
 check_name(info, "Member of alternate '%s'" % name, key)
 check_known_keys(info,
  "member '%s' of alternate '%s'" % (key, name),
- value, ['type'], [])
+ value, ['type'], ['if'])
 typ = value['type']
 
 # Ensure alternates have no type conflicts.
@@ -1754,8 +1754,8 @@ class QAPISchema(object):
   self._make_members(data, info),
   None))
 
-def _make_variant(self, case, typ):
-return QAPISchemaObjectTypeVariant(case, typ)
+def _make_variant(self, case, typ, ifcond):
+return QAPISchemaObjectTypeVariant(case, typ, ifcond)
 
 def _make_simple_variant(self, case, typ, ifcond, info):
 if isinstance(typ, list):
@@ -1778,7 +1778,7 @@ class QAPISchema(object):
 name, info, doc, ifcond,
 'base', self._make_members(base, info))
 if tag_name:
-variants = [self._make_variant(key, value['type'])
+variants = [self._make_variant(key, value['type'], value.get('if'))
 for (key, value) in data.items()]
 members = []
 else:
@@ -1799,7 +1799,7 @@ class QAPISchema(object):
 name = expr['alternate']
 data = expr['data']
 ifcond = expr.get('if')
-variants = [self._make_variant(key, value['type'])
+variants = [self._make_variant(key, value['type'], value.get('if'))
 for (key, value) in data.items()]
 tag_member = QAPISchemaObjectTypeMember('type', 'QType', False)
 self._def_entity(
diff --git a/tests/qapi-schema/qapi-schema-test.json 
b/tests/qapi-schema/qapi-schema-test.json
index a33eff8f86..cb0857df52 100644
--- a/tests/qapi-schema/qapi-schema-test.json
+++ b/tests/qapi-schema/qapi-schema-test.json
@@ -218,7 +218,9 @@
 { 'command': 'TestIfUnionCmd', 'data': { 'union_cmd_arg': 'TestIfUnion' },
   'if': 'defined(TEST_IF_UNION)' }
 
-{ 'alternate': 'TestIfAlternate', 'data': { 'foo': 'int', 'bar': 'TestStruct' 
},
+{ 'alternate': 'TestIfAlternate', 'data':
+  { 'foo': 'int',
+'bar': { 'type': 'TestStruct', 'if': 'defined(TEST_IF_ALT_BAR)'} },
   'if': 'defined(TEST_IF_ALT) && defined(TEST_IF_STRUCT)' }
 
 { 'command': 'TestIfAlternateCmd', 'data': { 'alt_cmd_arg': 'TestIfAlternate' 
},
diff --git a/tests/qapi-schema/qapi-schema-test.out 
b/tests/qapi-schema/qapi-schema-test.out
index f4c11f1e6a..9464101d26 100644
--- a/tests/qapi-schema/qapi-schema-test.out
+++ b/tests/qapi-schema/qapi-schema-test.out
@@ -300,6 +300,7 @@ alternate TestIfAlternate
 tag type
 case foo: int
 case bar: TestStruct
+if ['defined(TEST_IF_ALT_BAR)']
 if ['defined(TEST_IF_ALT) && defined(TEST_IF_STRUCT)']
 object q_obj_TestIfAlternateCmd-arg
 member alt_cmd_arg: TestIfAlternate optional=False
-- 
2.17.2




[Qemu-devel] [Bug 1806824] Re: SIE-200 (TrustZone) MPC: BLK_MAX returns an incorrect value

2018-12-13 Thread Peter Maydell
Thanks for the bug report and the test program. The fix seems straightforward 
-- just adjust what we return for the register value. I've sent a patch:
http://patchwork.ozlabs.org/patch/1013034/


** Changed in: qemu
   Status: New => In Progress

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

Title:
  SIE-200 (TrustZone) MPC: BLK_MAX returns an incorrect value

Status in QEMU:
  In Progress

Bug description:
  Version: 
  $ qemu-system-arm --version
  QEMU emulator version 3.0.92 (v3.1.0-rc2-31-gd522fba244)

  Arm SIE-200 Technical Reference Manual describes that BLK_MAX
  indicates the maximum value of "block based index register" (BLK_IDX).
  For example, the value 1 would indicate that BLK_IDX can be 0 or 1.
  According to my experiments, the AN505 FPGA image apparently follows
  this behavior.

  In the current implementation of QEMU, it appears to indicate the
  number of possible values for BLK_IDX, i.e., one plus the value it's
  supposed to return.

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



[Qemu-devel] [PULL 16/32] qapi: change enum visitor and gen_enum* to take QAPISchemaMember

2018-12-13 Thread Markus Armbruster
From: Marc-André Lureau 

This will allow to add and access more properties associated with enum
values/members, like the associated 'if' condition. We may want to
have a specialized type QAPISchemaEnumMember, for now this will do.

Modify gen_enum() and gen_enum_lookup() for the same reason.

Suggested-by: Markus Armbruster 
Signed-off-by: Marc-André Lureau 
Reviewed-by: Markus Armbruster 
Message-Id: <20181213123724.4866-3-marcandre.lur...@redhat.com>
Signed-off-by: Markus Armbruster 
---
 scripts/qapi/common.py | 22 +++---
 scripts/qapi/doc.py|  2 +-
 scripts/qapi/events.py | 13 +++--
 scripts/qapi/introspect.py |  5 +++--
 scripts/qapi/types.py  |  6 +++---
 scripts/qapi/visit.py  |  2 +-
 tests/qapi-schema/test-qapi.py |  4 ++--
 7 files changed, 28 insertions(+), 26 deletions(-)

diff --git a/scripts/qapi/common.py b/scripts/qapi/common.py
index 55c914ec44..1fa2f79990 100644
--- a/scripts/qapi/common.py
+++ b/scripts/qapi/common.py
@@ -1063,7 +1063,7 @@ class QAPISchemaVisitor(object):
 def visit_builtin_type(self, name, info, json_type):
 pass
 
-def visit_enum_type(self, name, info, ifcond, values, prefix):
+def visit_enum_type(self, name, info, ifcond, members, prefix):
 pass
 
 def visit_array_type(self, name, info, ifcond, element_type):
@@ -1193,7 +1193,7 @@ class QAPISchemaEnumType(QAPISchemaType):
 
 def visit(self, visitor):
 visitor.visit_enum_type(self.name, self.info, self.ifcond,
-self.member_names(), self.prefix)
+self.members, self.prefix)
 
 
 class QAPISchemaArrayType(QAPISchemaType):
@@ -2012,19 +2012,19 @@ def _wrap_ifcond(ifcond, before, after):
 return out
 
 
-def gen_enum_lookup(name, values, prefix=None):
+def gen_enum_lookup(name, members, prefix=None):
 ret = mcgen('''
 
 const QEnumLookup %(c_name)s_lookup = {
 .array = (const char *const[]) {
 ''',
 c_name=c_name(name))
-for value in values:
-index = c_enum_const(name, value, prefix)
+for m in members:
+index = c_enum_const(name, m.name, prefix)
 ret += mcgen('''
-[%(index)s] = "%(value)s",
+[%(index)s] = "%(name)s",
 ''',
- index=index, value=value)
+ index=index, name=m.name)
 
 ret += mcgen('''
 },
@@ -2035,9 +2035,9 @@ const QEnumLookup %(c_name)s_lookup = {
 return ret
 
 
-def gen_enum(name, values, prefix=None):
+def gen_enum(name, members, prefix=None):
 # append automatically generated _MAX value
-enum_values = values + ['_MAX']
+enum_members = members + [QAPISchemaMember('_MAX')]
 
 ret = mcgen('''
 
@@ -2045,11 +2045,11 @@ typedef enum %(c_name)s {
 ''',
 c_name=c_name(name))
 
-for value in enum_values:
+for m in enum_members:
 ret += mcgen('''
 %(c_enum)s,
 ''',
- c_enum=c_enum_const(name, value, prefix))
+ c_enum=c_enum_const(name, m.name, prefix))
 
 ret += mcgen('''
 } %(c_name)s;
diff --git a/scripts/qapi/doc.py b/scripts/qapi/doc.py
index 987fd3c943..76cb186ff9 100755
--- a/scripts/qapi/doc.py
+++ b/scripts/qapi/doc.py
@@ -206,7 +206,7 @@ class 
QAPISchemaGenDocVisitor(qapi.common.QAPISchemaVisitor):
 def write(self, output_dir):
 self._gen.write(output_dir, self._prefix + 'qapi-doc.texi')
 
-def visit_enum_type(self, name, info, ifcond, values, prefix):
+def visit_enum_type(self, name, info, ifcond, members, prefix):
 doc = self.cur_doc
 self._gen.add(TYPE_FMT(type='Enum',
name=doc.symbol,
diff --git a/scripts/qapi/events.py b/scripts/qapi/events.py
index 2ed7902424..f1b88d8786 100644
--- a/scripts/qapi/events.py
+++ b/scripts/qapi/events.py
@@ -143,8 +143,8 @@ class QAPISchemaGenEventVisitor(QAPISchemaModularCVisitor):
 QAPISchemaModularCVisitor.__init__(
 self, prefix, 'qapi-events',
 ' * Schema-defined QAPI/QMP events', __doc__)
-self._enum_name = c_name(prefix + 'QAPIEvent', protect=False)
-self._event_names = []
+self._event_enum_name = c_name(prefix + 'QAPIEvent', protect=False)
+self._event_enum_members = []
 
 def _begin_module(self, name):
 types = self._module_basename('qapi-types', name)
@@ -170,15 +170,16 @@ class 
QAPISchemaGenEventVisitor(QAPISchemaModularCVisitor):
 
 def visit_end(self):
 (genc, genh) = self._module[self._main_module]
-genh.add(gen_enum(self._enum_name, self._event_names))
-genc.add(gen_enum_lookup(self._enum_name, self._event_names))
+genh.add(gen_enum(self._event_enum_name, self._event_enum_members))
+genc.add(gen_enum_lookup(self._event_enum_name,
+ self._event_enum_members))
 
 def visit_event(self, name, info, ifcond, arg_type, boxed):
 with 

[Qemu-devel] [PULL 18/32] qapi: factor out checking for keys

2018-12-13 Thread Markus Armbruster
From: Marc-André Lureau 

Introduce a new helper function to check if the given keys are known,
and if mandatory keys are present. The function will be reused in
other places in the following code changes.

Signed-off-by: Marc-André Lureau 
Reviewed-by: Markus Armbruster 
Message-Id: <20181213123724.4866-5-marcandre.lur...@redhat.com>
Signed-off-by: Markus Armbruster 
---
 scripts/qapi/common.py | 20 +---
 1 file changed, 13 insertions(+), 7 deletions(-)

diff --git a/scripts/qapi/common.py b/scripts/qapi/common.py
index 1fa2f79990..18f5872808 100644
--- a/scripts/qapi/common.py
+++ b/scripts/qapi/common.py
@@ -873,6 +873,17 @@ def check_struct(expr, info):
allow_metas=['struct'])
 
 
+def check_known_keys(info, source, keys, required, optional):
+for key in keys:
+if key not in required and key not in optional:
+raise QAPISemError(info, "Unknown key '%s' in %s" % (key, source))
+
+for key in required:
+if key not in keys:
+raise QAPISemError(info, "Key '%s' is missing from %s"
+   % (key, source))
+
+
 def check_keys(expr_elem, meta, required, optional=[]):
 expr = expr_elem['expr']
 info = expr_elem['info']
@@ -880,10 +891,9 @@ def check_keys(expr_elem, meta, required, optional=[]):
 if not isinstance(name, str):
 raise QAPISemError(info, "'%s' key must have a string value" % meta)
 required = required + [meta]
+source = "%s '%s'" % (meta, name)
+check_known_keys(info, source, expr.keys(), required, optional)
 for (key, value) in expr.items():
-if key not in required and key not in optional:
-raise QAPISemError(info, "Unknown key '%s' in %s '%s'"
-   % (key, meta, name))
 if key in ['gen', 'success-response'] and value is not False:
 raise QAPISemError(info,
"'%s' of %s '%s' should only use false value"
@@ -895,10 +905,6 @@ def check_keys(expr_elem, meta, required, optional=[]):
% (key, meta, name))
 if key == 'if':
 check_if(expr, info)
-for key in required:
-if key not in expr:
-raise QAPISemError(info, "Key '%s' is missing from %s '%s'"
-   % (key, meta, name))
 
 
 def check_exprs(exprs):
-- 
2.17.2




[Qemu-devel] [PULL 01/32] cutils: Add qemu_strtod() and qemu_strtod_finite()

2018-12-13 Thread Markus Armbruster
From: David Hildenbrand 

Let's provide a wrapper for strtod().

Reviewed-by: Markus Armbruster 
Signed-off-by: David Hildenbrand 
Message-Id: <20181121164421.20780-2-da...@redhat.com>
Signed-off-by: Markus Armbruster 
---
 include/qemu/cutils.h |  2 ++
 util/cutils.c | 65 +++
 2 files changed, 67 insertions(+)

diff --git a/include/qemu/cutils.h b/include/qemu/cutils.h
index 7071bfe2d4..756b41c193 100644
--- a/include/qemu/cutils.h
+++ b/include/qemu/cutils.h
@@ -146,6 +146,8 @@ int qemu_strtoi64(const char *nptr, const char **endptr, 
int base,
   int64_t *result);
 int qemu_strtou64(const char *nptr, const char **endptr, int base,
   uint64_t *result);
+int qemu_strtod(const char *nptr, const char **endptr, double *result);
+int qemu_strtod_finite(const char *nptr, const char **endptr, double *result);
 
 int parse_uint(const char *s, unsigned long long *value, char **endptr,
int base);
diff --git a/util/cutils.c b/util/cutils.c
index 0621565930..ec0a401d9a 100644
--- a/util/cutils.c
+++ b/util/cutils.c
@@ -551,6 +551,71 @@ int qemu_strtou64(const char *nptr, const char **endptr, 
int base,
 return check_strtox_error(nptr, ep, endptr, errno);
 }
 
+/**
+ * Convert string @nptr to a double.
+  *
+ * This is a wrapper around strtod() that is harder to misuse.
+ * Semantics of @nptr and @endptr match strtod() with differences
+ * noted below.
+ *
+ * @nptr may be null, and no conversion is performed then.
+ *
+ * If no conversion is performed, store @nptr in *@endptr and return
+ * -EINVAL.
+ *
+ * If @endptr is null, and the string isn't fully converted, return
+ * -EINVAL. This is the case when the pointer that would be stored in
+ * a non-null @endptr points to a character other than '\0'.
+ *
+ * If the conversion overflows, store +/-HUGE_VAL in @result, depending
+ * on the sign, and return -ERANGE.
+ *
+ * If the conversion underflows, store +/-0.0 in @result, depending on the
+ * sign, and return -ERANGE.
+ *
+ * Else store the converted value in @result, and return zero.
+ */
+int qemu_strtod(const char *nptr, const char **endptr, double *result)
+{
+char *ep;
+
+if (!nptr) {
+if (endptr) {
+*endptr = nptr;
+}
+return -EINVAL;
+}
+
+errno = 0;
+*result = strtod(nptr, );
+return check_strtox_error(nptr, ep, endptr, errno);
+}
+
+/**
+ * Convert string @nptr to a finite double.
+ *
+ * Works like qemu_strtod(), except that "NaN" and "inf" are rejected
+ * with -EINVAL and no conversion is performed.
+ */
+int qemu_strtod_finite(const char *nptr, const char **endptr, double *result)
+{
+double tmp;
+int ret;
+
+ret = qemu_strtod(nptr, endptr, );
+if (!ret && !isfinite(tmp)) {
+if (endptr) {
+*endptr = nptr;
+}
+ret = -EINVAL;
+}
+
+if (ret != -EINVAL) {
+*result = tmp;
+}
+return ret;
+}
+
 /**
  * Searches for the first occurrence of 'c' in 's', and returns a pointer
  * to the trailing null byte if none was found.
-- 
2.17.2




Re: [Qemu-devel] [PULL 0/2] Tracing patches

2018-12-13 Thread Peter Maydell
On Wed, 12 Dec 2018 at 10:16, Stefan Hajnoczi  wrote:
>
> The following changes since commit bb9bf94b3e8926553290bc9a7cb84315af422086:
>
>   Merge remote-tracking branch 
> 'remotes/ehabkost/tags/machine-next-pull-request' into staging (2018-12-11 
> 19:18:58 +)
>
> are available in the Git repository at:
>
>   git://github.com/stefanha/qemu.git tags/tracing-pull-request
>
> for you to fetch changes up to 7ff5920717d413d8b7c3ba13d9a0805291b9e6ec:
>
>   trace: simple style changes (2018-12-12 10:04:59 +)
>
> 
> Pull request
>
> Minor tracing improvements.
>
> 
>
> Fabiano Rosas (1):
>   tracetool: Include thread id information in log backend
>
> Larry Dewey (1):
>   trace: simple style changes
>
>  trace/simple.c   | 4 ++--
>  scripts/tracetool/backend/log.py | 2 +-
>  2 files changed, 3 insertions(+), 3 deletions(-)

Applied, thanks.

Please update the changelog at https://wiki.qemu.org/ChangeLog/4.0
for any user-visible changes.

-- PMM



[Qemu-devel] [PULL 29/32] qapi: add 'If:' condition to struct members documentation

2018-12-13 Thread Markus Armbruster
From: Marc-André Lureau 

Signed-off-by: Marc-André Lureau 
Message-Id: <20181213123724.4866-20-marcandre.lur...@redhat.com>
Reviewed-by: Markus Armbruster 
Signed-off-by: Markus Armbruster 
---
 scripts/qapi/doc.py | 4 ++--
 tests/qapi-schema/doc-good.json | 3 ++-
 tests/qapi-schema/doc-good.out  | 1 +
 tests/qapi-schema/doc-good.texi | 1 +
 4 files changed, 6 insertions(+), 3 deletions(-)

diff --git a/scripts/qapi/doc.py b/scripts/qapi/doc.py
index ab36b9dec6..b6f834b917 100755
--- a/scripts/qapi/doc.py
+++ b/scripts/qapi/doc.py
@@ -143,10 +143,10 @@ def texi_member(member, desc, suffix):
 """Format a table of members item for an object type member"""
 typ = member.type.doc_type()
 membertype = ': ' + typ if typ else ''
-return '@item @code{%s%s}%s%s\n%s' % (
+return '@item @code{%s%s}%s%s\n%s%s' % (
 member.name, membertype,
 ' (optional)' if member.optional else '',
-suffix, desc)
+suffix, desc, texi_if(member.ifcond, prefix='@*'))
 
 
 def texi_members(doc, what, base, variants, member_func):
diff --git a/tests/qapi-schema/doc-good.json b/tests/qapi-schema/doc-good.json
index 1cd4935710..28992fc615 100644
--- a/tests/qapi-schema/doc-good.json
+++ b/tests/qapi-schema/doc-good.json
@@ -72,7 +72,8 @@
 #
 # Another paragraph (but no @var: line)
 ##
-{ 'struct': 'Variant1', 'data': { 'var1': 'str' } }
+{ 'struct': 'Variant1',
+  'data': { 'var1': { 'type': 'str', 'if': 'defined(IFSTR)' } } }
 
 ##
 # @Variant2:
diff --git a/tests/qapi-schema/doc-good.out b/tests/qapi-schema/doc-good.out
index 53bd177f7d..4ab55683ce 100644
--- a/tests/qapi-schema/doc-good.out
+++ b/tests/qapi-schema/doc-good.out
@@ -18,6 +18,7 @@ object Base
 member base1: Enum optional=False
 object Variant1
 member var1: str optional=False
+if ['defined(IFSTR)']
 object Variant2
 object Object
 base Base
diff --git a/tests/qapi-schema/doc-good.texi b/tests/qapi-schema/doc-good.texi
index 405055b146..f87f9faacb 100644
--- a/tests/qapi-schema/doc-good.texi
+++ b/tests/qapi-schema/doc-good.texi
@@ -119,6 +119,7 @@ Another paragraph (but no @code{var}: line)
 @table @asis
 @item @code{var1: string}
 Not documented
+@*@b{If:} @code{defined(IFSTR)}
 @end table
 
 @end deftp
-- 
2.17.2




[Qemu-devel] [PULL 19/32] qapi: improve reporting of unknown or missing keys

2018-12-13 Thread Markus Armbruster
From: Marc-André Lureau 

Report the set of missing or unknown keys. And give a hint about the
accepted keys.

The error message for multiple meta type members (visible in
tests/qapi-schema/double-type.err) is not improved.

Signed-off-by: Marc-André Lureau 
Reviewed-by: Markus Armbruster 
Message-Id: <20181213123724.4866-6-marcandre.lur...@redhat.com>
Signed-off-by: Markus Armbruster 
---
 scripts/qapi/common.py  | 21 ++---
 tests/qapi-schema/alternate-base.err|  1 +
 tests/qapi-schema/double-type.err   |  1 +
 tests/qapi-schema/unknown-expr-key.err  |  3 ++-
 tests/qapi-schema/unknown-expr-key.json |  2 +-
 5 files changed, 19 insertions(+), 9 deletions(-)

diff --git a/scripts/qapi/common.py b/scripts/qapi/common.py
index 18f5872808..f205805751 100644
--- a/scripts/qapi/common.py
+++ b/scripts/qapi/common.py
@@ -874,14 +874,21 @@ def check_struct(expr, info):
 
 
 def check_known_keys(info, source, keys, required, optional):
-for key in keys:
-if key not in required and key not in optional:
-raise QAPISemError(info, "Unknown key '%s' in %s" % (key, source))
 
-for key in required:
-if key not in keys:
-raise QAPISemError(info, "Key '%s' is missing from %s"
-   % (key, source))
+def pprint(elems):
+return ', '.join("'" + e + "'" for e in sorted(elems))
+
+missing = set(required) - set(keys)
+if missing:
+raise QAPISemError(info, "Key%s %s %s missing from %s"
+   % ('s' if len(missing) > 1 else '', pprint(missing),
+  'are' if len(missing) > 1 else 'is', source))
+allowed = set(required + optional)
+unknown = set(keys) - allowed
+if unknown:
+raise QAPISemError(info, "Unknown key%s %s in %s\nValid keys are %s."
+   % ('s' if len(unknown) > 1 else '', pprint(unknown),
+  source, pprint(allowed)))
 
 
 def check_keys(expr_elem, meta, required, optional=[]):
diff --git a/tests/qapi-schema/alternate-base.err 
b/tests/qapi-schema/alternate-base.err
index 30d8a34373..ebe05bc898 100644
--- a/tests/qapi-schema/alternate-base.err
+++ b/tests/qapi-schema/alternate-base.err
@@ -1 +1,2 @@
 tests/qapi-schema/alternate-base.json:4: Unknown key 'base' in alternate 'Alt'
+Valid keys are 'alternate', 'data', 'if'.
diff --git a/tests/qapi-schema/double-type.err 
b/tests/qapi-schema/double-type.err
index f9613c6d6b..799193dba1 100644
--- a/tests/qapi-schema/double-type.err
+++ b/tests/qapi-schema/double-type.err
@@ -1 +1,2 @@
 tests/qapi-schema/double-type.json:2: Unknown key 'command' in struct 'bar'
+Valid keys are 'base', 'data', 'if', 'struct'.
diff --git a/tests/qapi-schema/unknown-expr-key.err 
b/tests/qapi-schema/unknown-expr-key.err
index 12f5ed5b43..6ff8bb99c5 100644
--- a/tests/qapi-schema/unknown-expr-key.err
+++ b/tests/qapi-schema/unknown-expr-key.err
@@ -1 +1,2 @@
-tests/qapi-schema/unknown-expr-key.json:2: Unknown key 'bogus' in struct 'bar'
+tests/qapi-schema/unknown-expr-key.json:2: Unknown keys 'bogus', 'phony' in 
struct 'bar'
+Valid keys are 'base', 'data', 'if', 'struct'.
diff --git a/tests/qapi-schema/unknown-expr-key.json 
b/tests/qapi-schema/unknown-expr-key.json
index 3b2be00cc4..13292d75ed 100644
--- a/tests/qapi-schema/unknown-expr-key.json
+++ b/tests/qapi-schema/unknown-expr-key.json
@@ -1,2 +1,2 @@
 # we reject an expression with unknown top-level keys
-{ 'struct': 'bar', 'data': { 'string': 'str'}, 'bogus': { } }
+{ 'struct': 'bar', 'data': { 'string': 'str'}, 'bogus': { }, 'phony': { } }
-- 
2.17.2




[Qemu-devel] [PULL 22/32] qapi-events: add 'if' condition to implicit event enum

2018-12-13 Thread Markus Armbruster
From: Marc-André Lureau 

Add condition to QAPIEvent enum members based on the event 'if'.

The generated code remains unconditional for now. Later patches
generate the conditionals (also there is no additional coverage of
this change in qapi-schema-test.out since the event_names enum is an
implicit type created by qapi/events.py).

Signed-off-by: Marc-André Lureau 
Reviewed-by: Markus Armbruster 
Message-Id: <20181213123724.4866-11-marcandre.lur...@redhat.com>
Signed-off-by: Markus Armbruster 
---
 scripts/qapi/events.py | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/scripts/qapi/events.py b/scripts/qapi/events.py
index f1b88d8786..37ee5de682 100644
--- a/scripts/qapi/events.py
+++ b/scripts/qapi/events.py
@@ -179,7 +179,7 @@ class QAPISchemaGenEventVisitor(QAPISchemaModularCVisitor):
 self._genh.add(gen_event_send_decl(name, arg_type, boxed))
 self._genc.add(gen_event_send(name, arg_type, boxed,
   self._event_enum_name))
-self._event_enum_members.append(QAPISchemaMember(name))
+self._event_enum_members.append(QAPISchemaMember(name, ifcond))
 
 
 def gen_events(schema, output_dir, prefix):
-- 
2.17.2




[Qemu-devel] [PULL 23/32] qapi: add a dictionary form for TYPE

2018-12-13 Thread Markus Armbruster
From: Marc-André Lureau 

Wherever a struct/union/alternate/command/event member with NAME: TYPE
form is accepted, desugar it to a NAME: { 'type': TYPE } form.

This will allow to add new member details, such as 'if' in the
following patch to introduce conditionals, or 'default' for default
values etc.

Signed-off-by: Marc-André Lureau 
Message-Id: <20181213123724.4866-13-marcandre.lur...@redhat.com>
Reviewed-by: Markus Armbruster 
Signed-off-by: Markus Armbruster 
---
 scripts/qapi/common.py| 70 ---
 tests/Makefile.include|  6 ++
 tests/qapi-schema/alternate-invalid-dict.err  |  1 +
 tests/qapi-schema/alternate-invalid-dict.exit |  1 +
 tests/qapi-schema/alternate-invalid-dict.json |  4 ++
 tests/qapi-schema/alternate-invalid-dict.out  |  0
 .../qapi-schema/event-member-invalid-dict.err |  1 +
 .../event-member-invalid-dict.exit|  1 +
 .../event-member-invalid-dict.json|  2 +
 .../qapi-schema/event-member-invalid-dict.out |  0
 tests/qapi-schema/event-nest-struct.json  |  2 +-
 .../flat-union-inline-invalid-dict.err|  1 +
 .../flat-union-inline-invalid-dict.exit   |  1 +
 .../flat-union-inline-invalid-dict.json   | 11 +++
 .../flat-union-inline-invalid-dict.out|  0
 tests/qapi-schema/flat-union-inline.json  |  2 +-
 .../nested-struct-data-invalid-dict.err   |  1 +
 .../nested-struct-data-invalid-dict.exit  |  1 +
 .../nested-struct-data-invalid-dict.json  |  3 +
 .../nested-struct-data-invalid-dict.out   |  0
 tests/qapi-schema/nested-struct-data.json |  2 +-
 tests/qapi-schema/qapi-schema-test.json   | 10 +--
 .../struct-member-invalid-dict.err|  1 +
 .../struct-member-invalid-dict.exit   |  1 +
 .../struct-member-invalid-dict.json   |  3 +
 .../struct-member-invalid-dict.out|  0
 .../qapi-schema/union-branch-invalid-dict.err |  1 +
 .../union-branch-invalid-dict.exit|  1 +
 .../union-branch-invalid-dict.json|  4 ++
 .../qapi-schema/union-branch-invalid-dict.out |  0
 30 files changed, 99 insertions(+), 32 deletions(-)
 create mode 100644 tests/qapi-schema/alternate-invalid-dict.err
 create mode 100644 tests/qapi-schema/alternate-invalid-dict.exit
 create mode 100644 tests/qapi-schema/alternate-invalid-dict.json
 create mode 100644 tests/qapi-schema/alternate-invalid-dict.out
 create mode 100644 tests/qapi-schema/event-member-invalid-dict.err
 create mode 100644 tests/qapi-schema/event-member-invalid-dict.exit
 create mode 100644 tests/qapi-schema/event-member-invalid-dict.json
 create mode 100644 tests/qapi-schema/event-member-invalid-dict.out
 create mode 100644 tests/qapi-schema/flat-union-inline-invalid-dict.err
 create mode 100644 tests/qapi-schema/flat-union-inline-invalid-dict.exit
 create mode 100644 tests/qapi-schema/flat-union-inline-invalid-dict.json
 create mode 100644 tests/qapi-schema/flat-union-inline-invalid-dict.out
 create mode 100644 tests/qapi-schema/nested-struct-data-invalid-dict.err
 create mode 100644 tests/qapi-schema/nested-struct-data-invalid-dict.exit
 create mode 100644 tests/qapi-schema/nested-struct-data-invalid-dict.json
 create mode 100644 tests/qapi-schema/nested-struct-data-invalid-dict.out
 create mode 100644 tests/qapi-schema/struct-member-invalid-dict.err
 create mode 100644 tests/qapi-schema/struct-member-invalid-dict.exit
 create mode 100644 tests/qapi-schema/struct-member-invalid-dict.json
 create mode 100644 tests/qapi-schema/struct-member-invalid-dict.out
 create mode 100644 tests/qapi-schema/union-branch-invalid-dict.err
 create mode 100644 tests/qapi-schema/union-branch-invalid-dict.exit
 create mode 100644 tests/qapi-schema/union-branch-invalid-dict.json
 create mode 100644 tests/qapi-schema/union-branch-invalid-dict.out

diff --git a/scripts/qapi/common.py b/scripts/qapi/common.py
index a609ffcfee..cdfe2bf2a5 100644
--- a/scripts/qapi/common.py
+++ b/scripts/qapi/common.py
@@ -588,11 +588,11 @@ def discriminator_find_enum_define(expr):
 if not base_members:
 return None
 
-discriminator_type = base_members.get(discriminator)
-if not discriminator_type:
+discriminator_value = base_members.get(discriminator)
+if not discriminator_value:
 return None
 
-return enum_types.get(discriminator_type)
+return enum_types.get(discriminator_value['type'])
 
 
 # Names must be letters, numbers, -, and _.  They must start with letter,
@@ -704,8 +704,10 @@ def check_type(info, source, value, allow_array=False,
% (source, key))
 # Todo: allow dictionaries to represent default values of
 # an optional argument.
-check_type(info, "Member '%s' of %s" % (key, source), arg,
-   allow_array=True,
+check_known_keys(info, "member '%s' of %s" % (key, source),
+ arg, ['type'], [])
+check_type(info, "Member '%s' of %s" % (key, 

[Qemu-devel] [PULL 21/32] qapi: add 'if' to enum members

2018-12-13 Thread Markus Armbruster
From: Marc-André Lureau 

QAPISchemaMember gains .ifcond for enum members: inherited classes,
such as QAPISchemaObjectTypeMember, will thus have an ifcond member
after this (those different types will also use the .ifcond to store
the condition and generate conditional code in the following patches).

The generated code remains unconditional for now. Later patches
generate the conditionals.

Signed-off-by: Marc-André Lureau 
Reviewed-by: Markus Armbruster 
Message-Id: <20181213123724.4866-10-marcandre.lur...@redhat.com>
Signed-off-by: Markus Armbruster 
---
 docs/devel/qapi-code-gen.txt   | 9 +
 scripts/qapi/common.py | 8 +---
 tests/Makefile.include | 1 +
 tests/qapi-schema/enum-dict-member-unknown.err | 2 +-
 tests/qapi-schema/enum-if-invalid.err  | 1 +
 tests/qapi-schema/enum-if-invalid.exit | 1 +
 tests/qapi-schema/enum-if-invalid.json | 3 +++
 tests/qapi-schema/enum-if-invalid.out  | 0
 tests/qapi-schema/qapi-schema-test.json| 5 +++--
 tests/qapi-schema/qapi-schema-test.out | 2 ++
 tests/qapi-schema/test-qapi.py | 1 +
 11 files changed, 27 insertions(+), 6 deletions(-)
 create mode 100644 tests/qapi-schema/enum-if-invalid.err
 create mode 100644 tests/qapi-schema/enum-if-invalid.exit
 create mode 100644 tests/qapi-schema/enum-if-invalid.json
 create mode 100644 tests/qapi-schema/enum-if-invalid.out

diff --git a/docs/devel/qapi-code-gen.txt b/docs/devel/qapi-code-gen.txt
index 2c8b392b20..7ba9066eac 100644
--- a/docs/devel/qapi-code-gen.txt
+++ b/docs/devel/qapi-code-gen.txt
@@ -752,6 +752,15 @@ gets its generated code guarded like this:
  #endif /* defined(HAVE_BAR) */
  #endif /* defined(CONFIG_FOO) */
 
+An enum value can be replaced by a dictionary with a 'name' and a 'if'
+key.
+
+Example: a conditional 'bar' enum member.
+
+{ 'enum': 'IfEnum', 'data':
+  [ 'foo',
+{ 'name' : 'bar', 'if': 'defined(IFCOND)' } ] }
+
 Please note that you are responsible to ensure that the C code will
 compile with an arbitrary combination of conditions, since the
 generators are unable to check it at this point.
diff --git a/scripts/qapi/common.py b/scripts/qapi/common.py
index b1cf33af21..a609ffcfee 100644
--- a/scripts/qapi/common.py
+++ b/scripts/qapi/common.py
@@ -871,7 +871,8 @@ def check_enum(expr, info):
 
 for member in members:
 source = "dictionary member of enum '%s'" % name
-check_known_keys(info, source, member, ['name'], [])
+check_known_keys(info, source, member, ['name'], ['if'])
+check_if(member, info)
 check_name(info, "Member of enum '%s'" % name, member['name'],
enum_member=True)
 
@@ -1345,9 +1346,10 @@ class QAPISchemaObjectType(QAPISchemaType):
 class QAPISchemaMember(object):
 role = 'member'
 
-def __init__(self, name):
+def __init__(self, name, ifcond=None):
 assert isinstance(name, str)
 self.name = name
+self.ifcond = listify_cond(ifcond)
 self.owner = None
 
 def set_owner(self, name):
@@ -1656,7 +1658,7 @@ class QAPISchema(object):
 qtype_values, 'QTYPE'))
 
 def _make_enum_members(self, values):
-return [QAPISchemaMember(v['name']) for v in values]
+return [QAPISchemaMember(v['name'], v.get('if')) for v in values]
 
 def _make_implicit_enum_type(self, name, info, ifcond, values):
 # See also QAPISchemaObjectTypeMember._pretty_owner()
diff --git a/tests/Makefile.include b/tests/Makefile.include
index 2e894c1037..3c9eea27fd 100644
--- a/tests/Makefile.include
+++ b/tests/Makefile.include
@@ -384,6 +384,7 @@ qapi-schema += enum-bad-name.json
 qapi-schema += enum-bad-prefix.json
 qapi-schema += enum-clash-member.json
 qapi-schema += enum-dict-member-unknown.json
+qapi-schema += enum-if-invalid.json
 qapi-schema += enum-int-member.json
 qapi-schema += enum-member-case.json
 qapi-schema += enum-missing-data.json
diff --git a/tests/qapi-schema/enum-dict-member-unknown.err 
b/tests/qapi-schema/enum-dict-member-unknown.err
index 76bd0471db..2aae618be0 100644
--- a/tests/qapi-schema/enum-dict-member-unknown.err
+++ b/tests/qapi-schema/enum-dict-member-unknown.err
@@ -1,2 +1,2 @@
 tests/qapi-schema/enum-dict-member-unknown.json:2: Unknown key 'bad-key' in 
dictionary member of enum 'MyEnum'
-Valid keys are 'name'.
+Valid keys are 'if', 'name'.
diff --git a/tests/qapi-schema/enum-if-invalid.err 
b/tests/qapi-schema/enum-if-invalid.err
new file mode 100644
index 00..54c3cf887b
--- /dev/null
+++ b/tests/qapi-schema/enum-if-invalid.err
@@ -0,0 +1 @@
+tests/qapi-schema/enum-if-invalid.json:2: 'if' condition must be a string or a 
list of strings
diff --git a/tests/qapi-schema/enum-if-invalid.exit 
b/tests/qapi-schema/enum-if-invalid.exit
new file mode 100644
index 00..d00491fd7e
--- /dev/null
+++ b/tests/qapi-schema/enum-if-invalid.exit
@@ -0,0 +1 @@
+1
diff 

[Qemu-devel] [PULL 25/32] qapi: add 'if' to union members

2018-12-13 Thread Markus Armbruster
From: Marc-André Lureau 

Add 'if' key to union members:

{ 'union': 'TestIfUnion', 'data':
'mem': { 'type': 'str', 'if': 'COND'} }

The generated code remains unconditional for now. Later patches
generate the conditionals.

Signed-off-by: Marc-André Lureau 
Reviewed-by: Markus Armbruster 
Message-Id: <20181213123724.4866-16-marcandre.lur...@redhat.com>
Signed-off-by: Markus Armbruster 
---
 docs/devel/qapi-code-gen.txt|  2 +-
 scripts/qapi/common.py  | 15 ---
 tests/qapi-schema/qapi-schema-test.json |  4 +++-
 tests/qapi-schema/qapi-schema-test.out  |  4 
 tests/qapi-schema/test-qapi.py  |  1 +
 5 files changed, 17 insertions(+), 9 deletions(-)

diff --git a/docs/devel/qapi-code-gen.txt b/docs/devel/qapi-code-gen.txt
index 3895808b4a..0a0e53ede5 100644
--- a/docs/devel/qapi-code-gen.txt
+++ b/docs/devel/qapi-code-gen.txt
@@ -754,7 +754,7 @@ gets its generated code guarded like this:
 
 Where a member can be defined with a single string value for its type,
 it is also possible to supply a dictionary instead with both 'type'
-and 'if' keys. (TODO: union and alternate)
+and 'if' keys. (TODO: alternate)
 
 Example: a conditional 'bar' member
 
diff --git a/scripts/qapi/common.py b/scripts/qapi/common.py
index 98e9d6f109..44fe8868ed 100644
--- a/scripts/qapi/common.py
+++ b/scripts/qapi/common.py
@@ -803,7 +803,7 @@ def check_union(expr, info):
 check_name(info, "Member of union '%s'" % name, key)
 
 check_known_keys(info, "member '%s' of union '%s'" % (key, name),
- value, ['type'], [])
+ value, ['type'], ['if'])
 # Each value must name a known type
 check_type(info, "Member '%s' of union '%s'" % (key, name),
value['type'],
@@ -1483,8 +1483,8 @@ class QAPISchemaObjectTypeVariants(object):
 class QAPISchemaObjectTypeVariant(QAPISchemaObjectTypeMember):
 role = 'branch'
 
-def __init__(self, name, typ):
-QAPISchemaObjectTypeMember.__init__(self, name, typ, False)
+def __init__(self, name, typ, ifcond=None):
+QAPISchemaObjectTypeMember.__init__(self, name, typ, False, ifcond)
 
 
 class QAPISchemaAlternateType(QAPISchemaType):
@@ -1757,14 +1757,14 @@ class QAPISchema(object):
 def _make_variant(self, case, typ):
 return QAPISchemaObjectTypeVariant(case, typ)
 
-def _make_simple_variant(self, case, typ, info):
+def _make_simple_variant(self, case, typ, ifcond, info):
 if isinstance(typ, list):
 assert len(typ) == 1
 typ = self._make_array_type(typ[0], info)
 typ = self._make_implicit_object_type(
 typ, info, None, self.lookup_type(typ),
 'wrapper', [self._make_member('data', typ, None, info)])
-return QAPISchemaObjectTypeVariant(case, typ)
+return QAPISchemaObjectTypeVariant(case, typ, ifcond)
 
 def _def_union_type(self, expr, info, doc):
 name = expr['union']
@@ -1782,9 +1782,10 @@ class QAPISchema(object):
 for (key, value) in data.items()]
 members = []
 else:
-variants = [self._make_simple_variant(key, value['type'], info)
+variants = [self._make_simple_variant(key, value['type'],
+  value.get('if'), info)
 for (key, value) in data.items()]
-enum = [{'name': v.name} for v in variants]
+enum = [{'name': v.name, 'if': v.ifcond} for v in variants]
 typ = self._make_implicit_enum_type(name, info, ifcond, enum)
 tag_member = QAPISchemaObjectTypeMember('type', typ, False)
 members = [tag_member]
diff --git a/tests/qapi-schema/qapi-schema-test.json 
b/tests/qapi-schema/qapi-schema-test.json
index c46f3b5732..a33eff8f86 100644
--- a/tests/qapi-schema/qapi-schema-test.json
+++ b/tests/qapi-schema/qapi-schema-test.json
@@ -210,7 +210,9 @@
   [ 'foo', { 'name' : 'bar', 'if': 'defined(TEST_IF_ENUM_BAR)' } ],
   'if': 'defined(TEST_IF_ENUM)' }
 
-{ 'union': 'TestIfUnion', 'data': { 'foo': 'TestStruct' },
+{ 'union': 'TestIfUnion', 'data':
+  { 'foo': 'TestStruct',
+'union_bar': { 'type': 'str', 'if': 'defined(TEST_IF_UNION_BAR)'} },
   'if': 'defined(TEST_IF_UNION) && defined(TEST_IF_STRUCT)' }
 
 { 'command': 'TestIfUnionCmd', 'data': { 'union_cmd_arg': 'TestIfUnion' },
diff --git a/tests/qapi-schema/qapi-schema-test.out 
b/tests/qapi-schema/qapi-schema-test.out
index 7987b23403..f4c11f1e6a 100644
--- a/tests/qapi-schema/qapi-schema-test.out
+++ b/tests/qapi-schema/qapi-schema-test.out
@@ -280,11 +280,15 @@ object q_obj_TestStruct-wrapper
 member data: TestStruct optional=False
 enum TestIfUnionKind
 member foo
+member union_bar
+if ['defined(TEST_IF_UNION_BAR)']
 if ['defined(TEST_IF_UNION) && defined(TEST_IF_STRUCT)']
 object TestIfUnion
 member type: TestIfUnionKind optional=False
 tag type

[Qemu-devel] [PULL 28/32] qapi: add 'If:' condition to enum values documentation

2018-12-13 Thread Markus Armbruster
From: Marc-André Lureau 

Use a common function to generate the "If:..." line.

While at it, get rid of the existing \n\n (no idea why it was
there). Use a line-break in member description, this seems to look
slightly better in the plaintext version.

Signed-off-by: Marc-André Lureau 
Message-Id: <20181213123724.4866-19-marcandre.lur...@redhat.com>
Reviewed-by: Markus Armbruster 
Signed-off-by: Markus Armbruster 
---
 scripts/qapi/doc.py | 25 -
 tests/qapi-schema/doc-good.json |  4 +++-
 tests/qapi-schema/doc-good.out  |  1 +
 tests/qapi-schema/doc-good.texi |  2 +-
 4 files changed, 21 insertions(+), 11 deletions(-)

diff --git a/scripts/qapi/doc.py b/scripts/qapi/doc.py
index 76cb186ff9..ab36b9dec6 100755
--- a/scripts/qapi/doc.py
+++ b/scripts/qapi/doc.py
@@ -126,19 +126,27 @@ def texi_body(doc):
 return texi_format(doc.body.text)
 
 
-def texi_enum_value(value):
+def texi_if(ifcond, prefix='\n', suffix='\n'):
+"""Format the #if condition"""
+if not ifcond:
+return ''
+return '%s@b{If:} @code{%s}%s' % (prefix, ', '.join(ifcond), suffix)
+
+
+def texi_enum_value(value, desc, suffix):
 """Format a table of members item for an enumeration value"""
-return '@item @code{%s}\n' % value.name
+return '@item @code{%s}\n%s%s' % (
+value.name, desc, texi_if(value.ifcond, prefix='@*'))
 
 
-def texi_member(member, suffix=''):
+def texi_member(member, desc, suffix):
 """Format a table of members item for an object type member"""
 typ = member.type.doc_type()
 membertype = ': ' + typ if typ else ''
-return '@item @code{%s%s}%s%s\n' % (
+return '@item @code{%s%s}%s%s\n%s' % (
 member.name, membertype,
 ' (optional)' if member.optional else '',
-suffix)
+suffix, desc)
 
 
 def texi_members(doc, what, base, variants, member_func):
@@ -155,7 +163,7 @@ def texi_members(doc, what, base, variants, member_func):
 desc = 'One of ' + members_text + '\n'
 else:
 desc = 'Not documented\n'
-items += member_func(section.member) + desc
+items += member_func(section.member, desc, suffix='')
 if base:
 items += '@item The members of @code{%s}\n' % base.doc_type()
 if variants:
@@ -165,7 +173,7 @@ def texi_members(doc, what, base, variants, member_func):
 if v.type.is_implicit():
 assert not v.type.base and not v.type.variants
 for m in v.type.local_members:
-items += member_func(m, when)
+items += member_func(m, desc='', suffix=when)
 else:
 items += '@item The members of @code{%s}%s\n' % (
 v.type.doc_type(), when)
@@ -185,8 +193,7 @@ def texi_sections(doc, ifcond):
 body += texi_example(section.text)
 else:
 body += texi_format(section.text)
-if ifcond:
-body += '\n\n@b{If:} @code{%s}' % ", ".join(ifcond)
+body += texi_if(ifcond, suffix='')
 return body
 
 
diff --git a/tests/qapi-schema/doc-good.json b/tests/qapi-schema/doc-good.json
index 984cd8ed06..1cd4935710 100644
--- a/tests/qapi-schema/doc-good.json
+++ b/tests/qapi-schema/doc-good.json
@@ -55,7 +55,9 @@
 #
 # @two is undocumented
 ##
-{ 'enum': 'Enum', 'data': [ 'one', 'two' ], 'if': 'defined(IFCOND)' }
+{ 'enum': 'Enum', 'data':
+  [ { 'name': 'one', 'if': 'defined(IFONE)' }, 'two' ],
+  'if': 'defined(IFCOND)' }
 
 ##
 # @Base:
diff --git a/tests/qapi-schema/doc-good.out b/tests/qapi-schema/doc-good.out
index c2fc5c774a..53bd177f7d 100644
--- a/tests/qapi-schema/doc-good.out
+++ b/tests/qapi-schema/doc-good.out
@@ -11,6 +11,7 @@ enum QType
 module doc-good.json
 enum Enum
 member one
+if ['defined(IFONE)']
 member two
 if ['defined(IFCOND)']
 object Base
diff --git a/tests/qapi-schema/doc-good.texi b/tests/qapi-schema/doc-good.texi
index e42eace474..405055b146 100644
--- a/tests/qapi-schema/doc-good.texi
+++ b/tests/qapi-schema/doc-good.texi
@@ -84,12 +84,12 @@ Examples:
 @table @asis
 @item @code{one}
 The @emph{one} @{and only@}
+@*@b{If:} @code{defined(IFONE)}
 @item @code{two}
 Not documented
 @end table
 @code{two} is undocumented
 
-
 @b{If:} @code{defined(IFCOND)}
 @end deftp
 
-- 
2.17.2




[Qemu-devel] [PULL 20/32] qapi: add a dictionary form with 'name' key for enum members

2018-12-13 Thread Markus Armbruster
From: Marc-André Lureau 

Desugar the enum NAME form to { 'name': NAME }. This will allow to add
new enum members, such as 'if' in the following patch.

Signed-off-by: Marc-André Lureau 
Message-Id: <20181213123724.4866-7-marcandre.lur...@redhat.com>
Message-Id: <20181213123724.4866-8-marcandre.lur...@redhat.com>
Message-Id: <20181213123724.4866-9-marcandre.lur...@redhat.com>
Reviewed-by: Markus Armbruster 
[Harmless accidental move backed out, long line wrapped, patches
squashed]
Signed-off-by: Markus Armbruster 
---
 scripts/qapi/common.py| 36 +--
 tests/Makefile.include|  3 +-
 tests/qapi-schema/enum-bad-member.err |  1 +
 ...-dict-member.exit => enum-bad-member.exit} |  0
 tests/qapi-schema/enum-bad-member.json|  2 ++
 ...um-dict-member.out => enum-bad-member.out} |  0
 .../qapi-schema/enum-dict-member-unknown.err  |  2 ++
 .../qapi-schema/enum-dict-member-unknown.exit |  1 +
 .../qapi-schema/enum-dict-member-unknown.json |  2 ++
 .../qapi-schema/enum-dict-member-unknown.out  |  0
 tests/qapi-schema/enum-dict-member.err|  1 -
 tests/qapi-schema/enum-dict-member.json   |  2 --
 12 files changed, 36 insertions(+), 14 deletions(-)
 create mode 100644 tests/qapi-schema/enum-bad-member.err
 rename tests/qapi-schema/{enum-dict-member.exit => enum-bad-member.exit} (100%)
 create mode 100644 tests/qapi-schema/enum-bad-member.json
 rename tests/qapi-schema/{enum-dict-member.out => enum-bad-member.out} (100%)
 create mode 100644 tests/qapi-schema/enum-dict-member-unknown.err
 create mode 100644 tests/qapi-schema/enum-dict-member-unknown.exit
 create mode 100644 tests/qapi-schema/enum-dict-member-unknown.json
 create mode 100644 tests/qapi-schema/enum-dict-member-unknown.out
 delete mode 100644 tests/qapi-schema/enum-dict-member.err
 delete mode 100644 tests/qapi-schema/enum-dict-member.json

diff --git a/scripts/qapi/common.py b/scripts/qapi/common.py
index f205805751..b1cf33af21 100644
--- a/scripts/qapi/common.py
+++ b/scripts/qapi/common.py
@@ -740,6 +740,10 @@ def check_event(expr, info):
allow_metas=meta)
 
 
+def enum_get_names(expr):
+return [e['name'] for e in expr['data']]
+
+
 def check_union(expr, info):
 name = expr['union']
 base = expr.get('base')
@@ -799,7 +803,7 @@ def check_union(expr, info):
 # If the discriminator names an enum type, then all members
 # of 'data' must also be members of the enum type.
 if enum_define:
-if key not in enum_define['data']:
+if key not in enum_get_names(enum_define):
 raise QAPISemError(info,
"Discriminator value '%s' is not found in "
"enum '%s'"
@@ -831,7 +835,7 @@ def check_alternate(expr, info):
 if qtype == 'QTYPE_QSTRING':
 enum_expr = enum_types.get(value)
 if enum_expr:
-for v in enum_expr['data']:
+for v in enum_get_names(enum_expr):
 if v in ['on', 'off']:
 conflicting.add('QTYPE_QBOOL')
 if re.match(r'[-+0-9.]', v): # lazy, could be tightened
@@ -847,9 +851,15 @@ def check_alternate(expr, info):
 types_seen[qt] = key
 
 
+def normalize_enum(expr):
+if isinstance(expr['data'], list):
+expr['data'] = [m if isinstance(m, dict) else {'name': m}
+for m in expr['data']]
+
+
 def check_enum(expr, info):
 name = expr['enum']
-members = expr.get('data')
+members = expr['data']
 prefix = expr.get('prefix')
 
 if not isinstance(members, list):
@@ -858,8 +868,11 @@ def check_enum(expr, info):
 if prefix is not None and not isinstance(prefix, str):
 raise QAPISemError(info,
"Enum '%s' requires a string for 'prefix'" % name)
+
 for member in members:
-check_name(info, "Member of enum '%s'" % name, member,
+source = "dictionary member of enum '%s'" % name
+check_known_keys(info, source, member, ['name'], [])
+check_name(info, "Member of enum '%s'" % name, member['name'],
enum_member=True)
 
 
@@ -937,6 +950,7 @@ def check_exprs(exprs):
 if 'enum' in expr:
 meta = 'enum'
 check_keys(expr_elem, 'enum', ['data'], ['if', 'prefix'])
+normalize_enum(expr)
 enum_types[expr[meta]] = expr
 elif 'union' in expr:
 meta = 'union'
@@ -1633,14 +1647,16 @@ class QAPISchema(object):
 self.the_empty_object_type = QAPISchemaObjectType(
 'q_empty', None, None, None, None, [], None)
 self._def_entity(self.the_empty_object_type)
-qtype_values = self._make_enum_members(['none', 'qnull', 'qnum',
-'qstring', 'qdict', 'qlist',
-'qbool'])
+
+

[Qemu-devel] [PULL 30/32] qapi: add condition to variants documentation

2018-12-13 Thread Markus Armbruster
From: Marc-André Lureau 

Signed-off-by: Marc-André Lureau 
Message-Id: <20181213123724.4866-21-marcandre.lur...@redhat.com>
Reviewed-by: Markus Armbruster 
Signed-off-by: Markus Armbruster 
---
 scripts/qapi/doc.py | 4 ++--
 tests/qapi-schema/doc-good.json | 4 ++--
 tests/qapi-schema/doc-good.out  | 3 +++
 tests/qapi-schema/doc-good.texi | 4 ++--
 4 files changed, 9 insertions(+), 6 deletions(-)

diff --git a/scripts/qapi/doc.py b/scripts/qapi/doc.py
index b6f834b917..c03b690161 100755
--- a/scripts/qapi/doc.py
+++ b/scripts/qapi/doc.py
@@ -168,8 +168,8 @@ def texi_members(doc, what, base, variants, member_func):
 items += '@item The members of @code{%s}\n' % base.doc_type()
 if variants:
 for v in variants.variants:
-when = ' when @code{%s} is @t{"%s"}' % (
-variants.tag_member.name, v.name)
+when = ' when @code{%s} is @t{"%s"}%s' % (
+variants.tag_member.name, v.name, texi_if(v.ifcond, " (", ")"))
 if v.type.is_implicit():
 assert not v.type.base and not v.type.variants
 for m in v.type.local_members:
diff --git a/tests/qapi-schema/doc-good.json b/tests/qapi-schema/doc-good.json
index 28992fc615..f7fb48af38 100644
--- a/tests/qapi-schema/doc-good.json
+++ b/tests/qapi-schema/doc-good.json
@@ -86,13 +86,13 @@
 { 'union': 'Object',
   'base': 'Base',
   'discriminator': 'base1',
-  'data': { 'one': 'Variant1', 'two': 'Variant2' } }
+  'data': { 'one': 'Variant1', 'two': { 'type': 'Variant2', 'if': 'IFTWO' } } }
 
 ##
 # @SugaredUnion:
 ##
 { 'union': 'SugaredUnion',
-  'data': { 'one': 'Variant1', 'two': 'Variant2' } }
+  'data': { 'one': 'Variant1', 'two': { 'type': 'Variant2', 'if': 'IFTWO' } } }
 
 ##
 # == Another subsection
diff --git a/tests/qapi-schema/doc-good.out b/tests/qapi-schema/doc-good.out
index 4ab55683ce..21bf345ff0 100644
--- a/tests/qapi-schema/doc-good.out
+++ b/tests/qapi-schema/doc-good.out
@@ -25,6 +25,7 @@ object Object
 tag base1
 case one: Variant1
 case two: Variant2
+if ['IFTWO']
 object q_obj_Variant1-wrapper
 member data: Variant1 optional=False
 object q_obj_Variant2-wrapper
@@ -32,11 +33,13 @@ object q_obj_Variant2-wrapper
 enum SugaredUnionKind
 member one
 member two
+if ['IFTWO']
 object SugaredUnion
 member type: SugaredUnionKind optional=False
 tag type
 case one: q_obj_Variant1-wrapper
 case two: q_obj_Variant2-wrapper
+if ['IFTWO']
 object q_obj_cmd-arg
 member arg1: int optional=False
 member arg2: str optional=True
diff --git a/tests/qapi-schema/doc-good.texi b/tests/qapi-schema/doc-good.texi
index f87f9faacb..2526abc6d9 100644
--- a/tests/qapi-schema/doc-good.texi
+++ b/tests/qapi-schema/doc-good.texi
@@ -142,7 +142,7 @@ Not documented
 @table @asis
 @item The members of @code{Base}
 @item The members of @code{Variant1} when @code{base1} is @t{"one"}
-@item The members of @code{Variant2} when @code{base1} is @t{"two"}
+@item The members of @code{Variant2} when @code{base1} is @t{"two"} (@b{If:} 
@code{IFTWO})
 @end table
 
 @end deftp
@@ -158,7 +158,7 @@ Not documented
 @item @code{type}
 One of @t{"one"}, @t{"two"}
 @item @code{data: Variant1} when @code{type} is @t{"one"}
-@item @code{data: Variant2} when @code{type} is @t{"two"}
+@item @code{data: Variant2} when @code{type} is @t{"two"} (@b{If:} 
@code{IFTWO})
 @end table
 
 @end deftp
-- 
2.17.2




[Qemu-devel] [PULL 27/32] qapi: add #if conditions to generated code members

2018-12-13 Thread Markus Armbruster
From: Marc-André Lureau 

Wrap generated enum and struct members and their supporting code with

We do enum and struct in a single patch because union tag enum and the
associated variants tie them together, and dealing with that to split
the patch doesn't seem worthwhile.

Signed-off-by: Marc-André Lureau 
Reviewed-by: Markus Armbruster 
Message-Id: <20181213123724.4866-18-marcandre.lur...@redhat.com>
Signed-off-by: Markus Armbruster 
---
 scripts/qapi/common.py |  4 
 scripts/qapi/introspect.py | 14 ++
 scripts/qapi/types.py  |  4 
 scripts/qapi/visit.py  |  6 ++
 4 files changed, 24 insertions(+), 4 deletions(-)

diff --git a/scripts/qapi/common.py b/scripts/qapi/common.py
index 17707b6de7..8c2d97369e 100644
--- a/scripts/qapi/common.py
+++ b/scripts/qapi/common.py
@@ -2078,11 +2078,13 @@ const QEnumLookup %(c_name)s_lookup = {
 ''',
 c_name=c_name(name))
 for m in members:
+ret += gen_if(m.ifcond)
 index = c_enum_const(name, m.name, prefix)
 ret += mcgen('''
 [%(index)s] = "%(name)s",
 ''',
  index=index, name=m.name)
+ret += gen_endif(m.ifcond)
 
 ret += mcgen('''
 },
@@ -2104,10 +2106,12 @@ typedef enum %(c_name)s {
 c_name=c_name(name))
 
 for m in enum_members:
+ret += gen_if(m.ifcond)
 ret += mcgen('''
 %(c_enum)s,
 ''',
  c_enum=c_enum_const(name, m.name, prefix))
+ret += gen_endif(m.ifcond)
 
 ret += mcgen('''
 } %(c_name)s;
diff --git a/scripts/qapi/introspect.py b/scripts/qapi/introspect.py
index 417625d54b..f7f2ca07e4 100644
--- a/scripts/qapi/introspect.py
+++ b/scripts/qapi/introspect.py
@@ -162,6 +162,8 @@ const QLitObject %(c_name)s = %(c_string)s;
 ret = {'name': member.name, 'type': self._use_type(member.type)}
 if member.optional:
 ret['default'] = None
+if member.ifcond:
+ret = (ret, {'if': member.ifcond})
 return ret
 
 def _gen_variants(self, tag_name, variants):
@@ -169,14 +171,17 @@ const QLitObject %(c_name)s = %(c_string)s;
 'variants': [self._gen_variant(v) for v in variants]}
 
 def _gen_variant(self, variant):
-return {'case': variant.name, 'type': self._use_type(variant.type)}
+return ({'case': variant.name, 'type': self._use_type(variant.type)},
+{'if': variant.ifcond})
 
 def visit_builtin_type(self, name, info, json_type):
 self._gen_qlit(name, 'builtin', {'json-type': json_type}, [])
 
 def visit_enum_type(self, name, info, ifcond, members, prefix):
 self._gen_qlit(name, 'enum',
-   {'values': [m.name for m in members]}, ifcond)
+   {'values':
+[(m.name, {'if': m.ifcond}) for m in members]},
+   ifcond)
 
 def visit_array_type(self, name, info, ifcond, element_type):
 element = self._use_type(element_type)
@@ -192,8 +197,9 @@ const QLitObject %(c_name)s = %(c_string)s;
 
 def visit_alternate_type(self, name, info, ifcond, variants):
 self._gen_qlit(name, 'alternate',
-   {'members': [{'type': self._use_type(m.type)}
-for m in variants.variants]}, ifcond)
+   {'members': [
+   ({'type': self._use_type(m.type)}, {'if': m.ifcond})
+   for m in variants.variants]}, ifcond)
 
 def visit_command(self, name, info, ifcond, arg_type, ret_type, gen,
   success_response, boxed, allow_oob, allow_preconfig):
diff --git a/scripts/qapi/types.py b/scripts/qapi/types.py
index e8d22c5081..62d4cf9f95 100644
--- a/scripts/qapi/types.py
+++ b/scripts/qapi/types.py
@@ -43,6 +43,7 @@ struct %(c_name)s {
 def gen_struct_members(members):
 ret = ''
 for memb in members:
+ret += gen_if(memb.ifcond)
 if memb.optional:
 ret += mcgen('''
 bool has_%(c_name)s;
@@ -52,6 +53,7 @@ def gen_struct_members(members):
 %(c_type)s %(c_name)s;
 ''',
  c_type=memb.type.c_type(), c_name=c_name(memb.name))
+ret += gen_endif(memb.ifcond)
 return ret
 
 
@@ -131,11 +133,13 @@ def gen_variants(variants):
 for var in variants.variants:
 if var.type.name == 'q_empty':
 continue
+ret += gen_if(var.ifcond)
 ret += mcgen('''
 %(c_type)s %(c_name)s;
 ''',
  c_type=var.type.c_unboxed_type(),
  c_name=c_name(var.name))
+ret += gen_endif(var.ifcond)
 
 ret += mcgen('''
 } u;
diff --git a/scripts/qapi/visit.py b/scripts/qapi/visit.py
index 24f85a2e85..82eab72b21 100644
--- a/scripts/qapi/visit.py
+++ b/scripts/qapi/visit.py
@@ -54,6 +54,7 @@ void visit_type_%(c_name)s_members(Visitor *v, %(c_name)s 
*obj, Error **errp)
  c_type=base.c_name())
 
 for 

[Qemu-devel] [PULL 09/32] test-string-input-visitor: Add range overflow tests

2018-12-13 Thread Markus Armbruster
From: David Hildenbrand 

Let's make sure that the range handling code can properly deal with
ranges that end at the biggest possible number.

Reviewed-by: Markus Armbruster 
Signed-off-by: David Hildenbrand 
Message-Id: <20181121164421.20780-10-da...@redhat.com>
Signed-off-by: Markus Armbruster 
---
 tests/test-string-input-visitor.c | 10 ++
 1 file changed, 10 insertions(+)

diff --git a/tests/test-string-input-visitor.c 
b/tests/test-string-input-visitor.c
index 9b1dd44b2d..34b54dfc89 100644
--- a/tests/test-string-input-visitor.c
+++ b/tests/test-string-input-visitor.c
@@ -112,6 +112,7 @@ static void test_visitor_in_intList(TestInputVisitorData 
*data,
 int64_t expect2[] = { 32767, -32768, -32767 };
 int64_t expect3[] = { INT64_MIN, INT64_MAX };
 int64_t expect4[] = { 1 };
+int64_t expect5[] = { INT64_MAX - 2,  INT64_MAX - 1, INT64_MAX };
 Error *err = NULL;
 int64List *res = NULL;
 Visitor *v;
@@ -132,6 +133,10 @@ static void test_visitor_in_intList(TestInputVisitorData 
*data,
 v = visitor_input_test_init(data, "1-1");
 check_ilist(v, expect4, ARRAY_SIZE(expect4));
 
+v = visitor_input_test_init(data,
+"9223372036854775805-9223372036854775807");
+check_ilist(v, expect5, ARRAY_SIZE(expect5));
+
 /* Value too large */
 
 v = visitor_input_test_init(data, "9223372036854775808");
@@ -216,6 +221,7 @@ static void test_visitor_in_uintList(TestInputVisitorData 
*data,
 uint64_t expect3[] = { INT64_MIN, INT64_MAX };
 uint64_t expect4[] = { 1 };
 uint64_t expect5[] = { UINT64_MAX };
+uint64_t expect6[] = { UINT64_MAX - 2,  UINT64_MAX - 1, UINT64_MAX };
 Error *err = NULL;
 uint64List *res = NULL;
 Visitor *v;
@@ -239,6 +245,10 @@ static void test_visitor_in_uintList(TestInputVisitorData 
*data,
 v = visitor_input_test_init(data, "18446744073709551615");
 check_ulist(v, expect5, ARRAY_SIZE(expect5));
 
+v = visitor_input_test_init(data,
+"18446744073709551613-18446744073709551615");
+check_ulist(v, expect6, ARRAY_SIZE(expect6));
+
 /* Value too large */
 
 v = visitor_input_test_init(data, "18446744073709551616");
-- 
2.17.2




[Qemu-devel] [PULL 31/32] qapi: add more conditions to SPICE

2018-12-13 Thread Markus Armbruster
From: Marc-André Lureau 

Now that member can be made conditional, let's make SPICE chardev
conditional:

* spiceport, spicevmc

  Before and after the patch for !CONFIG_SPICE, the error is the
  same ('spiceport' is not a valid char driver name).

Signed-off-by: Marc-André Lureau 
Reviewed-by: Markus Armbruster 
Message-Id: <20181213123724.4866-22-marcandre.lur...@redhat.com>
Signed-off-by: Markus Armbruster 
---
 qapi/char.json | 16 
 1 file changed, 8 insertions(+), 8 deletions(-)

diff --git a/qapi/char.json b/qapi/char.json
index 24628331ec..77ed847972 100644
--- a/qapi/char.json
+++ b/qapi/char.json
@@ -332,8 +332,8 @@
 ##
 { 'struct': 'ChardevSpiceChannel',
   'data': { 'type': 'str' },
-  'base': 'ChardevCommon' }
-# TODO: 'if': 'defined(CONFIG_SPICE)'
+  'base': 'ChardevCommon',
+  'if': 'defined(CONFIG_SPICE)' }
 
 ##
 # @ChardevSpicePort:
@@ -346,8 +346,8 @@
 ##
 { 'struct': 'ChardevSpicePort',
   'data': { 'fqdn': 'str' },
-  'base': 'ChardevCommon' }
-# TODO: 'if': 'defined(CONFIG_SPICE)'
+  'base': 'ChardevCommon',
+  'if': 'defined(CONFIG_SPICE)' }
 
 ##
 # @ChardevVC:
@@ -404,10 +404,10 @@
 'testdev': 'ChardevCommon',
 'stdio': 'ChardevStdio',
 'console': 'ChardevCommon',
-'spicevmc': 'ChardevSpiceChannel',
-# TODO: { 'type': 'ChardevSpiceChannel', 'if': 'defined(CONFIG_SPICE)' },
-'spiceport': 'ChardevSpicePort',
-# TODO: { 'type': 'ChardevSpicePort', 'if': 'defined(CONFIG_SPICE)' },
+'spicevmc': { 'type': 'ChardevSpiceChannel',
+  'if': 'defined(CONFIG_SPICE)' },
+'spiceport': { 'type': 'ChardevSpicePort',
+   'if': 'defined(CONFIG_SPICE)' },
 'vc': 'ChardevVC',
 'ringbuf': 'ChardevRingbuf',
 # next one is just for compatibility
-- 
2.17.2




[Qemu-devel] [PULL 11/32] json: Fix to reject duplicate object member names

2018-12-13 Thread Markus Armbruster
The JSON parser happily accepts duplicate object member names.  The
last value wins.  Reproducer #1:

$ qemu-system-x86_64 -qmp stdio
{"QMP": {"version": {"qemu": {"micro": 93, "minor": 0, "major": 3},
"package": "v3.1.0-rc3-7-g87a45d86ed"}, "capabilities": []}}
{'execute':'qmp_capabilities'}
{"return": {}}
{'execute':'blockdev-add','arguments':{'driver':'null-co',
 'node-name':'foo','node-name':'bar'}}
{"return": {}}
{'execute':'query-named-block-nodes'}
{"return": [{ [...] "node-name": "bar" [...] }]}

Reproducer #2 is iotest 229.

Fix the parser to reject duplicates, and fix iotest 229 not to use
them.

Reported-by: Max Reitz 
Signed-off-by: Markus Armbruster 
Message-Id: <20181206121743.20762-1-arm...@redhat.com>
Reviewed-by: Daniel P. Berrangé 
Reviewed-by: Philippe Mathieu-Daudé 
[Trailing whitespace tidied up]
Signed-off-by: Markus Armbruster 
---
 qobject/json-parser.c  | 5 +
 tests/qemu-iotests/229 | 1 -
 2 files changed, 5 insertions(+), 1 deletion(-)

diff --git a/qobject/json-parser.c b/qobject/json-parser.c
index 5a840dfd86..7a7ae9e8d1 100644
--- a/qobject/json-parser.c
+++ b/qobject/json-parser.c
@@ -288,6 +288,11 @@ static int parse_pair(JSONParserContext *ctxt, QDict *dict)
 goto out;
 }
 
+if (qdict_haskey(dict, qstring_get_str(key))) {
+parse_error(ctxt, token, "duplicate key");
+goto out;
+}
+
 qdict_put_obj(dict, qstring_get_str(key), value);
 
 qobject_unref(key);
diff --git a/tests/qemu-iotests/229 b/tests/qemu-iotests/229
index 86602437ff..893d098ad2 100755
--- a/tests/qemu-iotests/229
+++ b/tests/qemu-iotests/229
@@ -69,7 +69,6 @@ echo
 _send_qemu_cmd $QEMU_HANDLE \
 "{'execute': 'drive-mirror',
  'arguments': {'device': 'testdisk',
-   'mode':   'absolute-paths',
'format': '$IMGFMT',
'target': '$DEST_IMG',
'sync':   'full',
-- 
2.17.2




[Qemu-devel] [PULL 12/32] tests/qapi: Cover commands with 'if' and union / alternate 'data'

2018-12-13 Thread Markus Armbruster
From: Marc-André Lureau 

Forgotten in commit 967c885108f.

Signed-off-by: Marc-André Lureau 
Message-Id: <20181208111606.8505-19-marcandre.lur...@redhat.com>
Message-Id: <20181208111606.8505-21-marcandre.lur...@redhat.com>
Reviewed-by: Markus Armbruster 
[Squashed, commit message adjusted]
Signed-off-by: Markus Armbruster 
---
 tests/qapi-schema/qapi-schema-test.json |  6 ++
 tests/qapi-schema/qapi-schema-test.out  | 12 
 2 files changed, 18 insertions(+)

diff --git a/tests/qapi-schema/qapi-schema-test.json 
b/tests/qapi-schema/qapi-schema-test.json
index fb03163430..15388ae9a4 100644
--- a/tests/qapi-schema/qapi-schema-test.json
+++ b/tests/qapi-schema/qapi-schema-test.json
@@ -210,9 +210,15 @@
 { 'union': 'TestIfUnion', 'data': { 'foo': 'TestStruct' },
   'if': 'defined(TEST_IF_UNION) && defined(TEST_IF_STRUCT)' }
 
+{ 'command': 'TestIfUnionCmd', 'data': { 'union_cmd_arg': 'TestIfUnion' },
+  'if': 'defined(TEST_IF_UNION)' }
+
 { 'alternate': 'TestIfAlternate', 'data': { 'foo': 'int', 'bar': 'TestStruct' 
},
   'if': 'defined(TEST_IF_ALT) && defined(TEST_IF_STRUCT)' }
 
+{ 'command': 'TestIfAlternateCmd', 'data': { 'alt_cmd_arg': 'TestIfAlternate' 
},
+  'if': 'defined(TEST_IF_ALT)' }
+
 { 'command': 'TestIfCmd', 'data': { 'foo': 'TestIfStruct' },
   'returns': 'UserDefThree',
   'if': ['defined(TEST_IF_CMD)', 'defined(TEST_IF_STRUCT)'] }
diff --git a/tests/qapi-schema/qapi-schema-test.out 
b/tests/qapi-schema/qapi-schema-test.out
index 218ac7d556..3ca858dd0e 100644
--- a/tests/qapi-schema/qapi-schema-test.out
+++ b/tests/qapi-schema/qapi-schema-test.out
@@ -251,11 +251,23 @@ object TestIfUnion
 tag type
 case foo: q_obj_TestStruct-wrapper
 if ['defined(TEST_IF_UNION) && defined(TEST_IF_STRUCT)']
+object q_obj_TestIfUnionCmd-arg
+member union_cmd_arg: TestIfUnion optional=False
+if ['defined(TEST_IF_UNION)']
+command TestIfUnionCmd q_obj_TestIfUnionCmd-arg -> None
+   gen=True success_response=True boxed=False oob=False preconfig=False
+if ['defined(TEST_IF_UNION)']
 alternate TestIfAlternate
 tag type
 case foo: int
 case bar: TestStruct
 if ['defined(TEST_IF_ALT) && defined(TEST_IF_STRUCT)']
+object q_obj_TestIfAlternateCmd-arg
+member alt_cmd_arg: TestIfAlternate optional=False
+if ['defined(TEST_IF_ALT)']
+command TestIfAlternateCmd q_obj_TestIfAlternateCmd-arg -> None
+   gen=True success_response=True boxed=False oob=False preconfig=False
+if ['defined(TEST_IF_ALT)']
 object q_obj_TestIfCmd-arg
 member foo: TestIfStruct optional=False
 if ['defined(TEST_IF_CMD)', 'defined(TEST_IF_STRUCT)']
-- 
2.17.2




[Qemu-devel] [PULL 14/32] qapi: break long lines at 'data' member

2018-12-13 Thread Markus Armbruster
From: Marc-André Lureau 

Let's break the line before 'data'. While at it, improve a bit
indentation/spacing. (I removed some alignment which are not helping
much readability and become quickly inconsistent)

Suggested-by: Markus Armbruster 
Signed-off-by: Marc-André Lureau 
Message-Id: <20181208111606.8505-26-marcandre.lur...@redhat.com>
Reviewed-by: Markus Armbruster 
Signed-off-by: Markus Armbruster 
---
 qapi/block-core.json |  13 ++--
 qapi/char.json   | 138 +--
 qapi/migration.json  |   3 +-
 qapi/misc.json   |   7 ++-
 qapi/net.json|   3 +-
 qapi/tpm.json|   5 +-
 qapi/ui.json |   3 +-
 7 files changed, 101 insertions(+), 71 deletions(-)

diff --git a/qapi/block-core.json b/qapi/block-core.json
index d4fe710836..92e0205d91 100644
--- a/qapi/block-core.json
+++ b/qapi/block-core.json
@@ -1143,8 +1143,10 @@
 # This command is now obsolete and will always return an error since 2.10
 #
 ##
-{ 'command': 'block_passwd', 'data': {'*device': 'str',
-  '*node-name': 'str', 'password': 'str'} }
+{ 'command': 'block_passwd',
+  'data': { '*device': 'str',
+'*node-name': 'str',
+'password': 'str' } }
 
 ##
 # @block_resize:
@@ -1171,9 +1173,10 @@
 # <- { "return": {} }
 #
 ##
-{ 'command': 'block_resize', 'data': { '*device': 'str',
-   '*node-name': 'str',
-   'size': 'int' }}
+{ 'command': 'block_resize',
+  'data': { '*device': 'str',
+'*node-name': 'str',
+'size': 'int' } }
 
 ##
 # @NewImageMode:
diff --git a/qapi/char.json b/qapi/char.json
index 79bac598a0..24628331ec 100644
--- a/qapi/char.json
+++ b/qapi/char.json
@@ -25,9 +25,10 @@
 #
 # Since: 0.14.0
 ##
-{ 'struct': 'ChardevInfo', 'data': {'label': 'str',
-  'filename': 'str',
-  'frontend-open': 'bool'} }
+{ 'struct': 'ChardevInfo',
+  'data': { 'label': 'str',
+'filename': 'str',
+'frontend-open': 'bool' } }
 
 ##
 # @query-chardev:
@@ -152,7 +153,8 @@
 #
 ##
 { 'command': 'ringbuf-write',
-  'data': {'device': 'str', 'data': 'str',
+  'data': { 'device': 'str',
+'data': 'str',
'*format': 'DataFormat'} }
 
 ##
@@ -202,8 +204,9 @@
 #
 # Since: 2.6
 ##
-{ 'struct': 'ChardevCommon', 'data': { '*logfile': 'str',
-   '*logappend': 'bool' } }
+{ 'struct': 'ChardevCommon',
+  'data': { '*logfile': 'str',
+'*logappend': 'bool' } }
 
 ##
 # @ChardevFile:
@@ -217,9 +220,10 @@
 #
 # Since: 1.4
 ##
-{ 'struct': 'ChardevFile', 'data': { '*in' : 'str',
-   'out' : 'str',
-   '*append': 'bool' },
+{ 'struct': 'ChardevFile',
+  'data': { '*in': 'str',
+'out': 'str',
+'*append': 'bool' },
   'base': 'ChardevCommon' }
 
 ##
@@ -232,7 +236,8 @@
 #
 # Since: 1.4
 ##
-{ 'struct': 'ChardevHostdev', 'data': { 'device' : 'str' },
+{ 'struct': 'ChardevHostdev',
+  'data': { 'device': 'str' },
   'base': 'ChardevCommon' }
 
 ##
@@ -260,15 +265,16 @@
 #
 # Since: 1.4
 ##
-{ 'struct': 'ChardevSocket', 'data': { 'addr'   : 'SocketAddressLegacy',
- '*tls-creds'  : 'str',
- '*server': 'bool',
- '*wait'  : 'bool',
- '*nodelay'   : 'bool',
- '*telnet': 'bool',
- '*tn3270': 'bool',
- '*websocket' : 'bool',
- '*reconnect' : 'int' },
+{ 'struct': 'ChardevSocket',
+  'data': { 'addr': 'SocketAddressLegacy',
+'*tls-creds': 'str',
+'*server': 'bool',
+'*wait': 'bool',
+'*nodelay': 'bool',
+'*telnet': 'bool',
+'*tn3270': 'bool',
+'*websocket': 'bool',
+'*reconnect': 'int' },
   'base': 'ChardevCommon' }
 
 ##
@@ -281,8 +287,9 @@
 #
 # Since: 1.5
 ##
-{ 'struct': 'ChardevUdp', 'data': { 'remote' : 'SocketAddressLegacy',
-  '*local' : 'SocketAddressLegacy' },
+{ 'struct': 'ChardevUdp',
+  'data': { 'remote': 'SocketAddressLegacy',
+'*local': 'SocketAddressLegacy' },
   'base': 'ChardevCommon' }
 
 ##
@@ -294,7 +301,8 @@
 #
 # Since: 1.5
 ##
-{ 'struct': 'ChardevMux', 'data': { 'chardev' : 'str' },
+{ 'struct': 'ChardevMux',
+  'data': { 'chardev': 'str' },
   'base': 'ChardevCommon' }
 
 ##
@@ -308,7 +316,8 @@
 #
 # Since: 1.5
 ##
-{ 'struct': 'ChardevStdio', 'data': { '*signal' : 'bool' },
+{ 'struct': 'ChardevStdio',
+  'data': { '*signal': 'bool' },
   'base': 'ChardevCommon' }
 
 
@@ -321,7 +330,8 @@
 #
 # Since: 1.5
 ##
-{ 'struct': 'ChardevSpiceChannel', 'data': { 'type'  : 

[Qemu-devel] [PULL 04/32] qapi: Use qemu_strtod_finite() in qobject-input-visitor

2018-12-13 Thread Markus Armbruster
From: David Hildenbrand 

Let's use the new function. Just as current behavior, we have to
consume the whole string (now it's just way clearer what's going on).

Reviewed-by: Eric Blake 
Reviewed-by: Markus Armbruster 
Signed-off-by: David Hildenbrand 
Message-Id: <20181121164421.20780-5-da...@redhat.com>
Signed-off-by: Markus Armbruster 
---
 qapi/qobject-input-visitor.c | 9 +
 1 file changed, 5 insertions(+), 4 deletions(-)

diff --git a/qapi/qobject-input-visitor.c b/qapi/qobject-input-visitor.c
index 3e88b27f9e..07465f9947 100644
--- a/qapi/qobject-input-visitor.c
+++ b/qapi/qobject-input-visitor.c
@@ -562,19 +562,20 @@ static void qobject_input_type_number_keyval(Visitor *v, 
const char *name,
 {
 QObjectInputVisitor *qiv = to_qiv(v);
 const char *str = qobject_input_get_keyval(qiv, name, errp);
-char *endp;
+double val;
 
 if (!str) {
 return;
 }
 
-errno = 0;
-*obj = strtod(str, );
-if (errno || endp == str || *endp || !isfinite(*obj)) {
+if (qemu_strtod_finite(str, NULL, )) {
 /* TODO report -ERANGE more nicely */
 error_setg(errp, QERR_INVALID_PARAMETER_TYPE,
full_name(qiv, name), "number");
+return;
 }
+
+*obj = val;
 }
 
 static void qobject_input_type_any(Visitor *v, const char *name, QObject **obj,
-- 
2.17.2




[Qemu-devel] [PULL 10/32] docs: Update references to JSON RFC

2018-12-13 Thread Markus Armbruster
From: Eric Blake 

RFC8259 obsoletes RFC7159. Fix a couple of URLs to point to the
newer version.

Signed-off-by: Eric Blake 
Message-Id: <20181203175702.128701-1-ebl...@redhat.com>
Reviewed-by: Markus Armbruster 
Signed-off-by: Markus Armbruster 
---
 docs/devel/qapi-code-gen.txt | 2 +-
 docs/interop/qmp-spec.txt| 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/docs/devel/qapi-code-gen.txt b/docs/devel/qapi-code-gen.txt
index 53eaf01f34..2c8b392b20 100644
--- a/docs/devel/qapi-code-gen.txt
+++ b/docs/devel/qapi-code-gen.txt
@@ -26,7 +26,7 @@ how the schemas, scripts, and resulting code are used.
 == QMP/Guest agent schema ==
 
 A QAPI schema file is designed to be loosely based on JSON
-(http://www.ietf.org/rfc/rfc7159.txt) with changes for quoting style
+(http://www.ietf.org/rfc/rfc8259.txt) with changes for quoting style
 and the use of comments; a QAPI schema file is then parsed by a python
 code generation program.  A valid QAPI schema consists of a series of
 top-level expressions, with no commas between them.  Where
diff --git a/docs/interop/qmp-spec.txt b/docs/interop/qmp-spec.txt
index 67e44a8120..adcf86754d 100644
--- a/docs/interop/qmp-spec.txt
+++ b/docs/interop/qmp-spec.txt
@@ -32,7 +32,7 @@ following format:
 Where DATA-STRUCTURE-NAME is any valid JSON data structure, as defined
 by the JSON standard:
 
-http://www.ietf.org/rfc/rfc7159.txt
+http://www.ietf.org/rfc/rfc8259.txt
 
 The server expects its input to be encoded in UTF-8, and sends its
 output encoded in ASCII.
-- 
2.17.2




[Qemu-devel] [PULL 15/32] qapi: Do not define enumeration value explicitly

2018-12-13 Thread Markus Armbruster
From: Marc-André Lureau 

The generated C enumeration types explicitly set the enumeration
constants to 0, 1, 2, ...  That's exactly what you get when you don't
supply values.

Drop the explicit values.  No change now, but it will avoid gaps in
the values when we later add support for 'if' conditions.  Avoiding
such gaps will save us the trouble of changing the ENUM_lookup[]
tables to work without a sentinel.

We'll have to take care to ensure the headers required by the 'if'
conditions get always included before the generated QAPI code.
Fortunately, our convention to include "qemu/osdep.h" first in any .c
ensures that's the case for our CONFIG_FOO macros.

Signed-off-by: Marc-André Lureau 
Reviewed-by: Markus Armbruster 
Message-Id: <20181213123724.4866-2-marcandre.lur...@redhat.com>
Signed-off-by: Markus Armbruster 
---
 scripts/qapi/common.py | 7 ++-
 1 file changed, 2 insertions(+), 5 deletions(-)

diff --git a/scripts/qapi/common.py b/scripts/qapi/common.py
index 046b7e5681..55c914ec44 100644
--- a/scripts/qapi/common.py
+++ b/scripts/qapi/common.py
@@ -2045,14 +2045,11 @@ typedef enum %(c_name)s {
 ''',
 c_name=c_name(name))
 
-i = 0
 for value in enum_values:
 ret += mcgen('''
-%(c_enum)s = %(i)d,
+%(c_enum)s,
 ''',
- c_enum=c_enum_const(name, value, prefix),
- i=i)
-i += 1
+ c_enum=c_enum_const(name, value, prefix))
 
 ret += mcgen('''
 } %(c_name)s;
-- 
2.17.2




[Qemu-devel] [PULL 08/32] test-string-input-visitor: Split off uint64 list tests

2018-12-13 Thread Markus Armbruster
From: David Hildenbrand 

Basically copy all int64 list tests but adapt them to work on uint64
instead. The values for very big/very small values have to be adapted.

Reviewed-by: Markus Armbruster 
Signed-off-by: David Hildenbrand 
Message-Id: <20181121164421.20780-9-da...@redhat.com>
Signed-off-by: Markus Armbruster 
---
 tests/test-string-input-visitor.c | 113 --
 1 file changed, 109 insertions(+), 4 deletions(-)

diff --git a/tests/test-string-input-visitor.c 
b/tests/test-string-input-visitor.c
index 718d9a03c3..9b1dd44b2d 100644
--- a/tests/test-string-input-visitor.c
+++ b/tests/test-string-input-visitor.c
@@ -112,7 +112,6 @@ static void test_visitor_in_intList(TestInputVisitorData 
*data,
 int64_t expect2[] = { 32767, -32768, -32767 };
 int64_t expect3[] = { INT64_MIN, INT64_MAX };
 int64_t expect4[] = { 1 };
-uint64_t expect5[] = { UINT64_MAX };
 Error *err = NULL;
 int64List *res = NULL;
 Visitor *v;
@@ -133,9 +132,6 @@ static void test_visitor_in_intList(TestInputVisitorData 
*data,
 v = visitor_input_test_init(data, "1-1");
 check_ilist(v, expect4, ARRAY_SIZE(expect4));
 
-v = visitor_input_test_init(data, "18446744073709551615");
-check_ulist(v, expect5, ARRAY_SIZE(expect5));
-
 /* Value too large */
 
 v = visitor_input_test_init(data, "9223372036854775808");
@@ -211,6 +207,113 @@ static void test_visitor_in_intList(TestInputVisitorData 
*data,
 visit_end_list(v, NULL);
 }
 
+static void test_visitor_in_uintList(TestInputVisitorData *data,
+ const void *unused)
+{
+uint64_t expect1[] = { 1, 2, 0, 2, 3, 4, 20, 5, 6, 7,
+   8, 9, 1, 2, 3, 4, 5, 6, 7, 8 };
+uint64_t expect2[] = { 32767, -32768, -32767 };
+uint64_t expect3[] = { INT64_MIN, INT64_MAX };
+uint64_t expect4[] = { 1 };
+uint64_t expect5[] = { UINT64_MAX };
+Error *err = NULL;
+uint64List *res = NULL;
+Visitor *v;
+uint64_t val;
+
+/* Valid lists */
+
+v = visitor_input_test_init(data, "1,2,0,2-4,20,5-9,1-8");
+check_ulist(v, expect1, ARRAY_SIZE(expect1));
+
+v = visitor_input_test_init(data, "32767,-32768--32767");
+check_ulist(v, expect2, ARRAY_SIZE(expect2));
+
+v = visitor_input_test_init(data,
+"-9223372036854775808,9223372036854775807");
+check_ulist(v, expect3, ARRAY_SIZE(expect3));
+
+v = visitor_input_test_init(data, "1-1");
+check_ulist(v, expect4, ARRAY_SIZE(expect4));
+
+v = visitor_input_test_init(data, "18446744073709551615");
+check_ulist(v, expect5, ARRAY_SIZE(expect5));
+
+/* Value too large */
+
+v = visitor_input_test_init(data, "18446744073709551616");
+visit_type_uint64List(v, NULL, , );
+error_free_or_abort();
+g_assert(!res);
+
+/* Value too small */
+
+v = visitor_input_test_init(data, "-18446744073709551616");
+visit_type_uint64List(v, NULL, , );
+error_free_or_abort();
+g_assert(!res);
+
+/* Range not ascending */
+
+v = visitor_input_test_init(data, "3-1");
+visit_type_uint64List(v, NULL, , );
+error_free_or_abort();
+g_assert(!res);
+
+v = visitor_input_test_init(data, "18446744073709551615-0");
+visit_type_uint64List(v, NULL, , );
+error_free_or_abort();
+g_assert(!res);
+
+/* Range too big (65536 is the limit against DOS attacks) */
+
+v = visitor_input_test_init(data, "0-65536");
+visit_type_uint64List(v, NULL, , );
+error_free_or_abort();
+g_assert(!res);
+
+/* Empty list */
+
+v = visitor_input_test_init(data, "");
+visit_type_uint64List(v, NULL, , _abort);
+g_assert(!res);
+
+/* Not a list */
+
+v = visitor_input_test_init(data, "not an uint list");
+
+visit_type_uint64List(v, NULL, , );
+error_free_or_abort();
+g_assert(!res);
+
+/* Unvisited list tail */
+
+v = visitor_input_test_init(data, "0,2-3");
+
+visit_start_list(v, NULL, NULL, 0, _abort);
+visit_type_uint64(v, NULL, , _abort);
+g_assert_cmpuint(val, ==, 0);
+visit_type_uint64(v, NULL, , _abort);
+g_assert_cmpuint(val, ==, 2);
+
+visit_check_list(v, );
+error_free_or_abort();
+visit_end_list(v, NULL);
+
+/* Visit beyond end of list */
+
+v = visitor_input_test_init(data, "0");
+
+visit_start_list(v, NULL, NULL, 0, _abort);
+visit_type_uint64(v, NULL, , );
+g_assert_cmpuint(val, ==, 0);
+visit_type_uint64(v, NULL, , );
+error_free_or_abort();
+
+visit_check_list(v, _abort);
+visit_end_list(v, NULL);
+}
+
 static void test_visitor_in_bool(TestInputVisitorData *data,
  const void *unused)
 {
@@ -384,6 +487,8 @@ int main(int argc, char **argv)
_visitor_data, test_visitor_in_int);
 input_visitor_test_add("/string-visitor/input/intList",
_visitor_data, test_visitor_in_intList);
+

[Qemu-devel] [PULL 32/32] qapi: add conditions to REPLICATION type/commands on the schema

2018-12-13 Thread Markus Armbruster
From: Marc-André Lureau 

Add #if defined(CONFIG_REPLICATION) in generated code, and adjust the
code accordingly.

Made conditional:

* xen-set-replication, query-xen-replication-status,
  xen-colo-do-checkpoint

  Before the patch, we first register the commands unconditionally in
  generated code (requires a stub), then conditionally unregister in
  qmp_unregister_commands_hack().

  Afterwards, we register only when CONFIG_REPLICATION.  The command
  fails exactly the same, with CommandNotFound.

  Improvement, because now query-qmp-schema is accurate, and we're one
  step closer to killing qmp_unregister_commands_hack().

* enum BlockdevDriver value "replication" in command blockdev-add

* BlockdevOptions variant @replication

and related structures.

Signed-off-by: Marc-André Lureau 
Reviewed-by: Markus Armbruster 
Message-Id: <20181213123724.4866-23-marcandre.lur...@redhat.com>
Signed-off-by: Markus Armbruster 
---
 migration/colo.c | 16 
 monitor.c|  5 -
 qapi/block-core.json | 13 +
 qapi/migration.json  | 12 
 4 files changed, 21 insertions(+), 25 deletions(-)

diff --git a/migration/colo.c b/migration/colo.c
index fcff04c78c..398b239d1c 100644
--- a/migration/colo.c
+++ b/migration/colo.c
@@ -24,7 +24,9 @@
 #include "trace.h"
 #include "qemu/error-report.h"
 #include "migration/failover.h"
+#ifdef CONFIG_REPLICATION
 #include "replication.h"
+#endif
 #include "net/colo-compare.h"
 #include "net/colo.h"
 #include "block/block.h"
@@ -201,11 +203,11 @@ void colo_do_failover(MigrationState *s)
 }
 }
 
+#ifdef CONFIG_REPLICATION
 void qmp_xen_set_replication(bool enable, bool primary,
  bool has_failover, bool failover,
  Error **errp)
 {
-#ifdef CONFIG_REPLICATION
 ReplicationMode mode = primary ?
REPLICATION_MODE_PRIMARY :
REPLICATION_MODE_SECONDARY;
@@ -224,14 +226,10 @@ void qmp_xen_set_replication(bool enable, bool primary,
 }
 replication_stop_all(failover, failover ? NULL : errp);
 }
-#else
-abort();
-#endif
 }
 
 ReplicationStatus *qmp_query_xen_replication_status(Error **errp)
 {
-#ifdef CONFIG_REPLICATION
 Error *err = NULL;
 ReplicationStatus *s = g_new0(ReplicationStatus, 1);
 
@@ -246,19 +244,13 @@ ReplicationStatus *qmp_query_xen_replication_status(Error 
**errp)
 
 error_free(err);
 return s;
-#else
-abort();
-#endif
 }
 
 void qmp_xen_colo_do_checkpoint(Error **errp)
 {
-#ifdef CONFIG_REPLICATION
 replication_do_checkpoint_all(errp);
-#else
-abort();
-#endif
 }
+#endif
 
 COLOStatus *qmp_query_colo_status(Error **errp)
 {
diff --git a/monitor.c b/monitor.c
index cf9cece965..7848a3cb0d 100644
--- a/monitor.c
+++ b/monitor.c
@@ -1147,11 +1147,6 @@ static void qmp_query_qmp_schema(QDict *qdict, QObject 
**ret_data,
  */
 static void qmp_unregister_commands_hack(void)
 {
-#ifndef CONFIG_REPLICATION
-qmp_unregister_command(_commands, "xen-set-replication");
-qmp_unregister_command(_commands, "query-xen-replication-status");
-qmp_unregister_command(_commands, "xen-colo-do-checkpoint");
-#endif
 #ifndef TARGET_I386
 qmp_unregister_command(_commands, "rtc-reset-reinjection");
 qmp_unregister_command(_commands, "query-sev");
diff --git a/qapi/block-core.json b/qapi/block-core.json
index 92e0205d91..762000f31f 100644
--- a/qapi/block-core.json
+++ b/qapi/block-core.json
@@ -2623,7 +2623,9 @@
 'copy-on-read', 'dmg', 'file', 'ftp', 'ftps', 'gluster',
 'host_cdrom', 'host_device', 'http', 'https', 'iscsi', 'luks',
 'nbd', 'nfs', 'null-aio', 'null-co', 'nvme', 'parallels', 'qcow',
-'qcow2', 'qed', 'quorum', 'raw', 'rbd', 'replication', 'sheepdog',
+'qcow2', 'qed', 'quorum', 'raw', 'rbd',
+{ 'name': 'replication', 'if': 'defined(CONFIG_REPLICATION)' },
+'sheepdog',
 'ssh', 'throttle', 'vdi', 'vhdx', 'vmdk', 'vpc', 'vvfat', 'vxhs' ] 
}
 
 ##
@@ -3380,7 +3382,8 @@
 #
 # Since: 2.9
 ##
-{ 'enum' : 'ReplicationMode', 'data' : [ 'primary', 'secondary' ] }
+{ 'enum' : 'ReplicationMode', 'data' : [ 'primary', 'secondary' ],
+  'if': 'defined(CONFIG_REPLICATION)' }
 
 ##
 # @BlockdevOptionsReplication:
@@ -3398,7 +3401,8 @@
 { 'struct': 'BlockdevOptionsReplication',
   'base': 'BlockdevOptionsGenericFormat',
   'data': { 'mode': 'ReplicationMode',
-'*top-id': 'str' } }
+'*top-id': 'str' },
+  'if': 'defined(CONFIG_REPLICATION)' }
 
 ##
 # @NFSTransport:
@@ -3714,7 +3718,8 @@
   'quorum': 'BlockdevOptionsQuorum',
   'raw':'BlockdevOptionsRaw',
   'rbd':'BlockdevOptionsRbd',
-  'replication':'BlockdevOptionsReplication',
+  'replication': { 'type': 'BlockdevOptionsReplication',
+   'if': 'defined(CONFIG_REPLICATION)' },
   'sheepdog':   'BlockdevOptionsSheepdog',
   'ssh':   

[Qemu-devel] [PULL 13/32] qapi: rename QAPISchemaEnumType.values to .members

2018-12-13 Thread Markus Armbruster
From: Marc-André Lureau 

Rename QAPISchemaEnumType.values and related variables to members.
Makes sense ever since commit 93bda4dd4 changed .values from list of
string to list of QAPISchemaMember. Obvious no-op.

Signed-off-by: Marc-André Lureau 
Reviewed-by: Markus Armbruster 
Message-Id: <20181208111606.8505-4-marcandre.lur...@redhat.com>
Signed-off-by: Markus Armbruster 
---
 scripts/qapi/common.py | 24 
 1 file changed, 12 insertions(+), 12 deletions(-)

diff --git a/scripts/qapi/common.py b/scripts/qapi/common.py
index 7b62a4c7b0..046b7e5681 100644
--- a/scripts/qapi/common.py
+++ b/scripts/qapi/common.py
@@ -1161,22 +1161,22 @@ class QAPISchemaBuiltinType(QAPISchemaType):
 
 
 class QAPISchemaEnumType(QAPISchemaType):
-def __init__(self, name, info, doc, ifcond, values, prefix):
+def __init__(self, name, info, doc, ifcond, members, prefix):
 QAPISchemaType.__init__(self, name, info, doc, ifcond)
-for v in values:
-assert isinstance(v, QAPISchemaMember)
-v.set_owner(name)
+for m in members:
+assert isinstance(m, QAPISchemaMember)
+m.set_owner(name)
 assert prefix is None or isinstance(prefix, str)
-self.values = values
+self.members = members
 self.prefix = prefix
 
 def check(self, schema):
 QAPISchemaType.check(self, schema)
 seen = {}
-for v in self.values:
-v.check_clash(self.info, seen)
+for m in self.members:
+m.check_clash(self.info, seen)
 if self.doc:
-self.doc.connect_member(v)
+self.doc.connect_member(m)
 
 def is_implicit(self):
 # See QAPISchema._make_implicit_enum_type() and ._def_predefineds()
@@ -1186,7 +1186,7 @@ class QAPISchemaEnumType(QAPISchemaType):
 return c_name(self.name)
 
 def member_names(self):
-return [v.name for v in self.values]
+return [m.name for m in self.members]
 
 def json_type(self):
 return 'string'
@@ -1403,9 +1403,9 @@ class QAPISchemaObjectTypeVariants(object):
 if self._tag_name:# flat union
 # branches that are not explicitly covered get an empty type
 cases = set([v.name for v in self.variants])
-for val in self.tag_member.type.values:
-if val.name not in cases:
-v = QAPISchemaObjectTypeVariant(val.name, 'q_empty')
+for m in self.tag_member.type.members:
+if m.name not in cases:
+v = QAPISchemaObjectTypeVariant(m.name, 'q_empty')
 v.set_owner(self.tag_member.owner)
 self.variants.append(v)
 for v in self.variants:
-- 
2.17.2




[Qemu-devel] [PULL 05/32] test-string-input-visitor: Add more tests

2018-12-13 Thread Markus Armbruster
From: David Hildenbrand 

Test that very big/small values are not accepted and that ranges with
only one element work. Also test that ranges are ascending and cannot
have more than 65536 elements.

Rename expect4 to expect5, as we will be moving that to a separate ulist
test after the rework.

Reviewed-by: Eric Blake 
Reviewed-by: Markus Armbruster 
Signed-off-by: David Hildenbrand 
Message-Id: <20181121164421.20780-6-da...@redhat.com>
Signed-off-by: Markus Armbruster 
---
 tests/test-string-input-visitor.c | 41 +--
 1 file changed, 39 insertions(+), 2 deletions(-)

diff --git a/tests/test-string-input-visitor.c 
b/tests/test-string-input-visitor.c
index 1efba06948..8ee0d1b284 100644
--- a/tests/test-string-input-visitor.c
+++ b/tests/test-string-input-visitor.c
@@ -121,7 +121,8 @@ static void test_visitor_in_intList(TestInputVisitorData 
*data,
 int64_t expect1[] = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 20 };
 int64_t expect2[] = { 32767, -32768, -32767 };
 int64_t expect3[] = { INT64_MAX, INT64_MIN };
-uint64_t expect4[] = { UINT64_MAX };
+int64_t expect4[] = { 1 };
+uint64_t expect5[] = { UINT64_MAX };
 Error *err = NULL;
 int64List *res = NULL;
 int64List *tail;
@@ -140,8 +141,44 @@ static void test_visitor_in_intList(TestInputVisitorData 
*data,
 "-9223372036854775808,9223372036854775807");
 check_ilist(v, expect3, ARRAY_SIZE(expect3));
 
+v = visitor_input_test_init(data, "1-1");
+check_ilist(v, expect4, ARRAY_SIZE(expect4));
+
 v = visitor_input_test_init(data, "18446744073709551615");
-check_ulist(v, expect4, ARRAY_SIZE(expect4));
+check_ulist(v, expect5, ARRAY_SIZE(expect5));
+
+/* Value too large */
+
+v = visitor_input_test_init(data, "9223372036854775808");
+visit_type_int64List(v, NULL, , );
+error_free_or_abort();
+g_assert(!res);
+
+/* Value too small */
+
+v = visitor_input_test_init(data, "-9223372036854775809");
+visit_type_int64List(v, NULL, , );
+error_free_or_abort();
+g_assert(!res);
+
+/* Range not ascending */
+
+v = visitor_input_test_init(data, "3-1");
+visit_type_int64List(v, NULL, , );
+error_free_or_abort();
+g_assert(!res);
+
+v = visitor_input_test_init(data, "9223372036854775807-0");
+visit_type_int64List(v, NULL, , );
+error_free_or_abort();
+g_assert(!res);
+
+/* Range too big (65536 is the limit against DOS attacks) */
+
+v = visitor_input_test_init(data, "0-65536");
+visit_type_int64List(v, NULL, , );
+error_free_or_abort();
+g_assert(!res);
 
 /* Empty list */
 
-- 
2.17.2




[Qemu-devel] [PULL 02/32] cutils: Fix qemu_strtosz() & friends to reject non-finite sizes

2018-12-13 Thread Markus Armbruster
From: David Hildenbrand 

qemu_strtosz() & friends reject NaNs, but happily accept infinities.
They shouldn't. Fix that.

The fix makes use of qemu_strtod_finite(). To avoid ugly casts,
change the @end parameter of qemu_strtosz() & friends from char **
to const char **.

Also, add two test cases, testing that "inf" and "NaN" are properly
rejected. While at it, also fixup the function documentation.

Reviewed-by: Eric Blake 
Reviewed-by: Markus Armbruster 
Signed-off-by: David Hildenbrand 
Message-Id: <20181121164421.20780-3-da...@redhat.com>
Signed-off-by: Markus Armbruster 
---
 include/qemu/cutils.h |  6 +++---
 monitor.c |  2 +-
 tests/test-cutils.c   | 24 +---
 util/cutils.c | 18 --
 4 files changed, 29 insertions(+), 21 deletions(-)

diff --git a/include/qemu/cutils.h b/include/qemu/cutils.h
index 756b41c193..d2dad3057c 100644
--- a/include/qemu/cutils.h
+++ b/include/qemu/cutils.h
@@ -153,9 +153,9 @@ int parse_uint(const char *s, unsigned long long *value, 
char **endptr,
int base);
 int parse_uint_full(const char *s, unsigned long long *value, int base);
 
-int qemu_strtosz(const char *nptr, char **end, uint64_t *result);
-int qemu_strtosz_MiB(const char *nptr, char **end, uint64_t *result);
-int qemu_strtosz_metric(const char *nptr, char **end, uint64_t *result);
+int qemu_strtosz(const char *nptr, const char **end, uint64_t *result);
+int qemu_strtosz_MiB(const char *nptr, const char **end, uint64_t *result);
+int qemu_strtosz_metric(const char *nptr, const char **end, uint64_t *result);
 
 /* used to print char* safely */
 #define STR_OR_NULL(str) ((str) ? (str) : "null")
diff --git a/monitor.c b/monitor.c
index 6e81b09294..cf9cece965 100644
--- a/monitor.c
+++ b/monitor.c
@@ -3232,7 +3232,7 @@ static QDict *monitor_parse_arguments(Monitor *mon,
 {
 int ret;
 uint64_t val;
-char *end;
+const char *end;
 
 while (qemu_isspace(*p)) {
 p++;
diff --git a/tests/test-cutils.c b/tests/test-cutils.c
index d85c3e0f6d..1aa8351520 100644
--- a/tests/test-cutils.c
+++ b/tests/test-cutils.c
@@ -1950,7 +1950,7 @@ static void test_qemu_strtou64_full_max(void)
 static void test_qemu_strtosz_simple(void)
 {
 const char *str;
-char *endptr = NULL;
+const char *endptr;
 int err;
 uint64_t res = 0xbaadf00d;
 
@@ -2017,7 +2017,7 @@ static void test_qemu_strtosz_units(void)
 const char *p = "1P";
 const char *e = "1E";
 int err;
-char *endptr = NULL;
+const char *endptr;
 uint64_t res = 0xbaadf00d;
 
 /* default is M */
@@ -2066,7 +2066,7 @@ static void test_qemu_strtosz_float(void)
 {
 const char *str = "12.345M";
 int err;
-char *endptr = NULL;
+const char *endptr;
 uint64_t res = 0xbaadf00d;
 
 err = qemu_strtosz(str, , );
@@ -2078,7 +2078,7 @@ static void test_qemu_strtosz_float(void)
 static void test_qemu_strtosz_invalid(void)
 {
 const char *str;
-char *endptr = NULL;
+const char *endptr;
 int err;
 uint64_t res = 0xbaadf00d;
 
@@ -2096,12 +2096,22 @@ static void test_qemu_strtosz_invalid(void)
 err = qemu_strtosz(str, , );
 g_assert_cmpint(err, ==, -EINVAL);
 g_assert(endptr == str);
+
+str = "inf";
+err = qemu_strtosz(str, , );
+g_assert_cmpint(err, ==, -EINVAL);
+g_assert(endptr == str);
+
+str = "NaN";
+err = qemu_strtosz(str, , );
+g_assert_cmpint(err, ==, -EINVAL);
+g_assert(endptr == str);
 }
 
 static void test_qemu_strtosz_trailing(void)
 {
 const char *str;
-char *endptr = NULL;
+const char *endptr;
 int err;
 uint64_t res = 0xbaadf00d;
 
@@ -2126,7 +2136,7 @@ static void test_qemu_strtosz_trailing(void)
 static void test_qemu_strtosz_erange(void)
 {
 const char *str;
-char *endptr = NULL;
+const char *endptr;
 int err;
 uint64_t res = 0xbaadf00d;
 
@@ -2160,7 +2170,7 @@ static void test_qemu_strtosz_metric(void)
 {
 const char *str = "12345k";
 int err;
-char *endptr = NULL;
+const char *endptr;
 uint64_t res = 0xbaadf00d;
 
 err = qemu_strtosz_metric(str, , );
diff --git a/util/cutils.c b/util/cutils.c
index ec0a401d9a..e098debdc0 100644
--- a/util/cutils.c
+++ b/util/cutils.c
@@ -203,23 +203,21 @@ static int64_t suffix_mul(char suffix, int64_t unit)
 /*
  * Convert string to bytes, allowing either B/b for bytes, K/k for KB,
  * M/m for MB, G/g for GB or T/t for TB. End pointer will be returned
- * in *end, if not NULL. Return -ERANGE on overflow, Return -EINVAL on
+ * in *end, if not NULL. Return -ERANGE on overflow, and -EINVAL on
  * other error.
  */
-static int do_strtosz(const char *nptr, char **end,
+static int do_strtosz(const char *nptr, const char **end,
   const char default_suffix, int64_t unit,
   uint64_t *result)
 {
 int retval;
-char *endptr;
+const char 

[Qemu-devel] [PULL 06/32] qapi: Rewrite string-input-visitor's integer and list parsing

2018-12-13 Thread Markus Armbruster
From: David Hildenbrand 

The input visitor has some problems right now, especially
- unsigned type "Range" is used to process signed ranges, resulting in
  inconsistent behavior and ugly/magical code
- uint64_t are parsed like int64_t, so big uint64_t values are not
  supported and error messages are misleading
- lists/ranges of int64_t are accepted although no list is parsed and
  we should rather report an error
- lists/ranges are preparsed using int64_t, making it hard to
  implement uint64_t values or uint64_t lists
- types that don't support lists don't bail out
- visiting beyond the end of a list is not handled properly
- we don't actually parse lists, we parse *sets*: members are sorted,
  and duplicates eliminated

So let's rewrite it by getting rid of usage of the type "Range" and
properly supporting lists of int64_t and uint64_t (including ranges of
both types), fixing the above mentioned issues.

Lists of other types are not supported and will properly report an
error. Virtual walks are now supported.

Tests have to be fixed up:
- Two BUGs were hardcoded that are fixed now
- The string-input-visitor now actually returns a parsed list and not
  an ordered set.

Please note that no users/callers have to be fixed up. Candidates using
visit_type_uint16List() and friends are:
- backends/hostmem.c:host_memory_backend_set_host_nodes()
-- Code can deal with duplicates/unsorted lists
- numa.c::query_memdev()
-- via object_property_get_uint16List(), the list will still be sorted
   and without duplicates (via host_memory_backend_get_host_nodes())
- qapi-visit.c::visit_type_Memdev_members()
- qapi-visit.c::visit_type_NumaNodeOptions_members()
- qapi-visit.c::visit_type_RockerOfDpaGroup_members
- qapi-visit.c::visit_type_RxFilterInfo_members()
-- Not used with string-input-visitor.

Reviewed-by: Eric Blake 
Reviewed-by: Markus Armbruster 
Signed-off-by: David Hildenbrand 
Message-Id: <20181121164421.20780-7-da...@redhat.com>
Signed-off-by: Markus Armbruster 
---
 include/qapi/string-input-visitor.h |   4 +-
 qapi/string-input-visitor.c | 401 
 tests/test-string-input-visitor.c   |  18 +-
 3 files changed, 232 insertions(+), 191 deletions(-)

diff --git a/include/qapi/string-input-visitor.h 
b/include/qapi/string-input-visitor.h
index 33551340e3..921f3875b9 100644
--- a/include/qapi/string-input-visitor.h
+++ b/include/qapi/string-input-visitor.h
@@ -19,8 +19,8 @@ typedef struct StringInputVisitor StringInputVisitor;
 
 /*
  * The string input visitor does not implement support for visiting
- * QAPI structs, alternates, null, or arbitrary QTypes.  It also
- * requires a non-null list argument to visit_start_list().
+ * QAPI structs, alternates, null, or arbitrary QTypes. Only flat lists
+ * of integers (except type "size") are supported.
  */
 Visitor *string_input_visitor_new(const char *str);
 
diff --git a/qapi/string-input-visitor.c b/qapi/string-input-visitor.c
index b89c6c4e06..bd92080667 100644
--- a/qapi/string-input-visitor.c
+++ b/qapi/string-input-visitor.c
@@ -4,10 +4,10 @@
  * Copyright Red Hat, Inc. 2012-2016
  *
  * Author: Paolo Bonzini 
+ * David Hildenbrand 
  *
  * This work is licensed under the terms of the GNU LGPL, version 2.1 or later.
  * See the COPYING.LIB file in the top-level directory.
- *
  */
 
 #include "qemu/osdep.h"
@@ -18,21 +18,42 @@
 #include "qapi/qmp/qerror.h"
 #include "qapi/qmp/qnull.h"
 #include "qemu/option.h"
-#include "qemu/queue.h"
-#include "qemu/range.h"
 #include "qemu/cutils.h"
 
+typedef enum ListMode {
+/* no list parsing active / no list expected */
+LM_NONE,
+/* we have an unparsed string remaining */
+LM_UNPARSED,
+/* we have an unfinished int64 range */
+LM_INT64_RANGE,
+/* we have an unfinished uint64 range */
+LM_UINT64_RANGE,
+/* we have parsed the string completely and no range is remaining */
+LM_END,
+} ListMode;
+
+/* protect against DOS attacks, limit the amount of elements per range */
+#define RANGE_MAX_ELEMENTS 65536
+
+typedef union RangeElement {
+int64_t i64;
+uint64_t u64;
+} RangeElement;
 
 struct StringInputVisitor
 {
 Visitor visitor;
 
-GList *ranges;
-GList *cur_range;
-int64_t cur;
+/* List parsing state */
+ListMode lm;
+RangeElement rangeNext;
+RangeElement rangeEnd;
+const char *unparsed_string;
+void *list;
 
+/* The original string to parse */
 const char *string;
-void *list; /* Only needed for sanity checking the caller */
 };
 
 static StringInputVisitor *to_siv(Visitor *v)
@@ -40,136 +61,42 @@ static StringInputVisitor *to_siv(Visitor *v)
 return container_of(v, StringInputVisitor, visitor);
 }
 
-static void free_range(void *range, void *dummy)
-{
-g_free(range);
-}
-
-static int parse_str(StringInputVisitor *siv, const char *name, Error **errp)
-{
-char *str = (char *) siv->string;
-long long start, end;
-Range *cur;
-char *endptr;
-
-if 

[Qemu-devel] [PULL 00/32] QAPI patches for 2018-12-13

2018-12-13 Thread Markus Armbruster
The following changes since commit c3ec0fa1a8e815ecfec9eabb9c20ee206c313e07:

  Merge remote-tracking branch 'remotes/armbru/tags/pull-monitor-2018-12-12' 
into staging (2018-12-13 13:41:44 +)

are available in the Git repository at:

  git://repo.or.cz/qemu/armbru.git tags/pull-qapi-2018-12-13

for you to fetch changes up to badfa07f5fc309936e22aabd5a51a0203de78cb4:

  qapi: add conditions to REPLICATION type/commands on the schema (2018-12-13 
19:20:11 +0100)


QAPI patches for 2018-12-13

* Rewrite the ugly parts of string-input-visitor
* Support conditional QAPI enum, struct, union and alternate members


David Hildenbrand (9):
  cutils: Add qemu_strtod() and qemu_strtod_finite()
  cutils: Fix qemu_strtosz() & friends to reject non-finite sizes
  qapi: Fix string-input-visitor to reject NaN and infinities
  qapi: Use qemu_strtod_finite() in qobject-input-visitor
  test-string-input-visitor: Add more tests
  qapi: Rewrite string-input-visitor's integer and list parsing
  test-string-input-visitor: Use virtual walk
  test-string-input-visitor: Split off uint64 list tests
  test-string-input-visitor: Add range overflow tests

Eric Blake (1):
  docs: Update references to JSON RFC

Marc-André Lureau (21):
  tests/qapi: Cover commands with 'if' and union / alternate 'data'
  qapi: rename QAPISchemaEnumType.values to .members
  qapi: break long lines at 'data' member
  qapi: Do not define enumeration value explicitly
  qapi: change enum visitor and gen_enum* to take QAPISchemaMember
  tests: print enum type members more like object type members
  qapi: factor out checking for keys
  qapi: improve reporting of unknown or missing keys
  qapi: add a dictionary form with 'name' key for enum members
  qapi: add 'if' to enum members
  qapi-events: add 'if' condition to implicit event enum
  qapi: add a dictionary form for TYPE
  qapi: Add 'if' to implicit struct members
  qapi: add 'if' to union members
  qapi: add 'if' to alternate members
  qapi: add #if conditions to generated code members
  qapi: add 'If:' condition to enum values documentation
  qapi: add 'If:' condition to struct members documentation
  qapi: add condition to variants documentation
  qapi: add more conditions to SPICE
  qapi: add conditions to REPLICATION type/commands on the schema

Markus Armbruster (1):
  json: Fix to reject duplicate object member names

 docs/devel/qapi-code-gen.txt   |  21 +-
 docs/interop/qmp-spec.txt  |   2 +-
 include/qapi/string-input-visitor.h|   4 +-
 include/qemu/cutils.h  |   8 +-
 migration/colo.c   |  16 +-
 monitor.c  |   7 +-
 qapi/block-core.json   |  26 +-
 qapi/char.json | 150 
 qapi/migration.json|  15 +-
 qapi/misc.json |   7 +-
 qapi/net.json  |   3 +-
 qapi/qobject-input-visitor.c   |   9 +-
 qapi/string-input-visitor.c| 407 -
 qapi/tpm.json  |   5 +-
 qapi/ui.json   |   3 +-
 qobject/json-parser.c  |   5 +
 scripts/qapi/common.py | 207 +++
 scripts/qapi/doc.py|  31 +-
 scripts/qapi/events.py |  13 +-
 scripts/qapi/introspect.py |  17 +-
 scripts/qapi/types.py  |  10 +-
 scripts/qapi/visit.py  |   8 +-
 tests/Makefile.include |  11 +-
 tests/qapi-schema/alternate-base.err   |   1 +
 tests/qapi-schema/alternate-invalid-dict.err   |   1 +
 ...ict-member.exit => alternate-invalid-dict.exit} |   0
 tests/qapi-schema/alternate-invalid-dict.json  |   4 +
 ...-dict-member.out => alternate-invalid-dict.out} |   0
 tests/qapi-schema/comments.out |  14 +-
 tests/qapi-schema/doc-bad-section.out  |  13 +-
 tests/qapi-schema/doc-good.json|  11 +-
 tests/qapi-schema/doc-good.out |  22 +-
 tests/qapi-schema/doc-good.texi|   7 +-
 tests/qapi-schema/double-type.err  |   1 +
 tests/qapi-schema/empty.out|   9 +-
 tests/qapi-schema/enum-bad-member.err  |   1 +
 tests/qapi-schema/enum-bad-member.exit |   1 +
 tests/qapi-schema/enum-bad-member.json |   2 +
 

[Qemu-devel] [PULL 03/32] qapi: Fix string-input-visitor to reject NaN and infinities

2018-12-13 Thread Markus Armbruster
From: David Hildenbrand 

The string-input-visitor happily accepts NaN and infinities when parsing
numbers (doubles). They shouldn't. Fix that.

Also, add two test cases, testing if "NaN" and "inf" is properly
rejected.

Reviewed-by: Eric Blake 
Reviewed-by: Markus Armbruster 
Signed-off-by: David Hildenbrand 
Message-Id: <20181121164421.20780-4-da...@redhat.com>
Signed-off-by: Markus Armbruster 
---
 qapi/string-input-visitor.c   |  6 ++
 tests/test-string-input-visitor.c | 13 +
 2 files changed, 15 insertions(+), 4 deletions(-)

diff --git a/qapi/string-input-visitor.c b/qapi/string-input-visitor.c
index b3fdd0827d..b89c6c4e06 100644
--- a/qapi/string-input-visitor.c
+++ b/qapi/string-input-visitor.c
@@ -20,6 +20,7 @@
 #include "qemu/option.h"
 #include "qemu/queue.h"
 #include "qemu/range.h"
+#include "qemu/cutils.h"
 
 
 struct StringInputVisitor
@@ -313,12 +314,9 @@ static void parse_type_number(Visitor *v, const char 
*name, double *obj,
   Error **errp)
 {
 StringInputVisitor *siv = to_siv(v);
-char *endp = (char *) siv->string;
 double val;
 
-errno = 0;
-val = strtod(siv->string, );
-if (errno || endp == siv->string || *endp) {
+if (qemu_strtod_finite(siv->string, NULL, )) {
 error_setg(errp, QERR_INVALID_PARAMETER_TYPE, name ? name : "null",
"number");
 return;
diff --git a/tests/test-string-input-visitor.c 
b/tests/test-string-input-visitor.c
index 88e0e1aa9a..1efba06948 100644
--- a/tests/test-string-input-visitor.c
+++ b/tests/test-string-input-visitor.c
@@ -252,6 +252,19 @@ static void test_visitor_in_number(TestInputVisitorData 
*data,
 visit_type_number(v, NULL, , );
 g_assert(!err);
 g_assert_cmpfloat(res, ==, value);
+
+/* NaN and infinity has to be rejected */
+
+v = visitor_input_test_init(data, "NaN");
+
+visit_type_number(v, NULL, , );
+error_free_or_abort();
+
+v = visitor_input_test_init(data, "inf");
+
+visit_type_number(v, NULL, , );
+error_free_or_abort();
+
 }
 
 static void test_visitor_in_string(TestInputVisitorData *data,
-- 
2.17.2




[Qemu-devel] [PULL 17/32] tests: print enum type members more like object type members

2018-12-13 Thread Markus Armbruster
From: Marc-André Lureau 

Commit 93bda4dd461 changed the internal representation of enum type
members from str to QAPISchemaMember, but we still print only a
string.  Has been good enough, as the name is the member's only
attribute of interest, but that's about to change.  To prepare, print
them more like object type members.

Signed-off-by: Marc-André Lureau 
Reviewed-by: Markus Armbruster 
Message-Id: <20181213123724.4866-4-marcandre.lur...@redhat.com>
Signed-off-by: Markus Armbruster 
---
 tests/qapi-schema/comments.out   | 14 ++-
 tests/qapi-schema/doc-bad-section.out| 13 +-
 tests/qapi-schema/doc-good.out   | 17 ++--
 tests/qapi-schema/empty.out  |  9 -
 tests/qapi-schema/event-case.out |  9 -
 tests/qapi-schema/ident-with-escape.out  |  9 -
 tests/qapi-schema/include-relpath.out| 14 ++-
 tests/qapi-schema/include-repetition.out | 14 ++-
 tests/qapi-schema/include-simple.out | 14 ++-
 tests/qapi-schema/indented-expr.out  |  9 -
 tests/qapi-schema/qapi-schema-test.out   | 50 +++-
 tests/qapi-schema/test-qapi.py   |  4 +-
 12 files changed, 149 insertions(+), 27 deletions(-)

diff --git a/tests/qapi-schema/comments.out b/tests/qapi-schema/comments.out
index 8d2f1ce8a2..d1abc4b5a1 100644
--- a/tests/qapi-schema/comments.out
+++ b/tests/qapi-schema/comments.out
@@ -1,5 +1,15 @@
 object q_empty
-enum QType ['none', 'qnull', 'qnum', 'qstring', 'qdict', 'qlist', 'qbool']
+enum QType
 prefix QTYPE
+member none
+member qnull
+member qnum
+member qstring
+member qdict
+member qlist
+member qbool
 module comments.json
-enum Status ['good', 'bad', 'ugly']
+enum Status
+member good
+member bad
+member ugly
diff --git a/tests/qapi-schema/doc-bad-section.out 
b/tests/qapi-schema/doc-bad-section.out
index cd28721568..db8014eed0 100644
--- a/tests/qapi-schema/doc-bad-section.out
+++ b/tests/qapi-schema/doc-bad-section.out
@@ -1,8 +1,17 @@
 object q_empty
-enum QType ['none', 'qnull', 'qnum', 'qstring', 'qdict', 'qlist', 'qbool']
+enum QType
 prefix QTYPE
+member none
+member qnull
+member qnum
+member qstring
+member qdict
+member qlist
+member qbool
 module doc-bad-section.json
-enum Enum ['one', 'two']
+enum Enum
+member one
+member two
 doc symbol=Enum
 body=
 == Produces *invalid* texinfo
diff --git a/tests/qapi-schema/doc-good.out b/tests/qapi-schema/doc-good.out
index 35f3f1164c..c2fc5c774a 100644
--- a/tests/qapi-schema/doc-good.out
+++ b/tests/qapi-schema/doc-good.out
@@ -1,8 +1,17 @@
 object q_empty
-enum QType ['none', 'qnull', 'qnum', 'qstring', 'qdict', 'qlist', 'qbool']
+enum QType
 prefix QTYPE
+member none
+member qnull
+member qnum
+member qstring
+member qdict
+member qlist
+member qbool
 module doc-good.json
-enum Enum ['one', 'two']
+enum Enum
+member one
+member two
 if ['defined(IFCOND)']
 object Base
 member base1: Enum optional=False
@@ -18,7 +27,9 @@ object q_obj_Variant1-wrapper
 member data: Variant1 optional=False
 object q_obj_Variant2-wrapper
 member data: Variant2 optional=False
-enum SugaredUnionKind ['one', 'two']
+enum SugaredUnionKind
+member one
+member two
 object SugaredUnion
 member type: SugaredUnionKind optional=False
 tag type
diff --git a/tests/qapi-schema/empty.out b/tests/qapi-schema/empty.out
index 0ec234eec4..5483cb7bc6 100644
--- a/tests/qapi-schema/empty.out
+++ b/tests/qapi-schema/empty.out
@@ -1,3 +1,10 @@
 object q_empty
-enum QType ['none', 'qnull', 'qnum', 'qstring', 'qdict', 'qlist', 'qbool']
+enum QType
 prefix QTYPE
+member none
+member qnull
+member qnum
+member qstring
+member qdict
+member qlist
+member qbool
diff --git a/tests/qapi-schema/event-case.out b/tests/qapi-schema/event-case.out
index 88c0964917..f69d4ffe4e 100644
--- a/tests/qapi-schema/event-case.out
+++ b/tests/qapi-schema/event-case.out
@@ -1,6 +1,13 @@
 object q_empty
-enum QType ['none', 'qnull', 'qnum', 'qstring', 'qdict', 'qlist', 'qbool']
+enum QType
 prefix QTYPE
+member none
+member qnull
+member qnum
+member qstring
+member qdict
+member qlist
+member qbool
 module event-case.json
 event oops None
boxed=False
diff --git a/tests/qapi-schema/ident-with-escape.out 
b/tests/qapi-schema/ident-with-escape.out
index 24c976f473..7f891f7e90 100644
--- a/tests/qapi-schema/ident-with-escape.out
+++ b/tests/qapi-schema/ident-with-escape.out
@@ -1,6 +1,13 @@
 object q_empty
-enum QType ['none', 'qnull', 'qnum', 'qstring', 'qdict', 'qlist', 'qbool']
+enum QType
 prefix QTYPE
+member none
+member qnull
+member qnum
+member qstring
+member qdict
+member qlist
+member qbool
 module ident-with-escape.json
 object q_obj_fooA-arg
 member bar1: str optional=False
diff --git a/tests/qapi-schema/include-relpath.out 

[Qemu-devel] [PULL 07/32] test-string-input-visitor: Use virtual walk

2018-12-13 Thread Markus Armbruster
From: David Hildenbrand 

We now support virtual walks, so use that instead.

Reviewed-by: Markus Armbruster 
Reviewed-by: Eric Blake 
Signed-off-by: David Hildenbrand 
Message-Id: <20181121164421.20780-8-da...@redhat.com>
Signed-off-by: Markus Armbruster 
---
 tests/test-string-input-visitor.c | 36 +++
 1 file changed, 12 insertions(+), 24 deletions(-)

diff --git a/tests/test-string-input-visitor.c 
b/tests/test-string-input-visitor.c
index c5379365a6..718d9a03c3 100644
--- a/tests/test-string-input-visitor.c
+++ b/tests/test-string-input-visitor.c
@@ -115,7 +115,6 @@ static void test_visitor_in_intList(TestInputVisitorData 
*data,
 uint64_t expect5[] = { UINT64_MAX };
 Error *err = NULL;
 int64List *res = NULL;
-int64List *tail;
 Visitor *v;
 int64_t val;
 
@@ -188,39 +187,28 @@ static void test_visitor_in_intList(TestInputVisitorData 
*data,
 
 v = visitor_input_test_init(data, "0,2-3");
 
-/* Would be simpler if the visitor genuinely supported virtual walks */
-visit_start_list(v, NULL, (GenericList **), sizeof(*res),
- _abort);
-tail = res;
-visit_type_int64(v, NULL, >value, _abort);
-g_assert_cmpint(tail->value, ==, 0);
-tail = (int64List *)visit_next_list(v, (GenericList *)tail, sizeof(*res));
-g_assert(tail);
-visit_type_int64(v, NULL, >value, _abort);
-g_assert_cmpint(tail->value, ==, 2);
-tail = (int64List *)visit_next_list(v, (GenericList *)tail, sizeof(*res));
-g_assert(tail);
+visit_start_list(v, NULL, NULL, 0, _abort);
+visit_type_int64(v, NULL, , _abort);
+g_assert_cmpint(val, ==, 0);
+visit_type_int64(v, NULL, , _abort);
+g_assert_cmpint(val, ==, 2);
 
 visit_check_list(v, );
 error_free_or_abort();
-visit_end_list(v, (void **));
-
-qapi_free_int64List(res);
+visit_end_list(v, NULL);
 
 /* Visit beyond end of list */
+
 v = visitor_input_test_init(data, "0");
 
-visit_start_list(v, NULL, (GenericList **), sizeof(*res),
- _abort);
-tail = res;
-visit_type_int64(v, NULL, >value, );
-g_assert_cmpint(tail->value, ==, 0);
+visit_start_list(v, NULL, NULL, 0, _abort);
+visit_type_int64(v, NULL, , );
+g_assert_cmpint(val, ==, 0);
 visit_type_int64(v, NULL, , );
 error_free_or_abort();
+
 visit_check_list(v, _abort);
-visit_end_list(v, (void **));
-
-qapi_free_int64List(res);
+visit_end_list(v, NULL);
 }
 
 static void test_visitor_in_bool(TestInputVisitorData *data,
-- 
2.17.2




Re: [Qemu-devel] [PATCH v2 7/7] iotests: add iotest 236 for testing bitmap merge

2018-12-13 Thread John Snow



On 12/13/18 8:50 AM, Vladimir Sementsov-Ogievskiy wrote:
> 13.12.2018 4:50, John Snow wrote:
>> New interface, new smoke test.
>>
>> Signed-off-by: John Snow 
>> ---
>>   tests/qemu-iotests/236 | 123 +
>>   tests/qemu-iotests/236.out | 265 +
>>   tests/qemu-iotests/group   |   1 +
>>   3 files changed, 389 insertions(+)
>>   create mode 100755 tests/qemu-iotests/236
>>   create mode 100644 tests/qemu-iotests/236.out
>>
>> diff --git a/tests/qemu-iotests/236 b/tests/qemu-iotests/236
>> new file mode 100755
>> index 00..3d162e967b
>> --- /dev/null
>> +++ b/tests/qemu-iotests/236
>> @@ -0,0 +1,123 @@
>> +#!/usr/bin/env python
>> +#
>> +# Test bitmap merges.
>> +#
>> +# Copyright (c) 2018 John Snow for Red Hat, Inc.
>> +#
>> +# This program is free software; you can redistribute it and/or modify
>> +# it under the terms of the GNU General Public License as published by
>> +# the Free Software Foundation; either version 2 of the License, or
>> +# (at your option) any later version.
>> +#
>> +# This program is distributed in the hope that it will be useful,
>> +# but WITHOUT ANY WARRANTY; without even the implied warranty of
>> +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
>> +# GNU General Public License for more details.
>> +#
>> +# You should have received a copy of the GNU General Public License
>> +# along with this program.  If not, see .
>> +#
>> +# owner=js...@redhat.com
>> +
>> +import sys
>> +import os
>> +import iotests
>> +from iotests import log
>> +sys.path.append(os.path.join(os.path.dirname(__file__), '..', '..', 
>> 'scripts'))
>> +from qemu import QEMUMachine
> 
> unused, with previous line and, therefore, os and sys modules)
> 

Forgive the copy and paste. I'll trim it down.

>> +
>> +iotests.verify_image_format(supported_fmts=['qcow2'])
>> +
>> +patterns = [("0x5d", "0", "64k"),
>> +("0xd5", "1M","64k"),
>> +("0xdc", "32M",   "64k"),
>> +("0xcd", "0x3ff", "64k")]  # 64M - 64K
>> +
>> +overwrite = [("0xab", "0", "64k"), # Full overwrite
>> + ("0xad", "0x00f8000", "64k"), # Partial-left (1M-32K)
>> + ("0x1d", "0x2008000", "64k"), # Partial-right (32M+32K)
>> + ("0xea", "0x3fe", "64k")] # Adjacent-left (64M - 128K)
>> +
>> +with iotests.FilePath('img') as img_path, \
>> + iotests.VM() as vm:
>> +
>> +log('--- Preparing image & VM ---\n')
>> +iotests.qemu_img_pipe('create', '-f', iotests.imgfmt, img_path, '64M')
> 
> hm, actually null device is enough here.
> 

Sure.

>> +vm.add_drive(img_path)
>> +vm.launch()
>> +
>> +log('--- Adding preliminary bitmaps A & B ---\n')
>> +vm.qmp_log("block-dirty-bitmap-add", node="drive0", name="bitmapA")
>> +vm.qmp_log("block-dirty-bitmap-add", node="drive0", name="bitmapB")
>> +
>> +# Dirties 4 clusters. count=262144 > +log('')
>> +log('--- Emulating writes ---\n')
>> +for p in patterns:
>> +cmd = "write -P%s %s %s" % p
>> +log(cmd)
>> +log(vm.hmp_qemu_io("drive0", cmd))
>> +
>> +vm.qmp_log("query-block", indent=2,
>> +   filters=[iotests.filter_generated_node_ids,
>> +iotests.filter_testfiles])
> 
> I'm against. query-block prints a lot of unrelated things, which may change 
> from
> version to version (for example, Andrey is now adding bitmap information to 
> qcow2
> format-specific info), then, backported test may fail for previous versions 
> (or just
> different config) because of something absolutely unrelated to bitmaps.
> 

You have a point. I'm only interested in the bitmap info structures, here.

> I think, it should be shortened to result[0]['device'], 
> result[0]['dirty-bitmaps']
> 

OK, let me look at printing something like

{
  "device0": bitmapInfo0,
  "device1": bitmapInfo1,
  ...
}

to the log.

> And, I think, any way it would be good to create a separate helper for 
> printing
> current state of bitmaps (which may output their sha256 too)
> 

Yeah, I was working on a command to do just this but I ran into troubles
with caching the bitmap info for computing it and wound up shelving the
series and I got sidetracked on other issues...

>> +
>> +log('')
>> +log('--- Disabling B & Adding C ---\n')
> 
> why not just
> log('\n--- Disabling B & Adding C ---\n')
> 

Just preference, there's no reason.

I have a habit of avoiding pre-pending control characters to string
lines, but don't have an aversion to appending them.

I can change it if it sticks out as too unusual.

> [...]
> 
> Otherwise, the test looks fine for me
> 
> 

Thanks for looking!



[Qemu-devel] [PATCH v1 1/1] sifive_u: Add clock DT node for GEM ethernet

2018-12-13 Thread Alistair Francis
From: Anup Patel 

The GEM ethernet on SiFive unleashed has fixed input clock
of 125MHz as-per SiFive FU540 manual. This patch updates FDT
generation for QEMU sifive_u machine to provide fixed-rate
clock for GEM ethernet.

Signed-off-by: Anup Patel 
Signed-off-by: Anup Patel 
Signed-off-by: Alistair Francis 
---
 hw/riscv/sifive_u.c | 18 +-
 include/hw/riscv/sifive_u.h |  3 ++-
 2 files changed, 19 insertions(+), 2 deletions(-)

diff --git a/hw/riscv/sifive_u.c b/hw/riscv/sifive_u.c
index ef07df2442..5c41ee5017 100644
--- a/hw/riscv/sifive_u.c
+++ b/hw/riscv/sifive_u.c
@@ -85,7 +85,8 @@ static void create_fdt(SiFiveUState *s, const struct 
MemmapEntry *memmap,
 int cpu;
 uint32_t *cells;
 char *nodename;
-uint32_t plic_phandle;
+char ethclk_names[] = "pclk\0hclk\0tx_clk";
+uint32_t plic_phandle, ethclk_phandle;
 
 fdt = s->fdt = create_device_tree(>fdt_size);
 if (!fdt) {
@@ -197,6 +198,17 @@ static void create_fdt(SiFiveUState *s, const struct 
MemmapEntry *memmap,
 g_free(cells);
 g_free(nodename);
 
+nodename = g_strdup_printf("/soc/ethclk");
+qemu_fdt_add_subnode(fdt, nodename);
+qemu_fdt_setprop_string(fdt, nodename, "compatible", "fixed-clock");
+qemu_fdt_setprop_cell(fdt, nodename, "#clock-cells", 0x0);
+qemu_fdt_setprop_cell(fdt, nodename, "clock-frequency",
+SIFIVE_U_GEM_CLOCK_FREQ);
+qemu_fdt_setprop_cell(fdt, nodename, "phandle", 3);
+qemu_fdt_setprop_cell(fdt, nodename, "linux,phandle", 3);
+ethclk_phandle = qemu_fdt_get_phandle(fdt, nodename);
+g_free(nodename);
+
 nodename = g_strdup_printf("/soc/ethernet@%lx",
 (long)memmap[SIFIVE_U_GEM].base);
 qemu_fdt_add_subnode(fdt, nodename);
@@ -208,6 +220,10 @@ static void create_fdt(SiFiveUState *s, const struct 
MemmapEntry *memmap,
 qemu_fdt_setprop_string(fdt, nodename, "phy-mode", "gmii");
 qemu_fdt_setprop_cells(fdt, nodename, "interrupt-parent", plic_phandle);
 qemu_fdt_setprop_cells(fdt, nodename, "interrupts", SIFIVE_U_GEM_IRQ);
+qemu_fdt_setprop_cells(fdt, nodename, "clocks",
+ethclk_phandle, ethclk_phandle, ethclk_phandle);
+qemu_fdt_setprop(fdt, nodename, "clocks-names", ethclk_names,
+sizeof(ethclk_names));
 qemu_fdt_setprop_cells(fdt, nodename, "#address-cells", 1);
 qemu_fdt_setprop_cells(fdt, nodename, "#size-cells", 0);
 g_free(nodename);
diff --git a/include/hw/riscv/sifive_u.h b/include/hw/riscv/sifive_u.h
index e8b4d9ffa3..be13cc1304 100644
--- a/include/hw/riscv/sifive_u.h
+++ b/include/hw/riscv/sifive_u.h
@@ -63,7 +63,8 @@ enum {
 };
 
 enum {
-SIFIVE_U_CLOCK_FREQ = 10
+SIFIVE_U_CLOCK_FREQ = 10,
+SIFIVE_U_GEM_CLOCK_FREQ = 12500
 };
 
 #define SIFIVE_U_PLIC_HART_CONFIG "MS"
-- 
2.19.1




[Qemu-devel] [PATCH v1 1/1] sifive_u: Set 'clock-frequency' DT property for SiFive UART

2018-12-13 Thread Alistair Francis
From: Anup Patel 

The 'clock-frequency' DT property is required by U-Boot to compute
the divider value. This patch sets the 'clock-frequency' DT property
of the SiFive UART device tree node (similar to virt machine).

Signed-off-by: Anup Patel 
Signed-off-by: Anup Patel 
Signed-off-by: Alistair Francis 
---
 hw/riscv/sifive_u.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/hw/riscv/sifive_u.c b/hw/riscv/sifive_u.c
index ef07df2442..f30bbfd1d6 100644
--- a/hw/riscv/sifive_u.c
+++ b/hw/riscv/sifive_u.c
@@ -225,6 +225,8 @@ static void create_fdt(SiFiveUState *s, const struct 
MemmapEntry *memmap,
 qemu_fdt_setprop_cells(fdt, nodename, "reg",
 0x0, memmap[SIFIVE_U_UART0].base,
 0x0, memmap[SIFIVE_U_UART0].size);
+qemu_fdt_setprop_cell(fdt, nodename, "clock-frequency",
+  SIFIVE_U_CLOCK_FREQ / 2);
 qemu_fdt_setprop_cells(fdt, nodename, "interrupt-parent", plic_phandle);
 qemu_fdt_setprop_cells(fdt, nodename, "interrupts", 1);
 
-- 
2.19.1




[Qemu-devel] [PATCH] hw/misc/tz-mpc: Fix value of BLK_MAX register

2018-12-13 Thread Peter Maydell
In the TZ Memory Protection Controller, the BLK_MAX register is supposed
to return the maximum permitted value of the BLK_IDX register. Our
implementation incorrectly returned max+1 (ie the total number of
valid index values, since BLK_IDX is zero-based).

Correct this off-by-one error. Since we consistently initialize
and use s->blk_max throughout the implementation as the 'size'
of the LUT, just adjust the value we return when the guest reads
the BLK_MAX register, rather than trying to change the semantics
of the s->blk_max internal struct field.

Fixes: https://bugs.launchpad.net/qemu/+bug/1806824
Signed-off-by: Peter Maydell 
---
 hw/misc/tz-mpc.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/hw/misc/tz-mpc.c b/hw/misc/tz-mpc.c
index e0c58ba37ec..946147b1c02 100644
--- a/hw/misc/tz-mpc.c
+++ b/hw/misc/tz-mpc.c
@@ -150,7 +150,7 @@ static MemTxResult tz_mpc_reg_read(void *opaque, hwaddr 
addr,
 r = s->ctrl;
 break;
 case A_BLK_MAX:
-r = s->blk_max;
+r = s->blk_max - 1;
 break;
 case A_BLK_CFG:
 /* We are never in "init in progress state", so this just indicates
-- 
2.19.2




Re: [Qemu-devel] Loading snapshot with readonly qcow2 image

2018-12-13 Thread Michael Spradling
On Nov 30 08:58, Eric Blake wrote:
> On 11/30/18 8:44 AM, Michael Spradling wrote:
> > Hello,
> > 
> > I would like to resume a snapshot via the command line option -loadvm
> > with a read only QCOW2 file.  For my use case, I would ideally like to
> > load multiple instances of different snapshots from the same QCOW2 image.
> > 
> > It seems this is not possible at the moment as when a snapshot is loaded, 
> > QEMU
> > copies some meta data around in the qcow2 image.
> > 
> > I have also tried to use the "-snapshot" option, which to my understanding
> > creates a new temporary QCOW2 file with a backing file pointing the original
> > image passed on the command line.  This also does not work, when looking
> > through the source it appears QEMU only supports loading snapshots from 
> > writable
> > QCOW2 images and doesn't support loading from images in backing files.
> > 
> > My question is has anyone looked into loading snapshots from a backing
> > file?  I have attempted to look through the code and this looks to be
> > difficult.  If I attempt to add support for this is there any general
> > advice to follow?  Any other ideas?
> 
> 'qemu-nbd -l' can serve snapshots from a qcow2 file; perhaps that can be
> used to cobble together something that works for your needs?
> 
> Sadly, internal snapshots don't get much attention these days, so there may
> well be missing functionality, but no one is really stepping up to provide
> patches.
> 
> -- 
> Eric Blake, Principal Software Engineer
> Red Hat, Inc.   +1-919-301-3266
> Virtualization:  qemu.org | libvirt.org

I looked at "qemu-nbd -l" and this seems to only export a readonly
interface.  Really, what I need is a writable temp file that can load a
snapshot snapshot.

Please excuse and correct me if I get some of the terminology of the
sections below wrong.

I went down the path of hacking up some of the qemu qcow2 file system
code to see if I can achieve the ability to restore a snapshot from a
backing file to the temporarily created "-snapshot" qcow2 image.  The
backing file has been marked readonly by the filesystem and the active
image file was created with the "-snapshot" option.  I spend some time
reading the qcow2 documentation and it seems I have to copy the l1 and
l2 table values(are these actual host clusters) from the backing file
snapshot to the active images l1 and l2 tables.  Is there anything else
that may need updated that I have not yet stumbled upon?

I still don't have this working yet and I believe my area of problems is
qcow2_update_snapshot_refcount.  Can anyone explain what this does
exactly.  It seems the function does three different things based on the
value of addend, either -1, 0, 1, but its somewhat unclear.

Thanks,
Michael



Re: [Qemu-devel] [PATCH v2 7/7] iotests: add iotest 236 for testing bitmap merge

2018-12-13 Thread John Snow



On 12/12/18 9:27 PM, Eric Blake wrote:
> On 12/12/18 7:50 PM, John Snow wrote:
>> New interface, new smoke test.
>>
>> Signed-off-by: John Snow 
>> ---
>>   tests/qemu-iotests/236 | 123 +
>>   tests/qemu-iotests/236.out | 265 +
>>   tests/qemu-iotests/group   |   1 +
>>   3 files changed, 389 insertions(+)
>>   create mode 100755 tests/qemu-iotests/236
>>   create mode 100644 tests/qemu-iotests/236.out
>>
>> diff --git a/tests/qemu-iotests/236 b/tests/qemu-iotests/236
> 
>> +    log('')
>> +    log('--- Disabling B & Adding C ---\n')
>> +    vm.qmp_log("transaction", actions=[
>> +    { "type": "block-dirty-bitmap-disable",
>> +  "data": { "node": "drive0", "name": "bitmapB" }},
>> +    { "type": "block-dirty-bitmap-add",
>> +  "data": { "node": "drive0", "name": "bitmapC" }}
>> +    ])
> 
> Just for grins, what happens if we extend that transaction to
> additionally call:
> 
>    { "type": "block-dirty-bitmap-disable",
>  "data": { "node": "drive0", "name": "bitmapC" }},
>    { "type": "block-dirty-bitmap-enable",
>  "data": { "node": "drive0", "name": "bitmapC" }}
> 
> Yes, we have a redundancy where plain '-add' coupled with '-disable' in
> a transaction does the same as '-add' with 'enabled':false.  And I'd
> rather keep 'enabled':false as part of '-add', as it's handy to do that
> without having to code up a transaction.  But the specific act of
> toggling the enabled bit twice on a brand new bitmap as part of the same
> transaction, while unlikely to be done by libvirt, may still prove to be
> a useful validation of our transaction semantics.
> 
>> +++ b/tests/qemu-iotests/group
>> @@ -233,3 +233,4 @@
>>   233 auto quick
>>   234 auto quick migration
>>   235 auto quick
>> +236 auto quick
>> \ No newline at end of file
> 
> You'll want to fix that.
> 

Now that you've pointed it out, I have to. :)

> Reviewed-by: Eric Blake 
> 

OK. I want more tests, too; mostly around malformed requests (bad
target, single bad source, multiple bad sources, mixed bad sources).
your suggestion to merge self into self,
and maybe anything else I've forgotten by now.

--js



Re: [Qemu-devel] [PATCH v2 6/7] iotests: allow pretty-print for qmp_log

2018-12-13 Thread John Snow



On 12/12/18 9:20 PM, Eric Blake wrote:
> On 12/12/18 7:50 PM, John Snow wrote:
>> If iotests have lines exceeding >998 characters long, git doesn't
>> want to send it plaintext to the list. We can solve this by allowing
>> the iotests to use pretty printed QMP output that we can match against
>> instead.
>>
>> As a bonus, it's much nicer for human eyes, too.
>>
>> Signed-off-by: John Snow 
>> ---
>>   tests/qemu-iotests/iotests.py | 4 ++--
>>   1 file changed, 2 insertions(+), 2 deletions(-)
>>
>> diff --git a/tests/qemu-iotests/iotests.py
>> b/tests/qemu-iotests/iotests.py
>> index 9595429fea..dbbef4bad3 100644
>> --- a/tests/qemu-iotests/iotests.py
>> +++ b/tests/qemu-iotests/iotests.py
>> @@ -447,12 +447,12 @@ class VM(qtest.QEMUQtestMachine):
>>   result.append(filter_qmp_event(ev))
>>   return result
>>   -    def qmp_log(self, cmd, filters=[filter_testfiles], **kwargs):
>> +    def qmp_log(self, cmd, indent=None, filters=[filter_testfiles],
>> **kwargs):
> 
> Why None instead of False?
> 
>>   logmsg = '{"execute": "%s", "arguments": %s}' % \
>>   (cmd, json.dumps(kwargs, sort_keys=True))
>>   log(logmsg, filters)
>>   result = self.qmp(cmd, **kwargs)
>> -    log(json.dumps(result, sort_keys=True), filters)
>> +    log(json.dumps(result, indent=indent, sort_keys=True), filters)
> 
> But I'd actually have to read the contract to json.dumps() to learn what
> is expected.
> 
> /me goes and does that...
> https://docs.python.org/2/library/json.html
> 
> If indent is a non-negative integer, then JSON array elements and object
> members will be pretty-printed with that indent level. An indent level
> of 0, or negative, will only insert newlines. None (the default) selects
> the most compact representation.
> 
> Okay, makes sense.
> Reviewed-by: Eric Blake 
> 

Yeah, it's a bubbling up of API in this case and a little messy, but it
was the quickest route to making the output look pretty.



Re: [Qemu-devel] [PATCH 0/1] checkpatch: checker for comment block

2018-12-13 Thread Peter Maydell
On Thu, 13 Dec 2018 at 18:07, Paolo Bonzini  wrote:
> On 13/12/18 19:01, Peter Maydell wrote:
> > I sent a patch to do this a little while back:
> >  https://patchwork.kernel.org/patch/10561557/
> >
> > It didn't get applied because Paolo disagreed with having
> > our tools enforcing what our style guide says.
>
> I didn't disagree with that---I disagreed with having a single style in
> the style guide, because unlike most other blatant violations of the
> coding style (eg. braces), this one is pervasive in maintained code and
> I don't want code that I maintain to mix two comment styles.
>
> So I proposed two alternatives:
>
> - someone fixes all the comment blocks which are "starred" but don't
> have a lone "/*" at the beginning, and then we can commit that patch;
>
> - we allow "/* foo" on the first line, except for doc comments and for
> the first line of the file (author/license block), and fix the style
> guide accordingly.

We came to a consensus on the comment style when we discussed
the patch which updated CODING_STYLE. I'm not personally
a fan of the result (I used to use "/* foo"), but what we have in the
doc is what we achieved consensus for. I'm not going to reopen
the "what should block comments look like" style debate.

We have always had older code which isn't following the new style,
and our general approach is that we don't do mass-style-fix patches
across the whole codebase. If you as a maintainer of a particular
sub-area want to do a style update you're free to do that.

thanks
-- PMM



Re: [Qemu-devel] ping2 Re: [PATCH v4 0/8] dirty-bitmap: rewrite bdrv_dirty_iter_next_area

2018-12-13 Thread John Snow



On 12/13/18 6:07 AM, Vladimir Sementsov-Ogievskiy wrote:
> 12.12.2018 23:41, John Snow wrote:
>>
>>
>> On 12/12/18 4:27 AM, Vladimir Sementsov-Ogievskiy wrote:
>>> ping. No dependencies, apply to master.
>>>
>>
>> Sure thing.
>>
>> Staged to jsnow/bitmaps.
> 
> 
> Thank you!
> 
> Oops, I've missed your email about s/firt_dirty_off/first_dirty_off
> 
> I can resend, or you can fix in your branch, as you prefer.
> The variable touches two commits in jsnow/bitmaps:
> 

Whoops, I forgot too. I just remember that I was waiting on a requisite
and it got lost so I was in a hurry to stage it for you. I'll just
squash any fixes in.

I'll try to send the PR when the qemu-img bitmap info patch is ready,
alongside my series to drop the x-prefix (and adjust the merge API.)

Anything else urgent for the start of the 4.0 window before we all
disappear on holiday break?

--js

> commit f235204c39dd5ce122666d87f18005264eb56e51
> Author: Vladimir Sementsov-Ogievskiy 
> Date:   Mon Sep 17 17:57:27 2018 +0300
> 
>  dirty-bitmap: add bdrv_dirty_bitmap_next_dirty_area
> 
> and the last one:
> 
> commit 7f73174ca1c8a92e4a5139b35f2a2273f59ce29b (jnsnow/bitmaps)
> Author: Vladimir Sementsov-Ogievskiy 
> Date:   Mon Sep 17 17:57:32 2018 +0300
> 
>  Revert "hbitmap: Add @advance param to hbitmap_iter_next()"
> 
> 
> 
> 



[Qemu-devel] [PULL v2 00/46] Misc patches for 2018-12-13

2018-12-13 Thread Paolo Bonzini
The following changes since commit bb9bf94b3e8926553290bc9a7cb84315af422086:

  Merge remote-tracking branch 
'remotes/ehabkost/tags/machine-next-pull-request' into staging (2018-12-11 
19:18:58 +)

are available in the Git repository at:

  git://github.com/bonzini/qemu.git tags/for-upstream

for you to fetch changes up to d115ceb731fc09134fb0816c956ab0eb88fbfa7b:

  vhost-user-test: create a temporary directory per TestServer (2018-12-13 
10:57:30 +0100)


* HAX support for Linux hosts (Alejandro)
* esp bugfixes (Guenter)
* Windows build cleanup (Marc-André)
* checkpatch logic improvements (Paolo)
* coalesced range bugfix (Paolo)
* switch testsuite to TAP (Paolo)
* QTAILQ rewrite (Paolo)
* enable vhost for TCG and clean up vhost-user-test (Paolo)
* block/iscsi.c cancellation fixes (Stefan)
* improve selection of the default accelerator (Thomas)


Alexandro Sanchez Bach (1):
  hax: Support for Linux hosts

Guenter Roeck (2):
  esp-pci: Fix status register write erase control
  scsi: esp: Defer command completion until previous interrupts have been 
handled

Marc-André Lureau (5):
  vhost-user-bridge: fix "unknown type name" compilation error
  build-sys: don't include windows.h, osdep.h does it
  build-sys: move windows defines in osdep.h header
  build-sys: build with Vista API by default
  qga: drop < Vista compatibility

Paolo Bonzini (32):
  checkpatch: fix premature exit when no input or --mailback
  checkpatch: check Signed-off-by in --mailback mode
  checkpatch: improve handling of multiple patches or files
  checkpatch: colorize output to terminal
  pam: wrap MemoryRegion initialization in a transaction
  memory: extract flat_range_coalesced_io_{del,add}
  memory: avoid unnecessary coalesced_io_del operations
  memory: update coalesced_range on transaction_commit
  test: execute g_test_run when tests are skipped
  test: replace gtester with a TAP driver
  qemu/queue.h: do not access tqe_prev directly
  vfio: make vfio_address_spaces static
  qemu/queue.h: leave head structs anonymous unless necessary
  qemu/queue.h: typedef QTAILQ heads
  qemu/queue.h: remove Q_TAILQ_{HEAD,ENTRY}
  qemu/queue.h: reimplement QTAILQ without pointer-to-pointers
  qemu/queue.h: simplify reverse access to QTAILQ
  checkpatch: warn about qemu/queue.h head structs that are not typedef-ed
  vhost-net: move stubs to a separate file
  vhost-net-user: add stubs for when no virtio-net device is present
  vhost: restrict Linux dependency to kernel vhost
  vhost-net: compile it on all targets that have virtio-net.
  vhost-net: revamp configure logic
  vhost-user-test: use g_cond_broadcast
  vhost-user-test: signal data_cond when s->rings changes
  vhost-user: support cross-endian vnet headers
  vhost-user-test: support VHOST_USER_PROTOCOL_F_CROSS_ENDIAN
  vhost-user-test: skip if there is no memory at address 0
  vhost-user-test: reduce usage of global_qtest
  vhost-user-test: create a main loop per TestServer
  vhost-user-test: small changes to init_hugepagefs
  vhost-user-test: create a temporary directory per TestServer

Peng Hao (1):
  hw/watchdog/wdt_i6300esb: remove a unnecessary comment

Stefan Hajnoczi (4):
  block/iscsi: drop unused IscsiAIOCB->buf field
  block/iscsi: take iscsilun->mutex in iscsi_timed_check_events()
  block/iscsi: fix ioctl cancel use-after-free
  block/iscsi: cancel libiscsi task when ABORT TASK TMF completes

Thomas Huth (1):
  accel: Improve selection of the default accelerator

 accel/accel.c|  18 +-
 accel/kvm/kvm-all.c  |   4 +-
 accel/tcg/translate-all.c|   4 -
 backends/Makefile.objs   |   5 +-
 block/gluster.c  |   2 +-
 block/iscsi.c|  47 +++-
 block/mirror.c   |   2 +-
 block/qcow2-bitmap.c |   4 +-
 block/qcow2.h|   2 +-
 block/sheepdog.c |   6 +-
 block/vhdx.h |   2 +-
 blockdev.c   |   4 +-
 configure| 105 +---
 contrib/ivshmem-client/ivshmem-client.h  |   4 +-
 contrib/ivshmem-server/ivshmem-server.h  |   5 +-
 cpus-common.c|   2 +-
 default-configs/virtio.mak   |   4 +-
 dump.c   |   2 +-
 exec.c   |   5 +-
 fsdev/qemu-fsdev.c   |   2 +-
 hw/block/nvme.h  |   8 +-
 hw/block/xen_disk.c  |   6 +-
 

Re: [Qemu-devel] [PULL 00/11] Monitor patches for 2018-12-12

2018-12-13 Thread Markus Armbruster
Peter Maydell  writes:

> On Wed, 12 Dec 2018 at 10:13, Markus Armbruster  wrote:
>>
>> The following changes since commit bb9bf94b3e8926553290bc9a7cb84315af422086:
>>
>>   Merge remote-tracking branch 
>> 'remotes/ehabkost/tags/machine-next-pull-request' into staging (2018-12-11 
>> 19:18:58 +)
>>
>> are available in the Git repository at:
>>
>>   git://repo.or.cz/qemu/armbru.git tags/pull-monitor-2018-12-12
>>
>> for you to fetch changes up to c55f070b7195cee4e06998c10f57f13c7df98dbd:
>>
>>   tests: add oob functional test for test-qmp-cmds (2018-12-12 10:28:27 
>> +0100)
>>
>> 
>> Monitor patches for 2018-12-12
>>
>> * Fixes related to running the monitor in an I/O thread
>> * Change how OOB-enabled QMP monitors handle flow control: suspend
>>   monitor instead dropping commands
>> * Offer QMP capability "oob" unconditionally, remove "x-oob"
>>
>
> Applied, thanks.
>
> Please update the changelog at https://wiki.qemu.org/ChangeLog/4.0
> for any user-visible changes.

Done.  Thanks for the reminder!



Re: [Qemu-devel] [PATCH 0/1] checkpatch: checker for comment block

2018-12-13 Thread Paolo Bonzini
On 13/12/18 19:01, Peter Maydell wrote:
> On Thu, 13 Dec 2018 at 17:57, Wainer dos Santos Moschetta
>  wrote:
>>
>> Eduardo Habkost pointed out a malformed block of comments on my
>> patch [1] that I had ran checkpatch.pl and no warn/error was
>> reported. Then I realized the script does not catch such as
>> case (or it had a bug).
>>
>> It turns out that checkpatch.pl does not parse comment blocks (If I 
>> understood
>> its code correctly...). So I implemented a checker that warns about:
>> 1. block doesn't begin on its own line.
>> Example:
>>   /* blah blah
>>* and blah blah
>>*/
> 
> I sent a patch to do this a little while back:
>  https://patchwork.kernel.org/patch/10561557/
> 
> It didn't get applied because Paolo disagreed with having
> our tools enforcing what our style guide says.

I didn't disagree with that---I disagreed with having a single style in
the style guide, because unlike most other blatant violations of the
coding style (eg. braces), this one is pervasive in maintained code and
I don't want code that I maintain to mix two comment styles.

So I proposed two alternatives:

- someone fixes all the comment blocks which are "starred" but don't
have a lone "/*" at the beginning, and then we can commit that patch;

- we allow "/* foo" on the first line, except for doc comments and for
the first line of the file (author/license block), and fix the style
guide accordingly.

Paolo



Re: [Qemu-devel] [PATCH 0/1] checkpatch: checker for comment block

2018-12-13 Thread Peter Maydell
On Thu, 13 Dec 2018 at 17:57, Wainer dos Santos Moschetta
 wrote:
>
> Eduardo Habkost pointed out a malformed block of comments on my
> patch [1] that I had ran checkpatch.pl and no warn/error was
> reported. Then I realized the script does not catch such as
> case (or it had a bug).
>
> It turns out that checkpatch.pl does not parse comment blocks (If I understood
> its code correctly...). So I implemented a checker that warns about:
> 1. block doesn't begin on its own line.
> Example:
>   /* blah blah
>* and blah blah
>*/

I sent a patch to do this a little while back:
 https://patchwork.kernel.org/patch/10561557/

It didn't get applied because Paolo disagreed with having
our tools enforcing what our style guide says.

Personally I think we should just commit my patch, and then
we can stop having people manually pointing out where
submitters' patches don't match CODING_STYLE.

thanks
-- PMM



[Qemu-devel] [PATCH] vl: Use error_fatal to simplify obvious fatal errors (again)

2018-12-13 Thread Markus Armbruster
Patch created mechanically by rerunning:

$ spatch --in-place --sp-file scripts/coccinelle/use-error_fatal.cocci \
 --macro-file scripts/cocci-macro-file.h vl.c

Signed-off-by: Markus Armbruster 
---
 vl.c | 7 ++-
 1 file changed, 2 insertions(+), 5 deletions(-)

diff --git a/vl.c b/vl.c
index a5ae5f23d2..702a828ca2 100644
--- a/vl.c
+++ b/vl.c
@@ -3138,11 +3138,8 @@ int main(int argc, char **argv, char **envp)
 Visitor *v;
 BlockdevOptions_queue *bdo;
 
-v = qobject_input_visitor_new_str(optarg, "driver", );
-if (!v) {
-error_report_err(err);
-exit(1);
-}
+v = qobject_input_visitor_new_str(optarg, "driver",
+  _fatal);
 
 bdo = g_new(BlockdevOptions_queue, 1);
 visit_type_BlockdevOptions(v, NULL, >bdo,
-- 
2.17.2




[Qemu-devel] [PATCH 1/1] checkpatch: check for malformed comment block.

2018-12-13 Thread Wainer dos Santos Moschetta
Currently scripts/checkpatch.pl does not check if multiline
comments follow the QEMU's coding sytle.

It is added a check for multiline comments that warns about:
1. block doesn't begin on its own line.
2. line in the block doesn't start with asterisk.
3. block doesn't end on its own line.

Signed-off-by: Wainer dos Santos Moschetta 
---
 scripts/checkpatch.pl | 32 
 1 file changed, 32 insertions(+)

diff --git a/scripts/checkpatch.pl b/scripts/checkpatch.pl
index 60f6f89a27..5abb579ed7 100755
--- a/scripts/checkpatch.pl
+++ b/scripts/checkpatch.pl
@@ -1858,6 +1858,38 @@ sub process {
$line =~ s@//.*@@;
$opline =~ s@//.*@@;
 
+# check for malformed comment block.
+   if ($rawline =~ m{/\*} && $rawline !~ m{\*\/}) {
+   if ($rawline !~ m{^.\s*/\*+$}) {
+   WARN("comment block should begin on its own" .
+   " line\n" . $herecurr);
+   }
+
+   my $rel_line = 1;
+   my $reported = 0;
+   my $comment_line = '';
+   my $herecurr = '';
+   do {
+   $comment_line = $rawlines[$rel_line + $linenr
+   - 1];
+   $herecurr = "#".($linenr + $rel_line) .
+   ": FILE: ".$realfile .
+   ":".($realline + $rel_line)."\n" .
+   $comment_line."\n";
+   if (!$reported && $comment_line !~ m{^.\s*\*}) {
+   WARN("line in comment block should" .
+   " start with asterisk\n" .
+   $herecurr);
+   $reported = 1;
+   }
+   $rel_line++;
+   } while ($comment_line && $comment_line !~ m{\*\/});
+
+   if ($comment_line && $comment_line !~ m{^.\s*\*+\/}) {
+   WARN("comment block should end on its own" .
+   " line\n".$herecurr);
+   }
+   }
 # check for global initialisers.
if ($line =~ 
/^.$Type\s*$Ident\s*(?:\s+$Modifier)*\s*=\s*(0|NULL|false)\s*;/) {
ERROR("do not initialise globals to 0 or NULL\n" .
-- 
2.19.1




<    1   2   3   4   5   >