Linux NFS development
 help / color / mirror / Atom feed
From: Chuck Lever <chuck.lever@oracle.com>
To: steved@redhat.com
Cc: linux-nfs@vger.kernel.org
Subject: [PATCH 4/6] showmount command: remove legacy RPC logic
Date: Fri, 27 Feb 2009 15:05:29 -0500	[thread overview]
Message-ID: <20090227200529.11301.88197.stgit@ingres.1015granger.net> (raw)
In-Reply-To: <20090227200511.11301.33720.stgit-07a7zB5ZJzbwdl/1UfZZQIVfYA8g3rJ/@public.gmane.org>

Turns out both legacy RPC and TI-RPC have a clnt_create(3) API.  So there's
really no need to keep the old open-coded transport logic around.

Signed-off-by: Chuck Lever <chuck.lever@oracle.com>
---

 utils/showmount/showmount.c |  141 -------------------------------------------
 1 files changed, 0 insertions(+), 141 deletions(-)

diff --git a/utils/showmount/showmount.c b/utils/showmount/showmount.c
index 2695c51..418e8b9 100644
--- a/utils/showmount/showmount.c
+++ b/utils/showmount/showmount.c
@@ -78,8 +78,6 @@ static void usage(FILE *fp, int n)
 	exit(n);
 }
 
-#ifdef HAVE_CLNT_CREATE
-
 static const char *nfs_sm_pgmtbl[] = {
 	"showmount",
 	"mount",
@@ -110,145 +108,6 @@ static CLIENT *nfs_get_mount_client(const char *hostname)
 	exit(1);
 }
 
-#else	/* HAVE_CLNT_CREATE */
-
-/*
- *  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).
- *
- *  Returns zero on success; otherwise, -1 is returned and errno is set
- *  to reflect the nature of the error.
- */
-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 = -1;
-		goto done;
-	}
-
-	if (ret == 0)
-		goto done;
-
-	/* now wait */
-	FD_ZERO(&rset);
-	FD_SET(fd, &rset);
-
-	ret = select(fd + 1, NULL, &rset, NULL, tout);
-	if (ret <= 0) {
-		if (ret == 0)
-			errno = ETIMEDOUT;
-		ret = -1;
-		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 = -1;
-			goto done;
-		}
-
-		/* Oops - something wrong with connect */
-		if (ret != 0) {
-			errno = ret;
-			ret = -1;
-		}
-	}
-
-done:
-	fcntl(fd, F_SETFL, flags);
-	return ret;
-}
-
-/*
- * Generate an RPC client handle connected to the mountd service
- * at @hostname, or die trying.
- *
- * Supports only AF_INET server addresses.
- */
-static CLIENT *nfs_get_mount_client(const char *hostname)
-{
-	struct hostent *hp;
-	struct sockaddr_in server_addr;
-	struct timeval pertry_timeout;
-	CLIENT *mclient = NULL;
-	int ret, msock;
-
-	if (inet_aton(hostname, &server_addr.sin_addr)) {
-		server_addr.sin_family = AF_INET;
-	}
-	else {
-		if ((hp = gethostbyname(hostname)) == NULL) {
-			fprintf(stderr, "%s: can't get address for %s\n",
-				program_name, hostname);
-			exit(1);
-		}
-		server_addr.sin_family = AF_INET;
-		memcpy(&server_addr.sin_addr, hp->h_addr, hp->h_length);
-	}
-
-	msock = socket(PF_INET, SOCK_STREAM, IPPROTO_TCP);
-	if (msock != -1) {
-		if (nfs_getport_ping((struct sockaddr *)&server_addr,
-					sizeof(server_addr), MOUNTPROG,
-					MOUNTVERS, IPPROTO_TCP)) {
-			ret = connect_nb(msock, &server_addr, 0);
-			if (ret == 0)
-				mclient = clnttcp_create(&server_addr,
-						MOUNTPROG, MOUNTVERS, &msock,
-						0, 0);
-			else
-				close(msock);
-		} else
-			close(msock);
-	}
-
-	if (!mclient) {
-		if (nfs_getport_ping((struct sockaddr *)&server_addr,
-					sizeof(server_addr), MOUNTPROG,
-					MOUNTVERS, IPPROTO_UDP)) {
-			clnt_pcreateerror("showmount");
-			exit(1);
-		}
-		msock = RPC_ANYSOCK;
-		pertry_timeout.tv_sec = TIMEOUT_UDP;
-		pertry_timeout.tv_usec = 0;
-		if ((mclient = clntudp_create(&server_addr,
-		    MOUNTPROG, MOUNTVERS, pertry_timeout, &msock)) == NULL) {
-			clnt_pcreateerror("mount clntudp_create");
-			exit(1);
-		}
-	}
-
-	return mclient;
-}
-
-#endif	/* HAVE_CLNT_CREATE */
-
 int main(int argc, char **argv)
 {
 	char hostname_buf[MAXHOSTLEN];


  parent reply	other threads:[~2009-02-27 20:06 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-02-27 20:05 [PATCH 1/6] mount: Fix a bug in the legacy version of nfs_name_to_address() Chuck Lever
     [not found] ` <20090227200511.11301.33720.stgit-07a7zB5ZJzbwdl/1UfZZQIVfYA8g3rJ/@public.gmane.org>
2009-02-27 20:05   ` [PATCH 2/6] nfs(5): document new [no]resvport option Chuck Lever
2009-02-27 20:05   ` [PATCH 3/6] " Chuck Lever
2009-02-27 20:05   ` Chuck Lever [this message]
2009-02-27 20:05   ` [PATCH 5/6] nfs-utils: Remove fprintf() call from support/nfs/getport.c Chuck Lever
2009-02-27 20:05   ` [PATCH 6/6] configure: fix AC_CACHE_VAL warnings on Fedora 10 Chuck Lever
2009-03-04 22:59   ` [PATCH 1/6] mount: Fix a bug in the legacy version of nfs_name_to_address() Steve Dickson

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=20090227200529.11301.88197.stgit@ingres.1015granger.net \
    --to=chuck.lever@oracle.com \
    --cc=linux-nfs@vger.kernel.org \
    --cc=steved@redhat.com \
    /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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox