From nobody Sun May 5 10:24:01 2024 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: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1501862483127620.8220061478437; Fri, 4 Aug 2017 09:01:23 -0700 (PDT) Received: from localhost ([::1]:50458 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ddf2P-0007Lw-N9 for importer@patchew.org; Fri, 04 Aug 2017 12:01:21 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:51179) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ddeFD-0001XL-6l for qemu-devel@nongnu.org; Fri, 04 Aug 2017 11:10:32 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ddeFA-000470-Kn for qemu-devel@nongnu.org; Fri, 04 Aug 2017 11:10:31 -0400 Received: from mailhub.sw.ru ([195.214.232.25]:16486 helo=relay.sw.ru) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1ddeFA-00041K-8q for qemu-devel@nongnu.org; Fri, 04 Aug 2017 11:10:28 -0400 Received: from localhost.localdomain (msk-vpn.virtuozzo.com [195.214.232.6]) by relay.sw.ru (8.13.4/8.13.4) with ESMTP id v74FAEtw021861; Fri, 4 Aug 2017 18:10:16 +0300 (MSK) From: "Denis V. Lunev" To: qemu-block@nongnu.org, qemu-devel@nongnu.org Date: Fri, 4 Aug 2017 18:10:11 +0300 Message-Id: <20170804151013.13057-2-den@openvz.org> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20170804151013.13057-1-den@openvz.org> References: <20170804151013.13057-1-den@openvz.org> X-detected-operating-system: by eggs.gnu.org: OpenBSD 3.x [fuzzy] X-Received-From: 195.214.232.25 Subject: [Qemu-devel] [PATCH 1/3] block: respect error code from bdrv_getlength in handle_aiocb_write_zeroes X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Kevin Wolf , den@openvz.org, Markus Armbruster , 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" Original idea beyond the code in question was the following: we have failed to write zeroes with fallocate(FALLOC_FL_ZERO_RANGE) as the simplest approach and via fallocate(FALLOC_FL_PUNCH_HOLE)/fallocate(0). We have the only chance now: if the request comes beyond end of the file. Thus we should calculate file length and respect the error code from that op. Signed-off-by: Denis V. Lunev CC: Markus Armbruster CC: Kevin Wolf CC: Max Reitz CC: Stefan Hajnoczi Reviewed-by: Eric Blake --- block/file-posix.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/block/file-posix.c b/block/file-posix.c index cfbb236f6f..f4de022ae0 100644 --- a/block/file-posix.c +++ b/block/file-posix.c @@ -1339,6 +1339,9 @@ static ssize_t handle_aiocb_write_zeroes(RawPosixAIOD= ata *aiocb) #if defined(CONFIG_FALLOCATE) || defined(CONFIG_XFS) BDRVRawState *s =3D aiocb->bs->opaque; #endif +#ifdef CONFIG_FALLOCATE + int64_t len; +#endif =20 if (aiocb->aio_type & QEMU_AIO_BLKDEV) { return handle_aiocb_write_zeroes_block(aiocb); @@ -1381,7 +1384,10 @@ static ssize_t handle_aiocb_write_zeroes(RawPosixAIO= Data *aiocb) #endif =20 #ifdef CONFIG_FALLOCATE - if (s->has_fallocate && aiocb->aio_offset >=3D bdrv_getlength(aiocb->b= s)) { + /* Last resort: we are trying to extend the file with zeroed data. This + * can be done via fallocate(fd, 0) */ + len =3D bdrv_getlength(aiocb->bs); + if (s->has_fallocate && len >=3D 0 && aiocb->aio_offset >=3D len) { int ret =3D do_fallocate(s->fd, 0, aiocb->aio_offset, aiocb->aio_n= bytes); if (ret =3D=3D 0 || ret !=3D -ENOTSUP) { return ret; --=20 2.11.0 From nobody Sun May 5 10:24:01 2024 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: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 150186265267987.79863995669314; Fri, 4 Aug 2017 09:04:12 -0700 (PDT) Received: from localhost ([::1]:50747 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ddf59-0001LB-8B for importer@patchew.org; Fri, 04 Aug 2017 12:04:11 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:51178) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ddeFD-0001XJ-62 for qemu-devel@nongnu.org; Fri, 04 Aug 2017 11:10:32 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ddeFA-00046M-9Y for qemu-devel@nongnu.org; Fri, 04 Aug 2017 11:10:31 -0400 Received: from mailhub.sw.ru ([195.214.232.25]:4459 helo=relay.sw.ru) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1ddeF9-00041I-Ts for qemu-devel@nongnu.org; Fri, 04 Aug 2017 11:10:28 -0400 Received: from localhost.localdomain (msk-vpn.virtuozzo.com [195.214.232.6]) by relay.sw.ru (8.13.4/8.13.4) with ESMTP id v74FAEtx021861; Fri, 4 Aug 2017 18:10:16 +0300 (MSK) From: "Denis V. Lunev" To: qemu-block@nongnu.org, qemu-devel@nongnu.org Date: Fri, 4 Aug 2017 18:10:12 +0300 Message-Id: <20170804151013.13057-3-den@openvz.org> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20170804151013.13057-1-den@openvz.org> References: <20170804151013.13057-1-den@openvz.org> X-detected-operating-system: by eggs.gnu.org: OpenBSD 3.x [fuzzy] X-Received-From: 195.214.232.25 Subject: [Qemu-devel] [PATCH 2/3] parallels: respect error code of bdrv_getlength() in allocate_clusters() X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Kevin Wolf , den@openvz.org, Markus Armbruster , 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" If we can not get the file length, the state of BDS is broken completely. Return error to the caller. Signed-off-by: Denis V. Lunev CC: Markus Armbruster CC: Kevin Wolf CC: Max Reitz CC: Stefan Hajnoczi Reviewed-by: Eric Blake --- block/parallels.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/block/parallels.c b/block/parallels.c index 5bbdfabb7a..6794e53c0b 100644 --- a/block/parallels.c +++ b/block/parallels.c @@ -192,7 +192,7 @@ static int64_t allocate_clusters(BlockDriverState *bs, = int64_t sector_num, int nb_sectors, int *pnum) { BDRVParallelsState *s =3D bs->opaque; - int64_t pos, space, idx, to_allocate, i; + int64_t pos, space, idx, to_allocate, i, len; =20 pos =3D block_status(s, sector_num, nb_sectors, pnum); if (pos > 0) { @@ -214,7 +214,11 @@ static int64_t allocate_clusters(BlockDriverState *bs,= int64_t sector_num, assert(idx < s->bat_size && idx + to_allocate <=3D s->bat_size); =20 space =3D to_allocate * s->tracks; - if (s->data_end + space > bdrv_getlength(bs->file->bs) >> BDRV_SECTOR_= BITS) { + len =3D bdrv_getlength(bs->file->bs); + if (len < 0) { + return len; + } + if (s->data_end + space > (len >> BDRV_SECTOR_BITS)) { int ret; space +=3D s->prealloc_size; if (s->prealloc_mode =3D=3D PRL_PREALLOC_MODE_FALLOCATE) { --=20 2.11.0 From nobody Sun May 5 10:24:01 2024 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: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1501862863450951.6625966130078; Fri, 4 Aug 2017 09:07:43 -0700 (PDT) Received: from localhost ([::1]:51525 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ddf8X-0004kQ-4O for importer@patchew.org; Fri, 04 Aug 2017 12:07:41 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:51184) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ddeFD-0001XP-7R for qemu-devel@nongnu.org; Fri, 04 Aug 2017 11:10:32 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ddeFB-00048r-8Q for qemu-devel@nongnu.org; Fri, 04 Aug 2017 11:10:31 -0400 Received: from mailhub.sw.ru ([195.214.232.25]:15402 helo=relay.sw.ru) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1ddeFA-00041f-Sx for qemu-devel@nongnu.org; Fri, 04 Aug 2017 11:10:29 -0400 Received: from localhost.localdomain (msk-vpn.virtuozzo.com [195.214.232.6]) by relay.sw.ru (8.13.4/8.13.4) with ESMTP id v74FAEu0021861; Fri, 4 Aug 2017 18:10:16 +0300 (MSK) From: "Denis V. Lunev" To: qemu-block@nongnu.org, qemu-devel@nongnu.org Date: Fri, 4 Aug 2017 18:10:13 +0300 Message-Id: <20170804151013.13057-4-den@openvz.org> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20170804151013.13057-1-den@openvz.org> References: <20170804151013.13057-1-den@openvz.org> X-detected-operating-system: by eggs.gnu.org: OpenBSD 3.x [fuzzy] X-Received-From: 195.214.232.25 Subject: [Qemu-devel] [PATCH 3/3] parallels: drop check that bdrv_truncate() is working X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Kevin Wolf , den@openvz.org, Markus Armbruster , 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" This would be actually strange and error prone. If truncate() nowadays will fail, there is something fatally wrong. Let's check for that during the actual work. The only fallback case is when the file is not zero initialized. In this case we should switch to preallocation via fallocate(). Signed-off-by: Denis V. Lunev CC: Markus Armbruster CC: Kevin Wolf CC: Max Reitz CC: Stefan Hajnoczi --- block/parallels.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/block/parallels.c b/block/parallels.c index 6794e53c0b..e1e06d23cc 100644 --- a/block/parallels.c +++ b/block/parallels.c @@ -703,9 +703,7 @@ static int parallels_open(BlockDriverState *bs, QDict *= options, int flags, goto fail_options; } =20 - if (!(flags & BDRV_O_RESIZE) || !bdrv_has_zero_init(bs->file->bs) || - bdrv_truncate(bs->file, bdrv_getlength(bs->file->bs), - PREALLOC_MODE_OFF, NULL) !=3D 0) { + if (!bdrv_has_zero_init(bs->file->bs)) { s->prealloc_mode =3D PRL_PREALLOC_MODE_FALLOCATE; } =20 --=20 2.11.0