PERFORCE change 81572 for review

Victor Cruceru soc-victor at FreeBSD.org
Sat Aug 6 19:49:47 GMT 2005


http://perforce.freebsd.org/chv.cgi?CH=81572

Change 81572 by soc-victor at 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 <string.h>
 #include <err.h>
 
+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);
 }
 


More information about the p4-projects mailing list