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

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