Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

ublk: merge stop_work and quiesce_work

Save some lines by merging stop_work and quiesce_work into nosrv_work,
which looks at the recovery flags and does the right thing when the "no
ublk server" condition is detected.

Signed-off-by: Uday Shankar <ushankar@purestorage.com>
Reviewed-by: Ming Lei <ming.lei@redhat.com>
Link: https://lore.kernel.org/r/20241007182419.3263186-4-ushankar@purestorage.com
Signed-off-by: Jens Axboe <axboe@kernel.dk>

authored by

Uday Shankar and committed by
Jens Axboe
27b5d417 3b939b8f

+25 -39
+25 -39
drivers/block/ublk_drv.c
··· 182 182 unsigned int nr_queues_ready; 183 183 unsigned int nr_privileged_daemon; 184 184 185 - struct work_struct quiesce_work; 186 - struct work_struct stop_work; 185 + struct work_struct nosrv_work; 187 186 }; 188 187 189 188 /* header of ublk_params */ ··· 1260 1261 struct ublk_device *ub = ubq->dev; 1261 1262 1262 1263 if (ublk_abort_requests(ub, ubq)) { 1263 - if (ublk_nosrv_should_stop_dev(ub)) 1264 - schedule_work(&ub->stop_work); 1265 - else 1266 - schedule_work(&ub->quiesce_work); 1264 + schedule_work(&ub->nosrv_work); 1267 1265 } 1268 1266 return BLK_EH_DONE; 1269 1267 } ··· 1510 1514 ublk_cancel_cmd(ubq, io, issue_flags); 1511 1515 1512 1516 if (need_schedule) { 1513 - if (ublk_nosrv_should_stop_dev(ub)) 1514 - schedule_work(&ub->stop_work); 1515 - else 1516 - schedule_work(&ub->quiesce_work); 1517 + schedule_work(&ub->nosrv_work); 1517 1518 } 1518 1519 } 1519 1520 ··· 1573 1580 ub->dev_info.state = UBLK_S_DEV_QUIESCED; 1574 1581 } 1575 1582 1576 - static void ublk_quiesce_work_fn(struct work_struct *work) 1577 - { 1578 - struct ublk_device *ub = 1579 - container_of(work, struct ublk_device, quiesce_work); 1580 - 1581 - mutex_lock(&ub->mutex); 1582 - if (ub->dev_info.state != UBLK_S_DEV_LIVE) 1583 - goto unlock; 1584 - __ublk_quiesce_dev(ub); 1585 - unlock: 1586 - mutex_unlock(&ub->mutex); 1587 - ublk_cancel_dev(ub); 1588 - } 1589 - 1590 1583 static void ublk_unquiesce_dev(struct ublk_device *ub) 1591 1584 { 1592 1585 int i; ··· 1616 1637 ub->ub_disk = NULL; 1617 1638 spin_unlock(&ub->lock); 1618 1639 put_disk(disk); 1640 + unlock: 1641 + mutex_unlock(&ub->mutex); 1642 + ublk_cancel_dev(ub); 1643 + } 1644 + 1645 + static void ublk_nosrv_work(struct work_struct *work) 1646 + { 1647 + struct ublk_device *ub = 1648 + container_of(work, struct ublk_device, nosrv_work); 1649 + 1650 + if (ublk_nosrv_should_stop_dev(ub)) { 1651 + ublk_stop_dev(ub); 1652 + return; 1653 + } 1654 + 1655 + mutex_lock(&ub->mutex); 1656 + if (ub->dev_info.state != UBLK_S_DEV_LIVE) 1657 + goto unlock; 1658 + __ublk_quiesce_dev(ub); 1619 1659 unlock: 1620 1660 mutex_unlock(&ub->mutex); 1621 1661 ublk_cancel_dev(ub); ··· 2153 2155 return ret; 2154 2156 } 2155 2157 2156 - static void ublk_stop_work_fn(struct work_struct *work) 2157 - { 2158 - struct ublk_device *ub = 2159 - container_of(work, struct ublk_device, stop_work); 2160 - 2161 - ublk_stop_dev(ub); 2162 - } 2163 - 2164 2158 /* align max io buffer size with PAGE_SIZE */ 2165 2159 static void ublk_align_max_io_size(struct ublk_device *ub) 2166 2160 { ··· 2177 2187 static void ublk_remove(struct ublk_device *ub) 2178 2188 { 2179 2189 ublk_stop_dev(ub); 2180 - cancel_work_sync(&ub->stop_work); 2181 - cancel_work_sync(&ub->quiesce_work); 2190 + cancel_work_sync(&ub->nosrv_work); 2182 2191 cdev_device_del(&ub->cdev, &ub->cdev_dev); 2183 2192 ublk_put_device(ub); 2184 2193 ublks_added--; ··· 2446 2457 goto out_unlock; 2447 2458 mutex_init(&ub->mutex); 2448 2459 spin_lock_init(&ub->lock); 2449 - INIT_WORK(&ub->quiesce_work, ublk_quiesce_work_fn); 2450 - INIT_WORK(&ub->stop_work, ublk_stop_work_fn); 2460 + INIT_WORK(&ub->nosrv_work, ublk_nosrv_work); 2451 2461 2452 2462 ret = ublk_alloc_dev_number(ub, header->dev_id); 2453 2463 if (ret < 0) ··· 2581 2593 static int ublk_ctrl_stop_dev(struct ublk_device *ub) 2582 2594 { 2583 2595 ublk_stop_dev(ub); 2584 - cancel_work_sync(&ub->stop_work); 2585 - cancel_work_sync(&ub->quiesce_work); 2586 - 2596 + cancel_work_sync(&ub->nosrv_work); 2587 2597 return 0; 2588 2598 } 2589 2599