All of lore.kernel.org
 help / color / mirror / Atom feed
From: Tom Tucker <tom@opengridcomputing.com>
To: nfs@lists.sourceforge.net
Cc: neilb@suse.de, bfields@fieldses.org, gnb@sgi.com
Subject: [RFC,PATCH 14/35] svc: Change sk_inuse to a kref
Date: Mon, 01 Oct 2007 14:28:01 -0500	[thread overview]
Message-ID: <20071001192801.3250.49751.stgit@dell3.ogc.int> (raw)
In-Reply-To: <20071001191426.3250.15371.stgit@dell3.ogc.int>


Change the atomic_t reference count to a kref and move it to the 
transport indepenent svc_xprt structure. Change the reference count
wrapper names to be generic.

Signed-off-by: Tom Tucker <tom@opengridcomputing.com>
---

 include/linux/sunrpc/svc_xprt.h |    8 ++++++
 include/linux/sunrpc/svcsock.h  |    1 -
 net/sunrpc/svc_xprt.c           |   17 ++++++++++++
 net/sunrpc/svcsock.c            |   54 +++++++++++++++------------------------
 4 files changed, 46 insertions(+), 34 deletions(-)

diff --git a/include/linux/sunrpc/svc_xprt.h b/include/linux/sunrpc/svc_xprt.h
index 6a34bb4..c77e873 100644
--- a/include/linux/sunrpc/svc_xprt.h
+++ b/include/linux/sunrpc/svc_xprt.h
@@ -8,6 +8,7 @@ #ifndef SUNRPC_SVC_XPRT_H
 #define SUNRPC_SVC_XPRT_H
 
 #include <linux/sunrpc/svc.h>
