#include "block_int.h"
#include "module.h"
-#include <stdbool.h>
-
typedef struct BlkdebugVars {
int state;
} BlkdebugVars;
typedef struct BDRVBlkdebugState {
- BlockDriverState *hd;
BlkdebugVars vars;
QLIST_HEAD(list, BlkdebugRule) rules[BLKDBG_EVENT_MAX];
} BDRVBlkdebugState;
static QemuOptsList set_state_opts = {
.name = "set-state",
- .head = QTAILQ_HEAD_INITIALIZER(inject_error_opts.head),
+ .head = QTAILQ_HEAD_INITIALIZER(set_state_opts.head),
.desc = {
{
.name = "event",
};
static const char *event_names[BLKDBG_EVENT_MAX] = {
+ [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] = "read",
+ [BLKDBG_READ_AIO] = "read_aio",
+ [BLKDBG_READ_BACKING] = "read_backing",
+ [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",
+
+ [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",
};
static int get_event_by_name(const char *name, BlkDebugEvent *event)
ret = 0;
fail:
+ qemu_opts_reset(&inject_error_opts);
+ qemu_opts_reset(&set_state_opts);
fclose(f);
return ret;
}
}
filename = c + 1;
+ /* Set initial state */
+ s->vars.state = 1;
+
/* Open the backing file */
- ret = bdrv_file_open(&s->hd, filename, flags);
+ ret = bdrv_file_open(&bs->file, filename, flags);
if (ret < 0) {
return ret;
}
static void blkdebug_aio_cancel(BlockDriverAIOCB *blockacb)
{
- BlkdebugAIOCB *acb = (BlkdebugAIOCB*) blockacb;
+ BlkdebugAIOCB *acb = container_of(blockacb, BlkdebugAIOCB, common);
qemu_aio_release(acb);
}
acb->bh = bh;
qemu_bh_schedule(bh);
- return (BlockDriverAIOCB*) acb;
+ return &acb->common;
}
static BlockDriverAIOCB *blkdebug_aio_readv(BlockDriverState *bs,
}
BlockDriverAIOCB *acb =
- bdrv_aio_readv(s->hd, sector_num, qiov, nb_sectors, cb, opaque);
+ bdrv_aio_readv(bs->file, sector_num, qiov, nb_sectors, cb, opaque);
return acb;
}
}
BlockDriverAIOCB *acb =
- bdrv_aio_writev(s->hd, sector_num, qiov, nb_sectors, cb, opaque);
+ bdrv_aio_writev(bs->file, sector_num, qiov, nb_sectors, cb, opaque);
return acb;
}
qemu_free(rule);
}
}
-
- bdrv_delete(s->hd);
}
-static void blkdebug_flush(BlockDriverState *bs)
+static int blkdebug_flush(BlockDriverState *bs)
{
- BDRVBlkdebugState *s = bs->opaque;
- bdrv_flush(s->hd);
+ return bdrv_flush(bs->file);
}
static BlockDriverAIOCB *blkdebug_aio_flush(BlockDriverState *bs,
BlockDriverCompletionFunc *cb, void *opaque)
{
- BDRVBlkdebugState *s = bs->opaque;
- return bdrv_aio_flush(s->hd, cb, opaque);
+ return bdrv_aio_flush(bs->file, cb, opaque);
}
static void process_rule(BlockDriverState *bs, struct BlkdebugRule *rule,
struct BlkdebugRule *rule;
BlkdebugVars old_vars = s->vars;
- if (event < 0 || event >= BLKDBG_EVENT_MAX) {
- return;
- }
+ assert((int)event >= 0 && event < BLKDBG_EVENT_MAX);
QLIST_FOREACH(rule, &s->rules[event], next) {
process_rule(bs, rule, &old_vars);
.instance_size = sizeof(BDRVBlkdebugState),
- .bdrv_open = blkdebug_open,
+ .bdrv_file_open = blkdebug_open,
.bdrv_close = blkdebug_close,
.bdrv_flush = blkdebug_flush,