[Qemu-devel] [PATCH v3 07/14] qapi: Move camel_to_upper(), c_enum_const() to closely related code

2015-05-05 Thread Eric Blake
From: Markus Armbruster arm...@redhat.com

Signed-off-by: Markus Armbruster arm...@redhat.com
Signed-off-by: Eric Blake ebl...@redhat.com
---
 scripts/qapi.py | 50 +-
 1 file changed, 25 insertions(+), 25 deletions(-)

diff --git a/scripts/qapi.py b/scripts/qapi.py
index 967dadb..b9822c6 100644
--- a/scripts/qapi.py
+++ b/scripts/qapi.py
@@ -742,6 +742,31 @@ def camel_case(name):
 new_name += ch.lower()
 return new_name

+# ENUMName - ENUM_NAME, EnumName1 - ENUM_NAME1
+# ENUM_NAME - ENUM_NAME, ENUM_NAME1 - ENUM_NAME1, ENUM_Name2 - ENUM_NAME2
+# ENUM24_Name - ENUM24_NAME
+def camel_to_upper(value):
+c_fun_str = c_name(value, False)
+if value.isupper():
+return c_fun_str
+
+new_name = ''
+l = len(c_fun_str)
+for i in range(l):
+c = c_fun_str[i]
+# When c is upper and no _ appears before, do more checks
+if c.isupper() and (i  0) and c_fun_str[i - 1] != _:
+# Case 1: next string is lower
+# Case 2: previous string is digit
+if (i  (l - 1) and c_fun_str[i + 1].islower()) or \
+c_fun_str[i - 1].isdigit():
+new_name += '_'
+new_name += c
+return new_name.lstrip('_').upper()
+
+def c_enum_const(type_name, const_name):
+return camel_to_upper(type_name + '_' + const_name)
+
 c_name_trans = string.maketrans('.-', '__')

 def c_name(name, protect=True):
@@ -926,28 +951,3 @@ def guardend(name):

 ''',
  name=guardname(name))
-
-# ENUMName - ENUM_NAME, EnumName1 - ENUM_NAME1
-# ENUM_NAME - ENUM_NAME, ENUM_NAME1 - ENUM_NAME1, ENUM_Name2 - ENUM_NAME2
-# ENUM24_Name - ENUM24_NAME
-def camel_to_upper(value):
-c_fun_str = c_name(value, False)
-if value.isupper():
-return c_fun_str
-
-new_name = ''
-l = len(c_fun_str)
-for i in range(l):
-c = c_fun_str[i]
-# When c is upper and no _ appears before, do more checks
-if c.isupper() and (i  0) and c_fun_str[i - 1] != _:
-# Case 1: next string is lower
-# Case 2: previous string is digit
-if (i  (l - 1) and c_fun_str[i + 1].islower()) or \
-c_fun_str[i - 1].isdigit():
-new_name += '_'
-new_name += c
-return new_name.lstrip('_').upper()
-
-def c_enum_const(type_name, const_name):
-return camel_to_upper(type_name + '_' + const_name)
-- 
2.1.0




[Qemu-devel] [PATCH v3 08/14] qapi: Make c_type() consistently convert qapi names

2015-05-05 Thread Eric Blake
Continuing the string of cleanups for supporting downstream names
containing '.', this patch focuses on ensuring c_type() can
handle a downstream name.  This patch alone does not fix the
places where generator output should be calling this function
but was open-coding things instead, but it gets us a step closer.

Note that we generate a List type for our builtins; the code has
to make sure that ['int'] maps to 'intList' (and not 'q_intList'),
and that a member with type 'int' still maps to the C type 'int';
on the other hand, a member with a name of 'int' will still map
to 'q_int' when going through c_name().  This patch had to teach
type_name() to special-case builtins, since it is used by
c_list_type() which in turn feeds c_type().

Signed-off-by: Eric Blake ebl...@redhat.com
---
 scripts/qapi.py | 17 +
 1 file changed, 13 insertions(+), 4 deletions(-)

diff --git a/scripts/qapi.py b/scripts/qapi.py
index b9822c6..a1dfc85 100644
--- a/scripts/qapi.py
+++ b/scripts/qapi.py
@@ -769,6 +769,9 @@ def c_enum_const(type_name, const_name):

 c_name_trans = string.maketrans('.-', '__')

+# This function is used for converting the name portion of 'name':'type'
+# into a valid C name, for use as a struct member or substring of a
+# function name.
 def c_name(name, protect=True):
 # ANSI X3J11/88-090, 3.1.1
 c89_words = set(['auto', 'break', 'case', 'char', 'const', 'continue',
@@ -800,13 +803,18 @@ def c_name(name, protect=True):
 return q_ + name
 return name.translate(c_name_trans)

+# This function is used for computing the C type of a 'member':['name'] array.
 def c_list_type(name):
-return '%sList' % name
+return type_name(name) + 'List'

+# This function is used for converting the type of 'member':'name' into a
+# substring for use in C pointer types or function names.
 def type_name(name):
 if type(name) == list:
 return c_list_type(name[0])
-return name
+if name in builtin_types.keys():
+return name
+return c_name(name)

 def add_name(name, info, meta, implicit = False):
 global all_names
@@ -864,6 +872,7 @@ def is_enum(name):

 eatspace = '\033EATSPACE.'

+# This function is used for computing the full C type of 'member':'name'.
 # A special suffix is added in c_type() for pointer types, and it's
 # stripped in mcgen(). So please notice this when you check the return
 # value of c_type() outside mcgen().
@@ -888,13 +897,13 @@ def c_type(name, is_param=False):
 elif type(name) == list:
 return '%s *%s' % (c_list_type(name[0]), eatspace)
 elif is_enum(name):
-return name
+return c_name(name)
 elif name == None or len(name) == 0:
 return 'void'
 elif name in events:
 return '%sEvent *%s' % (camel_case(name), eatspace)
 else:
-return '%s *%s' % (name, eatspace)
+return '%s *%s' % (c_name(name), eatspace)

 def is_c_ptr(name):
 suffix = * + eatspace
-- 
2.1.0




[Qemu-devel] [PATCH v3 00/14] Fix qapi mangling of downstream names

2015-05-05 Thread Eric Blake
This series makes it possible to use downstream extensions
(such as __com.redhat_xyz) and temporary names (such as x-foo)
in every position possible in QAPI schemes, with added tests
that the generated code still compiles.

There's still some things we could do to the qapi generator,
such as normalizing struct member names and C manglings and
creating named implicit types up front on the initial parse
rather than multiple times in each backend.  But that should
wait until existing pending patches have landed, to minimize
rebase churn.

v2 was here:
https://lists.gnu.org/archive/html/qemu-devel/2015-04/msg01300.html

v3 includes several more of Markus' original RFC series, splits
up my work into smaller pieces, incorporates fixes suggested by
Markus, and rebases on top of the pending v8 qapi drop nested
structs series.  The series has changed enough from v2 that it
is not worth showing git backport-diff statistics (as only patch
1 survived intact).

Eric Blake (8):
  qapi: Rename identical c_fun()/c_var() into c_name()
  qapi: Make c_type() consistently convert qapi names
  qapi: Support downstream enums
  qapi: Support downstream structs
  qapi: Support downstream simple unions
  qapi: Support downstream flat unions
  qapi: Support downstream alternates
  qapi: Support downstream events and commands

Markus Armbruster (6):
  qapi: Fix C identifiers generated for names containing '.'
  qapi: Rename _generate_enum_string() to camel_to_upper()
  qapi: Rename generate_enum_full_value() to c_enum_const()
  qapi: Simplify c_enum_const()
  qapi: Use c_enum_const() in generate_alternate_qtypes()
  qapi: Move camel_to_upper(), c_enum_const() to closely related code

 scripts/qapi-commands.py| 51 --
 scripts/qapi-event.py   | 15 +++---
 scripts/qapi-types.py   | 44 +++
 scripts/qapi-visit.py   | 54 ++-
 scripts/qapi.py | 96 -
 tests/qapi-schema/qapi-schema-test.json | 20 +++
 tests/qapi-schema/qapi-schema-test.out  | 21 ++--
 tests/test-qmp-commands.c   | 15 ++
 8 files changed, 179 insertions(+), 137 deletions(-)

-- 
2.1.0




[Qemu-devel] [PATCH v3 01/14] qapi: Fix C identifiers generated for names containing '.'

2015-05-05 Thread Eric Blake
From: Markus Armbruster arm...@redhat.com

c_fun() maps '.' to '_', c_var() doesn't.  Nothing prevents '.' in
QAPI names that get passed to c_var().

Which QAPI names get passed to c_fun(), to c_var(), or to both is not
obvious.  Names of command parameters and struct type members get
passed to c_var().

c_var() strips a leading '*', but this cannot happen.  c_fun()
doesn't.

Fix c_var() to work exactly like c_fun().

Perhaps they should be replaced by a single mapping function.

Signed-off-by: Markus Armbruster arm...@redhat.com
[add 'import string']
Signed-off-by: Eric Blake ebl...@redhat.com
Reviewed-by: Alberto Garcia be...@igalia.com
---
 scripts/qapi.py | 7 +--
 1 file changed, 5 insertions(+), 2 deletions(-)

diff --git a/scripts/qapi.py b/scripts/qapi.py
index edfaf9e..ca1adf2 100644
--- a/scripts/qapi.py
+++ b/scripts/qapi.py
@@ -15,6 +15,7 @@ import re
 from ordereddict import OrderedDict
 import os
 import sys
+import string

 builtin_types = {
 'str':  'QTYPE_QSTRING',
@@ -752,6 +753,8 @@ def camel_case(name):
 new_name += ch.lower()
 return new_name

+c_var_trans = string.maketrans('.-', '__')
+
 def c_var(name, protect=True):
 # ANSI X3J11/88-090, 3.1.1
 c89_words = set(['auto', 'break', 'case', 'char', 'const', 'continue',
@@ -781,10 +784,10 @@ def c_var(name, protect=True):
 polluted_words = set(['unix', 'errno'])
 if protect and (name in c89_words | c99_words | c11_words | gcc_words | 
cpp_words | polluted_words):
 return q_ + name
-return name.replace('-', '_').lstrip(*)
+return name.translate(c_var_trans)

 def c_fun(name, protect=True):
-return c_var(name, protect).replace('.', '_')
+return c_var(name, protect)

 def c_list_type(name):
 return '%sList' % name
-- 
2.1.0




Re: [Qemu-devel] [PATCH] QJSON: Use OBJECT_CHECK

2015-05-05 Thread Juan Quintela
Eduardo Habkost ehabk...@redhat.com wrote:
 On Sat, Apr 25, 2015 at 07:05:55PM +0200, Andreas Färber wrote:
 Am 25.04.2015 um 17:28 schrieb Eduardo Habkost:
  The QJSON code used casts to (QJSON*) directly, instead of OBJECT_CHECK.
  There were even some functions using object_dynamic_cast() calls
  followed by assert(), which is exactly what OBJECT_CHECK does (by
  calling object_dynamic_cast_assert()).
 
 Suggest s/OBJECT_CHECK/OBJECT_CHECK()/g everywhere for clarity.

 I assume it can be fixed during commit by whoever is going to queue it.

 
  
  Signed-off-by: Eduardo Habkost ehabk...@redhat.com
  ---
   qjson.c | 10 +-
   1 file changed, 5 insertions(+), 5 deletions(-)
 
 Reviewed-by: Andreas Färber afaer...@suse.de
 
 Wasn't aware QJSON is using QOM - assuming this will go through some
 QAPI/QMP tree.

 The only user of qjson.c right now is migration code. Should it go through
 the migration tree?


I will take it, but I trust your reviews-by O:-)


 Also, why do we have two JSON writers in QEMU? And why do they have
 exactly the same name?

Alex?  I guess alex have this implementation when he did the code long
ago?

Later, Juan.



Re: [Qemu-devel] [PATCH 2/6] qcow2: simplify qcow2_cache_put() and qcow2_cache_entry_mark_dirty()

2015-05-05 Thread Alberto Garcia
On Fri 01 May 2015 04:31:52 PM CEST, Stefan Hajnoczi wrote:

  int qcow2_cache_put(BlockDriverState *bs, Qcow2Cache *c, void **table)
  {
 -int i;
 +int i = (*table - c-table_array) / c-table_size;
  
 -for (i = 0; i  c-size; i++) {
 -if (table_addr(c, i) == *table) {
 -goto found;
 -}
 +if (c-entries[i].offset == 0) {
 +return -ENOENT;
  }
 -return -ENOENT;
  
 -found:
  c-entries[i].ref--;
  *table = NULL;
  

 When is this function called with a bogus table pointer?

I also could not image any such scenario, but I decided to be
conservative and keep the error handling code. I'll double check all
places where it's used and remove the relevant code.

Berto



Re: [Qemu-devel] [PATCH qemu v7 13/14] spapr_pci/spapr_pci_vfio: Support Dynamic DMA Windows (DDW)

2015-05-05 Thread David Gibson
On Sat, Apr 25, 2015 at 10:24:43PM +1000, Alexey Kardashevskiy wrote:
 This adds support for Dynamic DMA Windows (DDW) option defined by
 the SPAPR specification which allows to have additional DMA window(s)
 
 This implements DDW for emulated and VFIO devices. As all TCE root regions
 are mapped at 0 and 64bit long (and actual tables are child regions),
 this replaces memory_region_add_subregion() with _overlap() to make
 QEMU memory API happy.
 
 This reserves RTAS token numbers for DDW calls.
 
 This implements helpers to interact with VFIO kernel interface.
 
 This changes the TCE table migration descriptor to support dynamic
 tables as from now on, PHB will create as many stub TCE table objects
 as PHB can possibly support but not all of them might be initialized at
 the time of migration because DDW might or might not be requested by
 the guest.
 
 The ddw property is enabled by default on a PHB but for compatibility
 the pseries-2.3 machine and older disable it.
 
 This implements DDW for VFIO. The host kernel support is required.
 This adds a levels property to PHB to control the number of levels
 in the actual TCE table allocated by the host kernel, 0 is the default
 value to tell QEMU to calculate the correct value. Current hardware
 supports up to 5 levels.
 
 The existing linux guests try creating one additional huge DMA window
 with 64K or 16MB pages and map the entire guest RAM to. If succeeded,
 the guest switches to dma_direct_ops and never calls TCE hypercalls
 (H_PUT_TCE,...) again. This enables VFIO devices to use the entire RAM
 and not waste time on map/unmap later.
 
 This adds 4 RTAS handlers:
 * ibm,query-pe-dma-window
 * ibm,create-pe-dma-window
 * ibm,remove-pe-dma-window
 * ibm,reset-pe-dma-window
 These are registered from type_init() callback.
 
 These RTAS handlers are implemented in a separate file to avoid polluting
 spapr_iommu.c with PCI.
 
 Signed-off-by: Alexey Kardashevskiy a...@ozlabs.ru

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

 ---
 Changes:
 v6:
 * rework as there is no more special device for VFIO PHB
 
 v5:
 * total rework
 * enabled for machines 2.3
 * fixed migration
 * merged rtas handlers here
 
 v4:
 * reset handler is back in generalized form
 
 v3:
 * removed reset
 * windows_num is now 1 or bigger rather than 0-based value and it is only
 changed in PHB code, not in RTAS
 * added page mask check in create()
 * added SPAPR_PCI_DDW_MAX_WINDOWS to track how many windows are already
 created
 
 v2:
 * tested on hacked emulated E1000
 * implemented DDW reset on the PHB reset
 * spapr_pci_ddw_remove/spapr_pci_ddw_reset are public for reuse by VFIO
 ---
  hw/ppc/Makefile.objs|   3 +
  hw/ppc/spapr.c  |  10 +-
  hw/ppc/spapr_iommu.c|  35 +-
  hw/ppc/spapr_pci.c  |  66 --
  hw/ppc/spapr_pci_vfio.c |  80 
  hw/ppc/spapr_rtas_ddw.c | 300 
 
  include/hw/pci-host/spapr.h |  21 
  include/hw/ppc/spapr.h  |  17 ++-
  trace-events|   4 +
  9 files changed, 521 insertions(+), 15 deletions(-)
  create mode 100644 hw/ppc/spapr_rtas_ddw.c
 
 diff --git a/hw/ppc/Makefile.objs b/hw/ppc/Makefile.objs
 index 437955d..c6b344f 100644
 --- a/hw/ppc/Makefile.objs
 +++ b/hw/ppc/Makefile.objs
 @@ -7,6 +7,9 @@ obj-$(CONFIG_PSERIES) += spapr_pci.o spapr_rtc.o
  ifeq ($(CONFIG_PCI)$(CONFIG_PSERIES)$(CONFIG_LINUX), yyy)
  obj-y += spapr_pci_vfio.o
  endif
 +ifeq ($(CONFIG_PCI)$(CONFIG_PSERIES), yy)
 +obj-y += spapr_rtas_ddw.o
 +endif
  # PowerPC 4xx boards
  obj-y += ppc405_boards.o ppc4xx_devs.o ppc405_uc.o ppc440_bamboo.o
  obj-y += ppc4xx_pci.o
 diff --git a/hw/ppc/spapr.c b/hw/ppc/spapr.c
 index b28209f..fd7fdb3 100644
 --- a/hw/ppc/spapr.c
 +++ b/hw/ppc/spapr.c
 @@ -1801,7 +1801,15 @@ static const TypeInfo spapr_machine_info = {
  },
  };
  
 +#define SPAPR_COMPAT_2_3 \
 +{\
 +.driver   = TYPE_SPAPR_PCI_HOST_BRIDGE,\
 +.property = ddw,\
 +.value= stringify(off),\
 +}
 +
  #define SPAPR_COMPAT_2_2 \
 +SPAPR_COMPAT_2_3, \
  {\
  .driver   = TYPE_SPAPR_PCI_HOST_BRIDGE,\
  .property = mem_win_size,\
 @@ -1853,7 +1861,7 @@ static const TypeInfo spapr_machine_2_2_info = {
  static void spapr_machine_2_3_class_init(ObjectClass *oc, void *data)
  {
  static GlobalProperty compat_props[] = {
 -SPAPR_COMPAT_2_2,
 +SPAPR_COMPAT_2_3,
  { /* end of list */ }
  };
  MachineClass *mc = MACHINE_CLASS(oc);
 diff --git a/hw/ppc/spapr_iommu.c b/hw/ppc/spapr_iommu.c
 index 245534f..df4c72d 100644
 --- a/hw/ppc/spapr_iommu.c
 +++ b/hw/ppc/spapr_iommu.c
 @@ -90,6 +90,15 @@ static IOMMUTLBEntry 
 spapr_tce_translate_iommu(MemoryRegion *iommu, hwaddr addr,
  return ret;
  }
  
 +static void spapr_tce_table_pre_save(void *opaque)
 +{
 +sPAPRTCETable *tcet = SPAPR_TCE_TABLE(opaque);
 +
 +tcet-migtable = tcet-table;
 

Re: [Qemu-devel] [PATCH v3 5/6] spapr_pci: fix boot-time device tree fields for pci hotplug

2015-05-05 Thread David Gibson
On Tue, May 05, 2015 at 02:23:55PM +0530, Nikunj A Dadhania wrote:
 From: Michael Roth mdr...@linux.vnet.ibm.com
 
 We need to set the proper drc_index values in ibm,my-drc-index
 fields in order to allow a PCI device that was present at
 boot-time to be unplugged.
 
 Previously SLOF handles this, but with QEMU handling the DT we
 need to do it there as well.
 
 This patch slightly changes how SLOF handled it in the past,
 which was to allows add an ibm,my-drc-index value based on
 PCI slot/devices topology. Now we only add it when the slot
 supports hotplug and has a DR connector, which is more inline
 with PAPR.
 
 Signed-off-by: Michael Roth mdr...@linux.vnet.ibm.com
 Signed-off-by: Nikunj A Dadhania nik...@linux.vnet.ibm.com
 ---
  hw/ppc/spapr_pci.c | 21 +++--
  1 file changed, 19 insertions(+), 2 deletions(-)
 
 diff --git a/hw/ppc/spapr_pci.c b/hw/ppc/spapr_pci.c
 index 103284a..cbd5661 100644
 --- a/hw/ppc/spapr_pci.c
 +++ b/hw/ppc/spapr_pci.c
 @@ -951,7 +951,9 @@ static int spapr_populate_pci_child_dt(PCIDevice *dev, 
 void *fdt, int offset,
  _FDT(fdt_setprop(fdt, offset, ibm,loc-code, drc_name,
   strlen(drc_name)));
  }
 -_FDT(fdt_setprop_cell(fdt, offset, ibm,my-drc-index, drc_index));
 +if (drc_index) {
 +_FDT(fdt_setprop_cell(fdt, offset, ibm,my-drc-index, drc_index));
 +}
  
  _FDT(fdt_setprop_cell(fdt, offset, #address-cells,
RESOURCE_CELLS_ADDRESS));
 @@ -1483,6 +1485,20 @@ PCIHostState *spapr_create_phb(sPAPREnvironment 
 *spapr, int index)
  return PCI_HOST_BRIDGE(dev);
  }
  
 +static uint32_t spapr_phb_get_pci_drc_index(sPAPRPHBState *phb,
 +PCIDevice *pdev)
 +{
 +sPAPRDRConnector *drc = spapr_phb_get_pci_drc(phb, pdev);
 +sPAPRDRConnectorClass *drck;
 +
 +if (!drc) {
 +return 0;
 +}
 +
 +drck = SPAPR_DR_CONNECTOR_GET_CLASS(drc);
 +return drck-get_index(drc);
 +}
 +
  typedef struct sPAPRFDT {
  void *fdt;
  int node_off;
 @@ -1499,6 +1515,7 @@ static void spapr_populate_pci_devices_dt(PCIBus *bus, 
 PCIDevice *pdev,
  int func = PCI_FUNC(pdev-devfn);
  char nodename[512];
  sPAPRFDT s_fdt;
 +uint32_t drc_index = spapr_phb_get_pci_drc_index(p-sphb, pdev);

The line above causes a compile error, since sPAPRFDT doesn't have an
sphb member.

Its fixed in the next patch, but can you adjust the series so it won't
break bisection.


  if (func) {
  sprintf(nodename, pci@%d,%d, slot, func);
 @@ -1506,7 +1523,7 @@ static void spapr_populate_pci_devices_dt(PCIBus *bus, 
 PCIDevice *pdev,
  sprintf(nodename, pci@%d, slot);
  }
  offset = fdt_add_subnode(p-fdt, p-node_off, nodename);
 -ret = spapr_populate_pci_child_dt(pdev, p-fdt, offset, p-index, 0, 
 NULL);
 +ret = spapr_populate_pci_child_dt(pdev, p-fdt, offset, p-index, 
 drc_index, NULL);
  g_assert(!ret);
  
  if ((pci_default_read_config(pdev, PCI_HEADER_TYPE, 1) !=

-- 
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


pgpco9DmQAB9h.pgp
Description: PGP signature


Re: [Qemu-devel] Fwd: qemu drive mirror assert fault

2015-05-05 Thread Paolo Bonzini


On 05/05/2015 13:48, Kevin Wolf wrote:
 It depends. In its basic form, bdrv_discard() just means I don't care
 about the data any more. Then clearing the dirty bitmap is correct.
 
 The content is only important if the caller used discard to write zeros
 because can_write_zeroes_with_unmap = true. Do we have any such callers
 apart from qemu-img convert?

Yes, the SCSI command WRITE SAME with UNMAP = 1 (not coincidentially :))
calls discard too.  Who knows what the guest used it for...

However, write zeroes doesn't go through bdrv_co_discard, does it?

Paolo



Re: [Qemu-devel] [RFC PATCH 13/15] spapr_pci: provide node start offset via spapr_populate_pci_dt()

2015-05-05 Thread David Gibson
On Wed, Apr 29, 2015 at 02:20:22PM -0500, Michael Roth wrote:
 PHB hotplug re-uses PHB device tree generation code and passes
 it to a guest via RTAS. Doing this requires knowledge of where
 exactly in the device tree the node describing the PHB begins.
 
 Provide this via a new optional pointer that can be used to
 store the PHB node's start offset.
 
 Signed-off-by: Michael Roth mdr...@linux.vnet.ibm.com

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

 ---
  hw/ppc/spapr.c  | 2 +-
  hw/ppc/spapr_pci.c  | 6 +-
  include/hw/pci-host/spapr.h | 3 ++-
  3 files changed, 8 insertions(+), 3 deletions(-)
 
 diff --git a/hw/ppc/spapr.c b/hw/ppc/spapr.c
 index 042e7a9..ecf40e4 100644
 --- a/hw/ppc/spapr.c
 +++ b/hw/ppc/spapr.c
 @@ -767,7 +767,7 @@ static void spapr_finalize_fdt(sPAPREnvironment *spapr,
  }
  
  QLIST_FOREACH(phb, spapr-phbs, list) {
 -ret = spapr_populate_pci_dt(phb, PHANDLE_XICP, fdt);
 +ret = spapr_populate_pci_dt(phb, PHANDLE_XICP, fdt, NULL);
  }
  
  if (ret  0) {
 diff --git a/hw/ppc/spapr_pci.c b/hw/ppc/spapr_pci.c
 index e37de28..66fe85f 100644
 --- a/hw/ppc/spapr_pci.c
 +++ b/hw/ppc/spapr_pci.c
 @@ -1534,7 +1534,8 @@ PCIHostState *spapr_create_phb(sPAPREnvironment *spapr, 
 int index)
  
  int spapr_populate_pci_dt(sPAPRPHBState *phb,
uint32_t xics_phandle,
 -  void *fdt)
 +  void *fdt,
 +  int *node_offset)
  {
  int bus_off, i, j, ret;
  char nodename[256];
 @@ -1578,6 +1579,9 @@ int spapr_populate_pci_dt(sPAPRPHBState *phb,
  if (bus_off  0) {
  return bus_off;
  }
 +if (node_offset) {
 +*node_offset = bus_off;
 +}
  
  /* Write PHB properties */
  _FDT(fdt_setprop_string(fdt, bus_off, device_type, pci));
 diff --git a/include/hw/pci-host/spapr.h b/include/hw/pci-host/spapr.h
 index 9dca388..32a9213 100644
 --- a/include/hw/pci-host/spapr.h
 +++ b/include/hw/pci-host/spapr.h
 @@ -126,7 +126,8 @@ PCIHostState *spapr_create_phb(sPAPREnvironment *spapr, 
 int index);
  
  int spapr_populate_pci_dt(sPAPRPHBState *phb,
uint32_t xics_phandle,
 -  void *fdt);
 +  void *fdt,
 +  int *node_offset);
  
  void spapr_pci_msi_init(sPAPREnvironment *spapr, hwaddr addr);
  

-- 
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


pgporrsnYzElb.pgp
Description: PGP signature


[Qemu-devel] [PATCH 3/5] gtk: add ui_info support

2015-05-05 Thread Gerd Hoffmann
Pass new display size to the guest after window resizes.

Signed-off-by: Gerd Hoffmann kra...@redhat.com
---
 ui/gtk.c | 19 +++
 1 file changed, 19 insertions(+)

diff --git a/ui/gtk.c b/ui/gtk.c
index 51ea1b9..9163b43 100644
--- a/ui/gtk.c
+++ b/ui/gtk.c
@@ -1478,6 +1478,19 @@ static gboolean gd_focus_out_event(GtkWidget *widget,
 return TRUE;
 }
 
+static gboolean gd_configure(GtkWidget *widget,
+ GdkEventConfigure *cfg, gpointer opaque)
+{
+VirtualConsole *vc = opaque;
+QemuUIInfo info;
+
+memset(info, 0, sizeof(info));
+info.width = cfg-width;
+info.height = cfg-height;
+dpy_set_ui_info(vc-gfx.dcl.con, info);
+return FALSE;
+}
+
 /** Virtual Console Callbacks **/
 
 static GSList *gd_vc_menu_init(GtkDisplayState *s, VirtualConsole *vc,
@@ -1655,6 +1668,8 @@ static void gd_connect_vc_gfx_signals(VirtualConsole *vc)
  G_CALLBACK(gd_leave_event), vc);
 g_signal_connect(vc-gfx.drawing_area, focus-out-event,
  G_CALLBACK(gd_focus_out_event), vc);
+g_signal_connect(vc-gfx.drawing_area, configure-event,
+ G_CALLBACK(gd_configure), vc);
 } else {
 g_signal_connect(vc-gfx.drawing_area, key-press-event,
  G_CALLBACK(gd_text_key_down), vc);
@@ -1772,6 +1787,10 @@ static GSList *gd_vc_gfx_init(GtkDisplayState *s, 
VirtualConsole *vc,
 gd_connect_vc_gfx_signals(vc);
 group = gd_vc_menu_init(s, vc, idx, group, view_menu);
 
+if (dpy_ui_info_supported(vc-gfx.dcl.con)) {
+gtk_menu_item_activate(GTK_MENU_ITEM(s-zoom_fit_item));
+}
+
 return group;
 }
 
-- 
1.8.3.1




[Qemu-devel] [PATCH v3 12/14] qapi: Support downstream flat unions

2015-05-05 Thread Eric Blake
Enhance the testsuite to cover downstream flat unions, including
the base type, discriminator name and type, and branch name and
type.  Update the generator to mangle the union names in the
appropriate places.

Signed-off-by: Eric Blake ebl...@redhat.com
---
 scripts/qapi-types.py   | 2 +-
 scripts/qapi-visit.py   | 4 ++--
 tests/qapi-schema/qapi-schema-test.json | 5 +
 tests/qapi-schema/qapi-schema-test.out  | 7 +--
 4 files changed, 13 insertions(+), 5 deletions(-)

diff --git a/scripts/qapi-types.py b/scripts/qapi-types.py
index 5b0bc5d..13e4b53 100644
--- a/scripts/qapi-types.py
+++ b/scripts/qapi-types.py
@@ -213,7 +213,7 @@ struct %(name)s
 void *data;
 ''',
 name=name,
