From nobody Wed Nov 30 22:31:27 2022 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 4NMv7g4km0z4jCGY; Wed, 30 Nov 2022 22:31:27 +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 4NMv7g3PGwz44R6; Wed, 30 Nov 2022 22:31:27 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1669847487; 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=p2vxxvsDjN7an02UoOAH+Rc2IXvQ7a7jcj/GWu4yhzI=; b=HXK/Lig/P6se6WIbXxV9ctTXPxp7RgkXtq5Ic/68ZOWlVX5u6nZOfWC4rKfky6InH3R41/ I66Cl+1u+zw9jhBTSkw3pLER14Ktl5z+/1k7qA/EBjSnpqe/iTC1TnD0ZT9xtWOM+Hy/jj 9x1p26oRsl8Jb1JB5eL/whNWLwY1smUqbpk96A8ZesDB5+nYyh3K5Aot3ITGE7yckKGxPi 4xyNiCqS/iTFfbF4zGo5zKX4pqyBGAo5ds+5x7YUep+EElNMrQGvXBhQ8FZDXcR3ZcKtpk 8T0Cva4xx6oce4YnQ/JcwBF+JhEXfld5ZEa0xWC9Qq5PFFwJS80egl5ibZtqlg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1669847487; 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=p2vxxvsDjN7an02UoOAH+Rc2IXvQ7a7jcj/GWu4yhzI=; b=Mr1zIFDgqH7eWxPh1dGv7wd8hrZop8cwdIY9T2H9dx9lzu1gC2xCH1AeOFcS7h7hydKMp3 bXUhiDiQ1Gr8LC6X35xH/omwV6Al0OVJQMQV2QxxrLx9Y9H/G8bhcPa+PyO1CfJnfaxBb+ aI8/xaFj/do6PPJScLbhC0TdAcW9VDtuKa1EOBJ1nFRZqYmB2YQbQdrT+0l1L2O50vV64O k0LKM5rEpWi7GAeKbcKek9+RYPtrM6llF4i4HHzw+6cYeT3aCkD8raSf/M/dogMDuPkDxO OKXWFRw2RLXipAfyvsitHU201uRwFezzm4YOvesJUo9cyxKlNqXUurzXPMDqKw== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1669847487; a=rsa-sha256; cv=none; b=ovHO0CSsu+w7g3Zn3sqiPEVWua2G5TOzYO2eJUiDHBG+ZMjOXNGrK6XXEefkfPHp5WmF/e AFZIyMzQp9HVu92kH6CdZVTvh2gWOYA5lDX0i5SARN1ke46OJFlY9fuM99cNt4i75wsCKN HvXO44Jc8LZnyIJXIgtQX2kJJ7aHcUk0YvS8hh0aFtXf7WgbdnETNMSycZOEnBqzZ4RYny 9CWN/G6BLlV2NLS9Brfmjkjc8nk7eSfQVwASifh28iVpkpb8/6mrheQYTzSJ4igPvPqcCA X9na76cxonNdTZ+3fIAiRNqhYabVM0FOBsxBXt3bDnAURPwveQpdqUs3Qk68gw== 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 4NMv7g1yJjz1Cth; Wed, 30 Nov 2022 22:31:27 +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 2AUMVR5n023631; Wed, 30 Nov 2022 22:31:27 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 2AUMVRXw023630; Wed, 30 Nov 2022 22:31:27 GMT (envelope-from git) Date: Wed, 30 Nov 2022 22:31:27 GMT Message-Id: <202211302231.2AUMVRXw023630@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: a07cef5a7386 - main - stand: Add dv_match 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: a07cef5a738642ae0a39fa513945d9f867a5e2f1 Auto-Submitted: auto-generated X-ThisMailContainsUnwantedMimeParts: N The branch main has been updated by imp: URL: https://cgit.FreeBSD.org/src/commit/?id=a07cef5a738642ae0a39fa513945d9f867a5e2f1 commit a07cef5a738642ae0a39fa513945d9f867a5e2f1 Author: Warner Losh AuthorDate: 2022-11-30 22:09:51 +0000 Commit: Warner Losh CommitDate: 2022-11-30 22:30:33 +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 --- 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 *); }; /*