Skip site navigation (1)Skip section navigation (2)
Date:      Sat, 30 Jul 2005 23:11:13 GMT
From:      Victor Cruceru <soc-victor@FreeBSD.org>
To:        Perforce Change Reviews <perforce@freebsd.org>
Subject:   PERFORCE change 81218 for review
Message-ID:  <200507302311.j6UNBDCs007042@repoman.freebsd.org>

next in thread | raw e-mail | index | archive | help
http://perforce.freebsd.org/chv.cgi?CH=81218

Change 81218 by soc-victor@soc-victor_82.76.158.176 on 2005/07/30 23:11:09

	Added the SNMP instrumentation for hrDiskStorageTable (the very first version).
	Updated the hrDeviceTable accordingly. Also fixed a bug in devd Unix socket
	read part of hrDeviceTable code (zero length read means the devd process
	is dead). hrDiskStorageTable's instrumentation  needs many improvements.

Affected files ...

.. //depot/projects/soc2005/bsnmp/usr.sbin/bsnmpd/modules/snmp_hostres/Makefile#14 edit
.. //depot/projects/soc2005/bsnmp/usr.sbin/bsnmpd/modules/snmp_hostres/hostres_device_tbl.c#6 edit
.. //depot/projects/soc2005/bsnmp/usr.sbin/bsnmpd/modules/snmp_hostres/hostres_diskstorage_tbl.c#1 add
.. //depot/projects/soc2005/bsnmp/usr.sbin/bsnmpd/modules/snmp_hostres/hostres_snmp.c#12 edit
.. //depot/projects/soc2005/bsnmp/usr.sbin/bsnmpd/modules/snmp_hostres/hostres_snmp.h#16 edit

Differences ...

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

@@ -33,11 +33,12 @@
 	hostres_storage_tbl.c hostres_fs_tbl.c \
 	hostres_swrun_tbl.c hostres_swrunperf_tbl.c \
 	hostres_device_tbl.c \
-	hostres_processor_tbl.c
+	hostres_processor_tbl.c \
+	hostres_diskstorage_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 \

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

@@ -42,9 +42,15 @@
 #include <unistd.h>
 #include <errno.h>
 
-/*just a prototype*/
+/*some prototypes*/
 int hr_device_collector(struct devinfo_dev *dev, void *arg); 
 
+void
+hrDeviceTblEntry_delete_v( struct hrDeviceTblEntry* entry );
+
+struct hrDeviceTblEntry *
+hrDeviceTblEntry_find_by_index(int32_t idx);
+
 static
 struct hrDeviceTblEntry* 
 hrDeviceTblEntry_create( const struct devinfo_dev *dev_p) {
@@ -126,7 +132,7 @@
 	
 }
 
-static
+
 void
 hrDeviceTblEntry_delete_v( struct hrDeviceTblEntry* entry ) {
 	struct deviceNameMapEntry  *map;
@@ -158,7 +164,7 @@
 	return (NULL);
 }
 
-static
+
 struct hrDeviceTblEntry *
 hrDeviceTblEntry_find_by_index(int32_t idx) {
 
@@ -316,8 +322,9 @@
 
 		
 	/*mark each entry as missing*/
-	TAILQ_FOREACH(entry, &hrState_g.hr_device_tbl, link)
+	TAILQ_FOREACH(entry, &hrState_g.hr_device_tbl, link) {
 		entry->flags &= ~HR_DEVICE_FOUND;
+	}
 	
 	hrDevice_OS_get_devices_v();
 
@@ -327,7 +334,7 @@
 	entry = TAILQ_FIRST(&hrState_g.hr_device_tbl);
 	while (entry != NULL) {
 		entry_tmp = TAILQ_NEXT(entry, link);
-		if (!(entry->flags & HR_DEVICE_FOUND))
+		if (!(entry->flags & HR_DEVICE_FOUND) && !(entry->flags & HR_DEVICE_IMMUTABLE) )
 			hrDeviceTblEntry_delete_v(entry);
 		entry = entry_tmp;
 	}
@@ -340,7 +347,10 @@
 	devinfo_free();		
 	hrState_g.dev_root =  NULL;
 
-						
+	/*
+	 *  Force a refresh for the hrDiskStorageTable
+	 */					
+	refresh_DiskStorage_tbl_v(); 
 	HR_DPRINTF((stderr, "%s: refresh DONE\n ",__func__));
 
 }
