Re: [Qemu-devel] [Bug 1262650] [NEW] Latest git version fails to compile in block/iscsi.o

2013-12-20 Thread Stefan Hajnoczi
On Thu, Dec 19, 2013 at 12:49:36PM -, Nigel Horne wrote:
 Public bug reported:
 
 Git version f46e720a82ccdf1a521cf459448f3f96ed895d43 (and possibly
 b91f93243bbe36dc436a64a662a9bbfb2362534a) fail to build under Linux
 using gcc 4.8.1:
 
 block/iscsi.c: In function ‘iscsi_co_readv’:
 block/iscsi.c:363:40: error: too many arguments to function 
 ‘iscsi_read10_task’
 iscsi_co_generic_cb, iTask);

Thanks for reporting this bug.  The fix will soon be merged into
qemu.git, it's currently in my block subsystem tree:

commit 219c252193862898430e5dea5efb7447877aaa85
Author: Stefan Weil s...@weilnetz.de
Date:   Tue Dec 17 08:57:10 2013 +0100

block/iscsi: Fix compilation for libiscsi 1.4.0 (API change)



Re: [Qemu-devel] [PATCH] acpi unit-test: Create temporary disk file under /tmp

2013-12-20 Thread Michael Tokarev
20.12.2013 11:05, Fam Zheng wrote:
 As other tests, the image file is created in /tmp other than current
 dir. Thus there will not be an unignored file under tests for intree
 build.
 
 Signed-off-by: Fam Zheng f...@redhat.com
 ---
  tests/acpi-test.c | 2 +-
  1 file changed, 1 insertion(+), 1 deletion(-)
 
 diff --git a/tests/acpi-test.c b/tests/acpi-test.c
 index ca83b1d6..e4f31b7 100644
 --- a/tests/acpi-test.c
 +++ b/tests/acpi-test.c
 @@ -116,7 +116,7 @@ static uint8_t boot_sector[0x200] = {
  [0x1FF] = 0xAA,
  };
  
 -static const char *disk = tests/acpi-test-disk.raw;
 +static const char *disk = /tmp/qtest-acpi-test-disk.raw;

Please, PLEASE do NOT do this.

If you want a temp dir, create one in qemu source directory
(there's no urge to be able to specify one at build/run time,
a symlink created by user will do), -- so that all this junk
will be in a single dir easy to remove.

But never, ever, use /tmp like this, not here not elsewhere
else.  When you use /tmp, first, there's $TEMPDIR, and second,
much more important, there are apis like mkstemp(3) or
tmpfile(3), or tempnam(3), -- THIS is the only proper way to
use common temporary directories.

Never, ever, create fixed (or even predictable, with getpid()
for example) files in public temporary dirs.  Never.

For this issue, I think a better solution is to actually remove
this file on make clean.  Now you're just moving an unignored
file elsewhere, which isn't good by its own.

Thanks,

/mjt



Re: [Qemu-devel] [PATCH] qemu-iotests: drop duplicate virtio-blk initialization failure

2013-12-20 Thread Stefan Hajnoczi
On Thu, Dec 19, 2013 at 04:26:44PM +0100, Stefan Hajnoczi wrote:
 Commit 75884afd5c6c42e523b08565e289dbe319e17ad9 (virtio-blk: Convert to
 QOM realize) dropped a duplicate error_report() call.  Now we no longer
 get the following error message twice:
 
   QEMU_PROG: -drive if=virtio: Device initialization failed.
 
 Update qemu-iotests 051.
 
 Signed-off-by: Stefan Hajnoczi stefa...@redhat.com
 ---
  tests/qemu-iotests/051.out | 1 -
  1 file changed, 1 deletion(-)

Applied to my block tree:
https://github.com/stefanha/qemu/commits/block

Stefan



[Qemu-devel] [PATCH] block/iscsi: return -ENOMEM if an async call fails immediately

2013-12-20 Thread Peter Lieven
if an async libiscsi call fails directly it can only be due
to an out of memory condition. All other errors are returned
through the callback.

Signed-off-by: Peter Lieven p...@kamp.de
---
 block/iscsi.c |   12 ++--
 1 file changed, 6 insertions(+), 6 deletions(-)

diff --git a/block/iscsi.c b/block/iscsi.c
index 56c0799..657a348 100644
--- a/block/iscsi.c
+++ b/block/iscsi.c
@@ -308,7 +308,7 @@ retry:
 iscsi_co_generic_cb, iTask);
 if (iTask.task == NULL) {
 g_free(buf);
-return -EIO;
+return -ENOMEM;
 }
 #if defined(LIBISCSI_FEATURE_IOVECTOR)
 scsi_task_set_iov_out(iTask.task, (struct scsi_iovec *) iov-iov,
@@ -376,7 +376,7 @@ retry:
 break;
 }
 if (iTask.task == NULL) {
-return -EIO;
+return -ENOMEM;
 }
 #if defined(LIBISCSI_FEATURE_IOVECTOR)
 scsi_task_set_iov_in(iTask.task, (struct scsi_iovec *) iov-iov, 
iov-niov);
@@ -419,7 +419,7 @@ static int coroutine_fn iscsi_co_flush(BlockDriverState *bs)
 retry:
 if (iscsi_synchronizecache10_task(iscsilun-iscsi, iscsilun-lun, 0, 0, 0,
   0, iscsi_co_generic_cb, iTask) == NULL) 
{
-return -EIO;
+return -ENOMEM;
 }
 
 while (!iTask.complete) {
@@ -669,7 +669,7 @@ retry:
   sector_qemu2lun(sector_num, iscsilun),
   8 + 16, iscsi_co_generic_cb,
   iTask) == NULL) {
-ret = -EIO;
+ret = -ENOMEM;
 goto out;
 }
 
