Skip to content

Commit 27b5d41

Browse files
ps-ushankaraxboe
authored andcommitted
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 <[email protected]> Reviewed-by: Ming Lei <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Jens Axboe <[email protected]>
1 parent 3b939b8 commit 27b5d41

File tree

1 file changed

+25
-39
lines changed

1 file changed

+25
-39
lines changed

drivers/block/ublk_drv.c

Lines changed: 25 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -182,8 +182,7 @@ struct ublk_device {
182182
unsigned int nr_queues_ready;
183183
unsigned int nr_privileged_daemon;
184184

185-
struct work_struct quiesce_work;
186-
struct work_struct stop_work;
185+
struct work_struct nosrv_work;
187186
};
188187

189188
/* header of ublk_params */
@@ -1261,10 +1260,7 @@ static enum blk_eh_timer_return ublk_timeout(struct request *rq)
12611260
struct ublk_device *ub = ubq->dev;
12621261

12631262
if (ublk_abort_requests(ub, ubq)) {
1264-
if (ublk_nosrv_should_stop_dev(ub))
1265-
schedule_work(&ub->stop_work);
1266-
else
1267-
schedule_work(&ub->quiesce_work);
1263+
schedule_work(&ub->nosrv_work);
12681264
}
12691265
return BLK_EH_DONE;
12701266
}
@@ -1514,10 +1510,7 @@ static void ublk_uring_cmd_cancel_fn(struct io_uring_cmd *cmd,
15141510
ublk_cancel_cmd(ubq, io, issue_flags);
15151511

15161512
if (need_schedule) {
1517-
if (ublk_nosrv_should_stop_dev(ub))
1518-
schedule_work(&ub->stop_work);
1519-
else
1520-
schedule_work(&ub->quiesce_work);
1513+
schedule_work(&ub->nosrv_work);
15211514
}
15221515
}
15231516

@@ -1580,20 +1573,6 @@ static void __ublk_quiesce_dev(struct ublk_device *ub)
15801573
ub->dev_info.state = UBLK_S_DEV_QUIESCED;
15811574
}
15821575

1583-
static void ublk_quiesce_work_fn(struct work_struct *work)
1584-
{
1585-
struct ublk_device *ub =
1586-
container_of(work, struct ublk_device, quiesce_work);
1587-
1588-
mutex_lock(&ub->mutex);
1589-
if (ub->dev_info.state != UBLK_S_DEV_LIVE)
1590-
goto unlock;
1591-
__ublk_quiesce_dev(ub);
1592-
unlock:
1593-
mutex_unlock(&ub->mutex);
1594-
ublk_cancel_dev(ub);
1595-
}
1596-
15971576
static void ublk_unquiesce_dev(struct ublk_device *ub)
15981577
{
15991578
int i;
@@ -1642,6 +1621,25 @@ static void ublk_stop_dev(struct ublk_device *ub)
16421621
ublk_cancel_dev(ub);
16431622
}
16441623

1624+
static void ublk_nosrv_work(struct work_struct *work)
1625+
{
1626+
struct ublk_device *ub =
1627+
container_of(work, struct ublk_device, nosrv_work);
1628+
1629+
if (ublk_nosrv_should_stop_dev(ub)) {
1630+
ublk_stop_dev(ub);
1631+
return;
1632+
}
1633+
1634+
mutex_lock(&ub->mutex);
1635+
if (ub->dev_info.state != UBLK_S_DEV_LIVE)
1636+
goto unlock;
1637+
__ublk_quiesce_dev(ub);
1638+
unlock:
1639+
mutex_unlock(&ub->mutex);
1640+
ublk_cancel_dev(ub);
1641+
}
1642+
16451643
/* device can only be started after all IOs are ready */
16461644
static void ublk_mark_io_ready(struct ublk_device *ub, struct ublk_queue *ubq)
16471645
{
@@ -2155,14 +2153,6 @@ static int ublk_add_chdev(struct ublk_device *ub)
21552153
return ret;
21562154
}
21572155

2158-
static void ublk_stop_work_fn(struct work_struct *work)
2159-
{
2160-
struct ublk_device *ub =
2161-
container_of(work, struct ublk_device, stop_work);
2162-
2163-
ublk_stop_dev(ub);
2164-
}
2165-
21662156
/* align max io buffer size with PAGE_SIZE */
21672157
static void ublk_align_max_io_size(struct ublk_device *ub)
21682158
{
@@ -2187,8 +2177,7 @@ static int ublk_add_tag_set(struct ublk_device *ub)
21872177
static void ublk_remove(struct ublk_device *ub)
21882178
{
21892179
ublk_stop_dev(ub);
2190-
cancel_work_sync(&ub->stop_work);
2191-
cancel_work_sync(&ub->quiesce_work);
2180+
cancel_work_sync(&ub->nosrv_work);
21922181
cdev_device_del(&ub->cdev, &ub->cdev_dev);
21932182
ublk_put_device(ub);
21942183
ublks_added--;
@@ -2457,8 +2446,7 @@ static int ublk_ctrl_add_dev(struct io_uring_cmd *cmd)
24572446
goto out_unlock;
24582447
mutex_init(&ub->mutex);
24592448
spin_lock_init(&ub->lock);
2460-
INIT_WORK(&ub->quiesce_work, ublk_quiesce_work_fn);
2461-
INIT_WORK(&ub->stop_work, ublk_stop_work_fn);
2449+
INIT_WORK(&ub->nosrv_work, ublk_nosrv_work);
24622450

24632451
ret = ublk_alloc_dev_number(ub, header->dev_id);
24642452
if (ret < 0)
@@ -2593,9 +2581,7 @@ static inline void ublk_ctrl_cmd_dump(struct io_uring_cmd *cmd)
25932581
static int ublk_ctrl_stop_dev(struct ublk_device *ub)
25942582
{
25952583
ublk_stop_dev(ub);
2596-
cancel_work_sync(&ub->stop_work);
2597-
cancel_work_sync(&ub->quiesce_work);
2598-
2584+
cancel_work_sync(&ub->nosrv_work);
25992585
return 0;
26002586
}
26012587

0 commit comments

Comments
 (0)