Skip to content

Commit

Permalink
iostatus: move BlockdevOnError declaration to QAPI
Browse files Browse the repository at this point in the history
This will let block-stream reuse the enum.  Places that used the enums
are renamed accordingly.

Signed-off-by: Paolo Bonzini <[email protected]>
Reviewed-by: Eric Blake <[email protected]>
Signed-off-by: Kevin Wolf <[email protected]>
  • Loading branch information
bonzini authored and kevmw committed Sep 28, 2012
1 parent ff06f5f commit 92aa5c6
Show file tree
Hide file tree
Showing 11 changed files with 54 additions and 36 deletions.
6 changes: 3 additions & 3 deletions block.c
Original file line number Diff line number Diff line change
Expand Up @@ -4209,9 +4209,9 @@ void bdrv_iostatus_enable(BlockDriverState *bs)
bool bdrv_iostatus_is_enabled(const BlockDriverState *bs)
{
return (bs->iostatus_enabled &&
(bs->on_write_error == BLOCK_ERR_STOP_ENOSPC ||
bs->on_write_error == BLOCK_ERR_STOP_ANY ||
bs->on_read_error == BLOCK_ERR_STOP_ANY));
(bs->on_write_error == BLOCKDEV_ON_ERROR_ENOSPC ||
bs->on_write_error == BLOCKDEV_ON_ERROR_STOP ||
bs->on_read_error == BLOCKDEV_ON_ERROR_STOP));
}

