mirror of
https://github.com/opnsense/src.git
synced 2026-04-20 21:59:20 -04:00
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)
This commit is contained in:
parent
8ae58e0edb
commit
1e8b00a1cb
1 changed files with 12 additions and 22 deletions
|
|
@ -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);
|
||||
|
|
|
|||
Loading…
Reference in a new issue