Skip site navigation (1)Skip section navigation (2)
Date:      Fri, 15 Jul 2005 14:44:35 GMT
From:      soc-victor <soc-victor@FreeBSD.org>
To:        Perforce Change Reviews <perforce@freebsd.org>
Subject:   PERFORCE change 80266 for review
Message-ID:  <200507151444.j6FEiZMR000309@repoman.freebsd.org>

next in thread | raw e-mail | index | archive | help
http://perforce.freebsd.org/chv.cgi?CH=80266

Change 80266 by soc-victor@soc-victor_82.76.158.176 on 2005/07/15 14:43:44

	Some code cleanup for hrStorageTable

Affected files ...

.. //depot/projects/soc2005/bsnmp/usr.sbin/bsnmpd/modules/snmp_hostres/hostres_snmp.c#6 edit
.. //depot/projects/soc2005/bsnmp/usr.sbin/bsnmpd/modules/snmp_hostres/hostres_snmp.h#6 edit
.. //depot/projects/soc2005/bsnmp/usr.sbin/bsnmpd/modules/snmp_hostres/hostres_storage_tbl.c#3 edit

Differences ...

==== //depot/projects/soc2005/bsnmp/usr.sbin/bsnmpd/modules/snmp_hostres/hostres_snmp.c#6 (text+ko) ====

@@ -147,7 +147,7 @@
 static
 void hostres_idle_v(void) {
 	if ( (time(NULL) - hrState_g.hrStorage_tbl_age) > HR_STORAGE_TBL_REFRESH ) {
-		HR_DPRINTF((stderr, "%s: hrStorageTable needd refresh\n ",__func__));
+		HR_DPRINTF((stderr, "%s: hrStorageTable needs refresh\n ", __func__));
 		refresh_hrStorage_tbl_v();
 	}
 

==== //depot/projects/soc2005/bsnmp/usr.sbin/bsnmpd/modules/snmp_hostres/hostres_snmp.h#6 (text+ko) ====

@@ -55,39 +55,9 @@
 #define HR_DPRINTF(ARGS)
 #endif /*NDEBUG*/
 
-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*/
-	
-	u_char 		*time_to_set;    /*for setting hrSystemDate*/
-	struct timeval	timeval_to_set;	 /*for setting hrSystemDate*/	
-	
-	uint64_t 	hr_tick;
-	
-	struct kvm_swap *swap_devs;	 /*for kvm_getswapinfo*/
-	size_t		swap_devs_len;   /*idem */ 
-	
-	struct statfs	*fs_buf;	 /*for getfsstat*/
-	size_t		fs_buf_count;	 /*idem*/	
-	
-	uint32_t 	next_hrStorage_index; /*next int availabe for indexing the hrStorageTable*/
-	time_t		hrStorage_tbl_age; 
-	
 
-	
-};
 
 /*
- *  Instance to keep most of the globals related to 
- *  HOST RESOURCES MIB implementation
- */
-extern struct hostres_state hrState_g;
-
-/*
  * This structure is used to hold on SNMP table entry
  * for HOST-RESOURCES-MIB's hrStorageTable
  */
@@ -104,9 +74,8 @@
 	TAILQ_ENTRY(hrStorageTblEntry) link;	
 };
 
+TAILQ_HEAD(storage_tbl, hrStorageTblEntry);
 
-TAILQ_HEAD(storage_tbl, hrStorageTblEntry);
-extern struct storage_tbl storage_tbl;
 
 
 /*
@@ -125,7 +94,42 @@
 };
 
 STAILQ_HEAD(storage_map_list, storageNameMapEntry);
-extern struct storage_map_list storage_name_map;
+
+
+
+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*/
+	
+	u_char 		*time_to_set;    /*for setting hrSystemDate*/
+	struct timeval	timeval_to_set;	 /*for setting hrSystemDate*/	
+	
+	/* next items are used for hrStorageTable */
+	struct 
+	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*/
+	size_t		swap_devs_len;     /*idem */ 
+	struct statfs	*fs_buf;	   /*for getfsstat*/
+	size_t		fs_buf_count;	   /*idem*/	
+	uint32_t 	next_hrStorage_index; /*next int availabe for indexing the hrStorageTable*/
+	time_t		hrStorage_tbl_age; 
+	
+	
+};
+
+/*
+ *  Instance to keep most of the globals related to 
+ *  HOST RESOURCES MIB implementation
+ */
+extern struct hostres_state hrState_g;
 
 /*
  * Init the things for hrStorageTable.

==== //depot/projects/soc2005/bsnmp/usr.sbin/bsnmpd/modules/snmp_hostres/hostres_storage_tbl.c#3 (text+ko) ====

@@ -41,9 +41,6 @@
 #include <err.h>
 #include <unistd.h> /*for getpagesize()*/
 
-struct storage_tbl storage_tbl = TAILQ_HEAD_INITIALIZER(storage_tbl);
-
-struct storage_map_list storage_name_map = STAILQ_HEAD_INITIALIZER(storage_name_map);
 
 
 static
@@ -66,7 +63,7 @@
 	memset(entry, 0, sizeof(*entry));
 	strcpy(entry->descr, name);
 
