diff options
Diffstat (limited to 'meta/recipes-devtools/qemu/qemu/0001-osdep-Add-runtime-OFD-lock-detection.patch')
-rw-r--r-- | meta/recipes-devtools/qemu/qemu/0001-osdep-Add-runtime-OFD-lock-detection.patch | 141 |
1 files changed, 0 insertions, 141 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 deleted file mode 100644 index f83f0d2055..0000000000 --- a/meta/recipes-devtools/qemu/qemu/0001-osdep-Add-runtime-OFD-lock-detection.patch +++ /dev/null | |||
@@ -1,141 +0,0 @@ | |||
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 | |||