Blame SOURCES/0001-NSS-Move-memcache-setup-to-separate-function.patch

ced1f5
From 82d52dbfd51330cd1fda4734b9e901431e137211 Mon Sep 17 00:00:00 2001
ced1f5
From: =?UTF-8?q?Michal=20=C5=BDidek?= <mzidek@redhat.com>
ced1f5
Date: Thu, 19 Oct 2017 16:39:27 +0200
ced1f5
Subject: [PATCH 01/21] NSS: Move memcache setup to separate function
ced1f5
MIME-Version: 1.0
ced1f5
Content-Type: text/plain; charset=UTF-8
ced1f5
Content-Transfer-Encoding: 8bit
ced1f5
ced1f5
Related:
ced1f5
https://pagure.io/SSSD/sssd/issue/3496
ced1f5
ced1f5
Reviewed-by: Sumit Bose <sbose@redhat.com>
ced1f5
Reviewed-by: Pavel Březina <pbrezina@redhat.com>
ced1f5
Reviewed-by: Fabiano Fidêncio <fidencio@redhat.com>
ced1f5
Reviewed-by: Jakub Hrozek <jhrozek@redhat.com>
ced1f5
(cherry picked from commit 878b0d42aca5839fdc1d97a68ce181e280f1ed7b)
ced1f5
---
ced1f5
 src/responder/nss/nsssrv.c | 91 ++++++++++++++++++++++++++--------------------
ced1f5
 1 file changed, 51 insertions(+), 40 deletions(-)
ced1f5
ced1f5
diff --git a/src/responder/nss/nsssrv.c b/src/responder/nss/nsssrv.c
ced1f5
index d67b9fac8d770d113560e41b259e2d5edd219343..21dd198226da6cf14d7db4941806048662970fed 100644
ced1f5
--- a/src/responder/nss/nsssrv.c
ced1f5
+++ b/src/responder/nss/nsssrv.c
ced1f5
@@ -252,6 +252,56 @@ static void nss_dp_reconnect_init(struct sbus_connection *conn,
ced1f5
     /* nss_shutdown(rctx); */
ced1f5
 }
ced1f5
 
ced1f5
+static int setup_memcaches(struct nss_ctx *nctx)
ced1f5
+{
ced1f5
+    int ret;
ced1f5
+    int memcache_timeout;
ced1f5
+
ced1f5
+    /* Remove the CLEAR_MC_FLAG file if exists. */
ced1f5
+    ret = unlink(SSS_NSS_MCACHE_DIR"/"CLEAR_MC_FLAG);
ced1f5
+    if (ret != 0 && errno != ENOENT) {
ced1f5
+        ret = errno;
ced1f5
+        DEBUG(SSSDBG_CRIT_FAILURE,
ced1f5
+              "Failed to unlink file [%s]. This can cause memory cache to "
ced1f5
+               "be purged when next log rotation is requested. %d: %s\n",
ced1f5
+               SSS_NSS_MCACHE_DIR"/"CLEAR_MC_FLAG, ret, strerror(ret));
ced1f5
+    }
ced1f5
+
ced1f5
+    ret = confdb_get_int(nctx->rctx->cdb,
ced1f5
+                         CONFDB_NSS_CONF_ENTRY,
ced1f5
+                         CONFDB_MEMCACHE_TIMEOUT,
ced1f5
+                         300, &memcache_timeout);
ced1f5
+    if (ret != EOK) {
ced1f5
+        DEBUG(SSSDBG_FATAL_FAILURE,
ced1f5
+              "Failed to get 'memcache_timeout' option from confdb.\n");
ced1f5
+        return ret;
ced1f5
+    }
ced1f5
+
ced1f5
+    /* TODO: read cache sizes from configuration */
ced1f5
+    ret = sss_mmap_cache_init(nctx, "passwd", SSS_MC_PASSWD,
ced1f5
+                              SSS_MC_CACHE_ELEMENTS, (time_t)memcache_timeout,
ced1f5
+                              &nctx->pwd_mc_ctx);
ced1f5
+    if (ret) {
ced1f5
+        DEBUG(SSSDBG_CRIT_FAILURE, "passwd mmap cache is DISABLED\n");
ced1f5
+    }
ced1f5
+
ced1f5
+    ret = sss_mmap_cache_init(nctx, "group", SSS_MC_GROUP,
ced1f5
+                              SSS_MC_CACHE_ELEMENTS, (time_t)memcache_timeout,
ced1f5
+                              &nctx->grp_mc_ctx);
ced1f5
+    if (ret) {
ced1f5
+        DEBUG(SSSDBG_CRIT_FAILURE, "group mmap cache is DISABLED\n");
ced1f5
+    }
ced1f5
+
ced1f5
+    ret = sss_mmap_cache_init(nctx, "initgroups", SSS_MC_INITGROUPS,
ced1f5
+                              SSS_MC_CACHE_ELEMENTS, (time_t)memcache_timeout,
ced1f5
+                              &nctx->initgr_mc_ctx);
ced1f5
+    if (ret) {
ced1f5
+        DEBUG(SSSDBG_CRIT_FAILURE, "initgroups mmap cache is DISABLED\n");
ced1f5
+    }
ced1f5
+
ced1f5
+    return EOK;
ced1f5
+}
ced1f5
+
ced1f5
 int nss_process_init(TALLOC_CTX *mem_ctx,
ced1f5
                      struct tevent_context *ev,
ced1f5
                      struct confdb_ctx *cdb)
