From owner-svn-src-head@freebsd.org Thu Sep 13 14:06:03 2018 Return-Path: Delivered-To: svn-src-head@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id 0EB92108EF9D; Thu, 13 Sep 2018 14:06:03 +0000 (UTC) (envelope-from trasz@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client CN "mxrelay.nyi.freebsd.org", Issuer "Let's Encrypt Authority X3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id A8A2C728D4; Thu, 13 Sep 2018 14:06:02 +0000 (UTC) (envelope-from trasz@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 mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 9DC891683C; Thu, 13 Sep 2018 14:06:02 +0000 (UTC) (envelope-from trasz@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id w8DE62di037566; Thu, 13 Sep 2018 14:06:02 GMT (envelope-from trasz@FreeBSD.org) Received: (from trasz@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id w8DE62Tb037564; Thu, 13 Sep 2018 14:06:02 GMT (envelope-from trasz@FreeBSD.org) Message-Id: <201809131406.w8DE62Tb037564@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: trasz set sender to trasz@FreeBSD.org using -f From: Edward Tomasz Napierala Date: Thu, 13 Sep 2018 14:06:02 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r338640 - head/sbin/geom/core X-SVN-Group: head X-SVN-Commit-Author: trasz X-SVN-Commit-Paths: head/sbin/geom/core X-SVN-Commit-Revision: 338640 X-SVN-Commit-Repository: base MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-head@freebsd.org X-Mailman-Version: 2.1.27 Precedence: list List-Id: SVN commit messages for the src tree for head/-current List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 13 Sep 2018 14:06:03 -0000 Author: trasz Date: Thu Sep 13 14:06:01 2018 New Revision: 338640 URL: https://svnweb.freebsd.org/changeset/base/338640 Log: Add new option to the geom(8) utility, "-p". It makes it easy to look up the GEOM class instance from the provider name. Reviewed by: oshogbo, 0mp Approved by: re (kib) MFC after: 2 weeks Relnotes: yes Sponsored by: DARPA, AFRL Differential Revision: https://reviews.freebsd.org/D17116 Modified: head/sbin/geom/core/geom.8 head/sbin/geom/core/geom.c Modified: head/sbin/geom/core/geom.8 ============================================================================== --- head/sbin/geom/core/geom.8 Thu Sep 13 13:57:42 2018 (r338639) +++ head/sbin/geom/core/geom.8 Thu Sep 13 14:06:01 2018 (r338640) @@ -24,7 +24,7 @@ .\" .\" $FreeBSD$ .\" -.Dd January 5, 2011 +.Dd September 13, 2018 .Dt GEOM 8 .Os .Sh NAME @@ -52,6 +52,9 @@ .Ar class .Cm unload .Op Fl v +.Nm +.Fl p +.Ar provider-name .Sh DESCRIPTION The .Nm @@ -101,6 +104,13 @@ sysctl. Unload the kernel module which implements the given class. This command is only available if the given class is loaded as a kernel module. +.El +.Pp +Additional options include: +.Bl -tag -width ".Cm status" +.It Fl p Ar provider-name +Print detailed information about the geom which provides +.Ar provider-name . .El .Pp Class-specific commands are implemented as shared libraries which Modified: head/sbin/geom/core/geom.c ============================================================================== --- head/sbin/geom/core/geom.c Thu Sep 13 13:57:42 2018 (r338639) +++ head/sbin/geom/core/geom.c Thu Sep 13 14:06:01 2018 (r338640) @@ -40,6 +40,7 @@ __FBSDID("$FreeBSD$"); #include #include #include +#include #include #include #include @@ -68,6 +69,7 @@ static struct g_command *class_commands = NULL; #define GEOM_CLASS_CMDS 0x01 #define GEOM_STD_CMDS 0x02 static struct g_command *find_command(const char *cmdstr, int flags); +static void list_one_geom_by_provider(const char *provider_name); static int std_available(const char *name); static void std_help(struct gctl_req *req, unsigned flags); @@ -146,6 +148,7 @@ usage(void) if (class_name == NULL) { fprintf(stderr, "usage: geom [options]\n"); + fprintf(stderr, " geom -p \n"); exit(EXIT_FAILURE); } else { struct g_command *cmd; @@ -650,10 +653,57 @@ get_class(int *argc, char ***argv) usage(); } +static struct ggeom * +find_geom_by_provider(struct gmesh *mesh, const char *name) +{ + struct gclass *classp; + struct ggeom *gp; + struct gprovider *pp; + + LIST_FOREACH(classp, &mesh->lg_class, lg_class) { + LIST_FOREACH(gp, &classp->lg_geom, lg_geom) { + LIST_FOREACH(pp, &gp->lg_provider, lg_provider) { + if (strcmp(pp->lg_name, name) == 0) + return (gp); + } + } + } + + return (NULL); +} + int main(int argc, char *argv[]) { + char *provider_name; + int ch; + provider_name = NULL; + + if (strcmp(getprogname(), "geom") == 0) { + while ((ch = getopt(argc, argv, "hp:")) != -1) { + switch (ch) { + case 'p': + provider_name = strdup(optarg); + if (provider_name == NULL) + err(1, "strdup"); + break; + case 'h': + default: + usage(); + } + } + + /* + * Don't adjust argc and argv, it would break get_class(). + */ + } + + if (provider_name != NULL) { + list_one_geom_by_provider(provider_name); + return (0); + } + get_class(&argc, &argv); run_command(argc, argv); /* NOTREACHED */ @@ -765,6 +815,25 @@ list_one_geom(struct ggeom *gp) } } printf("\n"); +} + +static void +list_one_geom_by_provider(const char *provider_name) +{ + struct gmesh mesh; + struct ggeom *gp; + int error; + + error = geom_gettree(&mesh); + if (error != 0) + errc(EXIT_FAILURE, error, "Cannot get GEOM tree"); + + gp = find_geom_by_provider(&mesh, provider_name); + if (gp == NULL) + errx(EXIT_FAILURE, "Cannot find provider '%s'.", provider_name); + + printf("Geom class: %s\n", gp->lg_class->lg_name); + list_one_geom(gp); } static void