Sophie

Sophie

distrib > Scientific%20Linux > 5x > x86_64 > by-pkgid > 20db51d70e6b59a061db97ce9b89c771 > files > 57

net-snmp-5.3.2.2-14.el5.src.rpm

654384: hrStorageSize from HOST-RESOURCES-TYPES mib reports incorrect size for filesystems > 16TB

commit 5ba63b9fc8d4b64ea1efcbb122d76c6e18a0c64e
Author: jsafranek <jsafranek@06827809-a52a-0410-b366-d66718629ded>
Date:   Fri Feb 18 14:43:48 2011 +0000

(heavily backported to RHEL5 + made the realStorageUnits '1' by default)

    CHANGES: snmpd: reworked hrStorageTable to support large filesystems.
    
    The hrStorageAllocationUnits does not report real allocation unit size,
    but some calculated value so hrStorageAllocationUnits * hrStorageSize
    gives real size of the filesystem.
    
    This calculation happens only when hrStorageSize is too small (32bits)
    for filesystem size, e.g. filesystems larger than 8TB with 4096 bytes
    block size.
    
    This calculation can be turned off by 'realStorageUnits' config option.
    
    git-svn-id: https://net-snmp.svn.sourceforge.net/svnroot/net-snmp/trunk@19941 06827809-a52a-0410-b366-d66718629ded

diff -up net-snmp-5.3.2.2/agent/mibgroup/hardware/fsys/fsys_getfsstats.c.hrStorageSize-adjust-allocation-units net-snmp-5.3.2.2/agent/mibgroup/hardware/fsys/fsys_getfsstats.c
--- net-snmp-5.3.2.2/agent/mibgroup/hardware/fsys/fsys_getfsstats.c.hrStorageSize-adjust-allocation-units	2011-03-29 15:01:17.500368555 +0200
+++ net-snmp-5.3.2.2/agent/mibgroup/hardware/fsys/fsys_getfsstats.c	2011-03-29 15:01:17.598373836 +0200
@@ -173,6 +173,6 @@ netsnmp_fsys_arch_load( void )
         if (  stats[i].NSFS_FLAGS & MNT_ROOTFS ) {
             entry->flags |= NETSNMP_FS_FLAG_BOOTABLE;
         }
-        
+        netsnmp_fsys_calculate32(entry);
     }
 }
diff -up net-snmp-5.3.2.2/agent/mibgroup/hardware/fsys/fsys_mntctl.c.hrStorageSize-adjust-allocation-units net-snmp-5.3.2.2/agent/mibgroup/hardware/fsys/fsys_mntctl.c
--- net-snmp-5.3.2.2/agent/mibgroup/hardware/fsys/fsys_mntctl.c.hrStorageSize-adjust-allocation-units	2011-03-29 15:01:17.501368608 +0200
+++ net-snmp-5.3.2.2/agent/mibgroup/hardware/fsys/fsys_mntctl.c	2011-03-29 15:01:17.599373890 +0200
@@ -171,6 +171,7 @@ netsnmp_fsys_arch_load( void )
         entry->avail =  stat_buf.f_bavail;
         entry->inums_total = stat_buf.f_files;
         entry->inums_avail = stat_buf.f_ffree;
+        netsnmp_fsys_calculate32(entry);
     }
     free(aixmnt);
     aixmnt  = NULL;
diff -up net-snmp-5.3.2.2/agent/mibgroup/hardware/fsys/fsys_mntent.c.hrStorageSize-adjust-allocation-units net-snmp-5.3.2.2/agent/mibgroup/hardware/fsys/fsys_mntent.c
--- net-snmp-5.3.2.2/agent/mibgroup/hardware/fsys/fsys_mntent.c.hrStorageSize-adjust-allocation-units	2011-03-29 15:01:17.503368720 +0200
+++ net-snmp-5.3.2.2/agent/mibgroup/hardware/fsys/fsys_mntent.c	2011-03-29 15:56:21.703525877 +0200
@@ -235,6 +236,7 @@ netsnmp_fsys_arch_load( void )
         entry->avail =  stat_buf.f_bavail;
         entry->inums_total = stat_buf.f_files;
         entry->inums_avail = stat_buf.f_ffree;
+        netsnmp_fsys_calculate32(entry);
     }
     fclose( fp );
 }
diff -up net-snmp-5.3.2.2/agent/mibgroup/hardware/fsys/hw_fsys.c.hrStorageSize-adjust-allocation-units net-snmp-5.3.2.2/agent/mibgroup/hardware/fsys/hw_fsys.c
--- net-snmp-5.3.2.2/agent/mibgroup/hardware/fsys/hw_fsys.c.hrStorageSize-adjust-allocation-units	2011-03-29 15:01:17.504368776 +0200
+++ net-snmp-5.3.2.2/agent/mibgroup/hardware/fsys/hw_fsys.c	2011-03-29 15:01:17.601373999 +0200
@@ -247,7 +247,7 @@ _fsys_create_entry( void )
  *    (attempting to avoid 32-bit overflow!)
  */
 unsigned int
