[openib-general] [PATCH] opensm: reuse PKey values for "dynamic" partitions.

Sasha Khapyorsky sashak at voltaire.com
Wed Nov 1 12:39:36 PST 2006


When partition is specified in partition configuration file without
desired PKey value OpenSM will generate one dynamically.

The problem is that when the list of such "dynamic" partitions is
edited (some partitions are removed and/or some added), PKey values
will be regenerated again and reassigned.

This patch fixes this undesired behavior. Now OpenSM will try to reuse
PKey values for such "dynamic" partitions.

Signed-off-by: Sasha Khapyorsky <sashak at voltaire.com>
---
 osm/include/opensm/osm_partition.h |   14 +++++++--
 osm/opensm/osm_prtn.c              |   55 ++++++++++++++++++++++++++++-------
 2 files changed, 55 insertions(+), 14 deletions(-)

diff --git a/osm/include/opensm/osm_partition.h b/osm/include/opensm/osm_partition.h
index 3e2c896..0a63411 100644
--- a/osm/include/opensm/osm_partition.h
+++ b/osm/include/opensm/osm_partition.h
@@ -118,9 +118,17 @@ typedef struct _osm_prtn
 *	sl
 *		The Service Level (SL) associated with this Partiton.
 *
-*	port_guid_tbl
-*		Container of pointers to all Port objects in the Partition,
-*		indexed by port GUID.
+*	part_guid_tbl
+*		Container of pointers to all Port objects in the Partition
+*		with limited membership, indexed by port GUID.
+*
+*	full_guid_tbl
+*		Container of pointers to all Port objects in the Partition
+*		with full membership, indexed by port GUID.
+*
+*	name
+*		Name of the Partition as specified in partition
+*		configuration.
 *
 * SEE ALSO
 *	Partition
diff --git a/osm/opensm/osm_prtn.c b/osm/opensm/osm_prtn.c
index ae0f6e0..7719fd7 100644
--- a/osm/opensm/osm_prtn.c
+++ b/osm/opensm/osm_prtn.c
@@ -263,6 +263,22 @@ static uint16_t __generate_pkey(osm_subn
 	return 0;
 }
 
+static osm_prtn_t *find_prtn_by_name(osm_subn_t *p_subn, const char *name)
+{
+	cl_map_item_t *p_next;
+	osm_prtn_t *p;
+
+	p_next = cl_qmap_head(&p_subn->prtn_pkey_tbl);
+	while (p_next != cl_qmap_end(&p_subn->prtn_pkey_tbl)) {
+		p = (osm_prtn_t *)p_next;
+		p_next = cl_qmap_next(&p->map_item);
+		if (!strncmp(p->name, name, sizeof(p->name)))
+			return p;
+	}
+
+	return NULL;
+}
+
 osm_prtn_t *osm_prtn_make_new(osm_log_t *p_log, osm_subn_t *p_subn,
 			      const char *name, uint16_t pkey)
 {
@@ -270,8 +286,12 @@ osm_prtn_t *osm_prtn_make_new(osm_log_t
 
 	pkey &= cl_hton16((uint16_t)~0x8000);
 
-	if (pkey == 0 && !(pkey = __generate_pkey(p_subn)))
-		return NULL;
+	if (!pkey) {
+		if (name && (p = find_prtn_by_name(p_subn, name)))
+			return p;
+		if(!(pkey = __generate_pkey(p_subn)))
+			return NULL;
+	}
 
 	p = osm_prtn_new(name, pkey);
 	if (!p) {
@@ -327,7 +347,8 @@ ib_api_status_t osm_prtn_make_partitions
 	const char *file_name;
 	boolean_t is_config = TRUE;
 	ib_api_status_t status = IB_SUCCESS;
-	osm_prtn_t *p, *p_next;
+	cl_map_item_t *p_next;
+	osm_prtn_t *p;
 
 	file_name = p_subn->opt.partition_config_file ?
 			p_subn->opt.partition_config_file :
@@ -335,15 +356,14 @@ ib_api_status_t osm_prtn_make_partitions
 	if (stat(file_name, &statbuf))
 		is_config = FALSE;
 
-	/* cl_qmap uses self addresses so we cannot just save
-	   qmap state and clean it later, so clean all now */
-	p_next = (osm_prtn_t *)cl_qmap_head(&p_subn->prtn_pkey_tbl);
-	while (p_next != (osm_prtn_t *)cl_qmap_end(&p_subn->prtn_pkey_tbl)) {
-		p = p_next;
-		p_next = (osm_prtn_t *)cl_qmap_next(&p->map_item);
-		osm_prtn_delete(&p);
+	/* clean up current port maps */
+	p_next = cl_qmap_head(&p_subn->prtn_pkey_tbl);
+	while (p_next != cl_qmap_end(&p_subn->prtn_pkey_tbl)) {
+		p = (osm_prtn_t *)p_next;
+		p_next = cl_qmap_next(&p->map_item);
+		cl_map_remove_all(&p->part_guid_tbl);
+		cl_map_remove_all(&p->full_guid_tbl);
 	}
-	cl_qmap_init(&p_subn->prtn_pkey_tbl);
 
 	global_pkey_counter = 0;
 
@@ -357,6 +377,19 @@ ib_api_status_t osm_prtn_make_partitions
 			"was not fully processed\n");
 	}
 
+	/* and now clean up empty partitions */
+	p_next = cl_qmap_head(&p_subn->prtn_pkey_tbl);
+	while (p_next != cl_qmap_end(&p_subn->prtn_pkey_tbl)) {
+		p = (osm_prtn_t *)p_next;
+		p_next = cl_qmap_next(&p->map_item);
+		if (cl_map_count(&p->part_guid_tbl) == 0 &&
+		    cl_map_count(&p->full_guid_tbl) == 0) {
+			cl_qmap_remove_item(&p_subn->prtn_pkey_tbl,
+					    (cl_map_item_t *)p);
+			osm_prtn_delete(&p);
+		}
+	}
+
   _err:
 	return status;
 }
-- 
1.4.3.2.g4bf7





More information about the general mailing list