andykimpe / rpms / 389-ds-base

Forked from rpms/389-ds-base 5 months ago
Clone
dc8c34
From 6fb1ca2bc3f601b33f5dd69e5892175bae123d7c Mon Sep 17 00:00:00 2001
dc8c34
From: Mark Reynolds <mreynolds@redhat.com>
dc8c34
Date: Fri, 12 Jul 2013 16:52:57 -0400
dc8c34
Subject: [PATCH] Tickets 47427 & 47385 - Disk Monitoring Fixes
dc8c34
dc8c34
Bug Description:
dc8c34
dc8c34
      47427 - Overflow of treshold setting
dc8c34
      47385 - Server not shutting down as expected when disks fill up.
dc8c34
dc8c34
Fix Description:
dc8c34
dc8c34
      47427 - Change data type from "int" to PRUint64 for thresold and other size related variables
dc8c34
      47385 - removed unnecessary checks(if free disk space is continuing to drop).
dc8c34
dc8c34
https://fedorahosted.org/389/ticket/47385
dc8c34
https://fedorahosted.org/389/ticket/47427
dc8c34
dc8c34
Reviewed by: richm & nhosoi(Thanks!!)
dc8c34
---
dc8c34
 ldap/servers/slapd/daemon.c     |   50 ++++++++++++++++++---------------------
dc8c34
 ldap/servers/slapd/libglobs.c   |   11 ++++----
dc8c34
 ldap/servers/slapd/proto-slap.h |    2 +-
dc8c34
 ldap/servers/slapd/slap.h       |    2 +-
dc8c34
 4 files changed, 31 insertions(+), 34 deletions(-)
