diff options
-rw-r--r-- | hw/ide/piix.c | 27 |
1 files changed, 13 insertions, 14 deletions
diff --git a/hw/ide/piix.c b/hw/ide/piix.c index b402a93..b9860e3 100644 --- a/hw/ide/piix.c +++ b/hw/ide/piix.c @@ -164,30 +164,29 @@ static void pci_piix_ide_realize(PCIDevice *dev, Error **errp) int pci_piix3_xen_ide_unplug(DeviceState *dev, bool aux) { PCIIDEState *pci_ide; - DriveInfo *di; int i; IDEDevice *idedev; + IDEBus *idebus; + BlockBackend *blk; pci_ide = PCI_IDE(dev); for (i = aux ? 1 : 0; i < 4; i++) { - di = drive_get_by_index(IF_IDE, i); - if (di != NULL && !di->media_cd) { - BlockBackend *blk = blk_by_legacy_dinfo(di); - DeviceState *ds = blk_get_attached_dev(blk); + idebus = &pci_ide->bus[i / 2]; + blk = idebus->ifs[i % 2].blk; - blk_drain(blk); - blk_flush(blk); - - if (ds) { - blk_detach_dev(blk, ds); - } - pci_ide->bus[di->bus].ifs[di->unit].blk = NULL; + if (blk && idebus->ifs[i % 2].drive_kind != IDE_CD) { if (!(i % 2)) { - idedev = pci_ide->bus[di->bus].master; + idedev = idebus->master; } else { - idedev = pci_ide->bus[di->bus].slave; + idedev = idebus->slave; } + + blk_drain(blk); + blk_flush(blk); + + blk_detach_dev(blk, DEVICE(idedev)); + idebus->ifs[i % 2].blk = NULL; idedev->conf.blk = NULL; monitor_remove_blk(blk); blk_unref(blk); |