From patchwork Tue Sep 3 09:20:21 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lukas Straub X-Patchwork-Id: 11127475 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id DE8ED13B1 for ; Tue, 3 Sep 2019 09:24:16 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id B501322CF8 for ; Tue, 3 Sep 2019 09:24:16 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (1024-bit key) header.d=web.de header.i=@web.de header.b="Mz5u+SGs" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org B501322CF8 Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=web.de Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Received: from localhost ([::1]:43246 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1i552t-0002eM-IV for patchwork-qemu-devel@patchwork.kernel.org; Tue, 03 Sep 2019 05:24:15 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:33543) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1i54zW-00083o-Fs for qemu-devel@nongnu.org; Tue, 03 Sep 2019 05:20:51 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1i54zV-0002Q6-8n for qemu-devel@nongnu.org; Tue, 03 Sep 2019 05:20:46 -0400 Received: from mout.web.de ([212.227.15.3]:35737) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1i54zU-0002PF-Vf for qemu-devel@nongnu.org; Tue, 03 Sep 2019 05:20:45 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=web.de; s=dbaedf251592; t=1567502426; bh=1aMK3WcfXGtXkTJdGeILldP4LKkJ6RJ1Yf8zxuMXcY0=; h=X-UI-Sender-Class:Date:From:To:Cc:Subject:In-Reply-To:References; b=Mz5u+SGsiV9KfRIGchX1DGjWSZiHo9wlfX4KBXGTPRqTVv7w3hJ9WT1pPatZv7UDb M0OKL5ylfTEghIfTPxDu3aFZsBKr2E5BBnGkf4GNHDsgLOZY+fR+YelEumRvpK+K/T mssEtkUMfmEM/3ypA1f92gy7QiZru6Kahgv3UDX4= X-UI-Sender-Class: c548c8c5-30a9-4db5-a2e7-cb6cb037b8f9 Received: from luklap ([88.130.61.78]) by smtp.web.de (mrweb003 [213.165.67.108]) with ESMTPSA (Nemesis) id 0M3k9J-1iNA2F2unJ-00rLNi; Tue, 03 Sep 2019 11:20:26 +0200 Date: Tue, 3 Sep 2019 11:20:21 +0200 From: Lukas Straub To: qemu-devel Message-ID: <5305f30b0f798adfc3883bbcebbfc5030661dbe9.1567500411.git.lukasstraub2@web.de> In-Reply-To: References: MIME-Version: 1.0 X-Provags-ID: V03:K1:6n7NUftyhGnsv3QHpJPJcpP7cONMly5SDtg4EveHA7CKukumlVU kkaEnL/EzNYE/fecpU94pqUmzucidGS3VXpCBlaloKmvHMVAjHy3DAFBjARlOVnx88Q0yjr Wz+IFJ1WC5QvrpADRwgNoF83JAgtKSFBD0oXyUDEWnk7rqj4OA+90C0yyQzqkooPfehMVM2 8W8yMneAidMWlMDqnGKlw== X-UI-Out-Filterresults: notjunk:1;V03:K0:Qf8/f9fOP8k=:fiQ0/c/PWc8JeIvNEadnsz aYlpVdKv51IbRNBwBNdNJPaTRF4LSj5FhihVn/e4lsaDgqCZSfujVoyB8g/Iaw5TuX2m/YZxo tpYwUcCTIotbYdCuJrOh9yGbB9Irrb2JS18jDgw9PmTsR0wU9CaphBbPxQV0WfPJQDyRTLr8R +8iauT+F5P5TDgQt1xTt5PhKwPeeC/FYJxqL4Mz/9w8Fv5XCxOOlaTKdpQIkFeMaE0ud/bNnW DcMpMO3tOL9JIZbjYHZULIYbFf/ah05AYeSN9Si+9vGTln52H1jE3fTVqEKSxzbolWjje/FG7 fpQ5wRQd+JQkC3uEI+QX3Z9tu/dYEfek6w5/G2RgKqbmedlIAa9G4ns8mJlbH0WnZRTDrFF6H EQ3kJuX2K+kl0xskiksJ7fNzJFEF2PUn/HkMga6tXm4mcfBPu9IHGgW9sqFr1hwFZTyiuKtus 2AngeNaLJbhSAjRB6jhNwfgarjKiVPjs/uwzzTdPLIOwPeHx6pvBeUzj8M3YO+hw3R/rPP/E1 9V8ZbQzNEHHYtxBsoHD+NfOUcwnEmhDdATQTLqVzjhkWDoPGahLFExRMFzGzkX34Ns5jzNblW GKMjToXAtLO6GinX2cGhZBRaDfcEVxsrCX27PoP/7ISwATT7rkJyhK1kANpMGdDmd6Gm5uxPW JfNn/3eYFKVCu1sz+QuyBv49JV/JKYWn5VmmQ0RT+T8RZram7dFRTvjgHklAzO5oXbl4wRoT1 sWriopiKWUIaRJHbv1NFgQMKJsMt6HkkNuDebIYKj6v9Ec4uio17fT5wOmHA6T+an2Q855iJl vE6v7Y4W9L3SJ587Jf6leNMFSkweXhej4CnFQCLRdmfIFI5IzCrYPCMdmCv1LZd/4v0es2362 G6tBxX57SQ5WxONMElFgsVwqdoSKMmcRiAFbzA/ii04Ix0eyq8FmvN5NrzEaUtRV712DcC4ZP Ck3wTu0FywaoXJehWXOXvW4arv814LRU7SLrgMcRxkpnhIJ6lhlIC04MeZ4BbNtAYYeQ0Nr/L c8EFsYUn5VqrGct5JG6SGs6I4NBJ1G7szHW9uHePw88SHd3FytBwi1fEYI+No5Y4GeBxuz1hK wbUgOLXz4Z95RWK9vkOJcNk5gi1bgO0vvafWYNXX5Qu771q0UcBkrmd8cUKO/ZXveYndTM2zw KT2g0s+uYa54NYb/2VRgwKj9npE6KnGwDwTre6f9NLk2fLIg== X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 212.227.15.3 Subject: [Qemu-devel] [PATCH v3 1/4] block/replication.c: Ignore requests after failover X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: kwolf@redhat.com, Wen Congyang , Jason Wang , mreitz@redhat.com, Zhang Chen , Xie Changlong Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" After failover the Secondary side of replication shouldn't change state, because it now functions as our primary disk. In replication_start, replication_do_checkpoint, replication_stop, ignore the request if current state is BLOCK_REPLICATION_DONE (sucessful failover) or BLOCK_REPLICATION_FAILOVER (failover in progres i.e. currently merging active and hidden images into the base image). Signed-off-by: Lukas Straub --- block/replication.c | 38 +++++++++++++++++++++++++++++++++++--- 1 file changed, 35 insertions(+), 3 deletions(-) -- 2.20.1 diff --git a/block/replication.c b/block/replication.c index 3d4dedddfc..97cc65c0cf 100644 --- a/block/replication.c +++ b/block/replication.c @@ -454,6 +454,17 @@ static void replication_start(ReplicationState *rs, ReplicationMode mode, aio_context_acquire(aio_context); s = bs->opaque; + if (s->stage == BLOCK_REPLICATION_DONE || + s->stage == BLOCK_REPLICATION_FAILOVER) { + /* + * This case happens when a secondary is promoted to primary. + * Ignore the request because the secondary side of replication + * doesn't have to do anything anymore. + */ + aio_context_release(aio_context); + return; + } + if (s->stage != BLOCK_REPLICATION_NONE) { error_setg(errp, "Block replication is running or done"); aio_context_release(aio_context); @@ -529,8 +540,7 @@ static void replication_start(ReplicationState *rs, ReplicationMode mode, "Block device is in use by internal backup job"); top_bs = 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)) { + if (!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); @@ -577,6 +587,17 @@ static void replication_do_checkpoint(ReplicationState *rs, Error **errp) aio_context_acquire(aio_context); s = bs->opaque; + if (s->stage == BLOCK_REPLICATION_DONE || + s->stage == BLOCK_REPLICATION_FAILOVER) { + /* + * This case happens when a secondary was promoted to primary. + * Ignore the request because the secondary side of replication + * doesn't have to do anything anymore. + */ + aio_context_release(aio_context); + return; + } + if (s->mode == REPLICATION_MODE_SECONDARY) { secondary_do_checkpoint(s, errp); } @@ -593,7 +614,7 @@ static void replication_get_error(ReplicationState *rs, Error **errp) aio_context_acquire(aio_context); s = bs->opaque; - if (s->stage != BLOCK_REPLICATION_RUNNING) { + if (s->stage == BLOCK_REPLICATION_NONE) { error_setg(errp, "Block replication is not running"); aio_context_release(aio_context); return; @@ -635,6 +656,17 @@ static void replication_stop(ReplicationState *rs, bool failover, Error **errp) aio_context_acquire(aio_context); s = bs->opaque; + if (s->stage == BLOCK_REPLICATION_DONE || + s->stage == BLOCK_REPLICATION_FAILOVER) { + /* + * This case happens when a secondary was promoted to primary. + * Ignore the request because the secondary side of replication + * doesn't have to do anything anymore. + */ + aio_context_release(aio_context); + return; + } + if (s->stage != BLOCK_REPLICATION_RUNNING) { error_setg(errp, "Block replication is not running"); aio_context_release(aio_context); From patchwork Tue Sep 3 09:20:29 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lukas Straub X-Patchwork-Id: 11127477 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 2013B13B1 for ; Tue, 3 Sep 2019 09:28:17 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id EAB2622CF8 for ; Tue, 3 Sep 2019 09:28:16 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (1024-bit key) header.d=web.de header.i=@web.de header.b="YGP6XdIy" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org EAB2622CF8 Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=web.de Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Received: from localhost ([::1]:43276 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1i556l-0005st-UT for patchwork-qemu-devel@patchwork.kernel.org; Tue, 03 Sep 2019 05:28:16 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:33559) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1i54zc-00088z-2i for qemu-devel@nongnu.org; Tue, 03 Sep 2019 05:20:53 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1i54zX-0002S5-Je for qemu-devel@nongnu.org; Tue, 03 Sep 2019 05:20:51 -0400 Received: from mout.web.de ([212.227.15.14]:35421) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1i54zX-0002Qe-7o for qemu-devel@nongnu.org; Tue, 03 Sep 2019 05:20:47 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=web.de; s=dbaedf251592; t=1567502430; bh=fyxFW0jLN+bdzNxHGPogdBIgIPlW9CiQAqsYYHE4l04=; h=X-UI-Sender-Class:Date:From:To:Cc:Subject:In-Reply-To:References; b=YGP6XdIyXYRMvlYOqKlSQc0BNCkYQM8oKX3GrnurXm8xsRpDC3F/Ha9+iAv0f4qL3 FeLSwUoSsgcJYYPZ6OUhYkHzlsjhVxe4wYvjNp7jl3399wKqVclgXUT5ZwOavsTDz9 dDufNJdwX4zn2TUROVWjrv+aldGNLaEMxFPe2U8Y= X-UI-Sender-Class: c548c8c5-30a9-4db5-a2e7-cb6cb037b8f9 Received: from luklap ([88.130.61.78]) by smtp.web.de (mrweb002 [213.165.67.108]) with ESMTPSA (Nemesis) id 0MfYTr-1hpT6b04ol-00P9Gd; Tue, 03 Sep 2019 11:20:30 +0200 Date: Tue, 3 Sep 2019 11:20:29 +0200 From: Lukas Straub To: qemu-devel Message-ID: In-Reply-To: References: MIME-Version: 1.0 X-Provags-ID: V03:K1:HQvkqKwr0+u8BVTtVfw182Wcoesbz4BDN99+KV9I8lVtiWk7G5e qErAIk4TL+Oj4gCwT3U0b5XGA7d0hUGLgURQueQN5o5iEEDQNJ3mfSUi+VfQrpyZduO/DYx anD1ZEEWGE/HmioJqR3sM5qB2HGZPWRlGA9bQWL5RyFwrhu3SQDWwg7gFCwf3F40h1nA9nT YllVMRT0pw6EjhDthB66Q== X-UI-Out-Filterresults: notjunk:1;V03:K0:W9NIws5o3KI=:S9EnPoIpybIiD5SllAhvy6 BeiBn2eULnHlFSH/vEfdSmWd4dJF0vL0cGb5eGdHI1e/z4YG0sTaQzrcZrxLL3VtmUtyJTtij WJ96nLxvV2HVDIaF/T+xgbvsRuoruvhoWqiex1xiua7llnNTYn2TYXm5JCbxIMMTkYLzwuv4b HfLPvmeG0Or1g3GY9nPGpODfPlNtPN5o9pOp1l/Vmm97IbMSOjRA2G6/THly1Wrl6bpVduPTO FI6umKACgid9TGH4cjpmflugTnrurS8XdZd5ajOgWptHKSO0tJZIxK4rD6P9bqEDJKyp63I/J P9kKVn1kGZXfuC07ntTcj+QUmUCqQpQlzEGrPGkk2nNJKMUY3GCj+Ip5fM6vCxvBbZSjL/cag CSS3AVDzNhiFxT1Z0nWwDDlcqgg8JThDSAN34AWR0JfCETgacnzmrEroNi4ee6BfNKfoPHr8P pdZAQ26bRjR1J4FEx1JfumUpsmp6OIohpZuLvH77TyfA8YdiM+EnjEfhJ1ycjExzj+SAiO9rB BtI5gtm6MilTmbou3l25UBRqTBU0b0Q9fWY3xiKaEwpEtPeHKoCg8534JqVW6MzNBXFsW5Pkr NlzMrxa6/sSg1ElvJB/EXABYSkhi4DGm17ZSMtQPWWhaK6T5adK1OeDs3Awx0D6d1HDDxHPqL iaL2IayBCvC1GJougZhJyKsN1QOG0FI+ZfmzMYV3mcpPcHMT6URSGKnuzY6Wdxwp7aTGKzxVq j6/qAdjSamyTLOdzIEmdVUujWy9KYlA96akoJ0pob6kSg9aTU2aD60gHPMqyp64olXqDnXfrf /+vVHG69IL4OBjvS7aTin6TsqpHPhacnwUyPxnozOlnOX/pIB34i5algcOItaG1O31+wdp/qt 6tw/GPXiD0QY8AycJWvAERckyaY8eMxbnysDKGVWawT/CyqenjnbPAmtejPrNyCOn0Q4NSifJ KSNuDJWrRtiEsSs6a014dIw+cxcZJiWT7RbQO5tC3U3hX+uOPM45zX1d0VhUVDKQ6G/MN/sMO WoKgG1rTVKl4EiE1u55yR2enFFe5W10YfoF8vwdAhWPhhvKmQirXauSxnqYyAVpzOP2+YNxtg I8orKupUbq+gNtIQrovP0G5OLCKuxJ7/b09xGy67Zc5ebmwgzOLK5yRyzwWVOPCYcY9mJxT+g 65ehy42odFUAbp5BE+NL48m41ozkyuoDi3R4F7gygdR1XoYQ== X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 212.227.15.14 Subject: [Qemu-devel] [PATCH v3 2/4] tests/test-replication.c: Add test for ignoring requests after failover X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: kwolf@redhat.com, Wen Congyang , Jason Wang , mreitz@redhat.com, Zhang Chen , Xie Changlong Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" This simulates the case that happens when we resume COLO after failover. Signed-off-by: Lukas Straub --- tests/test-replication.c | 52 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 52 insertions(+) -- 2.20.1 diff --git a/tests/test-replication.c b/tests/test-replication.c index f085d1993a..4502a6f816 100644 --- a/tests/test-replication.c +++ b/tests/test-replication.c @@ -489,6 +489,56 @@ static void test_secondary_stop(void) teardown_secondary(); } +static void test_secondary_failover_then_ignore_requests(void) +{ + BlockBackend *top_blk, *local_blk; + Error *local_err = NULL; + + top_blk = start_secondary(); + replication_start_all(REPLICATION_MODE_SECONDARY, &local_err); + g_assert(!local_err); + + /* write 0x22 to s_local_disk (IMG_SIZE / 2, IMG_SIZE) */ + local_blk = blk_by_name(S_LOCAL_DISK_ID); + test_blk_write(local_blk, 0x22, IMG_SIZE / 2, IMG_SIZE / 2, false); + + /* replication will backup s_local_disk to s_hidden_disk */ + test_blk_read(top_blk, 0x11, IMG_SIZE / 2, + IMG_SIZE / 2, 0, IMG_SIZE, false); + + /* write 0x33 to s_active_disk (0, IMG_SIZE / 2) */ + test_blk_write(top_blk, 0x33, 0, IMG_SIZE / 2, false); + + /* do failover (active commit) */ + replication_stop_all( true, &local_err); + g_assert(!local_err); + + /* it should ignore all requests from now on */ + + /* start after failover */ + replication_start_all(REPLICATION_MODE_SECONDARY, &local_err); + g_assert(!local_err); + + /* checkpoint */ + replication_do_checkpoint_all(&local_err); + g_assert(!local_err); + + /* stop */ + replication_stop_all( true, &local_err); + g_assert(!local_err); + + /* read from s_local_disk (0, IMG_SIZE / 2) */ + test_blk_read(top_blk, 0x33, 0, IMG_SIZE / 2, + 0, IMG_SIZE / 2, false); + + + /* read from s_local_disk (IMG_SIZE / 2, IMG_SIZE) */ + test_blk_read(top_blk, 0x22, IMG_SIZE / 2, + IMG_SIZE / 2, 0, IMG_SIZE, false); + + teardown_secondary(); +} + static void test_secondary_do_checkpoint(void) { BlockBackend *top_blk, *local_blk; @@ -584,6 +634,8 @@ int main(int argc, char **argv) g_test_add_func("/replication/secondary/write", test_secondary_write); g_test_add_func("/replication/secondary/start", test_secondary_start); g_test_add_func("/replication/secondary/stop", test_secondary_stop); + g_test_add_func("/replication/secondary/failover_then_ignore_requests", + test_secondary_failover_then_ignore_requests); g_test_add_func("/replication/secondary/do_checkpoint", test_secondary_do_checkpoint); g_test_add_func("/replication/secondary/get_error_all", From patchwork Tue Sep 3 09:20:32 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lukas Straub X-Patchwork-Id: 11127479 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id BF5E913B1 for ; Tue, 3 Sep 2019 09:29:08 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 9560522CF8 for ; Tue, 3 Sep 2019 09:29:08 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (1024-bit key) header.d=web.de header.i=@web.de header.b="LxILPuoj" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 9560522CF8 Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=web.de Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Received: from localhost ([::1]:43282 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1i557b-0006NC-J8 for patchwork-qemu-devel@patchwork.kernel.org; Tue, 03 Sep 2019 05:29:07 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:33620) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1i54zj-0008JM-FV for qemu-devel@nongnu.org; Tue, 03 Sep 2019 05:21:02 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1i54zg-0002bi-Hb for qemu-devel@nongnu.org; Tue, 03 Sep 2019 05:20:59 -0400 Received: from mout.web.de ([212.227.15.4]:51727) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1i54zg-0002aJ-8O for qemu-devel@nongnu.org; Tue, 03 Sep 2019 05:20:56 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=web.de; s=dbaedf251592; t=1567502433; bh=EQfG/A3jWr0rwlKpE0l7vZXu2bBYArUGmn3F6XCqY6U=; h=X-UI-Sender-Class:Date:From:To:Cc:Subject:In-Reply-To:References; b=LxILPuojfR+pfIGd0iRspe4cyRXK1ewCGqJbZlh3j81ZW/NRMI75zuIlSbtYdhzLS Y2SN6mgnQ2b22iLM2Fpa3OklJ03bEIYqTtCtEaaCkYL09+SMMawNghFZwgS7DyfgRW x6ict+fadrQqObFv0r6NRMb3fZAzuM1X0fj3LZWU= X-UI-Sender-Class: c548c8c5-30a9-4db5-a2e7-cb6cb037b8f9 Received: from luklap ([88.130.61.78]) by smtp.web.de (mrweb002 [213.165.67.108]) with ESMTPSA (Nemesis) id 0MMFB7-1i6S2W2ixp-0081qR; Tue, 03 Sep 2019 11:20:33 +0200 Date: Tue, 3 Sep 2019 11:20:32 +0200 From: Lukas Straub To: qemu-devel Message-ID: <13409421f1217cf755b694779dccb6dd127708fc.1567500411.git.lukasstraub2@web.de> In-Reply-To: References: MIME-Version: 1.0 X-Provags-ID: V03:K1:yj61fF/zWfbRK2noQMvAcQs9f732wkJh44ZaXcFpe61rC496ebp 1C5ibpHYtir9M90WokrDtaWHjx5NBc433eDvlPuCA/BzXtVkTMq/d4m1j3e1D5UljyqoLSq DtUrFvztVh36wL/BgPCs1oiw0+HjrWeYWtJJTor9dUVVCENNKH0lEukAIPtikMeXA3Ev7Eu kCzbWwZ3vP2ftam5sWOcQ== X-UI-Out-Filterresults: notjunk:1;V03:K0:Gs8JxF+T2iY=:iDDirV4S2RrrVlARhL3opw kgC7h0PLenrJdUzNN6ijAd5RFLNCMTXhZRVyaSqAn+04HSz2sEfCBEwIq4rkc3Sddq41juUAD izgQJ71+UKc4IzSZRfTKHRs4Akl9oOhkZkQ/Yoxch+ZDiWH9gqFUZis/KtJ7+9NvD6LllRpcl 4DriIpaGjFWkXSzPzqgAXg0Za1rfGWXAOh1ZW1bsgI78JQvFPlZ+cHdJ8Q1+vVFENNayO/Hnk 6lmN93FRSY+XHFM2vDjI2XycznZ6T4Jy0OyGBGWvgPnWllfNN9Op/Uc/Ty9zeYnXa7SV+GZFw MGkDTZqXHjwFLM7dwUhfJlHo0IBS32MeE3I+D67mEnX1nThlbCvsE5H0T8InoG5HMAYf3EtsE iXC4Vgu17vzrEwjpYJqKEGoDl9vJ2kvRJI+hxURKdcSWgWB6yY50YUrqz1Mz93ouXBLewc2rn gQljNMc7MCv0iqyQFKF5lwbegxCuxffM8dg2kCKiLikMwgEZxclDa51RaOoa6JmtfeUoR6hH7 OgpW0LM0HvCVWdQvvpvO3pD/n952xmDf6s9BsWkbFEEYaIEO2etAqlrJq3+r9VoTZ2hltX2tA ngDZ4RD2KEN5AfZobABNMI9zl9OMHxfh9j1ftUsc9gB29dlOc+kjpg9m1+Kx5706ys989vPM4 K80/p7qOLe1eo2GpQigVg2WUlYNf7LHoVbstPncnBpeuP51pzfLGmZbGU+NN36c/tihzaCUVh 0c1YhfE12ENejHkXMu82VsIvZhZcPNEFhiB5nqDYzmxWyV8DVujbIyIVFFcz1/VcQuwoIi1zi bxcWn3JK+TRdvBnuUwet21bFLDACIUwo9OZBayTJNaKzhVZVoJ3CzWPFKgj5/kPkcKvb8QWfJ FmX8b6yf775nKSJo02kb1EUl9eW9zbA9gGlbg3Cku5f9DO4/9qFePOd06Jz6sISlQaYtt6JBQ ZfrQOBEEbAzfkgX4CzvpFa2+IrQxbp1O2vTCNn4QGMr9vZx/jHF1hVa0gKyzzebZnLWDp+VVx nSa/nyCqIEYjnLt6ZhKCk+sIVssSYwnxnEy1qXXxFmxBSI2onUC7krLpyCjuiWDpyTsnZol60 gwsledllExjdQ0oo0gwSyqa/eazokZurGDNXP+mrmLnNwu6Uroon5nbJAEoDej1E19FfJYsHA y2QBYhZSEnNlFgij8QMRqEoAqY5SA/w6iQngWqIQ4NbS1YEg== X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 212.227.15.4 Subject: [Qemu-devel] [PATCH v3 3/4] net/filter.c: Add Options to insert filters anywhere in the filter list X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: kwolf@redhat.com, Wen Congyang , Jason Wang , mreitz@redhat.com, Zhang Chen , Xie Changlong Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" To switch the Secondary to Primary, we need to insert new filters before the filter-rewriter. Add the options insert= and position= to be able to insert filters anywhere in the filter list. position should be either "head", "tail" or the id of another filter. insert should be either "before" or "behind" to specify where to insert the new filter relative to the one specified with position. Signed-off-by: Lukas Straub --- include/net/filter.h | 2 ++ net/filter.c | 78 +++++++++++++++++++++++++++++++++++++++++++- qemu-options.hx | 10 +++--- 3 files changed, 84 insertions(+), 6 deletions(-) -- 2.20.1 diff --git a/include/net/filter.h b/include/net/filter.h index 49da666ac0..22a723305b 100644 --- a/include/net/filter.h +++ b/include/net/filter.h @@ -62,6 +62,8 @@ struct NetFilterState { NetClientState *netdev; NetFilterDirection direction; bool on; + char *position; + bool insert_before_flag; QTAILQ_ENTRY(NetFilterState) next; }; diff --git a/net/filter.c b/net/filter.c index 28d1930db7..7edebb2bf7 100644 --- a/net/filter.c +++ b/net/filter.c @@ -171,11 +171,47 @@ static void netfilter_set_status(Object *obj, const char *str, Error **errp) } } +static char *netfilter_get_position(Object *obj, Error **errp) +{ + NetFilterState *nf = NETFILTER(obj); + + return g_strdup(nf->position); +} + +static void netfilter_set_position(Object *obj, const char *str, Error **errp) +{ + NetFilterState *nf = NETFILTER(obj); + + nf->position = g_strdup(str); +} + +static char *netfilter_get_insert(Object *obj, Error **errp) +{ + NetFilterState *nf = NETFILTER(obj); + + return nf->insert_before_flag ? g_strdup("before") : g_strdup("behind"); +} + +static void netfilter_set_insert(Object *obj, const char *str, Error **errp) +{ + NetFilterState *nf = NETFILTER(obj); + + if (strcmp(str, "before") && strcmp(str, "behind")) { + error_setg(errp, "Invalid value for netfilter insert, " + "should be 'before' or 'behind'"); + return; + } + + nf->insert_before_flag = !strcmp(str, "before"); +} + static void netfilter_init(Object *obj) { NetFilterState *nf = NETFILTER(obj); nf->on = true; + nf->insert_before_flag = false; + nf->position = g_strdup("tail"); object_property_add_str(obj, "netdev", netfilter_get_netdev_id, netfilter_set_netdev_id, @@ -187,11 +223,18 @@ static void netfilter_init(Object *obj) object_property_add_str(obj, "status", netfilter_get_status, netfilter_set_status, NULL); + object_property_add_str(obj, "position", + netfilter_get_position, netfilter_set_position, + NULL); + object_property_add_str(obj, "insert", + netfilter_get_insert, netfilter_set_insert, + NULL); } static void netfilter_complete(UserCreatable *uc, Error **errp) { NetFilterState *nf = NETFILTER(uc); + NetFilterState *position = NULL; NetClientState *ncs[MAX_QUEUE_NUM]; NetFilterClass *nfc = NETFILTER_GET_CLASS(uc); int queues; @@ -219,6 +262,27 @@ static void netfilter_complete(UserCreatable *uc, Error **errp) return; } + if (strcmp(nf->position, "head") && strcmp(nf->position, "tail")) { + /* Search for the position to insert before/behind */ + Object *container; + Object *obj; + + container = object_get_objects_root(); + obj = object_resolve_path_component(container, nf->position); + if (!obj) { + error_setg(errp, "filter '%s' not found", nf->position); + return; + } + + position = NETFILTER(obj); + + if (position->netdev != ncs[0]) { + error_setg(errp, "filter '%s' belongs to a different netdev", + nf->position); + return; + } + } + nf->netdev = ncs[0]; if (nfc->setup) { @@ -228,7 +292,18 @@ static void netfilter_complete(UserCreatable *uc, Error **errp) return; } } - QTAILQ_INSERT_TAIL(&nf->netdev->filters, nf, next); + + if (position) { + if (nf->insert_before_flag) { + QTAILQ_INSERT_BEFORE(position, nf, next); + } else { + QTAILQ_INSERT_AFTER(&nf->netdev->filters, position, nf, next); + } + } else if (!strcmp(nf->position, "head")) { + QTAILQ_INSERT_HEAD(&nf->netdev->filters, nf, next); + } else if (!strcmp(nf->position, "tail")) { + QTAILQ_INSERT_TAIL(&nf->netdev->filters, nf, next); + } } static void netfilter_finalize(Object *obj) @@ -245,6 +320,7 @@ static void netfilter_finalize(Object *obj) QTAILQ_REMOVE(&nf->netdev->filters, nf, next); } g_free(nf->netdev_id); + g_free(nf->position); } static void default_handle_event(NetFilterState *nf, int event, Error **errp) diff --git a/qemu-options.hx b/qemu-options.hx index 08749a3391..1fd294a10f 100644 --- a/qemu-options.hx +++ b/qemu-options.hx @@ -4368,7 +4368,7 @@ applications, they can do this through this parameter. Its format is a gnutls priority string as described at @url{https://gnutls.org/manual/html_node/Priority-Strings.html}. -@item -object filter-buffer,id=@var{id},netdev=@var{netdevid},interval=@var{t}[,queue=@var{all|rx|tx}][,status=@var{on|off}] +@item -object filter-buffer,id=@var{id},netdev=@var{netdevid},interval=@var{t}[,queue=@var{all|rx|tx}][,status=@var{on|off}][,position=@var{head|tail|id}][,insert=@var{behind|before}] Interval @var{t} can't be 0, this filter batches the packet delivery: all packets arriving in a given interval on netdev @var{netdevid} are delayed @@ -4387,11 +4387,11 @@ queue @var{all|rx|tx} is an option that can be applied to any netfilter. @option{tx}: the filter is attached to the transmit queue of the netdev, where it will receive packets sent by the netdev. -@item -object filter-mirror,id=@var{id},netdev=@var{netdevid},outdev=@var{chardevid},queue=@var{all|rx|tx}[,vnet_hdr_support] +@item -object filter-mirror,id=@var{id},netdev=@var{netdevid},outdev=@var{chardevid},queue=@var{all|rx|tx}[,vnet_hdr_support][,position=@var{head|tail|id}][,insert=@var{behind|before}] filter-mirror on netdev @var{netdevid},mirror net packet to chardev@var{chardevid}, if it has the vnet_hdr_support flag, filter-mirror will mirror packet with vnet_hdr_len. -@item -object filter-redirector,id=@var{id},netdev=@var{netdevid},indev=@var{chardevid},outdev=@var{chardevid},queue=@var{all|rx|tx}[,vnet_hdr_support] +@item -object filter-redirector,id=@var{id},netdev=@var{netdevid},indev=@var{chardevid},outdev=@var{chardevid},queue=@var{all|rx|tx}[,vnet_hdr_support][,position=@var{head|tail|id}][,insert=@var{behind|before}] filter-redirector on netdev @var{netdevid},redirect filter's net packet to chardev @var{chardevid},and redirect indev's packet to filter.if it has the vnet_hdr_support flag, @@ -4400,7 +4400,7 @@ Create a filter-redirector we need to differ outdev id from indev id, id can not be the same. we can just use indev or outdev, but at least one of indev or outdev need to be specified. -@item -object filter-rewriter,id=@var{id},netdev=@var{netdevid},queue=@var{all|rx|tx},[vnet_hdr_support] +@item -object filter-rewriter,id=@var{id},netdev=@var{netdevid},queue=@var{all|rx|tx},[vnet_hdr_support][,position=@var{head|tail|id}][,insert=@var{behind|before}] Filter-rewriter is a part of COLO project.It will rewrite tcp packet to secondary from primary to keep secondary tcp connection,and rewrite @@ -4413,7 +4413,7 @@ colo secondary: -object filter-redirector,id=f2,netdev=hn0,queue=rx,outdev=red1 -object filter-rewriter,id=rew0,netdev=hn0,queue=all -@item -object filter-dump,id=@var{id},netdev=@var{dev}[,file=@var{filename}][,maxlen=@var{len}] +@item -object filter-dump,id=@var{id},netdev=@var{dev}[,file=@var{filename}][,maxlen=@var{len}][,position=@var{head|tail|id}][,insert=@var{behind|before}] Dump the network traffic on netdev @var{dev} to the file specified by @var{filename}. At most @var{len} bytes (64k by default) per packet are stored. From patchwork Tue Sep 3 09:20:36 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Lukas Straub X-Patchwork-Id: 11127473 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id C671115E9 for ; Tue, 3 Sep 2019 09:23:25 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 8B9BD22CF8 for ; Tue, 3 Sep 2019 09:23:25 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (1024-bit key) header.d=web.de header.i=@web.de header.b="bePBOtK2" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 8B9BD22CF8 Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=web.de Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Received: from localhost ([::1]:43242 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1i5524-0001iK-G2 for patchwork-qemu-devel@patchwork.kernel.org; Tue, 03 Sep 2019 05:23:24 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:33585) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1i54ze-0008CW-B9 for qemu-devel@nongnu.org; Tue, 03 Sep 2019 05:20:56 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1i54zb-0002Tq-RY for qemu-devel@nongnu.org; Tue, 03 Sep 2019 05:20:54 -0400 Received: from mout.web.de ([212.227.15.3]:43867) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1i54zb-0002SK-Gj for qemu-devel@nongnu.org; Tue, 03 Sep 2019 05:20:51 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=web.de; s=dbaedf251592; t=1567502437; bh=F8rQ0VouieUn+oow9fTkwiSw9uF7L9Sl9OeJnrI1M0E=; h=X-UI-Sender-Class:Date:From:To:Cc:Subject:In-Reply-To:References; b=bePBOtK2dZCQRNZvbLHRpQCRBAiXdAsKM/COqgCIizXFuul/+DE6RoV69zFHYJ7pm VWHv672qRaBe5JrMByNmwRZJHkhe02fCZQ/ft71MuSzgnfVU9he04JHm6avGkuyb/I tWm9Zr3ONHLgXo0IUDgs91D6hEcl8RosxV68rF7s= X-UI-Sender-Class: c548c8c5-30a9-4db5-a2e7-cb6cb037b8f9 Received: from luklap ([88.130.61.78]) by smtp.web.de (mrweb003 [213.165.67.108]) with ESMTPSA (Nemesis) id 0MMVpO-1i5cxX0SNS-008Hj2; Tue, 03 Sep 2019 11:20:37 +0200 Date: Tue, 3 Sep 2019 11:20:36 +0200 From: Lukas Straub To: qemu-devel Message-ID: <9190e28ef622df5c2b085a9909407850ecda4c01.1567500411.git.lukasstraub2@web.de> In-Reply-To: References: MIME-Version: 1.0 X-Provags-ID: V03:K1:LqPSt/FGLZdjafaD1zxv3cpOIpTHrehMI/gaU7D4g3IU2ojClp/ SoNb2+sCpsEOh5Bul+iKKxJTRxnUx4mdWS7XCHELI7HCoiAEW8librK/lWkMTXzLWFyVTne +DxifTRDKsAS7txpnBpdk07GQyrQ73ObYCWDOyIBJasVdOmGEfFi8sLsOIG6Vd30aV4bK+o GugdDNuPCPU5QQEZNZWvw== X-UI-Out-Filterresults: notjunk:1;V03:K0:XEA8k75nFlo=:l1ihCGLYQ023Pbz/M6J9CE fS9EU//31ZFCKvDUkIz4bKm+NaACND8BreCQpFfbr/y41bv5LEPI9/FDagyDPRDUjboMo9igi Xm/5h60gmZEi39jjWTup+hPP1MH+CfTaQNQuhz1GKG0N+f1WgHiJskV6734/RGKa+tQMAGgBs d/R7UtXbtBQjQ9QAY4HG+jBb8UbqiiD2sX/Sk3ouyqmXVihyXm8Y75S0jXM/kkHem9L31w13p OWHIbpvlTwf7QUH1PvBiJHE4mv7PWM7QEyp0u/qqz9r3Q4roWLepJV3frmAsaEhLVjA1ry+g+ NFwheGldCmIX6n+mYSMjQj8A5a/2c0Bf16kkqRRxbMTU1oyL87NkcKpx8i/kpfTuhomUrK6S/ 1BOwUEafC/nf50euo9GYd7Bq/5Qgr8G/+049mJ9hreEuB8QqWYckbRh7J6eoepFiaZlihTc3p IYsTtkEySpeWOLmxBxVlqE8Ft1zWtWNGHkUFolJglprRHnYVQUqq4ejju6XKKDhWvpSpWxIPx m/NYlmKN2EowPrVheQv895cuwrGMC8D1HURWaDh1oghr8LFxI4p5HYUrL1lhW8rKodjCpIYte C1JCstyihub8CcD4ZMYGvpX/SPLnYzCJDhZRaDQKIgxMaykw0SKkvwiM7d8wR5SRP/UfVB02M hhZx5jz4tLQ/3V9IH43L4WV3rF/AGCxtNQNaZROVmYE+n8kbUFabc46/tl+0DiTdK9We6MI70 Op6xAAyCd6lzkmfextiwBvhII6oF8hqCXPwCX/yBW5kvzxDPNUk/PaR1le28jITxDhNzfQCH6 IqW3+d4b2TUje1DxOCuUROH95lUNnMwW+SoVFxOMYc3qBpwEWZmF9K6Yb3f3kt9pJ2y6Et5Op 83OG4Dh2opob78LIpC9UM3muzQQVNsIb7F4z/ZYp+g9aFOFwJWEXNH4wlEt0R85TvKRSMuuAb aQFu+0+EMj7qsimH1jKN6MlfDzH3NCufGWmuUzpJX0wfZ2cOBviP2vgfRqPkTXw2cMcv73Jwr uaw1SRAuEnY8knuCH7ZWozEPSCayC36qVC0C5YcgOSDK1WWguS7N6+CkGPcjrwmtd+HMMjPd8 IdroQHylDBUuh3oPXv6WGIcNeTptVma6QcwkFNONhnYhWbpyIJoBxvrLzyRD9YrpLwIWj6NLp pVolHAwKa6zR3q4AkP8hvisakVbk2Jr5rP4V/CUDqLJyjYfA== X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 212.227.15.3 Subject: [Qemu-devel] [PATCH v3 4/4] colo: Update Documentation for continious replication X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: kwolf@redhat.com, Wen Congyang , Jason Wang , mreitz@redhat.com, Zhang Chen , Xie Changlong Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" Document the qemu command-line and qmp commands for continious replication Signed-off-by: Lukas Straub --- docs/COLO-FT.txt | 212 +++++++++++++++++++++++++++---------- docs/block-replication.txt | 26 +++-- 2 files changed, 172 insertions(+), 66 deletions(-) diff --git a/docs/COLO-FT.txt b/docs/COLO-FT.txt index ad24680d13..30dcb45d48 100644 --- a/docs/COLO-FT.txt +++ b/docs/COLO-FT.txt @@ -145,35 +145,65 @@ The diagram just shows the main qmp command, you can get the detail in test procedure. == Test procedure == -1. Startup qemu -Primary: -# qemu-system-x86_64 -accel kvm -m 2048 -smp 2 -qmp stdio -name primary \ - -device piix3-usb-uhci -vnc :7 \ - -device usb-tablet -netdev tap,id=hn0,vhost=off \ - -device virtio-net-pci,id=net-pci0,netdev=hn0 \ - -drive if=virtio,id=primary-disk0,driver=quorum,read-pattern=fifo,vote-threshold=1,\ - children.0.file.filename=1.raw,\ - children.0.driver=raw -S -Secondary: -# qemu-system-x86_64 -accel kvm -m 2048 -smp 2 -qmp stdio -name secondary \ - -device piix3-usb-uhci -vnc :7 \ - -device usb-tablet -netdev tap,id=hn0,vhost=off \ - -device virtio-net-pci,id=net-pci0,netdev=hn0 \ - -drive if=none,id=secondary-disk0,file.filename=1.raw,driver=raw,node-name=node0 \ - -drive if=virtio,id=active-disk0,driver=replication,mode=secondary,\ - file.driver=qcow2,top-id=active-disk0,\ - file.file.filename=/mnt/ramfs/active_disk.img,\ - file.backing.driver=qcow2,\ - file.backing.file.filename=/mnt/ramfs/hidden_disk.img,\ - file.backing.backing=secondary-disk0 \ - -incoming tcp:0:8888 - -2. On Secondary VM's QEMU monitor, issue command +Note: Here we are running both instances on the same Machine for testing, +change the IP Addresses if you want to run it on two Hosts + +== Startup qemu == +1. Primary: +# imagefolder="/mnt/vms/colo-test" + +The disks for the primary and secondary need to be the same before starting colo +# cp --reflink=auto $imagefolder/primary.qcow2 $imagefolder/primary-copy.qcow2 + +# qemu-system-x86_64 -enable-kvm -cpu qemu64,+kvmclock -m 512 -smp 1 -qmp stdio \ + -vnc :0 -device piix3-usb-uhci -device usb-tablet -name primary \ + -netdev tap,id=hn0,vhost=off,helper=/usr/lib/qemu/qemu-bridge-helper \ + -device rtl8139,id=e0,netdev=hn0 \ + -chardev socket,id=mirror0,host=127.0.0.1,port=9003,server,nowait \ + -chardev socket,id=compare1,host=127.0.0.1,port=9004,server,wait \ + -chardev socket,id=compare0,host=127.0.0.1,port=9001,server,nowait \ + -chardev socket,id=compare0-0,host=127.0.0.1,port=9001 \ + -chardev socket,id=compare_out,host=127.0.0.1,port=9005,server,nowait \ + -chardev socket,id=compare_out0,host=127.0.0.1,port=9005 \ + -object filter-mirror,id=m0,netdev=hn0,queue=tx,outdev=mirror0 \ + -object filter-redirector,netdev=hn0,id=redire0,queue=rx,indev=compare_out \ + -object filter-redirector,netdev=hn0,id=redire1,queue=rx,outdev=compare0 \ + -object iothread,id=iothread1 \ + -object colo-compare,id=comp0,primary_in=compare0-0,secondary_in=compare1,\ +outdev=compare_out0,iothread=iothread1 \ + -drive if=ide,id=colo-disk0,driver=quorum,read-pattern=fifo,vote-threshold=1,\ +children.0.file.filename=$imagefolder/primary.qcow2,children.0.driver=qcow2 -S + +2. Secondary: +# imagefolder="/mnt/vms/colo-test" + +# qemu-img create -f qcow2 $imagefolder/secondary-active.qcow2 10G + +# qemu-img create -f qcow2 $imagefolder/secondary-hidden.qcow2 10G + +# qemu-system-x86_64 -enable-kvm -cpu qemu64,+kvmclock -m 512 -smp 1 -qmp stdio \ + -vnc :1 -device piix3-usb-uhci -device usb-tablet -name secondary \ + -netdev tap,id=hn0,vhost=off,helper=/usr/lib/qemu/qemu-bridge-helper \ + -device rtl8139,id=e0,netdev=hn0 \ + -chardev socket,id=red0,host=127.0.0.1,port=9003,reconnect=1 \ + -chardev socket,id=red1,host=127.0.0.1,port=9004,reconnect=1 \ + -object filter-redirector,id=f1,netdev=hn0,queue=tx,indev=red0 \ + -object filter-redirector,id=f2,netdev=hn0,queue=rx,outdev=red1 \ + -object filter-rewriter,id=rew0,netdev=hn0,queue=all \ + -drive if=none,id=parent0,file.filename=$imagefolder/primary-copy.qcow2,driver=qcow2 \ + -drive if=none,id=childs0,driver=replication,mode=secondary,file.driver=qcow2,\ +top-id=childs0,file.file.filename=$imagefolder/secondary-active.qcow2,\ +file.backing.driver=qcow2,file.backing.file.filename=$imagefolder/secondary-hidden.qcow2,\ +file.backing.backing=parent0 \ + -drive if=ide,id=colo-disk0,driver=quorum,read-pattern=fifo,vote-threshold=1,\ +children.0=childs0 \ + -incoming tcp:0:9998 + + +3. On Secondary VM's QEMU monitor, issue command {'execute':'qmp_capabilities'} -{ 'execute': 'nbd-server-start', - 'arguments': {'addr': {'type': 'inet', 'data': {'host': 'xx.xx.xx.xx', 'port': '8889'} } } -} -{'execute': 'nbd-server-add', 'arguments': {'device': 'secondary-disk0', 'writable': true } } +{'execute': 'nbd-server-start', 'arguments': {'addr': {'type': 'inet', 'data': {'host': '127.0.0.1', 'port': '9999'} } } } +{'execute': 'nbd-server-add', 'arguments': {'device': 'parent0', 'writable': true } } Note: a. The qmp command nbd-server-start and nbd-server-add must be run @@ -182,44 +212,112 @@ Note: same. c. It is better to put active disk and hidden disk in ramdisk. -3. On Primary VM's QEMU monitor, issue command: +4. On Primary VM's QEMU monitor, issue command: {'execute':'qmp_capabilities'} -{ 'execute': 'human-monitor-command', - 'arguments': {'command-line': 'drive_add -n buddy driver=replication,mode=primary,file.driver=nbd,file.host=xx.xx.xx.xx,file.port=8889,file.export=secondary-disk0,node-name=nbd_client0'}} -{ 'execute':'x-blockdev-change', 'arguments':{'parent': 'primary-disk0', 'node': 'nbd_client0' } } -{ 'execute': 'migrate-set-capabilities', - 'arguments': {'capabilities': [ {'capability': 'x-colo', 'state': true } ] } } -{ 'execute': 'migrate', 'arguments': {'uri': 'tcp:xx.xx.xx.xx:8888' } } +{'execute': 'human-monitor-command', 'arguments': {'command-line': 'drive_add -n buddy driver=replication,mode=primary,file.driver=nbd,file.host=127.0.0.1,file.port=9999,file.export=parent0,node-name=replication0'}} +{'execute': 'x-blockdev-change', 'arguments':{'parent': 'colo-disk0', 'node': 'replication0' } } +{'execute': 'migrate-set-capabilities', 'arguments': {'capabilities': [ {'capability': 'x-colo', 'state': true } ] } } +{'execute': 'migrate', 'arguments': {'uri': 'tcp:127.0.0.1:9998' } } Note: a. There should be only one NBD Client for each primary disk. - b. xx.xx.xx.xx is the secondary physical machine's hostname or IP - c. The qmp command line must be run after running qmp command line in + b. The qmp command line must be run after running qmp command line in secondary qemu. -4. After the above steps, you will see, whenever you make changes to PVM, SVM will be synced. +5. After the above steps, you will see, whenever you make changes to PVM, SVM will be synced. You can issue command '{ "execute": "migrate-set-parameters" , "arguments":{ "x-checkpoint-delay": 2000 } }' -to change the checkpoint period time +to change the idle checkpoint period time + +6. Failover test +You can kill one of the VMs and Failover on the surviving VM: + +If you killed the Secondary, then follow "Primary Failover". After that, +if you want to resume the replication, follow "Primary resume replication" + +If you killed the Primary, then follow "Secondary Failover". After that, +if you want to resume the replication, follow "Secondary resume replication" + +== Primary Failover == +The Secondary died, resume on the Primary + +{'execute': 'x-blockdev-change', 'arguments':{ 'parent': 'colo-disk0', 'child': 'children.1'} } +{'execute': 'human-monitor-command', 'arguments':{ 'command-line': 'drive_del replication0' } } +{'execute': 'object-del', 'arguments':{ 'id': 'comp0' } } +{'execute': 'object-del', 'arguments':{ 'id': 'iothread1' } } +{'execute': 'object-del', 'arguments':{ 'id': 'm0' } } +{'execute': 'object-del', 'arguments':{ 'id': 'redire0' } } +{'execute': 'object-del', 'arguments':{ 'id': 'redire1' } } +{'execute': 'x-colo-lost-heartbeat' } + +== Secondary Failover == +The Primary died, resume on the Secondary and prepare to become the new Primary + +{'execute': 'nbd-server-stop'} +{'execute': 'x-colo-lost-heartbeat'} + +{'execute': 'object-del', 'arguments':{ 'id': 'f2' } } +{'execute': 'object-del', 'arguments':{ 'id': 'f1' } } +{'execute': 'chardev-remove', 'arguments':{ 'id': 'red1' } } +{'execute': 'chardev-remove', 'arguments':{ 'id': 'red0' } } + +{'execute': 'chardev-add', 'arguments':{ 'id': 'mirror0', 'backend': {'type': 'socket', 'data': {'addr': { 'type': 'inet', 'data': { 'host': '127.0.0.1', 'port': '9003' } }, 'server': true } } } } +{'execute': 'chardev-add', 'arguments':{ 'id': 'compare1', 'backend': {'type': 'socket', 'data': {'addr': { 'type': 'inet', 'data': { 'host': '127.0.0.1', 'port': '9004' } }, 'server': true } } } } +{'execute': 'chardev-add', 'arguments':{ 'id': 'compare0', 'backend': {'type': 'socket', 'data': {'addr': { 'type': 'inet', 'data': { 'host': '127.0.0.1', 'port': '9001' } }, 'server': true } } } } +{'execute': 'chardev-add', 'arguments':{ 'id': 'compare0-0', 'backend': {'type': 'socket', 'data': {'addr': { 'type': 'inet', 'data': { 'host': '127.0.0.1', 'port': '9001' } }, 'server': false } } } } +{'execute': 'chardev-add', 'arguments':{ 'id': 'compare_out', 'backend': {'type': 'socket', 'data': {'addr': { 'type': 'inet', 'data': { 'host': '127.0.0.1', 'port': '9005' } }, 'server': true } } } } +{'execute': 'chardev-add', 'arguments':{ 'id': 'compare_out0', 'backend': {'type': 'socket', 'data': {'addr': { 'type': 'inet', 'data': { 'host': '127.0.0.1', 'port': '9005' } }, 'server': false } } } } + +== Primary resume replication == +Resume replication after new Secondary is up. + +Start the new Secondary (Steps 2 and 3 above), then: +{'execute': 'drive-mirror', 'arguments':{ 'device': 'colo-disk0', 'job-id': 'resync', 'target': 'nbd://127.0.0.1:9999/parent0', 'mode': 'existing', 'format': 'raw', 'sync': 'full'} } + +Wait until disk is synced, then: +{'execute': 'stop'} +{'execute': 'block-job-cancel', 'arguments':{ 'device': 'resync'} } + +{'execute': 'human-monitor-command', 'arguments':{ 'command-line': 'drive_add -n buddy driver=replication,mode=primary,file.driver=nbd,file.host=127.0.0.1,file.port=9999,file.export=parent0,node-name=replication0'}} +{'execute': 'x-blockdev-change', 'arguments':{ 'parent': 'colo-disk0', 'node': 'replication0' } } + +{'execute': 'object-add', 'arguments':{ 'qom-type': 'filter-mirror', 'id': 'm0', 'props': { 'netdev': 'hn0', 'queue': 'tx', 'outdev': 'mirror0' } } } +{'execute': 'object-add', 'arguments':{ 'qom-type': 'filter-redirector', 'id': 'redire0', 'props': { 'netdev': 'hn0', 'queue': 'rx', 'indev': 'compare_out' } } } +{'execute': 'object-add', 'arguments':{ 'qom-type': 'filter-redirector', 'id': 'redire1', 'props': { 'netdev': 'hn0', 'queue': 'rx', 'outdev': 'compare0' } } } +{'execute': 'object-add', 'arguments':{ 'qom-type': 'iothread', 'id': 'iothread1' } } +{'execute': 'object-add', 'arguments':{ 'qom-type': 'colo-compare', 'id': 'comp0', 'props': { 'primary_in': 'compare0-0', 'secondary_in': 'compare1', 'outdev': 'compare_out0', 'iothread': 'iothread1' } } } + +{'execute': 'migrate-set-capabilities', 'arguments':{ 'capabilities': [ {'capability': 'x-colo', 'state': true } ] } } +{'execute': 'migrate', 'arguments':{ 'uri': 'tcp:127.0.0.1:9998' } } + +Note: +If this Primary previously was a Secondary, then we need to insert the +filters before the filter-rewriter by using the +"'insert': 'before', 'position': 'rew0'" Options. See below. + +== Secondary resume replication == +Become Primary and resume replication after new Secondary is up. + +Start the new Secondary (Steps 2 and 3 above, but with different image than +primary-copy.qcow2 and different VNC port), then: +{'execute': 'drive-mirror', 'arguments':{ 'device': 'colo-disk0', 'job-id': 'resync', 'target': 'nbd://127.0.0.1:9999/parent0', 'mode': 'existing', 'format': 'raw', 'sync': 'full'} } + +Wait until disk is synced, then: +{'execute': 'stop'} +{'execute': 'block-job-cancel', 'arguments':{ 'device': 'resync' } } -5. Failover test -You can kill Primary VM and run 'x_colo_lost_heartbeat' in Secondary VM's -monitor at the same time, then SVM will failover and client will not detect this -change. +{'execute': 'human-monitor-command', 'arguments':{ 'command-line': 'drive_add -n buddy driver=replication,mode=primary,file.driver=nbd,file.host=127.0.0.1,file.port=9999,file.export=parent0,node-name=replication0'}} +{'execute': 'x-blockdev-change', 'arguments':{ 'parent': 'colo-disk0', 'node': 'replication0' } } -Before issuing '{ "execute": "x-colo-lost-heartbeat" }' command, we have to -issue block related command to stop block replication. -Primary: - Remove the nbd child from the quorum: - { 'execute': 'x-blockdev-change', 'arguments': {'parent': 'colo-disk0', 'child': 'children.1'}} - { 'execute': 'human-monitor-command','arguments': {'command-line': 'drive_del blk-buddy0'}} - Note: there is no qmp command to remove the blockdev now +{'execute': 'object-add', 'arguments':{ 'qom-type': 'filter-mirror', 'id': 'm0', 'props': { 'insert': 'before', 'position': 'rew0', 'netdev': 'hn0', 'queue': 'tx', 'outdev': 'mirror0' } } } +{'execute': 'object-add', 'arguments':{ 'qom-type': 'filter-redirector', 'id': 'redire0', 'props': { 'insert': 'before', 'position': 'rew0', 'netdev': 'hn0', 'queue': 'rx', 'indev': 'compare_out' } } } +{'execute': 'object-add', 'arguments':{ 'qom-type': 'filter-redirector', 'id': 'redire1', 'props': { 'insert': 'before', 'position': 'rew0', 'netdev': 'hn0', 'queue': 'rx', 'outdev': 'compare0' } } } +{'execute': 'object-add', 'arguments':{ 'qom-type': 'iothread', 'id': 'iothread1' } } +{'execute': 'object-add', 'arguments':{ 'qom-type': 'colo-compare', 'id': 'comp0', 'props': { 'primary_in': 'compare0-0', 'secondary_in': 'compare1', 'outdev': 'compare_out0', 'iothread': 'iothread1' } } } -Secondary: - The primary host is down, so we should do the following thing: - { 'execute': 'nbd-server-stop' } +{'execute': 'migrate-set-capabilities', 'arguments':{ 'capabilities': [ {'capability': 'x-colo', 'state': true } ] } } +{'execute': 'migrate', 'arguments':{ 'uri': 'tcp:127.0.0.1:9998' } } == TODO == -1. Support continuous VM replication. -2. Support shared storage. -3. Develop the heartbeat part. -4. Reduce checkpoint VM’s downtime while doing checkpoint. +1. Support shared storage. +2. Develop the heartbeat part. +3. Reduce checkpoint VM’s downtime while doing checkpoint. diff --git a/docs/block-replication.txt b/docs/block-replication.txt index 6bde6737fb..9fc145af86 100644 --- a/docs/block-replication.txt +++ b/docs/block-replication.txt @@ -65,12 +65,12 @@ blocks that are already in QEMU. ^ || .---------- | || | Secondary 1 Quorum || '---------- - / \ || - / \ || - Primary 2 filter - disk ^ virtio-blk - | ^ - 3 NBD -------> 3 NBD | + / \ || virtio-blk + / \ || ^ + Primary 2 filter | + disk ^ 7 Quorum + | / + 3 NBD -------> 3 NBD / client || server 2 filter || ^ ^ --------. || | | @@ -106,6 +106,10 @@ any state that would otherwise be lost by the speculative 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. +7) The secondary also has a quorum node, so after secondary failover it +can become the new primary and continiue replication. + + == Failure Handling == There are 7 internal errors when block replication is running: 1. I/O error on primary disk @@ -171,16 +175,18 @@ Primary: leading whitespace. 5. The qmp command line must be run after running qmp command line in secondary qemu. - 6. After failover we need remove children.1 (replication driver). + 6. After primary failover we need remove children.1 (replication driver). Secondary: -drive if=none,driver=raw,file.filename=1.raw,id=colo1 \ - -drive if=xxx,id=topxxx,driver=replication,mode=secondary,top-id=topxxx\ + -drive if=none,id=childs1,driver=replication,mode=secondary,top-id=childs1 file.file.filename=active_disk.qcow2,\ file.driver=qcow2,\ file.backing.file.filename=hidden_disk.qcow2,\ file.backing.driver=qcow2,\ file.backing.backing=colo1 + -drive if=xxx,driver=quorum,read-pattern=fifo,id=top-disk1,\ + vote-threshold=1,children.0=childs1 Then run qmp command in secondary qemu: { 'execute': 'nbd-server-start', @@ -233,7 +239,9 @@ Primary: Secondary: The primary host is down, so we should do the following thing: { 'execute': 'nbd-server-stop' } + +Promote Secondary to Primary: + see COLO-FT.txt TODO: -1. Continuous block replication 2. Shared disk