From patchwork Fri May 26 20:21:45 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kevin Wolf X-Patchwork-Id: 9751123 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 9113560246 for ; Fri, 26 May 2017 20:24:08 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 83BBE27F90 for ; Fri, 26 May 2017 20:24:08 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 7849E28347; Fri, 26 May 2017 20:24:08 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.9 required=2.0 tests=BAYES_00,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id E16CF27F90 for ; Fri, 26 May 2017 20:24:07 +0000 (UTC) Received: from localhost ([::1]:38271 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dELmI-0004bY-Tn for patchwork-qemu-devel@patchwork.kernel.org; Fri, 26 May 2017 16:24:06 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:58409) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dELks-0004Sf-DB for qemu-devel@nongnu.org; Fri, 26 May 2017 16:22:39 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dELkr-0005D9-Ad for qemu-devel@nongnu.org; Fri, 26 May 2017 16:22:38 -0400 Received: from mx1.redhat.com ([209.132.183.28]:58764) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1dELko-0005C9-F2; Fri, 26 May 2017 16:22:34 -0400 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 6E7BC368E6; Fri, 26 May 2017 20:22:33 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 6E7BC368E6 Authentication-Results: ext-mx06.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx06.extmail.prod.ext.phx2.redhat.com; spf=pass smtp.mailfrom=kwolf@redhat.com DKIM-Filter: OpenDKIM Filter v2.11.0 mx1.redhat.com 6E7BC368E6 Received: from noname.redhat.com (ovpn-116-43.ams2.redhat.com [10.36.116.43]) by smtp.corp.redhat.com (Postfix) with ESMTP id 7C69F1713B; Fri, 26 May 2017 20:22:31 +0000 (UTC) From: Kevin Wolf To: qemu-block@nongnu.org Date: Fri, 26 May 2017 22:21:45 +0200 Message-Id: <1495830130-30611-5-git-send-email-kwolf@redhat.com> In-Reply-To: <1495830130-30611-1-git-send-email-kwolf@redhat.com> References: <1495830130-30611-1-git-send-email-kwolf@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.30]); Fri, 26 May 2017 20:22:33 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH 04/29] qed: Remove callback from qed_read_l2_table() X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: kwolf@redhat.com, pbonzini@redhat.com, qemu-devel@nongnu.org, stefanha@redhat.com, mreitz@redhat.com Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP Signed-off-by: Kevin Wolf Reviewed-by: Eric Blake Reviewed-by: Stefan Hajnoczi --- block/qed-cluster.c | 94 ++++++++++++++++++----------------------------------- block/qed-table.c | 15 +++------ block/qed.h | 3 +- 3 files changed, 36 insertions(+), 76 deletions(-) diff --git a/block/qed-cluster.c b/block/qed-cluster.c index 8f5da74..d279944 100644 --- a/block/qed-cluster.c +++ b/block/qed-cluster.c @@ -61,59 +61,6 @@ static unsigned int qed_count_contiguous_clusters(BDRVQEDState *s, return i - index; } -typedef struct { - BDRVQEDState *s; - uint64_t pos; - size_t len; - - QEDRequest *request; - - /* User callback */ - QEDFindClusterFunc *cb; - void *opaque; -} QEDFindClusterCB; - -static void qed_find_cluster_cb(void *opaque, int ret) -{ - QEDFindClusterCB *find_cluster_cb = opaque; - BDRVQEDState *s = find_cluster_cb->s; - QEDRequest *request = find_cluster_cb->request; - uint64_t offset = 0; - size_t len = 0; - unsigned int index; - unsigned int n; - - qed_acquire(s); - if (ret) { - goto out; - } - - index = qed_l2_index(s, find_cluster_cb->pos); - n = qed_bytes_to_clusters(s, - qed_offset_into_cluster(s, find_cluster_cb->pos) + - find_cluster_cb->len); - n = qed_count_contiguous_clusters(s, request->l2_table->table, - index, n, &offset); - - if (qed_offset_is_unalloc_cluster(offset)) { - ret = QED_CLUSTER_L2; - } else if (qed_offset_is_zero_cluster(offset)) { - ret = QED_CLUSTER_ZERO; - } else if (qed_check_cluster_offset(s, offset)) { - ret = QED_CLUSTER_FOUND; - } else { - ret = -EINVAL; - } - - len = MIN(find_cluster_cb->len, n * s->header.cluster_size - - qed_offset_into_cluster(s, find_cluster_cb->pos)); - -out: - find_cluster_cb->cb(find_cluster_cb->opaque, ret, offset, len); - qed_release(s); - g_free(find_cluster_cb); -} - /** * Find the offset of a data cluster * @@ -137,8 +84,11 @@ out: void qed_find_cluster(BDRVQEDState *s, QEDRequest *request, uint64_t pos, size_t len, QEDFindClusterFunc *cb, void *opaque) { - QEDFindClusterCB *find_cluster_cb; uint64_t l2_offset; + uint64_t offset = 0; + unsigned int index; + unsigned int n; + int ret; /* Limit length to L2 boundary. Requests are broken up at the L2 boundary * so that a request acts on one L2 table at a time. @@ -155,14 +105,32 @@ void qed_find_cluster(BDRVQEDState *s, QEDRequest *request, uint64_t pos, return; } - find_cluster_cb = g_malloc(sizeof(*find_cluster_cb)); - find_cluster_cb->s = s; - find_cluster_cb->pos = pos; - find_cluster_cb->len = len; - find_cluster_cb->cb = cb; - find_cluster_cb->opaque = opaque; - find_cluster_cb->request = request; + ret = qed_read_l2_table(s, request, l2_offset); + qed_acquire(s); + if (ret) { + goto out; + } + + index = qed_l2_index(s, pos); + n = qed_bytes_to_clusters(s, + qed_offset_into_cluster(s, pos) + len); + n = qed_count_contiguous_clusters(s, request->l2_table->table, + index, n, &offset); + + if (qed_offset_is_unalloc_cluster(offset)) { + ret = QED_CLUSTER_L2; + } else if (qed_offset_is_zero_cluster(offset)) { + ret = QED_CLUSTER_ZERO; + } else if (qed_check_cluster_offset(s, offset)) { + ret = QED_CLUSTER_FOUND; + } else { + ret = -EINVAL; + } + + len = MIN(len, + n * s->header.cluster_size - qed_offset_into_cluster(s, pos)); - qed_read_l2_table(s, request, l2_offset, - qed_find_cluster_cb, find_cluster_cb); +out: + cb(opaque, ret, offset, len); + qed_release(s); } diff --git a/block/qed-table.c b/block/qed-table.c index 4270003..ffecbea 100644 --- a/block/qed-table.c +++ b/block/qed-table.c @@ -177,8 +177,7 @@ int qed_write_l1_table_sync(BDRVQEDState *s, unsigned int index, return ret; } -void qed_read_l2_table(BDRVQEDState *s, QEDRequest *request, uint64_t offset, - BlockCompletionFunc *cb, void *opaque) +int qed_read_l2_table(BDRVQEDState *s, QEDRequest *request, uint64_t offset) { int ret; @@ -187,8 +186,7 @@ void qed_read_l2_table(BDRVQEDState *s, QEDRequest *request, uint64_t offset, /* Check for cached L2 entry */ request->l2_table = qed_find_l2_cache_entry(&s->l2_cache, offset); if (request->l2_table) { - cb(opaque, 0); - return; + return 0; } request->l2_table = qed_alloc_l2_cache_entry(&s->l2_cache); @@ -215,17 +213,12 @@ void qed_read_l2_table(BDRVQEDState *s, QEDRequest *request, uint64_t offset, } qed_release(s); - cb(opaque, ret); + return ret; } int qed_read_l2_table_sync(BDRVQEDState *s, QEDRequest *request, uint64_t offset) { - int ret = -EINPROGRESS; - - qed_read_l2_table(s, request, offset, qed_sync_cb, &ret); - BDRV_POLL_WHILE(s->bs, ret == -EINPROGRESS); - - return ret; + return qed_read_l2_table(s, request, offset); } void qed_write_l2_table(BDRVQEDState *s, QEDRequest *request, diff --git a/block/qed.h b/block/qed.h index ce8c314..c715058 100644 --- a/block/qed.h +++ b/block/qed.h @@ -237,8 +237,7 @@ int qed_write_l1_table_sync(BDRVQEDState *s, unsigned int index, unsigned int n); int qed_read_l2_table_sync(BDRVQEDState *s, QEDRequest *request, uint64_t offset); -void qed_read_l2_table(BDRVQEDState *s, QEDRequest *request, uint64_t offset, - BlockCompletionFunc *cb, void *opaque); +int qed_read_l2_table(BDRVQEDState *s, QEDRequest *request, uint64_t offset); void qed_write_l2_table(BDRVQEDState *s, QEDRequest *request, unsigned int index, unsigned int n, bool flush, BlockCompletionFunc *cb, void *opaque);