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 struct add_rule_data
{
153 BDRVBlkdebugState
*s
;
157 static int add_rule(void *opaque
, QemuOpts
*opts
, Error
**errp
)
159 struct add_rule_data
*d
= opaque
;
160 BDRVBlkdebugState
*s
= d
->s
;
161 const char* event_name
;
163 struct BlkdebugRule
*rule
;
166 /* Find the right event for the rule */
167 event_name
= qemu_opt_get(opts
, "event");
169 error_setg(errp
, "Missing event name for rule");
172 event
= qapi_enum_parse(&BlkdebugEvent_lookup
, event_name
, -1, errp
);
177 /* Set attributes common for all actions */
178 rule
= g_malloc0(sizeof(*rule
));
179 *rule
= (struct BlkdebugRule
) {
182 .state
= qemu_opt_get_number(opts
, "state", 0),
185 /* Parse action-specific options */
187 case ACTION_INJECT_ERROR
:
188 rule
->options
.inject
.error
= qemu_opt_get_number(opts
, "errno", EIO
);
189 rule
->options
.inject
.once
= qemu_opt_get_bool(opts
, "once", 0);
190 rule
->options
.inject
.immediately
=
191 qemu_opt_get_bool(opts
, "immediately", 0);
192 sector
= qemu_opt_get_number(opts
, "sector", -1);
193 rule
->options
.inject
.offset
=
194 sector
== -1 ? -1 : sector
* BDRV_SECTOR_SIZE
;
197 case ACTION_SET_STATE
:
198 rule
->options
.set_state
.new_state
=
199 qemu_opt_get_number(opts
, "new_state", 0);
203 rule
->options
.suspend
.tag
=
204 g_strdup(qemu_opt_get(opts
, "tag"));
209 QLIST_INSERT_HEAD(&s
->rules
[event
], rule
, next
);
214 static void remove_rule(BlkdebugRule
*rule
)
216 switch (rule
->action
) {
217 case ACTION_INJECT_ERROR
:
218 case ACTION_SET_STATE
:
221 g_free(rule
->options
.suspend
.tag
);
225 QLIST_REMOVE(rule
, next
);
229 static int read_config(BDRVBlkdebugState
*s
, const char *filename
,
230 QDict
*options
, Error
**errp
)
234 struct add_rule_data d
;
235 Error
*local_err
= NULL
;
238 f
= fopen(filename
, "r");
240 error_setg_errno(errp
, errno
, "Could not read blkdebug config file");
244 ret
= qemu_config_parse(f
, config_groups
, filename
);
246 error_setg(errp
, "Could not parse blkdebug config file");
251 qemu_config_parse_qdict(options
, config_groups
, &local_err
);
253 error_propagate(errp
, local_err
);
259 d
.action
= ACTION_INJECT_ERROR
;
260 qemu_opts_foreach(&inject_error_opts
, add_rule
, &d
, &local_err
);
262 error_propagate(errp
, local_err
);
267 d
.action
= ACTION_SET_STATE
;
268 qemu_opts_foreach(&set_state_opts
, add_rule
, &d
, &local_err
);
270 error_propagate(errp
, local_err
);
277 qemu_opts_reset(&inject_error_opts
);
278 qemu_opts_reset(&set_state_opts
);
285 /* Valid blkdebug filenames look like blkdebug:path/to/config:path/to/image */
286 static void blkdebug_parse_filename(const char *filename
, QDict
*options
,
291 /* Parse the blkdebug: prefix */
292 if (!strstart(filename
, "blkdebug:", &filename
)) {
293 /* There was no prefix; therefore, all options have to be already
294 present in the QDict (except for the filename) */
295 qdict_put_str(options
, "x-image", filename
);
299 /* Parse config file path */
300 c
= strchr(filename
, ':');
302 error_setg(errp
, "blkdebug requires both config file and image path");
307 QString
*config_path
;
308 config_path
= qstring_from_substr(filename
, 0, c
- filename
- 1);
309 qdict_put(options
, "config", config_path
);
312 /* TODO Allow multi-level nesting and set file.filename here */
314 qdict_put_str(options
, "x-image", filename
);
317 static QemuOptsList runtime_opts
= {
319 .head
= QTAILQ_HEAD_INITIALIZER(runtime_opts
.head
),
323 .type
= QEMU_OPT_STRING
,
324 .help
= "Path to the configuration file",
328 .type
= QEMU_OPT_STRING
,
329 .help
= "[internal use only, will be removed]",
333 .type
= QEMU_OPT_SIZE
,
334 .help
= "Required alignment in bytes",
337 .name
= "max-transfer",
338 .type
= QEMU_OPT_SIZE
,
339 .help
= "Maximum transfer size in bytes",
342 .name
= "opt-write-zero",
343 .type
= QEMU_OPT_SIZE
,
344 .help
= "Optimum write zero alignment in bytes",
347 .name
= "max-write-zero",
348 .type
= QEMU_OPT_SIZE
,
349 .help
= "Maximum write zero size in bytes",
352 .name
= "opt-discard",
353 .type
= QEMU_OPT_SIZE
,
354 .help
= "Optimum discard alignment in bytes",
357 .name
= "max-discard",
358 .type
= QEMU_OPT_SIZE
,
359 .help
= "Maximum discard size in bytes",
361 { /* end of list */ }
365 static int blkdebug_open(BlockDriverState
*bs
, QDict
*options
, int flags
,
368 BDRVBlkdebugState
*s
= bs
->opaque
;
370 Error
*local_err
= NULL
;
374 opts
= qemu_opts_create(&runtime_opts
, NULL
, 0, &error_abort
);
375 qemu_opts_absorb_qdict(opts
, options
, &local_err
);
377 error_propagate(errp
, local_err
);
382 /* Read rules from config file or command line options */
383 s
->config_file
= g_strdup(qemu_opt_get(opts
, "config"));
384 ret
= read_config(s
, s
->config_file
, options
, errp
);
389 /* Set initial state */
392 /* Open the image file */
393 bs
->file
= bdrv_open_child(qemu_opt_get(opts
, "x-image"), options
, "image",
394 bs
, &child_file
, false, &local_err
);
397 error_propagate(errp
, local_err
);
401 bs
->supported_write_flags
= BDRV_REQ_FUA
&
402 bs
->file
->bs
->supported_write_flags
;
403 bs
->supported_zero_flags
= (BDRV_REQ_FUA
| BDRV_REQ_MAY_UNMAP
) &
404 bs
->file
->bs
->supported_zero_flags
;
407 /* Set alignment overrides */
408 s
->align
= qemu_opt_get_size(opts
, "align", 0);
409 if (s
->align
&& (s
->align
>= INT_MAX
|| !is_power_of_2(s
->align
))) {
410 error_setg(errp
, "Cannot meet constraints with align %" PRIu64
,
414 align
= MAX(s
->align
, bs
->file
->bs
->bl
.request_alignment
);
416 s
->max_transfer
= qemu_opt_get_size(opts
, "max-transfer", 0);
417 if (s
->max_transfer
&&
418 (s
->max_transfer
>= INT_MAX
||
419 !QEMU_IS_ALIGNED(s
->max_transfer
, align
))) {
420 error_setg(errp
, "Cannot meet constraints with max-transfer %" PRIu64
,
425 s
->opt_write_zero
= qemu_opt_get_size(opts
, "opt-write-zero", 0);
426 if (s
->opt_write_zero
&&
427 (s
->opt_write_zero
>= INT_MAX
||
428 !QEMU_IS_ALIGNED(s
->opt_write_zero
, align
))) {
429 error_setg(errp
, "Cannot meet constraints with opt-write-zero %" PRIu64
,
434 s
->max_write_zero
= qemu_opt_get_size(opts
, "max-write-zero", 0);
435 if (s
->max_write_zero
&&
436 (s
->max_write_zero
>= INT_MAX
||
437 !QEMU_IS_ALIGNED(s
->max_write_zero
,
438 MAX(s
->opt_write_zero
, align
)))) {
439 error_setg(errp
, "Cannot meet constraints with max-write-zero %" PRIu64
,
444 s
->opt_discard
= qemu_opt_get_size(opts
, "opt-discard", 0);
445 if (s
->opt_discard
&&
446 (s
->opt_discard
>= INT_MAX
||
447 !QEMU_IS_ALIGNED(s
->opt_discard
, align
))) {
448 error_setg(errp
, "Cannot meet constraints with opt-discard %" PRIu64
,
453 s
->max_discard
= qemu_opt_get_size(opts
, "max-discard", 0);
454 if (s
->max_discard
&&
455 (s
->max_discard
>= INT_MAX
||
456 !QEMU_IS_ALIGNED(s
->max_discard
,
457 MAX(s
->opt_discard
, align
)))) {
458 error_setg(errp
, "Cannot meet constraints with max-discard %" PRIu64
,
466 g_free(s
->config_file
);
472 static int rule_check(BlockDriverState
*bs
, uint64_t offset
, uint64_t bytes
)
474 BDRVBlkdebugState
*s
= bs
->opaque
;
475 BlkdebugRule
*rule
= NULL
;
479 QSIMPLEQ_FOREACH(rule
, &s
->active_rules
, active_next
) {
480 uint64_t inject_offset
= rule
->options
.inject
.offset
;
482 if (inject_offset
== -1 ||
483 (bytes
&& inject_offset
>= offset
&&
484 inject_offset
< offset
+ bytes
))
490 if (!rule
|| !rule
->options
.inject
.error
) {
494 immediately
= rule
->options
.inject
.immediately
;
495 error
= rule
->options
.inject
.error
;
497 if (rule
->options
.inject
.once
) {
498 QSIMPLEQ_REMOVE(&s
->active_rules
, rule
, BlkdebugRule
, active_next
);
503 aio_co_schedule(qemu_get_current_aio_context(), qemu_coroutine_self());
504 qemu_coroutine_yield();
510 static int coroutine_fn
511 blkdebug_co_preadv(BlockDriverState
*bs
, uint64_t offset
, uint64_t bytes
,
512 QEMUIOVector
*qiov
, int flags
)
516 /* Sanity check block layer guarantees */
517 assert(QEMU_IS_ALIGNED(offset
, bs
->bl
.request_alignment
));
518 assert(QEMU_IS_ALIGNED(bytes
, bs
->bl
.request_alignment
));
519 if (bs
->bl
.max_transfer
) {
520 assert(bytes
<= bs
->bl
.max_transfer
);
523 err
= rule_check(bs
, offset
, bytes
);
528 return bdrv_co_preadv(bs
->file
, offset
, bytes
, qiov
, flags
);
531 static int coroutine_fn
532 blkdebug_co_pwritev(BlockDriverState
*bs
, uint64_t offset
, uint64_t bytes
,
533 QEMUIOVector
*qiov
, int flags
)
537 /* Sanity check block layer guarantees */
538 assert(QEMU_IS_ALIGNED(offset
, bs
->bl
.request_alignment
));
539 assert(QEMU_IS_ALIGNED(bytes
, bs
->bl
.request_alignment
));
540 if (bs
->bl
.max_transfer
) {
541 assert(bytes
<= bs
->bl
.max_transfer
);
544 err
= rule_check(bs
, offset
, bytes
);
549 return bdrv_co_pwritev(bs
->file
, offset
, bytes
, qiov
, flags
);
552 static int blkdebug_co_flush(BlockDriverState
*bs
)
554 int err
= rule_check(bs
, 0, 0);
560 return bdrv_co_flush(bs
->file
->bs
);
563 static int coroutine_fn
blkdebug_co_pwrite_zeroes(BlockDriverState
*bs
,
564 int64_t offset
, int bytes
,
565 BdrvRequestFlags flags
)
567 uint32_t align
= MAX(bs
->bl
.request_alignment
,
568 bs
->bl
.pwrite_zeroes_alignment
);
571 /* Only pass through requests that are larger than requested
572 * preferred alignment (so that we test the fallback to writes on
573 * unaligned portions), and check that the block layer never hands
574 * us anything unaligned that crosses an alignment boundary. */
576 assert(QEMU_IS_ALIGNED(offset
, align
) ||
577 QEMU_IS_ALIGNED(offset
+ bytes
, align
) ||
578 DIV_ROUND_UP(offset
, align
) ==
579 DIV_ROUND_UP(offset
+ bytes
, align
));
582 assert(QEMU_IS_ALIGNED(offset
, align
));
583 assert(QEMU_IS_ALIGNED(bytes
, align
));
584 if (bs
->bl
.max_pwrite_zeroes
) {
585 assert(bytes
<= bs
->bl
.max_pwrite_zeroes
);
588 err
= rule_check(bs
, offset
, bytes
);
593 return bdrv_co_pwrite_zeroes(bs
->file
, offset
, bytes
, flags
);
596 static int coroutine_fn
blkdebug_co_pdiscard(BlockDriverState
*bs
,
597 int64_t offset
, int bytes
)
599 uint32_t align
= bs
->bl
.pdiscard_alignment
;
602 /* Only pass through requests that are larger than requested
603 * minimum alignment, and ensure that unaligned requests do not
604 * cross optimum discard boundaries. */
605 if (bytes
< bs
->bl
.request_alignment
) {
606 assert(QEMU_IS_ALIGNED(offset
, align
) ||
607 QEMU_IS_ALIGNED(offset
+ bytes
, align
) ||
608 DIV_ROUND_UP(offset
, align
) ==
609 DIV_ROUND_UP(offset
+ bytes
, align
));
612 assert(QEMU_IS_ALIGNED(offset
, bs
->bl
.request_alignment
));
613 assert(QEMU_IS_ALIGNED(bytes
, bs
->bl
.request_alignment
));
614 if (align
&& bytes
>= align
) {
615 assert(QEMU_IS_ALIGNED(offset
, align
));
616 assert(QEMU_IS_ALIGNED(bytes
, align
));
618 if (bs
->bl
.max_pdiscard
) {
619 assert(bytes
<= bs
->bl
.max_pdiscard
);
622 err
= rule_check(bs
, offset
, bytes
);
627 return bdrv_co_pdiscard(bs
->file
->bs
, offset
, bytes
);
630 static void blkdebug_close(BlockDriverState
*bs
)
632 BDRVBlkdebugState
*s
= bs
->opaque
;
633 BlkdebugRule
*rule
, *next
;
636 for (i
= 0; i
< BLKDBG__MAX
; i
++) {
637 QLIST_FOREACH_SAFE(rule
, &s
->rules
[i
], next
, next
) {
642 g_free(s
->config_file
);
645 static void suspend_request(BlockDriverState
*bs
, BlkdebugRule
*rule
)
647 BDRVBlkdebugState
*s
= bs
->opaque
;
648 BlkdebugSuspendedReq r
;
650 r
= (BlkdebugSuspendedReq
) {
651 .co
= qemu_coroutine_self(),
652 .tag
= g_strdup(rule
->options
.suspend
.tag
),
656 QLIST_INSERT_HEAD(&s
->suspended_reqs
, &r
, next
);
658 if (!qtest_enabled()) {
659 printf("blkdebug: Suspended request '%s'\n", r
.tag
);
661 qemu_coroutine_yield();
662 if (!qtest_enabled()) {
663 printf("blkdebug: Resuming request '%s'\n", r
.tag
);
666 QLIST_REMOVE(&r
, next
);
670 static bool process_rule(BlockDriverState
*bs
, struct BlkdebugRule
*rule
,
673 BDRVBlkdebugState
*s
= bs
->opaque
;
675 /* Only process rules for the current state */
676 if (rule
->state
&& rule
->state
!= s
->state
) {
680 /* Take the action */
681 switch (rule
->action
) {
682 case ACTION_INJECT_ERROR
:
684 QSIMPLEQ_INIT(&s
->active_rules
);
687 QSIMPLEQ_INSERT_HEAD(&s
->active_rules
, rule
, active_next
);
690 case ACTION_SET_STATE
:
691 s
->new_state
= rule
->options
.set_state
.new_state
;
695 suspend_request(bs
, rule
);
701 static void blkdebug_debug_event(BlockDriverState
*bs
, BlkdebugEvent event
)
703 BDRVBlkdebugState
*s
= bs
->opaque
;
704 struct BlkdebugRule
*rule
, *next
;
707 assert((int)event
>= 0 && event
< BLKDBG__MAX
);
710 s
->new_state
= s
->state
;
711 QLIST_FOREACH_SAFE(rule
, &s
->rules
[event
], next
, next
) {
712 injected
= process_rule(bs
, rule
, injected
);
714 s
->state
= s
->new_state
;
717 static int blkdebug_debug_breakpoint(BlockDriverState
*bs
, const char *event
,
720 BDRVBlkdebugState
*s
= bs
->opaque
;
721 struct BlkdebugRule
*rule
;
724 blkdebug_event
= qapi_enum_parse(&BlkdebugEvent_lookup
, event
, -1, NULL
);
725 if (blkdebug_event
< 0) {
729 rule
= g_malloc(sizeof(*rule
));
730 *rule
= (struct BlkdebugRule
) {
731 .event
= blkdebug_event
,
732 .action
= ACTION_SUSPEND
,
734 .options
.suspend
.tag
= g_strdup(tag
),
737 QLIST_INSERT_HEAD(&s
->rules
[blkdebug_event
], rule
, next
);
742 static int blkdebug_debug_resume(BlockDriverState
*bs
, const char *tag
)
744 BDRVBlkdebugState
*s
= bs
->opaque
;
745 BlkdebugSuspendedReq
*r
, *next
;
747 QLIST_FOREACH_SAFE(r
, &s
->suspended_reqs
, next
, next
) {
748 if (!strcmp(r
->tag
, tag
)) {
749 qemu_coroutine_enter(r
->co
);
756 static int blkdebug_debug_remove_breakpoint(BlockDriverState
*bs
,
759 BDRVBlkdebugState
*s
= bs
->opaque
;
760 BlkdebugSuspendedReq
*r
, *r_next
;
761 BlkdebugRule
*rule
, *next
;
762 int i
, ret
= -ENOENT
;
764 for (i
= 0; i
< BLKDBG__MAX
; i
++) {
765 QLIST_FOREACH_SAFE(rule
, &s
->rules
[i
], next
, next
) {
766 if (rule
->action
== ACTION_SUSPEND
&&
767 !strcmp(rule
->options
.suspend
.tag
, tag
)) {
773 QLIST_FOREACH_SAFE(r
, &s
->suspended_reqs
, next
, r_next
) {
774 if (!strcmp(r
->tag
, tag
)) {
775 qemu_coroutine_enter(r
->co
);
782 static bool blkdebug_debug_is_suspended(BlockDriverState
*bs
, const char *tag
)
784 BDRVBlkdebugState
*s
= bs
->opaque
;
785 BlkdebugSuspendedReq
*r
;
787 QLIST_FOREACH(r
, &s
->suspended_reqs
, next
) {
788 if (!strcmp(r
->tag
, tag
)) {
795 static int64_t blkdebug_getlength(BlockDriverState
*bs
)
797 return bdrv_getlength(bs
->file
->bs
);
800 static void blkdebug_refresh_filename(BlockDriverState
*bs
, QDict
*options
)
802 BDRVBlkdebugState
*s
= bs
->opaque
;
805 bool force_json
= false;
807 for (e
= qdict_first(options
); e
; e
= qdict_next(options
, e
)) {
808 if (strcmp(qdict_entry_key(e
), "config") &&
809 strcmp(qdict_entry_key(e
), "x-image"))
816 if (force_json
&& !bs
->file
->bs
->full_open_options
) {
817 /* The config file cannot be recreated, so creating a plain filename
822 if (!force_json
&& bs
->file
->bs
->exact_filename
[0]) {
823 int ret
= snprintf(bs
->exact_filename
, sizeof(bs
->exact_filename
),
824 "blkdebug:%s:%s", s
->config_file
?: "",
825 bs
->file
->bs
->exact_filename
);
826 if (ret
>= sizeof(bs
->exact_filename
)) {
827 /* An overflow makes the filename unusable, so do not report any */
828 bs
->exact_filename
[0] = 0;
833 qdict_put_str(opts
, "driver", "blkdebug");
835 QINCREF(bs
->file
->bs
->full_open_options
);
836 qdict_put(opts
, "image", bs
->file
->bs
->full_open_options
);
838 for (e
= qdict_first(options
); e
; e
= qdict_next(options
, e
)) {
839 if (strcmp(qdict_entry_key(e
), "x-image")) {
840 qobject_incref(qdict_entry_value(e
));
841 qdict_put_obj(opts
, qdict_entry_key(e
), qdict_entry_value(e
));
845 bs
->full_open_options
= opts
;
848 static void blkdebug_refresh_limits(BlockDriverState
*bs
, Error
**errp
)
850 BDRVBlkdebugState
*s
= bs
->opaque
;
853 bs
->bl
.request_alignment
= s
->align
;
855 if (s
->max_transfer
) {
856 bs
->bl
.max_transfer
= s
->max_transfer
;
858 if (s
->opt_write_zero
) {
859 bs
->bl
.pwrite_zeroes_alignment
= s
->opt_write_zero
;
861 if (s
->max_write_zero
) {
862 bs
->bl
.max_pwrite_zeroes
= s
->max_write_zero
;
864 if (s
->opt_discard
) {
865 bs
->bl
.pdiscard_alignment
= s
->opt_discard
;
867 if (s
->max_discard
) {
868 bs
->bl
.max_pdiscard
= s
->max_discard
;
872 static int blkdebug_reopen_prepare(BDRVReopenState
*reopen_state
,
873 BlockReopenQueue
*queue
, Error
**errp
)
878 static BlockDriver bdrv_blkdebug
= {
879 .format_name
= "blkdebug",
880 .protocol_name
= "blkdebug",
881 .instance_size
= sizeof(BDRVBlkdebugState
),
884 .bdrv_parse_filename
= blkdebug_parse_filename
,
885 .bdrv_file_open
= blkdebug_open
,
886 .bdrv_close
= blkdebug_close
,
887 .bdrv_reopen_prepare
= blkdebug_reopen_prepare
,
888 .bdrv_child_perm
= bdrv_filter_default_perms
,
890 .bdrv_getlength
= blkdebug_getlength
,
891 .bdrv_refresh_filename
= blkdebug_refresh_filename
,
892 .bdrv_refresh_limits
= blkdebug_refresh_limits
,
894 .bdrv_co_preadv
= blkdebug_co_preadv
,
895 .bdrv_co_pwritev
= blkdebug_co_pwritev
,
896 .bdrv_co_flush_to_disk
= blkdebug_co_flush
,
897 .bdrv_co_pwrite_zeroes
= blkdebug_co_pwrite_zeroes
,
898 .bdrv_co_pdiscard
= blkdebug_co_pdiscard
,
899 .bdrv_co_get_block_status
= bdrv_co_get_block_status_from_file
,
901 .bdrv_debug_event
= blkdebug_debug_event
,
902 .bdrv_debug_breakpoint
= blkdebug_debug_breakpoint
,
903 .bdrv_debug_remove_breakpoint
904 = blkdebug_debug_remove_breakpoint
,
905 .bdrv_debug_resume
= blkdebug_debug_resume
,
906 .bdrv_debug_is_suspended
= blkdebug_debug_is_suspended
,
909 static void bdrv_blkdebug_init(void)
911 bdrv_register(&bdrv_blkdebug
);
914 block_init(bdrv_blkdebug_init
);