[ofa-general] [PATCH 2/4] opensm: config file functions return int

Sasha Khapyorsky sashak at voltaire.com
Tue Apr 8 18:10:23 PDT 2008


config file handling functions (parse and write) will return integer
values instead of ib_api_status_t (it does nothing with 'ib') - when
a failure is not existing config file a positive value will be returned
to a caller, other errors will be indicated by a negative return value.

Signed-off-by: Sasha Khapyorsky <sashak at voltaire.com>
---
 opensm/include/opensm/osm_subnet.h |   35 +++++++++++------------------------
 opensm/opensm/main.c               |    4 ++--
 opensm/opensm/osm_state_mgr.c      |    3 +--
 opensm/opensm/osm_subnet.c         |   24 +++++++++++-------------
 4 files changed, 25 insertions(+), 41 deletions(-)

diff --git a/opensm/include/opensm/osm_subnet.h b/opensm/include/opensm/osm_subnet.h
index 98afbd4..5b6cef0 100644
--- a/opensm/include/opensm/osm_subnet.h
+++ b/opensm/include/opensm/osm_subnet.h
@@ -1061,8 +1061,7 @@ void osm_subn_set_default_opt(IN osm_subn_opt_t * const p_opt);
 *
 * SYNOPSIS
 */
-ib_api_status_t osm_subn_parse_conf_file(char *conf_file,
-					 IN osm_subn_opt_t * const p_opt);
+int osm_subn_parse_conf_file(char *conf_file, osm_subn_opt_t * const p_opt);
 /*
 * PARAMETERS
 *
@@ -1070,14 +1069,8 @@ ib_api_status_t osm_subn_parse_conf_file(char *conf_file,
 *		[in] Pointer to the subnet options structure.
 *
 * RETURN VALUES
-*	IB_SUCCESS, IB_ERROR
-*
-* NOTES
-*  Assumes the conf file is part of the cache dir which defaults to
-*  OSM_DEFAULT_CACHE_DIR or OSM_CACHE_DIR the name is opensm.opts
-*
-* SEE ALSO
-*	Subnet object, osm_subn_construct, osm_subn_destroy
+*	0 on success, positive value if file doesn't exist,
+*	negative value otherwise
 *********/
 
 /****f* OpenSM: Subnet/osm_subn_rescan_conf_files
@@ -1090,7 +1083,7 @@ ib_api_status_t osm_subn_parse_conf_file(char *conf_file,
 *
 * SYNOPSIS
 */
-ib_api_status_t osm_subn_rescan_conf_files(IN osm_subn_t * const p_subn);
+int osm_subn_rescan_conf_files(IN osm_subn_t * const p_subn);
 /*
 * PARAMETERS
 *
@@ -1098,10 +1091,8 @@ ib_api_status_t osm_subn_rescan_conf_files(IN osm_subn_t * const p_subn);
 *		[in] Pointer to the subnet structure.
 *
 * RETURN VALUES
-*	IB_SUCCESS, IB_ERROR
-*
-* NOTES
-*  This uses the same file as osm_subn_parse_conf_files()
+*	0 on success, positive value if file doesn't exist,
+*	negative value otherwise
 *
 *********/
 
@@ -1110,12 +1101,11 @@ ib_api_status_t osm_subn_rescan_conf_files(IN osm_subn_t * const p_subn);
 *	osm_subn_write_conf_file
 *
 * DESCRIPTION
-*  Write the configuration file into the cache
+*	Write the configuration file into the cache
 *
 * SYNOPSIS
 */
-ib_api_status_t osm_subn_write_conf_file(char *file_name,
-					 IN osm_subn_opt_t * const p_opt);
+int osm_subn_write_conf_file(char *file_name, IN osm_subn_opt_t * const p_opt);
 /*
 * PARAMETERS
 *
@@ -1123,14 +1113,11 @@ ib_api_status_t osm_subn_write_conf_file(char *file_name,
 *		[in] Pointer to the subnet options structure.
 *
 * RETURN VALUES
-*	IB_SUCCESS, IB_ERROR
+*	0 on success, negative value otherwise
 *
 * NOTES
-*  Assumes the conf file is part of the cache dir which defaults to
-*  OSM_DEFAULT_CACHE_DIR or OSM_CACHE_DIR the name is opensm.opts
-*
-* SEE ALSO
-*	Subnet object, osm_subn_construct, osm_subn_destroy
+*	Assumes the conf file is part of the cache dir which defaults to
+*	OSM_DEFAULT_CACHE_DIR or OSM_CACHE_DIR the name is opensm.opts
 *********/
 
 END_C_DECLS
diff --git a/opensm/opensm/main.c b/opensm/opensm/main.c
index 91ee143..da8047e 100644
--- a/opensm/opensm/main.c
+++ b/opensm/opensm/main.c
@@ -683,7 +683,7 @@ int main(int argc, char *argv[])
 		cache_dir = OSM_DEFAULT_CACHE_DIR;
 	snprintf(conf_file, sizeof(conf_file), "%s/opensm.opts", cache_dir);
 
-	if (osm_subn_parse_conf_file(conf_file, &opt) != IB_SUCCESS)
+	if (osm_subn_parse_conf_file(conf_file, &opt) < 0)
 		printf("\nosm_subn_parse_conf_file failed!\n");
 
 	printf("Command Line Arguments:\n");
