PERFORCE change 81546 for review

Victor Cruceru soc-victor at FreeBSD.org
Sat Aug 6 10:47:28 GMT 2005


http://perforce.freebsd.org/chv.cgi?CH=81546

Change 81546 by soc-victor at soc-victor_82.76.158.176 on 2005/08/06 10:46:41

	This is the very first SNMP instrumentation for hrPartitionTable (based on libdisk).
	Things to be done:
	-implement the SNMP operations (get, get next, etc.);
	-link the table's entries to hrFSTable's entries

Affected files ...

.. //depot/projects/soc2005/bsnmp/usr.sbin/bsnmpd/modules/snmp_hostres/Makefile#16 edit
.. //depot/projects/soc2005/bsnmp/usr.sbin/bsnmpd/modules/snmp_hostres/hostres_diskstorage_tbl.c#5 edit
.. //depot/projects/soc2005/bsnmp/usr.sbin/bsnmpd/modules/snmp_hostres/hostres_partition_tbl.c#1 add
.. //depot/projects/soc2005/bsnmp/usr.sbin/bsnmpd/modules/snmp_hostres/hostres_snmp.c#15 edit
.. //depot/projects/soc2005/bsnmp/usr.sbin/bsnmpd/modules/snmp_hostres/hostres_snmp.h#19 edit

Differences ...

==== //depot/projects/soc2005/bsnmp/usr.sbin/bsnmpd/modules/snmp_hostres/Makefile#16 (text+ko) ====

@@ -34,11 +34,12 @@
 	hostres_swrun_tbl.c hostres_swrunperf_tbl.c \
 	hostres_device_tbl.c \
 	hostres_processor_tbl.c \
-	hostres_diskstorage_tbl.c
+	hostres_diskstorage_tbl.c \
+	hostres_partition_tbl.c
 	
 WARNS?=	6
 #Not having NDEBUG defined will enable assertions and a lot of output on stderr
-CFLAGS+=	-DNDEBUG
+#CFLAGS+=	-DNDEBUG
 XSYM=	host hrStorageOther hrStorageRam hrStorageVirtualMemory \
 	hrStorageFixedDisk hrStorageRemovableDisk hrStorageFloppyDisk \
 	hrStorageCompactDisc hrStorageRamDisk hrStorageFlashMemory \
@@ -56,5 +57,5 @@
 	
 DEFS=	${MOD}_tree.def
 BMIBS=	HOST-RESOURCES-MIB.txt HOST-RESOURCES-TYPES.txt
-LDADD=	-lkvm -ldevinfo -lm
+LDADD=	-lkvm -ldevinfo -lm -ldisk
 .include <bsd.lib.mk>

==== //depot/projects/soc2005/bsnmp/usr.sbin/bsnmpd/modules/snmp_hostres/hostres_diskstorage_tbl.c#5 (text+ko) ====

@@ -28,8 +28,8 @@
  *
  * Host Resources MIB for SNMPd. Implementation for the hrDiskStorageTable
  */
-
-
+ 
+ 
 #include "hostres_snmp.h"
 #include "hostres_oid.h"
 #include "hostres_tree.h"
@@ -40,7 +40,7 @@
 #include <unistd.h>
 #include <sys/types.h>
 #include <libdisk.h>
-#include <assert.h>
+#include <assert.h>	
 #include <err.h>
 #include <sys/sysctl.h>
 #include <sys/ata.h>
@@ -57,38 +57,48 @@
 void
 hrDeviceTblEntry_delete_v( struct hrDeviceTblEntry* entry );
 
+extern 
+void 
+Partition_tbl_pre_refresh_v(void);
 
+extern 
+void 
+Partition_tbl_post_refresh_v(void);
+
+void 
+handleDiskStorage(int32_t ds_index, const char* disk_dev_name);
+
 static
-struct hrDiskStorageTblEntry*
+struct hrDiskStorageTblEntry* 
 hrDiskStorageEntry_create( const struct hrDeviceTblEntry* devEntry) {
-       struct
-       hrDiskStorageTblEntry   *entry = NULL;
+	struct 
+	hrDiskStorageTblEntry	*entry = NULL;
 
-       assert(devEntry != NULL);
-       if (devEntry == NULL) {
-               return NULL;
-       }
-
-       if ((entry = malloc(sizeof(*entry))) == NULL) {
-               syslog(LOG_WARNING, "hrDiskStorageTable: %s: %m", __func__);
-               return (NULL);
-       }
-       memset(entry, 0, sizeof(*entry));
-       entry->index = devEntry->index;
-       INSERT_OBJECT_INT(entry, &hrState_g.hr_disk_storage_tbl);
-       return entry;
+	assert(devEntry != NULL);
+	if (devEntry == NULL) {
+		return NULL;
+	}
+	
+	if ((entry = malloc(sizeof(*entry))) == NULL) {
+		syslog(LOG_WARNING, "hrDiskStorageTable: %s: %m", __func__);
+		return (NULL);
+	}
+	memset(entry, 0, sizeof(*entry));
+	entry->index = devEntry->index;
+	INSERT_OBJECT_INT(entry, &hrState_g.hr_disk_storage_tbl);
+	return entry;
 
 }
 
 static
 void
 hrDiskStorageEntry_delete_v( struct hrDiskStorageTblEntry* entry ) {
-       assert(entry != NULL);
-       if (entry == NULL) {
-               return;
-       }
-       TAILQ_REMOVE(&hrState_g.hr_disk_storage_tbl, entry, link);
-       free(entry);
+	assert(entry != NULL);
+	if (entry == NULL) {
+		return;
+	}
+	TAILQ_REMOVE(&hrState_g.hr_disk_storage_tbl, entry, link);	
+	free(entry);
 }
 
 
