Bug 532672 - hrStorage does not seem to keep track of indexes
Summary: hrStorage does not seem to keep track of indexes
Keywords:
Status: CLOSED WONTFIX
Alias: None
Product: Red Hat Enterprise Linux 4
Classification: Red Hat
Component: net-snmp
Version: 4.8
Hardware: All
OS: Linux
medium
medium
Target Milestone: rc
: 4.9
Assignee: Jan Safranek
QA Contact: BaseOS QE Security Team
URL:
Whiteboard:
Depends On:
Blocks: 485811 595322 595325
TreeView+ depends on / blocked
 
Reported: 2009-11-03 12:36 UTC by Olivier Fourdan
Modified: 2013-03-04 02:48 UTC (History)
4 users (show)

Fixed In Version:
Doc Type: Bug Fix
Doc Text:
Clone Of:
: 595322 595325 (view as bug list)
Environment:
Last Closed: 2010-05-14 13:18:09 UTC
Target Upstream Version:
Embargoed:


Attachments (Terms of Use)
Proposed patch for net-snmp 5.1.2 (7.62 KB, patch)
2009-11-03 12:36 UTC, Olivier Fourdan
no flags Details | Diff
Same patch for current upstream svn (4.10 KB, patch)
2009-11-03 12:42 UTC, Olivier Fourdan
no flags Details | Diff
New reworked patch (7.30 KB, patch)
2009-11-05 16:41 UTC, Olivier Fourdan
no flags Details | Diff
Reworked patch for current svn net-snmp (3.98 KB, patch)
2009-11-05 16:42 UTC, Olivier Fourdan
no flags Details | Diff

Description Olivier Fourdan 2009-11-03 12:36:38 UTC
Created attachment 367291 [details]
Proposed patch for net-snmp 5.1.2

Description of problem:

The indexes of the filesystems as reported by hrStorage are not persistent across mount/umoumts.

That breaks third party tools that rely on persistent indexes, as specified in the RFC1514:

 http://tools.ietf.org/html/rfc1514#page-6

 hrFSIndex OBJECT-TYPE
      SYNTAX INTEGER (1..2147483647)
      ACCESS read-only
      STATUS mandatory
      DESCRIPTION
              "A unique value for each file system local to this
              host.  The value for each file system must remain
              constant at least from one re-initialization of
              the agent to the next re-initialization."


Version-Release number of selected component (if applicable):

net0snmp-5.1.2

How reproducible:

Always

Steps to Reproduce:
1. Make sure the MIB for hrStorage is available:

    # cat /etc/snmp/snmpd.conf
    com2sec notConfigUser  default       public
    group   notConfigGroup v1           notConfigUser
    group   notConfigGroup v2c           notConfigUser
    view    systemview    included   .1
    access  notConfigGroup ""      any       noauth    exact  systemview none none

2. Make sure different filesystems are mounted:

    # mount
    /dev/mapper/VolGroup00-LogVol00 on / type ext3 (rw)
    none on /proc type proc (rw)
    none on /sys type sysfs (rw)
    none on /dev/pts type devpts (rw,gid=5,mode=620)
    usbfs on /proc/bus/usb type usbfs (rw)
    /dev/hda1 on /boot type ext3 (rw)
    none on /dev/shm type tmpfs (rw)
    none on /proc/sys/fs/binfmt_misc type binfmt_misc (rw)
    sunrpc on /var/lib/nfs/rpc_pipefs type rpc_pipefs (rw)
    /dev/sda1 on /mnt/sda1 type ext3 (rw)
    /dev/sdb1 on /mnt/sdb1 type ext3 (rw)
    /dev/sda2 on /mnt/sda2 type ext3 (rw)
    /dev/sdb2 on /mnt/sdb2 type ext3 (rw)
    /dev/sda3 on /mnt/sda3 type ext3 (rw)
    /dev/sdb3 on /mnt/sdb3 type ext3 (rw)
    /dev/sda5 on /mnt/sda5 type ext3 (rw)
    /dev/sdb5 on /mnt/sdb5 type ext3 (rw)

