Blame SOURCES/autofs-5.1.2-work-around-sss-startup-delay.patch

306fa1
autofs-5.1.2 - work around sss startup delay
306fa1
306fa1
From: Ian Kent <raven@themaw.net>
306fa1
306fa1
When sssd is starting up there can be a delay before the map
306fa1
information is read. During that time an ENOENT can be returned
306fa1
when there actually is a map and autofs must respect the ENOENT
306fa1
return and continue because no map present is a valid response.
306fa1
306fa1
To work around that make the master map read wait and retry for
306fa1
for a time to give sssd a chance to read the map before returning
306fa1
either an ENOENT or, if the retry limit is exceeded, ETIMEDOUT.
306fa1
306fa1
Signed-off-by: Ian Kent <raven@themaw.net>
306fa1
---
306fa1
 CHANGELOG            |    1 
306fa1
 modules/lookup_sss.c |   61 +++++++++++++++++++++++++++++++++++++++++++++++++++
306fa1
 2 files changed, 62 insertions(+)
306fa1
306fa1
--- autofs-5.0.7.orig/CHANGELOG
306fa1
+++ autofs-5.0.7/CHANGELOG
306fa1
@@ -240,6 +240,7 @@
306fa1
 - log functions to prefix messages with attempt_id if available.
306fa1
 - factor out set_thread_mount_request_log_id().
306fa1
 - add config option to use mount request log id.
306fa1
+- work around sss startup delay.
306fa1
 
306fa1
 25/07/2012 autofs-5.0.7
306fa1
 =======================
306fa1
--- autofs-5.0.7.orig/modules/lookup_sss.c
306fa1
+++ autofs-5.0.7/modules/lookup_sss.c
306fa1
@@ -30,6 +30,11 @@
306fa1
 
306fa1
 #define MAPFMT_DEFAULT "sun"
306fa1
 
306fa1
+/* Half a second between retries */
306fa1
+#define SETAUTOMOUNTENT_MASTER_INTERVAL	500000000
306fa1
+/* Try for 10 seconds */
306fa1
+#define SETAUTOMOUNTENT_MASTER_RETRIES	10 * 2
306fa1
+
306fa1
 #define MODPREFIX "lookup(sss): "
306fa1
 
306fa1
 #define SSS_SO_NAME "libsss_autofs"
306fa1
@@ -219,6 +224,53 @@ static int setautomntent(unsigned int lo
306fa1
 	return ret;
306fa1
 }
306fa1
 
306fa1
+static int setautomntent_wait(unsigned int logopt,
306fa1
+			      struct lookup_context *ctxt,
306fa1
+			      const char *mapname,
306fa1
+			      void **sss_ctxt, unsigned int retries)
306fa1
+{
306fa1
+	unsigned int retry = 0;
306fa1
+	int ret = 0;
306fa1
+
306fa1
+	*sss_ctxt = NULL;
306fa1
+
306fa1
+	while (++retry < retries) {
306fa1
+		struct timespec t = { 0, SETAUTOMOUNTENT_MASTER_INTERVAL };
306fa1
+		struct timespec r;
306fa1
+
306fa1
+		ret = ctxt->setautomntent(mapname, sss_ctxt);
306fa1
+		if (ret != ENOENT)
306fa1
+			break;
306fa1
+
306fa1
+		if (*sss_ctxt) {
306fa1
+			free(*sss_ctxt);
306fa1
+			*sss_ctxt = NULL;
306fa1
+		}
306fa1
+
306fa1
+		while (nanosleep(&t, &r) == -1 && errno == EINTR)
306fa1
+			memcpy(&t, &r, sizeof(struct timespec));
306fa1
+	}
306fa1
+
306fa1
+
306fa1
+	if (ret) {
306fa1
+		char buf[MAX_ERR_BUF];
306fa1
+		char *estr;
306fa1
+
306fa1
+		if (*sss_ctxt) {
306fa1
+			free(*sss_ctxt);
306fa1
+			*sss_ctxt = NULL;
306fa1
+		}
306fa1
+
306fa1
+		if (retry == retries)
306fa1
+			ret = ETIMEDOUT;
306fa1
+
306fa1
+		estr = strerror_r(ret, buf, MAX_ERR_BUF);
306fa1
+		error(logopt, MODPREFIX "setautomntent: %s", estr);
306fa1
+	}
306fa1
+
306fa1
+	return ret;
306fa1
+}
306fa1
+
306fa1
 static int endautomntent(unsigned int logopt,
306fa1
 			 struct lookup_context *ctxt, void **sss_ctxt)
306fa1
 {
306fa1
@@ -247,6 +299,15 @@ int lookup_read_master(struct master *ma
306fa1
 
306fa1
 	ret = setautomntent(logopt, ctxt, ctxt->mapname, &sss_ctxt);
306fa1
 	if (ret) {
306fa1
+		unsigned int retries;
306fa1
+
306fa1
+		if (ret != ENOENT)
306fa1
+			return NSS_STATUS_UNAVAIL;
306fa1
+
306fa1
+		retries = SETAUTOMOUNTENT_MASTER_RETRIES;
306fa1
+		ret = setautomntent_wait(logopt,
306fa1
+					 ctxt, ctxt->mapname, &sss_ctxt,
306fa1
+					 retries);
306fa1
 		if (ret == ENOENT)
306fa1
 			return NSS_STATUS_NOTFOUND;
306fa1
 		return NSS_STATUS_UNAVAIL;