git: 1e9e198b7f06 - main - libgeom: Open the control device read-write

From: Dag-Erling Smørgrav <des_at_FreeBSD.org>
Date: Sat, 14 Nov 2026 16:25:01 UTC
The branch main has been updated by des:

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

commit 1e9e198b7f064322687746d26b283c3fcbad4579
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-14 16:24:40 +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
---
 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);
 }