summaryrefslogtreecommitdiff
path: root/lib/scatterlist.c
diff options
context:
space:
mode:
authorJohannes Thumshirn <jthumshirn@suse.de>2017-06-07 11:45:28 +0200
committerChristoph Hellwig <hch@lst.de>2017-06-15 14:30:14 +0200
commit0945e56994ac855d01c4aecf69bded65c751b894 (patch)
tree4eb91a5f067aa28a6cbb0056e56d7a5e0f9ed351 /lib/scatterlist.c
parentd19d4c8eb1c08f5292a5a5619098e498166055c2 (diff)
downloadlwn-0945e56994ac855d01c4aecf69bded65c751b894.tar.gz
lwn-0945e56994ac855d01c4aecf69bded65c751b894.zip
scatterlist: add sg_zero_buffer() helper
The sg_zero_buffer() helper is used to zero fill an area in a SG list. Signed-off-by: Johannes Thumshirn <jthumshirn@suse.de> Reviewed-by: Sagi Grimberg <sagi@grimberg.me> [hch: renamed to sg_zero_buffer] Signed-off-by: Christoph Hellwig <hch@lst.de>
Diffstat (limited to 'lib/scatterlist.c')
-rw-r--r--lib/scatterlist.c35
1 files changed, 35 insertions, 0 deletions
diff --git a/lib/scatterlist.c b/lib/scatterlist.c
index c6cf82242d65..be7b4dd6b68d 100644
--- a/lib/scatterlist.c
+++ b/lib/scatterlist.c
@@ -751,3 +751,38 @@ 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_zero_buffer - 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_zero_buffer(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_zero_buffer);