From nobody Sat Apr 27 12:19:14 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) client-ip=209.132.183.28; envelope-from=libvir-list-bounces@redhat.com; helo=mx1.redhat.com; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1506356576229556.4231439479145; Mon, 25 Sep 2017 09:22:56 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id B57552F944D; Mon, 25 Sep 2017 16:22:54 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.21]) by smtp.corp.redhat.com (Postfix) with ESMTPS id B8A92781E9; Mon, 25 Sep 2017 16:22:53 +0000 (UTC) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by colo-mx.corp.redhat.com (Postfix) with ESMTP id 44B084EE4F; Mon, 25 Sep 2017 16:22:51 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id v8PFkUJo021174 for ; Mon, 25 Sep 2017 11:46:30 -0400 Received: by smtp.corp.redhat.com (Postfix) id 959BC6F7E9; Mon, 25 Sep 2017 15:46:30 +0000 (UTC) Received: from dnr.brq.redhat.com (unknown [10.43.2.37]) by smtp.corp.redhat.com (Postfix) with ESMTP id 1DAD66F7E2 for ; Mon, 25 Sep 2017 15:46:26 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com B57552F944D Authentication-Results: ext-mx05.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx05.extmail.prod.ext.phx2.redhat.com; spf=fail smtp.mailfrom=libvir-list-bounces@redhat.com From: =?UTF-8?q?J=C3=A1n=20Tomko?= To: libvir-list@redhat.com Date: Mon, 25 Sep 2017 17:46:08 +0200 Message-Id: <231810f37c12ba05d7c3ae713cb0c3cccf717cc7.1506354254.git.jtomko@redhat.com> In-Reply-To: References: In-Reply-To: References: X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH 1/3] use virFileAllocate in virStorageFileResize X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.29]); Mon, 25 Sep 2017 16:22:55 +0000 (UTC) X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" Introduce a new function virFileAllocate that will call the non-destructive variants of safezero, essentially reverting my commit 1390c268 safezero: fall back to writing zeroes even when resizing back to the state as of commit 18f0316 virstoragefile: Have virStorageFileResize use safezero This means that _ALLOCATE flag will no longer work on platforms without the allocate syscalls, but it will not overwrite data either. Reviewed-by: John Ferlan --- src/util/virfile.c | 11 +++++++++++ src/util/virfile.h | 2 ++ src/util/virstoragefile.c | 15 ++++++++++----- 3 files changed, 23 insertions(+), 5 deletions(-) diff --git a/src/util/virfile.c b/src/util/virfile.c index a03a23fab..7ca60052d 100644 --- a/src/util/virfile.c +++ b/src/util/virfile.c @@ -1216,6 +1216,17 @@ int safezero(int fd, off_t offset, off_t len) return safezero_slow(fd, offset, len); } =20 +int virFileAllocate(int fd, off_t offset, off_t len) +{ + int ret; + + ret =3D safezero_posix_fallocate(fd, offset, len); + if (ret !=3D -2) + return ret; + + return safezero_sys_fallocate(fd, offset, len); +} + #if defined HAVE_MNTENT_H && defined HAVE_GETMNTENT_R /* search /proc/mounts for mount point of *type; return pointer to * malloc'ed string of the path if found, otherwise return NULL diff --git a/src/util/virfile.h b/src/util/virfile.h index 57ceb8072..21fb41b70 100644 --- a/src/util/virfile.h +++ b/src/util/virfile.h @@ -44,6 +44,8 @@ ssize_t safewrite(int fd, const void *buf, size_t count) ATTRIBUTE_RETURN_CHECK; int safezero(int fd, off_t offset, off_t len) ATTRIBUTE_RETURN_CHECK; +int virFileAllocate(int fd, off_t offset, off_t len) + ATTRIBUTE_RETURN_CHECK; =20 /* Don't call these directly - use the macros below */ int virFileClose(int *fdptr, virFileCloseFlags flags) diff --git a/src/util/virstoragefile.c b/src/util/virstoragefile.c index 484a5c806..b3da0a452 100644 --- a/src/util/virstoragefile.c +++ b/src/util/virstoragefile.c @@ -1320,7 +1320,7 @@ virStorageFileResize(const char *path, { int fd =3D -1; int ret =3D -1; - int rc ATTRIBUTE_UNUSED; + int rc; off_t offset ATTRIBUTE_UNUSED; off_t len ATTRIBUTE_UNUSED; =20 @@ -1333,10 +1333,15 @@ virStorageFileResize(const char *path, } =20 if (pre_allocate) { - if (safezero(fd, offset, len) !=3D 0) { - virReportSystemError(errno, - _("Failed to pre-allocate space for " - "file '%s'"), path); + if ((rc =3D virFileAllocate(fd, offset, len)) !=3D 0) { + if (rc =3D=3D -2) { + virReportError(VIR_ERR_OPERATION_UNSUPPORTED, "%s", + _("preallocate is not supported on this pla= tform")); + } else { + virReportSystemError(errno, + _("Failed to pre-allocate space for " + "file '%s'"), path); + } goto cleanup; } } else { --=20 2.13.0 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Sat Apr 27 12:19:14 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) client-ip=209.132.183.28; envelope-from=libvir-list-bounces@redhat.com; helo=mx1.redhat.com; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1506354577263680.4610571319857; Mon, 25 Sep 2017 08:49:37 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 13F11267FB; Mon, 25 Sep 2017 15:49:36 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.20]) by smtp.corp.redhat.com (Postfix) with ESMTPS id E86355D9C9; Mon, 25 Sep 2017 15:49:35 +0000 (UTC) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by colo-mx.corp.redhat.com (Postfix) with ESMTP id B126C180884A; Mon, 25 Sep 2017 15:49:35 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id v8PFkZMa021185 for ; Mon, 25 Sep 2017 11:46:35 -0400 Received: by smtp.corp.redhat.com (Postfix) id 059AC6F443; Mon, 25 Sep 2017 15:46:35 +0000 (UTC) Received: from dnr.brq.redhat.com (unknown [10.43.2.37]) by smtp.corp.redhat.com (Postfix) with ESMTP id 8193A6F7EA for ; Mon, 25 Sep 2017 15:46:30 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 13F11267FB Authentication-Results: ext-mx06.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx06.extmail.prod.ext.phx2.redhat.com; spf=fail smtp.mailfrom=libvir-list-bounces@redhat.com From: =?UTF-8?q?J=C3=A1n=20Tomko?= To: libvir-list@redhat.com Date: Mon, 25 Sep 2017 17:46:09 +0200 Message-Id: <3142aaf19f71a37f84fa09020526331aa0299244.1506354254.git.jtomko@redhat.com> In-Reply-To: References: In-Reply-To: References: X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH 2/3] virStorageFileResize: fallocate the whole capacity X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.30]); Mon, 25 Sep 2017 15:49:36 +0000 (UTC) X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" We have been trying to implement the ALLOCATE flag to mean "the volume should be fully allocated after the resize". Since commit b0579ed9 we do not allocate from the existing capacity, but from the existing allocation value. However this value is a total of all the allocated bytes, not an offset. For a sparsely allocated file: $ perl -e 'print "x"x8192;' > vol1 $ fallocate -p -o 0 -l 4096 vol1 Treating allocation as an offset would result in an incompletely allocated file: $ virsh vol-resize vol1 --pool default 16384 --allocate Capacity: 16.00 KiB Allocation: 12.00 KiB Call fallocate from zero on the whole requested capacity to fully allocate the file. Reviewed-by: John Ferlan --- src/storage/storage_util.c | 3 +-- src/util/virstoragefile.c | 8 +------- src/util/virstoragefile.h | 1 - 3 files changed, 2 insertions(+), 10 deletions(-) diff --git a/src/storage/storage_util.c b/src/storage/storage_util.c index 07dba2222..b94b3f397 100644 --- a/src/storage/storage_util.c +++ b/src/storage/storage_util.c @@ -2329,8 +2329,7 @@ virStorageBackendVolResizeLocal(virConnectPtr conn AT= TRIBUTE_UNUSED, bool pre_allocate =3D flags & VIR_STORAGE_VOL_RESIZE_ALLOCATE; =20 if (vol->target.format =3D=3D VIR_STORAGE_FILE_RAW) { - return virStorageFileResize(vol->target.path, capacity, - vol->target.allocation, pre_allocate); + return virStorageFileResize(vol->target.path, capacity, pre_alloca= te); } else if (vol->target.format =3D=3D VIR_STORAGE_FILE_PLOOP) { return storagePloopResize(vol, capacity); } else { diff --git a/src/util/virstoragefile.c b/src/util/virstoragefile.c index b3da0a452..5df1ea0b8 100644 --- a/src/util/virstoragefile.c +++ b/src/util/virstoragefile.c @@ -1315,17 +1315,11 @@ virStorageFileChainGetBroken(virStorageSourcePtr ch= ain, int virStorageFileResize(const char *path, unsigned long long capacity, - unsigned long long orig_capacity, bool pre_allocate) { int fd =3D -1; int ret =3D -1; int rc; - off_t offset ATTRIBUTE_UNUSED; - off_t len ATTRIBUTE_UNUSED; - - offset =3D orig_capacity; - len =3D capacity - orig_capacity; =20 if ((fd =3D open(path, O_RDWR)) < 0) { virReportSystemError(errno, _("Unable to open '%s'"), path); @@ -1333,7 +1327,7 @@ virStorageFileResize(const char *path, } =20 if (pre_allocate) { - if ((rc =3D virFileAllocate(fd, offset, len)) !=3D 0) { + if ((rc =3D virFileAllocate(fd, 0, capacity)) !=3D 0) { if (rc =3D=3D -2) { virReportError(VIR_ERR_OPERATION_UNSUPPORTED, "%s", _("preallocate is not supported on this pla= tform")); diff --git a/src/util/virstoragefile.h b/src/util/virstoragefile.h index f7e897f25..1eb1c6471 100644 --- a/src/util/virstoragefile.h +++ b/src/util/virstoragefile.h @@ -328,7 +328,6 @@ virStorageSourcePtr virStorageFileChainLookup(virStorag= eSourcePtr chain, =20 int virStorageFileResize(const char *path, unsigned long long capacity, - unsigned long long orig_capacity, bool pre_allocate); =20 int virStorageFileIsClusterFS(const char *path); --=20 2.13.0 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Sat Apr 27 12:19:14 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) client-ip=209.132.183.28; envelope-from=libvir-list-bounces@redhat.com; helo=mx1.redhat.com; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1506354589306457.607215490468; Mon, 25 Sep 2017 08:49:49 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 05B54806AF; Mon, 25 Sep 2017 15:49:48 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.21]) by smtp.corp.redhat.com (Postfix) with ESMTPS id DBC5D6F10B; Mon, 25 Sep 2017 15:49:47 +0000 (UTC) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by colo-mx.corp.redhat.com (Postfix) with ESMTP id A3D763FACE; Mon, 25 Sep 2017 15:49:47 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id v8PFkaxr021193 for ; Mon, 25 Sep 2017 11:46:36 -0400 Received: by smtp.corp.redhat.com (Postfix) id 996366F442; Mon, 25 Sep 2017 15:46:36 +0000 (UTC) Received: from dnr.brq.redhat.com (unknown [10.43.2.37]) by smtp.corp.redhat.com (Postfix) with ESMTP id 211436F443 for ; Mon, 25 Sep 2017 15:46:35 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 05B54806AF Authentication-Results: ext-mx02.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx02.extmail.prod.ext.phx2.redhat.com; spf=fail smtp.mailfrom=libvir-list-bounces@redhat.com From: =?UTF-8?q?J=C3=A1n=20Tomko?= To: libvir-list@redhat.com Date: Mon, 25 Sep 2017 17:46:10 +0200 Message-Id: <6a6b579eef641c031e1620128230c91df032c876.1506354254.git.jtomko@redhat.com> In-Reply-To: References: In-Reply-To: References: X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH 3/3] Shrink volume even with ALLOCATE flag X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.26]); Mon, 25 Sep 2017 15:49:48 +0000 (UTC) X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" Calling fallocate on the new (smaller) capacity ensures that the whole file is allocated, but it does not reduce the file size. Also call ftruncate after fallocate. https://bugzilla.redhat.com/show_bug.cgi?id=3D1366446 Reviewed-by: John Ferlan --- src/util/virstoragefile.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/util/virstoragefile.c b/src/util/virstoragefile.c index 5df1ea0b8..80a33b1a6 100644 --- a/src/util/virstoragefile.c +++ b/src/util/virstoragefile.c @@ -1338,12 +1338,12 @@ virStorageFileResize(const char *path, } goto cleanup; } - } else { - if (ftruncate(fd, capacity) < 0) { - virReportSystemError(errno, - _("Failed to truncate file '%s'"), path); - goto cleanup; - } + } + + if (ftruncate(fd, capacity) < 0) { + virReportSystemError(errno, + _("Failed to truncate file '%s'"), path); + goto cleanup; } =20 if (VIR_CLOSE(fd) < 0) { --=20 2.13.0 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list