1 /**
2  * css_get - obtain a reference on the specified css
3  * @css: target css
4  *
5  * The caller must already have a reference.
6  */
7 CGROUP_REF_FN_ATTRS
css_get(struct cgroup_subsys_state * css)8 void css_get(struct cgroup_subsys_state *css)
9 {
10 	if (!(css->flags & CSS_NO_REF))
11 		percpu_ref_get(&css->refcnt);
12 }
CGROUP_REF_EXPORT(css_get)13 CGROUP_REF_EXPORT(css_get)
14 
15 /**
16  * css_get_many - obtain references on the specified css
17  * @css: target css
18  * @n: number of references to get
19  *
20  * The caller must already have a reference.
21  */
22 CGROUP_REF_FN_ATTRS
23 void css_get_many(struct cgroup_subsys_state *css, unsigned int n)
24 {
25 	if (!(css->flags & CSS_NO_REF))
26 		percpu_ref_get_many(&css->refcnt, n);
27 }
CGROUP_REF_EXPORT(css_get_many)28 CGROUP_REF_EXPORT(css_get_many)
29 
30 /**
31  * css_tryget - try to obtain a reference on the specified css
32  * @css: target css
33  *
34  * Obtain a reference on @css unless it already has reached zero and is
35  * being released.  This function doesn't care whether @css is on or
36  * offline.  The caller naturally needs to ensure that @css is accessible
37  * but doesn't have to be holding a reference on it - IOW, RCU protected
38  * access is good enough for this function.  Returns %true if a reference
39  * count was successfully obtained; %false otherwise.
40  */
41 CGROUP_REF_FN_ATTRS
42 bool css_tryget(struct cgroup_subsys_state *css)
43 {
44 	if (!(css->flags & CSS_NO_REF))
45 		return percpu_ref_tryget(&css->refcnt);
46 	return true;
47 }
CGROUP_REF_EXPORT(css_tryget)48 CGROUP_REF_EXPORT(css_tryget)
49 
50 /**
51  * css_tryget_online - try to obtain a reference on the specified css if online
52  * @css: target css
53  *
54  * Obtain a reference on @css if it's online.  The caller naturally needs
55  * to ensure that @css is accessible but doesn't have to be holding a
56  * reference on it - IOW, RCU protected access is good enough for this
57  * function.  Returns %true if a reference count was successfully obtained;
58  * %false otherwise.
59  */
60 CGROUP_REF_FN_ATTRS
61 bool css_tryget_online(struct cgroup_subsys_state *css)
62 {
63 	if (!(css->flags & CSS_NO_REF))
64 		return percpu_ref_tryget_live(&css->refcnt);
65 	return true;
66 }
CGROUP_REF_EXPORT(css_tryget_online)67 CGROUP_REF_EXPORT(css_tryget_online)
68 
69 /**
70  * css_put - put a css reference
71  * @css: target css
72  *
73  * Put a reference obtained via css_get() and css_tryget_online().
74  */
75 CGROUP_REF_FN_ATTRS
76 void css_put(struct cgroup_subsys_state *css)
77 {
78 	if (!(css->flags & CSS_NO_REF))
79 		percpu_ref_put(&css->refcnt);
80 }
CGROUP_REF_EXPORT(css_put)81 CGROUP_REF_EXPORT(css_put)
82 
83 /**
84  * css_put_many - put css references
85  * @css: target css
86  * @n: number of references to put
87  *
88  * Put references obtained via css_get() and css_tryget_online().
89  */
90 CGROUP_REF_FN_ATTRS
91 void css_put_many(struct cgroup_subsys_state *css, unsigned int n)
92 {
93 	if (!(css->flags & CSS_NO_REF))
94 		percpu_ref_put_many(&css->refcnt, n);
95 }
96 CGROUP_REF_EXPORT(css_put_many)
97