Commit ce4b6522 authored by Kevin Wolf's avatar Kevin Wolf Committed by Anthony Liguori
Browse files

ide: Implement rerror option

parent e9b2e818
Loading
Loading
Loading
Loading
+37 −17
Original line number Diff line number Diff line
@@ -61,8 +61,9 @@ static inline int media_is_cd(IDEState *s)
}

static void ide_dma_start(IDEState *s, BlockDriverCompletionFunc *dma_cb);
static void ide_dma_restart(IDEState *s);
static void ide_dma_restart(IDEState *s, int is_read);
static void ide_atapi_cmd_read_dma_cb(void *opaque, int ret);
static int ide_handle_rw_error(IDEState *s, int error, int op);

static void padstr(char *str, const char *src, int len)
{
@@ -407,9 +408,12 @@ static void ide_sector_read(IDEState *s)
            n = s->req_nb_sectors;
        ret = bdrv_read(s->bs, sector_num, s->io_buffer, n);
        if (ret != 0) {
            ide_rw_error(s);
            if (ide_handle_rw_error(s, -ret,
                BM_STATUS_PIO_RETRY | BM_STATUS_RETRY_READ))
            {
                return;
            }
        }
        ide_transfer_start(s, s->io_buffer, 512 * n, ide_sector_read);
        ide_set_irq(s->bus);
        ide_set_sector(s, sector_num + n);
@@ -471,9 +475,10 @@ void ide_dma_error(IDEState *s)
    ide_set_irq(s->bus);
}

static int ide_handle_write_error(IDEState *s, int error, int op)
static int ide_handle_rw_error(IDEState *s, int error, int op)
{
    BlockInterfaceErrorAction action = drive_get_on_error(s->bs, 0);
    int is_read = (op & BM_STATUS_RETRY_READ);
    BlockInterfaceErrorAction action = drive_get_on_error(s->bs, is_read);

    if (action == BLOCK_ERR_IGNORE)
        return 0;
@@ -484,7 +489,7 @@ static int ide_handle_write_error(IDEState *s, int error, int op)
        s->bus->bmdma->status |= op;
        vm_stop(0);
    } else {
        if (op == BM_STATUS_DMA_RETRY) {
        if (op & BM_STATUS_DMA_RETRY) {
            dma_buf_commit(s, 0);
            ide_dma_error(s);
        } else {
@@ -551,10 +556,12 @@ static void ide_read_dma_cb(void *opaque, int ret)
    int64_t sector_num;

    if (ret < 0) {
        dma_buf_commit(s, 1);
	ide_dma_error(s);
        if (ide_handle_rw_error(s, -ret,
            BM_STATUS_DMA_RETRY | BM_STATUS_RETRY_READ))
        {
            return;
        }
    }

    n = s->io_buffer_size >> 9;
    sector_num = ide_get_sector(s);
@@ -622,7 +629,7 @@ static void ide_sector_write(IDEState *s)
    ret = bdrv_write(s->bs, sector_num, s->io_buffer, n);

    if (ret != 0) {
        if (ide_handle_write_error(s, -ret, BM_STATUS_PIO_RETRY))
        if (ide_handle_rw_error(s, -ret, BM_STATUS_PIO_RETRY))
            return;
    }

@@ -658,18 +665,25 @@ static void ide_sector_write(IDEState *s)
static void ide_dma_restart_bh(void *opaque)
{
    BMDMAState *bm = opaque;
    int is_read;

    qemu_bh_delete(bm->bh);
    bm->bh = NULL;

    is_read = !!(bm->status & BM_STATUS_RETRY_READ);

    if (bm->status & BM_STATUS_DMA_RETRY) {
        bm->status &= ~BM_STATUS_DMA_RETRY;
        ide_dma_restart(bmdma_active_if(bm));
        bm->status &= ~(BM_STATUS_DMA_RETRY | BM_STATUS_RETRY_READ);
        ide_dma_restart(bmdma_active_if(bm), is_read);
    } else if (bm->status & BM_STATUS_PIO_RETRY) {
        bm->status &= ~BM_STATUS_PIO_RETRY;
        bm->status &= ~(BM_STATUS_PIO_RETRY | BM_STATUS_RETRY_READ);
        if (is_read) {
            ide_sector_read(bmdma_active_if(bm));
        } else {
            ide_sector_write(bmdma_active_if(bm));
        }
    }
}

void ide_dma_restart_cb(void *opaque, int running, int reason)
{
@@ -692,7 +706,7 @@ static void ide_write_dma_cb(void *opaque, int ret)
    int64_t sector_num;

    if (ret < 0) {
        if (ide_handle_write_error(s, -ret,  BM_STATUS_DMA_RETRY))
        if (ide_handle_rw_error(s, -ret,  BM_STATUS_DMA_RETRY))
            return;
    }

@@ -2715,7 +2729,7 @@ static void ide_dma_start(IDEState *s, BlockDriverCompletionFunc *dma_cb)
    }
}

static void ide_dma_restart(IDEState *s)
static void ide_dma_restart(IDEState *s, int is_read)
{
    BMDMAState *bm = s->bus->bmdma;
    ide_set_sector(s, bm->sector_num);
@@ -2723,7 +2737,13 @@ static void ide_dma_restart(IDEState *s)
    s->io_buffer_size = 0;
    s->nsector = bm->nsector;
    bm->cur_addr = bm->addr;

    if (is_read) {
        bm->dma_cb = ide_read_dma_cb;
    } else {
        bm->dma_cb = ide_write_dma_cb;
    }

    ide_dma_start(s, bm->dma_cb);
}

+1 −0
Original line number Diff line number Diff line
@@ -464,6 +464,7 @@ struct IDEDeviceInfo {
#define BM_STATUS_INT    0x04
#define BM_STATUS_DMA_RETRY  0x08
#define BM_STATUS_PIO_RETRY  0x10
#define BM_STATUS_RETRY_READ 0x20

#define BM_CMD_START     0x01
#define BM_CMD_READ      0x08
+1 −1
Original line number Diff line number Diff line
@@ -2198,7 +2198,7 @@ DriveInfo *drive_init(QemuOpts *opts, void *opaque,

    on_read_error = BLOCK_ERR_REPORT;
    if ((buf = qemu_opt_get(opts, "rerror")) != NULL) {
        if (1) {
        if (type != IF_IDE) {
            fprintf(stderr, "rerror is no supported by this format\n");
            return NULL;
        }