Add remove_boot_device_path() function to remove bootindex when hot-unplug a device.
Signed-off-by: Jun Li <junm...@gmail.com> --- hw/block/virtio-blk.c | 1 + hw/i386/kvm/pci-assign.c | 1 + hw/misc/vfio.c | 1 + hw/net/e1000.c | 1 + hw/net/eepro100.c | 1 + hw/net/ne2000.c | 1 + hw/net/rtl8139.c | 1 + hw/net/spapr_llan.c | 2 ++ hw/net/virtio-net.c | 1 + hw/net/vmxnet3.c | 2 ++ hw/scsi/scsi-disk.c | 1 + hw/scsi/scsi-generic.c | 1 + hw/usb/dev-network.c | 1 + hw/usb/host-libusb.c | 1 + hw/usb/redirect.c | 1 + include/sysemu/sysemu.h | 1 + vl.c | 16 ++++++++++++++++ 17 files changed, 34 insertions(+) diff --git a/hw/block/virtio-blk.c b/hw/block/virtio-blk.c index 8a568e5..497eb40 100644 --- a/hw/block/virtio-blk.c +++ b/hw/block/virtio-blk.c @@ -752,6 +752,7 @@ static void virtio_blk_device_unrealize(DeviceState *dev, Error **errp) unregister_savevm(dev, "virtio-blk", s); blockdev_mark_auto_del(s->bs); virtio_cleanup(vdev); + remove_boot_device_path(s->conf->bootindex); } static Property virtio_blk_properties[] = { diff --git a/hw/i386/kvm/pci-assign.c b/hw/i386/kvm/pci-assign.c index de33657..e655c8c 100644 --- a/hw/i386/kvm/pci-assign.c +++ b/hw/i386/kvm/pci-assign.c @@ -1855,6 +1855,7 @@ static void assigned_exitfn(struct PCIDevice *pci_dev) deassign_device(dev); free_assigned_device(dev); + remove_boot_device_path(dev->bootindex); } static Property assigned_dev_properties[] = { diff --git a/hw/misc/vfio.c b/hw/misc/vfio.c index 9cf5b84..1fea17d 100644 --- a/hw/misc/vfio.c +++ b/hw/misc/vfio.c @@ -3900,6 +3900,7 @@ static void vfio_exitfn(PCIDevice *pdev) g_free(vdev->rom); vfio_put_device(vdev); vfio_put_group(group); + remove_boot_device_path(vdev->bootindex); } static void vfio_pci_reset(DeviceState *dev) diff --git a/hw/net/e1000.c b/hw/net/e1000.c index 8387443..190a9b1 100644 --- a/hw/net/e1000.c +++ b/hw/net/e1000.c @@ -1491,6 +1491,7 @@ pci_e1000_uninit(PCIDevice *dev) memory_region_destroy(&d->mmio); memory_region_destroy(&d->io); qemu_del_nic(d->nic); + remove_boot_device_path(d->conf.bootindex); } static NetClientInfo net_e1000_info = { diff --git a/hw/net/eepro100.c b/hw/net/eepro100.c index 3b891ca..54924a4 100644 --- a/hw/net/eepro100.c +++ b/hw/net/eepro100.c @@ -1850,6 +1850,7 @@ static void pci_nic_uninit(PCIDevice *pci_dev) vmstate_unregister(&pci_dev->qdev, s->vmstate, s); eeprom93xx_free(&pci_dev->qdev, s->eeprom); qemu_del_nic(s->nic); + remove_boot_device_path(s->conf.bootindex); } static NetClientInfo net_eepro100_info = { diff --git a/hw/net/ne2000.c b/hw/net/ne2000.c index 4c32e9e..53ef57a 100644 --- a/hw/net/ne2000.c +++ b/hw/net/ne2000.c @@ -753,6 +753,7 @@ static void pci_ne2000_exit(PCIDevice *pci_dev) memory_region_destroy(&s->io); qemu_del_nic(s->nic); qemu_free_irq(s->irq); + remove_boot_device_path(s->c.bootindex); } static Property ne2000_properties[] = { diff --git a/hw/net/rtl8139.c b/hw/net/rtl8139.c index 5329f44..a6b6130 100644 --- a/hw/net/rtl8139.c +++ b/hw/net/rtl8139.c @@ -3474,6 +3474,7 @@ static void pci_rtl8139_uninit(PCIDevice *dev) timer_del(s->timer); timer_free(s->timer); qemu_del_nic(s->nic); + remove_boot_device_path(s->conf.bootindex); } static void rtl8139_set_link_status(NetClientState *nc) diff --git a/hw/net/spapr_llan.c b/hw/net/spapr_llan.c index c433337..8fbd5b1 100644 --- a/hw/net/spapr_llan.c +++ b/hw/net/spapr_llan.c @@ -185,6 +185,8 @@ static void spapr_vlan_cleanup(NetClientState *nc) VIOsPAPRVLANDevice *dev = qemu_get_nic_opaque(nc); dev->nic = NULL; + + remove_boot_device_path(dev->nicconf.bootindex); } static NetClientInfo net_spapr_vlan_info = { diff --git a/hw/net/virtio-net.c b/hw/net/virtio-net.c index 940a7cf..6afb1ca 100644 --- a/hw/net/virtio-net.c +++ b/hw/net/virtio-net.c @@ -1645,6 +1645,7 @@ static void virtio_net_device_unrealize(DeviceState *dev, Error **errp) g_free(n->vqs); qemu_del_nic(n->nic); virtio_cleanup(vdev); + remove_boot_device_path(n->nic_conf.bootindex); } static void virtio_net_instance_init(Object *obj) diff --git a/hw/net/vmxnet3.c b/hw/net/vmxnet3.c index 1bb9259..20a657c 100644 --- a/hw/net/vmxnet3.c +++ b/hw/net/vmxnet3.c @@ -2186,6 +2186,8 @@ static void vmxnet3_pci_uninit(PCIDevice *pci_dev) memory_region_destroy(&s->bar0); memory_region_destroy(&s->bar1); memory_region_destroy(&s->msix_bar); + + remove_boot_device_path(s->conf.bootindex); } static void vmxnet3_qdev_reset(DeviceState *dev) diff --git a/hw/scsi/scsi-disk.c b/hw/scsi/scsi-disk.c index 4bcef55..d33df2e 100644 --- a/hw/scsi/scsi-disk.c +++ b/hw/scsi/scsi-disk.c @@ -2156,6 +2156,7 @@ static void scsi_destroy(SCSIDevice *dev) scsi_device_purge_requests(&s->qdev, SENSE_CODE(NO_SENSE)); blockdev_mark_auto_del(s->qdev.conf.bs); + remove_boot_device_path(s->qdev.conf.bootindex); } static void scsi_disk_resize_cb(void *opaque) diff --git a/hw/scsi/scsi-generic.c b/hw/scsi/scsi-generic.c index 3733d2c..d387f3e 100644 --- a/hw/scsi/scsi-generic.c +++ b/hw/scsi/scsi-generic.c @@ -390,6 +390,7 @@ static void scsi_destroy(SCSIDevice *s) { scsi_device_purge_requests(s, SENSE_CODE(NO_SENSE)); blockdev_mark_auto_del(s->conf.bs); + remove_boot_device_path(s->conf.bootindex); } static int scsi_generic_initfn(SCSIDevice *s) diff --git a/hw/usb/dev-network.c b/hw/usb/dev-network.c index 518d536..3aab429 100644 --- a/hw/usb/dev-network.c +++ b/hw/usb/dev-network.c @@ -1331,6 +1331,7 @@ static void usb_net_handle_destroy(USBDevice *dev) /* TODO: remove the nd_table[] entry */ rndis_clear_responsequeue(s); qemu_del_nic(s->nic); + remove_boot_device_path(s->conf.bootindex); } static NetClientInfo net_usbnet_info = { diff --git a/hw/usb/host-libusb.c b/hw/usb/host-libusb.c index 57bed09..3026258 100644 --- a/hw/usb/host-libusb.c +++ b/hw/usb/host-libusb.c @@ -920,6 +920,7 @@ static void usb_host_handle_destroy(USBDevice *udev) qemu_remove_exit_notifier(&s->exit); QTAILQ_REMOVE(&hostdevs, s, next); usb_host_close(s); + remove_boot_device_path(s->bootindex); } static void usb_host_cancel_packet(USBDevice *udev, USBPacket *p) diff --git a/hw/usb/redirect.c b/hw/usb/redirect.c index 287a505..27dc173 100644 --- a/hw/usb/redirect.c +++ b/hw/usb/redirect.c @@ -1351,6 +1351,7 @@ static void usbredir_handle_destroy(USBDevice *udev) } free(dev->filter_rules); + remove_boot_device_path(dev->bootindex); } static int usbredir_check_filter(USBRedirDevice *dev) diff --git a/include/sysemu/sysemu.h b/include/sysemu/sysemu.h index ba5c7f8..2510e3b 100644 --- a/include/sysemu/sysemu.h +++ b/include/sysemu/sysemu.h @@ -193,6 +193,7 @@ void rtc_change_mon_event(struct tm *tm); void add_boot_device_path(int32_t bootindex, DeviceState *dev, const char *suffix); +void remove_boot_device_path(int32_t bootindex); char *get_boot_devices_list(size_t *size, bool ignore_suffixes); DeviceState *get_boot_device(uint32_t position); diff --git a/vl.c b/vl.c index 709d8cd..dd4049e 100644 --- a/vl.c +++ b/vl.c @@ -1189,6 +1189,22 @@ void add_boot_device_path(int32_t bootindex, DeviceState *dev, QTAILQ_INSERT_TAIL(&fw_boot_order, node, link); } +void remove_boot_device_path(int32_t bootindex) +{ + FWBootEntry *node, *next_node; + + if (bootindex == -1) { + return; + } + + QTAILQ_FOREACH_SAFE(node, &fw_boot_order, link, next_node) { + if (node->bootindex == bootindex) { + QTAILQ_REMOVE(&fw_boot_order, node, link); + return; + } + } +} + DeviceState *get_boot_device(uint32_t position) { uint32_t counter = 0; -- 1.9.0