nbd: Support auto-read-only option

If read-only=off, but auto-read-only=on is 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 <kwolf@redhat.com>
Reviewed-by: Eric Blake <eblake@redhat.com>
master
Kevin Wolf 2018-10-08 17:27:18 +02:00
parent eaa2410f1e
commit 6c2e581d4d
1 changed files with 5 additions and 5 deletions

View File

@ -992,11 +992,11 @@ int nbd_client_init(BlockDriverState *bs,
logout("Failed to negotiate with the NBD server\n"); logout("Failed to negotiate with the NBD server\n");
return ret; return ret;
} }
if (client->info.flags & NBD_FLAG_READ_ONLY && if (client->info.flags & NBD_FLAG_READ_ONLY) {
!bdrv_is_read_only(bs)) { ret = bdrv_apply_auto_read_only(bs, "NBD export is read-only", errp);
error_setg(errp, if (ret < 0) {
"request for write access conflicts with read-only export"); return ret;
return -EACCES; }
} }
if (client->info.flags & NBD_FLAG_SEND_FUA) { if (client->info.flags & NBD_FLAG_SEND_FUA) {
bs->supported_write_flags = BDRV_REQ_FUA; bs->supported_write_flags = BDRV_REQ_FUA;