[PATCH] knfsd: SUNRPC: update internal API: separate pmap register and temp sockets
[powerpc.git] / net / sunrpc / svcsock.c
index cf93cd1..27ba34a 100644 (file)
@@ -58,7 +58,7 @@
  *     providing that certain rules are followed:
  *
  *     SK_CONN, SK_DATA, can be set or cleared at any time.
- *             after a set, svc_sock_enqueue must be called.   
+ *             after a set, svc_sock_enqueue must be called.
  *             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.
@@ -75,7 +75,7 @@
 
 
 static struct svc_sock *svc_setup_socket(struct svc_serv *, struct socket *,
-                                        int *errp, int pmap_reg);
+                                        int *errp, int flags);
 static void            svc_delete_socket(struct svc_sock *svsk);
 static void            svc_udp_data_ready(struct sock *, int);
 static int             svc_udp_recvfrom(struct svc_rqst *);
@@ -252,7 +252,7 @@ svc_sock_enqueue(struct svc_sock *svsk)
                        svsk->sk_sk, rqstp);
                svc_thread_dequeue(pool, rqstp);
                if (rqstp->rq_sock)
-                       printk(KERN_ERR 
+                       printk(KERN_ERR
                                "svc_sock_enqueue: server %p, rq_sock=%p!\n",
                                rqstp, rqstp->rq_sock);
                rqstp->rq_sock = svsk;
@@ -484,7 +484,7 @@ svc_sendto(struct svc_rqst *rqstp, struct xdr_buf *xdr)
        if (xdr->tail[0].iov_len) {
                result = kernel_sendpage(sock, rqstp->rq_respages[0],
                                             ((unsigned long)xdr->tail[0].iov_base)
-                                               & (PAGE_SIZE-1),
+                                               & (PAGE_SIZE-1),
                                             xdr->tail[0].iov_len, 0);
 
                if (result > 0)
@@ -711,7 +711,7 @@ svc_udp_recvfrom(struct svc_rqst *rqstp)
                tv.tv_sec = xtime.tv_sec;
                tv.tv_usec = xtime.tv_nsec / NSEC_PER_USEC;
                skb_set_timestamp(skb, &tv);
-               /* Don't enable netstamp, sunrpc doesn't 
+               /* Don't enable netstamp, sunrpc doesn't
                   need that much accuracy */
        }
        skb_get_timestamp(skb, &svsk->sk_sk->sk_stamp);
@@ -743,7 +743,7 @@ svc_udp_recvfrom(struct svc_rqst *rqstp)
                        return 0;
                }
                local_bh_enable();
