From patchwork Sat Jan 15 00:00:43 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stefan Hajnoczi X-Patchwork-Id: 79020 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [199.232.76.165]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id BD2FFB6EF1 for ; Sat, 15 Jan 2011 11:02:37 +1100 (EST) Received: from localhost ([127.0.0.1]:36627 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1Pdtb1-0005ib-Vf for incoming@patchwork.ozlabs.org; Fri, 14 Jan 2011 19:02:20 -0500 Received: from [140.186.70.92] (port=59376 helo=eggs.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1Pdta1-0005Fg-Kn for qemu-devel@nongnu.org; Fri, 14 Jan 2011 19:01:18 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Pdta0-00024J-32 for qemu-devel@nongnu.org; Fri, 14 Jan 2011 19:01:17 -0500 Received: from mtagate4.uk.ibm.com ([194.196.100.164]:44860) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1PdtZz-00023s-NI for qemu-devel@nongnu.org; Fri, 14 Jan 2011 19:01:16 -0500 Received: from d06nrmr1707.portsmouth.uk.ibm.com (d06nrmr1707.portsmouth.uk.ibm.com [9.149.39.225]) by mtagate4.uk.ibm.com (8.13.1/8.13.1) with ESMTP id p0F01DXO006967 for ; Sat, 15 Jan 2011 00:01:13 GMT Received: from d06av03.portsmouth.uk.ibm.com (d06av03.portsmouth.uk.ibm.com [9.149.37.213]) by d06nrmr1707.portsmouth.uk.ibm.com (8.13.8/8.13.8/NCO v10.0) with ESMTP id p0F019sm1310830 for ; Sat, 15 Jan 2011 00:01:15 GMT Received: from d06av03.portsmouth.uk.ibm.com (localhost.localdomain [127.0.0.1]) by d06av03.portsmouth.uk.ibm.com (8.14.4/8.13.1/NCO v10.0 AVout) with ESMTP id p0F0166C031127 for ; Fri, 14 Jan 2011 17:01:07 -0700 Received: from stefanha-thinkpad.ibm.com (sig-9-146-159-111.uk.ibm.com [9.146.159.111]) by d06av03.portsmouth.uk.ibm.com (8.14.4/8.13.1/NCO v10.0 AVin) with ESMTP id p0F016no031110; Fri, 14 Jan 2011 17:01:06 -0700 From: Stefan Hajnoczi To: Date: Sat, 15 Jan 2011 00:00:43 +0000 Message-Id: <1295049643-23443-1-git-send-email-stefanha@linux.vnet.ibm.com> X-Mailer: git-send-email 1.7.2.3 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6, seldom 2.4 (older, 4) Cc: Kevin Wolf , Christoph Hellwig , "Justin M. Forbes" , Stefan Hajnoczi Subject: [Qemu-devel] [PATCH] usb-msd: Add usb-storage, removable=on|off property X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: qemu-devel.nongnu.org List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org USB Mass Storage Devices sometimes have the RMB (removable) bit set in the SCSI INQUIRY response. Thumbdrives tend to have the bit set whereas hard disks do not. Operating systems differentiate between removable devices and fixed devices. Under Linux, the anaconda installer looks for removable devices. Under Windows, only fixed devices may have more than one partition and AutoRun is also affected by the removable bit. For these reasons, allow USB Mass Storage Devices to override the removable bit: qemu -usb -drive if=none,file=test.img,cache=none,id=disk0 -device usb-storage,drive=disk0,removable=on The default is off. Signed-off-by: Stefan Hajnoczi --- hw/scsi-disk.c | 6 +++++- hw/usb-msd.c | 19 +++++++++++++++++++ 2 files changed, 24 insertions(+), 1 deletions(-) diff --git a/hw/scsi-disk.c b/hw/scsi-disk.c index 6cb317c..39c1279 100644 --- a/hw/scsi-disk.c +++ b/hw/scsi-disk.c @@ -548,7 +548,6 @@ static int scsi_disk_emulate_inquiry(SCSIRequest *req, uint8_t *outbuf) if (bdrv_get_type_hint(s->bs) == BDRV_TYPE_CDROM) { outbuf[0] = 5; - outbuf[1] = 0x80; memcpy(&outbuf[16], "QEMU CD-ROM ", 16); } else { outbuf[0] = 0; @@ -557,6 +556,11 @@ static int scsi_disk_emulate_inquiry(SCSIRequest *req, uint8_t *outbuf) memcpy(&outbuf[8], "QEMU ", 8); memset(&outbuf[32], 0, 4); memcpy(&outbuf[32], s->version, MIN(4, strlen(s->version))); + + if (bdrv_is_removable(s->bs)) { + outbuf[1] |= 0x80; + } + /* * We claim conformance to SPC-3, which is required for guests * to ask for modern features like READ CAPACITY(16) or the diff --git a/hw/usb-msd.c b/hw/usb-msd.c index 0a95d8d..2dce9df 100644 --- a/hw/usb-msd.c +++ b/hw/usb-msd.c @@ -50,6 +50,7 @@ typedef struct { SCSIBus bus; BlockConf conf; SCSIDevice *scsi_dev; + uint32_t removable; int result; /* For async completion. */ USBPacket *packet; @@ -520,6 +521,13 @@ static void usb_msd_password_cb(void *opaque, int err) qdev_unplug(&s->dev.qdev); } +static void usb_msd_change_cb(void *opaque) +{ + MSDState *s = opaque; + + qdev_unplug(&s->dev.qdev); +} + static int usb_msd_initfn(USBDevice *dev) { MSDState *s = DO_UPCAST(MSDState, dev, dev); @@ -548,6 +556,16 @@ static int usb_msd_initfn(USBDevice *dev) if (!s->scsi_dev) { return -1; } + + /* + * Allow overriding the SCSI INQUIRY removable (RMB) bit for hard disks. + * USB thumbdrives tend report removable media but USB hard disks do not. + */ + if (s->removable && bdrv_get_type_hint(bs) == BDRV_TYPE_HD) { + bdrv_set_change_cb(bs, usb_msd_change_cb, s); + bdrv_set_removable(bs, 1); + } + s->bus.qbus.allow_hotplug = 0; usb_msd_handle_reset(dev); @@ -634,6 +652,7 @@ static struct USBDeviceInfo msd_info = { .usbdevice_init = usb_msd_init, .qdev.props = (Property[]) { DEFINE_BLOCK_PROPERTIES(MSDState, conf), + DEFINE_PROP_BIT("removable", MSDState, removable, 1, false), DEFINE_PROP_END_OF_LIST(), }, };