@@ -66,7 +66,8 @@ static struct tracer_flags blk_tracer_flags = {
66
66
};
67
67
68
68
/* Global reference count of probes */
69
- static atomic_t blk_probes_ref = ATOMIC_INIT (0 );
69
+ static DEFINE_MUTEX (blk_probe_mutex );
70
+ static int blk_probes_ref ;
70
71
71
72
static void blk_register_tracepoints (void );
72
73
static void blk_unregister_tracepoints (void );
@@ -329,11 +330,26 @@ static void blk_trace_free(struct blk_trace *bt)
329
330
kfree (bt );
330
331
}
331
332
333
+ static void get_probe_ref (void )
334
+ {
335
+ mutex_lock (& blk_probe_mutex );
336
+ if (++ blk_probes_ref == 1 )
337
+ blk_register_tracepoints ();
338
+ mutex_unlock (& blk_probe_mutex );
339
+ }
340
+
341
+ static void put_probe_ref (void )
342
+ {
343
+ mutex_lock (& blk_probe_mutex );
344
+ if (!-- blk_probes_ref )
345
+ blk_unregister_tracepoints ();
346
+ mutex_unlock (& blk_probe_mutex );
347
+ }
348
+
332
349
static void blk_trace_cleanup (struct blk_trace * bt )
333
350
{
334
351
blk_trace_free (bt );
335
- if (atomic_dec_and_test (& blk_probes_ref ))
336
- blk_unregister_tracepoints ();
352
+ put_probe_ref ();
337
353
}
338
354
339
355
static int __blk_trace_remove (struct request_queue * q )
@@ -549,8 +565,7 @@ static int do_blk_trace_setup(struct request_queue *q, char *name, dev_t dev,
549
565
if (cmpxchg (& q -> blk_trace , NULL , bt ))
550
566
goto err ;
551
567
552
- if (atomic_inc_return (& blk_probes_ref ) == 1 )
553
- blk_register_tracepoints ();
568
+ get_probe_ref ();
554
569
555
570
ret = 0 ;
556
571
err :
@@ -1596,9 +1611,7 @@ static int blk_trace_remove_queue(struct request_queue *q)
1596
1611
if (bt == NULL )
1597
1612
return - EINVAL ;
1598
1613
1599
- if (atomic_dec_and_test (& blk_probes_ref ))
1600
- blk_unregister_tracepoints ();
1601
-
1614
+ put_probe_ref ();
1602
1615
blk_trace_free (bt );
1603
1616
return 0 ;
1604
1617
}
@@ -1629,8 +1642,7 @@ static int blk_trace_setup_queue(struct request_queue *q,
1629
1642
if (cmpxchg (& q -> blk_trace , NULL , bt ))
1630
1643
goto free_bt ;
1631
1644
1632
- if (atomic_inc_return (& blk_probes_ref ) == 1 )
1633
- blk_register_tracepoints ();
1645
+ get_probe_ref ();
1634
1646
return 0 ;
1635
1647
1636
1648
free_bt :
0 commit comments