@@ -392,13 +392,25 @@ static int nullb_update_nr_hw_queues(struct nullb_device *dev,
392
392
static int nullb_apply_submit_queues (struct nullb_device * dev ,
393
393
unsigned int submit_queues )
394
394
{
395
- return nullb_update_nr_hw_queues (dev , submit_queues , dev -> poll_queues );
395
+ int ret ;
396
+
397
+ mutex_lock (& lock );
398
+ ret = nullb_update_nr_hw_queues (dev , submit_queues , dev -> poll_queues );
399
+ mutex_unlock (& lock );
400
+
401
+ return ret ;
396
402
}
397
403
398
404
static int nullb_apply_poll_queues (struct nullb_device * dev ,
399
405
unsigned int poll_queues )
400
406
{
401
- return nullb_update_nr_hw_queues (dev , dev -> submit_queues , poll_queues );
407
+ int ret ;
408
+
409
+ mutex_lock (& lock );
410
+ ret = nullb_update_nr_hw_queues (dev , dev -> submit_queues , poll_queues );
411
+ mutex_unlock (& lock );
412
+
413
+ return ret ;
402
414
}
403
415
404
416
NULLB_DEVICE_ATTR (size , ulong , NULL );
@@ -444,28 +456,31 @@ static ssize_t nullb_device_power_store(struct config_item *item,
444
456
if (ret < 0 )
445
457
return ret ;
446
458
459
+ ret = count ;
460
+ mutex_lock (& lock );
447
461
if (!dev -> power && newp ) {
448
462
if (test_and_set_bit (NULLB_DEV_FL_UP , & dev -> flags ))
449
- return count ;
463
+ goto out ;
464
+
450
465
ret = null_add_dev (dev );
451
466
if (ret ) {
452
467
clear_bit (NULLB_DEV_FL_UP , & dev -> flags );
453
- return ret ;
468
+ goto out ;
454
469
}
455
470
456
471
set_bit (NULLB_DEV_FL_CONFIGURED , & dev -> flags );
457
472
dev -> power = newp ;
458
473
} else if (dev -> power && !newp ) {
459
474
if (test_and_clear_bit (NULLB_DEV_FL_UP , & dev -> flags )) {
460
- mutex_lock (& lock );
461
475
dev -> power = newp ;
462
476
null_del_dev (dev -> nullb );
463
- mutex_unlock (& lock );
464
477
}
465
478
clear_bit (NULLB_DEV_FL_CONFIGURED , & dev -> flags );
466
479
}
467
480
468
- return count ;
481
+ out :
482
+ mutex_unlock (& lock );
483
+ return ret ;
469
484
}
470
485
471
486
CONFIGFS_ATTR (nullb_device_ , power );
@@ -2102,15 +2117,12 @@ static int null_add_dev(struct nullb_device *dev)
2102
2117
blk_queue_flag_set (QUEUE_FLAG_NONROT , nullb -> q );
2103
2118
blk_queue_flag_clear (QUEUE_FLAG_ADD_RANDOM , nullb -> q );
2104
2119
2105
- mutex_lock (& lock );
2106
2120
rv = ida_alloc (& nullb_indexes , GFP_KERNEL );
2107
- if (rv < 0 ) {
2108
- mutex_unlock (& lock );
2121
+ if (rv < 0 )
2109
2122
goto out_cleanup_zone ;
2110
- }
2123
+
2111
2124
nullb -> index = rv ;
2112
2125
dev -> index = rv ;
2113
- mutex_unlock (& lock );
2114
2126
2115
2127
blk_queue_logical_block_size (nullb -> q , dev -> blocksize );
2116
2128
blk_queue_physical_block_size (nullb -> q , dev -> blocksize );
@@ -2134,9 +2146,7 @@ static int null_add_dev(struct nullb_device *dev)
2134
2146
if (rv )
2135
2147
goto out_ida_free ;
2136
2148
2137
- mutex_lock (& lock );
2138
2149
list_add_tail (& nullb -> list , & nullb_list );
2139
- mutex_unlock (& lock );
2140
2150
2141
2151
pr_info ("disk %s created\n" , nullb -> disk_name );
2142
2152
@@ -2185,7 +2195,9 @@ static int null_create_dev(void)
2185
2195
if (!dev )
2186
2196
return - ENOMEM ;
2187
2197
2198
+ mutex_lock (& lock );
2188
2199
ret = null_add_dev (dev );
2200
+ mutex_unlock (& lock );
2189
2201
if (ret ) {
2190
2202
null_free_dev (dev );
2191
2203
return ret ;
0 commit comments