Skip to content

ibv_open_device()

Contents

4.75 avg. rating (95% score) - 4 votes
struct ibv_context *ibv_open_device(struct ibv_device *device);

Description

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.

Parameters

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

Examples

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",
                ibv_get_device_name(device_list[i]));
        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",
                ibv_get_device_name(ctx->device));
        return -1;
}

open_devices.c

Share Our Posts

Share this post through social bookmarks.

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

Comments

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

      Hi.

      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.

      Thanks
      Dotan

  2. Robert Zeh says: November 1, 2019

    If this goes wrong, and returns NULL, is there a way to find out why?

    • Dotan Barak says: February 22, 2020

      Hi.

      Unfortunately ,the answer is "no".

      This is once of the problems in the RDMA verbs
      :(

      You can get the same errno code for many reasons, without a real ability to understand what went wrong.

      Thanks
      Dotan

  3. Bob says: November 7, 2020

    Will the context still remain valid, if the RDMA device is rebooted after ibv_open_device() is called. Or do we need to call ibv_open_device() again after reboot to get a valid context?

    • Dotan Barak says: November 21, 2020

      Hi.

      I don't understand what "RDMA device is rebooted", so i can't answer.
      Can you elaborate on that?

      Sorry
      Dotan

Add a Comment

This comment will be moderated; answer may be provided within 14 days.

Time limit is exhausted. Please reload CAPTCHA.