Skip to contentSkip to conversation

Block patches

GIT PULL Applied Stefan Hajnoczi 2 participants 5 messages Feb 9, 2016 Block layer

lore
Share & tools
lore
#0 lore raw

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(-)
Signature · 1 line
2.5.0
#1 lore raw

[Qemu-devel] [PULL 1/3] iov: avoid memcpy for "simple" iov_from_buf/iov_to_buf

From: Paolo Bonzini <[email protected]>

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.

Message-id: [email protected]

---
 include/qemu/iov.h | 34 ++++++++++++++++++++++++++++++----
 util/iov.c         |  8 ++++----
 2 files changed, 34 insertions(+), 8 deletions(-)
include/qemu/iov.h +30 -4
index 569b2c2..2847551 100644
@@ -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,
util/iov.c +4 -4
index e802ee1..062f4e5 100644
@@ -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;
Signature · 1 line
2.5.0
#2 lore raw

[Qemu-devel] [PULL 2/3] blockjob: Fix hang in block_job_finish_sync

In reply to Stefan Hajnoczi

From: Fam Zheng <[email protected]>

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.

Message-id: [email protected]

---
 blockjob.c               | 6 +++++-
 include/block/blockjob.h | 5 +++++
 2 files changed, 10 insertions(+), 1 deletion(-)
blockjob.c +5 -1
index a402181..9fc37ca 100644
@@ -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);
 }
include/block/blockjob.h +5 -0
index d84ccd8..8bedc49 100644
@@ -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;
 
Signature · 1 line
2.5.0
#3 lore raw

[Qemu-devel] [PULL 3/3] block: add missing call to bdrv_drain_recurse

In reply to Stefan Hajnoczi

From: Paolo Bonzini <[email protected]>

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

Message-id: [email protected]

---
 block/io.c | 1 +
 1 file changed, 1 insertion(+)
block/io.c +1 -0
index 343ff1f..a69bfc4 100644
@@ -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)) {
Signature · 1 line
2.5.0
#4 lore raw
In reply to Stefan Hajnoczi
Quoted 8 lines · 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

Quoted 7 lines

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