-_fsys_to_K( int size, int units )
+_fsys_to_K( unsigned long long size, unsigned long long units )
 {
     int factor = 1;
 
@@ -289,3 +289,26 @@ netsnmp_fsys_avail( netsnmp_fsys_info *f
     }
     return _fsys_to_K( f->avail, f->units );
 }
+
+#ifndef INT32_MAX
+#define INT32_MAX 0x7fffffff
+#endif
+
+/* recalculate f->size_32, used_32, avail_32 and units_32 from f->size & comp.*/
+void
+netsnmp_fsys_calculate32( netsnmp_fsys_info *f)
+{
+    unsigned long long s = f->size;
+    unsigned long long u = f->units;
+    int factor = 0;
+    while (s > INT32_MAX) {
+        s = s >> 1;
+        u = u << 1;
+        factor++;
+    }
+
+    f->size_32 = s;
+    f->units_32 = u;
+    f->avail_32 = f->avail << factor;
+    f->used_32 = f->used << factor;
+}
diff -up net-snmp-5.3.2.2/agent/mibgroup/host/hrh_storage.c.hrStorageSize-adjust-allocation-units net-snmp-5.3.2.2/agent/mibgroup/host/hrh_storage.c
--- net-snmp-5.3.2.2/agent/mibgroup/host/hrh_storage.c.hrStorageSize-adjust-allocation-units	2011-03-29 15:01:17.514369313 +0200
+++ net-snmp-5.3.2.2/agent/mibgroup/host/hrh_storage.c	2011-03-29 16:00:35.302279746 +0200
@@ -129,6 +129,12 @@ init_hrh_storage(void)
     netsnmp_ds_register_config(ASN_BOOLEAN, appname, "skipNFSInHostResources", 
 			       NETSNMP_DS_APPLICATION_ID,
 			       NETSNMP_DS_AGENT_SKIPNFSINHOSTRESOURCES);
+    netsnmp_ds_set_boolean(NETSNMP_DS_APPLICATION_ID,
+            NETSNMP_DS_AGENT_REALSTORAGEUNITS, 1);
+
+    netsnmp_ds_register_config(ASN_BOOLEAN, appname, "realStorageUnits",
+                   NETSNMP_DS_APPLICATION_ID,
+                   NETSNMP_DS_AGENT_REALSTORAGEUNITS);
 
     snmpd_register_config_handler("storageUseNFS", parse_storage_config, NULL,
 	"1 | 2\t\t(1 = enable, 2 = disable)");
@@ -415,27 +421,39 @@ really_try_next:
             return (u_char *) mem->descr;
         }
     case HRSTORE_UNITS:
