xref: /openbmc/linux/net/sunrpc/sysfs.c (revision 0a4cad9c)
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)
295 		return 0;
296 
297 	if (!strncmp(buf, "offline", 7))
298 		offline = 1;
299 	else if (!strncmp(buf, "online", 6))
300 		online = 1;
301 	else if (!strncmp(buf, "remove", 6))
302 		remove = 1;
303 	else {
304 		count = -EINVAL;
305 		goto out_put;
306 	}
307 
308 	if (wait_on_bit_lock(&xprt->state, XPRT_LOCKED, TASK_KILLABLE)) {
309 		count = -EINTR;
310 		goto out_put;
311 	}
312 	if (xprt->main) {
313 		count = -EINVAL;
314 		goto release_tasks;
315 	}
316 	if (offline) {
317 		if (!test_and_set_bit(XPRT_OFFLINE, &xprt->state)) {
318 			spin_lock(&xps->xps_lock);
319 			xps->xps_nactive--;
320 			spin_unlock(&xps->xps_lock);
321 		}
322 	} else if (online) {
323 		if (test_and_clear_bit(XPRT_OFFLINE, &xprt->state)) {
324 			spin_lock(&xps->xps_lock);
325 			xps->xps_nactive++;
326 			spin_unlock(&xps->xps_lock);
327 		}
328 	} else if (remove) {
329 		if (test_bit(XPRT_OFFLINE, &xprt->state)) {
330 			if (!test_and_set_bit(XPRT_REMOVE, &xprt->state)) {
331 				xprt_force_disconnect(xprt);
332 				if (test_bit(XPRT_CONNECTED, &xprt->state)) {
333 					if (!xprt->sending.qlen &&
334 					    !xprt->pending.qlen &&
335 					    !xprt->backlog.qlen &&
336 					    !atomic_long_read(&xprt->queuelen))
337 						rpc_xprt_switch_remove_xprt(xps, xprt);
338 				}
339 			}
340 		} else {
341 			count = -EINVAL;
342 		}
343 	}
344 
345 release_tasks:
346 	xprt_release_write(xprt, NULL);
347 out_put:
348 	xprt_put(xprt);
349 	xprt_switch_put(xps);
350 	return count;
351 }
352 
353 int rpc_sysfs_init(void)
354 {
355 	rpc_sunrpc_kset = kset_create_and_add("sunrpc", NULL, kernel_kobj);
356 	if (!rpc_sunrpc_kset)
357 		return -ENOMEM;
358 	rpc_sunrpc_client_kobj =
359 		rpc_sysfs_object_alloc("rpc-clients", rpc_sunrpc_kset, NULL);
360 	if (!rpc_sunrpc_client_kobj)
361 		goto err_client;
362 	rpc_sunrpc_xprt_switch_kobj =
363 		rpc_sysfs_object_alloc("xprt-switches", rpc_sunrpc_kset, NULL);
364 	if (!rpc_sunrpc_xprt_switch_kobj)
365 		goto err_switch;
366 	return 0;
367 err_switch:
368 	kobject_put(rpc_sunrpc_client_kobj);
369 	rpc_sunrpc_client_kobj = NULL;
370 err_client:
371 	kset_unregister(rpc_sunrpc_kset);
372 	rpc_sunrpc_kset = NULL;
373 	return -ENOMEM;
374 }
375 
376 static void rpc_sysfs_client_release(struct kobject *kobj)
377 {
378 	struct rpc_sysfs_client *c;
379 
380 	c = container_of(kobj, struct rpc_sysfs_client, kobject);
381 	kfree(c);
382 }
383 
384 static void rpc_sysfs_xprt_switch_release(struct kobject *kobj)
385 {
386 	struct rpc_sysfs_xprt_switch *xprt_switch;
387 
388 	xprt_switch = container_of(kobj, struct rpc_sysfs_xprt_switch, kobject);
389 	kfree(xprt_switch);
390 }
391 
392 static void rpc_sysfs_xprt_release(struct kobject *kobj)
393 {
394 	struct rpc_sysfs_xprt *xprt;
395 
396 	xprt = container_of(kobj, struct rpc_sysfs_xprt, kobject);
397 	kfree(xprt);
398 }
399 
400 static const void *rpc_sysfs_client_namespace(struct kobject *kobj)
401 {
402 	return container_of(kobj, struct rpc_sysfs_client, kobject)->net;
403 }
404 
405 static const void *rpc_sysfs_xprt_switch_namespace(struct kobject *kobj)
406 {
407 	return container_of(kobj, struct rpc_sysfs_xprt_switch, kobject)->net;
408 }
409 
410 static const void *rpc_sysfs_xprt_namespace(struct kobject *kobj)
411 {
412 	return container_of(kobj, struct rpc_sysfs_xprt,
413 			    kobject)->xprt->xprt_net;
414 }
415 
416 static struct kobj_attribute rpc_sysfs_xprt_dstaddr = __ATTR(dstaddr,
417 	0644, rpc_sysfs_xprt_dstaddr_show, rpc_sysfs_xprt_dstaddr_store);
418 
419 static struct kobj_attribute rpc_sysfs_xprt_srcaddr = __ATTR(srcaddr,
420 	0644, rpc_sysfs_xprt_srcaddr_show, NULL);
421 
422 static struct kobj_attribute rpc_sysfs_xprt_info = __ATTR(xprt_info,
423 	0444, rpc_sysfs_xprt_info_show, NULL);
424 
425 static struct kobj_attribute rpc_sysfs_xprt_change_state = __ATTR(xprt_state,
426 	0644, rpc_sysfs_xprt_state_show, rpc_sysfs_xprt_state_change);
427 
428 static struct attribute *rpc_sysfs_xprt_attrs[] = {
429 	&rpc_sysfs_xprt_dstaddr.attr,
430 	&rpc_sysfs_xprt_srcaddr.attr,
431 	&rpc_sysfs_xprt_info.attr,
432 	&rpc_sysfs_xprt_change_state.attr,
433 	NULL,
434 };
435 ATTRIBUTE_GROUPS(rpc_sysfs_xprt);
436 
437 static struct kobj_attribute rpc_sysfs_xprt_switch_info =
438 	__ATTR(xprt_switch_info, 0444, rpc_sysfs_xprt_switch_info_show, NULL);
439 
440 static struct attribute *rpc_sysfs_xprt_switch_attrs[] = {
441 	&rpc_sysfs_xprt_switch_info.attr,
442 	NULL,
443 };
444 ATTRIBUTE_GROUPS(rpc_sysfs_xprt_switch);
445 
446 static struct kobj_type rpc_sysfs_client_type = {
447 	.release = rpc_sysfs_client_release,
448 	.sysfs_ops = &kobj_sysfs_ops,
449 	.namespace = rpc_sysfs_client_namespace,
450 };
451 
452 static struct kobj_type rpc_sysfs_xprt_switch_type = {
453 	.release = rpc_sysfs_xprt_switch_release,
454 	.default_groups = rpc_sysfs_xprt_switch_groups,
455 	.sysfs_ops = &kobj_sysfs_ops,
456 	.namespace = rpc_sysfs_xprt_switch_namespace,
457 };
458 
459 static struct kobj_type rpc_sysfs_xprt_type = {
460 	.release = rpc_sysfs_xprt_release,
461 	.default_groups = rpc_sysfs_xprt_groups,
462 	.sysfs_ops = &kobj_sysfs_ops,
463 	.namespace = rpc_sysfs_xprt_namespace,
464 };
465 
466 void rpc_sysfs_exit(void)
467 {
468 	kobject_put(rpc_sunrpc_client_kobj);
469 	kobject_put(rpc_sunrpc_xprt_switch_kobj);
470 	kset_unregister(rpc_sunrpc_kset);
471 }
472 
473 static struct rpc_sysfs_client *rpc_sysfs_client_alloc(struct kobject *parent,
474 						       struct net *net,
475 						       int clid)
476 {
477 	struct rpc_sysfs_client *p;
478 
479 	p = kzalloc(sizeof(*p), GFP_KERNEL);
480 	if (p) {
481 		p->net = net;
482 		p->kobject.kset = rpc_sunrpc_kset;
483 		if (kobject_init_and_add(&p->kobject, &rpc_sysfs_client_type,
484 					 parent, "clnt-%d", clid) == 0)
485 			return p;
486 		kobject_put(&p->kobject);
487 	}
488 	return NULL;
489 }
490 
491 static struct rpc_sysfs_xprt_switch *
492 rpc_sysfs_xprt_switch_alloc(struct kobject *parent,
493 			    struct rpc_xprt_switch *xprt_switch,
494 			    struct net *net,
495 			    gfp_t gfp_flags)
496 {
497 	struct rpc_sysfs_xprt_switch *p;
498 
499 	p = kzalloc(sizeof(*p), gfp_flags);
500 	if (p) {
501 		p->net = net;
502 		p->kobject.kset = rpc_sunrpc_kset;
503 		if (kobject_init_and_add(&p->kobject,
504 					 &rpc_sysfs_xprt_switch_type,
505 					 parent, "switch-%d",
506 					 xprt_switch->xps_id) == 0)
507 			return p;
508 		kobject_put(&p->kobject);
509 	}
510 	return NULL;
511 }
512 
513 static struct rpc_sysfs_xprt *rpc_sysfs_xprt_alloc(struct kobject *parent,
514 						   struct rpc_xprt *xprt,
515 						   gfp_t gfp_flags)
516 {
517 	struct rpc_sysfs_xprt *p;
518 
519 	p = kzalloc(sizeof(*p), gfp_flags);
520 	if (!p)
521 		goto out;
522 	p->kobject.kset = rpc_sunrpc_kset;
523 	if (kobject_init_and_add(&p->kobject, &rpc_sysfs_xprt_type,
524 				 parent, "xprt-%d-%s", xprt->id,
525 				 xprt->address_strings[RPC_DISPLAY_PROTO]) == 0)
526 		return p;
527 	kobject_put(&p->kobject);
528 out:
529 	return NULL;
530 }
531 
532 void rpc_sysfs_client_setup(struct rpc_clnt *clnt,
533 			    struct rpc_xprt_switch *xprt_switch,
534 			    struct net *net)
535 {
536 	struct rpc_sysfs_client *rpc_client;
537 
538 	rpc_client = rpc_sysfs_client_alloc(rpc_sunrpc_client_kobj,
539 					    net, clnt->cl_clid);
540 	if (rpc_client) {
541 		char name[] = "switch";
542 		struct rpc_sysfs_xprt_switch *xswitch =
543 			(struct rpc_sysfs_xprt_switch *)xprt_switch->xps_sysfs;
544 		int ret;
545 
546 		clnt->cl_sysfs = rpc_client;
547 		rpc_client->clnt = clnt;
548 		rpc_client->xprt_switch = xprt_switch;
549 		kobject_uevent(&rpc_client->kobject, KOBJ_ADD);
550 		ret = sysfs_create_link_nowarn(&rpc_client->kobject,
551 					       &xswitch->kobject, name);
552 		if (ret)
553 			pr_warn("can't create link to %s in sysfs (%d)\n",
554 				name, ret);
555 	}
556 }
557 
558 void rpc_sysfs_xprt_switch_setup(struct rpc_xprt_switch *xprt_switch,
559 				 struct rpc_xprt *xprt,
560 				 gfp_t gfp_flags)
561 {
562 	struct rpc_sysfs_xprt_switch *rpc_xprt_switch;
563 	struct net *net;
564 
565 	if (xprt_switch->xps_net)
566 		net = xprt_switch->xps_net;
567 	else
568 		net = xprt->xprt_net;
569 	rpc_xprt_switch =
570 		rpc_sysfs_xprt_switch_alloc(rpc_sunrpc_xprt_switch_kobj,
571 					    xprt_switch, net, gfp_flags);
572 	if (rpc_xprt_switch) {
573 		xprt_switch->xps_sysfs = rpc_xprt_switch;
574 		rpc_xprt_switch->xprt_switch = xprt_switch;
575 		rpc_xprt_switch->xprt = xprt;
576 		kobject_uevent(&rpc_xprt_switch->kobject, KOBJ_ADD);
577 	}
578 }
579 
580 void rpc_sysfs_xprt_setup(struct rpc_xprt_switch *xprt_switch,
581 			  struct rpc_xprt *xprt,
582 			  gfp_t gfp_flags)
583 {
584 	struct rpc_sysfs_xprt *rpc_xprt;
585 	struct rpc_sysfs_xprt_switch *switch_obj =
586 		(struct rpc_sysfs_xprt_switch *)xprt_switch->xps_sysfs;
587 
588 	rpc_xprt = rpc_sysfs_xprt_alloc(&switch_obj->kobject, xprt, gfp_flags);
589 	if (rpc_xprt) {
590 		xprt->xprt_sysfs = rpc_xprt;
591 		rpc_xprt->xprt = xprt;
592 		rpc_xprt->xprt_switch = xprt_switch;
593 		kobject_uevent(&rpc_xprt->kobject, KOBJ_ADD);
594 	}
595 }
596 
597 void rpc_sysfs_client_destroy(struct rpc_clnt *clnt)
598 {
599 	struct rpc_sysfs_client *rpc_client = clnt->cl_sysfs;
600 
601 	if (rpc_client) {
602 		char name[] = "switch";
603 
604 		sysfs_remove_link(&rpc_client->kobject, name);
605 		kobject_uevent(&rpc_client->kobject, KOBJ_REMOVE);
606 		kobject_del(&rpc_client->kobject);
607 		kobject_put(&rpc_client->kobject);
608 		clnt->cl_sysfs = NULL;
609 	}
610 }
611 
612 void rpc_sysfs_xprt_switch_destroy(struct rpc_xprt_switch *xprt_switch)
613 {
614 	struct rpc_sysfs_xprt_switch *rpc_xprt_switch = xprt_switch->xps_sysfs;
615 
616 	if (rpc_xprt_switch) {
617 		kobject_uevent(&rpc_xprt_switch->kobject, KOBJ_REMOVE);
618 		kobject_del(&rpc_xprt_switch->kobject);
619 		kobject_put(&rpc_xprt_switch->kobject);
620 		xprt_switch->xps_sysfs = NULL;
621 	}
622 }
623 
624 void rpc_sysfs_xprt_destroy(struct rpc_xprt *xprt)
625 {
626 	struct rpc_sysfs_xprt *rpc_xprt = xprt->xprt_sysfs;
627 
628 	if (rpc_xprt) {
629 		kobject_uevent(&rpc_xprt->kobject, KOBJ_REMOVE);
630 		kobject_del(&rpc_xprt->kobject);
631 		kobject_put(&rpc_xprt->kobject);
632 		xprt->xprt_sysfs = NULL;
633 	}
634 }
635