2010-02-18 19:48:12 +03:00
|
|
|
/*
|
|
|
|
* Block protocol for I/O error injection
|
|
|
|
*
|
|
|
|
* Copyright (c) 2010 Kevin Wolf <kwolf@redhat.com>
|
|
|
|
*
|
|
|
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
|
|
* of this software and associated documentation files (the "Software"), to deal
|
|
|
|
* in the Software without restriction, including without limitation the rights
|
|
|
|
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
|
|
* copies of the Software, and to permit persons to whom the Software is
|
|
|
|
* furnished to do so, subject to the following conditions:
|
|
|
|
*
|
|
|
|
* The above copyright notice and this permission notice shall be included in
|
|
|
|
* all copies or substantial portions of the Software.
|
|
|
|
*
|
|
|
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
|
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
|
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
|
|
|
|
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
|
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
|
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
|
|
* THE SOFTWARE.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "qemu-common.h"
|
2012-12-17 21:20:00 +04:00
|
|
|
#include "qemu/config-file.h"
|
2012-12-17 21:19:44 +04:00
|
|
|
#include "block/block_int.h"
|
2012-12-17 21:20:00 +04:00
|
|
|
#include "qemu/module.h"
|
2014-07-18 22:24:57 +04:00
|
|
|
#include "qapi/qmp/qbool.h"
|
|
|
|
#include "qapi/qmp/qdict.h"
|
|
|
|
#include "qapi/qmp/qint.h"
|
|
|
|
#include "qapi/qmp/qstring.h"
|
2010-02-18 19:48:12 +03:00
|
|
|
|
|
|
|
typedef struct BDRVBlkdebugState {
|
2012-06-06 10:10:42 +04:00
|
|
|
int state;
|
2012-09-28 19:23:00 +04:00
|
|
|
int new_state;
|
2012-12-06 17:32:57 +04:00
|
|
|
|
2012-06-06 10:10:42 +04:00
|
|
|
QLIST_HEAD(, BlkdebugRule) rules[BLKDBG_EVENT_MAX];
|
|
|
|
QSIMPLEQ_HEAD(, BlkdebugRule) active_rules;
|
2012-12-06 17:32:57 +04:00
|
|
|
QLIST_HEAD(, BlkdebugSuspendedReq) suspended_reqs;
|
2010-02-18 19:48:12 +03:00
|
|
|
} BDRVBlkdebugState;
|
|
|
|
|
2010-02-19 18:24:35 +03:00
|
|
|
typedef struct BlkdebugAIOCB {
|
2014-10-07 15:59:14 +04:00
|
|
|
BlockAIOCB common;
|
2010-02-19 18:24:35 +03:00
|
|
|
QEMUBH *bh;
|
|
|
|
int ret;
|
|
|
|
} BlkdebugAIOCB;
|
|
|
|
|
2012-12-06 17:32:57 +04:00
|
|
|
typedef struct BlkdebugSuspendedReq {
|
|
|
|
Coroutine *co;
|
|
|
|
char *tag;
|
|
|
|
QLIST_ENTRY(BlkdebugSuspendedReq) next;
|
|
|
|
} BlkdebugSuspendedReq;
|
|
|
|
|
2012-10-31 19:34:37 +04:00
|
|
|
static const AIOCBInfo blkdebug_aiocb_info = {
|
2014-09-11 09:41:17 +04:00
|
|
|
.aiocb_size = sizeof(BlkdebugAIOCB),
|
2010-02-19 18:24:35 +03:00
|
|
|
};
|
|
|
|
|
2010-03-15 19:27:00 +03:00
|
|
|
enum {
|
|
|
|
ACTION_INJECT_ERROR,
|
|
|
|
ACTION_SET_STATE,
|
2012-12-06 17:32:57 +04:00
|
|
|
ACTION_SUSPEND,
|
2010-03-15 19:27:00 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
typedef struct BlkdebugRule {
|
|
|
|
BlkDebugEvent event;
|
|
|
|
int action;
|
|
|
|
int state;
|
|
|
|
union {
|
|
|
|
struct {
|
|
|
|
int error;
|
|
|
|
int immediately;
|
|
|
|
int once;
|
2012-06-06 10:10:43 +04:00
|
|
|
int64_t sector;
|
2010-03-15 19:27:00 +03:00
|
|
|
} inject;
|
|
|
|
struct {
|
|
|
|
int new_state;
|
|
|
|
} set_state;
|
2012-12-06 17:32:57 +04:00
|
|
|
struct {
|
|
|
|
char *tag;
|
|
|
|
} suspend;
|
2010-03-15 19:27:00 +03:00
|
|
|
} options;
|
|
|
|
QLIST_ENTRY(BlkdebugRule) next;
|
2012-06-06 10:10:42 +04:00
|
|
|
QSIMPLEQ_ENTRY(BlkdebugRule) active_next;
|
2010-03-15 19:27:00 +03:00
|
|
|
} BlkdebugRule;
|
|
|
|
|
|
|
|
static QemuOptsList inject_error_opts = {
|
|
|
|
.name = "inject-error",
|
|
|
|
.head = QTAILQ_HEAD_INITIALIZER(inject_error_opts.head),
|
|
|
|
.desc = {
|
|
|
|
{
|
|
|
|
.name = "event",
|
|
|
|
.type = QEMU_OPT_STRING,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
.name = "state",
|
|
|
|
.type = QEMU_OPT_NUMBER,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
.name = "errno",
|
|
|
|
.type = QEMU_OPT_NUMBER,
|
|
|
|
},
|
2012-06-06 10:10:43 +04:00
|
|
|
{
|
|
|
|
.name = "sector",
|
|
|
|
.type = QEMU_OPT_NUMBER,
|
|
|
|
},
|
2010-03-15 19:27:00 +03:00
|
|
|
{
|
|
|
|
.name = "once",
|
|
|
|
.type = QEMU_OPT_BOOL,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
.name = "immediately",
|
|
|
|
.type = QEMU_OPT_BOOL,
|
|
|
|
},
|
|
|
|
{ /* end of list */ }
|
|
|
|
},
|
|
|
|
};
|
|
|
|
|
|
|
|
static QemuOptsList set_state_opts = {
|
|
|
|
.name = "set-state",
|
2010-06-30 19:40:42 +04:00
|
|
|
.head = QTAILQ_HEAD_INITIALIZER(set_state_opts.head),
|
2010-03-15 19:27:00 +03:00
|
|
|
.desc = {
|
|
|
|
{
|
|
|
|
.name = "event",
|
|
|
|
.type = QEMU_OPT_STRING,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
.name = "state",
|
|
|
|
.type = QEMU_OPT_NUMBER,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
.name = "new_state",
|
|
|
|
.type = QEMU_OPT_NUMBER,
|
|
|
|
},
|
|
|
|
{ /* end of list */ }
|
|
|
|
},
|
|
|
|
};
|
|
|
|
|
|
|
|
static QemuOptsList *config_groups[] = {
|
|
|
|
&inject_error_opts,
|
|
|
|
&set_state_opts,
|
|
|
|
NULL
|
|
|
|
};
|
|
|
|
|
|
|
|
static const char *event_names[BLKDBG_EVENT_MAX] = {
|
2010-03-15 19:38:05 +03:00
|
|
|
[BLKDBG_L1_UPDATE] = "l1_update",
|
|
|
|
[BLKDBG_L1_GROW_ALLOC_TABLE] = "l1_grow.alloc_table",
|
|
|
|
[BLKDBG_L1_GROW_WRITE_TABLE] = "l1_grow.write_table",
|
|
|
|
[BLKDBG_L1_GROW_ACTIVATE_TABLE] = "l1_grow.activate_table",
|
|
|
|
|
|
|
|
[BLKDBG_L2_LOAD] = "l2_load",
|
|
|
|
[BLKDBG_L2_UPDATE] = "l2_update",
|
|
|
|
[BLKDBG_L2_UPDATE_COMPRESSED] = "l2_update_compressed",
|
|
|
|
[BLKDBG_L2_ALLOC_COW_READ] = "l2_alloc.cow_read",
|
|
|
|
[BLKDBG_L2_ALLOC_WRITE] = "l2_alloc.write",
|
|
|
|
|
|
|
|
[BLKDBG_READ_AIO] = "read_aio",
|
|
|
|
[BLKDBG_READ_BACKING_AIO] = "read_backing_aio",
|
|
|
|
[BLKDBG_READ_COMPRESSED] = "read_compressed",
|
|
|
|
|
|
|
|
[BLKDBG_WRITE_AIO] = "write_aio",
|
|
|
|
[BLKDBG_WRITE_COMPRESSED] = "write_compressed",
|
|
|
|
|
|
|
|
[BLKDBG_VMSTATE_LOAD] = "vmstate_load",
|
|
|
|
[BLKDBG_VMSTATE_SAVE] = "vmstate_save",
|
|
|
|
|
|
|
|
[BLKDBG_COW_READ] = "cow_read",
|
|
|
|
[BLKDBG_COW_WRITE] = "cow_write",
|
|
|
|
|
|
|
|
[BLKDBG_REFTABLE_LOAD] = "reftable_load",
|
|
|
|
[BLKDBG_REFTABLE_GROW] = "reftable_grow",
|
2013-09-02 11:25:10 +04:00
|
|
|
[BLKDBG_REFTABLE_UPDATE] = "reftable_update",
|
2010-03-15 19:38:05 +03:00
|
|
|
|
|
|
|
[BLKDBG_REFBLOCK_LOAD] = "refblock_load",
|
|
|
|
[BLKDBG_REFBLOCK_UPDATE] = "refblock_update",
|
|
|
|
[BLKDBG_REFBLOCK_UPDATE_PART] = "refblock_update_part",
|
|
|
|
[BLKDBG_REFBLOCK_ALLOC] = "refblock_alloc",
|
|
|
|
[BLKDBG_REFBLOCK_ALLOC_HOOKUP] = "refblock_alloc.hookup",
|
|
|
|
[BLKDBG_REFBLOCK_ALLOC_WRITE] = "refblock_alloc.write",
|
|
|
|
[BLKDBG_REFBLOCK_ALLOC_WRITE_BLOCKS] = "refblock_alloc.write_blocks",
|
|
|
|
[BLKDBG_REFBLOCK_ALLOC_WRITE_TABLE] = "refblock_alloc.write_table",
|
|
|
|
[BLKDBG_REFBLOCK_ALLOC_SWITCH_TABLE] = "refblock_alloc.switch_table",
|
|
|
|
|
|
|
|
[BLKDBG_CLUSTER_ALLOC] = "cluster_alloc",
|
|
|
|
[BLKDBG_CLUSTER_ALLOC_BYTES] = "cluster_alloc_bytes",
|
|
|
|
[BLKDBG_CLUSTER_FREE] = "cluster_free",
|
2013-06-05 17:17:55 +04:00
|
|
|
|
|
|
|
[BLKDBG_FLUSH_TO_OS] = "flush_to_os",
|
|
|
|
[BLKDBG_FLUSH_TO_DISK] = "flush_to_disk",
|
2014-01-14 18:37:03 +04:00
|
|
|
|
|
|
|
[BLKDBG_PWRITEV_RMW_HEAD] = "pwritev_rmw.head",
|
|
|
|
[BLKDBG_PWRITEV_RMW_AFTER_HEAD] = "pwritev_rmw.after_head",
|
|
|
|
[BLKDBG_PWRITEV_RMW_TAIL] = "pwritev_rmw.tail",
|
|
|
|
[BLKDBG_PWRITEV_RMW_AFTER_TAIL] = "pwritev_rmw.after_tail",
|
|
|
|
[BLKDBG_PWRITEV] = "pwritev",
|
|
|
|
[BLKDBG_PWRITEV_ZERO] = "pwritev_zero",
|
|
|
|
[BLKDBG_PWRITEV_DONE] = "pwritev_done",
|
2014-10-24 17:57:32 +04:00
|
|
|
|
|
|
|
[BLKDBG_EMPTY_IMAGE_PREPARE] = "empty_image_prepare",
|
2010-03-15 19:27:00 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
static int get_event_by_name(const char *name, BlkDebugEvent *event)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
|
|
|
|
for (i = 0; i < BLKDBG_EVENT_MAX; i++) {
|
|
|
|
if (!strcmp(event_names[i], name)) {
|
|
|
|
*event = i;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
struct add_rule_data {
|
|
|
|
BDRVBlkdebugState *s;
|
|
|
|
int action;
|
2014-09-20 12:55:52 +04:00
|
|
|
Error **errp;
|
2010-03-15 19:27:00 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
static int add_rule(QemuOpts *opts, void *opaque)
|
|
|
|
{
|
|
|
|
struct add_rule_data *d = opaque;
|
|
|
|
BDRVBlkdebugState *s = d->s;
|
|
|
|
const char* event_name;
|
|
|
|
BlkDebugEvent event;
|
|
|
|
struct BlkdebugRule *rule;
|
|
|
|
|
|
|
|
/* Find the right event for the rule */
|
|
|
|
event_name = qemu_opt_get(opts, "event");
|
2014-09-20 12:55:52 +04:00
|
|
|
if (!event_name) {
|
|
|
|
error_setg(d->errp, "Missing event name for rule");
|
|
|
|
return -1;
|
|
|
|
} else if (get_event_by_name(event_name, &event) < 0) {
|
|
|
|
error_setg(d->errp, "Invalid event name \"%s\"", event_name);
|
2010-03-15 19:27:00 +03:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Set attributes common for all actions */
|
2011-08-21 07:09:37 +04:00
|
|
|
rule = g_malloc0(sizeof(*rule));
|
2010-03-15 19:27:00 +03:00
|
|
|
*rule = (struct BlkdebugRule) {
|
|
|
|
.event = event,
|
|
|
|
.action = d->action,
|
|
|
|
.state = qemu_opt_get_number(opts, "state", 0),
|
|
|
|
};
|
|
|
|
|
|
|
|
/* Parse action-specific options */
|
|
|
|
switch (d->action) {
|
|
|
|
case ACTION_INJECT_ERROR:
|
|
|
|
rule->options.inject.error = qemu_opt_get_number(opts, "errno", EIO);
|
|
|
|
rule->options.inject.once = qemu_opt_get_bool(opts, "once", 0);
|
|
|
|
rule->options.inject.immediately =
|
|
|
|
qemu_opt_get_bool(opts, "immediately", 0);
|
2012-06-06 10:10:43 +04:00
|
|
|
rule->options.inject.sector = qemu_opt_get_number(opts, "sector", -1);
|
2010-03-15 19:27:00 +03:00
|
|
|
break;
|
|
|
|
|
|
|
|
case ACTION_SET_STATE:
|
|
|
|
rule->options.set_state.new_state =
|
|
|
|
qemu_opt_get_number(opts, "new_state", 0);
|
|
|
|
break;
|
2012-12-06 17:32:57 +04:00
|
|
|
|
|
|
|
case ACTION_SUSPEND:
|
|
|
|
rule->options.suspend.tag =
|
|
|
|
g_strdup(qemu_opt_get(opts, "tag"));
|
|
|
|
break;
|
2010-03-15 19:27:00 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
/* Add the rule */
|
|
|
|
QLIST_INSERT_HEAD(&s->rules[event], rule, next);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2012-12-06 17:32:56 +04:00
|
|
|
static void remove_rule(BlkdebugRule *rule)
|
|
|
|
{
|
|
|
|
switch (rule->action) {
|
|
|
|
case ACTION_INJECT_ERROR:
|
|
|
|
case ACTION_SET_STATE:
|
|
|
|
break;
|
2012-12-06 17:32:57 +04:00
|
|
|
case ACTION_SUSPEND:
|
|
|
|
g_free(rule->options.suspend.tag);
|
|
|
|
break;
|
2012-12-06 17:32:56 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
QLIST_REMOVE(rule, next);
|
|
|
|
g_free(rule);
|
|
|
|
}
|
|
|
|
|
2013-12-20 22:28:07 +04:00
|
|
|
static int read_config(BDRVBlkdebugState *s, const char *filename,
|
|
|
|
QDict *options, Error **errp)
|
2010-03-15 19:27:00 +03:00
|
|
|
{
|
2013-12-20 22:28:06 +04:00
|
|
|
FILE *f = NULL;
|
2010-03-15 19:27:00 +03:00
|
|
|
int ret;
|
|
|
|
struct add_rule_data d;
|
2013-12-20 22:28:07 +04:00
|
|
|
Error *local_err = NULL;
|
2010-03-15 19:27:00 +03:00
|
|
|
|
2013-12-20 22:28:06 +04:00
|
|
|
if (filename) {
|
|
|
|
f = fopen(filename, "r");
|
|
|
|
if (f == NULL) {
|
|
|
|
error_setg_errno(errp, errno, "Could not read blkdebug config file");
|
|
|
|
return -errno;
|
|
|
|
}
|
2010-03-15 19:27:00 +03:00
|
|
|
|
2013-12-20 22:28:06 +04:00
|
|
|
ret = qemu_config_parse(f, config_groups, filename);
|
|
|
|
if (ret < 0) {
|
|
|
|
error_setg(errp, "Could not parse blkdebug config file");
|
|
|
|
ret = -EINVAL;
|
|
|
|
goto fail;
|
|
|
|
}
|
2010-03-15 19:27:00 +03:00
|
|
|
}
|
|
|
|
|
2013-12-20 22:28:07 +04:00
|
|
|
qemu_config_parse_qdict(options, config_groups, &local_err);
|
2014-01-30 18:07:28 +04:00
|
|
|
if (local_err) {
|
2013-12-20 22:28:07 +04:00
|
|
|
error_propagate(errp, local_err);
|
|
|
|
ret = -EINVAL;
|
|
|
|
goto fail;
|
|
|
|
}
|
|
|
|
|
2010-03-15 19:27:00 +03:00
|
|
|
d.s = s;
|
|
|
|
d.action = ACTION_INJECT_ERROR;
|
2014-09-20 12:55:52 +04:00
|
|
|
d.errp = &local_err;
|
|
|
|
qemu_opts_foreach(&inject_error_opts, add_rule, &d, 1);
|
|
|
|
if (local_err) {
|
|
|
|
error_propagate(errp, local_err);
|
|
|
|
ret = -EINVAL;
|
|
|
|
goto fail;
|
|
|
|
}
|
2010-03-15 19:27:00 +03:00
|
|
|
|
|
|
|
d.action = ACTION_SET_STATE;
|
2014-09-20 12:55:52 +04:00
|
|
|
qemu_opts_foreach(&set_state_opts, add_rule, &d, 1);
|
|
|
|
if (local_err) {
|
|
|
|
error_propagate(errp, local_err);
|
|
|
|
ret = -EINVAL;
|
|
|
|
goto fail;
|
|
|
|
}
|
2010-03-15 19:27:00 +03:00
|
|
|
|
|
|
|
ret = 0;
|
|
|
|
fail:
|
2010-06-30 19:42:23 +04:00
|
|
|
qemu_opts_reset(&inject_error_opts);
|
|
|
|
qemu_opts_reset(&set_state_opts);
|
2013-12-20 22:28:06 +04:00
|
|
|
if (f) {
|
|
|
|
fclose(f);
|
|
|
|
}
|
2010-03-15 19:27:00 +03:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Valid blkdebug filenames look like blkdebug:path/to/config:path/to/image */
|
2013-04-10 15:37:33 +04:00
|
|
|
static void blkdebug_parse_filename(const char *filename, QDict *options,
|
|
|
|
Error **errp)
|
2010-02-18 19:48:12 +03:00
|
|
|
{
|
2013-04-10 15:37:33 +04:00
|
|
|
const char *c;
|
2010-02-18 19:48:12 +03:00
|
|
|
|
2010-03-15 19:27:00 +03:00
|
|
|
/* Parse the blkdebug: prefix */
|
2013-04-10 15:37:33 +04:00
|
|
|
if (!strstart(filename, "blkdebug:", &filename)) {
|
2013-12-20 22:28:02 +04:00
|
|
|
/* There was no prefix; therefore, all options have to be already
|
|
|
|
present in the QDict (except for the filename) */
|
|
|
|
qdict_put(options, "x-image", qstring_from_str(filename));
|
2013-04-10 15:37:33 +04:00
|
|
|
return;
|
2010-02-18 19:48:12 +03:00
|
|
|
}
|
|
|
|
|
2013-04-10 15:37:33 +04:00
|
|
|
/* Parse config file path */
|
2010-03-15 19:27:00 +03:00
|
|
|
c = strchr(filename, ':');
|
|
|
|
if (c == NULL) {
|
2013-04-10 15:37:33 +04:00
|
|
|
error_setg(errp, "blkdebug requires both config file and image path");
|
|
|
|
return;
|
2010-03-15 19:27:00 +03:00
|
|
|
}
|
|
|
|
|
2013-04-10 15:37:33 +04:00
|
|
|
if (c != filename) {
|
|
|
|
QString *config_path;
|
|
|
|
config_path = qstring_from_substr(filename, 0, c - filename - 1);
|
|
|
|
qdict_put(options, "config", config_path);
|
2010-03-15 19:27:00 +03:00
|
|
|
}
|
2013-04-10 15:37:33 +04:00
|
|
|
|
|
|
|
/* TODO Allow multi-level nesting and set file.filename here */
|
2010-03-15 19:27:00 +03:00
|
|
|
filename = c + 1;
|
2013-04-10 15:37:33 +04:00
|
|
|
qdict_put(options, "x-image", qstring_from_str(filename));
|
|
|
|
}
|
|
|
|
|
|
|
|
static QemuOptsList runtime_opts = {
|
|
|
|
.name = "blkdebug",
|
|
|
|
.head = QTAILQ_HEAD_INITIALIZER(runtime_opts.head),
|
|
|
|
.desc = {
|
|
|
|
{
|
|
|
|
.name = "config",
|
|
|
|
.type = QEMU_OPT_STRING,
|
|
|
|
.help = "Path to the configuration file",
|
|
|
|
},
|
|
|
|
{
|
|
|
|
.name = "x-image",
|
|
|
|
.type = QEMU_OPT_STRING,
|
|
|
|
.help = "[internal use only, will be removed]",
|
|
|
|
},
|
2014-01-14 16:44:35 +04:00
|
|
|
{
|
|
|
|
.name = "align",
|
|
|
|
.type = QEMU_OPT_SIZE,
|
|
|
|
.help = "Required alignment in bytes",
|
|
|
|
},
|
2013-04-10 15:37:33 +04:00
|
|
|
{ /* end of list */ }
|
|
|
|
},
|
|
|
|
};
|
|
|
|
|
2013-09-05 16:22:29 +04:00
|
|
|
static int blkdebug_open(BlockDriverState *bs, QDict *options, int flags,
|
|
|
|
Error **errp)
|
2013-04-10 15:37:33 +04:00
|
|
|
{
|
|
|
|
BDRVBlkdebugState *s = bs->opaque;
|
|
|
|
QemuOpts *opts;
|
|
|
|
Error *local_err = NULL;
|
2013-12-20 22:28:15 +04:00
|
|
|
const char *config;
|
2014-01-14 16:44:35 +04:00
|
|
|
uint64_t align;
|
2013-04-10 15:37:33 +04:00
|
|
|
int ret;
|
|
|
|
|
2014-01-02 06:49:17 +04:00
|
|
|
opts = qemu_opts_create(&runtime_opts, NULL, 0, &error_abort);
|
2013-04-10 15:37:33 +04:00
|
|
|
qemu_opts_absorb_qdict(opts, options, &local_err);
|
2014-01-30 18:07:28 +04:00
|
|
|
if (local_err) {
|
2013-10-10 17:44:03 +04:00
|
|
|
error_propagate(errp, local_err);
|
2013-04-10 15:37:33 +04:00
|
|
|
ret = -EINVAL;
|
2014-02-08 12:53:22 +04:00
|
|
|
goto out;
|
2013-04-10 15:37:33 +04:00
|
|
|
}
|
|
|
|
|
2013-12-20 22:28:07 +04:00
|
|
|
/* Read rules from config file or command line options */
|
2013-04-10 15:37:33 +04:00
|
|
|
config = qemu_opt_get(opts, "config");
|
2013-12-20 22:28:07 +04:00
|
|
|
ret = read_config(s, config, options, errp);
|
2013-12-20 22:28:06 +04:00
|
|
|
if (ret) {
|
2014-02-08 12:53:22 +04:00
|
|
|
goto out;
|
2013-04-10 15:37:33 +04:00
|
|
|
}
|
2010-03-15 19:27:00 +03:00
|
|
|
|
2010-06-30 19:43:40 +04:00
|
|
|
/* Set initial state */
|
2012-06-06 10:10:42 +04:00
|
|
|
s->state = 1;
|
2010-06-30 19:43:40 +04:00
|
|
|
|
2010-03-15 19:27:00 +03:00
|
|
|
/* Open the backing file */
|
2014-02-18 21:33:05 +04:00
|
|
|
assert(bs->file == NULL);
|
2013-12-20 22:28:15 +04:00
|
|
|
ret = bdrv_open_image(&bs->file, qemu_opt_get(opts, "x-image"), options, "image",
|
2014-02-18 21:33:12 +04:00
|
|
|
flags | BDRV_O_PROTOCOL, false, &local_err);
|
2010-03-15 19:27:00 +03:00
|
|
|
if (ret < 0) {
|
2013-10-10 17:44:03 +04:00
|
|
|
error_propagate(errp, local_err);
|
2014-02-08 12:53:22 +04:00
|
|
|
goto out;
|
2010-03-15 19:27:00 +03:00
|
|
|
}
|
|
|
|
|
2014-01-14 16:44:35 +04:00
|
|
|
/* Set request alignment */
|
|
|
|
align = qemu_opt_get_size(opts, "align", bs->request_alignment);
|
|
|
|
if (align > 0 && align < INT_MAX && !(align & (align - 1))) {
|
|
|
|
bs->request_alignment = align;
|
|
|
|
} else {
|
|
|
|
error_setg(errp, "Invalid alignment");
|
|
|
|
ret = -EINVAL;
|
2014-02-08 12:53:22 +04:00
|
|
|
goto fail_unref;
|
2014-01-14 16:44:35 +04:00
|
|
|
}
|
|
|
|
|
2013-04-10 15:37:33 +04:00
|
|
|
ret = 0;
|
2014-02-08 12:53:22 +04:00
|
|
|
goto out;
|
|
|
|
|
|
|
|
fail_unref:
|
|
|
|
bdrv_unref(bs->file);
|
|
|
|
out:
|
2013-04-10 15:37:33 +04:00
|
|
|
qemu_opts_del(opts);
|
|
|
|
return ret;
|
2010-02-18 19:48:12 +03:00
|
|
|
}
|
|
|
|
|
2010-02-19 18:24:35 +03:00
|
|
|
static void error_callback_bh(void *opaque)
|
|
|
|
{
|
|
|
|
struct BlkdebugAIOCB *acb = opaque;
|
|
|
|
qemu_bh_delete(acb->bh);
|
|
|
|
acb->common.cb(acb->common.opaque, acb->ret);
|
2014-09-11 09:41:28 +04:00
|
|
|
qemu_aio_unref(acb);
|
2010-02-19 18:24:35 +03:00
|
|
|
}
|
|
|
|
|
2014-10-07 15:59:14 +04:00
|
|
|
static BlockAIOCB *inject_error(BlockDriverState *bs,
|
2014-10-07 15:59:15 +04:00
|
|
|
BlockCompletionFunc *cb, void *opaque, BlkdebugRule *rule)
|
2010-02-19 18:24:35 +03:00
|
|
|
{
|
|
|
|
BDRVBlkdebugState *s = bs->opaque;
|
2012-06-06 10:10:42 +04:00
|
|
|
int error = rule->options.inject.error;
|
2010-02-19 18:24:35 +03:00
|
|
|
struct BlkdebugAIOCB *acb;
|
|
|
|
QEMUBH *bh;
|
|
|
|
|
2012-06-06 10:10:42 +04:00
|
|
|
if (rule->options.inject.once) {
|
|
|
|
QSIMPLEQ_INIT(&s->active_rules);
|
2010-02-19 18:24:35 +03:00
|
|
|
}
|
|
|
|
|
2012-06-06 10:10:42 +04:00
|
|
|
if (rule->options.inject.immediately) {
|
2010-02-19 18:24:35 +03:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2012-10-31 19:34:37 +04:00
|
|
|
acb = qemu_aio_get(&blkdebug_aiocb_info, bs, cb, opaque);
|
2010-02-19 18:24:35 +03:00
|
|
|
acb->ret = -error;
|
|
|
|
|
2014-05-08 18:34:38 +04:00
|
|
|
bh = aio_bh_new(bdrv_get_aio_context(bs), error_callback_bh, acb);
|
2010-02-19 18:24:35 +03:00
|
|
|
acb->bh = bh;
|
|
|
|
qemu_bh_schedule(bh);
|
|
|
|
|
2010-05-05 13:44:39 +04:00
|
|
|
return &acb->common;
|
2010-02-19 18:24:35 +03:00
|
|
|
}
|
|
|
|
|
2014-10-07 15:59:14 +04:00
|
|
|
static BlockAIOCB *blkdebug_aio_readv(BlockDriverState *bs,
|
2010-02-18 19:48:12 +03:00
|
|
|
int64_t sector_num, QEMUIOVector *qiov, int nb_sectors,
|
2014-10-07 15:59:15 +04:00
|
|
|
BlockCompletionFunc *cb, void *opaque)
|
2010-02-18 19:48:12 +03:00
|
|
|
{
|
|
|
|
BDRVBlkdebugState *s = bs->opaque;
|
2012-06-06 10:10:43 +04:00
|
|
|
BlkdebugRule *rule = NULL;
|
|
|
|
|
|
|
|
QSIMPLEQ_FOREACH(rule, &s->active_rules, active_next) {
|
|
|
|
if (rule->options.inject.sector == -1 ||
|
|
|
|
(rule->options.inject.sector >= sector_num &&
|
|
|
|
rule->options.inject.sector < sector_num + nb_sectors)) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2010-02-19 18:24:35 +03:00
|
|
|
|
2012-06-06 10:10:42 +04:00
|
|
|
if (rule && rule->options.inject.error) {
|
|
|
|
return inject_error(bs, cb, opaque, rule);
|
2010-02-19 18:24:35 +03:00
|
|
|
}
|
|
|
|
|
2012-06-06 10:10:40 +04:00
|
|
|
return bdrv_aio_readv(bs->file, sector_num, qiov, nb_sectors, cb, opaque);
|
2010-02-18 19:48:12 +03:00
|
|
|
}
|
|
|
|
|
2014-10-07 15:59:14 +04:00
|
|
|
static BlockAIOCB *blkdebug_aio_writev(BlockDriverState *bs,
|
2010-02-18 19:48:12 +03:00
|
|
|
int64_t sector_num, QEMUIOVector *qiov, int nb_sectors,
|
2014-10-07 15:59:15 +04:00
|
|
|
BlockCompletionFunc *cb, void *opaque)
|
2010-02-18 19:48:12 +03:00
|
|
|
{
|
|
|
|
BDRVBlkdebugState *s = bs->opaque;
|
2012-06-06 10:10:43 +04:00
|
|
|
BlkdebugRule *rule = NULL;
|
|
|
|
|
|
|
|
QSIMPLEQ_FOREACH(rule, &s->active_rules, active_next) {
|
|
|
|
if (rule->options.inject.sector == -1 ||
|
|
|
|
(rule->options.inject.sector >= sector_num &&
|
|
|
|
rule->options.inject.sector < sector_num + nb_sectors)) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2010-02-19 18:24:35 +03:00
|
|
|
|
2012-06-06 10:10:42 +04:00
|
|
|
if (rule && rule->options.inject.error) {
|
|
|
|
return inject_error(bs, cb, opaque, rule);
|
2010-02-19 18:24:35 +03:00
|
|
|
}
|
|
|
|
|
2012-06-06 10:10:40 +04:00
|
|
|
return bdrv_aio_writev(bs->file, sector_num, qiov, nb_sectors, cb, opaque);
|
2010-02-18 19:48:12 +03:00
|
|
|
}
|
|
|
|
|
2014-10-07 15:59:14 +04:00
|
|
|
static BlockAIOCB *blkdebug_aio_flush(BlockDriverState *bs,
|
2014-10-07 15:59:15 +04:00
|
|
|
BlockCompletionFunc *cb, void *opaque)
|
2014-08-05 01:11:02 +04:00
|
|
|
{
|
|
|
|
BDRVBlkdebugState *s = bs->opaque;
|
|
|
|
BlkdebugRule *rule = NULL;
|
|
|
|
|
|
|
|
QSIMPLEQ_FOREACH(rule, &s->active_rules, active_next) {
|
|
|
|
if (rule->options.inject.sector == -1) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (rule && rule->options.inject.error) {
|
|
|
|
return inject_error(bs, cb, opaque, rule);
|
|
|
|
}
|
|
|
|
|
|
|
|
return bdrv_aio_flush(bs->file, cb, opaque);
|
|
|
|
}
|
|
|
|
|
2012-12-06 17:32:57 +04:00
|
|
|
|
2010-02-18 19:48:12 +03:00
|
|
|
static void blkdebug_close(BlockDriverState *bs)
|
|
|
|
{
|
|
|
|
BDRVBlkdebugState *s = bs->opaque;
|
2010-03-15 19:27:00 +03:00
|
|
|
BlkdebugRule *rule, *next;
|
|
|
|
int i;
|
|
|
|
|
|
|
|
for (i = 0; i < BLKDBG_EVENT_MAX; i++) {
|
|
|
|
QLIST_FOREACH_SAFE(rule, &s->rules[i], next, next) {
|
2012-12-06 17:32:56 +04:00
|
|
|
remove_rule(rule);
|
2010-03-15 19:27:00 +03:00
|
|
|
}
|
|
|
|
}
|
2010-02-18 19:48:12 +03:00
|
|
|
}
|
|
|
|
|
2012-12-06 17:32:57 +04:00
|
|
|
static void suspend_request(BlockDriverState *bs, BlkdebugRule *rule)
|
|
|
|
{
|
|
|
|
BDRVBlkdebugState *s = bs->opaque;
|
|
|
|
BlkdebugSuspendedReq r;
|
|
|
|
|
|
|
|
r = (BlkdebugSuspendedReq) {
|
|
|
|
.co = qemu_coroutine_self(),
|
|
|
|
.tag = g_strdup(rule->options.suspend.tag),
|
|
|
|
};
|
|
|
|
|
|
|
|
remove_rule(rule);
|
|
|
|
QLIST_INSERT_HEAD(&s->suspended_reqs, &r, next);
|
|
|
|
|
|
|
|
printf("blkdebug: Suspended request '%s'\n", r.tag);
|
|
|
|
qemu_coroutine_yield();
|
|
|
|
printf("blkdebug: Resuming request '%s'\n", r.tag);
|
|
|
|
|
|
|
|
QLIST_REMOVE(&r, next);
|
|
|
|
g_free(r.tag);
|
|
|
|
}
|
|
|
|
|
2012-06-06 10:10:42 +04:00
|
|
|
static bool process_rule(BlockDriverState *bs, struct BlkdebugRule *rule,
|
2012-09-28 19:23:00 +04:00
|
|
|
bool injected)
|
2010-03-15 19:27:00 +03:00
|
|
|
{
|
|
|
|
BDRVBlkdebugState *s = bs->opaque;
|
|
|
|
|
|
|
|
/* Only process rules for the current state */
|
2012-09-28 19:23:00 +04:00
|
|
|
if (rule->state && rule->state != s->state) {
|
2012-06-06 10:10:42 +04:00
|
|
|
return injected;
|
2010-03-15 19:27:00 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Take the action */
|
|
|
|
switch (rule->action) {
|
|
|
|
case ACTION_INJECT_ERROR:
|
2012-06-06 10:10:42 +04:00
|
|
|
if (!injected) {
|
|
|
|
QSIMPLEQ_INIT(&s->active_rules);
|
|
|
|
injected = true;
|
|
|
|
}
|
|
|
|
QSIMPLEQ_INSERT_HEAD(&s->active_rules, rule, active_next);
|
2010-03-15 19:27:00 +03:00
|
|
|
break;
|
|
|
|
|
|
|
|
case ACTION_SET_STATE:
|
2012-09-28 19:23:00 +04:00
|
|
|
s->new_state = rule->options.set_state.new_state;
|
2010-03-15 19:27:00 +03:00
|
|
|
break;
|
2012-12-06 17:32:57 +04:00
|
|
|
|
|
|
|
case ACTION_SUSPEND:
|
|
|
|
suspend_request(bs, rule);
|
|
|
|
break;
|
2010-03-15 19:27:00 +03:00
|
|
|
}
|
2012-06-06 10:10:42 +04:00
|
|
|
return injected;
|
2010-03-15 19:27:00 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
static void blkdebug_debug_event(BlockDriverState *bs, BlkDebugEvent event)
|
|
|
|
{
|
|
|
|
BDRVBlkdebugState *s = bs->opaque;
|
2012-12-06 17:32:57 +04:00
|
|
|
struct BlkdebugRule *rule, *next;
|
2012-06-06 10:10:42 +04:00
|
|
|
bool injected;
|
2010-03-15 19:27:00 +03:00
|
|
|
|
2010-09-18 09:53:15 +04:00
|
|
|
assert((int)event >= 0 && event < BLKDBG_EVENT_MAX);
|
2010-03-15 19:27:00 +03:00
|
|
|
|
2012-06-06 10:10:42 +04:00
|
|
|
injected = false;
|
2012-09-28 19:23:00 +04:00
|
|
|
s->new_state = s->state;
|
2012-12-06 17:32:57 +04:00
|
|
|
QLIST_FOREACH_SAFE(rule, &s->rules[event], next, next) {
|
2012-09-28 19:23:00 +04:00
|
|
|
injected = process_rule(bs, rule, injected);
|
2010-03-15 19:27:00 +03:00
|
|
|
}
|
2012-09-28 19:23:00 +04:00
|
|
|
s->state = s->new_state;
|
2010-03-15 19:27:00 +03:00
|
|
|
}
|
|
|
|
|
2012-12-06 17:32:57 +04:00
|
|
|
static int blkdebug_debug_breakpoint(BlockDriverState *bs, const char *event,
|
|
|
|
const char *tag)
|
|
|
|
{
|
|
|
|
BDRVBlkdebugState *s = bs->opaque;
|
|
|
|
struct BlkdebugRule *rule;
|
|
|
|
BlkDebugEvent blkdebug_event;
|
|
|
|
|
|
|
|
if (get_event_by_name(event, &blkdebug_event) < 0) {
|
|
|
|
return -ENOENT;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
rule = g_malloc(sizeof(*rule));
|
|
|
|
*rule = (struct BlkdebugRule) {
|
|
|
|
.event = blkdebug_event,
|
|
|
|
.action = ACTION_SUSPEND,
|
|
|
|
.state = 0,
|
|
|
|
.options.suspend.tag = g_strdup(tag),
|
|
|
|
};
|
|
|
|
|
|
|
|
QLIST_INSERT_HEAD(&s->rules[blkdebug_event], rule, next);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int blkdebug_debug_resume(BlockDriverState *bs, const char *tag)
|
|
|
|
{
|
|
|
|
BDRVBlkdebugState *s = bs->opaque;
|
2013-12-13 11:25:12 +04:00
|
|
|
BlkdebugSuspendedReq *r, *next;
|
2012-12-06 17:32:57 +04:00
|
|
|
|
2013-12-13 11:25:12 +04:00
|
|
|
QLIST_FOREACH_SAFE(r, &s->suspended_reqs, next, next) {
|
2012-12-06 17:32:57 +04:00
|
|
|
if (!strcmp(r->tag, tag)) {
|
|
|
|
qemu_coroutine_enter(r->co, NULL);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return -ENOENT;
|
|
|
|
}
|
|
|
|
|
2013-11-20 06:01:54 +04:00
|
|
|
static int blkdebug_debug_remove_breakpoint(BlockDriverState *bs,
|
|
|
|
const char *tag)
|
|
|
|
{
|
|
|
|
BDRVBlkdebugState *s = bs->opaque;
|
2013-12-13 11:25:12 +04:00
|
|
|
BlkdebugSuspendedReq *r, *r_next;
|
2013-11-20 06:01:54 +04:00
|
|
|
BlkdebugRule *rule, *next;
|
|
|
|
int i, ret = -ENOENT;
|
|
|
|
|
|
|
|
for (i = 0; i < BLKDBG_EVENT_MAX; i++) {
|
|
|
|
QLIST_FOREACH_SAFE(rule, &s->rules[i], next, next) {
|
|
|
|
if (rule->action == ACTION_SUSPEND &&
|
|
|
|
!strcmp(rule->options.suspend.tag, tag)) {
|
|
|
|
remove_rule(rule);
|
|
|
|
ret = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2013-12-13 11:25:12 +04:00
|
|
|
QLIST_FOREACH_SAFE(r, &s->suspended_reqs, next, r_next) {
|
2013-11-20 06:01:54 +04:00
|
|
|
if (!strcmp(r->tag, tag)) {
|
|
|
|
qemu_coroutine_enter(r->co, NULL);
|
|
|
|
ret = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return ret;
|
|
|
|
}
|
2012-12-06 17:32:57 +04:00
|
|
|
|
|
|
|
static bool blkdebug_debug_is_suspended(BlockDriverState *bs, const char *tag)
|
|
|
|
{
|
|
|
|
BDRVBlkdebugState *s = bs->opaque;
|
|
|
|
BlkdebugSuspendedReq *r;
|
|
|
|
|
|
|
|
QLIST_FOREACH(r, &s->suspended_reqs, next) {
|
|
|
|
if (!strcmp(r->tag, tag)) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2012-06-06 10:10:41 +04:00
|
|
|
static int64_t blkdebug_getlength(BlockDriverState *bs)
|
|
|
|
{
|
|
|
|
return bdrv_getlength(bs->file);
|
|
|
|
}
|
|
|
|
|
2014-07-18 22:24:57 +04:00
|
|
|
static void blkdebug_refresh_filename(BlockDriverState *bs)
|
|
|
|
{
|
|
|
|
BDRVBlkdebugState *s = bs->opaque;
|
|
|
|
struct BlkdebugRule *rule;
|
|
|
|
QDict *opts;
|
|
|
|
QList *inject_error_list = NULL, *set_state_list = NULL;
|
|
|
|
QList *suspend_list = NULL;
|
|
|
|
int event;
|
|
|
|
|
|
|
|
if (!bs->file->full_open_options) {
|
|
|
|
/* The config file cannot be recreated, so creating a plain filename
|
|
|
|
* is impossible */
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
opts = qdict_new();
|
|
|
|
qdict_put_obj(opts, "driver", QOBJECT(qstring_from_str("blkdebug")));
|
|
|
|
|
|
|
|
QINCREF(bs->file->full_open_options);
|
|
|
|
qdict_put_obj(opts, "image", QOBJECT(bs->file->full_open_options));
|
|
|
|
|
|
|
|
for (event = 0; event < BLKDBG_EVENT_MAX; event++) {
|
|
|
|
QLIST_FOREACH(rule, &s->rules[event], next) {
|
|
|
|
if (rule->action == ACTION_INJECT_ERROR) {
|
|
|
|
QDict *inject_error = qdict_new();
|
|
|
|
|
|
|
|
qdict_put_obj(inject_error, "event", QOBJECT(qstring_from_str(
|
|
|
|
BlkdebugEvent_lookup[rule->event])));
|
|
|
|
qdict_put_obj(inject_error, "state",
|
|
|
|
QOBJECT(qint_from_int(rule->state)));
|
|
|
|
qdict_put_obj(inject_error, "errno", QOBJECT(qint_from_int(
|
|
|
|
rule->options.inject.error)));
|
|
|
|
qdict_put_obj(inject_error, "sector", QOBJECT(qint_from_int(
|
|
|
|
rule->options.inject.sector)));
|
|
|
|
qdict_put_obj(inject_error, "once", QOBJECT(qbool_from_int(
|
|
|
|
rule->options.inject.once)));
|
|
|
|
qdict_put_obj(inject_error, "immediately",
|
|
|
|
QOBJECT(qbool_from_int(
|
|
|
|
rule->options.inject.immediately)));
|
|
|
|
|
|
|
|
if (!inject_error_list) {
|
|
|
|
inject_error_list = qlist_new();
|
|
|
|
}
|
|
|
|
|
|
|
|
qlist_append_obj(inject_error_list, QOBJECT(inject_error));
|
|
|
|
} else if (rule->action == ACTION_SET_STATE) {
|
|
|
|
QDict *set_state = qdict_new();
|
|
|
|
|
|
|
|
qdict_put_obj(set_state, "event", QOBJECT(qstring_from_str(
|
|
|
|
BlkdebugEvent_lookup[rule->event])));
|
|
|
|
qdict_put_obj(set_state, "state",
|
|
|
|
QOBJECT(qint_from_int(rule->state)));
|
|
|
|
qdict_put_obj(set_state, "new_state", QOBJECT(qint_from_int(
|
|
|
|
rule->options.set_state.new_state)));
|
|
|
|
|
|
|
|
if (!set_state_list) {
|
|
|
|
set_state_list = qlist_new();
|
|
|
|
}
|
|
|
|
|
|
|
|
qlist_append_obj(set_state_list, QOBJECT(set_state));
|
|
|
|
} else if (rule->action == ACTION_SUSPEND) {
|
|
|
|
QDict *suspend = qdict_new();
|
|
|
|
|
|
|
|
qdict_put_obj(suspend, "event", QOBJECT(qstring_from_str(
|
|
|
|
BlkdebugEvent_lookup[rule->event])));
|
|
|
|
qdict_put_obj(suspend, "state",
|
|
|
|
QOBJECT(qint_from_int(rule->state)));
|
|
|
|
qdict_put_obj(suspend, "tag", QOBJECT(qstring_from_str(
|
|
|
|
rule->options.suspend.tag)));
|
|
|
|
|
|
|
|
if (!suspend_list) {
|
|
|
|
suspend_list = qlist_new();
|
|
|
|
}
|
|
|
|
|
|
|
|
qlist_append_obj(suspend_list, QOBJECT(suspend));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (inject_error_list) {
|
|
|
|
qdict_put_obj(opts, "inject-error", QOBJECT(inject_error_list));
|
|
|
|
}
|
|
|
|
if (set_state_list) {
|
|
|
|
qdict_put_obj(opts, "set-state", QOBJECT(set_state_list));
|
|
|
|
}
|
|
|
|
if (suspend_list) {
|
|
|
|
qdict_put_obj(opts, "suspend", QOBJECT(suspend_list));
|
|
|
|
}
|
|
|
|
|
|
|
|
bs->full_open_options = opts;
|
|
|
|
}
|
|
|
|
|
2010-02-18 19:48:12 +03:00
|
|
|
static BlockDriver bdrv_blkdebug = {
|
2013-04-10 15:37:33 +04:00
|
|
|
.format_name = "blkdebug",
|
|
|
|
.protocol_name = "blkdebug",
|
|
|
|
.instance_size = sizeof(BDRVBlkdebugState),
|
2010-02-18 19:48:12 +03:00
|
|
|
|
2013-04-10 15:37:33 +04:00
|
|
|
.bdrv_parse_filename = blkdebug_parse_filename,
|
|
|
|
.bdrv_file_open = blkdebug_open,
|
|
|
|
.bdrv_close = blkdebug_close,
|
|
|
|
.bdrv_getlength = blkdebug_getlength,
|
2014-07-18 22:24:57 +04:00
|
|
|
.bdrv_refresh_filename = blkdebug_refresh_filename,
|
2010-02-18 19:48:12 +03:00
|
|
|
|
2013-04-10 15:37:33 +04:00
|
|
|
.bdrv_aio_readv = blkdebug_aio_readv,
|
|
|
|
.bdrv_aio_writev = blkdebug_aio_writev,
|
2014-08-05 01:11:02 +04:00
|
|
|
.bdrv_aio_flush = blkdebug_aio_flush,
|
2010-03-15 19:27:00 +03:00
|
|
|
|
2012-12-06 17:32:57 +04:00
|
|
|
.bdrv_debug_event = blkdebug_debug_event,
|
|
|
|
.bdrv_debug_breakpoint = blkdebug_debug_breakpoint,
|
2013-11-20 06:01:54 +04:00
|
|
|
.bdrv_debug_remove_breakpoint
|
|
|
|
= blkdebug_debug_remove_breakpoint,
|
2012-12-06 17:32:57 +04:00
|
|
|
.bdrv_debug_resume = blkdebug_debug_resume,
|
|
|
|
.bdrv_debug_is_suspended = blkdebug_debug_is_suspended,
|
2010-02-18 19:48:12 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
static void bdrv_blkdebug_init(void)
|
|
|
|
{
|
|
|
|
bdrv_register(&bdrv_blkdebug);
|
|
|
|
}
|
|
|
|
|
|
|
|
block_init(bdrv_blkdebug_init);
|