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

Yuriy Vasilev yuriy.vasilev at virtuozzo.com
Wed Nov 29 13:12:54 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.h | 12 ++++++++++++
 1 file changed, 12 insertions(+)

diff --git a/fs/fuse/kio/pcs/pcs_map.h b/fs/fuse/kio/pcs/pcs_map.h
index cadc106d45c1..b8416712fb69 100644
--- a/fs/fuse/kio/pcs/pcs_map.h
+++ b/fs/fuse/kio/pcs/pcs_map.h
@@ -232,6 +232,18 @@ extern unsigned int cs_enable_fanout;
 
 void cslist_destroy(struct pcs_cs_list * 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