Commit dd86fec7 authored by Jakub Kicinski's avatar Jakub Kicinski Committed by David S. Miller

devlink: factor out building a snapshot notification

We'll need to send snapshot info back on the socket
which requested a snapshot to be created. Factor out
constructing a snapshot description from the broadcast
notification code.

v3: new patch
Signed-off-by: default avatarJakub Kicinski <kuba@kernel.org>
Reviewed-by: default avatarJiri Pirko <jiri@mellanox.com>
Reviewed-by: default avatarJacob Keller <jacob.e.keller@intel.com>
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parent 39d01050
...@@ -3716,24 +3716,26 @@ static int devlink_nl_region_fill(struct sk_buff *msg, struct devlink *devlink, ...@@ -3716,24 +3716,26 @@ static int devlink_nl_region_fill(struct sk_buff *msg, struct devlink *devlink,
return err; return err;
} }
static void devlink_nl_region_notify(struct devlink_region *region, static struct sk_buff *
struct devlink_snapshot *snapshot, devlink_nl_region_notify_build(struct devlink_region *region,
enum devlink_command cmd) struct devlink_snapshot *snapshot,
enum devlink_command cmd, u32 portid, u32 seq)
{ {
struct devlink *devlink = region->devlink; struct devlink *devlink = region->devlink;
struct sk_buff *msg; struct sk_buff *msg;
void *hdr; void *hdr;
int err; int err;
WARN_ON(cmd != DEVLINK_CMD_REGION_NEW && cmd != DEVLINK_CMD_REGION_DEL);
msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
if (!msg) if (!msg)
return; return ERR_PTR(-ENOMEM);
hdr = genlmsg_put(msg, 0, 0, &devlink_nl_family, 0, cmd); hdr = genlmsg_put(msg, portid, seq, &devlink_nl_family, 0, cmd);
if (!hdr) if (!hdr) {
err = -EMSGSIZE;
goto out_free_msg; goto out_free_msg;
}
err = devlink_nl_put_handle(msg, devlink); err = devlink_nl_put_handle(msg, devlink);
if (err) if (err)
...@@ -3757,15 +3759,30 @@ static void devlink_nl_region_notify(struct devlink_region *region, ...@@ -3757,15 +3759,30 @@ static void devlink_nl_region_notify(struct devlink_region *region,
} }
genlmsg_end(msg, hdr); genlmsg_end(msg, hdr);
genlmsg_multicast_netns(&devlink_nl_family, devlink_net(devlink), return msg;
msg, 0, DEVLINK_MCGRP_CONFIG, GFP_KERNEL);
return;
out_cancel_msg: out_cancel_msg:
genlmsg_cancel(msg, hdr); genlmsg_cancel(msg, hdr);
out_free_msg: out_free_msg:
nlmsg_free(msg); nlmsg_free(msg);
return ERR_PTR(err);
}
static void devlink_nl_region_notify(struct devlink_region *region,
struct devlink_snapshot *snapshot,
enum devlink_command cmd)
{
struct devlink *devlink = region->devlink;
struct sk_buff *msg;
WARN_ON(cmd != DEVLINK_CMD_REGION_NEW && cmd != DEVLINK_CMD_REGION_DEL);
msg = devlink_nl_region_notify_build(region, snapshot, cmd, 0, 0);
if (IS_ERR(msg))
return;
genlmsg_multicast_netns(&devlink_nl_family, devlink_net(devlink),
msg, 0, DEVLINK_MCGRP_CONFIG, GFP_KERNEL);
} }
/** /**
......
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