From nobody Sun Feb 19 06:48:29 2023 X-Original-To: dev-commits-src-branches@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 4PKGNF6MZxz3sqqj; Sun, 19 Feb 2023 06:48:29 +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 4PKGNF2YZjz3jS5; Sun, 19 Feb 2023 06:48:29 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1676789309; 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=Rs2Y8Aq7DfiPh0SrVpiH5igSNbNcKyRK0jTrD+KgrrQ=; b=XWLSjHSLYjKWFmMoMO13EFvhst+YI0tkfgkczbgCdHo5xVakvHXYIuTQwEhsCTlwHwZZZx DeKd9t4jQJaJaqMxJk0sqitKCIc1vbccK/7GK1tb5NXD0fgp1Z7UwaJjlxR95tYNp3m8v7 HXcFVCII9Y3INpQWljlSFtOb2mG0tLcBVV9aiQScR+pXjigy2bKa3aZwf0A3Sz7k/vj5yZ kAaGttE6ptNUSvvt20gOIP350PtvUwmzN3gnrt2GgwLaSvrhVhn6m+6VGYHV9TIJ5I49um DWeKV8SYEXjJ99EWP0AVQAqUL2/EyLZvwmI+6CkKG4EAyTemAgCAlOAkRDxSgQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1676789309; 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=Rs2Y8Aq7DfiPh0SrVpiH5igSNbNcKyRK0jTrD+KgrrQ=; b=P8b8vXr0jvCrd8enMvdA922148KnZYIiEGpjatRbxeNUQXXkmHt7u2eEX2fpEbfhv0ciCH ubU3vuTZ8dc7VpHLp4Jui/cXyLyOVa01ocgnDFPFHRnr97+Hns4Jdk1RqT4baDLbIkPt08 /CimJnqHhjNnI4KulEwPzgIavkYh0X2rb2aA7PXWoF320Df2oJWByRGpU4zK6DEYEJ/DWN cjE6Peh+Kn2UelD2q0My4i1igroGLCB/LF1w95vsnA3iJUqyMp52AEmxP7j29aeBa0J0Xq JbEo11IzwiNTFsM7QUtPwzeKbG4mzgYOjht88dxD7QEFKMx9/MwzeosBJu+aiw== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1676789309; a=rsa-sha256; cv=none; b=ppiM/o76czbcLAq0UycEufs0F/SpARk0DuD/+QeNBNVzMH6pX6ni1rMFBEg5RiavKZ1QfH BXHDAIMiC8OJraj8eqPUgnlS8IWv7B43mZhy/THrWs0ZggszcX2Ym9wrcX2fd23W4gZv1m WhgZ4gbsIVFYkEwTIFYQKxAwjXxgTssaBw2hx19VeNe5OyyJ3c0cOQ9XD3pXOwRmHV88Ok FuHnSpxCXfZn+eB6jD1PYEkK5n7d8q4GFggOfIuEOCZn8pxurBh6Hrh830IviOnxSNSEmM xjtL6f+QmGk5L2n+n/TPw0Xlhk5MMtca2h6b7xdFv9cnvKuXwd0Jo+g7pCLgBg== 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 4PKGNF1g0Yzs7y; Sun, 19 Feb 2023 06:48:29 +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 31J6mTqv082671; Sun, 19 Feb 2023 06:48:29 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 31J6mT5G082670; Sun, 19 Feb 2023 06:48:29 GMT (envelope-from git) Date: Sun, 19 Feb 2023 06:48:29 GMT Message-Id: <202302190648.31J6mT5G082670@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: 3cfda2537654 - releng/13.2 - efivar: Really look for labels for the provider with right efimedia List-Id: Commits to the stable branches of the FreeBSD src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-branches List-Help: List-Post: List-Subscribe: List-Unsubscribe: Sender: owner-dev-commits-src-branches@freebsd.org X-BeenThere: dev-commits-src-branches@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/13.2 X-Git-Reftype: branch X-Git-Commit: 3cfda25376542b65b459bc5af48b2fb0f200b552 Auto-Submitted: auto-generated X-ThisMailContainsUnwantedMimeParts: N The branch releng/13.2 has been updated by imp: URL: https://cgit.FreeBSD.org/src/commit/?id=3cfda25376542b65b459bc5af48b2fb0f200b552 commit 3cfda25376542b65b459bc5af48b2fb0f200b552 Author: Warner Losh AuthorDate: 2023-02-16 16:36:03 +0000 Commit: Warner Losh CommitDate: 2023-02-19 06:47:25 +0000 efivar: Really look for labels for the provider with right efimedia The prior code mistakently thought that the g_consumer that hung off the provider we found were the right thing to use to find all the glabel aliases for this node. However, the only way to find that is to iterate through all the geoms that belong to the glabel geom class, looking for those geoms with the same name as the provider with the right efimedia. Do this in a way that caches glabel class, and allows for it to be absent. Tighten the filter for mounted filesystems to only look for the ones that are mounted on /dev/.. since the rest of the code assumes that. MFC After: 3 days Sponsored by: Netflix Reviewed by: corvink, asomers Differential Revision: https://reviews.freebsd.org/D38619 Approved by: re@ (cperciva) (cherry picked from commit 2b460910326c4f39068fe2158a0726dc3d362f68) (cherry picked from commit f4d711e7209073404c821c9c26c7c17b87b61997) --- lib/libefivar/efivar-dp-xlate.c | 64 ++++++++++++++++++++++++++++++----------- 1 file changed, 47 insertions(+), 17 deletions(-) diff --git a/lib/libefivar/efivar-dp-xlate.c b/lib/libefivar/efivar-dp-xlate.c index 586ba7d08180..3d63868dacef 100644 --- a/lib/libefivar/efivar-dp-xlate.c +++ b/lib/libefivar/efivar-dp-xlate.c @@ -134,12 +134,15 @@ efi_hd_to_unix(struct gmesh *mesh, const_efidp dp, char **dev, char **relpath, c const_efidp media, file, walker; size_t len, mntlen; char buf[MAX_DP_TEXT_LEN]; - char *pwalk; + char *pwalk, *newdev = NULL; struct gprovider *pp, *provider; - struct gconsumer *cp; struct statfs *mnt; + struct gclass *glabel; + struct ggeom *gp; walker = media = dp; + *dev = NULL; + *relpath = NULL; /* * Now, we can either have a filepath node next, or the end. @@ -174,12 +177,6 @@ efi_hd_to_unix(struct gmesh *mesh, const_efidp dp, char **dev, char **relpath, c goto errout; } - *dev = strdup(pp->lg_name); - if (*dev == NULL) { - rv = ENOMEM; - goto errout; - } - /* * No file specified, just return the device. Don't even look * for a mountpoint. XXX Sane? @@ -217,6 +214,16 @@ efi_hd_to_unix(struct gmesh *mesh, const_efidp dp, char **dev, char **relpath, c rv = errno; goto errout; } + + /* + * Find glabel, if it exists. It's OK if not: we'll skip searching for + * labels. + */ + LIST_FOREACH(glabel, &mesh->lg_class, lg_class) { + if (strcmp(glabel->lg_name, G_LABEL) == 0) + break; + } + provider = pp; for (i = 0; i < n; i++) { /* @@ -225,30 +232,53 @@ efi_hd_to_unix(struct gmesh *mesh, const_efidp dp, char **dev, char **relpath, c * we'll need to invent one, but its decoding will be handled in * a separate function. */ - if (mnt[i].f_mntfromname[0] != '/') + if (strncmp(mnt[i].f_mntfromname, "/dev/", 5) != 0) continue; /* * First see if it is directly attached */ - if (strcmp(provider->lg_name, mnt[i].f_mntfromname + 5) == 0) + if (strcmp(provider->lg_name, mnt[i].f_mntfromname + 5) == 0) { + newdev = provider->lg_name; break; + } /* - * Next see if it is attached via one of the physical disk's - * labels. + * Next see if it is attached via one of the physical disk's labels. + * We can't search directly from the pointers we have for the + * provider, so we have to cast a wider net for all labels and + * filter those down to geoms whose name matches the PART provider + * we found the efimedia attribute on. */ - LIST_FOREACH(cp, &provider->lg_consumers, lg_consumer) { - pp = cp->lg_provider; - if (strcmp(pp->lg_geom->lg_class->lg_name, G_LABEL) != 0) + if (glabel == NULL) + continue; + LIST_FOREACH(gp, &glabel->lg_geom, lg_geom) { + if (strcmp(gp->lg_name, provider->lg_name) != 0) { continue; - if (strcmp(g_device_path(pp->lg_name), mnt[i].f_mntfromname) == 0) - goto break2; + } + LIST_FOREACH(pp, &gp->lg_provider, lg_provider) { + if (strcmp(pp->lg_name, mnt[i].f_mntfromname + 5) == 0) { + newdev = pp->lg_name; + goto break2; + } + } } /* Not the one, try the next mount point */ } break2: + /* + * If nothing better was mounted, then use the provider we found as + * is. It's the most correct thing we can return in that acse. + */ + if (newdev == NULL) + newdev = provider->lg_name; + *dev = strdup(newdev); + if (*dev == NULL) { + rv = ENOMEM; + goto errout; + } + /* * No mountpoint found, no absolute path possible */