On Thu, Oct 28, 2021 at 04:37:36PM +0200, Kevin Wolf wrote: > Am 27.08.2021 um 17:09 hat Eric Blake geschrieben: > > According to the NBD spec, a server advertising > > NBD_FLAG_CAN_MULTI_CONN promises that multiple client connections will > > not see any cache inconsistencies: when properly separated by a single > > flush, actions performed by one client will be visible to another > > client, regardless of which client did the flush. We satisfy these > > conditions in qemu because our block layer serializes any overlapping > > operations (see bdrv_find_conflicting_request and friends): no matter > > which client performs a flush, parallel requests coming from distinct > > NBD clients will still be well-ordered by the time they are passed on > > to the underlying device, with no caching in qemu proper to allow > > stale results to leak after a flush. > > > > We don't want to advertise MULTI_CONN when we know that a second > > client can connect (which is the default for qemu-nbd, but not for QMP > > nbd-server-add), > > Do you mean when a second client _can't_ connect?
Oops, yes. The default for qemu-nbd is a single client (you have to request -e for more than one), so a second client can't connect; for nbd-server-add it is unlimited clients [1]. > > > so it does require a QAPI addition. But other than > > that, the actual change to advertise the bit for writable servers is > > fairly small. The harder part of this patch is setting up an iotest > > to demonstrate behavior of multiple NBD clients to a single server. > > It might be possible with parallel qemu-io processes, but concisely > > managing that in shell is painful. > > I think it should be fairly straightforward in a Python test case. Probably, but my python is rather weak for writing such a case off-hand from scratch. Is there an existing test that you are aware of that might be easy to copy-and-paste from? > > Another option is using a single QEMU or QSD instance that has multiple > -blockdev for the same NBD server. For the server these are multiple > clients, even if all connnection come from a single process. > > > I found it easier to do by relying > > on the libnbd project's nbdsh, which means this test will be skipped > > on platforms where that is not available. > > > > Signed-off-by: Eric Blake <ebl...@redhat.com> > > > diff --git a/docs/interop/nbd.txt b/docs/interop/nbd.txt > > index 10ce098a29bf..d03910f1e9eb 100644 > > --- a/docs/interop/nbd.txt > > +++ b/docs/interop/nbd.txt > > @@ -68,3 +68,4 @@ NBD_CMD_BLOCK_STATUS for "qemu:dirty-bitmap:", > > NBD_CMD_CACHE > > * 4.2: NBD_FLAG_CAN_MULTI_CONN for shareable read-only exports, > > NBD_CMD_FLAG_FAST_ZERO > > * 5.2: NBD_CMD_BLOCK_STATUS for "qemu:allocation-depth" > > +* 6.2: NBD_FLAG_CAN_MULTI_CONN for shareable writable exports > > diff --git a/docs/tools/qemu-nbd.rst b/docs/tools/qemu-nbd.rst > > index 5643da26e982..81be32164a55 100644 > > --- a/docs/tools/qemu-nbd.rst > > +++ b/docs/tools/qemu-nbd.rst > > @@ -138,8 +138,7 @@ driver options if ``--image-opts`` is specified. > > .. option:: -e, --shared=NUM > > > > Allow up to *NUM* clients to share the device (default > > - ``1``), 0 for unlimited. Safe for readers, but for now, > > - consistency is not guaranteed between multiple writers. > > + ``1``), 0 for unlimited. > > > > .. option:: -t, --persistent > > If qemu-nbd supports a maximum number of connections rather than just a > bool... > > > diff --git a/qapi/block-export.json b/qapi/block-export.json > > index 0ed63442a819..b2085a9fdd4c 100644 > > --- a/qapi/block-export.json > > +++ b/qapi/block-export.json > > @@ -95,11 +95,15 @@ > > # the metadata context name "qemu:allocation-depth" to > > # inspect allocation details. (since 5.2) > > # > > +# @shared: True if the server should advertise that multiple clients may > > +# connect, default false. (since 6.2) > > +# > > # Since: 5.2 > > ## > > { 'struct': 'BlockExportOptionsNbd', > > 'base': 'BlockExportOptionsNbdBase', > > - 'data': { '*bitmaps': ['str'], '*allocation-depth': 'bool' } } > > + 'data': { '*bitmaps': ['str'], '*allocation-depth': 'bool', > > + '*shared': 'bool' } } > > ...wouldn't it be better to mirror this in the QAPI interface? Yeah, now that you mention it. (In fact, before I got to this part of the email, at point [1] above I was trying to look in block-export.json to see whether there is any way to use QMP to expose less than unlimited clients, and couldn't find it - because it isn't there) > > I think eventually we want to add everything missing to the built-in NBD > server and then change qemu-nbd to use it instead of managing the > connections itself. So I'm not sure if diverging here is a good idea. That argument alone makes it sound like it is worth respinning this series to at least pick up on exposing max-clients through QMP, so that qemu-nbd and QMP have the same knobs (even if those knobs have different defaults). -- Eric Blake, Principal Software Engineer Red Hat, Inc. +1-919-301-3266 Virtualization: qemu.org | libvirt.org