|
|
9ae3a8 |
From ea0e0a4820d0dfa1227bd8351d89e9d55b25da44 Mon Sep 17 00:00:00 2001
|
|
|
9ae3a8 |
From: Stefan Hajnoczi <stefanha@redhat.com>
|
|
|
9ae3a8 |
Date: Tue, 17 Mar 2015 12:59:01 +0100
|
|
|
9ae3a8 |
Subject: [PATCH 12/16] raw-posix: Fail gracefully if no working alignment is
|
|
|
9ae3a8 |
found
|
|
|
9ae3a8 |
|
|
|
9ae3a8 |
Message-id: <1424365599-9801-3-git-send-email-stefanha@redhat.com>
|
|
|
9ae3a8 |
Patchwork-id: 63913
|
|
|
9ae3a8 |
O-Subject: [RHEL-7.1 qemu-kvm PATCH 2/2] raw-posix: Fail gracefully if no working alignment is found
|
|
|
9ae3a8 |
Bugzilla: 1184363
|
|
|
9ae3a8 |
RH-Acked-by: Max Reitz <mreitz@redhat.com>
|
|
|
9ae3a8 |
RH-Acked-by: John Snow <jsnow@redhat.com>
|
|
|
9ae3a8 |
RH-Acked-by: Laszlo Ersek <lersek@redhat.com>
|
|
|
9ae3a8 |
|
|
|
9ae3a8 |
From: Kevin Wolf <kwolf@redhat.com>
|
|
|
9ae3a8 |
|
|
|
9ae3a8 |
If qemu couldn't find out what O_DIRECT alignment to use with a given
|
|
|
9ae3a8 |
file, it would run into assert(bdrv_opt_mem_align(bs) != 0); in block.c
|
|
|
9ae3a8 |
and confuse users. This adds a more descriptive error message for such
|
|
|
9ae3a8 |
cases.
|
|
|
9ae3a8 |
|
|
|
9ae3a8 |
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
|
|
|
9ae3a8 |
Reviewed-by: Eric Blake <eblake@redhat.com>
|
|
|
9ae3a8 |
Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
|
|
|
9ae3a8 |
(cherry picked from commit df26a35025427f34c1d4e5a8e51152371a5e231e)
|
|
|
9ae3a8 |
Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
|
|
|
9ae3a8 |
---
|
|
|
9ae3a8 |
block/raw-posix.c | 35 +++++++++++++++++++++++++++--------
|
|
|
9ae3a8 |
1 file changed, 27 insertions(+), 8 deletions(-)
|
|
|
9ae3a8 |
|
|
|
9ae3a8 |
diff --git a/block/raw-posix.c b/block/raw-posix.c
|
|
|
9ae3a8 |
index 6a50856..af526ca 100644
|
|
|
9ae3a8 |
--- a/block/raw-posix.c
|
|
|
9ae3a8 |
+++ b/block/raw-posix.c
|
|
|
9ae3a8 |
@@ -213,7 +213,7 @@ static int raw_normalize_devicepath(const char **filename)
|
|
|
9ae3a8 |
}
|
|
|
9ae3a8 |
#endif
|
|
|
9ae3a8 |
|
|
|
9ae3a8 |
-static void raw_probe_alignment(BlockDriverState *bs)
|
|
|
9ae3a8 |
+static void raw_probe_alignment(BlockDriverState *bs, int fd, Error **errp)
|
|
|
9ae3a8 |
{
|
|
|
9ae3a8 |
BDRVRawState *s = bs->opaque;
|
|
|
9ae3a8 |
char *buf;
|
|
|
9ae3a8 |
@@ -232,24 +232,24 @@ static void raw_probe_alignment(BlockDriverState *bs)
|
|
|
9ae3a8 |
s->buf_align = 0;
|
|
|
9ae3a8 |
|
|
|
9ae3a8 |
#ifdef BLKSSZGET
|
|
|
9ae3a8 |
- if (ioctl(s->fd, BLKSSZGET, §or_size) >= 0) {
|
|
|
9ae3a8 |
+ if (ioctl(fd, BLKSSZGET, §or_size) >= 0) {
|
|
|
9ae3a8 |
bs->request_alignment = sector_size;
|
|
|
9ae3a8 |
}
|
|
|
9ae3a8 |
#endif
|
|
|
9ae3a8 |
#ifdef DKIOCGETBLOCKSIZE
|
|
|
9ae3a8 |
- if (ioctl(s->fd, DKIOCGETBLOCKSIZE, §or_size) >= 0) {
|
|
|
9ae3a8 |
+ if (ioctl(fd, DKIOCGETBLOCKSIZE, §or_size) >= 0) {
|
|
|
9ae3a8 |
bs->request_alignment = sector_size;
|
|
|
9ae3a8 |
}
|
|
|
9ae3a8 |
#endif
|
|
|
9ae3a8 |
#ifdef DIOCGSECTORSIZE
|
|
|
9ae3a8 |
- if (ioctl(s->fd, DIOCGSECTORSIZE, §or_size) >= 0) {
|
|
|
9ae3a8 |
+ if (ioctl(fd, DIOCGSECTORSIZE, §or_size) >= 0) {
|
|
|
9ae3a8 |
bs->request_alignment = sector_size;
|
|
|
9ae3a8 |
}
|
|
|
9ae3a8 |
#endif
|
|
|
9ae3a8 |
#ifdef CONFIG_XFS
|
|
|
9ae3a8 |
if (s->is_xfs) {
|
|
|
9ae3a8 |
struct dioattr da;
|
|
|
9ae3a8 |
- if (xfsctl(NULL, s->fd, XFS_IOC_DIOINFO, &da) >= 0) {
|
|
|
9ae3a8 |
+ if (xfsctl(NULL, fd, XFS_IOC_DIOINFO, &da) >= 0) {
|
|
|
9ae3a8 |
bs->request_alignment = da.d_miniosz;
|
|
|
9ae3a8 |
/* The kernel returns wrong information for d_mem */
|
|
|
9ae3a8 |
/* s->buf_align = da.d_mem; */
|
|
|
9ae3a8 |
@@ -262,7 +262,7 @@ static void raw_probe_alignment(BlockDriverState *bs)
|
|
|
9ae3a8 |
size_t align;
|
|
|
9ae3a8 |
buf = qemu_memalign(MAX_BLOCKSIZE, 2 * MAX_BLOCKSIZE);
|
|
|
9ae3a8 |
for (align = 512; align <= MAX_BLOCKSIZE; align <<= 1) {
|
|
|
9ae3a8 |
- if (pread(s->fd, buf + align, MAX_BLOCKSIZE, 0) >= 0) {
|
|
|
9ae3a8 |
+ if (pread(fd, buf + align, MAX_BLOCKSIZE, 0) >= 0) {
|
|
|
9ae3a8 |
s->buf_align = align;
|
|
|
9ae3a8 |
break;
|
|
|
9ae3a8 |
}
|
|
|
9ae3a8 |
@@ -274,13 +274,18 @@ static void raw_probe_alignment(BlockDriverState *bs)
|
|
|
9ae3a8 |
size_t align;
|
|
|
9ae3a8 |
buf = qemu_memalign(s->buf_align, MAX_BLOCKSIZE);
|
|
|
9ae3a8 |
for (align = 512; align <= MAX_BLOCKSIZE; align <<= 1) {
|
|
|
9ae3a8 |
- if (pread(s->fd, buf, align, 0) >= 0) {
|
|
|
9ae3a8 |
+ if (pread(fd, buf, align, 0) >= 0) {
|
|
|
9ae3a8 |
bs->request_alignment = align;
|
|
|
9ae3a8 |
break;
|
|
|
9ae3a8 |
}
|
|
|
9ae3a8 |
}
|
|
|
9ae3a8 |
qemu_vfree(buf);
|
|
|
9ae3a8 |
}
|
|
|
9ae3a8 |
+
|
|
|
9ae3a8 |
+ if (!s->buf_align || !bs->request_alignment) {
|
|
|
9ae3a8 |
+ error_setg(errp, "Could not find working O_DIRECT alignment. "
|
|
|
9ae3a8 |
+ "Try cache.direct=off.");
|
|
|
9ae3a8 |
+ }
|
|
|
9ae3a8 |
}
|
|
|
9ae3a8 |
|
|
|
9ae3a8 |
static void raw_parse_flags(int bdrv_flags, int *open_flags)
|
|
|
9ae3a8 |
@@ -459,6 +464,7 @@ static int raw_reopen_prepare(BDRVReopenState *state,
|
|
|
9ae3a8 |
BDRVRawState *s;
|
|
|
9ae3a8 |
BDRVRawReopenState *raw_s;
|
|
|
9ae3a8 |
int ret = 0;
|
|
|
9ae3a8 |
+ Error *local_err = NULL;
|
|
|
9ae3a8 |
|
|
|
9ae3a8 |
assert(state != NULL);
|
|
|
9ae3a8 |
assert(state->bs != NULL);
|
|
|
9ae3a8 |
@@ -531,6 +537,19 @@ static int raw_reopen_prepare(BDRVReopenState *state,
|
|
|
9ae3a8 |
ret = -1;
|
|
|
9ae3a8 |
}
|
|
|
9ae3a8 |
}
|
|
|
9ae3a8 |
+
|
|
|
9ae3a8 |
+ /* Fail already reopen_prepare() if we can't get a working O_DIRECT
|
|
|
9ae3a8 |
+ * alignment with the new fd. */
|
|
|
9ae3a8 |
+ if (raw_s->fd != -1) {
|
|
|
9ae3a8 |
+ raw_probe_alignment(state->bs, raw_s->fd, &local_err);
|
|
|
9ae3a8 |
+ if (local_err) {
|
|
|
9ae3a8 |
+ qemu_close(raw_s->fd);
|
|
|
9ae3a8 |
+ raw_s->fd = -1;
|
|
|
9ae3a8 |
+ error_propagate(errp, local_err);
|
|
|
9ae3a8 |
+ ret = -EINVAL;
|
|
|
9ae3a8 |
+ }
|
|
|
9ae3a8 |
+ }
|
|
|
9ae3a8 |
+
|
|
|
9ae3a8 |
return ret;
|
|
|
9ae3a8 |
}
|
|
|
9ae3a8 |
|
|
|
9ae3a8 |
@@ -573,7 +592,7 @@ static int raw_refresh_limits(BlockDriverState *bs)
|
|
|
9ae3a8 |
{
|
|
|
9ae3a8 |
BDRVRawState *s = bs->opaque;
|
|
|
9ae3a8 |
|
|
|
9ae3a8 |
- raw_probe_alignment(bs);
|
|
|
9ae3a8 |
+ raw_probe_alignment(bs, s->fd, errp);
|
|
|
9ae3a8 |
bs->bl.opt_mem_alignment = s->buf_align;
|
|
|
9ae3a8 |
|
|
|
9ae3a8 |
return 0;
|
|
|
9ae3a8 |
--
|
|
|
9ae3a8 |
1.8.3.1
|
|
|
9ae3a8 |
|