netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Jacob Keller <jacob.e.keller@intel.com>
To: netdev@vger.kernel.org
Cc: valex@mellanox.com, jiri@resnulli.us,
	Jacob Keller <jacob.e.keller@intel.com>
Subject: [PATCH v2 2/3] devlink: introduce command to trigger region snapshot
Date: Thu,  9 Jan 2020 11:33:10 -0800	[thread overview]
Message-ID: <20200109193311.1352330-4-jacob.e.keller@intel.com> (raw)
In-Reply-To: <20200109193311.1352330-1-jacob.e.keller@intel.com>

Devlink regions exist as a mechanism for drivers to export addressable
regions of data to userspace. An astute reviewer might notice that the
devlink-health interface is similar and could be used for such
a purpose. However, the health API is intended for reporting and
recovering from error conditions.

If a driver wants to export a set of data that is not an error
condition, it does not make much sense to use the health APIs. For
example, a driver might expose some portion of the flash memory contents
of the device as a region that could then be dumped. In this case, the
only time it makes sense to capture the region is upon request.

The health API makes more sense for cases where the driver detects error
conditions and triggers dumping and recovery mechanisms automatically.

Add a new command, DEVLINK_CMD_REGION_TRIGGER, which enables userspace
to request a snapshot of a region. A future commit will modify the
netdevsim driver as an example of how this is implemented.

Signed-off-by: Jacob Keller <jacob.e.keller@intel.com>
---
 include/uapi/linux/devlink.h |  2 ++
 net/core/devlink.c           | 34 ++++++++++++++++++++++++++++++++++
 2 files changed, 36 insertions(+)

diff --git a/include/uapi/linux/devlink.h b/include/uapi/linux/devlink.h
index ae37fd4d194a..a5f54953e7b2 100644
--- a/include/uapi/linux/devlink.h
+++ b/include/uapi/linux/devlink.h
@@ -117,6 +117,8 @@ enum devlink_command {
 	DEVLINK_CMD_TRAP_GROUP_NEW,
 	DEVLINK_CMD_TRAP_GROUP_DEL,
 
+	DEVLINK_CMD_REGION_TRIGGER,
+
 	/* add new commands above here */
 	__DEVLINK_CMD_MAX,
 	DEVLINK_CMD_MAX = __DEVLINK_CMD_MAX - 1
diff --git a/net/core/devlink.c b/net/core/devlink.c
index e54600afdaf0..3b5151a9b7db 100644
--- a/net/core/devlink.c
+++ b/net/core/devlink.c
@@ -4053,6 +4053,32 @@ static int devlink_nl_cmd_region_read_dumpit(struct sk_buff *skb,
 	return err;
 }
 
+static int devlink_nl_cmd_region_trigger_snapshot(struct sk_buff *skb,
+						  struct genl_info *info)
+{
+	struct devlink *devlink = info->user_ptr[0];
+	struct devlink_region *region;
+	const char *region_name;
+	struct sk_buff *msg;
+	u32 snapshot_id;
+	int err;
+
+	if (!info->attrs[DEVLINK_ATTR_REGION_NAME])
+		return -EINVAL;
+
+	region_name = nla_data(info->attrs[DEVLINK_ATTR_REGION_NAME]);
+	region = devlink_region_get_by_name(devlink, region_name);
+	if (!region)
+		return -EINVAL;
+
+	if (!region->trigger_snapshot) {
+		NL_SET_ERR_MSG_MOD(info->extack, "Triggering snapshots for the requested region is not supported");
+		return -EOPNOTSUPP;
+	}
+
+	return region->trigger_snapshot(devlink, region, info->extack);
+}
+
 struct devlink_info_req {
 	struct sk_buff *msg;
 };
@@ -6159,6 +6185,14 @@ static const struct genl_ops devlink_nl_ops[] = {
 		.flags = GENL_ADMIN_PERM,
 		.internal_flags = DEVLINK_NL_FLAG_NEED_DEVLINK,
 	},
+	{
+		.cmd = DEVLINK_CMD_REGION_TRIGGER,
+		.validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
+		.doit = devlink_nl_cmd_region_trigger_snapshot,
+		.flags = GENL_ADMIN_PERM,
+		.internal_flags = DEVLINK_NL_FLAG_NEED_DEVLINK |
+				  DEVLINK_NL_FLAG_NO_LOCK,
+	},
 	{
 		.cmd = DEVLINK_CMD_INFO_GET,
 		.validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
-- 
2.25.0.rc1


  parent reply	other threads:[~2020-01-09 19:33 UTC|newest]

Thread overview: 25+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-01-09 19:33 [PATCH v2 0/3] devlink region trigger support Jacob Keller
2020-01-09 19:33 ` [PATCH v2 1/3] devlink: add callback to trigger region snapshots Jacob Keller
2020-01-09 19:33 ` [PATCH v2 1/1] devlink: add support for DEVLINK_CMD_REGION_TRIGGER Jacob Keller
2020-01-09 19:33 ` Jacob Keller [this message]
2020-01-09 19:33 ` [PATCH v2 3/3] netdevsim: support triggering snapshot through devlink Jacob Keller
2020-01-09 20:13 ` [PATCH v2 0/3] devlink region trigger support Jacob Keller
2020-01-10  4:10 ` Yunsheng Lin
2020-01-10 17:52   ` Jacob Keller
2020-01-11  1:51     ` Yunsheng Lin
2020-01-12 20:45       ` Jakub Kicinski
2020-01-12 21:18         ` Alex Vesker
2020-01-13  1:39           ` Yunsheng Lin
2020-01-13 11:34             ` Jakub Kicinski
2020-01-13 18:16               ` Jacob Keller
2020-01-13 18:33                 ` Jiri Pirko
2020-01-13 16:58       ` Jiri Pirko
2020-01-13 18:22         ` Jacob Keller
2020-01-13 18:33           ` Jiri Pirko
2020-01-14  8:33           ` Yunsheng Lin
2020-01-14 20:04             ` Jacob Keller
2020-01-15  8:36               ` Yunsheng Lin
2020-01-10  9:40 ` Jiri Pirko
2020-01-10 17:54   ` Jacob Keller
2020-01-10 18:47     ` Jakub Kicinski
2020-01-10 18:57       ` Jacob Keller

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=20200109193311.1352330-4-jacob.e.keller@intel.com \
    --to=jacob.e.keller@intel.com \
    --cc=jiri@resnulli.us \
    --cc=netdev@vger.kernel.org \
    --cc=valex@mellanox.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).