public inbox for linux-nvme@lists.infradead.org
 help / color / mirror / Atom feed
From: Sagi Grimberg <sagi@grimberg.me>
To: Jeremy Allison <jallison@ciq.com>,
	jra@samba.org, tansuresh@google.com, hch@lst.de,
	gregkh@linuxfoundation.org, rafael@kernel.org,
	bhelgaas@google.com
Cc: linux-nvme@lists.infradead.org
Subject: Re: [PATCH 3/5] nvme: Change 'bool shutdown' into an enum shutdown_type.
Date: Thu, 4 Jan 2024 15:26:11 +0200	[thread overview]
Message-ID: <4486c671-af66-4466-bfca-e184584d884b@grimberg.me> (raw)
In-Reply-To: <20240103210405.3593499-4-jallison@ciq.com>



On 1/3/24 23:04, Jeremy Allison wrote:
> Convert nvme_disable_ctrl() and nvme_dev_disable()
> inside drivers/nvme/host/pci.c to use this:
> 
> bool shutdown = false == NVME_DISABLE_RESET
> bool shutdown = true == NVME_DISABLE_SHUTDOWN_SYNC.
> 
> This will make it easier to add a third request later:
> NVME_DISABLE_SHUTDOWN_ASNYC
> 
> As nvme_disable_ctrl() is used outside of drivers/nvme/host/pci.c,
> convert the callers of nvme_disable_ctrl() to this convention too.
> 
> Signed-off-by: Jeremy Allison <jallison@ciq.com>
> ---
>   drivers/nvme/host/apple.c  |  4 ++--
>   drivers/nvme/host/core.c   |  6 +++---
>   drivers/nvme/host/nvme.h   |  7 +++++-
>   drivers/nvme/host/pci.c    | 44 +++++++++++++++++++-------------------
>   drivers/nvme/host/rdma.c   |  3 ++-
>   drivers/nvme/host/tcp.c    |  3 ++-
>   drivers/nvme/target/loop.c |  2 +-
>   7 files changed, 38 insertions(+), 31 deletions(-)
> 
> diff --git a/drivers/nvme/host/apple.c b/drivers/nvme/host/apple.c
> index 596bb11eeba5..764639ede41d 100644
> --- a/drivers/nvme/host/apple.c
> +++ b/drivers/nvme/host/apple.c
> @@ -844,8 +844,8 @@ static void apple_nvme_disable(struct apple_nvme *anv, bool shutdown)
>   		 * NVMe disabled state, after a clean shutdown).
>   		 */
>   		if (shutdown)
> -			nvme_disable_ctrl(&anv->ctrl, shutdown);
> -		nvme_disable_ctrl(&anv->ctrl, false);
> +			nvme_disable_ctrl(&anv->ctrl, NVME_DISABLE_SHUTDOWN_SYNC);
> +		nvme_disable_ctrl(&anv->ctrl, NVME_DISABLE_RESET);
>   	}
>   
>   	WRITE_ONCE(anv->ioq.enabled, false);
> diff --git a/drivers/nvme/host/core.c b/drivers/nvme/host/core.c
> index 50818dbcfa1a..e1b2facb7d6a 100644
> --- a/drivers/nvme/host/core.c
> +++ b/drivers/nvme/host/core.c
> @@ -2219,12 +2219,12 @@ static int nvme_wait_ready(struct nvme_ctrl *ctrl, u32 mask, u32 val,
>   	return ret;
>   }
>   
> -int nvme_disable_ctrl(struct nvme_ctrl *ctrl, bool shutdown)
> +int nvme_disable_ctrl(struct nvme_ctrl *ctrl, enum shutdown_type shutdown_type)
>   {
>   	int ret;
>   
>   	ctrl->ctrl_config &= ~NVME_CC_SHN_MASK;
> -	if (shutdown)
> +	if (shutdown_type == NVME_DISABLE_SHUTDOWN_SYNC)
>   		ctrl->ctrl_config |= NVME_CC_SHN_NORMAL;
>   	else
>   		ctrl->ctrl_config &= ~NVME_CC_ENABLE;
> @@ -2233,7 +2233,7 @@ int nvme_disable_ctrl(struct nvme_ctrl *ctrl, bool shutdown)
>   	if (ret)
>   		return ret;
>   
> -	if (shutdown) {
> +	if (shutdown_type == NVME_DISABLE_SHUTDOWN_SYNC) {
>   		return nvme_wait_ready(ctrl, NVME_CSTS_SHST_MASK,
>   				       NVME_CSTS_SHST_CMPLT,
>   				       ctrl->shutdown_timeout, "shutdown");
> diff --git a/drivers/nvme/host/nvme.h b/drivers/nvme/host/nvme.h
> index 6092cc361837..1a748640f2fb 100644
> --- a/drivers/nvme/host/nvme.h
> +++ b/drivers/nvme/host/nvme.h
> @@ -187,6 +187,11 @@ enum {
>   	NVME_MPATH_IO_STATS		= (1 << 2),
>   };
>   
> +enum shutdown_type {
> +	NVME_DISABLE_RESET = 0,
> +	NVME_DISABLE_SHUTDOWN_SYNC = 1
> +};

I also don't find this a bit awkward especially when another
enumeration value is added later on.

An alternative approach would be to stick with nvme_disable_ctrl that
accepts shutdown bool, and add nvme_disable_ctrl_nowait() wrapper for it
that call-sites can use. Or even better, because we only have a nowait
variant for shutdown, perhaps we can add nvme_shutdown_ctrl_nowait()
wrapper that accepts only the ctrl instead (this will require splitting
nvme_disable_ctrl to the disabling phase and the waiting phase, but that
is hidden in the core as static functions).


  reply	other threads:[~2024-01-04 13:26 UTC|newest]

Thread overview: 20+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-01-03 21:04 Make NVME shutdown two-pass - Version 4 Jeremy Allison
2024-01-03 21:04 ` [PATCH 1/5] driver core: Support two-pass driver shutdown Jeremy Allison
2024-01-04 13:12   ` Sagi Grimberg
2024-01-04 17:27     ` Jeremy Allison
2024-01-03 21:04 ` [PATCH 2/5] PCI: Support two-pass shutdown Jeremy Allison
2024-01-04 18:55   ` Bjorn Helgaas
2024-01-04 19:34     ` Jeremy Allison
2024-01-03 21:04 ` [PATCH 3/5] nvme: Change 'bool shutdown' into an enum shutdown_type Jeremy Allison
2024-01-04 13:26   ` Sagi Grimberg [this message]
2024-01-04 17:43     ` Jeremy Allison
2024-01-04 18:44       ` Jeremy Allison
2024-01-08 17:42         ` Sagi Grimberg
2024-01-08 18:41           ` Jeremy Allison
2024-01-03 21:04 ` [PATCH 4/5] nvme: Export nvme_wait_ready() Jeremy Allison
2024-01-03 21:04 ` [PATCH 5/5] nvme: Add two-pass shutdown support Jeremy Allison
2024-01-04 13:14   ` Sagi Grimberg
2024-01-04 17:30     ` Jeremy Allison
2024-01-04  4:48 ` Make NVME shutdown two-pass - Version 4 Chaitanya Kulkarni
2024-01-04  6:38   ` Jeremy Allison
2024-01-04 19:00 ` Keith Busch

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=4486c671-af66-4466-bfca-e184584d884b@grimberg.me \
    --to=sagi@grimberg.me \
    --cc=bhelgaas@google.com \
    --cc=gregkh@linuxfoundation.org \
    --cc=hch@lst.de \
    --cc=jallison@ciq.com \
    --cc=jra@samba.org \
    --cc=linux-nvme@lists.infradead.org \
    --cc=rafael@kernel.org \
    --cc=tansuresh@google.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox