From patchwork Thu Feb 12 03:07:17 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Wen Congyang X-Patchwork-Id: 439015 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 9F12814017A for ; Thu, 12 Feb 2015 14:12:56 +1100 (AEDT) Received: from localhost ([::1]:48033 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YLkD0-000635-FZ for incoming@patchwork.ozlabs.org; Wed, 11 Feb 2015 22:12:54 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:32792) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YLk5s-0002Ca-H3 for qemu-devel@nongnu.org; Wed, 11 Feb 2015 22:05:36 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1YLk5o-00019n-8I for qemu-devel@nongnu.org; Wed, 11 Feb 2015 22:05:32 -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 1YLk5m-00016B-95 for qemu-devel@nongnu.org; Wed, 11 Feb 2015 22:05:27 -0500 X-IronPort-AV: E=Sophos;i="5.04,848,1406563200"; d="scan'208";a="57476544" Received: from unknown (HELO edo.cn.fujitsu.com) ([10.167.33.5]) by heian.cn.fujitsu.com with ESMTP; 12 Feb 2015 11:01:48 +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 t1C34ZU8030085; Thu, 12 Feb 2015 11:04:35 +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:21 +0800 From: Wen Congyang To: qemu devel , Kevin Wolf , Stefan Hajnoczi , Paolo Bonzini Date: Thu, 12 Feb 2015 11:07:17 +0800 Message-ID: <1423710438-14377-14-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 13/14] COW: move cow interfaces to a seperate file 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 --- Makefile.objs | 2 +- block/backup.c | 52 ++++----------------------------------------------- blockcow.c | 52 +++++++++++++++++++++++++++++++++++++++++++++++++++ include/block/block.h | 17 +++++++++++++++++ 4 files changed, 74 insertions(+), 49 deletions(-) create mode 100644 blockcow.c diff --git a/Makefile.objs b/Makefile.objs index 28999d3..91bba07 100644 --- a/Makefile.objs +++ b/Makefile.objs @@ -7,7 +7,7 @@ util-obj-y = util/ qobject/ qapi/ qapi-types.o qapi-visit.o qapi-event.o # block-obj-y is code used by both qemu system emulation and qemu-img block-obj-y = async.o thread-pool.o -block-obj-y += nbd.o block.o blockjob.o +block-obj-y += nbd.o block.o blockjob.o blockcow.o block-obj-y += main-loop.o iohandler.o qemu-timer.o block-obj-$(CONFIG_POSIX) += aio-posix.o block-obj-$(CONFIG_WIN32) += aio-win32.o diff --git a/block/backup.c b/block/backup.c index 1c535b1..2816b9a 100644 --- a/block/backup.c +++ b/block/backup.c @@ -27,13 +27,6 @@ #define SLICE_TIME 100000000ULL /* ns */ -typedef struct CowRequest { - int64_t start; - int64_t end; - QLIST_ENTRY(CowRequest) list; - CoQueue wait_queue; /* coroutines blocked on this request */ -} CowRequest; - typedef struct BackupBlockJob { BlockJob common; BlockDriverState *target; @@ -44,46 +37,9 @@ typedef struct BackupBlockJob { CoRwlock flush_rwlock; uint64_t sectors_read; HBitmap *bitmap; - QLIST_HEAD(, CowRequest) inflight_reqs; + CowJob cow_job; } BackupBlockJob; -/* See if in-flight requests overlap and wait for them to complete */ -static void coroutine_fn wait_for_overlapping_requests(BackupBlockJob *job, - int64_t start, - int64_t end) -{ - CowRequest *req; - bool retry; - - do { - retry = false; - QLIST_FOREACH(req, &job->inflight_reqs, list) { - if (end > req->start && start < req->end) { - qemu_co_queue_wait(&req->wait_queue); - retry = true; - break; - } - } - } while (retry); -} - -/* Keep track of an in-flight request */ -static void cow_request_begin(CowRequest *req, BackupBlockJob *job, - int64_t start, int64_t end) -{ - req->start = start; - req->end = end; - qemu_co_queue_init(&req->wait_queue); - QLIST_INSERT_HEAD(&job->inflight_reqs, req, list); -} - -/* Forget about a completed request */ -static void cow_request_end(CowRequest *req) -{ - QLIST_REMOVE(req, list); - qemu_co_queue_restart_all(&req->wait_queue); -} - static int coroutine_fn backup_do_cow(BlockDriverState *bs, int64_t sector_num, int nb_sectors, bool *error_is_read) @@ -104,8 +60,8 @@ static int coroutine_fn backup_do_cow(BlockDriverState *bs, trace_backup_do_cow_enter(job, start, sector_num, nb_sectors); - wait_for_overlapping_requests(job, start, end); - cow_request_begin(&cow_request, job, start, end); + wait_for_overlapping_requests(&job->cow_job, start, end); + cow_request_begin(&cow_request, &job->cow_job, start, end); for (; start < end; start++) { if (hbitmap_get(job->bitmap, start)) { @@ -255,7 +211,7 @@ static void coroutine_fn backup_run(void *opaque) int64_t start, end; int ret = 0; - QLIST_INIT(&job->inflight_reqs); + QLIST_INIT(&job->cow_job.inflight_reqs); qemu_co_rwlock_init(&job->flush_rwlock); start = 0; diff --git a/blockcow.c b/blockcow.c new file mode 100644 index 0000000..c070a62 --- /dev/null +++ b/blockcow.c @@ -0,0 +1,52 @@ +/* + * QEMU block WAW + * + * Copyright Fujitsu, Corp. 2015 + * Copyright (c) 2015 Intel Corporation + * Copyright (c) 2015 HUAWEI TECHNOLOGIES CO.,LTD. + * + * Authors: + * Wen Congyang (wency@cn.fujitsu.com) + * + * This work is licensed under the terms of the GNU GPL, version 2 or later. + * See the COPYING file in the top-level directory. + * + */ + +#include "block/block.h" + +/* See if in-flight requests overlap and wait for them to complete */ +void coroutine_fn +wait_for_overlapping_requests(CowJob *job, int64_t start, int64_t end) +{ + CowRequest *req; + bool retry; + + do { + retry = false; + QLIST_FOREACH(req, &job->inflight_reqs, list) { + if (end > req->start && start < req->end) { + qemu_co_queue_wait(&req->wait_queue); + retry = true; + break; + } + } + } while (retry); +} + +/* Keep track of an in-flight request */ +void cow_request_begin(CowRequest *req, CowJob *job, + int64_t start, int64_t end) +{ + req->start = start; + req->end = end; + qemu_co_queue_init(&req->wait_queue); + QLIST_INSERT_HEAD(&job->inflight_reqs, req, list); +} + +/* Forget about a completed request */ +void cow_request_end(CowRequest *req) +{ + QLIST_REMOVE(req, list); + qemu_co_queue_restart_all(&req->wait_queue); +} diff --git a/include/block/block.h b/include/block/block.h index 632b9fc..0a55373 100644 --- a/include/block/block.h +++ b/include/block/block.h @@ -567,4 +567,21 @@ int bdrv_start_replication(BlockDriverState *bs, int mode); int bdrv_do_checkpoint(BlockDriverState *bs); int bdrv_stop_replication(BlockDriverState *bs); +typedef struct CowRequest { + int64_t start; + int64_t end; + QLIST_ENTRY(CowRequest) list; + CoQueue wait_queue; /* coroutines blocked on this request */ +} CowRequest; + +typedef struct CowJob { + QLIST_HEAD(, CowRequest) inflight_reqs; +} CowJob; + +void coroutine_fn +wait_for_overlapping_requests(CowJob *job, int64_t start, int64_t end); +void cow_request_begin(CowRequest *req, CowJob *job, + int64_t start, int64_t end); +void cow_request_end(CowRequest *req); + #endif