qemu-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Qemu-devel] [PATCH v6 06/27] bootindex: move setting bootindex on reset


From: arei.gonglei
Subject: [Qemu-devel] [PATCH v6 06/27] bootindex: move setting bootindex on reset() instead of realize/init()
Date: Sat, 30 Aug 2014 18:00:06 +0800

From: Gonglei <address@hidden>

Only in this way, we can assure the new bootindex take effect
during vm rebooting.

Signed-off-by: Gonglei <address@hidden>
---
 hw/block/fdc.c           |  6 +++---
 hw/block/virtio-blk.c    |  4 ++--
 hw/i386/kvm/pci-assign.c |  4 ++--
 hw/ide/qdev.c            | 14 +++++++++++---
 hw/misc/vfio.c           |  3 ++-
 hw/net/e1000.c           |  4 ++--
 hw/net/eepro100.c        | 10 ++++++++--
 hw/net/lance.c           |  2 ++
 hw/net/ne2000.c          | 11 +++++++++--
 hw/net/pcnet-pci.c       |  3 +++
 hw/net/pcnet.c           |  7 +++++--
 hw/net/pcnet.h           |  1 +
 hw/net/rtl8139.c         |  4 ++--
 hw/net/spapr_llan.c      |  4 ++--
 hw/net/virtio-net.c      |  5 +++--
 hw/net/vmxnet3.c         |  4 ++--
 hw/scsi/scsi-disk.c      |  3 ++-
 hw/scsi/scsi-generic.c   |  7 ++++---
 hw/usb/dev-network.c     |  4 +++-
 hw/usb/host-libusb.c     |  3 ++-
 hw/usb/redirect.c        |  3 ++-
 21 files changed, 72 insertions(+), 34 deletions(-)

diff --git a/hw/block/fdc.c b/hw/block/fdc.c
index 490d127..8add4a1 100644
--- a/hw/block/fdc.c
+++ b/hw/block/fdc.c
@@ -787,6 +787,9 @@ static void fdctrl_external_reset_isa(DeviceState *d)
     FDCtrl *s = &isa->state;
 
     fdctrl_reset(s, 0);
+
+    add_boot_device_path(isa->bootindexA, d, "/address@hidden");
+    add_boot_device_path(isa->bootindexB, d, "/address@hidden");
 }
 
 static void fdctrl_handle_tc(void *opaque, int irq, int level)
@@ -2142,9 +2145,6 @@ static void isabus_fdc_realize(DeviceState *dev, Error 
**errp)
         error_propagate(errp, err);
         return;
     }
-
-    add_boot_device_path(isa->bootindexA, dev, "/address@hidden");
-    add_boot_device_path(isa->bootindexB, dev, "/address@hidden");
 }
 
 static void sysbus_fdc_initfn(Object *obj)
diff --git a/hw/block/virtio-blk.c b/hw/block/virtio-blk.c
index a7f2827..e74a4c5 100644
--- a/hw/block/virtio-blk.c
+++ b/hw/block/virtio-blk.c
@@ -509,6 +509,8 @@ static void virtio_blk_reset(VirtIODevice *vdev)
      */
     bdrv_drain_all();
     bdrv_set_enable_write_cache(s->bs, s->original_wce);
+
+    add_boot_device_path(s->conf->bootindex, DEVICE(vdev), 
"/address@hidden,0");
 }
 
 /* coalesce internal state, copy to pci i/o region 0
@@ -777,8 +779,6 @@ static void virtio_blk_device_realize(DeviceState *dev, 
Error **errp)
     bdrv_set_guest_block_size(s->bs, s->conf->logical_block_size);
 
     bdrv_iostatus_enable(s->bs);
-
-    add_boot_device_path(s->conf->bootindex, dev, "/address@hidden,0");
 }
 
 static void virtio_blk_device_unrealize(DeviceState *dev, Error **errp)
diff --git a/hw/i386/kvm/pci-assign.c b/hw/i386/kvm/pci-assign.c
index 17c7d6dc..0e6aa8a 100644
--- a/hw/i386/kvm/pci-assign.c
+++ b/hw/i386/kvm/pci-assign.c
@@ -1740,6 +1740,8 @@ static void reset_assigned_device(DeviceState *dev)
      * disconnected from the PCI bus. This avoids further DMA transfers.
      */
     assigned_dev_pci_write_config(pci_dev, PCI_COMMAND, 0, 1);
