Skip to content

Commit

Permalink
devlink: extract snapshot id allocation to helper function
Browse files Browse the repository at this point in the history
A future change is going to implement a new devlink command to request
a snapshot on demand. As part of this, the logic for handling the
snapshot ids will be refactored. To simplify the snapshot id allocation
function, move it to a separate function prefixed by `__`. This helper
function will assume the lock is held.

While no other callers will exist, it simplifies refactoring the logic
because there is no need to complicate the function with gotos to handle
unlocking on failure.

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>
  • Loading branch information
Jacob Keller authored and David S. Miller committed Mar 27, 2020
1 parent 47a39f6 commit 7000108
Showing 1 changed file with 14 additions and 1 deletion.
15 changes: 14 additions & 1 deletion net/core/devlink.c
Original file line number Diff line number Diff line change
Expand Up @@ -3768,6 +3768,19 @@ static void devlink_nl_region_notify(struct devlink_region *region,
nlmsg_free(msg);
}

/**
* __devlink_region_snapshot_id_get - get snapshot ID
* @devlink: devlink instance
*
* Returns a new snapshot id. Must be called while holding the
* devlink instance lock.
*/
static u32 __devlink_region_snapshot_id_get(struct devlink *devlink)
{
lockdep_assert_held(&devlink->lock);
return ++devlink->snapshot_id;
}

/**
* __devlink_region_snapshot_create - create a new snapshot
* This will add a new snapshot of a region. The snapshot
Expand Down Expand Up @@ -7776,7 +7789,7 @@ u32 devlink_region_snapshot_id_get(struct devlink *devlink)
u32 id;

mutex_lock(&devlink->lock);
id = ++devlink->snapshot_id;
id = __devlink_region_snapshot_id_get(devlink);
mutex_unlock(&devlink->lock);

return id;
Expand Down

0 comments on commit 7000108

Please sign in to comment.