From patchwork Wed Jul 27 13:44:43 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stefan Hajnoczi X-Patchwork-Id: 107068 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [140.186.70.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id AF172B6F68 for ; Wed, 27 Jul 2011 23:45:22 +1000 (EST) Received: from localhost ([::1]:59325 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Qm4QJ-0007Ls-Aj for incoming@patchwork.ozlabs.org; Wed, 27 Jul 2011 09:45:19 -0400 Received: from eggs.gnu.org ([140.186.70.92]:33389) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Qm4Q7-0007DX-Dt for qemu-devel@nongnu.org; Wed, 27 Jul 2011 09:45:09 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Qm4Q5-0004Uf-5O for qemu-devel@nongnu.org; Wed, 27 Jul 2011 09:45:07 -0400 Received: from mtagate3.uk.ibm.com ([194.196.100.163]:48825) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Qm4Q4-0004Ty-RI for qemu-devel@nongnu.org; Wed, 27 Jul 2011 09:45:05 -0400 Received: from d06nrmr1806.portsmouth.uk.ibm.com (d06nrmr1806.portsmouth.uk.ibm.com [9.149.39.193]) by mtagate3.uk.ibm.com (8.13.1/8.13.1) with ESMTP id p6RDj4A9018756 for ; Wed, 27 Jul 2011 13:45:04 GMT Received: from d06av09.portsmouth.uk.ibm.com (d06av09.portsmouth.uk.ibm.com [9.149.37.250]) by d06nrmr1806.portsmouth.uk.ibm.com (8.13.8/8.13.8/NCO v10.0) with ESMTP id p6RDj3852601126 for ; Wed, 27 Jul 2011 14:45:04 +0100 Received: from d06av09.portsmouth.uk.ibm.com (loopback [127.0.0.1]) by d06av09.portsmouth.uk.ibm.com (8.14.4/8.13.1/NCO v10.0 AVout) with ESMTP id p6RDj3kW016099 for ; Wed, 27 Jul 2011 07:45:03 -0600 Received: from stefanha-thinkpad.ibm.com ([9.78.66.144]) by d06av09.portsmouth.uk.ibm.com (8.14.4/8.13.1/NCO v10.0 AVin) with ESMTP id p6RDj1DC016013; Wed, 27 Jul 2011 07:45:03 -0600 From: Stefan Hajnoczi To: Date: Wed, 27 Jul 2011 14:44:43 +0100 Message-Id: <1311774295-8696-4-git-send-email-stefanha@linux.vnet.ibm.com> X-Mailer: git-send-email 1.7.5.4 In-Reply-To: <1311774295-8696-1-git-send-email-stefanha@linux.vnet.ibm.com> References: <1311774295-8696-1-git-send-email-stefanha@linux.vnet.ibm.com> X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6, seldom 2.4 (older, 4) X-Received-From: 194.196.100.163 Cc: Kevin Wolf , Anthony Liguori , Stefan Hajnoczi , Adam Litke Subject: [Qemu-devel] [PATCH 03/15] qed: extract qed_start_allocating_write() 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 Copy-on-read requests are a form of allocating write and will need to be queued like other allocating writes. This patch extracts the request queuing code for allocating writes so that it can be reused for copy-on-read in a later patch. Signed-off-by: Stefan Hajnoczi --- block/qed.c | 32 ++++++++++++++++++++++++++------ 1 files changed, 26 insertions(+), 6 deletions(-) diff --git a/block/qed.c b/block/qed.c index 565bbc1..cc193ad 100644 --- a/block/qed.c +++ b/block/qed.c @@ -1097,14 +1097,15 @@ static bool qed_should_set_need_check(BDRVQEDState *s) } /** - * Write new data cluster + * Start an allocating write request or queue it * - * @acb: Write request - * @len: Length in bytes + * @ret: true if request can proceed, false if queued * - * This path is taken when writing to previously unallocated clusters. + * If a request is queued this function returns false and the caller should + * return. When it becomes time for the request to proceed the qed_aio_next() + * function will be called. */ -static void qed_aio_write_alloc(QEDAIOCB *acb, size_t len) +static bool qed_start_allocating_write(QEDAIOCB *acb) { BDRVQEDState *s = acb_to_s(acb); @@ -1119,7 +1120,26 @@ static void qed_aio_write_alloc(QEDAIOCB *acb, size_t len) } if (acb != QSIMPLEQ_FIRST(&s->allocating_write_reqs) || s->allocating_write_reqs_plugged) { - return; /* wait for existing request to finish */ + return false; + } + return true; +} + +/** + * Write new data cluster + * + * @acb: Write request + * @len: Length in bytes + * + * This path is taken when writing to previously unallocated clusters. + */ +static void qed_aio_write_alloc(QEDAIOCB *acb, size_t len) +{ + BDRVQEDState *s = acb_to_s(acb); + BlockDriverCompletionFunc *cb; + + if (!qed_start_allocating_write(acb)) { + return; } acb->cur_nclusters = qed_bytes_to_clusters(s,