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

 

posted @ 2017-12-13 20:07  huststephen  阅读(627)  评论(0编辑  收藏  举报