@@ -96,723 +106,732 @@
 struct hrDiskStorageTblEntry *
 hrDiskStorageTblEntry_find_by_index(int32_t idx) {
 
-       struct hrDiskStorageTblEntry *entry;
+	struct hrDiskStorageTblEntry *entry;
 
-       TAILQ_FOREACH(entry, &hrState_g.hr_disk_storage_tbl, link)
-               if (entry->index == idx)
-                       return (entry);
-       return (NULL);
+	TAILQ_FOREACH(entry, &hrState_g.hr_disk_storage_tbl, link)
+		if (entry->index == idx)
+			return (entry);
+	return (NULL);
 }
 
 
 static
-struct hrDeviceTblEntry*
+struct hrDeviceTblEntry* 
 hrDeviceTblEntry_create( const char* dev_name) {
-       struct
-       hrDeviceTblEntry        *entry;
-       struct
-       deviceNameMapEntry      *map = NULL;
+	struct 
+	hrDeviceTblEntry	*entry;
+	struct 
+	deviceNameMapEntry 	*map = NULL;
 
+	
+	assert(dev_name != NULL);
 
-       assert(dev_name != NULL);
+	if (dev_name == NULL) {
+		return (NULL);
+	}
+	
+	if (dev_name[0] == '\0') {
+		return (NULL);	
+	}
+	
+	if ((entry = malloc(sizeof(*entry))) == NULL) {
+		syslog(LOG_WARNING, "hrDiskStorageTable: %s: %m", __func__);
+		return (NULL);
+	}
+	memset(entry, 0, sizeof(*entry));
+	
 
-       if (dev_name == NULL) {
-               return (NULL);
-       }
+	STAILQ_FOREACH(map, &hrState_g.device_name_map, link)
+		if (strcmp(map->name_key, dev_name) == 0) {
+			entry->index = map->hrIndex;
+			map->entry_p = entry;
+			break;
+		}
+	
+	if (map == NULL) {
+		/* new object - get a new index */
+		if (hrState_g.next_hrDevice_index > INT_MAX) {
+		        syslog(LOG_ERR, "%s: hrDeviceTable index wrap", __func__ );
+			errx(1, "hrDeviceTable index wrap");
+		}	
 
-       if (dev_name[0] == '\0') {
-               return (NULL);
-       }
+		if ((map = malloc(sizeof(*map))) == NULL) {
+			syslog(LOG_ERR, "hrStorageTable: %s: %m", __func__ );
+			free(entry);
+			return (NULL);
+		}
+		map->hrIndex = hrState_g.next_hrDevice_index ++;
+		
+		memset(&map->name_key[0], 0, sizeof(map->name_key));
+		strncpy(map->name_key, dev_name, sizeof(map->name_key) - 1);
+		
+		memset(&map->location_key[0], 0, sizeof(map->location_key));
+		snprintf(map->location_key, sizeof(map->location_key) - 1, "/dev/%s", dev_name);
 
-       if ((entry = malloc(sizeof(*entry))) == NULL) {
-               syslog(LOG_WARNING, "hrDiskStorageTable: %s: %m", __func__);
-               return (NULL);
-       }
-       memset(entry, 0, sizeof(*entry));
 
+		map->entry_p = entry;
+		STAILQ_INSERT_TAIL(&hrState_g.device_name_map, map, link);
+		HR_DPRINTF((stderr, "%s at %s  added into hrDeviceMap at index=%d\n ",
+				dev_name, 
+				dev_name, map->hrIndex));
+	} else {
+		HR_DPRINTF((stderr, "%s at %s  exists in hrDeviceMap index=%d\n ",
+				dev_name, 
+				dev_name, map->hrIndex));
 
-       STAILQ_FOREACH(map, &hrState_g.device_name_map, link)
-               if (strcmp(map->name_key, dev_name) == 0) {
-                       entry->index = map->hrIndex;
-                       map->entry_p = entry;
-                       break;
-               }
-
-       if (map == NULL) {
-               /* new object - get a new index */
-               if (hrState_g.next_hrDevice_index > INT_MAX) {
-                       syslog(LOG_ERR, "%s: hrDeviceTable index wrap", __func__ );
-                       errx(1, "hrDeviceTable index wrap");
-               }
-
-               if ((map = malloc(sizeof(*map))) == NULL) {
-                       syslog(LOG_ERR, "hrStorageTable: %s: %m", __func__ );
-                       free(entry);
-                       return (NULL);
-               }
-               map->hrIndex = hrState_g.next_hrDevice_index ++;
-
-               memset(&map->name_key[0], 0, sizeof(map->name_key));
-               strncpy(map->name_key, dev_name, sizeof(map->name_key) - 1);
-
-               memset(&map->location_key[0], 0, sizeof(map->location_key));
-               snprintf(map->location_key, sizeof(map->location_key) - 1, "/dev/%s", dev_name);
-
-
-               map->entry_p = entry;
-               STAILQ_INSERT_TAIL(&hrState_g.device_name_map, map, link);
-               HR_DPRINTF((stderr, "%s at %s  added into hrDeviceMap at index=%d\n ",
-                               dev_name,
-                               dev_name, map->hrIndex));
-       } else {
-               HR_DPRINTF((stderr, "%s at %s  exists in hrDeviceMap index=%d\n ",
-                               dev_name,
-                               dev_name, map->hrIndex));
-
-       }
-
-       entry->index = map->hrIndex;
-       memset(&entry->name[0], 0, sizeof(entry->name));
-       strncpy(entry->name, dev_name, sizeof(entry->name) - 1);
-
-       memset(&entry->location[0], 0, sizeof(entry->location));
-       snprintf(entry->location, sizeof(entry->location) - 1, "/dev/%s", dev_name);
-
-       INSERT_OBJECT_INT(entry, &hrState_g.hr_device_tbl);
-
-       return entry;
-
+	}
+	
+	entry->index = map->hrIndex;
+	memset(&entry->name[0], 0, sizeof(entry->name));
+	strncpy(entry->name, dev_name, sizeof(entry->name) - 1);
+		
+	memset(&entry->location[0], 0, sizeof(entry->location));
+	snprintf(entry->location, sizeof(entry->location) - 1, "/dev/%s", dev_name);
+					
+	INSERT_OBJECT_INT(entry, &hrState_g.hr_device_tbl);
+	
+	return entry;
+	
 }
 
