d6418de057
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
51 lines
1.3 KiB
Bash
Executable File
51 lines
1.3 KiB
Bash
Executable File
#!/bin/ksh -p
|
|
#
|
|
# Common functions used by the zpool_status and zpool_iostat tests for running
|
|
# scripts with the -c option.
|
|
#
|
|
# Copyright (c) 2017 Lawrence Livermore National Security, LLC.
|
|
#
|
|
|
|
. $STF_SUITE/include/libtest.shlib
|
|
|
|
function test_zpool_script {
|
|
script="$1"
|
|
testpool="$2"
|
|
cmd="$3"
|
|
wholecmd="$cmd $script $testpool"
|
|
out="$($wholecmd)"
|
|
|
|
# Default number of columns that get printed without -c
|
|
if echo "$cmd" | grep -q iostat ; then
|
|
# iostat
|
|
dcols=7
|
|
else
|
|
|
|
# status
|
|
dcols=5
|
|
fi
|
|
|
|
# Get the new column name that the script created
|
|
col="$(echo "$out" | \
|
|
awk '/^pool +alloc +free +read +write +/ {print $8} \
|
|
/NAME +STATE +READ +WRITE +CKSUM/ {print $6}')"
|
|
|
|
if [ -z "$col" ] ; then
|
|
log_fail "'$wholecmd' created no new columns"
|
|
fi
|
|
|
|
# Count the number of columns for each vdev. Each script should produce
|
|
# at least one new column value. Even if scripts return blank, zpool
|
|
# will convert the blank to a '-' to make things awk-able. Normal
|
|
# zpool iostat -v output is 7 columns, so if the script ran correctly
|
|
# we should see more than that.
|
|
if ! newcols=$(echo "$out" | \
|
|
awk '/\/dev/{print NF-'$dcols'; if (NF <= '$dcols') {exit 1}}' | \
|
|
head -n 1) ; \
|
|
then
|
|
log_fail "'$wholecmd' didn't create a new column value"
|
|
else
|
|
log_note "'$wholecmd' passed ($newcols new columns)"
|
|
fi
|
|
}
|