Patchwork [05/10] ide: Drop redundant IDEState member bs

login
register
mail settings
Submitter Markus Armbruster
Date Dec. 17, 2012, 2:05 p.m.
Message ID <1355753160-17544-6-git-send-email-armbru@redhat.com>
Download mbox | patch
Permalink /patch/206871/
State New
Headers show

Comments

Markus Armbruster - Dec. 17, 2012, 2:05 p.m.
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.

Signed-off-by: Markus Armbruster <armbru@redhat.com>
---
 hw/ide/ahci.c     | 11 +++++-----
 hw/ide/atapi.c    | 37 ++++++++++++++++++---------------
 hw/ide/core.c     | 62 ++++++++++++++++++++++++++++++-------------------------
 hw/ide/internal.h |  3 +--
 hw/ide/macio.c    | 20 ++++++++++--------
 hw/ide/piix.c     |  1 -
 hw/ide/qdev.c     |  2 +-
 7 files changed, 73 insertions(+), 63 deletions(-)

Patch

diff --git a/hw/ide/ahci.c b/hw/ide/ahci.c
index 4249489..5fce616 100644
--- a/hw/ide/ahci.c
+++ b/hw/ide/ahci.c
@@ -732,7 +732,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;
 }
@@ -743,6 +743,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 */
@@ -782,9 +783,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;
@@ -795,9 +796,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;
diff --git a/hw/ide/atapi.c b/hw/ide/atapi.c
index 861fd2b..d077d18 100644
--- a/hw/ide/atapi.c
+++ b/hw/ide/atapi.c
@@ -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;
diff --git a/hw/ide/core.c b/hw/ide/core.c
index 66e56c2..9f306c6 100644
--- a/hw/ide/core.c
+++ b/hw/ide/core.c
@@ -148,10 +148,11 @@  static void ide_identify(IDEState *s)
         put_le16(p + 84, (1 << 14) | 0);
     }
     /* 14 = NOP supported, 5=WCACHE enabled, 0=SMART feature set enabled */
-    if (bdrv_enable_write_cache(s->bs))
+    if (bdrv_enable_write_cache(s->dev->conf.bs)) {
          put_le16(p + 85, (1 << 14) | (1 << 5) | 1);
-    else
+    } else {
          put_le16(p + 85, (1 << 14) | 1);
+    }
     /* 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 */
@@ -478,7 +479,7 @@  static void ide_sector_read_cb(void *opaque, int ret)
     s->pio_aiocb = NULL;
     s->status &= ~BUSY_STAT;
 