-discriminator_type_name=discriminator_type_name)
+discriminator_type_name=c_name(discriminator_type_name))

 for key in typeinfo:
 ret += mcgen('''
diff --git a/scripts/qapi-visit.py b/scripts/qapi-visit.py
index 1397707..def0c50 100644
--- a/scripts/qapi-visit.py
+++ b/scripts/qapi-visit.py
@@ -253,7 +253,7 @@ def generate_visit_union(expr):
 if enum_define:
 # Use the enum type as discriminator
 ret = 
-disc_type = enum_define['enum_name']
+disc_type = c_name(enum_define['enum_name'])
 else:
 # There will always be a discriminator in the C switch code, by default
 # it is an enum type generated silently
@@ -291,7 +291,7 @@ void visit_type_%(name)s(Visitor *m, %(name)s **obj, const 
char *name, Error **e
 goto out_obj;
 }
 ''',
-name=name)
+ name=c_name(name))

 if not discriminator:
 disc_key = type
diff --git a/tests/qapi-schema/qapi-schema-test.json 
b/tests/qapi-schema/qapi-schema-test.json
index 6416d85..ac236e3 100644
--- a/tests/qapi-schema/qapi-schema-test.json
+++ b/tests/qapi-schema/qapi-schema-test.json
@@ -115,3 +115,8 @@
 { 'struct': '__org.qemu_x-Struct', 'base': '__org.qemu_x-Base',
   'data': { '__org.qemu_x-member2': 'str' } }
 { 'union': '__org.qemu_x-Union1', 'data': { '__org.qemu_x-branch': 'str' } }
+{ 'struct': '__org.qemu_x-Struct2',
+  'data': { 'array': ['__org.qemu_x-Union1'] } }
+{ 'union': '__org.qemu_x-Union2', 'base': '__org.qemu_x-Base',
+  'discriminator': '__org.qemu_x-member1',
+  'data': { '__org.qemu_x-value': '__org.qemu_x-Struct2' } }
diff --git a/tests/qapi-schema/qapi-schema-test.out 
b/tests/qapi-schema/qapi-schema-test.out
index f9ebe08..3fc24e8 100644
--- a/tests/qapi-schema/qapi-schema-test.out
+++ b/tests/qapi-schema/qapi-schema-test.out
@@ -26,7 +26,9 @@
  OrderedDict([('enum', '__org.qemu_x-Enum'), ('data', 
['__org.qemu_x-value'])]),
  OrderedDict([('struct', '__org.qemu_x-Base'), ('data', 
OrderedDict([('__org.qemu_x-member1', '__org.qemu_x-Enum')]))]),
  OrderedDict([('struct', '__org.qemu_x-Struct'), ('base', 
'__org.qemu_x-Base'), ('data', OrderedDict([('__org.qemu_x-member2', 
'str')]))]),
- OrderedDict([('union', '__org.qemu_x-Union1'), ('data', 
OrderedDict([('__org.qemu_x-branch', 'str')]))])]
+ OrderedDict([('union', '__org.qemu_x-Union1'), ('data', 
OrderedDict([('__org.qemu_x-branch', 'str')]))]),
+ OrderedDict([('struct', '__org.qemu_x-Struct2'), ('data', 
OrderedDict([('array', ['__org.qemu_x-Union1'])]))]),
+ OrderedDict([('union', '__org.qemu_x-Union2'), ('base', '__org.qemu_x-Base'), 
('discriminator', '__org.qemu_x-member1'), ('data', 
OrderedDict([('__org.qemu_x-value', '__org.qemu_x-Struct2')]))])]
 [{'enum_name': 'EnumOne', 'enum_values': ['value1', 'value2', 'value3']},
  {'enum_name': '__org.qemu_x-Enum', 'enum_values': ['__org.qemu_x-value']},
  {'enum_name': 'UserDefAlternateKind', 'enum_values': None},
@@ -45,4 +47,5 @@
  OrderedDict([('struct', 'UserDefOptions'), ('data', OrderedDict([('*i64', 
['int']), ('*u64', ['uint64']), ('*u16', ['uint16']), ('*i64x', 'int'), 
('*u64x', 'uint64')]))]),
  OrderedDict([('struct', 'EventStructOne'), ('data', OrderedDict([('struct1', 
'UserDefOne'), ('string', 'str'), ('*enum2', 'EnumOne')]))]),
  OrderedDict([('struct', '__org.qemu_x-Base'), ('data', 
OrderedDict([('__org.qemu_x-member1', '__org.qemu_x-Enum')]))]),
- OrderedDict([('struct', '__org.qemu_x-Struct'), ('base', 
'__org.qemu_x-Base'), ('data', OrderedDict([('__org.qemu_x-member2', 
'str')]))])]
+ OrderedDict([('struct', '__org.qemu_x-Struct'), ('base', 
'__org.qemu_x-Base'), ('data', OrderedDict([('__org.qemu_x-member2', 
'str')]))]),
+ OrderedDict([('struct', '__org.qemu_x-Struct2'), ('data', 
OrderedDict([('array', ['__org.qemu_x-Union1'])]))])]
-- 
2.1.0




[Qemu-devel] [PATCH v3 03/14] qapi: Rename _generate_enum_string() to camel_to_upper()

2015-05-05 Thread Eric Blake
From: Markus Armbruster arm...@redhat.com

Signed-off-by: Markus Armbruster arm...@redhat.com
Signed-off-by: Eric Blake ebl...@redhat.com
---
 scripts/qapi.py | 12 ++--
 1 file changed, 6 insertions(+), 6 deletions(-)

diff --git a/scripts/qapi.py b/scripts/qapi.py
index 2431327..d9ed73a 100644
--- a/scripts/qapi.py
+++ b/scripts/qapi.py
@@ -538,7 +538,7 @@ def check_union(expr, expr_info):

 # Otherwise, check for conflicts in the generated enum
 else:
-c_key = _generate_enum_string(key)
+c_key = camel_to_upper(key)
 if c_key in values:
 raise QAPIExprError(expr_info,
 Union '%s' member '%s' clashes with '%s'
@@ -556,7 +556,7 @@ def check_alternate(expr, expr_info):
 check_name(expr_info, Member of alternate '%s' % name, key)

 # Check for conflicts in the generated enum
-c_key = _generate_enum_string(key)
+c_key = camel_to_upper(key)
 if c_key in values:
 raise QAPIExprError(expr_info,
 Alternate '%s' member '%s' clashes with '%s'
@@ -587,7 +587,7 @@ def check_enum(expr, expr_info):
 for member in members:
 check_name(expr_info, Member of enum '%s' %name, member,
enum_member=True)
-key = _generate_enum_string(member)
+key = camel_to_upper(member)
 if key in values:
 raise QAPIExprError(expr_info,
 Enum '%s' member '%s' clashes with '%s'
@@ -941,7 +941,7 @@ def guardend(name):
 # ENUMName - ENUM_NAME, EnumName1 - ENUM_NAME1
 # ENUM_NAME - ENUM_NAME, ENUM_NAME1 - ENUM_NAME1, ENUM_Name2 - ENUM_NAME2
 # ENUM24_Name - ENUM24_NAME
-def _generate_enum_string(value):
+def camel_to_upper(value):
 c_fun_str = c_name(value, False)
 if value.isupper():
 return c_fun_str
@@ -961,6 +961,6 @@ def _generate_enum_string(value):
 return new_name.lstrip('_').upper()

 def generate_enum_full_value(enum_name, enum_value):
-abbrev_string = _generate_enum_string(enum_name)
-value_string = _generate_enum_string(enum_value)
+abbrev_string = camel_to_upper(enum_name)
+value_string = camel_to_upper(enum_value)
 return %s_%s % (abbrev_string, value_string)
-- 
2.1.0




[Qemu-devel] [PATCH 4/4] qemu-iotests: Add test case for mirror with unmap

2015-05-05 Thread Fam Zheng
This checks that the discard on mirror source that effectively zeroes
data is also reflected by the data of target.

Signed-off-by: Fam Zheng f...@redhat.com
---
 tests/qemu-iotests/131 | 59 ++
 tests/qemu-iotests/131.out |  5 
 tests/qemu-iotests/group   |  1 +
 3 files changed, 65 insertions(+)
 create mode 100644 tests/qemu-iotests/131
 create mode 100644 tests/qemu-iotests/131.out

diff --git a/tests/qemu-iotests/131 b/tests/qemu-iotests/131
new file mode 100644
index 000..e33ca72
--- /dev/null
+++ b/tests/qemu-iotests/131
@@ -0,0 +1,59 @@
+#!/usr/bin/env python
+#
+# Test mirror with unmap
+#
+# Copyright (C) 2015 Red Hat, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program.  If not, see http://www.gnu.org/licenses/.
+#
+
+import time
+import os
+import iotests
+from iotests import qemu_img, qemu_io
+
+test_img = os.path.join(iotests.test_dir, 'test.img')
+target_img = os.path.join(iotests.test_dir, 'target.img')
+
+class TestSingleDrive(iotests.QMPTestCase):
+image_len = 2 * 1024 * 1024 # MB
+
+def setUp(self):
+# Write data to the image so we can compare later
+qemu_img('create', '-f', iotests.imgfmt, test_img, 
str(TestSingleDrive.image_len))
+qemu_io('-f', iotests.imgfmt, '-c', 'write -P0x5d 0 2M', test_img)
+
+self.vm = iotests.VM().add_drive(test_img, 'discard=unmap')
+self.vm.launch()
+
+def tearDown(self):
+self.vm.shutdown()
+os.remove(test_img)
+try:
+os.remove(target_img)
+except OSError:
+pass
+
+def test_mirror_discard(self):
+result = self.vm.qmp('drive-mirror', device='drive0', sync='full',
+ target=target_img)
+self.assert_qmp(result, 'return', {})
+self.vm.hmp_qemu_io('drive0', 'discard 0 64k')
+self.complete_and_wait('drive0')
+self.vm.shutdown()
+self.assertTrue(iotests.compare_images(test_img, target_img),
+'target image does not match source after mirroring')
+
+if __name__ == '__main__':
+iotests.main(supported_fmts=['raw'])
diff --git a/tests/qemu-iotests/131.out b/tests/qemu-iotests/131.out
new file mode 100644
index 000..ae1213e
--- /dev/null
+++ b/tests/qemu-iotests/131.out
@@ -0,0 +1,5 @@
+.
+--
+Ran 1 tests
+
+OK
diff --git a/tests/qemu-iotests/group b/tests/qemu-iotests/group
index 6ca3466..34b16cb 100644
--- a/tests/qemu-iotests/group
+++ b/tests/qemu-iotests/group
@@ -128,3 +128,4 @@
 128 rw auto quick
 129 rw auto quick
 130 rw auto quick
+131 rw auto quick
-- 
1.9.3




Re: [Qemu-devel] Fwd: qemu drive mirror assert fault

2015-05-05 Thread Kevin Wolf
Am 05.05.2015 um 13:49 hat Paolo Bonzini geschrieben:
 
 
 On 05/05/2015 13:48, Kevin Wolf wrote:
  It depends. In its basic form, bdrv_discard() just means I don't care
  about the data any more. Then clearing the dirty bitmap is correct.
  
  The content is only important if the caller used discard to write zeros
  because can_write_zeroes_with_unmap = true. Do we have any such callers
  apart from qemu-img convert?
 
 Yes, the SCSI command WRITE SAME with UNMAP = 1 (not coincidentially :))
 calls discard too.  Who knows what the guest used it for...
 
 However, write zeroes doesn't go through bdrv_co_discard, does it?

Initially I expected that it does, but when I checked, it turned out
that it uses a different path. The only thing I found that really uses
discard is the call in qemu-img that I mentioned. But that can't be the
cause of the corruption you're debugging.

Kevin



Re: [Qemu-devel] [PATCH v3 3/6] spapr_pci: encode class code including Prog IF register

2015-05-05 Thread David Gibson
On Tue, May 05, 2015 at 02:23:53PM +0530, Nikunj A Dadhania wrote:
 Current code missed the Prog IF register. All Class Code, Subclass,
 and Prog IF registers are needed to identify the accurate device type.
 
 For example: USB controllers use the PROG IF for denoting: USB
 FullSpeed, HighSpeed or SuperSpeed.
 
 Signed-off-by: Nikunj A Dadhania nik...@linux.vnet.ibm.com

Um.. I'm guessing the CLASS_PROG register essentially includes the
CLASS_DEVICE value?  Otherwise it looks like you're losing the
CLASS_DEVICE value.

For the benefit of those who don't remember the PCI spec from memory,
can you explain in more detail what the situation is with the several
class registers and how they overlap / interact.

 ---
  hw/ppc/spapr_pci.c | 3 +--
  1 file changed, 1 insertion(+), 2 deletions(-)
 
 diff --git a/hw/ppc/spapr_pci.c b/hw/ppc/spapr_pci.c
 index ea1a092..8b02a3e 100644
 --- a/hw/ppc/spapr_pci.c
 +++ b/hw/ppc/spapr_pci.c
 @@ -899,8 +899,7 @@ static int spapr_populate_pci_child_dt(PCIDevice *dev, 
 void *fdt, int offset,
  _FDT(fdt_setprop_cell(fdt, offset, revision-id,
pci_default_read_config(dev, PCI_REVISION_ID, 1)));
  _FDT(fdt_setprop_cell(fdt, offset, class-code,
 -  pci_default_read_config(dev, PCI_CLASS_DEVICE, 2)
 - 8));
 +  pci_default_read_config(dev, PCI_CLASS_PROG, 3)));
  if (pci_default_read_config(dev, PCI_INTERRUPT_PIN, 1)) {
  _FDT(fdt_setprop_cell(fdt, offset, interrupts,
   pci_default_read_config(dev, PCI_INTERRUPT_PIN, 1)));

-- 
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


pgpkBL8fDx4gG.pgp
Description: PGP signature


Re: [Qemu-devel] [PATCH qemu v7 08/14] spapr_pci: Do complete reset of DMA config when resetting PHB

2015-05-05 Thread David Gibson
On Sat, Apr 25, 2015 at 10:24:38PM +1000, Alexey Kardashevskiy wrote:
 On a system reset, DMA configuration has to reset too. At the moment
 it clears the table content. This is enough for the single table case
 but with DDW, we will also have to disable all DMA windows except
 the default one. Furthermore according to sPAPR, if the guest removed
 the default window and created a huge one at the same zero offset on
 a PCI bus, the reset handler has to recreate the default window with
 the default properties (2GB big, 4K pages).
 
 This reworks SPAPR PHB code to disable the existing DMA window on reset
 and then configure and enable the default window.
 Without DDW that means that the same window will be disabled and then
 enabled with no other change in behaviour.
 
 This changes the table creation to do it in one place in PHB (VFIO PHB
 just inherits the behaviour from PHB). The actual table allocation is
 done from the reset handler and this is where dma_init_window() is called.
 
 This disables all DMA windows on a PHB reset. It does not make any
 difference now as there is just one DMA window but it will later with DDW
 patches.
 
 This makes spapr_phb_dma_reset() and spapr_phb_dma_remove_window() public
 as these will be used in DDW RTAS ibm,reset-pe-dma-window and
 ibm,remove-pe-dma-window handlers later; the handlers will reside in
 hw/ppc/spapr_rtas_ddw.c.
 
 Signed-off-by: Alexey Kardashevskiy a...@ozlabs.ru

Reviewed-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


pgpERd1EAzbyd.pgp
Description: PGP signature


Re: [Qemu-devel] [PATCH v6 03/17] Extend QMP command query-cpus to return accelerator id and model name

2015-05-05 Thread Eduardo Habkost
On Mon, Apr 27, 2015 at 04:53:17PM +0200, Michael Mueller wrote:
 The QMP command query-cpus now additionally displays a model name and
 the backing accelerator. Both are omitted if the model name is not
 initialized.
 
   request:
 { execute : query-cpus }
 
   answer:
 { { current: true,
 CPU: 0,
 model: 2827-ga2,
 halted: false,
 accel: kvm,
 thread_id: 31917
   }, ... }
 
 Signed-off-by: Michael Mueller m...@linux.vnet.ibm.com
 Acked-by: Christian Borntraeger borntrae...@de.ibm.com

With the new qom-path field I submitted yesterday, this can be provided
as QOM properties through qom-get.

-- 
Eduardo



Re: [Qemu-devel] [PATCH qemu v7 14/14] vfio: Enable DDW ioctls to VFIO IOMMU driver

2015-05-05 Thread David Gibson
On Sat, Apr 25, 2015 at 10:24:44PM +1000, Alexey Kardashevskiy wrote:
 This enables DDW RTAS-related ioctls in VFIO.
 
 Signed-off-by: Alexey Kardashevskiy a...@ozlabs.ru

This patch belongs before the last one (since the last one won't work
without it).

But otherwise,

Reviewed-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


pgpTqGi6hHSc6.pgp
Description: PGP signature


Re: [Qemu-devel] [PATCH v6 04/17] Extend HMP command info cpus to display accelerator id and model name

2015-05-05 Thread Eduardo Habkost
On Mon, Apr 27, 2015 at 04:53:18PM +0200, Michael Mueller wrote:
 The HMP command info cpus now displays the CPU model name and the
 backing accelerator if part of the CPUState.
 
 (qemu) info cpus
 * CPU #0: (halted) model=2827-ga2 accel=kvm thread_id=1679
 
 Signed-off-by: Michael Mueller m...@linux.vnet.ibm.com
 Acked-by: Christian Borntraeger borntrae...@de.ibm.com

Do we really need this? I mean: I expect the amount of CPU data we
provide to QMP clients to grow a lot in the near future, but that
doesn't mean HMP users need all that data to be printed by info cpus.


 ---
  hmp.c | 7 +++
  1 file changed, 7 insertions(+)
 
 diff --git a/hmp.c b/hmp.c
 index f142d36..676d821 100644
 --- a/hmp.c
 +++ b/hmp.c
 @@ -290,6 +290,13 @@ void hmp_info_cpus(Monitor *mon, const QDict *qdict)
  monitor_printf(mon,  (halted));
  }
  
 +if (cpu-value-has_model) {
 +monitor_printf(mon,  model=%s, cpu-value-model);
 +}
 +if (cpu-value-has_accel) {
 +monitor_printf(mon,  accel=%s, 
 AccelId_lookup[cpu-value-accel]);
 +}
 +
  monitor_printf(mon,  thread_id=% PRId64 \n, 
 cpu-value-thread_id);
  }
  
 -- 
 1.8.3.1
 

-- 
Eduardo



Re: [Qemu-devel] [ARM]: Adding support for Cortex-M4

2015-05-05 Thread Liviu Ionescu

 On 05 May 2015, at 15:52, aurelio remonda aurelioremo...@gmail.com wrote:
 
 Hi, i would like to to add support for cortex-m4 on qemu. ...

For your information, I'm also planning to improve support for the Cortex-M 
family in my GNU ARM Eclipse QEMU fork. My first priority is fully supporting 
the Cortex-M system peripherals, then the main STM32F peripherals (like 
clocks), and later consider the M4 instruction set, so if you plan some work on 
this, perhaps it would be useful to coordinate our efforts.


regards,

Liviu




[Qemu-devel] [PATCH 5/5] gtk: update mouse position in mouse_set()

2015-05-05 Thread Gerd Hoffmann
Without that the next mouse motion event uses the old position
as base for relative move calculation, giving wrong results and
making your mouse pointer jump around.

Signed-off-by: Gerd Hoffmann kra...@redhat.com
---
 ui/gtk.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/ui/gtk.c b/ui/gtk.c
