Skip to content

Commit fee32f3

Browse files
Ming Leiaxboe
authored andcommitted
ublk_drv: add ublk_queue_cmd() for cleanup
Add helper of ublk_queue_cmd() so that both ublk_queue_rq() and ublk_handle_need_get_data() can reuse this helper. Signed-off-by: Ming Lei <[email protected]> Reviewed-by: ZiyangZhang <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Jens Axboe <[email protected]>
1 parent 3ab6e94 commit fee32f3

File tree

1 file changed

+21
-26
lines changed

1 file changed

+21
-26
lines changed

drivers/block/ublk_drv.c

Lines changed: 21 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -817,12 +817,28 @@ static void ublk_submit_cmd(struct ublk_queue *ubq, const struct request *rq)
817817
}
818818
}
819819

820+
static void ublk_queue_cmd(struct ublk_queue *ubq, struct request *rq,
821+
bool last)
822+
{
823+
struct ublk_rq_data *data = blk_mq_rq_to_pdu(rq);
824+
825+
if (ublk_can_use_task_work(ubq)) {
826+
enum task_work_notify_mode notify_mode = last ?
827+
TWA_SIGNAL_NO_IPI : TWA_NONE;
828+
829+
if (task_work_add(ubq->ubq_daemon, &data->work, notify_mode))
830+
__ublk_abort_rq(ubq, rq);
831+
} else {
832+
if (llist_add(&data->node, &ubq->io_cmds))
833+
ublk_submit_cmd(ubq, rq);
834+
}
835+
}
836+
820837
static blk_status_t ublk_queue_rq(struct blk_mq_hw_ctx *hctx,
821838
const struct blk_mq_queue_data *bd)
822839
{
823840
struct ublk_queue *ubq = hctx->driver_data;
824841
struct request *rq = bd->rq;
825-
struct ublk_rq_data *data = blk_mq_rq_to_pdu(rq);
826842
blk_status_t res;
827843

828844
/* fill iod to slot in io cmd buffer */
@@ -845,21 +861,12 @@ static blk_status_t ublk_queue_rq(struct blk_mq_hw_ctx *hctx,
845861
blk_mq_start_request(bd->rq);
846862

847863
if (unlikely(ubq_daemon_is_dying(ubq))) {
848-
fail:
849864
__ublk_abort_rq(ubq, rq);
850865
return BLK_STS_OK;
851866
}
852867

853-
if (ublk_can_use_task_work(ubq)) {
854-
enum task_work_notify_mode notify_mode = bd->last ?
855-
TWA_SIGNAL_NO_IPI : TWA_NONE;
868+
ublk_queue_cmd(ubq, rq, bd->last);
856869

857-
if (task_work_add(ubq->ubq_daemon, &data->work, notify_mode))
858-
goto fail;
859-
} else {
860-
if (llist_add(&data->node, &ubq->io_cmds))
861-
ublk_submit_cmd(ubq, rq);
862-
}
863870
return BLK_STS_OK;
864871
}
865872

@@ -1185,24 +1192,12 @@ static void ublk_mark_io_ready(struct ublk_device *ub, struct ublk_queue *ubq)
11851192
}
11861193

11871194
static void ublk_handle_need_get_data(struct ublk_device *ub, int q_id,
1188-
int tag, struct io_uring_cmd *cmd)
1195+
int tag)
11891196
{
11901197
struct ublk_queue *ubq = ublk_get_queue(ub, q_id);
11911198
struct request *req = blk_mq_tag_to_rq(ub->tag_set.tags[q_id], tag);
1192-
struct ublk_rq_data *data = blk_mq_rq_to_pdu(req);
11931199

1194-
if (ublk_can_use_task_work(ubq)) {
1195-
/* should not fail since we call it just in ubq->ubq_daemon */
1196-
task_work_add(ubq->ubq_daemon, &data->work, TWA_SIGNAL_NO_IPI);
1197-
} else {
1198-
struct ublk_uring_cmd_pdu *pdu = ublk_get_uring_cmd_pdu(cmd);
1199-
1200-
if (llist_add(&data->node, &ubq->io_cmds)) {
1201-
pdu->ubq = ubq;
1202-
io_uring_cmd_complete_in_task(cmd,
1203-
ublk_rq_task_work_cb);
1204-
}
1205-
}
1200+
ublk_queue_cmd(ubq, req, true);
12061201
}
12071202

12081203
static int ublk_ch_uring_cmd(struct io_uring_cmd *cmd, unsigned int issue_flags)
@@ -1290,7 +1285,7 @@ static int ublk_ch_uring_cmd(struct io_uring_cmd *cmd, unsigned int issue_flags)
12901285
io->addr = ub_cmd->addr;
12911286
io->cmd = cmd;
12921287
io->flags |= UBLK_IO_FLAG_ACTIVE;
1293-
ublk_handle_need_get_data(ub, ub_cmd->q_id, ub_cmd->tag, cmd);
1288+
ublk_handle_need_get_data(ub, ub_cmd->q_id, ub_cmd->tag);
12941289
break;
12951290
default:
12961291
goto out;

0 commit comments

Comments
 (0)