ibv_close_device()函数

Posted huststephen

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了ibv_close_device()函数相关的知识,希望对你有一定的参考价值。

int ibv_close_device(struct ibv_context *context);

 

描述

函数用来关闭一个RDMA设备context;

注意:

  • 函数不能用来释放与该Context关联的资源
  • 用户应该在调用这个ibv_close_device()函数之前释放这些资源,为了避免资源泄露
  • 使用这些孤子资源可能会导致一个segmentation fault
  • 当进程结束时,操作系统会自动清理这些资源

 

参数

参数为函数ibv_open_device()返回值

 

返回值

  • 成功返回0
  • 失败返回-1

 

例子

打开设备context 以及 关闭它

#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 -1;
    }

    printf("%d RDMA device(s) found:\n\n", num_devices);

    for (i = 0; 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 = -1;
            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 = -1;
            goto out;
        }
    }
        
    ibv_free_device_list(device_list);

    return 0;

out:
    ibv_free_device_list(device_list);
    return rc;
}

 

以上是关于ibv_close_device()函数的主要内容,如果未能解决你的问题,请参考以下文章

VSCode自定义代码片段——声明函数

VSCode自定义代码片段8——声明函数

使用从循环内的代码片段中提取的函数避免代码冗余/计算开销

在 Visual Studio 中创建构造函数的代码片段或快捷方式

调用模板化成员函数:帮助我理解另一个 *** 帖子中的代码片段

web代码片段