struct ibv_context *ibv_open_device(struct ibv_device *device);

描述

函数会创建一个RDMA设备相关的context;可以通过ibv_close_device()函数来关闭设备。

context的作用

  • 查询RDMA设备的资源
  • 创建资源

注意:

  • 函数的功能与函数名所代表的意思不同,它事实上并不是打开设备;
  • 设备实际是被内核底层的驱动打开;
  • 设备可能被其他的用户/内核层的代码所使用;
  • 这个verb仅仅打开一个context,供用户层应用来使用它;

参数(struct ibv_device *device)

参数为函数ibv_get_device_list()返回RDMA可用RDMA设备数组的某一项。

返回值(struct ibv_context *)

struct ibv_context包含下面区域

  • async_fd:async_fd是一个文件描述符,为了用来读取异步事件。如果他想在一个non-blocking模式下读取一个异步事件,可以使用这个描述符
  • num_comp_vectors:可用于此RDMA设备的完成向量(completion vectors)的数量。

例子

#include <stdio.h>
#include <infiniband/verbs.h> int main(void)
{
struct ibv_device **device_list;
int num_devices;
int i;
int rc; device_list = ibv_get_device_list(&num_devices);
if (!device_list) {
fprintf(stderr, "Error, ibv_get_device_list() failed\n");
return -;
} printf("%d RDMA device(s) found:\n\n", num_devices); for (i = ; i < num_devices; ++ i) {
struct ibv_context *ctx; ctx = ibv_open_device(device_list[i]);
if (!ctx) {
fprintf(stderr, "Error, failed to open the device '%s'\n",
ibv_get_device_name(device_list[i]));
rc = -;
goto out;
} printf("The device '%s' was opened\n", ibv_get_device_name(ctx->device)); rc = ibv_close_device(ctx);
if (rc) {
fprintf(stderr, "Error, failed to close the device '%s'\n",
ibv_get_device_name(ctx->device));
rc = -;
goto out;
}
} ibv_free_device_list(device_list); return ; out:
ibv_free_device_list(device_list);
return rc;
}

最新文章

  1. 怎么使用CKEDITOR
  2. Elasticsearch增删改查 之 —— Update更新
  3. Location of several networks in brain
  4. 极光推送 JPush 项目简单使用
  5. java集合类(二)
  6. java核心知识点学习----多线程间的数据共享和对象独立,ThreadLocal详解
  7. 在Excel中实现查询功能
  8. PHP 性能分析与实验——性能的宏观分析
  9. Android学习笔记⑧——UI组件的学习AdapterView相关2
  10. 撤销 git reset --hard HEAD~1
  11. VS编译出现 HTTP 错误 403.14 - Forbidden 决绝办法
  12. js For循环练习。
  13. J Query库
  14. C#基础第二天
  15. c++堆和栈(转)
  16. Mysql Group by 使用解析
  17. TCP/IP模型及OSI七层参考模型各层的功能和主要协议
  18. 简述 cookies 和 session 的区别
  19. NIO,OIO,AIO区别
  20. 第三十天- 进程 Process模块 空间隔离

热门文章

  1. C++ 中memset 勿要对类使用
  2. sql语句练习题及答案
  3. eclipse使用maven tomcat插件部署无法关联源代码
  4. geolocation h5
  5. 数据结构 单链表元素定位 PTA
  6. DataProtection Key的选择
  7. elasticsearch 基础语句
  8. Velocity(5)——#macro 指令
  9. [转载] Linux的Top命令解析
  10. selenium3.7+ python3 添加cookie模拟登陆