+#include <linux/module.h>
 
 struct svc_xprt_ops {
 	struct svc_xprt	*(*xpo_create)(struct svc_serv *,
@@ -35,11 +36,18 @@ struct svc_xprt {
 	struct svc_xprt_class	*xpt_class;
 	struct svc_xprt_ops	xpt_ops;
 	u32			xpt_max_payload;
+	struct kref		xpt_ref;
 };
 
 int	svc_reg_xprt_class(struct svc_xprt_class *);
 int	svc_unreg_xprt_class(struct svc_xprt_class *);
 void	svc_xprt_init(struct svc_xprt_class *, struct svc_xprt *);
 int	svc_create_xprt(struct svc_serv *, char *, unsigned short, int);
+void	svc_xprt_put(struct svc_xprt *xprt);
+
+static inline void svc_xprt_get(struct svc_xprt *xprt)
+{
+	kref_get(&xprt->xpt_ref);
+}
 
 #endif /* SUNRPC_SVC_XPRT_H */
diff --git a/include/linux/sunrpc/svcsock.h b/include/linux/sunrpc/svcsock.h
index 3181d9d..ba07d50 100644
--- a/include/linux/sunrpc/svcsock.h
+++ b/include/linux/sunrpc/svcsock.h
@@ -24,7 +24,6 @@ struct svc_sock {
 
 	struct svc_pool *	sk_pool;	/* current pool iff queued */
 	struct svc_serv *	sk_server;	/* service for this socket */
-	atomic_t		sk_inuse;	/* use count */
 	unsigned long		sk_flags;
 #define	SK_BUSY		0			/* enqueued/receiving */
 #define	SK_CONN		1			/* conn pending */
diff --git a/net/sunrpc/svc_xprt.c b/net/sunrpc/svc_xprt.c
index d57064f..05ccfa6 100644
--- a/net/sunrpc/svc_xprt.c
+++ b/net/sunrpc/svc_xprt.c
@@ -82,6 +82,22 @@ int svc_unreg_xprt_class(struct svc_xprt
 }
 EXPORT_SYMBOL_GPL(svc_unreg_xprt_class);
 
+static inline void svc_xprt_free(struct kref *kref)
+{
+	struct svc_xprt *xprt =
+		container_of(kref, struct svc_xprt, xpt_ref);
+	struct module *owner = xprt->xpt_class->xcl_owner;
+	BUG_ON(atomic_read(&kref->refcount));
+	xprt->xpt_ops.xpo_free(xprt);
+	module_put(owner);
+}
+
+void svc_xprt_put(struct svc_xprt *xprt)
+{
+	kref_put(&xprt->xpt_ref, svc_xprt_free);
+}
+EXPORT_SYMBOL_GPL(svc_xprt_put);
+
 /*
  * Called by transport drivers to initialize the transport independent
  * portion of the transport instance.
@@ -91,6 +107,7 @@ void svc_xprt_init(struct svc_xprt_class
 	xpt->xpt_class = xcl;
 	xpt->xpt_ops = *xcl->xcl_ops;
 	xpt->xpt_max_payload = xcl->xcl_max_payload;
+	kref_init(&xpt->xpt_ref);
 }
 EXPORT_SYMBOL_GPL(svc_xprt_init);
 
diff --git a/net/sunrpc/svcsock.c b/net/sunrpc/svcsock.c
index 373f020..d5e78b9 100644
--- a/net/sunrpc/svcsock.c
+++ b/net/sunrpc/svcsock.c
@@ -65,8 +65,8 @@ #include <linux/sunrpc/stats.h>
  *		after a clear, the socket must be read/accepted
  *		 if this succeeds, it must be set again.
  *	SK_CLOSE can set at any time. It is never cleared.
- *      sk_inuse contains a bias of '1' until SK_DEAD is set.
- *             so when sk_inuse hits zero, we know the socket is dead
+ *      xpt_ref contains a bias of '1' until SK_DEAD is set.
+ *             so when xprt_ref hits zero, we know the transport is dead
  *             and no-one is using it.
  *      SK_DEAD can only be set while SK_BUSY is held which ensures
  *             no other thread will be using the socket or will try to
@@ -301,7 +301,7 @@ svc_sock_enqueue(struct svc_sock *svsk)
 				"svc_sock_enqueue: server %p, rq_sock=%p!\n",
 				rqstp, rqstp->rq_sock);
 		rqstp->rq_sock = svsk;
-		atomic_inc(&svsk->sk_inuse);
+		svc_xprt_get(&svsk->sk_xprt);
 		rqstp->rq_reserved = serv->sv_max_mesg;
 		atomic_add(rqstp->rq_reserved, &svsk->sk_reserved);
 		BUG_ON(svsk->sk_pool != pool);
@@ -332,7 +332,7 @@ svc_sock_dequeue(struct svc_pool *pool)
 	list_del_init(&svsk->sk_ready);
 
 	dprintk("svc: socket %p dequeued, inuse=%d\n",
-		svsk->sk_sk, atomic_read(&svsk->sk_inuse));
+		svsk->sk_sk, atomic_read(&svsk->sk_xprt.xpt_ref.refcount));
 
 	return svsk;
 }
@@ -375,19 +375,6 @@ void svc_reserve(struct svc_rqst *rqstp,
 	}
 }
 
-/*
- * Release a socket after use.
- */
-static inline void
-svc_sock_put(struct svc_sock *svsk)
-{
-	if (atomic_dec_and_test(&svsk->sk_inuse)) {
-		BUG_ON(!test_bit(SK_DEAD, &svsk->sk_flags));
-		module_put(svsk->sk_xprt.xpt_class->xcl_owner);
-		svsk->sk_xprt.xpt_ops.xpo_free(&svsk->sk_xprt);
-	}
-}
-
 static void
 svc_sock_release(struct svc_rqst *rqstp)
 {
@@ -414,7 +401,7 @@ svc_sock_release(struct svc_rqst *rqstp)
 	svc_reserve(rqstp, 0);
 	rqstp->rq_sock = NULL;
 
-	svc_sock_put(svsk);
+	svc_xprt_put(&svsk->sk_xprt);
 }
 
 /*
@@ -1506,13 +1493,13 @@ svc_check_conn_limits(struct svc_serv *s
 					  struct svc_sock,
 					  sk_list);
 			set_bit(SK_CLOSE, &svsk->sk_flags);
-			atomic_inc(&svsk->sk_inuse);
+			svc_xprt_get(&svsk->sk_xprt);
 		}
 		spin_unlock_bh(&serv->sv_lock);
 
 		if (svsk) {
 			svc_sock_enqueue(svsk);
-			svc_sock_put(svsk);
+			svc_xprt_put(&svsk->sk_xprt);
 		}
 	}
 }
@@ -1577,7 +1564,7 @@ svc_recv(struct svc_rqst *rqstp, long ti
 	spin_lock_bh(&pool->sp_lock);
 	if ((svsk = svc_sock_dequeue(pool)) != NULL) {
 		rqstp->rq_sock = svsk;
-		atomic_inc(&svsk->sk_inuse);
+		svc_xprt_get(&svsk->sk_xprt);
 		rqstp->rq_reserved = serv->sv_max_mesg;
 		atomic_add(rqstp->rq_reserved, &svsk->sk_reserved);
 	} else {
@@ -1626,7 +1613,8 @@ svc_recv(struct svc_rqst *rqstp, long ti
 		svc_sock_received(svsk);
 	} else {
 		dprintk("svc: server %p, pool %u, socket %p, inuse=%d\n",
-			rqstp, pool->sp_id, svsk, atomic_read(&svsk->sk_inuse));
+			rqstp, pool->sp_id, svsk,
+			atomic_read(&svsk->sk_xprt.xpt_ref.refcount));
 		len = svsk->sk_xprt.xpt_ops.xpo_recvfrom(rqstp);
 		dprintk("svc: got len=%d\n", len);
 	}
@@ -1723,9 +1711,10 @@ svc_age_temp_sockets(unsigned long closu
 
 		if (!test_and_set_bit(SK_OLD, &svsk->sk_flags))
 			continue;
-		if (atomic_read(&svsk->sk_inuse) > 1 || test_bit(SK_BUSY, &svsk->sk_flags))
+		if (atomic_read(&svsk->sk_xprt.xpt_ref.refcount) > 1
+		    || test_bit(SK_BUSY, &svsk->sk_flags))
 			continue;
-		atomic_inc(&svsk->sk_inuse);
+		svc_xprt_get(&svsk->sk_xprt);
 		list_move(le, &to_be_aged);
 		set_bit(SK_CLOSE, &svsk->sk_flags);
 		set_bit(SK_DETACHED, &svsk->sk_flags);
@@ -1743,7 +1732,7 @@ svc_age_temp_sockets(unsigned long closu
 
 		/* a thread will dequeue and close it soon */
 		svc_sock_enqueue(svsk);
-		svc_sock_put(svsk);
+		svc_xprt_put(&svsk->sk_xprt);
 	}
 
 	mod_timer(&serv->sv_temptimer, jiffies + svc_conn_age_period * HZ);
@@ -1788,7 +1777,6 @@ static struct svc_sock *svc_setup_socket
 	svsk->sk_odata = inet->sk_data_ready;
 	svsk->sk_owspace = inet->sk_write_space;
 	svsk->sk_server = serv;
-	atomic_set(&svsk->sk_inuse, 1);
 	svsk->sk_lastrecv = get_seconds();
 	spin_lock_init(&svsk->sk_lock);
 	INIT_LIST_HEAD(&svsk->sk_deferred);
@@ -1977,8 +1965,8 @@ svc_delete_socket(struct svc_sock *svsk)
 	 * is about to be destroyed (in svc_destroy).
 	 */
 	if (!test_and_set_bit(SK_DEAD, &svsk->sk_flags)) {
-		BUG_ON(atomic_read(&svsk->sk_inuse)<2);
-		atomic_dec(&svsk->sk_inuse);
+		BUG_ON(atomic_read(&svsk->sk_xprt.xpt_ref.refcount) < 2);
+		svc_xprt_put(&svsk->sk_xprt);
 		if (test_bit(SK_TEMP, &svsk->sk_flags))
 			serv->sv_tmpcnt--;
 	}
@@ -1993,10 +1981,10 @@ static void svc_close_socket(struct svc_
 		/* someone else will have to effect the close */
 		return;
 
-	atomic_inc(&svsk->sk_inuse);
+	svc_xprt_get(&svsk->sk_xprt);
 	svc_delete_socket(svsk);
 	clear_bit(SK_BUSY, &svsk->sk_flags);
-	svc_sock_put(svsk);
+	svc_xprt_put(&svsk->sk_xprt);
 }
 
 void svc_force_close_socket(struct svc_sock *svsk)
@@ -2022,7 +2010,7 @@ static void svc_revisit(struct cache_def
 	struct svc_sock *svsk;
 
 	if (too_many) {
-		svc_sock_put(dr->svsk);
+		svc_xprt_put(&dr->svsk->sk_xprt);
 		kfree(dr);
 		return;
 	}
@@ -2034,7 +2022,7 @@ static void svc_revisit(struct cache_def
 	spin_unlock(&svsk->sk_lock);
 	set_bit(SK_DEFERRED, &svsk->sk_flags);
 	svc_sock_enqueue(svsk);
-	svc_sock_put(svsk);
+	svc_xprt_put(&svsk->sk_xprt);
 }
 
 static struct cache_deferred_req *
@@ -2064,7 +2052,7 @@ svc_defer(struct cache_req *req)
 		dr->argslen = rqstp->rq_arg.len >> 2;
 		memcpy(dr->args, rqstp->rq_arg.head[0].iov_base-skip, dr->argslen<<2);
 	}
-	atomic_inc(&rqstp->rq_sock->sk_inuse);
+	svc_xprt_get(rqstp->rq_xprt);
 	dr->svsk = rqstp->rq_sock;
 
 	dr->handle.revisit = svc_revisit;

-------------------------------------------------------------------------
This SF.net email is sponsored by: Microsoft
Defy all challenges. Microsoft(R) Visual Studio 2005.
http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/
_______________________________________________
NFS maillist  -  NFS@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/nfs

  parent reply	other threads:[~2007-10-01 19:28 UTC|newest]

Thread overview: 103+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2007-10-01 19:14 [RFC,PATCH 00/35] SVC Transport Switch Tom Tucker
2007-10-01 19:27 ` [RFC,PATCH 01/35] svc: Add an svc transport class Tom Tucker
2007-10-01 19:27 ` [RFC,PATCH 02/35] svc: Make svc_sock the tcp/udp transport Tom Tucker
2007-10-01 19:27 ` [RFC, PATCH 03/35] svc: Change the svc_sock in the rqstp structure to a transport Tom Tucker
2007-10-01 19:27 ` [RFC, PATCH 04/35] svc: Add a max payload value to the transport Tom Tucker
2007-10-02 14:54   ` Chuck Lever
2007-10-02 16:28     ` Tom Tucker
2007-10-03 11:09       ` Greg Banks
2007-10-03 14:26         ` Tom Tucker
2007-10-03 15:18           ` Chuck Lever
2007-10-04  1:10           ` Greg Banks
2007-10-01 19:27 ` [RFC, PATCH 05/35] svc: Move sk_sendto and sk_recvfrom to svc_xprt_class Tom Tucker
2007-10-02 15:04   ` Chuck Lever
2007-10-02 16:29     ` Tom Tucker
2007-10-02 16:57       ` Chuck Lever
2007-10-02 18:24         ` Tom Tucker
2007-10-02 18:30           ` Tom Tucker
2007-10-02 18:47             ` Chuck Lever
2007-10-02 19:55               ` Tom Tucker
2007-10-02 20:29                 ` Chuck Lever
2007-10-02 20:35                   ` Tom Tucker
2007-10-02 20:38                     ` Tom Tucker
2007-10-04  1:34                 ` Greg Banks
2007-10-04  1:21             ` Greg Banks
2007-10-03 11:13       ` Greg Banks
2007-10-01 19:27 ` [RFC, PATCH 06/35] svc: Add transport specific xpo_release function Tom Tucker
2007-10-02 15:18   ` Chuck Lever
2007-10-02 16:35     ` Tom Tucker
2007-10-04  1:48     ` Greg Banks
2007-10-01 19:27 ` [RFC,PATCH 07/35] svc: Add per-transport delete functions Tom Tucker
2007-10-01 19:27 ` [RFC,PATCH 08/35] svc: Add xpo_prep_reply_hdr Tom Tucker
2007-10-01 19:27 ` [RFC, PATCH 09/35] svc: Add a transport function that checks for write space Tom Tucker
2007-10-01 19:27 ` [RFC, PATCH 10/35] svc: Move close processing to a single place Tom Tucker
2007-10-01 19:27 ` [RFC,PATCH 11/35] svc: Add xpo_accept transport function Tom Tucker
2007-10-02 15:33   ` Chuck Lever
2007-10-02 16:41     ` Tom Tucker
2007-10-02 17:07       ` Chuck Lever
2007-10-02 18:28         ` Tom Tucker
2007-10-02 18:49           ` Chuck Lever
2007-10-04  1:54           ` Greg Banks
2007-10-01 19:27 ` [RFC, PATCH 12/35] svc: Add a generic transport svc_create_xprt function Tom Tucker
2007-10-02 15:39   ` Chuck Lever
2007-10-03 20:01     ` Tom Tucker
2007-10-03 20:04       ` Tom Tucker
2007-10-04  2:30     ` Greg Banks
2007-10-04 15:18       ` Chuck Lever
2007-10-01 19:27 ` [RFC, PATCH 13/35] svc: Change services to use new svc_create_xprt service Tom Tucker
2007-10-02 15:44   ` Chuck Lever
2007-10-02 16:45     ` Tom Tucker
2007-10-03 15:25       ` Chuck Lever
2007-10-03 16:23         ` Tom Tucker
2007-10-04  2:35     ` Greg Banks
2007-10-04 14:27       ` Tom Tucker
2007-10-09 17:09   ` J. Bruce Fields
2007-10-09 18:32     ` Tom Tucker
2007-10-09 19:49       ` J. Bruce Fields
2007-10-09 20:19       ` J. Bruce Fields
2007-10-01 19:28 ` Tom Tucker [this message]
2007-10-03 11:12   ` [RFC,PATCH 14/35] svc: Change sk_inuse to a kref Christoph Hellwig
2007-10-03 14:39     ` Tom Tucker
2007-10-03 14:45     ` J. Bruce Fields
2007-10-03 14:52       ` Christoph Hellwig
2007-10-03 15:11         ` J. Bruce Fields
2007-10-03 15:15           ` Christoph Hellwig
2007-10-08  3:52             ` Neil Brown
2007-10-03 15:13         ` Chuck Lever
2007-10-03 15:34           ` J. Bruce Fields
2007-10-04  2:51             ` Greg Banks
2007-10-01 19:28 ` [RFC, PATCH 15/35] svc: Move sk_flags to the svc_xprt structure Tom Tucker
2007-10-01 19:28 ` [RFC, PATCH 16/35] svc: Move sk_server and sk_pool to svc_xprt Tom Tucker
2007-10-01 19:28 ` [RFC,PATCH 17/35] svc: Make close transport independent Tom Tucker
2007-10-01 19:28 ` [RFC,PATCH 18/35] svc: Move sk_reserved to svc_xprt Tom Tucker
2007-10-01 19:28 ` [RFC, PATCH 19/35] svc: Make the enqueue service transport neutral and export it Tom Tucker
2007-10-01 19:28 ` [RFC,PATCH 20/35] svc: Make svc_send transport neutral Tom Tucker
2007-10-02 16:15   ` Chuck Lever
2007-10-02 16:46     ` Tom Tucker
2007-10-02 16:54       ` Chuck Lever
2007-10-04  2:59         ` Greg Banks
2007-10-01 19:28 ` [RFC, PATCH 21/35] svc: Change svc_sock_received to svc_xprt_received and export it Tom Tucker
2007-10-02 16:18   ` Chuck Lever
2007-10-01 19:28 ` [RFC,PATCH 22/35] svc: Remove sk_lastrecv Tom Tucker
2007-10-01 19:28 ` [RFC,PATCH 23/35] svc: Move the authinfo cache to svc_xprt Tom Tucker
2007-10-01 19:28 ` [RFC, PATCH 24/35] svc: Make deferral processing xprt independent Tom Tucker
2007-10-01 19:28 ` [RFC, PATCH 25/35] svc: Move the sockaddr information to svc_xprt Tom Tucker
2007-10-02 16:34   ` Chuck Lever
2007-10-02 16:50     ` Tom Tucker
2007-10-01 19:28 ` [RFC, PATCH 26/35] svc: Make svc_sock_release svc_xprt_release Tom Tucker
2007-10-01 19:28 ` [RFC,PATCH 27/35] svc: Make svc_recv transport neutral Tom Tucker
2007-10-02 16:36   ` Chuck Lever
2007-10-01 19:28 ` [RFC, PATCH 28/35] svc: Make svc_age_temp_sockets svc_age_temp_transports Tom Tucker
2007-10-01 19:28 ` [RFC, PATCH 29/35] svc: Move common create logic to common code Tom Tucker
2007-10-02 16:42   ` Chuck Lever
2007-10-02 16:51     ` Tom Tucker
2007-10-01 19:28 ` [RFC, PATCH 30/35] svc: Removing remaining references to rq_sock in rqstp Tom Tucker
2007-10-01 19:28 ` [RFC, PATCH 31/35] svc: Make svc_check_conn_limits xprt independent Tom Tucker
2007-10-01 19:28 ` [RFC, PATCH 32/35] svc: Move the xprt independent code to the svc_xprt.c file Tom Tucker
2007-10-01 19:28 ` [RFC, PATCH 33/35] svc: Add transport hdr size for defer/revisit Tom Tucker
2007-10-01 19:28 ` [RFC,PATCH 34/35] svc: Add /proc/sys/sunrpc/transport files Tom Tucker
2007-10-01 19:28 ` [RFC, PATCH 35/35] knfsd: Support adding transports by writing portlist file Tom Tucker
2007-10-02 15:25 ` [RFC,PATCH 00/35] SVC Transport Switch J. Bruce Fields
2007-10-02 16:18   ` Tom Tucker
2007-10-03 11:03 ` Greg Banks
2007-10-03 14:02   ` Tom Tucker

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=20071001192801.3250.49751.stgit@dell3.ogc.int \
    --to=tom@opengridcomputing.com \
    --cc=bfields@fieldses.org \
    --cc=gnb@sgi.com \
    --cc=neilb@suse.de \
    --cc=nfs@lists.sourceforge.net \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.