From owner-svn-src-all@freebsd.org Mon Sep 9 17:43:45 2019 Return-Path: Delivered-To: svn-src-all@mailman.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.nyi.freebsd.org (Postfix) with ESMTP id 7688DD9B87; Mon, 9 Sep 2019 17:43:45 +0000 (UTC) (envelope-from kevans@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) server-signature RSA-PSS (4096 bits) client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "Let's Encrypt Authority X3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 46RwWP2KgKz4JJc; Mon, 9 Sep 2019 17:43:45 +0000 (UTC) (envelope-from kevans@FreeBSD.org) Received: from repo.freebsd.org (repo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 33292193BB; Mon, 9 Sep 2019 17:43:45 +0000 (UTC) (envelope-from kevans@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id x89HhjTF089338; Mon, 9 Sep 2019 17:43:45 GMT (envelope-from kevans@FreeBSD.org) Received: (from kevans@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id x89Hhixv089335; Mon, 9 Sep 2019 17:43:44 GMT (envelope-from kevans@FreeBSD.org) Message-Id: <201909091743.x89Hhixv089335@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: kevans set sender to kevans@FreeBSD.org using -f From: Kyle Evans Date: Mon, 9 Sep 2019 17:43:44 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-12@freebsd.org Subject: svn commit: r352084 - in stable/12: lib/geom/part sys/geom/part X-SVN-Group: stable-12 X-SVN-Commit-Author: kevans X-SVN-Commit-Paths: in stable/12: lib/geom/part sys/geom/part X-SVN-Commit-Revision: 352084 X-SVN-Commit-Repository: base MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-all@freebsd.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: "SVN commit messages for the entire src tree \(except for " user" and " projects" \)" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 09 Sep 2019 17:43:45 -0000 Author: kevans Date: Mon Sep 9 17:43:44 2019 New Revision: 352084 URL: https://svnweb.freebsd.org/changeset/base/352084 Log: MFC r351797: (Optional) Allow more nesting of GEOM partitioning schemes GEOM is supposed to be topology-agnostic, but the GPT and BSD partition code has arbitrary restrictions on nesting that are annoying in cases such as running VMs on raw partitions (since the VM's partitioning scheme is not visible to the host). This patch adds sysctls to disable the restrictions except in the case of BSD label (and similar) partitions with offset 0 (where we need to avoid recursively recognizing the label). Modified: stable/12/lib/geom/part/gpart.8 stable/12/sys/geom/part/g_part.c stable/12/sys/geom/part/g_part_gpt.c Directory Properties: stable/12/ (props changed) Modified: stable/12/lib/geom/part/gpart.8 ============================================================================== --- stable/12/lib/geom/part/gpart.8 Mon Sep 9 17:37:52 2019 (r352083) +++ stable/12/lib/geom/part/gpart.8 Mon Sep 9 17:43:44 2019 (r352084) @@ -24,7 +24,7 @@ .\" .\" $FreeBSD$ .\" -.Dd June 17, 2018 +.Dd September 3, 2019 .Dt GPART 8 .Os .Sh NAME @@ -1198,7 +1198,13 @@ variables can be used to control the behavior of the GEOM class. The default value is shown next to each variable. .Bl -tag -width indent -.It Va kern.geom.part.auto_resize: No 1 +.It Va kern.geom.part.allow_nesting : No 0 +By default, some schemes (currently BSD, BSD64 and VTOC8) do not permit +further nested partitioning. +This variable overrides this restriction and allows arbitrary nesting (except +within partitions created at offset 0). +Some schemes have their own separate checks, for which see below. +.It Va kern.geom.part.auto_resize : No 1 This variable controls automatic resize behavior of .Nm GEOM class. @@ -1219,6 +1225,9 @@ disk metadata. If some inconsistency is detected, the partition table will be rejected with a diagnostic message: .Sy "GEOM_PART: Integrity check failed (provider, scheme)" . +.It Va kern.geom.part.gpt.allow_nesting : No 0 +By default the GPT scheme is allowed only at the outermost nesting level. +This variable allows this restriction to be removed. .It Va kern.geom.part.ldm.debug : No 0 Debug level of the Logical Disk Manager (LDM) module. This can be set to a number between 0 and 2 inclusive. Modified: stable/12/sys/geom/part/g_part.c ============================================================================== --- stable/12/sys/geom/part/g_part.c Mon Sep 9 17:37:52 2019 (r352083) +++ stable/12/sys/geom/part/g_part.c Mon Sep 9 17:43:44 2019 (r352084) @@ -143,6 +143,10 @@ static u_int auto_resize = 1; SYSCTL_UINT(_kern_geom_part, OID_AUTO, auto_resize, CTLFLAG_RWTUN, &auto_resize, 1, "Enable auto resize"); +static u_int allow_nesting = 0; +SYSCTL_UINT(_kern_geom_part, OID_AUTO, allow_nesting, + CTLFLAG_RWTUN, &allow_nesting, 0, + "Allow additional levels of nesting"); /* * The GEOM partitioning class. @@ -2264,7 +2268,13 @@ g_part_start(struct bio *bp) return; if (g_handleattr_int(bp, "GEOM::fwsectors", table->gpt_sectors)) return; - if (g_handleattr_int(bp, "PART::isleaf", table->gpt_isleaf)) + /* + * allow_nesting overrides "isleaf" to false _unless_ the + * provider offset is zero, since otherwise we would recurse. + */ + if (g_handleattr_int(bp, "PART::isleaf", + table->gpt_isleaf && + (allow_nesting == 0 || entry->gpe_offset == 0))) return; if (g_handleattr_int(bp, "PART::depth", table->gpt_depth)) return; Modified: stable/12/sys/geom/part/g_part_gpt.c ============================================================================== --- stable/12/sys/geom/part/g_part_gpt.c Mon Sep 9 17:37:52 2019 (r352083) +++ stable/12/sys/geom/part/g_part_gpt.c Mon Sep 9 17:43:44 2019 (r352084) @@ -53,6 +53,14 @@ __FBSDID("$FreeBSD$"); FEATURE(geom_part_gpt, "GEOM partitioning class for GPT partitions support"); +SYSCTL_DECL(_kern_geom_part); +static SYSCTL_NODE(_kern_geom_part, OID_AUTO, gpt, CTLFLAG_RW, 0, + "GEOM_PART_GPT GUID Partition Table"); + +static u_int allow_nesting = 0; +SYSCTL_UINT(_kern_geom_part_gpt, OID_AUTO, allow_nesting, + CTLFLAG_RWTUN, &allow_nesting, 0, "Allow GPT to be nested inside other schemes"); + CTASSERT(offsetof(struct gpt_hdr, padding) == 92); CTASSERT(sizeof(struct gpt_ent) == 128); @@ -651,8 +659,8 @@ g_part_gpt_create(struct g_part_table *basetable, stru struct g_part_gpt_table *table; size_t tblsz; - /* We don't nest, which means that our depth should be 0. */ - if (basetable->gpt_depth != 0) + /* Our depth should be 0 unless nesting was explicitly enabled. */ + if (!allow_nesting && basetable->gpt_depth != 0) return (ENXIO); table = (struct g_part_gpt_table *)basetable; @@ -814,8 +822,8 @@ g_part_gpt_probe(struct g_part_table *table, struct g_ u_char *buf; int error, index, pri, res; - /* We don't nest, which means that our depth should be 0. */ - if (table->gpt_depth != 0) + /* Our depth should be 0 unless nesting was explicitly enabled. */ + if (!allow_nesting && table->gpt_depth != 0) return (ENXIO); pp = cp->provider;