Blame SOURCES/0051-sss_cache-Wait-a-while-for-invalidation-of-mc-by-nss.patch

6cf099
From a09b3853da819cc773c0098100f9dd96af08f933 Mon Sep 17 00:00:00 2001
6cf099
From: Lukas Slebodnik <lslebodn@redhat.com>
6cf099
Date: Mon, 10 Aug 2015 10:16:58 +0200
6cf099
Subject: [PATCH 51/57] sss_cache: Wait a while for invalidation of mc by nss
6cf099
 responder
6cf099
MIME-Version: 1.0
6cf099
Content-Type: text/plain; charset=UTF-8
6cf099
Content-Transfer-Encoding: 8bit
6cf099
6cf099
The sss_cache cannot invalidate memory cache directly
6cf099
because the nss responder owns file locks to memory caches.
6cf099
Therefore sss_cache just "tell" nss responder to invalidate
6cf099
memory cache.
6cf099
6cf099
However there might be short interval between calling
6cf099
the utility sss_cache and stopping sssd. So nss responder
6cf099
needn't be so fast and therefore memory cache needn't be invalidated.
6cf099
6cf099
Resolves:
6cf099
https://fedorahosted.org/sssd/ticket/2748
6cf099
6cf099
Reviewed-by: Michal Židek <mzidek@redhat.com>
6cf099
---
6cf099
 src/tools/tools_mc_util.c | 34 ++++++++++++++++++++++++++++++++++
6cf099
 1 file changed, 34 insertions(+)
6cf099
6cf099
diff --git a/src/tools/tools_mc_util.c b/src/tools/tools_mc_util.c
6cf099
index c1b5c616d0e6d50147ecd81308aaa1e69304af92..65c461093e859d4da73761782a3a694bf5bda8fb 100644
6cf099
--- a/src/tools/tools_mc_util.c
6cf099
+++ b/src/tools/tools_mc_util.c
6cf099
@@ -21,6 +21,7 @@
6cf099
 
6cf099
 #include <talloc.h>
6cf099
 #include <fcntl.h>
6cf099
+#include <sys/stat.h>
6cf099
 
6cf099
 #include "db/sysdb.h"
6cf099
 #include "util/util.h"
6cf099
@@ -161,6 +162,33 @@ static int clear_fastcache(bool *sssd_nss_is_off)
6cf099
     return EOK;
6cf099
 }
6cf099
 
6cf099
+static errno_t wait_till_nss_responder_invalidate_cache(void)
6cf099
+{
6cf099
+    struct stat stat_buf = { 0 };
6cf099
+    const time_t max_wait = 1000000; /* 1 second */
6cf099
+    const time_t step_time = 5000; /* 5 miliseconds */
6cf099
+    const size_t steps_count = max_wait / step_time;
6cf099
+    int ret;
6cf099
+
6cf099
+    for (size_t i = 0; i < steps_count; ++i) {
6cf099
+        ret = stat(SSS_NSS_MCACHE_DIR "/" CLEAR_MC_FLAG, &stat_buf);
6cf099
+        if (ret == -1) {
6cf099
+            ret = errno;
6cf099
+            if (ret == ENOENT) {
6cf099
+                /* nss responder has already invalidated memory caches */
6cf099
+                return EOK;
6cf099
+            }
6cf099
+
6cf099
+            DEBUG(SSSDBG_CRIT_FAILURE,
6cf099
+                  "stat failed: %s (%d)\n", sss_strerror(ret), ret);
6cf099
+        }
6cf099
+
6cf099
+        usleep(step_time);
6cf099
+    }
6cf099
+
6cf099
+    return EAGAIN;
6cf099
+}
6cf099
+
6cf099
 errno_t sss_memcache_clear_all(void)
6cf099
 {
6cf099
     errno_t ret;
6cf099
@@ -196,6 +224,12 @@ errno_t sss_memcache_clear_all(void)
6cf099
                   "Failed to send SIGHUP to monitor.\n");
6cf099
             return EIO;
6cf099
         }
6cf099
+
6cf099
+        ret = wait_till_nss_responder_invalidate_cache();
6cf099
+        if (ret != EOK) {
6cf099
+            ERROR("The fast memory caches was not invalidated by NSS "
6cf099
+                  "responder.\n");
6cf099
+        }
6cf099
     }
6cf099
 
6cf099
     return EOK;
6cf099
-- 
6cf099
2.4.3
6cf099