From nobody Mon Aug 19 16:03:22 2024 X-Original-To: dev-commits-src-all@mlmmj.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id 4Wncp31cykz5TGqm; Mon, 19 Aug 2024 16:03:23 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "R11" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4Wncp26CR1z49Lp; Mon, 19 Aug 2024 16:03:22 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1724083402; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=VWybNsLNxxOXDXyp4IV6ydDi7+0IsuyphQwrErpQ2D0=; b=LxNJGcnKUiT70dyJC/KMQNwMnsX8FiqHgv3ijwUzqYEQ0sMs5dDkKxJkw4Lr/CrPx3RiGu 50TuIYt5id325kaqvquwTtXgHvQLu0EbqaV+tDJGmxackQ0nWtL3tO7jfQTEiRXU/k2d+p FsmC9Z82nREnKnIRyv18dfwIXCaW1gYdBx562yincADmglu3Ik3tsdQzZx1gd5jg3+npid 8QXw5sjaPmPe/Y2MiJH8AEv6A7gKrJSuqaMYUqhLWPaFgvS4GioO2r/dzYBwUrpbCtseRd 5tJaXaqhTLZTTklN+ZeVNX4wPcwu/2OYC3L2/nmuzCCYoSVtn7LefQk5RzQl+Q== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1724083402; a=rsa-sha256; cv=none; b=xl0PYiJIgU3Z/1PvBLXkIPcT2DfHwndTq+tOoKEJ2FzfAN5OF5nT3zIicq9E4fktMaLb5N zEwhRRaJB1pEBwBKfTqwC7DTb+OEUwEGcW5eisysVOkTRXmghnF2B8pl5TDoq2zcQddIzO UOOBfHS6kRf0qybGTFyywujqxzxWmVG2xCn+IEWak0HGzUczlEVewB4TD6Xr7dqaOO7JtY muchOYFrqQQv4XZEugbYehOrg0Ta2UIvZVm+DriEk6vCwYM3NO8H7NCEOOw+ylbSbgyQPb 2JSgXUI24T03sUuXWEXIH/npVSt28dfFbYWaTJ58egrfKSsWg1HgQiMWRGyWSQ== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1724083402; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=VWybNsLNxxOXDXyp4IV6ydDi7+0IsuyphQwrErpQ2D0=; b=ZqbRFRB1d74PlXBin9opiWRR5NitlePgHn3Af1Zh3kR+rYAsc20CWFjpxdS3148HZbMlQD ETJFkl1EFEk9bwbHwUgP8RAVBiCUw3yg/mN/OiESzgVPxwcPsXgkBWcDqvLmErIjO9JJdM CJbluGs2XENTi8mPrNEIkzZD8so97hFV3wktEPCXeqm/bI/806hODp/nWG+bVyIN7yUpbd CQhTjA/DFqCZioDHoBXDKuqUdtBiyq/j78Y1KEANy790rsgnxb8il/8VuUpL/KRiktNi2y Clvex7PC8/hRa85pBP7IbVv08T0rWSGwg3w5fQ7n0iLzV/20EfW4rXBes+2vgQ== Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 4Wncp25XP6zNXB; Mon, 19 Aug 2024 16:03:22 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.18.1/8.18.1) with ESMTP id 47JG3MxD047889; Mon, 19 Aug 2024 16:03:22 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.18.1/8.18.1/Submit) id 47JG3MVt047886; Mon, 19 Aug 2024 16:03:22 GMT (envelope-from git) Date: Mon, 19 Aug 2024 16:03:22 GMT Message-Id: <202408191603.47JG3MVt047886@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Mark Johnston Subject: git: d06fe346eccf - main - libgeom: Avoid fixed remappings of the devstat device List-Id: Commit messages for all branches of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-all List-Help: List-Post: List-Subscribe: List-Unsubscribe: X-BeenThere: dev-commits-src-all@freebsd.org Sender: owner-dev-commits-src-all@FreeBSD.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: markj X-Git-Repository: src X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: d06fe346eccf0919a29d43599548e49c0d6a7a17 Auto-Submitted: auto-generated The branch main has been updated by markj: URL: https://cgit.FreeBSD.org/src/commit/?id=d06fe346eccf0919a29d43599548e49c0d6a7a17 commit d06fe346eccf0919a29d43599548e49c0d6a7a17 Author: Mark Johnston AuthorDate: 2024-08-19 16:02:26 +0000 Commit: Mark Johnston CommitDate: 2024-08-19 16:02:59 +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 --- 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);