From nobody Thu Nov 6 14:07:01 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zoho.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1489441265421804.1400904530944; Mon, 13 Mar 2017 14:41:05 -0700 (PDT) Received: from localhost ([::1]:54530 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cnXiB-0006tD-3k for importer@patchew.org; Mon, 13 Mar 2017 17:41:03 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:43471) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cnXhO-0006r4-75 for qemu-devel@nongnu.org; Mon, 13 Mar 2017 17:40:16 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1cnXhM-0001bL-J9 for qemu-devel@nongnu.org; Mon, 13 Mar 2017 17:40:14 -0400 Received: from mx1.redhat.com ([209.132.183.28]:50202) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1cnXhI-0001XS-MQ; Mon, 13 Mar 2017 17:40:08 -0400 Received: from int-mx10.intmail.prod.int.phx2.redhat.com (int-mx10.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id C231CC04B332; Mon, 13 Mar 2017 21:40:08 +0000 (UTC) Received: from localhost (ovpn-204-63.brq.redhat.com [10.40.204.63]) by int-mx10.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id v2DLe6X7032087 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=NO); Mon, 13 Mar 2017 17:40:08 -0400 From: Max Reitz To: qemu-block@nongnu.org Date: Mon, 13 Mar 2017 22:39:46 +0100 Message-Id: <20170313214001.26339-2-mreitz@redhat.com> In-Reply-To: <20170313214001.26339-1-mreitz@redhat.com> References: <20170313214001.26339-1-mreitz@redhat.com> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.23 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.31]); Mon, 13 Mar 2017 21:40:08 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH for-2.10 01/16] block: Add PreallocMode to BD.bdrv_truncate() 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 , qemu-devel@nongnu.org, Max Reitz Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Add a PreallocMode parameter to the bdrv_truncate() function implemented by each block driver. Currently, we always pass PREALLOC_MODE_OFF and no driver accepts anything else. Signed-off-by: Max Reitz Reviewed-by: Stefan Hajnoczi --- include/block/block_int.h | 3 ++- block.c | 2 +- block/blkdebug.c | 9 ++++++++- block/crypto.c | 8 +++++++- block/file-posix.c | 9 ++++++++- block/file-win32.c | 9 ++++++++- block/gluster.c | 6 +++++- block/iscsi.c | 7 ++++++- block/nfs.c | 8 +++++++- block/qcow2.c | 9 ++++++++- block/qed.c | 9 ++++++++- block/raw-format.c | 9 ++++++++- block/rbd.c | 7 ++++++- block/sheepdog.c | 11 +++++++++-- 14 files changed, 91 insertions(+), 15 deletions(-) diff --git a/include/block/block_int.h b/include/block/block_int.h index ee55d5e9cd..2615356581 100644 --- a/include/block/block_int.h +++ b/include/block/block_int.h @@ -196,7 +196,8 @@ struct BlockDriver { int coroutine_fn (*bdrv_co_flush_to_os)(BlockDriverState *bs); =20 const char *protocol_name; - int (*bdrv_truncate)(BlockDriverState *bs, int64_t offset, Error **err= p); + int (*bdrv_truncate)(BlockDriverState *bs, int64_t offset, + PreallocMode prealloc, Error **errp); =20 int64_t (*bdrv_getlength)(BlockDriverState *bs); bool has_variable_length; diff --git a/block.c b/block.c index 267c761ff7..57ae40a84e 100644 --- a/block.c +++ b/block.c @@ -3237,7 +3237,7 @@ int bdrv_truncate(BdrvChild *child, int64_t offset, E= rror **errp) return -EACCES; } =20 - ret =3D drv->bdrv_truncate(bs, offset, errp); + ret =3D drv->bdrv_truncate(bs, offset, PREALLOC_MODE_OFF, errp); if (ret =3D=3D 0) { ret =3D refresh_total_sectors(bs, offset >> BDRV_SECTOR_BITS); bdrv_dirty_bitmap_truncate(bs); diff --git a/block/blkdebug.c b/block/blkdebug.c index c795ae9e72..31a71a34d3 100644 --- a/block/blkdebug.c +++ b/block/blkdebug.c @@ -661,8 +661,15 @@ static int64_t blkdebug_getlength(BlockDriverState *bs) return bdrv_getlength(bs->file->bs); } =20 -static int blkdebug_truncate(BlockDriverState *bs, int64_t offset, Error *= *errp) +static int blkdebug_truncate(BlockDriverState *bs, int64_t offset, + PreallocMode prealloc, Error **errp) { + if (prealloc !=3D PREALLOC_MODE_OFF) { + error_setg(errp, "Unsupported preallocation mode '%s'", + PreallocMode_lookup[prealloc]); + return -ENOTSUP; + } + return bdrv_truncate(bs->file, offset, errp); } =20 diff --git a/block/crypto.c b/block/crypto.c index 17b3140998..fa61aef380 100644 --- a/block/crypto.c +++ b/block/crypto.c @@ -382,12 +382,18 @@ static int block_crypto_create_generic(QCryptoBlockFo= rmat format, } =20 static int block_crypto_truncate(BlockDriverState *bs, int64_t offset, - Error **errp) + PreallocMode prealloc, Error **errp) { BlockCrypto *crypto =3D bs->opaque; size_t payload_offset =3D qcrypto_block_get_payload_offset(crypto->block); =20 + if (prealloc !=3D PREALLOC_MODE_OFF) { + error_setg(errp, "Unsupported preallocation mode '%s'", + PreallocMode_lookup[prealloc]); + return -ENOTSUP; + } + offset +=3D payload_offset; =20 return bdrv_truncate(bs->file, offset, errp); diff --git a/block/file-posix.c b/block/file-posix.c index 3a402151f1..dde8c101c8 100644 --- a/block/file-posix.c +++ b/block/file-posix.c @@ -1384,12 +1384,19 @@ static void raw_close(BlockDriverState *bs) } } =20 -static int raw_truncate(BlockDriverState *bs, int64_t offset, Error **errp) +static int raw_truncate(BlockDriverState *bs, int64_t offset, + PreallocMode prealloc, Error **errp) { BDRVRawState *s =3D bs->opaque; struct stat st; int ret; =20 + if (prealloc !=3D PREALLOC_MODE_OFF) { + error_setg(errp, "Unsupported preallocation mode '%s'", + PreallocMode_lookup[prealloc]); + return -ENOTSUP; + } + if (fstat(s->fd, &st)) { ret =3D -errno; error_setg_errno(errp, -ret, "Failed to fstat() the file"); diff --git a/block/file-win32.c b/block/file-win32.c index 3f3925623f..bf6f20d3b0 100644 --- a/block/file-win32.c +++ b/block/file-win32.c @@ -461,12 +461,19 @@ static void raw_close(BlockDriverState *bs) } } =20 -static int raw_truncate(BlockDriverState *bs, int64_t offset, Error **errp) +static int raw_truncate(BlockDriverState *bs, int64_t offset, + PreallocMode prealloc, Error **errp) { BDRVRawState *s =3D bs->opaque; LONG low, high; DWORD dwPtrLow; =20 + if (prealloc !=3D PREALLOC_MODE_OFF) { + error_setg(errp, "Unsupported preallocation mode '%s'", + PreallocMode_lookup[prealloc]); + return -ENOTSUP; + } + low =3D offset; high =3D offset >> 32; =20 diff --git a/block/gluster.c b/block/gluster.c index 00b8240562..2d4c278500 100644 --- a/block/gluster.c +++ b/block/gluster.c @@ -1085,11 +1085,15 @@ static coroutine_fn int qemu_gluster_co_rw(BlockDri= verState *bs, } =20 static int qemu_gluster_truncate(BlockDriverState *bs, int64_t offset, - Error **errp) + PreallocMode prealloc, Error **errp) { int ret; BDRVGlusterState *s =3D bs->opaque; =20 + if (prealloc !=3D PREALLOC_MODE_OFF) { + return -ENOTSUP; + } + ret =3D glfs_ftruncate(s->fd, offset); if (ret < 0) { return -errno; diff --git a/block/iscsi.c b/block/iscsi.c index ab559a6f71..5d6265c4a6 100644 --- a/block/iscsi.c +++ b/block/iscsi.c @@ -2060,11 +2060,16 @@ static void iscsi_reopen_commit(BDRVReopenState *re= open_state) } } =20 -static int iscsi_truncate(BlockDriverState *bs, int64_t offset, Error **er= rp) +static int iscsi_truncate(BlockDriverState *bs, int64_t offset, + PreallocMode prealloc, Error **errp) { IscsiLun *iscsilun =3D bs->opaque; Error *local_err =3D NULL; =20 + if (prealloc !=3D PREALLOC_MODE_OFF) { + return -ENOTSUP; + } + if (iscsilun->type !=3D TYPE_DISK) { return -ENOTSUP; } diff --git a/block/nfs.c b/block/nfs.c index 57d12efc51..a44c526b80 100644 --- a/block/nfs.c +++ b/block/nfs.c @@ -757,9 +757,15 @@ static int64_t nfs_get_allocated_file_size(BlockDriver= State *bs) return (task.ret < 0 ? task.ret : st.st_blocks * 512); } =20 -static int nfs_file_truncate(BlockDriverState *bs, int64_t offset, Error *= *errp) +static int nfs_file_truncate(BlockDriverState *bs, int64_t offset, + PreallocMode prealloc, Error **errp) { NFSClient *client =3D bs->opaque; + + if (prealloc !=3D PREALLOC_MODE_OFF) { + return -ENOTSUP; + } + return nfs_ftruncate(client->context, client->fh, offset); } =20 diff --git a/block/qcow2.c b/block/qcow2.c index 53b0bd61a7..8d180bbf9d 100644 --- a/block/qcow2.c +++ b/block/qcow2.c @@ -2524,12 +2524,19 @@ static coroutine_fn int qcow2_co_pdiscard(BlockDriv= erState *bs, return ret; } =20 -static int qcow2_truncate(BlockDriverState *bs, int64_t offset, Error **er= rp) +static int qcow2_truncate(BlockDriverState *bs, int64_t offset, + PreallocMode prealloc, Error **errp) { BDRVQcow2State *s =3D bs->opaque; int64_t new_l1_size; int ret; =20 + if (prealloc !=3D PREALLOC_MODE_OFF) { + error_setg(errp, "Unsupported preallocation mode '%s'", + PreallocMode_lookup[prealloc]); + return -ENOTSUP; + } + if (offset & 511) { error_setg(errp, "The new size must be a multiple of 512"); return -EINVAL; diff --git a/block/qed.c b/block/qed.c index eb346d645b..b5102f5d7f 100644 --- a/block/qed.c +++ b/block/qed.c @@ -1518,12 +1518,19 @@ static int coroutine_fn bdrv_qed_co_pwrite_zeroes(B= lockDriverState *bs, return cb.ret; } =20 -static int bdrv_qed_truncate(BlockDriverState *bs, int64_t offset, Error *= *errp) +static int bdrv_qed_truncate(BlockDriverState *bs, int64_t offset, + PreallocMode prealloc, Error **errp) { BDRVQEDState *s =3D bs->opaque; uint64_t old_image_size; int ret; =20 + if (prealloc !=3D PREALLOC_MODE_OFF) { + error_setg(errp, "Unsupported preallocation mode '%s'", + PreallocMode_lookup[prealloc]); + return -ENOTSUP; + } + if (!qed_is_image_size_valid(offset, s->header.cluster_size, s->header.table_size)) { error_setg(errp, "Invalid image size specified"); diff --git a/block/raw-format.c b/block/raw-format.c index 36e65036f0..aeaa13e3f5 100644 --- a/block/raw-format.c +++ b/block/raw-format.c @@ -327,10 +327,17 @@ static void raw_refresh_limits(BlockDriverState *bs, = Error **errp) } } =20 -static int raw_truncate(BlockDriverState *bs, int64_t offset, Error **errp) +static int raw_truncate(BlockDriverState *bs, int64_t offset, + PreallocMode prealloc, Error **errp) { BDRVRawState *s =3D bs->opaque; =20 + if (prealloc !=3D PREALLOC_MODE_OFF) { + error_setg(errp, "Unsupported preallocation mode '%s'", + PreallocMode_lookup[prealloc]); + return -ENOTSUP; + } + if (s->has_size) { error_setg(errp, "Cannot resize fixed-size raw disks"); return -ENOTSUP; diff --git a/block/rbd.c b/block/rbd.c index f7d4dd93fe..fd31f8626e 100644 --- a/block/rbd.c +++ b/block/rbd.c @@ -1028,11 +1028,16 @@ static int64_t qemu_rbd_getlength(BlockDriverState = *bs) return info.size; } =20 -static int qemu_rbd_truncate(BlockDriverState *bs, int64_t offset, Error *= *errp) +static int qemu_rbd_truncate(BlockDriverState *bs, int64_t offset, + PreallocMode prealloc, Error **errp) { BDRVRBDState *s =3D bs->opaque; int r; =20 + if (prealloc !=3D PREALLOC_MODE_OFF) { + return -ENOTSUP; + } + r =3D rbd_resize(s->image, offset); if (r < 0) { return r; diff --git a/block/sheepdog.c b/block/sheepdog.c index 27126ea474..546708adaf 100644 --- a/block/sheepdog.c +++ b/block/sheepdog.c @@ -2133,13 +2133,20 @@ static int64_t sd_getlength(BlockDriverState *bs) return s->inode.vdi_size; } =20 -static int sd_truncate(BlockDriverState *bs, int64_t offset, Error **errp) +static int sd_truncate(BlockDriverState *bs, int64_t offset, + PreallocMode prealloc, Error **errp) { BDRVSheepdogState *s =3D bs->opaque; int ret, fd; unsigned int datalen; uint64_t max_vdi_size; =20 + if (prealloc !=3D PREALLOC_MODE_OFF) { + error_setg(errp, "Unsupported preallocation mode '%s'", + PreallocMode_lookup[prealloc]); + return -ENOTSUP; + } + max_vdi_size =3D (UINT64_C(1) << s->inode.block_size_shift) * MAX_DATA= _OBJS; if (offset < s->inode.vdi_size) { error_setg(errp, "shrinking is not supported"); @@ -2428,7 +2435,7 @@ static coroutine_fn int sd_co_writev(BlockDriverState= *bs, int64_t sector_num, BDRVSheepdogState *s =3D bs->opaque; =20 if (offset > s->inode.vdi_size) { - ret =3D sd_truncate(bs, offset, NULL); + ret =3D sd_truncate(bs, offset, PREALLOC_MODE_OFF, NULL); if (ret < 0) { return ret; } --=20 2.12.0 From nobody Thu Nov 6 14:07:01 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zoho.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1489441409696928.3969116218401; Mon, 13 Mar 2017 14:43:29 -0700 (PDT) Received: from localhost ([::1]:54540 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cnXkW-0000Tv-6C for importer@patchew.org; Mon, 13 Mar 2017 17:43:28 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:43598) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cnXhs-0007Ch-5E for qemu-devel@nongnu.org; Mon, 13 Mar 2017 17:40:45 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1cnXhq-0001lD-Nl for qemu-devel@nongnu.org; Mon, 13 Mar 2017 17:40:44 -0400 Received: from mx1.redhat.com ([209.132.183.28]:44274) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1cnXhl-0001kH-Co; Mon, 13 Mar 2017 17:40:37 -0400 Received: from int-mx09.intmail.prod.int.phx2.redhat.com (int-mx09.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 76CC5104CE; Mon, 13 Mar 2017 21:40:37 +0000 (UTC) Received: from localhost (ovpn-204-63.brq.redhat.com [10.40.204.63]) by int-mx09.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id v2DLeZaT018446 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=NO); Mon, 13 Mar 2017 17:40:36 -0400 From: Max Reitz To: qemu-block@nongnu.org Date: Mon, 13 Mar 2017 22:40:18 +0100 Message-Id: <20170313214032.26672-1-mreitz@redhat.com> In-Reply-To: <20170313214001.26339-1-mreitz@redhat.com> References: <20170313214001.26339-1-mreitz@redhat.com> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.22 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.38]); Mon, 13 Mar 2017 21:40:37 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH for-2.10 02/16] block: Add PreallocMode to bdrv_truncate() 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 , qemu-devel@nongnu.org, Max Reitz Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" For block drivers that just pass a truncate request to the underlying protocol, we can now pass the preallocation mode instead of aborting if it is not PREALLOC_MODE_OFF. Signed-off-by: Max Reitz Reviewed-by: Stefan Hajnoczi --- include/block/block.h | 3 ++- block.c | 12 +++++++++--- block/blkdebug.c | 8 +------- block/block-backend.c | 2 +- block/crypto.c | 8 +------- block/parallels.c | 11 +++++++---- block/qcow.c | 6 ++++-- block/qcow2-refcount.c | 2 +- block/qcow2.c | 4 ++-- block/raw-format.c | 8 +------- block/vhdx-log.c | 2 +- block/vhdx.c | 3 ++- 12 files changed, 32 insertions(+), 37 deletions(-) diff --git a/include/block/block.h b/include/block/block.h index 4c9ed0e43c..5042b79dc9 100644 --- a/include/block/block.h +++ b/include/block/block.h @@ -294,7 +294,8 @@ BlockDriverState *bdrv_find_backing_image(BlockDriverSt= ate *bs, const char *backing_file); int bdrv_get_backing_file_depth(BlockDriverState *bs); void bdrv_refresh_filename(BlockDriverState *bs); -int bdrv_truncate(BdrvChild *child, int64_t offset, Error **errp); +int bdrv_truncate(BdrvChild *child, int64_t offset, PreallocMode prealloc, + Error **errp); int64_t bdrv_nb_sectors(BlockDriverState *bs); int64_t bdrv_getlength(BlockDriverState *bs); int64_t bdrv_get_allocated_file_size(BlockDriverState *bs); diff --git a/block.c b/block.c index 57ae40a84e..9dc7ad85e2 100644 --- a/block.c +++ b/block.c @@ -3216,7 +3216,8 @@ exit: /** * Truncate file to 'offset' bytes (needed only for file protocols) */ -int bdrv_truncate(BdrvChild *child, int64_t offset, Error **errp) +int bdrv_truncate(BdrvChild *child, int64_t offset, PreallocMode prealloc, + Error **errp) { BlockDriverState *bs =3D child->bs; BlockDriver *drv =3D bs->drv; @@ -3237,14 +3238,19 @@ int bdrv_truncate(BdrvChild *child, int64_t offset,= Error **errp) return -EACCES; } =20 - ret =3D drv->bdrv_truncate(bs, offset, PREALLOC_MODE_OFF, errp); + ret =3D drv->bdrv_truncate(bs, offset, prealloc, errp); if (ret =3D=3D 0) { ret =3D refresh_total_sectors(bs, offset >> BDRV_SECTOR_BITS); bdrv_dirty_bitmap_truncate(bs); bdrv_parent_cb_resize(bs); ++bs->write_gen; } else if (errp && !*errp) { - error_setg_errno(errp, -ret, "Failed to resize image"); + if (ret =3D=3D -ENOTSUP) { + error_setg(errp, "Resize or preallocation mode not supported f= or " + "this image"); + } else { + error_setg_errno(errp, -ret, "Failed to resize image"); + } } return ret; } diff --git a/block/blkdebug.c b/block/blkdebug.c index 31a71a34d3..f682cbdbcb 100644 --- a/block/blkdebug.c +++ b/block/blkdebug.c @@ -664,13 +664,7 @@ static int64_t blkdebug_getlength(BlockDriverState *bs) static int blkdebug_truncate(BlockDriverState *bs, int64_t offset, PreallocMode prealloc, Error **errp) { - if (prealloc !=3D PREALLOC_MODE_OFF) { - error_setg(errp, "Unsupported preallocation mode '%s'", - PreallocMode_lookup[prealloc]); - return -ENOTSUP; - } - - return bdrv_truncate(bs->file, offset, errp); + return bdrv_truncate(bs->file, offset, prealloc, errp); } =20 static void blkdebug_refresh_filename(BlockDriverState *bs, QDict *options) diff --git a/block/block-backend.c b/block/block-backend.c index 24a16aadca..1bebc7f1ba 100644 --- a/block/block-backend.c +++ b/block/block-backend.c @@ -1705,7 +1705,7 @@ int blk_truncate(BlockBackend *blk, int64_t offset, E= rror **errp) return -ENOMEDIUM; } =20 - return bdrv_truncate(blk->root, offset, errp); + return bdrv_truncate(blk->root, offset, PREALLOC_MODE_OFF, errp); } =20 static void blk_pdiscard_entry(void *opaque) diff --git a/block/crypto.c b/block/crypto.c index fa61aef380..c24102fa7f 100644 --- a/block/crypto.c +++ b/block/crypto.c @@ -388,15 +388,9 @@ static int block_crypto_truncate(BlockDriverState *bs,= int64_t offset, size_t payload_offset =3D qcrypto_block_get_payload_offset(crypto->block); =20 - if (prealloc !=3D PREALLOC_MODE_OFF) { - error_setg(errp, "Unsupported preallocation mode '%s'", - PreallocMode_lookup[prealloc]); - return -ENOTSUP; - } - offset +=3D payload_offset; =20 - return bdrv_truncate(bs->file, offset, errp); + return bdrv_truncate(bs->file, offset, prealloc, errp); } =20 static void block_crypto_close(BlockDriverState *bs) diff --git a/block/parallels.c b/block/parallels.c index 618fc860e2..180111f71e 100644 --- a/block/parallels.c +++ b/block/parallels.c @@ -217,7 +217,7 @@ static int64_t allocate_clusters(BlockDriverState *bs, = int64_t sector_num, } else { ret =3D bdrv_truncate(bs->file, (s->data_end + space) << BDRV_SECTOR_BITS, - NULL); + PREALLOC_MODE_OFF, NULL); } if (ret < 0) { return ret; @@ -451,7 +451,8 @@ static int parallels_check(BlockDriverState *bs, BdrvCh= eckResult *res, res->leaks +=3D count; if (fix & BDRV_FIX_LEAKS) { Error *local_err =3D NULL; - ret =3D bdrv_truncate(bs->file, res->image_end_offset, &local_= err); + ret =3D bdrv_truncate(bs->file, res->image_end_offset, + PREALLOC_MODE_OFF, &local_err); if (ret < 0) { error_report_err(local_err); res->check_errors++; @@ -691,7 +692,8 @@ static int parallels_open(BlockDriverState *bs, QDict *= options, int flags, goto fail_options; } if (!bdrv_has_zero_init(bs->file->bs) || - bdrv_truncate(bs->file, bdrv_getlength(bs->file->bs), NULL) != =3D 0) { + bdrv_truncate(bs->file, bdrv_getlength(bs->file->bs), + PREALLOC_MODE_OFF, NULL) !=3D 0) { s->prealloc_mode =3D PRL_PREALLOC_MODE_FALLOCATE; } =20 @@ -734,7 +736,8 @@ static void parallels_close(BlockDriverState *bs) } =20 if (bs->open_flags & BDRV_O_RDWR) { - bdrv_truncate(bs->file, s->data_end << BDRV_SECTOR_BITS, NULL); + bdrv_truncate(bs->file, s->data_end << BDRV_SECTOR_BITS, + PREALLOC_MODE_OFF, NULL); } =20 g_free(s->bat_dirty_bmap); diff --git a/block/qcow.c b/block/qcow.c index 5d147b962e..45e3ff1a89 100644 --- a/block/qcow.c +++ b/block/qcow.c @@ -473,7 +473,8 @@ static uint64_t get_cluster_offset(BlockDriverState *bs, /* round to cluster size */ cluster_offset =3D (cluster_offset + s->cluster_size - 1) & ~(s->cluster_size - 1); - bdrv_truncate(bs->file, cluster_offset + s->cluster_size, = NULL); + bdrv_truncate(bs->file, cluster_offset + s->cluster_size, + PREALLOC_MODE_OFF, NULL); /* if encrypted, we must initialize the cluster content which won't be written */ if (bs->encrypted && @@ -916,7 +917,8 @@ static int qcow_make_empty(BlockDriverState *bs) if (bdrv_pwrite_sync(bs->file, s->l1_table_offset, s->l1_table, l1_length) < 0) return -1; - ret =3D bdrv_truncate(bs->file, s->l1_table_offset + l1_length, NULL); + ret =3D bdrv_truncate(bs->file, s->l1_table_offset + l1_length, + PREALLOC_MODE_OFF, NULL); if (ret < 0) return ret; =20 diff --git a/block/qcow2-refcount.c b/block/qcow2-refcount.c index 4efca7ebdb..c176ffed14 100644 --- a/block/qcow2-refcount.c +++ b/block/qcow2-refcount.c @@ -1736,7 +1736,7 @@ static int check_refblocks(BlockDriverState *bs, Bdrv= CheckResult *res, } =20 ret =3D bdrv_truncate(bs->file, offset + s->cluster_size, - &local_err); + PREALLOC_MODE_OFF, &local_err); if (ret < 0) { error_report_err(local_err); goto resize_fail; diff --git a/block/qcow2.c b/block/qcow2.c index 8d180bbf9d..52b9ad75fe 100644 --- a/block/qcow2.c +++ b/block/qcow2.c @@ -2592,7 +2592,7 @@ qcow2_co_pwritev_compressed(BlockDriverState *bs, uin= t64_t offset, /* align end of file to a sector boundary to ease reading with sector based I/Os */ cluster_offset =3D bdrv_getlength(bs->file->bs); - return bdrv_truncate(bs->file, cluster_offset, NULL); + return bdrv_truncate(bs->file, cluster_offset, PREALLOC_MODE_OFF, = NULL); } =20 buf =3D qemu_blockalign(bs, s->cluster_size); @@ -2808,7 +2808,7 @@ static int make_completely_empty(BlockDriverState *bs) } =20 ret =3D bdrv_truncate(bs->file, (3 + l1_clusters) * s->cluster_size, - &local_err); + PREALLOC_MODE_OFF, &local_err); if (ret < 0) { error_report_err(local_err); goto fail; diff --git a/block/raw-format.c b/block/raw-format.c index aeaa13e3f5..a7c5a7bce8 100644 --- a/block/raw-format.c +++ b/block/raw-format.c @@ -332,12 +332,6 @@ static int raw_truncate(BlockDriverState *bs, int64_t = offset, { BDRVRawState *s =3D bs->opaque; =20 - if (prealloc !=3D PREALLOC_MODE_OFF) { - error_setg(errp, "Unsupported preallocation mode '%s'", - PreallocMode_lookup[prealloc]); - return -ENOTSUP; - } - if (s->has_size) { error_setg(errp, "Cannot resize fixed-size raw disks"); return -ENOTSUP; @@ -350,7 +344,7 @@ static int raw_truncate(BlockDriverState *bs, int64_t o= ffset, =20 s->size =3D offset; offset +=3D s->offset; - return bdrv_truncate(bs->file, offset, errp); + return bdrv_truncate(bs->file, offset, prealloc, errp); } =20 static int raw_media_changed(BlockDriverState *bs) diff --git a/block/vhdx-log.c b/block/vhdx-log.c index 3f4c2aa095..01278f3fc9 100644 --- a/block/vhdx-log.c +++ b/block/vhdx-log.c @@ -548,7 +548,7 @@ static int vhdx_log_flush(BlockDriverState *bs, BDRVVHD= XState *s, if (new_file_size % (1024*1024)) { /* round up to nearest 1MB boundary */ new_file_size =3D ((new_file_size >> 20) + 1) << 20; - bdrv_truncate(bs->file, new_file_size, NULL); + bdrv_truncate(bs->file, new_file_size, PREALLOC_MODE_OFF, = NULL); } } qemu_vfree(desc_entries); diff --git a/block/vhdx.c b/block/vhdx.c index e8fe3fb5e9..967c93e996 100644 --- a/block/vhdx.c +++ b/block/vhdx.c @@ -1171,7 +1171,8 @@ static int vhdx_allocate_block(BlockDriverState *bs, = BDRVVHDXState *s, /* per the spec, the address for a block is in units of 1MB */ *new_offset =3D ROUND_UP(*new_offset, 1024 * 1024); =20 - return bdrv_truncate(bs->file, *new_offset + s->block_size, NULL); + return bdrv_truncate(bs->file, *new_offset + s->block_size, + PREALLOC_MODE_OFF, NULL); } =20 /* --=20 2.12.0 From nobody Thu Nov 6 14:07:01 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zoho.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1489441549537282.1563008540039; Mon, 13 Mar 2017 14:45:49 -0700 (PDT) Received: from localhost ([::1]:54551 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cnXml-0002Ww-60 for importer@patchew.org; Mon, 13 Mar 2017 17:45:47 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:43707) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cnXi5-0007RA-31 for qemu-devel@nongnu.org; Mon, 13 Mar 2017 17:40:58 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1cnXi3-0001pC-1h for qemu-devel@nongnu.org; Mon, 13 Mar 2017 17:40:57 -0400 Received: from mx1.redhat.com ([209.132.183.28]:52752) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1cnXhx-0001n8-C7; Mon, 13 Mar 2017 17:40:49 -0400 Received: from int-mx09.intmail.prod.int.phx2.redhat.com (int-mx09.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 7C6BD128D; Mon, 13 Mar 2017 21:40:49 +0000 (UTC) Received: from localhost (ovpn-204-63.brq.redhat.com [10.40.204.63]) by int-mx09.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id v2DLelSs018917 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=NO); Mon, 13 Mar 2017 17:40:48 -0400 From: Max Reitz To: qemu-block@nongnu.org Date: Mon, 13 Mar 2017 22:40:32 +0100 Message-Id: <20170313214045.26857-1-mreitz@redhat.com> In-Reply-To: <20170313214001.26339-1-mreitz@redhat.com> References: <20170313214001.26339-1-mreitz@redhat.com> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.22 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.29]); Mon, 13 Mar 2017 21:40:49 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH for-2.10 03/16] block: Add PreallocMode to blk_truncate() 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 , qemu-devel@nongnu.org, Max Reitz Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" blk_truncate() itself will pass that value to bdrv_truncate(), and all callers of blk_truncate() just set the parameter to PREALLOC_MODE_OFF for now. Signed-off-by: Max Reitz Reviewed-by: Stefan Hajnoczi --- include/sysemu/block-backend.h | 3 ++- block/block-backend.c | 5 +++-- block/commit.c | 4 ++-- block/mirror.c | 3 ++- block/parallels.c | 2 +- block/qcow.c | 2 +- block/qcow2.c | 4 ++-- block/qed.c | 2 +- block/vdi.c | 3 ++- block/vhdx.c | 5 +++-- block/vmdk.c | 7 ++++--- block/vpc.c | 2 +- blockdev.c | 2 +- qemu-img.c | 2 +- qemu-io-cmds.c | 2 +- 15 files changed, 27 insertions(+), 21 deletions(-) diff --git a/include/sysemu/block-backend.h b/include/sysemu/block-backend.h index 5796d1d634..9bdb216127 100644 --- a/include/sysemu/block-backend.h +++ b/include/sysemu/block-backend.h @@ -217,7 +217,8 @@ int coroutine_fn blk_co_pwrite_zeroes(BlockBackend *blk= , int64_t offset, int count, BdrvRequestFlags flags); int blk_pwrite_compressed(BlockBackend *blk, int64_t offset, const void *b= uf, int count); -int blk_truncate(BlockBackend *blk, int64_t offset, Error **errp); +int blk_truncate(BlockBackend *blk, int64_t offset, PreallocMode prealloc, + Error **errp); int blk_pdiscard(BlockBackend *blk, int64_t offset, int count); int blk_save_vmstate(BlockBackend *blk, const uint8_t *buf, int64_t pos, int size); diff --git a/block/block-backend.c b/block/block-backend.c index 1bebc7f1ba..ab0b649b6a 100644 --- a/block/block-backend.c +++ b/block/block-backend.c @@ -1698,14 +1698,15 @@ int blk_pwrite_compressed(BlockBackend *blk, int64_= t offset, const void *buf, BDRV_REQ_WRITE_COMPRESSED); } =20 -int blk_truncate(BlockBackend *blk, int64_t offset, Error **errp) +int blk_truncate(BlockBackend *blk, int64_t offset, PreallocMode prealloc, + Error **errp) { if (!blk_is_available(blk)) { error_setg(errp, "No medium inserted"); return -ENOMEDIUM; } =20 - return bdrv_truncate(blk->root, offset, PREALLOC_MODE_OFF, errp); + return bdrv_truncate(blk->root, offset, prealloc, errp); } =20 static void blk_pdiscard_entry(void *opaque) diff --git a/block/commit.c b/block/commit.c index bfdd1b4142..9a32338b82 100644 --- a/block/commit.c +++ b/block/commit.c @@ -151,7 +151,7 @@ static void coroutine_fn commit_run(void *opaque) } =20 if (base_len < s->common.len) { - ret =3D blk_truncate(s->base, s->common.len, NULL); + ret =3D blk_truncate(s->base, s->common.len, PREALLOC_MODE_OFF, NU= LL); if (ret) { goto out; } @@ -508,7 +508,7 @@ int bdrv_commit(BlockDriverState *bs) * grow the backing file image if possible. If not possible, * we must return an error */ if (length > backing_length) { - ret =3D blk_truncate(backing, length, &local_err); + ret =3D blk_truncate(backing, length, PREALLOC_MODE_OFF, &local_er= r); if (ret < 0) { error_report_err(local_err); goto ro_cleanup; diff --git a/block/mirror.c b/block/mirror.c index a520007800..cd187eaddb 100644 --- a/block/mirror.c +++ b/block/mirror.c @@ -722,7 +722,8 @@ static void coroutine_fn mirror_run(void *opaque) } =20 if (s->bdev_length > base_length) { - ret =3D blk_truncate(s->target, s->bdev_length, NULL); + ret =3D blk_truncate(s->target, s->bdev_length, PREALLOC_MODE_= OFF, + NULL); if (ret < 0) { goto immediate_exit; } diff --git a/block/parallels.c b/block/parallels.c index 180111f71e..e4c3f877f6 100644 --- a/block/parallels.c +++ b/block/parallels.c @@ -501,7 +501,7 @@ static int parallels_create(const char *filename, QemuO= pts *opts, Error **errp) =20 blk_set_allow_write_beyond_eof(file, true); =20 - ret =3D blk_truncate(file, 0, errp); + ret =3D blk_truncate(file, 0, PREALLOC_MODE_OFF, errp); if (ret < 0) { goto exit; } diff --git a/block/qcow.c b/block/qcow.c index 45e3ff1a89..20d160a9ac 100644 --- a/block/qcow.c +++ b/block/qcow.c @@ -834,7 +834,7 @@ static int qcow_create(const char *filename, QemuOpts *= opts, Error **errp) =20 blk_set_allow_write_beyond_eof(qcow_blk, true); =20 - ret =3D blk_truncate(qcow_blk, 0, errp); + ret =3D blk_truncate(qcow_blk, 0, PREALLOC_MODE_OFF, errp); if (ret < 0) { goto exit; } diff --git a/block/qcow2.c b/block/qcow2.c index 52b9ad75fe..210646b60f 100644 --- a/block/qcow2.c +++ b/block/qcow2.c @@ -2294,7 +2294,7 @@ static int qcow2_create2(const char *filename, int64_= t total_size, } =20 /* Okay, now that we have a valid image, let's give it the right size = */ - ret =3D blk_truncate(blk, total_size, errp); + ret =3D blk_truncate(blk, total_size, PREALLOC_MODE_OFF, errp); if (ret < 0) { goto out; } @@ -3284,7 +3284,7 @@ static int qcow2_amend_options(BlockDriverState *bs, = QemuOpts *opts, return ret; } =20 - ret =3D blk_truncate(blk, new_size, &local_err); + ret =3D blk_truncate(blk, new_size, PREALLOC_MODE_OFF, &local_err); blk_unref(blk); if (ret < 0) { error_report_err(local_err); diff --git a/block/qed.c b/block/qed.c index b5102f5d7f..7490ecf026 100644 --- a/block/qed.c +++ b/block/qed.c @@ -635,7 +635,7 @@ static int qed_create(const char *filename, uint32_t cl= uster_size, blk_set_allow_write_beyond_eof(blk, true); =20 /* File must start empty and grow, check truncate is supported */ - ret =3D blk_truncate(blk, 0, errp); + ret =3D blk_truncate(blk, 0, PREALLOC_MODE_OFF, errp); if (ret < 0) { goto out; } diff --git a/block/vdi.c b/block/vdi.c index d12d9cdc79..2434a9cd8d 100644 --- a/block/vdi.c +++ b/block/vdi.c @@ -832,7 +832,8 @@ static int vdi_create(const char *filename, QemuOpts *o= pts, Error **errp) } =20 if (image_type =3D=3D VDI_TYPE_STATIC) { - ret =3D blk_truncate(blk, offset + blocks * block_size, errp); + ret =3D blk_truncate(blk, offset + blocks * block_size, + PREALLOC_MODE_OFF, errp); if (ret < 0) { error_prepend(errp, "Failed to statically allocate %s", filena= me); goto exit; diff --git a/block/vhdx.c b/block/vhdx.c index 967c93e996..96933ed2f0 100644 --- a/block/vhdx.c +++ b/block/vhdx.c @@ -1608,12 +1608,13 @@ static int vhdx_create_bat(BlockBackend *blk, BDRVV= HDXState *s, if (type =3D=3D VHDX_TYPE_DYNAMIC) { /* All zeroes, so we can just extend the file - the end of the BAT * is the furthest thing we have written yet */ - ret =3D blk_truncate(blk, data_file_offset, errp); + ret =3D blk_truncate(blk, data_file_offset, PREALLOC_MODE_OFF, err= p); if (ret < 0) { goto exit; } } else if (type =3D=3D VHDX_TYPE_FIXED) { - ret =3D blk_truncate(blk, data_file_offset + image_size, errp); + ret =3D blk_truncate(blk, data_file_offset + image_size, + PREALLOC_MODE_OFF, errp); if (ret < 0) { goto exit; } diff --git a/block/vmdk.c b/block/vmdk.c index c61b9cc8e0..7decd3ed44 100644 --- a/block/vmdk.c +++ b/block/vmdk.c @@ -1714,7 +1714,7 @@ static int vmdk_create_extent(const char *filename, i= nt64_t filesize, blk_set_allow_write_beyond_eof(blk, true); =20 if (flat) { - ret =3D blk_truncate(blk, filesize, errp); + ret =3D blk_truncate(blk, filesize, PREALLOC_MODE_OFF, errp); goto exit; } magic =3D cpu_to_be32(VMDK4_MAGIC); @@ -1777,7 +1777,8 @@ static int vmdk_create_extent(const char *filename, i= nt64_t filesize, goto exit; } =20 - ret =3D blk_truncate(blk, le64_to_cpu(header.grain_offset) << 9, errp); + ret =3D blk_truncate(blk, le64_to_cpu(header.grain_offset) << 9, + PREALLOC_MODE_OFF, errp); if (ret < 0) { goto exit; } @@ -2086,7 +2087,7 @@ static int vmdk_create(const char *filename, QemuOpts= *opts, Error **errp) /* bdrv_pwrite write padding zeros to align to sector, we don't need t= hat * for description file */ if (desc_offset =3D=3D 0) { - ret =3D blk_truncate(new_blk, desc_len, errp); + ret =3D blk_truncate(new_blk, desc_len, PREALLOC_MODE_OFF, errp); } exit: if (new_blk) { diff --git a/block/vpc.c b/block/vpc.c index ecfee77149..de71398eb4 100644 --- a/block/vpc.c +++ b/block/vpc.c @@ -858,7 +858,7 @@ static int create_fixed_disk(BlockBackend *blk, uint8_t= *buf, /* Add footer to total size */ total_size +=3D HEADER_SIZE; =20 - ret =3D blk_truncate(blk, total_size, errp); + ret =3D blk_truncate(blk, total_size, PREALLOC_MODE_OFF, errp); if (ret < 0) { return ret; } diff --git a/blockdev.c b/blockdev.c index de50d461d2..77f14f6a10 100644 --- a/blockdev.c +++ b/blockdev.c @@ -2928,7 +2928,7 @@ void qmp_block_resize(bool has_device, const char *de= vice, /* complete all in-flight operations before resizing the device */ bdrv_drain_all(); =20 - ret =3D blk_truncate(blk, size, errp); + ret =3D blk_truncate(blk, size, PREALLOC_MODE_OFF, errp); =20 out: blk_unref(blk); diff --git a/qemu-img.c b/qemu-img.c index 0b0178949d..3e637a932b 100644 --- a/qemu-img.c +++ b/qemu-img.c @@ -3440,7 +3440,7 @@ static int img_resize(int argc, char **argv) goto out; } =20 - ret =3D blk_truncate(blk, total_size, &err); + ret =3D blk_truncate(blk, total_size, PREALLOC_MODE_OFF, &err); if (!ret) { qprintf(quiet, "Image resized.\n"); } else { diff --git a/qemu-io-cmds.c b/qemu-io-cmds.c index 05bb0b34ec..b5d9b293b0 100644 --- a/qemu-io-cmds.c +++ b/qemu-io-cmds.c @@ -1570,7 +1570,7 @@ static int truncate_f(BlockBackend *blk, int argc, ch= ar **argv) return 0; } =20 - ret =3D blk_truncate(blk, offset, &local_err); + ret =3D blk_truncate(blk, offset, PREALLOC_MODE_OFF, &local_err); if (ret < 0) { error_report_err(local_err); return 0; --=20 2.12.0 From nobody Thu Nov 6 14:07:01 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zoho.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1489441408819995.1461999656476; Mon, 13 Mar 2017 14:43:28 -0700 (PDT) Received: from localhost ([::1]:54541 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cnXkV-0000UE-GY for importer@patchew.org; Mon, 13 Mar 2017 17:43:27 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:43700) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cnXi4-0007Qi-Lv for qemu-devel@nongnu.org; Mon, 13 Mar 2017 17:40:57 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1cnXi3-0001pP-Fk for qemu-devel@nongnu.org; Mon, 13 Mar 2017 17:40:56 -0400 Received: from mx1.redhat.com ([209.132.183.28]:42528) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1cnXhz-0001oT-Qd; Mon, 13 Mar 2017 17:40:52 -0400 Received: from int-mx11.intmail.prod.int.phx2.redhat.com (int-mx11.intmail.prod.int.phx2.redhat.com [10.5.11.24]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id E827581222; Mon, 13 Mar 2017 21:40:51 +0000 (UTC) Received: from localhost (ovpn-204-63.brq.redhat.com [10.40.204.63]) by int-mx11.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id v2DLeovj015077 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=NO); Mon, 13 Mar 2017 17:40:51 -0400 From: Max Reitz To: qemu-block@nongnu.org Date: Mon, 13 Mar 2017 22:40:33 +0100 Message-Id: <20170313214045.26857-2-mreitz@redhat.com> In-Reply-To: <20170313214001.26339-1-mreitz@redhat.com> References: <20170313214001.26339-1-mreitz@redhat.com> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.24 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.25]); Mon, 13 Mar 2017 21:40:51 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH for-2.10 04/16] qemu-img: Expose PreallocMode for resizing 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 , qemu-devel@nongnu.org, Max Reitz Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Add a --preallocation command line option to qemu-img resize which can be used to set the PreallocMode parameter of blk_truncate(). Signed-off-by: Max Reitz --- qemu-img.c | 33 ++++++++++++++++++++++++++++++--- qemu-img.texi | 7 ++++++- 2 files changed, 36 insertions(+), 4 deletions(-) diff --git a/qemu-img.c b/qemu-img.c index 3e637a932b..a5fdd30202 100644 --- a/qemu-img.c +++ b/qemu-img.c @@ -24,6 +24,7 @@ #include "qemu/osdep.h" #include "qemu-version.h" #include "qapi/error.h" +#include "qapi/util.h" #include "qapi-visit.h" #include "qapi/qobject-output-visitor.h" #include "qapi/qmp/qerror.h" @@ -59,6 +60,7 @@ enum { OPTION_PATTERN =3D 260, OPTION_FLUSH_INTERVAL =3D 261, OPTION_NO_DRAIN =3D 262, + OPTION_PREALLOCATION =3D 263, }; =20 typedef enum OutputFormat { @@ -3317,9 +3319,10 @@ static int img_resize(int argc, char **argv) Error *err =3D NULL; int c, ret, relative; const char *filename, *fmt, *size; - int64_t n, total_size; + int64_t n, total_size, current_size; bool quiet =3D false; BlockBackend *blk =3D NULL; + PreallocMode prealloc =3D PREALLOC_MODE_OFF; QemuOpts *param; =20 static QemuOptsList resize_options =3D { @@ -3353,6 +3356,7 @@ static int img_resize(int argc, char **argv) {"help", no_argument, 0, 'h'}, {"object", required_argument, 0, OPTION_OBJECT}, {"image-opts", no_argument, 0, OPTION_IMAGE_OPTS}, + {"preallocation", required_argument, 0, OPTION_PREALLOCATION}, {0, 0, 0, 0} }; c =3D getopt_long(argc, argv, "f:hq", @@ -3382,6 +3386,15 @@ static int img_resize(int argc, char **argv) case OPTION_IMAGE_OPTS: image_opts =3D true; break; + case OPTION_PREALLOCATION: + prealloc =3D qapi_enum_parse(PreallocMode_lookup, optarg, + PREALLOC_MODE__MAX, PREALLOC_MODE__= MAX, + NULL); + if (prealloc =3D=3D PREALLOC_MODE__MAX) { + error_report("Invalid preallocation mode '%s'", optarg); + return 1; + } + break; } } if (optind !=3D argc - 1) { @@ -3429,8 +3442,16 @@ static int img_resize(int argc, char **argv) goto out; } =20 + current_size =3D blk_getlength(blk); + if (current_size < 0) { + error_report("Failed to inquire current image length: %s\n", + strerror(-current_size)); + ret =3D -1; + goto out; + } + if (relative) { - total_size =3D blk_getlength(blk) + n * relative; + total_size =3D current_size + n * relative; } else { total_size =3D n; } @@ -3440,7 +3461,13 @@ static int img_resize(int argc, char **argv) goto out; } =20 - ret =3D blk_truncate(blk, total_size, PREALLOC_MODE_OFF, &err); + if (total_size <=3D current_size && prealloc !=3D PREALLOC_MODE_OFF) { + error_report("Preallocation can only be used for growing images"); + ret =3D -1; + goto out; + } + + ret =3D blk_truncate(blk, total_size, prealloc, &err); if (!ret) { qprintf(quiet, "Image resized.\n"); } else { diff --git a/qemu-img.texi b/qemu-img.texi index c81db3e81c..ad46fa5f05 100644 --- a/qemu-img.texi +++ b/qemu-img.texi @@ -490,7 +490,7 @@ qemu-img rebase -b base.img diff.qcow2 At this point, @code{modified.img} can be discarded, since @code{base.img + diff.qcow2} contains the same information. =20 -@item resize @var{filename} [+ | -]@var{size} +@item resize [--preallocation=3D@var{prealloc}] @var{filename} [+ | -]@var= {size} =20 Change the disk image as if it had been created with @var{size}. =20 @@ -502,6 +502,11 @@ After using this command to grow a disk image, you mus= t use file system and partitioning tools inside the VM to actually begin using the new space on = the device. =20 +When growing an image, the @code{--preallocation} option may be used to sp= ecify +how the additional image area should be allocated on the host. See the fo= rmat +description in the @code{NOTES} section which values are allowed. Using t= his +option may result in more data being allocated than necessary. + @item amend [-p] [-f @var{fmt}] [-t @var{cache}] -o @var{options} @var{fil= ename} =20 Amends the image format specific @var{options} for the image file --=20 2.12.0 From nobody Thu Nov 6 14:07:01 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zoho.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1489441411317314.916551536509; Mon, 13 Mar 2017 14:43:31 -0700 (PDT) Received: from localhost ([::1]:54543 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cnXkY-0000XN-3j for importer@patchew.org; Mon, 13 Mar 2017 17:43:30 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:43710) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cnXi5-0007RO-9W for qemu-devel@nongnu.org; Mon, 13 Mar 2017 17:40:58 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1cnXi4-0001pf-6i for qemu-devel@nongnu.org; Mon, 13 Mar 2017 17:40:57 -0400 Received: from mx1.redhat.com ([209.132.183.28]:44382) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1cnXi2-0001op-42; Mon, 13 Mar 2017 17:40:54 -0400 Received: from int-mx09.intmail.prod.int.phx2.redhat.com (int-mx09.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 437997702; Mon, 13 Mar 2017 21:40:54 +0000 (UTC) Received: from localhost (ovpn-204-63.brq.redhat.com [10.40.204.63]) by int-mx09.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id v2DLeqt0018960 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=NO); Mon, 13 Mar 2017 17:40:53 -0400 From: Max Reitz To: qemu-block@nongnu.org Date: Mon, 13 Mar 2017 22:40:34 +0100 Message-Id: <20170313214045.26857-3-mreitz@redhat.com> In-Reply-To: <20170313214001.26339-1-mreitz@redhat.com> References: <20170313214001.26339-1-mreitz@redhat.com> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.22 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.38]); Mon, 13 Mar 2017 21:40:54 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH for-2.10 05/16] block/file-posix: Small fixes in raw_create() 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 , qemu-devel@nongnu.org, Max Reitz Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Variables should be declared at the start of a block, and if a certain parameter value is not supported it may be better to return -ENOTSUP instead of -EINVAL. Signed-off-by: Max Reitz Reviewed-by: Stefan Hajnoczi --- block/file-posix.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/block/file-posix.c b/block/file-posix.c index dde8c101c8..b02d8fc37b 100644 --- a/block/file-posix.c +++ b/block/file-posix.c @@ -1670,6 +1670,8 @@ static int raw_create(const char *filename, QemuOpts = *opts, Error **errp) #endif case PREALLOC_MODE_FULL: { + int64_t num =3D 0, left =3D total_size; + /* * Knowing the final size from the beginning could allow the file * system driver to do less allocations and possibly avoid @@ -1681,7 +1683,6 @@ static int raw_create(const char *filename, QemuOpts = *opts, Error **errp) goto out_close; } =20 - int64_t num =3D 0, left =3D total_size; buf =3D g_malloc0(65536); =20 while (left > 0) { @@ -1713,7 +1714,7 @@ static int raw_create(const char *filename, QemuOpts = *opts, Error **errp) } break; default: - result =3D -EINVAL; + result =3D -ENOTSUP; error_setg(errp, "Unsupported preallocation mode: %s", PreallocMode_lookup[prealloc]); break; --=20 2.12.0 From nobody Thu Nov 6 14:07:01 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zoho.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1489441554407800.3365724878714; Mon, 13 Mar 2017 14:45:54 -0700 (PDT) Received: from localhost ([::1]:54553 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cnXmq-0002d8-PM for importer@patchew.org; Mon, 13 Mar 2017 17:45:52 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:43758) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cnXiA-0007Wu-CA for qemu-devel@nongnu.org; Mon, 13 Mar 2017 17:41:03 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1cnXi9-0001tH-80 for qemu-devel@nongnu.org; Mon, 13 Mar 2017 17:41:02 -0400 Received: from mx1.redhat.com ([209.132.183.28]:51582) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1cnXi4-0001pa-L4; Mon, 13 Mar 2017 17:40:56 -0400 Received: from int-mx13.intmail.prod.int.phx2.redhat.com (int-mx13.intmail.prod.int.phx2.redhat.com [10.5.11.26]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id C073A61B86; Mon, 13 Mar 2017 21:40:56 +0000 (UTC) Received: from localhost (ovpn-204-63.brq.redhat.com [10.40.204.63]) by int-mx13.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id v2DLesYV026113 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=NO); Mon, 13 Mar 2017 17:40:56 -0400 From: Max Reitz To: qemu-block@nongnu.org Date: Mon, 13 Mar 2017 22:40:35 +0100 Message-Id: <20170313214045.26857-4-mreitz@redhat.com> In-Reply-To: <20170313214001.26339-1-mreitz@redhat.com> References: <20170313214001.26339-1-mreitz@redhat.com> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.26 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.39]); Mon, 13 Mar 2017 21:40:56 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH for-2.10 06/16] block/file-posix: Extract raw_regular_truncate() 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 , qemu-devel@nongnu.org, Max Reitz Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" This functionality is part of raw_create() which we will be able to reuse nicely in raw_truncate(). Signed-off-by: Max Reitz Reviewed-by: Stefan Hajnoczi --- block/file-posix.c | 144 +++++++++++++++++++++++++++++--------------------= ---- 1 file changed, 78 insertions(+), 66 deletions(-) diff --git a/block/file-posix.c b/block/file-posix.c index b02d8fc37b..35a9e43f3e 100644 --- a/block/file-posix.c +++ b/block/file-posix.c @@ -1384,6 +1384,81 @@ static void raw_close(BlockDriverState *bs) } } =20 +static int raw_regular_truncate(int fd, int64_t offset, PreallocMode preal= loc, + Error **errp) +{ + int result =3D 0; + char *buf; + + switch (prealloc) { +#ifdef CONFIG_POSIX_FALLOCATE + case PREALLOC_MODE_FALLOC: + /* + * Truncating before posix_fallocate() makes it about twice slower= on + * file systems that do not support fallocate(), trying to check i= f a + * block is allocated before allocating it, so don't do that here. + */ + result =3D -posix_fallocate(fd, 0, offset); + if (result !=3D 0) { + /* posix_fallocate() doesn't set errno. */ + error_setg_errno(errp, -result, + "Could not preallocate data for the new file"= ); + } + return result; +#endif + case PREALLOC_MODE_FULL: + { + int64_t num =3D 0, left =3D offset; + + /* + * Knowing the final size from the beginning could allow the file + * system driver to do less allocations and possibly avoid + * fragmentation of the file. + */ + if (ftruncate(fd, offset) !=3D 0) { + result =3D -errno; + error_setg_errno(errp, -result, "Could not resize file"); + return result; + } + + buf =3D g_malloc0(65536); + + while (left > 0) { + num =3D MIN(left, 65536); + result =3D write(fd, buf, num); + if (result < 0) { + result =3D -errno; + error_setg_errno(errp, -result, + "Could not write to the new file"); + break; + } + left -=3D result; + } + if (result >=3D 0) { + result =3D fsync(fd); + if (result < 0) { + result =3D -errno; + error_setg_errno(errp, -result, + "Could not flush new file to disk"); + } + } + g_free(buf); + return result; + } + case PREALLOC_MODE_OFF: + if (ftruncate(fd, offset) !=3D 0) { + result =3D -errno; + error_setg_errno(errp, -result, "Could not resize file"); + } + return result; + default: + result =3D -ENOTSUP; + error_setg(errp, "Unsupported preallocation mode: %s", + PreallocMode_lookup[prealloc]); + return result; + } +} + static int raw_truncate(BlockDriverState *bs, int64_t offset, PreallocMode prealloc, Error **errp) { @@ -1652,72 +1727,9 @@ static int raw_create(const char *filename, QemuOpts= *opts, Error **errp) #endif } =20 - switch (prealloc) { -#ifdef CONFIG_POSIX_FALLOCATE - case PREALLOC_MODE_FALLOC: - /* - * Truncating before posix_fallocate() makes it about twice slower= on - * file systems that do not support fallocate(), trying to check i= f a - * block is allocated before allocating it, so don't do that here. - */ - result =3D -posix_fallocate(fd, 0, total_size); - if (result !=3D 0) { - /* posix_fallocate() doesn't set errno. */ - error_setg_errno(errp, -result, - "Could not preallocate data for the new file"= ); - } - break; -#endif - case PREALLOC_MODE_FULL: - { - int64_t num =3D 0, left =3D total_size; - - /* - * Knowing the final size from the beginning could allow the file - * system driver to do less allocations and possibly avoid - * fragmentation of the file. - */ - if (ftruncate(fd, total_size) !=3D 0) { - result =3D -errno; - error_setg_errno(errp, -result, "Could not resize file"); - goto out_close; - } - - buf =3D g_malloc0(65536); - - while (left > 0) { - num =3D MIN(left, 65536); - result =3D write(fd, buf, num); - if (result < 0) { - result =3D -errno; - error_setg_errno(errp, -result, - "Could not write to the new file"); - break; - } - left -=3D result; - } - if (result >=3D 0) { - result =3D fsync(fd); - if (result < 0) { - result =3D -errno; - error_setg_errno(errp, -result, - "Could not flush new file to disk"); - } - } - g_free(buf); - break; - } - case PREALLOC_MODE_OFF: - if (ftruncate(fd, total_size) !=3D 0) { - result =3D -errno; - error_setg_errno(errp, -result, "Could not resize file"); - } - break; - default: - result =3D -ENOTSUP; - error_setg(errp, "Unsupported preallocation mode: %s", - PreallocMode_lookup[prealloc]); - break; + result =3D raw_regular_truncate(fd, total_size, prealloc, errp); + if (result < 0) { + goto out_close; } =20 out_close: --=20 2.12.0 From nobody Thu Nov 6 14:07:01 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zoho.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1489441330715151.25069382878792; Mon, 13 Mar 2017 14:42:10 -0700 (PDT) Received: from localhost ([::1]:54533 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cnXjF-0007bv-Eh for importer@patchew.org; Mon, 13 Mar 2017 17:42:09 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:43784) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cnXiB-0007YF-Ny for qemu-devel@nongnu.org; Mon, 13 Mar 2017 17:41:04 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1cnXiA-0001un-Ea for qemu-devel@nongnu.org; Mon, 13 Mar 2017 17:41:03 -0400 Received: from mx1.redhat.com ([209.132.183.28]:52840) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1cnXi7-0001rP-4e; Mon, 13 Mar 2017 17:40:59 -0400 Received: from int-mx11.intmail.prod.int.phx2.redhat.com (int-mx11.intmail.prod.int.phx2.redhat.com [10.5.11.24]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 3BE3A437F41; Mon, 13 Mar 2017 21:40:59 +0000 (UTC) Received: from localhost (ovpn-204-63.brq.redhat.com [10.40.204.63]) by int-mx11.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id v2DLevTn015147 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=NO); Mon, 13 Mar 2017 17:40:58 -0400 From: Max Reitz To: qemu-block@nongnu.org Date: Mon, 13 Mar 2017 22:40:36 +0100 Message-Id: <20170313214045.26857-5-mreitz@redhat.com> In-Reply-To: <20170313214001.26339-1-mreitz@redhat.com> References: <20170313214001.26339-1-mreitz@redhat.com> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.24 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.29]); Mon, 13 Mar 2017 21:40:59 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH for-2.10 07/16] block/file-posix: Generalize raw_regular_truncate 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 , qemu-devel@nongnu.org, Max Reitz Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Currently, raw_regular_truncate() is intended for setting the size of a newly created file. However, we also want to use it for truncating an existing file in which case only the newly added space (when growing) should be preallocated. This also means that if resizing failed, we should try to restore the original file size. This is important when using preallocation. Signed-off-by: Max Reitz --- block/file-posix.c | 73 ++++++++++++++++++++++++++++++++++++++++++++------= ---- 1 file changed, 60 insertions(+), 13 deletions(-) diff --git a/block/file-posix.c b/block/file-posix.c index 35a9e43f3e..cd229324ba 100644 --- a/block/file-posix.c +++ b/block/file-posix.c @@ -1384,11 +1384,39 @@ static void raw_close(BlockDriverState *bs) } } =20 -static int raw_regular_truncate(int fd, int64_t offset, PreallocMode preal= loc, +/** + * Truncates the given regular file @fd to @offset and, when growing, fill= s the + * new space according to @prealloc. + * + * @create must be true iff the file is new. In that case, @bs is ignored.= If + * @create is false, @bs must be valid and correspond to the same file as = @fd. + */ +static int raw_regular_truncate(int fd, BlockDriverState *bs, int64_t offs= et, + PreallocMode prealloc, bool create, Error **errp) { int result =3D 0; - char *buf; + int64_t current_length =3D 0; + char *buf =3D NULL; + + assert(create || bs); + if (!create) { + BDRVRawState *s =3D bs->opaque; + assert(s->fd =3D=3D fd); + } + + if (!create) { + current_length =3D bdrv_getlength(bs); + if (current_length < 0) { + error_setg_errno(errp, -current_length, + "Could not inquire current length"); + return -current_length; + } + + if (current_length > offset && prealloc !=3D PREALLOC_MODE_OFF) { + return -ENOTSUP; + } + } =20 switch (prealloc) { #ifdef CONFIG_POSIX_FALLOCATE @@ -1398,17 +1426,17 @@ static int raw_regular_truncate(int fd, int64_t off= set, PreallocMode prealloc, * file systems that do not support fallocate(), trying to check i= f a * block is allocated before allocating it, so don't do that here. */ - result =3D -posix_fallocate(fd, 0, offset); + result =3D -posix_fallocate(fd, current_length, offset - current_l= ength); if (result !=3D 0) { /* posix_fallocate() doesn't set errno. */ error_setg_errno(errp, -result, - "Could not preallocate data for the new file"= ); + "Could not preallocate new data"); } - return result; + goto out; #endif case PREALLOC_MODE_FULL: { - int64_t num =3D 0, left =3D offset; + int64_t num =3D 0, left =3D offset - current_length; =20 /* * Knowing the final size from the beginning could allow the file @@ -1418,19 +1446,27 @@ static int raw_regular_truncate(int fd, int64_t off= set, PreallocMode prealloc, if (ftruncate(fd, offset) !=3D 0) { result =3D -errno; error_setg_errno(errp, -result, "Could not resize file"); - return result; + goto out; } =20 buf =3D g_malloc0(65536); =20 + result =3D lseek(fd, current_length, SEEK_SET); + if (result < 0) { + result =3D -errno; + error_setg_errno(errp, -result, + "Failed to seek to the old end of file"); + goto out; + } + while (left > 0) { num =3D MIN(left, 65536); result =3D write(fd, buf, num); if (result < 0) { result =3D -errno; error_setg_errno(errp, -result, - "Could not write to the new file"); - break; + "Could not write zeros for preallocation"= ); + goto out; } left -=3D result; } @@ -1439,11 +1475,11 @@ static int raw_regular_truncate(int fd, int64_t off= set, PreallocMode prealloc, if (result < 0) { result =3D -errno; error_setg_errno(errp, -result, - "Could not flush new file to disk"); + "Could not flush file to disk"); + goto out; } } - g_free(buf); - return result; + goto out; } case PREALLOC_MODE_OFF: if (ftruncate(fd, offset) !=3D 0) { @@ -1457,6 +1493,17 @@ static int raw_regular_truncate(int fd, int64_t offs= et, PreallocMode prealloc, PreallocMode_lookup[prealloc]); return result; } + +out: + if (result < 0 && !create) { + if (ftruncate(fd, current_length) < 0) { + error_report("Failed to restore old file length: %s", + strerror(errno)); + } + } + + g_free(buf); + return result; } =20 static int raw_truncate(BlockDriverState *bs, int64_t offset, @@ -1727,7 +1774,7 @@ static int raw_create(const char *filename, QemuOpts = *opts, Error **errp) #endif } =20 - result =3D raw_regular_truncate(fd, total_size, prealloc, errp); + result =3D raw_regular_truncate(fd, NULL, total_size, prealloc, true, = errp); if (result < 0) { goto out_close; } --=20 2.12.0 From nobody Thu Nov 6 14:07:01 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zoho.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1489441467922482.11803150791025; Mon, 13 Mar 2017 14:44:27 -0700 (PDT) Received: from localhost ([::1]:54544 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cnXlR-0001IZ-Jb for importer@patchew.org; Mon, 13 Mar 2017 17:44:25 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:43802) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cnXiD-0007a0-4P for qemu-devel@nongnu.org; Mon, 13 Mar 2017 17:41:06 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1cnXiC-0001vu-BM for qemu-devel@nongnu.org; Mon, 13 Mar 2017 17:41:05 -0400 Received: from mx1.redhat.com ([209.132.183.28]:58344) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1cnXiA-0001tj-0L; Mon, 13 Mar 2017 17:41:02 -0400 Received: from int-mx14.intmail.prod.int.phx2.redhat.com (int-mx14.intmail.prod.int.phx2.redhat.com [10.5.11.27]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 2929680F6B; Mon, 13 Mar 2017 21:41:02 +0000 (UTC) Received: from localhost (ovpn-204-63.brq.redhat.com [10.40.204.63]) by int-mx14.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id v2DLexNT016369 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=NO); Mon, 13 Mar 2017 17:41:01 -0400 From: Max Reitz To: qemu-block@nongnu.org Date: Mon, 13 Mar 2017 22:40:37 +0100 Message-Id: <20170313214045.26857-6-mreitz@redhat.com> In-Reply-To: <20170313214001.26339-1-mreitz@redhat.com> References: <20170313214001.26339-1-mreitz@redhat.com> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.27 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.27]); Mon, 13 Mar 2017 21:41:02 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH for-2.10 08/16] block/file-posix: Preallocation for truncate 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 , qemu-devel@nongnu.org, Max Reitz Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" By using raw_regular_truncate() in raw_truncate(), we can now easily support preallocation. Signed-off-by: Max Reitz Reviewed-by: Stefan Hajnoczi --- block/file-posix.c | 22 ++++++++++------------ 1 file changed, 10 insertions(+), 12 deletions(-) diff --git a/block/file-posix.c b/block/file-posix.c index cd229324ba..c181f13e98 100644 --- a/block/file-posix.c +++ b/block/file-posix.c @@ -1513,12 +1513,6 @@ static int raw_truncate(BlockDriverState *bs, int64_= t offset, struct stat st; int ret; =20 - if (prealloc !=3D PREALLOC_MODE_OFF) { - error_setg(errp, "Unsupported preallocation mode '%s'", - PreallocMode_lookup[prealloc]); - return -ENOTSUP; - } - if (fstat(s->fd, &st)) { ret =3D -errno; error_setg_errno(errp, -ret, "Failed to fstat() the file"); @@ -1526,12 +1520,16 @@ static int raw_truncate(BlockDriverState *bs, int64= _t offset, } =20 if (S_ISREG(st.st_mode)) { - if (ftruncate(s->fd, offset) < 0) { - ret =3D -errno; - error_setg_errno(errp, -ret, "Failed to resize the file"); - return ret; - } - } else if (S_ISCHR(st.st_mode) || S_ISBLK(st.st_mode)) { + return raw_regular_truncate(s->fd, bs, offset, prealloc, false, er= rp); + } + + if (prealloc !=3D PREALLOC_MODE_OFF) { + error_setg(errp, "Preallocation mode '%s' unsupported for this " + "non-regular file", PreallocMode_lookup[prealloc]); + return -ENOTSUP; + } + + if (S_ISCHR(st.st_mode) || S_ISBLK(st.st_mode)) { if (offset > raw_getlength(bs)) { error_setg(errp, "Cannot grow device files"); return -EINVAL; --=20 2.12.0 From nobody Thu Nov 6 14:07:01 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zoho.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1489441607397126.39392787050167; Mon, 13 Mar 2017 14:46:47 -0700 (PDT) Received: from localhost ([::1]:54562 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cnXni-0003On-0D for importer@patchew.org; Mon, 13 Mar 2017 17:46:46 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:43826) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cnXiF-0007cK-CL for qemu-devel@nongnu.org; Mon, 13 Mar 2017 17:41:10 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1cnXiE-0001wr-J7 for qemu-devel@nongnu.org; Mon, 13 Mar 2017 17:41:07 -0400 Received: from mx1.redhat.com ([209.132.183.28]:40210) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1cnXiC-0001vQ-7w; Mon, 13 Mar 2017 17:41:04 -0400 Received: from int-mx11.intmail.prod.int.phx2.redhat.com (int-mx11.intmail.prod.int.phx2.redhat.com [10.5.11.24]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 62E133B720; Mon, 13 Mar 2017 21:41:04 +0000 (UTC) Received: from localhost (ovpn-204-63.brq.redhat.com [10.40.204.63]) by int-mx11.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id v2DLf2lB015201 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=NO); Mon, 13 Mar 2017 17:41:03 -0400 From: Max Reitz To: qemu-block@nongnu.org Date: Mon, 13 Mar 2017 22:40:38 +0100 Message-Id: <20170313214045.26857-7-mreitz@redhat.com> In-Reply-To: <20170313214001.26339-1-mreitz@redhat.com> References: <20170313214001.26339-1-mreitz@redhat.com> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.24 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.30]); Mon, 13 Mar 2017 21:41:04 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH for-2.10 09/16] block/qcow2: Generalize preallocate() 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 , qemu-devel@nongnu.org, Max Reitz Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" This patch adds two new parameters to the preallocate() function so we will be able to use it not just for preallocating a new image but also for preallocated image growth. The offset parameter allows the caller to specify a virtual offset from which to start preallocating. For newly created images this is always 0, but for preallocating growth this will be the old image length. The new_length parameter specifies the supposed new length of the image (basically the "end offset" for preallocation). During image truncation, bdrv_getlength() will return the old image length so we cannot rely on its return value then. Signed-off-by: Max Reitz --- block/qcow2.c | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/block/qcow2.c b/block/qcow2.c index 210646b60f..9abdf9e0fb 100644 --- a/block/qcow2.c +++ b/block/qcow2.c @@ -2034,17 +2034,16 @@ static int qcow2_change_backing_file(BlockDriverSta= te *bs, return qcow2_update_header(bs); } =20 -static int preallocate(BlockDriverState *bs) +static int preallocate(BlockDriverState *bs, int64_t offset, int64_t new_l= ength) { uint64_t bytes; - uint64_t offset; uint64_t host_offset =3D 0; unsigned int cur_bytes; int ret; QCowL2Meta *meta; =20 - bytes =3D bdrv_getlength(bs); - offset =3D 0; + assert(offset <=3D new_length); + bytes =3D new_length - offset; =20 while (bytes) { cur_bytes =3D MIN(bytes, INT_MAX); @@ -2313,7 +2312,7 @@ static int qcow2_create2(const char *filename, int64_= t total_size, if (prealloc !=3D PREALLOC_MODE_OFF) { BDRVQcow2State *s =3D blk_bs(blk)->opaque; qemu_co_mutex_lock(&s->lock); - ret =3D preallocate(blk_bs(blk)); + ret =3D preallocate(blk_bs(blk), 0, total_size); qemu_co_mutex_unlock(&s->lock); if (ret < 0) { error_setg_errno(errp, -ret, "Could not preallocate metadata"); --=20 2.12.0 From nobody Thu Nov 6 14:07:01 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zoho.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1489441563523683.8455328271124; Mon, 13 Mar 2017 14:46:03 -0700 (PDT) Received: from localhost ([::1]:54556 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cnXn0-0002ln-6C for importer@patchew.org; Mon, 13 Mar 2017 17:46:02 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:43911) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cnXiW-0007pM-0g for qemu-devel@nongnu.org; Mon, 13 Mar 2017 17:41:25 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1cnXiV-00025D-1t for qemu-devel@nongnu.org; Mon, 13 Mar 2017 17:41:24 -0400 Received: from mx1.redhat.com ([209.132.183.28]:58438) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1cnXiS-00023x-K6; Mon, 13 Mar 2017 17:41:20 -0400 Received: from int-mx14.intmail.prod.int.phx2.redhat.com (int-mx14.intmail.prod.int.phx2.redhat.com [10.5.11.27]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id BB3B183F46; Mon, 13 Mar 2017 21:41:20 +0000 (UTC) Received: from localhost (ovpn-204-63.brq.redhat.com [10.40.204.63]) by int-mx14.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id v2DLfIH5016520 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=NO); Mon, 13 Mar 2017 17:41:20 -0400 From: Max Reitz To: qemu-block@nongnu.org Date: Mon, 13 Mar 2017 22:41:11 +0100 Message-Id: <20170313214117.27350-1-mreitz@redhat.com> In-Reply-To: <20170313214001.26339-1-mreitz@redhat.com> References: <20170313214001.26339-1-mreitz@redhat.com> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.27 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.27]); Mon, 13 Mar 2017 21:41:20 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH for-2.10 10/16] block/qcow2: Lock s->lock in preallocate() 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 , qemu-devel@nongnu.org, Max Reitz Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" preallocate() is and will be called only from places that do not lock s->lock: Currently that is qcow2_create2(), as of a future patch it will be called from qcow2_truncate(), too. It therefore makes sense to move locking that mutex into preallocate() itself. Signed-off-by: Max Reitz Reviewed-by: Stefan Hajnoczi --- block/qcow2.c | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/block/qcow2.c b/block/qcow2.c index 9abdf9e0fb..5479fed938 100644 --- a/block/qcow2.c +++ b/block/qcow2.c @@ -2036,12 +2036,15 @@ static int qcow2_change_backing_file(BlockDriverSta= te *bs, =20 static int preallocate(BlockDriverState *bs, int64_t offset, int64_t new_l= ength) { + BDRVQcow2State *s =3D bs->opaque; uint64_t bytes; uint64_t host_offset =3D 0; unsigned int cur_bytes; int ret; QCowL2Meta *meta; =20 + qemu_co_mutex_lock(&s->lock); + assert(offset <=3D new_length); bytes =3D new_length - offset; =20 @@ -2050,7 +2053,7 @@ static int preallocate(BlockDriverState *bs, int64_t = offset, int64_t new_length) ret =3D qcow2_alloc_cluster_offset(bs, offset, &cur_bytes, &host_offset, &meta); if (ret < 0) { - return ret; + goto done; } =20 while (meta) { @@ -2060,7 +2063,7 @@ static int preallocate(BlockDriverState *bs, int64_t = offset, int64_t new_length) if (ret < 0) { qcow2_free_any_clusters(bs, meta->alloc_offset, meta->nb_clusters, QCOW2_DISCARD_N= EVER); - return ret; + goto done; } =20 /* There are no dependent requests, but we need to remove our @@ -2087,11 +2090,15 @@ static int preallocate(BlockDriverState *bs, int64_= t offset, int64_t new_length) ret =3D bdrv_pwrite(bs->file, (host_offset + cur_bytes) - 1, &data, 1); if (ret < 0) { - return ret; + goto done; } } =20 - return 0; + ret =3D 0; + +done: + qemu_co_mutex_unlock(&s->lock); + return ret; } =20 static int qcow2_create2(const char *filename, int64_t total_size, @@ -2310,10 +2317,7 @@ static int qcow2_create2(const char *filename, int64= _t total_size, =20 /* And if we're supposed to preallocate metadata, do that now */ if (prealloc !=3D PREALLOC_MODE_OFF) { - BDRVQcow2State *s =3D blk_bs(blk)->opaque; - qemu_co_mutex_lock(&s->lock); ret =3D preallocate(blk_bs(blk), 0, total_size); - qemu_co_mutex_unlock(&s->lock); if (ret < 0) { error_setg_errno(errp, -ret, "Could not preallocate metadata"); goto out; --=20 2.12.0 From nobody Thu Nov 6 14:07:01 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zoho.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 148944172490932.11069819301133; Mon, 13 Mar 2017 14:48:44 -0700 (PDT) Received: from localhost ([::1]:54573 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cnXpb-0004w8-HP for importer@patchew.org; Mon, 13 Mar 2017 17:48:43 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:43947) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cnXia-0007uF-PD for qemu-devel@nongnu.org; Mon, 13 Mar 2017 17:41:30 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1cnXiX-00025v-Nq for qemu-devel@nongnu.org; Mon, 13 Mar 2017 17:41:28 -0400 Received: from mx1.redhat.com ([209.132.183.28]:52738) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1cnXiV-000256-27; Mon, 13 Mar 2017 17:41:23 -0400 Received: from int-mx10.intmail.prod.int.phx2.redhat.com (int-mx10.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 3172C85547; Mon, 13 Mar 2017 21:41:23 +0000 (UTC) Received: from localhost (ovpn-204-63.brq.redhat.com [10.40.204.63]) by int-mx10.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id v2DLfL3L000586 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=NO); Mon, 13 Mar 2017 17:41:22 -0400 From: Max Reitz To: qemu-block@nongnu.org Date: Mon, 13 Mar 2017 22:41:12 +0100 Message-Id: <20170313214117.27350-2-mreitz@redhat.com> In-Reply-To: <20170313214001.26339-1-mreitz@redhat.com> References: <20170313214001.26339-1-mreitz@redhat.com> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.23 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.28]); Mon, 13 Mar 2017 21:41:23 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH for-2.10 11/16] block/qcow2: Metadata preallocation for truncate 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 , qemu-devel@nongnu.org, Max Reitz Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" We can support PREALLOC_MODE_METADATA by invoking preallocate() in qcow2_truncate(). Signed-off-by: Max Reitz Reviewed-by: Stefan Hajnoczi --- block/qcow2.c | 24 ++++++++++++++++++++++-- 1 file changed, 22 insertions(+), 2 deletions(-) diff --git a/block/qcow2.c b/block/qcow2.c index 5479fed938..5dc95ff0a5 100644 --- a/block/qcow2.c +++ b/block/qcow2.c @@ -2531,10 +2531,11 @@ static int qcow2_truncate(BlockDriverState *bs, int= 64_t offset, PreallocMode prealloc, Error **errp) { BDRVQcow2State *s =3D bs->opaque; + uint64_t old_length; int64_t new_l1_size; int ret; =20 - if (prealloc !=3D PREALLOC_MODE_OFF) { + if (prealloc !=3D PREALLOC_MODE_OFF && prealloc !=3D PREALLOC_MODE_MET= ADATA) { error_setg(errp, "Unsupported preallocation mode '%s'", PreallocMode_lookup[prealloc]); return -ENOTSUP; @@ -2551,8 +2552,10 @@ static int qcow2_truncate(BlockDriverState *bs, int6= 4_t offset, return -ENOTSUP; } =20 + old_length =3D bs->total_sectors * 512; + /* shrinking is currently not supported */ - if (offset < bs->total_sectors * 512) { + if (offset < old_length) { error_setg(errp, "qcow2 doesn't support shrinking images yet"); return -ENOTSUP; } @@ -2564,6 +2567,23 @@ static int qcow2_truncate(BlockDriverState *bs, int6= 4_t offset, return ret; } =20 + switch (prealloc) { + case PREALLOC_MODE_OFF: + break; + + case PREALLOC_MODE_METADATA: + ret =3D preallocate(bs, old_length, offset); + if (ret < 0) { + error_setg_errno(errp, -ret, "Preallocation failed, image may = now " + "occupy more space than necessary"); + return ret; + } + break; + + default: + g_assert_not_reached(); + } + /* write updated header.size */ offset =3D cpu_to_be64(offset); ret =3D bdrv_pwrite_sync(bs->file, offsetof(QCowHeader, size), --=20 2.12.0 From nobody Thu Nov 6 14:07:01 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zoho.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1489441825012104.72008909627539; Mon, 13 Mar 2017 14:50:25 -0700 (PDT) Received: from localhost ([::1]:54581 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cnXrC-0006JU-UH for importer@patchew.org; Mon, 13 Mar 2017 17:50:23 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:43999) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cnXid-0007xN-M1 for qemu-devel@nongnu.org; Mon, 13 Mar 2017 17:41:32 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1cnXic-00027H-79 for qemu-devel@nongnu.org; Mon, 13 Mar 2017 17:41:31 -0400 Received: from mx1.redhat.com ([209.132.183.28]:58452) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1cnXiX-00025i-II; Mon, 13 Mar 2017 17:41:25 -0400 Received: from int-mx14.intmail.prod.int.phx2.redhat.com (int-mx14.intmail.prod.int.phx2.redhat.com [10.5.11.27]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 9EAAE83F46; Mon, 13 Mar 2017 21:41:25 +0000 (UTC) Received: from localhost (ovpn-204-63.brq.redhat.com [10.40.204.63]) by int-mx14.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id v2DLfNWY016561 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=NO); Mon, 13 Mar 2017 17:41:25 -0400 From: Max Reitz To: qemu-block@nongnu.org Date: Mon, 13 Mar 2017 22:41:13 +0100 Message-Id: <20170313214117.27350-3-mreitz@redhat.com> In-Reply-To: <20170313214001.26339-1-mreitz@redhat.com> References: <20170313214001.26339-1-mreitz@redhat.com> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.27 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.27]); Mon, 13 Mar 2017 21:41:25 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH for-2.10 12/16] block/qcow2: Extract qcow2_calc_size_usage() 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 , qemu-devel@nongnu.org, Max Reitz Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" We will need very similar functionality for full/falloc preallocation in qcow2_truncate(). Although we will not be able to reuse much of the actual code, it still makes sense to keep all of this in one place. Signed-off-by: Max Reitz Reviewed-by: Stefan Hajnoczi --- block/qcow2.c | 126 +++++++++++++++++++++++++++++++-----------------------= ---- 1 file changed, 68 insertions(+), 58 deletions(-) diff --git a/block/qcow2.c b/block/qcow2.c index 5dc95ff0a5..21b2b3cd53 100644 --- a/block/qcow2.c +++ b/block/qcow2.c @@ -2101,6 +2101,70 @@ done: return ret; } =20 +static uint64_t qcow2_calc_size_usage(uint64_t new_size, + int cluster_bits, int refcount_order) +{ + size_t cluster_size =3D 1u << cluster_bits; + + /* Note: The following calculation does not need to be exact; if it is= a + * bit off, either some bytes will be "leaked" (which is fine) or we + * will need to increase the file size by some bytes (which is fine, + * too, as long as the bulk is allocated here). Therefore, using + * floating point arithmetic is fine. */ + int64_t meta_size =3D 0; + uint64_t nreftablee, nrefblocke, nl1e, nl2e; + uint64_t aligned_total_size =3D align_offset(new_size, cluster_size); + int refblock_bits, refblock_size; + /* refcount entry size in bytes */ + double rces =3D (1 << refcount_order) / 8.; + + /* see qcow2_open() */ + refblock_bits =3D cluster_bits - (refcount_order - 3); + refblock_size =3D 1 << refblock_bits; + + /* header: 1 cluster */ + meta_size +=3D cluster_size; + + /* total size of L2 tables */ + nl2e =3D aligned_total_size / cluster_size; + nl2e =3D align_offset(nl2e, cluster_size / sizeof(uint64_t)); + meta_size +=3D nl2e * sizeof(uint64_t); + + /* total size of L1 tables */ + nl1e =3D nl2e * sizeof(uint64_t) / cluster_size; + nl1e =3D align_offset(nl1e, cluster_size / sizeof(uint64_t)); + meta_size +=3D nl1e * sizeof(uint64_t); + + /* total size of refcount blocks + * + * note: every host cluster is reference-counted, including metadata + * (even refcount blocks are recursively included). + * Let: + * a =3D total_size (this is the guest disk size) + * m =3D meta size not including refcount blocks and refcount tables + * c =3D cluster size + * y1 =3D number of refcount blocks entries + * y2 =3D meta size including everything + * rces =3D refcount entry size in bytes + * then, + * y1 =3D (y2 + a)/c + * y2 =3D y1 * rces + y1 * rces * sizeof(u64) / c + m + * we can get y1: + * y1 =3D (a + m) / (c - rces - rces * sizeof(u64) / c) + */ + nrefblocke =3D (aligned_total_size + meta_size + cluster_size) + / (cluster_size - rces - rces * sizeof(uint64_t) + / cluster_size); + meta_size +=3D DIV_ROUND_UP(nrefblocke, refblock_size) * cluster_size; + + /* total size of refcount tables */ + nreftablee =3D nrefblocke / refblock_size; + nreftablee =3D align_offset(nreftablee, cluster_size / sizeof(uint64_t= )); + meta_size +=3D nreftablee * sizeof(uint64_t); + + return aligned_total_size + meta_size; +} + static int qcow2_create2(const char *filename, int64_t total_size, const char *backing_file, const char *backing_for= mat, int flags, size_t cluster_size, PreallocMode prea= lloc, @@ -2139,64 +2203,10 @@ static int qcow2_create2(const char *filename, int6= 4_t total_size, int ret; =20 if (prealloc =3D=3D PREALLOC_MODE_FULL || prealloc =3D=3D PREALLOC_MOD= E_FALLOC) { - /* Note: The following calculation does not need to be exact; if i= t is a - * bit off, either some bytes will be "leaked" (which is fine) or = we - * will need to increase the file size by some bytes (which is fin= e, - * too, as long as the bulk is allocated here). Therefore, using - * floating point arithmetic is fine. */ - int64_t meta_size =3D 0; - uint64_t nreftablee, nrefblocke, nl1e, nl2e; - int64_t aligned_total_size =3D align_offset(total_size, cluster_si= ze); - int refblock_bits, refblock_size; - /* refcount entry size in bytes */ - double rces =3D (1 << refcount_order) / 8.; - - /* see qcow2_open() */ - refblock_bits =3D cluster_bits - (refcount_order - 3); - refblock_size =3D 1 << refblock_bits; - - /* header: 1 cluster */ - meta_size +=3D cluster_size; - - /* total size of L2 tables */ - nl2e =3D aligned_total_size / cluster_size; - nl2e =3D align_offset(nl2e, cluster_size / sizeof(uint64_t)); - meta_size +=3D nl2e * sizeof(uint64_t); - - /* total size of L1 tables */ - nl1e =3D nl2e * sizeof(uint64_t) / cluster_size; - nl1e =3D align_offset(nl1e, cluster_size / sizeof(uint64_t)); - meta_size +=3D nl1e * sizeof(uint64_t); - - /* total size of refcount blocks - * - * note: every host cluster is reference-counted, including metada= ta - * (even refcount blocks are recursively included). - * Let: - * a =3D total_size (this is the guest disk size) - * m =3D meta size not including refcount blocks and refcount ta= bles - * c =3D cluster size - * y1 =3D number of refcount blocks entries - * y2 =3D meta size including everything - * rces =3D refcount entry size in bytes - * then, - * y1 =3D (y2 + a)/c - * y2 =3D y1 * rces + y1 * rces * sizeof(u64) / c + m - * we can get y1: - * y1 =3D (a + m) / (c - rces - rces * sizeof(u64) / c) - */ - nrefblocke =3D (aligned_total_size + meta_size + cluster_size) - / (cluster_size - rces - rces * sizeof(uint64_t) - / cluster_size); - meta_size +=3D DIV_ROUND_UP(nrefblocke, refblock_size) * cluster_s= ize; - - /* total size of refcount tables */ - nreftablee =3D nrefblocke / refblock_size; - nreftablee =3D align_offset(nreftablee, cluster_size / sizeof(uint= 64_t)); - meta_size +=3D nreftablee * sizeof(uint64_t); - - qemu_opt_set_number(opts, BLOCK_OPT_SIZE, - aligned_total_size + meta_size, &error_abort); + uint64_t file_size =3D qcow2_calc_size_usage(total_size, cluster_b= its, + refcount_order); + + qemu_opt_set_number(opts, BLOCK_OPT_SIZE, file_size, &error_abort); qemu_opt_set(opts, BLOCK_OPT_PREALLOC, PreallocMode_lookup[preallo= c], &error_abort); } --=20 2.12.0 From nobody Thu Nov 6 14:07:01 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zoho.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1489441713556524.553515499386; Mon, 13 Mar 2017 14:48:33 -0700 (PDT) Received: from localhost ([::1]:54570 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cnXpP-0004oF-Uh for importer@patchew.org; Mon, 13 Mar 2017 17:48:32 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:44015) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cnXie-0007yZ-Q6 for qemu-devel@nongnu.org; Mon, 13 Mar 2017 17:41:34 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1cnXid-00027p-JB for qemu-devel@nongnu.org; Mon, 13 Mar 2017 17:41:32 -0400 Received: from mx1.redhat.com ([209.132.183.28]:40898) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1cnXia-00026O-2l; Mon, 13 Mar 2017 17:41:28 -0400 Received: from int-mx09.intmail.prod.int.phx2.redhat.com (int-mx09.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 3A2DEC05AA4F; Mon, 13 Mar 2017 21:41:28 +0000 (UTC) Received: from localhost (ovpn-204-63.brq.redhat.com [10.40.204.63]) by int-mx09.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id v2DLfQ2U019270 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=NO); Mon, 13 Mar 2017 17:41:27 -0400 From: Max Reitz To: qemu-block@nongnu.org Date: Mon, 13 Mar 2017 22:41:14 +0100 Message-Id: <20170313214117.27350-4-mreitz@redhat.com> In-Reply-To: <20170313214001.26339-1-mreitz@redhat.com> References: <20170313214001.26339-1-mreitz@redhat.com> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.22 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.32]); Mon, 13 Mar 2017 21:41:28 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH for-2.10 13/16] block/qcow2: qcow2_calc_size_usage() for truncate 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 , qemu-devel@nongnu.org, Max Reitz Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" This patch extends qcow2_calc_size_usage() so it can calculate the additional space needed for preallocating image growth. Signed-off-by: Max Reitz --- block/qcow2.c | 137 +++++++++++++++++++++++++++++++++++++++++-------------= ---- 1 file changed, 98 insertions(+), 39 deletions(-) diff --git a/block/qcow2.c b/block/qcow2.c index 21b2b3cd53..80fb815b15 100644 --- a/block/qcow2.c +++ b/block/qcow2.c @@ -2101,7 +2101,15 @@ done: return ret; } =20 -static uint64_t qcow2_calc_size_usage(uint64_t new_size, +/** + * Returns the number of bytes that must be allocated in the underlying fi= le + * to accomodate an image growth from @current_size to @new_size. + * + * @current_size must be 0 when creating a new image. In that case, @bs is + * ignored; otherwise it must be valid. + */ +static uint64_t qcow2_calc_size_usage(BlockDriverState *bs, + uint64_t current_size, uint64_t new_= size, int cluster_bits, int refcount_order) { size_t cluster_size =3D 1u << cluster_bits; @@ -2122,47 +2130,97 @@ static uint64_t qcow2_calc_size_usage(uint64_t new_= size, refblock_bits =3D cluster_bits - (refcount_order - 3); refblock_size =3D 1 << refblock_bits; =20 - /* header: 1 cluster */ - meta_size +=3D cluster_size; - - /* total size of L2 tables */ - nl2e =3D aligned_total_size / cluster_size; - nl2e =3D align_offset(nl2e, cluster_size / sizeof(uint64_t)); - meta_size +=3D nl2e * sizeof(uint64_t); + if (!current_size) { + /* header: 1 cluster */ + meta_size +=3D cluster_size; + + /* total size of L2 tables */ + nl2e =3D aligned_total_size / cluster_size; + nl2e =3D align_offset(nl2e, cluster_size / sizeof(uint64_t)); + meta_size +=3D nl2e * sizeof(uint64_t); + + /* total size of L1 tables */ + nl1e =3D nl2e * sizeof(uint64_t) / cluster_size; + nl1e =3D align_offset(nl1e, cluster_size / sizeof(uint64_t)); + meta_size +=3D nl1e * sizeof(uint64_t); + + /* total size of refcount blocks + * + * note: every host cluster is reference-counted, including metada= ta + * (even refcount blocks are recursively included). + * Let: + * a =3D total_size (this is the guest disk size) + * m =3D meta size not including refcount blocks and refcount ta= bles + * c =3D cluster size + * y1 =3D number of refcount blocks entries + * y2 =3D meta size including everything + * rces =3D refcount entry size in bytes + * then, + * y1 =3D (y2 + a)/c + * y2 =3D y1 * rces + y1 * rces * sizeof(u64) / c + m + * we can get y1: + * y1 =3D (a + m) / (c - rces - rces * sizeof(u64) / c) + */ + nrefblocke =3D (aligned_total_size + meta_size + cluster_size) + / (cluster_size - rces - rces * sizeof(uint64_t) + / cluster_size); + meta_size +=3D DIV_ROUND_UP(nrefblocke, refblock_size) * cluster_s= ize; =20 - /* total size of L1 tables */ - nl1e =3D nl2e * sizeof(uint64_t) / cluster_size; - nl1e =3D align_offset(nl1e, cluster_size / sizeof(uint64_t)); - meta_size +=3D nl1e * sizeof(uint64_t); + /* total size of refcount tables */ + nreftablee =3D nrefblocke / refblock_size; + nreftablee =3D align_offset(nreftablee, cluster_size / sizeof(uint= 64_t)); + meta_size +=3D nreftablee * sizeof(uint64_t); =20 - /* total size of refcount blocks - * - * note: every host cluster is reference-counted, including metadata - * (even refcount blocks are recursively included). - * Let: - * a =3D total_size (this is the guest disk size) - * m =3D meta size not including refcount blocks and refcount tables - * c =3D cluster size - * y1 =3D number of refcount blocks entries - * y2 =3D meta size including everything - * rces =3D refcount entry size in bytes - * then, - * y1 =3D (y2 + a)/c - * y2 =3D y1 * rces + y1 * rces * sizeof(u64) / c + m - * we can get y1: - * y1 =3D (a + m) / (c - rces - rces * sizeof(u64) / c) - */ - nrefblocke =3D (aligned_total_size + meta_size + cluster_size) - / (cluster_size - rces - rces * sizeof(uint64_t) - / cluster_size); - meta_size +=3D DIV_ROUND_UP(nrefblocke, refblock_size) * cluster_size; + return aligned_total_size + meta_size; + } else { + BDRVQcow2State *s =3D bs->opaque; + uint64_t aligned_cur_size =3D align_offset(current_size, cluster_s= ize); + uint64_t creftable_length; + uint64_t i; + + /* new total size of L2 tables */ + nl2e =3D aligned_total_size / cluster_size; + nl2e =3D align_offset(nl2e, cluster_size / sizeof(uint64_t)); + meta_size +=3D nl2e * sizeof(uint64_t); + + /* Subtract L2 tables which are already present */ + for (i =3D 0; i < s->l1_size; i++) { + if (s->l1_table[i] & L1E_OFFSET_MASK) { + meta_size -=3D cluster_size; + } + } =20 - /* total size of refcount tables */ - nreftablee =3D nrefblocke / refblock_size; - nreftablee =3D align_offset(nreftablee, cluster_size / sizeof(uint64_t= )); - meta_size +=3D nreftablee * sizeof(uint64_t); + /* Do not add L1 table size because the only caller of this path + * (qcow2_truncate) has increased its size already. */ =20 - return aligned_total_size + meta_size; + /* Calculate size of the additional refblocks (this assumes that a= ll of + * the existing image is covered by refblocks, which is extremely + * likely); this may result in overallocation because parts of the= newly + * added space may be covered by existing refblocks, but that is f= ine. + * + * This only considers the newly added space. Since we cannot upda= te the + * reftable in-place, we will have to able to store both the old a= nd the + * new one at the same time, though. Therefore, we need to add the= size + * of the old reftable here. + */ + creftable_length =3D ROUND_UP(s->refcount_table_size * sizeof(uint= 64_t), + cluster_size); + nrefblocke =3D ((aligned_total_size - aligned_cur_size) + meta_siz= e + + creftable_length + cluster_size) + / (cluster_size - rces - + rces * sizeof(uint64_t) / cluster_size); + meta_size +=3D DIV_ROUND_UP(nrefblocke, refblock_size) * cluster_s= ize; + + /* total size of the new refcount table (again, may be too much be= cause + * it assumes that the new area is not covered by any refcount blo= cks + * yet) */ + nreftablee =3D s->max_refcount_table_index + 1 + + nrefblocke / refblock_size; + nreftablee =3D align_offset(nreftablee, cluster_size / sizeof(uint= 64_t)); + meta_size +=3D nreftablee * sizeof(uint64_t); + + return (aligned_total_size - aligned_cur_size) + meta_size; + } } =20 static int qcow2_create2(const char *filename, int64_t total_size, @@ -2203,7 +2261,8 @@ static int qcow2_create2(const char *filename, int64_= t total_size, int ret; =20 if (prealloc =3D=3D PREALLOC_MODE_FULL || prealloc =3D=3D PREALLOC_MOD= E_FALLOC) { - uint64_t file_size =3D qcow2_calc_size_usage(total_size, cluster_b= its, + uint64_t file_size =3D qcow2_calc_size_usage(NULL, 0, total_size, + cluster_bits, refcount_order); =20 qemu_opt_set_number(opts, BLOCK_OPT_SIZE, file_size, &error_abort); --=20 2.12.0 From nobody Thu Nov 6 14:07:01 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zoho.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1489441961848736.4728247411074; Mon, 13 Mar 2017 14:52:41 -0700 (PDT) Received: from localhost ([::1]:54597 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cnXtQ-0008IN-MA for importer@patchew.org; Mon, 13 Mar 2017 17:52:40 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:44035) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cnXii-000831-LH for qemu-devel@nongnu.org; Mon, 13 Mar 2017 17:41:39 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1cnXie-00028L-Jb for qemu-devel@nongnu.org; Mon, 13 Mar 2017 17:41:33 -0400 Received: from mx1.redhat.com ([209.132.183.28]:50764) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1cnXic-000276-FC; Mon, 13 Mar 2017 17:41:30 -0400 Received: from int-mx10.intmail.prod.int.phx2.redhat.com (int-mx10.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 97845C04B920; Mon, 13 Mar 2017 21:41:30 +0000 (UTC) Received: from localhost (ovpn-204-63.brq.redhat.com [10.40.204.63]) by int-mx10.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id v2DLfSbY000658 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=NO); Mon, 13 Mar 2017 17:41:30 -0400 From: Max Reitz To: qemu-block@nongnu.org Date: Mon, 13 Mar 2017 22:41:15 +0100 Message-Id: <20170313214117.27350-5-mreitz@redhat.com> In-Reply-To: <20170313214001.26339-1-mreitz@redhat.com> References: <20170313214001.26339-1-mreitz@redhat.com> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.23 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.31]); Mon, 13 Mar 2017 21:41:30 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH for-2.10 14/16] block/qcow2: falloc/full preallocating growth 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 , qemu-devel@nongnu.org, Max Reitz Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Implement the preallocation modes falloc and full for growing qcow2 images. Signed-off-by: Max Reitz --- block/qcow2.c | 36 +++++++++++++++++++++++++++++++++++- 1 file changed, 35 insertions(+), 1 deletion(-) diff --git a/block/qcow2.c b/block/qcow2.c index 80fb815b15..b6b08d70da 100644 --- a/block/qcow2.c +++ b/block/qcow2.c @@ -2604,7 +2604,9 @@ static int qcow2_truncate(BlockDriverState *bs, int64= _t offset, int64_t new_l1_size; int ret; =20 - if (prealloc !=3D PREALLOC_MODE_OFF && prealloc !=3D PREALLOC_MODE_MET= ADATA) { + if (prealloc !=3D PREALLOC_MODE_OFF && prealloc !=3D PREALLOC_MODE_MET= ADATA && + prealloc !=3D PREALLOC_MODE_FALLOC && prealloc !=3D PREALLOC_MODE_= FULL) + { error_setg(errp, "Unsupported preallocation mode '%s'", PreallocMode_lookup[prealloc]); return -ENOTSUP; @@ -2649,6 +2651,38 @@ static int qcow2_truncate(BlockDriverState *bs, int6= 4_t offset, } break; =20 + case PREALLOC_MODE_FALLOC: + case PREALLOC_MODE_FULL: + { + uint64_t additional_size =3D qcow2_calc_size_usage(bs, old_length,= offset, + s->cluster_bits, + s->refcount_order= ); + int64_t old_file_length =3D bdrv_getlength(bs->file->bs); + if (old_file_length < 0) { + error_setg(errp, "Failed to inquire file length"); + return old_file_length; + } + + old_file_length =3D ROUND_UP(old_file_length, s->cluster_size); + + ret =3D bdrv_truncate(bs->file, old_file_length + additional_size, + prealloc, errp); + if (ret < 0) { + error_prepend(errp, "Failed to resize underlying file"); + return ret; + } + + /* Ensure that preallocation is done in the preallocated area */ + s->free_cluster_index =3D old_file_length / s->cluster_size; + ret =3D preallocate(bs, old_length, offset); + if (ret < 0) { + error_setg_errno(errp, -ret, "Preallocation failed, image may = now " + "occupy more space than necessary"); + return ret; + } + break; + } + default: g_assert_not_reached(); } --=20 2.12.0 From nobody Thu Nov 6 14:07:01 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zoho.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1489442040818850.6544429789377; Mon, 13 Mar 2017 14:54:00 -0700 (PDT) Received: from localhost ([::1]:54607 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cnXuh-0001A7-Ed for importer@patchew.org; Mon, 13 Mar 2017 17:53:59 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:44096) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cnXin-00088d-HA for qemu-devel@nongnu.org; Mon, 13 Mar 2017 17:41:43 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1cnXim-0002Cy-37 for qemu-devel@nongnu.org; Mon, 13 Mar 2017 17:41:41 -0400 Received: from mx1.redhat.com ([209.132.183.28]:42846) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1cnXif-00028I-0S; Mon, 13 Mar 2017 17:41:33 -0400 Received: from int-mx13.intmail.prod.int.phx2.redhat.com (int-mx13.intmail.prod.int.phx2.redhat.com [10.5.11.26]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 1D84B81F07; Mon, 13 Mar 2017 21:41:33 +0000 (UTC) Received: from localhost (ovpn-204-63.brq.redhat.com [10.40.204.63]) by int-mx13.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id v2DLfVk6026451 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=NO); Mon, 13 Mar 2017 17:41:32 -0400 From: Max Reitz To: qemu-block@nongnu.org Date: Mon, 13 Mar 2017 22:41:16 +0100 Message-Id: <20170313214117.27350-6-mreitz@redhat.com> In-Reply-To: <20170313214001.26339-1-mreitz@redhat.com> References: <20170313214001.26339-1-mreitz@redhat.com> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.26 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.25]); Mon, 13 Mar 2017 21:41:33 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH for-2.10 15/16] iotests: Add preallocated resize test for raw 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 , qemu-devel@nongnu.org, Max Reitz Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Signed-off-by: Max Reitz Reviewed-by: Stefan Hajnoczi --- tests/qemu-iotests/106 | 92 ++++++++++++++++++++++++++++++++++++++++++= ++++ tests/qemu-iotests/106.out | 50 +++++++++++++++++++++++++ tests/qemu-iotests/group | 1 + 3 files changed, 143 insertions(+) create mode 100755 tests/qemu-iotests/106 create mode 100644 tests/qemu-iotests/106.out diff --git a/tests/qemu-iotests/106 b/tests/qemu-iotests/106 new file mode 100755 index 0000000000..32649578fb --- /dev/null +++ b/tests/qemu-iotests/106 @@ -0,0 +1,92 @@ +#!/bin/bash +# +# Test preallocated resize of raw images +# +# Copyright (C) 2017 Red Hat, Inc. +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 2 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . +# + +# creator +owner=3Dmreitz@redhat.com + +seq=3D$(basename $0) +echo "QA output created by $seq" + +here=3D$PWD +status=3D1 # failure is the default! + +_cleanup() +{ + _cleanup_test_img +} +trap "_cleanup; exit \$status" 0 1 2 3 15 + +# get standard environment and filters +. ./common.rc +. ./common.filter + +_supported_fmt raw +_supported_proto file +_supported_os Linux + +# in kB +CREATION_SIZE=3D128 +GROWTH_SIZE=3D256 + +echo '=3D=3D=3D Testing image growth =3D=3D=3D' + +for create_mode in off falloc full; do + for growth_mode in off falloc full; do + echo + echo "--- create_mode=3D$create_mode growth_mode=3D$growth_mode --= -" + + IMGOPTS=3D"preallocation=3D$create_mode" _make_test_img ${CREATION= _SIZE}K + $QEMU_IMG resize -f "$IMGFMT" --preallocation=3D$growth_mode "$TES= T_IMG" +${GROWTH_SIZE}K + + expected_size=3D0 + if [ $create_mode !=3D off ]; then + expected_size=3D$CREATION_SIZE + fi + if [ $growth_mode !=3D off ]; then + expected_size=3D$((expected_size + $GROWTH_SIZE)) + fi + + actual_size=3D$($QEMU_IMG info -f "$IMGFMT" "$TEST_IMG" | grep 'di= sk size') + actual_size=3D$(echo "$actual_size" | sed -e 's/^[^0-9]*\([0-9]\+\= ).*$/\1/') + + # The actual size may exceed the expected size, depending on the f= ile + # system. Therefore we just test that the actual size is at least = what + # we expect. + if [ $actual_size -lt $expected_size ]; then + echo "ERROR: Image should have at least ${expected_size}K, but= has ${actual_size}K" + fi + done +done + +echo +echo '=3D=3D=3D Testing image shrinking =3D=3D=3D' + +# None of this should work except for "off", because other modes cannot be= used +# for shrinking +for growth_mode in falloc full off; do + echo + echo "--- growth_mode=3D$growth_mode ---" + $QEMU_IMG resize -f "$IMGFMT" --preallocation=3D$growth_mode "$TEST_IM= G" -${GROWTH_SIZE}K +done + +# success, all done +echo '*** done' +rm -f $seq.full +status=3D0 diff --git a/tests/qemu-iotests/106.out b/tests/qemu-iotests/106.out new file mode 100644 index 0000000000..0a42312301 --- /dev/null +++ b/tests/qemu-iotests/106.out @@ -0,0 +1,50 @@ +QA output created by 106 +=3D=3D=3D Testing image growth =3D=3D=3D + +--- create_mode=3Doff growth_mode=3Doff --- +Formatting 'TEST_DIR/t.IMGFMT', fmt=3DIMGFMT size=3D131072 preallocation= =3Doff +Image resized. + +--- create_mode=3Doff growth_mode=3Dfalloc --- +Formatting 'TEST_DIR/t.IMGFMT', fmt=3DIMGFMT size=3D131072 preallocation= =3Doff +Image resized. + +--- create_mode=3Doff growth_mode=3Dfull --- +Formatting 'TEST_DIR/t.IMGFMT', fmt=3DIMGFMT size=3D131072 preallocation= =3Doff +Image resized. + +--- create_mode=3Dfalloc growth_mode=3Doff --- +Formatting 'TEST_DIR/t.IMGFMT', fmt=3DIMGFMT size=3D131072 preallocation= =3Dfalloc +Image resized. + +--- create_mode=3Dfalloc growth_mode=3Dfalloc --- +Formatting 'TEST_DIR/t.IMGFMT', fmt=3DIMGFMT size=3D131072 preallocation= =3Dfalloc +Image resized. + +--- create_mode=3Dfalloc growth_mode=3Dfull --- +Formatting 'TEST_DIR/t.IMGFMT', fmt=3DIMGFMT size=3D131072 preallocation= =3Dfalloc +Image resized. + +--- create_mode=3Dfull growth_mode=3Doff --- +Formatting 'TEST_DIR/t.IMGFMT', fmt=3DIMGFMT size=3D131072 preallocation= =3Dfull +Image resized. + +--- create_mode=3Dfull growth_mode=3Dfalloc --- +Formatting 'TEST_DIR/t.IMGFMT', fmt=3DIMGFMT size=3D131072 preallocation= =3Dfull +Image resized. + +--- create_mode=3Dfull growth_mode=3Dfull --- +Formatting 'TEST_DIR/t.IMGFMT', fmt=3DIMGFMT size=3D131072 preallocation= =3Dfull +Image resized. + +=3D=3D=3D Testing image shrinking =3D=3D=3D + +--- growth_mode=3Dfalloc --- +qemu-img: Preallocation can only be used for growing images + +--- growth_mode=3Dfull --- +qemu-img: Preallocation can only be used for growing images + +--- growth_mode=3Doff --- +Image resized. +*** done diff --git a/tests/qemu-iotests/group b/tests/qemu-iotests/group index 1f4bf03185..1a89bebe14 100644 --- a/tests/qemu-iotests/group +++ b/tests/qemu-iotests/group @@ -112,6 +112,7 @@ 103 rw auto quick 104 rw auto 105 rw auto quick +106 rw auto quick 107 rw auto quick 108 rw auto quick 109 rw auto --=20 2.12.0 From nobody Thu Nov 6 14:07:01 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zoho.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1489441733803467.7061397693967; Mon, 13 Mar 2017 14:48:53 -0700 (PDT) Received: from localhost ([::1]:54575 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cnXpk-00052M-Ar for importer@patchew.org; Mon, 13 Mar 2017 17:48:52 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:44125) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cnXis-0008DC-KN for qemu-devel@nongnu.org; Mon, 13 Mar 2017 17:41:49 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1cnXip-0002EG-DP for qemu-devel@nongnu.org; Mon, 13 Mar 2017 17:41:46 -0400 Received: from mx1.redhat.com ([209.132.183.28]:52806) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1cnXii-00029D-Ma; Mon, 13 Mar 2017 17:41:36 -0400 Received: from int-mx10.intmail.prod.int.phx2.redhat.com (int-mx10.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id F386C85547; Mon, 13 Mar 2017 21:41:35 +0000 (UTC) Received: from localhost (ovpn-204-63.brq.redhat.com [10.40.204.63]) by int-mx10.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id v2DLfXbk000684 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=NO); Mon, 13 Mar 2017 17:41:35 -0400 From: Max Reitz To: qemu-block@nongnu.org Date: Mon, 13 Mar 2017 22:41:17 +0100 Message-Id: <20170313214117.27350-7-mreitz@redhat.com> In-Reply-To: <20170313214001.26339-1-mreitz@redhat.com> References: <20170313214001.26339-1-mreitz@redhat.com> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.23 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.28]); Mon, 13 Mar 2017 21:41:36 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH for-2.10 16/16] iotests: Add preallocated growth test for qcow2 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 , qemu-devel@nongnu.org, Max Reitz Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Signed-off-by: Max Reitz Reviewed-by: Stefan Hajnoczi --- tests/qemu-iotests/125 | 130 +++++++++++++++ tests/qemu-iotests/125.out | 386 +++++++++++++++++++++++++++++++++++++++++= ++++ tests/qemu-iotests/group | 1 + 3 files changed, 517 insertions(+) create mode 100755 tests/qemu-iotests/125 create mode 100644 tests/qemu-iotests/125.out diff --git a/tests/qemu-iotests/125 b/tests/qemu-iotests/125 new file mode 100755 index 0000000000..9424313e82 --- /dev/null +++ b/tests/qemu-iotests/125 @@ -0,0 +1,130 @@ +#!/bin/bash +# +# Test preallocated growth of qcow2 images +# +# Copyright (C) 2017 Red Hat, Inc. +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 2 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . +# + +# creator +owner=3Dmreitz@redhat.com + +seq=3D$(basename $0) +echo "QA output created by $seq" + +here=3D$PWD +status=3D1 # failure is the default! + +_cleanup() +{ + _cleanup_test_img +} +trap "_cleanup; exit \$status" 0 1 2 3 15 + +get_image_size_on_host() +{ + $QEMU_IMG info -f "$IMGFMT" "$TEST_IMG" | grep "disk size" \ + | sed -e 's/^[^0-9]*\([0-9]\+\).*$/\1/' +} + +# get standard environment and filters +. ./common.rc +. ./common.filter + +_supported_fmt qcow2 +_supported_proto file +_supported_os Linux + +if [ -z "$TEST_IMG_FILE" ]; then + TEST_IMG_FILE=3D$TEST_IMG +fi + +# Generally, we create some image with or without existing preallocation a= nd +# then resize it. Then we write some data into the image and verify that i= ts +# size does not change if we have used preallocation. + +# With a cluster size of 512 B, one L2 table covers 64 * 512 B =3D 32 kB. +# One cluster of the L1 table covers 64 * 32 kB =3D 2 MB. +# There are multiple cases we want to test: +# (1) Grow an image without having to allocate a new L2 table. +# (2) Grow an image, having to allocate a new L2 table. +# (3) Grow an image, having to grow the L1 table. +# Therefore, we create an image that is 48 kB below 2 MB. Then: +# (1) We resize it to 2 MB - 32 kB. (+ 16 kB) +# (2) We resize it to 2 MB. (+ 48 kB) +# (3) We resize it to 2 MB + 32 kB. (+ 80 kB) + +# in B +CREATION_SIZE=3D$((2 * 1024 * 1024 - 48 * 1024)) + +# in kB +for GROWTH_SIZE in 16 48 80; do + for create_mode in off metadata falloc full; do + for growth_mode in off metadata falloc full; do + echo "--- growth_size=3D$GROWTH_SIZE create_mode=3D$create_mod= e growth_mode=3D$growth_mode ---" + + IMGOPTS=3D"preallocation=3D$create_mode,cluster_size=3D512" _m= ake_test_img ${CREATION_SIZE} + $QEMU_IMG resize -f "$IMGFMT" --preallocation=3D$growth_mode "= $TEST_IMG" +${GROWTH_SIZE}K + + host_size_0=3D$(get_image_size_on_host) + file_length_0=3D$(stat -c '%s' "$TEST_IMG_FILE") + + $QEMU_IO -c "write 0 $CREATION_SIZE" "$TEST_IMG" | _filter_qem= u_io + + host_size_1=3D$(get_image_size_on_host) + file_length_1=3D$(stat -c '%s' "$TEST_IMG_FILE") + + $QEMU_IO -c "write $CREATION_SIZE ${GROWTH_SIZE}K" "$TEST_IMG"= | _filter_qemu_io + + host_size_2=3D$(get_image_size_on_host) + file_length_2=3D$(stat -c '%s' "$TEST_IMG_FILE") + + # Test creation preallocation: Compare #0 against #1 + if [ $create_mode !=3D off ]; then + # The image length should not have grown + if [ $file_length_1 -gt $file_length_0 ]; then + echo "ERROR (create): Image length has grown from $fil= e_length_0 to $file_length_1" + fi + if [ $create_mode !=3D metadata ]; then + # The host size should not have grown either + if [ $host_size_1 -gt $host_size_0 ]; then + echo "ERROR (create): Host size has grown from $ho= st_size_0 to $host_size_1" + fi + fi + fi + + # Test resize preallocation: Compare #2 against #1 + if [ $growth_mode !=3D off ]; then + # The image length should not have grown + if [ $file_length_2 -gt $file_length_1 ]; then + echo "ERROR (grow): Image length has grown from $file_= length_1 to $file_length_2" + fi + if [ $create_mode !=3D metadata ]; then + # The host size should not have grown either + if [ $host_size_2 -gt $host_size_1 ]; then + echo "ERROR (grow): Host size has grown from $host= _size_1 to $host_size_2" + fi + fi + fi + + echo + done + done +done + +# success, all done +echo '*** done' +rm -f $seq.full +status=3D0 diff --git a/tests/qemu-iotests/125.out b/tests/qemu-iotests/125.out new file mode 100644 index 0000000000..3f4d6e31a6 --- /dev/null +++ b/tests/qemu-iotests/125.out @@ -0,0 +1,386 @@ +QA output created by 125 +--- growth_size=3D16 create_mode=3Doff growth_mode=3Doff --- +Formatting 'TEST_DIR/t.IMGFMT', fmt=3DIMGFMT size=3D2048000 preallocation= =3Doff +Image resized. +wrote 2048000/2048000 bytes at offset 0 +1.953 MiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec) +wrote 16384/16384 bytes at offset 2048000 +16 KiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec) + +--- growth_size=3D16 create_mode=3Doff growth_mode=3Dmetadata --- +Formatting 'TEST_DIR/t.IMGFMT', fmt=3DIMGFMT size=3D2048000 preallocation= =3Doff +Image resized. +wrote 2048000/2048000 bytes at offset 0 +1.953 MiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec) +wrote 16384/16384 bytes at offset 2048000 +16 KiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec) + +--- growth_size=3D16 create_mode=3Doff growth_mode=3Dfalloc --- +Formatting 'TEST_DIR/t.IMGFMT', fmt=3DIMGFMT size=3D2048000 preallocation= =3Doff +Image resized. +wrote 2048000/2048000 bytes at offset 0 +1.953 MiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec) +wrote 16384/16384 bytes at offset 2048000 +16 KiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec) + +--- growth_size=3D16 create_mode=3Doff growth_mode=3Dfull --- +Formatting 'TEST_DIR/t.IMGFMT', fmt=3DIMGFMT size=3D2048000 preallocation= =3Doff +Image resized. +wrote 2048000/2048000 bytes at offset 0 +1.953 MiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec) +wrote 16384/16384 bytes at offset 2048000 +16 KiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec) + +--- growth_size=3D16 create_mode=3Dmetadata growth_mode=3Doff --- +Formatting 'TEST_DIR/t.IMGFMT', fmt=3DIMGFMT size=3D2048000 preallocation= =3Dmetadata +Image resized. +wrote 2048000/2048000 bytes at offset 0 +1.953 MiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec) +wrote 16384/16384 bytes at offset 2048000 +16 KiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec) + +--- growth_size=3D16 create_mode=3Dmetadata growth_mode=3Dmetadata --- +Formatting 'TEST_DIR/t.IMGFMT', fmt=3DIMGFMT size=3D2048000 preallocation= =3Dmetadata +Image resized. +wrote 2048000/2048000 bytes at offset 0 +1.953 MiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec) +wrote 16384/16384 bytes at offset 2048000 +16 KiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec) + +--- growth_size=3D16 create_mode=3Dmetadata growth_mode=3Dfalloc --- +Formatting 'TEST_DIR/t.IMGFMT', fmt=3DIMGFMT size=3D2048000 preallocation= =3Dmetadata +Image resized. +wrote 2048000/2048000 bytes at offset 0 +1.953 MiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec) +wrote 16384/16384 bytes at offset 2048000 +16 KiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec) + +--- growth_size=3D16 create_mode=3Dmetadata growth_mode=3Dfull --- +Formatting 'TEST_DIR/t.IMGFMT', fmt=3DIMGFMT size=3D2048000 preallocation= =3Dmetadata +Image resized. +wrote 2048000/2048000 bytes at offset 0 +1.953 MiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec) +wrote 16384/16384 bytes at offset 2048000 +16 KiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec) + +--- growth_size=3D16 create_mode=3Dfalloc growth_mode=3Doff --- +Formatting 'TEST_DIR/t.IMGFMT', fmt=3DIMGFMT size=3D2048000 preallocation= =3Dfalloc +Image resized. +wrote 2048000/2048000 bytes at offset 0 +1.953 MiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec) +wrote 16384/16384 bytes at offset 2048000 +16 KiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec) + +--- growth_size=3D16 create_mode=3Dfalloc growth_mode=3Dmetadata --- +Formatting 'TEST_DIR/t.IMGFMT', fmt=3DIMGFMT size=3D2048000 preallocation= =3Dfalloc +Image resized. +wrote 2048000/2048000 bytes at offset 0 +1.953 MiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec) +wrote 16384/16384 bytes at offset 2048000 +16 KiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec) + +--- growth_size=3D16 create_mode=3Dfalloc growth_mode=3Dfalloc --- +Formatting 'TEST_DIR/t.IMGFMT', fmt=3DIMGFMT size=3D2048000 preallocation= =3Dfalloc +Image resized. +wrote 2048000/2048000 bytes at offset 0 +1.953 MiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec) +wrote 16384/16384 bytes at offset 2048000 +16 KiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec) + +--- growth_size=3D16 create_mode=3Dfalloc growth_mode=3Dfull --- +Formatting 'TEST_DIR/t.IMGFMT', fmt=3DIMGFMT size=3D2048000 preallocation= =3Dfalloc +Image resized. +wrote 2048000/2048000 bytes at offset 0 +1.953 MiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec) +wrote 16384/16384 bytes at offset 2048000 +16 KiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec) + +--- growth_size=3D16 create_mode=3Dfull growth_mode=3Doff --- +Formatting 'TEST_DIR/t.IMGFMT', fmt=3DIMGFMT size=3D2048000 preallocation= =3Dfull +Image resized. +wrote 2048000/2048000 bytes at offset 0 +1.953 MiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec) +wrote 16384/16384 bytes at offset 2048000 +16 KiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec) + +--- growth_size=3D16 create_mode=3Dfull growth_mode=3Dmetadata --- +Formatting 'TEST_DIR/t.IMGFMT', fmt=3DIMGFMT size=3D2048000 preallocation= =3Dfull +Image resized. +wrote 2048000/2048000 bytes at offset 0 +1.953 MiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec) +wrote 16384/16384 bytes at offset 2048000 +16 KiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec) + +--- growth_size=3D16 create_mode=3Dfull growth_mode=3Dfalloc --- +Formatting 'TEST_DIR/t.IMGFMT', fmt=3DIMGFMT size=3D2048000 preallocation= =3Dfull +Image resized. +wrote 2048000/2048000 bytes at offset 0 +1.953 MiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec) +wrote 16384/16384 bytes at offset 2048000 +16 KiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec) + +--- growth_size=3D16 create_mode=3Dfull growth_mode=3Dfull --- +Formatting 'TEST_DIR/t.IMGFMT', fmt=3DIMGFMT size=3D2048000 preallocation= =3Dfull +Image resized. +wrote 2048000/2048000 bytes at offset 0 +1.953 MiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec) +wrote 16384/16384 bytes at offset 2048000 +16 KiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec) + +--- growth_size=3D48 create_mode=3Doff growth_mode=3Doff --- +Formatting 'TEST_DIR/t.IMGFMT', fmt=3DIMGFMT size=3D2048000 preallocation= =3Doff +Image resized. +wrote 2048000/2048000 bytes at offset 0 +1.953 MiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec) +wrote 49152/49152 bytes at offset 2048000 +48 KiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec) + +--- growth_size=3D48 create_mode=3Doff growth_mode=3Dmetadata --- +Formatting 'TEST_DIR/t.IMGFMT', fmt=3DIMGFMT size=3D2048000 preallocation= =3Doff +Image resized. +wrote 2048000/2048000 bytes at offset 0 +1.953 MiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec) +wrote 49152/49152 bytes at offset 2048000 +48 KiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec) + +--- growth_size=3D48 create_mode=3Doff growth_mode=3Dfalloc --- +Formatting 'TEST_DIR/t.IMGFMT', fmt=3DIMGFMT size=3D2048000 preallocation= =3Doff +Image resized. +wrote 2048000/2048000 bytes at offset 0 +1.953 MiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec) +wrote 49152/49152 bytes at offset 2048000 +48 KiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec) + +--- growth_size=3D48 create_mode=3Doff growth_mode=3Dfull --- +Formatting 'TEST_DIR/t.IMGFMT', fmt=3DIMGFMT size=3D2048000 preallocation= =3Doff +Image resized. +wrote 2048000/2048000 bytes at offset 0 +1.953 MiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec) +wrote 49152/49152 bytes at offset 2048000 +48 KiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec) + +--- growth_size=3D48 create_mode=3Dmetadata growth_mode=3Doff --- +Formatting 'TEST_DIR/t.IMGFMT', fmt=3DIMGFMT size=3D2048000 preallocation= =3Dmetadata +Image resized. +wrote 2048000/2048000 bytes at offset 0 +1.953 MiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec) +wrote 49152/49152 bytes at offset 2048000 +48 KiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec) + +--- growth_size=3D48 create_mode=3Dmetadata growth_mode=3Dmetadata --- +Formatting 'TEST_DIR/t.IMGFMT', fmt=3DIMGFMT size=3D2048000 preallocation= =3Dmetadata +Image resized. +wrote 2048000/2048000 bytes at offset 0 +1.953 MiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec) +wrote 49152/49152 bytes at offset 2048000 +48 KiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec) + +--- growth_size=3D48 create_mode=3Dmetadata growth_mode=3Dfalloc --- +Formatting 'TEST_DIR/t.IMGFMT', fmt=3DIMGFMT size=3D2048000 preallocation= =3Dmetadata +Image resized. +wrote 2048000/2048000 bytes at offset 0 +1.953 MiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec) +wrote 49152/49152 bytes at offset 2048000 +48 KiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec) + +--- growth_size=3D48 create_mode=3Dmetadata growth_mode=3Dfull --- +Formatting 'TEST_DIR/t.IMGFMT', fmt=3DIMGFMT size=3D2048000 preallocation= =3Dmetadata +Image resized. +wrote 2048000/2048000 bytes at offset 0 +1.953 MiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec) +wrote 49152/49152 bytes at offset 2048000 +48 KiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec) + +--- growth_size=3D48 create_mode=3Dfalloc growth_mode=3Doff --- +Formatting 'TEST_DIR/t.IMGFMT', fmt=3DIMGFMT size=3D2048000 preallocation= =3Dfalloc +Image resized. +wrote 2048000/2048000 bytes at offset 0 +1.953 MiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec) +wrote 49152/49152 bytes at offset 2048000 +48 KiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec) + +--- growth_size=3D48 create_mode=3Dfalloc growth_mode=3Dmetadata --- +Formatting 'TEST_DIR/t.IMGFMT', fmt=3DIMGFMT size=3D2048000 preallocation= =3Dfalloc +Image resized. +wrote 2048000/2048000 bytes at offset 0 +1.953 MiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec) +wrote 49152/49152 bytes at offset 2048000 +48 KiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec) + +--- growth_size=3D48 create_mode=3Dfalloc growth_mode=3Dfalloc --- +Formatting 'TEST_DIR/t.IMGFMT', fmt=3DIMGFMT size=3D2048000 preallocation= =3Dfalloc +Image resized. +wrote 2048000/2048000 bytes at offset 0 +1.953 MiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec) +wrote 49152/49152 bytes at offset 2048000 +48 KiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec) + +--- growth_size=3D48 create_mode=3Dfalloc growth_mode=3Dfull --- +Formatting 'TEST_DIR/t.IMGFMT', fmt=3DIMGFMT size=3D2048000 preallocation= =3Dfalloc +Image resized. +wrote 2048000/2048000 bytes at offset 0 +1.953 MiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec) +wrote 49152/49152 bytes at offset 2048000 +48 KiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec) + +--- growth_size=3D48 create_mode=3Dfull growth_mode=3Doff --- +Formatting 'TEST_DIR/t.IMGFMT', fmt=3DIMGFMT size=3D2048000 preallocation= =3Dfull +Image resized. +wrote 2048000/2048000 bytes at offset 0 +1.953 MiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec) +wrote 49152/49152 bytes at offset 2048000 +48 KiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec) + +--- growth_size=3D48 create_mode=3Dfull growth_mode=3Dmetadata --- +Formatting 'TEST_DIR/t.IMGFMT', fmt=3DIMGFMT size=3D2048000 preallocation= =3Dfull +Image resized. +wrote 2048000/2048000 bytes at offset 0 +1.953 MiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec) +wrote 49152/49152 bytes at offset 2048000 +48 KiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec) + +--- growth_size=3D48 create_mode=3Dfull growth_mode=3Dfalloc --- +Formatting 'TEST_DIR/t.IMGFMT', fmt=3DIMGFMT size=3D2048000 preallocation= =3Dfull +Image resized. +wrote 2048000/2048000 bytes at offset 0 +1.953 MiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec) +wrote 49152/49152 bytes at offset 2048000 +48 KiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec) + +--- growth_size=3D48 create_mode=3Dfull growth_mode=3Dfull --- +Formatting 'TEST_DIR/t.IMGFMT', fmt=3DIMGFMT size=3D2048000 preallocation= =3Dfull +Image resized. +wrote 2048000/2048000 bytes at offset 0 +1.953 MiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec) +wrote 49152/49152 bytes at offset 2048000 +48 KiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec) + +--- growth_size=3D80 create_mode=3Doff growth_mode=3Doff --- +Formatting 'TEST_DIR/t.IMGFMT', fmt=3DIMGFMT size=3D2048000 preallocation= =3Doff +Image resized. +wrote 2048000/2048000 bytes at offset 0 +1.953 MiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec) +wrote 81920/81920 bytes at offset 2048000 +80 KiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec) + +--- growth_size=3D80 create_mode=3Doff growth_mode=3Dmetadata --- +Formatting 'TEST_DIR/t.IMGFMT', fmt=3DIMGFMT size=3D2048000 preallocation= =3Doff +Image resized. +wrote 2048000/2048000 bytes at offset 0 +1.953 MiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec) +wrote 81920/81920 bytes at offset 2048000 +80 KiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec) + +--- growth_size=3D80 create_mode=3Doff growth_mode=3Dfalloc --- +Formatting 'TEST_DIR/t.IMGFMT', fmt=3DIMGFMT size=3D2048000 preallocation= =3Doff +Image resized. +wrote 2048000/2048000 bytes at offset 0 +1.953 MiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec) +wrote 81920/81920 bytes at offset 2048000 +80 KiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec) + +--- growth_size=3D80 create_mode=3Doff growth_mode=3Dfull --- +Formatting 'TEST_DIR/t.IMGFMT', fmt=3DIMGFMT size=3D2048000 preallocation= =3Doff +Image resized. +wrote 2048000/2048000 bytes at offset 0 +1.953 MiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec) +wrote 81920/81920 bytes at offset 2048000 +80 KiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec) + +--- growth_size=3D80 create_mode=3Dmetadata growth_mode=3Doff --- +Formatting 'TEST_DIR/t.IMGFMT', fmt=3DIMGFMT size=3D2048000 preallocation= =3Dmetadata +Image resized. +wrote 2048000/2048000 bytes at offset 0 +1.953 MiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec) +wrote 81920/81920 bytes at offset 2048000 +80 KiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec) + +--- growth_size=3D80 create_mode=3Dmetadata growth_mode=3Dmetadata --- +Formatting 'TEST_DIR/t.IMGFMT', fmt=3DIMGFMT size=3D2048000 preallocation= =3Dmetadata +Image resized. +wrote 2048000/2048000 bytes at offset 0 +1.953 MiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec) +wrote 81920/81920 bytes at offset 2048000 +80 KiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec) + +--- growth_size=3D80 create_mode=3Dmetadata growth_mode=3Dfalloc --- +Formatting 'TEST_DIR/t.IMGFMT', fmt=3DIMGFMT size=3D2048000 preallocation= =3Dmetadata +Image resized. +wrote 2048000/2048000 bytes at offset 0 +1.953 MiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec) +wrote 81920/81920 bytes at offset 2048000 +80 KiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec) + +--- growth_size=3D80 create_mode=3Dmetadata growth_mode=3Dfull --- +Formatting 'TEST_DIR/t.IMGFMT', fmt=3DIMGFMT size=3D2048000 preallocation= =3Dmetadata +Image resized. +wrote 2048000/2048000 bytes at offset 0 +1.953 MiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec) +wrote 81920/81920 bytes at offset 2048000 +80 KiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec) + +--- growth_size=3D80 create_mode=3Dfalloc growth_mode=3Doff --- +Formatting 'TEST_DIR/t.IMGFMT', fmt=3DIMGFMT size=3D2048000 preallocation= =3Dfalloc +Image resized. +wrote 2048000/2048000 bytes at offset 0 +1.953 MiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec) +wrote 81920/81920 bytes at offset 2048000 +80 KiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec) + +--- growth_size=3D80 create_mode=3Dfalloc growth_mode=3Dmetadata --- +Formatting 'TEST_DIR/t.IMGFMT', fmt=3DIMGFMT size=3D2048000 preallocation= =3Dfalloc +Image resized. +wrote 2048000/2048000 bytes at offset 0 +1.953 MiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec) +wrote 81920/81920 bytes at offset 2048000 +80 KiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec) + +--- growth_size=3D80 create_mode=3Dfalloc growth_mode=3Dfalloc --- +Formatting 'TEST_DIR/t.IMGFMT', fmt=3DIMGFMT size=3D2048000 preallocation= =3Dfalloc +Image resized. +wrote 2048000/2048000 bytes at offset 0 +1.953 MiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec) +wrote 81920/81920 bytes at offset 2048000 +80 KiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec) + +--- growth_size=3D80 create_mode=3Dfalloc growth_mode=3Dfull --- +Formatting 'TEST_DIR/t.IMGFMT', fmt=3DIMGFMT size=3D2048000 preallocation= =3Dfalloc +Image resized. +wrote 2048000/2048000 bytes at offset 0 +1.953 MiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec) +wrote 81920/81920 bytes at offset 2048000 +80 KiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec) + +--- growth_size=3D80 create_mode=3Dfull growth_mode=3Doff --- +Formatting 'TEST_DIR/t.IMGFMT', fmt=3DIMGFMT size=3D2048000 preallocation= =3Dfull +Image resized. +wrote 2048000/2048000 bytes at offset 0 +1.953 MiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec) +wrote 81920/81920 bytes at offset 2048000 +80 KiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec) + +--- growth_size=3D80 create_mode=3Dfull growth_mode=3Dmetadata --- +Formatting 'TEST_DIR/t.IMGFMT', fmt=3DIMGFMT size=3D2048000 preallocation= =3Dfull +Image resized. +wrote 2048000/2048000 bytes at offset 0 +1.953 MiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec) +wrote 81920/81920 bytes at offset 2048000 +80 KiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec) + +--- growth_size=3D80 create_mode=3Dfull growth_mode=3Dfalloc --- +Formatting 'TEST_DIR/t.IMGFMT', fmt=3DIMGFMT size=3D2048000 preallocation= =3Dfull +Image resized. +wrote 2048000/2048000 bytes at offset 0 +1.953 MiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec) +wrote 81920/81920 bytes at offset 2048000 +80 KiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec) + +--- growth_size=3D80 create_mode=3Dfull growth_mode=3Dfull --- +Formatting 'TEST_DIR/t.IMGFMT', fmt=3DIMGFMT size=3D2048000 preallocation= =3Dfull +Image resized. +wrote 2048000/2048000 bytes at offset 0 +1.953 MiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec) +wrote 81920/81920 bytes at offset 2048000 +80 KiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec) + +*** done diff --git a/tests/qemu-iotests/group b/tests/qemu-iotests/group index 1a89bebe14..a9a3b29db9 100644 --- a/tests/qemu-iotests/group +++ b/tests/qemu-iotests/group @@ -131,6 +131,7 @@ 122 rw auto 123 rw auto quick 124 rw auto backing +125 rw auto 128 rw auto quick 129 rw auto quick 130 rw auto quick --=20 2.12.0