zrhoffman / rpms / 389-ds-base

Forked from rpms/389-ds-base 3 years ago
Clone

Blame SOURCES/0052-Ticket-49257-Reject-nsslapd-cachememsize-nsslapd-cac.patch

b69e47
From 0f04c8e7c1219940baf0ae9c1bcb2464ddf079df Mon Sep 17 00:00:00 2001
b69e47
From: Mark Reynolds <mreynolds@redhat.com>
b69e47
Date: Tue, 16 May 2017 13:19:43 -0400
b69e47
Subject: [PATCH] Ticket 49257 - Reject nsslapd-cachememsize &
b69e47
 nsslapd-cachesize when nsslapd-cache-autosize is set
b69e47
b69e47
Description:  We need to also reject entry cache changes when cache autosizing is being used.
b69e47
b69e47
              I also found out that we were not registering the ldbm instance callbacks at startup.
b69e47
              So all those functions were only used when creating an instance, and not after it was
b69e47
              started.
b69e47
b69e47
https://pagure.io/389-ds-base/issue/49257
b69e47
b69e47
Reviewed by: tbordaz(Thanks!)
b69e47
---
b69e47
 ldap/servers/slapd/back-ldbm/instance.c            | 19 +++++++++----
b69e47
 .../servers/slapd/back-ldbm/ldbm_instance_config.c | 32 ++++++++++++++++++++--
b69e47
 ldap/servers/slapd/back-ldbm/start.c               |  2 +-
b69e47
 3 files changed, 44 insertions(+), 9 deletions(-)
b69e47
b69e47
diff --git a/ldap/servers/slapd/back-ldbm/instance.c b/ldap/servers/slapd/back-ldbm/instance.c
b69e47
index f79d048..8b38644 100644
b69e47
--- a/ldap/servers/slapd/back-ldbm/instance.c
b69e47
+++ b/ldap/servers/slapd/back-ldbm/instance.c
b69e47
@@ -302,12 +302,19 @@ ldbm_instance_startall(struct ldbminfo *li)
b69e47
         inst = (ldbm_instance *) object_get_data(inst_obj);
b69e47
         ldbm_instance_set_flags(inst);
b69e47
         rc1 = ldbm_instance_start(inst->inst_be);
b69e47
-    if (rc1 != 0) {
b69e47
-        rc = rc1;
b69e47
-    } else {
b69e47
-        vlv_init(inst);
b69e47
-        slapi_mtn_be_started(inst->inst_be);
b69e47
-    }
b69e47
+        if (rc1 != 0) {
b69e47
+            rc = rc1;
b69e47
+        } else {
b69e47
+            if(ldbm_instance_config_load_dse_info(inst) != 0){
b69e47
+                slapi_log_err(SLAPI_LOG_ERR, "ldbm_instance_startall",
b69e47
+                    "Loading database instance configuration failed for (%s)\n",
b69e47
+                    inst->inst_name);
b69e47
+                rc = -1;
b69e47
+            } else {
b69e47
+                vlv_init(inst);
b69e47
+                slapi_mtn_be_started(inst->inst_be);
b69e47
+            }
b69e47
+        }
b69e47
         inst_obj = objset_next_obj(li->li_instance_set, inst_obj);
b69e47
     }
b69e47
 
b69e47
diff --git a/ldap/servers/slapd/back-ldbm/ldbm_instance_config.c b/ldap/servers/slapd/back-ldbm/ldbm_instance_config.c
b69e47
index 55f1887..49a6cac 100644
b69e47
--- a/ldap/servers/slapd/back-ldbm/ldbm_instance_config.c
b69e47
+++ b/ldap/servers/slapd/back-ldbm/ldbm_instance_config.c
b69e47
@@ -72,6 +72,18 @@ ldbm_instance_config_cachesize_set(void *arg, void *value, char *errorbuf, int p
b69e47
     /* Do whatever we can to make sure the data is ok. */
b69e47
 
b69e47
     if (apply) {
b69e47
+        if (CONFIG_PHASE_RUNNING == phase) {
b69e47
+            if (val > 0 && inst->inst_li->li_cache_autosize) {
b69e47
+                /* We are auto-tuning the cache, so this change would be overwritten - return an error */
b69e47
+                slapi_create_errormsg(errorbuf, SLAPI_DSE_RETURNTEXT_SIZE,
b69e47
+                    "Error: \"nsslapd-cachesize\" can not be updated while \"nsslapd-cache-autosize\" is set "
b69e47
+                    "in \"cn=config,cn=ldbm database,cn=plugins,cn=config\".");
b69e47
+                slapi_log_err(SLAPI_LOG_ERR, "ldbm_instance_config_cachesize_set",
b69e47
+                    "\"nsslapd-cachesize\" can not be set while \"nsslapd-cache-autosize\" is set "
b69e47
+                    "in \"cn=config,cn=ldbm database,cn=plugins,cn=config\".\n");
b69e47
+                return LDAP_UNWILLING_TO_PERFORM;
b69e47
+            }
b69e47
+        }
b69e47
         cache_set_max_entries(&(inst->inst_cache), val);
b69e47
     }
b69e47
 
b69e47
@@ -87,7 +99,11 @@ ldbm_instance_config_cachememsize_get(void *arg)
b69e47
 }
