From nobody Tue Feb 10 05:41:41 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zoho.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1492006070367570.5131231147786; Wed, 12 Apr 2017 07:07:50 -0700 (PDT) Received: from localhost ([::1]:44546 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cyIw0-0003sr-SW for importer@patchew.org; Wed, 12 Apr 2017 10:07:48 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:36517) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cyIuV-0002sN-Dd for qemu-devel@nongnu.org; Wed, 12 Apr 2017 10:06:17 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1cyIuR-00016W-8V for qemu-devel@nongnu.org; Wed, 12 Apr 2017 10:06:15 -0400 Received: from szxga03-in.huawei.com ([45.249.212.189]:3367 helo=dggrg03-dlp.huawei.com) by eggs.gnu.org with esmtps (TLS1.0:RSA_ARCFOUR_SHA1:16) (Exim 4.71) (envelope-from ) id 1cyIuF-0000tT-UZ; Wed, 12 Apr 2017 10:06:00 -0400 Received: from 172.30.72.55 (EHLO DGGEML403-HUB.china.huawei.com) ([172.30.72.55]) by dggrg03-dlp.huawei.com (MOS 4.4.6-GA FastPath queued) with ESMTP id ALP11469; Wed, 12 Apr 2017 22:05:50 +0800 (CST) Received: from localhost (10.177.24.212) by DGGEML403-HUB.china.huawei.com (10.3.17.33) with Microsoft SMTP Server id 14.3.301.0; Wed, 12 Apr 2017 22:05:39 +0800 From: zhanghailiang To: , Date: Wed, 12 Apr 2017 22:05:17 +0800 Message-ID: <1492005921-15664-3-git-send-email-zhang.zhanghailiang@huawei.com> X-Mailer: git-send-email 2.7.2.windows.1 In-Reply-To: <1492005921-15664-1-git-send-email-zhang.zhanghailiang@huawei.com> References: <1492005921-15664-1-git-send-email-zhang.zhanghailiang@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.177.24.212] X-CFilter-Loop: Reflected X-Mirapoint-Virus-RAPID-Raw: score=unknown(0), refid=str=0001.0A020205.58EE3440.0330, ss=1, re=0.000, recu=0.000, reip=0.000, cl=1, cld=1, fgs=0, ip=0.0.0.0, so=2014-11-16 11:51:01, dmn=2013-03-21 17:37:32 X-Mirapoint-Loop-Id: c48c0529f8388afef3a51dbbd290e8dc X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.4.x-2.6.x [generic] [fuzzy] X-Received-From: 45.249.212.189 Subject: [Qemu-devel] [PATCH v4 2/6] 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, zhangchen.fnst@cn.fujitsu.com, Wen Congyang , qemu-block@nongnu.org, zhanghailiang Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" 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 Reviewed-by: Stefan Hajnoczi --- v4: - Add proper comment for primary_disk (Stefan) v2: - Move g_free(s->shared_disk_id) to the common fail process place (Stefan) - Fix comments for these two options --- block/replication.c | 43 +++++++++++++++++++++++++++++++++++++++++-- qapi/block-core.json | 10 +++++++++- 2 files changed, 50 insertions(+), 3 deletions(-) diff --git a/block/replication.c b/block/replication.c index bf3c395..418b81b 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 f= ailover, =20 #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 =3D { .name =3D "replication", .head =3D QTAILQ_HEAD_INITIALIZER(replication_runtime_opts.head), @@ -65,6 +71,14 @@ static QemuOptsList replication_runtime_opts =3D { .name =3D REPLICATION_TOP_ID, .type =3D QEMU_OPT_STRING, }, + { + .name =3D REPLICATION_SHARED_DISK_ID, + .type =3D QEMU_OPT_STRING, + }, + { + .name =3D REPLICATION_SHARED_DISK, + .type =3D QEMU_OPT_BOOL, + }, { /* end of list */ } }, }; @@ -85,6 +99,9 @@ static int replication_open(BlockDriverState *bs, QDict *= options, QemuOpts *opts =3D NULL; const char *mode; const char *top_id; + const char *shared_disk_id; + BlockBackend *blk; + BlockDriverState *tmp_bs; =20 bs->file =3D bdrv_open_child(NULL, options, "file", bs, &child_file, false, errp); @@ -125,12 +142,33 @@ static int replication_open(BlockDriverState *bs, QDi= ct *options, "The option mode's value should be primary or secondary= "); goto fail; } + s->is_shared_disk =3D qemu_opt_get_bool(opts, REPLICATION_SHARED_DISK, + false); + if (s->is_shared_disk && (s->mode =3D=3D REPLICATION_MODE_PRIMARY)) { + shared_disk_id =3D qemu_opt_get(opts, REPLICATION_SHARED_DISK_ID); + if (!shared_disk_id) { + error_setg(&local_err, "Missing shared disk blk option"); + goto fail; + } + s->shared_disk_id =3D g_strdup(shared_disk_id); + blk =3D blk_by_name(s->shared_disk_id); + if (!blk) { + error_setg(&local_err, "There is no %s block", s->shared_disk_= id); + goto fail; + } + /* We have a BlockBackend for the primary disk but use BdrvChild f= or + * consistency - active_disk, secondary_disk, etc are also BdrvChi= ld. + */ + tmp_bs =3D blk_bs(blk); + s->primary_disk =3D QLIST_FIRST(&tmp_bs->parents); + } =20 s->rs =3D replication_new(bs, &replication_ops); =20 - ret =3D 0; - + qemu_opts_del(opts); + return 0; fail: + g_free(s->shared_disk_id); qemu_opts_del(opts); error_propagate(errp, local_err); =20 @@ -141,6 +179,7 @@ static void replication_close(BlockDriverState *bs) { BDRVReplicationState *s =3D bs->opaque; =20 + g_free(s->shared_disk_id); if (s->replication_state =3D=3D BLOCK_REPLICATION_RUNNING) { replication_stop(s->rs, false, NULL); } diff --git a/qapi/block-core.json b/qapi/block-core.json index 033457c..361c932 100644 --- a/qapi/block-core.json +++ b/qapi/block-core.json @@ -2661,12 +2661,20 @@ # node who owns the replication node chain. Must not be given in # primary mode. # +# @shared-disk-id: Id of shared disk while is replication mode, if @shared= -disk +# is true, this option is required (Since: 2.10) +# +# @shared-disk: To indicate whether or not a disk is shared by primary VM +# and secondary VM. (The default is false) (Since: 2.10) +# # Since: 2.9 ## { 'struct': 'BlockdevOptionsReplication', 'base': 'BlockdevOptionsGenericFormat', 'data': { 'mode': 'ReplicationMode', - '*top-id': 'str' } } + '*top-id': 'str', + '*shared-disk-id': 'str', + '*shared-disk': 'bool' } } =20 ## # @NFSTransport: --=20 1.8.3.1