linux-nvme.lists.infradead.org archive mirror
 help / color / mirror / Atom feed
* [PATCH V4 0/3] nvmet: add target ns revalidate support
@ 2020-05-19  8:06 Chaitanya Kulkarni
  2020-05-19  8:06 ` [PATCH V4 1/4] nvmet: add helper to revalidate bdev and file ns Chaitanya Kulkarni
                   ` (4 more replies)
  0 siblings, 5 replies; 10+ messages in thread
From: Chaitanya Kulkarni @ 2020-05-19  8:06 UTC (permalink / raw)
  To: hch, sagi; +Cc: Chaitanya Kulkarni, linux-nvme

Hi Christoph/Sagi,

As per previous discussion on the ns-revalidation thread, this patch
series adds a new per namespace configfs attribute so that AEN check
can be triggered from the userspace with appropriate notification
tool(s).

As always test log at the end for reference.

Regards,
Chaitanya

Changes from V3:-
1. Use if/else than ?: in nvmet_ns_revalidate().
2. Move AEN generation in nvmet_ns_revalidate() into a separate patch
   and add documentation.
3. Rename configfs attribute from "resize_check" to "revalidate_size".
4. Only accept "true" value for "revalidate_size" from #3 otherwise
   return -EINVAL.

Changes from V2:-
1. Move old size check and AEN generation in nvmet_ns_revalidate(), fix
   the correspondig prototypes.
2. Return -EINVAL when ns is not enabled for resize_check attr.
3. Move result calculation into tracing code.

Changes from V1:-
1. Move AEN generation into common helper nvmet_ns_revalidate().
2. Change the calling convention of the nvmet_file_ns_revalidate()
   such that now it will return an error and take the parameter to 
   size_change boolean pointer to indicate a change in the size of
   namespace.
3. Move the result extraction into the tracing code.

Chaitanya Kulkarni (4):
  nvmet: add helper to revalidate bdev and file ns
  nvmet: generate AEN for ns revalidate size change
  nvmet: revalidate-ns & generate AEN from configfs
  nvmet: add async event tracing support

 drivers/nvme/target/admin-cmd.c |  5 +----
 drivers/nvme/target/configfs.c  | 26 ++++++++++++++++++++++++++
 drivers/nvme/target/core.c      | 14 ++++++++++++++
 drivers/nvme/target/nvmet.h     |  1 +
 drivers/nvme/target/trace.h     | 28 ++++++++++++++++++++++++++++
 5 files changed, 70 insertions(+), 4 deletions(-)

-- 
2.22.1


_______________________________________________
linux-nvme mailing list
linux-nvme@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-nvme

^ permalink raw reply	[flat|nested] 10+ messages in thread

* [PATCH V4 1/4] nvmet: add helper to revalidate bdev and file ns
  2020-05-19  8:06 [PATCH V4 0/3] nvmet: add target ns revalidate support Chaitanya Kulkarni
@ 2020-05-19  8:06 ` Chaitanya Kulkarni
  2020-05-19  8:49   ` Sagi Grimberg
  2020-05-19  8:06 ` [PATCH V4 2/4] nvmet: generate AEN for ns revalidate size change Chaitanya Kulkarni
                   ` (3 subsequent siblings)
  4 siblings, 1 reply; 10+ messages in thread
From: Chaitanya Kulkarni @ 2020-05-19  8:06 UTC (permalink / raw)
  To: hch, sagi; +Cc: Chaitanya Kulkarni, linux-nvme

This patch adds a wrapper helper to indicate size change in the bdev &
file-backed namespace when revalidating ns. This helper is needed in
order to minimize code repetition in the next patch for configfs.c and
existing admin-cmd.c.  

Signed-off-by: Chaitanya Kulkarni <chaitanya.kulkarni@wdc.com>
---
 drivers/nvme/target/admin-cmd.c | 5 +----
 drivers/nvme/target/core.c      | 8 ++++++++
 drivers/nvme/target/nvmet.h     | 1 +
 3 files changed, 10 insertions(+), 4 deletions(-)

diff --git a/drivers/nvme/target/admin-cmd.c b/drivers/nvme/target/admin-cmd.c
index 4c79aa804887..f544a14e8b5c 100644
--- a/drivers/nvme/target/admin-cmd.c
+++ b/drivers/nvme/target/admin-cmd.c
@@ -486,10 +486,7 @@ static void nvmet_execute_identify_ns(struct nvmet_req *req)
 	if (!ns)
 		goto done;
 
