From nobody Fri May 3 11:19:11 2024 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 1492006193608704.9245978255391; Wed, 12 Apr 2017 07:09:53 -0700 (PDT) Received: from localhost ([::1]:44555 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cyIy0-0005cu-82 for importer@patchew.org; Wed, 12 Apr 2017 10:09:52 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:36631) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cyIuf-00031I-RV for qemu-devel@nongnu.org; Wed, 12 Apr 2017 10:06:33 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1cyIuX-00018B-PD for qemu-devel@nongnu.org; Wed, 12 Apr 2017 10:06:25 -0400 Received: from szxga03-in.huawei.com ([45.249.212.189]:3366 helo=dggrg03-dlp.huawei.com) by eggs.gnu.org with esmtps (TLS1.0:RSA_ARCFOUR_SHA1:16) (Exim 4.71) (envelope-from ) id 1cyIuK-0000tR-Mh; Wed, 12 Apr 2017 10:06:05 -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 ALP11468; 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:16 +0800 Message-ID: <1492005921-15664-2-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.0A020203.58EE3440.032D, 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: e36426469222b5fe45615e6ca46f9aba 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 1/6] docs/block-replication: Add description for shared-disk case 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" Introuduce the scenario of shared-disk block replication and how to use it. Reviewed-by: Changlong Xie Reviewed-by: Stefan Hajnoczi Signed-off-by: zhanghailiang Signed-off-by: Wen Congyang Signed-off-by: Zhang Chen --- docs/block-replication.txt | 139 +++++++++++++++++++++++++++++++++++++++++= ++-- 1 file changed, 135 insertions(+), 4 deletions(-) diff --git a/docs/block-replication.txt b/docs/block-replication.txt index 6bde673..fbfe005 100644 --- a/docs/block-replication.txt +++ b/docs/block-replication.txt @@ -24,7 +24,7 @@ only dropped at next checkpoint time. To reduce the netwo= rk transportation effort during a vmstate checkpoint, the disk modification operations of the Primary disk are asynchronously forwarded to the Secondary node. =20 -=3D=3D Workflow =3D=3D +=3D=3D Non-shared disk workflow =3D=3D The following is the image of block replication workflow: =20 +----------------------+ +------------------------+ @@ -57,7 +57,7 @@ The following is the image of block replication workflow: 4) Secondary write requests will be buffered in the Disk buffer and it will overwrite the existing sector content in the buffer. =20 -=3D=3D Architecture =3D=3D +=3D=3D Non-shared disk architecture =3D=3D We are going to implement block replication from many basic blocks that are already in QEMU. =20 @@ -106,6 +106,74 @@ any state that would otherwise be lost by the speculat= ive write-through of the NBD server into the secondary disk. So before block replication, the primary disk and secondary disk should contain the same data. =20 +=3D=3D Shared Disk Mode Workflow =3D=3D +The following is the image of block replication workflow: + + +----------------------+ +------------------------+ + |Primary Write Requests| |Secondary Write Requests| + +----------------------+ +------------------------+ + | | + | (4) + | V + | /-------------\ + | (2)Forward and write through | | + | +--------------------------> | Disk Buffer | + | | | | + | | \-------------/ + | |(1)read | + | | | + (3)write | | | backing file + V | | + +-----------------------------+ | + | Shared Disk | <-----+ + +-----------------------------+ + + 1) Primary writes will read original data and forward it to Secondary + QEMU. + 2) Before Primary write requests are written to Shared disk, the + original sector content will be read from Shared disk and + forwarded and buffered in the Disk buffer on the secondary site, + but it will not overwrite the existing sector content (it could be + from either "Secondary Write Requests" or previous COW of "Primary + Write Requests") in the Disk buffer. + 3) Primary write requests will be written to Shared disk. + 4) Secondary write requests will be buffered in the Disk buffer and it + will overwrite the existing sector content in the buffer. + +=3D=3D Shared Disk Mode Architecture =3D=3D +We are going to implement block replication from many basic +blocks that are already in QEMU. + virtio-blk || .= ---------- + / || |= Secondary + / || '= ---------- + / || = virtio-blk + / || = | + | || r= eplication(5) + | NBD --------> NBD (2) = | + | client || server ---> hidden disk <-- = active disk(4) + | ^ || | + | replication(1) || | + | | || | + | +-----------------' || | + (3) |drive-backup sync=3Dnone || | +--------. | +-----------------+ || | +Primary | | | || backing | +--------' | | || | + V | | + +-------------------------------------------+ | + | shared disk | <----------+ + +-------------------------------------------+ + + + 1) Primary writes will read original data and forward it to Secondary + QEMU. + 2) The hidden-disk buffers the original content that is modified by the + primary VM. It should also be an empty disk, and the driver supports + bdrv_make_empty() and backing file. + 3) Primary write requests will be written to Shared disk. + 4) Secondary write requests will be buffered in the active disk and it + will overwrite the existing sector content in the buffer. + =3D=3D Failure Handling =3D=3D There are 7 internal errors when block replication is running: 1. I/O error on primary disk @@ -145,7 +213,7 @@ d. replication_stop_all() things except failover. The caller must hold the I/O mutex lock if it is in migration/checkpoint thread. =20 -=3D=3D Usage =3D=3D +=3D=3D Non-shared disk usage =3D=3D Primary: -drive if=3Dxxx,driver=3Dquorum,read-pattern=3Dfifo,id=3Dcolo1,vote-thre= shold=3D1,\ children.0.file.filename=3D1.raw,\ @@ -234,6 +302,69 @@ Secondary: The primary host is down, so we should do the following thing: { 'execute': 'nbd-server-stop' } =20 +=3D=3D Shared disk usage =3D=3D +Primary: + -drive if=3Dvirtio,id=3Dprimary_disk0,file.filename=3D1.raw,driver=3Draw + +Issue qmp command: + { 'execute': 'blockdev-add', + 'arguments': { + 'driver': 'replication', + 'node-name': 'rep', + 'mode': 'primary', + 'shared-disk-id': 'primary_disk0', + 'shared-disk': true, + 'file': { + 'driver': 'nbd', + 'export': 'hidden_disk0', + 'server': { + 'type': 'inet', + 'data': { + 'host': 'xxx.xxx.xxx.xxx', + 'port': 'yyy' + } + } + } + } + } + +Secondary: + -drive if=3Dnone,driver=3Dqcow2,file.filename=3D/mnt/ramfs/hidden_disk.im= g,id=3Dhidden_disk0,\ + backing.driver=3Draw,backing.file.filename=3D1.raw \ + -drive if=3Dvirtio,id=3Dactive-disk0,driver=3Dreplication,mode=3Dsecondar= y,\ + file.driver=3Dqcow2,top-id=3Dactive-disk0,\ + file.file.filename=3D/mnt/ramfs/active_disk.img,\ + file.backing=3Dhidden_disk0,shared-disk=3Don + +Issue qmp command: +1. { 'execute': 'nbd-server-start', + 'arguments': { + 'addr': { + 'type': 'inet', + 'data': { + 'host': '0', + 'port': 'yyy' + } + } + } + } +2. { 'execute': 'nbd-server-add', + 'arguments': { + 'device': 'hidden_disk0', + 'writable': true + } + } + +After Failover: +Primary: + { 'execute': 'x-blockdev-del', + 'arguments': { + 'node-name': 'rep' + } + } + +Secondary: + {'execute': 'nbd-server-stop' } + TODO: 1. Continuous block replication -2. Shared disk --=20 1.8.3.1 From nobody Fri May 3 11:19:11 2024 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 From nobody Fri May 3 11:19:11 2024 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 1492006273490918.593825074822; Wed, 12 Apr 2017 07:11:13 -0700 (PDT) Received: from localhost ([::1]:44570 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cyIzH-0006YQ-Rz for importer@patchew.org; Wed, 12 Apr 2017 10:11:11 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:36605) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cyIuc-0002xy-HE for qemu-devel@nongnu.org; Wed, 12 Apr 2017 10:06:26 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1cyIuX-00018C-PN for qemu-devel@nongnu.org; Wed, 12 Apr 2017 10:06:22 -0400 Received: from szxga03-in.huawei.com ([45.249.212.189]:3369 helo=dggrg03-dlp.huawei.com) by eggs.gnu.org with esmtps (TLS1.0:RSA_ARCFOUR_SHA1:16) (Exim 4.71) (envelope-from ) id 1cyIuS-000168-DE; Wed, 12 Apr 2017 10:06:12 -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 ALP11467; 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:40 +0800 From: zhanghailiang To: , Date: Wed, 12 Apr 2017 22:05:18 +0800 Message-ID: <1492005921-15664-4-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.0A020204.58EE343F.0256, 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: 3ad758c9b00723559aacc8bed436446b 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 3/6] replication: Split out backup_do_checkpoint() from secondary_do_checkpoint() 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, 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" The helper backup_do_checkpoint() will be used for primary related codes. Here we split it out from secondary_do_checkpoint(). Besides, it is unnecessary to call backup_do_checkpoint() in replication starting and normally stop replication path. We only need call it while do real checkpointing. Reviewed-by: Stefan Hajnoczi Reviewed-by: Changlong Xie Signed-off-by: zhanghailiang --- block/replication.c | 36 +++++++++++++++++++----------------- 1 file changed, 19 insertions(+), 17 deletions(-) diff --git a/block/replication.c b/block/replication.c index 418b81b..b021215 100644 --- a/block/replication.c +++ b/block/replication.c @@ -352,20 +352,8 @@ static bool replication_recurse_is_first_non_filter(Bl= ockDriverState *bs, =20 static void secondary_do_checkpoint(BDRVReplicationState *s, Error **errp) { - Error *local_err =3D NULL; int ret; =20 - if (!s->secondary_disk->bs->job) { - error_setg(errp, "Backup job was cancelled unexpectedly"); - return; - } - - backup_do_checkpoint(s->secondary_disk->bs->job, &local_err); - if (local_err) { - error_propagate(errp, local_err); - return; - } - ret =3D s->active_disk->bs->drv->bdrv_make_empty(s->active_disk->bs); if (ret < 0) { error_setg(errp, "Cannot make active disk empty"); @@ -578,6 +566,8 @@ static void replication_start(ReplicationState *rs, Rep= licationMode mode, return; } block_job_start(job); + + secondary_do_checkpoint(s, errp); break; default: aio_context_release(aio_context); @@ -586,10 +576,6 @@ static void replication_start(ReplicationState *rs, Re= plicationMode mode, =20 s->replication_state =3D BLOCK_REPLICATION_RUNNING; =20 - if (s->mode =3D=3D REPLICATION_MODE_SECONDARY) { - secondary_do_checkpoint(s, errp); - } - s->error =3D 0; aio_context_release(aio_context); } @@ -599,13 +585,29 @@ static void replication_do_checkpoint(ReplicationStat= e *rs, Error **errp) BlockDriverState *bs =3D rs->opaque; BDRVReplicationState *s; AioContext *aio_context; + Error *local_err =3D NULL; =20 aio_context =3D bdrv_get_aio_context(bs); aio_context_acquire(aio_context); s =3D bs->opaque; =20 - if (s->mode =3D=3D REPLICATION_MODE_SECONDARY) { + switch (s->mode) { + case REPLICATION_MODE_PRIMARY: + break; + case REPLICATION_MODE_SECONDARY: + if (!s->secondary_disk->bs->job) { + error_setg(errp, "Backup job was cancelled unexpectedly"); + break; + } + backup_do_checkpoint(s->secondary_disk->bs->job, &local_err); + if (local_err) { + error_propagate(errp, local_err); + break; + } secondary_do_checkpoint(s, errp); + break; + default: + abort(); } aio_context_release(aio_context); } --=20 1.8.3.1 From nobody Fri May 3 11:19:11 2024 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 1492006192536873.3192465683567; Wed, 12 Apr 2017 07:09:52 -0700 (PDT) Received: from localhost ([::1]:44554 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cyIxz-0005a9-2b for importer@patchew.org; Wed, 12 Apr 2017 10:09:51 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:36594) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cyIua-0002vI-EW for qemu-devel@nongnu.org; Wed, 12 Apr 2017 10:06:21 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1cyIuZ-00019W-9b for qemu-devel@nongnu.org; Wed, 12 Apr 2017 10:06:20 -0400 Received: from szxga03-in.huawei.com ([45.249.212.189]:3368 helo=dggrg03-dlp.huawei.com) by eggs.gnu.org with esmtps (TLS1.0:RSA_ARCFOUR_SHA1:16) (Exim 4.71) (envelope-from ) id 1cyIuV-000178-UP; Wed, 12 Apr 2017 10:06:16 -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 ALP11471; 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:41 +0800 From: zhanghailiang To: , Date: Wed, 12 Apr 2017 22:05:19 +0800 Message-ID: <1492005921-15664-5-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.0A020203.58EE3440.030D, 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: 369987425c1aff86f2669f6763cd12b9 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 4/6] replication: fix code logic with the new shared_disk option 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, 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" Some code logic only be needed in non-shared disk, here we adjust these codes to prepare for shared disk scenario. Reviewed-by: Stefan Hajnoczi Signed-off-by: zhanghailiang --- block/replication.c | 73 ++++++++++++++++++++++++++++++-------------------= ---- 1 file changed, 41 insertions(+), 32 deletions(-) diff --git a/block/replication.c b/block/replication.c index b021215..3a35471 100644 --- a/block/replication.c +++ b/block/replication.c @@ -539,33 +539,40 @@ static void replication_start(ReplicationState *rs, R= eplicationMode mode, return; } =20 - /* start backup job now */ - error_setg(&s->blocker, - "Block device is in use by internal backup job"); - - top_bs =3D bdrv_lookup_bs(s->top_id, s->top_id, NULL); - if (!top_bs || !bdrv_is_root_node(top_bs) || - !check_top_bs(top_bs, bs)) { - error_setg(errp, "No top_bs or it is invalid"); - reopen_backing_file(bs, false, NULL); - aio_context_release(aio_context); - return; - } - bdrv_op_block_all(top_bs, s->blocker); - bdrv_op_unblock(top_bs, BLOCK_OP_TYPE_DATAPLANE, s->blocker); - - job =3D backup_job_create(NULL, s->secondary_disk->bs, s->hidden_d= isk->bs, - 0, MIRROR_SYNC_MODE_NONE, NULL, false, + /* + * Only in the case of non-shared disk, + * the backup job is in the secondary side + */ + if (!s->is_shared_disk) { + /* start backup job now */ + error_setg(&s->blocker, + "Block device is in use by internal backup job"); + + top_bs =3D bdrv_lookup_bs(s->top_id, s->top_id, NULL); + if (!top_bs || !bdrv_is_root_node(top_bs) || + !check_top_bs(top_bs, bs)) { + error_setg(errp, "No top_bs or it is invalid"); + reopen_backing_file(bs, false, NULL); + aio_context_release(aio_context); + return; + } + + bdrv_op_block_all(top_bs, s->blocker); + bdrv_op_unblock(top_bs, BLOCK_OP_TYPE_DATAPLANE, s->blocker); + job =3D backup_job_create(NULL, s->secondary_disk->bs, + s->hidden_disk->bs, 0, + MIRROR_SYNC_MODE_NONE, NULL, false, BLOCKDEV_ON_ERROR_REPORT, BLOCKDEV_ON_ERROR_REPORT, BLOCK_JOB_INTERN= AL, backup_job_completed, bs, NULL, &local_err= ); - if (local_err) { - error_propagate(errp, local_err); - backup_job_cleanup(bs); - aio_context_release(aio_context); - return; + if (local_err) { + error_propagate(errp, local_err); + backup_job_cleanup(bs); + aio_context_release(aio_context); + return; + } + block_job_start(job); } - block_job_start(job); =20 secondary_do_checkpoint(s, errp); break; @@ -595,14 +602,16 @@ static void replication_do_checkpoint(ReplicationStat= e *rs, Error **errp) case REPLICATION_MODE_PRIMARY: break; case REPLICATION_MODE_SECONDARY: - if (!s->secondary_disk->bs->job) { - error_setg(errp, "Backup job was cancelled unexpectedly"); - break; - } - backup_do_checkpoint(s->secondary_disk->bs->job, &local_err); - if (local_err) { - error_propagate(errp, local_err); - break; + if (!s->is_shared_disk) { + if (!s->secondary_disk->bs->job) { + error_setg(errp, "Backup job was cancelled unexpectedly"); + break; + } + backup_do_checkpoint(s->secondary_disk->bs->job, &local_err); + if (local_err) { + error_propagate(errp, local_err); + break; + } } secondary_do_checkpoint(s, errp); break; @@ -683,7 +692,7 @@ static void replication_stop(ReplicationState *rs, bool= failover, Error **errp) * before the BDS is closed, because we will access hidden * disk, secondary disk in backup_job_completed(). */ - if (s->secondary_disk->bs->job) { + if (!s->is_shared_disk && s->secondary_disk->bs->job) { block_job_cancel_sync(s->secondary_disk->bs->job); } =20 --=20 1.8.3.1 From nobody Fri May 3 11:19:11 2024 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 1492006069714742.136154957515; Wed, 12 Apr 2017 07:07:49 -0700 (PDT) Received: from localhost ([::1]:44545 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cyIw0-0003sB-4k for importer@patchew.org; Wed, 12 Apr 2017 10:07:48 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:36519) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cyIuV-0002sP-OZ 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-00016e-HL for qemu-devel@nongnu.org; Wed, 12 Apr 2017 10:06:15 -0400 Received: from szxga03-in.huawei.com ([45.249.212.189]:3365 helo=dggrg03-dlp.huawei.com) by eggs.gnu.org with esmtps (TLS1.0:RSA_ARCFOUR_SHA1:16) (Exim 4.71) (envelope-from ) id 1cyIuK-0000tL-I8; Wed, 12 Apr 2017 10:06:05 -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 ALP11472; Wed, 12 Apr 2017 22:05:51 +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:42 +0800 From: zhanghailiang To: , Date: Wed, 12 Apr 2017 22:05:20 +0800 Message-ID: <1492005921-15664-6-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.0A020201.58EE3440.034C, 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: 5c6cc602e433b6bfc9c4c7bd21dba11a 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 5/6] replication: Implement block replication for shared disk case 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" Just as the scenario of non-shared disk block replication, we are going to implement block replication from many basic blocks that are already in QEMU. The architecture is: virtio-blk || .-= --------- / || | = Secondary / || '-= --------- / || = virtio-blk / || = | | || re= plication(5) | NBD --------> NBD (2) = | | client || server ---> hidden disk <-- a= ctive disk(4) | ^ || | | replication(1) || | | | || | | +-----------------' || | (3) |drive-backup sync=3Dnone || | --------. | +-----------------+ || | Primary | | | || backing | --------' | | || | V | | +-------------------------------------------+ | | shared disk | <----------+ +-------------------------------------------+ 1) Primary writes will read original data and forward it to Secondary QEMU. 2) The hidden-disk is created automatically. It buffers the original co= ntent that is modified by the primary VM. It should also be an empty disk,= and the driver supports bdrv_make_empty() and backing file. 3) Primary write requests will be written to Shared disk. 4) Secondary write requests will be buffered in the active disk and it will overwrite the existing sector content in the buffer. Signed-off-by: zhanghailiang Signed-off-by: Wen Congyang Signed-off-by: Zhang Chen --- v4: - Call bdrv_invalidate_cache() while do checkpoint for shared disk --- block/replication.c | 58 +++++++++++++++++++++++++++++++++++++++++++++++--= ---- 1 file changed, 52 insertions(+), 6 deletions(-) diff --git a/block/replication.c b/block/replication.c index 3a35471..fb604e5 100644 --- a/block/replication.c +++ b/block/replication.c @@ -253,7 +253,7 @@ static coroutine_fn int replication_co_readv(BlockDrive= rState *bs, QEMUIOVector *qiov) { BDRVReplicationState *s =3D bs->opaque; - BdrvChild *child =3D s->secondary_disk; + BdrvChild *child =3D s->is_shared_disk ? s->primary_disk : s->secondar= y_disk; BlockJob *job =3D NULL; CowRequest req; int ret; @@ -435,7 +435,12 @@ static void backup_job_completed(void *opaque, int ret) s->error =3D -EIO; } =20 - backup_job_cleanup(bs); + if (s->mode =3D=3D REPLICATION_MODE_PRIMARY) { + s->replication_state =3D BLOCK_REPLICATION_DONE; + s->error =3D 0; + } else { + backup_job_cleanup(bs); + } } =20 static bool check_top_bs(BlockDriverState *top_bs, BlockDriverState *bs) @@ -487,6 +492,19 @@ static void replication_start(ReplicationState *rs, Re= plicationMode mode, =20 switch (s->mode) { case REPLICATION_MODE_PRIMARY: + if (s->is_shared_disk) { + job =3D backup_job_create(NULL, s->primary_disk->bs, bs, 0, + MIRROR_SYNC_MODE_NONE, NULL, false, BLOCKDEV_ON_ERROR_REPO= RT, + BLOCKDEV_ON_ERROR_REPORT, BLOCK_JOB_INTERNAL, + backup_job_completed, bs, NULL, &local_err); + if (local_err) { + error_propagate(errp, local_err); + backup_job_cleanup(bs); + aio_context_release(aio_context); + return; + } + block_job_start(job); + } break; case REPLICATION_MODE_SECONDARY: s->active_disk =3D bs->file; @@ -505,7 +523,8 @@ static void replication_start(ReplicationState *rs, Rep= licationMode mode, } =20 s->secondary_disk =3D s->hidden_disk->bs->backing; - if (!s->secondary_disk->bs || !bdrv_has_blk(s->secondary_disk->bs)= ) { + if (!s->secondary_disk->bs || + (!s->is_shared_disk && !bdrv_has_blk(s->secondary_disk->bs))) { error_setg(errp, "The secondary disk doesn't have block backen= d"); aio_context_release(aio_context); return; @@ -600,11 +619,24 @@ static void replication_do_checkpoint(ReplicationStat= e *rs, Error **errp) =20 switch (s->mode) { case REPLICATION_MODE_PRIMARY: + if (s->is_shared_disk) { + if (!s->primary_disk->bs->job) { + error_setg(errp, "Primary backup job was cancelled" + " unexpectedly"); + break; + } + + backup_do_checkpoint(s->primary_disk->bs->job, &local_err); + if (local_err) { + error_propagate(errp, local_err); + } + } break; case REPLICATION_MODE_SECONDARY: if (!s->is_shared_disk) { if (!s->secondary_disk->bs->job) { - error_setg(errp, "Backup job was cancelled unexpectedly"); + error_setg(errp, "Secondary backup job was cancelled" + " unexpectedly"); break; } backup_do_checkpoint(s->secondary_disk->bs->job, &local_err); @@ -612,6 +644,16 @@ static void replication_do_checkpoint(ReplicationState= *rs, Error **errp) error_propagate(errp, local_err); break; } + } else { + /* + * For shared disk, we need to force SVM to re-read metadata + * that is loaded in memory, or there will be inconsistent. + */ + bdrv_invalidate_cache(s->secondary_disk->bs, &local_err); + if (local_err) { + error_propagate(errp, local_err); + break; + } } secondary_do_checkpoint(s, errp); break; @@ -683,8 +725,12 @@ static void replication_stop(ReplicationState *rs, boo= l failover, Error **errp) =20 switch (s->mode) { case REPLICATION_MODE_PRIMARY: - s->replication_state =3D BLOCK_REPLICATION_DONE; - s->error =3D 0; + if (s->is_shared_disk && s->primary_disk->bs->job) { + block_job_cancel(s->primary_disk->bs->job); + } else { + s->replication_state =3D BLOCK_REPLICATION_DONE; + s->error =3D 0; + } break; case REPLICATION_MODE_SECONDARY: /* --=20 1.8.3.1 From nobody Fri May 3 11:19:11 2024 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 149200614823242.05021348592061; Wed, 12 Apr 2017 07:09:08 -0700 (PDT) Received: from localhost ([::1]:44553 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cyIxG-0004zf-VH for importer@patchew.org; Wed, 12 Apr 2017 10:09:07 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:37145) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cyIvl-0003vt-8t for qemu-devel@nongnu.org; Wed, 12 Apr 2017 10:07:34 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1cyIvg-0001ks-Tp for qemu-devel@nongnu.org; Wed, 12 Apr 2017 10:07:33 -0400 Received: from szxga03-in.huawei.com ([45.249.212.189]:3372 helo=dggrg03-dlp.huawei.com) by eggs.gnu.org with esmtps (TLS1.0:RSA_ARCFOUR_SHA1:16) (Exim 4.71) (envelope-from ) id 1cyIvg-0001jv-Ay; Wed, 12 Apr 2017 10:07:28 -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 ALP11477; Wed, 12 Apr 2017 22:05:53 +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:42 +0800 From: zhanghailiang To: , Date: Wed, 12 Apr 2017 22:05:21 +0800 Message-ID: <1492005921-15664-7-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.0A020203.58EE3441.0355, 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: c596af653b4a97285df48f808b2de751 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 6/6] nbd/replication: implement .bdrv_get_info() for nbd and replication driver 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, Wen Congyang , qemu-block@nongnu.org, zhangchen.fnst@cn.fujitsu.com, 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" Without this callback, there will be an error reports in the primary side: "qemu-system-x86_64: Couldn't determine the cluster size of the target imag= e, which has no backing file: Operation not supported Aborting, since this may create an unusable destination image" For nbd driver, it doesn't have cluster size, so here we return a fake value for it. This patch should be dropped if Eric's nbd patch be merged. https://lists.gnu.org/archive/html/qemu-block/2017-02/msg00825.html '[PATCH v4 7/8] nbd: Implement NBD_INFO_BLOCK_SIZE on server'. Cc: Eric Blake Signed-off-by: zhanghailiang Signed-off-by: Wen Congyang --- block/nbd.c | 12 ++++++++++++ block/replication.c | 6 ++++++ 2 files changed, 18 insertions(+) diff --git a/block/nbd.c b/block/nbd.c index 814ab26d..fceb14b 100644 --- a/block/nbd.c +++ b/block/nbd.c @@ -43,6 +43,8 @@ =20 #define EN_OPTSTR ":exportname=3D" =20 +#define NBD_FAKE_CLUSTER_SIZE 512 + typedef struct BDRVNBDState { NBDClientSession client; =20 @@ -561,6 +563,13 @@ static void nbd_refresh_filename(BlockDriverState *bs,= QDict *options) bs->full_open_options =3D opts; } =20 +static int nbd_get_info(BlockDriverState *bs, BlockDriverInfo *bdi) +{ + bdi->cluster_size =3D NBD_FAKE_CLUSTER_SIZE; + + return 0; +} + static BlockDriver bdrv_nbd =3D { .format_name =3D "nbd", .protocol_name =3D "nbd", @@ -578,6 +587,7 @@ static BlockDriver bdrv_nbd =3D { .bdrv_detach_aio_context =3D nbd_detach_aio_context, .bdrv_attach_aio_context =3D nbd_attach_aio_context, .bdrv_refresh_filename =3D nbd_refresh_filename, + .bdrv_get_info =3D nbd_get_info, }; =20 static BlockDriver bdrv_nbd_tcp =3D { @@ -597,6 +607,7 @@ static BlockDriver bdrv_nbd_tcp =3D { .bdrv_detach_aio_context =3D nbd_detach_aio_context, .bdrv_attach_aio_context =3D nbd_attach_aio_context, .bdrv_refresh_filename =3D nbd_refresh_filename, + .bdrv_get_info =3D nbd_get_info, }; =20 static BlockDriver bdrv_nbd_unix =3D { @@ -616,6 +627,7 @@ static BlockDriver bdrv_nbd_unix =3D { .bdrv_detach_aio_context =3D nbd_detach_aio_context, .bdrv_attach_aio_context =3D nbd_attach_aio_context, .bdrv_refresh_filename =3D nbd_refresh_filename, + .bdrv_get_info =3D nbd_get_info, }; =20 static void bdrv_nbd_init(void) diff --git a/block/replication.c b/block/replication.c index fb604e5..7371caa 100644 --- a/block/replication.c +++ b/block/replication.c @@ -761,6 +761,11 @@ static void replication_stop(ReplicationState *rs, boo= l failover, Error **errp) aio_context_release(aio_context); } =20 +static int replication_get_info(BlockDriverState *bs, BlockDriverInfo *bdi) +{ + return bdrv_get_info(bs->file->bs, bdi); +} + BlockDriver bdrv_replication =3D { .format_name =3D "replication", .protocol_name =3D "replication", @@ -774,6 +779,7 @@ BlockDriver bdrv_replication =3D { .bdrv_co_readv =3D replication_co_readv, .bdrv_co_writev =3D replication_co_writev, =20 + .bdrv_get_info =3D replication_get_info, .is_filter =3D true, .bdrv_recurse_is_first_non_filter =3D replication_recurse_is_first_non= _filter, =20 --=20 1.8.3.1