Skip to content

Commit

Permalink
nbd: Don't export a block device with no medium.
Browse files Browse the repository at this point in the history
The device is exported with erroneous values and can't be read.

Before the patch:
$ sudo nbd-client localhost -p 10809 /dev/nbd0 -name floppy0
Negotiation: ..size = 17592186044415MB
bs=1024, sz=18446744073709547520 bytes

$ sudo mount /dev/nbd0 /mnt/tmp/
mount: block device /dev/nbd0 is write-protected, mounting read-only
mount: /dev/nbd0: can't read superblock

After the patch:
(qemu) nbd_server_add ide0-hd0
(qemu) nbd_server_add floppy0
Device 'floppy0' has no medium

Signed-off-by: Hani Benhabiles <[email protected]>
Cc: [email protected]
Signed-off-by: Paolo Bonzini <[email protected]>
  • Loading branch information
kroosec authored and bonzini committed Jun 27, 2014
1 parent d4cba13 commit 60fe4fa
Showing 1 changed file with 4 additions and 0 deletions.
4 changes: 4 additions & 0 deletions blockdev-nbd.c
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,10 @@ void qmp_nbd_server_add(const char *device, bool has_writable, bool writable,
error_set(errp, QERR_DEVICE_NOT_FOUND, device);
return;
}
if (!bdrv_is_inserted(bs)) {
error_set(errp, QERR_DEVICE_HAS_NO_MEDIUM, device);
return;
}

if (!has_writable) {
writable = false;
Expand Down

0 comments on commit 60fe4fa

Please sign in to comment.