Skip to content

Commit

Permalink
drop_monitor: Rename and document scope of mutex
Browse files Browse the repository at this point in the history
The 'trace_state_mutex' does not only protect the global 'trace_state'
variable, but also the global 'hw_stats_list'.

Subsequent patches are going add more operations from user space to
drop_monitor and these all need to be mutually exclusive.

Rename 'trace_state_mutex' to the more fitting 'net_dm_mutex' name and
document its scope.

Signed-off-by: Ido Schimmel <idosch@mellanox.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
  • Loading branch information
Ido Schimmel authored and David S. Miller committed Aug 6, 2019
1 parent 2230a7e commit dbf896b
Showing 1 changed file with 13 additions and 7 deletions.
20 changes: 13 additions & 7 deletions net/core/drop_monitor.c
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,13 @@
* netlink alerts
*/
static int trace_state = TRACE_OFF;
static DEFINE_MUTEX(trace_state_mutex);

/* net_dm_mutex
*
* An overall lock guarding every operation coming from userspace.
* It also guards the global 'hw_stats_list' list.
*/
static DEFINE_MUTEX(net_dm_mutex);

struct per_cpu_dm_data {
spinlock_t lock;
Expand Down Expand Up @@ -241,7 +247,7 @@ static int set_all_monitor_traces(int state)
struct dm_hw_stat_delta *new_stat = NULL;
struct dm_hw_stat_delta *temp;

mutex_lock(&trace_state_mutex);
mutex_lock(&net_dm_mutex);

if (state == trace_state) {
rc = -EAGAIN;
Expand Down Expand Up @@ -289,7 +295,7 @@ static int set_all_monitor_traces(int state)
rc = -EINPROGRESS;

out_unlock:
mutex_unlock(&trace_state_mutex);
mutex_unlock(&net_dm_mutex);

return rc;
}
Expand Down Expand Up @@ -330,12 +336,12 @@ static int dropmon_net_event(struct notifier_block *ev_block,

new_stat->dev = dev;
new_stat->last_rx = jiffies;
mutex_lock(&trace_state_mutex);
mutex_lock(&net_dm_mutex);
list_add_rcu(&new_stat->list, &hw_stats_list);
mutex_unlock(&trace_state_mutex);
mutex_unlock(&net_dm_mutex);
break;
case NETDEV_UNREGISTER:
mutex_lock(&trace_state_mutex);
mutex_lock(&net_dm_mutex);
list_for_each_entry_safe(new_stat, tmp, &hw_stats_list, list) {
if (new_stat->dev == dev) {
new_stat->dev = NULL;
Expand All @@ -346,7 +352,7 @@ static int dropmon_net_event(struct notifier_block *ev_block,
}
}
}
mutex_unlock(&trace_state_mutex);
mutex_unlock(&net_dm_mutex);
break;
}
out:
Expand Down

0 comments on commit dbf896b

Please sign in to comment.