From nobody Sun May 5 04:56:49 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 1504770813159855.6619627769935; Thu, 7 Sep 2017 00:53:33 -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 A0BCF356D9; Thu, 7 Sep 2017 07:53:24 +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 7C27218E4B; Thu, 7 Sep 2017 07:53:24 +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 4003218045C2; Thu, 7 Sep 2017 07:53:24 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id v877ijiM000795 for ; Thu, 7 Sep 2017 03:44:45 -0400 Received: by smtp.corp.redhat.com (Postfix) id 697D218B0C; Thu, 7 Sep 2017 07:44:45 +0000 (UTC) Received: from mx1.redhat.com (ext-mx01.extmail.prod.ext.phx2.redhat.com [10.5.110.25]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 6461618B0B for ; Thu, 7 Sep 2017 07:44:43 +0000 (UTC) Received: from relay.sw.ru (mailhub.sw.ru [195.214.232.25]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 0DCC381DFE for ; Thu, 7 Sep 2017 07:44:41 +0000 (UTC) Received: from dim-vz7.qa.sw.ru (msk-vpn.virtuozzo.com [195.214.232.6]) by relay.sw.ru (8.13.4/8.13.4) with ESMTP id v877icE1023693 for ; Thu, 7 Sep 2017 10:44:38 +0300 (MSK) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com A0BCF356D9 Authentication-Results: ext-mx06.extmail.prod.ext.phx2.redhat.com; dmarc=fail (p=none dis=none) header.from=virtuozzo.com Authentication-Results: ext-mx06.extmail.prod.ext.phx2.redhat.com; spf=fail smtp.mailfrom=libvir-list-bounces@redhat.com DKIM-Filter: OpenDKIM Filter v2.11.0 mx1.redhat.com A0BCF356D9 DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 0DCC381DFE Authentication-Results: ext-mx01.extmail.prod.ext.phx2.redhat.com; dmarc=pass (p=none dis=none) header.from=virtuozzo.com Authentication-Results: ext-mx01.extmail.prod.ext.phx2.redhat.com; spf=pass smtp.mailfrom=nshirokovskiy@virtuozzo.com DKIM-Filter: OpenDKIM Filter v2.11.0 mx1.redhat.com 0DCC381DFE From: Nikolay Shirokovskiy To: libvir-list@redhat.com Date: Thu, 7 Sep 2017 10:44:13 +0300 Message-Id: <1504770256-674340-2-git-send-email-nshirokovskiy@virtuozzo.com> In-Reply-To: <1504770256-674340-1-git-send-email-nshirokovskiy@virtuozzo.com> References: <1504770256-674340-1-git-send-email-nshirokovskiy@virtuozzo.com> X-Greylist: IP, sender and recipient auto-whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.25]); Thu, 07 Sep 2017 07:44:42 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.25]); Thu, 07 Sep 2017 07:44:42 +0000 (UTC) for IP:'195.214.232.25' DOMAIN:'mailhub.sw.ru' HELO:'relay.sw.ru' FROM:'nshirokovskiy@virtuozzo.com' RCPT:'' X-RedHat-Spam-Score: -0.001 (SPF_PASS) 195.214.232.25 mailhub.sw.ru 195.214.232.25 mailhub.sw.ru X-Scanned-By: MIMEDefang 2.78 on 10.5.110.25 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH 1/4] iohelper: drop unused operation length limit 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]); Thu, 07 Sep 2017 07:53:25 +0000 (UTC) X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" --- src/util/iohelper.c | 28 +++++++--------------------- src/util/virfile.c | 2 +- 2 files changed, 8 insertions(+), 22 deletions(-) diff --git a/src/util/iohelper.c b/src/util/iohelper.c index d7bf5c7..5fc311b 100644 --- a/src/util/iohelper.c +++ b/src/util/iohelper.c @@ -44,7 +44,7 @@ #define VIR_FROM_THIS VIR_FROM_STORAGE =20 static int -runIO(const char *path, int fd, int oflags, unsigned long long length) +runIO(const char *path, int fd, int oflags) { void *base =3D NULL; /* Location to be freed */ char *buf =3D NULL; /* Aligned location within base */ @@ -79,7 +79,7 @@ runIO(const char *path, int fd, int oflags, unsigned long= long length) fdoutname =3D "stdout"; /* To make the implementation simpler, we give up on any * attempt to use O_DIRECT in a non-trivial manner. */ - if (direct && ((end =3D lseek(fd, 0, SEEK_CUR)) !=3D 0 || length))= { + if (direct && ((end =3D lseek(fd, 0, SEEK_CUR)) !=3D 0)) { virReportSystemError(end < 0 ? errno : EINVAL, "%s", _("O_DIRECT read needs entire seekable fi= le")); goto cleanup; @@ -110,20 +110,13 @@ runIO(const char *path, int fd, int oflags, unsigned = long long length) while (1) { ssize_t got; =20 - if (length && - (length - total) < buflen) - buflen =3D length - total; - - if (buflen =3D=3D 0) - break; /* End of requested data from client */ - if ((got =3D saferead(fdin, buf, buflen)) < 0) { virReportSystemError(errno, _("Unable to read %s"), fdinname); goto cleanup; } if (got =3D=3D 0) break; /* End of file before end of requested data */ - if (got < buflen || (buflen & alignMask)) { + if (got < buflen) { /* O_DIRECT can handle at most one short read, at end of file = */ if (direct && shortRead) { virReportSystemError(EINVAL, "%s", @@ -178,7 +171,7 @@ usage(int status) if (status) { fprintf(stderr, _("%s: try --help for more details"), program_name= ); } else { - printf(_("Usage: %s FILENAME LENGTH FD\n"), program_name); + printf(_("Usage: %s FILENAME FD\n"), program_name); } exit(status); } @@ -187,7 +180,6 @@ int main(int argc, char **argv) { const char *path; - unsigned long long length; int oflags =3D -1; int fd =3D -1; =20 @@ -204,14 +196,8 @@ main(int argc, char **argv) =20 if (argc > 1 && STREQ(argv[1], "--help")) usage(EXIT_SUCCESS); - if (argc =3D=3D 4) { /* FILENAME LENGTH FD */ - if (virStrToLong_ull(argv[2], NULL, 10, &length) < 0) { - fprintf(stderr, _("%s: malformed file length %s"), - program_name, argv[2]); - exit(EXIT_FAILURE); - } - - if (virStrToLong_i(argv[3], NULL, 10, &fd) < 0) { + if (argc =3D=3D 3) { /* FILENAME FD */ + if (virStrToLong_i(argv[2], NULL, 10, &fd) < 0) { fprintf(stderr, _("%s: malformed fd %s"), program_name, argv[3]); exit(EXIT_FAILURE); @@ -234,7 +220,7 @@ main(int argc, char **argv) usage(EXIT_FAILURE); } =20 - if (fd < 0 || runIO(path, fd, oflags, length) < 0) + if (fd < 0 || runIO(path, fd, oflags) < 0) goto error; =20 return 0; diff --git a/src/util/virfile.c b/src/util/virfile.c index 2f28e83..e746d87 100644 --- a/src/util/virfile.c +++ b/src/util/virfile.c @@ -260,7 +260,7 @@ virFileWrapperFdNew(int *fd, const char *name, unsigned= int flags) LIBEXECDIR))) goto error; =20 - ret->cmd =3D virCommandNewArgList(iohelper_path, name, "0", NULL); + ret->cmd =3D virCommandNewArgList(iohelper_path, name, NULL); =20 VIR_FREE(iohelper_path); =20 --=20 1.8.3.1 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Sun May 5 04:56:49 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 1504770691860762.013626359172; Thu, 7 Sep 2017 00:51:31 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 71998C047B69; Thu, 7 Sep 2017 07:51:29 +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 8B0165D6A3; Thu, 7 Sep 2017 07:51:28 +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 508201806106; Thu, 7 Sep 2017 07:51:22 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id v877ik6K000805 for ; Thu, 7 Sep 2017 03:44:46 -0400 Received: by smtp.corp.redhat.com (Postfix) id 46E22173F4; Thu, 7 Sep 2017 07:44:46 +0000 (UTC) Received: from mx1.redhat.com (ext-mx01.extmail.prod.ext.phx2.redhat.com [10.5.110.25]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 410A94D9E5 for ; Thu, 7 Sep 2017 07:44:43 +0000 (UTC) Received: from relay.sw.ru (mailhub.sw.ru [195.214.232.25]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 12CB481E02 for ; Thu, 7 Sep 2017 07:44:41 +0000 (UTC) Received: from dim-vz7.qa.sw.ru (msk-vpn.virtuozzo.com [195.214.232.6]) by relay.sw.ru (8.13.4/8.13.4) with ESMTP id v877icE2023693 for ; Thu, 7 Sep 2017 10:44:38 +0300 (MSK) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 71998C047B69 Authentication-Results: ext-mx07.extmail.prod.ext.phx2.redhat.com; dmarc=fail (p=none dis=none) header.from=virtuozzo.com Authentication-Results: ext-mx07.extmail.prod.ext.phx2.redhat.com; spf=fail smtp.mailfrom=libvir-list-bounces@redhat.com DKIM-Filter: OpenDKIM Filter v2.11.0 mx1.redhat.com 71998C047B69 DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 12CB481E02 Authentication-Results: ext-mx01.extmail.prod.ext.phx2.redhat.com; dmarc=pass (p=none dis=none) header.from=virtuozzo.com Authentication-Results: ext-mx01.extmail.prod.ext.phx2.redhat.com; spf=pass smtp.mailfrom=nshirokovskiy@virtuozzo.com DKIM-Filter: OpenDKIM Filter v2.11.0 mx1.redhat.com 12CB481E02 From: Nikolay Shirokovskiy To: libvir-list@redhat.com Date: Thu, 7 Sep 2017 10:44:14 +0300 Message-Id: <1504770256-674340-3-git-send-email-nshirokovskiy@virtuozzo.com> In-Reply-To: <1504770256-674340-1-git-send-email-nshirokovskiy@virtuozzo.com> References: <1504770256-674340-1-git-send-email-nshirokovskiy@virtuozzo.com> X-Greylist: IP, sender and recipient auto-whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.25]); Thu, 07 Sep 2017 07:44:42 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.25]); Thu, 07 Sep 2017 07:44:42 +0000 (UTC) for IP:'195.214.232.25' DOMAIN:'mailhub.sw.ru' HELO:'relay.sw.ru' FROM:'nshirokovskiy@virtuozzo.com' RCPT:'' X-RedHat-Spam-Score: -0.001 (SPF_PASS) 195.214.232.25 mailhub.sw.ru 195.214.232.25 mailhub.sw.ru X-Scanned-By: MIMEDefang 2.78 on 10.5.110.25 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH 2/4] iohelper: simplify last direct write alignment 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.15 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.31]); Thu, 07 Sep 2017 07:51:30 +0000 (UTC) X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" Make alignment of last direct write more straightforward. Using additionally two flags 'end' and 'shortRead' looks complicated. --- src/util/iohelper.c | 33 +++++++++++++++++---------------- 1 file changed, 17 insertions(+), 16 deletions(-) diff --git a/src/util/iohelper.c b/src/util/iohelper.c index 5fc311b..1896fd3 100644 --- a/src/util/iohelper.c +++ b/src/util/iohelper.c @@ -55,7 +55,6 @@ runIO(const char *path, int fd, int oflags) const char *fdinname, *fdoutname; unsigned long long total =3D 0; bool direct =3D O_DIRECT && ((oflags & O_DIRECT) !=3D 0); - bool shortRead =3D false; /* true if we hit a short read */ off_t end =3D 0; =20 #if HAVE_POSIX_MEMALIGN @@ -115,30 +114,32 @@ runIO(const char *path, int fd, int oflags) goto cleanup; } if (got =3D=3D 0) - break; /* End of file before end of requested data */ - if (got < buflen) { - /* O_DIRECT can handle at most one short read, at end of file = */ - if (direct && shortRead) { - virReportSystemError(EINVAL, "%s", - _("Too many short reads for O_DIRECT"= )); - } - shortRead =3D true; - } + break; =20 total +=3D got; - if (fdout =3D=3D fd && direct && shortRead) { - end =3D total; + + /* handle last write size align in direct case */ + if (got < buflen && direct && fdout =3D=3D fd) { memset(buf + got, 0, buflen - got); got =3D (got + alignMask) & ~alignMask; + + if (safewrite(fdout, buf, got) < 0) { + virReportSystemError(errno, _("Unable to write %s"), fdout= name); + goto cleanup; + } + + if (ftruncate(fd, total) < 0) { + virReportSystemError(errno, _("Unable to truncate %s"), fd= outname); + goto cleanup; + } + + break; } + if (safewrite(fdout, buf, got) < 0) { virReportSystemError(errno, _("Unable to write %s"), fdoutname= ); goto cleanup; } - if (end && ftruncate(fd, end) < 0) { - virReportSystemError(errno, _("Unable to truncate %s"), fdoutn= ame); - goto cleanup; - } } =20 /* Ensure all data is written */ --=20 1.8.3.1 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Sun May 5 04:56:49 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 1504770826947583.0680167833331; Thu, 7 Sep 2017 00:53:46 -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 74B8CC047B60; Thu, 7 Sep 2017 07:53:45 +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 4D763187BD; Thu, 7 Sep 2017 07:53:45 +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 120763FC75; Thu, 7 Sep 2017 07:53:45 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id v877ikU8000806 for ; Thu, 7 Sep 2017 03:44:46 -0400 Received: by smtp.corp.redhat.com (Postfix) id 471E65C670; Thu, 7 Sep 2017 07:44:46 +0000 (UTC) Received: from mx1.redhat.com (ext-mx07.extmail.prod.ext.phx2.redhat.com [10.5.110.31]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 3F9CA5C66F for ; Thu, 7 Sep 2017 07:44:43 +0000 (UTC) Received: from relay.sw.ru (mailhub.sw.ru [195.214.232.25]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 0B39AC047B66 for ; Thu, 7 Sep 2017 07:44:41 +0000 (UTC) Received: from dim-vz7.qa.sw.ru (msk-vpn.virtuozzo.com [195.214.232.6]) by relay.sw.ru (8.13.4/8.13.4) with ESMTP id v877icE3023693 for ; Thu, 7 Sep 2017 10:44:38 +0300 (MSK) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 74B8CC047B60 Authentication-Results: ext-mx07.extmail.prod.ext.phx2.redhat.com; dmarc=fail (p=none dis=none) header.from=virtuozzo.com Authentication-Results: ext-mx07.extmail.prod.ext.phx2.redhat.com; spf=fail smtp.mailfrom=libvir-list-bounces@redhat.com DKIM-Filter: OpenDKIM Filter v2.11.0 mx1.redhat.com 74B8CC047B60 DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 0B39AC047B66 Authentication-Results: ext-mx07.extmail.prod.ext.phx2.redhat.com; dmarc=pass (p=none dis=none) header.from=virtuozzo.com Authentication-Results: ext-mx07.extmail.prod.ext.phx2.redhat.com; spf=pass smtp.mailfrom=nshirokovskiy@virtuozzo.com DKIM-Filter: OpenDKIM Filter v2.11.0 mx1.redhat.com 0B39AC047B66 From: Nikolay Shirokovskiy To: libvir-list@redhat.com Date: Thu, 7 Sep 2017 10:44:15 +0300 Message-Id: <1504770256-674340-4-git-send-email-nshirokovskiy@virtuozzo.com> In-Reply-To: <1504770256-674340-1-git-send-email-nshirokovskiy@virtuozzo.com> References: <1504770256-674340-1-git-send-email-nshirokovskiy@virtuozzo.com> X-Greylist: IP, sender and recipient auto-whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.31]); Thu, 07 Sep 2017 07:44:42 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.31]); Thu, 07 Sep 2017 07:44:42 +0000 (UTC) for IP:'195.214.232.25' DOMAIN:'mailhub.sw.ru' HELO:'relay.sw.ru' FROM:'nshirokovskiy@virtuozzo.com' RCPT:'' X-RedHat-Spam-Score: -0.001 (SPF_PASS) 195.214.232.25 mailhub.sw.ru 195.214.232.25 mailhub.sw.ru X-Scanned-By: MIMEDefang 2.78 on 10.5.110.31 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH 3/4] iohelper: reduce zero-out in align case 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.31]); Thu, 07 Sep 2017 07:53:45 +0000 (UTC) X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" We only need to zero-out bytes that will be written. May be we even don't need to zero-out at all because of immediate truncate. --- src/util/iohelper.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/util/iohelper.c b/src/util/iohelper.c index 1896fd3..fe15a92 100644 --- a/src/util/iohelper.c +++ b/src/util/iohelper.c @@ -120,10 +120,11 @@ runIO(const char *path, int fd, int oflags) =20 /* handle last write size align in direct case */ if (got < buflen && direct && fdout =3D=3D fd) { - memset(buf + got, 0, buflen - got); - got =3D (got + alignMask) & ~alignMask; + ssize_t aligned_got =3D (got + alignMask) & ~alignMask; =20 - if (safewrite(fdout, buf, got) < 0) { + memset(buf + got, 0, aligned_got - got); + + if (safewrite(fdout, buf, aligned_got) < 0) { virReportSystemError(errno, _("Unable to write %s"), fdout= name); goto cleanup; } --=20 1.8.3.1 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Sun May 5 04:56:49 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 1504770784096766.403311438027; Thu, 7 Sep 2017 00:53:04 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 98E99356D0; Thu, 7 Sep 2017 07:53:02 +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 70B4461F21; Thu, 7 Sep 2017 07:53:02 +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 D49FC3FC74; Thu, 7 Sep 2017 07:53:01 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id v877ijVX000796 for ; Thu, 7 Sep 2017 03:44:45 -0400 Received: by smtp.corp.redhat.com (Postfix) id 82DE7187BD; Thu, 7 Sep 2017 07:44:45 +0000 (UTC) Received: from mx1.redhat.com (ext-mx07.extmail.prod.ext.phx2.redhat.com [10.5.110.31]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 7D7A060D10 for ; Thu, 7 Sep 2017 07:44:43 +0000 (UTC) Received: from relay.sw.ru (mailhub.sw.ru [195.214.232.25]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 0D3E8C047B67 for ; Thu, 7 Sep 2017 07:44:41 +0000 (UTC) Received: from dim-vz7.qa.sw.ru (msk-vpn.virtuozzo.com [195.214.232.6]) by relay.sw.ru (8.13.4/8.13.4) with ESMTP id v877icE4023693 for ; Thu, 7 Sep 2017 10:44:39 +0300 (MSK) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 98E99356D0 Authentication-Results: ext-mx06.extmail.prod.ext.phx2.redhat.com; dmarc=fail (p=none dis=none) header.from=virtuozzo.com Authentication-Results: ext-mx06.extmail.prod.ext.phx2.redhat.com; spf=fail smtp.mailfrom=libvir-list-bounces@redhat.com DKIM-Filter: OpenDKIM Filter v2.11.0 mx1.redhat.com 98E99356D0 DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 0D3E8C047B67 Authentication-Results: ext-mx07.extmail.prod.ext.phx2.redhat.com; dmarc=pass (p=none dis=none) header.from=virtuozzo.com Authentication-Results: ext-mx07.extmail.prod.ext.phx2.redhat.com; spf=pass smtp.mailfrom=nshirokovskiy@virtuozzo.com DKIM-Filter: OpenDKIM Filter v2.11.0 mx1.redhat.com 0D3E8C047B67 From: Nikolay Shirokovskiy To: libvir-list@redhat.com Date: Thu, 7 Sep 2017 10:44:16 +0300 Message-Id: <1504770256-674340-5-git-send-email-nshirokovskiy@virtuozzo.com> In-Reply-To: <1504770256-674340-1-git-send-email-nshirokovskiy@virtuozzo.com> References: <1504770256-674340-1-git-send-email-nshirokovskiy@virtuozzo.com> X-Greylist: IP, sender and recipient auto-whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.31]); Thu, 07 Sep 2017 07:44:42 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.31]); Thu, 07 Sep 2017 07:44:42 +0000 (UTC) for IP:'195.214.232.25' DOMAIN:'mailhub.sw.ru' HELO:'relay.sw.ru' FROM:'nshirokovskiy@virtuozzo.com' RCPT:'' X-RedHat-Spam-Score: -0.001 (SPF_PASS) 195.214.232.25 mailhub.sw.ru 195.214.232.25 mailhub.sw.ru X-Scanned-By: MIMEDefang 2.78 on 10.5.110.31 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH 4/4] iohelper: fix reading with O_DIRECT 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.15 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.30]); Thu, 07 Sep 2017 07:53:03 +0000 (UTC) X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" saferead is not suitable for direct reads. If file size is not multiple of align size then we get EINVAL on the read(2) that is supposed to return 0 because read buffer will not be aligned at this point. Let's not read again after partial read and check that we read everything by comparing the number of total bytes read against file size. --- src/util/iohelper.c | 40 +++++++++++++++++++++++++++++++++++----- 1 file changed, 35 insertions(+), 5 deletions(-) diff --git a/src/util/iohelper.c b/src/util/iohelper.c index fe15a92..32c5a89 100644 --- a/src/util/iohelper.c +++ b/src/util/iohelper.c @@ -78,10 +78,22 @@ runIO(const char *path, int fd, int oflags) fdoutname =3D "stdout"; /* To make the implementation simpler, we give up on any * attempt to use O_DIRECT in a non-trivial manner. */ - if (direct && ((end =3D lseek(fd, 0, SEEK_CUR)) !=3D 0)) { - virReportSystemError(end < 0 ? errno : EINVAL, "%s", - _("O_DIRECT read needs entire seekable fi= le")); - goto cleanup; + if (direct) { + if ((end =3D lseek(fd, 0, SEEK_CUR)) !=3D 0) { + virReportSystemError(end < 0 ? errno : EINVAL, "%s", + _("O_DIRECT read needs entire seekabl= e file")); + goto cleanup; + } + + if ((end =3D lseek(fd, 0, SEEK_END)) < 0) { + virReportSystemError(errno, "%s", _("can not seek file end= ")); + goto cleanup; + } + + if (lseek(fd, 0, SEEK_SET) < 0) { + virReportSystemError(errno, "%s", _("can not seek file beg= in")); + goto cleanup; + } } break; case O_WRONLY: @@ -109,7 +121,25 @@ runIO(const char *path, int fd, int oflags) while (1) { ssize_t got; =20 - if ((got =3D saferead(fdin, buf, buflen)) < 0) { + /* in case of O_DIRECT we cannot read again to check for EOF + * after partial buffer read as it is done in saferead */ + if (direct && fdin =3D=3D fd && end - total < buflen) { + if (total =3D=3D end) + break; + + while ((got =3D read(fd, buf, buflen)) < 0 && errno =3D=3D EIN= TR); + + if (got < end - total) { + virReportError(VIR_ERR_INTERNAL_ERROR, + _("Unable to read last chunk from %s"), + fdinname); + goto cleanup; + } + } else { + got =3D saferead(fdin, buf, buflen); + } + + if (got < 0) { virReportSystemError(errno, _("Unable to read %s"), fdinname); goto cleanup; } --=20 1.8.3.1 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list