[Devel] [PATCH VZ7 2/4] fs/fuse kio: introduce try_cslist_get()

Yuriy Vasilev yuriy.vasilev at virtuozzo.com
Fri Dec 15 18:33:52 MSK 2023


This function allows checking if the cslist has been dropped before
usage.

https://pmc.acronis.work/browse/VSTOR-76384

Signed-off-by: Yuriy Vasilev <yuriy.vasilev at virtuozzo.com>
---
 fs/fuse/kio/pcs/pcs_map.c | 12 ++++++++++++
 1 file changed, 12 insertions(+)

diff --git a/fs/fuse/kio/pcs/pcs_map.c b/fs/fuse/kio/pcs/pcs_map.c
index 8f7dcb311f9f..1ce07b0fd28f 100644
--- a/fs/fuse/kio/pcs/pcs_map.c
+++ b/fs/fuse/kio/pcs/pcs_map.c
@@ -87,6 +87,18 @@ static void cslist_destroy(struct pcs_cs_list * csl)
 	kfree(csl);
 }
 
+/* Return:
+ * - true if refcnt incrementation is successful;
+ * - false if refcnt is equal to 0, it indicates that the cslist has been dropped
+ *   and it is not safe to use it without acquiring the cs->lock
+ */
+static inline bool try_cslist_get(struct pcs_cs_list *csl)
+{
+	TRACE("csl:%p csl->map:%p refcnt:%d\n", csl, csl->map, atomic_read(&csl->refcnt));
+
+	return atomic_inc_not_zero(&csl->refcnt);
+}
+
 static inline void cslist_get(struct pcs_cs_list * csl)
 {
 	TRACE("csl:%p csl->map:%p refcnt:%d\n", csl, csl->map, atomic_read(&csl->refcnt));
-- 
2.34.1



More information about the Devel mailing list