From: "Denis V. Lunev" <den@openvz.org>
Cc: "Denis V. Lunev" <den@openvz.org>,
qemu-devel@nongnu.org, Paolo Bonzini <pbonzini@redhat.com>
Subject: [Qemu-devel] [PATCH 1/1] nbd: fix block-mirror NBD target
Date: Wed, 17 Feb 2016 18:08:11 +0300 [thread overview]
Message-ID: <1455721691-14802-1-git-send-email-den@openvz.org> (raw)
There is VM with 8 GB QCOW2 storage. Real size of the image file is 2 GB.
'drive-mirror' redirected to NBD target creates 8 GB image at destination.
The situation is even worse as zeroes are sent through the channel.
The patch simply adds .bdrv_co_write_zeroes callback to NBD block driver
which works though NBD_TRIM to avoid transfer of zeroes.
Signed-off-by: Denis V. Lunev <den@openvz.org>
CC: Paolo Bonzini <pbonzini@redhat.com>
---
block/nbd-client.c | 10 ++++++++++
block/nbd-client.h | 2 ++
block/nbd.c | 9 +++++++++
3 files changed, 21 insertions(+)
diff --git a/block/nbd-client.c b/block/nbd-client.c
index 568c56c..ef0c5e8 100644
--- a/block/nbd-client.c
+++ b/block/nbd-client.c
@@ -344,7 +344,17 @@ int nbd_client_co_discard(BlockDriverState *bs, int64_t sector_num,
}
nbd_coroutine_end(client, &request);
return -reply.error;
+}
+
+int nbd_client_co_write_zeroes(BlockDriverState *bs, int64_t sector_num,
+ int nb_sectors, BdrvRequestFlags flags)
+{
+ NbdClientSession *client = nbd_get_client_session(bs);
+ if (!(client->nbdflags & NBD_FLAG_SEND_TRIM)) {
+ return -ENOTSUP;
+ }
+ return nbd_client_co_discard(bs, sector_num, nb_sectors);
}
void nbd_client_detach_aio_context(BlockDriverState *bs)
diff --git a/block/nbd-client.h b/block/nbd-client.h
index e841340..aaef18d 100644
--- a/block/nbd-client.h
+++ b/block/nbd-client.h
@@ -40,6 +40,8 @@ void nbd_client_close(BlockDriverState *bs);
int nbd_client_co_discard(BlockDriverState *bs, int64_t sector_num,
int nb_sectors);
+int nbd_client_co_write_zeroes(BlockDriverState *bs, int64_t sector_num,
+ int nb_sectors, BdrvRequestFlags flags);
int nbd_client_co_flush(BlockDriverState *bs);
int nbd_client_co_writev(BlockDriverState *bs, int64_t sector_num,
int nb_sectors, QEMUIOVector *qiov);
diff --git a/block/nbd.c b/block/nbd.c
index 1a90bc7..8b05480 100644
--- a/block/nbd.c
+++ b/block/nbd.c
@@ -318,6 +318,13 @@ static int nbd_co_discard(BlockDriverState *bs, int64_t sector_num,
return nbd_client_co_discard(bs, sector_num, nb_sectors);
}
+static coroutine_fn int nbd_co_write_zeroes(BlockDriverState *bs,
+ int64_t sector_num, int nb_sectors, BdrvRequestFlags flags)
+{
+ return nbd_client_co_write_zeroes(bs, sector_num, nb_sectors, flags);
+}
+
+
static void nbd_close(BlockDriverState *bs)
{
nbd_client_close(bs);
@@ -415,6 +422,7 @@ static BlockDriver bdrv_nbd_tcp = {
.bdrv_close = nbd_close,
.bdrv_co_flush_to_os = nbd_co_flush,
.bdrv_co_discard = nbd_co_discard,
+ .bdrv_co_write_zeroes = nbd_co_write_zeroes,
.bdrv_refresh_limits = nbd_refresh_limits,
.bdrv_getlength = nbd_getlength,
.bdrv_detach_aio_context = nbd_detach_aio_context,
@@ -433,6 +441,7 @@ static BlockDriver bdrv_nbd_unix = {
.bdrv_close = nbd_close,
.bdrv_co_flush_to_os = nbd_co_flush,
.bdrv_co_discard = nbd_co_discard,
+ .bdrv_co_write_zeroes = nbd_co_write_zeroes,
.bdrv_refresh_limits = nbd_refresh_limits,
.bdrv_getlength = nbd_getlength,
.bdrv_detach_aio_context = nbd_detach_aio_context,
--
2.5.0
next reply other threads:[~2016-02-17 15:08 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-02-17 15:08 Denis V. Lunev [this message]
2016-02-17 15:21 ` [Qemu-devel] [PATCH 1/1] nbd: fix block-mirror NBD target Max Reitz
2016-02-17 16:28 ` Denis V. Lunev
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=1455721691-14802-1-git-send-email-den@openvz.org \
--to=den@openvz.org \
--cc=pbonzini@redhat.com \
--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).