Re: [Qemu-devel] [PATCH][RFC 0/14] implement power chip

2013-03-18 Thread li guang
ping ...


在 2013-03-15五的 08:59 +0800,li guang写道:
 Hi, Anthony
 
 Sorry to bother you,
 can you please help to see it this work is
 worth to go on, or ...
 
 or someone else can help to see this patch-set.
 
 Thanks All.
 
 
 在 2013-03-13三的 16:01 +0800,liguang写道:
  By now, all devices of QEMU do not have much more
  power management consideration, for example, if
  system do suspend, it will call all registered notifiers,
  this was loosely required, and the code to do power management
  state transition seems just do 'ugly emulation', rather than be
  conscious with whole system devices, same condition with reset(it
  has been embedded in DeviceClass, good!),
  shutdown, in real world, commonly all devices' power are controlled
  by a power chip, then all power sequence can be done just
  issue commands to this chip.
  so, I come across an idea to implement qdev'ed power device, and
  make all qdev struct of devices aware of self power management(add
  on/off/wakeup/suspend ... filed for DeviceClass), this will
  bring tidy power management, and the emulation will more like what
  happened in real world.
  
  Of course, it's only a patch-set for RFC, I'd like to ask all 
  developers to help correct this idea, if it's worth to implement, 
  I'll go head to refactor more.
  
  Li Guang (14)
   gitignore: ignore more files
   qdev: add power management method
   qdev: remove redundant abort()
   qdev: add power on/off/suspend/wakeup handler
   power: add power chip emulation
   sysemu: remove PowerReason in sysemu.h
   acpi: refactor acpi wakeup function
   ich9: make lpc's reset also do pm_reset
   ich9: do lpc's power on by reset function
   piix4: refactor piix4's power callbacks
   pckbd: refactor pckbd's power callbacks
   ps2: call ps2_{kbd,mouse}_reset in kbd_reset
   parallel: refactor parallel_reset function
   uhci: refactor uhci's power callbacks
  
  .gitignore  |   3 +++
  Makefile.objs   |   1 +
  hw/acpi.c   |  20 +---
  hw/acpi.h   |   3 ++-
  hw/acpi_ich9.c  |   4 ++--
  hw/ich9.h   |   1 +
  hw/lpc_ich9.c   |  12 ++-
  hw/parallel.c   |  10 ++
  hw/pckbd.c  |  25 --
  hw/piix4.c  |  14 --
  hw/ps2.c|   8 
  hw/ps2.h|   2 ++
  hw/qdev-core.h  |  15 ++
  hw/qdev.c   |  99 +--
  hw/usb/hcd-uhci.c   |  10 ++
  include/sysemu/sysemu.h |   7 +--
  power.c | 133 
  +
  power.h |  41 +
  18 files changed, 365 insertions(+), 43 deletions(-)
   create mode 100644 power.c
   create mode 100644 power.h
  
  
  
 





[Qemu-devel] [PATCH] sheepdog: show error message for halt status

2013-03-18 Thread Liu Yuan
From: Liu Yuan tailai...@taobao.com

Sheepdog (neither quorum nor unsafe mode) will refuse to serve IO requests when
number of alive nodes is less than that of copies specified by users. This will
return 0x19 to QEMU client which currently doesn't recognize it.

This patch adds an error description when QEMU client receives it, other than
plainly printing 'Invalid error code'

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

diff --git a/block/sheepdog.c b/block/sheepdog.c
index 4245328..54d3e53 100644
--- a/block/sheepdog.c
+++ b/block/sheepdog.c
@@ -65,6 +65,7 @@
 #define SD_RES_WAIT_FOR_FORMAT  0x16 /* Waiting for a format operation */
 #define SD_RES_WAIT_FOR_JOIN0x17 /* Waiting for other nodes joining */
 #define SD_RES_JOIN_FAILED   0x18 /* Target node had failed to join sheepdog */
+#define SD_RES_HALT  0x19 /* Sheepdog is stopped serving IO request */
 
 /*
  * Object ID rules
@@ -344,6 +345,7 @@ static const char * sd_strerror(int err)
 {SD_RES_WAIT_FOR_FORMAT, Sheepdog is waiting for a format operation},
 {SD_RES_WAIT_FOR_JOIN, Sheepdog is waiting for other nodes joining},
 {SD_RES_JOIN_FAILED, Target node had failed to join sheepdog},
+{SD_RES_HALT, Sheepdog is stopped serving IO request},
 };
 
 for (i = 0; i  ARRAY_SIZE(errors); ++i) {
-- 
1.7.9.5




[Qemu-devel] [PATCH] HLFS driver for QEMU

2013-03-18 Thread harryxiyou
From: Harry Wei harryxi...@gmail.com

HLFS is HDFS-based(Hadoop Distributed File System) Log-Structured File
System. Actually, HLFS, currently, is not a FS but a block-storage system,
which we simplify LFS to fit block-level storage. So you could also call HLFS
as HLBS (HDFS-based Log-Structured Block-storage System).  HLFS has
two mode, which are local mode and HDFS mode. HDFS is once write and
many read so HLFS realize LBS(Log-Structured Block-storage System) to
achieve reading and writing randomly. LBS is based on LFS's basic theories
but is different from LFS, which LBS fits block storage better. See
http://code.google.com/p/cloudxy/wiki/WHAT_IS_CLOUDXY
about HLFS in details.

Currently, HLFS support following features:

1, Portions of POSIX --- Just realize some interfaces VM image need.
2, Randomly Read/Write.
3, Large file storage (TB).
4, Support snapshots(Linear snapshots and tree snapshots), Clone,
Block compression, Cache, etc.
5, A copy of the data more.
6, Cluster system can dynamic expand.
...

Signed-off-by: Harry Wei harryxi...@gmail.com

---
 block/Makefile.objs |2 +-
 block/hlfs.c|  515 +++
 configure   |   51 +
 3 files changed, 567 insertions(+), 1 deletion(-)
 create mode 100644 block/hlfs.c

diff --git a/block/Makefile.objs b/block/Makefile.objs
index c067f38..723c7a5 100644
--- a/block/Makefile.objs
+++ b/block/Makefile.objs
@@ -8,7 +8,7 @@ block-obj-$(CONFIG_POSIX) += raw-posix.o
 block-obj-$(CONFIG_LINUX_AIO) += linux-aio.o
 
 ifeq ($(CONFIG_POSIX),y)
-block-obj-y += nbd.o sheepdog.o
+block-obj-y += nbd.o sheepdog.o hlfs.o
 block-obj-$(CONFIG_LIBISCSI) += iscsi.o
 block-obj-$(CONFIG_CURL) += curl.o
 block-obj-$(CONFIG_RBD) += rbd.o
diff --git a/block/hlfs.c b/block/hlfs.c
new file mode 100644
index 000..331feae
--- /dev/null
+++ b/block/hlfs.c
@@ -0,0 +1,514 @@
+/*
+ * Block driver for HLFS(HDFS-based Log-structured File System)
+ *
+ * Copyright (c) 2013, Kang Hua kanghua...@gmail.com
+ * Copyright (c) 2013, Wang Sen kelvin.x...@gmail.com
+ * Copyright (c) 2013, Harry Wei harryxi...@gmail.com
+ *
+ * This program is free software. You can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 as published by
+ * the Free Software Foundation.
+ *
+ * Reference:
+ * http://code.google.com/p/cloudxy
+ */
+
+#include qemu-common.h
+#include qemu/error-report.h
+#include qemu/sockets.h
+#include block/block_int.h
+#include qemu/bitops.h
+#include api/hlfs.h
+#include storage_helper.h
+#include comm_define.h
+#include snapshot_helper.h
+#include address.h
+
+#define DEBUG_HLBS
+#undef dprintf
+#ifdef DEBUG_HLBS
+#define dprintf(fmt, args...) \
+do {\
+fprintf(stdout, %s %d:  fmt, __func__, __LINE__, ##args); \
+} while (0)
+#else
+#define dprintf(fmt, args...)
+#endif
+
+#define HLBS_MAX_VDI_SIZE (8192ULL*8192ULL*8192ULL*8192ULL)
+#define SECTOR_SIZE 512
+
+typedef struct BDRVHLBSState {
+struct hlfs_ctrl *hctrl;
+char *snapshot;
+char *uri;
+} BDRVHLBSState;
+
+/*
+ * Parse a filename.
+ *
+ * file name format must be one of the following:
+ *1. [vdiname]
+ *2. [vdiname]%[snapshot]
+ ** vdiname format --
+ ** local:///tmp/testenv/testfs
+ ** hdfs:///tmp/testenv/testfs
+ ** hdfs://localhost:8020/tmp/testenv/testfs
+ ** hdfs://localhost/tmp/testenv/testfs
+ ** hdfs://192.168.0.1:8020/tmp/testenv/testfs
+ */
+
+static int parse_vdiname(BDRVHLBSState *s, const char *filename, char *vdi,
+char *snapshot)
+{
+if (!filename) {
+return -1;
+}
+
+gchar **v = g_strsplit(filename, %, 2);
+if (g_strv_length(v) == 1) {
+strcpy(vdi, v[0]);
+s-uri = g_strdup(vdi);
+} else if (g_strv_length(v) == 2) {
+strcpy(vdi, v[0]);
+strcpy(snapshot, v[1]);
+s-uri = g_strdup(vdi);
+s-snapshot = g_strdup(snapshot);
+} else {
+goto out;
+}
+
+return 0;
+out:
+g_strfreev(v);
+return -1;
+}
+
+static int hlbs_open(BlockDriverState *bs, const char *filename, int flags)
+{
+int ret = 0;
+BDRVHLBSState *s = bs-opaque;
+char vdi[256];
+char snapshot[HLFS_FILE_NAME_MAX];
+
+strstart(filename, hlfs:, (const char **)filename);
+memset(snapshot, 0, sizeof(snapshot));
+memset(vdi, 0, sizeof(vdi));
+
+if (parse_vdiname(s, filename, vdi, snapshot)  0) {
+goto out;
+}
+
+HLFS_CTRL *ctrl = init_hlfs(vdi);
+if (strlen(snapshot)) {
+dprintf(snapshot:%s was open.\n, snapshot);
+ret = hlfs_open_by_snapshot(ctrl, snapshot, 1);
+} else {
+ret = hlfs_open(ctrl, 1);
+}
+g_assert(ret == 0);
+s-hctrl = ctrl;
+bs-total_sectors = ctrl-sb.max_fs_size * 1024 * 1024 / SECTOR_SIZE;
+return 0;
+out:
+if (s-hctrl) {
+hlfs_close(s-hctrl);
+deinit_hlfs(s-hctrl);
+}
+return -1;
+}
+
+static int hlbs_create(const char *filename, 

Re: [Qemu-devel] [RFC] qmp interface for save vmstate to image

2013-03-18 Thread Wenchao Xia
于 2013-3-15 22:51, Stefan Hajnoczi 写道:
 On Fri, Mar 15, 2013 at 03:24:38PM +0800, Wenchao Xia wrote:
I'd like to add a new way to save vmstate, which will based on the
 migration thread, but will write contents to block images, instead
 of fd as stream. Following is the method to add API:
 
 Hi Wenchao,
 What use cases are there besides saving vmstate to a raw image?
 
 I'm curious if you're proposing this since there is no file: URI or
 because you really want to do things like saving vmstate into a qcow2
 file or over NBD.
 
 Stefan
 
Hi, Stefan
  Most used cases would be raw and qcow2, which is flex and can be
chosen by user. In this way, existing block layer feature in qemu can
be used, such as tagging zeros. I haven't check the buffer/cache status
in qemu block layer, but if there is, it can also benefit.
  User can specify raw or qcow2 according to host configuration, If
there is dedicated storage components underlining, he can use raw to
skip qemu's block layer.

-- 
Best Regards

Wenchao Xia




[Qemu-devel] [PATCH] HLFS driver for QEMU

2013-03-18 Thread harryxiyou
From: Harry Wei harryxi...@gmail.com

HLFS is HDFS-based(Hadoop Distributed File System) Log-Structured File
System. Actually, HLFS, currently, is not a FS but a block-storage system,
which we simplify LFS to fit block-level storage. So you could also call HLFS
as HLBS (HDFS-based Log-Structured Block-storage System).  HLFS has
two mode, which are local mode and HDFS mode. HDFS is once write and
many read so HLFS realize LBS(Log-Structured Block-storage System) to
achieve reading and writing randomly. LBS is based on LFS's basic theories
but is different from LFS, which LBS fits block storage better. See
http://code.google.com/p/cloudxy/wiki/WHAT_IS_CLOUDXY
about HLFS in details.

Currently, HLFS support following features:

1, Portions of POSIX --- Just realize some interfaces VM image need.
2, Randomly Read/Write.
3, Large file storage (TB).
4, Support snapshots(Linear snapshots and tree snapshots), Clone,
Block compression, Cache, etc.
5, A copy of the data more.
6, Cluster system can dynamic expand.
...

Signed-off-by: Harry Wei harryxi...@gmail.com

---
 block/Makefile.objs |2 +-
 block/hlfs.c|  515 +++
 configure   |   51 +
 3 files changed, 567 insertions(+), 1 deletion(-)
 create mode 100644 block/hlfs.c

diff --git a/block/Makefile.objs b/block/Makefile.objs
index c067f38..723c7a5 100644
--- a/block/Makefile.objs
+++ b/block/Makefile.objs
@@ -8,7 +8,7 @@ block-obj-$(CONFIG_POSIX) += raw-posix.o
 block-obj-$(CONFIG_LINUX_AIO) += linux-aio.o
 
 ifeq ($(CONFIG_POSIX),y)
-block-obj-y += nbd.o sheepdog.o
+block-obj-y += nbd.o sheepdog.o hlfs.o
 block-obj-$(CONFIG_LIBISCSI) += iscsi.o
 block-obj-$(CONFIG_CURL) += curl.o
 block-obj-$(CONFIG_RBD) += rbd.o
diff --git a/block/hlfs.c b/block/hlfs.c
new file mode 100644
index 000..331feae
--- /dev/null
+++ b/block/hlfs.c
@@ -0,0 +1,514 @@
+/*
+ * Block driver for HLFS(HDFS-based Log-structured File System)
+ *
+ * Copyright (c) 2013, Kang Hua kanghua...@gmail.com
+ * Copyright (c) 2013, Wang Sen kelvin.x...@gmail.com
+ * Copyright (c) 2013, Harry Wei harryxi...@gmail.com
+ *
+ * This program is free software. You can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 as published by
+ * the Free Software Foundation.
+ *
+ * Reference:
+ * http://code.google.com/p/cloudxy
+ */
+
+#include qemu-common.h
+#include qemu/error-report.h
+#include qemu/sockets.h
+#include block/block_int.h
+#include qemu/bitops.h
+#include api/hlfs.h
+#include storage_helper.h
+#include comm_define.h
+#include snapshot_helper.h
+#include address.h
+
+#define DEBUG_HLBS
+#undef dprintf
+#ifdef DEBUG_HLBS
+#define dprintf(fmt, args...) \
+do {\
+fprintf(stdout, %s %d:  fmt, __func__, __LINE__, ##args); \
+} while (0)
+#else
+#define dprintf(fmt, args...)
+#endif
+
+#define HLBS_MAX_VDI_SIZE (8192ULL*8192ULL*8192ULL*8192ULL)
+#define SECTOR_SIZE 512
+
+typedef struct BDRVHLBSState {
+struct hlfs_ctrl *hctrl;
+char *snapshot;
+char *uri;
+} BDRVHLBSState;
+
+/*
+ * Parse a filename.
+ *
+ * file name format must be one of the following:
+ *1. [vdiname]
+ *2. [vdiname]%[snapshot]
+ ** vdiname format --
+ ** local:///tmp/testenv/testfs
+ ** hdfs:///tmp/testenv/testfs
+ ** hdfs://localhost:8020/tmp/testenv/testfs
+ ** hdfs://localhost/tmp/testenv/testfs
+ ** hdfs://192.168.0.1:8020/tmp/testenv/testfs
+ */
+
+static int parse_vdiname(BDRVHLBSState *s, const char *filename, char *vdi,
+char *snapshot)
+{
+if (!filename) {
+return -1;
+}
+
+gchar **v = g_strsplit(filename, %, 2);
+if (g_strv_length(v) == 1) {
+strcpy(vdi, v[0]);
+s-uri = g_strdup(vdi);
+} else if (g_strv_length(v) == 2) {
+strcpy(vdi, v[0]);
+strcpy(snapshot, v[1]);
+s-uri = g_strdup(vdi);
+s-snapshot = g_strdup(snapshot);
+} else {
+goto out;
+}
+
+return 0;
+out:
+g_strfreev(v);
+return -1;
+}
+
+static int hlbs_open(BlockDriverState *bs, const char *filename, int flags)
+{
+int ret = 0;
+BDRVHLBSState *s = bs-opaque;
+char vdi[256];
+char snapshot[HLFS_FILE_NAME_MAX];
+
+strstart(filename, hlfs:, (const char **)filename);
+memset(snapshot, 0, sizeof(snapshot));
+memset(vdi, 0, sizeof(vdi));
+
+if (parse_vdiname(s, filename, vdi, snapshot)  0) {
+goto out;
+}
+
+HLFS_CTRL *ctrl = init_hlfs(vdi);
+if (strlen(snapshot)) {
+dprintf(snapshot:%s was open.\n, snapshot);
+ret = hlfs_open_by_snapshot(ctrl, snapshot, 1);
+} else {
+ret = hlfs_open(ctrl, 1);
+}
+g_assert(ret == 0);
+s-hctrl = ctrl;
+bs-total_sectors = ctrl-sb.max_fs_size * 1024 * 1024 / SECTOR_SIZE;
+return 0;
+out:
+if (s-hctrl) {
+hlfs_close(s-hctrl);
+deinit_hlfs(s-hctrl);
+}
+return -1;
+}
+
+static int hlbs_create(const char *filename, 

Re: [Qemu-devel] [PATCH] sheepdog: show error message for halt status

2013-03-18 Thread MORITA Kazutaka
At Mon, 18 Mar 2013 14:27:55 +0800,
Liu Yuan wrote:
 
 From: Liu Yuan tailai...@taobao.com
 
 Sheepdog (neither quorum nor unsafe mode) will refuse to serve IO requests 
 when
 number of alive nodes is less than that of copies specified by users. This 
 will
 return 0x19 to QEMU client which currently doesn't recognize it.
 
 This patch adds an error description when QEMU client receives it, other than
 plainly printing 'Invalid error code'
 
 Cc: MORITA Kazutaka morita.kazut...@lab.ntt.co.jp
 Cc: Kevin Wolf kw...@redhat.com
 Cc: Stefan Hajnoczi stefa...@redhat.com
 Signed-off-by: Liu Yuan tailai...@taobao.com
 ---
  block/sheepdog.c |2 ++
  1 file changed, 2 insertions(+)

Reviewed-by: MORITA Kazutaka morita.kazut...@lab.ntt.co.jp



[Qemu-devel] [Bug 1155403] Re: virtio cdrom detected as hard disk

2013-03-18 Thread Laszlo Ersek
Consider filing a Debian/Ubuntu bug so that their initramfs / installer
/ live disk comes with virtio-scsi. See eg.
https://bugzilla.redhat.com/show_bug.cgi?id=864012

** Bug watch added: Red Hat Bugzilla #864012
   https://bugzilla.redhat.com/show_bug.cgi?id=864012

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

Title:
  virtio cdrom detected as hard disk

Status in QEMU:
  Invalid
Status in “qemu” package in Ubuntu:
  Invalid

Bug description:
  Trying to install Ubuntu or Debian using virtio to emulate the cdrom
  fails.  This appears to be due to the drive appearing to be a hard
  disk, rather than a cdrom, despite the media=cdrom argument to qemu.

  I'm not sure if this is a bug in qemu, or the kernel virtio driver?

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



Re: [Qemu-devel] [PATCH][RFC 02/14] qdev: add power management method

2013-03-18 Thread Andreas Färber
Am 13.03.2013 09:01, schrieb liguang:
 In fact, every devices have to be aware of
 it's power management, so it can decide what
 to do when platform board switch it's power
 state between on/off/suspend/wakeup.
 
 Signed-off-by: liguang lig.f...@cn.fujitsu.com
 ---
  hw/qdev-core.h |6 ++
  1 files changed, 6 insertions(+), 0 deletions(-)
 
 diff --git a/hw/qdev-core.h b/hw/qdev-core.h
 index 2486f36..e69c50b 100644
 --- a/hw/qdev-core.h
 +++ b/hw/qdev-core.h
 @@ -85,6 +85,12 @@ typedef struct DeviceClass {
  Property *props;
  int no_user;
  
 +/* power management */
 +void (*on)(DeviceState *dev);
 +void (*off)(DeviceState *dev);
 +void (*suspend)(DeviceState *dev);
 +void (*wakeup)(DeviceState *dev);
 +
  /* callbacks */
  void (*reset)(DeviceState *dev);
  DeviceRealize realize;

Whatever callbacks get added, they should be added down here and get
gtk-doc documentation above the struct. That should also include some
guidelines on how new devices should implement these (hint: we'd want to
avoid code duplication).

I have the feeling your hooks may be rather x86-specific - have you
checked against any other architecture?

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][RFC 03/14] qdev: remove redundant abort()

2013-03-18 Thread Andreas Färber
Am 13.03.2013 09:01, schrieb liguang:
 Signed-off-by: liguang lig.f...@cn.fujitsu.com
 ---
  hw/qdev.c |3 +--
  1 files changed, 1 insertions(+), 2 deletions(-)
 
 diff --git a/hw/qdev.c b/hw/qdev.c
 index 689cd54..2bed9d8 100644
 --- a/hw/qdev.c
 +++ b/hw/qdev.c
 @@ -116,11 +116,10 @@ DeviceState *qdev_create(BusState *bus, const char 
 *name)
  if (bus) {
  error_report(Unknown device '%s' for bus '%s', name,
   object_get_typename(OBJECT(bus)));
 -abort();
  } else {
  error_report(Unknown device '%s' for default sysbus, name);
 -abort();
  }
 +abort();
  }
  
  return dev;

Reviewed-by: Andreas Färber afaer...@suse.de

However this being a fatal abort, it doesn't really matter too much.

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][RFC 04/14] qdev: add power on/off/suspend/wakeup handler

2013-03-18 Thread Andreas Färber
Am 13.03.2013 09:01, schrieb liguang:
 Signed-off-by: liguang lig.f...@cn.fujitsu.com
 ---
  hw/qdev-core.h |9 +
  hw/qdev.c  |   96 
 
  2 files changed, 105 insertions(+), 0 deletions(-)
 
 diff --git a/hw/qdev-core.h b/hw/qdev-core.h
 index e69c50b..805ac69 100644
 --- a/hw/qdev-core.h
 +++ b/hw/qdev-core.h
 @@ -262,6 +262,15 @@ void qdev_reset_all(DeviceState *dev);
  void qbus_reset_all(BusState *bus);
  void qbus_reset_all_fn(void *opaque);
  
 +void qdev_power_on(DeviceState *dev);
 +void qdev_power_off(DeviceState *dev);
 +void qdev_power_wakeup(DeviceState *dev);
 +void qdev_power_suspend(DeviceState *dev);

No new qdev_ functions please. qdev no longer exists in its original
form since the QOM introduction. Please use device_ instead.

Note that here you use power_*, so it may be worth using an identical
callback field name for at least on and off if we go with your concept.

Andreas

 +void qbus_power_off(void *opaque);
 +void qbus_power_wakeup(void *opaque);
 +void qbus_power_suspend(void *opaque);
 +void qbus_power_on(void *opaque);
 +
  void qbus_free(BusState *bus);
  
  #define FROM_QBUS(type, dev) DO_UPCAST(type, qbus, dev)
[snip]

-- 
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] hw/vexpress: set default block type to SD

2013-03-18 Thread Paolo Bonzini
Il 17/03/2013 19:54, Peter Maydell ha scritto:
 On 17 March 2013 18:51, Paolo Bonzini pbonz...@redhat.com wrote:
 Il 17/03/2013 01:04, Aurelien Jarno ha scritto:
   | boot | install build-dep | build lm-sensors |
   +--+---+--+
   versatile   | 1:09 | 2:27  | 4:09 |
   versatile cache=wb  | 1:08 | 2:25  | 3:44 |

 Strange, cache=wb should be the default.

 The real problem with SD is that it doesn't have a flush command, hence
 it cannot be made safe against power losses.
 
 So, two things here:
 (a) the way to make it safe against power loss is that when the
 guest writes a block of data it has to really hit the emulated
 disk, because this is how the hardware works
 (b) I thought this was the reason cache=wb wasn't the default (ie
 that we weren't defaulting to 'may lose data on powerloss').

See the commit message that Aurelien posted.  The combination of
virtio-blk will auto-toggle to writethrough on very old kernels,
guests can toggle it for all of IDE/SCSI/virtio, memory cards are
anyway unusable with writethrough finally made the balance tilt in
favor of cache=wb.

Paolo



Re: [Qemu-devel] [PATCH][RFC 0/14] implement power chip

2013-03-18 Thread Andreas Färber
Am 13.03.2013 09:01, schrieb liguang:
 Li Guang (14)
gitignore: ignore more files
qdev: add power management method
qdev: remove redundant abort()
qdev: add power on/off/suspend/wakeup handler

power: add power chip emulation

This patch seems to be missing, whereas the previous one arrived twice.

Andreas

sysemu: remove PowerReason in sysemu.h
acpi: refactor acpi wakeup function
ich9: make lpc's reset also do pm_reset
ich9: do lpc's power on by reset function
piix4: refactor piix4's power callbacks
pckbd: refactor pckbd's power callbacks
ps2: call ps2_{kbd,mouse}_reset in kbd_reset
parallel: refactor parallel_reset function
uhci: refactor uhci's power callbacks

-- 
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] SSD Trim Support- Current State?

2013-03-18 Thread Paolo Bonzini
Il 17/03/2013 21:58, d hee ha scritto:
 What is the current state of SSD Trim/Discard support  for a Qemu/KVM
 guests? 
 
 I run a Qemi/ KVM host wtih these kvm guests...they are all Linux os's
 and use raw images: 1) 20 gig Linux web-server 2) Subsonic music
 streaming server for my Android phone 3) Postfix server for automated
 emails 4) Linux guest for sandbox for testing. All of this is on my on
 personal system as a hobby and not a a business production system. If
 I run them off a ssd drive without the trim support, will I see
 performance impacted as the guest blocks slowly fill up without being
 marked for reuse?

DISCARD is finally supported in qemu.git.  It is experimental in all
released versions.  To get trim support you need to do all of the following:

2) use virtio-scsi or another SCSI HBA (IDE would work too, but it is slow);

2) compile qemu.git from master and add ,discard=on to the -drive
option; or for released versions add ,discard_granularity=4096 to the
-device options for disks.  For more informations on -drive and
-device check out the docs/qdev-device-use.txt file.

3) mount the filesystems with the discard option in the guest, or
periodically run fstrim in the guest;

4) either run the images directly from a partition or logical volume, or
mount the filesystems with the discard option in the host, or
periodically run fstrim in the host.

Paolo



Re: [Qemu-devel] [RFC PATCH RDMA support v4: 09/10] check for QMP string and bypass nonblock() calls

2013-03-18 Thread Paolo Bonzini
Il 18/03/2013 04:19, mrhi...@linux.vnet.ibm.com ha scritto:
 From: Michael R. Hines mrhi...@us.ibm.com
 
 Since we're not using TCP anymore, we skip these calls.
 
 Also print a little extra text while debugging, like gbps
 which is helpful to know how the link is being utilized.
 
 Signed-off-by: Michael R. Hines mrhi...@us.ibm.com
 ---
  include/migration/migration.h |3 +++
  migration.c   |   19 +--
  2 files changed, 16 insertions(+), 6 deletions(-)
 
 diff --git a/include/migration/migration.h b/include/migration/migration.h
 index bb617fd..88ab5f6 100644
 --- a/include/migration/migration.h
 +++ b/include/migration/migration.h
 @@ -20,6 +20,7 @@
  #include qemu/notify.h
  #include qapi/error.h
  #include migration/vmstate.h
 +#include migration/rdma.h
  #include qapi-types.h
  
  struct MigrationParams {
 @@ -102,6 +103,7 @@ uint64_t xbzrle_mig_bytes_transferred(void);
  uint64_t xbzrle_mig_pages_transferred(void);
  uint64_t xbzrle_mig_pages_overflow(void);
  uint64_t xbzrle_mig_pages_cache_miss(void);
 +uint64_t delta_norm_mig_bytes_transferred(void);

Please add the protocol under the
  
  /**
   * @migrate_add_blocker - prevent migration from proceeding
 @@ -122,6 +124,7 @@ int xbzrle_encode_buffer(uint8_t *old_buf, uint8_t 
 *new_buf, int slen,
  int xbzrle_decode_buffer(uint8_t *src, int slen, uint8_t *dst, int dlen);
  
  int migrate_use_xbzrle(void);
 +void *migrate_use_rdma(QEMUFile *f);

Perhaps you can add a new function to QEMUFile send_page?  And if it
returns -ENOTSUP, proceed with the normal is_dup_page + put_buffer.  I
wonder if that lets use remove migrate_use_rdma() completely.

Also, if QEMUFileRDMA is moved to rdma.c, the number of public and
stubbed functions should decrease noticeably.  There is a patch on the
list to move QEMUFile to its own source file.  You could incorporate it
in your series.

  int64_t migrate_xbzrle_cache_size(void);
  
  int64_t xbzrle_cache_resize(int64_t new_size);
 diff --git a/migration.c b/migration.c
 index 185d112..634437a 100644
 --- a/migration.c
 +++ b/migration.c
 @@ -15,6 +15,7 @@
  
  #include qemu-common.h
  #include migration/migration.h
 +#include migration/rdma.h
  #include monitor/monitor.h
  #include migration/qemu-file.h
  #include sysemu/sysemu.h
 @@ -77,6 +78,8 @@ void qemu_start_incoming_migration(const char *uri, Error 
 **errp)
  
  if (strstart(uri, tcp:, p))
  tcp_start_incoming_migration(p, errp);
 +else if (strstart(uri, rdma:, p))
 +rdma_start_incoming_migration(p, errp);
  #if !defined(WIN32)
  else if (strstart(uri, exec:, p))
  exec_start_incoming_migration(p, errp);
 @@ -118,10 +121,11 @@ static void process_incoming_migration_co(void *opaque)
  void process_incoming_migration(QEMUFile *f)
  {
  Coroutine *co = qemu_coroutine_create(process_incoming_migration_co);
 -int fd = qemu_get_fd(f);
 -
 -assert(fd != -1);
 -socket_set_nonblock(fd);
 +if(!migrate_use_rdma(f)) {
 +int fd = qemu_get_fd(f);
 +assert(fd != -1);
 +socket_set_nonblock(fd);

Is this because qemu_get_fd(f) returns -1 for RDMA?  Then, you can
instead put socket_set_nonblock under an if(fd != -1).

 +}
  qemu_coroutine_enter(co, f);
  }
  
 @@ -404,6 +408,8 @@ void qmp_migrate(const char *uri, bool has_blk, bool blk,
  
  if (strstart(uri, tcp:, p)) {
  tcp_start_outgoing_migration(s, p, local_err);
 +} else if (strstart(uri, rdma:, p)) {
 +rdma_start_outgoing_migration(s, p, local_err);
  #if !defined(WIN32)
  } else if (strstart(uri, exec:, p)) {
  exec_start_outgoing_migration(s, p, local_err);
 @@ -545,8 +551,9 @@ static void *migration_thread(void *opaque)
  max_size = bandwidth * migrate_max_downtime() / 100;
  
  DPRINTF(transferred % PRIu64  time_spent % PRIu64
 - bandwidth %g max_size % PRId64 \n,
 -transferred_bytes, time_spent, bandwidth, max_size);
 + bandwidth %g (%0.2f mbps) max_size % PRId64 \n,
 +transferred_bytes, time_spent, 
 +bandwidth, Gbps(transferred_bytes, time_spent), 
 max_size);
  /* if we haven't sent anything, we don't want to recalculate
 1 is a small enough number for our purposes */
  if (s-dirty_bytes_rate  transferred_bytes  1) {
 

Otherwise looks good.



Re: [Qemu-devel] [RFC PATCH RDMA support v4: 04/10] iterators for getting the RAMBlocks

2013-03-18 Thread Paolo Bonzini
Il 18/03/2013 04:18, mrhi...@linux.vnet.ibm.com ha scritto:
 From: Michael R. Hines mrhi...@us.ibm.com
 
 This introduces:
 1. qemu_ram_foreach_block
 2. qemu_ram_count_blocks
 
 Both used in communicating the RAMBlocks
 to each side for later memory registration.
 
 Signed-off-by: Michael R. Hines mrhi...@us.ibm.com
 ---
  exec.c|   21 +
  include/exec/cpu-common.h |6 ++
  2 files changed, 27 insertions(+)
 
 diff --git a/exec.c b/exec.c
 index 8a6aac3..a985da8 100644
 --- a/exec.c
 +++ b/exec.c
 @@ -2629,3 +2629,24 @@ bool cpu_physical_memory_is_io(hwaddr phys_addr)
   memory_region_is_romd(section-mr));
  }
  #endif
 +
 +void qemu_ram_foreach_block(RAMBlockIterFunc func, void *opaque)
 +{
 +RAMBlock *block;
 +
 +QTAILQ_FOREACH(block, ram_list.blocks, next) {
 +func(block-host, block-offset, block-length, opaque);
 +}
 +}
 +
 +int qemu_ram_count_blocks(void)
 +{
 +RAMBlock *block;
 +int total = 0;
 +
 +QTAILQ_FOREACH(block, ram_list.blocks, next) {
 +total++;
 +}

Please move this to rdma.c, and implement it using qemu_ram_foreach_block.

Otherwise looks good.

Paolo

 +return total;
 +}
 diff --git a/include/exec/cpu-common.h b/include/exec/cpu-common.h
 index 2e5f11f..aea3fe0 100644
 --- a/include/exec/cpu-common.h
 +++ b/include/exec/cpu-common.h
 @@ -119,6 +119,12 @@ extern struct MemoryRegion io_mem_rom;
  extern struct MemoryRegion io_mem_unassigned;
  extern struct MemoryRegion io_mem_notdirty;
  
 +typedef void  (RAMBlockIterFunc)(void *host_addr, 
 +ram_addr_t offset, ram_addr_t length, void *opaque); 
 +
 +void qemu_ram_foreach_block(RAMBlockIterFunc func, void *opaque);
 +int qemu_ram_count_blocks(void);
 +
  #endif
  
  #endif /* !CPU_COMMON_H */
 




