Revision 329c0a48

b/block.c
943 943
    }
944 944
}
945 945

  
946
void bdrv_emit_qmp_error_event(const BlockDriverState *bdrv,
947
                               BlockQMPEventAction action, int is_read)
948
{
949
    QObject *data;
950
    const char *action_str;
951

  
952
    switch (action) {
953
    case BDRV_ACTION_REPORT:
954
        action_str = "report";
955
        break;
956
    case BDRV_ACTION_IGNORE:
957
        action_str = "ignore";
958
        break;
959
    case BDRV_ACTION_STOP:
960
        action_str = "stop";
961
        break;
962
    default:
963
        abort();
964
    }
965

  
966
    data = qobject_from_jsonf("{ 'device': %s, 'action': %s, 'operation': %s }",
967
                              bdrv->device_name,
968
                              action_str,
969
                              is_read ? "read" : "write");
970
    monitor_protocol_event(QEVENT_BLOCK_IO_ERROR, data);
971

  
972
    qobject_decref(data);
973
}
974

  
946 975
static void bdrv_dev_change_media_cb(BlockDriverState *bs, bool load)
947 976
{
948 977
    if (bs->dev_ops && bs->dev_ops->change_media_cb) {
......
2293 2322
    return data.ret;
2294 2323
}
2295 2324

  
2296
void bdrv_mon_event(const BlockDriverState *bdrv,
2297
                    BlockMonEventAction action, int is_read)
2298
{
2299
    QObject *data;
2300
    const char *action_str;
2301

  
2302
    switch (action) {
2303
    case BDRV_ACTION_REPORT:
2304
        action_str = "report";
2305
        break;
2306
    case BDRV_ACTION_IGNORE:
2307
        action_str = "ignore";
2308
        break;
2309
    case BDRV_ACTION_STOP:
2310
        action_str = "stop";
2311
        break;
2312
    default:
2313
        abort();
2314
    }
2315

  
2316
    data = qobject_from_jsonf("{ 'device': %s, 'action': %s, 'operation': %s }",
2317
                              bdrv->device_name,
2318
                              action_str,
2319
                              is_read ? "read" : "write");
2320
    monitor_protocol_event(QEVENT_BLOCK_IO_ERROR, data);
2321

  
2322
    qobject_decref(data);
2323
}
2324

  
2325 2325
BlockInfoList *qmp_query_block(Error **errp)
2326 2326
{
2327 2327
    BlockInfoList *head = NULL, *cur_item = NULL;
b/block.h
85 85

  
86 86
typedef enum {
87 87
    BDRV_ACTION_REPORT, BDRV_ACTION_IGNORE, BDRV_ACTION_STOP
88
} BlockMonEventAction;
88
} BlockQMPEventAction;
89 89

  
90 90
void bdrv_iostatus_enable(BlockDriverState *bs);
91 91
void bdrv_iostatus_reset(BlockDriverState *bs);
92 92
void bdrv_iostatus_disable(BlockDriverState *bs);
93 93
bool bdrv_iostatus_is_enabled(const BlockDriverState *bs);
94 94
void bdrv_iostatus_set_err(BlockDriverState *bs, int error);
95
void bdrv_mon_event(const BlockDriverState *bdrv,
96
                    BlockMonEventAction action, int is_read);
95
void bdrv_emit_qmp_error_event(const BlockDriverState *bdrv,
96
                               BlockQMPEventAction action, int is_read);
97 97
void bdrv_info_print(Monitor *mon, const QObject *data);
98 98
void bdrv_info(Monitor *mon, QObject **ret_data);
99 99
void bdrv_stats_print(Monitor *mon, const QObject *data);
b/hw/ide/core.c
519 519
    BlockErrorAction action = bdrv_get_on_error(s->bs, is_read);
520 520

  
521 521
    if (action == BLOCK_ERR_IGNORE) {
522
        bdrv_mon_event(s->bs, BDRV_ACTION_IGNORE, is_read);
522
        bdrv_emit_qmp_error_event(s->bs, BDRV_ACTION_IGNORE, is_read);
523 523
        return 0;
524 524
    }
525 525

  
......
527 527
            || action == BLOCK_ERR_STOP_ANY) {
528 528
        s->bus->dma->ops->set_unit(s->bus->dma, s->unit);
529 529
        s->bus->error_status = op;
530
        bdrv_mon_event(s->bs, BDRV_ACTION_STOP, is_read);
530
        bdrv_emit_qmp_error_event(s->bs, BDRV_ACTION_STOP, is_read);
531 531
        vm_stop(RUN_STATE_IO_ERROR);
532 532
        bdrv_iostatus_set_err(s->bs, error);
533 533
    } else {
......
537 537
        } else {
538 538
            ide_rw_error(s);
539 539
        }
