Skip site navigation (1)Skip section navigation (2)
Date:      Fri, 22 Jul 2005 23:08:03 GMT
From:      soc-victor <soc-victor@FreeBSD.org>
To:        Perforce Change Reviews <perforce@freebsd.org>
Subject:   PERFORCE change 80810 for review
Message-ID:  <200507222308.j6MN83iT048059@repoman.freebsd.org>

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

Change 80810 by soc-victor@soc-victor_82.76.158.176 on 2005/07/22 23:08:00

	This is the very first implementation (based on libdevinfo) for hrDeviceTable.
	A lot of things still to polish....

Affected files ...

.. //depot/projects/soc2005/bsnmp/usr.sbin/bsnmpd/modules/snmp_hostres/Makefile#10 edit
.. //depot/projects/soc2005/bsnmp/usr.sbin/bsnmpd/modules/snmp_hostres/hostres_device_tbl.c#1 add
.. //depot/projects/soc2005/bsnmp/usr.sbin/bsnmpd/modules/snmp_hostres/hostres_snmp.c#9 edit
.. //depot/projects/soc2005/bsnmp/usr.sbin/bsnmpd/modules/snmp_hostres/hostres_snmp.h#12 edit
.. //depot/projects/soc2005/bsnmp/usr.sbin/bsnmpd/modules/snmp_hostres/hostres_swrun_tbl.c#3 edit
.. //depot/projects/soc2005/bsnmp/usr.sbin/bsnmpd/modules/snmp_hostres/hostres_swrunperf_tbl.c#2 edit

Differences ...

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

@@ -9,7 +9,8 @@
 MOD=	hostres
 SRCS=	hostres_snmp.c hostres_scalars.c \
 	hostres_storage_tbl.c hostres_fs_tbl.c \
-	hostres_swrun_tbl.c hostres_swrunperf_tbl.c
+	hostres_swrun_tbl.c hostres_swrunperf_tbl.c \
+	hostres_device_tbl.c
 WARNS?=	6
 #Not having NDEBUG defined will enable assertions and a lot of output on stderr
 CFLAGS+=	-DNDEBUG
@@ -30,5 +31,5 @@
 	
 DEFS=	${MOD}_tree.def
 BMIBS=	HOST-RESOURCES-MIB.txt HOST-RESOURCES-TYPES.txt
-LDADD=	-lkvm
+LDADD=	-lkvm -ldevinfo
 .include <bsd.lib.mk>

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

@@ -90,35 +90,43 @@
 		return (-1); /*error*/
 	}
 	
+	hrState_g.dev_root = NULL;
+	
 	hrState_g.hrSWOSIndex = 0;
 
 	hrState_g.next_hrStorage_index  = 1;
-	
 	STAILQ_INIT(&hrState_g.storage_name_map);
-	
 	TAILQ_INIT(&hrState_g.hr_storage_tbl);
 
 
 	hrState_g.next_hrFS_index  = 1;
-	
 	STAILQ_INIT(&hrState_g.fs_name_map);
-	
 	TAILQ_INIT(&hrState_g.hr_fs_tbl);
 
 	TAILQ_INIT(&hrState_g.hr_swrun_tbl);
 
+		
+	hrState_g.next_hrDevice_index  = 1;
+	STAILQ_INIT(&hrState_g.device_name_map);
+	TAILQ_INIT(&hrState_g.hr_device_tbl);
+
+
 	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.hrStorage_tbl_age = 0;		
 	hrState_g.hrFS_tbl_age = 0;		
-	hrState_g.hrSWRun_tbl_age = 0;		
+	hrState_g.hrSWRun_tbl_age = 0;	
+	hrState_g.hrDevice_tbl_age = 0;	
 
 	
 	init_hrStorage_tbl_v();
 	init_hrFS_tbl_v();
-	init_hrSWRun_tbl_v();
+	init_hrSWRun_tbl_v(); /*also the hrSWRunPerfTable's
+			       support is initialized here */
+	init_hrDevice_tbl_v();			       
 			
         HR_DPRINTF((stderr, "[%s] done.\n", __func__));		
 
@@ -163,14 +171,19 @@
 	fini_hrStorage_tbl_v();
 	fini_hrFS_tbl_v();
 	fini_hrSWRun_tbl_v();
+	fini_hrDevice_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.hrStorage_tbl_age = 0;		
 	hrState_g.hrFS_tbl_age = 0;		
 	hrState_g.hrSWRun_tbl_age = 0;	
+	hrState_g.hrDevice_tbl_age = 0;
+	
+	hrState_g.dev_root = NULL;
 	
 	hrState_g.hrSWOSIndex = 0;
 																							
@@ -198,9 +211,14 @@
 	}
 	if ( (time(NULL) - hrState_g.hrSWRun_tbl_age) > HR_SWRUN_TBL_REFRESH ) {
 		HR_DPRINTF((stderr, "%s: hrSWRunTable needs refresh\n ", __func__));
-		refresh_hrStorage_tbl_v();
+		refresh_hrSWRun_tbl_v();
 	}
 	
+	if ( (time(NULL) - hrState_g.hrDevice_tbl_age) > HR_DEVICE_TBL_REFRESH ) {
+		HR_DPRINTF((stderr, "%s: hrDeviceTable needs refresh\n ", __func__));
+		refresh_hrDevice_tbl_v();
+	}
+
 
         HR_DPRINTF((stderr, "[%s] done.\n ", __func__));		
 }
@@ -272,14 +290,6 @@
 Once one of them is implemented it will be moved into its own C file
 */
 
