From nobody Fri Feb 03 15:50:32 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 4P7g946B2Sz3kRbG; Fri, 3 Feb 2023 15:50:32 +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 4P7g945lfxz3H7s; Fri, 3 Feb 2023 15:50:32 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1675439432; 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=Y5tOV/CbkDWXLotB3/Gd8ucLNhLGsEhk8qGu2k5Uf2k=; b=fjwggha1Qz40VV9QoNUdxDMWyxalZDyU33pU+n1dGIORYGBHx33/JXea1ZxUjRTst6VYdo lxVdip1Ubx8H15P9sMP+/J+wozMVIryd4RpmZbEBawcJn/puw82+px1xpqKj8ONU/IPIF2 vQm7dsHaQsXoBO9VfaIZR7pWe811RRpgOzrTpHNdymFyH9D7OROuqEEdlMb8UsC5Qd92PV 9DFiR5ECcnQ9umC/PyljRC1qfvE8cWIRLxKVqr0ha6VPpOTDN7x3q7nJmHLKr6HQKD+W2h sKuvv1P59/trQIH4WrCHRVQV+QdjTRjXfUqA6aNiSjD2No1di5KqpLjEqOk9lw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1675439432; 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=Y5tOV/CbkDWXLotB3/Gd8ucLNhLGsEhk8qGu2k5Uf2k=; b=fCfClmQRViUKn9zGsAB8wyBHBIvkRP1Kf5XhB+n8DLetxBmmFzO/Zofoo9/cOrOegzLlCH cB4ngBS0Sc2qKwsgSxVXyHKwIc53Auo6sQRHobj7tmYp85dm80N0pDwT2MWjw63ZSadVJZ zgxKskq2nMJBg8F3UR0dNN7x2P/RnpYvVwbGVm3ilP+4/Wf9KH3jR5svk7tcxMr1cTBIx/ iPJOWVy+7XCD4E2/GlpvVh1RDQMh3UtFqNb1oi1Ha5Foyoj7lCsKmu6+OqkOqdWn6kewtz xJ+AbGyz0IMeT3CyeVyfAau0ZsN4rHVWQQcr64/VSttVa3lHZoQJvguksP8lqQ== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1675439432; a=rsa-sha256; cv=none; b=cbzUncUNf3U9B0uw50Ug8mlr99WyTyUOnTGePdKc88DTn334z1syeGEXjnht5jXzG+8nDL 3E/JQo1kMeFOauQb7ddJekhy34wlY/UpmHKEh1Gv0b7wt+9XMaFSUMg8DoNBRl01KD4npy exbbZwsEtKqHlC/pF0DZwJJVKxatkwZBBWT14g1iMFhio0sX116AkPHN96LUuBAazyYPHQ b4VjBCfdlRFFe7JKSqgMRhIZ/MqW1/aSyK9P/VtLJ7YRFrp3uael2/xe2wU0p86YKSOm58 KN1tNoCxOq825Cr8Iy24pJvpRIp9GLhSz8FEQY6DBone6F8W0psgMa/dcs0O7A== 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 4P7g944pT9zgB0; Fri, 3 Feb 2023 15:50:32 +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 313FoWw9022849; Fri, 3 Feb 2023 15:50:32 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 313FoWFL022848; Fri, 3 Feb 2023 15:50:32 GMT (envelope-from git) Date: Fri, 3 Feb 2023 15:50:32 GMT Message-Id: <202302031550.313FoWFL022848@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Warner Losh Subject: git: d76330efd9f9 - main - kboot: Probe all disks and partitions for a kernel 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/main X-Git-Reftype: branch X-Git-Commit: d76330efd9f970c3d0e5b848f6ba330b1bd1ee3d Auto-Submitted: auto-generated X-ThisMailContainsUnwantedMimeParts: N The branch main has been updated by imp: URL: https://cgit.FreeBSD.org/src/commit/?id=d76330efd9f970c3d0e5b848f6ba330b1bd1ee3d commit d76330efd9f970c3d0e5b848f6ba330b1bd1ee3d Author: Warner Losh AuthorDate: 2023-02-03 15:37:31 +0000 Commit: Warner Losh CommitDate: 2023-02-03 15:41:38 +0000 kboot: Probe all disks and partitions for a kernel Guess where to boot from when bootdev= isn't on the command line or other config. Search all the disks and partitions for one that looks like it could be a boot partition (same as we do when probing zpools). Return the first one we find. Sponsored by: Netflix Reviewed by: tsoome Differential Revision: https://reviews.freebsd.org/D38319 --- stand/kboot/hostdisk.c | 69 ++++++++++++++++++++++++++++++++++++++++---------- stand/kboot/kboot.h | 1 + stand/kboot/main.c | 2 ++ 3 files changed, 58 insertions(+), 14 deletions(-) diff --git a/stand/kboot/hostdisk.c b/stand/kboot/hostdisk.c index 3c924293223a..b71ae256b0f6 100644 --- a/stand/kboot/hostdisk.c +++ b/stand/kboot/hostdisk.c @@ -488,6 +488,61 @@ hostdisk_parsedev(struct devdesc **idev, const char *devspec, const char **path) return (0); } +/* XXX refactor */ +static bool +sanity_check_currdev(void) +{ + struct stat st; + + return (stat(PATH_DEFAULTS_LOADER_CONF, &st) == 0 || +#ifdef PATH_BOOTABLE_TOKEN + stat(PATH_BOOTABLE_TOKEN, &st) == 0 || /* non-standard layout */ +#endif + stat(PATH_KERNEL, &st) == 0); +} + +static const char * +hostdisk_try_one(hdinfo_t *hd) +{ + char *fn; + + if (asprintf(&fn, "%s:", hd->hd_dev) == -1) + return (NULL); + set_currdev(fn); + printf("Trying %s\n", fn); + if (sanity_check_currdev()) + return (fn); + printf("Failed %s\n", fn); + free(fn); + return (NULL); +} + +const char * +hostdisk_gen_probe(void) +{ + hdinfo_t *hd, *md; + const char *rv = NULL; + + STAILQ_FOREACH(hd, &hdinfo, hd_link) { + /* try whole disk */ + if (hd->hd_flags & HDF_HAS_ZPOOL) + continue; + rv = hostdisk_try_one(hd); + if (rv != NULL) + return (rv); + + /* try all partitions */ + STAILQ_FOREACH(md, &hd->hd_children, hd_link) { + if (md->hd_flags & HDF_HAS_ZPOOL) + continue; + rv = hostdisk_try_one(md); + if (rv != NULL) + return (rv); + } + } + return (false); +} + #ifdef LOADER_ZFS_SUPPORT static bool hostdisk_zfs_check_one(hdinfo_t *hd) @@ -524,19 +579,6 @@ hostdisk_zfs_probe(void) } } -/* XXX refactor */ -static bool -sanity_check_currdev(void) -{ - struct stat st; - - return (stat(PATH_DEFAULTS_LOADER_CONF, &st) == 0 || -#ifdef PATH_BOOTABLE_TOKEN - stat(PATH_BOOTABLE_TOKEN, &st) == 0 || /* non-standard layout */ -#endif - stat(PATH_KERNEL, &st) == 0); -} - /* This likely shoud move to libsa/zfs/zfs.c and be used by at least EFI booting */ static bool probe_zfs_currdev(uint64_t pool_guid, uint64_t root_guid, bool setcurrdev) @@ -599,5 +641,4 @@ hostdisk_zfs_find_default(void) } return (false); } - #endif diff --git a/stand/kboot/kboot.h b/stand/kboot/kboot.h index 58cbedff67a1..d7e406f86d7a 100644 --- a/stand/kboot/kboot.h +++ b/stand/kboot/kboot.h @@ -22,6 +22,7 @@ uint8_t kboot_get_kernel_machine_bits(void); /* hostdisk.c */ extern const char *hostfs_root; +const char *hostdisk_gen_probe(void); void hostdisk_zfs_probe(void); bool hostdisk_zfs_find_default(void); diff --git a/stand/kboot/main.c b/stand/kboot/main.c index e8320503647f..b8523cb202a2 100644 --- a/stand/kboot/main.c +++ b/stand/kboot/main.c @@ -221,6 +221,8 @@ main(int argc, const char **argv) devinit(); bootdev = getenv("bootdev"); + if (bootdev == NULL) + bootdev = hostdisk_gen_probe(); if (bootdev == NULL) bootdev="zfs:"; hostfs_root = getenv("hostfs_root");