Skip to content

Commit af48f95

Browse files
MarkZhang81rleon
authored andcommitted
RDMA/core: Introduce "name_assign_type" for an IB device
The name_assign_type indicates how the name is provided. Currently these types are supported: - RDMA_NAME_ASSIGN_TYPE_UNKNOWN: Unknown or not set; - RDMA_NAME_ASSIGN_TYPE_USER: Name is provided by the user; The user-created sub device, rxe and siw device has this type. When filling nl device info, it is set in the new attribute RDMA_NLDEV_ATTR_NAME_ASSIGN_TYPE. User-space tools like udev "rdma_rename" could check this attribute to determine if this device needs to be renamed or not. Signed-off-by: Mark Zhang <[email protected]> Link: https://lore.kernel.org/r/522591bef9a369cc8e5dcb77787e017bffee37fe.1719837610.git.leon@kernel.org Signed-off-by: Leon Romanovsky <[email protected]>
1 parent f802078 commit af48f95

File tree

6 files changed

+27
-2
lines changed

6 files changed

+27
-2
lines changed

drivers/infiniband/core/nldev.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -169,6 +169,7 @@ static const struct nla_policy nldev_policy[RDMA_NLDEV_ATTR_MAX] = {
169169
[RDMA_NLDEV_ATTR_DRIVER_DETAILS] = { .type = NLA_U8 },
170170
[RDMA_NLDEV_ATTR_DEV_TYPE] = { .type = NLA_U8 },
171171
[RDMA_NLDEV_ATTR_PARENT_NAME] = { .type = NLA_NUL_STRING },
172+
[RDMA_NLDEV_ATTR_NAME_ASSIGN_TYPE] = { .type = NLA_U8 },
172173
};
173174

174175
static int put_driver_name_print_type(struct sk_buff *msg, const char *name,
@@ -312,6 +313,10 @@ static int fill_dev_info(struct sk_buff *msg, struct ib_device *device)
312313
dev_name(&device->parent->dev)))
313314
return -EMSGSIZE;
314315

316+
if (nla_put_u8(msg, RDMA_NLDEV_ATTR_NAME_ASSIGN_TYPE,
317+
device->name_assign_type))
318+
return -EMSGSIZE;
319+
315320
/*
316321
* Link type is determined on first port and mlx4 device
317322
* which can potentially have two different link type for the same

drivers/infiniband/hw/mlx5/main.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4198,9 +4198,10 @@ static int mlx5_ib_stage_ib_reg_init(struct mlx5_ib_dev *dev)
41984198
{
41994199
const char *name;
42004200

4201-
if (dev->sub_dev_name)
4201+
if (dev->sub_dev_name) {
42024202
name = dev->sub_dev_name;
4203-
else if (!mlx5_lag_is_active(dev->mdev))
4203+
ib_mark_name_assigned_by_user(&dev->ib_dev);
4204+
} else if (!mlx5_lag_is_active(dev->mdev))
42044205
name = "mlx5_%d";
42054206
else
42064207
name = "mlx5_bond_%d";

drivers/infiniband/sw/rxe/rxe_net.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -537,6 +537,7 @@ int rxe_net_add(const char *ibdev_name, struct net_device *ndev)
537537
return -ENOMEM;
538538

539539
rxe->ndev = ndev;
540+
ib_mark_name_assigned_by_user(&rxe->ib_dev);
540541

541542
err = rxe_add(rxe, ndev->mtu, ibdev_name);
542543
if (err) {

drivers/infiniband/sw/siw/siw_main.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -485,6 +485,7 @@ static int siw_newlink(const char *basedev_name, struct net_device *netdev)
485485
else
486486
sdev->state = IB_PORT_DOWN;
487487

488+
ib_mark_name_assigned_by_user(&sdev->base_dev);
488489
rv = siw_device_register(sdev, basedev_name);
489490
if (rv)
490491
ib_dealloc_device(&sdev->base_dev);

include/rdma/ib_verbs.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2794,6 +2794,8 @@ struct ib_device {
27942794
enum rdma_nl_dev_type type;
27952795
struct ib_device *parent;
27962796
struct list_head subdev_list;
2797+
2798+
enum rdma_nl_name_assign_type name_assign_type;
27972799
};
27982800

27992801
static inline void *rdma_zalloc_obj(struct ib_device *dev, size_t size,
@@ -4867,4 +4869,10 @@ int ib_add_sub_device(struct ib_device *parent,
48674869
* Return 0 on success, an error code otherwise
48684870
*/
48694871
int ib_del_sub_device_and_put(struct ib_device *sub);
4872+
4873+
static inline void ib_mark_name_assigned_by_user(struct ib_device *ibdev)
4874+
{
4875+
ibdev->name_assign_type = RDMA_NAME_ASSIGN_TYPE_USER;
4876+
}
4877+
48704878
#endif /* IB_VERBS_H */

include/uapi/rdma/rdma_netlink.h

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -572,6 +572,8 @@ enum rdma_nldev_attr {
572572

573573
RDMA_NLDEV_ATTR_PARENT_NAME, /* string */
574574

575+
RDMA_NLDEV_ATTR_NAME_ASSIGN_TYPE, /* u8 */
576+
575577
/*
576578
* Always the end
577579
*/
@@ -615,4 +617,11 @@ enum rdma_nl_counter_mask {
615617
enum rdma_nl_dev_type {
616618
RDMA_DEVICE_TYPE_SMI = 1,
617619
};
620+
621+
/* RDMA device name assignment types */
622+
enum rdma_nl_name_assign_type {
623+
RDMA_NAME_ASSIGN_TYPE_UNKNOWN = 0,
624+
RDMA_NAME_ASSIGN_TYPE_USER = 1, /* Provided by user-space */
625+
};
626+
618627
#endif /* _UAPI_RDMA_NETLINK_H */

0 commit comments

Comments
 (0)