[Qemu-devel] [PATCH V3 4/6] migration: add postcopy downtime into MigrationIncommingState

2017-04-25 Thread Alexey Perevalov
This patch add request to kernel space for UFFD_FEATURE_THREAD_ID,
in case when this feature is provided by kernel.

DowntimeContext is incapsulated inside migration.c.

Signed-off-by: Alexey Perevalov 
---
 include/migration/migration.h | 12 
 migration/migration.c | 33 +
 migration/postcopy-ram.c  |  8 
 3 files changed, 53 insertions(+)

diff --git a/include/migration/migration.h b/include/migration/migration.h
index 5720c88..b1759f7 100644
--- a/include/migration/migration.h
+++ b/include/migration/migration.h
@@ -83,6 +83,8 @@ typedef enum {
 POSTCOPY_INCOMING_END
 } PostcopyState;
 
+struct DowntimeContext;
+
 /* State for the incoming migration */
 struct MigrationIncomingState {
 QEMUFile *from_src_file;
@@ -123,10 +125,20 @@ struct MigrationIncomingState {
 
 /* See savevm.c */
 LoadStateEntry_Head loadvm_handlers;
+
+/*
+ * DowntimeContext to keep information for postcopy
+ * live migration, to calculate downtime
+ * */
+struct DowntimeContext *downtime_ctx;
 };
 
 MigrationIncomingState *migration_incoming_get_current(void);
 void migration_incoming_state_destroy(void);
+/*
+ * Functions to work with downtime context
+ */
+struct DowntimeContext *downtime_context_new(void);
 
 /*
  * An outstanding page request, on the source, having been received
diff --git a/migration/migration.c b/migration/migration.c
index 79f6425..0309c2b 100644
--- a/migration/migration.c
+++ b/migration/migration.c
@@ -77,6 +77,18 @@ static NotifierList migration_state_notifiers =
 
 static bool deferred_incoming;
 
+typedef struct DowntimeContext {
+/* time when page fault initiated per vCPU */
+int64_t *page_fault_vcpu_time;
+/* page address per vCPU */
+uint64_t *vcpu_addr;
+int64_t total_downtime;
+/* downtime per vCPU */
+int64_t *vcpu_downtime;
+/* point in time when last page fault was initiated */
+int64_t last_begin;
+} DowntimeContext;
+
 /*
  * Current state of incoming postcopy; note this is not part of
  * MigrationIncomingState since it's state is used during cleanup
@@ -117,6 +129,23 @@ MigrationState *migrate_get_current(void)
 return _migration;
 }
 
+struct DowntimeContext *downtime_context_new(void)
+{
+DowntimeContext *ctx = g_new0(DowntimeContext, 1);
+ctx->page_fault_vcpu_time = g_new0(int64_t, smp_cpus);
+ctx->vcpu_addr = g_new0(uint64_t, smp_cpus);
+ctx->vcpu_downtime = g_new0(int64_t, smp_cpus);
+return ctx;
+}
+
+static void destroy_downtime_context(struct DowntimeContext *ctx)
+{
+g_free(ctx->page_fault_vcpu_time);
+g_free(ctx->vcpu_addr);
+g_free(ctx->vcpu_downtime);
+g_free(ctx);
+}
+
 MigrationIncomingState *migration_incoming_get_current(void)
 {
 static bool once;
@@ -139,6 +168,10 @@ void migration_incoming_state_destroy(void)
 
 qemu_event_destroy(>main_thread_load_event);
 loadvm_free_handlers(mis);
+if (mis->downtime_ctx) {
+destroy_downtime_context(mis->downtime_ctx);
+mis->downtime_ctx = NULL;
+}
 }
 
 
diff --git a/migration/postcopy-ram.c b/migration/postcopy-ram.c
index 55b5243..ce1ea5d 100644
--- a/migration/postcopy-ram.c
+++ b/migration/postcopy-ram.c
@@ -132,6 +132,14 @@ static bool ufd_version_check(int ufd, 
MigrationIncomingState *mis)
 return false;
 }
 
+#ifdef UFFD_FEATURE_THREAD_ID
+if (mis && UFFD_FEATURE_THREAD_ID & supported_features) {
+/* kernel supports that feature */
+mis->downtime_ctx = downtime_context_new();
+new_features |= UFFD_FEATURE_THREAD_ID;
+}
+#endif
+
 /* request features */
 if (new_features && !request_ufd_features(ufd, new_features)) {
 error_report("ufd_version_check failed: features %" PRIu64,
-- 
1.9.1




[Qemu-devel] [PATCH V3 2/6] migration: pass ptr to MigrationIncomingState into migration ufd_version_check & postcopy_ram_supported_by_host

2017-04-25 Thread Alexey Perevalov
That tiny refactoring is necessary to be able to set
UFFD_FEATURE_THREAD_ID while requesting features, and then
to create downtime context in case when kernel supports it.

Signed-off-by: Alexey Perevalov 
---
 include/migration/postcopy-ram.h |  2 +-
 migration/migration.c|  2 +-
 migration/postcopy-ram.c | 10 +-
 migration/savevm.c   |  2 +-
 4 files changed, 8 insertions(+), 8 deletions(-)

diff --git a/include/migration/postcopy-ram.h b/include/migration/postcopy-ram.h
index 8e036b9..809f6db 100644
--- a/include/migration/postcopy-ram.h
+++ b/include/migration/postcopy-ram.h
@@ -14,7 +14,7 @@
 #define QEMU_POSTCOPY_RAM_H
 
 /* Return true if the host supports everything we need to do postcopy-ram */
-bool postcopy_ram_supported_by_host(void);
+bool postcopy_ram_supported_by_host(MigrationIncomingState *mis);
 
 /*
  * Make all of RAM sensitive to accesses to areas that haven't yet been written
diff --git a/migration/migration.c b/migration/migration.c
index ad4036f..79f6425 100644
--- a/migration/migration.c
+++ b/migration/migration.c
@@ -802,7 +802,7 @@ void 
qmp_migrate_set_capabilities(MigrationCapabilityStatusList *params,
  * special support.
  */
 if (!old_postcopy_cap && runstate_check(RUN_STATE_INMIGRATE) &&
-!postcopy_ram_supported_by_host()) {
+!postcopy_ram_supported_by_host(NULL)) {
 /* postcopy_ram_supported_by_host will have emitted a more
  * detailed message
  */
diff --git a/migration/postcopy-ram.c b/migration/postcopy-ram.c
index dc80dbb..dcf2ed1 100644
--- a/migration/postcopy-ram.c
+++ b/migration/postcopy-ram.c
@@ -60,7 +60,7 @@ struct PostcopyDiscardState {
 #include 
 #include 
 
-static bool ufd_version_check(int ufd)
+static bool ufd_version_check(int ufd, MigrationIncomingState *mis)
 {
 struct uffdio_api api_struct;
 uint64_t ioctl_mask;
@@ -113,7 +113,7 @@ static int test_range_shared(const char *block_name, void 
*host_addr,
  * normally fine since if the postcopy succeeds it gets turned back on at the
  * end.
  */
-bool postcopy_ram_supported_by_host(void)
+bool postcopy_ram_supported_by_host(MigrationIncomingState *mis)
 {
 long pagesize = getpagesize();
 int ufd = -1;
@@ -136,7 +136,7 @@ bool postcopy_ram_supported_by_host(void)
 }
 
 /* Version and features check */
-if (!ufd_version_check(ufd)) {
+if (!ufd_version_check(ufd, mis)) {
 goto out;
 }
 
@@ -515,7 +515,7 @@ int postcopy_ram_enable_notify(MigrationIncomingState *mis)
  * Although the host check already tested the API, we need to
  * do the check again as an ABI handshake on the new fd.
  */
-if (!ufd_version_check(mis->userfault_fd)) {
+if (!ufd_version_check(mis->userfault_fd, mis)) {
 return -1;
 }
 
@@ -653,7 +653,7 @@ void *postcopy_get_tmp_page(MigrationIncomingState *mis)
 
 #else
 /* No target OS support, stubs just fail */
-bool postcopy_ram_supported_by_host(void)
+bool postcopy_ram_supported_by_host(MigrationIncomingState *mis)
 {
 error_report("%s: No OS support", __func__);
 return false;
diff --git a/migration/savevm.c b/migration/savevm.c
index 3b19a4a..f01e418 100644
--- a/migration/savevm.c
+++ b/migration/savevm.c
@@ -1360,7 +1360,7 @@ static int 
loadvm_postcopy_handle_advise(MigrationIncomingState *mis)
 return -1;
 }
 
-if (!postcopy_ram_supported_by_host()) {
+if (!postcopy_ram_supported_by_host(mis)) {
 postcopy_state_set(POSTCOPY_INCOMING_NONE);
 return -1;
 }
-- 
1.9.1




[Qemu-devel] [PATCH V3 5/6] migration: calculate downtime on dst side

2017-04-25 Thread Alexey Perevalov
This patch provides downtime calculation per vCPU,
as a summary and as a overlapped value for all vCPUs.

This approach was suggested by Peter Xu, as an improvements of
previous approch where QEMU kept tree with faulted page address and cpus bitmask
in it. Now QEMU is keeping array with faulted page address as value and vCPU
as index. It helps to find proper vCPU at UFFD_COPY time. Also it keeps
list for downtime per vCPU (could be traced with page_fault_addr)

For more details see comments for get_postcopy_total_downtime
implementation.

Downtime will not calculated if postcopy_downtime field of
MigrationIncomingState wasn't initialized.

Signed-off-by: Alexey Perevalov 
---
 include/migration/migration.h |   3 ++
 migration/migration.c | 103 ++
 migration/postcopy-ram.c  |  20 +++-
 migration/trace-events|   6 ++-
 4 files changed, 130 insertions(+), 2 deletions(-)

diff --git a/include/migration/migration.h b/include/migration/migration.h
index b1759f7..137405b 100644
--- a/include/migration/migration.h
+++ b/include/migration/migration.h
@@ -139,6 +139,9 @@ void migration_incoming_state_destroy(void);
  * Functions to work with downtime context
  */
 struct DowntimeContext *downtime_context_new(void);
+void mark_postcopy_downtime_begin(uint64_t addr, int cpu);
+void mark_postcopy_downtime_end(uint64_t addr);
+uint64_t get_postcopy_total_downtime(void);
 
 /*
  * An outstanding page request, on the source, having been received
diff --git a/migration/migration.c b/migration/migration.c
index 0309c2b..b559dfe 100644
--- a/migration/migration.c
+++ b/migration/migration.c
@@ -2150,3 +2150,106 @@ PostcopyState postcopy_state_set(PostcopyState 
new_state)
 return atomic_xchg(_postcopy_state, new_state);
 }
 
+void mark_postcopy_downtime_begin(uint64_t addr, int cpu)
+{
+MigrationIncomingState *mis = migration_incoming_get_current();
+DowntimeContext *dc;
+if (!mis->downtime_ctx || cpu < 0) {
+return;
+}
+dc = mis->downtime_ctx;
+dc->vcpu_addr[cpu] = addr;
+dc->last_begin = dc->page_fault_vcpu_time[cpu] =
+qemu_clock_get_ms(QEMU_CLOCK_REALTIME);
+
+trace_mark_postcopy_downtime_begin(addr, dc, dc->page_fault_vcpu_time[cpu],
+cpu);
+}
+
+void mark_postcopy_downtime_end(uint64_t addr)
+{
+MigrationIncomingState *mis = migration_incoming_get_current();
+DowntimeContext *dc;
+int i;
+bool all_vcpu_down = true;
+int64_t now;
+
+if (!mis->downtime_ctx) {
+return;
+}
+dc = mis->downtime_ctx;
+now = qemu_clock_get_ms(QEMU_CLOCK_REALTIME);
+
+/* check all vCPU down,
+ * QEMU has bitmap.h, but even with bitmap_and
+ * will be a cycle */
+for (i = 0; i < smp_cpus; i++) {
+if (dc->vcpu_addr[i]) {
+continue;
+}
+all_vcpu_down = false;
+break;
+}
+
+if (all_vcpu_down) {
+dc->total_downtime += now - dc->last_begin;
+}
+
+/* lookup cpu, to clear it */
+for (i = 0; i < smp_cpus; i++) {
+uint64_t vcpu_downtime;
+
+if (dc->vcpu_addr[i] != addr) {
+continue;
+}
+
+vcpu_downtime = now - dc->page_fault_vcpu_time[i];
+
+dc->vcpu_addr[i] = 0;
+dc->vcpu_downtime[i] += vcpu_downtime;
+}
+
+trace_mark_postcopy_downtime_end(addr, dc, dc->total_downtime);
+}
+
+/*
+ * This function just provide calculated before downtime per cpu and trace it.
+ * Total downtime is calculated in mark_postcopy_downtime_end.
+ *
+ *
+ * Assume we have 3 CPU
+ *
+ *  S1E1   S1   E1
+ * -***xxx***> CPU1
+ *
+ * S2E2
+ * xxx---> CPU2
+ *
+ * S3E3
+ * xxx---> CPU3
+ *
+ * We have sequence S1,S2,E1,S3,S1,E2,E3,E1
+ * S2,E1 - doesn't match condition due to sequence S1,S2,E1 doesn't include 
CPU3
+ * S3,S1,E2 - sequence includes all CPUs, in this case overlap will be S1,E2 -
+ *it's a part of total downtime.
+ * S1 - here is last_begin
+ * Legend of the picture is following:
+ *  * - means downtime per vCPU
+ *  x - means overlapped downtime (total downtime)
+ */
+uint64_t get_postcopy_total_downtime(void)
+{
+MigrationIncomingState *mis = migration_incoming_get_current();
+
+if (!mis->downtime_ctx) {
+return 0;
+}
+
+if (trace_event_get_state(TRACE_DOWNTIME_PER_CPU)) {
+int i;
+for (i = 0; i < smp_cpus; i++) {
+trace_downtime_per_cpu(i, mis->downtime_ctx->vcpu_downtime[i]);
+}
+}
+return mis->downtime_ctx->total_downtime;
+}
diff --git a/migration/postcopy-ram.c b/migration/postcopy-ram.c
index ce1ea5d..03c2be7 100644
--- 

[Qemu-devel] [PATCH V3 6/6] migration: trace postcopy total downtime

2017-04-25 Thread Alexey Perevalov
It's not possible to transmit it back to source host,
due to RP protocol is not expandable.

Signed-off-by: Alexey Perevalov 
---
 migration/postcopy-ram.c | 2 ++
 migration/trace-events   | 1 +
 2 files changed, 3 insertions(+)

diff --git a/migration/postcopy-ram.c b/migration/postcopy-ram.c
index 03c2be7..46a42d4 100644
--- a/migration/postcopy-ram.c
+++ b/migration/postcopy-ram.c
@@ -390,6 +390,8 @@ int postcopy_ram_incoming_cleanup(MigrationIncomingState 
*mis)
 }
 
 postcopy_state_set(POSTCOPY_INCOMING_END);
+/* here should be downtime receiving back operation */
+
trace_postcopy_ram_incoming_cleanup_downtime(get_postcopy_total_downtime());
 migrate_send_rp_shut(mis, qemu_file_get_error(mis->from_src_file) != 0);
 
 if (mis->postcopy_tmp_page) {
diff --git a/migration/trace-events b/migration/trace-events
index 19e7dc5..25521d4 100644
--- a/migration/trace-events
+++ b/migration/trace-events
@@ -194,6 +194,7 @@ postcopy_ram_incoming_cleanup_closeuf(void) ""
 postcopy_ram_incoming_cleanup_entry(void) ""
 postcopy_ram_incoming_cleanup_exit(void) ""
 postcopy_ram_incoming_cleanup_join(void) ""
+postcopy_ram_incoming_cleanup_downtime(uint64_t total) "total downtime %" 
PRIu64
 save_xbzrle_page_skipping(void) ""
 save_xbzrle_page_overflow(void) ""
 ram_save_iterate_big_wait(uint64_t milliconds, int iterations) "big wait: %" 
PRIu64 " milliseconds, %d iterations"
-- 
1.9.1




[Qemu-devel] [PATCH V3 3/6] migration: split ufd_version_check onto receive/request features part

2017-04-25 Thread Alexey Perevalov
This modification is necessary for userfault fd features which are
required to be requested from userspace.
UFFD_FEATURE_THREAD_ID is a one of such "on demand" feature, which will
be introduced in the next patch.

QEMU need to use separate userfault file descriptor, due to
userfault context has internal state, and after first call of
ioctl UFFD_API it changes its state to UFFD_STATE_RUNNING (in case of
success), but
kernel while handling ioctl UFFD_API expects UFFD_STATE_WAIT_API. So
only one ioctl with UFFD_API is possible per ufd.

Signed-off-by: Alexey Perevalov 
---
 migration/postcopy-ram.c | 68 
 1 file changed, 63 insertions(+), 5 deletions(-)

diff --git a/migration/postcopy-ram.c b/migration/postcopy-ram.c
index dcf2ed1..55b5243 100644
--- a/migration/postcopy-ram.c
+++ b/migration/postcopy-ram.c
@@ -60,15 +60,51 @@ struct PostcopyDiscardState {
 #include 
 #include 
 
-static bool ufd_version_check(int ufd, MigrationIncomingState *mis)
+
+/*
+ * Check userfault fd features, to request only supported features in
+ * future.
+ * __NR_userfaultfd - should be checked before
+ * Return obtained features
+ */
+static bool receive_ufd_features(__u64 *features)
 {
-struct uffdio_api api_struct;
-uint64_t ioctl_mask;
+struct uffdio_api api_struct = {0};
+int ufd;
+bool ret = true;
 
+/* if we are here __NR_userfaultfd should exists */
+ufd = syscall(__NR_userfaultfd, O_CLOEXEC);
+if (ufd == -1) {
+return false;
+}
+
+/* ask features */
 api_struct.api = UFFD_API;
 api_struct.features = 0;
 if (ioctl(ufd, UFFDIO_API, _struct)) {
-error_report("postcopy_ram_supported_by_host: UFFDIO_API failed: %s",
+error_report("receive_ufd_features: UFFDIO_API failed: %s",
+strerror(errno));
+ret = false;
+goto release_ufd;
+}
+
+*features = api_struct.features;
+
+release_ufd:
+close(ufd);
+return ret;
+}
+
+static bool request_ufd_features(int ufd, __u64 features)
+{
+struct uffdio_api api_struct = {0};
+uint64_t ioctl_mask;
+
+api_struct.api = UFFD_API;
+api_struct.features = features;
+if (ioctl(ufd, UFFDIO_API, _struct)) {
+error_report("request_ufd_features: UFFDIO_API failed: %s",
  strerror(errno));
 return false;
 }
@@ -81,11 +117,33 @@ static bool ufd_version_check(int ufd, 
MigrationIncomingState *mis)
 return false;
 }
 
+return true;
+}
+
+static bool ufd_version_check(int ufd, MigrationIncomingState *mis)
+{
+__u64 new_features = 0;
+
+/* ask features */
+__u64 supported_features;
+
+if (!receive_ufd_features(_features)) {
+error_report("ufd_version_check failed");
+return false;
+}
+
+/* request features */
+if (new_features && !request_ufd_features(ufd, new_features)) {
+error_report("ufd_version_check failed: features %" PRIu64,
+(uint64_t)new_features);
+return false;
+}
+
 if (getpagesize() != ram_pagesize_summary()) {
 bool have_hp = false;
 /* We've got a huge page */
 #ifdef UFFD_FEATURE_MISSING_HUGETLBFS
-have_hp = api_struct.features & UFFD_FEATURE_MISSING_HUGETLBFS;
+have_hp = supported_features & UFFD_FEATURE_MISSING_HUGETLBFS;
 #endif
 if (!have_hp) {
 error_report("Userfault on this host does not support huge pages");
-- 
1.9.1




[Qemu-devel] [PATCH V3 0/6] calculate downtime for postcopy live migration

2017-04-25 Thread Alexey Perevalov
This is third version of patch set.
First version was tagged as RFC, second was without version tag.

Difference since previous version (V3 -> V2)
- Downtime calculation approach was changed, thanks to Peter Xu
- Due to previous point no more need to keep GTree as well as bitmap of 
cpus.
So glib changes aren't included in this patch set, it could be resent in
another patch set, if it will be a good reason for it.
- No procfs traces in this patchset, if somebody wants it, you could get it
from patchwork site to track down page fault initiators.
- UFFD_FEATURE_THREAD_ID is requesting only when kernel supports it
- It doesn't send back the downtime, just trace it

This patch set is based on master branch of git://git.qemu-project.org/qemu.git
base commit is commit 372b3fe0b2ecdd39ba850e31c0c6686315c507af.

It contains patch for kernel header, just for convinience of applying current
patch set, for testing until kernel headers arn't synced.


Alexey Perevalov (6):
  userfault: add pid into uffd_msg & update UFFD_FEATURE_*
  migration: pass ptr to MigrationIncomingState into migration
ufd_version_check & postcopy_ram_supported_by_host
  migration: split ufd_version_check onto receive/request features part
  migration: add postcopy downtime into MigrationIncommingState
  migration: calculate downtime on dst side
  migration: trace postcopy total downtime

 include/migration/migration.h |  15 +
 include/migration/postcopy-ram.h  |   2 +-
 linux-headers/linux/userfaultfd.h |   5 ++
 migration/migration.c | 138 +-
 migration/postcopy-ram.c  | 107 ++---
 migration/savevm.c|   2 +-
 migration/trace-events|   7 +-
 7 files changed, 262 insertions(+), 14 deletions(-)

-- 
1.9.1




[Qemu-devel] [PATCH V3 1/6] userfault: add pid into uffd_msg & update UFFD_FEATURE_*

2017-04-25 Thread Alexey Perevalov
This commit duplicates header of "userfaultfd: provide pid in userfault msg"
into linux kernel.

Signed-off-by: Alexey Perevalov 
---
 linux-headers/linux/userfaultfd.h | 5 +
 1 file changed, 5 insertions(+)

diff --git a/linux-headers/linux/userfaultfd.h 
b/linux-headers/linux/userfaultfd.h
index 2ed5dc3..e7c8898 100644
--- a/linux-headers/linux/userfaultfd.h
+++ b/linux-headers/linux/userfaultfd.h
@@ -77,6 +77,9 @@ struct uffd_msg {
struct {
__u64   flags;
__u64   address;
+   union {
+   __u32   ptid;
+   } feat;
} pagefault;
 
struct {
@@ -158,6 +161,8 @@ struct uffdio_api {
 #define UFFD_FEATURE_EVENT_MADVDONTNEED(1<<3)
 #define UFFD_FEATURE_MISSING_HUGETLBFS (1<<4)
 #define UFFD_FEATURE_MISSING_SHMEM (1<<5)
+#define UFFD_FEATURE_EVENT_UNMAP   (1<<6)
+#define UFFD_FEATURE_THREAD_ID (1<<7)
__u64 features;
 
__u64 ioctls;
-- 
1.9.1




Re: [Qemu-devel] Subject: [PATCH] target-ppc: Add global timer group A to open-pic.

2017-04-25 Thread David Gibson
On Fri, Apr 21, 2017 at 02:58:23PM -0700, Aaron Larson wrote:
> Add global timer group A to open-pic.  This patch is still somewhat
> dubious because I'm not sure how to determine what QEMU wants for the
> timer frequency.  Suggestions solicited.
> 
> Signed-off-by: Aaron Larson 
> ---
>  hw/intc/openpic.c | 134 
> ++
>  1 file changed, 116 insertions(+), 18 deletions(-)
> 
> diff --git a/hw/intc/openpic.c b/hw/intc/openpic.c
> index 4349e45..769a31a 100644
> --- a/hw/intc/openpic.c
> +++ b/hw/intc/openpic.c
> @@ -45,6 +45,7 @@
>  #include "qemu/bitops.h"
>  #include "qapi/qmp/qerror.h"
>  #include "qemu/log.h"
> +#include "qemu/timer.h"
>  
>  //#define DEBUG_OPENPIC
>  
> @@ -54,8 +55,10 @@ static const int debug_openpic = 1;
>  static const int debug_openpic = 0;
>  #endif
>  
> +static int get_current_cpu(void);
>  #define DPRINTF(fmt, ...) do { \
>  if (debug_openpic) { \
> +printf("Core%d: ", get_current_cpu()); \
>  printf(fmt , ## __VA_ARGS__); \
>  } \
>  } while (0)
> @@ -246,9 +249,24 @@ typedef struct IRQSource {
>  #define IDR_EP  0x8000  /* external pin */
>  #define IDR_CI  0x4000  /* critical interrupt */
>  
> +/* Conversion between ticks and nanosecs: TODO: need better way for this.
> + Assume a 100mhz clock, divided by 8, or 25mhz
> + 25,000,000 ticks/sec, 25,000/ms, 25/us, 1 tick/40ns
> +*/

I'm not sure what you mean by "ticks" here.  Ticks of the openpic
clock itself?  Or something internal to qemu?

> +#define CONV_FACTOR 40LL
> +static inline uint64_t ns_to_ticks(uint64_t ns)   { return ns   / 
> CONV_FACTOR; }
> +static inline uint64_t ticks_to_ns(uint64_t tick) { return tick * 
> CONV_FACTOR; }
> +
>  typedef struct OpenPICTimer {
>  uint32_t tccr;  /* Global timer current count register */
>  uint32_t tbcr;  /* Global timer base count register */
> +int   n_IRQ;
> +bool  qemu_timer_active; /* Is the qemu_timer is 
> running? */
> +struct QEMUTimer *qemu_timer;   /* May be 0 if not created. */

s/0/NULL/

> +struct OpenPICState  *opp;  /* device timer is part of. */
> +/* the time corresponding to the last current_count written or read,
> +   only defined if qemu_timer_active. */
> +uint64_t  originTime;

time by what measure?

>  } OpenPICTimer;
>  
>  typedef struct OpenPICMSI {
> @@ -795,37 +813,102 @@ static uint64_t openpic_gbl_read(void *opaque, hwaddr 
> addr, unsigned len)
>  return retval;
>  }
>  
> +static void openpic_tmr_set_tmr(OpenPICTimer *tmr, uint32_t val, bool 
> enabled);
> +
> +static void qemu_timer_cb(void *opaque)
> +{
> +OpenPICTimer *tmr = opaque;
> +OpenPICState *opp = tmr->opp;
> +uint32_t  n_IRQ = tmr->n_IRQ;
> +uint32_t val =   tmr->tbcr & ~TBCR_CI;
> +uint32_t tog = ((tmr->tccr & TCCR_TOG) ^ TCCR_TOG);  /* invert toggle. */
> +
> +DPRINTF("%s n_IRQ=%d\n", __func__, n_IRQ);
> +/* reload current count from base count and setup timer. */
> +tmr->tccr = val | tog;
> +openpic_tmr_set_tmr(tmr, val, /*enabled=*/true);
> +/* raise the interrupt. */
> +opp->src[n_IRQ].destmask = read_IRQreg_idr(opp, n_IRQ);
> +openpic_set_irq(opp, n_IRQ, 1);
> +openpic_set_irq(opp, n_IRQ, 0);
> +}
> +
> +/* If enabled is true, arranges for an interrupt to be raised val clocks into
> +   the future, if enabled is false cancels the timer. */
> +static void openpic_tmr_set_tmr(OpenPICTimer *tmr, uint32_t val, bool 
> enabled)
> +{
> +/* if timer doesn't exist, create it. */
> +if (tmr->qemu_timer == 0) {

Please use == NULL, or just !tmr->qemu_timer

> +tmr->qemu_timer = timer_new_ns(QEMU_CLOCK_VIRTUAL, _timer_cb, 
> tmr);
> +DPRINTF("Created timer for n_IRQ %d\n", tmr->n_IRQ);
> +}
> +uint64_t ns = ticks_to_ns(val & ~TCCR_TOG);
> +/* A count of zero causes a timer to be set to expire immediately.  This
> +   effectively stops the simulation so we don't honor that configuration.
> +   On real hardware, this would generate an interrupt on every clock 
> cycle
> +   if the interrupt was unmasked. */
> +if ((ns == 0) || !enabled) {
> +tmr->qemu_timer_active = false;
> +tmr->tccr = tmr->tccr & TCCR_TOG;
> +timer_del(tmr->qemu_timer); /* set timer to never expire. */
> +} else {
> +tmr->qemu_timer_active = true;
> +uint64_t now = qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL);
> +tmr->originTime = now;
> +timer_mod(tmr->qemu_timer, now + ns); /* set timer expiration. */
> +}
> +}
> +
> +/* Returns the currrent tccr value, i.e., timer value (in clocks) with
> +   appropriate TOG. */
> +static uint64_t openpic_tmr_get_timer(OpenPICTimer *tmr)
> +{
> +uint64_t retval;
> +if (!tmr->qemu_timer_active) {
> +retval = tmr->tccr;
> +} else {
> +uint64_t now = 

[Qemu-devel] [PATCH] monitor: Check whether TCG is enabled before running the "info jit" code

2017-04-25 Thread Thomas Huth
The "info jit" command currently aborts on Mac OS X with the message
"qemu_mutex_lock: Invalid argument" when running with "-M accel=qtest".
We should only call into the TCG code here if TCG has really been
enabled and initialized.

Signed-off-by: Thomas Huth 
---
 monitor.c | 5 +
 1 file changed, 5 insertions(+)

diff --git a/monitor.c b/monitor.c
index be282ec..3e0979d 100644
--- a/monitor.c
+++ b/monitor.c
@@ -1086,6 +1086,11 @@ static void hmp_info_registers(Monitor *mon, const QDict 
*qdict)
 
 static void hmp_info_jit(Monitor *mon, const QDict *qdict)
 {
+if (!tcg_enabled()) {
+error_report("JIT information is only available with accel=tcg");
+return;
+}
+
 dump_exec_info((FILE *)mon, monitor_fprintf);
 dump_drift_info((FILE *)mon, monitor_fprintf);
 }
-- 
1.8.3.1




[Qemu-devel] [PATCH v15 20/21] file-posix: Add image locking to perm operations

2017-04-25 Thread Fam Zheng
This extends the permission bits of op blocker API to external using
Linux OFD locks.

Each permission in @perm and @shared_perm is represented by a locked
byte in the image file.  Requesting a permission in @perm is translated
to a shared lock of the corresponding byte; rejecting to share the same
permission is translated to a shared lock of a separate byte. With that,
we use 2x number of bytes of distinct permission types.

virtlockd in libvirt locks the first byte, so we do locking from a
higher offset.

Suggested-by: Kevin Wolf 
Signed-off-by: Fam Zheng 
---
 block/file-posix.c | 267 -
 1 file changed, 264 insertions(+), 3 deletions(-)

diff --git a/block/file-posix.c b/block/file-posix.c
index 2114720..b92fdc3 100644
--- a/block/file-posix.c
+++ b/block/file-posix.c
@@ -129,12 +129,28 @@ do { \
 
 #define MAX_BLOCKSIZE  4096
 
+/* Posix file locking bytes. Libvirt takes byte 0, we start from higher bytes,
+ * leaving a few more bytes for its future use. */
+#define RAW_LOCK_PERM_BASE 100
+#define RAW_LOCK_SHARED_BASE   200
+#ifdef F_OFD_SETLK
+#define RAW_LOCK_SUPPORTED 1
+#else
+#define RAW_LOCK_SUPPORTED 0
+#endif
+
 typedef struct BDRVRawState {
 int fd;
+int lock_fd;
+bool use_lock;
 int type;
 int open_flags;
 size_t buf_align;
 
+/* The current permissions. */
+uint64_t perm;
+uint64_t shared_perm;
+
 #ifdef CONFIG_XFS
 bool is_xfs:1;
 #endif
@@ -440,6 +456,8 @@ static int raw_open_common(BlockDriverState *bs, QDict 
*options,
 }
 s->use_linux_aio = (aio == BLOCKDEV_AIO_OPTIONS_NATIVE);
 
+s->use_lock = qemu_opt_get_bool(opts, "locking", true);
+
 s->open_flags = open_flags;
 raw_parse_flags(bdrv_flags, >open_flags);
 
@@ -455,6 +473,21 @@ static int raw_open_common(BlockDriverState *bs, QDict 
*options,
 }
 s->fd = fd;
 
+s->lock_fd = -1;
+fd = qemu_open(filename, O_RDONLY);
+if (fd < 0) {
+if (RAW_LOCK_SUPPORTED) {
+ret = -errno;
+error_setg_errno(errp, errno, "Could not open '%s' for locking",
+ filename);
+qemu_close(s->fd);
+goto fail;
+}
+}
+s->lock_fd = fd;
+s->perm = 0;
+s->shared_perm = BLK_PERM_ALL;
+
 #ifdef CONFIG_LINUX_AIO
  /* Currently Linux does AIO only for files opened with O_DIRECT */
 if (s->use_linux_aio && !(s->open_flags & O_DIRECT)) {
@@ -542,6 +575,156 @@ static int raw_open(BlockDriverState *bs, QDict *options, 
int flags,
 return raw_open_common(bs, options, flags, 0, errp);
 }
 
+typedef enum {
+RAW_PL_PREPARE,
+RAW_PL_COMMIT,
+RAW_PL_ABORT,
+} RawPermLockOp;
+
+/* Lock wanted bytes by @perm and ~@shared_perm in the file; if @unlock ==
+ * true, also unlock the unneeded bytes. */
+static int raw_apply_lock_bytes(BDRVRawState *s,
+uint64_t perm_lock_bits,
+uint64_t shared_perm_lock_bits,
+bool unlock, Error **errp)
+{
+int ret;
+int i;
+
+for (i = 0; i < BLK_PERM_MAX; ++i) {
+int off = RAW_LOCK_PERM_BASE + i;
+if (perm_lock_bits & (1ULL << i)) {
+ret = qemu_lock_fd(s->lock_fd, off, 1, false);
+if (ret) {
+error_setg(errp, "Failed to lock byte %d", off);
+return ret;
+}
+} else if (unlock) {
+ret = qemu_unlock_fd(s->lock_fd, off, 1);
+if (ret) {
+error_setg(errp, "Failed to unlock byte %d", off);
+return ret;
+}
+}
+}
+for (i = 0; i < BLK_PERM_MAX; ++i) {
+int off = RAW_LOCK_SHARED_BASE + i;
+if (shared_perm_lock_bits & (1ULL << i)) {
+ret = qemu_lock_fd(s->lock_fd, off, 1, false);
+if (ret) {
+error_setg(errp, "Failed to lock byte %d", off);
+return ret;
+}
+} else if (unlock) {
+ret = qemu_unlock_fd(s->lock_fd, off, 1);
+if (ret) {
+error_setg(errp, "Failed to unlock byte %d", off);
+return ret;
+}
+}
+}
+return 0;
+}
+
+/* Check "unshared" bytes implied by @perm and ~@shared_perm in the file. */
+static int raw_check_lock_bytes(BDRVRawState *s,
+uint64_t perm, uint64_t shared_perm,
+Error **errp)
+{
+int ret;
+int i;
+
+for (i = 0; i < BLK_PERM_MAX; ++i) {
+int off = RAW_LOCK_SHARED_BASE + i;
+uint64_t p = 1ULL << i;
+if (perm & p) {
+ret = qemu_lock_fd_test(s->lock_fd, off, 1, true);
+if (ret) {
+error_setg(errp,
+   "Failed to check byte %d for \"%s\" permission",
+   off, bdrv_perm_names(p));
+

[Qemu-devel] [PATCH v15 14/21] iotests: 172: Use separate images for multiple devices

2017-04-25 Thread Fam Zheng
To avoid image lock failures.

Signed-off-by: Fam Zheng 
---
 tests/qemu-iotests/172 | 55 +-
 tests/qemu-iotests/172.out | 50 +
 2 files changed, 56 insertions(+), 49 deletions(-)

diff --git a/tests/qemu-iotests/172 b/tests/qemu-iotests/172
index 1b7d3a1..826d6fe 100755
--- a/tests/qemu-iotests/172
+++ b/tests/qemu-iotests/172
@@ -30,6 +30,8 @@ status=1  # failure is the default!
 _cleanup()
 {
_cleanup_test_img
+rm -f "$TEST_IMG.2"
+rm -f "$TEST_IMG.3"
 }
 trap "_cleanup; exit \$status" 0 1 2 3 15
 
@@ -86,6 +88,9 @@ size=720k
 
 _make_test_img $size
 
+TEST_IMG="$TEST_IMG.2" _make_test_img $size
+TEST_IMG="$TEST_IMG.3" _make_test_img $size
+
 # Default drive semantics:
 #
 # By default you get a single empty floppy drive. You can override it with
@@ -105,7 +110,7 @@ echo === Using -fda/-fdb options ===
 
 check_floppy_qtree -fda "$TEST_IMG"
 check_floppy_qtree -fdb "$TEST_IMG"
-check_floppy_qtree -fda "$TEST_IMG" -fdb "$TEST_IMG"
+check_floppy_qtree -fda "$TEST_IMG" -fdb "$TEST_IMG.2"
 
 
 echo
@@ -114,7 +119,7 @@ echo === Using -drive options ===
 
 check_floppy_qtree -drive if=floppy,file="$TEST_IMG"
 check_floppy_qtree -drive if=floppy,file="$TEST_IMG",index=1
-check_floppy_qtree -drive if=floppy,file="$TEST_IMG" -drive 
if=floppy,file="$TEST_IMG",index=1
+check_floppy_qtree -drive if=floppy,file="$TEST_IMG" -drive 
if=floppy,file="$TEST_IMG.2",index=1
 
 echo
 echo
@@ -122,7 +127,7 @@ echo === Using -drive if=none and -global ===
 
 check_floppy_qtree -drive if=none,file="$TEST_IMG" -global isa-fdc.driveA=none0
 check_floppy_qtree -drive if=none,file="$TEST_IMG" -global isa-fdc.driveB=none0
-check_floppy_qtree -drive if=none,file="$TEST_IMG" -drive 
if=none,file="$TEST_IMG" \
+check_floppy_qtree -drive if=none,file="$TEST_IMG" -drive 
if=none,file="$TEST_IMG.2" \
-global isa-fdc.driveA=none0 -global isa-fdc.driveB=none1
 
 echo
@@ -131,7 +136,7 @@ echo === Using -drive if=none and -device ===
 
 check_floppy_qtree -drive if=none,file="$TEST_IMG" -device floppy,drive=none0
 check_floppy_qtree -drive if=none,file="$TEST_IMG" -device 
floppy,drive=none0,unit=1
-check_floppy_qtree -drive if=none,file="$TEST_IMG" -drive 
if=none,file="$TEST_IMG" \
+check_floppy_qtree -drive if=none,file="$TEST_IMG" -drive 
if=none,file="$TEST_IMG.2" \
-device floppy,drive=none0 -device floppy,drive=none1,unit=1
 
 echo
@@ -139,58 +144,58 @@ echo
 echo === Mixing -fdX and -global ===
 
 # Working
-check_floppy_qtree -fda "$TEST_IMG" -drive if=none,file="$TEST_IMG" -global 
isa-fdc.driveB=none0
-check_floppy_qtree -fdb "$TEST_IMG" -drive if=none,file="$TEST_IMG" -global 
isa-fdc.driveA=none0
+check_floppy_qtree -fda "$TEST_IMG" -drive if=none,file="$TEST_IMG.2" -global 
isa-fdc.driveB=none0
+check_floppy_qtree -fdb "$TEST_IMG" -drive if=none,file="$TEST_IMG.2" -global 
isa-fdc.driveA=none0
 
 # Conflicting (-fdX wins)
-check_floppy_qtree -fda "$TEST_IMG" -drive if=none,file="$TEST_IMG" -global 
isa-fdc.driveA=none0
-check_floppy_qtree -fdb "$TEST_IMG" -drive if=none,file="$TEST_IMG" -global 
isa-fdc.driveB=none0
+check_floppy_qtree -fda "$TEST_IMG" -drive if=none,file="$TEST_IMG.2" -global 
isa-fdc.driveA=none0
+check_floppy_qtree -fdb "$TEST_IMG" -drive if=none,file="$TEST_IMG.2" -global 
isa-fdc.driveB=none0
 
 echo
 echo
 echo === Mixing -fdX and -device ===
 
 # Working
-check_floppy_qtree -fda "$TEST_IMG" -drive if=none,file="$TEST_IMG" -device 
floppy,drive=none0
-check_floppy_qtree -fda "$TEST_IMG" -drive if=none,file="$TEST_IMG" -device 
floppy,drive=none0,unit=1
+check_floppy_qtree -fda "$TEST_IMG" -drive if=none,file="$TEST_IMG.2" -device 
floppy,drive=none0
+check_floppy_qtree -fda "$TEST_IMG" -drive if=none,file="$TEST_IMG.2" -device 
floppy,drive=none0,unit=1
 
-check_floppy_qtree -fdb "$TEST_IMG" -drive if=none,file="$TEST_IMG" -device 
floppy,drive=none0
-check_floppy_qtree -fdb "$TEST_IMG" -drive if=none,file="$TEST_IMG" -device 
floppy,drive=none0,unit=0
+check_floppy_qtree -fdb "$TEST_IMG" -drive if=none,file="$TEST_IMG.2" -device 
floppy,drive=none0
+check_floppy_qtree -fdb "$TEST_IMG" -drive if=none,file="$TEST_IMG.2" -device 
floppy,drive=none0,unit=0
 
 # Conflicting
-check_floppy_qtree -fda "$TEST_IMG" -drive if=none,file="$TEST_IMG" -device 
floppy,drive=none0,unit=0
-check_floppy_qtree -fdb "$TEST_IMG" -drive if=none,file="$TEST_IMG" -device 
floppy,drive=none0,unit=1
+check_floppy_qtree -fda "$TEST_IMG" -drive if=none,file="$TEST_IMG.2" -device 
floppy,drive=none0,unit=0
+check_floppy_qtree -fdb "$TEST_IMG" -drive if=none,file="$TEST_IMG.2" -device 
floppy,drive=none0,unit=1
 
 echo
 echo
 echo === Mixing -drive and -device ===
 
 # Working
-check_floppy_qtree -drive if=floppy,file="$TEST_IMG" -drive 
if=none,file="$TEST_IMG" -device floppy,drive=none0
-check_floppy_qtree -drive if=floppy,file="$TEST_IMG" -drive 

[Qemu-devel] [PATCH v15 21/21] qemu-iotests: Add test case 153 for image locking

2017-04-25 Thread Fam Zheng
Signed-off-by: Fam Zheng 
---
 tests/qemu-iotests/153 | 220 +
 tests/qemu-iotests/153.out | 390 +
 tests/qemu-iotests/group   |   1 +
 3 files changed, 611 insertions(+)
 create mode 100755 tests/qemu-iotests/153
 create mode 100644 tests/qemu-iotests/153.out

diff --git a/tests/qemu-iotests/153 b/tests/qemu-iotests/153
new file mode 100755
index 000..7501efa
--- /dev/null
+++ b/tests/qemu-iotests/153
@@ -0,0 +1,220 @@
+#!/bin/bash
+#
+# Test image locking
+#
+# Copyright 2016, 2017 Red Hat, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program.  If not, see .
+#
+
+# creator
+owner=f...@redhat.com
+
+seq="$(basename $0)"
+echo "QA output created by $seq"
+
+here="$PWD"
+tmp=/tmp/$$
+status=1   # failure is the default!
+
+_cleanup()
+{
+_cleanup_test_img
+rm -f "${TEST_IMG}.base"
+rm -f "${TEST_IMG}.convert"
+rm -f "${TEST_IMG}.a"
+rm -f "${TEST_IMG}.b"
+rm -f "${TEST_IMG}.lnk"
+}
+trap "_cleanup; exit \$status" 0 1 2 3 15
+
+# get standard environment, filters and checks
+. ./common.rc
+. ./common.filter
+. ./common.qemu
+
+_supported_fmt qcow2
+_supported_proto file
+_supported_os Linux
+
+size=32M
+
+_run_cmd()
+{
+echo
+(echo "$@"; "$@" 2>&1 1>/dev/null) | _filter_testdir
+}
+
+function _do_run_qemu()
+{
+(
+if ! test -t 0; then
+while read cmd; do
+echo $cmd
+done
+fi
+echo quit
+) | $QEMU -nographic -monitor stdio -serial none "$@" 1>/dev/null
+}
+
+function _run_qemu_with_images()
+{
+_do_run_qemu \
+$(for i in $@; do echo "-drive if=none,file=$i"; done) 2>&1 \
+| _filter_testdir | _filter_qemu
+}
+
+echo "== readonly=off,force-share=on should be rejected =="
+_run_qemu_with_images null-co://,readonly=off,force-share=on
+
+for opts1 in "" "read-only=on" "read-only=on,force-share=on"; do
+echo
+echo "== Creating base image =="
+TEST_IMG="${TEST_IMG}.base" _make_test_img $size
+
+echo
+echo "== Creating test image =="
+$QEMU_IMG create -f $IMGFMT "${TEST_IMG}" -b ${TEST_IMG}.base | 
_filter_img_create
+
+echo
+echo "== Launching QEMU, opts: '$opts1' =="
+_launch_qemu -drive file="${TEST_IMG}",if=none,$opts1
+h=$QEMU_HANDLE
+
+for opts2 in "" "read-only=on" "read-only=on,force-share=on"; do
+echo
+echo "== Launching another QEMU, opts: '$opts2' =="
+echo "quit" | \
+$QEMU -nographic -monitor stdio \
+-drive file="${TEST_IMG}",if=none,$opts2 2>&1 1>/dev/null | \
+_filter_testdir | _filter_qemu
+done
+
+for L in "" "-U"; do
+
+echo
+echo "== Running utility commands $L =="
+_run_cmd $QEMU_IO $L -c "read 0 512" "${TEST_IMG}"
+_run_cmd $QEMU_IO $L -r -c "read 0 512" "${TEST_IMG}"
+_run_cmd $QEMU_IO -c "open $L ${TEST_IMG}" -c "read 0 512"
+_run_cmd $QEMU_IO -c "open -r $L ${TEST_IMG}" -c "read 0 512"
+_run_cmd $QEMU_IMG info$L "${TEST_IMG}"
+_run_cmd $QEMU_IMG check   $L "${TEST_IMG}"
+_run_cmd $QEMU_IMG compare $L "${TEST_IMG}" "${TEST_IMG}"
+_run_cmd $QEMU_IMG map $L "${TEST_IMG}"
+_run_cmd $QEMU_IMG amend -o "" $L "${TEST_IMG}"
+_run_cmd $QEMU_IMG commit  $L "${TEST_IMG}"
+_run_cmd $QEMU_IMG resize  $L "${TEST_IMG}" $size
+_run_cmd $QEMU_IMG rebase  $L "${TEST_IMG}" -b "${TEST_IMG}.base"
+_run_cmd $QEMU_IMG snapshot -l $L "${TEST_IMG}"
+_run_cmd $QEMU_IMG convert $L "${TEST_IMG}" "${TEST_IMG}.convert"
+_run_cmd $QEMU_IMG dd  $L if="${TEST_IMG}" 
of="${TEST_IMG}.convert" bs=512 count=1
+_run_cmd $QEMU_IMG bench   $L -c 1 "${TEST_IMG}"
+_run_cmd $QEMU_IMG bench   $L -w -c 1 "${TEST_IMG}"
+done
+_send_qemu_cmd $h "{ 'execute': 'quit', }" ""
+echo
+echo "Round done"
+_cleanup_qemu
+done
+
+for opt1 in $test_opts; do
+for opt2 in $test_opts; do
+echo
+echo "== Two devices with the same image ($opt1 - $opt2) =="
+_run_qemu_with_images "${TEST_IMG},$opt1" "${TEST_IMG},$opt2"
+done
+done
+
+echo "== Creating ${TEST_IMG}.[abc] =="
+(
+$QEMU_IMG create -f qcow2 "${TEST_IMG}.a" -b "${TEST_IMG}"
+$QEMU_IMG create -f qcow2 "${TEST_IMG}.b" -b 

[Qemu-devel] [PATCH v15 11/21] iotests: 085: Avoid image locking conflict

2017-04-25 Thread Fam Zheng
In the case where we test the expected error when a blockdev-snapshot
target already has a backing image, the backing chain is opened multiple
times. This will be a problem when we use image locking, so use a
different backing file that is not already open.

Signed-off-by: Fam Zheng 
---
 tests/qemu-iotests/085 | 34 --
 tests/qemu-iotests/085.out |  3 ++-
 2 files changed, 22 insertions(+), 15 deletions(-)

diff --git a/tests/qemu-iotests/085 b/tests/qemu-iotests/085
index c53e97f..cc6efd8 100755
--- a/tests/qemu-iotests/085
+++ b/tests/qemu-iotests/085
@@ -45,7 +45,7 @@ _cleanup()
 rm -f "${TEST_DIR}/${i}-${snapshot_virt0}"
 rm -f "${TEST_DIR}/${i}-${snapshot_virt1}"
 done
-rm -f "${TEST_IMG}.1" "${TEST_IMG}.2"
+rm -f "${TEST_IMG}" "${TEST_IMG}.1" "${TEST_IMG}.2" "${TEST_IMG}.base"
 
 }
 trap "_cleanup; exit \$status" 0 1 2 3 15
@@ -87,24 +87,26 @@ function create_group_snapshot()
 }
 
 # ${1}: unique identifier for the snapshot filename
-# ${2}: true: open backing images; false: don't open them (default)
+# ${2}: extra_params to the blockdev-add command
+# ${3}: filename
+function do_blockdev_add()
+{
+cmd="{ 'execute': 'blockdev-add', 'arguments':
+   { 'driver': 'qcow2', 'node-name': 'snap_${1}', ${2}
+ 'file':
+ { 'driver': 'file', 'filename': '${3}',
+   'node-name': 'file_${1}' } } }"
+_send_qemu_cmd $h "${cmd}" "return"
+}
+
+# ${1}: unique identifier for the snapshot filename
 function add_snapshot_image()
 {
-if [ "${2}" = "true" ]; then
-extra_params=""
-else
-extra_params="'backing': '', "
-fi
 base_image="${TEST_DIR}/$((${1}-1))-${snapshot_virt0}"
 snapshot_file="${TEST_DIR}/${1}-${snapshot_virt0}"
 _make_test_img -b "${base_image}" "$size"
 mv "${TEST_IMG}" "${snapshot_file}"
-cmd="{ 'execute': 'blockdev-add', 'arguments':
-   { 'driver': 'qcow2', 'node-name': 'snap_${1}', ${extra_params}
- 'file':
- { 'driver': 'file', 'filename': '${snapshot_file}',
-   'node-name': 'file_${1}' } } }"
-_send_qemu_cmd $h "${cmd}" "return"
+do_blockdev_add "$1" "'backing': '', " "${snapshot_file}"
 }
 
 # ${1}: unique identifier for the snapshot filename
@@ -222,7 +224,11 @@ echo === Invalid command - snapshot node has a backing 
image ===
 echo
 
 SNAPSHOTS=$((${SNAPSHOTS}+1))
-add_snapshot_image ${SNAPSHOTS} true
+
+_make_test_img "$size"
+mv "${TEST_IMG}" "${TEST_IMG}.base"
+_make_test_img -b "${TEST_IMG}.base" "$size"
+do_blockdev_add ${SNAPSHOTS} "" "${TEST_IMG}"
 blockdev_snapshot ${SNAPSHOTS} error
 
 echo
diff --git a/tests/qemu-iotests/085.out b/tests/qemu-iotests/085.out
index 182acb4..65b0f68 100644
--- a/tests/qemu-iotests/085.out
+++ b/tests/qemu-iotests/085.out
@@ -78,7 +78,8 @@ Formatting 'TEST_DIR/t.IMGFMT', fmt=IMGFMT size=134217728 
backing_file=TEST_DIR/
 
 === Invalid command - snapshot node has a backing image ===
 
-Formatting 'TEST_DIR/t.IMGFMT', fmt=IMGFMT size=134217728 
backing_file=TEST_DIR/12-snapshot-v0.IMGFMT
+Formatting 'TEST_DIR/t.IMGFMT', fmt=IMGFMT size=134217728
+Formatting 'TEST_DIR/t.IMGFMT', fmt=IMGFMT size=134217728 
backing_file=TEST_DIR/t.IMGFMT.base
 {"return": {}}
 {"error": {"class": "GenericError", "desc": "The snapshot already has a 
backing image"}}
 
-- 
2.9.3




[Qemu-devel] [PATCH v15 16/21] file-posix: Add 'locking' option

2017-04-25 Thread Fam Zheng
Making this option available even before implementing it will let
converting tests easier: in coming patches they can specify the option
already when necessary, before we actually write code to lock the
images.

Signed-off-by: Fam Zheng 
---
 block/file-posix.c | 5 +
 1 file changed, 5 insertions(+)

diff --git a/block/file-posix.c b/block/file-posix.c
index ade71db..2114720 100644
--- a/block/file-posix.c
+++ b/block/file-posix.c
@@ -392,6 +392,11 @@ static QemuOptsList raw_runtime_opts = {
 .type = QEMU_OPT_STRING,
 .help = "host AIO implementation (threads, native)",
 },
+{
+.name = "locking",
+.type = QEMU_OPT_BOOL,
+.help = "lock the file",
+},
 { /* end of list */ }
 },
 };
-- 
2.9.3




[Qemu-devel] [PATCH v15 09/21] iotests: 046: Prepare for image locking

2017-04-25 Thread Fam Zheng
The qemu-img info command is executed while VM is running, add -U option
to avoid the image locking error.

Signed-off-by: Fam Zheng 
---
 tests/qemu-iotests/046 | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/tests/qemu-iotests/046 b/tests/qemu-iotests/046
index e528b67..f2ebecf 100755
--- a/tests/qemu-iotests/046
+++ b/tests/qemu-iotests/046
@@ -192,7 +192,7 @@ echo "== Verify image content =="
 
 function verify_io()
 {
-if ($QEMU_IMG info -f "$IMGFMT" "$TEST_IMG" | grep "compat: 0.10" > 
/dev/null); then
+if ($QEMU_IMG info -U -f "$IMGFMT" "$TEST_IMG" | grep "compat: 0.10" > 
/dev/null); then
 # For v2 images, discarded clusters are read from the backing file
 # Keep the variable empty so that the backing file value can be used as
 # the default below
-- 
2.9.3




[Qemu-devel] [PATCH v15 19/21] osdep: Add qemu_lock_fd and qemu_unlock_fd

2017-04-25 Thread Fam Zheng
They are wrappers of POSIX fcntl "file private locking", with a
convenient "try lock" wrapper implemented with F_OFD_GETLK.

Signed-off-by: Fam Zheng 
Reviewed-by: Max Reitz 
---
 include/qemu/osdep.h |  3 +++
 util/osdep.c | 48 
 2 files changed, 51 insertions(+)

diff --git a/include/qemu/osdep.h b/include/qemu/osdep.h
index 122ff06..1c9f5e2 100644
--- a/include/qemu/osdep.h
+++ b/include/qemu/osdep.h
@@ -341,6 +341,9 @@ int qemu_close(int fd);
 #ifndef _WIN32
 int qemu_dup(int fd);
 #endif
+int qemu_lock_fd(int fd, int64_t start, int64_t len, bool exclusive);
+int qemu_unlock_fd(int fd, int64_t start, int64_t len);
+int qemu_lock_fd_test(int fd, int64_t start, int64_t len, bool exclusive);
 
 #if defined(__HAIKU__) && defined(__i386__)
 #define FMT_pid "%ld"
diff --git a/util/osdep.c b/util/osdep.c
index 06fb1cf..3de4a18 100644
--- a/util/osdep.c
+++ b/util/osdep.c
@@ -140,6 +140,54 @@ static int qemu_parse_fdset(const char *param)
 {
 return qemu_parse_fd(param);
 }
+
+static int qemu_lock_fcntl(int fd, int64_t start, int64_t len, int fl_type)
+{
+#ifdef F_OFD_SETLK
+int ret;
+struct flock fl = {
+.l_whence = SEEK_SET,
+.l_start  = start,
+.l_len= len,
+.l_type   = fl_type,
+};
+ret = fcntl(fd, F_OFD_SETLK, );
+return ret == -1 ? -errno : 0;
+#else
+return -ENOTSUP;
+#endif
+}
+
+int qemu_lock_fd(int fd, int64_t start, int64_t len, bool exclusive)
+{
+return qemu_lock_fcntl(fd, start, len, exclusive ? F_WRLCK : F_RDLCK);
+}
+
+int qemu_unlock_fd(int fd, int64_t start, int64_t len)
+{
+return qemu_lock_fcntl(fd, start, len, F_UNLCK);
+}
+
+int qemu_lock_fd_test(int fd, int64_t start, int64_t len, bool exclusive)
+{
+#ifdef F_OFD_SETLK
+int ret;
+struct flock fl = {
+.l_whence = SEEK_SET,
+.l_start  = start,
+.l_len= len,
+.l_type   = exclusive ? F_WRLCK : F_RDLCK,
+};
+ret = fcntl(fd, F_OFD_GETLK, );
+if (ret == -1) {
+return -errno;
+} else {
+return fl.l_type == F_UNLCK ? 0 : -EAGAIN;
+}
+#else
+return -ENOTSUP;
+#endif
+}
 #endif
 
 /*
-- 
2.9.3




[Qemu-devel] [PATCH v15 18/21] block: Reuse bs as backing hd for drive-backup sync=none

2017-04-25 Thread Fam Zheng
Signed-off-by: Fam Zheng 
---
 blockdev.c | 15 ++-
 1 file changed, 14 insertions(+), 1 deletion(-)

diff --git a/blockdev.c b/blockdev.c
index 4927914..4e04dec 100644
--- a/blockdev.c
+++ b/blockdev.c
@@ -3174,6 +3174,7 @@ static BlockJob *do_drive_backup(DriveBackup *backup, 
BlockJobTxn *txn,
 Error *local_err = NULL;
 int flags;
 int64_t size;
+bool set_backing_hd = false;
 
 if (!backup->has_speed) {
 backup->speed = 0;
@@ -3224,6 +3225,8 @@ static BlockJob *do_drive_backup(DriveBackup *backup, 
BlockJobTxn *txn,
 }
 if (backup->sync == MIRROR_SYNC_MODE_NONE) {
 source = bs;
+flags |= BDRV_O_NO_BACKING;
+set_backing_hd = true;
 }
 
 size = bdrv_getlength(bs);
@@ -3250,7 +3253,9 @@ static BlockJob *do_drive_backup(DriveBackup *backup, 
BlockJobTxn *txn,
 }
 
 if (backup->format) {
-options = qdict_new();
+if (!options) {
+options = qdict_new();
+}
 qdict_put(options, "driver", qstring_from_str(backup->format));
 }
 
@@ -3261,6 +3266,14 @@ static BlockJob *do_drive_backup(DriveBackup *backup, 
BlockJobTxn *txn,
 
 bdrv_set_aio_context(target_bs, aio_context);
 
+if (set_backing_hd) {
+bdrv_set_backing_hd(target_bs, source, _err);
+if (local_err) {
+bdrv_unref(target_bs);
+goto out;
+}
+}
+
 if (backup->has_bitmap) {
 bmap = bdrv_find_dirty_bitmap(bs, backup->bitmap);
 if (!bmap) {
-- 
2.9.3




[Qemu-devel] [PATCH v15 13/21] iotests: 091: Quit QEMU before checking image

2017-04-25 Thread Fam Zheng
Signed-off-by: Fam Zheng 
Reviewed-by: Max Reitz 
---
 tests/qemu-iotests/091 | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/tests/qemu-iotests/091 b/tests/qemu-iotests/091
index 32bbd56..10ac4a8 100755
--- a/tests/qemu-iotests/091
+++ b/tests/qemu-iotests/091
@@ -95,7 +95,9 @@ echo "vm2: qemu process running successfully"
 echo "vm2: flush io, and quit"
 _send_qemu_cmd $h2 'qemu-io disk flush' "(qemu)"
 _send_qemu_cmd $h2 'quit' ""
+_send_qemu_cmd $h1 'quit' ""
 
+wait
 echo "Check image pattern"
 ${QEMU_IO} -c "read -P 0x22 0 4M" "${TEST_IMG}" | _filter_testdir | 
_filter_qemu_io
 
-- 
2.9.3




[Qemu-devel] [PATCH v15 10/21] iotests: 055: Don't attach the target image already for drive-backup

2017-04-25 Thread Fam Zheng
Double attach is not a valid usage of the target image, drive-backup
will open the blockdev itself so skip the add_drive call in this case.

Signed-off-by: Fam Zheng 
Reviewed-by: Max Reitz 
---
 tests/qemu-iotests/055 | 32 ++--
 1 file changed, 18 insertions(+), 14 deletions(-)

diff --git a/tests/qemu-iotests/055 b/tests/qemu-iotests/055
index aafcd24..ba4da65 100755
--- a/tests/qemu-iotests/055
+++ b/tests/qemu-iotests/055
@@ -458,17 +458,18 @@ class TestDriveCompression(iotests.QMPTestCase):
 except OSError:
 pass
 
-def do_prepare_drives(self, fmt, args):
+def do_prepare_drives(self, fmt, args, attach_target):
 self.vm = iotests.VM().add_drive(test_img)
 
 qemu_img('create', '-f', fmt, blockdev_target_img,
  str(TestDriveCompression.image_len), *args)
-self.vm.add_drive(blockdev_target_img, format=fmt, interface="none")
+if attach_target:
+self.vm.add_drive(blockdev_target_img, format=fmt, 
interface="none")
 
 self.vm.launch()
 
-def do_test_compress_complete(self, cmd, format, **args):
-self.do_prepare_drives(format['type'], format['args'])
+def do_test_compress_complete(self, cmd, format, attach_target, **args):
+self.do_prepare_drives(format['type'], format['args'], attach_target)
 
 self.assert_no_active_block_jobs()
 
@@ -484,15 +485,16 @@ class TestDriveCompression(iotests.QMPTestCase):
 
 def test_complete_compress_drive_backup(self):
 for format in TestDriveCompression.fmt_supports_compression:
-self.do_test_compress_complete('drive-backup', format,
+self.do_test_compress_complete('drive-backup', format, False,
target=blockdev_target_img, 
mode='existing')
 
 def test_complete_compress_blockdev_backup(self):
 for format in TestDriveCompression.fmt_supports_compression:
-self.do_test_compress_complete('blockdev-backup', format, 
target='drive1')
+self.do_test_compress_complete('blockdev-backup', format, True,
+   target='drive1')
 
-def do_test_compress_cancel(self, cmd, format, **args):
-self.do_prepare_drives(format['type'], format['args'])
+def do_test_compress_cancel(self, cmd, format, attach_target, **args):
+self.do_prepare_drives(format['type'], format['args'], attach_target)
 
 self.assert_no_active_block_jobs()
 
@@ -506,15 +508,16 @@ class TestDriveCompression(iotests.QMPTestCase):
 
 def test_compress_cancel_drive_backup(self):
 for format in TestDriveCompression.fmt_supports_compression:
-self.do_test_compress_cancel('drive-backup', format,
+self.do_test_compress_cancel('drive-backup', format, False,
  target=blockdev_target_img, 
mode='existing')
 
 def test_compress_cancel_blockdev_backup(self):
for format in TestDriveCompression.fmt_supports_compression:
-self.do_test_compress_cancel('blockdev-backup', format, 
target='drive1')
+self.do_test_compress_cancel('blockdev-backup', format, True,
+ target='drive1')
 
-def do_test_compress_pause(self, cmd, format, **args):
-self.do_prepare_drives(format['type'], format['args'])
+def do_test_compress_pause(self, cmd, format, attach_target, **args):
+self.do_prepare_drives(format['type'], format['args'], attach_target)
 
 self.assert_no_active_block_jobs()
 
@@ -546,12 +549,13 @@ class TestDriveCompression(iotests.QMPTestCase):
 
 def test_compress_pause_drive_backup(self):
 for format in TestDriveCompression.fmt_supports_compression:
-self.do_test_compress_pause('drive-backup', format,
+self.do_test_compress_pause('drive-backup', format, False,
 target=blockdev_target_img, 
mode='existing')
 
 def test_compress_pause_blockdev_backup(self):
 for format in TestDriveCompression.fmt_supports_compression:
-self.do_test_compress_pause('blockdev-backup', format, 
target='drive1')
+self.do_test_compress_pause('blockdev-backup', format, True,
+target='drive1')
 
 if __name__ == '__main__':
 iotests.main(supported_fmts=['raw', 'qcow2'])
-- 
2.9.3




[Qemu-devel] [PATCH v15 17/21] tests: Disable image lock in test-replication

2017-04-25 Thread Fam Zheng
The COLO block replication architecture requires one disk to be shared
between primary and secondary, in the test both processes use posix file
protocol (instead of over NBD) so it is affected by image locking.
Disable the lock.

Signed-off-by: Fam Zheng 
---
 tests/test-replication.c | 9 +++--
 1 file changed, 7 insertions(+), 2 deletions(-)

diff --git a/tests/test-replication.c b/tests/test-replication.c
index fac2da3..e1c4235 100644
--- a/tests/test-replication.c
+++ b/tests/test-replication.c
@@ -179,7 +179,8 @@ static BlockBackend *start_primary(void)
 char *cmdline;
 
 cmdline = g_strdup_printf("driver=replication,mode=primary,node-name=xxx,"
-  "file.driver=qcow2,file.file.filename=%s"
+  "file.driver=qcow2,file.file.filename=%s,"
+  "file.file.locking=off"
   , p_local_disk);
 opts = qemu_opts_parse_noisily(_drive_opts, cmdline, false);
 g_free(cmdline);
@@ -310,7 +311,9 @@ static BlockBackend *start_secondary(void)
 Error *local_err = NULL;
 
 /* add s_local_disk and forge S_LOCAL_DISK_ID */
-cmdline = g_strdup_printf("file.filename=%s,driver=qcow2", s_local_disk);
+cmdline = g_strdup_printf("file.filename=%s,driver=qcow2,"
+  "file.locking=off",
+  s_local_disk);
 opts = qemu_opts_parse_noisily(_drive_opts, cmdline, false);
 g_free(cmdline);
 
@@ -331,8 +334,10 @@ static BlockBackend *start_secondary(void)
 /* add S_(ACTIVE/HIDDEN)_DISK and forge S_ID */
 cmdline = g_strdup_printf("driver=replication,mode=secondary,top-id=%s,"
   "file.driver=qcow2,file.file.filename=%s,"
+  "file.file.locking=off,"
   "file.backing.driver=qcow2,"
   "file.backing.file.filename=%s,"
+  "file.backing.file.locking=off,"
   "file.backing.backing=%s"
   , S_ID, s_active_disk, s_hidden_disk
   , S_LOCAL_DISK_ID);
-- 
2.9.3




[Qemu-devel] [PATCH v15 06/21] qemu-img: Update documentation for -U

2017-04-25 Thread Fam Zheng
Signed-off-by: Fam Zheng 
---
 qemu-img-cmds.hx | 36 ++--
 1 file changed, 18 insertions(+), 18 deletions(-)

diff --git a/qemu-img-cmds.hx b/qemu-img-cmds.hx
index 8ac7822..ae309c0 100644
--- a/qemu-img-cmds.hx
+++ b/qemu-img-cmds.hx
@@ -10,15 +10,15 @@ STEXI
 ETEXI
 
 DEF("bench", img_bench,
-"bench [-c count] [-d depth] [-f fmt] [--flush-interval=flush_interval] 
[-n] [--no-drain] [-o offset] [--pattern=pattern] [-q] [-s buffer_size] [-S 
step_size] [-t cache] [-w] filename")
+"bench [-c count] [-d depth] [-f fmt] [--flush-interval=flush_interval] 
[-n] [--no-drain] [-o offset] [--pattern=pattern] [-q] [-s buffer_size] [-S 
step_size] [-t cache] [-w] [-U] filename")
 STEXI
-@item bench [-c @var{count}] [-d @var{depth}] [-f @var{fmt}] 
[--flush-interval=@var{flush_interval}] [-n] [--no-drain] [-o @var{offset}] 
[--pattern=@var{pattern}] [-q] [-s @var{buffer_size}] [-S @var{step_size}] [-t 
@var{cache}] [-w] @var{filename}
+@item bench [-c @var{count}] [-d @var{depth}] [-f @var{fmt}] 
[--flush-interval=@var{flush_interval}] [-n] [--no-drain] [-o @var{offset}] 
[--pattern=@var{pattern}] [-q] [-s @var{buffer_size}] [-S @var{step_size}] [-t 
@var{cache}] [-w] [-U] @var{filename}
 ETEXI
 
 DEF("check", img_check,
-"check [-q] [--object objectdef] [--image-opts] [-f fmt] [--output=ofmt] 
[-r [leaks | all]] [-T src_cache] filename")
+"check [-q] [--object objectdef] [--image-opts] [-f fmt] [--output=ofmt] 
[-r [leaks | all]] [-T src_cache] [-U] filename")
 STEXI
-@item check [--object @var{objectdef}] [--image-opts] [-q] [-f @var{fmt}] 
[--output=@var{ofmt}] [-r [leaks | all]] [-T @var{src_cache}] @var{filename}
+@item check [--object @var{objectdef}] [--image-opts] [-q] [-f @var{fmt}] 
[--output=@var{ofmt}] [-r [leaks | all]] [-T @var{src_cache}] [-U] 
@var{filename}
 ETEXI
 
 DEF("create", img_create,
@@ -34,45 +34,45 @@ STEXI
 ETEXI
 
 DEF("compare", img_compare,
-"compare [--object objectdef] [--image-opts] [-f fmt] [-F fmt] [-T 
src_cache] [-p] [-q] [-s] filename1 filename2")
+"compare [--object objectdef] [--image-opts] [-f fmt] [-F fmt] [-T 
src_cache] [-p] [-q] [-s] [-U] filename1 filename2")
 STEXI
-@item compare [--object @var{objectdef}] [--image-opts] [-f @var{fmt}] [-F 
@var{fmt}] [-T @var{src_cache}] [-p] [-q] [-s] @var{filename1} @var{filename2}
+@item compare [--object @var{objectdef}] [--image-opts] [-f @var{fmt}] [-F 
@var{fmt}] [-T @var{src_cache}] [-p] [-q] [-s] [-U] @var{filename1} 
@var{filename2}
 ETEXI
 
 DEF("convert", img_convert,
-"convert [--object objectdef] [--image-opts] [-c] [-p] [-q] [-n] [-f fmt] 
[-t cache] [-T src_cache] [-O output_fmt] [-o options] [-s snapshot_id_or_name] 
[-l snapshot_param] [-S sparse_size] [-m num_coroutines] [-W] filename 
[filename2 [...]] output_filename")
+"convert [--object objectdef] [--image-opts] [-c] [-p] [-q] [-n] [-f fmt] 
[-t cache] [-T src_cache] [-O output_fmt] [-o options] [-s snapshot_id_or_name] 
[-l snapshot_param] [-S sparse_size] [-m num_coroutines] [-W] [-U] filename 
[filename2 [...]] output_filename")
 STEXI
-@item convert [--object @var{objectdef}] [--image-opts] [-c] [-p] [-q] [-n] 
[-f @var{fmt}] [-t @var{cache}] [-T @var{src_cache}] [-O @var{output_fmt}] [-o 
@var{options}] [-s @var{snapshot_id_or_name}] [-l @var{snapshot_param}] [-S 
@var{sparse_size}] [-m @var{num_coroutines}] [-W] @var{filename} 
[@var{filename2} [...]] @var{output_filename}
+@item convert [--object @var{objectdef}] [--image-opts] [-c] [-p] [-q] [-n] 
[-f @var{fmt}] [-t @var{cache}] [-T @var{src_cache}] [-O @var{output_fmt}] [-o 
@var{options}] [-s @var{snapshot_id_or_name}] [-l @var{snapshot_param}] [-S 
@var{sparse_size}] [-m @var{num_coroutines}] [-W] [-U] @var{filename} 
[@var{filename2} [...]] @var{output_filename}
 ETEXI
 
 DEF("dd", img_dd,
-"dd [--image-opts] [-f fmt] [-O output_fmt] [bs=block_size] [count=blocks] 
[skip=blocks] if=input of=output")
+"dd [--image-opts] [-U] [-f fmt] [-O output_fmt] [bs=block_size] 
[count=blocks] [skip=blocks] if=input of=output")
 STEXI
-@item dd [--image-opts] [-f @var{fmt}] [-O @var{output_fmt}] 
[bs=@var{block_size}] [count=@var{blocks}] [skip=@var{blocks}] if=@var{input} 
of=@var{output}
+@item dd [--image-opts] [-U] [-f @var{fmt}] [-O @var{output_fmt}] 
[bs=@var{block_size}] [count=@var{blocks}] [skip=@var{blocks}] if=@var{input} 
of=@var{output}
 ETEXI
 
 DEF("info", img_info,
-"info [--object objectdef] [--image-opts] [-f fmt] [--output=ofmt] 
[--backing-chain] filename")
+"info [--object objectdef] [--image-opts] [-f fmt] [--output=ofmt] 
[--backing-chain] [-U] filename")
 STEXI
-@item info [--object @var{objectdef}] [--image-opts] [-f @var{fmt}] 
[--output=@var{ofmt}] [--backing-chain] @var{filename}
+@item info [--object @var{objectdef}] [--image-opts] [-f @var{fmt}] 
[--output=@var{ofmt}] [--backing-chain] [-U] @var{filename}
 ETEXI
 
 DEF("map", img_map,
-"map [--object objectdef] [--image-opts] [-f fmt] 

[Qemu-devel] [PATCH v15 12/21] iotests: 087: Don't attach test image twice

2017-04-25 Thread Fam Zheng
The test scenario doesn't require the same image, instead it focuses on
the duplicated node-name, so use null-co to avoid locking conflict.

Reviewed-by: Max Reitz 
Signed-off-by: Fam Zheng 
---
 tests/qemu-iotests/087 | 6 ++
 1 file changed, 2 insertions(+), 4 deletions(-)

diff --git a/tests/qemu-iotests/087 b/tests/qemu-iotests/087
index 9de57dd..6d52f7d 100755
--- a/tests/qemu-iotests/087
+++ b/tests/qemu-iotests/087
@@ -82,8 +82,7 @@ run_qemu -drive 
driver=$IMGFMT,id=disk,node-name=test-node,file="$TEST_IMG" <

[Qemu-devel] [PATCH v15 08/21] iotests: 030: Prepare for image locking

2017-04-25 Thread Fam Zheng
qemu-img and qemu-io commands when guest is running need "-U" option,
add it.

Signed-off-by: Fam Zheng 
---
 tests/qemu-iotests/030 | 18 +-
 1 file changed, 9 insertions(+), 9 deletions(-)

diff --git a/tests/qemu-iotests/030 b/tests/qemu-iotests/030
index 0d472d5..e00c11b 100755
--- a/tests/qemu-iotests/030
+++ b/tests/qemu-iotests/030
@@ -63,8 +63,8 @@ class TestSingleDrive(iotests.QMPTestCase):
 def test_stream_intermediate(self):
 self.assert_no_active_block_jobs()
 
-self.assertNotEqual(qemu_io('-f', 'raw', '-c', 'map', backing_img),
-qemu_io('-f', iotests.imgfmt, '-c', 'map', 
mid_img),
+self.assertNotEqual(qemu_io('-f', 'raw', '-rU', '-c', 'map', 
backing_img),
+qemu_io('-f', iotests.imgfmt, '-rU', '-c', 'map', 
mid_img),
 'image file map matches backing file before 
streaming')
 
 result = self.vm.qmp('block-stream', device='mid', job_id='stream-mid')
@@ -114,7 +114,7 @@ class TestSingleDrive(iotests.QMPTestCase):
 self.assert_no_active_block_jobs()
 
 # The image map is empty before the operation
-empty_map = qemu_io('-f', iotests.imgfmt, '-c', 'map', test_img)
+empty_map = qemu_io('-f', iotests.imgfmt, '-rU', '-c', 'map', test_img)
 
 # This is a no-op: no data should ever be copied from the base image
 result = self.vm.qmp('block-stream', device='drive0', base=mid_img)
@@ -197,8 +197,8 @@ class TestParallelOps(iotests.QMPTestCase):
 
 # Check that the maps don't match before the streaming operations
 for i in range(2, self.num_imgs, 2):
-self.assertNotEqual(qemu_io('-f', iotests.imgfmt, '-c', 'map', 
self.imgs[i]),
-qemu_io('-f', iotests.imgfmt, '-c', 'map', 
self.imgs[i-1]),
+self.assertNotEqual(qemu_io('-f', iotests.imgfmt, '-rU', '-c', 
'map', self.imgs[i]),
+qemu_io('-f', iotests.imgfmt, '-rU', '-c', 
'map', self.imgs[i-1]),
 'image file map matches backing file before 
streaming')
 
 # Create all streaming jobs
@@ -351,8 +351,8 @@ class TestParallelOps(iotests.QMPTestCase):
 def test_stream_base_node_name(self):
 self.assert_no_active_block_jobs()
 
-self.assertNotEqual(qemu_io('-f', iotests.imgfmt, '-c', 'map', 
self.imgs[4]),
-qemu_io('-f', iotests.imgfmt, '-c', 'map', 
self.imgs[3]),
+self.assertNotEqual(qemu_io('-f', iotests.imgfmt, '-rU', '-c', 'map', 
self.imgs[4]),
+qemu_io('-f', iotests.imgfmt, '-rU', '-c', 'map', 
self.imgs[3]),
 'image file map matches backing file before 
streaming')
 
 # Error: the base node does not exist
@@ -422,8 +422,8 @@ class TestQuorum(iotests.QMPTestCase):
 if not iotests.supports_quorum():
 return
 
-self.assertNotEqual(qemu_io('-f', iotests.imgfmt, '-c', 'map', 
self.children[0]),
-qemu_io('-f', iotests.imgfmt, '-c', 'map', 
self.backing[0]),
+self.assertNotEqual(qemu_io('-f', iotests.imgfmt, '-rU', '-c', 'map', 
self.children[0]),
+qemu_io('-f', iotests.imgfmt, '-rU', '-c', 'map', 
self.backing[0]),
 'image file map matches backing file before 
streaming')
 
 self.assert_no_active_block_jobs()
-- 
2.9.3




[Qemu-devel] [PATCH v15 15/21] tests: Use null-co:// instead of /dev/null as the dummy image

2017-04-25 Thread Fam Zheng
Signed-off-by: Fam Zheng 
Reviewed-by: Max Reitz 
---
 tests/drive_del-test.c| 2 +-
 tests/nvme-test.c | 2 +-
 tests/usb-hcd-uhci-test.c | 2 +-
 tests/usb-hcd-xhci-test.c | 2 +-
 tests/virtio-blk-test.c   | 2 +-
 tests/virtio-scsi-test.c  | 5 +++--
 6 files changed, 8 insertions(+), 7 deletions(-)

diff --git a/tests/drive_del-test.c b/tests/drive_del-test.c
index 121b9c9..2175139 100644
--- a/tests/drive_del-test.c
+++ b/tests/drive_del-test.c
@@ -92,7 +92,7 @@ static void test_after_failed_device_add(void)
 static void test_drive_del_device_del(void)
 {
 /* Start with a drive used by a device that unplugs instantaneously */
-qtest_start("-drive if=none,id=drive0,file=/dev/null,format=raw"
+qtest_start("-drive if=none,id=drive0,file=null-co://,format=raw"
 " -device virtio-scsi-pci"
 " -device scsi-hd,drive=drive0,id=dev0");
 
diff --git a/tests/nvme-test.c b/tests/nvme-test.c
index c8bece4..7674a44 100644
--- a/tests/nvme-test.c
+++ b/tests/nvme-test.c
@@ -22,7 +22,7 @@ int main(int argc, char **argv)
 g_test_init(, , NULL);
 qtest_add_func("/nvme/nop", nop);
 
-qtest_start("-drive id=drv0,if=none,file=/dev/null,format=raw "
+qtest_start("-drive id=drv0,if=none,file=null-co://,format=raw "
 "-device nvme,drive=drv0,serial=foo");
 ret = g_test_run();
 
diff --git a/tests/usb-hcd-uhci-test.c b/tests/usb-hcd-uhci-test.c
index f25bae5..5b500fe 100644
--- a/tests/usb-hcd-uhci-test.c
+++ b/tests/usb-hcd-uhci-test.c
@@ -79,7 +79,7 @@ int main(int argc, char **argv)
 {
 const char *arch = qtest_get_arch();
 const char *cmd = "-device piix3-usb-uhci,id=uhci,addr=1d.0"
-  " -drive id=drive0,if=none,file=/dev/null,format=raw"
+  " -drive id=drive0,if=none,file=null-co://,format=raw"
   " -device usb-tablet,bus=uhci.0,port=1";
 int ret;
 
diff --git a/tests/usb-hcd-xhci-test.c b/tests/usb-hcd-xhci-test.c
index 22513e9..031764d 100644
--- a/tests/usb-hcd-xhci-test.c
+++ b/tests/usb-hcd-xhci-test.c
@@ -89,7 +89,7 @@ int main(int argc, char **argv)
 qtest_add_func("/xhci/pci/hotplug/usb-uas", test_usb_uas_hotplug);
 
 qtest_start("-device nec-usb-xhci,id=xhci"
-" -drive id=drive0,if=none,file=/dev/null,format=raw");
+" -drive id=drive0,if=none,file=null-co://,format=raw");
 ret = g_test_run();
 qtest_end();
 
diff --git a/tests/virtio-blk-test.c b/tests/virtio-blk-test.c
index 1eee95d..fd2078c 100644
--- a/tests/virtio-blk-test.c
+++ b/tests/virtio-blk-test.c
@@ -63,7 +63,7 @@ static QOSState *pci_test_start(void)
 const char *arch = qtest_get_arch();
 char *tmp_path;
 const char *cmd = "-drive if=none,id=drive0,file=%s,format=raw "
-  "-drive if=none,id=drive1,file=/dev/null,format=raw "
+  "-drive if=none,id=drive1,file=null-co://,format=raw "
   "-device virtio-blk-pci,id=drv0,drive=drive0,"
   "addr=%x.%x";
 
diff --git a/tests/virtio-scsi-test.c b/tests/virtio-scsi-test.c
index 0eabd56..8b0f77a 100644
--- a/tests/virtio-scsi-test.c
+++ b/tests/virtio-scsi-test.c
@@ -35,7 +35,7 @@ typedef struct {
 static QOSState *qvirtio_scsi_start(const char *extra_opts)
 {
 const char *arch = qtest_get_arch();
-const char *cmd = "-drive id=drv0,if=none,file=/dev/null,format=raw "
+const char *cmd = "-drive id=drv0,if=none,file=null-co://,format=raw "
   "-device virtio-scsi-pci,id=vs0 "
   "-device scsi-hd,bus=vs0.0,drive=drv0 %s";
 
@@ -195,7 +195,8 @@ static void hotplug(void)
 QDict *response;
 QOSState *qs;
 
-qs = qvirtio_scsi_start("-drive 
id=drv1,if=none,file=/dev/null,format=raw");
+qs = qvirtio_scsi_start(
+"-drive id=drv1,if=none,file=null-co://,format=raw");
 response = qmp("{\"execute\": \"device_add\","
" \"arguments\": {"
"   \"driver\": \"scsi-hd\","
-- 
2.9.3




[Qemu-devel] [PATCH v15 07/21] qemu-io: Add --force-share option

2017-04-25 Thread Fam Zheng
Add --force-share/-U to program options and -U to open subcommand.

Signed-off-by: Fam Zheng 
---
 qemu-io.c | 42 ++
 1 file changed, 34 insertions(+), 8 deletions(-)

diff --git a/qemu-io.c b/qemu-io.c
index 427cbae..cf4b876 100644
--- a/qemu-io.c
+++ b/qemu-io.c
@@ -20,6 +20,7 @@
 #include "qemu/readline.h"
 #include "qemu/log.h"
 #include "qapi/qmp/qstring.h"
+#include "qapi/qmp/qbool.h"
 #include "qom/object_interfaces.h"
 #include "sysemu/block-backend.h"
 #include "block/block_int.h"
@@ -53,7 +54,8 @@ static const cmdinfo_t close_cmd = {
 .oneline= "close the current open file",
 };
 
-static int openfile(char *name, int flags, bool writethrough, QDict *opts)
+static int openfile(char *name, int flags, bool writethrough, bool force_share,
+QDict *opts)
 {
 Error *local_err = NULL;
 BlockDriverState *bs;
@@ -64,6 +66,18 @@ static int openfile(char *name, int flags, bool 
writethrough, QDict *opts)
 return 1;
 }
 
+if (force_share) {
+if (!opts) {
+opts = qdict_new();
+}
+if (qdict_haskey(opts, BDRV_OPT_FORCE_SHARE)
+&& !qdict_get_bool(opts, BDRV_OPT_FORCE_SHARE)) {
+error_report("-U conflicts with image options");
+QDECREF(opts);
+return 1;
+}
+qdict_put(opts, BDRV_OPT_FORCE_SHARE, qbool_from_bool(true));
+}
 qemuio_blk = blk_new_open(name, NULL, opts, flags, _err);
 if (!qemuio_blk) {
 error_reportf_err(local_err, "can't open%s%s: ",
@@ -108,6 +122,7 @@ static void open_help(void)
 " -r, -- open file read-only\n"
 " -s, -- use snapshot file\n"
 " -n, -- disable host cache, short for -t none\n"
+" -U, -- force shared permissions\n"
 " -k, -- use kernel AIO implementation (on Linux only)\n"
 " -t, -- use the given cache mode for the image\n"
 " -d, -- use the given discard mode for the image\n"
@@ -124,7 +139,7 @@ static const cmdinfo_t open_cmd = {
 .argmin = 1,
 .argmax = -1,
 .flags  = CMD_NOFILE_OK,
-.args   = "[-rsnk] [-t cache] [-d discard] [-o options] [path]",
+.args   = "[-rsnkU] [-t cache] [-d discard] [-o options] [path]",
 .oneline= "open the file specified by path",
 .help   = open_help,
 };
@@ -147,8 +162,9 @@ static int open_f(BlockBackend *blk, int argc, char **argv)
 int c;
 QemuOpts *qopts;
 QDict *opts;
+bool force_share = false;
 
-while ((c = getopt(argc, argv, "snro:kt:d:")) != -1) {
+while ((c = getopt(argc, argv, "snro:kt:d:U")) != -1) {
 switch (c) {
 case 's':
 flags |= BDRV_O_SNAPSHOT;
@@ -188,6 +204,9 @@ static int open_f(BlockBackend *blk, int argc, char **argv)
 return 0;
 }
 break;
+case 'U':
+force_share = true;
+break;
 default:
 qemu_opts_reset(_opts);
 return qemuio_command_usage(_cmd);
@@ -211,9 +230,9 @@ static int open_f(BlockBackend *blk, int argc, char **argv)
 qemu_opts_reset(_opts);
 
 if (optind == argc - 1) {
-return openfile(argv[optind], flags, writethrough, opts);
+return openfile(argv[optind], flags, writethrough, force_share, opts);
 } else if (optind == argc) {
-return openfile(NULL, flags, writethrough, opts);
+return openfile(NULL, flags, writethrough, force_share, opts);
 } else {
 QDECREF(opts);
 return qemuio_command_usage(_cmd);
@@ -257,6 +276,7 @@ static void usage(const char *name)
 "  -T, --trace [[enable=]][,events=][,file=]\n"
 "   specify tracing options\n"
 "   see qemu-img(1) man page for full description\n"
+"  -U, --force-shareforce shared permissions\n"
 "  -h, --help   display this help and exit\n"
 "  -V, --versionoutput version information and exit\n"
 "\n"
@@ -436,7 +456,7 @@ static QemuOptsList file_opts = {
 int main(int argc, char **argv)
 {
 int readonly = 0;
-const char *sopt = "hVc:d:f:rsnmkt:T:";
+const char *sopt = "hVc:d:f:rsnmkt:T:U";
 const struct option lopt[] = {
 { "help", no_argument, NULL, 'h' },
 { "version", no_argument, NULL, 'V' },
@@ -452,6 +472,7 @@ int main(int argc, char **argv)
 { "trace", required_argument, NULL, 'T' },
 { "object", required_argument, NULL, OPTION_OBJECT },
 { "image-opts", no_argument, NULL, OPTION_IMAGE_OPTS },
+{ "force-share", no_argument, 0, 'U'},
 { NULL, 0, NULL, 0 }
 };
 int c;
@@ -462,6 +483,7 @@ int main(int argc, char **argv)
 QDict *opts = NULL;
 const char *format = NULL;
 char *trace_file = NULL;
+bool force_share = false;
 
 #ifdef CONFIG_POSIX
 signal(SIGPIPE, SIG_IGN);
@@ -524,6 +546,9 @@ int main(int argc, char **argv)
 case 'h':
 usage(progname);
 exit(0);
+case 'U':
+

[Qemu-devel] [PATCH v15 03/21] block: Add, parse and store "force-share" option

2017-04-25 Thread Fam Zheng
Signed-off-by: Fam Zheng 
---
 block.c   | 17 +
 include/block/block.h |  1 +
 include/block/block_int.h |  1 +
 qapi/block-core.json  |  3 +++
 4 files changed, 22 insertions(+)

diff --git a/block.c b/block.c
index fce77bf..9db39b6 100644
--- a/block.c
+++ b/block.c
@@ -763,6 +763,7 @@ static void bdrv_inherited_options(int *child_flags, QDict 
*child_options,
  * the parent. */
 qdict_copy_default(child_options, parent_options, BDRV_OPT_CACHE_DIRECT);
 qdict_copy_default(child_options, parent_options, BDRV_OPT_CACHE_NO_FLUSH);
+qdict_copy_default(child_options, parent_options, BDRV_OPT_FORCE_SHARE);
 
 /* Inherit the read-only option from the parent if it's not set */
 qdict_copy_default(child_options, parent_options, BDRV_OPT_READ_ONLY);
@@ -871,6 +872,7 @@ static void bdrv_backing_options(int *child_flags, QDict 
*child_options,
  * which is only applied on the top level (BlockBackend) */
 qdict_copy_default(child_options, parent_options, BDRV_OPT_CACHE_DIRECT);
 qdict_copy_default(child_options, parent_options, BDRV_OPT_CACHE_NO_FLUSH);
+qdict_copy_default(child_options, parent_options, BDRV_OPT_FORCE_SHARE);
 
 /* backing files always opened read-only */
 qdict_set_default_str(child_options, BDRV_OPT_READ_ONLY, "on");
@@ -1115,6 +1117,11 @@ QemuOptsList bdrv_runtime_opts = {
 .type = QEMU_OPT_STRING,
 .help = "discard operation (ignore/off, unmap/on)",
 },
+{
+.name = BDRV_OPT_FORCE_SHARE,
+.type = QEMU_OPT_BOOL,
+.help = "always accept other writers (default: off)",
+},
 { /* end of list */ }
 },
 };
@@ -1154,6 +1161,16 @@ static int bdrv_open_common(BlockDriverState *bs, 
BlockBackend *file,
 drv = bdrv_find_format(driver_name);
 assert(drv != NULL);
 
+bs->force_share = qemu_opt_get_bool(opts, BDRV_OPT_FORCE_SHARE, false);
+
+if (bs->force_share && (bs->open_flags & BDRV_O_RDWR)) {
+error_setg(errp,
+   BDRV_OPT_FORCE_SHARE
+   "=on can only be used with read-only images");
+ret = -EINVAL;
+goto fail_opts;
+}
+
 if (file != NULL) {
 filename = blk_bs(file)->filename;
 } else {
diff --git a/include/block/block.h b/include/block/block.h
index a798f10..feae379 100644
--- a/include/block/block.h
+++ b/include/block/block.h
@@ -109,6 +109,7 @@ typedef struct HDGeometry {
 #define BDRV_OPT_CACHE_NO_FLUSH "cache.no-flush"
 #define BDRV_OPT_READ_ONLY  "read-only"
 #define BDRV_OPT_DISCARD"discard"
+#define BDRV_OPT_FORCE_SHARE"force-share"
 
 
 #define BDRV_SECTOR_BITS   9
diff --git a/include/block/block_int.h b/include/block/block_int.h
index 59400bd..94ba697 100644
--- a/include/block/block_int.h
+++ b/include/block/block_int.h
@@ -518,6 +518,7 @@ struct BlockDriverState {
 bool valid_key; /* if true, a valid encryption key has been set */
 bool sg;/* if true, the device is a /dev/sg* */
 bool probed;/* if true, format was probed rather than specified */
+bool force_share; /* if true, always allow all shared permissions */
 
 BlockDriver *drv; /* NULL means no media */
 void *opaque;
diff --git a/qapi/block-core.json b/qapi/block-core.json
index 033457c..5bc56969 100644
--- a/qapi/block-core.json
+++ b/qapi/block-core.json
@@ -2880,6 +2880,8 @@
 # (default: false)
 # @detect-zeroes: detect and optimize zero writes (Since 2.1)
 # (default: off)
+# @force-share:   force share all permission on added nodes.
+# Requires read-only=true. (Since 2.10)
 #
 # Remaining options are determined by the block driver.
 #
@@ -2891,6 +2893,7 @@
 '*discard': 'BlockdevDiscardOptions',
 '*cache': 'BlockdevCacheOptions',
 '*read-only': 'bool',
+'*force-share': 'bool',
 '*detect-zeroes': 'BlockdevDetectZeroesOptions' },
   'discriminator': 'driver',
   'data': {
-- 
2.9.3




[Qemu-devel] [PATCH v15 05/21] qemu-img: Add --force-share option to subcommands

2017-04-25 Thread Fam Zheng
This will force the opened images to allow sharing all permissions with other
programs.

Signed-off-by: Fam Zheng 
---
 qemu-img.c | 154 ++---
 1 file changed, 118 insertions(+), 36 deletions(-)

diff --git a/qemu-img.c b/qemu-img.c
index ed24371..c0fb1ce 100644
--- a/qemu-img.c
+++ b/qemu-img.c
@@ -28,6 +28,7 @@
 #include "qapi/qobject-output-visitor.h"
 #include "qapi/qmp/qerror.h"
 #include "qapi/qmp/qjson.h"
+#include "qapi/qmp/qbool.h"
 #include "qemu/cutils.h"
 #include "qemu/config-file.h"
 #include "qemu/option.h"
@@ -283,12 +284,20 @@ static int img_open_password(BlockBackend *blk, const 
char *filename,
 
 static BlockBackend *img_open_opts(const char *optstr,
QemuOpts *opts, int flags, bool 
writethrough,
-   bool quiet)
+   bool quiet, bool force_share)
 {
 QDict *options;
 Error *local_err = NULL;
 BlockBackend *blk;
 options = qemu_opts_to_qdict(opts, NULL);
+if (force_share) {
+if (qdict_haskey(options, BDRV_OPT_FORCE_SHARE)
+&& !qdict_get_bool(options, BDRV_OPT_FORCE_SHARE)) {
+error_report("--force-share/-U conflicts with image options");
+return NULL;
+}
+qdict_put(options, BDRV_OPT_FORCE_SHARE, qbool_from_bool(true));
+}
 blk = blk_new_open(NULL, NULL, options, flags, _err);
 if (!blk) {
 error_reportf_err(local_err, "Could not open '%s': ", optstr);
@@ -305,17 +314,20 @@ static BlockBackend *img_open_opts(const char *optstr,
 
 static BlockBackend *img_open_file(const char *filename,
const char *fmt, int flags,
-   bool writethrough, bool quiet)
+   bool writethrough, bool quiet,
+   bool force_share)
 {
 BlockBackend *blk;
 Error *local_err = NULL;
-QDict *options = NULL;
+QDict *options = qdict_new();
 
 if (fmt) {
-options = qdict_new();
 qdict_put(options, "driver", qstring_from_str(fmt));
 }
 
+if (force_share) {
+qdict_put(options, BDRV_OPT_FORCE_SHARE, qbool_from_bool(true));
+}
 blk = blk_new_open(filename, NULL, options, flags, _err);
 if (!blk) {
 error_reportf_err(local_err, "Could not open '%s': ", filename);
@@ -334,7 +346,7 @@ static BlockBackend *img_open_file(const char *filename,
 static BlockBackend *img_open(bool image_opts,
   const char *filename,
   const char *fmt, int flags, bool writethrough,
-  bool quiet)
+  bool quiet, bool force_share)
 {
 BlockBackend *blk;
 if (image_opts) {
@@ -348,9 +360,11 @@ static BlockBackend *img_open(bool image_opts,
 if (!opts) {
 return NULL;
 }
-blk = img_open_opts(filename, opts, flags, writethrough, quiet);
+blk = img_open_opts(filename, opts, flags, writethrough, quiet,
+force_share);
 } else {
-blk = img_open_file(filename, fmt, flags, writethrough, quiet);
+blk = img_open_file(filename, fmt, flags, writethrough, quiet,
+force_share);
 }
 return blk;
 }
@@ -650,6 +664,7 @@ static int img_check(int argc, char **argv)
 ImageCheck *check;
 bool quiet = false;
 bool image_opts = false;
+bool force_share = false;
 
 fmt = NULL;
 output = NULL;
@@ -664,9 +679,10 @@ static int img_check(int argc, char **argv)
 {"output", required_argument, 0, OPTION_OUTPUT},
 {"object", required_argument, 0, OPTION_OBJECT},
 {"image-opts", no_argument, 0, OPTION_IMAGE_OPTS},
+{"force-share", no_argument, 0, 'U'},
 {0, 0, 0, 0}
 };
-c = getopt_long(argc, argv, ":hf:r:T:q",
+c = getopt_long(argc, argv, ":hf:r:T:qU",
 long_options, _index);
 if (c == -1) {
 break;
@@ -705,6 +721,9 @@ static int img_check(int argc, char **argv)
 case 'q':
 quiet = true;
 break;
+case 'U':
+force_share = true;
+break;
 case OPTION_OBJECT: {
 QemuOpts *opts;
 opts = qemu_opts_parse_noisily(_object_opts,
@@ -744,7 +763,8 @@ static int img_check(int argc, char **argv)
 return 1;
 }
 
-blk = img_open(image_opts, filename, fmt, flags, writethrough, quiet);
+blk = img_open(image_opts, filename, fmt, flags, writethrough, quiet,
+   force_share);
 if (!blk) {
 return 1;
 }
@@ -947,7 +967,8 @@ static int img_commit(int argc, char **argv)
 return 1;
 }
 
-blk = img_open(image_opts, filename, fmt, flags, writethrough, quiet);
+blk = img_open(image_opts, 

[Qemu-devel] [PATCH v15 04/21] block: Respect "force-share" in perm propagating

2017-04-25 Thread Fam Zheng
Signed-off-by: Fam Zheng 
---
 block.c | 32 
 1 file changed, 24 insertions(+), 8 deletions(-)

diff --git a/block.c b/block.c
index 9db39b6..e9f4750 100644
--- a/block.c
+++ b/block.c
@@ -1430,6 +1430,22 @@ static int bdrv_child_check_perm(BdrvChild *c, uint64_t 
perm, uint64_t shared,
 static void bdrv_child_abort_perm_update(BdrvChild *c);
 static void bdrv_child_set_perm(BdrvChild *c, uint64_t perm, uint64_t shared);
 
+static void bdrv_child_perm(BlockDriverState *bs, BlockDriverState *child_bs,
+BdrvChild *c,
+const BdrvChildRole *role,
+uint64_t parent_perm, uint64_t parent_shared,
+uint64_t *nperm, uint64_t *nshared)
+{
+if (bs->drv && bs->drv->bdrv_child_perm) {
+bs->drv->bdrv_child_perm(bs, c, role,
+ parent_perm, parent_shared,
+ nperm, nshared);
+}
+if (child_bs && child_bs->force_share) {
+*nshared = BLK_PERM_ALL;
+}
+}
+
 /*
  * Check whether permissions on this node can be changed in a way that
  * @cumulative_perms and @cumulative_shared_perms are the new cumulative
@@ -1474,9 +1490,9 @@ static int bdrv_check_perm(BlockDriverState *bs, uint64_t 
cumulative_perms,
 /* Check all children */
 QLIST_FOREACH(c, >children, next) {
 uint64_t cur_perm, cur_shared;
-drv->bdrv_child_perm(bs, c, c->role,
- cumulative_perms, cumulative_shared_perms,
- _perm, _shared);
+bdrv_child_perm(bs, c->bs, c, c->role,
+cumulative_perms, cumulative_shared_perms,
+_perm, _shared);
 ret = bdrv_child_check_perm(c, cur_perm, cur_shared, ignore_children,
 errp);
 if (ret < 0) {
@@ -1536,9 +1552,9 @@ static void bdrv_set_perm(BlockDriverState *bs, uint64_t 
cumulative_perms,
 /* Update all children */
 QLIST_FOREACH(c, >children, next) {
 uint64_t cur_perm, cur_shared;
-drv->bdrv_child_perm(bs, c, c->role,
- cumulative_perms, cumulative_shared_perms,
- _perm, _shared);
+bdrv_child_perm(bs, c->bs, c, c->role,
+cumulative_perms, cumulative_shared_perms,
+_perm, _shared);
 bdrv_child_set_perm(c, cur_perm, cur_shared);
 }
 }
@@ -1873,8 +1889,8 @@ BdrvChild *bdrv_attach_child(BlockDriverState *parent_bs,
 
 assert(parent_bs->drv);
 assert(bdrv_get_aio_context(parent_bs) == bdrv_get_aio_context(child_bs));
-parent_bs->drv->bdrv_child_perm(parent_bs, NULL, child_role,
-perm, shared_perm, , _perm);
+bdrv_child_perm(parent_bs, child_bs, NULL, child_role,
+perm, shared_perm, , _perm);
 
 child = bdrv_root_attach_child(child_bs, child_name, child_role,
perm, shared_perm, parent_bs, errp);
-- 
2.9.3




[Qemu-devel] [PATCH v15 01/21] block: Make bdrv_perm_names public

2017-04-25 Thread Fam Zheng
It can be used outside of block.c for making user friendly messages.

Signed-off-by: Fam Zheng 
---
 block.c   | 2 +-
 include/block/block.h | 2 ++
 2 files changed, 3 insertions(+), 1 deletion(-)

diff --git a/block.c b/block.c
index 1e668fb..fce77bf 100644
--- a/block.c
+++ b/block.c
@@ -1551,7 +1551,7 @@ static char *bdrv_child_user_desc(BdrvChild *c)
 return g_strdup("another user");
 }
 
-static char *bdrv_perm_names(uint64_t perm)
+char *bdrv_perm_names(uint64_t perm)
 {
 struct perm_name {
 uint64_t perm;
diff --git a/include/block/block.h b/include/block/block.h
index 5ddc0cf..eb0565d 100644
--- a/include/block/block.h
+++ b/include/block/block.h
@@ -224,6 +224,8 @@ enum {
 BLK_PERM_ALL= 0x1f,
 };
 
+char *bdrv_perm_names(uint64_t perm);
+
 /* disk I/O throttling */
 void bdrv_init(void);
 void bdrv_init_with_whitelist(void);
-- 
2.9.3




[Qemu-devel] [PATCH v15 02/21] block: Define BLK_PERM_MAX

2017-04-25 Thread Fam Zheng
This is the order of the largest possible permission.

Signed-off-by: Fam Zheng 
---
 include/block/block.h | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/include/block/block.h b/include/block/block.h
index eb0565d..a798f10 100644
--- a/include/block/block.h
+++ b/include/block/block.h
@@ -224,6 +224,8 @@ enum {
 BLK_PERM_ALL= 0x1f,
 };
 
+#define BLK_PERM_MAX (64 - clz64((uint64_t)BLK_PERM_ALL))
+
 char *bdrv_perm_names(uint64_t perm);
 
 /* disk I/O throttling */
-- 
2.9.3




[Qemu-devel] [PATCH v15 00/21] block: Image locking series

2017-04-25 Thread Fam Zheng
v15: Rework a number of things, especially around what and how lockings are
 done.  [Kevin]
 - Map each permission to a locked byte.
 - Make the new option --force-share-perms, and require read-only=on.
 - Update test case 153 accordingly.
 - Only add -U where necessary in iotest 030.
 - Reject -U if conflicting with image opts in qemu-img/qemu-io.

v14: Replace BDRV_ flag with the "force-shared-write" block option. [Kevin]
 Add bs->force_shared_write.
 Update test case accordingly.
 A few fixes in the locking code spotted by patchew and the new test,
 though the long line error is still there for readability.
 Replace the workaround to drive-backup with a real fix in patch 17.

v13: - Address Max's comments.
 - Add reviewed-by from Max and Eric.
 - Rebase for 2.10:
   * Use op blocker API
   * Add --unsafe-read for qemu-img and qemu-io

Fam Zheng (21):
  block: Make bdrv_perm_names public
  block: Define BLK_PERM_MAX
  block: Add, parse and store "force-share" option
  block: Respect "force-share" in perm propagating
  qemu-img: Add --force-share option to subcommands
  qemu-img: Update documentation for -U
  qemu-io: Add --force-share option
  iotests: 030: Prepare for image locking
  iotests: 046: Prepare for image locking
  iotests: 055: Don't attach the target image already for drive-backup
  iotests: 085: Avoid image locking conflict
  iotests: 087: Don't attach test image twice
  iotests: 091: Quit QEMU before checking image
  iotests: 172: Use separate images for multiple devices
  tests: Use null-co:// instead of /dev/null as the dummy image
  file-posix: Add 'locking' option
  tests: Disable image lock in test-replication
  block: Reuse bs as backing hd for drive-backup sync=none
  osdep: Add qemu_lock_fd and qemu_unlock_fd
  file-posix: Add image locking to perm operations
  qemu-iotests: Add test case 153 for image locking

 block.c|  51 --
 block/file-posix.c | 272 ++-
 blockdev.c |  15 +-
 include/block/block.h  |   5 +
 include/block/block_int.h  |   1 +
 include/qemu/osdep.h   |   3 +
 qapi/block-core.json   |   3 +
 qemu-img-cmds.hx   |  36 ++---
 qemu-img.c | 154 +-
 qemu-io.c  |  42 -
 tests/drive_del-test.c |   2 +-
 tests/nvme-test.c  |   2 +-
 tests/qemu-iotests/030 |  18 +--
 tests/qemu-iotests/046 |   2 +-
 tests/qemu-iotests/055 |  32 ++--
 tests/qemu-iotests/085 |  34 ++--
 tests/qemu-iotests/085.out |   3 +-
 tests/qemu-iotests/087 |   6 +-
 tests/qemu-iotests/091 |   2 +
 tests/qemu-iotests/153 | 220 +
 tests/qemu-iotests/153.out | 390 +
 tests/qemu-iotests/172 |  55 ---
 tests/qemu-iotests/172.out |  50 +++---
 tests/qemu-iotests/group   |   1 +
 tests/test-replication.c   |   9 +-
 tests/usb-hcd-uhci-test.c  |   2 +-
 tests/usb-hcd-xhci-test.c  |   2 +-
 tests/virtio-blk-test.c|   2 +-
 tests/virtio-scsi-test.c   |   5 +-
 util/osdep.c   |  48 ++
 30 files changed, 1291 insertions(+), 176 deletions(-)
 create mode 100755 tests/qemu-iotests/153
 create mode 100644 tests/qemu-iotests/153.out

-- 
2.9.3




Re: [Qemu-devel] [PULL 00/47] ppc-for-2.10 queue 20170424

2017-04-25 Thread David Gibson
On Mon, Apr 24, 2017 at 02:12:19PM +0100, Peter Maydell wrote:
> On 24 April 2017 at 02:58, David Gibson  wrote:
> > The following changes since commit 32c7e0ab755745e961f1772e95cac381cc68769d:
> >
> >   Merge remote-tracking branch 
> > 'remotes/juanquintela/tags/migration/20170421' into staging (2017-04-21 
> > 15:59:27 +0100)
> >
> > are available in the git repository at:
> >
> >   git://github.com/dgibson/qemu.git tags/ppc-for-2.10-20170424
> >
> > for you to fetch changes up to 4cab48942a1c5353f0a314fab1aa85a5f0a61461:
> >
> >   target/ppc: Style fixes (2017-04-24 08:56:19 +1000)
> >
> > 
> > ppc patch queue 2017-04-24
> >
> > Here's my first pull request for qemu-2.10, consisting of assorted
> > patches which have accumulated while qemu-2.9 stabilized.  Highlights
> > are:
> > * Rework / cleanup of the XICS interrupt controller
> > * Substantial improvement to the 'powernv' machine type
> > - Includes an MMIO XICS version
> > * POWER9 support improvements
> > - POWER9 guests with KVM
> > - Partial support for POWER9 guests with TCG
> > * IOMMU and VFIO improvements
> > * Assorted minor changes
> >
> > There are several IPMI patches here that aren't usually in my area of
> > maintenance, but there isn't a regular maintainer and these patches
> > are for the benefit of the powernv machine type.
> 
> 
> Hi -- I'm afraid this pullreq generates a new clang sanitizer warning
> running 'make check':

Drat.  What do I need to do to see these warnings?  Sounds like I
should add that to my pre-pull-request testing sequence.  Just
building with clang (on Fedora 25) and running make check doesn't seem
to be sufficient.

> /home/petmay01/linaro/qemu-for-merges/hw/core/loader.c:67:15: runtime
> error: null pointer passed as argument 1, which is declared to never
> be null
> 
> It looks like we try to call open(NULL, ...).
> 
> Affected tests are in check-qtest-i386:
> tests/bios-tables-test
>   /i386/acpi/piix4/ipmi
>   /i386/acpi/q35/ipmi
> tests/ipmi-kcs-test
> 
> Here's a backtrace:
> 
> #0  0x567e6197 in get_image_size (filename=0x0) at
> /home/petmay01/linaro/qemu-for-merges/hw/core/loader.c:67
> #1  0x568ead3c in ipmi_fru_init (fru=0x5ab98588)
> at /home/petmay01/linaro/qemu-for-merges/hw/ipmi/ipmi_bmc_sim.c:1902
> #2  0x568e91ac in ipmi_sim_realize (dev=,
> errp=)
> at /home/petmay01/linaro/qemu-for-merges/hw/ipmi/ipmi_bmc_sim.c:1943
> #3  0x567d6df6 in device_set_realized (obj=,
> value=, errp=)
> at /home/petmay01/linaro/qemu-for-merges/hw/core/qdev.c:905
> #4  0x56d7b1f8 in property_set_bool (obj=0x5ab93c90,
> v=, name=, opaque=,
> errp=0x7fffde90) at
> /home/petmay01/linaro/qemu-for-merges/qom/object.c:1860
> #5  0x56d7dd1d in object_property_set_qobject (obj=0x0,
> value=, name=0x58fdf801  address 0x58fdf801>, errp=0x1) at
> /home/petmay01/linaro/qemu-for-merges/qom/qom-qobject.c:27
> #6  0x56d78cb2 in object_property_set_bool
> (obj=0x5ab93c90, value=, name=0x5710e087
> "realized", errp=0x7fffde90) at
> /home/petmay01/linaro/qemu-for-merges/qom/object.c:1163
> #7  0x5661d80d in qdev_device_add (opts=,
> errp=)
> at /home/petmay01/linaro/qemu-for-merges/qdev-monitor.c:630
> #8  0x566374cb in device_init_func (opaque=,
> opts=0x0, errp=0x58fdf801)
> at /home/petmay01/linaro/qemu-for-merges/vl.c:2305
> #9  0x5701dc81 in qemu_opts_foreach (list=,
> func=, opaque=, errp=) at
> /home/petmay01/linaro/qemu-for-merges/util/qemu-option.c:1114
> #10 0x56633289 in main (argc=, argv= out>, envp=)
> at /home/petmay01/linaro/qemu-for-merges/vl.c:4583
> 
> It looks like the device doesn't handle not having its fru.filename
> property set -- this should either cause an error in realize or the
> rest of the device code should handle NULL.
> 
> thanks
> -- PMM
> 

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


signature.asc
Description: PGP signature


Re: [Qemu-devel] Subject: [PATCH] target-ppc: Add global timer group A to open-pic.

2017-04-25 Thread David Gibson
On Sun, Apr 23, 2017 at 07:37:55PM -0500, alar...@ddci.com wrote:
> David Gibson  wrote on 04/23/2017 06:17:22 
> PM:
> 
> > From: David Gibson 
> > To: Aaron Larson 
> > Cc: ag...@suse.de, qemu-devel@nongnu.org, qemu-...@nongnu.org
> > Date: 04/23/2017 06:54 PM
> > Subject: Re: Subject: [PATCH] target-ppc: Add global timer group A to 
> open-pic.
> > 
> > On Fri, Apr 21, 2017 at 02:58:23PM -0700, Aaron Larson wrote:
> > > Add global timer group A to open-pic.  This patch is still somewhat
> > > dubious because I'm not sure how to determine what QEMU wants for the
> > > timer frequency.  Suggestions solicited.
> > 
> > This commit message really needs some more context.  What's a "global
> > time group A" a and why do we want it?
> 
> The open-pic spec includes two sets/groups of timers, groups A and B,
> 4 timers in each group.  Previously in QEMU the timer group A
> registers were implemented but they did not "count" or generate any
> interrupts.  The patch makes the timers to do both (count and generate
> interrupts).

Ok, sounds good, but this is exactly the sort of thing that needs to
go in the commit message.

> About a year ago I mentioned that we had implemented this and offered
> to submit a patch, which seemed to be acceptable.  Sadly, when I
> reviewed the implementation it had several egregious errors that I
> didn't know how to fix until recently.

Ok.  Now that you mention that, it rings a vague bell.

> Quite frankly I didn't expect the patch to be accepted in its current
> form for the reason mentioned in the above commit log and was hoping
> for some guidance.  If this is no longer a desirable patch, I can
> certainly continue to maintain it locally for our use.

That's fine - but I need context of what the patch is attempting to
do, and why that's desirable in order to properly review it.

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


signature.asc
Description: PGP signature


Re: [Qemu-devel] [PATCH 2/2] ipmi: don't try to open a NULL filename

2017-04-25 Thread David Gibson
On Tue, Apr 25, 2017 at 04:06:17PM +0200, Cédric Le Goater wrote:
> On 04/25/2017 03:31 PM, Peter Maydell wrote:
> > On 25 April 2017 at 07:51, Cédric Le Goater  wrote:
> >> Currenlty, the code relies on the fact that open() handles NULL
> >> filenames but that can cause an error with new clang:
> >>
> >>   hw/core/loader.c:67:15: runtime error: null pointer passed as argument 1,
> >>   which is declared to never be null
> > 
> > This isn't "new clang", incidentally, it's just clang with the
> > runtime-static-analysis enabled, which causes warnings to be
> > printed at runtime for undefined behaviours. You can enable
> > this by passing configure --extra-cflags=-fsanitize=undefined .
> > (I have clang 3.8.0 here.)
> 
> OK. So I have now reproduced the issue on a f24. That made be 
> realize that the IPMI tests check for the arch they are being 
> run on and that more changes are required for them to run on 
> ppc64. 
> 
> We can drop patch 1/2. Tell me if you want a resend.

No, that's fine.  A patch to enable the tests on ppc properly ASAP
would be great, though.

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


signature.asc
Description: PGP signature


Re: [Qemu-devel] [PATCH 2/2] ipmi: don't try to open a NULL filename

2017-04-25 Thread David Gibson
On Tue, Apr 25, 2017 at 08:51:41AM +0200, Cédric Le Goater wrote:
> Currenlty, the code relies on the fact that open() handles NULL
> filenames but that can cause an error with new clang:
> 
>   hw/core/loader.c:67:15: runtime error: null pointer passed as argument 1,
>   which is declared to never be null
> 
> Signed-off-by: Cédric Le Goater 

Since my ppc-for-2.10 pull request has been held up because of this
anyway, tather than just apply this on top, I've folded it into your
earlier patch which caused the bug - that way we won't break bisect.

> ---
>  hw/ipmi/ipmi_bmc_sim.c | 5 +
>  1 file changed, 5 insertions(+)
> 
> diff --git a/hw/ipmi/ipmi_bmc_sim.c b/hw/ipmi/ipmi_bmc_sim.c
> index 155561d06614..277c28cb40ed 100644
> --- a/hw/ipmi/ipmi_bmc_sim.c
> +++ b/hw/ipmi/ipmi_bmc_sim.c
> @@ -1899,6 +1899,10 @@ static void ipmi_fru_init(IPMIFru *fru)
>  int fsize;
>  int size = 0;
>  
> +if (!fru->filename) {
> +goto out;
> +}
> +
>  fsize = get_image_size(fru->filename);
>  if (fsize > 0) {
>  size = QEMU_ALIGN_UP(fsize, fru->areasize);
> @@ -1910,6 +1914,7 @@ static void ipmi_fru_init(IPMIFru *fru)
>  }
>  }
>  
> +out:
>  if (!fru->data) {
>  /* give one default FRU */
>  size = fru->areasize;

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


signature.asc
Description: PGP signature


[Qemu-devel] [PATCH] block: Remove NULL check in bdrv_co_flush

2017-04-25 Thread Fam Zheng
Reported by Coverity. We already use bs in bdrv_inc_in_flight before
checking for NULL. It is unnecessary as all callers pass non-NULL bs, so
drop it.

Signed-off-by: Fam Zheng 
---
 block/io.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/block/io.c b/block/io.c
index a7142e0..a039966 100644
--- a/block/io.c
+++ b/block/io.c
@@ -2308,7 +2308,7 @@ int coroutine_fn bdrv_co_flush(BlockDriverState *bs)
 
 bdrv_inc_in_flight(bs);
 
-if (!bs || !bdrv_is_inserted(bs) || bdrv_is_read_only(bs) ||
+if (!bdrv_is_inserted(bs) || bdrv_is_read_only(bs) ||
 bdrv_is_sg(bs)) {
 goto early_exit;
 }
-- 
2.9.3




Re: [Qemu-devel] [PATCH 10/21] xen: import ring.h from xen

2017-04-25 Thread Philippe Mathieu-Daudé

On 04/25/2017 03:35 PM, Stefano Stabellini wrote:

Do not use the ring.h header installed on the system. Instead, import
the header into the QEMU codebase. This avoids problems when QEMU is
built against a Xen version too old to provide all the ring macros.

Signed-off-by: Stefano Stabellini 
Reviewed-by: Greg Kurz 


Reviewed-by: Philippe Mathieu-Daudé 


CC: anthony.per...@citrix.com
CC: jgr...@suse.com
---
 hw/block/xen_blkif.h |   2 +-
 hw/usb/xen-usb.c |   2 +-
 include/hw/xen/io/ring.h | 482 +++
 3 files changed, 484 insertions(+), 2 deletions(-)
 create mode 100644 include/hw/xen/io/ring.h

diff --git a/hw/block/xen_blkif.h b/hw/block/xen_blkif.h
index 3300b6f..3e6e1ea 100644
--- a/hw/block/xen_blkif.h
+++ b/hw/block/xen_blkif.h
@@ -1,7 +1,7 @@
 #ifndef XEN_BLKIF_H
 #define XEN_BLKIF_H

-#include 
+#include "hw/xen/io/ring.h"
 #include 
 #include 

diff --git a/hw/usb/xen-usb.c b/hw/usb/xen-usb.c
index 8e676e6..370b3d9 100644
--- a/hw/usb/xen-usb.c
+++ b/hw/usb/xen-usb.c
@@ -33,7 +33,7 @@
 #include "qapi/qmp/qint.h"
 #include "qapi/qmp/qstring.h"

-#include 
+#include "hw/xen/io/ring.h"
 #include 

 /*
diff --git a/include/hw/xen/io/ring.h b/include/hw/xen/io/ring.h
new file mode 100644
index 000..abbca47
--- /dev/null
+++ b/include/hw/xen/io/ring.h
@@ -0,0 +1,482 @@
+/**
+ * ring.h
+ *
+ * Shared producer-consumer ring macros.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to
+ * deal in the Software without restriction, including without limitation the
+ * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
+ * sell copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+ * DEALINGS IN THE SOFTWARE.
+ *
+ * Tim Deegan and Andrew Warfield November 2004.
+ */
+
+#ifndef __XEN_PUBLIC_IO_RING_H__
+#define __XEN_PUBLIC_IO_RING_H__
+
+/*
+ * When #include'ing this header, you need to provide the following
+ * declaration upfront:
+ * - standard integers types (uint8_t, uint16_t, etc)
+ * They are provided by stdint.h of the standard headers.
+ *
+ * In addition, if you intend to use the FLEX macros, you also need to
+ * provide the following, before invoking the FLEX macros:
+ * - size_t
+ * - memcpy
+ * - grant_ref_t
+ * These declarations are provided by string.h of the standard headers,
+ * and grant_table.h from the Xen public headers.
+ */
+
+#if __XEN_INTERFACE_VERSION__ < 0x00030208
+#define xen_mb()  mb()
+#define xen_rmb() rmb()
+#define xen_wmb() wmb()
+#endif
+
+typedef unsigned int RING_IDX;
+
+/* Round a 32-bit unsigned constant down to the nearest power of two. */
+#define __RD2(_x)  (((_x) & 0x0002) ? 0x2  : ((_x) & 0x1))
+#define __RD4(_x)  (((_x) & 0x000c) ? __RD2((_x)>>2)<<2: __RD2(_x))
+#define __RD8(_x)  (((_x) & 0x00f0) ? __RD4((_x)>>4)<<4: __RD4(_x))
+#define __RD16(_x) (((_x) & 0xff00) ? __RD8((_x)>>8)<<8: __RD8(_x))
+#define __RD32(_x) (((_x) & 0x) ? __RD16((_x)>>16)<<16 : __RD16(_x))
+
+/*
+ * Calculate size of a shared ring, given the total available space for the
+ * ring and indexes (_sz), and the name tag of the request/response structure.
+ * A ring contains as many entries as will fit, rounded down to the nearest
+ * power of two (so we can mask with (size-1) to loop around).
+ */
+#define __CONST_RING_SIZE(_s, _sz) \
+(__RD32(((_sz) - offsetof(struct _s##_sring, ring)) / \
+   sizeof(((struct _s##_sring *)0)->ring[0])))
+/*
+ * The same for passing in an actual pointer instead of a name tag.
+ */
+#define __RING_SIZE(_s, _sz) \
+(__RD32(((_sz) - (long)(_s)->ring + (long)(_s)) / sizeof((_s)->ring[0])))
+
+/*
+ * Macros to make the correct C datatypes for a new kind of ring.
+ *
+ * To make a new ring datatype, you need to have two message structures,
+ * let's say request_t, and response_t already defined.
+ *
+ * In a header where you want the ring datatype declared, you then do:
+ *
+ * DEFINE_RING_TYPES(mytag, request_t, response_t);
+ *
+ * These expand out to give you a set of types, as you can see below.
+ * 

Re: [Qemu-devel] [PATCH 25/26] audio: un-export OPLResetChip

2017-04-25 Thread Philippe Mathieu-Daudé

On 04/25/2017 07:37 PM, Juan Quintela wrote:

Signed-off-by: Juan Quintela 


Reviewed-by: Philippe Mathieu-Daudé 


---
 hw/audio/fmopl.c | 2 +-
 hw/audio/fmopl.h | 1 -
 2 files changed, 1 insertion(+), 2 deletions(-)

diff --git a/hw/audio/fmopl.c b/hw/audio/fmopl.c
index 99d09c5..dc9043c 100644
--- a/hw/audio/fmopl.c
+++ b/hw/audio/fmopl.c
@@ -1036,7 +1036,7 @@ void YM3812UpdateOne(FM_OPL *OPL, int16_t *buffer, int 
length)
 }

 /* -- reset one of chip -- */
-void OPLResetChip(FM_OPL *OPL)
+static void OPLResetChip(FM_OPL *OPL)
 {
int c,s;
int i;
diff --git a/hw/audio/fmopl.h b/hw/audio/fmopl.h
index f89af08..fc9f16b 100644
--- a/hw/audio/fmopl.h
+++ b/hw/audio/fmopl.h
@@ -95,7 +95,6 @@ FM_OPL *OPLCreate(int clock, int rate);
 void OPLDestroy(FM_OPL *OPL);
 void OPLSetTimerHandler(FM_OPL *OPL,OPL_TIMERHANDLER TimerHandler,int 
channelOffset);

-void OPLResetChip(FM_OPL *OPL);
 int OPLWrite(FM_OPL *OPL,int a,int v);
 unsigned char OPLRead(FM_OPL *OPL,int a);
 int OPLTimerOver(FM_OPL *OPL,int c);





Re: [Qemu-devel] [PATCH 26/26] audio: Use ARRAY_SIZE from qemu/osdep.h

2017-04-25 Thread Philippe Mathieu-Daudé

On 04/25/2017 07:37 PM, Juan Quintela wrote:

Signed-off-by: Juan Quintela 


Reviewed-by: Philippe Mathieu-Daudé 


---
 hw/audio/fmopl.c | 6 +-
 1 file changed, 1 insertion(+), 5 deletions(-)

diff --git a/hw/audio/fmopl.c b/hw/audio/fmopl.c
index dc9043c..202f752 100644
--- a/hw/audio/fmopl.c
+++ b/hw/audio/fmopl.c
@@ -34,15 +34,11 @@
 #include 
 //#include "driver.h"/* use M.A.M.E. */
 #include "fmopl.h"
-
+#include "qemu/osdep.h"
 #ifndef PI
 #define PI 3.14159265358979323846
 #endif

-#ifndef ARRAY_SIZE
-#define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0]))
-#endif
-
 /*  for debug - */
 /* #define OPL_OUTPUT_LOG */
 #ifdef OPL_OUTPUT_LOG





Re: [Qemu-devel] [PATCH 19/26] audio: GUSsample is int16_t

2017-04-25 Thread Philippe Mathieu-Daudé

Hi Juan,

Same here, why not squashing as "Use stdint instead of dead GUSEMU32"?

On 04/25/2017 07:37 PM, Juan Quintela wrote:

Signed-off-by: Juan Quintela 
---
 hw/audio/gus.c  |  2 +-
 hw/audio/gusemu.h   | 12 +---
 hw/audio/gusemu_hal.c   |  2 +-
 hw/audio/gusemu_mixer.c |  8 
 4 files changed, 7 insertions(+), 17 deletions(-)

diff --git a/hw/audio/gus.c b/hw/audio/gus.c
index 3d08a65..ec103a4 100644
--- a/hw/audio/gus.c
+++ b/hw/audio/gus.c
@@ -53,7 +53,7 @@ typedef struct GUSState {
 uint32_t freq;
 uint32_t port;
 int pos, left, shift, irqs;
-GUSsample *mixbuf;
+int16_t *mixbuf;
 uint8_t himem[1024 * 1024 + 32 + 4096];
 int samples;
 SWVoiceOut *voice;
diff --git a/hw/audio/gusemu.h b/hw/audio/gusemu.h
index 69dadef..ab591ee 100644
--- a/hw/audio/gusemu.h
+++ b/hw/audio/gusemu.h
@@ -25,16 +25,6 @@
 #ifndef GUSEMU_H
 #define GUSEMU_H

-/* data types (need to be adjusted if neither a VC6 nor a C99 compatible 
compiler is used) */
-
-#if defined _WIN32 && defined _MSC_VER /* doesn't support other win32 
compilers yet, do it yourself... */
- typedef unsigned int GUSdword;
- typedef signed short GUSsample;
-#else
- typedef uint32_t GUSdword;
- typedef int16_t GUSsample;
-#endif
-
 typedef struct _GUSEmuState
 {
  uint8_t *himemaddr; /* 1024*1024 bytes used for storing uploaded samples (+32 
additional bytes for read padding) */
@@ -86,7 +76,7 @@ void gus_dma_transferdata(GUSEmuState *state, char *dma_addr, 
unsigned int count
 /* If the interrupts are asynchronous, it may be needed to use a separate 
thread mixing into a temporary */
 /* audio buffer in order to avoid quality loss caused by large numsamples and 
elapsed_time values. */

-void gus_mixvoices(GUSEmuState *state, unsigned int playback_freq, unsigned 
int numsamples, GUSsample *bufferpos);
+void gus_mixvoices(GUSEmuState *state, unsigned int playback_freq, unsigned 
int numsamples, int16_t *bufferpos);
 /* recommended range: 10 < numsamples < 100 */
 /* lower values may result in increased rounding error, higher values often 
cause audible timing delays */

diff --git a/hw/audio/gusemu_hal.c b/hw/audio/gusemu_hal.c
index 3dd7239..1150fc4 100644
--- a/hw/audio/gusemu_hal.c
+++ b/hw/audio/gusemu_hal.c
@@ -32,7 +32,7 @@

 #define GUSregb(position) (*(gusptr+(position)))
 #define GUSregw(position) (*(uint16_t *) (gusptr+(position)))
-#define GUSregd(position) (*(GUSdword *)(gusptr+(position)))
+#define GUSregd(position) (*(uint16_t *)(gusptr+(position)))

 /* size given in bytes */
 unsigned int gus_read(GUSEmuState * state, int port, int size)
diff --git a/hw/audio/gusemu_mixer.c b/hw/audio/gusemu_mixer.c
index 981a9ae..00b9861 100644
--- a/hw/audio/gusemu_mixer.c
+++ b/hw/audio/gusemu_mixer.c
@@ -28,13 +28,13 @@

 #define GUSregb(position)  (*(gusptr+(position)))
 #define GUSregw(position)  (*(uint16_t *) (gusptr+(position)))
-#define GUSregd(position)  (*(GUSdword *)(gusptr+(position)))
+#define GUSregd(position)  (*(uint16_t *)(gusptr+(position)))

 #define GUSvoice(position) (*(uint16_t *)(voiceptr+(position)))

 /* samples are always 16bit stereo (4 bytes each, first right then left 
interleaved) */
 void gus_mixvoices(GUSEmuState * state, unsigned int playback_freq, unsigned 
int numsamples,
-   GUSsample *bufferpos)
+   int16_t *bufferpos)
 {
 /* note that byte registers are stored in the upper half of each voice 
register! */
 uint8_t*gusptr;
@@ -171,8 +171,8 @@ void gus_mixvoices(GUSEmuState * state, unsigned int 
playback_freq, unsigned int
 }

 /* mix samples into buffer */
-*(bufferpos + 2 * sample) += (GUSsample) ((sample1 * PanningPos) 
>> 4);/* right */
-*(bufferpos + 2 * sample + 1) += (GUSsample) ((sample1 * (15 - 
PanningPos)) >> 4); /* left */
+*(bufferpos + 2 * sample) += (int16_t) ((sample1 * PanningPos) 
>> 4);/* right */
+*(bufferpos + 2 * sample + 1) += (int16_t) ((sample1 * (15 - 
PanningPos)) >> 4); /* left */
 }
 /* write back voice and volume */
 GUSvoice(wVSRCurrVol)   = Volume32 / 32;





Re: [Qemu-devel] [PATCH 10/26] audio: Remove INT32

2017-04-25 Thread Philippe Mathieu-Daudé

Hi Juan, is there a benefit in not squashing the previous stdint commits?

On 04/25/2017 07:37 PM, Juan Quintela wrote:

Signed-off-by: Juan Quintela 
---
 hw/audio/fmopl.c | 42 +-
 hw/audio/fmopl.h | 54 --
 2 files changed, 45 insertions(+), 51 deletions(-)

diff --git a/hw/audio/fmopl.c b/hw/audio/fmopl.c
index ebd3dbb..8f935f6 100644
--- a/hw/audio/fmopl.c
+++ b/hw/audio/fmopl.c
@@ -170,7 +170,7 @@ static const uint32_t KSL_TABLE[8*16]=
 /* sustain lebel table (3db per step) */
 /* 0 - 15: 0, 3, 6, 9,12,15,18,21,24,27,30,33,36,39,42,93 (dB)*/
 #define SC(db) (db*((3/EG_STEP)*(1<connect1 = CH->CON ? carrier : 
CH->connect2 = carrier;
 }
@@ -498,7 +498,7 @@ static inline void OPL_CALC_RH( OPL_CH *CH )
 {
uint32_t env_tam,env_sd,env_top,env_hh;
int whitenoise = (rand()&1)*(WHITE_NOISE_db/EG_STEP);
-   INT32 tone8;
+   int32_t tone8;

OPL_SLOT *SLOT;
int env_out;
@@ -616,20 +616,20 @@ static int OPLOpenTable( void )
double pom;

/* allocate dynamic tables */
-   if( (TL_TABLE = malloc(TL_MAX*2*sizeof(INT32))) == NULL)
+   if( (TL_TABLE = malloc(TL_MAX*2*sizeof(int32_t))) == NULL)
return 0;
-   if( (SIN_TABLE = malloc(SIN_ENT*4 *sizeof(INT32 *))) == NULL)
+   if( (SIN_TABLE = malloc(SIN_ENT*4 *sizeof(int32_t *))) == NULL)
{
free(TL_TABLE);
return 0;
}
-   if( (AMS_TABLE = malloc(AMS_ENT*2 *sizeof(INT32))) == NULL)
+   if( (AMS_TABLE = malloc(AMS_ENT*2 *sizeof(int32_t))) == NULL)
{
free(TL_TABLE);
free(SIN_TABLE);
return 0;
}
-   if( (VIB_TABLE = malloc(VIB_ENT*2 *sizeof(INT32))) == NULL)
+   if( (VIB_TABLE = malloc(VIB_ENT*2 *sizeof(int32_t))) == NULL)
{
free(TL_TABLE);
free(SIN_TABLE);
diff --git a/hw/audio/fmopl.h b/hw/audio/fmopl.h
index 0bc3415..1e74019 100644
--- a/hw/audio/fmopl.h
+++ b/hw/audio/fmopl.h
@@ -7,12 +7,6 @@
 /* select bit size of output : 8 or 16 */
 #define OPL_OUTPUT_BIT 16

-/* compiler dependence */
-#ifndef OSD_CPU_H
-#define OSD_CPU_H
-typedef signed int INT32;   /* signed 32bit   */
-#endif
-
 #if (OPL_OUTPUT_BIT==16)
 typedef int16_t OPLSAMPLE;
 #endif
@@ -36,13 +30,13 @@ typedef unsigned char (*OPL_PORTHANDLER_R)(int param);
 /* Saving is necessary for member of the 'R' mark for suspend/resume */
 /* -- OPL one of slot  -- */
 typedef struct fm_opl_slot {
-   INT32 TL;   /* total level :TL << 8*/
-   INT32 TLL;  /* adjusted now TL */
+   int32_t TL; /* total level :TL << 8*/
+   int32_t TLL;/* adjusted now TL */
uint8_t 

Re: [Qemu-devel] [PATCH 05/26] audio: Remove UINT8

2017-04-25 Thread Philippe Mathieu-Daudé

Hi Juan,

On 04/25/2017 07:37 PM, Juan Quintela wrote:

uint8_t has existed since . all this century?

Signed-off-by: Juan Quintela 
---
 hw/audio/fmopl.c |  8 
 hw/audio/fmopl.h | 39 ---
 2 files changed, 24 insertions(+), 23 deletions(-)

diff --git a/hw/audio/fmopl.c b/hw/audio/fmopl.c
index 282662a..3d14b45 100644
--- a/hw/audio/fmopl.c
+++ b/hw/audio/fmopl.c
@@ -789,8 +789,8 @@ static void OPLWriteReg(FM_OPL *OPL, int r, int v)
}
else
{   /* set IRQ mask ,timer enable*/
-   UINT8 st1 = v&1;
-   UINT8 st2 = (v>>1)&1;
+   uint8_t st1 = v&1;
+   uint8_t st2 = (v>>1)&1;


Welcome to stdint! but since you're changing this code please make it 
more readable (at least spaces) so checkpatch don't reject your serie:


ERROR: spaces required around that '&'


/* IRQRST,T1MSK,t2MSK,EOSMSK,BRMSK,x,ST2,ST1 */
OPL_STATUS_RESET(OPL,v&0x78);
OPL_STATUSMASK_SET(OPL,((~v)&0x78)|0x01);
@@ -838,7 +838,7 @@ static void OPLWriteReg(FM_OPL *OPL, int r, int v)
case 0xbd:
/* amsep,vibdep,r,bd,sd,tom,tc,hh */
{
-   UINT8 rkey = OPL->rhythm^v;
+   uint8_t rkey = OPL->rhythm^v;
OPL->ams_table = _TABLE[v&0x80 ? AMS_ENT : 0];
OPL->vib_table = _TABLE[v&0x40 ? VIB_ENT : 0];
OPL->rhythm  = v&0x3f;
@@ -991,7 +991,7 @@ void YM3812UpdateOne(FM_OPL *OPL, INT16 *buffer, int length)
OPLSAMPLE *buf = buffer;
UINT32 amsCnt  = OPL->amsCnt;
UINT32 vibCnt  = OPL->vibCnt;
-   UINT8 rhythm = OPL->rhythm&0x20;
+   uint8_t rhythm = OPL->rhythm&0x20;
OPL_CH *CH,*R_CH;

if( (void *)OPL != cur_chip ){
diff --git a/hw/audio/fmopl.h b/hw/audio/fmopl.h
index e476497..3df8942 100644
--- a/hw/audio/fmopl.h
+++ b/hw/audio/fmopl.h
@@ -1,6 +1,8 @@
 #ifndef FMOPL_H
 #define FMOPL_H

+#include 
+
 /* --- system optimize --- */
 /* select bit size of output : 8 or 16 */
 #define OPL_OUTPUT_BIT 16
@@ -8,7 +10,6 @@
 /* compiler dependence */
 #ifndef OSD_CPU_H
 #define OSD_CPU_H
-typedef unsigned char  UINT8;   /* unsigned  8bit */
 typedef unsigned short UINT16;  /* unsigned 16bit */
 typedef unsigned int   UINT32;  /* unsigned 32bit */
 typedef signed charINT8;/* signed  8bit   */
@@ -41,19 +42,19 @@ typedef unsigned char (*OPL_PORTHANDLER_R)(int param);
 typedef struct fm_opl_slot {
INT32 TL;   /* total level :TL << 8*/
INT32 TLL;  /* adjusted now TL */
-   UINT8  KSR; /* key scale rate  :(shift down bit)   */
+   uint8_t  KSR;   /* key scale rate  :(shift down bit)   */
INT32 *AR;  /* attack rate :_TABLE[AR<<2]   */
INT32 *DR;  /* decay rate  :_TALBE[DR<<2]   */
INT32 SL;   /* sustin level:SL_TALBE[SL]   */
INT32 *RR;  /* release rate:_TABLE[RR<<2]   */
-   UINT8 ksl;  /* keyscale level  :(shift down bits)  */
-   UINT8 ksr;  /* key scale rate  :kcode>>KSR */
+   uint8_t ksl;/* keyscale level  :(shift down bits)  */
+   uint8_t ksr;/* key scale rate  :kcode>>KSR */
UINT32 mul; /* multiple:ML_TABLE[ML]   */
UINT32 Cnt; /* frequency count :   */
UINT32 Incr;/* frequency step  :   */
/* envelope generator state */
-   UINT8 eg_typ;   /* envelope type flag  */
-   UINT8 evm;  /* envelope phase  */
+   uint8_t eg_typ; /* envelope type flag  */
+   uint8_t evm;/* envelope phase  */
INT32 evc;  /* envelope counter*/
INT32 eve;  /* envelope counter end point  */
INT32 evs;  /* envelope counter step   */
@@ -61,8 +62,8 @@ typedef struct fm_opl_slot {
INT32 evsd; /* envelope step for DR :DR[ksr]   */
INT32 evsr; /* envelope step for RR :RR[ksr]   */
/* LFO */
-   UINT8 ams;  /* ams flag*/
-   UINT8 vib;  /* vibrate flag*/
+   uint8_t ams;/* ams flag*/
+   uint8_t vib;/* vibrate flag*/
/* wave selector */
INT32 **wavetable;
 }OPL_SLOT;
@@ -70,38 +71,38 @@ typedef struct 

Re: [Qemu-devel] [PATCH v4] qga: Add support network interfacestatistics in

2017-04-25 Thread lu.zhipeng
> +   */> +colon = strchr(line, ':')> +if (!colon) {> + 
   continue> +}> +*colon = '\0'> +if (colon - path_len 
>= line && strcmp(colon - path_len, path) == 0) {colon - path_len > line would 
imply the current line isn't a matcheither, so i think that can be tightened to 
colon - path_len == line.



The text reading from /proc/net/dev/ is  aligned to the right. so i think it 
should be colon - path_len >= line






















为了让您的VPlat虚拟化故障得到高效的处理,请上报故障到: $VPlat技术支持。


芦志朋 luzhipeng






IT开发工程师 IT Development
Engineer
操作系统产品部/中心研究院/系统产品 OS Product Dept./Central R&D Institute/System Product









深圳市南山区科技南路55号中兴通讯研发大楼33楼 
33/F, R Building, ZTE
Corporation Hi-tech Road South, 
Hi-tech
Industrial Park Nanshan District, Shenzhen, P.R.China, 518057 
T: +86 755  F:+86 755  
M: +86 xxx 
E: lu.zhip...@zte.com.cn 
www.zte.com.cn






原始邮件



发件人: <mdr...@linux.vnet.ibm.com>
收件人:芦志朋10108272
抄送人:芦志朋10108272 <qemu-devel@nongnu.org>
日 期 :2017年04月26日 05:17
主 题 :Re: [Qemu-devel] [PATCH v4] qga: Add support network interfacestatistics in





Quoting ZhiPeng Lu (2017-04-25 03:12:20)
> we can get the network interface statistics inside a virtual machine by
> guest-network-get-interfaces command. it is very useful for us to monitor
> and analyze network traffic.
> 
> Signed-off-by: ZhiPeng Lu <lu.zhip...@zte.com.cn>
> Signed-off-by: Daniel P. Berrange <berra...@redhat.com>
> ---
>  qga/commands-posix.c | 71 
+++-
>  qga/qapi-schema.json | 38 +++-
>  2 files changed, 107 insertions(+), 2 deletions(-)
> 
> diff --git a/qga/commands-posix.c b/qga/commands-posix.c
> index 915df9e..1e35340 100644
> --- a/qga/commands-posix.c
> +++ b/qga/commands-posix.c
> @@ -1638,6 +1638,65 @@ guest_find_interface(GuestNetworkInterfaceList *head,
>  return head
>  }
> 
> + static int guest_get_network_stats(const char *path,

Path is a little misleading. Isn't this the device name?

> +   GuestNetworkInterfaceStat *stats)
> +{
> +int path_len
> +char const *devinfo = "/proc/net/dev"
> +FILE *fp
> +char *line = NULL, *colon
> +size_t n
> +fp = fopen(devinfo, "r")
> +if (!fp) {
> +return -1
> +}
> +path_len = strlen(path)

name_len?

> +while (getline(, , fp) != -1) {
> +long long dummy
> +long long rx_bytes
> +long long rx_packets
> +long long rx_errs
> +long long rx_dropped
> +long long tx_bytes
> +long long tx_packets
> +long long tx_errs
> +long long tx_dropped
> +
> +  /* The line looks like:
> +   *"   eth0:..."
> +   *Split it at the colon.

Space after the "*". Indentation seems to wrong too.

> +   */
> +colon = strchr(line, ':')
> +if (!colon) {
> +continue
> +}
> +*colon = '\0'
> +if (colon - path_len >= line && strcmp(colon - path_len, path) == 0) 
{

colon - path_len > line would imply the current line isn't a match
either, so i think that can be tightened to colon - path_len == line.

> +if (sscanf(colon + 1,
> +"%lld %lld %lld %lld %lld %lld %lld %lld %lld %lld %lld %lld 
%lld %lld %lld %lld",
> +  _bytes, _packets, _errs, _dropped,
> +  , , , ,
> +  _bytes, _packets, _errs, _dropped,
> +  , , , ) != 16) {
> +continue
> +}
> +stats->rx_bytes = rx_bytes
> +stats->rx_packets = rx_packets
> +stats->rx_errs = rx_errs
> +stats->rx_dropped = rx_dropped
> +stats->tx_bytes = tx_bytes
> +stats->tx_packets = tx_packets
> +stats->tx_errs = tx_errs
> +stats->tx_dropped = tx_dropped
> +fclose(fp)
> +return 0
> +}
> +}
> +fclose(fp)
> +g_debug("/proc/net/dev: Interface not found")
> +return -1
> +}
> +
>  /*
>   * Build information about guest interfaces
>   */
> @@ -1654,6 +1713,7 @@ GuestNetworkInterfaceList 
*qmp_guest_network_get_interfaces(Error **errp)
>  for (ifa = ifap ifa ifa = ifa->ifa_next) {
>  GuestNetworkInterfaceList *info
>  GuestIpAddressList **address_list = NULL, *address_item = NULL
> +GuestNetworkInterfaceStat  *interface_stat = NULL
>  char addr4[INET_ADDRSTRLEN]
>  char addr6[INET6_ADDRSTRLEN]
>  int sock
> @@ -1773,7 +1833,16 @@ GuestNetworkInterfaceList 
*qmp_guest_network_get_interfaces(Error **errp)
> 
>  info->value->has_ip_addresses = true
> 
> -
> +if (!info->value->has_statistics) {
> +interface_stat = g_malloc0(sizeof(*interface_stat))
> +if (guest_get_network_stats(info->value->name,
> +interface_stat) == -1) {
> +error_setg_errno(errp, errno, "guest_get_network_stats 

Re: [Qemu-devel] [PATCH for 2.9 v3 10/10] block: Fix bdrv_co_flush early return

2017-04-25 Thread Fam Zheng
On Tue, 04/25 17:16, Kevin Wolf wrote:
> Am 10.04.2017 um 17:05 hat Fam Zheng geschrieben:
> > bdrv_inc_in_flight and bdrv_dec_in_flight are mandatory for
> > BDRV_POLL_WHILE to work, even for the shortcut case where flush is
> > unnecessary. Move the if block to below bdrv_dec_in_flight, and BTW fix
> > the variable declaration position.
> > 
> > Signed-off-by: Fam Zheng 
> > ---
> >  block/io.c | 16 +---
> >  1 file changed, 9 insertions(+), 7 deletions(-)
> > 
> > diff --git a/block/io.c b/block/io.c
> > index 00e45ca..bae6947 100644
> > --- a/block/io.c
> > +++ b/block/io.c
> > @@ -2278,16 +2278,17 @@ static void coroutine_fn bdrv_flush_co_entry(void 
> > *opaque)
> >  
> >  int coroutine_fn bdrv_co_flush(BlockDriverState *bs)
> >  {
> > -int ret;
> > -
> > -if (!bs || !bdrv_is_inserted(bs) || bdrv_is_read_only(bs) ||
> > -bdrv_is_sg(bs)) {
> > -return 0;
> > -}
> > +int current_gen;
> > +int ret = 0;
> >  
> >  bdrv_inc_in_flight(bs);
> 
> As Coverity points out, we're now using bs...
> 
> > -int current_gen = bs->write_gen;
> > +if (!bs || !bdrv_is_inserted(bs) || bdrv_is_read_only(bs) ||
> 
> ...before doing the NULL check.
> 
> I'm not sure if we even need to have a NULL check here, but we would have
> to check all callers to make sure that it's unnecessary. Before commit
> 29cdb251, it only checked bs->drv and I don't see how that commit
> introduced a NULL caller, but maybe one was added later.
> 
> In any case, bdrv_co_flush() needs a fix, either remove the NULL check
> or do it first.

After auditing the callers and knowing the fact that the above
bdrv_inc_in_flight didn't cause a problem, I think removing the NULL check is
fine.

I'll send a patch.

Thanks.

Fam

> 
> > +bdrv_is_sg(bs)) {
> > +goto early_exit;
> > +}
> 
> Kevin



Re: [Qemu-devel] [PULL 10/11] block: Fix bdrv_co_flush early return

2017-04-25 Thread Fam Zheng
On Tue, 04/25 16:00, Peter Maydell wrote:
> 
> Coverity points out that there's a problem here -- we call
> bdrv_inc_in_flight(bs), which assumes bs is not NULL, before
> we do the test for whether bs is NULL.
> 
> Presumably the NULL check needs to be pulled up earlier in
> the function?
> 

Yes, will take care of this one.

Fam



Re: [Qemu-devel] [PATCH v3 3/3] vfio-pci: process non fatal error of AER

2017-04-25 Thread Alex Williamson
On Tue, 25 Apr 2017 23:32:52 +0300
"Michael S. Tsirkin"  wrote:

> On Tue, Mar 28, 2017 at 08:55:04PM -0600, Alex Williamson wrote:
> > On Wed, 29 Mar 2017 02:59:34 +0300
> > "Michael S. Tsirkin"  wrote:
> >   
> > > On Tue, Mar 28, 2017 at 10:12:25AM -0600, Alex Williamson wrote:  
> > > > On Tue, 28 Mar 2017 21:49:17 +0800
> > > > Cao jin  wrote:
> > > > 
> > > > > On 03/25/2017 06:12 AM, Alex Williamson wrote:
> > > > > > On Thu, 23 Mar 2017 17:09:23 +0800
> > > > > > Cao jin  wrote:
> > > > > >   
> > > > > >> Make use of the non fatal error eventfd that the kernel module 
> > > > > >> provide
> > > > > >> to process the AER non fatal error. Fatal error still goes into the
> > > > > >> legacy way which results in VM stop.
> > > > > >>
> > > > > >> Register the handler, wait for notification. Construct aer message 
> > > > > >> and
> > > > > >> pass it to root port on notification. Root port will trigger an 
> > > > > >> interrupt
> > > > > >> to signal guest, then guest driver will do the recovery.  
> > > > > > 
> > > > > > Can we guarantee this is the better solution in all cases or could
> > > > > > there be guests without AER support where the VM stop is the better
> > > > > > solution?
> > > > > >   
> > > > > 
> > > > > Currently, we only have VM stop on errors, that looks the same as a
> > > > > sudden power down to me.  With this solution, we have about
> > > > > 50%(non-fatal) chance to reduce the sudden power-down risk.
> > > > 
> > > > If half of all faults are expected to be non-fatal, then you must have
> > > > some real examples of devices triggering non-fatal errors which can be
> > > > corrected in the guest driver that you can share to justify why it's a
> > > > good thing to enable this behavior.
> > > > 
> > > > > What if a guest doesn't support AER?  It looks the same as a host
> > > > > without AER support. Now I only can speculate the worst condition: 
> > > > > guest
> > > > > crash, would that be quite different from a sudden power-down?
> > > > 
> > > > Yes, it's very different.  In one case we contain the fault by stopping
> > > > the guest, in the other case we allow the guest to continue operating
> > > > with a known fault in the device which may allow the fault to propagate
> > > > and perhaps go unnoticed.  We have established with the current
> > > > behavior that QEMU will prevent further propagation of a fault by
> > > > halting the VM.  To change QEMU's behavior here risks that a VM relying
> > > > on that behavior no longer has that protection.  So it seems we either
> > > > need to detect whether the VM is handling AER or we need to require the
> > > > VM administrator to opt-in to this new feature.
> > > 
> > > An opt-in flag sounds very reasonable. It can also specify whether
> > > to log the errors. We have a similar flag for disk errors.  
> > 
> > An opt-in works, but is rather burdensome to the user.
> >
> > > >  Real hardware has
> > > > these same issues and I believe there are handshakes that can be done
> > > > through ACPI to allow the guest to take over error handling from the
> > > > system.
> > > 
> > > No, that's only for error reporting IIUC. Driver needs to be
> > > aware of a chance for errors to trigger and be able to
> > > handle them.  
> > 
> > See drivers/acpi/pci_root.c:negotiate_os_control(), it seems that the
> > OSPM uses an _OSC to tell ACPI via OSC_PCI_EXPRESS_AER_CONTROL.  Would
> > that not be a reasonable mechanism for the guest to indicate AER
> > support?  
> 
> I'm not sure - it seems to be designed for firmware that can drive
> AER natively. E.g. if we ever set FIRMWARE_FIRST then linux
> will not set this bit.
> 
> It's also global so doesn't really indicate a given driver
> supports AER.
> 
> Still - would this remove some or all of your concern?

Certainly not all, I have rather deep concerns about where we're going
here.

> Could you outline a set of requirements that can be satisfied
> to make you consider the feature for inclusion?

Like any enhancement, show me that it's useful, show me that we've done
due diligence in researching the problem and solution, show me that
we're not painting ourselves into a corner by only addressing a subset
of the problem, show me that it's been thoroughly tested and reviewed.
Currently, I have little confidence in any of this.  We seem to just be
tossing AER spitballs at the wall hoping one of them sticks.
 
> I tried by writing up
>   vfio/pci: guest error recovery proposal
> back in December and there didn't seem to be any objections, so I am
> quite surprised to see patches implementing that proposal more or less
> verbatim getting rejected.

Are the concerns from the patch review not valid?  I think this is
indicative of the problems we've had throughout this 2+ year
development process, a suggestion is made and it's implemented without
a thorough 

Re: [Qemu-devel] [PATCH 00/26] Audio Cleanup

2017-04-25 Thread no-reply
Hi,

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

Message-id: 20170425223739.6703-1-quint...@redhat.com
Subject: [Qemu-devel] [PATCH 00/26] Audio Cleanup
Type: series

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

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

# Useful git options
git config --local diff.renamelimit 0
git config --local diff.renames True

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

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

Updating 3c8cf5a9c21ff8782164d1def7f44bd888713384
From https://github.com/patchew-project/qemu
 * [new tag] 
patchew/1493161481-29595-1-git-send-email-mdr...@linux.vnet.ibm.com -> 
patchew/1493161481-29595-1-git-send-email-mdr...@linux.vnet.ibm.com
Switched to a new branch 'test'
426bc46 audio: Use ARRAY_SIZE from qemu/osdep.h
67f41a4 audio: un-export OPLResetChip
2928139 audio: Remove unused typedefs
c5bed44 audio: UpdateHandler is not used anymore
0f97e4e audio: IRQHandler is not used anymore
9be6fbb audio: OPLSetUpdateHandler is not used anywhere
17d4a87 audio: OPLSetIRQHandler is not used anywhere
331f9f0 audio: GUSsample is int16_t
eb7522b audio: GUSword is uint16_t
b6db066 audio: GUSword is uint16_t
4f2e7e5 audio: remove GUSchar
430732c audio: GUSbyte is uint8_t
5494808 audio: Remove unused fields
2f74da9 audio: Remove type field
91ee28c audio: Remove Unused OPL_TYPE_*
54a318a audio: Unfold OPLSAMPLE
ca7aa23 audio: Remove INT32
237513a audio: remove INT16
975980b audio: Remove INT8
1b97e08 audio: remove UINT32
7beb767 audio: remove UINT16
6699511 audio: Remove UINT8
4e01d17 audio: YM3812 was always defined
decafab audio: Remove YM3526 support
9ee2738 audio: remove Y8950 configuration
b24fc9b adlib: Remove support for YMF262

=== OUTPUT BEGIN ===
Checking PATCH 1/26: adlib: Remove support for YMF262...
Checking PATCH 2/26: audio: remove Y8950 configuration...
Checking PATCH 3/26: audio: Remove YM3526 support...
Checking PATCH 4/26: audio: YM3812 was always defined...
Checking PATCH 5/26: audio: Remove UINT8...
ERROR: code indent should never use tabs
#21: FILE: hw/audio/fmopl.c:792:
+^I^I^I^Iuint8_t st1 = v&1;$

ERROR: spaces required around that '&' (ctx:VxV)
#21: FILE: hw/audio/fmopl.c:792:
+   uint8_t st1 = v&1;
   ^

ERROR: code indent should never use tabs
#22: FILE: hw/audio/fmopl.c:793:
+^I^I^I^Iuint8_t st2 = (v>>1)&1;$

ERROR: spaces required around that '>>' (ctx:VxV)
#22: FILE: hw/audio/fmopl.c:793:
+   uint8_t st2 = (v>>1)&1;
^

ERROR: spaces required around that '&' (ctx:VxV)
#22: FILE: hw/audio/fmopl.c:793:
+   uint8_t st2 = (v>>1)&1;
^

ERROR: code indent should never use tabs
#31: FILE: hw/audio/fmopl.c:841:
+^I^I^Iuint8_t rkey = OPL->rhythm^v;$

ERROR: spaces required around that '^' (ctx:VxV)
#31: FILE: hw/audio/fmopl.c:841:
+   uint8_t rkey = OPL->rhythm^v;
  ^

ERROR: code indent should never use tabs
#40: FILE: hw/audio/fmopl.c:994:
+^Iuint8_t rhythm = OPL->rhythm&0x20;$

ERROR: spaces required around that '&' (ctx:VxV)
#40: FILE: hw/audio/fmopl.c:994:
+   uint8_t rhythm = OPL->rhythm&0x20;
^

ERROR: code indent should never use tabs
#70: FILE: hw/audio/fmopl.h:45:
+^Iuint8_t  KSR;^I^I/* key scale rate  :(shift down bit)   */$

ERROR: code indent should never use tabs
#77: FILE: hw/audio/fmopl.h:50:
+^Iuint8_t ksl;^I^I/* keyscale level  :(shift down bits)  */$

ERROR: code indent should never use tabs
#78: FILE: hw/audio/fmopl.h:51:
+^Iuint8_t ksr;^I^I/* key scale rate  :kcode>>KSR */$

ERROR: code indent should never use tabs
#85: FILE: hw/audio/fmopl.h:56:
+^Iuint8_t eg_typ;^I/* envelope type flag  */$

ERROR: code indent should never use tabs
#86: FILE: hw/audio/fmopl.h:57:
+^Iuint8_t evm;^I^I/* envelope phase  */$

ERROR: code indent should never use tabs
#96: FILE: hw/audio/fmopl.h:65:
+^Iuint8_t ams;^I^I/* ams flag*/$

ERROR: code indent should never use tabs
#97: FILE: hw/audio/fmopl.h:66:
+^Iuint8_t vib;^I^I/* vibrate flag*/$

WARNING: line over 80 characters
#107: FILE: hw/audio/fmopl.h:74:
+   uint8_t CON;/* connection type 
*/

ERROR: code indent should never use tabs
#107: FILE: hw/audio/fmopl.h:74:
+^Iuint8_t CON;^I^I^I/* connection type */$

WARNING: line over 80 characters
#108: FILE: hw/audio/fmopl.h:75:
+   uint8_t FB; 

[Qemu-devel] [PULL 7/8] qga: Add 'guest-get-users' command

2017-04-25 Thread Michael Roth
From: Vinzenz Feenstra 

A command that will list all currently logged in users, and the time
since when they are logged in.

Examples:

virsh # qemu-agent-command F25 '{ "execute": "guest-get-users" }'
{"return":[{"login-time":1490622289.903835,"user":"root"}]}

virsh # qemu-agent-command Win2k12r2 '{ "execute": "guest-get-users" }'
{"return":[{"login-time":1490351044.670552,"domain":"LADIDA",
"user":"Administrator"}]}

Signed-off-by: Vinzenz Feenstra 
Signed-off-by: Michael Roth 
---
 configure |   2 +-
 include/glib-compat.h |   5 +++
 qga/commands-posix.c  |  60 +
 qga/commands-win32.c  | 103 ++
 qga/qapi-schema.json  |  25 
 5 files changed, 194 insertions(+), 1 deletion(-)

diff --git a/configure b/configure
index 5c2accc..74ba64b 100755
--- a/configure
+++ b/configure
@@ -743,7 +743,7 @@ if test "$mingw32" = "yes" ; then
   sysconfdir="\${prefix}"
   local_statedir=
   confsuffix=""
-  libs_qga="-lws2_32 -lwinmm -lpowrprof -liphlpapi -lnetapi32 $libs_qga"
+  libs_qga="-lws2_32 -lwinmm -lpowrprof -lwtsapi32 -liphlpapi -lnetapi32 
$libs_qga"
 fi
 
 werror=""
diff --git a/include/glib-compat.h b/include/glib-compat.h
index 863c8cf..f8ee9dc 100644
--- a/include/glib-compat.h
+++ b/include/glib-compat.h
@@ -217,6 +217,11 @@ static inline void g_hash_table_add(GHashTable 
*hash_table, gpointer key)
 {
 g_hash_table_replace(hash_table, key, key);
 }
+
+static gboolean g_hash_table_contains(GHashTable *hash_table, gpointer key)
+{
+return g_hash_table_lookup_extended(hash_table, key, NULL, NULL);
+}
 #endif
 
 #ifndef g_assert_true
diff --git a/qga/commands-posix.c b/qga/commands-posix.c
index 915df9e..ba06be4 100644
--- a/qga/commands-posix.c
+++ b/qga/commands-posix.c
@@ -15,6 +15,7 @@
 #include 
 #include 
 #include 
+#include 
 #include "qga/guest-agent-core.h"
 #include "qga-qmp-commands.h"
 #include "qapi/qmp/qerror.h"
@@ -2517,3 +2518,62 @@ void ga_command_state_init(GAState *s, GACommandState 
*cs)
 ga_command_state_add(cs, NULL, guest_fsfreeze_cleanup);
 #endif
 }
+
+#define QGA_MICRO_SECOND_TO_SECOND 100
+
+static double ga_get_login_time(struct utmpx *user_info)
+{
+double seconds = (double)user_info->ut_tv.tv_sec;
+double useconds = (double)user_info->ut_tv.tv_usec;
+useconds /= QGA_MICRO_SECOND_TO_SECOND;
+return seconds + useconds;
+}
+
+GuestUserList *qmp_guest_get_users(Error **err)
+{
+GHashTable *cache = NULL;
+GuestUserList *head = NULL, *cur_item = NULL;
+struct utmpx *user_info = NULL;
+gpointer value = NULL;
+GuestUser *user = NULL;
+GuestUserList *item = NULL;
+double login_time = 0;
+
+cache = g_hash_table_new(g_str_hash, g_str_equal);
+setutxent();
+
+for (;;) {
+user_info = getutxent();
+if (user_info == NULL) {
+break;
+} else if (user_info->ut_type != USER_PROCESS) {
+continue;
+} else if (g_hash_table_contains(cache, user_info->ut_user)) {
+value = g_hash_table_lookup(cache, user_info->ut_user);
+user = (GuestUser *)value;
+login_time = ga_get_login_time(user_info);
+/* We're ensuring the earliest login time to be sent */
+if (login_time < user->login_time) {
+user->login_time = login_time;
+}
+continue;
+}
+
+item = g_new0(GuestUserList, 1);
+item->value = g_new0(GuestUser, 1);
+item->value->user = g_strdup(user_info->ut_user);
+item->value->login_time = ga_get_login_time(user_info);
+
+g_hash_table_insert(cache, item->value->user, item->value);
+
+if (!cur_item) {
+head = cur_item = item;
+} else {
+cur_item->next = item;
+cur_item = item;
+}
+}
+endutxent();
+g_hash_table_destroy(cache);
+return head;
+}
diff --git a/qga/commands-win32.c b/qga/commands-win32.c
index 9fec1fb..439d229 100644
--- a/qga/commands-win32.c
+++ b/qga/commands-win32.c
@@ -11,6 +11,9 @@
  * See the COPYING file in the top-level directory.
  */
 
+#ifndef _WIN32_WINNT
+#   define _WIN32_WINNT 0x0600
+#endif
 #include "qemu/osdep.h"
 #include 
 #include 
@@ -25,6 +28,7 @@
 #include 
 #endif
 #include 
+#include 
 
 #include "qga/guest-agent-core.h"
 #include "qga/vss-win32.h"
@@ -1536,3 +1540,102 @@ void ga_command_state_init(GAState *s, GACommandState 
*cs)
 ga_command_state_add(cs, NULL, guest_fsfreeze_cleanup);
 }
 }
+
+/* MINGW is missing two fields: IncomingFrames & OutgoingFrames */
+typedef struct _GA_WTSINFOA {
+WTS_CONNECTSTATE_CLASS State;
+DWORD SessionId;
+DWORD IncomingBytes;
+DWORD OutgoingBytes;
+DWORD IncomingFrames;
+DWORD OutgoingFrames;
+DWORD IncomingCompressedBytes;
+DWORD OutgoingCompressedBy;
+CHAR 

[Qemu-devel] [PULL 5/8] qga: Add 'guest-get-host-name' command

2017-04-25 Thread Michael Roth
From: Vinzenz Feenstra 

Retrieving the guest host name is a very useful feature for virtual management
systems. This information can help to have more user friendly VM access
details, instead of an IP there would be the host name. Also the host name
reported can be used to have automated checks for valid SSL certificates.

virsh # qemu-agent-command F25 '{ "execute": "guest-get-host-name" }'
{"return":{"host-name":"F25.lab.evilissimo.net"}}

Signed-off-by: Vinzenz Feenstra 
* minor whitespace fix-ups
Signed-off-by: Michael Roth 
---
 qga/commands.c   | 11 +++
 qga/qapi-schema.json | 26 ++
 2 files changed, 37 insertions(+)

diff --git a/qga/commands.c b/qga/commands.c
index 4d92946..57a31bb 100644
--- a/qga/commands.c
+++ b/qga/commands.c
@@ -499,3 +499,14 @@ int ga_parse_whence(GuestFileWhence *whence, Error **errp)
 error_setg(errp, "invalid whence code %"PRId64, whence->u.value);
 return -1;
 }
+
+GuestHostName *qmp_guest_get_host_name(Error **err)
+{
+GuestHostName *result = NULL;
+gchar const *hostname = g_get_host_name();
+if (hostname != NULL) {
+result = g_new0(GuestHostName, 1);
+result->host_name = g_strdup(hostname);
+}
+return result;
+}
diff --git a/qga/qapi-schema.json b/qga/qapi-schema.json
index a02dbf2..6307ae2 100644
--- a/qga/qapi-schema.json
+++ b/qga/qapi-schema.json
@@ -1042,3 +1042,29 @@
   'data':{ 'path': 'str', '*arg': ['str'], '*env': ['str'],
'*input-data': 'str', '*capture-output': 'bool' },
   'returns': 'GuestExec' }
+
+
+##
+# @GuestHostName:
+# @host-name: Fully qualified domain name of the guest OS
+#
+# Since: 2.10
+##
+{ 'struct': 'GuestHostName',
+  'data':   { 'host-name': 'str' } }
+
+##
+# @guest-get-host-name:
+#
+# Return a name for the machine.
+#
+# The returned name is not necessarily a fully-qualified domain name, or even
+# present in DNS or some other name service at all. It need not even be unique
+# on your local network or site, but usually it is.
+#
+# Returns: the host name of the machine on success
+#
+# Since: 2.10
+##
+{ 'command': 'guest-get-host-name',
+  'returns': 'GuestHostName' }
-- 
2.7.4




[Qemu-devel] [PULL 3/8] qga-win: Fix a bug where qemu-ga service is stuck during stop operation

2017-04-25 Thread Michael Roth
From: Sameeh Jubran 

After triggering a freeze command without any following thaw command,
qemu-ga will not respond to stop operation. This behaviour is wanted on Linux
as there is no time limit for a freeze command and we want to prevent
quitting in the middle of freeze, on the other hand on Windows the time
limit for freeze is 10 seconds, so we should wait for the timeout, thaw
the file system and quit.

Signed-off-by: Sameeh Jubran 
Signed-off-by: Michael Roth 
---
 qga/main.c  | 23 +++
 qga/vss-win32.h |  1 +
 qga/vss-win32/vss-common.h  | 11 +--
 qga/vss-win32/vss-handles.h | 14 ++
 4 files changed, 39 insertions(+), 10 deletions(-)
 create mode 100644 qga/vss-win32/vss-handles.h

diff --git a/qga/main.c b/qga/main.c
index 07c2953..ad6f68f 100644
--- a/qga/main.c
+++ b/qga/main.c
@@ -131,9 +131,32 @@ static void quit_handler(int sig)
  * unless all log/pid files are on unfreezable filesystems. there's
  * also a very likely chance killing the agent before unfreezing
  * the filesystems is a mistake (or will be viewed as one later).
+ * On Windows the freeze interval is limited to 10 seconds, so
+ * we should quit, but first we should wait for the timeout, thaw
+ * the filesystem and quit.
  */
 if (ga_is_frozen(ga_state)) {
+#ifdef _WIN32
+int i = 0;
+Error *err = NULL;
+HANDLE hEventTimeout;
+
+g_debug("Thawing filesystems before exiting");
+
+hEventTimeout = OpenEvent(EVENT_ALL_ACCESS, FALSE, EVENT_NAME_TIMEOUT);
+if (hEventTimeout) {
+WaitForSingleObject(hEventTimeout, 0);
+CloseHandle(hEventTimeout);
+}
+qga_vss_fsfreeze(, false, );
+if (err) {
+g_debug("Error unfreezing filesystems prior to exiting: %s",
+error_get_pretty(err));
+error_free(err);
+}
+#else
 return;
+#endif
 }
 g_debug("received signal num %d, quitting", sig);
 
diff --git a/qga/vss-win32.h b/qga/vss-win32.h
index 51d303a..4f8e39a 100644
--- a/qga/vss-win32.h
+++ b/qga/vss-win32.h
@@ -13,6 +13,7 @@
 #ifndef VSS_WIN32_H
 #define VSS_WIN32_H
 
+#include "qga/vss-win32/vss-handles.h"
 
 bool vss_init(bool init_requester);
 void vss_deinit(bool deinit_requester);
diff --git a/qga/vss-win32/vss-common.h b/qga/vss-win32/vss-common.h
index c81a856..61c170b 100644
--- a/qga/vss-win32/vss-common.h
+++ b/qga/vss-win32/vss-common.h
@@ -51,21 +51,12 @@
  * http://www.microsoft.com/en-us/download/details.aspx?id=23490
  */
 #include 
+#include "vss-handles.h"
 
 /* Macros to convert char definitions to wchar */
 #define _L(a) L##a
 #define L(a) _L(a)
 
-/* Constants for QGA VSS Provider */
-
-#define QGA_PROVIDER_NAME "QEMU Guest Agent VSS Provider"
-#define QGA_PROVIDER_LNAME L(QGA_PROVIDER_NAME)
-#define QGA_PROVIDER_VERSION L(QEMU_VERSION)
-
-#define EVENT_NAME_FROZEN  "Global\\QGAVSSEvent-frozen"
-#define EVENT_NAME_THAW"Global\\QGAVSSEvent-thaw"
-#define EVENT_NAME_TIMEOUT "Global\\QGAVSSEvent-timeout"
-
 const GUID g_gProviderId = { 0x3629d4ed, 0xee09, 0x4e0e,
 {0x9a, 0x5c, 0x6d, 0x8b, 0xa2, 0x87, 0x2a, 0xef} };
 const GUID g_gProviderVersion = { 0x11ef8b15, 0xcac6, 0x40d6,
diff --git a/qga/vss-win32/vss-handles.h b/qga/vss-win32/vss-handles.h
new file mode 100644
index 000..ff399dd
--- /dev/null
+++ b/qga/vss-win32/vss-handles.h
@@ -0,0 +1,14 @@
+#ifndef VSS_HANDLES
+#define VSS_HANDLES
+
+/* Constants for QGA VSS Provider */
+
+#define QGA_PROVIDER_NAME "QEMU Guest Agent VSS Provider"
+#define QGA_PROVIDER_LNAME L(QGA_PROVIDER_NAME)
+#define QGA_PROVIDER_VERSION L(QEMU_VERSION)
+
+#define EVENT_NAME_FROZEN  "Global\\QGAVSSEvent-frozen"
+#define EVENT_NAME_THAW"Global\\QGAVSSEvent-thaw"
+#define EVENT_NAME_TIMEOUT "Global\\QGAVSSEvent-timeout"
+
+#endif
-- 
2.7.4




[Qemu-devel] [PULL 0/8] qemu-ga patch queue

2017-04-25 Thread Michael Roth
The following changes since commit fe491fa85c4634453b340b18046aae2eaf8147db:

  Merge remote-tracking branch 'remotes/agraf/tags/signed-s390-for-upstream' 
into staging (2017-04-25 14:48:55 +0100)

are available in the git repository at:

  git://github.com/mdroth/qemu.git tags/qga-pull-2017-04-25-tag

for you to fetch changes up to b3734da00e4285521f8eb2c958ab08b981f7a298:

  qga: Add `guest-get-timezone` command (2017-04-25 15:49:24 -0500)


qemu-ga patch queue

* new commands: guest-get-timezone, guest-get-users, guest-get-host-name
* fix hang on w32 when stopping qemu-ga service while fs frozen
* fix missing setting of can-offline in guest-get-vcpus
* make qemu-ga VSS w32 service on-demand rather than on-startup
* fix unecessary errors to EventLog on w32
* improvements to fsfreeze documentation


Marc-André Lureau (1):
  qga: improve fsfreeze documentations

Sameeh Jubran (4):
  qemu-ga: Make QGA VSS provider service run only when needed
  qga-win: Enable 'can-offline' field in 'guest-get-vcpus' reply
  qga-win: Fix a bug where qemu-ga service is stuck during stop operation
  qga-win: Fix Event Viewer errors caused by qemu-ga

Vinzenz Feenstra (3):
  qga: Add 'guest-get-host-name' command
  qga: Add 'guest-get-users' command
  qga: Add `guest-get-timezone` command

 configure   |   2 +-
 include/glib-compat.h   |   5 +++
 qga/commands-posix.c|  60 +
 qga/commands-win32.c| 105 +++-
 qga/commands.c  |  49 +
 qga/main.c  |  23 ++
 qga/qapi-schema.json|  87 +++-
 qga/vss-win32.h |   1 +
 qga/vss-win32/install.cpp   |  28 +++-
 qga/vss-win32/install.h |  20 +
 qga/vss-win32/provider.cpp  |   1 -
 qga/vss-win32/requester.cpp |   2 +
 qga/vss-win32/vss-common.h  |  11 +
 qga/vss-win32/vss-handles.h |  14 ++
 14 files changed, 391 insertions(+), 17 deletions(-)
 create mode 100644 qga/vss-win32/install.h
 create mode 100644 qga/vss-win32/vss-handles.h




[Qemu-devel] [PULL 6/8] qga: improve fsfreeze documentations

2017-04-25 Thread Michael Roth
From: Marc-André Lureau 

Some users find the fsfreeze behaviour confusing. Add some notes about
invalid mount points and Windows usage.

Related to:
https://bugzilla.redhat.com/show_bug.cgi?id=1436976

Signed-off-by: Marc-André Lureau 
Reviewed-by: Vinzenz Feenstra 
Signed-off-by: Michael Roth 
---
 qga/qapi-schema.json | 12 ++--
 1 file changed, 10 insertions(+), 2 deletions(-)

diff --git a/qga/qapi-schema.json b/qga/qapi-schema.json
index 6307ae2..0f4cba5 100644
--- a/qga/qapi-schema.json
+++ b/qga/qapi-schema.json
@@ -426,7 +426,13 @@
 ##
 # @guest-fsfreeze-freeze:
 #
-# Sync and freeze all freezable, local guest filesystems
+# Sync and freeze all freezable, local guest filesystems. If this
+# command succeeded, you may call @guest-fsfreeze-thaw later to
+# unfreeze.
+#
+# Note: On Windows, the command is implemented with the help of a
+# Volume Shadow-copy Service DLL helper. The frozen state is limited
+# for up to 10 seconds by VSS.
 #
 # Returns: Number of file systems currently frozen. On error, all filesystems
 # will be thawed.
@@ -439,10 +445,12 @@
 ##
 # @guest-fsfreeze-freeze-list:
 #
-# Sync and freeze specified guest filesystems
+# Sync and freeze specified guest filesystems.
+# See also @guest-fsfreeze-freeze.
 #
 # @mountpoints: an array of mountpoints of filesystems to be frozen.
 #   If omitted, every mounted filesystem is frozen.
+#   Invalid mount points are ignored.
 #
 # Returns: Number of file systems currently frozen. On error, all filesystems
 # will be thawed.
-- 
2.7.4




[Qemu-devel] [PULL 1/8] qemu-ga: Make QGA VSS provider service run only when needed

2017-04-25 Thread Michael Roth
From: Sameeh Jubran 

Currently the service runs in background on boot even though it is not
needed and once it is running it never stops. The service needs to be
running only during freeze operation and it should be stopped after
executing thaw.

Signed-off-by: Sameeh Jubran 
Signed-off-by: Michael Roth 
---
 qga/vss-win32/install.cpp   | 28 ++--
 qga/vss-win32/install.h | 20 
 qga/vss-win32/requester.cpp |  2 ++
 3 files changed, 48 insertions(+), 2 deletions(-)
 create mode 100644 qga/vss-win32/install.h

diff --git a/qga/vss-win32/install.cpp b/qga/vss-win32/install.cpp
index f4160a3..f41fcdf 100644
--- a/qga/vss-win32/install.cpp
+++ b/qga/vss-win32/install.cpp
@@ -14,7 +14,7 @@
 
 #include "vss-common.h"
 #include 
-#include 
+#include "install.h"
 #include 
 #include 
 #include 
@@ -276,7 +276,7 @@ STDAPI COMRegister(void)
 
 chk(pCatalog->CreateServiceForApplication(
 _bstr_t(QGA_PROVIDER_LNAME), _bstr_t(QGA_PROVIDER_LNAME),
-_bstr_t(L"SERVICE_AUTO_START"), _bstr_t(L"SERVICE_ERROR_NORMAL"),
+_bstr_t(L"SERVICE_DEMAND_START"), _bstr_t(L"SERVICE_ERROR_NORMAL"),
 _bstr_t(L""), _bstr_t(L".\\localsystem"), _bstr_t(L""), FALSE));
 chk(pCatalog->InstallComponent(_bstr_t(QGA_PROVIDER_LNAME),
_bstr_t(dllPath), _bstr_t(tlbPath),
@@ -461,3 +461,27 @@ namespace _com_util
 return bstr;
 }
 }
+
+/* Stop QGA VSS provider service from COM+ Application Admin Catalog */
+
+STDAPI StopService(void)
+{
+HRESULT hr;
+COMInitializer initializer;
+COMPointer pUnknown;
+COMPointer pCatalog;
+
+int count = 0;
+
+chk(QGAProviderFind(QGAProviderCount, (void *)));
+if (count) {
+chk(CoCreateInstance(CLSID_COMAdminCatalog, NULL, CLSCTX_INPROC_SERVER,
+IID_IUnknown, (void **)pUnknown.replace()));
+chk(pUnknown->QueryInterface(IID_ICOMAdminCatalog2,
+(void **)pCatalog.replace()));
+chk(pCatalog->ShutdownApplication(_bstr_t(QGA_PROVIDER_LNAME)));
+}
+
+out:
+return hr;
+}
diff --git a/qga/vss-win32/install.h b/qga/vss-win32/install.h
new file mode 100644
index 000..35364af
--- /dev/null
+++ b/qga/vss-win32/install.h
@@ -0,0 +1,20 @@
+/*
+ * QEMU Guest Agent VSS requester declarations
+ *
+ * Copyright Hitachi Data Systems Corp. 2013
+ *
+ * Authors:
+ *  Tomoki Sekiyama   
+ *
+ * This work is licensed under the terms of the GNU GPL, version 2 or later.
+ * See the COPYING file in the top-level directory.
+ */
+
+#ifndef INSTALL_H
+#define INSTALL_H
+
+#include 
+
+STDAPI StopService(void);
+
+#endif
diff --git a/qga/vss-win32/requester.cpp b/qga/vss-win32/requester.cpp
index 0cd2f0e..301762d 100644
--- a/qga/vss-win32/requester.cpp
+++ b/qga/vss-win32/requester.cpp
@@ -13,6 +13,7 @@
 #include "qemu/osdep.h"
 #include "vss-common.h"
 #include "requester.h"
+#include "install.h"
 #include 
 #include 
 
@@ -501,4 +502,5 @@ void requester_thaw(int *num_vols, ErrorSet *errset)
 requester_cleanup();
 
 CoUninitialize();
+StopService();
 }
-- 
2.7.4




[Qemu-devel] [PULL 4/8] qga-win: Fix Event Viewer errors caused by qemu-ga

2017-04-25 Thread Michael Roth
From: Sameeh Jubran 

When the command "guest-fsfreeze-freeze" is executed it causes
the VSS service to log the error below in the Event Viewer. This
error is caused by an issue in the function "CommitSnapshots" in
provider.cpp:

* When VSS_TIMEOUT_MSEC expires the funtion returns E_ABORT. This causes
the error #12293.

|event id|   error   |
* 12293  : Volume Shadow Copy Service error: Error calling a routine on a
   Shadow Copy Provider {----}.
   Routine details CommitSnapshots [hr = 0x80004004, Operation
   aborted.

Signed-off-by: Sameeh Jubran 
Signed-off-by: Michael Roth 
---
 qga/vss-win32/provider.cpp | 1 -
 1 file changed, 1 deletion(-)

diff --git a/qga/vss-win32/provider.cpp b/qga/vss-win32/provider.cpp
index ef94669..72d8b0e 100644
--- a/qga/vss-win32/provider.cpp
+++ b/qga/vss-win32/provider.cpp
@@ -377,7 +377,6 @@ STDMETHODIMP CQGAVssProvider::CommitSnapshots(VSS_ID 
SnapshotSetId)
 if (WaitForSingleObject(hEventThaw, VSS_TIMEOUT_MSEC) != WAIT_OBJECT_0) {
 /* Send event to qemu-ga to notify the provider is timed out */
 SetEvent(hEventTimeout);
-hr = E_ABORT;
 }
 
 CloseHandle(hEventThaw);
-- 
2.7.4




[Qemu-devel] [PULL 2/8] qga-win: Enable 'can-offline' field in 'guest-get-vcpus' reply

2017-04-25 Thread Michael Roth
From: Sameeh Jubran 

The QGA schema states:

@can-offline: Whether offlining the VCPU is possible. This member
   is always filled in by the guest agent when the structure
   is returned, and always ignored on input (hence it can be
   omitted then).

Currently 'can-offline' is missing entirely from the reply. This causes
errors in libvirt which is expecting the reply to be compliant with the
schema docs.

BZ#1438735: https://bugzilla.redhat.com/show_bug.cgi?id=1438735

Signed-off-by: Sameeh Jubran 
Reviewed-by: Eric Blake 
Cc: qemu-sta...@nongnu.org
Signed-off-by: Michael Roth 
---
 qga/commands-win32.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/qga/commands-win32.c b/qga/commands-win32.c
index 04026ee..9fec1fb 100644
--- a/qga/commands-win32.c
+++ b/qga/commands-win32.c
@@ -1344,7 +1344,7 @@ GuestLogicalProcessorList *qmp_guest_get_vcpus(Error 
**errp)
 vcpu = g_malloc0(sizeof *vcpu);
 vcpu->logical_id = current++;
 vcpu->online = true;
-vcpu->has_can_offline = false;
+vcpu->has_can_offline = true;
 
 entry = g_malloc0(sizeof *entry);
 entry->value = vcpu;
-- 
2.7.4




[Qemu-devel] [PULL 8/8] qga: Add `guest-get-timezone` command

2017-04-25 Thread Michael Roth
From: Vinzenz Feenstra 

Adds a new command `guest-get-timezone` reporting the currently
configured timezone on the system. The information on what timezone is
currently is configured is useful in case of Windows VMs where the
offset of the hardware clock is required to have the same offset. This
can be used for management systems like `oVirt` to detect the timezone
difference and warn administrators of the misconfiguration.

Signed-off-by: Vinzenz Feenstra 
Reviewed-by: Sameeh Jubran 
Tested-by: Sameeh Jubran 
* moved stub implementation to end of function for consistency
Signed-off-by: Michael Roth 
---
 qga/commands.c   | 38 ++
 qga/qapi-schema.json | 24 
 2 files changed, 62 insertions(+)

diff --git a/qga/commands.c b/qga/commands.c
index 57a31bb..ed5 100644
--- a/qga/commands.c
+++ b/qga/commands.c
@@ -510,3 +510,41 @@ GuestHostName *qmp_guest_get_host_name(Error **err)
 }
 return result;
 }
+
+GuestTimezone *qmp_guest_get_timezone(Error **errp)
+{
+#if GLIB_CHECK_VERSION(2, 28, 0)
+GuestTimezone *info = NULL;
+GTimeZone *tz = NULL;
+gint64 now = 0;
+gint32 intv = 0;
+gchar const *name = NULL;
+
+info = g_new0(GuestTimezone, 1);
+tz = g_time_zone_new_local();
+if (tz == NULL) {
+error_setg(errp, QERR_QGA_COMMAND_FAILED,
+   "Couldn't retrieve local timezone");
+goto error;
+}
+
+now = g_get_real_time() / G_USEC_PER_SEC;
+intv = g_time_zone_find_interval(tz, G_TIME_TYPE_UNIVERSAL, now);
+info->offset = g_time_zone_get_offset(tz, intv);
+name = g_time_zone_get_abbreviation(tz, intv);
+if (name != NULL) {
+info->has_zone = true;
+info->zone = g_strdup(name);
+}
+g_time_zone_unref(tz);
+
+return info;
+
+error:
+g_free(info);
+return NULL;
+#else
+error_setg(errp, QERR_UNSUPPORTED);
+return NULL;
+#endif
+}
diff --git a/qga/qapi-schema.json b/qga/qapi-schema.json
index f25467a..5c325b1 100644
--- a/qga/qapi-schema.json
+++ b/qga/qapi-schema.json
@@ -1101,3 +1101,27 @@
 ##
 { 'command': 'guest-get-users',
   'returns': ['GuestUser'] }
+
+##
+# @GuestTimezone:
+#
+# @zone:Timezone name
+# @offset:  Offset to UTC in seconds, negative numbers for time zones west of
+#   GMT, positive numbers for east
+#
+# Since: 2.10
+##
+{ 'struct': 'GuestTimezone',
+  'data':   { '*zone': 'str', 'offset': 'int' } }
+
+##
+# @guest-get-timezone:
+#
+# Retrieves the timezone information from the guest.
+#
+# Returns: A GuestTimezone dictionary.
+#
+# Since: 2.10
+##
+{ 'command': 'guest-get-timezone',
+  'returns': 'GuestTimezone' }
-- 
2.7.4




Re: [Qemu-devel] [PATCH 3/4] migration: spapr: migrate ccs_list in spapr state

2017-04-25 Thread Michael Roth
Quoting Daniel Henrique Barboza (2017-04-24 17:08:27)
> From: Jianjun Duan 
> 
> ccs_list in spapr state maintains the device tree related
> information on the rtas side for hotplugged devices. In racing
> situations between hotplug events and migration operation, a rtas
> hotplug event could be migrated from the source guest to target
> guest, or the source guest could have not yet finished fetching
> the device tree when migration is started, the target will try
> to finish fetching the device tree. By migrating ccs_list, the
> target can fetch the device tree properly.
> 
> In theory there would be other alternatives besides migrating the
> css_list to fix this. For example, we could add a flag that indicates
> whether a device is in the middle of the configure_connector during the
> migration process, in the post_load we can detect if this flag
> is active and then return an error informing the guest to restart the
> hotplug process. However, the DRC state can still be modified outside of
> hotplug. Using:
> 
>drmgr -c pci -s  -r
>drmgr -c pci -s  -a
> 
> it is possible to return a device to firmware and then later take it
> back and reconfigure it. This is not a common case but it's not prohibited,
> and performing a migration between these 2 operations would fail because
> the default coldplug state on target assumes a configured state in
> the source*. Migrating ccs_list is one solution that cover this
> case as well.
> 
> ccs_list is put in a subsection in the spapr state VMSD to make
> sure migration across different versions is not broken.
> 
> * see http://lists.nongnu.org/archive/html/qemu-devel/2016-10/msg01763.html
> for more information on this discussion.
> 
> Signed-off-by: Jianjun Duan 
> Signed-off-by: Daniel Henrique Barboza 
> ---
>  hw/ppc/spapr.c | 32 
>  1 file changed, 32 insertions(+)
> 
> diff --git a/hw/ppc/spapr.c b/hw/ppc/spapr.c
> index 35db949..22f351c 100644
> --- a/hw/ppc/spapr.c
> +++ b/hw/ppc/spapr.c
> @@ -1388,6 +1388,37 @@ static bool version_before_3(void *opaque, int 
> version_id)
>  return version_id < 3;
>  }
> 
> +static bool spapr_ccs_list_needed(void *opaque)
> +{
> +sPAPRMachineState *spapr = (sPAPRMachineState *)opaque;
> +return !QTAILQ_EMPTY(>ccs_list);
> +}
> +
> +static const VMStateDescription vmstate_spapr_ccs = {
> +.name = "spaprconfigureconnectorstate",

some word separators wouldn't hurt, since they might show up in
migration error messages.

> +.version_id = 1,
> +.minimum_version_id = 1,
> +.fields = (VMStateField[]) {
> +VMSTATE_UINT32(drc_index, sPAPRConfigureConnectorState),
> +VMSTATE_INT32(fdt_offset, sPAPRConfigureConnectorState),
> +VMSTATE_INT32(fdt_depth, sPAPRConfigureConnectorState),
> +VMSTATE_END_OF_LIST()
> +},
> +};
> +
> +static const VMStateDescription vmstate_spapr_ccs_list = {
> +.name = "spaprccslist",
> +.version_id = 1,
> +.minimum_version_id = 1,
> +.needed = spapr_ccs_list_needed,
> +.fields = (VMStateField[]) {
> +VMSTATE_QTAILQ_V(ccs_list, sPAPRMachineState, 1,
> + vmstate_spapr_ccs, sPAPRConfigureConnectorState,
> + next),
> +VMSTATE_END_OF_LIST()
> +},
> +};
> +
>  static bool spapr_ov5_cas_needed(void *opaque)
>  {
>  sPAPRMachineState *spapr = opaque;
> @@ -1486,6 +1517,7 @@ static const VMStateDescription vmstate_spapr = {
>  .subsections = (const VMStateDescription*[]) {
>  _spapr_ov5_cas,
>  _spapr_patb_entry,
> +_spapr_ccs_list,
>  NULL
>  }
>  };
> -- 
> 2.9.3
> 
> 




[Qemu-devel] [PATCH 25/26] audio: un-export OPLResetChip

2017-04-25 Thread Juan Quintela
Signed-off-by: Juan Quintela 
---
 hw/audio/fmopl.c | 2 +-
 hw/audio/fmopl.h | 1 -
 2 files changed, 1 insertion(+), 2 deletions(-)

diff --git a/hw/audio/fmopl.c b/hw/audio/fmopl.c
index 99d09c5..dc9043c 100644
--- a/hw/audio/fmopl.c
+++ b/hw/audio/fmopl.c
@@ -1036,7 +1036,7 @@ void YM3812UpdateOne(FM_OPL *OPL, int16_t *buffer, int 
length)
 }
 
 /* -- reset one of chip -- */
-void OPLResetChip(FM_OPL *OPL)
+static void OPLResetChip(FM_OPL *OPL)
 {
int c,s;
int i;
diff --git a/hw/audio/fmopl.h b/hw/audio/fmopl.h
index f89af08..fc9f16b 100644
--- a/hw/audio/fmopl.h
+++ b/hw/audio/fmopl.h
@@ -95,7 +95,6 @@ FM_OPL *OPLCreate(int clock, int rate);
 void OPLDestroy(FM_OPL *OPL);
 void OPLSetTimerHandler(FM_OPL *OPL,OPL_TIMERHANDLER TimerHandler,int 
channelOffset);
 
-void OPLResetChip(FM_OPL *OPL);
 int OPLWrite(FM_OPL *OPL,int a,int v);
 unsigned char OPLRead(FM_OPL *OPL,int a);
 int OPLTimerOver(FM_OPL *OPL,int c);
-- 
2.9.3




Re: [Qemu-devel] [PATCH] RFC: vmcoreinfo device

2017-04-25 Thread Eduardo Habkost
On Tue, Apr 25, 2017 at 11:35:23PM +0300, Michael S. Tsirkin wrote:
> On Tue, Apr 25, 2017 at 05:29:20PM -0300, Eduardo Habkost wrote:
> > On Mon, Apr 24, 2017 at 05:03:55PM +0400, Marc-André Lureau wrote:
> > [...]
> > > diff --git a/include/hw/compat.h b/include/hw/compat.h
> > > index 5d5be91daf..d0c9b71902 100644
> > > --- a/include/hw/compat.h
> > > +++ b/include/hw/compat.h
> > > @@ -135,6 +135,10 @@
> > >  .driver   = "vmgenid",\
> > >  .property = "x-write-pointer-available",\
> > >  .value= "off",\
> > > +},{\
> > > +.driver   = "vmcoreinfo",\
> > > +.property = "x-write-pointer-available",\
> > > +.value= "off",\
> > >  },
> > 
> > My first reaction to this was "we don't need this compat property, because 
> > the
> > device didn't even exist in QEMU 2.4".
> > 
> > But then I read commit f2a1ae45d8ec5ad494e66a9234499a2e0fbf4b40 and now I 
> > see
> > why this is required: this is a compat property whose sole function is to
> > prevent the device from being instantiated.
> > 
> > Instead of requiring an extra compat property, I suggest just checking if
> > fw_cfg has DMA enabled. e.g.:
> > 
> >  static void vmgenid_realize(DeviceState *dev, Error **errp)
> >  {
> >  VmGenIdState *vms = VMGENID(dev);
> > +FWCfgState *fw_cfg = FW_CFG(object_resolve_path_type("", TYPE_FW_CFG, 
> > NULL));
> > 
> > -if (!vms->write_pointer_available) {
> > +if (!fw_cfg || !fw_cfg_dma_enabled(fw_cfg)) {
> >  error_setg(errp, "%s requires DMA write support in fw_cfg, "
> > "which this machine type does not provide", 
> > VMGENID_DEVICE);
> >  return;
> > 
> > 
> > This has the additional benefit of handling other cases properly, like:
> > 
> >   $ qemu-system-x86_64 -device vmgenid -machine none
> >   qemu-system-x86_64: -device vmgenid: vmgenid requires DMA write support 
> > in fw_cfg, which this machine type does not provide
> >   $ qemu-system-x86_64 -device vmgenid -machine pc-i440fx-2.9 -global 
> > fw_cfg.dma_enabled=off
> >   qemu-system-x86_64: -device vmgenid: vmgenid requires DMA write support 
> > in fw_cfg, which this machine type does not provide
> >   $ qemu-system-x86_64 -device vmgenid -machine pc-i440fx-2.6 -global 
> > fw_cfg.dma_enabled=on
> >   [boots normally]
> >   $
> 
> It's quite ugly to make it poke at fw cfg internals though,
> it shouldn't know how is write pointer implemented.
> We need some kind of API that it can share with vm gen id.

Do you mean adding something like this to bios-linker-loader.c?

  bool bios_linker_loader_can_write_pointer(void)
  {
  FWCfgState *fw_cfg = FW_CFG(object_resolve_path_type("", TYPE_FW_CFG, 
NULL));
  return fw_cfg && fw_cfg_dma_enabled(fw_cfg);
  }

-- 
Eduardo



[Qemu-devel] [PATCH 24/26] audio: Remove unused typedefs

2017-04-25 Thread Juan Quintela
Signed-off-by: Juan Quintela 
---
 hw/audio/fmopl.h | 4 
 1 file changed, 4 deletions(-)

diff --git a/hw/audio/fmopl.h b/hw/audio/fmopl.h
index 8410275..f89af08 100644
--- a/hw/audio/fmopl.h
+++ b/hw/audio/fmopl.h
@@ -4,10 +4,6 @@
 #include 
 
 typedef void (*OPL_TIMERHANDLER)(int channel,double interval_Sec);
-typedef void (*OPL_IRQHANDLER)(int param,int irq);
-typedef void (*OPL_UPDATEHANDLER)(int param,int min_interval_us);
-typedef void (*OPL_PORTHANDLER_W)(int param,unsigned char data);
-typedef unsigned char (*OPL_PORTHANDLER_R)(int param);
 
 /* ! here is private section , do not access there member direct ! */
 
-- 
2.9.3




Re: [Qemu-devel] [PATCH 4/4] migration: spapr: migrate pending_events of spapr state

2017-04-25 Thread Michael Roth
Quoting Daniel Henrique Barboza (2017-04-24 17:08:28)
> From: Jianjun Duan 
> 
> In racing situations between hotplug events and migration operation,
> a rtas hotplug event could have not yet be delivered to the source
> guest when migration is started. In this case the pending_events of
> spapr state need be transmitted to the target so that the hotplug
> event can be finished on the target.
> 
> All the different fields of the events are encoded as defined by
> PAPR. We can migrate them as uint8_t binary stream without any
> concerns about data padding or endianess.
> 
> pending_events is put in a subsection in the spapr state VMSD to make
> sure migration across different versions is not broken.
> 
> Signed-off-by: Jianjun Duan 
> Signed-off-by: Daniel Henrique Barboza 
> ---
>  hw/ppc/spapr.c | 33 +
>  hw/ppc/spapr_events.c  | 24 +---
>  include/hw/ppc/spapr.h |  3 ++-
>  3 files changed, 48 insertions(+), 12 deletions(-)
> 
> diff --git a/hw/ppc/spapr.c b/hw/ppc/spapr.c
> index 22f351c..a3e939b 100644
> --- a/hw/ppc/spapr.c
> +++ b/hw/ppc/spapr.c
> @@ -1419,6 +1419,38 @@ static const VMStateDescription vmstate_spapr_ccs_list 
> = {
>  },
>  };
> 
> +static bool spapr_pending_events_needed(void *opaque)
> +{
> +sPAPRMachineState *spapr = (sPAPRMachineState *)opaque;
> +return !QTAILQ_EMPTY(>pending_events);
> +}
> +
> +static const VMStateDescription vmstate_spapr_event_entry = {
> +.name = "spapreventlogentry",

Similar suggestion on the naming here and elsewhere.

> +.version_id = 1,
> +.minimum_version_id = 1,
> +.fields = (VMStateField[]) {
> +VMSTATE_INT32(log_type, sPAPREventLogEntry),
> +VMSTATE_BOOL(exception, sPAPREventLogEntry),
> +VMSTATE_UINT32(data_size, sPAPREventLogEntry),
> +VMSTATE_VARRAY_UINT32_ALLOC(data, sPAPREventLogEntry, data_size,
> +0, vmstate_info_uint8, uint8_t),
> +VMSTATE_END_OF_LIST()
> +},
> +};
> +
> +static const VMStateDescription vmstate_spapr_pending_events = {
> +.name = "spaprpendingevents",
> +.version_id = 1,
> +.minimum_version_id = 1,
> +.needed = spapr_pending_events_needed,
> +.fields = (VMStateField[]) {
> +VMSTATE_QTAILQ_V(pending_events, sPAPRMachineState, 1,
> + vmstate_spapr_event_entry, sPAPREventLogEntry, 
> next),
> +VMSTATE_END_OF_LIST()
> +},
> +};
> +
>  static bool spapr_ov5_cas_needed(void *opaque)
>  {
>  sPAPRMachineState *spapr = opaque;
> @@ -1518,6 +1550,7 @@ static const VMStateDescription vmstate_spapr = {
>  _spapr_ov5_cas,
>  _spapr_patb_entry,
>  _spapr_ccs_list,
> +_spapr_pending_events,
>  NULL
>  }
>  };
> diff --git a/hw/ppc/spapr_events.c b/hw/ppc/spapr_events.c
> index 24a5758..399dd49 100644
> --- a/hw/ppc/spapr_events.c
> +++ b/hw/ppc/spapr_events.c
> @@ -342,7 +342,8 @@ static int rtas_event_log_to_irq(sPAPRMachineState 
> *spapr, int log_type)
>  return source->irq;
>  }
> 
> -static void rtas_event_log_queue(int log_type, void *data, bool exception)
> +static void rtas_event_log_queue(int log_type, void *data, bool exception,
> + int data_size)
>  {
>  sPAPRMachineState *spapr = SPAPR_MACHINE(qdev_get_machine());
>  sPAPREventLogEntry *entry = g_new(sPAPREventLogEntry, 1);
> @@ -351,6 +352,7 @@ static void rtas_event_log_queue(int log_type, void 
> *data, bool exception)
>  entry->log_type = log_type;
>  entry->exception = exception;
>  entry->data = data;
> +entry->data_size = data_size;
>  QTAILQ_INSERT_TAIL(>pending_events, entry, next);
>  }
> 
> @@ -445,6 +447,7 @@ static void spapr_powerdown_req(Notifier *n, void *opaque)
>  struct rtas_event_log_v6_mainb *mainb;
>  struct rtas_event_log_v6_epow *epow;
>  struct epow_log_full *new_epow;
> +uint32_t data_size;
> 
>  new_epow = g_malloc0(sizeof(*new_epow));
>  hdr = _epow->hdr;
> @@ -453,14 +456,13 @@ static void spapr_powerdown_req(Notifier *n, void 
> *opaque)
>  mainb = _epow->mainb;
>  epow = _epow->epow;
> 
> +data_size = sizeof(*new_epow);
>  hdr->summary = cpu_to_be32(RTAS_LOG_VERSION_6
> | RTAS_LOG_SEVERITY_EVENT
> | RTAS_LOG_DISPOSITION_NOT_RECOVERED
> | RTAS_LOG_OPTIONAL_PART_PRESENT
> | RTAS_LOG_TYPE_EPOW);
> -hdr->extended_length = cpu_to_be32(sizeof(*new_epow)
> -   - sizeof(new_epow->hdr));
> -
> +hdr->extended_length = cpu_to_be32(data_size - sizeof(new_epow->hdr));
>  spapr_init_v6hdr(v6hdr);
>  spapr_init_maina(maina, 3 /* Main-A, Main-B and EPOW */);
> 
> @@ -479,7 +481,7 @@ static void spapr_powerdown_req(Notifier *n, 

[Qemu-devel] [PATCH 21/26] audio: OPLSetUpdateHandler is not used anywhere

2017-04-25 Thread Juan Quintela
Signed-off-by: Juan Quintela 
---
 hw/audio/fmopl.c | 6 +-
 hw/audio/fmopl.h | 1 -
 2 files changed, 1 insertion(+), 6 deletions(-)

diff --git a/hw/audio/fmopl.c b/hw/audio/fmopl.c
index f91e700..694a77b 100644
--- a/hw/audio/fmopl.c
+++ b/hw/audio/fmopl.c
@@ -1141,11 +1141,7 @@ void OPLSetTimerHandler(FM_OPL *OPL,OPL_TIMERHANDLER 
TimerHandler,int channelOff
OPL->TimerHandler   = TimerHandler;
OPL->TimerParam = channelOffset;
 }
-void OPLSetUpdateHandler(FM_OPL *OPL,OPL_UPDATEHANDLER UpdateHandler,int param)
-{
-   OPL->UpdateHandler = UpdateHandler;
-   OPL->UpdateParam = param;
-}
+
 /* -- YM3812 I/O interface -- */
 int OPLWrite(FM_OPL *OPL,int a,int v)
 {
diff --git a/hw/audio/fmopl.h b/hw/audio/fmopl.h
index 375f971..446de08 100644
--- a/hw/audio/fmopl.h
+++ b/hw/audio/fmopl.h
@@ -102,7 +102,6 @@ typedef struct fm_opl_f {
 FM_OPL *OPLCreate(int clock, int rate);
 void OPLDestroy(FM_OPL *OPL);
 void OPLSetTimerHandler(FM_OPL *OPL,OPL_TIMERHANDLER TimerHandler,int 
channelOffset);
-void OPLSetUpdateHandler(FM_OPL *OPL,OPL_UPDATEHANDLER UpdateHandler,int 
param);
 
 void OPLResetChip(FM_OPL *OPL);
 int OPLWrite(FM_OPL *OPL,int a,int v);
-- 
2.9.3




[Qemu-devel] [PATCH 15/26] audio: GUSbyte is uint8_t

2017-04-25 Thread Juan Quintela
Signed-off-by: Juan Quintela 
---
 hw/audio/gusemu.h   |  6 ++---
 hw/audio/gusemu_hal.c   | 58 -
 hw/audio/gusemu_mixer.c |  4 ++--
 3 files changed, 33 insertions(+), 35 deletions(-)

diff --git a/hw/audio/gusemu.h b/hw/audio/gusemu.h
index 9aec7bf..3a69222 100644
--- a/hw/audio/gusemu.h
+++ b/hw/audio/gusemu.h
@@ -28,14 +28,12 @@
 /* data types (need to be adjusted if neither a VC6 nor a C99 compatible 
compiler is used) */
 
 #if defined _WIN32 && defined _MSC_VER /* doesn't support other win32 
compilers yet, do it yourself... */
- typedef unsigned char GUSbyte;
  typedef unsigned short GUSword;
  typedef unsigned int GUSdword;
  typedef signed char GUSchar;
  typedef signed short GUSsample;
 #else
  typedef int8_t GUSchar;
- typedef uint8_t GUSbyte;
  typedef uint16_t GUSword;
  typedef uint32_t GUSdword;
  typedef int16_t GUSsample;
@@ -43,8 +41,8 @@
 
 typedef struct _GUSEmuState
 {
- GUSbyte *himemaddr; /* 1024*1024 bytes used for storing uploaded samples (+32 
additional bytes for read padding) */
- GUSbyte *gusdatapos; /* (gusdataend-gusdata) bytes used for storing emulated 
GF1/mixer register states (32*32+4 bytes in initial GUSemu32 version) */
+ uint8_t *himemaddr; /* 1024*1024 bytes used for storing uploaded samples (+32 
additional bytes for read padding) */
+ uint8_t *gusdatapos; /* (gusdataend-gusdata) bytes used for storing emulated 
GF1/mixer register states (32*32+4 bytes in initial GUSemu32 version) */
  uint32_t gusirq;
  uint32_t gusdma;
  unsigned int timer1fraction;
diff --git a/hw/audio/gusemu_hal.c b/hw/audio/gusemu_hal.c
index 973d6b9..444a2bb 100644
--- a/hw/audio/gusemu_hal.c
+++ b/hw/audio/gusemu_hal.c
@@ -39,7 +39,7 @@ unsigned int gus_read(GUSEmuState * state, int port, int size)
 {
 int value_read = 0;
 
-GUSbyte*gusptr;
+uint8_t*gusptr;
 gusptr = state->gusdatapos;
 GUSregd(portaccesses)++;
 
@@ -125,7 +125,7 @@ unsigned int gus_read(GUSEmuState * state, int port, int 
size)
 if (!GUSregb(IRQStatReg2x6))
 GUS_irqclear(state, state->gusirq);
 }
-return (GUSbyte) value_read;
+return (uint8_t) value_read;
 /* DramDMAmemPosReg */
 /* case 0x42: value_read=GUSregw(GUS42DMAStart); break;*/
 /* 43h+44h write only */
@@ -178,7 +178,7 @@ unsigned int gus_read(GUSEmuState * state, int port, int 
size)
 /*  return 0xff; */ /* Pre 3.6 boards, ICS mixer NOT present */
 case 0x307: /* DRAMaccess */
 {
-GUSbyte*adr;
+uint8_t*adr;
 adr = state->himemaddr + (GUSregd(GUSDRAMPOS24bit) & 0xf);
 return *adr;
 }
@@ -189,14 +189,14 @@ unsigned int gus_read(GUSEmuState * state, int port, int 
size)
 
 void gus_write(GUSEmuState * state, int port, int size, unsigned int data)
 {
-GUSbyte*gusptr;
+uint8_t*gusptr;
 gusptr = state->gusdatapos;
 GUSregd(portaccesses)++;
 
 switch (port & 0xff0f)
 {
 case 0x200: /* MixerCtrlReg */
-GUSregb(MixerCtrlReg2x0) = (GUSbyte) data;
+GUSregb(MixerCtrlReg2x0) = (uint8_t) data;
 break;
 case 0x206: /* IRQstatReg / SB2x6IRQ */
 if (GUSregb(GUS45TimerCtrl) & 0x20) /* SB IRQ enabled? -> set 2x6IRQ 
bit */
@@ -208,7 +208,7 @@ void gus_write(GUSEmuState * state, int port, int size, 
unsigned int data)
 break;
 case 0x308:/* AdLib 388h */
 case 0x208:/* AdLibCommandReg */
-GUSregb(AdLibCommand2xA) = (GUSbyte) data;
+GUSregb(AdLibCommand2xA) = (uint8_t) data;
 break;
 case 0x309:/* AdLib 389h */
 case 0x209:/* AdLibDataReg */
@@ -217,11 +217,11 @@ void gus_write(GUSEmuState * state, int port, int size, 
unsigned int data)
 if (data & 0x80)
 GUSregb(TimerStatus2x8) &= 0x1f; /* AdLib IRQ reset? -> clear 
maskable adl. timer int regs */
 else
-GUSregb(TimerDataReg2x9) = (GUSbyte) data;
+GUSregb(TimerDataReg2x9) = (uint8_t) data;
 }
 else
 {
-GUSregb(AdLibData2x9) = (GUSbyte) data;
+GUSregb(AdLibData2x9) = (uint8_t) data;
 if (GUSregb(GUS45TimerCtrl) & 0x02)
 {
 GUSregb(TimerStatus2x8) |= 0x01;
@@ -231,16 +231,16 @@ void gus_write(GUSEmuState * state, int port, int size, 
unsigned int data)
 }
 break;
 case 0x20A:
-GUSregb(AdLibStatus2x8) = (GUSbyte) data;
+GUSregb(AdLibStatus2x8) = (uint8_t) data;
 break; /* AdLibStatus2x8 */
 case 0x20B:/* GUS hidden registers */
 switch (GUSregb(RegCtrl_2xF) & 0x7)
 {
 case 0:
 if 

[Qemu-devel] [PATCH 16/26] audio: remove GUSchar

2017-04-25 Thread Juan Quintela
Signed-off-by: Juan Quintela 
---
 hw/audio/gusemu.h   | 2 --
 hw/audio/gusemu_mixer.c | 8 
 2 files changed, 4 insertions(+), 6 deletions(-)

diff --git a/hw/audio/gusemu.h b/hw/audio/gusemu.h
index 3a69222..1c1a63c 100644
--- a/hw/audio/gusemu.h
+++ b/hw/audio/gusemu.h
@@ -30,10 +30,8 @@
 #if defined _WIN32 && defined _MSC_VER /* doesn't support other win32 
compilers yet, do it yourself... */
  typedef unsigned short GUSword;
  typedef unsigned int GUSdword;
- typedef signed char GUSchar;
  typedef signed short GUSsample;
 #else
- typedef int8_t GUSchar;
  typedef uint16_t GUSword;
  typedef uint32_t GUSdword;
  typedef int16_t GUSsample;
diff --git a/hw/audio/gusemu_mixer.c b/hw/audio/gusemu_mixer.c
index d255ac8..b189db9 100644
--- a/hw/audio/gusemu_mixer.c
+++ b/hw/audio/gusemu_mixer.c
@@ -85,16 +85,16 @@ void gus_mixvoices(GUSEmuState * state, unsigned int 
playback_freq, unsigned int
 if (GUSvoice(wVSRControl) & 0x400)  /* 16bit */
 {
 int offset = ((CurrPos >> 9) & 0xc) + (((CurrPos >> 9) 
& 0x1) << 1);
-GUSchar *adr;
-adr = (GUSchar *) state->himemaddr + offset;
+int8_t *adr;
+adr = (int8_t *) state->himemaddr + offset;
 sample1 = (*adr & 0xff) + (*(adr + 1) * 256);
 sample2 = (*(adr + 2) & 0xff) + (*(adr + 2 + 1) * 256);
 }
 else/* 8bit */
 {
 int offset = (CurrPos >> 9) & 0xf;
-GUSchar *adr;
-adr = (GUSchar *) state->himemaddr + offset;
+int8_t *adr;
+adr = (int8_t *) state->himemaddr + offset;
 sample1 = (*adr) * 256;
 sample2 = (*(adr + 1)) * 256;
 }
-- 
2.9.3




[Qemu-devel] [PATCH 14/26] audio: Remove unused fields

2017-04-25 Thread Juan Quintela
These were used for the remove stuff.

Signed-off-by: Juan Quintela 
---
 hw/audio/fmopl.h | 6 --
 1 file changed, 6 deletions(-)

diff --git a/hw/audio/fmopl.h b/hw/audio/fmopl.h
index df790a0..8730ead 100644
--- a/hw/audio/fmopl.h
+++ b/hw/audio/fmopl.h
@@ -76,12 +76,6 @@ typedef struct fm_opl_f {
int max_ch; /* maximum channel   */
/* Rhythm sention */
uint8_t rhythm; /* Rhythm mode , key flag */
-   OPL_PORTHANDLER_R porthandler_r;
-   OPL_PORTHANDLER_W porthandler_w;
-   int port_param;
-   OPL_PORTHANDLER_R keyboardhandler_r;
-   OPL_PORTHANDLER_W keyboardhandler_w;
-   int keyboard_param;
/* time tables */
int32_t AR_TABLE[75];   /* atttack rate tables */
int32_t DR_TABLE[75];   /* decay rate tables   */
-- 
2.9.3




Re: [Qemu-devel] [PATCH 2/4] hw/ppc: migrating the DRC state of hotplugged devices

2017-04-25 Thread Michael Roth
Quoting Daniel Henrique Barboza (2017-04-24 17:08:26)
> In pseries, a firmware abstraction called Dynamic Reconfiguration
> Connector (DRC) is used to assign a particular dynamic resource
> to the guest and provide an interface to manage configuration/removal
> of the resource associated with it. In other words, DRC is the
> 'plugged state' of a device.
> 
> Before this patch, DRC wasn't being migrated. This causes
> post-migration problems due to DRC state mismatch between source and
> target. The DRC state of a device X in the source might
> change, while in the target the DRC state of X is still fresh. When
> migrating the guest, X will not have the same hotplugged state as it
> did in the source. This means that we can't hot unplug X in the
> target after migration is completed because its DRC state is not consistent.
> https://bugs.launchpad.net/ubuntu/+source/qemu/+bug/1677552 is one
> bug that is caused by this DRC state mismatch between source and
> target.
> 
> To migrate the DRC state, we defined the VMStateDescription struct for
> spapr_drc to enable the transmission of spapr_drc state in migration.
> Not all the elements in the DRC state are migrated - only those
> that can be modified by guest actions or device add/remove
> operations:
> 
> - 'isolation_state', 'allocation_state' and 'configured' are involved
> in the DR state transition diagram from PAPR+ 2.7, 13.4;
> 
> - 'configured' and 'signalled' are needed in attaching and detaching
> devices;
> 
> - 'indicator_state' provides users with hardware state information.
> 
> These are the DRC elements that are migrated.
> 
> In this patch the DRC state is migrated for PCI, LMB and CPU
> connector types. At this moment there is no support to migrate
> DRC for the PHB (PCI Host Bridge) type.
> 
> The instance_id is used to identify objects in migration. We set
> instance_id of DRC using the unique index so that it is the same
> across migration.
> 
> In hw/ppc/spapr_pci.c, a function called spapr_pci_set_detach_cb
> was created to set the detach_cb of the migrated DRC in the
> spapr_pci_post_load. The reason is that detach_cb is a DRC function
> pointer that can't be migrated but we need it set in the target
> so a ongoing hot-unplug event can properly finish.
> 
> Signed-off-by: Daniel Henrique Barboza 
> ---
>  hw/ppc/spapr_drc.c | 67 
> ++
>  hw/ppc/spapr_pci.c | 22 ++
>  2 files changed, 89 insertions(+)
> 
> diff --git a/hw/ppc/spapr_drc.c b/hw/ppc/spapr_drc.c
> index a1cdc87..5c2baad 100644
> --- a/hw/ppc/spapr_drc.c
> +++ b/hw/ppc/spapr_drc.c
> @@ -651,6 +651,70 @@ static void spapr_dr_connector_instance_init(Object *obj)
>  NULL, NULL, NULL, NULL);
>  }
> 
> +static bool spapr_drc_needed(void *opaque)
> +{
> +sPAPRDRConnector *drc = (sPAPRDRConnector *)opaque;
> +sPAPRDRConnectorClass *drck = SPAPR_DR_CONNECTOR_GET_CLASS(drc);
> +bool rc = false;
> +sPAPRDREntitySense value;
> +drck->entity_sense(drc, );
> +/* If no dev is plugged in there is no need to migrate the DRC state */
> +if (value != SPAPR_DR_ENTITY_SENSE_PRESENT) {
> +return false;
> +}
> +
> +/*
> + * If there is dev plugged in, we need to migrate the DRC state when
> + * it is different from cold-plugged state
> + */
> +switch (drc->type) {
> +
> +case SPAPR_DR_CONNECTOR_TYPE_PCI:
> +rc = !((drc->isolation_state == SPAPR_DR_ISOLATION_STATE_UNISOLATED) 
> &&
> +   (drc->allocation_state == SPAPR_DR_ALLOCATION_STATE_USABLE) &&
> +   drc->configured && drc->signalled && !drc->awaiting_release);
> +break;
> +
> +case SPAPR_DR_CONNECTOR_TYPE_LMB:
> +rc = !((drc->isolation_state == SPAPR_DR_ISOLATION_STATE_ISOLATED) &&
> +   (drc->allocation_state == SPAPR_DR_ALLOCATION_STATE_UNUSABLE) 
> &&
> +   drc->configured && drc->signalled && !drc->awaiting_release);
> +break;
> +
> +case SPAPR_DR_CONNECTOR_TYPE_CPU:
> +rc = !((drc->isolation_state == SPAPR_DR_ISOLATION_STATE_ISOLATED) &&
> +   (drc->allocation_state == SPAPR_DR_ALLOCATION_STATE_UNUSABLE) 
> &&
> +drc->configured && drc->signalled && !drc->awaiting_release);
> +break;
> +
> +default:
> +;
> +}
> +return rc;
> +}
> +
> +/* return the unique drc index as instance_id for qom interfaces*/
> +static int get_instance_id(DeviceState *dev)
> +{
> +return (int)get_index(SPAPR_DR_CONNECTOR(OBJECT(dev)));
> +}
> +
> +static const VMStateDescription vmstate_spapr_drc = {
> +.name = "spapr_drc",
> +.version_id = 1,
> +.minimum_version_id = 1,
> +.needed = spapr_drc_needed,
> +.fields  = (VMStateField []) {
> +VMSTATE_UINT32(isolation_state, sPAPRDRConnector),
> +VMSTATE_UINT32(allocation_state, sPAPRDRConnector),
> +VMSTATE_UINT32(indicator_state, 

[Qemu-devel] [PATCH 26/26] audio: Use ARRAY_SIZE from qemu/osdep.h

2017-04-25 Thread Juan Quintela
Signed-off-by: Juan Quintela 
---
 hw/audio/fmopl.c | 6 +-
 1 file changed, 1 insertion(+), 5 deletions(-)

diff --git a/hw/audio/fmopl.c b/hw/audio/fmopl.c
index dc9043c..202f752 100644
--- a/hw/audio/fmopl.c
+++ b/hw/audio/fmopl.c
@@ -34,15 +34,11 @@
 #include 
 //#include "driver.h"  /* use M.A.M.E. */
 #include "fmopl.h"
-
+#include "qemu/osdep.h"
 #ifndef PI
 #define PI 3.14159265358979323846
 #endif
 
-#ifndef ARRAY_SIZE
-#define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0]))
-#endif
-
 /*  for debug - */
 /* #define OPL_OUTPUT_LOG */
 #ifdef OPL_OUTPUT_LOG
-- 
2.9.3




[Qemu-devel] [PATCH 12/26] audio: Remove Unused OPL_TYPE_*

2017-04-25 Thread Juan Quintela
Since we removed the previous unused devices, they are not used anymore.

Signed-off-by: Juan Quintela 
---
 hw/audio/fmopl.c | 16 
 hw/audio/fmopl.h |  3 ---
 2 files changed, 19 deletions(-)

diff --git a/hw/audio/fmopl.c b/hw/audio/fmopl.c
index b1cb4b4..9171001 100644
--- a/hw/audio/fmopl.c
+++ b/hw/audio/fmopl.c
@@ -1188,28 +1188,12 @@ unsigned char OPLRead(FM_OPL *OPL,int a)
switch(OPL->address)
{
case 0x05: /* KeyBoard IN */
-   if(OPL->type_TYPE_KEYBOARD)
-   {
-   if(OPL->keyboardhandler_r)
-   return 
OPL->keyboardhandler_r(OPL->keyboard_param);
-   else {
-   LOG(LOG_WAR,("OPL:read unmapped KEYBOARD 
port\n"));
-   }
-   }
return 0;
 #if 0
case 0x0f: /* ADPCM-DATA  */
return 0;
 #endif
case 0x19: /* I/O DATA*/
-   if(OPL->type_TYPE_IO)
-   {
-   if(OPL->porthandler_r)
-   return OPL->porthandler_r(OPL->port_param);
-   else {
-   LOG(LOG_WAR,("OPL:read unmapped I/O port\n"));
-   }
-   }
return 0;
case 0x1a: /* PCM-DATA*/
return 0;
diff --git a/hw/audio/fmopl.h b/hw/audio/fmopl.h
index c236287..8ef0b3e 100644
--- a/hw/audio/fmopl.h
+++ b/hw/audio/fmopl.h
@@ -12,9 +12,6 @@ typedef unsigned char (*OPL_PORTHANDLER_R)(int param);
 /* ! here is private section , do not access there member direct ! */
 
 #define OPL_TYPE_WAVESEL   0x01  /* waveform select*/
-#define OPL_TYPE_ADPCM 0x02  /* DELTA-T ADPCM unit */
-#define OPL_TYPE_KEYBOARD  0x04  /* keyboard interface */
-#define OPL_TYPE_IO0x08  /* I/O port */
 
 /* Saving is necessary for member of the 'R' mark for suspend/resume */
 /* -- OPL one of slot  -- */
-- 
2.9.3




[Qemu-devel] [PATCH 23/26] audio: UpdateHandler is not used anymore

2017-04-25 Thread Juan Quintela
Signed-off-by: Juan Quintela 
---
 hw/audio/fmopl.c | 2 --
 hw/audio/fmopl.h | 2 --
 2 files changed, 4 deletions(-)

diff --git a/hw/audio/fmopl.c b/hw/audio/fmopl.c
index 5b8a884..99d09c5 100644
--- a/hw/audio/fmopl.c
+++ b/hw/audio/fmopl.c
@@ -1147,7 +1147,6 @@ int OPLWrite(FM_OPL *OPL,int a,int v)
}
else
{   /* data port */
-   if(OPL->UpdateHandler) OPL->UpdateHandler(OPL->UpdateParam,0);
 #ifdef OPL_OUTPUT_LOG
if(opl_dbg_fp)
{
@@ -1197,7 +1196,6 @@ int OPLTimerOver(FM_OPL *OPL,int c)
if( OPL->mode & 0x80 )
{   /* CSM mode total level latch and auto key on */
int ch;
-   if(OPL->UpdateHandler) 
OPL->UpdateHandler(OPL->UpdateParam,0);
for(ch=0;ch<9;ch++)
CSMKeyControll( >P_CH[ch] );
}
diff --git a/hw/audio/fmopl.h b/hw/audio/fmopl.h
index b1641f5..8410275 100644
--- a/hw/audio/fmopl.h
+++ b/hw/audio/fmopl.h
@@ -92,8 +92,6 @@ typedef struct fm_opl_f {
/* external event callback handler */
OPL_TIMERHANDLER  TimerHandler; /* TIMER handler   */
int TimerParam; /* TIMER 
parameter */
-   OPL_UPDATEHANDLER UpdateHandler;/* stream update handler   */
-   int UpdateParam;/* stream 
update parameter */
 } FM_OPL;
 
 /* -- Generic interface section -- */
-- 
2.9.3




[Qemu-devel] [PATCH 22/26] audio: IRQHandler is not used anymore

2017-04-25 Thread Juan Quintela
Signed-off-by: Juan Quintela 
---
 hw/audio/fmopl.c | 4 
 hw/audio/fmopl.h | 2 --
 2 files changed, 6 deletions(-)

diff --git a/hw/audio/fmopl.c b/hw/audio/fmopl.c
index 694a77b..5b8a884 100644
--- a/hw/audio/fmopl.c
+++ b/hw/audio/fmopl.c
@@ -260,8 +260,6 @@ static inline void OPL_STATUS_SET(FM_OPL *OPL,int flag)
if(OPL->status & OPL->statusmask)
{   /* IRQ on */
OPL->status |= 0x80;
-   /* callback user interrupt handler (IRQ is OFF to ON) */
-   if(OPL->IRQHandler) (OPL->IRQHandler)(OPL->IRQParam,1);
}
}
 }
@@ -276,8 +274,6 @@ static inline void OPL_STATUS_RESET(FM_OPL *OPL,int flag)
if (!(OPL->status & OPL->statusmask) )
{
OPL->status &= 0x7f;
-   /* callback user interrupt handler (IRQ is ON to OFF) */
-   if(OPL->IRQHandler) (OPL->IRQHandler)(OPL->IRQParam,0);
}
}
 }
diff --git a/hw/audio/fmopl.h b/hw/audio/fmopl.h
index 446de08..b1641f5 100644
--- a/hw/audio/fmopl.h
+++ b/hw/audio/fmopl.h
@@ -92,8 +92,6 @@ typedef struct fm_opl_f {
/* external event callback handler */
OPL_TIMERHANDLER  TimerHandler; /* TIMER handler   */
int TimerParam; /* TIMER 
parameter */
-   OPL_IRQHANDLERIRQHandler;   /* IRQ handler*/
-   int IRQParam;   /* IRQ 
parameter  */
OPL_UPDATEHANDLER UpdateHandler;/* stream update handler   */
int UpdateParam;/* stream 
update parameter */
 } FM_OPL;
-- 
2.9.3




[Qemu-devel] [PATCH 11/26] audio: Unfold OPLSAMPLE

2017-04-25 Thread Juan Quintela
It was used only once, and now it was always int16_t.

Signed-off-by: Juan Quintela 
---
 hw/audio/fmopl.c |  2 +-
 hw/audio/fmopl.h | 11 ---
 2 files changed, 1 insertion(+), 12 deletions(-)

diff --git a/hw/audio/fmopl.c b/hw/audio/fmopl.c
index 8f935f6..b1cb4b4 100644
--- a/hw/audio/fmopl.c
+++ b/hw/audio/fmopl.c
@@ -988,7 +988,7 @@ void YM3812UpdateOne(FM_OPL *OPL, int16_t *buffer, int 
length)
 {
 int i;
int data;
-   OPLSAMPLE *buf = buffer;
+   int16_t *buf = buffer;
uint32_t amsCnt  = OPL->amsCnt;
uint32_t  vibCnt  = OPL->vibCnt;
uint8_t rhythm = OPL->rhythm&0x20;
diff --git a/hw/audio/fmopl.h b/hw/audio/fmopl.h
index 1e74019..c236287 100644
--- a/hw/audio/fmopl.h
+++ b/hw/audio/fmopl.h
@@ -3,17 +3,6 @@
 
 #include 
 
-/* --- system optimize --- */
-/* select bit size of output : 8 or 16 */
-#define OPL_OUTPUT_BIT 16
-
-#if (OPL_OUTPUT_BIT==16)
-typedef int16_t OPLSAMPLE;
-#endif
-#if (OPL_OUTPUT_BIT==8)
-typedef unsigned char  OPLSAMPLE;
-#endif
-
 typedef void (*OPL_TIMERHANDLER)(int channel,double interval_Sec);
 typedef void (*OPL_IRQHANDLER)(int param,int irq);
 typedef void (*OPL_UPDATEHANDLER)(int param,int min_interval_us);
-- 
2.9.3




[Qemu-devel] [PATCH 18/26] audio: GUSword is uint16_t

2017-04-25 Thread Juan Quintela
Signed-off-by: Juan Quintela 
---
 hw/audio/gusemu_hal.c   | 14 +++---
 hw/audio/gusemu_mixer.c |  8 
 2 files changed, 11 insertions(+), 11 deletions(-)

diff --git a/hw/audio/gusemu_hal.c b/hw/audio/gusemu_hal.c
index 444a2bb..3dd7239 100644
--- a/hw/audio/gusemu_hal.c
+++ b/hw/audio/gusemu_hal.c
@@ -31,7 +31,7 @@
 #include "gusemu.h"
 
 #define GUSregb(position) (*(gusptr+(position)))
-#define GUSregw(position) (*(GUSword *) (gusptr+(position)))
+#define GUSregw(position) (*(uint16_t *) (gusptr+(position)))
 #define GUSregd(position) (*(GUSdword *)(gusptr+(position)))
 
 /* size given in bytes */
@@ -173,7 +173,7 @@ unsigned int gus_read(GUSEmuState * state, int port, int 
size)
 value_read = value_read >> 8;
 value_read &= 0xff;
 }
-return (GUSword) value_read;
+return (uint16_t) value_read;
 /* case 0x306:  */ /* Mixer/Version info */
 /*  return 0xff; */ /* Pre 3.6 boards, ICS mixer NOT present */
 case 0x307: /* DRAMaccess */
@@ -318,15 +318,15 @@ void gus_write(GUSEmuState * state, int port, int size, 
unsigned int data)
 case 0x304:
 case 0x305:
 {
-GUSword writedata = (GUSword) data;
-GUSword readmask = 0x;
+uint16_t writedata = (uint16_t) data;
+uint16_t readmask = 0x;
 if (size == 1)
 {
 readmask = 0xff00;
 writedata &= 0xff;
 if ((port & 0xff0f) == 0x305)
 {
-writedata = (GUSword) (writedata << 8);
+writedata = (uint16_t) (writedata << 8);
 readmask = 0x00ff;
 }
 }
@@ -353,7 +353,7 @@ void gus_write(GUSEmuState * state, int port, int size, 
unsigned int data)
 break;  /* reset flag active? */
 offset = 2 * (GUSregb(FunkSelReg3x3) & 0x0f);
 offset += (GUSregb(VoiceSelReg3x2) & 0x1f) << 5; /*  = 
Voice*32 + Funktion*2 */
-GUSregw(offset) = (GUSword) ((GUSregw(offset) & readmask) 
| writedata);
+GUSregw(offset) = (uint16_t) ((GUSregw(offset) & readmask) 
| writedata);
 }
 break;
 /* voice unspecific functions */
@@ -521,7 +521,7 @@ void gus_dma_transferdata(GUSEmuState * state, char 
*dma_addr, unsigned int coun
 destaddr = (char *) state->himemaddr + offset; /* wavetable RAM 
address */
 }
 
-GUSregw(GUS42DMAStart) += (GUSword)  (count >> 4); 
  /* ToDo: add 16bit GUS page limit? */
+GUSregw(GUS42DMAStart) += (uint16_t)  (count >> 4);
   /* ToDo: add 16bit GUS page limit? */
 GUSregb(GUS50DMAHigh)   = (uint8_t) ((count + GUSregb(GUS50DMAHigh)) & 
0xf); /* ToDo: add 16bit GUS page limit? */
 
 if (GUSregb(GUS41DMACtrl) & 0x02)   /* direction, 0 := sysram->gusram */
diff --git a/hw/audio/gusemu_mixer.c b/hw/audio/gusemu_mixer.c
index b189db9..981a9ae 100644
--- a/hw/audio/gusemu_mixer.c
+++ b/hw/audio/gusemu_mixer.c
@@ -27,10 +27,10 @@
 #include "gustate.h"
 
 #define GUSregb(position)  (*(gusptr+(position)))
-#define GUSregw(position)  (*(GUSword *) (gusptr+(position)))
+#define GUSregw(position)  (*(uint16_t *) (gusptr+(position)))
 #define GUSregd(position)  (*(GUSdword *)(gusptr+(position)))
 
-#define GUSvoice(position) (*(GUSword *)(voiceptr+(position)))
+#define GUSvoice(position) (*(uint16_t *)(voiceptr+(position)))
 
 /* samples are always 16bit stereo (4 bytes each, first right then left 
interleaved) */
 void gus_mixvoices(GUSEmuState * state, unsigned int playback_freq, unsigned 
int numsamples,
@@ -39,14 +39,14 @@ void gus_mixvoices(GUSEmuState * state, unsigned int 
playback_freq, unsigned int
 /* note that byte registers are stored in the upper half of each voice 
register! */
 uint8_t*gusptr;
 int Voice;
-GUSword*voiceptr;
+uint16_t   *voiceptr;
 
 unsigned intcount;
 for (count = 0; count < numsamples * 2; count++)
 *(bufferpos + count) = 0;   /* clear */
 
 gusptr = state->gusdatapos;
-voiceptr = (GUSword *) gusptr;
+voiceptr = (uint16_t *) gusptr;
 if (!(GUSregb(GUS4cReset) & 0x01))  /* reset flag active? */
 return;
 
-- 
2.9.3




[Qemu-devel] [PATCH 10/26] audio: Remove INT32

2017-04-25 Thread Juan Quintela
Signed-off-by: Juan Quintela 
---
 hw/audio/fmopl.c | 42 +-
 hw/audio/fmopl.h | 54 --
 2 files changed, 45 insertions(+), 51 deletions(-)

diff --git a/hw/audio/fmopl.c b/hw/audio/fmopl.c
index ebd3dbb..8f935f6 100644
--- a/hw/audio/fmopl.c
+++ b/hw/audio/fmopl.c
@@ -170,7 +170,7 @@ static const uint32_t KSL_TABLE[8*16]=
 /* sustain lebel table (3db per step) */
 /* 0 - 15: 0, 3, 6, 9,12,15,18,21,24,27,30,33,36,39,42,93 (dB)*/
 #define SC(db) (db*((3/EG_STEP)*(1<connect1 = CH->CON ? carrier : 
CH->connect2 = carrier;
 }
@@ -498,7 +498,7 @@ static inline void OPL_CALC_RH( OPL_CH *CH )
 {
uint32_t env_tam,env_sd,env_top,env_hh;
int whitenoise = (rand()&1)*(WHITE_NOISE_db/EG_STEP);
-   INT32 tone8;
+   int32_t tone8;
 
OPL_SLOT *SLOT;
int env_out;
@@ -616,20 +616,20 @@ static int OPLOpenTable( void )
double pom;
 
/* allocate dynamic tables */
-   if( (TL_TABLE = malloc(TL_MAX*2*sizeof(INT32))) == NULL)
+   if( (TL_TABLE = malloc(TL_MAX*2*sizeof(int32_t))) == NULL)
return 0;
-   if( (SIN_TABLE = malloc(SIN_ENT*4 *sizeof(INT32 *))) == NULL)
+   if( (SIN_TABLE = malloc(SIN_ENT*4 *sizeof(int32_t *))) == NULL)
{
free(TL_TABLE);
return 0;
}
-   if( (AMS_TABLE = malloc(AMS_ENT*2 *sizeof(INT32))) == NULL)
+   if( (AMS_TABLE = malloc(AMS_ENT*2 *sizeof(int32_t))) == NULL)
{
free(TL_TABLE);
free(SIN_TABLE);
return 0;
}
-   if( (VIB_TABLE = malloc(VIB_ENT*2 *sizeof(INT32))) == NULL)
+   if( (VIB_TABLE = malloc(VIB_ENT*2 *sizeof(int32_t))) == NULL)
{
free(TL_TABLE);
free(SIN_TABLE);
diff --git a/hw/audio/fmopl.h b/hw/audio/fmopl.h
index 0bc3415..1e74019 100644
--- a/hw/audio/fmopl.h
+++ b/hw/audio/fmopl.h
@@ -7,12 +7,6 @@
 /* select bit size of output : 8 or 16 */
 #define OPL_OUTPUT_BIT 16
 
-/* compiler dependence */
-#ifndef OSD_CPU_H
-#define OSD_CPU_H
-typedef signed int INT32;   /* signed 32bit   */
-#endif
-
 #if (OPL_OUTPUT_BIT==16)
 typedef int16_t OPLSAMPLE;
 #endif
@@ -36,13 +30,13 @@ typedef unsigned char (*OPL_PORTHANDLER_R)(int param);
 /* Saving is necessary for member of the 'R' mark for suspend/resume */
 /* -- OPL one of slot  -- */
 typedef struct fm_opl_slot {
-   INT32 TL;   /* total level :TL << 8*/
-   INT32 TLL;  /* adjusted now TL */
+   int32_t TL; /* total level :TL << 8*/
+   int32_t TLL;/* adjusted now TL */
uint8_t  KSR;   /* key scale rate  :(shift down bit)   */
-   INT32 *AR;  /* attack rate 

[Qemu-devel] [PATCH 20/26] audio: OPLSetIRQHandler is not used anywhere

2017-04-25 Thread Juan Quintela
Signed-off-by: Juan Quintela 
---
 hw/audio/fmopl.c | 5 -
 hw/audio/fmopl.h | 1 -
 2 files changed, 6 deletions(-)

diff --git a/hw/audio/fmopl.c b/hw/audio/fmopl.c
index 48db828..f91e700 100644
--- a/hw/audio/fmopl.c
+++ b/hw/audio/fmopl.c
@@ -1141,11 +1141,6 @@ void OPLSetTimerHandler(FM_OPL *OPL,OPL_TIMERHANDLER 
TimerHandler,int channelOff
OPL->TimerHandler   = TimerHandler;
OPL->TimerParam = channelOffset;
 }
-void OPLSetIRQHandler(FM_OPL *OPL,OPL_IRQHANDLER IRQHandler,int param)
-{
-   OPL->IRQHandler = IRQHandler;
-   OPL->IRQParam = param;
-}
 void OPLSetUpdateHandler(FM_OPL *OPL,OPL_UPDATEHANDLER UpdateHandler,int param)
 {
OPL->UpdateHandler = UpdateHandler;
diff --git a/hw/audio/fmopl.h b/hw/audio/fmopl.h
index 8730ead..375f971 100644
--- a/hw/audio/fmopl.h
+++ b/hw/audio/fmopl.h
@@ -102,7 +102,6 @@ typedef struct fm_opl_f {
 FM_OPL *OPLCreate(int clock, int rate);
 void OPLDestroy(FM_OPL *OPL);
 void OPLSetTimerHandler(FM_OPL *OPL,OPL_TIMERHANDLER TimerHandler,int 
channelOffset);
-void OPLSetIRQHandler(FM_OPL *OPL,OPL_IRQHANDLER IRQHandler,int param);
 void OPLSetUpdateHandler(FM_OPL *OPL,OPL_UPDATEHANDLER UpdateHandler,int 
param);
 
 void OPLResetChip(FM_OPL *OPL);
-- 
2.9.3




[Qemu-devel] [PATCH 09/26] audio: remove INT16

2017-04-25 Thread Juan Quintela
Signed-off-by: Juan Quintela 
---
 hw/audio/fmopl.c | 2 +-
 hw/audio/fmopl.h | 5 ++---
 2 files changed, 3 insertions(+), 4 deletions(-)

diff --git a/hw/audio/fmopl.c b/hw/audio/fmopl.c
index 47754e8..ebd3dbb 100644
--- a/hw/audio/fmopl.c
+++ b/hw/audio/fmopl.c
@@ -984,7 +984,7 @@ static void OPL_UnLockTable(void)
 
/***/
 
 /* -- update one of chip --- */
-void YM3812UpdateOne(FM_OPL *OPL, INT16 *buffer, int length)
+void YM3812UpdateOne(FM_OPL *OPL, int16_t *buffer, int length)
 {
 int i;
int data;
diff --git a/hw/audio/fmopl.h b/hw/audio/fmopl.h
index bede671..0bc3415 100644
--- a/hw/audio/fmopl.h
+++ b/hw/audio/fmopl.h
@@ -10,12 +10,11 @@
 /* compiler dependence */
 #ifndef OSD_CPU_H
 #define OSD_CPU_H
-typedef signed short   INT16;   /* signed 16bit   */
 typedef signed int INT32;   /* signed 32bit   */
 #endif
 
 #if (OPL_OUTPUT_BIT==16)
-typedef INT16 OPLSAMPLE;
+typedef int16_t OPLSAMPLE;
 #endif
 #if (OPL_OUTPUT_BIT==8)
 typedef unsigned char  OPLSAMPLE;
@@ -142,5 +141,5 @@ int OPLWrite(FM_OPL *OPL,int a,int v);
 unsigned char OPLRead(FM_OPL *OPL,int a);
 int OPLTimerOver(FM_OPL *OPL,int c);
 
-void YM3812UpdateOne(FM_OPL *OPL, INT16 *buffer, int length);
+void YM3812UpdateOne(FM_OPL *OPL, int16_t *buffer, int length);
 #endif
-- 
2.9.3




[Qemu-devel] [PATCH 06/26] audio: remove UINT16

2017-04-25 Thread Juan Quintela
More modernitation.

Signed-off-by: Juan Quintela 
---
 hw/audio/fmopl.h | 1 -
 1 file changed, 1 deletion(-)

diff --git a/hw/audio/fmopl.h b/hw/audio/fmopl.h
index 3df8942..1891a22 100644
--- a/hw/audio/fmopl.h
+++ b/hw/audio/fmopl.h
@@ -10,7 +10,6 @@
 /* compiler dependence */
 #ifndef OSD_CPU_H
 #define OSD_CPU_H
-typedef unsigned short UINT16;  /* unsigned 16bit */
 typedef unsigned int   UINT32;  /* unsigned 32bit */
 typedef signed charINT8;/* signed  8bit   */
 typedef signed short   INT16;   /* signed 16bit   */
-- 
2.9.3




[Qemu-devel] [PATCH 19/26] audio: GUSsample is int16_t

2017-04-25 Thread Juan Quintela
Signed-off-by: Juan Quintela 
---
 hw/audio/gus.c  |  2 +-
 hw/audio/gusemu.h   | 12 +---
 hw/audio/gusemu_hal.c   |  2 +-
 hw/audio/gusemu_mixer.c |  8 
 4 files changed, 7 insertions(+), 17 deletions(-)

diff --git a/hw/audio/gus.c b/hw/audio/gus.c
index 3d08a65..ec103a4 100644
--- a/hw/audio/gus.c
+++ b/hw/audio/gus.c
@@ -53,7 +53,7 @@ typedef struct GUSState {
 uint32_t freq;
 uint32_t port;
 int pos, left, shift, irqs;
-GUSsample *mixbuf;
+int16_t *mixbuf;
 uint8_t himem[1024 * 1024 + 32 + 4096];
 int samples;
 SWVoiceOut *voice;
diff --git a/hw/audio/gusemu.h b/hw/audio/gusemu.h
index 69dadef..ab591ee 100644
--- a/hw/audio/gusemu.h
+++ b/hw/audio/gusemu.h
@@ -25,16 +25,6 @@
 #ifndef GUSEMU_H
 #define GUSEMU_H
 
-/* data types (need to be adjusted if neither a VC6 nor a C99 compatible 
compiler is used) */
-
-#if defined _WIN32 && defined _MSC_VER /* doesn't support other win32 
compilers yet, do it yourself... */
- typedef unsigned int GUSdword;
- typedef signed short GUSsample;
-#else
- typedef uint32_t GUSdword;
- typedef int16_t GUSsample;
-#endif
-
 typedef struct _GUSEmuState
 {
  uint8_t *himemaddr; /* 1024*1024 bytes used for storing uploaded samples (+32 
additional bytes for read padding) */
@@ -86,7 +76,7 @@ void gus_dma_transferdata(GUSEmuState *state, char *dma_addr, 
unsigned int count
 /* If the interrupts are asynchronous, it may be needed to use a separate 
thread mixing into a temporary */
 /* audio buffer in order to avoid quality loss caused by large numsamples and 
elapsed_time values. */
 
-void gus_mixvoices(GUSEmuState *state, unsigned int playback_freq, unsigned 
int numsamples, GUSsample *bufferpos);
+void gus_mixvoices(GUSEmuState *state, unsigned int playback_freq, unsigned 
int numsamples, int16_t *bufferpos);
 /* recommended range: 10 < numsamples < 100 */
 /* lower values may result in increased rounding error, higher values often 
cause audible timing delays */
 
diff --git a/hw/audio/gusemu_hal.c b/hw/audio/gusemu_hal.c
index 3dd7239..1150fc4 100644
--- a/hw/audio/gusemu_hal.c
+++ b/hw/audio/gusemu_hal.c
@@ -32,7 +32,7 @@
 
 #define GUSregb(position) (*(gusptr+(position)))
 #define GUSregw(position) (*(uint16_t *) (gusptr+(position)))
-#define GUSregd(position) (*(GUSdword *)(gusptr+(position)))
+#define GUSregd(position) (*(uint16_t *)(gusptr+(position)))
 
 /* size given in bytes */
 unsigned int gus_read(GUSEmuState * state, int port, int size)
diff --git a/hw/audio/gusemu_mixer.c b/hw/audio/gusemu_mixer.c
index 981a9ae..00b9861 100644
--- a/hw/audio/gusemu_mixer.c
+++ b/hw/audio/gusemu_mixer.c
@@ -28,13 +28,13 @@
 
 #define GUSregb(position)  (*(gusptr+(position)))
 #define GUSregw(position)  (*(uint16_t *) (gusptr+(position)))
-#define GUSregd(position)  (*(GUSdword *)(gusptr+(position)))
+#define GUSregd(position)  (*(uint16_t *)(gusptr+(position)))
 
 #define GUSvoice(position) (*(uint16_t *)(voiceptr+(position)))
 
 /* samples are always 16bit stereo (4 bytes each, first right then left 
interleaved) */
 void gus_mixvoices(GUSEmuState * state, unsigned int playback_freq, unsigned 
int numsamples,
-   GUSsample *bufferpos)
+   int16_t *bufferpos)
 {
 /* note that byte registers are stored in the upper half of each voice 
register! */
 uint8_t*gusptr;
@@ -171,8 +171,8 @@ void gus_mixvoices(GUSEmuState * state, unsigned int 
playback_freq, unsigned int
 }
 
 /* mix samples into buffer */
-*(bufferpos + 2 * sample) += (GUSsample) ((sample1 * 
PanningPos) >> 4);/* right */
-*(bufferpos + 2 * sample + 1) += (GUSsample) ((sample1 * (15 - 
PanningPos)) >> 4); /* left */
+*(bufferpos + 2 * sample) += (int16_t) ((sample1 * 
PanningPos) >> 4);/* right */
+*(bufferpos + 2 * sample + 1) += (int16_t) ((sample1 * (15 - 
PanningPos)) >> 4); /* left */
 }
 /* write back voice and volume */
 GUSvoice(wVSRCurrVol)   = Volume32 / 32;
-- 
2.9.3




[Qemu-devel] [PATCH 08/26] audio: Remove INT8

2017-04-25 Thread Juan Quintela
Signed-off-by: Juan Quintela 
---
 hw/audio/fmopl.h | 1 -
 1 file changed, 1 deletion(-)

diff --git a/hw/audio/fmopl.h b/hw/audio/fmopl.h
index b52f039..bede671 100644
--- a/hw/audio/fmopl.h
+++ b/hw/audio/fmopl.h
@@ -10,7 +10,6 @@
 /* compiler dependence */
 #ifndef OSD_CPU_H
 #define OSD_CPU_H
-typedef signed charINT8;/* signed  8bit   */
 typedef signed short   INT16;   /* signed 16bit   */
 typedef signed int INT32;   /* signed 32bit   */
 #endif
-- 
2.9.3




[Qemu-devel] [PATCH 17/26] audio: GUSword is uint16_t

2017-04-25 Thread Juan Quintela
Signed-off-by: Juan Quintela 
---
 hw/audio/gusemu.h | 2 --
 1 file changed, 2 deletions(-)

diff --git a/hw/audio/gusemu.h b/hw/audio/gusemu.h
index 1c1a63c..69dadef 100644
--- a/hw/audio/gusemu.h
+++ b/hw/audio/gusemu.h
@@ -28,11 +28,9 @@
 /* data types (need to be adjusted if neither a VC6 nor a C99 compatible 
compiler is used) */
 
 #if defined _WIN32 && defined _MSC_VER /* doesn't support other win32 
compilers yet, do it yourself... */
- typedef unsigned short GUSword;
  typedef unsigned int GUSdword;
  typedef signed short GUSsample;
 #else
- typedef uint16_t GUSword;
  typedef uint32_t GUSdword;
  typedef int16_t GUSsample;
 #endif
-- 
2.9.3




[Qemu-devel] [PATCH 05/26] audio: Remove UINT8

2017-04-25 Thread Juan Quintela
uint8_t has existed since . all this century?

Signed-off-by: Juan Quintela 
---
 hw/audio/fmopl.c |  8 
 hw/audio/fmopl.h | 39 ---
 2 files changed, 24 insertions(+), 23 deletions(-)

diff --git a/hw/audio/fmopl.c b/hw/audio/fmopl.c
index 282662a..3d14b45 100644
--- a/hw/audio/fmopl.c
+++ b/hw/audio/fmopl.c
@@ -789,8 +789,8 @@ static void OPLWriteReg(FM_OPL *OPL, int r, int v)
}
else
{   /* set IRQ mask ,timer enable*/
-   UINT8 st1 = v&1;
-   UINT8 st2 = (v>>1)&1;
+   uint8_t st1 = v&1;
+   uint8_t st2 = (v>>1)&1;
/* IRQRST,T1MSK,t2MSK,EOSMSK,BRMSK,x,ST2,ST1 */
OPL_STATUS_RESET(OPL,v&0x78);
OPL_STATUSMASK_SET(OPL,((~v)&0x78)|0x01);
@@ -838,7 +838,7 @@ static void OPLWriteReg(FM_OPL *OPL, int r, int v)
case 0xbd:
/* amsep,vibdep,r,bd,sd,tom,tc,hh */
{
-   UINT8 rkey = OPL->rhythm^v;
+   uint8_t rkey = OPL->rhythm^v;
OPL->ams_table = _TABLE[v&0x80 ? AMS_ENT : 0];
OPL->vib_table = _TABLE[v&0x40 ? VIB_ENT : 0];
OPL->rhythm  = v&0x3f;
@@ -991,7 +991,7 @@ void YM3812UpdateOne(FM_OPL *OPL, INT16 *buffer, int length)
OPLSAMPLE *buf = buffer;
UINT32 amsCnt  = OPL->amsCnt;
UINT32 vibCnt  = OPL->vibCnt;
-   UINT8 rhythm = OPL->rhythm&0x20;
+   uint8_t rhythm = OPL->rhythm&0x20;
OPL_CH *CH,*R_CH;
 
if( (void *)OPL != cur_chip ){
diff --git a/hw/audio/fmopl.h b/hw/audio/fmopl.h
index e476497..3df8942 100644
--- a/hw/audio/fmopl.h
+++ b/hw/audio/fmopl.h
@@ -1,6 +1,8 @@
 #ifndef FMOPL_H
 #define FMOPL_H
 
+#include 
+
 /* --- system optimize --- */
 /* select bit size of output : 8 or 16 */
 #define OPL_OUTPUT_BIT 16
@@ -8,7 +10,6 @@
 /* compiler dependence */
 #ifndef OSD_CPU_H
 #define OSD_CPU_H
-typedef unsigned char  UINT8;   /* unsigned  8bit */
 typedef unsigned short UINT16;  /* unsigned 16bit */
 typedef unsigned int   UINT32;  /* unsigned 32bit */
 typedef signed charINT8;/* signed  8bit   */
@@ -41,19 +42,19 @@ typedef unsigned char (*OPL_PORTHANDLER_R)(int param);
 typedef struct fm_opl_slot {
INT32 TL;   /* total level :TL << 8*/
INT32 TLL;  /* adjusted now TL */
-   UINT8  KSR; /* key scale rate  :(shift down bit)   */
+   uint8_t  KSR;   /* key scale rate  :(shift down bit)   */
INT32 *AR;  /* attack rate :_TABLE[AR<<2]   */
INT32 *DR;  /* decay rate  :_TALBE[DR<<2]   */
INT32 SL;   /* sustin level:SL_TALBE[SL]   */
INT32 *RR;  /* release rate:_TABLE[RR<<2]   */
-   UINT8 ksl;  /* keyscale level  :(shift down bits)  */
-   UINT8 ksr;  /* key scale rate  :kcode>>KSR */
+   uint8_t ksl;/* keyscale level  :(shift down bits)  */
+   uint8_t ksr;/* key scale rate  :kcode>>KSR */
UINT32 mul; /* multiple:ML_TABLE[ML]   */
UINT32 Cnt; /* frequency count :   */
UINT32 Incr;/* frequency step  :   */
/* envelope generator state */
-   UINT8 eg_typ;   /* envelope type flag  */
-   UINT8 evm;  /* envelope phase  */
+   uint8_t eg_typ; /* envelope type flag  */
+   uint8_t evm;/* envelope phase  */
INT32 evc;  /* envelope counter*/
INT32 eve;  /* envelope counter end point  */
INT32 evs;  /* envelope counter step   */
@@ -61,8 +62,8 @@ typedef struct fm_opl_slot {
INT32 evsd; /* envelope step for DR :DR[ksr]   */
INT32 evsr; /* envelope step for RR :RR[ksr]   */
/* LFO */
-   UINT8 ams;  /* ams flag*/
-   UINT8 vib;  /* vibrate flag*/
+   uint8_t ams;/* ams flag*/
+   uint8_t vib;/* vibrate flag*/
/* wave selector */
INT32 **wavetable;
 }OPL_SLOT;
@@ -70,38 +71,38 @@ typedef struct fm_opl_slot {
 /* -- OPL one of channel  -- */
 typedef struct fm_opl_channel {
OPL_SLOT SLOT[2];
-   UINT8 CON;  /* connection type 
*/
-   UINT8 FB;  

[Qemu-devel] [PATCH 04/26] audio: YM3812 was always defined

2017-04-25 Thread Juan Quintela
So, remove the ifdefs.

Signed-off-by: Juan Quintela 
---
 hw/audio/fmopl.c | 4 
 hw/audio/fmopl.h | 4 
 2 files changed, 8 deletions(-)

diff --git a/hw/audio/fmopl.c b/hw/audio/fmopl.c
index 1e05efc..282662a 100644
--- a/hw/audio/fmopl.c
+++ b/hw/audio/fmopl.c
@@ -30,8 +30,6 @@
  * License along with this library; if not, see .
  */
 
-#define HAS_YM3812 1
-
 #include "qemu/osdep.h"
 #include 
 //#include "driver.h"  /* use M.A.M.E. */
@@ -981,7 +979,6 @@ static void OPL_UnLockTable(void)
OPLCloseTable();
 }
 
-#if BUILD_YM3812
 
/***/
 /* YM3812 local section
   */
 
/***/
@@ -1044,7 +1041,6 @@ void YM3812UpdateOne(FM_OPL *OPL, INT16 *buffer, int 
length)
}
 #endif
 }
-#endif /* BUILD_YM3812 */
 
 /* -- reset one of chip -- */
 void OPLResetChip(FM_OPL *OPL)
diff --git a/hw/audio/fmopl.h b/hw/audio/fmopl.h
index b254968..e476497 100644
--- a/hw/audio/fmopl.h
+++ b/hw/audio/fmopl.h
@@ -1,9 +1,6 @@
 #ifndef FMOPL_H
 #define FMOPL_H
 
-/* --- select emulation chips --- */
-#define BUILD_YM3812 (HAS_YM3812)
-
 /* --- system optimize --- */
 /* select bit size of output : 8 or 16 */
 #define OPL_OUTPUT_BIT 16
@@ -147,6 +144,5 @@ int OPLWrite(FM_OPL *OPL,int a,int v);
 unsigned char OPLRead(FM_OPL *OPL,int a);
 int OPLTimerOver(FM_OPL *OPL,int c);
 
-/* YM3626/YM3812 local section */
 void YM3812UpdateOne(FM_OPL *OPL, INT16 *buffer, int length);
 #endif
-- 
2.9.3




[Qemu-devel] [PATCH 07/26] audio: remove UINT32

2017-04-25 Thread Juan Quintela
Signed-off-by: Juan Quintela 
---
 hw/audio/fmopl.c | 14 +++---
 hw/audio/fmopl.h | 17 -
 2 files changed, 15 insertions(+), 16 deletions(-)

diff --git a/hw/audio/fmopl.c b/hw/audio/fmopl.c
index 3d14b45..47754e8 100644
--- a/hw/audio/fmopl.c
+++ b/hw/audio/fmopl.c
@@ -122,7 +122,7 @@ static const int slot_array[32]=
 /* key scale level */
 /* table is 3dB/OCT , DV converts this in TL step at 6dB/OCT */
 #define DV (EG_STEP/2)
-static const UINT32 KSL_TABLE[8*16]=
+static const uint32_t KSL_TABLE[8*16]=
 {
/* OCT 0 */
 0.000/DV, 0.000/DV, 0.000/DV, 0.000/DV,
@@ -195,7 +195,7 @@ static INT32 ENV_CURVE[2*EG_ENT+1];
 
 /* multiple table */
 #define ML 2
-static const UINT32 MUL_TABLE[16]= {
+static const uint32_t MUL_TABLE[16]= {
 /* 1/2, 1, 2, 3, 4, 5, 6, 7, 8, 9,10,11,12,13,14,15 */
0.50*ML, 1.00*ML, 2.00*ML, 3.00*ML, 4.00*ML, 5.00*ML, 6.00*ML, 7.00*ML,
8.00*ML, 9.00*ML,10.00*ML,10.00*ML,12.00*ML,12.00*ML,15.00*ML,15.00*ML
@@ -319,7 +319,7 @@ static inline void OPL_KEYOFF(OPL_SLOT *SLOT)
 
 /* -- calcrate Envelope Generator & Phase Generator -- */
 /* return : envelope output */
-static inline UINT32 OPL_CALC_SLOT( OPL_SLOT *SLOT )
+static inline uint32_t OPL_CALC_SLOT( OPL_SLOT *SLOT )
 {
/* calcrate envelope generator */
if( (SLOT->evc+=SLOT->evs) >= SLOT->eve )
@@ -451,7 +451,7 @@ static inline void set_sl_rr(FM_OPL *OPL,int slot,int v)
 /* -- calcrate one of channel -- */
 static inline void OPL_CALC_CH( OPL_CH *CH )
 {
-   UINT32 env_out;
+   uint32_t env_out;
OPL_SLOT *SLOT;
 
feedback2 = 0;
@@ -496,7 +496,7 @@ static inline void OPL_CALC_CH( OPL_CH *CH )
 #define WHITE_NOISE_db 6.0
 static inline void OPL_CALC_RH( OPL_CH *CH )
 {
-   UINT32 env_tam,env_sd,env_top,env_hh;
+   uint32_t env_tam,env_sd,env_top,env_hh;
int whitenoise = (rand()&1)*(WHITE_NOISE_db/EG_STEP);
INT32 tone8;
 
@@ -989,8 +989,8 @@ void YM3812UpdateOne(FM_OPL *OPL, INT16 *buffer, int length)
 int i;
int data;
OPLSAMPLE *buf = buffer;
-   UINT32 amsCnt  = OPL->amsCnt;
-   UINT32 vibCnt  = OPL->vibCnt;
+   uint32_t amsCnt  = OPL->amsCnt;
+   uint32_t  vibCnt  = OPL->vibCnt;
uint8_t rhythm = OPL->rhythm&0x20;
OPL_CH *CH,*R_CH;
 
diff --git a/hw/audio/fmopl.h b/hw/audio/fmopl.h
index 1891a22..b52f039 100644
--- a/hw/audio/fmopl.h
+++ b/hw/audio/fmopl.h
@@ -10,7 +10,6 @@
 /* compiler dependence */
 #ifndef OSD_CPU_H
 #define OSD_CPU_H
-typedef unsigned int   UINT32;  /* unsigned 32bit */
 typedef signed charINT8;/* signed  8bit   */
 typedef signed short   INT16;   /* signed 16bit   */
 typedef signed int INT32;   /* signed 32bit   */
@@ -48,9 +47,9 @@ typedef struct fm_opl_slot {
INT32 *RR;  /* release rate:_TABLE[RR<<2]   */
uint8_t ksl;/* keyscale level  :(shift down bits)  */
uint8_t ksr;/* key scale rate  :kcode>>KSR */
-   UINT32 mul; /* multiple:ML_TABLE[ML]   */
-   UINT32 Cnt; /* frequency count :   */
-   UINT32 Incr;/* frequency step  :   */
+   uint32_t mul;   /* multiple:ML_TABLE[ML]   */
+   uint32_t Cnt;   /* frequency count :   */
+   uint32_t Incr;  /* frequency step  :   */
/* envelope generator state */
uint8_t eg_typ; /* envelope type flag  */
uint8_t evm;/* envelope phase  */
@@ -76,10 +75,10 @@ typedef struct fm_opl_channel {
INT32 *connect2;/* slot2 output pointer*/
INT32 op1_out[2];   /* slot1 output for selfeedback*/
/* phase generator state */
-   UINT32  block_fnum; /* block+fnum  :   */
+   uint32_t  block_fnum;   /* block+fnum  :   */
uint8_t kcode;  /* key code: KeyScaleCode  */
-   UINT32  fc; /* Freq. Increment base
*/
-   UINT32  ksl_base;   /* KeyScaleLevel Base step */
+   uint32_t  fc;   /* Freq. Increment base
*/
+   uint32_t  ksl_base; /* KeyScaleLevel Base step */
uint8_t keyon;  /* key on/off flag */
 } OPL_CH;
 
@@ -93,7 +92,7 @@ typedef struct fm_opl_f {
uint8_t address;/* address register  */
uint8_t status; /* status flag   */
uint8_t statusmask; /* status mask   */
-   UINT32 mode;/* Reg.08 : CSM , notesel,etc.   */
+   uint32_t mode;  /* Reg.08 : CSM , notesel,etc.   */
/* Timer */
int T[2]; 

[Qemu-devel] [PATCH 13/26] audio: Remove type field

2017-04-25 Thread Juan Quintela
It was not used anymore as now there is only one type of devices.

Signed-off-by: Juan Quintela 
---
 hw/audio/adlib.c |  2 +-
 hw/audio/fmopl.c | 20 
 hw/audio/fmopl.h |  7 +--
 3 files changed, 10 insertions(+), 19 deletions(-)

diff --git a/hw/audio/adlib.c b/hw/audio/adlib.c
index f9adcd7..09b8248 100644
--- a/hw/audio/adlib.c
+++ b/hw/audio/adlib.c
@@ -265,7 +265,7 @@ static void adlib_realizefn (DeviceState *dev, Error **errp)
 }
 glob_adlib = s;
 
-s->opl = OPLCreate (OPL_TYPE_YM3812, 3579545, s->freq);
+s->opl = OPLCreate (3579545, s->freq);
 if (!s->opl) {
 error_setg (errp, "OPLCreate %d failed", s->freq);
 return;
diff --git a/hw/audio/fmopl.c b/hw/audio/fmopl.c
index 9171001..48db828 100644
--- a/hw/audio/fmopl.c
+++ b/hw/audio/fmopl.c
@@ -761,18 +761,15 @@ static void OPLWriteReg(FM_OPL *OPL, int r, int v)
{
case 0x01:
/* wave selector enable */
-   if(OPL->type_TYPE_WAVESEL)
+   OPL->wavesel = v&0x20;
+if(!OPL->wavesel)
{
-   OPL->wavesel = v&0x20;
-   if(!OPL->wavesel)
+   /* preset compatible mode */
+   int c;
+   for(c=0;cmax_ch;c++)
{
-   /* preset compatible mode */
-   int c;
-   for(c=0;cmax_ch;c++)
-   {
-   
OPL->P_CH[c].SLOT[SLOT1].wavetable = _TABLE[0];
-   
OPL->P_CH[c].SLOT[SLOT2].wavetable = _TABLE[0];
-   }
+   OPL->P_CH[c].SLOT[SLOT1].wavetable = 
_TABLE[0];
+   OPL->P_CH[c].SLOT[SLOT2].wavetable = 
_TABLE[0];
}
}
return;
@@ -1076,7 +1073,7 @@ void OPLResetChip(FM_OPL *OPL)
 
 /* --  Create one of vietual YM3812 --   */
 /* 'rate'  is sampling rate and 'bufsiz' is the size of the  */
-FM_OPL *OPLCreate(int type, int clock, int rate)
+FM_OPL *OPLCreate(int clock, int rate)
 {
char *ptr;
FM_OPL *OPL;
@@ -1095,7 +1092,6 @@ FM_OPL *OPLCreate(int type, int clock, int rate)
OPL= (FM_OPL *)ptr; ptr+=sizeof(FM_OPL);
OPL->P_CH  = (OPL_CH *)ptr; ptr+=sizeof(OPL_CH)*max_ch;
/* set channel state pointer */
-   OPL->type  = type;
OPL->clock = clock;
OPL->rate  = rate;
OPL->max_ch = max_ch;
diff --git a/hw/audio/fmopl.h b/hw/audio/fmopl.h
index 8ef0b3e..df790a0 100644
--- a/hw/audio/fmopl.h
+++ b/hw/audio/fmopl.h
@@ -11,8 +11,6 @@ typedef unsigned char (*OPL_PORTHANDLER_R)(int param);
 
 /* ! here is private section , do not access there member direct ! */
 
-#define OPL_TYPE_WAVESEL   0x01  /* waveform select*/
-
 /* Saving is necessary for member of the 'R' mark for suspend/resume */
 /* -- OPL one of slot  -- */
 typedef struct fm_opl_slot {
@@ -62,7 +60,6 @@ typedef struct fm_opl_channel {
 
 /* OPL state */
 typedef struct fm_opl_f {
-   uint8_t type;   /* chip type */
int clock;  /* master clock  (Hz)*/
int rate;   /* sampling rate (Hz)*/
double freqbase;/* frequency base*/
@@ -108,9 +105,7 @@ typedef struct fm_opl_f {
 } FM_OPL;
 
 /* -- Generic interface section -- */
-#define OPL_TYPE_YM3812 (OPL_TYPE_WAVESEL)
-
-FM_OPL *OPLCreate(int type, int clock, int rate);
+FM_OPL *OPLCreate(int clock, int rate);
 void OPLDestroy(FM_OPL *OPL);
 void OPLSetTimerHandler(FM_OPL *OPL,OPL_TIMERHANDLER TimerHandler,int 
channelOffset);
 void OPLSetIRQHandler(FM_OPL *OPL,OPL_IRQHANDLER IRQHandler,int param);
-- 
2.9.3




[Qemu-devel] [PATCH 01/26] adlib: Remove support for YMF262

2017-04-25 Thread Juan Quintela
Notice that the code was supposed to be in the file ymf262.h, that has
never been on qemu source tree.

Signed-off-by: Juan Quintela 
---
 hw/audio/adlib.c | 45 +
 1 file changed, 1 insertion(+), 44 deletions(-)

diff --git a/hw/audio/adlib.c b/hw/audio/adlib.c
index 7836446..f9adcd7 100644
--- a/hw/audio/adlib.c
+++ b/hw/audio/adlib.c
@@ -33,11 +33,7 @@
 
 #define ADLIB_KILL_TIMERS 1
 
-#ifdef HAS_YMF262
-#define ADLIB_DESC "Yamaha YMF262 (OPL3)"
-#else
 #define ADLIB_DESC "Yamaha YM3812 (OPL2)"
-#endif
 
 #ifdef DEBUG
 #include "qemu/timer.h"
@@ -50,14 +46,8 @@
 #define ldebug(...)
 #endif
 
-#ifdef HAS_YMF262
-#include "ymf262.h"
-void YMF262UpdateOneQEMU (int which, INT16 *dst, int length);
-#define SHIFT 2
-#else
 #include "fmopl.h"
 #define SHIFT 1
-#endif
 
 #define TYPE_ADLIB "adlib"
 #define ADLIB(obj) OBJECT_CHECK(AdlibState, (obj), TYPE_ADLIB)
@@ -80,9 +70,7 @@ typedef struct {
 SWVoiceOut *voice;
 int left, pos, samples;
 QEMUAudioTimeStamp ats;
-#ifndef HAS_YMF262
 FM_OPL *opl;
-#endif
 PortioList port_list;
 } AdlibState;
 
@@ -90,11 +78,7 @@ static AdlibState *glob_adlib;
 
 static void adlib_stop_opl_timer (AdlibState *s, size_t n)
 {
-#ifdef HAS_YMF262
-YMF262TimerOver (0, n);
-#else
 OPLTimerOver (s->opl, n);
-#endif
 s->ticking[n] = 0;
 }
 
@@ -131,11 +115,7 @@ static void adlib_write(void *opaque, uint32_t nport, 
uint32_t val)
 
 adlib_kill_timers (s);
 
-#ifdef HAS_YMF262
-YMF262Write (0, a, val);
-#else
 OPLWrite (s->opl, a, val);
-#endif
 }
 
 static uint32_t adlib_read(void *opaque, uint32_t nport)
@@ -145,12 +125,8 @@ static uint32_t adlib_read(void *opaque, uint32_t nport)
 int a = nport & 3;
 
 adlib_kill_timers (s);
-
-#ifdef HAS_YMF262
-data = YMF262Read (0, a);
-#else
 data = OPLRead (s->opl, a);
-#endif
+
 return data;
 }
 
@@ -240,11 +216,7 @@ static void adlib_callback (void *opaque, int free)
 return;
 }
 
-#ifdef HAS_YMF262
-YMF262UpdateOneQEMU (0, s->mixbuf + s->pos * 2, samples);
-#else
 YM3812UpdateOne (s->opl, s->mixbuf + s->pos, samples);
-#endif
 
 while (samples) {
 written = write_audio (s, samples);
@@ -263,14 +235,10 @@ static void adlib_callback (void *opaque, int free)
 
 static void Adlib_fini (AdlibState *s)
 {
-#ifdef HAS_YMF262
-YMF262Shutdown ();
-#else
 if (s->opl) {
 OPLDestroy (s->opl);
 s->opl = NULL;
 }
-#endif
 
 g_free(s->mixbuf);
 
@@ -297,16 +265,6 @@ static void adlib_realizefn (DeviceState *dev, Error 
**errp)
 }
 glob_adlib = s;
 
-#ifdef HAS_YMF262
-if (YMF262Init (1, 14318180, s->freq)) {
-error_setg (errp, "YMF262Init %d failed", s->freq);
-return;
-}
-else {
-YMF262SetTimerHandler (0, timer_handler, 0);
-s->enabled = 1;
-}
-#else
 s->opl = OPLCreate (OPL_TYPE_YM3812, 3579545, s->freq);
 if (!s->opl) {
 error_setg (errp, "OPLCreate %d failed", s->freq);
@@ -316,7 +274,6 @@ static void adlib_realizefn (DeviceState *dev, Error **errp)
 OPLSetTimerHandler (s->opl, timer_handler, 0);
 s->enabled = 1;
 }
-#endif
 
 as.freq = s->freq;
 as.nchannels = SHIFT;
-- 
2.9.3




[Qemu-devel] [PATCH 02/26] audio: remove Y8950 configuration

2017-04-25 Thread Juan Quintela
Include file has never been on qemu and it has been undefined from the very 
beginning.

Signed-off-by: Juan Quintela 
---
 hw/audio/Makefile.objs |   2 -
 hw/audio/fmopl.c   | 146 -
 hw/audio/fmopl.h   |  20 ---
 3 files changed, 168 deletions(-)

diff --git a/hw/audio/Makefile.objs b/hw/audio/Makefile.objs
index 7ce85a2..bb6f07a 100644
--- a/hw/audio/Makefile.objs
+++ b/hw/audio/Makefile.objs
@@ -14,5 +14,3 @@ common-obj-$(CONFIG_PL041) += pl041.o lm4549.o
 common-obj-$(CONFIG_CS4231) += cs4231.o
 common-obj-$(CONFIG_MARVELL_88W8618) += marvell_88w8618.o
 common-obj-$(CONFIG_MILKYMIST) += milkymist-ac97.o
-
-$(obj)/adlib.o $(obj)/fmopl.o: QEMU_CFLAGS += -DBUILD_Y8950=0
diff --git a/hw/audio/fmopl.c b/hw/audio/fmopl.c
index 731110f..29f6d3c 100644
--- a/hw/audio/fmopl.c
+++ b/hw/audio/fmopl.c
@@ -812,57 +812,6 @@ static void OPLWriteReg(FM_OPL *OPL, int r, int v)
}
}
return;
-#if BUILD_Y8950
-   case 0x06:  /* Key Board OUT */
-   if(OPL->type_TYPE_KEYBOARD)
-   {
-   if(OPL->keyboardhandler_w)
-   
OPL->keyboardhandler_w(OPL->keyboard_param,v);
-   else
-   LOG(LOG_WAR,("OPL:write unmapped 
KEYBOARD port\n"));
-   }
-   return;
-   case 0x07:  /* DELTA-T control : 
START,REC,MEMDATA,REPT,SPOFF,x,x,RST */
-   if(OPL->type_TYPE_ADPCM)
-   YM_DELTAT_ADPCM_Write(OPL->deltat,r-0x07,v);
-   return;
-   case 0x08:  /* MODE,DELTA-T : 
CSM,NOTESEL,x,x,smpl,da/ad,64k,rom */
-   OPL->mode = v;
-   v&=0x1f;/* for DELTA-T unit */
-   case 0x09:  /* START ADD */
-   case 0x0a:
-   case 0x0b:  /* STOP ADD  */
-   case 0x0c:
-   case 0x0d:  /* PRESCALE   */
-   case 0x0e:
-   case 0x0f:  /* ADPCM data */
-   case 0x10:  /* DELTA-N*/
-   case 0x11:  /* DELTA-N*/
-   case 0x12:  /* EG-CTRL*/
-   if(OPL->type_TYPE_ADPCM)
-   YM_DELTAT_ADPCM_Write(OPL->deltat,r-0x07,v);
-   return;
-#if 0
-   case 0x15:  /* DAC data*/
-   case 0x16:
-   case 0x17:  /* SHIFT*/
-   return;
-   case 0x18:  /* I/O CTRL (Direction) */
-   if(OPL->type_TYPE_IO)
-   OPL->portDirection = v&0x0f;
-   return;
-   case 0x19:  /* I/O DATA */
-   if(OPL->type_TYPE_IO)
-   {
-   OPL->portLatch = v;
-   if(OPL->porthandler_w)
-   
OPL->porthandler_w(OPL->port_param,v>portDirection);
-   }
-   return;
-   case 0x1a:  /* PCM data */
-   return;
-#endif
-#endif
}
break;
case 0x20:  /* am,vib,ksr,eg type,mul */
@@ -1097,68 +1046,6 @@ void YM3812UpdateOne(FM_OPL *OPL, INT16 *buffer, int 
length)
 }
 #endif /* (BUILD_YM3812 || BUILD_YM3526) */
 
-#if BUILD_Y8950
-
-void Y8950UpdateOne(FM_OPL *OPL, INT16 *buffer, int length)
-{
-int i;
-   int data;
-   OPLSAMPLE *buf = buffer;
-   UINT32 amsCnt  = OPL->amsCnt;
-   UINT32 vibCnt  = OPL->vibCnt;
-   UINT8 rhythm = OPL->rhythm&0x20;
-   OPL_CH *CH,*R_CH;
-   YM_DELTAT *DELTAT = OPL->deltat;
-
-   /* setup DELTA-T unit */
-   YM_DELTAT_DECODE_PRESET(DELTAT);
-
-   if( (void *)OPL != cur_chip ){
-   cur_chip = (void *)OPL;
-   /* channel pointers */
-   S_CH = OPL->P_CH;
-   E_CH = _CH[9];
-   /* rhythm slot */
-   SLOT7_1 = _CH[7].SLOT[SLOT1];
-   SLOT7_2 = _CH[7].SLOT[SLOT2];
-   SLOT8_1 = _CH[8].SLOT[SLOT1];
-   SLOT8_2 = _CH[8].SLOT[SLOT2];
-   /* LFO state */
-   amsIncr = OPL->amsIncr;
-   vibIncr = OPL->vibIncr;
-   ams_table = OPL->ams_table;
-   vib_table = OPL->vib_table;
-   }
-   R_CH = rhythm ? _CH[6] : E_CH;
-for( i=0; i < length ; i++ )
-   {
-   /*channel A channel B channel C 
 */
-   /* LFO */
-   ams = ams_table[(amsCnt+=amsIncr)>>AMS_SHIFT];

[Qemu-devel] [PATCH 00/26] Audio Cleanup

2017-04-25 Thread Juan Quintela
Hi

This are an old series that were hidden on my harddisk.  To give you
one idea, I had a patch to remove this:

commit 8307c294a355bbf3c5352e00877365b0cda66d52
Author: Nutan Shinde 
Date:   Wed Oct 7 22:02:54 2015 +0530

Remove macros IO_READ_PROTO and IO_WRITE_PROTO

And somebody else removed it and got it upstream.

There are just cleanups of removing unused code, or moving audio to
c89 and int*_t types.

Please, review and consider them.

Later, Juan.


Juan Quintela (26):
  adlib: Remove support for YMF262
  audio: remove Y8950 configuration
  audio: Remove YM3526 support
  audio: YM3812 was always defined
  audio: Remove UINT8
  audio: remove UINT16
  audio: remove UINT32
  audio: Remove INT8
  audio: remove INT16
  audio: Remove INT32
  audio: Unfold OPLSAMPLE
  audio: Remove Unused OPL_TYPE_*
  audio: Remove type field
  audio: Remove unused fields
  audio: GUSbyte is uint8_t
  audio: remove GUSchar
  audio: GUSword is uint16_t
  audio: GUSword is uint16_t
  audio: GUSsample is int16_t
  audio: OPLSetIRQHandler is not used anywhere
  audio: OPLSetUpdateHandler is not used anywhere
  audio: IRQHandler is not used anymore
  audio: UpdateHandler is not used anymore
  audio: Remove unused typedefs
  audio: un-export OPLResetChip
  audio: Use ARRAY_SIZE from qemu/osdep.h

 hw/audio/Makefile.objs  |   2 -
 hw/audio/adlib.c|  47 +---
 hw/audio/fmopl.c| 277 
 hw/audio/fmopl.h| 175 +-
 hw/audio/gus.c  |   2 +-
 hw/audio/gusemu.h   |  22 +---
 hw/audio/gusemu_hal.c   |  74 ++---
 hw/audio/gusemu_mixer.c |  28 ++---
 8 files changed, 153 insertions(+), 474 deletions(-)

-- 
2.9.3




[Qemu-devel] [PATCH 03/26] audio: Remove YM3526 support

2017-04-25 Thread Juan Quintela
It was never compiled in.

Signed-off-by: Juan Quintela 
---
 hw/audio/fmopl.c | 4 ++--
 hw/audio/fmopl.h | 2 --
 2 files changed, 2 insertions(+), 4 deletions(-)

diff --git a/hw/audio/fmopl.c b/hw/audio/fmopl.c
index 29f6d3c..1e05efc 100644
--- a/hw/audio/fmopl.c
+++ b/hw/audio/fmopl.c
@@ -981,7 +981,7 @@ static void OPL_UnLockTable(void)
OPLCloseTable();
 }
 
-#if (BUILD_YM3812 || BUILD_YM3526)
+#if BUILD_YM3812
 
/***/
 /* YM3812 local section
   */
 
/***/
@@ -1044,7 +1044,7 @@ void YM3812UpdateOne(FM_OPL *OPL, INT16 *buffer, int 
length)
}
 #endif
 }
-#endif /* (BUILD_YM3812 || BUILD_YM3526) */
+#endif /* BUILD_YM3812 */
 
 /* -- reset one of chip -- */
 void OPLResetChip(FM_OPL *OPL)
diff --git a/hw/audio/fmopl.h b/hw/audio/fmopl.h
index 96d958a..b254968 100644
--- a/hw/audio/fmopl.h
+++ b/hw/audio/fmopl.h
@@ -3,7 +3,6 @@
 
 /* --- select emulation chips --- */
 #define BUILD_YM3812 (HAS_YM3812)
-//#define BUILD_YM3526 (HAS_YM3526)
 
 /* --- system optimize --- */
 /* select bit size of output : 8 or 16 */
@@ -135,7 +134,6 @@ typedef struct fm_opl_f {
 } FM_OPL;
 
 /* -- Generic interface section -- */
-#define OPL_TYPE_YM3526 (0)
 #define OPL_TYPE_YM3812 (OPL_TYPE_WAVESEL)
 
 FM_OPL *OPLCreate(int type, int clock, int rate);
-- 
2.9.3




[Qemu-devel] [PATCH v5] crypto: qcrypto_random_bytes() now works on windows w/o any other crypto libs

2017-04-25 Thread Geert Martin Ijewski
If no crypto library is included in the build, QEMU uses
qcrypto_random_bytes() to generate random data. That function tried to open
/dev/urandom or /dev/random and if opening both files failed it errored out.

Those files obviously do not exist on windows, so there the code uses
CryptGenRandom().

Furthermore there was some refactoring and a new function
qcrypto_random_init() was introduced. If a proper crypto library (gnutls or
libgcrypt) is included in the build, this function does nothing. If neither
is included it initializes the (platform specific) handles that are used by
qcrypto_random_bytes().
Either:
* a handle to /dev/urandom | /dev/random on unix like systems
* a handle to a cryptographic service provider on windows

Signed-off-by: Geert Martin Ijewski 
---
 crypto/init.c|  6 ++
 crypto/random-gcrypt.c   |  2 ++
 crypto/random-gnutls.c   |  3 +++
 crypto/random-platform.c | 45 +
 include/crypto/random.h  |  9 +
 5 files changed, 57 insertions(+), 8 deletions(-)

diff --git a/crypto/init.c b/crypto/init.c
index f65207e..f131c42 100644
--- a/crypto/init.c
+++ b/crypto/init.c
@@ -32,6 +32,8 @@
 #include 
 #endif
 
+#include "crypto/random.h"
+
 /* #define DEBUG_GNUTLS */
 
 /*
@@ -146,5 +148,9 @@ int qcrypto_init(Error **errp)
 gcry_control(GCRYCTL_INITIALIZATION_FINISHED, 0);
 #endif
 
+if (qcrypto_random_init(errp) < 0) {
+return -1;
+}
+
 return 0;
 }
diff --git a/crypto/random-gcrypt.c b/crypto/random-gcrypt.c
index 0de9a09..9f1c9ee 100644
--- a/crypto/random-gcrypt.c
+++ b/crypto/random-gcrypt.c
@@ -31,3 +31,5 @@ int qcrypto_random_bytes(uint8_t *buf,
 gcry_randomize(buf, buflen, GCRY_STRONG_RANDOM);
 return 0;
 }
+
+int qcrypto_random_init(Error **errp G_GNUC_UNUSED) { return 0; }
diff --git a/crypto/random-gnutls.c b/crypto/random-gnutls.c
index 04b45a8..5350003 100644
--- a/crypto/random-gnutls.c
+++ b/crypto/random-gnutls.c
@@ -41,3 +41,6 @@ int qcrypto_random_bytes(uint8_t *buf,
 
 return 0;
 }
+
+
+int qcrypto_random_init(Error **errp G_GNUC_UNUSED) { return 0; }
diff --git a/crypto/random-platform.c b/crypto/random-platform.c
index 82b755a..0eddb91 100644
--- a/crypto/random-platform.c
+++ b/crypto/random-platform.c
@@ -22,14 +22,16 @@
 
 #include "crypto/random.h"
 
-int qcrypto_random_bytes(uint8_t *buf G_GNUC_UNUSED,
- size_t buflen G_GNUC_UNUSED,
- Error **errp)
-{
-int fd;
-int ret = -1;
-int got;
+#ifdef _WIN32
+#include 
+static HCRYPTPROV hCryptProv;
+#else
+static int fd; /* a file handle to either /dev/urandom or /dev/random */
+#endif
 
+int qcrypto_random_init(Error **errp)
+{
+#ifndef _WIN32
 /* TBD perhaps also add support for BSD getentropy / Linux
  * getrandom syscalls directly */
 fd = open("/dev/urandom", O_RDONLY);
@@ -41,6 +43,25 @@ int qcrypto_random_bytes(uint8_t *buf G_GNUC_UNUSED,
 error_setg(errp, "No /dev/urandom or /dev/random found");
 return -1;
 }
+#else
+if (!CryptAcquireContext(, NULL, NULL, PROV_RSA_FULL,
+ CRYPT_SILENT | CRYPT_VERIFYCONTEXT)) {
+error_setg_win32(errp, GetLastError(),
+ "Unable to create cryptographic provider");
+return -1;
+}
+#endif
+
+return 0;
+}
+
+int qcrypto_random_bytes(uint8_t *buf G_GNUC_UNUSED,
+ size_t buflen G_GNUC_UNUSED,
+ Error **errp)
+{
+#ifndef _WIN32
+int ret = -1;
+int got;
 
 while (buflen > 0) {
 got = read(fd, buf, buflen);
@@ -59,6 +80,14 @@ int qcrypto_random_bytes(uint8_t *buf G_GNUC_UNUSED,
 
 ret = 0;
  cleanup:
-close(fd);
 return ret;
+#else
+if (!CryptGenRandom(hCryptProv, buflen, buf)) {
+error_setg_win32(errp, GetLastError(),
+ "Unable to read random bytes");
+return -1;
+}
+
+return 0;
+#endif
 }
diff --git a/include/crypto/random.h b/include/crypto/random.h
index a101353..a07229c 100644
--- a/include/crypto/random.h
+++ b/include/crypto/random.h
@@ -40,5 +40,14 @@ int qcrypto_random_bytes(uint8_t *buf,
  size_t buflen,
  Error **errp);
 
+/**
+ * qcrypto_random_init:
+ * @errp: pointer to a NULL-initialized error object
+ *
+ * Initializes the handles used by qcrypto_random_bytes
+ *
+ * Returns 0 on success, -1 on error
+ */
+int qcrypto_random_init(Error **errp);
 
 #endif /* QCRYPTO_RANDOM_H */
-- 
2.10.1.windows.1




Re: [Qemu-devel] [PATCH 1/4] migration: alternative way to set instance_id in SaveStateEntry

2017-04-25 Thread Michael Roth
Quoting Daniel Henrique Barboza (2017-04-24 17:08:25)
> From: Jianjun Duan 
> 
> In QOM (QEMU Object Model) migrated objects are identified with instance_id
> which is calculated automatically using their path in the QOM composition
> tree. For some objects, this path could change from source to target in
> migration. To migrate such objects, we need to make sure the instance_id does
> not change from source to target. We add a hook in DeviceClass to do 
> customized
> instance_id calculation in such cases.

When I tried to pluck a subset of these patches for another series it
was noticed that we don't actually need this patch anymore:

  https://lists.gnu.org/archive/html/qemu-devel/2016-11/msg05475.html

hw/ppc/spapr_iommu.c already implements an approach for registering DRCs
that would work for our case as well since DRCs are bus-less and do not sit
on a BusClass that implements bc->get_dev_path, so using
vmstate_register(DEVICE(drc), drck->get_index(drc), ...) will work in
the same way this patch expects it to.

> 
> As a result, in these cases compat will not be set in the concerned
> SaveStateEntry. This will prevent the inconsistent idstr to be sent over in
> migration. We could have set alias_id in a similar way. But that will be
> overloading the purpose of alias_id.
> 
> The first application will be setting instance_id for pseries DRC objects 
> using
> its unique index. Doing this makes the instance_id of DRC to be consistent
> across migration and supports flexible management of DRC objects in migration.
> 
> Signed-off-by: Jianjun Duan 
> Signed-off-by: Daniel Henrique Barboza 
> ---
>  include/hw/qdev-core.h | 6 ++
>  migration/savevm.c | 6 ++
>  2 files changed, 12 insertions(+)
> 
> diff --git a/include/hw/qdev-core.h b/include/hw/qdev-core.h
> index 4bf86b0..9b3914c 100644
> --- a/include/hw/qdev-core.h
> +++ b/include/hw/qdev-core.h
> @@ -127,6 +127,12 @@ typedef struct DeviceClass {
>  qdev_initfn init; /* TODO remove, once users are converted to realize */
>  qdev_event exit; /* TODO remove, once users are converted to unrealize */
>  const char *bus_type;
> +
> +/* When this field is set, qemu will use it to get an unique instance_id
> + * instead of calculating an auto idstr and instance_id for the relevant
> + * SaveStateEntry
> + */
> +int (*dev_get_instance_id)(DeviceState *dev);
>  } DeviceClass;
> 
>  typedef struct NamedGPIOList NamedGPIOList;
> diff --git a/migration/savevm.c b/migration/savevm.c
> index 03ae1bd..5d8135f 100644
> --- a/migration/savevm.c
> +++ b/migration/savevm.c
> @@ -606,6 +606,9 @@ int register_savevm_live(DeviceState *dev,
>   calculate_compat_instance_id(idstr) : instance_id;
>  instance_id = -1;
>  }
> +if (DEVICE_GET_CLASS(dev)->dev_get_instance_id) {
> +instance_id = DEVICE_GET_CLASS(dev)->dev_get_instance_id(dev);
> +}
>  }
>  pstrcat(se->idstr, sizeof(se->idstr), idstr);
> 
> @@ -696,6 +699,9 @@ int vmstate_register_with_alias_id(DeviceState *dev, int 
> instance_id,
>   calculate_compat_instance_id(vmsd->name) : 
> instance_id;
>  instance_id = -1;
>  }
> +if (DEVICE_GET_CLASS(dev)->dev_get_instance_id) {
> +instance_id = DEVICE_GET_CLASS(dev)->dev_get_instance_id(dev);
> +}
>  }
>  pstrcat(se->idstr, sizeof(se->idstr), vmsd->name);
> 
> -- 
> 2.9.3
> 
> 




[Qemu-devel] [PATCH 37/41] migration: Move last funtions to misc.h

2017-04-25 Thread Juan Quintela
After this, nothing outside of migration uses migration.h

Signed-off-by: Juan Quintela 
---
 include/migration/migration.h | 7 ---
 include/migration/misc.h  | 8 +++-
 ui/spice-core.c   | 2 +-
 3 files changed, 8 insertions(+), 9 deletions(-)

diff --git a/include/migration/migration.h b/include/migration/migration.h
index 1e18b24..735f565 100644
--- a/include/migration/migration.h
+++ b/include/migration/migration.h
@@ -133,17 +133,10 @@ void migrate_fd_error(MigrationState *s, const Error 
*error);
 
 void migrate_fd_connect(MigrationState *s);
 
-void add_migration_state_change_notifier(Notifier *notify);
-void remove_migration_state_change_notifier(Notifier *notify);
 MigrationState *migrate_init(void);
 bool migration_is_blocked(Error **errp);
-bool migration_in_setup(MigrationState *);
-bool migration_has_finished(MigrationState *);
-bool migration_has_failed(MigrationState *);
 /* True if outgoing migration has entered postcopy phase */
 bool migration_in_postcopy(void);
-/* ...and after the device transmission */
-bool migration_in_postcopy_after_devices(MigrationState *);
 MigrationState *migrate_get_current(void);
 
 bool migrate_release_ram(void);
diff --git a/include/migration/misc.h b/include/migration/misc.h
index 6709b15..28f69be 100644
--- a/include/migration/misc.h
+++ b/include/migration/misc.h
@@ -41,5 +41,11 @@ void savevm_skip_configuration(void);
 /* migration/migration.c */
 void qemu_start_incoming_migration(const char *uri, Error **errp);
 bool migration_is_idle(void);
-
+void add_migration_state_change_notifier(Notifier *notify);
+void remove_migration_state_change_notifier(Notifier *notify);
+bool migration_in_setup(MigrationState *);
+bool migration_has_finished(MigrationState *);
+bool migration_has_failed(MigrationState *);
+/* ...and after the device transmission */
+bool migration_in_postcopy_after_devices(MigrationState *);
 #endif
diff --git a/ui/spice-core.c b/ui/spice-core.c
index 804abc5..a087ad5 100644
--- a/ui/spice-core.c
+++ b/ui/spice-core.c
@@ -35,7 +35,7 @@
 #include "qapi/qmp/qstring.h"
 #include "qapi/qmp/qjson.h"
 #include "qemu/notify.h"
-#include "migration/migration.h"
+#include "migration/misc.h"
 #include "hw/hw.h"
 #include "ui/spice-display.h"
 #include "qapi-event.h"
-- 
2.9.3




Re: [Qemu-devel] [PATCH v4] crypto: qcrypto_random_bytes() now works on windows w/o any other crypto libs

2017-04-25 Thread no-reply
Hi,

This series failed automatic build test. Please find the testing commands and
their output below. If you have docker installed, you can probably reproduce it
locally.

Message-id: 1493157212-22070-1-git-send-email-gm.ijew...@web.de
Subject: [Qemu-devel] [PATCH v4] crypto: qcrypto_random_bytes() now works on 
windows w/o any other crypto libs
Type: series

=== TEST SCRIPT BEGIN ===
#!/bin/bash
set -e
git submodule update --init dtc
# Let docker tests dump environment info
export SHOW_ENV=1
export J=8
make docker-test-quick@centos6
make docker-test-mingw@fedora
make docker-test-build@min-glib
=== TEST SCRIPT END ===

Updating 3c8cf5a9c21ff8782164d1def7f44bd888713384
From https://github.com/patchew-project/qemu
 * [new tag] 
patchew/1493157212-22070-1-git-send-email-gm.ijew...@web.de -> 
patchew/1493157212-22070-1-git-send-email-gm.ijew...@web.de
Switched to a new branch 'test'
14d16be crypto: qcrypto_random_bytes() now works on windows w/o any other 
crypto libs

=== OUTPUT BEGIN ===
Submodule 'dtc' (git://git.qemu-project.org/dtc.git) registered for path 'dtc'
Cloning into '/var/tmp/patchew-tester-tmp-enwbuccb/src/dtc'...
Submodule path 'dtc': checked out '558cd81bdd432769b59bff01240c44f82cfb1a9d'
  BUILD   centos6
make[1]: Entering directory '/var/tmp/patchew-tester-tmp-enwbuccb/src'
  ARCHIVE qemu.tgz
  ARCHIVE dtc.tgz
  COPYRUNNER
RUN test-quick in qemu:centos6 
Packages installed:
SDL-devel-1.2.14-7.el6_7.1.x86_64
ccache-3.1.6-2.el6.x86_64
epel-release-6-8.noarch
gcc-4.4.7-17.el6.x86_64
git-1.7.1-4.el6_7.1.x86_64
glib2-devel-2.28.8-5.el6.x86_64
libfdt-devel-1.4.0-1.el6.x86_64
make-3.81-23.el6.x86_64
package g++ is not installed
pixman-devel-0.32.8-1.el6.x86_64
tar-1.23-15.el6_8.x86_64
zlib-devel-1.2.3-29.el6.x86_64

Environment variables:
PACKAGES=libfdt-devel ccache tar git make gcc g++ zlib-devel 
glib2-devel SDL-devel pixman-devel epel-release
HOSTNAME=7c9e7a41478a
TERM=xterm
MAKEFLAGS= -j8
HISTSIZE=1000
J=8
USER=root
CCACHE_DIR=/var/tmp/ccache
EXTRA_CONFIGURE_OPTS=
V=
SHOW_ENV=1
MAIL=/var/spool/mail/root
PATH=/usr/lib/ccache:/usr/lib64/ccache:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
PWD=/
LANG=en_US.UTF-8
TARGET_LIST=
HISTCONTROL=ignoredups
SHLVL=1
HOME=/root
TEST_DIR=/tmp/qemu-test
LOGNAME=root
LESSOPEN=||/usr/bin/lesspipe.sh %s
FEATURES= dtc
DEBUG=
G_BROKEN_FILENAMES=1
CCACHE_HASHDIR=
_=/usr/bin/env

Configure options:
--enable-werror --target-list=x86_64-softmmu,aarch64-softmmu 
--prefix=/var/tmp/qemu-build/install
grep: scripts/tracetool/backend/*.py: No such file or directory
No C++ compiler available; disabling C++ specific optional code
Install prefix/var/tmp/qemu-build/install
BIOS directory/var/tmp/qemu-build/install/share/qemu
binary directory  /var/tmp/qemu-build/install/bin
library directory /var/tmp/qemu-build/install/lib
module directory  /var/tmp/qemu-build/install/lib/qemu
libexec directory /var/tmp/qemu-build/install/libexec
include directory /var/tmp/qemu-build/install/include
config directory  /var/tmp/qemu-build/install/etc
local state directory   /var/tmp/qemu-build/install/var
Manual directory  /var/tmp/qemu-build/install/share/man
ELF interp prefix /usr/gnemul/qemu-%M
Source path   /tmp/qemu-test/src
C compilercc
Host C compiler   cc
C++ compiler  
Objective-C compiler cc
ARFLAGS   rv
CFLAGS-O2 -U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=2 -g 
QEMU_CFLAGS   -I/usr/include/pixman-1   -I$(SRC_PATH)/dtc/libfdt -pthread 
-I/usr/include/glib-2.0 -I/usr/lib64/glib-2.0/include   -fPIE -DPIE -m64 -mcx16 
-D_GNU_SOURCE -D_FILE_OFFSET_BITS=64 -D_LARGEFILE_SOURCE -Wstrict-prototypes 
-Wredundant-decls -Wall -Wundef -Wwrite-strings -Wmissing-prototypes 
-fno-strict-aliasing -fno-common -fwrapv  -Wendif-labels 
-Wno-missing-include-dirs -Wempty-body -Wnested-externs -Wformat-security 
-Wformat-y2k -Winit-self -Wignored-qualifiers -Wold-style-declaration 
-Wold-style-definition -Wtype-limits -fstack-protector-all
LDFLAGS   -Wl,--warn-common -Wl,-z,relro -Wl,-z,now -pie -m64 -g 
make  make
install   install
pythonpython -B
smbd  /usr/sbin/smbd
module supportno
host CPU  x86_64
host big endian   no
target list   x86_64-softmmu aarch64-softmmu
tcg debug enabled no
gprof enabled no
sparse enabledno
strip binariesyes
profiler  no
static build  no
pixmansystem
SDL support   yes (1.2.14)
GTK support   no 
GTK GL supportno
VTE support   no 
TLS priority  NORMAL
GNUTLS supportno
GNUTLS rndno
libgcrypt no
libgcrypt kdf no
nettleno 
nettle kdfno
libtasn1  no
curses supportno
virgl support no
curl support  no
mingw32 support   no
Audio drivers oss
Block whitelist (rw) 
Block whitelist (ro) 
VirtFS supportno
VNC support   yes
VNC SASL support  no
VNC JPEG support  no
VNC PNG support   no
xen support   no
brlapi 

[Qemu-devel] [PATCH 36/41] migration: Move more exported functions to migration/misc.h

2017-04-25 Thread Juan Quintela
Signed-off-by: Juan Quintela 
---
 hw/i386/pc_piix.c | 2 +-
 hw/ppc/spapr.c| 2 +-
 include/migration/migration.h | 6 --
 include/migration/misc.h  | 6 ++
 migration/migration.c | 1 +
 qdev-monitor.c| 2 +-
 vl.c  | 1 -
 xen-common.c  | 2 +-
 8 files changed, 11 insertions(+), 11 deletions(-)

diff --git a/hw/i386/pc_piix.c b/hw/i386/pc_piix.c
index 6c72bd3..d68859e 100644
--- a/hw/i386/pc_piix.c
+++ b/hw/i386/pc_piix.c
@@ -53,7 +53,7 @@
 #include "hw/xen/xen_pt.h"
 #endif
 #include "migration/global_state.h"
-#include "migration/migration.h"
+#include "migration/misc.h"
 #include "kvm_i386.h"
 
 #define MAX_IDE_BUS 2
diff --git a/hw/ppc/spapr.c b/hw/ppc/spapr.c
index f779c35..74cea96 100644
--- a/hw/ppc/spapr.c
+++ b/hw/ppc/spapr.c
@@ -38,7 +38,7 @@
 #include "sysemu/cpus.h"
 #include "sysemu/hw_accel.h"
 #include "kvm_ppc.h"
-#include "migration/migration.h"
+#include "migration/misc.h"
 #include "migration/global_state.h"
 #include "migration/register.h"
 #include "mmu-hash64.h"
diff --git a/include/migration/migration.h b/include/migration/migration.h
index fc31f8e..1e18b24 100644
--- a/include/migration/migration.h
+++ b/include/migration/migration.h
@@ -127,8 +127,6 @@ void migrate_set_state(int *state, int old_state, int 
new_state);
 
 void migration_fd_process_incoming(QEMUFile *f);
 
-void qemu_start_incoming_migration(const char *uri, Error **errp);
-
 uint64_t migrate_max_downtime(void);
 
 void migrate_fd_error(MigrationState *s, const Error *error);
@@ -140,7 +138,6 @@ void remove_migration_state_change_notifier(Notifier 
*notify);
 MigrationState *migrate_init(void);
 bool migration_is_blocked(Error **errp);
 bool migration_in_setup(MigrationState *);
-bool migration_is_idle(void);
 bool migration_has_finished(MigrationState *);
 bool migration_has_failed(MigrationState *);
 /* True if outgoing migration has entered postcopy phase */
@@ -176,7 +173,4 @@ void migrate_send_rp_pong(MigrationIncomingState *mis,
 void migrate_send_rp_req_pages(MigrationIncomingState *mis, const char* rbname,
   ram_addr_t start, size_t len);
 
-void savevm_skip_section_footers(void);
-void savevm_skip_configuration(void);
-
 #endif
diff --git a/include/migration/misc.h b/include/migration/misc.h
index 21a9182..6709b15 100644
--- a/include/migration/misc.h
+++ b/include/migration/misc.h
@@ -35,5 +35,11 @@ int64_t self_announce_delay(int round)
 /* migration/savevm.c */
 
 void dump_vmstate_json_to_file(FILE *out_fp);
+void savevm_skip_section_footers(void);
+void savevm_skip_configuration(void);
+
+/* migration/migration.c */
+void qemu_start_incoming_migration(const char *uri, Error **errp);
+bool migration_is_idle(void);
 
 #endif
diff --git a/migration/migration.c b/migration/migration.c
index 4cda97c..287b762 100644
--- a/migration/migration.c
+++ b/migration/migration.c
@@ -24,6 +24,7 @@
 #include "ram.h"
 #include "rdma.h"
 #include "migration/global_state.h"
+#include "migration/misc.h"
 #include "migration/migration.h"
 #include "savevm.h"
 #include "qemu-file-channel.h"
diff --git a/qdev-monitor.c b/qdev-monitor.c
index e61d596..5ab468f 100644
--- a/qdev-monitor.c
+++ b/qdev-monitor.c
@@ -29,7 +29,7 @@
 #include "qemu/error-report.h"
 #include "qemu/help_option.h"
 #include "sysemu/block-backend.h"
-#include "migration/migration.h"
+#include "migration/misc.h"
 
 /*
  * Aliases were a bad idea from the start.  Let's keep them
diff --git a/vl.c b/vl.c
index c0796e4..d506c7e 100644
--- a/vl.c
+++ b/vl.c
@@ -92,7 +92,6 @@ int main(int argc, char **argv)
 #include "sysemu/tpm.h"
 #include "sysemu/dma.h"
 #include "audio/audio.h"
-#include "migration/migration.h"
 #include "sysemu/cpus.h"
 #include "migration/colo.h"
 #include "sysemu/kvm.h"
diff --git a/xen-common.c b/xen-common.c
index 172131a..2daf2aa 100644
--- a/xen-common.c
+++ b/xen-common.c
@@ -13,7 +13,7 @@
 #include "qmp-commands.h"
 #include "sysemu/char.h"
 #include "sysemu/accel.h"
-#include "migration/migration.h"
+#include "migration/misc.h"
 #include "migration/global_state.h"
 
 //#define DEBUG_XEN
-- 
2.9.3




[Qemu-devel] [PATCH 41/41] migration: Remove unneeded includes

2017-04-25 Thread Juan Quintela
Signed-off-by: Juan Quintela 
---
 include/migration/misc.h  | 2 ++
 migration/block.c | 6 --
 migration/colo-failover.c | 2 ++
 migration/colo.c  | 2 --
 migration/colo.h  | 3 ---
 migration/exec.c  | 2 --
 migration/fd.c| 2 --
 migration/global_state.c  | 1 -
 migration/migration.c | 6 --
 migration/migration.h | 2 --
 migration/postcopy-ram.c  | 4 +---
 migration/qemu-file.c | 2 --
 migration/ram.c   | 4 
 migration/savevm.c| 6 --
 14 files changed, 5 insertions(+), 39 deletions(-)

diff --git a/include/migration/misc.h b/include/migration/misc.h
index 28f69be..5c62e92 100644
--- a/include/migration/misc.h
+++ b/include/migration/misc.h
@@ -14,6 +14,8 @@
 #ifndef MIGRATION_MISC_H
 #define MIGRATION_MISC_H
 
+#include "qemu/notify.h"
+
 /* migration/ram.c */
 
 void ram_mig_init(void);
diff --git a/migration/block.c b/migration/block.c
index 6457f25..5c89436 100644
--- a/migration/block.c
+++ b/migration/block.c
@@ -15,19 +15,13 @@
 
 #include "qemu/osdep.h"
 #include "qapi/error.h"
-#include "qemu-common.h"
-#include "block/block.h"
 #include "qemu/error-report.h"
-#include "qemu/main-loop.h"
-#include "hw/hw.h"
 #include "qemu/cutils.h"
 #include "qemu/queue.h"
-#include "qemu/timer.h"
 #include "block.h"
 #include "migration/misc.h"
 #include "migration.h"
 #include "migration/register.h"
-#include "sysemu/blockdev.h"
 #include "qemu-file.h"
 #include "migration/vmstate.h"
 #include "sysemu/block-backend.h"
diff --git a/migration/colo-failover.c b/migration/colo-failover.c
index 85c4526..9f2fb71 100644
--- a/migration/colo-failover.c
+++ b/migration/colo-failover.c
@@ -11,7 +11,9 @@
  */
 
 #include "qemu/osdep.h"
+#include "qemu/main-loop.h"
 #include "colo.h"
+#include "migration.h"
 #include "colo-failover.h"
 #include "qmp-commands.h"
 #include "qapi/qmp/qerror.h"
diff --git a/migration/colo.c b/migration/colo.c
index 72001a5..4f41d2a 100644
--- a/migration/colo.c
+++ b/migration/colo.c
@@ -11,7 +11,6 @@
  */
 
 #include "qemu/osdep.h"
-#include "qemu/timer.h"
 #include "sysemu/sysemu.h"
 #include "qemu-file-channel.h"
 #include "migration.h"
@@ -21,7 +20,6 @@
 #include "io/channel-buffer.h"
 #include "trace.h"
 #include "qemu/error-report.h"
-#include "qapi/error.h"
 #include "colo-failover.h"
 #include "replication.h"
 #include "qmp-commands.h"
diff --git a/migration/colo.h b/migration/colo.h
index ba0bb6e..be6beba 100644
--- a/migration/colo.h
+++ b/migration/colo.h
@@ -14,9 +14,6 @@
 #define QEMU_COLO_H
 
 #include "qemu-common.h"
-#include "qemu/coroutine_int.h"
-#include "qemu/thread.h"
-#include "qemu/main-loop.h"
 
 bool colo_supported(void);
 void colo_info_init(void);
diff --git a/migration/exec.c b/migration/exec.c
index 074943a..6d535dc 100644
--- a/migration/exec.c
+++ b/migration/exec.c
@@ -19,10 +19,8 @@
 
 #include "qemu/osdep.h"
 #include "qapi/error.h"
-#include "qemu-common.h"
 #include "channel.h"
 #include "exec.h"
-#include "migration.h"
 #include "io/channel-command.h"
 #include "trace.h"
 
diff --git a/migration/fd.c b/migration/fd.c
index b2384bf..30f5258 100644
--- a/migration/fd.c
+++ b/migration/fd.c
@@ -16,10 +16,8 @@
 
 #include "qemu/osdep.h"
 #include "qapi/error.h"
-#include "qemu-common.h"
 #include "channel.h"
 #include "fd.h"
-#include "migration.h"
 #include "monitor/monitor.h"
 #include "io/channel-util.h"
 #include "trace.h"
diff --git a/migration/global_state.c b/migration/global_state.c
index 3d67ba2..bf82aa7 100644
--- a/migration/global_state.c
+++ b/migration/global_state.c
@@ -20,7 +20,6 @@
 #include "qapi/util.h"
 #include "migration/global_state.h"
 #include "migration/vmstate.h"
-#include "sysemu/sysemu.h"
 #include "trace.h"
 
 typedef struct {
diff --git a/migration/migration.c b/migration/migration.c
index 38740b4..83caa58 100644
--- a/migration/migration.c
+++ b/migration/migration.c
@@ -16,7 +16,6 @@
 #include "qemu/osdep.h"
 #include "qemu/cutils.h"
 #include "qemu/error-report.h"
-#include "qemu/main-loop.h"
 #include "migration/blocker.h"
 #include "exec.h"
 #include "fd.h"
@@ -30,11 +29,9 @@
 #include "qemu-file-channel.h"
 #include "qemu-file.h"
 #include "migration/vmstate.h"
-#include "sysemu/sysemu.h"
 #include "block/block.h"
 #include "qapi/qmp/qerror.h"
 #include "qapi/util.h"
-#include "qemu/sockets.h"
 #include "qemu/rcu.h"
 #include "block.h"
 #include "postcopy-ram.h"
@@ -42,9 +39,6 @@
 #include "qmp-commands.h"
 #include "trace.h"
 #include "qapi-event.h"
-#include "qom/cpu.h"
-#include "exec/memory.h"
-#include "exec/address-spaces.h"
 #include "exec/target_page.h"
 #include "io/channel-buffer.h"
 #include "colo.h"
diff --git a/migration/migration.h b/migration/migration.h
index 735f565..f6bac81 100644
--- a/migration/migration.h
+++ b/migration/migration.h
@@ -14,10 +14,8 @@
 #ifndef QEMU_MIGRATION_H
 #define QEMU_MIGRATION_H
 
-#include "qapi/qmp/qdict.h"
 #include "qemu-common.h"
 #include "qemu/thread.h"
-#include 

[Qemu-devel] [PATCH 40/41] migration: Make savevm.c target independent

2017-04-25 Thread Juan Quintela
It only needed TARGET_PAGE_SIZE/BITS/BITS_MIN values, so just export
them from exec.h

Signed-off-by: Juan Quintela 
---
 Makefile.target|  2 +-
 exec.c |  9 +
 include/exec/target_page.h |  2 ++
 migration/Makefile.objs|  2 +-
 migration/savevm.c | 14 +++---
 5 files changed, 20 insertions(+), 9 deletions(-)

diff --git a/Makefile.target b/Makefile.target
index e62021d..4020b01 100644
--- a/Makefile.target
+++ b/Makefile.target
@@ -146,7 +146,7 @@ obj-$(CONFIG_KVM) += kvm-all.o
 obj-y += memory.o cputlb.o
 obj-y += memory_mapping.o
 obj-y += dump.o
-obj-y += migration/ram.o migration/savevm.o
+obj-y += migration/ram.o
 LIBS := $(libs_softmmu) $(LIBS)
 
 # xen support
diff --git a/exec.c b/exec.c
index e9a201a..447ac63 100644
--- a/exec.c
+++ b/exec.c
@@ -3387,6 +3387,15 @@ size_t qemu_target_page_size(void)
 return TARGET_PAGE_SIZE;
 }
 
+int qemu_target_page_bits(void)
+{
+return TARGET_PAGE_BITS;
+}
+
+int qemu_target_page_bits_min(void)
+{
+return TARGET_PAGE_BITS_MIN;
+}
 #endif
 
 /*
diff --git a/include/exec/target_page.h b/include/exec/target_page.h
index 0961591..e3a19cc 100644
--- a/include/exec/target_page.h
+++ b/include/exec/target_page.h
@@ -16,5 +16,7 @@
 #define EXEC_TARGET_PAGE_H
 
 size_t qemu_target_page_size(void);
+int qemu_target_page_bits(void);
+int qemu_target_page_bits_min(void);
 
 #endif
diff --git a/migration/Makefile.objs b/migration/Makefile.objs
index 775e4ad..4277c88 100644
--- a/migration/Makefile.objs
+++ b/migration/Makefile.objs
@@ -1,5 +1,5 @@
 common-obj-y += migration.o socket.o fd.o exec.o
-common-obj-y += tls.o channel.o
+common-obj-y += tls.o channel.o savevm.o
 common-obj-y += colo-comm.o colo.o colo-failover.o
 common-obj-y += vmstate.o vmstate-types.o page_cache.o
 common-obj-y += qemu-file.o global_state.o
diff --git a/migration/savevm.c b/migration/savevm.c
index 6a47dcd..2e5f6a4 100644
--- a/migration/savevm.c
+++ b/migration/savevm.c
@@ -27,7 +27,6 @@
  */
 
 #include "qemu/osdep.h"
-#include "cpu.h"
 #include "hw/boards.h"
 #include "hw/hw.h"
 #include "hw/qdev.h"
@@ -315,7 +314,7 @@ static void configuration_pre_save(void *opaque)
 
 state->len = strlen(current_name);
 state->name = current_name;
-state->target_page_bits = TARGET_PAGE_BITS;
+state->target_page_bits = qemu_target_page_bits();
 }
 
 static int configuration_pre_load(void *opaque)
@@ -326,7 +325,7 @@ static int configuration_pre_load(void *opaque)
  * predates the variable-target-page-bits support and is using the
  * minimum possible value for this CPU.
  */
-state->target_page_bits = TARGET_PAGE_BITS_MIN;
+state->target_page_bits = qemu_target_page_bits_min();
 return 0;
 }
 
@@ -341,9 +340,9 @@ static int configuration_post_load(void *opaque, int 
version_id)
 return -EINVAL;
 }
 
-if (state->target_page_bits != TARGET_PAGE_BITS) {
+if (state->target_page_bits != qemu_target_page_bits()) {
 error_report("Received TARGET_PAGE_BITS is %d but local is %d",
- state->target_page_bits, TARGET_PAGE_BITS);
+ state->target_page_bits, qemu_target_page_bits());
 return -EINVAL;
 }
 
@@ -359,7 +358,8 @@ static int configuration_post_load(void *opaque, int 
version_id)
  */
 static bool vmstate_target_page_bits_needed(void *opaque)
 {
-return TARGET_PAGE_BITS > TARGET_PAGE_BITS_MIN;
+return qemu_target_page_bits()
+> qemu_target_page_bits_min();
 }
 
 static const VMStateDescription vmstate_target_page_bits = {
@@ -1165,7 +1165,7 @@ void qemu_savevm_state_complete_precopy(QEMUFile *f, bool 
iterable_only)
 }
 
 vmdesc = qjson_new();
-json_prop_int(vmdesc, "page_size", TARGET_PAGE_SIZE);
+json_prop_int(vmdesc, "page_size", qemu_target_page_size());
 json_start_array(vmdesc, "devices");
 QTAILQ_FOREACH(se, _state.handlers, entry) {
 
-- 
2.9.3




[Qemu-devel] [PATCH 35/41] migration: create global_state.c

2017-04-25 Thread Juan Quintela
It don't belong anywhere else, just the global state where everybody
can stick other things.

Signed-off-by: Juan Quintela 
---
 hw/i386/pc_piix.c|   1 +
 hw/ppc/spapr.c   |   1 +
 include/migration/global_state.h |  26 +++
 include/migration/migration.h|   4 --
 migration/Makefile.objs  |   2 +-
 migration/global_state.c | 143 +++
 migration/migration.c| 121 +
 migration/savevm.c   |   1 +
 vl.c |   1 +
 xen-common.c |   1 +
 10 files changed, 176 insertions(+), 125 deletions(-)
 create mode 100644 include/migration/global_state.h
 create mode 100644 migration/global_state.c

diff --git a/hw/i386/pc_piix.c b/hw/i386/pc_piix.c
index 9f102aa..6c72bd3 100644
--- a/hw/i386/pc_piix.c
+++ b/hw/i386/pc_piix.c
@@ -52,6 +52,7 @@
 #include 
 #include "hw/xen/xen_pt.h"
 #endif
+#include "migration/global_state.h"
 #include "migration/migration.h"
 #include "kvm_i386.h"
 
diff --git a/hw/ppc/spapr.c b/hw/ppc/spapr.c
index 4c4701e..f779c35 100644
--- a/hw/ppc/spapr.c
+++ b/hw/ppc/spapr.c
@@ -39,6 +39,7 @@
 #include "sysemu/hw_accel.h"
 #include "kvm_ppc.h"
 #include "migration/migration.h"
+#include "migration/global_state.h"
 #include "migration/register.h"
 #include "mmu-hash64.h"
 #include "qom/cpu.h"
diff --git a/include/migration/global_state.h b/include/migration/global_state.h
new file mode 100644
index 000..84a19d0
--- /dev/null
+++ b/include/migration/global_state.h
@@ -0,0 +1,26 @@
+/*
+ * QEMU live migration
+ *
+ * Copyright IBM, Corp. 2008
+ *
+ * Authors:
+ *  Anthony Liguori   
+ *
+ * This work is licensed under the terms of the GNU GPL, version 2.  See
+ * the COPYING file in the top-level directory.
+ *
+ */
+
+#ifndef QEMU_MIGRATION_GLOBAL_STATE_H
+#define QEMU_MIGRATION_GLOBAL_STATE_H
+
+#include "sysemu/sysemu.h"
+
+void register_global_state(void);
+void global_state_set_optional(void);
+int global_state_store(void);
+void global_state_store_running(void);
+bool global_state_received(void);
+RunState global_state_get_runstate(void);
+
+#endif
diff --git a/include/migration/migration.h b/include/migration/migration.h
index 7bd87f8..fc31f8e 100644
--- a/include/migration/migration.h
+++ b/include/migration/migration.h
@@ -177,10 +177,6 @@ void migrate_send_rp_req_pages(MigrationIncomingState 
*mis, const char* rbname,
   ram_addr_t start, size_t len);
 
 void savevm_skip_section_footers(void);
-void register_global_state(void);
-void global_state_set_optional(void);
 void savevm_skip_configuration(void);
-int global_state_store(void);
-void global_state_store_running(void);
 
 #endif
diff --git a/migration/Makefile.objs b/migration/Makefile.objs
index 812b2ec..775e4ad 100644
--- a/migration/Makefile.objs
+++ b/migration/Makefile.objs
@@ -2,7 +2,7 @@ common-obj-y += migration.o socket.o fd.o exec.o
 common-obj-y += tls.o channel.o
 common-obj-y += colo-comm.o colo.o colo-failover.o
 common-obj-y += vmstate.o vmstate-types.o page_cache.o
-common-obj-y += qemu-file.o
+common-obj-y += qemu-file.o global_state.o
 common-obj-y += qemu-file-channel.o
 common-obj-y += xbzrle.o postcopy-ram.o
 common-obj-y += qjson.o
diff --git a/migration/global_state.c b/migration/global_state.c
new file mode 100644
index 000..3d67ba2
--- /dev/null
+++ b/migration/global_state.c
@@ -0,0 +1,143 @@
+/*
+ * QEMU live migration global state
+ *
+ * Copyright IBM, Corp. 2008
+ *
+ * Authors:
+ *  Anthony Liguori   
+ *
+ * This work is licensed under the terms of the GNU GPL, version 2.  See
+ * the COPYING file in the top-level directory.
+ *
+ * Contributions after 2012-01-13 are licensed under the terms of the
+ * GNU GPL, version 2 or (at your option) any later version.
+ */
+
+#include "qemu/osdep.h"
+#include "qemu/cutils.h"
+#include "qemu/error-report.h"
+#include "qapi/error.h"
+#include "qapi/util.h"
+#include "migration/global_state.h"
+#include "migration/vmstate.h"
+#include "sysemu/sysemu.h"
+#include "trace.h"
+
+typedef struct {
+bool optional;
+uint32_t size;
+uint8_t runstate[100];
+RunState state;
+bool received;
+} GlobalState;
+
+static GlobalState global_state;
+
+int global_state_store(void)
+{
+if (!runstate_store((char *)global_state.runstate,
+sizeof(global_state.runstate))) {
+error_report("runstate name too big: %s", global_state.runstate);
+trace_migrate_state_too_big();
+return -EINVAL;
+}
+return 0;
+}
+
+void global_state_store_running(void)
+{
+const char *state = RunState_lookup[RUN_STATE_RUNNING];
+strncpy((char *)global_state.runstate,
+   state, sizeof(global_state.runstate));
+}
+
+bool global_state_received(void)
+{
+return global_state.received;
+}
+
+RunState global_state_get_runstate(void)
+{
+

[Qemu-devel] [PATCH 38/41] migration: Move migration.h to migration/

2017-04-25 Thread Juan Quintela
Nothing uses it outside of migration.h

Signed-off-by: Juan Quintela 
---
 migration/block.c| 2 +-
 migration/channel.c  | 2 +-
 migration/colo-comm.c| 2 +-
 migration/colo.c | 2 +-
 migration/exec.c | 2 +-
 migration/fd.c   | 2 +-
 migration/migration.c| 2 +-
 {include/migration => migration}/migration.h | 0
 migration/postcopy-ram.c | 2 +-
 migration/qemu-file.c| 2 +-
 migration/ram.c  | 2 +-
 migration/rdma.c | 2 +-
 migration/savevm.c   | 2 +-
 migration/socket.c   | 2 +-
 migration/tls.c  | 2 +-
 migration/vmstate-types.c| 2 +-
 migration/vmstate.c  | 2 +-
 tests/test-vmstate.c | 2 +-
 18 files changed, 17 insertions(+), 17 deletions(-)
 rename {include/migration => migration}/migration.h (100%)

diff --git a/migration/block.c b/migration/block.c
index 307f136..6457f25 100644
--- a/migration/block.c
+++ b/migration/block.c
@@ -25,7 +25,7 @@
 #include "qemu/timer.h"
 #include "block.h"
 #include "migration/misc.h"
-#include "migration/migration.h"
+#include "migration.h"
 #include "migration/register.h"
 #include "sysemu/blockdev.h"
 #include "qemu-file.h"
diff --git a/migration/channel.c b/migration/channel.c
index 5a81a60..633423c 100644
--- a/migration/channel.c
+++ b/migration/channel.c
@@ -16,7 +16,7 @@
 #include "qemu/osdep.h"
 #include "channel.h"
 #include "tls.h"
-#include "migration/migration.h"
+#include "migration.h"
 #include "qemu-file-channel.h"
 #include "trace.h"
 #include "qapi/error.h"
diff --git a/migration/colo-comm.c b/migration/colo-comm.c
index b4288b8..1acdb94 100644
--- a/migration/colo-comm.c
+++ b/migration/colo-comm.c
@@ -12,7 +12,7 @@
  */
 
 #include "qemu/osdep.h"
-#include "migration/migration.h"
+#include "migration.h"
 #include "migration/vmstate.h"
 #include "colo.h"
 #include "trace.h"
diff --git a/migration/colo.c b/migration/colo.c
index 3757ad9..72001a5 100644
--- a/migration/colo.c
+++ b/migration/colo.c
@@ -14,7 +14,7 @@
 #include "qemu/timer.h"
 #include "sysemu/sysemu.h"
 #include "qemu-file-channel.h"
-#include "migration/migration.h"
+#include "migration.h"
 #include "qemu-file.h"
 #include "migration/savevm.h"
 #include "migration/colo.h"
diff --git a/migration/exec.c b/migration/exec.c
index c532c56..074943a 100644
--- a/migration/exec.c
+++ b/migration/exec.c
@@ -22,7 +22,7 @@
 #include "qemu-common.h"
 #include "channel.h"
 #include "exec.h"
-#include "migration/migration.h"
+#include "migration.h"
 #include "io/channel-command.h"
 #include "trace.h"
 
diff --git a/migration/fd.c b/migration/fd.c
index 8a04dcd..b2384bf 100644
--- a/migration/fd.c
+++ b/migration/fd.c
@@ -19,7 +19,7 @@
 #include "qemu-common.h"
 #include "channel.h"
 #include "fd.h"
-#include "migration/migration.h"
+#include "migration.h"
 #include "monitor/monitor.h"
 #include "io/channel-util.h"
 #include "trace.h"
diff --git a/migration/migration.c b/migration/migration.c
index 287b762..fccd779 100644
--- a/migration/migration.c
+++ b/migration/migration.c
@@ -25,7 +25,7 @@
 #include "rdma.h"
 #include "migration/global_state.h"
 #include "migration/misc.h"
-#include "migration/migration.h"
+#include "migration.h"
 #include "savevm.h"
 #include "qemu-file-channel.h"
 #include "qemu-file.h"
diff --git a/include/migration/migration.h b/migration/migration.h
similarity index 100%
rename from include/migration/migration.h
rename to migration/migration.h
diff --git a/migration/postcopy-ram.c b/migration/postcopy-ram.c
index cae5d48..bd23971 100644
--- a/migration/postcopy-ram.c
+++ b/migration/postcopy-ram.c
@@ -19,7 +19,7 @@
 #include "qemu/osdep.h"
 
 #include "qemu-common.h"
-#include "migration/migration.h"
+#include "migration.h"
 #include "qemu-file.h"
 #include "savevm.h"
 #include "postcopy-ram.h"
diff --git a/migration/qemu-file.c b/migration/qemu-file.c
index ab26f4e..e65c373 100644
--- a/migration/qemu-file.c
+++ b/migration/qemu-file.c
@@ -28,7 +28,7 @@
 #include "qemu/iov.h"
 #include "qemu/sockets.h"
 #include "qemu/coroutine.h"
-#include "migration/migration.h"
+#include "migration.h"
 #include "qemu-file.h"
 #include "trace.h"
 
diff --git a/migration/ram.c b/migration/ram.c
index b6cef70..14104f1 100644
--- a/migration/ram.c
+++ b/migration/ram.c
@@ -37,7 +37,7 @@
 #include "qemu/main-loop.h"
 #include "xbzrle.h"
 #include "ram.h"
-#include "migration/migration.h"
+#include "migration.h"
 #include "migration/register.h"
 #include "migration/misc.h"
 #include "qemu-file.h"
diff --git a/migration/rdma.c b/migration/rdma.c
index f8fea9b..1d91266 100644
--- a/migration/rdma.c
+++ b/migration/rdma.c
@@ -18,7 +18,7 @@
 #include 

[Qemu-devel] [PATCH 26/41] migration: Move include/migration/block.h into migration/

2017-04-25 Thread Juan Quintela
All functions were internal, except blk_mig_init() that is exported in
misc.h now.

Signed-off-by: Juan Quintela 
---
 include/migration/misc.h | 4 
 migration/block.c| 3 ++-
 {include/migration => migration}/block.h | 1 -
 migration/migration.c| 2 +-
 vl.c | 1 -
 5 files changed, 7 insertions(+), 4 deletions(-)
 rename {include/migration => migration}/block.h (95%)

diff --git a/include/migration/misc.h b/include/migration/misc.h
index 0b37714..9e64c16 100644
--- a/include/migration/misc.h
+++ b/include/migration/misc.h
@@ -18,4 +18,8 @@
 
 void ram_mig_init(void);
 
+/* migration/block.c */
+
+void blk_mig_init(void);
+
 #endif
diff --git a/migration/block.c b/migration/block.c
index c26bdb2..d19dc15 100644
--- a/migration/block.c
+++ b/migration/block.c
@@ -23,7 +23,8 @@
 #include "qemu/cutils.h"
 #include "qemu/queue.h"
 #include "qemu/timer.h"
-#include "migration/block.h"
+#include "block.h"
+#include "migration/misc.h"
 #include "migration/migration.h"
 #include "sysemu/blockdev.h"
 #include "qemu-file.h"
diff --git a/include/migration/block.h b/migration/block.h
similarity index 95%
rename from include/migration/block.h
rename to migration/block.h
index 41a1ac8..9f6febb 100644
--- a/include/migration/block.h
+++ b/migration/block.h
@@ -14,7 +14,6 @@
 #ifndef MIGRATION_BLOCK_H
 #define MIGRATION_BLOCK_H
 
-void blk_mig_init(void);
 int blk_mig_active(void);
 uint64_t blk_mig_bytes_transferred(void);
 uint64_t blk_mig_bytes_remaining(void);
diff --git a/migration/migration.c b/migration/migration.c
index 394930d..ff32086 100644
--- a/migration/migration.c
+++ b/migration/migration.c
@@ -34,7 +34,7 @@
 #include "qapi/util.h"
 #include "qemu/sockets.h"
 #include "qemu/rcu.h"
-#include "migration/block.h"
+#include "block.h"
 #include "postcopy-ram.h"
 #include "qemu/thread.h"
 #include "qmp-commands.h"
diff --git a/vl.c b/vl.c
index 17c0297..605c98f 100644
--- a/vl.c
+++ b/vl.c
@@ -86,7 +86,6 @@ int main(int argc, char **argv)
 #include "qemu/log.h"
 #include "sysemu/blockdev.h"
 #include "hw/block/block.h"
-#include "migration/block.h"
 #include "migration/misc.h"
 #include "migration/snapshot.h"
 #include "sysemu/tpm.h"
-- 
2.9.3




[Qemu-devel] [PATCH 28/41] migration: Split registration functions from vmstate.h

2017-04-25 Thread Juan Quintela
They are indpendent, and nowadays almost every device register things
with qdev->vmsd.

Signed-off-by: Juan Quintela 
---
 hw/net/vmxnet3.c |  1 +
 hw/ppc/spapr.c   |  1 +
 hw/s390x/s390-skeys.c|  1 +
 hw/s390x/s390-virtio-ccw.c   |  1 +
 include/migration/register.h | 64 
 include/migration/vmstate.h  | 45 ---
 migration/block.c|  1 +
 migration/ram.c  |  1 +
 migration/savevm.c   |  1 +
 slirp/slirp.c|  1 +
 10 files changed, 72 insertions(+), 45 deletions(-)
 create mode 100644 include/migration/register.h

diff --git a/hw/net/vmxnet3.c b/hw/net/vmxnet3.c
index 8b1fab2..21ac646 100644
--- a/hw/net/vmxnet3.c
+++ b/hw/net/vmxnet3.c
@@ -26,6 +26,7 @@
 #include "qemu/bswap.h"
 #include "hw/pci/msix.h"
 #include "hw/pci/msi.h"
+#include "migration/register.h"
 
 #include "vmxnet3.h"
 #include "vmxnet_debug.h"
diff --git a/hw/ppc/spapr.c b/hw/ppc/spapr.c
index 35db949..4c4701e 100644
--- a/hw/ppc/spapr.c
+++ b/hw/ppc/spapr.c
@@ -39,6 +39,7 @@
 #include "sysemu/hw_accel.h"
 #include "kvm_ppc.h"
 #include "migration/migration.h"
+#include "migration/register.h"
 #include "mmu-hash64.h"
 #include "qom/cpu.h"
 
diff --git a/hw/s390x/s390-skeys.c b/hw/s390x/s390-skeys.c
index 619152c..58f084a 100644
--- a/hw/s390x/s390-skeys.c
+++ b/hw/s390x/s390-skeys.c
@@ -15,6 +15,7 @@
 #include "hw/s390x/storage-keys.h"
 #include "qemu/error-report.h"
 #include "sysemu/kvm.h"
+#include "migration/register.h"
 
 #define S390_SKEYS_BUFFER_SIZE 131072  /* Room for 128k storage keys */
 #define S390_SKEYS_SAVE_FLAG_EOS 0x01
diff --git a/hw/s390x/s390-virtio-ccw.c b/hw/s390x/s390-virtio-ccw.c
index 04bd0eb..22716e1 100644
--- a/hw/s390x/s390-virtio-ccw.c
+++ b/hw/s390x/s390-virtio-ccw.c
@@ -28,6 +28,7 @@
 #include "ipl.h"
 #include "hw/s390x/s390-virtio-ccw.h"
 #include "hw/s390x/css-bridge.h"
+#include "migration/register.h"
 
 static const char *const reset_dev_types[] = {
 TYPE_VIRTUAL_CSS_BRIDGE,
diff --git a/include/migration/register.h b/include/migration/register.h
new file mode 100644
index 000..844afaf
--- /dev/null
+++ b/include/migration/register.h
@@ -0,0 +1,64 @@
+/*
+ * QEMU migration vmstate registration
+ *
+ * Copyright IBM, Corp. 2008
+ *
+ * Authors:
+ *  Anthony Liguori   
+ *
+ * This work is licensed under the terms of the GNU GPL, version 2.  See
+ * the COPYING file in the top-level directory.
+ *
+ */
+
+#ifndef MIGRATION_REGISTER_H
+#define MIGRATION_REGISTER_H
+
+typedef void SaveStateHandler(QEMUFile *f, void *opaque);
+typedef int LoadStateHandler(QEMUFile *f, void *opaque, int version_id);
+
+typedef struct SaveVMHandlers {
+/* This runs inside the iothread lock.  */
+SaveStateHandler *save_state;
+
+void (*cleanup)(void *opaque);
+int (*save_live_complete_postcopy)(QEMUFile *f, void *opaque);
+int (*save_live_complete_precopy)(QEMUFile *f, void *opaque);
+
+/* This runs both outside and inside the iothread lock.  */
+bool (*is_active)(void *opaque);
+
+/* This runs outside the iothread lock in the migration case, and
+ * within the lock in the savevm case.  The callback had better only
+ * use data that is local to the migration thread or protected
+ * by other locks.
+ */
+int (*save_live_iterate)(QEMUFile *f, void *opaque);
+
+/* This runs outside the iothread lock!  */
+int (*save_live_setup)(QEMUFile *f, void *opaque);
+void (*save_live_pending)(QEMUFile *f, void *opaque,
+  uint64_t threshold_size,
+  uint64_t *non_postcopiable_pending,
+  uint64_t *postcopiable_pending);
+LoadStateHandler *load_state;
+} SaveVMHandlers;
+
+int register_savevm(DeviceState *dev,
+const char *idstr,
+int instance_id,
+int version_id,
+SaveStateHandler *save_state,
+LoadStateHandler *load_state,
+void *opaque);
+
+int register_savevm_live(DeviceState *dev,
+ const char *idstr,
+ int instance_id,
+ int version_id,
+ SaveVMHandlers *ops,
+ void *opaque);
+
+void unregister_savevm(DeviceState *dev, const char *idstr, void *opaque);
+
+#endif
diff --git a/include/migration/vmstate.h b/include/migration/vmstate.h
index 68d..6b7031f 100644
--- a/include/migration/vmstate.h
+++ b/include/migration/vmstate.h
@@ -29,53 +29,8 @@
 
 #include "migration/qjson.h"
 
-typedef void SaveStateHandler(QEMUFile *f, void *opaque);
 typedef int LoadStateHandler(QEMUFile *f, void *opaque, int version_id);
 
-typedef struct SaveVMHandlers {
-/* This runs inside the iothread lock.  */
-SaveStateHandler *save_state;
-
-void (*cleanup)(void 

[Qemu-devel] [PATCH 33/41] migration: Commands are only used inside migration.c

2017-04-25 Thread Juan Quintela
So, move them there.  Notice that we export functions that send
commands, not the command themselves.

Signed-off-by: Juan Quintela 
---
 include/migration/migration.h | 15 --
 migration/migration.c | 46 +++
 2 files changed, 29 insertions(+), 32 deletions(-)

diff --git a/include/migration/migration.h b/include/migration/migration.h
index ac6e545..9884be6 100644
--- a/include/migration/migration.h
+++ b/include/migration/migration.h
@@ -25,18 +25,6 @@
 /* for vl.c */
 extern int only_migratable;
 
-/* Messages sent on the return path from destination to source */
-enum mig_rp_message_type {
-MIG_RP_MSG_INVALID = 0,  /* Must be 0 */
-MIG_RP_MSG_SHUT, /* sibling will not send any more RP messages */
-MIG_RP_MSG_PONG, /* Response to a PING; data (seq: be32 ) */
-
-MIG_RP_MSG_REQ_PAGES_ID, /* data (start: be64, len: be32, id: string) */
-MIG_RP_MSG_REQ_PAGES,/* data (start: be64, len: be32) */
-
-MIG_RP_MSG_MAX
-};
-
 typedef QLIST_HEAD(, LoadStateEntry) LoadStateEntry_Head;
 
 /* State for the incoming migration */
@@ -181,9 +169,6 @@ int migrate_decompress_threads(void);
 bool migrate_use_events(void);
 
 /* Sending on the return path - generic and then for each message type */
-void migrate_send_rp_message(MigrationIncomingState *mis,
- enum mig_rp_message_type message_type,
- uint16_t len, void *data);
 void migrate_send_rp_shut(MigrationIncomingState *mis,
   uint32_t value);
 void migrate_send_rp_pong(MigrationIncomingState *mis,
diff --git a/migration/migration.c b/migration/migration.c
index d2f3c5e..6e43ae3 100644
--- a/migration/migration.c
+++ b/migration/migration.c
@@ -85,6 +85,18 @@ static NotifierList migration_state_notifiers =
 
 static bool deferred_incoming;
 
+/* Messages sent on the return path from destination to source */
+enum mig_rp_message_type {
+MIG_RP_MSG_INVALID = 0,  /* Must be 0 */
+MIG_RP_MSG_SHUT, /* sibling will not send any more RP messages */
+MIG_RP_MSG_PONG, /* Response to a PING; data (seq: be32 ) */
+
+MIG_RP_MSG_REQ_PAGES_ID, /* data (start: be64, len: be32, id: string) */
+MIG_RP_MSG_REQ_PAGES,/* data (start: be64, len: be32) */
+
+MIG_RP_MSG_MAX
+};
+
 /* When we add fault tolerance, we could have several
migrations at once.  For now we don't need to add
dynamic creation of migration */
@@ -281,6 +293,23 @@ static void deferred_incoming_migration(Error **errp)
 deferred_incoming = true;
 }
 
+/*
+ * Send a message on the return channel back to the source
+ * of the migration.
+ */
+static void migrate_send_rp_message(MigrationIncomingState *mis,
+enum mig_rp_message_type message_type,
+uint16_t len, void *data)
+{
+trace_migrate_send_rp_message((int)message_type, len);
+qemu_mutex_lock(>rp_mutex);
+qemu_put_be16(mis->to_src_file, (unsigned int)message_type);
+qemu_put_be16(mis->to_src_file, len);
+qemu_put_buffer(mis->to_src_file, data, len);
+qemu_fflush(mis->to_src_file);
+qemu_mutex_unlock(>rp_mutex);
+}
+
 /* Request a range of pages from the source VM at the given
  * start address.
  *   rbname: Name of the RAMBlock to request the page in, if NULL it's the same
@@ -461,23 +490,6 @@ void migration_fd_process_incoming(QEMUFile *f)
 }
 
 /*
- * Send a message on the return channel back to the source
- * of the migration.
- */
-void migrate_send_rp_message(MigrationIncomingState *mis,
- enum mig_rp_message_type message_type,
- uint16_t len, void *data)
-{
-trace_migrate_send_rp_message((int)message_type, len);
-qemu_mutex_lock(>rp_mutex);
-qemu_put_be16(mis->to_src_file, (unsigned int)message_type);
-qemu_put_be16(mis->to_src_file, len);
-qemu_put_buffer(mis->to_src_file, data, len);
-qemu_fflush(mis->to_src_file);
-qemu_mutex_unlock(>rp_mutex);
-}
-
-/*
  * Send a 'SHUT' message on the return channel with the given value
  * to indicate that we've finished with the RP.  Non-0 value indicates
  * error.
-- 
2.9.3




[Qemu-devel] [PATCH 39/41] exec: Create include for target_page_size()

2017-04-25 Thread Juan Quintela
That is the only function that we need from exec.c, and having to
include the whole sysemu.h for this.

Signed-off-by: Juan Quintela 
---
 exec.c |  1 +
 include/exec/target_page.h | 20 
 include/sysemu/sysemu.h|  1 -
 migration/migration.c  |  1 +
 migration/postcopy-ram.c   |  1 +
 migration/savevm.c |  1 +
 6 files changed, 24 insertions(+), 1 deletion(-)
 create mode 100644 include/exec/target_page.h

diff --git a/exec.c b/exec.c
index eac6085..e9a201a 100644
--- a/exec.c
+++ b/exec.c
@@ -24,6 +24,7 @@
 #include "qemu/cutils.h"
 #include "cpu.h"
 #include "exec/exec-all.h"
+#include "exec/target_page.h"
 #include "tcg.h"
 #include "hw/qdev-core.h"
 #if !defined(CONFIG_USER_ONLY)
diff --git a/include/exec/target_page.h b/include/exec/target_page.h
new file mode 100644
index 000..0961591
--- /dev/null
+++ b/include/exec/target_page.h
@@ -0,0 +1,20 @@
+
+ /*
+ * QEMU exec target page sizes
+ *
+ * Copyright IBM, Corp. 2008
+ *
+ * Authors:
+ *  Anthony Liguori   
+ *
+ * This work is licensed under the terms of the GNU GPL, version 2.  See
+ * the COPYING file in the top-level directory.
+ *
+ */
+
+#ifndef EXEC_TARGET_PAGE_H
+#define EXEC_TARGET_PAGE_H
+
+size_t qemu_target_page_size(void);
+
+#endif
diff --git a/include/sysemu/sysemu.h b/include/sysemu/sysemu.h
index 503b51f..5970ca4 100644
--- a/include/sysemu/sysemu.h
+++ b/include/sysemu/sysemu.h
@@ -67,7 +67,6 @@ int qemu_reset_requested_get(void);
 void qemu_system_killed(int signal, pid_t pid);
 void qemu_system_reset(bool report);
 void qemu_system_guest_panicked(GuestPanicInformation *info);
-size_t qemu_target_page_size(void);
 
 void qemu_add_exit_notifier(Notifier *notify);
 void qemu_remove_exit_notifier(Notifier *notify);
diff --git a/migration/migration.c b/migration/migration.c
index fccd779..38740b4 100644
--- a/migration/migration.c
+++ b/migration/migration.c
@@ -45,6 +45,7 @@
 #include "qom/cpu.h"
 #include "exec/memory.h"
 #include "exec/address-spaces.h"
+#include "exec/target_page.h"
 #include "io/channel-buffer.h"
 #include "colo.h"
 
diff --git a/migration/postcopy-ram.c b/migration/postcopy-ram.c
index bd23971..88e1646 100644
--- a/migration/postcopy-ram.c
+++ b/migration/postcopy-ram.c
@@ -19,6 +19,7 @@
 #include "qemu/osdep.h"
 
 #include "qemu-common.h"
+#include "exec/target_page.h"
 #include "migration.h"
 #include "qemu-file.h"
 #include "savevm.h"
diff --git a/migration/savevm.c b/migration/savevm.c
index 03ff007..6a47dcd 100644
--- a/migration/savevm.c
+++ b/migration/savevm.c
@@ -50,6 +50,7 @@
 #include "qemu/queue.h"
 #include "sysemu/cpus.h"
 #include "exec/memory.h"
+#include "exec/target_page.h"
 #include "qmp-commands.h"
 #include "trace.h"
 #include "qemu/bitops.h"
-- 
2.9.3




  1   2   3   4   5   >