vringh: add vringh_kiov_length() helper
authorStefano Garzarella <sgarzare@redhat.com>
Mon, 15 Mar 2021 16:34:42 +0000 (17:34 +0100)
committerMichael S. Tsirkin <mst@redhat.com>
Mon, 3 May 2021 08:55:53 +0000 (04:55 -0400)
This new helper returns the total number of bytes covered by
a vringh_kiov.

Suggested-by: Jason Wang <jasowang@redhat.com>
Acked-by: Jason Wang <jasowang@redhat.com>
Signed-off-by: Stefano Garzarella <sgarzare@redhat.com>
Link: https://lore.kernel.org/r/20210315163450.254396-7-sgarzare@redhat.com
Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
include/linux/vringh.h

index 755211e..84db7b8 100644 (file)
@@ -199,6 +199,17 @@ static inline void vringh_kiov_cleanup(struct vringh_kiov *kiov)
        kiov->iov = NULL;
 }
 
+static inline size_t vringh_kiov_length(struct vringh_kiov *kiov)
+{
+       size_t len = 0;
+       int i;
+
+       for (i = kiov->i; i < kiov->used; i++)
+               len += kiov->iov[i].iov_len;
+
+       return len;
+}
+
 void vringh_kiov_advance(struct vringh_kiov *kiov, size_t len);
 
 int vringh_getdesc_kern(struct vringh *vrh,