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

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