All of lore.kernel.org
 help / color / mirror / Atom feed
From: Denis Drozdov <denisd-VPRAkNaXOzVWk0Htik3J/w@public.gmane.org>
To: davem-fT/PcQaiUtIeIZ0/mPfg9Q@public.gmane.org
Cc: jgg-VPRAkNaXOzVWk0Htik3J/w@public.gmane.org,
	dledford-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org,
	leonro-VPRAkNaXOzVWk0Htik3J/w@public.gmane.org,
	linux-rdma-u79uwXL29TY76Z2rM5mHXA@public.gmane.org,
	netdev-u79uwXL29TY76Z2rM5mHXA@public.gmane.org,
	gerlitz.or-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org,
	Denis Drozdov <denisd-VPRAkNaXOzVWk0Htik3J/w@public.gmane.org>
Subject: [PATCH v2 net 1/2] rtnl: device allocation/free via rtnl_link_ops
Date: Tue,  9 Jan 2018 23:42:46 +0200	[thread overview]
Message-ID: <1515534167-13062-2-git-send-email-denisd@mellanox.com> (raw)
In-Reply-To: <1515534167-13062-1-git-send-email-denisd-VPRAkNaXOzVWk0Htik3J/w@public.gmane.org>

Introduced new rtnl_link_ops callbacks: alloc_link()
to allocate multi-queue netdev and free_link() to release
the netdevice. free_link() appoints to free_netdev by
default and could be reassigned.

These calls should be used by IB ULP code to allocate and
release both enhanced and non-enhanced IB drivers and aren't
necessary by the regular drivers.

Fixes: cd565b4b51e5 ("IB/IPoIB: Support acceleration options callbacks")
Signed-off-by: Denis Drozdov <denisd-VPRAkNaXOzVWk0Htik3J/w@public.gmane.org>
Reviewed-by: Erez Shitrit <erezsh-VPRAkNaXOzVWk0Htik3J/w@public.gmane.org>
Reviewed-by: Saeed Mahameed <saeedm-VPRAkNaXOzVWk0Htik3J/w@public.gmane.org>
---
 include/net/rtnetlink.h |  4 ++++
 net/core/dev.c          |  2 ++
 net/core/rtnetlink.c    | 29 ++++++++++++++++++++++-------
 3 files changed, 28 insertions(+), 7 deletions(-)

diff --git a/include/net/rtnetlink.h b/include/net/rtnetlink.h
index ead01874..f02975e 100644
--- a/include/net/rtnetlink.h
+++ b/include/net/rtnetlink.h
@@ -70,6 +70,10 @@ struct rtnl_link_ops {
 					    struct nlattr *data[],
 					    struct netlink_ext_ack *extack);
 
