Skip to content

Commit

Permalink
tests: Open readonly connection when server is readonly.
Browse files Browse the repository at this point in the history
Eric Blake patched qemu so it is no longer possible to open a
writeable connection from qemu to an NBD server which has advertized
that it supports only readonly connections:

  commit 1104d83c726d2b20f9cec7b99ab3570a2fdbd46d
  Author: Eric Blake <eblake@redhat.com>
  Date:   Wed Nov 8 15:56:58 2017 -0600

    nbd-client: Refuse read-only client with BDRV_O_RDWR

    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

Therefore we need to open such connections readonly.

There is a further problem that libguestfs was broken because it tried
to add the locking=off flag to NBD connections, so that requires the
following fix to libguestfs:

  https://bugzilla.redhat.com/show_bug.cgi?id=1516094
  libguestfs/libguestfs@35320dd

Thanks: Eric Blake and Lars Seipel.
  • Loading branch information
rwmjones committed Dec 3, 2017
1 parent 3bcb6e2 commit a6b907e
Show file tree
Hide file tree
Showing 3 changed files with 3 additions and 0 deletions.
1 change: 1 addition & 0 deletions tests/test-connect.c
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ main (int argc, char *argv[])
}

r = guestfs_add_drive_opts (g, "",
GUESTFS_ADD_DRIVE_OPTS_READONLY, 1,
GUESTFS_ADD_DRIVE_OPTS_FORMAT, "raw",
GUESTFS_ADD_DRIVE_OPTS_PROTOCOL, "nbd",
GUESTFS_ADD_DRIVE_OPTS_SERVER, server,
Expand Down
1 change: 1 addition & 0 deletions tests/test-gzip.c
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ main (int argc, char *argv[])
}

r = guestfs_add_drive_opts (g, "",
GUESTFS_ADD_DRIVE_OPTS_READONLY, 1,
GUESTFS_ADD_DRIVE_OPTS_FORMAT, "raw",
GUESTFS_ADD_DRIVE_OPTS_PROTOCOL, "nbd",
GUESTFS_ADD_DRIVE_OPTS_SERVER, server,
Expand Down
1 change: 1 addition & 0 deletions tests/test-xz.c
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ main (int argc, char *argv[])
}

r = guestfs_add_drive_opts (g, "",
GUESTFS_ADD_DRIVE_OPTS_READONLY, 1,
GUESTFS_ADD_DRIVE_OPTS_FORMAT, "raw",
GUESTFS_ADD_DRIVE_OPTS_PROTOCOL, "nbd",
GUESTFS_ADD_DRIVE_OPTS_SERVER, server,
Expand Down

0 comments on commit a6b907e

Please sign in to comment.