Linux-NVDIMM Archive on lore.kernel.org
 help / color / mirror / Atom feed
* [ndctl PATCH] ndctl, check: Add a sigbus handler to detect metadata corruption
@ 2017-04-14  0:02 Vishal Verma
  2017-04-14  0:10 ` Rudoff, Andy
  2017-04-17 15:37 ` Jeff Moyer
  0 siblings, 2 replies; 11+ messages in thread
From: Vishal Verma @ 2017-04-14  0:02 UTC (permalink / raw)
  To: linux-nvdimm

If we have poison/badblocks in the BTT metadata sections, the mmap-reads
happening in the checker will trigger a SIGBUS, and the program will
halt abruptly. Add a sigbus handler which notifies the user of this, and
prints out a relevant error message:

  namespace5.0: namespace_check: checking namespace5.0
  namespace5.0: btt_discover_arenas: found 1 BTT arena
  namespace5.0: btt_check_arenas: checking arena 0
  namespace5.0: namespace_check: Received a SIGBUS
  namespace5.0: namespace_check: Metadata corruption found, recovery is not possible
  error checking namespaces: Bad address

Cc: Dan Williams <dan.j.williams@intel.com>
Reported-by: Jeff Moyer <jmoyer@redhat.com>
Signed-off-by: Vishal Verma <vishal.l.verma@intel.com>
---
 ndctl/check.c | 31 +++++++++++++++++++++++++++++++
 1 file changed, 31 insertions(+)

diff --git a/ndctl/check.c b/ndctl/check.c
index 3b30a98..3775c2e 100644
--- a/ndctl/check.c
+++ b/ndctl/check.c
@@ -13,6 +13,8 @@
 #include <stdio.h>
 #include <fcntl.h>
 #include <errno.h>
+#include <setjmp.h>
+#include <signal.h>
 #include <stdint.h>
 #include <stdlib.h>
 #include <unistd.h>
@@ -40,6 +42,13 @@
 #include <ndctl.h>
 #endif
 
+static sigjmp_buf sj_env;
+
+static void sigbus_hdl(int sig, siginfo_t *siginfo, void *ptr)
+{
+	siglongjmp(sj_env, 1);
+}
+
 static int repair_msg(struct btt_chk *bttc)
 {
 	info(bttc, "  Run with --repair to make the changes\n");
@@ -872,6 +881,7 @@ int namespace_check(struct ndctl_namespace *ndns, struct check_opts *opts)
 	int raw_mode, rc, disabled_flag = 0, open_flags;
 	struct btt_sb *btt_sb;
 	struct btt_chk *bttc;
+	struct sigaction act;
 	char path[50];
 
 	bttc = calloc(1, sizeof(*bttc));
@@ -882,6 +892,15 @@ int namespace_check(struct ndctl_namespace *ndns, struct check_opts *opts)
 	if (opts->verbose)
 		bttc->ctx.log_priority = LOG_DEBUG;
 
+	memset(&act, 0, sizeof(act));
+	act.sa_sigaction = sigbus_hdl;
+	act.sa_flags = SA_SIGINFO;
+
+	if (sigaction(SIGBUS, &act, 0)) {
+		err(bttc, "Unable to set sigaction\n");
+		return -errno;
+	}
+
 	bttc->opts = opts;
 	bttc->start_off = BTT_START_OFFSET;
 	bttc->sys_page_size = sysconf(_SC_PAGESIZE);
@@ -949,6 +968,18 @@ int namespace_check(struct ndctl_namespace *ndns, struct check_opts *opts)
 		goto out_sb;
 	}
 
+	/*
+	 * This is where we jump to if we receive a SIGBUS, prior to doing any
+	 * mmaped reads, and can safely abort
+	 */
+	if (sigsetjmp(sj_env, 1)) {
+		err(bttc, "Received a SIGBUS\n");
+		err(bttc,
+			"Metadata corruption found, recovery is not possible\n");
+		rc = -EFAULT;
+		goto out_close;
+	}
+
 	rc = btt_info_read_verify(bttc, btt_sb, bttc->start_off);
 	if (rc) {
 		rc = btt_recover_first_sb(bttc);
-- 
2.9.3

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

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

end of thread, other threads:[~2017-04-18 16:09 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2017-04-14  0:02 [ndctl PATCH] ndctl, check: Add a sigbus handler to detect metadata corruption Vishal Verma
2017-04-14  0:10 ` Rudoff, Andy
2017-04-14 19:00   ` Verma, Vishal L
2017-04-14 19:04     ` Dan Williams
2017-04-14 19:26       ` Rudoff, Andy
2017-04-14 19:40         ` Verma, Vishal L
2017-04-14 19:52           ` Rudoff, Andy
2017-04-14 20:28             ` Verma, Vishal L
2017-04-14 20:31               ` Rudoff, Andy
2017-04-17 15:37 ` Jeff Moyer
2017-04-18 16:09   ` Verma, Vishal L

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox