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