-
+ 
 static
 struct hrDeviceTblEntry*
 hrDeviceTblEntry_find_by_name(const char *dev_name) {
-       struct deviceNameMapEntry  *map;
-       assert(dev_name != NULL);
+	struct deviceNameMapEntry  *map;
+	assert(dev_name != NULL);
+		
 
-
-       STAILQ_FOREACH(map, &hrState_g.device_name_map, link)
-               if (strcmp(map->name_key, dev_name) == 0 ) {
-                       return (map->entry_p);
-               }
-       return (NULL);
+	STAILQ_FOREACH(map, &hrState_g.device_name_map, link)
+		if (strcmp(map->name_key, dev_name) == 0 ) {
+		    	return (map->entry_p);
+		}
+	return (NULL);
 }
 
 
-static
+static 
 void hrDiskStorage_queryDisk(struct hrDiskStorageTblEntry *entry){
-       char dev_path[128] = "";
-       int fd = -1;
-       if (entry == NULL) {
-               return;
-       }
-       if( entry->dev_name[0] == '\0' ) {
-               return;
-       }
-       snprintf(dev_path, sizeof(dev_path) - 1, "/dev/%s", entry->dev_name);
-       entry->capacity = 0;
-       HR_DPRINTF((stderr,"OPENING device %s\n",dev_path));
-       fd = open(dev_path, O_RDONLY|O_NONBLOCK);
-       if ( fd < 0 ) {
-               HR_DPRINTF((stderr,"OPEN device %s failed: %d (%s)\n",
-                       dev_path,
-                       errno,
-                       strerror(errno)));
-               goto QUERY_DONE;
-       } else {
-               off_t   mediasize = 0;
-               if (ioctl(fd, DIOCGMEDIASIZE, &mediasize) < 0) {
-                       HR_DPRINTF((stderr,"DIOCGMEDIASIZE for device %s failed: %d (%s)\n",
-                               dev_path,
-                               errno,
-                               strerror(errno)));
-                       goto QUERY_DONE;
-               }
-               mediasize = mediasize / 1024;
-               entry->capacity = (mediasize > (off_t)INT_MAX ? INT_MAX : mediasize);
-       }
+	char dev_path[128] = "";
+	int fd = -1;
+	if (entry == NULL) {
+		return;
+	}
+	if( entry->dev_name[0] == '\0' ) {
+		return;
+	}
+	snprintf(dev_path, sizeof(dev_path) - 1, "/dev/%s", entry->dev_name);
+	entry->capacity = 0;
+	HR_DPRINTF((stderr,"OPENING device %s\n",dev_path));
+	fd = open(dev_path, O_RDONLY|O_NONBLOCK);
+	if ( fd < 0 ) {
+		HR_DPRINTF((stderr,"OPEN device %s failed: %d (%s)\n",
+			dev_path, 
+			errno, 
+			strerror(errno)));
+		goto QUERY_DONE;
+	} else {
+		off_t	mediasize = 0;
+		if (ioctl(fd, DIOCGMEDIASIZE, &mediasize) < 0) {
+			HR_DPRINTF((stderr,"DIOCGMEDIASIZE for device %s failed: %d (%s)\n",
+				dev_path, 
+				errno, 
+				strerror(errno)));
+			goto QUERY_DONE;
+		}
+		mediasize = mediasize / 1024;
+		entry->capacity = (mediasize > (off_t)INT_MAX ? INT_MAX : mediasize);
+		if (entry->media == DSM_HARDDISK) {
+			/*this silly libdisk crashes if a empty cdrom device
+			is oppened*/
+			handleDiskStorage(entry->index, entry->dev_name);
+		}
+	}
 QUERY_DONE:
-       if (fd > 0) {
-               close(fd);
-       }
-
+	if (fd > 0) {
+		close(fd);
+	}
+	
+	
+			
+	
 }
