[ofa-general] [PATCH 2/3] New utility ibsendtrap

Ira Weiny weiny2 at llnl.gov
Fri Mar 21 09:49:59 PDT 2008


On Fri, 21 Mar 2008 04:39:43 -0700
Hal Rosenstock <hrosenstock at xsigo.com> wrote:

> Ira,
> 
> On Thu, 2008-03-20 at 18:13 -0700, Ira Weiny wrote:
> > >From bd6213e232cb3e86574fd21cb13fdc00ffcd0a02 Mon Sep 17 00:00:00 2001
> > From: Ira K. Weiny <weiny2 at llnl.gov>
> > Date: Mon, 17 Mar 2008 15:20:05 -0700
> > Subject: [PATCH] New utility ibsendtrap
> 
> This looks like a test tool to me rather than a diagnostic. IMO such
> functionality belongs in the SMA.

Agreed, new patch series to follow,
Ira

> 
> -- Hal
> 
> > Signed-off-by: Ira K. Weiny <weiny2 at llnl.gov>
> > ---
> >  infiniband-diags/Makefile.am      |    6 +-
> >  infiniband-diags/src/ibsendtrap.c |  179 +++++++++++++++++++++++++++++++++++++
> >  2 files changed, 184 insertions(+), 1 deletions(-)
> >  create mode 100644 infiniband-diags/src/ibsendtrap.c
> > 
> > diff --git a/infiniband-diags/Makefile.am b/infiniband-diags/Makefile.am
> > index 07a6233..85411ea 100644
> > --- a/infiniband-diags/Makefile.am
> > +++ b/infiniband-diags/Makefile.am
> > @@ -10,7 +10,7 @@ endif
> >  sbin_PROGRAMS = src/ibaddr src/ibnetdiscover src/ibping src/ibportstate \
> >  	        src/ibroute src/ibstat src/ibsysstat src/ibtracert \
> >  	        src/perfquery src/sminfo src/smpdump src/smpquery \
> > -	        src/saquery src/vendstat
> > +	        src/saquery src/vendstat src/ibsendtrap
> >  
> >  sbin_SCRIPTS = scripts/ibcheckerrs scripts/ibchecknet scripts/ibchecknode \
> >                 scripts/ibcheckport scripts/ibhosts scripts/ibstatus \
> > @@ -71,6 +71,10 @@ src_saquery_SOURCES = src/saquery.c src/ibdiag_common.c
> >  src_saquery_CFLAGS = -Wall -DOSM_VENDOR_INTF_OPENIB -DVENDOR_RMPP_SUPPORT -DDUAL_SIDED_RMPP $(DBGFLAGS)
> >  src_saquery_LDFLAGS = -Wl,--rpath -Wl,$(libdir)
> >  
> > +src_ibsendtrap_SOURCES = src/ibsendtrap.c src/ibdiag_common.c
> > +src_ibsendtrap_CFLAGS = -Wall $(DBGFLAGS)
> > +src_ibsendtrap_LDFLAGS = -Wl,--rpath -Wl,$(libdir)
> > +
> >  src_vendstat_SOURCES = src/vendstat.c src/ibdiag_common.c
> >  src_vendstat_CFLAGS = -Wall $(DBGFLAGS)
> >  
> > diff --git a/infiniband-diags/src/ibsendtrap.c b/infiniband-diags/src/ibsendtrap.c
> > new file mode 100644
> > index 0000000..ae5069b
> > --- /dev/null
> > +++ b/infiniband-diags/src/ibsendtrap.c
> > @@ -0,0 +1,179 @@
> > +/*
> > + * Copyright (c) 2008 Lawrence Livermore National Security
> > + *
> > + * Produced at Lawrence Livermore National Laboratory.
> > + * Written by Ira Weiny <weiny2 at llnl.gov>.
> > + *
> > + * This software is available to you under a choice of one of two
> > + * licenses.  You may choose to be licensed under the terms of the GNU
> > + * General Public License (GPL) Version 2, available from the file
> > + * COPYING in the main directory of this source tree, or the
> > + * OpenIB.org BSD license below:
> > + *
> > + *     Redistribution and use in source and binary forms, with or
> > + *     without modification, are permitted provided that the following
> > + *     conditions are met:
> > + *
> > + *      - Redistributions of source code must retain the above
> > + *        copyright notice, this list of conditions and the following
> > + *        disclaimer.
> > + *
> > + *      - Redistributions in binary form must reproduce the above
> > + *        copyright notice, this list of conditions and the following
> > + *        disclaimer in the documentation and/or other materials
> > + *        provided with the distribution.
> > + *
> > + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
> > + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
> > + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
> > + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
> > + * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
> > + * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
> > + * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
> > + * SOFTWARE.
> > + *
> > + */
> > +
> > +#include <stdio.h>
> > +#include <unistd.h>
> > +
> > +#define _GNU_SOURCE
> > +#include <getopt.h>
> > +
> > +#include <infiniband/mad.h>
> > +#include <infiniband/iba/ib_types.h>
> > +
> > +#include "ibdiag_common.h"
> > +
> > +char     *argv0 = "";
> > +char	 *sa_hca_name = NULL;
> > +uint32_t  sa_port_num = 0;
> > +
> > +
> > +static int
> > +send_144_node_desc_update(void)
> > +{
> > +	ib_portid_t sm_port;
> > +	ib_portid_t selfportid;
> > +	int selfport;
> > +	ib_rpc_t  trap_rpc;
> > +	ib_mad_notice_attr_t notice;
> > +
> > +	if (ib_resolve_self(&selfportid, &selfport, NULL))
> > +		IBERROR("can't resolve self");
> > +
> > +	if (ib_resolve_smlid(&sm_port, 0))
> > +		IBERROR("can't resolve SM destination port");
> > +
> > +	memset(&trap_rpc, 0, sizeof(trap_rpc));
> > +	trap_rpc.mgtclass = IB_SMI_CLASS;
> > +	trap_rpc.method = IB_MAD_METHOD_TRAP;
> > +	trap_rpc.trid = mad_trid();
> > +	trap_rpc.attr.id = NOTICE;
> > +	trap_rpc.datasz = IB_SMP_DATA_SIZE;
> > +	trap_rpc.dataoffs = IB_SMP_DATA_OFFS;
> > +
> > +	memset(&notice, 0, sizeof(notice));
> > +	notice.generic_type = 0x80 | IB_NOTICE_TYPE_INFO;
> > +	notice.g_or_v.generic.prod_type_lsb = cl_hton16(IB_NODE_TYPE_CA);
> > +	notice.g_or_v.generic.trap_num = cl_hton16(144);
> > +	notice.issuer_lid = cl_hton16(selfportid.lid);
> > +	notice.data_details.ntc_144.lid = cl_hton16(selfportid.lid);
> > +	notice.data_details.ntc_144.local_changes = TRAP_144_MASK_OTHER_LOCAL_CHANGES;
> > +	notice.data_details.ntc_144.change_flgs = TRAP_144_MASK_NODE_DESCRIPTION_CHANGE;
> > +
> > +	return (mad_send(&trap_rpc, &sm_port, NULL, &notice));
> > +}
> > +
> > +typedef struct _trap_def {
> > +	char *trap_name;
> > +	int (*send_func)(void);
> > +} trap_def_t;
> > +
> > +trap_def_t traps[2] = {
> > +	{ "node_desc_change", send_144_node_desc_update },
> > +	{ NULL, NULL }
> > +};
> > +
> > +static void
> > +usage(void)
> > +{
> > +	int i = 0;
> > +	fprintf(stderr, "Usage: %s [-hV]"
> > +		"[-C <ca_name> -P <ca_port>] <trap_name>\n",
> > +		argv0);
> > +	fprintf(stderr, "   Queries node records by default\n");
> > +	fprintf(stderr, "   -C <ca_name> specify the SA query HCA\n");
> > +	fprintf(stderr, "   -P <ca_port> specify the SA query port\n");
> > +	fprintf(stderr, "   -V print version\n");
> > +	fprintf(stderr, "   <trap_name> can be one of the following\n");
> > +	for (i=0; traps[i].trap_name; i++) {
> > +		fprintf(stderr, "      %s\n", traps[i].trap_name);
> > +	}
> > +	fprintf(stderr, "   default behavior is to send \"%s\"\n",
> > +		traps[0].trap_name);
> > +
> > +	exit(-1);
> > +}
> > +
> > +int
> > +send_trap(char *trap_name)
> > +{
> > +	int i = 0;
> > +	for (i=0; traps[i].trap_name; i++) {
> > +		if (strcmp(traps[i].trap_name, trap_name) == 0) {
> > +			return (traps[i].send_func());
> > +		}
> > +	}
> > +	usage();
> > +	exit(1);
> > +}
> > +
> > +int
> > +main(int argc, char **argv)
> > +{
> > +	int mgmt_classes[2] = {IB_SMI_CLASS, IB_SMI_DIRECT_CLASS};
> > +	int ch = 0;
> > +	char *trap_name = NULL;
> > +
> > +	static char const str_opts[] = "hVP:C:";
> > +	static const struct option long_opts [] = {
> > +	   {"Version", 0, 0, 'V'},
> > +	   {"P", 1, 0, 'P'},
> > +	   {"C", 1, 0, 'C'},
> > +	   {"help", 0, 0, 'h'},
> > +	   { }
> > +	};
> > +
> > +	argv0 = argv[0];
> > +
> > +	while ((ch = getopt_long(argc, argv, str_opts, long_opts, NULL)) != -1) {
> > +		switch (ch) {
> > +		case 'V':
> > +			fprintf(stderr, "%s %s\n", argv0, get_build_version());
> > +			exit(-1);
> > +		case 'C':
> > +			sa_hca_name = optarg;
> > +			break;
> > +		case 'P':
> > +			sa_port_num = strtoul(optarg, NULL, 0);
> > +			break;
> > +		case 'h':
> > +		default:
> > +			usage();
> > +		}
> > +	}
> > +	argc -= optind;
> > +	argv += optind;
> > +
> > +	if (!argv[0]) {
> > +		trap_name = traps[0].trap_name;
> > +	} else {
> > +		trap_name = argv[0];
> > +	}
> > +
> > +	madrpc_show_errors(1);
> > +	madrpc_init(NULL, 0, mgmt_classes, 2);
> > +
> > +	return (send_trap(trap_name));
> > +}



More information about the general mailing list