qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Paolo Bonzini <pbonzini@redhat.com>
To: qemu-devel@nongnu.org
Cc: Pavel Dovgalyuk <pavel.dovgaluk@ispras.ru>
Subject: [Qemu-devel] [PULL 28/28] replay: allow replay stopping and restarting
Date: Mon, 26 Sep 2016 15:40:58 +0200	[thread overview]
Message-ID: <1474897258-1205-29-git-send-email-pbonzini@redhat.com> (raw)
In-Reply-To: <1474897258-1205-1-git-send-email-pbonzini@redhat.com>

From: Pavel Dovgalyuk <pavel.dovgaluk@ispras.ru>

This patch fixes bug with stopping and restarting replay
through monitor.

Signed-off-by: Pavel Dovgalyuk <pavel.dovgaluk@ispras.ru>
Message-Id: <20160926080815.6992.71818.stgit@PASHA-ISP>
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
---
 block/blkreplay.c        | 15 +++++----------
 cpus.c                   |  1 +
 include/sysemu/replay.h  |  4 ++++
 replay/replay-events.c   |  8 ++++++++
 replay/replay-internal.h |  6 ++++--
 replay/replay-snapshot.c |  1 +
 stubs/replay.c           |  5 +++++
 vl.c                     |  1 +
 8 files changed, 29 insertions(+), 12 deletions(-)

diff --git a/block/blkreplay.c b/block/blkreplay.c
index 30f9d5f..a741654 100755
--- a/block/blkreplay.c
+++ b/block/blkreplay.c
@@ -20,11 +20,6 @@ typedef struct Request {
     QEMUBH *bh;
 } Request;
 
