From nobody Mon Apr 29 17:27:57 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (208.118.235.17 [208.118.235.17]) by mx.zohomail.com with SMTPS id 1516954542924700.0104266974306; Fri, 26 Jan 2018 00:15:42 -0800 (PST) Received: from localhost ([::1]:39814 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eezAX-0000QI-V6 for importer@patchew.org; Fri, 26 Jan 2018 03:15:29 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:43667) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eez9b-0008QH-4E for qemu-devel@nongnu.org; Fri, 26 Jan 2018 03:14:33 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1eez9X-0007fu-Si for qemu-devel@nongnu.org; Fri, 26 Jan 2018 03:14:31 -0500 Received: from mx1.redhat.com ([209.132.183.28]:38198) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1eez9X-0007fg-Kp for qemu-devel@nongnu.org; Fri, 26 Jan 2018 03:14:27 -0500 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 5C261DEE82; Fri, 26 Jan 2018 08:05:21 +0000 (UTC) Received: from sirius.home.kraxel.org (ovpn-116-227.ams2.redhat.com [10.36.116.227]) by smtp.corp.redhat.com (Postfix) with ESMTP id 6C1486F977; Fri, 26 Jan 2018 08:05:17 +0000 (UTC) Received: by sirius.home.kraxel.org (Postfix, from userid 1000) id DBC9211ABC; Fri, 26 Jan 2018 09:05:15 +0100 (CET) From: Gerd Hoffmann To: qemu-devel@nongnu.org Date: Fri, 26 Jan 2018 09:05:11 +0100 Message-Id: <20180126080515.26108-2-kraxel@redhat.com> In-Reply-To: <20180126080515.26108-1-kraxel@redhat.com> References: <20180126080515.26108-1-kraxel@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.39]); Fri, 26 Jan 2018 08:05:21 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PULL 1/5] usb: Remove legacy -usbdevice options (host, serial, disk and net) X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Samuel Thibault , Thomas Huth , Gerd Hoffmann , Paolo Bonzini Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" From: Thomas Huth The option have been marked as deprecated since QEMU 2.10, and so far nobody complained that the host, serial, disk and net options are urgently required anymore. So let's now get rid at least of this legacy pile, to simplify the usb code quite a bit. This patch removes the usbdevices host, serial, disk and net. These devices use their own complicated parameter parsing mechanisms, so they are just ugly to maintain, without real benefit for the users (the users can use the corresponding "-device" parameters instead which have the same complexity as the "-usbdevice" devices here). Note that the other rather simple -usbdevice options (mouse, tablet, etc.) are not removed yet (the code is really simple here, so it does not hurt much to keep it), as well as the two devices "braille" and "bt" which are easier to use with -usbdevice than with -device. Signed-off-by: Thomas Huth Message-id: 1515519171-20315-1-git-send-email-thuth@redhat.com [kraxel] delete some usb_host_device_open() leftovers. Signed-off-by: Gerd Hoffmann --- include/hw/usb.h | 1 - hw/usb/dev-network.c | 26 ---------- hw/usb/dev-serial.c | 30 ----------- hw/usb/dev-storage.c | 58 --------------------- hw/usb/host-legacy.c | 144 -----------------------------------------------= ---- hw/usb/host-stub.c | 6 --- vl.c | 15 ------ hw/usb/Makefile.objs | 2 +- qemu-options.hx | 19 ------- 9 files changed, 1 insertion(+), 300 deletions(-) delete mode 100644 hw/usb/host-legacy.c diff --git a/include/hw/usb.h b/include/hw/usb.h index 9dd9c6f0d9..a5080adecc 100644 --- a/include/hw/usb.h +++ b/include/hw/usb.h @@ -466,7 +466,6 @@ void usb_wakeup(USBEndpoint *ep, unsigned int stream); void usb_generic_async_ctrl_complete(USBDevice *s, USBPacket *p); =20 /* usb-linux.c */ -USBDevice *usb_host_device_open(USBBus *bus, const char *devname); void hmp_info_usbhost(Monitor *mon, const QDict *qdict); bool usb_host_dev_is_scsi_storage(USBDevice *usbdev); =20 diff --git a/hw/usb/dev-network.c b/hw/usb/dev-network.c index 85fc81bf43..aea7edcf31 100644 --- a/hw/usb/dev-network.c +++ b/hw/usb/dev-network.c @@ -1382,31 +1382,6 @@ static void usb_net_instance_init(Object *obj) &dev->qdev, NULL); } =20 -static USBDevice *usb_net_init(USBBus *bus, const char *cmdline) -{ - Error *local_err =3D NULL; - USBDevice *dev; - QemuOpts *opts; - int idx; - - opts =3D qemu_opts_parse_noisily(qemu_find_opts("net"), cmdline, false= ); - if (!opts) { - return NULL; - } - qemu_opt_set(opts, "type", "nic", &error_abort); - qemu_opt_set(opts, "model", "usb", &error_abort); - - idx =3D net_client_init(opts, false, &local_err); - if (local_err) { - error_report_err(local_err); - return NULL; - } - - dev =3D usb_create(bus, "usb-net"); - qdev_set_nic_properties(&dev->qdev, &nd_table[idx]); - return dev; -} - static const VMStateDescription vmstate_usb_net =3D { .name =3D "usb-net", .unmigratable =3D 1, @@ -1446,7 +1421,6 @@ static const TypeInfo net_info =3D { static void usb_net_register_types(void) { type_register_static(&net_info); - usb_legacy_register(TYPE_USB_NET, "net", usb_net_init); } =20 type_init(usb_net_register_types) diff --git a/hw/usb/dev-serial.c b/hw/usb/dev-serial.c index 94b5c34afe..2829dda391 100644 --- a/hw/usb/dev-serial.c +++ b/hw/usb/dev-serial.c @@ -509,35 +509,6 @@ static void usb_serial_realize(USBDevice *dev, Error *= *errp) } } =20 -static USBDevice *usb_serial_init(USBBus *bus, const char *filename) -{ - USBDevice *dev; - Chardev *cdrv; - char label[32]; - static int index; - - if (*filename =3D=3D ':') { - filename++; - } else if (*filename) { - error_report("unrecognized serial USB option %s", filename); - return NULL; - } - if (!*filename) { - error_report("character device specification needed"); - return NULL; - } - - snprintf(label, sizeof(label), "usbserial%d", index++); - cdrv =3D qemu_chr_new(label, filename); - if (!cdrv) - return NULL; - - dev =3D usb_create(bus, "usb-serial"); - qdev_prop_set_chr(&dev->qdev, "chardev", cdrv); - - return dev; -} - static USBDevice *usb_braille_init(USBBus *bus, const char *unused) { USBDevice *dev; @@ -624,7 +595,6 @@ static void usb_serial_register_types(void) { type_register_static(&usb_serial_dev_type_info); type_register_static(&serial_info); - usb_legacy_register("usb-serial", "serial", usb_serial_init); type_register_static(&braille_info); usb_legacy_register("usb-braille", "braille", usb_braille_init); } diff --git a/hw/usb/dev-storage.c b/hw/usb/dev-storage.c index 9722ac854c..e44a5c72cf 100644 --- a/hw/usb/dev-storage.c +++ b/hw/usb/dev-storage.c @@ -666,63 +666,6 @@ static void usb_msd_bot_realize(USBDevice *dev, Error = **errp) usb_msd_handle_reset(dev); } =20 -static USBDevice *usb_msd_init(USBBus *bus, const char *filename) -{ - static int nr=3D0; - Error *err =3D NULL; - char id[8]; - QemuOpts *opts; - DriveInfo *dinfo; - USBDevice *dev; - const char *p1; - char fmt[32]; - - /* parse -usbdevice disk: syntax into drive opts */ - do { - snprintf(id, sizeof(id), "usb%d", nr++); - opts =3D qemu_opts_create(qemu_find_opts("drive"), id, 1, NULL); - } while (!opts); - - p1 =3D strchr(filename, ':'); - if (p1++) { - const char *p2; - - if (strstart(filename, "format=3D", &p2)) { - int len =3D MIN(p1 - p2, sizeof(fmt)); - pstrcpy(fmt, len, p2); - qemu_opt_set(opts, "format", fmt, &error_abort); - } else if (*filename !=3D ':') { - error_report("unrecognized USB mass-storage option %s", filena= me); - return NULL; - } - filename =3D p1; - } - if (!*filename) { - error_report("block device specification needed"); - return NULL; - } - qemu_opt_set(opts, "file", filename, &error_abort); - qemu_opt_set(opts, "if", "none", &error_abort); - - /* create host drive */ - dinfo =3D drive_new(opts, 0); - if (!dinfo) { - qemu_opts_del(opts); - return NULL; - } - - /* create guest device */ - dev =3D usb_create(bus, "usb-storage"); - qdev_prop_set_drive(&dev->qdev, "drive", blk_by_legacy_dinfo(dinfo), - &err); - if (err) { - error_report_err(err); - object_unparent(OBJECT(dev)); - return NULL; - } - return dev; -} - static const VMStateDescription vmstate_usb_msd =3D { .name =3D "usb-storage", .version_id =3D 1, @@ -855,7 +798,6 @@ static void usb_msd_register_types(void) type_register_static(&usb_storage_dev_type_info); type_register_static(&msd_info); type_register_static(&bot_info); - usb_legacy_register("usb-storage", "disk", usb_msd_init); } =20 type_init(usb_msd_register_types) diff --git a/hw/usb/host-legacy.c b/hw/usb/host-legacy.c deleted file mode 100644 index 3b57e21b52..0000000000 --- a/hw/usb/host-legacy.c +++ /dev/null @@ -1,144 +0,0 @@ -/* - * Linux host USB redirector - * - * Copyright (c) 2005 Fabrice Bellard - * - * Copyright (c) 2008 Max Krasnyansky - * Support for host device auto connect & disconnect - * Major rewrite to support fully async operation - * - * Copyright 2008 TJ - * Added flexible support for /dev/bus/usb /sys/bus/usb/devices in ad= dition - * to the legacy /proc/bus/usb USB device discovery and handling - * - * Permission is hereby granted, free of charge, to any person obtaining a= copy - * of this software and associated documentation files (the "Software"), t= o deal - * in the Software without restriction, including without limitation the r= ights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or se= ll - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included= in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS= OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL - * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OT= HER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING= FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS = IN - * THE SOFTWARE. - */ - -#include "qemu/osdep.h" -#include "qemu-common.h" -#include "hw/usb.h" -#include "hw/usb/host.h" - -/* - * Autoconnect filter - * Format: - * auto:bus:dev[:vid:pid] - * auto:bus.dev[:vid:pid] - * - * bus - bus number (dec, * means any) - * dev - device number (dec, * means any) - * vid - vendor id (hex, * means any) - * pid - product id (hex, * means any) - * - * See 'lsusb' output. - */ -static int parse_filter(const char *spec, struct USBAutoFilter *f) -{ - enum { BUS, DEV, VID, PID, DONE }; - const char *p =3D spec; - int i; - - f->bus_num =3D 0; - f->addr =3D 0; - f->vendor_id =3D 0; - f->product_id =3D 0; - - for (i =3D BUS; i < DONE; i++) { - p =3D strpbrk(p, ":."); - if (!p) { - break; - } - p++; - - if (*p =3D=3D '*') { - continue; - } - switch (i) { - case BUS: - f->bus_num =3D strtol(p, NULL, 10); - break; - case DEV: - f->addr =3D strtol(p, NULL, 10); - break; - case VID: - f->vendor_id =3D strtol(p, NULL, 16); - break; - case PID: - f->product_id =3D strtol(p, NULL, 16); - break; - } - } - - if (i < DEV) { - fprintf(stderr, "husb: invalid auto filter spec %s\n", spec); - return -1; - } - - return 0; -} - -USBDevice *usb_host_device_open(USBBus *bus, const char *devname) -{ - struct USBAutoFilter filter; - USBDevice *dev; - char *p; - - dev =3D usb_create(bus, "usb-host"); - - if (strstr(devname, "auto:")) { - if (parse_filter(devname, &filter) < 0) { - goto fail; - } - } else { - p =3D strchr(devname, '.'); - if (p) { - filter.bus_num =3D strtoul(devname, NULL, 0); - filter.addr =3D strtoul(p + 1, NULL, 0); - filter.vendor_id =3D 0; - filter.product_id =3D 0; - } else { - p =3D strchr(devname, ':'); - if (p) { - filter.bus_num =3D 0; - filter.addr =3D 0; - filter.vendor_id =3D strtoul(devname, NULL, 16); - filter.product_id =3D strtoul(p + 1, NULL, 16); - } else { - goto fail; - } - } - } - - qdev_prop_set_uint32(&dev->qdev, "hostbus", filter.bus_num); - qdev_prop_set_uint32(&dev->qdev, "hostaddr", filter.addr); - qdev_prop_set_uint32(&dev->qdev, "vendorid", filter.vendor_id); - qdev_prop_set_uint32(&dev->qdev, "productid", filter.product_id); - return dev; - -fail: - object_unparent(OBJECT(dev)); - return NULL; -} - -static void usb_host_register_types(void) -{ - usb_legacy_register("usb-host", "host", usb_host_device_open); -} - -type_init(usb_host_register_types) diff --git a/hw/usb/host-stub.c b/hw/usb/host-stub.c index d0268baaa0..41d93ec8a0 100644 --- a/hw/usb/host-stub.c +++ b/hw/usb/host-stub.c @@ -41,12 +41,6 @@ void hmp_info_usbhost(Monitor *mon, const QDict *qdict) monitor_printf(mon, "USB host devices not supported\n"); } =20 -/* XXX: modify configure to compile the right host driver */ -USBDevice *usb_host_device_open(USBBus *bus, const char *devname) -{ - return NULL; -} - bool usb_host_dev_is_scsi_storage(USBDevice *ud) { return false; diff --git a/vl.c b/vl.c index e725ecbc08..2323111321 100644 --- a/vl.c +++ b/vl.c @@ -1451,30 +1451,15 @@ static void igd_gfx_passthru(void) static int usb_device_add(const char *devname) { USBDevice *dev =3D NULL; -#ifndef CONFIG_LINUX - const char *p; -#endif =20 if (!machine_usb(current_machine)) { return -1; } =20 - /* drivers with .usbdevice_name entry in USBDeviceInfo */ dev =3D usbdevice_create(devname); - if (dev) - goto done; - - /* the other ones */ -#ifndef CONFIG_LINUX - /* only the linux version is qdev-ified, usb-bsd still needs this */ - if (strstart(devname, "host:", &p)) { - dev =3D usb_host_device_open(usb_bus_find(-1), p); - } -#endif if (!dev) return -1; =20 -done: return 0; } =20 diff --git a/hw/usb/Makefile.objs b/hw/usb/Makefile.objs index bdfead6701..fbcd498c59 100644 --- a/hw/usb/Makefile.objs +++ b/hw/usb/Makefile.objs @@ -43,7 +43,7 @@ redirect.o-libs =3D $(USB_REDIR_LIBS) =20 # usb pass-through ifeq ($(CONFIG_USB_LIBUSB)$(CONFIG_USB),yy) -common-obj-y +=3D host-libusb.o host-legacy.o +common-obj-y +=3D host-libusb.o else common-obj-y +=3D host-stub.o endif diff --git a/qemu-options.hx b/qemu-options.hx index 5ff741a4af..1d73fb151d 100644 --- a/qemu-options.hx +++ b/qemu-options.hx @@ -1221,29 +1221,10 @@ Pointer device that uses absolute coordinates (like= a touchscreen). This means QEMU is able to report the mouse position without having to grab the mouse. Also overrides the PS/2 mouse emulation when activated. =20 -@item disk:[format=3D@var{format}]:@var{file} -Mass storage device based on file. The optional @var{format} argument -will be used rather than detecting the format. Can be used to specify -@code{format=3Draw} to avoid interpreting an untrusted format header. - -@item host:@var{bus}.@var{addr} -Pass through the host device identified by @var{bus}.@var{addr} (Linux onl= y). - -@item host:@var{vendor_id}:@var{product_id} -Pass through the host device identified by @var{vendor_id}:@var{product_id} -(Linux only). - -@item serial:[vendorid=3D@var{vendor_id}][,productid=3D@var{product_id}]:@= var{dev} -Serial converter to host character device @var{dev}, see @code{-serial} fo= r the -available devices. - @item braille Braille device. This will use BrlAPI to display the braille output on a r= eal or fake device. =20 -@item net:@var{options} -Network adapter that supports CDC ethernet and RNDIS protocols. - @end table ETEXI =20 --=20 2.9.3 From nobody Mon Apr 29 17:27:57 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1516975311732101.93266963339408; Fri, 26 Jan 2018 06:01:51 -0800 (PST) Received: from localhost ([::1]:57451 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ef4Zf-0000lC-ME for importer@patchew.org; Fri, 26 Jan 2018 09:01:47 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:56123) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ef4YW-0000Fp-8x for qemu-devel@nongnu.org; Fri, 26 Jan 2018 09:00:37 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ef4YS-00074e-31 for qemu-devel@nongnu.org; Fri, 26 Jan 2018 09:00:36 -0500 Received: from mx1.redhat.com ([209.132.183.28]:43060) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1ef4YR-00074P-Rr; Fri, 26 Jan 2018 09:00:32 -0500 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 853971618BC; Fri, 26 Jan 2018 08:05:24 +0000 (UTC) Received: from sirius.home.kraxel.org (ovpn-116-227.ams2.redhat.com [10.36.116.227]) by smtp.corp.redhat.com (Postfix) with ESMTP id 4233C5C544; Fri, 26 Jan 2018 08:05:18 +0000 (UTC) Received: by sirius.home.kraxel.org (Postfix, from userid 1000) id E6DB411ABD; Fri, 26 Jan 2018 09:05:15 +0100 (CET) From: Gerd Hoffmann To: qemu-devel@nongnu.org Date: Fri, 26 Jan 2018 09:05:12 +0100 Message-Id: <20180126080515.26108-3-kraxel@redhat.com> In-Reply-To: <20180126080515.26108-1-kraxel@redhat.com> References: <20180126080515.26108-1-kraxel@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.27]); Fri, 26 Jan 2018 08:05:24 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PULL 2/5] usb-storage: Fix share-rw option parsing X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Paolo Bonzini , Fam Zheng , qemu-stable@nongnu.org, Gerd Hoffmann Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" From: Fam Zheng Because usb-storage creates an internal scsi device, we should propagate options. We already do so for bootindex etc, but failed to take care of share-rw. Fix it in an apparent way: add a new parameter to scsi_bus_legacy_add_drive and pass in s->conf.share_rw. Cc: qemu-stable@nongnu.org Signed-off-by: Fam Zheng Reviewed-by: Darren Kenny Message-id: 20180117005222.4781-1-famz@redhat.com Signed-off-by: Gerd Hoffmann --- include/hw/scsi/scsi.h | 1 + hw/scsi/scsi-bus.c | 9 ++++++++- hw/usb/dev-storage.c | 3 ++- 3 files changed, 11 insertions(+), 2 deletions(-) diff --git a/include/hw/scsi/scsi.h b/include/hw/scsi/scsi.h index 23a8ee6a7d..802a647cdc 100644 --- a/include/hw/scsi/scsi.h +++ b/include/hw/scsi/scsi.h @@ -151,6 +151,7 @@ static inline SCSIBus *scsi_bus_from_device(SCSIDevice = *d) =20 SCSIDevice *scsi_bus_legacy_add_drive(SCSIBus *bus, BlockBackend *blk, int unit, bool removable, int bootin= dex, + bool share_rw, const char *serial, Error **errp); void scsi_bus_legacy_handle_cmdline(SCSIBus *bus, bool deprecated); void scsi_legacy_handle_cmdline(void); diff --git a/hw/scsi/scsi-bus.c b/hw/scsi/scsi-bus.c index 965becf31f..05e501efd3 100644 --- a/hw/scsi/scsi-bus.c +++ b/hw/scsi/scsi-bus.c @@ -224,6 +224,7 @@ static void scsi_qdev_unrealize(DeviceState *qdev, Erro= r **errp) /* handle legacy '-drive if=3Dscsi,...' cmd line args */ SCSIDevice *scsi_bus_legacy_add_drive(SCSIBus *bus, BlockBackend *blk, int unit, bool removable, int bootin= dex, + bool share_rw, const char *serial, Error **errp) { const char *driver; @@ -254,6 +255,12 @@ SCSIDevice *scsi_bus_legacy_add_drive(SCSIBus *bus, Bl= ockBackend *blk, object_unparent(OBJECT(dev)); return NULL; } + object_property_set_bool(OBJECT(dev), share_rw, "share-rw", &err); + if (err !=3D NULL) { + error_propagate(errp, err); + object_unparent(OBJECT(dev)); + return NULL; + } object_property_set_bool(OBJECT(dev), true, "realized", &err); if (err !=3D NULL) { error_propagate(errp, err); @@ -288,7 +295,7 @@ void scsi_bus_legacy_handle_cmdline(SCSIBus *bus, bool = deprecated) } } scsi_bus_legacy_add_drive(bus, blk_by_legacy_dinfo(dinfo), - unit, false, -1, NULL, &error_fatal); + unit, false, -1, false, NULL, &error_fat= al); } loc_pop(&loc); } diff --git a/hw/usb/dev-storage.c b/hw/usb/dev-storage.c index e44a5c72cf..b56c75a73a 100644 --- a/hw/usb/dev-storage.c +++ b/hw/usb/dev-storage.c @@ -633,7 +633,8 @@ static void usb_msd_storage_realize(USBDevice *dev, Err= or **errp) scsi_bus_new(&s->bus, sizeof(s->bus), DEVICE(dev), &usb_msd_scsi_info_storage, NULL); scsi_dev =3D scsi_bus_legacy_add_drive(&s->bus, blk, 0, !!s->removable, - s->conf.bootindex, dev->serial, + s->conf.bootindex, s->conf.share_= rw, + dev->serial, errp); blk_unref(blk); if (!scsi_dev) { --=20 2.9.3 From nobody Mon Apr 29 17:27:57 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1516977035224245.06488545397087; Fri, 26 Jan 2018 06:30:35 -0800 (PST) Received: from localhost ([::1]:58813 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ef51W-0000hH-Ex for importer@patchew.org; Fri, 26 Jan 2018 09:30:34 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:33126) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ef50V-0000HG-U0 for qemu-devel@nongnu.org; Fri, 26 Jan 2018 09:29:33 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ef50S-0001uR-Id for qemu-devel@nongnu.org; Fri, 26 Jan 2018 09:29:31 -0500 Received: from mx1.redhat.com ([209.132.183.28]:13999) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1ef50S-0001tz-AZ for qemu-devel@nongnu.org; Fri, 26 Jan 2018 09:29:28 -0500 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id E525EDEE81; Fri, 26 Jan 2018 08:05:21 +0000 (UTC) Received: from sirius.home.kraxel.org (ovpn-116-227.ams2.redhat.com [10.36.116.227]) by smtp.corp.redhat.com (Postfix) with ESMTP id 1CB2C5EE1B; Fri, 26 Jan 2018 08:05:18 +0000 (UTC) Received: by sirius.home.kraxel.org (Postfix, from userid 1000) id F2B5B11ABE; Fri, 26 Jan 2018 09:05:15 +0100 (CET) From: Gerd Hoffmann To: qemu-devel@nongnu.org Date: Fri, 26 Jan 2018 09:05:13 +0100 Message-Id: <20180126080515.26108-4-kraxel@redhat.com> In-Reply-To: <20180126080515.26108-1-kraxel@redhat.com> References: <20180126080515.26108-1-kraxel@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.39]); Fri, 26 Jan 2018 08:05:21 +0000 (UTC) Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PULL 3/5] hw/usb/ccid: Make ccid_card_init() take an error parameter X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Mao Zhongyi , Gerd Hoffmann , Cao jin , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" From: Mao Zhongyi Replace init() of CCIDCardClass with realize, then convert ccid_card_init(), ccid_card_initfn() and it's callbacks to take an Error** in ordor to report the error more clearly. Signed-off-by: Mao Zhongyi Signed-off-by: Cao jin Signed-off-by: Philippe Mathieu-Daud=C3=A9 Message-id: 20180125171432.13554-2-f4bug@amsat.org [PMD: fixed s->card assignation in ccid_card_realize()] Signed-off-by: Philippe Mathieu-Daud=C3=A9 Signed-off-by: Gerd Hoffmann --- hw/usb/ccid.h | 2 +- hw/usb/ccid-card-emulated.c | 44 +++++++++++++++++++++------------------= ---- hw/usb/ccid-card-passthru.c | 12 ++++++------ hw/usb/dev-smartcard-reader.c | 37 ++++++++++++++++++++---------------- 4 files changed, 50 insertions(+), 45 deletions(-) diff --git a/hw/usb/ccid.h b/hw/usb/ccid.h index 1f070116d6..6c6c10188d 100644 --- a/hw/usb/ccid.h +++ b/hw/usb/ccid.h @@ -34,7 +34,7 @@ typedef struct CCIDCardClass { const uint8_t *apdu, uint32_t len); void (*exitfn)(CCIDCardState *card); - int (*initfn)(CCIDCardState *card); + void (*realize)(CCIDCardState *card, Error **errp); } CCIDCardClass; =20 /* diff --git a/hw/usb/ccid-card-emulated.c b/hw/usb/ccid-card-emulated.c index e646eb243b..daefd9f8f4 100644 --- a/hw/usb/ccid-card-emulated.c +++ b/hw/usb/ccid-card-emulated.c @@ -35,6 +35,7 @@ #include "qemu/thread.h" #include "qemu/main-loop.h" #include "ccid.h" +#include "qapi/error.h" =20 #define DPRINTF(card, lvl, fmt, ...) \ do {\ @@ -401,10 +402,10 @@ static void card_event_handler(EventNotifier *notifie= r) qemu_mutex_unlock(&card->event_list_mutex); } =20 -static int init_event_notifier(EmulatedState *card) +static int init_event_notifier(EmulatedState *card, Error **errp) { if (event_notifier_init(&card->notifier, false) < 0) { - DPRINTF(card, 2, "event notifier creation failed\n"); + error_setg(errp, "ccid-card-emul: event notifier creation failed"); return -1; } event_notifier_set_handler(&card->notifier, card_event_handler); @@ -480,7 +481,7 @@ static uint32_t parse_enumeration(char *str, return ret; } =20 -static int emulated_initfn(CCIDCardState *base) +static void emulated_realize(CCIDCardState *base, Error **errp) { EmulatedState *card =3D EMULATED_CCID_CARD(base); VCardEmulError ret; @@ -494,8 +495,8 @@ static int emulated_initfn(CCIDCardState *base) qemu_cond_init(&card->handle_apdu_cond); card->reader =3D NULL; card->quit_apdu_thread =3D 0; - if (init_event_notifier(card) < 0) { - return -1; + if (init_event_notifier(card, errp) < 0) { + return; } =20 card->backend =3D 0; @@ -505,11 +506,11 @@ static int emulated_initfn(CCIDCardState *base) } =20 if (card->backend =3D=3D 0) { - printf("backend must be one of:\n"); + error_setg(errp, "backend must be one of:"); for (ptable =3D backend_enum_table; ptable->name !=3D NULL; ++ptab= le) { - printf("%s\n", ptable->name); + error_append_hint(errp, "%s\n", ptable->name); } - return -1; + return; } =20 /* TODO: a passthru backened that works on local machine. third card t= ype?*/ @@ -517,34 +518,33 @@ static int emulated_initfn(CCIDCardState *base) if (card->cert1 !=3D NULL && card->cert2 !=3D NULL && card->cert3 = !=3D NULL) { ret =3D emulated_initialize_vcard_from_certificates(card); } else { - printf("%s: you must provide all three certs for" - " certificates backend\n", TYPE_EMULATED_CCID); - return -1; + error_setg(errp, "%s: you must provide all three certs for" + " certificates backend", TYPE_EMULATED_CCID); + return; } } else { if (card->backend !=3D BACKEND_NSS_EMULATED) { - printf("%s: bad backend specified. The options are:\n%s (defau= lt)," - " %s.\n", TYPE_EMULATED_CCID, BACKEND_NSS_EMULATED_NAME, - BACKEND_CERTIFICATES_NAME); - return -1; + error_setg(errp, "%s: bad backend specified. The options are:%= s" + " (default), %s.", TYPE_EMULATED_CCID, + BACKEND_NSS_EMULATED_NAME, BACKEND_CERTIFICATES_NAM= E); + return; } if (card->cert1 !=3D NULL || card->cert2 !=3D NULL || card->cert3 = !=3D NULL) { - printf("%s: unexpected cert parameters to nss emulated backend= \n", - TYPE_EMULATED_CCID); - return -1; + error_setg(errp, "%s: unexpected cert parameters to nss emulat= ed " + "backend", TYPE_EMULATED_CCID); + return; } /* default to mirroring the local hardware readers */ ret =3D wrap_vcard_emul_init(NULL); } if (ret !=3D VCARD_EMUL_OK) { - printf("%s: failed to initialize vcard\n", TYPE_EMULATED_CCID); - return -1; + error_setg(errp, "%s: failed to initialize vcard", TYPE_EMULATED_C= CID); + return; } qemu_thread_create(&card->event_thread_id, "ccid/event", event_thread, card, QEMU_THREAD_JOINABLE); qemu_thread_create(&card->apdu_thread_id, "ccid/apdu", handle_apdu_thr= ead, card, QEMU_THREAD_JOINABLE); - return 0; } =20 static void emulated_exitfn(CCIDCardState *base) @@ -581,7 +581,7 @@ static void emulated_class_initfn(ObjectClass *klass, v= oid *data) DeviceClass *dc =3D DEVICE_CLASS(klass); CCIDCardClass *cc =3D CCID_CARD_CLASS(klass); =20 - cc->initfn =3D emulated_initfn; + cc->realize =3D emulated_realize; cc->exitfn =3D emulated_exitfn; cc->get_atr =3D emulated_get_atr; cc->apdu_from_guest =3D emulated_apdu_from_guest; diff --git a/hw/usb/ccid-card-passthru.c b/hw/usb/ccid-card-passthru.c index 117711862e..b7dd3602dc 100644 --- a/hw/usb/ccid-card-passthru.c +++ b/hw/usb/ccid-card-passthru.c @@ -14,6 +14,7 @@ #include "qemu/error-report.h" #include "qemu/sockets.h" #include "ccid.h" +#include "qapi/error.h" =20 #define DPRINTF(card, lvl, fmt, ...) \ do { \ @@ -337,29 +338,28 @@ static const uint8_t *passthru_get_atr(CCIDCardState = *base, uint32_t *len) return card->atr; } =20 -static int passthru_initfn(CCIDCardState *base) +static void passthru_realize(CCIDCardState *base, Error **errp) { PassthruState *card =3D PASSTHRU_CCID_CARD(base); =20 card->vscard_in_pos =3D 0; card->vscard_in_hdr =3D 0; if (qemu_chr_fe_backend_connected(&card->cs)) { - DPRINTF(card, D_INFO, "initing chardev\n"); + error_setg(errp, "ccid-card-passthru: initing chardev"); qemu_chr_fe_set_handlers(&card->cs, ccid_card_vscard_can_read, ccid_card_vscard_read, ccid_card_vscard_event, NULL, card, NULL, true); ccid_card_vscard_send_init(card); } else { - error_report("missing chardev"); - return -1; + error_setg(errp, "missing chardev"); + return; } card->debug =3D parse_debug_env("QEMU_CCID_PASSTHRU_DEBUG", D_VERBOSE, card->debug); assert(sizeof(DEFAULT_ATR) <=3D MAX_ATR_SIZE); memcpy(card->atr, DEFAULT_ATR, sizeof(DEFAULT_ATR)); card->atr_length =3D sizeof(DEFAULT_ATR); - return 0; } =20 static VMStateDescription passthru_vmstate =3D { @@ -387,7 +387,7 @@ static void passthru_class_initfn(ObjectClass *klass, v= oid *data) DeviceClass *dc =3D DEVICE_CLASS(klass); CCIDCardClass *cc =3D CCID_CARD_CLASS(klass); =20 - cc->initfn =3D passthru_initfn; + cc->realize =3D passthru_realize; cc->get_atr =3D passthru_get_atr; cc->apdu_from_guest =3D passthru_apdu_from_guest; set_bit(DEVICE_CATEGORY_INPUT, dc->categories); diff --git a/hw/usb/dev-smartcard-reader.c b/hw/usb/dev-smartcard-reader.c index e334d3be11..0092493f4e 100644 --- a/hw/usb/dev-smartcard-reader.c +++ b/hw/usb/dev-smartcard-reader.c @@ -510,14 +510,18 @@ static void ccid_card_exitfn(CCIDCardState *card) =20 } =20 -static int ccid_card_initfn(CCIDCardState *card) +static void ccid_card_initfn(CCIDCardState *card, Error **errp) { CCIDCardClass *cc =3D CCID_CARD_GET_CLASS(card); + Error *local_err =3D NULL; =20 - if (cc->initfn) { - return cc->initfn(card); + if (cc->realize) { + cc->realize(card, &local_err); + if (local_err !=3D NULL) { + error_propagate(errp, local_err); + return; + } } - return 0; } =20 static bool ccid_has_pending_answers(USBCCIDState *s) @@ -1295,27 +1299,28 @@ static int ccid_card_exit(DeviceState *qdev) return 0; } =20 -static int ccid_card_init(DeviceState *qdev) +static void ccid_card_realize(DeviceState *qdev, Error **errp) { CCIDCardState *card =3D CCID_CARD(qdev); USBDevice *dev =3D USB_DEVICE(qdev->parent_bus->parent); USBCCIDState *s =3D USB_CCID_DEV(dev); - int ret =3D 0; + Error *local_err =3D NULL; =20 if (card->slot !=3D 0) { - warn_report("usb-ccid supports one slot, can't add %d", - card->slot); - return -1; + error_setg(errp, "usb-ccid supports one slot, can't add %d", + card->slot); + return; } if (s->card !=3D NULL) { - warn_report("usb-ccid card already full, not adding"); - return -1; + error_setg(errp, "usb-ccid card already full, not adding"); + return; } - ret =3D ccid_card_initfn(card); - if (ret =3D=3D 0) { - s->card =3D card; + ccid_card_initfn(card, &local_err); + if (local_err !=3D NULL) { + error_propagate(errp, local_err); + return; } - return ret; + s->card =3D card; } =20 static void ccid_realize(USBDevice *dev, Error **errp) @@ -1477,7 +1482,7 @@ static void ccid_card_class_init(ObjectClass *klass, = void *data) { DeviceClass *k =3D DEVICE_CLASS(klass); k->bus_type =3D TYPE_CCID_BUS; - k->init =3D ccid_card_init; + k->realize =3D ccid_card_realize; k->exit =3D ccid_card_exit; k->props =3D ccid_props; } --=20 2.9.3 From nobody Mon Apr 29 17:27:57 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (208.118.235.17 [208.118.235.17]) by mx.zohomail.com with SMTPS id 151695501490861.43979008759038; Fri, 26 Jan 2018 00:23:34 -0800 (PST) Received: from localhost ([::1]:40142 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eezIE-0002UB-85 for importer@patchew.org; Fri, 26 Jan 2018 03:23:26 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:44529) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eezHG-00027Z-Au for qemu-devel@nongnu.org; Fri, 26 Jan 2018 03:22:27 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1eezHC-0004FU-TJ for qemu-devel@nongnu.org; Fri, 26 Jan 2018 03:22:26 -0500 Received: from mx1.redhat.com ([209.132.183.28]:57320) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1eezHC-0004FA-OS for qemu-devel@nongnu.org; Fri, 26 Jan 2018 03:22:22 -0500 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 44CF4394C5A; Fri, 26 Jan 2018 08:05:21 +0000 (UTC) Received: from sirius.home.kraxel.org (ovpn-116-227.ams2.redhat.com [10.36.116.227]) by smtp.corp.redhat.com (Postfix) with ESMTP id 26B356F978; Fri, 26 Jan 2018 08:05:18 +0000 (UTC) Received: by sirius.home.kraxel.org (Postfix, from userid 1000) id 0702E16E03; Fri, 26 Jan 2018 09:05:16 +0100 (CET) From: Gerd Hoffmann To: qemu-devel@nongnu.org Date: Fri, 26 Jan 2018 09:05:14 +0100 Message-Id: <20180126080515.26108-5-kraxel@redhat.com> In-Reply-To: <20180126080515.26108-1-kraxel@redhat.com> References: <20180126080515.26108-1-kraxel@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.29]); Fri, 26 Jan 2018 08:05:21 +0000 (UTC) Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PULL 4/5] usb-ccid: inline ccid_card_initfn() in ccid_card_realize() X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Gerd Hoffmann Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" From: Philippe Mathieu-Daud=C3=A9 Signed-off-by: Philippe Mathieu-Daud=C3=A9 Message-id: 20180125171432.13554-3-f4bug@amsat.org Signed-off-by: Gerd Hoffmann --- hw/usb/dev-smartcard-reader.c | 25 +++++++------------------ 1 file changed, 7 insertions(+), 18 deletions(-) diff --git a/hw/usb/dev-smartcard-reader.c b/hw/usb/dev-smartcard-reader.c index 0092493f4e..85f5f2247b 100644 --- a/hw/usb/dev-smartcard-reader.c +++ b/hw/usb/dev-smartcard-reader.c @@ -510,20 +510,6 @@ static void ccid_card_exitfn(CCIDCardState *card) =20 } =20 -static void ccid_card_initfn(CCIDCardState *card, Error **errp) -{ - CCIDCardClass *cc =3D CCID_CARD_GET_CLASS(card); - Error *local_err =3D NULL; - - if (cc->realize) { - cc->realize(card, &local_err); - if (local_err !=3D NULL) { - error_propagate(errp, local_err); - return; - } - } -} - static bool ccid_has_pending_answers(USBCCIDState *s) { return s->pending_answers_num > 0; @@ -1302,6 +1288,7 @@ static int ccid_card_exit(DeviceState *qdev) static void ccid_card_realize(DeviceState *qdev, Error **errp) { CCIDCardState *card =3D CCID_CARD(qdev); + CCIDCardClass *cc =3D CCID_CARD_GET_CLASS(card); USBDevice *dev =3D USB_DEVICE(qdev->parent_bus->parent); USBCCIDState *s =3D USB_CCID_DEV(dev); Error *local_err =3D NULL; @@ -1315,10 +1302,12 @@ static void ccid_card_realize(DeviceState *qdev, Er= ror **errp) error_setg(errp, "usb-ccid card already full, not adding"); return; } - ccid_card_initfn(card, &local_err); - if (local_err !=3D NULL) { - error_propagate(errp, local_err); - return; + if (cc->realize) { + cc->realize(card, &local_err); + if (local_err !=3D NULL) { + error_propagate(errp, local_err); + return; + } } s->card =3D card; } --=20 2.9.3 From nobody Mon Apr 29 17:27:57 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1516954001137761.1685061269408; Fri, 26 Jan 2018 00:06:41 -0800 (PST) Received: from localhost ([::1]:39358 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eez1y-0004pM-Mo for importer@patchew.org; Fri, 26 Jan 2018 03:06:38 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:41989) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eez0t-0004MH-PS for qemu-devel@nongnu.org; Fri, 26 Jan 2018 03:05:32 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1eez0q-00014D-Ju for qemu-devel@nongnu.org; Fri, 26 Jan 2018 03:05:31 -0500 Received: from mx1.redhat.com ([209.132.183.28]:59352) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1eez0q-00013q-Aj for qemu-devel@nongnu.org; Fri, 26 Jan 2018 03:05:28 -0500 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 891B51618A3; Fri, 26 Jan 2018 08:05:27 +0000 (UTC) Received: from sirius.home.kraxel.org (ovpn-116-227.ams2.redhat.com [10.36.116.227]) by smtp.corp.redhat.com (Postfix) with ESMTP id 926985EE1B; Fri, 26 Jan 2018 08:05:25 +0000 (UTC) Received: by sirius.home.kraxel.org (Postfix, from userid 1000) id 1248417442; Fri, 26 Jan 2018 09:05:16 +0100 (CET) From: Gerd Hoffmann To: qemu-devel@nongnu.org Date: Fri, 26 Jan 2018 09:05:15 +0100 Message-Id: <20180126080515.26108-6-kraxel@redhat.com> In-Reply-To: <20180126080515.26108-1-kraxel@redhat.com> References: <20180126080515.26108-1-kraxel@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.27]); Fri, 26 Jan 2018 08:05:27 +0000 (UTC) Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PULL 5/5] usb-ccid: convert CCIDCardClass::exitfn() -> unrealize() X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Gerd Hoffmann Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" From: Philippe Mathieu-Daud=C3=A9 Signed-off-by: Philippe Mathieu-Daud=C3=A9 Message-id: 20180125171432.13554-4-f4bug@amsat.org Signed-off-by: Gerd Hoffmann --- hw/usb/ccid.h | 4 +++- hw/usb/ccid-card-emulated.c | 4 ++-- hw/usb/ccid-card-passthru.c | 1 + hw/usb/dev-smartcard-reader.c | 25 +++++++++++-------------- 4 files changed, 17 insertions(+), 17 deletions(-) diff --git a/hw/usb/ccid.h b/hw/usb/ccid.h index 6c6c10188d..3920733f13 100644 --- a/hw/usb/ccid.h +++ b/hw/usb/ccid.h @@ -28,13 +28,15 @@ typedef struct CCIDCardInfo CCIDCardInfo; * into the smartcard device (hw/ccid-card-*.c) */ typedef struct CCIDCardClass { + /*< private >*/ DeviceClass parent_class; + /*< public >*/ const uint8_t *(*get_atr)(CCIDCardState *card, uint32_t *len); void (*apdu_from_guest)(CCIDCardState *card, const uint8_t *apdu, uint32_t len); - void (*exitfn)(CCIDCardState *card); void (*realize)(CCIDCardState *card, Error **errp); + void (*unrealize)(CCIDCardState *card, Error **errp); } CCIDCardClass; =20 /* diff --git a/hw/usb/ccid-card-emulated.c b/hw/usb/ccid-card-emulated.c index daefd9f8f4..ea42e4681d 100644 --- a/hw/usb/ccid-card-emulated.c +++ b/hw/usb/ccid-card-emulated.c @@ -547,7 +547,7 @@ static void emulated_realize(CCIDCardState *base, Error= **errp) card, QEMU_THREAD_JOINABLE); } =20 -static void emulated_exitfn(CCIDCardState *base) +static void emulated_unrealize(CCIDCardState *base, Error **errp) { EmulatedState *card =3D EMULATED_CCID_CARD(base); VEvent *vevent =3D vevent_new(VEVENT_LAST, NULL, NULL); @@ -582,7 +582,7 @@ static void emulated_class_initfn(ObjectClass *klass, v= oid *data) CCIDCardClass *cc =3D CCID_CARD_CLASS(klass); =20 cc->realize =3D emulated_realize; - cc->exitfn =3D emulated_exitfn; + cc->unrealize =3D emulated_unrealize; cc->get_atr =3D emulated_get_atr; cc->apdu_from_guest =3D emulated_apdu_from_guest; set_bit(DEVICE_CATEGORY_INPUT, dc->categories); diff --git a/hw/usb/ccid-card-passthru.c b/hw/usb/ccid-card-passthru.c index b7dd3602dc..085ed2c667 100644 --- a/hw/usb/ccid-card-passthru.c +++ b/hw/usb/ccid-card-passthru.c @@ -9,6 +9,7 @@ */ =20 #include "qemu/osdep.h" +#include "qapi/error.h" #include #include "chardev/char-fe.h" #include "qemu/error-report.h" diff --git a/hw/usb/dev-smartcard-reader.c b/hw/usb/dev-smartcard-reader.c index 85f5f2247b..e6468057a0 100644 --- a/hw/usb/dev-smartcard-reader.c +++ b/hw/usb/dev-smartcard-reader.c @@ -500,16 +500,6 @@ static void ccid_card_apdu_from_guest(CCIDCardState *c= ard, } } =20 -static void ccid_card_exitfn(CCIDCardState *card) -{ - CCIDCardClass *cc =3D CCID_CARD_GET_CLASS(card); - - if (cc->exitfn) { - cc->exitfn(card); - } - -} - static bool ccid_has_pending_answers(USBCCIDState *s) { return s->pending_answers_num > 0; @@ -1271,18 +1261,25 @@ void ccid_card_card_inserted(CCIDCardState *card) ccid_on_slot_change(s, true); } =20 -static int ccid_card_exit(DeviceState *qdev) +static void ccid_card_unrealize(DeviceState *qdev, Error **errp) { CCIDCardState *card =3D CCID_CARD(qdev); + CCIDCardClass *cc =3D CCID_CARD_GET_CLASS(card); USBDevice *dev =3D USB_DEVICE(qdev->parent_bus->parent); USBCCIDState *s =3D USB_CCID_DEV(dev); + Error *local_err =3D NULL; =20 if (ccid_card_inserted(s)) { ccid_card_card_removed(card); } - ccid_card_exitfn(card); + if (cc->unrealize) { + cc->unrealize(card, &local_err); + if (local_err !=3D NULL) { + error_propagate(errp, local_err); + return; + } + } s->card =3D NULL; - return 0; } =20 static void ccid_card_realize(DeviceState *qdev, Error **errp) @@ -1472,7 +1469,7 @@ static void ccid_card_class_init(ObjectClass *klass, = void *data) DeviceClass *k =3D DEVICE_CLASS(klass); k->bus_type =3D TYPE_CCID_BUS; k->realize =3D ccid_card_realize; - k->exit =3D ccid_card_exit; + k->unrealize =3D ccid_card_unrealize; k->props =3D ccid_props; } =20 --=20 2.9.3