3. query the hrStorage MIB with snmpwalk

    # snmpwalk -v1 -c public localhost HOST-RESOURCES-MIB::hrStorage

    HOST-RESOURCES-MIB::hrStorageDescr.1 = STRING: Memory Buffers
    HOST-RESOURCES-MIB::hrStorageDescr.2 = STRING: Real Memory
    HOST-RESOURCES-MIB::hrStorageDescr.3 = STRING: Swap Space
    HOST-RESOURCES-MIB::hrStorageDescr.4 = STRING: /
    HOST-RESOURCES-MIB::hrStorageDescr.5 = STRING: /sys
    HOST-RESOURCES-MIB::hrStorageDescr.6 = STRING: /proc/bus/usb
    HOST-RESOURCES-MIB::hrStorageDescr.7 = STRING: /boot
    HOST-RESOURCES-MIB::hrStorageDescr.8 = STRING: /proc/sys/fs/binfmt_misc
    HOST-RESOURCES-MIB::hrStorageDescr.9 = STRING: /var/lib/nfs/rpc_pipefs
    HOST-RESOURCES-MIB::hrStorageDescr.10 = STRING: /mnt/sda1
    HOST-RESOURCES-MIB::hrStorageDescr.11 = STRING: /mnt/sdb1
    HOST-RESOURCES-MIB::hrStorageDescr.12 = STRING: /mnt/sda2
    HOST-RESOURCES-MIB::hrStorageDescr.13 = STRING: /mnt/sdb2
    HOST-RESOURCES-MIB::hrStorageDescr.14 = STRING: /mnt/sda3
    HOST-RESOURCES-MIB::hrStorageDescr.15 = STRING: /mnt/sdb3
    HOST-RESOURCES-MIB::hrStorageDescr.16 = STRING: /mnt/sda5
    HOST-RESOURCES-MIB::hrStorageDescr.17 = STRING: /mnt/sdb5

4. umoung one of the file systems in the middle and remount it

    # umount /mnt/sda2
    # mount /dev/sda2 /mnt/sda2
    
5. query the hrStorage MIB with snmpwalk again

Actual results:

    HOST-RESOURCES-MIB::hrStorageDescr.1 = STRING: Memory Buffers
    HOST-RESOURCES-MIB::hrStorageDescr.2 = STRING: Real Memory
    HOST-RESOURCES-MIB::hrStorageDescr.3 = STRING: Swap Space
    HOST-RESOURCES-MIB::hrStorageDescr.4 = STRING: /
    HOST-RESOURCES-MIB::hrStorageDescr.5 = STRING: /sys
    HOST-RESOURCES-MIB::hrStorageDescr.6 = STRING: /proc/bus/usb
    HOST-RESOURCES-MIB::hrStorageDescr.7 = STRING: /boot
    HOST-RESOURCES-MIB::hrStorageDescr.8 = STRING: /proc/sys/fs/binfmt_misc
    HOST-RESOURCES-MIB::hrStorageDescr.9 = STRING: /var/lib/nfs/rpc_pipefs
    HOST-RESOURCES-MIB::hrStorageDescr.10 = STRING: /mnt/sda1
    HOST-RESOURCES-MIB::hrStorageDescr.11 = STRING: /mnt/sdb1
    HOST-RESOURCES-MIB::hrStorageDescr.12 = STRING: /mnt/sdb2
    HOST-RESOURCES-MIB::hrStorageDescr.13 = STRING: /mnt/sda3
    HOST-RESOURCES-MIB::hrStorageDescr.14 = STRING: /mnt/sdb3
    HOST-RESOURCES-MIB::hrStorageDescr.15 = STRING: /mnt/sda5
    HOST-RESOURCES-MIB::hrStorageDescr.16 = STRING: /mnt/sdb5
    HOST-RESOURCES-MIB::hrStorageDescr.17 = STRING: /mnt/sda2

=> Notice all indexes are shifted, and /mnt/sda2 now appearas in pos 14 instead of 12 previously

Expected results:

    HOST-RESOURCES-MIB::hrStorageDescr.1 = STRING: Memory Buffers
    HOST-RESOURCES-MIB::hrStorageDescr.2 = STRING: Real Memory
    HOST-RESOURCES-MIB::hrStorageDescr.3 = STRING: Swap Space
    HOST-RESOURCES-MIB::hrStorageDescr.4 = STRING: /
    HOST-RESOURCES-MIB::hrStorageDescr.5 = STRING: /sys
    HOST-RESOURCES-MIB::hrStorageDescr.6 = STRING: /proc/bus/usb
    HOST-RESOURCES-MIB::hrStorageDescr.7 = STRING: /boot
    HOST-RESOURCES-MIB::hrStorageDescr.8 = STRING: /proc/sys/fs/binfmt_misc
    HOST-RESOURCES-MIB::hrStorageDescr.9 = STRING: /var/lib/nfs/rpc_pipefs
    HOST-RESOURCES-MIB::hrStorageDescr.10 = STRING: /mnt/sda1
    HOST-RESOURCES-MIB::hrStorageDescr.11 = STRING: /mnt/sdb1
    HOST-RESOURCES-MIB::hrStorageDescr.12 = STRING: /mnt/sda2
    HOST-RESOURCES-MIB::hrStorageDescr.13 = STRING: /mnt/sdb2
    HOST-RESOURCES-MIB::hrStorageDescr.14 = STRING: /mnt/sda3
    HOST-RESOURCES-MIB::hrStorageDescr.15 = STRING: /mnt/sdb3
    HOST-RESOURCES-MIB::hrStorageDescr.16 = STRING: /mnt/sda5
    HOST-RESOURCES-MIB::hrStorageDescr.17 = STRING: /mnt/sdb5

