示例#1
0
文件: ps4_ib_pp.c 项目: JonBau/pscom
static
int psib_get_hca_name(OUT VAPI_hca_id_t *hca_id, IN const char *in_hca_name)
{
    u_int32_t num_of_hcas, i;
    VAPI_hca_id_t *hca_id_buf_p, inst_hca_id;
    VAPI_ret_t rc;

    assert(hca_id != NULL);

    if (in_hca_name && in_hca_name[0]) {
	/* Use the in name. */
	strncpy(*hca_id, in_hca_name, HCA_MAXNAME);
	return 0;
    }

    /* Search for a HCA name */
    /* hca_id not specified by the user */

    while ((rc = EVAPI_list_hcas(1, &num_of_hcas, &inst_hca_id)) == VAPI_EAGAIN) {};
    if (rc != VAPI_OK) goto err_EVAPI_list_hcas;

    switch (num_of_hcas) {
    case 0:
	psib_err("There are no HCAs installed in your system!");
	return -1;
    case 1:
        strcpy(*hca_id, inst_hca_id);
	if (psib_debug)
	    printf("Using HCA: %s\n", *hca_id);
        break;
    default:
        strcpy(*hca_id, inst_hca_id);
	if (psib_debug) {
	    printf("Using first HCA: %s\n", *hca_id);
	    hca_id_buf_p = malloc(sizeof(VAPI_hca_id_t)*num_of_hcas);
	    if (!hca_id_buf_p) goto err_malloc;

	    rc = EVAPI_list_hcas(num_of_hcas, &num_of_hcas, hca_id_buf_p);
	    if (rc != VAPI_OK) goto err_EVAPI_list_hcas;

	    printf("The following HCAs are installed in your system. "
		   "Please use <-h hcaid> to specify one (not implemented!).\n");
	    for (i = 0; i < num_of_hcas; i++) {
		printf("%s\n", hca_id_buf_p[i]);
	    }
	    free(hca_id_buf_p);
	}
    }

    return 0;
    /* --- */
 err_malloc:
    psib_err("malloc() failed!");
    return -1;
    /* --- */
 err_EVAPI_list_hcas:
    psib_err_rc("EVAPI_list_hcas() failed", rc);
    return -1;
}
示例#2
0
/********************************************************************************
 * get the CA names available on the system
 * NOTE: user of this function needs to deallocate p_hca_ids after usage.
 ********************************************************************************/
static ib_api_status_t
__osm_vendor_get_ca_ids(IN osm_vendor_t * const p_vend,
			IN VAPI_hca_id_t ** const p_hca_ids,
			IN uint32_t * const p_num_guids)
{
	ib_api_status_t status;
	VAPI_ret_t vapi_res;

	OSM_LOG_ENTER(p_vend->p_log);

	CL_ASSERT(p_hca_ids);
	CL_ASSERT(p_num_guids);

	/* first call is just to get the number */
	vapi_res = EVAPI_list_hcas(0, p_num_guids, NULL);

	/* fail ? */
	if (vapi_res == VAPI_EINVAL_PARAM) {
		osm_log(p_vend->p_log, OSM_LOG_ERROR,
			"__osm_vendor_get_ca_ids: ERR 3D08: : "
			"Bad parameter in calling: EVAPI_list_hcas. (%d)\n",
			vapi_res);
		status = IB_ERROR;
		goto Exit;
	}

	/* NO HCA ? */
	if (*p_num_guids == 0) {
		osm_log(p_vend->p_log, OSM_LOG_ERROR,
			"__osm_vendor_get_ca_ids: ERR 3D09: "
			"No available channel adapters.\n");
		status = IB_INSUFFICIENT_RESOURCES;
		goto Exit;
	}

	/* allocate and really call - user of this function needs to deallocate it */
	*p_hca_ids =
	    (VAPI_hca_id_t *) malloc(*p_num_guids * sizeof(VAPI_hca_id_t));

	/* now call it really */
	vapi_res = EVAPI_list_hcas(*p_num_guids, p_num_guids, *p_hca_ids);

	/* too many ? */
	if (vapi_res == VAPI_EAGAIN) {
		osm_log(p_vend->p_log, OSM_LOG_ERROR,
			"__osm_vendor_get_ca_ids: ERR 3D10: "
			"More CA GUIDs than allocated array (%d).\n",
			*p_num_guids);
		status = IB_ERROR;
		goto Exit;
	}

	/* fail ? */
	if (vapi_res != VAPI_OK) {
		osm_log(p_vend->p_log, OSM_LOG_ERROR,
			"__osm_vendor_get_ca_ids: ERR 3D11: : "
			"Bad parameter in calling: EVAPI_list_hcas.\n");
		status = IB_ERROR;
		goto Exit;
	}

	if (osm_log_is_active(p_vend->p_log, OSM_LOG_DEBUG)) {
		osm_log(p_vend->p_log, OSM_LOG_DEBUG,
			"__osm_vendor_get_ca_ids: "
			"Detected %u local channel adapters.\n", *p_num_guids);
	}

	status = IB_SUCCESS;

Exit:
	OSM_LOG_EXIT(p_vend->p_log);
	return (status);
}