@@ -1022,7 +1022,7 @@ int main(int argc, char *argv[])
 		opt.guid = get_port_guid(&osm, opt.guid);
 
 	if (cache_options == TRUE
-	    && osm_subn_write_conf_file(conf_file, &opt) != IB_SUCCESS)
+	    && osm_subn_write_conf_file(conf_file, &opt))
 		printf("\nosm_subn_write_conf_file failed!\n");
 
 	status = osm_opensm_bind(&osm, opt.guid);
diff --git a/opensm/opensm/osm_state_mgr.c b/opensm/opensm/osm_state_mgr.c
index 9b03314..8f1e086 100644
--- a/opensm/opensm/osm_state_mgr.c
+++ b/opensm/opensm/osm_state_mgr.c
@@ -1039,8 +1039,7 @@ _repeat_discovery:
 	sm->p_subn->subnet_initialization_error = FALSE;
 
 	/* rescan configuration updates */
-	status = osm_subn_rescan_conf_files(sm->p_subn);
-	if (status != IB_SUCCESS)
+	if (osm_subn_rescan_conf_files(sm->p_subn) < 0)
 		OSM_LOG(sm->p_log, OSM_LOG_ERROR, "ERR 331A: "
 			"osm_subn_rescan_conf_file failed\n");
 
diff --git a/opensm/opensm/osm_subnet.c b/opensm/opensm/osm_subnet.c
index f3f4c52..29a247a 100644
--- a/opensm/opensm/osm_subnet.c
+++ b/opensm/opensm/osm_subnet.c
@@ -777,7 +777,7 @@ osm_parse_prefix_routes_file(IN osm_subn_t * const p_subn)
 
 /**********************************************************************
  **********************************************************************/
-ib_api_status_t osm_subn_rescan_conf_files(IN osm_subn_t * const p_subn)
+int osm_subn_rescan_conf_files(IN osm_subn_t * const p_subn)
 {
 	FILE *opts_file;
 	char line[1024];
@@ -789,11 +789,11 @@ ib_api_status_t osm_subn_rescan_conf_files(IN osm_subn_t * const p_subn)
 	opts_file = fopen(p_subn->opt.config_file, "r");
 	if (!opts_file) {
 		if (errno == ENOENT)
-			return IB_SUCCESS;
+			return 1;
 		OSM_LOG(&p_subn->p_osm->log, OSM_LOG_ERROR,
 			"cannot open file \'%s\': %s\n",
 			p_subn->opt.config_file, strerror(errno));
-		return IB_ERROR;
+		return -1;
 	}
 
 	while (fgets(line, 1023, opts_file) != NULL) {
@@ -828,7 +828,7 @@ ib_api_status_t osm_subn_rescan_conf_files(IN osm_subn_t * const p_subn)
 
 	osm_parse_prefix_routes_file(p_subn);
 
-	return IB_SUCCESS;
+	return 0;
 }
 
 /**********************************************************************
@@ -1128,8 +1128,7 @@ static void subn_verify_conf_file(IN osm_subn_opt_t * const p_opts)
 
 /**********************************************************************
  **********************************************************************/
-ib_api_status_t osm_subn_parse_conf_file(char *file_name,
-					 IN osm_subn_opt_t * const p_opts)
+int osm_subn_parse_conf_file(char *file_name, osm_subn_opt_t * const p_opts)
 {
 	char line[1024];
 	FILE *opts_file;
@@ -1138,10 +1137,10 @@ ib_api_status_t osm_subn_parse_conf_file(char *file_name,
 	opts_file = fopen(file_name, "r");
 	if (!opts_file) {
 		if (errno == ENOENT)
-			return IB_SUCCESS;
+			return 1;
 		printf("cannot open file \'%s\': %s\n",
 		       file_name, strerror(errno));
-		return IB_ERROR;
+		return -1;
 	}
 
 	printf(" Reading Cached Option File: %s\n", file_name);
@@ -1379,13 +1378,12 @@ ib_api_status_t osm_subn_parse_conf_file(char *file_name,
 
 	subn_verify_conf_file(p_opts);
 
-	return IB_SUCCESS;
+	return 0;
 }
 
 /**********************************************************************
  **********************************************************************/
-ib_api_status_t osm_subn_write_conf_file(char *file_name,
-					 IN osm_subn_opt_t * const p_opts)
+int osm_subn_write_conf_file(char *file_name, IN osm_subn_opt_t *const p_opts)
 {
 	FILE *opts_file;
 
@@ -1393,7 +1391,7 @@ ib_api_status_t osm_subn_write_conf_file(char *file_name,
 	if (!opts_file) {
 		printf("cannot open file \'%s\' for writing: %s\n",
 		       file_name, strerror(errno));
-		return IB_ERROR;
+		return -1;
 	}
 
 	fprintf(opts_file,
@@ -1715,5 +1713,5 @@ ib_api_status_t osm_subn_write_conf_file(char *file_name,
 
 	fclose(opts_file);
 
-	return IB_SUCCESS;
+	return 0;
 }
-- 
1.5.4.1.122.gaa8d




More information about the general mailing list