-/* Next request id.
-   This counter is global, because requests from different
-   block devices should not get overlapping ids. */
-static uint64_t request_id;
-
 static int blkreplay_open(BlockDriverState *bs, QDict *options, int flags,
                           Error **errp)
 {
@@ -84,7 +79,7 @@ static void block_request_create(uint64_t reqid, BlockDriverState *bs,
 static int coroutine_fn blkreplay_co_preadv(BlockDriverState *bs,
     uint64_t offset, uint64_t bytes, QEMUIOVector *qiov, int flags)
 {
-    uint64_t reqid = request_id++;
+    uint64_t reqid = blkreplay_next_id();
     int ret = bdrv_co_preadv(bs->file, offset, bytes, qiov, flags);
     block_request_create(reqid, bs, qemu_coroutine_self());
     qemu_coroutine_yield();
@@ -95,7 +90,7 @@ static int coroutine_fn blkreplay_co_preadv(BlockDriverState *bs,
 static int coroutine_fn blkreplay_co_pwritev(BlockDriverState *bs,
     uint64_t offset, uint64_t bytes, QEMUIOVector *qiov, int flags)
 {
-    uint64_t reqid = request_id++;
+    uint64_t reqid = blkreplay_next_id();
     int ret = bdrv_co_pwritev(bs->file, offset, bytes, qiov, flags);
     block_request_create(reqid, bs, qemu_coroutine_self());
     qemu_coroutine_yield();
@@ -106,7 +101,7 @@ static int coroutine_fn blkreplay_co_pwritev(BlockDriverState *bs,
 static int coroutine_fn blkreplay_co_pwrite_zeroes(BlockDriverState *bs,
     int64_t offset, int count, BdrvRequestFlags flags)
 {
-    uint64_t reqid = request_id++;
+    uint64_t reqid = blkreplay_next_id();
     int ret = bdrv_co_pwrite_zeroes(bs->file, offset, count, flags);
     block_request_create(reqid, bs, qemu_coroutine_self());
     qemu_coroutine_yield();
@@ -117,7 +112,7 @@ static int coroutine_fn blkreplay_co_pwrite_zeroes(BlockDriverState *bs,
 static int coroutine_fn blkreplay_co_pdiscard(BlockDriverState *bs,
                                               int64_t offset, int count)
 {
-    uint64_t reqid = request_id++;
+    uint64_t reqid = blkreplay_next_id();
     int ret = bdrv_co_pdiscard(bs->file->bs, offset, count);
     block_request_create(reqid, bs, qemu_coroutine_self());
     qemu_coroutine_yield();
@@ -127,7 +122,7 @@ static int coroutine_fn blkreplay_co_pdiscard(BlockDriverState *bs,
 
 static int coroutine_fn blkreplay_co_flush(BlockDriverState *bs)
 {
-    uint64_t reqid = request_id++;
+    uint64_t reqid = blkreplay_next_id();
     int ret = bdrv_co_flush(bs->file->bs);
     block_request_create(reqid, bs, qemu_coroutine_self());
     qemu_coroutine_yield();
diff --git a/cpus.c b/cpus.c
index fbd70f5..b2fbe33 100644
--- a/cpus.c
+++ b/cpus.c
@@ -750,6 +750,7 @@ static int do_vm_stop(RunState state)
     }
 
     bdrv_drain_all();
+    replay_disable_events();
     ret = blk_flush_all();
 
     return ret;
diff --git a/include/sysemu/replay.h b/include/sysemu/replay.h
index 0a88393..f80d6d2 100644
--- a/include/sysemu/replay.h
+++ b/include/sysemu/replay.h
@@ -105,6 +105,8 @@ bool replay_checkpoint(ReplayCheckpoint checkpoint);
 
 /*! Disables storing events in the queue */
 void replay_disable_events(void);
+/*! Enables storing events in the queue */
+void replay_enable_events(void);
 /*! Returns true when saving events is enabled */
 bool replay_events_enabled(void);
 /*! Adds bottom half event to the queue */
@@ -115,6 +117,8 @@ void replay_input_event(QemuConsole *src, InputEvent *evt);
 void replay_input_sync_event(void);
 /*! Adds block layer event to the queue */
 void replay_block_event(QEMUBH *bh, uint64_t id);
+/*! Returns ID for the next block event */
+uint64_t blkreplay_next_id(void);
 
 /* Character device */
 
diff --git a/replay/replay-events.c b/replay/replay-events.c
index 4eb2ea3..c513913 100644
--- a/replay/replay-events.c
+++ b/replay/replay-events.c
@@ -309,3 +309,11 @@ bool replay_events_enabled(void)
 {
     return events_enabled;
 }
+
+uint64_t blkreplay_next_id(void)
+{
+    if (replay_events_enabled()) {
+        return replay_state.block_request_id++;
+    }
+    return 0;
+}
diff --git a/replay/replay-internal.h b/replay/replay-internal.h
index e07eb7d..9117e44 100644
--- a/replay/replay-internal.h
+++ b/replay/replay-internal.h
@@ -68,6 +68,10 @@ typedef struct ReplayState {
     unsigned int has_unread_data;
     /*! Temporary variable for saving current log offset. */
     uint64_t file_offset;
+    /*! Next block operation id.
+        This counter is global, because requests from different
+        block devices should not get overlapping ids. */
+    uint64_t block_request_id;
 } ReplayState;
 extern ReplayState replay_state;
 
@@ -123,8 +127,6 @@ void replay_read_next_clock(unsigned int kind);
 void replay_init_events(void);
 /*! Clears internal data structures for events handling */
 void replay_finish_events(void);
-/*! Enables storing events in the queue */
-void replay_enable_events(void);
 /*! Flushes events queue */
 void replay_flush_events(void);
 /*! Clears events list before loading new VM state */
diff --git a/replay/replay-snapshot.c b/replay/replay-snapshot.c
index bd95dcd..5a70869 100644
--- a/replay/replay-snapshot.c
+++ b/replay/replay-snapshot.c
@@ -50,6 +50,7 @@ static const VMStateDescription vmstate_replay = {
         VMSTATE_UINT32(data_kind, ReplayState),
         VMSTATE_UINT32(has_unread_data, ReplayState),
         VMSTATE_UINT64(file_offset, ReplayState),
+        VMSTATE_UINT64(block_request_id, ReplayState),
         VMSTATE_END_OF_LIST()
     },
 };
diff --git a/stubs/replay.c b/stubs/replay.c
index de9fa1e..d9a6da9 100644
--- a/stubs/replay.c
+++ b/stubs/replay.c
@@ -67,3 +67,8 @@ void replay_char_read_all_save_buf(uint8_t *buf, int offset)
 void replay_block_event(QEMUBH *bh, uint64_t id)
 {
 }
+
+uint64_t blkreplay_next_id(void)
+{
+    return 0;
+}
diff --git a/vl.c b/vl.c
index eda83fa..5759e0a 100644
--- a/vl.c
+++ b/vl.c
@@ -784,6 +784,7 @@ void vm_start(void)
     if (runstate_is_running()) {
         qapi_event_send_stop(&error_abort);
     } else {
+        replay_enable_events();
         cpu_enable_ticks();
         runstate_set(RUN_STATE_RUNNING);
         vm_state_notify(1, RUN_STATE_RUNNING);
-- 
2.7.4

  parent reply	other threads:[~2016-09-26 13:41 UTC|newest]

Thread overview: 37+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-09-26 13:40 [Qemu-devel] [PULL 00/28] Misc patches for 2016-09-26 Paolo Bonzini
2016-09-26 13:40 ` [Qemu-devel] [PULL 01/28] memory: introduce IOMMUNotifier and its caps Paolo Bonzini
2016-09-26 13:40 ` [Qemu-devel] [PULL 02/28] memory: introduce IOMMUOps.notify_flag_changed Paolo Bonzini
2016-09-26 13:40 ` [Qemu-devel] [PULL 03/28] intel_iommu: allow UNMAP notifiers Paolo Bonzini
2016-09-26 13:40 ` [Qemu-devel] [PULL 04/28] x86: ioapic: boost default version to 0x20 Paolo Bonzini
2016-09-26 13:40 ` [Qemu-devel] [PULL 05/28] checkpatch: downgrade "architecture specific defines should be avoided" Paolo Bonzini
2016-09-26 13:40 ` [Qemu-devel] [PULL 06/28] compiler: Swap 'public domain' header for license Paolo Bonzini
2016-09-26 13:40 ` [Qemu-devel] [PULL 07/28] migration: sync all address spaces Paolo Bonzini
2016-09-26 13:40 ` [Qemu-devel] [PULL 08/28] build-sys: remove unused GLIB_CFLAGS Paolo Bonzini
2016-09-26 13:40 ` [Qemu-devel] [PULL 09/28] build-sys: put glib_cflags in QEMU_CFLAGS Paolo Bonzini
2016-09-26 13:40 ` [Qemu-devel] [PULL 10/28] cpus: pass CPUState to run_on_cpu helpers Paolo Bonzini
2016-09-26 13:40 ` [Qemu-devel] [PULL 11/28] cpus: Move common code out of {async_, }run_on_cpu() Paolo Bonzini
2016-09-26 13:40 ` [Qemu-devel] [PULL 12/28] cpus: Rename flush_queued_work() Paolo Bonzini
2016-09-26 13:40 ` [Qemu-devel] [PULL 13/28] linux-user: Use QemuMutex and QemuCond Paolo Bonzini
2016-09-26 13:40 ` [Qemu-devel] [PULL 14/28] linux-user: Add qemu_cpu_is_self() and qemu_cpu_kick() Paolo Bonzini
2016-09-26 13:40 ` [Qemu-devel] [PULL 15/28] cpus-common: move CPU list management to common code Paolo Bonzini
2016-09-26 13:40 ` [Qemu-devel] [PULL 16/28] cpus-common: move CPU work item " Paolo Bonzini
2016-09-26 13:40 ` [Qemu-devel] [PULL 17/28] cpus-common: fix uninitialized variable use in run_on_cpu Paolo Bonzini
2016-09-26 13:40 ` [Qemu-devel] [PULL 18/28] cpus-common: move exclusive work infrastructure from linux-user Paolo Bonzini
2016-09-26 13:40 ` [Qemu-devel] [PULL 19/28] docs: include formal model for TCG exclusive sections Paolo Bonzini
2016-09-26 13:40 ` [Qemu-devel] [PULL 20/28] cpus-common: always defer async_run_on_cpu work items Paolo Bonzini
2016-09-26 13:40 ` [Qemu-devel] [PULL 21/28] cpus-common: remove redundant call to exclusive_idle() Paolo Bonzini
2016-09-26 13:40 ` [Qemu-devel] [PULL 22/28] cpus-common: simplify locking for start_exclusive/end_exclusive Paolo Bonzini
2016-09-26 13:40 ` [Qemu-devel] [PULL 23/28] cpus-common: Introduce async_safe_run_on_cpu() Paolo Bonzini
2016-09-26 13:40 ` [Qemu-devel] [PULL 24/28] tcg: Make tb_flush() thread safe Paolo Bonzini
2016-09-26 13:40 ` [Qemu-devel] [PULL 25/28] cpus-common: lock-free fast path for cpu_exec_start/end Paolo Bonzini
2016-09-26 13:40 ` [Qemu-devel] [PULL 26/28] replay: move internal data to the structure Paolo Bonzini
2016-09-26 13:40 ` [Qemu-devel] [PULL 27/28] replay: vmstate for replay module Paolo Bonzini
2016-09-26 13:40 ` Paolo Bonzini [this message]
2016-09-26 14:26 ` [Qemu-devel] [PULL 00/28] Misc patches for 2016-09-26 no-reply
2016-09-26 21:19 ` Peter Maydell
2016-09-27  2:12   ` Peter Xu
2016-09-27  8:53     ` Paolo Bonzini
2016-09-27  9:25       ` Peter Xu
2016-09-27 10:11         ` Paolo Bonzini
2016-09-28  3:12           ` Peter Xu
2016-09-28  9:54             ` Jason Wang

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1474897258-1205-29-git-send-email-pbonzini@redhat.com \
    --to=pbonzini@redhat.com \
    --cc=pavel.dovgaluk@ispras.ru \
    --cc=qemu-devel@nongnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).