Esempio n. 1
0
int main(int argc, char ** argv)
{
    FSTATUS             fstatus;
    uint8               hfi         = 1;
    uint8               port        = 0;
    EUI64               portGuid    = -1;
	uint32 caCount, portCount;
	char fiName[255];
	int caPort;

	if (argc > 3)
	{
		fprintf(stderr, "oparesolvehfiport: Too many arguments\n");
		Usage(2);
	}
	if (argc >= 2) {
		if (strcmp(argv[1], "--help") == 0) {
			Usage(0);
		}
		if (FSUCCESS != StringToUint8(&hfi, argv[1], NULL, 0, TRUE)) {
			fprintf(stderr, "oparesolvehfiport: Invalid HFI Number: %s\n", argv[1]);
			Usage(2);
		}
	}
	if (argc == 3) {
		if (FSUCCESS != StringToUint8(&port, argv[2], NULL, 0, TRUE)) {
			fprintf(stderr, "oparesolvehfiport: Invalid Port Number: %s\n", argv[2]);
			Usage(2);
		}
	}

	// find portGuid specified
	fstatus = oib_get_portguid(hfi, port, NULL, NULL, &portGuid, NULL, NULL,
								&caCount, &portCount, fiName, &caPort, NULL);

	if (FNOT_FOUND == fstatus) {
		fprintf(stderr, "oparesolvehfiport: %s\n",
			iba_format_get_portguid_error(hfi, port, caCount, portCount));
		return 1;
	} else if (FSUCCESS != fstatus) {
		fprintf(stderr, "opasaquery: iba_get_portguid Failed: %s\n", iba_fstatus_msg(fstatus));
		return 1;
	}
    //printf("PORT GUID 0x%016"PRIx64"\n",portGuid);

	printf("%s:%d\n", fiName, caPort);

	return 0;
}
Esempio n. 2
0
/** ========================================================================= */
int oib_open_port_by_num (struct oib_port **port, int hfiNum, uint8_t port_num)
{
	FSTATUS fstatus;
	char name[IBV_SYSFS_NAME_MAX];
	int  num = -1;
	uint32_t ca_count;
	uint32_t port_count;
	IB_PORT_ATTRIBUTES	*attrib = NULL;
	int ret_code;
	
    fstatus = oib_get_portguid(hfiNum, port_num, NULL, NULL, NULL, NULL, &attrib,
			       &ca_count, &port_count, name, &num, NULL);
	if (fstatus != FSUCCESS) {
		if (fstatus != FNOT_FOUND ||
		(ca_count == 0 || port_count == 0) ||
		hfiNum > ca_count || port_num > port_count) {
			ret_code=EIO;
			goto done;
		}
		/* no active port was found for wildcard ca/port.
		 * return EAGAIN so caller could query specific port/ca
		 */
		ret_code=EAGAIN;
		goto done;
	}

	ret_code = oib_open_port(port, name, num);

	// Remember the local guid for pa client
	if (ret_code >= 0 && port && *port && attrib) 
	{
		(*port)->local_gid = attrib->GIDTable[0];
	}
	
	done:
		if (attrib)
			MemoryDeallocate(attrib);
		return ret_code;
}
Esempio n. 3
0
/**
 * Load up xml parser and extract values 
 * 
 * @return int 0 on success.
 */
int loadConfig(void){
	FMXmlCompositeConfig_t *xml_config = NULL;
	int i, j, hfi, port;

	char      name[UMAD_CA_NAME_LEN];
	uint64_t guid;
	uint64_t  prefix;
	uint16    sm_lid;
	uint8     sm_sl;
	uint8     port_state;

	xml_config = parseFmConfig(FM_XML_CONFIG, IXML_PARSER_FLAG_NONE, /* instance does not matter for startup */ 0, /* full parse */ 1, /* embedded */ 0);
	if (!xml_config) {
		fprintf(stdout, "Could not open or there was a parse error while reading configuration file ('%s')\n", FM_XML_CONFIG);
		return -1;
	}

	for (i = 0; i < FM_MAX_INSTANCES; i++) {
		if (!xml_config->fm_instance[i]) {
			config.instance[i].enabled = 0;
		} else {
			config.instance[i].enabled = xml_config->fm_instance[i]->fm_config.start;
			config.instance[i].component[SM_COMPONENT].enabled = xml_config->fm_instance[i]->sm_config.start;
			config.instance[i].component[SM_COMPONENT].maxRetries = xml_config->fm_instance[i]->sm_config.startup_retries;
			config.instance[i].component[SM_COMPONENT].retryTimeout = xml_config->fm_instance[i]->sm_config.startup_stable_wait * 60;
			config.instance[i].component[FE_COMPONENT].enabled = xml_config->fm_instance[i]->fe_config.start;
			config.instance[i].component[FE_COMPONENT].maxRetries = xml_config->fm_instance[i]->fe_config.startup_retries;
			config.instance[i].component[FE_COMPONENT].retryTimeout = xml_config->fm_instance[i]->fe_config.startup_stable_wait * 60;
		}
	}

	struct { // Struct created to make the if tree below more readable.
		uint32 hfi;
		uint32 port;
		uint64 guid;
	} selected_device[FM_MAX_INSTANCES] = {{0}};

	for (i = 0; i < FM_MAX_INSTANCES; ++i) {
		selected_device[i].hfi = xml_config->fm_instance[i]->fm_config.hca;
		selected_device[i].port = xml_config->fm_instance[i]->fm_config.port;
		selected_device[i].guid = xml_config->fm_instance[i]->fm_config.port_guid;
		if (xml_config->fm_instance[i]->fm_config.start) {
			// To make sure we don't miss mismatched guid and hfi/port configs, we want to fill in missing info
			if (selected_device[i].guid && oib_get_hfi_from_portguid(selected_device[i].guid, name, &hfi, &port, &prefix, &sm_lid, &sm_sl, &port_state) == VSTATUS_OK) {
				selected_device[i].hfi = hfi;
				selected_device[i].port = port;
			} else if (selected_device[i].port &&
					   oib_get_portguid(selected_device[i].hfi, selected_device[i].port, NULL, NULL, &guid, NULL, NULL, NULL, NULL, NULL, NULL, NULL) == VSTATUS_OK) {
				selected_device[i].guid = guid;
			}
			if (!selected_device[i].guid || !selected_device[i].port) {
				fprintf(stderr, "Invalid config detected! Coundn't find device for instance %d!.\n", i);
				releaseXmlConfig(xml_config, /* full */ 1);
				return 1;
			}
		}
	}

	for (i = 0; i < FM_MAX_INSTANCES; ++i) {
		if (xml_config->fm_instance[i]->fm_config.start) { // only compare enabled instances
			for (j = i + 1; j < FM_MAX_INSTANCES; ++j) {
				if (xml_config->fm_instance[j]->fm_config.start && // against other enabled instances
					((selected_device[i].hfi == selected_device[j].hfi &&
					selected_device[i].port == selected_device[j].port) ||
					selected_device[i].guid == selected_device[j].guid)) {
						fprintf(stderr, "Invalid config detected! Same HFI detected for multiple enabled FM instances.\n");
						releaseXmlConfig(xml_config, /* full */ 1);
						return 1;
				}
			}
		}
	}

	releaseXmlConfig(xml_config, /* full */ 1);
	return 0;
}