Commit 14db4917 authored by Bart Van Assche's avatar Bart Van Assche Committed by Jens Axboe

target: Use sgl_alloc_order() and sgl_free()

Use the sgl_alloc_order() and sgl_free() functions instead of open
coding these functions.
Signed-off-by: default avatarBart Van Assche <bart.vanassche@wdc.com>
Acked-by: default avatarNicholas A. Bellinger <nab@linux-iscsi.org>
Reviewed-by: default avatarHannes Reinecke <hare@suse.com>
Cc: Christoph Hellwig <hch@lst.de>
Cc: Sagi Grimberg <sagi@grimberg.me>
Signed-off-by: default avatarJens Axboe <axboe@kernel.dk>
parent 68c6e9cd
...@@ -5,6 +5,7 @@ menuconfig TARGET_CORE ...@@ -5,6 +5,7 @@ menuconfig TARGET_CORE
select CONFIGFS_FS select CONFIGFS_FS
select CRC_T10DIF select CRC_T10DIF
select BLK_SCSI_REQUEST # only for scsi_command_size_tbl.. select BLK_SCSI_REQUEST # only for scsi_command_size_tbl..
select SGL_ALLOC
default n default n
help help
Say Y or M here to enable the TCM Storage Engine and ConfigFS enabled Say Y or M here to enable the TCM Storage Engine and ConfigFS enabled
......
...@@ -2300,13 +2300,7 @@ static void target_complete_ok_work(struct work_struct *work) ...@@ -2300,13 +2300,7 @@ static void target_complete_ok_work(struct work_struct *work)
void target_free_sgl(struct scatterlist *sgl, int nents) void target_free_sgl(struct scatterlist *sgl, int nents)
{ {
struct scatterlist *sg; sgl_free(sgl);
int count;
for_each_sg(sgl, sg, nents, count)
__free_page(sg_page(sg));
kfree(sgl);
} }
EXPORT_SYMBOL(target_free_sgl); EXPORT_SYMBOL(target_free_sgl);
...@@ -2414,42 +2408,10 @@ int ...@@ -2414,42 +2408,10 @@ int
target_alloc_sgl(struct scatterlist **sgl, unsigned int *nents, u32 length, target_alloc_sgl(struct scatterlist **sgl, unsigned int *nents, u32 length,
bool zero_page, bool chainable) bool zero_page, bool chainable)
{ {
struct scatterlist *sg; gfp_t gfp = GFP_KERNEL | (zero_page ? __GFP_ZERO : 0);
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;
sg_init_table(sg, nalloc);
while (length) { *sgl = sgl_alloc_order(length, 0, chainable, gfp, nents);
u32 page_len = min_t(u32, length, PAGE_SIZE); return *sgl ? 0 : -ENOMEM;
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;
} }
EXPORT_SYMBOL(target_alloc_sgl); EXPORT_SYMBOL(target_alloc_sgl);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment