Skip site navigation (1)Skip section navigation (2)
Date:      Tue, 3 Sep 2024 14:55:01 GMT
From:      Mark Johnston <markj@FreeBSD.org>
To:        src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org
Subject:   git: 1e8b00a1cbc8 - stable/14 - libgeom: Avoid fixed remappings of the devstat device
Message-ID:  <202409031455.483Et1W1070631@gitrepo.freebsd.org>

next in thread | raw e-mail | index | archive | help
The branch stable/14 has been updated by markj:

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

commit 1e8b00a1cbc801d0961482e81f9fc13d32d71e71
Author:     Mark Johnston <markj@FreeBSD.org>
AuthorDate: 2024-08-19 16:02:26 +0000
Commit:     Mark Johnston <markj@FreeBSD.org>
CommitDate: 2024-09-03 14:54:42 +0000

    libgeom: Avoid fixed remappings of the devstat device
    
    libgeom maintains a quasi-private mapping of /dev/devstat, which might
    grow over time if new devices appear.  When the mapping needs to be
    expanded, the old mapping is passed as a hint, but this appears to be
    unnecessary.
    
    Simplify and improve things a bit:
    - stop passing a hint when remapping,
    - don't creat a mapping in geom_stats_open(), as geom_stats_resync() will
      create it for us,
    - check for errors from munmap().
    
    Reviewed by:    imp, asomers
    Tested by:      asomers
    MFC after:      2 weeks
    Sponsored by:   Innovate UK
    Differential Revision:  https://reviews.freebsd.org/D46294
    
    (cherry picked from commit d06fe346eccf0919a29d43599548e49c0d6a7a17)
---
 lib/libgeom/geom_stats.c | 34 ++++++++++++----------------------
 1 file changed, 12 insertions(+), 22 deletions(-)

diff --git a/lib/libgeom/geom_stats.c b/lib/libgeom/geom_stats.c
index 7ae5c947b7b1..510636eb9a8b 100644
--- a/lib/libgeom/geom_stats.c
+++ b/lib/libgeom/geom_stats.c
@@ -54,9 +54,12 @@ geom_stats_close(void)
 {
 	if (statsfd == -1)
 		return;
-	munmap(statp, npages * pagesize);
-	statp = NULL;
-	close (statsfd);
+	if (statp != NULL) {
+		if (munmap(statp, npages * pagesize) != 0)
+			err(1, "munmap");
+		statp = NULL;
+	}
+	close(statsfd);
 	statsfd = -1;
 }
 
@@ -73,22 +76,18 @@ geom_stats_resync(void)
 	if (error)
 		err(1, "DIOCGMEDIASIZE(" _PATH_DEV DEVSTAT_DEVICE_NAME ")");
 
-	munmap(statp, npages * pagesize);
-	p = mmap(statp, mediasize, PROT_READ, MAP_SHARED, statsfd, 0);
+	if (statp != NULL && munmap(statp, npages * pagesize) != 0)
+		err(1, "munmap");
+	p = mmap(NULL, mediasize, PROT_READ, MAP_SHARED, statsfd, 0);
 	if (p == MAP_FAILED)
-		err(1, "mmap(/dev/devstat):");
-	else {
-		statp = p;
-		npages = mediasize / pagesize;
-	}
+		err(1, "mmap(/dev/devstat)");
+	statp = p;
+	npages = mediasize / pagesize;
 }
 
 int
 geom_stats_open(void)
 {
-	int error;
-	void *p;
-
 	if (statsfd != -1)
 		return (EBUSY);
 	statsfd = open(_PATH_DEV DEVSTAT_DEVICE_NAME, O_RDONLY);
@@ -96,15 +95,6 @@ geom_stats_open(void)
 		return (errno);
 	pagesize = getpagesize();
 	spp = pagesize / sizeof(struct devstat);
-	p = mmap(NULL, pagesize, PROT_READ, MAP_SHARED, statsfd, 0);
-	if (p == MAP_FAILED) {
-		error = errno;
-		close(statsfd);
-		statsfd = -1;
-		errno = error;
-		return (error);
-	}
-	statp = p;
 	npages = 1;
 	geom_stats_resync();
 	return (0);



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?202409031455.483Et1W1070631>