@@ -57,7 +57,8 @@ static struct tracer_flags blk_tracer_flags = {
57
57
};
58
58
59
59
/* Global reference count of probes */
60
- static atomic_t blk_probes_ref = ATOMIC_INIT (0 );
60
+ static DEFINE_MUTEX (blk_probe_mutex );
61
+ static int blk_probes_ref ;
61
62
62
63
static void blk_register_tracepoints (void );
63
64
static void blk_unregister_tracepoints (void );
@@ -306,11 +307,26 @@ static void blk_trace_free(struct blk_trace *bt)
306
307
kfree (bt );
307
308
}
308
309
310
+ static void get_probe_ref (void )
311
+ {
312
+ mutex_lock (& blk_probe_mutex );
313
+ if (++ blk_probes_ref == 1 )
314
+ blk_register_tracepoints ();
315
+ mutex_unlock (& blk_probe_mutex );
316
+ }
317
+
318
+ static void put_probe_ref (void )
319
+ {
320
+ mutex_lock (& blk_probe_mutex );
321
+ if (!-- blk_probes_ref )
322
+ blk_unregister_tracepoints ();
323
+ mutex_unlock (& blk_probe_mutex );
324
+ }
325
+
309
326
static void blk_trace_cleanup (struct blk_trace * bt )
310
327
{
311
328
blk_trace_free (bt );
312
- if (atomic_dec_and_test (& blk_probes_ref ))
313
- blk_unregister_tracepoints ();
329
+ put_probe_ref ();
314
330
}
315
331
316
332
int blk_trace_remove (struct request_queue * q )
@@ -522,8 +538,7 @@ int do_blk_trace_setup(struct request_queue *q, char *name, dev_t dev,
522
538
if (cmpxchg (& q -> blk_trace , NULL , bt ))
523
539
goto err ;
524
540
525
- if (atomic_inc_return (& blk_probes_ref ) == 1 )
526
- blk_register_tracepoints ();
541
+ get_probe_ref ();
527
542
528
543
return 0 ;
529
544
err :
@@ -1469,9 +1484,7 @@ static int blk_trace_remove_queue(struct request_queue *q)
1469
1484
if (bt == NULL )
1470
1485
return - EINVAL ;
1471
1486
1472
- if (atomic_dec_and_test (& blk_probes_ref ))
1473
- blk_unregister_tracepoints ();
1474
-
1487
+ put_probe_ref ();
1475
1488
blk_trace_free (bt );
1476
1489
return 0 ;
1477
1490
}
@@ -1502,8 +1515,7 @@ static int blk_trace_setup_queue(struct request_queue *q,
1502
1515
if (cmpxchg (& q -> blk_trace , NULL , bt ))
1503
1516
goto free_bt ;
1504
1517
1505
- if (atomic_inc_return (& blk_probes_ref ) == 1 )
1506
- blk_register_tracepoints ();
1518
+ get_probe_ref ();
1507
1519
return 0 ;
1508
1520
1509
1521
free_bt :
0 commit comments