qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
* [Qemu-devel] [PULL 0/3] Block patches
@ 2016-02-09 15:11 Stefan Hajnoczi
  2016-02-09 15:11 ` [Qemu-devel] [PULL 1/3] iov: avoid memcpy for "simple" iov_from_buf/iov_to_buf Stefan Hajnoczi
                   ` (3 more replies)
  0 siblings, 4 replies; 5+ messages in thread
From: Stefan Hajnoczi @ 2016-02-09 15:11 UTC (permalink / raw)
  To: qemu-devel; +Cc: Peter Maydell, Stefan Hajnoczi

The following changes since commit ee8e8f92a730afc17ab8be6e86df6b9a23b8ebc6:

  Merge remote-tracking branch 'remotes/amit-migration/tags/migration-for-2.6-2' into staging (2016-02-05 14:20:46 +0000)

are available in the git repository at:

  git://github.com/stefanha/qemu.git tags/block-pull-request

for you to fetch changes up to 9dcf8ecd9e74804aa1687e5688386001a1f3f89f:

  block: add missing call to bdrv_drain_recurse (2016-02-09 13:52:26 +0000)

----------------------------------------------------------------

----------------------------------------------------------------

Fam Zheng (1):
  blockjob: Fix hang in block_job_finish_sync

Paolo Bonzini (2):
  iov: avoid memcpy for "simple" iov_from_buf/iov_to_buf
  block: add missing call to bdrv_drain_recurse

 block/io.c               |  1 +
 blockjob.c               |  6 +++++-
 include/block/blockjob.h |  5 +++++
 include/qemu/iov.h       | 34 ++++++++++++++++++++++++++++++----
 util/iov.c               |  8 ++++----
 5 files changed, 45 insertions(+), 9 deletions(-)

-- 
2.5.0

^ permalink raw reply	[flat|nested] 5+ messages in thread

* [Qemu-devel] [PULL 1/3] iov: avoid memcpy for "simple" iov_from_buf/iov_to_buf
  2016-02-09 15:11 [Qemu-devel] [PULL 0/3] Block patches Stefan Hajnoczi
@ 2016-02-09 15:11 ` Stefan Hajnoczi
  2016-02-09 15:11 ` [Qemu-devel] [PULL 2/3] blockjob: Fix hang in block_job_finish_sync Stefan Hajnoczi
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 5+ messages in thread
From: Stefan Hajnoczi @ 2016-02-09 15:11 UTC (permalink / raw)
  To: qemu-devel; +Cc: Peter Maydell, Stefan Hajnoczi, Paolo Bonzini

From: Paolo Bonzini <pbonzini@redhat.com>

memcpy can take a large amount of time for small reads and writes.
For virtio it is a common case that the first iovec can satisfy the
whole read or write.  In that case, and if bytes is a constant to
avoid excessive growth of code, inline the first iteration
into the caller.

Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
Message-id: 1450782213-14227-1-git-send-email-pbonzini@redhat.com
Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
---
 include/qemu/iov.h | 34 ++++++++++++++++++++++++++++++----
 util/iov.c         |  8 ++++----
 2 files changed, 34 insertions(+), 8 deletions(-)

diff --git a/include/qemu/iov.h b/include/qemu/iov.h
index 569b2c2..2847551 100644
--- a/include/qemu/iov.h
+++ b/include/qemu/iov.h
@@ -39,10 +39,36 @@ size_t iov_size(const struct iovec *iov, const unsigned int iov_cnt);
  * such "large" value is -1 (sinice size_t is unsigned),
  * so specifying `-1' as `bytes' means 'up to the end of iovec'.
  */
