From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:60882) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XMhAG-0004DU-Qi for qemu-devel@nongnu.org; Wed, 27 Aug 2014 13:37:54 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1XMhA6-0003CC-EP for qemu-devel@nongnu.org; Wed, 27 Aug 2014 13:37:44 -0400 Received: from e39.co.us.ibm.com ([32.97.110.160]:45744) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XMhA6-0003BH-75 for qemu-devel@nongnu.org; Wed, 27 Aug 2014 13:37:34 -0400 Received: from /spool/local by e39.co.us.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Wed, 27 Aug 2014 11:37:33 -0600 From: Michael Roth Date: Wed, 27 Aug 2014 12:36:14 -0500 Message-Id: <1409160982-16389-18-git-send-email-mdroth@linux.vnet.ibm.com> In-Reply-To: <1409160982-16389-1-git-send-email-mdroth@linux.vnet.ibm.com> References: <1409160982-16389-1-git-send-email-mdroth@linux.vnet.ibm.com> Subject: [Qemu-devel] [PATCH 17/25] raw-posix: fix O_DIRECT short reads List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Cc: qemu-stable@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 (cherry picked from commit 61ed73cff427206b3a959b18a4877952f566279b) Signed-off-by: Michael Roth --- block/raw-posix.c | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/block/raw-posix.c b/block/raw-posix.c index 8e9758e..87fc170 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; -- 1.9.1