nfs-utils - showmount RPC timeout handling
Subsystems (2)
Hi all,
I've been doing some work on showmount to try and work out why it can take a long time to return when a non-existent server is specified.
Quoted 1 line
From what I can see showmount itself tries to use a short timeout but
the RPC clnttcp_create and clntudp_create calls will call portmap internally to get the port to use if it is set to 0 in the passed address structure. The above calls then use the internal timeouts, basically 60 seconds, which slows things down. Also the for tcp a blocking connect is used which can take quite a while to timeout as well.
showmount tries tcp then udp so a fail can go through several lengthy waits before failing.
Another thing I noticed in showmount is that RPC procedure calls don't use a call to the service null procedure before performing the call itself. This is not required but can sometimes return a fail somewhat more quickly than just going ahead and calling the procedure entry point straight away.
I've grabbed some of the autofs code and put together a patch to allow specification of the timeouts for the portmap getport and to implement a non-blocking connect.
I'd like feedback on the patch as to it's suitability for inclusion in nfs-utils or what other work may be needed and mistakes that I may have made.
Ian
---
utils/showmount/showmount.c renamed from utils/showmount/showmount.c.reduce-timeout +215 -8
@@ -19,6 +19,7 @@#include <stdio.h> #include <rpc/rpc.h> +#include <rpc/pmap_prot.h> #include <sys/socket.h> #include <netinet/in.h> #include <sys/time.h>
@@ -27,6 +28,7 @@#include <unistd.h> #include <memory.h> #include <stdlib.h> +#include <fcntl.h> #include <netdb.h> #include <arpa/inet.h>
@@ -35,6 +37,10 @@#include <mount.h> #include <unistd.h> +#define TOUT_UDP 3 +#define TOUT_TCP 10 +#define TOT_TOUT 20 +static char * version ="showmount for " VERSION ;static char * program_name;static int headers =1 ;
@@ -73,6 +79,180 @@exit (n); } +/* +* Perform a non-blocking connect on the socket fd. +* +* tout contains the timeout. It will be modified to contain the time +* remaining (i.e. time provided - time elasped). +*/ +static int connect_nb (int fd,struct sockaddr_in *addr,struct timeval *tout) +{ +int flags, ret; +socklen_t len; +fd_set wset, rset; + + flags =fcntl (fd,F_GETFL ,0 ); +if (flags <0 ) +return -1 ; + + ret =fcntl (fd,F_SETFL , flags |O_NONBLOCK ); +if (ret <0 ) +return -1 ; + +/* +* From here on subsequent sys calls could change errno so +* we set ret = -errno to capture it in case we decide to +* use it later. +*/ + len =sizeof (struct sockaddr ); + ret =connect (fd, (struct sockaddr *)addr, len); +if (ret <0 && errno !=EINPROGRESS ) { + ret = -errno; + goto done; + } + +if (ret ==0 ) + goto done; + +/* now wait */ +FD_ZERO (&rset); +FD_SET (fd, &rset); + wset = rset; + + ret =select (fd +1 , &rset, &wset,NULL , tout); +if (ret <=0 ) { +if (ret ==0 ) + ret = -ETIMEDOUT ; +else + ret = -errno; + goto done; + } + +if (FD_ISSET (fd, &rset) ||FD_ISSET (fd, &wset)) { +int status; + + len =sizeof (ret); + status =getsockopt (fd,SOL_SOCKET ,SO_ERROR , &ret, &len); +if (status <0 ) { + ret = -errno; + goto done; + } + +/* Oops - something wrong with connect */ +if (ret) + ret = -ret; + } + +done: +fcntl (fd,F_SETFL , flags); +return ret; +} + +static unsigned short getport (struct sockaddr_in *addr, +unsigned long prog,unsigned long vers,int prot) +{ +CLIENT *client; +enum clnt_stat status; +struct pmap parms; +int ret, sock; +struct sockaddr_in laddr, saddr; +struct timeval tout = {0 ,0 }; +socklen_t len; +unsigned int send_sz =0 ; +unsigned int recv_sz =0 ; +unsigned short port; + +memset (&laddr,0 ,sizeof (laddr)); +memset (&saddr,0 ,sizeof (saddr)); +memset (&parms,0 ,sizeof (parms)); + +memcpy (&saddr, addr,sizeof (saddr)); + saddr.sin_port =htons (PMAPPORT ); + +if (prot ==IPPROTO_TCP ) { + sock =socket (PF_INET ,SOCK_STREAM ,IPPROTO_TCP ); +if (sock ==-1 ) { + rpc_createerr.cf_stat =RPC_SYSTEMERROR ; + rpc_createerr.cf_error.re_errno = errno; +return 0 ; + } + + tout.tv_sec =TOUT_TCP ; + + ret =connect_nb (sock, &saddr, &tout); +if (ret ==-1 ) { +close (sock); + rpc_createerr.cf_stat =RPC_SYSTEMERROR ; + rpc_createerr.cf_error.re_errno = errno; +return 0 ; + } + }else { +/* +* bind to any unused port. If we left this up to the rpc +* layer, it would bind to a reserved port, which has been shown +* to exhaust the reserved port range in some situations. +*/ + sock =socket (PF_INET ,SOCK_DGRAM ,IPPROTO_UDP ); +if (sock ==-1 ) { + rpc_createerr.cf_stat =RPC_SYSTEMERROR ; + rpc_createerr.cf_error.re_errno = errno; +return 0 ; + } + + laddr.sin_family =AF_INET ; + laddr.sin_port =0 ; + laddr.sin_addr.s_addr =htonl (INADDR_ANY ); + + tout.tv_sec =TOUT_UDP ; + + send_sz =RPCSMALLMSGSIZE ; + recv_sz =RPCSMALLMSGSIZE ; + + len =sizeof (struct sockaddr_in ); +if (bind (sock, (struct sockaddr *)&laddr, len) <0 ) { +close (sock); + sock =RPC_ANYSOCK ; +/* FALLTHROUGH */ + } + } + + client =clntudp_bufcreate (&saddr,PMAPPROG ,PMAPVERS , + tout, &sock, send_sz, recv_sz); +if (!client) { +close (sock); + rpc_createerr.cf_stat =RPC_RPCBFAILURE ; +return 0 ; + } + +clnt_control (client,CLSET_FD_CLOSE ,NULL ); + + status =clnt_call (client,PMAPPROC_NULL , + (xdrproc_t ) xdr_void,0 , (xdrproc_t ) xdr_void,0 , tout); + +if (status ==RPC_SUCCESS ) { + parms.pm_prog = prog; + parms.pm_vers = vers; + parms.pm_prot = prot; + + status =clnt_call (client,PMAPPROC_GETPORT , + (xdrproc_t ) xdr_pmap, (caddr_t) &parms, + (xdrproc_t ) xdr_u_short, (caddr_t) &port, + tout); + } + + +if (status !=RPC_SUCCESS ) { +clnt_geterr (client, &rpc_createerr.cf_error); + rpc_createerr.cf_stat = status; +clnt_destroy (client); +return 0 ; + } + +clnt_destroy (client); + +return htons (port); +} + int main(argc, argv) int argc; char **argv;
@@ -82,7 +262,7 @@enum clnt_stat clnt_stat;struct hostent *hp;struct sockaddr_in server_addr; -int msock; +int ret, msock;struct timeval total_timeout;struct timeval pertry_timeout;int c;
@@ -171,13 +351,32 @@/* create mount deamon client */ - server_addr.sin_port =0 ; - msock =RPC_ANYSOCK ; -if ((mclient =clnttcp_create (&server_addr, -MOUNTPROG ,MOUNTVERS , &msock,0 ,0 )) ==NULL ) { - server_addr.sin_port =0 ; + mclient =NULL ; + msock =socket (PF_INET ,SOCK_STREAM ,IPPROTO_TCP ); +if (msock !=-1 ) { + server_addr.sin_port =getport (&server_addr, +MOUNTPROG ,MOUNTVERS ,IPPROTO_TCP ); +if (server_addr.sin_port) { + ret =connect_nb (msock, &server_addr,0 ); +if (ret !=-1 ) + mclient =clnttcp_create (&server_addr, +MOUNTPROG ,MOUNTVERS , &msock, +0 ,0 ); +else +close (msock); + }else +close (msock); + } + +if (!mclient) { + server_addr.sin_port =getport (&server_addr, +MOUNTPROG ,MOUNTVERS ,IPPROTO_UDP ); +if (!server_addr.sin_port) { +clnt_pcreateerror ("portmap getport" ); +exit (1 ); + } msock =RPC_ANYSOCK ; - pertry_timeout.tv_sec =3 ; + pertry_timeout.tv_sec =TOUT_UDP ; pertry_timeout.tv_usec =0 ;if ((mclient =clntudp_create (&server_addr,MOUNTPROG ,MOUNTVERS , pertry_timeout, &msock)) ==NULL ) {
@@ -186,11 +385,19 @@ } } mclient->cl_auth =authunix_create_default (); - total_timeout.tv_sec =20 ; + total_timeout.tv_sec =TOT_TOUT ; total_timeout.tv_usec =0 ;if (eflag) {memset (&exportlist,'\0' ,sizeof (exportlist)); + + clnt_stat =clnt_call (mclient,MOUNTPROC_NULL , + (xdrproc_t ) xdr_void,NULL , (xdrproc_t ) xdr_void, +NULL , total_timeout); +if (clnt_stat !=RPC_SUCCESS ) { +clnt_perror (mclient,"rpc mount null" ); +exit (1 ); + } clnt_stat = clnt_call(mclient, MOUNTPROC_EXPORT, (xdrproc_t) xdr_void, NULL, (xdrproc_t) xdr_exports, (caddr_t) &exportlist,
-------------------------------------------------------------------------
Take Surveys. Earn Cash. Influence the Future of IT
Join SourceForge.net's Techsay panel and you'll get the chance to share your opinions on IT & business topics through brief surveys - and earn cash
http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV
_______________________________________________
NFS maillist - [email protected]
https://lists.sourceforge.net/lists/listinfo/nfs
Quoted 14 lines · On Tuesday December 19, [email protected] wrote:
Hi all,
I've been doing some work on showmount to try and work out why it can take a long time to return when a non-existent server is specified.
Quoted 1 line
From what I can see showmount itself tries to use a short timeout but
the RPC
clnttcp_createandclntudp_createcalls will call portmap internally to get the port to use if it is set to 0 in the passed address structure. The above calls then use the internal timeouts, basically 60 seconds, which slows things down. Also the for tcp a blocking connect is used which can take quite a while to timeout as well.
Quoted 8 lines
showmount tries tcp then udp so a fail can go through several lengthy waits before failing.
Another thing I noticed in showmount is that RPC procedure calls don't use a call to the service null procedure before performing the call itself. This is not required but can sometimes return a fail somewhat more quickly than just going ahead and calling the procedure entry point straight away.
I don't get this. How can a call to NULL fail more quickly? It should always succeed or timeout, and it presumably has the same timeout so....???
What might make sense is to call NULL with a short time out and if that succeeds, call the real proceedure with a longer timeout (because it might take a longer time).
Quoted 8 lines
I've grabbed some of the autofs code and put together a patch to allow specification of the timeouts for the portmap getport and to implement a non-blocking connect.
I'd like feedback on the patch as to it's suitability for inclusion in nfs-utils or what other work may be needed and mistakes that I may have made.
Mostly good. See below.
Quoted 7 lines
Ian
---
utils/showmount/showmount.c line 43
Quoted 7 lines
utils/showmount/showmount.c renamed from utils/showmount/showmount.c.reduce-timeout +4
-0@@ -35,6 +37,10 @@#include <mount.h> #include <unistd.h> +#define TOUT_UDP 3 +#define TOUT_TCP 10 +#define TOT_TOUT 20 +
I guess you mean TIMEOUT_UDP TIMEOUT_TCP and TOTAL_TIMEOUT. Bits are cheap, and editors auto-complete. Can we have full names please ??
Quoted 11 lines
utils/showmount/showmount.c renamed from utils/showmount/showmount.c.reduce-timeout +11
-0+/* +* Perform a non-blocking connect on the socket fd. +* +* tout contains the timeout. It will be modified to contain the time +* remaining (i.e. time provided - time elasped). +*/ +static int connect_nb (int fd,struct sockaddr_in *addr,struct timeval *tout) +{ +int flags, ret; +socklen_t len; +fd_set wset, rset;
....
utils/showmount/showmount.c line 122
Quoted 7 lines
utils/showmount/showmount.c renamed from utils/showmount/showmount.c.reduce-timeout +7
-0+ +/* now wait */ +FD_ZERO (&rset); +FD_SET (fd, &rset); + wset = rset; + + ret =select (fd +1 , &rset, &wset,NULL , tout);
Do we need wset as well as rset? I thought a connection socket would always signal in rset, so wset is redundant. I'm will to be educated though.
Quoted 4 lines
utils/showmount/showmount.c renamed from utils/showmount/showmount.c.reduce-timeout +4
-0+ +static unsigned short getport (struct sockaddr_in *addr, +unsigned long prog,unsigned long vers,int prot) +{
....
utils/showmount/showmount.c line 212
Quoted 12 lines
utils/showmount/showmount.c renamed from utils/showmount/showmount.c.reduce-timeout +12
-0+ + laddr.sin_family =AF_INET ; + laddr.sin_port =0 ; + laddr.sin_addr.s_addr =htonl (INADDR_ANY ); + + tout.tv_sec =TOUT_UDP ; + + send_sz =RPCSMALLMSGSIZE ; + recv_sz =RPCSMALLMSGSIZE ; + + len =sizeof (struct sockaddr_in ); +if (bind (sock, (struct sockaddr *)&laddr, len) <0 ) {
Isn't this bind a no-op? When you first write to a socket which is unbound it is automatically bound, so you don't need to pre-bind it.
Apart from those small things, it is probably fine. Thanks!
NeilBrown
-------------------------------------------------------------------------
Take Surveys. Earn Cash. Influence the Future of IT
Join SourceForge.net's Techsay panel and you'll get the chance to share your opinions on IT & business topics through brief surveys - and earn cash
http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV
_______________________________________________
NFS maillist - [email protected]
https://lists.sourceforge.net/lists/listinfo/nfs
Quoted 24 lines · Neil Brown
Quoted 14 lines · On Tuesday December 19, [email protected] wrote:
Hi all,
I've been doing some work on showmount to try and work out why it can take a long time to return when a non-existent server is specified.
Quoted 1 line
From what I can see showmount itself tries to use a short timeout but
the RPC
clnttcp_createandclntudp_createcalls will call portmap internally to get the port to use if it is set to 0 in the passed address structure. The above calls then use the internal timeouts, basically 60 seconds, which slows things down. Also the for tcp a blocking connect is used which can take quite a while to timeout as well.Quoted 8 lines
showmount tries tcp then udp so a fail can go through several lengthy waits before failing.
Another thing I noticed in showmount is that RPC procedure calls don't use a call to the service null procedure before performing the call itself. This is not required but can sometimes return a fail somewhat more quickly than just going ahead and calling the procedure entry point straight away.
Quoted 3 lines
I don't get this. How can a call to NULL fail more quickly? It should always succeed or timeout, and it presumably has the same timeout so....???
I've certainly thought the same thing but had this impression from past experience, which may well be mistaken.
Quoted 3 lines
What might make sense is to call NULL with a short time out and if that succeeds, call the real proceedure with a longer timeout (because it might take a longer time).
Think that might be a bit dangerous as if a valid response could come back after the short timeout (which is already short for showmount) we might abandon the request in error.
I'll get rig of the NULL calls and re-test.
Quoted 22 lines
Quoted 9 lines
I've grabbed some of the autofs code and put together a patch to allow specification of the timeouts for the portmap getport and to implement a non-blocking connect.
I'd like feedback on the patch as to it's suitability for inclusion in nfs-utils or what other work may be needed and mistakes that I may have made.
Mostly good. See below.
Quoted 10 lines
Ian
---
utils/showmount/showmount.c renamed from utils/showmount/showmount.c.reduce-timeout +0
-0@@ -35,6 +37,10 @@#include <mount.h> #include <unistd.h>
Quoted 8 lines
utils/showmount/showmount.c line 43
Quoted 4 lines
utils/showmount/showmount.c renamed from utils/showmount/showmount.c.reduce-timeout +4
-0+#define TOUT_UDP 3 +#define TOUT_TCP 10 +#define TOT_TOUT 20 +I guess you mean
TIMEOUT_UDPTIMEOUT_TCPandTOTAL_TIMEOUT. Bits are cheap, and editors auto-complete. Can we have full names please ??
Will do.
Quoted 13 lines
Quoted 12 lines
utils/showmount/showmount.c renamed from utils/showmount/showmount.c.reduce-timeout +11
-0+/* +* Perform a non-blocking connect on the socket fd. +* +* tout contains the timeout. It will be modified to contain the time +* remaining (i.e. time provided - time elasped). +*/ +static int connect_nb (int fd,struct sockaddr_in *addr,struct timeval *tout) +{ +int flags, ret; +socklen_t len; +fd_set wset, rset;....
Quoted 11 lines
utils/showmount/showmount.c line 122
Quoted 7 lines
utils/showmount/showmount.c renamed from utils/showmount/showmount.c.reduce-timeout +7
-0+ +/* now wait */ +FD_ZERO (&rset); +FD_SET (fd, &rset); + wset = rset; + + ret =select (fd +1 , &rset, &wset,NULL , tout);Do we need wset as well as rset? I thought a connection socket would always signal in rset, so wset is redundant. I'm will to be educated though.
Haven't really thought about it.
I'll check and amend as needed.
Quoted 6 lines
Quoted 5 lines
utils/showmount/showmount.c renamed from utils/showmount/showmount.c.reduce-timeout +4
-0+ +static unsigned short getport (struct sockaddr_in *addr, +unsigned long prog,unsigned long vers,int prot) +{....
Quoted 15 lines
utils/showmount/showmount.c line 212
Quoted 12 lines
utils/showmount/showmount.c renamed from utils/showmount/showmount.c.reduce-timeout +12
-0+ + laddr.sin_family =AF_INET ; + laddr.sin_port =0 ; + laddr.sin_addr.s_addr =htonl (INADDR_ANY ); + + tout.tv_sec =TOUT_UDP ; + + send_sz =RPCSMALLMSGSIZE ; + recv_sz =RPCSMALLMSGSIZE ; + + len =sizeof (struct sockaddr_in ); +if (bind (sock, (struct sockaddr *)&laddr, len) <0 ) {Isn't this bind a no-op? When you first write to a socket which is unbound it is automatically bound, so you don't need to pre-bind it.
Possibly, but personally I like to retain stuff like this for internal documentation.
Do you feel strongly about it?
Thanks
Ian
-------------------------------------------------------------------------
Take Surveys. Earn Cash. Influence the Future of IT
Join SourceForge.net's Techsay panel and you'll get the chance to share your opinions on IT & business topics through brief surveys - and earn cash
http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV
_______________________________________________
NFS maillist - [email protected]
https://lists.sourceforge.net/lists/listinfo/nfs
Quoted 8 lines · On Tuesday December 19, [email protected] wrote:
Quoted 3 lines
Isn't this bind a no-op? When you first write to a socket which is unbound it is automatically bound, so you don't need to pre-bind it.
Possibly, but personally I like to retain stuff like this for internal documentation.
Do you feel strongly about it?
No. It just seemed like "that's a lot of new code for relatively little new functionality, I wonder if it is all needed", and I discovered some that wasn't.
But if you think it is good to keep it, I'm OK with that.
I'll look forward to your next revision which I'm sure will be accepted.
NeilBrown
-------------------------------------------------------------------------
Take Surveys. Earn Cash. Influence the Future of IT
Join SourceForge.net's Techsay panel and you'll get the chance to share your opinions on IT & business topics through brief surveys - and earn cash
http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV
_______________________________________________
NFS maillist - [email protected]
https://lists.sourceforge.net/lists/listinfo/nfs
Re: [RFC:PATCH] nfs-utils - showmount RPC timeout handling - second attempt
In reply to Neil BrownQuoted 24 lines · Neil Brown
Quoted 14 lines · On Tuesday December 19, [email protected] wrote:
Hi all,
I've been doing some work on showmount to try and work out why it can take a long time to return when a non-existent server is specified.
Quoted 1 line
From what I can see showmount itself tries to use a short timeout but
the RPC
clnttcp_createandclntudp_createcalls will call portmap internally to get the port to use if it is set to 0 in the passed address structure. The above calls then use the internal timeouts, basically 60 seconds, which slows things down. Also the for tcp a blocking connect is used which can take quite a while to timeout as well.Quoted 8 lines
showmount tries tcp then udp so a fail can go through several lengthy waits before failing.
Another thing I noticed in showmount is that RPC procedure calls don't use a call to the service null procedure before performing the call itself. This is not required but can sometimes return a fail somewhat more quickly than just going ahead and calling the procedure entry point straight away.
Quoted 12 lines
I don't get this. How can a call to NULL fail more quickly? It should always succeed or timeout, and it presumably has the same timeout so....???
What might make sense is to call NULL with a short time out and if that succeeds, call the real proceedure with a longer timeout (because it might take a longer time).Quoted 5 lines
I've grabbed some of the autofs code and put together a patch to allow specification of the timeouts for the portmap getport and to implement a non-blocking connect.
I've made the changes suggested.
Removing the NULL PROC calls had no adverse affect on timing that I could tell. My thoughts on that must have been due to some confusion in the past. That's good.
I still like the bind so I've left in in but ultimately it's up to you to decide whether to include it.
Anything else, anything I missed?
Ian
---
utils/showmount/showmount.c renamed from utils/showmount/showmount.c.reduce-timeout +201 -8
@@ -19,6 +19,7 @@#include <stdio.h> #include <rpc/rpc.h> +#include <rpc/pmap_prot.h> #include <sys/socket.h> #include <netinet/in.h> #include <sys/time.h>
@@ -27,6 +28,7 @@#include <unistd.h> #include <memory.h> #include <stdlib.h> +#include <fcntl.h> #include <netdb.h> #include <arpa/inet.h>
@@ -35,6 +37,10 @@#include <mount.h> #include <unistd.h> +#define TIMEOUT_UDP 3 +#define TIMEOUT_TCP 10 +#define TOTAL_TIMEOUT 20 +static char * version ="showmount for " VERSION ;static char * program_name;static int headers =1 ;
@@ -73,6 +79,173 @@exit (n); } +/* +* Perform a non-blocking connect on the socket fd. +* +* tout contains the timeout. It will be modified to contain the time +* remaining (i.e. time provided - time elasped). +*/ +static int connect_nb (int fd,struct sockaddr_in *addr,struct timeval *tout) +{ +int flags, ret; +socklen_t len; +fd_set rset; + + flags =fcntl (fd,F_GETFL ,0 ); +if (flags <0 ) +return -1 ; + + ret =fcntl (fd,F_SETFL , flags |O_NONBLOCK ); +if (ret <0 ) +return -1 ; + +/* +* From here on subsequent sys calls could change errno so +* we set ret = -errno to capture it in case we decide to +* use it later. +*/ + len =sizeof (struct sockaddr ); + ret =connect (fd, (struct sockaddr *)addr, len); +if (ret <0 && errno !=EINPROGRESS ) { + ret = -errno; + goto done; + } + +if (ret ==0 ) + goto done; + +/* now wait */ +FD_ZERO (&rset); +FD_SET (fd, &rset); + + ret =select (fd +1 , &rset,NULL ,NULL , tout); +if (ret <=0 ) { +if (ret ==0 ) + ret = -ETIMEDOUT ; +else + ret = -errno; + goto done; + } + +if (FD_ISSET (fd, &rset)) { +int status; + + len =sizeof (ret); + status =getsockopt (fd,SOL_SOCKET ,SO_ERROR , &ret, &len); +if (status <0 ) { + ret = -errno; + goto done; + } + +/* Oops - something wrong with connect */ +if (ret) + ret = -ret; + } + +done: +fcntl (fd,F_SETFL , flags); +return ret; +} + +static unsigned short getport (struct sockaddr_in *addr, +unsigned long prog,unsigned long vers,int prot) +{ +CLIENT *client; +enum clnt_stat status; +struct pmap parms; +int ret, sock; +struct sockaddr_in laddr, saddr; +struct timeval tout = {0 ,0 }; +socklen_t len; +unsigned int send_sz =0 ; +unsigned int recv_sz =0 ; +unsigned short port; + +memset (&laddr,0 ,sizeof (laddr)); +memset (&saddr,0 ,sizeof (saddr)); +memset (&parms,0 ,sizeof (parms)); + +memcpy (&saddr, addr,sizeof (saddr)); + saddr.sin_port =htons (PMAPPORT ); + +if (prot ==IPPROTO_TCP ) { + sock =socket (PF_INET ,SOCK_STREAM ,IPPROTO_TCP ); +if (sock ==-1 ) { + rpc_createerr.cf_stat =RPC_SYSTEMERROR ; + rpc_createerr.cf_error.re_errno = errno; +return 0 ; + } + + tout.tv_sec =TIMEOUT_TCP ; + + ret =connect_nb (sock, &saddr, &tout); +if (ret ==-1 ) { +close (sock); + rpc_createerr.cf_stat =RPC_SYSTEMERROR ; + rpc_createerr.cf_error.re_errno = errno; +return 0 ; + } + }else { +/* +* bind to any unused port. If we left this up to the rpc +* layer, it would bind to a reserved port, which has been shown +* to exhaust the reserved port range in some situations. +*/ + sock =socket (PF_INET ,SOCK_DGRAM ,IPPROTO_UDP ); +if (sock ==-1 ) { + rpc_createerr.cf_stat =RPC_SYSTEMERROR ; + rpc_createerr.cf_error.re_errno = errno; +return 0 ; + } + + laddr.sin_family =AF_INET ; + laddr.sin_port =0 ; + laddr.sin_addr.s_addr =htonl (INADDR_ANY ); + + tout.tv_sec =TIMEOUT_UDP ; + + send_sz =RPCSMALLMSGSIZE ; + recv_sz =RPCSMALLMSGSIZE ; + + len =sizeof (struct sockaddr_in ); +if (bind (sock, (struct sockaddr *)&laddr, len) <0 ) { +close (sock); + sock =RPC_ANYSOCK ; +/* FALLTHROUGH */ + } + } + + client =clntudp_bufcreate (&saddr,PMAPPROG ,PMAPVERS , + tout, &sock, send_sz, recv_sz); +if (!client) { +close (sock); + rpc_createerr.cf_stat =RPC_RPCBFAILURE ; +return 0 ; + } + +clnt_control (client,CLSET_FD_CLOSE ,NULL ); + + parms.pm_prog = prog; + parms.pm_vers = vers; + parms.pm_prot = prot; + + status =clnt_call (client,PMAPPROC_GETPORT , + (xdrproc_t ) xdr_pmap, (caddr_t) &parms, + (xdrproc_t ) xdr_u_short, (caddr_t) &port, + tout); + +if (status !=RPC_SUCCESS ) { +clnt_geterr (client, &rpc_createerr.cf_error); + rpc_createerr.cf_stat = status; +clnt_destroy (client); +return 0 ; + } + +clnt_destroy (client); + +return htons (port); +} + int main(argc, argv) int argc; char **argv;
@@ -82,7 +255,7 @@enum clnt_stat clnt_stat;struct hostent *hp;struct sockaddr_in server_addr; -int msock; +int ret, msock;struct timeval total_timeout;struct timeval pertry_timeout;int c;
@@ -171,13 +344,32 @@/* create mount deamon client */ - server_addr.sin_port =0 ; - msock =RPC_ANYSOCK ; -if ((mclient =clnttcp_create (&server_addr, -MOUNTPROG ,MOUNTVERS , &msock,0 ,0 )) ==NULL ) { - server_addr.sin_port =0 ; + mclient =NULL ; + msock =socket (PF_INET ,SOCK_STREAM ,IPPROTO_TCP ); +if (msock !=-1 ) { + server_addr.sin_port =getport (&server_addr, +MOUNTPROG ,MOUNTVERS ,IPPROTO_TCP ); +if (server_addr.sin_port) { + ret =connect_nb (msock, &server_addr,0 ); +if (ret !=-1 ) + mclient =clnttcp_create (&server_addr, +MOUNTPROG ,MOUNTVERS , &msock, +0 ,0 ); +else +close (msock); + }else +close (msock); + } + +if (!mclient) { + server_addr.sin_port =getport (&server_addr, +MOUNTPROG ,MOUNTVERS ,IPPROTO_UDP ); +if (!server_addr.sin_port) { +clnt_pcreateerror ("portmap getport" ); +exit (1 ); + } msock =RPC_ANYSOCK ; - pertry_timeout.tv_sec =3 ; + pertry_timeout.tv_sec =TIMEOUT_UDP ; pertry_timeout.tv_usec =0 ;if ((mclient =clntudp_create (&server_addr,MOUNTPROG ,MOUNTVERS , pertry_timeout, &msock)) ==NULL ) {
@@ -186,11 +378,12 @@ } } mclient->cl_auth =authunix_create_default (); - total_timeout.tv_sec =20 ; + total_timeout.tv_sec =TOTAL_TIMEOUT ; total_timeout.tv_usec =0 ;if (eflag) {memset (&exportlist,'\0' ,sizeof (exportlist)); + clnt_stat = clnt_call(mclient, MOUNTPROC_EXPORT, (xdrproc_t) xdr_void, NULL, (xdrproc_t) xdr_exports, (caddr_t) &exportlist,
-------------------------------------------------------------------------
Take Surveys. Earn Cash. Influence the Future of IT
Join SourceForge.net's Techsay panel and you'll get the chance to share your opinions on IT & business topics through brief surveys - and earn cash
http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV
_______________________________________________
NFS maillist - [email protected]
https://lists.sourceforge.net/lists/listinfo/nfs
Re: [RFC:PATCH] nfs-utils - showmount RPC timeout handling - second attempt
Quoted 3 lines · On Tuesday December 19, [email protected] wrote:
Anything else, anything I missed?
Only a changelog entry... I synthesised one from your original email.
Thanks.
NeilBrown
-------------------------------------------------------------------------
Take Surveys. Earn Cash. Influence the Future of IT
Join SourceForge.net's Techsay panel and you'll get the chance to share your opinions on IT & business topics through brief surveys - and earn cash
http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV
_______________________________________________
NFS maillist - [email protected]
https://lists.sourceforge.net/lists/listinfo/nfs
Re: [RFC:PATCH] nfs-utils - showmount RPC timeout handling - second attempt
In reply to Ian KentQuoted 11 lines · Ian Kent
I've made the changes suggested.
Removing the NULL PROC calls had no adverse affect on timing that I could tell. My thoughts on that must have been due to some confusion in the past. That's good.
I still like the bind so I've left in in but ultimately it's up to you to decide whether to include it.
Anything else, anything I missed?
Something I got wrong.
A bit more testing shows that the write file descriptor is actually needed.
I found that without it select will timeout even when the connection should succeed, not sure why. Anyone?
Ian
---
utils/showmount/showmount.c renamed from utils/showmount/showmount.c.reduce-timeout-2 +3 -2
@@ -89,7 +89,7 @@ {int flags, ret;socklen_t len; -fd_set rset; +fd_set rset, wset; flags =fcntl (fd,F_GETFL ,0 );if (flags <0 )
@@ -117,8 +117,9 @@/* now wait */ FD_ZERO (&rset);FD_SET (fd, &rset); + wset = rset; - ret =select (fd +1 , &rset,NULL ,NULL , tout); + ret =select (fd +1 , &rset, &wset,NULL , tout);if (ret <=0 ) {if (ret ==0 ) ret = -ETIMEDOUT ;
-------------------------------------------------------------------------
Take Surveys. Earn Cash. Influence the Future of IT
Join SourceForge.net's Techsay panel and you'll get the chance to share your opinions on IT & business topics through brief surveys - and earn cash
http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV
_______________________________________________
NFS maillist - [email protected]
https://lists.sourceforge.net/lists/listinfo/nfs
Re: [RFC:PATCH] nfs-utils - showmount RPC timeout handling - second attempt
Quoted 15 lines · Ian Kent
Quoted 11 lines · Ian Kent
I've made the changes suggested.
Removing the NULL PROC calls had no adverse affect on timing that I could tell. My thoughts on that must have been due to some confusion in the past. That's good.
I still like the bind so I've left in in but ultimately it's up to you to decide whether to include it.
Anything else, anything I missed?
Something I got wrong.
Quoted 7 lines
A bit more testing shows that the write file descriptor is actually needed.
I found that without it select will timeout even when the connection should succeed, not sure why. Anyone?
Ian
Oops, I think that last one might have wrap.
Try this one.
---
utils/showmount/showmount.c renamed from utils/showmount/showmount.c.reduce-timeout-2 +3 -2
@@ -89,7 +89,7 @@ {int flags, ret;socklen_t len; -fd_set rset; +fd_set rset, wset; flags =fcntl (fd,F_GETFL ,0 );if (flags <0 )
@@ -117,8 +117,9 @@/* now wait */ FD_ZERO (&rset);FD_SET (fd, &rset); + wset = rset; - ret =select (fd +1 , &rset,NULL ,NULL , tout); + ret =select (fd +1 , &rset, &wset,NULL , tout);if (ret <=0 ) {if (ret ==0 ) ret = -ETIMEDOUT ;
-------------------------------------------------------------------------
Take Surveys. Earn Cash. Influence the Future of IT
Join SourceForge.net's Techsay panel and you'll get the chance to share your opinions on IT & business topics through brief surveys - and earn cash
http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV
_______________________________________________
NFS maillist - [email protected]
https://lists.sourceforge.net/lists/listinfo/nfs