libnfs.a: move mnt_{open, close}clnt calls to utils/mount/network.c
authorChuck Lever <chuck.lever@oracle.com>
Sat, 28 Jul 2007 21:50:30 +0000 (17:50 -0400)
committerNeil Brown <neilb@suse.de>
Mon, 30 Jul 2007 06:12:53 +0000 (16:12 +1000)
It turns out that get_socket() accesses a global variable, "verbose," that
is only available in the mount command; yet it's in libnfs.a.  This creates
an undocumented API dependency that will bite someone someday.  This
mount-specific functionality doesn't really belong in libnfs.a anyway.

The simplest way to resolve this is to move all of the functions in
support/nfs/conn.c into utils/mount.  network.c seems like the logical
place to put these.  An added benefit is we eventually get to make
get_socket() static.

Let's start with the mnt_{open,close}clnt functions.

Signed-off-by: Chuck Lever <chuck.lever@oracle.com>
Signed-off-by: Neil Brown <neilb@suse.de>
support/include/conn.h
support/nfs/conn.c
utils/mount/network.c
utils/mount/network.h

index 11f16ab..f21c10e 100644 (file)
@@ -18,9 +18,6 @@
 #include <rpc/pmap_prot.h>
 #include <rpc/clnt.h>
 
-#define MNT_SENDBUFSIZE ((u_int)2048)
-#define MNT_RECVBUFSIZE ((u_int)1024)
-
 typedef struct {
        char **hostname;
        struct sockaddr_in saddr;
@@ -36,8 +33,6 @@ int clnt_ping(struct sockaddr_in *, const u_long, const u_long, const u_int,
 u_long nfsvers_to_mnt(const u_long);
 u_long mntvers_to_nfs(const u_long);
 int get_socket(struct sockaddr_in *, u_int, int, int);
-CLIENT * mnt_openclnt(clnt_addr_t *, int *);
-void mnt_closeclnt(CLIENT *, int);
 
 #endif /* _CONN_H */
 
index 9b98682..cf080c2 100644 (file)
@@ -190,51 +190,3 @@ clnt_ping(struct sockaddr_in *saddr, const u_long prog, const u_long vers,
        else
                return 0;
 }
-
-CLIENT *mnt_openclnt(clnt_addr_t *mnt_server, int *msock)
-{
-       struct sockaddr_in *mnt_saddr = &mnt_server->saddr;
-       struct pmap *mnt_pmap = &mnt_server->pmap;
-       CLIENT *clnt = NULL;
-
-       /* contact the mount daemon via TCP */
-       mnt_saddr->sin_port = htons((u_short)mnt_pmap->pm_port);
-       *msock = get_socket(mnt_saddr, mnt_pmap->pm_prot, TRUE, FALSE);
-       if (*msock == RPC_ANYSOCK) {
-               if (rpc_createerr.cf_error.re_errno == EADDRINUSE)
-                       /* Probably in-use by a TIME_WAIT connection,
-                        * It is worth waiting a while and trying again.
-                        */
-                       rpc_createerr.cf_stat = RPC_TIMEDOUT;
-               return NULL;
-       }
-
-       switch (mnt_pmap->pm_prot) {
-       case IPPROTO_UDP:
-               clnt = clntudp_bufcreate(mnt_saddr,
-                                        mnt_pmap->pm_prog, mnt_pmap->pm_vers,
-                                        RETRY_TIMEOUT, msock,
-                                        MNT_SENDBUFSIZE, MNT_RECVBUFSIZE);
-               break;
-       case IPPROTO_TCP:
-               clnt = clnttcp_create(mnt_saddr,
-                                     mnt_pmap->pm_prog, mnt_pmap->pm_vers,
-                                     msock,
-                                     MNT_SENDBUFSIZE, MNT_RECVBUFSIZE);
-               break;
-       }
-       if (clnt) {
-               /* try to mount hostname:dirname */
-               clnt->cl_auth = authunix_create_default();
-               return clnt;
-       }
-       return NULL;
-}
-
-void mnt_closeclnt(CLIENT *clnt, int msock)
-{
-       auth_destroy(clnt->cl_auth);
-       clnt_destroy(clnt);
-       close(msock);
-}
-
index c997c4c..08b1f99 100644 (file)
@@ -429,3 +429,50 @@ int nfs_call_umount(clnt_addr_t *mnt_server, dirpath *argp)
                return 1;
        return 0;
 }
+
+CLIENT *mnt_openclnt(clnt_addr_t *mnt_server, int *msock)
+{
+       struct sockaddr_in *mnt_saddr = &mnt_server->saddr;
+       struct pmap *mnt_pmap = &mnt_server->pmap;
+       CLIENT *clnt = NULL;
+
+       mnt_saddr->sin_port = htons((u_short)mnt_pmap->pm_port);
+       *msock = get_socket(mnt_saddr, mnt_pmap->pm_prot, TRUE, FALSE);
+       if (*msock == RPC_ANYSOCK) {
+               if (rpc_createerr.cf_error.re_errno == EADDRINUSE)
+                       /*
+                        * Probably in-use by a TIME_WAIT connection,
+                        * It is worth waiting a while and trying again.
+                        */
+                       rpc_createerr.cf_stat = RPC_TIMEDOUT;
+               return NULL;
+       }
+
+       switch (mnt_pmap->pm_prot) {
+       case IPPROTO_UDP:
+               clnt = clntudp_bufcreate(mnt_saddr,
+                                        mnt_pmap->pm_prog, mnt_pmap->pm_vers,
+                                        RETRY_TIMEOUT, msock,
+                                        MNT_SENDBUFSIZE, MNT_RECVBUFSIZE);
+               break;
+       case IPPROTO_TCP:
+               clnt = clnttcp_create(mnt_saddr,
+                                     mnt_pmap->pm_prog, mnt_pmap->pm_vers,
+                                     msock,
+                                     MNT_SENDBUFSIZE, MNT_RECVBUFSIZE);
+               break;
+       }
+       if (clnt) {
+               /* try to mount hostname:dirname */
+               clnt->cl_auth = authunix_create_default();
+               return clnt;
+       }
+       return NULL;
+}
+
+void mnt_closeclnt(CLIENT *clnt, int msock)
+{
+       auth_destroy(clnt->cl_auth);
+       clnt_destroy(clnt);
+       close(msock);
+}
index 83375f0..81a59da 100644 (file)
 #include "conn.h"
 #include "mount.h"
 
+#define MNT_SENDBUFSIZE (2048U)
+#define MNT_RECVBUFSIZE (1024U)
+
 int probe_bothports(clnt_addr_t *, clnt_addr_t *);
 int nfs_gethostbyname(const char *, struct sockaddr_in *);
 int nfs_call_umount(clnt_addr_t *, dirpath *);
 
 int start_statd(void);
+
+CLIENT *mnt_openclnt(clnt_addr_t *, int *);
+void mnt_closeclnt(CLIENT *, int);