Skip to content


4.50 avg. rating (91% score) - 2 votes
struct ibv_context *ibv_open_device(struct ibv_device *device);


ibv_open_device() creates a context for the RDMA device device. This context will later be used to query its resources or for creating resources and should be released with ibv_close_device().

Unlike the verb name suggests, it doesn't actually open the device, this device was opened by the kernel low-level driver and may be used by other user/kernel level code. This verb only opens a context to allow user level applications to use it.


Name Direction Description
device in RDMA device entry that was returned from ibv_get_device_list()

Return Values

Value Description
device context A pointer to the RDMA device context
This pointer also contains the following fields:

async_fd A file descriptor that is used (internally) in order to read the asynchronous events. One may use it if he wants to read the asynchronous events in non-blocking mode
num_comp_vectors The number of Completion vectors (i.e. MSI-X vectors) available for this RDMA device.
NULL On failure


Open a device context and close it:

/* In this example, we assume that this variable already holds the list of available devices */
struct ibv_device **device_list;
struct ibv_context *ctx;
ctx = ibv_open_device(device_list[0]);
if (!ctx) {
        fprintf(stderr, "Error, failed to open the device '%s'\n",
        return -1;
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",
        return -1;


Share Our Posts

Share this post through social bookmarks.

  • Delicious
  • Digg
  • Newsvine
  • RSS
  • StumbleUpon
  • Technorati


Tell us what do you think.

  1. Param says: June 25, 2017

    Whenever I call a ibv_open_device will it return me a same context or a different one. This doubt is because can I use same protection domain for different rdma queue pairs.

    • Dotan Barak says: July 2, 2017


      ibv_open_device() may or may not return a different context (it is implementation dependent).
      I would suggest to you: please don't assume that the context is the same.


Add a Comment

Fill in the form and submit.

Time limit is exhausted. Please reload CAPTCHA.