From: Kevin Wolf <kwolf@redhat.com>
To: qemu-block@nongnu.org
Cc: kwolf@redhat.com, mreitz@redhat.com, eblake@redhat.com,
pkrempa@redhat.com, qemu-devel@nongnu.org
Subject: [Qemu-devel] [PATCH 4/4] file-posix: Support auto-read-only option
Date: Tue, 9 Oct 2018 21:35:24 +0200 [thread overview]
Message-ID: <20181009193524.19052-5-kwolf@redhat.com> (raw)
In-Reply-To: <20181009193524.19052-1-kwolf@redhat.com>
If read-only=off, but auto-read-only=on are given, open the file
read-write if we have the permissions, but instead of erroring out for
read-only files, just degrade to read-only.
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
---
block/file-posix.c | 13 +++++++++++++
1 file changed, 13 insertions(+)
diff --git a/block/file-posix.c b/block/file-posix.c
index 2da3a76355..69b312a3a3 100644
--- a/block/file-posix.c
+++ b/block/file-posix.c
@@ -450,6 +450,7 @@ static int raw_open_common(BlockDriverState *bs, QDict *options,
int fd, ret;
struct stat st;
OnOffAuto locking;
+ bool auto_readonly = bdrv_flags & BDRV_O_AUTO_RDONLY;
opts = qemu_opts_create(&raw_runtime_opts, NULL, 0, &error_abort);
qemu_opts_absorb_qdict(opts, options, &local_err);
@@ -527,6 +528,18 @@ static int raw_open_common(BlockDriverState *bs, QDict *options,
s->fd = -1;
fd = qemu_open(filename, s->open_flags, 0644);
+
+ if (auto_readonly && fd < 0 && (errno == EACCES || errno == EROFS)) {
+ ret = bdrv_set_read_only(bs, true, errp);
+ if (ret < 0) {
+ goto fail;
+ }
+ bdrv_flags &= ~BDRV_O_RDWR;
+ raw_parse_flags(bdrv_flags, &s->open_flags);
+ assert(!(s->open_flags & O_CREAT));
+ fd = qemu_open(filename, s->open_flags);
+ }
+
if (fd < 0) {
ret = -errno;
error_setg_errno(errp, errno, "Could not open '%s'", filename);
--
2.13.6
next prev parent reply other threads:[~2018-10-09 19:35 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-10-09 19:35 [Qemu-devel] [PATCH 0/4] block: Add auto-read-only option Kevin Wolf
2018-10-09 19:35 ` [Qemu-devel] [PATCH 1/4] block: Update flags in bdrv_set_read_only() Kevin Wolf
2018-10-09 19:35 ` [Qemu-devel] [PATCH 2/4] block: Add auto-read-only option Kevin Wolf
2018-10-09 19:35 ` [Qemu-devel] [PATCH 3/4] nbd: Support " Kevin Wolf
2018-10-09 19:35 ` Kevin Wolf [this message]
2018-10-11 8:29 ` [Qemu-devel] [PATCH 0/4] block: Add " Peter Krempa
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=20181009193524.19052-5-kwolf@redhat.com \
--to=kwolf@redhat.com \
--cc=eblake@redhat.com \
--cc=mreitz@redhat.com \
--cc=pkrempa@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).