devlink: kernel region snapshot id allocation
Subsystems (6)
Jakub Kicinski
maintainerv4 cover devlink: kernel region snapshot id allocation
Hi!
currently users have to find a free snapshot id to pass to the kernel when they are requesting a snapshot to be taken.
This set extends the kernel so it can allocate the id on its own and send it back to user space in a response.
Jakub Kicinski (3):
devlink: factor out building a snapshot notification
devlink: let kernel allocate region snapshot id
docs: devlink: clarify the scope of snapshot id
.../networking/devlink/devlink-region.rst | 11 ++- net/core/devlink.c | 96 ++++++++++++++----- .../drivers/net/netdevsim/devlink.sh | 13 +++ 3 files changed, 94 insertions(+), 26 deletions(-)
Signature · 1 line
2.25.4
Jakub Kicinski
maintainerPATCH v4 1/3 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
--- net/core/devlink.c | 39 ++++++++++++++++++++++++++++----------- 1 file changed, 28 insertions(+), 11 deletions(-)
net/core/devlink.c +28 -11
@@ -3716,24 +3716,26 @@ static int devlink_nl_region_fill(struct sk_buff *msg, struct devlink *devlink,return err; } -static void devlink_nl_region_notify (struct devlink_region *region, -struct devlink_snapshot *snapshot, -enum devlink_command cmd) +static struct sk_buff * +devlink_nl_region_notify_build (struct devlink_region *region, +struct devlink_snapshot *snapshot, +enum devlink_command cmd,u32 portid,u32 seq) {struct devlink *devlink = region->devlink;struct sk_buff *msg;void *hdr;int err; -WARN_ON (cmd !=DEVLINK_CMD_REGION_NEW && cmd !=DEVLINK_CMD_REGION_DEL ); msg =nlmsg_new (NLMSG_DEFAULT_SIZE ,GFP_KERNEL );if (!msg) -return ; +return ERR_PTR (-ENOMEM ); - hdr =genlmsg_put (msg,0 ,0 , &devlink_nl_family,0 , cmd); -if (!hdr) + hdr =genlmsg_put (msg, portid, seq, &devlink_nl_family,0 , cmd); +if (!hdr) { + err = -EMSGSIZE ; goto out_free_msg; + } err =devlink_nl_put_handle (msg, devlink);if (err)
@@ -3757,15 +3759,30 @@ static void devlink_nl_region_notify(struct devlink_region *region, }genlmsg_end (msg, hdr); -genlmsg_multicast_netns (&devlink_nl_family,devlink_net (devlink), - msg,0 ,DEVLINK_MCGRP_CONFIG ,GFP_KERNEL ); - -return ; +return msg; out_cancel_msg:genlmsg_cancel (msg, hdr); out_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 ); }/**
Signature · 1 line
2.25.4
Re: [PATCH net-next v4 1/3] devlink: factor out building a snapshot notification
Quoted 9 lines · Jakub Kicinski
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 Jakub Kicinski <[email protected]>Reviewed-by Jiri Pirko <[email protected]>
Jakub Kicinski
maintainerPATCH v4 2/3 devlink: let kernel allocate region snapshot id
In reply to Jakub KicinskiCurrently users have to choose a free snapshot id before calling DEVLINK_CMD_REGION_NEW. This is potentially racy and inconvenient.
Make the DEVLINK_ATTR_REGION_SNAPSHOT_ID optional and try to allocate id automatically. Send a message back to the caller with the snapshot info.
Example use:
$ devlink region new netdevsim/netdevsim1/dummy netdevsim/netdevsim1/dummy: snapshot 1
$ id=$(devlink -j region new netdevsim/netdevsim1/dummy | \
jq '.[][][][]')
$ devlink region dump netdevsim/netdevsim1/dummy snapshot $id
[...]
$ devlink region del netdevsim/netdevsim1/dummy snapshot $idv4:
- inline the notification code
v3:
- send the notification only once snapshot creation completed.
v2:
- don't wrap the line containing extack;
- add a few sentences to the docs.
--- .../networking/devlink/devlink-region.rst | 7 ++- net/core/devlink.c | 57 ++++++++++++++----- .../drivers/net/netdevsim/devlink.sh | 13 +++++ 3 files changed, 62 insertions(+), 15 deletions(-)
Documentation/networking/devlink/devlink-region.rst +5 -2
@@ -23,7 +23,9 @@ states, but see also :doc:`devlink-health` Regions may optionally support capturing a snapshot on demand via the ``DEVLINK_CMD_REGION_NEW`` netlink message. A driver wishing to allow requested snapshots must implement the ``.snapshot`` callback for the region -in its ``devlink_region_ops`` structure. +in its ``devlink_region_ops`` structure. If snapshot id is not set in +the ``DEVLINK_CMD_REGION_NEW`` request kernel will allocate one and send +the snapshot information to user space. example usage -------------
@@ -45,7 +47,8 @@ example usage $ devlink region del pci/0000:00:05.0/cr-space snapshot 1 # Request an immediate snapshot, if supported by the region - $ devlink region new pci/0000:00:05.0/cr-space snapshot 5 + $ devlink region new pci/0000:00:05.0/cr-space + pci/0000:00:05.0/cr-space: snapshot 5 # Dump a snapshot: $ devlink region dump pci/0000:00:05.0/fw-health snapshot 1
net/core/devlink.c +44 -13
89 lines not on this page · raw message
tools/testing/selftests/drivers/net/netdevsim/devlink.sh +13 -0
@@ -166,6 +166,19 @@ regions_test() check_region_snapshot_count dummy post-second-delete 2 + sid=$(devlink -j region new $DL_HANDLE/dummy | jq '.[][][][]') + check_err $? "Failed to create a new snapshot with id allocated by the kernel" + + check_region_snapshot_count dummy post-first-request 3 + + devlink region dump $DL_HANDLE/dummy snapshot $sid >> /dev/null + check_err $? "Failed to dump a snapshot with id allocated by the kernel" + + devlink region del $DL_HANDLE/dummy snapshot $sid + check_err $? "Failed to delete snapshot with id allocated by the kernel" + + check_region_snapshot_count dummy post-first-request 2 + log_test "regions test" }
Signature · 1 line
2.25.4
Re: [PATCH net-next v4 2/3] devlink: let kernel allocate region snapshot id
Quoted 26 lines · Jakub Kicinski
Currently users have to choose a free snapshot id before calling
DEVLINK_CMD_REGION_NEW. This is potentially racy and inconvenient.Make the
DEVLINK_ATTR_REGION_SNAPSHOT_IDoptional and try to allocate id automatically. Send a message back to the caller with the snapshot info.Example use:
$ devlink region new netdevsim/netdevsim1/dummy netdevsim/netdevsim1/dummy: snapshot 1$ id=$(devlink -j region new netdevsim/netdevsim1/dummy | \ jq '.[][][][]') $ devlink region dump netdevsim/netdevsim1/dummy snapshot $id [...] $ devlink region del netdevsim/netdevsim1/dummy snapshot $idv4:
- inline the notification code
v3:
- send the notification only once snapshot creation completed.
v2:
- don't wrap the line containing extack;
- add a few sentences to the docs.
Quoted 1 line
Signed-off-by Jakub Kicinski <[email protected]>
Jakub Kicinski
maintainerPATCH v4 3/3 docs: devlink: clarify the scope of snapshot id
In reply to Jakub KicinskiIn past discussions Jiri explained snapshot ids are cross-region. Explain this in the docs.
v3: new patch
--- Documentation/networking/devlink/devlink-region.rst | 4 ++++ 1 file changed, 4 insertions(+)
Documentation/networking/devlink/devlink-region.rst +4 -0
@@ -14,6 +14,10 @@ Region snapshots are collected by the driver, and can be accessed via read or dump commands. This allows future analysis on the created snapshots. Regions may optionally support triggering snapshots on demand. +Snapshot identifiers are scoped to the devlink instance, not a region. +All snapshots with the same snapshot id within a devlink instance +correspond to the same event. + The major benefit to creating a region is to provide access to internal address regions that are otherwise inaccessible to the user.
Signature · 1 line
2.25.4
David Miller
maintainerFrom: Jakub Kicinski <[email protected]>
Date: Fri, 1 May 2020 09:40:39 -0700
Quoted 6 lines
currently users have to find a free snapshot id to pass to the kernel when they are requesting a snapshot to be taken.
This set extends the kernel so it can allocate the id on its own and send it back to user space in a response.
Series applied, thanks Jakub.