Blame SOURCES/autofs-5.1.6-sss-introduce-retries-calcuation-function.patch

d702dc
autofs-5.1.6 - sss introduce calculate_retry_count() function
d702dc
d702dc
From: Ian Kent <raven@themaw.net>
d702dc
d702dc
Add a function calculate_retry_count() to consolidate the calculation
d702dc
of the retry count into a single location.
d702dc
d702dc
Signed-off-by: Ian Kent <raven@themaw.net>
d702dc
---
d702dc
 CHANGELOG            |    1 +
d702dc
 modules/lookup_sss.c |   62 ++++++++++++++++++++++++++++++--------------------
d702dc
 2 files changed, 38 insertions(+), 25 deletions(-)
d702dc
d702dc
diff --git a/CHANGELOG b/CHANGELOG
d702dc
index 434e23d..4d83df2 100644
d702dc
--- a/CHANGELOG
d702dc
+++ b/CHANGELOG
d702dc
@@ -102,6 +102,7 @@ xx/xx/2018 autofs-5.1.5
d702dc
 - improve sss setautomntent() error handling.
d702dc
 - refactor sss getautomntent().
d702dc
 - improve sss getautomntent() error handling.
d702dc
+- sss introduce calculate_retry_count() function.
d702dc
 
d702dc
 19/12/2017 autofs-5.1.4
d702dc
 - fix spec file url.
d702dc
diff --git a/modules/lookup_sss.c b/modules/lookup_sss.c
d702dc
index f366b48..29666a3 100644
d702dc
--- a/modules/lookup_sss.c
d702dc
+++ b/modules/lookup_sss.c
d702dc
@@ -249,14 +249,9 @@ static unsigned int proto_version(struct lookup_context *ctxt)
d702dc
 	return proto_version;
d702dc
 }
d702dc
 
d702dc
-static int setautomntent_wait(unsigned int logopt,
d702dc
-			      struct lookup_context *ctxt, void **sss_ctxt)
d702dc
+static unsigned int calculate_retry_count(struct lookup_context *ctxt)
d702dc
 {
d702dc
-	unsigned int retries;
d702dc
-	unsigned int retry = 0;
d702dc
-	int ret = 0;
d702dc
-
d702dc
-	*sss_ctxt = NULL;
d702dc
+	int retries;
d702dc
 
d702dc
 	retries = defaults_get_sss_master_map_wait();
d702dc
 
d702dc
@@ -264,14 +259,37 @@ static int setautomntent_wait(unsigned int logopt,
d702dc
 	 * configuration give it a sensible value since we
d702dc
 	 * want to wait for a host that's down in case it
d702dc
 	 * comes back up.
d702dc
+	 *
d702dc
+	 * Use the sss_master_map_wait configuration option
d702dc
+	 * for the time to wait when reading a dependednt map
d702dc
+	 * or performing a key lookup too.
d702dc
 	 */
d702dc
 	if (retries <= 0) {
d702dc
 		/* Protocol version 0 cant't tell us about
d702dc
-		 * a host being down, return not found.
d702dc
+		 * a host being down, return 0 for retries.
d702dc
 		 */
d702dc
 		if (proto_version(ctxt) == 0)
d702dc
-			return ENOENT;
d702dc
-		retries = 10;
d702dc
+			retries = 0;
d702dc
+		else
d702dc
+			retries = 10;
d702dc
+	}
d702dc
+	return retries;
d702dc
+}
d702dc
+
d702dc
+static int setautomntent_wait(unsigned int logopt,
d702dc
+			      struct lookup_context *ctxt, void **sss_ctxt)
d702dc
+{
d702dc
+	unsigned int retries;
d702dc
+	unsigned int retry = 0;
d702dc
+	int ret = 0;
d702dc
+
d702dc
+	*sss_ctxt = NULL;
d702dc
+
d702dc
+	retries = calculate_retry_count(ctxt);
d702dc
+	if (retries == 0) {
d702dc
+		if (proto_version(ctxt) == 0)
d702dc
+			return EINVAL;
d702dc
+		return ENOENT;
d702dc
 	}
d702dc
 
d702dc
 	warn(logopt,
d702dc
@@ -345,6 +363,9 @@ static int setautomntent(unsigned int logopt,
d702dc
 			}
d702dc
 			if (ret == ETIMEDOUT)
d702dc
 				goto error;
d702dc
+			/* sss proto version 0 and sss timeout not set */
d702dc
+			if (ret == EINVAL)
d702dc
+				goto free;
d702dc
 			if (ret == ENOENT) {
d702dc
 				err = NSS_STATUS_NOTFOUND;
d702dc
 				goto free;
d702dc
@@ -385,21 +406,11 @@ static int getautomntent_wait(unsigned int logopt,
d702dc
 	unsigned int retry = 0;
d702dc
 	int ret = 0;
d702dc
 
d702dc
-	retries = defaults_get_sss_master_map_wait();
d702dc
-
d702dc
-	/* Use the sss_master_map_wait configuration option
d702dc
-	 * for the time to wait when reading a map too. If
d702dc
-	 * it isn't set in the antofs configuration give it
d702dc
-	 * a sensible value since we want to wait for a host
d702dc
-	 * that's down in case it comes back up.
d702dc
-	 */
d702dc
-	if (retries <= 0) {
d702dc
-		/* Protocol version 0 cant't tell us about
d702dc
-		 * a host being down, return not found.
d702dc
-		 */
d702dc
+	retries = calculate_retry_count(ctxt);
d702dc
+	if (retries == 0) {
d702dc
 		if (proto_version(ctxt) == 0)
d702dc
-			return ENOENT;
d702dc
-		retries = 10;
d702dc
+			return EINVAL;
d702dc
+		return ENOENT;
d702dc
 	}
d702dc
 
d702dc
 	warn(logopt,
d702dc
@@ -483,7 +494,8 @@ static int getautomntent(unsigned int logopt,
d702dc
 			}
d702dc
 			if (ret == ETIMEDOUT)
d702dc
 				goto error;
d702dc
-			if (ret == ENOENT) {
d702dc
+			/* sss proto version 0 and sss timeout not set => EINVAL */
d702dc
+			if (ret == ENOENT || ret == EINVAL) {
d702dc
 				err = NSS_STATUS_NOTFOUND;
d702dc
 				if (count)
d702dc
 					err = NSS_STATUS_SUCCESS;