From owner-p4-projects@FreeBSD.ORG Wed Jul 20 20:29:31 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 5F9A716A421; Wed, 20 Jul 2005 20:29:31 +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 2053316A41F for ; Wed, 20 Jul 2005 20:29:31 +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 A981643D46 for ; Wed, 20 Jul 2005 20:29:30 +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 j6KKTU3Q003088 for ; Wed, 20 Jul 2005 20:29:30 GMT (envelope-from soc-victor@freebsd.org) Received: (from perforce@localhost) by repoman.freebsd.org (8.13.1/8.13.1/Submit) id j6KKTU0G003085 for perforce@freebsd.org; Wed, 20 Jul 2005 20:29:30 GMT (envelope-from soc-victor@freebsd.org) Date: Wed, 20 Jul 2005 20:29:30 GMT Message-Id: <200507202029.j6KKTU0G003085@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 80629 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: Wed, 20 Jul 2005 20:29:32 -0000 http://perforce.freebsd.org/chv.cgi?CH=80629 Change 80629 by soc-victor@soc-victor_82.76.158.176 on 2005/07/20 20:29:18 Added the implementation for both hrSWRunTable and hrSWRunPerfTable (which AUGMENTS hrSWRunTable ). Both tables need some performance improvements; also hrSWRunTable needs SNMP SET support. Affected files ... .. //depot/projects/soc2005/bsnmp/usr.sbin/bsnmpd/modules/snmp_hostres/Makefile#8 edit .. //depot/projects/soc2005/bsnmp/usr.sbin/bsnmpd/modules/snmp_hostres/hostres_scalars.c#6 edit .. //depot/projects/soc2005/bsnmp/usr.sbin/bsnmpd/modules/snmp_hostres/hostres_snmp.c#8 edit .. //depot/projects/soc2005/bsnmp/usr.sbin/bsnmpd/modules/snmp_hostres/hostres_snmp.h#10 edit .. //depot/projects/soc2005/bsnmp/usr.sbin/bsnmpd/modules/snmp_hostres/hostres_swrun_tbl.c#1 add .. //depot/projects/soc2005/bsnmp/usr.sbin/bsnmpd/modules/snmp_hostres/hostres_swrunperf_tbl.c#1 add Differences ... ==== //depot/projects/soc2005/bsnmp/usr.sbin/bsnmpd/modules/snmp_hostres/Makefile#8 (text+ko) ==== @@ -7,7 +7,8 @@ MOD= hostres SRCS= hostres_snmp.c hostres_scalars.c \ - hostres_storage_tbl.c hostres_fs_tbl.c + hostres_storage_tbl.c hostres_fs_tbl.c \ + hostres_swrun_tbl.c hostres_swrunperf_tbl.c WARNS?= 6 #Not having NDEBUG defined will enable assertions and a lot of output on stderr CFLAGS+= -DNDEBUG ==== //depot/projects/soc2005/bsnmp/usr.sbin/bsnmpd/modules/snmp_hostres/hostres_scalars.c#6 (text+ko) ==== @@ -487,7 +487,7 @@ return (-1); /*error*/ } - if( kvm_getprocs(hrState_g.kd, KERN_PROC_PROC, 0, &proc_count) == NULL ) { + if( kvm_getprocs(hrState_g.kd, KERN_PROC_ALL, 0, &proc_count) == NULL ) { syslog(LOG_ERR, "kvm_getprocs failed: %m "); return (-1);/*error*/ } @@ -569,3 +569,31 @@ } return (-1); /*error*/ } + +int op_hrSWRun(struct snmp_context *ctx __unused, + struct snmp_value *value, + u_int sub, + u_int iidx __unused, + enum snmp_op curr_op) +{ + + + if(curr_op == SNMP_OP_GET) { + switch (value->var.subs[sub - 1]) { + case LEAF_hrSWOSIndex: + value->v.uint32 = hrState_g.hrSWOSIndex; + return (SNMP_ERR_NOERROR); + default: + assert(0); + return (SNMP_ERR_NOSUCHNAME); + + }/*end switch*/ + } else if (curr_op == SNMP_OP_SET) { + return (SNMP_ERR_NOT_WRITEABLE); + } else { + assert(0); + return (SNMP_ERR_GENERR); + } + +} + ==== //depot/projects/soc2005/bsnmp/usr.sbin/bsnmpd/modules/snmp_hostres/hostres_snmp.c#8 (text+ko) ==== @@ -54,14 +54,18 @@ struct hostres_state hrState_g; /* -HOST RESOURCES mib module initialization hook. -Returns 0 on success, < 0 on error -*/ + * HOST RESOURCES mib module initialization hook. + * Returns 0 on success, < 0 on error + */ static int hostres_init(struct lmodule * mod, int argc __unused, char *argv[] __unused) { + hostres_module = mod; + /* + * NOTE: order of these calls is important here! + */ hrState_g.utmp_fp = (FILE*)NULL; hrState_g.kd = (kvm_t*)NULL; hrState_g.kernel_boot = 0; @@ -86,6 +90,7 @@ return (-1); /*error*/ } + hrState_g.hrSWOSIndex = 0; hrState_g.next_hrStorage_index = 1; @@ -100,16 +105,21 @@ TAILQ_INIT(&hrState_g.hr_fs_tbl); + TAILQ_INIT(&hrState_g.hr_swrun_tbl); hrState_g.hr_storage_tick = 0; hrState_g.hr_fs_tick = 0; + hrState_g.hr_swrun_tick = 0; hrState_g.hrStorage_tbl_age = 0; hrState_g.hrFS_tbl_age = 0; + hrState_g.hrSWRun_tbl_age = 0; + init_hrStorage_tbl_v(); init_hrFS_tbl_v(); - + init_hrSWRun_tbl_v(); + HR_DPRINTF((stderr, "[%s] done.\n", __func__)); return (0); @@ -152,7 +162,18 @@ fini_hrStorage_tbl_v(); fini_hrFS_tbl_v(); - + fini_hrSWRun_tbl_v(); + + hrState_g.hr_storage_tick = 0; + hrState_g.hr_fs_tick = 0; + hrState_g.hr_swrun_tick = 0; + + hrState_g.hrStorage_tbl_age = 0; + hrState_g.hrFS_tbl_age = 0; + hrState_g.hrSWRun_tbl_age = 0; + + hrState_g.hrSWOSIndex = 0; + if( host_registration_id > 0){ or_unregister(host_registration_id); } @@ -175,6 +196,11 @@ HR_DPRINTF((stderr, "%s: hrFSTable needs refresh\n ", __func__)); refresh_hrFS_tbl_v(); } + 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(); + } + HR_DPRINTF((stderr, "[%s] done.\n ", __func__)); } @@ -307,35 +333,11 @@ -int op_hrSWRun(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_hrSWRunTable(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_hrSWRunPerfTable(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_hrSWInstalled(struct snmp_context *ctx __unused, ==== //depot/projects/soc2005/bsnmp/usr.sbin/bsnmpd/modules/snmp_hostres/hostres_snmp.h#10 (text+ko) ==== @@ -59,7 +59,7 @@ /* - * This structure is used to hold on SNMP table entry + * This structure is used to hold a SNMP table entry * for HOST-RESOURCES-MIB's hrStorageTable */ @@ -110,10 +110,14 @@ SNMP_FALSE= 2 }; +/* + * This structure is used to hold a SNMP table entry + * for HOST-RESOURCES-MIB's hrFSTable + */ struct hrFSTblEntry { int32_t index; - u_char mountPoint[128]; - u_char remoteMountPoint[128]; + u_char mountPoint[128+11]; + u_char remoteMountPoint[128+1]; struct asn_oid type; int32_t access; /* enum hrFSAccess, see above */ int32_t bootable; /* enum snmpTCTruthValue, see above */ @@ -150,6 +154,44 @@ STAILQ_HEAD(fs_map_list, FSNameMapEntry); +enum SWRunType { + SRT_UNKNOWN = 1, + SRT_OPERATING_SYSTEM = 2, + SRT_DEVICE_DRIVER = 3, + SRT_APPLICATION = 4 + +}; + +enum SWRunStatus { + SRS_RUNNING = 1, + SRS_RUNNABLE = 2, + SRS_NOT_RUNNABLE = 3, + SRS_INVALID = 4 +}; + +/* + * This structure is used to hold a SNMP table entry + * for both hrSWRunTable and hrSWRunPerfTable because + * hrSWRunPerfTable AUGMENTS hrSWRunTable + */ +struct hrSWRunTblEntry { + int32_t index; + u_char name[64+1]; + struct asn_oid id; + u_char path[128+1]; + u_char parameters[128+1]; + int32_t type; /* one item from enum SWRunType, see above */ + int32_t status; /* one item from enum SWRunStatus, see above */ + int32_t perfCPU; + int32_t perfMemory; +#define HR_SWRUN_FOUND 0x001 + uint32_t flags; /*not from the SNMP mib table, only to be used internally*/ + TAILQ_ENTRY(hrSWRunTblEntry) link; +}; + +TAILQ_HEAD(swrun_tbl, hrSWRunTblEntry); + + struct hostres_state { FILE *utmp_fp; /*file pointer to keep an open instance of utmp*/ kvm_t *kd; /*kernel descriptor*/ @@ -171,9 +213,9 @@ storage_tbl hr_storage_tbl; /*the head of the list with table's entries */ uint64_t hr_storage_tick; /*last (agent) tick when hrStorageTable was updated */ struct kvm_swap *swap_devs; /*for kvm_getswapinfo, malloc'd*/ - size_t swap_devs_len; /*idem */ + size_t swap_devs_len; /*item count for swap_devs */ struct statfs *fs_buf; /*for getfsstat, malloc'd*/ - size_t fs_buf_count; /*idem*/ + size_t fs_buf_count; /*item count for fs_buf */ struct vmtotal mem_stats; uint32_t next_hrStorage_index; /*next int available for indexing the hrStorageTable*/ time_t hrStorage_tbl_age; @@ -189,7 +231,17 @@ time_t hrFS_tbl_age; uint64_t hr_fs_tick; /*last (agent) tick when hrFSTable was updated */ - + /* + * next items are used for both hrSWRunTable and hrSWRunPerfTable + */ + struct + swrun_tbl hr_swrun_tbl; /*the head of the list with hrSWRunTable's entries */ + + 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*/ + }; /* @@ -267,6 +319,35 @@ */ void refresh_hrFS_tbl_v(void); +/* + * Find an entry in hrSWRunTable (or hrSWRunPerfTable) by its SNMP index + * Returns NULL if none found + */ +struct hrSWRunTblEntry * +hrSWRunTblEntry_find_by_index(int32_t idx); + +/* + * Init the things for both of hrSWRunTable an hrSWRunPerfTable + */ +void init_hrSWRun_tbl_v(void); + +/* + * Finalization routine for both of hrSWRunTable an hrSWRunPerfTable + * It destroys the lists and frees any allocated heap memory + */ +void fini_hrSWRun_tbl_v(void); + +/* + * Next macro represents the number of seconds + * between two consecutive queries to the OS for getting the new data + * for both of hrSWRunTable and hrSWRunPerfTable + */ +#define HR_SWRUN_TBL_REFRESH 3 +/* + * Refresh routine for both of hrSWRunTable and hrSWRunPerfTable + * Usable for polling the system for any changes. + */ +void refresh_hrSWRun_tbl_v(void); #endif /*__HOSTRES_SNMP_H_INCLUDED__ */