From owner-p4-projects@FreeBSD.ORG Sat Aug 6 19:49:47 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 BE19516A421; Sat, 6 Aug 2005 19:49:46 +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 94F0616A41F for ; Sat, 6 Aug 2005 19:49:46 +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 31A8543D46 for ; Sat, 6 Aug 2005 19:49:46 +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 j76JnkWU017325 for ; Sat, 6 Aug 2005 19:49:46 GMT (envelope-from soc-victor@freebsd.org) Received: (from perforce@localhost) by repoman.freebsd.org (8.13.1/8.13.1/Submit) id j76Jnj2h017322 for perforce@freebsd.org; Sat, 6 Aug 2005 19:49:45 GMT (envelope-from soc-victor@freebsd.org) Date: Sat, 6 Aug 2005 19:49:45 GMT Message-Id: <200508061949.j76Jnj2h017322@repoman.freebsd.org> X-Authentication-Warning: repoman.freebsd.org: perforce set sender to soc-victor@freebsd.org using -f From: Victor Cruceru To: Perforce Change Reviews Cc: Subject: PERFORCE change 81572 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: Sat, 06 Aug 2005 19:49:47 -0000 http://perforce.freebsd.org/chv.cgi?CH=81572 Change 81572 by soc-victor@soc-victor_82.76.158.176 on 2005/08/06 19:49:02 Finished the SNMP instrumentation for hrPartitionTable. Affected files ... .. //depot/projects/soc2005/bsnmp/usr.sbin/bsnmpd/modules/snmp_hostres/Makefile#17 edit .. //depot/projects/soc2005/bsnmp/usr.sbin/bsnmpd/modules/snmp_hostres/hostres_fs_tbl.c#3 edit .. //depot/projects/soc2005/bsnmp/usr.sbin/bsnmpd/modules/snmp_hostres/hostres_partition_tbl.c#2 edit Differences ... ==== //depot/projects/soc2005/bsnmp/usr.sbin/bsnmpd/modules/snmp_hostres/Makefile#17 (text+ko) ==== @@ -39,7 +39,7 @@ 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_fs_tbl.c#3 (text+ko) ==== @@ -42,6 +42,10 @@ #include #include +extern +void +handle_partition_fs_index(const char *name, int32_t fs_idx); + static struct hrFSTblEntry* hrFSTblEntry_create( const char *name ) { @@ -322,7 +326,10 @@ memset(&entry->lastPartialBackupDate[0], 0, sizeof(entry->lastPartialBackupDate)); /*Info not available*/ - + + + handle_partition_fs_index(fs_p->f_mntfromname, entry->index); + return; } if ((entry = hrFSTblEntry_create(fs_p->f_mntonname)) != NULL) { @@ -368,6 +375,7 @@ memset(&entry->lastPartialBackupDate[0], 0, sizeof(entry->lastPartialBackupDate)); /*Info not available*/ + handle_partition_fs_index(fs_p->f_mntfromname, entry->index); } return; ==== //depot/projects/soc2005/bsnmp/usr.sbin/bsnmpd/modules/snmp_hostres/hostres_partition_tbl.c#2 (text+ko) ==== @@ -50,6 +50,10 @@ void Partition_tbl_post_refresh_v(void); +void +handle_partition_fs_index(const char *name, int32_t fs_idx); + + static struct hrPartitionTblEntry* hrPartitonTblEntry_create( int32_t ds_index, const struct chunk* curr_chunk) { @@ -151,6 +155,17 @@ } static +struct hrPartitionTblEntry* +hrPartitionTblEntry_find_by_label(const char *name) { + struct hrPartitionTblEntry *entry = NULL; + + TAILQ_FOREACH(entry, &hrState_g.hr_partition_tbl, link) + if (strncmp(entry->label, name, sizeof(entry->label) - 1) == 0) + return (entry); + return (NULL); +} + +static void handleChunk(int32_t ds_index, const struct chunk* chunk_p) { struct hrPartitionTblEntry* entry = NULL; assert(chunk_p != NULL); @@ -168,10 +183,10 @@ } assert(entry != NULL); entry->flags |= HR_PARTITION_FOUND; - strncpy(entry->label,chunk_p->name, sizeof(entry->label) - 1); - entry->size = chunk_p->size/2; - entry->fs_Index = 0; /*FIX ME*/ - + snprintf(entry->label, sizeof(entry->label) - 1, "/dev/%s", chunk_p->name ); + daddr_t k_size= chunk_p->size/2; + /*may overflow the SNMP type*/ + entry->size = ( k_size > (daddr_t)INT_MAX ? INT_MAX : k_size ); } void handleDiskStorage(int32_t ds_index, const char* disk_dev_name) { @@ -261,12 +276,96 @@ hrState_g.hrPartition_tbl_age = time(NULL); } -int op_hrPartitionTable(struct snmp_context *ctx __unused, - struct snmp_value *value __unused, - u_int sub __unused, - u_int iidx __unused, - enum snmp_op curr_op __unused) + +void +handle_partition_fs_index(const char *name, int32_t fs_idx){ + struct hrPartitionTblEntry* entry = NULL; + + entry = hrPartitionTblEntry_find_by_label(name); + if (entry == NULL) { + HR_DPRINTF((stderr, "%s IS MISSING from hrPartitionTable\n ", name)); + } else { + HR_DPRINTF((stderr, "%s [FS index = %d] IS in hrPartitionTable\n ", name, fs_idx)); + entry->fs_Index = fs_idx; + } + +} + + +int op_hrPartitionTable(struct snmp_context *ctx __unused, struct snmp_value *value, + u_int sub, u_int iidx __unused, enum snmp_op op) { - return (SNMP_ERR_NOSUCHNAME); + struct hrPartitionTblEntry *entry = NULL; + int ret = SNMP_ERR_NOERROR; + + if ( (time(NULL) - hrState_g.hrDiskStorage_age) > HR_DISKSTORAGE_TBL_REFRESH ) { + HR_DPRINTF((stderr, "%s: need refresh\n ",__func__)); + refresh_DiskStorage_tbl_v(); + } + + switch (op) { + + case SNMP_OP_GETNEXT: { + int found = 0; + TAILQ_FOREACH(entry, &hrState_g.hr_partition_tbl, link) + if (index_compare(&value->var, sub, &entry->index) < 0) { + found = 1; + break; + } + if (found == 0) { + return (SNMP_ERR_NOSUCHNAME); + } + index_append(&value->var, sub, &entry->index); + break; + } + case SNMP_OP_GET: { + int found = 0; + TAILQ_FOREACH(entry, &hrState_g.hr_partition_tbl, link) + if (index_compare(&value->var, sub, &entry->index) == 0) { + found = 1; + break; + } + if (found == 0) { + return (SNMP_ERR_NOSUCHNAME); + } + break; + } + case SNMP_OP_SET: + return (SNMP_ERR_NOT_WRITEABLE); + + case SNMP_OP_ROLLBACK: + case SNMP_OP_COMMIT: + default: + assert(0); + return (SNMP_ERR_NOERROR); + } + + if (entry == NULL) { + return (SNMP_ERR_GENERR); + } + + switch (value->var.subs[sub - 1]) { + + case LEAF_hrPartitionIndex: + value->v.integer = entry->index.subs[1]; + break; + + case LEAF_hrPartitionLabel: + ret = string_get(value, entry->label, -1); + break; + + case LEAF_hrPartitionID: + ret = string_get(value, entry->id, -1); + break; + + case LEAF_hrPartitionSize: + value->v.integer = entry->size; + break; + + case LEAF_hrPartitionFSIndex: + value->v.integer = entry->fs_Index; + break; + } + return (ret); }