From nobody Thu May 1 22:53:07 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.zohomail.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: <qemu-devel-bounces+importer=patchew.org@nongnu.org> Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1499792766325715.667080928002; Tue, 11 Jul 2017 10:06:06 -0700 (PDT) Received: from localhost ([::1]:47652 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from <qemu-devel-bounces+importer=patchew.org@nongnu.org>) id 1dUybr-0001sN-RA for importer@patchew.org; Tue, 11 Jul 2017 13:06:03 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:46917) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from <mreitz@redhat.com>) id 1dUxmB-0001yl-5K for qemu-devel@nongnu.org; Tue, 11 Jul 2017 12:12:43 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from <mreitz@redhat.com>) id 1dUxm9-000793-9E for qemu-devel@nongnu.org; Tue, 11 Jul 2017 12:12:39 -0400 Received: from mx1.redhat.com ([209.132.183.28]:47468) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from <mreitz@redhat.com>) id 1dUxm4-00076i-P6; Tue, 11 Jul 2017 12:12:32 -0400 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 6BFC4C04B31C; Tue, 11 Jul 2017 16:12:31 +0000 (UTC) Received: from localhost (ovpn-204-123.brq.redhat.com [10.40.204.123]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 78827756C0; Tue, 11 Jul 2017 16:12:30 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 6BFC4C04B31C Authentication-Results: ext-mx07.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx07.extmail.prod.ext.phx2.redhat.com; spf=pass smtp.mailfrom=mreitz@redhat.com DKIM-Filter: OpenDKIM Filter v2.11.0 mx1.redhat.com 6BFC4C04B31C From: Max Reitz <mreitz@redhat.com> To: qemu-block@nongnu.org Date: Tue, 11 Jul 2017 18:07:59 +0200 Message-Id: <20170711160814.20941-71-mreitz@redhat.com> In-Reply-To: <20170711160814.20941-1-mreitz@redhat.com> References: <20170711160814.20941-1-mreitz@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.31]); Tue, 11 Jul 2017 16:12:31 +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] [PULL 70/85] block: Add PreallocMode to BD.bdrv_truncate() X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: <qemu-devel.nongnu.org> List-Unsubscribe: <https://lists.nongnu.org/mailman/options/qemu-devel>, <mailto:qemu-devel-request@nongnu.org?subject=unsubscribe> List-Archive: <http://lists.nongnu.org/archive/html/qemu-devel/> List-Post: <mailto:qemu-devel@nongnu.org> List-Help: <mailto:qemu-devel-request@nongnu.org?subject=help> List-Subscribe: <https://lists.nongnu.org/mailman/listinfo/qemu-devel>, <mailto:qemu-devel-request@nongnu.org?subject=subscribe> Cc: qemu-devel@nongnu.org, Max Reitz <mreitz@redhat.com> Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" <qemu-devel-bounces+importer=patchew.org@nongnu.org> 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 <mreitz@redhat.com> Reviewed-by: Stefan Hajnoczi <stefanha@redhat.com> Message-id: 20170613202107.10125-2-mreitz@redhat.com Signed-off-by: Max Reitz <mreitz@redhat.com> --- 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 | 8 +++++++- block/iscsi.c | 9 ++++++++- block/nfs.c | 9 ++++++++- block/qcow2.c | 9 ++++++++- block/qed.c | 9 ++++++++- block/raw-format.c | 9 ++++++++- block/rbd.c | 9 ++++++++- block/sheepdog.c | 11 +++++++++-- 14 files changed, 98 insertions(+), 15 deletions(-) diff --git a/include/block/block_int.h b/include/block/block_int.h index d0cd8a3..669a279 100644 --- a/include/block/block_int.h +++ b/include/block/block_int.h @@ -204,7 +204,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 162e9d9..37e7b3d 100644 --- a/block.c +++ b/block.c @@ -3434,7 +3434,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, 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 b25856c..a9b03ff 100644 --- a/block/blkdebug.c +++ b/block/blkdebug.c @@ -821,8 +821,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 c561cba..33f690f 100644 --- a/block/crypto.c +++ b/block/crypto.c @@ -361,12 +361,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 3927fab..4a40976 100644 --- a/block/file-posix.c +++ b/block/file-posix.c @@ -1624,12 +1624,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 ef2910b..4706335 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 addceed..bfa4df1 100644 --- a/block/gluster.c +++ b/block/gluster.c @@ -1096,11 +1096,17 @@ 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) { + error_setg(errp, "Unsupported preallocation mode '%s'", + PreallocMode_lookup[prealloc]); + return -ENOTSUP; + } + ret =3D glfs_ftruncate(s->fd, offset); if (ret < 0) { ret =3D -errno; diff --git a/block/iscsi.c b/block/iscsi.c index 54067e2..904ef20 100644 --- a/block/iscsi.c +++ b/block/iscsi.c @@ -2079,11 +2079,18 @@ 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) { + error_setg(errp, "Unsupported preallocation mode '%s'", + PreallocMode_lookup[prealloc]); + return -ENOTSUP; + } + if (iscsilun->type !=3D TYPE_DISK) { error_setg(errp, "Cannot resize non-disk iSCSI devices"); return -ENOTSUP; diff --git a/block/nfs.c b/block/nfs.c index c3c5de0..c396ee1 100644 --- a/block/nfs.c +++ b/block/nfs.c @@ -759,11 +759,18 @@ static int64_t nfs_get_allocated_file_size(BlockDrive= rState *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; int ret; =20 + if (prealloc !=3D PREALLOC_MODE_OFF) { + error_setg(errp, "Unsupported preallocation mode '%s'", + PreallocMode_lookup[prealloc]); + return -ENOTSUP; + } + ret =3D nfs_ftruncate(client->context, client->fh, offset); if (ret < 0) { error_setg_errno(errp, -ret, "Failed to truncate file"); diff --git a/block/qcow2.c b/block/qcow2.c index 52dc6bf..b7c5994 100644 --- a/block/qcow2.c +++ b/block/qcow2.c @@ -3058,12 +3058,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 385381a..8f7e45c 100644 --- a/block/qed.c +++ b/block/qed.c @@ -1342,12 +1342,19 @@ static int coroutine_fn bdrv_qed_co_pwrite_zeroes(B= lockDriverState *bs, QED_AIOCB_WRITE | QED_AIOCB_ZERO); } =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 a1622c6..721c9a0 100644 --- a/block/raw-format.c +++ b/block/raw-format.c @@ -352,10 +352,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 9da02cd..9151d5c 100644 --- a/block/rbd.c +++ b/block/rbd.c @@ -936,11 +936,18 @@ static int64_t qemu_rbd_getlength(BlockDriverState *b= s) 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) { + error_setg(errp, "Unsupported preallocation mode '%s'", + PreallocMode_lookup[prealloc]); + return -ENOTSUP; + } + r =3D rbd_resize(s->image, offset); if (r < 0) { error_setg_errno(errp, -r, "Failed to resize file"); diff --git a/block/sheepdog.c b/block/sheepdog.c index 08d7b11..b7b7e6b 100644 --- a/block/sheepdog.c +++ b/block/sheepdog.c @@ -2153,13 +2153,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"); @@ -2448,7 +2455,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.9.4