index 8b1458f..c58028f 100644
--- a/ui/gtk.c
+++ b/ui/gtk.c
@@ -463,6 +463,8 @@ static void gd_mouse_set(DisplayChangeListener *dcl,
 gdk_device_warp(gdk_device_manager_get_client_pointer(mgr),
 gtk_widget_get_screen(vc-gfx.drawing_area),
 x_root, y_root);
+vc-s-last_x = x;
+vc-s-last_y = y;
 }
 #else
 static void gd_mouse_set(DisplayChangeListener *dcl,
-- 
1.8.3.1




Re: [Qemu-devel] [RFC PATCH 14/15] spapr_pci: add ibm, my-drc-index property for PHB hotplug

2015-05-05 Thread David Gibson
On Wed, Apr 29, 2015 at 02:20:23PM -0500, Michael Roth wrote:
 This is needed to denote a boot-time PHB as being hot-pluggable.
 
 Signed-off-by: Michael Roth mdr...@linux.vnet.ibm.com

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

 ---
  hw/ppc/spapr_pci.c | 10 ++
  1 file changed, 10 insertions(+)
 
 diff --git a/hw/ppc/spapr_pci.c b/hw/ppc/spapr_pci.c
 index 66fe85f..91dfd96 100644
 --- a/hw/ppc/spapr_pci.c
 +++ b/hw/ppc/spapr_pci.c
 @@ -1572,6 +1572,7 @@ int spapr_populate_pci_dt(sPAPRPHBState *phb,
  cpu_to_be32(b_d(-1)|b_fff(0)), 0x0, 0x0, cpu_to_be32(-1)};
  uint32_t interrupt_map[PCI_SLOT_MAX * PCI_NUM_PINS][7];
  sPAPRTCETable *tcet;
 +sPAPRDRConnector *drc;
  
  /* Start populating the FDT */
  sprintf(nodename, pci@% PRIx64, phb-buid);
 @@ -1624,6 +1625,15 @@ int spapr_populate_pci_dt(sPAPRPHBState *phb,
   tcet-liobn, tcet-bus_offset,
   tcet-nb_table  tcet-page_shift);
  
 +drc = spapr_dr_connector_by_id(SPAPR_DR_CONNECTOR_TYPE_PHB, phb-index);
 +if (drc) {
 +sPAPRDRConnectorClass *drck = SPAPR_DR_CONNECTOR_GET_CLASS(drc);
 +uint32_t drc_index = cpu_to_be32(drck-get_index(drc));
 +
 +_FDT(fdt_setprop(fdt, bus_off, ibm,my-drc-index, drc_index,
 + sizeof(drc_index)));
 +}
 +
  ret = spapr_drc_populate_dt(fdt, bus_off, OBJECT(phb),
  SPAPR_DR_CONNECTOR_TYPE_PCI);
  if (ret) {

-- 
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


pgpkk_2piJIny.pgp
Description: PGP signature


Re: [Qemu-devel] [RFC PATCH 08/15] spapr: create DR connectors for PHBs and register reset hooks

2015-05-05 Thread David Gibson
On Wed, Apr 29, 2015 at 02:20:17PM -0500, Michael Roth wrote:
 Since we route hotplugged PHBs to their DR connector using their
 PHB.index value, we align the number of DR connectors with the
 maximum index value: SPAPR_PCI_MAX_INDEX.
 
 Signed-off-by: Michael Roth mdr...@linux.vnet.ibm.com

As with Bharata's similar patch, I'm not sure why the DRC needs an
explicitly registered reset, rather than -reset being called
automatically by the qdev model, but otherwise

Reviewed-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


pgpeIcWWwOsyA.pgp
Description: PGP signature


Re: [Qemu-devel] [RFC PATCH 15/15] spapr: add hotplug hooks for PHB hotplug

2015-05-05 Thread David Gibson
On Wed, Apr 29, 2015 at 02:20:24PM -0500, Michael Roth wrote:
 Hotplugging PHBs is a machine-level operation, but PHBs reside on the
 main system bus, so we register spapr machine as the handler for the
 main system bus. The entry point for plug/unplug is shared by all
 such machine-level hotplug operations (memory, CPU, PHB, etc), and
 from there we branch off to specific hotplug callbacks based on the
 object type.
 
 Signed-off-by: Michael Roth mdr...@linux.vnet.ibm.com

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

Although it will almost certainly need adjustment to fit with the cpu
and hotplug patches that are also pending.

-- 
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


pgpBKOKwgZ0aR.pgp
Description: PGP signature


Re: [Qemu-devel] [RFC PATCH 07/15] spapr: enable PHB hotplug for pseries-2.4

2015-05-05 Thread David Gibson
On Wed, Apr 29, 2015 at 02:20:16PM -0500, Michael Roth wrote:
 Introduce an sPAPRMachineClass sub-class of MachineClass to
 handle sPAPR-specific machine configuration properties.
 
 The 'dr_phb_enabled' field of that class can be set as
 part of machine-specific init code, and is then propagated
 to sPAPREnvironment to conditionally enable creation of DRC
 objects and device-tree description to facilitate hotplug
 of PHBs.
 
 Since we can't migrate this state to older machine types,
 default the option to false and only enable it for new
 machine types.
 
 Signed-off-by: Michael Roth mdr...@linux.vnet.ibm.com

This will obviously conflict with Bharata's patch doing much the same
thing for cpu and memory hotplug.

I'll try to put a patch in spapr-next tomorrow which adds an empty
sPAPRMachineClass which you can both then add fields to.

-- 
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


pgp0dWUKd7BVU.pgp
Description: PGP signature


Re: [Qemu-devel] [PATCH] QJSON: Use OBJECT_CHECK

2015-05-05 Thread Luiz Capitulino
On Tue, 05 May 2015 14:43:19 +0200
Juan Quintela quint...@redhat.com wrote:

 Eduardo Habkost ehabk...@redhat.com wrote:
  On Sat, Apr 25, 2015 at 07:05:55PM +0200, Andreas Färber wrote:
  Am 25.04.2015 um 17:28 schrieb Eduardo Habkost:
   The QJSON code used casts to (QJSON*) directly, instead of OBJECT_CHECK.
   There were even some functions using object_dynamic_cast() calls
   followed by assert(), which is exactly what OBJECT_CHECK does (by
   calling object_dynamic_cast_assert()).
  
  Suggest s/OBJECT_CHECK/OBJECT_CHECK()/g everywhere for clarity.
 
  I assume it can be fixed during commit by whoever is going to queue it.
 
  
   
   Signed-off-by: Eduardo Habkost ehabk...@redhat.com
   ---
qjson.c | 10 +-
1 file changed, 5 insertions(+), 5 deletions(-)
  
  Reviewed-by: Andreas Färber afaer...@suse.de
  
  Wasn't aware QJSON is using QOM - assuming this will go through some
  QAPI/QMP tree.
 
  The only user of qjson.c right now is migration code. Should it go through
  the migration tree?
 
 
 I will take it, but I trust your reviews-by O:-)

I've already applied this one to the QMP tree.

 
 
  Also, why do we have two JSON writers in QEMU? And why do they have
  exactly the same name?
 
 Alex?  I guess alex have this implementation when he did the code long
 ago?
 
 Later, Juan.
 




Re: [Qemu-devel] [PATCH v8 20/40] qapi: Better error messages for duplicated expressions

2015-05-05 Thread Eric Blake
On 05/05/2015 03:11 AM, Markus Armbruster wrote:
 Eric Blake ebl...@redhat.com writes:
 
 The previous commit demonstrated that the generator overlooked
 duplicate expressions:
 - a complex type or command reusing a built-in type name
 - redeclaration of a type name, whether by the same or different
 metatype
 - redeclaration of a command or event
 - collision of a type with implicit 'Kind' enum for a union
 - collision with an implicit MAX enum constant

 Since the c_type() function in the generator treats all names
 as being in the same namespace, this patch adds a global array
 to track all known names and their source, to prevent collisions
 before it can cause further problems.  While valid .json files
 won't trigger any of these cases, we might as well be nicer to
 developers that make a typo while trying to add new QAPI code.


 +def add_name(name, info, meta, implicit = False):
 +global all_names
 +if name in all_names:
 +raise QAPIExprError(info,
 +%s '%s' is already defined
 +%(all_names[name], name))
 
 Let's put a space between binary operator % and its right operand.

I was copying existing examples, but I can easily do a separate followup
patch that unifies the style of % formatting (or switches to +
concatenation where that is more legible).

 
 +if not implicit and name[-4:] == 'Kind':
 +raise QAPIExprError(info,
 +%s '%s' should not end in 'Kind'
 +%(meta, name))
 
 Likewise.  Can fix up on commit.

Of course, I'll wait until any of your fixups in the pull request are
already in place to write such a followup, to minimize rebase churn.

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



signature.asc
Description: OpenPGP digital signature


[Qemu-devel] [PATCH 1/5] console: delayed ui_info guest notification

2015-05-05 Thread Gerd Hoffmann
So we don't flood the guest with display change notifications
while the user resizes the window.

Signed-off-by: Gerd Hoffmann kra...@redhat.com
---
 ui/console.c | 22 +++---
 1 file changed, 19 insertions(+), 3 deletions(-)

diff --git a/ui/console.c b/ui/console.c
index f5295c4..248dd60 100644
--- a/ui/console.c
+++ b/ui/console.c
@@ -126,6 +126,7 @@ struct QemuConsole {
 Object *device;
 uint32_t head;
 QemuUIInfo ui_info;
+QEMUTimer *ui_timer;
 const GraphicHwOps *hw_ops;
 void *hw;
 
@@ -1383,14 +1384,28 @@ void 
unregister_displaychangelistener(DisplayChangeListener *dcl)
 gui_setup_refresh(ds);
 }
 
+static void dpy_set_ui_info_timer(void *opaque)
+{
+QemuConsole *con = opaque;
+
+con-hw_ops-ui_info(con-hw, con-head, con-ui_info);
+}
+
 int dpy_set_ui_info(QemuConsole *con, QemuUIInfo *info)
 {
 assert(con != NULL);
 con-ui_info = *info;
-if (con-hw_ops-ui_info) {
-return con-hw_ops-ui_info(con-hw, con-head, info);
+if (!con-hw_ops-ui_info) {
+return -1;
 }
-return -1;
+
+/*
+ * Typically we get a flood of these as the user resizes the window.
+ * Wait until the dust has settled (one second without updates), then
+ * go notify the guest.
+ */
+timer_mod(con-ui_timer, qemu_clock_get_ms(QEMU_CLOCK_REALTIME) + 1000);
+return 0;
 }
 
 void dpy_gfx_update(QemuConsole *con, int x, int y, int w, int h)
@@ -1724,6 +1739,7 @@ QemuConsole *graphic_console_init(DeviceState *dev, 
uint32_t head,
 ds = get_alloc_displaystate();
 trace_console_gfx_new();
 s = new_console(ds, GRAPHIC_CONSOLE, head);
+s-ui_timer = timer_new_ms(QEMU_CLOCK_REALTIME, dpy_set_ui_info_timer, s);
 graphic_console_set_hwops(s, hw_ops, opaque);
 if (dev) {
 object_property_set_link(OBJECT(s), OBJECT(dev), device,
-- 
1.8.3.1




[Qemu-devel] [PATCH 0/5] gtk: misc bits

2015-05-05 Thread Gerd Hoffmann
  Hi,

A few small gtk patches.  The two console patches are dependencies
for patch #3.  Adding ui_info is preparation for virtio-gpu merge:
virtio-gpu will be able to adapt the guest display to the user's window
size, simliar to how spice is doing it with the spice guest agent.
ui_info basically is the qemu-side infrastructure for this.

please review,
  Gerd

Gerd Hoffmann (5):
  console: delayed ui_info guest notification
  console: add dpy_ui_info_supported
  gtk: add ui_info support
  gtk: create gtk.h
  gtk: update mouse position in mouse_set()

 include/ui/console.h |  1 +
 include/ui/gtk.h | 76 ++
 ui/console.c | 27 +--
 ui/gtk.c | 94 +---
 4 files changed, 124 insertions(+), 74 deletions(-)
 create mode 100644 include/ui/gtk.h

-- 
1.8.3.1




Re: [Qemu-devel] Fwd: qemu drive mirror assert fault

2015-05-05 Thread Paolo Bonzini


On 05/05/2015 13:49, Paolo Bonzini wrote:
 
 
 On 05/05/2015 13:48, Kevin Wolf wrote:
 It depends. In its basic form, bdrv_discard() just means I don't care
 about the data any more. Then clearing the dirty bitmap is correct.

 The content is only important if the caller used discard to write zeros
 because can_write_zeroes_with_unmap = true. Do we have any such callers
 apart from qemu-img convert?
 
 Yes, the SCSI command WRITE SAME with UNMAP = 1 (not coincidentially :))
 calls discard too.

s/discard/write_zeroes/ of course!

Paolo

 Who knows what the guest used it for...
 However, write zeroes doesn't go through bdrv_co_discard, does it?
 
 Paolo
 
 



[Qemu-devel] [PATCH 4/5] gtk: create gtk.h

2015-05-05 Thread Gerd Hoffmann
Move various gtk bits (includes, data structures) to a header file.

Signed-off-by: Gerd Hoffmann kra...@redhat.com
---
 include/ui/gtk.h | 76 
 ui/gtk.c | 73 ++---
 2 files changed, 78 insertions(+), 71 deletions(-)
 create mode 100644 include/ui/gtk.h

diff --git a/include/ui/gtk.h b/include/ui/gtk.h
new file mode 100644
index 000..b750845
--- /dev/null
+++ b/include/ui/gtk.h
@@ -0,0 +1,76 @@
+#ifndef UI_GTK_H
+#define UI_GTK_H
+
+#ifdef _WIN32
+# define _WIN32_WINNT 0x0601 /* needed to get definition of MAPVK_VK_TO_VSC */
+#endif
+
+#ifdef CONFIG_PRAGMA_DIAGNOSTIC_AVAILABLE
+/* Work around an -Wstrict-prototypes warning in GTK headers */
+#pragma GCC diagnostic push
+#pragma GCC diagnostic ignored -Wstrict-prototypes
+#endif
+#include gtk/gtk.h
+#ifdef CONFIG_PRAGMA_DIAGNOSTIC_AVAILABLE
+#pragma GCC diagnostic pop
+#endif
+
+#include gdk/gdkkeysyms.h
+
+#ifdef GDK_WINDOWING_X11
+#include gdk/gdkx.h
+#include X11/XKBlib.h
+#endif
+
+/* Compatibility define to let us build on both Gtk2 and Gtk3 */
+#if GTK_CHECK_VERSION(3, 0, 0)
+static inline void gdk_drawable_get_size(GdkWindow *w, gint *ww, gint *wh)
+{
+*ww = gdk_window_get_width(w);
+*wh = gdk_window_get_height(w);
+}
+#endif
+
+typedef struct GtkDisplayState GtkDisplayState;
+
+typedef struct VirtualGfxConsole {
+GtkWidget *drawing_area;
+DisplayChangeListener dcl;
+DisplaySurface *ds;
+pixman_image_t *convert;
+cairo_surface_t *surface;
+double scale_x;
+double scale_y;
+} VirtualGfxConsole;
+
+#if defined(CONFIG_VTE)
+typedef struct VirtualVteConsole {
+GtkWidget *box;
+GtkWidget *scrollbar;
+GtkWidget *terminal;
+CharDriverState *chr;
+} VirtualVteConsole;
+#endif
+
+typedef enum VirtualConsoleType {
+GD_VC_GFX,
+GD_VC_VTE,
+} VirtualConsoleType;
+
+typedef struct VirtualConsole {
+GtkDisplayState *s;
+char *label;
+GtkWidget *window;
+GtkWidget *menu_item;
+GtkWidget *tab_item;
+GtkWidget *focus;
+VirtualConsoleType type;
+union {
+VirtualGfxConsole gfx;
+#if defined(CONFIG_VTE)
+VirtualVteConsole vte;
+#endif
+};
+} VirtualConsole;
+
+#endif /* UI_GTK_H */
diff --git a/ui/gtk.c b/ui/gtk.c
index 9163b43..8b1458f 100644
--- a/ui/gtk.c
+++ b/ui/gtk.c
@@ -34,24 +34,11 @@
 #define GETTEXT_PACKAGE qemu
 #define LOCALEDIR po
 
-#ifdef _WIN32
-# define _WIN32_WINNT 0x0601 /* needed to get definition of MAPVK_VK_TO_VSC */
-#endif
-
 #include qemu-common.h
 
-#ifdef CONFIG_PRAGMA_DIAGNOSTIC_AVAILABLE
-/* Work around an -Wstrict-prototypes warning in GTK headers */
-#pragma GCC diagnostic push
-#pragma GCC diagnostic ignored -Wstrict-prototypes
-#endif
-#include gtk/gtk.h
-#ifdef CONFIG_PRAGMA_DIAGNOSTIC_AVAILABLE
-#pragma GCC diagnostic pop
-#endif
-
+#include ui/console.h
+#include ui/gtk.h
 
-#include gdk/gdkkeysyms.h
 #include glib/gi18n.h
 #include locale.h
 #if defined(CONFIG_VTE)
@@ -60,7 +47,6 @@
 #include math.h
 
 #include trace.h
-#include ui/console.h
 #include ui/input.h
 #include sysemu/sysemu.h
 #include qmp-commands.h
@@ -68,10 +54,6 @@
 #include keymaps.h
 #include sysemu/char.h
 #include qom/object.h
-#ifdef GDK_WINDOWING_X11
-#include gdk/gdkx.h
-#include X11/XKBlib.h
-#endif
 
 #define MAX_VCS 10
 #define VC_WINDOW_X_MIN  320
@@ -99,15 +81,6 @@
 # define VTE_RESIZE_HACK 1
 #endif
 
-/* Compatibility define to let us build on both Gtk2 and Gtk3 */
-#if GTK_CHECK_VERSION(3, 0, 0)
-static inline void gdk_drawable_get_size(GdkWindow *w, gint *ww, gint *wh)
-{
-*ww = gdk_window_get_width(w);
-*wh = gdk_window_get_height(w);
-}
-#endif
-
 #if !GTK_CHECK_VERSION(2, 20, 0)
 #define gtk_widget_get_realized(widget) GTK_WIDGET_REALIZED(widget)
 #endif
@@ -138,48 +111,6 @@ static const int modifier_keycode[] = {
 0x2a, 0x36, 0x1d, 0x9d, 0x38, 0xb8, 0xdb, 0xdd,
 };
 
-typedef struct GtkDisplayState GtkDisplayState;
-
-typedef struct VirtualGfxConsole {
-GtkWidget *drawing_area;
-DisplayChangeListener dcl;
-DisplaySurface *ds;
-pixman_image_t *convert;
-cairo_surface_t *surface;
-double scale_x;
-double scale_y;
-} VirtualGfxConsole;
-
-#if defined(CONFIG_VTE)
-typedef struct VirtualVteConsole {
-GtkWidget *box;
-GtkWidget *scrollbar;
-GtkWidget *terminal;
-CharDriverState *chr;
-} VirtualVteConsole;
-#endif
-
-typedef enum VirtualConsoleType {
-GD_VC_GFX,
-GD_VC_VTE,
-} VirtualConsoleType;
-
-typedef struct VirtualConsole {
-GtkDisplayState *s;
-char *label;
-GtkWidget *window;
-GtkWidget *menu_item;
-GtkWidget *tab_item;
-GtkWidget *focus;
-VirtualConsoleType type;
-union {
-VirtualGfxConsole gfx;
-#if defined(CONFIG_VTE)
-VirtualVteConsole vte;
-#endif
-};
-} VirtualConsole;
-
 struct GtkDisplayState {
 GtkWidget *window;
 
-- 
1.8.3.1




[Qemu-devel] [PATCH v3 09/14] qapi: Support downstream enums

2015-05-05 Thread Eric Blake
Enhance the testsuite to cover a downstream enum type and enum
string.  Update the generator to mangle the enum name in the
appropriate places.  The code for generating list visitors must
be careful how it mangles names for enum lists differently than
code for builtin type lists.

Signed-off-by: Eric Blake ebl...@redhat.com
---
 scripts/qapi-types.py   | 15 ---
 scripts/qapi-visit.py   | 11 ++-
 tests/qapi-schema/qapi-schema-test.json |  3 +++
 tests/qapi-schema/qapi-schema-test.out  |  4 +++-
 4 files changed, 20 insertions(+), 13 deletions(-)

diff --git a/scripts/qapi-types.py b/scripts/qapi-types.py
index 9eb08a6..1593fc6 100644
--- a/scripts/qapi-types.py
+++ b/scripts/qapi-types.py
@@ -58,7 +58,7 @@ typedef struct %(name)sList
 struct %(name)sList *next;
 } %(name)sList;
 ''',
- name=name)
+ name=c_name(name))

 def generate_struct_fields(members):
 ret = ''
@@ -115,7 +115,7 @@ def generate_enum_lookup(name, values):
 ret = mcgen('''
 const char *%(name)s_lookup[] = {
 ''',
- name=name)
+name=c_name(name))
 i = 0
 for value in values:
 index = c_enum_const(name, value)
@@ -134,6 +134,7 @@ const char *%(name)s_lookup[] = {
 return ret

 def generate_enum(name, values):
+name = c_name(name)
 lookup_decl = mcgen('''
 extern const char *%(name)s_lookup[];
 ''',
@@ -247,15 +248,15 @@ extern const int %(name)s_qtypes[];

 def generate_type_cleanup_decl(name):
 ret = mcgen('''
-void qapi_free_%(type)s(%(c_type)s obj);
+void qapi_free_%(name)s(%(c_type)s obj);
 ''',
-c_type=c_type(name),type=name)
+c_type=c_type(name), name=c_name(name))
 return ret

 def generate_type_cleanup(name):
 ret = mcgen('''

-void qapi_free_%(type)s(%(c_type)s obj)
+void qapi_free_%(name)s(%(c_type)s obj)
 {
 QapiDeallocVisitor *md;
 Visitor *v;
@@ -266,11 +267,11 @@ void qapi_free_%(type)s(%(c_type)s obj)

 md = qapi_dealloc_visitor_new();
 v = qapi_dealloc_get_visitor(md);
-visit_type_%(type)s(v, obj, NULL, NULL);
+visit_type_%(name)s(v, obj, NULL, NULL);
 qapi_dealloc_visitor_cleanup(md);
 }
 ''',
-c_type=c_type(name),type=name)
+c_type=c_type(name), name=c_name(name))
 return ret


diff --git a/scripts/qapi-visit.py b/scripts/qapi-visit.py
index 0368e62..feb6c0b 100644
--- a/scripts/qapi-visit.py
+++ b/scripts/qapi-visit.py
@@ -146,7 +146,8 @@ void visit_type_%(name)s(Visitor *m, %(name)s **obj, const 
char *name, Error **e
 ''')
 return ret

-def generate_visit_list(name, members):
+def generate_visit_list(name, members, builtin=False):
+name = c_name(name, not builtin)
 return mcgen('''

 void visit_type_%(name)sList(Visitor *m, %(name)sList **obj, const char *name, 
Error **errp)
@@ -183,7 +184,7 @@ void visit_type_%(name)s(Visitor *m, %(name)s *obj, const 
char *name, Error **er
 visit_type_enum(m, (int *)obj, %(name)s_lookup, %(name)s, name, errp);
 }
 ''',
- name=name)
+ name=c_name(name))

 def generate_visit_alternate(name, members):
 ret = mcgen('''
@@ -364,7 +365,7 @@ def generate_enum_declaration(name, members):
 ret = mcgen('''
 void visit_type_%(name)sList(Visitor *m, %(name)sList **obj, const char *name, 
Error **errp);
 ''',
-name=name)
+name=c_name(name))

 return ret

@@ -373,7 +374,7 @@ def generate_decl_enum(name, members):

 void visit_type_%(name)s(Visitor *m, %(name)s *obj, const char *name, Error 
**errp);
 ''',
-name=name)
+ name=c_name(name))

 try:
 opts, args = getopt.gnu_getopt(sys.argv[1:], chbp:i:o:,
@@ -490,7 +491,7 @@ fdecl.write(guardend(QAPI_VISIT_BUILTIN_VISITOR_DECL))
 # over these cases
 if do_builtins:
 for typename in builtin_types.keys():
-fdef.write(generate_visit_list(typename, None))
+fdef.write(generate_visit_list(typename, None, builtin=True))

 for expr in exprs:
 if expr.has_key('struct'):
diff --git a/tests/qapi-schema/qapi-schema-test.json 
b/tests/qapi-schema/qapi-schema-test.json
index 8193dc1..5f9af66 100644
--- a/tests/qapi-schema/qapi-schema-test.json
+++ b/tests/qapi-schema/qapi-schema-test.json
@@ -107,3 +107,6 @@
   'data': { '*a': 'int', '*b': 'UserDefOne', 'c': 'str' } }
 { 'event': 'EVENT_D',
   'data': { 'a' : 'EventStructOne', 'b' : 'str', '*c': 'str', '*enum3': 
'EnumOne' } }
+
+# test that we correctly compile downstream extensions
+{ 'enum': '__org.qemu_x-Enum', 'data': [ '__org.qemu_x-value' ] }
diff --git a/tests/qapi-schema/qapi-schema-test.out 
b/tests/qapi-schema/qapi-schema-test.out
index 93c4963..40f0f20 100644
--- a/tests/qapi-schema/qapi-schema-test.out
+++ b/tests/qapi-schema/qapi-schema-test.out
@@ -22,8 +22,10 @@
  OrderedDict([('event', 'EVENT_A')]),
  OrderedDict([('event', 'EVENT_B'), ('data', OrderedDict())]),
  

[Qemu-devel] [PATCH v3 06/14] qapi: Use c_enum_const() in generate_alternate_qtypes()

2015-05-05 Thread Eric Blake
From: Markus Armbruster arm...@redhat.com

Missed in commit b0b5819.

Signed-off-by: Markus Armbruster arm...@redhat.com
Signed-off-by: Eric Blake ebl...@redhat.com
---
 scripts/qapi-types.py |  6 ++
 scripts/qapi.py   | 11 ---
 2 files changed, 2 insertions(+), 15 deletions(-)

diff --git a/scripts/qapi-types.py b/scripts/qapi-types.py
index 6ca48c1..9eb08a6 100644
--- a/scripts/qapi-types.py
+++ b/scripts/qapi-types.py
@@ -180,11 +180,9 @@ const int %(name)s_qtypes[QTYPE_MAX] = {
 assert qtype, Invalid alternate member

 ret += mcgen('''
-[ %(qtype)s ] = %(abbrev)s_KIND_%(enum)s,
+[ %(qtype)s ] = %(enum_const)s,
 ''',
-qtype = qtype,
-abbrev = de_camel_case(name).upper(),
-enum = c_name(de_camel_case(key),False).upper())
+qtype = qtype, enum_const = c_enum_const(name + 'Kind', key))

 ret += mcgen('''
 };
diff --git a/scripts/qapi.py b/scripts/qapi.py
index 9209fd5..967dadb 100644
--- a/scripts/qapi.py
+++ b/scripts/qapi.py
@@ -729,17 +729,6 @@ def parse_args(typeinfo):
 # value of an optional argument.
 yield (argname, argentry, optional)

-def de_camel_case(name):
-new_name = ''
-for ch in name:
-if ch.isupper() and new_name:
-new_name += '_'
-if ch == '-':
-new_name += '_'
-else:
-new_name += ch.lower()
-return new_name
-
 def camel_case(name):
 new_name = ''
 first = True
-- 
2.1.0




[Qemu-devel] [PATCH 2/4] block: Remove bdrv_reset_dirty

2015-05-05 Thread Fam Zheng
Using this function woule always be wrong because a dirty bitmap must
have a specific owner that consumes the dirty bits and calls
bdrv_reset_dirty_bitmap().

Remove the unused function to avoid future misuse.

Signed-off-by: Fam Zheng f...@redhat.com
---
 block.c   | 12 
 include/block/block_int.h |  2 --
 2 files changed, 14 deletions(-)

diff --git a/block.c b/block.c
index 7904098..511e13c 100644
--- a/block.c
+++ b/block.c
@@ -3324,18 +3324,6 @@ void bdrv_set_dirty(BlockDriverState *bs, int64_t 
cur_sector,
 }
 }
 
-void bdrv_reset_dirty(BlockDriverState *bs, int64_t cur_sector,
-  int nr_sectors)
-{
-BdrvDirtyBitmap *bitmap;
-QLIST_FOREACH(bitmap, bs-dirty_bitmaps, list) {
-if (!bdrv_dirty_bitmap_enabled(bitmap)) {
-continue;
-}
-hbitmap_reset(bitmap-bitmap, cur_sector, nr_sectors);
-}
-}
-
 /**
  * Advance an HBitmapIter to an arbitrary offset.
  */
diff --git a/include/block/block_int.h b/include/block/block_int.h
index db29b74..aaed2fa 100644
--- a/include/block/block_int.h
+++ b/include/block/block_int.h
@@ -635,7 +635,5 @@ bool blk_dev_is_medium_locked(BlockBackend *blk);
 void blk_dev_resize_cb(BlockBackend *blk);
 
 void bdrv_set_dirty(BlockDriverState *bs, int64_t cur_sector, int nr_sectors);
-void bdrv_reset_dirty(BlockDriverState *bs, int64_t cur_sector,
-  int nr_sectors);
 
 #endif /* BLOCK_INT_H */
-- 
1.9.3




[Qemu-devel] [PATCH 3/4] qemu-iotests: Make block job methods common

2015-05-05 Thread Fam Zheng
Signed-off-by: Fam Zheng f...@redhat.com
---
 tests/qemu-iotests/041| 66 ++-
 tests/qemu-iotests/iotests.py | 28 ++
 2 files changed, 43 insertions(+), 51 deletions(-)

diff --git a/tests/qemu-iotests/041 b/tests/qemu-iotests/041
index 59a8f73..3d46ed7 100755
--- a/tests/qemu-iotests/041
+++ b/tests/qemu-iotests/041
@@ -34,38 +34,8 @@ quorum_img3 = os.path.join(iotests.test_dir, 'quorum3.img')
 quorum_repair_img = os.path.join(iotests.test_dir, 'quorum_repair.img')
 quorum_snapshot_file = os.path.join(iotests.test_dir, 'quorum_snapshot.img')
 
-class ImageMirroringTestCase(iotests.QMPTestCase):
-'''Abstract base class for image mirroring test cases'''
 
-def wait_ready(self, drive='drive0'):
-'''Wait until a block job BLOCK_JOB_READY event'''
-ready = False
-while not ready:
-for event in self.vm.get_qmp_events(wait=True):
-if event['event'] == 'BLOCK_JOB_READY':
-self.assert_qmp(event, 'data/type', 'mirror')
-self.assert_qmp(event, 'data/device', drive)
-ready = True
-
-def wait_ready_and_cancel(self, drive='drive0'):
-self.wait_ready(drive=drive)
-event = self.cancel_and_wait(drive=drive)
-self.assertEquals(event['event'], 'BLOCK_JOB_COMPLETED')
-self.assert_qmp(event, 'data/type', 'mirror')
-self.assert_qmp(event, 'data/offset', event['data']['len'])
-
-def complete_and_wait(self, drive='drive0', wait_ready=True):
-'''Complete a block job and wait for it to finish'''
-if wait_ready:
-self.wait_ready(drive=drive)
-
-result = self.vm.qmp('block-job-complete', device=drive)
-self.assert_qmp(result, 'return', {})
-
-event = self.wait_until_completed(drive=drive)
-self.assert_qmp(event, 'data/type', 'mirror')
-
-class TestSingleDrive(ImageMirroringTestCase):
+class TestSingleDrive(iotests.QMPTestCase):
 image_len = 1 * 1024 * 1024 # MB
 
 def setUp(self):
@@ -221,17 +191,9 @@ class TestSingleDriveUnalignedLength(TestSingleDrive):
 test_small_buffer2 = None
 test_large_cluster = None
 
-class TestMirrorNoBacking(ImageMirroringTestCase):
+class TestMirrorNoBacking(iotests.QMPTestCase):
 image_len = 2 * 1024 * 1024 # MB
 
-def complete_and_wait(self, drive='drive0', wait_ready=True):
-iotests.create_image(target_backing_img, TestMirrorNoBacking.image_len)
-return ImageMirroringTestCase.complete_and_wait(self, drive, 
wait_ready)
-
-def compare_images(self, img1, img2):
-iotests.create_image(target_backing_img, TestMirrorNoBacking.image_len)
-return iotests.compare_images(img1, img2)
-
 def setUp(self):
 iotests.create_image(backing_img, TestMirrorNoBacking.image_len)
 qemu_img('create', '-f', iotests.imgfmt, '-o', 'backing_file=%s' % 
backing_img, test_img)
@@ -242,7 +204,10 @@ class TestMirrorNoBacking(ImageMirroringTestCase):
 self.vm.shutdown()
 os.remove(test_img)
 os.remove(backing_img)
-os.remove(target_backing_img)
+try:
+os.remove(target_backing_img)
+except:
+pass
 os.remove(target_img)
 
 def test_complete(self):
@@ -257,7 +222,7 @@ class TestMirrorNoBacking(ImageMirroringTestCase):
 result = self.vm.qmp('query-block')
 self.assert_qmp(result, 'return[0]/inserted/file', target_img)
 self.vm.shutdown()
-self.assertTrue(self.compare_images(test_img, target_img),
+self.assertTrue(iotests.compare_images(test_img, target_img),
 'target image does not match source after mirroring')
 
 def test_cancel(self):
@@ -272,7 +237,7 @@ class TestMirrorNoBacking(ImageMirroringTestCase):
 result = self.vm.qmp('query-block')
 self.assert_qmp(result, 'return[0]/inserted/file', test_img)
 self.vm.shutdown()
-self.assertTrue(self.compare_images(test_img, target_img),
+self.assertTrue(iotests.compare_images(test_img, target_img),
 'target image does not match source after mirroring')
 
 def test_large_cluster(self):
@@ -283,7 +248,6 @@ class TestMirrorNoBacking(ImageMirroringTestCase):
 %(TestMirrorNoBacking.image_len), target_backing_img)
 qemu_img('create', '-f', iotests.imgfmt, '-o', 
'cluster_size=%d,backing_file=%s'
 % (TestMirrorNoBacking.image_len, target_backing_img), 
target_img)
-os.remove(target_backing_img)
 
 result = self.vm.qmp('drive-mirror', device='drive0', sync='full',
  mode='existing', target=target_img)
@@ -293,10 +257,10 @@ class TestMirrorNoBacking(ImageMirroringTestCase):
 result = self.vm.qmp('query-block')
 self.assert_qmp(result, 'return[0]/inserted/file', target_img)
 self.vm.shutdown()
-

[Qemu-devel] [PATCH 1/4] block: Fix dirty bitmap in bdrv_co_discard

2015-05-05 Thread Fam Zheng
Unsetting dirty globally with discard is not very correct. The discard may zero
out sectors (depending on can_write_zeroes_with_unmap), we should replicate
this change to destinition side to make sure that the guest sees the same data.

Calling bdrv_reset_dirty also troubles mirror job because the hbitmap iterator
doesn't expect unsetting of bits after current position.

So let's do it the opposite way which fixes both problems: set the dirty bits
if we are to discard it.

Reported-by: wangxiaol...@ucloud.cn
Signed-off-by: Fam Zheng f...@redhat.com
---
 block/io.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/block/io.c b/block/io.c
index 1ce62c4..809688b 100644
--- a/block/io.c
+++ b/block/io.c
@@ -2343,8 +2343,6 @@ int coroutine_fn bdrv_co_discard(BlockDriverState *bs, 
int64_t sector_num,
 return -EROFS;
 }
 
-bdrv_reset_dirty(bs, sector_num, nb_sectors);
-
 /* Do nothing if disabled.  */
 if (!(bs-open_flags  BDRV_O_UNMAP)) {
 return 0;
@@ -2354,6 +2352,8 @@ int coroutine_fn bdrv_co_discard(BlockDriverState *bs, 
int64_t sector_num,
 return 0;
 }
 
+bdrv_set_dirty(bs, sector_num, nb_sectors);
+
 max_discard = MIN_NON_ZERO(bs-bl.max_discard, BDRV_REQUEST_MAX_SECTORS);
 while (nb_sectors  0) {
 int ret;
-- 
1.9.3




Re: [Qemu-devel] [PATCH 1/6] qcow2: use one single memory block for the L2/refcount cache tables

2015-05-05 Thread Alberto Garcia
On Thu 30 Apr 2015 05:08:05 PM CEST, Eric Blake ebl...@redhat.com wrote:

  typedef struct Qcow2CachedTable {
 -void*   table;
  int64_t offset;
  booldirty;
  int cache_hits;
 @@ -40,39 +39,34 @@ struct Qcow2Cache {
  struct Qcow2Cache*  depends;
  int size;
  booldepends_on_flush;
 +void   *table_array;
 +int table_size;

 Should this be size_t? [1]

The maximum supported table size is 2MB (MAX_CLUSTER_BITS == 21).

  c-entries = g_try_new0(Qcow2CachedTable, num_tables);
 -if (!c-entries) {
 -goto fail;
 -}
 +c-table_array = qemu_try_blockalign(bs-file, num_tables * 
 c-table_size);

 Are we sure this won't overflow?

That's a good catch. I was making some numbers and I doubt that scenario
would happen in practice, but I think it's possible so I'll fix it.

Berto



Re: [Qemu-devel] [ARM]: Adding support for Cortex-M4

2015-05-05 Thread Peter Maydell
On 5 May 2015 at 13:52, aurelio remonda aurelioremo...@gmail.com wrote:
 Hi, i would like to to add support for cortex-m4 on qemu. Most features of
 the Cortex-M3 and M4 are the same with the significant difference that
 Cortex-M4 has DSP extensions and optional FPU. Even so, i really need some
 pointers for this (im a newbie on qemu devel). I found out that qemu can
 manage dsp instructions such as ADD16, ASX, SAX, etc. and all their
 combinations with suffixes (u, s, sh, etc.), so half (if not all) of the
 work is done.

To quote something from the mail I wrote last time somebody
asked about Cortex-M4:

The instructions themselves are generally supported for
the A profile cores, so getting that part right would mostly
involve enabling those feature bits for the new M4 CPU class.
The difficult bits are going to involve:
 * correct trapping when fp is disabled
 * getting the exception handling right, including lazy
   exception frame population
 * bits where M profile FP differs from A profile (eg fp
   status and ID registers being memory mapped)

 How should I go about this? What's the standard procedure for adding a new
 CPU, even if it's so similar to the existing ones? That is, which are the
 relevant functions/files that I should modify, and so on.

For a new ARM CPU, the files you want are all in target-arm/.

-- PMM



Re: [Qemu-devel] [RFC PATCH 09/15] spapr: populate PHB DRC entries for root DT node

2015-05-05 Thread David Gibson
On Wed, Apr 29, 2015 at 02:20:18PM -0500, Michael Roth wrote:
 From: Nathan Fontenot nf...@linux.vnet.ibm.com
 
 This add entries to the root OF node to advertise our PHBs as being
 DR-capable in accordance with PAPR specification.
 
 Signed-off-by: Nathan Fontenot nf...@linux.vnet.ibm.com
 Signed-off-by: Michael Roth mdr...@linux.vnet.ibm.com
 ---
  hw/ppc/spapr.c | 9 +
  1 file changed, 9 insertions(+)
 
 diff --git a/hw/ppc/spapr.c b/hw/ppc/spapr.c
 index c539932..a7af332 100644
 --- a/hw/ppc/spapr.c
 +++ b/hw/ppc/spapr.c
 @@ -57,6 +57,7 @@
  #include qemu/error-report.h
  #include trace.h
  #include hw/nmi.h
 +#include hw/ppc/spapr_drc.h
  
  #include hw/compat.h
  
 @@ -745,6 +746,7 @@ static void spapr_finalize_fdt(sPAPREnvironment *spapr,
  size_t cb = 0;
  char *bootlist;
  void *fdt;
 +int fdt_offset;
  sPAPRPHBState *phb;
  
  fdt = g_malloc(FDT_MAX_SIZE);
 @@ -804,6 +806,13 @@ static void spapr_finalize_fdt(sPAPREnvironment *spapr,
  spapr_populate_chosen_stdout(fdt, spapr-vio_bus);
  }
  
 +fdt_offset = fdt_path_offset(fdt, /);
 +ret = spapr_drc_populate_dt(fdt, fdt_offset, NULL,
 +SPAPR_DR_CONNECTOR_TYPE_PHB);
 +if (ret  0) {
 +fprintf(stderr, Couldn't set up RTAS device tree properties\n);

This error message isn't right.

Otherwise,

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

 +}
 +
  _FDT((fdt_pack(fdt)));
  
  if (fdt_totalsize(fdt)  FDT_MAX_SIZE) {

-- 
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


pgpndzPveCr3s.pgp
Description: PGP signature


Re: [Qemu-devel] [RFC PATCH 10/15] spapr_events: add support for phb hotplug events

2015-05-05 Thread David Gibson
On Wed, Apr 29, 2015 at 02:20:19PM -0500, Michael Roth wrote:
 Extend the existing EPOW event format we use for PCI
 devices to emit PHB plug/unplug events.
 
 Signed-off-by: Michael Roth mdr...@linux.vnet.ibm.com

Reviewed-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


pgpRoNS4pauOe.pgp
Description: PGP signature


Re: [Qemu-devel] [PATCH v4 0/4] scripts: qmp-shell: add transaction support

2015-05-05 Thread Luiz Capitulino
On Mon, 04 May 2015 15:24:02 -0400
John Snow js...@redhat.com wrote:

 Ping
 (I should've CC'd Luiz to begin with ...)
 
 Eric's given this series the once over and Kashyap has tested it, so it 
 should in theory be good to go.

I lost track of it. Is v4 a new posting?

 
 On 04/29/2015 03:14 PM, John Snow wrote:
  The qmp-shell is a little rudimentary, but it can be hacked
  to give us some transactional support without too much difficulty.
 
  (1) Prep.
  (2) Add support for serializing json arrays and
   improve the robustness of QMP parsing
  (3) Add a special transaction( ... ) syntax that lets users
   build up transactional commands using the existing qmp shell
   syntax to define each action.
  (4) Add a verbose flag to display generated QMP commands.
 
  The parsing is not as robust as one would like, but this suffices
  without adding a proper parser.
 
  Design considerations:
 
  (1) Try not to disrupt the existing design of the qmp-shell. The existing
   API is not disturbed.
  (2) Pick a magic token such that it could not be confused for legitimate
   QMP/JSON syntax. Parentheses are used for this purpose.
 
  For convenience, this branch is available at:
  https://github.com/jnsnow/qemu.git branch qmp-shell++
  This version is tagged qmp-shell++-v4.
 
  ===
  v++
  ===
 
- Use the AST to allow 'true', 'false' and 'null' within QMP expressions
- Fix a bunch of stupid junk I broke in v2, apparently.
 
  ===
  v3:
  ===
 
- Folding in hotfix from list (import ast)
 
  ===
  v2:
  ===
 
- Squash patches 2  3:
- Remove wholesale replacement of single quotes, in favor of try blocks
  that attempt to parse as pure JSON, then as Python.
- Factored out the value parser block to accomplish the above.
- Allow both true/True and false/False for values.
- Fix typo in patch 3 cover letter. (was patch 4.)
 
  John Snow (4):
 scripts: qmp-shell: refactor helpers
 scripts: qmp-shell: Expand support for QMP expressions
 scripts: qmp-shell: add transaction subshell
 scripts: qmp-shell: Add verbose flag
 
scripts/qmp/qmp-shell | 147 
  +++---
1 file changed, 116 insertions(+), 31 deletions(-)
 
 




Re: [Qemu-devel] [PATCH v5 4/7] vmport_rpc: Add QMP access to vmport_rpc object.

2015-05-05 Thread Eric Blake
On 04/30/2015 12:20 PM, Don Slutz wrote:
 This adds one new inject command:
 
 inject-vmport-action
 
 And three guest info commands:
 
 vmport-guestinfo-set
 vmport-guestinfo-get
 query-vmport-guestinfo
 
 More details in qmp-commands.hx
 
 Signed-off-by: Don Slutz dsl...@verizon.com
 ---

 +++ b/qapi-schema.json
 @@ -1295,6 +1295,96 @@
  { 'command': 'inject-nmi' }
  

 +##
 +# @vmport-guestinfo-get:
 +#
 +# Get a VMWare Tools guestinfo value for a key
 +#
 +# @key: the key to get
 +#
 +# @format: #optional data encoding (default 'utf8').
 +#  - base64: the value is returned in base64 encoding.
 +#  - utf8: the value is interpreted as UTF-8.
 +#
 +# Returns: value for the guest info key
 +#
 +# Since: 2.4
 +##
 +{ 'command': 'vmport-guestinfo-get',
 +  'data': {'key': 'str', '*format': 'DataFormat'},
 +  'returns': 'str' }

Returning a non-dictionary is not extensible.  Once my qapi nested
struct series is applied, you'd have to modify the whitelist to allow
this command.  Better would be to return things in a dictionary, as in:

{ 'command': 'vmport-guestinfo-get',
  'data': {'key': 'str', '*format': 'DataFormat'},
  'returns': {'data':'str'} }

 +
 +##
 +# @VmportGuestInfo:
 +#
 +# Information about a single VMWare Tools guestinfo
 +#
 +# @key: The known key
 +#
 +# Since: 2.4
 +##
 +{ 'type': 'VmportGuestInfo', 'data': {'key': 'str'} }

Also, once my series is in, you'll need to s/type/struct/


 +++ b/qmp-commands.hx
 @@ -490,6 +490,126 @@ Note: inject-nmi fails when the guest doesn't support 
 injecting.
  EQMP
  
  {
 +.name   = inject-vmport-action,
 +.args_type  = action:s,
 +.mhandler.cmd_new = qmp_marshal_input_inject_vmport_action,
 +},
 +
 +SQMP
 +inject-vmport-action
 +--

Cosmetic, but the majority of the file matches the length of the -
to the command it is underlining.


 +
 +- { execute: vmport-guestinfo-get,
 +arguments: { key: foo,
 +   format: utf8 } }
 +- {return: abcdefgh}

Again, I don't like the notion of returning a non-dictionary without
good cause.


 +- { execute: query-vmport-guestinfo }
 +- {
 +  return: [
 + {
 +key: ip,
 + },

Invalid JSON - no trailing commas allowed in the objects.

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



signature.asc
Description: OpenPGP digital signature


Re: [Qemu-devel] Fwd: qemu drive mirror assert fault

2015-05-05 Thread Paolo Bonzini


On 05/05/2015 15:03, Kevin Wolf wrote:
  Yes, the SCSI command WRITE SAME with UNMAP = 1 (not coincidentially :))
  calls discard too.  Who knows what the guest used it for...
  
  However, write zeroes doesn't go through bdrv_co_discard, does it?
 
 Initially I expected that it does, but when I checked, it turned out
 that it uses a different path. The only thing I found that really uses
 discard is the call in qemu-img that I mentioned. But that can't be the
 cause of the corruption you're debugging.

I'm not seeing corruption; it's a crash in drive-mirror.

The question is how to treat discard:

1) mark sectors as dirty, discard on the destination as well (similar to
Fam's just-posted patches, but they do not discard on the destination)

2) keep marking sectors as not dirty, change util/hbitmap.c to avoid the
assertion failure.  This loses the discard on the destination but no
need to change block/mirror.c

Both are valid approaches.

Paolo



Re: [Qemu-devel] [PATCH qemu v7 06/14] spapr_iommu: Introduce enabled state for TCE table

2015-05-05 Thread David Gibson
On Sat, Apr 25, 2015 at 10:24:36PM +1000, Alexey Kardashevskiy wrote:
 Currently TCE tables are created once at start and their size never
 changes. We are going to change that by introducing a Dynamic DMA windows
 support where DMA configuration may change during the guest execution.
 
 This changes spapr_tce_new_table() to create an empty stub object. Only
 LIOBN is assigned by the time of creation. It still will be called once
 at the owner object (VIO or PHB) creation.
 
 This introduces an enabled state for TCE table objects with two
 helper functions - spapr_tce_table_enable()/spapr_tce_table_disable().
 spapr_tce_table_enable() receives TCE table parameters and allocates
 a guest view of the TCE table (in the user space or KVM).
 spapr_tce_table_disable() disposes the table.
 
 Follow up patches will disable+enable tables on reset (system reset
 or DDW reset).
 
 No visible change in behaviour is expected except the actual table
 will be reallocated every reset. We might optimize this later.
 
 The other way to implement this would be dynamically create/remove
 the TCE table QOM objects but this would make migration impossible
 as migration expects all QOM objects to exist at the receiver
 so we have to have TCE table objects created when migration begins.
 
 spapr_tce_table_do_enable() is separated from from spapr_tce_table_enable()
 as later it will be called at the sPAPRTCETable post-migration stage when
 it has all the properties set after the migration.
 
 Signed-off-by: Alexey Kardashevskiy a...@ozlabs.ru

Reviewed-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


pgpgab8NzxIQh.pgp
Description: PGP signature


[Qemu-devel] [PATCH v3 11/14] qapi: Support downstream simple unions

2015-05-05 Thread Eric Blake
Enhance the testsuite to cover downstream simple unions, including
when a union branch is a downstream name.  Update the generator to
mangle the union names in the appropriate places.

Signed-off-by: Eric Blake ebl...@redhat.com
---
 scripts/qapi-types.py   | 2 +-
 scripts/qapi-visit.py   | 8 
 tests/qapi-schema/qapi-schema-test.json | 1 +
 tests/qapi-schema/qapi-schema-test.out  | 6 --
 4 files changed, 10 insertions(+), 7 deletions(-)

diff --git a/scripts/qapi-types.py b/scripts/qapi-types.py
index 5118151..5b0bc5d 100644
--- a/scripts/qapi-types.py
+++ b/scripts/qapi-types.py
@@ -193,7 +193,7 @@ const int %(name)s_qtypes[QTYPE_MAX] = {

 def generate_union(expr, meta):

-name = expr[meta]
+name = c_name(expr[meta])
 typeinfo = expr['data']

 base = expr.get('base')
diff --git a/scripts/qapi-visit.py b/scripts/qapi-visit.py
index a7486ec..1397707 100644
--- a/scripts/qapi-visit.py
+++ b/scripts/qapi-visit.py
@@ -256,9 +256,9 @@ def generate_visit_union(expr):
 disc_type = enum_define['enum_name']
 else:
 # There will always be a discriminator in the C switch code, by default
-# it is an enum type generated silently as '%sKind' % (name)
-ret = generate_visit_enum('%sKind' % name, members.keys())
-disc_type = '%sKind' % (name)
+# it is an enum type generated silently
+ret = generate_visit_enum(name + 'Kind', members.keys())
+disc_type = c_name(name) + 'Kind'

 if base:
 assert discriminator
@@ -282,7 +282,7 @@ void visit_type_%(name)s(Visitor *m, %(name)s **obj, const 
char *name, Error **e
 }
 if (*obj) {
 ''',
- name=name)
+ name=c_name(name))

 if base:
 ret += mcgen('''
diff --git a/tests/qapi-schema/qapi-schema-test.json 
b/tests/qapi-schema/qapi-schema-test.json
index ca9b34c..6416d85 100644
--- a/tests/qapi-schema/qapi-schema-test.json
+++ b/tests/qapi-schema/qapi-schema-test.json
@@ -114,3 +114,4 @@
   'data': { '__org.qemu_x-member1': '__org.qemu_x-Enum' } }
 { 'struct': '__org.qemu_x-Struct', 'base': '__org.qemu_x-Base',
   'data': { '__org.qemu_x-member2': 'str' } }
+{ 'union': '__org.qemu_x-Union1', 'data': { '__org.qemu_x-branch': 'str' } }
diff --git a/tests/qapi-schema/qapi-schema-test.out 
b/tests/qapi-schema/qapi-schema-test.out
index 6ab4f00..f9ebe08 100644
--- a/tests/qapi-schema/qapi-schema-test.out
+++ b/tests/qapi-schema/qapi-schema-test.out
@@ -25,11 +25,13 @@
  OrderedDict([('event', 'EVENT_D'), ('data', OrderedDict([('a', 
'EventStructOne'), ('b', 'str'), ('*c', 'str'), ('*enum3', 'EnumOne')]))]),
  OrderedDict([('enum', '__org.qemu_x-Enum'), ('data', 
['__org.qemu_x-value'])]),
  OrderedDict([('struct', '__org.qemu_x-Base'), ('data', 
OrderedDict([('__org.qemu_x-member1', '__org.qemu_x-Enum')]))]),
- OrderedDict([('struct', '__org.qemu_x-Struct'), ('base', 
'__org.qemu_x-Base'), ('data', OrderedDict([('__org.qemu_x-member2', 
'str')]))])]
+ OrderedDict([('struct', '__org.qemu_x-Struct'), ('base', 
'__org.qemu_x-Base'), ('data', OrderedDict([('__org.qemu_x-member2', 
'str')]))]),
+ OrderedDict([('union', '__org.qemu_x-Union1'), ('data', 
OrderedDict([('__org.qemu_x-branch', 'str')]))])]
 [{'enum_name': 'EnumOne', 'enum_values': ['value1', 'value2', 'value3']},
  {'enum_name': '__org.qemu_x-Enum', 'enum_values': ['__org.qemu_x-value']},
  {'enum_name': 'UserDefAlternateKind', 'enum_values': None},
- {'enum_name': 'UserDefNativeListUnionKind', 'enum_values': None}]
+ {'enum_name': 'UserDefNativeListUnionKind', 'enum_values': None},
+ {'enum_name': '__org.qemu_x-Union1Kind', 'enum_values': None}]
 [OrderedDict([('struct', 'NestedEnumsOne'), ('data', OrderedDict([('enum1', 
'EnumOne'), ('*enum2', 'EnumOne'), ('enum3', 'EnumOne'), ('*enum4', 
'EnumOne')]))]),
  OrderedDict([('struct', 'UserDefZero'), ('data', OrderedDict([('integer', 
'int')]))]),
  OrderedDict([('struct', 'UserDefOne'), ('base', 'UserDefZero'), ('data', 
OrderedDict([('string', 'str'), ('*enum1', 'EnumOne')]))]),
-- 
2.1.0




[Qemu-devel] [PATCH v3 04/14] qapi: Rename generate_enum_full_value() to c_enum_const()

2015-05-05 Thread Eric Blake
From: Markus Armbruster arm...@redhat.com

Signed-off-by: Markus Armbruster arm...@redhat.com
Signed-off-by: Eric Blake ebl...@redhat.com
---
 scripts/qapi-event.py | 5 ++---
 scripts/qapi-types.py | 6 +++---
 scripts/qapi-visit.py | 4 ++--
 scripts/qapi.py   | 6 +++---
 4 files changed, 10 insertions(+), 11 deletions(-)

diff --git a/scripts/qapi-event.py b/scripts/qapi-event.py
index c4612e3..a7e0033 100644
--- a/scripts/qapi-event.py
+++ b/scripts/qapi-event.py
@@ -177,7 +177,7 @@ typedef enum %(event_enum_name)s
   event_enum_name = event_enum_name)

 # append automatically generated _MAX value
-enum_max_value = generate_enum_full_value(event_enum_name, MAX)
+enum_max_value = c_enum_const(event_enum_name, MAX)
 enum_values = event_enum_values + [ enum_max_value ]

 i = 0
@@ -343,8 +343,7 @@ for expr in exprs:
 fdecl.write(ret)

 # We need an enum value per event
-event_enum_value = generate_enum_full_value(event_enum_name,
-event_name)
+event_enum_value = c_enum_const(event_enum_name, event_name)
 ret = generate_event_implement(api_name, event_name, params)
 fdef.write(ret)

diff --git a/scripts/qapi-types.py b/scripts/qapi-types.py
index e74cabe..6ca48c1 100644
--- a/scripts/qapi-types.py
+++ b/scripts/qapi-types.py
@@ -118,13 +118,13 @@ const char *%(name)s_lookup[] = {
  name=name)
 i = 0
 for value in values:
-index = generate_enum_full_value(name, value)
+index = c_enum_const(name, value)
 ret += mcgen('''
 [%(index)s] = %(value)s,
 ''',
  index = index, value = value)

-max_index = generate_enum_full_value(name, 'MAX')
+max_index = c_enum_const(name, 'MAX')
 ret += mcgen('''
 [%(max_index)s] = NULL,
 };
@@ -150,7 +150,7 @@ typedef enum %(name)s

 i = 0
 for value in enum_values:
-enum_full_value = generate_enum_full_value(name, value)
+enum_full_value = c_enum_const(name, value)
 enum_decl += mcgen('''
 %(enum_full_value)s = %(i)d,
 ''',
diff --git a/scripts/qapi-visit.py b/scripts/qapi-visit.py
index ba623b1..0368e62 100644
--- a/scripts/qapi-visit.py
+++ b/scripts/qapi-visit.py
@@ -214,7 +214,7 @@ void visit_type_%(name)s(Visitor *m, %(name)s **obj, const 
char *name, Error **e
 or find_union(members[key])
 or find_enum(members[key])), Invalid alternate member

-enum_full_value = generate_enum_full_value(disc_type, key)
+enum_full_value = c_enum_const(disc_type, key)
 ret += mcgen('''
 case %(enum_full_value)s:
 visit_type_%(c_type)s(m, (*obj)-%(c_name)s, name, err);
@@ -315,7 +315,7 @@ void visit_type_%(name)s(Visitor *m, %(name)s **obj, const 
char *name, Error **e
 else:
 fmt = 'visit_type_implicit_%(c_type)s(m, (*obj)-%(c_name)s, 
err);'

-enum_full_value = generate_enum_full_value(disc_type, key)
+enum_full_value = c_enum_const(disc_type, key)
 ret += mcgen('''
 case %(enum_full_value)s:
 ''' + fmt + '''
diff --git a/scripts/qapi.py b/scripts/qapi.py
index d9ed73a..b3628fd 100644
--- a/scripts/qapi.py
+++ b/scripts/qapi.py
@@ -960,7 +960,7 @@ def camel_to_upper(value):
 new_name += c
 return new_name.lstrip('_').upper()

-def generate_enum_full_value(enum_name, enum_value):
-abbrev_string = camel_to_upper(enum_name)
-value_string = camel_to_upper(enum_value)
+def c_enum_const(type_name, const_name):
+abbrev_string = camel_to_upper(type_name)
+value_string = camel_to_upper(const_name)
 return %s_%s % (abbrev_string, value_string)
-- 
2.1.0




[Qemu-devel] [PATCH v3 14/14] qapi: Support downstream events and commands

2015-05-05 Thread Eric Blake
Enhance the testsuite to cover downstream events and commands.
Events worked without more tweaks, but commands needed a few final
updates in the generator to mangle names in the appropriate places.
In making those tweaks, it was easier to drop type_visitor() and
inline its actions instead.

Signed-off-by: Eric Blake ebl...@redhat.com
---
 scripts/qapi-commands.py| 16 +---
 tests/qapi-schema/qapi-schema-test.json |  5 +
 tests/qapi-schema/qapi-schema-test.out  |  4 +++-
 tests/test-qmp-commands.c   | 15 +++
 4 files changed, 28 insertions(+), 12 deletions(-)

diff --git a/scripts/qapi-commands.py b/scripts/qapi-commands.py
index 8c125ca..0a1d636 100644
--- a/scripts/qapi-commands.py
+++ b/scripts/qapi-commands.py
@@ -20,12 +20,6 @@ import os
 import getopt
 import errno

-def type_visitor(name):
-if type(name) == list:
-return 'visit_type_%sList' % name[0]
-else:
-return 'visit_type_%s' % name
-
 def generate_command_decl(name, args, ret_type):
 arglist=
 for argname, argtype, optional in parse_args(args):
@@ -153,10 +147,10 @@ if (has_%(c_name)s) {
  c_name=c_name(argname))
 push_indent()
 ret += mcgen('''
-%(visitor)s(v, %(c_name)s, %(name)s, %(errp)s);
+visit_type_%(visitor)s(v, %(c_name)s, %(name)s, %(errp)s);
 ''',
  c_name=c_name(argname), name=argname, argtype=argtype,
- visitor=type_visitor(argtype), errp=errparg)
+ visitor=type_name(argtype), errp=errparg)
 ret += gen_err_check(errarg)
 if optional:
 pop_indent()
@@ -184,7 +178,7 @@ static void qmp_marshal_output_%(c_name)s(%(c_ret_type)s 
ret_in, QObject **ret_o
 Visitor *v;

 v = qmp_output_get_visitor(mo);
-%(visitor)s(v, ret_in, unused, local_err);
+visit_type_%(visitor)s(v, ret_in, unused, local_err);
 if (local_err) {
 goto out;
 }
@@ -195,12 +189,12 @@ out:
 qmp_output_visitor_cleanup(mo);
 md = qapi_dealloc_visitor_new();
 v = qapi_dealloc_get_visitor(md);
-%(visitor)s(v, ret_in, unused, NULL);
+visit_type_%(visitor)s(v, ret_in, unused, NULL);
 qapi_dealloc_visitor_cleanup(md);
 }
 ''',
 c_ret_type=c_type(ret_type), c_name=c_name(name),
-visitor=type_visitor(ret_type))
+visitor=type_name(ret_type))

 return ret

diff --git a/tests/qapi-schema/qapi-schema-test.json 
b/tests/qapi-schema/qapi-schema-test.json
index d586b56..c7eaa86 100644
--- a/tests/qapi-schema/qapi-schema-test.json
+++ b/tests/qapi-schema/qapi-schema-test.json
@@ -122,3 +122,8 @@
   'data': { '__org.qemu_x-value': '__org.qemu_x-Struct2' } }
 { 'alternate': '__org.qemu_x-Alt',
   'data': { '__org.qemu_x-branch': 'str', 'b': '__org.qemu_x-Base' } }
+{ 'event': '__ORG.QEMU_X-EVENT', 'data': '__org.qemu_x-Struct' }
+{ 'command': '__org.qemu_x-command',
+  'data': { 'a': ['__org.qemu_x-Enum'], 'b': ['__org.qemu_x-Struct'],
+'c': '__org.qemu_x-Union2', 'd': '__org.qemu_x-Alt' },
+  'returns': '__org.qemu_x-Union1' }
diff --git a/tests/qapi-schema/qapi-schema-test.out 
b/tests/qapi-schema/qapi-schema-test.out
index 2161a90..cf0ccc4 100644
--- a/tests/qapi-schema/qapi-schema-test.out
+++ b/tests/qapi-schema/qapi-schema-test.out
@@ -29,7 +29,9 @@
  OrderedDict([('union', '__org.qemu_x-Union1'), ('data', 
OrderedDict([('__org.qemu_x-branch', 'str')]))]),
  OrderedDict([('struct', '__org.qemu_x-Struct2'), ('data', 
OrderedDict([('array', ['__org.qemu_x-Union1'])]))]),
  OrderedDict([('union', '__org.qemu_x-Union2'), ('base', '__org.qemu_x-Base'), 
('discriminator', '__org.qemu_x-member1'), ('data', 
OrderedDict([('__org.qemu_x-value', '__org.qemu_x-Struct2')]))]),
- OrderedDict([('alternate', '__org.qemu_x-Alt'), ('data', 
OrderedDict([('__org.qemu_x-branch', 'str'), ('b', '__org.qemu_x-Base')]))])]
+ OrderedDict([('alternate', '__org.qemu_x-Alt'), ('data', 
OrderedDict([('__org.qemu_x-branch', 'str'), ('b', '__org.qemu_x-Base')]))]),
+ OrderedDict([('event', '__ORG.QEMU_X-EVENT'), ('data', 
'__org.qemu_x-Struct')]),
+ OrderedDict([('command', '__org.qemu_x-command'), ('data', OrderedDict([('a', 
['__org.qemu_x-Enum']), ('b', ['__org.qemu_x-Struct']), ('c', 
'__org.qemu_x-Union2'), ('d', '__org.qemu_x-Alt')])), ('returns', 
'__org.qemu_x-Union1')])]
 [{'enum_name': 'EnumOne', 'enum_values': ['value1', 'value2', 'value3']},
  {'enum_name': '__org.qemu_x-Enum', 'enum_values': ['__org.qemu_x-value']},
  {'enum_name': 'UserDefAlternateKind', 'enum_values': None},
diff --git a/tests/test-qmp-commands.c b/tests/test-qmp-commands.c
index ad2e403..9918f23 100644
--- a/tests/test-qmp-commands.c
+++ b/tests/test-qmp-commands.c
@@ -51,6 +51,21 @@ int64_t qmp_user_def_cmd3(int64_t a, bool has_b, int64_t b, 
Error **errp)
 return a + (has_b ? b : 0);
 }

+__org_qemu_x_Union1 *qmp___org_qemu_x_command(__org_qemu_x_EnumList *a,
+  

Re: [Qemu-devel] [PATCH v2 3/4] qapi: Correctly handle downstream extensions in more locations

2015-05-05 Thread Eric Blake
On 04/29/2015 05:29 AM, Markus Armbruster wrote:
 Eric Blake ebl...@redhat.com writes:
 
 Now that c_var() handles '.' in downstream extension names, fix
 the generator to support such names as additional types, enums,
 members within an enum, branches of a union or alternate, and
 in arrays.


 -def generate_visit_list(name, members):
 +def generate_visit_list(name, members, builtin=False):
 +if not builtin:
 +name = c_var(name)
 
 Fun.
 
 c_var() does two things:
 
 (a) it protects certain words if protect=True
 
 (b) it maps funny characters to '_'.
 
 When builtin, (a) is unwanted, and (b) does nothing.  That's why we need
 the conditional.
 
 A possible alternative could be c_var(name, not builtin).  Matter of
 taste.
 
 Hmm, just saw what type_name() does.  Why not just
 
 name = type_name(name)
 
 ?

Oops, I think I missed this comment in my v3 posting, amidst all my
patch splitting.


 
 If it was my patch, I'd be tempted to split it up some.  Matter of
 taste, feel free to keep it a single patch.

v3 splits it up.


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



signature.asc
Description: OpenPGP digital signature


[Qemu-devel] [PATCH v3 13/14] qapi: Support downstream alternates

2015-05-05 Thread Eric Blake
Enhance the testsuite to cover downstream alternates, including
whether the branch name or type is downstream.  Update the
generator to mangle alternate names in the appropriate places.

Signed-off-by: Eric Blake ebl...@redhat.com
---
 scripts/qapi-types.py   | 7 ---
 scripts/qapi-visit.py   | 6 +++---
 tests/qapi-schema/qapi-schema-test.json | 2 ++
 tests/qapi-schema/qapi-schema-test.out  | 6 --
 4 files changed, 13 insertions(+), 8 deletions(-)

diff --git a/scripts/qapi-types.py b/scripts/qapi-types.py
index 13e4b53..5665145 100644
--- a/scripts/qapi-types.py
+++ b/scripts/qapi-types.py
@@ -174,16 +174,17 @@ def generate_alternate_qtypes(expr):
 ret = mcgen('''
 const int %(name)s_qtypes[QTYPE_MAX] = {
 ''',
-name=name)
+name=c_name(name))

 for key in members:
 qtype = find_alternate_member_qtype(members[key])
 assert qtype, Invalid alternate member

 ret += mcgen('''
-[ %(qtype)s ] = %(enum_const)s,
+[%(qtype)s] = %(enum_const)s,
 ''',
-qtype = qtype, enum_const = c_enum_const(name + 'Kind', key))
+ qtype = qtype,
+ enum_const = c_enum_const(name + 'Kind', key))

 ret += mcgen('''
 };
diff --git a/scripts/qapi-visit.py b/scripts/qapi-visit.py
index def0c50..a16cc54 100644
--- a/scripts/qapi-visit.py
+++ b/scripts/qapi-visit.py
@@ -203,11 +203,11 @@ void visit_type_%(name)s(Visitor *m, %(name)s **obj, 
const char *name, Error **e
 }
 switch ((*obj)-kind) {
 ''',
-name=name)
+name=c_name(name))

 # For alternate, always use the default enum type automatically generated
-# as '%sKind' % (name)
-disc_type = '%sKind' % (name)
+# as name + 'Kind'
+disc_type = c_name(name) + 'Kind'

 for key in members:
 assert (members[key] in builtin_types.keys()
diff --git a/tests/qapi-schema/qapi-schema-test.json 
b/tests/qapi-schema/qapi-schema-test.json
index ac236e3..d586b56 100644
--- a/tests/qapi-schema/qapi-schema-test.json
+++ b/tests/qapi-schema/qapi-schema-test.json
@@ -120,3 +120,5 @@
 { 'union': '__org.qemu_x-Union2', 'base': '__org.qemu_x-Base',
   'discriminator': '__org.qemu_x-member1',
   'data': { '__org.qemu_x-value': '__org.qemu_x-Struct2' } }
+{ 'alternate': '__org.qemu_x-Alt',
+  'data': { '__org.qemu_x-branch': 'str', 'b': '__org.qemu_x-Base' } }
diff --git a/tests/qapi-schema/qapi-schema-test.out 
b/tests/qapi-schema/qapi-schema-test.out
index 3fc24e8..2161a90 100644
--- a/tests/qapi-schema/qapi-schema-test.out
+++ b/tests/qapi-schema/qapi-schema-test.out
@@ -28,12 +28,14 @@
  OrderedDict([('struct', '__org.qemu_x-Struct'), ('base', 
'__org.qemu_x-Base'), ('data', OrderedDict([('__org.qemu_x-member2', 
'str')]))]),
  OrderedDict([('union', '__org.qemu_x-Union1'), ('data', 
OrderedDict([('__org.qemu_x-branch', 'str')]))]),
  OrderedDict([('struct', '__org.qemu_x-Struct2'), ('data', 
OrderedDict([('array', ['__org.qemu_x-Union1'])]))]),
- OrderedDict([('union', '__org.qemu_x-Union2'), ('base', '__org.qemu_x-Base'), 
('discriminator', '__org.qemu_x-member1'), ('data', 
OrderedDict([('__org.qemu_x-value', '__org.qemu_x-Struct2')]))])]
+ OrderedDict([('union', '__org.qemu_x-Union2'), ('base', '__org.qemu_x-Base'), 
('discriminator', '__org.qemu_x-member1'), ('data', 
OrderedDict([('__org.qemu_x-value', '__org.qemu_x-Struct2')]))]),
+ OrderedDict([('alternate', '__org.qemu_x-Alt'), ('data', 
OrderedDict([('__org.qemu_x-branch', 'str'), ('b', '__org.qemu_x-Base')]))])]
 [{'enum_name': 'EnumOne', 'enum_values': ['value1', 'value2', 'value3']},
  {'enum_name': '__org.qemu_x-Enum', 'enum_values': ['__org.qemu_x-value']},
  {'enum_name': 'UserDefAlternateKind', 'enum_values': None},
  {'enum_name': 'UserDefNativeListUnionKind', 'enum_values': None},
- {'enum_name': '__org.qemu_x-Union1Kind', 'enum_values': None}]
+ {'enum_name': '__org.qemu_x-Union1Kind', 'enum_values': None},
+ {'enum_name': '__org.qemu_x-AltKind', 'enum_values': None}]
 [OrderedDict([('struct', 'NestedEnumsOne'), ('data', OrderedDict([('enum1', 
'EnumOne'), ('*enum2', 'EnumOne'), ('enum3', 'EnumOne'), ('*enum4', 
'EnumOne')]))]),
  OrderedDict([('struct', 'UserDefZero'), ('data', OrderedDict([('integer', 
'int')]))]),
  OrderedDict([('struct', 'UserDefOne'), ('base', 'UserDefZero'), ('data', 
OrderedDict([('string', 'str'), ('*enum1', 'EnumOne')]))]),
-- 
2.1.0




[Qemu-devel] [PATCH v3 10/14] qapi: Support downstream structs

2015-05-05 Thread Eric Blake
Enhance the testsuite to cover downstream structs, including struct
members and base structs.  Update the generator to mangle the
struct names in the appropriate places.

Signed-off-by: Eric Blake ebl...@redhat.com
---
 scripts/qapi-types.py   |  4 ++--
 scripts/qapi-visit.py   | 11 ++-
 tests/qapi-schema/qapi-schema-test.json |  4 
 tests/qapi-schema/qapi-schema-test.out  |  8 ++--
 4 files changed, 18 insertions(+), 9 deletions(-)

diff --git a/scripts/qapi-types.py b/scripts/qapi-types.py
index 1593fc6..5118151 100644
--- a/scripts/qapi-types.py
+++ b/scripts/qapi-types.py
@@ -45,7 +45,7 @@ typedef struct %(name)sList
 struct %(name)sList *next;
 } %(name)sList;
 ''',
- name=name)
+ name=c_name(name))

 def generate_fwd_enum_struct(name, members):
 return mcgen('''
@@ -87,7 +87,7 @@ def generate_struct(expr):
 struct %(name)s
 {
 ''',
-  name=structname)
+  name=c_name(structname))

 if base:
 ret += generate_struct_fields({'base': base})
