NAME
ibv_get_device_list, ibv_free_device_list - 利用可能な RDMA デバイスのリストを取得・解放する。
SYNOPSIS
#include <infiniband/verbs.h> struct ibv_device **ibv_get_device_list(int *num_devices); void ibv_free_device_list(struct ibv_device **list);
DESCRIPTION
ibv_get_device_list()
は現在有効な RDMA デバイス情報へのポインタの配列を返す。
この配列はサイズは明示されないが、配列の最後の要素が NULLで終わっている。
ただし引数の num_devices に非 NULL を指定した場合、num_devices の指す領域に RDMA デバイス数が設定される。
ibv_free_device_list()
は ibv_get_device_list()
の戻り値として渡された配列を解放する。
RETURN VALUE
ibv_get_device_list()
が成功した場合、RDMA デバイスの情報へのポインタの配列を返す。
もしエラーとなった場合は、errno にエラー原因を設定し、NULL を返す。
RDMA デバイスがない場合には num_devices の指す先には 0 を格納し、非 NULL の値を返す。
ibv_free_device_list()
には戻り値はない。
ERRORS
ibv_get_device_list()
はエラー時には errno に以下のエラーを設定する。
EPERM | アクセス権限がない。 |
ENOSYS | カーネルが RDMA をサポートしていない。 |
ENOMEM | メモリが不足している。 |
NOTES
クライアントプログラムは ibv_free_device_list()
を呼ぶ前に、ibv_open_device()
で RDMA デバイスをオープンする必要がある。
ibv_open_device()
した RDMA デバイスは、ibv_free_device_list()
を呼び配列を解放しても使うことができる。
EXAMPLES
ibv_get_device_list()
を使いホストに搭載されている HCA のリストを取得するプログラムは以下のようになる。
ibv_get_device_name() と ibv_get_device_guid() は、ibv_open_device() を呼び出さなくても利用可能である。
/* * $ gcc -g -Wall -libverbs -o sample-ibv_get_device_list sample-ibv_get_device_list.c */ #include <stdio.h> #include <stdlib.h> #include <inttypes.h> #include <infiniband/verbs.h> #include <infiniband/arch.h> /* for ntohll() */ int main(int argc, char **argv) { int i; struct ibv_device **dev_list; dev_list = ibv_get_device_list(NULL); if (!dev_list) { perror("Failed to get IB devices list"); exit(EXIT_FAILURE); } for (i=0 ; dev_list[i] ; i++) { struct ibv_device *ib_dev = dev_list[i]; printf("[%d] \"%s\" 0x%016" PRIx64 "\n", i, ibv_get_device_name(ib_dev), ntohll(ibv_get_device_guid(ib_dev))); } ibv_free_device_list(dev_list); return 0; }
SEE ALSO
InfiniBand Verbs API Reference、ibv_fork_init(3)、ibv_get_device_name(3)、ibv_get_device_guid(3)、ibv_open_device(3)
AUTHORS
原文 Dotan Barak <dotanba@gmail.com>
原文にない加筆がある。