* [PATCH] block/file-posix: Use O_RDWR for locking on macOS
@ 2021-07-06 18:37 Akihiko Odaki
0 siblings, 0 replies; only message in thread
From: Akihiko Odaki @ 2021-07-06 18:37 UTC (permalink / raw)
Cc: Kevin Wolf, Akihiko Odaki, qemu-devel, qemu-block, Max Reitz
qemu_lock_fd_test always returns 0 when fd is not open for writing and
exclusive is true on macOS 11.3.1.
Signed-off-by: Akihiko Odaki <akihiko.odaki@gmail.com>
---
block/file-posix.c | 17 +++++++++++++++++
1 file changed, 17 insertions(+)
diff --git a/block/file-posix.c b/block/file-posix.c
index b3fbb9bd63a..017fbc6b055 100644
--- a/block/file-posix.c
+++ b/block/file-posix.c
@@ -130,6 +130,14 @@
#define RAW_LOCK_PERM_BASE 100
#define RAW_LOCK_SHARED_BASE 200
+/*
+ * qemu_lock_fd_test always returns 0 when fd is not open for writing and
+ * exclusive is true on macOS 11.3.1.
+ */
+#ifdef __APPLE__
+#define RAW_LOCK_WRITES
+#endif
+
typedef struct BDRVRawState {
int fd;
bool use_lock;
@@ -638,7 +646,11 @@ static int raw_open_common(BlockDriverState *bs, QDict *options,
false);
s->open_flags = open_flags;
+#ifdef RAW_LOCK_WRITES
+ raw_parse_flags(bdrv_flags, &s->open_flags, s->use_lock);
+#else
raw_parse_flags(bdrv_flags, &s->open_flags, false);
+#endif
s->fd = -1;
fd = qemu_open(filename, s->open_flags, errp);
@@ -1004,6 +1016,11 @@ static int raw_reconfigure_getfd(BlockDriverState *bs, int flags,
bool has_writers = perm &
(BLK_PERM_WRITE | BLK_PERM_WRITE_UNCHANGED | BLK_PERM_RESIZE);
int fcntl_flags = O_APPEND | O_NONBLOCK;
+#ifdef RAW_LOCK_WRITES
+ if (s->use_lock) {
+ has_writers = true;
+ }
+#endif
#ifdef O_NOATIME
fcntl_flags |= O_NOATIME;
#endif
--
2.30.1 (Apple Git-130)
^ permalink raw reply related [flat|nested] only message in thread
only message in thread, other threads:[~2021-07-06 18:39 UTC | newest]
Thread overview: (only message) (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2021-07-06 18:37 [PATCH] block/file-posix: Use O_RDWR for locking on macOS Akihiko Odaki
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).