-               skb_free_datagram(svsk->sk_sk, skb); 
+               skb_free_datagram(svsk->sk_sk, skb);
        } else {
                /* we can use it in-place */
                rqstp->rq_arg.head[0].iov_base = skb->data + sizeof(struct udphdr);
@@ -794,7 +794,7 @@ svc_udp_init(struct svc_sock *svsk)
        svsk->sk_sendto = svc_udp_sendto;
 
        /* initialise setting must have enough space to
-        * receive and respond to one request.  
+        * receive and respond to one request.
         * svc_udp_recvfrom will re-adjust if necessary
         */
        svc_sock_setbufsize(svsk->sk_sock,
@@ -923,7 +923,7 @@ svc_tcp_accept(struct svc_sock *svsk)
        if (ntohs(sin.sin_port) >= 1024) {
                dprintk(KERN_WARNING
                        "%s: connect from unprivileged port: %u.%u.%u.%u:%d\n",
-                       serv->sv_name, 
+                       serv->sv_name,
                        NIPQUAD(sin.sin_addr.s_addr), ntohs(sin.sin_port));
        }
 
@@ -935,7 +935,8 @@ svc_tcp_accept(struct svc_sock *svsk)
         */
        newsock->sk->sk_sndtimeo = HZ*30;
 
-       if (!(newsvsk = svc_setup_socket(serv, newsock, &err, 0)))
+       if (!(newsvsk = svc_setup_socket(serv, newsock, &err,
+                                (SVC_SOCK_ANONYMOUS | SVC_SOCK_TEMPORARY))))
                goto failed;
 
 
@@ -1038,7 +1039,7 @@ svc_tcp_recvfrom(struct svc_rqst *rqstp)
                 * on the number of threads which will access the socket.
                 *
                 * rcvbuf just needs to be able to hold a few requests.
-                * Normally they will be removed from the queue 
+                * Normally they will be removed from the queue
                 * as soon a a complete request arrives.
                 */
                svc_sock_setbufsize(svsk->sk_sock,
@@ -1063,7 +1064,7 @@ svc_tcp_recvfrom(struct svc_rqst *rqstp)
 
                if (len < want) {
                        dprintk("svc: short recvfrom while reading record length (%d of %lu)\n",
-                               len, want);
+                               len, want);
                        svc_sock_received(svsk);
                        return -EAGAIN; /* record header not complete */
                }
@@ -1221,7 +1222,7 @@ svc_tcp_init(struct svc_sock *svsk)
                tp->nonagle = 1;        /* disable Nagle's algorithm */
 
                /* initialise setting must have enough space to
-                * receive and respond to one request.  
+                * receive and respond to one request.
                 * svc_tcp_recvfrom will re-adjust if necessary
                 */
                svc_sock_setbufsize(svsk->sk_sock,
@@ -1230,7 +1231,7 @@ svc_tcp_init(struct svc_sock *svsk)
 
                set_bit(SK_CHNGBUF, &svsk->sk_flags);
                set_bit(SK_DATA, &svsk->sk_flags);
-               if (sk->sk_state != TCP_ESTABLISHED) 
+               if (sk->sk_state != TCP_ESTABLISHED)
                        set_bit(SK_CLOSE, &svsk->sk_flags);
        }
 }
@@ -1246,7 +1247,7 @@ svc_sock_update_bufs(struct svc_serv *serv)
 
        spin_lock_bh(&serv->sv_lock);
        list_for_each(le, &serv->sv_permsocks) {
-               struct svc_sock *svsk = 
+               struct svc_sock *svsk =
                        list_entry(le, struct svc_sock, sk_list);
                set_bit(SK_CHNGBUF, &svsk->sk_flags);
        }
@@ -1278,11 +1279,11 @@ svc_recv(struct svc_rqst *rqstp, long timeout)
                rqstp, timeout);
 
        if (rqstp->rq_sock)