-size_t iov_from_buf(const struct iovec *iov, unsigned int iov_cnt,
-                    size_t offset, const void *buf, size_t bytes);
-size_t iov_to_buf(const struct iovec *iov, const unsigned int iov_cnt,
-                  size_t offset, void *buf, size_t bytes);
+size_t iov_from_buf_full(const struct iovec *iov, unsigned int iov_cnt,
+                         size_t offset, const void *buf, size_t bytes);
+size_t iov_to_buf_full(const struct iovec *iov, const unsigned int iov_cnt,
+		       size_t offset, void *buf, size_t bytes);
+
+static inline size_t
+iov_from_buf(const struct iovec *iov, unsigned int iov_cnt,
+             size_t offset, const void *buf, size_t bytes)
+{
+    if (__builtin_constant_p(bytes) && iov_cnt &&
+        offset <= iov[0].iov_len && bytes <= iov[0].iov_len - offset) {
+        memcpy(iov[0].iov_base + offset, buf, bytes);
+        return bytes;
+    } else {
+        return iov_from_buf_full(iov, iov_cnt, offset, buf, bytes);
+    }
+}
+
+static inline size_t
+iov_to_buf(const struct iovec *iov, const unsigned int iov_cnt,
+           size_t offset, void *buf, size_t bytes)
+{
+    if (__builtin_constant_p(bytes) && iov_cnt &&
+        offset <= iov[0].iov_len && bytes <= iov[0].iov_len - offset) {
+        memcpy(buf, iov[0].iov_base + offset, bytes);
+        return bytes;
+    } else {
+        return iov_to_buf_full(iov, iov_cnt, offset, buf, bytes);
+    }
+}
 
 /**
  * Set data bytes pointed out by iovec `iov' of size `iov_cnt' elements,
diff --git a/util/iov.c b/util/iov.c
index e802ee1..062f4e5 100644
--- a/util/iov.c
+++ b/util/iov.c
@@ -20,8 +20,8 @@
 #include "qemu/iov.h"
 #include "qemu/sockets.h"
 
-size_t iov_from_buf(const struct iovec *iov, unsigned int iov_cnt,
-                    size_t offset, const void *buf, size_t bytes)
+size_t iov_from_buf_full(const struct iovec *iov, unsigned int iov_cnt,
+                         size_t offset, const void *buf, size_t bytes)
 {
     size_t done;
     unsigned int i;
@@ -39,8 +39,8 @@ size_t iov_from_buf(const struct iovec *iov, unsigned int iov_cnt,
     return done;
 }
 
-size_t iov_to_buf(const struct iovec *iov, const unsigned int iov_cnt,
-                  size_t offset, void *buf, size_t bytes)
+size_t iov_to_buf_full(const struct iovec *iov, const unsigned int iov_cnt,
+                       size_t offset, void *buf, size_t bytes)
 {
     size_t done;
     unsigned int i;
-- 
2.5.0

^ permalink raw reply related	[flat|nested] 5+ messages in thread

* [Qemu-devel] [PULL 2/3] blockjob: Fix hang in block_job_finish_sync
  2016-02-09 15:11 [Qemu-devel] [PULL 0/3] Block patches Stefan Hajnoczi
  2016-02-09 15:11 ` [Qemu-devel] [PULL 1/3] iov: avoid memcpy for "simple" iov_from_buf/iov_to_buf Stefan Hajnoczi
@ 2016-02-09 15:11 ` Stefan Hajnoczi
  2016-02-09 15:11 ` [Qemu-devel] [PULL 3/3] block: add missing call to bdrv_drain_recurse Stefan Hajnoczi
  2016-02-09 19:34 ` [Qemu-devel] [PULL 0/3] Block patches Peter Maydell
  3 siblings, 0 replies; 5+ messages in thread
From: Stefan Hajnoczi @ 2016-02-09 15:11 UTC (permalink / raw)
  To: qemu-devel; +Cc: Peter Maydell, Fam Zheng, Stefan Hajnoczi

From: Fam Zheng <famz@redhat.com>

With a mirror job running on a virtio-blk dataplane disk, sending "q" to
HMP will cause a dead loop in block_job_finish_sync.

This is because the aio_poll() only processes the AIO context of bs
which has no more work to do, while the main loop BH that is scheduled
for setting the job->completed flag is never processed.

Fix this by adding a flag in BlockJob structure, to track which context
to poll for the block job to make progress. Its value is set to true
when block_job_coroutine_complete() is called, and is checked in
block_job_finish_sync to determine which context to poll.

Suggested-by: Stefan Hajnoczi <stefanha@redhat.com>
Signed-off-by: Fam Zheng <famz@redhat.com>
Message-id: 1454379144-29807-1-git-send-email-famz@redhat.com
Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
---
 blockjob.c               | 6 +++++-
 include/block/blockjob.h | 5 +++++
 2 files changed, 10 insertions(+), 1 deletion(-)

diff --git a/blockjob.c b/blockjob.c
index a402181..9fc37ca 100644
--- a/blockjob.c
+++ b/blockjob.c
@@ -296,7 +296,9 @@ static int block_job_finish_sync(BlockJob *job,
         return -EBUSY;
     }
     while (!job->completed) {
-        aio_poll(bdrv_get_aio_context(bs), true);
+        aio_poll(job->deferred_to_main_loop ? qemu_get_aio_context() :
+                                              bdrv_get_aio_context(bs),
+                 true);
     }
     ret = (job->cancelled && job->ret == 0) ? -ECANCELED : job->ret;
     block_job_unref(job);
@@ -470,6 +472,7 @@ static void block_job_defer_to_main_loop_bh(void *opaque)
     aio_context = bdrv_get_aio_context(data->job->bs);
     aio_context_acquire(aio_context);
 
+    data->job->deferred_to_main_loop = false;
     data->fn(data->job, data->opaque);
 
     aio_context_release(aio_context);
@@ -489,6 +492,7 @@ void block_job_defer_to_main_loop(BlockJob *job,
     data->aio_context = bdrv_get_aio_context(job->bs);
     data->fn = fn;
     data->opaque = opaque;
+    job->deferred_to_main_loop = true;
 
     qemu_bh_schedule(data->bh);
 }
diff --git a/include/block/blockjob.h b/include/block/blockjob.h
index d84ccd8..8bedc49 100644
--- a/include/block/blockjob.h
+++ b/include/block/blockjob.h
@@ -130,6 +130,11 @@ struct BlockJob {
      */
     bool ready;
 
