int __ibv_close_device(struct ibv_context *context) { int async_fd = context->async_fd; int cmd_fd = context->cmd_fd; int cq_fd = -1; struct verbs_context *context_ex; context_ex = verbs_get_ctx(context); if (context_ex) { struct verbs_device *verbs_device = verbs_get_device(context->device); verbs_device->uninit_context(verbs_device, context); free(context_ex); } else { context->device->ops.free_context(context); } close(async_fd); close(cmd_fd); if (abi_ver <= 2) close(cq_fd); return 0; }
int __ibv_close_device(struct ibv_context *context) { int async_fd = context->async_fd; int cmd_fd = context->cmd_fd; struct verbs_context_exp *context_exp; context_exp = verbs_get_exp_ctx(context); if (context_exp) { struct verbs_device *verbs_device = verbs_get_device(context->device); verbs_device->uninit_context(verbs_device, context); clear_env(context_exp->venv); free(context_exp); } else { context->device->ops.free_context(context); } close(async_fd); close(cmd_fd); return 0; }
struct ibv_context *__ibv_open_device(struct ibv_device *device) { struct verbs_device *verbs_device = verbs_get_device(device); char *devpath; int cmd_fd, ret; struct ibv_context *context; struct verbs_context *context_ex; if (asprintf(&devpath, "/dev/infiniband/%s", device->dev_name) < 0) return NULL; /* * We'll only be doing writes, but we need O_RDWR in case the * provider needs to mmap() the file. */ cmd_fd = open(devpath, O_RDWR | O_CLOEXEC); free(devpath); if (cmd_fd < 0) return NULL; if (!verbs_device) { context = device->ops.alloc_context(device, cmd_fd); if (!context) goto err; } else { /* Library now allocates the context */ context_ex = calloc(1, sizeof(*context_ex) + verbs_device->size_of_context); if (!context_ex) { errno = ENOMEM; goto err; } context_ex->context.abi_compat = __VERBS_ABI_IS_EXTENDED; context_ex->sz = sizeof(*context_ex); context = &context_ex->context; ret = verbs_device->init_context(verbs_device, context, cmd_fd); if (ret) goto verbs_err; /* initialize *all* library ops to either lib calls or * directly to provider calls. * context_ex->lib_new_func1 = __verbs_new_func1; * context_ex->lib_new_func2 = __verbs_new_func2; */ context_ex->lib_ibv_create_flow = context_ex->drv_ibv_create_flow; context_ex->lib_ibv_destroy_flow = context_ex->drv_ibv_destroy_flow; } context->device = device; context->cmd_fd = cmd_fd; pthread_mutex_init(&context->mutex, NULL); return context; verbs_err: free(context_ex); err: close(cmd_fd); return NULL; }
struct ibv_context *__ibv_open_device(struct ibv_device *device) { struct verbs_device *verbs_device = verbs_get_device(device); char *devpath; int cmd_fd, ret; struct ibv_context *context; struct verbs_context *context_ex; struct verbs_context_exp *context_exp; if (asprintf(&devpath, "/dev/infiniband/%s", device->dev_name) < 0) return NULL; /* * We'll only be doing writes, but we need O_RDWR in case the * provider needs to mmap() the file. */ cmd_fd = open(devpath, O_RDWR); free(devpath); if (cmd_fd < 0) return NULL; if (!verbs_device) { context = device->ops.alloc_context(device, cmd_fd); if (!context) goto err; } else { /* Library now allocates the context */ context_exp = calloc(1, sizeof(*context_ex) + sizeof(*context_exp) + verbs_device->size_of_context); if (!context_exp) { errno = ENOMEM; goto err; } context_ex = (struct verbs_context *)((void *)context_exp + sizeof(*context_exp)); context_exp->sz = sizeof(*context_exp); context_ex->has_comp_mask |= VERBS_CONTEXT_EXP; context_ex->context.abi_compat = __VERBS_ABI_IS_EXTENDED; context_ex->sz = sizeof(*context_ex); context_exp->exp_query_gid_attr = __ibv_exp_query_gid_attr; context = &context_ex->context; ret = verbs_device->init_context(verbs_device, context, cmd_fd); if (ret) goto verbs_err; /* initialize *all* library ops to either lib calls or * directly to provider calls. * context_ex->lib_new_func1 = __verbs_new_func1; * context_ex->lib_new_func2 = __verbs_new_func2; */ /* initialize *all* library experimental ops to either lib calls or * directly to provider calls. * context_exp->lib_new_func1 = __verbs_new_func1; * context_exp->lib_new_func2 = __verbs_new_func2; */ context_exp->lib_exp_create_qp = context_exp->drv_exp_create_qp; context_exp->lib_exp_query_device = context_exp->drv_exp_query_device; context_exp->lib_exp_query_port = context_exp->drv_exp_query_port; context_exp->lib_exp_ibv_reg_shared_mr = __ibv_reg_shared_mr; context_exp->lib_exp_ibv_create_flow = context_exp->drv_exp_ibv_create_flow; context_exp->lib_exp_ibv_destroy_flow = context_exp->drv_exp_ibv_destroy_flow; context_exp->lib_exp_modify_cq = (context_exp->drv_exp_modify_cq ? context_exp->drv_exp_modify_cq : __ibv_exp_modify_cq); context_exp->lib_exp_query_device = (context_exp->drv_exp_query_device ? context_exp->drv_exp_query_device : __ibv_exp_query_device); context_exp->lib_exp_modify_qp = __ibv_exp_modify_qp; context_exp->lib_exp_post_task = (context_exp->drv_exp_post_task ? context_exp->drv_exp_post_task : __ibv_exp_post_task); context_exp->lib_exp_reg_mr = __ibv_exp_reg_mr; context_exp->lib_exp_bind_mw = (context_exp->drv_exp_bind_mw ? context_exp->drv_exp_bind_mw : __ibv_exp_bind_mw); context_exp->lib_exp_arm_dct = (context_exp->drv_exp_arm_dct ? context_exp->drv_exp_arm_dct : __ibv_exp_arm_dct); context_exp->lib_exp_create_mr = (context_exp->drv_exp_create_mr ? context_exp->drv_exp_create_mr : __ibv_exp_create_mr); context_exp->lib_exp_query_mkey = (context_exp->drv_exp_query_mkey ? context_exp->drv_exp_query_mkey : __ibv_exp_query_mkey); context_exp->lib_exp_dealloc_mkey_list_memory = (context_exp->drv_exp_dealloc_mkey_list_memory ? context_exp->drv_exp_dealloc_mkey_list_memory : __ibv_exp_dealloc_mkey_list_memory); context_exp->lib_exp_alloc_mkey_list_memory = (context_exp->drv_exp_alloc_mkey_list_memory ? context_exp->drv_exp_alloc_mkey_list_memory : __ibv_exp_alloc_mkey_list_memory); context_exp->lib_exp_prefetch_mr = (context_exp->drv_exp_prefetch_mr ? context_exp->drv_exp_prefetch_mr : __ibv_exp_prefetch_mr); context_exp->exp_rereg_mr = __ibv_exp_rereg_mr; context_exp->lib_exp_use_priv_env = __ibv_exp_use_priv_env; context_exp->lib_exp_setenv = __ibv_exp_setenv; ret = ibv_exp_use_priv_env(context); if (ret) fprintf(stderr, PFX "Warning: ibv_exp_use_priv_env failed, errno: %d\n", errno); } context->device = device; context->cmd_fd = cmd_fd; pthread_mutex_init(&context->mutex, NULL); return context; verbs_err: free(context_exp); err: close(cmd_fd); return NULL; }