-	if (ns->bdev)
-		nvmet_bdev_ns_revalidate(ns);
-	else
-		nvmet_file_ns_revalidate(ns);
+	nvmet_ns_revalidate(ns);
 
 	/*
 	 * nuse = ncap = nsze isn't always true, but we have no way to find
diff --git a/drivers/nvme/target/core.c b/drivers/nvme/target/core.c
index b685f99d56a1..86a75c7779d5 100644
--- a/drivers/nvme/target/core.c
+++ b/drivers/nvme/target/core.c
@@ -514,6 +514,14 @@ static void nvmet_p2pmem_ns_add_p2p(struct nvmet_ctrl *ctrl,
 		ns->nsid);
 }
 
+void nvmet_ns_revalidate(struct nvmet_ns *ns)
+{
+	if (ns->bdev)
+		nvmet_bdev_ns_revalidate(ns);
+	else
+		nvmet_file_ns_revalidate(ns);
+}
+
 int nvmet_ns_enable(struct nvmet_ns *ns)
 {
 	struct nvmet_subsys *subsys = ns->subsys;
diff --git a/drivers/nvme/target/nvmet.h b/drivers/nvme/target/nvmet.h
index 3d981eb6e100..93e0c2aa3e71 100644
--- a/drivers/nvme/target/nvmet.h
+++ b/drivers/nvme/target/nvmet.h
@@ -500,6 +500,7 @@ u16 nvmet_file_flush(struct nvmet_req *req);
 void nvmet_ns_changed(struct nvmet_subsys *subsys, u32 nsid);
 void nvmet_bdev_ns_revalidate(struct nvmet_ns *ns);
 int nvmet_file_ns_revalidate(struct nvmet_ns *ns);
+void nvmet_ns_revalidate(struct nvmet_ns *ns);
 
 static inline u32 nvmet_rw_len(struct nvmet_req *req)
 {
-- 
2.22.1


_______________________________________________
linux-nvme mailing list
linux-nvme@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-nvme

^ permalink raw reply related	[flat|nested] 10+ messages in thread

* [PATCH V4 2/4] nvmet: generate AEN for ns revalidate size change
  2020-05-19  8:06 [PATCH V4 0/3] nvmet: add target ns revalidate support Chaitanya Kulkarni
  2020-05-19  8:06 ` [PATCH V4 1/4] nvmet: add helper to revalidate bdev and file ns Chaitanya Kulkarni
@ 2020-05-19  8:06 ` Chaitanya Kulkarni
  2020-05-19  8:57   ` Sagi Grimberg
  2020-05-19  8:06 ` [PATCH V4 3/4] nvmet: revalidate-ns & generate AEN from configfs Chaitanya Kulkarni
                   ` (2 subsequent siblings)
  4 siblings, 1 reply; 10+ messages in thread
From: Chaitanya Kulkarni @ 2020-05-19  8:06 UTC (permalink / raw)
  To: hch, sagi; +Cc: Chaitanya Kulkarni, linux-nvme

The newly added function nvmet_ns_revalidate() does update the ns size
in the identify namespace in-core target data structure when host issues
id-ns command. This can lead to host having inconsistencies between size
of the namespace present in the id-ns command result and size of the
corresponding block device until host scans the namespaces explicitly.

To avoid this scenario generate AEN if old size is not same as the new
one in nvmet_ns_revalidate().

This will allow automatic AEN generation when host calls id-ns command
and also allows target to install userspace rules so that it can trigger
nvmet_ns_revalidate() (using configfs interface with the help of next
patch) resulting in appropriate AEN generation when underlying namespace
size change is detected.

Signed-off-by: Chaitanya Kulkarni <chaitanya.kulkarni@wdc.com>
---
 drivers/nvme/target/core.c | 5 +++++
 1 file changed, 5 insertions(+)

diff --git a/drivers/nvme/target/core.c b/drivers/nvme/target/core.c
index 86a75c7779d5..fa1f79b3fde3 100644
--- a/drivers/nvme/target/core.c
+++ b/drivers/nvme/target/core.c
@@ -516,10 +516,15 @@ static void nvmet_p2pmem_ns_add_p2p(struct nvmet_ctrl *ctrl,
 
 void nvmet_ns_revalidate(struct nvmet_ns *ns)
 {
+	loff_t oldsize = ns->size;
+
 	if (ns->bdev)
 		nvmet_bdev_ns_revalidate(ns);
 	else
 		nvmet_file_ns_revalidate(ns);
+
+	if (oldsize != ns->size)
+		nvmet_ns_changed(ns->subsys, ns->nsid);
 }
 
 int nvmet_ns_enable(struct nvmet_ns *ns)
-- 
2.22.1


_______________________________________________
linux-nvme mailing list
linux-nvme@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-nvme

^ permalink raw reply related	[flat|nested] 10+ messages in thread

* [PATCH V4 3/4] nvmet: revalidate-ns & generate AEN from configfs
  2020-05-19  8:06 [PATCH V4 0/3] nvmet: add target ns revalidate support Chaitanya Kulkarni
  2020-05-19  8:06 ` [PATCH V4 1/4] nvmet: add helper to revalidate bdev and file ns Chaitanya Kulkarni
  2020-05-19  8:06 ` [PATCH V4 2/4] nvmet: generate AEN for ns revalidate size change Chaitanya Kulkarni
@ 2020-05-19  8:06 ` Chaitanya Kulkarni
  2020-05-19  8:57   ` Sagi Grimberg
  2020-05-19  8:06 ` [PATCH V4 4/4] nvmet: add async event tracing support Chaitanya Kulkarni
  2020-05-20 17:12 ` [PATCH V4 0/3] nvmet: add target ns revalidate support Christoph Hellwig
  4 siblings, 1 reply; 10+ messages in thread
From: Chaitanya Kulkarni @ 2020-05-19  8:06 UTC (permalink / raw)
  To: hch, sagi; +Cc: Chaitanya Kulkarni, linux-nvme

Add a new attribute "revalidate_size" for the namespace which allows
user to revalidate and generate the AEN if needed. This attribute is
needed so that we can install userspace rules with systemd service based
on inotify/fsnotify/uevent. The registered callback for such a service
will end up writing to this attribute to generate AEN if needed.

Signed-off-by: Chaitanya Kulkarni <chaitanya.kulkarni@wdc.com>
---
 drivers/nvme/target/configfs.c | 26 ++++++++++++++++++++++++++
 1 file changed, 26 insertions(+)

diff --git a/drivers/nvme/target/configfs.c b/drivers/nvme/target/configfs.c
index 24eb4cf53b4f..17c529260e12 100644
--- a/drivers/nvme/target/configfs.c
+++ b/drivers/nvme/target/configfs.c
@@ -540,6 +540,31 @@ static ssize_t nvmet_ns_buffered_io_store(struct config_item *item,
 
 CONFIGFS_ATTR(nvmet_ns_, buffered_io);
 
+static ssize_t nvmet_ns_revalidate_size_store(struct config_item *item,
+		const char *page, size_t count)
+{
+	struct nvmet_ns *ns = to_nvmet_ns(item);
+	bool val;
+
+	if (strtobool(page, &val))
+		return -EINVAL;
+
+	if (!val)
+		return -EINVAL;
+
+	mutex_lock(&ns->subsys->lock);
+	if (!ns->enabled) {
+		pr_err("enable ns before revalidate.\n");
+		mutex_unlock(&ns->subsys->lock);
+		return -EINVAL;
+	}
+	nvmet_ns_revalidate(ns);
+	mutex_unlock(&ns->subsys->lock);
+	return count;
+}
+
+CONFIGFS_ATTR_WO(nvmet_ns_, revalidate_size);
+
 static struct configfs_attribute *nvmet_ns_attrs[] = {
 	&nvmet_ns_attr_device_path,
 	&nvmet_ns_attr_device_nguid,
@@ -547,6 +572,7 @@ static struct configfs_attribute *nvmet_ns_attrs[] = {
 	&nvmet_ns_attr_ana_grpid,
 	&nvmet_ns_attr_enable,
 	&nvmet_ns_attr_buffered_io,
+	&nvmet_ns_attr_revalidate_size,
 #ifdef CONFIG_PCI_P2PDMA
 	&nvmet_ns_attr_p2pmem,
 #endif
-- 
2.22.1


_______________________________________________
linux-nvme mailing list
linux-nvme@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-nvme

^ permalink raw reply related	[flat|nested] 10+ messages in thread

* [PATCH V4 4/4] nvmet: add async event tracing support
  2020-05-19  8:06 [PATCH V4 0/3] nvmet: add target ns revalidate support Chaitanya Kulkarni
                   ` (2 preceding siblings ...)
  2020-05-19  8:06 ` [PATCH V4 3/4] nvmet: revalidate-ns & generate AEN from configfs Chaitanya Kulkarni
@ 2020-05-19  8:06 ` Chaitanya Kulkarni
  2020-05-19  8:57   ` Sagi Grimberg
  2020-05-20 17:12 ` [PATCH V4 0/3] nvmet: add target ns revalidate support Christoph Hellwig
  4 siblings, 1 reply; 10+ messages in thread
From: Chaitanya Kulkarni @ 2020-05-19  8:06 UTC (permalink / raw)
  To: hch, sagi; +Cc: Chaitanya Kulkarni, linux-nvme

This adds a new tracepoint for the target to trace async event. This is
helpful in debugging and comparing host and target side async events
especially when host is connected to different targets on different
machines and now that we rely on userspace components to generate AEN. 

Signed-off-by: Chaitanya Kulkarni <chaitanya.kulkarni@wdc.com>
Reviewed-by: Christoph Hellwig <hch@lst.de>
Reviewed-by: Sagi Grimberg <sagi@grimberg.me>
---
 drivers/nvme/target/core.c  |  1 +
 drivers/nvme/target/trace.h | 28 ++++++++++++++++++++++++++++
 2 files changed, 29 insertions(+)

diff --git a/drivers/nvme/target/core.c b/drivers/nvme/target/core.c
index fa1f79b3fde3..fb78b165c123 100644
--- a/drivers/nvme/target/core.c
+++ b/drivers/nvme/target/core.c
@@ -151,6 +151,7 @@ static void nvmet_async_events_process(struct nvmet_ctrl *ctrl, u16 status)
 		kfree(aen);
 
 		mutex_unlock(&ctrl->lock);
+		trace_nvmet_async_event(ctrl, req->cqe->result.u32);
 		nvmet_req_complete(req, status);
 	}
 }
diff --git a/drivers/nvme/target/trace.h b/drivers/nvme/target/trace.h
index e645caa882dd..0458046d6501 100644
--- a/drivers/nvme/target/trace.h
+++ b/drivers/nvme/target/trace.h
@@ -130,6 +130,34 @@ TRACE_EVENT(nvmet_req_complete,
 
 );
 
+#define aer_name(aer) { aer, #aer }
+
+TRACE_EVENT(nvmet_async_event,
+	TP_PROTO(struct nvmet_ctrl *ctrl, __le32 result),
+	TP_ARGS(ctrl, result),
+	TP_STRUCT__entry(
+		__field(int, ctrl_id)
+		__field(u32, result)
+	),
+	TP_fast_assign(
+		__entry->ctrl_id = ctrl->cntlid;
+		__entry->result = (le32_to_cpu(result) & 0xff00) >> 8;
+	),
+	TP_printk("nvmet%d: NVME_AEN=%#08x [%s]",
+		__entry->ctrl_id, __entry->result,
+		__print_symbolic(__entry->result,
+		aer_name(NVME_AER_NOTICE_NS_CHANGED),
+		aer_name(NVME_AER_NOTICE_ANA),
+		aer_name(NVME_AER_NOTICE_FW_ACT_STARTING),
+		aer_name(NVME_AER_NOTICE_DISC_CHANGED),
+		aer_name(NVME_AER_ERROR),
+		aer_name(NVME_AER_SMART),
+		aer_name(NVME_AER_CSS),
+		aer_name(NVME_AER_VS))
+	)
+);
+#undef aer_name
+
 #endif /* _TRACE_NVMET_H */
 
 #undef TRACE_INCLUDE_PATH
