[ofa-general] [RFC,PATCH 13/20] svc: Add svc_[un]register_transport
Tom Tucker
tom at opengridcomputing.com
Mon Aug 20 11:57:53 PDT 2007
Add an exported function for transport modules to [un]register themselves
with the sunrpc server side transport switch.
Signed-off-by: Tom Tucker <tom at opengridcomputing.com>
---
include/linux/sunrpc/svcsock.h | 6 +++++
net/sunrpc/svcsock.c | 50 ++++++++++++++++++++++++++++++++++++++++
2 files changed, 56 insertions(+), 0 deletions(-)
diff --git a/include/linux/sunrpc/svcsock.h b/include/linux/sunrpc/svcsock.h
index 7def951..cc911ab 100644
--- a/include/linux/sunrpc/svcsock.h
+++ b/include/linux/sunrpc/svcsock.h
@@ -13,6 +13,7 @@ #include <linux/sunrpc/svc.h>
struct svc_xprt {
const char *xpt_name;
+ struct module *xpt_owner;
int (*xpt_recvfrom)(struct svc_rqst *rqstp);
int (*xpt_sendto)(struct svc_rqst *rqstp);
/*
@@ -45,7 +46,10 @@ struct svc_xprt {
* Accept a pending connection, for connection-oriented transports
*/
int (*xpt_accept)(struct svc_sock *svsk);
+ /* Transport list link */
+ struct list_head xpt_list;
};
+extern struct list_head svc_transport_list;
/*
* RPC server socket.
@@ -102,6 +106,8 @@ #define SK_LISTENER 11 /* listener (e.
/*
* Function prototypes.
*/
+int svc_register_transport(struct svc_xprt *xprt);
+int svc_unregister_transport(struct svc_xprt *xprt);
int svc_makesock(struct svc_serv *, int, unsigned short, int flags);
void svc_force_close_socket(struct svc_sock *);
int svc_recv(struct svc_rqst *, long);
diff --git a/net/sunrpc/svcsock.c b/net/sunrpc/svcsock.c
index 6acf22f..6183951 100644
--- a/net/sunrpc/svcsock.c
+++ b/net/sunrpc/svcsock.c
@@ -91,6 +91,54 @@ static struct svc_deferred_req *svc_defe
static int svc_deferred_recv(struct svc_rqst *rqstp);
static struct cache_deferred_req *svc_defer(struct cache_req *req);
+/* List of registered transports */
+static spinlock_t svc_transport_lock = SPIN_LOCK_UNLOCKED;
+LIST_HEAD(svc_transport_list);
+
+int svc_register_transport(struct svc_xprt *xprt)
+{
+ struct svc_xprt *ops;
+ int res;
+
+ dprintk("svc: Adding svc transport '%s'\n",
+ xprt->xpt_name);
+
+ res = -EEXIST;
+ INIT_LIST_HEAD(&xprt->xpt_list);
+ spin_lock(&svc_transport_lock);
+ list_for_each_entry(ops, &svc_transport_list, xpt_list) {
+ if (xprt == ops)
+ goto out;
+ }
+ list_add_tail(&xprt->xpt_list, &svc_transport_list);
+ res = 0;
+out:
+ spin_unlock(&svc_transport_lock);
+ return res;
+}
+EXPORT_SYMBOL_GPL(svc_register_transport);
+
+int svc_unregister_transport(struct svc_xprt *xprt)
+{
+ struct svc_xprt *ops;
+ int res = 0;
+
+ dprintk("svc: Removing svc transport '%s'\n", xprt->xpt_name);
+
+ spin_lock(&svc_transport_lock);
+ list_for_each_entry(ops, &svc_transport_list, xpt_list) {
+ if (xprt == ops) {
+ list_del_init(&ops->xpt_list);
+ goto out;
+ }
+ }
+ res = -ENOENT;
+ out:
+ spin_unlock(&svc_transport_lock);
+ return res;
+}
+EXPORT_SYMBOL_GPL(svc_unregister_transport);
+
/* apparently the "standard" is that clients close
* idle connections after 5 minutes, servers after
* 6 minutes
@@ -887,6 +935,7 @@ svc_udp_has_wspace(struct svc_sock *svsk
static const struct svc_xprt svc_udp_xprt = {
.xpt_name = "udp",
+ .xpt_owner = THIS_MODULE,
.xpt_recvfrom = svc_udp_recvfrom,
.xpt_sendto = svc_udp_sendto,
.xpt_detach = svc_sock_detach,
@@ -1346,6 +1395,7 @@ svc_tcp_has_wspace(struct svc_sock *svsk
static const struct svc_xprt svc_tcp_xprt = {
.xpt_name = "tcp",
+ .xpt_owner = THIS_MODULE,
.xpt_recvfrom = svc_tcp_recvfrom,
.xpt_sendto = svc_tcp_sendto,
.xpt_detach = svc_sock_detach,
More information about the general
mailing list