[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PATCH 07/20] graph-lock: implement WITH_GRAPH_RDLOCK_GUARD and GRAPH_RD
From: |
Emanuele Giuseppe Esposito |
Subject: |
[PATCH 07/20] graph-lock: implement WITH_GRAPH_RDLOCK_GUARD and GRAPH_RDLOCK_GUARD macros |
Date: |
Wed, 16 Nov 2022 08:48:37 -0500 |
Similar to the implementation in lockable.h, implement macros to
automatically take and release the rdlock.
Create the empty GraphLockable struct only to use it as a type for
G_DEFINE_AUTOPTR_CLEANUP_FUNC.
Signed-off-by: Emanuele Giuseppe Esposito <eesposit@redhat.com>
---
include/block/graph-lock.h | 35 +++++++++++++++++++++++++++++++++++
1 file changed, 35 insertions(+)
diff --git a/include/block/graph-lock.h b/include/block/graph-lock.h
index 9430707dca..0d886a9ca3 100644
--- a/include/block/graph-lock.h
+++ b/include/block/graph-lock.h
@@ -141,5 +141,40 @@ void assert_bdrv_graph_readable(void);
*/
void assert_bdrv_graph_writable(void);
+typedef struct GraphLockable { } GraphLockable;
+
+/*
+ * In C, compound literals have the lifetime of an automatic variable.
+ * In C++ it would be different, but then C++ wouldn't need QemuLockable
+ * either...
+ */
+#define GML_OBJ_() (&(GraphLockable) { })
+
+static inline GraphLockable *graph_lockable_auto_lock(GraphLockable *x)
+{
+ bdrv_graph_co_rdlock();
+ return x;
+}
+
+static inline void graph_lockable_auto_unlock(GraphLockable *x)
+{
+ bdrv_graph_co_rdunlock();
+}
+
+G_DEFINE_AUTOPTR_CLEANUP_FUNC(GraphLockable, graph_lockable_auto_unlock)
+
+#define WITH_GRAPH_RDLOCK_GUARD_(var) \
+ for (g_autoptr(GraphLockable) var = graph_lockable_auto_lock(GML_OBJ_()); \
+ var; \
+ graph_lockable_auto_unlock(var), var = NULL)
+
+#define WITH_GRAPH_RDLOCK_GUARD() \
+ WITH_GRAPH_RDLOCK_GUARD_(glue(graph_lockable_auto, __COUNTER__))
+
+#define GRAPH_RDLOCK_GUARD(x) \
+ g_autoptr(GraphLockable) \
+ glue(graph_lockable_auto, __COUNTER__) G_GNUC_UNUSED = \
+ graph_lockable_auto_lock(GML_OBJ_())
+
#endif /* GRAPH_LOCK_H */
--
2.31.1
- [PATCH 03/20] async: register/unregister aiocontext in graph lock list, (continued)
- [PATCH 03/20] async: register/unregister aiocontext in graph lock list, Emanuele Giuseppe Esposito, 2022/11/16
- [PATCH 04/20] block.c: wrlock in bdrv_replace_child_noperm, Emanuele Giuseppe Esposito, 2022/11/16
- [PATCH 18/20] block-gen: assert that bdrv_co_common_block_status_above is always called with graph rdlock taken, Emanuele Giuseppe Esposito, 2022/11/16
- [PATCH 09/20] block-backend: introduce new generated_co_wrapper_blk annotation, Emanuele Giuseppe Esposito, 2022/11/16
- [PATCH 17/20] block-gen: assert that bdrv_co_pdiscard is always called with graph rdlock taken, Emanuele Giuseppe Esposito, 2022/11/16
- [PATCH 06/20] block: assert that graph read and writes are performed correctly, Emanuele Giuseppe Esposito, 2022/11/16
- [PATCH 08/20] block-coroutine-wrapper.py: take the graph rdlock in bdrv_* functions, Emanuele Giuseppe Esposito, 2022/11/16
- [PATCH 16/20] block-gen: assert that bdrv_co_{read/write}v_vmstate are always called with graph rdlock taken, Emanuele Giuseppe Esposito, 2022/11/16
- [PATCH 20/20] block-gen: assert that nbd_co_do_establish_connection is always called with graph rdlock taken, Emanuele Giuseppe Esposito, 2022/11/16
- [PATCH 14/20] block-gen: assert that bdrv_co_pread is always called with graph rdlock taken, Emanuele Giuseppe Esposito, 2022/11/16
- [PATCH 07/20] graph-lock: implement WITH_GRAPH_RDLOCK_GUARD and GRAPH_RDLOCK_GUARD macros,
Emanuele Giuseppe Esposito <=
- Re: [PATCH 00/20] Protect the block layer with a rwlock: part 1, Emanuele Giuseppe Esposito, 2022/11/21