git: 902b9ce02e69 - stable/15 - libgeom: Open the control device read-write

From: Dag-Erling Smørgrav <des_at_FreeBSD.org>
Date: Fri, 20 Nov 2026 12:04:37 UTC
The branch stable/15 has been updated by des:

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

commit 902b9ce02e69fa7b6c69c06cf4b77e82892071f0
Author:     Dag-Erling Smørgrav <des@FreeBSD.org>
AuthorDate: 2026-11-14 16:24:40 +0000
Commit:     Dag-Erling Smørgrav <des@FreeBSD.org>
CommitDate: 2026-11-20 12:03:56 +0000

    libgeom: Open the control device read-write
    
    Try to open the control device read-write first, and fall back to
    read-only if that fails and the error is EACCES.  This prepares us for a
    future in which GEOM requires write access to execute verbs that modify
    the configuration.
    
    MFC after:      1 week
    Event:          EuroBSDCon 2026 DevSummit
    Reviewed by:    imp, markj, emaste
    Differential Revision:  https://reviews.freebsd.org/D59592
    
    (cherry picked from commit 1e9e198b7f064322687746d26b283c3fcbad4579)
---
 lib/libgeom/geom_ctl.c | 8 +++++---
 1 file changed, 5 insertions(+), 3 deletions(-)

diff --git a/lib/libgeom/geom_ctl.c b/lib/libgeom/geom_ctl.c
index 8cc4c5b0c4b2..45a8d19661ff 100644
--- a/lib/libgeom/geom_ctl.c
+++ b/lib/libgeom/geom_ctl.c
@@ -207,15 +207,17 @@ gctl_issue(struct gctl_req *req)
 		return (req->error);
 	}
 	req->lerror--;
-	fd = open(_PATH_DEV PATH_GEOM_CTL, O_RDONLY);
+	fd = open(_PATH_DEV PATH_GEOM_CTL, O_RDWR);
+	if (fd < 0 && errno == EACCES)
+		fd = open(_PATH_DEV PATH_GEOM_CTL, O_RDONLY);
 	if (fd < 0)
-		return(strerror(errno));
+		return (strerror(errno));
 	req->nerror = ioctl(fd, GEOM_CTL, req);
 	close(fd);
 	if (req->error[0] != '\0')
 		return (req->error);
 	if (req->nerror == -1)
-		return(strerror(errno));
+		return (strerror(errno));
 	return (NULL);
 }