-    bdrv_acct_done(s->bs, &s->acct);
+    bdrv_acct_done(s->dev->conf.bs, &s->acct);
     if (ret != 0) {
         if (ide_handle_rw_error(s, -ret, BM_STATUS_PIO_RETRY |
                                 BM_STATUS_RETRY_READ)) {
@@ -502,6 +503,7 @@  static void ide_sector_read_cb(void *opaque, int ret)
 
 void ide_sector_read(IDEState *s)
 {
+    BlockDriverState *bs = s->dev->conf.bs;
     int64_t sector_num;
     int n;
 
@@ -529,8 +531,8 @@  void ide_sector_read(IDEState *s)
     s->iov.iov_len  = n * BDRV_SECTOR_SIZE;
     qemu_iovec_init_external(&s->qiov, &s->iov, 1);
 
-    bdrv_acct_start(s->bs, &s->acct, n * BDRV_SECTOR_SIZE, BDRV_ACCT_READ);
-    s->pio_aiocb = bdrv_aio_readv(s->bs, sector_num, &s->qiov, n,
+    bdrv_acct_start(bs, &s->acct, n * BDRV_SECTOR_SIZE, BDRV_ACCT_READ);
+    s->pio_aiocb = bdrv_aio_readv(bs, sector_num, &s->qiov, n,
                                   ide_sector_read_cb, s);
 }
 
@@ -557,7 +559,8 @@  void ide_dma_error(IDEState *s)
 static int ide_handle_rw_error(IDEState *s, int error, int op)
 {
     bool is_read = (op & BM_STATUS_RETRY_READ) != 0;
-    BlockErrorAction action = bdrv_get_error_action(s->bs, is_read, error);
+    BlockErrorAction action = bdrv_get_error_action(s->dev->conf.bs,
+                                                    is_read, error);
 
     if (action == BDRV_ACTION_STOP) {
         s->bus->dma->ops->set_unit(s->bus->dma, s->unit);
@@ -570,13 +573,14 @@  static int ide_handle_rw_error(IDEState *s, int error, int op)
             ide_rw_error(s);
         }
     }
-    bdrv_error_action(s->bs, action, is_read, error);
+    bdrv_error_action(s->dev->conf.bs, action, is_read, error);
     return action != BDRV_ACTION_IGNORE;
 }
 
 void ide_dma_cb(void *opaque, int ret)
 {
     IDEState *s = opaque;
+    BlockDriverState *bs = s->dev->conf.bs;
     int n;
     int64_t sector_num;
     bool stay_active = false;
@@ -636,15 +640,15 @@  void ide_dma_cb(void *opaque, int ret)
 
     switch (s->dma_cmd) {
     case IDE_DMA_READ:
-        s->bus->dma->aiocb = dma_bdrv_read(s->bs, &s->sg, sector_num,
+        s->bus->dma->aiocb = dma_bdrv_read(bs, &s->sg, sector_num,
                                            ide_dma_cb, s);
         break;
     case IDE_DMA_WRITE:
-        s->bus->dma->aiocb = dma_bdrv_write(s->bs, &s->sg, sector_num,
+        s->bus->dma->aiocb = dma_bdrv_write(bs, &s->sg, sector_num,
                                             ide_dma_cb, s);
         break;
     case IDE_DMA_TRIM:
-        s->bus->dma->aiocb = dma_bdrv_io(s->bs, &s->sg, sector_num,
+        s->bus->dma->aiocb = dma_bdrv_io(bs, &s->sg, sector_num,
                                          ide_issue_trim, ide_dma_cb, s,
                                          DMA_DIRECTION_TO_DEVICE);
         break;
@@ -653,7 +657,7 @@  void ide_dma_cb(void *opaque, int ret)
 
 eot:
     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);
     }
     ide_set_inactive(s);
     if (stay_active) {
@@ -670,12 +674,12 @@  static void ide_sector_start_dma(IDEState *s, enum ide_dma_cmd dma_cmd)
 
     switch (dma_cmd) {
     case IDE_DMA_READ:
-        bdrv_acct_start(s->bs, &s->acct, s->nsector * BDRV_SECTOR_SIZE,
-                        BDRV_ACCT_READ);
+        bdrv_acct_start(s->dev->conf.bs, &s->acct,
+                        s->nsector * BDRV_SECTOR_SIZE, BDRV_ACCT_READ);
         break;
     case IDE_DMA_WRITE:
-        bdrv_acct_start(s->bs, &s->acct, s->nsector * BDRV_SECTOR_SIZE,
-                        BDRV_ACCT_WRITE);
+        bdrv_acct_start(s->dev->conf.bs, &s->acct,
+                        s->nsector * BDRV_SECTOR_SIZE, BDRV_ACCT_WRITE);
         break;
     default:
         break;
@@ -695,7 +699,7 @@  static void ide_sector_write_cb(void *opaque, int ret)
     IDEState *s = opaque;
     int n;
 
-    bdrv_acct_done(s->bs, &s->acct);
+    bdrv_acct_done(s->dev->conf.bs, &s->acct);
 
     s->pio_aiocb = NULL;
     s->status &= ~BUSY_STAT;
@@ -740,6 +744,7 @@  static void ide_sector_write_cb(void *opaque, int ret)
 
 void ide_sector_write(IDEState *s)
 {
+    BlockDriverState *bs = s->dev->conf.bs;
     int64_t sector_num;
     int n;
 
@@ -757,8 +762,8 @@  void ide_sector_write(IDEState *s)
     s->iov.iov_len  = n * BDRV_SECTOR_SIZE;
     qemu_iovec_init_external(&s->qiov, &s->iov, 1);
 
-    bdrv_acct_start(s->bs, &s->acct, n * BDRV_SECTOR_SIZE, BDRV_ACCT_READ);
-    s->pio_aiocb = bdrv_aio_writev(s->bs, sector_num, &s->qiov, n,
+    bdrv_acct_start(bs, &s->acct, n * BDRV_SECTOR_SIZE, BDRV_ACCT_READ);
+    s->pio_aiocb = bdrv_aio_writev(bs, sector_num, &s->qiov, n,
                                    ide_sector_write_cb, s);
 }
 
@@ -773,7 +778,7 @@  static void ide_flush_cb(void *opaque, int ret)
         }
     }
 
-    bdrv_acct_done(s->bs, &s->acct);
+    bdrv_acct_done(s->dev->conf.bs, &s->acct);
     s->status = READY_STAT | SEEK_STAT;
     ide_set_irq(s->bus);
 }
@@ -785,8 +790,8 @@  void ide_flush_cache(IDEState *s)
         return;
     }
 
-    bdrv_acct_start(s->bs, &s->acct, 0, BDRV_ACCT_FLUSH);
-    bdrv_aio_flush(s->bs, ide_flush_cb, s);
+    bdrv_acct_start(s->dev->conf.bs, &s->acct, 0, BDRV_ACCT_FLUSH);
+    bdrv_aio_flush(s->dev->conf.bs, ide_flush_cb, s);
 }
 
 static void ide_cfata_metadata_inquiry(IDEState *s)
@@ -849,7 +854,7 @@  static void ide_cd_change_cb(void *opaque, bool load)
     uint64_t nb_sectors;
 
     s->tray_open = !load;
-    bdrv_get_geometry(s->bs, &nb_sectors);
+    bdrv_get_geometry(s->dev->conf.bs, &nb_sectors);
     s->nb_sectors = nb_sectors;
 
     /*
@@ -1236,14 +1241,14 @@  void ide_exec_cmd(IDEBus *bus, uint32_t val)
         /* XXX: valid for CDROM ? */
         switch(s->feature) {
         case 0x02: /* write cache enable */
-            bdrv_set_enable_write_cache(s->bs, true);
+            bdrv_set_enable_write_cache(s->dev->conf.bs, true);
             identify_data = (uint16_t *)s->identify_data;
             put_le16(identify_data + 85, (1 << 14) | (1 << 5) | 1);
             s->status = READY_STAT | SEEK_STAT;
             ide_set_irq(s->bus);
             break;
         case 0x82: /* write cache disable */
-            bdrv_set_enable_write_cache(s->bs, false);
+            bdrv_set_enable_write_cache(s->dev->conf.bs, false);
             identify_data = (uint16_t *)s->identify_data;
             put_le16(identify_data + 85, (1 << 14) | 1);
             ide_flush_cache(s);
@@ -1923,15 +1928,15 @@  static const BlockDevOps ide_cd_block_ops = {
     .is_medium_locked = ide_cd_is_medium_locked,
 };
 
-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,
                    int chs_trans)
 {
+    BlockDriverState *bs = s->dev->conf.bs;
     uint64_t nb_sectors;
 
-    s->bs = bs;
     s->drive_kind = kind;
 
     bdrv_get_geometry(bs, &nb_sectors);
@@ -1951,7 +1956,7 @@  int ide_init_drive(IDEState *s, BlockDriverState *bs, IDEDriveKind kind,
         bdrv_set_dev_ops(bs, &ide_cd_block_ops, s);
         bdrv_set_buffer_alignment(bs, 2048);
     } else {
-        if (!bdrv_is_inserted(s->bs)) {
+        if (!bdrv_is_inserted(bs)) {
             error_report("Device needs media, but drive is empty");
             return -1;
         }
@@ -2139,7 +2144,8 @@  static int ide_drive_post_load(void *opaque, int version_id)
     IDEState *s = opaque;
 
     if (s->identify_set) {
-        bdrv_set_enable_write_cache(s->bs, !!(s->identify_data[85] & (1 << 5)));
+        bdrv_set_enable_write_cache(s->dev->conf.bs,
+                                    !!(s->identify_data[85] & (1 << 5)));
     }
     return 0;
 }
diff --git a/hw/ide/internal.h b/hw/ide/internal.h
index 52d1642..6058db4 100644
--- a/hw/ide/internal.h
+++ b/hw/ide/internal.h
@@ -374,7 +374,6 @@  struct IDEState {
 
     /* set for lba48 access */
     uint8_t lba48;
-    BlockDriverState *bs;
     char version[9];
     /* ATAPI specific */
     struct unreported_events events;
@@ -545,7 +544,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,
diff --git a/hw/ide/macio.c b/hw/ide/macio.c
index d2edcc0..44d31a1 100644
--- a/hw/ide/macio.c
+++ b/hw/ide/macio.c
@@ -82,13 +82,13 @@  static void pmac_ide_atapi_transfer_cb(void *opaque, int ret)
     io->addr += io->len;
     io->len = 0;
 
-    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:
-    bdrv_acct_done(s->bs, &s->acct);
+    bdrv_acct_done(s->dev->conf.bs, &s->acct);
     io->dma_end(opaque);
 }
 
@@ -97,6 +97,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;
     int64_t sector_num;
 
@@ -141,15 +142,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, s,
                                DMA_DIRECTION_TO_DEVICE);
         break;
@@ -158,7 +159,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);
 }
@@ -167,20 +168,21 @@  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;
 
     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;
diff --git a/hw/ide/piix.c b/hw/ide/piix.c
index 9431bad..51ee93a 100644
--- a/hw/ide/piix.c
+++ b/hw/ide/piix.c
@@ -184,7 +184,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);
         }
     }
diff --git a/hw/ide/qdev.c b/hw/ide/qdev.c
index 01bbc74..dbbc3dd 100644
--- a/hw/ide/qdev.c
+++ b/hw/ide/qdev.c
@@ -148,7 +148,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) {