@@ -390,7 +400,18 @@
 		}
 		
 	} else if (read_len == 0) {
-		syslog(LOG_ERR,"zero bytes read from devd pipe....");
+		syslog(LOG_ERR,"zero bytes read from devd pipe....closing socket! ");
+		if (close(hrState_g.devd_sock) < 0 ){
+ 			syslog(LOG_ERR,"Failed to close the devd socket: %m");
+ 		}
+		hrState_g.devd_sock = -1;
+		if (hrState_g.devd_fd != NULL) {
+				fd_deselect(hrState_g.devd_fd);
+				hrState_g.devd_fd = NULL;
+		}			
+		syslog(LOG_ERR,"Closing devd_fd, revert to devinfo polling");
+		
+
 	} else {
 		switch(buf[0]){
 			case '+':

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

@@ -120,17 +120,23 @@
 	hrState_g.ccpu = 0;	
 	TAILQ_INIT(&hrState_g.hr_processor_tbl);
 
+	/*data structure initialization for hrDiskStorageTable*/	
+	TAILQ_INIT(&hrState_g.hr_disk_storage_tbl);
+	hrState_g.disk_list = NULL;
+	hrState_g.disk_list_len = 0;	
+	
 	hrState_g.hr_storage_tick = 0;
 	hrState_g.hr_fs_tick = 0;
 	hrState_g.hr_swrun_tick = 0;
 	hrState_g.hr_device_tick = 0;
 	hrState_g.hr_processor_tick = 0;
+	hrState_g.hr_disk_storage_tick = 0;
 	
 	hrState_g.hrStorage_tbl_age = 0;		
 	hrState_g.hrFS_tbl_age = 0;		
 	hrState_g.hrSWRun_tbl_age = 0;	
 	hrState_g.hrDevice_tbl_age = 0;	
-	
+	hrState_g.hrDiskStorage_age = 0;	
 	
 	init_hrStorage_tbl_v();
 	init_hrFS_tbl_v();
@@ -139,16 +145,7 @@
 	init_hrDevice_tbl_v();			       
 	init_hrProcessor_tbl_v();			       			
 	
-	/*
-	 * Start the cpu stats collector
-	 * The semantics of timer_start parameters is in "SNMP ticks";  
-	 * we have 100 "SNMP ticks" per second, thus we are trying below
-	 * to get MAX_CPU_SAMPLES per minute
-	 */
-	
-	hrState_g.cpus_load_timer = 
-		timer_start(100, 100*60/MAX_CPU_SAMPLES, get_cpus_samples, NULL, mod);
-		
+	init_hrDiskStorage_tbl_v();	
         
 
 	if ((hrState_g.devd_sock = create_devd_socket()) < 0) {
@@ -213,20 +210,22 @@
 	fini_hrStorage_tbl_v();
 	fini_hrFS_tbl_v();
 	fini_hrSWRun_tbl_v();
+	fini_hrProcessor_tbl_v();
+	fini_DiskStorage_tbl_v();
 	fini_hrDevice_tbl_v();
-	fini_hrProcessor_tbl_v();
 
 	hrState_g.hr_storage_tick = 0;
 	hrState_g.hr_fs_tick = 0;
 	hrState_g.hr_swrun_tick = 0;
 	hrState_g.hr_device_tick = 0;
 	hrState_g.hr_processor_tick = 0;
+	hrState_g.hr_disk_storage_tick = 0;
 
 	hrState_g.hrStorage_tbl_age = 0;		
 	hrState_g.hrFS_tbl_age = 0;		
 	hrState_g.hrSWRun_tbl_age = 0;	
 	hrState_g.hrDevice_tbl_age = 0;
-
+	hrState_g.hrDiskStorage_age = 0;	
 		
 	hrState_g.dev_root = NULL;
 	
@@ -322,6 +321,17 @@
 			syslog(LOG_ERR, "fd_select failed on devd socket: %m");
 		}
 	}   
+
+	/*
+	 * Start the cpu stats collector
+	 * The semantics of timer_start parameters is in "SNMP ticks";  
+	 * we have 100 "SNMP ticks" per second, thus we are trying below
+	 * to get MAX_CPU_SAMPLES per minute
+	 */
+	
+	hrState_g.cpus_load_timer = 
+		timer_start(100, 100*60/MAX_CPU_SAMPLES, get_cpus_samples, NULL, hostres_module);
+		
         HR_DPRINTF((stderr, "[%s] done.\n ", __func__));       
 }
 
@@ -369,14 +379,6 @@
 }
 
 
-int op_hrDiskStorageTable(struct snmp_context *ctx __unused, 
-                struct snmp_value *value __unused, 
-		u_int sub __unused, 
-		u_int iidx __unused, 
-		enum snmp_op curr_op __unused)
-{
-	return  (SNMP_ERR_NOSUCHNAME);
-}
 
 
 int op_hrPartitionTable(struct snmp_context *ctx __unused, 

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

@@ -216,14 +216,45 @@
 	u_char 		cpu_no;		/*which cpu, counted from 0*/
 	pid_t		idle_pid;	/*the PID of idle process for this CPU */
 	double		samples[MAX_CPU_SAMPLES]; /*the samples from the last 
-						    minutes, as required by MIB*/
+						    minute, as required by MIB*/
 	uint32_t	cur_sample_idx;		  /*current sample to fill in next time,
 						    must be < MAX_CPU_SAMPLES*/
 };
 
 TAILQ_HEAD(processor_tbl, hrProcessorTblEntry);
 
