From nobody Thu Feb 16 15:58:51 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 4PHfkg5Y8Zz3r745; Thu, 16 Feb 2023 15:58:51 +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 4PHfkg53RRz3xpD; Thu, 16 Feb 2023 15:58:51 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1676563131; 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=MuGyrMoSHJkHKh2dKvHdzhgus1fuTJoYDKhFRRgmobk=; b=PMLDXi96tInetg+1cQDbYY77+OiTmpgtmnxD64KGlg/bO2+DzNtRVpTytHdOMFrrgAQIJr LpG6RCK2E8DTOYxz6j8VbPWIYPozZ9HbBnfDVAFf0fB2iyxgqHn11mbYumXt63wPtZIrRS 99qyVUKnfjBX6B9XLIHMrakYL5fQIkasu6TGNVrIbYND8ZJ94IkcwHliZxE7cZUa6/RgcW l6vhqD7sA4dOe8bSm9PM79nci0CvPDJVbza+Cxnn0xxUfbSXzTxRB0bW1ofBbBuqTG//MP S+BPin7hUCOEXRFHJJC2uTmu/+f3XvkB+QRIZiCYdGjlRnOx3peCTxrBv/Us6w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1676563131; 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=MuGyrMoSHJkHKh2dKvHdzhgus1fuTJoYDKhFRRgmobk=; b=p9yhDI66lFcvrkOEDFWyyK+faNAs7HNF1BAH1HAhqpg1zB2oJeil4s+mQeXfNt+itoGeaX bbNOCCNXrY2BVeqqU4XlLI6GvcrvC5qnXKLkzye2WJRxN97r5rfT2pv8MHrwdoIQXC8MWq Ykkqw5kuxBoGHurnFIKyoKi2M8Tvb3mFdRvGvAKbye8DW9yONue03+EqTgHey5F0c3BPab ksEYitMmknnU7yO2wKo+JVM70IvU+fJBZ/mLEes2+NGWo7RrW/8DcGly1DCDJuR8BPHQQC oXKTaMrzharLKRO/7sK2mw9qpg/axVmCIF2r8ZkSexIteHXajkwlUGH9mKDRrg== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1676563131; a=rsa-sha256; cv=none; b=dpK6s/V8CyM6ToTugB7mJ9N8B4egFYH2a5cekhDSa1s0m8BWf79Cu+4HXn2TpBUsynULuS l6LLBEPpMU2iIEOR27GkYI/cP8LytGEJ54uVnAgWbVaMPNXpI8xGh3wBHrimjQFps5cTYC QdwwE8qU6rd9o4u4Hl6/sGC5v7JwyZUNReR3xAyVyzw+hM20gxt8kaagD+S9+g2H8wjN4Q b8Rsnfqo0KM2bee3iaenwBNE0olZulnoqUsr6drAqaKfx174cVhZ9JT1lJ4gRYxdO1brn2 Djbd/f1cfv7/fh/irYmAU4RoNn2XYjlxH6qjPp/95pjhec6aKT09G5QdPMOUyg== 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 4PHfkg48vQz18Yp; Thu, 16 Feb 2023 15:58:51 +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 31GFwpnq000078; Thu, 16 Feb 2023 15:58:51 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 31GFwpiO000077; Thu, 16 Feb 2023 15:58:51 GMT (envelope-from git) Date: Thu, 16 Feb 2023 15:58:51 GMT Message-Id: <202302161558.31GFwpiO000077@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: 2b460910326c - main - 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/main X-Git-Reftype: branch X-Git-Commit: 2b460910326c4f39068fe2158a0726dc3d362f68 Auto-Submitted: auto-generated X-ThisMailContainsUnwantedMimeParts: N The branch main has been updated by imp: URL: https://cgit.FreeBSD.org/src/commit/?id=2b460910326c4f39068fe2158a0726dc3d362f68 commit 2b460910326c4f39068fe2158a0726dc3d362f68 Author: Warner Losh AuthorDate: 2023-02-16 15:53:53 +0000 Commit: Warner Losh CommitDate: 2023-02-16 15:54:39 +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 --- 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 */