3030#include <rdma/rdma_netlink.h>
3131#endif
3232
33+ #define UCT_IB_DEVICE_LOOPBACK_NDEV_INDEX_INVALID 0
34+
3335
3436/* This table is according to "Encoding for RNR NAK Timer Field"
3537 * in IBTA specification */
@@ -109,7 +111,7 @@ uct_ib_device_to_ndev_cache_hash_equal(uct_ib_device_to_ndev_key_t key1,
109111 (key1 .guid == key2 .guid );
110112}
111113
112- KHASH_INIT (uct_ib_device_to_ndev , uct_ib_device_to_ndev_key_t , int , 1 ,
114+ KHASH_INIT (uct_ib_device_to_ndev , uct_ib_device_to_ndev_key_t , unsigned , 1 ,
113115 uct_ib_device_to_ndev_cache_hash_func ,
114116 uct_ib_device_to_ndev_cache_hash_equal );
115117
@@ -1510,9 +1512,25 @@ uct_ib_device_get_roce_ndev_name(uct_ib_device_t *dev, uint8_t port_num,
15101512 return UCS_OK ;
15111513}
15121514
1515+ ucs_status_t uct_ib_iface_get_loopback_ndev_index (unsigned * ndev_index_p )
1516+ {
1517+ static unsigned loopback_ndev_index = UCT_IB_DEVICE_LOOPBACK_NDEV_INDEX_INVALID ;
1518+ ucs_status_t status ;
1519+
1520+ if (loopback_ndev_index == UCT_IB_DEVICE_LOOPBACK_NDEV_INDEX_INVALID ) {
1521+ status = ucs_ifname_to_index ("lo" , & loopback_ndev_index );
1522+ if (status != UCS_OK ) {
1523+ return status ;
1524+ }
1525+ }
1526+
1527+ * ndev_index_p = loopback_ndev_index ;
1528+ return UCS_OK ;
1529+ }
1530+
15131531ucs_status_t
15141532uct_ib_device_get_roce_ndev_index (uct_ib_device_t * dev , uint8_t port_num ,
1515- uint8_t gid_index , int * ndev_index_p )
1533+ uint8_t gid_index , unsigned * ndev_index_p )
15161534{
15171535 uct_ib_device_to_ndev_key_t ib_dev = {.guid = IBV_DEV_ATTR (dev , node_guid ),
15181536 .port_num = port_num ,
@@ -1521,9 +1539,9 @@ uct_ib_device_get_roce_ndev_index(uct_ib_device_t *dev, uint8_t port_num,
15211539 PTHREAD_MUTEX_INITIALIZER ;
15221540 ucs_status_t status ;
15231541 char ndev_name [IFNAMSIZ ];
1524- int ndev_index ;
1542+ unsigned ndev_index ;
15251543 khiter_t iter ;
1526- int khret ;
1544+ unsigned khret ;
15271545
15281546 pthread_mutex_lock (& uct_ib_device_to_ndev_cache_lock );
15291547 iter = kh_put (uct_ib_device_to_ndev , & ib_dev_to_ndev_map , ib_dev , & khret );
@@ -1539,11 +1557,8 @@ uct_ib_device_get_roce_ndev_index(uct_ib_device_t *dev, uint8_t port_num,
15391557 goto out_unlock ;
15401558 }
15411559
1542- ndev_index = if_nametoindex (ndev_name );
1543- if (ndev_index == 0 ) {
1544- ucs_error ("failed to get interface index for %s (errno %d)" ,
1545- ndev_name , errno );
1546- status = UCS_ERR_IO_ERROR ;
1560+ status = ucs_ifname_to_index (ndev_name , & ndev_index );
1561+ if (status != UCS_OK ) {
15471562 goto out_unlock ;
15481563 }
15491564
0 commit comments