From owner-svn-src-head@FreeBSD.ORG Thu Mar 14 22:29:38 2013 Return-Path: Delivered-To: svn-src-head@freebsd.org Received: from mx1.freebsd.org (mx1.FreeBSD.org [8.8.178.115]) by hub.freebsd.org (Postfix) with ESMTP id 8C6A721A; Thu, 14 Mar 2013 22:29:38 +0000 (UTC) (envelope-from marck@FreeBSD.org) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:1900:2254:2068::e6a:0]) by mx1.freebsd.org (Postfix) with ESMTP id 7E3CDF24; Thu, 14 Mar 2013 22:29:38 +0000 (UTC) Received: from svn.freebsd.org ([127.0.1.70]) by svn.freebsd.org (8.14.6/8.14.6) with ESMTP id r2EMTc9q044844; Thu, 14 Mar 2013 22:29:38 GMT (envelope-from marck@svn.freebsd.org) Received: (from marck@localhost) by svn.freebsd.org (8.14.6/8.14.5/Submit) id r2EMTcwG044842; Thu, 14 Mar 2013 22:29:38 GMT (envelope-from marck@svn.freebsd.org) Message-Id: <201303142229.r2EMTcwG044842@svn.freebsd.org> From: Dmitry Morozovsky Date: Thu, 14 Mar 2013 22:29:38 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r248291 - head/sbin/hastctl X-SVN-Group: head 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.14 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, 14 Mar 2013 22:29:38 -0000 Author: marck (doc committer) Date: Thu Mar 14 22:29:37 2013 New Revision: 248291 URL: http://svnweb.freebsd.org/changeset/base/248291 Log: Rename 'status' command to 'list' and introduce new 'status' which produces more terse output more observable for both scripts and humans. Also, it shifts hastctl closer to GEOM utilities with their list/status command pairs. Approved by: pjd MFC after: 4 weeks Modified: head/sbin/hastctl/hastctl.8 head/sbin/hastctl/hastctl.c Modified: head/sbin/hastctl/hastctl.8 ============================================================================== --- head/sbin/hastctl/hastctl.8 Thu Mar 14 22:16:13 2013 (r248290) +++ head/sbin/hastctl/hastctl.8 Thu Mar 14 22:29:37 2013 (r248291) @@ -27,7 +27,7 @@ .\" .\" $FreeBSD$ .\" -.Dd April 10, 2011 +.Dd March 14, 2013 .Dt HASTCTL 8 .Os .Sh NAME @@ -49,6 +49,11 @@ .Aq init | primary | secondary .Ar all | name ... .Nm +.Cm list +.Op Fl d +.Op Fl c Ar config +.Op Ar all | name ... +.Nm .Cm status .Op Fl d .Op Fl c Ar config @@ -139,8 +144,11 @@ GEOM provider .Pa /dev/hast/ will not be created on secondary node. .El +.It Cm list +Present verbose status of the configured resources. .It Cm status -Present status of the configured resources. +Present terse (and more easy machine-parseable) status of the configured +resources. .It Cm dump Dump metadata stored on local component for the configured resources. .El Modified: head/sbin/hastctl/hastctl.c ============================================================================== --- head/sbin/hastctl/hastctl.c Thu Mar 14 22:16:13 2013 (r248290) +++ head/sbin/hastctl/hastctl.c Thu Mar 14 22:29:37 2013 (r248291) @@ -60,7 +60,8 @@ enum { CMD_CREATE, CMD_ROLE, CMD_STATUS, - CMD_DUMP + CMD_DUMP, + CMD_LIST }; static __dead2 void @@ -75,6 +76,9 @@ usage(void) " %s role [-d] [-c config] all | name ...\n", getprogname()); fprintf(stderr, + " %s list [-d] [-c config] [all | name ...]\n", + getprogname()); + fprintf(stderr, " %s status [-d] [-c config] [all | name ...]\n", getprogname()); fprintf(stderr, @@ -287,7 +291,7 @@ control_set_role(struct nv *nv, const ch } static int -control_status(struct nv *nv) +control_list(struct nv *nv) { unsigned int ii; const char *str; @@ -351,6 +355,43 @@ control_status(struct nv *nv) return (ret); } +static int +control_status(struct nv *nv) +{ + unsigned int ii; + const char *str; + int error, hprinted, ret; + + hprinted = 0; + ret = 0; + + for (ii = 0; ; ii++) { + str = nv_get_string(nv, "resource%u", ii); + if (str == NULL) + break; + if (!hprinted) { + printf("Name\tStatus\t Role\t\tComponents\n"); + hprinted = 1; + } + printf("%s\t", str); + error = nv_get_int16(nv, "error%u", ii); + if (error != 0) { + if (ret == 0) + ret = error; + printf("ERR%d\n", error); + continue; + } + str = nv_get_string(nv, "status%u", ii); + printf("%-9s", (str != NULL) ? str : "-"); + printf("%-15s", nv_get_string(nv, "role%u", ii)); + printf("%s\t", + nv_get_string(nv, "localpath%u", ii)); + printf("%s\n", + nv_get_string(nv, "remoteaddr%u", ii)); + } + return (ret); +} + int main(int argc, char *argv[]) { @@ -371,6 +412,9 @@ main(int argc, char *argv[]) } else if (strcmp(argv[1], "role") == 0) { cmd = CMD_ROLE; optstr = "c:dh"; + } else if (strcmp(argv[1], "list") == 0) { + cmd = CMD_LIST; + optstr = "c:dh"; } else if (strcmp(argv[1], "status") == 0) { cmd = CMD_STATUS; optstr = "c:dh"; @@ -459,8 +503,19 @@ main(int argc, char *argv[]) for (ii = 0; ii < argc - 1; ii++) nv_add_string(nv, argv[ii + 1], "resource%d", ii); break; + case CMD_LIST: + /* Obtain verbose status of the given resources. */ + nv = nv_alloc(); + nv_add_uint8(nv, HASTCTL_CMD_STATUS, "cmd"); + if (argc == 0) + nv_add_string(nv, "all", "resource%d", 0); + else { + for (ii = 0; ii < argc; ii++) + nv_add_string(nv, argv[ii], "resource%d", ii); + } + break; case CMD_STATUS: - /* Obtain status of the given resources. */ + /* Obtain brief status of the given resources. */ nv = nv_alloc(); nv_add_uint8(nv, HASTCTL_CMD_STATUS, "cmd"); if (argc == 0) @@ -514,6 +569,9 @@ main(int argc, char *argv[]) case CMD_ROLE: error = control_set_role(nv, argv[0]); break; + case CMD_LIST: + error = control_list(nv); + break; case CMD_STATUS: error = control_status(nv); break;