[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-block] [PATCH 3/4] nbd: Support auto-read-only option
From: |
Kevin Wolf |
Subject: |
[Qemu-block] [PATCH 3/4] nbd: Support auto-read-only option |
Date: |
Tue, 9 Oct 2018 21:35:23 +0200 |
If read-only=off, but auto-read-only=on are given, open a read-write NBD
connection if the server provides a read-write export, but instead of
erroring out for read-only exports, just degrade to read-only.
Signed-off-by: Kevin Wolf <address@hidden>
---
block/nbd-client.h | 1 +
block/nbd-client.c | 14 +++++++++++---
block/nbd.c | 4 +++-
3 files changed, 15 insertions(+), 4 deletions(-)
diff --git a/block/nbd-client.h b/block/nbd-client.h
index cfc90550b9..1d14e78e92 100644
--- a/block/nbd-client.h
+++ b/block/nbd-client.h
@@ -46,6 +46,7 @@ int nbd_client_init(BlockDriverState *bs,
QCryptoTLSCreds *tlscreds,
const char *hostname,
const char *x_dirty_bitmap,
+ bool auto_readonly,
Error **errp);
void nbd_client_close(BlockDriverState *bs);
diff --git a/block/nbd-client.c b/block/nbd-client.c
index 9686ecbd5e..6a1e634bec 100644
--- a/block/nbd-client.c
+++ b/block/nbd-client.c
@@ -971,6 +971,7 @@ int nbd_client_init(BlockDriverState *bs,
QCryptoTLSCreds *tlscreds,
const char *hostname,
const char *x_dirty_bitmap,
+ bool auto_readonly,
Error **errp)
{
NBDClientSession *client = nbd_get_client_session(bs);
@@ -994,9 +995,16 @@ int nbd_client_init(BlockDriverState *bs,
}
if (client->info.flags & NBD_FLAG_READ_ONLY &&
!bdrv_is_read_only(bs)) {
- error_setg(errp,
- "request for write access conflicts with read-only export");
- return -EACCES;
+ if (auto_readonly) {
+ ret = bdrv_set_read_only(bs, true, errp);
+ if (ret < 0) {
+ return ret;
+ }
+ } else {
+ error_setg(errp, "request for write access conflicts with "
+ "read-only export");
+ return -EACCES;
+ }
}
if (client->info.flags & NBD_FLAG_SEND_FUA) {
bs->supported_write_flags = BDRV_REQ_FUA;
diff --git a/block/nbd.c b/block/nbd.c
index e87699fb73..8c352a45cd 100644
--- a/block/nbd.c
+++ b/block/nbd.c
@@ -445,7 +445,9 @@ static int nbd_open(BlockDriverState *bs, QDict *options,
int flags,
/* NBD handshake */
ret = nbd_client_init(bs, sioc, s->export, tlscreds, hostname,
- qemu_opt_get(opts, "x-dirty-bitmap"), errp);
+ qemu_opt_get(opts, "x-dirty-bitmap"),
+ (flags & BDRV_O_AUTO_RDONLY),
+ errp);
error:
if (sioc) {
object_unref(OBJECT(sioc));
--
2.13.6