From nobody Tue Mar 8 19:01:08 2022 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 348CF1A1380C; Tue, 8 Mar 2022 19:01:09 +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 4KCl6D5xt7z3KP1; Tue, 8 Mar 2022 19:01:08 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1646766068; 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=h6Iim5NAP1niiso+Jxt1EnVxedHkzXj0D7gQc1Fe/Vs=; b=b4+78+N+ZmNaHyuT7vgGUCsMvlekh/w7c+6Jyh2gabI2BeYmNHgvuN+N2r4Rae+T7zas6/ oAuXs9wRnXejSGmX3pICFOHmzBhXnzPMaDnXWAnlLyXuXsCLwGwMBz3ntiLR99cttAGSYI ARt1sjcUz9Xxm6NmjIVCqPxa6odXCDx6avp6h5KNKgrnFYNBqw4ZkxeEKlr0v601rg/Lid wrhxgX4fdFgCEDST3hdc3fZlC4nFtliqtuWf7hoF9inRihDXRk/08bfGe9/iFBBg1zZVaw +iIkZFNtS5FrgqCYZilyCSnN6r8o32cgwAqPI62D7IiLVbylxDRPXA5L+2NSpA== 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 81C2F22128; Tue, 8 Mar 2022 19:01:08 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.16.1/8.16.1) with ESMTP id 228J18X6077779; Tue, 8 Mar 2022 19:01:08 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 228J18hh077778; Tue, 8 Mar 2022 19:01:08 GMT (envelope-from git) Date: Tue, 8 Mar 2022 19:01:08 GMT Message-Id: <202203081901.228J18hh077778@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Alexander Motin Subject: git: 5c20bfc78706 - main - gpart: Avoid geom_gettree() call in "bootcode -b". 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: Sender: owner-dev-commits-src-main@freebsd.org X-BeenThere: dev-commits-src-main@freebsd.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: mav X-Git-Repository: src X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: 5c20bfc78706d2fe6e262ddb55af0a8b928d3835 Auto-Submitted: auto-generated ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1646766068; 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=h6Iim5NAP1niiso+Jxt1EnVxedHkzXj0D7gQc1Fe/Vs=; b=F0joQfREw3U3a2l4XtY2DZVBX3KzypwgdaosuH5fHW97AdP6SpbEfqvP8B8phY3KrjZ0V1 uayemXwTavXhfq6YSu5aokzatvugVW3bbx/hU/JF8quzJcnKLFSgRccIfADv4Vd/YiGpMH szV5lOpmeR1GJ2hMcIL/696jycNITkqPhMj5UBBY03ESayXiWj7Tw1kY0SPabRF/PjxQ9A tgHMhFSoySVQZKAdWNofQE0Oh6hwyPiDzyjfuvwgBh3mr8CJiRPNZF4ER4LawsvFx19XHl 1gYNsRqqUyrYJupvOAj3fyzyNgPZyRPdxoGucUJp9b/13DQ2KFgGu/LLP11wYA== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1646766068; a=rsa-sha256; cv=none; b=buFaP/v6dXtJ5KgFArqAcmhRO/aPsOrv/Zs4Hpz/MYh01JhBNjGwqYwYOiZiaxz+bjbhV7 DQ99kyVcyqRzpC/9DcPJHfmvkC5KnQ+TnjgMlpq7NZFaarRlYN0p+5W8DZMf1yDz0KGloD gRNKS2koZmh3EN+oMeCy3hrh1OgaA6BCm0g+WEzRgK5YHiRI+qAeKabaTQno2SpMrwN1+g pWLOuAagZrEev322RMCQN+aftQIhHeEx7pulmw4UxU51xYE11OJDvhD6uVKR8a7ZkGx3qW qpVW1DVq0W+Ivxc9bV/0g2jWDdGY/hMUi2PPug2uzax845RawrBIkm3KvA69rg== ARC-Authentication-Results: i=1; mx1.freebsd.org; none X-ThisMailContainsUnwantedMimeParts: N The branch main has been updated by mav: URL: https://cgit.FreeBSD.org/src/commit/?id=5c20bfc78706d2fe6e262ddb55af0a8b928d3835 commit 5c20bfc78706d2fe6e262ddb55af0a8b928d3835 Author: Alexander Motin AuthorDate: 2022-03-08 18:44:22 +0000 Commit: Alexander Motin CommitDate: 2022-03-08 19:01:04 +0000 gpart: Avoid geom_gettree() call in "bootcode -b". geom_gettree() may be pretty expensive on large systems, and it is not needed if only -b flag specified, that is processed by kernel. MFC after: 1 month --- lib/geom/part/geom_part.c | 45 +++++++++++++++++++++++---------------------- 1 file changed, 23 insertions(+), 22 deletions(-) diff --git a/lib/geom/part/geom_part.c b/lib/geom/part/geom_part.c index 41131646e246..330a4708251d 100644 --- a/lib/geom/part/geom_part.c +++ b/lib/geom/part/geom_part.c @@ -1217,6 +1217,14 @@ gpart_bootcode(struct gctl_req *req, unsigned int fl) } else bootcode = NULL; + if (!gctl_has_param(req, GPART_PARAM_PARTCODE)) { + if (bootcode == NULL) + errx(EXIT_FAILURE, "neither -b nor -p specified"); + if (gctl_has_param(req, GPART_PARAM_INDEX)) + errx(EXIT_FAILURE, "-i is only valid with -p"); + goto nopartcode; + } + s = gctl_get_ascii(req, "class"); if (s == NULL) abort(); @@ -1244,22 +1252,7 @@ gpart_bootcode(struct gctl_req *req, unsigned int fl) else vtoc8 = 0; - if (gctl_has_param(req, GPART_PARAM_PARTCODE)) { - s = gctl_get_ascii(req, GPART_PARAM_PARTCODE); - if (vtoc8 != 0) - partsize = VTOC_BOOTSIZE; - else - partsize = 1024 * 1024; /* Arbitrary limit. */ - partcode = gpart_bootfile_read(s, &partsize); - error = gctl_delete_param(req, GPART_PARAM_PARTCODE); - if (error) - errc(EXIT_FAILURE, error, "internal error"); - } else - partcode = NULL; - if (gctl_has_param(req, GPART_PARAM_INDEX)) { - if (partcode == NULL) - errx(EXIT_FAILURE, "-i is only valid with -p"); idx = (int)gctl_get_intmax(req, GPART_PARAM_INDEX); if (idx < 1) errx(EXIT_FAILURE, "invalid partition index"); @@ -1269,7 +1262,16 @@ gpart_bootcode(struct gctl_req *req, unsigned int fl) } else idx = 0; - if (partcode != NULL) { + if (gctl_has_param(req, GPART_PARAM_PARTCODE)) { + s = gctl_get_ascii(req, GPART_PARAM_PARTCODE); + if (vtoc8 != 0) + partsize = VTOC_BOOTSIZE; + else + partsize = 1024 * 1024; /* Arbitrary limit. */ + partcode = gpart_bootfile_read(s, &partsize); + error = gctl_delete_param(req, GPART_PARAM_PARTCODE); + if (error) + errc(EXIT_FAILURE, error, "internal error"); if (vtoc8 == 0) { if (idx == 0) errx(EXIT_FAILURE, "missing -i option"); @@ -1279,15 +1281,14 @@ gpart_bootcode(struct gctl_req *req, unsigned int fl) errx(EXIT_FAILURE, "invalid bootcode"); gpart_write_partcode_vtoc8(gp, idx, partcode); } - } else - if (bootcode == NULL) - errx(EXIT_FAILURE, "no -b nor -p"); + free(partcode); + } + geom_deletetree(&mesh); + +nopartcode: if (bootcode != NULL) gpart_issue(req, fl); - - geom_deletetree(&mesh); - free(partcode); } static void