Blame SOURCES/autofs-5.1.7-refactor-get_nfs_info.patch

91594d
autofs-5.1.7 - refactor get_nfs_info()
91594d
91594d
From: Ian Kent <raven@themaw.net>
91594d
91594d
Make getting a portmap client and getting a service port from portmap
91594d
helper functions and simplify the return handling.
91594d
91594d
Signed-off-by: Ian Kent <raven@themaw.net>
91594d
---
91594d
 CHANGELOG            |    1 
91594d
 modules/replicated.c |  135 ++++++++++++++++++++++++++++-----------------------
91594d
 2 files changed, 76 insertions(+), 60 deletions(-)
91594d
91594d
--- autofs-5.1.7.orig/CHANGELOG
91594d
+++ autofs-5.1.7/CHANGELOG
91594d
@@ -97,6 +97,7 @@
91594d
 - remove nonstrict parameter from tree_mapent_umount_offsets().
91594d
 - fix handling of incorrect return from umount_ent().
91594d
 - make NFS version check flags consistent.
91594d
+- refactor get_nfs_info().
91594d
 
91594d
 25/01/2021 autofs-5.1.7
91594d
 - make bind mounts propagation slave by default.
91594d
--- autofs-5.1.7.orig/modules/replicated.c
91594d
+++ autofs-5.1.7/modules/replicated.c
91594d
@@ -223,6 +223,49 @@ void free_host_list(struct host **list)
91594d
 	*list = NULL;
91594d
 }
91594d
 
91594d
+static unsigned int get_portmap_client(unsigned logopt,
91594d
+			struct conn_info *pm_info, struct host *host,
91594d
+			int proto)
91594d
+{
91594d
+	unsigned int status;
91594d
+
91594d
+	/* On success client is stored in pm_info->client */
91594d
+	status = rpc_portmap_getclient(pm_info,
91594d
+			host->name, host->addr, host->addr_len,
91594d
+			proto, RPC_CLOSE_DEFAULT);
91594d
+	if (status == -EHOSTUNREACH)
91594d
+		debug(logopt,
91594d
+		      "host not reachable getting portmap client");
91594d
+	else if (status)
91594d
+		debug(logopt, "error 0x%d getting portmap client");
91594d
+
91594d
+	return status;
91594d
+}
91594d
+
91594d
+static unsigned int get_portmap_port(unsigned logopt,
91594d
+		struct conn_info *pm_info, struct pmap *parms,
91594d
+		unsigned long vers, unsigned int version,
91594d
+		short unsigned int *port)
91594d
+{
91594d
+	unsigned int status;
91594d
+	short unsigned int nfs_port;
91594d
+
91594d
+	parms->pm_vers = vers;
91594d
+	status = rpc_portmap_getport(pm_info, parms, &nfs_port);
91594d
+	if (status == -EHOSTUNREACH || status == -ETIMEDOUT) {
91594d
+		debug(logopt,
91594d
+		      "host not reachable or timed out getting service port");
91594d
+	} else if (status < 0) {
91594d
+		if (!(version & NFS_VERS_MASK))
91594d
+			debug(logopt, "error 0x%d getting service port");
91594d
+	}
91594d
+
91594d
+	if (!status)
91594d
+		*port = nfs_port;
91594d
+
91594d
+	return status;
91594d
+}
91594d
+
91594d
 static unsigned int get_nfs_info(unsigned logopt, struct host *host,
91594d
 			 struct conn_info *pm_info, struct conn_info *rpc_info,
91594d
 			 int proto, unsigned int version, int port)