-static
-void
+static 
+void 
 hrDiskStorage_OS_get_ATA_disks_v(void) {
-       struct hrDeviceTblEntry *entry = NULL;
-       struct hrDiskStorageTblEntry *disk_entry = NULL;
+	struct hrDeviceTblEntry *entry = NULL;
+	struct hrDiskStorageTblEntry *disk_entry = NULL;
 
 /*
  * Remove the pre 6 vesrion if not needed
  */
-#if __FreeBSD_version < 600000
+#if __FreeBSD_version < 600000 
 
-       struct ata_cmd iocmd;
-       int  maxunit, unit, i;
-       if ( hrState_g.ata_fd < 0 ){
-               return;
-       }
+	struct ata_cmd iocmd;
+	int  maxunit, unit, i;
+	if ( hrState_g.ata_fd < 0 ){
+		return;
+	}
+	
+	iocmd.cmd = ATAGMAXCHANNEL;
+	if (ioctl(hrState_g.ata_fd, IOCATA, &iocmd) < 0) {
+		syslog(LOG_ERR, "ioctl(ATAGMAXCHANNEL) failed: %m");
+		goto ATA_DONE;
+	}		
+	maxunit = iocmd.u.maxchan;
+	for (unit = 0; unit < maxunit; unit++) {
+		struct ata_cmd u_iocmd;
 
-       iocmd.cmd = ATAGMAXCHANNEL;
-       if (ioctl(hrState_g.ata_fd, IOCATA, &iocmd) < 0) {
-               syslog(LOG_ERR, "ioctl(ATAGMAXCHANNEL) failed: %m");
-               goto ATA_DONE;
-       }
-       maxunit = iocmd.u.maxchan;
-       for (unit = 0; unit < maxunit; unit++) {
-               struct ata_cmd u_iocmd;
+		memset(&u_iocmd, 0, sizeof(struct ata_cmd));
+		u_iocmd.channel = unit;
+		u_iocmd.device = -1;
+		u_iocmd.cmd = ATAGPARM;
+		if (ioctl(hrState_g.ata_fd, IOCATA, &u_iocmd) < 0) {
+			syslog(LOG_ERR, "ioctl(IOCATA) failed: %m");
+			continue;
+		}	
 
-               memset(&u_iocmd, 0, sizeof(struct ata_cmd));
-               u_iocmd.channel = unit;
-               u_iocmd.device = -1;
-               u_iocmd.cmd = ATAGPARM;
-               if (ioctl(hrState_g.ata_fd, IOCATA, &u_iocmd) < 0) {
-                       syslog(LOG_ERR, "ioctl(IOCATA) failed: %m");
-                       continue;
-               }
+		for(i=0; i<=1; i++) {
+		        if (!u_iocmd.u.param.type[i]) {
+				continue;
+			}
+			/*first check if this disk is in hrDeiveTable*/
+			entry = hrDeviceTblEntry_find_by_name(u_iocmd.u.param.name[i]);
+			if (entry == NULL) {
+				HR_DPRINTF((stderr,
+				"hrDiskStorageTable: ATA disk %s not in hrDeviceTable\n",
+				u_iocmd.u.param.name[i] ));
+				entry =  hrDeviceTblEntry_create(u_iocmd.u.param.name[i]);
+				assert(entry != NULL);
+				if (entry == NULL) {
+					continue;
+				}	
 
-               for(i=0; i<=1; i++) {
-                       if (!u_iocmd.u.param.type[i]) {
-                               continue;
-                       }
-                       /*first check if this disk is in hrDeiveTable*/
-                       entry = hrDeviceTblEntry_find_by_name(u_iocmd.u.param.name[i]);
-                       if (entry == NULL) {
-                               HR_DPRINTF((stderr,
-                               "hrDiskStorageTable: ATA disk %s not in hrDeviceTable\n",
-                               u_iocmd.u.param.name[i] ));
-                               entry =  hrDeviceTblEntry_create(u_iocmd.u.param.name[i]);
-                               assert(entry != NULL);
-                               if (entry == NULL) {
-                                       continue;
-                               }
-
-                               entry->type = (struct asn_oid)OIDX_hrDeviceDiskStorage;
-                               entry->id = oid_zeroDotZero; /*unknown id - FIX ME*/
-                               entry->status = DR_RUNNING;
-                               entry->errors = 0; /*FIX ME*/
-                               snprintf(entry->descr, sizeof(entry->descr) - 1,
-                                       "%s: <%s, ser. %s> ",
-                                       u_iocmd.u.param.name[i],
-                                       u_iocmd.u.param.params[i].model,
-                                       u_iocmd.u.param.params[i].serial);
-
-                       }else{
-                               HR_DPRINTF((stderr,
-                               "hrDiskStorageTable; ATA disk %s already in hrDeviceTable\n",
-                               u_iocmd.u.param.name[i] ));
-                       }
-                       entry->flags |= HR_DEVICE_IMMUTABLE;
-                       entry->flags |= HR_DEVICE_FOUND;
-
-                       /*Then check hrDiskStorage table for this device*/
-                       disk_entry = hrDiskStorageTblEntry_find_by_index(entry->index);
-                       if (disk_entry == NULL) {
-                               disk_entry = hrDiskStorageEntry_create(entry);
-                               assert(disk_entry != NULL);
-                               if (disk_entry == NULL) {
-                                       continue;
-                               }
-                               disk_entry->access = DS_READ_WRITE;
-                               memset(&disk_entry->dev_name[0], 0, sizeof(disk_entry->dev_name));
-                               strncpy(disk_entry->dev_name, u_iocmd.u.param.name[i], sizeof(disk_entry->dev_name)-1);
-
-                               if (strncmp(disk_entry->dev_name, "ad", strlen("ad")) == 0) {
-                                       disk_entry->media = DSM_HARDDISK;
-                                       disk_entry->removable = SNMP_FALSE;
-                               } else if (strncmp(disk_entry->dev_name, "ar", strlen("ar")) == 0) {
-                                       disk_entry->media = DSM_OTHER;
-                                       disk_entry->removable = SNMP_FALSE;
-                               } else if (strncmp(disk_entry->dev_name, "acd", strlen("acd")) == 0) {
-                                       disk_entry->media = DSM_OPTICALDISKROM;
-                                       disk_entry->removable = SNMP_TRUE;
-                               } else if (strncmp(disk_entry->dev_name, "afd", strlen("afd")) == 0) {
-                                       disk_entry->media = DSM_FLOPPYDISK;
-                                       disk_entry->removable = SNMP_TRUE;
-                               } else if (strncmp(disk_entry->dev_name, "ast", strlen("ast")) == 0) {
-                                       disk_entry->media = DSM_OTHER;
-                                       disk_entry->removable = SNMP_TRUE;
-                               } else {
-                                       disk_entry->media = DSM_UNKNOWN;
-                                       disk_entry->removable = SNMP_FALSE;
-                               }
-
-                       }
-                       disk_entry->flags |= HR_DISKSTORAGE_FOUND;
-                       disk_entry->flags |= HR_DISKSTORAGE_ATA;
-
-                       hrDiskStorage_queryDisk(disk_entry);
-                       disk_entry->r_tick = this_tick;
-               }
-       }
+				entry->type = (struct asn_oid)OIDX_hrDeviceDiskStorage;
+				entry->id = oid_zeroDotZero; /*unknown id - FIX ME*/
+				entry->status = DR_RUNNING;
+				entry->errors = 0; /*FIX ME*/
+				snprintf(entry->descr, sizeof(entry->descr) - 1, 
+					"%s: <%s, ser. %s> ",
+					u_iocmd.u.param.name[i],
+					u_iocmd.u.param.params[i].model,
+					u_iocmd.u.param.params[i].serial);
+				
+			}else{
+				HR_DPRINTF((stderr,
+				"hrDiskStorageTable; ATA disk %s already in hrDeviceTable\n",
+				u_iocmd.u.param.name[i] ));
+			}
+			entry->flags |= HR_DEVICE_IMMUTABLE;
+			entry->flags |= HR_DEVICE_FOUND;
+						
+			/*Then check hrDiskStorage table for this device*/
+			disk_entry = hrDiskStorageTblEntry_find_by_index(entry->index);
+			if (disk_entry == NULL) {
+				disk_entry = hrDiskStorageEntry_create(entry);
+				assert(disk_entry != NULL);
+				if (disk_entry == NULL) {
+					continue;
+				}
+				disk_entry->access = DS_READ_WRITE;
+				memset(&disk_entry->dev_name[0], 0, sizeof(disk_entry->dev_name));
+				strncpy(disk_entry->dev_name, u_iocmd.u.param.name[i], sizeof(disk_entry->dev_name)-1);
+			
+				if (strncmp(disk_entry->dev_name, "ad", strlen("ad")) == 0) {
+					disk_entry->media = DSM_HARDDISK;
+					disk_entry->removable = SNMP_FALSE;
+				} else if (strncmp(disk_entry->dev_name, "ar", strlen("ar")) == 0) {
+					disk_entry->media = DSM_OTHER;
+					disk_entry->removable = SNMP_FALSE;
+				} else if (strncmp(disk_entry->dev_name, "acd", strlen("acd")) == 0) {
+					disk_entry->media = DSM_OPTICALDISKROM;
+					disk_entry->removable = SNMP_TRUE;
+				} else if (strncmp(disk_entry->dev_name, "afd", strlen("afd")) == 0) {
+					disk_entry->media = DSM_FLOPPYDISK;
+					disk_entry->removable = SNMP_TRUE;
+				} else if (strncmp(disk_entry->dev_name, "ast", strlen("ast")) == 0) {
+					disk_entry->media = DSM_OTHER;
+					disk_entry->removable = SNMP_TRUE;
+				} else {
+					disk_entry->media = DSM_UNKNOWN;
+					disk_entry->removable = SNMP_FALSE;
+				}
+				
+			}
+			disk_entry->flags |= HR_DISKSTORAGE_FOUND; 
+			disk_entry->flags |= HR_DISKSTORAGE_ATA;
+			
+			hrDiskStorage_queryDisk(disk_entry);
+			disk_entry->r_tick = this_tick;
+		}
+	}				
 ATA_DONE:
-       return;
+	return;
 #else
 /*
  * This the post 6 version: it is here to stay
  */
 
-       int  maxunit, unit, i;
-       if ( hrState_g.ata_fd < 0 ){
-               return;
-       }
+	int  maxunit, unit, i;
+	if ( hrState_g.ata_fd < 0 ){
+		return;
+	}
+	
+	
+	if (ioctl(hrState_g.ata_fd, IOCATAGMAXCHANNEL, &maxunit) < 0) {
+		syslog(LOG_ERR, "ioctl(IOCATAGMAXCHANNEL) failed: %m");
+		goto ATA_DONE;
+	}		
 
+	for (unit = 0; unit < maxunit; unit++) {
+		struct ata_ioc_devices devices;
+		memset(&devices, 0, sizeof(devices));
+		
+		devices.channel = unit;
 
-       if (ioctl(hrState_g.ata_fd, IOCATAGMAXCHANNEL, &maxunit) < 0) {
-               syslog(LOG_ERR, "ioctl(IOCATAGMAXCHANNEL) failed: %m");
-               goto ATA_DONE;
-       }
 
-       for (unit = 0; unit < maxunit; unit++) {
-               struct ata_ioc_devices devices;
-               memset(&devices, 0, sizeof(devices));
+		if (ioctl(hrState_g.ata_fd, IOCATADEVICES, &devices) < 0) {
+			HR_DPRINTF((stderr, "ioctl(IOCATADEVICES) failed: %s\n", strerror(errno)));
+			continue;
+		}	
 
-               devices.channel = unit;
+		for(i=0; i<=1; i++) {
+		        if (*devices.name[i] == 0) {
+				continue;
+			}
+			/*first check if this disk is in hrDeiveTable*/
+			entry = hrDeviceTblEntry_find_by_name(devices.name[i]);
+			if (entry == NULL) {
+				HR_DPRINTF((stderr,
+				"hrDiskStorageTable: ATA disk %s not in hrDeviceTable\n",
+				devices.name[i] ));
+				entry =  hrDeviceTblEntry_create(devices.name[i]);
+				assert(entry != NULL);
+				if (entry == NULL) {
+					continue;
+				}	
 
-
-               if (ioctl(hrState_g.ata_fd, IOCATADEVICES, &devices) < 0) {
-                       HR_DPRINTF((stderr, "ioctl(IOCATADEVICES) failed: %s\n", strerror(errno)));
-                       continue;
-               }
-
-               for(i=0; i<=1; i++) {
-                       if (*devices.name[i] == 0) {
-                               continue;
-                       }
-                       /*first check if this disk is in hrDeiveTable*/
-                       entry = hrDeviceTblEntry_find_by_name(devices.name[i]);
-                       if (entry == NULL) {
-                               HR_DPRINTF((stderr,
-                               "hrDiskStorageTable: ATA disk %s not in hrDeviceTable\n",
-                               devices.name[i] ));
-                               entry =  hrDeviceTblEntry_create(devices.name[i]);
-                               assert(entry != NULL);
-                               if (entry == NULL) {
-                                       continue;
-                               }
-
-                               entry->type = (struct asn_oid)OIDX_hrDeviceDiskStorage;
-                               entry->id = oid_zeroDotZero; /*unknown id - FIX ME*/
-                               entry->status = DR_RUNNING;
-                               entry->errors = 0; /*FIX ME*/
-                               snprintf(entry->descr, sizeof(entry->descr) - 1,
-                                       "%s: <%s, ser. %s> ",
-                                       devices.name[i],
-                                       devices.params[i].model,
-                                       devices.params[i].serial);
-
-                       }else{
-                               HR_DPRINTF((stderr,
-                               "hrDiskStorageTable; ATA disk %s already in hrDeviceTable\n",
-                               devices.name[i] ));
-                       }
-                       entry->flags |= HR_DEVICE_IMMUTABLE;
-                       entry->flags |= HR_DEVICE_FOUND;
-
-                       /*Then check hrDiskStorage table for this device*/
-                       disk_entry = hrDiskStorageTblEntry_find_by_index(entry->index);
-                       if (disk_entry == NULL) {
-                               disk_entry = hrDiskStorageEntry_create(entry);
-                               assert(disk_entry != NULL);
-                               if (disk_entry == NULL) {
-                                       continue;
-                               }
-                               disk_entry->access = DS_READ_WRITE;
-                               memset(&disk_entry->dev_name[0], 0,
-                                       sizeof(disk_entry->dev_name));
-                               strncpy(disk_entry->dev_name,
-                                       devices.name[i],
-                                       sizeof(disk_entry->dev_name)-1);
-
-                               if (strncmp(disk_entry->dev_name, "ad", strlen("ad")) == 0) {
-                                       disk_entry->media = DSM_HARDDISK;
-                                       disk_entry->removable = SNMP_FALSE;
-                               } else if (strncmp(disk_entry->dev_name, "ar", strlen("ar")) == 0) {
-                                       disk_entry->media = DSM_OTHER;
-                                       disk_entry->removable = SNMP_FALSE;
-                               } else if (strncmp(disk_entry->dev_name, "acd", strlen("acd")) == 0) {
-                                       disk_entry->media = DSM_OPTICALDISKROM;
-                                       disk_entry->removable = SNMP_TRUE;
-                               } else if (strncmp(disk_entry->dev_name, "afd", strlen("afd")) == 0) {
-                                       disk_entry->media = DSM_FLOPPYDISK;
-                                       disk_entry->removable = SNMP_TRUE;
-                               } else if (strncmp(disk_entry->dev_name, "ast", strlen("ast")) == 0) {
-                                       disk_entry->media = DSM_OTHER;
-                                       disk_entry->removable = SNMP_TRUE;
-                               } else {
-                                       disk_entry->media = DSM_UNKNOWN;
-                                       disk_entry->removable = SNMP_FALSE;
-                               }
-
-                       }
-                       disk_entry->flags |= HR_DISKSTORAGE_FOUND;
-                       disk_entry->flags |= HR_DISKSTORAGE_ATA;
-
-                       hrDiskStorage_queryDisk(disk_entry);
-                       disk_entry->r_tick = this_tick;
-               }
-       }
+				entry->type = (struct asn_oid)OIDX_hrDeviceDiskStorage;
+				entry->id = oid_zeroDotZero; /*unknown id - FIX ME*/
+				entry->status = DR_RUNNING;
+				entry->errors = 0; /*FIX ME*/
+				snprintf(entry->descr, sizeof(entry->descr) - 1, 
+					"%s: <%s, ser. %s> ",
+					devices.name[i],
+					devices.params[i].model,
+					devices.params[i].serial);
+				
+			}else{
+				HR_DPRINTF((stderr,
+				"hrDiskStorageTable; ATA disk %s already in hrDeviceTable\n",
+				devices.name[i] ));
+			}
+			entry->flags |= HR_DEVICE_IMMUTABLE;
+			entry->flags |= HR_DEVICE_FOUND;
+						
+			/*Then check hrDiskStorage table for this device*/
+			disk_entry = hrDiskStorageTblEntry_find_by_index(entry->index);
+			if (disk_entry == NULL) {
+				disk_entry = hrDiskStorageEntry_create(entry);
+				assert(disk_entry != NULL);
+				if (disk_entry == NULL) {
+					continue;
+				}
+				disk_entry->access = DS_READ_WRITE;
+				memset(&disk_entry->dev_name[0], 0, 
+					sizeof(disk_entry->dev_name));
+				strncpy(disk_entry->dev_name, 
+					devices.name[i], 
+					sizeof(disk_entry->dev_name)-1);
+			
+				if (strncmp(disk_entry->dev_name, "ad", strlen("ad")) == 0) {
+					disk_entry->media = DSM_HARDDISK;
+					disk_entry->removable = SNMP_FALSE;
+				} else if (strncmp(disk_entry->dev_name, "ar", strlen("ar")) == 0) {
+					disk_entry->media = DSM_OTHER;
+					disk_entry->removable = SNMP_FALSE;
+				} else if (strncmp(disk_entry->dev_name, "acd", strlen("acd")) == 0) {
+					disk_entry->media = DSM_OPTICALDISKROM;
+					disk_entry->removable = SNMP_TRUE;
+				} else if (strncmp(disk_entry->dev_name, "afd", strlen("afd")) == 0) {
+					disk_entry->media = DSM_FLOPPYDISK;
+					disk_entry->removable = SNMP_TRUE;
+				} else if (strncmp(disk_entry->dev_name, "ast", strlen("ast")) == 0) {
+					disk_entry->media = DSM_OTHER;
+					disk_entry->removable = SNMP_TRUE;
+				} else {
+					disk_entry->media = DSM_UNKNOWN;
+					disk_entry->removable = SNMP_FALSE;
+				}
+				
+			}
+			disk_entry->flags |= HR_DISKSTORAGE_FOUND; 
+			disk_entry->flags |= HR_DISKSTORAGE_ATA;
+			
+			hrDiskStorage_queryDisk(disk_entry);
+			disk_entry->r_tick = this_tick;
+		}
+	}				
 ATA_DONE:
-       return;
+	return;
 
 #endif /* __FreeBSD_version < 600000 */
-}
+}	
 
