mirror of
https://git.proxmox.com/git/mirror_zfs.git
synced 2024-11-17 10:01:01 +03:00
ZTS: devices_001_pos and devices_002_neg
Update the devices_001_pos and devices_002_neg test cases such that the special block device file created is backed by a ZFS volume. Specifying a specific device allows the major and minor numbers to be easily determined. Furthermore, this avoids the potentially dangerous behavior of opening the first block device we happen to find under /dev/. Reviewed-by: Ryan Moeller <ryan@ixsystems.com> Signed-off-by: Brian Behlendorf <behlendorf1@llnl.gov> Closes #9773
This commit is contained in:
parent
d5c97f3de7
commit
590ff61a55
@ -42,7 +42,7 @@
|
|||||||
# 1. Create pool and file system.
|
# 1. Create pool and file system.
|
||||||
# 2. Set devices=on on this file system.
|
# 2. Set devices=on on this file system.
|
||||||
# 3. Separately create block device file and character file.
|
# 3. Separately create block device file and character file.
|
||||||
# 4. Separately read from those two device files.
|
# 4. Separately read and write from those two device files.
|
||||||
# 5. Check the return value, and make sure it succeeds.
|
# 5. Check the return value, and make sure it succeeds.
|
||||||
#
|
#
|
||||||
|
|
||||||
@ -55,12 +55,18 @@ log_onexit cleanup
|
|||||||
log_must zfs set devices=on $TESTPOOL/$TESTFS
|
log_must zfs set devices=on $TESTPOOL/$TESTFS
|
||||||
|
|
||||||
#
|
#
|
||||||
# Separately create block device file and character device file, then try to
|
# Create block device file backed by a ZFS volume.
|
||||||
# open them and make sure it succeed.
|
# Verify it can be opened, written, and read.
|
||||||
#
|
#
|
||||||
create_dev_file b $TESTDIR/$TESTFILE1
|
create_dev_file b $TESTDIR/$TESTFILE1 $ZVOL_DEVDIR/$TESTPOOL/$TESTVOL
|
||||||
log_must dd if=$TESTDIR/$TESTFILE1 of=$TESTDIR/$TESTFILE1.out count=1
|
log_must dd if=/dev/urandom of=$TESTDIR/$TESTFILE1.out1 count=1 bs=128k
|
||||||
|
log_must dd if=$TESTDIR/$TESTFILE1.out1 of=$TESTDIR/$TESTFILE1 count=1 bs=128k
|
||||||
|
log_must dd if=$TESTDIR/$TESTFILE1 of=$TESTDIR/$TESTFILE1.out2 count=1 bs=128k
|
||||||
|
log_must cmp $TESTDIR/$TESTFILE1.out1 $TESTDIR/$TESTFILE1.out2
|
||||||
|
|
||||||
|
# Create character device file backed by /dev/null
|
||||||
|
# Verify it can be opened and written.
|
||||||
create_dev_file c $TESTDIR/$TESTFILE2
|
create_dev_file c $TESTDIR/$TESTFILE2
|
||||||
log_must dd if=$TESTDIR/$TESTFILE2 of=$TESTDIR/$TESTFILE2.out count=1
|
log_must dd if=/dev/urandom of=$TESTDIR/$TESTFILE2 count=1 bs=128k
|
||||||
|
|
||||||
log_pass "Setting devices=on on file system and testing it pass."
|
log_pass "Setting devices=on on file system and testing it pass."
|
||||||
|
@ -42,7 +42,7 @@
|
|||||||
# 1. Create pool and file system.
|
# 1. Create pool and file system.
|
||||||
# 2. Set devices=off on this file system.
|
# 2. Set devices=off on this file system.
|
||||||
# 3. Separately create block device file and character file.
|
# 3. Separately create block device file and character file.
|
||||||
# 4. Separately read from those two device files.
|
# 4. Separately read and write from those two device files.
|
||||||
# 5. Check the return value, and make sure it failed.
|
# 5. Check the return value, and make sure it failed.
|
||||||
#
|
#
|
||||||
|
|
||||||
@ -55,12 +55,16 @@ log_onexit cleanup
|
|||||||
log_must zfs set devices=off $TESTPOOL/$TESTFS
|
log_must zfs set devices=off $TESTPOOL/$TESTFS
|
||||||
|
|
||||||
#
|
#
|
||||||
# Separately create block device file and character device file, then try to
|
# Create block device file backed by a ZFS volume.
|
||||||
# open them and make sure it failed.
|
# Verify it cannot be opened, written, and read.
|
||||||
#
|
#
|
||||||
create_dev_file b $TESTDIR/$TESTFILE1
|
create_dev_file b $TESTDIR/$TESTFILE1 $ZVOL_DEVDIR/$TESTPOOL/$TESTVOL
|
||||||
log_mustnot dd if=$TESTDIR/$TESTFILE1 of=$TESTDIR/$TESTFILE1.out count=1
|
log_mustnot dd if=/dev/urandom of=$TESTDIR/$TESTFILE1 count=1 bs=128k
|
||||||
|
log_mustnot dd if=$TESTDIR/$TESTFILE1 of=/dev/null count=1 bs=128k
|
||||||
|
|
||||||
|
# Create character device file backed by /dev/null
|
||||||
|
# Verify it cannot be opened and written.
|
||||||
create_dev_file c $TESTDIR/$TESTFILE2
|
create_dev_file c $TESTDIR/$TESTFILE2
|
||||||
log_mustnot dd if=$TESTDIR/$TESTFILE2 of=$TESTDIR/$TESTFILE2.out count=1
|
log_mustnot dd if=/dev/urandom of=$TESTDIR/$TESTFILE2 count=1 bs=128k
|
||||||
|
|
||||||
log_pass "Setting devices=off on file system and testing it pass."
|
log_pass "Setting devices=off on file system and testing it pass."
|
||||||
|
@ -36,192 +36,70 @@
|
|||||||
#
|
#
|
||||||
# $1 device file type
|
# $1 device file type
|
||||||
# $2 file name
|
# $2 file name
|
||||||
|
# $3 device path (used for 'b' device type)
|
||||||
#
|
#
|
||||||
function create_dev_file
|
function create_dev_file
|
||||||
{
|
{
|
||||||
typeset filetype=$1
|
typeset filetype=$1
|
||||||
typeset filename=$2
|
typeset filename=$2
|
||||||
|
typeset devstr=$3
|
||||||
case $(uname) in
|
|
||||||
FreeBSD)
|
|
||||||
create_dev_file_freebsd "$filetype" "$filename"
|
|
||||||
;;
|
|
||||||
Linux)
|
|
||||||
create_dev_file_linux "$filetype" "$filename"
|
|
||||||
;;
|
|
||||||
*)
|
|
||||||
create_dev_file_illumos "$filetype" "$filename"
|
|
||||||
;;
|
|
||||||
esac
|
|
||||||
|
|
||||||
return 0
|
|
||||||
}
|
|
||||||
|
|
||||||
function create_dev_file_freebsd
|
|
||||||
{
|
|
||||||
typeset filetype=$1
|
|
||||||
typeset filename=$2
|
|
||||||
|
|
||||||
case $filetype in
|
case $filetype in
|
||||||
b)
|
b)
|
||||||
devtype=$(df -T / | grep -v "Type" | awk '{print $2}')
|
case $(uname) in
|
||||||
case $devtype in
|
Linux)
|
||||||
zfs)
|
#
|
||||||
rootpool=$(df / | grep -v "Filesystem" | \
|
# stat(1) --format=FORMAT tokens
|
||||||
awk '{print $2}')
|
# %t - major device type in hex
|
||||||
rootpool=${rootpool#\(}
|
# %T - minor device type in hex
|
||||||
rootpool=${rootpool%%/*}
|
#
|
||||||
|
major=$(stat --dereference --format="%t" "$devstr")
|
||||||
devstr=$(get_disklist $rootpool)
|
minor=$(stat --dereference --format="%T" "$devstr")
|
||||||
devstr=$(echo "$devstr" | \
|
log_must mknod $filename b "0x${major}" "0x${minor}"
|
||||||
awk '{print $1}')
|
|
||||||
[[ -z $devstr ]] && \
|
|
||||||
log_fail "Can not get block device file."
|
|
||||||
devstr=/dev/${devstr}
|
|
||||||
;;
|
|
||||||
ufs)
|
|
||||||
#
|
|
||||||
# Get the existing block device file in current system.
|
|
||||||
# And bring out the first one.
|
|
||||||
#
|
|
||||||
devstr=$(df -t ufs | \
|
|
||||||
grep "^/dev/" | \
|
|
||||||
head -n 1 | \
|
|
||||||
awk '{print $1}')
|
|
||||||
devstr=$(echo "$devstr" | \
|
|
||||||
awk '{print $1}')
|
|
||||||
[[ -z $devstr ]] && \
|
|
||||||
log_fail "Can not get block device file."
|
|
||||||
;;
|
;;
|
||||||
*)
|
*)
|
||||||
log_unsupported "Unsupported fstype " \
|
#
|
||||||
"for / ($devtype)," \
|
# Get the device file information. i.e:
|
||||||
"only ufs|zfs is supported."
|
# $devstr: block special (28/768)
|
||||||
|
#
|
||||||
|
devstr=$(file $devstr)
|
||||||
|
major=${devstr##*\(}
|
||||||
|
major=${major%%/*}
|
||||||
|
minor=${devstr##*/}
|
||||||
|
minor=${minor%\)}
|
||||||
|
log_must mknod $filename b $major $minor
|
||||||
;;
|
;;
|
||||||
esac
|
esac
|
||||||
|
|
||||||
#
|
|
||||||
# Get the device file information. i.e:
|
|
||||||
# /dev/c0t0d0s0: block special (28/768)
|
|
||||||
#
|
|
||||||
devstr=$(file $devstr)
|
|
||||||
|
|
||||||
#
|
|
||||||
# Bring out major and minor number.
|
|
||||||
#
|
|
||||||
major=${devstr##*\(}
|
|
||||||
major=${major%%/*}
|
|
||||||
minor=${devstr##*/}
|
|
||||||
minor=${minor%\)}
|
|
||||||
|
|
||||||
log_must mknod $filename b $major $minor
|
|
||||||
;;
|
;;
|
||||||
c)
|
c)
|
||||||
#
|
#
|
||||||
# Create device file '/dev/null'
|
# Create device file '/dev/null', $devstr is unused.
|
||||||
#
|
#
|
||||||
log_must mknod $filename c 13 2
|
case $(uname) in
|
||||||
;;
|
Linux)
|
||||||
*)
|
#
|
||||||
log_fail "'$filetype' is wrong."
|
# stat(1) --format=FORMAT tokens
|
||||||
;;
|
# %t - major device type in hex
|
||||||
esac
|
# %T - minor device type in hex
|
||||||
|
#
|
||||||
return 0
|
major=$(stat --format="%t" /dev/null)
|
||||||
}
|
minor=$(stat --format="%T" /dev/null)
|
||||||
|
log_must mknod $filename c "0x${major}" "0x${minor}"
|
||||||
function create_dev_file_illumos
|
|
||||||
{
|
|
||||||
typeset filetype=$1
|
|
||||||
typeset filename=$2
|
|
||||||
|
|
||||||
case $filetype in
|
|
||||||
b)
|
|
||||||
devtype=$(df -n / | awk '{print $3}')
|
|
||||||
case $devtype in
|
|
||||||
zfs)
|
|
||||||
rootpool=$(df / | \
|
|
||||||
awk '{print $2}')
|
|
||||||
rootpool=${rootpool#\(}
|
|
||||||
rootpool=${rootpool%%/*}
|
|
||||||
|
|
||||||
devstr=$(get_disklist $rootpool)
|
|
||||||
devstr=$(echo "$devstr" | \
|
|
||||||
awk '{print $1}')
|
|
||||||
[[ -z $devstr ]] && \
|
|
||||||
log_fail "Can not get block device file."
|
|
||||||
devstr=$DEV_DSKDIR/${devstr}
|
|
||||||
;;
|
;;
|
||||||
ufs)
|
FreeBSD)
|
||||||
#
|
#
|
||||||
# Get the existing block device file in current system.
|
# Create device file '/dev/null'
|
||||||
# And bring out the first one.
|
#
|
||||||
#
|
major=13
|
||||||
devstr=$(df-lhF ufs | \
|
minor=2
|
||||||
grep "^${DEV_DSKDIR}" | \
|
log_must mknod $filename b $major $minor
|
||||||
awk '{print $1}')
|
|
||||||
devstr=$(echo "$devstr" | \
|
|
||||||
awk '{print $1}')
|
|
||||||
[[ -z $devstr ]] && \
|
|
||||||
log_fail "Can not get block device file."
|
|
||||||
;;
|
;;
|
||||||
*)
|
*)
|
||||||
log_unsupported "Unsupported fstype " \
|
major=$(getmajor mm)
|
||||||
"for / ($devtype)," \
|
minor=2
|
||||||
"only ufs|zfs is supported."
|
log_must mknod $filename b $major $minor
|
||||||
;;
|
;;
|
||||||
esac
|
esac
|
||||||
|
|
||||||
#
|
|
||||||
# Get the device file information. i.e:
|
|
||||||
# $DEV_DSKDIR/c0t0d0s0: block special (28/768)
|
|
||||||
#
|
|
||||||
devstr=$(file $devstr)
|
|
||||||
|
|
||||||
#
|
|
||||||
# Bring out major and minor number.
|
|
||||||
#
|
|
||||||
major=${devstr##*\(}
|
|
||||||
major=${major%%/*}
|
|
||||||
minor=${devstr##*/}
|
|
||||||
minor=${minor%\)}
|
|
||||||
|
|
||||||
log_must mknod $filename b $major $minor
|
|
||||||
;;
|
|
||||||
c)
|
|
||||||
#
|
|
||||||
# Create device file '/dev/null'
|
|
||||||
#
|
|
||||||
log_must mknod $filename c $(getmajor mm) 2
|
|
||||||
;;
|
|
||||||
*)
|
|
||||||
log_fail "'$filetype' is wrong."
|
|
||||||
;;
|
|
||||||
esac
|
|
||||||
|
|
||||||
return 0
|
|
||||||
}
|
|
||||||
|
|
||||||
function create_dev_file_linux
|
|
||||||
{
|
|
||||||
typeset filetype=$1
|
|
||||||
typeset filename=$2
|
|
||||||
|
|
||||||
case $filetype in
|
|
||||||
b)
|
|
||||||
major=$(awk '/[hsv]d/ { print $1; exit }' \
|
|
||||||
/proc/partitions)
|
|
||||||
minor=$(awk '/[hsv]d/ { print $2; exit }' \
|
|
||||||
/proc/partitions)
|
|
||||||
log_must mknod $filename b $major $minor
|
|
||||||
;;
|
|
||||||
c)
|
|
||||||
#
|
|
||||||
# Create device file '/dev/null'
|
|
||||||
#
|
|
||||||
major=$(stat -c %t /dev/null)
|
|
||||||
minor=$(stat -c %T /dev/null)
|
|
||||||
log_must mknod $filename c $major $minor
|
|
||||||
;;
|
;;
|
||||||
*)
|
*)
|
||||||
log_fail "'$filetype' is wrong."
|
log_fail "'$filetype' is wrong."
|
||||||
@ -236,6 +114,6 @@ function cleanup
|
|||||||
log_must zfs set devices=on $TESTPOOL/$TESTFS
|
log_must zfs set devices=on $TESTPOOL/$TESTFS
|
||||||
log_must rm -f $TESTDIR/$TESTFILE1
|
log_must rm -f $TESTDIR/$TESTFILE1
|
||||||
log_must rm -f $TESTDIR/$TESTFILE2
|
log_must rm -f $TESTDIR/$TESTFILE2
|
||||||
log_must rm -f $TESTDIR/$TESTFILE1.out
|
log_must rm -f $TESTDIR/$TESTFILE1.out1
|
||||||
log_must rm -f $TESTDIR/$TESTFILE2.out
|
log_must rm -f $TESTDIR/$TESTFILE1.out2
|
||||||
}
|
}
|
||||||
|
@ -32,4 +32,4 @@
|
|||||||
. $STF_SUITE/include/libtest.shlib
|
. $STF_SUITE/include/libtest.shlib
|
||||||
|
|
||||||
DISK=${DISKS%% *}
|
DISK=${DISKS%% *}
|
||||||
default_setup $DISK
|
default_volume_setup $DISK
|
||||||
|
Loading…
Reference in New Issue
Block a user