From patchwork Tue Aug 7 13:44:26 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Benoit Canet X-Patchwork-Id: 175632 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id C90A42C008C for ; Tue, 7 Aug 2012 23:45:13 +1000 (EST) Received: from localhost ([::1]:39747 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Syk5v-0005e3-S7 for incoming@patchwork.ozlabs.org; Tue, 07 Aug 2012 09:45:11 -0400 Received: from eggs.gnu.org ([208.118.235.92]:38395) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Syk5W-0005IE-9L for qemu-devel@nongnu.org; Tue, 07 Aug 2012 09:44:50 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Syk5V-0007wA-2L for qemu-devel@nongnu.org; Tue, 07 Aug 2012 09:44:46 -0400 Received: from mail-we0-f173.google.com ([74.125.82.173]:40626) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Syk5U-0007v3-SJ for qemu-devel@nongnu.org; Tue, 07 Aug 2012 09:44:44 -0400 Received: by mail-we0-f173.google.com with SMTP id z53so2745686wey.4 for ; Tue, 07 Aug 2012 06:44:44 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=from:to:cc:subject:date:message-id:x-mailer:in-reply-to:references; bh=GnH8a9LdKDvcq8nzfWt9i9W0zMpmh8xUskCkW4/Bsi8=; b=gwszkM+crU53aZ1PLiIZOaAQOdxZz8W+J/rFavq/w12zAt/d7aBWxbCn0S2TpnPbK3 kN9u/COC6/WJ7sl9yM4mRMdqYqdBdSXuqI/6teHCuVTTfzCnkY3eYeoMt+l2AsRMPMHS s4nKAZf/p4TM+N/TTe5PrKJllXYAlbj+XHFxwmqxzhNS9qHu7LpmsKb1eP1V69HVfmRu /d5ivAXvpuC059bwLoVfBUIkvjEPsY8iOEpiFJKPeSOHvkbgyEjedhk5HU/aT4VUR0rC tQTKsCKfODhzltV0Ju3ag/tuiUyd0YrxC0P9/FgW/QJcsnv6snif8F21st/1y7iOeM4w 8qWw== Received: by 10.216.208.104 with SMTP id p82mr7681471weo.119.1344347084432; Tue, 07 Aug 2012 06:44:44 -0700 (PDT) Received: from Laure.box.in.irqsave.net (paradis.irqsave.net. [109.190.18.76]) by mx.google.com with ESMTPS id cu1sm21381569wib.6.2012.08.07.06.44.43 (version=TLSv1/SSLv3 cipher=OTHER); Tue, 07 Aug 2012 06:44:43 -0700 (PDT) From: "=?UTF-8?q?Beno=C3=AEt=20Canet?=" To: qemu-devel@nongnu.org Date: Tue, 7 Aug 2012 15:44:26 +0200 Message-Id: <1344347073-7773-4-git-send-email-benoit@irqsave.net> X-Mailer: git-send-email 1.7.9.5 In-Reply-To: <1344347073-7773-1-git-send-email-benoit@irqsave.net> References: <1344347073-7773-1-git-send-email-benoit@irqsave.net> X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 74.125.82.173 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?= Subject: [Qemu-devel] [RFC V2 03/10] quorum: Add quorum_open(). X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org 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)