[ofa-general] Re: [PATCH 8/8] Convert ibqueryerrors.pl to C and use new ibnetdisc library.

Sasha Khapyorsky sashak at voltaire.com
Sat Apr 25 08:54:41 PDT 2009


On 13:31 Thu 23 Apr     , Ira Weiny wrote:
> diff --git a/infiniband-diags/src/ibqueryerrors.c b/infiniband-diags/src/ibqueryerrors.c
> new file mode 100644
> index 0000000..9d96190
> --- /dev/null
> +++ b/infiniband-diags/src/ibqueryerrors.c
> @@ -0,0 +1,469 @@
> +/*
> + * Copyright (c) 2004-2007 Voltaire Inc.  All rights reserved.
> + * Copyright (c) 2007 Xsigo Systems Inc.  All rights reserved.
> + * Copyright (c) 2008 Lawrence Livermore National Lab.  All rights reserved.
> + *
> + * 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.
> + *
> + */
> +
> +#if HAVE_CONFIG_H
> +#  include <config.h>
> +#endif /* HAVE_CONFIG_H */
> +
> +#define _GNU_SOURCE
> +#include <stdio.h>
> +#include <stdlib.h>
> +#include <unistd.h>
> +#include <stdarg.h>
> +#include <time.h>
> +#include <string.h>
> +#include <getopt.h>
> +#include <errno.h>
> +#include <inttypes.h>
> +
> +#include <infiniband/complib/cl_nodenamemap.h>

AFAIR WinOF doesn't like such inclusion and uses

#include <complib/filename.h>

instead. I'm changing.

> +#include <infiniband/ibnetdisc.h>
> +#include <infiniband/mad.h>
> +
> +#include "ibdiag_common.h"
> +
> +char *argv0 = "ibqueryerrors";

argv0 variable is not needed if you are using ibdiag_common stuff.
Removing.

> +static FILE *f;

I don't see where 'f' is used (except 'f = stdout;' below). Removing.

[snip...]

> +static int process_opt(void *context, int ch, char *optarg)
> +{
> +	switch (ch) {
> +	case 's':
> +		calculate_suppressed_fields(optarg);
> +		break;
> +	case 'c':
> +		/* Right now this is the only "common" error */
> +		add_suppressed(IB_PC_ERR_SWITCH_REL_F);
> +		break;
> +	case 1:
> +		node_name_map_file = strdup(optarg);
> +		break;
> +	case 2:
> +		data_counters++;
> +		break;
> +	case 3:
> +		all_nodes++;
> +		break;
> +	case 'S':
> +		switch_guid_str = strdup(optarg);

Why should optarg be strdup()ed?

> +		switch_guid = (uint64_t)strtoull(switch_guid_str, 0, 0);
> +		break;
> +	case 'D':
> +		dr_path = strdup(optarg);
> +		break;
> +	case 'r':
> +		port_config++;
> +		break;
> +	case 'R': /* nop */
> +		break;
> +	default:
> +		return -1;
> +	}
> +
> +	return 0;
> +}
> +
> +int
> +main(int argc, char **argv)
> +{
> +	int rc = 0;
> +	ibnd_fabric_t *fabric = NULL;
> +
> +	int mgmt_classes[4] = {IB_SMI_CLASS, IB_SMI_DIRECT_CLASS, IB_SA_CLASS, IB_PERFORMANCE_CLASS};
> +
> +	const struct ibdiag_opt opts[] = {
> +		{ "suppress", 's', 1, "<err1,err2,...>", "suppress errors listed" },
> +		{ "suppress-common", 'c', 0, NULL, "suppress some of the common counters" },
> +		{ "node-name-map", 1, 1, "<file>", "node name map file" },
> +		{ "switch", 'S', 1, "<switch_guid>", "query only <switch_guid> (hex format)"},
> +		{ "Direct", 'D', 1, "<dr_path>", "query only switch specified by <dr_path>"},
> +		{ "report-port", 'r', 0, NULL, "report port configuration information"},
> +		{ "GNDN", 'R', 0, NULL, "(This option is obsolete and does nothing)"},
> +		{ "data", 2, 0, NULL, "include the data counters in the output"},
> +		{ "all", 3, 0, NULL, "output all nodes (not just switches)"},
> +		{ 0 }
> +	};
> +	char usage_args[] = "";
> +
> +	ibdiag_process_opts(argc, argv, "sDLG", "snSrR", opts, process_opt,
> +			    usage_args, NULL);
> +
> +	f = stdout;
> +
> +	argc -= optind;
> +	argv += optind;
> +
> +	if (ibverbose)
> +		ibnd_debug(1);
> +
> +	ibmad_port = mad_rpc_open_port(ibd_ca, ibd_ca_port, mgmt_classes, 4);
> +	if (!ibmad_port)
> +		IBERROR("Failed to open port; %s:%d\n", ibd_ca, ibd_ca_port);
> +
> +	node_name_map = open_node_name_map(node_name_map_file);
> +
> +	if (switch_guid) {
> +		/* limit the scan the fabric around the target */
> +		ib_portid_t portid = {0};
> +
> +		if (ib_resolve_portid_str_via(&portid, switch_guid_str, IB_DEST_GUID,
> +					ibd_sm_id, ibmad_port) < 0) {
> +			fprintf(stderr, "can't resolve destination port %s %p\n",
> +				switch_guid_str, ibd_sm_id);
> +			rc = 1;
> +			goto close_port;
> +		}
> +
> +		if ((fabric = ibnd_discover_fabric(ibmad_port, ibd_timeout, &portid, 1)) == NULL) {
> +			fprintf(stderr, "discover failed\n");
> +			rc = 1;
> +			goto close_port;
> +		}
> +	} else {
> +		if ((fabric = ibnd_discover_fabric(ibmad_port, ibd_timeout, NULL, -1)) == NULL) {
> +			fprintf(stderr, "discover failed\n");
> +			rc = 1;
> +			goto close_port;
> +		}

Above you are using IBERROR(), here is fprintf(stderr, ...). Could it be
consistent? (if yes - it is subsequent patch).

> +	}
> +
> +	report_suppressed();
> +
> +	if (switch_guid) {
> +		ibnd_node_t *node = ibnd_find_node_guid(fabric, switch_guid);
> +		print_node(node, NULL);
> +	} else if (dr_path) {
> +		ibnd_node_t *node = ibnd_find_node_dr(fabric, dr_path);
> +		print_node(node, NULL);

When GUID or DR Path are specified we don't need to discover whole
fabric, but can try to resolve LID using SA or querying PortInfo.

Although when in GUID is specified and SA is not responsive there is
probably no other choice than discover.

Sasha



More information about the general mailing list