-- 
2.22.1


_______________________________________________
linux-nvme mailing list
linux-nvme@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-nvme

^ permalink raw reply related	[flat|nested] 10+ messages in thread

* Re: [PATCH V4 1/4] nvmet: add helper to revalidate bdev and file ns
  2020-05-19  8:06 ` [PATCH V4 1/4] nvmet: add helper to revalidate bdev and file ns Chaitanya Kulkarni
@ 2020-05-19  8:49   ` Sagi Grimberg
  0 siblings, 0 replies; 10+ messages in thread
From: Sagi Grimberg @ 2020-05-19  8:49 UTC (permalink / raw)
  To: Chaitanya Kulkarni, hch; +Cc: linux-nvme

Reviewed-by: Sagi Grimberg <sagi@grimbeg.me>

_______________________________________________
linux-nvme mailing list
linux-nvme@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-nvme

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [PATCH V4 2/4] nvmet: generate AEN for ns revalidate size change
  2020-05-19  8:06 ` [PATCH V4 2/4] nvmet: generate AEN for ns revalidate size change Chaitanya Kulkarni
@ 2020-05-19  8:57   ` Sagi Grimberg
  0 siblings, 0 replies; 10+ messages in thread
From: Sagi Grimberg @ 2020-05-19  8:57 UTC (permalink / raw)
  To: Chaitanya Kulkarni, hch; +Cc: linux-nvme