-static
-void
+static 
+void 
 hrDiskStorage_OS_get_MD_disks_v(void) {
-       struct hrDeviceTblEntry *entry = NULL;
-       struct hrDiskStorageTblEntry *disk_entry = NULL;
+	struct hrDeviceTblEntry *entry = NULL;
+	struct hrDiskStorageTblEntry *disk_entry = NULL;
 
-       struct md_ioctl mdio;
-       int  unit = 0;
+	struct md_ioctl mdio;
+	int  unit = 0;
 
+	
+	if ( hrState_g.md_fd < 0 ){
+		return;
+	}
+	memset(&mdio, 0, sizeof(mdio));
+	mdio.md_version = MDIOVERSION;
+	mdio.md_options = MD_AUTOUNIT;
+	
+	if (ioctl( hrState_g.md_fd, MDIOCLIST, &mdio) < 0) {
+		syslog(LOG_ERR, "ioctl(/dev/%s) failed: %m", MDCTL_NAME);
+		return;
+	}	
+	for (unit = 0; unit < mdio.md_pad[0] && unit < MDNPAD - 1; unit++) {
+		char mddev[64] = "";
+		snprintf(mddev, sizeof(mddev) - 1, "%s%d", MD_NAME, mdio.md_pad[unit + 1]);
+		struct md_ioctl u_mdio;
 
-       if ( hrState_g.md_fd < 0 ){
-               return;
-       }
-       memset(&mdio, 0, sizeof(mdio));
-       mdio.md_version = MDIOVERSION;
-       mdio.md_options = MD_AUTOUNIT;
+		memset(&u_mdio, 0, sizeof(u_mdio));
+		u_mdio.md_version = MDIOVERSION;
+		u_mdio.md_unit = mdio.md_pad[unit + 1];
 
-       if (ioctl( hrState_g.md_fd, MDIOCLIST, &mdio) < 0) {
-               syslog(LOG_ERR, "ioctl(/dev/%s) failed: %m", MDCTL_NAME);
-               return;
-       }
-       for (unit = 0; unit < mdio.md_pad[0] && unit < MDNPAD - 1; unit++) {
-               char mddev[64] = "";
-               snprintf(mddev, sizeof(mddev) - 1, "%s%d", MD_NAME, mdio.md_pad[unit + 1]);
-               struct md_ioctl u_mdio;
+		if (ioctl( hrState_g.md_fd, MDIOCQUERY, &u_mdio) < 0) {
+			syslog(LOG_ERR, "ioctl(/dev/%s, MDIOCQUERY) [%s] failed: %m", MDCTL_NAME, mddev);
+			continue;
+		}
 
-               memset(&u_mdio, 0, sizeof(u_mdio));
-               u_mdio.md_version = MDIOVERSION;
-               u_mdio.md_unit = mdio.md_pad[unit + 1];
 
-               if (ioctl( hrState_g.md_fd, MDIOCQUERY, &u_mdio) < 0) {
-                       syslog(LOG_ERR, "ioctl(/dev/%s, MDIOCQUERY) [%s] failed: %m", MDCTL_NAME, mddev);
-                       continue;
-               }
+		/*first check if this disk is in hrDeiveTable*/
+		entry = hrDeviceTblEntry_find_by_name(mddev);
+		if (entry == NULL) {
+			HR_DPRINTF((stderr,
+			 "hrDiskStorageTable; MD %s not in hrDeviceTable\n",
+			  mddev ));
+			entry =  hrDeviceTblEntry_create(mddev);
+			assert(entry != NULL);
+			if (entry == NULL) {
+				continue;
+			}	
 
+			entry->type = (struct asn_oid)OIDX_hrDeviceDiskStorage;
+			entry->id = oid_zeroDotZero; /*unknown id - FIX ME*/
+			entry->status = DR_RUNNING;
+			entry->errors = 0; /*FIX ME*/
+			snprintf(entry->descr, sizeof(entry->descr) - 1, 
+				"%s: Memory Disk ",
+				 mddev);
+			
+		}else{
+			HR_DPRINTF((stderr,
+			"hrDiskStorageTable; MD %s already in hrDeviceTable\n",
+			mddev ));
+		}
+		entry->flags |= HR_DEVICE_IMMUTABLE;
+		entry->flags |= HR_DEVICE_FOUND;
+					
+		/*Then check hrDiskStorage table for this device*/
+		disk_entry = hrDiskStorageTblEntry_find_by_index(entry->index);
+		if (disk_entry == NULL) {
+			disk_entry = hrDiskStorageEntry_create(entry);
+			assert(disk_entry != NULL);
+			if (disk_entry == NULL) {
+				continue;
+			}
+			if ((u_mdio.md_options & MD_READONLY) == MD_READONLY) {
+				disk_entry->access = DS_READ_ONLY;
+			} else {
+				disk_entry->access = DS_READ_WRITE;
+			}
+			memset(&disk_entry->dev_name[0], 0, sizeof(disk_entry->dev_name));
+			strncpy(disk_entry->dev_name, mddev, sizeof(disk_entry->dev_name)-1);
 
-               /*first check if this disk is in hrDeiveTable*/
-               entry = hrDeviceTblEntry_find_by_name(mddev);
-               if (entry == NULL) {
-                       HR_DPRINTF((stderr,
-                        "hrDiskStorageTable; MD %s not in hrDeviceTable\n",
-                         mddev ));
-                       entry =  hrDeviceTblEntry_create(mddev);
-                       assert(entry != NULL);
-                       if (entry == NULL) {
-                               continue;
-                       }
-
-                       entry->type = (struct asn_oid)OIDX_hrDeviceDiskStorage;
-                       entry->id = oid_zeroDotZero; /*unknown id - FIX ME*/
-                       entry->status = DR_RUNNING;
-                       entry->errors = 0; /*FIX ME*/
-                       snprintf(entry->descr, sizeof(entry->descr) - 1,
-                               "%s: Memory Disk ",
-                                mddev);
-
-               }else{
-                       HR_DPRINTF((stderr,
-                       "hrDiskStorageTable; MD %s already in hrDeviceTable\n",
-                       mddev ));
-               }
-               entry->flags |= HR_DEVICE_IMMUTABLE;
-               entry->flags |= HR_DEVICE_FOUND;
-
-               /*Then check hrDiskStorage table for this device*/
-               disk_entry = hrDiskStorageTblEntry_find_by_index(entry->index);
-               if (disk_entry == NULL) {
-                       disk_entry = hrDiskStorageEntry_create(entry);
-                       assert(disk_entry != NULL);
-                       if (disk_entry == NULL) {
-                               continue;
-                       }
-                       if ((u_mdio.md_options & MD_READONLY) == MD_READONLY) {
-                               disk_entry->access = DS_READ_ONLY;
-                       } else {
-                               disk_entry->access = DS_READ_WRITE;
-                       }
-                       memset(&disk_entry->dev_name[0], 0, sizeof(disk_entry->dev_name));
-                       strncpy(disk_entry->dev_name, mddev, sizeof(disk_entry->dev_name)-1);
-
-                       disk_entry->media = DSM_RAMDISK;
-                       disk_entry->removable = SNMP_FALSE;
-
-
-               }
-               disk_entry->flags |= HR_DISKSTORAGE_FOUND;
-               disk_entry->flags |= HR_DISKSTORAGE_MD;
+			disk_entry->media = DSM_RAMDISK;
+			disk_entry->removable = SNMP_FALSE;
+		
+			
+		}
+		disk_entry->flags |= HR_DISKSTORAGE_FOUND; 
+		disk_entry->flags |= HR_DISKSTORAGE_MD;
 /*
  * Remove the pre 6 vesrion if not needed
  */
-#if __FreeBSD_version < 600000
-               disk_entry->capacity = u_mdio.md_size / 2;
-#else
-               disk_entry->capacity = u_mdio.md_mediasize / 1024;
-#endif /*__FreeBSD_version < 600000 */
-               disk_entry->r_tick = this_tick;

>>> TRUNCATED FOR MAIL (1000 lines) <<<


More information about the p4-projects mailing list