From nobody Mon Feb 9 09:43:21 2026 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 1497385555942382.98723561945746; Tue, 13 Jun 2017 13:25:55 -0700 (PDT) Received: from localhost ([::1]:45053 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dKsNu-0001kX-JB for importer@patchew.org; Tue, 13 Jun 2017 16:25:54 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:37875) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dKsJg-00068U-Fd for qemu-devel@nongnu.org; Tue, 13 Jun 2017 16:21:34 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dKsJe-0001V9-Vi for qemu-devel@nongnu.org; Tue, 13 Jun 2017 16:21:32 -0400 Received: from mx1.redhat.com ([209.132.183.28]:55012) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1dKsJX-0001Sy-1I; Tue, 13 Jun 2017 16:21:23 -0400 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 190E6C05FFCD; Tue, 13 Jun 2017 20:21:22 +0000 (UTC) Received: from localhost (ovpn-204-68.brq.redhat.com [10.40.204.68]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 2C3155B824; Tue, 13 Jun 2017 20:21:18 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 190E6C05FFCD Authentication-Results: ext-mx08.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx08.extmail.prod.ext.phx2.redhat.com; spf=pass smtp.mailfrom=mreitz@redhat.com DKIM-Filter: OpenDKIM Filter v2.11.0 mx1.redhat.com 190E6C05FFCD From: Max Reitz To: qemu-block@nongnu.org Date: Tue, 13 Jun 2017 22:20:53 +0200 Message-Id: <20170613202107.10125-3-mreitz@redhat.com> In-Reply-To: <20170613202107.10125-1-mreitz@redhat.com> References: <20170613202107.10125-1-mreitz@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.32]); Tue, 13 Jun 2017 20:21:22 +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 v4 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, Stefan Hajnoczi , 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 | 5 +++-- 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, 26 insertions(+), 36 deletions(-) diff --git a/include/block/block.h b/include/block/block.h index e2c6a0d..06b2f42 100644 --- a/include/block/block.h +++ b/include/block/block.h @@ -300,7 +300,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 2fdb8a5..d9f618a 100644 --- a/block.c +++ b/block.c @@ -3394,7 +3394,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; @@ -3417,7 +3418,7 @@ int bdrv_truncate(BdrvChild *child, int64_t offset, E= rror **errp) =20 assert(!(bs->open_flags & BDRV_O_INACTIVE)); =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); diff --git a/block/blkdebug.c b/block/blkdebug.c index 00090aa..3f971a3 100644 --- a/block/blkdebug.c +++ b/block/blkdebug.c @@ -815,13 +815,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 7d7f369..3c91655 100644 --- a/block/block-backend.c +++ b/block/block-backend.c @@ -1778,7 +1778,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 7047cb2..6370598 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 8be46a7..5a38998 100644 --- a/block/parallels.c +++ b/block/parallels.c @@ -224,7 +224,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; @@ -458,7 +458,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++; @@ -699,7 +700,8 @@ static int parallels_open(BlockDriverState *bs, QDict *= options, int flags, } =20 if (!(flags & BDRV_O_RESIZE) || !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 @@ -742,7 +744,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 7bd94dc..1306065 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 && @@ -917,7 +918,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 7c06061..84e0cee 100644 --- a/block/qcow2-refcount.c +++ b/block/qcow2-refcount.c @@ -1730,7 +1730,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 942befe..685958a 100644 --- a/block/qcow2.c +++ b/block/qcow2.c @@ -2665,7 +2665,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); @@ -2881,7 +2881,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 20134cb..83a0b33 100644 --- a/block/raw-format.c +++ b/block/raw-format.c @@ -357,12 +357,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; @@ -375,7 +369,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 3f4c2aa..01278f3 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 8b270b5..85c476a 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.9.4