From patchwork Thu Feb 12 03:07:11 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Wen Congyang X-Patchwork-Id: 439008 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [IPv6:2001:4830:134:3::11]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 66CE9140129 for ; Thu, 12 Feb 2015 14:08:29 +1100 (AEDT) Received: from localhost ([::1]:47995 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YLk8h-0006ti-GF for incoming@patchwork.ozlabs.org; Wed, 11 Feb 2015 22:08:27 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:60990) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YLk5n-00028p-Mf for qemu-devel@nongnu.org; Wed, 11 Feb 2015 22:05:33 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1YLk5j-000180-6c for qemu-devel@nongnu.org; Wed, 11 Feb 2015 22:05:27 -0500 Received: from [59.151.112.132] (port=8994 helo=heian.cn.fujitsu.com) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YLk5h-00016B-Pv for qemu-devel@nongnu.org; Wed, 11 Feb 2015 22:05:23 -0500 X-IronPort-AV: E=Sophos;i="5.04,848,1406563200"; d="scan'208";a="57476528" Received: from unknown (HELO edo.cn.fujitsu.com) ([10.167.33.5]) by heian.cn.fujitsu.com with ESMTP; 12 Feb 2015 11:01:37 +0800 Received: from G08CNEXCHPEKD02.g08.fujitsu.local (localhost.localdomain [127.0.0.1]) by edo.cn.fujitsu.com (8.14.3/8.13.1) with ESMTP id t1C34OW9030059; Thu, 12 Feb 2015 11:04:24 +0800 Received: from G08FNSTD140052.g08.fujitsu.local (10.167.226.52) by G08CNEXCHPEKD02.g08.fujitsu.local (10.167.33.89) with Microsoft SMTP Server (TLS) id 14.3.181.6; Thu, 12 Feb 2015 11:05:10 +0800 From: Wen Congyang To: qemu devel , Kevin Wolf , Stefan Hajnoczi , Paolo Bonzini Date: Thu, 12 Feb 2015 11:07:11 +0800 Message-ID: <1423710438-14377-8-git-send-email-wency@cn.fujitsu.com> X-Mailer: git-send-email 2.1.0 In-Reply-To: <1423710438-14377-1-git-send-email-wency@cn.fujitsu.com> References: <1423710438-14377-1-git-send-email-wency@cn.fujitsu.com> MIME-Version: 1.0 X-Originating-IP: [10.167.226.52] X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 59.151.112.132 Cc: Lai Jiangshan , Jiang Yunhong , Dong Eddie , "Dr. David Alan Gilbert" , Gonglei , Yang Hongyang , zhanghailiang Subject: [Qemu-devel] [RFC PATCH 07/14] NBD client: implement block driver interfaces for block replication X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Signed-off-by: Wen Congyang Signed-off-by: zhanghailiang Signed-off-by: Gonglei --- block/nbd.c | 55 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 55 insertions(+) diff --git a/block/nbd.c b/block/nbd.c index 19b9200..1ff6ecf 100644 --- a/block/nbd.c +++ b/block/nbd.c @@ -445,6 +445,58 @@ static void nbd_refresh_filename(BlockDriverState *bs) bs->full_open_options = opts; } +static int nbd_start_replication(BlockDriverState *bs, int mode) +{ + BDRVNBDState *s = bs->opaque; + Error *local_err = NULL; + int ret; + + /* + * TODO: support COLO_SECONDARY_MODE if we allow secondary + * QEMU becoming primary QEMU. + */ + if (mode != COLO_PRIMARY_MODE) { + return -1; + } + + if (s->connected) { + return -1; + } + + /* TODO: NBD client should be one child of quorum, how to verify it? */ + ret = nbd_connect_server(bs, &local_err); + if (local_err) { + error_free(local_err); + } + + return ret; +} + +static int nbd_do_checkpoint(BlockDriverState *bs) +{ + BDRVNBDState *s = bs->opaque; + + if (!s->connected) { + return -1; + } + + return 0; +} + +static int nbd_stop_replication(BlockDriverState *bs) +{ + BDRVNBDState *s = bs->opaque; + + if (!s->connected) { + return -1; + } + + nbd_client_session_close(&s->client); + s->connected = false; + + return 0; +} + static BlockDriver bdrv_nbd = { .format_name = "nbd", .protocol_name = "nbd", @@ -514,6 +566,9 @@ static BlockDriver bdrv_nbd_colo = { .bdrv_detach_aio_context = nbd_detach_aio_context, .bdrv_attach_aio_context = nbd_attach_aio_context, .bdrv_refresh_filename = nbd_refresh_filename, + .bdrv_start_replication = nbd_start_replication, + .bdrv_do_checkpoint = nbd_do_checkpoint, + .bdrv_stop_replication = nbd_stop_replication, .has_variable_length = true, };