blob: b576c7f06829406bd922ce80cb445504e534df12 [file] [log] [blame]
Olga Kornievskaia74678742021-06-08 15:59:10 -04001// SPDX-License-Identifier: GPL-2.0
2/*
3 * Copyright (c) 2020 Anna Schumaker <Anna.Schumaker@Netapp.com>
4 */
Olga Kornievskaiac441f122021-06-08 15:59:11 -04005#include <linux/sunrpc/clnt.h>
Olga Kornievskaia74678742021-06-08 15:59:10 -04006#include <linux/kobject.h>
Olga Kornievskaia587bc722021-06-08 15:59:19 -04007#include <linux/sunrpc/addr.h>
Olga Kornievskaiac1830a62021-06-23 23:28:49 -04008#include <linux/sunrpc/xprtsock.h>
Olga Kornievskaia587bc722021-06-08 15:59:19 -04009
Olga Kornievskaiac5a382e2021-06-08 15:59:12 -040010#include "sysfs.h"
Olga Kornievskaia74678742021-06-08 15:59:10 -040011
Olga Kornievskaia587bc722021-06-08 15:59:19 -040012struct xprt_addr {
13 const char *addr;
14 struct rcu_head rcu;
15};
16
17static void free_xprt_addr(struct rcu_head *head)
18{
19 struct xprt_addr *addr = container_of(head, struct xprt_addr, rcu);
20
21 kfree(addr->addr);
22 kfree(addr);
23}
24
Olga Kornievskaia74678742021-06-08 15:59:10 -040025static struct kset *rpc_sunrpc_kset;
Olga Kornievskaiabaea9942021-06-08 15:59:16 -040026static struct kobject *rpc_sunrpc_client_kobj, *rpc_sunrpc_xprt_switch_kobj;
Olga Kornievskaiac441f122021-06-08 15:59:11 -040027
28static void rpc_sysfs_object_release(struct kobject *kobj)
29{
30 kfree(kobj);
31}
32
33static const struct kobj_ns_type_operations *
34rpc_sysfs_object_child_ns_type(struct kobject *kobj)
35{
36 return &net_ns_type_operations;
37}
38
39static struct kobj_type rpc_sysfs_object_type = {
40 .release = rpc_sysfs_object_release,
41 .sysfs_ops = &kobj_sysfs_ops,
42 .child_ns_type = rpc_sysfs_object_child_ns_type,
43};
44
45static struct kobject *rpc_sysfs_object_alloc(const char *name,
46 struct kset *kset,
47 struct kobject *parent)
48{
49 struct kobject *kobj;
50
51 kobj = kzalloc(sizeof(*kobj), GFP_KERNEL);
52 if (kobj) {
53 kobj->kset = kset;
54 if (kobject_init_and_add(kobj, &rpc_sysfs_object_type,
55 parent, "%s", name) == 0)
56 return kobj;
57 kobject_put(kobj);
58 }
59 return NULL;
60}
Olga Kornievskaia74678742021-06-08 15:59:10 -040061
Olga Kornievskaia587bc722021-06-08 15:59:19 -040062static inline struct rpc_xprt *
63rpc_sysfs_xprt_kobj_get_xprt(struct kobject *kobj)
64{
65 struct rpc_sysfs_xprt *x = container_of(kobj,
66 struct rpc_sysfs_xprt, kobject);
67
68 return xprt_get(x->xprt);
69}
70
Olga Kornievskaia0e559032021-06-08 15:59:21 -040071static inline struct rpc_xprt_switch *
Olga Kornievskaia5b7eb782021-06-23 23:28:50 -040072rpc_sysfs_xprt_kobj_get_xprt_switch(struct kobject *kobj)
73{
74 struct rpc_sysfs_xprt *x = container_of(kobj,
75 struct rpc_sysfs_xprt, kobject);
76
77 return xprt_switch_get(x->xprt_switch);
78}
79
80static inline struct rpc_xprt_switch *
Olga Kornievskaia0e559032021-06-08 15:59:21 -040081rpc_sysfs_xprt_switch_kobj_get_xprt(struct kobject *kobj)
82{
83 struct rpc_sysfs_xprt_switch *x = container_of(kobj,
84 struct rpc_sysfs_xprt_switch, kobject);
85
86 return xprt_switch_get(x->xprt_switch);
87}
88
Olga Kornievskaia587bc722021-06-08 15:59:19 -040089static ssize_t rpc_sysfs_xprt_dstaddr_show(struct kobject *kobj,
90 struct kobj_attribute *attr,
91 char *buf)
92{
93 struct rpc_xprt *xprt = rpc_sysfs_xprt_kobj_get_xprt(kobj);
94 ssize_t ret;
95
96 if (!xprt)
97 return 0;
98 ret = sprintf(buf, "%s\n", xprt->address_strings[RPC_DISPLAY_ADDR]);
99 xprt_put(xprt);
100 return ret + 1;
101}
102
Olga Kornievskaia4a096512021-06-08 15:59:20 -0400103static ssize_t rpc_sysfs_xprt_info_show(struct kobject *kobj,
104 struct kobj_attribute *attr,
105 char *buf)
106{
107 struct rpc_xprt *xprt = rpc_sysfs_xprt_kobj_get_xprt(kobj);
108 ssize_t ret;
109
110 if (!xprt)
111 return 0;
112
113 ret = sprintf(buf, "last_used=%lu\ncur_cong=%lu\ncong_win=%lu\n"
114 "max_num_slots=%u\nmin_num_slots=%u\nnum_reqs=%u\n"
115 "binding_q_len=%u\nsending_q_len=%u\npending_q_len=%u\n"
Olga Kornievskaia6a284052021-06-23 23:28:52 -0400116 "backlog_q_len=%u\nmain_xprt=%d\nsrc_port=%u\n"
117 "tasks_queuelen=%ld\n",
Olga Kornievskaiac1830a62021-06-23 23:28:49 -0400118 xprt->last_used, xprt->cong, xprt->cwnd, xprt->max_reqs,
119 xprt->min_reqs, xprt->num_reqs, xprt->binding.qlen,
120 xprt->sending.qlen, xprt->pending.qlen,
121 xprt->backlog.qlen, xprt->main,
122 (xprt->xprt_class->ident == XPRT_TRANSPORT_TCP) ?
Olga Kornievskaia6a284052021-06-23 23:28:52 -0400123 get_srcport(xprt) : 0,
124 atomic_long_read(&xprt->queuelen));
Olga Kornievskaia4a096512021-06-08 15:59:20 -0400125 xprt_put(xprt);
126 return ret + 1;
127}
128
Olga Kornievskaia681d5692021-06-08 15:59:22 -0400129static ssize_t rpc_sysfs_xprt_state_show(struct kobject *kobj,
130 struct kobj_attribute *attr,
131 char *buf)
132{
133 struct rpc_xprt *xprt = rpc_sysfs_xprt_kobj_get_xprt(kobj);
134 ssize_t ret;
135 int locked, connected, connecting, close_wait, bound, binding,
Olga Kornievskaia5b7eb782021-06-23 23:28:50 -0400136 closing, congested, cwnd_wait, write_space, offline;
Olga Kornievskaia681d5692021-06-08 15:59:22 -0400137
138 if (!xprt)
139 return 0;
140
141 if (!xprt->state) {
142 ret = sprintf(buf, "state=CLOSED\n");
143 } else {
144 locked = test_bit(XPRT_LOCKED, &xprt->state);
145 connected = test_bit(XPRT_CONNECTED, &xprt->state);
146 connecting = test_bit(XPRT_CONNECTING, &xprt->state);
147 close_wait = test_bit(XPRT_CLOSE_WAIT, &xprt->state);
148 bound = test_bit(XPRT_BOUND, &xprt->state);
149 binding = test_bit(XPRT_BINDING, &xprt->state);
150 closing = test_bit(XPRT_CLOSING, &xprt->state);
151 congested = test_bit(XPRT_CONGESTED, &xprt->state);
152 cwnd_wait = test_bit(XPRT_CWND_WAIT, &xprt->state);
153 write_space = test_bit(XPRT_WRITE_SPACE, &xprt->state);
Olga Kornievskaia5b7eb782021-06-23 23:28:50 -0400154 offline = test_bit(XPRT_OFFLINE, &xprt->state);
Olga Kornievskaia681d5692021-06-08 15:59:22 -0400155
Olga Kornievskaia5b7eb782021-06-23 23:28:50 -0400156 ret = sprintf(buf, "state=%s %s %s %s %s %s %s %s %s %s %s\n",
Olga Kornievskaia681d5692021-06-08 15:59:22 -0400157 locked ? "LOCKED" : "",
158 connected ? "CONNECTED" : "",
159 connecting ? "CONNECTING" : "",
160 close_wait ? "CLOSE_WAIT" : "",
161 bound ? "BOUND" : "",
162 binding ? "BOUNDING" : "",
163 closing ? "CLOSING" : "",
164 congested ? "CONGESTED" : "",
165 cwnd_wait ? "CWND_WAIT" : "",
Olga Kornievskaia5b7eb782021-06-23 23:28:50 -0400166 write_space ? "WRITE_SPACE" : "",
167 offline ? "OFFLINE" : "");
Olga Kornievskaia681d5692021-06-08 15:59:22 -0400168 }
169
170 xprt_put(xprt);
171 return ret + 1;
172}
173
Olga Kornievskaia0e559032021-06-08 15:59:21 -0400174static ssize_t rpc_sysfs_xprt_switch_info_show(struct kobject *kobj,
175 struct kobj_attribute *attr,
176 char *buf)
177{
178 struct rpc_xprt_switch *xprt_switch =
179 rpc_sysfs_xprt_switch_kobj_get_xprt(kobj);
180 ssize_t ret;
181
182 if (!xprt_switch)
183 return 0;
184 ret = sprintf(buf, "num_xprts=%u\nnum_active=%u\nqueue_len=%ld\n",
185 xprt_switch->xps_nxprts, xprt_switch->xps_nactive,
186 atomic_long_read(&xprt_switch->xps_queuelen));
187 xprt_switch_put(xprt_switch);
188 return ret + 1;
189}
190
Olga Kornievskaia587bc722021-06-08 15:59:19 -0400191static ssize_t rpc_sysfs_xprt_dstaddr_store(struct kobject *kobj,
192 struct kobj_attribute *attr,
193 const char *buf, size_t count)
194{
195 struct rpc_xprt *xprt = rpc_sysfs_xprt_kobj_get_xprt(kobj);
196 struct sockaddr *saddr;
197 char *dst_addr;
198 int port;
199 struct xprt_addr *saved_addr;
200 size_t buf_len;
201
202 if (!xprt)
203 return 0;
204 if (!(xprt->xprt_class->ident == XPRT_TRANSPORT_TCP ||
205 xprt->xprt_class->ident == XPRT_TRANSPORT_RDMA)) {
206 xprt_put(xprt);
207 return -EOPNOTSUPP;
208 }
209
210 if (wait_on_bit_lock(&xprt->state, XPRT_LOCKED, TASK_KILLABLE)) {
211 count = -EINTR;
212 goto out_put;
213 }
214 saddr = (struct sockaddr *)&xprt->addr;
215 port = rpc_get_port(saddr);
216
217 /* buf_len is the len until the first occurence of either
218 * '\n' or '\0'
219 */
220 buf_len = strcspn(buf, "\n");
221
222 dst_addr = kstrndup(buf, buf_len, GFP_KERNEL);
223 if (!dst_addr)
224 goto out_err;
225 saved_addr = kzalloc(sizeof(*saved_addr), GFP_KERNEL);
226 if (!saved_addr)
227 goto out_err_free;
228 saved_addr->addr =
229 rcu_dereference_raw(xprt->address_strings[RPC_DISPLAY_ADDR]);
230 rcu_assign_pointer(xprt->address_strings[RPC_DISPLAY_ADDR], dst_addr);
231 call_rcu(&saved_addr->rcu, free_xprt_addr);
232 xprt->addrlen = rpc_pton(xprt->xprt_net, buf, buf_len, saddr,
233 sizeof(*saddr));
234 rpc_set_port(saddr, port);
235
236 xprt_force_disconnect(xprt);
237out:
238 xprt_release_write(xprt, NULL);
239out_put:
240 xprt_put(xprt);
241 return count;
242out_err_free:
243 kfree(dst_addr);
244out_err:
245 count = -ENOMEM;
246 goto out;
247}
248
Olga Kornievskaia5b7eb782021-06-23 23:28:50 -0400249static ssize_t rpc_sysfs_xprt_state_change(struct kobject *kobj,
250 struct kobj_attribute *attr,
251 const char *buf, size_t count)
252{
253 struct rpc_xprt *xprt = rpc_sysfs_xprt_kobj_get_xprt(kobj);
254 int offline = 0, online = 0;
255 struct rpc_xprt_switch *xps = rpc_sysfs_xprt_kobj_get_xprt_switch(kobj);
256
257 if (!xprt)
258 return 0;
259
260 if (!strncmp(buf, "offline", 7))
261 offline = 1;
262 else if (!strncmp(buf, "online", 6))
263 online = 1;
264 else
265 return -EINVAL;
266
267 if (wait_on_bit_lock(&xprt->state, XPRT_LOCKED, TASK_KILLABLE)) {
268 count = -EINTR;
269 goto out_put;
270 }
271 if (xprt->main) {
272 count = -EINVAL;
273 goto release_tasks;
274 }
275 if (offline) {
276 set_bit(XPRT_OFFLINE, &xprt->state);
277 spin_lock(&xps->xps_lock);
278 xps->xps_nactive--;
279 spin_unlock(&xps->xps_lock);
280 } else if (online) {
281 clear_bit(XPRT_OFFLINE, &xprt->state);
282 spin_lock(&xps->xps_lock);
283 xps->xps_nactive++;
284 spin_unlock(&xps->xps_lock);
285 }
286
287release_tasks:
288 xprt_release_write(xprt, NULL);
289out_put:
290 xprt_put(xprt);
291 xprt_switch_put(xps);
292 return count;
293}
294
Olga Kornievskaia74678742021-06-08 15:59:10 -0400295int rpc_sysfs_init(void)
296{
297 rpc_sunrpc_kset = kset_create_and_add("sunrpc", NULL, kernel_kobj);
298 if (!rpc_sunrpc_kset)
299 return -ENOMEM;
Olga Kornievskaiabaea9942021-06-08 15:59:16 -0400300 rpc_sunrpc_client_kobj =
301 rpc_sysfs_object_alloc("rpc-clients", rpc_sunrpc_kset, NULL);
302 if (!rpc_sunrpc_client_kobj)
303 goto err_client;
304 rpc_sunrpc_xprt_switch_kobj =
305 rpc_sysfs_object_alloc("xprt-switches", rpc_sunrpc_kset, NULL);
306 if (!rpc_sunrpc_xprt_switch_kobj)
307 goto err_switch;
Olga Kornievskaia74678742021-06-08 15:59:10 -0400308 return 0;
Olga Kornievskaiabaea9942021-06-08 15:59:16 -0400309err_switch:
310 kobject_put(rpc_sunrpc_client_kobj);
311 rpc_sunrpc_client_kobj = NULL;
312err_client:
313 kset_unregister(rpc_sunrpc_kset);
314 rpc_sunrpc_kset = NULL;
315 return -ENOMEM;
Olga Kornievskaia74678742021-06-08 15:59:10 -0400316}
317
Olga Kornievskaiac5a382e2021-06-08 15:59:12 -0400318static void rpc_sysfs_client_release(struct kobject *kobj)
319{
320 struct rpc_sysfs_client *c;
321
322 c = container_of(kobj, struct rpc_sysfs_client, kobject);
323 kfree(c);
324}
325
Olga Kornievskaiabaea9942021-06-08 15:59:16 -0400326static void rpc_sysfs_xprt_switch_release(struct kobject *kobj)
327{
328 struct rpc_sysfs_xprt_switch *xprt_switch;
329
330 xprt_switch = container_of(kobj, struct rpc_sysfs_xprt_switch, kobject);
331 kfree(xprt_switch);
332}
333
Olga Kornievskaiad408ebe2021-06-08 15:59:18 -0400334static void rpc_sysfs_xprt_release(struct kobject *kobj)
335{
336 struct rpc_sysfs_xprt *xprt;
337
338 xprt = container_of(kobj, struct rpc_sysfs_xprt, kobject);
339 kfree(xprt);
340}
341
Olga Kornievskaiac5a382e2021-06-08 15:59:12 -0400342static const void *rpc_sysfs_client_namespace(struct kobject *kobj)
343{
344 return container_of(kobj, struct rpc_sysfs_client, kobject)->net;
345}
346
Olga Kornievskaiabaea9942021-06-08 15:59:16 -0400347static const void *rpc_sysfs_xprt_switch_namespace(struct kobject *kobj)
348{
349 return container_of(kobj, struct rpc_sysfs_xprt_switch, kobject)->net;
350}
351
Olga Kornievskaiad408ebe2021-06-08 15:59:18 -0400352static const void *rpc_sysfs_xprt_namespace(struct kobject *kobj)
353{
354 return container_of(kobj, struct rpc_sysfs_xprt,
355 kobject)->xprt->xprt_net;
356}
357
Olga Kornievskaia587bc722021-06-08 15:59:19 -0400358static struct kobj_attribute rpc_sysfs_xprt_dstaddr = __ATTR(dstaddr,
359 0644, rpc_sysfs_xprt_dstaddr_show, rpc_sysfs_xprt_dstaddr_store);
360
Olga Kornievskaia4a096512021-06-08 15:59:20 -0400361static struct kobj_attribute rpc_sysfs_xprt_info = __ATTR(xprt_info,
362 0444, rpc_sysfs_xprt_info_show, NULL);
363
Olga Kornievskaia681d5692021-06-08 15:59:22 -0400364static struct kobj_attribute rpc_sysfs_xprt_change_state = __ATTR(xprt_state,
Olga Kornievskaia5b7eb782021-06-23 23:28:50 -0400365 0644, rpc_sysfs_xprt_state_show, rpc_sysfs_xprt_state_change);
Olga Kornievskaia681d5692021-06-08 15:59:22 -0400366
Olga Kornievskaia587bc722021-06-08 15:59:19 -0400367static struct attribute *rpc_sysfs_xprt_attrs[] = {
368 &rpc_sysfs_xprt_dstaddr.attr,
Olga Kornievskaia4a096512021-06-08 15:59:20 -0400369 &rpc_sysfs_xprt_info.attr,
Olga Kornievskaia681d5692021-06-08 15:59:22 -0400370 &rpc_sysfs_xprt_change_state.attr,
Olga Kornievskaia587bc722021-06-08 15:59:19 -0400371 NULL,
372};
373
Olga Kornievskaia0e559032021-06-08 15:59:21 -0400374static struct kobj_attribute rpc_sysfs_xprt_switch_info =
375 __ATTR(xprt_switch_info, 0444, rpc_sysfs_xprt_switch_info_show, NULL);
376
377static struct attribute *rpc_sysfs_xprt_switch_attrs[] = {
378 &rpc_sysfs_xprt_switch_info.attr,
379 NULL,
380};
381
Olga Kornievskaiac5a382e2021-06-08 15:59:12 -0400382static struct kobj_type rpc_sysfs_client_type = {
383 .release = rpc_sysfs_client_release,
384 .sysfs_ops = &kobj_sysfs_ops,
385 .namespace = rpc_sysfs_client_namespace,
386};
387
Olga Kornievskaiabaea9942021-06-08 15:59:16 -0400388static struct kobj_type rpc_sysfs_xprt_switch_type = {
389 .release = rpc_sysfs_xprt_switch_release,
Olga Kornievskaia0e559032021-06-08 15:59:21 -0400390 .default_attrs = rpc_sysfs_xprt_switch_attrs,
Olga Kornievskaiabaea9942021-06-08 15:59:16 -0400391 .sysfs_ops = &kobj_sysfs_ops,
392 .namespace = rpc_sysfs_xprt_switch_namespace,
393};
394
Olga Kornievskaiad408ebe2021-06-08 15:59:18 -0400395static struct kobj_type rpc_sysfs_xprt_type = {
396 .release = rpc_sysfs_xprt_release,
Olga Kornievskaia587bc722021-06-08 15:59:19 -0400397 .default_attrs = rpc_sysfs_xprt_attrs,
Olga Kornievskaiad408ebe2021-06-08 15:59:18 -0400398 .sysfs_ops = &kobj_sysfs_ops,
399 .namespace = rpc_sysfs_xprt_namespace,
400};
401
Olga Kornievskaia74678742021-06-08 15:59:10 -0400402void rpc_sysfs_exit(void)
403{
Olga Kornievskaiac441f122021-06-08 15:59:11 -0400404 kobject_put(rpc_sunrpc_client_kobj);
Olga Kornievskaiabaea9942021-06-08 15:59:16 -0400405 kobject_put(rpc_sunrpc_xprt_switch_kobj);
Olga Kornievskaia74678742021-06-08 15:59:10 -0400406 kset_unregister(rpc_sunrpc_kset);
407}
Olga Kornievskaiac5a382e2021-06-08 15:59:12 -0400408
409static struct rpc_sysfs_client *rpc_sysfs_client_alloc(struct kobject *parent,
410 struct net *net,
411 int clid)
412{
413 struct rpc_sysfs_client *p;
414
415 p = kzalloc(sizeof(*p), GFP_KERNEL);
416 if (p) {
417 p->net = net;
418 p->kobject.kset = rpc_sunrpc_kset;
419 if (kobject_init_and_add(&p->kobject, &rpc_sysfs_client_type,
420 parent, "clnt-%d", clid) == 0)
421 return p;
422 kobject_put(&p->kobject);
423 }
424 return NULL;
425}
426
Olga Kornievskaiabaea9942021-06-08 15:59:16 -0400427static struct rpc_sysfs_xprt_switch *
428rpc_sysfs_xprt_switch_alloc(struct kobject *parent,
429 struct rpc_xprt_switch *xprt_switch,
430 struct net *net,
431 gfp_t gfp_flags)
432{
433 struct rpc_sysfs_xprt_switch *p;
434
435 p = kzalloc(sizeof(*p), gfp_flags);
436 if (p) {
437 p->net = net;
438 p->kobject.kset = rpc_sunrpc_kset;
439 if (kobject_init_and_add(&p->kobject,
440 &rpc_sysfs_xprt_switch_type,
441 parent, "switch-%d",
442 xprt_switch->xps_id) == 0)
443 return p;
444 kobject_put(&p->kobject);
445 }
446 return NULL;
447}
448
Olga Kornievskaiad408ebe2021-06-08 15:59:18 -0400449static struct rpc_sysfs_xprt *rpc_sysfs_xprt_alloc(struct kobject *parent,
450 struct rpc_xprt *xprt,
451 gfp_t gfp_flags)
452{
453 struct rpc_sysfs_xprt *p;
454
455 p = kzalloc(sizeof(*p), gfp_flags);
456 if (!p)
457 goto out;
458 p->kobject.kset = rpc_sunrpc_kset;
459 if (kobject_init_and_add(&p->kobject, &rpc_sysfs_xprt_type,
460 parent, "xprt-%d-%s", xprt->id,
461 xprt->address_strings[RPC_DISPLAY_PROTO]) == 0)
462 return p;
463 kobject_put(&p->kobject);
464out:
465 return NULL;
466}
467
Olga Kornievskaia2a338a52021-06-08 15:59:17 -0400468void rpc_sysfs_client_setup(struct rpc_clnt *clnt,
469 struct rpc_xprt_switch *xprt_switch,
470 struct net *net)
Olga Kornievskaiac5a382e2021-06-08 15:59:12 -0400471{
472 struct rpc_sysfs_client *rpc_client;
473
Olga Kornievskaia2a338a52021-06-08 15:59:17 -0400474 rpc_client = rpc_sysfs_client_alloc(rpc_sunrpc_client_kobj,
475 net, clnt->cl_clid);
Olga Kornievskaiac5a382e2021-06-08 15:59:12 -0400476 if (rpc_client) {
Olga Kornievskaia2a338a52021-06-08 15:59:17 -0400477 char name[] = "switch";
478 struct rpc_sysfs_xprt_switch *xswitch =
479 (struct rpc_sysfs_xprt_switch *)xprt_switch->xps_sysfs;
480 int ret;
481
Olga Kornievskaiac5a382e2021-06-08 15:59:12 -0400482 clnt->cl_sysfs = rpc_client;
Olga Kornievskaia2a338a52021-06-08 15:59:17 -0400483 rpc_client->clnt = clnt;
484 rpc_client->xprt_switch = xprt_switch;
Olga Kornievskaiac5a382e2021-06-08 15:59:12 -0400485 kobject_uevent(&rpc_client->kobject, KOBJ_ADD);
Olga Kornievskaia2a338a52021-06-08 15:59:17 -0400486 ret = sysfs_create_link_nowarn(&rpc_client->kobject,
487 &xswitch->kobject, name);
488 if (ret)
489 pr_warn("can't create link to %s in sysfs (%d)\n",
490 name, ret);
Olga Kornievskaiac5a382e2021-06-08 15:59:12 -0400491 }
492}
493
Olga Kornievskaiabaea9942021-06-08 15:59:16 -0400494void rpc_sysfs_xprt_switch_setup(struct rpc_xprt_switch *xprt_switch,
495 struct rpc_xprt *xprt,
496 gfp_t gfp_flags)
497{
498 struct rpc_sysfs_xprt_switch *rpc_xprt_switch;
499 struct net *net;
500
501 if (xprt_switch->xps_net)
502 net = xprt_switch->xps_net;
503 else
504 net = xprt->xprt_net;
505 rpc_xprt_switch =
506 rpc_sysfs_xprt_switch_alloc(rpc_sunrpc_xprt_switch_kobj,
507 xprt_switch, net, gfp_flags);
508 if (rpc_xprt_switch) {
509 xprt_switch->xps_sysfs = rpc_xprt_switch;
510 rpc_xprt_switch->xprt_switch = xprt_switch;
511 rpc_xprt_switch->xprt = xprt;
512 kobject_uevent(&rpc_xprt_switch->kobject, KOBJ_ADD);
513 }
514}
515
Olga Kornievskaiad408ebe2021-06-08 15:59:18 -0400516void rpc_sysfs_xprt_setup(struct rpc_xprt_switch *xprt_switch,
517 struct rpc_xprt *xprt,
518 gfp_t gfp_flags)
519{
520 struct rpc_sysfs_xprt *rpc_xprt;
521 struct rpc_sysfs_xprt_switch *switch_obj =
522 (struct rpc_sysfs_xprt_switch *)xprt_switch->xps_sysfs;
523
524 rpc_xprt = rpc_sysfs_xprt_alloc(&switch_obj->kobject, xprt, gfp_flags);
525 if (rpc_xprt) {
526 xprt->xprt_sysfs = rpc_xprt;
527 rpc_xprt->xprt = xprt;
Olga Kornievskaia5b7eb782021-06-23 23:28:50 -0400528 rpc_xprt->xprt_switch = xprt_switch;
Olga Kornievskaiad408ebe2021-06-08 15:59:18 -0400529 kobject_uevent(&rpc_xprt->kobject, KOBJ_ADD);
530 }
531}
532
Olga Kornievskaiac5a382e2021-06-08 15:59:12 -0400533void rpc_sysfs_client_destroy(struct rpc_clnt *clnt)
534{
535 struct rpc_sysfs_client *rpc_client = clnt->cl_sysfs;
536
537 if (rpc_client) {
Olga Kornievskaia2a338a52021-06-08 15:59:17 -0400538 char name[] = "switch";
539
540 sysfs_remove_link(&rpc_client->kobject, name);
Olga Kornievskaiac5a382e2021-06-08 15:59:12 -0400541 kobject_uevent(&rpc_client->kobject, KOBJ_REMOVE);
542 kobject_del(&rpc_client->kobject);
543 kobject_put(&rpc_client->kobject);
544 clnt->cl_sysfs = NULL;
545 }
546}
Olga Kornievskaiabaea9942021-06-08 15:59:16 -0400547
548void rpc_sysfs_xprt_switch_destroy(struct rpc_xprt_switch *xprt_switch)
549{
550 struct rpc_sysfs_xprt_switch *rpc_xprt_switch = xprt_switch->xps_sysfs;
551
552 if (rpc_xprt_switch) {
553 kobject_uevent(&rpc_xprt_switch->kobject, KOBJ_REMOVE);
554 kobject_del(&rpc_xprt_switch->kobject);
555 kobject_put(&rpc_xprt_switch->kobject);
556 xprt_switch->xps_sysfs = NULL;
557 }
558}
Olga Kornievskaiad408ebe2021-06-08 15:59:18 -0400559
560void rpc_sysfs_xprt_destroy(struct rpc_xprt *xprt)
561{
562 struct rpc_sysfs_xprt *rpc_xprt = xprt->xprt_sysfs;
563
564 if (rpc_xprt) {
565 kobject_uevent(&rpc_xprt->kobject, KOBJ_REMOVE);
566 kobject_del(&rpc_xprt->kobject);
567 kobject_put(&rpc_xprt->kobject);
568 xprt->xprt_sysfs = NULL;
569 }
570}