Re: [Qemu-devel] [SeaBIOS PATCH 2/2] allow CPUs to have non-contiguous Local APIC IDs (v2)

2012-07-26 Thread Gleb Natapov
On Wed, Jul 25, 2012 at 03:42:21PM -0300, Eduardo Habkost wrote:
 On Mon, Jul 23, 2012 at 03:20:14PM +0300, Gleb Natapov wrote:
  On Fri, Jul 20, 2012 at 02:04:50PM -0300, Eduardo Habkost wrote:
   Extract Local APIC IDs directly from the CPUs, and instead of check for
   i  CountCPUs, check if the APIC ID was present on boot, when building
   ACPI tables and the MP-Table.
   
   This keeps ACPI Processor ID == APIC ID, but allows the
   hardware-SeaBIOS interface be completely APIC-ID based and not depend
   on any other kind of CPU identifier. This way, SeaBIOS may change the
   way ACPI Processor IDs are chosen in the future.
   
   As currently SeaBIOS supports only xAPIC and not x2APIC, the list of
   present-on-boot APIC IDs is a 256-bit bitmap. If one day SeaBIOS starts
   to support x2APIC, the data structure used to enumerate the APIC IDs
   will have to be changed (but this is an internal implementation detail,
   not visible to the OS or on any hardware=SeaBIOS interface).
   
   For current QEMU versions (that always make the APIC IDs contiguous),
   the OS-visible behavior and resulting ACPI tables should be exactly the
   same. This patch will simply allow QEMU to start setting non-contiguous
   APIC IDs (that is a requirement for some sockets/cores/threads topology
   settings).
   
   Changes v1 - v2:
- Use size suffixes on all asm instructions on smp.c
- New patch description
   
   Signed-off-by: Eduardo Habkost ehabk...@redhat.com
   ---
src/acpi-dsdt.dsl |4 +++-
src/acpi.c|9 +
src/mptable.c |2 +-
src/smp.c |   17 +
src/util.h|1 +
5 files changed, 27 insertions(+), 6 deletions(-)
   
   diff --git a/src/acpi-dsdt.dsl b/src/acpi-dsdt.dsl
   index 2060686..72dc7d8 100644
   --- a/src/acpi-dsdt.dsl
   +++ b/src/acpi-dsdt.dsl
   @@ -676,6 +676,7 @@ DefinitionBlock (
/* Methods called by run-time generated SSDT Processor objects */
Method (CPMA, 1, NotSerialized) {
// _MAT method - create an madt apic buffer
   +// Arg0 = Processor ID = Local APIC ID
// Local0 = CPON flag for this cpu
Store(DerefOf(Index(CPON, Arg0)), Local0)
// Local1 = Buffer (in madt apic form) to return
   @@ -688,6 +689,7 @@ DefinitionBlock (
}
Method (CPST, 1, NotSerialized) {
// _STA method - return ON status of cpu
   +// Arg0 = Processor ID = Local APIC ID
// Local0 = CPON flag for this cpu
Store(DerefOf(Index(CPON, Arg0)), Local0)
If (Local0) { Return(0xF) } Else { Return(0x0) }
   @@ -708,7 +710,7 @@ DefinitionBlock (
Store (PRS, Local5)
// Local2 = last read byte from bitmap
Store (Zero, Local2)
   -// Local0 = cpuid iterator
   +// Local0 = Processor ID / APIC ID iterator
Store (Zero, Local0)
While (LLess(Local0, SizeOf(CPON))) {
// Local1 = CPON flag for this cpu
   diff --git a/src/acpi.c b/src/acpi.c
   index da3bc57..39b7172 100644
   --- a/src/acpi.c
   +++ b/src/acpi.c
   @@ -327,7 +327,7 @@ build_madt(void)
apic-length = sizeof(*apic);
apic-processor_id = i;
apic-local_apic_id = i;
   -if (i  CountCPUs)
   +if (apic_id_is_present(apic-local_apic_id))
apic-flags = cpu_to_le32(1);
else
apic-flags = cpu_to_le32(0);
   @@ -445,6 +445,7 @@ build_ssdt(void)
}

// build Method(NTFY, 2) {If (LEqual(Arg0, 0x00)) {Notify(CP00, 
   Arg1)} ...}
   +// Arg0 = Processor ID = APIC ID
*(ssdt_ptr++) = 0x14; // MethodOp
ssdt_ptr = encodeLen(ssdt_ptr, 2+5+(12*acpi_cpus), 2);
*(ssdt_ptr++) = 'N';
   @@ -477,7 +478,7 @@ build_ssdt(void)
ssdt_ptr = encodeLen(ssdt_ptr, 2+1+(1*acpi_cpus), 2);
*(ssdt_ptr++) = acpi_cpus;
for (i=0; iacpi_cpus; i++)
   -*(ssdt_ptr++) = (i  CountCPUs) ? 0x01 : 0x00;
   +*(ssdt_ptr++) = (apic_id_is_present(i)) ? 0x01 : 0x00;

// store pci io windows: start, end, length
// this way we don't have to do the math in the dsdt
   @@ -656,10 +657,10 @@ build_srat(void)
core-proximity_lo = curnode;
memset(core-proximity_hi, 0, 3);
core-local_sapic_eid = 0;
   -if (i  CountCPUs)
   +if (apic_id_is_present(i))
core-flags = cpu_to_le32(1);
else
   -core-flags = 0;
   +core-flags = cpu_to_le32(0);
core++;
}

   diff --git a/src/mptable.c b/src/mptable.c
   index 103f462..9406f98 100644
   --- a/src/mptable.c
   +++ b/src/mptable.c
   @@ -59,7 +59,7 @@ mptable_init(void)
cpu-apicid = i;
cpu-apicver = apic_version;
/* cpu flags: enabled, 

Re: [Qemu-devel] [Qemu-discuss] qemu-kvm: -netdev user: Parameter 'id' is missing

2012-07-26 Thread anatoly techtonik
On Wed, Jul 25, 2012 at 6:00 PM, Stefan Hajnoczi stefa...@gmail.com wrote:
 On Tue, Jul 24, 2012 at 8:02 PM, anatoly techtonik techto...@gmail.com 
 wrote:
 On Tue, Jul 24, 2012 at 1:23 PM, Stefan Hajnoczi stefa...@gmail.com wrote:
 On Mon, Jul 23, 2012 at 10:41 PM, anatoly techtonik techto...@gmail.com 
 wrote:
 Forwarding per discussion in qemu-discuss.
 Please CC.

 -- Forwarded message --
 From: Mike Lovell m...@dev-zero.net
 Date: Mon, Jul 23, 2012 at 10:58 PM
 Subject: Re: [Qemu-discuss] qemu-kvm: -netdev user: Parameter 'id' is 
 missing
 To: qemu-disc...@nongnu.org


 On 07/20/2012 04:10 PM, anatoly techtonik wrote:

 The documentation at http://wiki.qemu.org/Documentation/Networking
 makes people think that 'id' parameter for -netdev user is optional,
 which doesn't appear to be true:

  $ qemu-kvm -hda image.img -netdev user
  qemu-kvm: -netdev user: Parameter 'id' is missing

 I have updated the wiki page.

 Even with -net nic considered obsolete (is the whole -net family
 obsolete?), it looks like there is no complete replacement for it. For
 example, there is no equivalent for -net nic,model=? (referenced from
 wiki). It is also strange to read proposal to see the qemu man page
 for the various options that you can pass to -net nic. Unfortunately,
 -netdev is completely undocumented in man and there is no info that
 -net nic and -net user are obsolete there. All this stuff is
 confusing.

 You are right that this is underdocumented and confusing.  Answers to
 your points:

 1. -device ? lists all device models built into QEMU.  This includes
 NICs but they are not grouped in an easy-to-find way.  Here is an
 example of the output:
 name e1000, bus PCI, desc Intel Gigabit Ethernet

I've seen it. 3 page long list of devices is not practical for every day use.

 A -netdev needs to be paired with a NIC -device.  That's why the
 identifier is essential, it allows you to say -netdev
 type,id=netdev0 -device type,netdev=netdev0.

 It still says The id option can be used with the -device..., where
 can be looks like it should be replaced by must.

 Strictly speaking can be is correct because -device id= is optional.
  You can also do:
 -net user -device virtio-net-pci,vlan=0

 This is basically equivalent to:
 -net user -net nic,model=virtio

-net user  is deprecated, no?

 What's going on here is that -device is used but with the legacy QEMU
 VLAN feature that can be used to connect NICs and backends.

 Things aren't as simple as they should be but I think the problem here
 is really the documentation.  We can try to improve it so that it
 doesn't leave open questions like this, maybe without going into every
 nasty detail.

Yes, it would be nice if documentation was user story oriented, going
gradually from the simplest use stories (tutorials) to more difficult:
1. download stuff from internet from guest (NAT) (OS updates, software
installation)
2. run services on guest accessible from host (web server and stuff)
without specialized configuration (i.e. port forwarding)
3. services on guest accessible from other guests (web development
scenarios - guest servers for db, web, client on host)
..
x. routers, vlans, networks, bridges and other hardcore hardware emulation stuff

 Why is it impossible for -netdev to create NIC device automatically if
 not explicitly set? As a user I don't really know which net device do
 I need. This would greatly simplify user experience (and lower Qemu
 bounce rate).

 There was a similar discussion about -drive for block devices just the
 other day.  I don't think there's a good answer except that QEMU
 command-line has historic baggage and that everyone has a different
 use case so it can be hard to come up with a good simplified
 command-line option set.

Do you maintain a list of use cases? It should be easy to forward
people to it when they face with this problem on not-intuitive
interface. Then outsiders can try to help with prototyping this
interface too. For example, with Python's argparse.



[Qemu-devel] [Bug 1021649] Re: qemu 1.1.0 waits for a keypress at boot

2012-07-26 Thread Michael Tokarev
This is definitely a wrong way to fix this issue.

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

Title:
  qemu 1.1.0 waits for a keypress at boot

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

Bug description:
  qemu 1.1.0 waits for a keypress at boot.  Please don't ever do this.

  Try the attached test script.  When run it will initially print
  nothing, until you hit a key on the keyboard.

  Removing -nographic fixes the problem.

  Using virtio-scsi instead of virtio-blk fixes the problem.

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



[Qemu-devel] Qemu crashed with lsi booting

2012-07-26 Thread Frediano Ziglio
I always get an assert launching this command

sudo ./x86_64-softmmu/qemu-system-x86_64 -m 1024 -hda test.qcow
-device lsi -drive file=/dev/sdb,if=none,id=XXX -device
scsi-block,drive=XXX -enable-kvm -bios ~/seabios/out/bios.bin -serial
file:out.txt
lsi_scsi: error: Multiple IO pending for request 0x7fd1075bf100
qemu-system-x86_64: /home/fredianoz/qemu/hw/lsi53c895a.c:774:
lsi_do_command: Assertion `s-current == ((void *)0)' failed.

(sometimes I don't get the Multiple IO ending line).

I'm using a recent SeaBIOS which support booting from LSI SCSI.

Qemu version

$ git branch -v
* master 61dc008 Revert audio: Make PC speaker audio card available by default

I'm using SeaBIOS commit 9d6bac1d32b72cdf7c0ad009c1371a2e69084de3
(some minor changes in order to support 4k sectors).

Adding some debugging to SeaBIOS lsi code seems that drivers send
initial INQUIRY request but after that all requests have some problems
and lead to a lot of reset command.

Frediano



Re: [Qemu-devel] [RFC PATCH] vfio: VFIO PCI driver for Qemu

2012-07-26 Thread Avi Kivity
On 07/25/2012 10:53 PM, Alex Williamson wrote:
 On Wed, 2012-07-25 at 22:30 +0300, Avi Kivity wrote:
 On 07/25/2012 08:03 PM, Alex Williamson wrote:
  This adds PCI based device assignment to Qemu using the Linux VFIO
  userspace driver interface.  After setting up VFIO device access,
  devices can be added to Qemu guests using the vfio-pci device
  option:
 
   -device vfio-pci,host=1:10.1,id=net0
 
 
 
 Let's use the same syntax as for kvm device assignment.  Then we can
 fall back on kvm when vfio is not available.  We can also have an
 optional parameter kernel-driver to explicitly select vfio or kvm.
 
 This seems confusing to me, pci-assign already has options like
 prefer_msi, share_intx, and configfd that vfio doesn't.  I'm sure vfio
 will eventually get options that pci-assign won't have.  How is a user
 supposed to figure out what options are actually available from -device
 pci-assign,? 

Read the documentation.

 Isn't this the same as asking to drop all model specific
 devices and just use -device net,model=e1000... hey, we've been there
 before ;)  Thanks,

It's not.  e1000 is a guest visible feature. vfio and kvm assignment do
exactly the same thing, as far as the guest is concerned, just using a
different driver.  This is more akin to -device virtio-net,vhost=on|off
(where we also have a default and a fallback, which wouldn't make sense
for model=e1000).

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





[Qemu-devel] [PATCH v4 06/07] s390: sclp ascii console support

2012-07-26 Thread Christian Borntraeger
From: Heinz Graalfs graa...@linux.vnet.ibm.com

This code adds console support  by implementing SCLP's ASCII Console
Data event. This is the same console as LPARs ASCII console or z/VMs
sysascii.

The console can be specified manually with something like
-chardev stdio,id=charconsole0 -device 
sclpconsole,chardev=charconsole0,id=console0

Newer kernels will autodetect that console and prefer that over virtio
console.

When data is received from the character layer it creates a service
interrupt to trigger a Read Event Data command from the guest that will
pick up the received character byte-stream.
When characters are echo'ed by the linux guest a Write Event Data occurs
which is forwarded by the Event Facility to the console that supports
a corresponding mask value.
Console resizing is not supported.
The character layer byte-stream is buffered using a fixed size iov
buffer.

changes in v4: fold in suggestions by blueswirl

Signed-off-by: Heinz Graalfs graa...@linux.vnet.ibm.com
Signed-off-by: Christian Borntraeger borntrae...@de.ibm.com
---
 hw/s390x/Makefile.objs |2 +-
 hw/s390x/sclpconsole.c |  323 
 2 files changed, 324 insertions(+), 1 deletions(-)
 create mode 100644 hw/s390x/sclpconsole.c

diff --git a/hw/s390x/Makefile.objs b/hw/s390x/Makefile.objs
index ed4e61a..096dfcd 100644
--- a/hw/s390x/Makefile.objs
+++ b/hw/s390x/Makefile.objs
@@ -3,4 +3,4 @@ obj-y = s390-virtio-bus.o s390-virtio.o
 obj-y := $(addprefix ../,$(obj-y))
 obj-y += sclp.o
 obj-y += event-facility.o
-obj-y += sclpquiesce.o
+obj-y += sclpquiesce.o sclpconsole.o
diff --git a/hw/s390x/sclpconsole.c b/hw/s390x/sclpconsole.c
new file mode 100644
index 000..c77b2a1
--- /dev/null
+++ b/hw/s390x/sclpconsole.c
@@ -0,0 +1,323 @@
+/*
+ * SCLP event type
+ *Ascii Console Data (VT220 Console)
+ *
+ * Copyright IBM, Corp. 2012
+ *
+ * Authors:
+ *  Heinz Graalfs graa...@de.ibm.com
+ *
+ * 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 hw/qdev.h
+#include qemu-thread.h
+
+#include sclp.h
+#include event-facility.h
+
+typedef struct ASCIIConsoleData {
+EventBufferHeader ebh;
+char data[0];
+} QEMU_PACKED ASCIIConsoleData;
+
+/* max size for ASCII data in 4K SCCB page */
+#define SIZE_BUFFER_VT220 4080
+
+typedef struct SCLPConsole {
+SCLPEvent event;
+CharDriverState *chr;
+/* io vector   */
+uint8_t *iov;   /* iov buffer pointer  */
+uint8_t *iov_sclp;  /* pointer to SCLP read offset */
+uint8_t *iov_bs;/* pointer byte stream read offset */
+uint32_t iov_data_len;  /* length of byte stream in buffer */
+uint32_t iov_sclp_rest; /* length of byte stream not read via SCLP */
+qemu_irq sclp_read_vt220;
+} SCLPConsole;
+
+/* character layer call-back functions */
+
+/* Return number of bytes that fit into iov buffer */
+static int chr_can_read(void *opaque)
+{
+int can_read;
+SCLPConsole *scon = opaque;
+
+qemu_mutex_lock(scon-event.lock);
+can_read = SIZE_BUFFER_VT220 - scon-iov_data_len;
+qemu_mutex_unlock(scon-event.lock);
+
+return can_read;
+}
+
+/* Receive n bytes from character layer, save in iov buffer,
+ * and set event pending */
+static void receive_from_chr_layer(SCLPConsole *scon, const uint8_t *buf,
+   int size)
+{
+assert(scon-iov);
+
+qemu_mutex_lock(scon-event.lock);
+
+/* if new data do not fit into current buffer */
+if (scon-iov_data_len + size  SIZE_BUFFER_VT220) {
+/* character layer sent more than allowed */
+qemu_mutex_unlock(scon-event.lock);
+return;
+}
+/* put byte-stream from character layer into buffer */
+memcpy(scon-iov_bs, buf, size);
+scon-iov_data_len += size;
+scon-iov_sclp_rest += size;
+scon-iov_bs += size;
+scon-event.event_pending = true;
+
+qemu_mutex_unlock(scon-event.lock);
+}
+
+/* Send data from a char device over to the guest */
+static void chr_read(void *opaque, const uint8_t *buf, int size)
+{
+SCLPConsole *scon = opaque;
+
+assert(scon);
+
+receive_from_chr_layer(scon, buf, size);
+/* trigger SCLP read operation */
+qemu_irq_raise(scon-sclp_read_vt220);
+}
+
+static void chr_event(void *opaque, int event)
+{
+SCLPConsole *scon = opaque;
+
+switch (event) {
+case CHR_EVENT_OPENED:
+if (!scon-iov) {
+scon-iov = g_malloc0(SIZE_BUFFER_VT220);
+scon-iov_sclp = scon-iov;
+scon-iov_bs = scon-iov;
+scon-iov_data_len = 0;
+scon-iov_sclp_rest = 0;
+}
+break;
+case CHR_EVENT_CLOSED:
+if (scon-iov) {
+g_free(scon-iov);
+scon-iov = NULL;
+}
+break;
+}
+}
+
+/* functions 

Re: [Qemu-devel] [PATCH] tcm_vhost: Expose ABI version via VHOST_SCSI_GET_ABI_VERSION

2012-07-26 Thread Avi Kivity
On 07/26/2012 05:34 AM, Nicholas A. Bellinger wrote:
 
 In that case, respinning a -v5 for tcm_vhost to start from ABI=0 and
 will post an updated patch shortly.
 
 The main thing I would like to confirm is that this only versions the
 tcm_vhost ioctls?  In that case a single version number works.
 
 
 Correct, the GET_ABI_VERSION call is only intended to identify the
 changing of tcm_vhost ioctls.

Why use version numbers at all?

Feature maps are better, because you can get very fine granularity.


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





Re: [Qemu-devel] [PATCH v5 6/6] block: Enable qemu_open/close to work with fd sets

2012-07-26 Thread Kevin Wolf
Am 26.07.2012 05:57, schrieb Corey Bryant:
 On 07/25/2012 03:43 PM, Eric Blake wrote:
 On 07/23/2012 07:08 AM, Corey Bryant wrote:
 +int monitor_fdset_get_fd(Monitor *mon, int64_t fdset_id, int flags)
 +{
 +mon_fdset_t *mon_fdset;
 +mon_fdset_fd_t *mon_fdset_fd;
 +int mon_fd_flags;
 +
 +if (!mon) {
 +errno = ENOENT;
 +return -1;
 +}
 +
 +QLIST_FOREACH(mon_fdset, mon-fdsets, next) {
 +if (mon_fdset-id != fdset_id) {
 +continue;
 +}
 +QLIST_FOREACH(mon_fdset_fd, mon_fdset-fds, next) {
 +if (mon_fdset_fd-removed) {
 +continue;
 +}
 +
 +mon_fd_flags = fcntl(mon_fdset_fd-fd, F_GETFL);
 +if (mon_fd_flags == -1) {
 +return -1;

 This says we fail on the first fcntl() failure, instead of trying other
 fds in the set.  Granted, an fcntl() failure is probably the sign of a
 bigger bug (such as closing an fd at the wrong point in time), so I
 guess trying to go on doesn't make much sense once we already know we
 are hosed.

 
 I think I'll stick with it the way it is.  If fcntl() fails we might 
 have a tainted fd set so I think we should fail.

The alternative would be s/return 1/continue/, right? I think either way
is acceptable.

 +}
 +
 +switch (flags  O_ACCMODE) {
 +case O_RDWR:
 +if ((mon_fd_flags  O_ACCMODE) == O_RDWR) {
 +return mon_fdset_fd-fd;
 +}
 +break;
 +case O_RDONLY:
 +if ((mon_fd_flags  O_ACCMODE) == O_RDONLY) {
 +return mon_fdset_fd-fd;
 +}
 +break;

 Do we want to allow the case where the caller asked for O_RDONLY, but
 the set only has O_RDWR?  After all, the caller is getting a compatible
 subset of what the set offers.
 
 I don't see a problem with it.

I would require exact matches like you implemented, in order to prevent
damage if we ever had a bug that writes to a read-only file. I believe
it also makes the semantics clearer and the code simpler, while it
shouldn't make much of a difference for clients.

Kevin



[Qemu-devel] [PATCH v4 07/07] s390: make sclp ascii console the default

2012-07-26 Thread Christian Borntraeger
This patch makes the sclp ascii default for S390. It requires a guest
kernel that autodetects the console and which not blindly assumes
that kvm means virtio console.
(commit cd1834591fe9564720ac4b0193bf1c790fe89f0d
KVM: s390: Perform early event mask processing during boot)
Otherwise the guest admin has to explicitely add console=ttyS1 to the
command line.

Signed-off-by: Christian Borntraeger borntrae...@de.ibm.com
---
 hw/s390-virtio.c |1 -
 vl.c |   48 
 2 files changed, 48 insertions(+), 1 deletions(-)

diff --git a/hw/s390-virtio.c b/hw/s390-virtio.c
index 28e320d..8b48f66 100644
--- a/hw/s390-virtio.c
+++ b/hw/s390-virtio.c
@@ -341,7 +341,6 @@ static QEMUMachine s390_machine = {
 .no_serial = 1,
 .no_parallel = 1,
 .no_sdcard = 1,
-.use_virtcon = 1,
 .max_cpus = 255,
 .is_default = 1,
 };
diff --git a/vl.c b/vl.c
index 46248b9..30fd506 100644
--- a/vl.c
+++ b/vl.c
@@ -168,6 +168,7 @@ int main(int argc, char **argv)
 #define DEFAULT_RAM_SIZE 128
 
 #define MAX_VIRTIO_CONSOLES 1
+#define MAX_SCLP_CONSOLES   1
 
 static const char *data_dir;
 const char *bios_name = NULL;
@@ -195,6 +196,7 @@ int no_quit = 0;
 CharDriverState *serial_hds[MAX_SERIAL_PORTS];
 CharDriverState *parallel_hds[MAX_PARALLEL_PORTS];
 CharDriverState *virtcon_hds[MAX_VIRTIO_CONSOLES];
+CharDriverState *sclpcon_hds[MAX_SCLP_CONSOLES];
 int win2k_install_hack = 0;
 int usb_enabled = 0;
 int singlestep = 0;
@@ -268,6 +270,7 @@ static int default_floppy = 1;
 static int default_cdrom = 1;
 static int default_sdcard = 1;
 static int default_vga = 1;
+static int default_sclpcon = 1;
 
 static struct {
 const char *driver;
@@ -289,6 +292,7 @@ static struct {
 { .driver = isa-cirrus-vga,   .flag = default_vga   },
 { .driver = vmware-svga,  .flag = default_vga   },
 { .driver = qxl-vga,  .flag = default_vga   },
+{ .driver = sclpconsole,  .flag = default_sclpcon   },
 };
 
 static void res_free(void)
@@ -1935,6 +1939,7 @@ struct device_config {
 DEV_VIRTCON,   /* -virtioconsole */
 DEV_DEBUGCON,  /* -debugcon */
 DEV_GDB,   /* -gdb, -s */
+DEV_SCLPCON,   /* sclp console */
 } type;
 const char *cmdline;
 Location loc;
@@ -2014,6 +2019,37 @@ static int parallel_parse(const char *devname)
 return 0;
 }
 
