From: "Denis V. Lunev" <den@openvz.org>
To: qemu-block@nongnu.org, qemu-devel@nongnu.org
Cc: Kevin Wolf <kwolf@redhat.com>, Fam Zheng <fam@euphon.net>,
Juan Quintela <quintela@redhat.com>,
"Dr. David Alan Gilbert" <dgilbert@redhat.com>,
Max Reitz <mreitz@redhat.com>,
Denis Plotnikov <dplotnikov@virtuozzo.com>,
Stefan Hajnoczi <stefanha@redhat.com>,
"Denis V. Lunev" <den@openvz.org>
Subject: [PATCH 5/6] block, migration: add bdrv_finalize_vmstate helper
Date: Fri, 19 Jun 2020 13:07:07 +0300 [thread overview]
Message-ID: <20200619100708.30440-6-den@openvz.org> (raw)
In-Reply-To: <20200619100708.30440-1-den@openvz.org>
Right now bdrv_fclose() is just calling bdrv_flush().
The problem is that migration code is working inefficiently from block
layer terms and are frequently called for very small pieces of
unaligned data. Block layer is capable to work this way, but this is very
slow.
This patch is a preparation for the introduction of the intermediate
buffer at block driver state. It would be beneficial to separate
conventional bdrv_flush() from closing QEMU file from migration code.
The patch also forces bdrv_finalize_vmstate() operation inside
synchronous blk_save_vmstate() operation. This helper is used from
qemu-io only.
Signed-off-by: Denis V. Lunev <den@openvz.org>
Reviewed-by: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com>
CC: Kevin Wolf <kwolf@redhat.com>
CC: Max Reitz <mreitz@redhat.com>
CC: Stefan Hajnoczi <stefanha@redhat.com>
CC: Fam Zheng <fam@euphon.net>
CC: Juan Quintela <quintela@redhat.com>
CC: "Dr. David Alan Gilbert" <dgilbert@redhat.com>
CC: Denis Plotnikov <dplotnikov@virtuozzo.com>
---
block/block-backend.c | 6 +++++-
block/io.c | 15 +++++++++++++++
include/block/block.h | 5 +++++
migration/savevm.c | 4 ++++
4 files changed, 29 insertions(+), 1 deletion(-)
diff --git a/block/block-backend.c b/block/block-backend.c
index 1c6e53bbde..5bb11c8e01 100644
--- a/block/block-backend.c
+++ b/block/block-backend.c
@@ -2177,16 +2177,20 @@ int blk_truncate(BlockBackend *blk, int64_t offset, bool exact,
int blk_save_vmstate(BlockBackend *blk, const uint8_t *buf,
int64_t pos, int size)
{
- int ret;
+ int ret, ret2;
if (!blk_is_available(blk)) {
return -ENOMEDIUM;
}
ret = bdrv_save_vmstate(blk_bs(blk), buf, pos, size);
+ ret2 = bdrv_finalize_vmstate(blk_bs(blk));
if (ret < 0) {
return ret;
}
+ if (ret2 < 0) {
+ return ret2;
+ }
if (!blk->enable_write_cache) {
ret = bdrv_flush(blk_bs(blk));
diff --git a/block/io.c b/block/io.c
index df8f2a98d4..1f69268361 100644
--- a/block/io.c
+++ b/block/io.c
@@ -2724,6 +2724,21 @@ int bdrv_readv_vmstate(BlockDriverState *bs, QEMUIOVector *qiov, int64_t pos)
return bdrv_rw_vmstate(bs, qiov, pos, true);
}
+static int coroutine_fn bdrv_co_finalize_vmstate(BlockDriverState *bs)
+{
+ return 0;
+}
+
+static int coroutine_fn bdrv_finalize_vmstate_co_entry(void *opaque)
+{
+ return bdrv_co_finalize_vmstate(opaque);
+}
+
+int bdrv_finalize_vmstate(BlockDriverState *bs)
+{
+ return bdrv_run_co(bs, bdrv_finalize_vmstate_co_entry, bs);
+}
+
/**************************************************************/
/* async I/Os */
diff --git a/include/block/block.h b/include/block/block.h
index 25e299605e..ab2c962094 100644
--- a/include/block/block.h
+++ b/include/block/block.h
@@ -572,6 +572,11 @@ int bdrv_save_vmstate(BlockDriverState *bs, const uint8_t *buf,
int bdrv_load_vmstate(BlockDriverState *bs, uint8_t *buf,
int64_t pos, int size);
+/*
+ * bdrv_finalize_vmstate() is mandatory to commit vmstate changes if
+ * bdrv_save_vmstate() was ever called.
+ */
+int bdrv_finalize_vmstate(BlockDriverState *bs);
void bdrv_img_create(const char *filename, const char *fmt,
const char *base_filename, const char *base_fmt,
diff --git a/migration/savevm.c b/migration/savevm.c
index da3dead4e9..798a4cb402 100644
--- a/migration/savevm.c
+++ b/migration/savevm.c
@@ -150,6 +150,10 @@ static ssize_t block_get_buffer(void *opaque, uint8_t *buf, int64_t pos,
static int bdrv_fclose(void *opaque, Error **errp)
{
+ int err = bdrv_finalize_vmstate(opaque);
+ if (err < 0) {
+ return err;
+ }
return bdrv_flush(opaque);
}
--
2.17.1
next prev parent reply other threads:[~2020-06-19 10:08 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-06-19 10:07 [PATCH v5 0/6] block: seriously improve savevm performance Denis V. Lunev
2020-06-19 10:07 ` [PATCH 1/6] migration/savevm: respect qemu_fclose() error code in save_snapshot() Denis V. Lunev
2020-06-19 10:07 ` [PATCH 2/6] block/aio_task: allow start/wait task from any coroutine Denis V. Lunev
2020-06-19 10:07 ` [PATCH 3/6] block/aio_task: drop aio_task_pool_wait_one() helper Denis V. Lunev
2020-06-19 10:07 ` [PATCH 4/6] block/block-backend: remove always true check from blk_save_vmstate Denis V. Lunev
2020-06-20 3:06 ` Vladimir Sementsov-Ogievskiy
2020-06-19 10:07 ` Denis V. Lunev [this message]
2020-06-19 10:07 ` [PATCH 6/6] block/io: improve savevm performance Denis V. Lunev
2020-06-19 11:02 ` [PATCH v5 0/6] block: seriously " no-reply
2020-06-22 8:34 ` Denis V. Lunev
2020-06-22 8:33 ` [PATCH 7/6] block/io: improve loadvm performance Denis V. Lunev
2020-06-22 17:02 ` Vladimir Sementsov-Ogievskiy
2020-06-22 17:17 ` Denis V. Lunev
2020-06-22 18:13 ` Vladimir Sementsov-Ogievskiy
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=20200619100708.30440-6-den@openvz.org \
--to=den@openvz.org \
--cc=dgilbert@redhat.com \
--cc=dplotnikov@virtuozzo.com \
--cc=fam@euphon.net \
--cc=kwolf@redhat.com \
--cc=mreitz@redhat.com \
--cc=qemu-block@nongnu.org \
--cc=qemu-devel@nongnu.org \
--cc=quintela@redhat.com \
--cc=stefanha@redhat.com \
/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).