[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [PATCH 07/18] iov: add iov_discard_front/back() to remove d
From: |
Stefan Hajnoczi |
Subject: |
[Qemu-devel] [PATCH 07/18] iov: add iov_discard_front/back() to remove data |
Date: |
Wed, 2 Jan 2013 16:15:45 +0100 |
The iov_discard_front/back() functions remove data from the front or
back of the vector. This is useful when peeling off header/footer
structs.
Signed-off-by: Stefan Hajnoczi <address@hidden>
---
include/qemu/iov.h | 13 +++++++++++++
iov.c | 51 +++++++++++++++++++++++++++++++++++++++++++++++++++
2 files changed, 64 insertions(+)
diff --git a/include/qemu/iov.h b/include/qemu/iov.h
index d06f8b9..68d25f2 100644
--- a/include/qemu/iov.h
+++ b/include/qemu/iov.h
@@ -99,4 +99,17 @@ unsigned iov_copy(struct iovec *dst_iov, unsigned int
dst_iov_cnt,
const struct iovec *iov, unsigned int iov_cnt,
size_t offset, size_t bytes);
+/*
+ * Remove a given number of bytes from the front or back of a vector.
+ * This may update iov and/or iov_cnt to exclude iovec elements that are
+ * no longer required.
+ *
+ * The number of bytes actually discarded is returned. This number may be
+ * smaller than requested if the vector is too small.
+ */
+size_t iov_discard_front(struct iovec **iov, unsigned int *iov_cnt,
+ size_t bytes);
+size_t iov_discard_back(struct iovec *iov, unsigned int *iov_cnt,
+ size_t bytes);
+
#endif
diff --git a/iov.c b/iov.c
index 419e419..92ad77b 100644
--- a/iov.c
+++ b/iov.c
@@ -354,3 +354,54 @@ size_t qemu_iovec_memset(QEMUIOVector *qiov, size_t offset,
{
return iov_memset(qiov->iov, qiov->niov, offset, fillc, bytes);
}
+
+size_t iov_discard_front(struct iovec **iov, unsigned int *iov_cnt,
+ size_t bytes)
+{
+ size_t total = 0;
+ struct iovec *cur;
+
+ for (cur = *iov; *iov_cnt > 0; cur++) {
+ if (cur->iov_len > bytes) {
+ cur->iov_base += bytes;
+ cur->iov_len -= bytes;
+ total += bytes;
+ break;
+ }
+
+ bytes -= cur->iov_len;
+ total += cur->iov_len;
+ *iov_cnt -= 1;
+ }
+
+ *iov = cur;
+ return total;
+}
+
+size_t iov_discard_back(struct iovec *iov, unsigned int *iov_cnt,
+ size_t bytes)
+{
+ size_t total = 0;
+ struct iovec *cur;
+
+ if (*iov_cnt == 0) {
+ return 0;
+ }
+
+ cur = iov + (*iov_cnt - 1);
+
+ while (*iov_cnt > 0) {
+ if (cur->iov_len > bytes) {
+ cur->iov_len -= bytes;
+ total += bytes;
+ break;
+ }
+
+ bytes -= cur->iov_len;
+ total += cur->iov_len;
+ cur--;
+ *iov_cnt -= 1;
+ }
+
+ return total;
+}
--
1.8.0.2
- [Qemu-devel] [PULL v2 00/18] Block patches, Stefan Hajnoczi, 2013/01/02
- [Qemu-devel] [PATCH 02/18] configure: add CONFIG_VIRTIO_BLK_DATA_PLANE, Stefan Hajnoczi, 2013/01/02
- [Qemu-devel] [PATCH 01/18] raw-posix: add raw_get_aio_fd() for virtio-blk-data-plane, Stefan Hajnoczi, 2013/01/02
- [Qemu-devel] [PATCH 03/18] dataplane: add host memory mapping code, Stefan Hajnoczi, 2013/01/02
- [Qemu-devel] [PATCH 04/18] dataplane: add virtqueue vring code, Stefan Hajnoczi, 2013/01/02
- [Qemu-devel] [PATCH 06/18] dataplane: add Linux AIO request queue, Stefan Hajnoczi, 2013/01/02
- [Qemu-devel] [PATCH 08/18] test-iov: add iov_discard_front/back() testcases, Stefan Hajnoczi, 2013/01/02
- [Qemu-devel] [PATCH 07/18] iov: add iov_discard_front/back() to remove data,
Stefan Hajnoczi <=
- [Qemu-devel] [PATCH 05/18] dataplane: add event loop, Stefan Hajnoczi, 2013/01/02
- [Qemu-devel] [PATCH 10/18] virtio-blk: restore VirtIOBlkConf->config_wce flag, Stefan Hajnoczi, 2013/01/02
- [Qemu-devel] [PATCH 09/18] iov: add qemu_iovec_concat_iov(), Stefan Hajnoczi, 2013/01/02
- [Qemu-devel] [PATCH 12/18] virtio-blk: add x-data-plane=on|off performance feature, Stefan Hajnoczi, 2013/01/02
- [Qemu-devel] [PATCH 11/18] dataplane: add virtio-blk data plane code, Stefan Hajnoczi, 2013/01/02
- [Qemu-devel] [PATCH 15/18] qemu-img: report size overflow error message, Stefan Hajnoczi, 2013/01/02
- [Qemu-devel] [PATCH 13/18] virtio-blk: Return UNSUPP for unknown request types, Stefan Hajnoczi, 2013/01/02
- [Qemu-devel] [PATCH 18/18] sheepdog: pass oid directly to send_pending_req(), Stefan Hajnoczi, 2013/01/02
- [Qemu-devel] [PATCH 16/18] block/raw-win32: Fix compiler warnings (wrong format specifiers), Stefan Hajnoczi, 2013/01/02
- [Qemu-devel] [PATCH 14/18] cutils: change strtosz_suffix_unit function, Stefan Hajnoczi, 2013/01/02