Commit 6b174337e5126de834a971d3edc3681bbfa45e2c

Authored by Chuck Lever
Committed by Linus Torvalds
1 parent f85aaeba45

[PATCH] knfsd: SUNRPC: update internal API: separate pmap register and temp sockets

Currently in the RPC server, registering with the local portmapper and
creating "permanent" sockets are tied together.  Expand the internal APIs to
allow these two socket characteristics to be separately specified.

This will be externalized in the next patch.

Signed-off-by: Chuck Lever <chuck.lever@oracle.com>
Cc: Aurelien Charbon <aurelien.charbon@ext.bull.net>
Signed-off-by: Neil Brown <neilb@suse.de>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>

Showing 2 changed files with 34 additions and 20 deletions Side-by-side Diff

include/linux/sunrpc/svcsock.h
... ... @@ -74,5 +74,12 @@
74 74 char *name_return,
75 75 int *proto);
76 76  
  77 +/*
  78 + * svc_makesock socket characteristics
  79 + */
  80 +#define SVC_SOCK_DEFAULTS (0U)
  81 +#define SVC_SOCK_ANONYMOUS (1U << 0) /* don't register with pmap */
  82 +#define SVC_SOCK_TEMPORARY (1U << 1) /* flag socket as temporary */
  83 +
77 84 #endif /* SUNRPC_SVCSOCK_H */
net/sunrpc/svcsock.c
... ... @@ -75,7 +75,7 @@
75 75  
76 76  
77 77 static struct svc_sock *svc_setup_socket(struct svc_serv *, struct socket *,
78   - int *errp, int pmap_reg);
  78 + int *errp, int flags);
79 79 static void svc_delete_socket(struct svc_sock *svsk);
80 80 static void svc_udp_data_ready(struct sock *, int);
81 81 static int svc_udp_recvfrom(struct svc_rqst *);
... ... @@ -935,7 +935,8 @@
935 935 */
936 936 newsock->sk->sk_sndtimeo = HZ*30;
937 937  
938   - if (!(newsvsk = svc_setup_socket(serv, newsock, &err, 0)))
  938 + if (!(newsvsk = svc_setup_socket(serv, newsock, &err,
  939 + (SVC_SOCK_ANONYMOUS | SVC_SOCK_TEMPORARY))))
939 940 goto failed;
940 941  
941 942  
942 943  
... ... @@ -1476,12 +1477,14 @@
1476 1477 * Initialize socket for RPC use and create svc_sock struct
1477 1478 * XXX: May want to setsockopt SO_SNDBUF and SO_RCVBUF.
1478 1479 */
1479   -static struct svc_sock *
1480   -svc_setup_socket(struct svc_serv *serv, struct socket *sock,
1481   - int *errp, int pmap_register)
  1480 +static struct svc_sock *svc_setup_socket(struct svc_serv *serv,
  1481 + struct socket *sock,
  1482 + int *errp, int flags)
1482 1483 {
1483 1484 struct svc_sock *svsk;
1484 1485 struct sock *inet;
  1486 + int pmap_register = !(flags & SVC_SOCK_ANONYMOUS);
  1487 + int is_temporary = flags & SVC_SOCK_TEMPORARY;
1485 1488  
1486 1489 dprintk("svc: svc_setup_socket %p\n", sock);
1487 1490 if (!(svsk = kzalloc(sizeof(*svsk), GFP_KERNEL))) {
... ... @@ -1523,7 +1526,7 @@
1523 1526 svc_tcp_init(svsk);
1524 1527  
1525 1528 spin_lock_bh(&serv->sv_lock);
1526   - if (!pmap_register) {
  1529 + if (is_temporary) {
1527 1530 set_bit(SK_TEMP, &svsk->sk_flags);
1528 1531 list_add(&svsk->sk_list, &serv->sv_tempsocks);
1529 1532 serv->sv_tmpcnt++;
... ... @@ -1567,7 +1570,7 @@
1567 1570 else if (so->state > SS_UNCONNECTED)
1568 1571 err = -EISCONN;
1569 1572 else {
1570   - svsk = svc_setup_socket(serv, so, &err, 1);
  1573 + svsk = svc_setup_socket(serv, so, &err, SVC_SOCK_DEFAULTS);
1571 1574 if (svsk)
1572 1575 err = 0;
1573 1576 }
... ... @@ -1583,8 +1586,8 @@
1583 1586 /*
1584 1587 * Create socket for RPC service.
1585 1588 */
1586   -static int
1587   -svc_create_socket(struct svc_serv *serv, int protocol, struct sockaddr_in *sin)
  1589 +static int svc_create_socket(struct svc_serv *serv, int protocol,
  1590 + struct sockaddr_in *sin, int flags)
1588 1591 {
1589 1592 struct svc_sock *svsk;
1590 1593 struct socket *sock;
... ... @@ -1620,8 +1623,8 @@
1620 1623 goto bummer;
1621 1624 }
1622 1625  
1623   - if ((svsk = svc_setup_socket(serv, sock, &error, 1)) != NULL)
1624   - return 0;
  1626 + if ((svsk = svc_setup_socket(serv, sock, &error, flags)) != NULL)
  1627 + return ntohs(inet_sk(svsk->sk_sk)->sport);
1625 1628  
1626 1629 bummer:
1627 1630 dprintk("svc: svc_create_socket error = %d\n", -error);
1628 1631  
1629 1632  
1630 1633  
... ... @@ -1681,19 +1684,23 @@
1681 1684 svc_sock_put(svsk);
1682 1685 }
1683 1686  
1684   -/*
1685   - * Make a socket for nfsd and lockd
  1687 +/**
  1688 + * svc_makesock - Make a socket for nfsd and lockd
  1689 + * @serv: RPC server structure
  1690 + * @protocol: transport protocol to use
  1691 + * @port: port to use
  1692 + *
1686 1693 */
1687   -int
1688   -svc_makesock(struct svc_serv *serv, int protocol, unsigned short port)
  1694 +int svc_makesock(struct svc_serv *serv, int protocol, unsigned short port)
1689 1695 {
1690   - struct sockaddr_in sin;
  1696 + struct sockaddr_in sin = {
  1697 + .sin_family = AF_INET,
  1698 + .sin_addr.s_addr = INADDR_ANY,
  1699 + .sin_port = htons(port),
  1700 + };
1691 1701  
1692 1702 dprintk("svc: creating socket proto = %d\n", protocol);
1693   - sin.sin_family = AF_INET;
1694   - sin.sin_addr.s_addr = INADDR_ANY;
1695   - sin.sin_port = htons(port);
1696   - return svc_create_socket(serv, protocol, &sin);
  1703 + return svc_create_socket(serv, protocol, &sin, SVC_SOCK_DEFAULTS);
1697 1704 }
1698 1705  
1699 1706 /*