From patchwork Fri Nov 3 22:23:34 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: 10041255 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 93B2B600C5 for ; Fri, 3 Nov 2017 22:23:48 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 8611B299B7 for ; Fri, 3 Nov 2017 22:23:48 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 7B11F299C6; Fri, 3 Nov 2017 22:23:48 +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 DDDB7299B7 for ; Fri, 3 Nov 2017 22:23:47 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751907AbdKCWXq (ORCPT ); Fri, 3 Nov 2017 18:23:46 -0400 Received: from esa1.hgst.iphmx.com ([68.232.141.245]:46889 "EHLO esa1.hgst.iphmx.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751942AbdKCWXn (ORCPT ); Fri, 3 Nov 2017 18:23:43 -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=1509747823; x=1541283823; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version; bh=YdqzouhPV1hARgo3Kvvig3L5K1MYE5EjIRDDnpnzTUg=; b=qVReg6wb/GcJpMo3QPLtnx2z1poyqETq2tVqhNyrvq4B/S5OxTw3wZtg 8q8BA7FVjsNsDxGYARxKkaQDjshOnYhSnlXJXTezu2vnLlian97xqE0O5 x/EqodDukAlg43HwIf895vlg5Xn38Tz03urmmNWQg6WPb+jaN2e2KdQ85 q/BrGxVA4eboW9tMkoJZX9XynnRvq1Fc1gG02IXDWORwgcopiYiyP+KHP Ihq1sEy+BRlwWP6xZTPsKA+CFM9KHb40VaP7yFZUkBCPMXJnxwdIMAaep xbBhqA47Kk8ns/83MG/w3jRxd1qoEh2GQ4xy3LEuq8VAgHPdLkZ9g1FaW Q==; X-IronPort-AV: E=Sophos;i="5.44,339,1505750400"; d="scan'208";a="163704787" 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 MILHUBIP03.sdcorp.global.sandisk.com) ([10.177.9.96]) by uls-op-cesaip02.wdc.com with ESMTP; 03 Nov 2017 15:23:42 -0700 Received: from milsmgip12.sandisk.com (10.177.8.100) by MILHUBIP03.sdcorp.global.sandisk.com (10.177.9.96) with Microsoft SMTP Server id 14.3.319.2; Fri, 3 Nov 2017 15:23:40 -0700 X-AuditID: 0ab1095a-d99e3980000146e4-7a-59fcec6c90fe Received: from thinkpad-bart.int.fusionio.com ( [10.177.8.100]) by (Symantec Messaging Gateway) with SMTP id 17.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 , James Smart , Sagi Grimberg Subject: [PATCH v3 3/8] nvmet/fc: Use sgl_alloc() and sgl_free() Date: Fri, 3 Nov 2017 15:23:34 -0700 Message-ID: <20171103222339.26540-4-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+NgFjrJJMWRmVeSWpSXmKPExsXCtZEjRTfnzZ9Ig13XtS3+f9jNaLH6bj+b xaU/XxgtVq4+ymTR/UrGYvfCj0wW945+YbLYe0vbYt3r9ywOnB6z7p9l89h2QNXj/L2NLB6L 97xk8rh8ttTjzrU9bB67bzaweXzeJOfRfqCbKYAzissmJTUnsyy1SN8ugSvjbs979oKrYhWv 1qk3MF4R6mLk5JAQMJFoe3ifHcQWEljNKHH1qBqIzSagJ3Fq3j4mEFtEQEGi5/dKti5GLg5m gT1MEs13frOAJIQFHCQWdT5lA7FZBFQl9s7eywxi8wpYS9zbcoQdYoG8xNq39xhBbE4BG4kr C5qYIJZZS/R2rmCfwMi9gJFhFaNYbmZOcW56ZoGhkV5xYl5KZnG2XnJ+7iZGcGBxRu1gvD7R /BAjEwenVANjT+HphIyoqoXLD89UXJQ9bZnEQnPxGDXHotNPyzLDDBbc2bY5Z4H21VaJZuuc U4a+GcwJHWvvL1w765fs7X+15tsTQjh/XpZ8pOlrlsFYa3oiq2CyUaKW3HsJnZK7xcVRzU2u dxTaFAq2yDpJJ/5r9gqyUsu6OqG/O9l/5pZGjd/5vZML6pVYijMSDbWYi4oTATy3fszcAQAA 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: James Smart Cc: Sagi Grimberg --- drivers/nvme/target/Kconfig | 1 + drivers/nvme/target/fc.c | 36 ++---------------------------------- 2 files changed, 3 insertions(+), 34 deletions(-) diff --git a/drivers/nvme/target/Kconfig b/drivers/nvme/target/Kconfig index 03e4ab65fe77..4d9715630e21 100644 --- a/drivers/nvme/target/Kconfig +++ b/drivers/nvme/target/Kconfig @@ -39,6 +39,7 @@ config NVME_TARGET_FC tristate "NVMe over Fabrics FC target driver" depends on NVME_TARGET depends on HAS_DMA + select SGL_ALLOC help This enables the NVMe FC target support, which allows exporting NVMe devices over FC. diff --git a/drivers/nvme/target/fc.c b/drivers/nvme/target/fc.c index 5f2570f5dfa9..1b4030d74ceb 100644 --- a/drivers/nvme/target/fc.c +++ b/drivers/nvme/target/fc.c @@ -1695,31 +1695,12 @@ static int nvmet_fc_alloc_tgt_pgs(struct nvmet_fc_fcp_iod *fod) { struct scatterlist *sg; - struct page *page; unsigned int nent; - u32 page_len, length; - int i = 0; - length = fod->total_length; - nent = DIV_ROUND_UP(length, PAGE_SIZE); - sg = kmalloc_array(nent, sizeof(struct scatterlist), GFP_KERNEL); + sg = sgl_alloc(fod->total_length, GFP_KERNEL, &nent); if (!sg) goto out; - sg_init_table(sg, nent); - - while (length) { - 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++; - } - fod->data_sg = sg; fod->data_sg_cnt = nent; fod->data_sg_cnt = fc_dma_map_sg(fod->tgtport->dev, sg, nent, @@ -1729,14 +1710,6 @@ nvmet_fc_alloc_tgt_pgs(struct nvmet_fc_fcp_iod *fod) return 0; -out_free_pages: - while (i > 0) { - i--; - __free_page(sg_page(&sg[i])); - } - kfree(sg); - fod->data_sg = NULL; - fod->data_sg_cnt = 0; out: return NVME_SC_INTERNAL; } @@ -1744,18 +1717,13 @@ nvmet_fc_alloc_tgt_pgs(struct nvmet_fc_fcp_iod *fod) static void nvmet_fc_free_tgt_pgs(struct nvmet_fc_fcp_iod *fod) { - struct scatterlist *sg; - int count; - if (!fod->data_sg || !fod->data_sg_cnt) return; fc_dma_unmap_sg(fod->tgtport->dev, fod->data_sg, fod->data_sg_cnt, ((fod->io_dir == NVMET_FCP_WRITE) ? DMA_FROM_DEVICE : DMA_TO_DEVICE)); - for_each_sg(fod->data_sg, sg, fod->data_sg_cnt, count) - __free_page(sg_page(sg)); - kfree(fod->data_sg); + sgl_free(fod->data_sg); fod->data_sg = NULL; fod->data_sg_cnt = 0; }