sunrpc: add xprt_switch direcotry to sunrpc's sysfs
[linux-2.6-microblaze.git] / net / sunrpc / xprtmultipath.c
index 78c075a..2d73a35 100644 (file)
@@ -19,6 +19,8 @@
 #include <linux/sunrpc/addr.h>
 #include <linux/sunrpc/xprtmultipath.h>
 
+#include "sysfs.h"
+
 typedef struct rpc_xprt *(*xprt_switch_find_xprt_t)(struct rpc_xprt_switch *xps,
                const struct rpc_xprt *cur);
 
@@ -86,6 +88,30 @@ void rpc_xprt_switch_remove_xprt(struct rpc_xprt_switch *xps,
        xprt_put(xprt);
 }
 
+static DEFINE_IDA(rpc_xprtswitch_ids);
+
+void xprt_multipath_cleanup_ids(void)
+{
+       ida_destroy(&rpc_xprtswitch_ids);
+}
+
+static int xprt_switch_alloc_id(struct rpc_xprt_switch *xps, gfp_t gfp_flags)
+{
+       int id;
+
+       id = ida_simple_get(&rpc_xprtswitch_ids, 0, 0, gfp_flags);
+       if (id < 0)
+               return id;
+
+       xps->xps_id = id;
+       return 0;
+}
+
+static void xprt_switch_free_id(struct rpc_xprt_switch *xps)
+{
+       ida_simple_remove(&rpc_xprtswitch_ids, xps->xps_id);
+}
+
 /**
  * xprt_switch_alloc - Allocate a new struct rpc_xprt_switch
  * @xprt: pointer to struct rpc_xprt
@@ -103,11 +129,13 @@ struct rpc_xprt_switch *xprt_switch_alloc(struct rpc_xprt *xprt,
        if (xps != NULL) {
                spin_lock_init(&xps->xps_lock);
                kref_init(&xps->xps_kref);
+               xprt_switch_alloc_id(xps, gfp_flags);
                xps->xps_nxprts = xps->xps_nactive = 0;
                atomic_long_set(&xps->xps_queuelen, 0);
                xps->xps_net = NULL;
                INIT_LIST_HEAD(&xps->xps_xprt_list);
                xps->xps_iter_ops = &rpc_xprt_iter_singular;
+               rpc_sysfs_xprt_switch_setup(xps, xprt, gfp_flags);
                xprt_switch_add_xprt_locked(xps, xprt);
        }
 
@@ -136,6 +164,8 @@ static void xprt_switch_free(struct kref *kref)
                        struct rpc_xprt_switch, xps_kref);
 
        xprt_switch_free_entries(xps);
+       rpc_sysfs_xprt_switch_destroy(xps);
+       xprt_switch_free_id(xps);
        kfree_rcu(xps, xps_rcu);
 }