b69e47
 
b69e47
 static int 
b69e47
-ldbm_instance_config_cachememsize_set(void *arg, void *value, char *errorbuf, int phase, int apply) 
b69e47
+ldbm_instance_config_cachememsize_set(void *arg,
b69e47
+                                      void *value,
b69e47
+                                      char *errorbuf,
b69e47
+                                      int phase,
b69e47
+                                      int apply)
b69e47
 {
b69e47
     ldbm_instance *inst = (ldbm_instance *) arg;
b69e47
     int retval = LDAP_SUCCESS;
b69e47
@@ -107,6 +123,18 @@ ldbm_instance_config_cachememsize_set(void *arg, void *value, char *errorbuf, in
b69e47
      */
b69e47
 
b69e47
     if (apply) {
b69e47
+        if (CONFIG_PHASE_RUNNING == phase) {
b69e47
+            if (val > 0 && inst->inst_li->li_cache_autosize) {
b69e47
+                /* We are auto-tuning the cache, so this change would be overwritten - return an error */
b69e47
+                slapi_create_errormsg(errorbuf, SLAPI_DSE_RETURNTEXT_SIZE,
b69e47
+                    "Error: \"nsslapd-cachememsize\" can not be updated while \"nsslapd-cache-autosize\" is set "
b69e47
+                    "in \"cn=config,cn=ldbm database,cn=plugins,cn=config\".");
b69e47
+                slapi_log_err(SLAPI_LOG_ERR, "ldbm_instance_config_cachememsize_set",
b69e47
+                    "\"nsslapd-cachememsize\" can not be set while \"nsslapd-cache-autosize\" is set "
b69e47
+                    "in \"cn=config,cn=ldbm database,cn=plugins,cn=config\".\n");
b69e47
+                return LDAP_UNWILLING_TO_PERFORM;
b69e47
+            }
b69e47
+        }
b69e47
         if (val > inst->inst_cache.c_maxsize) {
b69e47
             delta = val - inst->inst_cache.c_maxsize;
b69e47
             delta_original = delta;
b69e47
@@ -825,7 +853,7 @@ ldbm_instance_modify_config_entry_callback(Slapi_PBlock *pb, Slapi_Entry* entryB
b69e47
                 continue;
b69e47
             }
b69e47
 
b69e47
-        /* This assumes there is only one bval for this mod. */
b69e47
+            /* This assumes there is only one bval for this mod. */
b69e47
             if (mods[i]->mod_bvalues == NULL) {
b69e47
                 /* This avoids the null pointer deref.
b69e47
                  * In ldbm_config.c ldbm_config_set, it checks for the NULL.
b69e47
diff --git a/ldap/servers/slapd/back-ldbm/start.c b/ldap/servers/slapd/back-ldbm/start.c
b69e47
index 1834a19..d4e8bb8 100644
b69e47
--- a/ldap/servers/slapd/back-ldbm/start.c
b69e47
+++ b/ldap/servers/slapd/back-ldbm/start.c
b69e47
@@ -169,7 +169,7 @@ ldbm_back_start_autotune(struct ldbminfo *li) {
b69e47
     }
b69e47
 
b69e47
     slapi_log_err(SLAPI_LOG_NOTICE, "ldbm_back_start", "found %luk physical memory\n", mi->system_total_bytes / 1024);
b69e47
-    slapi_log_err(SLAPI_LOG_NOTICE, "ldbm_back_start", "found %luk avaliable\n", mi->system_available_bytes / 1024);
b69e47
+    slapi_log_err(SLAPI_LOG_NOTICE, "ldbm_back_start", "found %luk available\n", mi->system_available_bytes / 1024);
b69e47
 
b69e47
     /* We've now calculated the autotuning values. Do we need to apply it?
b69e47
      * we use the logic of "if size is 0, or autosize is > 0. This way three
b69e47
-- 
b69e47
2.9.4
b69e47