]> git.baikalelectronics.ru Git - kernel.git/commitdiff
sunrpc: add add sysfs directory per xprt under each xprt_switch
authorOlga Kornievskaia <kolga@netapp.com>
Tue, 8 Jun 2021 19:59:18 +0000 (15:59 -0400)
committerTrond Myklebust <trond.myklebust@hammerspace.com>
Thu, 8 Jul 2021 18:03:23 +0000 (14:03 -0400)
Add individual transport directories under each transport switch
group. For instance, for each nconnect=X connections there will be
a transport directory. Naming conventions also identifies transport
type -- xprt-<id>-<type> where type is udp, tcp, rdma, local, bc.

Signed-off-by: Olga Kornievskaia <kolga@netapp.com>
Signed-off-by: Trond Myklebust <trond.myklebust@hammerspace.com>
include/linux/sunrpc/xprt.h
net/sunrpc/sysfs.c
net/sunrpc/sysfs.h
net/sunrpc/xprtmultipath.c

index 7efc6c0a5455405445b613381ecc36aef16c6081..8360db664e5fe9ccaff5830b3b0c863ab99e427d 100644 (file)
@@ -183,6 +183,7 @@ enum xprt_transports {
        XPRT_TRANSPORT_LOCAL    = 257,
 };
 
+struct rpc_sysfs_xprt;
 struct rpc_xprt {
        struct kref             kref;           /* Reference count */
        const struct rpc_xprt_ops *ops;         /* transport methods */
@@ -291,6 +292,7 @@ struct rpc_xprt {
 #endif
        struct rcu_head         rcu;
        const struct xprt_class *xprt_class;
+       struct rpc_sysfs_xprt   *xprt_sysfs;
 };
 
 #if defined(CONFIG_SUNRPC_BACKCHANNEL)
index 0aa63747f49660daf539ceb4dcb349eff1b6f600..20f75708594f6e40d5388acae5071c87853531bc 100644 (file)
@@ -82,6 +82,14 @@ static void rpc_sysfs_xprt_switch_release(struct kobject *kobj)
        kfree(xprt_switch);
 }
 
+static void rpc_sysfs_xprt_release(struct kobject *kobj)
+{
+       struct rpc_sysfs_xprt *xprt;
+
+       xprt = container_of(kobj, struct rpc_sysfs_xprt, kobject);
+       kfree(xprt);
+}
+
 static const void *rpc_sysfs_client_namespace(struct kobject *kobj)
 {
        return container_of(kobj, struct rpc_sysfs_client, kobject)->net;
@@ -92,6 +100,12 @@ static const void *rpc_sysfs_xprt_switch_namespace(struct kobject *kobj)
        return container_of(kobj, struct rpc_sysfs_xprt_switch, kobject)->net;
 }
 
+static const void *rpc_sysfs_xprt_namespace(struct kobject *kobj)
+{
+       return container_of(kobj, struct rpc_sysfs_xprt,
+                           kobject)->xprt->xprt_net;
+}
+
 static struct kobj_type rpc_sysfs_client_type = {
        .release = rpc_sysfs_client_release,
        .sysfs_ops = &kobj_sysfs_ops,
@@ -104,6 +118,12 @@ static struct kobj_type rpc_sysfs_xprt_switch_type = {
        .namespace = rpc_sysfs_xprt_switch_namespace,
 };
 
+static struct kobj_type rpc_sysfs_xprt_type = {
+       .release = rpc_sysfs_xprt_release,
+       .sysfs_ops = &kobj_sysfs_ops,
+       .namespace = rpc_sysfs_xprt_namespace,
+};
+
 void rpc_sysfs_exit(void)
 {
        kobject_put(rpc_sunrpc_client_kobj);
@@ -151,6 +171,25 @@ rpc_sysfs_xprt_switch_alloc(struct kobject *parent,
        return NULL;
 }
 
+static struct rpc_sysfs_xprt *rpc_sysfs_xprt_alloc(struct kobject *parent,
+                                                  struct rpc_xprt *xprt,
+                                                  gfp_t gfp_flags)
+{
+       struct rpc_sysfs_xprt *p;
+
+       p = kzalloc(sizeof(*p), gfp_flags);
+       if (!p)
+               goto out;
+       p->kobject.kset = rpc_sunrpc_kset;
+       if (kobject_init_and_add(&p->kobject, &rpc_sysfs_xprt_type,
+                                parent, "xprt-%d-%s", xprt->id,
+                                xprt->address_strings[RPC_DISPLAY_PROTO]) == 0)
+               return p;
+       kobject_put(&p->kobject);
+out:
+       return NULL;
+}
+
 void rpc_sysfs_client_setup(struct rpc_clnt *clnt,
                            struct rpc_xprt_switch *xprt_switch,
                            struct net *net)
@@ -199,6 +238,22 @@ void rpc_sysfs_xprt_switch_setup(struct rpc_xprt_switch *xprt_switch,
        }
 }
 
+void rpc_sysfs_xprt_setup(struct rpc_xprt_switch *xprt_switch,
+                         struct rpc_xprt *xprt,
+                         gfp_t gfp_flags)
+{
+       struct rpc_sysfs_xprt *rpc_xprt;
+       struct rpc_sysfs_xprt_switch *switch_obj =
+               (struct rpc_sysfs_xprt_switch *)xprt_switch->xps_sysfs;
+
+       rpc_xprt = rpc_sysfs_xprt_alloc(&switch_obj->kobject, xprt, gfp_flags);
+       if (rpc_xprt) {
+               xprt->xprt_sysfs = rpc_xprt;
+               rpc_xprt->xprt = xprt;
+               kobject_uevent(&rpc_xprt->kobject, KOBJ_ADD);
+       }
+}
+
 void rpc_sysfs_client_destroy(struct rpc_clnt *clnt)
 {
        struct rpc_sysfs_client *rpc_client = clnt->cl_sysfs;
@@ -225,3 +280,15 @@ void rpc_sysfs_xprt_switch_destroy(struct rpc_xprt_switch *xprt_switch)
                xprt_switch->xps_sysfs = NULL;
        }
 }