ced1f5
@@ -260,7 +310,6 @@ int nss_process_init(TALLOC_CTX *mem_ctx,
ced1f5
     struct sss_cmd_table *nss_cmds;
ced1f5
     struct be_conn *iter;
ced1f5
     struct nss_ctx *nctx;
ced1f5
-    int memcache_timeout;
ced1f5
     int ret, max_retries;
ced1f5
     enum idmap_error_code err;
ced1f5
     int fd_limit;
ced1f5
@@ -330,49 +379,11 @@ int nss_process_init(TALLOC_CTX *mem_ctx,
ced1f5
         goto fail;
ced1f5
     }
ced1f5
 
ced1f5
-    /* create mmap caches */
ced1f5
-    /* Remove the CLEAR_MC_FLAG file if exists. */
ced1f5
-    ret = unlink(SSS_NSS_MCACHE_DIR"/"CLEAR_MC_FLAG);
ced1f5
-    if (ret != 0 && errno != ENOENT) {
ced1f5
-        ret = errno;
ced1f5
-        DEBUG(SSSDBG_CRIT_FAILURE,
ced1f5
-              "Failed to unlink file [%s]. This can cause memory cache to "
ced1f5
-               "be purged when next log rotation is requested. %d: %s\n",
ced1f5
-               SSS_NSS_MCACHE_DIR"/"CLEAR_MC_FLAG, ret, strerror(ret));
ced1f5
-    }
ced1f5
-
ced1f5
-    ret = confdb_get_int(nctx->rctx->cdb,
ced1f5
-                         CONFDB_NSS_CONF_ENTRY,
ced1f5
-                         CONFDB_MEMCACHE_TIMEOUT,
ced1f5
-                         300, &memcache_timeout);
ced1f5
+    ret = setup_memcaches(nctx);
ced1f5
     if (ret != EOK) {
ced1f5
-        DEBUG(SSSDBG_FATAL_FAILURE,
ced1f5
-              "Failed to get 'memcache_timeout' option from confdb.\n");
ced1f5
         goto fail;
ced1f5
     }
ced1f5
 
ced1f5
-    /* TODO: read cache sizes from configuration */
ced1f5
-    ret = sss_mmap_cache_init(nctx, "passwd", SSS_MC_PASSWD,
ced1f5
-                              SSS_MC_CACHE_ELEMENTS, (time_t)memcache_timeout,
ced1f5
-                              &nctx->pwd_mc_ctx);
ced1f5
-    if (ret) {
ced1f5
-        DEBUG(SSSDBG_CRIT_FAILURE, "passwd mmap cache is DISABLED\n");
ced1f5
-    }
ced1f5
-
ced1f5
-    ret = sss_mmap_cache_init(nctx, "group", SSS_MC_GROUP,
ced1f5
-                              SSS_MC_CACHE_ELEMENTS, (time_t)memcache_timeout,
ced1f5
-                              &nctx->grp_mc_ctx);
ced1f5
-    if (ret) {
ced1f5
-        DEBUG(SSSDBG_CRIT_FAILURE, "group mmap cache is DISABLED\n");
ced1f5
-    }
ced1f5
-
ced1f5
-    ret = sss_mmap_cache_init(nctx, "initgroups", SSS_MC_INITGROUPS,
ced1f5
-                              SSS_MC_CACHE_ELEMENTS, (time_t)memcache_timeout,
ced1f5
-                              &nctx->initgr_mc_ctx);
ced1f5
-    if (ret) {
ced1f5
-        DEBUG(SSSDBG_CRIT_FAILURE, "initgroups mmap cache is DISABLED\n");
ced1f5
-    }
ced1f5
-
ced1f5
     /* Set up file descriptor limits */
ced1f5
     ret = confdb_get_int(nctx->rctx->cdb,
ced1f5
                          CONFDB_NSS_CONF_ENTRY,
ced1f5
-- 
ced1f5
2.13.5
ced1f5