From owner-svn-src-all@freebsd.org Thu Dec 21 18:51:48 2017 Return-Path: Delivered-To: svn-src-all@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id 657B9E82C4E; Thu, 21 Dec 2017 18:51:48 +0000 (UTC) (envelope-from imp@FreeBSD.org) Received: from repo.freebsd.org (repo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mx1.freebsd.org (Postfix) with ESMTPS id 3D39873656; Thu, 21 Dec 2017 18:51:48 +0000 (UTC) (envelope-from imp@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id vBLIpldA084269; Thu, 21 Dec 2017 18:51:47 GMT (envelope-from imp@FreeBSD.org) Received: (from imp@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id vBLIpl64084267; Thu, 21 Dec 2017 18:51:47 GMT (envelope-from imp@FreeBSD.org) Message-Id: <201712211851.vBLIpl64084267@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: imp set sender to imp@FreeBSD.org using -f From: Warner Losh Date: Thu, 21 Dec 2017 18:51:47 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r327066 - head/usr.sbin/devinfo X-SVN-Group: head X-SVN-Commit-Author: imp X-SVN-Commit-Paths: head/usr.sbin/devinfo X-SVN-Commit-Revision: 327066 X-SVN-Commit-Repository: base MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-all@freebsd.org X-Mailman-Version: 2.1.25 Precedence: list List-Id: "SVN commit messages for the entire src tree \(except for " user" and " projects" \)" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 21 Dec 2017 18:51:48 -0000 Author: imp Date: Thu Dec 21 18:51:47 2017 New Revision: 327066 URL: https://svnweb.freebsd.org/changeset/base/327066 Log: Implement "-p dev" to print the path to the given device back to the nexus. With redirection, could also be used to test if the device exists in the device tree. Sponsored by: Netflix Modified: head/usr.sbin/devinfo/devinfo.8 head/usr.sbin/devinfo/devinfo.c Modified: head/usr.sbin/devinfo/devinfo.8 ============================================================================== --- head/usr.sbin/devinfo/devinfo.8 Thu Dec 21 18:30:11 2017 (r327065) +++ head/usr.sbin/devinfo/devinfo.8 Thu Dec 21 18:51:47 2017 (r327066) @@ -38,6 +38,8 @@ .Op Fl rv .Nm .Fl u +.Nm +.Fl p dev .Sh DESCRIPTION The .Nm @@ -62,6 +64,8 @@ the IRQ consumers together. Display all devices in the driver tree, not just those that are attached or busy. Without this flag, only those devices that have attached are reported. +.It Fl p dev +Display the path of dev back to the root of the device tree. .El .Sh SEE ALSO .Xr systat 1 , Modified: head/usr.sbin/devinfo/devinfo.c ============================================================================== --- head/usr.sbin/devinfo/devinfo.c Thu Dec 21 18:30:11 2017 (r327065) +++ head/usr.sbin/devinfo/devinfo.c Thu Dec 21 18:51:47 2017 (r327066) @@ -38,6 +38,7 @@ __FBSDID("$FreeBSD$"); #include #include #include +#include #include #include "devinfo.h" @@ -196,15 +197,47 @@ print_rman(struct devinfo_rman *rman, void *arg __unus return(0); } +static void __dead2 +usage(void) +{ + fprintf(stderr, "%s\n%s\n%s\n", + "usage: devinfo [-rv]", + " devinfo -u", + " devifno -p dev"); + exit(1); +} + + +static int +print_path(struct devinfo_dev *dev, void *xname) +{ + const char *name = xname; + int rv; + + if (strcmp(dev->dd_name, name) == 0) { + printf("%s", dev->dd_name); + return (1); + } + + rv = devinfo_foreach_device_child(dev, print_path, xname); + if (rv == 1) + printf(" %s", dev->dd_name[0] ? dev->dd_name : "unknown"); + return (rv); +} + int main(int argc, char *argv[]) { struct devinfo_dev *root; int c, uflag; + char *path; uflag = 0; - while ((c = getopt(argc, argv, "ruv")) != -1) { + while ((c = getopt(argc, argv, "p:ruv")) != -1) { switch(c) { + case 'p': + path = optarg; + break; case 'r': rflag++; break; @@ -215,21 +248,25 @@ main(int argc, char *argv[]) vflag++; break; default: - fprintf(stderr, "%s\n%s\n", - "usage: devinfo [-rv]", - " devinfo -u"); - exit(1); + usage(); } } + if (path && (rflag || uflag)) + usage(); + if (devinfo_init()) err(1, "devinfo_init"); if ((root = devinfo_handle_to_device(DEVINFO_ROOT_DEVICE)) == NULL) errx(1, "can't find root device"); - /* print resource usage? */ - if (uflag) { + if (path) { + if (devinfo_foreach_device_child(root, print_path, (void *)path) == 0) + errx(1, "%s: Not found", path); + printf("\n"); + } else if (uflag) { + /* print resource usage? */ devinfo_foreach_rman(print_rman, NULL); } else { /* print device hierarchy */