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
{
49 typedef struct BlkdebugSuspendedReq
{
52 QLIST_ENTRY(BlkdebugSuspendedReq
) next
;
53 } BlkdebugSuspendedReq
;
55 static const AIOCBInfo blkdebug_aiocb_info
= {
56 .aiocb_size
= sizeof(BlkdebugAIOCB
),
65 typedef struct BlkdebugRule
{
83 QLIST_ENTRY(BlkdebugRule
) next
;
84 QSIMPLEQ_ENTRY(BlkdebugRule
) active_next
;
87 static QemuOptsList inject_error_opts
= {
88 .name
= "inject-error",
89 .head
= QTAILQ_HEAD_INITIALIZER(inject_error_opts
.head
),
93 .type
= QEMU_OPT_STRING
,
97 .type
= QEMU_OPT_NUMBER
,
101 .type
= QEMU_OPT_NUMBER
,
105 .type
= QEMU_OPT_NUMBER
,
109 .type
= QEMU_OPT_BOOL
,
112 .name
= "immediately",
113 .type
= QEMU_OPT_BOOL
,
115 { /* end of list */ }
119 static QemuOptsList set_state_opts
= {
121 .head
= QTAILQ_HEAD_INITIALIZER(set_state_opts
.head
),
125 .type
= QEMU_OPT_STRING
,
129 .type
= QEMU_OPT_NUMBER
,
133 .type
= QEMU_OPT_NUMBER
,
135 { /* end of list */ }
139 static QemuOptsList
*config_groups
[] = {
145 static const char *event_names
[BLKDBG_EVENT_MAX
] = {
146 [BLKDBG_L1_UPDATE
] = "l1_update",
147 [BLKDBG_L1_GROW_ALLOC_TABLE
] = "l1_grow.alloc_table",
148 [BLKDBG_L1_GROW_WRITE_TABLE
] = "l1_grow.write_table",
149 [BLKDBG_L1_GROW_ACTIVATE_TABLE
] = "l1_grow.activate_table",
151 [BLKDBG_L2_LOAD
] = "l2_load",
152 [BLKDBG_L2_UPDATE
] = "l2_update",
153 [BLKDBG_L2_UPDATE_COMPRESSED
] = "l2_update_compressed",
154 [BLKDBG_L2_ALLOC_COW_READ
] = "l2_alloc.cow_read",
155 [BLKDBG_L2_ALLOC_WRITE
] = "l2_alloc.write",
157 [BLKDBG_READ_AIO
] = "read_aio",
158 [BLKDBG_READ_BACKING_AIO
] = "read_backing_aio",
159 [BLKDBG_READ_COMPRESSED
] = "read_compressed",
161 [BLKDBG_WRITE_AIO
] = "write_aio",
162 [BLKDBG_WRITE_COMPRESSED
] = "write_compressed",
164 [BLKDBG_VMSTATE_LOAD
] = "vmstate_load",
165 [BLKDBG_VMSTATE_SAVE
] = "vmstate_save",
167 [BLKDBG_COW_READ
] = "cow_read",
168 [BLKDBG_COW_WRITE
] = "cow_write",
170 [BLKDBG_REFTABLE_LOAD
] = "reftable_load",
171 [BLKDBG_REFTABLE_GROW
] = "reftable_grow",
172 [BLKDBG_REFTABLE_UPDATE
] = "reftable_update",
174 [BLKDBG_REFBLOCK_LOAD
] = "refblock_load",
175 [BLKDBG_REFBLOCK_UPDATE
] = "refblock_update",
176 [BLKDBG_REFBLOCK_UPDATE_PART
] = "refblock_update_part",
177 [BLKDBG_REFBLOCK_ALLOC
] = "refblock_alloc",
178 [BLKDBG_REFBLOCK_ALLOC_HOOKUP
] = "refblock_alloc.hookup",
179 [BLKDBG_REFBLOCK_ALLOC_WRITE
] = "refblock_alloc.write",
180 [BLKDBG_REFBLOCK_ALLOC_WRITE_BLOCKS
] = "refblock_alloc.write_blocks",
181 [BLKDBG_REFBLOCK_ALLOC_WRITE_TABLE
] = "refblock_alloc.write_table",
182 [BLKDBG_REFBLOCK_ALLOC_SWITCH_TABLE
] = "refblock_alloc.switch_table",
184 [BLKDBG_CLUSTER_ALLOC
] = "cluster_alloc",
185 [BLKDBG_CLUSTER_ALLOC_BYTES
] = "cluster_alloc_bytes",
186 [BLKDBG_CLUSTER_FREE
] = "cluster_free",
188 [BLKDBG_FLUSH_TO_OS
] = "flush_to_os",
189 [BLKDBG_FLUSH_TO_DISK
] = "flush_to_disk",
191 [BLKDBG_PWRITEV_RMW_HEAD
] = "pwritev_rmw.head",
192 [BLKDBG_PWRITEV_RMW_AFTER_HEAD
] = "pwritev_rmw.after_head",
193 [BLKDBG_PWRITEV_RMW_TAIL
] = "pwritev_rmw.tail",
194 [BLKDBG_PWRITEV_RMW_AFTER_TAIL
] = "pwritev_rmw.after_tail",
195 [BLKDBG_PWRITEV
] = "pwritev",
196 [BLKDBG_PWRITEV_ZERO
] = "pwritev_zero",
197 [BLKDBG_PWRITEV_DONE
] = "pwritev_done",
199 [BLKDBG_EMPTY_IMAGE_PREPARE
] = "empty_image_prepare",
202 static int get_event_by_name(const char *name
, BlkDebugEvent
*event
)
206 for (i
= 0; i
< BLKDBG_EVENT_MAX
; i
++) {
207 if (!strcmp(event_names
[i
], name
)) {
216 struct add_rule_data
{
217 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");
233 error_setg(d
->errp
, "Missing event name for rule");
235 } else if (get_event_by_name(event_name
, &event
) < 0) {
236 error_setg(d
->errp
, "Invalid event name \"%s\"", event_name
);
240 /* Set attributes common for all actions */
241 rule
= g_malloc0(sizeof(*rule
));
242 *rule
= (struct BlkdebugRule
) {
245 .state
= qemu_opt_get_number(opts
, "state", 0),
248 /* Parse action-specific options */
250 case ACTION_INJECT_ERROR
:
251 rule
->options
.inject
.error
= qemu_opt_get_number(opts
, "errno", EIO
);
252 rule
->options
.inject
.once
= qemu_opt_get_bool(opts
, "once", 0);
253 rule
->options
.inject
.immediately
=
254 qemu_opt_get_bool(opts
, "immediately", 0);
255 rule
->options
.inject
.sector
= qemu_opt_get_number(opts
, "sector", -1);
258 case ACTION_SET_STATE
:
259 rule
->options
.set_state
.new_state
=
260 qemu_opt_get_number(opts
, "new_state", 0);
264 rule
->options
.suspend
.tag
=
265 g_strdup(qemu_opt_get(opts
, "tag"));
270 QLIST_INSERT_HEAD(&s
->rules
[event
], rule
, next
);
275 static void remove_rule(BlkdebugRule
*rule
)
277 switch (rule
->action
) {
278 case ACTION_INJECT_ERROR
:
279 case ACTION_SET_STATE
:
282 g_free(rule
->options
.suspend
.tag
);
286 QLIST_REMOVE(rule
, next
);
290 static int read_config(BDRVBlkdebugState
*s
, const char *filename
,
291 QDict
*options
, Error
**errp
)
295 struct add_rule_data d
;
296 Error
*local_err
= NULL
;
299 f
= fopen(filename
, "r");
301 error_setg_errno(errp
, errno
, "Could not read blkdebug config file");
305 ret
= qemu_config_parse(f
, config_groups
, filename
);
307 error_setg(errp
, "Could not parse blkdebug config file");
313 qemu_config_parse_qdict(options
, config_groups
, &local_err
);
315 error_propagate(errp
, local_err
);
321 d
.action
= ACTION_INJECT_ERROR
;
323 qemu_opts_foreach(&inject_error_opts
, add_rule
, &d
, 1);
325 error_propagate(errp
, local_err
);
330 d
.action
= ACTION_SET_STATE
;
331 qemu_opts_foreach(&set_state_opts
, add_rule
, &d
, 1);
333 error_propagate(errp
, local_err
);
340 qemu_opts_reset(&inject_error_opts
);
341 qemu_opts_reset(&set_state_opts
);
348 /* Valid blkdebug filenames look like blkdebug:path/to/config:path/to/image */
349 static void blkdebug_parse_filename(const char *filename
, QDict
*options
,
354 /* Parse the blkdebug: prefix */
355 if (!strstart(filename
, "blkdebug:", &filename
)) {
356 /* There was no prefix; therefore, all options have to be already
357 present in the QDict (except for the filename) */
358 qdict_put(options
, "x-image", qstring_from_str(filename
));
362 /* Parse config file path */
363 c
= strchr(filename
, ':');
365 error_setg(errp
, "blkdebug requires both config file and image path");
370 QString
*config_path
;
371 config_path
= qstring_from_substr(filename
, 0, c
- filename
- 1);
372 qdict_put(options
, "config", config_path
);
375 /* TODO Allow multi-level nesting and set file.filename here */
377 qdict_put(options
, "x-image", qstring_from_str(filename
));
380 static QemuOptsList runtime_opts
= {
382 .head
= QTAILQ_HEAD_INITIALIZER(runtime_opts
.head
),
386 .type
= QEMU_OPT_STRING
,
387 .help
= "Path to the configuration file",
391 .type
= QEMU_OPT_STRING
,
392 .help
= "[internal use only, will be removed]",
396 .type
= QEMU_OPT_SIZE
,
397 .help
= "Required alignment in bytes",
399 { /* end of list */ }
403 static int blkdebug_open(BlockDriverState
*bs
, QDict
*options
, int flags
,
406 BDRVBlkdebugState
*s
= bs
->opaque
;
408 Error
*local_err
= NULL
;
413 opts
= qemu_opts_create(&runtime_opts
, NULL
, 0, &error_abort
);
414 qemu_opts_absorb_qdict(opts
, options
, &local_err
);
416 error_propagate(errp
, local_err
);
421 /* Read rules from config file or command line options */
422 config
= qemu_opt_get(opts
, "config");
423 ret
= read_config(s
, config
, options
, errp
);
428 /* Set initial state */
431 /* Open the backing file */
432 assert(bs
->file
== NULL
);
433 ret
= bdrv_open_image(&bs
->file
, qemu_opt_get(opts
, "x-image"), options
, "image",
434 flags
| BDRV_O_PROTOCOL
, false, &local_err
);
436 error_propagate(errp
, local_err
);
440 /* Set request alignment */
441 align
= qemu_opt_get_size(opts
, "align", bs
->request_alignment
);
442 if (align
> 0 && align
< INT_MAX
&& !(align
& (align
- 1))) {
443 bs
->request_alignment
= align
;
445 error_setg(errp
, "Invalid alignment");
454 bdrv_unref(bs
->file
);
460 static void error_callback_bh(void *opaque
)
462 struct BlkdebugAIOCB
*acb
= opaque
;
463 qemu_bh_delete(acb
->bh
);
464 acb
->common
.cb(acb
->common
.opaque
, acb
->ret
);
468 static BlockAIOCB
*inject_error(BlockDriverState
*bs
,
469 BlockCompletionFunc
*cb
, void *opaque
, BlkdebugRule
*rule
)
471 BDRVBlkdebugState
*s
= bs
->opaque
;
472 int error
= rule
->options
.inject
.error
;
473 struct BlkdebugAIOCB
*acb
;
476 if (rule
->options
.inject
.once
) {
477 QSIMPLEQ_INIT(&s
->active_rules
);
480 if (rule
->options
.inject
.immediately
) {
484 acb
= qemu_aio_get(&blkdebug_aiocb_info
, bs
, cb
, opaque
);
487 bh
= aio_bh_new(bdrv_get_aio_context(bs
), error_callback_bh
, acb
);
489 qemu_bh_schedule(bh
);
494 static BlockAIOCB
*blkdebug_aio_readv(BlockDriverState
*bs
,
495 int64_t sector_num
, QEMUIOVector
*qiov
, int nb_sectors
,
496 BlockCompletionFunc
*cb
, void *opaque
)
498 BDRVBlkdebugState
*s
= bs
->opaque
;
499 BlkdebugRule
*rule
= NULL
;
501 QSIMPLEQ_FOREACH(rule
, &s
->active_rules
, active_next
) {
502 if (rule
->options
.inject
.sector
== -1 ||
503 (rule
->options
.inject
.sector
>= sector_num
&&
504 rule
->options
.inject
.sector
< sector_num
+ nb_sectors
)) {
509 if (rule
&& rule
->options
.inject
.error
) {
510 return inject_error(bs
, cb
, opaque
, rule
);
513 return bdrv_aio_readv(bs
->file
, sector_num
, qiov
, nb_sectors
, cb
, opaque
);
516 static BlockAIOCB
*blkdebug_aio_writev(BlockDriverState
*bs
,
517 int64_t sector_num
, QEMUIOVector
*qiov
, int nb_sectors
,
518 BlockCompletionFunc
*cb
, void *opaque
)
520 BDRVBlkdebugState
*s
= bs
->opaque
;
521 BlkdebugRule
*rule
= NULL
;
523 QSIMPLEQ_FOREACH(rule
, &s
->active_rules
, active_next
) {
524 if (rule
->options
.inject
.sector
== -1 ||
525 (rule
->options
.inject
.sector
>= sector_num
&&
526 rule
->options
.inject
.sector
< sector_num
+ nb_sectors
)) {
531 if (rule
&& rule
->options
.inject
.error
) {
532 return inject_error(bs
, cb
, opaque
, rule
);
535 return bdrv_aio_writev(bs
->file
, sector_num
, qiov
, nb_sectors
, cb
, opaque
);
538 static BlockAIOCB
*blkdebug_aio_flush(BlockDriverState
*bs
,
539 BlockCompletionFunc
*cb
, void *opaque
)
541 BDRVBlkdebugState
*s
= bs
->opaque
;
542 BlkdebugRule
*rule
= NULL
;
544 QSIMPLEQ_FOREACH(rule
, &s
->active_rules
, active_next
) {
545 if (rule
->options
.inject
.sector
== -1) {
550 if (rule
&& rule
->options
.inject
.error
) {
551 return inject_error(bs
, cb
, opaque
, rule
);
554 return bdrv_aio_flush(bs
->file
, cb
, opaque
);
558 static void blkdebug_close(BlockDriverState
*bs
)
560 BDRVBlkdebugState
*s
= bs
->opaque
;
561 BlkdebugRule
*rule
, *next
;
564 for (i
= 0; i
< BLKDBG_EVENT_MAX
; i
++) {
565 QLIST_FOREACH_SAFE(rule
, &s
->rules
[i
], next
, next
) {
571 static void suspend_request(BlockDriverState
*bs
, BlkdebugRule
*rule
)
573 BDRVBlkdebugState
*s
= bs
->opaque
;
574 BlkdebugSuspendedReq r
;
576 r
= (BlkdebugSuspendedReq
) {
577 .co
= qemu_coroutine_self(),
578 .tag
= g_strdup(rule
->options
.suspend
.tag
),
582 QLIST_INSERT_HEAD(&s
->suspended_reqs
, &r
, next
);
584 printf("blkdebug: Suspended request '%s'\n", r
.tag
);
585 qemu_coroutine_yield();
586 printf("blkdebug: Resuming request '%s'\n", r
.tag
);
588 QLIST_REMOVE(&r
, next
);
592 static bool process_rule(BlockDriverState
*bs
, struct BlkdebugRule
*rule
,
595 BDRVBlkdebugState
*s
= bs
->opaque
;
597 /* Only process rules for the current state */
598 if (rule
->state
&& rule
->state
!= s
->state
) {
602 /* Take the action */
603 switch (rule
->action
) {
604 case ACTION_INJECT_ERROR
:
606 QSIMPLEQ_INIT(&s
->active_rules
);
609 QSIMPLEQ_INSERT_HEAD(&s
->active_rules
, rule
, active_next
);
612 case ACTION_SET_STATE
:
613 s
->new_state
= rule
->options
.set_state
.new_state
;
617 suspend_request(bs
, rule
);
623 static void blkdebug_debug_event(BlockDriverState
*bs
, BlkDebugEvent event
)
625 BDRVBlkdebugState
*s
= bs
->opaque
;
626 struct BlkdebugRule
*rule
, *next
;
629 assert((int)event
>= 0 && event
< BLKDBG_EVENT_MAX
);
632 s
->new_state
= s
->state
;
633 QLIST_FOREACH_SAFE(rule
, &s
->rules
[event
], next
, next
) {
634 injected
= process_rule(bs
, rule
, injected
);
636 s
->state
= s
->new_state
;
639 static int blkdebug_debug_breakpoint(BlockDriverState
*bs
, const char *event
,
642 BDRVBlkdebugState
*s
= bs
->opaque
;
643 struct BlkdebugRule
*rule
;
644 BlkDebugEvent blkdebug_event
;
646 if (get_event_by_name(event
, &blkdebug_event
) < 0) {
651 rule
= g_malloc(sizeof(*rule
));
652 *rule
= (struct BlkdebugRule
) {
653 .event
= blkdebug_event
,
654 .action
= ACTION_SUSPEND
,
656 .options
.suspend
.tag
= g_strdup(tag
),
659 QLIST_INSERT_HEAD(&s
->rules
[blkdebug_event
], rule
, next
);
664 static int blkdebug_debug_resume(BlockDriverState
*bs
, const char *tag
)
666 BDRVBlkdebugState
*s
= bs
->opaque
;
667 BlkdebugSuspendedReq
*r
, *next
;
669 QLIST_FOREACH_SAFE(r
, &s
->suspended_reqs
, next
, next
) {
670 if (!strcmp(r
->tag
, tag
)) {
671 qemu_coroutine_enter(r
->co
, NULL
);
678 static int blkdebug_debug_remove_breakpoint(BlockDriverState
*bs
,
681 BDRVBlkdebugState
*s
= bs
->opaque
;
682 BlkdebugSuspendedReq
*r
, *r_next
;
683 BlkdebugRule
*rule
, *next
;
684 int i
, ret
= -ENOENT
;
686 for (i
= 0; i
< BLKDBG_EVENT_MAX
; i
++) {
687 QLIST_FOREACH_SAFE(rule
, &s
->rules
[i
], next
, next
) {
688 if (rule
->action
== ACTION_SUSPEND
&&
689 !strcmp(rule
->options
.suspend
.tag
, tag
)) {
695 QLIST_FOREACH_SAFE(r
, &s
->suspended_reqs
, next
, r_next
) {
696 if (!strcmp(r
->tag
, tag
)) {
697 qemu_coroutine_enter(r
->co
, NULL
);
704 static bool blkdebug_debug_is_suspended(BlockDriverState
*bs
, const char *tag
)
706 BDRVBlkdebugState
*s
= bs
->opaque
;
707 BlkdebugSuspendedReq
*r
;
709 QLIST_FOREACH(r
, &s
->suspended_reqs
, next
) {
710 if (!strcmp(r
->tag
, tag
)) {
717 static int64_t blkdebug_getlength(BlockDriverState
*bs
)
719 return bdrv_getlength(bs
->file
);
722 static void blkdebug_refresh_filename(BlockDriverState
*bs
)
724 BDRVBlkdebugState
*s
= bs
->opaque
;
725 struct BlkdebugRule
*rule
;
727 QList
*inject_error_list
= NULL
, *set_state_list
= NULL
;
728 QList
*suspend_list
= NULL
;
731 if (!bs
->file
->full_open_options
) {
732 /* The config file cannot be recreated, so creating a plain filename
738 qdict_put_obj(opts
, "driver", QOBJECT(qstring_from_str("blkdebug")));
740 QINCREF(bs
->file
->full_open_options
);
741 qdict_put_obj(opts
, "image", QOBJECT(bs
->file
->full_open_options
));
743 for (event
= 0; event
< BLKDBG_EVENT_MAX
; event
++) {
744 QLIST_FOREACH(rule
, &s
->rules
[event
], next
) {
745 if (rule
->action
== ACTION_INJECT_ERROR
) {
746 QDict
*inject_error
= qdict_new();
748 qdict_put_obj(inject_error
, "event", QOBJECT(qstring_from_str(
749 BlkdebugEvent_lookup
[rule
->event
])));
750 qdict_put_obj(inject_error
, "state",
751 QOBJECT(qint_from_int(rule
->state
)));
752 qdict_put_obj(inject_error
, "errno", QOBJECT(qint_from_int(
753 rule
->options
.inject
.error
)));
754 qdict_put_obj(inject_error
, "sector", QOBJECT(qint_from_int(
755 rule
->options
.inject
.sector
)));
756 qdict_put_obj(inject_error
, "once", QOBJECT(qbool_from_int(
757 rule
->options
.inject
.once
)));
758 qdict_put_obj(inject_error
, "immediately",
759 QOBJECT(qbool_from_int(
760 rule
->options
.inject
.immediately
)));
762 if (!inject_error_list
) {
763 inject_error_list
= qlist_new();
766 qlist_append_obj(inject_error_list
, QOBJECT(inject_error
));
767 } else if (rule
->action
== ACTION_SET_STATE
) {
768 QDict
*set_state
= qdict_new();
770 qdict_put_obj(set_state
, "event", QOBJECT(qstring_from_str(
771 BlkdebugEvent_lookup
[rule
->event
])));
772 qdict_put_obj(set_state
, "state",
773 QOBJECT(qint_from_int(rule
->state
)));
774 qdict_put_obj(set_state
, "new_state", QOBJECT(qint_from_int(
775 rule
->options
.set_state
.new_state
)));
777 if (!set_state_list
) {
778 set_state_list
= qlist_new();
781 qlist_append_obj(set_state_list
, QOBJECT(set_state
));
782 } else if (rule
->action
== ACTION_SUSPEND
) {
783 QDict
*suspend
= qdict_new();
785 qdict_put_obj(suspend
, "event", QOBJECT(qstring_from_str(
786 BlkdebugEvent_lookup
[rule
->event
])));
787 qdict_put_obj(suspend
, "state",
788 QOBJECT(qint_from_int(rule
->state
)));
789 qdict_put_obj(suspend
, "tag", QOBJECT(qstring_from_str(
790 rule
->options
.suspend
.tag
)));
793 suspend_list
= qlist_new();
796 qlist_append_obj(suspend_list
, QOBJECT(suspend
));
801 if (inject_error_list
) {
802 qdict_put_obj(opts
, "inject-error", QOBJECT(inject_error_list
));
804 if (set_state_list
) {
805 qdict_put_obj(opts
, "set-state", QOBJECT(set_state_list
));
808 qdict_put_obj(opts
, "suspend", QOBJECT(suspend_list
));
811 bs
->full_open_options
= opts
;
814 static BlockDriver bdrv_blkdebug
= {
815 .format_name
= "blkdebug",
816 .protocol_name
= "blkdebug",
817 .instance_size
= sizeof(BDRVBlkdebugState
),
819 .bdrv_parse_filename
= blkdebug_parse_filename
,
820 .bdrv_file_open
= blkdebug_open
,
821 .bdrv_close
= blkdebug_close
,
822 .bdrv_getlength
= blkdebug_getlength
,
823 .bdrv_refresh_filename
= blkdebug_refresh_filename
,
825 .bdrv_aio_readv
= blkdebug_aio_readv
,
826 .bdrv_aio_writev
= blkdebug_aio_writev
,
827 .bdrv_aio_flush
= blkdebug_aio_flush
,
829 .bdrv_debug_event
= blkdebug_debug_event
,
830 .bdrv_debug_breakpoint
= blkdebug_debug_breakpoint
,
831 .bdrv_debug_remove_breakpoint
832 = blkdebug_debug_remove_breakpoint
,
833 .bdrv_debug_resume
= blkdebug_debug_resume
,
834 .bdrv_debug_is_suspended
= blkdebug_debug_is_suspended
,
837 static void bdrv_blkdebug_init(void)
839 bdrv_register(&bdrv_blkdebug
);
842 block_init(bdrv_blkdebug_init
);