[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [PULL 71/73] block/raw-posix: fix launching with failed dis
From: |
Kevin Wolf |
Subject: |
[Qemu-devel] [PULL 71/73] block/raw-posix: fix launching with failed disks |
Date: |
Mon, 9 Mar 2015 16:41:56 +0100 |
From: Stefan Hajnoczi <address@hidden>
Since commit c25f53b06eba1575d5d0e92a0132455c97825b83 ("raw: Probe
required direct I/O alignment") QEMU has failed to launch if image files
produce I/O errors.
Previously, QEMU would launch successfully and the guest would see the
errors when attempting I/O.
This is a regression and may prevent multipath I/O inside the guest,
where QEMU must launch and let the guest figure out by itself which
disks are online.
Tweak the alignment probing code in raw-posix.c to explicitly look for
EINVAL on Linux instead of bailing. The kernel refuses misaligned
requests with this error code and other error codes can be ignored.
Signed-off-by: Stefan Hajnoczi <address@hidden>
Signed-off-by: Kevin Wolf <address@hidden>
---
block/raw-posix.c | 29 +++++++++++++++++++++++++++--
1 file changed, 27 insertions(+), 2 deletions(-)
diff --git a/block/raw-posix.c b/block/raw-posix.c
index 3263d2b..f0b4488 100644
--- a/block/raw-posix.c
+++ b/block/raw-posix.c
@@ -272,6 +272,31 @@ static int probe_physical_blocksize(int fd, unsigned int
*blk_size)
#endif
}
+/* Check if read is allowed with given memory buffer and length.
+ *
+ * This function is used to check O_DIRECT memory buffer and request alignment.
+ */
+static bool raw_is_io_aligned(int fd, void *buf, size_t len)
+{
+ ssize_t ret = pread(fd, buf, len, 0);
+
+ if (ret >= 0) {
+ return true;
+ }
+
+#ifdef __linux__
+ /* The Linux kernel returns EINVAL for misaligned O_DIRECT reads. Ignore
+ * other errors (e.g. real I/O error), which could happen on a failed
+ * drive, since we only care about probing alignment.
+ */
+ if (errno != EINVAL) {
+ return true;
+ }
+#endif
+
+ return false;
+}
+
static void raw_probe_alignment(BlockDriverState *bs, int fd, Error **errp)
{
BDRVRawState *s = bs->opaque;
@@ -307,7 +332,7 @@ static void raw_probe_alignment(BlockDriverState *bs, int
fd, Error **errp)
size_t align;
buf = qemu_memalign(MAX_BLOCKSIZE, 2 * MAX_BLOCKSIZE);
for (align = 512; align <= MAX_BLOCKSIZE; align <<= 1) {
- if (pread(fd, buf + align, MAX_BLOCKSIZE, 0) >= 0) {
+ if (raw_is_io_aligned(fd, buf + align, MAX_BLOCKSIZE)) {
s->buf_align = align;
break;
}
@@ -319,7 +344,7 @@ static void raw_probe_alignment(BlockDriverState *bs, int
fd, Error **errp)
size_t align;
buf = qemu_memalign(s->buf_align, MAX_BLOCKSIZE);
for (align = 512; align <= MAX_BLOCKSIZE; align <<= 1) {
- if (pread(fd, buf, align, 0) >= 0) {
+ if (raw_is_io_aligned(fd, buf, align)) {
bs->request_alignment = align;
break;
}
--
1.8.3.1
- [Qemu-devel] [PULL 00/73] Block patches, Kevin Wolf, 2015/03/09
- [Qemu-devel] [PULL 65/73] iotests: Drop vpc from 004's and 104's format list, Kevin Wolf, 2015/03/09
- [Qemu-devel] [PULL 62/73] virtio-blk: Remove the stale FIXME comment, Kevin Wolf, 2015/03/09
- [Qemu-devel] [PULL 70/73] MAINTAINERS: Add jsnow as IDE maintainer, Kevin Wolf, 2015/03/09
- [Qemu-devel] [PULL 63/73] iotests: Fix 051's reference output, Kevin Wolf, 2015/03/09
- [Qemu-devel] [PULL 71/73] block/raw-posix: fix launching with failed disks,
Kevin Wolf <=
- [Qemu-devel] [PULL 66/73] block/vdi: Add locking for parallel requests, Kevin Wolf, 2015/03/09
- [Qemu-devel] [PULL 67/73] scsi-hd: fix property unset case, Kevin Wolf, 2015/03/09
- [Qemu-devel] [PULL 72/73] iotests: add O_DIRECT alignment probing test, Kevin Wolf, 2015/03/09
- [Qemu-devel] [PULL 64/73] iotests: Remove 006, Kevin Wolf, 2015/03/09
- [Qemu-devel] [PULL 68/73] Add testcase for scsi-hd devices without drive property, Kevin Wolf, 2015/03/09
- [Qemu-devel] [PULL 22/73] qcow2: Helper function for refcount modification, Kevin Wolf, 2015/03/09
- [Qemu-devel] [PULL 73/73] MAINTAINERS: Add jcody as blockjobs, block devices maintainer, Kevin Wolf, 2015/03/09
- [Qemu-devel] [PULL 69/73] sheepdog: Fix misleading error messages in sd_snapshot_create(), Kevin Wolf, 2015/03/09
- Re: [Qemu-devel] [PULL 00/73] Block patches, Peter Maydell, 2015/03/10