From: "Denis V. Lunev" <den@openvz.org>
To: qemu-devel@nongnu.org
Cc: den@openvz.org, Pavel Butsykin <pbutsykin@virtuozzo.com>,
Jeff Cody <jcody@redhat.com>,
Markus Armbruster <armbru@redhat.com>,
Eric Blake <eblake@redhat.com>, John Snow <jsnow@redhat.com>,
Stefan Hajnoczi <stefanha@redhat.com>,
Kevin Wolf <kwolf@redhat.com>
Subject: [Qemu-devel] [PATCH 01/10] block/io: add bdrv_co_write_compressed
Date: Sat, 14 May 2016 15:45:49 +0300 [thread overview]
Message-ID: <1463229957-14253-2-git-send-email-den@openvz.org> (raw)
In-Reply-To: <1463229957-14253-1-git-send-email-den@openvz.org>
From: Pavel Butsykin <pbutsykin@virtuozzo.com>
This patch just adds the interface to the bdrv_co_write_compressed, which
is currently not used but will be useful for safe implementation of the
bdrv_co_write_compressed callback in format drivers.
Signed-off-by: Pavel Butsykin <pbutsykin@virtuozzo.com>
Signed-off-by: Denis V. Lunev <den@openvz.org>
CC: Jeff Cody <jcody@redhat.com>
CC: Markus Armbruster <armbru@redhat.com>
CC: Eric Blake <eblake@redhat.com>
CC: John Snow <jsnow@redhat.com>
CC: Stefan Hajnoczi <stefanha@redhat.com>
CC: Kevin Wolf <kwolf@redhat.com>
---
block/io.c | 71 ++++++++++++++++++++++++++++++++++++++++++++---
include/block/block.h | 2 ++
include/block/block_int.h | 3 ++
qemu-img.c | 2 +-
4 files changed, 73 insertions(+), 5 deletions(-)
diff --git a/block/io.c b/block/io.c
index cd6d71a..88af10c 100644
--- a/block/io.c
+++ b/block/io.c
@@ -1828,8 +1828,8 @@ int bdrv_is_allocated_above(BlockDriverState *top,
return 0;
}
-int bdrv_write_compressed(BlockDriverState *bs, int64_t sector_num,
- const uint8_t *buf, int nb_sectors)
+int bdrv_co_write_compressed(BlockDriverState *bs, int64_t sector_num,
+ int nb_sectors, QEMUIOVector *qiov)
{
BlockDriver *drv = bs->drv;
int ret;
@@ -1837,7 +1837,7 @@ int bdrv_write_compressed(BlockDriverState *bs, int64_t sector_num,
if (!drv) {
return -ENOMEDIUM;
}
- if (!drv->bdrv_write_compressed) {
+ if (!drv->bdrv_co_write_compressed) {
return -ENOTSUP;
}
ret = bdrv_check_request(bs, sector_num, nb_sectors);
@@ -1846,8 +1846,71 @@ int bdrv_write_compressed(BlockDriverState *bs, int64_t sector_num,
}
assert(QLIST_EMPTY(&bs->dirty_bitmaps));
+ assert(qemu_in_coroutine());
+
+ return drv->bdrv_co_write_compressed(bs, sector_num, nb_sectors, qiov);
+}
+
+typedef struct BdrvWriteCompressedCo {
+ BlockDriverState *bs;
+ int64_t sector_num;
+ const uint8_t *buf;
+ int nb_sectors;
+ int ret;
+} BdrvWriteCompressedCo;
+
+static void bdrv_write_compressed_co_entry(void *opaque)
+{
+ BdrvWriteCompressedCo *co = opaque;
+ QEMUIOVector qiov;
+ struct iovec iov = {
+ .iov_base = (uint8_t *)co->buf,
+ .iov_len = co->nb_sectors << BDRV_SECTOR_BITS,
+ };
+ qemu_iovec_init_external(&qiov, &iov, 1);
+
+ co->ret = bdrv_co_write_compressed(co->bs, co->sector_num,
+ co->nb_sectors, &qiov);
+}
+
+int bdrv_write_compressed(BlockDriverState *bs, int64_t sector_num,
+ const uint8_t *buf, int nb_sectors)
+{
+ BlockDriver *drv = bs->drv;
+ BdrvWriteCompressedCo data = {
+ .bs = bs,
+ .sector_num = sector_num,
+ .buf = buf,
+ .nb_sectors = nb_sectors,
+ .ret = -EINPROGRESS,
+ };
+
+ if (!drv) {
+ return -ENOMEDIUM;
+ }
+
+ if (drv->bdrv_write_compressed) {
+ int ret = bdrv_check_request(bs, sector_num, nb_sectors);
+ if (ret < 0) {
+ return ret;
+ }
+ assert(QLIST_EMPTY(&bs->dirty_bitmaps));
+ return drv->bdrv_write_compressed(bs, sector_num, buf, nb_sectors);
+ }
- return drv->bdrv_write_compressed(bs, sector_num, buf, nb_sectors);
+ if (qemu_in_coroutine()) {
+ /* Fast-path if already in coroutine context */
+ bdrv_write_compressed_co_entry(&data);
+ } else {
+ AioContext *aio_context = bdrv_get_aio_context(bs);
+
+ Coroutine *co = qemu_coroutine_create(bdrv_write_compressed_co_entry);
+ qemu_coroutine_enter(co, &data);
+ while (data.ret == -EINPROGRESS) {
+ aio_poll(aio_context, true);
+ }
+ }
+ return data.ret;
}
int bdrv_save_vmstate(BlockDriverState *bs, const uint8_t *buf,
diff --git a/include/block/block.h b/include/block/block.h
index b210832..ae67fd8 100644
--- a/include/block/block.h
+++ b/include/block/block.h
@@ -423,6 +423,8 @@ const char *bdrv_get_device_or_node_name(const BlockDriverState *bs);
int bdrv_get_flags(BlockDriverState *bs);
int bdrv_write_compressed(BlockDriverState *bs, int64_t sector_num,
const uint8_t *buf, int nb_sectors);
+int bdrv_co_write_compressed(BlockDriverState *bs, int64_t sector_num,
+ int nb_sectors, QEMUIOVector *qiov);
int bdrv_get_info(BlockDriverState *bs, BlockDriverInfo *bdi);
ImageInfoSpecific *bdrv_get_specific_info(BlockDriverState *bs);
void bdrv_round_to_clusters(BlockDriverState *bs,
diff --git a/include/block/block_int.h b/include/block/block_int.h
index a029c20..3c93ddb 100644
--- a/include/block/block_int.h
+++ b/include/block/block_int.h
@@ -208,6 +208,9 @@ struct BlockDriver {
int (*bdrv_write_compressed)(BlockDriverState *bs, int64_t sector_num,
const uint8_t *buf, int nb_sectors);
+ int (*bdrv_co_write_compressed)(BlockDriverState *bs, int64_t sector_num,
+ int nb_sectors, QEMUIOVector *qiov);
+
int (*bdrv_snapshot_create)(BlockDriverState *bs,
QEMUSnapshotInfo *sn_info);
int (*bdrv_snapshot_goto)(BlockDriverState *bs,
diff --git a/qemu-img.c b/qemu-img.c
index 4792366..0d38eac 100644
--- a/qemu-img.c
+++ b/qemu-img.c
@@ -2022,7 +2022,7 @@ static int img_convert(int argc, char **argv)
const char *preallocation =
qemu_opt_get(opts, BLOCK_OPT_PREALLOC);
- if (!drv->bdrv_write_compressed) {
+ if (!drv->bdrv_write_compressed && !drv->bdrv_co_write_compressed) {
error_report("Compression not supported for this file format");
ret = -1;
goto out;
--
2.1.4
next prev parent reply other threads:[~2016-05-14 12:46 UTC|newest]
Thread overview: 34+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-05-14 12:45 [Qemu-devel] [PATCH v3 00/10] backup compression Denis V. Lunev
2016-05-14 12:45 ` Denis V. Lunev [this message]
2016-05-16 16:52 ` [Qemu-devel] [PATCH 01/10] block/io: add bdrv_co_write_compressed Eric Blake
2016-05-17 15:01 ` Pavel Butsykin
2016-05-19 21:25 ` Stefan Hajnoczi
2016-05-19 21:39 ` Denis V. Lunev
2016-05-14 12:45 ` [Qemu-devel] [PATCH 02/10] qcow2: add qcow2_co_write_compressed Denis V. Lunev
2016-05-27 17:33 ` Stefan Hajnoczi
2016-05-30 9:12 ` Pavel Butsykin
2016-05-30 12:58 ` Pavel Butsykin
2016-05-31 18:42 ` Eric Blake
2016-05-31 21:00 ` Denis V. Lunev
2016-05-31 21:13 ` Eric Blake
2016-06-01 9:53 ` Pavel Butsykin
2016-06-01 9:31 ` Kevin Wolf
2016-06-01 9:25 ` Kevin Wolf
2016-06-01 20:06 ` Stefan Hajnoczi
2016-05-14 12:45 ` [Qemu-devel] [PATCH 03/10] vmdk: add vmdk_co_write_compressed Denis V. Lunev
2016-05-27 17:38 ` Stefan Hajnoczi
2016-05-14 12:45 ` [Qemu-devel] [PATCH 04/10] qcow: add qcow_co_write_compressed Denis V. Lunev
2016-05-27 17:45 ` Stefan Hajnoczi
2016-05-30 14:27 ` Pavel Butsykin
2016-05-14 12:45 ` [Qemu-devel] [PATCH 05/10] block: remove BlockDriver.bdrv_write_compressed Denis V. Lunev
2016-05-16 16:57 ` Eric Blake
2016-05-17 12:22 ` Pavel Butsykin
2016-05-14 12:45 ` [Qemu-devel] [PATCH 06/10] drive-backup: added support for data compression Denis V. Lunev
2016-05-16 16:59 ` Eric Blake
2016-05-27 17:56 ` Stefan Hajnoczi
2016-05-14 12:45 ` [Qemu-devel] [PATCH 07/10] blockdev-backup: " Denis V. Lunev
2016-05-16 17:00 ` Eric Blake
2016-05-27 17:57 ` Stefan Hajnoczi
2016-05-14 12:45 ` [Qemu-devel] [PATCH 08/10] qemu-iotests: test backup compression in 055 Denis V. Lunev
2016-05-14 12:45 ` [Qemu-devel] [PATCH 09/10] block: fix backup in vmdk format image Denis V. Lunev
2016-05-27 18:01 ` Stefan Hajnoczi
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=1463229957-14253-2-git-send-email-den@openvz.org \
--to=den@openvz.org \
--cc=armbru@redhat.com \
--cc=eblake@redhat.com \
--cc=jcody@redhat.com \
--cc=jsnow@redhat.com \
--cc=kwolf@redhat.com \
--cc=pbutsykin@virtuozzo.com \
--cc=qemu-devel@nongnu.org \
--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).