* [PATCH 06/17] target/core: Use sg_alloc_table() instead of open-coding it
@ 2018-09-17 21:35 Bart Van Assche
2018-10-05 7:46 ` Christoph Hellwig
` (3 more replies)
0 siblings, 4 replies; 5+ messages in thread
From: Bart Van Assche @ 2018-09-17 21:35 UTC (permalink / raw)
To: target-devel
The purpose of sg_alloc_table() is to allocate and initialize an
sg-list. Use that function instead of open-coding it.
Signed-off-by: Bart Van Assche <bvanassche@acm.org>
Cc: Nicholas Bellinger <nab@linux-iscsi.org>
Cc: Mike Christie <mchristi@redhat.com>
Cc: Christoph Hellwig <hch@lst.de>
Cc: Hannes Reinecke <hare@suse.de>
---
drivers/target/target_core_sbc.c | 11 +++++------
1 file changed, 5 insertions(+), 6 deletions(-)
diff --git a/drivers/target/target_core_sbc.c b/drivers/target/target_core_sbc.c
index ebac2b49b9c6..689ba6da9a0f 100644
--- a/drivers/target/target_core_sbc.c
+++ b/drivers/target/target_core_sbc.c
@@ -453,7 +453,8 @@ static sense_reason_t compare_and_write_callback(struct se_cmd *cmd, bool succes
int *post_ret)
{
struct se_device *dev = cmd->se_dev;
- struct scatterlist *write_sg = NULL, *sg;
+ struct sg_table write_tbl = { };
+ struct scatterlist *write_sg, *sg;
unsigned char *buf = NULL, *addr;
struct sg_mapping_iter m;
unsigned int offset = 0, len;
@@ -494,14 +495,12 @@ static sense_reason_t compare_and_write_callback(struct se_cmd *cmd, bool succes
goto out;
}
- write_sg = kmalloc_array(cmd->t_data_nents, sizeof(*write_sg),
- GFP_KERNEL);
- if (!write_sg) {
+ if (sg_alloc_table(&write_tbl, cmd->t_data_nents, GFP_KERNEL) < 0) {
pr_err("Unable to allocate compare_and_write sg\n");
ret = TCM_OUT_OF_RESOURCES;
goto out;
}
- sg_init_table(write_sg, cmd->t_data_nents);
+ write_sg = write_tbl.sgl;
/*
* Setup verify and write data payloads from total NumberLBAs.
*/
@@ -597,7 +596,7 @@ static sense_reason_t compare_and_write_callback(struct se_cmd *cmd, bool succes
* sbc_compare_and_write() before the original READ I/O submission.
*/
up(&dev->caw_sem);
- kfree(write_sg);
+ sg_free_table(&write_tbl);
kfree(buf);
return ret;
}
--
2.18.0
^ permalink raw reply related [flat|nested] 5+ messages in thread
* Re: [PATCH 06/17] target/core: Use sg_alloc_table() instead of open-coding it
2018-09-17 21:35 [PATCH 06/17] target/core: Use sg_alloc_table() instead of open-coding it Bart Van Assche
@ 2018-10-05 7:46 ` Christoph Hellwig
2018-10-05 13:52 ` Bart Van Assche
` (2 subsequent siblings)
3 siblings, 0 replies; 5+ messages in thread
From: Christoph Hellwig @ 2018-10-05 7:46 UTC (permalink / raw)
To: target-devel
On Mon, Sep 17, 2018 at 02:35:43PM -0700, Bart Van Assche wrote:
> The purpose of sg_alloc_table() is to allocate and initialize an
> sg-list. Use that function instead of open-coding it.
Hmm. This looks correct, but what is the point if we don't plan
on using chained sg-lists?
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH 06/17] target/core: Use sg_alloc_table() instead of open-coding it
2018-09-17 21:35 [PATCH 06/17] target/core: Use sg_alloc_table() instead of open-coding it Bart Van Assche
2018-10-05 7:46 ` Christoph Hellwig
@ 2018-10-05 13:52 ` Bart Van Assche
2018-10-06 11:53 ` Christoph Hellwig
2018-10-08 16:32 ` Bart Van Assche
3 siblings, 0 replies; 5+ messages in thread
From: Bart Van Assche @ 2018-10-05 13:52 UTC (permalink / raw)
To: target-devel
On 10/5/18 12:46 AM, Christoph Hellwig wrote:
> On Mon, Sep 17, 2018 at 02:35:43PM -0700, Bart Van Assche wrote:
>> The purpose of sg_alloc_table() is to allocate and initialize an
>> sg-list. Use that function instead of open-coding it.
>
> Hmm. This looks correct, but what is the point if we don't plan
> on using chained sg-lists?
This patch makes it easier to replace the SCSI target sg-list allocation
code by (library) code that caches sg-list allocations. I still hope to
find some time to work on this.
Since the rest of this series does not depend on this patch, I can leave
it out if you want.
Bart.
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH 06/17] target/core: Use sg_alloc_table() instead of open-coding it
2018-09-17 21:35 [PATCH 06/17] target/core: Use sg_alloc_table() instead of open-coding it Bart Van Assche
2018-10-05 7:46 ` Christoph Hellwig
2018-10-05 13:52 ` Bart Van Assche
@ 2018-10-06 11:53 ` Christoph Hellwig
2018-10-08 16:32 ` Bart Van Assche
3 siblings, 0 replies; 5+ messages in thread
From: Christoph Hellwig @ 2018-10-06 11:53 UTC (permalink / raw)
To: target-devel
On Fri, Oct 05, 2018 at 06:52:12AM -0700, Bart Van Assche wrote:
> On 10/5/18 12:46 AM, Christoph Hellwig wrote:
>> On Mon, Sep 17, 2018 at 02:35:43PM -0700, Bart Van Assche wrote:
>>> The purpose of sg_alloc_table() is to allocate and initialize an
>>> sg-list. Use that function instead of open-coding it.
>>
>> Hmm. This looks correct, but what is the point if we don't plan
>> on using chained sg-lists?
>
> This patch makes it easier to replace the SCSI target sg-list allocation
> code by (library) code that caches sg-list allocations. I still hope to
> find some time to work on this.
Ok.
> Since the rest of this series does not depend on this patch, I can leave it
> out if you want.
Maybe just update the changelog to explain this better?
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH 06/17] target/core: Use sg_alloc_table() instead of open-coding it
2018-09-17 21:35 [PATCH 06/17] target/core: Use sg_alloc_table() instead of open-coding it Bart Van Assche
` (2 preceding siblings ...)
2018-10-06 11:53 ` Christoph Hellwig
@ 2018-10-08 16:32 ` Bart Van Assche
3 siblings, 0 replies; 5+ messages in thread
From: Bart Van Assche @ 2018-10-08 16:32 UTC (permalink / raw)
To: target-devel
On Sat, 2018-10-06 at 13:53 +-0200, Christoph Hellwig wrote:
+AD4 Maybe just update the changelog to explain this better?
OK, I will do that.
Bart.
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2018-10-08 16:32 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2018-09-17 21:35 [PATCH 06/17] target/core: Use sg_alloc_table() instead of open-coding it Bart Van Assche
2018-10-05 7:46 ` Christoph Hellwig
2018-10-05 13:52 ` Bart Van Assche
2018-10-06 11:53 ` Christoph Hellwig
2018-10-08 16:32 ` Bart Van Assche
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.