+
+void rpc_sysfs_xprt_destroy(struct rpc_xprt *xprt)
+{
+       struct rpc_sysfs_xprt *rpc_xprt = xprt->xprt_sysfs;
+
+       if (rpc_xprt) {
+               kobject_uevent(&rpc_xprt->kobject, KOBJ_REMOVE);
+               kobject_del(&rpc_xprt->kobject);
+               kobject_put(&rpc_xprt->kobject);
+               xprt->xprt_sysfs = NULL;
+       }
+}
index 760f0582aee5f84441d6703d1f09e5c8841dd828..ff10451de6fa302c129767343e3cf5eb59bb72cd 100644 (file)
@@ -19,6 +19,11 @@ struct rpc_sysfs_xprt_switch {
        struct rpc_xprt *xprt;
 };
 
+struct rpc_sysfs_xprt {
+       struct kobject kobject;
+       struct rpc_xprt *xprt;
+};
+
 int rpc_sysfs_init(void);
 void rpc_sysfs_exit(void);
 
@@ -29,5 +34,8 @@ void rpc_sysfs_client_destroy(struct rpc_clnt *clnt);
 void rpc_sysfs_xprt_switch_setup(struct rpc_xprt_switch *xprt_switch,
                                 struct rpc_xprt *xprt, gfp_t gfp_flags);
 void rpc_sysfs_xprt_switch_destroy(struct rpc_xprt_switch *xprt);
+void rpc_sysfs_xprt_setup(struct rpc_xprt_switch *xprt_switch,
+                         struct rpc_xprt *xprt, gfp_t gfp_flags);
+void rpc_sysfs_xprt_destroy(struct rpc_xprt *xprt);
 
 #endif
index 2d73a35df9eed283bd318387135a0c2c1eff266a..e7973c1ff70c1e8da1cb8cbea2dcf17008ab26eb 100644 (file)
@@ -57,6 +57,7 @@ void rpc_xprt_switch_add_xprt(struct rpc_xprt_switch *xps,
        if (xps->xps_net == xprt->xprt_net || xps->xps_net == NULL)
                xprt_switch_add_xprt_locked(xps, xprt);
        spin_unlock(&xps->xps_lock);
+       rpc_sysfs_xprt_setup(xps, xprt, GFP_KERNEL);
 }
 
 static void xprt_switch_remove_xprt_locked(struct rpc_xprt_switch *xps,
@@ -85,6 +86,7 @@ void rpc_xprt_switch_remove_xprt(struct rpc_xprt_switch *xps,
        spin_lock(&xps->xps_lock);
        xprt_switch_remove_xprt_locked(xps, xprt);
        spin_unlock(&xps->xps_lock);
+       rpc_sysfs_xprt_destroy(xprt);
        xprt_put(xprt);
 }
 
@@ -137,6 +139,7 @@ struct rpc_xprt_switch *xprt_switch_alloc(struct rpc_xprt *xprt,
                xps->xps_iter_ops = &rpc_xprt_iter_singular;
                rpc_sysfs_xprt_switch_setup(xps, xprt, gfp_flags);
                xprt_switch_add_xprt_locked(xps, xprt);
+               rpc_sysfs_xprt_setup(xps, xprt, gfp_flags);
        }
 
        return xps;
@@ -152,6 +155,7 @@ static void xprt_switch_free_entries(struct rpc_xprt_switch *xps)
                                struct rpc_xprt, xprt_switch);
                xprt_switch_remove_xprt_locked(xps, xprt);
                spin_unlock(&xps->xps_lock);
+               rpc_sysfs_xprt_destroy(xprt);
                xprt_put(xprt);
                spin_lock(&xps->xps_lock);
        }