Blame SOURCES/autofs-5.1.6-sss-introduce-a-flag-to-indicate-map-being-read.patch

1b50e3
autofs-5.1.6 - sss introduce a flag to indicate map being read
1b50e3
1b50e3
From: Ian Kent <raven@themaw.net>
1b50e3
1b50e3
When the master map is being read for the first time a retry loop is
1b50e3
used by the caller to try harder to read the master map because it
1b50e3
is required for autofs to start up.
1b50e3
1b50e3
But when re-reading the master map, reading dependent maps, or doing
1b50e3
key lookups that loop isn't used so a longer retry is needed for those
1b50e3
cases.
1b50e3
1b50e3
Introduce a flag to indicate which map is being read, or if the master
1b50e3
map is being re-read, or if a key lookup is being done so the number
1b50e3
of retries can be adjusted accordingly.
1b50e3
1b50e3
Signed-off-by: Ian Kent <raven@themaw.net>
1b50e3
---
1b50e3
 CHANGELOG            |    1 +
1b50e3
 modules/lookup_sss.c |   87 +++++++++++++++++++++++++++++++++++++++++---------
1b50e3
 2 files changed, 72 insertions(+), 16 deletions(-)
1b50e3
1b50e3
diff --git a/CHANGELOG b/CHANGELOG
1b50e3
index 4a6c042..2d98a3a 100644
1b50e3
--- a/CHANGELOG
1b50e3
+++ b/CHANGELOG
1b50e3
@@ -104,6 +104,7 @@ xx/xx/2018 autofs-5.1.5
1b50e3
 - improve sss getautomntent() error handling.
1b50e3
 - sss introduce calculate_retry_count() function.
1b50e3
 - move readall into struct master.
1b50e3
+- sss introduce a flag to indicate map being read.
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 29666a3..3c0ffde 100644
1b50e3
--- a/modules/lookup_sss.c
1b50e3
+++ b/modules/lookup_sss.c
1b50e3
@@ -53,6 +53,24 @@
1b50e3
  */
1b50e3
 #define SSS_PROTO_VERSION 1
1b50e3
 
1b50e3
+#define SSS_DEFAULT_WAIT	10
1b50e3
+
1b50e3
+/* When the master map is being read a retry loop is used by the
1b50e3
+ * caller to try harder to read the master map because it is required
1b50e3
+ * for autofs to start up.
1b50e3
+ *
1b50e3
+ * But when reading dependent maps or looking up a key that loop isn't
1b50e3
+ * used so a longer retry is needed for those cases.
1b50e3
+ *
1b50e3
+ * Introduce a flag to indicate which map is being read or if a lookup
1b50e3
+ * is being done so the number of retries can be adjusted accordingly.
1b50e3
+ */
1b50e3
+#define SSS_READ_NONE		0x00
1b50e3
+#define SSS_READ_MASTER_MAP	0x01
1b50e3
+#define SSS_REREAD_MASTER_MAP	0x02
1b50e3
+#define SSS_READ_DEPENDENT_MAP	0x04
1b50e3
+#define SSS_LOOKUP_KEY		0x08
1b50e3
+
1b50e3
 unsigned int _sss_auto_protocol_version(unsigned int);
1b50e3
 int _sss_setautomntent(const char *, void **);
1b50e3
 int _sss_getautomntent_r(char **, char **, void *);
1b50e3
@@ -249,7 +267,7 @@ static unsigned int proto_version(struct lookup_context *ctxt)
1b50e3
 	return proto_version;
1b50e3
 }
1b50e3
 
1b50e3
-static unsigned int calculate_retry_count(struct lookup_context *ctxt)
1b50e3
+static unsigned int calculate_retry_count(struct lookup_context *ctxt, unsigned int flags)
1b50e3
 {
1b50e3
 	int retries;
1b50e3
 
1b50e3
@@ -269,15 +287,39 @@ static unsigned int calculate_retry_count(struct lookup_context *ctxt)
1b50e3
 		 * a host being down, return 0 for retries.
1b50e3
 		 */
1b50e3
 		if (proto_version(ctxt) == 0)
1b50e3
-			retries = 0;
1b50e3
+			return 0;
1b50e3
 		else
1b50e3
-			retries = 10;
1b50e3
+			retries = SSS_DEFAULT_WAIT;
1b50e3
 	}