Reviewed-by: Sagi Grimberg <sagi@grimberg.me>

_______________________________________________
linux-nvme mailing list
linux-nvme@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-nvme

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [PATCH V4 3/4] nvmet: revalidate-ns & generate AEN from configfs
  2020-05-19  8:06 ` [PATCH V4 3/4] nvmet: revalidate-ns & generate AEN from configfs Chaitanya Kulkarni
@ 2020-05-19  8:57   ` Sagi Grimberg
  0 siblings, 0 replies; 10+ messages in thread
From: Sagi Grimberg @ 2020-05-19  8:57 UTC (permalink / raw)
  To: Chaitanya Kulkarni, hch; +Cc: linux-nvme

Reviewed-by: Sagi Grimberg <sagi@grimberg.me>

_______________________________________________
linux-nvme mailing list
linux-nvme@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-nvme

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [PATCH V4 4/4] nvmet: add async event tracing support
  2020-05-19  8:06 ` [PATCH V4 4/4] nvmet: add async event tracing support Chaitanya Kulkarni
@ 2020-05-19  8:57   ` Sagi Grimberg
  0 siblings, 0 replies; 10+ messages in thread
From: Sagi Grimberg @ 2020-05-19  8:57 UTC (permalink / raw)
  To: Chaitanya Kulkarni, hch; +Cc: linux-nvme