=> indexes are persistent across umounts/mounts.

Additional info:

Later versions of net-snmp implement persistent storage indexes, but that introduces another bug:

    http://sourceforge.net/tracker/index.php?func=detail&aid=1689551&group_id=12694&atid=112694
    
Basically, indexes are now stored in a slist, but as the filesystems are taken from the mtab, and that the mtab reproduces the mounts order, unmouting/remouting a filesystem makes it appear last with a lower index, which is rejected because the index have to increase monotonically.

This is due to a side effect of the "monotonically increasing" index, a filesystem that had a lower index does not show when remounted because its index is smaller than the latest filesystem listed (as the filesystems are evaluated in the mtab order).

The following patch avoids that problem by using a replacement for the system's getmntent() which works as follow:

 - It looks first in the list for the next entry based on an index that we increment each time. The index is used to search first in the slist "filesys" that ensures persistent index values.

 - If there is no value for that index, it's the end of the slist, the function returns the next getmntent() as usual.

 - However, if there is an entry in the slist for that index, then it searches in the fstab for that name. This is because the filesystem might have been unmounted, yet we still have it in the slist.

 - If it's found, the function returns the corresponding entry. If not, it returns the next getmntent() as usual, as it means that the entry in the list is ought to be ignored as it's not mounted.

So in the end, the order is preserved, even across mounts and umounts.

Example with net-snmp 5.1.2 with the patch included:

    # snmpwalk -v1 -c public localhost HOST-RESOURCES-MIB::hrStorage

    HOST-RESOURCES-MIB::hrStorageDescr.1 = STRING: Memory Buffers
    HOST-RESOURCES-MIB::hrStorageDescr.2 = STRING: Real Memory
    HOST-RESOURCES-MIB::hrStorageDescr.3 = STRING: Swap Space
    HOST-RESOURCES-MIB::hrStorageDescr.4 = STRING: /
    HOST-RESOURCES-MIB::hrStorageDescr.6 = STRING: /proc/bus/usb
    HOST-RESOURCES-MIB::hrStorageDescr.7 = STRING: /boot
    HOST-RESOURCES-MIB::hrStorageDescr.8 = STRING: /var/lib/nfs/rpc_pipefs
    HOST-RESOURCES-MIB::hrStorageDescr.9 = STRING: /mnt/sda1
    HOST-RESOURCES-MIB::hrStorageDescr.10 = STRING: /mnt/sdb1
    HOST-RESOURCES-MIB::hrStorageDescr.11 = STRING: /mnt/sda2
    HOST-RESOURCES-MIB::hrStorageDescr.12 = STRING: /mnt/sdb2
    HOST-RESOURCES-MIB::hrStorageDescr.13 = STRING: /mnt/sda3
    HOST-RESOURCES-MIB::hrStorageDescr.14 = STRING: /mnt/sdb3
    HOST-RESOURCES-MIB::hrStorageDescr.15 = STRING: /mnt/sda5
    HOST-RESOURCES-MIB::hrStorageDescr.16 = STRING: /mnt/sdb5

    # mount /dev/sda2 /mnt/sda2
    # snmpwalk -v1 -c public localhost HOST-RESOURCES-MIB::hrStorage

    HOST-RESOURCES-MIB::hrStorageDescr.1 = STRING: Memory Buffers
    HOST-RESOURCES-MIB::hrStorageDescr.2 = STRING: Real Memory
    HOST-RESOURCES-MIB::hrStorageDescr.3 = STRING: Swap Space
    HOST-RESOURCES-MIB::hrStorageDescr.4 = STRING: /
    HOST-RESOURCES-MIB::hrStorageDescr.6 = STRING: /proc/bus/usb
    HOST-RESOURCES-MIB::hrStorageDescr.7 = STRING: /boot
    HOST-RESOURCES-MIB::hrStorageDescr.8 = STRING: /var/lib/nfs/rpc_pipefs
    HOST-RESOURCES-MIB::hrStorageDescr.9 = STRING: /mnt/sda1
    HOST-RESOURCES-MIB::hrStorageDescr.10 = STRING: /mnt/sdb1
    HOST-RESOURCES-MIB::hrStorageDescr.12 = STRING: /mnt/sdb2
    HOST-RESOURCES-MIB::hrStorageDescr.13 = STRING: /mnt/sda3
    HOST-RESOURCES-MIB::hrStorageDescr.14 = STRING: /mnt/sdb3
    HOST-RESOURCES-MIB::hrStorageDescr.15 = STRING: /mnt/sda5
    HOST-RESOURCES-MIB::hrStorageDescr.16 = STRING: /mnt/sdb5

