Skip to content

Commit

Permalink
Merge branch 'netdevsim-allow-to-test-reload-failures'
Browse files Browse the repository at this point in the history
Jiri Pirko says:

====================
netdevsim: allow to test reload failures

Allow user to test devlink reload failures: Fail to reload and fail
during reload.
====================

Signed-off-by: David S. Miller <davem@davemloft.net>
  • Loading branch information
David S. Miller committed Oct 6, 2019
2 parents d44dc74 + 9278bc9 commit 0eb8516
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 0 deletions.
20 changes: 20 additions & 0 deletions drivers/net/netdevsim/dev.c
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,10 @@ static int nsim_dev_debugfs_init(struct nsim_dev *nsim_dev)
&nsim_dev->test1);
debugfs_create_file("take_snapshot", 0200, nsim_dev->ddir, nsim_dev,
&nsim_dev_take_snapshot_fops);
debugfs_create_bool("dont_allow_reload", 0600, nsim_dev->ddir,
&nsim_dev->dont_allow_reload);
debugfs_create_bool("fail_reload", 0600, nsim_dev->ddir,
&nsim_dev->fail_reload);
return 0;
}

Expand Down Expand Up @@ -478,6 +482,14 @@ static int nsim_dev_reload_down(struct devlink *devlink, bool netns_change,
{
struct nsim_dev *nsim_dev = devlink_priv(devlink);

if (nsim_dev->dont_allow_reload) {
/* For testing purposes, user set debugfs dont_allow_reload
* value to true. So forbid it.
*/
NL_SET_ERR_MSG_MOD(extack, "User forbidded reload for testing purposes");
return -EOPNOTSUPP;
}

nsim_dev_reload_destroy(nsim_dev);
return 0;
}
Expand All @@ -487,6 +499,14 @@ static int nsim_dev_reload_up(struct devlink *devlink,
{
struct nsim_dev *nsim_dev = devlink_priv(devlink);

if (nsim_dev->fail_reload) {
/* For testing purposes, user set debugfs fail_reload
* value to true. Fail right away.
*/
NL_SET_ERR_MSG_MOD(extack, "User setup the reload to fail for testing purposes");
return -EINVAL;
}

return nsim_dev_reload_create(nsim_dev, extack);
}

Expand Down
2 changes: 2 additions & 0 deletions drivers/net/netdevsim/netdevsim.h
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,8 @@ struct nsim_dev {
bool fw_update_status;
u32 max_macs;
bool test1;
bool dont_allow_reload;
bool fail_reload;
struct devlink_region *dummy_region;
};

Expand Down
24 changes: 24 additions & 0 deletions tools/testing/selftests/drivers/net/netdevsim/devlink.sh
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,30 @@ reload_test()
devlink dev reload $DL_HANDLE
check_err $? "Failed to reload"

echo "y"> $DEBUGFS_DIR/fail_reload
check_err $? "Failed to setup devlink reload to fail"

devlink dev reload $DL_HANDLE
check_fail $? "Unexpected success of devlink reload"

echo "n"> $DEBUGFS_DIR/fail_reload
check_err $? "Failed to setup devlink reload not to fail"

devlink dev reload $DL_HANDLE
check_err $? "Failed to reload after set not to fail"

echo "y"> $DEBUGFS_DIR/dont_allow_reload
check_err $? "Failed to forbid devlink reload"

devlink dev reload $DL_HANDLE
check_fail $? "Unexpected success of devlink reload"

echo "n"> $DEBUGFS_DIR/dont_allow_reload
check_err $? "Failed to re-enable devlink reload"

devlink dev reload $DL_HANDLE
check_err $? "Failed to reload after re-enable"

log_test "reload test"
}

Expand Down

0 comments on commit 0eb8516

Please sign in to comment.