Reviwed-by: Sagi Grimberg <sagi@grimberg.me>

_______________________________________________
linux-nvme mailing list
linux-nvme@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-nvme

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [PATCH V4 0/3] nvmet: add target ns revalidate support
  2020-05-19  8:06 [PATCH V4 0/3] nvmet: add target ns revalidate support Chaitanya Kulkarni
                   ` (3 preceding siblings ...)
  2020-05-19  8:06 ` [PATCH V4 4/4] nvmet: add async event tracing support Chaitanya Kulkarni
@ 2020-05-20 17:12 ` Christoph Hellwig
  4 siblings, 0 replies; 10+ messages in thread
From: Christoph Hellwig @ 2020-05-20 17:12 UTC (permalink / raw)
  To: Chaitanya Kulkarni; +Cc: hch, linux-nvme, sagi

Thanks,

applied to nvme-5.8.

_______________________________________________
linux-nvme mailing list
linux-nvme@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-nvme

^ permalink raw reply	[flat|nested] 10+ messages in thread

end of thread, other threads:[~2020-05-20 17:13 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-05-19  8:06 [PATCH V4 0/3] nvmet: add target ns revalidate support Chaitanya Kulkarni
2020-05-19  8:06 ` [PATCH V4 1/4] nvmet: add helper to revalidate bdev and file ns Chaitanya Kulkarni
2020-05-19  8:49   ` Sagi Grimberg
2020-05-19  8:06 ` [PATCH V4 2/4] nvmet: generate AEN for ns revalidate size change Chaitanya Kulkarni
2020-05-19  8:57   ` Sagi Grimberg
2020-05-19  8:06 ` [PATCH V4 3/4] nvmet: revalidate-ns & generate AEN from configfs Chaitanya Kulkarni
2020-05-19  8:57   ` Sagi Grimberg
2020-05-19  8:06 ` [PATCH V4 4/4] nvmet: add async event tracing support Chaitanya Kulkarni
2020-05-19  8:57   ` Sagi Grimberg
2020-05-20 17:12 ` [PATCH V4 0/3] nvmet: add target ns revalidate support Christoph Hellwig

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).