qemu-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[PATCH v7 02/11] block/reqlist: add reqlist_new_req() and reqlist_free_r


From: Vladimir Sementsov-Ogievskiy
Subject: [PATCH v7 02/11] block/reqlist: add reqlist_new_req() and reqlist_free_req()
Date: Sat, 4 Sep 2021 19:24:19 +0300

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 --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 */
-- 
2.29.2




reply via email to

[Prev in Thread] Current Thread [Next in Thread]