From patchwork Thu Oct 20 13:57:36 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Zhanghailiang X-Patchwork-Id: 9386971 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 903A960762 for ; Thu, 20 Oct 2016 14:38:00 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 7FA4729C9F for ; Thu, 20 Oct 2016 14:38:00 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 726BA29C9E; Thu, 20 Oct 2016 14:38:00 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.9 required=2.0 tests=BAYES_00,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id B497D29C8A for ; Thu, 20 Oct 2016 14:37:59 +0000 (UTC) Received: from localhost ([::1]:55227 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bxETm-00086V-RF for patchwork-qemu-devel@patchwork.kernel.org; Thu, 20 Oct 2016 10:37:58 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:36436) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bxDs4-0003Ea-1V for qemu-devel@nongnu.org; Thu, 20 Oct 2016 09:59:01 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1bxDrz-0000UD-Un for qemu-devel@nongnu.org; Thu, 20 Oct 2016 09:59:00 -0400 Received: from szxga01-in.huawei.com ([58.251.152.64]:47177) by eggs.gnu.org with esmtps (TLS1.0:RSA_ARCFOUR_SHA1:16) (Exim 4.71) (envelope-from ) id 1bxDrz-0000TE-4S; Thu, 20 Oct 2016 09:58:55 -0400 Received: from 172.24.1.36 (EHLO szxeml425-hub.china.huawei.com) ([172.24.1.36]) by szxrg01-dlp.huawei.com (MOS 4.3.7-GA FastPath queued) with ESMTP id DTR31879; Thu, 20 Oct 2016 21:58:28 +0800 (CST) Received: from localhost (10.177.24.212) by szxeml425-hub.china.huawei.com (10.82.67.180) with Microsoft SMTP Server id 14.3.235.1; Thu, 20 Oct 2016 21:58:20 +0800 From: zhanghailiang To: , Date: Thu, 20 Oct 2016 21:57:36 +0800 Message-ID: <1476971860-20860-4-git-send-email-zhang.zhanghailiang@huawei.com> X-Mailer: git-send-email 2.7.2.windows.1 In-Reply-To: <1476971860-20860-1-git-send-email-zhang.zhanghailiang@huawei.com> References: <1476971860-20860-1-git-send-email-zhang.zhanghailiang@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.177.24.212] X-CFilter-Loop: Reflected X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.4.x-2.6.x [generic] X-Received-From: 58.251.152.64 Subject: [Qemu-devel] [PATCH RFC 3/7] replication: add shared-disk and shared-disk-id options X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: kwolf@redhat.com, xiecl.fnst@cn.fujitsu.com, Zhang Chen , zhanghailiang , mreitz@redhat.com, stefanha@redhat.com, pbonzini@redhat.com Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP We use these two options to identify which disk is shared Signed-off-by: zhanghailiang Signed-off-by: Wen Congyang Signed-off-by: Zhang Chen --- block/replication.c | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/block/replication.c b/block/replication.c index 3bd1cf1..2a2fdb2 100644 --- a/block/replication.c +++ b/block/replication.c @@ -25,9 +25,12 @@ typedef struct BDRVReplicationState { ReplicationMode mode; int replication_state; + bool is_shared_disk; + char *shared_disk_id; BdrvChild *active_disk; BdrvChild *hidden_disk; BdrvChild *secondary_disk; + BdrvChild *primary_disk; char *top_id; ReplicationState *rs; Error *blocker; @@ -53,6 +56,9 @@ static void replication_stop(ReplicationState *rs, bool failover, #define REPLICATION_MODE "mode" #define REPLICATION_TOP_ID "top-id" +#define REPLICATION_SHARED_DISK "shared-disk" +#define REPLICATION_SHARED_DISK_ID "shared-disk-id" + static QemuOptsList replication_runtime_opts = { .name = "replication", .head = QTAILQ_HEAD_INITIALIZER(replication_runtime_opts.head), @@ -65,6 +71,14 @@ static QemuOptsList replication_runtime_opts = { .name = REPLICATION_TOP_ID, .type = QEMU_OPT_STRING, }, + { + .name = REPLICATION_SHARED_DISK_ID, + .type = QEMU_OPT_STRING, + }, + { + .name = REPLICATION_SHARED_DISK, + .type = QEMU_OPT_BOOL, + }, { /* end of list */ } }, }; @@ -85,6 +99,8 @@ static int replication_open(BlockDriverState *bs, QDict *options, QemuOpts *opts = NULL; const char *mode; const char *top_id; + const char *shared_disk_id; + BlockBackend *blk; ret = -EINVAL; opts = qemu_opts_create(&replication_runtime_opts, NULL, 0, &error_abort); @@ -114,6 +130,22 @@ static int replication_open(BlockDriverState *bs, QDict *options, "The option mode's value should be primary or secondary"); goto fail; } + s->is_shared_disk = qemu_opt_get_bool(opts, REPLICATION_SHARED_DISK, + false); + if (s->is_shared_disk && (s->mode == REPLICATION_MODE_PRIMARY)) { + shared_disk_id = qemu_opt_get(opts, REPLICATION_SHARED_DISK_ID); + if (!shared_disk_id) { + error_setg(&local_err, "Missing shared disk blk"); + goto fail; + } + s->shared_disk_id = g_strdup(shared_disk_id); + blk = blk_by_name(s->shared_disk_id); + if (!blk) { + error_setg(&local_err, "There is no %s block", s->shared_disk_id); + goto fail; + } + s->primary_disk = blk_root(blk); + } s->rs = replication_new(bs, &replication_ops); @@ -130,6 +162,7 @@ static void replication_close(BlockDriverState *bs) { BDRVReplicationState *s = bs->opaque; + g_free(s->shared_disk_id); if (s->replication_state == BLOCK_REPLICATION_RUNNING) { replication_stop(s->rs, false, NULL); }