+
+    add_boot_device_path(adev->bootindex, dev, NULL);
 }
 
 static int assigned_initfn(struct PCIDevice *pci_dev)
@@ -1825,8 +1827,6 @@ static int assigned_initfn(struct PCIDevice *pci_dev)
 
     assigned_dev_load_option_rom(dev);
 
-    add_boot_device_path(dev->bootindex, &pci_dev->qdev, NULL);
-
     return 0;
 
 assigned_out:
diff --git a/hw/ide/qdev.c b/hw/ide/qdev.c
index b4a4671..83bdb97 100644
--- a/hw/ide/qdev.c
+++ b/hw/ide/qdev.c
@@ -185,12 +185,17 @@ static int ide_dev_initfn(IDEDevice *dev, IDEDriveKind 
kind)
         dev->serial = g_strdup(s->drive_serial_str);
     }
 
-    add_boot_device_path(dev->conf.bootindex, &dev->qdev,
-                         dev->unit ? "/address@hidden" : "/address@hidden");
-
     return 0;
 }
 
+static void ide_dev_reset(DeviceState *dev)
+{
+    IDEDevice *d = DO_UPCAST(IDEDevice, qdev, dev);
+
+    add_boot_device_path(d->conf.bootindex, dev,
+                         d->unit ? "/address@hidden" : "/address@hidden");
+}
+
 static int ide_hd_initfn(IDEDevice *dev)
 {
     return ide_dev_initfn(dev, IDE_HD);
@@ -231,6 +236,7 @@ static void ide_hd_class_init(ObjectClass *klass, void 
*data)
     dc->fw_name = "drive";
     dc->desc = "virtual IDE disk";
     dc->props = ide_hd_properties;
+    dc->reset = ide_dev_reset;
 }
 
 static const TypeInfo ide_hd_info = {
@@ -253,6 +259,7 @@ static void ide_cd_class_init(ObjectClass *klass, void 
*data)
     dc->fw_name = "drive";
     dc->desc = "virtual IDE CD-ROM";
     dc->props = ide_cd_properties;
+    dc->reset = ide_dev_reset;
 }
 
 static const TypeInfo ide_cd_info = {
@@ -275,6 +282,7 @@ static void ide_drive_class_init(ObjectClass *klass, void 
*data)
     dc->fw_name = "drive";
     dc->desc = "virtual IDE disk or CD-ROM (legacy)";
     dc->props = ide_drive_properties;
+    dc->reset = ide_dev_reset;
 }
 
 static const TypeInfo ide_drive_info = {
diff --git a/hw/misc/vfio.c b/hw/misc/vfio.c
index 40dcaa6..625598a 100644
--- a/hw/misc/vfio.c
+++ b/hw/misc/vfio.c
@@ -4296,7 +4296,6 @@ static int vfio_initfn(PCIDevice *pdev)
         }
     }
 
-    add_boot_device_path(vdev->bootindex, &pdev->qdev, NULL);
     vfio_register_err_notifier(vdev);
 
     return 0;
@@ -4341,6 +4340,8 @@ static void vfio_pci_reset(DeviceState *dev)
 
     vfio_pci_pre_reset(vdev);
 
