From: james.smart@broadcom.com (James Smart) Date: Tue, 12 Jun 2018 15:05:56 -0700 Subject: [PATCH 4/4] nvme-fabrics: reverse polarity in __nvmf_check_ready In-Reply-To: <20180611154647.32558-5-hch@lst.de> References: <20180611154647.32558-1-hch@lst.de> <20180611154647.32558-5-hch@lst.de> Message-ID: <38afb6b9-2bb2-0d5d-5c8b-9051bc585848@broadcom.com> On 6/11/2018 8:46 AM, Christoph Hellwig wrote: > All non-live, non-dead states have the same command filters. So just > check for the dead state first, and then apply out filters to catch all > other "special" states automatically. > > Signed-off-by: Christoph Hellwig > --- > drivers/nvme/host/fabrics.c | 42 ++++++++++++++----------------------- > 1 file changed, 16 insertions(+), 26 deletions(-) > > diff --git a/drivers/nvme/host/fabrics.c b/drivers/nvme/host/fabrics.c > index 6b4e253b9347..dc87719a5c9e 100644 > --- a/drivers/nvme/host/fabrics.c > +++ b/drivers/nvme/host/fabrics.c > @@ -556,34 +556,24 @@ EXPORT_SYMBOL_GPL(nvmf_fail_nonready_command); > bool __nvmf_check_ready(struct nvme_ctrl *ctrl, struct request *rq, > bool queue_live) > { > - struct nvme_command *cmd = nvme_req(rq)->cmd; > - > - switch (ctrl->state) { > - case NVME_CTRL_NEW: > - case NVME_CTRL_CONNECTING: > - case NVME_CTRL_DELETING: > - /* > - * If queue is live, allow only commands that are internally > - * generated pass through. These are commands on the admin > - * queue to initialize the controller. This will reject any > - * ioctl admin cmds received while initializing. > - */ > - if (queue_live && !(nvme_req(rq)->flags & NVME_REQ_USERCMD)) > - return true; > - > - /* > - * If the queue is not live, allow only a connect command. This > - * will reject any ioctl admin cmd as well as initialization > - * commands if the controller reverted the queue to non-live. > - */ > - if (!queue_live && blk_rq_is_passthrough(rq) && > - cmd->common.opcode == nvme_fabrics_command && > - cmd->fabrics.fctype == nvme_fabrics_type_connect) > - return true; > + if (ctrl->state == NVME_CTRL_DEAD) > return false; > - default: > + > + /* > + * If the queue is not live the only thing allowed is a connect > + * command to actually set the queue live. > + */ > + if (!queue_live && > + (nvme_req(rq)->cmd->common.opcode != nvme_fabrics_command || > + nvme_req(rq)->cmd->fabrics.fctype != nvme_fabrics_type_connect)) > return false; > - } ok - so what still gets through to the next check are cases when queue_live=true is inconsistent with the controller state - e.g. std io or ioctls received while the workqueue item is queued and prior to the transport finally marking the queue not-live somewhere in the workqueue item code flow. > + > + /* > + * If we are in some state of setup or teardown only allow > + * internally generated commands. > + */ > + return blk_rq_is_passthrough(rq) && > + !(nvme_req(rq)->flags & NVME_REQ_USERCMD); > } > EXPORT_SYMBOL_GPL(__nvmf_check_ready); > and this (nice!) second check filters out those standard io's as well as any ioctls, which leaves only those things generated by core that should be for reset or initialization. Looks good. --james Reviewed-by:?? James Smart?