Skip to content

Commit

Permalink
libibverbs: Get stable IB device index
Browse files Browse the repository at this point in the history
The kernel which supports query over netlink interface returns stable IB
device index as part of it. This index much better identifier than sysfs
name that can be renamed and/or disappear. Up till now, this index was
used internally by libibverbs, but the next patch will rely on this API
in the librdmacm code.

The -1 as returned value means that kernel doesn't support indexes.

Reviewed-by: Yishai Hadas <yishaih@mellanox.com>
Signed-off-by: Leon Romanovsky <leonro@mellanox.com>
  • Loading branch information
Leon Romanovsky committed May 13, 2020
1 parent 4ca5caf commit 307f922
Show file tree
Hide file tree
Showing 9 changed files with 67 additions and 2 deletions.
2 changes: 2 additions & 0 deletions debian/libibverbs1.symbols
Expand Up @@ -6,6 +6,7 @@ libibverbs.so.1 libibverbs1 #MINVER#
IBVERBS_1.6@IBVERBS_1.6 24
IBVERBS_1.7@IBVERBS_1.7 25
IBVERBS_1.8@IBVERBS_1.8 28
IBVERBS_1.9@IBVERBS_1.9 30
(symver)IBVERBS_PRIVATE_25 25
ibv_ack_async_event@IBVERBS_1.0 1.1.6
ibv_ack_async_event@IBVERBS_1.1 1.1.6
Expand Down Expand Up @@ -58,6 +59,7 @@ libibverbs.so.1 libibverbs1 #MINVER#
ibv_get_cq_event@IBVERBS_1.1 1.1.6
ibv_get_device_guid@IBVERBS_1.0 1.1.6
ibv_get_device_guid@IBVERBS_1.1 1.1.6
ibv_get_device_index@IBVERBS_1.9 30
ibv_get_device_list@IBVERBS_1.0 1.1.6
ibv_get_device_list@IBVERBS_1.1 1.1.6
ibv_get_device_name@IBVERBS_1.0 1.1.6
Expand Down
2 changes: 1 addition & 1 deletion libibverbs/CMakeLists.txt
Expand Up @@ -21,7 +21,7 @@ configure_file("libibverbs.map.in"

rdma_library(ibverbs "${CMAKE_CURRENT_BINARY_DIR}/libibverbs.map"
# See Documentation/versioning.md
1 1.8.${PACKAGE_VERSION}
1 1.9.${PACKAGE_VERSION}
all_providers.c
cmd.c
cmd_ah.c
Expand Down
7 changes: 7 additions & 0 deletions libibverbs/device.c
Expand Up @@ -150,6 +150,13 @@ LATEST_SYMVER_FUNC(ibv_get_device_guid, 1_1, "IBVERBS_1.1",
return htobe64(guid);
}

int ibv_get_device_index(struct ibv_device *device)
{
struct verbs_sysfs_dev *sysfs_dev = verbs_get_device(device)->sysfs;

return sysfs_dev->ibdev_idx;
}

int ibv_get_fw_ver(char *value, size_t len, struct verbs_sysfs_dev *sysfs_dev)
{
/*
Expand Down
5 changes: 5 additions & 0 deletions libibverbs/libibverbs.map.in
Expand Up @@ -126,6 +126,11 @@ IBVERBS_1.8 {
ibv_reg_mr_iova2;
} IBVERBS_1.7;

IBVERBS_1.9 {
global:
ibv_get_device_index;
} IBVERBS_1.8;

/* If any symbols in this stanza change ABI then the entire staza gets a new symbol
version. See the top level CMakeLists.txt for this setting. */

Expand Down
1 change: 1 addition & 0 deletions libibverbs/man/CMakeLists.txt
Expand Up @@ -32,6 +32,7 @@ rdma_man_pages(
ibv_get_async_event.3
ibv_get_cq_event.3
ibv_get_device_guid.3.md
ibv_get_device_index.3.md
ibv_get_device_list.3.md
ibv_get_device_name.3.md
ibv_get_pkey_index.3.md
Expand Down
2 changes: 1 addition & 1 deletion libibverbs/man/ibv_get_device_guid.3.md
Expand Up @@ -31,7 +31,7 @@ RDMA device *device*.
order.
# SEE ALSO
**ibv_get_device_index**(3),
**ibv_get_device_list**(3),
**ibv_get_device_name**(3),
**ibv_open_device**(3)
Expand Down
40 changes: 40 additions & 0 deletions libibverbs/man/ibv_get_device_index.3.md
@@ -0,0 +1,40 @@
---
date: ' 2020-04-22'
footer: libibverbs
header: "Libibverbs Programmer's Manual"
layout: page
license: 'Licensed under the OpenIB.org BSD license (FreeBSD Variant) - See COPYING.md'
section: 3
title: IBV_GET_DEVICE_INDEX
---

# NAME

ibv_get_device_index - get an RDMA device index

# SYNOPSIS

```c
#include <infiniband/verbs.h>

int ibv_get_device_index(struct ibv_device *device);
```
# DESCRIPTION
**ibv_get_device_index()** returns stable IB device index as it is assigned by the kernel.
# RETURN VALUE
**ibv_get_device_index()** returns an index, or -1 if the kernel doesn't support device indexes.
# SEE ALSO
**ibv_get_device_name**(3),
**ibv_get_device_guid**(3),
**ibv_get_device_list**(3),
**ibv_open_device**(3)
# AUTHOR
Leon Romanovsky <leonro@mellanox.com>
1 change: 1 addition & 0 deletions libibverbs/man/ibv_get_device_list.3.md
Expand Up @@ -88,6 +88,7 @@ recommended.
**ibv_fork_init**(3),
**ibv_get_device_guid**(3),
**ibv_get_device_name**(3),
**ibv_get_device_index**(3),
**ibv_open_device**(3)
# AUTHOR
Expand Down
9 changes: 9 additions & 0 deletions libibverbs/verbs.h
Expand Up @@ -2202,6 +2202,15 @@ void ibv_free_device_list(struct ibv_device **list);
*/
const char *ibv_get_device_name(struct ibv_device *device);

/**
* ibv_get_device_index - Return kernel device index
*
* Available for the kernel with support of IB device query
* over netlink interface. For the unsupported kernels, the
* relevant -1 will be returned.
*/
int ibv_get_device_index(struct ibv_device *device);

/**
* ibv_get_device_guid - Return device's node GUID
*/
Expand Down

0 comments on commit 307f922

Please sign in to comment.