+    add_boot_device_path(vdev->bootindex, dev, NULL);
+
     if (vdev->reset_works && (vdev->has_flr || !vdev->has_pm_reset) &&
         !ioctl(vdev->fd, VFIO_DEVICE_RESET)) {
         DPRINTF("%04x:%02x:%02x.%x FLR/VFIO_DEVICE_RESET\n", vdev->host.domain,
diff --git a/hw/net/e1000.c b/hw/net/e1000.c
index 272df00..afdfaa3 100644
--- a/hw/net/e1000.c
+++ b/hw/net/e1000.c
@@ -1569,8 +1569,6 @@ static int pci_e1000_init(PCIDevice *pci_dev)
 
     qemu_format_nic_info_str(qemu_get_queue(d->nic), macaddr);
 
-    add_boot_device_path(d->conf.bootindex, dev, "/address@hidden");
-
     d->autoneg_timer = timer_new_ms(QEMU_CLOCK_VIRTUAL, e1000_autoneg_timer, 
d);
     d->mit_timer = timer_new_ns(QEMU_CLOCK_VIRTUAL, e1000_mit_timer, d);
 
@@ -1581,6 +1579,8 @@ static void qdev_e1000_reset(DeviceState *dev)
 {
     E1000State *d = E1000(dev);
     e1000_reset(d);
+
+    add_boot_device_path(d->conf.bootindex, dev, "/address@hidden");
 }
 
 static Property e1000_properties[] = {
diff --git a/hw/net/eepro100.c b/hw/net/eepro100.c
index 3cd826a..dcfaa48 100644
--- a/hw/net/eepro100.c
+++ b/hw/net/eepro100.c
@@ -1901,11 +1901,16 @@ static int e100_nic_init(PCIDevice *pci_dev)
     s->vmstate->name = qemu_get_queue(s->nic)->model;
     vmstate_register(&pci_dev->qdev, -1, s->vmstate, s);
 
-    add_boot_device_path(s->conf.bootindex, &pci_dev->qdev, "/address@hidden");
-
     return 0;
 }
 
+static void eepro100_reset(DeviceState *dev)
+{
+    EEPRO100State *s = DO_UPCAST(EEPRO100State, dev, PCI_DEVICE(dev));
+
+    add_boot_device_path(s->conf.bootindex, dev, "/address@hidden");
+}
+
 static E100PCIDeviceInfo e100_devices[] = {
     {
         .name = "i82550",
@@ -2082,6 +2087,7 @@ static void eepro100_class_init(ObjectClass *klass, void 
*data)
     set_bit(DEVICE_CATEGORY_NETWORK, dc->categories);
     dc->props = e100_properties;
     dc->desc = info->desc;
+    dc->reset = eepro100_reset;
     k->vendor_id = PCI_VENDOR_ID_INTEL;
     k->class_id = PCI_CLASS_NETWORK_ETHERNET;
     k->romfile = "pxe-eepro100.rom";
diff --git a/hw/net/lance.c b/hw/net/lance.c
index 7811a9e..3d921b0 100644
--- a/hw/net/lance.c
+++ b/hw/net/lance.c
@@ -141,6 +141,8 @@ static void lance_reset(DeviceState *dev)
     SysBusPCNetState *d = SYSBUS_PCNET(dev);
 
     pcnet_h_reset(&d->state);
+
+    pcnet_common_reset(dev, s);
 }
 
 static Property lance_properties[] = {
diff --git a/hw/net/ne2000.c b/hw/net/ne2000.c
index a62d12d..a6fc3c0 100644
--- a/hw/net/ne2000.c
+++ b/hw/net/ne2000.c
@@ -738,11 +738,17 @@ static int pci_ne2000_init(PCIDevice *pci_dev)
                           object_get_typename(OBJECT(pci_dev)), 
pci_dev->qdev.id, s);
     qemu_format_nic_info_str(qemu_get_queue(s->nic), s->c.macaddr.a);
 
-    add_boot_device_path(s->c.bootindex, &pci_dev->qdev, "/address@hidden");
-
     return 0;
 }
 
+static void pci_ne2000_reset(DeviceState *dev)
+{
+    PCINE2000State *d = DO_UPCAST(PCINE2000State, dev, PCI_DEVICE(dev));
+    NE2000State *s = &d->ne2000;
+
+    add_boot_device_path(s->c.bootindex, dev, "/address@hidden");
+}
+
 static void pci_ne2000_exit(PCIDevice *pci_dev)
 {
     PCINE2000State *d = DO_UPCAST(PCINE2000State, dev, pci_dev);
@@ -770,6 +776,7 @@ static void ne2000_class_init(ObjectClass *klass, void 
*data)
     k->class_id = PCI_CLASS_NETWORK_ETHERNET;
     dc->vmsd = &vmstate_pci_ne2000;
     dc->props = ne2000_properties;
+    dc->reset = pci_ne2000_reset;
     set_bit(DEVICE_CATEGORY_NETWORK, dc->categories);
 }
 
diff --git a/hw/net/pcnet-pci.c b/hw/net/pcnet-pci.c
index 50ffe91..e90344e 100644
--- a/hw/net/pcnet-pci.c
+++ b/hw/net/pcnet-pci.c
@@ -340,8 +340,11 @@ static int pci_pcnet_init(PCIDevice *pci_dev)
 static void pci_reset(DeviceState *dev)
 {
     PCIPCNetState *d = PCI_PCNET(dev);
+    PCNetState *s = &d->state;
 
     pcnet_h_reset(&d->state);
+
+    pcnet_common_reset(dev, s);
 }
 
 static Property pcnet_properties[] = {
diff --git a/hw/net/pcnet.c b/hw/net/pcnet.c
index 5299d52..4fd2e52 100644
--- a/hw/net/pcnet.c
+++ b/hw/net/pcnet.c
@@ -1735,8 +1735,6 @@ int pcnet_common_init(DeviceState *dev, PCNetState *s, 
NetClientInfo *info)
     s->nic = qemu_new_nic(info, &s->conf, object_get_typename(OBJECT(dev)), 
dev->id, s);
     qemu_format_nic_info_str(qemu_get_queue(s->nic), s->conf.macaddr.a);
 
-    add_boot_device_path(s->conf.bootindex, dev, "/address@hidden");
-
     /* Initialize the PROM */
 
     /*
@@ -1768,3 +1766,8 @@ int pcnet_common_init(DeviceState *dev, PCNetState *s, 
NetClientInfo *info)
 
     return 0;
 }
+
+void pcnet_common_reset(DeviceState *dev, PCNetState *s)
+{
+    add_boot_device_path(s->conf.bootindex, dev, "/address@hidden");
+}
diff --git a/hw/net/pcnet.h b/hw/net/pcnet.h
index 9dee6f3..ce9b9cb 100644
--- a/hw/net/pcnet.h
+++ b/hw/net/pcnet.h
@@ -65,6 +65,7 @@ ssize_t pcnet_receive(NetClientState *nc, const uint8_t *buf, 
size_t size_);
 void pcnet_set_link_status(NetClientState *nc);
 void pcnet_common_cleanup(PCNetState *d);
 int pcnet_common_init(DeviceState *dev, PCNetState *s, NetClientInfo *info);
+void pcnet_common_reset(DeviceState *dev, PCNetState *s);
 extern const VMStateDescription vmstate_pcnet;
 
 #endif
diff --git a/hw/net/rtl8139.c b/hw/net/rtl8139.c
index 6e59f38..b6d3930 100644
--- a/hw/net/rtl8139.c
+++ b/hw/net/rtl8139.c
@@ -1285,6 +1285,8 @@ static void rtl8139_reset(DeviceState *d)
 
     /* reset tally counters */
     RTL8139TallyCounters_clear(&s->tally_counters);
+
+    add_boot_device_path(s->conf.bootindex, d, "/address@hidden");
 }
 
 static void RTL8139TallyCounters_clear(RTL8139TallyCounters* counters)
@@ -3538,8 +3540,6 @@ static int pci_rtl8139_init(PCIDevice *dev)
     s->timer = timer_new_ns(QEMU_CLOCK_VIRTUAL, rtl8139_timer, s);
     rtl8139_set_next_tctr_time(s, qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL));
 
-    add_boot_device_path(s->conf.bootindex, d, "/address@hidden");
-
     return 0;
 }
 
