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 3/3] netdevsim: support triggering snapshot through devlink
Date: Thu,  9 Jan 2020 11:33:11 -0800	[thread overview]
Message-ID: <20200109193311.1352330-5-jacob.e.keller@intel.com> (raw)
In-Reply-To: <20200109193311.1352330-1-jacob.e.keller@intel.com>

Implement the trigger_snapshot callback for the dummy devlink region.
This enables the region snapshot to be requested directly through the
devlink API instead of using debugfs as an out-of-band mechanism for
triggering the snapshot.

Signed-off-by: Jacob Keller <jacob.e.keller@intel.com>
---
 drivers/net/netdevsim/dev.c | 36 ++++++++++++++++++++++++++----------
 1 file changed, 26 insertions(+), 10 deletions(-)

diff --git a/drivers/net/netdevsim/dev.c b/drivers/net/netdevsim/dev.c
index 2af97eeb7ba1..4ed9c8d8de7c 100644
--- a/drivers/net/netdevsim/dev.c
+++ b/drivers/net/netdevsim/dev.c
@@ -38,30 +38,46 @@ static struct dentry *nsim_dev_ddir;
 
 #define NSIM_DEV_DUMMY_REGION_SIZE (1024 * 32)
 
-static ssize_t nsim_dev_take_snapshot_write(struct file *file,
-					    const char __user *data,
-					    size_t count, loff_t *ppos)
+static int nsim_dev_trigger_snapshot(struct devlink *devlink,
+				     struct devlink_region *region,
+				     struct netlink_ext_ack *extack)
 {
-	struct nsim_dev *nsim_dev = file->private_data;
 	void *dummy_data;
 	int err;
 	u32 id;
 
 	dummy_data = kmalloc(NSIM_DEV_DUMMY_REGION_SIZE, GFP_KERNEL);
-	if (!dummy_data)
+	if (!dummy_data) {
+		NL_SET_ERR_MSG(extack, "Out of memory");
 		return -ENOMEM;
+	}
 
 	get_random_bytes(dummy_data, NSIM_DEV_DUMMY_REGION_SIZE);
 
-	id = devlink_region_snapshot_id_get(priv_to_devlink(nsim_dev));
-	err = devlink_region_snapshot_create(nsim_dev->dummy_region,
-					     dummy_data, id, kfree);
+	id = devlink_region_snapshot_id_get(devlink);
+	err = devlink_region_snapshot_create(region, dummy_data, id, kfree);
 	if (err) {
-		pr_err("Failed to create region snapshot\n");
+		NL_SET_ERR_MSG(extack, "Failed to create region snapshot");
 		kfree(dummy_data);
 		return err;
 	}
 
+	return (0);
+
+}
+
+static ssize_t nsim_dev_take_snapshot_write(struct file *file,
+					    const char __user *data,
+					    size_t count, loff_t *ppos)
+{
+	struct nsim_dev *nsim_dev = file->private_data;
+	int err;
+
+	err = nsim_dev_trigger_snapshot(priv_to_devlink(nsim_dev),
+					nsim_dev->dummy_region, NULL);
+	if (err)
+		return err;
+
 	return count;
 }
 
@@ -249,7 +265,7 @@ static int nsim_dev_dummy_region_init(struct nsim_dev *nsim_dev,
 		devlink_region_create(devlink, "dummy",
 				      NSIM_DEV_DUMMY_REGION_SNAPSHOT_MAX,
 				      NSIM_DEV_DUMMY_REGION_SIZE,
-				      NULL);
+				      nsim_dev_trigger_snapshot);
 	return PTR_ERR_OR_ZERO(nsim_dev->dummy_region);
 }
 
-- 
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 ` [PATCH v2 2/3] devlink: introduce command to trigger region snapshot Jacob Keller
2020-01-09 19:33 ` Jacob Keller [this message]
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-5-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).