Skip to content

Commit 17365ae

Browse files
lsgunthChristoph Hellwig
authored andcommitted
nvme: introduce nvme_execute_passthru_rq to call nvme_passthru_[start|end]()
Introduce a new nvme_execute_passthru_rq() helper which calls nvme_passthru_[start|end]() around blk_execute_rq(). This ensures all passthru calls (including nvme_submit_io()) will be wrapped appropriately. nvme_execute_passthru_rq() will also be useful for the nvmet passthru code and is exported in the NVME_TARGET_PASSTHRU namespace. Signed-off-by: Logan Gunthorpe <[email protected]> Reviewed-by: Keith Busch <[email protected]> Signed-off-by: Christoph Hellwig <[email protected]>
1 parent df21b6b commit 17365ae

File tree

2 files changed

+16
-7
lines changed

2 files changed

+16
-7
lines changed

drivers/nvme/host/core.c

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1028,6 +1028,20 @@ static void nvme_passthru_end(struct nvme_ctrl *ctrl, u32 effects)
10281028
}
10291029
}
10301030

1031+
void nvme_execute_passthru_rq(struct request *rq)
1032+
{
1033+
struct nvme_command *cmd = nvme_req(rq)->cmd;
1034+
struct nvme_ctrl *ctrl = nvme_req(rq)->ctrl;
1035+
struct nvme_ns *ns = rq->q->queuedata;
1036+
struct gendisk *disk = ns ? ns->disk : NULL;
1037+
u32 effects;
1038+
1039+
effects = nvme_passthru_start(ctrl, ns, cmd->common.opcode);
1040+
blk_execute_rq(rq->q, disk, rq, 0);
1041+
nvme_passthru_end(ctrl, effects);
1042+
}
1043+
EXPORT_SYMBOL_NS_GPL(nvme_execute_passthru_rq, NVME_TARGET_PASSTHRU);
1044+
10311045
static int nvme_submit_user_cmd(struct request_queue *q,
10321046
struct nvme_command *cmd, void __user *ubuffer,
10331047
unsigned bufflen, void __user *meta_buffer, unsigned meta_len,
@@ -1066,7 +1080,7 @@ static int nvme_submit_user_cmd(struct request_queue *q,
10661080
}
10671081
}
10681082

1069-
blk_execute_rq(req->q, disk, req, 0);
1083+
nvme_execute_passthru_rq(req);
10701084
if (nvme_req(req)->flags & NVME_REQ_CANCELLED)
10711085
ret = -EINTR;
10721086
else
@@ -1500,7 +1514,6 @@ static int nvme_user_cmd(struct nvme_ctrl *ctrl, struct nvme_ns *ns,
15001514
struct nvme_passthru_cmd cmd;
15011515
struct nvme_command c;
15021516
unsigned timeout = 0;
1503-
u32 effects;
15041517
u64 result;
15051518
int status;
15061519

@@ -1527,12 +1540,10 @@ static int nvme_user_cmd(struct nvme_ctrl *ctrl, struct nvme_ns *ns,
15271540
if (cmd.timeout_ms)
15281541
timeout = msecs_to_jiffies(cmd.timeout_ms);
15291542

1530-
effects = nvme_passthru_start(ctrl, ns, cmd.opcode);
15311543
status = nvme_submit_user_cmd(ns ? ns->queue : ctrl->admin_q, &c,
15321544
nvme_to_user_ptr(cmd.addr), cmd.data_len,
15331545
nvme_to_user_ptr(cmd.metadata), cmd.metadata_len,
15341546
0, &result, timeout);
1535-
nvme_passthru_end(ctrl, effects);
15361547

15371548
if (status >= 0) {
15381549
if (put_user(result, &ucmd->result))
@@ -1548,7 +1559,6 @@ static int nvme_user_cmd64(struct nvme_ctrl *ctrl, struct nvme_ns *ns,
15481559
struct nvme_passthru_cmd64 cmd;
15491560
struct nvme_command c;
15501561
unsigned timeout = 0;
1551-
u32 effects;
15521562
int status;
15531563

15541564
if (!capable(CAP_SYS_ADMIN))
@@ -1574,12 +1584,10 @@ static int nvme_user_cmd64(struct nvme_ctrl *ctrl, struct nvme_ns *ns,
15741584
if (cmd.timeout_ms)
15751585
timeout = msecs_to_jiffies(cmd.timeout_ms);
15761586

1577-
effects = nvme_passthru_start(ctrl, ns, cmd.opcode);
15781587
status = nvme_submit_user_cmd(ns ? ns->queue : ctrl->admin_q, &c,
15791588
nvme_to_user_ptr(cmd.addr), cmd.data_len,
15801589
nvme_to_user_ptr(cmd.metadata), cmd.metadata_len,
15811590
0, &cmd.result, timeout);
1582-
nvme_passthru_end(ctrl, effects);
15831591

15841592
if (status >= 0) {
15851593
if (put_user(cmd.result, &ucmd->result))

drivers/nvme/host/nvme.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -792,5 +792,6 @@ static inline void nvme_hwmon_init(struct nvme_ctrl *ctrl) { }
792792

793793
u32 nvme_command_effects(struct nvme_ctrl *ctrl, struct nvme_ns *ns,
794794
u8 opcode);
795+
void nvme_execute_passthru_rq(struct request *rq);
795796

796797
#endif /* _NVME_H */

0 commit comments

Comments
 (0)