From owner-p4-projects@FreeBSD.ORG Fri Jul 22 23:08:04 2005 Return-Path: X-Original-To: p4-projects@freebsd.org Delivered-To: p4-projects@freebsd.org Received: by hub.freebsd.org (Postfix, from userid 32767) id 3D8DF16A421; Fri, 22 Jul 2005 23:08:04 +0000 (GMT) X-Original-To: perforce@freebsd.org Delivered-To: perforce@freebsd.org Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id EE56D16A41F for ; Fri, 22 Jul 2005 23:08:03 +0000 (GMT) (envelope-from soc-victor@freebsd.org) Received: from repoman.freebsd.org (repoman.freebsd.org [216.136.204.115]) by mx1.FreeBSD.org (Postfix) with ESMTP id A63B743D45 for ; Fri, 22 Jul 2005 23:08:03 +0000 (GMT) (envelope-from soc-victor@freebsd.org) Received: from repoman.freebsd.org (localhost [127.0.0.1]) by repoman.freebsd.org (8.13.1/8.13.1) with ESMTP id j6MN832f048062 for ; Fri, 22 Jul 2005 23:08:03 GMT (envelope-from soc-victor@freebsd.org) Received: (from perforce@localhost) by repoman.freebsd.org (8.13.1/8.13.1/Submit) id j6MN83iT048059 for perforce@freebsd.org; Fri, 22 Jul 2005 23:08:03 GMT (envelope-from soc-victor@freebsd.org) Date: Fri, 22 Jul 2005 23:08:03 GMT Message-Id: <200507222308.j6MN83iT048059@repoman.freebsd.org> X-Authentication-Warning: repoman.freebsd.org: perforce set sender to soc-victor@freebsd.org using -f From: soc-victor To: Perforce Change Reviews Cc: Subject: PERFORCE change 80810 for review X-BeenThere: p4-projects@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: p4 projects tree changes List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 22 Jul 2005 23:08:05 -0000 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 ==== //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 /*for getfsstat*/ #include +#include /*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 - + +/* + * 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,