=> notice that the indexes are preserved. there is no index 11 (previously /mnt/sda2 that is now unmounted)

    # umount /mnt/sda2
    # snmpwalk -v1 -c public localhost HOST-RESOURCES-MIB::hrStorage

    HOST-RESOURCES-MIB::hrStorageDescr.1 = STRING: Memory Buffers
    HOST-RESOURCES-MIB::hrStorageDescr.2 = STRING: Real Memory
    HOST-RESOURCES-MIB::hrStorageDescr.3 = STRING: Swap Space
    HOST-RESOURCES-MIB::hrStorageDescr.4 = STRING: /
    HOST-RESOURCES-MIB::hrStorageDescr.6 = STRING: /proc/bus/usb
    HOST-RESOURCES-MIB::hrStorageDescr.7 = STRING: /boot
    HOST-RESOURCES-MIB::hrStorageDescr.8 = STRING: /var/lib/nfs/rpc_pipefs
    HOST-RESOURCES-MIB::hrStorageDescr.9 = STRING: /mnt/sda1
    HOST-RESOURCES-MIB::hrStorageDescr.10 = STRING: /mnt/sdb1
    HOST-RESOURCES-MIB::hrStorageDescr.11 = STRING: /mnt/sda2
    HOST-RESOURCES-MIB::hrStorageDescr.12 = STRING: /mnt/sdb2
    HOST-RESOURCES-MIB::hrStorageDescr.13 = STRING: /mnt/sda3
    HOST-RESOURCES-MIB::hrStorageDescr.14 = STRING: /mnt/sdb3
    HOST-RESOURCES-MIB::hrStorageDescr.15 = STRING: /mnt/sda5
    HOST-RESOURCES-MIB::hrStorageDescr.16 = STRING: /mnt/sdb5

=> notice that the index are still preserved, and /mnt/sda2 remains at the same position 11

Comment 1 Olivier Fourdan 2009-11-03 12:42:28 UTC
Created attachment 367292 [details]
Same patch for current upstream svn

This patch is the same for current svn. As current svn implements persistent indexes, this patch only to address the bug reported upstream here:

http://sourceforge.net/tracker/index.php?func=detail&aid=1689551&group_id=12694&atid=112694

That's just for testing and reference (the patch intended for el4 is attachment 367291 [details])

Comment 2 Olivier Fourdan 2009-11-05 16:41:07 UTC
Created attachment 367661 [details]
New reworked patch

Better patch for net-snmp-5.1.2 for el4. 

Avoids returning duplicate indexes, more in line with coding style (use of global vars HRFS_entry and HRFS_index, do not re-open mtab but uses exiting file stream).

Comment 3 Olivier Fourdan 2009-11-05 16:42:50 UTC
Created attachment 367662 [details]
Reworked patch for current svn net-snmp

Same patch for net-snmp svn (should also apply on el5 cleanly)

Avoids returning duplicate indexes, more in line with coding style (use of global vars HRFS_entry and HRFS_index, do not re-open mtab but uses exiting file stream).

Comment 4 Jan Safranek 2009-11-11 16:12:02 UTC
Olivier,

thanks for the path. It looks working, but I do not like the rewinding of /etc/mount file back and forth - in corner case the file could be read O(n^2) times, where n is nr. of its entries. How big the file can be? Would it be possible to cache it in memory?

Comment 5 Jan Safranek 2009-11-11 16:20:34 UTC
oops, /etc/mount -> /etc/mtab, of course

Comment 6 Olivier Fourdan 2009-11-12 08:33:38 UTC
Yes, the rewind is a suboptimal. However, I would expect the OS itself to cache the mtab file. Of course, using our own cache in memory would be better, indeed.

Comment 12 RHEL Program Management 2010-05-14 13:18:09 UTC
Quality Engineering Management has reviewed and declined this request.  You may
appeal this decision by reopening this request.


Note You need to log in before you can comment on or make changes to this bug.