Path: blob/main/tests/sys/geom/class/mirror/component_selection.sh
39635 views
1ATF_TEST=true2class=mirror3. $(atf_get_srcdir)/conf.sh45atf_test_case run_latest_genid cleanup6run_latest_genid_head()7{8atf_set "descr" \9"Ensure that we properly select components (latest genid) during STARTING."10atf_set "require.user" "root"11}12run_latest_genid_body()13{14geom_atf_test_setup15if ! error_message=$(geom_load_class_if_needed nop); then16atf_skip "$error_message"17fi1819f1=$(mktemp ${base}.XXXXXX)20f2=$(mktemp ${base}.XXXXXX)21f3=$(mktemp ${base}.XXXXXX)22rnd1=$(mktemp ${base}.XXXXXX)23rnd2=$(mktemp ${base}.XXXXXX)2425atf_check truncate -s 2M $f126atf_check truncate -s 2M $f227atf_check truncate -s 2M $f328dd if=/dev/urandom bs=512 count=1 of="$rnd1"29dd if=/dev/urandom bs=512 count=1 of="$rnd2"3031attach_md md1 -t vnode -f ${f1}32attach_md md2 -t vnode -f ${f2}33attach_md md3 -t vnode -f ${f3}3435# Use a gnop for md1 just for consistency; it's not used for anything.36atf_check gnop create $md137atf_check gnop create $md238atf_check gnop create $md339# Hardcode component names so that the non-.nop device isn't tasted40# instead.41atf_check gmirror label -h $name ${md1}.nop42devwait4344atf_check gmirror insert -h $name ${md2}.nop45atf_check gmirror insert -h $name ${md3}.nop46syncwait4748# Fail mirror 3, writing known contents to mirror 1+2 block 149atf_check -s exit:0 -e empty -o empty \50gnop configure -w 100 ${md3}.nop51atf_check -s exit:0 dd if="$rnd1" bs=512 count=1 oseek=1 conv=notrunc \52of=/dev/mirror/$name status=none5354disconnectwait nop "${md3}.nop"5556# Should have two mirrors remaining after md3 was evicted57atf_check [ $(gmirror status -s $name | wc -l) -eq 2 ]58atf_check -s exit:0 -o match:"DEGRADED ${md1}.nop \(ACTIVE\)" \59gmirror status -s $name60atf_check -s exit:0 -o match:"DEGRADED ${md2}.nop \(ACTIVE\)" \61gmirror status -s $name6263# Repeat:64# Fail mirror 2, writing known contents to mirror 1 block 265atf_check -s exit:0 -e empty -o empty \66gnop configure -w 100 ${md2}.nop67atf_check -s exit:0 dd if="$rnd2" bs=512 count=2 oseek=1 conv=notrunc \68of=/dev/mirror/$name status=none6970disconnectwait nop "${md2}.nop"7172# Should have one mirror remaining after md2 was evicted73atf_check [ $(gmirror status -s $name | wc -l) -eq 1 ]74atf_check -s exit:0 -o match:"DEGRADED ${md1}.nop \(ACTIVE\)" \75gmirror status -s $name7677# Stop the mirror and remove the pieces so gmirror can't see them.78atf_check gmirror stop $name79atf_check gnop destroy ${md1}.nop80atf_check gnop destroy ${md2}.nop81atf_check gnop destroy ${md3}.nop8283# Rebuild; spin up "disk" with lowest genid84atf_check gnop create $md385md3gen=$(gmirror dump /dev/${md3}.nop | grep genid | cut -d: -f2)86# Assert gmirror is referencing this component for now:87atf_check [ $(consumerrefs nop ${md3}.nop) = "r1w1e1" ]8889# Adding newer genid should kick out old component90atf_check gnop create $md291md2gen=$(gmirror dump /dev/${md2}.nop | grep genid | cut -d: -f2)92atf_check [ $md2gen -gt $md3gen ]9394disconnectwait nop "${md3}.nop"9596# Can't test this because 'status' doesn't exist until RUNNING:97#atf_check [ $(gmirror status -s $name | wc -l) -eq 1 ]98# But as a substitute, assert gmirror has dropped reference to staler99# component in favor of newer component:100atf_check [ $(consumerrefs nop ${md2}.nop) = "r1w1e1" ]101102# ditto103atf_check gnop create $md1104md1gen=$(gmirror dump /dev/${md1}.nop | grep genid | cut -d: -f2)105atf_check [ $md1gen -gt $md2gen ]106107disconnectwait nop "${md2}.nop"108109# Assert gmirror has dropped reference to stale component in favor of110# newer component:111atf_check [ $(consumerrefs nop ${md1}.nop) = "r1w1e1" ]112113# gmirror won't start the mirror automatically with only one component114# ($md0) of configured three, so this waits out the115# kern.geom.mirror.timeout:116devwait117118atf_check [ $(gmirror status -s $name | wc -l) -eq 1 ]119atf_check -s exit:0 -o match:"DEGRADED ${md1}.nop \(ACTIVE\)" \120gmirror status -s $name121}122run_latest_genid_cleanup()123{124. $(atf_get_srcdir)/conf.sh125126if [ -f "$TEST_MDS_FILE" ]; then127while read test_md; do128echo "# Removing test gnop: ${test_md}.nop"129gnop destroy -f "${test_md}.nop" 2>/dev/null || :130done < "$TEST_MDS_FILE"131fi132gmirror_test_cleanup133}134135atf_init_test_cases()136{137atf_add_test_case run_latest_genid138}139140141