Skip to contentSkip to conversation

Clean up IDE after completion of qdevification

PATCH In review Markus Armbruster 3 participants 18 messages Jan 30, 2014 – Feb 12, 2014

lore
Share & tools
lore
#3 lore raw

PATCH v3 3/9 ide: Don't block-align IDEState member smart_selftest_data

In reply to Markus Armbruster

All uses are simple array subscripts.

---
 hw/ide/core.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)
hw/ide/core.c +1 -2
index dcfd92d..6aaf6fa 100644
@@ -2164,8 +2164,7 @@ static void ide_init1(IDEBus *bus, int unit)
     s->io_buffer = qemu_memalign(2048, s->io_buffer_total_len);
     memset(s->io_buffer, 0, s->io_buffer_total_len);
 
-    s->smart_selftest_data = qemu_blockalign(s->bs, 512);
-    memset(s->smart_selftest_data, 0, 512);
+    s->smart_selftest_data = g_malloc0(512);
 
     s->sector_write_timer = timer_new_ns(QEMU_CLOCK_VIRTUAL,
                                            ide_sector_write_timer_cb, s);
Signature · 1 line
1.8.1.4
#4 lore raw

PATCH v3 4/9 ide: Drop redundant IDEState member bs

In reply to Markus Armbruster

It's a copy of dev->conf.bs. The copy was needed for non-qdevified controllers, which lacked dev.

Note how pci_piix3_xen_ide_unplug() cleared the copy. We'll get back to that in the next few commits.

---
 hw/ide/ahci.c     | 11 +++++-----
 hw/ide/atapi.c    | 37 ++++++++++++++++++---------------
 hw/ide/core.c     | 62 ++++++++++++++++++++++++++++++-------------------------
 hw/ide/internal.h |  3 +--
 hw/ide/macio.c    | 26 ++++++++++++-----------
 hw/ide/piix.c     |  4 ----
 hw/ide/qdev.c     |  2 +-
 7 files changed, 76 insertions(+), 69 deletions(-)
hw/ide/ahci.c +6 -5
index eb6a6fe..1afc37e 100644
@@ -735,7 +735,7 @@ static void ncq_cb(void *opaque, int ret)
     DPRINTF(ncq_tfs->drive->port_no, "NCQ transfer tag %d finished\n",
             ncq_tfs->tag);
 
-    bdrv_acct_done(ncq_tfs->drive->port.ifs[0].bs, &ncq_tfs->acct);
+    bdrv_acct_done(ncq_tfs->drive->port.ifs[0].dev->conf.bs, &ncq_tfs->acct);
     qemu_sglist_destroy(&ncq_tfs->sglist);
     ncq_tfs->used = 0;
 }
