Author: imp
Date: Thu Apr 30 00:27:19 2020
New Revision: 360482
URL: https://svnweb.freebsd.org/changeset/base/360482

Log:
  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.

Modified:
  head/sys/dev/nvme/nvme_ctrlr.c

Modified: head/sys/dev/nvme/nvme_ctrlr.c
==============================================================================
--- head/sys/dev/nvme/nvme_ctrlr.c      Thu Apr 30 00:20:31 2020        
(r360481)
+++ head/sys/dev/nvme/nvme_ctrlr.c      Thu Apr 30 00:27:19 2020        
(r360482)
@@ -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)
 {
@@ -607,23 +637,28 @@ nvme_ctrlr_log_critical_warnings(struct nvme_controlle
 {
 
        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
@@ -1121,7 +1156,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
_______________________________________________
svn-src-all@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/svn-src-all
To unsubscribe, send any mail to "svn-src-all-unsubscr...@freebsd.org"

Reply via email to