Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

sunrpc: Add a sysfs file for adding a new xprt

Writing to this file will clone the 'main' xprt of an xprt_switch and
add it to be used as an additional connection.

--

Reviewed-by: Benjamin Coddington <bcodding@redhat.com>
Signed-off-by: Anna Schumaker <anna.schumaker@oracle.com>
v3: Replace call to xprt_iter_get_xprt() with xprt_iter_get_next()
Link: https://lore.kernel.org/r/20250207204225.594002-5-anna@kernel.org
Signed-off-by: Trond Myklebust <trond.myklebust@hammerspace.com>

authored by

Anna Schumaker and committed by
Trond Myklebust
df210d9b 88efd79c

+76
+1
include/linux/sunrpc/xprtmultipath.h
··· 56 56 struct rpc_xprt *xprt); 57 57 extern void rpc_xprt_switch_remove_xprt(struct rpc_xprt_switch *xps, 58 58 struct rpc_xprt *xprt, bool offline); 59 + extern struct rpc_xprt *rpc_xprt_switch_get_main_xprt(struct rpc_xprt_switch *xps); 59 60 60 61 extern void xprt_iter_init(struct rpc_xprt_iter *xpi, 61 62 struct rpc_xprt_switch *xps);
+54
net/sunrpc/sysfs.c
··· 305 305 return ret; 306 306 } 307 307 308 + static ssize_t rpc_sysfs_xprt_switch_add_xprt_show(struct kobject *kobj, 309 + struct kobj_attribute *attr, 310 + char *buf) 311 + { 312 + return sprintf(buf, "# add one xprt to this xprt_switch\n"); 313 + } 314 + 315 + static ssize_t rpc_sysfs_xprt_switch_add_xprt_store(struct kobject *kobj, 316 + struct kobj_attribute *attr, 317 + const char *buf, size_t count) 318 + { 319 + struct rpc_xprt_switch *xprt_switch = 320 + rpc_sysfs_xprt_switch_kobj_get_xprt(kobj); 321 + struct xprt_create xprt_create_args; 322 + struct rpc_xprt *xprt, *new; 323 + 324 + if (!xprt_switch) 325 + return 0; 326 + 327 + xprt = rpc_xprt_switch_get_main_xprt(xprt_switch); 328 + if (!xprt) 329 + goto out; 330 + 331 + xprt_create_args.ident = xprt->xprt_class->ident; 332 + xprt_create_args.net = xprt->xprt_net; 333 + xprt_create_args.dstaddr = (struct sockaddr *)&xprt->addr; 334 + xprt_create_args.addrlen = xprt->addrlen; 335 + xprt_create_args.servername = xprt->servername; 336 + xprt_create_args.bc_xprt = xprt->bc_xprt; 337 + xprt_create_args.xprtsec = xprt->xprtsec; 338 + xprt_create_args.connect_timeout = xprt->connect_timeout; 339 + xprt_create_args.reconnect_timeout = xprt->max_reconnect_timeout; 340 + 341 + new = xprt_create_transport(&xprt_create_args); 342 + if (IS_ERR_OR_NULL(new)) { 343 + count = PTR_ERR(new); 344 + goto out_put_xprt; 345 + } 346 + 347 + rpc_xprt_switch_add_xprt(xprt_switch, new); 348 + xprt_put(new); 349 + 350 + out_put_xprt: 351 + xprt_put(xprt); 352 + out: 353 + xprt_switch_put(xprt_switch); 354 + return count; 355 + } 356 + 308 357 static ssize_t rpc_sysfs_xprt_dstaddr_store(struct kobject *kobj, 309 358 struct kobj_attribute *attr, 310 359 const char *buf, size_t count) ··· 572 523 static struct kobj_attribute rpc_sysfs_xprt_switch_info = 573 524 __ATTR(xprt_switch_info, 0444, rpc_sysfs_xprt_switch_info_show, NULL); 574 525 526 + static struct kobj_attribute rpc_sysfs_xprt_switch_add_xprt = 527 + __ATTR(add_xprt, 0644, rpc_sysfs_xprt_switch_add_xprt_show, 528 + rpc_sysfs_xprt_switch_add_xprt_store); 529 + 575 530 static struct attribute *rpc_sysfs_xprt_switch_attrs[] = { 576 531 &rpc_sysfs_xprt_switch_info.attr, 532 + &rpc_sysfs_xprt_switch_add_xprt.attr, 577 533 NULL, 578 534 }; 579 535 ATTRIBUTE_GROUPS(rpc_sysfs_xprt_switch);
+21
net/sunrpc/xprtmultipath.c
··· 92 92 xprt_put(xprt); 93 93 } 94 94 95 + /** 96 + * rpc_xprt_switch_get_main_xprt - Get the 'main' xprt for an xprt switch. 97 + * @xps: pointer to struct rpc_xprt_switch. 98 + */ 99 + struct rpc_xprt *rpc_xprt_switch_get_main_xprt(struct rpc_xprt_switch *xps) 100 + { 101 + struct rpc_xprt_iter xpi; 102 + struct rpc_xprt *xprt; 103 + 104 + xprt_iter_init_listall(&xpi, xps); 105 + 106 + xprt = xprt_iter_get_next(&xpi); 107 + while (xprt && !xprt->main) { 108 + xprt_put(xprt); 109 + xprt = xprt_iter_get_next(&xpi); 110 + } 111 + 112 + xprt_iter_destroy(&xpi); 113 + return xprt; 114 + } 115 + 95 116 static DEFINE_IDA(rpc_xprtswitch_ids); 96 117 97 118 void xprt_multipath_cleanup_ids(void)