@@ -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 );
@@ -300,11 +301,26 @@ static void blk_trace_free(struct blk_trace *bt)
300
301
kfree (bt );
301
302
}
302
303
304
+ static void get_probe_ref (void )
305
+ {
306
+ mutex_lock (& blk_probe_mutex );
307
+ if (++ blk_probes_ref == 1 )
308
+ blk_register_tracepoints ();
309
+ mutex_unlock (& blk_probe_mutex );
310
+ }
311
+
312
+ static void put_probe_ref (void )
313
+ {
314
+ mutex_lock (& blk_probe_mutex );
315
+ if (!-- blk_probes_ref )
316
+ blk_unregister_tracepoints ();
317
+ mutex_unlock (& blk_probe_mutex );
318
+ }
319
+
303
320
static void blk_trace_cleanup (struct blk_trace * bt )
304
321
{
305
322
blk_trace_free (bt );
306
- if (atomic_dec_and_test (& blk_probes_ref ))
307
- blk_unregister_tracepoints ();
323
+ put_probe_ref ();
308
324
}
309
325
310
326
int blk_trace_remove (struct request_queue * q )
@@ -527,8 +543,7 @@ int do_blk_trace_setup(struct request_queue *q, char *name, dev_t dev,
527
543
goto err ;
528
544
}
529
545
530
- if (atomic_inc_return (& blk_probes_ref ) == 1 )
531
- blk_register_tracepoints ();
546
+ get_probe_ref ();
532
547
533
548
return 0 ;
534
549
err :
@@ -1474,9 +1489,7 @@ static int blk_trace_remove_queue(struct request_queue *q)
1474
1489
if (bt == NULL )
1475
1490
return - EINVAL ;
1476
1491
1477
- if (atomic_dec_and_test (& blk_probes_ref ))
1478
- blk_unregister_tracepoints ();
1479
-
1492
+ put_probe_ref ();
1480
1493
blk_trace_free (bt );
1481
1494
return 0 ;
1482
1495
}
@@ -1510,8 +1523,7 @@ static int blk_trace_setup_queue(struct request_queue *q,
1510
1523
goto free_bt ;
1511
1524
}
1512
1525
1513
- if (atomic_inc_return (& blk_probes_ref ) == 1 )
1514
- blk_register_tracepoints ();
1526
+ get_probe_ref ();
1515
1527
return 0 ;
1516
1528
1517
1529
free_bt :
0 commit comments