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