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

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