git: 718283a2b709 - stable/12 - Generate a devctl event for interesting events
Warner Losh
imp at FreeBSD.org
Sat Jul 31 00:21:17 UTC 2021
The branch stable/12 has been updated by imp:
URL: https://cgit.FreeBSD.org/src/commit/?id=718283a2b7098e8f48b0bd003066d7c3e72a1513
commit 718283a2b7098e8f48b0bd003066d7c3e72a1513
Author: Warner Losh <imp at FreeBSD.org>
AuthorDate: 2020-04-30 00:27:19 +0000
Commit: Warner Losh <imp at FreeBSD.org>
CommitDate: 2021-07-31 00:02:51 +0000
Generate a devctl event for interesting events
When we reset the controller, and when the controller tells us about a
critical warning, send an event.
(cherry picked from commit 244b805397208842e4d8bbf1ad5b1b83dbcd4c91)
---
sys/dev/nvme/nvme_ctrlr.c | 51 +++++++++++++++++++++++++++++++++++++++--------
1 file changed, 43 insertions(+), 8 deletions(-)
diff --git a/sys/dev/nvme/nvme_ctrlr.c b/sys/dev/nvme/nvme_ctrlr.c
index d011eec99722..18a22aa4f041 100644
--- a/sys/dev/nvme/nvme_ctrlr.c
+++ b/sys/dev/nvme/nvme_ctrlr.c
@@ -40,7 +40,9 @@ __FBSDID("$FreeBSD$");
#include <sys/proc.h>
#include <sys/smp.h>
#include <sys/uio.h>
+#include <sys/sbuf.h>
#include <sys/endian.h>
+#include <machine/stdarg.h>
#include <vm/vm.h>
#include "nvme_private.h"
@@ -50,6 +52,34 @@ __FBSDID("$FreeBSD$");
static void nvme_ctrlr_construct_and_submit_aer(struct nvme_controller *ctrlr,
struct nvme_async_event_request *aer);
+static void
+nvme_ctrlr_devctl_log(struct nvme_controller *ctrlr, const char *type, const char *msg, ...)
+{
+ struct sbuf sb;
+ va_list ap;
+ int error;
+
+ sbuf_new(&sb, NULL, 0, SBUF_AUTOEXTEND | SBUF_NOWAIT);
+ sbuf_printf(&sb, "%s: ", device_get_nameunit(ctrlr->dev));
+ va_start(ap, msg);
+ sbuf_vprintf(&sb, msg, ap);
+ va_end(ap);
+ error = sbuf_finish(&sb);
+ if (error == 0)
+ printf("%s\n", sbuf_data(&sb));
+
+ sbuf_clear(&sb);
+ sbuf_printf(&sb, "name=\"%s\" reason=\"", device_get_nameunit(ctrlr->dev));
+ va_start(ap, msg);
+ sbuf_vprintf(&sb, msg, ap);
+ va_end(ap);
+ sbuf_printf(&sb, "\"");
+ error = sbuf_finish(&sb);
+ if (error == 0)
+ devctl_notify("nvme", "controller", type, sbuf_data(&sb));
+ sbuf_delete(&sb);
+}
+
static int
nvme_ctrlr_construct_admin_qpair(struct nvme_controller *ctrlr)
{
@@ -606,23 +636,28 @@ nvme_ctrlr_log_critical_warnings(struct nvme_controller *ctrlr,
{
if (state & NVME_CRIT_WARN_ST_AVAILABLE_SPARE)
- nvme_printf(ctrlr, "available spare space below threshold\n");
+ nvme_ctrlr_devctl_log(ctrlr, "critical",
+ "available spare space below threshold");
if (state & NVME_CRIT_WARN_ST_TEMPERATURE)
- nvme_printf(ctrlr, "temperature above threshold\n");
+ nvme_ctrlr_devctl_log(ctrlr, "critical",
+ "temperature above threshold");
if (state & NVME_CRIT_WARN_ST_DEVICE_RELIABILITY)
- nvme_printf(ctrlr, "device reliability degraded\n");
+ nvme_ctrlr_devctl_log(ctrlr, "critical",
+ "device reliability degraded");
if (state & NVME_CRIT_WARN_ST_READ_ONLY)
- nvme_printf(ctrlr, "media placed in read only mode\n");
+ nvme_ctrlr_devctl_log(ctrlr, "critical",
+ "media placed in read only mode");
if (state & NVME_CRIT_WARN_ST_VOLATILE_MEMORY_BACKUP)
- nvme_printf(ctrlr, "volatile memory backup device failed\n");
+ nvme_ctrlr_devctl_log(ctrlr, "critical",
+ "volatile memory backup device failed");
if (state & NVME_CRIT_WARN_ST_RESERVED_MASK)
- nvme_printf(ctrlr,
- "unknown critical warning(s): state = 0x%02x\n", state);
+ nvme_ctrlr_devctl_log(ctrlr, "critical",
+ "unknown critical warning(s): state = 0x%02x", state);
}
static void
@@ -1129,7 +1164,7 @@ nvme_ctrlr_reset_task(void *arg, int pending)
struct nvme_controller *ctrlr = arg;
int status;
- nvme_printf(ctrlr, "resetting controller\n");
+ nvme_ctrlr_devctl_log(ctrlr, "RESET", "resetting controller");
status = nvme_ctrlr_hw_reset(ctrlr);
/*
* Use pause instead of DELAY, so that we yield to any nvme interrupt
More information about the dev-commits-src-all
mailing list