[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-Id: <20200130225913.1671982-5-jacob.e.keller@intel.com>
Date: Thu, 30 Jan 2020 14:58:59 -0800
From: Jacob Keller <jacob.e.keller@...el.com>
To: netdev@...r.kernel.org
Cc: jiri@...nulli.us, valex@...lanox.com, linyunsheng@...wei.com,
lihong.yang@...el.com, Jacob Keller <jacob.e.keller@...el.com>
Subject: [PATCH 04/15] netdevsim: support taking immediate snapshot via devlink
Implement the .snapshot region operation for the dummy data region. This
enables a region snapshot to be taken upon request via the new
DEVLINK_CMD_REGION_SNAPSHOT command.
Signed-off-by: Jacob Keller <jacob.e.keller@...el.com>
---
drivers/net/netdevsim/dev.c | 38 +++++++++++++++----
.../drivers/net/netdevsim/devlink.sh | 5 +++
2 files changed, 36 insertions(+), 7 deletions(-)
diff --git a/drivers/net/netdevsim/dev.c b/drivers/net/netdevsim/dev.c
index d521b7bfe007..924cd328037f 100644
--- a/drivers/net/netdevsim/dev.c
+++ b/drivers/net/netdevsim/dev.c
@@ -38,24 +38,47 @@ static struct dentry *nsim_dev_ddir;
#define NSIM_DEV_DUMMY_REGION_SIZE (1024 * 32)
+static int nsim_dev_take_snapshot(struct devlink *devlink,
+ struct netlink_ext_ack *extack,
+ u8 **data,
+ devlink_snapshot_data_dest_t **destructor)
+{
+ void *dummy_data;
+
+ dummy_data = kmalloc(NSIM_DEV_DUMMY_REGION_SIZE, GFP_KERNEL);
+ if (!dummy_data) {
+ NL_SET_ERR_MSG(extack, "Out of memory");
+ return -ENOMEM;
+ }
+
+ get_random_bytes(dummy_data, NSIM_DEV_DUMMY_REGION_SIZE);
+
+ *data = dummy_data;
+ *destructor = kfree;
+
+ 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;
- void *dummy_data;
+ devlink_snapshot_data_dest_t *destructor;
+ u8 *dummy_data;
int err;
u32 id;
- dummy_data = kmalloc(NSIM_DEV_DUMMY_REGION_SIZE, GFP_KERNEL);
- if (!dummy_data)
- return -ENOMEM;
-
- get_random_bytes(dummy_data, NSIM_DEV_DUMMY_REGION_SIZE);
+ err = nsim_dev_take_snapshot(priv_to_devlink(nsim_dev), NULL,
+ &dummy_data, &destructor);
+ if (err) {
+ pr_err("Failed to capture region snapshot\n");
+ return err;
+ }
id = devlink_region_snapshot_id_get(priv_to_devlink(nsim_dev));
err = devlink_region_snapshot_create(nsim_dev->dummy_region,
- dummy_data, id, kfree);
+ dummy_data, id, destructor);
if (err) {
pr_err("Failed to create region snapshot\n");
kfree(dummy_data);
@@ -244,6 +267,7 @@ static void nsim_devlink_param_load_driverinit_values(struct devlink *devlink)
static const struct devlink_region_ops dummy_region_ops = {
.name = "dummy",
+ .snapshot = nsim_dev_take_snapshot,
};
static int nsim_dev_dummy_region_init(struct nsim_dev *nsim_dev,
diff --git a/tools/testing/selftests/drivers/net/netdevsim/devlink.sh b/tools/testing/selftests/drivers/net/netdevsim/devlink.sh
index 025a84c2ab5a..e7827a092478 100755
--- a/tools/testing/selftests/drivers/net/netdevsim/devlink.sh
+++ b/tools/testing/selftests/drivers/net/netdevsim/devlink.sh
@@ -141,6 +141,11 @@ regions_test()
check_region_snapshot_count dummy post-first-delete 2
+ devlink region snapshot $DL_HANDLE/dummy
+ check_err $? "Failed to request a snapshot"
+
+ check_region_snapshot_count dummy post-request 3
+
log_test "regions test"
}
--
2.25.0.rc1
Powered by blists - more mailing lists