git: 2f461ddd784b - main - geom: fix glabel status not showing components

From: Brad Davis <brd_at_FreeBSD.org>
Date: Mon, 20 Oct 2025 02:35:18 UTC
The branch main has been updated by brd:

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

commit 2f461ddd784b4abdb7f88701d20fc45f658c42f5
Author:     Brad Davis <brd@FreeBSD.org>
AuthorDate: 2025-10-18 00:31:12 +0000
Commit:     Brad Davis <brd@FreeBSD.org>
CommitDate: 2025-10-20 02:35:06 +0000

    geom: fix glabel status not showing components
    
    Also fix some typos and move a couple NULL checks earlier.
    
    Reviewed by:    mckusick, Johan Söllvander, markj, kevans, adrian
    Fixes:          0d4642a67e59f8da5e00a05001c342bdad2a806f
    MFC after:      3 days
    Differential Revision:  https://reviews.freebsd.org/D53180
---
 sbin/geom/core/geom.c | 37 ++++++++++++++++++++++---------------
 1 file changed, 22 insertions(+), 15 deletions(-)

diff --git a/sbin/geom/core/geom.c b/sbin/geom/core/geom.c
index 1a4f7e1f061a..2de696ce6a43 100644
--- a/sbin/geom/core/geom.c
+++ b/sbin/geom/core/geom.c
@@ -1189,10 +1189,11 @@ status_one_geom(struct ggeom *gp, int script, int name_len, int status_len)
 	gotone = len = 0;
 	xo_open_instance("status");
 	LIST_FOREACH(cp, &gp->lg_consumer, lg_consumer) {
+		if (cp->lg_provider == NULL)
+			continue;
+
 		cstate = status_one_consumer(cp, "state");
 		csyncr = status_one_consumer(cp, "synchronized");
-		if (cstate == NULL && csyncr == NULL)
-			continue;
 		if (!gotone || script) {
 			if (!gotone) {
 				xo_emit("{:name/%*s}  {:status/%*s}  ",
@@ -1206,14 +1207,17 @@ status_one_geom(struct ggeom *gp, int script, int name_len, int status_len)
 
 		xo_open_instance("components");
 		if (cstate != NULL && csyncr != NULL) {
-			xo_emit("{P:/%*s}{:compontent} ({:state}, {:synchronized})\n",
+			xo_emit("{P:/%*s}{:component} ({:state}, {:synchronized})\n",
 			len, "", cp->lg_provider->lg_name, cstate, csyncr);
 		} else if (cstate != NULL) {
-			xo_emit("{P:/%*s}{:compontent} ({:state})\n",
+			xo_emit("{P:/%*s}{:component} ({:state})\n",
 			len, "", cp->lg_provider->lg_name, cstate);
-		} else {
-			xo_emit("{P:/%*s}{:compontent} ({:synchronized})\n",
+		} else if (csyncr != NULL) {
+			xo_emit("{P:/%*s}{:component} ({:synchronized})\n",
 			len, "", cp->lg_provider->lg_name, csyncr);
+		} else {
+			xo_emit("{P:/%*s}{:component}\n",
+			len, "", cp->lg_provider->lg_name);
 		}
 		xo_close_instance("components");
 		gotone = 1;
@@ -1224,7 +1228,7 @@ status_one_geom(struct ggeom *gp, int script, int name_len, int status_len)
 		xo_emit("{:name/%*s}  {:status/%*s}  ", name_len, name, status_len, status);
 		xo_open_list("components");
 		xo_open_instance("components");
-		xo_emit("{P:/%*s}{d:compontent}\n", len, "", "N/A");
+		xo_emit("{P:/%*s}{d:component}\n", len, "", "N/A");
 		xo_close_instance("components");
 	}
 	xo_close_list("components");
@@ -1258,11 +1262,11 @@ status_one_geom_prs(struct ggeom *gp, int script, int name_len, int status_len)
 		}
 		gotone = len = 0;
 		LIST_FOREACH(cp, &gp->lg_consumer, lg_consumer) {
-			cstate = status_one_consumer(cp, "state");
-			csyncr = status_one_consumer(cp, "synchronized");
-			if (cstate == NULL && csyncr == NULL)
+			if (cp->lg_provider == NULL)
 				continue;
 
+			cstate = status_one_consumer(cp, "state");
+			csyncr = status_one_consumer(cp, "synchronized");
 			if (!gotone || script) {
 				if (!gotone) {
 					xo_emit("{:name/%*s}  {:status/%*s}  ",
@@ -1276,14 +1280,17 @@ status_one_geom_prs(struct ggeom *gp, int script, int name_len, int status_len)
 
 			xo_open_instance("component");
 			if (cstate != NULL && csyncr != NULL) {
-				xo_emit("{P:/%*s}{:compontent} ({:state}, {:synchronized})\n",
+				xo_emit("{P:/%*s}{:component} ({:state}, {:synchronized})\n",
 				len, "", cp->lg_provider->lg_name, cstate, csyncr);
 			} else if (cstate != NULL) {
-				xo_emit("{P:/%*s}{:compontent} ({:state})\n",
+				xo_emit("{P:/%*s}{:component} ({:state})\n",
 				len, "", cp->lg_provider->lg_name, cstate);
-			} else {
-				xo_emit("{P:/%*s}{:compontent} ({:synchronized})\n",
+			} else if (csyncr != NULL) {
+				xo_emit("{P:/%*s}{:component} ({:synchronized})\n",
 				len, "", cp->lg_provider->lg_name, csyncr);
+			} else {
+				xo_emit("{P:/%*s}{:component}\n",
+				len, "", cp->lg_provider->lg_name);
 			}
 			xo_close_instance("component");
 			gotone = 1;
@@ -1294,7 +1301,7 @@ status_one_geom_prs(struct ggeom *gp, int script, int name_len, int status_len)
 			xo_emit("{:name/%*s}  {:status/%*s}  ", name_len, name, status_len, status);
 			xo_open_list("components");
 			xo_open_instance("components");
-			xo_emit("{P:/%*s}{d:compontent}\n", len, "", "N/A");
+			xo_emit("{P:/%*s}{d:component}\n", len, "", "N/A");
 			xo_close_instance("components");
 		}
 		xo_close_list("components");