diff options
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 @@ | |||
1 | From ca749954b09b89e22cd69c4949fb7e689b057963 Mon Sep 17 00:00:00 2001 | ||
2 | From: Fam Zheng <famz@redhat.com> | ||
3 | Date: Fri, 11 Aug 2017 19:44:46 +0800 | ||
4 | Subject: [PATCH 1/2] osdep: Add runtime OFD lock detection | ||
5 | |||
6 | Build time check of OFD lock is not sufficient and can cause image open | ||
7 | errors when the runtime environment doesn't support it. | ||
8 | |||
9 | Add a helper function to probe it at runtime, additionally. Also provide | ||
10 | a qemu_has_ofd_lock() for callers to check the status. | ||
11 | |||
12 | Signed-off-by: Fam Zheng <famz@redhat.com> | ||
13 | Signed-off-by: Kevin Wolf <kwolf@redhat.com> | ||
14 | |||
15 | Upstream-Status: Backport | ||
16 | Signed-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 | |||
22 | diff --git a/include/qemu/osdep.h b/include/qemu/osdep.h | ||
23 | index 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" | ||
34 | diff --git a/util/osdep.c b/util/osdep.c | ||
35 | index 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 | -- | ||
140 | 2.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 @@ | |||
1 | From 2b218f5dbcca5fe728b1852d161d7a21fd02b2f5 Mon Sep 17 00:00:00 2001 | ||
2 | From: Fam Zheng <famz@redhat.com> | ||
3 | Date: Fri, 11 Aug 2017 19:44:47 +0800 | ||
4 | Subject: [PATCH 2/2] file-posix: Do runtime check for ofd lock API | ||
5 | |||
6 | It is reported that on Windows Subsystem for Linux, ofd operations fail | ||
7 | with -EINVAL. In other words, QEMU binary built with system headers that | ||
8 | exports F_OFD_SETLK doesn't necessarily run in an environment that | ||
9 | actually supports it: | ||
10 | |||
11 | $ qemu-system-aarch64 ... -drive file=test.vhdx,if=none,id=hd0 \ | ||
12 | -device virtio-blk-pci,drive=hd0 | ||
13 | qemu-system-aarch64: -drive file=test.vhdx,if=none,id=hd0: Failed to unlock byte 100 | ||
14 | qemu-system-aarch64: -drive file=test.vhdx,if=none,id=hd0: Failed to unlock byte 100 | ||
15 | qemu-system-aarch64: -drive file=test.vhdx,if=none,id=hd0: Failed to lock byte 100 | ||
16 | |||
17 | As a matter of fact this is not WSL specific. It can happen when running | ||
18 | a QEMU compiled against a newer glibc on an older kernel, such as in | ||
19 | a containerized environment. | ||
20 | |||
21 | Let's do a runtime check to cope with that. | ||
22 | |||
23 | Reported-by: Andrew Baumann <Andrew.Baumann@microsoft.com> | ||
24 | Reviewed-by: Eric Blake <eblake@redhat.com> | ||
25 | Signed-off-by: Fam Zheng <famz@redhat.com> | ||
26 | Signed-off-by: Kevin Wolf <kwolf@redhat.com> | ||
27 | |||
28 | Upstream-Status: Backport | ||
29 | Signed-off-by: Chen Qi <Qi.Chen@windriver.com> | ||
30 | --- | ||
31 | block/file-posix.c | 19 ++++++++----------- | ||
32 | 1 file changed, 8 insertions(+), 11 deletions(-) | ||
33 | |||
34 | diff --git a/block/file-posix.c b/block/file-posix.c | ||
35 | index 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 | -- | ||
70 | 2.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 | ||
29 | SRC_URI_append_class-native = " \ | 31 | SRC_URI_append_class-native = " \ |