void bdrv_iostatus_disable(BlockDriverState *bs)
Expand Down
5 changes: 0 additions & 5 deletions block.h
Original file line number Diff line number Diff line change
Expand Up @@ -90,11 +90,6 @@ typedef struct BlockDevOps {
#define BDRV_SECTOR_SIZE (1ULL << BDRV_SECTOR_BITS)
#define BDRV_SECTOR_MASK ~(BDRV_SECTOR_SIZE - 1)

typedef enum {
BLOCK_ERR_REPORT, BLOCK_ERR_IGNORE, BLOCK_ERR_STOP_ENOSPC,
BLOCK_ERR_STOP_ANY
} BlockdevOnError;

typedef enum {
BDRV_ACTION_REPORT, BDRV_ACTION_IGNORE, BDRV_ACTION_STOP
} BlockErrorAction;
Expand Down
14 changes: 7 additions & 7 deletions block/commit.c
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ typedef struct CommitBlockJob {
BlockDriverState *active;
BlockDriverState *top;
BlockDriverState *base;
BlockErrorAction on_error;
BlockdevOnError on_error;
int base_flags;
int orig_overlay_flags;
} CommitBlockJob;
Expand Down Expand Up @@ -126,9 +126,9 @@ static void coroutine_fn commit_run(void *opaque)
bytes_written += n * BDRV_SECTOR_SIZE;
}
if (ret < 0) {
if (s->on_error == BLOCK_ERR_STOP_ANY ||
s->on_error == BLOCK_ERR_REPORT ||
(s->on_error == BLOCK_ERR_STOP_ENOSPC && ret == -ENOSPC)) {
if (s->on_error == BLOCKDEV_ON_ERROR_STOP ||
s->on_error == BLOCKDEV_ON_ERROR_REPORT||
(s->on_error == BLOCKDEV_ON_ERROR_ENOSPC && ret == -ENOSPC)) {
goto exit_free_buf;
} else {
n = 0;
Expand Down Expand Up @@ -182,7 +182,7 @@ static BlockJobType commit_job_type = {

void commit_start(BlockDriverState *bs, BlockDriverState *base,
BlockDriverState *top, int64_t speed,
BlockErrorAction on_error, BlockDriverCompletionFunc *cb,
BlockdevOnError on_error, BlockDriverCompletionFunc *cb,
void *opaque, Error **errp)
{
CommitBlockJob *s;
Expand All @@ -192,8 +192,8 @@ void commit_start(BlockDriverState *bs, BlockDriverState *base,
BlockDriverState *overlay_bs;
Error *local_err = NULL;

if ((on_error == BLOCK_ERR_STOP_ANY ||
on_error == BLOCK_ERR_STOP_ENOSPC) &&
if ((on_error == BLOCKDEV_ON_ERROR_STOP ||
on_error == BLOCKDEV_ON_ERROR_ENOSPC) &&
!bdrv_iostatus_is_enabled(bs)) {
error_set(errp, QERR_INVALID_PARAMETER_COMBINATION);
return;
Expand Down
2 changes: 1 addition & 1 deletion block_int.h
Original file line number Diff line number Diff line change
Expand Up @@ -323,7 +323,7 @@ void stream_start(BlockDriverState *bs, BlockDriverState *base,
*/
void commit_start(BlockDriverState *bs, BlockDriverState *base,
BlockDriverState *top, int64_t speed,
BlockErrorAction on_error, BlockDriverCompletionFunc *cb,
BlockdevOnError on_error, BlockDriverCompletionFunc *cb,
void *opaque, Error **errp);

#endif /* BLOCK_INT_H */
14 changes: 7 additions & 7 deletions blockdev.c
Original file line number Diff line number Diff line change
Expand Up @@ -241,13 +241,13 @@ static void drive_put_ref_bh_schedule(DriveInfo *dinfo)
static int parse_block_error_action(const char *buf, int is_read)
{
if (!strcmp(buf, "ignore")) {
return BLOCK_ERR_IGNORE;
return BLOCKDEV_ON_ERROR_IGNORE;
} else if (!is_read && !strcmp(buf, "enospc")) {
return BLOCK_ERR_STOP_ENOSPC;
return BLOCKDEV_ON_ERROR_ENOSPC;
} else if (!strcmp(buf, "stop")) {
return BLOCK_ERR_STOP_ANY;
return BLOCKDEV_ON_ERROR_STOP;
} else if (!strcmp(buf, "report")) {
return BLOCK_ERR_REPORT;
return BLOCKDEV_ON_ERROR_REPORT;
} else {
error_report("'%s' invalid %s error action",
buf, is_read ? "read" : "write");
Expand Down Expand Up @@ -433,7 +433,7 @@ DriveInfo *drive_init(QemuOpts *opts, int default_to_scsi)
return NULL;
}

on_write_error = BLOCK_ERR_STOP_ENOSPC;
on_write_error = BLOCKDEV_ON_ERROR_ENOSPC;
if ((buf = qemu_opt_get(opts, "werror")) != NULL) {
if (type != IF_IDE && type != IF_SCSI && type != IF_VIRTIO && type != IF_NONE) {
error_report("werror is not supported by this bus type");
Expand All @@ -446,7 +446,7 @@ DriveInfo *drive_init(QemuOpts *opts, int default_to_scsi)
}
}

on_read_error = BLOCK_ERR_REPORT;
on_read_error = BLOCKDEV_ON_ERROR_REPORT;
if ((buf = qemu_opt_get(opts, "rerror")) != NULL) {
if (type != IF_IDE && type != IF_VIRTIO && type != IF_SCSI && type != IF_NONE) {
error_report("rerror is not supported by this bus type");
Expand Down Expand Up @@ -1143,7 +1143,7 @@ void qmp_block_commit(const char *device,
/* This will be part of the QMP command, if/when the
* BlockdevOnError change for blkmirror makes it in
*/
BlockErrorAction on_error = BLOCK_ERR_REPORT;
BlockdevOnError on_error = BLOCKDEV_ON_ERROR_REPORT;

/* drain all i/o before commits */
bdrv_drain_all();
Expand Down
4 changes: 2 additions & 2 deletions hw/fdc.c
Original file line number Diff line number Diff line change
Expand Up @@ -1994,11 +1994,11 @@ static int fdctrl_connect_drives(FDCtrl *fdctrl)
drive->fdctrl = fdctrl;

if (drive->bs) {
if (bdrv_get_on_error(drive->bs, 0) != BLOCK_ERR_STOP_ENOSPC) {
if (bdrv_get_on_error(drive->bs, 0) != BLOCKDEV_ON_ERROR_ENOSPC) {
error_report("fdc doesn't support drive option werror");
return -1;
}
if (bdrv_get_on_error(drive->bs, 1) != BLOCK_ERR_REPORT) {
if (bdrv_get_on_error(drive->bs, 1) != BLOCKDEV_ON_ERROR_REPORT) {
error_report("fdc doesn't support drive option rerror");
return -1;
}
Expand Down
6 changes: 3 additions & 3 deletions hw/ide/core.c
Original file line number Diff line number Diff line change
Expand Up @@ -559,13 +559,13 @@ static int ide_handle_rw_error(IDEState *s, int error, int op)
int is_read = (op & BM_STATUS_RETRY_READ);
BlockdevOnError action = bdrv_get_on_error(s->bs, is_read);

if (action == BLOCK_ERR_IGNORE) {
if (action == BLOCKDEV_ON_ERROR_IGNORE) {
bdrv_emit_qmp_error_event(s->bs, BDRV_ACTION_IGNORE, is_read);
return 0;
}

if ((error == ENOSPC && action == BLOCK_ERR_STOP_ENOSPC)
|| action == BLOCK_ERR_STOP_ANY) {
if ((error == ENOSPC && action == BLOCKDEV_ON_ERROR_ENOSPC)
|| action == BLOCKDEV_ON_ERROR_STOP) {
s->bus->dma->ops->set_unit(s->bus->dma, s->unit);
s->bus->error_status = op;
bdrv_emit_qmp_error_event(s->bs, BDRV_ACTION_STOP, is_read);
Expand Down
6 changes: 3 additions & 3 deletions hw/scsi-disk.c
Original file line number Diff line number Diff line change
Expand Up @@ -390,13 +390,13 @@ static int scsi_handle_rw_error(SCSIDiskReq *r, int error)
SCSIDiskState *s = DO_UPCAST(SCSIDiskState, qdev, r->req.dev);
BlockdevOnError action = bdrv_get_on_error(s->qdev.conf.bs, is_read);

if (action == BLOCK_ERR_IGNORE) {
if (action == BLOCKDEV_ON_ERROR_IGNORE) {
bdrv_emit_qmp_error_event(s->qdev.conf.bs, BDRV_ACTION_IGNORE, is_read);
return 0;
}

if ((error == ENOSPC && action == BLOCK_ERR_STOP_ENOSPC)
|| action == BLOCK_ERR_STOP_ANY) {
if ((error == ENOSPC && action == BLOCKDEV_ON_ERROR_ENOSPC)
|| action == BLOCKDEV_ON_ERROR_STOP) {

bdrv_emit_qmp_error_event(s->qdev.conf.bs, BDRV_ACTION_STOP, is_read);
vm_stop(RUN_STATE_IO_ERROR);
Expand Down
4 changes: 2 additions & 2 deletions hw/scsi-generic.c
Original file line number Diff line number Diff line change
Expand Up @@ -400,11 +400,11 @@ static int scsi_generic_initfn(SCSIDevice *s)
return -1;
}

if (bdrv_get_on_error(s->conf.bs, 0) != BLOCK_ERR_STOP_ENOSPC) {
if (bdrv_get_on_error(s->conf.bs, 0) != BLOCKDEV_ON_ERROR_ENOSPC) {
error_report("Device doesn't support drive option werror");
return -1;
}
if (bdrv_get_on_error(s->conf.bs, 1) != BLOCK_ERR_REPORT) {
if (bdrv_get_on_error(s->conf.bs, 1) != BLOCKDEV_ON_ERROR_REPORT) {
error_report("Device doesn't support drive option rerror");
return -1;
}
Expand Down
6 changes: 3 additions & 3 deletions hw/virtio-blk.c
Original file line number Diff line number Diff line change
Expand Up @@ -69,13 +69,13 @@ static int virtio_blk_handle_rw_error(VirtIOBlockReq *req, int error,
BlockdevOnError action = bdrv_get_on_error(req->dev->bs, is_read);
VirtIOBlock *s = req->dev;

if (action == BLOCK_ERR_IGNORE) {
if (action == BLOCKDEV_ON_ERROR_IGNORE) {
bdrv_emit_qmp_error_event(s->bs, BDRV_ACTION_IGNORE, is_read);
return 0;
}

if ((error == ENOSPC && action == BLOCK_ERR_STOP_ENOSPC)
|| action == BLOCK_ERR_STOP_ANY) {
if ((error == ENOSPC && action == BLOCKDEV_ON_ERROR_ENOSPC)
|| action == BLOCKDEV_ON_ERROR_STOP) {
req->next = s->rq;
s->rq = req;
bdrv_emit_qmp_error_event(s->bs, BDRV_ACTION_STOP, is_read);
Expand Down
23 changes: 23 additions & 0 deletions qapi-schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -1087,6 +1087,29 @@
##
{ 'command': 'query-pci', 'returns': ['PciInfo'] }

##
# @BlockdevOnError:
#
# An enumeration of possible behaviors for errors on I/O operations.
# The exact meaning depends on whether the I/O was initiated by a guest
# or by a block job
#
# @report: for guest operations, report the error to the guest;
# for jobs, cancel the job
#
# @ignore: ignore the error, only report a QMP event (BLOCK_IO_ERROR
# or BLOCK_JOB_ERROR)
#
# @enospc: same as @stop on ENOSPC, same as @report otherwise.
#
# @stop: for guest operations, stop the virtual machine;
# for jobs, pause the job
#
# Since: 1.3
##
{ 'enum': 'BlockdevOnError',
'data': ['report', 'ignore', 'enospc', 'stop'] }

##
# @BlockJobInfo:
#
Expand Down

0 comments on commit 92aa5c6

Please sign in to comment.