From: Jiri Pirko <jiri@resnulli.us>
To: netdev@vger.kernel.org
Cc: davem@davemloft.net, jakub.kicinski@netronome.com,
sthemmin@microsoft.com, dsahern@gmail.com, mlxsw@mellanox.com
Subject: [patch net-next v2 2/3] net: devlink: export devlink net set/get helpers
Date: Tue, 30 Jul 2019 10:57:33 +0200 [thread overview]
Message-ID: <20190730085734.31504-3-jiri@resnulli.us> (raw)
In-Reply-To: <20190730085734.31504-1-jiri@resnulli.us>
From: Jiri Pirko <jiri@mellanox.com>
Allow drivers to set/get net struct for devlink instance. Set is only
allowed for newly allocated devlink instance.
Signed-off-by: Jiri Pirko <jiri@mellanox.com>
---
include/net/devlink.h | 3 +++
net/core/devlink.c | 18 ++++++++++++++----
2 files changed, 17 insertions(+), 4 deletions(-)
diff --git a/include/net/devlink.h b/include/net/devlink.h
index bc36f942a7d5..98b89eabd73a 100644
--- a/include/net/devlink.h
+++ b/include/net/devlink.h
@@ -35,6 +35,7 @@ struct devlink {
struct device *dev;
possible_net_t _net;
struct mutex lock;
+ bool registered;
char priv[0] __aligned(NETDEV_ALIGN);
};
@@ -591,6 +592,8 @@ static inline struct devlink *netdev_to_devlink(struct net_device *dev)
struct ib_device;
+struct net *devlink_net(const struct devlink *devlink);
+void devlink_net_set(struct devlink *devlink, struct net *net);
struct devlink *devlink_alloc(const struct devlink_ops *ops, size_t priv_size);
int devlink_register(struct devlink *devlink, struct device *dev);
void devlink_unregister(struct devlink *devlink);
diff --git a/net/core/devlink.c b/net/core/devlink.c
index e1cbfd90f788..fc364bdb9cf2 100644
--- a/net/core/devlink.c
+++ b/net/core/devlink.c
@@ -92,16 +92,25 @@ static LIST_HEAD(devlink_list);
*/
static DEFINE_MUTEX(devlink_mutex);
-static struct net *devlink_net(const struct devlink *devlink)
+struct net *devlink_net(const struct devlink *devlink)
{
return read_pnet(&devlink->_net);
}
+EXPORT_SYMBOL_GPL(devlink_net);
-static void devlink_net_set(struct devlink *devlink, struct net *net)
+static void __devlink_net_set(struct devlink *devlink, struct net *net)
{
write_pnet(&devlink->_net, net);
}
+void devlink_net_set(struct devlink *devlink, struct net *net)
+{
+ if (WARN_ON(devlink->registered))
+ return;
+ __devlink_net_set(devlink, net);
+}
+EXPORT_SYMBOL_GPL(devlink_net_set);
+
static struct devlink *devlink_get_from_attrs(struct net *net,
struct nlattr **attrs)
{
@@ -696,7 +705,7 @@ static void devlink_netns_change(struct devlink *devlink, struct net *net)
if (net_eq(devlink_net(devlink), net))
return;
devlink_notify(devlink, DEVLINK_CMD_DEL);
- devlink_net_set(devlink, net);
+ __devlink_net_set(devlink, net);
devlink_notify(devlink, DEVLINK_CMD_NEW);
}
@@ -5603,7 +5612,7 @@ struct devlink *devlink_alloc(const struct devlink_ops *ops, size_t priv_size)
if (!devlink)
return NULL;
devlink->ops = ops;
- devlink_net_set(devlink, &init_net);
+ __devlink_net_set(devlink, &init_net);
INIT_LIST_HEAD(&devlink->port_list);
INIT_LIST_HEAD(&devlink->sb_list);
INIT_LIST_HEAD_RCU(&devlink->dpipe_table_list);
@@ -5627,6 +5636,7 @@ int devlink_register(struct devlink *devlink, struct device *dev)
{
mutex_lock(&devlink_mutex);
devlink->dev = dev;
+ devlink->registered = true;
list_add_tail(&devlink->list, &devlink_list);
devlink_notify(devlink, DEVLINK_CMD_NEW);
mutex_unlock(&devlink_mutex);
--
2.21.0
next prev parent reply other threads:[~2019-07-30 8:57 UTC|newest]
Thread overview: 28+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-07-30 8:57 [patch net-next v2 0/3] net: devlink: Finish network namespace support Jiri Pirko
2019-07-30 8:57 ` [patch net-next v2 1/3] net: devlink: allow to change namespaces Jiri Pirko
2019-07-30 22:39 ` Jakub Kicinski
2019-07-31 19:26 ` Jiri Pirko
2019-07-31 19:41 ` David Ahern
2019-07-31 19:45 ` Jiri Pirko
2019-07-31 19:46 ` David Ahern
2019-07-31 19:58 ` David Ahern
2019-07-31 20:20 ` David Ahern
2019-08-02 7:48 ` Jiri Pirko
2019-08-02 15:45 ` David Ahern
2019-08-05 5:54 ` Jiri Pirko
2019-08-05 14:10 ` David Ahern
2019-08-05 14:49 ` Jiri Pirko
2019-08-05 14:51 ` David Ahern
2019-08-05 15:20 ` Jiri Pirko
2019-08-06 17:34 ` David Ahern
2019-08-06 17:53 ` Jiri Pirko
2019-08-06 17:55 ` David Ahern
2019-08-06 18:07 ` Jiri Pirko
2019-08-02 7:43 ` Jiri Pirko
2019-07-30 8:57 ` Jiri Pirko [this message]
2019-07-30 22:40 ` [patch net-next v2 2/3] net: devlink: export devlink net set/get helpers Jakub Kicinski
2019-07-30 8:57 ` [patch net-next v2 3/3] netdevsim: create devlink and netdev instances in namespace Jiri Pirko
2019-07-30 22:40 ` Jakub Kicinski
2019-07-30 8:59 ` [patch iproute2-next v2 1/2] devlink: introduce cmdline option to switch to a different namespace Jiri Pirko
2019-07-30 8:59 ` [patch iproute2-next v2 2/2] devlink: add support for network namespace change Jiri Pirko
2019-07-31 22:59 ` [patch net-next v2 0/3] net: devlink: Finish network namespace support David Miller
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=20190730085734.31504-3-jiri@resnulli.us \
--to=jiri@resnulli.us \
--cc=davem@davemloft.net \
--cc=dsahern@gmail.com \
--cc=jakub.kicinski@netronome.com \
--cc=mlxsw@mellanox.com \
--cc=netdev@vger.kernel.org \
--cc=sthemmin@microsoft.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.