From patchwork Fri Nov 3 22:23:35 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bart Van Assche X-Patchwork-Id: 10041253 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 960EA600C5 for ; Fri, 3 Nov 2017 22:23:47 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 8836D299B0 for ; Fri, 3 Nov 2017 22:23:47 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 7CDDA299C3; Fri, 3 Nov 2017 22:23:47 +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.8 required=2.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_HI,T_DKIM_INVALID autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id E101A299C4 for ; Fri, 3 Nov 2017 22:23:46 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752968AbdKCWXp (ORCPT ); Fri, 3 Nov 2017 18:23:45 -0400 Received: from esa1.hgst.iphmx.com ([68.232.141.245]:54160 "EHLO esa1.hgst.iphmx.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751907AbdKCWXm (ORCPT ); Fri, 3 Nov 2017 18:23:42 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=wdc.com; i=@wdc.com; q=dns/txt; s=dkim.wdc.com; t=1509747822; x=1541283822; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version; bh=YNj6ihGFeluZFU6rsDNOQmOMVNsOR0DoJTzcCNbYXLQ=; b=RYVRI64lL813Ep1xEwiClPrbhqNLfs3zc+Mf8UNs52a1EF1/E43kBSoV zjEAWIgMMyYY7ZiqjF9ccYWjUf02BPRyCygNHaGgWMw1Mnbjw7IC3R2go jRAq5O8XsFn5lZuYnLyNfF99/Jy86cdC5aSUDwT1RZ1Z9ON0TeCbFXJY+ PHJARjQZ5+QgPUxbvK3NaRDob81rEfZxaFGL9mBryl3HYXW/0S3BRbp50 blyYSIJX6rM4V80s4m0Cv/yTbu0ZFy0IT+Uhs+CSKiY8sjB5IcXvFe75B h9yFap90a5HNEoAZcbjzpM0TXXHrrqtVwc2MKq/MD7+/zAogT0smQq6KK g==; X-IronPort-AV: E=Sophos;i="5.44,339,1505750400"; d="scan'208";a="163704785" Received: from h199-255-45-14.hgst.com (HELO uls-op-cesaep01.wdc.com) ([199.255.45.14]) by ob1.hgst.iphmx.com with ESMTP; 04 Nov 2017 06:23:41 +0800 Received: from uls-op-cesaip02.wdc.com ([10.248.3.37]) by uls-op-cesaep01.wdc.com with ESMTP; 03 Nov 2017 15:21:44 -0700 Received: from unknown (HELO MILHUBIP04.sdcorp.global.sandisk.com) ([10.177.9.97]) by uls-op-cesaip02.wdc.com with ESMTP; 03 Nov 2017 15:23:42 -0700 Received: from milsmgip12.sandisk.com (10.177.9.6) by MILHUBIP04.sdcorp.global.sandisk.com (10.177.9.97) with Microsoft SMTP Server id 14.3.319.2; Fri, 3 Nov 2017 15:23:40 -0700 X-AuditID: 0ab1095a-d99e3980000146e4-7b-59fcec6cac7b Received: from thinkpad-bart.int.fusionio.com ( [10.177.8.100]) by (Symantec Messaging Gateway) with SMTP id 87.92.18148.C6CECF95; Fri, 3 Nov 2017 15:23:40 -0700 (PDT) From: Bart Van Assche To: Jens Axboe CC: , Christoph Hellwig , "Ard Biesheuvel" , Herbert Xu , Bart Van Assche , Keith Busch , Sagi Grimberg Subject: [PATCH v3 4/8] nvmet/rdma: Use sgl_alloc() and sgl_free() Date: Fri, 3 Nov 2017 15:23:35 -0700 Message-ID: <20171103222339.26540-5-bart.vanassche@wdc.com> X-Mailer: git-send-email 2.14.3 In-Reply-To: <20171103222339.26540-1-bart.vanassche@wdc.com> References: <20171103222339.26540-1-bart.vanassche@wdc.com> X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFjrAJMWRmVeSWpSXmKPExsXCtZEjRTfnzZ9Ig1OXdC3+f9jNaLH6bj+b xaU/XxgtVq4+ymTR/UrG4t7RL0wWe29pW6x7/Z7FgcNj2wFVj/P3NrJ4LN7zksnj8tlSjzvX 9rB57L7ZwObxeZOcR/uBbqYAjigum5TUnMyy1CJ9uwSujIf7z7EVnJWqeDZ5NnsD4w/RLkZO DgkBE4nFB1oYuxi5OIQEVjNKPF42lwUkwSagJ3Fq3j4mEFtEQEGi5/dKNpAiZoFJTBK7N15i B0kICzhJvH+wFKibg4NFQFXi1Ms0kDCvgLXEouUf2CEWyEusfXuPEcTmFLCRuLKgCWymEFBN b+cK9gmM3AsYGVYxiuVm5hTnpmcWGBrpFSfmpWQWZ+sl5+duYgSHEWfUDsbrE80PMTJxcEo1 MG7cxnrlo6gWX87qI6d3W6XV199pS6nRm/ZdeEr+jrCit5ebOGYl8hk7zWb+fLq0tfXCinMT xBLknnnMdjvaWTdrm6bI35YlvM33WJ/yP9uQbNzDn9x4+a6firrhridrrxz8FGy6S/Xs5Jsa Ztb7T2gtcg7KqAg59k3z878nV37PidyutTzXw1mJpTgj0VCLuag4EQCFuq0+0wEAAA== MIME-Version: 1.0 Sender: linux-block-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-block@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Use the sgl_alloc() and sgl_free() functions instead of open coding these functions. Signed-off-by: Bart Van Assche Reviewed-by: Johannes Thumshirn Reviewed-by: Hannes Reinecke Cc: Keith Busch Cc: Christoph Hellwig Cc: Sagi Grimberg --- drivers/nvme/target/Kconfig | 1 + drivers/nvme/target/rdma.c | 63 +++------------------------------------------ 2 files changed, 5 insertions(+), 59 deletions(-) diff --git a/drivers/nvme/target/Kconfig b/drivers/nvme/target/Kconfig index 4d9715630e21..5f4f8b16685f 100644 --- a/drivers/nvme/target/Kconfig +++ b/drivers/nvme/target/Kconfig @@ -29,6 +29,7 @@ config NVME_TARGET_RDMA tristate "NVMe over Fabrics RDMA target support" depends on INFINIBAND depends on NVME_TARGET + select SGL_ALLOC help This enables the NVMe RDMA target support, which allows exporting NVMe devices over RDMA. diff --git a/drivers/nvme/target/rdma.c b/drivers/nvme/target/rdma.c index 76d2bb793afe..363d44c10b68 100644 --- a/drivers/nvme/target/rdma.c +++ b/drivers/nvme/target/rdma.c @@ -185,59 +185,6 @@ nvmet_rdma_put_rsp(struct nvmet_rdma_rsp *rsp) spin_unlock_irqrestore(&rsp->queue->rsps_lock, flags); } -static void nvmet_rdma_free_sgl(struct scatterlist *sgl, unsigned int nents) -{ - struct scatterlist *sg; - int count; - - if (!sgl || !nents) - return; - - for_each_sg(sgl, sg, nents, count) - __free_page(sg_page(sg)); - kfree(sgl); -} - -static int nvmet_rdma_alloc_sgl(struct scatterlist **sgl, unsigned int *nents, - u32 length) -{ - struct scatterlist *sg; - struct page *page; - unsigned int nent; - int i = 0; - - nent = DIV_ROUND_UP(length, PAGE_SIZE); - sg = kmalloc_array(nent, sizeof(struct scatterlist), GFP_KERNEL); - if (!sg) - goto out; - - sg_init_table(sg, nent); - - while (length) { - u32 page_len = min_t(u32, length, PAGE_SIZE); - - page = alloc_page(GFP_KERNEL); - if (!page) - goto out_free_pages; - - sg_set_page(&sg[i], page, page_len, 0); - length -= page_len; - i++; - } - *sgl = sg; - *nents = nent; - return 0; - -out_free_pages: - while (i > 0) { - i--; - __free_page(sg_page(&sg[i])); - } - kfree(sg); -out: - return NVME_SC_INTERNAL; -} - static int nvmet_rdma_alloc_cmd(struct nvmet_rdma_device *ndev, struct nvmet_rdma_cmd *c, bool admin) { @@ -484,7 +431,7 @@ static void nvmet_rdma_release_rsp(struct nvmet_rdma_rsp *rsp) } if (rsp->req.sg != &rsp->cmd->inline_sg) - nvmet_rdma_free_sgl(rsp->req.sg, rsp->req.sg_cnt); + sgl_free(rsp->req.sg); if (unlikely(!list_empty_careful(&queue->rsp_wr_wait_list))) nvmet_rdma_process_wr_wait_list(queue); @@ -620,16 +567,14 @@ static u16 nvmet_rdma_map_sgl_keyed(struct nvmet_rdma_rsp *rsp, u32 len = get_unaligned_le24(sgl->length); u32 key = get_unaligned_le32(sgl->key); int ret; - u16 status; /* no data command? */ if (!len) return 0; - status = nvmet_rdma_alloc_sgl(&rsp->req.sg, &rsp->req.sg_cnt, - len); - if (status) - return status; + rsp->req.sg = sgl_alloc(len, GFP_KERNEL, &rsp->req.sg_cnt); + if (!rsp->req.sg) + return NVME_SC_INTERNAL; ret = rdma_rw_ctx_init(&rsp->rw, cm_id->qp, cm_id->port_num, rsp->req.sg, rsp->req.sg_cnt, 0, addr, key,