From: Bart Van Assche <bart.vanassche@wdc.com>
To: Jens Axboe <axboe@kernel.dk>
Cc: linux-block@vger.kernel.org, linux-scsi@vger.kernel.org,
linux-nvme@lists.infradead.org, linux-crypto@vger.kernel.org,
Bart Van Assche <bart.vanassche@wdc.com>,
"Nicholas A . Bellinger" <nab@linux-iscsi.org>,
Christoph Hellwig <hch@lst.de>, Hannes Reinecke <hare@suse.com>,
Sagi Grimberg <sagi@grimberg.me>
Subject: [PATCH v2 5/8] target: Use sgl_alloc_order() and sgl_free()
Date: Mon, 16 Oct 2017 15:49:37 -0700 [thread overview]
Message-ID: <20171016224940.1332-6-bart.vanassche@wdc.com> (raw)
In-Reply-To: <20171016224940.1332-1-bart.vanassche@wdc.com>
Use the sgl_alloc_order() and sgl_free() functions instead of open
coding these functions.
Signed-off-by: Bart Van Assche <bart.vanassche@wdc.com>
Cc: Nicholas A. Bellinger <nab@linux-iscsi.org>
Cc: Christoph Hellwig <hch@lst.de>
Cc: Hannes Reinecke <hare@suse.com>
Cc: Sagi Grimberg <sagi@grimberg.me>
---
drivers/target/Kconfig | 1 +
drivers/target/target_core_transport.c | 46 +++-------------------------------
2 files changed, 5 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..9bbd08be9d60 100644
--- a/drivers/target/target_core_transport.c
+++ b/drivers/target/target_core_transport.c
@@ -2293,13 +2293,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 +2417,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, chainable, gfp, nents);
+ return *sgl ? 0 : -ENOMEM;
}
EXPORT_SYMBOL(target_alloc_sgl);
--
2.14.2
next prev parent reply other threads:[~2017-10-16 22:49 UTC|newest]
Thread overview: 28+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-10-16 22:49 [PATCH v2 0/8] Introduce sgl_alloc() and sgl_free() Bart Van Assche
2017-10-16 22:49 ` [PATCH v2 1/8] lib/scatterlist: " Bart Van Assche
2017-10-17 6:06 ` Hannes Reinecke
2017-10-17 9:20 ` Johannes Thumshirn
2017-10-16 22:49 ` [PATCH v2 2/8] crypto: scompress - use " Bart Van Assche
2017-10-17 6:07 ` Hannes Reinecke
2017-11-01 14:50 ` Bart Van Assche
2017-11-01 15:17 ` Ard Biesheuvel
2017-11-01 15:45 ` Bart Van Assche
2017-11-01 15:51 ` Ard Biesheuvel
2017-10-16 22:49 ` [PATCH v2 3/8] nvmet/fc: Use " Bart Van Assche
2017-10-17 6:07 ` Hannes Reinecke
2017-10-16 22:49 ` [PATCH v2 4/8] nvmet/rdma: " Bart Van Assche
2017-10-17 6:08 ` Hannes Reinecke
2017-10-16 22:49 ` Bart Van Assche [this message]
2017-10-17 6:14 ` [PATCH v2 5/8] target: Use sgl_alloc_order() " Hannes Reinecke
2017-10-17 14:31 ` Bart Van Assche
2017-10-16 22:49 ` [PATCH v2 6/8] scsi/ipr: Use sgl_alloc_order() and sgl_free_order() Bart Van Assche
2017-10-17 6:19 ` Hannes Reinecke
2017-10-18 20:57 ` Brian King
2017-10-30 20:37 ` Bart Van Assche
2017-10-30 21:01 ` Brian King
2017-11-01 11:13 ` Hannes Reinecke
2017-10-16 22:49 ` [PATCH v2 7/8] scsi/pmcraid: Remove an unused structure member Bart Van Assche
2017-10-17 6:21 ` Hannes Reinecke
2017-10-17 14:28 ` Bart Van Assche
2017-10-16 22:49 ` [PATCH v2 8/8] scsi/pmcraid: Use sgl_alloc_order() and sgl_free_order() Bart Van Assche
2017-10-17 6:22 ` Hannes Reinecke
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20171016224940.1332-6-bart.vanassche@wdc.com \
--to=bart.vanassche@wdc.com \
--cc=axboe@kernel.dk \
--cc=hare@suse.com \
--cc=hch@lst.de \
--cc=linux-block@vger.kernel.org \
--cc=linux-crypto@vger.kernel.org \
--cc=linux-nvme@lists.infradead.org \
--cc=linux-scsi@vger.kernel.org \
--cc=nab@linux-iscsi.org \
--cc=sagi@grimberg.me \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).