@@ -128,6 +128,20 @@ static void queue_if_no_path_timeout_work(struct timer_list *t);
128
128
#define MPATHF_PG_INIT_REQUIRED 5 /* pg_init needs calling? */
129
129
#define MPATHF_PG_INIT_DELAY_RETRY 6 /* Delay pg_init retry? */
130
130
131
+ static bool mpath_double_check_test_bit (int MPATHF_bit , struct multipath * m )
132
+ {
133
+ bool r = test_bit (MPATHF_bit , & m -> flags );
134
+
135
+ if (r ) {
136
+ unsigned long flags ;
137
+ spin_lock_irqsave (& m -> lock , flags );
138
+ r = test_bit (MPATHF_bit , & m -> flags );
139
+ spin_unlock_irqrestore (& m -> lock , flags );
140
+ }
141
+
142
+ return r ;
143
+ }
144
+
131
145
/*-----------------------------------------------
132
146
* Allocation routines
133
147
*-----------------------------------------------*/
@@ -499,16 +513,16 @@ static int multipath_clone_and_map(struct dm_target *ti, struct request *rq,
499
513
500
514
/* Do we need to select a new pgpath? */
501
515
pgpath = READ_ONCE (m -> current_pgpath );
502
- if (!pgpath || !test_bit (MPATHF_QUEUE_IO , & m -> flags ))
516
+ if (!pgpath || !mpath_double_check_test_bit (MPATHF_QUEUE_IO , m ))
503
517
pgpath = choose_pgpath (m , nr_bytes );
504
518
505
519
if (!pgpath ) {
506
520
if (must_push_back_rq (m ))
507
521
return DM_MAPIO_DELAY_REQUEUE ;
508
522
dm_report_EIO (m ); /* Failed */
509
523
return DM_MAPIO_KILL ;
510
- } else if (test_bit (MPATHF_QUEUE_IO , & m -> flags ) ||
511
- test_bit (MPATHF_PG_INIT_REQUIRED , & m -> flags )) {
524
+ } else if (mpath_double_check_test_bit (MPATHF_QUEUE_IO , m ) ||
525
+ mpath_double_check_test_bit (MPATHF_PG_INIT_REQUIRED , m )) {
512
526
pg_init_all_paths (m );
513
527
return DM_MAPIO_DELAY_REQUEUE ;
514
528
}
@@ -598,7 +612,7 @@ static struct pgpath *__map_bio(struct multipath *m, struct bio *bio)
598
612
599
613
/* Do we need to select a new pgpath? */
600
614
pgpath = READ_ONCE (m -> current_pgpath );
601
- if (!pgpath || !test_bit (MPATHF_QUEUE_IO , & m -> flags ))
615
+ if (!pgpath || !mpath_double_check_test_bit (MPATHF_QUEUE_IO , m ))
602
616
pgpath = choose_pgpath (m , bio -> bi_iter .bi_size );
603
617
604
618
if (!pgpath ) {
@@ -609,8 +623,8 @@ static struct pgpath *__map_bio(struct multipath *m, struct bio *bio)
609
623
}
610
624
spin_unlock_irqrestore (& m -> lock , flags );
611
625
612
- } else if (test_bit (MPATHF_QUEUE_IO , & m -> flags ) ||
613
- test_bit (MPATHF_PG_INIT_REQUIRED , & m -> flags )) {
626
+ } else if (mpath_double_check_test_bit (MPATHF_QUEUE_IO , m ) ||
627
+ mpath_double_check_test_bit (MPATHF_PG_INIT_REQUIRED , m )) {
614
628
multipath_queue_bio (m , bio );
615
629
pg_init_all_paths (m );
616
630
return ERR_PTR (- EAGAIN );
@@ -861,7 +875,7 @@ static int setup_scsi_dh(struct block_device *bdev, struct multipath *m,
861
875
struct request_queue * q = bdev_get_queue (bdev );
862
876
int r ;
863
877
864
- if (test_bit (MPATHF_RETAIN_ATTACHED_HW_HANDLER , & m -> flags )) {
878
+ if (mpath_double_check_test_bit (MPATHF_RETAIN_ATTACHED_HW_HANDLER , m )) {
865
879
retain :
866
880
if (* attached_handler_name ) {
867
881
/*
@@ -1967,11 +1981,11 @@ static int multipath_prepare_ioctl(struct dm_target *ti,
1967
1981
int r ;
1968
1982
1969
1983
pgpath = READ_ONCE (m -> current_pgpath );
1970
- if (!pgpath || !test_bit (MPATHF_QUEUE_IO , & m -> flags ))
1984
+ if (!pgpath || !mpath_double_check_test_bit (MPATHF_QUEUE_IO , m ))
1971
1985
pgpath = choose_pgpath (m , 0 );
1972
1986
1973
1987
if (pgpath ) {
1974
- if (!test_bit (MPATHF_QUEUE_IO , & m -> flags )) {
1988
+ if (!mpath_double_check_test_bit (MPATHF_QUEUE_IO , m )) {
1975
1989
* bdev = pgpath -> path .dev -> bdev ;
1976
1990
r = 0 ;
1977
1991
} else {
0 commit comments