summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorChen Qi <Qi.Chen@windriver.com>2017-08-18 18:19:13 +0800
committerRichard Purdie <richard.purdie@linuxfoundation.org>2017-08-19 22:15:39 +0100
commit045e3f9283b879f0a09a1512ec509b0c86948b45 (patch)
tree60ea3050908e22a8d7beaca221e3f3be2c4f2d67
parentee195eb03460e9dca41084695d4775ec830cfde7 (diff)
downloadpoky-045e3f9283b879f0a09a1512ec509b0c86948b45.tar.gz
qemu: backport patches to fix boot failure
Backport two patches to fix the following error when booting qemu. Failed to unlock byte 100 (From OE-Core rev: 91eee8b08cd52f49bb1c8f8c680607b3f3a52d24) Signed-off-by: Chen Qi <Qi.Chen@windriver.com> Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
-rw-r--r--meta/recipes-devtools/qemu/qemu/0001-osdep-Add-runtime-OFD-lock-detection.patch141
-rw-r--r--meta/recipes-devtools/qemu/qemu/0002-file-posix-Do-runtime-check-for-ofd-lock-API.patch71
-rw-r--r--meta/recipes-devtools/qemu/qemu_2.10.0-rc2.bb2
3 files changed, 214 insertions, 0 deletions
diff --git a/meta/recipes-devtools/qemu/qemu/0001-osdep-Add-runtime-OFD-lock-detection.patch b/meta/recipes-devtools/qemu/qemu/0001-osdep-Add-runtime-OFD-lock-detection.patch
new file mode 100644
index 0000000000..f83f0d2055
--- /dev/null
+++ b/meta/recipes-devtools/qemu/qemu/0001-osdep-Add-runtime-OFD-lock-detection.patch
@@ -0,0 +1,141 @@
1From ca749954b09b89e22cd69c4949fb7e689b057963 Mon Sep 17 00:00:00 2001
2From: Fam Zheng <famz@redhat.com>
3Date: Fri, 11 Aug 2017 19:44:46 +0800
4Subject: [PATCH 1/2] osdep: Add runtime OFD lock detection
5
6Build time check of OFD lock is not sufficient and can cause image open
7errors when the runtime environment doesn't support it.
8
9Add a helper function to probe it at runtime, additionally. Also provide
10a qemu_has_ofd_lock() for callers to check the status.
11
12Signed-off-by: Fam Zheng <famz@redhat.com>
13Signed-off-by: Kevin Wolf <kwolf@redhat.com>
14
15Upstream-Status: Backport
16Signed-off-by: Chen Qi <Qi.Chen@windriver.com>
17---
18 include/qemu/osdep.h | 1 +
19 util/osdep.c | 66 ++++++++++++++++++++++++++++++++++++++++++++--------
20 2 files changed, 57 insertions(+), 10 deletions(-)
21
22diff --git a/include/qemu/osdep.h b/include/qemu/osdep.h
23index 3b74f6fcb2..6855b94bbf 100644
24--- a/include/qemu/osdep.h
25+++ b/include/qemu/osdep.h
26@@ -357,6 +357,7 @@ int qemu_dup(int fd);
27 int qemu_lock_fd(int fd, int64_t start, int64_t len, bool exclusive);
28 int qemu_unlock_fd(int fd, int64_t start, int64_t len);
29 int qemu_lock_fd_test(int fd, int64_t start, int64_t len, bool exclusive);
30+bool qemu_has_ofd_lock(void);
31
32 #if defined(__HAIKU__) && defined(__i386__)
33 #define FMT_pid "%ld"
34diff --git a/util/osdep.c b/util/osdep.c
35index a2863c8e53..a479fedc4a 100644
36--- a/util/osdep.c
37+++ b/util/osdep.c
38@@ -38,14 +38,6 @@ extern int madvise(caddr_t, size_t, int);
39 #include "qemu/error-report.h"
40 #include "monitor/monitor.h"
41
42-#ifdef F_OFD_SETLK
43-#define QEMU_SETLK F_OFD_SETLK
44-#define QEMU_GETLK F_OFD_GETLK
45-#else
46-#define QEMU_SETLK F_SETLK
47-#define QEMU_GETLK F_GETLK
48-#endif
49-
50 static bool fips_enabled = false;
51
52 static const char *hw_version = QEMU_HW_VERSION;
53@@ -82,6 +74,10 @@ int qemu_madvise(void *addr, size_t len, int advice)
54 }
55
56 #ifndef _WIN32
57+
58+static int fcntl_op_setlk = -1;
59+static int fcntl_op_getlk = -1;
60+
61 /*
62 * Dups an fd and sets the flags
63 */
64@@ -149,6 +145,54 @@ static int qemu_parse_fdset(const char *param)
65 return qemu_parse_fd(param);
66 }
67
68+static void qemu_probe_lock_ops(void)
69+{
70+ if (fcntl_op_setlk == -1) {
71+#ifdef F_OFD_SETLK
72+ int fd;
73+ int ret;
74+ struct flock fl = {
75+ .l_whence = SEEK_SET,
76+ .l_start = 0,
77+ .l_len = 0,
78+ .l_type = F_WRLCK,
79+ };
80+
81+ fd = open("/dev/null", O_RDWR);
82+ if (fd < 0) {
83+ fprintf(stderr,
84+ "Failed to open /dev/null for OFD lock probing: %s\n",
85+ strerror(errno));
86+ fcntl_op_setlk = F_SETLK;
87+ fcntl_op_getlk = F_GETLK;
88+ return;
89+ }
90+ ret = fcntl(fd, F_OFD_GETLK, &fl);
91+ close(fd);
92+ if (!ret) {
93+ fcntl_op_setlk = F_OFD_SETLK;
94+ fcntl_op_getlk = F_OFD_GETLK;
95+ } else {
96+ fcntl_op_setlk = F_SETLK;
97+ fcntl_op_getlk = F_GETLK;
98+ }
99+#else
100+ fcntl_op_setlk = F_SETLK;
101+ fcntl_op_getlk = F_GETLK;
102+#endif
103+ }
104+}
105+
106+bool qemu_has_ofd_lock(void)
107+{
108+ qemu_probe_lock_ops();
109+#ifdef F_OFD_SETLK
110+ return fcntl_op_setlk == F_OFD_SETLK;
111+#else
112+ return false;
113+#endif
114+}
115+
116 static int qemu_lock_fcntl(int fd, int64_t start, int64_t len, int fl_type)
117 {
118 int ret;
119@@ -158,7 +202,8 @@ static int qemu_lock_fcntl(int fd, int64_t start, int64_t len, int fl_type)
120 .l_len = len,
121 .l_type = fl_type,
122 };
123- ret = fcntl(fd, QEMU_SETLK, &fl);
124+ qemu_probe_lock_ops();
125+ ret = fcntl(fd, fcntl_op_setlk, &fl);
126 return ret == -1 ? -errno : 0;
127 }
128
129@@ -181,7 +226,8 @@ int qemu_lock_fd_test(int fd, int64_t start, int64_t len, bool exclusive)
130 .l_len = len,
131 .l_type = exclusive ? F_WRLCK : F_RDLCK,
132 };
133- ret = fcntl(fd, QEMU_GETLK, &fl);
134+ qemu_probe_lock_ops();
135+ ret = fcntl(fd, fcntl_op_getlk, &fl);
136 if (ret == -1) {
137 return -errno;
138 } else {
139--
1402.11.0
141
diff --git a/meta/recipes-devtools/qemu/qemu/0002-file-posix-Do-runtime-check-for-ofd-lock-API.patch b/meta/recipes-devtools/qemu/qemu/0002-file-posix-Do-runtime-check-for-ofd-lock-API.patch
new file mode 100644
index 0000000000..0dacde46d1
--- /dev/null
+++ b/meta/recipes-devtools/qemu/qemu/0002-file-posix-Do-runtime-check-for-ofd-lock-API.patch
@@ -0,0 +1,71 @@
1From 2b218f5dbcca5fe728b1852d161d7a21fd02b2f5 Mon Sep 17 00:00:00 2001
2From: Fam Zheng <famz@redhat.com>
3Date: Fri, 11 Aug 2017 19:44:47 +0800
4Subject: [PATCH 2/2] file-posix: Do runtime check for ofd lock API
5
6It is reported that on Windows Subsystem for Linux, ofd operations fail
7with -EINVAL. In other words, QEMU binary built with system headers that
8exports F_OFD_SETLK doesn't necessarily run in an environment that
9actually supports it:
10
11$ qemu-system-aarch64 ... -drive file=test.vhdx,if=none,id=hd0 \
12 -device virtio-blk-pci,drive=hd0
13qemu-system-aarch64: -drive file=test.vhdx,if=none,id=hd0: Failed to unlock byte 100
14qemu-system-aarch64: -drive file=test.vhdx,if=none,id=hd0: Failed to unlock byte 100
15qemu-system-aarch64: -drive file=test.vhdx,if=none,id=hd0: Failed to lock byte 100
16
17As a matter of fact this is not WSL specific. It can happen when running
18a QEMU compiled against a newer glibc on an older kernel, such as in
19a containerized environment.
20
21Let's do a runtime check to cope with that.
22
23Reported-by: Andrew Baumann <Andrew.Baumann@microsoft.com>
24Reviewed-by: Eric Blake <eblake@redhat.com>
25Signed-off-by: Fam Zheng <famz@redhat.com>
26Signed-off-by: Kevin Wolf <kwolf@redhat.com>
27
28Upstream-Status: Backport
29Signed-off-by: Chen Qi <Qi.Chen@windriver.com>
30---
31 block/file-posix.c | 19 ++++++++-----------
32 1 file changed, 8 insertions(+), 11 deletions(-)
33
34diff --git a/block/file-posix.c b/block/file-posix.c
35index f4de022ae0..cb3bfce147 100644
36--- a/block/file-posix.c
37+++ b/block/file-posix.c
38@@ -457,22 +457,19 @@ static int raw_open_common(BlockDriverState *bs, QDict *options,
39 switch (locking) {
40 case ON_OFF_AUTO_ON:
41 s->use_lock = true;
42-#ifndef F_OFD_SETLK
43- fprintf(stderr,
44- "File lock requested but OFD locking syscall is unavailable, "
45- "falling back to POSIX file locks.\n"
46- "Due to the implementation, locks can be lost unexpectedly.\n");
47-#endif
48+ if (!qemu_has_ofd_lock()) {
49+ fprintf(stderr,
50+ "File lock requested but OFD locking syscall is "
51+ "unavailable, falling back to POSIX file locks.\n"
52+ "Due to the implementation, locks can be lost "
53+ "unexpectedly.\n");
54+ }
55 break;
56 case ON_OFF_AUTO_OFF:
57 s->use_lock = false;
58 break;
59 case ON_OFF_AUTO_AUTO:
60-#ifdef F_OFD_SETLK
61- s->use_lock = true;
62-#else
63- s->use_lock = false;
64-#endif
65+ s->use_lock = qemu_has_ofd_lock();
66 break;
67 default:
68 abort();
69--
702.11.0
71
diff --git a/meta/recipes-devtools/qemu/qemu_2.10.0-rc2.bb b/meta/recipes-devtools/qemu/qemu_2.10.0-rc2.bb
index 04d656ba39..08eaf19737 100644
--- a/meta/recipes-devtools/qemu/qemu_2.10.0-rc2.bb
+++ b/meta/recipes-devtools/qemu/qemu_2.10.0-rc2.bb
@@ -24,6 +24,8 @@ SRC_URI = "http://wiki.qemu-project.org/download/${BP}.tar.bz2 \
24 file://0003-Introduce-condition-in-TPM-backend-for-notification.patch \ 24 file://0003-Introduce-condition-in-TPM-backend-for-notification.patch \
25 file://0004-Add-support-for-VM-suspend-resume-for-TPM-TIS-v2.9.patch \ 25 file://0004-Add-support-for-VM-suspend-resume-for-TPM-TIS-v2.9.patch \
26 file://apic-fixup-fallthrough-to-PIC.patch \ 26 file://apic-fixup-fallthrough-to-PIC.patch \
27 file://0001-osdep-Add-runtime-OFD-lock-detection.patch \
28 file://0002-file-posix-Do-runtime-check-for-ofd-lock-API.patch \
27 " 29 "
28 30
29SRC_URI_append_class-native = " \ 31SRC_URI_append_class-native = " \