xilinx: Inline usages of xilinx_axi*_init()
[qemu/rayw.git] / block / quorum.c
blob6c2823971898e3d9bd73812d1bcfeb51e21f0f4e
1 /*
2 * Quorum Block filter
4 * Copyright (C) 2012-2014 Nodalink, EURL.
6 * Author:
7 * BenoƮt Canet <benoit.canet@irqsave.net>
9 * Based on the design and code of blkverify.c (Copyright (C) 2010 IBM, Corp)
10 * and blkmirror.c (Copyright (C) 2011 Red Hat, Inc).
12 * This work is licensed under the terms of the GNU GPL, version 2 or later.
13 * See the COPYING file in the top-level directory.
16 #include <gnutls/gnutls.h>
17 #include <gnutls/crypto.h>
18 #include "block/block_int.h"
19 #include "qapi/qmp/qjson.h"
21 #define HASH_LENGTH 32
23 #define QUORUM_OPT_VOTE_THRESHOLD "vote-threshold"
24 #define QUORUM_OPT_BLKVERIFY "blkverify"
26 /* This union holds a vote hash value */
27 typedef union QuorumVoteValue {
28 char h[HASH_LENGTH]; /* SHA-256 hash */
29 int64_t l; /* simpler 64 bits hash */
30 } QuorumVoteValue;
32 /* A vote item */
33 typedef struct QuorumVoteItem {
34 int index;
35 QLIST_ENTRY(QuorumVoteItem) next;
36 } QuorumVoteItem;
38 /* this structure is a vote version. A version is the set of votes sharing the
39 * same vote value.
40 * The set of votes will be tracked with the items field and its cardinality is
41 * vote_count.
43 typedef struct QuorumVoteVersion {
44 QuorumVoteValue value;
45 int index;
46 int vote_count;
47 QLIST_HEAD(, QuorumVoteItem) items;
48 QLIST_ENTRY(QuorumVoteVersion) next;
49 } QuorumVoteVersion;
51 /* this structure holds a group of vote versions together */
52 typedef struct QuorumVotes {
53 QLIST_HEAD(, QuorumVoteVersion) vote_list;
54 bool (*compare)(QuorumVoteValue *a, QuorumVoteValue *b);
55 } QuorumVotes;
57 /* the following structure holds the state of one quorum instance */
58 typedef struct BDRVQuorumState {
59 BlockDriverState **bs; /* children BlockDriverStates */
60 int num_children; /* children count */
61 int threshold; /* if less than threshold children reads gave the
62 * same result a quorum error occurs.
64 bool is_blkverify; /* true if the driver is in blkverify mode
65 * Writes are mirrored on two children devices.
66 * On reads the two children devices' contents are
67 * compared and if a difference is spotted its
68 * location is printed and the code aborts.
69 * It is useful to debug other block drivers by
70 * comparing them with a reference one.
72 } BDRVQuorumState;
74 typedef struct QuorumAIOCB QuorumAIOCB;
76 /* Quorum will create one instance of the following structure per operation it
77 * performs on its children.
78 * So for each read/write operation coming from the upper layer there will be
79 * $children_count QuorumChildRequest.
81 typedef struct QuorumChildRequest {
82 BlockDriverAIOCB *aiocb;
83 QEMUIOVector qiov;
84 uint8_t *buf;
85 int ret;
86 QuorumAIOCB *parent;
87 } QuorumChildRequest;
89 /* Quorum will use the following structure to track progress of each read/write
90 * operation received by the upper layer.
91 * This structure hold pointers to the QuorumChildRequest structures instances
92 * used to do operations on each children and track overall progress.
94 struct QuorumAIOCB {
95 BlockDriverAIOCB common;
97 /* Request metadata */
98 uint64_t sector_num;
99 int nb_sectors;
101 QEMUIOVector *qiov; /* calling IOV */
103 QuorumChildRequest *qcrs; /* individual child requests */
104 int count; /* number of completed AIOCB */
105 int success_count; /* number of successfully completed AIOCB */
107 QuorumVotes votes;
109 bool is_read;
110 int vote_ret;
113 static void quorum_vote(QuorumAIOCB *acb);
115 static void quorum_aio_cancel(BlockDriverAIOCB *blockacb)
117 QuorumAIOCB *acb = container_of(blockacb, QuorumAIOCB, common);
118 BDRVQuorumState *s = acb->common.bs->opaque;
119 int i;
121 /* cancel all callbacks */
122 for (i = 0; i < s->num_children; i++) {
123 bdrv_aio_cancel(acb->qcrs[i].aiocb);
126 g_free(acb->qcrs);
127 qemu_aio_release(acb);
130 static AIOCBInfo quorum_aiocb_info = {
131 .aiocb_size = sizeof(QuorumAIOCB),
132 .cancel = quorum_aio_cancel,
135 static void quorum_aio_finalize(QuorumAIOCB *acb)
137 BDRVQuorumState *s = acb->common.bs->opaque;
138 int i, ret = 0;
140 if (acb->vote_ret) {
141 ret = acb->vote_ret;
144 acb->common.cb(acb->common.opaque, ret);
146 if (acb->is_read) {
147 for (i = 0; i < s->num_children; i++) {
148 qemu_vfree(acb->qcrs[i].buf);
149 qemu_iovec_destroy(&acb->qcrs[i].qiov);
153 g_free(acb->qcrs);
154 qemu_aio_release(acb);
157 static bool quorum_sha256_compare(QuorumVoteValue *a, QuorumVoteValue *b)
159 return !memcmp(a->h, b->h, HASH_LENGTH);
162 static bool quorum_64bits_compare(QuorumVoteValue *a, QuorumVoteValue *b)
164 return a->l == b->l;
167 static QuorumAIOCB *quorum_aio_get(BDRVQuorumState *s,
168 BlockDriverState *bs,
169 QEMUIOVector *qiov,
170 uint64_t sector_num,
171 int nb_sectors,
172 BlockDriverCompletionFunc *cb,
173 void *opaque)
175 QuorumAIOCB *acb = qemu_aio_get(&quorum_aiocb_info, bs, cb, opaque);
176 int i;
178 acb->common.bs->opaque = s;
179 acb->sector_num = sector_num;
180 acb->nb_sectors = nb_sectors;
181 acb->qiov = qiov;
182 acb->qcrs = g_new0(QuorumChildRequest, s->num_children);
183 acb->count = 0;
184 acb->success_count = 0;
185 acb->votes.compare = quorum_sha256_compare;
186 QLIST_INIT(&acb->votes.vote_list);
187 acb->is_read = false;
188 acb->vote_ret = 0;
190 for (i = 0; i < s->num_children; i++) {
191 acb->qcrs[i].buf = NULL;
192 acb->qcrs[i].ret = 0;
193 acb->qcrs[i].parent = acb;
196 return acb;
199 static void quorum_report_bad(QuorumAIOCB *acb, char *node_name, int ret)
201 QObject *data;
202 assert(node_name);
203 data = qobject_from_jsonf("{ 'ret': %d"
204 ", 'node-name': %s"
205 ", 'sector-num': %" PRId64
206 ", 'sectors-count': %d }",
207 ret, node_name, acb->sector_num, acb->nb_sectors);
208 monitor_protocol_event(QEVENT_QUORUM_REPORT_BAD, data);
209 qobject_decref(data);
212 static void quorum_report_failure(QuorumAIOCB *acb)
214 QObject *data;
215 const char *reference = acb->common.bs->device_name[0] ?
216 acb->common.bs->device_name :
217 acb->common.bs->node_name;
218 data = qobject_from_jsonf("{ 'reference': %s"
219 ", 'sector-num': %" PRId64
220 ", 'sectors-count': %d }",
221 reference, acb->sector_num, acb->nb_sectors);
222 monitor_protocol_event(QEVENT_QUORUM_FAILURE, data);
223 qobject_decref(data);
226 static int quorum_vote_error(QuorumAIOCB *acb);
228 static bool quorum_has_too_much_io_failed(QuorumAIOCB *acb)
230 BDRVQuorumState *s = acb->common.bs->opaque;
232 if (acb->success_count < s->threshold) {
233 acb->vote_ret = quorum_vote_error(acb);
234 quorum_report_failure(acb);
235 return true;
238 return false;
241 static void quorum_aio_cb(void *opaque, int ret)
243 QuorumChildRequest *sacb = opaque;
244 QuorumAIOCB *acb = sacb->parent;
245 BDRVQuorumState *s = acb->common.bs->opaque;
247 sacb->ret = ret;
248 acb->count++;
249 if (ret == 0) {
250 acb->success_count++;
251 } else {
252 quorum_report_bad(acb, sacb->aiocb->bs->node_name, ret);
254 assert(acb->count <= s->num_children);
255 assert(acb->success_count <= s->num_children);
256 if (acb->count < s->num_children) {
257 return;
260 /* Do the vote on read */
261 if (acb->is_read) {
262 quorum_vote(acb);
263 } else {
264 quorum_has_too_much_io_failed(acb);
267 quorum_aio_finalize(acb);
270 static void quorum_report_bad_versions(BDRVQuorumState *s,
271 QuorumAIOCB *acb,
272 QuorumVoteValue *value)
274 QuorumVoteVersion *version;
275 QuorumVoteItem *item;
277 QLIST_FOREACH(version, &acb->votes.vote_list, next) {
278 if (acb->votes.compare(&version->value, value)) {
279 continue;
281 QLIST_FOREACH(item, &version->items, next) {
282 quorum_report_bad(acb, s->bs[item->index]->node_name, 0);
287 static void quorum_copy_qiov(QEMUIOVector *dest, QEMUIOVector *source)
289 int i;
290 assert(dest->niov == source->niov);
291 assert(dest->size == source->size);
292 for (i = 0; i < source->niov; i++) {
293 assert(dest->iov[i].iov_len == source->iov[i].iov_len);
294 memcpy(dest->iov[i].iov_base,
295 source->iov[i].iov_base,
296 source->iov[i].iov_len);
300 static void quorum_count_vote(QuorumVotes *votes,
301 QuorumVoteValue *value,
302 int index)
304 QuorumVoteVersion *v = NULL, *version = NULL;
305 QuorumVoteItem *item;
307 /* look if we have something with this hash */
308 QLIST_FOREACH(v, &votes->vote_list, next) {
309 if (votes->compare(&v->value, value)) {
310 version = v;
311 break;
315 /* It's a version not yet in the list add it */
316 if (!version) {
317 version = g_new0(QuorumVoteVersion, 1);
318 QLIST_INIT(&version->items);
319 memcpy(&version->value, value, sizeof(version->value));
320 version->index = index;
321 version->vote_count = 0;
322 QLIST_INSERT_HEAD(&votes->vote_list, version, next);
325 version->vote_count++;
327 item = g_new0(QuorumVoteItem, 1);
328 item->index = index;
329 QLIST_INSERT_HEAD(&version->items, item, next);
332 static void quorum_free_vote_list(QuorumVotes *votes)
334 QuorumVoteVersion *version, *next_version;
335 QuorumVoteItem *item, *next_item;
337 QLIST_FOREACH_SAFE(version, &votes->vote_list, next, next_version) {
338 QLIST_REMOVE(version, next);
339 QLIST_FOREACH_SAFE(item, &version->items, next, next_item) {
340 QLIST_REMOVE(item, next);
341 g_free(item);
343 g_free(version);
347 static int quorum_compute_hash(QuorumAIOCB *acb, int i, QuorumVoteValue *hash)
349 int j, ret;
350 gnutls_hash_hd_t dig;
351 QEMUIOVector *qiov = &acb->qcrs[i].qiov;
353 ret = gnutls_hash_init(&dig, GNUTLS_DIG_SHA256);
355 if (ret < 0) {
356 return ret;
359 for (j = 0; j < qiov->niov; j++) {
360 ret = gnutls_hash(dig, qiov->iov[j].iov_base, qiov->iov[j].iov_len);
361 if (ret < 0) {
362 break;
366 gnutls_hash_deinit(dig, (void *) hash);
367 return ret;
370 static QuorumVoteVersion *quorum_get_vote_winner(QuorumVotes *votes)
372 int max = 0;
373 QuorumVoteVersion *candidate, *winner = NULL;
375 QLIST_FOREACH(candidate, &votes->vote_list, next) {
376 if (candidate->vote_count > max) {
377 max = candidate->vote_count;
378 winner = candidate;
382 return winner;
385 /* qemu_iovec_compare is handy for blkverify mode because it returns the first
386 * differing byte location. Yet it is handcoded to compare vectors one byte
387 * after another so it does not benefit from the libc SIMD optimizations.
388 * quorum_iovec_compare is written for speed and should be used in the non
389 * blkverify mode of quorum.
391 static bool quorum_iovec_compare(QEMUIOVector *a, QEMUIOVector *b)
393 int i;
394 int result;
396 assert(a->niov == b->niov);
397 for (i = 0; i < a->niov; i++) {
398 assert(a->iov[i].iov_len == b->iov[i].iov_len);
399 result = memcmp(a->iov[i].iov_base,
400 b->iov[i].iov_base,
401 a->iov[i].iov_len);
402 if (result) {
403 return false;
407 return true;
410 static void GCC_FMT_ATTR(2, 3) quorum_err(QuorumAIOCB *acb,
411 const char *fmt, ...)
413 va_list ap;
415 va_start(ap, fmt);
416 fprintf(stderr, "quorum: sector_num=%" PRId64 " nb_sectors=%d ",
417 acb->sector_num, acb->nb_sectors);
418 vfprintf(stderr, fmt, ap);
419 fprintf(stderr, "\n");
420 va_end(ap);
421 exit(1);
424 static bool quorum_compare(QuorumAIOCB *acb,
425 QEMUIOVector *a,
426 QEMUIOVector *b)
428 BDRVQuorumState *s = acb->common.bs->opaque;
429 ssize_t offset;
431 /* This driver will replace blkverify in this particular case */
432 if (s->is_blkverify) {
433 offset = qemu_iovec_compare(a, b);
434 if (offset != -1) {
435 quorum_err(acb, "contents mismatch in sector %" PRId64,
436 acb->sector_num +
437 (uint64_t)(offset / BDRV_SECTOR_SIZE));
439 return true;
442 return quorum_iovec_compare(a, b);
445 /* Do a vote to get the error code */
446 static int quorum_vote_error(QuorumAIOCB *acb)
448 BDRVQuorumState *s = acb->common.bs->opaque;
449 QuorumVoteVersion *winner = NULL;
450 QuorumVotes error_votes;
451 QuorumVoteValue result_value;
452 int i, ret = 0;
453 bool error = false;
455 QLIST_INIT(&error_votes.vote_list);
456 error_votes.compare = quorum_64bits_compare;
458 for (i = 0; i < s->num_children; i++) {
459 ret = acb->qcrs[i].ret;
460 if (ret) {
461 error = true;
462 result_value.l = ret;
463 quorum_count_vote(&error_votes, &result_value, i);
467 if (error) {
468 winner = quorum_get_vote_winner(&error_votes);
469 ret = winner->value.l;
472 quorum_free_vote_list(&error_votes);
474 return ret;
477 static void quorum_vote(QuorumAIOCB *acb)
479 bool quorum = true;
480 int i, j, ret;
481 QuorumVoteValue hash;
482 BDRVQuorumState *s = acb->common.bs->opaque;
483 QuorumVoteVersion *winner;
485 if (quorum_has_too_much_io_failed(acb)) {
486 return;
489 /* get the index of the first successful read */
490 for (i = 0; i < s->num_children; i++) {
491 if (!acb->qcrs[i].ret) {
492 break;
496 assert(i < s->num_children);
498 /* compare this read with all other successful reads stopping at quorum
499 * failure
501 for (j = i + 1; j < s->num_children; j++) {
502 if (acb->qcrs[j].ret) {
503 continue;
505 quorum = quorum_compare(acb, &acb->qcrs[i].qiov, &acb->qcrs[j].qiov);
506 if (!quorum) {
507 break;
511 /* Every successful read agrees */
512 if (quorum) {
513 quorum_copy_qiov(acb->qiov, &acb->qcrs[i].qiov);
514 return;
517 /* compute hashes for each successful read, also store indexes */
518 for (i = 0; i < s->num_children; i++) {
519 if (acb->qcrs[i].ret) {
520 continue;
522 ret = quorum_compute_hash(acb, i, &hash);
523 /* if ever the hash computation failed */
524 if (ret < 0) {
525 acb->vote_ret = ret;
526 goto free_exit;
528 quorum_count_vote(&acb->votes, &hash, i);
531 /* vote to select the most represented version */
532 winner = quorum_get_vote_winner(&acb->votes);
534 /* if the winner count is smaller than threshold the read fails */
535 if (winner->vote_count < s->threshold) {
536 quorum_report_failure(acb);
537 acb->vote_ret = -EIO;
538 goto free_exit;
541 /* we have a winner: copy it */
542 quorum_copy_qiov(acb->qiov, &acb->qcrs[winner->index].qiov);
544 /* some versions are bad print them */
545 quorum_report_bad_versions(s, acb, &winner->value);
547 free_exit:
548 /* free lists */
549 quorum_free_vote_list(&acb->votes);
552 static BlockDriverAIOCB *quorum_aio_readv(BlockDriverState *bs,
553 int64_t sector_num,
554 QEMUIOVector *qiov,
555 int nb_sectors,
556 BlockDriverCompletionFunc *cb,
557 void *opaque)
559 BDRVQuorumState *s = bs->opaque;
560 QuorumAIOCB *acb = quorum_aio_get(s, bs, qiov, sector_num,
561 nb_sectors, cb, opaque);
562 int i;
564 acb->is_read = true;
566 for (i = 0; i < s->num_children; i++) {
567 acb->qcrs[i].buf = qemu_blockalign(s->bs[i], qiov->size);
568 qemu_iovec_init(&acb->qcrs[i].qiov, qiov->niov);
569 qemu_iovec_clone(&acb->qcrs[i].qiov, qiov, acb->qcrs[i].buf);
572 for (i = 0; i < s->num_children; i++) {
573 bdrv_aio_readv(s->bs[i], sector_num, &acb->qcrs[i].qiov, nb_sectors,
574 quorum_aio_cb, &acb->qcrs[i]);
577 return &acb->common;
580 static BlockDriverAIOCB *quorum_aio_writev(BlockDriverState *bs,
581 int64_t sector_num,
582 QEMUIOVector *qiov,
583 int nb_sectors,
584 BlockDriverCompletionFunc *cb,
585 void *opaque)
587 BDRVQuorumState *s = bs->opaque;
588 QuorumAIOCB *acb = quorum_aio_get(s, bs, qiov, sector_num, nb_sectors,
589 cb, opaque);
590 int i;
592 for (i = 0; i < s->num_children; i++) {
593 acb->qcrs[i].aiocb = bdrv_aio_writev(s->bs[i], sector_num, qiov,
594 nb_sectors, &quorum_aio_cb,
595 &acb->qcrs[i]);
598 return &acb->common;
601 static int64_t quorum_getlength(BlockDriverState *bs)
603 BDRVQuorumState *s = bs->opaque;
604 int64_t result;
605 int i;
607 /* check that all file have the same length */
608 result = bdrv_getlength(s->bs[0]);
609 if (result < 0) {
610 return result;
612 for (i = 1; i < s->num_children; i++) {
613 int64_t value = bdrv_getlength(s->bs[i]);
614 if (value < 0) {
615 return value;
617 if (value != result) {
618 return -EIO;
622 return result;
625 static void quorum_invalidate_cache(BlockDriverState *bs)
627 BDRVQuorumState *s = bs->opaque;
628 int i;
630 for (i = 0; i < s->num_children; i++) {
631 bdrv_invalidate_cache(s->bs[i]);
635 static coroutine_fn int quorum_co_flush(BlockDriverState *bs)
637 BDRVQuorumState *s = bs->opaque;
638 QuorumVoteVersion *winner = NULL;
639 QuorumVotes error_votes;
640 QuorumVoteValue result_value;
641 int i;
642 int result = 0;
644 QLIST_INIT(&error_votes.vote_list);
645 error_votes.compare = quorum_64bits_compare;
647 for (i = 0; i < s->num_children; i++) {
648 result = bdrv_co_flush(s->bs[i]);
649 result_value.l = result;
650 quorum_count_vote(&error_votes, &result_value, i);
653 winner = quorum_get_vote_winner(&error_votes);
654 result = winner->value.l;
656 quorum_free_vote_list(&error_votes);
658 return result;
661 static bool quorum_recurse_is_first_non_filter(BlockDriverState *bs,
662 BlockDriverState *candidate)
664 BDRVQuorumState *s = bs->opaque;
665 int i;
667 for (i = 0; i < s->num_children; i++) {
668 bool perm = bdrv_recurse_is_first_non_filter(s->bs[i],
669 candidate);
670 if (perm) {
671 return true;
675 return false;
678 static int quorum_valid_threshold(int threshold, int num_children, Error **errp)
681 if (threshold < 1) {
682 error_set(errp, QERR_INVALID_PARAMETER_VALUE,
683 "vote-threshold", "value >= 1");
684 return -ERANGE;
687 if (threshold > num_children) {
688 error_setg(errp, "threshold may not exceed children count");
689 return -ERANGE;
692 return 0;
695 static QemuOptsList quorum_runtime_opts = {
696 .name = "quorum",
697 .head = QTAILQ_HEAD_INITIALIZER(quorum_runtime_opts.head),
698 .desc = {
700 .name = QUORUM_OPT_VOTE_THRESHOLD,
701 .type = QEMU_OPT_NUMBER,
702 .help = "The number of vote needed for reaching quorum",
705 .name = QUORUM_OPT_BLKVERIFY,
706 .type = QEMU_OPT_BOOL,
707 .help = "Trigger block verify mode if set",
709 { /* end of list */ }
713 static int quorum_open(BlockDriverState *bs, QDict *options, int flags,
714 Error **errp)
716 BDRVQuorumState *s = bs->opaque;
717 Error *local_err = NULL;
718 QemuOpts *opts;
719 bool *opened;
720 QDict *sub = NULL;
721 QList *list = NULL;
722 const QListEntry *lentry;
723 int i;
724 int ret = 0;
726 qdict_flatten(options);
727 qdict_extract_subqdict(options, &sub, "children.");
728 qdict_array_split(sub, &list);
730 if (qdict_size(sub)) {
731 error_setg(&local_err, "Invalid option children.%s",
732 qdict_first(sub)->key);
733 ret = -EINVAL;
734 goto exit;
737 /* count how many different children are present */
738 s->num_children = qlist_size(list);
739 if (s->num_children < 2) {
740 error_setg(&local_err,
741 "Number of provided children must be greater than 1");
742 ret = -EINVAL;
743 goto exit;
746 opts = qemu_opts_create(&quorum_runtime_opts, NULL, 0, &error_abort);
747 qemu_opts_absorb_qdict(opts, options, &local_err);
748 if (error_is_set(&local_err)) {
749 ret = -EINVAL;
750 goto exit;
753 s->threshold = qemu_opt_get_number(opts, QUORUM_OPT_VOTE_THRESHOLD, 0);
755 /* and validate it against s->num_children */
756 ret = quorum_valid_threshold(s->threshold, s->num_children, &local_err);
757 if (ret < 0) {
758 goto exit;
761 /* is the driver in blkverify mode */
762 if (qemu_opt_get_bool(opts, QUORUM_OPT_BLKVERIFY, false) &&
763 s->num_children == 2 && s->threshold == 2) {
764 s->is_blkverify = true;
765 } else if (qemu_opt_get_bool(opts, QUORUM_OPT_BLKVERIFY, false)) {
766 fprintf(stderr, "blkverify mode is set by setting blkverify=on "
767 "and using two files with vote_threshold=2\n");
770 /* allocate the children BlockDriverState array */
771 s->bs = g_new0(BlockDriverState *, s->num_children);
772 opened = g_new0(bool, s->num_children);
774 for (i = 0, lentry = qlist_first(list); lentry;
775 lentry = qlist_next(lentry), i++) {
776 QDict *d;
777 QString *string;
779 switch (qobject_type(lentry->value))
781 /* List of options */
782 case QTYPE_QDICT:
783 d = qobject_to_qdict(lentry->value);
784 QINCREF(d);
785 ret = bdrv_open(&s->bs[i], NULL, NULL, d, flags, NULL,
786 &local_err);
787 break;
789 /* QMP reference */
790 case QTYPE_QSTRING:
791 string = qobject_to_qstring(lentry->value);
792 ret = bdrv_open(&s->bs[i], NULL, qstring_get_str(string), NULL,
793 flags, NULL, &local_err);
794 break;
796 default:
797 error_setg(&local_err, "Specification of child block device %i "
798 "is invalid", i);
799 ret = -EINVAL;
802 if (ret < 0) {
803 goto close_exit;
805 opened[i] = true;
808 g_free(opened);
809 goto exit;
811 close_exit:
812 /* cleanup on error */
813 for (i = 0; i < s->num_children; i++) {
814 if (!opened[i]) {
815 continue;
817 bdrv_unref(s->bs[i]);
819 g_free(s->bs);
820 g_free(opened);
821 exit:
822 /* propagate error */
823 if (error_is_set(&local_err)) {
824 error_propagate(errp, local_err);
826 QDECREF(list);
827 QDECREF(sub);
828 return ret;
831 static void quorum_close(BlockDriverState *bs)
833 BDRVQuorumState *s = bs->opaque;
834 int i;
836 for (i = 0; i < s->num_children; i++) {
837 bdrv_unref(s->bs[i]);
840 g_free(s->bs);
843 static BlockDriver bdrv_quorum = {
844 .format_name = "quorum",
845 .protocol_name = "quorum",
847 .instance_size = sizeof(BDRVQuorumState),
849 .bdrv_file_open = quorum_open,
850 .bdrv_close = quorum_close,
852 .authorizations = { true, true },
854 .bdrv_co_flush_to_disk = quorum_co_flush,
856 .bdrv_getlength = quorum_getlength,
858 .bdrv_aio_readv = quorum_aio_readv,
859 .bdrv_aio_writev = quorum_aio_writev,
860 .bdrv_invalidate_cache = quorum_invalidate_cache,
862 .bdrv_recurse_is_first_non_filter = quorum_recurse_is_first_non_filter,
865 static void bdrv_quorum_init(void)
867 bdrv_register(&bdrv_quorum);
870 block_init(bdrv_quorum_init);