[ofa-general] [PATCH v3] opensm/osm_console.c : Added dump_portguid function to console to generate a list of port guids matching one or more regexps
Nicolas Morey Chaisemartin
nicolas.morey-chaisemartin at ext.bull.net
Wed Feb 11 22:46:27 PST 2009
This add a dump_portguid functionnality to openSM console which makes it really easy to generate cn_guid_file, root_guid_file and such
by dumping into a file all port guids whom nodedesc contains at least one of the provided regexps
Signed-off-by: Nicolas Morey-Chaisemartin <nicolas.morey-chaisemartin at ext.bull.net>
---
Diff from v2:
- Changed lock to read-only instead of exclusive
- Removed useless cl_spinlock_release (remains from 1st patch)
opensm/opensm/osm_console.c | 104 +++++++++++++++++++++++++++++++++++++++++++
1 files changed, 104 insertions(+), 0 deletions(-)
diff --git a/opensm/opensm/osm_console.c b/opensm/opensm/osm_console.c
index c6e8e59..5bc1079 100644
--- a/opensm/opensm/osm_console.c
+++ b/opensm/opensm/osm_console.c
@@ -42,6 +42,7 @@
#include <sys/types.h>
#include <sys/socket.h>
#include <netdb.h>
+#include <regex.h>
#ifdef ENABLE_OSM_CONSOLE_SOCKET
#include <arpa/inet.h>
#endif
@@ -1173,6 +1174,108 @@ static void version_parse(char **p_last, osm_opensm_t * p_osm, FILE * out)
}
/* more parse routines go here */
+typedef struct _regexp_list {
+ regex_t exp;
+ struct _regexp_list *next;
+} regexp_list_t;
+
+static void dump_portguid_parse(char **p_last, osm_opensm_t * p_osm, FILE * out)
+{
+ cl_qmap_t *p_port_guid_tbl;
+ osm_port_t *p_port;
+ osm_port_t *p_next_port;
+
+ regexp_list_t *p_head_regexp = NULL;
+ regexp_list_t *p_regexp;
+
+ /* Option variables */
+ char *p_cmd = NULL;
+ FILE *output = out;
+
+ /* Read commande line */
+
+ while (1) {
+ p_cmd = next_token(p_last);
+ if (p_cmd) {
+ if (strcmp(p_cmd, "file") == 0) {
+ p_cmd = next_token(p_last);
+ if (p_cmd) {
+ output = fopen(p_cmd, "w+");
+ if (output == NULL) {
+ fprintf(out,
+ "Could not open file %s: %s\n",
+ p_cmd, strerror(errno));
+ output = out;
+ }
+ } else
+ fprintf(out, "No file name passed\n");
+ } else {
+ p_regexp = malloc(sizeof(*p_regexp));
+ if (regcomp
+ (&(p_regexp->exp), p_cmd,
+ REG_NOSUB | REG_EXTENDED) != 0) {
+ fprintf(out,
+ "Couldn't parse regular expression %s. Skipping it.\n",
+ p_cmd);
+ }
+ p_regexp->next = p_head_regexp;
+ p_head_regexp = p_regexp;
+ }
+ } else
+ break; /* No more tokens */
+
+ }
+
+ /* Check we have at least one expression to match */
+ if (p_head_regexp == NULL) {
+ fprintf(out, "No valid expression provided. Aborting\n");
+ return;
+ }
+
+ if (p_osm->sm.p_subn->need_update != 0) {
+ fprintf(out, "Subnet is not ready yet. Try again later.\n");
+ return;
+ }
+
+ /* Subnet doesn't need to be updated so we can carry on */
+
+ CL_PLOCK_ACQUIRE(p_osm->sm.p_lock);
+ p_port_guid_tbl = &(p_osm->sm.p_subn->port_guid_tbl);
+
+ p_next_port = (osm_port_t *) cl_qmap_head(p_port_guid_tbl);
+ while (p_next_port != (osm_port_t *) cl_qmap_end(p_port_guid_tbl)) {
+
+ p_port = p_next_port;
+ p_next_port =
+ (osm_port_t *) cl_qmap_next(&p_next_port->map_item);
+
+ for (p_regexp = p_head_regexp; p_regexp != NULL;
+ p_regexp = p_regexp->next)
+ if (regexec
+ (&(p_regexp->exp), p_port->p_node->print_desc, 0,
+ NULL, 0) == 0)
+ fprintf(output, "0x%" PRIxLEAST64 "\n",
+ cl_ntoh64(p_port->p_physp->port_guid));
+ }
+
+ CL_PLOCK_RELEASE(p_osm->sm.p_lock);
+ if (output != out)
+ fclose(output);
+
+}
+
+static void help_dump_portguid(FILE * out, int detail)
+{
+ fprintf(out,
+ "dump_portguid [file filename] regexp1 [regexp2 [regexp3 ...]] -- Dump port GUID matching a regexp \n");
+ if (detail) {
+ fprintf(out,
+ "getguidgetguid -- Dump all the port GUID whom node_desc matches one of the provided regexp\n");
+ fprintf(out,
+ " [file filename] -- Send the port GUID list to the specified file instead of regular output\n");
+ }
+
+}
static const struct command console_cmds[] = {
{"help", &help_command, &help_parse},
@@ -1192,6 +1295,7 @@ static const struct command console_cmds[] = {
#ifdef ENABLE_OSM_PERF_MGR
{"perfmgr", &help_perfmgr, &perfmgr_parse},
#endif /* ENABLE_OSM_PERF_MGR */
+ {"dump_portguid", &help_dump_portguid, &dump_portguid_parse},
{NULL, NULL, NULL} /* end of array */
};
--
1.6.1
More information about the general
mailing list