@@ -62,6 +62,8 @@ static __always_inline __must_check int __ns_ref_active_read(const struct ns_com
6262
6363static __always_inline __must_check bool __ns_ref_put (struct ns_common * ns )
6464{
65+ if (is_ns_init_id (ns ))
66+ return false;
6567 if (refcount_dec_and_test (& ns -> __ns_ref )) {
6668 VFS_WARN_ON_ONCE (__ns_ref_active_read (ns ));
6769 return true;
@@ -71,6 +73,8 @@ static __always_inline __must_check bool __ns_ref_put(struct ns_common *ns)
7173
7274static __always_inline __must_check bool __ns_ref_get (struct ns_common * ns )
7375{
76+ if (is_ns_init_id (ns ))
77+ return true;
7478 if (refcount_inc_not_zero (& ns -> __ns_ref ))
7579 return true;
7680 VFS_WARN_ON_ONCE (__ns_ref_active_read (ns ));
@@ -82,12 +86,27 @@ static __always_inline __must_check int __ns_ref_read(const struct ns_common *ns
8286 return refcount_read (& ns -> __ns_ref );
8387}
8488
89+ static __always_inline void __ns_ref_inc (struct ns_common * ns )
90+ {
91+ if (is_ns_init_id (ns ))
92+ return ;
93+ refcount_inc (& ns -> __ns_ref );
94+ }
95+
96+ static __always_inline __must_check bool __ns_ref_dec_and_lock (struct ns_common * ns ,
97+ spinlock_t * ns_lock )
98+ {
99+ if (is_ns_init_id (ns ))
100+ return false;
101+ return refcount_dec_and_lock (& ns -> __ns_ref , ns_lock );
102+ }
103+
85104#define ns_ref_read (__ns ) __ns_ref_read(to_ns_common((__ns)))
86- #define ns_ref_inc (__ns ) refcount_inc(& to_ns_common((__ns))->__ns_ref )
105+ #define ns_ref_inc (__ns ) __ns_ref_inc( to_ns_common((__ns)))
87106#define ns_ref_get (__ns ) __ns_ref_get(to_ns_common((__ns)))
88107#define ns_ref_put (__ns ) __ns_ref_put(to_ns_common((__ns)))
89- #define ns_ref_put_and_lock (__ns , __lock ) \
90- refcount_dec_and_lock(& to_ns_common((__ns))->__ns_ref, (__lock) )
108+ #define ns_ref_put_and_lock (__ns , __ns_lock ) \
109+ __ns_ref_dec_and_lock( to_ns_common((__ns)), __ns_lock )
91110
92111#define ns_ref_active_read (__ns ) \
93112 ((__ns) ? __ns_ref_active_read(to_ns_common(__ns)) : 0)
0 commit comments