2 * Block protocol for I/O error injection
4 * Copyright (c) 2010 Kevin Wolf <kwolf@redhat.com>
6 * Permission is hereby granted, free of charge, to any person obtaining a copy
7 * of this software and associated documentation files (the "Software"), to deal
8 * in the Software without restriction, including without limitation the rights
9 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10 * copies of the Software, and to permit persons to whom the Software is
11 * furnished to do so, subject to the following conditions:
13 * The above copyright notice and this permission notice shall be included in
14 * all copies or substantial portions of the Software.
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
19 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
25 #include "qemu-common.h"
26 #include "qemu/config-file.h"
27 #include "block/block_int.h"
28 #include "qemu/module.h"
29 #include "qapi/qmp/qbool.h"
30 #include "qapi/qmp/qdict.h"
31 #include "qapi/qmp/qint.h"
32 #include "qapi/qmp/qstring.h"
34 typedef struct BDRVBlkdebugState
{
38 QLIST_HEAD(, BlkdebugRule
) rules
[BLKDBG_EVENT_MAX
];
39 QSIMPLEQ_HEAD(, BlkdebugRule
) active_rules
;
40 QLIST_HEAD(, BlkdebugSuspendedReq
) suspended_reqs
;
43 typedef struct BlkdebugAIOCB
{
44 BlockDriverAIOCB common
;
49 typedef struct BlkdebugSuspendedReq
{
52 QLIST_ENTRY(BlkdebugSuspendedReq
) next
;
53 } BlkdebugSuspendedReq
;
55 static void blkdebug_aio_cancel(BlockDriverAIOCB
*blockacb
);
57 static const AIOCBInfo blkdebug_aiocb_info
= {
58 .aiocb_size
= sizeof(BlkdebugAIOCB
),
59 .cancel
= blkdebug_aio_cancel
,
68 typedef struct BlkdebugRule
{
86 QLIST_ENTRY(BlkdebugRule
) next
;
87 QSIMPLEQ_ENTRY(BlkdebugRule
) active_next
;
90 static QemuOptsList inject_error_opts
= {
91 .name
= "inject-error",
92 .head
= QTAILQ_HEAD_INITIALIZER(inject_error_opts
.head
),
96 .type
= QEMU_OPT_STRING
,
100 .type
= QEMU_OPT_NUMBER
,
104 .type
= QEMU_OPT_NUMBER
,
108 .type
= QEMU_OPT_NUMBER
,
112 .type
= QEMU_OPT_BOOL
,
115 .name
= "immediately",
116 .type
= QEMU_OPT_BOOL
,
118 { /* end of list */ }
122 static QemuOptsList set_state_opts
= {
124 .head
= QTAILQ_HEAD_INITIALIZER(set_state_opts
.head
),
128 .type
= QEMU_OPT_STRING
,
132 .type
= QEMU_OPT_NUMBER
,
136 .type
= QEMU_OPT_NUMBER
,
138 { /* end of list */ }
142 static QemuOptsList
*config_groups
[] = {
148 static const char *event_names
[BLKDBG_EVENT_MAX
] = {
149 [BLKDBG_L1_UPDATE
] = "l1_update",
150 [BLKDBG_L1_GROW_ALLOC_TABLE
] = "l1_grow.alloc_table",
151 [BLKDBG_L1_GROW_WRITE_TABLE
] = "l1_grow.write_table",
152 [BLKDBG_L1_GROW_ACTIVATE_TABLE
] = "l1_grow.activate_table",
154 [BLKDBG_L2_LOAD
] = "l2_load",
155 [BLKDBG_L2_UPDATE
] = "l2_update",
156 [BLKDBG_L2_UPDATE_COMPRESSED
] = "l2_update_compressed",
157 [BLKDBG_L2_ALLOC_COW_READ
] = "l2_alloc.cow_read",
158 [BLKDBG_L2_ALLOC_WRITE
] = "l2_alloc.write",
160 [BLKDBG_READ_AIO
] = "read_aio",
161 [BLKDBG_READ_BACKING_AIO
] = "read_backing_aio",
162 [BLKDBG_READ_COMPRESSED
] = "read_compressed",
164 [BLKDBG_WRITE_AIO
] = "write_aio",
165 [BLKDBG_WRITE_COMPRESSED
] = "write_compressed",
167 [BLKDBG_VMSTATE_LOAD
] = "vmstate_load",
168 [BLKDBG_VMSTATE_SAVE
] = "vmstate_save",
170 [BLKDBG_COW_READ
] = "cow_read",
171 [BLKDBG_COW_WRITE
] = "cow_write",
173 [BLKDBG_REFTABLE_LOAD
] = "reftable_load",
174 [BLKDBG_REFTABLE_GROW
] = "reftable_grow",
175 [BLKDBG_REFTABLE_UPDATE
] = "reftable_update",
177 [BLKDBG_REFBLOCK_LOAD
] = "refblock_load",
178 [BLKDBG_REFBLOCK_UPDATE
] = "refblock_update",
179 [BLKDBG_REFBLOCK_UPDATE_PART
] = "refblock_update_part",
180 [BLKDBG_REFBLOCK_ALLOC
] = "refblock_alloc",
181 [BLKDBG_REFBLOCK_ALLOC_HOOKUP
] = "refblock_alloc.hookup",
182 [BLKDBG_REFBLOCK_ALLOC_WRITE
] = "refblock_alloc.write",
183 [BLKDBG_REFBLOCK_ALLOC_WRITE_BLOCKS
] = "refblock_alloc.write_blocks",
184 [BLKDBG_REFBLOCK_ALLOC_WRITE_TABLE
] = "refblock_alloc.write_table",
185 [BLKDBG_REFBLOCK_ALLOC_SWITCH_TABLE
] = "refblock_alloc.switch_table",
187 [BLKDBG_CLUSTER_ALLOC
] = "cluster_alloc",
188 [BLKDBG_CLUSTER_ALLOC_BYTES
] = "cluster_alloc_bytes",
189 [BLKDBG_CLUSTER_FREE
] = "cluster_free",
191 [BLKDBG_FLUSH_TO_OS
] = "flush_to_os",
192 [BLKDBG_FLUSH_TO_DISK
] = "flush_to_disk",
194 [BLKDBG_PWRITEV_RMW_HEAD
] = "pwritev_rmw.head",
195 [BLKDBG_PWRITEV_RMW_AFTER_HEAD
] = "pwritev_rmw.after_head",
196 [BLKDBG_PWRITEV_RMW_TAIL
] = "pwritev_rmw.tail",
197 [BLKDBG_PWRITEV_RMW_AFTER_TAIL
] = "pwritev_rmw.after_tail",
198 [BLKDBG_PWRITEV
] = "pwritev",
199 [BLKDBG_PWRITEV_ZERO
] = "pwritev_zero",
200 [BLKDBG_PWRITEV_DONE
] = "pwritev_done",
203 static int get_event_by_name(const char *name
, BlkDebugEvent
*event
)
207 for (i
= 0; i
< BLKDBG_EVENT_MAX
; i
++) {
208 if (!strcmp(event_names
[i
], name
)) {
217 struct add_rule_data
{
218 BDRVBlkdebugState
*s
;
222 static int add_rule(QemuOpts
*opts
, void *opaque
)
224 struct add_rule_data
*d
= opaque
;
225 BDRVBlkdebugState
*s
= d
->s
;
226 const char* event_name
;
228 struct BlkdebugRule
*rule
;
230 /* Find the right event for the rule */
231 event_name
= qemu_opt_get(opts
, "event");
232 if (!event_name
|| get_event_by_name(event_name
, &event
) < 0) {
236 /* Set attributes common for all actions */
237 rule
= g_malloc0(sizeof(*rule
));
238 *rule
= (struct BlkdebugRule
) {
241 .state
= qemu_opt_get_number(opts
, "state", 0),
244 /* Parse action-specific options */
246 case ACTION_INJECT_ERROR
:
247 rule
->options
.inject
.error
= qemu_opt_get_number(opts
, "errno", EIO
);
248 rule
->options
.inject
.once
= qemu_opt_get_bool(opts
, "once", 0);
249 rule
->options
.inject
.immediately
=
250 qemu_opt_get_bool(opts
, "immediately", 0);
251 rule
->options
.inject
.sector
= qemu_opt_get_number(opts
, "sector", -1);
254 case ACTION_SET_STATE
:
255 rule
->options
.set_state
.new_state
=
256 qemu_opt_get_number(opts
, "new_state", 0);
260 rule
->options
.suspend
.tag
=
261 g_strdup(qemu_opt_get(opts
, "tag"));
266 QLIST_INSERT_HEAD(&s
->rules
[event
], rule
, next
);
271 static void remove_rule(BlkdebugRule
*rule
)
273 switch (rule
->action
) {
274 case ACTION_INJECT_ERROR
:
275 case ACTION_SET_STATE
:
278 g_free(rule
->options
.suspend
.tag
);
282 QLIST_REMOVE(rule
, next
);
286 static int read_config(BDRVBlkdebugState
*s
, const char *filename
,
287 QDict
*options
, Error
**errp
)
291 struct add_rule_data d
;
292 Error
*local_err
= NULL
;
295 f
= fopen(filename
, "r");
297 error_setg_errno(errp
, errno
, "Could not read blkdebug config file");
301 ret
= qemu_config_parse(f
, config_groups
, filename
);
303 error_setg(errp
, "Could not parse blkdebug config file");
309 qemu_config_parse_qdict(options
, config_groups
, &local_err
);
311 error_propagate(errp
, local_err
);
317 d
.action
= ACTION_INJECT_ERROR
;
318 qemu_opts_foreach(&inject_error_opts
, add_rule
, &d
, 0);
320 d
.action
= ACTION_SET_STATE
;
321 qemu_opts_foreach(&set_state_opts
, add_rule
, &d
, 0);
325 qemu_opts_reset(&inject_error_opts
);
326 qemu_opts_reset(&set_state_opts
);
333 /* Valid blkdebug filenames look like blkdebug:path/to/config:path/to/image */
334 static void blkdebug_parse_filename(const char *filename
, QDict
*options
,
339 /* Parse the blkdebug: prefix */
340 if (!strstart(filename
, "blkdebug:", &filename
)) {
341 /* There was no prefix; therefore, all options have to be already
342 present in the QDict (except for the filename) */
343 qdict_put(options
, "x-image", qstring_from_str(filename
));
347 /* Parse config file path */
348 c
= strchr(filename
, ':');
350 error_setg(errp
, "blkdebug requires both config file and image path");
355 QString
*config_path
;
356 config_path
= qstring_from_substr(filename
, 0, c
- filename
- 1);
357 qdict_put(options
, "config", config_path
);
360 /* TODO Allow multi-level nesting and set file.filename here */
362 qdict_put(options
, "x-image", qstring_from_str(filename
));
365 static QemuOptsList runtime_opts
= {
367 .head
= QTAILQ_HEAD_INITIALIZER(runtime_opts
.head
),
371 .type
= QEMU_OPT_STRING
,
372 .help
= "Path to the configuration file",
376 .type
= QEMU_OPT_STRING
,
377 .help
= "[internal use only, will be removed]",
381 .type
= QEMU_OPT_SIZE
,
382 .help
= "Required alignment in bytes",
384 { /* end of list */ }
388 static int blkdebug_open(BlockDriverState
*bs
, QDict
*options
, int flags
,
391 BDRVBlkdebugState
*s
= bs
->opaque
;
393 Error
*local_err
= NULL
;
398 opts
= qemu_opts_create(&runtime_opts
, NULL
, 0, &error_abort
);
399 qemu_opts_absorb_qdict(opts
, options
, &local_err
);
401 error_propagate(errp
, local_err
);
406 /* Read rules from config file or command line options */
407 config
= qemu_opt_get(opts
, "config");
408 ret
= read_config(s
, config
, options
, errp
);
413 /* Set initial state */
416 /* Open the backing file */
417 assert(bs
->file
== NULL
);
418 ret
= bdrv_open_image(&bs
->file
, qemu_opt_get(opts
, "x-image"), options
, "image",
419 flags
| BDRV_O_PROTOCOL
, false, &local_err
);
421 error_propagate(errp
, local_err
);
425 /* Set request alignment */
426 align
= qemu_opt_get_size(opts
, "align", bs
->request_alignment
);
427 if (align
> 0 && align
< INT_MAX
&& !(align
& (align
- 1))) {
428 bs
->request_alignment
= align
;
430 error_setg(errp
, "Invalid alignment");
439 bdrv_unref(bs
->file
);
445 static void error_callback_bh(void *opaque
)
447 struct BlkdebugAIOCB
*acb
= opaque
;
448 qemu_bh_delete(acb
->bh
);
449 acb
->common
.cb(acb
->common
.opaque
, acb
->ret
);
450 qemu_aio_release(acb
);
453 static void blkdebug_aio_cancel(BlockDriverAIOCB
*blockacb
)
455 BlkdebugAIOCB
*acb
= container_of(blockacb
, BlkdebugAIOCB
, common
);
456 qemu_aio_release(acb
);
459 static BlockDriverAIOCB
*inject_error(BlockDriverState
*bs
,
460 BlockDriverCompletionFunc
*cb
, void *opaque
, BlkdebugRule
*rule
)
462 BDRVBlkdebugState
*s
= bs
->opaque
;
463 int error
= rule
->options
.inject
.error
;
464 struct BlkdebugAIOCB
*acb
;
467 if (rule
->options
.inject
.once
) {
468 QSIMPLEQ_INIT(&s
->active_rules
);
471 if (rule
->options
.inject
.immediately
) {
475 acb
= qemu_aio_get(&blkdebug_aiocb_info
, bs
, cb
, opaque
);
478 bh
= aio_bh_new(bdrv_get_aio_context(bs
), error_callback_bh
, acb
);
480 qemu_bh_schedule(bh
);
485 static BlockDriverAIOCB
*blkdebug_aio_readv(BlockDriverState
*bs
,
486 int64_t sector_num
, QEMUIOVector
*qiov
, int nb_sectors
,
487 BlockDriverCompletionFunc
*cb
, void *opaque
)
489 BDRVBlkdebugState
*s
= bs
->opaque
;
490 BlkdebugRule
*rule
= NULL
;
492 QSIMPLEQ_FOREACH(rule
, &s
->active_rules
, active_next
) {
493 if (rule
->options
.inject
.sector
== -1 ||
494 (rule
->options
.inject
.sector
>= sector_num
&&
495 rule
->options
.inject
.sector
< sector_num
+ nb_sectors
)) {
500 if (rule
&& rule
->options
.inject
.error
) {
501 return inject_error(bs
, cb
, opaque
, rule
);
504 return bdrv_aio_readv(bs
->file
, sector_num
, qiov
, nb_sectors
, cb
, opaque
);
507 static BlockDriverAIOCB
*blkdebug_aio_writev(BlockDriverState
*bs
,
508 int64_t sector_num
, QEMUIOVector
*qiov
, int nb_sectors
,
509 BlockDriverCompletionFunc
*cb
, void *opaque
)
511 BDRVBlkdebugState
*s
= bs
->opaque
;
512 BlkdebugRule
*rule
= NULL
;
514 QSIMPLEQ_FOREACH(rule
, &s
->active_rules
, active_next
) {
515 if (rule
->options
.inject
.sector
== -1 ||
516 (rule
->options
.inject
.sector
>= sector_num
&&
517 rule
->options
.inject
.sector
< sector_num
+ nb_sectors
)) {
522 if (rule
&& rule
->options
.inject
.error
) {
523 return inject_error(bs
, cb
, opaque
, rule
);
526 return bdrv_aio_writev(bs
->file
, sector_num
, qiov
, nb_sectors
, cb
, opaque
);
529 static BlockDriverAIOCB
*blkdebug_aio_flush(BlockDriverState
*bs
,
530 BlockDriverCompletionFunc
*cb
, void *opaque
)
532 BDRVBlkdebugState
*s
= bs
->opaque
;
533 BlkdebugRule
*rule
= NULL
;
535 QSIMPLEQ_FOREACH(rule
, &s
->active_rules
, active_next
) {
536 if (rule
->options
.inject
.sector
== -1) {
541 if (rule
&& rule
->options
.inject
.error
) {
542 return inject_error(bs
, cb
, opaque
, rule
);
545 return bdrv_aio_flush(bs
->file
, cb
, opaque
);
549 static void blkdebug_close(BlockDriverState
*bs
)
551 BDRVBlkdebugState
*s
= bs
->opaque
;
552 BlkdebugRule
*rule
, *next
;
555 for (i
= 0; i
< BLKDBG_EVENT_MAX
; i
++) {
556 QLIST_FOREACH_SAFE(rule
, &s
->rules
[i
], next
, next
) {
562 static void suspend_request(BlockDriverState
*bs
, BlkdebugRule
*rule
)
564 BDRVBlkdebugState
*s
= bs
->opaque
;
565 BlkdebugSuspendedReq r
;
567 r
= (BlkdebugSuspendedReq
) {
568 .co
= qemu_coroutine_self(),
569 .tag
= g_strdup(rule
->options
.suspend
.tag
),
573 QLIST_INSERT_HEAD(&s
->suspended_reqs
, &r
, next
);
575 printf("blkdebug: Suspended request '%s'\n", r
.tag
);
576 qemu_coroutine_yield();
577 printf("blkdebug: Resuming request '%s'\n", r
.tag
);
579 QLIST_REMOVE(&r
, next
);
583 static bool process_rule(BlockDriverState
*bs
, struct BlkdebugRule
*rule
,
586 BDRVBlkdebugState
*s
= bs
->opaque
;
588 /* Only process rules for the current state */
589 if (rule
->state
&& rule
->state
!= s
->state
) {
593 /* Take the action */
594 switch (rule
->action
) {
595 case ACTION_INJECT_ERROR
:
597 QSIMPLEQ_INIT(&s
->active_rules
);
600 QSIMPLEQ_INSERT_HEAD(&s
->active_rules
, rule
, active_next
);
603 case ACTION_SET_STATE
:
604 s
->new_state
= rule
->options
.set_state
.new_state
;
608 suspend_request(bs
, rule
);
614 static void blkdebug_debug_event(BlockDriverState
*bs
, BlkDebugEvent event
)
616 BDRVBlkdebugState
*s
= bs
->opaque
;
617 struct BlkdebugRule
*rule
, *next
;
620 assert((int)event
>= 0 && event
< BLKDBG_EVENT_MAX
);
623 s
->new_state
= s
->state
;
624 QLIST_FOREACH_SAFE(rule
, &s
->rules
[event
], next
, next
) {
625 injected
= process_rule(bs
, rule
, injected
);
627 s
->state
= s
->new_state
;
630 static int blkdebug_debug_breakpoint(BlockDriverState
*bs
, const char *event
,
633 BDRVBlkdebugState
*s
= bs
->opaque
;
634 struct BlkdebugRule
*rule
;
635 BlkDebugEvent blkdebug_event
;
637 if (get_event_by_name(event
, &blkdebug_event
) < 0) {
642 rule
= g_malloc(sizeof(*rule
));
643 *rule
= (struct BlkdebugRule
) {
644 .event
= blkdebug_event
,
645 .action
= ACTION_SUSPEND
,
647 .options
.suspend
.tag
= g_strdup(tag
),
650 QLIST_INSERT_HEAD(&s
->rules
[blkdebug_event
], rule
, next
);
655 static int blkdebug_debug_resume(BlockDriverState
*bs
, const char *tag
)
657 BDRVBlkdebugState
*s
= bs
->opaque
;
658 BlkdebugSuspendedReq
*r
, *next
;
660 QLIST_FOREACH_SAFE(r
, &s
->suspended_reqs
, next
, next
) {
661 if (!strcmp(r
->tag
, tag
)) {
662 qemu_coroutine_enter(r
->co
, NULL
);
669 static int blkdebug_debug_remove_breakpoint(BlockDriverState
*bs
,
672 BDRVBlkdebugState
*s
= bs
->opaque
;
673 BlkdebugSuspendedReq
*r
, *r_next
;
674 BlkdebugRule
*rule
, *next
;
675 int i
, ret
= -ENOENT
;
677 for (i
= 0; i
< BLKDBG_EVENT_MAX
; i
++) {
678 QLIST_FOREACH_SAFE(rule
, &s
->rules
[i
], next
, next
) {
679 if (rule
->action
== ACTION_SUSPEND
&&
680 !strcmp(rule
->options
.suspend
.tag
, tag
)) {
686 QLIST_FOREACH_SAFE(r
, &s
->suspended_reqs
, next
, r_next
) {
687 if (!strcmp(r
->tag
, tag
)) {
688 qemu_coroutine_enter(r
->co
, NULL
);
695 static bool blkdebug_debug_is_suspended(BlockDriverState
*bs
, const char *tag
)
697 BDRVBlkdebugState
*s
= bs
->opaque
;
698 BlkdebugSuspendedReq
*r
;
700 QLIST_FOREACH(r
, &s
->suspended_reqs
, next
) {
701 if (!strcmp(r
->tag
, tag
)) {
708 static int64_t blkdebug_getlength(BlockDriverState
*bs
)
710 return bdrv_getlength(bs
->file
);
713 static void blkdebug_refresh_filename(BlockDriverState
*bs
)
715 BDRVBlkdebugState
*s
= bs
->opaque
;
716 struct BlkdebugRule
*rule
;
718 QList
*inject_error_list
= NULL
, *set_state_list
= NULL
;
719 QList
*suspend_list
= NULL
;
722 if (!bs
->file
->full_open_options
) {
723 /* The config file cannot be recreated, so creating a plain filename
729 qdict_put_obj(opts
, "driver", QOBJECT(qstring_from_str("blkdebug")));
731 QINCREF(bs
->file
->full_open_options
);
732 qdict_put_obj(opts
, "image", QOBJECT(bs
->file
->full_open_options
));
734 for (event
= 0; event
< BLKDBG_EVENT_MAX
; event
++) {
735 QLIST_FOREACH(rule
, &s
->rules
[event
], next
) {
736 if (rule
->action
== ACTION_INJECT_ERROR
) {
737 QDict
*inject_error
= qdict_new();
739 qdict_put_obj(inject_error
, "event", QOBJECT(qstring_from_str(
740 BlkdebugEvent_lookup
[rule
->event
])));
741 qdict_put_obj(inject_error
, "state",
742 QOBJECT(qint_from_int(rule
->state
)));
743 qdict_put_obj(inject_error
, "errno", QOBJECT(qint_from_int(
744 rule
->options
.inject
.error
)));
745 qdict_put_obj(inject_error
, "sector", QOBJECT(qint_from_int(
746 rule
->options
.inject
.sector
)));
747 qdict_put_obj(inject_error
, "once", QOBJECT(qbool_from_int(
748 rule
->options
.inject
.once
)));
749 qdict_put_obj(inject_error
, "immediately",
750 QOBJECT(qbool_from_int(
751 rule
->options
.inject
.immediately
)));
753 if (!inject_error_list
) {
754 inject_error_list
= qlist_new();
757 qlist_append_obj(inject_error_list
, QOBJECT(inject_error
));
758 } else if (rule
->action
== ACTION_SET_STATE
) {
759 QDict
*set_state
= qdict_new();
761 qdict_put_obj(set_state
, "event", QOBJECT(qstring_from_str(
762 BlkdebugEvent_lookup
[rule
->event
])));
763 qdict_put_obj(set_state
, "state",
764 QOBJECT(qint_from_int(rule
->state
)));
765 qdict_put_obj(set_state
, "new_state", QOBJECT(qint_from_int(
766 rule
->options
.set_state
.new_state
)));
768 if (!set_state_list
) {
769 set_state_list
= qlist_new();
772 qlist_append_obj(set_state_list
, QOBJECT(set_state
));
773 } else if (rule
->action
== ACTION_SUSPEND
) {
774 QDict
*suspend
= qdict_new();
776 qdict_put_obj(suspend
, "event", QOBJECT(qstring_from_str(
777 BlkdebugEvent_lookup
[rule
->event
])));
778 qdict_put_obj(suspend
, "state",
779 QOBJECT(qint_from_int(rule
->state
)));
780 qdict_put_obj(suspend
, "tag", QOBJECT(qstring_from_str(
781 rule
->options
.suspend
.tag
)));
784 suspend_list
= qlist_new();
787 qlist_append_obj(suspend_list
, QOBJECT(suspend
));
792 if (inject_error_list
) {
793 qdict_put_obj(opts
, "inject-error", QOBJECT(inject_error_list
));
795 if (set_state_list
) {
796 qdict_put_obj(opts
, "set-state", QOBJECT(set_state_list
));
799 qdict_put_obj(opts
, "suspend", QOBJECT(suspend_list
));
802 bs
->full_open_options
= opts
;
805 static BlockDriver bdrv_blkdebug
= {
806 .format_name
= "blkdebug",
807 .protocol_name
= "blkdebug",
808 .instance_size
= sizeof(BDRVBlkdebugState
),
810 .bdrv_parse_filename
= blkdebug_parse_filename
,
811 .bdrv_file_open
= blkdebug_open
,
812 .bdrv_close
= blkdebug_close
,
813 .bdrv_getlength
= blkdebug_getlength
,
814 .bdrv_refresh_filename
= blkdebug_refresh_filename
,
816 .bdrv_aio_readv
= blkdebug_aio_readv
,
817 .bdrv_aio_writev
= blkdebug_aio_writev
,
818 .bdrv_aio_flush
= blkdebug_aio_flush
,
820 .bdrv_debug_event
= blkdebug_debug_event
,
821 .bdrv_debug_breakpoint
= blkdebug_debug_breakpoint
,
822 .bdrv_debug_remove_breakpoint
823 = blkdebug_debug_remove_breakpoint
,
824 .bdrv_debug_resume
= blkdebug_debug_resume
,
825 .bdrv_debug_is_suspended
= blkdebug_debug_is_suspended
,
828 static void bdrv_blkdebug_init(void)
830 bdrv_register(&bdrv_blkdebug
);
833 block_init(bdrv_blkdebug_init
);