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