From patchwork Tue Aug 7 13:44:26 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: [RFC,V2,03/10] quorum: Add quorum_open(). From: Benoit Canet X-Patchwork-Id: 175632 Message-Id: <1344347073-7773-4-git-send-email-benoit@irqsave.net> To: qemu-devel@nongnu.org Cc: kwolf@redhat.com, stefanha@linux.vnet.ibm.com, blauwirbel@gmail.com, anthony@codemonkey.ws, pbonzini@redhat.com, eblake@redhat.com, afaerber@suse.de, =?UTF-8?q?Beno=C3=AEt=20Canet?= Date: Tue, 7 Aug 2012 15:44:26 +0200 Signed-off-by: Benoit Canet --- block/quorum.c | 62 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 62 insertions(+) diff --git a/block/quorum.c b/block/quorum.c index e0405b6..de58ab8 100644 --- a/block/quorum.c +++ b/block/quorum.c @@ -47,11 +47,73 @@ struct QuorumAIOCB { int vote_ret; }; +/* Valid quorum filenames look like + * quorum:path/to/a_image:path/to/b_image:path/to/c_image + */ +static int quorum_open(BlockDriverState *bs, const char *filename, int flags) +{ + BDRVQuorumState *s = bs->opaque; + int ret, i; + char *a, *b, *c, *filenames[3]; + + /* Parse the quorum: prefix */ + if (strncmp(filename, "quorum:", strlen("quorum:"))) { + return -EINVAL; + } + a = g_strdup(filename + strlen("quorum:")); + + /* Find separators */ + b = strchr(a, ':'); + if (b == NULL) { + return -EINVAL; + } + + c = strrchr(a, ':'); + if (c == NULL) { + return -EINVAL; + } + + /* Check that filename contains two separate ':' */ + if (b == c) { + return -EINVAL; + } + + /* Split string */ + *b = '\0'; + *c = '\0'; + + filenames[0] = a; + filenames[1] = b + 1; + filenames[2] = c + 1; + + /* Open files */ + for (i = 0; i <= 2; i++) { + s->bs[i] = bdrv_new(""); + ret = bdrv_open(s->bs[i], filenames[i], flags, NULL); + if (ret < 0) { + goto error_exit; + } + } + + goto clean_exit; + +error_exit: + for (; i >= 0; i--) { + bdrv_delete(s->bs[i]); + s->bs[i] = NULL; + } +clean_exit: + g_free(a); + return ret; +} + static BlockDriver bdrv_quorum = { .format_name = "quorum", .protocol_name = "quorum", .instance_size = sizeof(BDRVQuorumState), + + .bdrv_file_open = quorum_open, }; static void bdrv_quorum_init(void)