@@ -60,10 +60,17 @@ static __always_inline __must_check int __ns_ref_active_read(const struct ns_com
6060 return atomic_read (& ns -> __ns_ref_active );
6161}
6262
63+ static __always_inline __must_check int __ns_ref_read (const struct ns_common * ns )
64+ {
65+ return refcount_read (& ns -> __ns_ref );
66+ }
67+
6368static __always_inline __must_check bool __ns_ref_put (struct ns_common * ns )
6469{
65- if (is_ns_init_id (ns ))
70+ if (is_ns_init_id (ns )) {
71+ VFS_WARN_ON_ONCE (__ns_ref_read (ns ) != 1 );
6672 return false;
73+ }
6774 if (refcount_dec_and_test (& ns -> __ns_ref )) {
6875 VFS_WARN_ON_ONCE (__ns_ref_active_read (ns ));
6976 return true;
@@ -73,31 +80,32 @@ static __always_inline __must_check bool __ns_ref_put(struct ns_common *ns)
7380
7481static __always_inline __must_check bool __ns_ref_get (struct ns_common * ns )
7582{
76- if (is_ns_init_id (ns ))
83+ if (is_ns_init_id (ns )) {
84+ VFS_WARN_ON_ONCE (__ns_ref_read (ns ) != 1 );
7785 return true;
86+ }
7887 if (refcount_inc_not_zero (& ns -> __ns_ref ))
7988 return true;
8089 VFS_WARN_ON_ONCE (__ns_ref_active_read (ns ));
8190 return false;
8291}
8392
84- static __always_inline __must_check int __ns_ref_read (const struct ns_common * ns )
85- {
86- return refcount_read (& ns -> __ns_ref );
87- }
88-
8993static __always_inline void __ns_ref_inc (struct ns_common * ns )
9094{
91- if (is_ns_init_id (ns ))
95+ if (is_ns_init_id (ns )) {
96+ VFS_WARN_ON_ONCE (__ns_ref_read (ns ) != 1 );
9297 return ;
98+ }
9399 refcount_inc (& ns -> __ns_ref );
94100}
95101
96102static __always_inline __must_check bool __ns_ref_dec_and_lock (struct ns_common * ns ,
97103 spinlock_t * ns_lock )
98104{
99- if (is_ns_init_id (ns ))
105+ if (is_ns_init_id (ns )) {
106+ VFS_WARN_ON_ONCE (__ns_ref_read (ns ) != 1 );
100107 return false;
108+ }
101109 return refcount_dec_and_lock (& ns -> __ns_ref , ns_lock );
102110}
103111
0 commit comments