Exemple #1
0
int
main(int argc, char *argv[])
{
	char names[UMAD_MAX_DEVICES][UMAD_CA_NAME_LEN];
	int dev_port = -1;
	int list_only = 0, short_format = 0, list_ports = 0;
	int n, i;

	static char const str_opts[] = "dlspVhu";
	static const struct option long_opts[] = {
		{ "debug", 0, 0, 'd'},
		{ "list_of_cas", 0, 0, 'l'},
		{ "short", 0, 0, 's'},
		{ "port_list", 0, 0, 'p'},
		{ "Version", 0, 0, 'V'},
		{ "help", 0, 0, 'h'},
		{ "usage", 0, 0, 'u'},
		{ }
	};

	argv0 = argv[0];

	while (1) {
		int ch = getopt_long(argc, argv, str_opts, long_opts, NULL);
		if ( ch == -1 )
			break;
		switch(ch) {
		case 'd':
			debug++;
			break;
		case 'l':
			list_only++;
			break;
		case 's':
			short_format++;
			break;
		case 'p':
			list_ports++;
			break;
		case 'V':
			fprintf(stderr, "%s %s\n", argv0, get_build_version() );
			exit(-1);
		default:
			usage();
			break;
		}
	}
	argc -= optind;
	argv += optind;

	if (argc > 1)
		dev_port = strtol(argv[1], 0, 0);

	if (umad_init() < 0)
		IBPANIC("can't init UMAD library");

	if ((n = umad_get_cas_names(names, UMAD_MAX_DEVICES)) < 0)
		IBPANIC("can't list IB device names");

	if (argc) {
		for (i = 0; i < n; i++)
			if (!strncmp(names[i], argv[0], sizeof names[i]))
				break;
		if (i >= n)
			IBPANIC("'%s' IB device can't be found", argv[0]);

		strncpy(names[i], argv[0], sizeof names[i]);
		n = 1;
	}

	if (list_ports) {
		if (ports_list(names, n) < 0)
			IBPANIC("can't list ports");
		return 0;
	}

	if (!list_only && argc) {
		if (ca_stat(argv[0], dev_port, short_format) < 0)
			IBPANIC("stat of IB device '%s' failed", argv[0]);
		return 0;
	}

	for (i = 0; i < n; i++) {
		if (list_only)
			printf("%s\n", names[i]);
		else
			if (ca_stat(names[i], -1, short_format) < 0)
				IBPANIC("stat of IB device '%s' failed", names[i]);
	}

	return 0;
}
Exemple #2
0
int main(int argc, char *argv[])
{
    char names[UMAD_MAX_DEVICES][UMAD_CA_NAME_LEN];
    int dev_port = -1;
    int n, i;

    const struct ibdiag_opt opts[] = {
        {"list_of_cas", 'l', 0, NULL, "list all IB devices"},
        {"short", 's', 0, NULL, "short output"},
        {"port_list", 'p', 0, NULL, "show port list"},
        {0}
    };
    char usage_args[] = "<ca_name> [portnum]";
    const char *usage_examples[] = {
        "-l       # list all IB devices",
        "mthca0 2 # stat port 2 of 'mthca0'",
        NULL
    };

    ibdiag_process_opts(argc, argv, NULL, "CDeGKLPsty", opts, process_opt,
                        usage_args, usage_examples);

    argc -= optind;
    argv += optind;

    if (argc > 1)
        dev_port = strtol(argv[1], 0, 0);

    if (umad_init() < 0)
        IBPANIC("can't init UMAD library");

    if ((n = umad_get_cas_names(names, UMAD_MAX_DEVICES)) < 0)
        IBPANIC("can't list IB device names");

    if (argc) {
        for (i = 0; i < n; i++)
            if (!strncmp(names[i], argv[0], sizeof names[i]))
                break;
        if (i >= n)
            IBPANIC("'%s' IB device can't be found", argv[0]);

        strncpy(names[0], argv[0], sizeof(names[0])-1);
        names[0][sizeof(names[0])-1] = '\0';
        n = 1;
    }

    if (list_ports) {
        if (ports_list(names, n) < 0)
            IBPANIC("can't list ports");
        return 0;
    }

    for (i = 0; i < n; i++) {
        if (list_only)
            printf("%s\n", names[i]);
        else if (ca_stat(names[i], dev_port, short_format) < 0)
            IBPANIC("stat of IB device '%s' failed", names[i]);
    }

    return 0;
}