-        if (store_idx > NETSNMP_MEM_TYPE_MAX)
-            long_return = HRFS_entry->units;
-        else {
+        if (store_idx > NETSNMP_MEM_TYPE_MAX) {
+            if (netsnmp_ds_get_boolean(NETSNMP_DS_APPLICATION_ID,
+                    NETSNMP_DS_AGENT_REALSTORAGEUNITS))
+                long_return = HRFS_entry->units & 0xffffffff;
+            else
+                long_return = HRFS_entry->units_32;
+        } else {
             if ( !mem || mem->units == -1 )
                 goto try_next;
             long_return = mem->units;
         }
         return (u_char *) & long_return;
     case HRSTORE_SIZE:
-        if (store_idx > NETSNMP_MEM_TYPE_MAX)
-            long_return = HRFS_entry->size;
-        else {
+        if (store_idx > NETSNMP_MEM_TYPE_MAX) {
+            if (netsnmp_ds_get_boolean(NETSNMP_DS_APPLICATION_ID,
+                    NETSNMP_DS_AGENT_REALSTORAGEUNITS))
+                long_return = HRFS_entry->size & 0xffffffff;
+            else
+                long_return = HRFS_entry->size_32;
+        } else {
             if ( !mem || mem->size == -1 )
                 goto try_next;
             long_return = mem->size;
         }
         return (u_char *) & long_return;
     case HRSTORE_USED:
-        if (store_idx > NETSNMP_MEM_TYPE_MAX)
-            long_return = HRFS_entry->used;
-        else {
+        if (store_idx > NETSNMP_MEM_TYPE_MAX) {
+            if (netsnmp_ds_get_boolean(NETSNMP_DS_APPLICATION_ID,
+                    NETSNMP_DS_AGENT_REALSTORAGEUNITS))
+                long_return = HRFS_entry->used & 0xffffffff;
+            else
+                long_return = HRFS_entry->used_32;
+        } else {
             if ( !mem || mem->size == -1 || mem->free == -1 )
                 goto try_next;
             long_return = mem->size - mem->free;
diff -up net-snmp-5.3.2.2/include/net-snmp/agent/ds_agent.h.hrStorageSize-adjust-allocation-units net-snmp-5.3.2.2/include/net-snmp/agent/ds_agent.h
--- net-snmp-5.3.2.2/include/net-snmp/agent/ds_agent.h.hrStorageSize-adjust-allocation-units	2011-03-29 15:01:17.288357140 +0200
+++ net-snmp-5.3.2.2/include/net-snmp/agent/ds_agent.h	2011-03-29 15:01:17.603374107 +0200
@@ -21,6 +21,7 @@
 #define NETSNMP_DS_AGENT_DONT_LOG_TCPWRAPPERS_CONNECTS 12   /* 1 = disable logging */
 #define NETSNMP_DS_APP_DONT_LOG         NETSNMP_DS_AGENT_DONT_RETAIN_NOTIFICATIONS /* compat */
 #define NETSNMP_DS_AGENT_SKIPNFSINHOSTRESOURCES    13   /* 1 = don't store NFS entries in hrStorageTable */
+#define NETSNMP_DS_AGENT_REALSTORAGEUNITS 14    /* 1 = use real allocation units in hrStorageTable, 0 = recalculate it to fit 32bits */
 
 /* WARNING: The trap receiver uses DS flags and must not conflict with
    these!  If you use a value above 15, change the minimimum DS bool
diff -up net-snmp-5.3.2.2/include/net-snmp/agent/hardware/fsys.h.hrStorageSize-adjust-allocation-units net-snmp-5.3.2.2/include/net-snmp/agent/hardware/fsys.h
--- net-snmp-5.3.2.2/include/net-snmp/agent/hardware/fsys.h.hrStorageSize-adjust-allocation-units	2011-03-29 15:01:17.517369473 +0200
+++ net-snmp-5.3.2.2/include/net-snmp/agent/hardware/fsys.h	2011-03-29 15:01:17.603374107 +0200
@@ -59,13 +59,18 @@ struct netsnmp_fsys_info_s {
      char device[SNMP_MAXPATH+1];
      int  type;
 
-     long size;
-     long used;
-     long avail;
-     long units;
+     unsigned long long size;
+     unsigned long long used;
+     unsigned long long avail;
+     unsigned long long units;
+
+     unsigned long size_32;
+     unsigned long used_32;
+     unsigned long avail_32;
+     unsigned long units_32;
 
-     long inums_total;
-     long inums_avail;
+     unsigned long long inums_total;
+     unsigned long long inums_avail;
 
      long flags;
 
@@ -91,3 +96,5 @@ void netsnmp_fsys_free( netsnmp_cache *c
 unsigned int netsnmp_fsys_size( netsnmp_fsys_info* );
 unsigned int netsnmp_fsys_used( netsnmp_fsys_info* );
 unsigned int netsnmp_fsys_avail(netsnmp_fsys_info* );
+
+void netsnmp_fsys_calculate32( netsnmp_fsys_info *f);
diff -up net-snmp-5.3.2.2/man/snmpd.conf.5.def.hrStorageSize-adjust-allocation-units net-snmp-5.3.2.2/man/snmpd.conf.5.def
--- net-snmp-5.3.2.2/man/snmpd.conf.5.def.hrStorageSize-adjust-allocation-units	2011-03-29 15:01:17.292357355 +0200
+++ net-snmp-5.3.2.2/man/snmpd.conf.5.def	2011-03-29 15:01:17.607374322 +0200
@@ -413,6 +413,25 @@ Historically, the Net-SNMP agent has rep
 as 'Fixed Disks', and this is still the default behaviour.
 Setting this directive to '1' reports such file systems as
 'Network Disks', as required by the Host Resources MIB.
+.IP "realStorageUnits"
+controlls how the agent reports hrStorageAllocationUnits, hrStorageSize and
+hrStorageUsed in hrStorageTable.
+With this option set to '0', the agent re-calculates these values for
+big storage drives with small allocation units so
+hrStorageAllocationUnits x hrStorageSize
+gives real size of the storage.
+.RS
+.IP "Example:"
+Linux xfs 16TB filesystem with 4096 bytes large blocks will be
+reported as  hrStorageAllocationUnits = 8192 and hrStorageSize = 2147483647,
+so 8192 x 2147483647 gives real size of the filesystem (=16 TB).
+.RE
+.IP
+Setting this directive to '1' (=default) turns off
+this calculation and the agent reports real hrStorageAllocationUnits, but it
+might report wrong hrStorageSize for big drives because the value won't fit into
+Integer32. In this case, hrStorageAllocationUnits x hrStorageSize won't give
+real size of the storage.
 .SS Process Monitoring 
 The \fChrSWRun\fR group of the Host Resources MIB provides
 information about individual processes running on the local system.