540
        bdrv_mon_event(s->bs, BDRV_ACTION_REPORT, is_read);
540
        bdrv_emit_qmp_error_event(s->bs, BDRV_ACTION_REPORT, is_read);
541 541
    }
542 542

  
543 543
    return 1;
b/hw/scsi-disk.c
233 233
    BlockErrorAction action = bdrv_get_on_error(s->qdev.conf.bs, is_read);
234 234

  
235 235
    if (action == BLOCK_ERR_IGNORE) {
236
        bdrv_mon_event(s->qdev.conf.bs, BDRV_ACTION_IGNORE, is_read);
236
        bdrv_emit_qmp_error_event(s->qdev.conf.bs, BDRV_ACTION_IGNORE, is_read);
237 237
        return 0;
238 238
    }
239 239

  
240 240
    if ((error == ENOSPC && action == BLOCK_ERR_STOP_ENOSPC)
241 241
            || action == BLOCK_ERR_STOP_ANY) {
242 242

  
243
        bdrv_mon_event(s->qdev.conf.bs, BDRV_ACTION_STOP, is_read);
243
        bdrv_emit_qmp_error_event(s->qdev.conf.bs, BDRV_ACTION_STOP, is_read);
244 244
        vm_stop(RUN_STATE_IO_ERROR);
245 245
        bdrv_iostatus_set_err(s->qdev.conf.bs, error);
246 246
        scsi_req_retry(&r->req);
......
259 259
            scsi_check_condition(r, SENSE_CODE(IO_ERROR));
260 260
            break;
261 261
        }
262
        bdrv_mon_event(s->qdev.conf.bs, BDRV_ACTION_REPORT, is_read);
262
        bdrv_emit_qmp_error_event(s->qdev.conf.bs, BDRV_ACTION_REPORT, is_read);
263 263
    }
264 264
    return 1;
265 265
}
b/hw/virtio-blk.c
69 69
    VirtIOBlock *s = req->dev;
70 70

  
71 71
    if (action == BLOCK_ERR_IGNORE) {
72
        bdrv_mon_event(s->bs, BDRV_ACTION_IGNORE, is_read);
72
        bdrv_emit_qmp_error_event(s->bs, BDRV_ACTION_IGNORE, is_read);
73 73
        return 0;
74 74
    }
75 75

  
......
77 77
            || action == BLOCK_ERR_STOP_ANY) {
78 78
        req->next = s->rq;
79 79
        s->rq = req;
80
        bdrv_mon_event(s->bs, BDRV_ACTION_STOP, is_read);
80
        bdrv_emit_qmp_error_event(s->bs, BDRV_ACTION_STOP, is_read);
81 81
        vm_stop(RUN_STATE_IO_ERROR);
82 82
        bdrv_iostatus_set_err(s->bs, error);
83 83
    } else {
84 84
        virtio_blk_req_complete(req, VIRTIO_BLK_S_IOERR);
85 85
        bdrv_acct_done(s->bs, &req->acct);
86 86
        g_free(req);
87
        bdrv_mon_event(s->bs, BDRV_ACTION_REPORT, is_read);
87
        bdrv_emit_qmp_error_event(s->bs, BDRV_ACTION_REPORT, is_read);
88 88
    }
89 89

  
90 90
    return 1;

Also available in: Unified diff