2 * Block protocol for I/O error injection
4 * Copyright (C) 2016-2017 Red Hat, Inc.
5 * Copyright (c) 2010 Kevin Wolf <kwolf@redhat.com>
7 * Permission is hereby granted, free of charge, to any person obtaining a copy
8 * of this software and associated documentation files (the "Software"), to deal
9 * in the Software without restriction, including without limitation the rights
10 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11 * copies of the Software, and to permit persons to whom the Software is
12 * furnished to do so, subject to the following conditions:
14 * The above copyright notice and this permission notice shall be included in
15 * all copies or substantial portions of the Software.
17 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
20 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
26 #include "qemu/osdep.h"
27 #include "qapi/error.h"
28 #include "qemu/cutils.h"
29 #include "qemu/config-file.h"
30 #include "block/block_int.h"
31 #include "qemu/module.h"
32 #include "qapi/qmp/qbool.h"
33 #include "qapi/qmp/qdict.h"
34 #include "qapi/qmp/qstring.h"
35 #include "sysemu/qtest.h"
37 typedef struct BDRVBlkdebugState
{
41 uint64_t max_transfer
;
42 uint64_t opt_write_zero
;
43 uint64_t max_write_zero
;
47 /* For blkdebug_refresh_filename() */
50 QLIST_HEAD(, BlkdebugRule
) rules
[BLKDBG__MAX
];
51 QSIMPLEQ_HEAD(, BlkdebugRule
) active_rules
;
52 QLIST_HEAD(, BlkdebugSuspendedReq
) suspended_reqs
;
55 typedef struct BlkdebugAIOCB
{
60 typedef struct BlkdebugSuspendedReq
{
63 QLIST_ENTRY(BlkdebugSuspendedReq
) next
;
64 } BlkdebugSuspendedReq
;
72 typedef struct BlkdebugRule
{
90 QLIST_ENTRY(BlkdebugRule
) next
;
91 QSIMPLEQ_ENTRY(BlkdebugRule
) active_next
;
94 static QemuOptsList inject_error_opts
= {
95 .name
= "inject-error",
96 .head
= QTAILQ_HEAD_INITIALIZER(inject_error_opts
.head
),
100 .type
= QEMU_OPT_STRING
,
104 .type
= QEMU_OPT_NUMBER
,
108 .type
= QEMU_OPT_NUMBER
,
112 .type
= QEMU_OPT_NUMBER
,
116 .type
= QEMU_OPT_BOOL
,
119 .name
= "immediately",
120 .type
= QEMU_OPT_BOOL
,
122 { /* end of list */ }
126 static QemuOptsList set_state_opts
= {
128 .head
= QTAILQ_HEAD_INITIALIZER(set_state_opts
.head
),
132 .type
= QEMU_OPT_STRING
,
136 .type
= QEMU_OPT_NUMBER
,
140 .type
= QEMU_OPT_NUMBER
,
142 { /* end of list */ }
146 static QemuOptsList
*config_groups
[] = {
152 static int get_event_by_name(const char *name
, BlkdebugEvent
*event
)
156 for (i
= 0; i
< BLKDBG__MAX
; i
++) {
157 if (!strcmp(BlkdebugEvent_lookup
[i
], name
)) {
166 struct add_rule_data
{
167 BDRVBlkdebugState
*s
;
171 static int add_rule(void *opaque
, QemuOpts
*opts
, Error
**errp
)
173 struct add_rule_data
*d
= opaque
;
174 BDRVBlkdebugState
*s
= d
->s
;
175 const char* event_name
;
177 struct BlkdebugRule
*rule
;
180 /* Find the right event for the rule */
181 event_name
= qemu_opt_get(opts
, "event");
183 error_setg(errp
, "Missing event name for rule");
185 } else if (get_event_by_name(event_name
, &event
) < 0) {
186 error_setg(errp
, "Invalid event name \"%s\"", event_name
);
190 /* Set attributes common for all actions */
191 rule
= g_malloc0(sizeof(*rule
));
192 *rule
= (struct BlkdebugRule
) {
195 .state
= qemu_opt_get_number(opts
, "state", 0),
198 /* Parse action-specific options */
200 case ACTION_INJECT_ERROR
:
201 rule
->options
.inject
.error
= qemu_opt_get_number(opts
, "errno", EIO
);
202 rule
->options
.inject
.once
= qemu_opt_get_bool(opts
, "once", 0);
203 rule
->options
.inject
.immediately
=
204 qemu_opt_get_bool(opts
, "immediately", 0);
205 sector
= qemu_opt_get_number(opts
, "sector", -1);
206 rule
->options
.inject
.offset
=
207 sector
== -1 ? -1 : sector
* BDRV_SECTOR_SIZE
;
210 case ACTION_SET_STATE
:
211 rule
->options
.set_state
.new_state
=
212 qemu_opt_get_number(opts
, "new_state", 0);
216 rule
->options
.suspend
.tag
=
217 g_strdup(qemu_opt_get(opts
, "tag"));
222 QLIST_INSERT_HEAD(&s
->rules
[event
], rule
, next
);
227 static void remove_rule(BlkdebugRule
*rule
)
229 switch (rule
->action
) {
230 case ACTION_INJECT_ERROR
:
231 case ACTION_SET_STATE
:
234 g_free(rule
->options
.suspend
.tag
);
238 QLIST_REMOVE(rule
, next
);
242 static int read_config(BDRVBlkdebugState
*s
, const char *filename
,
243 QDict
*options
, Error
**errp
)
247 struct add_rule_data d
;
248 Error
*local_err
= NULL
;
251 f
= fopen(filename
, "r");
253 error_setg_errno(errp
, errno
, "Could not read blkdebug config file");
257 ret
= qemu_config_parse(f
, config_groups
, filename
);
259 error_setg(errp
, "Could not parse blkdebug config file");
265 qemu_config_parse_qdict(options
, config_groups
, &local_err
);
267 error_propagate(errp
, local_err
);
273 d
.action
= ACTION_INJECT_ERROR
;
274 qemu_opts_foreach(&inject_error_opts
, add_rule
, &d
, &local_err
);
276 error_propagate(errp
, local_err
);
281 d
.action
= ACTION_SET_STATE
;
282 qemu_opts_foreach(&set_state_opts
, add_rule
, &d
, &local_err
);
284 error_propagate(errp
, local_err
);
291 qemu_opts_reset(&inject_error_opts
);
292 qemu_opts_reset(&set_state_opts
);
299 /* Valid blkdebug filenames look like blkdebug:path/to/config:path/to/image */
300 static void blkdebug_parse_filename(const char *filename
, QDict
*options
,
305 /* Parse the blkdebug: prefix */
306 if (!strstart(filename
, "blkdebug:", &filename
)) {
307 /* There was no prefix; therefore, all options have to be already
308 present in the QDict (except for the filename) */
309 qdict_put_str(options
, "x-image", filename
);
313 /* Parse config file path */
314 c
= strchr(filename
, ':');
316 error_setg(errp
, "blkdebug requires both config file and image path");
321 QString
*config_path
;
322 config_path
= qstring_from_substr(filename
, 0, c
- filename
- 1);
323 qdict_put(options
, "config", config_path
);
326 /* TODO Allow multi-level nesting and set file.filename here */
328 qdict_put_str(options
, "x-image", filename
);
331 static QemuOptsList runtime_opts
= {
333 .head
= QTAILQ_HEAD_INITIALIZER(runtime_opts
.head
),
337 .type
= QEMU_OPT_STRING
,
338 .help
= "Path to the configuration file",
342 .type
= QEMU_OPT_STRING
,
343 .help
= "[internal use only, will be removed]",
347 .type
= QEMU_OPT_SIZE
,
348 .help
= "Required alignment in bytes",
351 .name
= "max-transfer",
352 .type
= QEMU_OPT_SIZE
,
353 .help
= "Maximum transfer size in bytes",
356 .name
= "opt-write-zero",
357 .type
= QEMU_OPT_SIZE
,
358 .help
= "Optimum write zero alignment in bytes",
361 .name
= "max-write-zero",
362 .type
= QEMU_OPT_SIZE
,
363 .help
= "Maximum write zero size in bytes",
366 .name
= "opt-discard",
367 .type
= QEMU_OPT_SIZE
,
368 .help
= "Optimum discard alignment in bytes",
371 .name
= "max-discard",
372 .type
= QEMU_OPT_SIZE
,
373 .help
= "Maximum discard size in bytes",
375 { /* end of list */ }
379 static int blkdebug_open(BlockDriverState
*bs
, QDict
*options
, int flags
,
382 BDRVBlkdebugState
*s
= bs
->opaque
;
384 Error
*local_err
= NULL
;
388 opts
= qemu_opts_create(&runtime_opts
, NULL
, 0, &error_abort
);
389 qemu_opts_absorb_qdict(opts
, options
, &local_err
);
391 error_propagate(errp
, local_err
);
396 /* Read rules from config file or command line options */
397 s
->config_file
= g_strdup(qemu_opt_get(opts
, "config"));
398 ret
= read_config(s
, s
->config_file
, options
, errp
);
403 /* Set initial state */
406 /* Open the image file */
407 bs
->file
= bdrv_open_child(qemu_opt_get(opts
, "x-image"), options
, "image",
408 bs
, &child_file
, false, &local_err
);
411 error_propagate(errp
, local_err
);
415 bs
->supported_write_flags
= BDRV_REQ_FUA
&
416 bs
->file
->bs
->supported_write_flags
;
417 bs
->supported_zero_flags
= (BDRV_REQ_FUA
| BDRV_REQ_MAY_UNMAP
) &
418 bs
->file
->bs
->supported_zero_flags
;
421 /* Set alignment overrides */
422 s
->align
= qemu_opt_get_size(opts
, "align", 0);
423 if (s
->align
&& (s
->align
>= INT_MAX
|| !is_power_of_2(s
->align
))) {
424 error_setg(errp
, "Cannot meet constraints with align %" PRIu64
,
428 align
= MAX(s
->align
, bs
->file
->bs
->bl
.request_alignment
);
430 s
->max_transfer
= qemu_opt_get_size(opts
, "max-transfer", 0);
431 if (s
->max_transfer
&&
432 (s
->max_transfer
>= INT_MAX
||
433 !QEMU_IS_ALIGNED(s
->max_transfer
, align
))) {
434 error_setg(errp
, "Cannot meet constraints with max-transfer %" PRIu64
,
439 s
->opt_write_zero
= qemu_opt_get_size(opts
, "opt-write-zero", 0);
440 if (s
->opt_write_zero
&&
441 (s
->opt_write_zero
>= INT_MAX
||
442 !QEMU_IS_ALIGNED(s
->opt_write_zero
, align
))) {
443 error_setg(errp
, "Cannot meet constraints with opt-write-zero %" PRIu64
,
448 s
->max_write_zero
= qemu_opt_get_size(opts
, "max-write-zero", 0);
449 if (s
->max_write_zero
&&
450 (s
->max_write_zero
>= INT_MAX
||
451 !QEMU_IS_ALIGNED(s
->max_write_zero
,
452 MAX(s
->opt_write_zero
, align
)))) {
453 error_setg(errp
, "Cannot meet constraints with max-write-zero %" PRIu64
,
458 s
->opt_discard
= qemu_opt_get_size(opts
, "opt-discard", 0);
459 if (s
->opt_discard
&&
460 (s
->opt_discard
>= INT_MAX
||
461 !QEMU_IS_ALIGNED(s
->opt_discard
, align
))) {
462 error_setg(errp
, "Cannot meet constraints with opt-discard %" PRIu64
,
467 s
->max_discard
= qemu_opt_get_size(opts
, "max-discard", 0);
468 if (s
->max_discard
&&
469 (s
->max_discard
>= INT_MAX
||
470 !QEMU_IS_ALIGNED(s
->max_discard
,
471 MAX(s
->opt_discard
, align
)))) {
472 error_setg(errp
, "Cannot meet constraints with max-discard %" PRIu64
,
480 g_free(s
->config_file
);
486 static int rule_check(BlockDriverState
*bs
, uint64_t offset
, uint64_t bytes
)
488 BDRVBlkdebugState
*s
= bs
->opaque
;
489 BlkdebugRule
*rule
= NULL
;
493 QSIMPLEQ_FOREACH(rule
, &s
->active_rules
, active_next
) {
494 uint64_t inject_offset
= rule
->options
.inject
.offset
;
496 if (inject_offset
== -1 ||
497 (bytes
&& inject_offset
>= offset
&&
498 inject_offset
< offset
+ bytes
))
504 if (!rule
|| !rule
->options
.inject
.error
) {
508 immediately
= rule
->options
.inject
.immediately
;
509 error
= rule
->options
.inject
.error
;
511 if (rule
->options
.inject
.once
) {
512 QSIMPLEQ_REMOVE(&s
->active_rules
, rule
, BlkdebugRule
, active_next
);
517 aio_co_schedule(qemu_get_current_aio_context(), qemu_coroutine_self());
518 qemu_coroutine_yield();
524 static int coroutine_fn
525 blkdebug_co_preadv(BlockDriverState
*bs
, uint64_t offset
, uint64_t bytes
,
526 QEMUIOVector
*qiov
, int flags
)
530 /* Sanity check block layer guarantees */
531 assert(QEMU_IS_ALIGNED(offset
, bs
->bl
.request_alignment
));
532 assert(QEMU_IS_ALIGNED(bytes
, bs
->bl
.request_alignment
));
533 if (bs
->bl
.max_transfer
) {
534 assert(bytes
<= bs
->bl
.max_transfer
);
537 err
= rule_check(bs
, offset
, bytes
);
542 return bdrv_co_preadv(bs
->file
, offset
, bytes
, qiov
, flags
);
545 static int coroutine_fn
546 blkdebug_co_pwritev(BlockDriverState
*bs
, uint64_t offset
, uint64_t bytes
,
547 QEMUIOVector
*qiov
, int flags
)
551 /* Sanity check block layer guarantees */
552 assert(QEMU_IS_ALIGNED(offset
, bs
->bl
.request_alignment
));
553 assert(QEMU_IS_ALIGNED(bytes
, bs
->bl
.request_alignment
));
554 if (bs
->bl
.max_transfer
) {
555 assert(bytes
<= bs
->bl
.max_transfer
);
558 err
= rule_check(bs
, offset
, bytes
);
563 return bdrv_co_pwritev(bs
->file
, offset
, bytes
, qiov
, flags
);
566 static int blkdebug_co_flush(BlockDriverState
*bs
)
568 int err
= rule_check(bs
, 0, 0);
574 return bdrv_co_flush(bs
->file
->bs
);
577 static int coroutine_fn
blkdebug_co_pwrite_zeroes(BlockDriverState
*bs
,
578 int64_t offset
, int bytes
,
579 BdrvRequestFlags flags
)
581 uint32_t align
= MAX(bs
->bl
.request_alignment
,
582 bs
->bl
.pwrite_zeroes_alignment
);
585 /* Only pass through requests that are larger than requested
586 * preferred alignment (so that we test the fallback to writes on
587 * unaligned portions), and check that the block layer never hands
588 * us anything unaligned that crosses an alignment boundary. */
590 assert(QEMU_IS_ALIGNED(offset
, align
) ||
591 QEMU_IS_ALIGNED(offset
+ bytes
, align
) ||
592 DIV_ROUND_UP(offset
, align
) ==
593 DIV_ROUND_UP(offset
+ bytes
, align
));
596 assert(QEMU_IS_ALIGNED(offset
, align
));
597 assert(QEMU_IS_ALIGNED(bytes
, align
));
598 if (bs
->bl
.max_pwrite_zeroes
) {
599 assert(bytes
<= bs
->bl
.max_pwrite_zeroes
);
602 err
= rule_check(bs
, offset
, bytes
);
607 return bdrv_co_pwrite_zeroes(bs
->file
, offset
, bytes
, flags
);
610 static int coroutine_fn
blkdebug_co_pdiscard(BlockDriverState
*bs
,
611 int64_t offset
, int bytes
)
613 uint32_t align
= bs
->bl
.pdiscard_alignment
;
616 /* Only pass through requests that are larger than requested
617 * minimum alignment, and ensure that unaligned requests do not
618 * cross optimum discard boundaries. */
619 if (bytes
< bs
->bl
.request_alignment
) {
620 assert(QEMU_IS_ALIGNED(offset
, align
) ||
621 QEMU_IS_ALIGNED(offset
+ bytes
, align
) ||
622 DIV_ROUND_UP(offset
, align
) ==
623 DIV_ROUND_UP(offset
+ bytes
, align
));
626 assert(QEMU_IS_ALIGNED(offset
, bs
->bl
.request_alignment
));
627 assert(QEMU_IS_ALIGNED(bytes
, bs
->bl
.request_alignment
));
628 if (align
&& bytes
>= align
) {
629 assert(QEMU_IS_ALIGNED(offset
, align
));
630 assert(QEMU_IS_ALIGNED(bytes
, align
));
632 if (bs
->bl
.max_pdiscard
) {
633 assert(bytes
<= bs
->bl
.max_pdiscard
);
636 err
= rule_check(bs
, offset
, bytes
);
641 return bdrv_co_pdiscard(bs
->file
->bs
, offset
, bytes
);
644 static int64_t coroutine_fn
blkdebug_co_get_block_status(
645 BlockDriverState
*bs
, int64_t sector_num
, int nb_sectors
, int *pnum
,
646 BlockDriverState
**file
)
649 *file
= bs
->file
->bs
;
650 return BDRV_BLOCK_RAW
| BDRV_BLOCK_OFFSET_VALID
|
651 (sector_num
<< BDRV_SECTOR_BITS
);
654 static void blkdebug_close(BlockDriverState
*bs
)
656 BDRVBlkdebugState
*s
= bs
->opaque
;
657 BlkdebugRule
*rule
, *next
;
660 for (i
= 0; i
< BLKDBG__MAX
; i
++) {
661 QLIST_FOREACH_SAFE(rule
, &s
->rules
[i
], next
, next
) {
666 g_free(s
->config_file
);
669 static void suspend_request(BlockDriverState
*bs
, BlkdebugRule
*rule
)
671 BDRVBlkdebugState
*s
= bs
->opaque
;
672 BlkdebugSuspendedReq r
;
674 r
= (BlkdebugSuspendedReq
) {
675 .co
= qemu_coroutine_self(),
676 .tag
= g_strdup(rule
->options
.suspend
.tag
),
680 QLIST_INSERT_HEAD(&s
->suspended_reqs
, &r
, next
);
682 if (!qtest_enabled()) {
683 printf("blkdebug: Suspended request '%s'\n", r
.tag
);
685 qemu_coroutine_yield();
686 if (!qtest_enabled()) {
687 printf("blkdebug: Resuming request '%s'\n", r
.tag
);
690 QLIST_REMOVE(&r
, next
);
694 static bool process_rule(BlockDriverState
*bs
, struct BlkdebugRule
*rule
,
697 BDRVBlkdebugState
*s
= bs
->opaque
;
699 /* Only process rules for the current state */
700 if (rule
->state
&& rule
->state
!= s
->state
) {
704 /* Take the action */
705 switch (rule
->action
) {
706 case ACTION_INJECT_ERROR
:
708 QSIMPLEQ_INIT(&s
->active_rules
);
711 QSIMPLEQ_INSERT_HEAD(&s
->active_rules
, rule
, active_next
);
714 case ACTION_SET_STATE
:
715 s
->new_state
= rule
->options
.set_state
.new_state
;
719 suspend_request(bs
, rule
);
725 static void blkdebug_debug_event(BlockDriverState
*bs
, BlkdebugEvent event
)
727 BDRVBlkdebugState
*s
= bs
->opaque
;
728 struct BlkdebugRule
*rule
, *next
;
731 assert((int)event
>= 0 && event
< BLKDBG__MAX
);
734 s
->new_state
= s
->state
;
735 QLIST_FOREACH_SAFE(rule
, &s
->rules
[event
], next
, next
) {
736 injected
= process_rule(bs
, rule
, injected
);
738 s
->state
= s
->new_state
;
741 static int blkdebug_debug_breakpoint(BlockDriverState
*bs
, const char *event
,
744 BDRVBlkdebugState
*s
= bs
->opaque
;
745 struct BlkdebugRule
*rule
;
746 BlkdebugEvent blkdebug_event
;
748 if (get_event_by_name(event
, &blkdebug_event
) < 0) {
753 rule
= g_malloc(sizeof(*rule
));
754 *rule
= (struct BlkdebugRule
) {
755 .event
= blkdebug_event
,
756 .action
= ACTION_SUSPEND
,
758 .options
.suspend
.tag
= g_strdup(tag
),
761 QLIST_INSERT_HEAD(&s
->rules
[blkdebug_event
], rule
, next
);
766 static int blkdebug_debug_resume(BlockDriverState
*bs
, const char *tag
)
768 BDRVBlkdebugState
*s
= bs
->opaque
;
769 BlkdebugSuspendedReq
*r
, *next
;
771 QLIST_FOREACH_SAFE(r
, &s
->suspended_reqs
, next
, next
) {
772 if (!strcmp(r
->tag
, tag
)) {
773 qemu_coroutine_enter(r
->co
);
780 static int blkdebug_debug_remove_breakpoint(BlockDriverState
*bs
,
783 BDRVBlkdebugState
*s
= bs
->opaque
;
784 BlkdebugSuspendedReq
*r
, *r_next
;
785 BlkdebugRule
*rule
, *next
;
786 int i
, ret
= -ENOENT
;
788 for (i
= 0; i
< BLKDBG__MAX
; i
++) {
789 QLIST_FOREACH_SAFE(rule
, &s
->rules
[i
], next
, next
) {
790 if (rule
->action
== ACTION_SUSPEND
&&
791 !strcmp(rule
->options
.suspend
.tag
, tag
)) {
797 QLIST_FOREACH_SAFE(r
, &s
->suspended_reqs
, next
, r_next
) {
798 if (!strcmp(r
->tag
, tag
)) {
799 qemu_coroutine_enter(r
->co
);
806 static bool blkdebug_debug_is_suspended(BlockDriverState
*bs
, const char *tag
)
808 BDRVBlkdebugState
*s
= bs
->opaque
;
809 BlkdebugSuspendedReq
*r
;
811 QLIST_FOREACH(r
, &s
->suspended_reqs
, next
) {
812 if (!strcmp(r
->tag
, tag
)) {
819 static int64_t blkdebug_getlength(BlockDriverState
*bs
)
821 return bdrv_getlength(bs
->file
->bs
);
824 static int blkdebug_truncate(BlockDriverState
*bs
, int64_t offset
,
825 PreallocMode prealloc
, Error
**errp
)
827 return bdrv_truncate(bs
->file
, offset
, prealloc
, errp
);
830 static void blkdebug_refresh_filename(BlockDriverState
*bs
, QDict
*options
)
832 BDRVBlkdebugState
*s
= bs
->opaque
;
835 bool force_json
= false;
837 for (e
= qdict_first(options
); e
; e
= qdict_next(options
, e
)) {
838 if (strcmp(qdict_entry_key(e
), "config") &&
839 strcmp(qdict_entry_key(e
), "x-image"))
846 if (force_json
&& !bs
->file
->bs
->full_open_options
) {
847 /* The config file cannot be recreated, so creating a plain filename
852 if (!force_json
&& bs
->file
->bs
->exact_filename
[0]) {
853 int ret
= snprintf(bs
->exact_filename
, sizeof(bs
->exact_filename
),
854 "blkdebug:%s:%s", s
->config_file
?: "",
855 bs
->file
->bs
->exact_filename
);
856 if (ret
>= sizeof(bs
->exact_filename
)) {
857 /* An overflow makes the filename unusable, so do not report any */
858 bs
->exact_filename
[0] = 0;
863 qdict_put_str(opts
, "driver", "blkdebug");
865 QINCREF(bs
->file
->bs
->full_open_options
);
866 qdict_put(opts
, "image", bs
->file
->bs
->full_open_options
);
868 for (e
= qdict_first(options
); e
; e
= qdict_next(options
, e
)) {
869 if (strcmp(qdict_entry_key(e
), "x-image")) {
870 qobject_incref(qdict_entry_value(e
));
871 qdict_put_obj(opts
, qdict_entry_key(e
), qdict_entry_value(e
));
875 bs
->full_open_options
= opts
;
878 static void blkdebug_refresh_limits(BlockDriverState
*bs
, Error
**errp
)
880 BDRVBlkdebugState
*s
= bs
->opaque
;
883 bs
->bl
.request_alignment
= s
->align
;
885 if (s
->max_transfer
) {
886 bs
->bl
.max_transfer
= s
->max_transfer
;
888 if (s
->opt_write_zero
) {
889 bs
->bl
.pwrite_zeroes_alignment
= s
->opt_write_zero
;
891 if (s
->max_write_zero
) {
892 bs
->bl
.max_pwrite_zeroes
= s
->max_write_zero
;
894 if (s
->opt_discard
) {
895 bs
->bl
.pdiscard_alignment
= s
->opt_discard
;
897 if (s
->max_discard
) {
898 bs
->bl
.max_pdiscard
= s
->max_discard
;
902 static int blkdebug_reopen_prepare(BDRVReopenState
*reopen_state
,
903 BlockReopenQueue
*queue
, Error
**errp
)
908 static BlockDriver bdrv_blkdebug
= {
909 .format_name
= "blkdebug",
910 .protocol_name
= "blkdebug",
911 .instance_size
= sizeof(BDRVBlkdebugState
),
913 .bdrv_parse_filename
= blkdebug_parse_filename
,
914 .bdrv_file_open
= blkdebug_open
,
915 .bdrv_close
= blkdebug_close
,
916 .bdrv_reopen_prepare
= blkdebug_reopen_prepare
,
917 .bdrv_child_perm
= bdrv_filter_default_perms
,
919 .bdrv_getlength
= blkdebug_getlength
,
920 .bdrv_truncate
= blkdebug_truncate
,
921 .bdrv_refresh_filename
= blkdebug_refresh_filename
,
922 .bdrv_refresh_limits
= blkdebug_refresh_limits
,
924 .bdrv_co_preadv
= blkdebug_co_preadv
,
925 .bdrv_co_pwritev
= blkdebug_co_pwritev
,
926 .bdrv_co_flush_to_disk
= blkdebug_co_flush
,
927 .bdrv_co_pwrite_zeroes
= blkdebug_co_pwrite_zeroes
,
928 .bdrv_co_pdiscard
= blkdebug_co_pdiscard
,
929 .bdrv_co_get_block_status
= blkdebug_co_get_block_status
,
931 .bdrv_debug_event
= blkdebug_debug_event
,
932 .bdrv_debug_breakpoint
= blkdebug_debug_breakpoint
,
933 .bdrv_debug_remove_breakpoint
934 = blkdebug_debug_remove_breakpoint
,
935 .bdrv_debug_resume
= blkdebug_debug_resume
,
936 .bdrv_debug_is_suspended
= blkdebug_debug_is_suspended
,
939 static void bdrv_blkdebug_init(void)
941 bdrv_register(&bdrv_blkdebug
);
944 block_init(bdrv_blkdebug_init
);