mirror of
https://gitlab.com/qemu-project/qemu
synced 2024-11-05 20:35:44 +00:00
Introduce rerror option for drives
rerror controls the action to be taken when an error occurs while accessing the guest image file. It corresponds to werror which already controls the action take for write errors. This purely introduces parsing rerror command line option into the right structures, real support for it in the device emulation is added in the following patches. Signed-off-by: Kevin Wolf <kwolf@redhat.com> Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
This commit is contained in:
parent
f785009961
commit
e9b2e81889
3 changed files with 44 additions and 19 deletions
|
@ -64,6 +64,9 @@ QemuOptsList qemu_drive_opts = {
|
|||
},{
|
||||
.name = "serial",
|
||||
.type = QEMU_OPT_STRING,
|
||||
},{
|
||||
.name = "rerror",
|
||||
.type = QEMU_OPT_STRING,
|
||||
},{
|
||||
.name = "werror",
|
||||
.type = QEMU_OPT_STRING,
|
||||
|
|
1
sysemu.h
1
sysemu.h
|
@ -180,6 +180,7 @@ typedef struct DriveInfo {
|
|||
int bus;
|
||||
int unit;
|
||||
QemuOpts *opts;
|
||||
BlockInterfaceErrorAction on_read_error;
|
||||
BlockInterfaceErrorAction on_write_error;
|
||||
char serial[BLOCK_SERIAL_STRLEN + 1];
|
||||
QTAILQ_ENTRY(DriveInfo) next;
|
||||
|
|
59
vl.c
59
vl.c
|
@ -1964,16 +1964,12 @@ BlockInterfaceErrorAction drive_get_on_error(
|
|||
{
|
||||
DriveInfo *dinfo;
|
||||
|
||||
if (is_read) {
|
||||
return BLOCK_ERR_REPORT;
|
||||
}
|
||||
|
||||
QTAILQ_FOREACH(dinfo, &drives, next) {
|
||||
if (dinfo->bdrv == bdrv)
|
||||
return dinfo->on_write_error;
|
||||
return is_read ? dinfo->on_read_error : dinfo->on_write_error;
|
||||
}
|
||||
|
||||
return BLOCK_ERR_STOP_ENOSPC;
|
||||
return is_read ? BLOCK_ERR_REPORT : BLOCK_ERR_STOP_ENOSPC;
|
||||
}
|
||||
|
||||
static void bdrv_format_print(void *opaque, const char *name)
|
||||
|
@ -1989,6 +1985,23 @@ void drive_uninit(DriveInfo *dinfo)
|
|||
qemu_free(dinfo);
|
||||
}
|
||||
|
||||
static int parse_block_error_action(const char *buf, int is_read)
|
||||
{
|
||||
if (!strcmp(buf, "ignore")) {
|
||||
return BLOCK_ERR_IGNORE;
|
||||
} else if (!is_read && !strcmp(buf, "enospc")) {
|
||||
return BLOCK_ERR_STOP_ENOSPC;
|
||||
} else if (!strcmp(buf, "stop")) {
|
||||
return BLOCK_ERR_STOP_ANY;
|
||||
} else if (!strcmp(buf, "report")) {
|
||||
return BLOCK_ERR_REPORT;
|
||||
} else {
|
||||
fprintf(stderr, "qemu: '%s' invalid %s error action\n",
|
||||
buf, is_read ? "read" : "write");
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
DriveInfo *drive_init(QemuOpts *opts, void *opaque,
|
||||
int *fatal_error)
|
||||
{
|
||||
|
@ -2008,7 +2021,8 @@ DriveInfo *drive_init(QemuOpts *opts, void *opaque,
|
|||
int cache;
|
||||
int aio = 0;
|
||||
int ro = 0;
|
||||
int bdrv_flags, onerror;
|
||||
int bdrv_flags;
|
||||
int on_read_error, on_write_error;
|
||||
const char *devaddr;
|
||||
DriveInfo *dinfo;
|
||||
int snapshot = 0;
|
||||
|
@ -2169,22 +2183,28 @@ DriveInfo *drive_init(QemuOpts *opts, void *opaque,
|
|||
}
|
||||
}
|
||||
|
||||
onerror = BLOCK_ERR_STOP_ENOSPC;
|
||||
on_write_error = BLOCK_ERR_STOP_ENOSPC;
|
||||
if ((buf = qemu_opt_get(opts, "werror")) != NULL) {
|
||||
if (type != IF_IDE && type != IF_SCSI && type != IF_VIRTIO) {
|
||||
fprintf(stderr, "werror is no supported by this format\n");
|
||||
return NULL;
|
||||
}
|
||||
if (!strcmp(buf, "ignore"))
|
||||
onerror = BLOCK_ERR_IGNORE;
|
||||
else if (!strcmp(buf, "enospc"))
|
||||
onerror = BLOCK_ERR_STOP_ENOSPC;
|
||||
else if (!strcmp(buf, "stop"))
|
||||
onerror = BLOCK_ERR_STOP_ANY;
|
||||
else if (!strcmp(buf, "report"))
|
||||
onerror = BLOCK_ERR_REPORT;
|
||||
else {
|
||||
fprintf(stderr, "qemu: '%s' invalid write error action\n", buf);
|
||||
|
||||
on_write_error = parse_block_error_action(buf, 0);
|
||||
if (on_write_error < 0) {
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
|
||||
on_read_error = BLOCK_ERR_REPORT;
|
||||
if ((buf = qemu_opt_get(opts, "rerror")) != NULL) {
|
||||
if (1) {
|
||||
fprintf(stderr, "rerror is no supported by this format\n");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
on_read_error = parse_block_error_action(buf, 1);
|
||||
if (on_read_error < 0) {
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
|
@ -2268,7 +2288,8 @@ DriveInfo *drive_init(QemuOpts *opts, void *opaque,
|
|||
dinfo->type = type;
|
||||
dinfo->bus = bus_id;
|
||||
dinfo->unit = unit_id;
|
||||
dinfo->on_write_error = onerror;
|
||||
dinfo->on_read_error = on_read_error;
|
||||
dinfo->on_write_error = on_write_error;
|
||||
dinfo->opts = opts;
|
||||
if (serial)
|
||||
strncpy(dinfo->serial, serial, sizeof(serial));
|
||||
|
|
Loading…
Reference in a new issue