From nobody Mon Oct 14 08:08:59 2024 X-Original-To: dev-commits-src-main@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 4XRqcr0YxLz5ZPT5; Mon, 14 Oct 2024 08:09:00 +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 4XRqcq6lJdz4c1j; Mon, 14 Oct 2024 08:08:59 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1728893340; 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=PJX1eYuUG56Q5cV18ZUs3g3X7V9RUzuPo+4daaOazS0=; b=dsfCwILxf+DYpFnUZbA+s0lWOtsyVuql2FEIWLXKqHoDi+xAzotZ45+U2iEouOZ2ZUx6VX C5HhJRwKZ6/cRN3lYF7jURAxCk+aNa5bGvWZOhXEDnF6i7AObrwWY278Zhv6HZQpaasRsv e6TYAYAEavjdIU97/AXOyoxMo8v6xopFsIf9gKYZugAKeMqzENoYFCKycNLD28yjck6HK1 VO+RiXClojkH5YiTS2QfM63quQpmNyXh/K/UWOuEJXXitQMw/2ewisF3lccMeCGDXSdfER gYfS66uBRjrLyVUyaI2FiSoXCMTY+xSM3lWfQOYMvY3kjRwpx/X+1fU4vtU9oA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1728893339; 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=PJX1eYuUG56Q5cV18ZUs3g3X7V9RUzuPo+4daaOazS0=; b=WWQPWcZ4Y/d8v86kcMX+RjB5j1+7A4fpVRqWajXkzsv1pnbtg/qmtZpnKMukvsoZ5IusB9 fGTYlVqSUvQ8i1ptq5o/llQLVTFbU+2zLfA+h6gkZjVKtbdk3XnD9i0C+n6Iz/bnB63vLo qlmNMrFILuHpMe5BLSAJeijjV9jl38jZgwHLRLgdL43a1mnCIzzHwqDymrGn5m1FLK7sge 5gTUySzhJPhyYDjyzysRNUa+K1EKspliOJC0fL79aeMQZVMZLto7RRzloZfHxQ4gqy0LNU 7KDKVm8kK7Z/Hce7i1D4OyvCzQjNPYv5hwZR5UUbGIMQDe4RYVndBziQibBbWg== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1728893339; a=rsa-sha256; cv=none; b=fRAPKc5zDDbNN4pRXFk4cI2WYs0wC2MdvInYEtJD73o01uXMmDgkzlllr/4pxXdCZ2qByP vhWN0OUIipVLunvdoI9rrAdC5cSviyQs97ArzkdJyX1P5Rhw1yMOpXFcOh/PGItoX0L0uI tdcttlCqnaVoDb2w1mDJzQ+HfZTx67klsvz+x5EGmPRpBeK4EjSwDp16a97iBwjSghTIrW 7bDyjg3wh59GC8xII6eaUQxX1KTIDreQ7ZpvSw+2/foAwatqCzWDgmCL0xX1vcos0TtGBR luaqW3df9FCJjYzm//FyBUCJOLrqmGLLYMko12Pf7M5Cz69gNEX5Uqo/qnbs9g== 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 4XRqcq6BNgzW8P; Mon, 14 Oct 2024 08:08:59 +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 49E88xfq031993; Mon, 14 Oct 2024 08:08:59 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.18.1/8.18.1/Submit) id 49E88x4H031990; Mon, 14 Oct 2024 08:08:59 GMT (envelope-from git) Date: Mon, 14 Oct 2024 08:08:59 GMT Message-Id: <202410140808.49E88x4H031990@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Konstantin Belousov Subject: git: 4bf34c597c44 - main - md(4): always trim the last partial sector List-Id: Commit messages for the main branch of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-main List-Help: List-Post: List-Subscribe: List-Unsubscribe: X-BeenThere: dev-commits-src-main@freebsd.org Sender: owner-dev-commits-src-main@FreeBSD.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: kib X-Git-Repository: src X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: 4bf34c597c44a2393ac5ec483e9cecac128d8202 Auto-Submitted: auto-generated The branch main has been updated by kib: URL: https://cgit.FreeBSD.org/src/commit/?id=4bf34c597c44a2393ac5ec483e9cecac128d8202 commit 4bf34c597c44a2393ac5ec483e9cecac128d8202 Author: Konstantin Belousov AuthorDate: 2024-10-13 21:28:22 +0000 Commit: Konstantin Belousov CommitDate: 2024-10-14 08:08:21 +0000 md(4): always trim the last partial sector Do it also for the preloaded disk, in addition to the dynamically configured device. This is needed to avoid geom checking alignment and panicing on read of the last sector, e.g. for partition schemes and label tasting. PR: 281978 Reported by: bz Reviewed by: bz, markj Sponsored by: The FreeBSD Foundation MFC after: 1 week Differential revision: https://reviews.freebsd.org/D47102 --- sys/dev/md/md.c | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/sys/dev/md/md.c b/sys/dev/md/md.c index af05373ae1d8..5d4f91d05917 100644 --- a/sys/dev/md/md.c +++ b/sys/dev/md/md.c @@ -1297,6 +1297,7 @@ mdinit(struct md_s *sc) { struct g_geom *gp; struct g_provider *pp; + unsigned remn; g_topology_lock(); gp = g_new_geomf(&g_md_class, "md%d", sc->unit); @@ -1305,6 +1306,13 @@ mdinit(struct md_s *sc) devstat_remove_entry(pp->stat); pp->stat = NULL; pp->flags |= G_PF_DIRECT_SEND | G_PF_DIRECT_RECEIVE; + /* Prune off any residual fractional sector. */ + remn = sc->mediasize % sc->sectorsize; + if (remn != 0) { + printf("md%d: truncating fractional last sector by %u bytes\n", + sc->unit, remn); + sc->mediasize -= remn; + } pp->mediasize = sc->mediasize; pp->sectorsize = sc->sectorsize; switch (sc->type) { @@ -1674,7 +1682,7 @@ kern_mdattach_locked(struct thread *td, struct md_req *mdr) { struct md_s *sc; unsigned sectsize; - int error, i; + int error; sx_assert(&md_sx, SA_XLOCKED); @@ -1746,10 +1754,6 @@ err_after_new: return (error); } - /* Prune off any residual fractional sector */ - i = sc->mediasize % sc->sectorsize; - sc->mediasize -= i; - mdinit(sc); return (0); }