mirror of
https://git.proxmox.com/git/mirror_zfs.git
synced 2026-05-22 18:40:43 +03:00
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:
committed by
Brian Behlendorf
parent
038091fd4f
commit
d6418de057
@@ -335,7 +335,8 @@ pre =
|
||||
post =
|
||||
|
||||
[tests/functional/cli_root/zpool_status]
|
||||
tests = ['zpool_status_001_pos', 'zpool_status_002_pos']
|
||||
tests = ['zpool_status_001_pos', 'zpool_status_002_pos','zpool_status_003_pos']
|
||||
user =
|
||||
|
||||
# DISABLED:
|
||||
# zpool_upgrade_002_pos - https://github.com/zfsonlinux/zfs/issues/4034
|
||||
|
||||
@@ -4,4 +4,5 @@ dist_pkgdata_SCRIPTS = \
|
||||
default.cfg \
|
||||
libtest.shlib \
|
||||
math.shlib \
|
||||
properties.shlib
|
||||
properties.shlib \
|
||||
zpool_script.shlib
|
||||
|
||||
@@ -34,6 +34,7 @@
|
||||
|
||||
# ZFS Directories
|
||||
export ZEDLETDIR=${ZEDLETDIR:-/etc/zfs/zed.d}
|
||||
export ZPOOLSCRIPTDIR=${ZPOOLSCRIPTDIR:-/etc/zfs/zpool.d}
|
||||
|
||||
# Define run length constants
|
||||
export RT_LONG="3"
|
||||
|
||||
Executable
+50
@@ -0,0 +1,50 @@
|
||||
#!/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
|
||||
}
|
||||
@@ -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
|
||||
|
||||
+76
@@ -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
|
||||
@@ -26,7 +26,7 @@
|
||||
#
|
||||
|
||||
#
|
||||
# Copyright (c) 2013, 2016 by Delphix. All rights reserved.
|
||||
# Copyright (c) 2013 by Delphix. All rights reserved.
|
||||
#
|
||||
|
||||
. $STF_SUITE/include/libtest.shlib
|
||||
@@ -69,23 +69,4 @@ check_pool_status
|
||||
log_must eval "zpool status -v $TESTPOOL > /tmp/pool-status.$$"
|
||||
check_pool_status
|
||||
|
||||
# Make sure -c option works, and that VDEV_PATH and VDEV_UPATH get set.
|
||||
#
|
||||
# grep for '^\s+/' to just get the vdevs (not pools). All vdevs will start with
|
||||
# a '/' when we specify the path (-P) flag. We check for "{}" to see if one
|
||||
# of the VDEV variables isn't set.
|
||||
C1=$(zpool status -P | grep -E '^\s+/' | wc -l)
|
||||
C2=$(zpool status -P -c 'echo vdev_test{$VDEV_PATH}{$VDEV_UPATH}' | \
|
||||
grep -E '^\s+/' | grep -v '{}' | wc -l)
|
||||
|
||||
if [ "$C1" != "$C2" ] ; then
|
||||
log_fail "zpool status -c option failed. Expected $C1 vdevs, got $C2"
|
||||
else
|
||||
log_pass "zpool status -c option passed. Expected $C1 vdevs, got $C2"
|
||||
fi
|
||||
|
||||
# $TESTPOOL.virt has an offline device, so -x will show it
|
||||
log_must eval "zpool status -x $TESTPOOL.virt > /tmp/pool-status.$$"
|
||||
check_pool_status
|
||||
|
||||
log_pass "zpool status works when run as a user"
|
||||
|
||||
@@ -30,11 +30,19 @@
|
||||
#
|
||||
|
||||
#
|
||||
# Copyright (c) 2016 by Lawrence Livermore National Security, LLC.
|
||||
# Copyright (c) 2016-2017 by Lawrence Livermore National Security, LLC.
|
||||
#
|
||||
|
||||
# DESCRIPTION:
|
||||
# Verify zpool iostat 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"
|
||||
|
||||
@@ -45,36 +53,24 @@ else
|
||||
testpool=${TESTPOOL%%/*}
|
||||
fi
|
||||
|
||||
#
|
||||
# DESCRIPTION:
|
||||
# Verify 'zpool iostat -c CMD' works, and that VDEV_PATH and VDEV_UPATH get set.
|
||||
#
|
||||
# STRATEGY:
|
||||
# grep for '^\s+/' to just get the vdevs (not pools). All vdevs will start with
|
||||
# a '/' when we specify the path (-P) flag. We check for "{}" to see if one
|
||||
# of the VDEV variables isn't set.
|
||||
#
|
||||
C1=$(zpool iostat -Pv $testpool | grep -E '^\s+/' | wc -l)
|
||||
C2=$(zpool iostat -Pv -c 'echo vdev_test{$VDEV_PATH}{$VDEV_UPATH}' $testpool \
|
||||
| grep -E '^\s+/' | grep -v '{}' | wc -l)
|
||||
if [ "$C1" != "$C2" ] ; then
|
||||
log_fail "zpool iostat -c failed, expected $C1 vdevs, got $C2"
|
||||
else
|
||||
log_note "zpool iostat -c passed, expected $C1 vdevs, got $C2"
|
||||
fi
|
||||
files="$(ls $ZPOOLSCRIPTDIR)"
|
||||
scripts=""
|
||||
for i in $files ; do
|
||||
if [ ! -x "$ZPOOLSCRIPTDIR/$i" ] ; then
|
||||
# Skip non-executables
|
||||
continue
|
||||
fi
|
||||
|
||||
# Call iostat on only a specific vdev, and verify that the command only gets
|
||||
# run on the vdev. We write the command results to a temp file to verify that
|
||||
# the command actually gets run, rather than just verifying that the results
|
||||
# are *displayed* for the specific vdev.
|
||||
TMP=$(mktemp)
|
||||
FIRST_VDEV=$(zpool iostat -Pv $testpool | grep -Eo '^\s+/[^ ]+' | head -n 1)
|
||||
log_must zpool iostat -Pv -c "echo \$VDEV_PATH >> $TMP" $testpool \
|
||||
$FIRST_VDEV > /dev/null
|
||||
C2=$(wc -w < $TMP)
|
||||
rm $TMP
|
||||
if [ "$C2" != "1" ] ; then
|
||||
log_fail "zpool iostat -c <VDEV> failed, expected 1 vdev, got $C2"
|
||||
else
|
||||
log_note "zpool iostat -c <VDEV> passed, expected 1 vdev, got $C2"
|
||||
fi
|
||||
# Collect executable script names
|
||||
scripts="$scripts $i"
|
||||
|
||||
# Run each one with -c
|
||||
test_zpool_script "$i" "$testpool" "zpool iostat -Pv -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 iostat -Pv -c"
|
||||
|
||||
exit 0
|
||||
|
||||
Reference in New Issue
Block a user