Use consistent error message in zpool sub-command

The zpool sub-commands like iostat, list, and status should
display consistent message when a given pool is unavailable or
no pool is present.  This change unifies the default behavior
as follows:

  root@prasad:~# ./zpool list 1 2
  no pools available
  no pools available

  root@prasad:~# ./zpool iostat  1 2
  no pools available
  no pools available

  root@prasad:~# ./zpool status 1 2
  no pools available
  no pools available

  root@prasad:~# ./zpool list tan 1 2
  cannot open 'tan': no such pool

  root@prasad:~# ./zpool iostat tan 1 2
  cannot open 'tan': no such pool

  root@prasad:~# ./zpool status tan 1 2
  cannot open 'tan': no such pool

Reported-by: Rajshree Thorat <rthorat@stec-inc.com>
Signed-off-by: Prasad Joshi <pjoshi@stec-inc.com>
Signed-off-by: Brian Behlendorf <behlendorf1@llnl.gov>

Closes #306
This commit is contained in:
Prasad Joshi 2011-07-04 23:45:35 +01:00 committed by Brian Behlendorf
parent b59322a0d8
commit 5a52105925

View File

@ -2358,27 +2358,31 @@ zpool_do_iostat(int argc, char **argv)
pool_list_update(list); pool_list_update(list);
if ((npools = pool_list_count(list)) == 0) if ((npools = pool_list_count(list)) == 0)
break; (void) printf(gettext("no pools available\n"));
else {
/* /*
* Refresh all statistics. This is done as an explicit step * Refresh all statistics. This is done as an
* before calculating the maximum name width, so that any * explicit step before calculating the maximum name
* configuration changes are properly accounted for. * width, so that any * configuration changes are
* properly accounted for.
*/ */
(void) pool_list_iter(list, B_FALSE, refresh_iostat, &cb); (void) pool_list_iter(list, B_FALSE, refresh_iostat,
&cb);
/* /*
* Iterate over all pools to determine the maximum width * Iterate over all pools to determine the maximum width
* for the pool / device name column across all pools. * for the pool / device name column across all pools.
*/ */
cb.cb_namewidth = 0; cb.cb_namewidth = 0;
(void) pool_list_iter(list, B_FALSE, get_namewidth, &cb); (void) pool_list_iter(list, B_FALSE, get_namewidth,
&cb);
if (timestamp_fmt != NODATE) if (timestamp_fmt != NODATE)
print_timestamp(timestamp_fmt); print_timestamp(timestamp_fmt);
/* /*
* If it's the first time, or verbose mode, print the header. * If it's the first time, or verbose mode, print the
* header.
*/ */
if (++cb.cb_iteration == 1 || verbose) if (++cb.cb_iteration == 1 || verbose)
print_iostat_header(&cb); print_iostat_header(&cb);
@ -2386,14 +2390,16 @@ zpool_do_iostat(int argc, char **argv)
(void) pool_list_iter(list, B_FALSE, print_iostat, &cb); (void) pool_list_iter(list, B_FALSE, print_iostat, &cb);
/* /*
* If there's more than one pool, and we're not in verbose mode * If there's more than one pool, and we're not in
* (which prints a separator for us), then print a separator. * verbose mode (which prints a separator for us),
* then print a separator.
*/ */
if (npools > 1 && !verbose) if (npools > 1 && !verbose)
print_iostat_separator(&cb); print_iostat_separator(&cb);
if (verbose) if (verbose)
(void) printf("\n"); (void) printf("\n");
}
/* /*
* Flush the output so that redirection to a file isn't buffered * Flush the output so that redirection to a file isn't buffered
@ -2592,10 +2598,12 @@ zpool_do_list(int argc, char **argv)
ret = for_each_pool(argc, argv, B_TRUE, &cb.cb_proplist, ret = for_each_pool(argc, argv, B_TRUE, &cb.cb_proplist,
list_callback, &cb); list_callback, &cb);
if (argc == 0 && cb.cb_first && !cb.cb_scripted) { if (argc == 0 && cb.cb_first)
(void) printf(gettext("no pools available\n")); (void) printf(gettext("no pools available\n"));
else if (argc && cb.cb_first) {
/* cannot open the given pool */
zprop_free_list(cb.cb_proplist); zprop_free_list(cb.cb_proplist);
return (0); return (1);
} }
if (interval == 0) if (interval == 0)