diff --git a/hw/net/spapr_llan.c b/hw/net/spapr_llan.c
index 2d47df6..62c0249 100644
--- a/hw/net/spapr_llan.c
+++ b/hw/net/spapr_llan.c
@@ -202,6 +202,8 @@ static void spapr_vlan_reset(VIOsPAPRDevice *sdev)
     dev->buf_list = 0;
     dev->rx_bufs = 0;
     dev->isopen = 0;
+
+    add_boot_device_path(dev->nicconf.bootindex, DEVICE(dev), "");
 }
 
 static int spapr_vlan_init(VIOsPAPRDevice *sdev)
@@ -214,8 +216,6 @@ static int spapr_vlan_init(VIOsPAPRDevice *sdev)
                             object_get_typename(OBJECT(sdev)), sdev->qdev.id, 
dev);
     qemu_format_nic_info_str(qemu_get_queue(dev->nic), dev->nicconf.macaddr.a);
 
-    add_boot_device_path(dev->nicconf.bootindex, DEVICE(dev), "");
-
     return 0;
 }
 
diff --git a/hw/net/virtio-net.c b/hw/net/virtio-net.c
index 268eff9..09ecb24 100644
--- a/hw/net/virtio-net.c
+++ b/hw/net/virtio-net.c
@@ -332,6 +332,9 @@ static void virtio_net_reset(VirtIODevice *vdev)
     memcpy(&n->mac[0], &n->nic->conf->macaddr, sizeof(n->mac));
     qemu_format_nic_info_str(qemu_get_queue(n->nic), n->mac);
     memset(n->vlans, 0, MAX_VLAN >> 3);
