From patchwork Tue May 6 12:54:40 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bart Van Assche X-Patchwork-Id: 4120841 Return-Path: X-Original-To: patchwork-linux-rdma@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.19.201]) by patchwork2.web.kernel.org (Postfix) with ESMTP id D30FAC0ACC for ; Tue, 6 May 2014 12:54:54 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id D7BD720123 for ; Tue, 6 May 2014 12:54:53 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id E7C2D201F9 for ; Tue, 6 May 2014 12:54:52 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1757301AbaEFMyr (ORCPT ); Tue, 6 May 2014 08:54:47 -0400 Received: from smtp03.stone-is.org ([87.238.162.6]:48276 "EHLO smtpgw.stone-is.be" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1757167AbaEFMyo (ORCPT ); Tue, 6 May 2014 08:54:44 -0400 Received: from localhost (unknown [127.0.0.1]) by smtpgw.stone-is.be (Postfix) with ESMTP id A5E29334BC0; Tue, 6 May 2014 12:54:43 +0000 (UTC) Received: from smtpgw.stone-is.be ([127.0.0.1]) by localhost (smtpgw.stone-is.be [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id 3YrUXTI0XFpm; Tue, 6 May 2014 14:54:42 +0200 (CEST) Received: from vz19.stone-is.net (vz19.stone-is.net [87.238.162.57]) by smtpgw.stone-is.be (Postfix) with ESMTP id 7D304334BC1; Tue, 6 May 2014 14:54:41 +0200 (CEST) X-No-Relay: not in my network X-No-Relay: not in my network X-No-Relay: not in my network X-No-Relay: not in my network X-No-Relay: not in my network X-No-Relay: not in my network Received: from [192.168.1.117] (178-119-65-67.access.telenet.be [178.119.65.67]) by vz19.stone-is.net (Postfix) with ESMTPSA id 39F872DC470; Tue, 6 May 2014 14:54:41 +0200 (CEST) Message-ID: <5368DB90.9050209@acm.org> Date: Tue, 06 May 2014 14:54:40 +0200 From: Bart Van Assche User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:24.0) Gecko/20100101 Thunderbird/24.4.0 MIME-Version: 1.0 To: Roland Dreier CC: Sagi Grimberg , Vu Pham , David Dillow , Sebastian Parschauer , linux-rdma Subject: [PATCH 6/9] IB/srp: Make srp_alloc_req_data() reallocate request data References: <5368DA5B.80609@acm.org> In-Reply-To: <5368DA5B.80609@acm.org> X-Enigmail-Version: 1.6 Sender: linux-rdma-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-rdma@vger.kernel.org X-Spam-Status: No, score=-7.5 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP This patch is needed by the patch that adds fast registration support. Signed-off-by: Bart Van Assche Cc: Roland Dreier Cc: David Dillow Cc: Sagi Grimberg Cc: Vu Pham Cc: Sebastian Parschauer Reviewed-by: Sagi Grimberg --- drivers/infiniband/ulp/srp/ib_srp.c | 41 ++++++++++++++++++++++++------------- 1 file changed, 27 insertions(+), 14 deletions(-) diff --git a/drivers/infiniband/ulp/srp/ib_srp.c b/drivers/infiniband/ulp/srp/ib_srp.c index ba434d6..1c4b0d3 100644 --- a/drivers/infiniband/ulp/srp/ib_srp.c +++ b/drivers/infiniband/ulp/srp/ib_srp.c @@ -574,17 +574,18 @@ static void srp_disconnect_target(struct srp_target_port *target) } } -static void srp_free_req_data(struct srp_target_port *target) +static void srp_free_req_data(struct srp_target_port *target, + struct srp_request *req_ring) { struct ib_device *ibdev = target->srp_host->srp_dev->dev; struct srp_request *req; int i; - if (!target->req_ring) + if (!req_ring) return; for (i = 0; i < target->req_ring_size; ++i) { - req = &target->req_ring[i]; + req = &req_ring[i]; kfree(req->fmr_list); kfree(req->map_page); if (req->indirect_dma_addr) { @@ -595,27 +596,34 @@ static void srp_free_req_data(struct srp_target_port *target) kfree(req->indirect_desc); } - kfree(target->req_ring); - target->req_ring = NULL; + kfree(req_ring); } +/** + * srp_alloc_req_data() - allocate or reallocate request data + * @target: SRP target port. + * + * If target->req_ring was non-NULL before this function got invoked it will + * also be non-NULL after this function has finished. + */ static int srp_alloc_req_data(struct srp_target_port *target) { struct srp_device *srp_dev = target->srp_host->srp_dev; struct ib_device *ibdev = srp_dev->dev; - struct srp_request *req; + struct list_head free_reqs; + struct srp_request *req_ring, *req; dma_addr_t dma_addr; int i, ret = -ENOMEM; - INIT_LIST_HEAD(&target->free_reqs); + INIT_LIST_HEAD(&free_reqs); - target->req_ring = kzalloc(target->req_ring_size * - sizeof(*target->req_ring), GFP_KERNEL); - if (!target->req_ring) + req_ring = kzalloc(target->req_ring_size * sizeof(*req_ring), + GFP_KERNEL); + if (!req_ring) goto out; for (i = 0; i < target->req_ring_size; ++i) { - req = &target->req_ring[i]; + req = &req_ring[i]; req->fmr_list = kmalloc(target->cmd_sg_cnt * sizeof(void *), GFP_KERNEL); req->map_page = kmalloc(SRP_FMR_SIZE * sizeof(void *), @@ -632,11 +640,16 @@ static int srp_alloc_req_data(struct srp_target_port *target) req->indirect_dma_addr = dma_addr; req->index = i; - list_add_tail(&req->list, &target->free_reqs); + list_add_tail(&req->list, &free_reqs); } + swap(target->req_ring, req_ring); + INIT_LIST_HEAD(&target->free_reqs); + list_splice(&free_reqs, &target->free_reqs); ret = 0; out: + srp_free_req_data(target, req_ring); + return ret; } @@ -669,7 +682,7 @@ static void srp_remove_target(struct srp_target_port *target) srp_free_target_ib(target); cancel_work_sync(&target->tl_err_work); srp_rport_put(target->rport); - srp_free_req_data(target); + srp_free_req_data(target, target->req_ring); spin_lock(&target->srp_host->target_lock); list_del(&target->list); @@ -2750,7 +2763,7 @@ err_free_ib: srp_free_target_ib(target); err_free_mem: - srp_free_req_data(target); + srp_free_req_data(target, target->req_ring); err: scsi_host_put(target_host);