[Qemu-devel] Re: SSD Trim Support- Current State?

2013-03-18 Thread Nicolas Sebrecht
The 17/03/13, d hee wrote:

 What is the current state of SSD Trim/Discard support  for a Qemu/KVM guests? 
 
 I run a Qemi/ KVM host wtih these kvm guests...they are all Linux os's and 
 use raw images: 1) 20 gig Linux web-server 2) Subsonic music streaming server 
 for my Android phone 3) Postfix server for automated emails 4) Linux guest 
 for sandbox for testing. All of this is on my on personal system as a hobby 
 and not a a business production system. If I run them off a ssd drive 
 without the trim support, will I see performance impacted as the guest blocks 
 slowly fill up without being marked for reuse?

Depends of the SSD you have and the use you make of it. For recent
enough SSD, TRIM support is no more required as firmwares better manage
blocks and pages than in the first days of SSD.

Unless you use your SSD for big rewrites every day, I bet you won't have
to enable TRIM.

Also, If you still want TRIM enabled I think there is no need for
QEMU/KVM to support TRIM as you use RAW format. This is the job of your
guests.

What would make high preformance degradation is not having blocks
aligned.

-- 
Nicolas Sebrecht



Re: [Qemu-devel] [RFC PATCH RDMA support v4: 07/10] connection-establishment for RDMA

