server: Remember .open(readonly) status
commit0ef9cfedf2e5dcdf4f4182aed92b402738ab00ca
authorEric Blake <eblake@redhat.com>
Fri, 30 Aug 2019 22:45:34 +0000 (30 17:45 -0500)
committerEric Blake <eblake@redhat.com>
Sat, 31 Aug 2019 22:30:04 +0000 (31 17:30 -0500)
treef296849f7dc16943cd963da46a8799cbf684b47c
parentd60d0f4248610fc1d116dc9f249526d20913c9a3
server: Remember .open(readonly) status

The previous patch argued that globally affecting .can_write based on
'-r' (the global 'readonly') prevents the ability for a filter to call
next_open(nxdata, false) to purposefully write to the plugin, even
while advertising .can_write=0 to the client.  But it also
demonstrated that when a filter passes readonly=true to next_open, we
were still making needless probes into the plugin, for something the
filter won't be using.

This patch improves things to prime the .can_write cache according to
.open.  The same script from the previous patch now fails a lot faster
under -r (since nozero is not a filter that changes readonly=false to
true, the plugin now fails .can_zero quickly):

$ /bin/time -f %e ./nbdkit -U - -r --filter=nozero sh script zeromode=notrim \
  --run 'qemu-nbd --list -k $unixsocket >/dev/null'
nbdkit: sh[1]: error: zeromode 'notrim' requires plugin zero support
qemu-nbd: Failed to read initial magic: Unexpected end-of-file before all bytes were read
Command exited with non-zero status 1
0.06

Signed-off-by: Eric Blake <eblake@redhat.com>
server/backend.c
server/connections.c
server/filters.c
server/internal.h
server/plugins.c