From patchwork Fri Oct 23 09:26:03 2009 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Gerd Hoffmann X-Patchwork-Id: 36773 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 75744B7BC0 for ; Fri, 23 Oct 2009 20:39:27 +1100 (EST) Received: from localhost ([127.0.0.1]:44224 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1N1GcG-00032x-Au for incoming@patchwork.ozlabs.org; Fri, 23 Oct 2009 05:39:24 -0400 Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1N1GPc-00082Z-Jh for qemu-devel@nongnu.org; Fri, 23 Oct 2009 05:26:20 -0400 Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1N1GPW-0007zZ-Tv for qemu-devel@nongnu.org; Fri, 23 Oct 2009 05:26:19 -0400 Received: from [199.232.76.173] (port=40166 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1N1GPW-0007zQ-HO for qemu-devel@nongnu.org; Fri, 23 Oct 2009 05:26:14 -0400 Received: from mx1.redhat.com ([209.132.183.28]:59899) by monty-python.gnu.org with esmtp (Exim 4.60) (envelope-from ) id 1N1GPW-0002CV-0Z for qemu-devel@nongnu.org; Fri, 23 Oct 2009 05:26:14 -0400 Received: from int-mx08.intmail.prod.int.phx2.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.21]) by mx1.redhat.com (8.13.8/8.13.8) with ESMTP id n9N9QDnu027943 for ; Fri, 23 Oct 2009 05:26:13 -0400 Received: from zweiblum.home.kraxel.org (vpn2-9-162.ams2.redhat.com [10.36.9.162]) by int-mx08.intmail.prod.int.phx2.redhat.com (8.13.8/8.13.8) with SMTP id n9N9QAPb017601; Fri, 23 Oct 2009 05:26:11 -0400 Received: by zweiblum.home.kraxel.org (Postfix, from userid 500) id 2F25F7010C; Fri, 23 Oct 2009 11:26:04 +0200 (CEST) From: Gerd Hoffmann To: qemu-devel@nongnu.org Date: Fri, 23 Oct 2009 11:26:03 +0200 Message-Id: <1256289963-26430-6-git-send-email-kraxel@redhat.com> In-Reply-To: <1256289963-26430-1-git-send-email-kraxel@redhat.com> References: <1256289963-26430-1-git-send-email-kraxel@redhat.com> X-Scanned-By: MIMEDefang 2.67 on 10.5.11.21 X-detected-operating-system: by monty-python.gnu.org: Genre and OS details not recognized. Cc: Gerd Hoffmann Subject: [Qemu-devel] [PATCH 5/5] usb-storage: use qdev for -usbdevice 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 Hook up usb_msd_init. Also rework handling of encrypted block devices, move the code out vl.c. Signed-off-by: Gerd Hoffmann --- hw/usb-msd.c | 33 +++++++++++++++++++++++++-------- hw/usb.h | 4 ---- vl.c | 25 ------------------------- 3 files changed, 25 insertions(+), 37 deletions(-) diff --git a/hw/usb-msd.c b/hw/usb-msd.c index dd3010e..8dc494f 100644 --- a/hw/usb-msd.c +++ b/hw/usb-msd.c @@ -14,6 +14,7 @@ #include "block.h" #include "scsi-disk.h" #include "console.h" +#include "monitor.h" //#define DEBUG_MSD @@ -508,6 +509,16 @@ static int usb_msd_handle_data(USBDevice *dev, USBPacket *p) return ret; } +static void usb_msd_password_cb(void *opaque, int err) +{ + MSDState *s = opaque; + + if (!err) + usb_device_attach(&s->dev); + else + qdev_unplug(&s->dev.qdev); +} + static int usb_msd_initfn(USBDevice *dev) { MSDState *s = DO_UPCAST(MSDState, dev, dev); @@ -522,10 +533,21 @@ static int usb_msd_initfn(USBDevice *dev) s->scsi_dev = scsi_bus_legacy_add_drive(&s->bus, s->dinfo, 0); s->bus.qbus.allow_hotplug = 0; usb_msd_handle_reset(dev); + + if (bdrv_key_required(s->dinfo->bdrv)) { + if (s->dev.qdev.hotplugged) { + monitor_read_bdrv_key_start(cur_mon, s->dinfo->bdrv, + usb_msd_password_cb, s); + s->dev.auto_attach = 0; + } else { + autostart = 0; + } + } + return 0; } -USBDevice *usb_msd_init(const char *filename) +static USBDevice *usb_msd_init(const char *filename) { static int nr=0; char id[8]; @@ -577,13 +599,6 @@ USBDevice *usb_msd_init(const char *filename) return dev; } -BlockDriverState *usb_msd_get_bdrv(USBDevice *dev) -{ - MSDState *s = (MSDState *)dev; - - return s->dinfo->bdrv; -} - static struct USBDeviceInfo msd_info = { .qdev.name = "QEMU USB MSD", .qdev.alias = "usb-storage", @@ -593,6 +608,8 @@ static struct USBDeviceInfo msd_info = { .handle_reset = usb_msd_handle_reset, .handle_control = usb_msd_handle_control, .handle_data = usb_msd_handle_data, + .usbdevice_name = "disk", + .usbdevice_init = usb_msd_init, .qdev.props = (Property[]) { DEFINE_PROP_DRIVE("drive", MSDState, dinfo), DEFINE_PROP_END_OF_LIST(), diff --git a/hw/usb.h b/hw/usb.h index a01f334..351c466 100644 --- a/hw/usb.h +++ b/hw/usb.h @@ -256,10 +256,6 @@ void usb_host_info(Monitor *mon); /* usb-hid.c */ void usb_hid_datain_cb(USBDevice *dev, void *opaque, void (*datain)(void *)); -/* usb-msd.c */ -USBDevice *usb_msd_init(const char *filename); -BlockDriverState *usb_msd_get_bdrv(USBDevice *dev); - /* usb-net.c */ USBDevice *usb_net_init(NICInfo *nd); diff --git a/vl.c b/vl.c index 64761cf..994065c 100644 --- a/vl.c +++ b/vl.c @@ -2523,16 +2523,6 @@ static void smp_parse(const char *optarg) /***********************************************************/ /* USB devices */ -static void usb_msd_password_cb(void *opaque, int err) -{ - USBDevice *dev = opaque; - - if (!err) - usb_device_attach(dev); - else - dev->info->handle_destroy(dev); -} - static int usb_device_add(const char *devname, int is_hotplug) { const char *p; @@ -2549,21 +2539,6 @@ static int usb_device_add(const char *devname, int is_hotplug) /* the other ones */ if (strstart(devname, "host:", &p)) { dev = usb_host_device_open(p); - } else if (strstart(devname, "disk:", &p)) { - BlockDriverState *bs; - - dev = usb_msd_init(p); - if (!dev) - return -1; - bs = usb_msd_get_bdrv(dev); - if (bdrv_key_required(bs)) { - autostart = 0; - if (is_hotplug) { - monitor_read_bdrv_key_start(cur_mon, bs, usb_msd_password_cb, - dev); - return 0; - } - } } else if (strstart(devname, "net:", &p)) { QemuOpts *opts; int idx;