From patchwork Thu Oct 12 22:45:47 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: 10003073 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 9DAF760325 for ; Thu, 12 Oct 2017 22:47:28 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 8FA6628E5D for ; Thu, 12 Oct 2017 22:47:28 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 848A928EA2; Thu, 12 Oct 2017 22:47:28 +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=-5.1 required=2.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_HI, T_DKIM_INVALID, URIBL_BLACK 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 22BA628E5D for ; Thu, 12 Oct 2017 22:47:27 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1757297AbdJLWrZ (ORCPT ); Thu, 12 Oct 2017 18:47:25 -0400 Received: from esa6.hgst.iphmx.com ([216.71.154.45]:37809 "EHLO esa6.hgst.iphmx.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753789AbdJLWrQ (ORCPT ); Thu, 12 Oct 2017 18:47:16 -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=1507848436; x=1539384436; h=from:to:cc:subject:date:message-id:in-reply-to: references; bh=1ummeTxtLkJN/SLwZicuvzD6n87X0I/qloLOdhmKGWw=; b=MfOZKXF41atrUs3S5lgC9HhZTIDsLDFiwySp1fHtgcLXuqkDWayeMdXh VxwwniRJVtc4LRzq/eV4T9w15oiHB6CMBCeuBKUspnpuGxbgs2sw5yTWv xbo08J8gBl4kpj6QXALstxus65MxJuOHIFWmz03vWs1GctEuXgsTTf/++ Kj6ooeKLQA9uvZKzCCkLceETsu7dCaYU1oNSB+RomcMfxN5OCPikQ6jHO aebN21ogLrbRdBQN3HdmzxkTFIFMr7+FlZbVsoq2m+IhT4HQ/6DbjFgWY 4DW1zYO9kxN4bmkyirMGGntuFv5GpqyN5/U8SfJc+0C7buv5e2xByxMB8 w==; X-IronPort-AV: E=Sophos;i="5.43,368,1503331200"; d="scan'208";a="58103854" Received: from sjappemgw12.hgst.com (HELO sjappemgw11.hgst.com) ([199.255.44.66]) by ob1.hgst.iphmx.com with ESMTP; 13 Oct 2017 06:47:14 +0800 Received: from thinkpad-bart.sdcorp.global.sandisk.com (HELO thinkpad-bart.int.fusionio.com) ([10.11.172.152]) by sjappemgw11.hgst.com with ESMTP; 12 Oct 2017 15:45:52 -0700 From: Bart Van Assche To: Jens Axboe Cc: linux-block@vger.kernel.org, linux-scsi@vger.kernel.org, linux-nvme@lists.infradead.org, Bart Van Assche , "Nicholas A . Bellinger" , Christoph Hellwig , Hannes Reinecke , Sagi Grimberg Subject: [PATCH 5/8] target: Use sgl_alloc_order() and sgl_free() Date: Thu, 12 Oct 2017 15:45:47 -0700 Message-Id: <20171012224550.25440-6-bart.vanassche@wdc.com> X-Mailer: git-send-email 2.14.2 In-Reply-To: <20171012224550.25440-1-bart.vanassche@wdc.com> References: <20171012224550.25440-1-bart.vanassche@wdc.com> 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_order() and sgl_free() functions instead of open coding these functions. Signed-off-by: Bart Van Assche Cc: Nicholas A. Bellinger Cc: Christoph Hellwig Cc: Hannes Reinecke Cc: Sagi Grimberg --- drivers/target/Kconfig | 1 + drivers/target/target_core_transport.c | 47 ++++------------------------------ 2 files changed, 6 insertions(+), 42 deletions(-) diff --git a/drivers/target/Kconfig b/drivers/target/Kconfig index e2bc99980f75..4c44d7bed01a 100644 --- a/drivers/target/Kconfig +++ b/drivers/target/Kconfig @@ -5,6 +5,7 @@ menuconfig TARGET_CORE select CONFIGFS_FS select CRC_T10DIF select BLK_SCSI_REQUEST # only for scsi_command_size_tbl.. + select SGL_ALLOC default n help Say Y or M here to enable the TCM Storage Engine and ConfigFS enabled diff --git a/drivers/target/target_core_transport.c b/drivers/target/target_core_transport.c index 836d552b0385..e8f0eabd25ab 100644 --- a/drivers/target/target_core_transport.c +++ b/drivers/target/target_core_transport.c @@ -34,6 +34,7 @@ #include #include #include +#include #include #include #include @@ -2293,13 +2294,7 @@ static void target_complete_ok_work(struct work_struct *work) void target_free_sgl(struct scatterlist *sgl, int nents) { - struct scatterlist *sg; - int count; - - for_each_sg(sgl, sg, nents, count) - __free_page(sg_page(sg)); - - kfree(sgl); + sgl_free(sgl); } EXPORT_SYMBOL(target_free_sgl); @@ -2423,42 +2418,10 @@ int target_alloc_sgl(struct scatterlist **sgl, unsigned int *nents, u32 length, bool zero_page, bool chainable) { - struct scatterlist *sg; - struct page *page; - gfp_t zero_flag = (zero_page) ? __GFP_ZERO : 0; - unsigned int nalloc, nent; - int i = 0; - - nalloc = nent = DIV_ROUND_UP(length, PAGE_SIZE); - if (chainable) - nalloc++; - sg = kmalloc_array(nalloc, sizeof(struct scatterlist), GFP_KERNEL); - if (!sg) - return -ENOMEM; + gfp_t gfp = GFP_KERNEL | (zero_page ? __GFP_ZERO : 0); - sg_init_table(sg, nalloc); - - while (length) { - u32 page_len = min_t(u32, length, PAGE_SIZE); - page = alloc_page(GFP_KERNEL | zero_flag); - if (!page) - goto out; - - sg_set_page(&sg[i], page, page_len, 0); - length -= page_len; - i++; - } - *sgl = sg; - *nents = nent; - return 0; - -out: - while (i > 0) { - i--; - __free_page(sg_page(&sg[i])); - } - kfree(sg); - return -ENOMEM; + *sgl = sgl_alloc_order(length, 0, nents, gfp, chainable); + return *sgl ? 0 : -ENOMEM; } EXPORT_SYMBOL(target_alloc_sgl);