From nobody Tue Jan 24 22:13:25 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 4P1h7V032Yz3bgLX; Tue, 24 Jan 2023 22:13:26 +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 4P1h7T6SQ9z3Gkl; Tue, 24 Jan 2023 22:13:25 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1674598405; 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=94pxIxkcRkexLmhQDfTGr7gZZEb0O0ybHpdTEqhJSCI=; b=hlwRrMKXKW4xI80Ifsd0uwFfTGf00LLNJ1vhoAFAK+GTFAVxmgGY7QidwBFZMgbVsYISJc 4t50bn2FVBS07BcKvOA76CukA7epaJmGW8Yvk+1sN6ixvt1ceJ2afwv/GWkzmWBi15/cg5 7XxWHgU9KPxlvhGUl/KvfwKlB7PomLQ1B+teBnfHgn+B10AVH0HaLjMONi+PZymr524lEL 419gjwRcf0FvbDL1wHgqwh4in5ir/N7PPzfJCOfusaC6UHMpE8aR4YmNdWHaLm9teZN51A AJGbtvR+8mwQzhZXLq51eABcpMXOWsUWwSuAXocC8feJPtaPXMJ5c8X70QLOUw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1674598405; 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=94pxIxkcRkexLmhQDfTGr7gZZEb0O0ybHpdTEqhJSCI=; b=QeJeprNvRtvsHInoiYWe/92GWSddMhrkIBe+NuwGQyd+wfIjyAPv3pcb2Xc1YQVJadLWLx y06wE/byQuHm93KZIS7KGVHfQiji8zTG+J3LY0uni1BNy7A6NsUjVplkwjDO+ex2vxU5YN GzW77baLDpeY9EIYAuaSYoke6Kzjkuzyd1HYBfKE+RGVkLu0o7octXXhTe/YQH59YDC94c EawmmRNclSlrWcGT+WYbmrUvdkm2gaRe3yB3/Sldy0aaCUNjPkQBSOgkXGUNOrjynYkQ3J K51blw0bDYhsLO30DEmbvqqtbs2RHMLyTZiwIkZTC00GGnn3pybZIrFjJnZzjw== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1674598405; a=rsa-sha256; cv=none; b=W91tkZ6MyF+VY7qlWfYmEQO5PWr1Fsc7Gmhi5eJ486zkEm8m+CyZtH62PfOyh3yO1xTZ4L AR5Z6anoGb0XS9sli9mr7hHuRAACjidb6pOjtnNAKR8c5RXHDwNuERQXprnwqPDgFTIsRK pThLmA514cS0aw4RZLS5d5cU9Zf/nnTOn3+bQEseiM9RDN1HZdLJIFIbrxepDWiKgxxCwe KEHS4zRoYI1kWK+HsHifA6JOgg2g4vxTafdWCyFUsNaFFFJlHqBQevMPNTgOxlrgKxI4yM ZwXStca7okrguZOBA3IYKowxFFLlysbvNQ9rrlJ5/DSmNVYuMRxpoANemXItNQ== 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 4P1h7T5Y50zQmT; Tue, 24 Jan 2023 22:13:25 +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 30OMDP5c088413; Tue, 24 Jan 2023 22:13:25 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 30OMDPpg088412; Tue, 24 Jan 2023 22:13:25 GMT (envelope-from git) Date: Tue, 24 Jan 2023 22:13:25 GMT Message-Id: <202301242213.30OMDPpg088412@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: 91cce9c871a6 - stable/13 - stand: Add dv_match 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/stable/13 X-Git-Reftype: branch X-Git-Commit: 91cce9c871a6d367a68ae1ada0d8e73fad994301 Auto-Submitted: auto-generated X-ThisMailContainsUnwantedMimeParts: N The branch stable/13 has been updated by imp: URL: https://cgit.FreeBSD.org/src/commit/?id=91cce9c871a6d367a68ae1ada0d8e73fad994301 commit 91cce9c871a6d367a68ae1ada0d8e73fad994301 Author: Warner Losh AuthorDate: 2022-11-30 22:09:51 +0000 Commit: Warner Losh CommitDate: 2023-01-24 21:49:40 +0000 stand: Add dv_match On OpenFirmware, and possibly kboot, we use full path names for the objects that are the 'device'. kboot uses a hack of knowing that all disk device nodes start with '/dev', but this generalizes it for OpenFirmware where both 'block' and 'network' devices live in the same namespace and one must ask the OF node its type to know if this device type matches. For drivers that don't specify, the current convention of using strncmp() is retained. This is done only in devparse(), but everything uses it directly (or will soon). Sponsored by: Netflix Differential Revision: https://reviews.freebsd.org/D37554 (cherry picked from commit a07cef5a738642ae0a39fa513945d9f867a5e2f1) --- stand/libsa/dev.c | 9 +++++++-- stand/libsa/libsa.3 | 12 ++++++++++++ stand/libsa/stand.h | 1 + 3 files changed, 20 insertions(+), 2 deletions(-) diff --git a/stand/libsa/dev.c b/stand/libsa/dev.c index b16637181059..b273edb4457e 100644 --- a/stand/libsa/dev.c +++ b/stand/libsa/dev.c @@ -126,8 +126,13 @@ devparse(struct devdesc **dev, const char *devspec, const char **path) /* look for a device that matches */ for (i = 0; devsw[i] != NULL; i++) { dv = devsw[i]; - if (!strncmp(devspec, dv->dv_name, strlen(dv->dv_name))) - break; + if (dv->dv_match != NULL) { + if (dv->dv_match(dv, devspec) != 0) + break; + } else { + if (!strncmp(devspec, dv->dv_name, strlen(dv->dv_name))) + break; + } } if (devsw[i] == NULL) return (ENOENT); diff --git a/stand/libsa/libsa.3 b/stand/libsa/libsa.3 index fcfd22cbf0d0..8e504ca2585d 100644 --- a/stand/libsa/libsa.3 +++ b/stand/libsa/libsa.3 @@ -750,6 +750,7 @@ struct devsw { char * (*dv_fmtdev)(struct devdesc *); int (*dv_parsedev)(struct devdesc **dev, const char *devpart, const char **path); + bool (*dv_match)(struct devsw *dv, const char *devspec); }; .Ed .Bl -tag -width ".Fn dv_strategy" @@ -823,6 +824,17 @@ in the earlier example. Generally, code needing to parse a path will use .Fa devparse instead of calling this routine directly. +.It Fn dv_match +.Dv NULL +to specify that all device paths starting with +.Fa dv_name +match. +Otherwise, this function returns 0 for a match and a non-zero +.Dv errno +to indicate why it didn't match. +This is helpful when you claim the device path after using it to query +properties on systems that have uniform naming for different types of +devices. .El .Sh HISTORY The diff --git a/stand/libsa/stand.h b/stand/libsa/stand.h index 660337db6980..b1c48bd88b39 100644 --- a/stand/libsa/stand.h +++ b/stand/libsa/stand.h @@ -161,6 +161,7 @@ struct devsw { void (*dv_cleanup)(void); char * (*dv_fmtdev)(struct devdesc *); int (*dv_parsedev)(struct devdesc **, const char *, const char **); + bool (*dv_match)(struct devsw *, const char *); }; /*