]> git.proxmox.com Git - mirror_ubuntu-jammy-kernel.git/commitdiff
target: Use sgl_alloc_order() and sgl_free()
authorBart Van Assche <bart.vanassche@wdc.com>
Fri, 5 Jan 2018 16:26:50 +0000 (08:26 -0800)
committerJens Axboe <axboe@kernel.dk>
Sat, 6 Jan 2018 16:18:00 +0000 (09:18 -0700)
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>
Acked-by: Nicholas A. Bellinger <nab@linux-iscsi.org>
Reviewed-by: Hannes Reinecke <hare@suse.com>
Cc: Christoph Hellwig <hch@lst.de>
Cc: Sagi Grimberg <sagi@grimberg.me>
Signed-off-by: Jens Axboe <axboe@kernel.dk>
drivers/target/Kconfig
drivers/target/target_core_transport.c

index e2bc99980f7553e75cd043f8315551520714f80e..4c44d7bed01a6c44b23a7898be558ae75329b191 100644 (file)
@@ -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
index 58caacd54a3b2a650061d558097d1179e1031035..a001ba711ccae8ba6275c749dbca15f3398cff0c 100644 (file)
@@ -2300,13 +2300,7 @@ queue_full:
 
 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);
 
@@ -2414,42 +2408,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);