Re: [PATCHv2 4/6] nvme: Introduce nvme_reset_continue

Christoph Hellwig
2019-09-27T21:37:21Z

On Fri, Sep 20, 2019 at 06:34:29AM +0900, kbusch@kernel.org wrote:
> From: Keith Busch <kbusch@kernel.org>
>
> There are times we need to reset the controller in two parts where the
> initialization happens in a different context than the disabling. We need
> to be able to set the state to RESETTING first in order to prevent another
> reset from scheduling while performing a critical section that handles
> the disable part. Introduce a new helpwer function, nvme_reset_continue()
> that can be called from such contexts after they've set the controller
> state to RESETTING.
>
> Signed-off-by: Keith Busch <kbusch@kernel.org>
> ---
> drivers/nvme/host/core.c | 12 ++++++++++--
> drivers/nvme/host/nvme.h | 1 +
> 2 files changed, 11 insertions(+), 2 deletions(-)
>
> diff --git a/drivers/nvme/host/core.c b/drivers/nvme/host/core.c
> index e03b1765fc01..95b74d020506 100644
> --- a/drivers/nvme/host/core.c
> +++ b/drivers/nvme/host/core.c
> @@ -117,14 +117,22 @@ static void nvme_queue_scan(struct nvme_ctrl *ctrl)
> queue_work(nvme_wq, &ctrl->scan_work);
> }
>
> -int nvme_reset_ctrl(struct nvme_ctrl *ctrl)
> +int nvme_reset_continue(struct nvme_ctrl *ctrl)
> {
> - if (!nvme_change_ctrl_state(ctrl, NVME_CTRL_RESETTING))
> + if (ctrl->state != NVME_CTRL_RESETTING)
> return -EBUSY;
> if (!queue_work(nvme_reset_wq, &ctrl->reset_work))
> return -EBUSY;
> return 0;
> }
> +EXPORT_SYMBOL_GPL(nvme_reset_continue);
> +
> +int nvme_reset_ctrl(struct nvme_ctrl *ctrl)
> +{
> + if (!nvme_change_ctrl_state(ctrl, NVME_CTRL_RESETTING))
> + return -EBUSY;
> + return nvme_reset_continue(ctrl);
> +}
> EXPORT_SYMBOL_GPL(nvme_reset_ctrl);

I'd prefer to still open code the queue_work in nvme_reset_ctrl.
It is one extra line but a little easier to read.