-	STAILQ_FOREACH(map, &storage_name_map, link)
+	STAILQ_FOREACH(map, &hrState_g.storage_name_map, link)
 		if (strcmp(map->a_name, entry->descr) == 0) {
 			entry->index = map->hrIndex;
 			map->entry_p = entry;
@@ -88,7 +85,7 @@
 		map->hrIndex = hrState_g.next_hrStorage_index ++;
 		strncpy(map->a_name, entry->descr, 255);
 		map->entry_p = entry;
-		STAILQ_INSERT_TAIL(&storage_name_map, map, link);
+		STAILQ_INSERT_TAIL(&hrState_g.storage_name_map, map, link);
 		HR_DPRINTF((stderr, "%s  added into hrStorageMap at index=%d\n ",name, map->hrIndex));
 	} else {
 		HR_DPRINTF((stderr, "%s  exists in hrStorageMap index=%d\n ",name, map->hrIndex));
@@ -96,7 +93,7 @@
 	
 	entry->index = map->hrIndex;
 
-	INSERT_OBJECT_INT(entry, &storage_tbl);
+	INSERT_OBJECT_INT(entry, &hrState_g.hr_storage_tbl);
 	
 	return entry;
 	
@@ -108,8 +105,8 @@
 	struct storageNameMapEntry  *map;
 	assert(entry != NULL);
 	
-	TAILQ_REMOVE(&storage_tbl, entry, link);	
-	STAILQ_FOREACH(map, &storage_name_map, link)
+	TAILQ_REMOVE(&hrState_g.hr_storage_tbl, entry, link);	
+	STAILQ_FOREACH(map, &hrState_g.storage_name_map, link)
 		if (map->entry_p == entry) {
 			map->entry_p = NULL;
 			break;
@@ -124,7 +121,7 @@
 hrStorageTblEntry_find_by_name(const char *name) {
 	struct hrStorageTblEntry *entry =  NULL;
 
-	TAILQ_FOREACH(entry, &storage_tbl, link)
+	TAILQ_FOREACH(entry, &hrState_g.hr_storage_tbl, link)
 		if (strncmp(entry->descr, name, 255) == 0)
 			return (entry);
 	return (NULL);
@@ -135,7 +132,7 @@
 hrStorageTblEntry_find_by_index(int32_t idx) {
 	struct hrStorageTblEntry *entry;
 
-	TAILQ_FOREACH(entry, &storage_tbl, link)
+	TAILQ_FOREACH(entry, &hrState_g.hr_storage_tbl, link)
 		if (entry->index == idx)
 			return (entry);
 	return (NULL);
@@ -356,6 +353,10 @@
 		
 	hrState_g.next_hrStorage_index  = 1;
 	
+	STAILQ_INIT(&hrState_g.storage_name_map);
+	
+	TAILQ_INIT(&hrState_g.hr_storage_tbl);
+	
 	hrStorage_get_vm_v();
 	
 	hrStorage_get_swap_v();
@@ -380,18 +381,18 @@
 	hrState_g.fs_buf_count = 0;
 
 				
-     	n1 = STAILQ_FIRST(&storage_name_map);
+     	n1 = STAILQ_FIRST(&hrState_g.storage_name_map);
      	while (n1 != NULL) {
              n2 = STAILQ_NEXT(n1, link);
 	     if(n1->entry_p != NULL){
-	     	TAILQ_REMOVE(&storage_tbl, n1->entry_p, link);
+	     	TAILQ_REMOVE(&hrState_g.hr_storage_tbl, n1->entry_p, link);
              	free( n1->entry_p );
 		n1->entry_p = NULL;
 	     }
 	     free(n1);
              n1 = n2;
      	}
-     	STAILQ_INIT(&storage_name_map);
+     	STAILQ_INIT(&hrState_g.storage_name_map);
 	
 	
 
@@ -407,7 +408,7 @@
 		return;
 	}
 	/*mark each entry as missisng*/
-	TAILQ_FOREACH(entry, &storage_tbl, link)
+	TAILQ_FOREACH(entry, &hrState_g.hr_storage_tbl, link)
 		entry->flags &= ~HR_STORAGE_FOUND;
 	
 	
@@ -420,7 +421,7 @@
 	/*
 	 * Purge items items that disappeared
 	 */
-	entry = TAILQ_FIRST(&storage_tbl);
+	entry = TAILQ_FIRST(&hrState_g.hr_storage_tbl);
 	while (entry != NULL) {
 		entry_tmp = TAILQ_NEXT(entry, link);
 		if (!(entry->flags & HR_STORAGE_FOUND))
@@ -457,7 +458,8 @@
 	switch (curr_op) {
 
 	  case SNMP_OP_GETNEXT:
-		if ((entry = NEXT_OBJECT_INT(&storage_tbl, &value->var, sub)) == NULL) {
+		if ((entry = NEXT_OBJECT_INT(&hrState_g.hr_storage_tbl, 
+					     &value->var, sub)) == NULL) {
 			return (SNMP_ERR_NOSUCHNAME);
 		}	
 		value->var.len = sub + 1;



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?200507151444.j6FEiZMR000309>