From patchwork Wed Oct 5 10:57:03 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Denis V. Lunev" X-Patchwork-Id: 678385 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [IPv6:2001:4830:134:3::11]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 3spt6z5xjLz9s3s for ; Wed, 5 Oct 2016 21:58:19 +1100 (AEDT) Received: from localhost ([::1]:47939 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1brjtw-0006Wt-PR for incoming@patchwork.ozlabs.org; Wed, 05 Oct 2016 06:58:16 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:34481) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1brjst-0005rJ-6A for qemu-devel@nongnu.org; Wed, 05 Oct 2016 06:57:12 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1brjsp-0001Kj-2C for qemu-devel@nongnu.org; Wed, 05 Oct 2016 06:57:11 -0400 Received: from mailhub.sw.ru ([195.214.232.25]:7424 helo=relay.sw.ru) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1brjso-0001Jd-Lx; Wed, 05 Oct 2016 06:57:06 -0400 Received: from hades.sw.ru ([10.30.8.132]) by relay.sw.ru (8.13.4/8.13.4) with ESMTP id u95Av3st014750; Wed, 5 Oct 2016 13:57:03 +0300 (MSK) From: "Denis V. Lunev" To: qemu-block@nongnu.org, qemu-devel@nongnu.org Date: Wed, 5 Oct 2016 13:57:03 +0300 Message-Id: <1475665023-21620-1-git-send-email-den@openvz.org> X-Mailer: git-send-email 2.5.0 X-detected-operating-system: by eggs.gnu.org: OpenBSD 3.x X-Received-From: 195.214.232.25 Subject: [Qemu-devel] [PATCH v2 1/1] nbd: add zero-init parameter X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Kevin Wolf , den@openvz.org, Max Reitz , Paolo Bonzini Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" When using a nbd block device, the info about necessity of prior disk zeroing could significantly improve the speed of certain operations (e.g. backups). This patch also will allow to preserve QCOW2 images during migration. Management software now may specify zero-init option and thus abscent areas in the original QCOW2 image will not be marked as zeroes in the target image. This is tight distiction but it is here. Signed-off-by: Denis V. Lunev CC: Paolo Bonzini CC: Kevin Wolf CC: Max Reitz --- block/nbd.c | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/block/nbd.c b/block/nbd.c index 6bc06d6..eed06d1 100644 --- a/block/nbd.c +++ b/block/nbd.c @@ -45,6 +45,7 @@ typedef struct BDRVNBDState { /* For nbd_refresh_filename() */ char *path, *host, *port, *export, *tlscredsid; + bool zero_init; } BDRVNBDState; static int nbd_parse_uri(const char *filename, QDict *options) @@ -194,6 +195,7 @@ out: static SocketAddress *nbd_config(BDRVNBDState *s, QemuOpts *opts, Error **errp) { SocketAddress *saddr; + const char *zero_init; s->path = g_strdup(qemu_opt_get(opts, "path")); s->host = g_strdup(qemu_opt_get(opts, "host")); @@ -232,6 +234,11 @@ static SocketAddress *nbd_config(BDRVNBDState *s, QemuOpts *opts, Error **errp) s->export = g_strdup(qemu_opt_get(opts, "export")); + zero_init = qemu_opt_get(opts, "zero-init"); + if (zero_init != NULL) { + s->zero_init = strcmp(zero_init, "on") == 0; + } + return saddr; } @@ -322,6 +329,11 @@ static QemuOptsList nbd_runtime_opts = { .type = QEMU_OPT_STRING, .help = "ID of the TLS credentials to use", }, + { + .name = "zero-init", + .type = QEMU_OPT_BOOL, + .help = "Zero-initialized image flag", + }, }, }; @@ -483,6 +495,12 @@ static void nbd_refresh_filename(BlockDriverState *bs, QDict *options) bs->full_open_options = opts; } +static int nbd_has_zero_init(BlockDriverState *bs) +{ + BDRVNBDState *s = bs->opaque; + return s->zero_init; +} + static BlockDriver bdrv_nbd = { .format_name = "nbd", .protocol_name = "nbd", @@ -499,6 +517,7 @@ static BlockDriver bdrv_nbd = { .bdrv_detach_aio_context = nbd_detach_aio_context, .bdrv_attach_aio_context = nbd_attach_aio_context, .bdrv_refresh_filename = nbd_refresh_filename, + .bdrv_has_zero_init = nbd_has_zero_init, }; static BlockDriver bdrv_nbd_tcp = { @@ -517,6 +536,7 @@ static BlockDriver bdrv_nbd_tcp = { .bdrv_detach_aio_context = nbd_detach_aio_context, .bdrv_attach_aio_context = nbd_attach_aio_context, .bdrv_refresh_filename = nbd_refresh_filename, + .bdrv_has_zero_init = nbd_has_zero_init, }; static BlockDriver bdrv_nbd_unix = { @@ -535,6 +555,7 @@ static BlockDriver bdrv_nbd_unix = { .bdrv_detach_aio_context = nbd_detach_aio_context, .bdrv_attach_aio_context = nbd_attach_aio_context, .bdrv_refresh_filename = nbd_refresh_filename, + .bdrv_has_zero_init = nbd_has_zero_init, }; static void bdrv_nbd_init(void)