+
+    add_boot_device_path(n->nic_conf.bootindex, DEVICE(vdev),
+                         "/address@hidden");
 }
 
 static void peer_test_vnet_hdr(VirtIONet *n)
@@ -1640,8 +1643,6 @@ static void virtio_net_device_realize(DeviceState *dev, 
Error **errp)
     n->qdev = dev;
     register_savevm(dev, "virtio-net", -1, VIRTIO_NET_VM_VERSION,
                     virtio_net_save, virtio_net_load, n);
-
-    add_boot_device_path(n->nic_conf.bootindex, dev, "/address@hidden");
 }
 
 static void virtio_net_device_unrealize(DeviceState *dev, Error **errp)
diff --git a/hw/net/vmxnet3.c b/hw/net/vmxnet3.c
index f246fa1..e82ef94 100644
--- a/hw/net/vmxnet3.c
+++ b/hw/net/vmxnet3.c
@@ -2172,8 +2172,6 @@ static int vmxnet3_pci_init(PCIDevice *pci_dev)
     register_savevm(dev, "vmxnet3-msix", -1, 1,
                     vmxnet3_msix_save, vmxnet3_msix_load, s);
 
-    add_boot_device_path(s->conf.bootindex, dev, "/address@hidden");
-
     return 0;
 }
 
@@ -2201,6 +2199,8 @@ static void vmxnet3_qdev_reset(DeviceState *dev)
 
     VMW_CBPRN("Starting QDEV reset...");
     vmxnet3_reset(s);
+
+    add_boot_device_path(s->conf.bootindex, dev, "/address@hidden");
 }
 
 static bool vmxnet3_mc_list_needed(void *opaque)
diff --git a/hw/scsi/scsi-disk.c b/hw/scsi/scsi-disk.c
index e34a544..03d1384 100644
--- a/hw/scsi/scsi-disk.c
+++ b/hw/scsi/scsi-disk.c
@@ -2149,6 +2149,8 @@ static void scsi_disk_reset(DeviceState *dev)
     /* reset tray statuses */
     s->tray_locked = 0;
     s->tray_open = 0;
+
+    add_boot_device_path(s->qdev.conf.bootindex, dev, NULL);
 }
 
 static void scsi_unrealize(SCSIDevice *dev, Error **errp)
@@ -2285,7 +2287,6 @@ static void scsi_realize(SCSIDevice *dev, Error **errp)
     bdrv_set_guest_block_size(s->qdev.conf.bs, s->qdev.blocksize);
 
     bdrv_iostatus_enable(s->qdev.conf.bs);
-    add_boot_device_path(s->qdev.conf.bootindex, &dev->qdev, NULL);
 }
 
 static void scsi_hd_realize(SCSIDevice *dev, Error **errp)
