Skip site navigation (1)Skip section navigation (2)
Date:      Thu, 14 Mar 2013 22:29:38 +0000 (UTC)
From:      Dmitry Morozovsky <marck@FreeBSD.org>
To:        src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org
Subject:   svn commit: r248291 - head/sbin/hastctl
Message-ID:  <201303142229.r2EMTcwG044842@svn.freebsd.org>

next in thread | raw e-mail | index | archive | help
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/<name>
 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] <init | primary | secondary> 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;



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201303142229.r2EMTcwG044842>