From 3fb00075d904389afce507fffe06ca3a8500ebf3 Mon Sep 17 00:00:00 2001 From: Leon Romanovsky Date: Wed, 31 Oct 2018 09:17:55 +0200 Subject: [PATCH 1/3] rdma: Update kernel include file to support IB device renaming Bring kernel header file changes upto commit 05d940d3a3ec ("RDMA/nldev: Allow IB device rename through RDMA netlink") Signed-off-by: Leon Romanovsky Reviewed-by: Steve Wise Signed-off-by: David Ahern --- rdma/include/uapi/rdma/rdma_netlink.h | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/rdma/include/uapi/rdma/rdma_netlink.h b/rdma/include/uapi/rdma/rdma_netlink.h index 6513fb89..e2228c09 100644 --- a/rdma/include/uapi/rdma/rdma_netlink.h +++ b/rdma/include/uapi/rdma/rdma_netlink.h @@ -227,8 +227,9 @@ enum rdma_nldev_command { RDMA_NLDEV_CMD_UNSPEC, RDMA_NLDEV_CMD_GET, /* can dump */ + RDMA_NLDEV_CMD_SET, - /* 2 - 4 are free to use */ + /* 3 - 4 are free to use */ RDMA_NLDEV_CMD_PORT_GET = 5, /* can dump */ From a14ceed32524c7f9c05572886cd63e921e4c0faf Mon Sep 17 00:00:00 2001 From: Leon Romanovsky Date: Wed, 31 Oct 2018 09:17:56 +0200 Subject: [PATCH 2/3] rdma: Introduce command execution helper with required device name In contradiction to various show commands, the set command explicitly requires to use device name as an argument. Provide new command execution helper which enforces it. Signed-off-by: Leon Romanovsky Reviewed-by: Steve Wise Signed-off-by: David Ahern --- rdma/rdma.h | 1 + rdma/utils.c | 10 ++++++++++ 2 files changed, 11 insertions(+) diff --git a/rdma/rdma.h b/rdma/rdma.h index c3b7530b..547bb574 100644 --- a/rdma/rdma.h +++ b/rdma/rdma.h @@ -90,6 +90,7 @@ int cmd_link(struct rd *rd); int cmd_res(struct rd *rd); int rd_exec_cmd(struct rd *rd, const struct rd_cmd *c, const char *str); int rd_exec_dev(struct rd *rd, int (*cb)(struct rd *rd)); +int rd_exec_require_dev(struct rd *rd, int (*cb)(struct rd *rd)); int rd_exec_link(struct rd *rd, int (*cb)(struct rd *rd), bool strict_port); void rd_free(struct rd *rd); int rd_set_arg_to_devname(struct rd *rd); diff --git a/rdma/utils.c b/rdma/utils.c index 4840bf22..61f4aeb1 100644 --- a/rdma/utils.c +++ b/rdma/utils.c @@ -577,6 +577,16 @@ out: return ret; } +int rd_exec_require_dev(struct rd *rd, int (*cb)(struct rd *rd)) +{ + if (rd_no_arg(rd)) { + pr_err("Please provide device name.\n"); + return -EINVAL; + } + + return rd_exec_dev(rd, cb); +} + int rd_exec_cmd(struct rd *rd, const struct rd_cmd *cmds, const char *str) { const struct rd_cmd *c; From 4443c9c6a01eac8c8f2743d4d185ceb9be4d1207 Mon Sep 17 00:00:00 2001 From: Leon Romanovsky Date: Wed, 31 Oct 2018 09:17:57 +0200 Subject: [PATCH 3/3] rdma: Add an option to rename IB device interface Enrich rdmatool with an option to rename IB devices, the command interface follows Iproute2 convention: "rdma dev set [OLD-DEVNAME] name NEW-DEVNAME" Signed-off-by: Leon Romanovsky Reviewed-by: Steve Wise Signed-off-by: David Ahern --- rdma/dev.c | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) diff --git a/rdma/dev.c b/rdma/dev.c index e2eafe47..760b7fb3 100644 --- a/rdma/dev.c +++ b/rdma/dev.c @@ -14,6 +14,7 @@ static int dev_help(struct rd *rd) { pr_out("Usage: %s dev show [DEV]\n", rd->filename); + pr_out(" %s dev set [DEV] name DEVNAME\n", rd->filename); return 0; } @@ -240,17 +241,51 @@ static int dev_one_show(struct rd *rd) return rd_exec_cmd(rd, cmds, "parameter"); } +static int dev_set_name(struct rd *rd) +{ + uint32_t seq; + + if (rd_no_arg(rd)) { + pr_err("Please provide device new name.\n"); + return -EINVAL; + } + + rd_prepare_msg(rd, RDMA_NLDEV_CMD_SET, + &seq, (NLM_F_REQUEST | NLM_F_ACK)); + mnl_attr_put_u32(rd->nlh, RDMA_NLDEV_ATTR_DEV_INDEX, rd->dev_idx); + mnl_attr_put_strz(rd->nlh, RDMA_NLDEV_ATTR_DEV_NAME, rd_argv(rd)); + + return rd_send_msg(rd); +} + +static int dev_one_set(struct rd *rd) +{ + const struct rd_cmd cmds[] = { + { NULL, dev_help}, + { "name", dev_set_name}, + { 0 } + }; + + return rd_exec_cmd(rd, cmds, "parameter"); +} + static int dev_show(struct rd *rd) { return rd_exec_dev(rd, dev_one_show); } +static int dev_set(struct rd *rd) +{ + return rd_exec_require_dev(rd, dev_one_set); +} + int cmd_dev(struct rd *rd) { const struct rd_cmd cmds[] = { { NULL, dev_show }, { "show", dev_show }, { "list", dev_show }, + { "set", dev_set }, { "help", dev_help }, { 0 } };