diff --git a/scripts/qapi-visit.py b/scripts/qapi-visit.py
index feb6c0b..a7486ec 100644
--- a/scripts/qapi-visit.py
+++ b/scripts/qapi-visit.py
@@ -56,7 +56,7 @@ static void visit_type_%(name)s_fields(Visitor *m, %(name)s 
**obj, Error **errp)
 {
 Error *err = NULL;
 ''',
- name=name)
+ name=c_name(name))
 push_indent()

 if base:
@@ -111,16 +111,16 @@ def generate_visit_struct_body(name, members):
 ret = mcgen('''
 Error *err = NULL;

-visit_start_struct(m, (void **)obj, %(name)s, name, sizeof(%(name)s), 
err);
+visit_start_struct(m, (void **)obj, %(name)s, name, sizeof(%(c_name)s), 
err);
 if (!err) {
 if (*obj) {
-visit_type_%(name)s_fields(m, obj, errp);
+visit_type_%(c_name)s_fields(m, obj, errp);
 }
 visit_end_struct(m, err);
 }
 error_propagate(errp, err);
 ''',
-name=name)
+name=name, c_name=c_name(name))

 return ret

@@ -137,7 +137,7 @@ def generate_visit_struct(expr):
 void visit_type_%(name)s(Visitor *m, %(name)s **obj, const char *name, Error 
**errp)
 {
 ''',
-name=name)
+ name=c_name(name))

 ret += generate_visit_struct_body(name, members)

