From nobody Thu Oct 26 23:22:28 2023 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 4SGhfD70ttz4yPmq; Thu, 26 Oct 2023 23:22:28 +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 "R3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4SGhfD6KCbz4F7s; Thu, 26 Oct 2023 23:22:28 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1698362548; 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=KaJMMHAo5hmTN4j2czb2NeAU/x4I6zloeeBUZyJCne4=; b=YP5y6LGxmO/MjXWXML1uIBJbvcRgVZXMGQizMc9xX63RYG4hjMbb4Fk96Ifwvdr+9liAaw i9OSWC0ufNITa2SV3DXVAe70C/M6G+WhIRymd+4ghxE1R9Gz06YCDbGb6GApvgWj5MJcix uuE1uCedcE368CUrA1TfNl4ZKQm1h+AEZrIRKiTWZGp9gUNbdtvGVUvuHieP6RgICzaI+R HdvFb2aAqDqP9ooAQn6kubi5lk4cF2mL9t+MNA+hOosT+jtdElCtVb8vIB5cAD/zcAuRvU Tcx/rV5DYnffObJ1hIeI1xL6mfDeTN0WUrZBkv9r71q10QUJyPWtPyaRKz2eFQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1698362548; 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=KaJMMHAo5hmTN4j2czb2NeAU/x4I6zloeeBUZyJCne4=; b=ggWj2xLuakSUFvZ/TdVJJsCP30hHCqu6kccy4uDn2B1q+ZnXUeCBEagYJ6jiOWZlsVw+ew nW7pujjkgCpQWg561xLNKBBnEwUMIYgyGE57dIAFLElINTj3I8LNp4U3u4+imVhRpwJKcV QTKcWIVZR2K71X+/jZYwAgJcvX0nLuk6azSuNP4nl2IKXWcnAcLyX9QFLt/hczH5Vj6f8D rCAp7bjYPKb/Or8shIQAVEYNa4yhNkI6sWLlXLeUt/HLd6Ja9qZEh+oXRJCF+7dTSuVQEi csQ7oew5xMdeGvJzMLBtIsidZm4AEyhGS6PFvTijAqYTUTdlbxAH6+APpxjTow== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1698362548; a=rsa-sha256; cv=none; b=HQbGzkukdocRKcdwtnQOop8AnMFm1mfTGLRYGtTQOZj6Ggpo5dIb6NIr9EQNN2NhjGFQtB 9qDHduLQ79Pe6MUED/Nh7Od8wp1Wl2Xzb3B4yklYOgZxDxBzHyflWwFQou0oN1OBAusqKM ikV/tnJuZhAIL27o+vJStSIa8qWGcioJAC3aFbLumdjxbE82BF6lwE+4xKjsd75IGg8dFh M6dCuTikMki3Z3RKNlFRyFHP+l6YV2hZedZTtEtOmM7XZOjlTfMyK3pCZ2wzCmQVFk7gHz 54x7av0OB85oC0nplNKBw841pca3iemoy5Ly6wJsErWVuZNjk6DgqL8uzHK78w== 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 4SGhfD5Q1gzqnk; Thu, 26 Oct 2023 23:22:28 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.17.1/8.17.1) with ESMTP id 39QNMSbZ074071; Thu, 26 Oct 2023 23:22:28 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.17.1/8.17.1/Submit) id 39QNMS3D074068; Thu, 26 Oct 2023 23:22:28 GMT (envelope-from git) Date: Thu, 26 Oct 2023 23:22:28 GMT Message-Id: <202310262322.39QNMS3D074068@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org From: Warner Losh Subject: git: 7bdb67cb1cfe - releng/14.0 - gpart: Be less picky about GPT Tables in some cases 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: Sender: owner-dev-commits-src-all@freebsd.org X-BeenThere: dev-commits-src-all@freebsd.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: imp X-Git-Repository: src X-Git-Refname: refs/heads/releng/14.0 X-Git-Reftype: branch X-Git-Commit: 7bdb67cb1cfe161de68bfe0cd35bab73d4c77e3c Auto-Submitted: auto-generated The branch releng/14.0 has been updated by imp: URL: https://cgit.FreeBSD.org/src/commit/?id=7bdb67cb1cfe161de68bfe0cd35bab73d4c77e3c commit 7bdb67cb1cfe161de68bfe0cd35bab73d4c77e3c Author: Warner Losh AuthorDate: 2023-10-26 16:14:54 +0000 Commit: Warner Losh CommitDate: 2023-10-26 23:18:38 +0000 gpart: Be less picky about GPT Tables in some cases When we're recoverying a damangae GPT, or when we're restoring a backed up partition tables, don't enforce the 4k alignment for start/end LBAs. This is useful for 512e/4kn drives when we're creating a new partition table or partition. However, when we're trying to fix / restore an old partition, we shouldn't force this alignment, since in that case it's more important to use the partition table as is than to optimize performance by rounding (which isn't required by the standard). MFC After: 1 week (pushed more quickly per re@) Sponsored by: Netflix Differential Revision: https://reviews.freebsd.org/D42359 (cherry picked from commit 5c9f0f72f47ea5315e5147185e47c2efca2e8c85) (cherry picked from commit 859d674e1745d0a37c9c8d77e21a3fadd713ef49) Approved-by: re (gjb) --- sys/geom/part/g_part_gpt.c | 41 +++++++++++++++++++++++++++++------------ 1 file changed, 29 insertions(+), 12 deletions(-) diff --git a/sys/geom/part/g_part_gpt.c b/sys/geom/part/g_part_gpt.c index 990ace4a25d4..c4cc840f583d 100644 --- a/sys/geom/part/g_part_gpt.c +++ b/sys/geom/part/g_part_gpt.c @@ -103,7 +103,8 @@ struct g_part_gpt_entry { static void g_gpt_printf_utf16(struct sbuf *, uint16_t *, size_t); static void g_gpt_utf8_to_utf16(const uint8_t *, uint16_t *, size_t); -static void g_gpt_set_defaults(struct g_part_table *, struct g_provider *); +static void g_gpt_set_defaults(struct g_part_table *, struct g_provider *, + struct g_part_parms *); static int g_part_gpt_add(struct g_part_table *, struct g_part_entry *, struct g_part_parms *); @@ -717,7 +718,7 @@ g_part_gpt_create(struct g_part_table *basetable, struct g_part_parms *gpp) table->hdr->hdr_entries = basetable->gpt_entries; table->hdr->hdr_entsz = sizeof(struct gpt_ent); - g_gpt_set_defaults(basetable, pp); + g_gpt_set_defaults(basetable, pp, gpp); return (0); } @@ -1083,7 +1084,7 @@ g_part_gpt_recover(struct g_part_table *basetable) table = (struct g_part_gpt_table *)basetable; pp = LIST_FIRST(&basetable->gpt_gp->consumer)->provider; gpt_create_pmbr(table, pp); - g_gpt_set_defaults(basetable, pp); + g_gpt_set_defaults(basetable, pp, NULL); basetable->gpt_corrupt = 0; return (0); } @@ -1300,7 +1301,8 @@ g_part_gpt_write(struct g_part_table *basetable, struct g_consumer *cp) } static void -g_gpt_set_defaults(struct g_part_table *basetable, struct g_provider *pp) +g_gpt_set_defaults(struct g_part_table *basetable, struct g_provider *pp, + struct g_part_parms *gpp) { struct g_part_entry *baseentry; struct g_part_gpt_entry *entry; @@ -1334,14 +1336,29 @@ g_gpt_set_defaults(struct g_part_table *basetable, struct g_provider *pp) if (entry->ent.ent_lba_end > max) max = entry->ent.ent_lba_end; } - spb = 4096 / pp->sectorsize; - if (spb > 1) { - lba = start + ((start % spb) ? spb - start % spb : 0); - if (lba <= min) - start = lba; - lba = end - (end + 1) % spb; - if (max <= lba) - end = lba; + /* + * Don't force alignment of any kind whatsoever on resize, restore or + * recover. resize doesn't go through this path, recover has a NULL gpp + * and restore has flags == restore (maybe with an appended 'C' to + * commit the operation). For these operations, we have to trust the + * user knows what they are doing. + * + * Otherwise it some flavor of creation of a new partition, so we align + * to a 4k offset on the drive, to make 512e/4kn drives more performant + * by default. + */ + if (gpp == NULL || + (gpp->gpp_parms & G_PART_PARM_FLAGS) == 0 || + strstr(gpp->gpp_flags, "restore") == NULL) { + spb = 4096 / pp->sectorsize; + if (spb > 1) { + lba = start + ((start % spb) ? spb - start % spb : 0); + if (lba <= min) + start = lba; + lba = end - (end + 1) % spb; + if (max <= lba) + end = lba; + } } table->hdr->hdr_lba_start = start; table->hdr->hdr_lba_end = end;