Commit 8273fd84 authored by Jiri Pirko's avatar Jiri Pirko Committed by David S. Miller

net: devlink: export devlink net setter

For newly allocated devlink instance allow drivers to set net struct
Signed-off-by: default avatarJiri Pirko <jiri@mellanox.com>
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parent 128d23c3
...@@ -39,6 +39,7 @@ struct devlink { ...@@ -39,6 +39,7 @@ struct devlink {
possible_net_t _net; possible_net_t _net;
struct mutex lock; struct mutex lock;
bool reload_failed; bool reload_failed;
bool registered;
char priv[0] __aligned(NETDEV_ALIGN); char priv[0] __aligned(NETDEV_ALIGN);
}; };
...@@ -772,6 +773,7 @@ static inline struct devlink *netdev_to_devlink(struct net_device *dev) ...@@ -772,6 +773,7 @@ static inline struct devlink *netdev_to_devlink(struct net_device *dev)
struct ib_device; struct ib_device;
struct net *devlink_net(const struct devlink *devlink); 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); struct devlink *devlink_alloc(const struct devlink_ops *ops, size_t priv_size);
int devlink_register(struct devlink *devlink, struct device *dev); int devlink_register(struct devlink *devlink, struct device *dev);
void devlink_unregister(struct devlink *devlink); void devlink_unregister(struct devlink *devlink);
......
...@@ -101,11 +101,19 @@ struct net *devlink_net(const struct devlink *devlink) ...@@ -101,11 +101,19 @@ struct net *devlink_net(const struct devlink *devlink)
} }
EXPORT_SYMBOL_GPL(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); 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, static struct devlink *devlink_get_from_attrs(struct net *net,
struct nlattr **attrs) struct nlattr **attrs)
{ {
...@@ -2750,7 +2758,7 @@ static void devlink_reload_netns_change(struct devlink *devlink, ...@@ -2750,7 +2758,7 @@ static void devlink_reload_netns_change(struct devlink *devlink,
DEVLINK_CMD_PARAM_DEL); DEVLINK_CMD_PARAM_DEL);
devlink_notify(devlink, DEVLINK_CMD_DEL); devlink_notify(devlink, DEVLINK_CMD_DEL);
devlink_net_set(devlink, dest_net); __devlink_net_set(devlink, dest_net);
devlink_notify(devlink, DEVLINK_CMD_NEW); devlink_notify(devlink, DEVLINK_CMD_NEW);
list_for_each_entry(param_item, &devlink->param_list, list) list_for_each_entry(param_item, &devlink->param_list, list)
...@@ -6278,7 +6286,7 @@ struct devlink *devlink_alloc(const struct devlink_ops *ops, size_t priv_size) ...@@ -6278,7 +6286,7 @@ struct devlink *devlink_alloc(const struct devlink_ops *ops, size_t priv_size)
if (!devlink) if (!devlink)
return NULL; return NULL;
devlink->ops = ops; 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->port_list);
INIT_LIST_HEAD(&devlink->sb_list); INIT_LIST_HEAD(&devlink->sb_list);
INIT_LIST_HEAD_RCU(&devlink->dpipe_table_list); INIT_LIST_HEAD_RCU(&devlink->dpipe_table_list);
...@@ -6304,6 +6312,7 @@ int devlink_register(struct devlink *devlink, struct device *dev) ...@@ -6304,6 +6312,7 @@ int devlink_register(struct devlink *devlink, struct device *dev)
{ {
mutex_lock(&devlink_mutex); mutex_lock(&devlink_mutex);
devlink->dev = dev; devlink->dev = dev;
devlink->registered = true;
list_add_tail(&devlink->list, &devlink_list); list_add_tail(&devlink->list, &devlink_list);
devlink_notify(devlink, DEVLINK_CMD_NEW); devlink_notify(devlink, DEVLINK_CMD_NEW);
mutex_unlock(&devlink_mutex); mutex_unlock(&devlink_mutex);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment