All of lore.kernel.org
 help / color / mirror / Atom feed
From: Vishal Verma <vishal.l.verma@intel.com>
To: linux-nvdimm@lists.01.org
Cc: Marek de Rosier <marekx.de.rosier@intel.com>
Subject: [ndctl PATCH] libndctl/inject: Refuse error injection for BTT namespaces
Date: Fri, 14 Jun 2019 12:52:22 -0600	[thread overview]
Message-ID: <20190614185222.30068-1-vishal.l.verma@intel.com> (raw)

Error injection on a BTT namespace would treat the namespace as 'raw'
for the purposes of the injection. This can be useful for development,
but to a user this can be surprising, as injecting with --block=1 would
corrupt the BTT info block, and the BTT would be lost.

The unit tests do not rely on injecting errors directly into a BTT
namespace - they convert the namespace to 'raw' mode before performing
such an injection. For development and testing purposes, we will still
retain this ability by enforcing that the BTT namespace be explicitly
forced into raw mode before injection.

Reported-by: Marek de Rosier <marekx.de.rosier@intel.com>
Reported-by: Dan Williams <dan.j.williams@intel.com>
Signed-off-by: Vishal Verma <vishal.l.verma@intel.com>
---
 ndctl/lib/inject.c | 33 ++++++++++++++++++++++++---------
 1 file changed, 24 insertions(+), 9 deletions(-)

diff --git a/ndctl/lib/inject.c b/ndctl/lib/inject.c
index c35d0f3..815f254 100644
--- a/ndctl/lib/inject.c
+++ b/ndctl/lib/inject.c
@@ -34,28 +34,36 @@ NDCTL_EXPORT int ndctl_bus_has_error_injection(struct ndctl_bus *bus)
 	return 0;
 }
 
-static void ndctl_namespace_get_injection_bounds(
+static int ndctl_namespace_get_injection_bounds(
 		struct ndctl_namespace *ndns, unsigned long long *ns_offset,
 		unsigned long long *ns_size)
 {
 	struct ndctl_pfn *pfn = ndctl_namespace_get_pfn(ndns);
 	struct ndctl_dax *dax = ndctl_namespace_get_dax(ndns);
+	struct ndctl_btt *btt = ndctl_namespace_get_btt(ndns);
 
 	if (!ns_offset || !ns_size)
-		return;
+		return -ENXIO;
 
 	if (pfn) {
 		*ns_offset = ndctl_pfn_get_resource(pfn);
 		*ns_size = ndctl_pfn_get_size(pfn);
-		return;
-	} else if (dax) {
+		return 0;
+	}
+
+	if (dax) {
 		*ns_offset = ndctl_dax_get_resource(dax);
 		*ns_size = ndctl_dax_get_size(dax);
-		return;
+		return 0;
 	}
-	/* raw or btt */
+
+	if (btt)
+		return -EOPNOTSUPP;
+
+	/* raw */
 	*ns_offset = ndctl_namespace_get_resource(ndns);
 	*ns_size = ndctl_namespace_get_size(ndns);
+	return 0;
 }
 
 static int block_to_spa_offset(struct ndctl_namespace *ndns,
@@ -64,8 +72,11 @@ static int block_to_spa_offset(struct ndctl_namespace *ndns,
 {
 	struct ndctl_ctx *ctx = ndctl_namespace_get_ctx(ndns);
 	unsigned long long ns_offset, ns_size;
+	int rc;
 
-	ndctl_namespace_get_injection_bounds(ndns, &ns_offset, &ns_size);
+	rc = ndctl_namespace_get_injection_bounds(ndns, &ns_offset, &ns_size);
+	if (rc)
+		return rc;
 	*offset = ns_offset + block * 512;
 	*length = count * 512;
 
@@ -98,8 +109,10 @@ static int ndctl_namespace_get_clear_unit(struct ndctl_namespace *ndns)
 	struct ndctl_cmd *cmd;
 	int rc;
 
-	ndctl_namespace_get_injection_bounds(ndns, &ns_offset,
+	rc = ndctl_namespace_get_injection_bounds(ndns, &ns_offset,
 		&ns_size);
+	if (rc)
+		return rc;
 	cmd = ndctl_bus_cmd_new_ars_cap(bus, ns_offset, ns_size);
 	rc = ndctl_cmd_submit(cmd);
 	if (rc < 0) {
@@ -438,8 +451,10 @@ NDCTL_EXPORT int ndctl_namespace_injection_status(struct ndctl_namespace *ndns)
 		return -EOPNOTSUPP;
 
 	if (ndctl_bus_has_nfit(bus)) {
-		ndctl_namespace_get_injection_bounds(ndns, &ns_offset,
+		rc = ndctl_namespace_get_injection_bounds(ndns, &ns_offset,
 			&ns_size);
+		if (rc)
+			return rc;
 
 		cmd = ndctl_bus_cmd_new_ars_cap(bus, ns_offset, ns_size);
 		rc = ndctl_cmd_submit(cmd);
-- 
2.20.1

_______________________________________________
Linux-nvdimm mailing list
Linux-nvdimm@lists.01.org
https://lists.01.org/mailman/listinfo/linux-nvdimm

             reply	other threads:[~2019-06-14 18:52 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-06-14 18:52 Vishal Verma [this message]
2019-06-14 19:52 ` [ndctl PATCH] libndctl/inject: Refuse error injection for BTT namespaces Dan Williams

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=20190614185222.30068-1-vishal.l.verma@intel.com \
    --to=vishal.l.verma@intel.com \
    --cc=linux-nvdimm@lists.01.org \
    --cc=marekx.de.rosier@intel.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.