@@ -753,7 +753,7 @@ coroutine_fn iscsi_co_discard(BlockDriverState *bs, int64_t 
sector_num,
 retry:
 if (iscsi_unmap_task(iscsilun-iscsi, iscsilun-lun, 0, 0, list, 1,
  iscsi_co_generic_cb, iTask) == NULL) {
-return -EIO;
+return -ENOMEM;
 }
 
 while (!iTask.complete) {
@@ -822,7 +822,7 @@ retry:
iscsilun-zeroblock, iscsilun-block_size,
nb_blocks, 0, !!(flags  BDRV_REQ_MAY_UNMAP),
0, 0, iscsi_co_generic_cb, iTask) == NULL) {
-return -EIO;
+return -ENOMEM;
 }
 
 while (!iTask.complete) {
-- 
1.7.9.5




Re: [Qemu-devel] [PULL 25/32] Add xxsel

2013-12-20 Thread Alexander Graf

On 20.12.2013, at 07:54, Stefan Weil s...@weilnetz.de wrote:

 Hi,
 
 this patch or one of the two following patches breaks compilation with
 --enable-debug (lots of TCGv_i32 - TCGv_i64 mismatches).

Bleks. Didn't we have buildbots for that?

I guess I will have to add a compile run with --enable-debug to my own autotest 
steps :(.

Either way, I'll write up a patch to fix this.


Alex




Re: [Qemu-devel] [PATCH] acpi unit-test: Create temporary disk file under /tmp

2013-12-20 Thread Fam Zheng

On 12/20/13 16:36, Michael Tokarev wrote:

20.12.2013 11:05, Fam Zheng wrote:

As other tests, the image file is created in /tmp other than current
dir. Thus there will not be an unignored file under tests for intree
build.

Signed-off-by: Fam Zheng f...@redhat.com
---
  tests/acpi-test.c | 2 +-
  1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/tests/acpi-test.c b/tests/acpi-test.c
index ca83b1d6..e4f31b7 100644
--- a/tests/acpi-test.c
+++ b/tests/acpi-test.c
@@ -116,7 +116,7 @@ static uint8_t boot_sector[0x200] = {
  [0x1FF] = 0xAA,
  };

-static const char *disk = tests/acpi-test-disk.raw;
+static const char *disk = /tmp/qtest-acpi-test-disk.raw;


Please, PLEASE do NOT do this.

If you want a temp dir, create one in qemu source directory
(there's no urge to be able to specify one at build/run time,
a symlink created by user will do), -- so that all this junk
will be in a single dir easy to remove.

But never, ever, use /tmp like this, not here not elsewhere
else.  When you use /tmp, first, there's $TEMPDIR, and second,
much more important, there are apis like mkstemp(3) or
tmpfile(3), or tempnam(3), -- THIS is the only proper way to
use common temporary directories.

Never, ever, create fixed (or even predictable, with getpid()
for example) files in public temporary dirs.  Never.

For this issue, I think a better solution is to actually remove
this file on make clean.  Now you're just moving an unignored
file elsewhere, which isn't good by its own.



OK, will take your suggestion. Thanks for explanation.

Fam



Re: [Qemu-devel] [PATCH v6 03/22] qdict: Add qdict_array_split()

2013-12-20 Thread Stefan Hajnoczi
On Thu, Dec 19, 2013 at 08:47:04PM +0100, Max Reitz wrote:
 This function splits a QDict consisting of entries prefixed by
 incrementally enumerated indices into a QList of QDicts.
 
 Signed-off-by: Max Reitz mre...@redhat.com
 Reviewed-by: Kevin Wolf kw...@redhat.com
 ---
  include/qapi/qmp/qdict.h |  1 +
  qobject/qdict.c  | 36 
  2 files changed, 37 insertions(+)

Please add a test case to tests/check-qdict.c.



Re: [Qemu-devel] [PATCH v6 04/22] qapi: extend qdict_flatten() for QLists

2013-12-20 Thread Stefan Hajnoczi
On Thu, Dec 19, 2013 at 08:47:05PM +0100, Max Reitz wrote:
 Reversing qdict_array_split(), qdict_flatten() should flatten QLists as
 well by interpreting them as QDicts where every entry's key is its
 index.
 
 This allows bringing QDicts with QLists from QMP commands to the same
 form as they would be given as command-line options, thereby allowing
 them to be parsed the same way.
 
 Signed-off-by: Max Reitz mre...@redhat.com
 ---
  qobject/qdict.c | 57 
 +++--
  1 file changed, 51 insertions(+), 6 deletions(-)

Please add a tests/check-qdict.c test case.

 diff --git a/qobject/qdict.c b/qobject/qdict.c
 index fca1902..7b6b08a 100644
 --- a/qobject/qdict.c
 +++ b/qobject/qdict.c
 @@ -477,7 +477,46 @@ static void qdict_destroy_obj(QObject *obj)
  g_free(qdict);
  }
  
 -static void qdict_do_flatten(QDict *qdict, QDict *target, const char *prefix)
 +static void qdict_flatten_qdict(QDict *qdict, QDict *target,
 +const char *prefix);
 +
 +static void qdict_flatten_qlist(QList *qlist, QDict *target, const char 
 *prefix)
 +{
 +QObject *value;
 +const QListEntry *entry;
 +char *new_key;
 +int i;
 +
 +/* This function is never called with prefix == NULL, i.e., it is always
 + * called from within qdict_flatten_q(list|dict)(). Therefore, it does 
 not
 + * need to remove list entries during the iteration (the whole list will 
 be
 + * deleted eventually anyway from qdict_flatten_qdict()). */
 +assert(prefix);
 +
 +entry = qlist_first(qlist);
 +
 +for (i = 0; entry; entry = qlist_next(entry), i++) {
 +value = qlist_entry_obj(entry);
 +
 +qobject_incref(value);
 +new_key = g_strdup_printf(%s.%i, prefix, i);
 +qdict_put_obj(target, new_key, value);

It seems this operation is clobbered by what follows and should be
deleted.  Is the incref also superfluous or...

 +
 +if (qobject_type(value) == QTYPE_QDICT) {
 +qdict_flatten_qdict(qobject_to_qdict(value), target, new_key);
 +} else if (qobject_type(value) == QTYPE_QLIST) {
 +qdict_flatten_qlist(qobject_to_qlist(value), target, new_key);
 +} else {
 +/* All other types are moved to the target unchanged. */
 +qobject_incref(value);

...should this one be deleted?

 +qdict_put_obj(target, new_key, value);
 +}
 +
 +g_free(new_key);
 +}



Re: [Qemu-devel] [PATCHv2] block: add native support for NFS

2013-12-20 Thread Peter Lieven

On 17.12.2013 17:47, Stefan Hajnoczi wrote:

On Tue, Dec 17, 2013 at 10:15:25AM +0100, Peter Lieven wrote:

This patch adds native support for accessing images on NFS shares without
the requirement to actually mount the entire NFS share on the host.

NFS Images can simply be specified by an url of the form:
nfs://host/export/filename

For example:
qemu-img create -f qcow2 nfs://10.0.0.1/qemu-images/test.qcow2

You need libnfs from Ronnie Sahlberg available at:
git://github.com/sahlberg/libnfs.git
for this to work.

During configure it is automatically probed for libnfs and support
is enabled on-the-fly. You can forbid or enforce libnfs support
with --disable-libnfs or --enable-libnfs respectively.

Due to NFS restrictions you might need to execute your binaries
as root, allow them to open priviledged ports (1024) or specify
insecure option on the NFS server.

Signed-off-by: Peter Lieven p...@kamp.de
---
v1-v2:
  - fixed block/Makefile.objs [Ronnie]
  - do not always register a read handler [Ronnie]
  - add support for reading beyond EOF [Fam]
  - fixed struct and paramter naming [Fam]
  - fixed overlong lines and whitespace errors [Fam]
  - return return status from libnfs whereever possible [Fam]
  - added comment why we set allocated_file_size to -ENOTSUP after write [Fam]
  - avoid segfault when parsing filname [Fam]
  - remove unused close_bh from NFSClient [Fam]
  - avoid dividing and mutliplying total_size by BDRV_SECTOR_SIZE in 
nfs_file_create [Fam]

  MAINTAINERS |5 +
  block/Makefile.objs |1 +
  block/nfs.c |  419 +++
  configure   |   38 +
  4 files changed, 463 insertions(+)
  create mode 100644 block/nfs.c

Which NFS protocol versions are supported by current libnfs?


+#include poll.h

Why is this header included?


+typedef struct nfsclient {

Please either drop the struct tag or use NFSClient.


+static void
+nfs_co_generic_cb(int status, struct nfs_context *nfs, void *data,
+  void *private_data)
+{
+NFSTask *Task = private_data;

lowercase task local variable name please.


+static int coroutine_fn nfs_co_writev(BlockDriverState *bs,
+int64_t sector_num, int nb_sectors,
+QEMUIOVector *iov)
+{
+NFSClient *client = bs-opaque;
+NFSTask task;
+char *buf = NULL;
+
+nfs_co_init_task(client, task);
+
+buf = g_malloc(nb_sectors * BDRV_SECTOR_SIZE);
+qemu_iovec_to_buf(iov, 0, buf, nb_sectors * BDRV_SECTOR_SIZE);
+
+if (nfs_pwrite_async(client-context, client-fh,
+ sector_num * BDRV_SECTOR_SIZE,
+ nb_sectors * BDRV_SECTOR_SIZE,
+ buf, nfs_co_generic_cb, task) != 0) {
+g_free(buf);
+return -EIO;

Can we get a more detailed errno here?  (e.g. ENOSPC)


+}
+
+while (!task.complete) {
+nfs_set_events(client);
+qemu_coroutine_yield();
+}
+
+g_free(buf);
+
+if (task.status != nb_sectors * BDRV_SECTOR_SIZE) {
+return task.status  0 ? task.status : -EIO;
+}
+
+bs-total_sectors = MAX(bs-total_sectors, sector_num + nb_sectors);

Why is this necessary?  block.c will update bs-total_sectors if the
file is growable.


+/* set to -ENOTSUP since bdrv_allocated_file_size is only used
+ * in qemu-img open. So we can use the cached value for allocate
+ * filesize obtained from fstat at open time */
+client-allocated_file_size = -ENOTSUP;

Can you implement this fully?  By stubbing it out like this we won't be
able to call get_allocated_file_size() at runtime in the future without
updating the nfs block driver code.  It's just an fstat call, shouldn't
be too hard to implement properly :).


It seems I have to leave it as is currently. bdrv_get_allocated_file_size
is not in a coroutine context. I get coroutine yields to no one.

Peter





[Qemu-devel] [PATCH 0/2] ppc-e500: Adding pci-pin to irq callback and some cleanup

2013-12-20 Thread Bharat Bhushan
First patch is doing some cleanup and second patch adds the PCI-PIN (INT[A-D])
to its interrupt number mapping callback. This is required to support pci device
passthrough using VFIO.

Bharat Bhushan (2):
  ppc-e500: some pci related cleanup
  ppc-e500: implement PCI INTx routing

 hw/pci-host/ppce500.c |   34 +-
 hw/ppc/e500.c |   12 +++-
 2 files changed, 32 insertions(+), 14 deletions(-)





[Qemu-devel] [PATCH 1/2] ppc-e500: some pci related cleanup

2013-12-20 Thread Bharat Bhushan
 - Use PCI_NUM_PINS rather than hardcoding
 - use pin wherever possible

Signed-off-by: Bharat Bhushan bharat.bhus...@freescale.com
---
 hw/pci-host/ppce500.c |   16 
 hw/ppc/e500.c |   12 +++-
 2 files changed, 15 insertions(+), 13 deletions(-)

diff --git a/hw/pci-host/ppce500.c b/hw/pci-host/ppce500.c
index f00793d..71e5ca9 100644
--- a/hw/pci-host/ppce500.c
+++ b/hw/pci-host/ppce500.c
@@ -87,7 +87,7 @@ struct PPCE500PCIState {
 struct pci_outbound pob[PPCE500_PCI_NR_POBS];
 struct pci_inbound pib[PPCE500_PCI_NR_PIBS];
 uint32_t gasket_time;
-qemu_irq irq[4];
+qemu_irq irq[PCI_NUM_PINS];
 uint32_t first_slot;
 /* mmio maps */
 MemoryRegion container;
@@ -252,26 +252,26 @@ static const MemoryRegionOps e500_pci_reg_ops = {
 .endianness = DEVICE_BIG_ENDIAN,
 };
 
-static int mpc85xx_pci_map_irq(PCIDevice *pci_dev, int irq_num)
+static int mpc85xx_pci_map_irq(PCIDevice *pci_dev, int pin)
 {
 int devno = pci_dev-devfn  3;
 int ret;
 
-ret = ppce500_pci_map_irq_slot(devno, irq_num);
+ret = ppce500_pci_map_irq_slot(devno, pin);
 
 pci_debug(%s: devfn %x irq %d - %d  devno:%x\n, __func__,
-   pci_dev-devfn, irq_num, ret, devno);
+   pci_dev-devfn, pin, ret, devno);
 
 return ret;
 }
 
-static void mpc85xx_pci_set_irq(void *opaque, int irq_num, int level)
+static void mpc85xx_pci_set_irq(void *opaque, int pin, int level)
 {
-qemu_irq *pic = opaque;
+qemu_irq *irq = opaque;
 
-pci_debug(%s: PCI irq %d, level:%d\n, __func__, irq_num, level);
+pci_debug(%s: PCI irq %d, level:%d\n, __func__, pin , level);
 
-qemu_set_irq(pic[irq_num], level);
+qemu_set_irq(irq[pin], level);
 }
 
 static const VMStateDescription vmstate_pci_outbound = {
diff --git a/hw/ppc/e500.c b/hw/ppc/e500.c
index b37ce9d..2a9f8ee 100644
--- a/hw/ppc/e500.c
+++ b/hw/ppc/e500.c
@@ -611,7 +611,9 @@ void ppce500_init(QEMUMachineInitArgs *args, PPCE500Params 
*params)
 target_long initrd_size = 0;
 target_ulong cur_base = 0;
 int i;
-unsigned int pci_irq_nrs[4] = {1, 2, 3, 4};
+/* irq num for pin INTA, INTB, INTC and INTD is 1, 2, 3 and
+ * 4 respectively */
+unsigned int pci_irq_nrs[PCI_NUM_PINS] = {1, 2, 3, 4};
 qemu_irq **irqs, *mpic;
 DeviceState *dev;
 CPUPPCState *firstenv = NULL;
@@ -713,10 +715,10 @@ void ppce500_init(QEMUMachineInitArgs *args, 
PPCE500Params *params)
 qdev_prop_set_uint32(dev, first_slot, params-pci_first_slot);
 qdev_init_nofail(dev);
 s = SYS_BUS_DEVICE(dev);
-sysbus_connect_irq(s, 0, mpic[pci_irq_nrs[0]]);
-sysbus_connect_irq(s, 1, mpic[pci_irq_nrs[1]]);
-sysbus_connect_irq(s, 2, mpic[pci_irq_nrs[2]]);
-sysbus_connect_irq(s, 3, mpic[pci_irq_nrs[3]]);
+for (i = 0; i  PCI_NUM_PINS; i++) {
+sysbus_connect_irq(s, i, mpic[pci_irq_nrs[i]]);
+}
+
 memory_region_add_subregion(ccsr_addr_space, MPC8544_PCI_REGS_OFFSET,
 sysbus_mmio_get_region(s, 0));
 
-- 
1.7.0.4





[Qemu-devel] [Bug 1042388] Re: qemu: Unsupported syscall: 257 (timer_create)

2013-12-20 Thread Erik de Castro Lopo
If someone wants to fix what's currently in Ubtuntu they should make a
package which includes those two patches.

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

Title:
  qemu: Unsupported syscall: 257 (timer_create)

Status in QEMU:
  Confirmed

Bug description:
  Running qemu-arm-static for git HEAD. When I try to install ghc from
  debian into my arm chroot I get:

  Setting up ghc (7.4.1-4) ...
  qemu: Unsupported syscall: 257
  ghc: timer_create: Function not implemented
  qemu: Unsupported syscall: 257
  ghc-pkg: timer_create: Function not implemented
  dpkg: error processing ghc (--configure):
   subprocess installed post-installation script returned error exit status 1
  Errors were encountered while processing:
   ghc
  E: Sub-process /usr/bin/dpkg returned an error code (1)

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



[Qemu-devel] [Bug 1042388] Re: qemu: Unsupported syscall: 257 (timer_create)

2013-12-20 Thread Erik de Castro Lopo
Its currently in git HEAD. It will be in the next full release which I
think is 2.0.

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

Title:
  qemu: Unsupported syscall: 257 (timer_create)

Status in QEMU:
  Confirmed

Bug description:
  Running qemu-arm-static for git HEAD. When I try to install ghc from
  debian into my arm chroot I get:

  Setting up ghc (7.4.1-4) ...
  qemu: Unsupported syscall: 257
  ghc: timer_create: Function not implemented
  qemu: Unsupported syscall: 257
  ghc-pkg: timer_create: Function not implemented
  dpkg: error processing ghc (--configure):
   subprocess installed post-installation script returned error exit status 1
  Errors were encountered while processing:
   ghc
  E: Sub-process /usr/bin/dpkg returned an error code (1)

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



Re: [Qemu-devel] [PATCH 11/21] target-arm: Update generic cpreg code for AArch64

2013-12-20 Thread Peter Maydell
On 20 December 2013 04:24, Peter Crosthwaite
peter.crosthwa...@xilinx.com wrote:
 On Thu, Dec 19, 2013 at 7:11 PM, Peter Maydell peter.mayd...@linaro.org 
 wrote:
 Almost all the shared registers appear as 32 bit on the AArch32
 side and 64 bits on the AArch64 side.

 Really? Reading v8, there are many 32 bit regs with these op0 AArch64
 encodings, for example the documentation of MIDR_EL1:

 Configurations
 MIDR_EL1 is architecturally mapped to AArch32 register MIDR.
 MIDR_EL1 is architecturally mapped to external register MIDR_EL1.
 Attributes
 MIDR_EL1 is a 32-bit register

32 bit register in the AArch64 documentation is a shorthand for
64 bit register with the top 32 bits (currently) RES0. There are
no 32 bit system registers in AArch64 by definition, because there's
no way to load only 32 bits in or out of them: MSR/MRS are always
64 bit transfers.

 CTR, REVIDR, ID_PFRx, CSSELR, CLIDR, DACR32 to name a few more that
 are similarly documented and by no means an exhaustive list (I just
 randomly picked those from the list).

These too are all 64 bits for AArch64.

 This means the required
 fieldoffset value is different [or potentially so for bigendian hosts].
 So you'd only be able to share registers which were genuinely
 64 bit on both sides, which are very rare. So it didn't seem worth
 trying to accommodate it.


 The support 32 vs 64 encoding scheme seems quite othogonal to the
 backing sotre bit width.

Well, we could add 4 to the fieldoffset for the copy of the reginfo
that we're using for the 32 bit side if TARGET_WORDS_BIGENDIAN,
I guess.

I'll have a think about this, because there are some wrinkles relating
to reset that might be usefully solved this way.

-- PMM



[Qemu-devel] [PATCH] PPC: Fix compilation with TCG debug

2013-12-20 Thread Alexander Graf
The recent VSX patches broken compilation of QEMU when configurated
with --enable-debug, as it was treating target long TCG variables
as i64 which is not true for 32bit targets.

This patch fixes all the places that the compiler has found to use
the correct variable type and if necessary manually cast.

Reported-by: Stefan Weil s...@weilnetz.de
Signed-off-by: Alexander Graf ag...@suse.de
---
 target-ppc/translate.c | 143 -
 1 file changed, 81 insertions(+), 62 deletions(-)

diff --git a/target-ppc/translate.c b/target-ppc/translate.c
index ea58dc9..c5c1108 100644
--- a/target-ppc/translate.c
+++ b/target-ppc/translate.c
@@ -2567,6 +2567,14 @@ static inline void gen_qemu_ld32u(DisasContext *ctx, 
TCGv arg1, TCGv arg2)
 }
 }
 
+static void gen_qemu_ld32u_i64(DisasContext *ctx, TCGv_i64 val, TCGv addr)
+{
+TCGv tmp = tcg_temp_new();
+gen_qemu_ld32u(ctx, tmp, addr);
+tcg_gen_extu_tl_i64(val, tmp);
+tcg_temp_free(tmp);
+}
+
 static inline void gen_qemu_ld32s(DisasContext *ctx, TCGv arg1, TCGv arg2)
 {
 if (unlikely(ctx-le_mode)) {
@@ -2616,6 +2624,14 @@ static inline void gen_qemu_st32(DisasContext *ctx, TCGv 
arg1, TCGv arg2)
 }
 }
 
+static void gen_qemu_st32_i64(DisasContext *ctx, TCGv_i64 val, TCGv addr)
+{
+TCGv tmp = tcg_temp_new();
+tcg_gen_trunc_i64_tl(tmp, val);
+gen_qemu_st32(ctx, tmp, addr);
+tcg_temp_free(tmp);
+}
+
 static inline void gen_qemu_st64(DisasContext *ctx, TCGv_i64 arg1, TCGv arg2)
 {
 if (unlikely(ctx-le_mode)) {
@@ -7048,13 +7064,14 @@ static void gen_lxvdsx(DisasContext *ctx)
 EA = tcg_temp_new();
 gen_addr_reg_index(ctx, EA);
 gen_qemu_ld64(ctx, cpu_vsrh(xT(ctx-opcode)), EA);
-tcg_gen_mov_tl(cpu_vsrl(xT(ctx-opcode)), cpu_vsrh(xT(ctx-opcode)));
+tcg_gen_mov_i64(cpu_vsrl(xT(ctx-opcode)), cpu_vsrh(xT(ctx-opcode)));
 tcg_temp_free(EA);
 }
 
 static void gen_lxvw4x(DisasContext *ctx)
 {
-TCGv EA, tmp;
+TCGv EA;
+TCGv_i64 tmp;
 TCGv_i64 xth = cpu_vsrh(xT(ctx-opcode));
 TCGv_i64 xtl = cpu_vsrl(xT(ctx-opcode));
 if (unlikely(!ctx-vsx_enabled)) {
@@ -7063,21 +7080,22 @@ static void gen_lxvw4x(DisasContext *ctx)
 }
 gen_set_access_type(ctx, ACCESS_INT);
 EA = tcg_temp_new();
-tmp = tcg_temp_new();
+tmp = tcg_temp_new_i64();
+
 gen_addr_reg_index(ctx, EA);
-gen_qemu_ld32u(ctx, tmp, EA);
+gen_qemu_ld32u_i64(ctx, tmp, EA);
 tcg_gen_addi_tl(EA, EA, 4);
-gen_qemu_ld32u(ctx, xth, EA);
+gen_qemu_ld32u_i64(ctx, xth, EA);
 tcg_gen_deposit_i64(xth, xth, tmp, 32, 32);
 
 tcg_gen_addi_tl(EA, EA, 4);
-gen_qemu_ld32u(ctx, tmp, EA);
+gen_qemu_ld32u_i64(ctx, tmp, EA);
 tcg_gen_addi_tl(EA, EA, 4);
-gen_qemu_ld32u(ctx, xtl, EA);
+gen_qemu_ld32u_i64(ctx, xtl, EA);
 tcg_gen_deposit_i64(xtl, xtl, tmp, 32, 32);
 
 tcg_temp_free(EA);
-tcg_temp_free(tmp);
+tcg_temp_free_i64(tmp);
 }
 
 static void gen_stxsdx(DisasContext *ctx)
@@ -7112,7 +7130,8 @@ static void gen_stxvd2x(DisasContext *ctx)
 
 static void gen_stxvw4x(DisasContext *ctx)
 {
-TCGv EA, tmp;
+TCGv_i64 tmp;
+TCGv EA;
 if (unlikely(!ctx-vsx_enabled)) {
 gen_exception(ctx, POWERPC_EXCP_VSXU);
 return;
@@ -7120,21 +7139,21 @@ static void gen_stxvw4x(DisasContext *ctx)
 gen_set_access_type(ctx, ACCESS_INT);
 EA = tcg_temp_new();
 gen_addr_reg_index(ctx, EA);
-tmp = tcg_temp_new();
+tmp = tcg_temp_new_i64();
 
 tcg_gen_shri_i64(tmp, cpu_vsrh(xS(ctx-opcode)), 32);
-gen_qemu_st32(ctx, tmp, EA);
+gen_qemu_st32_i64(ctx, tmp, EA);
 tcg_gen_addi_tl(EA, EA, 4);
-gen_qemu_st32(ctx, cpu_vsrh(xS(ctx-opcode)), EA);
+gen_qemu_st32_i64(ctx, cpu_vsrh(xS(ctx-opcode)), EA);
 
 tcg_gen_shri_i64(tmp, cpu_vsrl(xS(ctx-opcode)), 32);
 tcg_gen_addi_tl(EA, EA, 4);
-gen_qemu_st32(ctx, tmp, EA);
+gen_qemu_st32_i64(ctx, tmp, EA);
 tcg_gen_addi_tl(EA, EA, 4);
-gen_qemu_st32(ctx, cpu_vsrl(xS(ctx-opcode)), EA);
+gen_qemu_st32_i64(ctx, cpu_vsrl(xS(ctx-opcode)), EA);
 
 tcg_temp_free(EA);
-tcg_temp_free(tmp);
+tcg_temp_free_i64(tmp);
 }
 
 static void gen_xxpermdi(DisasContext *ctx)
@@ -7171,8 +7190,8 @@ static void glue(gen_, name)(DisasContext * ctx)  
\
 gen_exception(ctx, POWERPC_EXCP_VSXU);\
 return;   \
 } \
-xb = tcg_temp_new();  \
-sgm = tcg_temp_new(); \
+xb = tcg_temp_new_i64();  \
+sgm = tcg_temp_new_i64(); \
 tcg_gen_mov_i64(xb, cpu_vsrh(xB(ctx-opcode)));   \
 tcg_gen_movi_i64(sgm, sgn_mask);  \
 switch (op) { \

[Qemu-devel] [PATCH 2/2] ppc-e500: implement PCI INTx routing

2013-12-20 Thread Bharat Bhushan
This patch adds pci pin to irq_num routing callback.
This callback is called from pci_device_route_intx_to_irq to find which pci 
device
maps to which irq. This is used for pci-device passthrough using vfio.

Also without this patch we gets below warning


  PCI: Bug - unimplemented PCI INTx routing (e500-pcihost)
  qemu-system-ppc64: PCI: Bug - unimplemented PCI INTx routing (e500-pcihost)

and Legacy interrupt does not work with pci device passthrough.

Signed-off-by: Bharat Bhushan bharat.bhus...@freescale.com
Acked-by: Michael S. Tsirkin m...@redhat.com
---
 hw/pci-host/ppce500.c |   20 ++--
 1 files changed, 18 insertions(+), 2 deletions(-)

diff --git a/hw/pci-host/ppce500.c b/hw/pci-host/ppce500.c
index 71e5ca9..ffea782 100644
--- a/hw/pci-host/ppce500.c
+++ b/hw/pci-host/ppce500.c
@@ -88,6 +88,7 @@ struct PPCE500PCIState {
 struct pci_inbound pib[PPCE500_PCI_NR_PIBS];
 uint32_t gasket_time;
 qemu_irq irq[PCI_NUM_PINS];
+uint32_t irq_num[PCI_NUM_PINS];
 uint32_t first_slot;
 /* mmio maps */
 MemoryRegion container;
@@ -267,13 +268,26 @@ static int mpc85xx_pci_map_irq(PCIDevice *pci_dev, int 
pin)
 
 static void mpc85xx_pci_set_irq(void *opaque, int pin, int level)
 {
-qemu_irq *irq = opaque;
+PPCE500PCIState *s = opaque;
+qemu_irq *pic = s-irq;
 
 pci_debug(%s: PCI irq %d, level:%d\n, __func__, pin , level);
 
 qemu_set_irq(irq[pin], level);
 }
 
+static PCIINTxRoute e500_route_intx_pin_to_irq(void *opaque, int pin)
+{
+PCIINTxRoute route;
+PPCE500PCIState *s = opaque;
+
+route.mode = PCI_INTX_ENABLED;
+route.irq = s-irq_num[pin];
+
+pci_debug(%s: PCI irq-pin = %d, irq_num= %d\n, __func__, pin, route.irq);
+return route;
+}
+
 static const VMStateDescription vmstate_pci_outbound = {
 .name = pci_outbound,
 .version_id = 0,
@@ -350,12 +364,13 @@ static int e500_pcihost_initfn(SysBusDevice *dev)
 
 for (i = 0; i  ARRAY_SIZE(s-irq); i++) {
 sysbus_init_irq(dev, s-irq[i]);
+s-irq_num[i] = i + 1;
 }
 
 memory_region_init(s-pio, OBJECT(s), pci-pio, PCIE500_PCI_IOLEN);
 
 b = pci_register_bus(DEVICE(dev), NULL, mpc85xx_pci_set_irq,
- mpc85xx_pci_map_irq, s-irq, address_space_mem,
+ mpc85xx_pci_map_irq, s, address_space_mem,
  s-pio, PCI_DEVFN(s-first_slot, 0), 4, 
TYPE_PCI_BUS);
 h-bus = b;
 
@@ -373,6 +388,7 @@ static int e500_pcihost_initfn(SysBusDevice *dev)
 memory_region_add_subregion(s-container, PCIE500_REG_BASE, s-iomem);
 sysbus_init_mmio(dev, s-container);
 sysbus_init_mmio(dev, s-pio);
+pci_bus_set_route_irq_fn(b, e500_route_intx_pin_to_irq);
 
 return 0;
 }
-- 
1.7.0.4





Re: [Qemu-devel] [PATCH] target-arm: use c13_context field for CONTEXTIDR

2013-12-20 Thread Peter Maydell
On 20 December 2013 06:33, Sergey Fedorov s.fedo...@samsung.com wrote:
 Use c13_context field instead of c13_fcse for CONTEXTIDR register
 definition.

 Signed-off-by: Sergey Fedorov s.fedo...@samsung.com
 Reviewed-by: Peter Crosthwaite peter.crosthwa...@xilinx.com
 ---
  target-arm/helper.c |2 +-
  1 file changed, 1 insertion(+), 1 deletion(-)

 diff --git a/target-arm/helper.c b/target-arm/helper.c
 index 6ebd7dc..d52da0a 100644
 --- a/target-arm/helper.c
 +++ b/target-arm/helper.c
 @@ -397,7 +397,7 @@ static const ARMCPRegInfo cp_reginfo[] = {
.access = PL1_RW, .fieldoffset = offsetof(CPUARMState, cp15.c13_fcse),
.resetvalue = 0, .writefn = fcse_write, .raw_writefn = raw_write, },
  { .name = CONTEXTIDR, .cp = 15, .crn = 13, .crm = 0, .opc1 = 0, .opc2 
 = 1,
 -  .access = PL1_RW, .fieldoffset = offsetof(CPUARMState, cp15.c13_fcse),
 +  .access = PL1_RW, .fieldoffset = offsetof(CPUARMState, 
 cp15.c13_context),
.resetvalue = 0, .writefn = contextidr_write, .raw_writefn = 
 raw_write, },
  /* ??? This covers not just the impdef TLB lockdown registers but also
   * some v7VMSA registers relating to TEX remap, so it is overly broad.

Wow, I wonder how things worked with that broken. Obvious cut-n-paste
damage from back when we converted the cp regs.

Reviewed-by: Peter Maydell peter.mayd...@linaro.org

thanks
-- PMM



Re: [Qemu-devel] [RFC PATCH v3 1/6] block: introduce prealloc_mode

2013-12-20 Thread Stefan Hajnoczi
On Thu, Dec 19, 2013 at 10:27:36AM +0800, Hu Tao wrote:
 diff --git a/include/block/block.h b/include/block/block.h
 index 36efaea..3732f25 100644
 --- a/include/block/block.h
 +++ b/include/block/block.h
 @@ -527,4 +527,10 @@ int bdrv_debug_remove_breakpoint(BlockDriverState *bs, 
 const char *tag);
  int bdrv_debug_resume(BlockDriverState *bs, const char *tag);
  bool bdrv_debug_is_suspended(BlockDriverState *bs, const char *tag);
  
 +enum prealloc_mode {

Please follow modern QEMU coding style and use CamelCase: PreallocMode

It would be nice to use PreallocMode instead int for variables.



Re: [Qemu-devel] [RFC PATCH v3 2/6] block: add BlockDriver.bdrv_preallocate.

2013-12-20 Thread Stefan Hajnoczi
On Thu, Dec 19, 2013 at 10:27:37AM +0800, Hu Tao wrote:
 diff --git a/block.c b/block.c
 index 64e7d22..b901587 100644
 --- a/block.c
 +++ b/block.c
 @@ -3216,6 +3216,19 @@ bool bdrv_can_write_zeroes_with_unmap(BlockDriverState 
 *bs)
  return false;
  }
  
 +int bdrv_preallocate(BlockDriverState *bs, int64_t offset, int64_t length)
 +{
 +if (bs-backing_hd) {
 +return -ENOTSUP;
 +}

Depending on the image file format it may be possible to preallocate
metadata while using a backing file.  Why prevent this?



Re: [Qemu-devel] [RFC PATCH v3 3/6] block/raw-posix: implement bdrv_preallocate

2013-12-20 Thread Stefan Hajnoczi
On Thu, Dec 19, 2013 at 10:27:38AM +0800, Hu Tao wrote:
 +static int raw_preallocate2(int fd, int64_t offset, int64_t length)
 +{
 +int ret = -1;
 +
 +ret = fallocate(fd, 0, offset, length);
 +
 +/* fallback to posix_fallocate() if fallocate() is not supported */
 +if (ret  0  (errno == ENOSYS || errno == EOPNOTSUPP)) {
 +ret = posix_fallocate(fd, offset, length);
 +}
 +
 +return ret;

Return value semantics differ between the two functions:
 * fallocate - return 0 or -1 with errno set
 * posix_fallocate - return 0 or error number (without using errno!)

Please make it consistent.  Usually in QEMU we return 0 on success and
-errno on failure.



Re: [Qemu-devel] [PATCH v2] vmdk: Allow vmdk_create to work with protocol

2013-12-20 Thread Peter Lieven

On 20.12.2013 02:48, Fam Zheng wrote:

This improves vmdk_create to use bdrv_* functions to replace qemu_open
and other fd functions. The error handling are improved as well. One
difference is that bdrv_pwrite will round up buffer to sectors, so for
description file, an extra bdrv_truncate is used in the end to drop
inding zeros.

Notes:

  - A bonus bug fix is correct endian is used in initializing GD entries.

  - ROUND_UP and DIV_ROUND_UP are used where possible.

I tested that new code produces exactly the same file as previously.

Signed-off-by: Fam Zheng f...@redhat.com

---
v2: Address Stefan's comments:

Signed-off-by: Fam Zheng f...@redhat.com
---
  block/vmdk.c | 164 ++-
  1 file changed, 95 insertions(+), 69 deletions(-)

diff --git a/block/vmdk.c b/block/vmdk.c
index 0734bc2..ef078f6 100644
--- a/block/vmdk.c
+++ b/block/vmdk.c
@@ -1447,23 +1447,33 @@ static int coroutine_fn 
vmdk_co_write_zeroes(BlockDriverState *bs,
  }
  
  static int vmdk_create_extent(const char *filename, int64_t filesize,

-  bool flat, bool compress, bool zeroed_grain)
+  bool flat, bool compress, bool zeroed_grain,
+  Error **errp)
  {
  int ret, i;
-int fd = 0;
+BlockDriverState *bs = NULL;
  VMDK4Header header;
-uint32_t tmp, magic, grains, gd_size, gt_size, gt_count;
+Error *local_err;
+uint32_t tmp, magic, grains, gd_sectors, gt_size, gt_count;
+uint32_t *gd_buf = NULL;
+int gd_buf_size;
  
-fd = qemu_open(filename,

-   O_WRONLY | O_CREAT | O_TRUNC | O_BINARY | O_LARGEFILE,
-   0644);
-if (fd  0) {
-return -errno;
+ret = bdrv_create_file(filename, NULL, local_err);
+if (ret  0) {
+error_propagate(errp, local_err);
+goto exit;
  }
+
+ret = bdrv_file_open(bs, filename, NULL, BDRV_O_RDWR, local_err);
+if (ret  0) {
+error_propagate(errp, local_err);
+goto exit;
+}
+
  if (flat) {
-ret = ftruncate(fd, filesize);
+ret = bdrv_truncate(bs, filesize);
  if (ret  0) {
-ret = -errno;
+error_setg(errp, Could not truncate file);
  }
  goto exit;
  }
@@ -1474,24 +1484,23 @@ static int vmdk_create_extent(const char *filename, 
int64_t filesize,
 | (compress ? VMDK4_FLAG_COMPRESS | VMDK4_FLAG_MARKER : 0)
 | (zeroed_grain ? VMDK4_FLAG_ZERO_GRAIN : 0);
  header.compressAlgorithm = compress ? VMDK4_COMPRESSION_DEFLATE : 0;
-header.capacity = filesize / 512;
+header.capacity = filesize / BDRV_SECTOR_SIZE;
  header.granularity = 128;
-header.num_gtes_per_gt = 512;
+header.num_gtes_per_gt = BDRV_SECTOR_SIZE;
  
-grains = (filesize / 512 + header.granularity - 1) / header.granularity;

-gt_size = ((header.num_gtes_per_gt * sizeof(uint32_t)) + 511)  9;
-gt_count =
-(grains + header.num_gtes_per_gt - 1) / header.num_gtes_per_gt;
-gd_size = (gt_count * sizeof(uint32_t) + 511)  9;
+grains = DIV_ROUND_UP(filesize / BDRV_SECTOR_SIZE, header.granularity);
+gt_size = DIV_ROUND_UP(header.num_gtes_per_gt * sizeof(uint32_t),
+   BDRV_SECTOR_SIZE);
+gt_count = DIV_ROUND_UP(grains, header.num_gtes_per_gt);
+gd_sectors = DIV_ROUND_UP(gt_count * sizeof(uint32_t), BDRV_SECTOR_SIZE);
  
  header.desc_offset = 1;

  header.desc_size = 20;
  header.rgd_offset = header.desc_offset + header.desc_size;
-header.gd_offset = header.rgd_offset + gd_size + (gt_size * gt_count);
+header.gd_offset = header.rgd_offset + gd_sectors + (gt_size * gt_count);
  header.grain_offset =
-   ((header.gd_offset + gd_size + (gt_size * gt_count) +
- header.granularity - 1) / header.granularity) *
-header.granularity;
+ROUND_UP(header.gd_offset + gd_sectors + (gt_size * gt_count),
+ header.granularity);
  /* swap endianness for all header fields */
  header.version = cpu_to_le32(header.version);
  header.flags = cpu_to_le32(header.flags);
@@ -1511,48 +1520,55 @@ static int vmdk_create_extent(const char *filename, 
int64_t filesize,
  header.check_bytes[3] = 0xa;
  
  /* write all the data */

-ret = qemu_write_full(fd, magic, sizeof(magic));
-if (ret != sizeof(magic)) {
-ret = -errno;
+ret = bdrv_pwrite(bs, 0, magic, sizeof(magic));
+if (ret  0) {
+error_set(errp, QERR_IO_ERROR);
  goto exit;
  }
-ret = qemu_write_full(fd, header, sizeof(header));
-if (ret != sizeof(header)) {
-ret = -errno;
+ret = bdrv_pwrite(bs, sizeof(magic), header, sizeof(header));
+if (ret  0) {
+error_set(errp, QERR_IO_ERROR);
  goto exit;
  }
  
-ret = ftruncate(fd, le64_to_cpu(header.grain_offset)  9);

+ret = bdrv_truncate(bs, 

Re: [Qemu-devel] [RFC PATCH v3 5/6] qcow2: implement bdrv_preallocate

2013-12-20 Thread Stefan Hajnoczi
On Thu, Dec 19, 2013 at 10:27:40AM +0800, Hu Tao wrote:
 Signed-off-by: Hu Tao hu...@cn.fujitsu.com
 ---
  block/qcow2.c | 7 +++
  1 file changed, 7 insertions(+)
 
 diff --git a/block/qcow2.c b/block/qcow2.c
 index 32cb39f..487a595 100644
 --- a/block/qcow2.c
 +++ b/block/qcow2.c
 @@ -2188,6 +2188,12 @@ static int qcow2_amend_options(BlockDriverState *bs,
  return 0;
  }
  
 +static int qcow2_preallocate(BlockDriverState *bs, int64_t offset,
 + int64_t length)
 +{
 +return bdrv_preallocate(bs-file, offset, length);
 +}

What about qcow2-level preallocation (metadata)?

I'm not sure what the meaning of offset and length are here - are they
supposed to be virtual disk LBAs.  They are being passed through to
bs-file so they actually become physical file offsets.



Re: [Qemu-devel] [RFC PATCH v3 6/6] qcow2: Add full image preallocation option

2013-12-20 Thread Stefan Hajnoczi
On Thu, Dec 19, 2013 at 10:27:41AM +0800, Hu Tao wrote:
 -static int preallocate(BlockDriverState *bs)
 +static int preallocate(BlockDriverState *bs, enum prealloc_mode mode)
  {
  uint64_t nb_sectors;
  uint64_t offset;
 @@ -1395,9 +1395,19 @@ static int preallocate(BlockDriverState *bs)
  int ret;
  QCowL2Meta *meta;
  
 +assert(mode != PREALLOC_OFF);
 +
  nb_sectors = bdrv_getlength(bs)  9;
  offset = 0;
  
 +if (mode == PREALLOC_FULL) {
 +ret = bdrv_preallocate(bs-file, 0, bdrv_getlength(bs));

This doesn't make sense since it fails to factor in qcow2 metadata and
the file layout.



Re: [Qemu-devel] [RFC PATCH v3 0/6] qemu-img: add preallocation=full

2013-12-20 Thread Stefan Hajnoczi
On Thu, Dec 19, 2013 at 10:27:35AM +0800, Hu Tao wrote:
 This series implements full image preallocation to create a non-sparse image
 file at creation time, both for raw and qcow2 format. The purpose is to avoid
 performance deterioration of the guest cause by sparse image.

I'm not sure the new bdrv_preallocate() interface is necessary.  Can
qcow2_create() simply pass a preallocate=full option to
bdrv_create_file()?

It's simpler if we avoid bdrv_preallocate(), just keep it a
.bdrv_create() option.  That way we also avoid the question of how
exactly preallocate functions on an image file that already has blocks
allocated.

So what I imagine is:
1. Add preallocation=full support to raw-posix.c
2. Add preallocation=full support to qcow2.c, calculate image file size
including metadata for bdrv_create_file().

CCing Eric Blake so libvirt can consider how full preallocation
interacts with their safezero() preallocation.  If QEMU handles
preallocation can we skip safezero()?  Is there a concern about full
preallocation in QEMU taking a long time without progress report?

Stefan



Re: [Qemu-devel] [PATCH 2/2] ppc-e500: implement PCI INTx routing

2013-12-20 Thread Alexander Graf

On 20.12.2013, at 10:42, Bharat Bhushan r65...@freescale.com wrote:

 This patch adds pci pin to irq_num routing callback.
 This callback is called from pci_device_route_intx_to_irq to find which pci 
 device
 maps to which irq. This is used for pci-device passthrough using vfio.
 
 Also without this patch we gets below warning
 
 
  PCI: Bug - unimplemented PCI INTx routing (e500-pcihost)
  qemu-system-ppc64: PCI: Bug - unimplemented PCI INTx routing (e500-pcihost)
 
 and Legacy interrupt does not work with pci device passthrough.
 
 Signed-off-by: Bharat Bhushan bharat.bhus...@freescale.com
 Acked-by: Michael S. Tsirkin m...@redhat.com
 ---
 hw/pci-host/ppce500.c |   20 ++--
 1 files changed, 18 insertions(+), 2 deletions(-)
 
 diff --git a/hw/pci-host/ppce500.c b/hw/pci-host/ppce500.c
 index 71e5ca9..ffea782 100644
 --- a/hw/pci-host/ppce500.c
 +++ b/hw/pci-host/ppce500.c
 @@ -88,6 +88,7 @@ struct PPCE500PCIState {
 struct pci_inbound pib[PPCE500_PCI_NR_PIBS];
 uint32_t gasket_time;
 qemu_irq irq[PCI_NUM_PINS];
 +uint32_t irq_num[PCI_NUM_PINS];
 uint32_t first_slot;
 /* mmio maps */
 MemoryRegion container;
 @@ -267,13 +268,26 @@ static int mpc85xx_pci_map_irq(PCIDevice *pci_dev, int 
 pin)
 
 static void mpc85xx_pci_set_irq(void *opaque, int pin, int level)
 {
 -qemu_irq *irq = opaque;
 +PPCE500PCIState *s = opaque;
 +qemu_irq *pic = s-irq;
 
 pci_debug(%s: PCI irq %d, level:%d\n, __func__, pin , level);
 
 qemu_set_irq(irq[pin], level);
 }
 
 +static PCIINTxRoute e500_route_intx_pin_to_irq(void *opaque, int pin)
 +{
 +PCIINTxRoute route;
 +PPCE500PCIState *s = opaque;
 +
 +route.mode = PCI_INTX_ENABLED;
 +route.irq = s-irq_num[pin];
 +
 +pci_debug(%s: PCI irq-pin = %d, irq_num= %d\n, __func__, pin, 
 route.irq);
 +return route;
 +}
 +
 static const VMStateDescription vmstate_pci_outbound = {
 .name = pci_outbound,
 .version_id = 0,
 @@ -350,12 +364,13 @@ static int e500_pcihost_initfn(SysBusDevice *dev)
 
 for (i = 0; i  ARRAY_SIZE(s-irq); i++) {
 sysbus_init_irq(dev, s-irq[i]);
 +s-irq_num[i] = i + 1;

I still don't like how you duplicate the logic which MPIC irq line is 
associated with which pci host controller irq line. Please pass this 
information into the pcihost object somehow from ppce500_init() so that it's 
only at a single spot.

If you like, you can just use qom/qdev properties for that, but it needs to be 
configured from the outside.


Alex




Re: [Qemu-devel] [PATCH 0/5] targe-ppc: 970/p5+/p7/p7+/p8 SPRs cleanup

2013-12-20 Thread Alexander Graf

On 20.12.2013, at 07:41, Alexey Kardashevskiy a...@ozlabs.ru wrote:

 This removes not supported SPR from CPU classes.

Thanks a lot! Applied all to ppc-next.


Alex




Re: [Qemu-devel] [PATCH -V7 3/3] target-ppc: Fix page table lookup with kvm enabled

2013-12-20 Thread Alexander Graf

On 20.12.2013, at 06:24, Aneesh Kumar K.V aneesh.ku...@linux.vnet.ibm.com 
wrote:

 Alexander Graf ag...@suse.de writes:
 
 On 19.12.2013, at 07:55, Aneesh Kumar K.V aneesh.ku...@linux.vnet.ibm.com 
 wrote:
 
 Alexander Graf ag...@suse.de writes:
 
 On 07.11.2013, at 15:31, Aneesh Kumar K.V 
 aneesh.ku...@linux.vnet.ibm.com wrote:
 
 From: Aneesh Kumar K.V aneesh.ku...@linux.vnet.ibm.com
 
 With kvm enabled, we store the hash page table information in the 
 hypervisor.
 Use ioctl to read the htab contents. Without this we get the below error 
 when
 trying to read the guest address
 
 (gdb) x/10 do_fork
 0xc0098660 do_fork:   Cannot access memory at address 
 0xc0098660
 (gdb)
 
 Signed-off-by: Aneesh Kumar K.V aneesh.ku...@linux.vnet.ibm.com
 ---
 Changes from V6:
 * drop htab_fd argument and use global variable kvmppc_kern_htab instead
 
 hw/ppc/spapr.c  |  1 +
 hw/ppc/spapr_hcall.c| 50 +++
 target-ppc/kvm.c| 53 +
 target-ppc/kvm_ppc.h| 19 
 target-ppc/mmu-hash64.c | 78 
 -
 target-ppc/mmu-hash64.h | 23 ++-
 6 files changed, 183 insertions(+), 41 deletions(-)
 
 diff --git a/hw/ppc/spapr.c b/hw/ppc/spapr.c
 index d4f3502..8bf886e 100644
 --- a/hw/ppc/spapr.c
 +++ b/hw/ppc/spapr.c
 
 
 
 +hpte += index * HASH_PTE_SIZE_64;
 +
   ppc_hash64_store_hpte1(env, hpte, ptel);
 
 I'm not a big fan of fixing the read part, but leaving the write part
 broken. However I can see value in read only already, so I'm fine if
 the write part follows later.
 
 When do we want store support per hpte entry w.r.t to hash page table 
 maintained by the
 hypervisor. I didn't find a use case while doing this, hence i left that
 part out.
 
 Well, it's mostly a matter of consistency. The only case where it ever
 matters is if we wanted to emulate H_ENTER in QEMU - for tracing or
 debugging purposes. But if we leave it halfway implemented like this,
 you might get the impression it could work, but it doesn't.
 
 
 
 
   /* eieio();  FIXME: need some sort of barrier for smp? */
   ppc_hash64_store_hpte0(env, hpte, pteh | HPTE64_V_HPTE_DIRTY);
 
 -args[0] = pte_index + i;
 +args[0] = pte_index + index;
   return H_SUCCESS;
 }
 
 .
 
 #ifndef CONFIG_KVM
 diff --git a/target-ppc/mmu-hash64.c b/target-ppc/mmu-hash64.c
 index 67fc1b5..f59d199 100644
 --- a/target-ppc/mmu-hash64.c
 +++ b/target-ppc/mmu-hash64.c
 @@ -41,6 +41,11 @@
 #endif
 
 /*
 + * Used to indicate whether we have allocated htab in the
 + * host kernel
 + */
 +bool kvmppc_kern_htab;
 +/*
 * SLB handling
 */
 
 @@ -302,29 +307,76 @@ static int ppc_hash64_amr_prot(CPUPPCState *env, 
 ppc_hash_pte64_t pte)
   return prot;
 }
 
 -static hwaddr ppc_hash64_pteg_search(CPUPPCState *env, hwaddr pteg_off,
 +void *ppc_hash64_start_access(PowerPCCPU *cpu, unsigned long pte_index)
 +{
 +void *token = NULL;
 +hwaddr pte_offset;
 +
 +pte_offset = pte_index * HASH_PTE_SIZE_64;
 +if (kvmppc_kern_htab) {
 +/*
 + * HTAB is controlled by KVM. Fetch the PTEG into a new buffer.
 + */
 +token = kvmppc_hash64_read_pteg(cpu, pte_index);
 +if (token) {
 +return token;
 +}
 +/*
 + * pteg read failed, even though we have allocated htab via
 + * kvmppc_reset_htab.
 + */
 +return NULL;
 +}
 +/*
 + * HTAB is controlled by QEMU. Just point to the internally
 + * accessible PTEG.
 + */
 +if (cpu-env.external_htab) {
 +token = cpu-env.external_htab + pte_offset;
 +} else if (cpu-env.htab_base) {
 +token = (uint8_t *) cpu-env.htab_base + pte_offset;
 
 This breaks if you run a 64-bit guest on a 32-bit host trying to
 access memory beyond 4GB. In that case htab_base is hwaddr (64bit)
 while uint8_t is only 32bit wide.
 
 Wow!! didn't know that is possible.
 
 Well, with TCG you can run a 64-bit guest on a 32-bit host system, right?
 
 
 
 Just pass a 64bit token around. That makes it safe and easy.
 
 
 I converted that to uint64_t. How about Patch 1 and 2. Are they ok to go
 upstream ?
 
 Yup. It took me a while to figure out that the patches are doing the
 right thing. That code could really use some comments that explain
 what's going on - like the semantics of htab_mask (mask of the PTEG,
 will be shifted by 7 for physical address later), what htab_shift
 really is (log2 of the HTAB size), etc :).
 
 
 How about
 
/*
 * htab_mask is the mask used normalize hash value to PTEG index.
 * htab_shift is log2 of hash table size.
 * We have 8 hpte per group, and each hpte is 16 bytes.
 * ie have 128 bytes per hpte entry.
 */

I was thinking that maybe the htab_shift and htab_mask names are just 
confusing. But I haven't managed to come up with really good names either.

Just put some comment on the variable definitions and let's 

Re: [Qemu-devel] [PATCH V4] kvm: Add a new machine property kvm-type

2013-12-20 Thread Alexander Graf

On 19.12.2013, at 17:04, Aneesh Kumar K.V aneesh.ku...@linux.vnet.ibm.com 
wrote:

 From: Aneesh Kumar K.V aneesh.ku...@linux.vnet.ibm.com
 
 Targets like ppc64 support different typed of KVM, one which use
 hypervisor mode and the other which doesn't. Add a new machine
 property kvm-type that helps in selecting the respective ones
 We also add a new QEMUMachine callback get_vm_type that helps
 in mapping the string representation of kvm type specified.
 
 Signed-off-by: Aneesh Kumar K.V aneesh.ku...@linux.vnet.ibm.com

Thanks, applied to ppc-next.


Alex




[Qemu-devel] [RFC] test: QOM interface casting

2013-12-20 Thread Igor Mammedov
---
 tests/Makefile  |3 +
 tests/check-qom-interface.c |  102 +++
 2 files changed, 105 insertions(+), 0 deletions(-)
 create mode 100644 tests/check-qom-interface.c

diff --git a/tests/Makefile b/tests/Makefile
index 379cdd9..dfb6cce 100644
--- a/tests/Makefile
+++ b/tests/Makefile
@@ -52,6 +52,8 @@ check-unit-y += tests/test-int128$(EXESUF)
 gcov-files-test-int128-y =
 check-unit-y += tests/test-bitops$(EXESUF)
 check-unit-y += tests/test-qdev-global-props$(EXESUF)
+check-unit-y = tests/check-qom-interface$(EXESUF)
+gcov-files-check-qdict-y = object/object.c
 
 check-block-$(CONFIG_POSIX) += tests/qemu-iotests-quick.sh
 
@@ -205,6 +207,7 @@ tests/qom-test$(EXESUF): tests/qom-test.o
 tests/blockdev-test$(EXESUF): tests/blockdev-test.o $(libqos-pc-obj-y)
 tests/qdev-monitor-test$(EXESUF): tests/qdev-monitor-test.o $(libqos-pc-obj-y)
 tests/qemu-iotests/socket_scm_helper$(EXESUF): 
tests/qemu-iotests/socket_scm_helper.o
+tests/check-qom-interface$(EXESUF): tests/check-qom-interface.o qom/object.o 
qom/qom-qobject.o libqemuutil.a libqemustub.a
 
 # QTest rules
 
diff --git a/tests/check-qom-interface.c b/tests/check-qom-interface.c
new file mode 100644
index 000..6d59606
--- /dev/null
+++ b/tests/check-qom-interface.c
@@ -0,0 +1,102 @@
+/*
+ * OQM interfacei test.
+ *
+ * Copyright (C) 2013 Red Hat Inc.
+ *
+ * Authors:
+ *  Igor Mammedov imamm...@redhat.com
+ *
+ * This work is licensed under the terms of the GNU LGPL, version 2.1 or later.
+ * See the COPYING.LIB file in the top-level directory.
+ */
+#include glib.h
+
+#include qom/object.h
+#include qemu/module.h
+
+
+#define TYPE_TEST_IF test-interface
+#define TEST_IF_CLASS(klass) \
+ OBJECT_CLASS_CHECK(TestIfClass, (klass), TYPE_TEST_IF)
+#define TEST_IF_GET_CLASS(obj) \
+ OBJECT_GET_CLASS(TestIfClass, (obj), TYPE_TEST_IF)
+#define TEST_IF(obj) \
+ INTERFACE_CHECK(TestIf, (obj), TYPE_TEST_IF)
+
+typedef struct TestIf {
+Object Parent;
+} TestIf;
+
+typedef struct TestIfClass {
+InterfaceClass parent;
+
+uint32_t test;
+} TestIfClass;
+
+static const TypeInfo test_if_info = {
+.name  = TYPE_TEST_IF,
+.parent= TYPE_INTERFACE,
+.class_size = sizeof(TestIfClass),
+};
+
+#define PATTERN 0xFAFBFCFD
+static void test_class_init(ObjectClass *oc, void *data)
+{
+TestIfClass *tc = TEST_IF_CLASS(oc);
+
+g_assert(tc);
+tc-test = PATTERN;
+}
+
+#define TYPE_DIRECT_IMPL direct-impl
+static const TypeInfo direct_impl_info = {
+.name = TYPE_DIRECT_IMPL,
+.parent = TYPE_OBJECT,
+.class_init = test_class_init,
+.interfaces = (InterfaceInfo[]) {
+{ TYPE_TEST_IF },
+{ }
+}
+};
+
+#define TYPE_INTERMEDIATE_IMPL intermediate-impl
+static const TypeInfo intermediate_impl_info = {
+.name = TYPE_INTERMEDIATE_IMPL,
+.parent = TYPE_DIRECT_IMPL,
+};
+
+static void test_interface_impl(const char *type)
+{
+Object *obj = object_new(type);
+TestIf *iobj = TEST_IF(obj);
+TestIfClass *ico = TEST_IF_GET_CLASS(iobj);
+
+g_assert(iobj);
+g_assert(ico-test == PATTERN);
+}
+
+static void interface_direct_test(void)
+{
+test_interface_impl(TYPE_DIRECT_IMPL);
+}
+
+static void interface_intermediate_test(void)
+{
+test_interface_impl(TYPE_INTERMEDIATE_IMPL);
+}
+
+int main(int argc, char **argv)
+{
+g_test_init(argc, argv, NULL);
+
+module_call_init(MODULE_INIT_QOM);
+type_register_static(test_if_info);
+type_register_static(direct_impl_info);
+type_register_static(intermediate_impl_info);
+
+g_test_add_func(/interface/direct_impl, interface_direct_test);
+g_test_add_func(/interface/intermediate_impl,
+interface_intermediate_test);
+
+return g_test_run();
+}
-- 
1.7.1




Re: [Qemu-devel] [PATCH] qdev-monitor: Improve error message for -device nonexistant

2013-12-20 Thread Andreas Färber
Am 19.12.2013 15:30, schrieb arm...@redhat.com:
 From: Markus Armbruster arm...@redhat.com
 
 Once upon a time, the error message was:
 
 qemu: -device nonexistant: Device nonexistant not found.  Try -device 
 '?' for a list.
 
 But progress marches on, and conversion to QError (commit 0204276)
 changed it into:
 
 Invalid parameter 'driver'
 Try with argument '?' for a list.
 
 Progress didn't stop there, of course.  After a couple of iterations,
 we arrived at the current message (commit 6acbe4c):
 
 qemu: -device nonexistant: Parameter 'driver' expects device type
 
 Mission accomplished: this is complete mush.
 
 We've since abandoned our quest for rich error objects, fortunately
 before it turned all error messages into mush.  Time to undo the
 damage to this one.  Make it:
 
 qemu: -device nonexistant: nonexistant is not a valid device model name
 
 Signed-off-by: Markus Armbruster arm...@redhat.com
 ---
  qdev-monitor.c | 3 ++-
  1 file changed, 2 insertions(+), 1 deletion(-)

Thanks, rebased onto your other fix and applied to qom-next:
https://github.com/afaerber/qemu-cpu/commits/qom-next

Andreas

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



Re: [Qemu-devel] [PATCH v3 4/4] ioapic: QOM'ify ioapic

2013-12-20 Thread Andreas Färber
Am 19.12.2013 15:20, schrieb Paolo Bonzini:
 Il 18/12/2013 19:03, Andreas Färber ha scritto:
 @@ -61,7 +69,6 @@ static void ioapic_common_realize(DeviceState *dev, 
 Error **errp)
  {
  IOAPICCommonState *s = IOAPIC_COMMON(dev);
  IOAPICCommonClass *info;
 -static int ioapic_no;
  
  if (ioapic_no = MAX_IOAPICS) {
  error_setg(errp, Only %d ioapics allowed, MAX_IOAPICS);
 ... while the check for max. IOAPICs still happens in common code.

 Do we need to count KVM IOAPICs as well? Or can we consolidate this into
 the non-KVM version and keep it static there?
 
 KVM only supports one IOAPIC.  Creating a second fails with EEXIST.

As it turns out, MAX_IOAPICS is 1, so covers both cases. No KVM ioctl
actually happens on realize for using said EEXIST, so I moved the
increment back to where it was, minimizing changes.

If we want to redesign it, that can still be done in a follow-up patch.

Thanks,
Andreas

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



Re: [Qemu-devel] [PATCH v3] Fix QEMU build on OpenBSD on x86 archs

2013-12-20 Thread Brad Smith

On 14/12/13 11:27 PM, Brad Smith wrote:

On 10/12/13 7:49 PM, Brad Smith wrote:

This resolves the build issue with building the ROMs on OpenBSD on x86
archs.
As of OpenBSD 5.3 the compiler builds PIE binaries by default and thus
the
whole OS/packages and so forth. The ROMs need to have PIE disabled. This
is my initial attempt at trying to get somehting upstream so that QEMU
both builds out of the box and to resolve the build issue with the
buildbots that has been around for awhile. We have a patch in our ports
tree but it is just the flags hardcoded into the Makefile which obviously
is not appropriate for upstream.

 From the OpenBSD buildbots..
   Building optionrom/multiboot.img
ld: multiboot.o: relocation R_X86_64_16 can not be used when making a
shared object; recompile with -fPIC

Signed-off by: Brad Smith b...@comstyle.com


ping.


ping ping.


---

Change in v2:
 * Fix '==' is not portable syntax.

Change in v3:
 * Rename variables and use compile_prog to detect the presence of
the compiler/linker
   flags, as suggested by Stefan Weil.

diff --git a/configure b/configure
index 5d82283..89ae89d 100755
--- a/configure
+++ b/configure
@@ -1365,6 +1365,11 @@ EOF
pie=no
  fi
fi
+
+  if compile_prog -fno-pie -nopie; then
+CFLAGS_NOPIE=-fno-pie
+LDFLAGS_NOPIE=-nopie
+  fi
  fi

  ##
@@ -4320,6 +4325,7 @@ echo LD=$ld  $config_host_mak
  echo WINDRES=$windres  $config_host_mak
  echo LIBTOOL=$libtool  $config_host_mak
  echo CFLAGS=$CFLAGS  $config_host_mak
+echo CFLAGS_NOPIE=$CFLAGS_NOPIE  $config_host_mak
  echo QEMU_CFLAGS=$QEMU_CFLAGS  $config_host_mak
  echo QEMU_INCLUDES=$QEMU_INCLUDES  $config_host_mak
  if test $sparse = yes ; then
@@ -4333,6 +4339,7 @@ else
echo AUTOCONF_HOST :=  
$config_host_mak
  fi
  echo LDFLAGS=$LDFLAGS  $config_host_mak
+echo LDFLAGS_NOPIE=$LDFLAGS_NOPIE  $config_host_mak
  echo LIBTOOLFLAGS=$LIBTOOLFLAGS  $config_host_mak
  echo LIBS+=$LIBS  $config_host_mak
  echo LIBS_TOOLS+=$libs_tools  $config_host_mak
diff --git a/pc-bios/optionrom/Makefile b/pc-bios/optionrom/Makefile
index 57d8bd0..ce4852a 100644
--- a/pc-bios/optionrom/Makefile
+++ b/pc-bios/optionrom/Makefile
@@ -12,6 +12,7 @@ $(call set-vpath, $(SRC_PATH)/pc-bios/optionrom)
  CFLAGS := -Wall -Wstrict-prototypes -Werror -fomit-frame-pointer
-fno-builtin
  CFLAGS += -I$(SRC_PATH)
  CFLAGS += $(call cc-option, $(CFLAGS), -fno-stack-protector)
+CFLAGS += $(CFLAGS_NOPIE)
  QEMU_CFLAGS = $(CFLAGS)

  build-all: multiboot.bin linuxboot.bin kvmvapic.bin
@@ -20,7 +21,7 @@ build-all: multiboot.bin linuxboot.bin kvmvapic.bin
  .SECONDARY:

  %.img: %.o
-$(call quiet-command,$(LD) -Ttext 0 -e _start -s -o $@ $,
Building $(TARGET_DIR)$@)
+$(call quiet-command,$(LD) $(LDFLAGS_NOPIE) -Ttext 0 -e _start -s
-o $@ $,  Building $(TARGET_DIR)$@)

  %.raw: %.img
  $(call quiet-command,$(OBJCOPY) -O binary -j .text $ $@,
Building $(TARGET_DIR)$@)







--
This message has been scanned for viruses and
dangerous content by MailScanner, and is
believed to be clean.




Re: [Qemu-devel] [PATCH 2/2] ppc-e500: implement PCI INTx routing

2013-12-20 Thread bharat.bhus...@freescale.com


 -Original Message-
 From: Alexander Graf [mailto:ag...@suse.de]
 Sent: Friday, December 20, 2013 4:01 PM
 To: Bhushan Bharat-R65777
 Cc: Michael S. Tsirkin; Wood Scott-B07421; qemu-ppc; QEMU Developers; Bhushan
 Bharat-R65777
 Subject: Re: [PATCH 2/2] ppc-e500: implement PCI INTx routing
 
 
 On 20.12.2013, at 10:42, Bharat Bhushan r65...@freescale.com wrote:
 
  This patch adds pci pin to irq_num routing callback.
  This callback is called from pci_device_route_intx_to_irq to find
  which pci device maps to which irq. This is used for pci-device passthrough
 using vfio.
 
  Also without this patch we gets below warning
 
  
   PCI: Bug - unimplemented PCI INTx routing (e500-pcihost)
   qemu-system-ppc64: PCI: Bug - unimplemented PCI INTx routing
  (e500-pcihost) 
  and Legacy interrupt does not work with pci device passthrough.
 
  Signed-off-by: Bharat Bhushan bharat.bhus...@freescale.com
  Acked-by: Michael S. Tsirkin m...@redhat.com
  ---
  hw/pci-host/ppce500.c |   20 ++--
  1 files changed, 18 insertions(+), 2 deletions(-)
 
  diff --git a/hw/pci-host/ppce500.c b/hw/pci-host/ppce500.c index
  71e5ca9..ffea782 100644
  --- a/hw/pci-host/ppce500.c
  +++ b/hw/pci-host/ppce500.c
  @@ -88,6 +88,7 @@ struct PPCE500PCIState {
  struct pci_inbound pib[PPCE500_PCI_NR_PIBS];
  uint32_t gasket_time;
  qemu_irq irq[PCI_NUM_PINS];
  +uint32_t irq_num[PCI_NUM_PINS];
  uint32_t first_slot;
  /* mmio maps */
  MemoryRegion container;
  @@ -267,13 +268,26 @@ static int mpc85xx_pci_map_irq(PCIDevice
  *pci_dev, int pin)
 
  static void mpc85xx_pci_set_irq(void *opaque, int pin, int level) {
  -qemu_irq *irq = opaque;
  +PPCE500PCIState *s = opaque;
  +qemu_irq *pic = s-irq;
 
  pci_debug(%s: PCI irq %d, level:%d\n, __func__, pin , level);
 
  qemu_set_irq(irq[pin], level);
  }
 
  +static PCIINTxRoute e500_route_intx_pin_to_irq(void *opaque, int pin)
  +{
  +PCIINTxRoute route;
  +PPCE500PCIState *s = opaque;
  +
  +route.mode = PCI_INTX_ENABLED;
  +route.irq = s-irq_num[pin];
  +
  +pci_debug(%s: PCI irq-pin = %d, irq_num= %d\n, __func__, pin,
 route.irq);
  +return route;
  +}
  +
  static const VMStateDescription vmstate_pci_outbound = {
  .name = pci_outbound,
  .version_id = 0,
  @@ -350,12 +364,13 @@ static int e500_pcihost_initfn(SysBusDevice
  *dev)
 
  for (i = 0; i  ARRAY_SIZE(s-irq); i++) {
  sysbus_init_irq(dev, s-irq[i]);
  +s-irq_num[i] = i + 1;
 
 I still don't like how you duplicate the logic which MPIC irq line is 
 associated
 with which pci host controller irq line. Please pass this information into the
 pcihost object somehow from ppce500_init() so that it's only at a single spot.
 
 If you like, you can just use qom/qdev properties for that, but it needs to be
 configured from the outside.

Ok :)

I thought we guys agreed that let this patch come as is and Anthony's work will 
help globally.

Thanks
-Bharat

 
 
 Alex
 
 




Re: [Qemu-devel] [RFC] test: QOM interface casting

2013-12-20 Thread Peter Crosthwaite
On Fri, Dec 20, 2013 at 9:08 PM, Igor Mammedov imamm...@redhat.com wrote:
 ---
  tests/Makefile  |3 +
  tests/check-qom-interface.c |  102 
 +++
  2 files changed, 105 insertions(+), 0 deletions(-)
  create mode 100644 tests/check-qom-interface.c

 diff --git a/tests/Makefile b/tests/Makefile
 index 379cdd9..dfb6cce 100644
 --- a/tests/Makefile
 +++ b/tests/Makefile
 @@ -52,6 +52,8 @@ check-unit-y += tests/test-int128$(EXESUF)
  gcov-files-test-int128-y =
  check-unit-y += tests/test-bitops$(EXESUF)
  check-unit-y += tests/test-qdev-global-props$(EXESUF)
 +check-unit-y = tests/check-qom-interface$(EXESUF)
 +gcov-files-check-qdict-y = object/object.c

  check-block-$(CONFIG_POSIX) += tests/qemu-iotests-quick.sh

 @@ -205,6 +207,7 @@ tests/qom-test$(EXESUF): tests/qom-test.o
  tests/blockdev-test$(EXESUF): tests/blockdev-test.o $(libqos-pc-obj-y)
  tests/qdev-monitor-test$(EXESUF): tests/qdev-monitor-test.o 
 $(libqos-pc-obj-y)
  tests/qemu-iotests/socket_scm_helper$(EXESUF): 
 tests/qemu-iotests/socket_scm_helper.o
 +tests/check-qom-interface$(EXESUF): tests/check-qom-interface.o qom/object.o 
 qom/qom-qobject.o libqemuutil.a libqemustub.a

  # QTest rules

 diff --git a/tests/check-qom-interface.c b/tests/check-qom-interface.c
 new file mode 100644
 index 000..6d59606
 --- /dev/null
 +++ b/tests/check-qom-interface.c
 @@ -0,0 +1,102 @@
 +/*
 + * OQM interfacei test.
 + *
 + * Copyright (C) 2013 Red Hat Inc.
 + *
 + * Authors:
 + *  Igor Mammedov imamm...@redhat.com
 + *
 + * This work is licensed under the terms of the GNU LGPL, version 2.1 or 
 later.
 + * See the COPYING.LIB file in the top-level directory.
 + */
 +#include glib.h
 +
 +#include qom/object.h
 +#include qemu/module.h
 +
 +
 +#define TYPE_TEST_IF test-interface
 +#define TEST_IF_CLASS(klass) \
 + OBJECT_CLASS_CHECK(TestIfClass, (klass), TYPE_TEST_IF)
 +#define TEST_IF_GET_CLASS(obj) \
 + OBJECT_GET_CLASS(TestIfClass, (obj), TYPE_TEST_IF)
 +#define TEST_IF(obj) \
 + INTERFACE_CHECK(TestIf, (obj), TYPE_TEST_IF)
 +
 +typedef struct TestIf {
 +Object Parent;

parent_obj

 +} TestIf;
 +
 +typedef struct TestIfClass {
 +InterfaceClass parent;

parent_class?

Regards,
Peter

 +
 +uint32_t test;
 +} TestIfClass;
 +
 +static const TypeInfo test_if_info = {
 +.name  = TYPE_TEST_IF,
 +.parent= TYPE_INTERFACE,
 +.class_size = sizeof(TestIfClass),
 +};
 +
 +#define PATTERN 0xFAFBFCFD
 +static void test_class_init(ObjectClass *oc, void *data)
 +{
 +TestIfClass *tc = TEST_IF_CLASS(oc);
 +
 +g_assert(tc);
 +tc-test = PATTERN;
 +}
 +
 +#define TYPE_DIRECT_IMPL direct-impl
 +static const TypeInfo direct_impl_info = {
 +.name = TYPE_DIRECT_IMPL,
 +.parent = TYPE_OBJECT,
 +.class_init = test_class_init,
 +.interfaces = (InterfaceInfo[]) {
 +{ TYPE_TEST_IF },
 +{ }
 +}
 +};
 +
 +#define TYPE_INTERMEDIATE_IMPL intermediate-impl
 +static const TypeInfo intermediate_impl_info = {
 +.name = TYPE_INTERMEDIATE_IMPL,
 +.parent = TYPE_DIRECT_IMPL,
 +};
 +
 +static void test_interface_impl(const char *type)
 +{
 +Object *obj = object_new(type);
 +TestIf *iobj = TEST_IF(obj);
 +TestIfClass *ico = TEST_IF_GET_CLASS(iobj);
 +
 +g_assert(iobj);
 +g_assert(ico-test == PATTERN);
 +}
 +
 +static void interface_direct_test(void)
 +{
 +test_interface_impl(TYPE_DIRECT_IMPL);
 +}
 +
 +static void interface_intermediate_test(void)
 +{
 +test_interface_impl(TYPE_INTERMEDIATE_IMPL);
 +}
 +
 +int main(int argc, char **argv)
 +{
 +g_test_init(argc, argv, NULL);
 +
 +module_call_init(MODULE_INIT_QOM);
 +type_register_static(test_if_info);
 +type_register_static(direct_impl_info);
 +type_register_static(intermediate_impl_info);
 +
 +g_test_add_func(/interface/direct_impl, interface_direct_test);
 +g_test_add_func(/interface/intermediate_impl,
 +interface_intermediate_test);
 +
 +return g_test_run();
 +}
 --
 1.7.1





Re: [Qemu-devel] [PATCH 2/2] qom: detect bad reentrance during object_class_foreach

2013-12-20 Thread Andreas Färber
Am 19.12.2013 12:38, schrieb Alexey Kardashevskiy:
 On 12/16/2013 08:23 AM, Andreas Färber wrote:
 Am 04.12.2013 06:51, schrieb Peter Crosthwaite:
 On Wed, Dec 4, 2013 at 1:42 AM, Paolo Bonzini pbonz...@redhat.com wrote:
 From: Hervé Poussineau hpous...@reactos.org

 We should not modify the type hash table while it is being iterated on.
 Assert that it does not happen.

 Signed-off-by: Hervé Poussineau hpous...@reactos.org
 Signed-off-by: Paolo Bonzini pbonz...@redhat.com
 ---
  qom/object.c | 4 
  1 file changed, 4 insertions(+)

 diff --git a/qom/object.c b/qom/object.c
 index 3a43186..1dee9f0 100644
 --- a/qom/object.c
 +++ b/qom/object.c
 @@ -78,8 +78,10 @@ static GHashTable *type_table_get(void)
  return type_table;
  }

 +static bool enumerating = false;

 Global variable could probably use a more descriptive name.

 I renamed it to enumerating_types and dropped the assignment as
 suggested elsewhere by Alexey (a reply here would've been nice!).
 
 Whose reply? To what? :)

A reply of yours to Peter C.'s change request, stating that you have
addressed it - and in this case in which series. :)

 I also took the liberty of inserted a white line to make the function
 better readable.
 
 I do not mind, this was not my stuff :)
 
 What I wonder about is what is going to happen to the rest of what I
 posted? Should I wait till this qom-next gets merged to upstream and repost
 my patches for Alex Graf again? Thanks.

I do intend to post a pull before Chistmas, reviewing+applying the last
no_user patch from Markus was one key ingredient for that.

Not sure which rest exactly you're referring to? I need to review your
latest QemuOpts proposal among others. Actually I have a whole A4 page
written down with series I'm wading through. ;)

Cheers,
Andreas

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



[Qemu-devel] [PATCHv3] block: add native support for NFS

2013-12-20 Thread Peter Lieven
This patch adds native support for accessing images on NFS shares without
the requirement to actually mount the entire NFS share on the host.

NFS Images can simply be specified by an url of the form:
nfs://host/export/filename

For example:
qemu-img create -f qcow2 nfs://10.0.0.1/qemu-images/test.qcow2

You need libnfs from Ronnie Sahlberg available at:
   git://github.com/sahlberg/libnfs.git
for this to work.

During configure it is automatically probed for libnfs and support
is enabled on-the-fly. You can forbid or enforce libnfs support
with --disable-libnfs or --enable-libnfs respectively.

Due to NFS restrictions you might need to execute your binaries
as root, allow them to open priviledged ports (1024) or specify
insecure option on the NFS server.

LibNFS currently support NFS version 3 only.

Signed-off-by: Peter Lieven p...@kamp.de
---
v2-v3:
- rebased the stefanha/block
- use pkg_config to check for libnfs (ignoring cflags which are broken in 
1.8.0) [Stefan]
- fixed NFSClient declaration [Stefan]
- renamed Task variables to task [Stefan]
- renamed NFSTask to NFSRPC [Ronnie]
- do not update bs-total_sectors in nfs_co_writev [Stefan]
- return -ENOMEM on all async call failures [Stefan,Ronnie]
- fully implement ftruncate
- use util/uri.c for URL parsing [Stefan]
- reworked nfs_file_open_common to nfs_client_open which works on NFSClient 
[Stefan]
- added a comment ot the connect message that libnfs support NFSv3 only at the 
moment.
- DID NOT add full implementation of bdrv_get_allocated_file_size because
  we are not in a coroutine context and I cannot do an async call here.
  I could do a sync call if there would be a guarantee that no requests
  are in flight. [Stefan]

v1-v2:
 - fixed block/Makefile.objs [Ronnie]
 - do not always register a read handler [Ronnie]
 - add support for reading beyond EOF [Fam]
 - fixed struct and paramter naming [Fam]
 - fixed overlong lines and whitespace errors [Fam]
 - return return status from libnfs whereever possible [Fam]
 - added comment why we set allocated_file_size to -ENOTSUP after write [Fam]
 - avoid segfault when parsing filname [Fam]
 - remove unused close_bh from NFSClient [Fam]
 - avoid dividing and mutliplying total_size by BDRV_SECTOR_SIZE in 
nfs_file_create [Fam]

 MAINTAINERS |5 +
 block/Makefile.objs |1 +
 block/nfs.c |  402 +++
 configure   |   26 
 4 files changed, 434 insertions(+)
 create mode 100644 block/nfs.c

diff --git a/MAINTAINERS b/MAINTAINERS
index a5ab8f8..09996ab 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -935,6 +935,11 @@ M: Peter Lieven p...@kamp.de
 S: Supported
 F: block/iscsi.c
 
+NFS
+M: Peter Lieven p...@kamp.de
+S: Maintained
+F: block/nfs.c
+
 SSH
 M: Richard W.M. Jones rjo...@redhat.com
 S: Supported
diff --git a/block/Makefile.objs b/block/Makefile.objs
index 4e8c91e..e254a21 100644
--- a/block/Makefile.objs
+++ b/block/Makefile.objs
@@ -12,6 +12,7 @@ block-obj-$(CONFIG_LINUX_AIO) += linux-aio.o
 ifeq ($(CONFIG_POSIX),y)
 block-obj-y += nbd.o nbd-client.o sheepdog.o
 block-obj-$(CONFIG_LIBISCSI) += iscsi.o
+block-obj-$(CONFIG_LIBNFS) += nfs.o
 block-obj-$(CONFIG_CURL) += curl.o
 block-obj-$(CONFIG_RBD) += rbd.o
 block-obj-$(CONFIG_GLUSTERFS) += gluster.o
diff --git a/block/nfs.c b/block/nfs.c
new file mode 100644
index 000..5d34565
--- /dev/null
+++ b/block/nfs.c
@@ -0,0 +1,402 @@
+/*
+ * QEMU Block driver for native access to files on NFS shares
+ *
+ * Copyright (c) 2013 Peter Lieven p...@kamp.de
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the Software), to 
deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED AS IS, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
+ * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 
FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ * THE SOFTWARE.
+ */
+
+#include config-host.h
+
+#include poll.h
+#include qemu-common.h
+#include qemu/config-file.h
+#include qemu/error-report.h
+#include block/block_int.h
+#include trace.h
+#include qemu/iov.h
+#include qemu/uri.h
+#include sysemu/sysemu.h
+
+#include nfsc/libnfs-zdr.h
+#include nfsc/libnfs.h
+#include nfsc/libnfs-raw.h
+#include nfsc/libnfs-raw-mount.h
+

Re: [Qemu-devel] [PATCH] target-arm: use c13_context field for CONTEXTIDR

2013-12-20 Thread Peter Crosthwaite
On Fri, Dec 20, 2013 at 8:04 PM, Peter Maydell peter.mayd...@linaro.org wrote:
 On 20 December 2013 06:33, Sergey Fedorov s.fedo...@samsung.com wrote:
 Use c13_context field instead of c13_fcse for CONTEXTIDR register
 definition.

 Signed-off-by: Sergey Fedorov s.fedo...@samsung.com
 Reviewed-by: Peter Crosthwaite peter.crosthwa...@xilinx.com
 ---
  target-arm/helper.c |2 +-
  1 file changed, 1 insertion(+), 1 deletion(-)

 diff --git a/target-arm/helper.c b/target-arm/helper.c
 index 6ebd7dc..d52da0a 100644
 --- a/target-arm/helper.c
 +++ b/target-arm/helper.c
 @@ -397,7 +397,7 @@ static const ARMCPRegInfo cp_reginfo[] = {
.access = PL1_RW, .fieldoffset = offsetof(CPUARMState, cp15.c13_fcse),
.resetvalue = 0, .writefn = fcse_write, .raw_writefn = raw_write, },
  { .name = CONTEXTIDR, .cp = 15, .crn = 13, .crm = 0, .opc1 = 0, .opc2 
 = 1,
 -  .access = PL1_RW, .fieldoffset = offsetof(CPUARMState, cp15.c13_fcse),
 +  .access = PL1_RW, .fieldoffset = offsetof(CPUARMState, 
 cp15.c13_context),
.resetvalue = 0, .writefn = contextidr_write, .raw_writefn = 
 raw_write, },
  /* ??? This covers not just the impdef TLB lockdown registers but also
   * some v7VMSA registers relating to TEX remap, so it is overly broad.

 Wow, I wonder how things worked with that broken. Obvious cut-n-paste
 damage from back when we converted the cp regs.


Has a custom write handler which is correct AFAIK, so a write only
guest will work :)

Regards,
Peter

 Reviewed-by: Peter Maydell peter.mayd...@linaro.org

 thanks
 -- PMM




Re: [Qemu-devel] [PATCH 2/2] qom: detect bad reentrance during object_class_foreach

2013-12-20 Thread Alexey Kardashevskiy
On 12/20/2013 10:29 PM, Andreas Färber wrote:
 Am 19.12.2013 12:38, schrieb Alexey Kardashevskiy:
 On 12/16/2013 08:23 AM, Andreas Färber wrote:
 Am 04.12.2013 06:51, schrieb Peter Crosthwaite:
 On Wed, Dec 4, 2013 at 1:42 AM, Paolo Bonzini pbonz...@redhat.com wrote:
 From: Hervé Poussineau hpous...@reactos.org

 We should not modify the type hash table while it is being iterated on.
 Assert that it does not happen.

 Signed-off-by: Hervé Poussineau hpous...@reactos.org
 Signed-off-by: Paolo Bonzini pbonz...@redhat.com
 ---
  qom/object.c | 4 
  1 file changed, 4 insertions(+)

 diff --git a/qom/object.c b/qom/object.c
 index 3a43186..1dee9f0 100644
 --- a/qom/object.c
 +++ b/qom/object.c
 @@ -78,8 +78,10 @@ static GHashTable *type_table_get(void)
  return type_table;
  }

 +static bool enumerating = false;

 Global variable could probably use a more descriptive name.

 I renamed it to enumerating_types and dropped the assignment as
 suggested elsewhere by Alexey (a reply here would've been nice!).

 Whose reply? To what? :)
 
 A reply of yours to Peter C.'s change request, stating that you have
 addressed it - and in this case in which series. :)

You lost me here. I got these patches from Paolo Bonzini and I was told to
repost them together with my other patches, that's it :)


 I also took the liberty of inserted a white line to make the function
 better readable.

 I do not mind, this was not my stuff :)

 What I wonder about is what is going to happen to the rest of what I
 posted? Should I wait till this qom-next gets merged to upstream and repost
 my patches for Alex Graf again? Thanks.
 
 I do intend to post a pull before Chistmas, reviewing+applying the last
 no_user patch from Markus was one key ingredient for that.
 
 Not sure which rest exactly you're referring to? I need to review your
 latest QemuOpts proposal among others. Actually I have a whole A4 page
 written down with series I'm wading through. ;)


I posted the [PATCH v4 0/8] spapr: bootindex support series which
included the 2 patches you mentioned in this series, from the rest - 3 are
for spapr and 3 are platform independent.



-- 
Alexey



Re: [Qemu-devel] [PATCH v2 2/2] full introspection support for QMP

2013-12-20 Thread Amos Kong
(resend without big attachment)

Hello Eric, other

We had command, enumeration, type, unionobj in Eric suggested DataObject
union, it's helpful for us to provide meaningful metadata in the output.
but there still exists some problem.

We should describe some arbitrary data struct, I would like to call it 
undefined struct

eg 1: 
  { 'type': 'VersionInfo',
'data': {'qemu': {'major': 'int', 'minor': 'int', 'micro': 'int'},
 'package': 'str'} }
  it's same as:
  { 'type': 'newtype',
'data': {'major': 'int', 'minor': 'int', 'micro': 'int'} }
  { 'type': 'VersionInfo',
'data': { 'qemu': 'newtype', 'package': 'str'} }

  The difference between original 'DataObjectType' and 
'DataObjectUndefinedStruct'
  is that we don't have 'name' for the DataObject union for undefined struct.
  so I set the 'name' item in DataObjectBase to be optional.

eg 2:
  { 'command': 'human-monitor-command',
  'data': {'command-line': 'str', '*cpu-index': 'int'},
  'returns': 'str' }
  ... 'returns': ['RxFilterInfo'] }
  ... 'returns': 'ChardevReturn' }

  We returns str (native type), list or extended dict here. Sometimes we
  returns a defined type, but it doesn't need to be extended. And we need 
  to describe this kind of data (type str, dict or list) by DataObject
  in schema definition of DataObject** type.

  So I added a 'reference-type': 'String' in DataObject union.
  list, dict will still be described by DataObjectType


You can find the draft patches here:
  https://github.com/kongove/qemu/commits/qmp-introspection
I will post the V3 when I finish the cleanup.

Thanks, Amos


Command output
==
https://raw.github.com/kongove/misc/master/txt/qmp-introspection.output.txt 
(1.6M)

Latest schema definition

{ 'type': 'DataObjectBase',
  'data': { '*name': 'str', 'type': 'str' } }
{ 'union': 'DataObjectMemberType',
  'discriminator': {},
  'data': { 'reference': 'str',
'undefined': 'DataObject',
'extend': 'DataObject' } }
{ 'type': 'DataObjectMember',
  'data': { 'type': 'DataObjectMemberType', '*name': 'str',
'*optional': 'bool', '*recursive': 'bool' } }
{ 'type': 'DataObjectCommand',
  'data': { '*data': [ 'DataObjectMember' ],
'*returns': 'DataObject',
'*gen': 'bool' } }
{ 'type': 'DataObjectEnumeration',
  'data': { 'data': [ 'str' ] } }
{ 'type': 'DataObjectType',
  'data': { 'data': [ 'DataObjectMember' ] } }
{ 'type': 'DataObjectUndefinedStruct',
  'data': { 'data': [ 'DataObjectMember' ] } }
{ 'type': 'DataObjectUnion',
  'data': { 'data': [ 'DataObjectMember' ], '*base': 'str',
'*discriminator': 'str' } }
{ 'union': 'DataObject',
  'base': 'DataObjectBase',
  'discriminator': 'type',
  'data': {
'command': 'DataObjectCommand',
'enumeration': 'DataObjectEnumeration',
'type': 'DataObjectType',
'undefined-struct': 'DataObjectUndefinedStruct',
'reference-type': 'String',
'unionobj': 'DataObjectUnion' } }
{ 'command': 'query-qmp-schema', 'returns': ['DataObject'] }



pgpuoDAYkz555.pgp
Description: PGP signature


Re: [Qemu-devel] [RFC] test: QOM interface casting

2013-12-20 Thread Peter Maydell
On 20 December 2013 11:08, Igor Mammedov imamm...@redhat.com wrote:
 ---
  tests/Makefile  |3 +
  tests/check-qom-interface.c |  102 
 +++
  2 files changed, 105 insertions(+), 0 deletions(-)
  create mode 100644 tests/check-qom-interface.c

 diff --git a/tests/Makefile b/tests/Makefile
 index 379cdd9..dfb6cce 100644
 --- a/tests/Makefile
 +++ b/tests/Makefile
 @@ -52,6 +52,8 @@ check-unit-y += tests/test-int128$(EXESUF)
  gcov-files-test-int128-y =
  check-unit-y += tests/test-bitops$(EXESUF)
  check-unit-y += tests/test-qdev-global-props$(EXESUF)
 +check-unit-y = tests/check-qom-interface$(EXESUF)
 +gcov-files-check-qdict-y = object/object.c

  check-block-$(CONFIG_POSIX) += tests/qemu-iotests-quick.sh

 @@ -205,6 +207,7 @@ tests/qom-test$(EXESUF): tests/qom-test.o
  tests/blockdev-test$(EXESUF): tests/blockdev-test.o $(libqos-pc-obj-y)
  tests/qdev-monitor-test$(EXESUF): tests/qdev-monitor-test.o 
 $(libqos-pc-obj-y)
  tests/qemu-iotests/socket_scm_helper$(EXESUF): 
 tests/qemu-iotests/socket_scm_helper.o
 +tests/check-qom-interface$(EXESUF): tests/check-qom-interface.o qom/object.o 
 qom/qom-qobject.o libqemuutil.a libqemustub.a

This line's getting a bit long and could use folding I guess.


  # QTest rules

 diff --git a/tests/check-qom-interface.c b/tests/check-qom-interface.c
 new file mode 100644
 index 000..6d59606
 --- /dev/null
 +++ b/tests/check-qom-interface.c
 @@ -0,0 +1,102 @@
 +/*
 + * OQM interfacei test.

QOM, interface :-)

thanks
-- PMM



Re: [Qemu-devel] [PATCHv2] block: add native support for NFS

2013-12-20 Thread Stefan Hajnoczi
On Fri, Dec 20, 2013 at 10:48:41AM +0100, Peter Lieven wrote:
 On 17.12.2013 17:47, Stefan Hajnoczi wrote:
 On Tue, Dec 17, 2013 at 10:15:25AM +0100, Peter Lieven wrote:
 This patch adds native support for accessing images on NFS shares without
 the requirement to actually mount the entire NFS share on the host.
 
 NFS Images can simply be specified by an url of the form:
 nfs://host/export/filename
 
 For example:
 qemu-img create -f qcow2 nfs://10.0.0.1/qemu-images/test.qcow2
 
 You need libnfs from Ronnie Sahlberg available at:
 git://github.com/sahlberg/libnfs.git
 for this to work.
 
 During configure it is automatically probed for libnfs and support
 is enabled on-the-fly. You can forbid or enforce libnfs support
 with --disable-libnfs or --enable-libnfs respectively.
 
 Due to NFS restrictions you might need to execute your binaries
 as root, allow them to open priviledged ports (1024) or specify
 insecure option on the NFS server.
 
 Signed-off-by: Peter Lieven p...@kamp.de
 ---
 v1-v2:
   - fixed block/Makefile.objs [Ronnie]
   - do not always register a read handler [Ronnie]
   - add support for reading beyond EOF [Fam]
   - fixed struct and paramter naming [Fam]
   - fixed overlong lines and whitespace errors [Fam]
   - return return status from libnfs whereever possible [Fam]
   - added comment why we set allocated_file_size to -ENOTSUP after write 
  [Fam]
   - avoid segfault when parsing filname [Fam]
   - remove unused close_bh from NFSClient [Fam]
   - avoid dividing and mutliplying total_size by BDRV_SECTOR_SIZE in 
  nfs_file_create [Fam]
 
   MAINTAINERS |5 +
   block/Makefile.objs |1 +
   block/nfs.c |  419 
  +++
   configure   |   38 +
   4 files changed, 463 insertions(+)
   create mode 100644 block/nfs.c
 Which NFS protocol versions are supported by current libnfs?
 
 +#include poll.h
 Why is this header included?
 
 +typedef struct nfsclient {
 Please either drop the struct tag or use NFSClient.
 
 +static void
 +nfs_co_generic_cb(int status, struct nfs_context *nfs, void *data,
 +  void *private_data)
 +{
 +NFSTask *Task = private_data;
 lowercase task local variable name please.
 
 +static int coroutine_fn nfs_co_writev(BlockDriverState *bs,
 +int64_t sector_num, int nb_sectors,
 +QEMUIOVector *iov)
 +{
 +NFSClient *client = bs-opaque;
 +NFSTask task;
 +char *buf = NULL;
 +
 +nfs_co_init_task(client, task);
 +
 +buf = g_malloc(nb_sectors * BDRV_SECTOR_SIZE);
 +qemu_iovec_to_buf(iov, 0, buf, nb_sectors * BDRV_SECTOR_SIZE);
 +
 +if (nfs_pwrite_async(client-context, client-fh,
 + sector_num * BDRV_SECTOR_SIZE,
 + nb_sectors * BDRV_SECTOR_SIZE,
 + buf, nfs_co_generic_cb, task) != 0) {
 +g_free(buf);
 +return -EIO;
 Can we get a more detailed errno here?  (e.g. ENOSPC)
 
 +}
 +
 +while (!task.complete) {
 +nfs_set_events(client);
 +qemu_coroutine_yield();
 +}
 +
 +g_free(buf);
 +
 +if (task.status != nb_sectors * BDRV_SECTOR_SIZE) {
 +return task.status  0 ? task.status : -EIO;
 +}
 +
 +bs-total_sectors = MAX(bs-total_sectors, sector_num + nb_sectors);
 Why is this necessary?  block.c will update bs-total_sectors if the
 file is growable.
 
 +/* set to -ENOTSUP since bdrv_allocated_file_size is only used
 + * in qemu-img open. So we can use the cached value for allocate
 + * filesize obtained from fstat at open time */
 +client-allocated_file_size = -ENOTSUP;
 Can you implement this fully?  By stubbing it out like this we won't be
 able to call get_allocated_file_size() at runtime in the future without
 updating the nfs block driver code.  It's just an fstat call, shouldn't
 be too hard to implement properly :).
 
 It seems I have to leave it as is currently. bdrv_get_allocated_file_size
 is not in a coroutine context. I get coroutine yields to no one.

Create a coroutine and pump the event loop until it has reached
completion:

co = qemu_coroutine_create(my_coroutine_fn, ...);
qemu_coroutine_enter(co, foo);
while (!complete) {
qemu_aio_wait();
}

See block.c for similar examples.

Stefan



Re: [Qemu-devel] [RFC PATCH v3 1/6] block: introduce prealloc_mode

2013-12-20 Thread Eric Blake
On 12/18/2013 07:27 PM, Hu Tao wrote:
 This patch prepares for the subsequent patches.
 
 Signed-off-by: Hu Tao hu...@cn.fujitsu.com
 ---
  block/qcow2.c | 6 +++---
  include/block/block.h | 6 ++
  2 files changed, 9 insertions(+), 3 deletions(-)
 

 +++ b/include/block/block.h
 @@ -527,4 +527,10 @@ int bdrv_debug_remove_breakpoint(BlockDriverState *bs, 
 const char *tag);
  int bdrv_debug_resume(BlockDriverState *bs, const char *tag);
  bool bdrv_debug_is_suspended(BlockDriverState *bs, const char *tag);
  
 +enum prealloc_mode {
 +PREALLOC_OFF = 0,
 +PREALLOC_METADATA,
 +PREALLOC_FULL,
 +};

Why not make this a QAPI enum:

{ 'enum': 'PreallocMode', 'data': ['off', 'metadata', 'full'] }

After all, this is the sort of thing where we will eventually want to
select the prealloc mode of new files being created by online operations
such as snapshot creation.

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



signature.asc
Description: OpenPGP digital signature


Re: [Qemu-devel] [RFC] test: QOM interface casting

2013-12-20 Thread Andreas Färber
Hi,

Am 20.12.2013 12:08, schrieb Igor Mammedov:
 ---
  tests/Makefile  |3 +
  tests/check-qom-interface.c |  102 
 +++
  2 files changed, 105 insertions(+), 0 deletions(-)
  create mode 100644 tests/check-qom-interface.c

Apart from the style issues and typos that the two Peter's have pointed
out, I'd like to point out that this is missing Signed-off-by and commit
message. In particular, is this a test that should be committed
alongside the interface cast fixes or anything else that I have queued?
Or just to improve overall test coverage? Either way I'm in favor of
having them.

Concerning PMM's comment, don't we already have a qdev properties unit
test from Eduardo where we might share QOM dependencies via some
Makefile variable? Grouping the check-* tests also makes sense to me
than just adding at the bottom.

Anything in particular that you'd like comments on, this being an RFC?

Regards,
Andreas

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



Re: [Qemu-devel] [PATCH 03/27] pc: add 'etc/reserved-memory-end' fw_cfg interface for SeaBIOS

2013-12-20 Thread Igor Mammedov
On Thu, 19 Dec 2013 16:35:05 +0200
Michael S. Tsirkin m...@redhat.com wrote:

 On Thu, Nov 21, 2013 at 03:38:24AM +0100, Igor Mammedov wrote:
  'etc/reserved-memory-end' will allow QEMU to tell BIOS where PCI
  BARs mapping could safely start in high memory.
  
  Allowing BIOS to start mapping 64-bit PCI BARs at address where it
  wouldn't conflict with other mappings QEMU might place before it.
  
  That permits QEMU to reserve extra address space before
  64-bit PCI hole for memory hotplug.
  
  Signed-off-by: Igor Mammedov imamm...@redhat.com
  ---
  v2:
 * disable 'etc/reserved-memory-end' for 1.7 and older machine types
  ---
   hw/i386/pc.c |   27 +--
   hw/i386/pc_piix.c|1 +
   hw/i386/pc_q35.c |1 +
   hw/pci-host/piix.c   |3 ++-
   hw/pci-host/q35.c|3 ++-
   include/hw/i386/pc.h |   11 +--
   6 files changed, 40 insertions(+), 6 deletions(-)
  
  diff --git a/hw/i386/pc.c b/hw/i386/pc.c
  index 6c82ada..ba82c67 100644
  --- a/hw/i386/pc.c
  +++ b/hw/i386/pc.c
  @@ -1094,14 +1094,37 @@ PcGuestInfo *pc_guest_info_init(ram_addr_t 
  below_4g_mem_size,
   }
   
   /* setup pci memory address space mapping into system address space */
  -void pc_pci_as_mapping_init(Object *owner, MemoryRegion *system_memory,
  -MemoryRegion *pci_address_space)
  +void pc_pci_as_mapping_init_1_7(Object *owner, MemoryRegion *system_memory,
  +MemoryRegion *pci_address_space,
  +uint64_t reserved_memory_end)
   {
   /* Set to lower priority than RAM */
   memory_region_add_subregion_overlap(system_memory, 0x0,
   pci_address_space, -1);
   }
   
  +static
  +void pc_pci_as_mapping_init_1_8(Object *owner, MemoryRegion *system_memory,
  +MemoryRegion *pci_address_space,
  +uint64_t reserved_memory_end)
  +{
  +uint64_t *val;
  +FWCfgState *fw_cfg = fw_cfg_find();
  +g_assert(fw_cfg);
  +/*
  + *  Align address at 1G, this makes sure it can be exactly covered
  + *  with a PAT entry even when using huge pages.
  + */
  +val = g_malloc(sizeof(*val));
  +*val = cpu_to_le64(ROUND_UP(reserved_memory_end, 0x1ULL  30));
  +fw_cfg_add_file(fw_cfg, etc/reserved-memory-end, val, sizeof(*val));
  +
  +pc_pci_as_mapping_init_1_7(owner, system_memory, pci_address_space,
  +   reserved_memory_end);
  +}
  +
  +pc_pci_as_mapping_init_fn pc_pci_as_mapping_init = 
  pc_pci_as_mapping_init_1_8;
  +
   void pc_acpi_init(const char *default_dsdt)
   {
   char *filename;
  diff --git a/hw/i386/pc_piix.c b/hw/i386/pc_piix.c
  index 36f2495..e1fe85a 100644
  --- a/hw/i386/pc_piix.c
  +++ b/hw/i386/pc_piix.c
  @@ -249,6 +249,7 @@ static void pc_init_pci(QEMUMachineInitArgs *args)
   static void pc_compat_1_7(QEMUMachineInitArgs *args)
   {
   smbios_type1_defaults = false;
  +pc_pci_as_mapping_init = pc_pci_as_mapping_init_1_7;
   }
   
   static void pc_compat_1_6(QEMUMachineInitArgs *args)
  diff --git a/hw/i386/pc_q35.c b/hw/i386/pc_q35.c
  index 50ca458..5525465 100644
  --- a/hw/i386/pc_q35.c
  +++ b/hw/i386/pc_q35.c
  @@ -233,6 +233,7 @@ static void pc_q35_init(QEMUMachineInitArgs *args)
   static void pc_compat_1_7(QEMUMachineInitArgs *args)
   {
   smbios_type1_defaults = false;
  +pc_pci_as_mapping_init = pc_pci_as_mapping_init_1_7;
   }
   
   static void pc_compat_1_6(QEMUMachineInitArgs *args)
 
 I don't much like this: why not use a global flag like we do
 for other properties?
because flag would add extra branching clattering code, while
overriding function makes caller cleaner and potentially maps
well into method override when machines are converted to QOM objects.
So why not to try this vs flags?

 
 Also, 1_8 should be replaced with 2_0 now.
sure

 
  diff --git a/hw/pci-host/piix.c b/hw/pci-host/piix.c
  index 63be7f6..615ab0d 100644
  --- a/hw/pci-host/piix.c
  +++ b/hw/pci-host/piix.c
  @@ -352,7 +352,8 @@ PCIBus *i440fx_init(PCII440FXState **pi440fx_state,
   
   /* setup pci memory mapping */
   pc_pci_as_mapping_init(OBJECT(f), f-system_memory,
  -   f-pci_address_space);
  +   f-pci_address_space,
  +   0x1ULL + above_4g_mem_size);
   
   memory_region_init_alias(f-smram_region, OBJECT(d), smram-region,
f-pci_address_space, 0xa, 0x2);
  diff --git a/hw/pci-host/q35.c b/hw/pci-host/q35.c
  index 81c8240..6e28418 100644
  --- a/hw/pci-host/q35.c
  +++ b/hw/pci-host/q35.c
  @@ -359,7 +359,8 @@ static int mch_init(PCIDevice *d)
   
   /* setup pci memory mapping */
   pc_pci_as_mapping_init(OBJECT(mch), mch-system_memory,
  -   mch-pci_address_space);
  +   mch-pci_address_space,
  

Re: [Qemu-devel] [PATCHv2] block: add native support for NFS

2013-12-20 Thread Peter Lieven

On 20.12.2013 13:19, Stefan Hajnoczi wrote:

On Fri, Dec 20, 2013 at 10:48:41AM +0100, Peter Lieven wrote:

On 17.12.2013 17:47, Stefan Hajnoczi wrote:

On Tue, Dec 17, 2013 at 10:15:25AM +0100, Peter Lieven wrote:

This patch adds native support for accessing images on NFS shares without
the requirement to actually mount the entire NFS share on the host.

NFS Images can simply be specified by an url of the form:
nfs://host/export/filename

For example:
qemu-img create -f qcow2 nfs://10.0.0.1/qemu-images/test.qcow2

You need libnfs from Ronnie Sahlberg available at:
git://github.com/sahlberg/libnfs.git
for this to work.

During configure it is automatically probed for libnfs and support
is enabled on-the-fly. You can forbid or enforce libnfs support
with --disable-libnfs or --enable-libnfs respectively.

Due to NFS restrictions you might need to execute your binaries
as root, allow them to open priviledged ports (1024) or specify
insecure option on the NFS server.

Signed-off-by: Peter Lieven p...@kamp.de
---
v1-v2:
  - fixed block/Makefile.objs [Ronnie]
  - do not always register a read handler [Ronnie]
  - add support for reading beyond EOF [Fam]
  - fixed struct and paramter naming [Fam]
  - fixed overlong lines and whitespace errors [Fam]
  - return return status from libnfs whereever possible [Fam]
  - added comment why we set allocated_file_size to -ENOTSUP after write [Fam]
  - avoid segfault when parsing filname [Fam]
  - remove unused close_bh from NFSClient [Fam]
  - avoid dividing and mutliplying total_size by BDRV_SECTOR_SIZE in 
nfs_file_create [Fam]

  MAINTAINERS |5 +
  block/Makefile.objs |1 +
  block/nfs.c |  419 +++
  configure   |   38 +
  4 files changed, 463 insertions(+)
  create mode 100644 block/nfs.c

Which NFS protocol versions are supported by current libnfs?


+#include poll.h

Why is this header included?


+typedef struct nfsclient {

Please either drop the struct tag or use NFSClient.


+static void
+nfs_co_generic_cb(int status, struct nfs_context *nfs, void *data,
+  void *private_data)
+{
+NFSTask *Task = private_data;

lowercase task local variable name please.


+static int coroutine_fn nfs_co_writev(BlockDriverState *bs,
+int64_t sector_num, int nb_sectors,
+QEMUIOVector *iov)
+{
+NFSClient *client = bs-opaque;
+NFSTask task;
+char *buf = NULL;
+
+nfs_co_init_task(client, task);
+
+buf = g_malloc(nb_sectors * BDRV_SECTOR_SIZE);
+qemu_iovec_to_buf(iov, 0, buf, nb_sectors * BDRV_SECTOR_SIZE);
+
+if (nfs_pwrite_async(client-context, client-fh,
+ sector_num * BDRV_SECTOR_SIZE,
+ nb_sectors * BDRV_SECTOR_SIZE,
+ buf, nfs_co_generic_cb, task) != 0) {
+g_free(buf);
+return -EIO;

Can we get a more detailed errno here?  (e.g. ENOSPC)


+}
+
+while (!task.complete) {
+nfs_set_events(client);
+qemu_coroutine_yield();
+}
+
+g_free(buf);
+
+if (task.status != nb_sectors * BDRV_SECTOR_SIZE) {
+return task.status  0 ? task.status : -EIO;
+}
+
+bs-total_sectors = MAX(bs-total_sectors, sector_num + nb_sectors);

Why is this necessary?  block.c will update bs-total_sectors if the
file is growable.


+/* set to -ENOTSUP since bdrv_allocated_file_size is only used
+ * in qemu-img open. So we can use the cached value for allocate
+ * filesize obtained from fstat at open time */
+client-allocated_file_size = -ENOTSUP;

Can you implement this fully?  By stubbing it out like this we won't be
able to call get_allocated_file_size() at runtime in the future without
updating the nfs block driver code.  It's just an fstat call, shouldn't
be too hard to implement properly :).

It seems I have to leave it as is currently. bdrv_get_allocated_file_size
is not in a coroutine context. I get coroutine yields to no one.

Create a coroutine and pump the event loop until it has reached
completion:

co = qemu_coroutine_create(my_coroutine_fn, ...);
qemu_coroutine_enter(co, foo);
while (!complete) {
 qemu_aio_wait();
}

See block.c for similar examples.

Wouldn't it make sense to make this modification to 
bdrv_get_allocated_file_size in
block.c rather than in client/nfs.c and in the future potentially other drivers?

If yes, I would ask you to take v3 of the NFS protocol patch and I promise to 
send
a follow up early next year to make this modification to block.c and change 
block/nfs.c
and other implementations to be a coroutine_fn.

Thanks
Peter



Re: [Qemu-devel] [RFC PATCH v3 0/6] qemu-img: add preallocation=full

2013-12-20 Thread Eric Blake
On 12/20/2013 03:30 AM, Stefan Hajnoczi wrote:
 On Thu, Dec 19, 2013 at 10:27:35AM +0800, Hu Tao wrote:
 This series implements full image preallocation to create a non-sparse image
 file at creation time, both for raw and qcow2 format. The purpose is to avoid
 performance deterioration of the guest cause by sparse image.
 
 I'm not sure the new bdrv_preallocate() interface is necessary.  Can
 qcow2_create() simply pass a preallocate=full option to
 bdrv_create_file()?
 
 It's simpler if we avoid bdrv_preallocate(), just keep it a
 .bdrv_create() option.  That way we also avoid the question of how
 exactly preallocate functions on an image file that already has blocks
 allocated.
 
 So what I imagine is:
 1. Add preallocation=full support to raw-posix.c
 2. Add preallocation=full support to qcow2.c, calculate image file size
 including metadata for bdrv_create_file().
 
 CCing Eric Blake so libvirt can consider how full preallocation
 interacts with their safezero() preallocation.  If QEMU handles
 preallocation can we skip safezero()?  Is there a concern about full
 preallocation in QEMU taking a long time without progress report?

If libvirt can detect that qemu is new enough to do preallocation, then
libvirt can skip its own preallocation.  Which means you need to make
sure that QMP can probe the existence of this new feature (probably
already possible via query-command-line-options, but see also my reply
to 1/6 about starting to put this in QAPI).

The fact that preallocation is sometimes long running is definitely
worth considering; but it raises the more generic issue of how to turn
any long running blocking command into an asynchronous job that gets
started, then has both polling and event-notification progress until
completion, as well as the option of an early abort if it is taking too
long.

And there's my long-standing gripe that qemu-img doesn't support -p
progress meters for enough of its already-existing long-running
commands, which makes it harder for libvirt to provide wrappers around
qemu-img operations when manipulating images not associated with a
running VM.

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



signature.asc
Description: OpenPGP digital signature


Re: [Qemu-devel] [PATCHv3] block: add native support for NFS

2013-12-20 Thread Stefan Hajnoczi
On Fri, Dec 20, 2013 at 12:31:57PM +0100, Peter Lieven wrote:
 - DID NOT add full implementation of bdrv_get_allocated_file_size because
   we are not in a coroutine context and I cannot do an async call here.
   I could do a sync call if there would be a guarantee that no requests
   are in flight. [Stefan]

Let's discuss in the other email thread where we started.

 +static int64_t nfs_client_open(NFSClient *client, const char *filename,
 +   int flags, Error **errp)
 +{
 +int ret = -EINVAL;
 +URI *uri;
 +char *file = NULL, *strp = NULL;
 +struct stat st;
 +
 +uri = uri_parse(filename);
 +if (!uri) {
 +error_setg(errp, Invalid URL specified.\n);

\n should not be included in error_setg() messages.

 +goto fail;
 +}
 +strp = strrchr(uri-path, '/');
 +if (strp == NULL) {
 +error_setg(errp, Invalid URL specified.\n);

\n should not be included in error_setg() messages.



Re: [Qemu-devel] [PATCH 07/21] target-arm: A64: add support for 3 src data proc insns

2013-12-20 Thread Peter Maydell
On 19 December 2013 19:29, Richard Henderson r...@twiddle.net wrote:
 On 12/17/2013 07:12 AM, Peter Maydell wrote:
 +tcg_gen_mul_i64(tcg_tmp, tcg_op1, tcg_op2);
 +if (is_sub) {
 +tcg_gen_sub_i64(cpu_reg(s, rd), cpu_reg(s, ra), tcg_tmp);
 +} else {
 +tcg_gen_add_i64(cpu_reg(s, rd), cpu_reg(s, ra), tcg_tmp);
 +}

 Perhaps worth noticing the RA=XZR special case for the MUL alias?

Yeah, makes sense: have adjusted to:
+if (ra == 31) {
+/* We special-case rA == XZR as it is the standard MUL alias */
+tcg_gen_mul_i64(cpu_reg(s, rd), tcg_op1, tcg_op2);
+} else {
+tcg_gen_mul_i64(tcg_tmp, tcg_op1, tcg_op2);
+if (is_sub) {
+tcg_gen_sub_i64(cpu_reg(s, rd), cpu_reg(s, ra), tcg_tmp);
+} else {
+tcg_gen_add_i64(cpu_reg(s, rd), cpu_reg(s, ra), tcg_tmp);
+}
+}

thanks
-- PMM



Re: [Qemu-devel] [RFC] test: QOM interface casting

2013-12-20 Thread Igor Mammedov
On Fri, 20 Dec 2013 13:47:32 +0100
Andreas Färber afaer...@suse.de wrote:

 Hi,
 
 Am 20.12.2013 12:08, schrieb Igor Mammedov:
  ---
   tests/Makefile  |3 +
   tests/check-qom-interface.c |  102 
  +++
   2 files changed, 105 insertions(+), 0 deletions(-)
   create mode 100644 tests/check-qom-interface.c
 
 Apart from the style issues and typos that the two Peter's have pointed
 out, I'd like to point out that this is missing Signed-off-by and commit
 message. In particular, is this a test that should be committed
 alongside the interface cast fixes or anything else that I have queued?
 Or just to improve overall test coverage? Either way I'm in favor of
 having them.
Since interfaces are not widely used it's easy to break them, this adds
regression testing. It could go along with fixes you've queued.

 
 Concerning PMM's comment, don't we already have a qdev properties unit
 test from Eduardo where we might share QOM dependencies via some
 Makefile variable? Grouping the check-* tests also makes sense to me
 than just adding at the bottom.
 
 Anything in particular that you'd like comments on, this being an RFC?
Peters's and your comments are applied, I'll respin it as patch,
thanks for reviewing.

 Regards,
 Andreas
 




Re: [Qemu-devel] [PATCHv3] block: add native support for NFS

2013-12-20 Thread Peter Lieven

On 20.12.2013 14:07, Stefan Hajnoczi wrote:

On Fri, Dec 20, 2013 at 12:31:57PM +0100, Peter Lieven wrote:

- DID NOT add full implementation of bdrv_get_allocated_file_size because
   we are not in a coroutine context and I cannot do an async call here.
   I could do a sync call if there would be a guarantee that no requests
   are in flight. [Stefan]

Let's discuss in the other email thread where we started.

Okay.



+static int64_t nfs_client_open(NFSClient *client, const char *filename,
+   int flags, Error **errp)
+{
+int ret = -EINVAL;
+URI *uri;
+char *file = NULL, *strp = NULL;
+struct stat st;
+
+uri = uri_parse(filename);
+if (!uri) {
+error_setg(errp, Invalid URL specified.\n);

\n should not be included in error_setg() messages.


+goto fail;
+}
+strp = strrchr(uri-path, '/');
+if (strp == NULL) {
+error_setg(errp, Invalid URL specified.\n);

\n should not be included in error_setg() messages.


If thats the only objection you have, please remove the \n
when picking.

Thanks,
Peter



Re: [Qemu-devel] [PATCH 13/21] target-arm: A64: Implement MRS/MSR/SYS/SYSL

2013-12-20 Thread Peter Maydell
On 19 December 2013 20:30, Richard Henderson r...@twiddle.net wrote:
 On 12/17/2013 07:12 AM, Peter Maydell wrote:
 +/* Force a TB lookup after an instruction that changes the CPU state */
 +static inline void gen_lookup_tb(DisasContext *s)
 +{
 +gen_a64_set_pc_im(s-pc);
 +s-is_jmp = DISAS_UPDATE;
 +}
 +

 I'm a bit surprised that this set_pc doesn't happen in
 gen_intermediate_code_internal_a64.  Otherwise, what's the point in
 distinguishing between DISAS_JUMP and DISAS_UPDATE?

I just borrowed this from the 32 bit decoder, which also sets PC
in gen_lookup_tb(). However you're right that we might as well
do the set pc in the top level loop. I've adjusted that loop to do so
and dropped the gen_lookup_tb() function in favour of just setting
s-is_jmp = DISAS_UPDATE directly at its callsites.

thanks
-- PMM



[Qemu-devel] [PATCH] test: QOM interface casting

2013-12-20 Thread Igor Mammedov
Add basic regression testing for QOM Interface usage.

Signed-off-by: Igor Mammedov imamm...@redhat.com
---
v2:
 - Peter Crosthwaite peter.crosthwa...@xilinx.com
   * s/Parent/parent_obj/
   * s/parent/parent_class/
 - Peter Maydell peter.mayd...@linaro.org
   * s/interfacei/interface/
   * tests/Makefile split too long line
 - Andreas Färber afaer...@suse.de
   * consolidate QOM core object files in dedicated variable
   * add SoB and commit message
---
 tests/Makefile  |6 ++-
 tests/check-qom-interface.c |  102 +++
 2 files changed, 107 insertions(+), 1 deletions(-)
 create mode 100644 tests/check-qom-interface.c

diff --git a/tests/Makefile b/tests/Makefile
index 379cdd9..89f8eff 100644
--- a/tests/Makefile
+++ b/tests/Makefile
@@ -52,6 +52,8 @@ check-unit-y += tests/test-int128$(EXESUF)
 gcov-files-test-int128-y =
 check-unit-y += tests/test-bitops$(EXESUF)
 check-unit-y += tests/test-qdev-global-props$(EXESUF)
+check-unit-y = tests/check-qom-interface$(EXESUF)
+gcov-files-check-qdict-y = object/object.c
 
 check-block-$(CONFIG_POSIX) += tests/qemu-iotests-quick.sh
 
@@ -137,6 +139,7 @@ test-qapi-obj-y = tests/test-qapi-visit.o 
tests/test-qapi-types.o
 
 $(test-obj-y): QEMU_INCLUDES += -Itests
 QEMU_CFLAGS += -I$(SRC_PATH)/tests
+qom-core-obj = qom/object.o qom/qom-qobject.o qom/container.o
 
 tests/test-x86-cpuid.o: QEMU_INCLUDES += -I$(SRC_PATH)/target-i386
 
@@ -146,6 +149,7 @@ tests/check-qdict$(EXESUF): tests/check-qdict.o 
libqemuutil.a
 tests/check-qlist$(EXESUF): tests/check-qlist.o libqemuutil.a
 tests/check-qfloat$(EXESUF): tests/check-qfloat.o libqemuutil.a
 tests/check-qjson$(EXESUF): tests/check-qjson.o libqemuutil.a libqemustub.a
+tests/check-qom-interface$(EXESUF): tests/check-qom-interface.o 
$(qom-core-obj) libqemuutil.a
 tests/test-coroutine$(EXESUF): tests/test-coroutine.o $(block-obj-y) 
libqemuutil.a libqemustub.a
 tests/test-aio$(EXESUF): tests/test-aio.o $(block-obj-y) libqemuutil.a 
libqemustub.a
 tests/test-throttle$(EXESUF): tests/test-throttle.o $(block-obj-y) 
libqemuutil.a libqemustub.a
@@ -159,7 +163,7 @@ tests/test-int128$(EXESUF): tests/test-int128.o
 tests/test-qdev-global-props$(EXESUF): tests/test-qdev-global-props.o \
hw/core/qdev.o hw/core/qdev-properties.o \
hw/core/irq.o \
-   qom/object.o qom/container.o qom/qom-qobject.o \
+   $(qom-core-obj) \
$(test-qapi-obj-y) \
libqemuutil.a libqemustub.a
 
diff --git a/tests/check-qom-interface.c b/tests/check-qom-interface.c
new file mode 100644
index 000..8d7c1f8
--- /dev/null
+++ b/tests/check-qom-interface.c
@@ -0,0 +1,102 @@
+/*
+ * OQM interface test.
+ *
+ * Copyright (C) 2013 Red Hat Inc.
+ *
+ * Authors:
+ *  Igor Mammedov imamm...@redhat.com
+ *
+ * This work is licensed under the terms of the GNU LGPL, version 2.1 or later.
+ * See the COPYING.LIB file in the top-level directory.
+ */
+#include glib.h
+
+#include qom/object.h
+#include qemu/module.h
+
+
+#define TYPE_TEST_IF test-interface
+#define TEST_IF_CLASS(klass) \
+ OBJECT_CLASS_CHECK(TestIfClass, (klass), TYPE_TEST_IF)
+#define TEST_IF_GET_CLASS(obj) \
+ OBJECT_GET_CLASS(TestIfClass, (obj), TYPE_TEST_IF)
+#define TEST_IF(obj) \
+ INTERFACE_CHECK(TestIf, (obj), TYPE_TEST_IF)
+
+typedef struct TestIf {
+Object parent_obj;
+} TestIf;
+
+typedef struct TestIfClass {
+InterfaceClass parent_class;
+
+uint32_t test;
+} TestIfClass;
+
+static const TypeInfo test_if_info = {
+.name  = TYPE_TEST_IF,
+.parent= TYPE_INTERFACE,
+.class_size = sizeof(TestIfClass),
+};
+
+#define PATTERN 0xFAFBFCFD
+static void test_class_init(ObjectClass *oc, void *data)
+{
+TestIfClass *tc = TEST_IF_CLASS(oc);
+
+g_assert(tc);
+tc-test = PATTERN;
+}
+
+#define TYPE_DIRECT_IMPL direct-impl
+static const TypeInfo direct_impl_info = {
+.name = TYPE_DIRECT_IMPL,
+.parent = TYPE_OBJECT,
+.class_init = test_class_init,
+.interfaces = (InterfaceInfo[]) {
+{ TYPE_TEST_IF },
+{ }
+}
+};
+
+#define TYPE_INTERMEDIATE_IMPL intermediate-impl
+static const TypeInfo intermediate_impl_info = {
+.name = TYPE_INTERMEDIATE_IMPL,
+.parent = TYPE_DIRECT_IMPL,
+};
+
+static void test_interface_impl(const char *type)
+{
+Object *obj = object_new(type);
+TestIf *iobj = TEST_IF(obj);
+TestIfClass *ico = TEST_IF_GET_CLASS(iobj);
+
+g_assert(iobj);
+g_assert(ico-test == PATTERN);
+}
+
+static void interface_direct_test(void)
+{
+test_interface_impl(TYPE_DIRECT_IMPL);
+}
+
+static void interface_intermediate_test(void)
+{
+test_interface_impl(TYPE_INTERMEDIATE_IMPL);
+}
+
+int main(int argc, char **argv)
+{
+g_test_init(argc, argv, NULL);
+
+module_call_init(MODULE_INIT_QOM);
+type_register_static(test_if_info);
+type_register_static(direct_impl_info);
+type_register_static(intermediate_impl_info);
+
+g_test_add_func(/interface/direct_impl, 

Re: [Qemu-devel] [PULL 00/13] QMP queue

2013-12-20 Thread Luiz Capitulino
On Fri, 20 Dec 2013 14:00:21 +1000
Peter Crosthwaite peter.crosthwa...@xilinx.com wrote:

 On Fri, Dec 20, 2013 at 10:49 AM, Anthony Liguori anth...@codemonkey.ws 
 wrote:
  On Wed, Dec 18, 2013 at 8:59 AM, Luiz Capitulino lcapitul...@redhat.com 
  wrote:
  The following changes since commit 
  e157b8fdd412d48eacfbb8c67d3d58780154faa3:
 
Merge remote-tracking branch 'bonzini/virtio' into staging (2013-12-13 
  11:10:33 -0800)
 
  are available in the git repository at:
 
  Sorry, you lost the merge conflict to Peter.  Can you please rebase
  and resubmit?

Sure, no problem.

 Sorry - this one is my fault.

Peter, can you resend your series then?



Re: [Qemu-devel] [PATCH] test: QOM interface casting

2013-12-20 Thread Peter Maydell
On 20 December 2013 13:26, Igor Mammedov imamm...@redhat.com wrote:
 Add basic regression testing for QOM Interface usage.

 +/*
 + * OQM interface test.

Still says OQM not QOM...

thanks
-- PMM



Re: [Qemu-devel] [PULL 11/13] monitor: add object-add (QMP) and object_add (HMP) command

2013-12-20 Thread Luiz Capitulino
On Fri, 20 Dec 2013 12:15:53 +1000
Peter Crosthwaite peter.crosthwa...@xilinx.com wrote:

 On Thu, Dec 19, 2013 at 3:00 AM, Luiz Capitulino lcapitul...@redhat.com 
 wrote:
  From: Paolo Bonzini pbonz...@redhat.com
 
  Add two commands that are the monitor counterparts of -object.  The commands
  have the same Visitor-based implementation, but use different kinds of
  visitors so that the HMP command has a DWIM string-based syntax, while
  the QMP variant accepts a stricter JSON-based properties dictionary.
 
  Signed-off-by: Paolo Bonzini pbonz...@redhat.com
  Reviewed-By: Igor Mammedov imamm...@redhat.com
  Signed-off-by: Luiz Capitulino lcapitul...@redhat.com
  ---
   hmp-commands.hx   | 14 +++
   hmp.c | 58 
   hmp.h |  1 +
   include/monitor/monitor.h |  3 +++
   include/qapi/visitor.h|  3 +--
   include/qemu/typedefs.h   |  2 ++
   qapi-schema.json  | 20 +++
   qmp-commands.hx   | 27 +
   qmp.c | 62 
  +++
   9 files changed, 188 insertions(+), 2 deletions(-)
 
  diff --git a/hmp-commands.hx b/hmp-commands.hx
  index ebe8e78..2951d1e 100644
  --- a/hmp-commands.hx
  +++ b/hmp-commands.hx
  @@ -1243,6 +1243,20 @@ STEXI
   Remove host network device.
   ETEXI
 
  +{
  +.name   = object_add,
  +.args_type  = object:O,
  +.params = [qom-type=]type,id=str[,prop=value][,...],
  +.help   = create QOM object,
  +.mhandler.cmd = hmp_object_add,
  +},
  +
  +STEXI
  +@item object_add
  +@findex object_add
  +Create QOM object.
  +ETEXI
  +
   #ifdef CONFIG_SLIRP
   {
   .name   = hostfwd_add,
  diff --git a/hmp.c b/hmp.c
  index 32ee285..a1669ab 100644
  --- a/hmp.c
  +++ b/hmp.c
  @@ -21,6 +21,7 @@
   #include qmp-commands.h
   #include qemu/sockets.h
   #include monitor/monitor.h
  +#include qapi/opts-visitor.h
   #include ui/console.h
   #include block/qapi.h
   #include qemu-io.h
  @@ -1354,6 +1355,63 @@ void hmp_netdev_del(Monitor *mon, const QDict *qdict)
   hmp_handle_error(mon, err);
   }
 
  +void hmp_object_add(Monitor *mon, const QDict *qdict)
  +{
  +Error *err = NULL;
  +QemuOpts *opts;
  +char *type = NULL;
  +char *id = NULL;
  +void *dummy = NULL;
  +OptsVisitor *ov;
  +QDict *pdict;
  +
  +opts = qemu_opts_from_qdict(qemu_find_opts(object), qdict, err);
  +if (error_is_set(err)) {
  +goto out;
  +}
  +
  +ov = opts_visitor_new(opts);
  +pdict = qdict_clone_shallow(qdict);
  +
  +visit_start_struct(opts_get_visitor(ov), dummy, NULL, NULL, 0, err);
  +if (error_is_set(err)) {
  +goto out_clean;
  +}
  +
  +qdict_del(pdict, qom-type);
  +visit_type_str(opts_get_visitor(ov), type, qom-type, err);
  +if (error_is_set(err)) {
  +goto out_clean;
  +}
  +
  +qdict_del(pdict, id);
  +visit_type_str(opts_get_visitor(ov), id, id, err);
  +if (error_is_set(err)) {
  +goto out_clean;
  +}
  +
  +object_add(type, id, pdict, opts_get_visitor(ov), err);
  +if (error_is_set(err)) {
  +goto out_clean;
  +}
  +visit_end_struct(opts_get_visitor(ov), err);
  +if (error_is_set(err)) {
  +qmp_object_del(id, NULL);
 
 This is not bisect-able as you add this function in the next commit:

Thanks for catching it. This was a bad pull request.

Paolo, can resend?



Re: [Qemu-devel] [PATCH V7 2/6] qcow2: add error message in qcow2_write_snapshots()

2013-12-20 Thread Stefan Hajnoczi
On Thu, Dec 05, 2013 at 08:02:48PM +0800, Wenchao Xia wrote:
 @@ -227,24 +236,40 @@ static int qcow2_write_snapshots(BlockDriverState *bs)
  
  ret = bdrv_pwrite(bs-file, offset, h, sizeof(h));
  if (ret  0) {
 +error_setg_errno(errp, -ret,
 + Failed in write of snapshot header at %
 + PRIi64  with size %d,
 + offset, (int)sizeof(h));

The casts in this patch are not necessary:
size_t == %zu
ssize_t == %zd

(Very minor point but in case you respin)



Re: [Qemu-devel] [PATCHv2] block: add native support for NFS

2013-12-20 Thread Stefan Hajnoczi
On Fri, Dec 20, 2013 at 1:53 PM, Peter Lieven p...@kamp.de wrote:
 On 20.12.2013 13:19, Stefan Hajnoczi wrote:

 On Fri, Dec 20, 2013 at 10:48:41AM +0100, Peter Lieven wrote:

 On 17.12.2013 17:47, Stefan Hajnoczi wrote:

 On Tue, Dec 17, 2013 at 10:15:25AM +0100, Peter Lieven wrote:
 +/* set to -ENOTSUP since bdrv_allocated_file_size is only used
 + * in qemu-img open. So we can use the cached value for allocate
 + * filesize obtained from fstat at open time */
 +client-allocated_file_size = -ENOTSUP;

 Can you implement this fully?  By stubbing it out like this we won't be
 able to call get_allocated_file_size() at runtime in the future without
 updating the nfs block driver code.  It's just an fstat call, shouldn't
 be too hard to implement properly :).

 It seems I have to leave it as is currently. bdrv_get_allocated_file_size
 is not in a coroutine context. I get coroutine yields to no one.

 Create a coroutine and pump the event loop until it has reached
 completion:

 co = qemu_coroutine_create(my_coroutine_fn, ...);
 qemu_coroutine_enter(co, foo);
 while (!complete) {
  qemu_aio_wait();
 }

 See block.c for similar examples.

 Wouldn't it make sense to make this modification to
 bdrv_get_allocated_file_size in
 block.c rather than in client/nfs.c and in the future potentially other
 drivers?

 If yes, I would ask you to take v3 of the NFS protocol patch and I promise
 to send
 a follow up early next year to make this modification to block.c and change
 block/nfs.c
 and other implementations to be a coroutine_fn.

.bdrv_get_allocated_file_size() implementations in other block drivers
are synchronous.  Making the block driver interface use coroutines
would be wrong unless all the block drivers were updated to use
coroutines too.

Can you just call nfs_fstat() (the sync libnfs interface)?

Stefan



Re: [Qemu-devel] [PATCH] test: QOM interface casting

2013-12-20 Thread Andreas Färber
Am 20.12.2013 14:26, schrieb Igor Mammedov:
 Add basic regression testing for QOM Interface usage.
 
 Signed-off-by: Igor Mammedov imamm...@redhat.com
 ---
 v2:
  - Peter Crosthwaite peter.crosthwa...@xilinx.com
* s/Parent/parent_obj/
* s/parent/parent_class/
  - Peter Maydell peter.mayd...@linaro.org
* s/interfacei/interface/
* tests/Makefile split too long line
  - Andreas Färber afaer...@suse.de
* consolidate QOM core object files in dedicated variable
* add SoB and commit message
 ---
  tests/Makefile  |6 ++-
  tests/check-qom-interface.c |  102 
 +++
  2 files changed, 107 insertions(+), 1 deletions(-)
  create mode 100644 tests/check-qom-interface.c
 
 diff --git a/tests/Makefile b/tests/Makefile
 index 379cdd9..89f8eff 100644
 --- a/tests/Makefile
 +++ b/tests/Makefile
 @@ -52,6 +52,8 @@ check-unit-y += tests/test-int128$(EXESUF)
  gcov-files-test-int128-y =
  check-unit-y += tests/test-bitops$(EXESUF)
  check-unit-y += tests/test-qdev-global-props$(EXESUF)
 +check-unit-y = tests/check-qom-interface$(EXESUF)

Surely needs to be +=.

 +gcov-files-check-qdict-y = object/object.c

Copypaste? (qdict)
Also qom/object.c.

  
  check-block-$(CONFIG_POSIX) += tests/qemu-iotests-quick.sh
  
 @@ -137,6 +139,7 @@ test-qapi-obj-y = tests/test-qapi-visit.o 
 tests/test-qapi-types.o
  
  $(test-obj-y): QEMU_INCLUDES += -Itests
  QEMU_CFLAGS += -I$(SRC_PATH)/tests
 +qom-core-obj = qom/object.o qom/qom-qobject.o qom/container.o
  
  tests/test-x86-cpuid.o: QEMU_INCLUDES += -I$(SRC_PATH)/target-i386
  
 @@ -146,6 +149,7 @@ tests/check-qdict$(EXESUF): tests/check-qdict.o 
 libqemuutil.a
  tests/check-qlist$(EXESUF): tests/check-qlist.o libqemuutil.a
  tests/check-qfloat$(EXESUF): tests/check-qfloat.o libqemuutil.a
  tests/check-qjson$(EXESUF): tests/check-qjson.o libqemuutil.a libqemustub.a
 +tests/check-qom-interface$(EXESUF): tests/check-qom-interface.o 
 $(qom-core-obj) libqemuutil.a
  tests/test-coroutine$(EXESUF): tests/test-coroutine.o $(block-obj-y) 
 libqemuutil.a libqemustub.a
  tests/test-aio$(EXESUF): tests/test-aio.o $(block-obj-y) libqemuutil.a 
 libqemustub.a
  tests/test-throttle$(EXESUF): tests/test-throttle.o $(block-obj-y) 
 libqemuutil.a libqemustub.a
 @@ -159,7 +163,7 @@ tests/test-int128$(EXESUF): tests/test-int128.o
  tests/test-qdev-global-props$(EXESUF): tests/test-qdev-global-props.o \
   hw/core/qdev.o hw/core/qdev-properties.o \
   hw/core/irq.o \
 - qom/object.o qom/container.o qom/qom-qobject.o \
 + $(qom-core-obj) \
   $(test-qapi-obj-y) \
   libqemuutil.a libqemustub.a
  
 diff --git a/tests/check-qom-interface.c b/tests/check-qom-interface.c
 new file mode 100644
 index 000..8d7c1f8
 --- /dev/null
 +++ b/tests/check-qom-interface.c
 @@ -0,0 +1,102 @@
 +/*
 + * OQM interface test.
 + *
 + * Copyright (C) 2013 Red Hat Inc.
 + *
 + * Authors:
 + *  Igor Mammedov imamm...@redhat.com
 + *
 + * This work is licensed under the terms of the GNU LGPL, version 2.1 or 
 later.
 + * See the COPYING.LIB file in the top-level directory.
 + */
 +#include glib.h
 +
 +#include qom/object.h
 +#include qemu/module.h
 +
 +
 +#define TYPE_TEST_IF test-interface
 +#define TEST_IF_CLASS(klass) \
 + OBJECT_CLASS_CHECK(TestIfClass, (klass), TYPE_TEST_IF)
 +#define TEST_IF_GET_CLASS(obj) \
 + OBJECT_GET_CLASS(TestIfClass, (obj), TYPE_TEST_IF)
 +#define TEST_IF(obj) \
 + INTERFACE_CHECK(TestIf, (obj), TYPE_TEST_IF)
 +
 +typedef struct TestIf {
 +Object parent_obj;
 +} TestIf;
 +
 +typedef struct TestIfClass {
 +InterfaceClass parent_class;
 +
 +uint32_t test;
 +} TestIfClass;
 +
 +static const TypeInfo test_if_info = {
 +.name  = TYPE_TEST_IF,
 +.parent= TYPE_INTERFACE,

TestIf is not assigned here - no bug but let's set a consistent example.

 +.class_size = sizeof(TestIfClass),
 +};
 +
 +#define PATTERN 0xFAFBFCFD
 +static void test_class_init(ObjectClass *oc, void *data)
 +{
 +TestIfClass *tc = TEST_IF_CLASS(oc);
 +
 +g_assert(tc);
 +tc-test = PATTERN;
 +}
 +
 +#define TYPE_DIRECT_IMPL direct-impl
 +static const TypeInfo direct_impl_info = {
 +.name = TYPE_DIRECT_IMPL,
 +.parent = TYPE_OBJECT,
 +.class_init = test_class_init,
 +.interfaces = (InterfaceInfo[]) {
 +{ TYPE_TEST_IF },
 +{ }
 +}
 +};
 +
 +#define TYPE_INTERMEDIATE_IMPL intermediate-impl

I'd insert a white line here and above.

 +static const TypeInfo intermediate_impl_info = {
 +.name = TYPE_INTERMEDIATE_IMPL,
 +.parent = TYPE_DIRECT_IMPL,
 +};
 +
 +static void test_interface_impl(const char *type)
 +{
 +Object *obj = object_new(type);
 +TestIf *iobj = TEST_IF(obj);
 +TestIfClass *ico = TEST_IF_GET_CLASS(iobj);

What's the o in ico for BTW?

 +
 +g_assert(iobj);
 +g_assert(ico-test == PATTERN);
 +}
 +
 +static void interface_direct_test(void)
 +{
 +test_interface_impl(TYPE_DIRECT_IMPL);
 +}
 +
 +static void 

Re: [Qemu-devel] [PATCHv2] block: add native support for NFS

2013-12-20 Thread Peter Lieven

On 20.12.2013 14:57, Stefan Hajnoczi wrote:

On Fri, Dec 20, 2013 at 1:53 PM, Peter Lieven p...@kamp.de wrote:

On 20.12.2013 13:19, Stefan Hajnoczi wrote:

On Fri, Dec 20, 2013 at 10:48:41AM +0100, Peter Lieven wrote:

On 17.12.2013 17:47, Stefan Hajnoczi wrote:

On Tue, Dec 17, 2013 at 10:15:25AM +0100, Peter Lieven wrote:

+/* set to -ENOTSUP since bdrv_allocated_file_size is only used
+ * in qemu-img open. So we can use the cached value for allocate
+ * filesize obtained from fstat at open time */
+client-allocated_file_size = -ENOTSUP;

Can you implement this fully?  By stubbing it out like this we won't be
able to call get_allocated_file_size() at runtime in the future without
updating the nfs block driver code.  It's just an fstat call, shouldn't
be too hard to implement properly :).

It seems I have to leave it as is currently. bdrv_get_allocated_file_size
is not in a coroutine context. I get coroutine yields to no one.

Create a coroutine and pump the event loop until it has reached
completion:

co = qemu_coroutine_create(my_coroutine_fn, ...);
qemu_coroutine_enter(co, foo);
while (!complete) {
  qemu_aio_wait();
}

See block.c for similar examples.

Wouldn't it make sense to make this modification to
bdrv_get_allocated_file_size in
block.c rather than in client/nfs.c and in the future potentially other
drivers?

If yes, I would ask you to take v3 of the NFS protocol patch and I promise
to send
a follow up early next year to make this modification to block.c and change
block/nfs.c
and other implementations to be a coroutine_fn.

.bdrv_get_allocated_file_size() implementations in other block drivers
are synchronous.  Making the block driver interface use coroutines
would be wrong unless all the block drivers were updated to use
coroutines too.

I can do that. I think its not too complicated because all those
implementations do not rely on callbacks. It should be possible
to just rename the existing implemenations to lets say
.bdrv_co_get_allocated_file_size and call them inside a coroutine.


Can you just call nfs_fstat() (the sync libnfs interface)?

I can only do that if its guaranteed that no other requests are in flight
otherwise it will mess up.

Peter




Re: [Qemu-devel] [PATCH] test: QOM interface casting

2013-12-20 Thread Igor Mammedov
On Fri, 20 Dec 2013 14:58:07 +0100
Andreas Färber afaer...@suse.de wrote:

 Am 20.12.2013 14:26, schrieb Igor Mammedov:
  Add basic regression testing for QOM Interface usage.
  
  Signed-off-by: Igor Mammedov imamm...@redhat.com
  ---
  v2:
   - Peter Crosthwaite peter.crosthwa...@xilinx.com
 * s/Parent/parent_obj/
 * s/parent/parent_class/
   - Peter Maydell peter.mayd...@linaro.org
 * s/interfacei/interface/
 * tests/Makefile split too long line
   - Andreas Färber afaer...@suse.de
 * consolidate QOM core object files in dedicated variable
 * add SoB and commit message
  ---
   tests/Makefile  |6 ++-
   tests/check-qom-interface.c |  102 
  +++
   2 files changed, 107 insertions(+), 1 deletions(-)
   create mode 100644 tests/check-qom-interface.c
  
  diff --git a/tests/Makefile b/tests/Makefile
  index 379cdd9..89f8eff 100644
  --- a/tests/Makefile
  +++ b/tests/Makefile
  @@ -52,6 +52,8 @@ check-unit-y += tests/test-int128$(EXESUF)
   gcov-files-test-int128-y =
   check-unit-y += tests/test-bitops$(EXESUF)
   check-unit-y += tests/test-qdev-global-props$(EXESUF)
  +check-unit-y = tests/check-qom-interface$(EXESUF)
 
 Surely needs to be +=.
fixed.
 
  +gcov-files-check-qdict-y = object/object.c
 
 Copypaste? (qdict)
 Also qom/object.c.
fixed

 
   
   check-block-$(CONFIG_POSIX) += tests/qemu-iotests-quick.sh
   
  @@ -137,6 +139,7 @@ test-qapi-obj-y = tests/test-qapi-visit.o 
  tests/test-qapi-types.o
   
   $(test-obj-y): QEMU_INCLUDES += -Itests
   QEMU_CFLAGS += -I$(SRC_PATH)/tests
  +qom-core-obj = qom/object.o qom/qom-qobject.o qom/container.o
   
   tests/test-x86-cpuid.o: QEMU_INCLUDES += -I$(SRC_PATH)/target-i386
   
  @@ -146,6 +149,7 @@ tests/check-qdict$(EXESUF): tests/check-qdict.o 
  libqemuutil.a
   tests/check-qlist$(EXESUF): tests/check-qlist.o libqemuutil.a
   tests/check-qfloat$(EXESUF): tests/check-qfloat.o libqemuutil.a
   tests/check-qjson$(EXESUF): tests/check-qjson.o libqemuutil.a libqemustub.a
  +tests/check-qom-interface$(EXESUF): tests/check-qom-interface.o 
  $(qom-core-obj) libqemuutil.a
   tests/test-coroutine$(EXESUF): tests/test-coroutine.o $(block-obj-y) 
  libqemuutil.a libqemustub.a
   tests/test-aio$(EXESUF): tests/test-aio.o $(block-obj-y) libqemuutil.a 
  libqemustub.a
   tests/test-throttle$(EXESUF): tests/test-throttle.o $(block-obj-y) 
  libqemuutil.a libqemustub.a
  @@ -159,7 +163,7 @@ tests/test-int128$(EXESUF): tests/test-int128.o
   tests/test-qdev-global-props$(EXESUF): tests/test-qdev-global-props.o \
  hw/core/qdev.o hw/core/qdev-properties.o \
  hw/core/irq.o \
  -   qom/object.o qom/container.o qom/qom-qobject.o \
  +   $(qom-core-obj) \
  $(test-qapi-obj-y) \
  libqemuutil.a libqemustub.a
   
  diff --git a/tests/check-qom-interface.c b/tests/check-qom-interface.c
  new file mode 100644
  index 000..8d7c1f8
  --- /dev/null
  +++ b/tests/check-qom-interface.c
  @@ -0,0 +1,102 @@
  +/*
  + * OQM interface test.
  + *
  + * Copyright (C) 2013 Red Hat Inc.
  + *
  + * Authors:
  + *  Igor Mammedov imamm...@redhat.com
  + *
  + * This work is licensed under the terms of the GNU LGPL, version 2.1 or 
  later.
  + * See the COPYING.LIB file in the top-level directory.
  + */
  +#include glib.h
  +
  +#include qom/object.h
  +#include qemu/module.h
  +
  +
  +#define TYPE_TEST_IF test-interface
  +#define TEST_IF_CLASS(klass) \
  + OBJECT_CLASS_CHECK(TestIfClass, (klass), TYPE_TEST_IF)
  +#define TEST_IF_GET_CLASS(obj) \
  + OBJECT_GET_CLASS(TestIfClass, (obj), TYPE_TEST_IF)
  +#define TEST_IF(obj) \
  + INTERFACE_CHECK(TestIf, (obj), TYPE_TEST_IF)
  +
  +typedef struct TestIf {
  +Object parent_obj;
  +} TestIf;
  +
  +typedef struct TestIfClass {
  +InterfaceClass parent_class;
  +
  +uint32_t test;
  +} TestIfClass;
  +
  +static const TypeInfo test_if_info = {
  +.name  = TYPE_TEST_IF,
  +.parent= TYPE_INTERFACE,
 
 TestIf is not assigned here - no bug but let's set a consistent example.
What do you mean?

 
  +.class_size = sizeof(TestIfClass),
  +};
  +
  +#define PATTERN 0xFAFBFCFD
  +static void test_class_init(ObjectClass *oc, void *data)
  +{
  +TestIfClass *tc = TEST_IF_CLASS(oc);
  +
  +g_assert(tc);
  +tc-test = PATTERN;
  +}
  +
  +#define TYPE_DIRECT_IMPL direct-impl
  +static const TypeInfo direct_impl_info = {
  +.name = TYPE_DIRECT_IMPL,
  +.parent = TYPE_OBJECT,
  +.class_init = test_class_init,
  +.interfaces = (InterfaceInfo[]) {
  +{ TYPE_TEST_IF },
  +{ }
  +}
  +};
  +
  +#define TYPE_INTERMEDIATE_IMPL intermediate-impl
 
 I'd insert a white line here and above.
sure

 
  +static const TypeInfo intermediate_impl_info = {
  +.name = TYPE_INTERMEDIATE_IMPL,
  +.parent = TYPE_DIRECT_IMPL,
  +};
  +
  +static void test_interface_impl(const char *type)
  +{
  +Object *obj = object_new(type);
  +TestIf *iobj = TEST_IF(obj);
  +   

Re: [Qemu-devel] [PATCH 07/21] target-arm: A64: add support for 3 src data proc insns

2013-12-20 Thread Richard Henderson
On 12/20/2013 05:18 AM, Peter Maydell wrote:
 On 19 December 2013 19:29, Richard Henderson r...@twiddle.net wrote:
 On 12/17/2013 07:12 AM, Peter Maydell wrote:
 +tcg_gen_mul_i64(tcg_tmp, tcg_op1, tcg_op2);
 +if (is_sub) {
 +tcg_gen_sub_i64(cpu_reg(s, rd), cpu_reg(s, ra), tcg_tmp);
 +} else {
 +tcg_gen_add_i64(cpu_reg(s, rd), cpu_reg(s, ra), tcg_tmp);
 +}

 Perhaps worth noticing the RA=XZR special case for the MUL alias?
 
 Yeah, makes sense: have adjusted to:
 +if (ra == 31) {
 +/* We special-case rA == XZR as it is the standard MUL alias */
 +tcg_gen_mul_i64(cpu_reg(s, rd), tcg_op1, tcg_op2);
 +} else {

You need to handle (or dismiss) is_sub.

Either (ra == 31  !is_sub) or

   if (is_sub) {
   tcg_gen_neg_i64(tcg_rd, tcg_rd);
   }

with tcg_rd pre-loaded along with tcg_op1 and tcg_op2.

That said, unlike MUL I don't expect MNEG to be common at all.

 +tcg_gen_mul_i64(tcg_tmp, tcg_op1, tcg_op2);
 +if (is_sub) {
 +tcg_gen_sub_i64(cpu_reg(s, rd), cpu_reg(s, ra), tcg_tmp);
 +} else {
 +tcg_gen_add_i64(cpu_reg(s, rd), cpu_reg(s, ra), tcg_tmp);
 +}
 +}


r~



[Qemu-devel] [PATCH v4 2/7] Decouple vhost from kernel interface

2013-12-20 Thread Mian M. Hamayun
From: Antonios Motakis a.mota...@virtualopensystems.com

We introduce the concept of vhost-backend, which can be either vhost-kernel
or vhost-user. The existing vhost interface to the kernel is abstracted
behind the vhost-kernel backend.

We replace all direct ioctls to the kernel with a vhost_call to the backend.
vhost dev-control is referenced only in the vhost-backend (ioctl, open, close).

Signed-off-by: Antonios Motakis a.mota...@virtualopensystems.com
Signed-off-by: Nikolay Nikolaev n.nikol...@virtualopensystems.com
---
 hw/net/vhost_net.c| 13 +---
 hw/scsi/vhost-scsi.c  | 13 +---
 hw/virtio/Makefile.objs   |  2 +-
 hw/virtio/vhost-backend.c | 64 +++
 hw/virtio/vhost.c | 47 ++--
 include/hw/virtio/vhost-backend.h | 37 ++
 include/hw/virtio/vhost.h |  4 ++-
 7 files changed, 147 insertions(+), 33 deletions(-)
 create mode 100644 hw/virtio/vhost-backend.c
 create mode 100644 include/hw/virtio/vhost-backend.h

diff --git a/hw/net/vhost_net.c b/hw/net/vhost_net.c
index 006576d..4aaf0b4 100644
--- a/hw/net/vhost_net.c
+++ b/hw/net/vhost_net.c
@@ -27,7 +27,6 @@
 #include sys/socket.h
 #include linux/kvm.h
 #include fcntl.h
-#include sys/ioctl.h
 #include linux/virtio_ring.h
 #include netpacket/packet.h
 #include net/ethernet.h
@@ -113,7 +112,8 @@ struct vhost_net *vhost_net_init(NetClientState *backend, 
int devfd,
 net-dev.nvqs = 2;
 net-dev.vqs = net-vqs;
 
-r = vhost_dev_init(net-dev, devfd, /dev/vhost-net, force);
+r = vhost_dev_init(net-dev, devfd, /dev/vhost-net,
+   VHOST_BACKEND_TYPE_KERNEL, force);
 if (r  0) {
 goto fail;
 }
@@ -170,7 +170,8 @@ static int vhost_net_start_one(struct vhost_net *net,
 qemu_set_fd_handler(net-backend, NULL, NULL, NULL);
 file.fd = net-backend;
 for (file.index = 0; file.index  net-dev.nvqs; ++file.index) {
-r = ioctl(net-dev.control, VHOST_NET_SET_BACKEND, file);
+const VhostOps *vhost_ops = net-dev.vhost_ops;
+r = vhost_ops-vhost_call(net-dev, VHOST_NET_SET_BACKEND, file);
 if (r  0) {
 r = -errno;
 goto fail;
@@ -180,7 +181,8 @@ static int vhost_net_start_one(struct vhost_net *net,
 fail:
 file.fd = -1;
 while (file.index--  0) {
-int r = ioctl(net-dev.control, VHOST_NET_SET_BACKEND, file);
+const VhostOps *vhost_ops = net-dev.vhost_ops;
+int r = vhost_ops-vhost_call(net-dev, VHOST_NET_SET_BACKEND, file);
 assert(r = 0);
 }
 net-nc-info-poll(net-nc, true);
@@ -201,7 +203,8 @@ static void vhost_net_stop_one(struct vhost_net *net,
 }
 
 for (file.index = 0; file.index  net-dev.nvqs; ++file.index) {
-int r = ioctl(net-dev.control, VHOST_NET_SET_BACKEND, file);
+const VhostOps *vhost_ops = net-dev.vhost_ops;
+int r = vhost_ops-vhost_call(net-dev, VHOST_NET_SET_BACKEND, file);
 assert(r = 0);
 }
 net-nc-info-poll(net-nc, true);
diff --git a/hw/scsi/vhost-scsi.c b/hw/scsi/vhost-scsi.c
index 3983a5b..3faff65 100644
--- a/hw/scsi/vhost-scsi.c
+++ b/hw/scsi/vhost-scsi.c
@@ -27,12 +27,13 @@
 static int vhost_scsi_set_endpoint(VHostSCSI *s)
 {
 VirtIOSCSICommon *vs = VIRTIO_SCSI_COMMON(s);
+const VhostOps *vhost_ops = s-dev.vhost_ops;
 struct vhost_scsi_target backend;
 int ret;
 
 memset(backend, 0, sizeof(backend));
 pstrcpy(backend.vhost_wwpn, sizeof(backend.vhost_wwpn), vs-conf.wwpn);
-ret = ioctl(s-dev.control, VHOST_SCSI_SET_ENDPOINT, backend);
+ret = vhost_ops-vhost_call(s-dev, VHOST_SCSI_SET_ENDPOINT, backend);
 if (ret  0) {
 return -errno;
 }
@@ -43,10 +44,11 @@ static void vhost_scsi_clear_endpoint(VHostSCSI *s)
 {
 VirtIOSCSICommon *vs = VIRTIO_SCSI_COMMON(s);
 struct vhost_scsi_target backend;
+const VhostOps *vhost_ops = s-dev.vhost_ops;
 
 memset(backend, 0, sizeof(backend));
 pstrcpy(backend.vhost_wwpn, sizeof(backend.vhost_wwpn), vs-conf.wwpn);
-ioctl(s-dev.control, VHOST_SCSI_CLEAR_ENDPOINT, backend);
+vhost_ops-vhost_call(s-dev, VHOST_SCSI_CLEAR_ENDPOINT, backend);
 }
 
 static int vhost_scsi_start(VHostSCSI *s)
@@ -55,13 +57,15 @@ static int vhost_scsi_start(VHostSCSI *s)
 VirtIODevice *vdev = VIRTIO_DEVICE(s);
 BusState *qbus = BUS(qdev_get_parent_bus(DEVICE(vdev)));
 VirtioBusClass *k = VIRTIO_BUS_GET_CLASS(qbus);
+const VhostOps *vhost_ops = s-dev.vhost_ops;
 
 if (!k-set_guest_notifiers) {
 error_report(binding does not support guest notifiers);
 return -ENOSYS;
 }
 
-ret = ioctl(s-dev.control, VHOST_SCSI_GET_ABI_VERSION, abi_version);
+ret = vhost_ops-vhost_call(s-dev,
+VHOST_SCSI_GET_ABI_VERSION, abi_version);
 if (ret  0) {
 return -errno;
 }
@@ -227,7 +231,8 @@ static void vhost_scsi_realize(DeviceState *dev, 

[Qemu-devel] [PATCH v4 0/7] Vhost and vhost-net support for userspace based backends

2013-12-20 Thread Mian M. Hamayun
From: Mian M. Hamayun m.hama...@virtualopensystems.com

In this patch series we would like to introduce our approach for putting a
virtio-net backend in an external userspace process. Our eventual target is to
run the network backend in the Snabbswitch ethernet switch, while receiving
traffic from a guest inside QEMU/KVM which runs an unmodified virtio-net
implementation.

For this, we are working into extending vhost to allow equivalent functionality
for userspace. Vhost already passes control of the data plane of virtio-net to
the host kernel; we want to realize a similar model, but for userspace.

In this patch series the concept of a vhost-backend is introduced.

We define two vhost backend types - vhost-kernel and vhost-user. The former is
the interface to the current kernel module implementation. Its control plane is
ioctl based. The data plane is the kernel directly accessing the QEMU allocated,
guest memory.

In the new vhost-user backend, the control plane is based on communication
between QEMU and another userspace process using a unix domain socket. This
allows to implement a virtio backend for a guest running in QEMU, inside the
other userspace process.

We change -mem-path to QemuOpts and add prealloc, share and unlink as properties
to it. HugeTLBFS requirements of -mem-path are relaxed, so any valid path can
be used now. The new properties allow more fine grained control over the guest
RAM backing store.

The data path is realized by directly accessing the vrings and the buffer data
off the guest's memory.

The current user of vhost-user is only vhost-net. We add new netdev backend
that is intended to initialize vhost-net with vhost-user backend.

Example usage:

qemu -m 1024 -mem-path /hugetlbfs,prealloc=on,share=on \
 -netdev type=vhost-user,id=net0,file=/path/to/sock \
 -device virtio-net-pci,netdev=net0

Changes from v3:
 - Convert -mem-path to QemuOpts with prealloc, share and unlink properties
 - Set 1 sec timeout when read/write to the unix domain socket
 - Fix file descriptor leak

Changes from v2:
 - Reconnect when the backend disappears

Changes from v1:
 - Implementation of vhost-user netdev backend
 - Code improvements

Antonios Motakis (7):
  Convert -mem-path to QemuOpts and add prealloc,share and unlink
properties
  Decouple vhost from kernel interface
  Add vhost-user skeleton
  Add domain socket communication for vhost-user backend
  Add vhost-user calls implementation
  Add new vhost-user netdev backend
  Add vhost-user reconnection

 exec.c|  57 +-
 hmp-commands.hx   |   4 +-
 hw/net/vhost_net.c| 144 ++
 hw/net/virtio-net.c   |  42 ++--
 hw/scsi/vhost-scsi.c  |  13 +-
 hw/virtio/Makefile.objs   |   2 +-
 hw/virtio/vhost-backend.c | 409 ++
 hw/virtio/vhost.c |  46 +++--
 include/exec/cpu-all.h|   3 -
 include/hw/virtio/vhost-backend.h |  40 
 include/hw/virtio/vhost.h |   4 +-
 include/net/vhost-user.h  |  17 ++
 include/net/vhost_net.h   |  15 +-
 net/Makefile.objs |   2 +-
 net/clients.h |   3 +
 net/hub.c |   1 +
 net/net.c |   2 +
 net/tap.c |  16 +-
 net/vhost-user.c  | 167 
 qapi-schema.json  |  18 +-
 qemu-options.hx   |  13 +-
 vl.c  |  41 +++-
 22 files changed, 935 insertions(+), 124 deletions(-)
 create mode 100644 hw/virtio/vhost-backend.c
 create mode 100644 include/hw/virtio/vhost-backend.h
 create mode 100644 include/net/vhost-user.h
 create mode 100644 net/vhost-user.c

-- 
1.8.3.2




[Qemu-devel] [PATCH v4 6/7] Add new vhost-user netdev backend

2013-12-20 Thread Mian M. Hamayun
From: Antonios Motakis a.mota...@virtualopensystems.com

Add a new QEMU netdev backend that is intended to invoke vhost_net
with the vhost-user backend. Also decouple virtio-net from the tap
backend.

Signed-off-by: Antonios Motakis a.mota...@virtualopensystems.com
Signed-off-by: Nikolay Nikolaev n.nikol...@virtualopensystems.com
---
 hmp-commands.hx  |   4 +-
 hw/net/vhost_net.c   |  66 ++--
 hw/net/virtio-net.c  |  42 --
 hw/virtio/vhost.c|   1 -
 include/net/vhost-user.h |  17 
 include/net/vhost_net.h  |   1 +
 net/Makefile.objs|   2 +-
 net/clients.h|   3 ++
 net/hub.c|   1 +
 net/net.c|   2 +
 net/vhost-user.c | 111 +++
 qapi-schema.json |  18 +++-
 qemu-options.hx  |   3 ++
 13 files changed, 227 insertions(+), 44 deletions(-)
 create mode 100644 include/net/vhost-user.h
 create mode 100644 net/vhost-user.c

diff --git a/hmp-commands.hx b/hmp-commands.hx
index ebe8e78..d5a3774 100644
--- a/hmp-commands.hx
+++ b/hmp-commands.hx
@@ -1190,7 +1190,7 @@ ETEXI
 {
 .name   = host_net_add,
 .args_type  = device:s,opts:s?,
-.params = tap|user|socket|vde|netmap|dump [options],
+.params = tap|user|socket|vde|netmap|vhost-user|dump [options],
 .help   = add host VLAN client,
 .mhandler.cmd = net_host_device_add,
 },
@@ -1218,7 +1218,7 @@ ETEXI
 {
 .name   = netdev_add,
 .args_type  = netdev:O,
-.params = 
[user|tap|socket|hubport|netmap],id=str[,prop=value][,...],
+.params = 
[user|tap|socket|hubport|netmap|vhost-user],id=str[,prop=value][,...],
 .help   = add host network device,
 .mhandler.cmd = hmp_netdev_add,
 },
diff --git a/hw/net/vhost_net.c b/hw/net/vhost_net.c
index 3614e6c..e42f4d6 100644
--- a/hw/net/vhost_net.c
+++ b/hw/net/vhost_net.c
@@ -15,6 +15,7 @@
 
 #include net/net.h
 #include net/tap.h
+#include net/vhost-user.h
 
 #include hw/virtio/virtio-net.h
 #include net/vhost_net.h
@@ -174,15 +175,20 @@ static int vhost_net_start_one(struct vhost_net *net,
 goto fail_start;
 }
 
-net-nc-info-poll(net-nc, false);
-qemu_set_fd_handler(net-backend, NULL, NULL, NULL);
-file.fd = net-backend;
-for (file.index = 0; file.index  net-dev.nvqs; ++file.index) {
-const VhostOps *vhost_ops = net-dev.vhost_ops;
-r = vhost_ops-vhost_call(net-dev, VHOST_NET_SET_BACKEND, file);
-if (r  0) {
-r = -errno;
-goto fail;
+if (net-nc-info-poll) {
+net-nc-info-poll(net-nc, false);
+}
+
+if (net-nc-info-type == NET_CLIENT_OPTIONS_KIND_TAP) {
+qemu_set_fd_handler(net-backend, NULL, NULL, NULL);
+file.fd = net-backend;
+for (file.index = 0; file.index  net-dev.nvqs; ++file.index) {
+const VhostOps *vhost_ops = net-dev.vhost_ops;
+r = vhost_ops-vhost_call(net-dev, VHOST_NET_SET_BACKEND, file);
+if (r  0) {
+r = -errno;
+goto fail;
+}
 }
 }
 return 0;
@@ -193,7 +199,9 @@ fail:
 int r = vhost_ops-vhost_call(net-dev, VHOST_NET_SET_BACKEND, file);
 assert(r = 0);
 }
-net-nc-info-poll(net-nc, true);
+if (net-nc-info-poll) {
+net-nc-info-poll(net-nc, true);
+}
 vhost_dev_stop(net-dev, dev);
 fail_start:
 vhost_dev_disable_notifiers(net-dev, dev);
@@ -215,7 +223,9 @@ static void vhost_net_stop_one(struct vhost_net *net,
 int r = vhost_ops-vhost_call(net-dev, VHOST_NET_SET_BACKEND, file);
 assert(r = 0);
 }
-net-nc-info-poll(net-nc, true);
+if (net-nc-info-poll) {
+net-nc-info-poll(net-nc, true);
+}
 vhost_dev_stop(net-dev, dev);
 vhost_dev_disable_notifiers(net-dev, dev);
 }
@@ -235,7 +245,7 @@ int vhost_net_start(VirtIODevice *dev, NetClientState *ncs,
 }
 
 for (i = 0; i  total_queues; i++) {
-r = vhost_net_start_one(tap_get_vhost_net(ncs[i].peer), dev, i * 2);
+r = vhost_net_start_one(get_vhost_net(ncs[i].peer), dev, i * 2);
 
 if (r  0) {
 goto err;
@@ -252,7 +262,7 @@ int vhost_net_start(VirtIODevice *dev, NetClientState *ncs,
 
 err:
 while (--i = 0) {
-vhost_net_stop_one(tap_get_vhost_net(ncs[i].peer), dev);
+vhost_net_stop_one(get_vhost_net(ncs[i].peer), dev);
 }
 return r;
 }
@@ -273,7 +283,7 @@ void vhost_net_stop(VirtIODevice *dev, NetClientState *ncs,
 assert(r = 0);
 
 for (i = 0; i  total_queues; i++) {
-vhost_net_stop_one(tap_get_vhost_net(ncs[i].peer), dev);
+vhost_net_stop_one(get_vhost_net(ncs[i].peer), dev);
 }
 }
 
@@ -293,6 +303,29 @@ void vhost_net_virtqueue_mask(VHostNetState *net, 
VirtIODevice *dev,
 {
 vhost_virtqueue_mask(net-dev, dev, idx, mask);
 }
+
+VHostNetState 

[Qemu-devel] [PATCH v4 3/7] Add vhost-user skeleton

2013-12-20 Thread Mian M. Hamayun
From: Antonios Motakis a.mota...@virtualopensystems.com

Add empty vhost_call, init and cleanup for the vhost-user backend.

Signed-off-by: Antonios Motakis a.mota...@virtualopensystems.com
Signed-off-by: Nikolay Nikolaev n.nikol...@virtualopensystems.com
---
 hw/net/vhost_net.c| 57 ++-
 hw/virtio/vhost-backend.c | 35 
 include/hw/virtio/vhost-backend.h |  3 ++-
 include/net/vhost_net.h   | 13 -
 net/tap.c | 16 ++-
 5 files changed, 91 insertions(+), 33 deletions(-)

diff --git a/hw/net/vhost_net.c b/hw/net/vhost_net.c
index 4aaf0b4..3614e6c 100644
--- a/hw/net/vhost_net.c
+++ b/hw/net/vhost_net.c
@@ -91,43 +91,51 @@ static int vhost_net_get_fd(NetClientState *backend)
 }
 }
 
-struct vhost_net *vhost_net_init(NetClientState *backend, int devfd,
- bool force)
+struct vhost_net *vhost_net_init(VhostNetOptions *options)
 {
-int r;
+int r = -1;
 struct vhost_net *net = g_malloc(sizeof *net);
-if (!backend) {
-fprintf(stderr, vhost-net requires backend to be setup\n);
+
+if (!options-net_backend) {
+fprintf(stderr, vhost-net requires net backend to be setup\n);
 goto fail;
 }
-r = vhost_net_get_fd(backend);
-if (r  0) {
-goto fail;
+
+if (options-backend_type == VHOST_BACKEND_TYPE_KERNEL) {
+r = vhost_net_get_fd(options-net_backend);
+if (r  0) {
+goto fail;
+}
+
+net-dev.backend_features =
+tap_has_vnet_hdr(options-net_backend) ? 0 :
+(1  VHOST_NET_F_VIRTIO_NET_HDR);
 }
-net-nc = backend;
-net-dev.backend_features = tap_has_vnet_hdr(backend) ? 0 :
-(1  VHOST_NET_F_VIRTIO_NET_HDR);
+
+net-nc = options-net_backend;
 net-backend = r;
 
 net-dev.nvqs = 2;
 net-dev.vqs = net-vqs;
 
-r = vhost_dev_init(net-dev, devfd, /dev/vhost-net,
-   VHOST_BACKEND_TYPE_KERNEL, force);
+r = vhost_dev_init(net-dev, options-devfd, options-devpath,
+   options-backend_type, options-force);
 if (r  0) {
 goto fail;
 }
-if (!tap_has_vnet_hdr_len(backend,
-  sizeof(struct virtio_net_hdr_mrg_rxbuf))) {
-net-dev.features = ~(1  VIRTIO_NET_F_MRG_RXBUF);
-}
-if (~net-dev.features  net-dev.backend_features) {
-fprintf(stderr, vhost lacks feature mask % PRIu64  for backend\n,
-(uint64_t)(~net-dev.features  net-dev.backend_features));
-vhost_dev_cleanup(net-dev);
-goto fail;
+if (options-backend_type == VHOST_BACKEND_TYPE_KERNEL) {
+if (!tap_has_vnet_hdr_len(options-net_backend,
+sizeof(struct virtio_net_hdr_mrg_rxbuf))) {
+net-dev.features = ~(1  VIRTIO_NET_F_MRG_RXBUF);
+}
+if (~net-dev.features  net-dev.backend_features) {
+fprintf(stderr, vhost lacks feature mask % PRIu64
+for backend\n,
+   (uint64_t)(~net-dev.features  net-dev.backend_features));
+vhost_dev_cleanup(net-dev);
+goto fail;
+}
 }
-
 /* Set sane init value. Override when guest acks. */
 vhost_net_ack_features(net, 0);
 return net;
@@ -286,8 +294,7 @@ void vhost_net_virtqueue_mask(VHostNetState *net, 
VirtIODevice *dev,
 vhost_virtqueue_mask(net-dev, dev, idx, mask);
 }
 #else
-struct vhost_net *vhost_net_init(NetClientState *backend, int devfd,
- bool force)
+struct vhost_net *vhost_net_init(VhostNetOptions *options)
 {
 error_report(vhost-net support is not compiled in);
 return NULL;
diff --git a/hw/virtio/vhost-backend.c b/hw/virtio/vhost-backend.c
index 2a9a1ec..847809f 100644
--- a/hw/virtio/vhost-backend.c
+++ b/hw/virtio/vhost-backend.c
@@ -15,6 +15,38 @@
 #include unistd.h
 #include sys/ioctl.h
 
+static int vhost_user_call(struct vhost_dev *dev, unsigned long int request,
+void *arg)
+{
+assert(dev-vhost_ops-backend_type == VHOST_BACKEND_TYPE_USER);
+fprintf(stderr, vhost_user_call not implemented\n);
+
+return -1;
+}
+
+static int vhost_user_init(struct vhost_dev *dev, const char *devpath)
+{
+assert(dev-vhost_ops-backend_type == VHOST_BACKEND_TYPE_USER);
+fprintf(stderr, vhost_user_init not implemented\n);
+
+return -1;
+}
+
+static int vhost_user_cleanup(struct vhost_dev *dev)
+{
+assert(dev-vhost_ops-backend_type == VHOST_BACKEND_TYPE_USER);
+fprintf(stderr, vhost_user_cleanup not implemented\n);
+
+return -1;
+}
+
+static const VhostOps user_ops = {
+.backend_type = VHOST_BACKEND_TYPE_USER,
+.vhost_call = vhost_user_call,
+.vhost_backend_init = vhost_user_init,
+.vhost_backend_cleanup = vhost_user_cleanup
+};
+
 static int vhost_kernel_call(struct vhost_dev *dev, unsigned long 

[Qemu-devel] [PATCH v4 1/7] Convert -mem-path to QemuOpts and add prealloc, share and unlink properties

2013-12-20 Thread Mian M. Hamayun
From: Antonios Motakis a.mota...@virtualopensystems.com

Extend -mem-path with additional properties:

 - prealloc=on|off - default off, same as -mem-prealloc
 - share=on|off - default off, memory is mmapped with MAP_SHARED flag
 - unlink=on|off - default on, inlink the file after openinng it

Signed-off-by: Antonios Motakis a.mota...@virtualopensystems.com
Signed-off-by: Nikolay Nikolaev n.nikol...@virtualopensystems.com
---
 exec.c | 57 +-
 include/exec/cpu-all.h |  3 ---
 qemu-options.hx| 10 +++--
 vl.c   | 41 +++-
 4 files changed, 91 insertions(+), 20 deletions(-)

diff --git a/exec.c b/exec.c
index 7e49e8e..30f4019 100644
--- a/exec.c
+++ b/exec.c
@@ -957,6 +957,7 @@ void qemu_mutex_unlock_ramlist(void)
 #include sys/vfs.h
 
 #define HUGETLBFS_MAGIC   0x958458f6
+#define MIN_HUGE_PAGE_SIZE(2*1024*1024)
 
 static long gethugepagesize(const char *path)
 {
@@ -972,8 +973,9 @@ static long gethugepagesize(const char *path)
 return 0;
 }
 
-if (fs.f_type != HUGETLBFS_MAGIC)
-fprintf(stderr, Warning: path not on HugeTLBFS: %s\n, path);
+if (fs.f_type != HUGETLBFS_MAGIC) {
+return 0;
+}
 
 return fs.f_bsize;
 }
@@ -994,11 +996,14 @@ static void *file_ram_alloc(RAMBlock *block,
 char *c;
 void *area;
 int fd;
+int flags;
 unsigned long hpagesize;
+QemuOpts *opts;
+unsigned int mem_prealloc = 0, mem_share = 0, mem_unlink = 1;
 
 hpagesize = gethugepagesize(path);
 if (!hpagesize) {
-return NULL;
+hpagesize = MIN_HUGE_PAGE_SIZE;
 }
 
 if (memory  hpagesize) {
@@ -1010,6 +1015,14 @@ static void *file_ram_alloc(RAMBlock *block,
 return NULL;
 }
 
+/* Fill config options */
+opts = qemu_opts_find(qemu_find_opts(mem-path), NULL);
+if (opts) {
+mem_prealloc = qemu_opt_get_bool(opts, prealloc, 0);
+mem_share = qemu_opt_get_bool(opts, share, 0);
+mem_unlink = qemu_opt_get_bool(opts, unlink, 1);
+}
+
 /* Make name safe to use with mkstemp by replacing '/' with '_'. */
 sanitized_name = g_strdup(block-mr-name);
 for (c = sanitized_name; *c != '\0'; c++) {
@@ -1017,20 +1030,28 @@ static void *file_ram_alloc(RAMBlock *block,
 *c = '_';
 }
 
-filename = g_strdup_printf(%s/qemu_back_mem.%s.XX, path,
-   sanitized_name);
+filename = g_strdup_printf(%s/qemu_back_mem.%s%s, path, sanitized_name,
+   (mem_unlink) ? .XX : );
 g_free(sanitized_name);
 
-fd = mkstemp(filename);
+if (mem_unlink) {
+fd = mkstemp(filename);
+} else {
+fd = open(filename, O_CREAT | O_RDWR | O_EXCL,
+S_IRWXU | S_IRWXG | S_IRWXO);
+}
 if (fd  0) {
-perror(unable to create backing store for hugepages);
+perror(unable to create guest RAM backing store);
 g_free(filename);
 return NULL;
 }
-unlink(filename);
+
+if (mem_unlink) {
+unlink(filename);
+}
 g_free(filename);
 
-memory = (memory+hpagesize-1)  ~(hpagesize-1);
+memory = (memory + hpagesize - 1)  ~(hpagesize - 1);
 
 /*
  * ftruncate is not supported by hugetlbfs in older
@@ -1041,7 +1062,8 @@ static void *file_ram_alloc(RAMBlock *block,
 if (ftruncate(fd, memory))
 perror(ftruncate);
 
-area = mmap(0, memory, PROT_READ | PROT_WRITE, MAP_PRIVATE, fd, 0);
+flags = mem_share ? MAP_SHARED : MAP_PRIVATE;
+area = mmap(0, memory, PROT_READ | PROT_WRITE, flags, fd, 0);
 if (area == MAP_FAILED) {
 perror(file_ram_alloc: can't mmap RAM pages);
 close(fd);
@@ -1211,11 +1233,18 @@ ram_addr_t qemu_ram_alloc_from_ptr(ram_addr_t size, 
void *host,
MemoryRegion *mr)
 {
 RAMBlock *block, *new_block;
+QemuOpts *opts;
+const char *mem_path = 0;
 
 size = TARGET_PAGE_ALIGN(size);
 new_block = g_malloc0(sizeof(*new_block));
 new_block-fd = -1;
 
+opts = qemu_opts_find(qemu_find_opts(mem-path), NULL);
+if (opts) {
+mem_path = qemu_opt_get(opts, path);
+}
+
 /* This assumes the iothread lock is taken here too.  */
 qemu_mutex_lock_ramlist();
 new_block-mr = mr;
@@ -1348,6 +1377,14 @@ void qemu_ram_remap(ram_addr_t addr, ram_addr_t length)
 ram_addr_t offset;
 int flags;
 void *area, *vaddr;
+QemuOpts *opts;
+unsigned int mem_prealloc = 0;
+
+/* Fill config options */
+opts = qemu_opts_find(qemu_find_opts(mem-path), NULL);
+if (opts) {
+mem_prealloc = qemu_opt_get_bool(opts, prealloc, 0);
+}
 
 QTAILQ_FOREACH(block, ram_list.blocks, next) {
 offset = addr - block-offset;
diff --git a/include/exec/cpu-all.h b/include/exec/cpu-all.h
index b6998f0..4f8e989 100644
--- a/include/exec/cpu-all.h
+++ b/include/exec/cpu-all.h
@@ 

[Qemu-devel] [PATCH v4 5/7] Add vhost-user calls implementation

2013-12-20 Thread Mian M. Hamayun
From: Antonios Motakis a.mota...@virtualopensystems.com

Each ioctl request of vhost-kernel has a vhost-user message equivalent,
which is sent over the control socket.

The general approach is to copy the data from the supplied argument
pointer to a designated field in the message. If a file descriptor is
to be passed, it should be placed in the fds array for inclusion in
the sendmsg control header.

VHOST_SET_MEM_TABLE ignores the supplied vhost_memory structure and scans
the global ram_list for ram blocks with a valid fd field set. This would
be set when the -mem-path option with shared=on property is used.

Signed-off-by: Antonios Motakis a.mota...@virtualopensystems.com
Signed-off-by: Nikolay Nikolaev n.nikol...@virtualopensystems.com
---
 hw/virtio/vhost-backend.c | 137 +-
 1 file changed, 134 insertions(+), 3 deletions(-)

diff --git a/hw/virtio/vhost-backend.c b/hw/virtio/vhost-backend.c
index 96d3bf0..17f59ec 100644
--- a/hw/virtio/vhost-backend.c
+++ b/hw/virtio/vhost-backend.c
@@ -19,6 +19,7 @@
 #include linux/vhost.h
 
 #define VHOST_MEMORY_MAX_NREGIONS8
+#define VHOST_USER_SOCKTO(1000) /* msec */
 
 typedef enum VhostUserRequest {
 VHOST_USER_NONE = 0,
@@ -66,6 +67,40 @@ typedef struct VhostUserMsg {
 };
 } VhostUserMsg;
 
+static unsigned long int ioctl_to_vhost_user_request[VHOST_USER_MAX] = {
+-1, /* VHOST_USER_NONE */
+VHOST_GET_FEATURES, /* VHOST_USER_GET_FEATURES */
+VHOST_SET_FEATURES, /* VHOST_USER_SET_FEATURES */
+VHOST_SET_OWNER, /* VHOST_USER_SET_OWNER */
+VHOST_RESET_OWNER, /* VHOST_USER_RESET_OWNER */
+VHOST_SET_MEM_TABLE, /* VHOST_USER_SET_MEM_TABLE */
+VHOST_SET_LOG_BASE, /* VHOST_USER_SET_LOG_BASE */
+VHOST_SET_LOG_FD, /* VHOST_USER_SET_LOG_FD */
+VHOST_SET_VRING_NUM, /* VHOST_USER_SET_VRING_NUM */
+VHOST_SET_VRING_ADDR, /* VHOST_USER_SET_VRING_ADDR */
+VHOST_SET_VRING_BASE, /* VHOST_USER_SET_VRING_BASE */
+VHOST_GET_VRING_BASE, /* VHOST_USER_GET_VRING_BASE */
+VHOST_SET_VRING_KICK, /* VHOST_USER_SET_VRING_KICK */
+VHOST_SET_VRING_CALL, /* VHOST_USER_SET_VRING_CALL */
+VHOST_SET_VRING_ERR, /* VHOST_USER_SET_VRING_ERR */
+VHOST_NET_SET_BACKEND /* VHOST_USER_NET_SET_BACKEND */
+};
+
+static int vhost_user_cleanup(struct vhost_dev *dev);
+
+static VhostUserRequest vhost_user_request_translate(unsigned long int request)
+{
+VhostUserRequest idx;
+
+for (idx = 0; idx  VHOST_USER_MAX; idx++) {
+if (ioctl_to_vhost_user_request[idx] == request) {
+break;
+}
+}
+
+return (idx == VHOST_USER_MAX) ? VHOST_USER_NONE : idx;
+}
+
 static int vhost_user_recv(int fd, VhostUserMsg *msg)
 {
 ssize_t r = read(fd, msg, sizeof(VhostUserMsg));
@@ -129,13 +164,74 @@ static int vhost_user_call(struct vhost_dev *dev, 
unsigned long int request,
 {
 int fd = dev-control;
 VhostUserMsg msg;
+RAMBlock *block = 0;
 int result = 0, need_reply = 0;
 int fds[VHOST_MEMORY_MAX_NREGIONS];
 size_t fd_num = 0;
 
 assert(dev-vhost_ops-backend_type == VHOST_BACKEND_TYPE_USER);
 
+msg.request = vhost_user_request_translate(request);
+msg.flags = 0;
+
 switch (request) {
+case VHOST_GET_FEATURES:
+case VHOST_GET_VRING_BASE:
+need_reply = 1;
+break;
+
+case VHOST_SET_FEATURES:
+case VHOST_SET_LOG_BASE:
+msg.u64 = *((uint64_t *) arg);
+break;
+
+case VHOST_SET_OWNER:
+case VHOST_RESET_OWNER:
+break;
+
+case VHOST_SET_MEM_TABLE:
+QTAILQ_FOREACH(block, ram_list.blocks, next)
+{
+if (block-fd  0) {
+msg.memory.regions[fd_num].userspace_addr = (__u64) 
block-host;
+msg.memory.regions[fd_num].memory_size = block-length;
+msg.memory.regions[fd_num].guest_phys_addr = block-offset;
+fds[fd_num++] = block-fd;
+}
+}
+
+msg.memory.nregions = fd_num;
+
+if (!fd_num) {
+fprintf(stderr, Failed initializing vhost-user memory map\n
+consider -mem-path and -mem-prealloc options\n);
+return -1;
+}
+break;
+
+case VHOST_SET_LOG_FD:
+msg.fd = *((int *) arg);
+break;
+
+case VHOST_SET_VRING_NUM:
+case VHOST_SET_VRING_BASE:
+memcpy(msg.state, arg, sizeof(struct vhost_vring_state));
+break;
+
+case VHOST_SET_VRING_ADDR:
+memcpy(msg.addr, arg, sizeof(struct vhost_vring_addr));
+break;
+
+case VHOST_SET_VRING_KICK:
+case VHOST_SET_VRING_CALL:
+case VHOST_SET_VRING_ERR:
+case VHOST_NET_SET_BACKEND:
+memcpy(msg.file, arg, sizeof(struct vhost_vring_file));
+if (msg.file.fd  0) {
+fds[0] = msg.file.fd;
+fd_num = 1;
+}
+break;
 default:
 fprintf(stderr, vhost-user trying to send unhandled ioctl\n);
 return -1;
@@ -148,7 +244,11 @@ 

[Qemu-devel] [PATCH v4 4/7] Add domain socket communication for vhost-user backend

2013-12-20 Thread Mian M. Hamayun
From: Antonios Motakis a.mota...@virtualopensystems.com

Add structures for passing vhost-user messages over a unix domain socket.
This is the equivalent to the existing vhost-kernel ioctls.

Connect to the named unix domain socket. The system call sendmsg
is used for communication. To be able to pass file descriptors
between processes - we use SCM_RIGHTS type in the message control header.

Signed-off-by: Antonios Motakis a.mota...@virtualopensystems.com
Signed-off-by: Nikolay Nikolaev n.nikol...@virtualopensystems.com
---
 hw/virtio/vhost-backend.c | 167 --
 1 file changed, 161 insertions(+), 6 deletions(-)

diff --git a/hw/virtio/vhost-backend.c b/hw/virtio/vhost-backend.c
index 847809f..96d3bf0 100644
--- a/hw/virtio/vhost-backend.c
+++ b/hw/virtio/vhost-backend.c
@@ -14,30 +14,185 @@
 #include fcntl.h
 #include unistd.h
 #include sys/ioctl.h
+#include sys/socket.h
+#include sys/un.h
+#include linux/vhost.h
+
+#define VHOST_MEMORY_MAX_NREGIONS8
+
+typedef enum VhostUserRequest {
+VHOST_USER_NONE = 0,
+VHOST_USER_GET_FEATURES = 1,
+VHOST_USER_SET_FEATURES = 2,
+VHOST_USER_SET_OWNER = 3,
+VHOST_USER_RESET_OWNER = 4,
+VHOST_USER_SET_MEM_TABLE = 5,
+VHOST_USER_SET_LOG_BASE = 6,
+VHOST_USER_SET_LOG_FD = 7,
+VHOST_USER_SET_VRING_NUM = 8,
+VHOST_USER_SET_VRING_ADDR = 9,
+VHOST_USER_SET_VRING_BASE = 10,
+VHOST_USER_GET_VRING_BASE = 11,
+VHOST_USER_SET_VRING_KICK = 12,
+VHOST_USER_SET_VRING_CALL = 13,
+VHOST_USER_SET_VRING_ERR = 14,
+VHOST_USER_NET_SET_BACKEND = 15,
+VHOST_USER_MAX
+} VhostUserRequest;
+
+typedef struct VhostUserMemoryRegion {
+__u64 guest_phys_addr;
+__u64 memory_size;
+__u64 userspace_addr;
+} VhostUserMemoryRegion;
+
+typedef struct VhostUserMemory {
+__u32 nregions;
+VhostUserMemoryRegion regions[VHOST_MEMORY_MAX_NREGIONS];
+} VhostUserMemory;
+
+typedef struct VhostUserMsg {
+VhostUserRequest request;
+
+int flags;
+union {
+uint64_tu64;
+int fd;
+struct vhost_vring_state state;
+struct vhost_vring_addr addr;
+struct vhost_vring_file file;
+
+VhostUserMemory memory;
+};
+} VhostUserMsg;
+
+static int vhost_user_recv(int fd, VhostUserMsg *msg)
+{
+ssize_t r = read(fd, msg, sizeof(VhostUserMsg));
+
+return (r == sizeof(VhostUserMsg)) ? 0 : -1;
+}
+
+static int vhost_user_send_fds(int fd, const VhostUserMsg *msg, int *fds,
+size_t fd_num)
+{
+int r;
+
+struct msghdr msgh;
+struct iovec iov[1];
+
+size_t fd_size = fd_num * sizeof(int);
+char control[CMSG_SPACE(fd_size)];
+struct cmsghdr *cmsg;
+
+memset(msgh, 0, sizeof(msgh));
+memset(control, 0, sizeof(control));
+
+/* set the payload */
+iov[0].iov_base = (void *) msg;
+iov[0].iov_len = sizeof(VhostUserMsg);
+
+msgh.msg_iov = iov;
+msgh.msg_iovlen = 1;
+
+if (fd_num) {
+msgh.msg_control = control;
+msgh.msg_controllen = sizeof(control);
+
+cmsg = CMSG_FIRSTHDR(msgh);
+
+cmsg-cmsg_len = CMSG_LEN(fd_size);
+cmsg-cmsg_level = SOL_SOCKET;
+cmsg-cmsg_type = SCM_RIGHTS;
+memcpy(CMSG_DATA(cmsg), fds, fd_size);
+} else {
+msgh.msg_control = 0;
+msgh.msg_controllen = 0;
+}
+
+do {
+r = sendmsg(fd, msgh, 0);
+} while (r  0  errno == EINTR);
+
+if (r  0) {
+fprintf(stderr, Failed to send msg(%d), reason: %s\n,
+msg-request, strerror(errno));
+} else {
+r = 0;
+}
+
+return r;
+}
 
 static int vhost_user_call(struct vhost_dev *dev, unsigned long int request,
 void *arg)
 {
+int fd = dev-control;
+VhostUserMsg msg;
+int result = 0, need_reply = 0;
+int fds[VHOST_MEMORY_MAX_NREGIONS];
+size_t fd_num = 0;
+
 assert(dev-vhost_ops-backend_type == VHOST_BACKEND_TYPE_USER);
-fprintf(stderr, vhost_user_call not implemented\n);
 
-return -1;
+switch (request) {
+default:
+fprintf(stderr, vhost-user trying to send unhandled ioctl\n);
+return -1;
+break;
+}
+
+result = vhost_user_send_fds(fd, msg, fds, fd_num);
+
+if (!result  need_reply) {
+result = vhost_user_recv(fd, msg);
+if (!result) {
+switch (request) {
+default:
+break;
+}
+}
+}
+
+return result;
 }
 
 static int vhost_user_init(struct vhost_dev *dev, const char *devpath)
 {
+int fd = -1;
+struct sockaddr_un un;
+size_t len;
+
 assert(dev-vhost_ops-backend_type == VHOST_BACKEND_TYPE_USER);
-fprintf(stderr, vhost_user_init not implemented\n);
 
-return -1;
+/* Create the socket */
+fd = socket(AF_UNIX, SOCK_STREAM, 0);
+if (fd == -1) {
+perror(socket);
+return -1;
+}
+
+un.sun_family = AF_UNIX;
+strcpy(un.sun_path, devpath);
+
+len = sizeof(un.sun_family) 

[Qemu-devel] [PATCH v4 7/7] Add vhost-user reconnection

2013-12-20 Thread Mian M. Hamayun
From: Antonios Motakis a.mota...@virtualopensystems.com

At runtime vhost-user netdev will detect if the vhost backend is up or down.
Upon disconnection it will set link_down accordingly and notify virtio-net.

Signed-off-by: Antonios Motakis a.mota...@virtualopensystems.com
Signed-off-by: Nikolay Nikolaev n.nikol...@virtualopensystems.com
---
 hw/net/vhost_net.c| 16 +++
 hw/virtio/vhost-backend.c | 28 ++--
 include/hw/virtio/vhost-backend.h |  2 ++
 include/net/vhost_net.h   |  1 +
 net/vhost-user.c  | 56 +++
 5 files changed, 101 insertions(+), 2 deletions(-)

diff --git a/hw/net/vhost_net.c b/hw/net/vhost_net.c
index e42f4d6..56c218e 100644
--- a/hw/net/vhost_net.c
+++ b/hw/net/vhost_net.c
@@ -304,6 +304,17 @@ void vhost_net_virtqueue_mask(VHostNetState *net, 
VirtIODevice *dev,
 vhost_virtqueue_mask(net-dev, dev, idx, mask);
 }
 
+int vhost_net_link_status(VHostNetState *net)
+{
+int r = 0;
+
+if (net-dev.vhost_ops-vhost_status) {
+r = net-dev.vhost_ops-vhost_status(net-dev);
+}
+
+return r;
+}
+
 VHostNetState *get_vhost_net(NetClientState *nc)
 {
 VHostNetState *vhost_net = 0;
@@ -372,6 +383,11 @@ void vhost_net_virtqueue_mask(VHostNetState *net, 
VirtIODevice *dev,
 {
 }
 
+int vhost_net_link_status(VHostNetState *net)
+{
+return 0;
+}
+
 VHostNetState *get_vhost_net(NetClientState *nc)
 {
 return 0;
diff --git a/hw/virtio/vhost-backend.c b/hw/virtio/vhost-backend.c
index 17f59ec..10f813b 100644
--- a/hw/virtio/vhost-backend.c
+++ b/hw/virtio/vhost-backend.c
@@ -171,6 +171,10 @@ static int vhost_user_call(struct vhost_dev *dev, unsigned 
long int request,
 
 assert(dev-vhost_ops-backend_type == VHOST_BACKEND_TYPE_USER);
 
+if (fd  0) {
+return 0;
+}
+
 msg.request = vhost_user_request_translate(request);
 msg.flags = 0;
 
@@ -254,9 +258,25 @@ static int vhost_user_call(struct vhost_dev *dev, unsigned 
long int request,
 }
 }
 
+/* mark the backend non operational */
+if (result  0) {
+fprintf(stderr, %s: Connection break detected\n, __func__);
+vhost_user_cleanup(dev);
+return 0;
+}
+
 return result;
 }
 
+static int vhost_user_status(struct vhost_dev *dev)
+{
+uint64_t features = 0;
+
+vhost_user_call(dev, VHOST_GET_FEATURES, features);
+
+return (dev-control = 0);
+}
+
 static int vhost_user_init(struct vhost_dev *dev, const char *devpath)
 {
 int fd = -1;
@@ -316,11 +336,13 @@ fail:
 
 static int vhost_user_cleanup(struct vhost_dev *dev)
 {
-int r;
+int r = 0;
 
 assert(dev-vhost_ops-backend_type == VHOST_BACKEND_TYPE_USER);
 
-r = close(dev-control);
+if (dev-control = 0) {
+r = close(dev-control);
+}
 dev-control = -1;
 
 return r;
@@ -329,6 +351,7 @@ static int vhost_user_cleanup(struct vhost_dev *dev)
 static const VhostOps user_ops = {
 .backend_type = VHOST_BACKEND_TYPE_USER,
 .vhost_call = vhost_user_call,
+.vhost_status = vhost_user_status,
 .vhost_backend_init = vhost_user_init,
 .vhost_backend_cleanup = vhost_user_cleanup
 };
@@ -361,6 +384,7 @@ static int vhost_kernel_cleanup(struct vhost_dev *dev)
 static const VhostOps kernel_ops = {
 .backend_type = VHOST_BACKEND_TYPE_KERNEL,
 .vhost_call = vhost_kernel_call,
+.vhost_status = 0,
 .vhost_backend_init = vhost_kernel_init,
 .vhost_backend_cleanup = vhost_kernel_cleanup
 };
diff --git a/include/hw/virtio/vhost-backend.h 
b/include/hw/virtio/vhost-backend.h
index ef87ffa..f2b4a6c 100644
--- a/include/hw/virtio/vhost-backend.h
+++ b/include/hw/virtio/vhost-backend.h
@@ -22,12 +22,14 @@ struct vhost_dev;
 
 typedef int (*vhost_call)(struct vhost_dev *dev, unsigned long int request,
  void *arg);
+typedef int (*vhost_status)(struct vhost_dev *dev);
 typedef int (*vhost_backend_init)(struct vhost_dev *dev, const char *devpath);
 typedef int (*vhost_backend_cleanup)(struct vhost_dev *dev);
 
 typedef struct VhostOps {
 VhostBackendType backend_type;
 vhost_call vhost_call;
+vhost_status vhost_status;
 vhost_backend_init vhost_backend_init;
 vhost_backend_cleanup vhost_backend_cleanup;
 } VhostOps;
diff --git a/include/net/vhost_net.h b/include/net/vhost_net.h
index abd3d0b..6390907 100644
--- a/include/net/vhost_net.h
+++ b/include/net/vhost_net.h
@@ -31,5 +31,6 @@ void vhost_net_ack_features(VHostNetState *net, unsigned 
features);
 bool vhost_net_virtqueue_pending(VHostNetState *net, int n);
 void vhost_net_virtqueue_mask(VHostNetState *net, VirtIODevice *dev,
   int idx, bool mask);
+int vhost_net_link_status(VHostNetState *net);
 VHostNetState *get_vhost_net(NetClientState *nc);
 #endif
diff --git a/net/vhost-user.c b/net/vhost-user.c
index 6fd5afc..56f7dd4 100644
--- a/net/vhost-user.c
+++ b/net/vhost-user.c
@@ -12,6 

Re: [Qemu-devel] [RFC PATCH 18/21] target-arm: switch banked CP registers

2013-12-20 Thread Fedorov Sergey


On 12/19/2013 03:38 PM, Peter Maydell wrote:

On 19 December 2013 07:27, Fedorov Sergey s.fedo...@samsung.com wrote:

Yes, this banking scheme makes state changing events quite heavy. But
maintaining the active copies allows to keep translation table walking code
untouched. I think there is a trade-off between state changing and
translation table walking overheads.

We shouldn't be doing tlb walks that often that it makes a
difference whether we do env-ttbr0 or env-ttbr0[env-ns] ...


I think the CP banking is the most fragile thing in this patch series and
this should become much better after review :)

It would probably be a good idea to look at the v8 ARM ARM and
figure out how banked-for-NS/S registers should fit in with the
AArch64 vs AArch32 split.
[if you don't have a copy, it's on the ARM website:
http://infocenter.arm.com/help/topic/com.arm.doc.ddi0487a.a_errata2/index.html
you'll need to register an account on the website if you don't already
have one but it's a fairly simple fill in the form automated process]

Note in particular that:
  * many of the current uint32_t fields in our CPU state struct are
likely to widen to uint64_t, so the AArch64 representation is
canonical, and the AArch32 register accessors access a part
of that state (typically the lower 32 bits)
  * registers which are banked S/NS in AArch32 are not necessarily
banked in AArch64

AArch64 support is likely to land before your TrustZone stuff
does so we need to make the two features work together cleanly.

thanks
-- PMM



I've briefly looked at the v8 ARM ARM. As I can see there is no banked 
system control registers in AArch64. Seems the concept is changed to 
provide separate registers for each meaningful execution level. Please, 
correct me if I am wrong.


So I think there shouldn't be active and banked fields for banked 
AArch32 CP15 registers as in my patch. Seems it is worth to use AArch64 
view of system control registers as a basis. That means there would be 
separate S and NS register fields in CPU state structure that will me 
mapped to separate AArch64 registers. ARMCPRegInfo structure would have 
additional field holding NS register state filed offset for AArch32 
banked registers.


Which branch in https://git.linaro.org/people/peter.maydell/qemu-arm.git 
repository holds the most actual A64 support?


Thanks!

Best regards,
Sergey Fedorov



Re: [Qemu-devel] [PATCH 07/21] target-arm: A64: add support for 3 src data proc insns

2013-12-20 Thread Peter Maydell
On 20 December 2013 14:10, Richard Henderson r...@twiddle.net wrote:
 On 12/20/2013 05:18 AM, Peter Maydell wrote:
 On 19 December 2013 19:29, Richard Henderson r...@twiddle.net wrote:
 On 12/17/2013 07:12 AM, Peter Maydell wrote:
 +tcg_gen_mul_i64(tcg_tmp, tcg_op1, tcg_op2);
 +if (is_sub) {
 +tcg_gen_sub_i64(cpu_reg(s, rd), cpu_reg(s, ra), tcg_tmp);
 +} else {
 +tcg_gen_add_i64(cpu_reg(s, rd), cpu_reg(s, ra), tcg_tmp);
 +}

 Perhaps worth noticing the RA=XZR special case for the MUL alias?

 Yeah, makes sense: have adjusted to:
 +if (ra == 31) {
 +/* We special-case rA == XZR as it is the standard MUL alias */
 +tcg_gen_mul_i64(cpu_reg(s, rd), tcg_op1, tcg_op2);
 +} else {

 You need to handle (or dismiss) is_sub.

 Either (ra == 31  !is_sub) or

if (is_sub) {
tcg_gen_neg_i64(tcg_rd, tcg_rd);
}

 with tcg_rd pre-loaded along with tcg_op1 and tcg_op2.

 That said, unlike MUL I don't expect MNEG to be common at all.

Oops. Yes, let's just have (ra == 31  !is_sub).

thanks
-- PMM



[Qemu-devel] [Bug 1042388] Re: qemu: Unsupported syscall: 257 (timer_create)

2013-12-20 Thread LocutusOfBorg
mmm I don't know, I built it in my ppa, with your patch.
Upgraded the system
https://code.launchpad.net/~costamagnagianfranco/+archive/firefox/+packages
Preparing to replace qemu-user 1.5.0+dfsg-3ubuntu5.2 (using 
.../qemu-user_1.7.0+dfsg-2ubuntu4~saucy1_amd64.deb) ...
Unpacking replacement qemu-user ...
Preparing to replace qemu-keymaps 1.5.0+dfsg-3ubuntu5.2 (using 
.../qemu-keymaps_1.7.0+dfsg-2ubuntu4~saucy1_all.deb) ...
Unpacking replacement qemu-keymaps ...
Preparing to replace qemu-system-ppc 1.5.0+dfsg-3ubuntu5.2 (using 
.../qemu-system-ppc_1.7.0+dfsg-2ubuntu4~saucy1_amd64.deb) ...
Unpacking replacement qemu-system-ppc ...
Preparing to replace qemu-system-sparc 1.5.0+dfsg-3ubuntu5.2 (using 
.../qemu-system-sparc_1.7.0+dfsg-2ubuntu4~saucy1_amd64.deb) ...
Unpacking replacement qemu-system-sparc ...
Preparing to replace qemu-system-x86 1.5.0+dfsg-3ubuntu5.2 (using 
.../qemu-system-x86_1.7.0+dfsg-2ubuntu4~saucy1_amd64.deb) ...
Unpacking replacement qemu-system-x86 ...
Preparing to replace qemu-system-arm 1.5.0+dfsg-3ubuntu5.2 (using 
.../qemu-system-arm_1.7.0+dfsg-2ubuntu4~saucy1_amd64.deb) ...
Unpacking replacement qemu-system-arm ...
Preparing to replace qemu-system-misc 1.5.0+dfsg-3ubuntu5.2 (using 
.../qemu-system-misc_1.7.0+dfsg-2ubuntu4~saucy1_amd64.deb) ...
Unpacking replacement qemu-system-misc ...
Preparing to replace qemu-system-mips 1.5.0+dfsg-3ubuntu5.2 (using 
.../qemu-system-mips_1.7.0+dfsg-2ubuntu4~saucy1_amd64.deb) ...
Unpacking replacement qemu-system-mips ...
Preparing to replace qemu-system 1.5.0+dfsg-3ubuntu5.2 (using 
.../qemu-system_1.7.0+dfsg-2ubuntu4~saucy1_amd64.deb) ...
Unpacking replacement qemu-system ...
Preparing to replace qemu-utils 1.5.0+dfsg-3ubuntu5.2 (using 
.../qemu-utils_1.7.0+dfsg-2ubuntu4~saucy1_amd64.deb) ...
Unpacking replacement qemu-utils ...
Preparing to replace qemu 1.5.0+dfsg-3ubuntu5.2 (using 
.../qemu_1.7.0+dfsg-2ubuntu4~saucy1_amd64.deb) ...
Unpacking replacement qemu ...
Preparing to replace qemu-user-static 1.5.0+dfsg-3ubuntu5.2 (using 
.../qemu-user-static_1.7.0+dfsg-2ubuntu4~saucy1_amd64.deb) ...
Unpacking replacement qemu-user-static ...


pbuilder-dist sid armhf login
apt-get install ghc
Setting up ghc (7.6.3-6) ...
qemu: Unsupported syscall: 257
ghc: timer_create: Function not implemented
update-alternatives: using /usr/bin/ghc to provide /usr/bin/haskell-compiler 
(haskell-compiler) in auto mode
qemu: Unsupported syscall: 257
ghc-pkg: timer_create: Function not implemented
dpkg: error processing package ghc (--configure):
 subprocess installed post-installation script returned error exit status 1

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

Title:
  qemu: Unsupported syscall: 257 (timer_create)

Status in QEMU:
  Confirmed

Bug description:
  Running qemu-arm-static for git HEAD. When I try to install ghc from
  debian into my arm chroot I get:

  Setting up ghc (7.4.1-4) ...
  qemu: Unsupported syscall: 257
  ghc: timer_create: Function not implemented
  qemu: Unsupported syscall: 257
  ghc-pkg: timer_create: Function not implemented
  dpkg: error processing ghc (--configure):
   subprocess installed post-installation script returned error exit status 1
  Errors were encountered while processing:
   ghc
  E: Sub-process /usr/bin/dpkg returned an error code (1)

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



Re: [Qemu-devel] [PATCH V7 4/6] qcow2: cancel the modification on fail in qcow2_snapshot_create()

2013-12-20 Thread Stefan Hajnoczi
On Thu, Dec 05, 2013 at 08:02:50PM +0800, Wenchao Xia wrote:
 +restore_refcount:
 +if (qcow2_update_snapshot_refcount(bs, s-l1_table_offset, s-l1_size, 
 -1)
 + 0  errp) {
 +/* Nothing can be done now, need image check later */
 +error_setg(err, %s\nqcow2: Error in restoring refcount in 
 snapshot,
 +   error_get_pretty(*errp));
 +error_free(*errp);
 +*errp = NULL;
 +error_propagate(errp, err);
 +}

We get here if writing the new snapshot list failed.  If
qcow2_update_snapshot_refcount(..., -1) also fails I think we should
skip qcow2_free_clusters() below.  We don't know the exact state of the
disk image anymore - better to leak clusters than to have a dangling
reference.

 +dealloc_cluster:
 +qcow2_free_clusters(bs, sn-l1_table_offset,
 +sn-l1_size * sizeof(uint64_t),
 +QCOW2_DISCARD_ALWAYS);
 +
  fail:
  g_free(sn-id_str);
  g_free(sn-name);
 -- 
 1.7.1
 
 



Re: [Qemu-devel] [PATCH V7 1/6] snapshot: add parameter *errp in snapshot create

2013-12-20 Thread Stefan Hajnoczi
On Thu, Dec 05, 2013 at 08:02:47PM +0800, Wenchao Xia wrote:
 @@ -366,7 +368,8 @@ int qcow2_snapshot_create(BlockDriverState *bs, 
 QEMUSnapshotInfo *sn_info)
  
  /* Check that the ID is unique */
  if (find_snapshot_by_id_and_name(bs, sn_info-id_str, NULL) = 0) {
 -return -EEXIST;
 +error_setg(errp, Snapshot with id %s already exist, 
 sn_info-id_str);

s/exist/exists/



Re: [Qemu-devel] [PATCH V7 0/6] qcow2: rollback the modification on fail in snapshot creation

2013-12-20 Thread Stefan Hajnoczi
On Thu, Dec 05, 2013 at 08:02:46PM +0800, Wenchao Xia wrote:
 V2:
   1: all fail case will goto fail section.
   2: add the goto code.
 
 v3:
   Address Stefan's comments:
   2: don't goto fail after allocation failure.
   3: use sn-l1size correctly in qcow2_free_cluster().
   4-7: add test case to verify the error paths.
   Other:
   1: new patch fix a existing bug, which will be exposed in error path test.
 
 v4:
   General change:
   rebased on upstream since error path for qcow2_write_snapshots() already
 exist in upstream. removed old patch 1 since it is fixed by Max in upstream.
   5: moved the snapshot_l1_update event just before write operation, instead 
 of
 before overlap check, since it is more straight.
   6: remove a duplicated error path test about flush after snapshot list
 update, add a filter which replace number to X, since now in error in report
 detailed message including error cluster number.
   Address Stefan's comments:
   1, 2, 4: add *errp to store detailed error message, instead of 
 error_report()
 and compile time determined debug printf message.
   3: do not free cluster when fail in header update for safety reason.
   Address Eric's comments:
   1, 2, 4: add *errp to store detailed error message, instead of 
 error_report()
 and compile time determined debug printf message.
   5: squashed patches that add and use debug events.
   6: added comments about test only on Linux.
 
 v5:
   General change:
   6: rebased on upstream, use case number 070, adjust 070.out due to error
 message change in this version.
 
   Address Max's comments:
   1 use error_setg_errno() when possible, remove ret = in functions when
 possible since the function does not need to return int value, fix 32bit/
 64bit issue in printf for sizeof and offse, typo fix.
   2 use error_setg_errno() when possible, fix 32bit/64bit issue in printf
 for sizeof and offse, typo fix.
   3 typo fix in comments.
   5 typo fix in commit message.
 
   Address Eric's comments:
   2 fix 32bit/64bit issue in printf for sizeof and offse.
 
 v6:
   Address Jeff's comments:
   6: add quote for image name in test case.
 
 v7:
   Rebased on Stefan's block tree, since I need to test after Fam's
 cache mode series.
   6: change case number to 075 to avoid conflict, add a comments in
 case that it covers only default cache mode, qemu-img snapshot would
 not be affected by case's cache setting.
 
 Wenchao Xia (6):
   1 snapshot: add parameter *errp in snapshot create
   2 qcow2: add error message in qcow2_write_snapshots()
   3 qcow2: do not free clusters when fail in header update in 
 qcow2_write_snapshots
   4 qcow2: cancel the modification on fail in qcow2_snapshot_create()
   5 blkdebug: add debug events for snapshot
   6 qemu-iotests: add test for qcow2 snapshot
 
  block/blkdebug.c |4 +
  block/qcow2-snapshot.c   |  105 ---
  block/qcow2.h|4 +-
  block/rbd.c  |   19 ++--
  block/sheepdog.c |   28 +++--
  block/snapshot.c |   19 +++-
  blockdev.c   |   10 +-
  include/block/block.h|4 +
  include/block/block_int.h|5 +-
  include/block/snapshot.h |5 +-
  qemu-img.c   |   10 +-
  savevm.c |   12 ++-
  tests/qemu-iotests/075   |  218 
 ++
  tests/qemu-iotests/075.out   |   35 ++
  tests/qemu-iotests/common.filter |7 ++
  tests/qemu-iotests/group |1 +
  16 files changed, 429 insertions(+), 57 deletions(-)
  create mode 100755 tests/qemu-iotests/075
  create mode 100644 tests/qemu-iotests/075.out

This looks very close.  I pointed out one code path where I feel freeing
clusters is too agressive (better to leak than to corrupt the image).
There are a few minor fixups that would be nice too.

Otherwise, looks good.  Good job on extending blkdebug and adding a test
case.



Re: [Qemu-devel] [RFC PATCH 18/21] target-arm: switch banked CP registers

2013-12-20 Thread Peter Maydell
On 20 December 2013 14:12, Fedorov Sergey s.fedo...@samsung.com wrote:
 I've briefly looked at the v8 ARM ARM. As I can see there is no banked
 system control registers in AArch64. Seems the concept is changed to provide
 separate registers for each meaningful execution level. Please, correct me
 if I am wrong.

Yes, I think this is generally correct.

 So I think there shouldn't be active and banked fields for banked
 AArch32 CP15 registers as in my patch. Seems it is worth to use AArch64 view
 of system control registers as a basis. That means there would be separate S
 and NS register fields in CPU state structure that will me mapped to
 separate AArch64 registers. ARMCPRegInfo structure would have additional
 field holding NS register state filed offset for AArch32 banked registers.

This sounds like it could work, though there are some wrinkles for
registers with readfns/writefns -- do we have extra s vs ns read/write
functions, or just one set of functions which has to look in env-ns to
figure out whether to use the S or NS version?

 Which branch in https://git.linaro.org/people/peter.maydell/qemu-arm.git
 repository holds the most actual A64 support?

It's still a work in progress so it depends what you want.
a64-third-fourth-set is the last set of patches that went out for
review, and should generally work for integer instructions.
a64-working is my work-in-progress branch so it will have the
most recent versions of everything, but it rebases frequently
and is liable to occasionally be broken...

thanks
-- PMM



Re: [Qemu-devel] [RFC PATCH 18/21] target-arm: switch banked CP registers

2013-12-20 Thread Fedorov Sergey

On 12/20/2013 06:33 PM, Peter Maydell wrote:
 On 20 December 2013 14:12, Fedorov Sergey s.fedo...@samsung.com wrote:
 I've briefly looked at the v8 ARM ARM. As I can see there is no banked
 system control registers in AArch64. Seems the concept is changed to provide
 separate registers for each meaningful execution level. Please, correct me
 if I am wrong.
 Yes, I think this is generally correct.

 So I think there shouldn't be active and banked fields for banked
 AArch32 CP15 registers as in my patch. Seems it is worth to use AArch64 view
 of system control registers as a basis. That means there would be separate S
 and NS register fields in CPU state structure that will me mapped to
 separate AArch64 registers. ARMCPRegInfo structure would have additional
 field holding NS register state filed offset for AArch32 banked registers.
 This sounds like it could work, though there are some wrinkles for
 registers with readfns/writefns -- do we have extra s vs ns read/write
 functions, or just one set of functions which has to look in env-ns to
 figure out whether to use the S or NS version?

I think if most read/write functions do the same work for both S/NS
versions then this code should not be duplicated.


 Which branch in https://git.linaro.org/people/peter.maydell/qemu-arm.git
 repository holds the most actual A64 support?
 It's still a work in progress so it depends what you want.
 a64-third-fourth-set is the last set of patches that went out for
 review, and should generally work for integer instructions.
 a64-working is my work-in-progress branch so it will have the
 most recent versions of everything, but it rebases frequently
 and is liable to occasionally be broken...

Thanks.


 thanks
 -- PMM


-- 
Best regards,
Sergey Fedorov




Re: [Qemu-devel] [PATCHv2] block: add native support for NFS

2013-12-20 Thread Stefan Hajnoczi
On Fri, Dec 20, 2013 at 3:07 PM, Peter Lieven p...@kamp.de wrote:
 On 20.12.2013 14:57, Stefan Hajnoczi wrote:

 On Fri, Dec 20, 2013 at 1:53 PM, Peter Lieven p...@kamp.de wrote:

 On 20.12.2013 13:19, Stefan Hajnoczi wrote:

 On Fri, Dec 20, 2013 at 10:48:41AM +0100, Peter Lieven wrote:

 On 17.12.2013 17:47, Stefan Hajnoczi wrote:

 On Tue, Dec 17, 2013 at 10:15:25AM +0100, Peter Lieven wrote:

 +/* set to -ENOTSUP since bdrv_allocated_file_size is only used
 + * in qemu-img open. So we can use the cached value for allocate
 + * filesize obtained from fstat at open time */
 +client-allocated_file_size = -ENOTSUP;

 Can you implement this fully?  By stubbing it out like this we won't
 be
 able to call get_allocated_file_size() at runtime in the future
 without
 updating the nfs block driver code.  It's just an fstat call,
 shouldn't
 be too hard to implement properly :).

 It seems I have to leave it as is currently.
 bdrv_get_allocated_file_size
 is not in a coroutine context. I get coroutine yields to no one.

 Create a coroutine and pump the event loop until it has reached
 completion:

 co = qemu_coroutine_create(my_coroutine_fn, ...);
 qemu_coroutine_enter(co, foo);
 while (!complete) {
   qemu_aio_wait();
 }

 See block.c for similar examples.

 Wouldn't it make sense to make this modification to
 bdrv_get_allocated_file_size in
 block.c rather than in client/nfs.c and in the future potentially other
 drivers?

 If yes, I would ask you to take v3 of the NFS protocol patch and I
 promise
 to send
 a follow up early next year to make this modification to block.c and
 change
 block/nfs.c
 and other implementations to be a coroutine_fn.

 .bdrv_get_allocated_file_size() implementations in other block drivers
 are synchronous.  Making the block driver interface use coroutines
 would be wrong unless all the block drivers were updated to use
 coroutines too.

 I can do that. I think its not too complicated because all those
 implementations do not rely on callbacks. It should be possible
 to just rename the existing implemenations to lets say
 .bdrv_co_get_allocated_file_size and call them inside a coroutine.

No, that would be wrong because coroutine functions should not block.
The point of coroutines is that if they cannot proceed they must yield
so the event loop regains control.  If you simply rename the function
to _co_ then they will block the event loop and not be true coroutine
functions.


 Can you just call nfs_fstat() (the sync libnfs interface)?

 I can only do that if its guaranteed that no other requests are in flight
 otherwise it will mess up.

How will it mess up?

Stefan



Re: [Qemu-devel] [PATCHv2] block: add native support for NFS

2013-12-20 Thread Peter Lieven

On 20.12.2013 15:38, Stefan Hajnoczi wrote:

On Fri, Dec 20, 2013 at 3:07 PM, Peter Lieven p...@kamp.de wrote:

On 20.12.2013 14:57, Stefan Hajnoczi wrote:

On Fri, Dec 20, 2013 at 1:53 PM, Peter Lieven p...@kamp.de wrote:

On 20.12.2013 13:19, Stefan Hajnoczi wrote:

On Fri, Dec 20, 2013 at 10:48:41AM +0100, Peter Lieven wrote:

On 17.12.2013 17:47, Stefan Hajnoczi wrote:

On Tue, Dec 17, 2013 at 10:15:25AM +0100, Peter Lieven wrote:

+/* set to -ENOTSUP since bdrv_allocated_file_size is only used
+ * in qemu-img open. So we can use the cached value for allocate
+ * filesize obtained from fstat at open time */
+client-allocated_file_size = -ENOTSUP;

Can you implement this fully?  By stubbing it out like this we won't
be
able to call get_allocated_file_size() at runtime in the future
without
updating the nfs block driver code.  It's just an fstat call,
shouldn't
be too hard to implement properly :).

It seems I have to leave it as is currently.
bdrv_get_allocated_file_size
is not in a coroutine context. I get coroutine yields to no one.

Create a coroutine and pump the event loop until it has reached
completion:

co = qemu_coroutine_create(my_coroutine_fn, ...);
qemu_coroutine_enter(co, foo);
while (!complete) {
   qemu_aio_wait();
}

See block.c for similar examples.

Wouldn't it make sense to make this modification to
bdrv_get_allocated_file_size in
block.c rather than in client/nfs.c and in the future potentially other
drivers?

If yes, I would ask you to take v3 of the NFS protocol patch and I
promise
to send
a follow up early next year to make this modification to block.c and
change
block/nfs.c
and other implementations to be a coroutine_fn.

.bdrv_get_allocated_file_size() implementations in other block drivers
are synchronous.  Making the block driver interface use coroutines
would be wrong unless all the block drivers were updated to use
coroutines too.

I can do that. I think its not too complicated because all those
implementations do not rely on callbacks. It should be possible
to just rename the existing implemenations to lets say
.bdrv_co_get_allocated_file_size and call them inside a coroutine.

No, that would be wrong because coroutine functions should not block.
The point of coroutines is that if they cannot proceed they must yield
so the event loop regains control.  If you simply rename the function
to _co_ then they will block the event loop and not be true coroutine
functions.


Can you just call nfs_fstat() (the sync libnfs interface)?

I can only do that if its guaranteed that no other requests are in flight
otherwise it will mess up.

How will it mess up?

The sync calls into libnfs are just wrappers around the async calls.
The problem is that this wrapper will handle all the callbacks for the
in-flight requests and they will never return.

Peter




Re: [Qemu-devel] [PATCH] PPC: Fix compilation with TCG debug

2013-12-20 Thread Tom Musta
On 12/20/2013 4:01 AM, Alexander Graf wrote:
 The recent VSX patches broken compilation of QEMU when configurated
 with --enable-debug, as it was treating target long TCG variables
 as i64 which is not true for 32bit targets.
 
 This patch fixes all the places that the compiler has found to use
 the correct variable type and if necessary manually cast.
 
 Reported-by: Stefan Weil s...@weilnetz.de
 Signed-off-by: Alexander Graf ag...@suse.de
 ---

Alex:  I suspect my other VSX patches have the same problem.  I will look at
those.






[Qemu-devel] [PATCH] scsi-disk: add non-zero MAX UNMAP LBA COUNT to block limits VPD page

2013-12-20 Thread Paolo Bonzini
Linux prefers WRITE SAME to UNMAP if the count is zero, and WRITE
SAME does not discard anything unless the device can guarantee that
the resulting block is zero.

This fixes thin provisioning on glusterfs.

Reported-by: Bharata B Rao bhar...@linux.vnet.ibm.com
Signed-off-by: Paolo Bonzini pbonz...@redhat.com
---
 hw/scsi/scsi-disk.c | 11 +++
 1 file changed, 11 insertions(+)

diff --git a/hw/scsi/scsi-disk.c b/hw/scsi/scsi-disk.c
index 7653411..156c965 100644
--- a/hw/scsi/scsi-disk.c
+++ b/hw/scsi/scsi-disk.c
@@ -74,6 +74,7 @@ struct SCSIDiskState
 bool media_event;
 bool eject_request;
 uint64_t wwn;
+uint64_t max_unmap_size;
 QEMUBH *bh;
 char *version;
 char *serial;
@@ -625,6 +626,8 @@ static int scsi_disk_emulate_inquiry(SCSIRequest *req, 
uint8_t *outbuf)
 s-qdev.conf.min_io_size / s-qdev.blocksize;
 unsigned int opt_io_size =
 s-qdev.conf.opt_io_size / s-qdev.blocksize;
+   unsigned int max_unmap_sectors =
+   s-max_unmap_size / s-qdev.blocksize; /* 1 GB */
 
 if (s-qdev.type == TYPE_ROM) {
 DPRINTF(Inquiry (EVPD[%02X] not supported for CDROM\n,
@@ -647,6 +650,12 @@ static int scsi_disk_emulate_inquiry(SCSIRequest *req, 
uint8_t *outbuf)
 outbuf[14] = (opt_io_size  8)  0xff;
 outbuf[15] = opt_io_size  0xff;
 
+/* maximum unmap LBA count, hardcoded to 1GB */
+outbuf[20] = (max_unmap_sectors  24)  0xff;
+outbuf[21] = (max_unmap_sectors  16)  0xff;
+outbuf[22] = (max_unmap_sectors  8)  0xff;
+outbuf[23] = max_unmap_sectors  0xff;
+
 /* optimal unmap granularity */
 outbuf[28] = (unmap_sectors  24)  0xff;
 outbuf[29] = (unmap_sectors  16)  0xff;
@@ -2519,6 +2528,7 @@ static Property scsi_hd_properties[] = {
 DEFINE_PROP_BIT(dpofua, SCSIDiskState, features,
 SCSI_DISK_F_DPOFUA, false),
 DEFINE_PROP_HEX64(wwn, SCSIDiskState, wwn, 0),
+DEFINE_PROP_UINT64(max_unmap_size, SCSIDiskState, max_unmap_size, 1  
30),
 DEFINE_BLOCK_CHS_PROPERTIES(SCSIDiskState, qdev.conf),
 DEFINE_PROP_END_OF_LIST(),
 };
@@ -2628,6 +2638,7 @@ static Property scsi_disk_properties[] = {
 DEFINE_PROP_BIT(dpofua, SCSIDiskState, features,
 SCSI_DISK_F_DPOFUA, false),
 DEFINE_PROP_HEX64(wwn, SCSIDiskState, wwn, 0),
+DEFINE_PROP_UINT64(max_unmap_size, SCSIDiskState, max_unmap_size, 1  
30),
 DEFINE_PROP_END_OF_LIST(),
 };
 
-- 
1.8.4.2




Re: [Qemu-devel] [PATCHv2] block: add native support for NFS

2013-12-20 Thread ronnie sahlberg
The sync calls uses a trivial eventloop built into libnfs using poll().

Mixing the _async() and _sync() interfaces in libnfs means you may
risk running nested eventloops. Pain and tears lie behind that door.

On Fri, Dec 20, 2013 at 6:43 AM, Peter Lieven p...@kamp.de wrote:
 On 20.12.2013 15:38, Stefan Hajnoczi wrote:

 On Fri, Dec 20, 2013 at 3:07 PM, Peter Lieven p...@kamp.de wrote:

 On 20.12.2013 14:57, Stefan Hajnoczi wrote:

 On Fri, Dec 20, 2013 at 1:53 PM, Peter Lieven p...@kamp.de wrote:

 On 20.12.2013 13:19, Stefan Hajnoczi wrote:

 On Fri, Dec 20, 2013 at 10:48:41AM +0100, Peter Lieven wrote:

 On 17.12.2013 17:47, Stefan Hajnoczi wrote:

 On Tue, Dec 17, 2013 at 10:15:25AM +0100, Peter Lieven wrote:

 +/* set to -ENOTSUP since bdrv_allocated_file_size is only used
 + * in qemu-img open. So we can use the cached value for
 allocate
 + * filesize obtained from fstat at open time */
 +client-allocated_file_size = -ENOTSUP;

 Can you implement this fully?  By stubbing it out like this we won't
 be
 able to call get_allocated_file_size() at runtime in the future
 without
 updating the nfs block driver code.  It's just an fstat call,
 shouldn't
 be too hard to implement properly :).

 It seems I have to leave it as is currently.
 bdrv_get_allocated_file_size
 is not in a coroutine context. I get coroutine yields to no one.

 Create a coroutine and pump the event loop until it has reached
 completion:

 co = qemu_coroutine_create(my_coroutine_fn, ...);
 qemu_coroutine_enter(co, foo);
 while (!complete) {
qemu_aio_wait();
 }

 See block.c for similar examples.

 Wouldn't it make sense to make this modification to
 bdrv_get_allocated_file_size in
 block.c rather than in client/nfs.c and in the future potentially other
 drivers?

 If yes, I would ask you to take v3 of the NFS protocol patch and I
 promise
 to send
 a follow up early next year to make this modification to block.c and
 change
 block/nfs.c
 and other implementations to be a coroutine_fn.

 .bdrv_get_allocated_file_size() implementations in other block drivers
 are synchronous.  Making the block driver interface use coroutines
 would be wrong unless all the block drivers were updated to use
 coroutines too.

 I can do that. I think its not too complicated because all those
 implementations do not rely on callbacks. It should be possible
 to just rename the existing implemenations to lets say
 .bdrv_co_get_allocated_file_size and call them inside a coroutine.

 No, that would be wrong because coroutine functions should not block.
 The point of coroutines is that if they cannot proceed they must yield
 so the event loop regains control.  If you simply rename the function
 to _co_ then they will block the event loop and not be true coroutine
 functions.

 Can you just call nfs_fstat() (the sync libnfs interface)?

 I can only do that if its guaranteed that no other requests are in flight
 otherwise it will mess up.

 How will it mess up?

 The sync calls into libnfs are just wrappers around the async calls.
 The problem is that this wrapper will handle all the callbacks for the
 in-flight requests and they will never return.

 Peter





Re: [Qemu-devel] [PATCH] block/iscsi: return -ENOMEM if an async call fails immediately

2013-12-20 Thread ronnie sahlberg
Looks good.

Reviewed-by: Ronnie Sahlberg ronniesahlb...@gmail.com

On Fri, Dec 20, 2013 at 1:02 AM, Peter Lieven p...@kamp.de wrote:
 if an async libiscsi call fails directly it can only be due
 to an out of memory condition. All other errors are returned
 through the callback.

 Signed-off-by: Peter Lieven p...@kamp.de
 ---
  block/iscsi.c |   12 ++--
  1 file changed, 6 insertions(+), 6 deletions(-)

 diff --git a/block/iscsi.c b/block/iscsi.c
 index 56c0799..657a348 100644
 --- a/block/iscsi.c
 +++ b/block/iscsi.c
 @@ -308,7 +308,7 @@ retry:
  iscsi_co_generic_cb, iTask);
  if (iTask.task == NULL) {
  g_free(buf);
 -return -EIO;
 +return -ENOMEM;
  }
  #if defined(LIBISCSI_FEATURE_IOVECTOR)
  scsi_task_set_iov_out(iTask.task, (struct scsi_iovec *) iov-iov,
 @@ -376,7 +376,7 @@ retry:
  break;
  }
  if (iTask.task == NULL) {
 -return -EIO;
 +return -ENOMEM;
  }
  #if defined(LIBISCSI_FEATURE_IOVECTOR)
  scsi_task_set_iov_in(iTask.task, (struct scsi_iovec *) iov-iov, 
 iov-niov);
 @@ -419,7 +419,7 @@ static int coroutine_fn iscsi_co_flush(BlockDriverState 
 *bs)
  retry:
  if (iscsi_synchronizecache10_task(iscsilun-iscsi, iscsilun-lun, 0, 0, 
 0,
0, iscsi_co_generic_cb, iTask) == 
 NULL) {
 -return -EIO;
 +return -ENOMEM;
  }

  while (!iTask.complete) {
 @@ -669,7 +669,7 @@ retry:
sector_qemu2lun(sector_num, iscsilun),
8 + 16, iscsi_co_generic_cb,
iTask) == NULL) {
 -ret = -EIO;
 +ret = -ENOMEM;
  goto out;
  }

 @@ -753,7 +753,7 @@ coroutine_fn iscsi_co_discard(BlockDriverState *bs, 
 int64_t sector_num,
  retry:
  if (iscsi_unmap_task(iscsilun-iscsi, iscsilun-lun, 0, 0, list, 1,
   iscsi_co_generic_cb, iTask) == NULL) {
 -return -EIO;
 +return -ENOMEM;
  }

  while (!iTask.complete) {
 @@ -822,7 +822,7 @@ retry:
 iscsilun-zeroblock, iscsilun-block_size,
 nb_blocks, 0, !!(flags  BDRV_REQ_MAY_UNMAP),
 0, 0, iscsi_co_generic_cb, iTask) == NULL) {
 -return -EIO;
 +return -ENOMEM;
  }

  while (!iTask.complete) {
 --
 1.7.9.5




Re: [Qemu-devel] [PATCH] test: QOM interface casting

2013-12-20 Thread Igor Mammedov
On Fri, 20 Dec 2013 14:26:11 +0100
Igor Mammedov imamm...@redhat.com wrote:

Andreas,

test shows that commit:

qom: Do not register interface types in the type table 
https://github.com/afaerber/qemu-cpu/commit/7f00136ff5534ee651f4f10475170b8db18e5c03

regresses QOM Interface in case where interface is implemented
in not a leaf class, leading to abort.

 Add basic regression testing for QOM Interface usage.
 
 Signed-off-by: Igor Mammedov imamm...@redhat.com
 ---
 v2:
  - Peter Crosthwaite peter.crosthwa...@xilinx.com
* s/Parent/parent_obj/
* s/parent/parent_class/
  - Peter Maydell peter.mayd...@linaro.org
* s/interfacei/interface/
* tests/Makefile split too long line
  - Andreas Färber afaer...@suse.de
* consolidate QOM core object files in dedicated variable
* add SoB and commit message
 ---
  tests/Makefile  |6 ++-
  tests/check-qom-interface.c |  102 
 +++
  2 files changed, 107 insertions(+), 1 deletions(-)
  create mode 100644 tests/check-qom-interface.c
 
 diff --git a/tests/Makefile b/tests/Makefile
 index 379cdd9..89f8eff 100644
 --- a/tests/Makefile
 +++ b/tests/Makefile
 @@ -52,6 +52,8 @@ check-unit-y += tests/test-int128$(EXESUF)
  gcov-files-test-int128-y =
  check-unit-y += tests/test-bitops$(EXESUF)
  check-unit-y += tests/test-qdev-global-props$(EXESUF)
 +check-unit-y = tests/check-qom-interface$(EXESUF)
 +gcov-files-check-qdict-y = object/object.c
  
  check-block-$(CONFIG_POSIX) += tests/qemu-iotests-quick.sh
  
 @@ -137,6 +139,7 @@ test-qapi-obj-y = tests/test-qapi-visit.o 
 tests/test-qapi-types.o
  
  $(test-obj-y): QEMU_INCLUDES += -Itests
  QEMU_CFLAGS += -I$(SRC_PATH)/tests
 +qom-core-obj = qom/object.o qom/qom-qobject.o qom/container.o
  
  tests/test-x86-cpuid.o: QEMU_INCLUDES += -I$(SRC_PATH)/target-i386
  
 @@ -146,6 +149,7 @@ tests/check-qdict$(EXESUF): tests/check-qdict.o 
 libqemuutil.a
  tests/check-qlist$(EXESUF): tests/check-qlist.o libqemuutil.a
  tests/check-qfloat$(EXESUF): tests/check-qfloat.o libqemuutil.a
  tests/check-qjson$(EXESUF): tests/check-qjson.o libqemuutil.a libqemustub.a
 +tests/check-qom-interface$(EXESUF): tests/check-qom-interface.o 
 $(qom-core-obj) libqemuutil.a
  tests/test-coroutine$(EXESUF): tests/test-coroutine.o $(block-obj-y) 
 libqemuutil.a libqemustub.a
  tests/test-aio$(EXESUF): tests/test-aio.o $(block-obj-y) libqemuutil.a 
 libqemustub.a
  tests/test-throttle$(EXESUF): tests/test-throttle.o $(block-obj-y) 
 libqemuutil.a libqemustub.a
 @@ -159,7 +163,7 @@ tests/test-int128$(EXESUF): tests/test-int128.o
  tests/test-qdev-global-props$(EXESUF): tests/test-qdev-global-props.o \
   hw/core/qdev.o hw/core/qdev-properties.o \
   hw/core/irq.o \
 - qom/object.o qom/container.o qom/qom-qobject.o \
 + $(qom-core-obj) \
   $(test-qapi-obj-y) \
   libqemuutil.a libqemustub.a
  
 diff --git a/tests/check-qom-interface.c b/tests/check-qom-interface.c
 new file mode 100644
 index 000..8d7c1f8
 --- /dev/null
 +++ b/tests/check-qom-interface.c
 @@ -0,0 +1,102 @@
 +/*
 + * OQM interface test.
 + *
 + * Copyright (C) 2013 Red Hat Inc.
 + *
 + * Authors:
 + *  Igor Mammedov imamm...@redhat.com
 + *
 + * This work is licensed under the terms of the GNU LGPL, version 2.1 or 
 later.
 + * See the COPYING.LIB file in the top-level directory.
 + */
 +#include glib.h
 +
 +#include qom/object.h
 +#include qemu/module.h
 +
 +
 +#define TYPE_TEST_IF test-interface
 +#define TEST_IF_CLASS(klass) \
 + OBJECT_CLASS_CHECK(TestIfClass, (klass), TYPE_TEST_IF)
 +#define TEST_IF_GET_CLASS(obj) \
 + OBJECT_GET_CLASS(TestIfClass, (obj), TYPE_TEST_IF)
 +#define TEST_IF(obj) \
 + INTERFACE_CHECK(TestIf, (obj), TYPE_TEST_IF)
 +
 +typedef struct TestIf {
 +Object parent_obj;
 +} TestIf;
 +
 +typedef struct TestIfClass {
 +InterfaceClass parent_class;
 +
 +uint32_t test;
 +} TestIfClass;
 +
 +static const TypeInfo test_if_info = {
 +.name  = TYPE_TEST_IF,
 +.parent= TYPE_INTERFACE,
 +.class_size = sizeof(TestIfClass),
 +};
 +
 +#define PATTERN 0xFAFBFCFD
 +static void test_class_init(ObjectClass *oc, void *data)
 +{
 +TestIfClass *tc = TEST_IF_CLASS(oc);
 +
 +g_assert(tc);
 +tc-test = PATTERN;
 +}
 +
 +#define TYPE_DIRECT_IMPL direct-impl
 +static const TypeInfo direct_impl_info = {
 +.name = TYPE_DIRECT_IMPL,
 +.parent = TYPE_OBJECT,
 +.class_init = test_class_init,
 +.interfaces = (InterfaceInfo[]) {
 +{ TYPE_TEST_IF },
 +{ }
 +}
 +};
 +
 +#define TYPE_INTERMEDIATE_IMPL intermediate-impl
 +static const TypeInfo intermediate_impl_info = {
 +.name = TYPE_INTERMEDIATE_IMPL,
 +.parent = TYPE_DIRECT_IMPL,
 +};
 +
 +static void test_interface_impl(const char *type)
 +{
 +Object *obj = object_new(type);
 +TestIf *iobj = TEST_IF(obj);
 +TestIfClass *ico = TEST_IF_GET_CLASS(iobj);
 +
 +g_assert(iobj);
 +g_assert(ico-test == PATTERN);
 +}
 +
 +static void 

Re: [Qemu-devel] [PATCH] PPC: Fix compilation with TCG debug

2013-12-20 Thread Alexander Graf

On 20.12.2013, at 15:44, Tom Musta tommu...@gmail.com wrote:

 On 12/20/2013 4:01 AM, Alexander Graf wrote:
 The recent VSX patches broken compilation of QEMU when configurated
 with --enable-debug, as it was treating target long TCG variables
 as i64 which is not true for 32bit targets.
 
 This patch fixes all the places that the compiler has found to use
 the correct variable type and if necessary manually cast.
 
 Reported-by: Stefan Weil s...@weilnetz.de
 Signed-off-by: Alexander Graf ag...@suse.de
 ---
 
 Alex:  I suspect my other VSX patches have the same problem.  I will look at
 those.

Yes, please. Make sure to always compile ppc-softmmu alongside ppc64-softmmu 
and use --enable-debug when working on TCG.


Alex




Re: [Qemu-devel] [PATCHv2] block: add native support for NFS

2013-12-20 Thread Stefan Hajnoczi
On Fri, Dec 20, 2013 at 3:43 PM, Peter Lieven p...@kamp.de wrote:
 On 20.12.2013 15:38, Stefan Hajnoczi wrote:

 On Fri, Dec 20, 2013 at 3:07 PM, Peter Lieven p...@kamp.de wrote:

 On 20.12.2013 14:57, Stefan Hajnoczi wrote:

 On Fri, Dec 20, 2013 at 1:53 PM, Peter Lieven p...@kamp.de wrote:

 On 20.12.2013 13:19, Stefan Hajnoczi wrote:

 On Fri, Dec 20, 2013 at 10:48:41AM +0100, Peter Lieven wrote:

 On 17.12.2013 17:47, Stefan Hajnoczi wrote:

 On Tue, Dec 17, 2013 at 10:15:25AM +0100, Peter Lieven wrote:

 +/* set to -ENOTSUP since bdrv_allocated_file_size is only used
 + * in qemu-img open. So we can use the cached value for
 allocate
 + * filesize obtained from fstat at open time */
 +client-allocated_file_size = -ENOTSUP;

 Can you implement this fully?  By stubbing it out like this we won't
 be
 able to call get_allocated_file_size() at runtime in the future
 without
 updating the nfs block driver code.  It's just an fstat call,
 shouldn't
 be too hard to implement properly :).

 It seems I have to leave it as is currently.
 bdrv_get_allocated_file_size
 is not in a coroutine context. I get coroutine yields to no one.

 Create a coroutine and pump the event loop until it has reached
 completion:

 co = qemu_coroutine_create(my_coroutine_fn, ...);
 qemu_coroutine_enter(co, foo);
 while (!complete) {
qemu_aio_wait();
 }

 See block.c for similar examples.

 Wouldn't it make sense to make this modification to
 bdrv_get_allocated_file_size in
 block.c rather than in client/nfs.c and in the future potentially other
 drivers?

 If yes, I would ask you to take v3 of the NFS protocol patch and I
 promise
 to send
 a follow up early next year to make this modification to block.c and
 change
 block/nfs.c
 and other implementations to be a coroutine_fn.

 .bdrv_get_allocated_file_size() implementations in other block drivers
 are synchronous.  Making the block driver interface use coroutines
 would be wrong unless all the block drivers were updated to use
 coroutines too.

 I can do that. I think its not too complicated because all those
 implementations do not rely on callbacks. It should be possible
 to just rename the existing implemenations to lets say
 .bdrv_co_get_allocated_file_size and call them inside a coroutine.

 No, that would be wrong because coroutine functions should not block.
 The point of coroutines is that if they cannot proceed they must yield
 so the event loop regains control.  If you simply rename the function
 to _co_ then they will block the event loop and not be true coroutine
 functions.

 Can you just call nfs_fstat() (the sync libnfs interface)?

 I can only do that if its guaranteed that no other requests are in flight
 otherwise it will mess up.

 How will it mess up?

 The sync calls into libnfs are just wrappers around the async calls.
 The problem is that this wrapper will handle all the callbacks for the
 in-flight requests and they will never return.

So back to my original suggestion to use a qemu_aio_wait() loop in block/nfs.c?

Stefan



Re: [Qemu-devel] [PATCH v7 0/7] block: allow commit active as top

2013-12-20 Thread Stefan Hajnoczi
On Mon, Dec 16, 2013 at 02:45:26PM +0800, Fam Zheng wrote:
 Previously live commit of active block device is not supported, this series
 implements it and updates corresponding qemu-iotests cases.
 
 This series is based on BlockJobType enum QAPI series.
 
 v7: Fix Since 1.8 to Since 2.0.
 Rebase patch 05 to master.
 
 v6: Address comments from Stefan:
 
 [04/06] commit: support commit active layer
 Fix wording.
 [05/06] qemu-iotests: update test cases for commit active
 Drop is_active.
 
 Experimental for reviewers: the side by side diff against previous series:
 
 http://goo.gl/vgN6mc
 
 v5: Address comments from Eric and Paolo:
 Add mirror_start_job and front end wrapper. [Paolo]
 Base on BlockJobType enum in QAPI. [Eric]
 Drop common sync mode. [Eric]
 
 v4: Rewrite to reuse block/mirror.c.
 When committing the active layer, the job is internally a mirror job with
 type name faked to commit.
 When the job completes, the BDSes are swapped, so the base image become
 active and [top, base) dropped.
 
 
 Fam Zheng (7):
   blkdebug: Use QLIST_FOREACH_SAFE to resume IO
   mirror: Don't close target
   mirror: Move base to MirrorBlockJob
   block: Add commit_active_start()
   commit: Support commit active layer
   qemu-iotests: Update test cases for commit active
   commit: Remove unused check
 
  block/blkdebug.c  |  8 ++---
  block/commit.c|  8 +
  block/mirror.c| 78 
 +++
  blockdev.c|  9 --
  include/block/block_int.h | 22 +++--
  qapi-schema.json  |  5 +--
  tests/qemu-iotests/040| 74 +++-
  7 files changed, 131 insertions(+), 73 deletions(-)
 
 -- 
 1.8.5.1
 
 

Thanks, applied to my block tree:
https://github.com/stefanha/qemu/commits/block

Stefan



Re: [Qemu-devel] [PATCH] PPC: Fix compilation with TCG debug

2013-12-20 Thread Richard Henderson
On 12/20/2013 07:27 AM, Alexander Graf wrote:
 Yes, please. Make sure to always compile ppc-softmmu alongside ppc64-softmmu 
 and use --enable-debug when working on TCG.

Or --enable-debug-tcg.  If you only ever use --enable-debug, you can miss
warnings generated by the optimizer (e.g. may be used uninitialized).


r~




[Qemu-devel] [PULL 05/18] dataplane: replace hostmem with memory_region_find

2013-12-20 Thread Stefan Hajnoczi
From: Paolo Bonzini pbonz...@redhat.com

Signed-off-by: Paolo Bonzini pbonz...@redhat.com
Signed-off-by: Stefan Hajnoczi stefa...@redhat.com
---
 hw/virtio/dataplane/Makefile.objs |   2 +-
 hw/virtio/dataplane/hostmem.c | 183 --
 hw/virtio/dataplane/vring.c   |  78 +--
 include/hw/virtio/dataplane/hostmem.h |  58 ---
 include/hw/virtio/dataplane/vring.h   |   3 +-
 5 files changed, 72 insertions(+), 252 deletions(-)
 delete mode 100644 hw/virtio/dataplane/hostmem.c
 delete mode 100644 include/hw/virtio/dataplane/hostmem.h

diff --git a/hw/virtio/dataplane/Makefile.objs 
b/hw/virtio/dataplane/Makefile.objs
index a91bf33..9a8cfc0 100644
--- a/hw/virtio/dataplane/Makefile.objs
+++ b/hw/virtio/dataplane/Makefile.objs
@@ -1 +1 @@
-common-obj-y += hostmem.o vring.o
+common-obj-y += vring.o
diff --git a/hw/virtio/dataplane/hostmem.c b/hw/virtio/dataplane/hostmem.c
deleted file mode 100644
index 901d98b..000
--- a/hw/virtio/dataplane/hostmem.c
+++ /dev/null
@@ -1,183 +0,0 @@
-/*
- * Thread-safe guest to host memory mapping
- *
- * Copyright 2012 Red Hat, Inc. and/or its affiliates
- *
- * Authors:
- *   Stefan Hajnoczi stefa...@redhat.com
- *
- * This work is licensed under the terms of the GNU GPL, version 2 or later.
- * See the COPYING file in the top-level directory.
- *
- */
-
-#include exec/address-spaces.h
-#include hw/virtio/dataplane/hostmem.h
-
-static int hostmem_lookup_cmp(const void *phys_, const void *region_)
-{
-hwaddr phys = *(const hwaddr *)phys_;
-const HostMemRegion *region = region_;
-
-if (phys  region-guest_addr) {
-return -1;
-} else if (phys = region-guest_addr + region-size) {
-return 1;
-} else {
-return 0;
-}
-}
-
-/**
- * Map guest physical address to host pointer
- */
-void *hostmem_lookup(HostMem *hostmem, hwaddr phys, hwaddr len, bool is_write)
-{
-HostMemRegion *region;
-void *host_addr = NULL;
-hwaddr offset_within_region;
-
-qemu_mutex_lock(hostmem-current_regions_lock);
-region = bsearch(phys, hostmem-current_regions,
- hostmem-num_current_regions,
- sizeof(hostmem-current_regions[0]),
- hostmem_lookup_cmp);
-if (!region) {
-goto out;
-}
-if (is_write  region-readonly) {
-goto out;
-}
-offset_within_region = phys - region-guest_addr;
-if (len = region-size - offset_within_region) {
-host_addr = region-host_addr + offset_within_region;
-}
-out:
-qemu_mutex_unlock(hostmem-current_regions_lock);
-
-return host_addr;
-}
-
-/**
- * Install new regions list
- */
-static void hostmem_listener_commit(MemoryListener *listener)
-{
-HostMem *hostmem = container_of(listener, HostMem, listener);
-int i;
-
-qemu_mutex_lock(hostmem-current_regions_lock);
-for (i = 0; i  hostmem-num_current_regions; i++) {
-memory_region_unref(hostmem-current_regions[i].mr);
-}
-g_free(hostmem-current_regions);
-hostmem-current_regions = hostmem-new_regions;
-hostmem-num_current_regions = hostmem-num_new_regions;
-qemu_mutex_unlock(hostmem-current_regions_lock);
-
-/* Reset new regions list */
-hostmem-new_regions = NULL;
-hostmem-num_new_regions = 0;
-}
-
-/**
- * Add a MemoryRegionSection to the new regions list
- */
-static void hostmem_append_new_region(HostMem *hostmem,
-  MemoryRegionSection *section)
-{
-void *ram_ptr = memory_region_get_ram_ptr(section-mr);
-size_t num = hostmem-num_new_regions;
-size_t new_size = (num + 1) * sizeof(hostmem-new_regions[0]);
-
-hostmem-new_regions = g_realloc(hostmem-new_regions, new_size);
-hostmem-new_regions[num] = (HostMemRegion){
-.host_addr = ram_ptr + section-offset_within_region,
-.guest_addr = section-offset_within_address_space,
-.size = int128_get64(section-size),
-.readonly = section-readonly,
-.mr = section-mr,
-};
-hostmem-num_new_regions++;
-
-memory_region_ref(section-mr);
-}
-
-static void hostmem_listener_append_region(MemoryListener *listener,
-   MemoryRegionSection *section)
-{
-HostMem *hostmem = container_of(listener, HostMem, listener);
-
-/* Ignore non-RAM regions, we may not be able to map them */
-if (!memory_region_is_ram(section-mr)) {
-return;
-}
-
-/* Ignore regions with dirty logging, we cannot mark them dirty */
-if (memory_region_is_logging(section-mr)) {
-return;
-}
-
-hostmem_append_new_region(hostmem, section);
-}
-
-/* We don't implement most MemoryListener callbacks, use these nop stubs */
-static void hostmem_listener_dummy(MemoryListener *listener)
-{
-}
-
-static void hostmem_listener_section_dummy(MemoryListener *listener,
-   MemoryRegionSection *section)
-{
-}
-
-static void 

[Qemu-devel] [PULL 04/18] dataplane: change vring API to use VirtQueueElement

2013-12-20 Thread Stefan Hajnoczi
From: Paolo Bonzini pbonz...@redhat.com

Signed-off-by: Paolo Bonzini pbonz...@redhat.com
Signed-off-by: Stefan Hajnoczi stefa...@redhat.com
---
 hw/block/dataplane/virtio-blk.c | 85 ++---
 hw/virtio/dataplane/vring.c | 56 +++-
 include/hw/virtio/dataplane/vring.h |  7 ++-
 3 files changed, 72 insertions(+), 76 deletions(-)

diff --git a/hw/block/dataplane/virtio-blk.c b/hw/block/dataplane/virtio-blk.c
index 2b4a773..456d437 100644
--- a/hw/block/dataplane/virtio-blk.c
+++ b/hw/block/dataplane/virtio-blk.c
@@ -35,7 +35,7 @@ enum {
 typedef struct {
 struct iocb iocb;   /* Linux AIO control block */
 QEMUIOVector *inhdr;/* iovecs for virtio_blk_inhdr */
-unsigned int head;  /* vring descriptor index */
+VirtQueueElement *elem; /* saved data from the virtqueue */
 struct iovec *bounce_iov;   /* used if guest buffers are unaligned */
 QEMUIOVector *read_qiov;/* for read completion /w bounce buffer */
 } VirtIOBlockRequest;
@@ -96,7 +96,7 @@ static void complete_request(struct iocb *iocb, ssize_t ret, 
void *opaque)
 len = 0;
 }
 
-trace_virtio_blk_data_plane_complete_request(s, req-head, ret);
+trace_virtio_blk_data_plane_complete_request(s, req-elem-index, ret);
 
 if (req-read_qiov) {
 assert(req-bounce_iov);
@@ -118,12 +118,12 @@ static void complete_request(struct iocb *iocb, ssize_t 
ret, void *opaque)
  * written to, but for virtio-blk it seems to be the number of bytes
  * transferred plus the status bytes.
  */
-vring_push(s-vring, req-head, len + sizeof(hdr));
-
+vring_push(s-vring, req-elem, len + sizeof(hdr));
+req-elem = NULL;
 s-num_reqs--;
 }
 
-static void complete_request_early(VirtIOBlockDataPlane *s, unsigned int head,
+static void complete_request_early(VirtIOBlockDataPlane *s, VirtQueueElement 
*elem,
QEMUIOVector *inhdr, unsigned char status)
 {
 struct virtio_blk_inhdr hdr = {
@@ -134,26 +134,26 @@ static void complete_request_early(VirtIOBlockDataPlane 
*s, unsigned int head,
 qemu_iovec_destroy(inhdr);
 g_slice_free(QEMUIOVector, inhdr);
 
-vring_push(s-vring, head, sizeof(hdr));
+vring_push(s-vring, elem, sizeof(hdr));
 notify_guest(s);
 }
 
 /* Get disk serial number */
 static void do_get_id_cmd(VirtIOBlockDataPlane *s,
   struct iovec *iov, unsigned int iov_cnt,
-  unsigned int head, QEMUIOVector *inhdr)
+  VirtQueueElement *elem, QEMUIOVector *inhdr)
 {
 char id[VIRTIO_BLK_ID_BYTES];
 
 /* Serial number not NUL-terminated when shorter than buffer */
 strncpy(id, s-blk-serial ? s-blk-serial : , sizeof(id));
 iov_from_buf(iov, iov_cnt, 0, id, sizeof(id));
-complete_request_early(s, head, inhdr, VIRTIO_BLK_S_OK);
+complete_request_early(s, elem, inhdr, VIRTIO_BLK_S_OK);
 }
 
 static int do_rdwr_cmd(VirtIOBlockDataPlane *s, bool read,
-   struct iovec *iov, unsigned int iov_cnt,
-   long long offset, unsigned int head,
+   struct iovec *iov, unsigned iov_cnt,
+   long long offset, VirtQueueElement *elem,
QEMUIOVector *inhdr)
 {
 struct iocb *iocb;
@@ -186,19 +186,20 @@ static int do_rdwr_cmd(VirtIOBlockDataPlane *s, bool read,
 
 /* Fill in virtio block metadata needed for completion */
 VirtIOBlockRequest *req = container_of(iocb, VirtIOBlockRequest, iocb);
-req-head = head;
+req-elem = elem;
 req-inhdr = inhdr;
 req-bounce_iov = bounce_iov;
 req-read_qiov = read_qiov;
 return 0;
 }
 
-static int process_request(IOQueue *ioq, struct iovec iov[],
-   unsigned int out_num, unsigned int in_num,
-   unsigned int head)
+static int process_request(IOQueue *ioq, VirtQueueElement *elem)
 {
 VirtIOBlockDataPlane *s = container_of(ioq, VirtIOBlockDataPlane, ioqueue);
-struct iovec *in_iov = iov[out_num];
+struct iovec *iov = elem-out_sg;
+struct iovec *in_iov = elem-in_sg;
+unsigned out_num = elem-out_num;
+unsigned in_num = elem-in_num;
 struct virtio_blk_outhdr outhdr;
 QEMUIOVector *inhdr;
 size_t in_size;
@@ -229,29 +230,29 @@ static int process_request(IOQueue *ioq, struct iovec 
iov[],
 
 switch (outhdr.type) {
 case VIRTIO_BLK_T_IN:
-do_rdwr_cmd(s, true, in_iov, in_num, outhdr.sector * 512, head, inhdr);
+do_rdwr_cmd(s, true, in_iov, in_num, outhdr.sector * 512, elem, inhdr);
 return 0;
 
 case VIRTIO_BLK_T_OUT:
-do_rdwr_cmd(s, false, iov, out_num, outhdr.sector * 512, head, inhdr);
+do_rdwr_cmd(s, false, iov, out_num, outhdr.sector * 512, elem, inhdr);
 return 0;
 
 case VIRTIO_BLK_T_SCSI_CMD:
 /* TODO support SCSI commands */
-

[Qemu-devel] [PULL 01/18] sheepdog: fix dynamic grow for running qcow2 format

2013-12-20 Thread Stefan Hajnoczi
From: Liu Yuan namei.u...@gmail.com

When running qcow2 over sheepdog, we might meet following problem

  qemu-system-x86_64: shrinking is not supported

And cause IO errors to Guest. This is because we abuse bs-total_sectors, which
is manipulated by generic block layer and race with sheepdog code.

We should directly check if offset  vdi_size to dynamically enlarge the volume
instead of 'offset  bs-total_sectors', which will cause problem when following
case happens:

   vdi_size  offset  bs-total_sectors

   # then trigger sd_truncate() to shrink the volume wrongly.

Cc: qemu-devel@nongnu.org
Cc: Kevin Wolf kw...@redhat.com
Cc: Stefan Hajnoczi stefa...@redhat.com
Reported-by: Hadrien KOHL hadrien.k...@gmail.com
Signed-off-by: Liu Yuan namei.u...@gmail.com
Signed-off-by: Stefan Hajnoczi stefa...@redhat.com
---
 block/sheepdog.c | 7 ---
 1 file changed, 4 insertions(+), 3 deletions(-)

diff --git a/block/sheepdog.c b/block/sheepdog.c
index d1c812d..ba451a9 100644
--- a/block/sheepdog.c
+++ b/block/sheepdog.c
@@ -2048,13 +2048,14 @@ static coroutine_fn int sd_co_writev(BlockDriverState 
*bs, int64_t sector_num,
 {
 SheepdogAIOCB *acb;
 int ret;
+int64_t offset = (sector_num + nb_sectors) * BDRV_SECTOR_SIZE;
+BDRVSheepdogState *s = bs-opaque;
 
-if (bs-growable  sector_num + nb_sectors  bs-total_sectors) {
-ret = sd_truncate(bs, (sector_num + nb_sectors) * BDRV_SECTOR_SIZE);
+if (bs-growable  offset  s-inode.vdi_size) {
+ret = sd_truncate(bs, offset);
 if (ret  0) {
 return ret;
 }
-bs-total_sectors = sector_num + nb_sectors;
 }
 
 acb = sd_aio_setup(bs, qiov, sector_num, nb_sectors);
-- 
1.8.4.2




[Qemu-devel] [PULL 16/18] commit: Support commit active layer

2013-12-20 Thread Stefan Hajnoczi
From: Fam Zheng f...@redhat.com

If active is top, it will be mirrored to base, (with block/mirror.c
code), then the image is switched when user completes the block job.

QMP documentation is updated.

Signed-off-by: Fam Zheng f...@redhat.com
Signed-off-by: Stefan Hajnoczi stefa...@redhat.com
---
 block/mirror.c   | 11 +++
 blockdev.c   |  9 +++--
 qapi-schema.json |  5 +++--
 3 files changed, 21 insertions(+), 4 deletions(-)

diff --git a/block/mirror.c b/block/mirror.c
index 04af341..2932bab 100644
--- a/block/mirror.c
+++ b/block/mirror.c
@@ -481,6 +481,13 @@ immediate_exit:
 bdrv_reopen(s-target, bdrv_get_flags(s-common.bs), NULL);
 }
 bdrv_swap(s-target, s-common.bs);
+if (s-common.driver-job_type == BLOCK_JOB_TYPE_COMMIT) {
+/* drop the bs loop chain formed by the swap: break the loop then
+ * trigger the unref from the top one */
+BlockDriverState *p = s-base-backing_hd;
+s-base-backing_hd = NULL;
+bdrv_unref(p);
+}
 }
 bdrv_unref(s-target);
 block_job_completed(s-common, ret);
@@ -623,6 +630,10 @@ void commit_active_start(BlockDriverState *bs, 
BlockDriverState *base,
  BlockDriverCompletionFunc *cb,
  void *opaque, Error **errp)
 {
+if (bdrv_reopen(base, bs-open_flags, errp)) {
+return;
+}
+bdrv_ref(base);
 mirror_start_job(bs, base, speed, 0, 0,
  on_error, on_error, cb, opaque, errp,
  commit_active_job_driver, false, base);
diff --git a/blockdev.c b/blockdev.c
index 6a85961..2c3242b 100644
--- a/blockdev.c
+++ b/blockdev.c
@@ -1820,8 +1820,13 @@ void qmp_block_commit(const char *device,
 return;
 }
 
-commit_start(bs, base_bs, top_bs, speed, on_error, block_job_cb, bs,
-local_err);
+if (top_bs == bs) {
+commit_active_start(bs, base_bs, speed, on_error, block_job_cb,
+bs, local_err);
+} else {
+commit_start(bs, base_bs, top_bs, speed, on_error, block_job_cb, bs,
+local_err);
+}
 if (local_err != NULL) {
 error_propagate(errp, local_err);
 return;
diff --git a/qapi-schema.json b/qapi-schema.json
index 5aa4581..b9b051c 100644
--- a/qapi-schema.json
+++ b/qapi-schema.json
@@ -1967,9 +1967,11 @@
 #
 # @top:  The file name of the backing image within the image chain,
 #which contains the topmost data to be committed down.
-#Note, the active layer as 'top' is currently unsupported.
 #
 #If top == base, that is an error.
+#If top == active, the job will not be completed by itself,
+#user needs to complete the job with the block-job-complete
+#command after getting the ready event. (Since 2.0)
 #
 #
 # @speed:  #optional the maximum speed, in bytes per second
@@ -1979,7 +1981,6 @@
 #  If @device does not exist, DeviceNotFound
 #  If image commit is not supported by this device, NotSupported
 #  If @base or @top is invalid, a generic error is returned
-#  If @top is the active layer, or omitted, a generic error is returned
 #  If @speed is invalid, InvalidParameter
 #
 # Since: 1.3
-- 
1.8.4.2




[Qemu-devel] [PULL 02/18] vring: create a common function to parse descriptors

2013-12-20 Thread Stefan Hajnoczi
From: Paolo Bonzini pbonz...@redhat.com

Signed-off-by: Paolo Bonzini pbonz...@redhat.com
Signed-off-by: Stefan Hajnoczi stefa...@redhat.com
---
 hw/virtio/dataplane/vring.c | 113 
 1 file changed, 51 insertions(+), 62 deletions(-)

diff --git a/hw/virtio/dataplane/vring.c b/hw/virtio/dataplane/vring.c
index 351a343..8294f36 100644
--- a/hw/virtio/dataplane/vring.c
+++ b/hw/virtio/dataplane/vring.c
@@ -110,6 +110,47 @@ bool vring_should_notify(VirtIODevice *vdev, Vring *vring)
 return vring_need_event(vring_used_event(vring-vr), new, old);
 }
 
+
+static int get_desc(Vring *vring,
+struct iovec iov[], struct iovec *iov_end,
+unsigned int *out_num, unsigned int *in_num,
+struct vring_desc *desc)
+{
+unsigned *num;
+
+if (desc-flags  VRING_DESC_F_WRITE) {
+num = in_num;
+} else {
+num = out_num;
+
+/* If it's an output descriptor, they're all supposed
+ * to come before any input descriptors. */
+if (unlikely(*in_num)) {
+error_report(Descriptor has out after in);
+return -EFAULT;
+}
+}
+
+/* Stop for now if there are not enough iovecs available. */
+iov += *in_num + *out_num;
+if (iov = iov_end) {
+return -ENOBUFS;
+}
+
+/* TODO handle non-contiguous memory across region boundaries */
+iov-iov_base = hostmem_lookup(vring-hostmem, desc-addr, desc-len,
+   desc-flags  VRING_DESC_F_WRITE);
+if (!iov-iov_base) {
+error_report(Failed to map descriptor addr %# PRIx64  len %u,
+ (uint64_t)desc-addr, desc-len);
+return -EFAULT;
+}
+
+iov-iov_len = desc-len;
+*num += 1;
+return 0;
+}
+
 /* This is stolen from linux/drivers/vhost/vhost.c. */
 static int get_indirect(Vring *vring,
 struct iovec iov[], struct iovec *iov_end,
@@ -118,6 +159,7 @@ static int get_indirect(Vring *vring,
 {
 struct vring_desc desc;
 unsigned int i = 0, count, found = 0;
+int ret;
 
 /* Sanity check */
 if (unlikely(indirect-len % sizeof(desc))) {
@@ -170,36 +212,10 @@ static int get_indirect(Vring *vring,
 return -EFAULT;
 }
 
-/* Stop for now if there are not enough iovecs available. */
-if (iov = iov_end) {
-return -ENOBUFS;
-}
-
-iov-iov_base = hostmem_lookup(vring-hostmem, desc.addr, desc.len,
-   desc.flags  VRING_DESC_F_WRITE);
-if (!iov-iov_base) {
-error_report(Failed to map indirect descriptor
- addr %# PRIx64  len %u,
- (uint64_t)desc.addr, desc.len);
-vring-broken = true;
-return -EFAULT;
-}
-iov-iov_len = desc.len;
-iov++;
-
-/* If this is an input descriptor, increment that count. */
-if (desc.flags  VRING_DESC_F_WRITE) {
-*in_num += 1;
-} else {
-/* If it's an output descriptor, they're all supposed
- * to come before any input descriptors. */
-if (unlikely(*in_num)) {
-error_report(Indirect descriptor 
- has out after in: idx %u, i);
-vring-broken = true;
-return -EFAULT;
-}
-*out_num += 1;
+ret = get_desc(vring, iov, iov_end, out_num, in_num, desc);
+if (ret  0) {
+vring-broken |= (ret == -EFAULT);
+return ret;
 }
 i = desc.next;
 } while (desc.flags  VRING_DESC_F_NEXT);
@@ -224,6 +240,7 @@ int vring_pop(VirtIODevice *vdev, Vring *vring,
 struct vring_desc desc;
 unsigned int i, head, found = 0, num = vring-vr.num;
 uint16_t avail_idx, last_avail_idx;
+int ret;
 
 /* If there was a fatal error then refuse operation */
 if (vring-broken) {
@@ -294,40 +311,12 @@ int vring_pop(VirtIODevice *vdev, Vring *vring,
 continue;
 }
 
-/* If there are not enough iovecs left, stop for now.  The caller
- * should check if there are more descs available once they have dealt
- * with the current set.
- */
-if (iov = iov_end) {
-return -ENOBUFS;
+ret = get_desc(vring, iov, iov_end, out_num, in_num, desc);
+if (ret  0) {
+vring-broken |= (ret == -EFAULT);
+return ret;
 }
 
-/* TODO handle non-contiguous memory across region boundaries */
-iov-iov_base = hostmem_lookup(vring-hostmem, desc.addr, desc.len,
-   desc.flags  VRING_DESC_F_WRITE);
-if (!iov-iov_base) {
-error_report(Failed to map vring desc addr %# PRIx64  len %u,
- (uint64_t)desc.addr, desc.len);
-vring-broken = true;
-return 

[Qemu-devel] [PULL 12/18] qemu-iotests: drop duplicate virtio-blk initialization failure

2013-12-20 Thread Stefan Hajnoczi
Commit 75884afd5c6c42e523b08565e289dbe319e17ad9 (virtio-blk: Convert to
QOM realize) dropped a duplicate error_report() call.  Now we no longer
get the following error message twice:

  QEMU_PROG: -drive if=virtio: Device initialization failed.

Update qemu-iotests 051.

Signed-off-by: Stefan Hajnoczi stefa...@redhat.com
---
 tests/qemu-iotests/051.out | 1 -
 1 file changed, 1 deletion(-)

diff --git a/tests/qemu-iotests/051.out b/tests/qemu-iotests/051.out
index 49e95a2..c2cadba 100644
--- a/tests/qemu-iotests/051.out
+++ b/tests/qemu-iotests/051.out
@@ -91,7 +91,6 @@ Testing: -drive if=virtio
 QEMU X.Y.Z monitor - type 'help' for more information
 (qemu) QEMU_PROG: -drive if=virtio: Device needs media, but drive is empty
 QEMU_PROG: -drive if=virtio: Device initialization failed.
-QEMU_PROG: -drive if=virtio: Device initialization failed.
 QEMU_PROG: -drive if=virtio: Device 'virtio-blk-pci' could not be initialized
 
 Testing: -drive if=scsi
-- 
1.8.4.2




[Qemu-devel] [PULL 13/18] mirror: Don't close target

2013-12-20 Thread Stefan Hajnoczi
From: Fam Zheng f...@redhat.com

Let reference count manage target and don't call bdrv_close here.

Signed-off-by: Fam Zheng f...@redhat.com
Reviewed-by: Kevin Wolf kw...@redhat.com
Signed-off-by: Stefan Hajnoczi stefa...@redhat.com
---
 block/mirror.c | 1 -
 1 file changed, 1 deletion(-)

diff --git a/block/mirror.c b/block/mirror.c
index 6dc27ad..5b2c119 100644
--- a/block/mirror.c
+++ b/block/mirror.c
@@ -482,7 +482,6 @@ immediate_exit:
 }
 bdrv_swap(s-target, s-common.bs);
 }
-bdrv_close(s-target);
 bdrv_unref(s-target);
 block_job_completed(s-common, ret);
 }
-- 
1.8.4.2




[Qemu-devel] [PULL 06/18] qapi-schema: fix QEMU 1.8 references

2013-12-20 Thread Stefan Hajnoczi
We are moving boldly on to QEMU 2.0 in the next release.  Some patches
written at a time where we assumed 1.8 would be the next version number
managed to sneak in.

s/1.8/2.0/ in qapi-schema.json

Signed-off-by: Stefan Hajnoczi stefa...@redhat.com
Reviewed-by: Fam Zheng f...@redhat.com
Reviewed-by: Eric Blake ebl...@redhat.com
---
 qapi-schema.json | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/qapi-schema.json b/qapi-schema.json
index c3c939c..5aa4581 100644
--- a/qapi-schema.json
+++ b/qapi-schema.json
@@ -3022,7 +3022,7 @@
 #
 # @devname: #optional path of the netmap device (default: '/dev/netmap').
 #
-# Since 1.8
+# Since 2.0
 ##
 { 'type': 'NetdevNetmapOptions',
   'data': {
-- 
1.8.4.2




[Qemu-devel] [PULL 15/18] block: Add commit_active_start()

2013-12-20 Thread Stefan Hajnoczi
From: Fam Zheng f...@redhat.com

commit_active_start is implemented in block/mirror.c, It will create a
job with commit type and designated base in block-commit command. This
will be used for committing active layer of device.

Sync mode is removed from MirrorBlockJob because there's no proper type
for commit. The used information is is_none_mode.

The common part of mirror_start and commit_active_start is moved to
mirror_start_job().

Fix the comment wording for commit_start.

Signed-off-by: Fam Zheng f...@redhat.com
Reviewed-by: Kevin Wolf kw...@redhat.com
Signed-off-by: Stefan Hajnoczi stefa...@redhat.com
---
 block/mirror.c| 66 +++
 include/block/block_int.h | 22 +---
 2 files changed, 69 insertions(+), 19 deletions(-)

diff --git a/block/mirror.c b/block/mirror.c
index 605dda6..04af341 100644
--- a/block/mirror.c
+++ b/block/mirror.c
@@ -32,7 +32,7 @@ typedef struct MirrorBlockJob {
 RateLimit limit;
 BlockDriverState *target;
 BlockDriverState *base;
-MirrorSyncMode mode;
+bool is_none_mode;
 BlockdevOnError on_source_error, on_target_error;
 bool synced;
 bool should_complete;
@@ -336,7 +336,7 @@ static void coroutine_fn mirror_run(void *opaque)
 sectors_per_chunk = s-granularity  BDRV_SECTOR_BITS;
 mirror_free_init(s);
 
-if (s-mode != MIRROR_SYNC_MODE_NONE) {
+if (!s-is_none_mode) {
 /* First part, loop on the sectors and initialize the dirty bitmap.  */
 BlockDriverState *base = s-base;
 for (sector_num = 0; sector_num  end; ) {
@@ -535,15 +535,26 @@ static const BlockJobDriver mirror_job_driver = {
 .complete  = mirror_complete,
 };
 
-void mirror_start(BlockDriverState *bs, BlockDriverState *target,
-  int64_t speed, int64_t granularity, int64_t buf_size,
-  MirrorSyncMode mode, BlockdevOnError on_source_error,
-  BlockdevOnError on_target_error,
-  BlockDriverCompletionFunc *cb,
-  void *opaque, Error **errp)
+static const BlockJobDriver commit_active_job_driver = {
+.instance_size = sizeof(MirrorBlockJob),
+.job_type  = BLOCK_JOB_TYPE_COMMIT,
+.set_speed = mirror_set_speed,
+.iostatus_reset
+   = mirror_iostatus_reset,
+.complete  = mirror_complete,
+};
+
+static void mirror_start_job(BlockDriverState *bs, BlockDriverState *target,
+int64_t speed, int64_t granularity,
+int64_t buf_size,
+BlockdevOnError on_source_error,
+BlockdevOnError on_target_error,
+BlockDriverCompletionFunc *cb,
+void *opaque, Error **errp,
+const BlockJobDriver *driver,
+bool is_none_mode, BlockDriverState *base)
 {
 MirrorBlockJob *s;
-BlockDriverState *base = NULL;
 
 if (granularity == 0) {
 /* Choose the default granularity based on the target file's cluster
@@ -566,13 +577,8 @@ void mirror_start(BlockDriverState *bs, BlockDriverState 
*target,
 return;
 }
 
-if (mode == MIRROR_SYNC_MODE_TOP) {
-base = bs-backing_hd;
-} else {
-base = NULL;
-}
 
-s = block_job_create(mirror_job_driver, bs, speed, cb, opaque, errp);
+s = block_job_create(driver, bs, speed, cb, opaque, errp);
 if (!s) {
 return;
 }
@@ -580,7 +586,7 @@ void mirror_start(BlockDriverState *bs, BlockDriverState 
*target,
 s-on_source_error = on_source_error;
 s-on_target_error = on_target_error;
 s-target = target;
-s-mode = mode;
+s-is_none_mode = is_none_mode;
 s-base = base;
 s-granularity = granularity;
 s-buf_size = MAX(buf_size, granularity);
@@ -593,3 +599,31 @@ void mirror_start(BlockDriverState *bs, BlockDriverState 
*target,
 trace_mirror_start(bs, s, s-common.co, opaque);
 qemu_coroutine_enter(s-common.co, s);
 }
+
+void mirror_start(BlockDriverState *bs, BlockDriverState *target,
+  int64_t speed, int64_t granularity, int64_t buf_size,
+  MirrorSyncMode mode, BlockdevOnError on_source_error,
+  BlockdevOnError on_target_error,
+  BlockDriverCompletionFunc *cb,
+  void *opaque, Error **errp)
+{
+bool is_none_mode;
+BlockDriverState *base;
+
+is_none_mode = mode == MIRROR_SYNC_MODE_NONE;
+base = mode == MIRROR_SYNC_MODE_TOP ? bs-backing_hd : NULL;
+mirror_start_job(bs, target, speed, granularity, buf_size,
+ on_source_error, on_target_error, cb, opaque, errp,
+ mirror_job_driver, is_none_mode, base);
+}
+
+void commit_active_start(BlockDriverState *bs, BlockDriverState *base,
+ int64_t speed,
+ BlockdevOnError on_error,
+ 

[Qemu-devel] [PULL 17/18] qemu-iotests: Update test cases for commit active

2013-12-20 Thread Stefan Hajnoczi
From: Fam Zheng f...@redhat.com

Factor out commit test common logic into super class, and update test
of committing the active image.

Signed-off-by: Fam Zheng f...@redhat.com
Signed-off-by: Stefan Hajnoczi stefa...@redhat.com
---
 tests/qemu-iotests/040 | 74 ++
 1 file changed, 32 insertions(+), 42 deletions(-)

diff --git a/tests/qemu-iotests/040 b/tests/qemu-iotests/040
index 18dcd61..72eaad5 100755
--- a/tests/qemu-iotests/040
+++ b/tests/qemu-iotests/040
@@ -39,6 +39,29 @@ class ImageCommitTestCase(iotests.QMPTestCase):
 result = self.vm.qmp('query-block-jobs')
 self.assert_qmp(result, 'return', [])
 
+def run_commit_test(self, top, base):
+self.assert_no_active_commit()
+result = self.vm.qmp('block-commit', device='drive0', top=top, 
base=base)
+self.assert_qmp(result, 'return', {})
+
+completed = False
+while not completed:
+for event in self.vm.get_qmp_events(wait=True):
+if event['event'] == 'BLOCK_JOB_COMPLETED':
+self.assert_qmp(event, 'data/type', 'commit')
+self.assert_qmp(event, 'data/device', 'drive0')
+self.assert_qmp(event, 'data/offset', self.image_len)
+self.assert_qmp(event, 'data/len', self.image_len)
+completed = True
+elif event['event'] == 'BLOCK_JOB_READY':
+self.assert_qmp(event, 'data/type', 'commit')
+self.assert_qmp(event, 'data/device', 'drive0')
+self.assert_qmp(event, 'data/len', self.image_len)
+self.vm.qmp('block-job-complete', device='drive0')
+
+self.assert_no_active_commit()
+self.vm.shutdown()
+
 class TestSingleDrive(ImageCommitTestCase):
 image_len = 1 * 1024 * 1024
 test_len = 1 * 1024 * 256
@@ -59,23 +82,7 @@ class TestSingleDrive(ImageCommitTestCase):
 os.remove(backing_img)
 
 def test_commit(self):
-self.assert_no_active_commit()
-result = self.vm.qmp('block-commit', device='drive0', top='%s' % 
mid_img)
-self.assert_qmp(result, 'return', {})
-
-completed = False
-while not completed:
-for event in self.vm.get_qmp_events(wait=True):
-if event['event'] == 'BLOCK_JOB_COMPLETED':
-self.assert_qmp(event, 'data/type', 'commit')
-self.assert_qmp(event, 'data/device', 'drive0')
-self.assert_qmp(event, 'data/offset', self.image_len)
-self.assert_qmp(event, 'data/len', self.image_len)
-completed = True
-
-self.assert_no_active_commit()
-self.vm.shutdown()
-
+self.run_commit_test(mid_img, backing_img)
 self.assertEqual(-1, qemu_io('-c', 'read -P 0xab 0 524288', 
backing_img).find(verification failed))
 self.assertEqual(-1, qemu_io('-c', 'read -P 0xef 524288 524288', 
backing_img).find(verification failed))
 
@@ -102,10 +109,9 @@ class TestSingleDrive(ImageCommitTestCase):
 self.assert_qmp(result, 'error/desc', 'Base \'badfile\' not found')
 
 def test_top_is_active(self):
-self.assert_no_active_commit()
-result = self.vm.qmp('block-commit', device='drive0', top='%s' % 
test_img, base='%s' % backing_img)
-self.assert_qmp(result, 'error/class', 'GenericError')
-self.assert_qmp(result, 'error/desc', 'Top image as the active layer 
is currently unsupported')
+self.run_commit_test(test_img, backing_img)
+self.assertEqual(-1, qemu_io('-c', 'read -P 0xab 0 524288', 
backing_img).find(verification failed))
+self.assertEqual(-1, qemu_io('-c', 'read -P 0xef 524288 524288', 
backing_img).find(verification failed))
 
 def test_top_and_base_reversed(self):
 self.assert_no_active_commit()
@@ -166,23 +172,7 @@ class TestRelativePaths(ImageCommitTestCase):
 raise
 
 def test_commit(self):
-self.assert_no_active_commit()
-result = self.vm.qmp('block-commit', device='drive0', top='%s' % 
self.mid_img)
-self.assert_qmp(result, 'return', {})
-
-completed = False
-while not completed:
-for event in self.vm.get_qmp_events(wait=True):
-if event['event'] == 'BLOCK_JOB_COMPLETED':
-self.assert_qmp(event, 'data/type', 'commit')
-self.assert_qmp(event, 'data/device', 'drive0')
-self.assert_qmp(event, 'data/offset', self.image_len)
-self.assert_qmp(event, 'data/len', self.image_len)
-completed = True
-
-self.assert_no_active_commit()
-self.vm.shutdown()
-
+self.run_commit_test(self.mid_img, self.backing_img)
 self.assertEqual(-1, qemu_io('-c', 'read -P 0xab 0 524288', 
self.backing_img_abs).find(verification failed))
 

[Qemu-devel] [PULL 09/18] docs: updated qemu-img man page and qemu-doc to reflect VHDX support.

2013-12-20 Thread Stefan Hajnoczi
From: Jeff Cody jc...@redhat.com

The man page for qemu-img, and the qemu-doc, did not mention VHDX
as a supported format.  This adds in reference to VHDX in those
documents.

[Stefan Weil s...@weilnetz.de suggested s/Block Size/Block size/ for
consistency.  I have made this change.
--Stefan]

Signed-off-by: Jeff Cody jc...@redhat.com
Reviewed-by: Stefan Weil s...@weilnetz.de
Signed-off-by: Stefan Hajnoczi stefa...@redhat.com
---
 qemu-doc.texi | 15 +++
 qemu-img.texi |  4 ++--
 2 files changed, 17 insertions(+), 2 deletions(-)

diff --git a/qemu-doc.texi b/qemu-doc.texi
index 185dd47..4e9c6e9 100644
--- a/qemu-doc.texi
+++ b/qemu-doc.texi
@@ -654,6 +654,21 @@ Supported options:
 Specifies which VHD subformat to use. Valid options are
 @code{dynamic} (default) and @code{fixed}.
 @end table
+
+@item VHDX
+Hyper-V compatible image format (VHDX).
+Supported options:
+@table @code
+@item subformat
+Specifies which VHDX subformat to use. Valid options are
+@code{dynamic} (default) and @code{fixed}.
+@item block_state_zero
+Force use of payload blocks of type 'ZERO'.
+@item block_size
+Block size; min 1 MB, max 256 MB.  0 means auto-calculate based on image size.
+@item log_size
+Log size; min 1 MB.
+@end table
 @end table
 
 @subsubsection Read-only formats
diff --git a/qemu-img.texi b/qemu-img.texi
index be31191..1bba91e 100644
--- a/qemu-img.texi
+++ b/qemu-img.texi
@@ -431,8 +431,8 @@ This option can only be enabled if @code{compat=1.1} is 
specified.
 
 @item Other
 QEMU also supports various other image file formats for compatibility with
-older QEMU versions or other hypervisors, including VMDK, VDI, VHD (vpc), qcow1
-and QED. For a full list of supported formats see @code{qemu-img --help}.
+older QEMU versions or other hypervisors, including VMDK, VDI, VHD (vpc), VHDX,
+qcow1 and QED. For a full list of supported formats see @code{qemu-img --help}.
 For a more detailed description of these formats, see the QEMU Emulation User
 Documentation.
 
-- 
1.8.4.2




[Qemu-devel] [PATCH] Add DSDT node for AppleSMC

2013-12-20 Thread Gabriel L. Somlo
AppleSMC (-device isa-applesmc) is required to boot OS X guests.
OS X expects a SMC node to be present in the ACPI DSDT. This patch
adds a SMC node to the DSDT, and dynamically patches the return value
of SMC._STA to either 0x0B if the chip is present, or otherwise to 0x00,
before booting the guest.

Signed-off-by: Gabriel Somlo so...@cmu.edu
---
 hw/misc/applesmc.c|  1 -
 include/hw/isa/isa.h  |  2 ++
 hw/i386/acpi-dsdt.dsl |  1 +
 hw/i386/q35-acpi-dsdt.dsl |  1 +
 hw/i386/acpi-dsdt-isa.dsl | 14 ++
 hw/i386/acpi-build.c  | 10 ++
 6 files changed, 28 insertions(+), 1 deletion(-)

diff --git a/hw/misc/applesmc.c b/hw/misc/applesmc.c
index 1e8d183..627adb9 100644
--- a/hw/misc/applesmc.c
+++ b/hw/misc/applesmc.c
@@ -66,7 +66,6 @@ struct AppleSMCData {
 QLIST_ENTRY(AppleSMCData) node;
 };
 
-#define TYPE_APPLE_SMC isa-applesmc
 #define APPLE_SMC(obj) OBJECT_CHECK(AppleSMCState, (obj), TYPE_APPLE_SMC)
 
 typedef struct AppleSMCState AppleSMCState;
diff --git a/include/hw/isa/isa.h b/include/hw/isa/isa.h
index fa45a5b..5596cdc 100644
--- a/include/hw/isa/isa.h
+++ b/include/hw/isa/isa.h
@@ -20,6 +20,8 @@
 #define TYPE_ISA_BUS ISA
 #define ISA_BUS(obj) OBJECT_CHECK(ISABus, (obj), TYPE_ISA_BUS)
 
+#define TYPE_APPLE_SMC isa-applesmc
+
 typedef struct ISADeviceClass {
 DeviceClass parent_class;
 } ISADeviceClass;
diff --git a/hw/i386/acpi-dsdt.dsl b/hw/i386/acpi-dsdt.dsl
index a377424..7f8f147 100644
--- a/hw/i386/acpi-dsdt.dsl
+++ b/hw/i386/acpi-dsdt.dsl
@@ -114,6 +114,7 @@ DefinitionBlock (
 }
 }
 
+#define SMC_PFX piix_
 #include acpi-dsdt-isa.dsl
 
 
diff --git a/hw/i386/q35-acpi-dsdt.dsl b/hw/i386/q35-acpi-dsdt.dsl
index 575c5d7..7609e78 100644
--- a/hw/i386/q35-acpi-dsdt.dsl
+++ b/hw/i386/q35-acpi-dsdt.dsl
@@ -171,6 +171,7 @@ DefinitionBlock (
 }
 }
 
+#define SMC_PFX q35_
 #include acpi-dsdt-isa.dsl
 
 
diff --git a/hw/i386/acpi-dsdt-isa.dsl b/hw/i386/acpi-dsdt-isa.dsl
index 89caa16..410e658 100644
--- a/hw/i386/acpi-dsdt-isa.dsl
+++ b/hw/i386/acpi-dsdt-isa.dsl
@@ -13,9 +13,23 @@
  * with this program; if not, see http://www.gnu.org/licenses/.
  */
 
+#define _CONCAT_SYM(a, b) a##b
+#define CONCAT_SYM(a, b) _CONCAT_SYM(a, b)
+
 /* Common legacy ISA style devices. */
 Scope(\_SB.PCI0.ISA) {
 
+Device (SMC) {
+Name(_HID, EisaId(APP0001))
+/* _STA will be patched to 0x0B if AppleSMC is present */
+ACPI_EXTRACT_NAME_WORD_CONST CONCAT_SYM(SMC_PFX, smc_sta)
+Name(_STA, 0xFF00)
+Name(_CRS, ResourceTemplate () {
+IO (Decode16, 0x0300, 0x0300, 0x01, 0x20)
+IRQNoFlags() { 6 }
+})
+}
+
 Device(RTC) {
 Name(_HID, EisaId(PNP0B00))
 Name(_CRS, ResourceTemplate() {
diff --git a/hw/i386/acpi-build.c b/hw/i386/acpi-build.c
index 48312f5..529b655 100644
--- a/hw/i386/acpi-build.c
+++ b/hw/i386/acpi-build.c
@@ -36,6 +36,7 @@
 #include hw/nvram/fw_cfg.h
 #include bios-linker-loader.h
 #include hw/loader.h
+#include hw/isa/isa.h
 
 /* Supported chipsets: */
 #include hw/acpi/piix4.h
@@ -80,6 +81,8 @@ typedef struct AcpiMiscInfo {
 
 static void acpi_get_dsdt(AcpiMiscInfo *info)
 {
+unsigned short smc_sta_val = 0x00;
+unsigned short *smc_sta_off;
 Object *piix = piix4_pm_find();
 Object *lpc = ich9_lpc_find();
 assert(!!piix != !!lpc);
@@ -87,11 +90,18 @@ static void acpi_get_dsdt(AcpiMiscInfo *info)
 if (piix) {
 info-dsdt_code = AcpiDsdtAmlCode;
 info-dsdt_size = sizeof AcpiDsdtAmlCode;
+smc_sta_off = piix_smc_sta;
 }
 if (lpc) {
 info-dsdt_code = Q35AcpiDsdtAmlCode;
 info-dsdt_size = sizeof Q35AcpiDsdtAmlCode;
+smc_sta_off = q35_smc_sta;
 }
+
+/* Patch in appropriate value for AppleSMC _STA */
+if (object_resolve_path_type(, TYPE_APPLE_SMC, NULL))
+smc_sta_val = 0x0b; /* present, enabled, and functional */
+*(uint16_t *)(info-dsdt_code + *smc_sta_off) = cpu_to_le16(smc_sta_val);
 }
 
 static
-- 
1.8.1.4




  1   2   3   >