dc8c34
dc8c34
diff --git a/ldap/servers/slapd/daemon.c b/ldap/servers/slapd/daemon.c
dc8c34
index 5cc643a..b161ae6 100644
dc8c34
--- a/ldap/servers/slapd/daemon.c
dc8c34
+++ b/ldap/servers/slapd/daemon.c
dc8c34
@@ -638,16 +638,16 @@ disk_mon_get_dirs(char ***list, int logs_critical){
dc8c34
  *  directory.
dc8c34
  */
dc8c34
 char *
dc8c34
-disk_mon_check_diskspace(char **dirs, PRInt64 threshold, PRInt64 *disk_space)
dc8c34
+disk_mon_check_diskspace(char **dirs, PRUint64 threshold, PRUint64 *disk_space)
dc8c34
 {
dc8c34
 #ifdef LINUX
dc8c34
     struct statfs buf;
dc8c34
 #else
dc8c34
     struct statvfs buf;
dc8c34
 #endif
dc8c34
-    PRInt64 worst_disk_space = threshold;
dc8c34
-    PRInt64 freeBytes = 0;
dc8c34
-    PRInt64 blockSize = 0;
dc8c34
+    PRUint64 worst_disk_space = threshold;
dc8c34
+    PRUint64 freeBytes = 0;
dc8c34
+    PRUint64 blockSize = 0;
dc8c34
     char *worst_dir = NULL;
dc8c34
     int hit_threshold = 0;
dc8c34
     int i = 0;
dc8c34
@@ -704,9 +704,10 @@ disk_monitoring_thread(void *nothing)
dc8c34
     char errorbuf[BUFSIZ];
dc8c34
     char **dirs = NULL;
dc8c34
     char *dirstr = NULL;
dc8c34
-    PRInt64 previous_mark = 0;
dc8c34
-    PRInt64 disk_space = 0;
dc8c34
-    PRInt64 threshold = 0;
dc8c34
+    PRUint64 previous_mark = 0;
dc8c34
+    PRUint64 disk_space = 0;
dc8c34
+    PRUint64 threshold = 0;
dc8c34
+    PRUint64 halfway = 0;
dc8c34
     time_t start = 0;
dc8c34
     time_t now = 0;
dc8c34
     int deleted_rotated_logs = 0;
dc8c34
@@ -718,7 +719,6 @@ disk_monitoring_thread(void *nothing)
dc8c34
     int logs_disabled = 0;
dc8c34
     int grace_period = 0;
dc8c34
     int first_pass = 1;
dc8c34
-    int halfway = 0;
dc8c34
     int ok_now = 0;
dc8c34
 
dc8c34
     while(!g_get_shutdown()) {
dc8c34
@@ -789,7 +789,7 @@ disk_monitoring_thread(void *nothing)
dc8c34
          *  Check if we are already critical
dc8c34
          */
dc8c34
         if(disk_space < 4096){ /* 4 k */
dc8c34
-            LDAPDebug(LDAP_DEBUG_ANY, "Disk space is critically low on disk (%s), remaining space: %d Kb.  "
dc8c34
+            LDAPDebug(LDAP_DEBUG_ANY, "Disk space is critically low on disk (%s), remaining space: %" NSPRIu64 " Kb.  "
dc8c34
                 "Signaling slapd for shutdown...\n", dirstr , (disk_space / 1024), 0);
dc8c34
             g_set_shutdown( SLAPI_SHUTDOWN_EXIT );
dc8c34
             return;
dc8c34
@@ -799,7 +799,7 @@ disk_monitoring_thread(void *nothing)
dc8c34
          *  if logging is not critical
dc8c34
          */
dc8c34
         if(verbose_logging != 0 && verbose_logging != LDAP_DEBUG_ANY){
dc8c34
-            LDAPDebug(LDAP_DEBUG_ANY, "Disk space is low on disk (%s), remaining space: %d Kb, "
dc8c34
+            LDAPDebug(LDAP_DEBUG_ANY, "Disk space is low on disk (%s), remaining space: %" NSPRIu64 " Kb, "
dc8c34
                 "temporarily setting error loglevel to zero.\n", dirstr,
dc8c34
                 (disk_space / 1024), 0);
dc8c34
             /* Setting the log level back to zero, actually sets the value to LDAP_DEBUG_ANY */
dc8c34
@@ -811,13 +811,11 @@ disk_monitoring_thread(void *nothing)
dc8c34
          *  access/audit logs, log another error, and continue.
dc8c34
          */
dc8c34
         if(!logs_disabled && !logging_critical){
dc8c34
-            if(disk_space < previous_mark){
dc8c34
-                LDAPDebug(LDAP_DEBUG_ANY, "Disk space is too low on disk (%s), remaining space: %d Kb, "
dc8c34
-                    "disabling access and audit logging.\n", dirstr, (disk_space / 1024), 0);
dc8c34
-                config_set_accesslog_enabled(LOGGING_OFF);
dc8c34
-                config_set_auditlog_enabled(LOGGING_OFF);
dc8c34
-                logs_disabled = 1;
dc8c34
-            }
dc8c34
+            LDAPDebug(LDAP_DEBUG_ANY, "Disk space is too low on disk (%s), remaining space: %" NSPRIu64 " Kb, "
dc8c34
+                "disabling access and audit logging.\n", dirstr, (disk_space / 1024), 0);
dc8c34
+            config_set_accesslog_enabled(LOGGING_OFF);
dc8c34
+            config_set_auditlog_enabled(LOGGING_OFF);
dc8c34
+            logs_disabled = 1;
dc8c34
             continue;
dc8c34
         }
dc8c34
         /*
dc8c34
@@ -825,19 +823,17 @@ disk_monitoring_thread(void *nothing)
dc8c34
          *  access/audit logging, then delete the rotated logs, log another error, and continue.
dc8c34
          */
dc8c34
         if(!deleted_rotated_logs && !logging_critical){
dc8c34
-            if(disk_space < previous_mark){
dc8c34
-                LDAPDebug(LDAP_DEBUG_ANY, "Disk space is too low on disk (%s), remaining space: %d Kb, "
dc8c34
-                    "deleting rotated logs.\n", dirstr, (disk_space / 1024), 0);
dc8c34
-                log__delete_rotated_logs();
dc8c34
-                deleted_rotated_logs = 1;
dc8c34
-            }
dc8c34
+            LDAPDebug(LDAP_DEBUG_ANY, "Disk space is too low on disk (%s), remaining space: %" NSPRIu64 " Kb, "
dc8c34
+                "deleting rotated logs.\n", dirstr, (disk_space / 1024), 0);
dc8c34
+            log__delete_rotated_logs();
dc8c34
+            deleted_rotated_logs = 1;
dc8c34
             continue;
dc8c34
         }
dc8c34
         /*
dc8c34
          *  Ok, we've done what we can, log a message if we continue to lose available disk space
dc8c34
          */
dc8c34
         if(disk_space < previous_mark){
dc8c34
-            LDAPDebug(LDAP_DEBUG_ANY, "Disk space is too low on disk (%s), remaining space: %d Kb\n",
dc8c34
+            LDAPDebug(LDAP_DEBUG_ANY, "Disk space is too low on disk (%s), remaining space: %" NSPRIu64 " Kb\n",
dc8c34
                 dirstr, (disk_space / 1024), 0);
dc8c34
         }
dc8c34
         /*
dc8c34
@@ -849,7 +845,7 @@ disk_monitoring_thread(void *nothing)
dc8c34
          *
dc8c34
          */
dc8c34
         if(disk_space < halfway){
dc8c34
-            LDAPDebug(LDAP_DEBUG_ANY, "Disk space on (%s) is too far below the threshold(%d bytes).  "
dc8c34
+            LDAPDebug(LDAP_DEBUG_ANY, "Disk space on (%s) is too far below the threshold(%" NSPRIu64 " bytes).  "
dc8c34
                 "Waiting %d minutes for disk space to be cleaned up before shutting slapd down...\n",
dc8c34
                 dirstr, threshold, (grace_period / 60));
dc8c34
             time(&start;;
dc8c34
@@ -871,7 +867,7 @@ disk_monitoring_thread(void *nothing)
dc8c34
                     /*
dc8c34
                      *  Excellent, we are back to acceptable levels, reset everything...
dc8c34
                      */
dc8c34
-                    LDAPDebug(LDAP_DEBUG_ANY, "Available disk space is now acceptable (%d bytes).  Aborting"
dc8c34
+                    LDAPDebug(LDAP_DEBUG_ANY, "Available disk space is now acceptable (%" NSPRIu64 " bytes).  Aborting"
dc8c34
                                               " shutdown, and restoring the log settings.\n",disk_space,0,0);
dc8c34
                     if(logs_disabled && using_accesslog){
dc8c34
                         config_set_accesslog_enabled(LOGGING_ON);
dc8c34
@@ -891,7 +887,7 @@ disk_monitoring_thread(void *nothing)
dc8c34
                     /*
dc8c34
                      *  Disk space is critical, log an error, and shut it down now!
dc8c34
                      */
dc8c34
-                    LDAPDebug(LDAP_DEBUG_ANY, "Disk space is critically low on disk (%s), remaining space: %d Kb."
dc8c34
+                    LDAPDebug(LDAP_DEBUG_ANY, "Disk space is critically low on disk (%s), remaining space: %" NSPRIu64 " Kb."
dc8c34
                         "  Signaling slapd for shutdown...\n", dirstr, (disk_space / 1024), 0);
dc8c34
                     g_set_shutdown( SLAPI_SHUTDOWN_DISKFULL );
dc8c34
                     return;
dc8c34
diff --git a/ldap/servers/slapd/libglobs.c b/ldap/servers/slapd/libglobs.c
dc8c34
index 02e9df1..db0a221 100644
dc8c34
--- a/ldap/servers/slapd/libglobs.c
dc8c34
+++ b/ldap/servers/slapd/libglobs.c
dc8c34
@@ -1228,17 +1228,18 @@ config_set_disk_threshold( const char *attrname, char *value, char *errorbuf, in
dc8c34
 {
dc8c34
     slapdFrontendConfig_t *slapdFrontendConfig = getFrontendConfig();
dc8c34
     int retVal = LDAP_SUCCESS;
dc8c34
-    long threshold = 0;
dc8c34
+    PRUint64 threshold = 0;
dc8c34
     char *endp = NULL;
dc8c34
 
dc8c34
     if ( config_value_is_null( attrname, value, errorbuf, 0 )) {
dc8c34
         return LDAP_OPERATIONS_ERROR;
dc8c34
     }
dc8c34
 
dc8c34
-    threshold = strtol(value, &endp, 10);
dc8c34
+    errno = 0;
dc8c34
+    threshold = strtoll(value, &endp, 10);
dc8c34
 
dc8c34
-    if ( *endp != '\0' || threshold < 2048 ) {
dc8c34
-        PR_snprintf ( errorbuf, SLAPI_DSE_RETURNTEXT_SIZE, "%s: \"%s\" is invalid, threshold must be greater than 2048 and less then %ld",
dc8c34
+    if ( *endp != '\0' || threshold < 4096 || errno == ERANGE ) {
dc8c34
+        PR_snprintf ( errorbuf, SLAPI_DSE_RETURNTEXT_SIZE, "%s: \"%s\" is invalid, threshold must be greater than 4096 and less then %lu",
dc8c34
             attrname, value, LONG_MAX );
dc8c34
         retVal = LDAP_OPERATIONS_ERROR;
dc8c34
         return retVal;
dc8c34
@@ -3749,7 +3750,7 @@ config_get_disk_grace_period(){
dc8c34
     return retVal;
dc8c34
 }
dc8c34
 
dc8c34
-long
dc8c34
+PRUint64
dc8c34
 config_get_disk_threshold(){
dc8c34
     slapdFrontendConfig_t *slapdFrontendConfig = getFrontendConfig();
dc8c34
     long retVal;
dc8c34
diff --git a/ldap/servers/slapd/proto-slap.h b/ldap/servers/slapd/proto-slap.h
dc8c34
index 17b1e99..9d3a16d 100644
dc8c34
--- a/ldap/servers/slapd/proto-slap.h
dc8c34
+++ b/ldap/servers/slapd/proto-slap.h
dc8c34
@@ -541,7 +541,7 @@ void config_set_accesslog_enabled(int value);
dc8c34
 void config_set_auditlog_enabled(int value);
dc8c34
 int config_get_accesslog_logging_enabled();
dc8c34
 int config_get_disk_monitoring();
dc8c34
-long config_get_disk_threshold();
dc8c34
+PRUint64 config_get_disk_threshold();
dc8c34
 int config_get_disk_grace_period();
dc8c34
 int config_get_disk_logging_critical();
dc8c34
 
dc8c34
diff --git a/ldap/servers/slapd/slap.h b/ldap/servers/slapd/slap.h
dc8c34
index e0b261d..403ea8a 100644
dc8c34
--- a/ldap/servers/slapd/slap.h
dc8c34
+++ b/ldap/servers/slapd/slap.h
dc8c34
@@ -2233,7 +2233,7 @@ typedef struct _slapdFrontendConfig {
dc8c34
 
dc8c34
   /* disk monitoring */
dc8c34
   int disk_monitoring;
dc8c34
-  int disk_threshold;
dc8c34
+  PRUint64 disk_threshold;
dc8c34
   int disk_grace_period;
dc8c34
   int disk_logging_critical;
dc8c34
 } slapdFrontendConfig_t;
dc8c34
-- 
dc8c34
1.7.1
dc8c34