Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > linux.kernel > #1659611 > unrolled thread

[PATCH v6 01/10] scatterlist: add sg_zeroout_area() helper

Started byJohannes Thumshirn <jthumshirn@suse.de>
First post2017-06-07 11:50 +0200
Last post2017-06-08 09:50 +0200
Articles 4 — 3 participants

Back to article view | Back to linux.kernel

This discussion starts older than the indexed window; earlier articles aren't shown. The article labeled Started by below is the oldest one visible, not the original post.


Contents

  [PATCH v6 01/10] scatterlist: add sg_zeroout_area() helper Johannes Thumshirn <jthumshirn@suse.de> - 2017-06-07 11:50 +0200
    Re: [PATCH v6 01/10] scatterlist: add sg_zeroout_area() helper Sagi Grimberg <sagi@grimberg.me> - 2017-06-07 12:00 +0200
    Re: [PATCH v6 01/10] scatterlist: add sg_zeroout_area() helper Christoph Hellwig <hch@lst.de> - 2017-06-08 09:50 +0200
      Re: [PATCH v6 01/10] scatterlist: add sg_zeroout_area() helper Johannes Thumshirn <jthumshirn@suse.de> - 2017-06-08 09:50 +0200

#1659611 — [PATCH v6 01/10] scatterlist: add sg_zeroout_area() helper

FromJohannes Thumshirn <jthumshirn@suse.de>
Date2017-06-07 11:50 +0200
Subject[PATCH v6 01/10] scatterlist: add sg_zeroout_area() helper
Message-ID<tPFLb-4SX-13@gated-at.bofh.it>
The sg_zeroout_area() helper is used to zero fill an area in a SG
list.

Signed-off-by: Johannes Thumshirn <jthumshirn@suse.de>
---
 include/linux/scatterlist.h |  3 +++
 lib/scatterlist.c           | 37 +++++++++++++++++++++++++++++++++++++
 2 files changed, 40 insertions(+)

diff --git a/include/linux/scatterlist.h b/include/linux/scatterlist.h
index cb3c8fe6acd7..a38ce9f4e78a 100644
--- a/include/linux/scatterlist.h
+++ b/include/linux/scatterlist.h
@@ -279,6 +279,9 @@ size_t sg_pcopy_from_buffer(struct scatterlist *sgl, unsigned int nents,
 size_t sg_pcopy_to_buffer(struct scatterlist *sgl, unsigned int nents,
 			  void *buf, size_t buflen, off_t skip);
 
+size_t sg_zeroout_area(struct scatterlist *sgl, unsigned int nents,
+		       size_t buflen, off_t skip);
+
 /*
  * Maximum number of entries that will be allocated in one piece, if
  * a list larger than this is required then chaining will be utilized.
diff --git a/lib/scatterlist.c b/lib/scatterlist.c
index c6cf82242d65..584f50c94fce 100644
--- a/lib/scatterlist.c
+++ b/lib/scatterlist.c
@@ -751,3 +751,40 @@ size_t sg_pcopy_to_buffer(struct scatterlist *sgl, unsigned int nents,
 	return sg_copy_buffer(sgl, nents, buf, buflen, skip, true);
 }
 EXPORT_SYMBOL(sg_pcopy_to_buffer);
+
+/**
+ * sg_zeroout_area - Zero-out a part of a SG list
+ * @sgl:		 The SG list
+ * @nents:		 Number of SG entries
+ * @buflen:		 The number of bytes to zero out
+ * @skip:		 Number of bytes to skip before zeroing
+ *
+ * Returns the number of bytes zeroed.
+ *
+ **/
+size_t sg_zeroout_area(struct scatterlist *sgl, unsigned int nents,
+		       size_t buflen, off_t skip)
+{
+	unsigned int offset = 0;
+	struct sg_mapping_iter miter;
+	unsigned int sg_flags = SG_MITER_ATOMIC | SG_MITER_TO_SG;
+
+	sg_miter_start(&miter, sgl, nents, sg_flags);
+
+	if (!sg_miter_skip(&miter, skip))
+		return false;
+
+	while ((offset < buflen) && sg_miter_next(&miter)) {
+		unsigned int len;
+
+		len = min(miter.length, buflen - offset);
+		memset(miter.addr, 0, len);
+
+		offset += len;
+	}
+
+	sg_miter_stop(&miter);
+
+	return offset;
+}
+EXPORT_SYMBOL(sg_zeroout_area);
-- 
2.12.3

[toc] | [next] | [standalone]


#1659636

FromSagi Grimberg <sagi@grimberg.me>
Date2017-06-07 12:00 +0200
Message-ID<tPFUS-4WH-29@gated-at.bofh.it>
In reply to#1659611
Reviewed-by: Sagi Grimberg <sagi@grimberg.me>

[toc] | [prev] | [next] | [standalone]


#1660877

FromChristoph Hellwig <hch@lst.de>
Date2017-06-08 09:50 +0200
Message-ID<tQ0mD-1kN-47@gated-at.bofh.it>
In reply to#1659611
>  size_t sg_pcopy_to_buffer(struct scatterlist *sgl, unsigned int nents,
>  			  void *buf, size_t buflen, off_t skip);
>  
> +size_t sg_zeroout_area(struct scatterlist *sgl, unsigned int nents,
> +		       size_t buflen, off_t skip);

Maybe sg_zero_buffer to fit with the other functions in the family?

(I'd be happy to fix this up if you're ok and we don't need another
respin otherwise).

> +	while ((offset < buflen) && sg_miter_next(&miter)) {

Nit: no need for the inner braces.

Otherwise looks good:

Reviewed-by: Christoph Hellwig <hch@lst.de>

[toc] | [prev] | [next] | [standalone]


#1660879

FromJohannes Thumshirn <jthumshirn@suse.de>
Date2017-06-08 09:50 +0200
Message-ID<tQ0mD-1kN-53@gated-at.bofh.it>
In reply to#1660877
On 06/08/2017 09:41 AM, Christoph Hellwig wrote:
>>  size_t sg_pcopy_to_buffer(struct scatterlist *sgl, unsigned int nents,
>>  			  void *buf, size_t buflen, off_t skip);
>>  
>> +size_t sg_zeroout_area(struct scatterlist *sgl, unsigned int nents,
>> +		       size_t buflen, off_t skip);
> 
> Maybe sg_zero_buffer to fit with the other functions in the family?
> 
> (I'd be happy to fix this up if you're ok and we don't need another
> respin otherwise).

Sounds good.

-- 
Johannes Thumshirn                                          Storage
jthumshirn@suse.de                                +49 911 74053 689
SUSE LINUX GmbH, Maxfeldstr. 5, 90409 Nürnberg
GF: Felix Imendörffer, Jane Smithard, Graham Norton
HRB 21284 (AG Nürnberg)
Key fingerprint = EC38 9CAB C2C4 F25D 8600 D0D0 0393 969D 2D76 0850

[toc] | [prev] | [standalone]


Back to top | Article view | linux.kernel


csiph-web