scatterlist: add sg_nents
authorMaxim Levitsky <maximlevitsky@gmail.com>
Thu, 27 Sep 2012 10:45:28 +0000 (12:45 +0200)
committerJens Axboe <axboe@kernel.dk>
Thu, 27 Sep 2012 10:45:28 +0000 (12:45 +0200)
Useful helper to know the number of entries in scatterlist.

Signed-off-by: Maxim Levitsky <maximlevitsky@gmail.com>
Cc: Alex Dubov <oakad@yahoo.com>
Acked-by: Tejun Heo <tj@kernel.org>
Cc: Jens Axboe <axboe@kernel.dk>
Signed-off-by: Jens Axboe <axboe@kernel.dk>
include/linux/scatterlist.h
lib/scatterlist.c

index 7b600da9a635027393368715a43e0a2a44827db0..4bd6c06eb28edb13cc8a47698fd2b1df94d72f65 100644 (file)
@@ -201,6 +201,7 @@ static inline void *sg_virt(struct scatterlist *sg)
        return page_address(sg_page(sg)) + sg->offset;
 }
 
+int sg_nents(struct scatterlist *sg);
 struct scatterlist *sg_next(struct scatterlist *);
 struct scatterlist *sg_last(struct scatterlist *s, unsigned int);
 void sg_init_table(struct scatterlist *, unsigned int);
index fadae774a20cc6abb0226ee4c3bfbc6cb4cd4eeb..1bf60efb5e02424368d0847af2894f900a3ad5d2 100644 (file)
@@ -38,6 +38,28 @@ struct scatterlist *sg_next(struct scatterlist *sg)
 }
 EXPORT_SYMBOL(sg_next);
 
+/**
+ * sg_nents - return total count of entries in scatterlist
+ * @sg:                The scatterlist
+ *
+ * Description:
+ * Allows to know how many entries are in sg, taking into acount
+ * chaining as well
+ *
+ **/
+int sg_nents(struct scatterlist *sg)
+{
+       int nents = 0;
+       while (sg) {
+               nents++;
+               sg = sg_next(sg);
+       }
+
+       return nents;
+}
+EXPORT_SYMBOL(sg_nents);
+
+
 /**
  * sg_last - return the last scatterlist entry in a list
  * @sgl:       First entry in the scatterlist