qemu with hax to log dma reads & writes jcs.org/2018/11/12/vfio

usb: Remove legacy -usbdevice options (host, serial, disk and net)

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 <thuth@redhat.com>
Message-id: 1515519171-20315-1-git-send-email-thuth@redhat.com

[kraxel] delete some usb_host_device_open() leftovers.

Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>

authored by

Thomas Huth and committed by
Gerd Hoffmann
99761176 2077fef9

+1 -300
+1 -1
hw/usb/Makefile.objs
··· 43 43 44 44 # usb pass-through 45 45 ifeq ($(CONFIG_USB_LIBUSB)$(CONFIG_USB),yy) 46 - common-obj-y += host-libusb.o host-legacy.o 46 + common-obj-y += host-libusb.o 47 47 else 48 48 common-obj-y += host-stub.o 49 49 endif
-26
hw/usb/dev-network.c
··· 1382 1382 &dev->qdev, NULL); 1383 1383 } 1384 1384 1385 - static USBDevice *usb_net_init(USBBus *bus, const char *cmdline) 1386 - { 1387 - Error *local_err = NULL; 1388 - USBDevice *dev; 1389 - QemuOpts *opts; 1390 - int idx; 1391 - 1392 - opts = qemu_opts_parse_noisily(qemu_find_opts("net"), cmdline, false); 1393 - if (!opts) { 1394 - return NULL; 1395 - } 1396 - qemu_opt_set(opts, "type", "nic", &error_abort); 1397 - qemu_opt_set(opts, "model", "usb", &error_abort); 1398 - 1399 - idx = net_client_init(opts, false, &local_err); 1400 - if (local_err) { 1401 - error_report_err(local_err); 1402 - return NULL; 1403 - } 1404 - 1405 - dev = usb_create(bus, "usb-net"); 1406 - qdev_set_nic_properties(&dev->qdev, &nd_table[idx]); 1407 - return dev; 1408 - } 1409 - 1410 1385 static const VMStateDescription vmstate_usb_net = { 1411 1386 .name = "usb-net", 1412 1387 .unmigratable = 1, ··· 1446 1421 static void usb_net_register_types(void) 1447 1422 { 1448 1423 type_register_static(&net_info); 1449 - usb_legacy_register(TYPE_USB_NET, "net", usb_net_init); 1450 1424 } 1451 1425 1452 1426 type_init(usb_net_register_types)
-30
hw/usb/dev-serial.c
··· 509 509 } 510 510 } 511 511 512 - static USBDevice *usb_serial_init(USBBus *bus, const char *filename) 513 - { 514 - USBDevice *dev; 515 - Chardev *cdrv; 516 - char label[32]; 517 - static int index; 518 - 519 - if (*filename == ':') { 520 - filename++; 521 - } else if (*filename) { 522 - error_report("unrecognized serial USB option %s", filename); 523 - return NULL; 524 - } 525 - if (!*filename) { 526 - error_report("character device specification needed"); 527 - return NULL; 528 - } 529 - 530 - snprintf(label, sizeof(label), "usbserial%d", index++); 531 - cdrv = qemu_chr_new(label, filename); 532 - if (!cdrv) 533 - return NULL; 534 - 535 - dev = usb_create(bus, "usb-serial"); 536 - qdev_prop_set_chr(&dev->qdev, "chardev", cdrv); 537 - 538 - return dev; 539 - } 540 - 541 512 static USBDevice *usb_braille_init(USBBus *bus, const char *unused) 542 513 { 543 514 USBDevice *dev; ··· 624 595 { 625 596 type_register_static(&usb_serial_dev_type_info); 626 597 type_register_static(&serial_info); 627 - usb_legacy_register("usb-serial", "serial", usb_serial_init); 628 598 type_register_static(&braille_info); 629 599 usb_legacy_register("usb-braille", "braille", usb_braille_init); 630 600 }
-58
hw/usb/dev-storage.c
··· 666 666 usb_msd_handle_reset(dev); 667 667 } 668 668 669 - static USBDevice *usb_msd_init(USBBus *bus, const char *filename) 670 - { 671 - static int nr=0; 672 - Error *err = NULL; 673 - char id[8]; 674 - QemuOpts *opts; 675 - DriveInfo *dinfo; 676 - USBDevice *dev; 677 - const char *p1; 678 - char fmt[32]; 679 - 680 - /* parse -usbdevice disk: syntax into drive opts */ 681 - do { 682 - snprintf(id, sizeof(id), "usb%d", nr++); 683 - opts = qemu_opts_create(qemu_find_opts("drive"), id, 1, NULL); 684 - } while (!opts); 685 - 686 - p1 = strchr(filename, ':'); 687 - if (p1++) { 688 - const char *p2; 689 - 690 - if (strstart(filename, "format=", &p2)) { 691 - int len = MIN(p1 - p2, sizeof(fmt)); 692 - pstrcpy(fmt, len, p2); 693 - qemu_opt_set(opts, "format", fmt, &error_abort); 694 - } else if (*filename != ':') { 695 - error_report("unrecognized USB mass-storage option %s", filename); 696 - return NULL; 697 - } 698 - filename = p1; 699 - } 700 - if (!*filename) { 701 - error_report("block device specification needed"); 702 - return NULL; 703 - } 704 - qemu_opt_set(opts, "file", filename, &error_abort); 705 - qemu_opt_set(opts, "if", "none", &error_abort); 706 - 707 - /* create host drive */ 708 - dinfo = drive_new(opts, 0); 709 - if (!dinfo) { 710 - qemu_opts_del(opts); 711 - return NULL; 712 - } 713 - 714 - /* create guest device */ 715 - dev = usb_create(bus, "usb-storage"); 716 - qdev_prop_set_drive(&dev->qdev, "drive", blk_by_legacy_dinfo(dinfo), 717 - &err); 718 - if (err) { 719 - error_report_err(err); 720 - object_unparent(OBJECT(dev)); 721 - return NULL; 722 - } 723 - return dev; 724 - } 725 - 726 669 static const VMStateDescription vmstate_usb_msd = { 727 670 .name = "usb-storage", 728 671 .version_id = 1, ··· 855 798 type_register_static(&usb_storage_dev_type_info); 856 799 type_register_static(&msd_info); 857 800 type_register_static(&bot_info); 858 - usb_legacy_register("usb-storage", "disk", usb_msd_init); 859 801 } 860 802 861 803 type_init(usb_msd_register_types)
-144
hw/usb/host-legacy.c
··· 1 - /* 2 - * Linux host USB redirector 3 - * 4 - * Copyright (c) 2005 Fabrice Bellard 5 - * 6 - * Copyright (c) 2008 Max Krasnyansky 7 - * Support for host device auto connect & disconnect 8 - * Major rewrite to support fully async operation 9 - * 10 - * Copyright 2008 TJ <linux@tjworld.net> 11 - * Added flexible support for /dev/bus/usb /sys/bus/usb/devices in addition 12 - * to the legacy /proc/bus/usb USB device discovery and handling 13 - * 14 - * Permission is hereby granted, free of charge, to any person obtaining a copy 15 - * of this software and associated documentation files (the "Software"), to deal 16 - * in the Software without restriction, including without limitation the rights 17 - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 18 - * copies of the Software, and to permit persons to whom the Software is 19 - * furnished to do so, subject to the following conditions: 20 - * 21 - * The above copyright notice and this permission notice shall be included in 22 - * all copies or substantial portions of the Software. 23 - * 24 - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 25 - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 26 - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 27 - * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 28 - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 29 - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 30 - * THE SOFTWARE. 31 - */ 32 - 33 - #include "qemu/osdep.h" 34 - #include "qemu-common.h" 35 - #include "hw/usb.h" 36 - #include "hw/usb/host.h" 37 - 38 - /* 39 - * Autoconnect filter 40 - * Format: 41 - * auto:bus:dev[:vid:pid] 42 - * auto:bus.dev[:vid:pid] 43 - * 44 - * bus - bus number (dec, * means any) 45 - * dev - device number (dec, * means any) 46 - * vid - vendor id (hex, * means any) 47 - * pid - product id (hex, * means any) 48 - * 49 - * See 'lsusb' output. 50 - */ 51 - static int parse_filter(const char *spec, struct USBAutoFilter *f) 52 - { 53 - enum { BUS, DEV, VID, PID, DONE }; 54 - const char *p = spec; 55 - int i; 56 - 57 - f->bus_num = 0; 58 - f->addr = 0; 59 - f->vendor_id = 0; 60 - f->product_id = 0; 61 - 62 - for (i = BUS; i < DONE; i++) { 63 - p = strpbrk(p, ":."); 64 - if (!p) { 65 - break; 66 - } 67 - p++; 68 - 69 - if (*p == '*') { 70 - continue; 71 - } 72 - switch (i) { 73 - case BUS: 74 - f->bus_num = strtol(p, NULL, 10); 75 - break; 76 - case DEV: 77 - f->addr = strtol(p, NULL, 10); 78 - break; 79 - case VID: 80 - f->vendor_id = strtol(p, NULL, 16); 81 - break; 82 - case PID: 83 - f->product_id = strtol(p, NULL, 16); 84 - break; 85 - } 86 - } 87 - 88 - if (i < DEV) { 89 - fprintf(stderr, "husb: invalid auto filter spec %s\n", spec); 90 - return -1; 91 - } 92 - 93 - return 0; 94 - } 95 - 96 - USBDevice *usb_host_device_open(USBBus *bus, const char *devname) 97 - { 98 - struct USBAutoFilter filter; 99 - USBDevice *dev; 100 - char *p; 101 - 102 - dev = usb_create(bus, "usb-host"); 103 - 104 - if (strstr(devname, "auto:")) { 105 - if (parse_filter(devname, &filter) < 0) { 106 - goto fail; 107 - } 108 - } else { 109 - p = strchr(devname, '.'); 110 - if (p) { 111 - filter.bus_num = strtoul(devname, NULL, 0); 112 - filter.addr = strtoul(p + 1, NULL, 0); 113 - filter.vendor_id = 0; 114 - filter.product_id = 0; 115 - } else { 116 - p = strchr(devname, ':'); 117 - if (p) { 118 - filter.bus_num = 0; 119 - filter.addr = 0; 120 - filter.vendor_id = strtoul(devname, NULL, 16); 121 - filter.product_id = strtoul(p + 1, NULL, 16); 122 - } else { 123 - goto fail; 124 - } 125 - } 126 - } 127 - 128 - qdev_prop_set_uint32(&dev->qdev, "hostbus", filter.bus_num); 129 - qdev_prop_set_uint32(&dev->qdev, "hostaddr", filter.addr); 130 - qdev_prop_set_uint32(&dev->qdev, "vendorid", filter.vendor_id); 131 - qdev_prop_set_uint32(&dev->qdev, "productid", filter.product_id); 132 - return dev; 133 - 134 - fail: 135 - object_unparent(OBJECT(dev)); 136 - return NULL; 137 - } 138 - 139 - static void usb_host_register_types(void) 140 - { 141 - usb_legacy_register("usb-host", "host", usb_host_device_open); 142 - } 143 - 144 - type_init(usb_host_register_types)
-6
hw/usb/host-stub.c
··· 41 41 monitor_printf(mon, "USB host devices not supported\n"); 42 42 } 43 43 44 - /* XXX: modify configure to compile the right host driver */ 45 - USBDevice *usb_host_device_open(USBBus *bus, const char *devname) 46 - { 47 - return NULL; 48 - } 49 - 50 44 bool usb_host_dev_is_scsi_storage(USBDevice *ud) 51 45 { 52 46 return false;
-1
include/hw/usb.h
··· 466 466 void usb_generic_async_ctrl_complete(USBDevice *s, USBPacket *p); 467 467 468 468 /* usb-linux.c */ 469 - USBDevice *usb_host_device_open(USBBus *bus, const char *devname); 470 469 void hmp_info_usbhost(Monitor *mon, const QDict *qdict); 471 470 bool usb_host_dev_is_scsi_storage(USBDevice *usbdev); 472 471
-19
qemu-options.hx
··· 1221 1221 means QEMU is able to report the mouse position without having to grab the 1222 1222 mouse. Also overrides the PS/2 mouse emulation when activated. 1223 1223 1224 - @item disk:[format=@var{format}]:@var{file} 1225 - Mass storage device based on file. The optional @var{format} argument 1226 - will be used rather than detecting the format. Can be used to specify 1227 - @code{format=raw} to avoid interpreting an untrusted format header. 1228 - 1229 - @item host:@var{bus}.@var{addr} 1230 - Pass through the host device identified by @var{bus}.@var{addr} (Linux only). 1231 - 1232 - @item host:@var{vendor_id}:@var{product_id} 1233 - Pass through the host device identified by @var{vendor_id}:@var{product_id} 1234 - (Linux only). 1235 - 1236 - @item serial:[vendorid=@var{vendor_id}][,productid=@var{product_id}]:@var{dev} 1237 - Serial converter to host character device @var{dev}, see @code{-serial} for the 1238 - available devices. 1239 - 1240 1224 @item braille 1241 1225 Braille device. This will use BrlAPI to display the braille output on a real 1242 1226 or fake device. 1243 - 1244 - @item net:@var{options} 1245 - Network adapter that supports CDC ethernet and RNDIS protocols. 1246 1227 1247 1228 @end table 1248 1229 ETEXI
-15
vl.c
··· 1451 1451 static int usb_device_add(const char *devname) 1452 1452 { 1453 1453 USBDevice *dev = NULL; 1454 - #ifndef CONFIG_LINUX 1455 - const char *p; 1456 - #endif 1457 1454 1458 1455 if (!machine_usb(current_machine)) { 1459 1456 return -1; 1460 1457 } 1461 1458 1462 - /* drivers with .usbdevice_name entry in USBDeviceInfo */ 1463 1459 dev = usbdevice_create(devname); 1464 - if (dev) 1465 - goto done; 1466 - 1467 - /* the other ones */ 1468 - #ifndef CONFIG_LINUX 1469 - /* only the linux version is qdev-ified, usb-bsd still needs this */ 1470 - if (strstart(devname, "host:", &p)) { 1471 - dev = usb_host_device_open(usb_bus_find(-1), p); 1472 - } 1473 - #endif 1474 1460 if (!dev) 1475 1461 return -1; 1476 1462 1477 - done: 1478 1463 return 0; 1479 1464 } 1480 1465