Skip to content

Commit 35897b9

Browse files
author
Christoph Hellwig
committed
nvme-fabrics: fix and refine state checks in __nvmf_check_ready
- make sure we only allow internally generates commands in any non-live state - only allow connect commands on non-live queues when actually in the new or connecting states - treat all other non-live, non-dead states the same as a default cach-all This fixes a regression where we could not shutdown a controller orderly as we didn't allow the internal generated Property Set command, and also ensures we don't accidentally let a Connect command through in the wrong state. Signed-off-by: Christoph Hellwig <[email protected]> Reviewed-by: James Smart <[email protected]>
1 parent 278ab37 commit 35897b9

File tree

1 file changed

+19
-20
lines changed

1 file changed

+19
-20
lines changed

drivers/nvme/host/fabrics.c

Lines changed: 19 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -556,34 +556,33 @@ EXPORT_SYMBOL_GPL(nvmf_fail_nonready_command);
556556
bool __nvmf_check_ready(struct nvme_ctrl *ctrl, struct request *rq,
557557
bool queue_live)
558558
{
559-
struct nvme_command *cmd = nvme_req(rq)->cmd;
559+
struct nvme_request *req = nvme_req(rq);
560560

561+
/*
562+
* If we are in some state of setup or teardown only allow
563+
* internally generated commands.
564+
*/
565+
if (!blk_rq_is_passthrough(rq) || (req->flags & NVME_REQ_USERCMD))
566+
return false;
567+
568+
/*
569+
* Only allow commands on a live queue, except for the connect command,
570+
* which is require to set the queue live in the appropinquate states.
571+
*/
561572
switch (ctrl->state) {
562573
case NVME_CTRL_NEW:
563574
case NVME_CTRL_CONNECTING:
564-
case NVME_CTRL_DELETING:
565-
/*
566-
* If queue is live, allow only commands that are internally
567-
* generated pass through. These are commands on the admin
568-
* queue to initialize the controller. This will reject any
569-
* ioctl admin cmds received while initializing.
570-
*/
571-
if (queue_live && !(nvme_req(rq)->flags & NVME_REQ_USERCMD))
575+
if (req->cmd->common.opcode == nvme_fabrics_command &&
576+
req->cmd->fabrics.fctype == nvme_fabrics_type_connect)
572577
return true;
573-
574-
/*
575-
* If the queue is not live, allow only a connect command. This
576-
* will reject any ioctl admin cmd as well as initialization
577-
* commands if the controller reverted the queue to non-live.
578-
*/
579-
if (!queue_live && blk_rq_is_passthrough(rq) &&
580-
cmd->common.opcode == nvme_fabrics_command &&
581-
cmd->fabrics.fctype == nvme_fabrics_type_connect)
582-
return true;
583-
return false;
578+
break;
584579
default:
580+
break;
581+
case NVME_CTRL_DEAD:
585582
return false;
586583
}
584+
585+
return queue_live;
587586
}
588587
EXPORT_SYMBOL_GPL(__nvmf_check_ready);
589588

0 commit comments

Comments
 (0)