@@ -348,6 +348,7 @@ out:
 def generate_declaration(name, members, builtin_type=False):
 ret = 
 if not builtin_type:
+name = c_name(name)
 ret += mcgen('''

 void visit_type_%(name)s(Visitor *m, %(name)s **obj, const char *name, Error 
**errp);
diff --git a/tests/qapi-schema/qapi-schema-test.json 
b/tests/qapi-schema/qapi-schema-test.json
index 5f9af66..ca9b34c 100644
--- a/tests/qapi-schema/qapi-schema-test.json
+++ b/tests/qapi-schema/qapi-schema-test.json
@@ -110,3 +110,7 @@

 # test that we correctly compile downstream extensions
 { 'enum': '__org.qemu_x-Enum', 'data': [ '__org.qemu_x-value' ] }
+{ 'struct': '__org.qemu_x-Base',
+  'data': { '__org.qemu_x-member1': '__org.qemu_x-Enum' } }
+{ 'struct': '__org.qemu_x-Struct', 'base': '__org.qemu_x-Base',
+  'data': { '__org.qemu_x-member2': 'str' } }
diff --git a/tests/qapi-schema/qapi-schema-test.out 
b/tests/qapi-schema/qapi-schema-test.out
index 40f0f20..6ab4f00 100644
--- a/tests/qapi-schema/qapi-schema-test.out
+++ b/tests/qapi-schema/qapi-schema-test.out
@@ -23,7 +23,9 @@
  OrderedDict([('event', 'EVENT_B'), ('data', OrderedDict())]),
  OrderedDict([('event', 'EVENT_C'), ('data', OrderedDict([('*a', 'int'), 
('*b', 'UserDefOne'), ('c', 'str')]))]),
  OrderedDict([('event', 'EVENT_D'), ('data', OrderedDict([('a', 
'EventStructOne'), ('b', 'str'), ('*c', 'str'), ('*enum3', 'EnumOne')]))]),
- OrderedDict([('enum', '__org.qemu_x-Enum'), ('data', 
['__org.qemu_x-value'])])]
+ OrderedDict([('enum', '__org.qemu_x-Enum'), ('data', 
['__org.qemu_x-value'])]),
+ OrderedDict([('struct', '__org.qemu_x-Base'), ('data', 
OrderedDict([('__org.qemu_x-member1', '__org.qemu_x-Enum')]))]),
+ OrderedDict([('struct', '__org.qemu_x-Struct'), ('base', 
'__org.qemu_x-Base'), ('data', OrderedDict([('__org.qemu_x-member2', 
'str')]))])]
 [{'enum_name': 'EnumOne', 'enum_values': ['value1', 'value2', 'value3']},
  {'enum_name': '__org.qemu_x-Enum', 'enum_values': ['__org.qemu_x-value']},
  {'enum_name': 'UserDefAlternateKind', 'enum_values': None},
@@ -39,4 +41,6 @@
  OrderedDict([('struct', 'UserDefC'), ('data', OrderedDict([('string1', 
'str'), ('string2', 'str')]))]),
  OrderedDict([('struct', 'UserDefUnionBase'), ('data', OrderedDict([('string', 
'str'), ('enum1', 'EnumOne')]))]),
  OrderedDict([('struct', 'UserDefOptions'), ('data', OrderedDict([('*i64', 
['int']), ('*u64', ['uint64']), ('*u16', ['uint16']), ('*i64x', 'int'), 
('*u64x', 'uint64')]))]),
- OrderedDict([('struct', 'EventStructOne'), ('data', OrderedDict([('struct1', 
'UserDefOne'), ('string', 'str'), ('*enum2', 'EnumOne')]))])]
+ OrderedDict([('struct', 'EventStructOne'), ('data', 

Re: [Qemu-devel] [PATCH 1/4] block: Fix dirty bitmap in bdrv_co_discard

2015-05-05 Thread Paolo Bonzini


On 05/05/2015 14:46, Fam Zheng wrote:
 Unsetting dirty globally with discard is not very correct. The discard may 
 zero
 out sectors (depending on can_write_zeroes_with_unmap), we should replicate
 this change to destinition side to make sure that the guest sees the same 
 data.
 
 Calling bdrv_reset_dirty also troubles mirror job because the hbitmap iterator
 doesn't expect unsetting of bits after current position.
 
 So let's do it the opposite way which fixes both problems: set the dirty bits
 if we are to discard it.

This is not enough, you also have to do the discard in block/mirror.c,
otherwise the destination image could even become fully provisioned!

Paolo

 Reported-by: wangxiaol...@ucloud.cn
 Signed-off-by: Fam Zheng f...@redhat.com
 ---
  block/io.c | 4 ++--
  1 file changed, 2 insertions(+), 2 deletions(-)
 
 diff --git a/block/io.c b/block/io.c
 index 1ce62c4..809688b 100644
 --- a/block/io.c
 +++ b/block/io.c
 @@ -2343,8 +2343,6 @@ int coroutine_fn bdrv_co_discard(BlockDriverState *bs, 
 int64_t sector_num,
  return -EROFS;
  }
  
 -bdrv_reset_dirty(bs, sector_num, nb_sectors);
 -
  /* Do nothing if disabled.  */
  if (!(bs-open_flags  BDRV_O_UNMAP)) {
  return 0;
 @@ -2354,6 +2352,8 @@ int coroutine_fn bdrv_co_discard(BlockDriverState *bs, 
 int64_t sector_num,
  return 0;
  }
  
 +bdrv_set_dirty(bs, sector_num, nb_sectors);
 +
  max_discard = MIN_NON_ZERO(bs-bl.max_discard, BDRV_REQUEST_MAX_SECTORS);
  while (nb_sectors  0) {
  int ret;
 



Re: [Qemu-devel] [PATCH v6 02/17] Add accelerator id and model name to CPUState

2015-05-05 Thread Eduardo Habkost
On Mon, Apr 27, 2015 at 04:53:16PM +0200, Michael Mueller wrote:
 The patch defines ids per accelerator and adds the accel_id and
 the model_name to the CPUState. The accel_id is initialized by
 common code, the model name needs to be initialized by target
 specific code.
 
 Signed-off-by: Michael Mueller m...@linux.vnet.ibm.com
 Acked-by: Christian Borntraeger borntrae...@de.ibm.com
 ---
  include/qom/cpu.h |  5 +
  qapi-schema.json  |  9 +
  qom/cpu.c | 14 ++
  3 files changed, 28 insertions(+)
 
 diff --git a/include/qom/cpu.h b/include/qom/cpu.h
 index 9dafb48..4ffc050 100644
 --- a/include/qom/cpu.h
 +++ b/include/qom/cpu.h
 @@ -236,6 +236,8 @@ struct kvm_run;
   * @mem_io_pc: Host Program Counter at which the memory was accessed.
   * @mem_io_vaddr: Target virtual address at which the memory was accessed.
   * @kvm_fd: vCPU file descriptor for KVM.
 + * @accel_id: accelerator id of this CPU.
 + * @model_name: model name of this CPU
   *
   * State of one CPU core or thread.
   */
 @@ -313,6 +315,9 @@ struct CPUState {
 (absolute value) offset as small as possible.  This reduces code
 size, especially for hosts without large memory offsets.  */
  volatile sig_atomic_t tcg_exit_req;
 +
 +AccelId accel_id;

This can be a AccelState pointer, set on initialization, because we have
another user case for having a AccelState pointer: query-cpu-definition
implementations may create temporary CPU objects with a different accel
object to be able to probe for accel-specific data.

(The pointer may become a link QOM property later.)


 +char *model_name;
  };
  
  QTAILQ_HEAD(CPUTailQ, CPUState);
 diff --git a/qapi-schema.json b/qapi-schema.json
 index ac9594d..540e520 100644
 --- a/qapi-schema.json
 +++ b/qapi-schema.json
 @@ -2515,6 +2515,15 @@
  ##
  { 'command': 'query-machines', 'returns': ['MachineInfo'] }
  
 +# @AccelId
 +#
 +# Defines accelerator ids
 +#
 +# Since: 2.4
 +##
 +{ 'enum': 'AccelId',
 +  'data': ['qtest', 'tcg', 'kvm', 'xen'] }
 +

Not sure if it is better to have an enum or simply a string here.

  ##
  # @CpuDefinitionInfo:
  #
 diff --git a/qom/cpu.c b/qom/cpu.c
 index 108bfa2..457afc7 100644
 --- a/qom/cpu.c
 +++ b/qom/cpu.c
 @@ -67,6 +67,20 @@ CPUState *cpu_generic_init(const char *typename, const 
 char *cpu_model)
  goto out;
  }
  
 +if (tcg_enabled()) {
 +cpu-accel_id = ACCEL_ID_TCG;
 +} else if (kvm_enabled()) {
 +cpu-accel_id = ACCEL_ID_KVM;
 +}
 +#ifdef CONFIG_XEN
 +else if (xen_enabled()) {
 +cpu-accel_id = ACCEL_ID_XEN;
 +}
 +#endif
 +else {
 +cpu-accel_id = ACCEL_ID_QTEST;
 +}

You can simply use ACCEL_GET_CLASS(current_machine-accelerator)-name
here. If we really want an enum, we can add an AccelId field to
AccelClass, and initialize it properly on the accel class_init
functions.

CONFIG_USER may require some special code when returning the accelerator
ID as tcg because IIRC it doesn't use the QOM accel classes (yet).

 +
  object_property_set_bool(OBJECT(cpu), true, realized, err);
  
  out:
 -- 
 1.8.3.1
 

-- 
Eduardo



[Qemu-devel] [PATCH v3 05/14] qapi: Simplify c_enum_const()

2015-05-05 Thread Eric Blake
From: Markus Armbruster arm...@redhat.com

Signed-off-by: Markus Armbruster arm...@redhat.com
Signed-off-by: Eric Blake ebl...@redhat.com
---
 scripts/qapi.py | 4 +---
 1 file changed, 1 insertion(+), 3 deletions(-)

diff --git a/scripts/qapi.py b/scripts/qapi.py
index b3628fd..9209fd5 100644
--- a/scripts/qapi.py
+++ b/scripts/qapi.py
@@ -961,6 +961,4 @@ def camel_to_upper(value):
 return new_name.lstrip('_').upper()

 def c_enum_const(type_name, const_name):
-abbrev_string = camel_to_upper(type_name)
-value_string = camel_to_upper(const_name)
-return %s_%s % (abbrev_string, value_string)
+return camel_to_upper(type_name + '_' + const_name)
-- 
2.1.0




[Qemu-devel] [PATCH v3 02/14] qapi: Rename identical c_fun()/c_var() into c_name()

2015-05-05 Thread Eric Blake
Now that the two functions are identical, we only need one of them,
and we might as well give it a more descriptive name.  Basically,
the function serves as the translation from a QAPI name into a
(portion of a) C identifier, without regards to whether it is a
variable or function name.

Signed-off-by: Eric Blake ebl...@redhat.com
---
 scripts/qapi-commands.py | 35 ++-
 scripts/qapi-event.py| 10 +-
 scripts/qapi-types.py|  8 
 scripts/qapi-visit.py| 10 +-
 scripts/qapi.py  | 11 ---
 5 files changed, 36 insertions(+), 38 deletions(-)

diff --git a/scripts/qapi-commands.py b/scripts/qapi-commands.py
index 93e43f0..8c125ca 100644
--- a/scripts/qapi-commands.py
+++ b/scripts/qapi-commands.py
@@ -31,12 +31,13 @@ def generate_command_decl(name, args, ret_type):
 for argname, argtype, optional in parse_args(args):
 argtype = c_type(argtype, is_param=True)
 if optional:
-arglist += bool has_%s,  % c_var(argname)
-arglist += %s %s,  % (argtype, c_var(argname))
+arglist += bool has_%s,  % c_name(argname)
+arglist += %s %s,  % (argtype, c_name(argname))
 return mcgen('''
 %(ret_type)s qmp_%(name)s(%(args)sError **errp);
 ''',
- ret_type=c_type(ret_type), name=c_fun(name), 
args=arglist).strip()
+ ret_type=c_type(ret_type), name=c_name(name),
+ args=arglist).strip()

 def gen_err_check(errvar):
 if errvar:
@@ -55,14 +56,14 @@ def gen_sync_call(name, args, ret_type, indent=0):
 retval = retval = 
 for argname, argtype, optional in parse_args(args):
 if optional:
-arglist += has_%s,  % c_var(argname)
-arglist += %s,  % (c_var(argname))
+arglist += has_%s,  % c_name(argname)
+arglist += %s,  % (c_name(argname))
 push_indent(indent)
 ret = mcgen('''
 %(retval)sqmp_%(name)s(%(args)slocal_err);

 ''',
-name=c_fun(name), args=arglist, retval=retval).rstrip()
+name=c_name(name), args=arglist, retval=retval).rstrip()
 if ret_type:
 ret += \n + gen_err_check('local_err')
 ret += \n + mcgen(
@@ -76,7 +77,7 @@ def gen_sync_call(name, args, ret_type, indent=0):
 def gen_marshal_output_call(name, ret_type):
 if not ret_type:
 return 
-return qmp_marshal_output_%s(retval, ret, local_err); % c_fun(name)
+return qmp_marshal_output_%s(retval, ret, local_err); % c_name(name)

 def gen_visitor_input_containers_decl(args, obj):
 ret = 
@@ -101,17 +102,17 @@ def gen_visitor_input_vars_decl(args):
 ret += mcgen('''
 bool has_%(argname)s = false;
 ''',
- argname=c_var(argname))
+ argname=c_name(argname))
 if is_c_ptr(argtype):
 ret += mcgen('''
 %(argtype)s %(argname)s = NULL;
 ''',
- argname=c_var(argname), argtype=c_type(argtype))
+ argname=c_name(argname), argtype=c_type(argtype))
 else:
 ret += mcgen('''
 %(argtype)s %(argname)s = {0};
 ''',
- argname=c_var(argname), argtype=c_type(argtype))
+ argname=c_name(argname), argtype=c_type(argtype))

 pop_indent()
 return ret.rstrip()
@@ -144,17 +145,17 @@ v = qmp_input_get_visitor(mi);
 ret += mcgen('''
 visit_optional(v, has_%(c_name)s, %(name)s, %(errp)s);
 ''',
- c_name=c_var(argname), name=argname, errp=errparg)
+ c_name=c_name(argname), name=argname, errp=errparg)
 ret += gen_err_check(errarg)
 ret += mcgen('''
 if (has_%(c_name)s) {
 ''',
- c_name=c_var(argname))
+ c_name=c_name(argname))
 push_indent()
 ret += mcgen('''
 %(visitor)s(v, %(c_name)s, %(name)s, %(errp)s);
 ''',
- c_name=c_var(argname), name=argname, argtype=argtype,
+ c_name=c_name(argname), name=argname, argtype=argtype,
  visitor=type_visitor(argtype), errp=errparg)
 ret += gen_err_check(errarg)
 if optional:
@@ -198,16 +199,16 @@ out:
 qapi_dealloc_visitor_cleanup(md);
 }
 ''',
-c_ret_type=c_type(ret_type), c_name=c_fun(name),
+c_ret_type=c_type(ret_type), c_name=c_name(name),
 visitor=type_visitor(ret_type))

 return ret

 def gen_marshal_input_decl(name, args, ret_type, middle_mode):
 if middle_mode:
-return 'int qmp_marshal_input_%s(Monitor *mon, const QDict *qdict, 
QObject **ret)' % c_fun(name)
+return 'int qmp_marshal_input_%s(Monitor *mon, const QDict *qdict, 
QObject **ret)' % c_name(name)
 else:
-return 'static void qmp_marshal_input_%s(QDict *args, QObject **ret, 
Error **errp)' % c_fun(name)
+return 'static void qmp_marshal_input_%s(QDict *args, 

[Qemu-devel] [PATCH 0/4] block: Mirror discarded sectors

2015-05-05 Thread Fam Zheng
This fixes the mirror assert failure reported by wangxiaolong:

https://lists.gnu.org/archive/html/qemu-devel/2015-04/msg04458.html

The direct cause is that hbitmap code couldn't handle unset of bits *after*
iterator's current position. We could fix that, but the bdrv_reset_dirty() call
is more questionable:

Before, if guest discarded some sectors during migration, it could see
different data after moving to dest side, depending on block backends of the
src and the dest. This is IMO worse than mirroring the actual reading as done
in this series, because we don't know what the guest is doing.

For example if a guest first issues WRITE SAME to wipe out the area then issues
UNMAP to discard it, just to get rid of some sensitive data completely, we may
miss both operations and leave stale data on dest image.


Fam Zheng (4):
  block: Fix dirty bitmap in bdrv_co_discard
  block: Remove bdrv_reset_dirty
  qemu-iotests: Make block job methods common
  qemu-iotests: Add test case for mirror with unmap

 block.c   | 12 
 block/io.c|  4 +--
 include/block/block_int.h |  2 --
 tests/qemu-iotests/041| 66 ++-
 tests/qemu-iotests/131| 59 ++
 tests/qemu-iotests/131.out|  5 
 tests/qemu-iotests/group  |  1 +
 tests/qemu-iotests/iotests.py | 28 ++
 8 files changed, 110 insertions(+), 67 deletions(-)
 create mode 100644 tests/qemu-iotests/131
 create mode 100644 tests/qemu-iotests/131.out

-- 
1.9.3




[Qemu-devel] [ARM]: Adding support for Cortex-M4

2015-05-05 Thread aurelio remonda
Hi, i would like to to add support for cortex-m4 on qemu. Most features of
the Cortex-M3 and M4 are the same with the significant difference that
Cortex-M4 has DSP extensions and optional FPU. Even so, i really need some
pointers for this (im a newbie on qemu devel). I found out that qemu can
manage dsp instructions such as ADD16, ASX, SAX, etc. and all their
combinations with suffixes (u, s, sh, etc.), so half (if not all) of the
work is done.

How should I go about this? What's the standard procedure for adding a new
CPU, even if it's so similar to the existing ones? That is, which are the
relevant functions/files that I should modify, and so on.

Thanks a lot!


Re: [Qemu-devel] [PATCH qemu v7 07/14] spapr_iommu: Add root memory region

2015-05-05 Thread David Gibson
On Sat, Apr 25, 2015 at 10:24:37PM +1000, Alexey Kardashevskiy wrote:
 We are going to have multiple DMA windows at different offsets on
 a PCI bus. For the sake of migration, we will have as many TCE table
 objects pre-created as many windows supported.
 So we need a way to map windows dynamically onto a PCI bus
 when migration of a table is completed but at this stage a TCE table
 object does not have access to a PHB to ask it to map a DMA window
 backed by just migrated TCE table.
 
 This adds a root memory region (UINT64_MAX long) to the TCE object.
 This new region is mapped on a PCI bus with enabled overlapping as
 there will be one root MR per TCE table, each of them mapped at 0.
 The actual IOMMU memory region is a subregion of the root region and
 a TCE table enables/disables this subregion and maps it at
 the specific offset inside the root MR which is 1:1 mapping of
 a PCI address space.
 
 Signed-off-by: Alexey Kardashevskiy a...@ozlabs.ru

Reviewed-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


pgpw3IVNevxVj.pgp
Description: PGP signature


Re: [Qemu-devel] [PATCH] QJSON: Use OBJECT_CHECK

2015-05-05 Thread Juan Quintela
Luiz Capitulino lcapitul...@redhat.com wrote:
 On Tue, 05 May 2015 14:43:19 +0200
 Juan Quintela quint...@redhat.com wrote:

 Eduardo Habkost ehabk...@redhat.com wrote:
  On Sat, Apr 25, 2015 at 07:05:55PM +0200, Andreas Färber wrote:
  Am 25.04.2015 um 17:28 schrieb Eduardo Habkost:
   The QJSON code used casts to (QJSON*) directly, instead of OBJECT_CHECK.
   There were even some functions using object_dynamic_cast() calls
   followed by assert(), which is exactly what OBJECT_CHECK does (by
   calling object_dynamic_cast_assert()).
  
  Suggest s/OBJECT_CHECK/OBJECT_CHECK()/g everywhere for clarity.
 
  I assume it can be fixed during commit by whoever is going to queue it.
 
  
   
   Signed-off-by: Eduardo Habkost ehabk...@redhat.com
   ---
qjson.c | 10 +-
1 file changed, 5 insertions(+), 5 deletions(-)
  
  Reviewed-by: Andreas Färber afaer...@suse.de
  
  Wasn't aware QJSON is using QOM - assuming this will go through some
  QAPI/QMP tree.
 
  The only user of qjson.c right now is migration code. Should it go through
  the migration tree?
 
 
 I will take it, but I trust your reviews-by O:-)

 I've already applied this one to the QMP tree.

I saw it later on the thread, I was about to say that all for you O:-)



 
 
  Also, why do we have two JSON writers in QEMU? And why do they have
  exactly the same name?
 
 Alex?  I guess alex have this implementation when he did the code long
 ago?
 
 Later, Juan.
 



Re: [Qemu-devel] Fwd: qemu drive mirror assert fault

2015-05-05 Thread Kevin Wolf
Am 05.05.2015 um 15:07 hat Paolo Bonzini geschrieben:
 
 
 On 05/05/2015 15:03, Kevin Wolf wrote:
   Yes, the SCSI command WRITE SAME with UNMAP = 1 (not coincidentially :))
   calls discard too.  Who knows what the guest used it for...
   
   However, write zeroes doesn't go through bdrv_co_discard, does it?
  
  Initially I expected that it does, but when I checked, it turned out
  that it uses a different path. The only thing I found that really uses
  discard is the call in qemu-img that I mentioned. But that can't be the
  cause of the corruption you're debugging.
 
 I'm not seeing corruption; it's a crash in drive-mirror.

Ah, yes, sorry. I was confused.

 The question is how to treat discard:
 
 1) mark sectors as dirty, discard on the destination as well (similar to
 Fam's just-posted patches, but they do not discard on the destination)
 
 2) keep marking sectors as not dirty, change util/hbitmap.c to avoid the
 assertion failure.  This loses the discard on the destination but no
 need to change block/mirror.c
 
 Both are valid approaches.

Which kind of suggests that it should be an option. But if I had to
choose one, I think 1) is nicer because it results in an exact copy.

Kevin



Re: [Qemu-devel] [PATCH v6 1/6] Qemu-Xen-vTPM: Support for Xen stubdom vTPM command line options

2015-05-05 Thread Xu, Quan


 -Original Message-
 From: Eric Blake [mailto:ebl...@redhat.com]
 Sent: Tuesday, May 05, 2015 10:29 PM
 To: Xu, Quan; stefano.stabell...@eu.citrix.com; stef...@linux.vnet.ibm.com
 Cc: qemu-devel@nongnu.org; wei.l...@citrix.com; dgde...@tycho.nsa.gov;
 xen-de...@lists.xen.org
 Subject: Re: [PATCH v6 1/6] Qemu-Xen-vTPM: Support for Xen stubdom vTPM
 command line options
 
 On 05/04/2015 01:22 AM, Quan Xu wrote:
  Signed-off-by: Quan Xu quan...@intel.com
 
  --Changes in v6:
   -Remove stray insertion.
  ---
   configure| 14 ++
   hmp.c|  2 ++
   qapi-schema.json | 16 ++--  qemu-options.hx  | 13
  +++--
   tpm.c|  7 ++-
   5 files changed, 47 insertions(+), 5 deletions(-)
 
 Reviewed-by: Eric Blake ebl...@redhat.com
 

Eric, thanks for your review! :)

-Quan

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



Re: [Qemu-devel] [PATCH v3 1/5] qtest: allow arbitrarily long sends

2015-05-05 Thread Eric Blake
On 05/05/2015 04:22 PM, John Snow wrote:
 qtest currently has a static buffer of size 1024 that if we
 overflow, ignores the additional data silently which leads
 to hangs or stream failures.
 
 Use glib's string facilities to allow arbitrarily long data,
 but split this off into a new function, qtest_sendf.
 
 Static data can still be sent using qtest_send, which avoids
 the malloc/copy overflow.

Did you mean 'overhead' instead of 'overflow'?

 
 Signed-off-by: John Snow js...@redhat.com
 ---
  qtest.c | 46 --
  1 file changed, 28 insertions(+), 18 deletions(-)
 

  qtest_send_prefix(chr);
 -qtest_send(chr, FAIL Unknown command `%s'\n, words[0]);
 +qtest_sendf(chr, FAIL Unknown command `%s'\n, words[0]);
  }

Unrelated - these days, I don't see `this' quoting much any more (except
in m4); most people have moved to 'this' quoting.  We could clean it
while touching this line, but it really doesn't affect correctness
either way.

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

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



signature.asc
Description: OpenPGP digital signature


Re: [Qemu-devel] [PATCH 1/4] block: Fix dirty bitmap in bdrv_co_discard

