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

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