[Libguestfs] [nbdkit PATCH 6/9] server: Cache per-connection can_FOO flags

Eric Blake eblake at redhat.com
Fri Aug 30 13:20:47 UTC 2019


On 8/29/19 10:08 PM, Eric Blake wrote:
> Similar to the previous patch in caching size, we want to avoid
> calling into the plugin more than once per connection on any of the
> flag determination callbacks.
> 

> +++ b/server/protocol-handshake.c
> @@ -51,87 +51,72 @@ protocol_compute_eflags (struct connection *conn, uint16_t *flags)
>  {
>    uint16_t eflags = NBD_FLAG_HAS_FLAGS;
>    int fl;
> +  bool can_write = true;
> 
>    fl = backend_can_write (backend, conn);
>    if (fl == -1)
>      return -1;
>    if (readonly || !fl) {
>      eflags |= NBD_FLAG_READ_ONLY;
> -    conn->readonly = true;
> +    can_write = false;

The old code set conn->readonly=false if either the command line -r was
present or if the backend failed .can_write...


> +++ b/server/protocol.c
> @@ -64,14 +64,19 @@ validate_request (struct connection *conn,
>                    uint16_t cmd, uint16_t flags, uint64_t offset, uint32_t count,
>                    uint32_t *error)
>  {
> +  int r;
> +
>    /* Readonly connection? */
> -  if (conn->readonly &&
> -      (cmd == NBD_CMD_WRITE || cmd == NBD_CMD_TRIM ||
> -       cmd == NBD_CMD_WRITE_ZEROES)) {
> -    nbdkit_error ("invalid request: %s: write request on readonly connection",
> -                  name_of_nbd_cmd (cmd));
> -    *error = EROFS;
> -    return false;
> +  if (cmd == NBD_CMD_WRITE || cmd == NBD_CMD_TRIM ||
> +      cmd == NBD_CMD_WRITE_ZEROES) {
> +    r = backend_can_write (backend, conn);

...but the new code is only checking if the backend supports .can_write
(if the backend says yes, then this permits a broken client to write in
spite of the -r command line flag).  I'll fix that.

-- 
Eric Blake, Principal Software Engineer
Red Hat, Inc.           +1-919-301-3226
Virtualization:  qemu.org | libvirt.org

-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 488 bytes
Desc: OpenPGP digital signature
URL: <http://listman.redhat.com/archives/libguestfs/attachments/20190830/ea87df95/attachment.sig>


More information about the Libguestfs mailing list