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 From: Wen Congyang Date: Thu, 12 Feb 2015 11:07:11 +0800 Message-ID: <1423710438-14377-8-git-send-email-wency@cn.fujitsu.com> 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 Content-Type: text/plain Subject: [Qemu-devel] [RFC PATCH 07/14] NBD client: implement block driver interfaces for block replication List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu devel , Kevin Wolf , Stefan Hajnoczi , Paolo Bonzini Cc: Lai Jiangshan , Jiang Yunhong , Dong Eddie , "Dr. David Alan Gilbert" , Gonglei , Yang Hongyang , zhanghailiang 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, }; -- 2.1.0