2015-05-05 Thread Fam Zheng
On Tue, 05/05 15:06, Paolo Bonzini wrote:
 
 
 On 05/05/2015 14:46, Fam Zheng wrote:
  Unsetting dirty globally with discard is not very correct. The discard may 
  zero
  out sectors (depending on can_write_zeroes_with_unmap), we should replicate
  this change to destinition side to make sure that the guest sees the same 
  data.
  
  Calling bdrv_reset_dirty also troubles mirror job because the hbitmap 
  iterator
  doesn't expect unsetting of bits after current position.
  
  So let's do it the opposite way which fixes both problems: set the dirty 
  bits
  if we are to discard it.
 
 This is not enough, you also have to do the discard in block/mirror.c,
 otherwise the destination image could even become fully provisioned!

I wasn't sure what if src and dest have different can_write_zeroes_with_unmap
value, but your argument is stronger.

I will add discard in mirror.  Besides that, do we need to compare the
can_write_zeroes_with_unmap?

Fam

 
 Paolo
 
  Reported-by: wangxiaol...@ucloud.cn
  Signed-off-by: Fam Zheng f...@redhat.com
  ---
   block/io.c | 4 ++--
   1 file changed, 2 insertions(+), 2 deletions(-)
  
  diff --git a/block/io.c b/block/io.c
  index 1ce62c4..809688b 100644
  --- a/block/io.c
  +++ b/block/io.c
  @@ -2343,8 +2343,6 @@ int coroutine_fn bdrv_co_discard(BlockDriverState 
  *bs, int64_t sector_num,
   return -EROFS;
   }
   
  -bdrv_reset_dirty(bs, sector_num, nb_sectors);
  -
   /* Do nothing if disabled.  */
   if (!(bs-open_flags  BDRV_O_UNMAP)) {
   return 0;
  @@ -2354,6 +2352,8 @@ int coroutine_fn bdrv_co_discard(BlockDriverState 
  *bs, int64_t sector_num,
   return 0;
   }
   
  +bdrv_set_dirty(bs, sector_num, nb_sectors);
  +
   max_discard = MIN_NON_ZERO(bs-bl.max_discard, 
  BDRV_REQUEST_MAX_SECTORS);
   while (nb_sectors  0) {
   int ret;
  



Re: [Qemu-devel] [PATCH v3 1/5] qtest: allow arbitrarily long sends

2015-05-05 Thread John Snow


On 05/05/2015 07:22 PM, Eric Blake wrote:
 On 05/05/2015 04:22 PM, John Snow wrote:
 qtest currently has a static buffer of size 1024 that if we 
 overflow, ignores the additional data silently which leads to
 hangs or stream failures.
 
 Use glib's string facilities to allow arbitrarily long data, but
 split this off into a new function, qtest_sendf.
 
 Static data can still be sent using qtest_send, which avoids the
 malloc/copy overflow.
 
 Did you mean 'overhead' instead of 'overflow'?
 

Sigh, yes. The fingers run on autopilot without input from the brain.
Will nab it if I spin again.

 
 Signed-off-by: John Snow js...@redhat.com --- qtest.c | 46
 -- 1 file changed, 28
 insertions(+), 18 deletions(-)
 
 
 qtest_send_prefix(chr); -qtest_send(chr, FAIL Unknown
 command `%s'\n, words[0]); +qtest_sendf(chr, FAIL
 Unknown command `%s'\n, words[0]); }
 
 Unrelated - these days, I don't see `this' quoting much any more
 (except in m4); most people have moved to 'this' quoting.  We could
 clean it while touching this line, but it really doesn't affect
 correctness either way.
 

If I spin again I'll get it.

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



Re: [Qemu-devel] [PATCH] s390x: Fix stoc direction

2015-05-05 Thread Richard Henderson
On 04/14/2015 06:45 PM, Alexander Graf wrote:
 The store conditional instruction wants to store when the condition
 is fulfilled, so we should branch out when it's not true.
 
 The code today branches out when the condition is true, clearly
 reversing the logic. Fix it up by negating the condition.
 
 Signed-off-by: Alexander Graf ag...@suse.de
 ---
  target-s390x/translate.c | 4 
  1 file changed, 4 insertions(+)
 
 diff --git a/target-s390x/translate.c b/target-s390x/translate.c
 index 4f82edd..8ae4912 100644
 --- a/target-s390x/translate.c
 +++ b/target-s390x/translate.c
 @@ -3082,6 +3082,10 @@ static ExitStatus op_soc(DisasContext *s, DisasOps *o)
  
  disas_jcc(s, c, get_field(s-fields, m3));
  
 +/* We want to store when the condition is fulfilled, so branch
 +   out when it's not */
 +c.cond = tcg_invert_cond(c.cond);

Doh.

Reviewed-by: Richard Henderson r...@twiddle.net


r~




[Qemu-devel] [Bug 1452062] [NEW] qemu-img will fail to convert images in 2.3.0

2015-05-05 Thread David Hill
Public bug reported:

Hello guys,

There seems to be a bug in qemu-img with 2.3.0 that wasn't there in
2.2.1   qemu convert will always fail converting.  See the output
below:


Started by upstream project Create windows image build number 73
originally caused by:
 Started by user anonymous
Building remotely on builder (builder lab) in workspace 
/var/lib/jenkins/remote/workspace/Prepare windows Image
[Prepare WS2008R2 Image] $ /bin/sh -xe /tmp/hudson4138890034689910617.sh
+ sudo bash -x /var/images/prepare_windows.sh WS2008R2
+ set +x

Preparing: windows
Virtio CD: virtio-win-0.1.96.iso

Sparsifying...
qemu-img: error while compressing sector 11131648: Input/output error
virt-sparsify: error: external command failed: qemu-img convert -f 
qcow2 -O 'qcow2' -c -o 'compat=0.10' '/tmp/sparsifyb459a0.qcow2' 
'/var/images/generated/WS2008R2.qcow2'

virt-sparsify: If reporting bugs, run virt-sparsify with debugging 
enabled (-v) and include the complete output.
Build step 'Execute shell' marked build as failure
Warning: you have no plugins providing access control for builds, so falling 
back to legacy behavior of permitting any downstream builds to be triggered
Finished: FAILURE

Thanks,
Dave

** Affects: qemu
 Importance: Undecided
 Status: New


** Tags: 2.3.0 qemu qemu-img

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

Title:
  qemu-img will fail to convert images in 2.3.0

Status in QEMU:
  New

Bug description:
  Hello guys,

  There seems to be a bug in qemu-img with 2.3.0 that wasn't there
  in 2.2.1   qemu convert will always fail converting.  See the
  output below:

  
  Started by upstream project Create windows image build number 73
  originally caused by:
   Started by user anonymous
  Building remotely on builder (builder lab) in workspace 
/var/lib/jenkins/remote/workspace/Prepare windows Image
  [Prepare WS2008R2 Image] $ /bin/sh -xe /tmp/hudson4138890034689910617.sh
  + sudo bash -x /var/images/prepare_windows.sh WS2008R2
  + set +x

  Preparing: windows
  Virtio CD: virtio-win-0.1.96.iso

  Sparsifying...
  qemu-img: error while compressing sector 11131648: Input/output error
  virt-sparsify: error: external command failed: qemu-img convert -f 
  qcow2 -O 'qcow2' -c -o 'compat=0.10' '/tmp/sparsifyb459a0.qcow2' 
  '/var/images/generated/WS2008R2.qcow2'

  virt-sparsify: If reporting bugs, run virt-sparsify with debugging 
  enabled (-v) and include the complete output.
  Build step 'Execute shell' marked build as failure
  Warning: you have no plugins providing access control for builds, so falling 
back to legacy behavior of permitting any downstream builds to be triggered
  Finished: FAILURE

  Thanks,
  Dave

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



[Qemu-devel] [PULL] tcg: optimise memory layout of TCGTemp

2015-05-05 Thread Richard Henderson
From: Emilio G. Cota c...@braap.org

This brings down the size of the struct from 56 to 32 bytes on 64-bit,
and to 20 bytes on 32-bit. This leads to memory savings:

Before:
$ find . -name 'tcg.o' | xargs size
   textdata bss dec hex filename
  41131   29800  88   71019   1156b ./aarch64-softmmu/tcg/tcg.o
  37969   29416  96   67481   10799 ./x86_64-linux-user/tcg/tcg.o
  39354   28816  96   68266   10aaa ./arm-linux-user/tcg/tcg.o
  40802   29096  88   69986   11162 ./arm-softmmu/tcg/tcg.o
  39417   29672  88   69177   10e39 ./x86_64-softmmu/tcg/tcg.o

After:
$ find . -name 'tcg.o' | xargs size
   textdata bss dec hex filename
  40883   29800  88   70771   11473 ./aarch64-softmmu/tcg/tcg.o
  37473   29416  96   66985   105a9 ./x86_64-linux-user/tcg/tcg.o
  38858   28816  96   67770   108ba ./arm-linux-user/tcg/tcg.o
  40554   29096  88   69738   1106a ./arm-softmmu/tcg/tcg.o
  39169   29672  88   68929   10d41 ./x86_64-softmmu/tcg/tcg.o

Note that using an entire byte for some enums that need less than
that wastes a few bits (noticeable in 32 bits, where we use
20 bytes instead of 16) but avoids extraction code, which overall
is a win--I've tested several variations of the patch, and the appended
is the best performer for OpenSSL's bntest by a very small margin:

Before:
$ taskset -c 0 perf stat -r 15 -- x86_64-linux-user/qemu-x86_64 
img/bntest-x86_64 /dev/null
[...]
 Performance counter stats for 'x86_64-linux-user/qemu-x86_64 
img/bntest-x86_64' (15 runs):

  10538.479833 task-clock (msec)  # 0.999 CPUs utilized  ( +-  0.38% )
   772 context-switches   # 0.073 K/sec  ( +-  2.03% )
 0 cpu-migrations # 0.000 K/sec  ( +-100.00% )
 2,207 page-faults# 0.209 K/sec  ( +-  0.08% )
  10.552871687 seconds time elapsed  ( +-  0.39% )

After:
$ taskset -c 0 perf stat -r 15 -- x86_64-linux-user/qemu-x86_64 
img/bntest-x86_64 /dev/null
 Performance counter stats for 'x86_64-linux-user/qemu-x86_64 
img/bntest-x86_64' (15 runs):

  10459.968847 task-clock (msec)  # 0.999 CPUs utilized  ( +-  0.30% )
   739 context-switches   # 0.071 K/sec  ( +-  1.71% )
 0 cpu-migrations # 0.000 K/sec  ( +- 68.14% )
 2,204 page-faults# 0.211 K/sec  ( +-  0.10% )
  10.473900411 seconds time elapsed  ( +-  0.30% )

Suggested-by: Stefan Weil s...@weilnetz.de
Suggested-by: Richard Henderson r...@twiddle.net
Reviewed-by: Alex Bennée alex.ben...@linaro.org
Signed-off-by: Emilio G. Cota c...@braap.org
Signed-off-by: Richard Henderson r...@twiddle.net
---
 tcg/tcg.h | 26 ++
 1 file changed, 14 insertions(+), 12 deletions(-)

diff --git a/tcg/tcg.h b/tcg/tcg.h
index 3d004ba..fbb3daf 100644
--- a/tcg/tcg.h
+++ b/tcg/tcg.h
@@ -417,20 +417,19 @@ static inline TCGCond tcg_high_cond(TCGCond c)
 }
 }
 
-#define TEMP_VAL_DEAD  0
-#define TEMP_VAL_REG   1
-#define TEMP_VAL_MEM   2
-#define TEMP_VAL_CONST 3
+typedef enum TCGTempVal {
+TEMP_VAL_DEAD,
+TEMP_VAL_REG,
+TEMP_VAL_MEM,
+TEMP_VAL_CONST,
+} TCGTempVal;
 
-/* XXX: optimize memory layout */
 typedef struct TCGTemp {
-TCGType base_type;
-TCGType type;
-int val_type;
-int reg;
-tcg_target_long val;
-int mem_reg;
-intptr_t mem_offset;
+unsigned int reg:8;
+unsigned int mem_reg:8;
+TCGTempVal val_type:8;
+TCGType base_type:8;
+TCGType type:8;
 unsigned int fixed_reg:1;
 unsigned int mem_coherent:1;
 unsigned int mem_allocated:1;
@@ -438,6 +437,9 @@ typedef struct TCGTemp {
   basic blocks. Otherwise, it is not
   preserved across basic blocks. */
 unsigned int temp_allocated:1; /* never used for code gen */
+
+tcg_target_long val;
+intptr_t mem_offset;
 const char *name;
 } TCGTemp;
 
-- 
2.1.0




[Qemu-devel] [PULL] Queued tcg patch

2015-05-05 Thread Richard Henderson
Only one tcg related patch since the 2.3 freeze.


r~



The following changes since commit 874e9aeeeb74c5459639a93439a502d262847e68:

  Merge remote-tracking branch 'remotes/kraxel/tags/pull-sdl-20150505-1' into 
staging (2015-05-05 14:06:12 +0100)

are available in the git repository at:

  git://github.com/rth7680/qemu.git tags/tcg-next-20150505

for you to fetch changes up to 00c8fa9ffeee7458e5ed62c962faf638156c18da:

  tcg: optimise memory layout of TCGTemp (2015-05-05 08:44:46 -0700)


size reduction merge


Emilio G. Cota (1):
  tcg: optimise memory layout of TCGTemp

 tcg/tcg.h | 26 ++
 1 file changed, 14 insertions(+), 12 deletions(-)



Re: [Qemu-devel] [PATCH 3/4] qemu-iotests: Make block job methods common

2015-05-05 Thread Fam Zheng
On Tue, 05/05 18:17, John Snow wrote:
 
 
 On 05/05/2015 08:46 AM, Fam Zheng wrote:
  Signed-off-by: Fam Zheng f...@redhat.com
  ---
   tests/qemu-iotests/041| 66 
  ++-
   tests/qemu-iotests/iotests.py | 28 ++
   2 files changed, 43 insertions(+), 51 deletions(-)
  
  diff --git a/tests/qemu-iotests/041 b/tests/qemu-iotests/041
  index 59a8f73..3d46ed7 100755
  --- a/tests/qemu-iotests/041
  +++ b/tests/qemu-iotests/041
  @@ -34,38 +34,8 @@ quorum_img3 = os.path.join(iotests.test_dir, 
  'quorum3.img')
   quorum_repair_img = os.path.join(iotests.test_dir, 'quorum_repair.img')
   quorum_snapshot_file = os.path.join(iotests.test_dir, 
  'quorum_snapshot.img')
   
  -class ImageMirroringTestCase(iotests.QMPTestCase):
  -'''Abstract base class for image mirroring test cases'''
   
  -def wait_ready(self, drive='drive0'):
  -'''Wait until a block job BLOCK_JOB_READY event'''
  -ready = False
  -while not ready:
  -for event in self.vm.get_qmp_events(wait=True):
  -if event['event'] == 'BLOCK_JOB_READY':
  -self.assert_qmp(event, 'data/type', 'mirror')
  -self.assert_qmp(event, 'data/device', drive)
  -ready = True
  -
  -def wait_ready_and_cancel(self, drive='drive0'):
  -self.wait_ready(drive=drive)
  -event = self.cancel_and_wait(drive=drive)
  -self.assertEquals(event['event'], 'BLOCK_JOB_COMPLETED')
  -self.assert_qmp(event, 'data/type', 'mirror')
  -self.assert_qmp(event, 'data/offset', event['data']['len'])
  -
  -def complete_and_wait(self, drive='drive0', wait_ready=True):
  -'''Complete a block job and wait for it to finish'''
  -if wait_ready:
  -self.wait_ready(drive=drive)
  -
  -result = self.vm.qmp('block-job-complete', device=drive)
  -self.assert_qmp(result, 'return', {})
  -
  -event = self.wait_until_completed(drive=drive)
  -self.assert_qmp(event, 'data/type', 'mirror')
  -
  -class TestSingleDrive(ImageMirroringTestCase):
  +class TestSingleDrive(iotests.QMPTestCase):
   image_len = 1 * 1024 * 1024 # MB
   
   def setUp(self):
  @@ -221,17 +191,9 @@ class TestSingleDriveUnalignedLength(TestSingleDrive):
   test_small_buffer2 = None
   test_large_cluster = None
   
  -class TestMirrorNoBacking(ImageMirroringTestCase):
  +class TestMirrorNoBacking(iotests.QMPTestCase):
   image_len = 2 * 1024 * 1024 # MB
   
  -def complete_and_wait(self, drive='drive0', wait_ready=True):
  -iotests.create_image(target_backing_img, 
  TestMirrorNoBacking.image_len)
  -return ImageMirroringTestCase.complete_and_wait(self, drive, 
  wait_ready)
  -
  -def compare_images(self, img1, img2):
  -iotests.create_image(target_backing_img, 
  TestMirrorNoBacking.image_len)
  -return iotests.compare_images(img1, img2)
  -
   def setUp(self):
   iotests.create_image(backing_img, TestMirrorNoBacking.image_len)
   qemu_img('create', '-f', iotests.imgfmt, '-o', 'backing_file=%s' % 
  backing_img, test_img)
  @@ -242,7 +204,10 @@ class TestMirrorNoBacking(ImageMirroringTestCase):
   self.vm.shutdown()
   os.remove(test_img)
   os.remove(backing_img)
  -os.remove(target_backing_img)
  +try:
  +os.remove(target_backing_img)
  +except:
  +pass
   os.remove(target_img)
   
   def test_complete(self):
  @@ -257,7 +222,7 @@ class TestMirrorNoBacking(ImageMirroringTestCase):
   result = self.vm.qmp('query-block')
   self.assert_qmp(result, 'return[0]/inserted/file', target_img)
   self.vm.shutdown()
  -self.assertTrue(self.compare_images(test_img, target_img),
  +self.assertTrue(iotests.compare_images(test_img, target_img),
   'target image does not match source after 
  mirroring')
   
   def test_cancel(self):
  @@ -272,7 +237,7 @@ class TestMirrorNoBacking(ImageMirroringTestCase):
   result = self.vm.qmp('query-block')
   self.assert_qmp(result, 'return[0]/inserted/file', test_img)
   self.vm.shutdown()
  -self.assertTrue(self.compare_images(test_img, target_img),
  +self.assertTrue(iotests.compare_images(test_img, target_img),
   'target image does not match source after 
  mirroring')
   
   def test_large_cluster(self):
  @@ -283,7 +248,6 @@ class TestMirrorNoBacking(ImageMirroringTestCase):
   %(TestMirrorNoBacking.image_len), 
  target_backing_img)
   qemu_img('create', '-f', iotests.imgfmt, '-o', 
  'cluster_size=%d,backing_file=%s'
   % (TestMirrorNoBacking.image_len, 
  target_backing_img), target_img)
  -os.remove(target_backing_img)
   
   result = 

Re: [Qemu-devel] [PATCH] translate-all: remove redundant page_find from tb_invalidate_phys_page

2015-05-05 Thread Richard Henderson
On 04/08/2015 02:37 PM, Emilio G. Cota wrote:
 The callers have just looked up the page descriptor, so there's no
 point in searching again for it.
 
 Signed-off-by: Emilio G. Cota c...@braap.org
 ---
  translate-all.c | 11 +++
  1 file changed, 3 insertions(+), 8 deletions(-)

Reviewed-by: Richard Henderson r...@twiddle.net


r~



Re: [Qemu-devel] [PATCH COLO v3 01/14] docs: block replication's description

2015-05-05 Thread Fam Zheng
On Wed, 05/06 02:26, Dong, Eddie wrote:
 
 
  -Original Message-
  From: Dr. David Alan Gilbert [mailto:dgilb...@redhat.com]
  Sent: Tuesday, May 05, 2015 11:24 PM
  To: Stefan Hajnoczi
  Cc: Paolo Bonzini; Wen Congyang; Fam Zheng; Kevin Wolf; Lai Jiangshan; qemu
  block; Jiang, Yunhong; Dong, Eddie; qemu devel; Max Reitz; Gonglei; Yang
  Hongyang; zhanghailiang; arm...@redhat.com; jc...@redhat.com
  Subject: Re: [PATCH COLO v3 01/14] docs: block replication's description
  
  * Stefan Hajnoczi (stefa...@redhat.com) wrote:
   On Fri, Apr 24, 2015 at 11:36:35AM +0200, Paolo Bonzini wrote:
   
   
On 24/04/2015 11:38, Wen Congyang wrote:
 
  That can be done with drive-mirror.  But I think it's too early 
  for that.
 Do you mean use drive-mirror instead of quorum?
   
Only before starting up a new secondary.  Basically you do a
migration with non-shared storage, and then start the secondary in colo
  mode.
   
But it's only for the failover case.  Quorum (or a new block/colo.c
driver or filter) is fine for normal colo operation.
  
   Perhaps this patch series should mirror the Secondary's disk to a
   Backup Secondary so that the system can be protected very quickly
   after failover.
  
   I think anyone serious about fault tolerance would deploy a Backup
   Secondary, otherwise the system cannot survive two failures unless a
   human administrator is lucky/fast enough to set up a new Secondary.
  
  I'd assumed that a higher level management layer would do the allocation of 
  a
  new secondary after the first failover, so no human need be involved.
  
 
 I agree. The cloud OS, such as open stack, will have the capability to handle
 the case, together with certain API in VMM side for this (libvirt?). 

The question here is the QMP API to switch secondary mode to primary mode is
not mentioned in this series.  I think that interface matters for this series.

Fam



Re: [Qemu-devel] qemu-ga and logging domain

2015-05-05 Thread David Gibson
On Thu, Apr 30, 2015 at 10:37:21PM -0500, Michael Roth wrote:
 Quoting David Gibson (2015-04-30 20:29:23)
  Michael,
  
  I was just looking at some of the logging stuff in qemu-ga, and it
  seems to be doing something very odd with the domain.
  
  static void ga_log(const gchar *domain, GLogLevelFlags level,
 const gchar *msg, gpointer opaque)
  {
  GAState *s = opaque;
  GTimeVal time;
  const char *level_str = ga_log_level_str(level);
  
  if (!ga_logging_enabled(s)) {
  return;
  }
  
  level = G_LOG_LEVEL_MASK;
  #ifndef _WIN32
  if (domain  strcmp(domain, syslog) == 0) {
  syslog(LOG_INFO, %s: %s, level_str, msg);
  } else if (level  s-log_level) {
  #else
  if (level  s-log_level) {
  #endif
  g_get_current_time(time);
  fprintf(s-log_file,
  %lu.%lu: %s: %s\n, time.tv_sec, time.tv_usec, level_str, 
  msg);
  fflush(s-log_file);
  }
  }
  
  This is sending messages to syslog instead of a logfile if domain is
  set to syslog.  But the log domain is usually about where the
  messages came from, not where they're going.
  
  What's up with this?
 
 Hmm, good question... IIRC I originally wanted a way to extend
 GLogLevelFlags to support a syslog log-level, but failing that
 I ended up re-purposing the unused domain field as a sort of
 hack instead.
 
 As for why I felt the need to have slog() hook into this instead
 of calling syslog() directly... I think maybe I wanted to avoid
 having a global GAState *s in the qga/command* code for
 ga_logging_enable(s), but that could simply be done by having
 the slog() implementation live in qga/main.c. Then we can drop
 the need to re-purpose g_logv()'s 'domain' field.

That sounds like a better idea to me.

-- 
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


pgpHCOlTFDqjt.pgp
Description: PGP signature


Re: [Qemu-devel] [RFC PATCH v3 08/24] ppc: Prepare CPU socket/core abstraction

2015-05-05 Thread Bharata B Rao
On Mon, May 04, 2015 at 05:15:04PM +0200, Thomas Huth wrote:
 On Fri, 24 Apr 2015 12:17:30 +0530
 Bharata B Rao bhar...@linux.vnet.ibm.com wrote:
 
  Signed-off-by: Bharata B Rao bhar...@linux.vnet.ibm.com
  Signed-off-by: Andreas Färber afaer...@suse.de
 
 Not sure if QEMU is fully following the kernel Sob-process, but if
 that's the case, I think your Sob should be below the one of Andreas in
 case you're the last person who touched the patch (and I think that's
 the case here since you've sent it out)?

The patch is from me, but I included Andreas' sob and copyrights since
the code was derived from his equivalent x86 implementation.

 
 Also a short patch description would be really nice.

Guess I will get rid of this whole socket abstraction for now as noted
in an earlier thread.

Regards,
Bharata.


Guess I will get rid of this whole socket abstraction for now as noted
in an earlier thread.

Regards,
Bharata.




Re: [Qemu-devel] [RFC PATCH v3 18/24] xics_kvm: Don't enable KVM_CAP_IRQ_XICS if already enabled

2015-05-05 Thread Bharata B Rao
On Tue, May 05, 2015 at 05:22:52PM +1000, David Gibson wrote:
 On Fri, Apr 24, 2015 at 12:17:40PM +0530, Bharata B Rao wrote:
  When supporting CPU hot removal by parking the vCPU fd and reusing
  it during hotplug again, there can be cases where we try to reenable
  KVM_CAP_IRQ_XICS CAP for the vCPU for which it was already enabled.
  Introduce a boolean member in ICPState to track this and don't
  reenable the CAP if it was already enabled earlier.
  
  This change allows CPU hot removal to work for sPAPR.
  
  Signed-off-by: Bharata B Rao bhar...@linux.vnet.ibm.com
 
 Do you actually need this?  Is there any harm in setting the
 capability multiple times, or could you just ignore the already set
 error?

We discussed this last time and concluded that this patch is needed.

Ref: http://lists.nongnu.org/archive/html/qemu-devel/2015-03/msg05361.html

Regards,
Bharata.




Re: [Qemu-devel] [RFC PATCH v3 10/24] ppc: Update cpu_model in MachineState

2015-05-05 Thread Bharata B Rao
On Tue, May 05, 2015 at 04:49:08PM +1000, David Gibson wrote:
 On Fri, Apr 24, 2015 at 12:17:32PM +0530, Bharata B Rao wrote:
  Keep cpu_model field in MachineState uptodate so that it can be used
  from the CPU hotplug path.
  
  Signed-off-by: Bharata B Rao bhar...@linux.vnet.ibm.com
  Reviewed-by: David Gibson da...@gibson.dropbear.id.au
 
 As before, this looks fine to me, but I'm not sure which tree it
 should go through.
 
 Alex, do you want to take it directly, or send an Acked-by and I'll
 take it through spapr-next?

In addition to this patch, there are a few other patches that are required
by hotplug but can go in independently.

03/24 - spapr: Consider max_cpus during xics initialization
04/24 - spapr: Support ibm,lrdr-capacity device tree property
05/24 - spapr: Reorganize CPU dt generation code (Maybe?)
06/24 - spapr: Consolidate cpu init code into a routine
18/24 - xics_kvm: Don't enable KVM_CAP_IRQ_XICS if already enabled
19/24 - xics_kvm: Add cpu_destroy method to XICS

Should I post these as a separate set (pre-requisites for sPAPR CPU hotplug)
so that they can be pushed independently of the core hotplug patchset ?

Regards,
Bharata.




[Qemu-devel] [PATCH v2 1/6] mirror: Discard target sectors if not allocated at source side

2015-05-05 Thread Fam Zheng
If guest discards a source cluster during mirror, we would want to
discard target side as well.

Signed-off-by: Fam Zheng f...@redhat.com
---
 block/mirror.c | 12 ++--
 1 file changed, 10 insertions(+), 2 deletions(-)

diff --git a/block/mirror.c b/block/mirror.c
index 58f391a..37a5b61 100644
--- a/block/mirror.c
+++ b/block/mirror.c
@@ -163,6 +163,7 @@ static uint64_t coroutine_fn 
mirror_iteration(MirrorBlockJob *s)
 int64_t end, sector_num, next_chunk, next_sector, hbitmap_next_sector;
 uint64_t delay_ns = 0;
 MirrorOp *op;
+int pnum;
 
 s-sector_num = hbitmap_iter_next(s-hbi);
 if (s-sector_num  0) {
@@ -289,8 +290,15 @@ static uint64_t coroutine_fn 
mirror_iteration(MirrorBlockJob *s)
 s-in_flight++;
 s-sectors_in_flight += nb_sectors;
 trace_mirror_one_iteration(s, sector_num, nb_sectors);
-bdrv_aio_readv(source, sector_num, op-qiov, nb_sectors,
-   mirror_read_complete, op);
+
+if (!bdrv_is_allocated_above(source, NULL, sector_num,
+ nb_sectors, pnum)) {
+bdrv_aio_discard(s-target, sector_num, nb_sectors,
+ mirror_write_complete, op);
+} else {
+bdrv_aio_readv(source, sector_num, op-qiov, nb_sectors,
+   mirror_read_complete, op);
+}
 return delay_ns;
 }
 
-- 
1.9.3




[Qemu-devel] [PATCH v2 0/6] block: Mirror discarded sectors

2015-05-05 Thread Fam Zheng
v2: Fix typo and add Eric's rev-by in patch 3.
Add patch 1 to discard target in mirror job. (Paolo)
Add patch 6 to improve iotests.wait_ready. (John)

This fixes the mirror assert failure reported by wangxiaolong:

https://lists.gnu.org/archive/html/qemu-devel/2015-04/msg04458.html

The direct cause is that hbitmap code couldn't handle unset of bits *after*
iterator's current position. We could fix that, but the bdrv_reset_dirty() call
is more questionable:

Before, if guest discarded some sectors during migration, it could see
different data after moving to dest side, depending on block backends of the
src and the dest. This is IMO worse than mirroring the actual reading as done
in this series, because we don't know what the guest is doing.

For example if a guest first issues WRITE SAME to wipe out the area then issues
UNMAP to discard it, just to get rid of some sensitive data completely, we may
miss both operations and leave stale data on dest image.


Fam Zheng (6):
  mirror: Discard target sectors if not allocated at source side
  block: Fix dirty bitmap in bdrv_co_discard
  block: Remove bdrv_reset_dirty
  qemu-iotests: Make block job methods common
  qemu-iotests: Add test case for mirror with unmap
  iotests: Use event_wait in wait_ready

 block.c   | 12 
 block/io.c|  4 +--
 block/mirror.c| 12 ++--
 include/block/block_int.h |  2 --
 tests/qemu-iotests/041| 66 ++-
 tests/qemu-iotests/131| 59 ++
 tests/qemu-iotests/131.out|  5 
 tests/qemu-iotests/group  |  1 +
 tests/qemu-iotests/iotests.py | 23 +++
 9 files changed, 115 insertions(+), 69 deletions(-)
 create mode 100644 tests/qemu-iotests/131
 create mode 100644 tests/qemu-iotests/131.out

-- 
1.9.3




[Qemu-devel] [PATCH v2 6/6] iotests: Use event_wait in wait_ready

2015-05-05 Thread Fam Zheng
Only poll the specific type of event we are interested in, to avoid
stealing events that should be consumed by someone else.

Suggested-by: John Snow js...@redhat.com
Signed-off-by: Fam Zheng f...@redhat.com
---
 tests/qemu-iotests/iotests.py | 9 ++---
 1 file changed, 2 insertions(+), 7 deletions(-)

diff --git a/tests/qemu-iotests/iotests.py b/tests/qemu-iotests/iotests.py
index 2e07cc4..0ddc513 100644
--- a/tests/qemu-iotests/iotests.py
+++ b/tests/qemu-iotests/iotests.py
@@ -328,13 +328,8 @@ class QMPTestCase(unittest.TestCase):
 
 def wait_ready(self, drive='drive0'):
 '''Wait until a block job BLOCK_JOB_READY event'''
-ready = False
-while not ready:
-for event in self.vm.get_qmp_events(wait=True):
-if event['event'] == 'BLOCK_JOB_READY':
-self.assert_qmp(event, 'data/type', 'mirror')
-self.assert_qmp(event, 'data/device', drive)
-ready = True
+f = {'data': {'type': 'mirror', 'device': drive } }
+event = self.vm.event_wait(name='BLOCK_JOB_READY', match=f)
 
 def wait_ready_and_cancel(self, drive='drive0'):
 self.wait_ready(drive=drive)
-- 
1.9.3




[Qemu-devel] [PATCH v2 3/6] block: Remove bdrv_reset_dirty

2015-05-05 Thread Fam Zheng
Using this function would always be wrong because a dirty bitmap must
have a specific owner that consumes the dirty bits and calls
bdrv_reset_dirty_bitmap().

Remove the unused function to avoid future misuse.

Reviewed-by: Eric Blake ebl...@redhat.com
Signed-off-by: Fam Zheng f...@redhat.com
---
 block.c   | 12 
 include/block/block_int.h |  2 --
 2 files changed, 14 deletions(-)

diff --git a/block.c b/block.c
index 7904098..511e13c 100644
--- a/block.c
+++ b/block.c
@@ -3324,18 +3324,6 @@ void bdrv_set_dirty(BlockDriverState *bs, int64_t 
cur_sector,
 }
 }
 
-void bdrv_reset_dirty(BlockDriverState *bs, int64_t cur_sector,
-  int nr_sectors)
-{
-BdrvDirtyBitmap *bitmap;
-QLIST_FOREACH(bitmap, bs-dirty_bitmaps, list) {
-if (!bdrv_dirty_bitmap_enabled(bitmap)) {
-continue;
-}
-hbitmap_reset(bitmap-bitmap, cur_sector, nr_sectors);
-}
-}
-
 /**
  * Advance an HBitmapIter to an arbitrary offset.
  */
diff --git a/include/block/block_int.h b/include/block/block_int.h
index db29b74..aaed2fa 100644
--- a/include/block/block_int.h
+++ b/include/block/block_int.h
@@ -635,7 +635,5 @@ bool blk_dev_is_medium_locked(BlockBackend *blk);
 void blk_dev_resize_cb(BlockBackend *blk);
 
 void bdrv_set_dirty(BlockDriverState *bs, int64_t cur_sector, int nr_sectors);
-void bdrv_reset_dirty(BlockDriverState *bs, int64_t cur_sector,
-  int nr_sectors);
 
 #endif /* BLOCK_INT_H */
-- 
1.9.3




[Qemu-devel] [PATCH v2 2/6] block: Fix dirty bitmap in bdrv_co_discard

2015-05-05 Thread Fam Zheng
Unsetting dirty globally with discard is not very correct. The discard may zero
out sectors (depending on can_write_zeroes_with_unmap), we should replicate
this change to destinition side to make sure that the guest sees the same data.

Calling bdrv_reset_dirty also troubles mirror job because the hbitmap iterator
doesn't expect unsetting of bits after current position.

So let's do it the opposite way which fixes both problems: set the dirty bits
if we are to discard it.

Reported-by: wangxiaol...@ucloud.cn
Signed-off-by: Fam Zheng f...@redhat.com
---
 block/io.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/block/io.c b/block/io.c
index 1ce62c4..809688b 100644
--- a/block/io.c
+++ b/block/io.c
@@ -2343,8 +2343,6 @@ int coroutine_fn bdrv_co_discard(BlockDriverState *bs, 
int64_t sector_num,
 return -EROFS;
 }
 
-bdrv_reset_dirty(bs, sector_num, nb_sectors);
-
 /* Do nothing if disabled.  */
 if (!(bs-open_flags  BDRV_O_UNMAP)) {
 return 0;
@@ -2354,6 +2352,8 @@ int coroutine_fn bdrv_co_discard(BlockDriverState *bs, 
int64_t sector_num,
 return 0;
 }
 
+bdrv_set_dirty(bs, sector_num, nb_sectors);
+
 max_discard = MIN_NON_ZERO(bs-bl.max_discard, BDRV_REQUEST_MAX_SECTORS);
 while (nb_sectors  0) {
 int ret;
-- 
1.9.3




[Qemu-devel] [PATCH v2 5/6] qemu-iotests: Add test case for mirror with unmap

2015-05-05 Thread Fam Zheng
This checks that the discard on mirror source that effectively zeroes
data is also reflected by the data of target.

Signed-off-by: Fam Zheng f...@redhat.com
---
 tests/qemu-iotests/131 | 59 ++
 tests/qemu-iotests/131.out |  5 
 tests/qemu-iotests/group   |  1 +
 3 files changed, 65 insertions(+)
 create mode 100644 tests/qemu-iotests/131
 create mode 100644 tests/qemu-iotests/131.out

diff --git a/tests/qemu-iotests/131 b/tests/qemu-iotests/131
new file mode 100644
index 000..f53ef6e
--- /dev/null
+++ b/tests/qemu-iotests/131
@@ -0,0 +1,59 @@
+#!/usr/bin/env python
+#
+# Test mirror with unmap
+#
+# Copyright (C) 2015 Red Hat, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program.  If not, see http://www.gnu.org/licenses/.
+#
+
+import time
+import os
+import iotests
+from iotests import qemu_img, qemu_io
+
+test_img = os.path.join(iotests.test_dir, 'test.img')
+target_img = os.path.join(iotests.test_dir, 'target.img')
+
+class TestSingleDrive(iotests.QMPTestCase):
+image_len = 2 * 1024 * 1024 # MB
+
+def setUp(self):
+# Write data to the image so we can compare later
+qemu_img('create', '-f', iotests.imgfmt, test_img, 
str(TestSingleDrive.image_len))
+qemu_io('-f', iotests.imgfmt, '-c', 'write -P0x5d 0 2M', test_img)
+
+self.vm = iotests.VM().add_drive(test_img, 'discard=unmap')
+self.vm.launch()
+
+def tearDown(self):
+self.vm.shutdown()
+os.remove(test_img)
+try:
+os.remove(target_img)
+except OSError:
+pass
+
+def test_mirror_discard(self):
+result = self.vm.qmp('drive-mirror', device='drive0', sync='full',
+ target=target_img)
+self.assert_qmp(result, 'return', {})
+self.vm.hmp_qemu_io('drive0', 'discard 0 64k')
+self.complete_and_wait('drive0')
+self.vm.shutdown()
+self.assertTrue(iotests.compare_images(test_img, target_img),
+'target image does not match source after mirroring')
+
+if __name__ == '__main__':
+iotests.main(supported_fmts=['raw', 'qcow2'])
diff --git a/tests/qemu-iotests/131.out b/tests/qemu-iotests/131.out
new file mode 100644
index 000..ae1213e
--- /dev/null
+++ b/tests/qemu-iotests/131.out
@@ -0,0 +1,5 @@
+.
+--
+Ran 1 tests
+
+OK
diff --git a/tests/qemu-iotests/group b/tests/qemu-iotests/group
index 6ca3466..34b16cb 100644
--- a/tests/qemu-iotests/group
+++ b/tests/qemu-iotests/group
@@ -128,3 +128,4 @@
 128 rw auto quick
 129 rw auto quick
 130 rw auto quick
+131 rw auto quick
-- 
1.9.3




Re: [Qemu-devel] [PATCH v3 2/6] spapr_pci: encode missing 64-bit memory address space

2015-05-05 Thread Nikunj A Dadhania
Thomas Huth th...@redhat.com writes:

 On Tue,  5 May 2015 14:23:52 +0530
 Nikunj A Dadhania nik...@linux.vnet.ibm.com wrote:

 The properties reg/assigned-resources need to encode 64-bit memory
 address space as part of phys.hi dword.
 
   00 if configuration space
   01 if IO region,
   10 if 32-bit MEM region
   11 if 64-bit MEM region
 
 Signed-off-by: Nikunj A Dadhania nik...@linux.vnet.ibm.com
 ---
  hw/ppc/spapr_pci.c | 10 +-
  1 file changed, 9 insertions(+), 1 deletion(-)
 
 diff --git a/hw/ppc/spapr_pci.c b/hw/ppc/spapr_pci.c
 index 4df3a33..ea1a092 100644
 --- a/hw/ppc/spapr_pci.c
 +++ b/hw/ppc/spapr_pci.c
 @@ -786,7 +786,13 @@ typedef struct ResourceProps {
   * phys.hi = 0xYYZZ, where:
   *   0xYY = npt000ss
   *  |||   |
 - *  |||   +-- space code: 1 if IO region, 2 if MEM region
 + *  |||   +-- space code
 + *  |||   |
 + *  |||   +  00 if configuration space
 + *  |||   +  01 if IO region,
 + *  |||   +  10 if 32-bit MEM region
 + *  |||   +  11 if 64-bit MEM region
 + *  |||
   *  ||+-- for non-relocatable IO: 1 if aliased
   *  ||for relocatable IO: 1 if below 64KB
   *  ||for MEM: 1 if below 1MB
 @@ -846,6 +852,8 @@ static void populate_resource_props(PCIDevice *d, 
 ResourceProps *rp)
  reg-phys_hi = cpu_to_be32(dev_id | b_(pci_bar(d, i)));
  if (d-io_regions[i].type  PCI_BASE_ADDRESS_SPACE_IO) {
  reg-phys_hi |= cpu_to_be32(b_ss(1));
 +} else if (d-io_regions[i].type  PCI_BASE_ADDRESS_MEM_TYPE_64) {
 +reg-phys_hi |= cpu_to_be32(b_ss(3));
  } else {
  reg-phys_hi |= cpu_to_be32(b_ss(2));
  }

 Reviewed-by: Thomas Huth th...@redhat.com

 BTW, does this also require the new version of SLOF already?

Not yet, only after patch 4/6 newer SLOF would be needed.

This fixes the hotplug case for device requesting 64-bit bars, like
nec-usb-xhci.

Regards,
Nikunj




Re: [Qemu-devel] [PATCH v3 5/6] spapr_pci: fix boot-time device tree fields for pci hotplug

2015-05-05 Thread Nikunj A Dadhania
David Gibson da...@gibson.dropbear.id.au writes:

 On Tue, May 05, 2015 at 02:23:55PM +0530, Nikunj A Dadhania wrote:
 From: Michael Roth mdr...@linux.vnet.ibm.com
 
 We need to set the proper drc_index values in ibm,my-drc-index
 fields in order to allow a PCI device that was present at
 boot-time to be unplugged.
 
 Previously SLOF handles this, but with QEMU handling the DT we
 need to do it there as well.
 
 This patch slightly changes how SLOF handled it in the past,
 which was to allows add an ibm,my-drc-index value based on
 PCI slot/devices topology. Now we only add it when the slot
 supports hotplug and has a DR connector, which is more inline
 with PAPR.
 
 Signed-off-by: Michael Roth mdr...@linux.vnet.ibm.com
 Signed-off-by: Nikunj A Dadhania nik...@linux.vnet.ibm.com
 ---
  hw/ppc/spapr_pci.c | 21 +++--
  1 file changed, 19 insertions(+), 2 deletions(-)
 
 diff --git a/hw/ppc/spapr_pci.c b/hw/ppc/spapr_pci.c
 index 103284a..cbd5661 100644
 --- a/hw/ppc/spapr_pci.c
 +++ b/hw/ppc/spapr_pci.c
 @@ -951,7 +951,9 @@ static int spapr_populate_pci_child_dt(PCIDevice *dev, 
 void *fdt, int offset,
  _FDT(fdt_setprop(fdt, offset, ibm,loc-code, drc_name,
   strlen(drc_name)));
  }
 -_FDT(fdt_setprop_cell(fdt, offset, ibm,my-drc-index, drc_index));
 +if (drc_index) {
 +_FDT(fdt_setprop_cell(fdt, offset, ibm,my-drc-index, drc_index));
 +}
  
  _FDT(fdt_setprop_cell(fdt, offset, #address-cells,
RESOURCE_CELLS_ADDRESS));
 @@ -1483,6 +1485,20 @@ PCIHostState *spapr_create_phb(sPAPREnvironment 
 *spapr, int index)
  return PCI_HOST_BRIDGE(dev);
  }
  
 +static uint32_t spapr_phb_get_pci_drc_index(sPAPRPHBState *phb,
 +PCIDevice *pdev)
 +{
 +sPAPRDRConnector *drc = spapr_phb_get_pci_drc(phb, pdev);
 +sPAPRDRConnectorClass *drck;
 +
 +if (!drc) {
 +return 0;
 +}
 +
 +drck = SPAPR_DR_CONNECTOR_GET_CLASS(drc);
 +return drck-get_index(drc);
 +}
 +
  typedef struct sPAPRFDT {
  void *fdt;
  int node_off;
 @@ -1499,6 +1515,7 @@ static void spapr_populate_pci_devices_dt(PCIBus *bus, 
 PCIDevice *pdev,
  int func = PCI_FUNC(pdev-devfn);
  char nodename[512];
  sPAPRFDT s_fdt;
 +uint32_t drc_index = spapr_phb_get_pci_drc_index(p-sphb, pdev);

 The line above causes a compile error, since sPAPRFDT doesn't have an
 sphb member.

 Its fixed in the next patch, but can you adjust the series so it won't
 break bisection.

Sure, will rearrange the patch.



  if (func) {
  sprintf(nodename, pci@%d,%d, slot, func);
 @@ -1506,7 +1523,7 @@ static void spapr_populate_pci_devices_dt(PCIBus *bus, 
 PCIDevice *pdev,
  sprintf(nodename, pci@%d, slot);
  }
  offset = fdt_add_subnode(p-fdt, p-node_off, nodename);
 -ret = spapr_populate_pci_child_dt(pdev, p-fdt, offset, p-index, 0, 
 NULL);
 +ret = spapr_populate_pci_child_dt(pdev, p-fdt, offset, p-index, 
 drc_index, NULL);
  g_assert(!ret);
  
  if ((pci_default_read_config(pdev, PCI_HEADER_TYPE, 1) !=

 -- 
 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 PATCH v3 07/24] cpu: Prepare Socket container type

2015-05-05 Thread Bharata B Rao
On Tue, May 05, 2015 at 11:47:30AM +1000, David Gibson wrote:
 On Fri, Apr 24, 2015 at 12:17:29PM +0530, Bharata B Rao wrote:
  From: Andreas Färber afaer...@suse.de
  
  Signed-off-by: Andreas Färber afaer...@suse.de
  Signed-off-by: Bharata B Rao bhar...@linux.vnet.ibm.com
 
 So, how to organize this generically is still under discussion.  For
 now, I don't think this generic outline is really worth it.  In any
 case I can't really take it through my tree.
 
 What I'd suggest instead is just implementing the POWER core device in
 the ppc specific code.  As the generic socket vs. core vs. whatever
 stuff clarifies, that POWER core device might become a virtual
 socket or CM or whatever, but I think we'll be able to keep the
 external interface compatible with the right use of aliases.
 
 In the meantime it should at least give us a draft we can experiment
 with on Power without requiring new generic infrastructure.

Makes sense, I will switch to the semantics that I had in v1 where
I enabled CPU hotplug for POWER8 using device_add.

(qemu) device_add POWER8-powerpc64-cpu,id=XXX

Regards,
Bharata.




Re: [Qemu-devel] [PATCH v3 1/6] spapr_pci: remove duplicate macros

2015-05-05 Thread Nikunj A Dadhania
Thomas Huth th...@redhat.com writes:

 On Tue,  5 May 2015 14:23:51 +0530
 Nikunj A Dadhania nik...@linux.vnet.ibm.com wrote:

 Signed-off-by: Nikunj A Dadhania nik...@linux.vnet.ibm.com
 ---
  hw/ppc/spapr_pci.c | 11 ---
  1 file changed, 11 deletions(-)
 
 diff --git a/hw/ppc/spapr_pci.c b/hw/ppc/spapr_pci.c
 index 2e7590c..4df3a33 100644
 --- a/hw/ppc/spapr_pci.c
 +++ b/hw/ppc/spapr_pci.c
 @@ -1475,17 +1475,6 @@ PCIHostState *spapr_create_phb(sPAPREnvironment 
 *spapr, int index)
  return PCI_HOST_BRIDGE(dev);
  }
  
 -/* Macros to operate with address in OF binding to PCI */
 -#define b_x(x, p, l)(((x)  ((1(l))-1))  (p))
 -#define b_n(x)  b_x((x), 31, 1) /* 0 if relocatable */
 -#define b_p(x)  b_x((x), 30, 1) /* 1 if prefetchable */
 -#define b_t(x)  b_x((x), 29, 1) /* 1 if the address is aliased */
 -#define b_ss(x) b_x((x), 24, 2) /* the space code */
 -#define b_(x)   b_x((x), 16, 8) /* bus number */
 -#define b_d(x)  b_x((x), 11, 5) /* device number */
 -#define b_fff(x)b_x((x), 8, 3)  /* function number */
 -#define b_(x)   b_x((x), 0, 8)  /* register number */

 Seems like the duplication is not in master yet, only in spapr-next,
 and has apparently been introduced by commit 2c938a6692c01818e 
 (spapr_pci: enable basic hotplug operations) ...
 So an alternative would be to fix up that patch instead. David?

Yes, that would be fine with me as well.

 Anyway, the duplication should go away, so:

 Reviewed-by: Thomas Huth th...@redhat.com

Regards
Nikunj




[Qemu-devel] Bug report - Windows XP guest failure

2015-05-05 Thread Programmingkid
Just wanted to note that for the i386 target, Windows XP as a guest fails to 
boot. When it safe mode, loading always stops at  
Windows\System32\Drivers\Mup.sys. The guest boots in QEMU 2.2.0, so this seems 
to indicate a bug with the May 5th or earlier patch set. 


Re: [Qemu-devel] [PATCH v3 4/6] spapr_pci: enumerate and add PCI device tree

2015-05-05 Thread Nikunj A Dadhania
Thomas Huth th...@redhat.com writes:

 On Tue,  5 May 2015 14:23:54 +0530
 Nikunj A Dadhania nik...@linux.vnet.ibm.com wrote:

 All the PCI enumeration and device node creation was off-loaded to
 SLOF. With PCI hotplug support, code needed to be added to add device
 node. This creates multiple copy of the code one in SLOF and other in
 hotplug code. To unify this, the patch adds the pci device node
 creation in Qemu. For backward compatibility, a flag
 qemu,phb-enumerated is added to the phb, suggesting to SLOF to not
 do device node creation.
 
 Signed-off-by: Nikunj A Dadhania nik...@linux.vnet.ibm.com
 ---
  hw/ppc/spapr_pci.c | 108 
 ++---
  1 file changed, 103 insertions(+), 5 deletions(-)
 
 diff --git a/hw/ppc/spapr_pci.c b/hw/ppc/spapr_pci.c
 index 8b02a3e..103284a 100644
 --- a/hw/ppc/spapr_pci.c
 +++ b/hw/ppc/spapr_pci.c
 @@ -23,6 +23,7 @@
   * THE SOFTWARE.
   */
  #include hw/hw.h
 +#include hw/sysbus.h
  #include hw/pci/pci.h
  #include hw/pci/msi.h
  #include hw/pci/msix.h
 @@ -35,6 +36,7 @@
  #include qemu/error-report.h
  #include qapi/qmp/qerror.h
  
 +#include hw/pci/pci_bridge.h
  #include hw/pci/pci_bus.h
  #include hw/ppc/spapr_drc.h
  #include sysemu/device_tree.h
 @@ -945,7 +947,10 @@ static int spapr_populate_pci_child_dt(PCIDevice *dev, 
 void *fdt, int offset,
   * processed by OF beforehand
   */
  _FDT(fdt_setprop_string(fdt, offset, name, pci));
 -_FDT(fdt_setprop(fdt, offset, ibm,loc-code, drc_name, 
 strlen(drc_name)));
 +if (drc_name) {
 +_FDT(fdt_setprop(fdt, offset, ibm,loc-code, drc_name,
 + strlen(drc_name)));
 +}
  _FDT(fdt_setprop_cell(fdt, offset, ibm,my-drc-index, drc_index));
  
  _FDT(fdt_setprop_cell(fdt, offset, #address-cells,
 @@ -1001,10 +1006,6 @@ static void spapr_phb_add_pci_device(sPAPRDRConnector 
 *drc,
  void *fdt = NULL;
  int fdt_start_offset = 0;
  
 -/* boot-time devices get their device tree node created by SLOF, but for
 - * hotplugged devices we need QEMU to generate it so the guest can fetch
 - * it via RTAS
 - */
  if (dev-hotplugged) {
  fdt = spapr_create_pci_child_dt(phb, pdev, drc_index, drc_name,
  fdt_start_offset);
 @@ -1482,6 +1483,89 @@ PCIHostState *spapr_create_phb(sPAPREnvironment 
 *spapr, int index)
  return PCI_HOST_BRIDGE(dev);
  }
  
 +typedef struct sPAPRFDT {
 +void *fdt;
 +int node_off;
 +uint32_t index;
 +} sPAPRFDT;
 +
 +static void spapr_populate_pci_devices_dt(PCIBus *bus, PCIDevice *pdev,
 +  void *opaque)
 +{
 +PCIBus *sec_bus;
 +sPAPRFDT *p = opaque;
 +int ret, offset;
 +int slot = PCI_SLOT(pdev-devfn);
 +int func = PCI_FUNC(pdev-devfn);
 +char nodename[512];

 That's quite a big array 

 +sPAPRFDT s_fdt;
 +
 +if (func) {
 +sprintf(nodename, pci@%d,%d, slot, func);
 +} else {
 +sprintf(nodename, pci@%d, slot);
 +}

 ... just for holding such a small string. Could you maybe use
 a smaller array size for nodename (especially since you call this
 function recursively)?

Sure, will change this to 32 bytes, that should be sufficient. 


 +offset = fdt_add_subnode(p-fdt, p-node_off, nodename);
 +ret = spapr_populate_pci_child_dt(pdev, p-fdt, offset, p-index, 0, 
 NULL);

 The above code sequence looks pretty much similar to
 spapr_create_pci_child_dt() ... maybe it's worth the effort to merge
 the common code of both functions into a separate helper function
 to avoid the duplication? ... not sure if this is worth the effort,
 it's just a suggestion.

I had thought about it earlier but something was not matching. Let me
have a relook, things have changed.


 +g_assert(!ret);

 You know that assert statements can simply be disabled by a
 preprocessor switch - and in that case there is no more error handling
 here at all and the code continues silently with a partial initialized
 node!

Thanks for bringing this to notice, assert() ?

 So it's maybe better to do a proper error handling here instead?

Will change this error handling here.


 +if ((pci_default_read_config(pdev, PCI_HEADER_TYPE, 1) !=
 + PCI_HEADER_TYPE_BRIDGE)) {
 +return;
 +}
 +
 +sec_bus = pci_bridge_get_sec_bus(PCI_BRIDGE(pdev));
 +if (!sec_bus) {
 +return;
 +}
 +
 +s_fdt.fdt = p-fdt;
 +s_fdt.node_off = offset;
 +s_fdt.index = p-index;
 +pci_for_each_device(sec_bus, pci_bus_num(sec_bus),
 +spapr_populate_pci_devices_dt,
 +s_fdt);
 +}
 +
 +static void spapr_phb_pci_enumerate_bridge(PCIBus *bus, PCIDevice *pdev,
 +   void *opaque)
 +{
 +unsigned short *bus_no = (unsigned short *) opaque;

 opaque is a void pointer, so I think you don't need the typecast here.

Ok, QEMU has strong type checking, so by 

Re: [Qemu-devel] [RFC PATCH v3 06/24] spapr: Consolidate cpu init code into a routine

2015-05-05 Thread Bharata B Rao
On Mon, May 04, 2015 at 06:10:59PM +0200, Thomas Huth wrote:
 On Fri, 24 Apr 2015 12:17:28 +0530
 Bharata B Rao bhar...@linux.vnet.ibm.com wrote:
 
  Factor out bits of sPAPR specific CPU initialization code into
  a separate routine so that it can be called from CPU hotplug
  path too.
  
  Signed-off-by: Bharata B Rao bhar...@linux.vnet.ibm.com
  Reviewed-by: David Gibson da...@gibson.dropbear.id.au
  ---
   hw/ppc/spapr.c | 54 +-
   1 file changed, 29 insertions(+), 25 deletions(-)
  
  diff --git a/hw/ppc/spapr.c b/hw/ppc/spapr.c
  index a56f9a1..5c8f2ff 100644
  --- a/hw/ppc/spapr.c
  +++ b/hw/ppc/spapr.c
  @@ -1440,6 +1440,34 @@ static void spapr_drc_reset(void *opaque)
   }
   }
   
  +static void spapr_cpu_init(PowerPCCPU *cpu)
  +{
  +CPUPPCState *env = cpu-env;
  +
  +/* Set time-base frequency to 512 MHz */
  +cpu_ppc_tb_init(env, TIMEBASE_FREQ);
  +
  +/* PAPR always has exception vectors in RAM not ROM. To ensure this,
  + * MSR[IP] should never be set.
  + */
  +env-msr_mask = ~(1  6);
 
 While you're at it ... could we maybe get a proper #define for that MSR
 bit? (just like the other ones in target-ppc/cpu.h)

Sure will use MSR_EP here next time.

Regards,
Bharata.




Re: [Qemu-devel] [RFC PATCH v3 12/24] spapr: CPU hotplug support

2015-05-05 Thread Bharata B Rao
On Mon, May 04, 2015 at 05:53:23PM +0200, Thomas Huth wrote:
 On Fri, 24 Apr 2015 12:17:34 +0530
 Bharata B Rao bhar...@linux.vnet.ibm.com wrote:
 
  Support CPU hotplug via device-add command. Set up device tree
  entries for the hotplugged CPU core and use the exising EPOW event
  infrastructure to send CPU hotplug notification to the guest.
  
  Also support cold plugged CPUs that are specified by -device option
  on cmdline.
  
  Signed-off-by: Bharata B Rao bhar...@linux.vnet.ibm.com
  ---
   hw/ppc/spapr.c| 129 
  ++
   hw/ppc/spapr_events.c |   8 ++--
   hw/ppc/spapr_rtas.c   |  11 +
   3 files changed, 145 insertions(+), 3 deletions(-)
  
  diff --git a/hw/ppc/spapr.c b/hw/ppc/spapr.c
  index b526b7d..9b0701c 100644
  --- a/hw/ppc/spapr.c
  +++ b/hw/ppc/spapr.c
 [...]
  +static void spapr_cpu_plug(HotplugHandler *hotplug_dev, DeviceState *dev,
  +Error **errp)
  +{
  +CPUState *cs = CPU(dev);
  +PowerPCCPU *cpu = POWERPC_CPU(cs);
  +int id = ppc_get_vcpu_dt_id(cpu);
  +sPAPRDRConnector *drc =
  +spapr_dr_connector_by_id(SPAPR_DR_CONNECTOR_TYPE_CPU, id);
  +sPAPRDRConnectorClass *drck;
  +int smt = kvmppc_smt_threads();
  +Error *local_err = NULL;
  +void *fdt = NULL;
  +int i, fdt_offset = 0;
  +
  +/* Set NUMA node for the added CPUs  */
  +for (i = 0; i  nb_numa_nodes; i++) {
  +if (test_bit(cs-cpu_index, numa_info[i].node_cpu)) {
  +cs-numa_node = i;
  +break;
  +}
  +}
  +
  +/*
  + * SMT threads return from here, only main thread (core) will
  + * continue and signal hotplug event to the guest.
  + */
  +if ((id % smt) != 0) {
  +return;
  +}
  +
  +if (!spapr-dr_cpu_enabled) {
  +/*
  + * This is a cold plugged CPU but the machine doesn't support
  + * DR. So skip the hotplug path ensuring that the CPU is brought
  + * up online with out an associated DR connector.
  + */
  +return;
  +}
  +
  +g_assert(drc);
  +
  +/*
  + * Setup CPU DT entries only for hotplugged CPUs. For boot time or
  + * coldplugged CPUs DT entries are setup in spapr_finalize_fdt().
  + */
  +if (dev-hotplugged) {
  +fdt = spapr_populate_hotplug_cpu_dt(dev, cs, fdt_offset);
  +}
  +
  +drck = SPAPR_DR_CONNECTOR_GET_CLASS(drc);
  +drck-attach(drc, dev, fdt, fdt_offset, !dev-hotplugged, local_err);
  +if (local_err) {
  +g_free(fdt);
  +error_propagate(errp, local_err);
  +return;
  +}
  +
  +/*
  + * We send hotplug notification interrupt to the guest only in case
  + * of hotplugged CPUs.
  + */
  +if (dev-hotplugged) {
  +spapr_hotplug_req_add_event(drc);
  +} else {
  +/*
  + * HACK to support removal of hotplugged CPU after VM migration:
  + *
  + * Since we want to be able to hot-remove those coldplugged CPUs
  + * started at boot time using -device option at the target VM, we 
  set
  + * the right allocation_state and isolation_state for them, which 
  for
  + * the hotplugged CPUs would be set via RTAS calls done from the
  + * guest during hotplug.
  + *
  + * This allows the coldplugged CPUs started using -device option to
  + * have the right isolation and allocation states as expected by 
  the
  + * CPU hot removal code.
  + *
  + * This hack will be removed once we have DRC states migrated as 
  part
  + * of VM migration.
  + */
  +drck-set_allocation_state(drc, SPAPR_DR_ALLOCATION_STATE_USABLE);
  +drck-set_isolation_state(drc, 
  SPAPR_DR_ISOLATION_STATE_UNISOLATED);
  +}
  +
  +return;
 
 Cosmetic nit: Superfluous return statement
 
  +}
  +
 [...]
  diff --git a/hw/ppc/spapr_rtas.c b/hw/ppc/spapr_rtas.c
  index 57ec97a..48aeb86 100644
  --- a/hw/ppc/spapr_rtas.c
  +++ b/hw/ppc/spapr_rtas.c
  @@ -121,6 +121,16 @@ static void rtas_query_cpu_stopped_state(PowerPCCPU 
  *cpu_,
   rtas_st(rets, 0, RTAS_OUT_PARAM_ERROR);
   }
   
  +static void spapr_cpu_set_endianness(PowerPCCPU *cpu)
  +{
  +PowerPCCPU *fcpu = POWERPC_CPU(first_cpu);
  +PowerPCCPUClass *pcc = POWERPC_CPU_GET_CLASS(fcpu);
  +
  +if (!(*pcc-interrupts_big_endian)(fcpu)) {
 
 Functions pointers are sometimes still confusing to me, but can't you
 simplify that to:
 
 if (!pcc-interrupts_big_endian(fcpu)) {

That should work too. Thanks.

Regards,
Bharata.




[Qemu-devel] [PATCH v2 4/6] qemu-iotests: Make block job methods common

2015-05-05 Thread Fam Zheng
Signed-off-by: Fam Zheng f...@redhat.com
---
 tests/qemu-iotests/041| 66 ++-
 tests/qemu-iotests/iotests.py | 28 ++
 2 files changed, 43 insertions(+), 51 deletions(-)

diff --git a/tests/qemu-iotests/041 b/tests/qemu-iotests/041
index 59a8f73..3d46ed7 100755
--- a/tests/qemu-iotests/041
+++ b/tests/qemu-iotests/041
@@ -34,38 +34,8 @@ quorum_img3 = os.path.join(iotests.test_dir, 'quorum3.img')
 quorum_repair_img = os.path.join(iotests.test_dir, 'quorum_repair.img')
 quorum_snapshot_file = os.path.join(iotests.test_dir, 'quorum_snapshot.img')
 
-class ImageMirroringTestCase(iotests.QMPTestCase):
-'''Abstract base class for image mirroring test cases'''
 
-def wait_ready(self, drive='drive0'):
-'''Wait until a block job BLOCK_JOB_READY event'''
-ready = False
-while not ready:
-for event in self.vm.get_qmp_events(wait=True):
-if event['event'] == 'BLOCK_JOB_READY':
-self.assert_qmp(event, 'data/type', 'mirror')
-self.assert_qmp(event, 'data/device', drive)
-ready = True
-
-def wait_ready_and_cancel(self, drive='drive0'):
-self.wait_ready(drive=drive)
-event = self.cancel_and_wait(drive=drive)
-self.assertEquals(event['event'], 'BLOCK_JOB_COMPLETED')
-self.assert_qmp(event, 'data/type', 'mirror')
-self.assert_qmp(event, 'data/offset', event['data']['len'])
-
-def complete_and_wait(self, drive='drive0', wait_ready=True):
-'''Complete a block job and wait for it to finish'''
-if wait_ready:
-self.wait_ready(drive=drive)
-
-result = self.vm.qmp('block-job-complete', device=drive)
-self.assert_qmp(result, 'return', {})
-
-event = self.wait_until_completed(drive=drive)
-self.assert_qmp(event, 'data/type', 'mirror')
-
-class TestSingleDrive(ImageMirroringTestCase):
+class TestSingleDrive(iotests.QMPTestCase):
 image_len = 1 * 1024 * 1024 # MB
 
 def setUp(self):
@@ -221,17 +191,9 @@ class TestSingleDriveUnalignedLength(TestSingleDrive):
 test_small_buffer2 = None
 test_large_cluster = None
 
-class TestMirrorNoBacking(ImageMirroringTestCase):
+class TestMirrorNoBacking(iotests.QMPTestCase):
 image_len = 2 * 1024 * 1024 # MB
 
-def complete_and_wait(self, drive='drive0', wait_ready=True):
-iotests.create_image(target_backing_img, TestMirrorNoBacking.image_len)
-return ImageMirroringTestCase.complete_and_wait(self, drive, 
wait_ready)
-
-def compare_images(self, img1, img2):
-iotests.create_image(target_backing_img, TestMirrorNoBacking.image_len)
-return iotests.compare_images(img1, img2)
-
 def setUp(self):
 iotests.create_image(backing_img, TestMirrorNoBacking.image_len)
 qemu_img('create', '-f', iotests.imgfmt, '-o', 'backing_file=%s' % 
backing_img, test_img)
@@ -242,7 +204,10 @@ class TestMirrorNoBacking(ImageMirroringTestCase):
 self.vm.shutdown()
 os.remove(test_img)
 os.remove(backing_img)
-os.remove(target_backing_img)
+try:
+os.remove(target_backing_img)
+except:
+pass
 os.remove(target_img)
 
 def test_complete(self):
@@ -257,7 +222,7 @@ class TestMirrorNoBacking(ImageMirroringTestCase):
 result = self.vm.qmp('query-block')
 self.assert_qmp(result, 'return[0]/inserted/file', target_img)
 self.vm.shutdown()
-self.assertTrue(self.compare_images(test_img, target_img),
+self.assertTrue(iotests.compare_images(test_img, target_img),
 'target image does not match source after mirroring')
 
 def test_cancel(self):
@@ -272,7 +237,7 @@ class TestMirrorNoBacking(ImageMirroringTestCase):
 result = self.vm.qmp('query-block')
 self.assert_qmp(result, 'return[0]/inserted/file', test_img)
 self.vm.shutdown()
-self.assertTrue(self.compare_images(test_img, target_img),
+self.assertTrue(iotests.compare_images(test_img, target_img),
 'target image does not match source after mirroring')
 
 def test_large_cluster(self):
@@ -283,7 +248,6 @@ class TestMirrorNoBacking(ImageMirroringTestCase):
 %(TestMirrorNoBacking.image_len), target_backing_img)
 qemu_img('create', '-f', iotests.imgfmt, '-o', 
'cluster_size=%d,backing_file=%s'
 % (TestMirrorNoBacking.image_len, target_backing_img), 
target_img)
-os.remove(target_backing_img)
 
 result = self.vm.qmp('drive-mirror', device='drive0', sync='full',
  mode='existing', target=target_img)
@@ -293,10 +257,10 @@ class TestMirrorNoBacking(ImageMirroringTestCase):
 result = self.vm.qmp('query-block')
 self.assert_qmp(result, 'return[0]/inserted/file', target_img)
 self.vm.shutdown()
-

Re: [Qemu-devel] [PATCH 7/7] disas: arm: Use target_disas impl for monitor

2015-05-05 Thread Claudio Fontana
Hello Peter,

On 05.05.2015 06:45, Peter Crosthwaite wrote:
 As it is more fully featured. It has multi-endian, thumb and AArch64
 support whereas the existing monitor disas support only has vanilla
 AA32 support.
 
 E.G. Running an AA64 linux kernel the follow -d in_asm disas happens
 (taget_disas()):
 
 IN:
 0x4000:  58c0  ldr x0, pc+24 (addr 0x4018)
 0x4004:  aa1f03e1  mov x1, xzr
 
 However before this patch, disasing the same from the monitor:
 
 (qemu) xp/i 0x4000
 0x4000:  58c0  stmdapl  r0, {r6, r7}
 
 After this patch:
 (qemu) xp/i 0x4000
 0x4000:  58c0  ldr x0, pc+24 (addr 0x4018)
 
 Signed-off-by: Peter Crosthwaite crosthwaite.pe...@gmail.com
 ---
  disas.c | 48 +++-
  1 file changed, 23 insertions(+), 25 deletions(-)
 
 diff --git a/disas.c b/disas.c
 index 498b05f..e1da40d 100644
 --- a/disas.c
 +++ b/disas.c
 @@ -208,6 +208,27 @@ target_disas_set_info(int (**print_insn)(bfd_vma pc, 
 disassemble_info *info),
  s-info.mach = bfd_mach_i386_i386;
  }
  *print_insn = print_insn_i386;
 +#elif defined(TARGET_ARM)
 +if (flags  4) {
 +/* We might not be compiled with the A64 disassembler
 +* because it needs a C++ compiler; in that case we will

nit: misaligned * (add one space)

for all the rest, I didn't notice any problems.

Regarding the libvixl output, I still have a lot of unimplemented instructions..
is it possible to improve libvixl to dissect system instructions?
I guess this question is more for the libvixl project itself.

Looking at my disassembly I just tested I have:

0x400d08a0:   d50342df  unimplemented (System)
0x400d08a4:   d5033fdf  isb
0x400d08a8:   d503207f  unimplemented (System)
0x400d08ac:   d503207f  unimplemented (System)

Tested-by: Claudio Fontana claudio.font...@huawei.com
Reviewed-by: Claudio Fontana claudio.font...@huawei.com

 + * fall through to the default print_insn_od case.
 + */
 +#if defined(CONFIG_ARM_A64_DIS)
 +*print_insn = print_insn_arm_a64;
 +#endif
 +} else if (flags  1) {
 +*print_insn = print_insn_thumb1;
 +} else {
 +*print_insn = print_insn_arm;
 +}
 +if (flags  2) {
 +#ifdef TARGET_WORDS_BIGENDIAN
 +s-info.endian = BFD_ENDIAN_LITTLE;
 +#else
 +s-info.endian = BFD_ENDIAN_BIG;
 +#endif
 +}
  #elif defined(TARGET_SPARC)
  *print_insn = print_insn_sparc;
  #ifdef TARGET_SPARC64
 @@ -271,28 +292,7 @@ void target_disas(FILE *out, CPUArchState *env, 
 target_ulong code,
  s.info.buffer_vma = code;
  s.info.buffer_length = size;
  
 -#if defined(TARGET_ARM)
 -if (flags  4) {
 -/* We might not be compiled with the A64 disassembler
 - * because it needs a C++ compiler; in that case we will
 - * fall through to the default print_insn_od case.
 - */
 -#if defined(CONFIG_ARM_A64_DIS)
 -print_insn = print_insn_arm_a64;
 -#endif
 -} else if (flags  1) {
 -print_insn = print_insn_thumb1;
 -} else {
 -print_insn = print_insn_arm;
 -}
 -if (flags  2) {
 -#ifdef TARGET_WORDS_BIGENDIAN
 -s.info.endian = BFD_ENDIAN_LITTLE;
 -#else
 -s.info.endian = BFD_ENDIAN_BIG;
 -#endif
 -}
 -#elif defined(TARGET_PPC)
 +#if defined(TARGET_PPC)
  if ((flags  16)  1) {
  s.info.endian = BFD_ENDIAN_LITTLE;
  }
 @@ -475,9 +475,7 @@ void monitor_disas(Monitor *mon, CPUArchState *env,
  
  s.info.buffer_vma = pc;
  
 -#if defined(TARGET_ARM)
 -print_insn = print_insn_arm;
 -#elif defined(TARGET_ALPHA)
 +#if defined(TARGET_ALPHA)
  print_insn = print_insn_alpha;
  #elif defined(TARGET_PPC)
  if (flags  0x) {
 


-- 
Claudio Fontana
Server Virtualization Architect
Huawei Technologies Duesseldorf GmbH
Riesstraße 25 - 80992 München




Re: [Qemu-devel] [PATCH v3 3/6] spapr_pci: encode class code including Prog IF register

2015-05-05 Thread Thomas Huth
On Tue, 5 May 2015 22:55:00 +1000
David Gibson da...@gibson.dropbear.id.au wrote:

 On Tue, May 05, 2015 at 02:23:53PM +0530, Nikunj A Dadhania wrote:
  Current code missed the Prog IF register. All Class Code, Subclass,
  and Prog IF registers are needed to identify the accurate device type.
  
  For example: USB controllers use the PROG IF for denoting: USB
  FullSpeed, HighSpeed or SuperSpeed.
  
  Signed-off-by: Nikunj A Dadhania nik...@linux.vnet.ibm.com
 
 Um.. I'm guessing the CLASS_PROG register essentially includes the
 CLASS_DEVICE value?  Otherwise it looks like you're losing the
 CLASS_DEVICE value.
 
 For the benefit of those who don't remember the PCI spec from memory,
 can you explain in more detail what the situation is with the several
 class registers and how they overlap / interact.

In the PCI local bus spec, the Class Code is a 3-bytes field starting
at offset 9 in the config space. The QEMU defines seem to split this up
into PCI_CLASS_PROG (9) and PCI_CLASS_DEVICE (10), but originally they
belong together.

  ---
   hw/ppc/spapr_pci.c | 3 +--
   1 file changed, 1 insertion(+), 2 deletions(-)
  
  diff --git a/hw/ppc/spapr_pci.c b/hw/ppc/spapr_pci.c
  index ea1a092..8b02a3e 100644
  --- a/hw/ppc/spapr_pci.c
  +++ b/hw/ppc/spapr_pci.c
  @@ -899,8 +899,7 @@ static int spapr_populate_pci_child_dt(PCIDevice *dev, 
  void *fdt, int offset,
   _FDT(fdt_setprop_cell(fdt, offset, revision-id,
 pci_default_read_config(dev, PCI_REVISION_ID, 
  1)));
   _FDT(fdt_setprop_cell(fdt, offset, class-code,
  -  pci_default_read_config(dev, PCI_CLASS_DEVICE, 2)
  - 8));
  +  pci_default_read_config(dev, PCI_CLASS_PROG, 
  3)));
   if (pci_default_read_config(dev, PCI_INTERRUPT_PIN, 1)) {
   _FDT(fdt_setprop_cell(fdt, offset, interrupts,
pci_default_read_config(dev, PCI_INTERRUPT_PIN, 1)));
 

Patch looks fine to me.

Reviewed-by: Thomas Huth th...@redhat.com



[Qemu-devel] [PATCH 2/2] spice-char: notify the server when chardev is writable

2015-05-05 Thread Marc-André Lureau
The spice server is polling on write, unless
SPICE_CHAR_DEVICE_NOTIFY_WRITABLE flag is set. In this case, qemu must
call spice_server_char_device_wakeup() when the frontend is writable.

Signed-off-by: Marc-André Lureau marcandre.lur...@gmail.com
---
 spice-qemu-char.c | 11 +++
 1 file changed, 11 insertions(+)

diff --git a/spice-qemu-char.c b/spice-qemu-char.c
index a4f4e57..0f8903e 100644
--- a/spice-qemu-char.c
+++ b/spice-qemu-char.c
@@ -110,6 +110,9 @@ static SpiceCharDeviceInterface vmc_interface = {
 #if SPICE_SERVER_VERSION = 0x000c02
 .event  = vmc_event,
 #endif
+#if SPICE_SERVER_VERSION = 0x000c06
+.flags  = SPICE_CHAR_DEVICE_NOTIFY_WRITABLE,
+#endif
 };
 
 
@@ -260,6 +263,13 @@ static void print_allowed_subtypes(void)
 fprintf(stderr, \n);
 }
 
+static void spice_chr_accept_input(struct CharDriverState *chr)
+{
+SpiceCharDriver *s = chr-opaque;
+
+spice_server_char_device_wakeup(s-sin);
+}
+
 static CharDriverState *chr_open(const char *subtype,
 void (*set_fe_open)(struct CharDriverState *, int))
 
@@ -279,6 +289,7 @@ static CharDriverState *chr_open(const char *subtype,
 chr-chr_set_fe_open = set_fe_open;
 chr-explicit_be_open = true;
 chr-chr_fe_event = spice_chr_fe_event;
+chr-chr_accept_input = spice_chr_accept_input;
 
 QLIST_INSERT_HEAD(spice_chars, s, next);
 
-- 
2.1.0




Re: [Qemu-devel] [Qemu-block] [PATCH 1/6] qcow2: use one single memory block for the L2/refcount cache tables

2015-05-05 Thread Alberto Garcia
On Tue 05 May 2015 01:20:19 PM CEST, Kevin Wolf wrote:

 Though looking at the code again I see now that c-table_size isn't
 consistently used. The I/O requests still use s-cluster_size. We
 should either use it everywhere or not introduce it at all.

c-table_size is necessary in order to calculate the offset of a
particular table, because s-cluster_size is not always available
(e.g. qcow2_cache_entry_mark_dirty()). We could make it a requirement of
the API, though.

Alternatively we could have c-bs instead of c-table_size. That would
spare us from passing the BlockDriverState pointer to all qcow2_cache_
functions.

The assumption would be that the BlockDriverState pointer is the same
for the whole lifetime of the cache, but that's always guaranteed to be
like that, right?

Berto



Re: [Qemu-devel] [PATCH v1 RFC 34/34] char: introduce support for TLS encrypted TCP chardev backend

2015-05-05 Thread Paolo Bonzini


On 05/05/2015 15:49, Daniel P. Berrange wrote:
  qemu-system-x86_64: -object qcrypto-tls-cred,id=tls0,credtype=x509,:
  invalid object type: qcrypto-tls-cred
 Typo in my commit message - it should end in  '-creds' not '-cred' for
 the object type.

FWIW, I think just tls-creds is probably a better name for the -object
option.  qcrypto is more of an internal detail.

Paolo



Re: [Qemu-devel] [PATCH v3 1/6] spapr_pci: remove duplicate macros

2015-05-05 Thread Thomas Huth
On Tue,  5 May 2015 14:23:51 +0530
Nikunj A Dadhania nik...@linux.vnet.ibm.com wrote:

 Signed-off-by: Nikunj A Dadhania nik...@linux.vnet.ibm.com
 ---
  hw/ppc/spapr_pci.c | 11 ---
  1 file changed, 11 deletions(-)
 
 diff --git a/hw/ppc/spapr_pci.c b/hw/ppc/spapr_pci.c
 index 2e7590c..4df3a33 100644
 --- a/hw/ppc/spapr_pci.c
 +++ b/hw/ppc/spapr_pci.c
 @@ -1475,17 +1475,6 @@ PCIHostState *spapr_create_phb(sPAPREnvironment 
 *spapr, int index)
  return PCI_HOST_BRIDGE(dev);
  }
  
 -/* Macros to operate with address in OF binding to PCI */
 -#define b_x(x, p, l)(((x)  ((1(l))-1))  (p))
 -#define b_n(x)  b_x((x), 31, 1) /* 0 if relocatable */
 -#define b_p(x)  b_x((x), 30, 1) /* 1 if prefetchable */
 -#define b_t(x)  b_x((x), 29, 1) /* 1 if the address is aliased */
 -#define b_ss(x) b_x((x), 24, 2) /* the space code */
 -#define b_(x)   b_x((x), 16, 8) /* bus number */
 -#define b_d(x)  b_x((x), 11, 5) /* device number */
 -#define b_fff(x)b_x((x), 8, 3)  /* function number */
 -#define b_(x)   b_x((x), 0, 8)  /* register number */

Seems like the duplication is not in master yet, only in spapr-next,
and has apparently been introduced by commit 2c938a6692c01818e 
(spapr_pci: enable basic hotplug operations) ...
So an alternative would be to fix up that patch instead. David?

Anyway, the duplication should go away, so:

Reviewed-by: Thomas Huth th...@redhat.com




Re: [Qemu-devel] [PATCH 6/7] monitor: i: Add ARM specifics

2015-05-05 Thread Claudio Fontana
On 05.05.2015 06:45, Peter Crosthwaite wrote:
 Add the ARM specific disassembly flags setup, so ARM can be correctly
 disassembled from the monitor.
 
 Signed-off-by: Peter Crosthwaite crosthwaite.pe...@gmail.com
 ---
  monitor.c | 11 +++
  1 file changed, 11 insertions(+)
 
 diff --git a/monitor.c b/monitor.c
 index d831d98..9d9f1e2 100644
 --- a/monitor.c
 +++ b/monitor.c
 @@ -1217,6 +1217,17 @@ static void memory_dump(Monitor *mon, int count, int 
 format, int wsize,
  int flags;
  flags = 0;
  env = mon_get_cpu();
 +#ifdef TARGET_ARM
 +if (env-thumb) {
 +flags |= 1;
 +}
 +if (env-bswap_code) {
 +flags |= 2;
 +}
 +if (env-aarch64) {
 +flags |= 4;
 +}
 +#endif
  #ifdef TARGET_I386
  if (wsize == 2) {
  flags = 1;
 

Reviewed-by: Claudio Fontana claudio.font...@huawei.com
Tested-by: Claudio Fontana claudio.font...@huawei.com




Re: [Qemu-devel] [PATCH v1 RFC 34/34] char: introduce support for TLS encrypted TCP chardev backend

2015-05-05 Thread Kashyap Chamarthy
On Tue, May 05, 2015 at 02:49:51PM +0100, Daniel P. Berrange wrote:
 On Mon, May 04, 2015 at 10:07:15PM +0200, Kashyap Chamarthy wrote:
  On Fri, Apr 17, 2015 at 03:22:37PM +0100, Daniel P. Berrange wrote:
   This integrates support for QIOChannelTLS object in the TCP
   chardev backend. If the 'tls-cred=NAME' option is passed with
   the '-chardev tcp' argument, then it will setup the chardev
   such that the client is required to establish a TLS handshake
   when connecting. The 'acl' option will further enable the
   creation of a 'char.$ID.tlspeername' ACL which will be used
   to validate the client x509 certificate, if provided.
   
   A complete invokation to run QEMU as the server for a TLS
   encrypted serial dev might be
   
 $ qemu-system-x86_64 \
 -nodefconfig -nodefaults -device sga -display none \
 -chardev socket,id=s0,host=127.0.0.1,port=9000,tls-cred=tls0,server 
   \
 -device isa-serial,chardev=s0 \
 -object qcrypto-tls-cred,id=tls0,credtype=x509,\
   
   endpoint=server,dir=/home/berrange/security/qemutls,verify-peer=off
   
   To test with the gnutls-cli tool as the client:
   
 $ gnutls-cli --priority=NORMAL -p 9000 \
  --x509cafile=/home/berrange/security/qemutls/ca-cert.pem \
  127.0.0.1
   
   If QEMU was told to use 'anon' credential type, then use the
   priority string 'NOMAL:+ANON-DH' with gnutls-cli
   
   Alternatively, if setting up a chardev to operate as a client,
   then the TLS credentials registered must be for the client
   endpoint. First a TLS server must be setup, which can be done
   with the gnutls-serv tool
   
 $ gnutls-serv --priority=NORMAL -p 9000 \
  --x509cafile=/home/berrange/security/qemutls/ca-cert.pem \
  --x509certfile=/home/berrange/security/qemutls/server-cert.pem \
  --x509keyfile=/home/berrange/security/qemutls/server-key.pem
   
   Then QEMU can connect with
   
 $ qemu-system-x86_64 \
 -nodefconfig -nodefaults -device sga -display none \
 -chardev socket,id=s0,host=127.0.0.1,port=9000,tls-cred=tls0 \
 -device isa-serial,chardev=s0 \
 -object qcrypto-tls-cred,id=tls0,credtype=x509,\
   endpoint=client,dir=/home/berrange/security/qemutls
  
  I've applied your 'qemu-io-channel-7' branch locally, compiled QEMU and
  began to play around.
  
  $ git describe
  v2.3.0-rc3-42-g5878696
  
  When running QEMU either as server or as client, I notice this error
  (further below are the details of how I tested):
  
  [. . .]
  qemu-system-x86_64: -object qcrypto-tls-cred,id=tls0,credtype=x509,:
  invalid object type: qcrypto-tls-cred
 
 Typo in my commit message - it should end in  '-creds' not '-cred' for
 the object type.

Yep, that fixed it. I should have looked deeper -- your example in
include/crypto/tlscreds.h has the correct syntax and also includes a
QMP variant. Just to note, there seems to be three instances of this
typo in qemu-options.hx (found via `git grep qcrypto-tls-cred`).

While running QEMU as TLS server, the TLS handshake completes
successfully when connected via `gnutls-cli`.

However, when using QEMU as client to connect to an existing GnuTLS
server, I notice a segmentation fault:

  $ /home/kashyapc/build/tls-qemu/x86_64-softmmu/qemu-system-x86_64 \
  -nodefconfig -nodefaults -device sga -display none \
  -chardev socket,id=s0,host=localhost,port=9000,tls-cred=tls0 \
  -device isa-serial,chardev=s0 \
  -object 
qcrypto-tls-creds,id=tls0,credtype=x509,endpoint=client,dir=/export/security/gnutls
  Segmentation fault (core dumped)


-- 
/kashyap



[Qemu-devel] [PATCH 0/3] virtio-1 updates

2015-05-05 Thread Cornelia Huck
Hi Michael,

I've taken your virtio-1.0 branch and updated it to a more currrent
code base. There was some churn mostly in virtio-ccw, but it doesn't
hit any obvious errors. I haven't looked at every single patch,
collected r-bs etc. that might have been floating around or added my
sign-off, but the current state is at

git://github.com/cohuck/qemu virtio-1

I've also added three patches on top (which I post as a followup) that
cleanup/change some earlier patches. It might make sense to merge
them in.

Feedback welcome.

Cornelia Huck (3):
  virtio: legacy features
  virtio-ccw: BE accesses in SET_VIRTIO_REV
  virtio: rename __virtio_set_features

 hw/9pfs/virtio-9p-device.c |  5 +++--
 hw/block/virtio-blk.c  | 14 --
 hw/char/virtio-serial-bus.c| 22 +-
 hw/net/virtio-net.c| 31 +++
 hw/s390x/s390-virtio-bus.c |  4 ++--
 hw/s390x/virtio-ccw.c  | 31 +++
 hw/s390x/virtio-ccw.h  |  4 ++--
 hw/scsi/virtio-scsi.c  |  8 
 hw/virtio/virtio-balloon.c |  5 +++--
 hw/virtio/virtio-bus.c | 28 ++--
 hw/virtio/virtio-mmio.c|  4 ++--
 hw/virtio/virtio-pci.c |  4 ++--
 hw/virtio/virtio-rng.c |  7 +++
 hw/virtio/virtio.c | 18 +++---
 include/hw/virtio/virtio-bus.h |  5 ++---
 include/hw/virtio/virtio.h |  6 +++---
 16 files changed, 138 insertions(+), 58 deletions(-)

-- 
2.4.0




[Qemu-devel] [PATCH v3 3/3] qemu-sockets: Report explicit error if unlink fails

2015-05-05 Thread Cole Robinson
Consider this case:

$ ls -ld ~/root-owned/
drwx--x--x. 2 root root 4096 Apr 29 12:55 /home/crobinso/root-owned/
$ ls -l ~/root-owned/foo.sock
-rwxrwxrwx. 1 crobinso crobinso 0 Apr 29 12:55 
/home/crobinso/root-owned/foo.sock

$ qemu-system-x86_64 -vnc unix:~/root-owned/foo.sock
qemu-system-x86_64: -vnc unix:/home/crobinso/root-owned/foo.sock: Failed to 
start VNC server: Failed to bind socket to /home/crobinso/root-owned/foo.sock: 
Address already in use

...which is techinically true, but the real error is that we failed to
unlink. So report it.

This may seem pathological but it's a real possibility via libvirt.

Signed-off-by: Cole Robinson crobi...@redhat.com
---
v3:
Fix checkpatch warning

 util/qemu-sockets.c | 7 ++-
 1 file changed, 6 insertions(+), 1 deletion(-)

diff --git a/util/qemu-sockets.c b/util/qemu-sockets.c
index 87c9bc6..22c8c4c 100644
--- a/util/qemu-sockets.c
+++ b/util/qemu-sockets.c
@@ -729,7 +729,12 @@ int unix_listen_opts(QemuOpts *opts, Error **errp)
 qemu_opt_set(opts, path, un.sun_path, error_abort);
 }
 
-unlink(un.sun_path);
+if ((access(un.sun_path, F_OK) == 0) 
+unlink(un.sun_path)  0) {
+error_setg_errno(errp, errno,
+ Failed to unlink socket %s, un.sun_path);
+goto err;
+}
 if (bind(sock, (struct sockaddr*) un, sizeof(un))  0) {
 error_setg_errno(errp, errno, Failed to bind socket to %s, 
un.sun_path);
 goto err;
-- 
2.4.0




  1   2   3   4   >