mirror of
https://github.com/torvalds/linux.git
synced 2024-11-29 07:31:29 +00:00
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@intel.com> Reviewed-by: Jiri Pirko <jiri@mellanox.com> Signed-off-by: David S. Miller <davem@davemloft.net>
This commit is contained in:
parent
b9a17abfde
commit
3fe0fd531a
@ -39,17 +39,11 @@ 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_take_snapshot(struct devlink *devlink, struct netlink_ext_ack *extack,
|
||||
u8 **data)
|
||||
{
|
||||
struct nsim_dev *nsim_dev = file->private_data;
|
||||
struct devlink *devlink;
|
||||
void *dummy_data;
|
||||
int err;
|
||||
u32 id;
|
||||
|
||||
devlink = priv_to_devlink(nsim_dev);
|
||||
|
||||
dummy_data = kmalloc(NSIM_DEV_DUMMY_REGION_SIZE, GFP_KERNEL);
|
||||
if (!dummy_data)
|
||||
@ -57,6 +51,27 @@ static ssize_t nsim_dev_take_snapshot_write(struct file *file,
|
||||
|
||||
get_random_bytes(dummy_data, NSIM_DEV_DUMMY_REGION_SIZE);
|
||||
|
||||
*data = dummy_data;
|
||||
|
||||
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;
|
||||
struct devlink *devlink;
|
||||
u8 *dummy_data;
|
||||
int err;
|
||||
u32 id;
|
||||
|
||||
devlink = priv_to_devlink(nsim_dev);
|
||||
|
||||
err = nsim_dev_take_snapshot(devlink, NULL, &dummy_data);
|
||||
if (err)
|
||||
return err;
|
||||
|
||||
err = devlink_region_snapshot_id_get(devlink, &id);
|
||||
if (err) {
|
||||
pr_err("Failed to get snapshot id\n");
|
||||
@ -351,6 +366,7 @@ static void nsim_devlink_param_load_driverinit_values(struct devlink *devlink)
|
||||
static const struct devlink_region_ops dummy_region_ops = {
|
||||
.name = "dummy",
|
||||
.destructor = &kfree,
|
||||
.snapshot = nsim_dev_take_snapshot,
|
||||
};
|
||||
|
||||
static int nsim_dev_dummy_region_init(struct nsim_dev *nsim_dev,
|
||||
|
@ -141,6 +141,16 @@ regions_test()
|
||||
|
||||
check_region_snapshot_count dummy post-first-delete 2
|
||||
|
||||
devlink region new $DL_HANDLE/dummy snapshot 25
|
||||
check_err $? "Failed to create a new snapshot with id 25"
|
||||
|
||||
check_region_snapshot_count dummy post-first-request 3
|
||||
|
||||
devlink region del $DL_HANDLE/dummy snapshot 25
|
||||
check_err $? "Failed to delete snapshot with id 25"
|
||||
|
||||
check_region_snapshot_count dummy post-second-delete 2
|
||||
|
||||
log_test "regions test"
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user