+    /**
+     * Set to true when the job has deferred work to the main loop.
+     */
+    bool deferred_to_main_loop;
+
     /** Status that is published by the query-block-jobs QMP API */
     BlockDeviceIoStatus iostatus;
 
-- 
2.5.0

^ permalink raw reply related	[flat|nested] 5+ messages in thread

* [Qemu-devel] [PULL 3/3] block: add missing call to bdrv_drain_recurse
  2016-02-09 15:11 [Qemu-devel] [PULL 0/3] Block patches Stefan Hajnoczi
  2016-02-09 15:11 ` [Qemu-devel] [PULL 1/3] iov: avoid memcpy for "simple" iov_from_buf/iov_to_buf Stefan Hajnoczi
  2016-02-09 15:11 ` [Qemu-devel] [PULL 2/3] blockjob: Fix hang in block_job_finish_sync Stefan Hajnoczi
@ 2016-02-09 15:11 ` Stefan Hajnoczi
  2016-02-09 19:34 ` [Qemu-devel] [PULL 0/3] Block patches Peter Maydell
  3 siblings, 0 replies; 5+ messages in thread
From: Stefan Hajnoczi @ 2016-02-09 15:11 UTC (permalink / raw)
  To: qemu-devel; +Cc: Peter Maydell, Stefan Hajnoczi, Paolo Bonzini

From: Paolo Bonzini <pbonzini@redhat.com>

This is also needed in bdrv_drain_all, not just in bdrv_drain.

Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
Reviewed-by: Fam Zheng <famz@redhat.com>
Reviewed-by: Kevin Wolf <kwolf@redhat.com>
Message-id: 1450867706-19860-3-git-send-email-pbonzini@redhat.com
Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
---
 block/io.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/block/io.c b/block/io.c
index 343ff1f..a69bfc4 100644
--- a/block/io.c
+++ b/block/io.c
@@ -301,6 +301,7 @@ void bdrv_drain_all(void)
         if (bs->job) {
             block_job_pause(bs->job);
         }
+        bdrv_drain_recurse(bs);
         aio_context_release(aio_context);
 
         if (!g_slist_find(aio_ctxs, aio_context)) {
-- 
2.5.0

^ permalink raw reply related	[flat|nested] 5+ messages in thread

* Re: [Qemu-devel] [PULL 0/3] Block patches
  2016-02-09 15:11 [Qemu-devel] [PULL 0/3] Block patches Stefan Hajnoczi
                   ` (2 preceding siblings ...)
  2016-02-09 15:11 ` [Qemu-devel] [PULL 3/3] block: add missing call to bdrv_drain_recurse Stefan Hajnoczi
@ 2016-02-09 19:34 ` Peter Maydell
  3 siblings, 0 replies; 5+ messages in thread
From: Peter Maydell @ 2016-02-09 19:34 UTC (permalink / raw)
  To: Stefan Hajnoczi; +Cc: QEMU Developers

On 9 February 2016 at 15:11, Stefan Hajnoczi <stefanha@redhat.com> wrote:
> The following changes since commit ee8e8f92a730afc17ab8be6e86df6b9a23b8ebc6:
>
>   Merge remote-tracking branch 'remotes/amit-migration/tags/migration-for-2.6-2' into staging (2016-02-05 14:20:46 +0000)
>
> are available in the git repository at:
>
>   git://github.com/stefanha/qemu.git tags/block-pull-request
>
> for you to fetch changes up to 9dcf8ecd9e74804aa1687e5688386001a1f3f89f:
>
>   block: add missing call to bdrv_drain_recurse (2016-02-09 13:52:26 +0000)
>
> ----------------------------------------------------------------
>
> ----------------------------------------------------------------

Applied, thanks.

-- PMM

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2016-02-09 19:34 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-02-09 15:11 [Qemu-devel] [PULL 0/3] Block patches Stefan Hajnoczi
2016-02-09 15:11 ` [Qemu-devel] [PULL 1/3] iov: avoid memcpy for "simple" iov_from_buf/iov_to_buf Stefan Hajnoczi
2016-02-09 15:11 ` [Qemu-devel] [PULL 2/3] blockjob: Fix hang in block_job_finish_sync Stefan Hajnoczi
2016-02-09 15:11 ` [Qemu-devel] [PULL 3/3] block: add missing call to bdrv_drain_recurse Stefan Hajnoczi
2016-02-09 19:34 ` [Qemu-devel] [PULL 0/3] Block patches Peter Maydell

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