+	struct net_device      *(*alloc_link)(struct net *src_net,
+					      const char *dev_name,
+					      struct nlattr *tb[]);
+	void			(*free_link)(struct net_device *dev);
 	int			(*newlink)(struct net *src_net,
 					   struct net_device *dev,
 					   struct nlattr *tb[],
diff --git a/net/core/dev.c b/net/core/dev.c
index 0e0ba36..850bcbd 100644
--- a/net/core/dev.c
+++ b/net/core/dev.c
@@ -7967,6 +7967,8 @@ void netdev_run_todo(void)
 
 		if (dev->priv_destructor)
 			dev->priv_destructor(dev);
+		if (dev->rtnl_link_ops && dev->rtnl_link_ops->free_link)
+			dev->rtnl_link_ops->free_link(dev);
 		if (dev->needs_free_netdev)
 			free_netdev(dev);
 
diff --git a/net/core/rtnetlink.c b/net/core/rtnetlink.c
index 778d7f0..a87557b 100644
--- a/net/core/rtnetlink.c
+++ b/net/core/rtnetlink.c
@@ -2556,10 +2556,18 @@ struct net_device *rtnl_create_link(struct net *net,
 	else if (ops->get_num_rx_queues)
 		num_rx_queues = ops->get_num_rx_queues();
 
-	dev = alloc_netdev_mqs(ops->priv_size, ifname, name_assign_type,
-			       ops->setup, num_tx_queues, num_rx_queues);
-	if (!dev)
-		return ERR_PTR(-ENOMEM);
+	if (ops->alloc_link) {
+		dev = ops->alloc_link(net, ifname, tb);
+
+		if (IS_ERR(dev))
+			return dev;
+	} else {
+		dev = alloc_netdev_mqs(ops->priv_size, ifname,
+				       name_assign_type, ops->setup,
+				       num_tx_queues, num_rx_queues);
+		if (!dev)
+			return ERR_PTR(-ENOMEM);
+	}
 
 	dev_net_set(dev, net);
 	dev->rtnl_link_ops = ops;
@@ -2820,14 +2828,21 @@ static int rtnl_newlink(struct sk_buff *skb, struct nlmsghdr *nlh,
 			 */
 			if (err < 0) {
 				/* If device is not registered at all, free it now */
-				if (dev->reg_state == NETREG_UNINITIALIZED)
-					free_netdev(dev);
+				if (dev->reg_state == NETREG_UNINITIALIZED) {
+					if (ops->free_link)
+						ops->free_link(dev);
+					else
+						free_netdev(dev);
+				}
 				goto out;
 			}
 		} else {
 			err = register_netdevice(dev);
 			if (err < 0) {
-				free_netdev(dev);
+				if (ops->free_link)
+					ops->free_link(dev);
+				else
+					free_netdev(dev);
 				goto out;
 			}
 		}
-- 
1.8.3.1

--
To unsubscribe from this list: send the line "unsubscribe linux-rdma" in
the body of a message to majordomo-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

  parent reply	other threads:[~2018-01-09 21:42 UTC|newest]

Thread overview: 18+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-12-31 11:16 [PATCH net 0/2] IB/ipoib: ip link support Denis Drozdov
     [not found] ` <1514718983-466-1-git-send-email-denisd-VPRAkNaXOzVWk0Htik3J/w@public.gmane.org>
2017-12-31 11:16   ` [PATCH net 1/2] rtnl: device allocation/free via rtnl_link_ops Denis Drozdov
     [not found]     ` <1514718983-466-2-git-send-email-denisd-VPRAkNaXOzVWk0Htik3J/w@public.gmane.org>
2018-01-01 22:43       ` [rtnl] b1585bdfb2: kernel_BUG_at_net/core/dev.c kernel test robot
2018-01-01 22:43         ` kernel test robot
2018-01-01 22:43         ` kernel test robot
2018-01-09 21:42         ` [PATCH v2 net 0/2] IB/ipoib: ip link support Denis Drozdov
     [not found]           ` <1515534167-13062-1-git-send-email-denisd-VPRAkNaXOzVWk0Htik3J/w@public.gmane.org>
2018-01-09 21:42             ` Denis Drozdov [this message]
2018-01-09 21:42           ` [PATCH v2 net 2/2] IB/ipoib: Fix netlink support in IPoIB Denis Drozdov
2018-01-15 18:13           ` [PATCH v2 net 0/2] IB/ipoib: ip link support David Miller
     [not found]             ` <20180115.131309.1163036253579166139.davem-fT/PcQaiUtIeIZ0/mPfg9Q@public.gmane.org>
2018-01-18  4:25               ` Jason Gunthorpe
2018-05-07 17:29                 ` Or Gerlitz
2017-12-31 12:28   ` [PATCH " Or Gerlitz
     [not found]     ` <CAJ3xEMiVHc=E7=uKJ4cRRRDxjNDRKQ17=NxnYsEeXNe6-RUvvQ-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2018-01-02  7:29       ` Or Gerlitz
2018-01-02  8:44         ` Erez Shitrit
2018-01-02  9:15           ` Or Gerlitz
2017-12-31 11:16 ` [PATCH net 2/2] IB/ipoib: Fix netlink support in IPoIB Denis Drozdov
     [not found]   ` <1514718983-466-3-git-send-email-denisd-VPRAkNaXOzVWk0Htik3J/w@public.gmane.org>
2017-12-31 20:23     ` Jason Gunthorpe
     [not found]       ` <20171231202308.GA10145-uk2M96/98Pc@public.gmane.org>
2018-01-01  6:38         ` Leon Romanovsky

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=1515534167-13062-2-git-send-email-denisd@mellanox.com \
    --to=denisd-vpraknaxozvwk0htik3j/w@public.gmane.org \
    --cc=davem-fT/PcQaiUtIeIZ0/mPfg9Q@public.gmane.org \
    --cc=dledford-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org \
    --cc=gerlitz.or-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org \
    --cc=jgg-VPRAkNaXOzVWk0Htik3J/w@public.gmane.org \
    --cc=leonro-VPRAkNaXOzVWk0Htik3J/w@public.gmane.org \
    --cc=linux-rdma-u79uwXL29TY76Z2rM5mHXA@public.gmane.org \
    --cc=netdev-u79uwXL29TY76Z2rM5mHXA@public.gmane.org \
    /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.