git: fc3afe939530 - main - nvme: split devctl out to its own function

From: Warner Losh <imp_at_FreeBSD.org>
Date: Thu, 07 Mar 2024 01:39:12 UTC
The branch main has been updated by imp:

URL: https://cgit.FreeBSD.org/src/commit/?id=fc3afe93953082549e84925d303f4d9c8676f0ba

commit fc3afe93953082549e84925d303f4d9c8676f0ba
Author:     Warner Losh <imp@FreeBSD.org>
AuthorDate: 2024-03-07 01:22:13 +0000
Commit:     Warner Losh <imp@FreeBSD.org>
CommitDate: 2024-03-07 01:38:59 +0000

    nvme: split devctl out to its own function
    
    Split the devctl aspect of things out to its own function in
    nvme_ctrlr_devctl_log. In preparing to document this, and based on
    actual use, we want something different for the SMART errors, so this
    will facilitate that.
    
    Sponsored by:           Netflix
    Reviewed by:            chuck, mav
    Differential Revision:  https://reviews.freebsd.org/D44209
---
 sys/dev/nvme/nvme_ctrlr.c | 29 ++++++++++++++++++++---------
 1 file changed, 20 insertions(+), 9 deletions(-)

diff --git a/sys/dev/nvme/nvme_ctrlr.c b/sys/dev/nvme/nvme_ctrlr.c
index 0d33454125bd..1bc0331f002c 100644
--- a/sys/dev/nvme/nvme_ctrlr.c
+++ b/sys/dev/nvme/nvme_ctrlr.c
@@ -55,6 +55,24 @@ nvme_ctrlr_barrier(struct nvme_controller *ctrlr, int flags)
 	bus_barrier(ctrlr->resource, 0, rman_get_size(ctrlr->resource), flags);
 }
 
+static void
+nvme_ctrlr_devctl_va(struct nvme_controller *ctrlr, const char *type,
+    const char *msg, va_list ap)
+{
+	struct sbuf sb;
+	int error;
+
+	if (sbuf_new(&sb, NULL, 0, SBUF_AUTOEXTEND | SBUF_NOWAIT) == NULL)
+		return;
+	sbuf_printf(&sb, "name=\"%s\" reason=\"", device_get_nameunit(ctrlr->dev));
+	sbuf_vprintf(&sb, msg, ap);
+	sbuf_printf(&sb, "\"");
+	error = sbuf_finish(&sb);
+	if (error == 0)
+		devctl_notify("nvme", "controller", type, sbuf_data(&sb));
+	sbuf_delete(&sb);
+}
+
 static void
 nvme_ctrlr_devctl_log(struct nvme_controller *ctrlr, const char *type, const char *msg, ...)
 {
@@ -71,17 +89,10 @@ nvme_ctrlr_devctl_log(struct nvme_controller *ctrlr, const char *type, const cha
 	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));
+	sbuf_delete(&sb);
 	va_start(ap, msg);
-	sbuf_vprintf(&sb, msg, ap);
+	nvme_ctrlr_devctl_va(ctrlr, type, 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