xref: /openbmc/linux/net/sunrpc/sysfs.c (revision 6e63153d)
1 // SPDX-License-Identifier: GPL-2.0
2 /*
3  * Copyright (c) 2020 Anna Schumaker <Anna.Schumaker@Netapp.com>
4  */
5 #include <linux/sunrpc/clnt.h>
6 #include <linux/kobject.h>
7 #include <linux/sunrpc/addr.h>
8 #include <linux/sunrpc/xprtsock.h>
9 
10 #include "sysfs.h"
11 
12 struct xprt_addr {
13 	const char *addr;
14 	struct rcu_head rcu;
15 };
16 
17 static 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 
25 static struct kset *rpc_sunrpc_kset;
26 static struct kobject *rpc_sunrpc_client_kobj, *rpc_sunrpc_xprt_switch_kobj;
27 
28 static void rpc_sysfs_object_release(struct kobject *kobj)
29 {
30 	kfree(kobj);
31 }
32 
33 static const struct kobj_ns_type_operations *
34 rpc_sysfs_object_child_ns_type(struct kobject *kobj)
35 {
36 	return &net_ns_type_operations;
37 }
38 
39 static 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 
45 static 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 }
61 
62 static inline struct rpc_xprt *
63 rpc_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 
71 static inline struct rpc_xprt_switch *
72 rpc_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 
80 static inline struct rpc_xprt_switch *
81 rpc_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 
89 static 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 		ret = sprintf(buf, "<closed>\n");
98 		goto out;
99 	}
100 	ret = sprintf(buf, "%s\n", xprt->address_strings[RPC_DISPLAY_ADDR]);
101 	xprt_put(xprt);
102 out:
103 	return ret;
104 }
105 
106 static ssize_t rpc_sysfs_xprt_srcaddr_show(struct kobject *kobj,
107 					   struct kobj_attribute *attr,
108 					   char *buf)
109 {
110 	struct rpc_xprt *xprt = rpc_sysfs_xprt_kobj_get_xprt(kobj);
111 	size_t buflen = PAGE_SIZE;
112 	ssize_t ret;
113 
114 	if (!xprt || !xprt_connected(xprt)) {
115 		ret = sprintf(buf, "<closed>\n");
116 	} else if (xprt->ops->get_srcaddr) {
117 		ret = xprt->ops->get_srcaddr(xprt, buf, buflen);
118 		if (ret > 0) {
119 			if (ret < buflen - 1) {
120 				buf[ret] = '\n';
121 				ret++;
122 				buf[ret] = '\0';
123 			}
124 		} else
125 			ret = sprintf(buf, "<closed>\n");
126 	} else
127 		ret = sprintf(buf, "<not a socket>\n");
128 	xprt_put(xprt);
129 	return ret;
130 }
131 
132 static ssize_t rpc_sysfs_xprt_info_show(struct kobject *kobj,
133 					struct kobj_attribute *attr, char *buf)
134 {
135 	struct rpc_xprt *xprt = rpc_sysfs_xprt_kobj_get_xprt(kobj);
136 	unsigned short srcport = 0;
137 	size_t buflen = PAGE_SIZE;
138 	ssize_t ret;
139 
140 	if (!xprt || !xprt_connected(xprt)) {
141 		ret = sprintf(buf, "<closed>\n");
142 		goto out;
143 	}
144 
145 	if (xprt->ops->get_srcport)
146 		srcport = xprt->ops->get_srcport(xprt);
147 
148 	ret = snprintf(buf, buflen,
149 		       "last_used=%lu\ncur_cong=%lu\ncong_win=%lu\n"
150 		       "max_num_slots=%u\nmin_num_slots=%u\nnum_reqs=%u\n"
151 		       "binding_q_len=%u\nsending_q_len=%u\npending_q_len=%u\n"
152 		       "backlog_q_len=%u\nmain_xprt=%d\nsrc_port=%u\n"
153 		       "tasks_queuelen=%ld\ndst_port=%s\n",
154 		       xprt->last_used, xprt->cong, xprt->cwnd, xprt->max_reqs,
155 		       xprt->min_reqs, xprt->num_reqs, xprt->binding.qlen,
156 		       xprt->sending.qlen, xprt->pending.qlen,
157 		       xprt->backlog.qlen, xprt->main, srcport,
158 		       atomic_long_read(&xprt->queuelen),
159 		       xprt->address_strings[RPC_DISPLAY_PORT]);
160 out:
161 	xprt_put(xprt);
162 	return ret;
163 }
164 
165 static ssize_t rpc_sysfs_xprt_state_show(struct kobject *kobj,
166 					 struct kobj_attribute *attr,
167 					 char *buf)
168 {
169 	struct rpc_xprt *xprt = rpc_sysfs_xprt_kobj_get_xprt(kobj);
170 	ssize_t ret;
171 	int locked, connected, connecting, close_wait, bound, binding,
172 	    closing, congested, cwnd_wait, write_space, offline, remove;
173 
174 	if (!(xprt && xprt->state)) {
175 		ret = sprintf(buf, "state=CLOSED\n");
176 	} else {
177 		locked = test_bit(XPRT_LOCKED, &xprt->state);
178 		connected = test_bit(XPRT_CONNECTED, &xprt->state);
179 		connecting = test_bit(XPRT_CONNECTING, &xprt->state);
180 		close_wait = test_bit(XPRT_CLOSE_WAIT, &xprt->state);
181 		bound = test_bit(XPRT_BOUND, &xprt->state);
182 		binding = test_bit(XPRT_BINDING, &xprt->state);
183 		closing = test_bit(XPRT_CLOSING, &xprt->state);
184 		congested = test_bit(XPRT_CONGESTED, &xprt->state);
185 		cwnd_wait = test_bit(XPRT_CWND_WAIT, &xprt->state);
186 		write_space = test_bit(XPRT_WRITE_SPACE, &xprt->state);
187 		offline = test_bit(XPRT_OFFLINE, &xprt->state);
188 		remove = test_bit(XPRT_REMOVE, &xprt->state);
189 
190 		ret = sprintf(buf, "state=%s %s %s %s %s %s %s %s %s %s %s %s\n",
191 			      locked ? "LOCKED" : "",
192 			      connected ? "CONNECTED" : "",
193 			      connecting ? "CONNECTING" : "",
194 			      close_wait ? "CLOSE_WAIT" : "",
195 			      bound ? "BOUND" : "",
196 			      binding ? "BOUNDING" : "",
197 			      closing ? "CLOSING" : "",
198 			      congested ? "CONGESTED" : "",
199 			      cwnd_wait ? "CWND_WAIT" : "",
200 			      write_space ? "WRITE_SPACE" : "",
201 			      offline ? "OFFLINE" : "",
202 			      remove ? "REMOVE" : "");
203 	}
204 
205 	xprt_put(xprt);
206 	return ret;
207 }
208 
209 static ssize_t rpc_sysfs_xprt_switch_info_show(struct kobject *kobj,
210 					       struct kobj_attribute *attr,
211 					       char *buf)
212 {
213 	struct rpc_xprt_switch *xprt_switch =
214 		rpc_sysfs_xprt_switch_kobj_get_xprt(kobj);
215 	ssize_t ret;
216 
217 	if (!xprt_switch)
218 		return 0;
219 	ret = sprintf(buf, "num_xprts=%u\nnum_active=%u\n"
220 		      "num_unique_destaddr=%u\nqueue_len=%ld\n",
221 		      xprt_switch->xps_nxprts, xprt_switch->xps_nactive,
222 		      xprt_switch->xps_nunique_destaddr_xprts,
223 		      atomic_long_read(&xprt_switch->xps_queuelen));
224 	xprt_switch_put(xprt_switch);
225 	return ret;
226 }
227 
228 static ssize_t rpc_sysfs_xprt_dstaddr_store(struct kobject *kobj,
229 					    struct kobj_attribute *attr,
230 					    const char *buf, size_t count)
231 {
232 	struct rpc_xprt *xprt = rpc_sysfs_xprt_kobj_get_xprt(kobj);
233 	struct sockaddr *saddr;
234 	char *dst_addr;
235 	int port;
236 	struct xprt_addr *saved_addr;
237 	size_t buf_len;
238 
239 	if (!xprt)
240 		return 0;
241 	if (!(xprt->xprt_class->ident == XPRT_TRANSPORT_TCP ||
242 	      xprt->xprt_class->ident == XPRT_TRANSPORT_RDMA)) {
243 		xprt_put(xprt);
244 		return -EOPNOTSUPP;
245 	}
246 
247 	if (wait_on_bit_lock(&xprt->state, XPRT_LOCKED, TASK_KILLABLE)) {
248 		count = -EINTR;
249 		goto out_put;
250 	}
251 	saddr = (struct sockaddr *)&xprt->addr;
252 	port = rpc_get_port(saddr);
253 
254 	/* buf_len is the len until the first occurence of either
255 	 * '\n' or '\0'
256 	 */
257 	buf_len = strcspn(buf, "\n");
258 
259 	dst_addr = kstrndup(buf, buf_len, GFP_KERNEL);
260 	if (!dst_addr)
261 		goto out_err;
262 	saved_addr = kzalloc(sizeof(*saved_addr), GFP_KERNEL);
263 	if (!saved_addr)
264 		goto out_err_free;
265 	saved_addr->addr =
266 		rcu_dereference_raw(xprt->address_strings[RPC_DISPLAY_ADDR]);
267 	rcu_assign_pointer(xprt->address_strings[RPC_DISPLAY_ADDR], dst_addr);
268 	call_rcu(&saved_addr->rcu, free_xprt_addr);
269 	xprt->addrlen = rpc_pton(xprt->xprt_net, buf, buf_len, saddr,
270 				 sizeof(*saddr));
271 	rpc_set_port(saddr, port);
272 
273 	xprt_force_disconnect(xprt);
274 out:
275 	xprt_release_write(xprt, NULL);
276 out_put:
277 	xprt_put(xprt);
278 	return count;
279 out_err_free:
280 	kfree(dst_addr);
281 out_err:
282 	count = -ENOMEM;
283 	goto out;
284 }
285 
286 static ssize_t rpc_sysfs_xprt_state_change(struct kobject *kobj,
287 					   struct kobj_attribute *attr,
288 					   const char *buf, size_t count)
289 {
290 	struct rpc_xprt *xprt = rpc_sysfs_xprt_kobj_get_xprt(kobj);
291 	int offline = 0, online = 0, remove = 0;
292 	struct rpc_xprt_switch *xps = rpc_sysfs_xprt_kobj_get_xprt_switch(kobj);
293 
294 	if (!xprt || !xps) {
295 		count = 0;
296 		goto out_put;
297 	}
298 
299 	if (!strncmp(buf, "offline", 7))
300 		offline = 1;
301 	else if (!strncmp(buf, "online", 6))
302 		online = 1;
303 	else if (!strncmp(buf, "remove", 6))
304 		remove = 1;
305 	else {
306 		count = -EINVAL;
307 		goto out_put;
308 	}
309 
310 	if (wait_on_bit_lock(&xprt->state, XPRT_LOCKED, TASK_KILLABLE)) {
311 		count = -EINTR;
312 		goto out_put;
313 	}
314 	if (xprt->main) {
315 		count = -EINVAL;
316 		goto release_tasks;
317 	}
318 	if (offline) {
319 		xprt_set_offline_locked(xprt, xps);
320 	} else if (online) {
321 		xprt_set_online_locked(xprt, xps);
322 	} else if (remove) {
323 		if (test_bit(XPRT_OFFLINE, &xprt->state))
324 			xprt_delete_locked(xprt, xps);
325 		else
326 			count = -EINVAL;
327 	}
328 
329 release_tasks:
330 	xprt_release_write(xprt, NULL);
331 out_put:
332 	xprt_put(xprt);
333 	xprt_switch_put(xps);
334 	return count;
335 }
336 
337 int rpc_sysfs_init(void)
338 {
339 	rpc_sunrpc_kset = kset_create_and_add("sunrpc", NULL, kernel_kobj);
340 	if (!rpc_sunrpc_kset)
341 		return -ENOMEM;
342 	rpc_sunrpc_client_kobj =
343 		rpc_sysfs_object_alloc("rpc-clients", rpc_sunrpc_kset, NULL);
344 	if (!rpc_sunrpc_client_kobj)
345 		goto err_client;
346 	rpc_sunrpc_xprt_switch_kobj =
347 		rpc_sysfs_object_alloc("xprt-switches", rpc_sunrpc_kset, NULL);
348 	if (!rpc_sunrpc_xprt_switch_kobj)
349 		goto err_switch;
350 	return 0;
351 err_switch:
352 	kobject_put(rpc_sunrpc_client_kobj);
353 	rpc_sunrpc_client_kobj = NULL;
354 err_client:
355 	kset_unregister(rpc_sunrpc_kset);
356 	rpc_sunrpc_kset = NULL;
357 	return -ENOMEM;
358 }
359 
360 static void rpc_sysfs_client_release(struct kobject *kobj)
361 {
362 	struct rpc_sysfs_client *c;
363 
364 	c = container_of(kobj, struct rpc_sysfs_client, kobject);
365 	kfree(c);
366 }
367 
368 static void rpc_sysfs_xprt_switch_release(struct kobject *kobj)
369 {
370 	struct rpc_sysfs_xprt_switch *xprt_switch;
371 
372 	xprt_switch = container_of(kobj, struct rpc_sysfs_xprt_switch, kobject);
373 	kfree(xprt_switch);
374 }
375 
376 static void rpc_sysfs_xprt_release(struct kobject *kobj)
377 {
378 	struct rpc_sysfs_xprt *xprt;
379 
380 	xprt = container_of(kobj, struct rpc_sysfs_xprt, kobject);
381 	kfree(xprt);
382 }
383 
384 static const void *rpc_sysfs_client_namespace(struct kobject *kobj)
385 {
386 	return container_of(kobj, struct rpc_sysfs_client, kobject)->net;
387 }
388 
389 static const void *rpc_sysfs_xprt_switch_namespace(struct kobject *kobj)
390 {
391 	return container_of(kobj, struct rpc_sysfs_xprt_switch, kobject)->net;
392 }
393 
394 static const void *rpc_sysfs_xprt_namespace(struct kobject *kobj)
395 {
396 	return container_of(kobj, struct rpc_sysfs_xprt,
397 			    kobject)->xprt->xprt_net;
398 }
399 
400 static struct kobj_attribute rpc_sysfs_xprt_dstaddr = __ATTR(dstaddr,
401 	0644, rpc_sysfs_xprt_dstaddr_show, rpc_sysfs_xprt_dstaddr_store);
402 
403 static struct kobj_attribute rpc_sysfs_xprt_srcaddr = __ATTR(srcaddr,
404 	0644, rpc_sysfs_xprt_srcaddr_show, NULL);
405 
406 static struct kobj_attribute rpc_sysfs_xprt_info = __ATTR(xprt_info,
407 	0444, rpc_sysfs_xprt_info_show, NULL);
408 
409 static struct kobj_attribute rpc_sysfs_xprt_change_state = __ATTR(xprt_state,
410 	0644, rpc_sysfs_xprt_state_show, rpc_sysfs_xprt_state_change);
411 
412 static struct attribute *rpc_sysfs_xprt_attrs[] = {
413 	&rpc_sysfs_xprt_dstaddr.attr,
414 	&rpc_sysfs_xprt_srcaddr.attr,
415 	&rpc_sysfs_xprt_info.attr,
416 	&rpc_sysfs_xprt_change_state.attr,
417 	NULL,
418 };
419 ATTRIBUTE_GROUPS(rpc_sysfs_xprt);
420 
421 static struct kobj_attribute rpc_sysfs_xprt_switch_info =
422 	__ATTR(xprt_switch_info, 0444, rpc_sysfs_xprt_switch_info_show, NULL);
423 
424 static struct attribute *rpc_sysfs_xprt_switch_attrs[] = {
425 	&rpc_sysfs_xprt_switch_info.attr,
426 	NULL,
427 };
428 ATTRIBUTE_GROUPS(rpc_sysfs_xprt_switch);
429 
430 static struct kobj_type rpc_sysfs_client_type = {
431 	.release = rpc_sysfs_client_release,
432 	.sysfs_ops = &kobj_sysfs_ops,
433 	.namespace = rpc_sysfs_client_namespace,
434 };
435 
436 static struct kobj_type rpc_sysfs_xprt_switch_type = {
437 	.release = rpc_sysfs_xprt_switch_release,
438 	.default_groups = rpc_sysfs_xprt_switch_groups,
439 	.sysfs_ops = &kobj_sysfs_ops,
440 	.namespace = rpc_sysfs_xprt_switch_namespace,
441 };
442 
443 static struct kobj_type rpc_sysfs_xprt_type = {
444 	.release = rpc_sysfs_xprt_release,
445 	.default_groups = rpc_sysfs_xprt_groups,
446 	.sysfs_ops = &kobj_sysfs_ops,
447 	.namespace = rpc_sysfs_xprt_namespace,
448 };
449 
450 void rpc_sysfs_exit(void)
451 {
452 	kobject_put(rpc_sunrpc_client_kobj);
453 	kobject_put(rpc_sunrpc_xprt_switch_kobj);
454 	kset_unregister(rpc_sunrpc_kset);
455 }
456 
457 static struct rpc_sysfs_client *rpc_sysfs_client_alloc(struct kobject *parent,
458 						       struct net *net,
459 						       int clid)
460 {
461 	struct rpc_sysfs_client *p;
462 
463 	p = kzalloc(sizeof(*p), GFP_KERNEL);
464 	if (p) {
465 		p->net = net;
466 		p->kobject.kset = rpc_sunrpc_kset;
467 		if (kobject_init_and_add(&p->kobject, &rpc_sysfs_client_type,
468 					 parent, "clnt-%d", clid) == 0)
469 			return p;
470 		kobject_put(&p->kobject);
471 	}
472 	return NULL;
473 }
474 
475 static struct rpc_sysfs_xprt_switch *
476 rpc_sysfs_xprt_switch_alloc(struct kobject *parent,
477 			    struct rpc_xprt_switch *xprt_switch,
478 			    struct net *net,
479 			    gfp_t gfp_flags)
480 {
481 	struct rpc_sysfs_xprt_switch *p;
482 
483 	p = kzalloc(sizeof(*p), gfp_flags);
484 	if (p) {
485 		p->net = net;
486 		p->kobject.kset = rpc_sunrpc_kset;
487 		if (kobject_init_and_add(&p->kobject,
488 					 &rpc_sysfs_xprt_switch_type,
489 					 parent, "switch-%d",
490 					 xprt_switch->xps_id) == 0)
491 			return p;
492 		kobject_put(&p->kobject);
493 	}
494 	return NULL;
495 }
496 
497 static struct rpc_sysfs_xprt *rpc_sysfs_xprt_alloc(struct kobject *parent,
498 						   struct rpc_xprt *xprt,
499 						   gfp_t gfp_flags)
500 {
501 	struct rpc_sysfs_xprt *p;
502 
503 	p = kzalloc(sizeof(*p), gfp_flags);
504 	if (!p)
505 		goto out;
506 	p->kobject.kset = rpc_sunrpc_kset;
507 	if (kobject_init_and_add(&p->kobject, &rpc_sysfs_xprt_type,
508 				 parent, "xprt-%d-%s", xprt->id,
509 				 xprt->address_strings[RPC_DISPLAY_PROTO]) == 0)
510 		return p;
511 	kobject_put(&p->kobject);
512 out:
513 	return NULL;
514 }
515 
516 void rpc_sysfs_client_setup(struct rpc_clnt *clnt,
517 			    struct rpc_xprt_switch *xprt_switch,
518 			    struct net *net)
519 {
520 	struct rpc_sysfs_client *rpc_client;
521 
522 	rpc_client = rpc_sysfs_client_alloc(rpc_sunrpc_client_kobj,
523 					    net, clnt->cl_clid);
524 	if (rpc_client) {
525 		char name[] = "switch";
526 		struct rpc_sysfs_xprt_switch *xswitch =
527 			(struct rpc_sysfs_xprt_switch *)xprt_switch->xps_sysfs;
528 		int ret;
529 
530 		clnt->cl_sysfs = rpc_client;
531 		rpc_client->clnt = clnt;
532 		rpc_client->xprt_switch = xprt_switch;
533 		kobject_uevent(&rpc_client->kobject, KOBJ_ADD);
534 		ret = sysfs_create_link_nowarn(&rpc_client->kobject,
535 					       &xswitch->kobject, name);
536 		if (ret)
537 			pr_warn("can't create link to %s in sysfs (%d)\n",
538 				name, ret);
539 	}
540 }
541 
542 void rpc_sysfs_xprt_switch_setup(struct rpc_xprt_switch *xprt_switch,
543 				 struct rpc_xprt *xprt,
544 				 gfp_t gfp_flags)
545 {
546 	struct rpc_sysfs_xprt_switch *rpc_xprt_switch;
547 	struct net *net;
548 
549 	if (xprt_switch->xps_net)
550 		net = xprt_switch->xps_net;
551 	else
552 		net = xprt->xprt_net;
553 	rpc_xprt_switch =
554 		rpc_sysfs_xprt_switch_alloc(rpc_sunrpc_xprt_switch_kobj,
555 					    xprt_switch, net, gfp_flags);
556 	if (rpc_xprt_switch) {
557 		xprt_switch->xps_sysfs = rpc_xprt_switch;
558 		rpc_xprt_switch->xprt_switch = xprt_switch;
559 		rpc_xprt_switch->xprt = xprt;
560 		kobject_uevent(&rpc_xprt_switch->kobject, KOBJ_ADD);
561 	}
562 }
563 
564 void rpc_sysfs_xprt_setup(struct rpc_xprt_switch *xprt_switch,
565 			  struct rpc_xprt *xprt,
566 			  gfp_t gfp_flags)
567 {
568 	struct rpc_sysfs_xprt *rpc_xprt;
569 	struct rpc_sysfs_xprt_switch *switch_obj =
570 		(struct rpc_sysfs_xprt_switch *)xprt_switch->xps_sysfs;
571 
572 	rpc_xprt = rpc_sysfs_xprt_alloc(&switch_obj->kobject, xprt, gfp_flags);
573 	if (rpc_xprt) {
574 		xprt->xprt_sysfs = rpc_xprt;
575 		rpc_xprt->xprt = xprt;
576 		rpc_xprt->xprt_switch = xprt_switch;
577 		kobject_uevent(&rpc_xprt->kobject, KOBJ_ADD);
578 	}
579 }
580 
581 void rpc_sysfs_client_destroy(struct rpc_clnt *clnt)
582 {
583 	struct rpc_sysfs_client *rpc_client = clnt->cl_sysfs;
584 
585 	if (rpc_client) {
586 		char name[] = "switch";
587 
588 		sysfs_remove_link(&rpc_client->kobject, name);
589 		kobject_uevent(&rpc_client->kobject, KOBJ_REMOVE);
590 		kobject_del(&rpc_client->kobject);
591 		kobject_put(&rpc_client->kobject);
592 		clnt->cl_sysfs = NULL;
593 	}
594 }
595 
596 void rpc_sysfs_xprt_switch_destroy(struct rpc_xprt_switch *xprt_switch)
597 {
598 	struct rpc_sysfs_xprt_switch *rpc_xprt_switch = xprt_switch->xps_sysfs;
599 
600 	if (rpc_xprt_switch) {
601 		kobject_uevent(&rpc_xprt_switch->kobject, KOBJ_REMOVE);
602 		kobject_del(&rpc_xprt_switch->kobject);
603 		kobject_put(&rpc_xprt_switch->kobject);
604 		xprt_switch->xps_sysfs = NULL;
605 	}
606 }
607 
608 void rpc_sysfs_xprt_destroy(struct rpc_xprt *xprt)
609 {
610 	struct rpc_sysfs_xprt *rpc_xprt = xprt->xprt_sysfs;
611 
612 	if (rpc_xprt) {
613 		kobject_uevent(&rpc_xprt->kobject, KOBJ_REMOVE);
614 		kobject_del(&rpc_xprt->kobject);
615 		kobject_put(&rpc_xprt->kobject);
616 		xprt->xprt_sysfs = NULL;
617 	}
618 }
619