aboutsummaryrefslogtreecommitdiff
path: root/include
diff options
context:
space:
mode:
authorStefan Hajnoczi <stefanha@redhat.com>2020-09-17 10:44:53 +0100
committerStefan Hajnoczi <stefanha@redhat.com>2020-09-23 13:41:58 +0100
commit9dd6f7c28eaa7d001a526d51c74bbf89d5402b8c (patch)
tree5ce0c2924bf4607bbdbc892eb806b37971c52dff /include
parentbd0bbb9aba2afbc2ea24b0475be04f795468b381 (diff)
downloadqemu-9dd6f7c28eaa7d001a526d51c74bbf89d5402b8c.zip
qemu-9dd6f7c28eaa7d001a526d51c74bbf89d5402b8c.tar.gz
qemu-9dd6f7c28eaa7d001a526d51c74bbf89d5402b8c.tar.bz2
util/iov: add iov_discard_undo()
The iov_discard_front/back() operations are useful for parsing iovecs but they modify the array elements. If the original array is needed after parsing finishes there is currently no way to restore it. Although g_memdup() can be used before performing destructive iov_discard_front/back() operations, this is inefficient. Introduce iov_discard_undo() to restore the array to the state prior to an iov_discard_front/back() operation. Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com> Reviewed-by: Li Qiang <liq3ea@gmail.com> Message-Id: <20200917094455.822379-2-stefanha@redhat.com>
Diffstat (limited to 'include')
-rw-r--r--include/qemu/iov.h23
1 files changed, 23 insertions, 0 deletions
diff --git a/include/qemu/iov.h b/include/qemu/iov.h
index bffc151..b6b283a 100644
--- a/include/qemu/iov.h
+++ b/include/qemu/iov.h
@@ -130,6 +130,29 @@ size_t iov_discard_front(struct iovec **iov, unsigned int *iov_cnt,
size_t iov_discard_back(struct iovec *iov, unsigned int *iov_cnt,
size_t bytes);
+/* Information needed to undo an iov_discard_*() operation */
+typedef struct {
+ struct iovec *modified_iov;
+ struct iovec orig;
+} IOVDiscardUndo;
+
+/*
+ * Undo an iov_discard_front_undoable() or iov_discard_back_undoable()
+ * operation. If multiple operations are made then each one needs a separate
+ * IOVDiscardUndo and iov_discard_undo() must be called in the reverse order
+ * that the operations were made.
+ */
+void iov_discard_undo(IOVDiscardUndo *undo);
+
+/*
+ * Undoable versions of iov_discard_front() and iov_discard_back(). Use
+ * iov_discard_undo() to reset to the state before the discard operations.
+ */
+size_t iov_discard_front_undoable(struct iovec **iov, unsigned int *iov_cnt,
+ size_t bytes, IOVDiscardUndo *undo);
+size_t iov_discard_back_undoable(struct iovec *iov, unsigned int *iov_cnt,
+ size_t bytes, IOVDiscardUndo *undo);
+
typedef struct QEMUIOVector {
struct iovec *iov;
int niov;