xref: /openbmc/qemu/block/blkdebug.c (revision cd4eb4c5)
1 /*
2  * Block protocol for I/O error injection
3  *
4  * Copyright (c) 2010 Kevin Wolf <kwolf@redhat.com>
5  *
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:
12  *
13  * The above copyright notice and this permission notice shall be included in
14  * all copies or substantial portions of the Software.
15  *
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
22  * THE SOFTWARE.
23  */
24 
25 #include "qemu-common.h"
26 #include "qemu/config-file.h"
27 #include "block/block_int.h"
28 #include "qemu/module.h"
29 
30 typedef struct BDRVBlkdebugState {
31     int state;
32     int new_state;
33 
34     QLIST_HEAD(, BlkdebugRule) rules[BLKDBG_EVENT_MAX];
35     QSIMPLEQ_HEAD(, BlkdebugRule) active_rules;
36     QLIST_HEAD(, BlkdebugSuspendedReq) suspended_reqs;
37 } BDRVBlkdebugState;
38 
39 typedef struct BlkdebugAIOCB {
40     BlockDriverAIOCB common;
41     QEMUBH *bh;
42     int ret;
43 } BlkdebugAIOCB;
44 
45 typedef struct BlkdebugSuspendedReq {
46     Coroutine *co;
47     char *tag;
48     QLIST_ENTRY(BlkdebugSuspendedReq) next;
49 } BlkdebugSuspendedReq;
50 
51 static void blkdebug_aio_cancel(BlockDriverAIOCB *blockacb);
52 
53 static const AIOCBInfo blkdebug_aiocb_info = {
54     .aiocb_size = sizeof(BlkdebugAIOCB),
55     .cancel     = blkdebug_aio_cancel,
56 };
57 
58 enum {
59     ACTION_INJECT_ERROR,
60     ACTION_SET_STATE,
61     ACTION_SUSPEND,
62 };
63 
64 typedef struct BlkdebugRule {
65     BlkDebugEvent event;
66     int action;
67     int state;
68     union {
69         struct {
70             int error;
71             int immediately;
72             int once;
73             int64_t sector;
74         } inject;
75         struct {
76             int new_state;
77         } set_state;
78         struct {
79             char *tag;
80         } suspend;
81     } options;
82     QLIST_ENTRY(BlkdebugRule) next;
83     QSIMPLEQ_ENTRY(BlkdebugRule) active_next;
84 } BlkdebugRule;
85 
86 static QemuOptsList inject_error_opts = {
87     .name = "inject-error",
88     .head = QTAILQ_HEAD_INITIALIZER(inject_error_opts.head),
89     .desc = {
90         {
91             .name = "event",
92             .type = QEMU_OPT_STRING,
93         },
94         {
95             .name = "state",
96             .type = QEMU_OPT_NUMBER,
97         },
98         {
99             .name = "errno",
100             .type = QEMU_OPT_NUMBER,
101         },
102         {
103             .name = "sector",
104             .type = QEMU_OPT_NUMBER,
105         },
106         {
107             .name = "once",
108             .type = QEMU_OPT_BOOL,
109         },
110         {
111             .name = "immediately",
112             .type = QEMU_OPT_BOOL,
113         },
114         { /* end of list */ }
115     },
116 };
117 
118 static QemuOptsList set_state_opts = {
119     .name = "set-state",
120     .head = QTAILQ_HEAD_INITIALIZER(set_state_opts.head),
121     .desc = {
122         {
123             .name = "event",
124             .type = QEMU_OPT_STRING,
125         },
126         {
127             .name = "state",
128             .type = QEMU_OPT_NUMBER,
129         },
130         {
131             .name = "new_state",
132             .type = QEMU_OPT_NUMBER,
133         },
134         { /* end of list */ }
135     },
136 };
137 
138 static QemuOptsList *config_groups[] = {
139     &inject_error_opts,
140     &set_state_opts,
141     NULL
142 };
143 
144 static const char *event_names[BLKDBG_EVENT_MAX] = {
145     [BLKDBG_L1_UPDATE]                      = "l1_update",
146     [BLKDBG_L1_GROW_ALLOC_TABLE]            = "l1_grow.alloc_table",
147     [BLKDBG_L1_GROW_WRITE_TABLE]            = "l1_grow.write_table",
148     [BLKDBG_L1_GROW_ACTIVATE_TABLE]         = "l1_grow.activate_table",
149 
150     [BLKDBG_L2_LOAD]                        = "l2_load",
151     [BLKDBG_L2_UPDATE]                      = "l2_update",
152     [BLKDBG_L2_UPDATE_COMPRESSED]           = "l2_update_compressed",
153     [BLKDBG_L2_ALLOC_COW_READ]              = "l2_alloc.cow_read",
154     [BLKDBG_L2_ALLOC_WRITE]                 = "l2_alloc.write",
155 
156     [BLKDBG_READ_AIO]                       = "read_aio",
157     [BLKDBG_READ_BACKING_AIO]               = "read_backing_aio",
158     [BLKDBG_READ_COMPRESSED]                = "read_compressed",
159 
160     [BLKDBG_WRITE_AIO]                      = "write_aio",
161     [BLKDBG_WRITE_COMPRESSED]               = "write_compressed",
162 
163     [BLKDBG_VMSTATE_LOAD]                   = "vmstate_load",
164     [BLKDBG_VMSTATE_SAVE]                   = "vmstate_save",
165 
166     [BLKDBG_COW_READ]                       = "cow_read",
167     [BLKDBG_COW_WRITE]                      = "cow_write",
168 
169     [BLKDBG_REFTABLE_LOAD]                  = "reftable_load",
170     [BLKDBG_REFTABLE_GROW]                  = "reftable_grow",
171     [BLKDBG_REFTABLE_UPDATE]                = "reftable_update",
172 
173     [BLKDBG_REFBLOCK_LOAD]                  = "refblock_load",
174     [BLKDBG_REFBLOCK_UPDATE]                = "refblock_update",
175     [BLKDBG_REFBLOCK_UPDATE_PART]           = "refblock_update_part",
176     [BLKDBG_REFBLOCK_ALLOC]                 = "refblock_alloc",
177     [BLKDBG_REFBLOCK_ALLOC_HOOKUP]          = "refblock_alloc.hookup",
178     [BLKDBG_REFBLOCK_ALLOC_WRITE]           = "refblock_alloc.write",
179     [BLKDBG_REFBLOCK_ALLOC_WRITE_BLOCKS]    = "refblock_alloc.write_blocks",
180     [BLKDBG_REFBLOCK_ALLOC_WRITE_TABLE]     = "refblock_alloc.write_table",
181     [BLKDBG_REFBLOCK_ALLOC_SWITCH_TABLE]    = "refblock_alloc.switch_table",
182 
183     [BLKDBG_CLUSTER_ALLOC]                  = "cluster_alloc",
184     [BLKDBG_CLUSTER_ALLOC_BYTES]            = "cluster_alloc_bytes",
185     [BLKDBG_CLUSTER_FREE]                   = "cluster_free",
186 
187     [BLKDBG_FLUSH_TO_OS]                    = "flush_to_os",
188     [BLKDBG_FLUSH_TO_DISK]                  = "flush_to_disk",
189 
190     [BLKDBG_PWRITEV_RMW_HEAD]               = "pwritev_rmw.head",
191     [BLKDBG_PWRITEV_RMW_AFTER_HEAD]         = "pwritev_rmw.after_head",
192     [BLKDBG_PWRITEV_RMW_TAIL]               = "pwritev_rmw.tail",
193     [BLKDBG_PWRITEV_RMW_AFTER_TAIL]         = "pwritev_rmw.after_tail",
194     [BLKDBG_PWRITEV]                        = "pwritev",
195     [BLKDBG_PWRITEV_ZERO]                   = "pwritev_zero",
196     [BLKDBG_PWRITEV_DONE]                   = "pwritev_done",
197 };
198 
199 static int get_event_by_name(const char *name, BlkDebugEvent *event)
200 {
201     int i;
202 
203     for (i = 0; i < BLKDBG_EVENT_MAX; i++) {
204         if (!strcmp(event_names[i], name)) {
205             *event = i;
206             return 0;
207         }
208     }
209 
210     return -1;
211 }
212 
213 struct add_rule_data {
214     BDRVBlkdebugState *s;
215     int action;
216 };
217 
218 static int add_rule(QemuOpts *opts, void *opaque)
219 {
220     struct add_rule_data *d = opaque;
221     BDRVBlkdebugState *s = d->s;
222     const char* event_name;
223     BlkDebugEvent event;
224     struct BlkdebugRule *rule;
225 
226     /* Find the right event for the rule */
227     event_name = qemu_opt_get(opts, "event");
228     if (!event_name || get_event_by_name(event_name, &event) < 0) {
229         return -1;
230     }
231 
232     /* Set attributes common for all actions */
233     rule = g_malloc0(sizeof(*rule));
234     *rule = (struct BlkdebugRule) {
235         .event  = event,
236         .action = d->action,
237         .state  = qemu_opt_get_number(opts, "state", 0),
238     };
239 
240     /* Parse action-specific options */
241     switch (d->action) {
242     case ACTION_INJECT_ERROR:
243         rule->options.inject.error = qemu_opt_get_number(opts, "errno", EIO);
244         rule->options.inject.once  = qemu_opt_get_bool(opts, "once", 0);
245         rule->options.inject.immediately =
246             qemu_opt_get_bool(opts, "immediately", 0);
247         rule->options.inject.sector = qemu_opt_get_number(opts, "sector", -1);
248         break;
249 
250     case ACTION_SET_STATE:
251         rule->options.set_state.new_state =
252             qemu_opt_get_number(opts, "new_state", 0);
253         break;
254 
255     case ACTION_SUSPEND:
256         rule->options.suspend.tag =
257             g_strdup(qemu_opt_get(opts, "tag"));
258         break;
259     };
260 
261     /* Add the rule */
262     QLIST_INSERT_HEAD(&s->rules[event], rule, next);
263 
264     return 0;
265 }
266 
267 static void remove_rule(BlkdebugRule *rule)
268 {
269     switch (rule->action) {
270     case ACTION_INJECT_ERROR:
271     case ACTION_SET_STATE:
272         break;
273     case ACTION_SUSPEND:
274         g_free(rule->options.suspend.tag);
275         break;
276     }
277 
278     QLIST_REMOVE(rule, next);
279     g_free(rule);
280 }
281 
282 static int read_config(BDRVBlkdebugState *s, const char *filename,
283                        QDict *options, Error **errp)
284 {
285     FILE *f = NULL;
286     int ret;
287     struct add_rule_data d;
288     Error *local_err = NULL;
289 
290     if (filename) {
291         f = fopen(filename, "r");
292         if (f == NULL) {
293             error_setg_errno(errp, errno, "Could not read blkdebug config file");
294             return -errno;
295         }
296 
297         ret = qemu_config_parse(f, config_groups, filename);
298         if (ret < 0) {
299             error_setg(errp, "Could not parse blkdebug config file");
300             ret = -EINVAL;
301             goto fail;
302         }
303     }
304 
305     qemu_config_parse_qdict(options, config_groups, &local_err);
306     if (error_is_set(&local_err)) {
307         error_propagate(errp, local_err);
308         ret = -EINVAL;
309         goto fail;
310     }
311 
312     d.s = s;
313     d.action = ACTION_INJECT_ERROR;
314     qemu_opts_foreach(&inject_error_opts, add_rule, &d, 0);
315 
316     d.action = ACTION_SET_STATE;
317     qemu_opts_foreach(&set_state_opts, add_rule, &d, 0);
318 
319     ret = 0;
320 fail:
321     qemu_opts_reset(&inject_error_opts);
322     qemu_opts_reset(&set_state_opts);
323     if (f) {
324         fclose(f);
325     }
326     return ret;
327 }
328 
329 /* Valid blkdebug filenames look like blkdebug:path/to/config:path/to/image */
330 static void blkdebug_parse_filename(const char *filename, QDict *options,
331                                     Error **errp)
332 {
333     const char *c;
334 
335     /* Parse the blkdebug: prefix */
336     if (!strstart(filename, "blkdebug:", &filename)) {
337         /* There was no prefix; therefore, all options have to be already
338            present in the QDict (except for the filename) */
339         qdict_put(options, "x-image", qstring_from_str(filename));
340         return;
341     }
342 
343     /* Parse config file path */
344     c = strchr(filename, ':');
345     if (c == NULL) {
346         error_setg(errp, "blkdebug requires both config file and image path");
347         return;
348     }
349 
350     if (c != filename) {
351         QString *config_path;
352         config_path = qstring_from_substr(filename, 0, c - filename - 1);
353         qdict_put(options, "config", config_path);
354     }
355 
356     /* TODO Allow multi-level nesting and set file.filename here */
357     filename = c + 1;
358     qdict_put(options, "x-image", qstring_from_str(filename));
359 }
360 
361 static QemuOptsList runtime_opts = {
362     .name = "blkdebug",
363     .head = QTAILQ_HEAD_INITIALIZER(runtime_opts.head),
364     .desc = {
365         {
366             .name = "config",
367             .type = QEMU_OPT_STRING,
368             .help = "Path to the configuration file",
369         },
370         {
371             .name = "x-image",
372             .type = QEMU_OPT_STRING,
373             .help = "[internal use only, will be removed]",
374         },
375         {
376             .name = "align",
377             .type = QEMU_OPT_SIZE,
378             .help = "Required alignment in bytes",
379         },
380         { /* end of list */ }
381     },
382 };
383 
384 static int blkdebug_open(BlockDriverState *bs, QDict *options, int flags,
385                          Error **errp)
386 {
387     BDRVBlkdebugState *s = bs->opaque;
388     QemuOpts *opts;
389     Error *local_err = NULL;
390     const char *config;
391     uint64_t align;
392     int ret;
393 
394     opts = qemu_opts_create(&runtime_opts, NULL, 0, &error_abort);
395     qemu_opts_absorb_qdict(opts, options, &local_err);
396     if (error_is_set(&local_err)) {
397         error_propagate(errp, local_err);
398         ret = -EINVAL;
399         goto fail;
400     }
401 
402     /* Read rules from config file or command line options */
403     config = qemu_opt_get(opts, "config");
404     ret = read_config(s, config, options, errp);
405     if (ret) {
406         goto fail;
407     }
408 
409     /* Set initial state */
410     s->state = 1;
411 
412     /* Open the backing file */
413     ret = bdrv_open_image(&bs->file, qemu_opt_get(opts, "x-image"), options, "image",
414                           flags, true, false, &local_err);
415     if (ret < 0) {
416         error_propagate(errp, local_err);
417         goto fail;
418     }
419 
420     /* Set request alignment */
421     align = qemu_opt_get_size(opts, "align", bs->request_alignment);
422     if (align > 0 && align < INT_MAX && !(align & (align - 1))) {
423         bs->request_alignment = align;
424     } else {
425         error_setg(errp, "Invalid alignment");
426         ret = -EINVAL;
427         goto fail;
428     }
429 
430     ret = 0;
431 fail:
432     qemu_opts_del(opts);
433     return ret;
434 }
435 
436 static void error_callback_bh(void *opaque)
437 {
438     struct BlkdebugAIOCB *acb = opaque;
439     qemu_bh_delete(acb->bh);
440     acb->common.cb(acb->common.opaque, acb->ret);
441     qemu_aio_release(acb);
442 }
443 
444 static void blkdebug_aio_cancel(BlockDriverAIOCB *blockacb)
445 {
446     BlkdebugAIOCB *acb = container_of(blockacb, BlkdebugAIOCB, common);
447     qemu_aio_release(acb);
448 }
449 
450 static BlockDriverAIOCB *inject_error(BlockDriverState *bs,
451     BlockDriverCompletionFunc *cb, void *opaque, BlkdebugRule *rule)
452 {
453     BDRVBlkdebugState *s = bs->opaque;
454     int error = rule->options.inject.error;
455     struct BlkdebugAIOCB *acb;
456     QEMUBH *bh;
457 
458     if (rule->options.inject.once) {
459         QSIMPLEQ_INIT(&s->active_rules);
460     }
461 
462     if (rule->options.inject.immediately) {
463         return NULL;
464     }
465 
466     acb = qemu_aio_get(&blkdebug_aiocb_info, bs, cb, opaque);
467     acb->ret = -error;
468 
469     bh = qemu_bh_new(error_callback_bh, acb);
470     acb->bh = bh;
471     qemu_bh_schedule(bh);
472 
473     return &acb->common;
474 }
475 
476 static BlockDriverAIOCB *blkdebug_aio_readv(BlockDriverState *bs,
477     int64_t sector_num, QEMUIOVector *qiov, int nb_sectors,
478     BlockDriverCompletionFunc *cb, void *opaque)
479 {
480     BDRVBlkdebugState *s = bs->opaque;
481     BlkdebugRule *rule = NULL;
482 
483     QSIMPLEQ_FOREACH(rule, &s->active_rules, active_next) {
484         if (rule->options.inject.sector == -1 ||
485             (rule->options.inject.sector >= sector_num &&
486              rule->options.inject.sector < sector_num + nb_sectors)) {
487             break;
488         }
489     }
490 
491     if (rule && rule->options.inject.error) {
492         return inject_error(bs, cb, opaque, rule);
493     }
494 
495     return bdrv_aio_readv(bs->file, sector_num, qiov, nb_sectors, cb, opaque);
496 }
497 
498 static BlockDriverAIOCB *blkdebug_aio_writev(BlockDriverState *bs,
499     int64_t sector_num, QEMUIOVector *qiov, int nb_sectors,
500     BlockDriverCompletionFunc *cb, void *opaque)
501 {
502     BDRVBlkdebugState *s = bs->opaque;
503     BlkdebugRule *rule = NULL;
504 
505     QSIMPLEQ_FOREACH(rule, &s->active_rules, active_next) {
506         if (rule->options.inject.sector == -1 ||
507             (rule->options.inject.sector >= sector_num &&
508              rule->options.inject.sector < sector_num + nb_sectors)) {
509             break;
510         }
511     }
512 
513     if (rule && rule->options.inject.error) {
514         return inject_error(bs, cb, opaque, rule);
515     }
516 
517     return bdrv_aio_writev(bs->file, sector_num, qiov, nb_sectors, cb, opaque);
518 }
519 
520 
521 static void blkdebug_close(BlockDriverState *bs)
522 {
523     BDRVBlkdebugState *s = bs->opaque;
524     BlkdebugRule *rule, *next;
525     int i;
526 
527     for (i = 0; i < BLKDBG_EVENT_MAX; i++) {
528         QLIST_FOREACH_SAFE(rule, &s->rules[i], next, next) {
529             remove_rule(rule);
530         }
531     }
532 }
533 
534 static void suspend_request(BlockDriverState *bs, BlkdebugRule *rule)
535 {
536     BDRVBlkdebugState *s = bs->opaque;
537     BlkdebugSuspendedReq r;
538 
539     r = (BlkdebugSuspendedReq) {
540         .co         = qemu_coroutine_self(),
541         .tag        = g_strdup(rule->options.suspend.tag),
542     };
543 
544     remove_rule(rule);
545     QLIST_INSERT_HEAD(&s->suspended_reqs, &r, next);
546 
547     printf("blkdebug: Suspended request '%s'\n", r.tag);
548     qemu_coroutine_yield();
549     printf("blkdebug: Resuming request '%s'\n", r.tag);
550 
551     QLIST_REMOVE(&r, next);
552     g_free(r.tag);
553 }
554 
555 static bool process_rule(BlockDriverState *bs, struct BlkdebugRule *rule,
556     bool injected)
557 {
558     BDRVBlkdebugState *s = bs->opaque;
559 
560     /* Only process rules for the current state */
561     if (rule->state && rule->state != s->state) {
562         return injected;
563     }
564 
565     /* Take the action */
566     switch (rule->action) {
567     case ACTION_INJECT_ERROR:
568         if (!injected) {
569             QSIMPLEQ_INIT(&s->active_rules);
570             injected = true;
571         }
572         QSIMPLEQ_INSERT_HEAD(&s->active_rules, rule, active_next);
573         break;
574 
575     case ACTION_SET_STATE:
576         s->new_state = rule->options.set_state.new_state;
577         break;
578 
579     case ACTION_SUSPEND:
580         suspend_request(bs, rule);
581         break;
582     }
583     return injected;
584 }
585 
586 static void blkdebug_debug_event(BlockDriverState *bs, BlkDebugEvent event)
587 {
588     BDRVBlkdebugState *s = bs->opaque;
589     struct BlkdebugRule *rule, *next;
590     bool injected;
591 
592     assert((int)event >= 0 && event < BLKDBG_EVENT_MAX);
593 
594     injected = false;
595     s->new_state = s->state;
596     QLIST_FOREACH_SAFE(rule, &s->rules[event], next, next) {
597         injected = process_rule(bs, rule, injected);
598     }
599     s->state = s->new_state;
600 }
601 
602 static int blkdebug_debug_breakpoint(BlockDriverState *bs, const char *event,
603                                      const char *tag)
604 {
605     BDRVBlkdebugState *s = bs->opaque;
606     struct BlkdebugRule *rule;
607     BlkDebugEvent blkdebug_event;
608 
609     if (get_event_by_name(event, &blkdebug_event) < 0) {
610         return -ENOENT;
611     }
612 
613 
614     rule = g_malloc(sizeof(*rule));
615     *rule = (struct BlkdebugRule) {
616         .event  = blkdebug_event,
617         .action = ACTION_SUSPEND,
618         .state  = 0,
619         .options.suspend.tag = g_strdup(tag),
620     };
621 
622     QLIST_INSERT_HEAD(&s->rules[blkdebug_event], rule, next);
623 
624     return 0;
625 }
626 
627 static int blkdebug_debug_resume(BlockDriverState *bs, const char *tag)
628 {
629     BDRVBlkdebugState *s = bs->opaque;
630     BlkdebugSuspendedReq *r, *next;
631 
632     QLIST_FOREACH_SAFE(r, &s->suspended_reqs, next, next) {
633         if (!strcmp(r->tag, tag)) {
634             qemu_coroutine_enter(r->co, NULL);
635             return 0;
636         }
637     }
638     return -ENOENT;
639 }
640 
641 static int blkdebug_debug_remove_breakpoint(BlockDriverState *bs,
642                                             const char *tag)
643 {
644     BDRVBlkdebugState *s = bs->opaque;
645     BlkdebugSuspendedReq *r, *r_next;
646     BlkdebugRule *rule, *next;
647     int i, ret = -ENOENT;
648 
649     for (i = 0; i < BLKDBG_EVENT_MAX; i++) {
650         QLIST_FOREACH_SAFE(rule, &s->rules[i], next, next) {
651             if (rule->action == ACTION_SUSPEND &&
652                 !strcmp(rule->options.suspend.tag, tag)) {
653                 remove_rule(rule);
654                 ret = 0;
655             }
656         }
657     }
658     QLIST_FOREACH_SAFE(r, &s->suspended_reqs, next, r_next) {
659         if (!strcmp(r->tag, tag)) {
660             qemu_coroutine_enter(r->co, NULL);
661             ret = 0;
662         }
663     }
664     return ret;
665 }
666 
667 static bool blkdebug_debug_is_suspended(BlockDriverState *bs, const char *tag)
668 {
669     BDRVBlkdebugState *s = bs->opaque;
670     BlkdebugSuspendedReq *r;
671 
672     QLIST_FOREACH(r, &s->suspended_reqs, next) {
673         if (!strcmp(r->tag, tag)) {
674             return true;
675         }
676     }
677     return false;
678 }
679 
680 static int64_t blkdebug_getlength(BlockDriverState *bs)
681 {
682     return bdrv_getlength(bs->file);
683 }
684 
685 static BlockDriver bdrv_blkdebug = {
686     .format_name            = "blkdebug",
687     .protocol_name          = "blkdebug",
688     .instance_size          = sizeof(BDRVBlkdebugState),
689 
690     .bdrv_parse_filename    = blkdebug_parse_filename,
691     .bdrv_file_open         = blkdebug_open,
692     .bdrv_close             = blkdebug_close,
693     .bdrv_getlength         = blkdebug_getlength,
694 
695     .bdrv_aio_readv         = blkdebug_aio_readv,
696     .bdrv_aio_writev        = blkdebug_aio_writev,
697 
698     .bdrv_debug_event           = blkdebug_debug_event,
699     .bdrv_debug_breakpoint      = blkdebug_debug_breakpoint,
700     .bdrv_debug_remove_breakpoint
701                                 = blkdebug_debug_remove_breakpoint,
702     .bdrv_debug_resume          = blkdebug_debug_resume,
703     .bdrv_debug_is_suspended    = blkdebug_debug_is_suspended,
704 };
705 
706 static void bdrv_blkdebug_init(void)
707 {
708     bdrv_register(&bdrv_blkdebug);
709 }
710 
711 block_init(bdrv_blkdebug_init);
712