diff mbox series

[v7,02/11] block/reqlist: add reqlist_new_req() and reqlist_free_req()

Message ID 20210904162428.222008-3-vsementsov@virtuozzo.com (mailing list archive)
State New, archived
Headers show
Series qcow2: fix parallel rewrite and discard (reqlist) | expand

Commit Message

Vladimir Sementsov-Ogievskiy Sept. 4, 2021, 4:24 p.m. UTC
Add convenient helpers for heap allocation of requests.

Signed-off-by: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com>
---
 include/block/reqlist.h | 20 ++++++++++++++++++++
 1 file changed, 20 insertions(+)
diff mbox series

Patch

diff --git a/include/block/reqlist.h b/include/block/reqlist.h
index b904d80216..32dc87666f 100644
--- a/include/block/reqlist.h
+++ b/include/block/reqlist.h
@@ -64,4 +64,24 @@  void coroutine_fn reqlist_shrink_req(BlockReq *req, int64_t new_bytes);
  */
 void coroutine_fn reqlist_remove_req(BlockReq *req);
 
+/* Allocate, initialize and add to the list new request. */
+static inline BlockReq *reqlist_new_req(BlockReqList *reqs, uint64_t offset,
+                                        uint64_t bytes)
+{
+    BlockReq *req = g_new(BlockReq, 1);
+
+    reqlist_init_req(reqs, req, offset, bytes);
+
+    return req;
+}
+
+/* Remove request and g_free it. */
+static inline void reqlist_free_req(BlockReq *req)
+{
+    if (req) {
+        reqlist_remove_req(req);
+        g_free(req);
+    }
+}
+
 #endif /* REQLIST_H */