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
This commit is contained in:
Dmitry Morozovsky 2013-03-14 22:29:37 +00:00
parent 0ba771b570
commit 5632176c77
Notes: svn2git 2020-12-20 02:59:44 +00:00
svn path=/head/; revision=248291
2 changed files with 71 additions and 5 deletions

View file

@ -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

View file

@ -60,7 +60,8 @@ enum {
CMD_CREATE,
CMD_ROLE,
CMD_STATUS,
CMD_DUMP
CMD_DUMP,
CMD_LIST
};
static __dead2 void
@ -74,6 +75,9 @@ usage(void)
fprintf(stderr,
" %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());
@ -287,7 +291,7 @@ control_set_role(struct nv *nv, const char *newrole)
}
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;