Received: from eggs.gnu.org ([2001:4830:134:3::10]:39536) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XF84V-0002W7-3S for qemu-devel@nongnu.org; Wed, 06 Aug 2014 16:44:54 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1XF840-0005oK-LG for qemu-devel@nongnu.org; Wed, 06 Aug 2014 16:44:31 -0400 Received: from e9.ny.us.ibm.com ([32.97.182.139]:40003) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XF840-0005o7-H4 for qemu-devel@nongnu.org; Wed, 06 Aug 2014 16:44:00 -0400 Received: from /spool/local by e9.ny.us.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Wed, 6 Aug 2014 16:44:00 -0400 From: Michael Roth Date: Wed, 6 Aug 2014 15:39:39 -0500 Message-Id: <1407357598-21541-90-git-send-email-mdroth@linux.vnet.ibm.com> In-Reply-To: <1407357598-21541-1-git-send-email-mdroth@linux.vnet.ibm.com> References: <1407357598-21541-1-git-send-email-mdroth@linux.vnet.ibm.com> Subject: [Qemu-devel] [PATCH 089/108] nbd: Don't export a block device with no medium. List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Cc: qemu-stable@nongnu.org From: Hani Benhabiles 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 Cc: qemu-stable@nongnu.org Signed-off-by: Paolo Bonzini (cherry picked from commit 60fe4fac22895576973e317d7148b084c31cc64c) Signed-off-by: Michael Roth --- blockdev-nbd.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/blockdev-nbd.c b/blockdev-nbd.c index 922cf56..a700d52 100644 --- a/blockdev-nbd.c +++ b/blockdev-nbd.c @@ -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; -- 1.9.1