From nobody Sun Feb 19 00:48:41 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 4PK6P61TYJz3s8vf; Sun, 19 Feb 2023 00:48:42 +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 4PK6P56hT9z43by; Sun, 19 Feb 2023 00:48:41 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1676767721; 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=GehJUUVawgy7JaIlcG3mmuAhZI+J9vmOpiX2apLK+mY=; b=xo2ntETRDc+yzMU6F0IV3Z/+bhMC0nStG0YuuXUZ2rojcXPgItHivG8QG63DnPXZxIwBAa dV0D/iBRPZ+WggV+Jr5RJhVVdmTbtdEHvT12FF2Fp8eCGRj6aMP5vgkiToPjV3E0h4rG1Q 5+4SCOpoVWifCt4/mwFepETjliyEPgY+/65fM4c/7kpy8sliE5Fi+d8/+OCrEHiB4yGcEn llYIL9aUTjjpmZd3FdZz817ZWwZWeZa/VMEXD8jfW2eZLqDv+ObPyZQYBWo1L+WTjgv+5B dHPgClYttNu1FWCBEL9jWlhGT/iNcZ4fKOhlLybFkhkbMLNLi3dbVBgL7uYmtg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1676767721; 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=GehJUUVawgy7JaIlcG3mmuAhZI+J9vmOpiX2apLK+mY=; b=B+9I8wFpJiItlk6kh4uJQh34QJE6IL5B/YTTTG2QKWTAHN2WIR5iAS0P7NIoUruoimMLE4 lHHuCHgxydoS/PzK+2bvXj5PjsJp4Xdj2sgDIjkMh8rhsM36av2ePihiPbna1HVDKOtEhM nWNKaJPESr8/P9X2pV8zw0uUyBt9O1cWuYlqgRjdFOQixj0Rv+fGemdiNUrFg7qdlrv8By +vddq1NS5ycOm0q2fPtG/Wqc7h2UkV1JDo+pVtSMHbzP+ENx9cDG28Xpyeq0KbGy2i2JFJ FM1/cWVCL/xEWMsf0qPz6EInHYiqe7kHZKbPlZUJoI7b3ns9yv7NP9ShCWQN/w== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1676767721; a=rsa-sha256; cv=none; b=oxihPRxD4dWi3ctvDIpQPCz2ewqWHUJnbDHupPSYgFuSXFIsLSZCVpC91yccLEd8lFU7MC NKH8pqYc3KhUc9xB7v113H8WMzR9ZJO5GgNLhartSJRVYAkYhSF/FDRVFIcKeTBtbIvWev C3iKuSA+4fyiDRK7GppokuGVdxdZKK8+/z6ezIphjfqKZxFyCng2+gYOYEKGzz9ioGKmSl /opzQU1TB46DZKZUWo3fXg7Rby4QJIVhJ8vJ5I6UNwNN+jjKjLJ2Bro250C4qJ4VDn7nf0 Afvsy5Sk7Gu/QjEPMdX8TL47ObFuu5pUU6cUW46B2VSexleBppQ2sFAlXeqoig== 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 4PK6P55mZPzj9M; Sun, 19 Feb 2023 00:48:41 +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 31J0mfdk069665; Sun, 19 Feb 2023 00:48:41 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 31J0mfX8069664; Sun, 19 Feb 2023 00:48:41 GMT (envelope-from git) Date: Sun, 19 Feb 2023 00:48:41 GMT Message-Id: <202302190048.31J0mfX8069664@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: f4d711e72090 - stable/13 - efivar: Really look for labels for the provider with right efimedia 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/stable/13 X-Git-Reftype: branch X-Git-Commit: f4d711e7209073404c821c9c26c7c17b87b61997 Auto-Submitted: auto-generated X-ThisMailContainsUnwantedMimeParts: N The branch stable/13 has been updated by imp: URL: https://cgit.FreeBSD.org/src/commit/?id=f4d711e7209073404c821c9c26c7c17b87b61997 commit f4d711e7209073404c821c9c26c7c17b87b61997 Author: Warner Losh AuthorDate: 2023-02-16 16:36:03 +0000 Commit: Warner Losh CommitDate: 2023-02-19 00:46:58 +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 (cherry picked from commit 2b460910326c4f39068fe2158a0726dc3d362f68) --- 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 */