@@ -395,6 +395,14 @@ static u32 req_to_nbd_cmd_type(struct request *req)
395
395
}
396
396
}
397
397
398
+ static struct nbd_config * nbd_get_config_unlocked (struct nbd_device * nbd )
399
+ {
400
+ if (refcount_inc_not_zero (& nbd -> config_refs ))
401
+ return nbd -> config ;
402
+
403
+ return NULL ;
404
+ }
405
+
398
406
static enum blk_eh_timer_return nbd_xmit_timeout (struct request * req )
399
407
{
400
408
struct nbd_cmd * cmd = blk_mq_rq_to_pdu (req );
@@ -409,13 +417,13 @@ static enum blk_eh_timer_return nbd_xmit_timeout(struct request *req)
409
417
return BLK_EH_DONE ;
410
418
}
411
419
412
- if (!refcount_inc_not_zero (& nbd -> config_refs )) {
420
+ config = nbd_get_config_unlocked (nbd );
421
+ if (!config ) {
413
422
cmd -> status = BLK_STS_TIMEOUT ;
414
423
__clear_bit (NBD_CMD_INFLIGHT , & cmd -> flags );
415
424
mutex_unlock (& cmd -> lock );
416
425
goto done ;
417
426
}
418
- config = nbd -> config ;
419
427
420
428
if (config -> num_connections > 1 ||
421
429
(config -> num_connections == 1 && nbd -> tag_set .timeout )) {
@@ -977,12 +985,12 @@ static int nbd_handle_cmd(struct nbd_cmd *cmd, int index)
977
985
struct nbd_sock * nsock ;
978
986
int ret ;
979
987
980
- if (!refcount_inc_not_zero (& nbd -> config_refs )) {
988
+ config = nbd_get_config_unlocked (nbd );
989
+ if (!config ) {
981
990
dev_err_ratelimited (disk_to_dev (nbd -> disk ),
982
991
"Socks array is empty\n" );
983
992
return - EINVAL ;
984
993
}
985
- config = nbd -> config ;
986
994
987
995
if (index >= config -> num_connections ) {
988
996
dev_err_ratelimited (disk_to_dev (nbd -> disk ),
@@ -1560,6 +1568,7 @@ static int nbd_alloc_and_init_config(struct nbd_device *nbd)
1560
1568
static int nbd_open (struct gendisk * disk , blk_mode_t mode )
1561
1569
{
1562
1570
struct nbd_device * nbd ;
1571
+ struct nbd_config * config ;
1563
1572
int ret = 0 ;
1564
1573
1565
1574
mutex_lock (& nbd_index_mutex );
@@ -1572,7 +1581,9 @@ static int nbd_open(struct gendisk *disk, blk_mode_t mode)
1572
1581
ret = - ENXIO ;
1573
1582
goto out ;
1574
1583
}
1575
- if (!refcount_inc_not_zero (& nbd -> config_refs )) {
1584
+
1585
+ config = nbd_get_config_unlocked (nbd );
1586
+ if (!config ) {
1576
1587
mutex_lock (& nbd -> config_lock );
1577
1588
if (refcount_inc_not_zero (& nbd -> config_refs )) {
1578
1589
mutex_unlock (& nbd -> config_lock );
@@ -1588,7 +1599,7 @@ static int nbd_open(struct gendisk *disk, blk_mode_t mode)
1588
1599
mutex_unlock (& nbd -> config_lock );
1589
1600
if (max_part )
1590
1601
set_bit (GD_NEED_PART_SCAN , & disk -> state );
1591
- } else if (nbd_disconnected (nbd -> config )) {
1602
+ } else if (nbd_disconnected (config )) {
1592
1603
if (max_part )
1593
1604
set_bit (GD_NEED_PART_SCAN , & disk -> state );
1594
1605
}
@@ -2205,15 +2216,15 @@ static int nbd_genl_reconfigure(struct sk_buff *skb, struct genl_info *info)
2205
2216
}
2206
2217
mutex_unlock (& nbd_index_mutex );
2207
2218
2208
- if (!refcount_inc_not_zero (& nbd -> config_refs )) {
2219
+ config = nbd_get_config_unlocked (nbd );
2220
+ if (!config ) {
2209
2221
dev_err (nbd_to_dev (nbd ),
2210
2222
"not configured, cannot reconfigure\n" );
2211
2223
nbd_put (nbd );
2212
2224
return - EINVAL ;
2213
2225
}
2214
2226
2215
2227
mutex_lock (& nbd -> config_lock );
2216
- config = nbd -> config ;
2217
2228
if (!test_bit (NBD_RT_BOUND , & config -> runtime_flags ) ||
2218
2229
!nbd -> pid ) {
2219
2230
dev_err (nbd_to_dev (nbd ),
0 commit comments