@@ -746,6 +746,7 @@ static void process_ncq_command(AHCIState *s, int port, uint8_t *cmd_fis,
     NCQFrame *ncq_fis = (NCQFrame*)cmd_fis;
     uint8_t tag = ncq_fis->tag >> 3;
     NCQTransferState *ncq_tfs = &s->dev[port].ncq_tfs[tag];
+    BlockDriverState *bs = ncq_tfs->drive->port.ifs[0].dev->conf.bs;
 
     if (ncq_tfs->used) {
         /* error - already in use */
@@ -785,9 +786,9 @@ static void process_ncq_command(AHCIState *s, int port, uint8_t *cmd_fis,
             DPRINTF(port, "tag %d aio read %"PRId64"\n",
                     ncq_tfs->tag, ncq_tfs->lba);
 
-            dma_acct_start(ncq_tfs->drive->port.ifs[0].bs, &ncq_tfs->acct,
+            dma_acct_start(bs, &ncq_tfs->acct,
                            &ncq_tfs->sglist, BDRV_ACCT_READ);
-            ncq_tfs->aiocb = dma_bdrv_read(ncq_tfs->drive->port.ifs[0].bs,
+            ncq_tfs->aiocb = dma_bdrv_read(bs,
                                            &ncq_tfs->sglist, ncq_tfs->lba,
                                            ncq_cb, ncq_tfs);
             break;
@@ -798,9 +799,9 @@ static void process_ncq_command(AHCIState *s, int port, uint8_t *cmd_fis,
             DPRINTF(port, "tag %d aio write %"PRId64"\n",
                     ncq_tfs->tag, ncq_tfs->lba);
 
-            dma_acct_start(ncq_tfs->drive->port.ifs[0].bs, &ncq_tfs->acct,
+            dma_acct_start(bs, &ncq_tfs->acct,
                            &ncq_tfs->sglist, BDRV_ACCT_WRITE);
-            ncq_tfs->aiocb = dma_bdrv_write(ncq_tfs->drive->port.ifs[0].bs,
+            ncq_tfs->aiocb = dma_bdrv_write(bs,
                                             &ncq_tfs->sglist, ncq_tfs->lba,
                                             ncq_cb, ncq_tfs);
             break;
hw/ide/atapi.c +20 -17
index f7d2009..3dc2de0 100644
@@ -106,18 +106,19 @@ static void cd_data_to_raw(uint8_t *buf, int lba)
 
 static int cd_read_sector(IDEState *s, int lba, uint8_t *buf, int sector_size)
 {
+    BlockDriverState *bs = s->dev->conf.bs;
     int ret;
 
     switch(sector_size) {
     case 2048:
-        bdrv_acct_start(s->bs, &s->acct, 4 * BDRV_SECTOR_SIZE, BDRV_ACCT_READ);
-        ret = bdrv_read(s->bs, (int64_t)lba << 2, buf, 4);
-        bdrv_acct_done(s->bs, &s->acct);
+        bdrv_acct_start(bs, &s->acct, 4 * BDRV_SECTOR_SIZE, BDRV_ACCT_READ);
+        ret = bdrv_read(bs, (int64_t)lba << 2, buf, 4);
+        bdrv_acct_done(bs, &s->acct);
         break;
     case 2352:
-        bdrv_acct_start(s->bs, &s->acct, 4 * BDRV_SECTOR_SIZE, BDRV_ACCT_READ);
-        ret = bdrv_read(s->bs, (int64_t)lba << 2, buf + 16, 4);
-        bdrv_acct_done(s->bs, &s->acct);
+        bdrv_acct_start(bs, &s->acct, 4 * BDRV_SECTOR_SIZE, BDRV_ACCT_READ);
+        ret = bdrv_read(bs, (int64_t)lba << 2, buf + 16, 4);
+        bdrv_acct_done(bs, &s->acct);
         if (ret < 0)
             return ret;
         cd_data_to_raw(buf, lba);
@@ -253,7 +254,7 @@ static void ide_atapi_cmd_reply(IDEState *s, int size, int max_size)
     s->io_buffer_index = 0;
 
     if (s->atapi_dma) {
-        bdrv_acct_start(s->bs, &s->acct, size, BDRV_ACCT_READ);
+        bdrv_acct_start(s->dev->conf.bs, &s->acct, size, BDRV_ACCT_READ);
         s->status = READY_STAT | SEEK_STAT | DRQ_STAT;
         s->bus->dma->ops->start_dma(s->bus->dma, s,
                                    ide_atapi_cmd_read_dma_cb);
@@ -349,13 +350,13 @@ static void ide_atapi_cmd_read_dma_cb(void *opaque, int ret)
     s->bus->dma->iov.iov_len = n * 4 * 512;
     qemu_iovec_init_external(&s->bus->dma->qiov, &s->bus->dma->iov, 1);
 
-    s->bus->dma->aiocb = bdrv_aio_readv(s->bs, (int64_t)s->lba << 2,
+    s->bus->dma->aiocb = bdrv_aio_readv(s->dev->conf.bs, (int64_t)s->lba << 2,
                                        &s->bus->dma->qiov, n * 4,
                                        ide_atapi_cmd_read_dma_cb, s);
     return;
 
 eot:
-    bdrv_acct_done(s->bs, &s->acct);
+    bdrv_acct_done(s->dev->conf.bs, &s->acct);
     s->bus->dma->ops->add_status(s->bus->dma, BM_STATUS_INT);
     ide_set_inactive(s);
 }
@@ -371,7 +372,8 @@ static void ide_atapi_cmd_read_dma(IDEState *s, int lba, int nb_sectors,
     s->io_buffer_size = 0;
     s->cd_sector_size = sector_size;
 
-    bdrv_acct_start(s->bs, &s->acct, s->packet_transfer_size, BDRV_ACCT_READ);
+    bdrv_acct_start(s->dev->conf.bs, &s->acct, s->packet_transfer_size,
+                    BDRV_ACCT_READ);
 
     /* XXX: check if BUSY_STAT should be set */
     s->status = READY_STAT | SEEK_STAT | DRQ_STAT | BUSY_STAT;
@@ -504,7 +506,7 @@ static unsigned int event_status_media(IDEState *s,
     media_status = 0;
     if (s->tray_open) {
         media_status = MS_TRAY_OPEN;
-    } else if (bdrv_is_inserted(s->bs)) {
+    } else if (bdrv_is_inserted(s->dev->conf.bs)) {
         media_status = MS_MEDIA_PRESENT;
     }
 
@@ -800,7 +802,7 @@ static void cmd_test_unit_ready(IDEState *s, uint8_t *buf)
 static void cmd_prevent_allow_medium_removal(IDEState *s, uint8_t* buf)
 {
     s->tray_locked = buf[4] & 1;
-    bdrv_lock_medium(s->bs, buf[4] & 1);
+    bdrv_lock_medium(s->dev->conf.bs, buf[4] & 1);
     ide_atapi_cmd_ok(s);
 }
 
@@ -884,14 +886,14 @@ static void cmd_start_stop_unit(IDEState *s, uint8_t* buf)
 
     if (loej) {
         if (!start && !s->tray_open && s->tray_locked) {
-            sense = bdrv_is_inserted(s->bs)
+            sense = bdrv_is_inserted(s->dev->conf.bs)
                 ? NOT_READY : ILLEGAL_REQUEST;
             ide_atapi_cmd_error(s, sense, ASC_MEDIA_REMOVAL_PREVENTED);
             return;
         }
 
         if (s->tray_open != !start) {
-            bdrv_eject(s->bs, !start);
+            bdrv_eject(s->dev->conf.bs, !start);
             s->tray_open = !start;
         }
     }
@@ -1094,6 +1096,7 @@ static const struct {
 void ide_atapi_cmd(IDEState *s)
 {
     uint8_t *buf;
+    bool is_inserted;
 
     buf = s->io_buffer;
 #ifdef DEBUG_IDE_ATAPI
@@ -1124,8 +1127,9 @@ void ide_atapi_cmd(IDEState *s)
      * GET_EVENT_STATUS_NOTIFICATION to detect such tray open/close
      * states rely on this behavior.
      */
+    is_inserted = bdrv_is_inserted(s->dev->conf.bs);
     if (!(atapi_cmd_table[s->io_buffer[0]].flags & ALLOW_UA) &&
-        !s->tray_open && bdrv_is_inserted(s->bs) && s->cdrom_changed) {
+        !s->tray_open && is_inserted && s->cdrom_changed) {
 
         if (s->cdrom_changed == 1) {
             ide_atapi_cmd_error(s, NOT_READY, ASC_MEDIUM_NOT_PRESENT);
@@ -1134,13 +1138,12 @@ void ide_atapi_cmd(IDEState *s)
             ide_atapi_cmd_error(s, UNIT_ATTENTION, ASC_MEDIUM_MAY_HAVE_CHANGED);
             s->cdrom_changed = 0;
         }
-
         return;
     }
 
     /* Report a Not Ready condition if appropriate for the command */
     if ((atapi_cmd_table[s->io_buffer[0]].flags & CHECK_READY) &&
-        (!media_present(s) || !bdrv_is_inserted(s->bs)))
+        (!media_present(s) || !is_inserted))
     {
         ide_atapi_cmd_error(s, NOT_READY, ASC_MEDIUM_NOT_PRESENT);
         return;
hw/ide/core.c +34 -28

203 lines not on this page · raw message

hw/ide/internal.h +1 -2
index 908d91d..8f673f8 100644
@@ -373,7 +373,6 @@ struct IDEState {
 
     /* set for lba48 access */
     uint8_t lba48;
-    BlockDriverState *bs;
     char version[9];
     /* ATAPI specific */
     struct unreported_events events;
@@ -546,7 +545,7 @@ uint32_t ide_data_readw(void *opaque, uint32_t addr);
 void ide_data_writel(void *opaque, uint32_t addr, uint32_t val);
 uint32_t ide_data_readl(void *opaque, uint32_t addr);
 
-int ide_init_drive(IDEState *s, BlockDriverState *bs, IDEDriveKind kind,
+int ide_init_drive(IDEState *s, IDEDriveKind kind,
                    const char *version, const char *serial, const char *model,
                    uint64_t wwn,
                    uint32_t cylinders, uint32_t heads, uint32_t secs,
hw/ide/macio.c +14 -12
index da94580..dfba4a5 100644
@@ -134,7 +134,7 @@ static void pmac_ide_atapi_transfer_cb(void *opaque, int ret)
         MACIO_DPRINTF("precopying unaligned %d bytes to %#" HWADDR_PRIx "\n",
                       unaligned, io->addr + io->len - unaligned);
 
-        bdrv_read(s->bs, sector_num + nsector, io->remainder, 1);
+        bdrv_read(s->dev->conf.bs, sector_num + nsector, io->remainder, 1);
         cpu_physical_memory_write(io->addr + io->len - unaligned,
                                   io->remainder, unaligned);
 
@@ -164,14 +164,14 @@ static void pmac_ide_atapi_transfer_cb(void *opaque, int ret)
                   (s->lba << 2) + (s->io_buffer_index >> 9),
                   s->packet_transfer_size, s->dma_cmd);
 
-    m->aiocb = dma_bdrv_read(s->bs, &s->sg,
+    m->aiocb = dma_bdrv_read(s->dev->conf.bs, &s->sg,
                              (int64_t)(s->lba << 2) + (s->io_buffer_index >> 9),
                              pmac_ide_atapi_transfer_cb, io);
     return;
 
 done:
     MACIO_DPRINTF("done DMA\n");
-    bdrv_acct_done(s->bs, &s->acct);
+    bdrv_acct_done(s->dev->conf.bs, &s->acct);
     io->dma_end(opaque);
 }
 
@@ -180,6 +180,7 @@ static void pmac_ide_transfer_cb(void *opaque, int ret)
     DBDMA_io *io = opaque;
     MACIOIDEState *m = io->opaque;
     IDEState *s = idebus_active_if(&m->bus);
+    BlockDriverState *bs = s->dev->conf.bs;
     int n = 0;
     int64_t sector_num;
     int unaligned;
@@ -229,7 +230,7 @@ static void pmac_ide_transfer_cb(void *opaque, int ret)
             break;
         case IDE_DMA_WRITE:
             cpu_physical_memory_read(io->addr, p, remainder_len);
-            bdrv_write(s->bs, sector_num - 1, io->remainder, 1);
+            bdrv_write(bs, sector_num - 1, io->remainder, 1);
             break;
         case IDE_DMA_TRIM:
             break;
@@ -267,7 +268,7 @@ static void pmac_ide_transfer_cb(void *opaque, int ret)
 
         switch (s->dma_cmd) {
         case IDE_DMA_READ:
-            bdrv_read(s->bs, sector_num + nsector, io->remainder, 1);
+            bdrv_read(bs, sector_num + nsector, io->remainder, 1);
             cpu_physical_memory_write(io->addr + io->len - unaligned,
                                       io->remainder, unaligned);
             break;
@@ -306,15 +307,15 @@ static void pmac_ide_transfer_cb(void *opaque, int ret)
 
     switch (s->dma_cmd) {
     case IDE_DMA_READ:
-        m->aiocb = dma_bdrv_read(s->bs, &s->sg, sector_num,
+        m->aiocb = dma_bdrv_read(bs, &s->sg, sector_num,
                                  pmac_ide_transfer_cb, io);
         break;
     case IDE_DMA_WRITE:
-        m->aiocb = dma_bdrv_write(s->bs, &s->sg, sector_num,
+        m->aiocb = dma_bdrv_write(bs, &s->sg, sector_num,
                                   pmac_ide_transfer_cb, io);
         break;
     case IDE_DMA_TRIM:
-        m->aiocb = dma_bdrv_io(s->bs, &s->sg, sector_num,
+        m->aiocb = dma_bdrv_io(bs, &s->sg, sector_num,
                                ide_issue_trim, pmac_ide_transfer_cb, io,
                                DMA_DIRECTION_TO_DEVICE);
         break;
@@ -323,7 +324,7 @@ static void pmac_ide_transfer_cb(void *opaque, int ret)
 
 done:
     if (s->dma_cmd == IDE_DMA_READ || s->dma_cmd == IDE_DMA_WRITE) {
-        bdrv_acct_done(s->bs, &s->acct);
+        bdrv_acct_done(bs, &s->acct);
     }
     io->dma_end(io);
 }
@@ -332,22 +333,23 @@ static void pmac_ide_transfer(DBDMA_io *io)
 {
     MACIOIDEState *m = io->opaque;
     IDEState *s = idebus_active_if(&m->bus);
+    BlockDriverState *bs = s->dev->conf.bs;
 
     MACIO_DPRINTF("\n");
 
     s->io_buffer_size = 0;
     if (s->drive_kind == IDE_CD) {
-        bdrv_acct_start(s->bs, &s->acct, io->len, BDRV_ACCT_READ);
+        bdrv_acct_start(bs, &s->acct, io->len, BDRV_ACCT_READ);
         pmac_ide_atapi_transfer_cb(io, 0);
         return;
     }
 
     switch (s->dma_cmd) {
     case IDE_DMA_READ:
-        bdrv_acct_start(s->bs, &s->acct, io->len, BDRV_ACCT_READ);
+        bdrv_acct_start(bs, &s->acct, io->len, BDRV_ACCT_READ);
         break;
     case IDE_DMA_WRITE:
-        bdrv_acct_start(s->bs, &s->acct, io->len, BDRV_ACCT_WRITE);
+        bdrv_acct_start(bs, &s->acct, io->len, BDRV_ACCT_WRITE);
         break;
     default:
         break;
hw/ide/piix.c +0 -4
index 9b5960b..246e283 100644
@@ -169,12 +169,9 @@ static int pci_piix_ide_initfn(PCIDevice *dev)
 
 static int pci_piix3_xen_ide_unplug(DeviceState *dev)
 {
-    PCIIDEState *pci_ide;
     DriveInfo *di;
     int i = 0;
 
-    pci_ide = PCI_IDE(dev);
-
     for (; i < 3; i++) {
         di = drive_get_by_index(IF_IDE, i);
         if (di != NULL && !di->media_cd) {
@@ -183,7 +180,6 @@ static int pci_piix3_xen_ide_unplug(DeviceState *dev)
                 bdrv_detach_dev(di->bdrv, ds);
             }
             bdrv_close(di->bdrv);
-            pci_ide->bus[di->bus].ifs[di->unit].bs = NULL;
             drive_put_ref(di);
         }
     }
hw/ide/qdev.c +1 -1
index 7e8ddc2..f9a4d31 100644
@@ -160,7 +160,7 @@ static int ide_dev_initfn(IDEDevice *dev, IDEDriveKind kind)
         return -1;
     }
 
-    if (ide_init_drive(s, dev->conf.bs, kind,
+    if (ide_init_drive(s, kind,
                        dev->version, dev->serial, dev->model, dev->wwn,
                        dev->conf.cyls, dev->conf.heads, dev->conf.secs,
                        dev->chs_trans) < 0) {
Signature · 1 line
1.8.1.4
#0 lore raw

v3 cover Clean up IDE after completion of qdevification

Obvious cleanups possible since we no longer have the special case of a non-qdevified controller.

Andreas liked v2 well enough, but felt it's more like a block topic. Kevin, Stefan, would you be willing to take this series through the block tree?

v3:
* Trivially rebased.
v2:
* Dropped PATCH 1/10 ide: Break all non-qdevified controllers Andreas qdevified them since; thanks!
* Series renamed from "Drop code for non-qdevified IDE, and clean up"
* Trivially rebased

Markus Armbruster (9):
ide: Move IDEDevice pointer from IDEBus to IDEState
ide: Use IDEState member dev for "device connected" test
ide: Don't block-align IDEState member smart_selftest_data
ide: Drop redundant IDEState member bs
ide: Drop redundant IDEState geometry members
ide: Drop redundant IDEState member version
ide: Drop redundant IDEState member drive_serial_str
ide: Drop redundant IDEState member model
ide: Drop redundant IDEState member wwn

 hw/ide/ahci.c       |  19 +++--
 hw/ide/atapi.c      |  39 +++++----
 hw/ide/core.c       | 235 +++++++++++++++++++++++-----------------------------
 hw/ide/internal.h   |  15 +---
 hw/ide/macio.c      |  26 +++---
 hw/ide/microdrive.c |   2 +-
 hw/ide/piix.c       |   4 -
 hw/ide/qdev.c       |  50 ++++++-----
 8 files changed, 181 insertions(+), 209 deletions(-)
Signature · 1 line
1.8.1.4
#1 lore raw

PATCH v3 1/9 ide: Move IDEDevice pointer from IDEBus to IDEState

---
 hw/ide/core.c     |  2 +-
 hw/ide/internal.h |  3 +--
 hw/ide/qdev.c     | 12 +++---------
 3 files changed, 5 insertions(+), 12 deletions(-)
hw/ide/core.c +1 -1
index 036cd4a..9087025 100644
@@ -79,7 +79,7 @@ static void ide_identify(IDEState *s)
 {
     uint16_t *p;
     unsigned int oldsize;
-    IDEDevice *dev = s->unit ? s->bus->slave : s->bus->master;
+    IDEDevice *dev = s->dev;
 
     if (s->identify_set) {
 	memcpy(s->io_buffer, s->identify_data, sizeof(s->identify_data));
hw/ide/internal.h +1 -2
index 0567a52..908d91d 100644
@@ -341,6 +341,7 @@ enum ide_dma_cmd {
 /* NOTE: IDEState represents in fact one drive */
 struct IDEState {
     IDEBus *bus;
+    IDEDevice *dev;
     uint8_t unit;
     /* ide config */
     IDEDriveKind drive_kind;
@@ -447,8 +448,6 @@ struct IDEDMA {
 
 struct IDEBus {
     BusState qbus;
-    IDEDevice *master;
-    IDEDevice *slave;
     IDEState ifs[2];
     int bus_id;
     int max_units;
hw/ide/qdev.c +3 -9
index 18c4b7e..6ea1698 100644
@@ -76,7 +76,7 @@ static int ide_qdev_init(DeviceState *qdev)
         goto err;
     }
     if (dev->unit == -1) {
-        dev->unit = bus->master ? 1 : 0;
+        dev->unit = bus->ifs[0].dev ? 1 : 0;
     }
 
     if (dev->unit >= bus->max_units) {
@@ -87,18 +87,12 @@ static int ide_qdev_init(DeviceState *qdev)
 
     switch (dev->unit) {
     case 0:
-        if (bus->master) {
-            error_report("IDE unit %d is in use", dev->unit);
-            goto err;
-        }
-        bus->master = dev;
-        break;
     case 1:
-        if (bus->slave) {
+        if (bus->ifs[dev->unit].dev) {
             error_report("IDE unit %d is in use", dev->unit);
             goto err;
         }
-        bus->slave = dev;
+        bus->ifs[dev->unit].dev = dev;
         break;
     default:
         error_report("Invalid IDE unit %d", dev->unit);
Signature · 1 line
1.8.1.4
#2 lore raw

PATCH v3 2/9 ide: Use IDEState member dev for "device connected" test

In reply to Markus Armbruster

Testing dev is more obvious than testing bs, in my opinion.

---
 hw/ide/ahci.c       |  8 ++++----
 hw/ide/core.c       | 56 ++++++++++++++++++++++++++++-------------------------
 hw/ide/microdrive.c |  2 +-
 hw/ide/qdev.c       |  2 +-
 4 files changed, 36 insertions(+), 32 deletions(-)
hw/ide/ahci.c +4 -4
index fbea9e8..eb6a6fe 100644
@@ -85,7 +85,7 @@ static uint32_t  ahci_port_read(AHCIState *s, int port, int offset)
         val = pr->sig;
         break;
     case PORT_SCR_STAT:
-        if (s->dev[port].port.ifs[0].bs) {
+        if (s->dev[port].port.ifs[0].dev) {
             val = SATA_SCR_SSTATUS_DET_DEV_PRESENT_PHY_UP |
                   SATA_SCR_SSTATUS_SPD_GEN1 | SATA_SCR_SSTATUS_IPM_ACTIVE;
         } else {
@@ -497,7 +497,7 @@ static void ahci_reset_port(AHCIState *s, int port)
     d->init_d2h_sent = false;
 
     ide_state = &s->dev[port].port.ifs[0];
-    if (!ide_state->bs) {
+    if (!ide_state->dev) {
         return;
     }
 
@@ -523,7 +523,7 @@ static void ahci_reset_port(AHCIState *s, int port)
     }
 
     s->dev[port].port_state = STATE_RUN;
-    if (!ide_state->bs) {
+    if (!ide_state->dev) {
         s->dev[port].port_regs.sig = 0;
         ide_state->status = SEEK_STAT | WRERR_STAT;
     } else if (ide_state->drive_kind == IDE_CD) {
@@ -851,7 +851,7 @@ static int handle_cmd(AHCIState *s, int port, int slot)
     /* The device we are working for */
     ide_state = &s->dev[port].port.ifs[0];
 
-    if (!ide_state->bs) {
+    if (!ide_state->dev) {
         DPRINTF(port, "error: guest accessed unused port");
         goto out;
     }
hw/ide/core.c +30 -26

180 lines not on this page · raw message

hw/ide/microdrive.c +1 -1
index 21d6495..29f0d64 100644
@@ -247,7 +247,7 @@ static uint16_t md_common_read(PCMCIACardState *card, uint32_t at)
         return ide_ioport_read(&s->bus, 0x1);
     case 0xe:	/* Alternate Status */
         ifs = idebus_active_if(&s->bus);
-        if (ifs->bs) {
+        if (ifs->dev) {
             return ifs->status;
         } else {
             return 0;
hw/ide/qdev.c +1 -1
index 6ea1698..7e8ddc2 100644
@@ -120,7 +120,7 @@ int ide_get_geometry(BusState *bus, int unit,
 {
     IDEState *s = &DO_UPCAST(IDEBus, qbus, bus)->ifs[unit];
 
-    if (s->drive_kind != IDE_HD || !s->bs) {
+    if (s->drive_kind != IDE_HD || !s->dev) {
         return -1;
     }
 
Signature · 1 line
1.8.1.4
#13 lore raw

PATCH v3 5/9 ide: Drop redundant IDEState geometry members

In reply to Markus Armbruster

Members cylinders, heads, sectors, chs_trans are copies of dev->conf.cyls, dev->conf.heads, dev->conf.secs, dev->chs_trans. Copies were needed for non-qdevified controllers, which lacked dev.

Note that pci_piix3_xen_ide_unplug() did not clear the copies (it only cleared the copy of bs). Begs the question whether stale data could have been used after unplug. As far as I can tell, the copies were used only when the copy of bs was non-null, thus no bug there.

---
 hw/ide/core.c     | 52 ++++++++++++++++++++++++----------------------------
 hw/ide/internal.h |  5 +----
 hw/ide/qdev.c     | 12 +++++-------
 3 files changed, 30 insertions(+), 39 deletions(-)
hw/ide/core.c +24 -28
index d220983..93ccb6e 100644
@@ -89,11 +89,11 @@ static void ide_identify(IDEState *s)
     memset(s->io_buffer, 0, 512);
     p = (uint16_t *)s->io_buffer;
     put_le16(p + 0, 0x0040);
-    put_le16(p + 1, s->cylinders);
-    put_le16(p + 3, s->heads);
-    put_le16(p + 4, 512 * s->sectors); /* XXX: retired, remove ? */
+    put_le16(p + 1, s->dev->conf.cyls);
+    put_le16(p + 3, s->dev->conf.heads);
+    put_le16(p + 4, 512 * s->dev->conf.secs); /* XXX: retired, remove ? */
     put_le16(p + 5, 512); /* XXX: retired, remove ? */
-    put_le16(p + 6, s->sectors);
+    put_le16(p + 6, s->dev->conf.secs);
     padstr((char *)(p + 10), s->drive_serial_str, 20); /* serial number */
     put_le16(p + 20, 3); /* XXX: retired, remove ? */
     put_le16(p + 21, 512); /* cache size in sectors */
@@ -108,10 +108,10 @@ static void ide_identify(IDEState *s)
     put_le16(p + 51, 0x200); /* PIO transfer cycle */
     put_le16(p + 52, 0x200); /* DMA transfer cycle */
     put_le16(p + 53, 1 | (1 << 1) | (1 << 2)); /* words 54-58,64-70,88 are valid */
-    put_le16(p + 54, s->cylinders);
-    put_le16(p + 55, s->heads);
-    put_le16(p + 56, s->sectors);
-    oldsize = s->cylinders * s->heads * s->sectors;
+    put_le16(p + 54, s->dev->conf.cyls);
+    put_le16(p + 55, s->dev->conf.heads);
+    put_le16(p + 56, s->dev->conf.secs);
+    oldsize = s->dev->conf.cyls * s->dev->conf.heads * s->dev->conf.secs;
     put_le16(p + 57, oldsize);
     put_le16(p + 58, oldsize >> 16);
     if (s->mult_sectors)
@@ -249,12 +249,12 @@ static void ide_cfata_identify(IDEState *s)
 
     memset(p, 0, sizeof(s->identify_data));
 
-    cur_sec = s->cylinders * s->heads * s->sectors;
+    cur_sec = s->dev->conf.cyls * s->dev->conf.heads * s->dev->conf.secs;
 
     put_le16(p + 0, 0x848a);			/* CF Storage Card signature */
-    put_le16(p + 1, s->cylinders);		/* Default cylinders */
-    put_le16(p + 3, s->heads);			/* Default heads */
-    put_le16(p + 6, s->sectors);		/* Default sectors per track */
+    put_le16(p + 1, s->dev->conf.cyls);         /* Default cylinders */
+    put_le16(p + 3, s->dev->conf.heads);        /* Default heads */
+    put_le16(p + 6, s->dev->conf.secs);         /* Default sectors per track */
     put_le16(p + 7, s->nb_sectors >> 16);	/* Sectors per card */
     put_le16(p + 8, s->nb_sectors);		/* Sectors per card */
     padstr((char *)(p + 10), s->drive_serial_str, 20); /* serial number */
@@ -270,9 +270,9 @@ static void ide_cfata_identify(IDEState *s)
     put_le16(p + 51, 0x0002);			/* PIO cycle timing mode */
     put_le16(p + 52, 0x0001);			/* DMA cycle timing mode */
     put_le16(p + 53, 0x0003);			/* Translation params valid */
-    put_le16(p + 54, s->cylinders);		/* Current cylinders */
-    put_le16(p + 55, s->heads);			/* Current heads */
-    put_le16(p + 56, s->sectors);		/* Current sectors */
+    put_le16(p + 54, s->dev->conf.cyls);        /* Current cylinders */
+    put_le16(p + 55, s->dev->conf.heads);       /* Current heads */
+    put_le16(p + 56, s->dev->conf.secs);        /* Current sectors */
     put_le16(p + 57, cur_sec);			/* Current capacity */
     put_le16(p + 58, cur_sec >> 16);		/* Current capacity */
     if (s->mult_sectors)			/* Multiple sector setting */
@@ -462,8 +462,10 @@ int64_t ide_get_sector(IDEState *s)
 		((int64_t) s->lcyl << 8) | s->sector;
 	}
     } else {
-        sector_num = ((s->hcyl << 8) | s->lcyl) * s->heads * s->sectors +
-            (s->select & 0x0f) * s->sectors + (s->sector - 1);
+        sector_num =
+            (((s->hcyl << 8) | s->lcyl) * s->dev->conf.heads
+             + (s->select & 0x0f)) * s->dev->conf.secs
+            + (s->sector - 1);
     }
     return sector_num;
 }
@@ -486,12 +488,12 @@ void ide_set_sector(IDEState *s, int64_t sector_num)
 	    s->hob_hcyl = sector_num >> 40;
 	}
     } else {
-        cyl = sector_num / (s->heads * s->sectors);
-        r = sector_num % (s->heads * s->sectors);
+        cyl = sector_num / (s->dev->conf.heads * s->dev->conf.secs);
+        r = sector_num % (s->dev->conf.heads * s->dev->conf.secs);
         s->hcyl = cyl >> 8;
         s->lcyl = cyl;
-        s->select = (s->select & 0xf0) | ((r / s->sectors) & 0x0f);
-        s->sector = (r % s->sectors) + 1;
+        s->select = (s->select & 0xf0) | ((r / s->dev->conf.secs) & 0x0f);
+        s->sector = (r % s->dev->conf.secs) + 1;
     }
 }
 
@@ -2088,9 +2090,7 @@ static const BlockDevOps ide_cd_block_ops = {
 
 int ide_init_drive(IDEState *s, IDEDriveKind kind,
                    const char *version, const char *serial, const char *model,
-                   uint64_t wwn,
-                   uint32_t cylinders, uint32_t heads, uint32_t secs,
-                   int chs_trans)
+                   uint64_t wwn)
 {
     BlockDriverState *bs = s->dev->conf.bs;
     uint64_t nb_sectors;
@@ -2098,10 +2098,6 @@ int ide_init_drive(IDEState *s, IDEDriveKind kind,
     s->drive_kind = kind;
 
     bdrv_get_geometry(bs, &nb_sectors);
-    s->cylinders = cylinders;
-    s->heads = heads;
-    s->sectors = secs;
-    s->chs_trans = chs_trans;
     s->nb_sectors = nb_sectors;
     s->wwn = wwn;
     /* The SMART values should be preserved across power cycles
hw/ide/internal.h +1 -4
index 8f673f8..7a39d44 100644
@@ -345,7 +345,6 @@ struct IDEState {
     uint8_t unit;
     /* ide config */
     IDEDriveKind drive_kind;
-    int cylinders, heads, sectors, chs_trans;
     int64_t nb_sectors;
     int mult_sectors;
     int identify_set;
@@ -547,9 +546,7 @@ uint32_t ide_data_readl(void *opaque, uint32_t addr);
 
 int ide_init_drive(IDEState *s, IDEDriveKind kind,
                    const char *version, const char *serial, const char *model,
-                   uint64_t wwn,
-                   uint32_t cylinders, uint32_t heads, uint32_t secs,
-                   int chs_trans);
+                   uint64_t wwn);
 void ide_init2(IDEBus *bus, qemu_irq irq);
 void ide_init_ioport(IDEBus *bus, ISADevice *isa, int iobase, int iobase2);
 
hw/ide/qdev.c +5 -7
index f9a4d31..c233d66 100644
@@ -124,15 +124,15 @@ int ide_get_geometry(BusState *bus, int unit,
         return -1;
     }
 
-    *cyls = s->cylinders;
-    *heads = s->heads;
-    *secs = s->sectors;
+    *cyls = s->dev->conf.cyls;
+    *heads = s->dev->conf.heads;
+    *secs = s->dev->conf.secs;
     return 0;
 }
 
 int ide_get_bios_chs_trans(BusState *bus, int unit)
 {
-    return DO_UPCAST(IDEBus, qbus, bus)->ifs[unit].chs_trans;
+    return DO_UPCAST(IDEBus, qbus, bus)->ifs[unit].dev->chs_trans;
 }
 
 /* --------------------------------- */
@@ -161,9 +161,7 @@ static int ide_dev_initfn(IDEDevice *dev, IDEDriveKind kind)
     }
 
     if (ide_init_drive(s, kind,
-                       dev->version, dev->serial, dev->model, dev->wwn,
-                       dev->conf.cyls, dev->conf.heads, dev->conf.secs,
-                       dev->chs_trans) < 0) {
+                       dev->version, dev->serial, dev->model, dev->wwn) < 0) {
         return -1;
     }
 
Signature · 1 line
1.8.1.4
#14 lore raw

PATCH v3 6/9 ide: Drop redundant IDEState member version

In reply to Markus Armbruster

It's a copy of dev->version. The copy was needed for non-qdevified controllers, which lacked dev.

Note that pci_piix3_xen_ide_unplug() did not clear the copy (it only cleared the copy of bs). Begs the question whether stale data could have been used after unplug. As far as I can tell, the copy was used only when the copy of bs was non-null, thus no bug there.

---
 hw/ide/atapi.c    |  2 +-
 hw/ide/core.c     | 14 ++++----------
 hw/ide/internal.h |  3 +--
 hw/ide/qdev.c     |  9 +++++----
 4 files changed, 11 insertions(+), 17 deletions(-)
hw/ide/atapi.c +1 -1
index 3dc2de0..f20b3a6 100644
@@ -634,7 +634,7 @@ static void cmd_inquiry(IDEState *s, uint8_t *buf)
     buf[7] = 0; /* reserved */
     padstr8(buf + 8, 8, "QEMU");
     padstr8(buf + 16, 16, "QEMU DVD-ROM");
-    padstr8(buf + 32, 4, s->version);
+    padstr8(buf + 32, 4, s->dev->version);
     ide_atapi_cmd_reply(s, 36, max_len);
 }
 
hw/ide/core.c +4 -10
index 93ccb6e..564ad71 100644
@@ -98,7 +98,7 @@ static void ide_identify(IDEState *s)
     put_le16(p + 20, 3); /* XXX: retired, remove ? */
     put_le16(p + 21, 512); /* cache size in sectors */
     put_le16(p + 22, 4); /* ecc bytes */
-    padstr((char *)(p + 23), s->version, 8); /* firmware version */
+    padstr((char *)(p + 23), s->dev->version, 8); /* firmware version */
     padstr((char *)(p + 27), s->drive_model_str, 40); /* model */
 #if MAX_MULT_SECTORS > 1
     put_le16(p + 47, 0x8000 | MAX_MULT_SECTORS);
@@ -202,7 +202,7 @@ static void ide_atapi_identify(IDEState *s)
     put_le16(p + 20, 3); /* buffer type */
     put_le16(p + 21, 512); /* cache size in sectors */
     put_le16(p + 22, 4); /* ecc bytes */
-    padstr((char *)(p + 23), s->version, 8); /* firmware version */
+    padstr((char *)(p + 23), s->dev->version, 8); /* firmware version */
     padstr((char *)(p + 27), s->drive_model_str, 40); /* model */
     put_le16(p + 48, 1); /* dword I/O (XXX: should not be set on CDROM) */
 #ifdef USE_DMA_CDROM
@@ -259,7 +259,7 @@ static void ide_cfata_identify(IDEState *s)
     put_le16(p + 8, s->nb_sectors);		/* Sectors per card */
     padstr((char *)(p + 10), s->drive_serial_str, 20); /* serial number */
     put_le16(p + 22, 0x0004);			/* ECC bytes */
-    padstr((char *) (p + 23), s->version, 8);	/* Firmware Revision */
+    padstr((char *) (p + 23), s->dev->version, 8); /* Firmware Revision */
     padstr((char *) (p + 27), s->drive_model_str, 40);/* Model number */
 #if MAX_MULT_SECTORS > 1
     put_le16(p + 47, 0x8000 | MAX_MULT_SECTORS);
@@ -2089,7 +2089,7 @@ static const BlockDevOps ide_cd_block_ops = {
 };
 
 int ide_init_drive(IDEState *s, IDEDriveKind kind,
-                   const char *version, const char *serial, const char *model,
+                   const char *serial, const char *model,
                    uint64_t wwn)
 {
     BlockDriverState *bs = s->dev->conf.bs;
@@ -2141,12 +2141,6 @@ int ide_init_drive(IDEState *s, IDEDriveKind kind,
         }
     }
 
-    if (version) {
-        pstrcpy(s->version, sizeof(s->version), version);
-    } else {
-        pstrcpy(s->version, sizeof(s->version), qemu_get_version());
-    }
-
     ide_reset(s);
     bdrv_iostatus_enable(bs);
     return 0;
hw/ide/internal.h +1 -2
index 7a39d44..4c0fb8e 100644
@@ -372,7 +372,6 @@ struct IDEState {
 
     /* set for lba48 access */
     uint8_t lba48;
-    char version[9];
     /* ATAPI specific */
     struct unreported_events events;
     uint8_t sense_key;
@@ -545,7 +544,7 @@ void ide_data_writel(void *opaque, uint32_t addr, uint32_t val);
 uint32_t ide_data_readl(void *opaque, uint32_t addr);
 
 int ide_init_drive(IDEState *s, IDEDriveKind kind,
-                   const char *version, const char *serial, const char *model,
+                   const char *serial, const char *model,
                    uint64_t wwn);
 void ide_init2(IDEBus *bus, qemu_irq irq);
 void ide_init_ioport(IDEBus *bus, ISADevice *isa, int iobase, int iobase2);
hw/ide/qdev.c +5 -4
index c233d66..0326360 100644
@@ -160,14 +160,15 @@ static int ide_dev_initfn(IDEDevice *dev, IDEDriveKind kind)
         return -1;
     }
 
+    if (!dev->version) {
+        dev->version = g_strdup(qemu_get_version());
+    }
+
     if (ide_init_drive(s, kind,
-                       dev->version, dev->serial, dev->model, dev->wwn) < 0) {
+                       dev->serial, dev->model, dev->wwn) < 0) {
         return -1;
     }
 
-    if (!dev->version) {
-        dev->version = g_strdup(s->version);
-    }
     if (!dev->serial) {
         dev->serial = g_strdup(s->drive_serial_str);
     }
Signature · 1 line
1.8.1.4
#15 lore raw

PATCH v3 7/9 ide: Drop redundant IDEState member drive_serial_str

In reply to Markus Armbruster

It's a copy of dev->serial. The copy was needed for non-qdevified controllers, which lacked dev.

Note that pci_piix3_xen_ide_unplug() did not clear the copy (it only cleared the copy of bs). Begs the question whether stale data could have been used after unplug. As far as I can tell, the copy was used only when the copy of bs was non-null, thus no bug there.

---
 hw/ide/core.c     | 14 ++++----------
 hw/ide/internal.h |  3 +--
 hw/ide/qdev.c     | 10 +++++-----
 3 files changed, 10 insertions(+), 17 deletions(-)
hw/ide/core.c +4 -10
index 564ad71..c123a14 100644
@@ -94,7 +94,7 @@ static void ide_identify(IDEState *s)
     put_le16(p + 4, 512 * s->dev->conf.secs); /* XXX: retired, remove ? */
     put_le16(p + 5, 512); /* XXX: retired, remove ? */
     put_le16(p + 6, s->dev->conf.secs);
-    padstr((char *)(p + 10), s->drive_serial_str, 20); /* serial number */
+    padstr((char *)(p + 10), s->dev->serial, 20); /* serial number */
     put_le16(p + 20, 3); /* XXX: retired, remove ? */
     put_le16(p + 21, 512); /* cache size in sectors */
     put_le16(p + 22, 4); /* ecc bytes */
@@ -198,7 +198,7 @@ static void ide_atapi_identify(IDEState *s)
     p = (uint16_t *)s->io_buffer;
     /* Removable CDROM, 50us response, 12 byte packets */
     put_le16(p + 0, (2 << 14) | (5 << 8) | (1 << 7) | (2 << 5) | (0 << 0));
-    padstr((char *)(p + 10), s->drive_serial_str, 20); /* serial number */
+    padstr((char *)(p + 10), s->dev->serial, 20); /* serial number */
     put_le16(p + 20, 3); /* buffer type */
     put_le16(p + 21, 512); /* cache size in sectors */
     put_le16(p + 22, 4); /* ecc bytes */
@@ -257,7 +257,7 @@ static void ide_cfata_identify(IDEState *s)
     put_le16(p + 6, s->dev->conf.secs);         /* Default sectors per track */
     put_le16(p + 7, s->nb_sectors >> 16);	/* Sectors per card */
     put_le16(p + 8, s->nb_sectors);		/* Sectors per card */
-    padstr((char *)(p + 10), s->drive_serial_str, 20); /* serial number */
+    padstr((char *)(p + 10), s->dev->serial, 20); /* serial number */
     put_le16(p + 22, 0x0004);			/* ECC bytes */
     padstr((char *) (p + 23), s->dev->version, 8); /* Firmware Revision */
     padstr((char *) (p + 27), s->drive_model_str, 40);/* Model number */
@@ -2089,7 +2089,7 @@ static const BlockDevOps ide_cd_block_ops = {
 };
 
 int ide_init_drive(IDEState *s, IDEDriveKind kind,
-                   const char *serial, const char *model,
+                   const char *model,
                    uint64_t wwn)
 {
     BlockDriverState *bs = s->dev->conf.bs;
@@ -2119,12 +2119,6 @@ int ide_init_drive(IDEState *s, IDEDriveKind kind,
             return -1;
         }
     }
-    if (serial) {
-        pstrcpy(s->drive_serial_str, sizeof(s->drive_serial_str), serial);
-    } else {
-        snprintf(s->drive_serial_str, sizeof(s->drive_serial_str),
-                 "QM%05d", s->drive_serial);
-    }
     if (model) {
         pstrcpy(s->drive_model_str, sizeof(s->drive_model_str), model);
     } else {
hw/ide/internal.h +1 -2
index 4c0fb8e..f6b5b7a 100644
@@ -350,7 +350,6 @@ struct IDEState {
     int identify_set;
     uint8_t identify_data[512];
     int drive_serial;
-    char drive_serial_str[21];
     char drive_model_str[41];
     uint64_t wwn;
     /* ide regs */
@@ -544,7 +543,7 @@ void ide_data_writel(void *opaque, uint32_t addr, uint32_t val);
 uint32_t ide_data_readl(void *opaque, uint32_t addr);
 
 int ide_init_drive(IDEState *s, IDEDriveKind kind,
-                   const char *serial, const char *model,
+                   const char *model,
                    uint64_t wwn);
 void ide_init2(IDEBus *bus, qemu_irq irq);
 void ide_init_ioport(IDEBus *bus, ISADevice *isa, int iobase, int iobase2);
hw/ide/qdev.c +5 -5
index 0326360..c1a4cb6 100644
@@ -160,19 +160,19 @@ static int ide_dev_initfn(IDEDevice *dev, IDEDriveKind kind)
         return -1;
     }
 
+    if (!dev->serial) {
+        dev->serial = g_strdup_printf("QM%05d", s->drive_serial);
+    }
+
     if (!dev->version) {
         dev->version = g_strdup(qemu_get_version());
     }
 
     if (ide_init_drive(s, kind,
-                       dev->serial, dev->model, dev->wwn) < 0) {
+                       dev->model, dev->wwn) < 0) {
         return -1;
     }
 
-    if (!dev->serial) {
-        dev->serial = g_strdup(s->drive_serial_str);
-    }
-
     add_boot_device_path(dev->conf.bootindex, &dev->qdev,
                          dev->unit ? "/disk@1" : "/disk@0");
 
Signature · 1 line
1.8.1.4
#16 lore raw

PATCH v3 8/9 ide: Drop redundant IDEState member model

In reply to Markus Armbruster

It's a copy of dev->serial. The copy was needed for non-qdevified controllers, which lacked dev.

Note that pci_piix3_xen_ide_unplug() did not clear the copy (it only cleared the copy of bs). Begs the question whether stale data could have been used after unplug. As far as I can tell, the copy was used only when the copy of bs was non-null, thus no bug there.

---
 hw/ide/core.c     | 22 +++-------------------
 hw/ide/internal.h |  2 --
 hw/ide/qdev.c     | 16 +++++++++++++++-
 3 files changed, 18 insertions(+), 22 deletions(-)
hw/ide/core.c +3 -19
index c123a14..1c4522a 100644
@@ -99,7 +99,7 @@ static void ide_identify(IDEState *s)
     put_le16(p + 21, 512); /* cache size in sectors */
     put_le16(p + 22, 4); /* ecc bytes */
     padstr((char *)(p + 23), s->dev->version, 8); /* firmware version */
-    padstr((char *)(p + 27), s->drive_model_str, 40); /* model */
+    padstr((char *)(p + 27), s->dev->model, 40);  /* model */
 #if MAX_MULT_SECTORS > 1
     put_le16(p + 47, 0x8000 | MAX_MULT_SECTORS);
 #endif
@@ -203,7 +203,7 @@ static void ide_atapi_identify(IDEState *s)
     put_le16(p + 21, 512); /* cache size in sectors */
     put_le16(p + 22, 4); /* ecc bytes */
     padstr((char *)(p + 23), s->dev->version, 8); /* firmware version */
-    padstr((char *)(p + 27), s->drive_model_str, 40); /* model */
+    padstr((char *)(p + 27), s->dev->model, 40);  /* model */
     put_le16(p + 48, 1); /* dword I/O (XXX: should not be set on CDROM) */
 #ifdef USE_DMA_CDROM
     put_le16(p + 49, 1 << 9 | 1 << 8); /* DMA and LBA supported */
@@ -260,7 +260,7 @@ static void ide_cfata_identify(IDEState *s)
     padstr((char *)(p + 10), s->dev->serial, 20); /* serial number */
     put_le16(p + 22, 0x0004);			/* ECC bytes */
     padstr((char *) (p + 23), s->dev->version, 8); /* Firmware Revision */
-    padstr((char *) (p + 27), s->drive_model_str, 40);/* Model number */
+    padstr((char *) (p + 27), s->dev->model, 40);  /* Model number */
 #if MAX_MULT_SECTORS > 1
     put_le16(p + 47, 0x8000 | MAX_MULT_SECTORS);
 #else
@@ -2089,7 +2089,6 @@ static const BlockDevOps ide_cd_block_ops = {
 };
 
 int ide_init_drive(IDEState *s, IDEDriveKind kind,
-                   const char *model,
                    uint64_t wwn)
 {
     BlockDriverState *bs = s->dev->conf.bs;
@@ -2119,21 +2118,6 @@ int ide_init_drive(IDEState *s, IDEDriveKind kind,
             return -1;
         }
     }
-    if (model) {
-        pstrcpy(s->drive_model_str, sizeof(s->drive_model_str), model);
-    } else {
-        switch (kind) {
-        case IDE_CD:
-            strcpy(s->drive_model_str, "QEMU DVD-ROM");
-            break;
-        case IDE_CFATA:
-            strcpy(s->drive_model_str, "QEMU MICRODRIVE");
-            break;
-        default:
-            strcpy(s->drive_model_str, "QEMU HARDDISK");
-            break;
-        }
-    }
 
     ide_reset(s);
     bdrv_iostatus_enable(bs);
hw/ide/internal.h +0 -2
index f6b5b7a..c4a5773 100644
@@ -350,7 +350,6 @@ struct IDEState {
     int identify_set;
     uint8_t identify_data[512];
     int drive_serial;
-    char drive_model_str[41];
     uint64_t wwn;
     /* ide regs */
     uint8_t feature;
@@ -543,7 +542,6 @@ void ide_data_writel(void *opaque, uint32_t addr, uint32_t val);
 uint32_t ide_data_readl(void *opaque, uint32_t addr);
 
 int ide_init_drive(IDEState *s, IDEDriveKind kind,
-                   const char *model,
                    uint64_t wwn);
 void ide_init2(IDEBus *bus, qemu_irq irq);
 void ide_init_ioport(IDEBus *bus, ISADevice *isa, int iobase, int iobase2);
hw/ide/qdev.c +15 -1
index c1a4cb6..915bc27 100644
@@ -168,8 +168,22 @@ static int ide_dev_initfn(IDEDevice *dev, IDEDriveKind kind)
         dev->version = g_strdup(qemu_get_version());
     }
 
+    if (!dev->model) {
+        switch (kind) {
+        case IDE_CD:
+            dev->model = g_strdup("QEMU DVD-ROM");
+            break;
+        case IDE_CFATA:
+            dev->model = g_strdup("QEMU MICRODRIVE");
+            break;
+        default:
+            dev->model = g_strdup("QEMU HARDDISK");
+            break;
+        }
+    }
+
     if (ide_init_drive(s, kind,
-                       dev->model, dev->wwn) < 0) {
+                       dev->wwn) < 0) {
         return -1;
     }
 
Signature · 1 line
1.8.1.4
#17 lore raw

PATCH v3 9/9 ide: Drop redundant IDEState member wwn

In reply to Markus Armbruster

It's a copy of dev->wwn. The copy was needed for non-qdevified controllers, which lacked dev.

Note that pci_piix3_xen_ide_unplug() did not clear the copy (it only cleared the copy of bs). Begs the question whether stale data could have been used after unplug. As far as I can tell, the copy was used only when the copy of bs was non-null, thus no bug there.

---
 hw/ide/core.c     | 18 ++++++++----------
 hw/ide/internal.h |  4 +---
 hw/ide/qdev.c     |  3 +--
 3 files changed, 10 insertions(+), 15 deletions(-)
hw/ide/core.c +8 -10
index 1c4522a..98b6611 100644
@@ -142,7 +142,7 @@ static void ide_identify(IDEState *s)
     /* 13=flush_cache_ext,12=flush_cache,10=lba48 */
     put_le16(p + 83, (1 << 14) | (1 << 13) | (1 <<12) | (1 << 10));
     /* 14=set to 1, 8=has WWN, 1=SMART self test, 0=SMART error logging */
-    if (s->wwn) {
+    if (s->dev->wwn) {
         put_le16(p + 84, (1 << 14) | (1 << 8) | 0);
     } else {
         put_le16(p + 84, (1 << 14) | 0);
@@ -156,7 +156,7 @@ static void ide_identify(IDEState *s)
     /* 13=flush_cache_ext,12=flush_cache,10=lba48 */
     put_le16(p + 86, (1 << 13) | (1 <<12) | (1 << 10));
     /* 14=set to 1, 8=has WWN, 1=SMART self test, 0=SMART error logging */
-    if (s->wwn) {
+    if (s->dev->wwn) {
         put_le16(p + 87, (1 << 14) | (1 << 8) | 0);
     } else {
         put_le16(p + 87, (1 << 14) | 0);
@@ -170,12 +170,12 @@ static void ide_identify(IDEState *s)
 
     if (dev && dev->conf.physical_block_size)
         put_le16(p + 106, 0x6000 | get_physical_block_exp(&dev->conf));
-    if (s->wwn) {
+    if (s->dev->wwn) {
         /* LE 16-bit words 111-108 contain 64-bit World Wide Name */
-        put_le16(p + 108, s->wwn >> 48);
-        put_le16(p + 109, s->wwn >> 32);
-        put_le16(p + 110, s->wwn >> 16);
-        put_le16(p + 111, s->wwn);
+        put_le16(p + 108, s->dev->wwn >> 48);
+        put_le16(p + 109, s->dev->wwn >> 32);
+        put_le16(p + 110, s->dev->wwn >> 16);
+        put_le16(p + 111, s->dev->wwn);
     }
     if (dev && dev->conf.discard_granularity) {
         put_le16(p + 169, 1); /* TRIM support */
@@ -2088,8 +2088,7 @@ static const BlockDevOps ide_cd_block_ops = {
     .is_medium_locked = ide_cd_is_medium_locked,
 };
 
-int ide_init_drive(IDEState *s, IDEDriveKind kind,
-                   uint64_t wwn)
+int ide_init_drive(IDEState *s, IDEDriveKind kind)
 {
     BlockDriverState *bs = s->dev->conf.bs;
     uint64_t nb_sectors;
@@ -2098,7 +2097,6 @@ int ide_init_drive(IDEState *s, IDEDriveKind kind,
 
     bdrv_get_geometry(bs, &nb_sectors);
     s->nb_sectors = nb_sectors;
-    s->wwn = wwn;
     /* The SMART values should be preserved across power cycles
        but they aren't.  */
     s->smart_enabled = 1;
hw/ide/internal.h +1 -3
index c4a5773..95ea75c 100644
@@ -350,7 +350,6 @@ struct IDEState {
     int identify_set;
     uint8_t identify_data[512];
     int drive_serial;
-    uint64_t wwn;
     /* ide regs */
     uint8_t feature;
     uint8_t error;
@@ -541,8 +540,7 @@ uint32_t ide_data_readw(void *opaque, uint32_t addr);
 void ide_data_writel(void *opaque, uint32_t addr, uint32_t val);
 uint32_t ide_data_readl(void *opaque, uint32_t addr);
 
-int ide_init_drive(IDEState *s, IDEDriveKind kind,
-                   uint64_t wwn);
+int ide_init_drive(IDEState *s, IDEDriveKind kind);
 void ide_init2(IDEBus *bus, qemu_irq irq);
 void ide_init_ioport(IDEBus *bus, ISADevice *isa, int iobase, int iobase2);
 
hw/ide/qdev.c +1 -2
index 915bc27..17404b8 100644
@@ -182,8 +182,7 @@ static int ide_dev_initfn(IDEDevice *dev, IDEDriveKind kind)
         }
     }
 
-    if (ide_init_drive(s, kind,
-                       dev->wwn) < 0) {
+    if (ide_init_drive(s, kind) < 0) {
         return -1;
     }
 
Signature · 1 line
1.8.1.4
#5 lore raw

Re: [Qemu-devel] [PATCH v3 4/9] ide: Drop redundant IDEState member bs

In reply to Markus Armbruster

Am 30.01.2014 um 13:16 hat Markus Armbruster geschrieben:

Quoted 7 lines

It's a copy of dev->conf.bs. The copy was needed for non-qdevified controllers, which lacked dev.

Note how pci_piix3_xen_ide_unplug() cleared the copy. We'll get back to that in the next few commits.

So this pci_piix3_xen_ide_unplug() is what happens here:

Quoted 16 lines
hw/ide/piix.c +0 -3
@@ -169,12 +169,9 @@ static int pci_piix_ide_initfn(PCIDevice *dev)
 
 static int pci_piix3_xen_ide_unplug(DeviceState *dev)
 {
-    PCIIDEState *pci_ide;
     DriveInfo *di;
     int i = 0;
 
-    pci_ide = PCI_IDE(dev);
-
     for (; i < 3; i++) {
         di = drive_get_by_index(IF_IDE, i);
         if (di != NULL && !di->media_cd) {

hw/ide/piix.c static int pci_piix3_xen_ide_unplug(DeviceState *dev) · line 185

Quoted 7 lines
hw/ide/piix.c +0 -1
@@ -183,7 +180,6 @@ static int pci_piix3_xen_ide_unplug(DeviceState *dev)
                 bdrv_detach_dev(di->bdrv, ds);
             }
             bdrv_close(di->bdrv);
-            pci_ide->bus[di->bus].ifs[di->unit].bs = NULL;
             drive_put_ref(di);
         }
     }

Probably I'm just missing the obvious, but it seems to me that the copy was cleared here, while the original was left around. This was no problem because the original was unused anyway after device initialisation.

Now that the copy doesn't exist any more, we can't clear it, obviously, but why don't we have to clear the original? Won't we still run the "device is attached" code branches even though the device is really unplugged?

Kevin

#6 lore raw

Re: [Qemu-devel] [PATCH v3 4/9] ide: Drop redundant IDEState member bs

[Note cc: Stefano]

Quoted 40 lines · Kevin Wolf

Am 30.01.2014 um 13:16 hat Markus Armbruster geschrieben:

Quoted 7 lines

It's a copy of dev->conf.bs. The copy was needed for non-qdevified controllers, which lacked dev.

Note how pci_piix3_xen_ide_unplug() cleared the copy. We'll get back to that in the next few commits.

So this pci_piix3_xen_ide_unplug() is what happens here:

Quoted 16 lines
hw/ide/piix.c +0 -3
@@ -169,12 +169,9 @@ static int pci_piix_ide_initfn(PCIDevice *dev)
 
 static int pci_piix3_xen_ide_unplug(DeviceState *dev)
 {
-    PCIIDEState *pci_ide;
     DriveInfo *di;
     int i = 0;
 
-    pci_ide = PCI_IDE(dev);
-
     for (; i < 3; i++) {
         di = drive_get_by_index(IF_IDE, i);
         if (di != NULL && !di->media_cd) {

hw/ide/piix.c static int pci_piix3_xen_ide_unplug(DeviceState *dev) · line 185

Quoted 7 lines
hw/ide/piix.c +0 -1
@@ -183,7 +180,6 @@ static int pci_piix3_xen_ide_unplug(DeviceState *dev)
                 bdrv_detach_dev(di->bdrv, ds);
             }
             bdrv_close(di->bdrv);
-            pci_ide->bus[di->bus].ifs[di->unit].bs = NULL;
             drive_put_ref(di);
         }
     }

Probably I'm just missing the obvious, but it seems to me that the copy was cleared here, while the original was left around. This was no problem because the original was unused anyway after device initialisation.

Quoted 4 lines

Now that the copy doesn't exist any more, we can't clear it, obviously, but why don't we have to clear the original? Won't we still run the "device is attached" code branches even though the device is really unplugged?

It's been a while since I wrote this. Almost 14 months, in fact.

No other IDE controller implements DeviceClass method unplug(). I can't remember why the normal code to detach the backend (release_drive()) doesn't do here. Stefano, can you help?

#7 lore raw

Re: [Qemu-devel] [PATCH v3 4/9] ide: Drop redundant IDEState member bs

Quoted 49 lines · Markus Armbruster

[Note cc: Stefano]

Quoted 40 lines · Kevin Wolf

Am 30.01.2014 um 13:16 hat Markus Armbruster geschrieben:

Quoted 7 lines

It's a copy of dev->conf.bs. The copy was needed for non-qdevified controllers, which lacked dev.

Note how pci_piix3_xen_ide_unplug() cleared the copy. We'll get back to that in the next few commits.

So this pci_piix3_xen_ide_unplug() is what happens here:

Quoted 16 lines
hw/ide/piix.c +0 -3
@@ -169,12 +169,9 @@ static int pci_piix_ide_initfn(PCIDevice *dev)
 
 static int pci_piix3_xen_ide_unplug(DeviceState *dev)
 {
-    PCIIDEState *pci_ide;
     DriveInfo *di;
     int i = 0;
 
-    pci_ide = PCI_IDE(dev);
-
     for (; i < 3; i++) {
         di = drive_get_by_index(IF_IDE, i);
         if (di != NULL && !di->media_cd) {

hw/ide/piix.c static int pci_piix3_xen_ide_unplug(DeviceState *dev) · line 185

Quoted 7 lines
hw/ide/piix.c +0 -1
@@ -183,7 +180,6 @@ static int pci_piix3_xen_ide_unplug(DeviceState *dev)
                 bdrv_detach_dev(di->bdrv, ds);
             }
             bdrv_close(di->bdrv);
-            pci_ide->bus[di->bus].ifs[di->unit].bs = NULL;
             drive_put_ref(di);
         }
     }

Probably I'm just missing the obvious, but it seems to me that the copy was cleared here, while the original was left around. This was no problem because the original was unused anyway after device initialisation.

Quoted 4 lines

Now that the copy doesn't exist any more, we can't clear it, obviously, but why don't we have to clear the original? Won't we still run the "device is attached" code branches even though the device is really unplugged?

Quoted 5 lines

It's been a while since I wrote this. Almost 14 months, in fact.

No other IDE controller implements DeviceClass method unplug(). I can't remember why the normal code to detach the backend (release_drive()) doesn't do here. Stefano, can you help?

Too long to be able to remember the exact details :-/ However if you point me to a branch I can give it a try and tell you if the unplug still works as it used to.

#8 lore raw

Re: [Qemu-devel] [PATCH v3 4/9] ide: Drop redundant IDEState member bs

Quoted 52 lines · Stefano Stabellini
Quoted 51 lines · Markus Armbruster

[Note cc: Stefano]

Quoted 40 lines · Kevin Wolf

Am 30.01.2014 um 13:16 hat Markus Armbruster geschrieben:

Quoted 7 lines

It's a copy of dev->conf.bs. The copy was needed for non-qdevified controllers, which lacked dev.

Note how pci_piix3_xen_ide_unplug() cleared the copy. We'll get back to that in the next few commits.

So this pci_piix3_xen_ide_unplug() is what happens here:

Quoted 16 lines
hw/ide/piix.c +0 -3
@@ -169,12 +169,9 @@ static int pci_piix_ide_initfn(PCIDevice *dev)
 
 static int pci_piix3_xen_ide_unplug(DeviceState *dev)
 {
-    PCIIDEState *pci_ide;
     DriveInfo *di;
     int i = 0;
 
-    pci_ide = PCI_IDE(dev);
-
     for (; i < 3; i++) {
         di = drive_get_by_index(IF_IDE, i);
         if (di != NULL && !di->media_cd) {

hw/ide/piix.c static int pci_piix3_xen_ide_unplug(DeviceState *dev) · line 185

Quoted 7 lines
hw/ide/piix.c +0 -1
@@ -183,7 +180,6 @@ static int pci_piix3_xen_ide_unplug(DeviceState *dev)
                 bdrv_detach_dev(di->bdrv, ds);
             }
             bdrv_close(di->bdrv);
-            pci_ide->bus[di->bus].ifs[di->unit].bs = NULL;
             drive_put_ref(di);
         }
     }

Probably I'm just missing the obvious, but it seems to me that the copy was cleared here, while the original was left around. This was no problem because the original was unused anyway after device initialisation.

Quoted 4 lines

Now that the copy doesn't exist any more, we can't clear it, obviously, but why don't we have to clear the original? Won't we still run the "device is attached" code branches even though the device is really unplugged?

It's been a while since I wrote this. Almost 14 months, in fact.

Quoted 7 lines
Quoted 3 lines

No other IDE controller implements DeviceClass method unplug(). I can't remember why the normal code to detach the backend (release_drive()) doesn't do here. Stefano, can you help?

Too long to be able to remember the exact details :-/ However if you point me to a branch I can give it a try and tell you if the unplug still works as it used to.

Series trivially rebased to current master available at
git://repo.or.cz/qemu/armbru.git branch kill-non-qdev-ide

#9 lore raw

Re: [Qemu-devel] [PATCH v3 4/9] ide: Drop redundant IDEState member bs

Quoted 58 lines · Markus Armbruster
Quoted 56 lines · Stefano Stabellini
Quoted 54 lines · Markus Armbruster

[Note cc: Stefano]

Quoted 40 lines · Kevin Wolf

Am 30.01.2014 um 13:16 hat Markus Armbruster geschrieben:

Quoted 7 lines

It's a copy of dev->conf.bs. The copy was needed for non-qdevified controllers, which lacked dev.

Note how pci_piix3_xen_ide_unplug() cleared the copy. We'll get back to that in the next few commits.

So this pci_piix3_xen_ide_unplug() is what happens here:

Quoted 16 lines
hw/ide/piix.c +0 -3
@@ -169,12 +169,9 @@ static int pci_piix_ide_initfn(PCIDevice *dev)
 
 static int pci_piix3_xen_ide_unplug(DeviceState *dev)
 {
-    PCIIDEState *pci_ide;
     DriveInfo *di;
     int i = 0;
 
-    pci_ide = PCI_IDE(dev);
-
     for (; i < 3; i++) {
         di = drive_get_by_index(IF_IDE, i);
         if (di != NULL && !di->media_cd) {

hw/ide/piix.c static int pci_piix3_xen_ide_unplug(DeviceState *dev) · line 185

Quoted 7 lines
hw/ide/piix.c +0 -1
@@ -183,7 +180,6 @@ static int pci_piix3_xen_ide_unplug(DeviceState *dev)
                 bdrv_detach_dev(di->bdrv, ds);
             }
             bdrv_close(di->bdrv);
-            pci_ide->bus[di->bus].ifs[di->unit].bs = NULL;
             drive_put_ref(di);
         }
     }

Probably I'm just missing the obvious, but it seems to me that the copy was cleared here, while the original was left around. This was no problem because the original was unused anyway after device initialisation.

Quoted 4 lines

Now that the copy doesn't exist any more, we can't clear it, obviously, but why don't we have to clear the original? Won't we still run the "device is attached" code branches even though the device is really unplugged?

It's been a while since I wrote this. Almost 14 months, in fact.

No other IDE controller implements DeviceClass method unplug(). I can't remember why the normal code to detach the backend (release_drive()) doesn't do here. Stefano, can you help?

Quoted 6 lines
Quoted 3 lines

Too long to be able to remember the exact details :-/ However if you point me to a branch I can give it a try and tell you if the unplug still works as it used to.

Series trivially rebased to current master available at
git://repo.or.cz/qemu/armbru.git branch kill-non-qdev-ide

Unfortunately it doesn't work: I can see both sda and xvda being present after the system has booted.

#10 lore raw

Re: [Qemu-devel] [PATCH v3 4/9] ide: Drop redundant IDEState member bs

Quoted 63 lines · Stefano Stabellini
Quoted 62 lines · Markus Armbruster
Quoted 59 lines · Stefano Stabellini
Quoted 49 lines · Markus Armbruster

[Note cc: Stefano]

Quoted 40 lines · Kevin Wolf

Am 30.01.2014 um 13:16 hat Markus Armbruster geschrieben:

Quoted 7 lines

It's a copy of dev->conf.bs. The copy was needed for non-qdevified controllers, which lacked dev.

Note how pci_piix3_xen_ide_unplug() cleared the copy. We'll get back to that in the next few commits.

So this pci_piix3_xen_ide_unplug() is what happens here:

Quoted 16 lines
hw/ide/piix.c +0 -3
@@ -169,12 +169,9 @@ static int pci_piix_ide_initfn(PCIDevice *dev)
 
 static int pci_piix3_xen_ide_unplug(DeviceState *dev)
 {
-    PCIIDEState *pci_ide;
     DriveInfo *di;
     int i = 0;
 
-    pci_ide = PCI_IDE(dev);
-
     for (; i < 3; i++) {
         di = drive_get_by_index(IF_IDE, i);
         if (di != NULL && !di->media_cd) {

hw/ide/piix.c static int pci_piix3_xen_ide_unplug(DeviceState *dev) · line 185

Quoted 7 lines
hw/ide/piix.c +0 -1
@@ -183,7 +180,6 @@ static int pci_piix3_xen_ide_unplug(DeviceState *dev)
                 bdrv_detach_dev(di->bdrv, ds);
             }
             bdrv_close(di->bdrv);
-            pci_ide->bus[di->bus].ifs[di->unit].bs = NULL;
             drive_put_ref(di);
         }
     }

Probably I'm just missing the obvious, but it seems to me that the copy was cleared here, while the original was left around. This was no problem because the original was unused anyway after device initialisation.

Quoted 4 lines

Now that the copy doesn't exist any more, we can't clear it, obviously, but why don't we have to clear the original? Won't we still run the "device is attached" code branches even though the device is really unplugged?

Quoted 5 lines

It's been a while since I wrote this. Almost 14 months, in fact.

No other IDE controller implements DeviceClass method unplug(). I can't remember why the normal code to detach the backend (release_drive()) doesn't do here. Stefano, can you help?

Too long to be able to remember the exact details :-/ However if you point me to a branch I can give it a try and tell you if the unplug still works as it used to.

Quoted 5 lines
Quoted 2 lines

Series trivially rebased to current master available at
git://repo.or.cz/qemu/armbru.git branch kill-non-qdev-ide

Unfortunately it doesn't work: I can see both sda and xvda being present after the system has booted.

Thank you for testing. I'll try to clear the originals like Kevin suggested. Hopefully, that'll pass your test.

#11 lore raw

Re: [Qemu-devel] [PATCH v3 4/9] ide: Drop redundant IDEState member bs

Quoted 65 lines · Markus Armbruster
Quoted 63 lines · Stefano Stabellini
Quoted 62 lines · Markus Armbruster
Quoted 59 lines · Stefano Stabellini
Quoted 49 lines · Markus Armbruster

[Note cc: Stefano]

Quoted 40 lines · Kevin Wolf

Am 30.01.2014 um 13:16 hat Markus Armbruster geschrieben:

Quoted 7 lines

It's a copy of dev->conf.bs. The copy was needed for non-qdevified controllers, which lacked dev.

Note how pci_piix3_xen_ide_unplug() cleared the copy. We'll get back to that in the next few commits.

So this pci_piix3_xen_ide_unplug() is what happens here:

Quoted 16 lines
hw/ide/piix.c +0 -3
@@ -169,12 +169,9 @@ static int pci_piix_ide_initfn(PCIDevice *dev)
 
 static int pci_piix3_xen_ide_unplug(DeviceState *dev)
 {
-    PCIIDEState *pci_ide;
     DriveInfo *di;
     int i = 0;
 
-    pci_ide = PCI_IDE(dev);
-
     for (; i < 3; i++) {
         di = drive_get_by_index(IF_IDE, i);
         if (di != NULL && !di->media_cd) {

hw/ide/piix.c static int pci_piix3_xen_ide_unplug(DeviceState *dev) · line 185

Quoted 7 lines
hw/ide/piix.c +0 -1
@@ -183,7 +180,6 @@ static int pci_piix3_xen_ide_unplug(DeviceState *dev)
                 bdrv_detach_dev(di->bdrv, ds);
             }
             bdrv_close(di->bdrv);
-            pci_ide->bus[di->bus].ifs[di->unit].bs = NULL;
             drive_put_ref(di);
         }
     }

Probably I'm just missing the obvious, but it seems to me that the copy was cleared here, while the original was left around. This was no problem because the original was unused anyway after device initialisation.

Quoted 4 lines

Now that the copy doesn't exist any more, we can't clear it, obviously, but why don't we have to clear the original? Won't we still run the "device is attached" code branches even though the device is really unplugged?

Quoted 5 lines

It's been a while since I wrote this. Almost 14 months, in fact.

No other IDE controller implements DeviceClass method unplug(). I can't remember why the normal code to detach the backend (release_drive()) doesn't do here. Stefano, can you help?

Too long to be able to remember the exact details :-/ However if you point me to a branch I can give it a try and tell you if the unplug still works as it used to.

Quoted 8 lines
Quoted 5 lines
Quoted 2 lines

Series trivially rebased to current master available at
git://repo.or.cz/qemu/armbru.git branch kill-non-qdev-ide

Unfortunately it doesn't work: I can see both sda and xvda being present after the system has booted.

Thank you for testing. I'll try to clear the originals like Kevin suggested. Hopefully, that'll pass your test.

Stefano, I updated the branch, please retest it.

#12 lore raw

Re: [Qemu-devel] [PATCH v3 4/9] ide: Drop redundant IDEState member bs

Quoted 70 lines · Markus Armbruster
Quoted 68 lines · Markus Armbruster
Quoted 66 lines · Stefano Stabellini
Quoted 64 lines · Markus Armbruster
Quoted 52 lines · Stefano Stabellini
Quoted 51 lines · Markus Armbruster

[Note cc: Stefano]

Quoted 40 lines · Kevin Wolf

Am 30.01.2014 um 13:16 hat Markus Armbruster geschrieben:

Quoted 7 lines

It's a copy of dev->conf.bs. The copy was needed for non-qdevified controllers, which lacked dev.

Note how pci_piix3_xen_ide_unplug() cleared the copy. We'll get back to that in the next few commits.

So this pci_piix3_xen_ide_unplug() is what happens here:

Quoted 16 lines
hw/ide/piix.c +0 -3
@@ -169,12 +169,9 @@ static int pci_piix_ide_initfn(PCIDevice *dev)
 
 static int pci_piix3_xen_ide_unplug(DeviceState *dev)
 {
-    PCIIDEState *pci_ide;
     DriveInfo *di;
     int i = 0;
 
-    pci_ide = PCI_IDE(dev);
-
     for (; i < 3; i++) {
         di = drive_get_by_index(IF_IDE, i);
         if (di != NULL && !di->media_cd) {

hw/ide/piix.c static int pci_piix3_xen_ide_unplug(DeviceState *dev) · line 185

Quoted 7 lines
hw/ide/piix.c +0 -1
@@ -183,7 +180,6 @@ static int pci_piix3_xen_ide_unplug(DeviceState *dev)
                 bdrv_detach_dev(di->bdrv, ds);
             }
             bdrv_close(di->bdrv);
-            pci_ide->bus[di->bus].ifs[di->unit].bs = NULL;
             drive_put_ref(di);
         }
     }

Probably I'm just missing the obvious, but it seems to me that the copy was cleared here, while the original was left around. This was no problem because the original was unused anyway after device initialisation.

Quoted 4 lines

Now that the copy doesn't exist any more, we can't clear it, obviously, but why don't we have to clear the original? Won't we still run the "device is attached" code branches even though the device is really unplugged?

It's been a while since I wrote this. Almost 14 months, in fact.

Quoted 7 lines
Quoted 3 lines

No other IDE controller implements DeviceClass method unplug(). I can't remember why the normal code to detach the backend (release_drive()) doesn't do here. Stefano, can you help?

Too long to be able to remember the exact details :-/ However if you point me to a branch I can give it a try and tell you if the unplug still works as it used to.

Series trivially rebased to current master available at
git://repo.or.cz/qemu/armbru.git branch kill-non-qdev-ide

Quoted 7 lines
Quoted 5 lines
Quoted 2 lines

Unfortunately it doesn't work: I can see both sda and xvda being present after the system has booted.

Thank you for testing. I'll try to clear the originals like Kevin suggested. Hopefully, that'll pass your test.

Stefano, I updated the branch, please retest it.

QEMU exists with:

hw/ide/piix.c:183:pci_piix3_xen_ide_unplug: Object 0x7f172045b050 is not an instance of type ide-device