1b50e3
+
1b50e3
+	if (proto_version(ctxt) == 0)
1b50e3
+		return retries;
1b50e3
+
1b50e3
+	/* When the master map is being read there's an additional
1b50e3
+	 * outer wait loop.
1b50e3
+	 *
1b50e3
+	 * If master map wait is set in the configuration there
1b50e3
+	 * will be an outer loop interating master_map_wait / 2
1b50e3
+	 * times so adjust the number of retries here to account
1b50e3
+	 * for this for the cases where the master map isn't being
1b50e3
+	 * read.
1b50e3
+	 */
1b50e3
+
1b50e3
+	if (!(flags & SSS_READ_MASTER_MAP) ||
1b50e3
+	     (flags & SSS_REREAD_MASTER_MAP)) {
1b50e3
+		unsigned int master_map_wait = defaults_get_master_wait();
1b50e3
+		unsigned int m_wait;
1b50e3
+
1b50e3
+		m_wait = master_map_wait ? master_map_wait : SSS_DEFAULT_WAIT;
1b50e3
+		retries *= (m_wait / 2);
1b50e3
+	}
1b50e3
+
1b50e3
 	return retries;
1b50e3
 }
1b50e3
 
1b50e3
 static int setautomntent_wait(unsigned int logopt,
1b50e3
-			      struct lookup_context *ctxt, void **sss_ctxt)
1b50e3
+			      struct lookup_context *ctxt, void **sss_ctxt,
1b50e3
+			      unsigned int flags)
1b50e3
 {
1b50e3
 	unsigned int retries;
1b50e3
 	unsigned int retry = 0;
1b50e3
@@ -285,7 +327,7 @@ static int setautomntent_wait(unsigned int logopt,
1b50e3
 
1b50e3
 	*sss_ctxt = NULL;
1b50e3
 
1b50e3
-	retries = calculate_retry_count(ctxt);
1b50e3
+	retries = calculate_retry_count(ctxt, flags);
1b50e3
 	if (retries == 0) {
1b50e3
 		if (proto_version(ctxt) == 0)
1b50e3
 			return EINVAL;
1b50e3
@@ -333,7 +375,8 @@ static int setautomntent_wait(unsigned int logopt,
1b50e3
 }
1b50e3
 
1b50e3
 static int setautomntent(unsigned int logopt,
1b50e3
-			 struct lookup_context *ctxt, void **sss_ctxt)
1b50e3
+			 struct lookup_context *ctxt, void **sss_ctxt,
1b50e3
+			 unsigned int flags)
1b50e3
 {
1b50e3
 	char buf[MAX_ERR_BUF];
1b50e3
 	char *estr;
1b50e3
@@ -355,7 +398,7 @@ static int setautomntent(unsigned int logopt,
1b50e3
 				goto error;
1b50e3
 		}
1b50e3
 
1b50e3
-		ret = setautomntent_wait(logopt, ctxt, sss_ctxt);
1b50e3
+		ret = setautomntent_wait(logopt, ctxt, sss_ctxt, flags);
1b50e3
 		if (ret) {
1b50e3
 			if (ret == ECONNREFUSED) {
1b50e3
 				err = NSS_STATUS_UNKNOWN;
1b50e3
@@ -400,13 +443,14 @@ static int endautomntent(unsigned int logopt,
1b50e3
 
1b50e3
 static int getautomntent_wait(unsigned int logopt,
1b50e3
 			 struct lookup_context *ctxt,
1b50e3
-			 char **key, char **value, void *sss_ctxt)
1b50e3
+			 char **key, char **value, void *sss_ctxt,
1b50e3
+			 unsigned int flags)
1b50e3
 {
1b50e3
 	unsigned int retries;
1b50e3
 	unsigned int retry = 0;
1b50e3
 	int ret = 0;
1b50e3
 
1b50e3
-	retries = calculate_retry_count(ctxt);
1b50e3
+	retries = calculate_retry_count(ctxt, flags);
1b50e3
 	if (retries == 0) {
1b50e3
 		if (proto_version(ctxt) == 0)
1b50e3
 			return EINVAL;
1b50e3
@@ -446,7 +490,8 @@ static int getautomntent_wait(unsigned int logopt,
1b50e3
 
1b50e3
 static int getautomntent(unsigned int logopt,
1b50e3
 			 struct lookup_context *ctxt,
1b50e3
-			 char **key, char **value, int count, void *sss_ctxt)
1b50e3
+			 char **key, char **value, int count,
1b50e3
+			 void *sss_ctxt, unsigned int flags)
1b50e3
 {
1b50e3
 	char buf[MAX_ERR_BUF];
1b50e3
 	char *estr;
1b50e3
@@ -486,7 +531,7 @@ static int getautomntent(unsigned int logopt,
1b50e3
 		}
1b50e3
 
1b50e3
 		ret = getautomntent_wait(logopt, ctxt,
1b50e3
-					 key, value, sss_ctxt);
1b50e3
+					 key, value, sss_ctxt, flags);
1b50e3
 		if (ret) {
1b50e3
 			if (ret == ECONNREFUSED) {
1b50e3
 				err = NSS_STATUS_UNKNOWN;
1b50e3
@@ -534,8 +579,13 @@ int lookup_read_master(struct master *master, time_t age, void *context)
1b50e3
 	char *key;
1b50e3
 	char *value = NULL;
1b50e3
 	int count, ret;
1b50e3
+	unsigned int flags;
1b50e3
+
1b50e3
+	flags = SSS_READ_MASTER_MAP;
1b50e3
+	if (master->readall)
1b50e3
+		flags |= SSS_REREAD_MASTER_MAP;
1b50e3
 
1b50e3
-	ret = setautomntent(logopt, ctxt, &sss_ctxt);
1b50e3
+	ret = setautomntent(logopt, ctxt, &sss_ctxt, flags);
1b50e3
 	if (ret)
1b50e3
 		return ret;
1b50e3
 
1b50e3
@@ -543,7 +593,9 @@ int lookup_read_master(struct master *master, time_t age, void *context)
1b50e3
 	while (1) {
1b50e3
 	        key = NULL;
1b50e3
 	        value = NULL;
1b50e3
-		ret = getautomntent(logopt, ctxt, &key, &value, count, sss_ctxt);
1b50e3
+		ret = getautomntent(logopt, ctxt,
1b50e3
+				    &key, &value, count,
1b50e3
+				    sss_ctxt, SSS_READ_MASTER_MAP);
1b50e3
 		if (ret) {
1b50e3
 			endautomntent(logopt, ctxt, &sss_ctxt);
1b50e3
 			return ret;
1b50e3
@@ -622,7 +674,8 @@ int lookup_read_map(struct autofs_point *ap, time_t age, void *context)
1b50e3
 		return NSS_STATUS_SUCCESS;
1b50e3
 	}
1b50e3
 
1b50e3
-	ret = setautomntent(ap->logopt, ctxt, &sss_ctxt);
1b50e3
+	ret = setautomntent(ap->logopt, ctxt,
1b50e3
+			    &sss_ctxt, SSS_READ_DEPENDENT_MAP);
1b50e3
 	if (ret)
1b50e3
 		return ret;
1b50e3
 
1b50e3
@@ -630,7 +683,9 @@ int lookup_read_map(struct autofs_point *ap, time_t age, void *context)
1b50e3
 	while (1) {
1b50e3
 	        key = NULL;
1b50e3
 	        value = NULL;
1b50e3
-		ret = getautomntent(ap->logopt, ctxt, &key, &value, count, sss_ctxt);
1b50e3
+		ret = getautomntent(ap->logopt, ctxt,
1b50e3
+				    &key, &value, count,
1b50e3
+				    sss_ctxt, SSS_READ_DEPENDENT_MAP);
1b50e3
 		if (ret) {
1b50e3
 			endautomntent(ap->logopt, ctxt, &sss_ctxt);
1b50e3
 			return ret;
1b50e3
@@ -711,7 +766,7 @@ static int lookup_one(struct autofs_point *ap,
1b50e3
 
1b50e3
 	mc = source->mc;
1b50e3
 
1b50e3
-	ret = setautomntent(ap->logopt, ctxt, &sss_ctxt);
1b50e3
+	ret = setautomntent(ap->logopt, ctxt, &sss_ctxt, SSS_LOOKUP_KEY);
1b50e3
 	if (ret)
1b50e3
 		return ret;
1b50e3