From patchwork Thu Mar 19 19:03:20 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Max Reitz X-Patchwork-Id: 452170 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 382BC140079 for ; Fri, 20 Mar 2015 06:04:57 +1100 (AEDT) Received: from localhost ([::1]:40713 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YYfkV-0004r3-8L for incoming@patchwork.ozlabs.org; Thu, 19 Mar 2015 15:04:55 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:47244) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YYfjL-0002lv-Js for qemu-devel@nongnu.org; Thu, 19 Mar 2015 15:03:51 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1YYfjE-0005zw-5z for qemu-devel@nongnu.org; Thu, 19 Mar 2015 15:03:43 -0400 Received: from mx1.redhat.com ([209.132.183.28]:45291) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YYfj3-0005wM-93; Thu, 19 Mar 2015 15:03:25 -0400 Received: from int-mx10.intmail.prod.int.phx2.redhat.com (int-mx10.intmail.prod.int.phx2.redhat.com [10.5.11.23]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id t2JJ3Oqe006864 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=FAIL); Thu, 19 Mar 2015 15:03:24 -0400 Received: from localhost (dhcp-17-47.bos.redhat.com [10.18.17.47]) by int-mx10.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id t2JJ3NxT028651 (version=TLSv1/SSLv3 cipher=AES128-GCM-SHA256 bits=128 verify=NO); Thu, 19 Mar 2015 15:03:24 -0400 From: Max Reitz To: qemu-block@nongnu.org Date: Thu, 19 Mar 2015 15:03:20 -0400 Message-Id: <1426791801-9042-3-git-send-email-mreitz@redhat.com> In-Reply-To: <1426791801-9042-1-git-send-email-mreitz@redhat.com> References: <1426791801-9042-1-git-send-email-mreitz@redhat.com> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.23 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x X-Received-From: 209.132.183.28 Cc: Kevin Wolf , qemu-devel@nongnu.org, Stefan Hajnoczi , Max Reitz Subject: [Qemu-devel] [PATCH v2 2/3] block: Introduce BDS.growing X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org This flag is set if the BDS's size can be increased by writing beyond its end. Signed-off-by: Max Reitz Reviewed-by: Eric Blake --- block.c | 4 ++++ block/blkdebug.c | 2 ++ block/blkverify.c | 2 ++ block/iscsi.c | 2 ++ block/nbd.c | 2 ++ block/qcow2.c | 5 +++++ block/quorum.c | 5 +++++ block/raw_bsd.c | 1 + include/block/block_int.h | 3 +++ 9 files changed, 26 insertions(+) diff --git a/block.c b/block.c index 4c620b1..6da30f8 100644 --- a/block.c +++ b/block.c @@ -1575,6 +1575,10 @@ int bdrv_open(BlockDriverState **pbs, const char *filename, * (the inverse results in an error message from bdrv_open_common()) */ assert(!(flags & BDRV_O_PROTOCOL) || !file); + /* Default, can be overridden by drv->bdrv_file_open() (conversely, + * drv->bdrv_open() can override bs->growing being false by default) */ + bs->growing = flags & BDRV_O_PROTOCOL; + /* Open the image */ ret = bdrv_open_common(bs, file, options, flags, drv, &local_err); if (ret < 0) { diff --git a/block/blkdebug.c b/block/blkdebug.c index 63611e0..83807f7 100644 --- a/block/blkdebug.c +++ b/block/blkdebug.c @@ -437,6 +437,8 @@ static int blkdebug_open(BlockDriverState *bs, QDict *options, int flags, goto out; } + bs->growing = bs->file->growing; + /* Set request alignment */ align = qemu_opt_get_size(opts, "align", bs->request_alignment); if (align > 0 && align < INT_MAX && !(align & (align - 1))) { diff --git a/block/blkverify.c b/block/blkverify.c index 438dff8..6add81c 100644 --- a/block/blkverify.c +++ b/block/blkverify.c @@ -141,6 +141,8 @@ static int blkverify_open(BlockDriverState *bs, QDict *options, int flags, goto fail; } + bs->growing = bs->file->growing && s->test_file->growing; + ret = 0; fail: qemu_opts_del(opts); diff --git a/block/iscsi.c b/block/iscsi.c index 3e34b1f..dd94cda 100644 --- a/block/iscsi.c +++ b/block/iscsi.c @@ -1285,6 +1285,8 @@ static int iscsi_open(BlockDriverState *bs, QDict *options, int flags, const char *filename; int i, ret = 0; + bs->growing = false; + if ((BDRV_SECTOR_SIZE % 512) != 0) { error_setg(errp, "iSCSI: Invalid BDRV_SECTOR_SIZE. " "BDRV_SECTOR_SIZE(%lld) is not a multiple " diff --git a/block/nbd.c b/block/nbd.c index 2176186..c433555 100644 --- a/block/nbd.c +++ b/block/nbd.c @@ -262,6 +262,8 @@ static int nbd_open(BlockDriverState *bs, QDict *options, int flags, int result, sock; Error *local_err = NULL; + bs->growing = false; + /* Pop the config into our state object. Exit if invalid. */ nbd_config(s, options, &export, &local_err); if (local_err) { diff --git a/block/qcow2.c b/block/qcow2.c index 32bdf75..b4e2aa3 100644 --- a/block/qcow2.c +++ b/block/qcow2.c @@ -552,6 +552,11 @@ static int qcow2_open(BlockDriverState *bs, QDict *options, int flags, int overlap_check_template = 0; uint64_t l2_cache_size, refcount_cache_size; + /* Note: bs->growing is not set, even though qcow2 supports writes beyond + * the virtual disk size; these writes do not increase the disk size, + * however, which would be necessary for that flag to be set (also, that + * behavior is used internally by qcow2 only anyway). */ + ret = bdrv_pread(bs->file, 0, &header, sizeof(header)); if (ret < 0) { error_setg_errno(errp, -ret, "Could not read qcow2 header"); diff --git a/block/quorum.c b/block/quorum.c index 437b122..7a6bcb7 100644 --- a/block/quorum.c +++ b/block/quorum.c @@ -974,6 +974,11 @@ static int quorum_open(BlockDriverState *bs, QDict *options, int flags, opened[i] = true; } + bs->growing = true; + for (i = 0; i < s->num_children; i++) { + bs->growing &= s->bs[i]->growing; + } + g_free(opened); goto exit; diff --git a/block/raw_bsd.c b/block/raw_bsd.c index e3d2d04..72fd951 100644 --- a/block/raw_bsd.c +++ b/block/raw_bsd.c @@ -208,6 +208,7 @@ static int raw_open(BlockDriverState *bs, QDict *options, int flags, Error **errp) { bs->sg = bs->file->sg; + bs->growing = bs->file->growing; if (bs->probed && !bdrv_is_read_only(bs)) { fprintf(stderr, diff --git a/include/block/block_int.h b/include/block/block_int.h index dccb092..01dee2a 100644 --- a/include/block/block_int.h +++ b/include/block/block_int.h @@ -345,6 +345,9 @@ struct BlockDriverState { note this is a reference count */ bool probed; + /* Set if writes beyond the BDS's size make it grow */ + bool growing; + BlockDriver *drv; /* NULL means no media */ void *opaque;