2013-03-18 Thread Paolo Bonzini
Il 18/03/2013 04:19, mrhi...@linux.vnet.ibm.com ha scritto:
 From: Michael R. Hines mrhi...@us.ibm.com
 
 
 Signed-off-by: Michael R. Hines mrhi...@us.ibm.com
 ---
  migration-rdma.c |  205 
 ++
  1 file changed, 205 insertions(+)
  create mode 100644 migration-rdma.c
 
 diff --git a/migration-rdma.c b/migration-rdma.c
 new file mode 100644
 index 000..e1ea055
 --- /dev/null
 +++ b/migration-rdma.c
 @@ -0,0 +1,205 @@
 +/*
 + *  Copyright (C) 2013 Michael R. Hines mrhi...@us.ibm.com
 + *  Copyright (C) 2013 Jiuxing Liu j...@us.ibm.com
 + *
 + *  This program is free software; you can redistribute it and/or modify
 + *  it under the terms of the GNU General Public License as published by
 + *  the Free Software Foundation; under version 2 of the License.
 + *
 + *  This program is distributed in the hope that it will be useful,
 + *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 + *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 + *  GNU General Public License for more details.
 + *
 + *  You should have received a copy of the GNU General Public License
 + *  along with this program; if not, see http://www.gnu.org/licenses/.
 + */
 +#include migration/rdma.h
 +#include qemu-common.h
 +#include migration/migration.h
 +#include migration/qemu-file.h
 +#include stdio.h
 +#include sys/types.h
 +#include sys/socket.h
 +#include netdb.h
 +#include arpa/inet.h
 +#include string.h
 +
 +//#define DEBUG_MIGRATION_RDMA
 +
 +#ifdef DEBUG_MIGRATION_RDMA
 +#define DPRINTF(fmt, ...) \
 +do { printf(migration-rdma:  fmt, ## __VA_ARGS__); } while (0)
 +#else
 +#define DPRINTF(fmt, ...) \
 +do { } while (0)
 +#endif
 +
 +static int rdma_accept_incoming_migration(RDMAData *rdma, Error **errp)
 +{
 +int ret;
 +
 +ret = qemu_rdma_migrate_listen(rdma, rdma-host, rdma-port);
 +if (ret) {
 +qemu_rdma_print(rdma migration: error listening!);
 +goto err_rdma_server_wait;
 +}
 +
 +ret = qemu_rdma_alloc_qp(rdma-rdma_ctx);
 +if (ret) {
 +qemu_rdma_print(rdma migration: error allocating qp!);
 +goto err_rdma_server_wait;
 +}
 +
 +ret = qemu_rdma_migrate_accept(rdma-rdma_ctx, NULL, NULL, NULL, 0);
 +if (ret) {
 +qemu_rdma_print(rdma migration: error accepting connection!);
 +goto err_rdma_server_wait;
 +}
 +
 +ret = qemu_rdma_post_recv_qemu_file(rdma);
 +if (ret) {
 +qemu_rdma_print(rdma migration: error posting second qemu file 
 recv!);
 +goto err_rdma_server_wait;
 +}
 +
 +ret = qemu_rdma_post_send_remote_info(rdma);
 +if (ret) {
 +qemu_rdma_print(rdma migration: error sending remote info!);
 +goto err_rdma_server_wait;
 +}
 +
 +ret = qemu_rdma_wait_for_wrid(rdma, RDMA_WRID_SEND_REMOTE_INFO);
 +if (ret  0) {
 +qemu_rdma_print(rdma migration: polling remote info error!);
 +goto err_rdma_server_wait;
 +}

In a socket-like abstraction, all of these steps except the initial
listen are part of accept.  Please move them to
qemu_rdma_migrate_accept (possibly renaming the existing
qemu_rdma_migrate_accept to a different name).

Similarly, perhaps you can merge qemu_rdma_server_prepare and
qemu_rdma_migrate_listen.

Try to make the public API between modules as small as possible (but not
smaller :)), so that you can easily document it without too many
references to RDMA concepts.

Thanks,

Paolo

 +rdma-total_bytes = 0;
 +rdma-enabled = 1;
 +qemu_rdma_dump_gid(server_connect, rdma-rdma_ctx.cm_id);
 +return 0;
 +
 +err_rdma_server_wait:
 +qemu_rdma_cleanup(rdma);
 +return -1;
 +
 +}
 +
 +int rdma_start_incoming_migration(const char * host_port, Error **errp)
 +{
 +RDMAData *rdma = g_malloc0(sizeof(RDMAData));
 +QEMUFile *f;
 +int ret;
 +
 +if ((ret = qemu_rdma_data_init(rdma, host_port, errp))  0)
 +return ret; 
 +
 +ret = qemu_rdma_server_init(rdma, NULL);
 +
 +DPRINTF(Starting RDMA-based incoming migration\n);
 +
 +if (!ret) {
 +DPRINTF(qemu_rdma_server_init success\n);
 +ret = qemu_rdma_server_prepare(rdma, NULL);
 +
 +if (!ret) {
 +DPRINTF(qemu_rdma_server_prepare success\n);
 +
 +ret = rdma_accept_incoming_migration(rdma, NULL);
 +if(!ret)
 +DPRINTF(qemu_rdma_accept_incoming_migration success\n);
 +f = qemu_fopen_rdma(rdma, rb);
 +if (f == NULL) {
 +fprintf(stderr, could not qemu_fopen RDMA\n);
 +ret = -EIO;
 +}
 +
 +process_incoming_migration(f);
 +}
 +}
 +
 +return ret;
 +}
 +
 +void rdma_start_outgoing_migration(void *opaque, const char *host_port, 
 Error **errp)
 +{
 +RDMAData *rdma = g_malloc0(sizeof(RDMAData));
 +MigrationState *s = opaque;
 +int ret;
 +
 +if (qemu_rdma_data_init(rdma, host_port, errp)  0)
 +return; 

Re: [Qemu-devel] [PATCH v9 03/10] virtio-blk: don't use pointer for configuration.

2013-03-18 Thread Kevin Wolf
Am 15.03.2013 um 19:48 hat fred.kon...@greensocs.com geschrieben:
 From: KONRAD Frederic fred.kon...@greensocs.com
 
 The configuration field must not be a pointer as it will be used for 
 virtio-blk
 properties. So *blk is replaced by blk in VirtIOBlock structure.
 
 Signed-off-by: KONRAD Frederic fred.kon...@greensocs.com
 Reviewed-by: Peter Maydell peter.mayd...@linaro.org
 ---
  hw/virtio-blk.c | 8 
  hw/virtio-blk.h | 2 +-
  2 files changed, 5 insertions(+), 5 deletions(-)
 
 diff --git a/hw/virtio-blk.c b/hw/virtio-blk.c
 index 6714b01..908c316 100644
 --- a/hw/virtio-blk.c
 +++ b/hw/virtio-blk.c
 @@ -151,7 +151,7 @@ static void virtio_blk_handle_scsi(VirtIOBlockReq *req)
   */
  req-scsi = (void *)req-elem.in_sg[req-elem.in_num - 2].iov_base;
  
 -if (!req-dev-blk-scsi) {
 +if (!req-dev-blk.scsi) {
  status = VIRTIO_BLK_S_UNSUPP;
  goto fail;
  }
 @@ -371,7 +371,7 @@ static void virtio_blk_handle_request(VirtIOBlockReq *req,
   * terminated by '\0' only when shorter than buffer.
   */
  strncpy(req-elem.in_sg[0].iov_base,
 -s-blk-serial ? s-blk-serial : ,
 +s-blk.serial ? s-blk.serial : ,
  MIN(req-elem.in_sg[0].iov_len, VIRTIO_BLK_ID_BYTES));
  virtio_blk_req_complete(req, VIRTIO_BLK_S_OK);
  g_free(req);
 @@ -534,7 +534,7 @@ static uint32_t virtio_blk_get_features(VirtIODevice 
 *vdev, uint32_t features)
  features |= (1  VIRTIO_BLK_F_BLK_SIZE);
  features |= (1  VIRTIO_BLK_F_SCSI);
  
 -if (s-blk-config_wce) {
 +if (s-blk.config_wce) {
  features |= (1  VIRTIO_BLK_F_CONFIG_WCE);
  }
  if (bdrv_enable_write_cache(s-bs))
 @@ -650,7 +650,7 @@ VirtIODevice *virtio_blk_init(DeviceState *dev, 
 VirtIOBlkConf *blk)
  s-vdev.reset = virtio_blk_reset;
  s-bs = blk-conf.bs;
  s-conf = blk-conf;
 -s-blk = blk;
 +memcpy((s-blk), blk, sizeof(struct VirtIOBlkConf));

Why not simply s-blk = *blk?

The reason why copying this works is that blk is read-only after
initialisation. We also get an additional reference to blk-serial, but
we know that it can only go away after this device has been destroyed
(the same assumption was necessary for the s-blk pointer in the old
code).

Is my understanding of this correct?

Kevin



Re: [Qemu-devel] [PATCH][RFC 0/14] implement power chip

2013-03-18 Thread li guang
在 2013-03-18一的 09:34 +0100,Andreas Färber写道:
 Am 13.03.2013 09:01, schrieb liguang:
  Li Guang (14)
   gitignore: ignore more files
   qdev: add power management method
   qdev: remove redundant abort()
   qdev: add power on/off/suspend/wakeup handler
 
   power: add power chip emulation
 
 This patch seems to be missing, whereas the previous one arrived twice.
 
 Andreas

Odd things!
anyway, I'll send 5/14 to mail-list
Thanks!

 
   sysemu: remove PowerReason in sysemu.h
   acpi: refactor acpi wakeup function
   ich9: make lpc's reset also do pm_reset
   ich9: do lpc's power on by reset function
   piix4: refactor piix4's power callbacks
   pckbd: refactor pckbd's power callbacks
   ps2: call ps2_{kbd,mouse}_reset in kbd_reset
   parallel: refactor parallel_reset function
   uhci: refactor uhci's power callbacks
 





Re: [Qemu-devel] [PATCH][RFC 04/14] qdev: add power on/off/suspend/wakeup handler

2013-03-18 Thread li guang
在 2013-03-18一的 09:31 +0100,Andreas Färber写道:
 Am 13.03.2013 09:01, schrieb liguang:
  Signed-off-by: liguang lig.f...@cn.fujitsu.com
  ---
   hw/qdev-core.h |9 +
   hw/qdev.c  |   96 
  
   2 files changed, 105 insertions(+), 0 deletions(-)
  
  diff --git a/hw/qdev-core.h b/hw/qdev-core.h
  index e69c50b..805ac69 100644
  --- a/hw/qdev-core.h
  +++ b/hw/qdev-core.h
  @@ -262,6 +262,15 @@ void qdev_reset_all(DeviceState *dev);
   void qbus_reset_all(BusState *bus);
   void qbus_reset_all_fn(void *opaque);
   
  +void qdev_power_on(DeviceState *dev);
  +void qdev_power_off(DeviceState *dev);
  +void qdev_power_wakeup(DeviceState *dev);
  +void qdev_power_suspend(DeviceState *dev);
 
 No new qdev_ functions please. qdev no longer exists in its original
 form since the QOM introduction. Please use device_ instead.
 
 Note that here you use power_*, so it may be worth using an identical
 callback field name for at least on and off if we go with your concept.
 
 Andreas

Good suggestion!
Thanks!

 
  +void qbus_power_off(void *opaque);
  +void qbus_power_wakeup(void *opaque);
  +void qbus_power_suspend(void *opaque);
  +void qbus_power_on(void *opaque);
  +
   void qbus_free(BusState *bus);
   
   #define FROM_QBUS(type, dev) DO_UPCAST(type, qbus, dev)
 [snip]
 





Re: [Qemu-devel] [PATCH][RFC 02/14] qdev: add power management method

2013-03-18 Thread li guang
Thanks!

在 2013-03-18一的 09:25 +0100,Andreas Färber写道:
 Am 13.03.2013 09:01, schrieb liguang:
  In fact, every devices have to be aware of
  it's power management, so it can decide what
  to do when platform board switch it's power
  state between on/off/suspend/wakeup.
  
  Signed-off-by: liguang lig.f...@cn.fujitsu.com
  ---
   hw/qdev-core.h |6 ++
   1 files changed, 6 insertions(+), 0 deletions(-)
  
  diff --git a/hw/qdev-core.h b/hw/qdev-core.h
  index 2486f36..e69c50b 100644
  --- a/hw/qdev-core.h
  +++ b/hw/qdev-core.h
  @@ -85,6 +85,12 @@ typedef struct DeviceClass {
   Property *props;
   int no_user;
   
  +/* power management */
  +void (*on)(DeviceState *dev);
  +void (*off)(DeviceState *dev);
  +void (*suspend)(DeviceState *dev);
  +void (*wakeup)(DeviceState *dev);
  +
   /* callbacks */
   void (*reset)(DeviceState *dev);
   DeviceRealize realize;
 
 Whatever callbacks get added, they should be added down here and get
 gtk-doc documentation above the struct. That should also include some
 guidelines on how new devices should implement these (hint: we'd want to
 avoid code duplication).

OK

 
 I have the feeling your hooks may be rather x86-specific - have you
 checked against any other architecture?
 

I'm considering to be generic

 Andreas
 





Re: [Qemu-devel] [RFC] qmp interface for save vmstate to image

2013-03-18 Thread Kevin Wolf
Am 18.03.2013 um 07:40 hat Wenchao Xia geschrieben:
 于 2013-3-15 22:51, Stefan Hajnoczi 写道:
  On Fri, Mar 15, 2013 at 03:24:38PM +0800, Wenchao Xia wrote:
 I'd like to add a new way to save vmstate, which will based on the
  migration thread, but will write contents to block images, instead
  of fd as stream. Following is the method to add API:
  
  Hi Wenchao,
  What use cases are there besides saving vmstate to a raw image?
  
  I'm curious if you're proposing this since there is no file: URI or
  because you really want to do things like saving vmstate into a qcow2
  file or over NBD.
  
  Stefan
  
 Hi, Stefan
   Most used cases would be raw and qcow2, which is flex and can be
 chosen by user. In this way, existing block layer feature in qemu can
 be used, such as tagging zeros. I haven't check the buffer/cache status
 in qemu block layer, but if there is, it can also benefit.
   User can specify raw or qcow2 according to host configuration, If
 there is dedicated storage components underlining, he can use raw to
 skip qemu's block layer.

Oh, seems I misread this then. I thought this was about internal live
snapshots, which is a feature that I consider really useful. I'm not so
sure if saving the VM state as the disk contents of a qcow2 image is
really helpful.

If zero clusters help a lot, then there's clearly something to improve
in the migration protocol, because it shouldn't send so many zeros in
the first place.

Kevin



Re: [Qemu-devel] [RFC PATCH RDMA support v4: 08/10] introduce QEMUFileRDMA

2013-03-18 Thread Paolo Bonzini
Il 18/03/2013 04:19, mrhi...@linux.vnet.ibm.com ha scritto:
 From: Michael R. Hines mrhi...@us.ibm.com
 
 This compiles with and without --enable-rdma.
 
 Signed-off-by: Michael R. Hines mrhi...@us.ibm.com
 ---
  include/migration/qemu-file.h |   10 +++
  savevm.c  |  172 
 ++---
  2 files changed, 172 insertions(+), 10 deletions(-)
 
 diff --git a/include/migration/qemu-file.h b/include/migration/qemu-file.h
 index df81261..9046751 100644
 --- a/include/migration/qemu-file.h
 +++ b/include/migration/qemu-file.h
 @@ -51,23 +51,33 @@ typedef int (QEMUFileCloseFunc)(void *opaque);
   */
  typedef int (QEMUFileGetFD)(void *opaque);
  
 +/* 
 + * 'drain' from a QEMUFile perspective means
 + * to flush the outbound send buffer
 + * (if one exists). (Only used by RDMA right now)
 + */
 +typedef int (QEMUFileDrainFunc)(void *opaque);
 +
  typedef struct QEMUFileOps {
  QEMUFilePutBufferFunc *put_buffer;
  QEMUFileGetBufferFunc *get_buffer;
  QEMUFileCloseFunc *close;
  QEMUFileGetFD *get_fd;
 +QEMUFileDrainFunc *drain;
  } QEMUFileOps;
  
  QEMUFile *qemu_fopen_ops(void *opaque, const QEMUFileOps *ops);
  QEMUFile *qemu_fopen(const char *filename, const char *mode);
  QEMUFile *qemu_fdopen(int fd, const char *mode);
  QEMUFile *qemu_fopen_socket(int fd, const char *mode);
 +QEMUFile *qemu_fopen_rdma(void *opaque, const char *mode);
  QEMUFile *qemu_popen_cmd(const char *command, const char *mode);
  int qemu_get_fd(QEMUFile *f);
  int qemu_fclose(QEMUFile *f);
  int64_t qemu_ftell(QEMUFile *f);
  void qemu_put_buffer(QEMUFile *f, const uint8_t *buf, int size);
  void qemu_put_byte(QEMUFile *f, int v);
 +int qemu_drain(QEMUFile *f);
  
  static inline void qemu_put_ubyte(QEMUFile *f, unsigned int v)
  {
 diff --git a/savevm.c b/savevm.c
 index 35c8d1e..9b90b7f 100644
 --- a/savevm.c
 +++ b/savevm.c
 @@ -32,6 +32,7 @@
  #include qemu/timer.h
  #include audio/audio.h
  #include migration/migration.h
 +#include migration/rdma.h
  #include qemu/sockets.h
  #include qemu/queue.h
  #include sysemu/cpus.h
 @@ -143,6 +144,13 @@ typedef struct QEMUFileSocket
  QEMUFile *file;
  } QEMUFileSocket;
  
 +typedef struct QEMUFileRDMA
 +{
 +void *rdma;

This is an RDMAData *.  Please avoid using void * as much as possible.

 +size_t len;
 +QEMUFile *file;
 +} QEMUFileRDMA;
 +
  typedef struct {
  Coroutine *co;
  int fd;
 @@ -178,6 +186,66 @@ static int socket_get_fd(void *opaque)
  return s-fd;
  }
  
 +/*
 + * SEND messages for none-live state only.
 + * pc.ram is handled elsewhere...
 + */
 +static int qemu_rdma_put_buffer(void *opaque, const uint8_t *buf, int64_t 
 pos, int size)
 +{
 +QEMUFileRDMA *r = opaque;
 +size_t remaining = size;
 +uint8_t * data = (void *) buf;
 +
 +/*
 + * Although we're sending non-live
 + * state here, push out any writes that
 + * we're queued up for pc.ram anyway.
 + */
 +if (qemu_rdma_write_flush(r-rdma)  0)
 +return -EIO;
 +
 +while(remaining) {
 +r-len = MIN(remaining, RDMA_SEND_INCREMENT);
 +remaining -= r-len;
 +
 +if(qemu_rdma_exchange_send(r-rdma, data, r-len)  0)
 +return -EINVAL;
 +
 +data += r-len;
 +}
 +
 +return size;
 +} 
 +
 +/*
 + * RDMA links don't use bytestreams, so we have to
 + * return bytes to QEMUFile opportunistically.
 + */
 +static int qemu_rdma_get_buffer(void *opaque, uint8_t *buf, int64_t pos, int 
 size)
 +{
 +QEMUFileRDMA *r = opaque;
 +
 +/*
 + * First, we hold on to the last SEND message we 
 + * were given and dish out the bytes until we run 
 + * out of bytes.
 + */
 +if((r-len = qemu_rdma_fill(r-rdma, buf, size)))
 + return r-len; 
 +
 + /*
 +  * Once we run out, we block and wait for another
 +  * SEND message to arrive.
 +  */
 +if(qemu_rdma_exchange_recv(r-rdma)  0)
 + return -EINVAL;
 +
 +/*
 + * SEND was received with new bytes, now try again.
 + */
 +return qemu_rdma_fill(r-rdma, buf, size);
 +} 

Please move these functions closer to qemu_fopen_rdma (or better, to an
RDMA-specific file altogether).  Also, using qemu_rdma_fill introduces a
dependency of savevm.c on migration-rdma.c.  There should be no such
dependency; migration-rdma.c should be used only by migration.c.

  static int socket_get_buffer(void *opaque, uint8_t *buf, int64_t pos, int 
 size)
  {
  QEMUFileSocket *s = opaque;
 @@ -390,16 +458,24 @@ static const QEMUFileOps socket_write_ops = {
  .close =  socket_close
  };
  
 -QEMUFile *qemu_fopen_socket(int fd, const char *mode)
 +static bool qemu_mode_is_not_valid(const char * mode)
  {
 -QEMUFileSocket *s = g_malloc0(sizeof(QEMUFileSocket));
 -
  if (mode == NULL ||
  (mode[0] != 'r'  mode[0] != 'w') ||
  mode[1] != 'b' || mode[2] != 0) {
  fprintf(stderr, qemu_fopen: Argument validity check failed\n);
 -return 

[Qemu-devel] [PATCH][RFC 05/14] power: add power chip emulation

2013-03-18 Thread liguang
this power chip manage on/off/wakeup/suspend
power state transition, when state changed,
it will trigger all callbacks embedded in
all device object. This just like power action
in real world.

Signed-off-by: liguang lig.f...@cn.fujitsu.com
---
 Makefile.objs |1 +
 power.c   |  133 +
 power.h   |   41 +
 3 files changed, 175 insertions(+), 0 deletions(-)
 create mode 100644 power.c
 create mode 100644 power.h

diff --git a/Makefile.objs b/Makefile.objs
index a68cdac..a895e7d 100644
--- a/Makefile.objs
+++ b/Makefile.objs
@@ -73,6 +73,7 @@ common-obj-y += bt-host.o bt-vhci.o
 
 common-obj-y += dma-helpers.o
 common-obj-y += vl.o
+common-obj-y += power.o
 
 common-obj-$(CONFIG_SLIRP) += slirp/
 
diff --git a/power.c b/power.c
new file mode 100644
index 000..ce9cdab
--- /dev/null
+++ b/power.c
@@ -0,0 +1,133 @@
+#include power.h
+#include qemu/main-loop.h
+
+
+PowerChip pmc;
+
+void power_management_set(PowerState ps)
+{
+switch (ps) {
+case POWER_OFF:
+case POWER_ON:
+case POWER_SUSPEND:
+case POWER_WAKEUP:
+pmc.power_state = ps;
+break;
+case POWER_RESET:
+pmc.power_state = ps | POWER_OFF;
+break;
+default:
+pmc.power_state = POWER_IDLE;
+break;
+}
+}
+
+static void power_management_on(DeviceState *dev)
+{
+qbus_reset_all_fn(sysbus_get_default());
+}
+
+static void power_management_off(DeviceState *dev)
+{
+qbus_power_off(sysbus_get_default());
+}
+
+static void power_management_suspend(DeviceState *dev)
+{
+qbus_power_suspend(sysbus_get_default());
+}
+
+static void power_management_wakeup(DeviceState *dev)
+{
+qbus_power_wakeup(sysbus_get_default());
+}
+
+WakeupReason power_management_wakeup_reason(void)
+{
+return pmc.wakeup_reason;
+}
+
+void power_management_wakeup_reason_set(WakeupReason wr)
+{
+pmc.wakeup_reason = wr;
+}
+
+void power_management_wakeup_capability(WakeupReason wr, bool ok)
+{
+switch (wr) {
+case QEMU_WAKEUP_REASON_RTC:
+case QEMU_WAKEUP_REASON_PMTIMER:
+if (ok) {
+pmc.wakeup_capability |= 1  wr;
+} else {
+pmc.wakeup_capability = ~(1  wr);
+}
+default:
+break;
+}
+}
+
+PowerState power_management(void)
+{
+int reset = pmc.power_state  0x80;
+
+switch (pmc.power_state  0xf) {
+case POWER_ON:
+power_management_on(NULL);
+break;
+case POWER_OFF:
+power_management_off(NULL);
+if (reset) {
+pmc.power_state = POWER_ON;
+}
+break;
+case POWER_SUSPEND:
+power_management_suspend(NULL);
+break;
+case POWER_WAKEUP:
+if (1  pmc.wakeup_reason  pmc.wakeup_capability) {
+power_management_wakeup(NULL);
+}
+default:
+break;
+}
+
+if (reset == 0) {
+pmc.power_state = POWER_IDLE;
+}
+
+return pmc.power_state;
+}
+
+static void power_chip_init(Object *obj)
+{
+pmc.power_state = POWER_IDLE;
+pmc.wakeup_reason = QEMU_WAKEUP_REASON_UNKNOWN;
+pmc.wakeup_capability = QEMU_WAKEUP_REASON_RTC | 
QEMU_WAKEUP_REASON_PMTIMER;
+}
+
+static void power_chip_class_init(ObjectClass *oc, void *data)
+{
+ DeviceClass *dc = DEVICE_CLASS(oc);
+
+ dc-on = power_management_on;
+ dc-off = power_management_off;
+ dc-wakeup = power_management_wakeup;
+ dc-suspend = power_management_suspend;
+}
+
+static const TypeInfo power_chip_info = {
+.name = TYPE_POWER_CHIP,
+.parent = NULL,
+.instance_size = sizeof(PowerChip),
+.instance_init = power_chip_init,
+.class_init = power_chip_class_init,
+};
+
+static void power_chip_types(void)
+{
+type_register_static(power_chip_info);
+}
+
+type_init(power_chip_types);
+
diff --git a/power.h b/power.h
new file mode 100644
index 000..e36fd31
--- /dev/null
+++ b/power.h
@@ -0,0 +1,41 @@
+#ifndef POWER_H_
+#define POWER_H_
+
+#include hw/qdev.h
+#include hw/qdev-core.h
+
+
+typedef enum PowerState {
+POWER_IDLE = 0,
+POWER_OFF = 0x1,
+POWER_ON = 0x2,
+POWER_RESET = 0x80,
+POWER_SUSPEND = 0x4,
+POWER_WAKEUP = 0x8,
+} PowerState;
+
+typedef enum WakeupReason {
+QEMU_WAKEUP_REASON_UNKNOWN = -1,
+QEMU_WAKEUP_REASON_OTHER = 0,
+QEMU_WAKEUP_REASON_RTC,
+QEMU_WAKEUP_REASON_PMTIMER,
+} WakeupReason;
+
+typedef struct PowerChip {
+DeviceState dev;
+PowerState power_state;
+WakeupReason wakeup_reason;
+int wakeup_capability;
+} PowerChip;
+
+#define TYPE_POWER_CHIP power-chip
+
+#define PMC(obj)  OBJECT_CHECK(PowerChip, (obj), TYPE_CPU)
+
+void power_management_set(PowerState ps);
+PowerState power_management(void);
+WakeupReason power_management_wakeup_reason(void);
+void power_management_wakeup_reason_set(WakeupReason wr);
+void power_management_wakeup_capability(WakeupReason wr, bool ok);
+
+#endif
-- 
1.7.2.5




[Qemu-devel] [Bug 1155403] Re: virtio cdrom detected as hard disk

2013-03-18 Thread Paolo Bonzini
 It seems the installer does not consider virtio devices when doing its
search.

That's another bug in the installer then.

 it seems a bit wasteful to go through a layer of scsi emulation.

Indeed treating the virtio disk similarly to installation from a USB
stick is better, but SCSI emulation is actually a very good way to not
reinvent the wheel. CD-ROM/DVD-ROM media need a lot of magic (such as
subdivision of the medium into tracks, different media formats, etc.)
and emulating those in virtio-blk would be even more wasteful.

 Shouldn't qemu at least warn you that the media=argument does nothing
 on virtio devices instead of silently ignoring it?

Yes, that's a legitimate request.

  Or better yet, shouldn't it automatically use virtio-scsi instead?

No, virtio-scsi is relatively new and not all distros have picked it up
yet.

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

Title:
  virtio cdrom detected as hard disk

Status in QEMU:
  Invalid
Status in “qemu” package in Ubuntu:
  Invalid

Bug description:
  Trying to install Ubuntu or Debian using virtio to emulate the cdrom
  fails.  This appears to be due to the drive appearing to be a hard
  disk, rather than a cdrom, despite the media=cdrom argument to qemu.

  I'm not sure if this is a bug in qemu, or the kernel virtio driver?

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



Re: [Qemu-devel] slow virtio network with vhost=on and multiple cores

2013-03-18 Thread Alexandre DERUMIER
Hello, about this bug,


Last Proxmox distrib use 2.6.32 rhel 6.3 kernel + qemu 1.4 , and have this 
problem with guest with 2.6.32 kernel.

do you think that +x2apic in guest cpu could help ?

(I think it's enable by default in RHEV/OVIRT ? but not in proxmox)



- Mail original -

De: Michael S. Tsirkin m...@redhat.com
À: Peter Lieven p...@dlhnet.de
Cc: Davide Guerri d.gue...@unidata.it, Alexandre DERUMIER 
aderum...@odiso.com, Stefan Hajnoczi stefa...@gmail.com, 
qemu-devel@nongnu.org, Jan Kiszka jan.kis...@web.de, Peter Lieven 
lieven-li...@dlhnet.de, Dietmar Maurer diet...@proxmox.com
Envoyé: Dimanche 17 Mars 2013 10:08:17
Objet: Re: [Qemu-devel] slow virtio network with vhost=on and multiple cores

On Fri, Mar 15, 2013 at 08:23:44AM +0100, Peter Lieven wrote:
 On 15.03.2013 00:04, Davide Guerri wrote:
 Yes this is definitely an option :)
 
 Just for curiosity, what is the effect of in-kernel irqchip?

 it emulates the irqchip in-kernel (in the KVM kernel module) which
 avoids userspace exits to qemu. in your particular case I remember
 that it made all IRQs deliverd to vcpu0 on. So I think this is a workaround
 and not the real fix. I think Michael is right that it is a
 client kernel bug. It would be good to find out what it is and ask
 the 2.6.32 maintainers to include it. i further have seen that
 with more recent kernels and inkernel-irqchip the irqs are delivered
 to vcpu0 only again (without multiqueue).

 Is it possible to disable it on a live domain?

 try it. i don't know. you definetely have to do a live migration for it, 
 but I have no clue if the VM will survice this.

 Peter

I doubt you can migrate VMs between irqchip/non irqchip configurations.

 
 Cheers,
  Davide
 
 
 On 14/mar/2013, at 19:21, Peter Lieven p...@dlhnet.de wrote:
 
 
 Am 14.03.2013 um 19:15 schrieb Davide Guerri d.gue...@unidata.it:
 
 Of course I can do some test but a kernel upgrade is not an option here :(
 
 disabling the in-kernel irqchip (default since 1.2.0) should also help, 
 maybe this is an option.
 
 Peter
 
 
 



Re: [Qemu-devel] slow virtio network with vhost=on and multiple cores

2013-03-18 Thread Michael S. Tsirkin
Do you see all interrupts going to the same CPU? If yes is
irqbalance in guest running?

On Mon, Mar 18, 2013 at 10:50:19AM +0100, Alexandre DERUMIER wrote:
 Hello, about this bug,
 
 
 Last Proxmox distrib use 2.6.32 rhel 6.3 kernel + qemu 1.4 , and have this 
 problem with guest with 2.6.32 kernel.
 
 do you think that +x2apic in guest cpu could help ?
 
 (I think it's enable by default in RHEV/OVIRT ? but not in proxmox)
 
 
 
 - Mail original -
 
 De: Michael S. Tsirkin m...@redhat.com
 À: Peter Lieven p...@dlhnet.de
 Cc: Davide Guerri d.gue...@unidata.it, Alexandre DERUMIER 
 aderum...@odiso.com, Stefan Hajnoczi stefa...@gmail.com, 
 qemu-devel@nongnu.org, Jan Kiszka jan.kis...@web.de, Peter Lieven 
 lieven-li...@dlhnet.de, Dietmar Maurer diet...@proxmox.com
 Envoyé: Dimanche 17 Mars 2013 10:08:17
 Objet: Re: [Qemu-devel] slow virtio network with vhost=on and multiple cores
 
 On Fri, Mar 15, 2013 at 08:23:44AM +0100, Peter Lieven wrote:
  On 15.03.2013 00:04, Davide Guerri wrote:
  Yes this is definitely an option :)
  
  Just for curiosity, what is the effect of in-kernel irqchip?
 
  it emulates the irqchip in-kernel (in the KVM kernel module) which
  avoids userspace exits to qemu. in your particular case I remember
  that it made all IRQs deliverd to vcpu0 on. So I think this is a workaround
  and not the real fix. I think Michael is right that it is a
  client kernel bug. It would be good to find out what it is and ask
  the 2.6.32 maintainers to include it. i further have seen that
  with more recent kernels and inkernel-irqchip the irqs are delivered
  to vcpu0 only again (without multiqueue).
 
  Is it possible to disable it on a live domain?
 
  try it. i don't know. you definetely have to do a live migration for it, 
  but I have no clue if the VM will survice this.
 
  Peter
 
 I doubt you can migrate VMs between irqchip/non irqchip configurations.
 
  
  Cheers,
   Davide
  
  
  On 14/mar/2013, at 19:21, Peter Lieven p...@dlhnet.de wrote:
  
  
  Am 14.03.2013 um 19:15 schrieb Davide Guerri d.gue...@unidata.it:
  
  Of course I can do some test but a kernel upgrade is not an option here 
  :(
  
  disabling the in-kernel irqchip (default since 1.2.0) should also help, 
  maybe this is an option.
  
  Peter
  
  
  



Re: [Qemu-devel] [Bug 1155403] Re: virtio cdrom detected as hard disk

2013-03-18 Thread Markus Armbruster
Phillip Susi ps...@ubuntu.com writes:

 It seems the installer does not consider virtio devices when doing its
 search.  It also seems the installer does not have the virtio-scsi
 module, and it seems a bit wasteful to go through a layer of scsi
 emulation.

virtio-scsi performs just fine.

 Shouldn't qemu at least warn you that the media=argument does nothing on
 virtio devices instead of silently ignoring it?  Or better yet,
 shouldn't it automatically use virtio-scsi instead?

Incompatible changes.  Doesn't mean we can't make them ever, only we
better be careful.

If we make incompatible changes to if=virtio, we might be better off
going all the way and switching it over to virtio-scsi wholesale.



Re: [Qemu-devel] [PATCH] pvevent: pvevent device driver

2013-03-18 Thread Paolo Bonzini
Il 15/03/2013 20:35, Matthew Garrett ha scritto:
 On Thu, 2013-03-14 at 16:51 +0800, Hu Tao wrote:
 
 +{ MSFT0001, 0},
 
 This seems wrong, and it looks like qemu agrees. Can you resubmit when
 there's agreement on the name?
 
 +acpi_evaluate_object(handle, WRPT, arg_list, NULL);
 
 Is there a spec for this?

Not yet.  Hu, in the next version of your QEMU patches you probably will
not need anymore usage information in docs/pvevent.txt.  Instead, please
add a spec for both the ISA and ACPI interfaces in docs/spec/pvevent.txt.

 Is the only reason for this to allow guests to notify the host that
 they've panicked? It seems like making use of pstore to push the crash
 dump to the host. as well would be a useful thing to do.

Since we try to limit the amount of VM-specific interfaces we have
(yeah, I know this is one), that would mean implementing APEI in QEMU, I
guess.  It is definitely a useful thing to have, but a bit wider in
scope than a simple device to distinguish idle and crashed VMs.

Paolo



Re: [Qemu-devel] [PATCH v8 05/24] hw/arm: add FTDDRII030 DDRII controller support

2013-03-18 Thread Kuo-Jung Su
2013/3/18 Peter Crosthwaite peter.crosthwa...@xilinx.com:
 On Mon, Mar 18, 2013 at 11:12 AM, Kuo-Jung Su dant...@gmail.com wrote:
 2013/3/16 Peter Crosthwaite peter.crosthwa...@xilinx.com:
 Hi Kuo-Jung,

 On Fri, Mar 15, 2013 at 11:13 PM, Kuo-Jung Su dant...@gmail.com wrote:
 From: Kuo-Jung Su dant...@faraday-tech.com

 The FTDDRII030 is a DDRII SDRAM controller which is responsible for
 SDRAM initialization.
 In QEMU we emulate only the SDRAM enable function.

 Signed-off-by: Kuo-Jung Su dant...@faraday-tech.com
 ---
  hw/arm/Makefile.objs  |1 +
  hw/arm/faraday_a369_soc.c |9 +++
  hw/arm/ftddrii030.c   |  183 
 +
  3 files changed, 193 insertions(+)
  create mode 100644 hw/arm/ftddrii030.c

 diff --git a/hw/arm/Makefile.objs b/hw/arm/Makefile.objs
 index af36b01..0bbf838 100644
 --- a/hw/arm/Makefile.objs
 +++ b/hw/arm/Makefile.objs
 @@ -39,3 +39,4 @@ obj-y += faraday_a369.o faraday_a369_soc.o 
 faraday_a369_scu.o \
  faraday_a369_kpd.o
  obj-y += ftintc020.o
  obj-y += ftahbc020.o
 +obj-y += ftddrii030.o
 diff --git a/hw/arm/faraday_a369_soc.c b/hw/arm/faraday_a369_soc.c
 index 01b4395..e8a63bb 100644
 --- a/hw/arm/faraday_a369_soc.c
 +++ b/hw/arm/faraday_a369_soc.c
 @@ -158,6 +158,15 @@ a369soc_device_init(FaradaySoCState *s)
  fprintf(stderr, a369soc: Unable to set soc link for 
 FTAHBC020\n);
  abort();
  }
 +
 +/* ftddrii030 */
 +ds = sysbus_create_simple(ftddrii030, 0x9310, NULL);
 +s-ddrc = ds;
 +object_property_set_link(OBJECT(ds), OBJECT(s), soc, local_errp);
 +if (local_errp) {
 +fprintf(stderr, a369soc: Unable to set soc link for 
 FTDDRII030\n);
 +abort();
 +}
  }

  static void a369soc_realize(DeviceState *dev, Error **errp)
 diff --git a/hw/arm/ftddrii030.c b/hw/arm/ftddrii030.c
 new file mode 100644
 index 000..90a5842
 --- /dev/null
 +++ b/hw/arm/ftddrii030.c
 @@ -0,0 +1,183 @@
 +/*
 + * Faraday DDRII controller
 + *
 + * Copyright (c) 2012 Faraday Technology
 + * Written by Dante Su dant...@faraday-tech.com
 + *
 + * This code is licensed under GNU GPL v2+
 + */
 +
 +#include hw/hw.h
 +#include hw/sysbus.h
 +#include hw/devices.h
 +#include sysemu/sysemu.h
 +
 +#include faraday.h
 +
 +#define REG_MCR 0x00/* memory configuration register */
 +#define REG_MSR 0x04/* memory status register */
 +#define REG_REVR0x50/* revision register */
 +
 +#define MSR_INIT_OK BIT(8)  /* DDR2 initial is completed */
 +#define MSR_CMD_MRS BIT(0)  /* start MRS command */
 +
 +#define CFG_REGSIZE (0x50 / 4)
 +
 +#define TYPE_FTDDRII030 ftddrii030
 +
 +typedef struct Ftddrii030State {
 +SysBusDevice busdev;
 +MemoryRegion iomem;
 +
 +FaradaySoCState *soc;
 +/* HW register cache */
 +uint32_t regs[CFG_REGSIZE];
 +} Ftddrii030State;
 +
 +#define FTDDRII030(obj) \
 +OBJECT_CHECK(Ftddrii030State, obj, TYPE_FTDDRII030)
 +
 +#define DDR_REG32(s, off) \
 +((s)-regs[(off) / 4])
 +
 +static uint64_t
 +ftddrii030_mem_read(void *opaque, hwaddr addr, unsigned size)
 +{
 +Ftddrii030State *s = FTDDRII030(opaque);
 +uint64_t ret = 0;
 +
 +if (s-soc-ddr_inited) {
 +DDR_REG32(s, REG_MSR) |= MSR_INIT_OK;
 +}
 +
 +switch (addr) {
 +case REG_MCR ... (CFG_REGSIZE - 1) * 4:
 +ret = s-regs[addr / 4];
 +break;
 +case REG_REVR:
 +ret = 0x100;/* rev. = 0.1.0 */
 +break;
 +default:
 +qemu_log_mask(LOG_GUEST_ERROR,
 +ftddrii030: undefined memory access@%# HWADDR_PRIx \n, 
 addr);
 +break;
 +}
 +
 +return ret;
 +}
 +
 +static void
 +ftddrii030_mem_write(void *opaque, hwaddr addr, uint64_t val, unsigned 
 size)
 +{
 +Ftddrii030State *s = FTDDRII030(opaque);
 +
 +switch (addr) {
 +case REG_MCR:
 +DDR_REG32(s, REG_MCR) = (uint32_t)val  0x;
 +break;
 +case REG_MSR:
 +val = (val  0x3f) | (DDR_REG32(s, REG_MSR)  MSR_INIT_OK);
 +if (!s-soc-ddr_inited  (val  MSR_CMD_MRS)) {
 +val = ~MSR_CMD_MRS;
 +val |= MSR_INIT_OK;
 +memory_region_add_subregion(s-soc-as,
 +s-soc-ram_base,
 +s-soc-ram);

 I feel like this is overstepping the bounds of the device. Its
 modifying the internals of the parent device (the SoC itself). AFAICT,
 this device does not need awareness of where the RAM is to live in the
 address map, thats the responsibility of the machine model. It might
 be cleaner to model the actual RAM as a second sysbus memory region
 then leave it up the machine model to decide where in the address map
 it should live. This device just adds/removes the ram from the second
 region without knowing where it lives and the machine model maps the
 RAM to its actual location. Keeps .as .ram_base and .ram private to
 the SoC device.


 Thanks 

Re: [Qemu-devel] [PATCH 0/4] Fix JSON string formatter

2013-03-18 Thread Markus Armbruster
Blue Swirl blauwir...@gmail.com writes:

 On Thu, Mar 14, 2013 at 5:49 PM, Markus Armbruster arm...@redhat.com wrote:
 This should unbreak make check on machines where char is unsigned.
 Blue, please give it a whirl.

 With the patches applied there are no errors, thanks.
 Tested-by: Blue Swirl blauwir...@gmail.com

Thanks!

 Though test-coroutine seems to hang, maybe fallout from recent
 coroutine changes.

I've seen rtc-test hang intermittently; haven't gotten around to digging
for roots.



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

2013-03-18 Thread Wenchao Xia

于 2013-3-14 16:22, Kevin Wolf 写道:

Am 14.03.2013 um 06:08 hat Wenchao Xia geschrieben:

于 2013-3-13 18:18, Kevin Wolf 写道:

Am 12.03.2013 um 09:30 hat Wenchao Xia geschrieben:

   I redesigned the structure, Following is the fake code:

typedef struct BdrvActionOps {
 /* check the request's validation, allocate p_opaque if needed */
 int (*check)(BlockdevAction *action, void **p_opaque, Error **errp);
 /* take the action */
 int (*submit)(BlockdevAction *action, void *opaque, Error **errp);
 /* update emulator */
 int (*commit)(BlockdevAction *action, void *opaque, Error **errp);
 /* cancel the action */
 int (*rollback)(BlockdevAction *action, void *opaque, Error **errp);
} BdrvActionOps;


Why do you need the split of prepare into check/submit?

If you have prepare/commit/abort, everybody will recognise this as the
standard transaction pattern because this is just how it's done.
Deviating from it needs a good justification in my opinion.

Kevin



   My thought is rejecting the request in *check if parameter invalid
before take any action, while submit do the real action, to reduce
the chance to of rolling back when some request not valid in the batch.


Okay, so it's not strictly needed, but an optimisation of the error
case?

Does it work well when the transaction includes an operation that
depends on the previous one, like create a snapshot and then do
something with this snapshot?


  This seems to complex, since prepare of all actions are executed
in first round, they may interrupt each other later. So I am
thinking make it more clear as complete one job one time, which
may change the old qmp_transcation() logic a little.


Anyway, even if we think it works and is worth the effort to optimise
such error cases, please use names that are consistent with the
transactions used for reopening: (check/)prepare/commit/abort.


  In above way check/prepare can be merged, how do you think of it?


Kevin




--
Best Regards

Wenchao Xia




Re: [Qemu-devel] [PATCH v3 0/2] bridge helper: includedir conf arg

2013-03-18 Thread Stefan Hajnoczi
On Sun, Mar 17, 2013 at 11:17:19PM -0500, Doug Goldstein wrote:
 The goal is to support an 'includedir' to include all files within a
 directory specified in the bridge.conf file. The rationale is to allow
 libvirt to be able to configure interfaces to for use by unprivileged
 users by just simply generating a new configuration file to the directory.
 
 Change from v3:
 - Integreated review changes from Blue Swirl
 
 Change from v2:
 - Integrated review changes from Corey Bryant
 - Integrated review changes from Stefan Hajnoczi
 
 Change from v1:
 - Reversed patch order to make the series clearer
 - Integrated review changes from Corey Bryant
 - Integrated review changes from Stefan Hajnoczi
 
 Doug Goldstein (2):
   bridge helper: unified error cleanup for parse_acl_file
   bridge helper: support conf dirs
 
  qemu-bridge-helper.c | 75 
 +++-
  1 file changed, 63 insertions(+), 12 deletions(-)
 
 -- 
 1.8.1.5
 
 

Reviewed-by: Stefan Hajnoczi stefa...@redhat.com



Re: [Qemu-devel] [RFC] qmp interface for save vmstate to image

2013-03-18 Thread Stefan Hajnoczi
On Mon, Mar 18, 2013 at 02:40:50PM +0800, Wenchao Xia wrote:
 于 2013-3-15 22:51, Stefan Hajnoczi 写道:
  On Fri, Mar 15, 2013 at 03:24:38PM +0800, Wenchao Xia wrote:
 I'd like to add a new way to save vmstate, which will based on the
  migration thread, but will write contents to block images, instead
  of fd as stream. Following is the method to add API:
  
  Hi Wenchao,
  What use cases are there besides saving vmstate to a raw image?
  
  I'm curious if you're proposing this since there is no file: URI or
  because you really want to do things like saving vmstate into a qcow2
  file or over NBD.
  
  Stefan
  
 Hi, Stefan
   Most used cases would be raw and qcow2, which is flex and can be
 chosen by user. In this way, existing block layer feature in qemu can
 be used, such as tagging zeros. I haven't check the buffer/cache status
 in qemu block layer, but if there is, it can also benefit.

Okay, thanks for explaining.

You can use caching with the BDRV_O_CACHE_WB option.  Then you need to
call bdrv_co_flush() to ensure data reaches the disk.  The advantage of
caching is that I/O patterns with many small unaligned writes may be
much faster when going through the host's page cache - and reads can
also be faster.

You can bypass the host page cache with BDRV_O_CACHE_WB | BDRV_NO_CACHE.
Here bdrv_co_flush() calls are still necessary to ensure data reaches
the disk.

Stefan



Re: [Qemu-devel] [RFC] qmp interface for save vmstate to image

2013-03-18 Thread Paolo Bonzini
Il 18/03/2013 10:04, Kevin Wolf ha scritto:
 Oh, seems I misread this then. I thought this was about internal live
 snapshots, which is a feature that I consider really useful. I'm not so
 sure if saving the VM state as the disk contents of a qcow2 image is
 really helpful.
 
 If zero clusters help a lot, then there's clearly something to improve
 in the migration protocol, because it shouldn't send so many zeros in
 the first place.

Zero pages are sent as a single 9-byte entry (64 bits for the address
and flags, 8 for the zero).

I don't expect the migration stream to have a single zero cluster, since
every page is prefixed by the 64 bits for the address and flags.
Furthermore, the RAM data would be horribly unaligned because of this.
15-20% sectors or so would be read twice, since reading each page (4104
bytes including the address and flags) would span 10 sectors (5120 bytes).

Paolo



Re: [Qemu-devel] [PATCH v8 05/24] hw/arm: add FTDDRII030 DDRII controller support

2013-03-18 Thread Peter Maydell
On 18 March 2013 09:56, Kuo-Jung Su dant...@gmail.com wrote:
 The FTDDRII030 is responsible for SDRAM initialization.
 Which means the DDRII SDRAM would not be stabilized until the
 SDRAM is correctly initialized.
 =
 In QEMU, the memory_region_add_subregion() is used to perform this emulation.

If you want to model sdram doesn't work unless it's inited
(which is optional, often for qemu it's fine to just have
the RAM always work), then the right way to do this is
probably to have this device provide a memory region which
is a container and which the SoC always maps. Then this device
just maps the RAM into the container when the guest does the
DDR init. Having the device mess with its parent's address
space is a red flag that you're not modelling things right.

 The FTAHBC030 is responsible for AHB device management (base + window size)
 and also the special case for AHB remap of slave4 and slave6.
 =
 In QEMU,
 1. If SDRAM is initialized before activating AHB remap:
 memory_region_del_subregion() must be called prior to
 memory_region_add_subregion().
 And this is the reason why I need '.ddr_inited' and
 '.ahb_remapped' in SoC struct.
 2. If SDRAM is not yet initialized while activating AHB remap:
 Only memory_region_add_subregion() needs to be invoked.

If you're handling add/del subregion then you need to model
this so that the device that does the add/del is working on
a memory region container that it controls. Then it can have
a private data structure field which tracks what the state
of the mapped subregions is. This almost always turns out to
be the same way the hardware design is structured.

At the moment you have add/del going on in this device but
fields relating to what state the subregions are in are
at the top level soc state.

-- PMM



Re: [Qemu-devel] [PATCH V9 00/14] qmp/hmp interfaces for internal snapshot info

2013-03-18 Thread Wenchao Xia

于 2013-3-15 16:07, Kevin Wolf 写道:

Am 15.03.2013 um 07:07 hat Wenchao Xia geschrieben:

于 2013-3-13 20:40, Stefan Hajnoczi 写道:

The same applies for VMDK where one .vmdk can reference multiple extent
files.


   I'd like to confirm: This means a block device can have multiple
images at top level, but one image can still have only one backing
image at most? If my understanding is correct,following should be the
case:

1 device hda have two active images: a.qcow2 and b.qcow2(maybe vmdk
format now, just an example)
2 a.qcow2 file's backing file will be a_base0.qcow2, never a_base0.qcow2
and a_base1.qcow2.


I don't think this describes exactly what happens. Each qemu block
device refers to one BlockDriverState, let's say top.vmdk for the top
level image. This may refer to a backing file, backing.vmdk for example.

Now top.vmdk nd back.vmdk could both be split images, and the former
refers to its extents top_0.vmdk and top_1.vmdk, which contain the
actual data of the image, and the latter may refer to backing_0.vmdk,
backing_1.vmdk and backing_2.vmdk.

So this can happen in any position in the BlockDriverState graph.


  Thank u for the detailed explaination. Currently BlockDriverState
have only one file name, so if my understanding is correct, the multiple
referred disk is actually an internal data struct in VMDK now. Qemu main
block layer only saw main disk in each layer.

an case:
BlockDriverState:
 |
top.vmdk---ref_top.vmdk
 ||
backing_top.vmdk---ref_backing_top.vmdk  backing_ref_top.vmdk

  This seems hard to be reflected in the structure I defined before,
and hard to get in currently block.c's API. what I can think is
improve ImageInfo:

{ 'type': 'ImageInfo',
   'data': {'filename': 'str', 'format': 'str', '*dirty-flag': 'bool',
'*actual-size': 'int', 'virtual-size': 'int',
'*cluster-size': 'int', '*encrypted': 'bool',
'*backing-filename': 'str', '*full-backing-filename': 'str',
'*backing-filename-format': 'str',
'*backing-image: 'ImageInfo',
'*ref-images: '[ImageInfo]',
'*snapshots': ['SnapshotInfo'] } }

  Backing-image reflect that one image can have one main backing file,
and one image can have multiple referenced images. Do you think this
structure is good enough?



   Since ImageInfo already have key 'backing-filename', which stands for
the information got in this image, not from the backing image,
add a new key 'bakcing-image' for recursive linking:

{ 'type': 'ImageInfo',
   'data': {'filename': 'str', 'format': 'str', '*dirty-flag': 'bool',
'*actual-size': 'int', 'virtual-size': 'int',
'*cluster-size': 'int', '*encrypted': 'bool',
'*backing-filename': 'str', '*full-backing-filename': 'str',
'*backing-filename-format': 'str',
'*backing-image: 'ImageInfo',
'*snapshots': ['SnapshotInfo'] } }

   Then insert ImageInfo into BlockDeviceInfo, with key 'images', since
'file' is already used which may break compatibility if we change it.
'images' uses an array for the case when multiple images exist in
top level, not for backing chain.

{ 'type': 'BlockDeviceInfo',
   'data': { 'file': 'str', 'ro': 'bool', 'drv': 'str',
 '*backing_file': 'str', 'backing_file_depth': 'int',
 'encrypted': 'bool', 'encryption_key_missing': 'bool',
 'bps': 'int', 'bps_rd': 'int', 'bps_wr': 'int',
 'iops': 'int', 'iops_rd': 'int', 'iops_wr': 'int',
 'images': ['ImageInfo']} }}


Yes, I think this is what Stefan meant (at least it looks like what I
was thinking of).

Kevin




--
Best Regards

Wenchao Xia




Re: [Qemu-devel] [RFC PATCH RDMA support v4: 03/10] more verbose documentation of the RDMA transport

2013-03-18 Thread Michael S. Tsirkin
On Sun, Mar 17, 2013 at 11:18:56PM -0400, mrhi...@linux.vnet.ibm.com wrote:
 From: Michael R. Hines mrhi...@us.ibm.com
 
 This tries to cover all the questions I got the last time.
 
 Please do tell me what is not clear, and I'll revise again.
 
 Signed-off-by: Michael R. Hines mrhi...@us.ibm.com
 ---
  docs/rdma.txt |  208 
 +
  1 file changed, 208 insertions(+)
  create mode 100644 docs/rdma.txt
 
 diff --git a/docs/rdma.txt b/docs/rdma.txt
 new file mode 100644
 index 000..2a48ab0
 --- /dev/null
 +++ b/docs/rdma.txt
 @@ -0,0 +1,208 @@
 +Changes since v3:
 +
 +- Compile-tested with and without --enable-rdma is working.
 +- Updated docs/rdma.txt (included below)
 +- Merged with latest pull queue from Paolo
 +- Implemented qemu_ram_foreach_block()
 +
 +mrhines@mrhinesdev:~/qemu$ git diff --stat master
 +Makefile.objs |1 +
 +arch_init.c   |   28 +-
 +configure |   25 ++
 +docs/rdma.txt |  190 +++
 +exec.c|   21 ++
 +include/exec/cpu-common.h |6 +
 +include/migration/migration.h |3 +
 +include/migration/qemu-file.h |   10 +
 +include/migration/rdma.h  |  269 
 +include/qemu/sockets.h|1 +
 +migration-rdma.c  |  205 
 +migration.c   |   19 +-
 +rdma.c| 1511 
 ++
 +savevm.c  |  172 +-
 +util/qemu-sockets.c   |2 +-
 +15 files changed, 2445 insertions(+), 18 deletions(-)


Above looks strange :)

 +QEMUFileRDMA:

I think there are two things here, API documentation
and protocol documentation, protocol documentation
still needs some more work. Also if what I understand
from this document is correct this breaks memory overcommit
on destination which needs to be fixed.


 +==
 +
 +QEMUFileRDMA introduces a couple of new functions:
 +
 +1. qemu_rdma_get_buffer()  (QEMUFileOps rdma_read_ops)
 +2. qemu_rdma_put_buffer()  (QEMUFileOps rdma_write_ops)
 +
 +These two functions provide an RDMA transport
 +(not a protocol) without changing the upper-level
 +users of QEMUFile that depend on a bytstream abstraction.
 +
 +In order to provide the same bytestream interface 
 +for RDMA, we use SEND messages instead of sockets.
 +The operations themselves and the protocol built on 
 +top of QEMUFile used throughout the migration 
 +process do not change whatsoever.
 +
 +An infiniband SEND message is the standard ibverbs
 +message used by applications of infiniband hardware.
 +The only difference between a SEND message and an RDMA
 +message is that SEND message cause completion notifications
 +to be posted to the completion queue (CQ) on the 
 +infiniband receiver side, whereas RDMA messages (used
 +for pc.ram) do not (to behave like an actual DMA).
 +
 +Messages in infiniband require two things:
 +
 +1. registration of the memory that will be transmitted
 +2. (SEND only) work requests to be posted on both
 +   sides of the network before the actual transmission
 +   can occur.
 +
 +RDMA messages much easier to deal with. Once the memory
 +on the receiver side is registed and pinned, we're
 +basically done. All that is required is for the sender
 +side to start dumping bytes onto the link.
 +
 +SEND messages require more coordination because the
 +receiver must have reserved space (using a receive
 +work request) on the receive queue (RQ) before QEMUFileRDMA
 +can start using them to carry all the bytes as
 +a transport for migration of device state.
 +
 +After the initial connection setup (migration-rdma.c),

Is there any feature and/or version negotiation? How are we going to
handle compatibility when we extend the protocol?

 +this coordination starts by having both sides post
 +a single work request to the RQ before any users
 +of QEMUFile are activated.

So how does destination know it's ok to send anything
to source?
I suspect this is wrong. When using CM you must post
on RQ before completing the connection negotiation,
not after it's done.

 +
 +Once an initial receive work request is posted,
 +we have a put_buffer()/get_buffer() implementation
 +that looks like this:
 +
 +Logically:
 +
 +qemu_rdma_get_buffer():
 +
 +1. A user on top of QEMUFile calls ops-get_buffer(),
 +   which calls us.
 +2. We transmit an empty SEND to let the sender know that 
 +   we are *ready* to receive some bytes from QEMUFileRDMA.
 +   These bytes will come in the form of a another SEND.
 +3. Before attempting to receive that SEND, we post another
 +   RQ work request to replace the one we just used up.
 +4. Block on a CQ event channel and wait for the SEND
 +   to arrive.
 +5. When the send arrives, librdmacm will unblock us
 +   and we can consume the bytes (described later).

Using an empty message seems somewhat hacky, 

Re: [Qemu-devel] [RFC] qmp interface for save vmstate to image

2013-03-18 Thread Wenchao Xia

于 2013-3-18 17:04, Kevin Wolf 写道:

Am 18.03.2013 um 07:40 hat Wenchao Xia geschrieben:

于 2013-3-15 22:51, Stefan Hajnoczi 写道:

On Fri, Mar 15, 2013 at 03:24:38PM +0800, Wenchao Xia wrote:

I'd like to add a new way to save vmstate, which will based on the
migration thread, but will write contents to block images, instead
of fd as stream. Following is the method to add API:


Hi Wenchao,
What use cases are there besides saving vmstate to a raw image?

I'm curious if you're proposing this since there is no file: URI or
because you really want to do things like saving vmstate into a qcow2
file or over NBD.

Stefan


Hi, Stefan
   Most used cases would be raw and qcow2, which is flex and can be
chosen by user. In this way, existing block layer feature in qemu can
be used, such as tagging zeros. I haven't check the buffer/cache status
in qemu block layer, but if there is, it can also benefit.
   User can specify raw or qcow2 according to host configuration, If
there is dedicated storage components underlining, he can use raw to
skip qemu's block layer.


Oh, seems I misread this then. I thought this was about internal live
snapshots, which is a feature that I consider really useful. I'm not so
sure if saving the VM state as the disk contents of a qcow2 image is
really helpful.


  Actually I am leaving internal live snapshot as 2nd step since there
are a bit more work to do when using migration thread, since SPICE
is handled in migration but not in internal snapshot.
  The main purpose is getting a standalone vmstate saving file with
limited size, since internal snapshot lacks a API now to drop vmstate
at any time.(better to have API to export vmstate/delta block data).


If zero clusters help a lot, then there's clearly something to improve
in the migration protocol, because it shouldn't send so many zeros in
the first place.


 In streaming case, zero are good encoded now I think, but when it uses
fseek(), there may be some zeros inside, and small writes. Handling
those are likely block layer's job, by using image I can directly use
qemu's block layer with qcow2 format, or using raw if underline
component there, make it flex.


Kevin




--
Best Regards

Wenchao Xia




Re: [Qemu-devel] [RFC] qmp interface for save vmstate to image

2013-03-18 Thread Wenchao Xia

于 2013-3-18 18:08, Paolo Bonzini 写道:

Il 18/03/2013 10:04, Kevin Wolf ha scritto:

Oh, seems I misread this then. I thought this was about internal live
snapshots, which is a feature that I consider really useful. I'm not so
sure if saving the VM state as the disk contents of a qcow2 image is
really helpful.

If zero clusters help a lot, then there's clearly something to improve
in the migration protocol, because it shouldn't send so many zeros in
the first place.


Zero pages are sent as a single 9-byte entry (64 bits for the address
and flags, 8 for the zero).

I don't expect the migration stream to have a single zero cluster, since
every page is prefixed by the 64 bits for the address and flags.
Furthermore, the RAM data would be horribly unaligned because of this.
15-20% sectors or so would be read twice, since reading each page (4104
bytes including the address and flags) would span 10 sectors (5120 bytes).

Paolo


  I think in streaming case, zero page will be handled well. I use
qcow2 mainly for fseek() case, which may have some zero holes inside.

--
Best Regards

Wenchao Xia




Re: [Qemu-devel] [PATCH 3/5] pseries: Fixes and enhancements to L1 cache properties

2013-03-18 Thread Andreas Färber
Am 15.03.2013 13:27, schrieb Alexander Graf:
 
 On 14.03.2013, at 02:53, David Gibson wrote:
 
 PAPR requires that the device tree's CPU nodes have several properties
 with information about the L1 cache.  We already create two of these
 properties, but with incorrect names - [id]cache-block-size instead
 of [id]-cache-block-size (note the extra hyphen).

 We were also missing some of the required cache properties.  This
 patch adds the [id]-cache-line-size properties (which have the same
 values as the block size properties in all current cases).  We also
 add the [id]-cache-size properties.

 Adding the cache sizes requires some extra infrastructure in the
 general target-ppc code to (optionally) set the cache sizes for
 various CPUs.  The CPU family descriptions in translate_init.c can set
 these sizes - this patch adds correct information for POWER7, I'm
 leaving other CPU types to people who have a physical example to
 verify against.  In addition, for -cpu host we take the values
 advertised by the host (if available) and use those to override the
 information based on PVR.

 Signed-off-by: David Gibson da...@gibson.dropbear.id.au
 ---
 hw/ppc/spapr.c  |   20 ++--
 target-ppc/cpu.h|1 +
 target-ppc/kvm.c|   39 +++
 target-ppc/translate_init.c |4 
 4 files changed, 62 insertions(+), 2 deletions(-)

 diff --git a/hw/ppc/spapr.c b/hw/ppc/spapr.c
 index 9a13697..7293082 100644
 --- a/hw/ppc/spapr.c
 +++ b/hw/ppc/spapr.c
 @@ -333,10 +333,26 @@ static void *spapr_create_fdt_skel(const char 
 *cpu_model,
 _FDT((fdt_property_string(fdt, device_type, cpu)));

 _FDT((fdt_property_cell(fdt, cpu-version, env-spr[SPR_PVR])));
 -_FDT((fdt_property_cell(fdt, dcache-block-size,
 +_FDT((fdt_property_cell(fdt, d-cache-block-size,
 env-dcache_line_size)));
 -_FDT((fdt_property_cell(fdt, icache-block-size,
 +_FDT((fdt_property_cell(fdt, d-cache-line-size,
 +env-dcache_line_size)));
 +_FDT((fdt_property_cell(fdt, i-cache-block-size,
 +env-icache_line_size)));
 +_FDT((fdt_property_cell(fdt, i-cache-line-size,
 env-icache_line_size)));
 +
 +if (env-l1_dcache_size) {
 +_FDT((fdt_property_cell(fdt, d-cache-size, 
 env-l1_dcache_size)));
 +} else {
 +fprintf(stderr, Warning: Unknown L1 dcache size for cpu\n);
 +}
 +if (env-l1_icache_size) {
 +_FDT((fdt_property_cell(fdt, i-cache-size, 
 env-l1_icache_size)));
 +} else {
 +fprintf(stderr, Warning: Unknown L1 icache size for cpu\n);
 +}
 
 The L1 sizes should come from the class, not env, right? Andreas, any ideas 
 on this?

Generally speaking,

CPUPPCState: Only if this is used for TCG with an offset from AREG0 (or
for legacy grouping reasons).

PowerPCCPU: If you ever intend to let the user override this value
(per-instance) from the command line.

PowerPCCPUClass: If the value is always constant at runtime.

I can't tell from a brief look at this patch which may be the case here.

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 3/5] pseries: Fixes and enhancements to L1 cache properties

2013-03-18 Thread Alexander Graf

On 18.03.2013, at 11:54, Andreas Färber wrote:

 Am 15.03.2013 13:27, schrieb Alexander Graf:
 
 On 14.03.2013, at 02:53, David Gibson wrote:
 
 PAPR requires that the device tree's CPU nodes have several properties
 with information about the L1 cache.  We already create two of these
 properties, but with incorrect names - [id]cache-block-size instead
 of [id]-cache-block-size (note the extra hyphen).
 
 We were also missing some of the required cache properties.  This
 patch adds the [id]-cache-line-size properties (which have the same
 values as the block size properties in all current cases).  We also
 add the [id]-cache-size properties.
 
 Adding the cache sizes requires some extra infrastructure in the
 general target-ppc code to (optionally) set the cache sizes for
 various CPUs.  The CPU family descriptions in translate_init.c can set
 these sizes - this patch adds correct information for POWER7, I'm
 leaving other CPU types to people who have a physical example to
 verify against.  In addition, for -cpu host we take the values
 advertised by the host (if available) and use those to override the
 information based on PVR.
 
 Signed-off-by: David Gibson da...@gibson.dropbear.id.au
 ---
 hw/ppc/spapr.c  |   20 ++--
 target-ppc/cpu.h|1 +
 target-ppc/kvm.c|   39 +++
 target-ppc/translate_init.c |4 
 4 files changed, 62 insertions(+), 2 deletions(-)
 
 diff --git a/hw/ppc/spapr.c b/hw/ppc/spapr.c
 index 9a13697..7293082 100644
 --- a/hw/ppc/spapr.c
 +++ b/hw/ppc/spapr.c
 @@ -333,10 +333,26 @@ static void *spapr_create_fdt_skel(const char 
 *cpu_model,
_FDT((fdt_property_string(fdt, device_type, cpu)));
 
_FDT((fdt_property_cell(fdt, cpu-version, env-spr[SPR_PVR])));
 -_FDT((fdt_property_cell(fdt, dcache-block-size,
 +_FDT((fdt_property_cell(fdt, d-cache-block-size,
env-dcache_line_size)));
 -_FDT((fdt_property_cell(fdt, icache-block-size,
 +_FDT((fdt_property_cell(fdt, d-cache-line-size,
 +env-dcache_line_size)));
 +_FDT((fdt_property_cell(fdt, i-cache-block-size,
 +env-icache_line_size)));
 +_FDT((fdt_property_cell(fdt, i-cache-line-size,
env-icache_line_size)));
 +
 +if (env-l1_dcache_size) {
 +_FDT((fdt_property_cell(fdt, d-cache-size, 
 env-l1_dcache_size)));
 +} else {
 +fprintf(stderr, Warning: Unknown L1 dcache size for cpu\n);
 +}
 +if (env-l1_icache_size) {
 +_FDT((fdt_property_cell(fdt, i-cache-size, 
 env-l1_icache_size)));
 +} else {
 +fprintf(stderr, Warning: Unknown L1 icache size for cpu\n);
 +}
 
 The L1 sizes should come from the class, not env, right? Andreas, any ideas 
 on this?
 
 Generally speaking,
 
 CPUPPCState: Only if this is used for TCG with an offset from AREG0 (or
 for legacy grouping reasons).
 
 PowerPCCPU: If you ever intend to let the user override this value
 (per-instance) from the command line.
 
 PowerPCCPUClass: If the value is always constant at runtime.
 
 I can't tell from a brief look at this patch which may be the case here.

Imagine the following:

  PPC
`- POWER7
|- POWER7_v10
`- POWER7_v20

Version 1.0 has L1 cache size of x MB. Version 2.0 has L1 cache size of y MB. 
The user should never override the value (except with -cpu host). It is 
constant during the lifetime of a VM.


Alex




[Qemu-devel] qemu segfault parsing iscsi options

2013-03-18 Thread Peter Lieven

Hi,

with recent qemu from git qemu segfaults with the following commandline:

x86_64-softmmu/qemu-system-x86_64 -iscsi test

qemu-system-x86_64: -iscsi test: There is no option group 'iscsi'
Speicherzugriffsfehler (Speicherabzug geschrieben)

It seems that there is something missing regarding the iscsi options
in qemu-option.hx.

This was working with qemu-kvm-1.2.0.

Peter



Re: [Qemu-devel] [PATCH][RFC 0/14] implement power chip

2013-03-18 Thread Peter Maydell
On 13 March 2013 08:01, liguang lig.f...@cn.fujitsu.com wrote:
 By now, all devices of QEMU do not have much more
 power management consideration, for example, if
 system do suspend, it will call all registered notifiers,
 this was loosely required, and the code to do power management
 state transition seems just do 'ugly emulation', rather than be
 conscious with whole system devices, same condition with reset(it
 has been embedded in DeviceClass, good!),
 shutdown, in real world, commonly all devices' power are controlled
 by a power chip, then all power sequence can be done just
 issue commands to this chip.
 so, I come across an idea to implement qdev'ed power device, and
 make all qdev struct of devices aware of self power management(add
 on/off/wakeup/suspend ... filed for DeviceClass), this will
 bring tidy power management, and the emulation will more like what
 happened in real world.

I'm really dubious that this can or should be implemented by
adding methods at the device base class level. I don't think
real hardware works this way. You could probably do power on/off
like this. Reset definitely shouldn't be done this way, and
suspend probably not either.

I think more documentation/discussion of what you think the
semantics of the power down/up/etc should be might be useful.

thanks
-- PMM



Re: [Qemu-devel] [Qemu-ppc] [PATCH 3/5] pseries: Fixes and enhancements to L1 cache properties

2013-03-18 Thread Andreas Färber
-BEGIN PGP SIGNED MESSAGE-
Hash: SHA1

Am 16.03.2013 08:10, schrieb David Gibson:
 On Fri, Mar 15, 2013 at 01:27:09PM +0100, Alexander Graf wrote:
 On 14.03.2013, at 02:53, David Gibson wrote:
 
 PAPR requires that the device tree's CPU nodes have several
 properties with information about the L1 cache.  We already
 create two of these properties, but with incorrect names -
 [id]cache-block-size instead of [id]-cache-block-size (note
 the extra hyphen).
 
 We were also missing some of the required cache properties.
 This patch adds the [id]-cache-line-size properties (which have
 the same values as the block size properties in all current
 cases).  We also add the [id]-cache-size properties.
 
 Adding the cache sizes requires some extra infrastructure in
 the general target-ppc code to (optionally) set the cache sizes
 for various CPUs.  The CPU family descriptions in
 translate_init.c can set these sizes - this patch adds correct
 information for POWER7, I'm leaving other CPU types to people
 who have a physical example to verify against.  In addition,
 for -cpu host we take the values advertised by the host (if
 available) and use those to override the information based on
 PVR.
 
 Signed-off-by: David Gibson da...@gibson.dropbear.id.au --- 
 hw/ppc/spapr.c  |   20 ++-- 
 target-ppc/cpu.h|1 + target-ppc/kvm.c
 |   39 +++ 
 target-ppc/translate_init.c |4  4 files changed, 62
 insertions(+), 2 deletions(-)
 
 diff --git a/hw/ppc/spapr.c b/hw/ppc/spapr.c index
 9a13697..7293082 100644 --- a/hw/ppc/spapr.c +++
 b/hw/ppc/spapr.c @@ -333,10 +333,26 @@ static void
 *spapr_create_fdt_skel(const char *cpu_model, 
 _FDT((fdt_property_string(fdt, device_type, cpu)));
 
 _FDT((fdt_property_cell(fdt, cpu-version,
 env-spr[SPR_PVR]))); -_FDT((fdt_property_cell(fdt,
 dcache-block-size, +_FDT((fdt_property_cell(fdt,
 d-cache-block-size, env-dcache_line_size))); -
 _FDT((fdt_property_cell(fdt, icache-block-size, +
 _FDT((fdt_property_cell(fdt, d-cache-line-size, +
 env-dcache_line_size))); +_FDT((fdt_property_cell(fdt,
 i-cache-block-size, +
 env-icache_line_size))); +_FDT((fdt_property_cell(fdt,
 i-cache-line-size, env-icache_line_size))); + +if
 (env-l1_dcache_size) { +
 _FDT((fdt_property_cell(fdt, d-cache-size,
 env-l1_dcache_size))); +} else { +
 fprintf(stderr, Warning: Unknown L1 dcache size for cpu\n); +
 } +if (env-l1_icache_size) { +
 _FDT((fdt_property_cell(fdt, i-cache-size,
 env-l1_icache_size))); +} else { +
 fprintf(stderr, Warning: Unknown L1 icache size for cpu\n); +
 }
 
 The L1 sizes should come from the class, not env, right?
 Andreas, any ideas on this?
 
 Well.. initially I was going to put them in class.  But then it 
 occurred to me that the class represents a family of similar CPUs,
 not a single precise CPU model.  Total cache sizes are the sort of
 thing that could easily vary between minor revisions, although I
 don't know if they have in practice.

Actually that is irrelevant: As it stands, we can do neither
model-specific instance_init nor class_init due to the old
POWERPC_DEF_SVR() macros. Adding support for either seems equally
invasive.

As I just replied to Alex, the question to ask is whether you want the
user to fiddle with this value or not.

Andreas

 So I thought it was safer to put these in env.

- -- 
SUSE LINUX Products GmbH, Maxfeldstr. 5, 90409 Nrnberg, Germany
GF: Jeff Hawn, Jennifer Guild, Felix Imend￶rffer; HRB 16746 AG Nrnberg
-BEGIN PGP SIGNATURE-
Version: GnuPG v2.0.19 (GNU/Linux)

iQIcBAEBAgAGBQJRRvYUAAoJEPou0S0+fgE/TuUP/2ZqXQw9klNYkkKfeA8lml8R
jX6NsdIGDxAh8BQMea5YEVfTUUqHa5ygO4HMSBT42GvWR4gY7lmDO08d2FrtO3Oz
ybWf1OubcNm3rp9vwtGKKWxWAiMBSjv9KqAR2gYd305e15ADr3wzRPRPyUtOXO6r
ute+snXu3rI49wCngAF3zBhQnq+HLyUcLpMn/ss/p0086e5LaPhPjEjUDRoKLED6
xqjG3x65rknpWdRPWtpZJHEhPfuDBKpZTS0XdPUkBQ48F2D0yZ3SbRHfIjnikEtV
G43RXBYAUK449HmJY0/hz5W51Nm81f1Sg04uXDLsG9K7mBNUcw/TxgjzW+7ByVyk
+zjCHsC0aimX7owIgMPNd8wtWXmxs4JxdC7icjDtZUNKUSFHC6plMPInlZdIkTU5
brJq02I16lQCYHfnFkFdUM+pwV7r4B0FtymirEX3G8l3n5ddoFmj4tUmLPdjxcHL
Dzn5LMOGNsvL0hqf5eW5JCcq4FMGIYKkeo839+p2u4nnoYSpNIB7mseZzzTTGEYH
HLMTXRijpX9Po65fMgPkiyv9Mv3w2N7UjjP2E9a2VJk2oRsEMO0GXrV3OUJBD64U
3qmB+xvjLgijrDvlYTWvZtOhqIRuqjtS+La2qxtbWE8Mf3YYZ1UxVFPd82qQf0zw
luXozSihIlcx55xtw9Lr
=ejJS
-END PGP SIGNATURE-



Re: [Qemu-devel] [PATCH] HLFS driver for QEMU

2013-03-18 Thread Stefan Hajnoczi
On Mon, Mar 18, 2013 at 02:47:44PM +0800, harryxi...@gmail.com wrote:
 From: Harry Wei harryxi...@gmail.com
 
 HLFS is HDFS-based(Hadoop Distributed File System) Log-Structured File
 System. Actually, HLFS, currently, is not a FS but a block-storage system,
 which we simplify LFS to fit block-level storage. So you could also call HLFS
 as HLBS (HDFS-based Log-Structured Block-storage System).  HLFS has
 two mode, which are local mode and HDFS mode. HDFS is once write and
 many read so HLFS realize LBS(Log-Structured Block-storage System) to
 achieve reading and writing randomly. LBS is based on LFS's basic theories
 but is different from LFS, which LBS fits block storage better. See
 http://code.google.com/p/cloudxy/wiki/WHAT_IS_CLOUDXY
 about HLFS in details.
 
 Currently, HLFS support following features:
 
 1, Portions of POSIX --- Just realize some interfaces VM image need.
 2, Randomly Read/Write.
 3, Large file storage (TB).
 4, Support snapshots(Linear snapshots and tree snapshots), Clone,
 Block compression, Cache, etc.
 5, A copy of the data more.
 6, Cluster system can dynamic expand.
 ...
 
 Signed-off-by: Harry Wei harryxi...@gmail.com

Is HLFS making releases that distros can package?  I don't see packages
in Debian or Fedora.

Block drivers in qemu.git should have active and sustainable communities
behind them.  For example, if this is a research project where the team
will move on within a year, then it may not be appropriate to merge the
code into QEMU.  Can you share some background on the HLFS community and
where the project is heading?

 ---
  block/Makefile.objs |2 +-
  block/hlfs.c|  515 
 +++
  configure   |   51 +
  3 files changed, 567 insertions(+), 1 deletion(-)
  create mode 100644 block/hlfs.c
 
 diff --git a/block/Makefile.objs b/block/Makefile.objs
 index c067f38..723c7a5 100644
 --- a/block/Makefile.objs
 +++ b/block/Makefile.objs
 @@ -8,7 +8,7 @@ block-obj-$(CONFIG_POSIX) += raw-posix.o
  block-obj-$(CONFIG_LINUX_AIO) += linux-aio.o
  
  ifeq ($(CONFIG_POSIX),y)
 -block-obj-y += nbd.o sheepdog.o
 +block-obj-y += nbd.o sheepdog.o hlfs.o

Missing CONFIG_HLFS to compile out hlfs.o.

 +static int hlbs_write(BlockDriverState *bs, int64_t sector_num, const uint8_t
 +*buf, int nb_sectors)
 +{
 +int ret;
 +BDRVHLBSState *s = bs-opaque;
 +uint32_t write_size = nb_sectors * 512;
 +uint64_t offset = sector_num * 512;
 +ret = hlfs_write(s-hctrl, (char *)buf, write_size, offset);
 +if (ret != write_size) {
 +return -EIO;
 +}
 +return 0;
 +}
 +
 +static int hlbs_read(BlockDriverState *bs, int64_t sector_num, uint8_t *buf,
 +int nb_sectors)
 +{
 +int ret;
 +BDRVHLBSState *s = bs-opaque;
 +uint32_t read_size = nb_sectors * 512;
 +uint64_t offset = sector_num * 512;
 +ret = hlfs_read(s-hctrl, (char *)buf, read_size, offset);
 +if (ret != read_size) {
 +return -EIO;
 +}
 +return 0;
 +}
 +
 +static int hlbs_flush(BlockDriverState *bs)
 +{
 +int ret;
 +BDRVHLBSState *s = bs-opaque;
 +ret = hlfs_flush(s-hctrl);
 +return ret;
 +}

read/write/flush should be either .bdrv_co_* or .bdrv_aio_*.

The current code pauses the guest while I/O is in progress!  Try running
disk I/O benchmarks inside the guest and you'll see that performance and
interactivity are poor.

QEMU has two ways of implementing efficient block drivers:

1. Coroutines - .bdrv_co_*

Good for image formats or block drivers that have internal logic.

Each request runs inside a coroutine - see include/block/coroutine.h.
In order to wait for I/O, submit an asynchronous request or worker
thread and yield the coroutine.  When the request completes, re-enter
the coroutine and continue.

Examples: block/sheepdog.c or block/qcow2.c.

2. Asynchronous I/O - .bdrv_aio_*

Good for low-level block drivers that have little logic.

The request processing code is split into callbacks.  I/O requests are
submitted and then the code returns back to QEMU's main loop.  When the
I/O request completes, a callback is invoked.

Examples: block/rbd.c or block/qed.c.

 +static int hlbs_snapshot_delete(BlockDriverState *bs, const char *snapshot)
 +{
 +/* FIXME: Delete specified snapshot id.  */

Outdated comment?

 +BDRVHLBSState *s = bs-opaque;
 +int ret = 0;
 +ret = hlfs_rm_snapshot(s-hctrl-storage-uri, snapshot);
 +return ret;
 +}
 +
 +static int hlbs_snapshot_list(BlockDriverState *bs, QEMUSnapshotInfo 
 **psn_tab)
 +{
 +BDRVHLBSState *s = bs-opaque;
 +/*Fixed: num_entries must be inited 0*/

Comment can be dropped?

 +int num_entries = 0;
 +struct snapshot *snapshots = 
 hlfs_get_all_snapshots(s-hctrl-storage-uri,

I suggest using hlfs_ as a prefix for libhlfs structs.  Otherwise you
risk name collisions.

 +num_entries);
 +dprintf(snapshot count:%d\n, num_entries);
 +/*Fixed: snapshots is NULL condition*/

Comment can be 

[Qemu-devel] [PULL 0/5] ipxe: add efi support

2013-03-18 Thread Gerd Hoffmann
  Hi,

This pull adds efi support to our nic roms.

Patches have been posted here for review:
https://lists.nongnu.org/archive/html/qemu-devel/2013-03/msg00344.html

As there have been no changes (other than a rebase to master)
I'm not posting the patches again.

please pull,
  Gerd

The following changes since commit 225dc991b03f0f034aa348f5cf499de9d0979107:

  s390: Fix cpu refactoring fallout. (2013-03-17 20:01:31 +)

are available in the git repository at:

  git://git.kraxel.org/qemu ipxe.2

for you to fetch changes up to c45e5b5b30ac1f5505725a7b36e68cedfce4f01f:

  Switch to efi-enabled nic roms by default (2013-03-18 10:21:56 +0100)


Gerd Hoffmann (5):
  Add Makefile rules to build nic rom binaries
  Update ipxe submodule to latest master
  Add Makefile rules to build nic rom binaries with efi support
  Add efi rom binaries
  Switch to efi-enabled nic roms by default

 hw/e1000.c   |2 +-
 hw/ne2000.c  |2 +-
 hw/pc.h  |   24 ++--
 hw/pcnet-pci.c   |2 +-
 hw/rtl8139.c |2 +-
 hw/virtio-pci.c  |2 +-
 pc-bios/efi-e1000.rom|  Bin 0 - 174080 bytes
 pc-bios/efi-eepro100.rom |  Bin 0 - 175104 bytes
 pc-bios/efi-ne2k_pci.rom |  Bin 0 - 173568 bytes
 pc-bios/efi-pcnet.rom|  Bin 0 - 173568 bytes
 pc-bios/efi-rtl8139.rom  |  Bin 0 - 177152 bytes
 pc-bios/efi-virtio.rom   |  Bin 0 - 171008 bytes
 roms/Makefile|   46 ++
 roms/ipxe|2 +-
 14 files changed, 74 insertions(+), 8 deletions(-)
 create mode 100644 pc-bios/efi-e1000.rom
 create mode 100644 pc-bios/efi-eepro100.rom
 create mode 100644 pc-bios/efi-ne2k_pci.rom
 create mode 100644 pc-bios/efi-pcnet.rom
 create mode 100644 pc-bios/efi-rtl8139.rom
 create mode 100644 pc-bios/efi-virtio.rom



[Qemu-devel] KVM call agenda for 2013-03-19

2013-03-18 Thread Juan Quintela

Hi

Please send in any agenda topics you are interested in.

Later, Juan.



[Qemu-devel] [PULL 00/18] console: data structures overhaul

2013-03-18 Thread Gerd Hoffmann
  Hi,

This pull sorts the qemu console data structures.  Current state
is that DisplayState is used pretty much everywhere.  Which is bad.
With this patch series applied it looks like this instead:

DisplaySurface
Central framebuffer data structure.  ui frontents (gtk, sdl,
vnc, ...) use this (and *only* this) as data source.

QemuConsole
Central hardware data structures.  Each graphic card gets one,
likewise each 'vc' chardev.

DisplayState
Ties everything together.  Private to console.c (well, should
be, we are not there yet).

This is a prerequisite for cleaning up and improving console.c and also
brings us a step closer to multihead support.

Patches have been posted for review here:
  https://lists.nongnu.org/archive/html/qemu-devel/2013-03/msg01961.html

There have been no changes, other than a rebase to latest master,
so I'm not posting the patches again.

please pull,
  Gerd

The following changes since commit 225dc991b03f0f034aa348f5cf499de9d0979107:

  s390: Fix cpu refactoring fallout. (2013-03-17 20:01:31 +)

are available in the git repository at:

  git://git.kraxel.org/qemu pixman.v8

for you to fetch changes up to 1562e53112fd1082c656a06d953a7447ab17e6e1:

  console: remove ds_get_* helper functions (2013-03-18 10:21:59 +0100)


Gerd Hoffmann (18):
  console: fix displaychangelisteners interface
  console: kill DisplayState-opaque
  spice: zap sdpy global
  qxl: zap qxl0 global
  qxl: better vga init in enter_vga_mode
  sdl: drop dead code
  console: rework DisplaySurface handling [vga emu side]
  console: rework DisplaySurface handling [dcl/ui side]
  console: add surface_*() getters
  gtk: stop using DisplayState
  vnc: stop using DisplayState
  sdl: stop using DisplayState
  spice: stop using DisplayState
  cocoa: stop using DisplayState
  console: zap displaystate from dcl callbacks
  console: stop using DisplayState in gfx hardware emulation
  console: zap color_table
  console: remove ds_get_* helper functions

 hw/arm/musicpal.c  |   20 +-
 hw/arm/nseries.c   |7 -
 hw/arm/palm.c  |7 -
 hw/blizzard.c  |   37 ++--
 hw/cirrus_vga.c|   22 ++-
 hw/exynos4210_fimd.c   |   17 +-
 hw/framebuffer.c   |4 +-
 hw/framebuffer.h   |2 +-
 hw/g364fb.c|   43 ++--
 hw/jazz_led.c  |   88 +
 hw/milkymist-vgafb.c   |   17 +-
 hw/omap_lcdc.c |   47 +++--
 hw/pl110.c |   24 +--
 hw/pxa2xx_lcd.c|   39 ++--
 hw/qxl-render.c|   21 +-
 hw/qxl.c   |   61 +++---
 hw/sm501.c |   34 ++--
 hw/ssd0303.c   |   17 +-
 hw/ssd0323.c   |   19 +-
 hw/tc6393xb.c  |   28 +--
 hw/tc6393xb_template.h |5 +-
 hw/tcx.c   |   62 +++---
 hw/vga-isa-mm.c|5 +-
 hw/vga-isa.c   |4 +-
 hw/vga-pci.c   |4 +-
 hw/vga.c   |  109 +-
 hw/vga_int.h   |2 +-
 hw/vmware_vga.c|  107 +-
 hw/xenfb.c |   57 +++---
 include/ui/console.h   |  274 +++---
 include/ui/spice-display.h |9 +-
 trace-events   |7 +-
 ui/cocoa.m |   57 ++
 ui/console.c   |  470 +---
 ui/curses.c|   28 ++-
 ui/gtk.c   |  160 ---
 ui/sdl.c   |  118 ++-
 ui/spice-display.c |   81 
 ui/vnc-enc-tight.c |7 +-
 ui/vnc-jobs.c  |1 -
 ui/vnc.c   |  143 +++---
 ui/vnc.h   |4 +-
 vl.c   |6 +-
 43 files changed, 1170 insertions(+), 1104 deletions(-)



[Qemu-devel] [PATCH 1/2] virtio-ccw: Add missing blk chs properties.

2013-03-18 Thread Cornelia Huck
Signed-off-by: Cornelia Huck cornelia.h...@de.ibm.com
---
 hw/s390x/virtio-ccw.c |1 +
 1 file changed, 1 insertion(+)

diff --git a/hw/s390x/virtio-ccw.c b/hw/s390x/virtio-ccw.c
index d4361f6..70aba41 100644
--- a/hw/s390x/virtio-ccw.c
+++ b/hw/s390x/virtio-ccw.c
@@ -755,6 +755,7 @@ static const TypeInfo virtio_ccw_net = {
 static Property virtio_ccw_blk_properties[] = {
 DEFINE_PROP_STRING(devno, VirtioCcwDevice, bus_id),
 DEFINE_BLOCK_PROPERTIES(VirtioCcwDevice, blk.conf),
+DEFINE_BLOCK_CHS_PROPERTIES(VirtioCcwDevice, blk.conf),
 DEFINE_PROP_STRING(serial, VirtioCcwDevice, blk.serial),
 #ifdef __linux__
 DEFINE_PROP_BIT(scsi, VirtioCcwDevice, blk.scsi, 0, true),
-- 
1.7.9.5




[Qemu-devel] [PATCH 2/2] s390-virtio, virtio-ccw: Add config_wce for virtio-blk.

2013-03-18 Thread Cornelia Huck
There's no reason why we wouldn't want to make the cache mode
configurable.

CC: Alexander Graf ag...@suse.de
Signed-off-by: Cornelia Huck cornelia.h...@de.ibm.com
---
 hw/s390x/s390-virtio-bus.c |1 +
 hw/s390x/virtio-ccw.c  |1 +
 2 files changed, 2 insertions(+)

diff --git a/hw/s390x/s390-virtio-bus.c b/hw/s390x/s390-virtio-bus.c
index d9b7f83..18f1292 100644
--- a/hw/s390x/s390-virtio-bus.c
+++ b/hw/s390x/s390-virtio-bus.c
@@ -434,6 +434,7 @@ static Property s390_virtio_blk_properties[] = {
 #ifdef __linux__
 DEFINE_PROP_BIT(scsi, VirtIOS390Device, blk.scsi, 0, true),
 #endif
+DEFINE_PROP_BIT(config-wce, VirtIOS390Device, blk.config_wce, 0, true),
 DEFINE_PROP_END_OF_LIST(),
 };
 
diff --git a/hw/s390x/virtio-ccw.c b/hw/s390x/virtio-ccw.c
index 70aba41..5795bdd 100644
--- a/hw/s390x/virtio-ccw.c
+++ b/hw/s390x/virtio-ccw.c
@@ -761,6 +761,7 @@ static Property virtio_ccw_blk_properties[] = {
 DEFINE_PROP_BIT(scsi, VirtioCcwDevice, blk.scsi, 0, true),
 #endif
 DEFINE_VIRTIO_BLK_FEATURES(VirtioCcwDevice, host_features[0]),
+DEFINE_PROP_BIT(config-wce, VirtioCcwDevice, blk.config_wce, 0, true),
 DEFINE_PROP_END_OF_LIST(),
 };
 
-- 
1.7.9.5




[Qemu-devel] [PATCH 0/2] virtio-ccw queue as of 03/18/13

2013-03-18 Thread Cornelia Huck
The following patches can be found in my git tree at

git://github.com/cohuck/qemu virtio-ccw-upstr

Current patches in the virtio-ccw queue deal both with adding some
missing properties for virtio-blk.

Alex: Could you please ack patch 2 for s390-virtio, or would you prefer
to take it through your tree?

Cornelia Huck (2):
  virtio-ccw: Add missing blk chs properties.
  s390-virtio, virtio-ccw: Add config_wce for virtio-blk.

 hw/s390x/s390-virtio-bus.c |1 +
 hw/s390x/virtio-ccw.c  |2 ++
 2 files changed, 3 insertions(+)

-- 
1.7.9.5




Re: [Qemu-devel] [PATCH 2/2] s390-virtio, virtio-ccw: Add config_wce for virtio-blk.

2013-03-18 Thread Alexander Graf

On 18.03.2013, at 12:42, Cornelia Huck wrote:

 There's no reason why we wouldn't want to make the cache mode
 configurable.
 
 CC: Alexander Graf ag...@suse.de
 Signed-off-by: Cornelia Huck cornelia.h...@de.ibm.com

Acked-by: Alexander Graf ag...@suse.de

Let's hope this whole bug category goes away with Fred's revamp of virtio :)


Alex

 ---
 hw/s390x/s390-virtio-bus.c |1 +
 hw/s390x/virtio-ccw.c  |1 +
 2 files changed, 2 insertions(+)
 
 diff --git a/hw/s390x/s390-virtio-bus.c b/hw/s390x/s390-virtio-bus.c
 index d9b7f83..18f1292 100644
 --- a/hw/s390x/s390-virtio-bus.c
 +++ b/hw/s390x/s390-virtio-bus.c
 @@ -434,6 +434,7 @@ static Property s390_virtio_blk_properties[] = {
 #ifdef __linux__
 DEFINE_PROP_BIT(scsi, VirtIOS390Device, blk.scsi, 0, true),
 #endif
 +DEFINE_PROP_BIT(config-wce, VirtIOS390Device, blk.config_wce, 0, true),
 DEFINE_PROP_END_OF_LIST(),
 };
 
 diff --git a/hw/s390x/virtio-ccw.c b/hw/s390x/virtio-ccw.c
 index 70aba41..5795bdd 100644
 --- a/hw/s390x/virtio-ccw.c
 +++ b/hw/s390x/virtio-ccw.c
 @@ -761,6 +761,7 @@ static Property virtio_ccw_blk_properties[] = {
 DEFINE_PROP_BIT(scsi, VirtioCcwDevice, blk.scsi, 0, true),
 #endif
 DEFINE_VIRTIO_BLK_FEATURES(VirtioCcwDevice, host_features[0]),
 +DEFINE_PROP_BIT(config-wce, VirtioCcwDevice, blk.config_wce, 0, true),
 DEFINE_PROP_END_OF_LIST(),
 };
 
 -- 
 1.7.9.5
 




[Qemu-devel] [PATCH 11/15] console: zap g_width + g_height

2013-03-18 Thread Gerd Hoffmann
We have a surface per QemuConsole now, so there is no need to keep
track of the QemuConsole size any more as we can query the surface
size directly at any time.

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

diff --git a/ui/console.c b/ui/console.c
index 241720b..771f155 100644
--- a/ui/console.c
+++ b/ui/console.c
@@ -123,7 +123,6 @@ struct QemuConsole {
 graphic_hw_invalidate_ptr hw_invalidate;
 graphic_hw_text_update_ptr hw_text_update;
 void *hw;
-int g_width, g_height;
 
 /* Text console state */
 int width;
@@ -384,8 +383,8 @@ static void text_console_resize(QemuConsole *s)
 int w1, x, y, last_width;
 
 last_width = s-width;
-s-width = s-g_width / FONT_WIDTH;
-s-height = s-g_height / FONT_HEIGHT;
+s-width = surface_width(s-surface) / FONT_WIDTH;
+s-height = surface_height(s-surface) / FONT_HEIGHT;
 
 w1 = last_width;
 if (s-width  w1)
@@ -946,18 +945,12 @@ static void console_putchar(QemuConsole *s, int ch)
 
 void console_select(unsigned int index)
 {
-DisplaySurface *surface;
 QemuConsole *s;
 
 if (index = MAX_CONSOLES)
 return;
 
 trace_console_select(index);
-if (active_console) {
-surface = qemu_console_surface(active_console);
-active_console-g_width = surface_width(surface);
-active_console-g_height = surface_height(surface);
-}
 s = consoles[index];
 if (s) {
 DisplayState *ds = s-ds;
@@ -1084,11 +1077,8 @@ void kbd_put_keysym(int keysym)
 static void text_console_invalidate(void *opaque)
 {
 QemuConsole *s = (QemuConsole *) opaque;
-DisplaySurface *surface = qemu_console_surface(s);
 
 if (s-ds-have_text  s-console_type == TEXT_CONSOLE) {
-s-g_width = surface_width(surface);
-s-g_height = surface_height(surface);
 text_console_resize(s);
 }
 console_refresh(s);
@@ -1492,6 +1482,8 @@ static void text_console_update_cursor(void *opaque)
 static void text_console_do_init(CharDriverState *chr, DisplayState *ds)
 {
 QemuConsole *s;
+int g_width = 80 * FONT_WIDTH;
+int g_height = 24 * FONT_HEIGHT;
 
 s = chr-opaque;
 
@@ -1507,16 +1499,13 @@ static void text_console_do_init(CharDriverState *chr, 
DisplayState *ds)
 s-total_height = DEFAULT_BACKSCROLL;
 s-x = 0;
 s-y = 0;
-if (s-console_type == TEXT_CONSOLE) {
+if (!s-surface) {
 if (active_console  active_console-surface) {
-s-g_width = surface_width(active_console-surface);
-s-g_height = surface_height(active_console-surface);
-} else {
-s-g_width = 80 * FONT_WIDTH;
-s-g_height = 24 * FONT_HEIGHT;
+g_width = surface_width(active_console-surface);
+g_height = surface_height(active_console-surface);
 }
+s-surface = qemu_create_displaysurface(g_width, g_height);
 }
-s-surface = qemu_create_displaysurface(s-g_width, s-g_height);
 
 s-cursor_timer =
 qemu_new_timer_ms(rt_clock, text_console_update_cursor, s);
@@ -1578,6 +1567,7 @@ static CharDriverState *text_console_init(ChardevVC *vc)
 s = new_console(NULL, TEXT_CONSOLE);
 } else {
 s = new_console(NULL, TEXT_CONSOLE_FIXED_SIZE);
+s-surface = qemu_create_displaysurface(width, height);
 }
 
 if (!s) {
@@ -1586,8 +1576,6 @@ static CharDriverState *text_console_init(ChardevVC *vc)
 }
 
 s-chr = chr;
-s-g_width = width;
-s-g_height = height;
 chr-opaque = s;
 chr-chr_set_echo = text_console_set_echo;
 
@@ -1614,8 +1602,6 @@ void qemu_console_resize(QemuConsole *s, int width, int 
height)
 DisplaySurface *surface;
 
 assert(s-console_type == GRAPHIC_CONSOLE);
-s-g_width = width;
-s-g_height = height;
 surface = qemu_create_displaysurface(width, height);
 dpy_gfx_replace_surface(s, surface);
 }
-- 
1.7.9.7




[Qemu-devel] [PATCH 03/15] console: use pixman for fill+blit

2013-03-18 Thread Gerd Hoffmann
Zap homegrown pixel shuffeling code, use pixman calls instead.

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

diff --git a/ui/console.c b/ui/console.c
index eb7a2bc..0ec0911 100644
--- a/ui/console.c
+++ b/ui/console.c
@@ -213,36 +213,14 @@ static void vga_fill_rect(QemuConsole *con,
   uint32_t color)
 {
 DisplaySurface *surface = qemu_console_surface(con);
-uint8_t *d, *d1;
-int x, y, bpp;
+pixman_rectangle16_t rect = {
+.x = posx, .y = posy, .width = width, .height = height
+};
+pixman_color_t pcolor;
 
-bpp = surface_bytes_per_pixel(surface);
-d1 = surface_data(surface) +
-surface_stride(surface) * posy + bpp * posx;
-for (y = 0; y  height; y++) {
-d = d1;
-switch(bpp) {
-case 1:
-for (x = 0; x  width; x++) {
-*((uint8_t *)d) = color;
-d++;
-}
-break;
-case 2:
-for (x = 0; x  width; x++) {
-*((uint16_t *)d) = color;
-d += 2;
-}
-break;
-case 4:
-for (x = 0; x  width; x++) {
-*((uint32_t *)d) = color;
-d += 4;
-}
-break;
-}
-d1 += surface_stride(surface);
-}
+pcolor = qemu_pixman_color(surface-pf, color);
+pixman_image_fill_rectangles(PIXMAN_OP_SRC, surface-image,
+ pcolor, 1, rect);
 }
 
 /* copy from (xs, ys) to (xd, yd) a rectangle of size (w, h) */
@@ -250,33 +228,10 @@ static void vga_bitblt(QemuConsole *con,
int xs, int ys, int xd, int yd, int w, int h)
 {
 DisplaySurface *surface = qemu_console_surface(con);
-const uint8_t *s;
-uint8_t *d;
-int wb, y, bpp;
 
-bpp = surface_bytes_per_pixel(surface);
-wb = w * bpp;
-if (yd = ys) {
-s = surface_data(surface) +
-surface_stride(surface) * ys + bpp * xs;
-d = surface_data(surface) +
-surface_stride(surface) * yd + bpp * xd;
-for (y = 0; y  h; y++) {
-memmove(d, s, wb);
-d += surface_stride(surface);
-s += surface_stride(surface);
-}
-} else {
-s = surface_data(surface) +
-surface_stride(surface) * (ys + h - 1) + bpp * xs;
-d = surface_data(surface) +
-surface_stride(surface) * (yd + h - 1) + bpp * xd;
-   for (y = 0; y  h; y++) {
-memmove(d, s, wb);
-d -= surface_stride(surface);
-s -= surface_stride(surface);
-}
-}
+pixman_image_composite(PIXMAN_OP_SRC,
+   surface-image, NULL, surface-image,
+   xs, ys, 0, 0, xd, yd, w, h);
 }
 
 /***/
-- 
1.7.9.7




[Qemu-devel] [PATCH 00/15] console: overhaul continued.

2013-03-18 Thread Gerd Hoffmann
  Hi,

Next round of console cleanup patches for review.  What is in there?

  (1) qemu text consoles are rendered using pixman now.
  (2) Each QemuConsole has its own DisplaySurface now, so we can
  switch consoles without re-rendering the QemuConsole and
  update non-active consoles.
  (3) Based on (2) the screendump code is simplified *alot*.
  (4) gui refresh timer adaption is fixes and consolidated.

Also some cleanups and bugfixes.

please review,
  Gerd

Gerd Hoffmann (15):
  pixman: add qemu_pixman_color()
  pixman: render vgafont glyphs into pixman images
  console: use pixman for fill+blit
  console: use pixman for font rendering
  console: switch color_table_rgb to pixman_color_t
  console: add trace events
  console: displaystate init revamp
  console: rename vga_hw_*, add QemuConsole param
  console: give each QemuConsole its own DisplaySurface
  console: simplify screendump
  console: zap g_width + g_height
  console: move gui_update+gui_setup_refresh from vl.c into console.c
  console: make DisplayState private to console.c
  console: add GraphicHwOps
  console: gui timer fixes

 hw/arm/musicpal.c|8 +-
 hw/blizzard.c|   21 +-
 hw/cirrus_vga.c  |   10 +-
 hw/exynos4210_fimd.c |8 +-
 hw/g364fb.c  |   80 +--
 hw/jazz_led.c|   11 +-
 hw/milkymist-vgafb.c |9 +-
 hw/omap_lcdc.c   |   93 +---
 hw/pl110.c   |9 +-
 hw/pxa2xx_lcd.c  |9 +-
 hw/qxl.c |   38 +---
 hw/sm501.c   |7 +-
 hw/ssd0303.c |9 +-
 hw/ssd0323.c |9 +-
 hw/tc6393xb.c|   10 +-
 hw/tcx.c |  143 +---
 hw/unicore32/puv3.c  |4 +-
 hw/vga-isa-mm.c  |4 +-
 hw/vga-isa.c |3 +-
 hw/vga-pci.c |3 +-
 hw/vga.c |   76 +--
 hw/vga_int.h |6 +-
 hw/vmware_vga.c  |   46 +---
 hw/xenfb.c   |   11 +-
 include/ui/console.h |   46 ++--
 include/ui/qemu-pixman.h |9 +
 trace-events |4 +
 ui/console.c |  568 +++---
 ui/curses.c  |4 +-
 ui/gtk.c |2 +-
 ui/qemu-pixman.c |   54 +
 ui/sdl.c |   28 +--
 ui/spice-display.c   |2 +-
 ui/vnc.c |   81 ++-
 ui/vnc.h |2 -
 vl.c |   55 +
 36 files changed, 548 insertions(+), 934 deletions(-)

-- 
1.7.9.7




[Qemu-devel] [PATCH 07/15] console: displaystate init revamp

2013-03-18 Thread Gerd Hoffmann
We have only one DisplayState, so there is no need for the next
linking, rip it.  Also consolidate all displaystate initialization
into init_displaystate().  This function is called by vl.c after
creating the devices (and thus all QemuConsoles) and before
initializing DisplayChangeListensers (aka gtk/sdl/vnc/spice ui).

Signed-off-by: Gerd Hoffmann kra...@redhat.com
---
 include/ui/console.h |5 +---
 ui/console.c |   73 +++---
 vl.c |6 +
 3 files changed, 36 insertions(+), 48 deletions(-)

diff --git a/include/ui/console.h b/include/ui/console.h
index a234c72..3725dae 100644
--- a/include/ui/console.h
+++ b/include/ui/console.h
@@ -189,12 +189,9 @@ struct DisplayState {
 bool have_text;
 
 QLIST_HEAD(, DisplayChangeListener) listeners;
-
-struct DisplayState *next;
 };
 
-void register_displaystate(DisplayState *ds);
-DisplayState *get_displaystate(void);
+DisplayState *init_displaystate(void);
 DisplaySurface* qemu_create_displaysurface_from(int width, int height, int bpp,
 int linesize, uint8_t *data,
 bool byteswap);
diff --git a/ui/console.c b/ui/console.c
index 45fa580..2c8fd91 100644
--- a/ui/console.c
+++ b/ui/console.c
@@ -163,6 +163,8 @@ static QemuConsole *active_console;
 static QemuConsole *consoles[MAX_CONSOLES];
 static int nb_consoles = 0;
 
+static void text_console_do_init(CharDriverState *chr, DisplayState *ds);
+
 void vga_hw_update(void)
 {
 if (active_console  active_console-hw_update)
@@ -1323,39 +1325,37 @@ bool dpy_cursor_define_supported(QemuConsole *con)
 return false;
 }
 
-static void dumb_display_init(void)
-{
-DisplayState *ds = g_malloc0(sizeof(DisplayState));
-int width = 640;
-int height = 480;
-
-if (is_fixedsize_console()) {
-width = active_console-g_width;
-height = active_console-g_height;
-}
-ds-surface = qemu_create_displaysurface(width, height);
-
-register_displaystate(ds);
-}
-
 /***/
 /* register display */
 
-void register_displaystate(DisplayState *ds)
+/* console.c internal use only */
+static DisplayState *get_alloc_displaystate(void)
 {
-DisplayState **s;
-s = display_state;
-while (*s != NULL)
-s = (*s)-next;
-ds-next = NULL;
-*s = ds;
+if (!display_state) {
+display_state = g_new0(DisplayState, 1);
+}
+return display_state;
 }
 
-DisplayState *get_displaystate(void)
+/*
+ * Called by main(), after creating QemuConsoles
+ * and before initializing ui (sdl/vnc/...).
+ */
+DisplayState *init_displaystate(void)
 {
+int i;
+
 if (!display_state) {
-dumb_display_init ();
+display_state = g_new0(DisplayState, 1);
 }
+
+for (i = 0; i  nb_consoles; i++) {
+if (consoles[i]-console_type != GRAPHIC_CONSOLE 
+consoles[i]-ds == NULL) {
+text_console_do_init(consoles[i]-chr, display_state);
+}
+}
+
 return display_state;
 }
 
@@ -1365,10 +1365,12 @@ QemuConsole *graphic_console_init(vga_hw_update_ptr 
update,
   vga_hw_text_update_ptr text_update,
   void *opaque)
 {
+int width = 640;
+int height = 480;
 QemuConsole *s;
 DisplayState *ds;
 
-ds = (DisplayState *) g_malloc0(sizeof(DisplayState));
+ds = get_alloc_displaystate();
 trace_console_gfx_new();
 s = new_console(ds, GRAPHIC_CONSOLE);
 s-hw_update = update;
@@ -1377,9 +1379,9 @@ QemuConsole *graphic_console_init(vga_hw_update_ptr 
update,
 s-hw_text_update = text_update;
 s-hw = opaque;
 
-ds-surface = qemu_create_displaysurface(640, 480);
-
-register_displaystate(ds);
+if (!ds-surface) {
+ds-surface = qemu_create_displaysurface(width, height);
+}
 return s;
 }
 
@@ -1505,6 +1507,10 @@ static CharDriverState *text_console_init(ChardevVC *vc)
 s-g_height = height;
 chr-opaque = s;
 chr-chr_set_echo = text_console_set_echo;
+
+if (display_state) {
+text_console_do_init(chr, display_state);
+}
 return chr;
 }
 
@@ -1520,17 +1526,6 @@ void register_vc_handler(VcHandler *handler)
 vc_handler = handler;
 }
 
-void text_consoles_set_display(DisplayState *ds)
-{
-int i;
-
-for (i = 0; i  nb_consoles; i++) {
-if (consoles[i]-console_type != GRAPHIC_CONSOLE) {
-text_console_do_init(consoles[i]-chr, ds);
-}
-}
-}
-
 void qemu_console_resize(QemuConsole *s, int width, int height)
 {
 s-g_width = width;
diff --git a/vl.c b/vl.c
index ce51e65..c5eb9a7 100644
--- a/vl.c
+++ b/vl.c
@@ -4300,8 +4300,7 @@ int main(int argc, char **argv, char **envp)
 
 net_check_clients();
 
-/* just use the first displaystate for the moment */
-ds = get_displaystate();
+ds = init_displaystate();
 
 /* 

[Qemu-devel] [PATCH 04/15] console: use pixman for font rendering

2013-03-18 Thread Gerd Hoffmann
Zap homegrown font rendering code, use pixman calls instead.

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

diff --git a/ui/console.c b/ui/console.c
index 0ec0911..4e79268 100644
--- a/ui/console.c
+++ b/ui/console.c
@@ -242,45 +242,6 @@ static void vga_bitblt(QemuConsole *con,
 
 #include vgafont.h
 
-#define cbswap_32(__x) \
-((uint32_t)( \
-   (((uint32_t)(__x)  (uint32_t)0x00ffUL)  24) | \
-   (((uint32_t)(__x)  (uint32_t)0xff00UL)   8) | \
-   (((uint32_t)(__x)  (uint32_t)0x00ffUL)   8) | \
-   (((uint32_t)(__x)  (uint32_t)0xff00UL)  24) ))
-
-#ifdef HOST_WORDS_BIGENDIAN
-#define PAT(x) x
-#else
-#define PAT(x) cbswap_32(x)
-#endif
-
-static const uint32_t dmask16[16] = {
-PAT(0x),
-PAT(0x00ff),
-PAT(0xff00),
-PAT(0x),
-PAT(0x00ff),
-PAT(0x00ff00ff),
-PAT(0x0000),
-PAT(0x00ff),
-PAT(0xff00),
-PAT(0xffff),
-PAT(0xff00ff00),
-PAT(0xff00),
-PAT(0x),
-PAT(0x00ff),
-PAT(0xff00),
-PAT(0x),
-};
-
-static const uint32_t dmask4[4] = {
-PAT(0x),
-PAT(0x),
-PAT(0x),
-PAT(0x),
-};
-
 #ifndef CONFIG_CURSES
 enum color_names {
 COLOR_BLACK   = 0,
@@ -353,17 +314,11 @@ static void console_print_text_attributes(TextAttributes 
*t_attrib, char ch)
 static void vga_putcharxy(QemuConsole *s, int x, int y, int ch,
   TextAttributes *t_attrib)
 {
+static pixman_image_t *glyphs[256];
 DisplaySurface *surface = qemu_console_surface(s);
-uint8_t *d;
-const uint8_t *font_ptr;
-unsigned int font_data, linesize, xorcol, bpp;
-int i;
 unsigned int fgcol, bgcol;
-
-#ifdef DEBUG_CONSOLE
-printf(x: %2i y: %2i, x, y);
-console_print_text_attributes(t_attrib, ch);
-#endif
+pixman_image_t *ifg, *ibg;
+pixman_color_t cfg, cbg;
 
 if (t_attrib-invers) {
 bgcol = color_table_rgb[t_attrib-bold][t_attrib-fgcol];
@@ -372,59 +327,16 @@ static void vga_putcharxy(QemuConsole *s, int x, int y, 
int ch,
 fgcol = color_table_rgb[t_attrib-bold][t_attrib-fgcol];
 bgcol = color_table_rgb[t_attrib-bold][t_attrib-bgcol];
 }
+cfg = qemu_pixman_color(surface-pf, fgcol);
+cbg = qemu_pixman_color(surface-pf, bgcol);
+ifg = pixman_image_create_solid_fill(cfg);
+ibg = pixman_image_create_solid_fill(cbg);
 
-bpp = surface_bytes_per_pixel(surface);
-d = surface_data(surface) +
-surface_stride(surface) * y * FONT_HEIGHT + bpp * x * FONT_WIDTH;
-linesize = surface_stride(surface);
-font_ptr = vgafont16 + FONT_HEIGHT * ch;
-xorcol = bgcol ^ fgcol;
-switch (surface_bits_per_pixel(surface)) {
-case 8:
-for(i = 0; i  FONT_HEIGHT; i++) {
-font_data = *font_ptr++;
-if (t_attrib-uline
- ((i == FONT_HEIGHT - 2) || (i == FONT_HEIGHT - 3))) {
-font_data = 0xFF;
-}
-((uint32_t *)d)[0] = (dmask16[(font_data  4)]  xorcol) ^ bgcol;
-((uint32_t *)d)[1] = (dmask16[(font_data  0)  0xf]  xorcol) ^ 
bgcol;
-d += linesize;
-}
-break;
-case 16:
-case 15:
-for(i = 0; i  FONT_HEIGHT; i++) {
-font_data = *font_ptr++;
-if (t_attrib-uline
- ((i == FONT_HEIGHT - 2) || (i == FONT_HEIGHT - 3))) {
-font_data = 0xFF;
-}
-((uint32_t *)d)[0] = (dmask4[(font_data  6)]  xorcol) ^ bgcol;
-((uint32_t *)d)[1] = (dmask4[(font_data  4)  3]  xorcol) ^ 
bgcol;
-((uint32_t *)d)[2] = (dmask4[(font_data  2)  3]  xorcol) ^ 
bgcol;
-((uint32_t *)d)[3] = (dmask4[(font_data  0)  3]  xorcol) ^ 
bgcol;
-d += linesize;
-}
-break;
-case 32:
-for(i = 0; i  FONT_HEIGHT; i++) {
-font_data = *font_ptr++;
-if (t_attrib-uline  ((i == FONT_HEIGHT - 2) || (i == 
FONT_HEIGHT - 3))) {
-font_data = 0xFF;
-}
-((uint32_t *)d)[0] = (-((font_data  7))  xorcol) ^ bgcol;
-((uint32_t *)d)[1] = (-((font_data  6)  1)  xorcol) ^ bgcol;
-((uint32_t *)d)[2] = (-((font_data  5)  1)  xorcol) ^ bgcol;
-((uint32_t *)d)[3] = (-((font_data  4)  1)  xorcol) ^ bgcol;
-((uint32_t *)d)[4] = (-((font_data  3)  1)  xorcol) ^ bgcol;
-((uint32_t *)d)[5] = (-((font_data  2)  1)  xorcol) ^ bgcol;
-((uint32_t *)d)[6] = (-((font_data  1)  1)  xorcol) ^ bgcol;
-((uint32_t *)d)[7] = (-((font_data  0)  1)  xorcol) ^ bgcol;
-d += linesize;
-}
-break;
+if (!glyphs[ch]) {
+glyphs[ch] = qemu_pixman_glyph_from_vgafont(FONT_HEIGHT, vgafont16, 
ch);

[Qemu-devel] [PATCH 02/15] pixman: render vgafont glyphs into pixman images

2013-03-18 Thread Gerd Hoffmann
Add helper functions to create pixman mask images for glyphs
and to render these glyphs into a pixman image.

Signed-off-by: Gerd Hoffmann kra...@redhat.com
---
 include/ui/qemu-pixman.h |7 +++
 ui/qemu-pixman.c |   43 +++
 2 files changed, 50 insertions(+)

diff --git a/include/ui/qemu-pixman.h b/include/ui/qemu-pixman.h
index b0f09b5..f012ec5 100644
--- a/include/ui/qemu-pixman.h
+++ b/include/ui/qemu-pixman.h
@@ -44,5 +44,12 @@ pixman_image_t 
*qemu_pixman_mirror_create(pixman_format_code_t format,
 void qemu_pixman_image_unref(pixman_image_t *image);
 
 pixman_color_t qemu_pixman_color(PixelFormat *pf, uint32_t color);
+pixman_image_t *qemu_pixman_glyph_from_vgafont(int height, const uint8_t *font,
+   unsigned int ch);
+void qemu_pixman_glyph_render(pixman_image_t *glyph,
+  pixman_image_t *surface,
+  pixman_color_t *fgcol,
+  pixman_color_t *bgcol,
+  int x, int y, int cw, int ch);
 
 #endif /* QEMU_PIXMAN_H */
diff --git a/ui/qemu-pixman.c b/ui/qemu-pixman.c
index be551e0..254bd8c 100644
--- a/ui/qemu-pixman.c
+++ b/ui/qemu-pixman.c
@@ -90,3 +90,46 @@ pixman_color_t qemu_pixman_color(PixelFormat *pf, uint32_t 
color)
 c.alpha = ((color  pf-amask)  pf-ashift)  (16 - pf-abits);
 return c;
 }
+
+pixman_image_t *qemu_pixman_glyph_from_vgafont(int height, const uint8_t *font,
+   unsigned int ch)
+{
+pixman_image_t *glyph;
+uint8_t *data;
+bool bit;
+int x, y;
+
+glyph = pixman_image_create_bits(PIXMAN_a8, 8, height,
+ NULL, 0);
+data = (uint8_t *)pixman_image_get_data(glyph);
+
+font += height * ch;
+for (y = 0; y  height; y++, font++) {
+for (x = 0; x  8; x++, data++) {
+bit = (*font)  (1  (7-x));
+*data = bit ? 0xff : 0x00;
+}
+}
+return glyph;
+}
+
+void qemu_pixman_glyph_render(pixman_image_t *glyph,
+  pixman_image_t *surface,
+  pixman_color_t *fgcol,
+  pixman_color_t *bgcol,
+  int x, int y, int cw, int ch)
+{
+pixman_image_t *ifg = pixman_image_create_solid_fill(fgcol);
+pixman_image_t *ibg = pixman_image_create_solid_fill(bgcol);
+
+pixman_image_composite(PIXMAN_OP_SRC, ibg, NULL, surface,
+   0, 0, 0, 0,
+   cw * x, ch * y,
+   cw, ch);
+pixman_image_composite(PIXMAN_OP_OVER, ifg, glyph, surface,
+   0, 0, 0, 0,
+   cw * x, ch * y,
+   cw, ch);
+pixman_image_unref(ifg);
+pixman_image_unref(ibg);
+}
-- 
1.7.9.7




[Qemu-devel] [PATCH 06/15] console: add trace events

2013-03-18 Thread Gerd Hoffmann
Signed-off-by: Gerd Hoffmann kra...@redhat.com
---
 trace-events |3 +++
 ui/console.c |4 
 2 files changed, 7 insertions(+)

diff --git a/trace-events b/trace-events
index 406fe5f..c241985 100644
--- a/trace-events
+++ b/trace-events
@@ -958,6 +958,9 @@ dma_bdrv_cb(void *dbs, int ret) dbs=%p ret=%d
 dma_map_wait(void *dbs) dbs=%p
 
 # console.h
+console_gfx_new(void) 
+console_txt_new(int w, int h) %dx%d
+console_select(int nr) %d
 displaysurface_create(void *display_surface, int w, int h) surface=%p, %dx%d
 displaysurface_create_from(void *display_surface, int w, int h, int bpp, int 
swap) surface=%p, %dx%d, bpp %d, bswap %d
 displaysurface_free(void *display_surface) surface=%p
diff --git a/ui/console.c b/ui/console.c
index fbec6cb..45fa580 100644
--- a/ui/console.c
+++ b/ui/console.c
@@ -904,6 +904,8 @@ void console_select(unsigned int index)
 
 if (index = MAX_CONSOLES)
 return;
+
+trace_console_select(index);
 if (active_console) {
 surface = qemu_console_surface(active_console);
 active_console-g_width = surface_width(surface);
@@ -1367,6 +1369,7 @@ QemuConsole *graphic_console_init(vga_hw_update_ptr 
update,
 DisplayState *ds;
 
 ds = (DisplayState *) g_malloc0(sizeof(DisplayState));
+trace_console_gfx_new();
 s = new_console(ds, GRAPHIC_CONSOLE);
 s-hw_update = update;
 s-hw_invalidate = invalidate;
@@ -1485,6 +1488,7 @@ static CharDriverState *text_console_init(ChardevVC *vc)
 height = vc-rows * FONT_HEIGHT;
 }
 
+trace_console_txt_new(width, height);
 if (width == 0 || height == 0) {
 s = new_console(NULL, TEXT_CONSOLE);
 } else {
-- 
1.7.9.7




[Qemu-devel] [PATCH 09/15] console: give each QemuConsole its own DisplaySurface

2013-03-18 Thread Gerd Hoffmann
Go away from the global DisplaySurface, give one to each QemuConsole
instead.  With this patch applied it is possible to call
graphics_hw_* functions with qemu consoles which are not the current
foreground console.

Signed-off-by: Gerd Hoffmann kra...@redhat.com
---
 include/ui/console.h |1 -
 ui/console.c |   96 --
 2 files changed, 69 insertions(+), 28 deletions(-)

diff --git a/include/ui/console.h b/include/ui/console.h
index 9c585c0..0dd66fd 100644
--- a/include/ui/console.h
+++ b/include/ui/console.h
@@ -183,7 +183,6 @@ struct DisplayChangeListener {
 };
 
 struct DisplayState {
-struct DisplaySurface *surface;
 struct QEMUTimer *gui_timer;
 bool have_gfx;
 bool have_text;
diff --git a/ui/console.c b/ui/console.c
index 23eed6f..7687ebc 100644
--- a/ui/console.c
+++ b/ui/console.c
@@ -116,6 +116,7 @@ struct QemuConsole {
 int index;
 console_type_t console_type;
 DisplayState *ds;
+DisplaySurface *surface;
 
 /* Graphic console state.  */
 graphic_hw_update_ptr hw_update;
@@ -164,6 +165,8 @@ static QemuConsole *consoles[MAX_CONSOLES];
 static int nb_consoles = 0;
 
 static void text_console_do_init(CharDriverState *chr, DisplayState *ds);
+static void dpy_gfx_switch_surface(DisplayState *ds,
+   DisplaySurface *surface);
 
 void graphic_hw_update(QemuConsole *con)
 {
@@ -933,8 +936,9 @@ void console_select(unsigned int index)
 }
 active_console = s;
 if (ds-have_gfx) {
-surface = qemu_create_displaysurface(s-g_width, s-g_height);
-dpy_gfx_replace_surface(s, surface);
+dpy_gfx_switch_surface(ds, s-surface);
+dpy_gfx_update(s, 0, 0, surface_width(s-surface),
+   surface_height(s-surface));
 }
 if (ds-have_text) {
 dpy_text_resize(s, s-width, s-height);
@@ -943,7 +947,6 @@ void console_select(unsigned int index)
 qemu_mod_timer(s-cursor_timer,
qemu_get_clock_ms(rt_clock) + CONSOLE_CURSOR_PERIOD / 2);
 }
-graphic_hw_invalidate(s);
 }
 }
 
@@ -1195,8 +1198,8 @@ void register_displaychangelistener(DisplayState *ds,
 dcl-ds = ds;
 QLIST_INSERT_HEAD(ds-listeners, dcl, next);
 gui_setup_refresh(ds);
-if (dcl-ops-dpy_gfx_switch) {
-dcl-ops-dpy_gfx_switch(dcl, ds-surface);
+if (dcl-ops-dpy_gfx_switch  active_console) {
+dcl-ops-dpy_gfx_switch(dcl, active_console-surface);
 }
 }
 
@@ -1212,8 +1215,8 @@ void dpy_gfx_update(QemuConsole *con, int x, int y, int 
w, int h)
 {
 DisplayState *s = con-ds;
 struct DisplayChangeListener *dcl;
-int width = pixman_image_get_width(s-surface-image);
-int height = pixman_image_get_height(s-surface-image);
+int width = surface_width(con-surface);
+int height = surface_height(con-surface);
 
 x = MAX(x, 0);
 y = MAX(y, 0);
@@ -1222,6 +1225,9 @@ void dpy_gfx_update(QemuConsole *con, int x, int y, int 
w, int h)
 w = MIN(w, width - x);
 h = MIN(h, height - y);
 
+if (con != active_console) {
+return;
+}
 QLIST_FOREACH(dcl, s-listeners, next) {
 if (dcl-ops-dpy_gfx_update) {
 dcl-ops-dpy_gfx_update(dcl, x, y, w, h);
@@ -1229,19 +1235,28 @@ void dpy_gfx_update(QemuConsole *con, int x, int y, int 
w, int h)
 }
 }
 
-void dpy_gfx_replace_surface(QemuConsole *con,
- DisplaySurface *surface)
+static void dpy_gfx_switch_surface(DisplayState *ds,
+   DisplaySurface *surface)
 {
-DisplayState *s = con-ds;
-DisplaySurface *old_surface = s-surface;
 struct DisplayChangeListener *dcl;
 
-s-surface = surface;
-QLIST_FOREACH(dcl, s-listeners, next) {
+QLIST_FOREACH(dcl, ds-listeners, next) {
 if (dcl-ops-dpy_gfx_switch) {
 dcl-ops-dpy_gfx_switch(dcl, surface);
 }
 }
+}
+
+void dpy_gfx_replace_surface(QemuConsole *con,
+ DisplaySurface *surface)
+{
+DisplayState *s = con-ds;
+DisplaySurface *old_surface = con-surface;
+
+con-surface = surface;
+if (con == active_console) {
+dpy_gfx_switch_surface(s, surface);
+}
 qemu_free_displaysurface(old_surface);
 }
 
@@ -1260,6 +1275,10 @@ void dpy_gfx_copy(QemuConsole *con, int src_x, int src_y,
 {
 DisplayState *s = con-ds;
 struct DisplayChangeListener *dcl;
+
+if (con != active_console) {
+return;
+}
 QLIST_FOREACH(dcl, s-listeners, next) {
 if (dcl-ops-dpy_gfx_copy) {
 dcl-ops-dpy_gfx_copy(dcl, src_x, src_y, dst_x, dst_y, w, h);
@@ -1273,6 +1292,10 @@ void dpy_text_cursor(QemuConsole *con, int x, int y)
 {
 DisplayState *s = con-ds;
 struct DisplayChangeListener *dcl;
+
+if (con != active_console) {
+return;
+}
 QLIST_FOREACH(dcl, s-listeners, next) {
 if 

[Qemu-devel] [PATCH 12/15] console: move gui_update+gui_setup_refresh from vl.c into console.c

2013-03-18 Thread Gerd Hoffmann
Pure code motion, no functional changes.

Signed-off-by: Gerd Hoffmann kra...@redhat.com
---
 include/ui/console.h |2 --
 ui/console.c |   50 ++
 vl.c |   49 -
 3 files changed, 50 insertions(+), 51 deletions(-)

diff --git a/include/ui/console.h b/include/ui/console.h
index d6e3e92..d92626b 100644
--- a/include/ui/console.h
+++ b/include/ui/console.h
@@ -213,8 +213,6 @@ static inline int is_buffer_shared(DisplaySurface *surface)
 return !(surface-flags  QEMU_ALLOCATED_FLAG);
 }
 
-void gui_setup_refresh(DisplayState *ds);
-
 void register_displaychangelistener(DisplayState *ds,
 DisplayChangeListener *dcl);
 void unregister_displaychangelistener(DisplayChangeListener *dcl);
diff --git a/ui/console.c b/ui/console.c
index 771f155..8e8f918 100644
--- a/ui/console.c
+++ b/ui/console.c
@@ -166,6 +166,56 @@ static void text_console_do_init(CharDriverState *chr, 
DisplayState *ds);
 static void dpy_gfx_switch_surface(DisplayState *ds,
DisplaySurface *surface);
 
+static void gui_update(void *opaque)
+{
+uint64_t interval = GUI_REFRESH_INTERVAL;
+DisplayState *ds = opaque;
+DisplayChangeListener *dcl;
+
+dpy_refresh(ds);
+
+QLIST_FOREACH(dcl, ds-listeners, next) {
+if (dcl-gui_timer_interval 
+dcl-gui_timer_interval  interval) {
+interval = dcl-gui_timer_interval;
+}
+}
+qemu_mod_timer(ds-gui_timer, interval + qemu_get_clock_ms(rt_clock));
+}
+
+static void gui_setup_refresh(DisplayState *ds)
+{
+DisplayChangeListener *dcl;
+bool need_timer = false;
+bool have_gfx = false;
+bool have_text = false;
+
+QLIST_FOREACH(dcl, ds-listeners, next) {
+if (dcl-ops-dpy_refresh != NULL) {
+need_timer = true;
+}
+if (dcl-ops-dpy_gfx_update != NULL) {
+have_gfx = true;
+}
+if (dcl-ops-dpy_text_update != NULL) {
+have_text = true;
+}
+}
+
+if (need_timer  ds-gui_timer == NULL) {
+ds-gui_timer = qemu_new_timer_ms(rt_clock, gui_update, ds);
+qemu_mod_timer(ds-gui_timer, qemu_get_clock_ms(rt_clock));
+}
+if (!need_timer  ds-gui_timer != NULL) {
+qemu_del_timer(ds-gui_timer);
+qemu_free_timer(ds-gui_timer);
+ds-gui_timer = NULL;
+}
+
+ds-have_gfx = have_gfx;
+ds-have_text = have_text;
+}
+
 void graphic_hw_update(QemuConsole *con)
 {
 if (!con) {
diff --git a/vl.c b/vl.c
index c5eb9a7..12ddd83 100644
--- a/vl.c
+++ b/vl.c
@@ -1615,55 +1615,6 @@ MachineInfoList *qmp_query_machines(Error **errp)
 /***/
 /* main execution loop */
 
-static void gui_update(void *opaque)
-{
-uint64_t interval = GUI_REFRESH_INTERVAL;
-DisplayState *ds = opaque;
-DisplayChangeListener *dcl;
-
-dpy_refresh(ds);
-
-QLIST_FOREACH(dcl, ds-listeners, next) {
-if (dcl-gui_timer_interval 
-dcl-gui_timer_interval  interval)
-interval = dcl-gui_timer_interval;
-}
-qemu_mod_timer(ds-gui_timer, interval + qemu_get_clock_ms(rt_clock));
-}
-
-void gui_setup_refresh(DisplayState *ds)
-{
-DisplayChangeListener *dcl;
-bool need_timer = false;
-bool have_gfx = false;
-bool have_text = false;
-
-QLIST_FOREACH(dcl, ds-listeners, next) {
-if (dcl-ops-dpy_refresh != NULL) {
-need_timer = true;
-}
-if (dcl-ops-dpy_gfx_update != NULL) {
-have_gfx = true;
-}
-if (dcl-ops-dpy_text_update != NULL) {
-have_text = true;
-}
-}
-
-if (need_timer  ds-gui_timer == NULL) {
-ds-gui_timer = qemu_new_timer_ms(rt_clock, gui_update, ds);
-qemu_mod_timer(ds-gui_timer, qemu_get_clock_ms(rt_clock));
-}
-if (!need_timer  ds-gui_timer != NULL) {
-qemu_del_timer(ds-gui_timer);
-qemu_free_timer(ds-gui_timer);
-ds-gui_timer = NULL;
-}
-
-ds-have_gfx = have_gfx;
-ds-have_text = have_text;
-}
-
 struct vm_change_state_entry {
 VMChangeStateHandler *cb;
 void *opaque;
-- 
1.7.9.7




[Qemu-devel] [PATCH 15/15] console: gui timer fixes

2013-03-18 Thread Gerd Hoffmann
Make gui update rate adaption code in gui_update() actually work.
Sprinkle in a tracepoint so you can see the code at work.  Remove
the update rate adaption code in vnc and make vnc simply use the
generic bits instead.

Signed-off-by: Gerd Hoffmann kra...@redhat.com
---
 include/ui/console.h |9 ---
 trace-events |1 +
 ui/console.c |   34 
 ui/sdl.c |   10 +++
 ui/vnc.c |   71 ++
 ui/vnc.h |2 --
 6 files changed, 60 insertions(+), 67 deletions(-)

diff --git a/include/ui/console.h b/include/ui/console.h
index f3e7791..3cb0018 100644
--- a/include/ui/console.h
+++ b/include/ui/console.h
@@ -21,7 +21,8 @@
 #define QEMU_CAPS_LOCK_LED   (1  2)
 
 /* in ms */
-#define GUI_REFRESH_INTERVAL 30
+#define GUI_REFRESH_INTERVAL_DEFAULT30
+#define GUI_REFRESH_INTERVAL_IDLE 3000
 
 typedef void QEMUPutKBDEvent(void *opaque, int keycode);
 typedef void QEMUPutLEDEvent(void *opaque, int ledstate);
@@ -174,8 +175,7 @@ typedef struct DisplayChangeListenerOps {
 } DisplayChangeListenerOps;
 
 struct DisplayChangeListener {
-int idle;
-uint64_t gui_timer_interval;
+uint64_t update_interval;
 const DisplayChangeListenerOps *ops;
 DisplayState *ds;
 
@@ -207,12 +207,13 @@ static inline int is_buffer_shared(DisplaySurface 
*surface)
 
 void register_displaychangelistener(DisplayState *ds,
 DisplayChangeListener *dcl);
+void update_displaychangelistener(DisplayChangeListener *dcl,
+  uint64_t interval);
 void unregister_displaychangelistener(DisplayChangeListener *dcl);
 
 void dpy_gfx_update(QemuConsole *con, int x, int y, int w, int h);
 void dpy_gfx_replace_surface(QemuConsole *con,
  DisplaySurface *surface);
-void dpy_refresh(DisplayState *s);
 void dpy_gfx_copy(QemuConsole *con, int src_x, int src_y,
   int dst_x, int dst_y, int w, int h);
 void dpy_text_cursor(QemuConsole *con, int x, int y);
diff --git a/trace-events b/trace-events
index c241985..88b1070 100644
--- a/trace-events
+++ b/trace-events
@@ -961,6 +961,7 @@ dma_map_wait(void *dbs) dbs=%p
 console_gfx_new(void) 
 console_txt_new(int w, int h) %dx%d
 console_select(int nr) %d
+console_refresh(int interval) interval %d ms
 displaysurface_create(void *display_surface, int w, int h) surface=%p, %dx%d
 displaysurface_create_from(void *display_surface, int w, int h, int bpp, int 
swap) surface=%p, %dx%d, bpp %d, bswap %d
 displaysurface_free(void *display_surface) surface=%p
diff --git a/ui/console.c b/ui/console.c
index e85ecf1..7c496e9 100644
--- a/ui/console.c
+++ b/ui/console.c
@@ -157,6 +157,9 @@ struct QemuConsole {
 
 struct DisplayState {
 struct QEMUTimer *gui_timer;
+uint64_t last_update;
+uint64_t update_interval;
+bool refreshing;
 bool have_gfx;
 bool have_text;
 
@@ -171,22 +174,32 @@ static int nb_consoles = 0;
 static void text_console_do_init(CharDriverState *chr, DisplayState *ds);
 static void dpy_gfx_switch_surface(DisplayState *ds,
DisplaySurface *surface);
+static void dpy_refresh(DisplayState *s);
 
 static void gui_update(void *opaque)
 {
-uint64_t interval = GUI_REFRESH_INTERVAL;
+uint64_t interval = GUI_REFRESH_INTERVAL_IDLE;
+uint64_t dcl_interval;
 DisplayState *ds = opaque;
 DisplayChangeListener *dcl;
 
+ds-refreshing = true;
 dpy_refresh(ds);
+ds-refreshing = false;
 
 QLIST_FOREACH(dcl, ds-listeners, next) {
-if (dcl-gui_timer_interval 
-dcl-gui_timer_interval  interval) {
-interval = dcl-gui_timer_interval;
+dcl_interval = dcl-update_interval ?
+dcl-update_interval : GUI_REFRESH_INTERVAL_DEFAULT;
+if (interval  dcl_interval) {
+interval = dcl_interval;
 }
 }
-qemu_mod_timer(ds-gui_timer, interval + qemu_get_clock_ms(rt_clock));
+if (ds-update_interval != interval) {
+ds-update_interval = interval;
+trace_console_refresh(interval);
+}
+ds-last_update = qemu_get_clock_ms(rt_clock);
+qemu_mod_timer(ds-gui_timer, ds-last_update + interval);
 }
 
 static void gui_setup_refresh(DisplayState *ds)
@@ -1280,6 +1293,17 @@ void register_displaychangelistener(DisplayState *ds,
 }
 }
 
+void update_displaychangelistener(DisplayChangeListener *dcl,
+  uint64_t interval)
+{
+DisplayState *ds = dcl-ds;
+
+dcl-update_interval = interval;
+if (!ds-refreshing  ds-update_interval  interval) {
+qemu_mod_timer(ds-gui_timer, ds-last_update + interval);
+}
+}
+
 void unregister_displaychangelistener(DisplayChangeListener *dcl)
 {
 DisplayState *ds = dcl-ds;
diff --git a/ui/sdl.c b/ui/sdl.c
index ede31dc..97764a6 100644
--- a/ui/sdl.c
+++ b/ui/sdl.c
@@ -751,12 +751,12 @@ static void 

[Qemu-devel] [PATCH 13/15] console: make DisplayState private to console.c

2013-03-18 Thread Gerd Hoffmann
With gui_* being moved to console.c nobody outside console.c needs
access to DisplayState fields any more.  Make the struct private.

Signed-off-by: Gerd Hoffmann kra...@redhat.com
---
 include/ui/console.h |8 
 ui/console.c |8 
 2 files changed, 8 insertions(+), 8 deletions(-)

diff --git a/include/ui/console.h b/include/ui/console.h
index d92626b..50cd7b0 100644
--- a/include/ui/console.h
+++ b/include/ui/console.h
@@ -182,14 +182,6 @@ struct DisplayChangeListener {
 QLIST_ENTRY(DisplayChangeListener) next;
 };
 
-struct DisplayState {
-struct QEMUTimer *gui_timer;
-bool have_gfx;
-bool have_text;
-
-QLIST_HEAD(, DisplayChangeListener) listeners;
-};
-
 DisplayState *init_displaystate(void);
 DisplaySurface* qemu_create_displaysurface_from(int width, int height, int bpp,
 int linesize, uint8_t *data,
diff --git a/ui/console.c b/ui/console.c
index 8e8f918..c22895f 100644
--- a/ui/console.c
+++ b/ui/console.c
@@ -157,6 +157,14 @@ struct QemuConsole {
 QEMUTimer *kbd_timer;
 };
 
+struct DisplayState {
+struct QEMUTimer *gui_timer;
+bool have_gfx;
+bool have_text;
+
+QLIST_HEAD(, DisplayChangeListener) listeners;
+};
+
 static DisplayState *display_state;
 static QemuConsole *active_console;
 static QemuConsole *consoles[MAX_CONSOLES];
-- 
1.7.9.7




[Qemu-devel] [PATCH 01/15] pixman: add qemu_pixman_color()

2013-03-18 Thread Gerd Hoffmann
Helper function to map qemu colors (32bit integer + matching PixelFormat)
into pixman_color_t.

Signed-off-by: Gerd Hoffmann kra...@redhat.com
---
 include/ui/qemu-pixman.h |2 ++
 ui/qemu-pixman.c |   11 +++
 2 files changed, 13 insertions(+)

diff --git a/include/ui/qemu-pixman.h b/include/ui/qemu-pixman.h
index b032f52..b0f09b5 100644
--- a/include/ui/qemu-pixman.h
+++ b/include/ui/qemu-pixman.h
@@ -43,4 +43,6 @@ pixman_image_t 
*qemu_pixman_mirror_create(pixman_format_code_t format,
   pixman_image_t *image);
 void qemu_pixman_image_unref(pixman_image_t *image);
 
+pixman_color_t qemu_pixman_color(PixelFormat *pf, uint32_t color);
+
 #endif /* QEMU_PIXMAN_H */
diff --git a/ui/qemu-pixman.c b/ui/qemu-pixman.c
index 6dcbe90..be551e0 100644
--- a/ui/qemu-pixman.c
+++ b/ui/qemu-pixman.c
@@ -79,3 +79,14 @@ void qemu_pixman_image_unref(pixman_image_t *image)
 }
 pixman_image_unref(image);
 }
+
+pixman_color_t qemu_pixman_color(PixelFormat *pf, uint32_t color)
+{
+pixman_color_t c;
+
+c.red   = ((color  pf-rmask)  pf-rshift)  (16 - pf-rbits);
+c.green = ((color  pf-gmask)  pf-gshift)  (16 - pf-gbits);
+c.blue  = ((color  pf-bmask)  pf-bshift)  (16 - pf-bbits);
+c.alpha = ((color  pf-amask)  pf-ashift)  (16 - pf-abits);
+return c;
+}
-- 
1.7.9.7




[Qemu-devel] [PATCH 05/15] console: switch color_table_rgb to pixman_color_t

2013-03-18 Thread Gerd Hoffmann
Now that all text console rendering uses pixman we can easily
switch the color tables to use pixman_color_t directly.

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

diff --git a/ui/console.c b/ui/console.c
index 4e79268..fbec6cb 100644
--- a/ui/console.c
+++ b/ui/console.c
@@ -32,9 +32,6 @@
 #define MAX_CONSOLES 12
 #define CONSOLE_CURSOR_PERIOD 500
 
-#define QEMU_RGBA(r, g, b, a) (((a)  24) | ((r)  16) | ((g)  8) | (b))
-#define QEMU_RGB(r, g, b) QEMU_RGBA(r, g, b, 0xff)
-
 typedef struct TextAttributes {
 uint8_t fgcol:4;
 uint8_t bgcol:4;
@@ -210,17 +207,15 @@ void vga_hw_text_update(console_ch_t *chardata)
 
 static void vga_fill_rect(QemuConsole *con,
   int posx, int posy, int width, int height,
-  uint32_t color)
+  pixman_color_t color)
 {
 DisplaySurface *surface = qemu_console_surface(con);
 pixman_rectangle16_t rect = {
 .x = posx, .y = posy, .width = width, .height = height
 };
-pixman_color_t pcolor;
 
-pcolor = qemu_pixman_color(surface-pf, color);
 pixman_image_fill_rectangles(PIXMAN_OP_SRC, surface-image,
- pcolor, 1, rect);
+ color, 1, rect);
 }
 
 /* copy from (xs, ys) to (xd, yd) a rectangle of size (w, h) */
@@ -255,7 +250,10 @@ enum color_names {
 };
 #endif
 
-static const uint32_t color_table_rgb[2][8] = {
+#define QEMU_RGB(r, g, b)   \
+{ .red = r  8, .green = g  8, .blue = b  8, .alpha = 0 }
+
+static const pixman_color_t color_table_rgb[2][8] = {
 {   /* dark */
 QEMU_RGB(0x00, 0x00, 0x00),  /* black */
 QEMU_RGB(0xaa, 0x00, 0x00),  /* red */
@@ -316,9 +314,7 @@ static void vga_putcharxy(QemuConsole *s, int x, int y, int 
ch,
 {
 static pixman_image_t *glyphs[256];
 DisplaySurface *surface = qemu_console_surface(s);
-unsigned int fgcol, bgcol;
-pixman_image_t *ifg, *ibg;
-pixman_color_t cfg, cbg;
+pixman_color_t fgcol, bgcol;
 
 if (t_attrib-invers) {
 bgcol = color_table_rgb[t_attrib-bold][t_attrib-fgcol];
@@ -327,16 +323,12 @@ static void vga_putcharxy(QemuConsole *s, int x, int y, 
int ch,
 fgcol = color_table_rgb[t_attrib-bold][t_attrib-fgcol];
 bgcol = color_table_rgb[t_attrib-bold][t_attrib-bgcol];
 }
-cfg = qemu_pixman_color(surface-pf, fgcol);
-cbg = qemu_pixman_color(surface-pf, bgcol);
-ifg = pixman_image_create_solid_fill(cfg);
-ibg = pixman_image_create_solid_fill(cbg);
 
 if (!glyphs[ch]) {
 glyphs[ch] = qemu_pixman_glyph_from_vgafont(FONT_HEIGHT, vgafont16, 
ch);
 }
 qemu_pixman_glyph_render(glyphs[ch], surface-image,
- cfg, cbg, x, y, FONT_WIDTH, FONT_HEIGHT);
+ fgcol, bgcol, x, y, FONT_WIDTH, FONT_HEIGHT);
 }
 
 static void text_console_resize(QemuConsole *s)
-- 
1.7.9.7




[Qemu-devel] [PATCH 10/15] console: simplify screendump

2013-03-18 Thread Gerd Hoffmann
Screendumps are alot simpler as we can update non-active
QemuConsoles now.  So we only need to update the QemuConsole
we want write out, then dump the DisplaySurface content into
a ppm file.  Done.

No console switching needed.  No special support code in the
gfx card emulation needed.  Zap it all.  Also move ppm_save
out of the vga code and next to the qmp_screendump function.

For now screen dumping is limited to console #0 (like it used
to be), even though it is dead simple to extend it to other
consoles.  I wanna finish the console cleanup before setting
new qapi interfaces into stone.
---
 hw/arm/musicpal.c|2 +-
 hw/blizzard.c|   14 +-
 hw/cirrus_vga.c  |4 +-
 hw/exynos4210_fimd.c |2 +-
 hw/g364fb.c  |   73 +---
 hw/jazz_led.c|1 -
 hw/milkymist-vgafb.c |2 +-
 hw/omap_lcdc.c   |   86 +
 hw/pl110.c   |2 +-
 hw/pxa2xx_lcd.c  |2 +-
 hw/qxl.c |   22 +
 hw/sm501.c   |2 +-
 hw/ssd0303.c |2 +-
 hw/ssd0323.c |2 +-
 hw/tc6393xb.c|1 -
 hw/tcx.c |  129 +-
 hw/unicore32/puv3.c  |2 +-
 hw/vga-isa-mm.c  |2 +-
 hw/vga-isa.c |2 +-
 hw/vga-pci.c |2 +-
 hw/vga.c |   66 --
 hw/vga_int.h |2 -
 hw/vmware_vga.c  |   26 --
 hw/xenfb.c   |1 -
 include/ui/console.h |3 --
 ui/console.c |   69 +++
 26 files changed, 69 insertions(+), 452 deletions(-)

diff --git a/hw/arm/musicpal.c b/hw/arm/musicpal.c
index edd5282..4e9a23c 100644
--- a/hw/arm/musicpal.c
+++ b/hw/arm/musicpal.c
@@ -612,7 +612,7 @@ static int musicpal_lcd_init(SysBusDevice *dev)
 sysbus_init_mmio(dev, s-iomem);
 
 s-con = graphic_console_init(lcd_refresh, lcd_invalidate,
-  NULL, NULL, s);
+  NULL, s);
 qemu_console_resize(s-con, 128*3, 64*3);
 
 qdev_init_gpio_in(dev-qdev, musicpal_lcd_gpio_brigthness_in, 3);
diff --git a/hw/blizzard.c b/hw/blizzard.c
index 020d3de..891bff8 100644
--- a/hw/blizzard.c
+++ b/hw/blizzard.c
@@ -933,18 +933,6 @@ static void blizzard_update_display(void *opaque)
 s-my[1] = 0;
 }
 
-static void blizzard_screen_dump(void *opaque, const char *filename,
- bool cswitch, Error **errp)
-{
-BlizzardState *s = (BlizzardState *) opaque;
-DisplaySurface *surface = qemu_console_surface(s-con);
-
-blizzard_update_display(opaque);
-if (s  surface_data(surface)) {
-ppm_save(filename, surface, errp);
-}
-}
-
 #define DEPTH 8
 #include hw/blizzard_template.h
 #define DEPTH 15
@@ -965,7 +953,7 @@ void *s1d13745_init(qemu_irq gpio_int)
 
 s-con = graphic_console_init(blizzard_update_display,
   blizzard_invalidate_display,
-  blizzard_screen_dump, NULL, s);
+  NULL, s);
 surface = qemu_console_surface(s-con);
 
 switch (surface_bits_per_pixel(surface)) {
diff --git a/hw/cirrus_vga.c b/hw/cirrus_vga.c
index 8a0f74f..03b3245 100644
--- a/hw/cirrus_vga.c
+++ b/hw/cirrus_vga.c
@@ -2911,7 +2911,7 @@ static int vga_initfn(ISADevice *dev)
 cirrus_init_common(d-cirrus_vga, CIRRUS_ID_CLGD5430, 0,
isa_address_space(dev), isa_address_space_io(dev));
 s-con = graphic_console_init(s-update, s-invalidate,
-  s-screen_dump, s-text_update,
+  s-text_update,
   s);
 rom_add_vga(VGABIOS_CIRRUS_FILENAME);
 /* XXX ISA-LFB support */
@@ -2960,7 +2960,7 @@ static int pci_cirrus_vga_initfn(PCIDevice *dev)
  cirrus_init_common(s, device_id, 1, pci_address_space(dev),
 pci_address_space_io(dev));
  s-vga.con = graphic_console_init(s-vga.update, s-vga.invalidate,
-   s-vga.screen_dump, s-vga.text_update,
+   s-vga.text_update,
s-vga);
 
  /* setup PCI */
diff --git a/hw/exynos4210_fimd.c b/hw/exynos4210_fimd.c
index bf316c6..0ae5d26 100644
--- a/hw/exynos4210_fimd.c
+++ b/hw/exynos4210_fimd.c
@@ -1901,7 +1901,7 @@ static int exynos4210_fimd_init(SysBusDevice *dev)
 exynos4210.fimd, FIMD_REGS_SIZE);
 sysbus_init_mmio(dev, s-iomem);
 s-console = graphic_console_init(exynos4210_fimd_update,
-  exynos4210_fimd_invalidate, NULL, NULL, s);
+  exynos4210_fimd_invalidate, NULL, s);
 
 return 0;
 }
diff --git a/hw/g364fb.c b/hw/g364fb.c
index f7014e9..b70fe8a 100644
--- a/hw/g364fb.c
+++ b/hw/g364fb.c
@@ -294,77 +294,6 @@ static void g364fb_reset(G364State *s)
 

[Qemu-devel] [PATCH] qcow2: Fix segfault in qcow2_invalidate_cache

2013-03-18 Thread Kevin Wolf
Need to pass an options QDict to qcow2_open() now. This fixes a segfault
on the migration target with qcow2.

Signed-off-by: Kevin Wolf kw...@redhat.com
---
 block/qcow2.c | 12 ++--
 block/qcow2.h |  3 +++
 2 files changed, 13 insertions(+), 2 deletions(-)

diff --git a/block/qcow2.c b/block/qcow2.c
index b90dd9e..7fcdc62 100644
--- a/block/qcow2.c
+++ b/block/qcow2.c
@@ -29,6 +29,7 @@
 #include block/qcow2.h
 #include qemu/error-report.h
 #include qapi/qmp/qerror.h
+#include qapi/qmp/qbool.h
 #include trace.h
 
 /*
@@ -520,7 +521,7 @@ static int qcow2_open(BlockDriverState *bs, QDict *options, 
int flags)
 goto fail;
 }
 
-s-use_lazy_refcounts = qemu_opt_get_bool(opts, lazy_refcounts,
+s-use_lazy_refcounts = qemu_opt_get_bool(opts, QCOW2_OPT_LAZY_REFCOUNTS,
 (s-compatible_features  QCOW2_COMPAT_LAZY_REFCOUNTS));
 
 qemu_opts_del(opts);
@@ -934,6 +935,7 @@ static void qcow2_invalidate_cache(BlockDriverState *bs)
 AES_KEY aes_encrypt_key;
 AES_KEY aes_decrypt_key;
 uint32_t crypt_method = 0;
+QDict *options;
 
 /*
  * Backing files are read-only which makes all of their metadata immutable,
@@ -948,8 +950,14 @@ static void qcow2_invalidate_cache(BlockDriverState *bs)
 
 qcow2_close(bs);
 
+options = qdict_new();
+qdict_put(options, QCOW2_OPT_LAZY_REFCOUNTS,
+  qbool_from_int(s-use_lazy_refcounts));
+
 memset(s, 0, sizeof(BDRVQcowState));
-qcow2_open(bs, NULL, flags);
+qcow2_open(bs, options, flags);
+
+QDECREF(options);
 
 if (crypt_method) {
 s-crypt_method = crypt_method;
diff --git a/block/qcow2.h b/block/qcow2.h
index 103abdb..e4b5e11 100644
--- a/block/qcow2.h
+++ b/block/qcow2.h
@@ -58,6 +58,9 @@
 
 #define DEFAULT_CLUSTER_SIZE 65536
 
+
+#define QCOW2_OPT_LAZY_REFCOUNTS lazy_refcounts
+
 typedef struct QCowHeader {
 uint32_t magic;
 uint32_t version;
-- 
1.8.1.4




Re: [Qemu-devel] [PATCH 2/8] virtio-console: Remove any pending watches on close

2013-03-18 Thread Amit Shah
On (Thu) 14 Mar 2013 [17:36:51], Hans de Goede wrote:
 Signed-off-by: Hans de Goede hdego...@redhat.com

Acked-by: Amit Shah amit.s...@redhat.com

Amit



[Qemu-devel] [PATCH v3] migration: Improve QMP documentation

2013-03-18 Thread Juan Quintela
Signed-off-by: Juan Quintela quint...@redhat.com
Reviewed-by: Eric Blake ebl...@redhat.com

---
v2:
 Add Markus suggestions:
v3:
 More Markus suggestions
 Eric Suggestions and reviewed-by
 Learn the --- trick for comments for reviewers

  qmp-commands.hx | 54 --
 1 file changed, 32 insertions(+), 22 deletions(-)

diff --git a/qmp-commands.hx b/qmp-commands.hx
index b370060..5e847b1 100644
--- a/qmp-commands.hx
+++ b/qmp-commands.hx
@@ -644,7 +644,7 @@ EQMP

 SQMP
 migrate-set-cache-size
--
+--

 Set cache size to be used by XBZRLE migration, the cache size will be rounded
 down to the nearest power of 2
@@ -667,7 +667,7 @@ EQMP

 SQMP
 query-migrate-cache-size
--
+

 Show cache size to be used by XBZRLE migration

@@ -2431,32 +2431,42 @@ The main json-object contains the following:
  - Possible values: active, completed, failed, cancelled
 - total-time: total amount of ms since migration started.  If
 migration has ended, it returns the total migration
-time (json-int)
+time (json-int)
 - downtime: only present when migration has finished correctly
   total amount in ms for downtime that happened (json-int)
 - expected-downtime: only present while migration is active
 total amount in ms for downtime that was calculated on
-   the last bitmap round (json-int)
+the last bitmap round (json-int)
 - ram: only present if status is active, it is a json-object with the
-  following RAM information (in bytes):
- - transferred: amount transferred (json-int)
- - remaining: amount remaining (json-int)
- - total: total (json-int)
- - duplicate: number of duplicated pages (json-int)
- - normal : number of normal pages transferred (json-int)
- - normal-bytes : number of normal bytes transferred (json-int)
+  following RAM information:
+ - transferred: amount transferred in bytes (json-int)
+ - remaining: amount remaining to transfer in bytes (json-int)
+ - total: total amount of memory in bytes (json-int)
+ - duplicate: number of pages filled entirely with the same
+byte (json-int)
+These are sent over the wire much more efficiently.
+ - normal : number of whole pages transfered.  I.e. they
+were not sent as duplicate or xbzrle pages (json-int)
+ - normal-bytes : number of bytes transferred in whole
+pages. This is just normal pages times size of one page,
+but this way upper levels don't need to care about page
+size (json-int)
 - disk: only present if status is active and it is a block migration,
-  it is a json-object with the following disk information (in bytes):
- - transferred: amount transferred (json-int)
- - remaining: amount remaining (json-int)
- - total: total (json-int)
+  it is a json-object with the following disk information:
+ - transferred: amount transferred in bytes (json-int)
+ - remaining: amount remaining to transfer in bytes json-int)
+ - total: total disk size in bytes (json-int)
 - xbzrle-cache: only present if XBZRLE is active.
   It is a json-object with the following XBZRLE information:
- - cache-size: XBZRLE cache size
- - bytes: total XBZRLE bytes transferred
+ - cache-size: XBZRLE cache size in bytes
+ - bytes: number of bytes transferred for XBZRLE compressed pages
  - pages: number of XBZRLE compressed pages
- - cache-miss: number of cache misses
- - overflow: number of XBZRLE overflows
+ - cache-miss: number of XBRZRLE page cache misses
+ - overflow: number of times XBZRLE overflows.  This means
+   that the XBZRLE encoding was bigger than just sent the
+   whole page, and then we sent the whole page instead (as as
+   normal page).
+
 Examples:

 1. Before the first migration
@@ -2567,11 +2577,11 @@ EQMP

 SQMP
 migrate-set-capabilities

+

 Enable/Disable migration capabilities

-- xbzrle: xbzrle support
+- xbzrle: XBZRLE support

 Arguments:

@@ -2590,7 +2600,7 @@ EQMP
 },
 SQMP
 query-migrate-capabilities

+--

 Query current migration capabilities

-- 
1.8.1.4




Re: [Qemu-devel] Spice / usb-redir chardev flowcontrol patches v2

2013-03-18 Thread Amit Shah
On (Thu) 14 Mar 2013 [17:36:49], Hans de Goede wrote:
 Here is v2 of the series adding watch support to the spicevmc chardev backend
 and flowcontrol support to the usb-redir device. It also includes a few
 virtio-consoled bugfixes which were found during the development of this
 series.
 
 Note that this series is based *on top of* Gerd Hoffmann's chardev.5 series
 to avoid conflicts with that series.

Looks good.

Acked-by: Amit Shah amit.s...@redhat.com

Gerd, will you pick these up via your tree?

Amit



[Qemu-devel] [PATCH 08/15] console: rename vga_hw_*, add QemuConsole param

2013-03-18 Thread Gerd Hoffmann
Add QemuConsole parameter to vga_hw_*, so the interface allows to update
non-active consoles (the actual code can't handle this yet, see next
patch).  Passing NULL is allowed and updates the active console, like
the functions do today.

While touching all vga_hw_* calls anyway rename that to the functions to
hardware-neutral graphics_hw_*

Signed-off-by: Gerd Hoffmann kra...@redhat.com
---
 hw/cirrus_vga.c  |2 +-
 hw/qxl.c |2 +-
 hw/vga.c |2 +-
 hw/vga_int.h |8 
 include/ui/console.h |   22 +++---
 ui/console.c |   49 ++---
 ui/curses.c  |4 ++--
 ui/gtk.c |2 +-
 ui/sdl.c |   18 +-
 ui/spice-display.c   |2 +-
 ui/vnc.c |   12 ++--
 11 files changed, 67 insertions(+), 56 deletions(-)

diff --git a/hw/cirrus_vga.c b/hw/cirrus_vga.c
index 7a4d634..8a0f74f 100644
--- a/hw/cirrus_vga.c
+++ b/hw/cirrus_vga.c
@@ -720,7 +720,7 @@ static void cirrus_do_copy(CirrusVGAState *s, int dst, int 
src, int w, int h)
 /* we have to flush all pending changes so that the copy
is generated at the appropriate moment in time */
 if (notify)
-   vga_hw_update();
+graphic_hw_update(s-vga.con);
 
 (*s-cirrus_rop) (s, s-vga.vram_ptr +
  (s-cirrus_blt_dstaddr  s-cirrus_addr_mask),
diff --git a/hw/qxl.c b/hw/qxl.c
index b66b414..1ceee7e 100644
--- a/hw/qxl.c
+++ b/hw/qxl.c
@@ -1074,7 +1074,7 @@ static void qxl_enter_vga_mode(PCIQXLDevice *d)
 qemu_spice_create_host_primary(d-ssd);
 d-mode = QXL_MODE_VGA;
 vga_dirty_log_start(d-vga);
-vga_hw_update();
+graphic_hw_update(d-vga.con);
 }
 
 static void qxl_exit_vga_mode(PCIQXLDevice *d)
diff --git a/hw/vga.c b/hw/vga.c
index 59bfb22..533b60e 100644
--- a/hw/vga.c
+++ b/hw/vga.c
@@ -2452,6 +2452,6 @@ static void vga_screen_dump(void *opaque, const char 
*filename, bool cswitch,
 if (cswitch) {
 vga_invalidate_display(s);
 }
-vga_hw_update();
+graphic_hw_update(s-con);
 ppm_save(filename, surface, errp);
 }
diff --git a/hw/vga_int.h b/hw/vga_int.h
index 260f7d6..1b8f670 100644
--- a/hw/vga_int.h
+++ b/hw/vga_int.h
@@ -152,10 +152,10 @@ typedef struct VGACommonState {
 uint32_t cursor_offset;
 unsigned int (*rgb_to_pixel)(unsigned int r,
  unsigned int g, unsigned b);
-vga_hw_update_ptr update;
-vga_hw_invalidate_ptr invalidate;
-vga_hw_screen_dump_ptr screen_dump;
-vga_hw_text_update_ptr text_update;
+graphic_hw_update_ptr update;
+graphic_hw_invalidate_ptr invalidate;
+graphic_hw_screen_dump_ptr screen_dump;
+graphic_hw_text_update_ptr text_update;
 bool full_update_text;
 bool full_update_gfx;
 /* hardware mouse cursor support */
diff --git a/include/ui/console.h b/include/ui/console.h
index 3725dae..9c585c0 100644
--- a/include/ui/console.h
+++ b/include/ui/console.h
@@ -278,21 +278,21 @@ static inline void console_write_ch(console_ch_t *dest, 
uint32_t ch)
 *dest = ch;
 }
 
-typedef void (*vga_hw_update_ptr)(void *);
-typedef void (*vga_hw_invalidate_ptr)(void *);
-typedef void (*vga_hw_screen_dump_ptr)(void *, const char *, bool cswitch,
+typedef void (*graphic_hw_update_ptr)(void *);
+typedef void (*graphic_hw_invalidate_ptr)(void *);
+typedef void (*graphic_hw_screen_dump_ptr)(void *, const char *, bool cswitch,
Error **errp);
-typedef void (*vga_hw_text_update_ptr)(void *, console_ch_t *);
+typedef void (*graphic_hw_text_update_ptr)(void *, console_ch_t *);
 
-QemuConsole *graphic_console_init(vga_hw_update_ptr update,
-  vga_hw_invalidate_ptr invalidate,
-  vga_hw_screen_dump_ptr screen_dump,
-  vga_hw_text_update_ptr text_update,
+QemuConsole *graphic_console_init(graphic_hw_update_ptr update,
+  graphic_hw_invalidate_ptr invalidate,
+  graphic_hw_screen_dump_ptr screen_dump,
+  graphic_hw_text_update_ptr text_update,
   void *opaque);
 
-void vga_hw_update(void);
-void vga_hw_invalidate(void);
-void vga_hw_text_update(console_ch_t *chardata);
+void graphic_hw_update(QemuConsole *con);
+void graphic_hw_invalidate(QemuConsole *con);
+void graphic_hw_text_update(QemuConsole *con, console_ch_t *chardata);
 
 int is_graphic_console(void);
 int is_fixedsize_console(void);
diff --git a/ui/console.c b/ui/console.c
index 2c8fd91..23eed6f 100644
--- a/ui/console.c
+++ b/ui/console.c
@@ -118,10 +118,10 @@ struct QemuConsole {
 DisplayState *ds;
 
 /* Graphic console state.  */
-vga_hw_update_ptr hw_update;
-vga_hw_invalidate_ptr hw_invalidate;
-vga_hw_screen_dump_ptr hw_screen_dump;
-vga_hw_text_update_ptr 

[Qemu-devel] [PATCHv3] QEMU(upstream): Disable xen's use of O_DIRECT by default as it results in crashes.

2013-03-18 Thread Alex Bligh
Due to what is almost certainly a kernel bug, writes with
O_DIRECT may continue to reference the page after the write
has been marked as completed, particularly in the case of
TCP retransmit. In other scenarios, this merely risks
data corruption on the write, but with Xen pages from domU
are only transiently mapped into dom0's memory, resulting
in kernel panics when they are subsequently accessed.

This brings PV devices in line with emulated devices. Removing
O_DIRECT is safe as barrier operations are now correctly passed
through.

See:
  http://lists.xen.org/archives/html/xen-devel/2012-12/msg01154.html
for more details.

This patch has already been applied to the xenbits.org
qemu-upstream repository.
  
http://xenbits.xen.org/gitweb/?p=qemu-upstream-unstable.git;a=commit;h=f3903bbac78a81fcbce1350cdce860764a62783a
Clearly it should go into qemu's own repository.

Acked-by: Stefano Stabellini stefano.stabell...@eu.citrix.com
Signed-off-by: Alex Bligh a...@alex.org.uk
---
 hw/xen_disk.c |2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)

diff --git a/hw/xen_disk.c b/hw/xen_disk.c
index a402ac8..14f8723 100644
--- a/hw/xen_disk.c
+++ b/hw/xen_disk.c
@@ -603,7 +603,7 @@ static int blk_init(struct XenDevice *xendev)
 }
 
 /* read-only ? */
-qflags = BDRV_O_NOCACHE | BDRV_O_CACHE_WB | BDRV_O_NATIVE_AIO;
+qflags = BDRV_O_CACHE_WB | BDRV_O_NATIVE_AIO;
 if (strcmp(blkdev-mode, w) == 0) {
 qflags |= BDRV_O_RDWR;
 } else {
-- 
1.7.4.1




Re: [Qemu-devel] [PATCH qom-cpu-next 00/10 v7] target-i386: convert CPU features into properties

2013-03-18 Thread Igor Mammedov
ping



Re: [Qemu-devel] [PATCH qom-cpu-next 00/10 v7] target-i386: convert CPU features into properties

2013-03-18 Thread Andreas Färber
Am 18.03.2013 13:31, schrieb Igor Mammedov:
 ping

Thanks. First day back at work here. :)

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] [PULL] virtio,pci,qom

2013-03-18 Thread Michael S. Tsirkin
The following changes since commit b1999e87b4d42305419329cae459e1b43f706d96:

  Fix TAGS creation (2013-03-15 11:36:49 -0500)

are available in the git repository at:

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

for you to fetch changes up to de14103c5c8e7eee9319d54a2e02258ee8415eb7:

  pcie: Mangle types to match topology (2013-03-17 14:19:23 +0200)


virtio,pci,qom

Work by Alex to support VGA assignment,
pci and virtio fixes by Stefan, Jason and myself, and a
new qmp event for hotplug support by myself.

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


Alex Williamson (12):
  pci: Add PCI VGA helpers
  pci: Teach PCI Bridges about VGA routing
  pci: Fix INTx routing notifier recursion
  pci_bridge: Use a default map_irq function
  pci_bridge: Remove duplicate IRQ swizzle function
  pci: Create and register a new PCI Express TypeInfo
  pci: Move PCI and PCIE type defines
  pci: Allow PCI bus creation interfaces to specify the type of bus
  pci: Q35, Root Ports, and Switches create PCI Express buses
  pci: Create pci_bus_is_express helper
  pci: Create and use API to determine root buses
  pcie: Mangle types to match topology

Jason Wang (1):
  virtio-net: remove layout assumptions for mq ctrl

Michael S. Tsirkin (6):
  qdev: DEVICE_DELETED event
  qom: pass original path to unparent method
  qmp: add path to device_deleted event
  virtio-pci: guest notifier mask without non-irqfd
  pci_bridge: factor out common code
  pci_bridge: drop formatting from source

Stefan Hajnoczi (2):
  pci: refuse empty ROM files
  exec: assert that RAMBlock size is non-zero

 QMP/qmp-events.txt|  18 +++
 exec.c|   2 +
 hw/alpha_typhoon.c|   2 +-
 hw/apb_pci.c  |   4 +-
 hw/bonito.c   |   2 +-
 hw/dec_pci.c  |   7 ++-
 hw/grackle_pci.c  |   2 +-
 hw/gt64xxx.c  |   2 +-
 hw/i82801b11.c|   2 +-
 hw/ioh3420.c  |   2 +-
 hw/pci/pci.c  | 121 ++
 hw/pci/pci.h  |  34 +++--
 hw/pci/pci_bridge.c   |  51 ---
 hw/pci/pci_bridge.h   |  17 +++
 hw/pci/pci_bus.h  |  10 ++--
 hw/pci/pcie.c |  13 +
 hw/pci/pcie_port.c|  18 ---
 hw/pci_bridge_dev.c   |  11 +
 hw/piix_pci.c |   2 +-
 hw/ppc4xx_pci.c   |   2 +-
 hw/ppce500_pci.c  |   2 +-
 hw/prep_pci.c |   2 +-
 hw/q35.c  |   3 +-
 hw/qdev.c |  16 +-
 hw/sh_pci.c   |   2 +-
 hw/spapr_pci.c|   2 +-
 hw/unin_pci.c |   4 +-
 hw/versatile_pci.c|   2 +-
 hw/virtio-net.c   |  23 -
 hw/virtio-pci.c   |  79 --
 hw/xio3130_downstream.c   |   2 +-
 hw/xio3130_upstream.c |   2 +-
 include/monitor/monitor.h |   1 +
 include/qom/object.h  |   3 +-
 monitor.c |   1 +
 qapi-schema.json  |   4 +-
 qom/object.c  |   4 +-
 37 files changed, 344 insertions(+), 130 deletions(-)



Re: [Qemu-devel] [PATCH] qcow2: Fix segfault in qcow2_invalidate_cache

2013-03-18 Thread Paolo Bonzini
Il 18/03/2013 13:10, Kevin Wolf ha scritto:
 Need to pass an options QDict to qcow2_open() now. This fixes a segfault
 on the migration target with qcow2.
 
 Signed-off-by: Kevin Wolf kw...@redhat.com
 ---
  block/qcow2.c | 12 ++--
  block/qcow2.h |  3 +++
  2 files changed, 13 insertions(+), 2 deletions(-)
 
 diff --git a/block/qcow2.c b/block/qcow2.c
 index b90dd9e..7fcdc62 100644
 --- a/block/qcow2.c
 +++ b/block/qcow2.c
 @@ -29,6 +29,7 @@
  #include block/qcow2.h
  #include qemu/error-report.h
  #include qapi/qmp/qerror.h
 +#include qapi/qmp/qbool.h
  #include trace.h
  
  /*
 @@ -520,7 +521,7 @@ static int qcow2_open(BlockDriverState *bs, QDict 
 *options, int flags)
  goto fail;
  }
  
 -s-use_lazy_refcounts = qemu_opt_get_bool(opts, lazy_refcounts,
 +s-use_lazy_refcounts = qemu_opt_get_bool(opts, QCOW2_OPT_LAZY_REFCOUNTS,
  (s-compatible_features  QCOW2_COMPAT_LAZY_REFCOUNTS));

Why not add

   s-use_lazy_refcounts ||

to the default, and just use an empty QDict in qcow2_invalidate_cache?

Paolo

  
  qemu_opts_del(opts);
 @@ -934,6 +935,7 @@ static void qcow2_invalidate_cache(BlockDriverState *bs)
  AES_KEY aes_encrypt_key;
  AES_KEY aes_decrypt_key;
  uint32_t crypt_method = 0;
 +QDict *options;
  
  /*
   * Backing files are read-only which makes all of their metadata 
 immutable,
 @@ -948,8 +950,14 @@ static void qcow2_invalidate_cache(BlockDriverState *bs)
  
  qcow2_close(bs);
  
 +options = qdict_new();
 +qdict_put(options, QCOW2_OPT_LAZY_REFCOUNTS,
 +  qbool_from_int(s-use_lazy_refcounts));
 +
  memset(s, 0, sizeof(BDRVQcowState));
 -qcow2_open(bs, NULL, flags);
 +qcow2_open(bs, options, flags);
 +
 +QDECREF(options);
  
  if (crypt_method) {
  s-crypt_method = crypt_method;
 diff --git a/block/qcow2.h b/block/qcow2.h
 index 103abdb..e4b5e11 100644
 --- a/block/qcow2.h
 +++ b/block/qcow2.h
 @@ -58,6 +58,9 @@
  
  #define DEFAULT_CLUSTER_SIZE 65536
  
 +
 +#define QCOW2_OPT_LAZY_REFCOUNTS lazy_refcounts
 +
  typedef struct QCowHeader {
  uint32_t magic;
  uint32_t version;
 




Re: [Qemu-devel] [PATCH v6 0/2] qdev: Detect duplicate device properties

2013-03-18 Thread Paolo Bonzini
Il 16/03/2013 17:39, Peter Maydell ha scritto:
 Detect and abort on duplicate properties in a qdev Property array.
 
 This patchset actually dates back to October last year (and got
 reviewed then, hence Anthony's r-b tags) but it didn't get applied
 (maybe we were in codefreeze) and I forgot about it. Anyway, I've
 rebased it so here we are again.
 
 Peter Maydell (2):
   qom: Detect attempts to add a property that already exists
   hw/qdev: Abort rather than ignoring errors adding device properties
 
  hw/qdev.c|   10 +++---
  qom/object.c |   13 -
  2 files changed, 19 insertions(+), 4 deletions(-)
 

Acked-by: Paolo Bonzini pbonz...@redhat.com

Paolo



[Qemu-devel] [PATCH 14/15] console: add GraphicHwOps

2013-03-18 Thread Gerd Hoffmann
Pass a single GraphicHwOps struct pointer to graphic_console_init,
instead of a bunch of function pointers.

Signed-off-by: Gerd Hoffmann kra...@redhat.com
---
 hw/arm/musicpal.c|8 ++--
 hw/blizzard.c|9 ++---
 hw/cirrus_vga.c  |8 ++--
 hw/exynos4210_fimd.c |8 ++--
 hw/g364fb.c  |9 ++---
 hw/jazz_led.c|   10 +++---
 hw/milkymist-vgafb.c |9 ++---
 hw/omap_lcdc.c   |9 ++---
 hw/pl110.c   |9 ++---
 hw/pxa2xx_lcd.c  |9 ++---
 hw/qxl.c |   16 ++--
 hw/sm501.c   |7 +--
 hw/ssd0303.c |9 ++---
 hw/ssd0323.c |9 ++---
 hw/tc6393xb.c|9 +
 hw/tcx.c |   18 --
 hw/unicore32/puv3.c  |4 +++-
 hw/vga-isa-mm.c  |4 +---
 hw/vga-isa.c |3 +--
 hw/vga-pci.c |3 +--
 hw/vga.c |   10 +++---
 hw/vga_int.h |4 +---
 hw/vmware_vga.c  |   20 
 hw/xenfb.c   |   10 ++
 include/ui/console.h |   12 ++--
 ui/console.c |   32 +++-
 26 files changed, 154 insertions(+), 104 deletions(-)

diff --git a/hw/arm/musicpal.c b/hw/arm/musicpal.c
index 4e9a23c..7d3e239 100644
--- a/hw/arm/musicpal.c
+++ b/hw/arm/musicpal.c
@@ -601,6 +601,11 @@ static const MemoryRegionOps musicpal_lcd_ops = {
 .endianness = DEVICE_NATIVE_ENDIAN,
 };
 
+static const GraphicHwOps musicpal_gfx_ops = {
+.invalidate  = lcd_invalidate,
+.gfx_update  = lcd_refresh,
+};
+
 static int musicpal_lcd_init(SysBusDevice *dev)
 {
 musicpal_lcd_state *s = FROM_SYSBUS(musicpal_lcd_state, dev);
@@ -611,8 +616,7 @@ static int musicpal_lcd_init(SysBusDevice *dev)
   musicpal-lcd, MP_LCD_SIZE);
 sysbus_init_mmio(dev, s-iomem);
 
-s-con = graphic_console_init(lcd_refresh, lcd_invalidate,
-  NULL, s);
+s-con = graphic_console_init(musicpal_gfx_ops, s);
 qemu_console_resize(s-con, 128*3, 64*3);
 
 qdev_init_gpio_in(dev-qdev, musicpal_lcd_gpio_brigthness_in, 3);
diff --git a/hw/blizzard.c b/hw/blizzard.c
index 891bff8..794b276 100644
--- a/hw/blizzard.c
+++ b/hw/blizzard.c
@@ -944,6 +944,11 @@ static void blizzard_update_display(void *opaque)
 #define DEPTH 32
 #include hw/blizzard_template.h
 
+static const GraphicHwOps blizzard_ops = {
+.invalidate  = blizzard_invalidate_display,
+.gfx_update  = blizzard_update_display,
+};
+
 void *s1d13745_init(qemu_irq gpio_int)
 {
 BlizzardState *s = (BlizzardState *) g_malloc0(sizeof(*s));
@@ -951,9 +956,7 @@ void *s1d13745_init(qemu_irq gpio_int)
 
 s-fb = g_malloc(0x18);
 
-s-con = graphic_console_init(blizzard_update_display,
-  blizzard_invalidate_display,
-  NULL, s);
+s-con = graphic_console_init(blizzard_ops, s);
 surface = qemu_console_surface(s-con);
 
 switch (surface_bits_per_pixel(surface)) {
diff --git a/hw/cirrus_vga.c b/hw/cirrus_vga.c
index 03b3245..ed7962f 100644
--- a/hw/cirrus_vga.c
+++ b/hw/cirrus_vga.c
@@ -2910,9 +2910,7 @@ static int vga_initfn(ISADevice *dev)
 vga_common_init(s);
 cirrus_init_common(d-cirrus_vga, CIRRUS_ID_CLGD5430, 0,
isa_address_space(dev), isa_address_space_io(dev));
-s-con = graphic_console_init(s-update, s-invalidate,
-  s-text_update,
-  s);
+s-con = graphic_console_init(s-hw_ops, s);
 rom_add_vga(VGABIOS_CIRRUS_FILENAME);
 /* XXX ISA-LFB support */
 /* FIXME not qdev yet */
@@ -2959,9 +2957,7 @@ static int pci_cirrus_vga_initfn(PCIDevice *dev)
  vga_common_init(s-vga);
  cirrus_init_common(s, device_id, 1, pci_address_space(dev),
 pci_address_space_io(dev));
- s-vga.con = graphic_console_init(s-vga.update, s-vga.invalidate,
-   s-vga.text_update,
-   s-vga);
+ s-vga.con = graphic_console_init(s-vga.hw_ops, s-vga);
 
  /* setup PCI */
 
diff --git a/hw/exynos4210_fimd.c b/hw/exynos4210_fimd.c
index 0ae5d26..af3d012 100644
--- a/hw/exynos4210_fimd.c
+++ b/hw/exynos4210_fimd.c
@@ -1887,6 +1887,11 @@ static const VMStateDescription exynos4210_fimd_vmstate 
= {
 }
 };
 
+static const GraphicHwOps exynos4210_fimd_ops = {
+.invalidate  = exynos4210_fimd_invalidate,
+.gfx_update  = exynos4210_fimd_update,
+};
+
 static int exynos4210_fimd_init(SysBusDevice *dev)
 {
 Exynos4210fimdState *s = FROM_SYSBUS(Exynos4210fimdState, dev);
@@ -1900,8 +1905,7 @@ static int exynos4210_fimd_init(SysBusDevice *dev)
 memory_region_init_io(s-iomem, exynos4210_fimd_mmio_ops, s,
 exynos4210.fimd, FIMD_REGS_SIZE);
 sysbus_init_mmio(dev, s-iomem);
-s-console = 

[Qemu-devel] [PATCH] s390-virtio: Add virtio-rng properties.

2013-03-18 Thread Cornelia Huck
Add the same 'max-bytes' and 'period' properties that are supported
for virtio-pci and virtio-ccw to make things consistent.

Signed-off-by: Cornelia Huck cornelia.h...@de.ibm.com
---
 hw/s390x/s390-virtio-bus.c | 9 +
 1 file changed, 9 insertions(+)

diff --git a/hw/s390x/s390-virtio-bus.c b/hw/s390x/s390-virtio-bus.c
index d9b7f83..ca2b590 100644
--- a/hw/s390x/s390-virtio-bus.c
+++ b/hw/s390x/s390-virtio-bus.c
@@ -483,11 +483,20 @@ static void s390_virtio_rng_initfn(Object *obj)
  (Object **)dev-rng.rng, NULL);
 }
 
+static Property s390_virtio_rng_properties[] = {
+DEFINE_VIRTIO_COMMON_FEATURES(VirtIOS390Device, host_features),
+DEFINE_PROP_UINT64(max-bytes, VirtIOS390Device, rng.max_bytes, 
INT64_MAX),
+DEFINE_PROP_UINT32(period, VirtIOS390Device, rng.period_ms, 1  16),
+DEFINE_PROP_END_OF_LIST(),
+};
+
 static void s390_virtio_rng_class_init(ObjectClass *klass, void *data)
 {
+DeviceClass *dc = DEVICE_CLASS(klass);
 VirtIOS390DeviceClass *k = VIRTIO_S390_DEVICE_CLASS(klass);
 
 k-init = s390_virtio_rng_init;
+dc-props = s390_virtio_rng_properties;
 }
 
 static const TypeInfo s390_virtio_rng = {
-- 
1.7.12.4




[Qemu-devel] [PATCH] s390-virtio property aligning.

2013-03-18 Thread Cornelia Huck
Hi Alex,

one more instance where a virtio driver on s390 missed properties
present on other transports. Please consider applying.

Cornelia Huck (1):
  s390-virtio: Add virtio-rng properties.

 hw/s390x/s390-virtio-bus.c | 9 +
 1 file changed, 9 insertions(+)

-- 
1.7.12.4




Re: [Qemu-devel] qemu segfault parsing iscsi options

2013-03-18 Thread Markus Armbruster
Peter Lieven p...@dlhnet.de writes:

 Hi,

 with recent qemu from git qemu segfaults with the following commandline:

 x86_64-softmmu/qemu-system-x86_64 -iscsi test

 qemu-system-x86_64: -iscsi test: There is no option group 'iscsi'
 Speicherzugriffsfehler (Speicherabzug geschrieben)

 It seems that there is something missing regarding the iscsi options
 in qemu-option.hx.

 This was working with qemu-kvm-1.2.0.

Works for me with current master 225dc991.



Re: [Qemu-devel] [PATCH v3] migration: Improve QMP documentation

2013-03-18 Thread Markus Armbruster
Juan Quintela quint...@redhat.com writes:

 Signed-off-by: Juan Quintela quint...@redhat.com
 Reviewed-by: Eric Blake ebl...@redhat.com

Reviewed-by: Markus Armbruster arm...@redhat.com



Re: [Qemu-devel] [PATCH v9 05/10] virtio-blk-pci: switch to new API.

2013-03-18 Thread Anthony Liguori
fred.kon...@greensocs.com writes:

 From: KONRAD Frederic fred.kon...@greensocs.com

 Here the virtio-blk-pci is modified for the new API. The device
 virtio-blk-pci extends virtio-pci. It creates and connects a virtio-blk
 during the init. The properties are not changed.

 Signed-off-by: KONRAD Frederic fred.kon...@greensocs.com
 Reviewed-by: Peter Maydell peter.mayd...@linaro.org

According to bisect, this breaks hot unplug:

Using RANDOM seed 35921
Testing block
Formatting '.tmp-15607/disk.img', fmt=qcow2 size=10737418240 encryption=off 
cluster_size=65536 lazy_refcounts=off 
/home/aliguori/build/qemu/x86_64-softmmu/qemu-system-x86_64 -kernel 
/usr/local/share/qemu-jeos/kernel-x86_64-pc -initrd 
.tmp-15607/initramfs-15607.img.gz -device isa-debug-exit -append console=ttyS0 
seed=35921 -nographic -enable-kvm -device virtio-balloon-pci,id=balloon0 
-pidfile .tmp-15607/pidfile-15607.pid -qmp 
unix:.tmp-15607/qmpsock-15607.sock,server,nowait
[0.00] Initializing cgroup subsys cpuset
[0.00] Initializing cgroup subsys cpu
[0.00] Linux version 3.4.0 (root@ccnode4) (gcc version 4.6.4 20120830 
(prerelease) (GCC) ) #2 SMP Mon Dec 3 19:40:41 CST 2012
[0.00] Command line: console=ttyS0 seed=35921
[0.00] BIOS-provided physical RAM map:
[0.00]  BIOS-e820:  - 0009fc00 (usable)
[0.00]  BIOS-e820: 0009fc00 - 000a (reserved)
[0.00]  BIOS-e820: 000f - 0010 (reserved)
[0.00]  BIOS-e820: 0010 - 07ffe000 (usable)
[0.00]  BIOS-e820: 07ffe000 - 0800 (reserved)
[0.00]  BIOS-e820: feffc000 - ff00 (reserved)
[0.00]  BIOS-e820: fffc - 0001 (reserved)
[0.00] NX (Execute Disable) protection: active
[0.00] DMI 2.4 present.
[0.00] No AGP bridge found
[0.00] last_pfn = 0x7ffe max_arch_pfn = 0x4
[0.00] PAT not supported by CPU.
[0.00] found SMP MP-table at [880fdaf0] fdaf0
[0.00] init_memory_mapping: -07ffe000
[0.00] RAMDISK: 07f58000 - 07ff
[0.00] ACPI: RSDP 000fd990 00014 (v00 BOCHS )
[0.00] ACPI: RSDT 07ffe4b0 00034 (v01 BOCHS  BXPCRSDT 0001 
BXPC 0001)
[0.00] ACPI: FACP 0780 00074 (v01 BOCHS  BXPCFACP 0001 
BXPC 0001)
[0.00] ACPI: DSDT 07ffe4f0 011A9 (v01   BXPC   BXDSDT 0001 
INTL 20100528)
[0.00] ACPI: FACS 0740 00040
[0.00] ACPI: SSDT 07fff800 00735 (v01 BOCHS  BXPCSSDT 0001 
BXPC 0001)
[0.00] ACPI: APIC 07fff6e0 00078 (v01 BOCHS  BXPCAPIC 0001 
BXPC 0001)
[0.00] ACPI: HPET 07fff6a0 00038 (v01 BOCHS  BXPCHPET 0001 
BXPC 0001)
[0.00] No NUMA configuration found
[0.00] Faking a node at -07ffe000
[0.00] Initmem setup node 0 -07ffe000
[0.00]   NODE_DATA [07ff7000 - 07ffafff]
[0.00] Zone PFN ranges:
[0.00]   DMA  0x0010 - 0x1000
[0.00]   DMA320x1000 - 0x0010
[0.00]   Normal   empty
[0.00] Movable zone start PFN for each node
[0.00] Early memory PFN ranges
[0.00] 0: 0x0010 - 0x009f
[0.00] 0: 0x0100 - 0x7ffe
[0.00] ACPI: PM-Timer IO Port: 0xb008
[0.00] ACPI: LAPIC (acpi_id[0x00] lapic_id[0x00] enabled)
[0.00] ACPI: LAPIC_NMI (acpi_id[0xff] dfl dfl lint[0x1])
[0.00] ACPI: IOAPIC (id[0x00] address[0xfec0] gsi_base[0])
[0.00] IOAPIC[0]: apic_id 0, version 17, address 0xfec0, GSI 0-23
[0.00] ACPI: INT_SRC_OVR (bus 0 bus_irq 0 global_irq 2 dfl dfl)
[0.00] ACPI: INT_SRC_OVR (bus 0 bus_irq 5 global_irq 5 high level)
[0.00] ACPI: INT_SRC_OVR (bus 0 bus_irq 9 global_irq 9 high level)
[0.00] ACPI: INT_SRC_OVR (bus 0 bus_irq 10 global_irq 10 high level)
[0.00] ACPI: INT_SRC_OVR (bus 0 bus_irq 11 global_irq 11 high level)
[0.00] Using ACPI (MADT) for SMP configuration information
[0.00] ACPI: HPET id: 0x8086a201 base: 0xfed0
[0.00] SMP: Allowing 1 CPUs, 0 hotplug CPUs
[0.00] PM: Registered nosave memory: 0009f000 - 000a
[0.00] PM: Registered nosave memory: 000a - 000f
[0.00] PM: Registered nosave memory: 000f - 0010
[0.00] Allocating PCI resources starting at 800 (gap: 
800:f6ffc000)
[0.00] setup_percpu: NR_CPUS:64 nr_cpumask_bits:64 nr_cpu_ids:1 
nr_node_ids:1
[0.00] PERCPU: Embedded 26 pages/cpu @880007c0 s77056 r8192 
d21248 u2097152
[0.00] Built 1 zonelists in Node order, mobility grouping on.  Total 
pages: 32136
[0.00] Policy zone: DMA32
[0.00] 

Re: [Qemu-devel] [PATCHv3] QEMU(upstream): Disable xen's use of O_DIRECT by default as it results in crashes.

2013-03-18 Thread Stefan Hajnoczi
On Mon, Mar 18, 2013 at 12:18:43PM +, Alex Bligh wrote:
 Due to what is almost certainly a kernel bug, writes with
 O_DIRECT may continue to reference the page after the write
 has been marked as completed, particularly in the case of
 TCP retransmit. In other scenarios, this merely risks
 data corruption on the write, but with Xen pages from domU
 are only transiently mapped into dom0's memory, resulting
 in kernel panics when they are subsequently accessed.
 
 This brings PV devices in line with emulated devices. Removing
 O_DIRECT is safe as barrier operations are now correctly passed
 through.
 
 See:
   http://lists.xen.org/archives/html/xen-devel/2012-12/msg01154.html
 for more details.

From the mailing list discussion it appears that this patch is a
workaround - using the dom0 page cache to avoid the failed host kernel
paging request, which is caused by the true bug.

Has any progress been made at understanding the true problem?

 This patch has already been applied to the xenbits.org
 qemu-upstream repository.
   
 http://xenbits.xen.org/gitweb/?p=qemu-upstream-unstable.git;a=commit;h=f3903bbac78a81fcbce1350cdce860764a62783a
 Clearly it should go into qemu's own repository.
 
 Acked-by: Stefano Stabellini stefano.stabell...@eu.citrix.com
 Signed-off-by: Alex Bligh a...@alex.org.uk
 ---
  hw/xen_disk.c |2 +-
  1 files changed, 1 insertions(+), 1 deletions(-)
 
 diff --git a/hw/xen_disk.c b/hw/xen_disk.c
 index a402ac8..14f8723 100644
 --- a/hw/xen_disk.c
 +++ b/hw/xen_disk.c
 @@ -603,7 +603,7 @@ static int blk_init(struct XenDevice *xendev)
  }
  
  /* read-only ? */
 -qflags = BDRV_O_NOCACHE | BDRV_O_CACHE_WB | BDRV_O_NATIVE_AIO;
 +qflags = BDRV_O_CACHE_WB | BDRV_O_NATIVE_AIO;
  if (strcmp(blkdev-mode, w) == 0) {
  qflags |= BDRV_O_RDWR;
  } else {
 -- 
 1.7.4.1
 
 



Re: [Qemu-devel] [PATCH V27 1/7] Support for TPM command line options

2013-03-18 Thread Markus Armbruster
Stefan Berger stef...@linux.vnet.ibm.com writes:

 On 03/15/2013 03:36 AM, Markus Armbruster wrote:
 I missed this one, because it wasn't cc'ed to QMP maintainers, the
 subject mentions only command line, not QMP, and even the body talks
 only about the human monitor command, not QMP.  Noticed it only when
 git-pull touched qapi-schema.json.  Please try harder to help Luiz and
 me keep track of QMP changes.

 I apologize for that.


 I gave the QMP interface and its documentation a look-over now.  It's
 just a look-over, because passthrough requires a box with TPM enabled,
 which I don't have handy, so I can't test anything.

 A few comments inline.

 Stefan Berger stef...@linux.vnet.ibm.com writes:
 +
 +@item -tpmdev @var{backend} ,id=@var{id} [,@var{options}]
 +@findex -tpmdev
 +Backend type must be:
 +
 +The specific backend type will determine the applicable options.
 +The @code{-tpmdev} option requires a @code{-device} option.
 You mean -tpmdev creates just a backend, so for a usable device you also
 need to create a frontend with -device?

 Yes, just like any other device.

Okay.  Corey already posted a patch to clarify the documentation here.
Appreciated!

[...]
 +{
 +if (qemu_opts_foreach(qemu_find_opts(tpmdev),
 +  tpm_init_tpmdev, NULL, 1) != 0) {
 +return -1;
 +}
 +
 +atexit(tpm_cleanup);

 Routine atexit() question: what happens when the program terminates
 abnormally?  atext() callbacks don't run then.  Impact of not doing
 cleanup on the system?

 In case the TPM is currently not operating on a command there will be
 no impact. In case the TPM is operating on a command, it will hold the
 thread inside /dev/tpm0 until the command has finished. The solution
 here is to write a byte into sysfs file to terminate the TPM from
 further executing the command and return; this code exists and is
 being invoked in all other cases than abnormal termination obviously.

Unlike other kernel resources such as file descriptors, this one isn't
tied to a process and cleaned up automatically on process termination.
Correct?

Therefore, we try to clean it up manually.  Actual cleanup code is
tpm_passthrough_cancel_cmd().  Correct?

The only existing cleanup function tpm_passthrough_destroy() does a
whole lot more.  Just to make sure I understand what's going on:
everything but tpm_passthrough_cancel_cmd() is effectively a no-op
there, correct?

 What other choices do we have? Do we need a signal handler that runs
 on SIGSEGV and provide a registration function for those functions
 that need to run on abnormal termination?

Not worth it.



[Qemu-devel] [PATCH 00/26] ccid and libcacard fixes for windows/mingw

2013-03-18 Thread Alon Levy
This series:
1. fixes windows guests to show the ccid device
2. changes libcacard to use glib
3. makes libcacard build under mingw
4. does some cleanups

It contains a few patches already posted to the list (the two Jim Meyering 
patches) which were already acked.

I'll make a pull request once this had some time to be reviewed.

Tested with a fedora and windows 7 guest.

The main non cleanup patches are:
  hw/usb/dev-smartcard-reader: support windows guest
  libcacard: correct T0 historical bytes size


Alon Levy (15):
  hw/ccid-card-passthru.c: add atr check
  ccid-card-passthru, dev-smartcard-reader: add debug environment
variables
  hw/usb/dev-smartcard-reader.c: white space fixes
  hw/usb/dev-smartcard-reader.c: nicer debug messages
  hw/usb/dev-smartcard-reader.c: remove aborts (never triggered, but
just in case)
  hw/usb/dev-smartcard-reader.c: define structs for CCID_Parameter
internals
  hw/usb/dev-smartcard-reader.c: copy atr's protocol to ccid's
parameters (adds todo's)
  hw/usb/dev-smartcard-reader.c: dwFeadvertise support for T=0 only
  hw/usb/dev-smartcard-reader: support windows guest
  dev-smartcard-reader: reuse usb.h definitions
  libcacard/vreader: add debugging messages for apdu
  libcacard: change default ATR
  libcacard: move atr setting from macro to function
  dev-smartcard-reader: empty implementation for Mechanical (fail
correctly)
  libcacard/cac.c: questionable change to single return of big switch
functions

Jim Meyering (2):
  ccid: make backend_enum_table static const and adjust users
  ccid: declare DEFAULT_ATR table to be static const

Marc-André Lureau (9):
  libcacard: correct T0 historical bytes size
  ccid-card-emul: do not crash if backend is not provided
  libcacard: use system config directory for nss db on win32
  util: move socket_init() to osdep.c
  build-sys: must link with -fstack-protector
  libcacard: fix mingw64 cross-compilation
  libcacard: split vscclient main() from socket reading
  libcacard: vscclient to use QemuThread for portability
  libcacard: teach vscclient to use GMainLoop for portability

 Makefile  |   8 +-
 Makefile.objs |   1 +
 configure |   8 +-
 hw/ccid-card-emulated.c   |   9 +-
 hw/ccid-card-passthru.c   |  77 ++-
 hw/usb/dev-smartcard-reader.c | 259 -
 libcacard/cac.c   |  80 ---
 libcacard/cac.h   |   8 +
 libcacard/vcard_emul_nss.c|  29 ++-
 libcacard/vcardt.c|  40 
 libcacard/vcardt.h|   7 +-
 libcacard/vreader.c   |  89 
 libcacard/vscclient.c | 506 +-
 rules.mak |   4 +-
 util/osdep.c  |  23 ++
 util/qemu-sockets.c   |  24 --
 16 files changed, 846 insertions(+), 326 deletions(-)
 create mode 100644 libcacard/vcardt.c

-- 
1.8.1.4




[Qemu-devel] [PATCH 02/26] ccid-card-emul: do not crash if backend is not provided

2013-03-18 Thread Alon Levy
From: Marc-André Lureau marcandre.lur...@gmail.com

Program received signal SIGSEGV, Segmentation fault.
__strcmp_sse42 () at ../sysdeps/x86_64/multiarch/strcmp-sse42.S:164
164   movdqu(%rsi), %xmm2
(gdb) bt
at /home/elmarco/320g/src/qemu/hw/ccid-card-emulated.c:477
at /home/elmarco/320g/src/qemu/hw/ccid-card-emulated.c:503
---
 hw/ccid-card-emulated.c | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/hw/ccid-card-emulated.c b/hw/ccid-card-emulated.c
index c8f8ba3..210433e 100644
--- a/hw/ccid-card-emulated.c
+++ b/hw/ccid-card-emulated.c
@@ -473,6 +473,9 @@ static uint32_t parse_enumeration(char *str,
 {
 uint32_t ret = not_found_value;
 
+if (str == NULL)
+return 0;
+
 while (table-name != NULL) {
 if (strcmp(table-name, str) == 0) {
 ret = table-value;
-- 
1.8.1.4




[Qemu-devel] [PATCH 05/26] libcacard: use system config directory for nss db on win32

2013-03-18 Thread Alon Levy
From: Marc-André Lureau marcandre.lur...@gmail.com

It's a bit nicer to look for default database under
CSIDL_COMMON_APPDATA\pki\nss rather that /etc/pki/nss.

Signed-off-by: Marc-André Lureau marcandre.lur...@redhat.com
---
 libcacard/vcard_emul_nss.c | 18 +-
 1 file changed, 17 insertions(+), 1 deletion(-)

diff --git a/libcacard/vcard_emul_nss.c b/libcacard/vcard_emul_nss.c
index df79476..21d4689 100644
--- a/libcacard/vcard_emul_nss.c
+++ b/libcacard/vcard_emul_nss.c
@@ -893,7 +893,23 @@ vcard_emul_init(const VCardEmulOptions *options)
 if (options-nss_db) {
 rv = NSS_Init(options-nss_db);
 } else {
-rv = NSS_Init(sql:/etc/pki/nssdb);
+gchar *path, *db;
+#ifndef _WIN32
+path = g_strdup(/etc/pki/nssdb);
+#else
+if (g_get_system_config_dirs() == NULL ||
+g_get_system_config_dirs()[0] == NULL) {
+return VCARD_EMUL_FAIL;
+}
+
+path = g_build_filename(
+g_get_system_config_dirs()[0], pki, nssdb, NULL);
+#endif
+db = g_strdup_printf(sql:%s, path);
+
+rv = NSS_Init(db);
+g_free(db);
+g_free(path);
 }
 if (rv != SECSuccess) {
 return VCARD_EMUL_FAIL;
-- 
1.8.1.4




[Qemu-devel] [PATCH 03/26] ccid: make backend_enum_table static const and adjust users

2013-03-18 Thread Alon Levy
From: Jim Meyering meyer...@redhat.com

Signed-off-by: Jim Meyering meyer...@redhat.com
---
 hw/ccid-card-emulated.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/hw/ccid-card-emulated.c b/hw/ccid-card-emulated.c
index 210433e..cb9ef10 100644
--- a/hw/ccid-card-emulated.c
+++ b/hw/ccid-card-emulated.c
@@ -462,14 +462,14 @@ typedef struct EnumTable {
 uint32_t value;
 } EnumTable;
 
-EnumTable backend_enum_table[] = {
+static const EnumTable backend_enum_table[] = {
 {BACKEND_NSS_EMULATED_NAME, BACKEND_NSS_EMULATED},
 {BACKEND_CERTIFICATES_NAME, BACKEND_CERTIFICATES},
 {NULL, 0},
 };
 
 static uint32_t parse_enumeration(char *str,
-EnumTable *table, uint32_t not_found_value)
+const EnumTable *table, uint32_t not_found_value)
 {
 uint32_t ret = not_found_value;
 
@@ -490,7 +490,7 @@ static int emulated_initfn(CCIDCardState *base)
 {
 EmulatedState *card = DO_UPCAST(EmulatedState, base, base);
 VCardEmulError ret;
-EnumTable *ptable;
+const EnumTable *ptable;
 
 QSIMPLEQ_INIT(card-event_list);
 QSIMPLEQ_INIT(card-guest_apdu_list);
-- 
1.8.1.4




[Qemu-devel] [PATCH 01/26] libcacard: correct T0 historical bytes size

2013-03-18 Thread Alon Levy
From: Marc-André Lureau marcandre.lur...@gmail.com

The VCARD_ATR_PREFIX macro adds a prefix of 6 characters only.

pcsc_scan was complaining before the patch:

+ Historical bytes: 56 43 41 52 44 5F 4E 53 53
 ERROR! ATR is truncated: 2 byte(s) is/are missing
---
 libcacard/vcardt.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/libcacard/vcardt.h b/libcacard/vcardt.h
index d3e9522..538bdde 100644
--- a/libcacard/vcardt.h
+++ b/libcacard/vcardt.h
@@ -26,7 +26,7 @@ typedef struct VCardEmulStruct VCardEmul;
 #define MAX_CHANNEL 4
 
 /* create an ATR with appropriate historical bytes */
-#define VCARD_ATR_PREFIX(size) 0x3b, 0x68+(size), 0x00, 0xff, \
+#define VCARD_ATR_PREFIX(size) 0x3b, 0x66+(size), 0x00, 0xff, \
'V', 'C', 'A', 'R', 'D', '_'
 
 
-- 
1.8.1.4




[Qemu-devel] [PATCH 11/26] libcacard: teach vscclient to use GMainLoop for portability

2013-03-18 Thread Alon Levy
From: Marc-André Lureau marcandre.lur...@gmail.com

This version handles non-blocking sending and receiving from the
socket.

Signed-off-by: Marc-André Lureau marcandre.lur...@redhat.com
---
 libcacard/vscclient.c | 391 +++---
 1 file changed, 246 insertions(+), 145 deletions(-)

diff --git a/libcacard/vscclient.c b/libcacard/vscclient.c
index 5f47634..ac23647 100644
--- a/libcacard/vscclient.c
+++ b/libcacard/vscclient.c
@@ -10,7 +10,10 @@
  * See the COPYING.LIB file in the top-level directory.
  */
 
+#ifndef _WIN32
 #include netdb.h
+#endif
+#include glib.h
 
 #include qemu-common.h
 #include qemu/thread.h
@@ -22,9 +25,7 @@
 #include vcard_emul.h
 #include vevent.h
 
-int verbose;
-
-int sock;
+static int verbose;
 
 static void
 print_byte_array(
@@ -51,7 +52,47 @@ print_usage(void) {
 vcard_emul_usage();
 }
 
-static QemuMutex write_lock;
+static GIOChannel *channel_socket;
+static GByteArray *socket_to_send;
+static QemuMutex socket_to_send_lock;
+static guint socket_tag;
+
+static void
+update_socket_watch(gboolean out);
+
+static gboolean
+do_socket_send(GIOChannel *source,
+   GIOCondition condition,
+   gpointer data)
+{
+gsize bw;
+GError *err = NULL;
+
+g_return_val_if_fail(socket_to_send-len != 0, FALSE);
+g_return_val_if_fail(condition  G_IO_OUT, FALSE);
+
+g_io_channel_write_chars(channel_socket,
+(gchar *)socket_to_send-data, socket_to_send-len, bw, err);
+if (err != NULL) {
+g_error(Error while sending socket %s, err-message);
+return FALSE;
+}
+g_byte_array_remove_range(socket_to_send, 0, bw);
+
+if (socket_to_send-len == 0) {
+update_socket_watch(FALSE);
+return FALSE;
+}
+return TRUE;
+}
+
+static gboolean
+socket_prepare_sending(gpointer user_data)
+{
+update_socket_watch(TRUE);
+
+return FALSE;
+}
 
 static int
 send_msg(
@@ -60,10 +101,9 @@ send_msg(
 const void *msg,
 unsigned int length
 ) {
-int rv;
 VSCMsgHeader mhHeader;
 
-qemu_mutex_lock(write_lock);
+qemu_mutex_lock(socket_to_send_lock);
 
 if (verbose  10) {
 printf(sending type=%d id=%u, len =%u (0x%x)\n,
@@ -73,23 +113,11 @@ send_msg(
 mhHeader.type = htonl(type);
 mhHeader.reader_id = 0;
 mhHeader.length = htonl(length);
-rv = write(sock, mhHeader, sizeof(mhHeader));
-if (rv  0) {
-/* Error */
-fprintf(stderr, write header error\n);
-close(sock);
-qemu_mutex_unlock(write_lock);
-return 16;
-}
-rv = write(sock, msg, length);
-if (rv  0) {
-/* Error */
-fprintf(stderr, write error\n);
-close(sock);
-qemu_mutex_unlock(write_lock);
-return 16;
-}
-qemu_mutex_unlock(write_lock);
+g_byte_array_append(socket_to_send, (guint8 *)mhHeader, sizeof(mhHeader));
+g_byte_array_append(socket_to_send, (guint8 *)msg, length);
+g_idle_add(socket_prepare_sending, NULL);
+
+qemu_mutex_unlock(socket_to_send_lock);
 
 return 0;
 }
@@ -245,139 +273,203 @@ on_host_init(VSCMsgHeader *mhHeader, VSCMsgInit 
*incoming)
 return 0;
 }
 
+
+enum {
+STATE_HEADER,
+STATE_MESSAGE,
+};
+
 #define APDUBufSize 270
 
-static int
-do_socket_read(void)
+static gboolean
+do_socket_read(GIOChannel *source,
+   GIOCondition condition,
+   gpointer data)
 {
 int rv;
 int dwSendLength;
 int dwRecvLength;
 uint8_t pbRecvBuffer[APDUBufSize];
-uint8_t pbSendBuffer[APDUBufSize];
+static uint8_t pbSendBuffer[APDUBufSize];
 VReaderStatus reader_status;
 VReader *reader = NULL;
-VSCMsgHeader mhHeader;
+static VSCMsgHeader mhHeader;
 VSCMsgError *error_msg;
+GError *err = NULL;
 
-rv = read(sock, mhHeader, sizeof(mhHeader));
-if (rv  sizeof(mhHeader)) {
-/* Error */
-if (rv  0) {
-perror(header read error\n);
-} else {
-fprintf(stderr, header short read %d\n, rv);
-}
-return -1;
-}
-mhHeader.type = ntohl(mhHeader.type);
-mhHeader.reader_id = ntohl(mhHeader.reader_id);
-mhHeader.length = ntohl(mhHeader.length);
-if (verbose) {
-printf(Header: type=%d, reader_id=%u length=%d (0x%x)\n,
-   mhHeader.type, mhHeader.reader_id, mhHeader.length,
-   mhHeader.length);
-}
-switch (mhHeader.type) {
-case VSC_APDU:
-case VSC_Flush:
-case VSC_Error:
-case VSC_Init:
-rv = read(sock, pbSendBuffer, mhHeader.length);
-break;
-default:
-fprintf(stderr, Unexpected message of type 0x%X\n, mhHeader.type);
-return -1;
+static gchar *buf;
+static gsize br, to_read;
+static int state = STATE_HEADER;
+
+if (state == STATE_HEADER  to_read == 0) {
+buf = (gchar *)mhHeader;
+to_read = sizeof(mhHeader);
 }
-switch (mhHeader.type) {
-case VSC_APDU:
-if 

[Qemu-devel] [PATCH 16/26] hw/usb/dev-smartcard-reader.c: remove aborts (never triggered, but just in case)

2013-03-18 Thread Alon Levy
From: Alon Levy a...@pobox.com

Signed-off-by: Alon Levy al...@redhat.com
---
 hw/usb/dev-smartcard-reader.c | 20 
 1 file changed, 12 insertions(+), 8 deletions(-)

diff --git a/hw/usb/dev-smartcard-reader.c b/hw/usb/dev-smartcard-reader.c
index 4ff0641..8f69a55 100644
--- a/hw/usb/dev-smartcard-reader.c
+++ b/hw/usb/dev-smartcard-reader.c
@@ -796,6 +796,12 @@ static void ccid_write_data_block(USBCCIDState *s, uint8_t 
slot, uint8_t seq,
 ccid_reset_error_status(s);
 }
 
+static void ccid_report_error_failed(USBCCIDState *s, uint8_t error)
+{
+s-bmCommandStatus = COMMAND_STATUS_FAILED;
+s-bError = error;
+}
+
 static void ccid_write_data_block_answer(USBCCIDState *s,
 const uint8_t *data, uint32_t len)
 {
@@ -803,7 +809,9 @@ static void ccid_write_data_block_answer(USBCCIDState *s,
 uint8_t slot;
 
 if (!ccid_has_pending_answers(s)) {
-abort();
+DPRINTF(s, D_WARN, error: no pending answer to return to guest\n);
+ccid_report_error_failed(s, ERROR_ICC_MUTE);
+return;
 }
 ccid_remove_pending_answer(s, slot, seq);
 ccid_write_data_block(s, slot, seq, data, len);
@@ -857,12 +865,6 @@ static void ccid_reset_parameters(USBCCIDState *s)
memcpy(s-abProtocolDataStructure, abDefaultProtocolDataStructure, len);
 }
 
-static void ccid_report_error_failed(USBCCIDState *s, uint8_t error)
-{
-s-bmCommandStatus = COMMAND_STATUS_FAILED;
-s-bError = error;
-}
-
 /* NOTE: only a single slot is supported (SLOT_0) */
 static void ccid_on_slot_change(USBCCIDState *s, bool full)
 {
@@ -1129,7 +1131,9 @@ void ccid_card_send_apdu_to_guest(CCIDCardState *card,
 s-bmCommandStatus = COMMAND_STATUS_NO_ERROR;
 answer = ccid_peek_next_answer(s);
 if (answer == NULL) {
-abort();
+DPRINTF(s, D_WARN, %s: error: unexpected lack of answer\n, __func__);
+ccid_report_error_failed(s, ERROR_HW_ERROR);
+return;
 }
 DPRINTF(s, 1, APDU returned to guest %d (answer seq %d, slot %d)\n,
 len, answer-seq, answer-slot);
-- 
1.8.1.4




[Qemu-devel] [PATCH 04/26] ccid: declare DEFAULT_ATR table to be static const

2013-03-18 Thread Alon Levy
From: Jim Meyering meyer...@redhat.com

Signed-off-by: Jim Meyering meyer...@redhat.com
---
 hw/ccid-card-passthru.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/hw/ccid-card-passthru.c b/hw/ccid-card-passthru.c
index 984bd0b..3566e55 100644
--- a/hw/ccid-card-passthru.c
+++ b/hw/ccid-card-passthru.c
@@ -27,7 +27,7 @@ do {\
 #define D_VERBOSE 4
 
 /* TODO: do we still need this? */
-uint8_t DEFAULT_ATR[] = {
+static const uint8_t DEFAULT_ATR[] = {
 /*
  * From some example somewhere
  * 0x3B, 0xB0, 0x18, 0x00, 0xD1, 0x81, 0x05, 0xB1, 0x40, 0x38, 0x1F, 0x03, 0x28
-- 
1.8.1.4




[Qemu-devel] [PATCH 06/26] util: move socket_init() to osdep.c

2013-03-18 Thread Alon Levy
From: Marc-André Lureau marcandre.lur...@redhat.com

vscclient needs to call socket_init() for portability.
Moving to osdep.c since it has no internal dependency.

Signed-off-by: Marc-André Lureau marcandre.lur...@redhat.com
---
 util/osdep.c| 23 +++
 util/qemu-sockets.c | 24 
 2 files changed, 23 insertions(+), 24 deletions(-)

diff --git a/util/osdep.c b/util/osdep.c
index bd59ac9..6ae5aaf 100644
--- a/util/osdep.c
+++ b/util/osdep.c
@@ -406,3 +406,26 @@ bool fips_get_state(void)
 return fips_enabled;
 }
 
+#ifdef _WIN32
+static void socket_cleanup(void)
+{
+WSACleanup();
+}
+#endif
+
+int socket_init(void)
+{
+#ifdef _WIN32
+WSADATA Data;
+int ret, err;
+
+ret = WSAStartup(MAKEWORD(2, 2), Data);
+if (ret != 0) {
+err = WSAGetLastError();
+fprintf(stderr, WSAStartup: %d\n, err);
+return -1;
+}
+atexit(socket_cleanup);
+#endif
+return 0;
+}
diff --git a/util/qemu-sockets.c b/util/qemu-sockets.c
index 83e4e08..f42f0b7 100644
--- a/util/qemu-sockets.c
+++ b/util/qemu-sockets.c
@@ -973,27 +973,3 @@ int socket_dgram(SocketAddress *remote, SocketAddress 
*local, Error **errp)
 qemu_opts_del(opts);
 return fd;
 }
-
-#ifdef _WIN32
-static void socket_cleanup(void)
-{
-WSACleanup();
-}
-#endif
-
-int socket_init(void)
-{
-#ifdef _WIN32
-WSADATA Data;
-int ret, err;
-
-ret = WSAStartup(MAKEWORD(2,2), Data);
-if (ret != 0) {
-err = WSAGetLastError();
-fprintf(stderr, WSAStartup: %d\n, err);
-return -1;
-}
-atexit(socket_cleanup);
-#endif
-return 0;
-}
-- 
1.8.1.4




[Qemu-devel] [PATCH 20/26] hw/usb/dev-smartcard-reader: support windows guest

2013-03-18 Thread Alon Levy
From: Alon Levy a...@pobox.com

By not advertising USB wakeup support (which we don't).

Signed-off-by: Alon Levy al...@redhat.com
---
 hw/usb/dev-smartcard-reader.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/hw/usb/dev-smartcard-reader.c b/hw/usb/dev-smartcard-reader.c
index 7b319b1..48bd519 100644
--- a/hw/usb/dev-smartcard-reader.c
+++ b/hw/usb/dev-smartcard-reader.c
@@ -381,11 +381,11 @@ static const uint8_t qemu_ccid_descriptor[] = {
  * 2 Short APDU level exchange with CCID
  * 4 Short and Extended APDU level exchange with CCID
  *
- * + 10 USB Wake up signaling supported on card
+ * 10 USB Wake up signaling supported on card
  * insertion and removal. Must set bit 5 in bmAttributes
  * in Configuration descriptor if 10 is set.
  */
-0xfe, 0x04, 0x11, 0x00,
+0xfe, 0x04, 0x01, 0x00,
 /*
  * u32 dwMaxCCIDMessageLength; For extended APDU in
  * [261 + 10 , 65544 + 10]. Otherwise the minimum is
-- 
1.8.1.4




[Qemu-devel] [PATCH 08/26] libcacard: fix mingw64 cross-compilation

2013-03-18 Thread Alon Levy
From: Marc-André Lureau marcandre.lur...@gmail.com

Compile and link with version.lo

Signed-off-by: Marc-André Lureau marcandre.lur...@redhat.com
---
 Makefile  | 8 ++--
 rules.mak | 3 ++-
 2 files changed, 8 insertions(+), 3 deletions(-)

diff --git a/Makefile b/Makefile
index 6915178..10abfee 100644
--- a/Makefile
+++ b/Makefile
@@ -151,11 +151,15 @@ recurse-all: $(SUBDIR_RULES) $(ROMSUBDIR_RULES)
 
 bt-host.o: QEMU_CFLAGS += $(BLUEZ_CFLAGS)
 
-version.o: $(SRC_PATH)/version.rc config-host.h
+version.o: $(SRC_PATH)/version.rc config-host.h | version.lo
$(call quiet-command,$(WINDRES) -I. -o $@ $,  RC$(TARGET_DIR)$@)
+version.lo: $(SRC_PATH)/version.rc config-host.h
+   $(call quiet-command,$(LIBTOOL) --mode=compile --tag=RC $(WINDRES) -I. 
-o $@ $,lt RC   $(TARGET_DIR)$@)
 
 version-obj-$(CONFIG_WIN32) += version.o
-Makefile: $(version-obj-y)
+version-lobj-$(CONFIG_WIN32) += $(if $(LIBTOOL),version.lo)
+Makefile: $(version-obj-y) $(version-lobj-y)
+
 
 ##
 # Build libraries
diff --git a/rules.mak b/rules.mak
index 36aba2d..292a422 100644
--- a/rules.mak
+++ b/rules.mak
@@ -35,7 +35,8 @@ LIBTOOL += $(if $(V),,--quiet)
 LINK = $(call quiet-command,\
$(if $(filter %.lo %.la,$^),$(LIBTOOL) --mode=link --tag=CC \
)$(CC) $(QEMU_CFLAGS) $(CFLAGS) $(LDFLAGS) -o $@ \
-   $(sort $(filter %.o, $1)) $(filter-out %.o, $1) $(version-obj-y) \
+   $(sort $(filter %.o, $1)) $(filter-out %.o, $1) \
+   $(if $(filter %.lo %.la,$^),$(version-lobj-y),$(version-obj-y)) \
$(if $(filter %.lo %.la,$^),$(LIBTOOLFLAGS)) \
$(LIBS),$(if $(filter %.lo %.la,$^),lt LINK ,   LINK  
)$(TARGET_DIR)$@)
 endif
-- 
1.8.1.4




[Qemu-devel] [PATCH 07/26] build-sys: must link with -fstack-protector

2013-03-18 Thread Alon Levy
From: Marc-André Lureau marcandre.lur...@gmail.com

It is needed to give that flag to the linker as well, but latest
libtool 2.4.2 still swallows that argument, so let's pass it with
libtool -Wc argument.

qemu-1.4.0/stubs/arch-query-cpu-def.c:6: undefined reference to 
`__stack_chk_guard'

Signed-off-by: Marc-André Lureau marcandre.lur...@redhat.com
---
 configure | 8 +++-
 rules.mak | 1 +
 2 files changed, 8 insertions(+), 1 deletion(-)

diff --git a/configure b/configure
index 46a7594..d76866a 100755
--- a/configure
+++ b/configure
@@ -1209,7 +1209,7 @@ fi
 gcc_flags=-Wold-style-declaration -Wold-style-definition -Wtype-limits
 gcc_flags=-Wformat-security -Wformat-y2k -Winit-self -Wignored-qualifiers 
$gcc_flags
 gcc_flags=-Wmissing-include-dirs -Wempty-body -Wnested-externs $gcc_flags
-gcc_flags=-fstack-protector-all -Wendif-labels $gcc_flags
+gcc_flags=-Wendif-labels $gcc_flags
 gcc_flags=-Wno-initializer-overrides $gcc_flags
 # Note that we do not add -Werror to gcc_flags here, because that would
 # enable it for all configure tests. If a configure test failed due
@@ -1228,6 +1228,11 @@ for flag in $gcc_flags; do
 fi
 done
 
+if compile_prog -Werror -fstack-protector-all  ; then
+QEMU_CFLAGS=$QEMU_CFLAGS -fstack-protector-all
+LIBTOOLFLAGS=$LIBTOOLFLAGS -Wc,-fstack-protector-all
+fi
+
 # Workaround for http://gcc.gnu.org/PR55489.  Happens with -fPIE/-fPIC and
 # large functions that use global variables.  The bug is in all releases of
 # GCC, but it became particularly acute in 4.6.x and 4.7.x.  It is fixed in
@@ -3890,6 +3895,7 @@ else
   echo AUTOCONF_HOST :=   $config_host_mak
 fi
 echo LDFLAGS=$LDFLAGS  $config_host_mak
+echo LIBTOOLFLAGS=$LIBTOOLFLAGS  $config_host_mak
 echo ARLIBS_BEGIN=$arlibs_begin  $config_host_mak
 echo ARLIBS_END=$arlibs_end  $config_host_mak
 echo LIBS+=$LIBS  $config_host_mak
diff --git a/rules.mak b/rules.mak
index edc2552..36aba2d 100644
--- a/rules.mak
+++ b/rules.mak
@@ -36,6 +36,7 @@ LINK = $(call quiet-command,\
$(if $(filter %.lo %.la,$^),$(LIBTOOL) --mode=link --tag=CC \
)$(CC) $(QEMU_CFLAGS) $(CFLAGS) $(LDFLAGS) -o $@ \
$(sort $(filter %.o, $1)) $(filter-out %.o, $1) $(version-obj-y) \
+   $(if $(filter %.lo %.la,$^),$(LIBTOOLFLAGS)) \
$(LIBS),$(if $(filter %.lo %.la,$^),lt LINK ,   LINK  
)$(TARGET_DIR)$@)
 endif
 
-- 
1.8.1.4




[Qemu-devel] [PATCH 15/26] hw/usb/dev-smartcard-reader.c: nicer debug messages

2013-03-18 Thread Alon Levy
From: Alon Levy a...@pobox.com

Signed-off-by: Alon Levy al...@redhat.com
---
 hw/usb/dev-smartcard-reader.c | 69 +++
 1 file changed, 63 insertions(+), 6 deletions(-)

diff --git a/hw/usb/dev-smartcard-reader.c b/hw/usb/dev-smartcard-reader.c
index 7205613..4ff0641 100644
--- a/hw/usb/dev-smartcard-reader.c
+++ b/hw/usb/dev-smartcard-reader.c
@@ -639,13 +639,47 @@ static void ccid_handle_reset(USBDevice *dev)
 ccid_reset(s);
 }
 
+static const char *ccid_control_to_str(USBCCIDState *s, int request)
+{
+switch (request) {
+/* generic - should be factored out if there are other debugees */
+case DeviceOutRequest | USB_REQ_SET_ADDRESS:
+return (generic) set address;
+case DeviceRequest | USB_REQ_GET_DESCRIPTOR:
+return (generic) get descriptor;
+case DeviceRequest | USB_REQ_GET_CONFIGURATION:
+return (generic) get configuration;
+case DeviceOutRequest | USB_REQ_SET_CONFIGURATION:
+return (generic) set configuration;
+case DeviceRequest | USB_REQ_GET_STATUS:
+return (generic) get status;
+case DeviceOutRequest | USB_REQ_CLEAR_FEATURE:
+return (generic) clear feature;
+case DeviceOutRequest | USB_REQ_SET_FEATURE:
+return (generic) set_feature;
+case InterfaceRequest | USB_REQ_GET_INTERFACE:
+return (generic) get interface;
+case InterfaceOutRequest | USB_REQ_SET_INTERFACE:
+return (generic) set interface;
+/* class requests */
+case ClassInterfaceOutRequest | CCID_CONTROL_ABORT:
+return ABORT;
+case ClassInterfaceRequest | CCID_CONTROL_GET_CLOCK_FREQUENCIES:
+return GET_CLOCK_FREQUENCIES;
+case ClassInterfaceRequest | CCID_CONTROL_GET_DATA_RATES:
+return GET_DATA_RATES;
+}
+return unknown;
+}
+
 static void ccid_handle_control(USBDevice *dev, USBPacket *p, int request,
int value, int index, int length, uint8_t *data)
 {
 USBCCIDState *s = DO_UPCAST(USBCCIDState, dev, dev);
 int ret;
 
-DPRINTF(s, 1, got control %x, value %x\n, request, value);
+DPRINTF(s, 1, %s: got control %s (%x), value %x\n, __func__,
+ccid_control_to_str(s, request), request, value);
 ret = usb_desc_handle_control(dev, p, request, value, index, length, data);
 if (ret = 0) {
 return;
@@ -695,7 +729,7 @@ static uint8_t ccid_calc_status(USBCCIDState *s)
  * bmCommandStatus
  */
 uint8_t ret = ccid_card_status(s) | (s-bmCommandStatus  6);
-DPRINTF(s, D_VERBOSE, status = %d\n, ret);
+DPRINTF(s, D_VERBOSE, %s: status = %d\n, __func__, ret);
 return ret;
 }
 
@@ -756,7 +790,7 @@ static void ccid_write_data_block(USBCCIDState *s, uint8_t 
slot, uint8_t seq,
 p-b.bStatus = ccid_calc_status(s);
 p-b.bError = s-bError;
 if (p-b.bError) {
-DPRINTF(s, D_VERBOSE, error %d, p-b.bError);
+DPRINTF(s, D_VERBOSE, error %d\n, p-b.bError);
 }
 memcpy(p-abData, data, len);
 ccid_reset_error_status(s);
@@ -873,6 +907,28 @@ static void ccid_on_apdu_from_guest(USBCCIDState *s, 
CCID_XferBlock *recv)
 }
 }
 
+static const char *ccid_message_type_to_str(uint8_t type)
+{
+switch (type) {
+case CCID_MESSAGE_TYPE_PC_to_RDR_IccPowerOn: return IccPowerOn;
+case CCID_MESSAGE_TYPE_PC_to_RDR_IccPowerOff: return IccPowerOff;
+case CCID_MESSAGE_TYPE_PC_to_RDR_GetSlotStatus: return GetSlotStatus;
+case CCID_MESSAGE_TYPE_PC_to_RDR_XfrBlock: return XfrBlock;
+case CCID_MESSAGE_TYPE_PC_to_RDR_GetParameters: return GetParameters;
+case CCID_MESSAGE_TYPE_PC_to_RDR_ResetParameters: return ResetParameters;
+case CCID_MESSAGE_TYPE_PC_to_RDR_SetParameters: return SetParameters;
+case CCID_MESSAGE_TYPE_PC_to_RDR_Escape: return Escape;
+case CCID_MESSAGE_TYPE_PC_to_RDR_IccClock: return IccClock;
+case CCID_MESSAGE_TYPE_PC_to_RDR_T0APDU: return T0APDU;
+case CCID_MESSAGE_TYPE_PC_to_RDR_Secure: return Secure;
+case CCID_MESSAGE_TYPE_PC_to_RDR_Mechanical: return Mechanical;
+case CCID_MESSAGE_TYPE_PC_to_RDR_Abort: return Abort;
+case CCID_MESSAGE_TYPE_PC_to_RDR_SetDataRateAndClockFrequency:
+return SetDataRateAndClockFrequency;
+}
+return unknown;
+}
+
 static void ccid_handle_bulk_out(USBCCIDState *s, USBPacket *p)
 {
 CCID_Header *ccid_header;
@@ -895,13 +951,15 @@ static void ccid_handle_bulk_out(USBCCIDState *s, 
USBPacket *p)
 %s: bad USB_TOKEN_OUT length, should be at least 10 bytes\n,
 __func__);
 } else {
-DPRINTF(s, D_MORE_INFO, %s %x\n, __func__, 
ccid_header-bMessageType);
+DPRINTF(s, D_MORE_INFO, %s %x %s\n, __func__,
+ccid_header-bMessageType,
+ccid_message_type_to_str(ccid_header-bMessageType));
 switch (ccid_header-bMessageType) {
 case CCID_MESSAGE_TYPE_PC_to_RDR_GetSlotStatus:
 ccid_write_slot_status(s, ccid_header);
 

[Qemu-devel] [PATCH 22/26] libcacard/vreader: add debugging messages for apdu

2013-03-18 Thread Alon Levy
From: Alon Levy a...@pobox.com

controllable by environment variable LIBCACARD_DEBUG.

Signed-off-by: Alon Levy al...@redhat.com
---
 libcacard/cac.c |  7 -
 libcacard/cac.h |  8 +
 libcacard/vreader.c | 89 +
 3 files changed, 97 insertions(+), 7 deletions(-)

diff --git a/libcacard/cac.c b/libcacard/cac.c
index 927a4ca..5864539 100644
--- a/libcacard/cac.c
+++ b/libcacard/cac.c
@@ -12,13 +12,6 @@
 #include vcard_emul.h
 #include card_7816.h
 
-#define CAC_GET_PROPERTIES  0x56
-#define CAC_GET_ACR 0x4c
-#define CAC_READ_BUFFER 0x52
-#define CAC_UPDATE_BUFFER   0x58
-#define CAC_SIGN_DECRYPT0x42
-#define CAC_GET_CERTIFICATE 0x36
-
 /* private data for PKI applets */
 typedef struct CACPKIAppletDataStruct {
 unsigned char *cert;
diff --git a/libcacard/cac.h b/libcacard/cac.h
index 15a61be..d24a2a8 100644
--- a/libcacard/cac.h
+++ b/libcacard/cac.h
@@ -9,6 +9,14 @@
 #define CAC_H 1
 #include vcard.h
 #include vreader.h
+
+#define CAC_GET_PROPERTIES  0x56
+#define CAC_GET_ACR 0x4c
+#define CAC_READ_BUFFER 0x52
+#define CAC_UPDATE_BUFFER   0x58
+#define CAC_SIGN_DECRYPT0x42
+#define CAC_GET_CERTIFICATE 0x36
+
 /*
  * Initialize the cac card. This is the only public function in this file. All
  * the rest are connected through function pointers.
diff --git a/libcacard/vreader.c b/libcacard/vreader.c
index f3efc27..3ab785e 100644
--- a/libcacard/vreader.c
+++ b/libcacard/vreader.c
@@ -13,6 +13,7 @@
 #include card_7816.h
 #include vreader.h
 #include vevent.h
+#include cac.h /* just for debugging defines */
 
 struct VReaderStruct {
 intreference_count;
@@ -24,6 +25,86 @@ struct VReaderStruct {
 VReaderEmulFree reader_private_free;
 };
 
+/*
+ * Debug helpers
+ */
+
+static void debug(const char *fmt, ...)
+{
+static int debug = -1;
+static int debug_inited;
+va_list ap;
+
+if (!debug_inited) {
+debug = getenv(LIBCACARD_DEBUG) ? atoi(getenv(LIBCACARD_DEBUG)) : 
0;
+debug_inited = 1;
+}
+
+if (debug = 0) {
+return;
+}
+
+va_start(ap, fmt);
+vfprintf(stderr, fmt, ap);
+va_end(ap);
+}
+
+static const char *
+apdu_ins_to_string(int ins)
+{
+switch (ins) {
+case VCARD7816_INS_MANAGE_CHANNEL:
+return manage channel;
+case VCARD7816_INS_EXTERNAL_AUTHENTICATE:
+return external authenticate;
+case VCARD7816_INS_GET_CHALLENGE:
+return get challenge;
+case VCARD7816_INS_INTERNAL_AUTHENTICATE:
+return internal authenticate;
+case VCARD7816_INS_ERASE_BINARY:
+return erase binary;
+case VCARD7816_INS_READ_BINARY:
+return read binary;
+case VCARD7816_INS_WRITE_BINARY:
+return write binary;
+case VCARD7816_INS_UPDATE_BINARY:
+return update binary;
+case VCARD7816_INS_READ_RECORD:
+return read record;
+case VCARD7816_INS_WRITE_RECORD:
+return write record;
+case VCARD7816_INS_UPDATE_RECORD:
+return update record;
+case VCARD7816_INS_APPEND_RECORD:
+return append record;
+case VCARD7816_INS_ENVELOPE:
+return envelope;
+case VCARD7816_INS_PUT_DATA:
+return put data;
+case VCARD7816_INS_GET_DATA:
+return get data;
+case VCARD7816_INS_SELECT_FILE:
+return select file;
+case VCARD7816_INS_VERIFY:
+return verify;
+case VCARD7816_INS_GET_RESPONSE:
+return get response;
+case CAC_GET_PROPERTIES:
+return get properties;
+case CAC_GET_ACR:
+return get acr;
+case CAC_READ_BUFFER:
+return read buffer;
+case CAC_UPDATE_BUFFER:
+return update buffer;
+case CAC_SIGN_DECRYPT:
+return sign decrypt;
+case CAC_GET_CERTIFICATE:
+return get certificate;
+}
+return unknown;
+}
+
 /* manage locking */
 static inline void
 vreader_lock(VReader *reader)
@@ -204,7 +285,15 @@ vreader_xfr_bytes(VReader *reader,
 response = vcard_make_response(status);
 card_status = VCARD_DONE;
 } else {
+debug(%s: CLS=0x%x,INS=0x%x,P1=0x%x,P2=0x%x,Lc=%d,Le=%d %s\n,
+  __func__, apdu-a_cla, apdu-a_ins, apdu-a_p1, apdu-a_p2,
+  apdu-a_Lc, apdu-a_Le, apdu_ins_to_string(apdu-a_ins));
 card_status = vcard_process_apdu(card, apdu, response);
+if (response) {
+debug(%s: status=%d sw1=0x%x sw2=0x%x len=%d (total=%d)\n,
+  __func__, response-b_status, response-b_sw1,
+  response-b_sw2, response-b_len, response-b_total_len);
+}
 }
 assert(card_status == VCARD_DONE);
 if (card_status == VCARD_DONE) {
-- 
1.8.1.4




  1   2   3   >