From: Eric Blake <eblake@redhat.com>
To: qemu-devel@nongnu.org
Cc: qemu-block@nongnu.org, vsementsov@virtuozzo.com,
pbonzini@redhat.com, kwolf@redhat.com, qemu-stable@nongnu.org,
Max Reitz <mreitz@redhat.com>
Subject: [Qemu-devel] [PATCH v2 2/7] nbd-client: Refuse read-only client with BDRV_O_RDWR
Date: Wed, 8 Nov 2017 15:56:58 -0600 [thread overview]
Message-ID: <20171108215703.9295-3-eblake@redhat.com> (raw)
In-Reply-To: <20171108215703.9295-1-eblake@redhat.com>
The NBD spec says that clients should not try to write/trim to
an export advertised as read-only by the server. But we failed
to check that, and would allow the block layer to use NBD with
BDRV_O_RDWR even when the server is read-only, which meant we
were depending on the server sending a proper EPERM failure for
various commands, and also exposes a leaky abstraction: using
qemu-io in read-write mode would succeed on 'w -z 0 0' because
of local short-circuiting logic, but 'w 0 0' would send a
request over the wire (where it then depends on the server, and
fails at least for qemu-nbd but might pass for other NBD
implementations).
With this patch, a client MUST request read-only mode to access
a server that is doing a read-only export, or else it will get
a message like:
can't open device nbd://localhost:10809/foo: request for write access conflicts with read-only export
It is no longer possible to even attempt writes over the wire
(including the corner case of 0-length writes), because the block
layer enforces the explicit read-only request; this matches the
behavior of qcow2 when backed by a read-only POSIX file.
Fix iotest 147 to comply with the new behavior (since nbd-server-add
defaults to a read-only export, we must tell blockdev-add to set up a
read-only client).
CC: qemu-stable@nongnu.org
Signed-off-by: Eric Blake <eblake@redhat.com>
---
v2: retitle; require explicit read-only request, rather than magically
setting it (includes iotest fallout) [Kevin]
---
block/nbd-client.c | 9 +++++++++
tests/qemu-iotests/147 | 1 +
2 files changed, 10 insertions(+)
diff --git a/block/nbd-client.c b/block/nbd-client.c
index de6c153328..daa4392531 100644
--- a/block/nbd-client.c
+++ b/block/nbd-client.c
@@ -697,6 +697,7 @@ int nbd_client_co_pwritev(BlockDriverState *bs, uint64_t offset,
.len = bytes,
};
+ assert(!(client->info.flags & NBD_FLAG_READ_ONLY));
if (flags & BDRV_REQ_FUA) {
assert(client->info.flags & NBD_FLAG_SEND_FUA);
request.flags |= NBD_CMD_FLAG_FUA;
@@ -717,6 +718,7 @@ int nbd_client_co_pwrite_zeroes(BlockDriverState *bs, int64_t offset,
.len = bytes,
};
+ assert(!(client->info.flags & NBD_FLAG_READ_ONLY));
if (!(client->info.flags & NBD_FLAG_SEND_WRITE_ZEROES)) {
return -ENOTSUP;
}
@@ -756,6 +758,7 @@ int nbd_client_co_pdiscard(BlockDriverState *bs, int64_t offset, int bytes)
.len = bytes,
};
+ assert(!(client->info.flags & NBD_FLAG_READ_ONLY));
if (!(client->info.flags & NBD_FLAG_SEND_TRIM)) {
return 0;
}
@@ -814,6 +817,12 @@ int nbd_client_init(BlockDriverState *bs,
logout("Failed to negotiate with the NBD server\n");
return ret;
}
+ 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 (client->info.flags & NBD_FLAG_SEND_FUA) {
bs->supported_write_flags = BDRV_REQ_FUA;
bs->supported_zero_flags |= BDRV_REQ_FUA;
diff --git a/tests/qemu-iotests/147 b/tests/qemu-iotests/147
index db34838cd0..90f40ed245 100755
--- a/tests/qemu-iotests/147
+++ b/tests/qemu-iotests/147
@@ -43,6 +43,7 @@ class NBDBlockdevAddBase(iotests.QMPTestCase):
'driver': 'raw',
'file': {
'driver': 'nbd',
+ 'read-only': True,
'server': address
} }
if export is not None:
--
2.13.6
next prev parent reply other threads:[~2017-11-08 21:57 UTC|newest]
Thread overview: 24+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-11-08 21:56 [Qemu-devel] [PATCH v2 0/7] various NBD fixes for 2.11 Eric Blake
2017-11-08 21:56 ` [Qemu-devel] [PATCH v2 1/7] nbd-client: Fix error message typos Eric Blake
2017-11-09 8:58 ` Vladimir Sementsov-Ogievskiy
2017-11-09 14:43 ` Eric Blake
2017-11-08 21:56 ` Eric Blake [this message]
2017-11-08 22:07 ` [Qemu-devel] [PATCH v2 2/7] nbd-client: Refuse read-only client with BDRV_O_RDWR Eric Blake
2017-11-08 22:23 ` [Qemu-devel] [PATCH v2 2.5/7] fixup! " Eric Blake
2017-11-09 9:05 ` Vladimir Sementsov-Ogievskiy
2017-11-09 9:04 ` [Qemu-devel] [PATCH v2 2/7] " Vladimir Sementsov-Ogievskiy
2017-11-08 21:56 ` [Qemu-devel] [PATCH v2 3/7] nbd/client: Nicer trace of structured reply Eric Blake
2017-11-09 9:10 ` Vladimir Sementsov-Ogievskiy
2017-11-08 21:57 ` [Qemu-devel] [PATCH v2 4/7] nbd: Fix struct name for structured reads Eric Blake
2017-11-09 9:13 ` Vladimir Sementsov-Ogievskiy
2017-11-08 21:57 ` [Qemu-devel] [PATCH v2 5/7] nbd-client: Short-circuit 0-length operations Eric Blake
2017-11-09 9:20 ` Vladimir Sementsov-Ogievskiy
2017-11-09 14:44 ` Eric Blake
2017-11-08 21:57 ` [Qemu-devel] [PATCH v2 6/7] nbd-client: Stricter enforcing of structured reply spec Eric Blake
2017-11-09 9:37 ` Vladimir Sementsov-Ogievskiy
2017-11-09 14:45 ` Eric Blake
2017-11-08 21:57 ` [Qemu-devel] [PATCH v2 7/7] nbd/server: Fix structured read of length 0 Eric Blake
2017-11-09 9:43 ` Vladimir Sementsov-Ogievskiy
2017-11-08 22:24 ` [Qemu-devel] [PATCH v2 0/7] various NBD fixes for 2.11 no-reply
2017-11-08 23:05 ` Eric Blake
2017-11-09 5:34 ` Fam Zheng
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=20171108215703.9295-3-eblake@redhat.com \
--to=eblake@redhat.com \
--cc=kwolf@redhat.com \
--cc=mreitz@redhat.com \
--cc=pbonzini@redhat.com \
--cc=qemu-block@nongnu.org \
--cc=qemu-devel@nongnu.org \
--cc=qemu-stable@nongnu.org \
--cc=vsementsov@virtuozzo.com \
/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).