+enum hrDiskStrorageAccess {
+	DS_READ_WRITE = 1,
+	DS_READ_ONLY  = 2
+};
 
+enum hrDiskStrorageMedia {
+	DSM_OTHER	=	1,
+	DSM_UNKNOWN	=	2,
+	DSM_HARDDISK	=	3,
+	DSM_FLOPPYDISK	=	4,
+	DSM_OPTICALDISKROM=	5,
+	DSM_OPTICALDISKWORM=	6,
+	DSM_OPTICALDISKRW=	7,
+	DSM_RAMDISK	=	8
+};
+
+struct hrDiskStorageTblEntry {
+	int32_t		index;
+	int32_t		access; /*enum hrDiskStrorageAccess */
+	int32_t		media;	/*enum hrDiskStrorageMedia*/
+	int32_t		removable; /*enum snmpTCTruthValue*/
+	int32_t		capacity; 
+	TAILQ_ENTRY(hrDiskStorageTblEntry) link;	
+	/*next items are not from the SNMP mib table, only to be used internally*/
+#define HR_DISKSTORAGE_FOUND		0x001		
+	uint32_t	flags;	
+	uint64_t	r_tick;
+	
+};
+
+TAILQ_HEAD(disk_storage_tbl, hrDiskStorageTblEntry);
+
 enum DeviceStatus {
 	DS_UNKNOWN	=	1,
 	DR_RUNNING	=	2,
@@ -245,7 +276,8 @@
 	int32_t		status;		/* one item from enum DeviceStatus, see above */
 	uint32_t	errors;
 
-#define HR_DEVICE_FOUND 0x001
+#define HR_DEVICE_FOUND		0x001
+#define HR_DEVICE_IMMUTABLE	0x002  /* not dectected by libdevice, so don't try to refresh it*/
 	/*next 3 are not from the SNMP mib table, only to be used internally*/
 	uint32_t	flags;		
 	u_char		name[32+1];	
@@ -360,6 +392,16 @@
 	uint64_t 	hr_processor_tick;	/*last (agent) tick when hrProcessorTable was updated */
 	void*		cpus_load_timer;	/*periodic time used to get cpu laod stats*/
 											  						  					  
+
+	/* 
+	 * next items are used for hrDiskStorageTable 
+	 */
+	struct 
+	disk_storage_tbl	hr_disk_storage_tbl;	/*the head of the list with hrDiskStorageTable's entries */	
+	uint64_t		hr_disk_storage_tick;
+	time_t			hrDiskStorage_age;
+	char*			disk_list;		/*returned by sysctl("kern.disks")*/
+	size_t			disk_list_len;
 				
 };
 
@@ -446,12 +488,12 @@
 hrSWRunTblEntry_find_by_index(int32_t idx); 
 
 /*
- * Init the things for both of hrSWRunTable an hrSWRunPerfTable
+ * Init the things for both of hrSWRunTable and hrSWRunPerfTable
  */
 void init_hrSWRun_tbl_v(void);
 
 /*
- * Finalization routine for both of hrSWRunTable an hrSWRunPerfTable
+ * Finalization routine for both of hrSWRunTable and hrSWRunPerfTable
  * It destroys the lists and frees any allocated heap memory
  */
 void fini_hrSWRun_tbl_v(void);
@@ -533,5 +575,28 @@
  *  Each CPU is "visited" MAX_CPU_SAMPLES times per one minute
  */
 void get_cpus_samples(void*);
+
+/*
+ * Init the things for both of hrDiskStorageTable 
+ */
+void init_hrDiskStorage_tbl_v(void);
+
+/*
+ * Finalization routine for hrDiskStorageTable 
+ * It destroys the lists and frees any allocated heap memory
+ */
+void fini_DiskStorage_tbl_v(void);
+
+/*
+ * Next macro represents the number of seconds
+ * between two consecutive queries to the OS for getting the new data
+ */
+#define HR_DISKSTORAGE_TBL_REFRESH	3
+/*
+ * Refresh routine for hrDiskStorageTable 
+ * Usable for polling the system for any changes.
+ */
+void refresh_DiskStorage_tbl_v(void);
+
 #endif /*__HOSTRES_SNMP_H_INCLUDED__ */
 



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?200507302311.j6UNBDCs007042>