From owner-svn-src-all@FreeBSD.ORG Tue Oct 25 08:03:51 2011 Return-Path: Delivered-To: svn-src-all@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id C9FB8106566C; Tue, 25 Oct 2011 08:03:51 +0000 (UTC) (envelope-from pjd@FreeBSD.org) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:4f8:fff6::2c]) by mx1.freebsd.org (Postfix) with ESMTP id AF43F8FC13; Tue, 25 Oct 2011 08:03:51 +0000 (UTC) Received: from svn.freebsd.org (localhost [127.0.0.1]) by svn.freebsd.org (8.14.4/8.14.4) with ESMTP id p9P83pIx085507; Tue, 25 Oct 2011 08:03:51 GMT (envelope-from pjd@svn.freebsd.org) Received: (from pjd@localhost) by svn.freebsd.org (8.14.4/8.14.4/Submit) id p9P83puw085504; Tue, 25 Oct 2011 08:03:51 GMT (envelope-from pjd@svn.freebsd.org) Message-Id: <201110250803.p9P83puw085504@svn.freebsd.org> From: Pawel Jakub Dawidek Date: Tue, 25 Oct 2011 08:03:51 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org X-SVN-Group: head MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Cc: Subject: svn commit: r226723 - head/sbin/geom/class/eli X-BeenThere: svn-src-all@freebsd.org X-Mailman-Version: 2.1.5 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: Tue, 25 Oct 2011 08:03:52 -0000 Author: pjd Date: Tue Oct 25 08:03:51 2011 New Revision: 226723 URL: http://svn.freebsd.org/changeset/base/226723 Log: Add 'geli version' subcommand, which will print GELI metadata version of each given GEOM provider or if not providers are given it will print versions supported by userland geli(8) utility and by ELI GEOM class. MFC after: 3 days Modified: head/sbin/geom/class/eli/geli.8 head/sbin/geom/class/eli/geom_eli.c Modified: head/sbin/geom/class/eli/geli.8 ============================================================================== --- head/sbin/geom/class/eli/geli.8 Tue Oct 25 07:56:27 2011 (r226722) +++ head/sbin/geom/class/eli/geli.8 Tue Oct 25 08:03:51 2011 (r226723) @@ -134,6 +134,9 @@ utility: .Fl s Ar oldsize .Ar prov .Nm +.Cm version +.Op Ar prov ... +.Nm .Cm clear .Op Fl v .Ar prov ... @@ -597,6 +600,18 @@ Additional options include: .It Fl s Ar oldsize The size of the provider before it was resized. .El +.It Cm version +If no arguments are given, the +.Cm version +subcommand will print the version of +.Nm +userland utility as well as the version of the +.Nm ELI +GEOM class. +.Pp +If GEOM providers are specified, the +.Cm version +subcommand will print metadata version used by each of them. .It Cm clear Clear metadata from the given providers. .It Cm dump Modified: head/sbin/geom/class/eli/geom_eli.c ============================================================================== --- head/sbin/geom/class/eli/geom_eli.c Tue Oct 25 07:56:27 2011 (r226722) +++ head/sbin/geom/class/eli/geom_eli.c Tue Oct 25 08:03:51 2011 (r226723) @@ -72,6 +72,7 @@ static void eli_kill(struct gctl_req *re static void eli_backup(struct gctl_req *req); static void eli_restore(struct gctl_req *req); static void eli_resize(struct gctl_req *req); +static void eli_version(struct gctl_req *req); static void eli_clear(struct gctl_req *req); static void eli_dump(struct gctl_req *req); @@ -96,6 +97,7 @@ static int eli_backup_create(struct gctl * backup [-v] prov file * restore [-fv] file prov * resize [-v] -s oldsize prov + * version [prov ...] * clear [-v] prov ... * dump [-v] prov ... */ @@ -241,6 +243,9 @@ struct g_command class_commands[] = { }, "[-v] -s oldsize prov" }, + { "version", G_FLAG_LOADKLD, eli_main, G_NULL_OPTS, + "[prov ...]" + }, { "clear", G_FLAG_VERBOSE, eli_main, G_NULL_OPTS, "[-v] prov ..." }, @@ -309,6 +314,8 @@ eli_main(struct gctl_req *req, unsigned eli_restore(req); else if (strcmp(name, "resize") == 0) eli_resize(req); + else if (strcmp(name, "version") == 0) + eli_version(req); else if (strcmp(name, "dump") == 0) eli_dump(req); else if (strcmp(name, "clear") == 0) @@ -1524,6 +1531,46 @@ out: } static void +eli_version(struct gctl_req *req) +{ + struct g_eli_metadata md; + const char *name; + unsigned int version; + int error, i, nargs; + + nargs = gctl_get_int(req, "nargs"); + + if (nargs == 0) { + unsigned int kernver; + ssize_t size; + + size = sizeof(kernver); + if (sysctlbyname("kern.geom.eli.version", &kernver, &size, + NULL, 0) == -1) { + warn("Unable to obtain GELI kernel version"); + } else { + printf("kernel: %u\n", kernver); + } + printf("userland: %u\n", G_ELI_VERSION); + return; + } + + for (i = 0; i < nargs; i++) { + name = gctl_get_ascii(req, "arg%d", i); + error = g_metadata_read(name, (unsigned char *)&md, + sizeof(md), G_ELI_MAGIC); + if (error != 0) { + warn("%s: Unable to read metadata: %s.", name, + strerror(error)); + gctl_error(req, "Not fully done."); + continue; + } + version = le32dec(&md.md_version); + printf("%s: %u\n", name, version); + } +} + +static void eli_clear(struct gctl_req *req) { const char *name;