From: Fam Zheng <famz@redhat.com>
To: qemu-devel@nongnu.org
Cc: qemu-block@nongnu.org, Kevin Wolf <kwolf@redhat.com>,
Andrew Baumann <Andrew.Baumann@microsoft.com>,
jsnow@redhat.com, Max Reitz <mreitz@redhat.com>,
eblake@redhat.com
Subject: [Qemu-devel] [PATCH 2/2] file-posix: Do runtime check for ofd lock API
Date: Fri, 21 Jul 2017 18:20:59 +0800 [thread overview]
Message-ID: <20170721102059.14663-3-famz@redhat.com> (raw)
In-Reply-To: <20170721102059.14663-1-famz@redhat.com>
It is reported that on Windows Subsystem for Linux, ofd operations fail
with -EINVAL. In other words, QEMU binary built with system headers that
exports F_OFD_SETLK doesn't necessarily run in an environment that
actually supports it:
$ qemu-system-aarch64 ... -drive file=test.vhdx,if=none,id=hd0 \
-device virtio-blk-pci,drive=hd0
qemu-system-aarch64: -drive file=test.vhdx,if=none,id=hd0: Failed to unlock byte 100
qemu-system-aarch64: -drive file=test.vhdx,if=none,id=hd0: Failed to unlock byte 100
qemu-system-aarch64: -drive file=test.vhdx,if=none,id=hd0: Failed to lock byte 100
Let's do a runtime check to cope with that.
Reported-by: Andrew Baumann <Andrew.Baumann@microsoft.com>
Signed-off-by: Fam Zheng <famz@redhat.com>
---
block/file-posix.c | 19 ++++++++-----------
1 file changed, 8 insertions(+), 11 deletions(-)
diff --git a/block/file-posix.c b/block/file-posix.c
index cfbb236f6f..5ddf2729eb 100644
--- a/block/file-posix.c
+++ b/block/file-posix.c
@@ -457,22 +457,19 @@ static int raw_open_common(BlockDriverState *bs, QDict *options,
switch (locking) {
case ON_OFF_AUTO_ON:
s->use_lock = true;
-#ifndef F_OFD_SETLK
- fprintf(stderr,
- "File lock requested but OFD locking syscall is unavailable, "
- "falling back to POSIX file locks.\n"
- "Due to the implementation, locks can be lost unexpectedly.\n");
-#endif
+ if (!qemu_has_ofd_lock()) {
+ fprintf(stderr,
+ "File lock requested but OFD locking syscall is "
+ "unavailable, falling back to POSIX file locks.\n"
+ "Due to the implementation, locks can be lost "
+ "unexpectedly.\n");
+ }
break;
case ON_OFF_AUTO_OFF:
s->use_lock = false;
break;
case ON_OFF_AUTO_AUTO:
-#ifdef F_OFD_SETLK
- s->use_lock = true;
-#else
- s->use_lock = false;
-#endif
+ s->use_lock = qemu_has_ofd_lock();
break;
default:
abort();
--
2.13.3
next prev parent reply other threads:[~2017-07-21 10:21 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-07-21 10:20 [Qemu-devel] [PATCH 0/2] block: Do OFD lock check at runtime Fam Zheng
2017-07-21 10:20 ` [Qemu-devel] [PATCH 1/2] osdep: Add runtime OFD lock detection Fam Zheng
2017-07-21 12:30 ` Eric Blake
2017-07-21 10:20 ` Fam Zheng [this message]
2017-07-21 12:36 ` [Qemu-devel] [PATCH 2/2] file-posix: Do runtime check for ofd lock API Eric Blake
2017-08-10 8:16 ` Christian Ehrhardt
2017-07-21 17:23 ` Andrew Baumann
2017-07-21 11:56 ` [Qemu-devel] [PATCH 0/2] block: Do OFD lock check at runtime Kevin Wolf
2017-07-21 12:34 ` Eric Blake
2017-07-21 13:47 ` Daniel P. Berrange
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20170721102059.14663-3-famz@redhat.com \
--to=famz@redhat.com \
--cc=Andrew.Baumann@microsoft.com \
--cc=eblake@redhat.com \
--cc=jsnow@redhat.com \
--cc=kwolf@redhat.com \
--cc=mreitz@redhat.com \
--cc=qemu-block@nongnu.org \
--cc=qemu-devel@nongnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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).