diff --git a/hw/scsi/scsi-generic.c b/hw/scsi/scsi-generic.c
index 20587b4..db6a80d 100644
--- a/hw/scsi/scsi-generic.c
+++ b/hw/scsi/scsi-generic.c
@@ -381,6 +381,10 @@ static void scsi_generic_reset(DeviceState *dev)
     SCSIDevice *s = SCSI_DEVICE(dev);
 
     scsi_device_purge_requests(s, SENSE_CODE(RESET));
+
+    if (s->type == TYPE_DISK || s->type == TYPE_ROM) {
+        add_boot_device_path(s->conf.bootindex, dev, NULL);
+    }
 }
 
 static void scsi_unrealize(SCSIDevice *s, Error **errp)
@@ -431,9 +435,6 @@ static void scsi_generic_realize(SCSIDevice *s, Error 
**errp)
     /* define device state */
     s->type = scsiid.scsi_type;
     DPRINTF("device type %d\n", s->type);
-    if (s->type == TYPE_DISK || s->type == TYPE_ROM) {
-        add_boot_device_path(s->conf.bootindex, &s->qdev, NULL);
-    }
 
     switch (s->type) {
     case TYPE_TAPE:
diff --git a/hw/usb/dev-network.c b/hw/usb/dev-network.c
index 518d536..ea038ab 100644
--- a/hw/usb/dev-network.c
+++ b/hw/usb/dev-network.c
@@ -1053,6 +1053,9 @@ static int rndis_parse(USBNetState *s, uint8_t *data, int 
length)
 
 static void usb_net_handle_reset(USBDevice *dev)
 {
+    USBNetState *s = DO_UPCAST(USBNetState, dev, dev);
+
+    add_boot_device_path(s->conf.bootindex, &dev->qdev, "/address@hidden");
 }
 
 static void usb_net_handle_control(USBDevice *dev, USBPacket *p,
@@ -1372,7 +1375,6 @@ static int usb_net_initfn(USBDevice *dev)
              s->conf.macaddr.a[5]);
     usb_desc_set_string(dev, STRING_ETHADDR, s->usbstring_mac);
 
-    add_boot_device_path(s->conf.bootindex, &dev->qdev, "/address@hidden");
     return 0;
 }
 
diff --git a/hw/usb/host-libusb.c b/hw/usb/host-libusb.c
index c189147..f37708d 100644
--- a/hw/usb/host-libusb.c
+++ b/hw/usb/host-libusb.c
@@ -975,7 +975,6 @@ static int usb_host_initfn(USBDevice *udev)
     qemu_add_exit_notifier(&s->exit);
 
     QTAILQ_INSERT_TAIL(&hostdevs, s, next);
-    add_boot_device_path(s->bootindex, &udev->qdev, NULL);
     usb_host_auto_check(NULL);
     return 0;
 }
@@ -1354,6 +1353,8 @@ static void usb_host_handle_reset(USBDevice *udev)
     if (rc != 0) {
         usb_host_nodev(s);
     }
+
+    add_boot_device_path(s->bootindex, &udev->qdev, NULL);
 }
 
 static int usb_host_alloc_streams(USBDevice *udev, USBEndpoint **eps,
diff --git a/hw/usb/redirect.c b/hw/usb/redirect.c
index 44522d9..92dd353 100644
--- a/hw/usb/redirect.c
+++ b/hw/usb/redirect.c
@@ -505,6 +505,8 @@ static void usbredir_handle_reset(USBDevice *udev)
     DPRINTF("reset device\n");
     usbredirparser_send_reset(dev->parser);
     usbredirparser_do_write(dev->parser);
+
+    add_boot_device_path(dev->bootindex, &udev->qdev, NULL);
 }
 
 static void usbredir_handle_iso_data(USBRedirDevice *dev, USBPacket *p,
@@ -1397,7 +1399,6 @@ static int usbredir_initfn(USBDevice *udev)
                           usbredir_chardev_read, usbredir_chardev_event, dev);
 
     qemu_add_vm_change_state_handler(usbredir_vm_state_change, dev);
-    add_boot_device_path(dev->bootindex, &udev->qdev, NULL);
     return 0;
 }
 
-- 
1.7.12.4





reply via email to

[Prev in Thread] Current Thread [Next in Thread]