Add zfault zpool configurations and tests
[zfs.git] / scripts / zpool-config / scsi_debug-raid10.sh
1 #!/bin/bash
2 #
3 # 1 scsi_debug device for fault injection and 3 loopback devices
4 # on top of which is layered raid10 (mirrored).
5 #
6
7 SDSIZE=${SDSIZE:-256}
8 SDHOSTS=${SDHOSTS:-1}
9 SDTGTS=${SDTGTS:-1}
10 SDLUNS=${SDLUNS:-1}
11 LDMOD=/sbin/modprobe
12 FILES="/tmp/zpool-vdev0  \
13        /tmp/zpool-vdev1  \
14        /tmp/zpool-vdev2"
15 DEVICES_M1=""
16 DEVICES_M2=""
17
18 zpool_create() {
19         local COUNT=0
20
21         check_loop_utils
22         check_sd_utils
23
24         test `${LSMOD} | grep -c scsi_debug` -gt 0 &&                        \
25                 (echo 0 >/sys/module/scsi_debug/parameters/every_nth &&      \
26                 ${RMMOD} scsi_debug || exit 1)
27         udev_trigger
28
29         msg "${LDMOD} scsi_debug dev_size_mb=${SDSIZE} "                     \
30                 "add_host=${SDHOSTS} num_tgts=${SDTGTS} "                    \
31                 "max_luns=${SDLUNS}"
32         ${LDMOD} scsi_debug                                                  \
33                 dev_size_mb=${SDSIZE}                                        \
34                 add_host=${SDHOSTS}                                          \
35                 num_tgts=${SDTGTS}                                           \
36                 max_luns=${SDLUNS} ||                                        \
37                 die "Error $? creating scsi_debug devices"
38         udev_trigger
39         SDDEVICE=`${LSSCSI}|${AWK} '/scsi_debug/ { print $6; exit }'`
40         msg "${PARTED} -s ${SDDEVICE} mklabel gpt"
41         ${PARTED} -s ${SDDEVICE} mklabel gpt ||                              \
42                 (${RMMOD} scsi_debug && die "Error $? creating gpt label")
43
44         for FILE in ${FILES}; do
45                 LODEVICE=`unused_loop_device`
46
47                 rm -f ${FILE} || exit 1
48                 dd if=/dev/zero of=${FILE} bs=1024k count=0 seek=256         \
49                         &>/dev/null || (${RMMOD} scsi_debug &&               \
50                         die "Error $? creating ${FILE}")
51
52                 # Setup the loopback device on the file.
53                 msg "Creating ${LODEVICE} using ${FILE}"
54                 ${LOSETUP} ${LODEVICE} ${FILE} || (${RMMOD} scsi_debug       \
55                         die "Error $? creating ${LODEVICE} using ${FILE}")
56
57                 DEVICES="${DEVICES} ${LODEVICE}"
58         done
59
60         DEVICES="${DEVICES} ${SDDEVICE}"
61
62         for DEVICE in ${DEVICES}; do
63                 let COUNT=${COUNT}+1
64
65                 if [ $((COUNT % 2)) -eq 0 ]; then
66                         DEVICES_M2="${DEVICES_M2} ${DEVICE}"
67                 else
68                         DEVICES_M1="${DEVICES_M1} ${DEVICE}"
69                 fi
70         done
71
72         msg "${ZPOOL} create ${FORCE_FLAG} ${ZPOOL_NAME} "                   \
73                 "mirror ${DEVICES_M1} mirror ${DEVICES_M2}"
74         ${ZPOOL} create ${FORCE_FLAG} ${ZPOOL_NAME}                          \
75                 mirror ${DEVICES_M1} mirror ${DEVICES_M2} ||                 \
76                 (${RMMOD} scsi_debug && exit 1)
77 }
78
79 zpool_destroy() {
80         msg ${ZPOOL} destroy ${ZPOOL_NAME}
81         ${ZPOOL} destroy ${ZPOOL_NAME}
82
83         for FILE in ${FILES}; do
84                 LODEVICE=`${LOSETUP} -a | grep ${FILE} | head -n1|cut -f1 -d:`
85                 msg "Removing ${LODEVICE} using ${FILE}"
86                 ${LOSETUP} -d ${LODEVICE} ||
87                         die "Error $? destroying ${LODEVICE} using ${FILE}"
88                 rm -f ${FILE} || exit 1
89         done
90
91         msg "${RMMOD} scsi_debug"
92         ${RMMOD} scsi_debug || die "Error $? removing scsi_debug devices"
93 }