public inbox for linux-nvme@lists.infradead.org
 help / color / mirror / Atom feed
From: Guixin Liu <kanie@linux.alibaba.com>
To: hch@lst.de, sagi@grimberg.me, kch@nvidia.com, chaitanyak@nvidia.com
Cc: linux-nvme@lists.infradead.org
Subject: [PATCH V2 3/3] nvme: introduce pr_work to handle resv event
Date: Sun, 14 Jan 2024 17:23:14 +0800	[thread overview]
Message-ID: <20240114092314.63694-4-kanie@linux.alibaba.com> (raw)
In-Reply-To: <20240114092314.63694-1-kanie@linux.alibaba.com>

When a reservation event is reported, the corresponding log page is
already on the target side, and the host side needs to send a get
log command to clear these log pages.

Signed-off-by: Guixin Liu <kanie@linux.alibaba.com>
---
 drivers/nvme/host/core.c | 47 +++++++++++++++++++++++++++++++++++++++-
 drivers/nvme/host/nvme.h |  1 +
 2 files changed, 47 insertions(+), 1 deletion(-)

diff --git a/drivers/nvme/host/core.c b/drivers/nvme/host/core.c
index 60f14019f981..a906aea2f4a8 100644
--- a/drivers/nvme/host/core.c
+++ b/drivers/nvme/host/core.c
@@ -4220,6 +4220,47 @@ static void nvme_handle_aer_persistent_error(struct nvme_ctrl *ctrl)
 	nvme_reset_ctrl(ctrl);
 }
 
+static void nvme_queue_pr(struct nvme_ctrl *ctrl)
+{
+	if (nvme_ctrl_state(ctrl) == NVME_CTRL_LIVE)
+		queue_work(nvme_wq, &ctrl->pr_work);
+}
+
+static void nvme_pr_work(struct work_struct *work)
+{
+	struct nvme_ctrl *ctrl = container_of(work, struct nvme_ctrl, pr_work);
+	struct nvme_pr_log log = { 0 };
+	int error;
+
+	if (nvme_ctrl_state(ctrl) != NVME_CTRL_LIVE)
+		return;
+
+	error = nvme_get_log(ctrl, NVME_NSID_ALL, NVME_LOG_RESERVATION, 0,
+			NVME_CSI_NVM, &log, sizeof(log), 0);
+	if (error) {
+		dev_warn(ctrl->device,
+			 "reading reservation log failed: %d\n", error);
+		return;
+	}
+
+	if (log.nr_avl_pages)
+		nvme_queue_pr(ctrl);
+}
+
+static void nvme_handle_aen_css(struct nvme_ctrl *ctrl, u32 result)
+{
+	u32 aer_css_type = nvme_aer_subtype(result);
+
+	switch (aer_css_type) {
+	case NVME_AEN_RESV_LOG_PAGE_AVALIABLE:
+		nvme_queue_pr(ctrl);
+		break;
+	default:
+		ctrl->aen_result = result;
+		dev_warn(ctrl->device, "async event result %08x\n", result);
+	}
+}
+
 void nvme_complete_async_event(struct nvme_ctrl *ctrl, __le16 status,
 		volatile union nvme_result *res)
 {
@@ -4236,6 +4277,9 @@ void nvme_complete_async_event(struct nvme_ctrl *ctrl, __le16 status,
 	case NVME_AER_NOTICE:
 		requeue = nvme_handle_aen_notice(ctrl, result);
 		break;
+	case NVME_AER_CSS:
+		nvme_handle_aen_css(ctrl, result);
+		break;
 	case NVME_AER_ERROR:
 		/*
 		 * For a persistent internal error, don't run async_event_work
@@ -4247,7 +4291,6 @@ void nvme_complete_async_event(struct nvme_ctrl *ctrl, __le16 status,
 		}
 		fallthrough;
 	case NVME_AER_SMART:
-	case NVME_AER_CSS:
 	case NVME_AER_VS:
 		ctrl->aen_result = result;
 		break;
@@ -4389,6 +4432,7 @@ void nvme_stop_ctrl(struct nvme_ctrl *ctrl)
 	nvme_stop_keep_alive(ctrl);
 	nvme_stop_failfast_work(ctrl);
 	flush_work(&ctrl->async_event_work);
+	flush_work(&ctrl->pr_work);
 	cancel_work_sync(&ctrl->fw_act_work);
 	if (ctrl->ops->stop_ctrl)
 		ctrl->ops->stop_ctrl(ctrl);
@@ -4494,6 +4538,7 @@ int nvme_init_ctrl(struct nvme_ctrl *ctrl, struct device *dev,
 	ctrl->quirks = quirks;
 	ctrl->numa_node = NUMA_NO_NODE;
 	INIT_WORK(&ctrl->scan_work, nvme_scan_work);
+	INIT_WORK(&ctrl->pr_work, nvme_pr_work);
 	INIT_WORK(&ctrl->async_event_work, nvme_async_event_work);
 	INIT_WORK(&ctrl->fw_act_work, nvme_fw_act_work);
 	INIT_WORK(&ctrl->delete_work, nvme_delete_ctrl_work);
diff --git a/drivers/nvme/host/nvme.h b/drivers/nvme/host/nvme.h
index e7411dac00f7..6ea4552c4de3 100644
--- a/drivers/nvme/host/nvme.h
+++ b/drivers/nvme/host/nvme.h
@@ -334,6 +334,7 @@ struct nvme_ctrl {
 	struct nvme_effects_log *effects;
 	struct xarray cels;
 	struct work_struct scan_work;
+	struct work_struct pr_work;
 	struct work_struct async_event_work;
 	struct delayed_work ka_work;
 	struct delayed_work failfast_work;
-- 
2.43.0



  parent reply	other threads:[~2024-01-14  9:23 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-01-14  9:23 [PATCH V2 0/3] *** Implement the NVMe reservation feature *** Guixin Liu
2024-01-14  9:23 ` [PATCH V2 1/3] nvmet: support reservation feature Guixin Liu
2024-01-15  9:26   ` Sagi Grimberg
2024-01-16  2:16     ` Guixin Liu
2024-01-14  9:23 ` [PATCH V2 2/3] nvmet: unify aer type enum Guixin Liu
2024-01-15  9:03   ` Sagi Grimberg
2024-01-14  9:23 ` Guixin Liu [this message]
2024-01-15  8:59   ` [PATCH V2 3/3] nvme: introduce pr_work to handle resv event Sagi Grimberg
2024-01-16  2:02     ` Guixin Liu
2024-01-16  7:59       ` Sagi Grimberg
2024-01-16  9:57         ` Guixin Liu
2024-01-15  9:51 ` [PATCH V2 0/3] *** Implement the NVMe reservation feature *** Sagi Grimberg
2024-01-16  2:29   ` Guixin Liu

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=20240114092314.63694-4-kanie@linux.alibaba.com \
    --to=kanie@linux.alibaba.com \
    --cc=chaitanyak@nvidia.com \
    --cc=hch@lst.de \
    --cc=kch@nvidia.com \
    --cc=linux-nvme@lists.infradead.org \
    --cc=sagi@grimberg.me \
    /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