Prebaked scripts for zpool status/iostat -c

This patch updates the "zpool status/iostat -c" commands to only run
"pre-baked" scripts from the /etc/zfs/zpool.d directory (or wherever
you install to).  The scripts can only be run from -c as an unprivileged
user (unless the ZPOOL_SCRIPTS_AS_ROOT environment var is
set by root).  This was done to encourage scripts to be written is such
a way that normal users can use them, and to be cautious.  If your
script needs to run a privileged command, consider adding the
appropriate line in /etc/sudoers.  See zpool(8) for an example of how
to do this.

The patch also allows the scripts to output custom column names.  If
the script outputs a line like:

name=value

then "name" is used for the column name, and "value" is its value.
Multiple columns can be specified by outputting multiple lines.  Column
names and values can have spaces.  If the value is empty, a dash (-) is
printed instead.

After all the "name=value" lines are read (if any), zpool will take the
next the next line of output (if any) and print it without a column
header.  After that, no more lines will be processed. This can be
useful for printing errors.

Lastly, this patch also disables the -c option with the latency and
request size histograms, since it produced awkward output and made the
code harder to maintain.

Reviewed-by: Brian Behlendorf <behlendorf1@llnl.gov>
Reviewed-by: Giuseppe Di Natale <dinatale2@llnl.gov>
Signed-off-by: Tony Hutter <hutter2@llnl.gov>
Closes #5852
This commit is contained in:
Tony Hutter
2017-04-21 09:27:04 -07:00
committed by Brian Behlendorf
parent 038091fd4f
commit d6418de057
36 changed files with 1218 additions and 156 deletions
@@ -3,4 +3,5 @@ dist_pkgdata_SCRIPTS = \
setup.ksh \
cleanup.ksh \
zpool_status_001_pos.ksh \
zpool_status_002_pos.ksh
zpool_status_002_pos.ksh \
zpool_status_003_pos.ksh
@@ -0,0 +1,76 @@
#!/bin/ksh -p
#
# CDDL HEADER START
#
# The contents of this file are subject to the terms of the
# Common Development and Distribution License (the "License").
# You may not use this file except in compliance with the License.
#
# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
# or http://www.opensolaris.org/os/licensing.
# See the License for the specific language governing permissions
# and limitations under the License.
#
# When distributing Covered Code, include this CDDL HEADER in each
# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
# If applicable, add the following below this CDDL HEADER, with the
# fields enclosed by brackets "[]" replaced with your own identifying
# information: Portions Copyright [yyyy] [name of copyright owner]
#
# CDDL HEADER END
#
#
# Copyright 2007 Sun Microsystems, Inc. All rights reserved.
# Use is subject to license terms.
#
#
# Copyright (c) 2013 by Delphix. All rights reserved.
#
#
# Copyright (c) 2016-2017 by Lawrence Livermore National Security, LLC.
#
# DESCRIPTION:
# Verify zpool status command mode (-c) works for all pre-baked scripts.
#
# STRATEGY:
# 1. Make sure each script creates at least one new column.
# 2. Make sure the new column values exist.
# 3. Make sure we can run multiple scripts in one -c line
. $STF_SUITE/include/libtest.shlib
. $STF_SUITE/include/zpool_script.shlib
verify_runnable "both"
typeset testpool
if is_global_zone ; then
testpool="$TESTPOOL"
else
testpool="${TESTPOOL%%/*}"
fi
files="$(ls $ZPOOLSCRIPTDIR)"
scripts=""
for i in $files ; do
if [ ! -x "$ZPOOLSCRIPTDIR/$i" ] ; then
# Skip non-executables
continue
fi
# Collect executable script names
scripts="$scripts $i"
# Run each one with -c
test_zpool_script "$i" "$testpool" "zpool status -P -c"
done
# Test that we can run multiple scripts separated with a commma by running
# all the scripts in a single -c line.
allscripts="$(echo $scripts | sed -r 's/[[:blank:]]+/,/g')"
test_zpool_script "$allscripts" "$testpool" "zpool status -P -c"
exit 0