-               printk(KERN_ERR 
+               printk(KERN_ERR
                        "svc_recv: service %p, socket not NULL!\n",
                         rqstp);
        if (waitqueue_active(&rqstp->rq_wait))
-               printk(KERN_ERR 
+               printk(KERN_ERR
                        "svc_recv: service %p, wait queue active!\n",
                         rqstp);
 
@@ -1371,7 +1372,7 @@ svc_recv(struct svc_rqst *rqstp, long timeout)
        return len;
 }
 
-/* 
+/*
  * Drop request
  */
 void
@@ -1476,12 +1477,14 @@ svc_age_temp_sockets(unsigned long closure)
  * Initialize socket for RPC use and create svc_sock struct
  * XXX: May want to setsockopt SO_SNDBUF and SO_RCVBUF.
  */
-static struct svc_sock *
-svc_setup_socket(struct svc_serv *serv, struct socket *sock,
-                                       int *errp, int pmap_register)
+static struct svc_sock *svc_setup_socket(struct svc_serv *serv,
+                                               struct socket *sock,
+                                               int *errp, int flags)
 {
        struct svc_sock *svsk;
        struct sock     *inet;
+       int             pmap_register = !(flags & SVC_SOCK_ANONYMOUS);
+       int             is_temporary = flags & SVC_SOCK_TEMPORARY;
 
        dprintk("svc: svc_setup_socket %p\n", sock);
        if (!(svsk = kzalloc(sizeof(*svsk), GFP_KERNEL))) {
@@ -1523,7 +1526,7 @@ svc_setup_socket(struct svc_serv *serv, struct socket *sock,
                svc_tcp_init(svsk);
 
        spin_lock_bh(&serv->sv_lock);
-       if (!pmap_register) {
+       if (is_temporary) {
                set_bit(SK_TEMP, &svsk->sk_flags);
                list_add(&svsk->sk_list, &serv->sv_tempsocks);
                serv->sv_tmpcnt++;
@@ -1567,7 +1570,7 @@ int svc_addsock(struct svc_serv *serv,
        else if (so->state > SS_UNCONNECTED)
                err = -EISCONN;
        else {
-               svsk = svc_setup_socket(serv, so, &err, 1);
+               svsk = svc_setup_socket(serv, so, &err, SVC_SOCK_DEFAULTS);
                if (svsk)
                        err = 0;
        }
@@ -1583,8 +1586,8 @@ EXPORT_SYMBOL_GPL(svc_addsock);
 /*
  * Create socket for RPC service.
  */
-static int
-svc_create_socket(struct svc_serv *serv, int protocol, struct sockaddr_in *sin)
+static int svc_create_socket(struct svc_serv *serv, int protocol,
+                               struct sockaddr_in *sin, int flags)
 {
        struct svc_sock *svsk;
        struct socket   *sock;
@@ -1620,8 +1623,8 @@ svc_create_socket(struct svc_serv *serv, int protocol, struct sockaddr_in *sin)
                        goto bummer;
        }
 
-       if ((svsk = svc_setup_socket(serv, sock, &error, 1)) != NULL)
-               return 0;
+       if ((svsk = svc_setup_socket(serv, sock, &error, flags)) != NULL)
+               return ntohs(inet_sk(svsk->sk_sk)->sport);
 
 bummer:
        dprintk("svc: svc_create_socket error = %d\n", -error);
@@ -1651,7 +1654,7 @@ svc_delete_socket(struct svc_sock *svsk)
 
        if (!test_and_set_bit(SK_DETACHED, &svsk->sk_flags))
                list_del_init(&svsk->sk_list);
-       /*
+       /*
         * We used to delete the svc_sock from whichever list
         * it's sk_ready node was on, but we don't actually
         * need to.  This is because the only time we're called
@@ -1681,23 +1684,27 @@ void svc_close_socket(struct svc_sock *svsk)
        svc_sock_put(svsk);
 }
 
-/*
- * Make a socket for nfsd and lockd
+/**
+ * svc_makesock - Make a socket for nfsd and lockd
+ * @serv: RPC server structure
+ * @protocol: transport protocol to use
+ * @port: port to use
+ *
  */
-int
-svc_makesock(struct svc_serv *serv, int protocol, unsigned short port)
+int svc_makesock(struct svc_serv *serv, int protocol, unsigned short port)
 {
-       struct sockaddr_in      sin;
+       struct sockaddr_in sin = {
+               .sin_family             = AF_INET,
+               .sin_addr.s_addr        = INADDR_ANY,
+               .sin_port               = htons(port),
+       };
 
        dprintk("svc: creating socket proto = %d\n", protocol);
-       sin.sin_family      = AF_INET;
-       sin.sin_addr.s_addr = INADDR_ANY;
-       sin.sin_port        = htons(port);
-       return svc_create_socket(serv, protocol, &sin);
+       return svc_create_socket(serv, protocol, &sin, SVC_SOCK_DEFAULTS);
 }
 
 /*
- * Handle defer and revisit of requests 
+ * Handle defer and revisit of requests
  */
 
 static void svc_revisit(struct cache_deferred_req *dreq, int too_many)
@@ -1776,7 +1783,7 @@ static int svc_deferred_recv(struct svc_rqst *rqstp)
 static struct svc_deferred_req *svc_deferred_dequeue(struct svc_sock *svsk)
 {
        struct svc_deferred_req *dr = NULL;
-       
+
        if (!test_bit(SK_DEFERRED, &svsk->sk_flags))
                return NULL;
        spin_lock_bh(&svsk->sk_defer_lock);