From: Dan Aloni <dan@kernelim.com>
To: linux-nfs@vger.kernel.org, Anna Schumaker <anna.schumaker@netapp.com>
Cc: Trond Myklebust <trond.myklebust@hammerspace.com>
Subject: [PATCH v1 8/8] sunrpc: introduce an 'add' node to 'multipath' sysfs directory
Date: Mon, 15 Feb 2021 19:40:02 +0200 [thread overview]
Message-ID: <20210215174002.2376333-9-dan@kernelim.com> (raw)
In-Reply-To: <20210215174002.2376333-1-dan@kernelim.com>
This allows adding new transports to an existing multipath switch. This
is similar to what the `nconnect` mount parameter does, but instead we
can do this while the NFS mount is live.
For example:
echo 'dstaddr 192.168.40.8 kind rdma' \
> /sys/kernel/sunrpc/client/0/multipath/add
Signed-off-by: Dan Aloni <dan@kernelim.com>
---
net/sunrpc/sysfs.c | 104 +++++++++++++++++++++++++++++++++++++++++++--
1 file changed, 101 insertions(+), 3 deletions(-)
diff --git a/net/sunrpc/sysfs.c b/net/sunrpc/sysfs.c
index 3592f3b862b2..d745dfb7cef4 100644
--- a/net/sunrpc/sysfs.c
+++ b/net/sunrpc/sysfs.c
@@ -315,18 +315,116 @@ static ssize_t rpc_netns_multipath_list_show(struct kobject *kobj,
return pos;
}
-static ssize_t rpc_netns_multipath_list_store(struct kobject *kobj,
+static ssize_t rpc_netns_multipath_add_store(struct kobject *kobj,
struct kobj_attribute *attr, const char *buf, size_t count)
{
- return -EINVAL;
+ struct rpc_netns_multipath *c =
+ container_of(kobj, struct rpc_netns_multipath, kobject);
+ struct rpc_xprt_switch *xps = c->xps;
+ struct rpc_xprt_iter xpi;
+ struct sockaddr_storage addr;
+ struct xprt_create xprt_args = {
+ .ident = XPRT_TRANSPORT_RDMA,
+ .net = c->net,
+ .dstaddr = (struct sockaddr *)&addr,
+ };
+ struct rpc_xprt *existing_xprt;
+ char *opt, *str, *arg;
+ bool has_dstaddr = false;
+ bool has_kind = false;
+ int err;
+
+ opt = kstrndup(buf, count, GFP_KERNEL);
+ if (!opt)
+ return -ENOMEM;
+
+ str = strstrip(opt);
+
+ while (1) {
+ arg = strsep(&str, " ");
+ if (!arg)
+ break;
+
+ if (sysfs_streq(arg, "kind")) {
+ arg = strsep(&str, " ");
+ if (!arg) {
+ err = -EINVAL;
+ goto out;
+ }
+ if (has_kind) {
+ err = -EINVAL;
+ goto out;
+ }
+
+ if (sysfs_streq(arg, "rdma")) {
+ xprt_args.ident = XPRT_TRANSPORT_RDMA;
+ } else if (sysfs_streq(arg, "tcp")) {
+ xprt_args.ident = XPRT_TRANSPORT_TCP;
+ } else {
+ err = -EINVAL;
+ goto out;
+ }
+
+ has_kind = true;
+ } else if (sysfs_streq(arg, "dstaddr")) {
+ arg = strsep(&str, " ");
+ if (!arg) {
+ err = -EINVAL;
+ goto out;
+ }
+ xprt_args.addrlen = rpc_pton(c->net,
+ arg, strlen(arg), (struct sockaddr *)&addr,
+ sizeof(addr));
+ if (has_dstaddr || !xprt_args.addrlen) {
+ err = -EINVAL;
+ goto out;
+ }
+
+ has_dstaddr = true;
+ } else {
+ break;
+ }
+ }
+
+ if (!has_dstaddr || !has_kind) {
+ err = -EINVAL;
+ goto out;
+ }
+
+
+ /* Discover an existing xprt */
+ xprt_iter_init_listall(&xpi, xps);
+ existing_xprt = xprt_iter_get_next(&xpi);
+ xprt_iter_destroy(&xpi);
+
+ if (!existing_xprt) {
+ err = -ENOENT;
+ goto out;
+ }
+
+ xprt_args.servername = existing_xprt->servername;
+ xprt_iter_init_listall(&xpi, xps);
+ rpc_add_xprt(&xpi, NULL, &xprt_args, NULL, NULL);
+ xprt_iter_destroy(&xpi);
+
+ xprt_put(existing_xprt);
+
+ err = count;
+out:
+ kfree(opt);
+
+ return err;
}
static struct kobj_attribute rpc_netns_multipath_list = __ATTR(list,
- 0644, rpc_netns_multipath_list_show, rpc_netns_multipath_list_store);
+ 0444, rpc_netns_multipath_list_show, NULL);
+static struct kobj_attribute rpc_netns_multipath_add = __ATTR(add,
+ 0200, NULL, rpc_netns_multipath_add_store);
static struct attribute *rpc_netns_multipath_attrs[] = {
&rpc_netns_multipath_list.attr,
+ &rpc_netns_multipath_add.attr,
NULL,
};
--
2.26.2
next prev parent reply other threads:[~2021-02-15 17:41 UTC|newest]
Thread overview: 16+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-02-15 17:39 [PATCH v1 0/8] sysfs files for multipath transport control Dan Aloni
2021-02-15 17:39 ` [PATCH v1 1/8] sunrpc: rename 'net' to 'client' Dan Aloni
2021-02-16 21:24 ` Anna Schumaker
2021-02-17 18:58 ` Dan Aloni
2021-02-15 17:39 ` [PATCH v1 2/8] sunrpc: add xprt id Dan Aloni
2021-02-15 17:39 ` [PATCH v1 3/8] sunrpc: add a directory per sunrpc xprt Dan Aloni
2021-02-16 21:46 ` Anna Schumaker
2021-02-17 19:01 ` Dan Aloni
2021-02-15 17:39 ` [PATCH v1 4/8] sunrpc: have client directory a symlink to the root transport Dan Aloni
2021-02-15 17:39 ` [PATCH v1 5/8] sunrpc: add IDs to multipath Dan Aloni
2021-02-15 17:40 ` [PATCH v1 6/8] sunrpc: add multipath directory and symlink from client Dan Aloni
2021-02-15 17:40 ` [PATCH v1 7/8] sunrpc: change rpc_clnt_add_xprt() to rpc_add_xprt() Dan Aloni
2021-02-15 17:40 ` Dan Aloni [this message]
2021-03-02 3:56 ` [PATCH v1 0/8] sysfs files for multipath transport control Olga Kornievskaia
2021-03-04 11:58 ` Dan Aloni
2021-03-04 18:39 ` Chuck Lever
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20210215174002.2376333-9-dan@kernelim.com \
--to=dan@kernelim.com \
--cc=anna.schumaker@netapp.com \
--cc=linux-nfs@vger.kernel.org \
--cc=trond.myklebust@hammerspace.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox