@@ -816,12 +816,77 @@ static int quorum_snapshot_reopen(BlockDriverState *bs, int bdrv_flags,
return ret;
}
+/* Valid quorum resources look like
+ * quorum:threshold/total:path/to/image_1: ... :path/to/image_total
+ *
+ * ':' is used as a separator
+ * '\' is the escaping character for filename containing ':'
+ */
+static int quorum_open(BlockDriverState *bs, const char *filename, int flags)
+{
+ BDRVQuorumState *s = bs->opaque;
+ Error *local_err = NULL;
+ int ret = 0;
+ int i;
+
+ ret = quorum_parse_url(s, filename, &local_err);
+ if (ret < 0) {
+ goto exit;
+ }
+
+ ret = quorum_validate_url(s, ret, &local_err);
+ if (ret < 0) {
+ goto free_exit;
+ }
+
+ /* Open files */
+ for (i = 0; i < s->total; i++) {
+ s->bs[i] = bdrv_new("");
+ ret = bdrv_open(s->bs[i], s->filenames[i], flags, NULL);
+ if (ret < 0) {
+ goto error_exit;
+ }
+ }
+
+ goto exit;
+
+error_exit:
+ for (; i >= 0; i--) {
+ bdrv_delete(s->bs[i]);
+ s->bs[i] = NULL;
+ }
+free_exit:
+ quorum_free(s);
+exit:
+ if (error_is_set(&local_err)) {
+ qerror_report_err(local_err);
+ }
+ return ret;
+}
+
+static void quorum_close(BlockDriverState *bs)
+{
+ BDRVQuorumState *s = bs->opaque;
+ int i;
+
+ for (i = 0; i < s->total; i++) {
+ /* Ensure writes reach stable storage */
+ bdrv_flush(s->bs[i]);
+ bdrv_delete(s->bs[i]);
+ }
+
+ quorum_free(s);
+}
+
static BlockDriver bdrv_quorum = {
.format_name = "quorum",
.protocol_name = "quorum",
.instance_size = sizeof(BDRVQuorumState),
+ .bdrv_file_open = quorum_open,
+ .bdrv_close = quorum_close,
+
.bdrv_co_flush_to_disk = quorum_co_flush,
.bdrv_getlength = quorum_getlength,
Valid quorum resources look like quorum:threshold/total:path/to/image_1: ... :path/to/image_total ':' is used as a separator '\' is the escaping character for filename containing ':' '\' escape itself ',' must be escaped with ',' On the command line for quorum files "img:test.raw", "img2,raw" and "img3.raw" invocation look like: -drive file=quorum:2/3:img\\:test.raw:img2,,raw:img3.raw (note the double \\ and the double ,,) Signed-off-by: Benoit Canet <benoit@irqsave.net> --- block/quorum.c | 65 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 65 insertions(+)