All of lore.kernel.org
 help / color / mirror / Atom feed
From: Leon Romanovsky <leon@kernel.org>
To: Doug Ledford <dledford@redhat.com>, Jason Gunthorpe <jgg@mellanox.com>
Cc: Leon Romanovsky <leonro@mellanox.com>,
	RDMA mailing list <linux-rdma@vger.kernel.org>,
	linux-s390@vger.kernel.org, Ursula Braun <ubraun@linux.ibm.com>,
	"David S. Miller" <davem@davemloft.net>,
	netdev@vger.kernel.org,
	Selvin Xavier <selvin.xavier@broadcom.com>,
	Steve Wise <swise@chelsio.com>, Lijun Ou <oulijun@huawei.com>,
	Shiraz Saleem <shiraz.saleem@intel.com>,
	Ariel Elior <Ariel.Elior@cavium.com>,
	Christian Benvenuti <benve@cisco.com>,
	Adit Ranadive <aditr@vmware.com>,
	Dennis Dalessandro <dennis.dalessandro@intel.com>
Subject: [PATCH rdma-next 5/5] RDMA/nldev: Allow IB device rename through RDMA netlink
Date: Thu, 20 Sep 2018 14:22:02 +0300	[thread overview]
Message-ID: <20180920112202.9181-6-leon@kernel.org> (raw)
In-Reply-To: <20180920112202.9181-1-leon@kernel.org>

From: Leon Romanovsky <leonro@mellanox.com>

Provide an option to rename IB device name through RDMA netlink and
limit it to users with ADMIN capability only.

Signed-off-by: Leon Romanovsky <leonro@mellanox.com>
---
 drivers/infiniband/core/nldev.c  | 33 +++++++++++++++++++++++++++++++++
 include/uapi/rdma/rdma_netlink.h |  3 ++-
 2 files changed, 35 insertions(+), 1 deletion(-)

diff --git a/drivers/infiniband/core/nldev.c b/drivers/infiniband/core/nldev.c
index 0385ab438320..64e1d12e9678 100644
--- a/drivers/infiniband/core/nldev.c
+++ b/drivers/infiniband/core/nldev.c
@@ -645,6 +645,35 @@ static int nldev_get_doit(struct sk_buff *skb, struct nlmsghdr *nlh,
 	return err;
 }

+static int nldev_set_doit(struct sk_buff *skb, struct nlmsghdr *nlh,
+			  struct netlink_ext_ack *extack)
+{
+	struct nlattr *tb[RDMA_NLDEV_ATTR_MAX];
+	struct ib_device *device;
+	u32 index;
+	int err;
+
+	err = nlmsg_parse(nlh, 0, tb, RDMA_NLDEV_ATTR_MAX - 1, nldev_policy,
+			  extack);
+	if (err || !tb[RDMA_NLDEV_ATTR_DEV_INDEX])
+		return -EINVAL;
+
+	index = nla_get_u32(tb[RDMA_NLDEV_ATTR_DEV_INDEX]);
+	device = ib_device_get_by_index(index);
+	if (!device)
+		return -EINVAL;
+
+	if (tb[RDMA_NLDEV_ATTR_DEV_NAME]) {
+		char name[IB_DEVICE_NAME_MAX] = {};
+
+		nla_strlcpy(name, tb[RDMA_NLDEV_ATTR_DEV_NAME],
+			    IB_DEVICE_NAME_MAX);
+		return ib_device_rename(device, name);
+	}
+
+	return 0;
+}
+
 static int _nldev_get_dumpit(struct ib_device *device,
 			     struct sk_buff *skb,
 			     struct netlink_callback *cb,
@@ -1077,6 +1106,10 @@ static const struct rdma_nl_cbs nldev_cb_table[RDMA_NLDEV_NUM_OPS] = {
 		.doit = nldev_get_doit,
 		.dump = nldev_get_dumpit,
 	},
+	[RDMA_NLDEV_CMD_SET] = {
+		.doit = nldev_set_doit,
+		.flags = RDMA_NL_ADMIN_PERM,
+	},
 	[RDMA_NLDEV_CMD_PORT_GET] = {
 		.doit = nldev_port_get_doit,
 		.dump = nldev_port_get_dumpit,
diff --git a/include/uapi/rdma/rdma_netlink.h b/include/uapi/rdma/rdma_netlink.h
index edba6351ac13..f9c41bf59efc 100644
--- a/include/uapi/rdma/rdma_netlink.h
+++ b/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 */

      parent reply	other threads:[~2018-09-20 11:22 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-09-20 11:21 [PATCH rdma-next 0/5] IB device rename support Leon Romanovsky
2018-09-20 11:21 ` [PATCH rdma-next 1/5] RDMA/core: Provide getter and setter to access IB device name Leon Romanovsky
2018-09-20 14:32   ` Steve Wise
2018-09-20 15:15   ` Jason Gunthorpe
2018-09-20 16:40     ` Leon Romanovsky
2018-09-20 16:46       ` Jason Gunthorpe
2018-09-20 11:21 ` [PATCH rdma-next 2/5] net/smc: Use IB device index instead of name Leon Romanovsky
2018-09-20 11:22 ` [PATCH rdma-next 3/5] RDMA: Convert IB drivers to name allocation routine Leon Romanovsky
2018-09-20 11:22 ` [PATCH rdma-next 4/5] RDMA/core: Implement IB device rename function Leon Romanovsky
2018-09-20 11:22 ` Leon Romanovsky [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20180920112202.9181-6-leon@kernel.org \
    --to=leon@kernel.org \
    --cc=Ariel.Elior@cavium.com \
    --cc=aditr@vmware.com \
    --cc=benve@cisco.com \
    --cc=davem@davemloft.net \
    --cc=dennis.dalessandro@intel.com \
    --cc=dledford@redhat.com \
    --cc=jgg@mellanox.com \
    --cc=leonro@mellanox.com \
    --cc=linux-rdma@vger.kernel.org \
    --cc=linux-s390@vger.kernel.org \
    --cc=netdev@vger.kernel.org \
    --cc=oulijun@huawei.com \
    --cc=selvin.xavier@broadcom.com \
    --cc=shiraz.saleem@intel.com \
    --cc=swise@chelsio.com \
    --cc=ubraun@linux.ibm.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.