91594d
@@ -263,33 +306,20 @@ static unsigned int get_nfs_info(unsigne
91594d
 		goto v3_ver;
91594d
 
91594d
 	if (!port) {
91594d
-		status = rpc_portmap_getclient(pm_info,
91594d
-				host->name, host->addr, host->addr_len,
91594d
-				proto, RPC_CLOSE_DEFAULT);
91594d
-		if (status == -EHOSTUNREACH) {
91594d
-			debug(logopt,
91594d
-			      "host not reachable getting portmap client");
91594d
-			supported = status;
91594d
-			goto done_ver;
91594d
-		} else if (status) {
91594d
-			debug(logopt, "error 0x%d getting portmap client");
91594d
+		status = get_portmap_client(logopt, pm_info, host, proto);
91594d
+		if (status) {
91594d
+			if (status == -EHOSTUNREACH)
91594d
+				supported = status;
91594d
 			goto done_ver;
91594d
 		}
91594d
-		parms.pm_vers = NFS4_VERSION;
91594d
-		status = rpc_portmap_getport(pm_info, &parms, &rpc_info->port);
91594d
-		if (status == -EHOSTUNREACH || status == -ETIMEDOUT) {
91594d
-			debug(logopt,
91594d
-			      "host not reachable or timed out getting service port");
91594d
-			supported = status;
91594d
-			goto done_ver;
91594d
-		} else if (status < 0) {
91594d
-			if (version & NFS_VERS_MASK)
91594d
+		status = get_portmap_port(logopt, pm_info, &parms,
91594d
+				NFS4_VERSION, version, &rpc_info->port);
91594d
+		if (status) {
91594d
+			if (status == -EHOSTUNREACH || status == -ETIMEDOUT)
91594d
+				supported = status;
91594d
+			if (status < 0 && version & NFS_VERS_MASK)
91594d
 				goto v3_ver; /* MOUNT_NFS_DEFAULT_PROTOCOL=4 */
91594d
-			else {
91594d
-				debug(logopt,
91594d
-				      "error 0x%d getting service port");
91594d
-				goto done_ver;
91594d
-			}
91594d
+			goto done_ver;
91594d
 		}
91594d
 	}
91594d
 
91594d
@@ -334,31 +364,22 @@ v3_ver:
91594d
 		goto v2_ver;
91594d
 
91594d
 	if (!port && !pm_info->client) {
91594d
-		status = rpc_portmap_getclient(pm_info,
91594d
-				host->name, host->addr, host->addr_len,
91594d
-				proto, RPC_CLOSE_DEFAULT);
91594d
-		if (status == -EHOSTUNREACH) {
91594d
-			debug(logopt,
91594d
-			      "host not reachable getting portmap client");
91594d
-			supported = status;
91594d
-			goto done_ver;
91594d
-		} else if (status) {
91594d
-			debug(logopt,
91594d
-			      "error 0x%d getting getting portmap client");
91594d
+		status = get_portmap_client(logopt, pm_info, host, proto);
91594d
+		if (status) {
91594d
+			if (status == -EHOSTUNREACH)
91594d
+				supported = status;
91594d
 			goto done_ver;
91594d
 		}
91594d
 	}
91594d
 
91594d
 	if (!port) {
91594d
-		parms.pm_vers = NFS3_VERSION;
91594d
-		status = rpc_portmap_getport(pm_info, &parms, &rpc_info->port);
91594d
-		if (status == -EHOSTUNREACH || status == -ETIMEDOUT) {
91594d
-			debug(logopt,
91594d
-			      "host not reachable or timed out getting service port");
91594d
-			supported = status;
91594d
+		status = get_portmap_port(logopt, pm_info, &parms,
91594d
+				NFS3_VERSION, version, &rpc_info->port);
91594d
+		if (status) {
91594d
+			if (status == -EHOSTUNREACH || status == -ETIMEDOUT)
91594d
+				supported = status;
91594d
 			goto done_ver;
91594d
-		} else if (status < 0)
91594d
-			goto v2_ver;
91594d
+		}
91594d
 	}
91594d
 
91594d
 	if (rpc_info->proto == IPPROTO_UDP)
91594d
@@ -399,28 +420,22 @@ v2_ver:
91594d
 		goto done_ver;
91594d
 
91594d
 	if (!port && !pm_info->client) {
91594d
-		status = rpc_portmap_getclient(pm_info,
91594d
-				host->name, host->addr, host->addr_len,
91594d
-				proto, RPC_CLOSE_DEFAULT);
91594d
-		if (status == -EHOSTUNREACH) {
91594d
-			debug(logopt,
91594d
-			      "host not reachable getting portmap client");
91594d
-			supported = status;
91594d
-			goto done_ver;
91594d
-		} else if (status)
91594d
+		status = get_portmap_client(logopt, pm_info, host, proto);
91594d
+		if (status) {
91594d
+			if (status == -EHOSTUNREACH)
91594d
+				supported = status;
91594d
 			goto done_ver;
91594d
+		}
91594d
 	}
91594d
 
91594d
 	if (!port) {
91594d
-		parms.pm_vers = NFS2_VERSION;
91594d
-		status = rpc_portmap_getport(pm_info, &parms, &rpc_info->port);
91594d
-		if (status == -EHOSTUNREACH || status == -ETIMEDOUT) {
91594d
-			debug(logopt,
91594d
-			      "host not reachable or timed out getting service port");
91594d
-			supported = status;
91594d
-			goto done_ver;
91594d
-		} else if (status < 0)
91594d
+		status = get_portmap_port(logopt, pm_info, &parms,
91594d
+				NFS2_VERSION, version, &rpc_info->port);
91594d
+		if (status) {
91594d
+			if (status == -EHOSTUNREACH || status == -ETIMEDOUT)
91594d
+				supported = status;
91594d
 			goto done_ver;
91594d
+		}
91594d
 	}
91594d
 
91594d
 	if (rpc_info->proto == IPPROTO_UDP)