From owner-p4-projects@FreeBSD.ORG Mon Jul 18 15:57:24 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 880EE16A420; Mon, 18 Jul 2005 15:57:23 +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 5F24916A41C for ; Mon, 18 Jul 2005 15:57:23 +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 13FA643D46 for ; Mon, 18 Jul 2005 15:57:23 +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 j6IFvMMv054037 for ; Mon, 18 Jul 2005 15:57:22 GMT (envelope-from soc-victor@freebsd.org) Received: (from perforce@localhost) by repoman.freebsd.org (8.13.1/8.13.1/Submit) id j6IFvMvo054034 for perforce@freebsd.org; Mon, 18 Jul 2005 15:57:22 GMT (envelope-from soc-victor@freebsd.org) Date: Mon, 18 Jul 2005 15:57:22 GMT Message-Id: <200507181557.j6IFvMvo054034@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 80446 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: Mon, 18 Jul 2005 15:57:24 -0000 http://perforce.freebsd.org/chv.cgi?CH=80446 Change 80446 by soc-victor@soc-victor_82.76.158.176 on 2005/07/18 15:56:49 Added the SNMP instrumentation for hrFSTable table from HOST-RESOURCES-MIB Affected files ... .. //depot/projects/soc2005/bsnmp/usr.sbin/bsnmpd/modules/snmp_hostres/Makefile#6 edit .. //depot/projects/soc2005/bsnmp/usr.sbin/bsnmpd/modules/snmp_hostres/hostres_fs_tbl.c#1 add .. //depot/projects/soc2005/bsnmp/usr.sbin/bsnmpd/modules/snmp_hostres/hostres_snmp.c#7 edit .. //depot/projects/soc2005/bsnmp/usr.sbin/bsnmpd/modules/snmp_hostres/hostres_snmp.h#8 edit .. //depot/projects/soc2005/bsnmp/usr.sbin/bsnmpd/modules/snmp_hostres/hostres_storage_tbl.c#5 edit Differences ... ==== //depot/projects/soc2005/bsnmp/usr.sbin/bsnmpd/modules/snmp_hostres/Makefile#6 (text+ko) ==== @@ -7,7 +7,7 @@ MOD= hostres SRCS= hostres_snmp.c hostres_scalars.c \ - hostres_storage_tbl.c + hostres_storage_tbl.c hostres_fs_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_snmp.c#7 (text+ko) ==== @@ -87,9 +87,28 @@ } - hrState_g.hr_tick = 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); + + + hrState_g.hr_storage_tick = 0; + hrState_g.hr_fs_tick = 0; + + hrState_g.hrStorage_tbl_age = 0; + hrState_g.hrFS_tbl_age = 0; + init_hrStorage_tbl_v(); + init_hrFS_tbl_v(); HR_DPRINTF((stderr, "[%s] done.\n", __func__)); @@ -132,6 +151,7 @@ hrState_g.phys_mem_size = 0; fini_hrStorage_tbl_v(); + fini_hrFS_tbl_v(); if( host_registration_id > 0){ or_unregister(host_registration_id); @@ -151,7 +171,11 @@ refresh_hrStorage_tbl_v(); } - /*nothing iteresting here for the time being*/ + if ( (time(NULL) - hrState_g.hrFS_tbl_age) > HR_FS_TBL_REFRESH ) { + HR_DPRINTF((stderr, "%s: hrFSTable needs refresh\n ", __func__)); + refresh_hrFS_tbl_v(); + } + HR_DPRINTF((stderr, "[%s] done.\n ", __func__)); } @@ -281,14 +305,6 @@ } -int op_hrFSTable(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_hrSWRun(struct snmp_context *ctx __unused, ==== //depot/projects/soc2005/bsnmp/usr.sbin/bsnmpd/modules/snmp_hostres/hostres_snmp.h#8 (text+ko) ==== @@ -62,7 +62,7 @@ * This structure is used to hold on SNMP table entry * for HOST-RESOURCES-MIB's hrStorageTable */ -#define HR_STORAGE_FOUND 0x001 + struct hrStorageTblEntry { int32_t index; struct asn_oid type; @@ -71,6 +71,7 @@ int32_t size; int32_t used; uint32_t allocationFailures; +#define HR_STORAGE_FOUND 0x001 uint32_t flags; /*not from the SNMP mib table, only to be used internally*/ TAILQ_ENTRY(hrStorageTblEntry) link; }; @@ -89,42 +90,106 @@ int32_t hrIndex; /*used for hrStorageTblEntry::index*/ u_char a_name[255+1]; /*map key, also used for hrStorageTblEntry::descr*/ - /*next may be NULL if the respective hrStorageTblEntry is (temporally) gone*/ + /* + * next may be NULL if the respective hrStorageTblEntry + * is (temporally) gone + */ struct hrStorageTblEntry *entry_p; STAILQ_ENTRY(storageNameMapEntry) link; }; STAILQ_HEAD(storage_map_list, storageNameMapEntry); +enum hrFSAccess { + FS_READ_WRITE = 1, + FS_READ_ONLY = 2 +}; + +enum snmpTCTruthValue { + SNMP_TRUE = 1, + SNMP_FALSE= 2 +}; + +struct hrFSTblEntry { + int32_t index; + u_char mountPoint[128]; + u_char remoteMountPoint[128]; + struct asn_oid type; + int32_t access; /* enum hrFSAccess, see above */ + int32_t bootable; /* enum snmpTCTruthValue, see above */ + int32_t storageIndex; /* hrStorageTblEntry::index */ + u_char lastFullBackupDate[11]; + u_char lastPartialBackupDate[11]; +#define HR_FS_FOUND 0x001 + uint32_t flags; /*not from the SNMP mib table, only to be used internally*/ + TAILQ_ENTRY(hrFSTblEntry) link; +}; + +TAILQ_HEAD(fs_tbl, hrFSTblEntry); + + +/* + * 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 FSNameMapEntry { + int32_t hrIndex; /*used for hrFSTblEntry::index*/ + u_char a_name[255+1]; /*map key*/ + + /* + * next may be NULL if the respective hrFSTblEntry + * is (temporally) gone + */ + struct + hrFSTblEntry *entry_p; + STAILQ_ENTRY(FSNameMapEntry) link; +}; + +STAILQ_HEAD(fs_map_list, FSNameMapEntry); struct hostres_state { - FILE *utmp_fp; /*file pointer to keep an open instance of utmp*/ - kvm_t *kd; /*kernel descriptor*/ - uint32_t kernel_boot; /*boot timestamp in centi-seconds*/ - char k_boot_line[128];/*kernel boot line*/ - int max_proc; /*maximum number of processes */ - uint32_t phys_mem_size; /*physical memory size in Kb*/ + FILE *utmp_fp; /*file pointer to keep an open instance of utmp*/ + kvm_t *kd; /*kernel descriptor*/ + uint32_t kernel_boot; /*boot timestamp in centi-seconds*/ + char k_boot_line[128]; /*kernel boot line*/ + int max_proc; /*maximum number of processes */ + uint32_t phys_mem_size; /*physical memory size in Kb*/ - u_char *time_to_set; /*for setting hrSystemDate*/ - struct timeval timeval_to_set; /*for setting hrSystemDate*/ + u_char *time_to_set; /*for setting hrSystemDate*/ + struct timeval timeval_to_set; /*for setting hrSystemDate*/ - /* next items are used for hrStorageTable */ + /* + * next items are used for hrStorageTable + */ struct - storage_map_list storage_name_map; /*for consistent table indexing*/ + storage_map_list storage_name_map; /*for consistent table indexing*/ struct - storage_tbl hr_storage_tbl; /*the head of the list with table's entries */ - uint64_t hr_tick; - struct kvm_swap *swap_devs; /*for kvm_getswapinfo, malloc'd*/ - size_t swap_devs_len; /*idem */ - struct statfs *fs_buf; /*for getfsstat, malloc'd*/ - size_t fs_buf_count; /*idem*/ + 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 */ + struct statfs *fs_buf; /*for getfsstat, malloc'd*/ + size_t fs_buf_count; /*idem*/ struct vmtotal mem_stats; - uint32_t next_hrStorage_index; /*next int availabe for indexing the hrStorageTable*/ + uint32_t next_hrStorage_index; /*next int available for indexing the hrStorageTable*/ time_t hrStorage_tbl_age; + /* + * next items are used for hrFSTable + */ + struct + fs_map_list fs_name_map; /*for consistent table indexing*/ + + struct fs_tbl hr_fs_tbl; /*the head of the list with hrFSTable's entries */ + uint32_t next_hrFS_index; /*next int available for indexing the hrFSTable*/ + time_t hrFS_tbl_age; + uint64_t hr_fs_tick; /*last (agent) tick when hrFSTable was updated */ + }; /* @@ -133,7 +198,14 @@ */ extern struct hostres_state hrState_g; + /* + * Query the underlaying OS for the mounted file systems + * anf fill in the respective lists (for hrStorageTable and for hrFSTable) + */ +void hrStorage_OS_get_fs_v(void); + +/* * Init the things for hrStorageTable. */ void init_hrStorage_tbl_v(void); @@ -151,5 +223,30 @@ */ void refresh_hrStorage_tbl_v(void); + + + +void +FS_tbl_process_statfs_entry_v(const struct statfs *fs_p, int32_t storage_idx); + +/* + * Init the things for hrFSTable. + */ +void init_hrFS_tbl_v(void); + +/* + * Finalization routine for hrFSTable. + * It destroys the lists and frees any allocated heap memory + */ +void fini_hrFS_tbl_v(void); + +#define HR_FS_TBL_REFRESH 7 +/* + * Refresh routine for hrFSTable. + * Usable for polling the system for any changes. + */ +void refresh_hrFS_tbl_v(void); + + #endif /*__HOSTRES_SNMP_H_INCLUDED__ */ ==== //depot/projects/soc2005/bsnmp/usr.sbin/bsnmpd/modules/snmp_hostres/hostres_storage_tbl.c#5 (text+ko) ==== @@ -143,7 +143,7 @@ */ static -void hrStorage_get_vm_v(void) { +void hrStorage_OS_get_vm_v(void) { /*FIX ME*/ int mib[2] = { CTL_VM, VM_TOTAL }; int len = sizeof(hrState_g.mem_stats); @@ -195,7 +195,7 @@ static -void hrStorage_get_swap_v(void) { +void hrStorage_OS_get_swap_v(void) { int nswapdev = 0; int len = sizeof(nswapdev); struct hrStorageTblEntry *entry; @@ -309,8 +309,8 @@ } -static -void hrStorage_get_fs_v(void) { + +void hrStorage_OS_get_fs_v(void) { int mounted_fs_count = 0; int i = 0; struct hrStorageTblEntry *entry; @@ -343,6 +343,7 @@ HR_DPRINTF((stderr, "%s: Got %d mounted FS\n ", __func__, mounted_fs_count)); for(i = 0; i < mounted_fs_count; i++ ) { + memset(&fs_string[0], '\0', sizeof(fs_string) ); snprintf(fs_string, 255, "%s, type: %s, dev: %s", hrState_g.fs_buf[i].f_mntonname, hrState_g.fs_buf[i].f_fstypename, @@ -368,7 +369,11 @@ INT_MAX : used_blocks_count ); /*may overflow the SNMP type*/ - entry->allocationFailures = 0; + entry->allocationFailures = 0; + + /*take care of hrFSTable*/ + FS_tbl_process_statfs_entry_v(&hrState_g.fs_buf[i], entry->index); + continue; } if ((entry = hrStorageTblEntry_create(fs_string)) != NULL) { @@ -392,6 +397,10 @@ entry->allocationFailures = 0; + /*take care of hrFSTable*/ + FS_tbl_process_statfs_entry_v(&hrState_g.fs_buf[i], entry->index); + + } }/*end for*/ @@ -408,18 +417,9 @@ memset( &hrState_g.mem_stats, 0, sizeof(hrState_g.mem_stats) ); - hrState_g.next_hrStorage_index = 1; - STAILQ_INIT(&hrState_g.storage_name_map); - - TAILQ_INIT(&hrState_g.hr_storage_tbl); + refresh_hrStorage_tbl_v(); - hrStorage_get_vm_v(); - - hrStorage_get_swap_v(); - - hrStorage_get_fs_v(); - } void fini_hrStorage_tbl_v(void) { @@ -450,8 +450,6 @@ n1 = n2; } STAILQ_INIT(&hrState_g.storage_name_map); - - } @@ -460,7 +458,7 @@ struct hrStorageTblEntry *entry = NULL, *entry_tmp = NULL; - if ( this_tick <= hrState_g.hr_tick) { + if ( this_tick <= hrState_g.hr_storage_tick) { HR_DPRINTF((stderr, "%s: no refresh needed\n ",__func__)); return; } @@ -469,11 +467,11 @@ entry->flags &= ~HR_STORAGE_FOUND; - hrStorage_get_vm_v(); + hrStorage_OS_get_vm_v(); - hrStorage_get_swap_v(); + hrStorage_OS_get_swap_v(); - hrStorage_get_fs_v(); + hrStorage_OS_get_fs_v(); /* * Purge items items that disappeared @@ -486,7 +484,7 @@ entry = entry_tmp; } - hrState_g.hr_tick = this_tick; + hrState_g.hr_storage_tick = this_tick; hrState_g.hrStorage_tbl_age = time(NULL);