-int op_hrDeviceTable(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_hrProcessorTable(struct snmp_context *ctx __unused, 
                 struct snmp_value *value __unused, 

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

@@ -45,6 +45,7 @@
 #include <sys/mount.h>	/*for getfsstat*/
 
 #include <sys/vmmeter.h> 
+#include <devinfo.h>
 
 /*a debug macro*/
 #ifndef NDEBUG
@@ -193,6 +194,61 @@
 TAILQ_HEAD(swrun_tbl, hrSWRunTblEntry);
 
 
+enum DeviceStatus {
+	DS_UNKNOWN	=	1,
+	DR_RUNNING	=	2,
+	DS_WARNING	=	3,
+	DS_TESTING	=	4,
+	DS_DOWN		=	4		
+};
+
+
+/*
+ * This structure is used to hold a SNMP table entry
+ * for HOST-RESOURCES-MIB's hrDeviceTable
+ */
+struct hrDeviceTblEntry {
+	int32_t		index;
+	struct asn_oid	type;
+	u_char		descr[64+1];
+	struct asn_oid	id;
+	int32_t		status;		/* one item from enum DeviceStatus, see above */
+	uint32_t	errors;
+
+#define HR_DEVICE_FOUND 0x001
+	/*next 3 are not from the SNMP mib table, only to be used internally*/
+	uint32_t	flags;		
+	u_char		name[32+1];	
+	u_char		location[128+1];	
+	TAILQ_ENTRY(hrDeviceTblEntry) link;		
+};
+
+TAILQ_HEAD(device_tbl, hrDeviceTblEntry);
+
+
+/*
+ * Next structure is used to keep o list of mappings from a specific
+ * name (a_name) to an entry in the hrFSTblEntry;
+ * We are trying to keep the same index for a specific name at least
+ * for the duration of one SNMP agent run
+ */
+struct deviceNameMapEntry {
+	int32_t		hrIndex;		/*used for hrDeviceTblEntry::index*/
+	/*map key is the pair (name_key, location_key)*/
+	u_char		name_key[32+1];		/*map key*/
+	u_char		location_key[128+1];	/*map key*/	
+	/*
+	 * next may be NULL if the respective hrDeviceTblEntry 
+	 * is (temporally) gone
+	 */
+	struct 
+	hrDeviceTblEntry	*entry_p; 
+	STAILQ_ENTRY(deviceNameMapEntry) 	link;
+};
+
+STAILQ_HEAD(device_map_list, deviceNameMapEntry);
+
+
 struct hostres_state {
 	FILE		*utmp_fp;		/*file pointer to keep an open instance of utmp*/
 	kvm_t		*kd;			/*kernel descriptor*/
@@ -241,7 +297,23 @@
 	time_t		hrSWRun_tbl_age; 
 	uint64_t 	hr_swrun_tick;		/*last (agent) tick when hrSWRunTable and hrSWRunPerTable 
 						  were updated */
-	int32_t		hrSWOSIndex;		/* the value of the MIB objecy with the same name*/						  
+	int32_t		hrSWOSIndex;		/* the value of the MIB objecy with the same name*/	
+	
+	/* 
+	 * next items are used for hrDeviceTable 
+	 */
+	struct 
+	device_map_list	device_name_map;	/*for consistent table indexing*/
+	
+	struct 
+	device_tbl	hr_device_tbl;		/*the head of the list with hrDeviceTable's entries */	
+	uint32_t 	next_hrDevice_index;	/*next int available for indexing the hrDeviceTable*/
+	time_t		hrDevice_tbl_age; 
+	uint64_t 	hr_device_tick;		/*last (agent) tick when hrDeviceTable was updated */
+	
+	struct 
+	devinfo_dev	*dev_root;
+						  					  
 				
 };
 
@@ -350,5 +422,28 @@
  */
 void refresh_hrSWRun_tbl_v(void);
 
+/*
+ * Init the things for hrDeviceTable 
+ */
+void init_hrDevice_tbl_v(void);
+
+/*
+ * Finalization routine for hrDeviceTable
+ * It destroys the lists and frees any allocated heap memory
+ */
+void fini_hrDevice_tbl_v(void);
+
+/*
+ * Next macro represents the number of seconds
+ * between two consecutive queries to the OS for getting the new data
+ * for hrDeviceTable
+ */
+#define HR_DEVICE_TBL_REFRESH	10
+/*
+ * Refresh routine for hrDeviceTable
+ * Usable for polling the system for any changes.
+ */
+void refresh_hrDevice_tbl_v(void);
+
 #endif /*__HOSTRES_SNMP_H_INCLUDED__ */
 

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

@@ -470,7 +470,8 @@
 }
 
 /*
- * This is the implmenetaion for a generated function prototype, see hostres_tree.h 
+ * This is the implementation for a generated (by a SNMP tool) 
+ * function prototype, see hostres_tree.h 
  * It hanldes the SNMP operations for hrSWRunTable
  */
 int op_hrSWRunTable(struct snmp_context *ctx __unused, 

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

@@ -32,7 +32,13 @@
 #include "hostres_oid.h"
 #include "hostres_tree.h"
 #include <assert.h>
-  
+
+/*
+ * This is the implementation for a generated (by a SNMP tool) 
+ * function prototype, see hostres_tree.h 
+ * It hanldes the SNMP operations for hrSWRunPerfTable
+ */
+   
 int op_hrSWRunPerfTable(struct snmp_context *ctx __unused, 
                 struct snmp_value *value, 
 		u_int sub, 



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