From patchwork Fri Aug 22 14:51:48 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kevin Wolf X-Patchwork-Id: 382265 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [IPv6:2001:4830:134:3::11]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 77A92140090 for ; Sat, 23 Aug 2014 01:06:15 +1000 (EST) Received: from localhost ([::1]:37709 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XKqPt-000158-Hh for incoming@patchwork.ozlabs.org; Fri, 22 Aug 2014 11:06:13 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:47945) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XKqCn-0001fP-93 for qemu-devel@nongnu.org; Fri, 22 Aug 2014 10:52:46 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1XKqCh-0005yR-Pz for qemu-devel@nongnu.org; Fri, 22 Aug 2014 10:52:41 -0400 Received: from mx1.redhat.com ([209.132.183.28]:27380) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XKqCh-0005yN-Ib for qemu-devel@nongnu.org; Fri, 22 Aug 2014 10:52:35 -0400 Received: from int-mx09.intmail.prod.int.phx2.redhat.com (int-mx09.intmail.prod.int.phx2.redhat.com [10.5.11.22]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id s7MEqZTK016960 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK) for ; Fri, 22 Aug 2014 10:52:35 -0400 Received: from noname.redhat.com (ovpn-116-98.ams2.redhat.com [10.36.116.98]) by int-mx09.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id s7MEptpS005727; Fri, 22 Aug 2014 10:52:33 -0400 From: Kevin Wolf To: qemu-devel@nongnu.org Date: Fri, 22 Aug 2014 16:51:48 +0200 Message-Id: <1408719113-5316-25-git-send-email-kwolf@redhat.com> In-Reply-To: <1408719113-5316-1-git-send-email-kwolf@redhat.com> References: <1408719113-5316-1-git-send-email-kwolf@redhat.com> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.22 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x X-Received-From: 209.132.183.28 Cc: kwolf@redhat.com Subject: [Qemu-devel] [PULL 24/29] raw-posix: fix O_DIRECT short reads X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org From: Stefan Hajnoczi The following O_DIRECT read from a <512 byte file fails: $ truncate -s 320 test.img $ qemu-io -n -c 'read -P 0 0 512' test.img qemu-io: can't open device test.img: Could not read image for determining its format: Invalid argument Note that qemu-io completes successfully without the -n (O_DIRECT) option. This patch fixes qemu-iotests ./check -nocache -vmdk 059. Cc: qemu-stable@nongnu.org Suggested-by: Kevin Wolf Reported-by: Markus Armbruster Signed-off-by: Stefan Hajnoczi Signed-off-by: Kevin Wolf --- block/raw-posix.c | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/block/raw-posix.c b/block/raw-posix.c index 5c745b9..d737f3a 100644 --- a/block/raw-posix.c +++ b/block/raw-posix.c @@ -747,6 +747,15 @@ static ssize_t handle_aiocb_rw_linear(RawPosixAIOData *aiocb, char *buf) } if (len == -1 && errno == EINTR) { continue; + } else if (len == -1 && errno == EINVAL && + (aiocb->bs->open_flags & BDRV_O_NOCACHE) && + !(aiocb->aio_type & QEMU_AIO_WRITE) && + offset > 0) { + /* O_DIRECT pread() may fail with EINVAL when offset is unaligned + * after a short read. Assume that O_DIRECT short reads only occur + * at EOF. Therefore this is a short read, not an I/O error. + */ + break; } else if (len == -1) { offset = -errno; break;