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

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