qemu-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Qemu-devel] [RFC 04/12] qorum: Add qorum_open().


From: Benoît Canet
Subject: [Qemu-devel] [RFC 04/12] qorum: Add qorum_open().
Date: Thu, 2 Aug 2012 12:16:36 +0200

Signed-off-by: Benoit Canet <address@hidden>
---
 block/qorum.c |   62 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 62 insertions(+)

diff --git a/block/qorum.c b/block/qorum.c
index ea2a720..bdf1530 100644
--- a/block/qorum.c
+++ b/block/qorum.c
@@ -48,11 +48,73 @@ struct QorumAIOCB {
     int vote_ret;
 };
 
+/* Valid qorum filenames look like
+ * qorum:path/to/a_image:path/to/b_image:path/to/c_image
+ */
+static int qorum_open(BlockDriverState *bs, const char *filename, int flags)
+{
+    BDRVQorumState *s = bs->opaque;
+    int ret, i;
+    char *a, *b, *c, *filenames[3];
+
+    /* Parse the qorum: prefix */
+    if (strncmp(filename, "qorum:", strlen("qorum:"))) {
+        return -EINVAL;
+    }
+    a = g_strdup(filename + strlen("qorum:"));
+
+    /* 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_qorum = {
     .format_name        = "qorum",
     .protocol_name      = "qorum",
 
     .instance_size      = sizeof(BDRVQorumState),
+
+    .bdrv_file_open     = qorum_open,
 };
 
 static void bdrv_qorum_init(void)
-- 
1.7.9.5




reply via email to

[Prev in Thread] Current Thread [Next in Thread]