From nobody Tue Sep 3 14:55:01 2024 X-Original-To: dev-commits-src-branches@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 4WypZG183Dz5TMhV; Tue, 03 Sep 2024 14:55:02 +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 4WypZF6x6bz4x3M; Tue, 3 Sep 2024 14:55:01 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1725375302; 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=UddM1j+QYj4lQqe85lOOMe8+oRAZoK2FJF17PJ0Z8+Q=; b=Sf4qvLwXetNrK1yDDmYAQuI0WeW6eORNfkyh1XG3Byyx+riOdrCMe6i//+GZF+ffGv15pB u8cDoui0A9JpSlGQ+nyn4EN4ojjePSohbYHy1kfGuVmleRrGMY8WEUEEyF08krKpF1xzQ3 xJcahUT3nkamdO7VLrjEK1utc96r51Mm3QaH6580wvhpk10DS7iv9q29zpRvLseawzv5mE BfwEttMfL5INZpij3gqt+iyqB2F+2FWfjbbmHmi7uOylFLpvM1yNgtt+Co09ZxEs/ULWat Ya2Du3833sNuTB6j9qwSJ+N6x6ZA2KjwmFmkpPGhwgshyUXM8iBtXYSyHkFuzg== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1725375302; a=rsa-sha256; cv=none; b=Ohc9FTeMEqtGlgzmN5joed+EVvvhxAGr7VttTpZZCI2uQQo0mPZ3i53wxQ3Vz+JymWrq2x dHwN4bnmzU9KMYigmViDc28OOltPnApJYci3vNcjWTJG4rbJJsjDhDy2Lx2tXeBJaxI3ZY rQBBPlzcWw1P9QL2XOLX+dqeQ53sQYYp4y73l5Lu/ccVIqjlZTmpfZEG9IEqoXEtuEwaRN pBMjlTi53IBrs//4R3e54HnS5spKUrVrLPp8T7NPPbJUZeqcRYmt1Gwcu2NfuJr6KLJotr 5MPOuc7uOP2ig/Mt6gSHBaQhW55NXQqbJA+G+XSadvADyJVTNMEYNtZ7pNgflA== 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=1725375302; 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=UddM1j+QYj4lQqe85lOOMe8+oRAZoK2FJF17PJ0Z8+Q=; b=b7xKhaBGLEg88PZMm2a5mJTx8wuPDC6xVUR/rjSIkYDhqG2Or7RBLm4AYayzpbMt0nMAqZ LqRTf3foB26F49DeVCynvgPkNhKWFCFHyA9WftZjXz/VLXxH5JFXpY25LDiha4ptLc0Q/1 o/kfyosYjNM/Au4gloJv88mwPscgGq4Y8rOcJ2uSSsAg1Pvl6Wx3lPuLyQY0lqsfqaon2z ehhNyW5syxF00KEAiB2H4hd+xHIlJD+s0yrOunUwIN6VBtMVXDENW4QcZkuvXiydtkFoJE 1qJQqvm13i6t32sqAVCjrYTRUhTj/8n+r4FREssHv7jT/rrj8SuOCPk0zsr67A== 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 4WypZF6Y5Zzllf; Tue, 3 Sep 2024 14:55:01 +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 483Et1sK070634; Tue, 3 Sep 2024 14:55:01 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.18.1/8.18.1/Submit) id 483Et1W1070631; Tue, 3 Sep 2024 14:55:01 GMT (envelope-from git) Date: Tue, 3 Sep 2024 14:55:01 GMT Message-Id: <202409031455.483Et1W1070631@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org From: Mark Johnston Subject: git: 1e8b00a1cbc8 - stable/14 - libgeom: Avoid fixed remappings of the devstat device List-Id: Commits to the stable branches of the FreeBSD src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-branches List-Help: List-Post: List-Subscribe: List-Unsubscribe: X-BeenThere: dev-commits-src-branches@freebsd.org Sender: owner-dev-commits-src-branches@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/stable/14 X-Git-Reftype: branch X-Git-Commit: 1e8b00a1cbc801d0961482e81f9fc13d32d71e71 Auto-Submitted: auto-generated The branch stable/14 has been updated by markj: URL: https://cgit.FreeBSD.org/src/commit/?id=1e8b00a1cbc801d0961482e81f9fc13d32d71e71 commit 1e8b00a1cbc801d0961482e81f9fc13d32d71e71 Author: Mark Johnston AuthorDate: 2024-08-19 16:02:26 +0000 Commit: Mark Johnston 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);