+static int sclpcon_parse(const char *devname)
+{
+QemuOptsList *device = qemu_find_opts(device);
+static int index;
+char label[32];
+QemuOpts *dev_opts;
+
+if (strcmp(devname, none) == 0) {
+return 0;
+}
+if (index == MAX_SCLP_CONSOLES) {
+fprintf(stderr, qemu: only one sclpconsole may be specified\n);
+exit(1);
+}
+
+dev_opts = qemu_opts_create(device, NULL, 0, NULL);
+qemu_opt_set(dev_opts, driver, sclpconsole);
+
+snprintf(label, sizeof(label), sclpcon%d, index);
+sclpcon_hds[index] = qemu_chr_new(label, devname, NULL);
+if (!sclpcon_hds[index]) {
+fprintf(stderr, qemu: could not open sclp console '%s': %s\n,
+devname, strerror(errno));
+return -1;
+}
+qemu_opt_set(dev_opts, chardev, label);
+
+index++;
+return 0;
+}
+
 static int virtcon_parse(const char *devname)
 {
 QemuOptsList *device = qemu_find_opts(device);
@@ -3122,6 +3158,7 @@ int main(int argc, char **argv, char **envp)
 default_cdrom = 0;
 default_sdcard = 0;
 default_vga = 0;
+default_sclpcon = 0;
 break;
 case QEMU_OPTION_xen_domid:
 if (!(xen_available())) {
@@ -3303,11 +3340,16 @@ int main(int argc, char **argv, char **envp)
 add_device_config(DEV_PARALLEL, null);
 if (default_serial  default_monitor) {
 add_device_config(DEV_SERIAL, mon:stdio);
+} else if (default_sclpcon  default_monitor) {
+add_device_config(DEV_SCLPCON, mon:stdio);
 } else if (default_virtcon  default_monitor) {
 add_device_config(DEV_VIRTCON, mon:stdio);
 } else {
 if (default_serial)
 add_device_config(DEV_SERIAL, stdio);
+if (default_sclpcon) {
+add_device_config(DEV_SCLPCON, stdio);
+}
 if (default_virtcon)
 add_device_config(DEV_VIRTCON, stdio);
 if (default_monitor)
@@ -3320,6 +3362,9 @@ int main(int argc, char **argv, char **envp)
 add_device_config(DEV_PARALLEL, vc:80Cx24C);
 if (default_monitor)
 monitor_parse(vc:80Cx24C, readline);
+if (default_sclpcon) {
+add_device_config(DEV_SCLPCON, vc:80Cx24C);
+}
 if (default_virtcon)
 add_device_config(DEV_VIRTCON, vc:80Cx24C);
 }
@@ -3490,6 +3535,9 @@ int main(int argc, char **argv, char **envp)
 exit(1);
 if 

[Qemu-devel] [PATCH v4 07/07] s390: make sclp ascii console the default

2012-07-26 Thread Christian Borntraeger
This patch makes the sclp ascii default for S390. It requires a guest
kernel that autodetects the console and which not blindly assumes
that kvm means virtio console.
(commit cd1834591fe9564720ac4b0193bf1c790fe89f0d
KVM: s390: Perform early event mask processing during boot)
Otherwise the guest admin has to explicitely add console=ttyS1 to the
command line.

Signed-off-by: Christian Borntraeger borntrae...@de.ibm.com
---
 hw/s390-virtio.c |1 -
 vl.c |   48 
 2 files changed, 48 insertions(+), 1 deletions(-)

diff --git a/hw/s390-virtio.c b/hw/s390-virtio.c
index 28e320d..8b48f66 100644
--- a/hw/s390-virtio.c
+++ b/hw/s390-virtio.c
@@ -341,7 +341,6 @@ static QEMUMachine s390_machine = {
 .no_serial = 1,
 .no_parallel = 1,
 .no_sdcard = 1,
-.use_virtcon = 1,
 .max_cpus = 255,
 .is_default = 1,
 };
diff --git a/vl.c b/vl.c
index 46248b9..30fd506 100644
--- a/vl.c
+++ b/vl.c
@@ -168,6 +168,7 @@ int main(int argc, char **argv)
 #define DEFAULT_RAM_SIZE 128
 
 #define MAX_VIRTIO_CONSOLES 1
+#define MAX_SCLP_CONSOLES   1
 
 static const char *data_dir;
 const char *bios_name = NULL;
@@ -195,6 +196,7 @@ int no_quit = 0;
 CharDriverState *serial_hds[MAX_SERIAL_PORTS];
 CharDriverState *parallel_hds[MAX_PARALLEL_PORTS];
 CharDriverState *virtcon_hds[MAX_VIRTIO_CONSOLES];
+CharDriverState *sclpcon_hds[MAX_SCLP_CONSOLES];
 int win2k_install_hack = 0;
 int usb_enabled = 0;
 int singlestep = 0;
@@ -268,6 +270,7 @@ static int default_floppy = 1;
 static int default_cdrom = 1;
 static int default_sdcard = 1;
 static int default_vga = 1;
+static int default_sclpcon = 1;
 
 static struct {
 const char *driver;
@@ -289,6 +292,7 @@ static struct {
 { .driver = isa-cirrus-vga,   .flag = default_vga   },
 { .driver = vmware-svga,  .flag = default_vga   },
 { .driver = qxl-vga,  .flag = default_vga   },
+{ .driver = sclpconsole,  .flag = default_sclpcon   },
 };
 
 static void res_free(void)
@@ -1935,6 +1939,7 @@ struct device_config {
 DEV_VIRTCON,   /* -virtioconsole */
 DEV_DEBUGCON,  /* -debugcon */
 DEV_GDB,   /* -gdb, -s */
+DEV_SCLPCON,   /* sclp console */
 } type;
 const char *cmdline;
 Location loc;
@@ -2014,6 +2019,37 @@ static int parallel_parse(const char *devname)
 return 0;
 }
 
+static int sclpcon_parse(const char *devname)
+{
+QemuOptsList *device = qemu_find_opts(device);
+static int index;
+char label[32];
+QemuOpts *dev_opts;
+
+if (strcmp(devname, none) == 0) {
+return 0;
+}
+if (index == MAX_SCLP_CONSOLES) {
+fprintf(stderr, qemu: only one sclpconsole may be specified\n);
+exit(1);
+}
+
+dev_opts = qemu_opts_create(device, NULL, 0, NULL);
+qemu_opt_set(dev_opts, driver, sclpconsole);
+
+snprintf(label, sizeof(label), sclpcon%d, index);
+sclpcon_hds[index] = qemu_chr_new(label, devname, NULL);
+if (!sclpcon_hds[index]) {
+fprintf(stderr, qemu: could not open sclp console '%s': %s\n,
+devname, strerror(errno));
+return -1;
+}
+qemu_opt_set(dev_opts, chardev, label);
+
+index++;
+return 0;
+}
+
 static int virtcon_parse(const char *devname)
 {
 QemuOptsList *device = qemu_find_opts(device);
@@ -3122,6 +3158,7 @@ int main(int argc, char **argv, char **envp)
 default_cdrom = 0;
 default_sdcard = 0;
 default_vga = 0;
+default_sclpcon = 0;
 break;
 case QEMU_OPTION_xen_domid:
 if (!(xen_available())) {
@@ -3303,11 +3340,16 @@ int main(int argc, char **argv, char **envp)
 add_device_config(DEV_PARALLEL, null);
 if (default_serial  default_monitor) {
 add_device_config(DEV_SERIAL, mon:stdio);
+} else if (default_sclpcon  default_monitor) {
+add_device_config(DEV_SCLPCON, mon:stdio);
 } else if (default_virtcon  default_monitor) {
 add_device_config(DEV_VIRTCON, mon:stdio);
 } else {
 if (default_serial)
 add_device_config(DEV_SERIAL, stdio);
+if (default_sclpcon) {
+add_device_config(DEV_SCLPCON, stdio);
+}
 if (default_virtcon)
 add_device_config(DEV_VIRTCON, stdio);
 if (default_monitor)
@@ -3320,6 +3362,9 @@ int main(int argc, char **argv, char **envp)
 add_device_config(DEV_PARALLEL, vc:80Cx24C);
 if (default_monitor)
 monitor_parse(vc:80Cx24C, readline);
+if (default_sclpcon) {
+add_device_config(DEV_SCLPCON, vc:80Cx24C);
+}
 if (default_virtcon)
 add_device_config(DEV_VIRTCON, vc:80Cx24C);
 }
@@ -3490,6 +3535,9 @@ int main(int argc, char **argv, char **envp)
 exit(1);
 if 

Re: [Qemu-devel] [PATCH 04/27] add a version number to ram_list

2012-07-26 Thread Juan Quintela
Michael Roth mdr...@linux.vnet.ibm.com wrote:
 On Tue, Jul 24, 2012 at 08:36:29PM +0200, Juan Quintela wrote:
 From: Umesh Deshpande udesh...@redhat.com
 
 This will be used to detect if last_block might have become invalid
 across different calls to ram_save_live.


 Was it a bug in the old code to not do this? In the unthreaded version
 it looks like last_block could still become invalid between iterations if it
 was removed in the meantime, so I'm trying to understand why it's needed
 now.

Old code assumed that we _never_ do hotplug/unplug of anything during
migration (I am still not convinced that everything works if we plug
some devices, but now at least memory works).

 And why do we re-sort when this happens? The old implementation didn't
 seem to place any guarantees on the block ordering beyond the initial
 sorting by block-idstr. After that they were sent in MRU order.

It is a subtle attempt to try to get the memory in order when we
suspend to disk.  So we could compare two files done while we were
stopped.  And no, I didn't liked when it was introduced.

Later, Juan.



Re: [Qemu-devel] [PATCH 10/27] Separate migration bitmap

2012-07-26 Thread Juan Quintela
Avi Kivity a...@redhat.com wrote:
 On 07/24/2012 09:36 PM, Juan Quintela wrote:
 This patch creates a migration bitmap, which is periodically kept in
 sync with the qemu bitmap. A separate copy of the dirty bitmap for the
 migration limits the amount of concurrent access to the qemu bitmap
 from iothread and migration thread (which requires taking the big
 lock).
 
 We use the qemu bitmap type.  We have to undo the dirty_pages
 counting optimization on the general dirty bitmap and do the counting
 optimization with the migration local bitmap.

 I had different plans for this (and a stale and possibly smelly patchset
 moving in that direction):

 - move the dirty bytemap from a single global instance to
 per-memory-region instances (in the MemoryRegion structure)
 - convert it from a bytemap to either a per-client bitmap (client =
 VGA/CODE/MIGRATION) or a variable bit-length bitfieldmap
 - allocate the bitmaps or strangely named thingie above on demand, so
 ordinarily you have nothing allocated and the framebuffer has a bitmap,
 when you start migration you allocate a bitmap for memory and a
 twobitmap for the framebuffer
 - protect the whole thing using rcu

 The patchset is stalled, mostly because it's very difficult to
 disentangle the tcg stuff.  I don't think we should introduce a
 dependency here, just something to keep in mind.

I tried something like that myself (before your memory regions work).
And got stuck on the same problem:
- for migration, I always had a ramblock handy
- for vga the same (well, I am not sure for the sparc ones, I think they
  were weird on that respect)
- for TCG, there is none around that I can find.  I guess it is there
  somewhere, but not in any obvious part.

So, to fix TCG, we need a TCG guru, and probably change the access
parters somehow :p

Later, Juan.



Re: [Qemu-devel] [Qemu-discuss] qemu-kvm: -netdev user: Parameter 'id' is missing

2012-07-26 Thread Stefan Hajnoczi
On Thu, Jul 26, 2012 at 9:21 AM, anatoly techtonik techto...@gmail.com wrote:
 On Wed, Jul 25, 2012 at 6:00 PM, Stefan Hajnoczi stefa...@gmail.com wrote:
 On Tue, Jul 24, 2012 at 8:02 PM, anatoly techtonik techto...@gmail.com 
 wrote:
 On Tue, Jul 24, 2012 at 1:23 PM, Stefan Hajnoczi stefa...@gmail.com wrote:
 On Mon, Jul 23, 2012 at 10:41 PM, anatoly techtonik techto...@gmail.com 
 wrote:
 A -netdev needs to be paired with a NIC -device.  That's why the
 identifier is essential, it allows you to say -netdev
 type,id=netdev0 -device type,netdev=netdev0.

 It still says The id option can be used with the -device..., where
 can be looks like it should be replaced by must.

 Strictly speaking can be is correct because -device id= is optional.
  You can also do:
 -net user -device virtio-net-pci,vlan=0

 This is basically equivalent to:
 -net user -net nic,model=virtio

 -net user  is deprecated, no?

Yes.  What I'm showing is that you can use -device without a netdev's
id.  So it isn't a must as you asked above.

But I think this detail is not helpful on the Networking wiki page.
The wiki edit I did yesterday removes the issue entirely.

 What's going on here is that -device is used but with the legacy QEMU
 VLAN feature that can be used to connect NICs and backends.

 Things aren't as simple as they should be but I think the problem here
 is really the documentation.  We can try to improve it so that it
 doesn't leave open questions like this, maybe without going into every
 nasty detail.

 Yes, it would be nice if documentation was user story oriented, going
 gradually from the simplest use stories (tutorials) to more difficult:
 1. download stuff from internet from guest (NAT) (OS updates, software
 installation)
 2. run services on guest accessible from host (web server and stuff)
 without specialized configuration (i.e. port forwarding)
 3. services on guest accessible from other guests (web development
 scenarios - guest servers for db, web, client on host)
 ..
 x. routers, vlans, networks, bridges and other hardcore hardware emulation 
 stuff

Absolutely.  Especially a quickstart would be handy.  For many people
it's not necessary to understand how QEMU networking works, they just
want their VM to access the internet.

 Why is it impossible for -netdev to create NIC device automatically if
 not explicitly set? As a user I don't really know which net device do
 I need. This would greatly simplify user experience (and lower Qemu
 bounce rate).

 There was a similar discussion about -drive for block devices just the
 other day.  I don't think there's a good answer except that QEMU
 command-line has historic baggage and that everyone has a different
 use case so it can be hard to come up with a good simplified
 command-line option set.

 Do you maintain a list of use cases? It should be easy to forward
 people to it when they face with this problem on not-intuitive
 interface. Then outsiders can try to help with prototyping this
 interface too. For example, with Python's argparse.

I'm not aware of a list, sorry.

Stefan



Re: [Qemu-devel] How to share disk image between two kvm guests

2012-07-26 Thread Stefan Hajnoczi
On Thu, Jul 26, 2012 at 3:51 AM, Bing Bu Cao m...@linux.vnet.ibm.com wrote:
 Hi,all

 I want to use qemu-nbd to share disk between two kvm guests.

 I.
 # qemu-nbd -p 1024 -e 2 -n my-disk.qcow2
 # nbd-client localhost 1024 /dev/nbd0
 # nbd-client localhost 1024 /dev/nbd1

 II.
 guest1:
 # /usr/local/bin/qemu -enable-kvm -m 1024 -drive file=ubuntu.img -drive
 file=/dev/nbd0,cache=none -net user -net nic,model=virtio -chardev
 stdio,id=mon0 -mon chardev=mon0 -usb -device usb-tablet

 guest2:
 # /usr/local/bin/qemu -enable-kvm -m 1024 -drive file=ubuntu.img -drive
 file=/dev/nbd0,cache=none -net user -net nic,model=virtio -chardev
 stdio,id=mon0 -mon chardev=mon0 -usb -device usb-tablet

 Found one problem:
 No disk r/w sync between 2 virtual hosts.
 One write/change on the shared disk,
 another virtual host must remount the disk and can see the update from the
 other virtual host.

 For example,a simply test:
 In the guest1,mount the disk and create on text file add some line to it.
 In the guest2,mount the same disk and print the text file and found the
 content is not updated.
 But after after I remount the disk, the content will be updated.



 Is it a issue of guest OS or qemu-nbd? Can you help me?

It's a guest OS issue.  If you want to share the same disk between
multiple machines you need to use a cluster file system.  If you are
using something like ext4 which is not a cluster file system then
mounting it from two or more machines simultaneously may corrupt the
file system or at least give an inconsistent view.

Which file system are you using inside the guest?

Stefan



Re: [Qemu-devel] [RFC 00/14]: add printf-like human msg to error_set()

2012-07-26 Thread Kevin Wolf
Am 26.07.2012 04:43, schrieb Anthony Liguori:
 Luiz Capitulino lcapitul...@redhat.com writes:
 
 Basically, this series changes a call like:

  error_set(errp, QERR_DEVICE_NOT_FOUND, device);

 to:

  error_set(errp, QERR_DEVICE_NOT_FOUND,
Device 'device=%s' not found, device);

 In the first call, QERR_DEVICE_NOT_FOUND is a string containing a json dict:

 { 'class': 'DeviceNotFound', 'data': { 'device': %s } }
 
 This is the wrong direction.  Looking through the patch, this makes the
 code much more redundant overall.  You have dozens of calls that are
 duplicating the same error message.  This is not progress.

I believe this is mostly because it's a mechanical conversion. Once this
is done, we can change error messages to better fit the individual cases.

 We should just stick with a simple QERR_GENERIC and call it a day.
 Let's not needlessly complicate existing code.

Why even have error codes when everything should become QERR_GENERIC? Or
am I misunderstanding?

Kevin



[Qemu-devel] [PATCH] configure: Fix xen probe with Xen 4.2 and later.

2012-07-26 Thread Anthony PERARD
The xs.h header is now deprecated and produce a warning. This prevent the
configure script from enabling xen with Xen unstable whom will become 4.2. As
this header is not anymore common to every version of Xen, we just remove it
from the early probe for Xen.

Signed-off-by: Anthony PERARD anthony.per...@citrix.com

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

diff --git a/configure b/configure
index cef0a71..b13adb0 100755
--- a/configure
+++ b/configure
@@ -1381,7 +1381,6 @@ if test $xen != no ; then
   # Xen (any)
   cat  $TMPC EOF
 #include xenctrl.h
-#include xs.h
 int main(void) {
   return 0;
 }
-- 
Anthony PERARD



Re: [Qemu-devel] How to share disk image between two kvm guests

2012-07-26 Thread Bing Bu Cao

On 07/26/2012 05:30 PM, Stefan Hajnoczi wrote:

On Thu, Jul 26, 2012 at 3:51 AM, Bing Bu Caom...@linux.vnet.ibm.com  wrote:

Hi,all

I want to use qemu-nbd to share disk between two kvm guests.

I.
# qemu-nbd -p 1024 -e 2 -n my-disk.qcow2
# nbd-client localhost 1024 /dev/nbd0
# nbd-client localhost 1024 /dev/nbd1

II.
guest1:
# /usr/local/bin/qemu -enable-kvm -m 1024 -drive file=ubuntu.img -drive
file=/dev/nbd0,cache=none -net user -net nic,model=virtio -chardev
stdio,id=mon0 -mon chardev=mon0 -usb -device usb-tablet

guest2:
# /usr/local/bin/qemu -enable-kvm -m 1024 -drive file=ubuntu.img -drive
file=/dev/nbd0,cache=none -net user -net nic,model=virtio -chardev
stdio,id=mon0 -mon chardev=mon0 -usb -device usb-tablet

Found one problem:
No disk r/w sync between 2 virtual hosts.
One write/change on the shared disk,
another virtual host must remount the disk and can see the update from the
other virtual host.

For example,a simply test:
In the guest1,mount the disk and create on text file add some line to it.
In the guest2,mount the same disk and print the text file and found the
content is not updated.
But after after I remount the disk, the content will be updated.



Is it a issue of guest OS or qemu-nbd? Can you help me?


It's a guest OS issue.  If you want to share the same disk between
multiple machines you need to use a cluster file system.  If you are
using something like ext4 which is not a cluster file system then
mounting it from two or more machines simultaneously may corrupt the
file system or at least give an inconsistent view.

Which file system are you using inside the guest?

Now using ext4 as file system inside the both guests.
Got it.
Thank you,Stefan.


Stefan




--
Best Regards,
Bing Bu Cao




Re: [Qemu-devel] [RFC PATCH 0/6] virtio-trace: Support virtio-trace

2012-07-26 Thread Stefan Hajnoczi
On Wed, Jul 25, 2012 at 10:13 AM, Yoshihiro YUNOMAE
yoshihiro.yunomae...@hitachi.com wrote:
 Hi Stefan,


 (2012/07/24 22:41), Stefan Hajnoczi wrote:

 On Tue, Jul 24, 2012 at 12:19 PM, Yoshihiro YUNOMAE
 yoshihiro.yunomae...@hitachi.com wrote:

 Are you using text formatted ftrace?

 No, currently using raw format, but we'd like to reformat it in text.


 Capturing the info necessary to translate numbers into symbols is one
 of the problems of host-guest tracing so I'm curious how you handle
 this :).


 Right, your consideration is true.


 Apologies for my lack of ftrace knowledge but how useful is the raw
 tracing data on the host?  How do you pretty-print it in
 human-readable form?


 perf and trace-cmd can actually translate raw-formatted trace data to
 text-formatted trace data by using information of kernel or trace
 format under tracing/events directory in debugfs. In the same way, if
 the information of a guest is exported to a host, we can translate
 raw trace data of a guest to text trace data on a host. We will use
 9pfs to export that.

Thanks, it's clear now :).

Stefan



[Qemu-devel] [PATCH v2] qemu-iotests: add qed.py image manipulation utility

2012-07-26 Thread Stefan Hajnoczi
The qed.py utility can inspect and manipulate QED image files.  It can
be used for testing to see the state of image metadata and also to
inject corruptions into the image file.  It also has a scrubbing feature
to copy just the metadata out of an image file, allowing users to share
broken image files without revealing data in bug reports.

This has lived in my local repo for a long time but could be useful
to others.  There are two use cases:

 1. qemu-iotests that need to manipulate (e.g. corrupt) QED image files.
 2. Users that want to inspect or recover their QED image files.

Signed-off-by: Stefan Hajnoczi stefa...@linux.vnet.ibm.com
---
Dong Xu Wang wdon...@linux.vnet.ibm.com has contributed generic qemu-img info
support for fragmentation statistics and dirty flag status.  I have dropped
fragmentation statistics from qed.py.  Setting the dirty flag is still
supported in qed.py for testing.

 tests/qemu-iotests/qed.py |  234 +
 1 file changed, 234 insertions(+)
 create mode 100755 tests/qemu-iotests/qed.py

diff --git a/tests/qemu-iotests/qed.py b/tests/qemu-iotests/qed.py
new file mode 100755
index 000..b7e5ea8
--- /dev/null
+++ b/tests/qemu-iotests/qed.py
@@ -0,0 +1,234 @@
+#!/usr/bin/env python
+#
+# Tool to manipulate QED image files
+#
+# Copyright (C) 2010 IBM, Corp.
+#
+# Authors:
+#  Stefan Hajnoczi stefa...@linux.vnet.ibm.com
+#
+# This work is licensed under the terms of the GNU GPL, version 2.  See
+# the COPYING file in the top-level directory.
+
+import sys
+import struct
+import random
+import optparse
+
+# This can be used as a module
+__all__ = ['QED_F_NEED_CHECK', 'QED']
+
+QED_F_NEED_CHECK = 0x02
+
+header_fmt = 'QII'
+header_size = struct.calcsize(header_fmt)
+field_names = ['magic', 'cluster_size', 'table_size',
+   'header_size', 'features', 'compat_features',
+   'autoclear_features', 'l1_table_offset', 'image_size',
+   'backing_filename_offset', 'backing_filename_size']
+table_elem_fmt = 'Q'
+table_elem_size = struct.calcsize(table_elem_fmt)
+
+def err(msg):
+sys.stderr.write(msg + '\n')
+sys.exit(1)
+
+def unpack_header(s):
+fields = struct.unpack(header_fmt, s)
+return dict((field_names[idx], val) for idx, val in enumerate(fields))
+
+def pack_header(header):
+fields = tuple(header[x] for x in field_names)
+return struct.pack(header_fmt, *fields)
+
+def unpack_table_elem(s):
+return struct.unpack(table_elem_fmt, s)[0]
+
+def pack_table_elem(elem):
+return struct.pack(table_elem_fmt, elem)
+
+class QED(object):
+def __init__(self, f):
+self.f = f
+
+self.f.seek(0, 2)
+self.filesize = f.tell()
+
+self.load_header()
+self.load_l1_table()
+
+def raw_pread(self, offset, size):
+self.f.seek(offset)
+return self.f.read(size)
+
+def raw_pwrite(self, offset, data):
+self.f.seek(offset)
+return self.f.write(data)
+
+def load_header(self):
+self.header = unpack_header(self.raw_pread(0, header_size))
+
+def store_header(self):
+self.raw_pwrite(0, pack_header(self.header))
+
+def read_table(self, offset):
+size = self.header['table_size'] * self.header['cluster_size']
+s = self.raw_pread(offset, size)
+table = [unpack_table_elem(s[i:i + table_elem_size]) for i in 
xrange(0, size, table_elem_size)]
+return table
+
+def load_l1_table(self):
+self.l1_table = self.read_table(self.header['l1_table_offset'])
+self.table_nelems = self.header['table_size'] * 
self.header['cluster_size'] / table_elem_size
+
+def write_table(self, offset, table):
+s = ''.join(pack_table_elem(x) for x in table)
+self.raw_pwrite(offset, s)
+
+def random_table_item(table):
+return random.choice([(index, offset) for index, offset in 
enumerate(table) if offset != 0])
+
+def corrupt_table_duplicate(table):
+'''Corrupt a table by introducing a duplicate offset'''
+_, dup_victim = random_table_item(table)
+
+for i in xrange(len(table)):
+dup_target = random.randint(0, len(table) - 1)
+if table[dup_target] != dup_victim:
+table[dup_target] = dup_victim
+return
+raise Exception('no duplication corruption possible in table')
+
+def corrupt_table_invalidate(qed, table):
+'''Corrupt a table by introducing an invalid offset'''
+index, _ = random_table_item(table)
+table[index] = qed.filesize + random.randint(0, 100 * 1024 * 1024 * 1024 * 
1024)
+
+def cmd_show(qed, *args):
+'''show [header|l1|l2 offset]- Show header or l1/l2 tables'''
+if not args or args[0] == 'header':
+print qed.header
+elif args[0] == 'l1':
+print qed.l1_table
+elif len(args) == 2 and args[0] == 'l2':
+offset = int(args[1])
+print qed.read_table(offset)
+else:
+err('unrecognized sub-command')
+
+def cmd_duplicate(qed, 

Re: [Qemu-devel] [RFC 00/27] Migration thread (WIP)

2012-07-26 Thread Jan Kiszka
On 2012-07-24 20:36, Juan Quintela wrote:
 Hi
 
 This series are on top of the migration-next-v5 series just posted.
 
 First of all, this is an RFC/Work in progress.  Just a lot of people
 asked for it, and I would like review of the design.
 
 It does:
 - get a new bitmap for migration, and that bitmap uses 1 bit by page
 - it unfolds migration_buffered_file.  Only one user existed.
 - it simplifies buffered_file a lot.
 
 - About the migration thread, special attention was giving to try to
   get the series review-able (reviewers would tell if I got it).
 
 Basic design:
 - we create a new thread instead of a timer function
 - we move all the migration work to that thread (but run everything
   except the waits with the iothread lock.
 - we move all the writting to outside the iothread lock.  i.e.
   we walk the state with the iothread hold, and copy everything to one buffer.
   then we write that buffer to the sockets outside the iothread lock.
 - once here, we move to writting synchronously to the sockets.
 - this allows us to simplify quite a lot.
 
 And basically, that is it.  Notice that we still do the iterate page
 walking with the iothread held.  Light testing show that we got
 similar speed and latencies than without the thread (notice that
 almost no optimizations done here yet).
 
 Appart of the review:
 - Are there any locking issues that I have missed (I guess so)
 - stop all cpus correctly.  vm_stop should be called from the iothread,
   I use the trick of using a bottom half to get that working correctly.
   but this _implementation_ is ugly as hell.  Is there an easy way
   of doing it?

vm_stop is prepared to be called from vcpu context as well. I'm not sure
right now if we actually do, but the code is there.

Jan

-- 
Siemens AG, Corporate Technology, CT RTC ITP SDP-DE
Corporate Competence Center Embedded Linux




Re: [Qemu-devel] [PATCH 06/11] qerror: QERR_AMBIGUOUS_PATH: drop %(object) from human msg

2012-07-26 Thread Markus Armbruster
Luiz Capitulino lcapitul...@redhat.com writes:

 Actually, renames it to 'object'. This must be what the original author
 meant to write, as there's no 'object' in the error's data member.

 Signed-off-by: Luiz Capitulino lcapitul...@redhat.com
 ---
  qerror.c | 2 +-
  1 file changed, 1 insertion(+), 1 deletion(-)

 diff --git a/qerror.c b/qerror.c
 index 3d8ba2a..01d2493 100644
 --- a/qerror.c
 +++ b/qerror.c
 @@ -49,7 +49,7 @@ static const QErrorStringTable qerror_table[] = {
  },
  {
  .error_fmt = QERR_AMBIGUOUS_PATH,
 -.desc  = Path '%(path)' does not uniquely identify a %(object)
 +.desc  = Path '%(path)' does not uniquely identify a object
  },
  {
  .error_fmt = QERR_BAD_BUS_FOR_DEVICE,

an object, please.



[Qemu-devel] [PATCH V4 0/3] Show backing file depth in HMP

2012-07-26 Thread benoit . canet
From: Benoît Canet ben...@irqsave.net

In some setups many backing files and snapshot are chained.
This lead to the formation of huge trees of snapshots all depending
on a common ancestor.

Hence if something bad happen to this common ancestor all the snapshot
of the tree will be broken.

This patch add an easy way for the user to monitor backing file depth
and take the good decision (streaming).

in v2:

lcapitulino: -Fix typo in qapi-schema.json
 -rename *file_ancestors_count to
  *backing_file_ancestor_count

in v3:

kwolf: qapi-schema.json backing_file_ancestor_count field not optional
   Add a (since 1.2) comment
   keep display in HMP optional

in v4:

eblake: rename backing_file.ancestors.count to backing.file.depth
in qapi-schema.json use - instead of _
Fix json docstring

Benoît Canet (3):
  block: create bdrv_get_backing_file_depth()
  block: Use bdrv_get_backing_file_depth()
  hmp: show the backing file depth

 block.c  |   16 
 block.h  |1 +
 hmp.c|2 ++
 qapi-schema.json |9 ++---
 4 files changed, 25 insertions(+), 3 deletions(-)

-- 
1.7.9.5




[Qemu-devel] [PATCH V4 1/3] block: create bdrv_get_backing_file_depth()

2012-07-26 Thread benoit . canet
From: Benoît Canet ben...@irqsave.net

Create bdrv_get_backing_file_depth() in order to be able to show
in QMP and HMP how many ancestors backing an image a block device
have.

Signed-off-by: Benoit Canet ben...@irqsave.net
---
 block.c |   13 +
 block.h |1 +
 2 files changed, 14 insertions(+)

diff --git a/block.c b/block.c
index ce7eb8f..22ebe49 100644
--- a/block.c
+++ b/block.c
@@ -2754,6 +2754,19 @@ BlockDriverState 
*bdrv_find_backing_image(BlockDriverState *bs,
 return NULL;
 }
 
+int bdrv_get_backing_file_depth(BlockDriverState *bs)
+{
+if (!bs-drv) {
+return 0;
+}
+
+if (!bs-backing_hd) {
+return 0;
+}
+
+return 1 + bdrv_get_backing_file_depth(bs-backing_hd);
+}
+
 #define NB_SUFFIXES 4
 
 char *get_human_readable_size(char *buf, int buf_size, int64_t size)
diff --git a/block.h b/block.h
index c89590d..650d872 100644
--- a/block.h
+++ b/block.h
@@ -174,6 +174,7 @@ int coroutine_fn 
bdrv_co_is_allocated_above(BlockDriverState *top,
 int nb_sectors, int *pnum);
 BlockDriverState *bdrv_find_backing_image(BlockDriverState *bs,
 const char *backing_file);
+int bdrv_get_backing_file_depth(BlockDriverState *bs);
 int bdrv_truncate(BlockDriverState *bs, int64_t offset);
 int64_t bdrv_getlength(BlockDriverState *bs);
 int64_t bdrv_get_allocated_file_size(BlockDriverState *bs);
-- 
1.7.9.5




[Qemu-devel] [PATCH V4 3/3] hmp: show the backing file depth

2012-07-26 Thread benoit . canet
From: Benoît Canet ben...@irqsave.net

Signed-off-by: Benoit Canet ben...@irqsave.net
---
 hmp.c |2 ++
 1 file changed, 2 insertions(+)

diff --git a/hmp.c b/hmp.c
index 6b72a64..25688ab 100644
--- a/hmp.c
+++ b/hmp.c
@@ -227,6 +227,8 @@ void hmp_info_block(Monitor *mon)
 if (info-value-inserted-has_backing_file) {
 monitor_printf(mon,  backing_file=);
 monitor_print_filename(mon, 
info-value-inserted-backing_file);
+monitor_printf(mon,  backing_file_depth=% PRId64,
+info-value-inserted-backing_file_depth);
 }
 monitor_printf(mon,  ro=%d drv=%s encrypted=%d,
info-value-inserted-ro,
-- 
1.7.9.5




[Qemu-devel] [PATCH V4 2/3] block: Use bdrv_get_backing_file_depth()

2012-07-26 Thread benoit . canet
From: Benoît Canet ben...@irqsave.net

Use the dedicated counting function in qmp_query_block in order to
propagate the backing file depth to HMP.

Signed-off-by: Benoit Canet ben...@irqsave.net
---
 block.c  |3 +++
 qapi-schema.json |9 ++---
 2 files changed, 9 insertions(+), 3 deletions(-)

diff --git a/block.c b/block.c
index 22ebe49..a6fba1d 100644
--- a/block.c
+++ b/block.c
@@ -2450,6 +2450,9 @@ BlockInfoList *qmp_query_block(Error **errp)
 info-value-inserted-backing_file = 
g_strdup(bs-backing_file);
 }
 
+info-value-inserted-backing_file_depth =
+bdrv_get_backing_file_depth(bs);
+
 if (bs-io_limits_enabled) {
 info-value-inserted-bps =
bs-io_limits.bps[BLOCK_IO_LIMIT_TOTAL];
diff --git a/qapi-schema.json b/qapi-schema.json
index a92adb1..70a17fb 100644
--- a/qapi-schema.json
+++ b/qapi-schema.json
@@ -398,6 +398,8 @@
 #
 # @backing_file: #optional the name of the backing file (for copy-on-write)
 #
+# @backing-file-depth: the count of ancestor's backing files (since: 1.2)
+#
 # @encrypted: true if the backing device is encrypted
 #
 # @bps: total throughput limit in bytes per second is specified
@@ -418,9 +420,10 @@
 ##
 { 'type': 'BlockDeviceInfo',
   'data': { 'file': 'str', 'ro': 'bool', 'drv': 'str',
-'*backing_file': 'str', 'encrypted': 'bool',
-'bps': 'int', 'bps_rd': 'int', 'bps_wr': 'int',
-'iops': 'int', 'iops_rd': 'int', 'iops_wr': 'int'} }
+'*backing_file': 'str', 'backing-file-depth': 'int',
+'encrypted': 'bool', 'bps': 'int', 'bps_rd': 'int',
+'bps_wr': 'int', 'iops': 'int', 'iops_rd': 'int',
+'iops_wr': 'int'} }
 
 ##
 # @BlockDeviceIoStatus:
-- 
1.7.9.5




Re: [Qemu-devel] [RFC 00/27] Migration thread (WIP)

2012-07-26 Thread Juan Quintela
Jan Kiszka jan.kis...@siemens.com wrote:
 On 2012-07-24 20:36, Juan Quintela wrote:
 Hi

 Appart of the review:
 - Are there any locking issues that I have missed (I guess so)
 - stop all cpus correctly.  vm_stop should be called from the iothread,
   I use the trick of using a bottom half to get that working correctly.
   but this _implementation_ is ugly as hell.  Is there an easy way
   of doing it?

 vm_stop is prepared to be called from vcpu context as well. I'm not sure
 right now if we actually do, but the code is there.

But this is a migation_thread (i.e. neither iothread of vcpu), and we
need to wait for vm_stop to finish.  My reading is that in vcpu context,
we just ask the iothread to stop all cpus.

void vm_stop(RunState state)
{
if (!qemu_thread_is_self(io_thread)) {
qemu_system_vmstop_request(state);
/*
 * FIXME: should not return to device code in case
 * vm_stop() has been requested.
 */
cpu_stop_current();
return;
}
do_vm_stop(state);
}

Or I am reading it wrong?

Later, Juan.



Re: [Qemu-devel] [PATCH 07/11] qapi: qapi.py: allow the ' character be escaped

2012-07-26 Thread Markus Armbruster
Peter Maydell peter.mayd...@linaro.org writes:

 On 25 July 2012 20:18, Luiz Capitulino lcapitul...@redhat.com wrote:
 Peter Maydell peter.mayd...@linaro.org wrote:
 On 25 July 2012 17:54, Luiz Capitulino lcapitul...@redhat.com wrote:
  --- a/scripts/qapi.py
  +++ b/scripts/qapi.py
  @@ -21,7 +21,9 @@ def tokenize(data):
   elif data[0] == ':
   data = data[1:]
   string = ''
  -while data[0] != ':
  +while True:
  +if data[0] == ' and string[len(string)-1] != \\:
  +break
   string += data[0]
   data = data[1:]
   data = data[1:]

 Won't this cause us to look at string[-1] if
 the input data has two ' characters in a row?

 Non escaped? If you meant '' that's a zero length string and should work, but
 if you meant 'foo '' bar' that's illegal, because ' characters
 should be escaped.

 I meant the zero length string case. yes. We come in with data = '',
 strip the first ' and set string to empty. Then in the first time
 in the while loop data[0] is ' but len(string) is 0 and so we'll
 do string[-1] which I think will throw an exception.

 ...and yep, quick test of a nobbbled qapi-schema.json confirms:
 $ python /home/pm215/src/qemu/qemu/scripts/qapi-types.py -h -o . 
 /home/pm215/src/qemu/qemu/qapi-schema.json
 Traceback (most recent call last):
   File /home/pm215/src/qemu/qemu/scripts/qapi-types.py, line 260, in 
 module
 exprs = parse_schema(sys.stdin)
   File /home/pm215/src/qemu/qemu/scripts/qapi.py, line 78, in parse_schema
 expr_eval = evaluate(expr)
   File /home/pm215/src/qemu/qemu/scripts/qapi.py, line 64, in evaluate
 return parse(map(lambda x: x, tokenize(string)))[0]
   File /home/pm215/src/qemu/qemu/scripts/qapi.py, line 25, in tokenize
 if data[0] == ' and string[len(string)-1] != \\:
 IndexError: string index out of range

 Try this (very lightly tested but seems to work):
 (feel free to do something nicer than raising an exception on
 the syntax error, and sorry I'm feeling too lazy to make this
 an actual patch email)

 Signed-off-by: Peter Maydell peter.mayd...@linaro.org

 --- a/scripts/qapi.py
 +++ b/scripts/qapi.py
 @@ -21,10 +21,16 @@ def tokenize(data):
  elif data[0] == ':
  data = data[1:]
  string = ''
 -while data[0] != ':
 -string += data[0]
 -data = data[1:]
 -data = data[1:]
 +while True:
 +pos = data.find(')
 +if pos == -1:
 +raise Exception(Mismatched quotes)
 +string += data[0:pos]
 +data = data[pos+1:]
 +if len(string) == 0 or string[-1] != \\:
 +# found a ' and it wasn't escaped
 +break
 +string = string[0:-1] + '
  yield string

  def parse(tokens):

 (if anybody wants to be able to use '\\' to escape escapes then
 this approach is a bit stuffed, of course.)

For what it's worth, the orthodox way to lexically analyze strings is a
finite automaton.  Utterly untested sketch:

diff --git a/scripts/qapi.py b/scripts/qapi.py
index 8082af3..a745e92 100644
--- a/scripts/qapi.py
+++ b/scripts/qapi.py
@@ -21,8 +21,17 @@ def tokenize(data):
 elif data[0] == ':
 data = data[1:]
 string = ''
-while data[0] != ':
-string += data[0]
+esc = False
+while True:
+if esc:
+string += data[0]
+esc = False
+elif data[0] == \\:
+esc = True
+elif data[0] == ':
+break
+else
+string += data[0]
 data = data[1:]
 data = data[1:]
 yield string

Doesn't handle missing close quote gracefully; you may want to add that.

 PS: Peter, I get claustrophobic when reading emails from you :)

 I can add more blank lines if that helps? :-)

 -- PMM



Re: [Qemu-devel] [PATCH v2] qemu-iotests: add qed.py image manipulation utility

2012-07-26 Thread Kevin Wolf
Am 26.07.2012 09:08, schrieb Stefan Hajnoczi:
 The qed.py utility can inspect and manipulate QED image files.  It can
 be used for testing to see the state of image metadata and also to
 inject corruptions into the image file.  It also has a scrubbing feature
 to copy just the metadata out of an image file, allowing users to share
 broken image files without revealing data in bug reports.
 
 This has lived in my local repo for a long time but could be useful
 to others.  There are two use cases:
 
  1. qemu-iotests that need to manipulate (e.g. corrupt) QED image files.
  2. Users that want to inspect or recover their QED image files.
 
 Signed-off-by: Stefan Hajnoczi stefa...@linux.vnet.ibm.com
 ---
 Dong Xu Wang wdon...@linux.vnet.ibm.com has contributed generic qemu-img 
 info
 support for fragmentation statistics and dirty flag status.  I have dropped
 fragmentation statistics from qed.py.  Setting the dirty flag is still
 supported in qed.py for testing.
 
  tests/qemu-iotests/qed.py |  234 
 +
  1 file changed, 234 insertions(+)
  create mode 100755 tests/qemu-iotests/qed.py

 +def random_table_item(table):
 +return random.choice([(index, offset) for index, offset in 
 enumerate(table) if offset != 0])
 +
 +def corrupt_table_duplicate(table):
 +'''Corrupt a table by introducing a duplicate offset'''
 +_, dup_victim = random_table_item(table)
 +
 +for i in xrange(len(table)):
 +dup_target = random.randint(0, len(table) - 1)
 +if table[dup_target] != dup_victim:
 +table[dup_target] = dup_victim
 +return
 +raise Exception('no duplication corruption possible in table')

At least the message isn't quite correct. If you have a table that is
mostly the same (probably unallocated), and has one allocated entry. In
this situation the chances should be relatively high that the random
number never hits the one different entry.

Not sure how bad this relatively high really is, but I could imagine
that we would see an occasional false positive if a test case used this.

 +def cmd_need_check(qed, *args):
 +'''need-check [on|off] - Test, set, or clear the QED_F_NEED_CHECK header 
 bit'''
 +if not args:
 +print bool(qed.header['features']  QED_F_NEED_CHECK)
 +return
 +
 +if args[0] == 'on':
 +qed.header['features'] |= QED_F_NEED_CHECK
 +elif args[1] == 'off':

args[0]

 +qed.header['features'] = ~QED_F_NEED_CHECK
 +else:
 +err('unrecognized sub-command')
 +qed.store_header()
 +
 +def cmd_zero_cluster(qed, pos, *args):
 +'''zero-cluster pos [n] - Zero data clusters'''
 +pos, n = int(pos), 1
 +if args:
 +if len(args) != 1:
 +err('expected one argument')
 +n = int(args[0])
 +
 +for i in xrange(n):
 +l1_index = pos / qed.header['cluster_size'] / len(qed.l1_table)
 +if qed.l1_table[l1_index] == 0:
 +err('no l2 table allocated')
 +
 +l2_offset = qed.l1_table[l1_index]
 +l2_table = qed.read_table(l2_offset)
 +
 +l2_index = (pos / qed.header['cluster_size']) % len(qed.l1_table)
 +l2_table[l2_index] = 1 # zero the data cluster
 +qed.write_table(l2_offset, l2_table)
 +pos += qed.header['cluster_size']

Isn't it quite slow to write the table after each updated cluster? But
okay, probably works good enough for small test cases.

 +def cmd_copy_metadata(qed, outfile):
 +'''copy-metadata outfile - Copy metadata only (for scrubbing corrupted 
 images)'''
 +out = open(outfile, 'wb')
 +
 +# Match file size
 +out.seek(qed.filesize - 1)
 +out.write('\0')
 +
 +# Copy header clusters
 +out.seek(0)
 +header_size_bytes = qed.header['header_size'] * 
 qed.header['cluster_size']
 +out.write(qed.raw_pread(0, header_size_bytes))
 +
 +# Copy L1 table
 +out.seek(qed.header['l1_table_offset'])
 +s = ''.join(pack_table_elem(x) for x in qed.l1_table)
 +out.write(s)
 +
 +# Copy L2 tables
 +for l2_offset in qed.l1_table:
 +if l2_offset == 0:
 +continue
 +l2_table = qed.read_table(l2_offset)
 +out.seek(l2_offset)
 +s = ''.join(pack_table_elem(x) for x in l2_table)
 +out.write(s)
 +
 +out.close()

Nice feature! :-)

Kevin



Re: [Qemu-devel] [RFC PATCH 0/6] virtio-trace: Support virtio-trace

2012-07-26 Thread Amit Shah
On (Tue) 24 Jul 2012 [11:36:57], Yoshihiro YUNOMAE wrote:
 Hi All,
 
 The following patch set provides a low-overhead system for collecting kernel
 tracing data of guests by a host in a virtualization environment.
 
 A guest OS generally shares some devices with other guests or a host, so
 reasons of any problems occurring in a guest may be from other guests or a 
 host.
 Then, to collect some tracing data of a number of guests and a host is needed
 when some problems occur in a virtualization environment. One of methods to
 realize that is to collect tracing data of guests in a host. To do this, 
 network
 is generally used. However, high load will be taken to applications on guests
 using network I/O because there are many network stack layers. Therefore,
 a communication method for collecting the data without using network is 
 needed.
 
 We submitted a patch set of IVRing, a ring-buffer driver constructed on
 Inter-VM shared memory (IVShmem), to LKML http://lwn.net/Articles/500304/ in
 this June. IVRing and the IVRing reader use POSIX shared memory each other
 without using network, so a low-overhead system for collecting guest tracing
 data is realized. However, this patch set has some problems as follows:
  - use IVShmem instead of virtio
  - create a new ring-buffer without using existing ring-buffer in kernel
  - scalability
-- not support SMP environment
-- buffer size limitation
-- not support live migration (maybe difficult for realize this)
 
 Therefore, we propose a new system virtio-trace, which uses enhanced
 virtio-serial and existing ring-buffer of ftrace, for collecting guest kernel
 tracing data. In this system, there are 5 main components:
  (1) Ring-buffer of ftrace in a guest
  - When trace agent reads ring-buffer, a page is removed from ring-buffer.
  (2) Trace agent in the guest
  - Splice the page of ring-buffer to read_pipe using splice() without
memory copying. Then, the page is spliced from write_pipe to virtio
without memory copying.

I really like the splicing idea.

  (3) Virtio-console driver in the guest
  - Pass the page to virtio-ring
  (4) Virtio-serial bus in QEMU
  - Copy the page to kernel pipe
  (5) Reader in the host
  - Read guest tracing data via FIFO(named pipe) 

So will this be useful only if guest and host run the same kernel?

I'd like to see the host kernel not being used at all -- collect all
relevant info from the guest and send it out to qemu, where it can be
consumed directly by apps driving the tracing.

 ***Evaluation***
 When a host collects tracing data of a guest, the performance of using
 virtio-trace is compared with that of using native(just running ftrace),
 IVRing, and virtio-serial(normal method of read/write).

Why is tracing performance-sensitive?  i.e. why try to optimise this
at all?

 environment
 The overview of this evaluation is as follows:
  (a) A guest on a KVM is prepared.
  - The guest is dedicated one physical CPU as a virtual CPU(VCPU).
 
  (b) The guest starts to write tracing data to ring-buffer of ftrace.
  - The probe points are all trace points of sched, timer, and kmem.
 
  (c) Writing trace data, dhrystone 2 in UNIX bench is executed as a benchmark
  tool in the guest.
  - Dhrystone 2 intends system performance by repeating integer arithmetic
as a score.
  - Since higher score equals to better system performance, if the score
decrease based on bare environment, it indicates that any operation
disturbs the integer arithmetic. Then, we define the overhead of
transporting trace data is calculated as follows:
   OVERHEAD = (1 - SCORE_OF_A_METHOD/NATIVE_SCORE) * 100.
 
 The performance of each method is compared as follows:
  [1] Native
  - only recording trace data to ring-buffer on a guest
  [2] Virtio-trace
  - running a trace agent on a guest
  - a reader on a host opens FIFO using cat command
  [3] IVRing
  - A SystemTap script in a guest records trace data to IVRing.
-- probe points are same as ftrace.
  [4] Virtio-serial(normal)
  - A reader(using cat) on a guest output trace data to a host using
standard output via virtio-serial.
 
 Other information is as follows:
  - host
kernel: 3.3.7-1 (Fedora16)
CPU: Intel Xeon x5660@2.80GHz(12core)
Memory: 48GB
 
  - guest(only booting one guest)
kernel: 3.5.0-rc4+ (Fedora16)
CPU: 1VCPU(dedicated)
Memory: 1GB
 
 result
 3 patterns based on the bare environment were indicated as follows:
  Scores  overhead against [0] Native
 [0] Native:  28807569.5   -
 [1] Virtio-trace:28685049.5 0.43%
 [2] IVRing:  28418595.5 1.35%
 [3] Virtio-serial:   13262258.753.96%
 
 
 ***Just enhancement ideas***
  - Support for trace-cmd
  - Support for 9pfs protocol
  - Support for non-blocking mode in QEMU

There were 

Re: [Qemu-devel] [PATCH 09/11] qapi: add qapi-errors.py

2012-07-26 Thread Markus Armbruster
Paolo, Eric, I got a make puzzle for you below.

Luiz Capitulino lcapitul...@redhat.com writes:

 This script generates two files from qapi-schema-errors.json:

  o qapi-errors.h: contains error macro definitions, eg. QERR_BASE_NOT_FOUND,
   corresponds to most of today's qerror.h

  o qapi-errors.c: contains the error table that currently exists in qerror.c

 Signed-off-by: Luiz Capitulino lcapitul...@redhat.com
 ---
  Makefile   |   8 ++-
  scripts/qapi-errors.py | 177 
 +
  2 files changed, 183 insertions(+), 2 deletions(-)
  create mode 100644 scripts/qapi-errors.py

 diff --git a/Makefile b/Makefile
 index ab82ef3..2cdc732 100644
 --- a/Makefile
 +++ b/Makefile
 @@ -22,8 +22,9 @@ GENERATED_HEADERS = config-host.h trace.h qemu-options.def
  ifeq ($(TRACE_BACKEND),dtrace)
  GENERATED_HEADERS += trace-dtrace.h
  endif
 -GENERATED_HEADERS += qmp-commands.h qapi-types.h qapi-visit.h
 -GENERATED_SOURCES += qmp-marshal.c qapi-types.c qapi-visit.c trace.c
 +GENERATED_HEADERS += qmp-commands.h qapi-types.h qapi-visit.h qapi-errors.h
 +GENERATED_SOURCES += qmp-marshal.c qapi-types.c qapi-visit.c qapi-errors.c \
 + trace.c
  
  # Don't try to regenerate Makefile or configure
  # We don't generate any of them
 @@ -200,6 +201,9 @@ $(SRC_PATH)/qapi-schema.json 
 $(SRC_PATH)/scripts/qapi-visit.py
  qmp-commands.h qmp-marshal.c :\
  $(SRC_PATH)/qapi-schema.json $(SRC_PATH)/scripts/qapi-commands.py
   $(call quiet-command,$(PYTHON) $(SRC_PATH)/scripts/qapi-commands.py 
 $(gen-out-type) -m -o .  $,   GEN   $@)
 +qapi-errors.h qapi-errors.c :\
 +$(SRC_PATH)/qapi-schema-errors.json $(SRC_PATH)/scripts/qapi-errors.py
 + $(call quiet-command,$(PYTHON) $(SRC_PATH)/scripts/qapi-errors.py -o 
 .  $,   GEN   $@)

I'm afraid this isn't quite what you want.  It's shorthand for two
separate rules with the same recipe[*].  Therefore, it's prone to run
the recipe twice, with make blissfully unaware that each of the two runs
clobbers the other file, too.  Could conceivably lead to trouble with
parallel execution.

Paolo, Eric, maybe you can provide advice on how to best tell make that
a recipe generates multiple files.

  QGALIB_OBJ=$(addprefix qapi-generated/, qga-qapi-types.o qga-qapi-visit.o 
 qga-qmp-marshal.o)
  QGALIB_GEN=$(addprefix qapi-generated/, qga-qapi-types.h qga-qapi-visit.h 
 qga-qmp-commands.h)
 diff --git a/scripts/qapi-errors.py b/scripts/qapi-errors.py
 new file mode 100644
 index 000..59cf426
 --- /dev/null
 +++ b/scripts/qapi-errors.py
 @@ -0,0 +1,177 @@
 +#
 +# QAPI errors generator
 +#
 +# Copyright (C) 2012 Red Hat, Inc.
 +#
 +# This work is licensed under the terms of the GNU GPLv2.

Sure you want v2 and not v2+?

 +# See the COPYING.LIB file in the top-level directory.

COPYING.LIB is for LGPL, use COPYING with GPL.

 +from ordereddict import OrderedDict
 +import getopt, sys, os, errno
 +from qapi import *
 +
 +def gen_error_decl_prologue(header, guard, prefix=):
 +ret = mcgen('''
 +/* THIS FILE IS AUTOMATICALLY GENERATED, DO NOT MODIFY */
 +
 +/*
 + * schema-defined QAPI Errors
 + *
 + * Copyright (C) 2012 Red Hat, Inc.
 + *
 + * 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.
 + *
 + */
 +
 +#ifndef %(guard)s
 +#define %(guard)s
 +
 +''',
 + header=basename(header), guard=guardname(header), 
 prefix=prefix)
 +return ret
 +
 +def gen_error_def_prologue(error_header, prefix=):
 +ret = mcgen('''
 +/* THIS FILE IS AUTOMATICALLY GENERATED, DO NOT MODIFY */
 +
 +/*
 + * schema-defined QMP Error table
 + *
 + * Copyright (C) 2012 Red Hat, Inc.
 + *
 + * 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 %(prefix)s%(error_header)s
 +
 +''',
 +prefix=prefix, error_header=error_header)
 +return ret
 +
 +def gen_error_macro(err_domain):
 +string = ''
 +cur = err_domain[0]
 +for nxt in err_domain[1:]:

err_domain is just a fancy name for the error symbol, i.e. what
qerror.h calls 'class', isn't it?

Is it the same as error_class in gen_error_decl_macros() below?

 +if string and cur.isupper() and nxt.islower():
 +string += '_'
 +string += cur
 +cur = nxt
 +string += cur
 +return 'QERR_' + string.upper()
 +
 +def gen_error_def_table(exprs):
 +ret = mcgen('''
 +static const QErrorStringTable qerror_table[] = {
 +''')
 +
 +for err in exprs:
 +macro = gen_error_macro(err['error'])
 +desc = err['description']
 +ret += mcgen('''
 +{
 +.error_fmt = %(error_macro)s,
 +.desc  = %(error_desc)s,
 +},
 +''',
 +error_macro=macro, error_desc=desc)
 +
 +ret += mcgen('''
 +{}
 +};
 +''')
 +
 +return ret
 +
 +def 

Re: [Qemu-devel] [PATCH 09/11] qapi: add qapi-errors.py

2012-07-26 Thread Paolo Bonzini
Il 26/07/2012 13:50, Markus Armbruster ha scritto:
  +qapi-errors.h qapi-errors.c :\
  +$(SRC_PATH)/qapi-schema-errors.json $(SRC_PATH)/scripts/qapi-errors.py
  +  $(call quiet-command,$(PYTHON) $(SRC_PATH)/scripts/qapi-errors.py -o 
  .  $,   GEN   $@)
 I'm afraid this isn't quite what you want.  It's shorthand for two
 separate rules with the same recipe[*].  Therefore, it's prone to run
 the recipe twice, with make blissfully unaware that each of the two runs
 clobbers the other file, too.  Could conceivably lead to trouble with
 parallel execution.
 
 Paolo, Eric, maybe you can provide advice on how to best tell make that
 a recipe generates multiple files.

Hmm, I would just do

qapi-errors.h: qapi-errors.c
qapi-errors.c: $(SRC_PATH)/qapi-schema-errors.json 
$(SRC_PATH)/scripts/qapi-errors.py
$(call quiet-command,$(PYTHON) $(SRC_PATH)/scripts/qapi-errors.py -o 
.  $,   GEN   $@)

I think that's what I usually saw for bison (which creates both .h and .c).

A perhaps cleaner alternative is to add a stamp file, and make both files
depend on it.

Paolo



Re: [Qemu-devel] [PATCH 10/11] qerror: switch to qapi generated error macros and table

2012-07-26 Thread Markus Armbruster
Luiz Capitulino lcapitul...@redhat.com writes:

 Previous commits added qapi infrastructure to automatically generate
 qerror macros and the qerror table from qapi-schema-errors.json.

 This commit drops the current error macros from qerror.h and the error
 table from qerror.c and use the generated ones instead.

 Please, note that qapi-error.c is actually _included_ by qerror.c.
 This is hacky, but the alternative is to make the table private to
 qapi-error.c and generate functions to return table entries. I think that
 doesn't pay much off.

Functions?  Why can't you simply put

const QErrorStringTable qerror_table[NUMBER_OF_ERRORS];

into qapi-errors.h?

With a literal number instead of NUMBER_OF_ERRORS.  If you suffer from
literal-phobia, you can also #define it instead.



Re: [Qemu-devel] [RFC 00/27] Migration thread (WIP)

2012-07-26 Thread Jan Kiszka
On 2012-07-26 13:16, Juan Quintela wrote:
 Jan Kiszka jan.kis...@siemens.com wrote:
 On 2012-07-24 20:36, Juan Quintela wrote:
 Hi
 
 Appart of the review:
 - Are there any locking issues that I have missed (I guess so)
 - stop all cpus correctly.  vm_stop should be called from the iothread,
   I use the trick of using a bottom half to get that working correctly.
   but this _implementation_ is ugly as hell.  Is there an easy way
   of doing it?

 vm_stop is prepared to be called from vcpu context as well. I'm not sure
 right now if we actually do, but the code is there.
 
 But this is a migation_thread (i.e. neither iothread of vcpu), and we
 need to wait for vm_stop to finish.  My reading is that in vcpu context,
 we just ask the iothread to stop all cpus.
 
 void vm_stop(RunState state)
 {
 if (!qemu_thread_is_self(io_thread)) {
 qemu_system_vmstop_request(state);
 /*
  * FIXME: should not return to device code in case
  * vm_stop() has been requested.
  */
 cpu_stop_current();
 return;
 }
 do_vm_stop(state);
 }
 
 Or I am reading it wrong?

Ah, indeed. Did you try top make this service ready for such a use case
(sorry, didn't look at the code yet)? Something like issuing
qemu_system_vmstop_request and then resuming the with the next step on a
vmstate change notification?

Jan

-- 
Siemens AG, Corporate Technology, CT RTC ITP SDP-DE
Corporate Competence Center Embedded Linux





Re: [Qemu-devel] [PATCH 11/11] scripts: update check-qerror.sh

2012-07-26 Thread Markus Armbruster
Luiz Capitulino lcapitul...@redhat.com writes:

 The qerror.h file doesn't contain the macros anymore, the script should
 check qapi-schema-errors.json instead.

 Signed-off-by: Luiz Capitulino lcapitul...@redhat.com
 ---
  scripts/check-qerror.sh | 6 ++
  1 file changed, 2 insertions(+), 4 deletions(-)

 diff --git a/scripts/check-qerror.sh b/scripts/check-qerror.sh
 index af7fbd5..e397b4f 100755
 --- a/scripts/check-qerror.sh
 +++ b/scripts/check-qerror.sh
 @@ -16,7 +16,5 @@ check_order() {
return 0
  }
  
 -check_order 'Definitions in qerror.h must be in alphabetical order:' \
 -grep '^#define QERR_' qerror.h
 -check_order 'Entries in qerror.c:qerror_table must be in alphabetical 
 order:' \
 -sed -n '/^static.*qerror_table\[\]/,/^};/s/QERR_//gp' qerror.c
 +check_order 'Definitions must be in alphabetical order:' \
 +grep '^# @' qapi-schema-errors.json

I'd add the new rule in the commit that adds qapi-schema-errors.json,
and drop the old rules in the commit that deletes the old definitions.



Re: [Qemu-devel] [PATCH v2] qemu-iotests: add qed.py image manipulation utility

2012-07-26 Thread Stefan Hajnoczi
On Thu, Jul 26, 2012 at 01:34:06PM +0200, Kevin Wolf wrote:
 Am 26.07.2012 09:08, schrieb Stefan Hajnoczi:
  The qed.py utility can inspect and manipulate QED image files.  It can
  be used for testing to see the state of image metadata and also to
  inject corruptions into the image file.  It also has a scrubbing feature
  to copy just the metadata out of an image file, allowing users to share
  broken image files without revealing data in bug reports.
  
  This has lived in my local repo for a long time but could be useful
  to others.  There are two use cases:
  
   1. qemu-iotests that need to manipulate (e.g. corrupt) QED image files.
   2. Users that want to inspect or recover their QED image files.
  
  Signed-off-by: Stefan Hajnoczi stefa...@linux.vnet.ibm.com
  ---
  Dong Xu Wang wdon...@linux.vnet.ibm.com has contributed generic qemu-img 
  info
  support for fragmentation statistics and dirty flag status.  I have dropped
  fragmentation statistics from qed.py.  Setting the dirty flag is still
  supported in qed.py for testing.
  
   tests/qemu-iotests/qed.py |  234 
  +
   1 file changed, 234 insertions(+)
   create mode 100755 tests/qemu-iotests/qed.py
 
  +def random_table_item(table):
  +return random.choice([(index, offset) for index, offset in 
  enumerate(table) if offset != 0])
  +
  +def corrupt_table_duplicate(table):
  +'''Corrupt a table by introducing a duplicate offset'''
  +_, dup_victim = random_table_item(table)
  +
  +for i in xrange(len(table)):
  +dup_target = random.randint(0, len(table) - 1)
  +if table[dup_target] != dup_victim:
  +table[dup_target] = dup_victim
  +return
  +raise Exception('no duplication corruption possible in table')
 
 At least the message isn't quite correct. If you have a table that is
 mostly the same (probably unallocated), and has one allocated entry. In
 this situation the chances should be relatively high that the random
 number never hits the one different entry.
 
 Not sure how bad this relatively high really is, but I could imagine
 that we would see an occasional false positive if a test case used this.

The loop is silly, I will replace it with a better solution.

  +def cmd_need_check(qed, *args):
  +'''need-check [on|off] - Test, set, or clear the QED_F_NEED_CHECK 
  header bit'''
  +if not args:
  +print bool(qed.header['features']  QED_F_NEED_CHECK)
  +return
  +
  +if args[0] == 'on':
  +qed.header['features'] |= QED_F_NEED_CHECK
  +elif args[1] == 'off':
 
 args[0]

Good catch

  +qed.header['features'] = ~QED_F_NEED_CHECK
  +else:
  +err('unrecognized sub-command')
  +qed.store_header()
  +
  +def cmd_zero_cluster(qed, pos, *args):
  +'''zero-cluster pos [n] - Zero data clusters'''
  +pos, n = int(pos), 1
  +if args:
  +if len(args) != 1:
  +err('expected one argument')
  +n = int(args[0])
  +
  +for i in xrange(n):
  +l1_index = pos / qed.header['cluster_size'] / len(qed.l1_table)
  +if qed.l1_table[l1_index] == 0:
  +err('no l2 table allocated')
  +
  +l2_offset = qed.l1_table[l1_index]
  +l2_table = qed.read_table(l2_offset)
  +
  +l2_index = (pos / qed.header['cluster_size']) % len(qed.l1_table)
  +l2_table[l2_index] = 1 # zero the data cluster
  +qed.write_table(l2_offset, l2_table)
  +pos += qed.header['cluster_size']
 
 Isn't it quite slow to write the table after each updated cluster? But
 okay, probably works good enough for small test cases.

Yes, it is slow but I never noticed an issue.  I would like to leave
this.




Re: [Qemu-devel] [PATCH 09/11] qapi: add qapi-errors.py

2012-07-26 Thread Markus Armbruster
Luiz Capitulino lcapitul...@redhat.com writes:

 This script generates two files from qapi-schema-errors.json:

  o qapi-errors.h: contains error macro definitions, eg. QERR_BASE_NOT_FOUND,
   corresponds to most of today's qerror.h

  o qapi-errors.c: contains the error table that currently exists in qerror.c
[...]
 diff --git a/scripts/qapi-errors.py b/scripts/qapi-errors.py
 new file mode 100644
 index 000..59cf426
 --- /dev/null
 +++ b/scripts/qapi-errors.py
[...]
 +def gen_error_def_table(exprs):
 +ret = mcgen('''
 +static const QErrorStringTable qerror_table[] = {
 +''')
 +
 +for err in exprs:
 +macro = gen_error_macro(err['error'])
 +desc = err['description']
 +ret += mcgen('''
 +{
 +.error_fmt = %(error_macro)s,
 +.desc  = %(error_desc)s,
 +},
 +''',

Trailing whitespace.

[...]



[Qemu-devel] [PATCH v3] qemu-iotests: add qed.py image manipulation utility

2012-07-26 Thread Stefan Hajnoczi
The qed.py utility can inspect and manipulate QED image files.  It can
be used for testing to see the state of image metadata and also to
inject corruptions into the image file.  It also has a scrubbing feature
to copy just the metadata out of an image file, allowing users to share
broken image files without revealing data in bug reports.

This has lived in my local repo for a long time but could be useful
to others.

Signed-off-by: Stefan Hajnoczi stefa...@linux.vnet.ibm.com
---
v3:
 * Replace random duplicate choice loop with straight-line code [Kevin]
 * Fix args[1] - args[0] typo [Kevin]
 * Fix l2_offset - offset typos

 tests/qemu-iotests/qed.py |  235 +
 1 file changed, 235 insertions(+)
 create mode 100755 tests/qemu-iotests/qed.py

diff --git a/tests/qemu-iotests/qed.py b/tests/qemu-iotests/qed.py
new file mode 100755
index 000..f06c074
--- /dev/null
+++ b/tests/qemu-iotests/qed.py
@@ -0,0 +1,235 @@
+#!/usr/bin/env python
+#
+# Tool to manipulate QED image files
+#
+# Copyright (C) 2010 IBM, Corp.
+#
+# Authors:
+#  Stefan Hajnoczi stefa...@linux.vnet.ibm.com
+#
+# This work is licensed under the terms of the GNU GPL, version 2.  See
+# the COPYING file in the top-level directory.
+
+import sys
+import struct
+import random
+import optparse
+
+# This can be used as a module
+__all__ = ['QED_F_NEED_CHECK', 'QED']
+
+QED_F_NEED_CHECK = 0x02
+
+header_fmt = 'QII'
+header_size = struct.calcsize(header_fmt)
+field_names = ['magic', 'cluster_size', 'table_size',
+   'header_size', 'features', 'compat_features',
+   'autoclear_features', 'l1_table_offset', 'image_size',
+   'backing_filename_offset', 'backing_filename_size']
+table_elem_fmt = 'Q'
+table_elem_size = struct.calcsize(table_elem_fmt)
+
+def err(msg):
+sys.stderr.write(msg + '\n')
+sys.exit(1)
+
+def unpack_header(s):
+fields = struct.unpack(header_fmt, s)
+return dict((field_names[idx], val) for idx, val in enumerate(fields))
+
+def pack_header(header):
+fields = tuple(header[x] for x in field_names)
+return struct.pack(header_fmt, *fields)
+
+def unpack_table_elem(s):
+return struct.unpack(table_elem_fmt, s)[0]
+
+def pack_table_elem(elem):
+return struct.pack(table_elem_fmt, elem)
+
+class QED(object):
+def __init__(self, f):
+self.f = f
+
+self.f.seek(0, 2)
+self.filesize = f.tell()
+
+self.load_header()
+self.load_l1_table()
+
+def raw_pread(self, offset, size):
+self.f.seek(offset)
+return self.f.read(size)
+
+def raw_pwrite(self, offset, data):
+self.f.seek(offset)
+return self.f.write(data)
+
+def load_header(self):
+self.header = unpack_header(self.raw_pread(0, header_size))
+
+def store_header(self):
+self.raw_pwrite(0, pack_header(self.header))
+
+def read_table(self, offset):
+size = self.header['table_size'] * self.header['cluster_size']
+s = self.raw_pread(offset, size)
+table = [unpack_table_elem(s[i:i + table_elem_size]) for i in 
xrange(0, size, table_elem_size)]
+return table
+
+def load_l1_table(self):
+self.l1_table = self.read_table(self.header['l1_table_offset'])
+self.table_nelems = self.header['table_size'] * 
self.header['cluster_size'] / table_elem_size
+
+def write_table(self, offset, table):
+s = ''.join(pack_table_elem(x) for x in table)
+self.raw_pwrite(offset, s)
+
+def random_table_item(table):
+vals = [(index, offset) for index, offset in enumerate(table) if offset != 
0]
+if not vals:
+err('cannot pick random item because table is empty')
+return random.choice(vals)
+
+def corrupt_table_duplicate(table):
+'''Corrupt a table by introducing a duplicate offset'''
+victim_idx, victim_val = random_table_item(table)
+unique_vals = set(table)
+if len(unique_vals) == 1:
+err('no duplication corruption possible in table')
+dup_val = random.choice(list(unique_vals.difference([victim_val])))
+table[victim_idx] = dup_val
+
+def corrupt_table_invalidate(qed, table):
+'''Corrupt a table by introducing an invalid offset'''
+index, _ = random_table_item(table)
+table[index] = qed.filesize + random.randint(0, 100 * 1024 * 1024 * 1024 * 
1024)
+
+def cmd_show(qed, *args):
+'''show [header|l1|l2 offset]- Show header or l1/l2 tables'''
+if not args or args[0] == 'header':
+print qed.header
+elif args[0] == 'l1':
+print qed.l1_table
+elif len(args) == 2 and args[0] == 'l2':
+offset = int(args[1])
+print qed.read_table(offset)
+else:
+err('unrecognized sub-command')
+
+def cmd_duplicate(qed, table_level):
+'''duplicate l1|l2 - Duplicate a random table element'''
+if table_level == 'l1':
+offset = qed.header['l1_table_offset']
+table = qed.l1_table
+elif table_level == 'l2':
+ 

[Qemu-devel] [PATCH RFC v4 18/18] MAINTAINERS: Document virtex_ml507 machine

2012-07-26 Thread Andreas Färber
It's a ppc440, so place it close to Bamboo.

Signed-off-by: Andreas Färber afaer...@suse.de
Cc: Alexander Graf ag...@suse.de
Cc: Edgar E. Iglesias edgar.igles...@gmail.com
---
 MAINTAINERS |6 ++
 1 files changed, 6 insertions(+), 0 deletions(-)

diff --git a/MAINTAINERS b/MAINTAINERS
index 00fb0fa..7a24e4d 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -359,6 +359,12 @@ S: Odd Fixes
 F: hw/ppc440_bamboo.c
 F: hw/ppc4xx_pci.c
 
+virtex_ml507
+M: Edgar E. Iglesias edgar.igles...@gmail.com
+L: qemu-...@nongnu.org
+S: Odd Fixes
+F: hw/virtex_ml507.c
+
 New World
 M: Alexander Graf ag...@suse.de
 L: qemu-...@nongnu.org
-- 
1.7.7




Re: [Qemu-devel] [PATCH V4 2/3] block: Use bdrv_get_backing_file_depth()

2012-07-26 Thread Eric Blake
On 07/26/2012 05:16 AM, benoit.ca...@gmail.com wrote:
 From: Benoît Canet ben...@irqsave.net
 
 Use the dedicated counting function in qmp_query_block in order to
 propagate the backing file depth to HMP.
 
  #
 +# @backing-file-depth: the count of ancestor's backing files (since: 1.2)
 +#

That still reads awkwardly; I had suggested completely ditching the word
'ancestor':

@backing_file_depth: number of files in the backing file chain (since: 1.2)

Also missing a counterpart patch to query-block in qmp-commands.hx to
list the new backing-file-depth field.

-- 
Eric Blake   ebl...@redhat.com+1-919-301-3266
Libvirt virtualization library http://libvirt.org



signature.asc
Description: OpenPGP digital signature


Re: [Qemu-devel] [PATCH v3] qemu-iotests: add qed.py image manipulation utility

2012-07-26 Thread Kevin Wolf
Am 26.07.2012 14:24, schrieb Stefan Hajnoczi:
 The qed.py utility can inspect and manipulate QED image files.  It can
 be used for testing to see the state of image metadata and also to
 inject corruptions into the image file.  It also has a scrubbing feature
 to copy just the metadata out of an image file, allowing users to share
 broken image files without revealing data in bug reports.
 
 This has lived in my local repo for a long time but could be useful
 to others.
 
 Signed-off-by: Stefan Hajnoczi stefa...@linux.vnet.ibm.com

Thanks, applied to the block branch.

Kevin



Re: [Qemu-devel] [PATCH 03/14] qerror: drop qerror_abort()

2012-07-26 Thread Markus Armbruster
Luiz Capitulino lcapitul...@redhat.com writes:

 Previously, developers had to create error dicts manually and also enter
 the matching desc table entry. Thus, qerro_abort() was added to help

s/qerro_/qerror_/

 catching bad error dicts.

 Today, all that stuff is generated automatically which makes the chance
 of a bad generated dict quite low.

The generator can only generate well-formed dicts, right?

 Also, qerror_abort() would... _abort_ on a bad error dict!

In my opinion, it's perfectly fine to abort on a programming error.

 This commit maintains the same verification logic on the error object
 but drops the abort() in favor of reporting UndefinedError for bad dicts
 (and also print a debug message to stderr).

I certainly won't object to your elaborate handling, but me, I'd simply
replace qerror_abort() by straight abort() and be done with it *shrug*

 Signed-off-by: Luiz Capitulino lcapitul...@redhat.com
 ---
  qerror.c | 83 
 +++-
  1 file changed, 46 insertions(+), 37 deletions(-)

 diff --git a/qerror.c b/qerror.c
 index d428b52..74b3659 100644
 --- a/qerror.c
 +++ b/qerror.c
 @@ -38,55 +38,50 @@ static QError *qerror_new(void)
  return qerr;
  }
  
 -static void GCC_FMT_ATTR(2, 3) qerror_abort(const QError *qerr,
 -const char *fmt, ...)
 -{
 -va_list ap;
 -
 -fprintf(stderr, qerror: bad call in function '%s':\n, qerr-func);
 -fprintf(stderr, qerror: - );
 -
 -va_start(ap, fmt);
 -vfprintf(stderr, fmt, ap);
 -va_end(ap);
 -
 -fprintf(stderr, \nqerror: call at %s:%d\n, qerr-file, qerr-linenr);
 -abort();
 -}
 -
 -static void GCC_FMT_ATTR(2, 0) qerror_set_data(QError *qerr,
 -   const char *fmt, va_list *va)
 +static QDict *error_object_from_fmt(const char *fmt, va_list *va)
  {
  QObject *obj;
 +QDict *ret;
  
  obj = qobject_from_jsonv(fmt, va);
  if (!obj) {
 -qerror_abort(qerr, invalid format '%s', fmt);
 +fprintf(stderr, invalid json in error dict '%s'\n, fmt);
 +return NULL;
  }
  if (qobject_type(obj) != QTYPE_QDICT) {
 -qerror_abort(qerr, error format is not a QDict '%s', fmt);
 +fprintf(stderr, error is not a dict '%s'\n, fmt);
 +goto out_free;
  }
  
 -qerr-error = qobject_to_qdict(obj);
 -
 -obj = qdict_get(qerr-error, class);
 +ret = qobject_to_qdict(obj);
 +obj = qdict_get(ret, class);
  if (!obj) {
 -qerror_abort(qerr, missing 'class' key in '%s', fmt);
 +fprintf(stderr, missing 'class' key in '%s'\n, fmt);
 +goto out_free;
  }
  if (qobject_type(obj) != QTYPE_QSTRING) {
 -qerror_abort(qerr, 'class' key value should be a QString);
 +fprintf(stderr, 'class' key value should be a string in '%s'\n, 
 fmt);
 +goto out_free;
  }
 -
 -obj = qdict_get(qerr-error, data);
 +
 +obj = qdict_get(ret, data);
  if (!obj) {
 -qerror_abort(qerr, missing 'data' key in '%s', fmt);
 +fprintf(stderr, missing 'data' key in '%s'\n, fmt);
 +goto out_free;
  }
  if (qobject_type(obj) != QTYPE_QDICT) {
 -qerror_abort(qerr, 'data' key value should be a QDICT);
 +fprintf(stderr, 'data' key value should be a dict in '%s'\n, fmt);
 +goto out_free;
  }
 +
 +return ret;
 +
 +out_free:
 +qobject_decref(obj);
 +return NULL;
  }
  
 -static void qerror_set_desc(QError *qerr, const char *fmt)
 +static const QErrorStringTable *error_get_desc(const char *fmt)
  {
  int i;
  
 @@ -94,12 +89,17 @@ static void qerror_set_desc(QError *qerr, const char *fmt)
  
  for (i = 0; qerror_table[i].error_fmt; i++) {
  if (strcmp(qerror_table[i].error_fmt, fmt) == 0) {
 -qerr-entry = qerror_table[i];
 -return;
 +return qerror_table[i];
  }
  }
  
 -qerror_abort(qerr, error format '%s' not found, fmt);
 +fprintf(stderr, error format '%s' not found\n, fmt);
 +return NULL;
 +}
 +
 +static QDict *build_error_no_arg(const char *fmt)
 +{
 +return qobject_to_qdict(qobject_from_jsonv(fmt, NULL));
  }
  
  /**
 @@ -127,13 +127,22 @@ static QError *qerror_from_info(const char *file, int 
 linenr, const char *func,
  qerr-file = file;
  qerr-func = func;
  
 -if (!fmt) {
 -qerror_abort(qerr, QDict not specified);
 +qerr-error = error_object_from_fmt(fmt, va);
 +if (!qerr-error) {
 +goto bad_err;
 +}
 +
 +qerr-entry = error_get_desc(fmt);
 +if (!qerr-entry) {
 +QDECREF(qerr-error);
 +goto bad_err;
  }
  
 -qerror_set_data(qerr, fmt, va);
 -qerror_set_desc(qerr, fmt);
 +return qerr;
  
 +bad_err:
 +qerr-error = build_error_no_arg(QERR_UNDEFINED_ERROR);

Nit: defeats gcc's format checking.  This shouldn't:

   qerr-error = 

Re: [Qemu-devel] [PATCH v2] qemu-iotests: add qed.py image manipulation utility

2012-07-26 Thread Eric Blake
On 07/26/2012 01:08 AM, Stefan Hajnoczi wrote:
 The qed.py utility can inspect and manipulate QED image files.  It can
 be used for testing to see the state of image metadata and also to
 inject corruptions into the image file.  It also has a scrubbing feature
 to copy just the metadata out of an image file, allowing users to share
 broken image files without revealing data in bug reports.
 
 This has lived in my local repo for a long time but could be useful
 to others.  There are two use cases:
 
  1. qemu-iotests that need to manipulate (e.g. corrupt) QED image files.
  2. Users that want to inspect or recover their QED image files.
 
 Signed-off-by: Stefan Hajnoczi stefa...@linux.vnet.ibm.com
 +#
 +# This work is licensed under the terms of the GNU GPL, version 2.  See

or later?

-- 
Eric Blake   ebl...@redhat.com+1-919-301-3266
Libvirt virtualization library http://libvirt.org



signature.asc
Description: OpenPGP digital signature


Re: [Qemu-devel] [PATCH 04/14] qerror: drop qerror_report_internal()

2012-07-26 Thread Markus Armbruster
Luiz Capitulino lcapitul...@redhat.com writes:

 It's not needed anymore and conflicts with future error improvements.

 Also drops related error information, that is, the file where the error
 ocurred, the line number and function. This has never been fully used.

Suggest Subject: qerror: drop file, linenr, func, because that's the
interesting part.  qerror_report_internal() is merely detail.



Re: [Qemu-devel] [PATCH 09/11] qapi: add qapi-errors.py

2012-07-26 Thread Eric Blake
On 07/26/2012 05:55 AM, Paolo Bonzini wrote:
 Il 26/07/2012 13:50, Markus Armbruster ha scritto:
 +qapi-errors.h qapi-errors.c :\
 +$(SRC_PATH)/qapi-schema-errors.json $(SRC_PATH)/scripts/qapi-errors.py
 +  $(call quiet-command,$(PYTHON) $(SRC_PATH)/scripts/qapi-errors.py -o 
 .  $,   GEN   $@)
 I'm afraid this isn't quite what you want.  It's shorthand for two
 separate rules with the same recipe[*].  Therefore, it's prone to run
 the recipe twice, with make blissfully unaware that each of the two runs
 clobbers the other file, too.  Could conceivably lead to trouble with
 parallel execution.

 Paolo, Eric, maybe you can provide advice on how to best tell make that
 a recipe generates multiple files.
 
 Hmm, I would just do
 
 qapi-errors.h: qapi-errors.c
 qapi-errors.c: $(SRC_PATH)/qapi-schema-errors.json 
 $(SRC_PATH)/scripts/qapi-errors.py
   $(call quiet-command,$(PYTHON) $(SRC_PATH)/scripts/qapi-errors.py -o 
 .  $,   GEN   $@)
 
 I think that's what I usually saw for bison (which creates both .h and .c).

Indeed, per
https://www.gnu.org/software/automake/manual/automake.html#Multiple-Outputs,
that is an appropriate solution for a 2-file generation.  It is only
when you have more than two files where...

 
 A perhaps cleaner alternative is to add a stamp file, and make both files
 depend on it.

a stamp file makes more sense.

-- 
Eric Blake   ebl...@redhat.com+1-919-301-3266
Libvirt virtualization library http://libvirt.org



signature.asc
Description: OpenPGP digital signature


[Qemu-devel] [PATCH v4 13/18] pci: Derive PCI host bridges from TYPE_PCI_HOST_BRIDGE

2012-07-26 Thread Andreas Färber
Some typedef'ed their state to PCIHostState. Use a proper struct,
and use PCIHostState and PCI_HOST_BRIDGE() where appropriate.

Signed-off-by: Andreas Färber afaer...@suse.de
---
 hw/alpha_typhoon.c |2 +-
 hw/bonito.c|   22 +++---
 hw/dec_pci.c   |4 ++--
 hw/grackle_pci.c   |6 +++---
 hw/gt64xxx.c   |4 ++--
 hw/piix_pci.c  |8 
 hw/ppc4xx_pci.c|4 ++--
 hw/ppc_prep.c  |4 +---
 hw/ppce500_pci.c   |4 ++--
 hw/prep_pci.c  |4 ++--
 hw/spapr_pci.c |2 +-
 hw/unin_pci.c  |   20 ++--
 12 files changed, 41 insertions(+), 43 deletions(-)

diff --git a/hw/alpha_typhoon.c b/hw/alpha_typhoon.c
index 06e84a1..58025a3 100644
--- a/hw/alpha_typhoon.c
+++ b/hw/alpha_typhoon.c
@@ -823,7 +823,7 @@ static void typhoon_pcihost_class_init(ObjectClass *klass, 
void *data)
 
 static const TypeInfo typhoon_pcihost_info = {
 .name  = TYPE_TYPHOON_PCI_HOST_BRIDGE,
-.parent= TYPE_SYS_BUS_DEVICE,
+.parent= TYPE_PCI_HOST_BRIDGE,
 .instance_size = sizeof(TyphoonState),
 .class_init= typhoon_pcihost_class_init,
 };
diff --git a/hw/bonito.c b/hw/bonito.c
index 062c701..6084ac4 100644
--- a/hw/bonito.c
+++ b/hw/bonito.c
@@ -416,7 +416,7 @@ static const MemoryRegionOps bonito_cop_ops = {
 static uint32_t bonito_sbridge_pciaddr(void *opaque, target_phys_addr_t addr)
 {
 PCIBonitoState *s = opaque;
-PCIHostState *phb = FROM_SYSBUS(PCIHostState, SYS_BUS_DEVICE(s-pcihost));
+PCIHostState *phb = PCI_HOST_BRIDGE(s-pcihost);
 uint32_t cfgaddr;
 uint32_t idsel;
 uint32_t devno;
@@ -454,7 +454,7 @@ static void bonito_spciconf_writeb(void *opaque, 
target_phys_addr_t addr,
 {
 PCIBonitoState *s = opaque;
 PCIDevice *d = PCI_DEVICE(s);
-PCIHostState *phb = FROM_SYSBUS(PCIHostState, SYS_BUS_DEVICE(s-pcihost));
+PCIHostState *phb = PCI_HOST_BRIDGE(s-pcihost);
 uint32_t pciaddr;
 uint16_t status;
 
@@ -480,7 +480,7 @@ static void bonito_spciconf_writew(void *opaque, 
target_phys_addr_t addr,
 {
 PCIBonitoState *s = opaque;
 PCIDevice *d = PCI_DEVICE(s);
-PCIHostState *phb = FROM_SYSBUS(PCIHostState, SYS_BUS_DEVICE(s-pcihost));
+PCIHostState *phb = PCI_HOST_BRIDGE(s-pcihost);
 uint32_t pciaddr;
 uint16_t status;
 
@@ -508,7 +508,7 @@ static void bonito_spciconf_writel(void *opaque, 
target_phys_addr_t addr,
 {
 PCIBonitoState *s = opaque;
 PCIDevice *d = PCI_DEVICE(s);
-PCIHostState *phb = FROM_SYSBUS(PCIHostState, SYS_BUS_DEVICE(s-pcihost));
+PCIHostState *phb = PCI_HOST_BRIDGE(s-pcihost);
 uint32_t pciaddr;
 uint16_t status;
 
@@ -535,7 +535,7 @@ static uint32_t bonito_spciconf_readb(void *opaque, 
target_phys_addr_t addr)
 {
 PCIBonitoState *s = opaque;
 PCIDevice *d = PCI_DEVICE(s);
-PCIHostState *phb = FROM_SYSBUS(PCIHostState, SYS_BUS_DEVICE(s-pcihost));
+PCIHostState *phb = PCI_HOST_BRIDGE(s-pcihost);
 uint32_t pciaddr;
 uint16_t status;
 
@@ -561,7 +561,7 @@ static uint32_t bonito_spciconf_readw(void *opaque, 
target_phys_addr_t addr)
 {
 PCIBonitoState *s = opaque;
 PCIDevice *d = PCI_DEVICE(s);
-PCIHostState *phb = FROM_SYSBUS(PCIHostState, SYS_BUS_DEVICE(s-pcihost));
+PCIHostState *phb = PCI_HOST_BRIDGE(s-pcihost);
 uint32_t pciaddr;
 uint16_t status;
 
@@ -589,7 +589,7 @@ static uint32_t bonito_spciconf_readl(void *opaque, 
target_phys_addr_t addr)
 {
 PCIBonitoState *s = opaque;
 PCIDevice *d = PCI_DEVICE(s);
-PCIHostState *phb = FROM_SYSBUS(PCIHostState, SYS_BUS_DEVICE(s-pcihost));
+PCIHostState *phb = PCI_HOST_BRIDGE(s-pcihost);
 uint32_t pciaddr;
 uint16_t status;
 
@@ -702,7 +702,7 @@ static const VMStateDescription vmstate_bonito = {
 
 static int bonito_pcihost_initfn(SysBusDevice *dev)
 {
-PCIHostState *phb = FROM_SYSBUS(PCIHostState, dev);
+PCIHostState *phb = PCI_HOST_BRIDGE(dev);
 
 phb-bus = pci_register_bus(DEVICE(dev), pci,
 pci_bonito_set_irq, pci_bonito_map_irq, dev,
@@ -716,7 +716,7 @@ static int bonito_initfn(PCIDevice *dev)
 {
 PCIBonitoState *s = DO_UPCAST(PCIBonitoState, dev, dev);
 SysBusDevice *sysbus = SYS_BUS_DEVICE(s-pcihost);
-PCIHostState *phb = FROM_SYSBUS(PCIHostState, sysbus);
+PCIHostState *phb = PCI_HOST_BRIDGE(s-pcihost);
 
 /* Bonito North Bridge, built on FPGA, VENDOR_ID/DEVICE_ID are undefined 
*/
 pci_config_set_prog_interface(dev-config, 0x00);
@@ -785,7 +785,7 @@ PCIBus *bonito_init(qemu_irq *pic)
 PCIDevice *d;
 
 dev = qdev_create(NULL, TYPE_BONITO_PCI_HOST_BRIDGE);
-phb = FROM_SYSBUS(PCIHostState, sysbus_from_qdev(dev));
+phb = PCI_HOST_BRIDGE(dev);
 pcihost = BONITO_PCI_HOST_BRIDGE(dev);
 pcihost-pic = pic;
 qdev_init_nofail(dev);
@@ -833,7 +833,7 @@ static void bonito_pcihost_class_init(ObjectClass *klass, 
void *data)
 
 static const TypeInfo bonito_pcihost_info = {
 

Re: [Qemu-devel] [PATCH RFC v4 15/18] MAINTAINERS: Document sPAPR (pSeries) machine

2012-07-26 Thread David Gibson
On Thu, Jul 26, 2012 at 02:28:33PM +0200, Andreas Färber wrote:
 Signed-off-by: Andreas Färber afaer...@suse.de
 Cc: Alexander Graf ag...@suse.de
 Cc: Benjamin Herrenschmidt b...@kernel.crashing.org
 Cc: David Gibson da...@gibson.dropbear.id.au

Acked-by: David Gibson da...@gibson.dropbear.id.au

-- 
David Gibson| I'll have my music baroque, and my code
david AT gibson.dropbear.id.au  | minimalist, thank you.  NOT _the_ _other_
| _way_ _around_!
http://www.ozlabs.org/~dgibson




Re: [Qemu-devel] [PATCH v4 10/18] spapr_pci: QOM'ify sPAPR PCI host bridge

2012-07-26 Thread David Gibson
On Thu, Jul 26, 2012 at 02:28:28PM +0200, Andreas Färber wrote:
 Introduce type constant. Introduce cast macro to drop bogus busdev field
 that would've broken SYS_BUS_DEVICE().

I believe there's already a patch making its way through agraf's tree
that removes the bogus extra busdev.

-- 
David Gibson| I'll have my music baroque, and my code
david AT gibson.dropbear.id.au  | minimalist, thank you.  NOT _the_ _other_
| _way_ _around_!
http://www.ozlabs.org/~dgibson




Re: [Qemu-devel] [RFC 00/14]: add printf-like human msg to error_set()

2012-07-26 Thread Anthony Liguori
Kevin Wolf kw...@redhat.com writes:

 Am 26.07.2012 04:43, schrieb Anthony Liguori:
 Luiz Capitulino lcapitul...@redhat.com writes:
 
 Basically, this series changes a call like:

  error_set(errp, QERR_DEVICE_NOT_FOUND, device);

 to:

  error_set(errp, QERR_DEVICE_NOT_FOUND,
Device 'device=%s' not found, device);

 In the first call, QERR_DEVICE_NOT_FOUND is a string containing a json dict:

 { 'class': 'DeviceNotFound', 'data': { 'device': %s } }
 
 This is the wrong direction.  Looking through the patch, this makes the
 code much more redundant overall.  You have dozens of calls that are
 duplicating the same error message.  This is not progress.

 I believe this is mostly because it's a mechanical conversion. Once this
 is done, we can change error messages to better fit the individual
 cases.

We don't gain anything by touching every user of error and the code gets
more verbose.  If we want to modify an existing error for some good
reason, we can do so my changing error types.

 We should just stick with a simple QERR_GENERIC and call it a day.
 Let's not needlessly complicate existing code.

 Why even have error codes when everything should become QERR_GENERIC? Or
 am I misunderstanding?

If we want to add an error code, we can do:

   error_set(QERR_GENERIC, domain, My free form text)

And then yes, we can change this to:

   error_setf(errp, domain, My free form text)

Or pick your favorite short name.

Regards,

Anthony Liguori


 Kevin




Re: [Qemu-devel] [PATCH 09/11] qapi: add qapi-errors.py

2012-07-26 Thread Eric Blake
On 07/26/2012 06:38 AM, Eric Blake wrote:
 Paolo, Eric, maybe you can provide advice on how to best tell make that
 a recipe generates multiple files.

 Hmm, I would just do

 qapi-errors.h: qapi-errors.c
 qapi-errors.c: $(SRC_PATH)/qapi-schema-errors.json 
 $(SRC_PATH)/scripts/qapi-errors.py
  $(call quiet-command,$(PYTHON) $(SRC_PATH)/scripts/qapi-errors.py -o 
 .  $,   GEN   $@)

 I think that's what I usually saw for bison (which creates both .h and .c).
 
 Indeed, per
 https://www.gnu.org/software/automake/manual/automake.html#Multiple-Outputs,
 that is an appropriate solution for a 2-file generation.

Or, since we depend on GNU make, we can use pattern rules instead
(untested):

%-errors.h %-errors.c: \
   %(SRC_PATH)/%-schema-errors.json $(SRC_PATH)/srcipts/%-errors.py
$(call quiet-command,$(PYTHON) $(SRC_PATH)/scripts/qapi-errors.py -o
.  $,   GEN   $@)

https://www.gnu.org/software/automake/manual/make.html#Pattern-Examples

-- 
Eric Blake   ebl...@redhat.com+1-919-301-3266
Libvirt virtualization library http://libvirt.org



signature.asc
Description: OpenPGP digital signature


[Qemu-devel] [PATCH for-ppc-next 0/2] target-ppc: e500 MAINTAINERS update

2012-07-26 Thread Andreas Färber
Hi Alex,

As discussed, here's a patchset on top of my master-based pci_host series
that updates the proposed MAINTAINERS entries to match Scott's pending changes.

This should go through ppc-next if the other series gets applied to master.
Otherwise the second patch can be squashed into the original patch.

Regards,
Andreas

Cc: Alexander Graf ag...@suse.de
Cc: Scott Wood scottw...@freescale.com

Andreas Färber (2):
  MAINTAINERS: Downgrade ppc405 to Odd Fixes
  MAINTAINERS: Update e500 machine

 MAINTAINERS |4 +++-
 1 files changed, 3 insertions(+), 1 deletions(-)

-- 
1.7.7




[Qemu-devel] [PATCH for-ppc-next 2/2] MAINTAINERS: Update e500 machine

2012-07-26 Thread Andreas Färber
Files were relocated and a new generic machine extracted.
hw/ppce500_* pattern is still needed for the PCI host bridge.

Signed-off-by: Andreas Färber afaer...@suse.de
Cc: Scott Wood scottw...@freescale.com
---
 MAINTAINERS |2 ++
 1 files changed, 2 insertions(+), 0 deletions(-)

diff --git a/MAINTAINERS b/MAINTAINERS
index 7b26818..285627d 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -400,6 +400,8 @@ M: Scott Wood scottw...@freescale.com
 L: qemu-...@nongnu.org
 S: Supported
 F: hw/ppce500_*
+F: hw/ppc/e500*
+F: hw/ppc/mpc8544ds.c
 
 SH4 Machines
 
-- 
1.7.7




[Qemu-devel] [PATCH for-ppc-next 1/2] MAINTAINERS: Downgrade ppc405 to Odd Fixes

2012-07-26 Thread Andreas Färber
As requested by Alex.

Signed-off-by: Andreas Färber afaer...@suse.de
---
 MAINTAINERS |2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)

diff --git a/MAINTAINERS b/MAINTAINERS
index 7a24e4d..7b26818 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -349,7 +349,7 @@ PowerPC Machines
 405
 M: Alexander Graf ag...@suse.de
 L: qemu-...@nongnu.org
-S: Maintained
+S: Odd Fixes
 F: hw/ppc405_boards.c
 
 Bamboo
-- 
1.7.7




Re: [Qemu-devel] [PATCH] vl: add -libvirt-caps option for libvirt to stop parsing help output

2012-07-26 Thread Daniel P. Berrange
On Wed, Jul 25, 2012 at 02:47:57PM -0500, Anthony Liguori wrote:
 The help output is going to change dramatically for 0.13.  We've spent too 
 long
 waiting for a perfect solution to capabilities handling and the end loser is
 the direct consumer of QEMU because the help output is awful.
 
 I will not apply any patches that change help output until 0.13 development
 opens up.  This should give libvirt adequate time to implement support for
 dealing with this new option.

I completely agree with this. We have spent far too long making do with
help output and its about time we finish with this once  for all.
I'm assuming you mean the 1.3 release here. If so I'll agree that it
is an acceptable plan to change help output at the start of the 1.3
release.

This gives us enough time to agree on what todo to support apps needing
to query QEMU.

 This capabilities set comes directly from libvirt's source code so it's 
 entirely
 adequate for libvirt's purposes.  We can still explore more sophisticated
 approaches that are more general purpose but the help output will be changing.

While I appreciate what you're trying todo here, I think this would be a
serious mistake on many counts, and even be incorrect in some ways.

 - It ignores the needs of other apps using QEMU. In particular Richard
   Jones has frequently requested a way to detect QEMU capabilities
   to satisfy libguestfs. I think it is unreasonable to expect libguestfs
   to use the libvirt capabilities described here. Likewise other apps

 - This is just a point in time snapshot of what libvirt currently uses
   from QEMU. If, for example, someone provided a patch to libvirt to
   support the bluetooth devices we'd be stuck, because although QEMU
   already supports bluetooth, this is not expressed in any of the
   caps libvirt already has.

 - Not all of this information actually comes from the help output.
   A bunch of it is stuff we detect from '-device ?' and
   '-device name,?'. Although, (AFAIR) no one has objections to use
   parsing the -device output because it is much better defined 
   stable than -help, I think we could use some improvement to make
   the parsing 100% long term maintainable by QEMU/apps. Similarly
   we do  '-cpu ?' and '-machine ?'.  Some of the caps are set based
   on the machine architecture, or QEMU version.

 - Some of the caps are set based on what libvirt is actually
   able to handle from a command line generation POV, so having
   QEMU report these unconditionally is misleading/wrong. It is
   not about what QEMU supports, it is about what libvirt is able
   to cope with.

 - In the future some of the caps may be describing supported
   monitor commands, detected via 'query-commands' QMP cmd.

 - Users of libvirt are asking us to expose information about
   what QEMU supports, in particular wrt to devices, but also
   other aspects of configuration.



A long time back I proposed a '-capabilities' command line argument
for querying QEMU.

  https://lists.gnu.org/archive/html/qemu-devel/2010-06/msg00921.html

There was a long discussion about this  many aspects of it were
disliked. In retrospect I agree with many of the comments, and
am glad we didn't adopt this. I think, however, there is a merit
in trying something vaguely related again, but with some key
differences. Basically I'd sum up my new idea as just use QMP.


 * No new command line arguments like -capabilities

 * libvirt invokes something like

 $QEMUBINARY -qmp CHARDEV -nodefault -nodefconfig -nographics

 * libvirt then runs a number of  QMP commands to find out
   what it needs to know. I'd expect the following existing
   commands would be used

 - query-version - already supported
 - query-commands- already supported
 - query-events  - already supported
 - query-kvm - already supported
 - qom-{list,list-types,get} - already supported
 - query-spice/vnc   - already supported

   And add the following new commands

 - query-devices - new, -device ?, and/or -device NAME,? data 
in QMP
 - query-machines- new, -M ? in QMP
 - query-cpu-types   - new, -cpu ? in QMP

The above would take care of probably 50% of the current libvirt
capabilities probing, including a portion of the -help stuff. Then
there is all the rest of the crap we detect from the -help. We could
just take the view, that as of 1.2, we assume everything we previously
detected is just available by default, and thus don't need to probe
it.  For stuff that is QOM based, I expect we'll be able to detect new
features in the future using the qom-XXX monitor commands. For stuff
that is non-qdev, and non-qom, libvirt can just do a plain version
number check, unless we decide there is specific info worth exposing
via other new 'query-XXX' monitor commands.

So in summary, as of 1.2 QEMU, libvirt would

  - Remove all use of -help, and other - command line args
   

Re: [Qemu-devel] [PATCH 08/14] qerror: add build_error_dict() and error_object_table[]

2012-07-26 Thread Markus Armbruster
Luiz Capitulino lcapitul...@redhat.com writes:

 In the near future, the QERR_ macros (which are json strings today) will
 be turned into an enumeration. When we get there, build_error_dict()
 will be used to (guess what) build an error dict by:

  1. Using the error class as an index to error_object_table[], which
 contains all QMP errors as json strings (with default values)

  2. Use the human error string to construct the error object data member.
 For example, an error message like:

  Parameter name=brain has not been found

  Will construct the following data member:

  'data': { 'name': 'brain' } }

 Signed-off-by: Luiz Capitulino lcapitul...@redhat.com
 ---
  qerror.c   | 86 
 ++
  qerror.h   |  1 +
  scripts/qapi-errors.py | 39 +++
  3 files changed, 126 insertions(+)

 diff --git a/qerror.c b/qerror.c
 index 42e8687..267545e 100644
 --- a/qerror.c
 +++ b/qerror.c
 @@ -38,6 +38,92 @@ static QError *qerror_new(void)
  return qerr;
  }
  
 +static bool iscchar(int c)
 +{
 +return (isalpha(c) || isdigit(c) || c == '_');
 +}

Depends on locale, which may not be what you want.

Beware of passing negative arguments to ctype.h functions.

 +
 +static char *get_key(const char *str)
 +{
 +char *p, *ret;
 +
 +ret = p = g_strdup(str);
 +
 +while (!iscchar(*p)) {
 +p++;
 +}
 +memmove(ret, p, strlen(ret));
 +
 +p = ret;
 +while (iscchar(*p)) {
 +p++;
 +}
 +*p = '\0';
 +
 +return ret;
 +}

Suggest something like

static char *get_key(const char *str)
{
char *beg, *end;

for (beg = str; !iscchar(*beg); beg++) ;
for (end = beg; iscchar(*end); end++) ;
return g_strndup(beg, end - beg);
}

 +
 +static char *get_value(const char *str)
 +{
 +char *p, *ret;
 +
 +p = strchr(str, '=');
 +while (!iscchar(*p)) {
 +p++;
 +}
 +p = ret = g_strdup(p);
 +while (iscchar(*p)) {
 +p++;
 +}
 +*p = '\0';
 +
 +return ret;
 +}

Likewise.

 +
 +static void set_dict_data(const char *msg, QDict *data_dict)
 +{
 +char *str, *msg2, *saveptr = NULL;
 +
 +msg2 = g_strdup(msg);
 +str = strtok_r(msg2,  , saveptr);
 +while (str) {
 +if (strchr(str, '=')) {
 +char *key = get_key(str);
 +char *value = get_value(str);
 +
 +/* FIXME: handle ints */
 +if (qdict_haskey(data_dict, key)) {
 +qdict_put(data_dict, key, qstring_from_str(value));
 +}
 +
 +g_free(key);
 +g_free(value);
 +}
 +str = strtok_r(NULL,  , saveptr);
 +}
 +
 +g_free(msg2);
 +}
 +
 +QDict *build_error_dict(int err_class, const char *msg)
 +{
 +QDict *err_dict;
 +QObject *obj;
 +
 +assert(msg[0] != '\0');
 +
 +obj = qobject_from_json(error_object_table[err_class]);
 +assert(obj);
 +assert(qobject_type(obj) == QTYPE_QDICT);
 +
 +err_dict = qobject_to_qdict(obj);
 +assert(qdict_haskey(err_dict, data));
 +
 +set_dict_data(msg, qdict_get_qdict(err_dict, data));
 +
 +return err_dict;
 +}
 +
  static QDict *error_object_from_fmt(const char *fmt, va_list *va)
  {
  QObject *obj;
 diff --git a/qerror.h b/qerror.h
 index 16401ff..c4f6053 100644
 --- a/qerror.h
 +++ b/qerror.h
 @@ -36,5 +36,6 @@ void qerror_report(const char *fmt, ...) GCC_FMT_ATTR(1, 2);
  void qerror_report_err(Error *err);
  void assert_no_error(Error *err);
  char *qerror_format(const char *fmt, QDict *error);
 +QDict *build_error_dict(int err_class, const char *msg);
  
  #endif /* QERROR_H */
 diff --git a/scripts/qapi-errors.py b/scripts/qapi-errors.py
 index 59cf426..5f8723e 100644
 --- a/scripts/qapi-errors.py
 +++ b/scripts/qapi-errors.py
 @@ -85,6 +85,42 @@ static const QErrorStringTable qerror_table[] = {
  
  return ret
  
 +def gen_error_data_obj(data):
 +colon = ''
 +data_str = ''
 +for k, v in data.items():
 +data_str += colon + '%s':  % k
 +if v == 'str':
 +data_str += 'unknown'
 +elif v == 'int':
 +data_str += '0'
 +else:
 +sys.exit(unknown data type '%s' for error '%s' % (v, name))
 +colon = ', '
 +return data_str

colon is either empty or ', ', but never a colon.  What about calling it
sep, for separator?

 +
 +def gen_error_obj_table(exprs):
 +ret = mcgen('''
 +static const char *error_object_table[] = {
 +''')
 +
 +for err in exprs:
 +data = gen_error_data_obj({})
 +if err.has_key('data'):
 +data = gen_error_data_obj(err['data'])
 +ret += mcgen('''
 +{ 'class': '%(error_class)s', 'data': { %(error_data)s } },
 +''',
 +error_class=err['error'], error_data=data)
 +
 +ret += mcgen('''
 +NULL,
 +};
 +
 +''')
 +
 +return ret;
 +
  def gen_error_macro_data_str(data):
  colon = ''
  data_str = ''
 @@ 

Re: [Qemu-devel] [PATCH 21/27] migration: stop all cpus correctly

2012-07-26 Thread Eric Blake
On 07/24/2012 12:36 PM, Juan Quintela wrote:
 You can only stop all cpus from the iothread or an vcpu.  As we want
 to do it from the migration_thread, we need to do this dance with the
 botton handlers.

s/botton/bottom/ ?

 
 This patch is a request for ideas.  I can move this function to cpus.c, but
 wondered if there is an easy way of doing this?

Sorry, I'm not able to help there.

-- 
Eric Blake   ebl...@redhat.com+1-919-301-3266
Libvirt virtualization library http://libvirt.org



signature.asc
Description: OpenPGP digital signature


Re: [Qemu-devel] [PATCH 11/14] qerror: drop qerror_table[] for good

2012-07-26 Thread Markus Armbruster
Luiz Capitulino lcapitul...@redhat.com writes:

 Last commit deprecated it.

Do you mean Unused since last commit?

Also drops the code that used it to generate
 error objects.



Re: [Qemu-devel] [PATCH v3] qemu-iotests: add qed.py image manipulation utility

2012-07-26 Thread Eric Blake
On 07/26/2012 06:24 AM, Stefan Hajnoczi wrote:
 The qed.py utility can inspect and manipulate QED image files.  It can
 be used for testing to see the state of image metadata and also to
 inject corruptions into the image file.  It also has a scrubbing feature
 to copy just the metadata out of an image file, allowing users to share
 broken image files without revealing data in bug reports.
 

 +# Copyright (C) 2010 IBM, Corp.
 +#
 +# Authors:
 +#  Stefan Hajnoczi stefa...@linux.vnet.ibm.com
 +#
 +# This work is licensed under the terms of the GNU GPL, version 2.  See
 +# the COPYING file in the top-level directory.

On 07/26/2012 06:31 AM, Kevin Wolf wrote: Am 26.07.2012 14:24, schrieb
 Thanks, applied to the block branch.

Is it too late to amend to GPLv2+?

-- 
Eric Blake   ebl...@redhat.com+1-919-301-3266
Libvirt virtualization library http://libvirt.org



signature.asc
Description: OpenPGP digital signature


Re: [Qemu-devel] [PATCH 1/5] qom: adopt rwlock to protect accessing dev from removing it

2012-07-26 Thread liu ping fan
On Wed, Jul 25, 2012 at 5:08 PM, Paolo Bonzini pbonz...@redhat.com wrote:
 Il 25/07/2012 05:31, Liu Ping Fan ha scritto:
 From: Liu Ping Fan pingf...@linux.vnet.ibm.com

 rwlock:
   qemu_device_tree_mutex

 rd side:
   --device_del(destruction of device will be postphoned until unplug
 ack from guest),
   --pci hot-unplug
   --iteration (qdev_reset_all)

 wr side:
   --device_add

 Signed-off-by: Liu Ping Fan pingf...@linux.vnet.ibm.com
 ---
  hw/pci-hotplug.c  |4 
  hw/qdev-monitor.c |   17 -
  hw/qdev.c |2 ++
  3 files changed, 22 insertions(+), 1 deletions(-)

 diff --git a/hw/pci-hotplug.c b/hw/pci-hotplug.c
 index e7fb780..b3b88c1 100644
 --- a/hw/pci-hotplug.c
 +++ b/hw/pci-hotplug.c
 @@ -265,9 +265,11 @@ static int pci_device_hot_remove(Monitor *mon, const 
 char *pci_addr)
  return -1;
  }

 +qemu_rwlock_rdlock_devtree();

 This is not defined anywhere, is a piece missing in the patch?

Oh, yes, I miss the patch.  In that patch, these rwlock are just place holder.
I see there is already try to implement rwlock for qemu.
http://lists.gnu.org/archive/html/qemu-devel/2011-10/msg00192.html
and is it the time for introduce rwlock for qemu?

Thanks,
pingfan


 Paolo




Re: [Qemu-devel] [PATCH v2 3/7] docs: add lazy refcounts bit to qcow2 specification

2012-07-26 Thread Kevin Wolf
Am 25.07.2012 14:21, schrieb Stefan Hajnoczi:
 The lazy refcounts bit indicates that this image can take advantage of
 the dirty bit and that refcount updates can be postponed.
 
 Signed-off-by: Stefan Hajnoczi stefa...@linux.vnet.ibm.com
 ---
  docs/specs/qcow2.txt |7 ++-
  1 file changed, 6 insertions(+), 1 deletion(-)
 
 diff --git a/docs/specs/qcow2.txt b/docs/specs/qcow2.txt
 index 339cdc1..f2f4faa 100644
 --- a/docs/specs/qcow2.txt
 +++ b/docs/specs/qcow2.txt
 @@ -86,7 +86,12 @@ in the description of a field.
  Bitmask of compatible features. An implementation can
  safely ignore any unknown bits that are set.
  
 -Bits 0-63:  Reserved (set to 0)
 +Bit 0:  Lazy refcounts bit.  If this bit is set then
 +lazy refcount updates can be used.  This 
 means
 +postponing marking the image file dirty and

Not sure what was intended here, but the dirty flag isn't set anywhere
yet, so you can't postpone it either. Maybe s/postponing//?

 +postponing refcount metadata updates.
 +
 +Bits 1-63:  Reserved (set to 0)
  
   88 -  95:  autoclear_features
  Bitmask of auto-clear features. An implementation may 
 only

Kevin



[Qemu-devel] [PATCH RFC v4 15/18] MAINTAINERS: Document sPAPR (pSeries) machine

2012-07-26 Thread Andreas Färber
Signed-off-by: Andreas Färber afaer...@suse.de
Cc: Alexander Graf ag...@suse.de
Cc: Benjamin Herrenschmidt b...@kernel.crashing.org
Cc: David Gibson da...@gibson.dropbear.id.au
---
 MAINTAINERS |7 +++
 1 files changed, 7 insertions(+), 0 deletions(-)

diff --git a/MAINTAINERS b/MAINTAINERS
index 2d219d2..282d497 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -374,6 +374,13 @@ S: Odd Fixes
 F: hw/ppc_prep.c
 F: hw/prep_pci.[hc]
 
+sPAPR
+M: David Gibson da...@gibson.dropbear.id.au
+M: Alexander Graf ag...@suse.de
+L: qemu-...@nongnu.org
+S: Supported
+F: hw/spapr*
+
 SH4 Machines
 
 R2D
-- 
1.7.7




[Qemu-devel] [PATCH v4 01/18] pci: Make host bridge TypeInfos const

2012-07-26 Thread Andreas Färber
During the QOM migration they were amended with further info but this is
no longer the case. All static TypeInfos can be const these days.

Signed-off-by: Andreas Färber afaer...@suse.de
---
 hw/alpha_typhoon.c |2 +-
 hw/bonito.c|4 ++--
 hw/dec_pci.c   |6 +++---
 hw/grackle_pci.c   |4 ++--
 hw/gt64xxx.c   |4 ++--
 hw/piix_pci.c  |8 
 hw/ppc4xx_pci.c|4 ++--
 hw/ppce500_pci.c   |4 ++--
 hw/prep_pci.c  |4 ++--
 hw/spapr_pci.c |2 +-
 hw/unin_pci.c  |   16 
 11 files changed, 29 insertions(+), 29 deletions(-)

diff --git a/hw/alpha_typhoon.c b/hw/alpha_typhoon.c
index 872e112..cc63737 100644
--- a/hw/alpha_typhoon.c
+++ b/hw/alpha_typhoon.c
@@ -817,7 +817,7 @@ static void typhoon_pcihost_class_init(ObjectClass *klass, 
void *data)
 dc-no_user = 1;
 }
 
-static TypeInfo typhoon_pcihost_info = {
+static const TypeInfo typhoon_pcihost_info = {
 .name  = typhoon-pcihost,
 .parent= TYPE_SYS_BUS_DEVICE,
 .instance_size = sizeof(TyphoonState),
diff --git a/hw/bonito.c b/hw/bonito.c
index 77786f8..b990875 100644
--- a/hw/bonito.c
+++ b/hw/bonito.c
@@ -781,7 +781,7 @@ static void bonito_class_init(ObjectClass *klass, void 
*data)
 dc-vmsd = vmstate_bonito;
 }
 
-static TypeInfo bonito_info = {
+static const TypeInfo bonito_info = {
 .name  = Bonito,
 .parent= TYPE_PCI_DEVICE,
 .instance_size = sizeof(PCIBonitoState),
@@ -797,7 +797,7 @@ static void bonito_pcihost_class_init(ObjectClass *klass, 
void *data)
 dc-no_user = 1;
 }
 
-static TypeInfo bonito_pcihost_info = {
+static const TypeInfo bonito_pcihost_info = {
 .name  = Bonito-pcihost,
 .parent= TYPE_SYS_BUS_DEVICE,
 .instance_size = sizeof(BonitoState),
diff --git a/hw/dec_pci.c b/hw/dec_pci.c
index 37337bf..5194a9f 100644
--- a/hw/dec_pci.c
+++ b/hw/dec_pci.c
@@ -66,7 +66,7 @@ static void dec_21154_pci_bridge_class_init(ObjectClass 
*klass, void *data)
 dc-vmsd = vmstate_pci_device;
 }
 
-static TypeInfo dec_21154_pci_bridge_info = {
+static const TypeInfo dec_21154_pci_bridge_info = {
 .name  = dec-21154-p2p-bridge,
 .parent= TYPE_PCI_DEVICE,
 .instance_size = sizeof(PCIBridge),
@@ -119,7 +119,7 @@ static void dec_21154_pci_host_class_init(ObjectClass 
*klass, void *data)
 k-is_bridge = 1;
 }
 
-static TypeInfo dec_21154_pci_host_info = {
+static const TypeInfo dec_21154_pci_host_info = {
 .name  = dec-21154,
 .parent= TYPE_PCI_DEVICE,
 .instance_size = sizeof(PCIDevice),
@@ -133,7 +133,7 @@ static void pci_dec_21154_device_class_init(ObjectClass 
*klass, void *data)
 sdc-init = pci_dec_21154_device_init;
 }
 
-static TypeInfo pci_dec_21154_device_info = {
+static const TypeInfo pci_dec_21154_device_info = {
 .name  = dec-21154-sysbus,
 .parent= TYPE_SYS_BUS_DEVICE,
 .instance_size = sizeof(DECState),
diff --git a/hw/grackle_pci.c b/hw/grackle_pci.c
index 81ff3a3..35667ad 100644
--- a/hw/grackle_pci.c
+++ b/hw/grackle_pci.c
@@ -134,7 +134,7 @@ static void grackle_pci_class_init(ObjectClass *klass, void 
*data)
 dc-no_user = 1;
 }
 
-static TypeInfo grackle_pci_info = {
+static const TypeInfo grackle_pci_info = {
 .name  = grackle,
 .parent= TYPE_PCI_DEVICE,
 .instance_size = sizeof(PCIDevice),
@@ -150,7 +150,7 @@ static void pci_grackle_class_init(ObjectClass *klass, void 
*data)
 dc-no_user = 1;
 }
 
-static TypeInfo grackle_pci_host_info = {
+static const TypeInfo grackle_pci_host_info = {
 .name  = grackle-pcihost,
 .parent= TYPE_SYS_BUS_DEVICE,
 .instance_size = sizeof(GrackleState),
diff --git a/hw/gt64xxx.c b/hw/gt64xxx.c
index a2d0e5a..04831bb 100644
--- a/hw/gt64xxx.c
+++ b/hw/gt64xxx.c
@@ -1147,7 +1147,7 @@ static void gt64120_pci_class_init(ObjectClass *klass, 
void *data)
 k-class_id = PCI_CLASS_BRIDGE_HOST;
 }
 
-static TypeInfo gt64120_pci_info = {
+static const TypeInfo gt64120_pci_info = {
 .name  = gt64120_pci,
 .parent= TYPE_PCI_DEVICE,
 .instance_size = sizeof(PCIDevice),
@@ -1161,7 +1161,7 @@ static void gt64120_class_init(ObjectClass *klass, void 
*data)
 sdc-init = gt64120_init;
 }
 
-static TypeInfo gt64120_info = {
+static const TypeInfo gt64120_info = {
 .name  = gt64120,
 .parent= TYPE_SYS_BUS_DEVICE,
 .instance_size = sizeof(GT64120State),
diff --git a/hw/piix_pci.c b/hw/piix_pci.c
index 09e84f5..5db4026 100644
--- a/hw/piix_pci.c
+++ b/hw/piix_pci.c
@@ -517,7 +517,7 @@ static void piix3_class_init(ObjectClass *klass, void *data)
 k-class_id = PCI_CLASS_BRIDGE_ISA;
 }
 
-static TypeInfo piix3_info = {
+static const TypeInfo piix3_info = {
 .name  = PIIX3,
 .parent= TYPE_PCI_DEVICE,
 .instance_size = sizeof(PIIX3State),
@@ -540,7 +540,7 @@ static void piix3_xen_class_init(ObjectClass 

Re: [Qemu-devel] [PATCH 03/14] qerror: drop qerror_abort()

2012-07-26 Thread Eric Blake
On 07/25/2012 02:50 PM, Luiz Capitulino wrote:
 Previously, developers had to create error dicts manually and also enter
 the matching desc table entry. Thus, qerro_abort() was added to help

s/qerro_/qerror_/

 catching bad error dicts.
 
 Today, all that stuff is generated automatically which makes the chance
 of a bad generated dict quite low.
 
 Also, qerror_abort() would... _abort_ on a bad error dict!
 
 This commit maintains the same verification logic on the error object
 but drops the abort() in favor of reporting UndefinedError for bad dicts
 (and also print a debug message to stderr).
 
 Signed-off-by: Luiz Capitulino lcapitul...@redhat.com
 ---

-- 
Eric Blake   ebl...@redhat.com+1-919-301-3266
Libvirt virtualization library http://libvirt.org



signature.asc
Description: OpenPGP digital signature


Re: [Qemu-devel] [PATCH 2/5] exec.c: use refcnt to protect device during dispatching

2012-07-26 Thread liu ping fan
On Wed, Jul 25, 2012 at 5:18 PM, Paolo Bonzini pbonz...@redhat.com wrote:
 Il 25/07/2012 10:12, liu ping fan ha scritto:
  +qemu_rwlock_rdlock_devtree();
   section = phys_page_find(page  TARGET_PAGE_BITS);
  +if (!(memory_region_is_ram(section-mr) ||
  +memory_region_is_romd(section-mr))  !is_write) {
  +bk = get_backend(section-mr, addr);
  +object_ref(bk);
  +} else if (!memory_region_is_ram(section-mr)  is_write) {
  +bk = get_backend(section-mr, addr);
  +object_ref(bk);
  +}
  +qemu_rwlock_unlock_devtree();
 
   if (is_write) {
   if (!memory_region_is_ram(section-mr)) {
  @@ -3426,6 +3462,7 @@ void cpu_physical_memory_rw(target_phys_addr_t 
  addr, uint8_t *buf,
   io_mem_write(section-mr, addr1, val, 1);
   l = 1;
   }
  +object_unref(bk);
 
  Currently object_ref()/object_unref() are not atomic.  Will you send
 We obey the rule:
rdlock-search-ref_get,
wrlock-remove -ref_put
 So can  it causes problem if object_ref()/object_unref()  are not atomic?

 Yes, two CPUs can perform object_ref at the same time.

 You can find a header file for atomic operations here:
 https://github.com/bonzini/qemu/commit/atomics.patch

Got it, thanks

 Paolo



Re: [Qemu-devel] [PATCH 1/5] qom: adopt rwlock to protect accessing dev from removing it

2012-07-26 Thread Avi Kivity
On 07/26/2012 03:56 PM, liu ping fan wrote:
 On Wed, Jul 25, 2012 at 5:08 PM, Paolo Bonzini pbonz...@redhat.com wrote:
 Il 25/07/2012 05:31, Liu Ping Fan ha scritto:
 From: Liu Ping Fan pingf...@linux.vnet.ibm.com

 rwlock:
   qemu_device_tree_mutex

 rd side:
   --device_del(destruction of device will be postphoned until unplug
 ack from guest),
   --pci hot-unplug
   --iteration (qdev_reset_all)

 wr side:
   --device_add


 This is not defined anywhere, is a piece missing in the patch?

 Oh, yes, I miss the patch.  In that patch, these rwlock are just place holder.
 I see there is already try to implement rwlock for qemu.
 http://lists.gnu.org/archive/html/qemu-devel/2011-10/msg00192.html
 and is it the time for introduce rwlock for qemu?


From the description above, I don't see why it can't be a mutex.

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





Re: [Qemu-devel] [PATCH v3] qemu-iotests: add qed.py image manipulation utility

2012-07-26 Thread Kevin Wolf
Am 26.07.2012 14:56, schrieb Eric Blake:
 On 07/26/2012 06:24 AM, Stefan Hajnoczi wrote:
 The qed.py utility can inspect and manipulate QED image files.  It can
 be used for testing to see the state of image metadata and also to
 inject corruptions into the image file.  It also has a scrubbing feature
 to copy just the metadata out of an image file, allowing users to share
 broken image files without revealing data in bug reports.

 
 +# Copyright (C) 2010 IBM, Corp.
 +#
 +# Authors:
 +#  Stefan Hajnoczi stefa...@linux.vnet.ibm.com
 +#
 +# This work is licensed under the terms of the GNU GPL, version 2.  See
 +# the COPYING file in the top-level directory.
 
 On 07/26/2012 06:31 AM, Kevin Wolf wrote: Am 26.07.2012 14:24, schrieb
 Thanks, applied to the block branch.
 
 Is it too late to amend to GPLv2+?

If Stefan sends a diff to squash in or a v4, I can still update it.
Nothing is final until it's in master.

Kevin



Re: [Qemu-devel] [PATCH v4 10/18] spapr_pci: QOM'ify sPAPR PCI host bridge

2012-07-26 Thread Andreas Färber
Am 26.07.2012 14:31, schrieb David Gibson:
 On Thu, Jul 26, 2012 at 02:28:28PM +0200, Andreas Färber wrote:
 Introduce type constant. Introduce cast macro to drop bogus busdev field
 that would've broken SYS_BUS_DEVICE().
 
 I believe there's already a patch making its way through agraf's tree
 that removes the bogus extra busdev.

True, there's Alexey's
http://repo.or.cz/w/qemu/agraf.git/commit/444aae9543ac840d2856ba4cd7885b892f746370

My series have been around longer though, I believe, fixing all bridges
and avoiding the old-style macros and parent name dependencies; so if my
series gets merged first, Alex can just dump that one patch. His
followup patch doesn't look affected.

Andreas

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





Re: [Qemu-devel] Synchronize issue and lost character when using serial as pipe type

2012-07-26 Thread Wei Xu
Hi Wei-Ren  All,
I have tried to upgrade qemu, but it looks so hard, my guest domain can't
boot up with the new qemu 1.0.1,
and i'm not sure if I make a wrong usage or something else.

Cos I don't know how to tell xend to use qemu-1.0.1 to replace it's
qemu-dm, so I try to find out some other way, when I see qemu can
directly boot up a guest use xen hypercall in the man page, then I'm going
to try it, but it told this can't be used with xend, so i set up a new
Ubuntu 11.10 and install Xen 4.1.2 from source code and boot to it, that
means no xend.

After compiled qemu-1.0.1 with --enable-xen option and installed it, I
launched the command line to boot my  guest domain:

 #qemu-system-x86_64 -vnc 0.0.0.0:0 -boot c -serial pipe:/tmp/bsd-serial
-net none -M pc -hda /wei/dev/FreeBSD9.0.img -xen-create -xen-domid 1
is it right?

System hang during boot up after printed out about 50% of successful boot
up message, I have compared it with before successfully boot up message, i
found it maybe hanging when try to recognize the disk or loading PV driver
for disk, as i know, xend use qemu-dm 0.10.2 to launch a guest while it
looks qemu-1.0.1 used a totally different way.

I wonder if qemu-dm is a similar thing with qemu itself?  looks qemu
support a lot thing? I have searched for the difference between them but
looks no answer, Does anyone know this?

Is there somebody have tried to replace or upgrade qemu-dm successfully?
or any other idea will be appreciated a lot.

Regards,
Wei


On Wed, Jul 25, 2012 at 11:27 AM, Wei Xu wei.xu@gmail.com wrote:

 Thanks, I'll try it and update later.


 On Tue, Jul 24, 2012 at 7:36 PM, 陳韋任 (Wei-Ren Chen) 
 che...@iis.sinica.edu.tw wrote:

 On Tue, Jul 24, 2012 at 07:32:44PM +0800, Wei Xu wrote:
  Hi Folks,
  I am trying to install FreeBSD9.0 with xen4.0.2 and qemu 0.10.2, and
 try to set
  up a kernel debug host pair using the serial with pipe type,
  after tried and failed for a lot of times and then I come here for some
 help,
  here is my info.

   QEMU 0.10 is really old. Have you ever considered using current
 release?

 Regards,
 chenwj

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





Re: [Qemu-devel] [PATCH 2/5] exec.c: use refcnt to protect device during dispatching

2012-07-26 Thread liu ping fan
On Wed, Jul 25, 2012 at 8:27 PM, Avi Kivity a...@redhat.com wrote:
 On 07/25/2012 01:58 PM, Avi Kivity wrote:
  while (len  0) {
  page = addr  TARGET_PAGE_MASK;
  l = (page + TARGET_PAGE_SIZE) - addr;
  if (l  len)
  l = len;
 +
 +qemu_rwlock_rdlock_devtree();
  section = phys_page_find(page  TARGET_PAGE_BITS);

 Does the devtree lock also protect the data structures accessed by
 phys_page_find()?  Seems wrong.

 The right way is to object_ref() in core_region_add() and object_unref()
 in core_region_del().  We're guaranteed that mr-object is alive during
 _add(), and DeviceClass::unmap() ensures that the extra ref doesn't
 block destruction.

OK, I see. I will try in this way.  But when
memory_region_destroy()-..-core_region_del(), should we reset the
lp.ptr to phys_section_unassigned , otherwise, if using  removed
target_phys_addr_t, we will still get the pointer to invalid
MemoryRegion?

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





Re: [Qemu-devel] [PATCH] vl: add -libvirt-caps option for libvirt to stop parsing help output

2012-07-26 Thread Daniel P. Berrange
On Thu, Jul 26, 2012 at 01:47:23PM +0100, Daniel P. Berrange wrote:
 On Wed, Jul 25, 2012 at 02:47:57PM -0500, Anthony Liguori wrote:
  The help output is going to change dramatically for 0.13.  We've spent too 
  long
  waiting for a perfect solution to capabilities handling and the end loser is
  the direct consumer of QEMU because the help output is awful.
  
  I will not apply any patches that change help output until 0.13 development
  opens up.  This should give libvirt adequate time to implement support for
  dealing with this new option.
 
 I completely agree with this. We have spent far too long making do with
 help output and its about time we finish with this once  for all.
 I'm assuming you mean the 1.3 release here. If so I'll agree that it
 is an acceptable plan to change help output at the start of the 1.3
 release.
 
 This gives us enough time to agree on what todo to support apps needing
 to query QEMU.
 
  This capabilities set comes directly from libvirt's source code so it's 
  entirely
  adequate for libvirt's purposes.  We can still explore more sophisticated
  approaches that are more general purpose but the help output will be 
  changing.
 
 While I appreciate what you're trying todo here, I think this would be a
 serious mistake on many counts, and even be incorrect in some ways.
 
  - It ignores the needs of other apps using QEMU. In particular Richard
Jones has frequently requested a way to detect QEMU capabilities
to satisfy libguestfs. I think it is unreasonable to expect libguestfs
to use the libvirt capabilities described here. Likewise other apps
 
  - This is just a point in time snapshot of what libvirt currently uses
from QEMU. If, for example, someone provided a patch to libvirt to
support the bluetooth devices we'd be stuck, because although QEMU
already supports bluetooth, this is not expressed in any of the
caps libvirt already has.
 
  - Not all of this information actually comes from the help output.
A bunch of it is stuff we detect from '-device ?' and
'-device name,?'. Although, (AFAIR) no one has objections to use
parsing the -device output because it is much better defined 
stable than -help, I think we could use some improvement to make
the parsing 100% long term maintainable by QEMU/apps. Similarly
we do  '-cpu ?' and '-machine ?'.  Some of the caps are set based
on the machine architecture, or QEMU version.
 
  - Some of the caps are set based on what libvirt is actually
able to handle from a command line generation POV, so having
QEMU report these unconditionally is misleading/wrong. It is
not about what QEMU supports, it is about what libvirt is able
to cope with.
 
  - In the future some of the caps may be describing supported
monitor commands, detected via 'query-commands' QMP cmd.
 
  - Users of libvirt are asking us to expose information about
what QEMU supports, in particular wrt to devices, but also
other aspects of configuration.
 
 
 
 A long time back I proposed a '-capabilities' command line argument
 for querying QEMU.
 
   https://lists.gnu.org/archive/html/qemu-devel/2010-06/msg00921.html
 
 There was a long discussion about this  many aspects of it were
 disliked. In retrospect I agree with many of the comments, and
 am glad we didn't adopt this. I think, however, there is a merit
 in trying something vaguely related again, but with some key
 differences. Basically I'd sum up my new idea as just use QMP.
 
 
  * No new command line arguments like -capabilities
 
  * libvirt invokes something like
 
  $QEMUBINARY -qmp CHARDEV -nodefault -nodefconfig -nographics
 
  * libvirt then runs a number of  QMP commands to find out
what it needs to know. I'd expect the following existing
commands would be used
 
  - query-version - already supported
  - query-commands- already supported
  - query-events  - already supported
  - query-kvm - already supported
  - qom-{list,list-types,get} - already supported
  - query-spice/vnc   - already supported
 
And add the following new commands
 
  - query-devices - new, -device ?, and/or -device NAME,? data 
 in QMP
  - query-machines- new, -M ? in QMP
  - query-cpu-types   - new, -cpu ? in QMP
 
 The above would take care of probably 50% of the current libvirt
 capabilities probing, including a portion of the -help stuff. Then
 there is all the rest of the crap we detect from the -help. We could
 just take the view, that as of 1.2, we assume everything we previously
 detected is just available by default, and thus don't need to probe
 it.  For stuff that is QOM based, I expect we'll be able to detect new
 features in the future using the qom-XXX monitor commands. For stuff
 that is non-qdev, and non-qom, libvirt can just do a plain version
 number check, unless we decide there is 

[Qemu-devel] [PATCH v4 05/18] grackle_pci: QOM'ify Grackle PCI host bridge

2012-07-26 Thread Andreas Färber
Introduce type constant. Introduce cast macro to drop dummy busdev field
used with FROM_SYSBUS() that would've broken SYS_BUS_DEVICE().
Avoid accessing parent fields directly.

Drop no-op reset function.

Signed-off-by: Andreas Färber afaer...@suse.de
---
 hw/grackle_pci.c |   57 ++---
 hw/ppc_mac.h |1 +
 2 files changed, 29 insertions(+), 29 deletions(-)

diff --git a/hw/grackle_pci.c b/hw/grackle_pci.c
index 35667ad..d814270 100644
--- a/hw/grackle_pci.c
+++ b/hw/grackle_pci.c
@@ -23,10 +23,9 @@
  * THE SOFTWARE.
  */
 
-#include sysbus.h
+#include pci_host.h
 #include ppc_mac.h
 #include pci.h
-#include pci_host.h
 
 /* debug Grackle */
 //#define DEBUG_GRACKLE
@@ -38,9 +37,12 @@
 #define GRACKLE_DPRINTF(fmt, ...)
 #endif
 
+#define GRACKLE_PCI_HOST_BRIDGE(obj) \
+OBJECT_CHECK(GrackleState, (obj), TYPE_GRACKLE_PCI_HOST_BRIDGE)
+
 typedef struct GrackleState {
-SysBusDevice busdev;
 PCIHostState host_state;
+
 MemoryRegion pci_mmio;
 MemoryRegion pci_hole;
 } GrackleState;
@@ -59,22 +61,20 @@ static void pci_grackle_set_irq(void *opaque, int irq_num, 
int level)
 qemu_set_irq(pic[irq_num + 0x15], level);
 }
 
-static void pci_grackle_reset(void *opaque)
-{
-}
-
 PCIBus *pci_grackle_init(uint32_t base, qemu_irq *pic,
  MemoryRegion *address_space_mem,
  MemoryRegion *address_space_io)
 {
 DeviceState *dev;
 SysBusDevice *s;
+PCIHostState *phb;
 GrackleState *d;
 
-dev = qdev_create(NULL, grackle-pcihost);
+dev = qdev_create(NULL, TYPE_GRACKLE_PCI_HOST_BRIDGE);
 qdev_init_nofail(dev);
-s = sysbus_from_qdev(dev);
-d = FROM_SYSBUS(GrackleState, s);
+s = SYS_BUS_DEVICE(dev);
+phb = FROM_SYSBUS(PCIHostState, s);
+d = GRACKLE_PCI_HOST_BRIDGE(dev);
 
 memory_region_init(d-pci_mmio, pci-mmio, 0x1ULL);
 memory_region_init_alias(d-pci_hole, pci-hole, d-pci_mmio,
@@ -82,36 +82,35 @@ PCIBus *pci_grackle_init(uint32_t base, qemu_irq *pic,
 memory_region_add_subregion(address_space_mem, 0x8000ULL,
 d-pci_hole);
 
-d-host_state.bus = pci_register_bus(d-busdev.qdev, pci,
- pci_grackle_set_irq,
- pci_grackle_map_irq,
- pic,
- d-pci_mmio,
- address_space_io,
- 0, 4);
+phb-bus = pci_register_bus(dev, pci,
+pci_grackle_set_irq,
+pci_grackle_map_irq,
+pic,
+d-pci_mmio,
+address_space_io,
+0, 4);
 
-pci_create_simple(d-host_state.bus, 0, grackle);
+pci_create_simple(phb-bus, 0, grackle);
 
 sysbus_mmio_map(s, 0, base);
 sysbus_mmio_map(s, 1, base + 0x0020);
 
-return d-host_state.bus;
+return phb-bus;
 }
 
 static int pci_grackle_init_device(SysBusDevice *dev)
 {
-GrackleState *s;
+PCIHostState *phb;
 
-s = FROM_SYSBUS(GrackleState, dev);
+phb = FROM_SYSBUS(PCIHostState, dev);
 
-memory_region_init_io(s-host_state.conf_mem, pci_host_conf_le_ops,
-  s-host_state, pci-conf-idx, 0x1000);
-memory_region_init_io(s-host_state.data_mem, pci_host_data_le_ops,
-  s-host_state, pci-data-idx, 0x1000);
-sysbus_init_mmio(dev, s-host_state.conf_mem);
-sysbus_init_mmio(dev, s-host_state.data_mem);
+memory_region_init_io(phb-conf_mem, pci_host_conf_le_ops,
+  dev, pci-conf-idx, 0x1000);
+memory_region_init_io(phb-data_mem, pci_host_data_le_ops,
+  dev, pci-data-idx, 0x1000);
+sysbus_init_mmio(dev, phb-conf_mem);
+sysbus_init_mmio(dev, phb-data_mem);
 
-qemu_register_reset(pci_grackle_reset, s-host_state);
 return 0;
 }
 
@@ -151,7 +150,7 @@ static void pci_grackle_class_init(ObjectClass *klass, void 
*data)
 }
 
 static const TypeInfo grackle_pci_host_info = {
-.name  = grackle-pcihost,
+.name  = TYPE_GRACKLE_PCI_HOST_BRIDGE,
 .parent= TYPE_SYS_BUS_DEVICE,
 .instance_size = sizeof(GrackleState),
 .class_init= pci_grackle_class_init,
diff --git a/hw/ppc_mac.h b/hw/ppc_mac.h
index af75e45..7d08418 100644
--- a/hw/ppc_mac.h
+++ b/hw/ppc_mac.h
@@ -55,6 +55,7 @@ qemu_irq *heathrow_pic_init(MemoryRegion **pmem,
 int nb_cpus, qemu_irq **irqs);
 
 /* Grackle PCI */
+#define TYPE_GRACKLE_PCI_HOST_BRIDGE grackle-pcihost
 PCIBus *pci_grackle_init(uint32_t base, qemu_irq *pic,
  MemoryRegion *address_space_mem,
  MemoryRegion *address_space_io);
-- 
1.7.7




[Qemu-devel] [PATCH v4 08/18] ppce500_pci: QOM'ify e500 PCI host bridge

2012-07-26 Thread Andreas Färber
Introduce type constant and cast macro. Avoid accessing parent fields
directly.

Signed-off-by: Andreas Färber afaer...@suse.de
---
 hw/ppce500_pci.c |   16 +++-
 1 files changed, 11 insertions(+), 5 deletions(-)

diff --git a/hw/ppce500_pci.c b/hw/ppce500_pci.c
index 99748b3..e4f065a 100644
--- a/hw/ppce500_pci.c
+++ b/hw/ppce500_pci.c
@@ -72,8 +72,14 @@ struct pci_inbound {
 uint32_t piwar;
 };
 
+#define TYPE_PPC_E500_PCI_HOST_BRIDGE e500-pcihost
+
+#define PPC_E500_PCI_HOST_BRIDGE(obj) \
+OBJECT_CHECK(PPCE500PCIState, (obj), TYPE_PPC_E500_PCI_HOST_BRIDGE)
+
 struct PPCE500PCIState {
 PCIHostState pci_state;
+
 struct pci_outbound pob[PPCE500_PCI_NR_POBS];
 struct pci_inbound pib[PPCE500_PCI_NR_PIBS];
 uint32_t gasket_time;
@@ -310,17 +316,17 @@ static int e500_pcihost_initfn(SysBusDevice *dev)
 MemoryRegion *address_space_mem = get_system_memory();
 MemoryRegion *address_space_io = get_system_io();
 
-h = FROM_SYSBUS(PCIHostState, sysbus_from_qdev(dev));
-s = DO_UPCAST(PPCE500PCIState, pci_state, h);
+h = FROM_SYSBUS(PCIHostState, dev);
+s = PPC_E500_PCI_HOST_BRIDGE(dev);
 
 for (i = 0; i  ARRAY_SIZE(s-irq); i++) {
 sysbus_init_irq(dev, s-irq[i]);
 }
 
-b = pci_register_bus(s-pci_state.busdev.qdev, NULL, mpc85xx_pci_set_irq,
+b = pci_register_bus(DEVICE(dev), NULL, mpc85xx_pci_set_irq,
  mpc85xx_pci_map_irq, s-irq, address_space_mem,
  address_space_io, PCI_DEVFN(0x11, 0), 4);
-s-pci_state.bus = b;
+h-bus = b;
 
 pci_create_simple(b, 0, e500-host-bridge);
 
@@ -367,7 +373,7 @@ static void e500_pcihost_class_init(ObjectClass *klass, 
void *data)
 }
 
 static const TypeInfo e500_pcihost_info = {
-.name  = e500-pcihost,
+.name  = TYPE_PPC_E500_PCI_HOST_BRIDGE,
 .parent= TYPE_SYS_BUS_DEVICE,
 .instance_size = sizeof(PPCE500PCIState),
 .class_init= e500_pcihost_class_init,
-- 
1.7.7




Re: [Qemu-devel] [PATCH v5 6/6] block: Enable qemu_open/close to work with fd sets

2012-07-26 Thread Eric Blake
On 07/25/2012 09:21 PM, Corey Bryant wrote:
 
 
 On 07/25/2012 03:25 PM, Eric Blake wrote:
 On 07/25/2012 02:22 AM, Kevin Wolf wrote:
 Hm, not a nice interface where qemu_close() needs the filename and
 (worse) could be given a wrong filename. Maybe it would be better to
 maintain a list of fd - fdset mappings in qemu_open/close?


 I agree, I don't really like it either.

 We already have a list of fd - fdset mappings (mon_fdset_fd_t -
 mon_fdset_t).  Would it be too costly to loop through all the
 fdsets/fds
 at the beginning of every qemu_close()?

 I don't think so. qemu_close() is not a fast path and happens almost
 never, and the list is short enough that searching it isn't a problem
 anyway.

 I agree - just do the loop to do the reverse lookup yourself, rather
 than making qemu_close() have a different signature than close().

 
 Great, I'll do this then.

You may want an optimization of using a bitset for tracking which fds
are tracked by fdset in the first place, so that the fast path of
qemu_close() will be a check against the bitset to see if you even have
to waste time on the reverse lookup in the first place.  The bitset will
typically be small (bounded not only by the maximum possible fd, but
further by the fact that we don't usually open that many fds in the
first place), but I'm not sure if you can get away with static sizing.

-- 
Eric Blake   ebl...@redhat.com+1-919-301-3266
Libvirt virtualization library http://libvirt.org



signature.asc
Description: OpenPGP digital signature


Re: [Qemu-devel] [PATCH 2/5] exec.c: use refcnt to protect device during dispatching

2012-07-26 Thread Avi Kivity
On 07/26/2012 04:06 PM, liu ping fan wrote:
 On Wed, Jul 25, 2012 at 8:27 PM, Avi Kivity a...@redhat.com wrote:
 On 07/25/2012 01:58 PM, Avi Kivity wrote:
  while (len  0) {
  page = addr  TARGET_PAGE_MASK;
  l = (page + TARGET_PAGE_SIZE) - addr;
  if (l  len)
  l = len;
 +
 +qemu_rwlock_rdlock_devtree();
  section = phys_page_find(page  TARGET_PAGE_BITS);

 Does the devtree lock also protect the data structures accessed by
 phys_page_find()?  Seems wrong.

 The right way is to object_ref() in core_region_add() and object_unref()
 in core_region_del().  We're guaranteed that mr-object is alive during
 _add(), and DeviceClass::unmap() ensures that the extra ref doesn't
 block destruction.

 OK, I see. I will try in this way.  But when
 memory_region_destroy()-..-core_region_del(), should we reset the
 lp.ptr to phys_section_unassigned , otherwise, if using  removed
 target_phys_addr_t, we will still get the pointer to invalid
 MemoryRegion?

The intent was to use rcu, so when we rebuild phys_map we build it into
a new tree, use rcu_assign_pointer() to switch into the new tree, then
synchronize_rcu() and drop the old tree.

Since we don't have rcu yet we can emulate it with a lock.  We can start
with a simple mutex around the lookup and rebuild, then switch to rwlock
or rcu if needed.

(without the lock or rcu, just changing lp.ptr is dangerous, since it is
a bit field)

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





[Qemu-devel] [PATCH v4 07/18] ppc4xx_pci: QOM'ify ppc4xx PCI host bridge

2012-07-26 Thread Andreas Färber
Introduce type constant and cast macro. Avoid accessing its parent field
directly.

Signed-off-by: Andreas Färber afaer...@suse.de
---
 hw/ppc440_bamboo.c |3 ++-
 hw/ppc4xx.h|2 ++
 hw/ppc4xx_pci.c|   13 -
 3 files changed, 12 insertions(+), 6 deletions(-)

diff --git a/hw/ppc440_bamboo.c b/hw/ppc440_bamboo.c
index 0dd4dab..c198071 100644
--- a/hw/ppc440_bamboo.c
+++ b/hw/ppc440_bamboo.c
@@ -216,7 +216,8 @@ static void bamboo_init(ram_addr_t ram_size,
   ram_bases, ram_sizes, 1);
 
 /* PCI */
-dev = sysbus_create_varargs(ppc4xx-pcihost, PPC440EP_PCI_CONFIG,
+dev = sysbus_create_varargs(TYPE_PPC4xx_PCI_HOST_BRIDGE,
+PPC440EP_PCI_CONFIG,
 pic[pci_irq_nrs[0]], pic[pci_irq_nrs[1]],
 pic[pci_irq_nrs[2]], pic[pci_irq_nrs[3]],
 NULL);
diff --git a/hw/ppc4xx.h b/hw/ppc4xx.h
index b511020..5cd78b6 100644
--- a/hw/ppc4xx.h
+++ b/hw/ppc4xx.h
@@ -53,6 +53,8 @@ void ppc4xx_sdram_init (CPUPPCState *env, qemu_irq irq, int 
nbanks,
 target_phys_addr_t *ram_sizes,
 int do_init);
 
+#define TYPE_PPC4xx_PCI_HOST_BRIDGE ppc4xx-pcihost
+
 PCIBus *ppc4xx_pci_init(CPUPPCState *env, qemu_irq pci_irqs[4],
 target_phys_addr_t config_space,
 target_phys_addr_t int_ack,
diff --git a/hw/ppc4xx_pci.c b/hw/ppc4xx_pci.c
index 104ed98..599a75a 100644
--- a/hw/ppc4xx_pci.c
+++ b/hw/ppc4xx_pci.c
@@ -45,6 +45,9 @@ struct PCITargetMap {
 uint32_t la;
 };
 
+#define PPC4xx_PCI_HOST_BRIDGE(obj) \
+OBJECT_CHECK(PPC4xxPCIState, (obj), TYPE_PPC4xx_PCI_HOST_BRIDGE)
+
 #define PPC4xx_PCI_NR_PMMS 3
 #define PPC4xx_PCI_NR_PTMS 2
 
@@ -335,17 +338,17 @@ static int ppc4xx_pcihost_initfn(SysBusDevice *dev)
 PCIBus *b;
 int i;
 
-h = FROM_SYSBUS(PCIHostState, sysbus_from_qdev(dev));
-s = DO_UPCAST(PPC4xxPCIState, pci_state, h);
+h = FROM_SYSBUS(PCIHostState, dev);
+s = PPC4xx_PCI_HOST_BRIDGE(dev);
 
 for (i = 0; i  ARRAY_SIZE(s-irq); i++) {
 sysbus_init_irq(dev, s-irq[i]);
 }
 
-b = pci_register_bus(s-pci_state.busdev.qdev, NULL, ppc4xx_pci_set_irq,
+b = pci_register_bus(DEVICE(dev), NULL, ppc4xx_pci_set_irq,
  ppc4xx_pci_map_irq, s-irq, get_system_memory(),
  get_system_io(), 0, 4);
-s-pci_state.bus = b;
+h-bus = b;
 
 pci_create_simple(b, 0, ppc4xx-host-bridge);
 
@@ -394,7 +397,7 @@ static void ppc4xx_pcihost_class_init(ObjectClass *klass, 
void *data)
 }
 
 static const TypeInfo ppc4xx_pcihost_info = {
-.name  = ppc4xx-pcihost,
+.name  = TYPE_PPC4xx_PCI_HOST_BRIDGE,
 .parent= TYPE_SYS_BUS_DEVICE,
 .instance_size = sizeof(PPC4xxPCIState),
 .class_init= ppc4xx_pcihost_class_init,
-- 
1.7.7




Re: [Qemu-devel] [PATCH 1/5] qom: adopt rwlock to protect accessing dev from removing it

2012-07-26 Thread liu ping fan
On Thu, Jul 26, 2012 at 9:00 PM, Avi Kivity a...@redhat.com wrote:
 On 07/26/2012 03:56 PM, liu ping fan wrote:
 On Wed, Jul 25, 2012 at 5:08 PM, Paolo Bonzini pbonz...@redhat.com wrote:
 Il 25/07/2012 05:31, Liu Ping Fan ha scritto:
 From: Liu Ping Fan pingf...@linux.vnet.ibm.com

 rwlock:
   qemu_device_tree_mutex

 rd side:
   --device_del(destruction of device will be postphoned until unplug
 ack from guest),
   --pci hot-unplug
   --iteration (qdev_reset_all)

 wr side:
   --device_add


 This is not defined anywhere, is a piece missing in the patch?

 Oh, yes, I miss the patch.  In that patch, these rwlock are just place 
 holder.
 I see there is already try to implement rwlock for qemu.
 http://lists.gnu.org/archive/html/qemu-devel/2011-10/msg00192.html
 and is it the time for introduce rwlock for qemu?


 From the description above, I don't see why it can't be a mutex.

Searching in the device tree (or MemoryRegion view) can be often in
parallel, especially in mmio-dispatch code path

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





[Qemu-devel] [PATCH v4 03/18] bonito: QOM'ify Bonito PCI host bridge

2012-07-26 Thread Andreas Färber
Introduce type constant. Avoid accessing DeviceState or SysBusDevice
indirectly through PCIHostState field.

Drop global state by passing BonitoState as opaque and adding the IRQs
and a pointer to PCIBonitoState to its state.

Signed-off-by: Andreas Färber afaer...@suse.de
---
 hw/bonito.c |  146 ---
 1 files changed, 90 insertions(+), 56 deletions(-)

diff --git a/hw/bonito.c b/hw/bonito.c
index b990875..062c701 100644
--- a/hw/bonito.c
+++ b/hw/bonito.c
@@ -180,11 +180,14 @@
 #define PCI_ADDR(busno,devno,funno,regno)  \
 busno)16)0xff) + (((devno)11)0xf800) + (((funno)8)0x700) 
+ (regno))
 
-typedef PCIHostState BonitoState;
+#define TYPE_BONITO_PCI_HOST_BRIDGE Bonito-pcihost
+
+typedef struct BonitoState BonitoState;
 
 typedef struct PCIBonitoState
 {
 PCIDevice dev;
+
 BonitoState *pcihost;
 uint32_t regs[BONITO_REGS];
 
@@ -218,7 +221,16 @@ typedef struct PCIBonitoState
 
 } PCIBonitoState;
 
-PCIBonitoState * bonito_state;
+#define BONITO_PCI_HOST_BRIDGE(obj) \
+OBJECT_CHECK(BonitoState, (obj), TYPE_BONITO_PCI_HOST_BRIDGE)
+
+struct BonitoState {
+PCIHostState parent_obj;
+
+qemu_irq *pic;
+
+PCIBonitoState *pci_dev;
+};
 
 static void bonito_writel(void *opaque, target_phys_addr_t addr,
   uint64_t val, unsigned size)
@@ -314,9 +326,10 @@ static void bonito_pciconf_writel(void *opaque, 
target_phys_addr_t addr,
   uint64_t val, unsigned size)
 {
 PCIBonitoState *s = opaque;
+PCIDevice *d = PCI_DEVICE(s);
 
 DPRINTF(bonito_pciconf_writel TARGET_FMT_plx val %x\n, addr, val);
-s-dev.config_write(s-dev, addr, val, 4);
+d-config_write(d, addr, val, 4);
 }
 
 static uint64_t bonito_pciconf_readl(void *opaque, target_phys_addr_t addr,
@@ -324,9 +337,10 @@ static uint64_t bonito_pciconf_readl(void *opaque, 
target_phys_addr_t addr,
 {
 
 PCIBonitoState *s = opaque;
+PCIDevice *d = PCI_DEVICE(s);
 
 DPRINTF(bonito_pciconf_readl TARGET_FMT_plx\n, addr);
-return s-dev.config_read(s-dev, addr, 4);
+return d-config_read(d, addr, 4);
 }
 
 /* north bridge PCI configure space. 0x1fe0  - 0x1fe0 00ff */
@@ -402,6 +416,7 @@ static const MemoryRegionOps bonito_cop_ops = {
 static uint32_t bonito_sbridge_pciaddr(void *opaque, target_phys_addr_t addr)
 {
 PCIBonitoState *s = opaque;
+PCIHostState *phb = FROM_SYSBUS(PCIHostState, SYS_BUS_DEVICE(s-pcihost));
 uint32_t cfgaddr;
 uint32_t idsel;
 uint32_t devno;
@@ -423,13 +438,13 @@ static uint32_t bonito_sbridge_pciaddr(void *opaque, 
target_phys_addr_t addr)
 regno = (cfgaddr  BONITO_PCICONF_REG_MASK)  BONITO_PCICONF_REG_OFFSET;
 
 if (idsel == 0) {
-fprintf(stderr, error in bonito pci config address TARGET_FMT_plx
+fprintf(stderr, error in bonito pci config address  TARGET_FMT_plx
 ,pcimap_cfg=%x\n, addr, s-regs[BONITO_PCIMAP_CFG]);
 exit(1);
 }
-pciaddr = PCI_ADDR(pci_bus_num(s-pcihost-bus), devno, funno, regno);
+pciaddr = PCI_ADDR(pci_bus_num(phb-bus), devno, funno, regno);
 DPRINTF(cfgaddr %x pciaddr %x busno %x devno %d funno %d regno %d\n,
-cfgaddr, pciaddr, pci_bus_num(s-pcihost-bus), devno, funno, regno);
+cfgaddr, pciaddr, pci_bus_num(phb-bus), devno, funno, regno);
 
 return pciaddr;
 }
@@ -438,6 +453,8 @@ static void bonito_spciconf_writeb(void *opaque, 
target_phys_addr_t addr,
uint32_t val)
 {
 PCIBonitoState *s = opaque;
+PCIDevice *d = PCI_DEVICE(s);
+PCIHostState *phb = FROM_SYSBUS(PCIHostState, SYS_BUS_DEVICE(s-pcihost));
 uint32_t pciaddr;
 uint16_t status;
 
@@ -449,24 +466,26 @@ static void bonito_spciconf_writeb(void *opaque, 
target_phys_addr_t addr,
 }
 
 /* set the pci address in s-config_reg */
-s-pcihost-config_reg = (pciaddr) | (1u  31);
-pci_data_write(s-pcihost-bus, s-pcihost-config_reg, val  0xff, 1);
+phb-config_reg = (pciaddr) | (1u  31);
+pci_data_write(phb-bus, phb-config_reg, val  0xff, 1);
 
 /* clear PCI_STATUS_REC_MASTER_ABORT and PCI_STATUS_REC_TARGET_ABORT */
-status = pci_get_word(s-dev.config + PCI_STATUS);
+status = pci_get_word(d-config + PCI_STATUS);
 status = ~(PCI_STATUS_REC_MASTER_ABORT | PCI_STATUS_REC_TARGET_ABORT);
-pci_set_word(s-dev.config + PCI_STATUS, status);
+pci_set_word(d-config + PCI_STATUS, status);
 }
 
 static void bonito_spciconf_writew(void *opaque, target_phys_addr_t addr,
uint32_t val)
 {
 PCIBonitoState *s = opaque;
+PCIDevice *d = PCI_DEVICE(s);
+PCIHostState *phb = FROM_SYSBUS(PCIHostState, SYS_BUS_DEVICE(s-pcihost));
 uint32_t pciaddr;
 uint16_t status;
 
 DPRINTF(bonito_spciconf_writew TARGET_FMT_plx val %x\n, addr, val);
-assert((addr0x1)==0);
+assert((addr  0x1) == 0);
 
 pciaddr = bonito_sbridge_pciaddr(s, addr);
 
@@ -475,24 

Re: [Qemu-devel] [PATCH 1/5] qom: adopt rwlock to protect accessing dev from removing it

2012-07-26 Thread Avi Kivity
On 07/26/2012 04:14 PM, liu ping fan wrote:

 From the description above, I don't see why it can't be a mutex.

 Searching in the device tree (or MemoryRegion view) can be often in
 parallel, especially in mmio-dispatch code path

In mmio dispatch we have a pointer to the object, we don't need to
search anything.  Is device tree search a hot path?


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





Re: [Qemu-devel] [PATCH v2 5/7] qcow2: implement lazy refcounts

2012-07-26 Thread Kevin Wolf
Am 25.07.2012 14:21, schrieb Stefan Hajnoczi:
 Lazy refcounts is a performance optimization for qcow2 that postpones
 refcount metadata updates and instead marks the image dirty.  In the
 case of crash or power failure the image will be left in a dirty state
 and repaired next time it is opened.
 
 Reducing metadata I/O is important for cache=writethrough and
 cache=directsync because these modes guarantee that data is on disk
 after each write (hence we cannot take advantage of caching updates in
 RAM).  Refcount metadata is not needed for guest-file block address
 translation and therefore does not need to be on-disk at the time of
 write completion - this is the motivation behind the lazy refcount
 optimization.
 
 The lazy refcount optimization must be enabled at image creation time:
 
   qemu-img create -f qcow2 -o compat=1.1,lazy_refcounts=on a.qcow2 10G
   qemu-system-x86_64 -drive if=virtio,file=a.qcow2,cache=writethrough
 
 Update qemu-iotests 031 and 036 since the extension header size changes
 when we add feature bit table entries.
 
 Signed-off-by: Stefan Hajnoczi stefa...@linux.vnet.ibm.com
 ---
  block/qcow2-cluster.c  |5 +++-
  block/qcow2.c  |   71 
 +---
  block/qcow2.h  |   13 
  block_int.h|   26 
  tests/qemu-iotests/031.out |   12 
  tests/qemu-iotests/036.out |2 +-
  6 files changed, 105 insertions(+), 24 deletions(-)
 
 diff --git a/block/qcow2-cluster.c b/block/qcow2-cluster.c
 index d7e0e19..e179211 100644
 --- a/block/qcow2-cluster.c
 +++ b/block/qcow2-cluster.c
 @@ -662,7 +662,10 @@ int qcow2_alloc_cluster_link_l2(BlockDriverState *bs, 
 QCowL2Meta *m)
  qcow2_cache_depends_on_flush(s-l2_table_cache);
  }
  
 -qcow2_cache_set_dependency(bs, s-l2_table_cache, 
 s-refcount_block_cache);
 +if (qcow2_need_accurate_refcounts(s)) {
 +qcow2_cache_set_dependency(bs, s-l2_table_cache,
 +   s-refcount_block_cache);
 +}
  ret = get_cluster_table(bs, m-offset, l2_table, l2_index);
  if (ret  0) {
  goto err;
 diff --git a/block/qcow2.c b/block/qcow2.c
 index 7fe1567..d48527f7 100644
 --- a/block/qcow2.c
 +++ b/block/qcow2.c
 @@ -215,6 +215,39 @@ static void report_unsupported_feature(BlockDriverState 
 *bs,
  }
  
  /*
 + * Sets the dirty bit and flushes afterwards if necessary.
 + *
 + * The incompatible_features bit is only set if the image file header was
 + * updated successfully.  Therefore it is not required to check the return
 + * value of this function.
 + */
 +static int qcow2_mark_dirty(BlockDriverState *bs)
 +{
 +BDRVQcowState *s = bs-opaque;
 +uint64_t val;
 +int ret;
 +
 +if (s-incompatible_features  QCOW2_INCOMPAT_DIRTY) {
 +return 0; /* already dirty */
 +}
 +
 +val = cpu_to_be64(s-incompatible_features | QCOW2_INCOMPAT_DIRTY);
 +ret = bdrv_pwrite(bs-file, offsetof(QCowHeader, incompatible_features),
 +  val, sizeof(val));

If you respin, I think would be nice to have either an assert(s-version
== 3) before writing to qcow3 header fields, or to use
qcow2_update_header() in the first place.

Kevin



Re: [Qemu-devel] [PATCH v5 6/6] block: Enable qemu_open/close to work with fd sets

2012-07-26 Thread Kevin Wolf
Am 26.07.2012 15:13, schrieb Eric Blake:
 On 07/25/2012 09:21 PM, Corey Bryant wrote:


 On 07/25/2012 03:25 PM, Eric Blake wrote:
 On 07/25/2012 02:22 AM, Kevin Wolf wrote:
 Hm, not a nice interface where qemu_close() needs the filename and
 (worse) could be given a wrong filename. Maybe it would be better to
 maintain a list of fd - fdset mappings in qemu_open/close?


 I agree, I don't really like it either.

 We already have a list of fd - fdset mappings (mon_fdset_fd_t -
 mon_fdset_t).  Would it be too costly to loop through all the
 fdsets/fds
 at the beginning of every qemu_close()?

 I don't think so. qemu_close() is not a fast path and happens almost
 never, and the list is short enough that searching it isn't a problem
 anyway.

 I agree - just do the loop to do the reverse lookup yourself, rather
 than making qemu_close() have a different signature than close().


 Great, I'll do this then.
 
 You may want an optimization of using a bitset for tracking which fds
 are tracked by fdset in the first place, so that the fast path of
 qemu_close() will be a check against the bitset to see if you even have
 to waste time on the reverse lookup in the first place.  The bitset will
 typically be small (bounded not only by the maximum possible fd, but
 further by the fact that we don't usually open that many fds in the
 first place), but I'm not sure if you can get away with static sizing.

Premature optimisation, in my opinion. The list is really small.

Kevin



[Qemu-devel] [PATCH V5 4/4] hmp: show the backing file depth

2012-07-26 Thread benoit . canet
From: Benoît Canet ben...@irqsave.net

Signed-off-by: Benoit Canet ben...@irqsave.net
---
 hmp.c |2 ++
 1 file changed, 2 insertions(+)

diff --git a/hmp.c b/hmp.c
index 6b72a64..25688ab 100644
--- a/hmp.c
+++ b/hmp.c
@@ -227,6 +227,8 @@ void hmp_info_block(Monitor *mon)
 if (info-value-inserted-has_backing_file) {
 monitor_printf(mon,  backing_file=);
 monitor_print_filename(mon, 
info-value-inserted-backing_file);
+monitor_printf(mon,  backing_file_depth=% PRId64,
+info-value-inserted-backing_file_depth);
 }
 monitor_printf(mon,  ro=%d drv=%s encrypted=%d,
info-value-inserted-ro,
-- 
1.7.9.5




[Qemu-devel] [PATCH V5 3/4] qmp: Add backing-file-depth to qmp-commands.hx

2012-07-26 Thread benoit . canet
From: Benoît Canet ben...@irqsave.net

Signed-off-by: Benoit Canet ben...@irqsave.net
---
 qmp-commands.hx |2 ++
 1 file changed, 2 insertions(+)

diff --git a/qmp-commands.hx b/qmp-commands.hx
index e3cf3c5..5de3adf 100644
--- a/qmp-commands.hx
+++ b/qmp-commands.hx
@@ -1317,6 +1317,7 @@ Each json-object contain the following:
 nbd, parallels, qcow, qcow2, raw,
 tftp, vdi, vmdk, vpc, vvfat
  - backing_file: backing file name (json-string, optional)
+ - backing-file-depth: number of files in the backing file chain 
(json-int)
  - encrypted: true if encrypted, false otherwise (json-bool)
  - bps: limit total bytes per second (json-int)
  - bps_rd: limit read bytes per second (json-int)
@@ -1345,6 +1346,7 @@ Example:
drv:qcow2,
encrypted:false,
file:disks/test.img,
+   backing-file-depth:0,
bps:100,
bps_rd:0,
bps_wr:0,
-- 
1.7.9.5




[Qemu-devel] [PATCH V5 0/4] Show backing file depth in HMP and QMP

2012-07-26 Thread benoit . canet
From: Benoît Canet ben...@irqsave.net

In some setups many backing files and snapshot are chained.
This lead to the formation of huge trees of snapshots all depending
on a common ancestor.

Hence if something bad happen to this common ancestor all the snapshot
of the tree will be broken.

This patch add an easy way for the user to monitor backing file depth
and take the good decision (streaming).

in v2:

lcapitulino: -Fix typo in qapi-schema.json
 -rename *file_ancestors_count to
  *backing_file_ancestor_count

in v3:

kwolf: qapi-schema.json backing_file_ancestor_count field not optional
   Add a (since 1.2) comment
   keep display in HMP optional

in v4:

eblake: rename backing_file.ancestors.count to backing.file.depth
in qapi-schema.json use - instead of _
Fix json docstring

in v5:

eblake: ditch completely the word ancestor in comment
Add the corresponding patch to qmp-commands.hx

Benoît Canet (4):
  block: create bdrv_get_backing_file_depth()
  block: Use bdrv_get_backing_file_depth()
  qmp: Add backing-file-depth to qmp-commands.hx
  hmp: show the backing file depth

 block.c  |   16 
 block.h  |1 +
 hmp.c|2 ++
 qapi-schema.json |9 ++---
 qmp-commands.hx  |2 ++
 5 files changed, 27 insertions(+), 3 deletions(-)

-- 
1.7.9.5




[Qemu-devel] [PATCH V5 2/4] block: Use bdrv_get_backing_file_depth()

2012-07-26 Thread benoit . canet
From: Benoît Canet ben...@irqsave.net

Use the dedicated counting function in qmp_query_block in order to
propagate the backing file depth to HMP.

Signed-off-by: Benoit Canet ben...@irqsave.net
---
 block.c  |3 +++
 qapi-schema.json |9 ++---
 2 files changed, 9 insertions(+), 3 deletions(-)

diff --git a/block.c b/block.c
index 22ebe49..a6fba1d 100644
--- a/block.c
+++ b/block.c
@@ -2450,6 +2450,9 @@ BlockInfoList *qmp_query_block(Error **errp)
 info-value-inserted-backing_file = 
g_strdup(bs-backing_file);
 }
 
+info-value-inserted-backing_file_depth =
+bdrv_get_backing_file_depth(bs);
+
 if (bs-io_limits_enabled) {
 info-value-inserted-bps =
bs-io_limits.bps[BLOCK_IO_LIMIT_TOTAL];
diff --git a/qapi-schema.json b/qapi-schema.json
index a92adb1..2b50f22 100644
--- a/qapi-schema.json
+++ b/qapi-schema.json
@@ -398,6 +398,8 @@
 #
 # @backing_file: #optional the name of the backing file (for copy-on-write)
 #
+# @backing_file_depth: number of files in the backing file chain (since: 1.2)
+#
 # @encrypted: true if the backing device is encrypted
 #
 # @bps: total throughput limit in bytes per second is specified
@@ -418,9 +420,10 @@
 ##
 { 'type': 'BlockDeviceInfo',
   'data': { 'file': 'str', 'ro': 'bool', 'drv': 'str',
-'*backing_file': 'str', 'encrypted': 'bool',
-'bps': 'int', 'bps_rd': 'int', 'bps_wr': 'int',
-'iops': 'int', 'iops_rd': 'int', 'iops_wr': 'int'} }
+'*backing_file': 'str', 'backing-file-depth': 'int',
+'encrypted': 'bool', 'bps': 'int', 'bps_rd': 'int',
+'bps_wr': 'int', 'iops': 'int', 'iops_rd': 'int',
+'iops_wr': 'int'} }
 
 ##
 # @BlockDeviceIoStatus:
-- 
1.7.9.5




[Qemu-devel] [PATCH V5 1/4] block: create bdrv_get_backing_file_depth()

2012-07-26 Thread benoit . canet
From: Benoît Canet ben...@irqsave.net

Create bdrv_get_backing_file_depth() in order to be able to show
in QMP and HMP how many ancestors backing an image a block device
have.

Signed-off-by: Benoit Canet ben...@irqsave.net
---
 block.c |   13 +
 block.h |1 +
 2 files changed, 14 insertions(+)

diff --git a/block.c b/block.c
index ce7eb8f..22ebe49 100644
--- a/block.c
+++ b/block.c
@@ -2754,6 +2754,19 @@ BlockDriverState 
*bdrv_find_backing_image(BlockDriverState *bs,
 return NULL;
 }
 
+int bdrv_get_backing_file_depth(BlockDriverState *bs)
+{
+if (!bs-drv) {
+return 0;
+}
+
+if (!bs-backing_hd) {
+return 0;
+}
+
+return 1 + bdrv_get_backing_file_depth(bs-backing_hd);
+}
+
 #define NB_SUFFIXES 4
 
 char *get_human_readable_size(char *buf, int buf_size, int64_t size)
diff --git a/block.h b/block.h
index c89590d..650d872 100644
--- a/block.h
+++ b/block.h
@@ -174,6 +174,7 @@ int coroutine_fn 
bdrv_co_is_allocated_above(BlockDriverState *top,
 int nb_sectors, int *pnum);
 BlockDriverState *bdrv_find_backing_image(BlockDriverState *bs,
 const char *backing_file);
+int bdrv_get_backing_file_depth(BlockDriverState *bs);
 int bdrv_truncate(BlockDriverState *bs, int64_t offset);
 int64_t bdrv_getlength(BlockDriverState *bs);
 int64_t bdrv_get_allocated_file_size(BlockDriverState *bs);
-- 
1.7.9.5




[Qemu-devel] [PATCH v4 02/18] alpha_typhoon: QOM'ify Typhoon PCI host bridge

2012-07-26 Thread Andreas Färber
Introduce type constant and cast macro. Don't access DeviceState
indirectly through parent fields.

Signed-off-by: Andreas Färber afaer...@suse.de
---
 hw/alpha_typhoon.c |   16 ++--
 1 files changed, 10 insertions(+), 6 deletions(-)

diff --git a/hw/alpha_typhoon.c b/hw/alpha_typhoon.c
index cc63737..06e84a1 100644
--- a/hw/alpha_typhoon.c
+++ b/hw/alpha_typhoon.c
@@ -15,6 +15,8 @@
 #include exec-memory.h
 
 
+#define TYPE_TYPHOON_PCI_HOST_BRIDGE typhoon-pcihost
+
 typedef struct TyphoonCchip {
 MemoryRegion region;
 uint64_t misc;
@@ -40,8 +42,12 @@ typedef struct TyphoonPchip {
 TyphoonWindow win[4];
 } TyphoonPchip;
 
+#define TYPHOON_PCI_HOST_BRIDGE(obj) \
+OBJECT_CHECK(TyphoonState, (obj), TYPE_TYPHOON_PCI_HOST_BRIDGE)
+
 typedef struct TyphoonState {
 PCIHostState host;
+
 TyphoonCchip cchip;
 TyphoonPchip pchip;
 MemoryRegion dchip_region;
@@ -700,16 +706,14 @@ PCIBus *typhoon_init(ram_addr_t ram_size, ISABus 
**isa_bus,
 MemoryRegion *addr_space = get_system_memory();
 MemoryRegion *addr_space_io = get_system_io();
 DeviceState *dev;
-PCIHostState *p;
 TyphoonState *s;
 PCIBus *b;
 int i;
 
-dev = qdev_create(NULL, typhoon-pcihost);
+dev = qdev_create(NULL, TYPE_TYPHOON_PCI_HOST_BRIDGE);
 qdev_init_nofail(dev);
 
-p = FROM_SYSBUS(PCIHostState, sysbus_from_qdev(dev));
-s = container_of(p, TyphoonState, host);
+s = TYPHOON_PCI_HOST_BRIDGE(dev);
 
 /* Remember the CPUs so that we can deliver interrupts to them.  */
 for (i = 0; i  4; i++) {
@@ -763,7 +767,7 @@ PCIBus *typhoon_init(ram_addr_t ram_size, ISABus **isa_bus,
 memory_region_add_subregion(addr_space, 0x801fc00ULL,
 s-pchip.reg_io);
 
-b = pci_register_bus(s-host.busdev.qdev, pci,
+b = pci_register_bus(dev, pci,
  typhoon_set_irq, sys_map_irq, s,
  s-pchip.reg_mem, addr_space_io, 0, 64);
 s-host.bus = b;
@@ -818,7 +822,7 @@ static void typhoon_pcihost_class_init(ObjectClass *klass, 
void *data)
 }
 
 static const TypeInfo typhoon_pcihost_info = {
-.name  = typhoon-pcihost,
+.name  = TYPE_TYPHOON_PCI_HOST_BRIDGE,
 .parent= TYPE_SYS_BUS_DEVICE,
 .instance_size = sizeof(TyphoonState),
 .class_init= typhoon_pcihost_class_init,
-- 
1.7.7




Re: [Qemu-devel] [PATCH 02/27] split MRU ram list

2012-07-26 Thread Avi Kivity
On 07/25/2012 11:20 PM, Michael Roth wrote:
 On Tue, Jul 24, 2012 at 08:36:27PM +0200, Juan Quintela wrote:
 From: Paolo Bonzini pbonz...@redhat.com
 
 Outside the execution threads the normal, non-MRU-ized order of
 the RAM blocks should always be enough.  So manage two separate
 lists, which will have separate locking rules.
 
 One thing I'm noticing is that, prior to this series, we're traversing the
 blocks in MRU order for migration. This seems counter-intuitive, as those are
 the blocks most likely to get re-dirtied and re-sent, so it make sense to hold
 off on sending those till last to reduce the amount of time the running guest
 has to invalidate the target's copy of it.
 
 This isn't as bad as it could be, since we at least don't restart the
 loop on every iteration, but it might still make sense to come up with a way
 to keep RAMList.blocks roughly in sync with RAMList.blocks_mru, and then
 traverse that in reverse order for ram_save_iterate. The fact that we're
 switching from the MRU ordering in the current version might be
 obscuring performance issues as well, which is probably worth keeping in
 mind.
 

Main memory is the only ram block which matters (the framebuffer a
remote second).  The others are ROMs.

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





Re: [Qemu-devel] [PATCH 1/5] qom: adopt rwlock to protect accessing dev from removing it

2012-07-26 Thread liu ping fan
On Thu, Jul 26, 2012 at 9:15 PM, Avi Kivity a...@redhat.com wrote:
 On 07/26/2012 04:14 PM, liu ping fan wrote:

 From the description above, I don't see why it can't be a mutex.

 Searching in the device tree (or MemoryRegion view) can be often in
 parallel, especially in mmio-dispatch code path

 In mmio dispatch we have a pointer to the object, we don't need to
 search anything.  Is device tree search a hot path?

I think, we need lock to protect searching --phys_page_find()  from
deleter--DeviceClass:unmap,  so rwlock?

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





[Qemu-devel] [PATCH v4 11/18] unin_pci: QOM'ify UniNorth PCI host bridges

2012-07-26 Thread Andreas Färber
Introduce type constants and cast macros.
Avoid accessing parent fields directly.

Signed-off-by: Andreas Färber afaer...@suse.de
---
 hw/unin_pci.c |  133 ++---
 1 files changed, 70 insertions(+), 63 deletions(-)

diff --git a/hw/unin_pci.c b/hw/unin_pci.c
index 2b309df..1fc8920 100644
--- a/hw/unin_pci.c
+++ b/hw/unin_pci.c
@@ -38,8 +38,23 @@
 
 static const int unin_irq_line[] = { 0x1b, 0x1c, 0x1d, 0x1e };
 
+#define TYPE_UNI_NORTH_PCI_HOST_BRIDGE uni-north-pci-pcihost
+#define TYPE_UNI_NORTH_AGP_HOST_BRIDGE uni-north-agp-pcihost
+#define TYPE_UNI_NORTH_INTERNAL_PCI_HOST_BRIDGE 
uni-north-internal-pci-pcihost
+#define TYPE_U3_AGP_HOST_BRIDGE u3-agp-pcihost
+
+#define UNI_NORTH_PCI_HOST_BRIDGE(obj) \
+OBJECT_CHECK(UNINState, (obj), TYPE_UNI_NORTH_PCI_HOST_BRIDGE)
+#define UNI_NORTH_AGP_HOST_BRIDGE(obj) \
+OBJECT_CHECK(UNINState, (obj), TYPE_UNI_NORTH_AGP_HOST_BRIDGE)
+#define UNI_NORTH_INTERNAL_PCI_HOST_BRIDGE(obj) \
+OBJECT_CHECK(UNINState, (obj), TYPE_UNI_NORTH_INTERNAL_PCI_HOST_BRIDGE)
+#define U3_AGP_HOST_BRIDGE(obj) \
+OBJECT_CHECK(UNINState, (obj), TYPE_U3_AGP_HOST_BRIDGE)
+
 typedef struct UNINState {
 PCIHostState host_state;
+
 MemoryRegion pci_mmio;
 MemoryRegion pci_hole;
 } UNINState;
@@ -130,19 +145,17 @@ static const MemoryRegionOps unin_data_ops = {
 static int pci_unin_main_init_device(SysBusDevice *dev)
 {
 PCIHostState *h;
-UNINState *s;
 
 /* Use values found on a real PowerMac */
 /* Uninorth main bus */
 h = FROM_SYSBUS(PCIHostState, dev);
-s = DO_UPCAST(UNINState, host_state, h);
 
-memory_region_init_io(s-host_state.conf_mem, pci_host_conf_le_ops,
-  s-host_state, pci-conf-idx, 0x1000);
-memory_region_init_io(s-host_state.data_mem, unin_data_ops, s,
+memory_region_init_io(h-conf_mem, pci_host_conf_le_ops,
+  dev, pci-conf-idx, 0x1000);
+memory_region_init_io(h-data_mem, unin_data_ops, dev,
   pci-conf-data, 0x1000);
-sysbus_init_mmio(dev, s-host_state.conf_mem);
-sysbus_init_mmio(dev, s-host_state.data_mem);
+sysbus_init_mmio(dev, h-conf_mem);
+sysbus_init_mmio(dev, h-data_mem);
 
 return 0;
 }
@@ -151,18 +164,16 @@ static int pci_unin_main_init_device(SysBusDevice *dev)
 static int pci_u3_agp_init_device(SysBusDevice *dev)
 {
 PCIHostState *h;
-UNINState *s;
 
 /* Uninorth U3 AGP bus */
 h = FROM_SYSBUS(PCIHostState, dev);
-s = DO_UPCAST(UNINState, host_state, h);
 
-memory_region_init_io(s-host_state.conf_mem, pci_host_conf_le_ops,
-  s-host_state, pci-conf-idx, 0x1000);
-memory_region_init_io(s-host_state.data_mem, unin_data_ops, s,
+memory_region_init_io(h-conf_mem, pci_host_conf_le_ops,
+  dev, pci-conf-idx, 0x1000);
+memory_region_init_io(h-data_mem, unin_data_ops, dev,
   pci-conf-data, 0x1000);
-sysbus_init_mmio(dev, s-host_state.conf_mem);
-sysbus_init_mmio(dev, s-host_state.data_mem);
+sysbus_init_mmio(dev, h-conf_mem);
+sysbus_init_mmio(dev, h-data_mem);
 
 return 0;
 }
@@ -170,36 +181,32 @@ static int pci_u3_agp_init_device(SysBusDevice *dev)
 static int pci_unin_agp_init_device(SysBusDevice *dev)
 {
 PCIHostState *h;
-UNINState *s;
 
 /* Uninorth AGP bus */
 h = FROM_SYSBUS(PCIHostState, dev);
-s = DO_UPCAST(UNINState, host_state, h);
 
-memory_region_init_io(s-host_state.conf_mem, pci_host_conf_le_ops,
-  s-host_state, pci-conf-idx, 0x1000);
-memory_region_init_io(s-host_state.data_mem, pci_host_data_le_ops,
-  s-host_state, pci-conf-data, 0x1000);
-sysbus_init_mmio(dev, s-host_state.conf_mem);
-sysbus_init_mmio(dev, s-host_state.data_mem);
+memory_region_init_io(h-conf_mem, pci_host_conf_le_ops,
+  dev, pci-conf-idx, 0x1000);
+memory_region_init_io(h-data_mem, pci_host_data_le_ops,
+  dev, pci-conf-data, 0x1000);
+sysbus_init_mmio(dev, h-conf_mem);
+sysbus_init_mmio(dev, h-data_mem);
 return 0;
 }
 
 static int pci_unin_internal_init_device(SysBusDevice *dev)
 {
 PCIHostState *h;
-UNINState *s;
 
 /* Uninorth internal bus */
 h = FROM_SYSBUS(PCIHostState, dev);
-s = DO_UPCAST(UNINState, host_state, h);
 
-memory_region_init_io(s-host_state.conf_mem, pci_host_conf_le_ops,
-  s-host_state, pci-conf-idx, 0x1000);
-memory_region_init_io(s-host_state.data_mem, pci_host_data_le_ops,
-  s-host_state, pci-conf-data, 0x1000);
-sysbus_init_mmio(dev, s-host_state.conf_mem);
-sysbus_init_mmio(dev, s-host_state.data_mem);
+memory_region_init_io(h-conf_mem, pci_host_conf_le_ops,
+  dev, pci-conf-idx, 0x1000);
+memory_region_init_io(h-data_mem, pci_host_data_le_ops,
+  

[Qemu-devel] [PATCH RFC v4 16/18] MAINTAINERS: Document e500 machine

2012-07-26 Thread Andreas Färber
Will need to be updated for the upcoming file reorganization.

Signed-off-by: Andreas Färber afaer...@suse.de
Cc: Alexander Graf ag...@suse.de
Cc: Scott Wood scottw...@freescale.com
---
 MAINTAINERS |7 +++
 1 files changed, 7 insertions(+), 0 deletions(-)

diff --git a/MAINTAINERS b/MAINTAINERS
index 282d497..1796421 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -381,6 +381,13 @@ L: qemu-...@nongnu.org
 S: Supported
 F: hw/spapr*
 
+e500
+M: Alexander Graf ag...@suse.de
+M: Scott Wood scottw...@freescale.com
+L: qemu-...@nongnu.org
+S: Supported
+F: hw/ppce500_*
+
 SH4 Machines
 
 R2D
-- 
1.7.7




[Qemu-devel] [PATCH v4 12/18] pci_host: Turn into SysBus-derived QOM type

2012-07-26 Thread Andreas Färber
From: Andreas Färber andreas.faer...@web.de

The preceding commits fixed misuses of FROM_SYSBUS() that led people to
add a bogus busdev field. For qdev the field order was less relevant but
for QOM the PCIHostState field (including the SysBusDevice actually
initialized with a value) must be placed first within the state struct.

To facilitate accessing the PCIHostState fields, derive all PCI host
bridges from TYPE_PCI_HOST_BRIDGE rather than TYPE_SYS_BUS_DEVICE.

We can now access PCIHostState QOM-style, with PCI_HOST_BRIDGE() macro.

Signed-off-by: Anthony Liguori aligu...@us.ibm.com
Signed-off-by: Wanpeng Li l...@linux.vnet.ibm.com
Signed-off-by: Andreas Färber andreas.faer...@web.de
Signed-off-by: Andreas Färber afaer...@suse.de
---
 hw/pci_host.c |   12 
 hw/pci_host.h |5 +
 2 files changed, 17 insertions(+), 0 deletions(-)

diff --git a/hw/pci_host.c b/hw/pci_host.c
index 8041778..3950e94 100644
--- a/hw/pci_host.c
+++ b/hw/pci_host.c
@@ -165,4 +165,16 @@ const MemoryRegionOps pci_host_data_be_ops = {
 .endianness = DEVICE_BIG_ENDIAN,
 };
 
+static const TypeInfo pci_host_type_info = {
+.name = TYPE_PCI_HOST_BRIDGE,
+.parent = TYPE_SYS_BUS_DEVICE,
+.abstract = true,
+.instance_size = sizeof(PCIHostState),
+};
+
+static void pci_host_register_types(void)
+{
+type_register_static(pci_host_type_info);
+}
 
+type_init(pci_host_register_types)
diff --git a/hw/pci_host.h b/hw/pci_host.h
index 359e38f..4b9c300 100644
--- a/hw/pci_host.h
+++ b/hw/pci_host.h
@@ -30,8 +30,13 @@
 
 #include sysbus.h
 
+#define TYPE_PCI_HOST_BRIDGE pci-host-bridge
+#define PCI_HOST_BRIDGE(obj) \
+OBJECT_CHECK(PCIHostState, (obj), TYPE_PCI_HOST_BRIDGE)
+
 struct PCIHostState {
 SysBusDevice busdev;
+
 MemoryRegion conf_mem;
 MemoryRegion data_mem;
 MemoryRegion mmcfg;
-- 
1.7.7




Re: [Qemu-devel] [PATCH v2 7/7] qemu-iotests: add 039 qcow2 lazy refcounts test

2012-07-26 Thread Kevin Wolf
Am 25.07.2012 14:21, schrieb Stefan Hajnoczi:
 This tests establishes the basic post-conditions of the qcow2 lazy
 refcounts features:
 
   1. If the image was closed normally, it is marked clean.
 
   2. If an allocating write was performed and the image was not close
  normally, then it is marked dirty.
 
  a. Written data can be read back successfully.
  b. The image file can be repaired and will be marked clean again.
 
 Signed-off-by: Stefan Hajnoczi stefa...@linux.vnet.ibm.com

I think an important case that is missing here is opening a dirty image
rw without having run qemu-img check -r first.

 +== Read-only access must still work ==
 +read 512/512 bytes at offset 0
 +512 bytes, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec)
 +incompatible_features 0x1
 +
 +== Repairing the image file must succeed ==
 +ERROR OFLAG_COPIED: offset=8005 refcount=0
 +Repairing cluster 5 refcount=0 reference=1
 +No errors were found on the image.
 +incompatible_features 0x0

I wonder what happened to the The following inconsistencies were found
and repaired message. Most likely not a problem with qemu-iotests,
though, but something unexpected in qemu-img.

Kevin



[Qemu-devel] [PATCH v4 00/18] pci_host: Convert to QOM

2012-07-26 Thread Andreas Färber
Hello Anthony,

As requested on the KVM call, here's a resend of the series making pci_host
a first-class QOM type.

In order to cc all relevant parties I have appended some patches adding
MAINTAINERS entries for the ppc devices touched herein. Those should only be
applied with the respective proposed maintainers' consent but are obviously
independent of applying the actual preceding patches.

This series is a prerequisite for the i440fx refactoring and q35 introduction.

mst's pci PULL no longer applied, so this is still based on master and will
require a trivial modification to Jan's patch that adds a PCI bus parameter.

Regards,
Andreas

Cc: Anthony Liguori anth...@codemonkey.ws
Cc: Wanpeng Li liw...@linux.vnet.ibm.com
Cc: Jason Baron jba...@redhat.com

Cc: Michael S. Tsirkin m...@redhat.com
Cc: Jan Kiszka jan.kis...@siemens.com

v3 - v4:
* Moved spapr_pci.c:register_types() rename to later dedicated spapr_pci patch.
* Added proposed patches for related MAINTAINERS machine entries w/ PHB files.
Anthony requested the QOM cast discussion to be held elsewhere, so no change.

v2 - v3:
* Renamed PCI_HOST to PCI_HOST_BRIDGE, suggested by mst.
* Split off const changes to clarify the name/parent changes.
* Split off cleanups per host bridge.
* Prepared and enforced QOM-style field access through explicit types.

v1 - v2:
* Converted remaining PCI host bridges to new type.

Andreas Färber (18):
  pci: Make host bridge TypeInfos const
  alpha_typhoon: QOM'ify Typhoon PCI host bridge
  bonito: QOM'ify Bonito PCI host bridge
  dec_pci: QOM'ify DEC 21154 PCI-PCI bridge
  grackle_pci: QOM'ify Grackle PCI host bridge
  gt64xxx: QOM'ify GT64120 PCI host bridge
  ppc4xx_pci: QOM'ify ppc4xx PCI host bridge
  ppce500_pci: QOM'ify e500 PCI host bridge
  prep_pci: QOM'ify Raven PCI host bridge
  spapr_pci: QOM'ify sPAPR PCI host bridge
  unin_pci: QOM'ify UniNorth PCI host bridges
  pci_host: Turn into SysBus-derived QOM type
  pci: Derive PCI host bridges from TYPE_PCI_HOST_BRIDGE
  pci: Tidy up PCI host bridges
  MAINTAINERS: Document sPAPR (pSeries) machine
  MAINTAINERS: Document e500 machine
  MAINTAINERS: Document Bamboo machine
  MAINTAINERS: Document virtex_ml507 machine

 MAINTAINERS|   27 
 hw/alpha_typhoon.c |   24 ---
 hw/bonito.c|  152 ++-
 hw/dec_pci.c   |   31 +
 hw/dec_pci.h   |2 +
 hw/grackle_pci.c   |   65 +-
 hw/gt64xxx.c   |   67 +++
 hw/pci_host.c  |   12 
 hw/pci_host.h  |5 ++
 hw/piix_pci.c  |   22 ---
 hw/ppc440_bamboo.c |3 +-
 hw/ppc4xx.h|2 +
 hw/ppc4xx_pci.c|   27 +---
 hw/ppc_mac.h   |1 +
 hw/ppc_prep.c  |4 +-
 hw/ppce500_pci.c   |   24 ---
 hw/prep_pci.c  |   33 ++
 hw/spapr_pci.c |   29 +
 hw/spapr_pci.h |8 ++-
 hw/unin_pci.c  |  183 +++-
 20 files changed, 427 insertions(+), 294 deletions(-)

-- 
1.7.7




[Qemu-devel] [PATCH v4 04/18] dec_pci: QOM'ify DEC 21154 PCI-PCI bridge

2012-07-26 Thread Andreas Färber
Introduce type constant. Introduce cast macro and drop dummy busdev
field used with FROM_SYSBUS() that would've broken SYS_BUS_DEVICE().
Avoid accessing parent fields directly.

Signed-off-by: Andreas Färber afaer...@suse.de
---
 hw/dec_pci.c |   21 +++--
 hw/dec_pci.h |2 ++
 2 files changed, 13 insertions(+), 10 deletions(-)

diff --git a/hw/dec_pci.c b/hw/dec_pci.c
index 5194a9f..19aed1b 100644
--- a/hw/dec_pci.c
+++ b/hw/dec_pci.c
@@ -40,8 +40,9 @@
 #define DEC_DPRINTF(fmt, ...)
 #endif
 
+#define DEC_21154(obj) OBJECT_CHECK(DECState, (obj), TYPE_DEC_21154)
+
 typedef struct DECState {
-SysBusDevice busdev;
 PCIHostState host_state;
 } DECState;
 
@@ -88,16 +89,16 @@ PCIBus *pci_dec_21154_init(PCIBus *parent_bus, int devfn)
 
 static int pci_dec_21154_device_init(SysBusDevice *dev)
 {
-DECState *s;
+PCIHostState *phb;
 
-s = FROM_SYSBUS(DECState, dev);
+phb = FROM_SYSBUS(PCIHostState, dev);
 
-memory_region_init_io(s-host_state.conf_mem, pci_host_conf_le_ops,
-  s-host_state, pci-conf-idx, 0x1000);
-memory_region_init_io(s-host_state.data_mem, pci_host_data_le_ops,
-  s-host_state, pci-data-idx, 0x1000);
-sysbus_init_mmio(dev, s-host_state.conf_mem);
-sysbus_init_mmio(dev, s-host_state.data_mem);
+memory_region_init_io(phb-conf_mem, pci_host_conf_le_ops,
+  dev, pci-conf-idx, 0x1000);
+memory_region_init_io(phb-data_mem, pci_host_data_le_ops,
+  dev, pci-data-idx, 0x1000);
+sysbus_init_mmio(dev, phb-conf_mem);
+sysbus_init_mmio(dev, phb-data_mem);
 return 0;
 }
 
@@ -134,7 +135,7 @@ static void pci_dec_21154_device_class_init(ObjectClass 
*klass, void *data)
 }
 
 static const TypeInfo pci_dec_21154_device_info = {
-.name  = dec-21154-sysbus,
+.name  = TYPE_DEC_21154,
 .parent= TYPE_SYS_BUS_DEVICE,
 .instance_size = sizeof(DECState),
 .class_init= pci_dec_21154_device_class_init,
diff --git a/hw/dec_pci.h b/hw/dec_pci.h
index 79264ba..17dc0c2 100644
--- a/hw/dec_pci.h
+++ b/hw/dec_pci.h
@@ -3,6 +3,8 @@
 
 #include qemu-common.h
 
+#define TYPE_DEC_21154 dec-21154-sysbus
+
 PCIBus *pci_dec_21154_init(PCIBus *parent_bus, int devfn);
 
 #endif
-- 
1.7.7




[Qemu-devel] [PATCH v4 10/18] spapr_pci: QOM'ify sPAPR PCI host bridge

2012-07-26 Thread Andreas Färber
Introduce type constant. Introduce cast macro to drop bogus busdev field
that would've broken SYS_BUS_DEVICE().

Signed-off-by: Andreas Färber afaer...@suse.de
Reviewed-by: Anthony Liguori aligu...@us.ibm.com
[AF: Moved type_init function rename here]
---
 hw/spapr_pci.c |   13 +++--
 hw/spapr_pci.h |6 +-
 2 files changed, 12 insertions(+), 7 deletions(-)

diff --git a/hw/spapr_pci.c b/hw/spapr_pci.c
index b901d34..17cdbbd 100644
--- a/hw/spapr_pci.c
+++ b/hw/spapr_pci.c
@@ -276,7 +276,7 @@ static DMAContext *spapr_pci_dma_context_fn(PCIBus *bus, 
void *opaque,
 
 static int spapr_phb_init(SysBusDevice *s)
 {
-sPAPRPHBState *phb = FROM_SYSBUS(sPAPRPHBState, s);
+sPAPRPHBState *phb = SPAPR_PCI_HOST_BRIDGE(s);
 char *namebuf;
 int i;
 PCIBus *bus;
@@ -314,7 +314,7 @@ static int spapr_phb_init(SysBusDevice *s)
 memory_region_add_subregion(get_system_memory(), phb-io_win_addr,
 phb-iowindow);
 
-bus = pci_register_bus(phb-busdev.qdev,
+bus = pci_register_bus(DEVICE(s),
phb-busname ? phb-busname : phb-dtbusname,
pci_spapr_set_irq, pci_spapr_map_irq, phb,
phb-memspace, phb-iospace,
@@ -369,7 +369,7 @@ static void spapr_phb_class_init(ObjectClass *klass, void 
*data)
 }
 
 static const TypeInfo spapr_phb_info = {
-.name  = spapr-pci-host-bridge,
+.name  = TYPE_SPAPR_PCI_HOST_BRIDGE,
 .parent= TYPE_SYS_BUS_DEVICE,
 .instance_size = sizeof(sPAPRPHBState),
 .class_init= spapr_phb_class_init,
@@ -382,7 +382,7 @@ void spapr_create_phb(sPAPREnvironment *spapr,
 {
 DeviceState *dev;
 
-dev = qdev_create(NULL, spapr_phb_info.name);
+dev = qdev_create(NULL, TYPE_SPAPR_PCI_HOST_BRIDGE);
 
 if (busname) {
 qdev_prop_set_string(dev, busname, g_strdup(busname));
@@ -490,8 +490,9 @@ int spapr_populate_pci_devices(sPAPRPHBState *phb,
 return 0;
 }
 
-static void register_types(void)
+static void spapr_pci_register_types(void)
 {
 type_register_static(spapr_phb_info);
 }
-type_init(register_types)
+
+type_init(spapr_pci_register_types)
diff --git a/hw/spapr_pci.h b/hw/spapr_pci.h
index d9e46e2..06e2742 100644
--- a/hw/spapr_pci.h
+++ b/hw/spapr_pci.h
@@ -27,8 +27,12 @@
 #include hw/pci_host.h
 #include hw/xics.h
 
+#define TYPE_SPAPR_PCI_HOST_BRIDGE spapr-pci-host-bridge
+
+#define SPAPR_PCI_HOST_BRIDGE(obj) \
+OBJECT_CHECK(sPAPRPHBState, (obj), TYPE_SPAPR_PCI_HOST_BRIDGE)
+
 typedef struct sPAPRPHBState {
-SysBusDevice busdev;
 PCIHostState host_state;
 
 uint64_t buid;
-- 
1.7.7




Re: [Qemu-devel] [PATCH V5 0/4] Show backing file depth in HMP and QMP

2012-07-26 Thread Eric Blake
On 07/26/2012 07:18 AM, benoit.ca...@gmail.com wrote:
 From: Benoît Canet ben...@irqsave.net
 
 In some setups many backing files and snapshot are chained.
 This lead to the formation of huge trees of snapshots all depending
 on a common ancestor.
 
 Hence if something bad happen to this common ancestor all the snapshot
 of the tree will be broken.
 
 This patch add an easy way for the user to monitor backing file depth
 and take the good decision (streaming).
 
 
 in v5:
 
 eblake: ditch completely the word ancestor in comment
 Add the corresponding patch to qmp-commands.hx

Series:
Reviewed-by: Eric Blake ebl...@redhat.com

-- 
Eric Blake   ebl...@redhat.com+1-919-301-3266
Libvirt virtualization library http://libvirt.org



signature.asc
Description: OpenPGP digital signature


[Qemu-devel] [PATCH RFC v4 17/18] MAINTAINERS: Document Bamboo machine

2012-07-26 Thread Andreas Färber
Place it close to ppc405 due to ppc4xx code sharing.

Signed-off-by: Andreas Färber afaer...@suse.de
Cc: Alexander Graf ag...@suse.de
---
 MAINTAINERS |7 +++
 1 files changed, 7 insertions(+), 0 deletions(-)

diff --git a/MAINTAINERS b/MAINTAINERS
index 1796421..00fb0fa 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -352,6 +352,13 @@ L: qemu-...@nongnu.org
 S: Maintained
 F: hw/ppc405_boards.c
 
+Bamboo
+M: Alexander Graf ag...@suse.de
+L: qemu-...@nongnu.org
+S: Odd Fixes
+F: hw/ppc440_bamboo.c
+F: hw/ppc4xx_pci.c
+
 New World
 M: Alexander Graf ag...@suse.de
 L: qemu-...@nongnu.org
-- 
1.7.7




Re: [Qemu-devel] [PATCH] ide scsi: Mess with geometry only for hard disk devices

2012-07-26 Thread Kevin Wolf
Am 23.07.2012 12:03, schrieb Paolo Bonzini:
 Il 23/07/2012 09:25, Markus Armbruster ha scritto:
 Ping?

 Markus Armbruster arm...@redhat.com writes:

 Legacy -drive cyls=... are now ignored completely when the drive
 doesn't back a hard disk device.  Before, they were first checked
 against a hard disk's limits, then ignored.

 Signed-off-by: Markus Armbruster arm...@redhat.com
 ---
  hw/ide/qdev.c  |3 ++-
  hw/scsi-disk.c |3 ++-
  2 files changed, 4 insertions(+), 2 deletions(-)

 diff --git a/hw/ide/qdev.c b/hw/ide/qdev.c
 index 22e58df..5ea9b8f 100644
 --- a/hw/ide/qdev.c
 +++ b/hw/ide/qdev.c
 @@ -149,7 +149,8 @@ static int ide_dev_initfn(IDEDevice *dev, IDEDriveKind 
 kind)
  }
  
  blkconf_serial(dev-conf, dev-serial);
 -if (blkconf_geometry(dev-conf, dev-chs_trans, 65536, 16, 255)  0) 
 {
 +if (kind != IDE_CD
 + blkconf_geometry(dev-conf, dev-chs_trans, 65536, 16, 255)  
 0) {
  return -1;
  }
  
 diff --git a/hw/scsi-disk.c b/hw/scsi-disk.c
 index 525816c..318318c 100644
 --- a/hw/scsi-disk.c
 +++ b/hw/scsi-disk.c
 @@ -1750,7 +1750,8 @@ static int scsi_initfn(SCSIDevice *dev)
  }
  
  blkconf_serial(s-qdev.conf, s-serial);
 -if (blkconf_geometry(dev-conf, NULL, 65535, 255, 255)  0) {
 +if (dev-type == TYPE_DISK
 + blkconf_geometry(dev-conf, NULL, 65535, 255, 255)  0) {
  return -1;
  }


 
 Acked-by: Paolo Bonzini pbonz...@redhat.com
 
 Kevin, are you taking this patch?

Thanks, applied to the block branch.

Kevin



[Qemu-devel] [PATCH v4 09/18] prep_pci: QOM'ify Raven PCI host bridge

2012-07-26 Thread Andreas Färber
Introduce type constant and cast macro. Avoid accessing parent fields
directly.

Also add missing space and braces.

Signed-off-by: Andreas Färber afaer...@suse.de
---
 hw/prep_pci.c |   17 -
 1 files changed, 12 insertions(+), 5 deletions(-)

diff --git a/hw/prep_pci.c b/hw/prep_pci.c
index a8cdc21..69c19df 100644
--- a/hw/prep_pci.c
+++ b/hw/prep_pci.c
@@ -28,8 +28,14 @@
 #include pc.h
 #include exec-memory.h
 
+#define TYPE_RAVEN_PCI_HOST_BRIDGE raven-pcihost
+
+#define RAVEN_PCI_HOST_BRIDGE(obj) \
+OBJECT_CHECK(PREPPCIState, (obj), TYPE_RAVEN_PCI_HOST_BRIDGE)
+
 typedef struct PRePPCIState {
 PCIHostState host_state;
+
 MemoryRegion intack;
 qemu_irq irq[4];
 } PREPPCIState;
@@ -42,9 +48,10 @@ static inline uint32_t PPC_PCIIO_config(target_phys_addr_t 
addr)
 {
 int i;
 
-for(i = 0; i  11; i++) {
-if ((addr  (1  (11 + i))) != 0)
+for (i = 0; i  11; i++) {
+if ((addr  (1  (11 + i))) != 0) {
 break;
+}
 }
 return (addr  0x7ff) |  (i  11);
 }
@@ -97,7 +104,7 @@ static void prep_set_irq(void *opaque, int irq_num, int 
level)
 static int raven_pcihost_init(SysBusDevice *dev)
 {
 PCIHostState *h = FROM_SYSBUS(PCIHostState, dev);
-PREPPCIState *s = DO_UPCAST(PREPPCIState, host_state, h);
+PREPPCIState *s = RAVEN_PCI_HOST_BRIDGE(dev);
 MemoryRegion *address_space_mem = get_system_memory();
 MemoryRegion *address_space_io = get_system_io();
 PCIBus *bus;
@@ -107,7 +114,7 @@ static int raven_pcihost_init(SysBusDevice *dev)
 sysbus_init_irq(dev, s-irq[i]);
 }
 
-bus = pci_register_bus(h-busdev.qdev, NULL,
+bus = pci_register_bus(DEVICE(dev), NULL,
prep_set_irq, prep_map_irq, s-irq,
address_space_mem, address_space_io, 0, 4);
 h-bus = bus;
@@ -184,7 +191,7 @@ static void raven_pcihost_class_init(ObjectClass *klass, 
void *data)
 }
 
 static const TypeInfo raven_pcihost_info = {
-.name = raven-pcihost,
+.name = TYPE_RAVEN_PCI_HOST_BRIDGE,
 .parent = TYPE_SYS_BUS_DEVICE,
 .instance_size = sizeof(PREPPCIState),
 .class_init = raven_pcihost_class_init,
-- 
1.7.7




[Qemu-devel] [PATCH v4 06/18] gt64xxx: QOM'ify GT64120 PCI host bridge

2012-07-26 Thread Andreas Färber
Introduce type constant. Introduce cast macro to drop dummy busdev field
used with FROM_SYSBUS() macro that would've broken SYS_BUS_DEVICE().
Avoid accessing DeviceState indirectly through PCIHostState.

Signed-off-by: Andreas Färber afaer...@suse.de
---
 hw/gt64xxx.c |   35 ---
 1 files changed, 20 insertions(+), 15 deletions(-)

diff --git a/hw/gt64xxx.c b/hw/gt64xxx.c
index 04831bb..0677299 100644
--- a/hw/gt64xxx.c
+++ b/hw/gt64xxx.c
@@ -229,9 +229,14 @@
 target_phys_addr_t regname ##_length; \
 MemoryRegion regname ##_mem
 
+#define TYPE_GT64120_PCI_HOST_BRIDGE gt64120
+
+#define GT64120_PCI_HOST_BRIDGE(obj) \
+OBJECT_CHECK(GT64120State, (obj), TYPE_GT64120_PCI_HOST_BRIDGE)
+
 typedef struct GT64120State {
-SysBusDevice busdev;
 PCIHostState pci;
+
 uint32_t regs[GT_REGS];
 PCI_MAPPING_ENTRY(PCI0IO);
 PCI_MAPPING_ENTRY(ISD);
@@ -1083,31 +1088,31 @@ static void gt64120_reset(void *opaque)
 
 PCIBus *gt64120_register(qemu_irq *pic)
 {
-SysBusDevice *s;
 GT64120State *d;
+PCIHostState *phb;
 DeviceState *dev;
 
-dev = qdev_create(NULL, gt64120);
+dev = qdev_create(NULL, TYPE_GT64120_PCI_HOST_BRIDGE);
 qdev_init_nofail(dev);
-s = sysbus_from_qdev(dev);
-d = FROM_SYSBUS(GT64120State, s);
-d-pci.bus = pci_register_bus(d-busdev.qdev, pci,
-  gt64120_pci_set_irq, gt64120_pci_map_irq,
-  pic,
-  get_system_memory(),
-  get_system_io(),
-  PCI_DEVFN(18, 0), 4);
+d = GT64120_PCI_HOST_BRIDGE(dev);
+phb = d-pci;
+phb-bus = pci_register_bus(dev, pci,
+gt64120_pci_set_irq, gt64120_pci_map_irq,
+pic,
+get_system_memory(),
+get_system_io(),
+PCI_DEVFN(18, 0), 4);
 memory_region_init_io(d-ISD_mem, isd_mem_ops, d, isd-mem, 0x1000);
 
-pci_create_simple(d-pci.bus, PCI_DEVFN(0, 0), gt64120_pci);
-return d-pci.bus;
+pci_create_simple(phb-bus, PCI_DEVFN(0, 0), gt64120_pci);
+return phb-bus;
 }
 
 static int gt64120_init(SysBusDevice *dev)
 {
 GT64120State *s;
 
-s = FROM_SYSBUS(GT64120State, dev);
+s = GT64120_PCI_HOST_BRIDGE(dev);
 
 /* FIXME: This value is computed from registers during reset, but some
devices (e.g. VGA card) need to know it when they are registered.
@@ -1162,7 +1167,7 @@ static void gt64120_class_init(ObjectClass *klass, void 
*data)
 }
 
 static const TypeInfo gt64120_info = {
-.name  = gt64120,
+.name  = TYPE_GT64120_PCI_HOST_BRIDGE,
 .parent= TYPE_SYS_BUS_DEVICE,
 .instance_size = sizeof(GT64120State),
 .class_init= gt64120_class_init,
-- 
1.7.7




Re: [Qemu-devel] [PATCH 1/5] qom: adopt rwlock to protect accessing dev from removing it

2012-07-26 Thread Avi Kivity
On 07/26/2012 04:21 PM, liu ping fan wrote:
 On Thu, Jul 26, 2012 at 9:15 PM, Avi Kivity a...@redhat.com wrote:
 On 07/26/2012 04:14 PM, liu ping fan wrote:

 From the description above, I don't see why it can't be a mutex.

 Searching in the device tree (or MemoryRegion view) can be often in
 parallel, especially in mmio-dispatch code path

 In mmio dispatch we have a pointer to the object, we don't need to
 search anything.  Is device tree search a hot path?

 I think, we need lock to protect searching --phys_page_find()  from
 deleter--DeviceClass:unmap,  so rwlock?

Better a lock on phys_map (because it is easily replaced by rcu, later).

I think phys_map is also better isolated, so it will be easier to find
all the placed that need protection and to avoid deadlock.


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





  1   2   3   >