8cb1f1548735c79fd3b8f58b1ebf110228978d9f
[zfs.git] / scripts / zpool-config / zpool-raid10.sh
1 #!/bin/bash
2 #
3 # Zpool Raid-10 Configuration
4 #
5 # This script is used to simplify testing with the /dev/disk/zpool/[A-Z][1-n]
6 # devices.  It assumes that you have already populated /dev/disk/zpool/ by
7 # creating an /etc/zfs/zdev.conf file based on your system design.  You may
8 # use the zpool_layout command or manually create your own config file.
9 #
10 # You can then use either the zpool-create.sh or the zpios.sh test script to
11 # test various Raid-10 configurations by adjusting the following tunables.
12 # For example if you wanted to create and test a single 4-disk Raid-10
13 # configuration using disks [A-D]1 with dedicated ZIL and L2ARC devices
14 # you could run the following.
15 #
16 # ZIL="log A2" L2ARC="cache B2" RANKS=1 CHANNELS=4 \
17 # zpool-create.sh -c zpool-raid10
18 #
19 # zpool status tank
20 #   pool: tank
21 #  state: ONLINE
22 #  scan: none requested
23 # config:
24
25 #       NAME        STATE     READ WRITE CKSUM
26 #       tank        ONLINE       0     0     0
27 #         mirror-0  ONLINE       0     0     0
28 #           A1      ONLINE       0     0     0
29 #           B1      ONLINE       0     0     0
30 #         mirror-1  ONLINE       0     0     0
31 #           C1      ONLINE       0     0     0
32 #           D1      ONLINE       0     0     0
33 #       logs
34 #         A2        ONLINE       0     0     0
35 #       cache
36 #         B2        ONLINE       0     0     0
37 #
38 # errors: No known data errors
39 #
40
41 # Number of interior vdevs to create using the following rank ids.
42 RANKS=${RANKS:-1}
43 RANK_LIST=( 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 )
44
45 # Number of devices per vdev using the following channel ids.
46 CHANNELS=${CHANNELS:-8}
47 CHANNEL_LIST=( A B C D E F G H I J K L M N O P Q R S T U V W X Y Z )
48
49 # Create a ZIL vdev as follows.
50 ZIL=${ZIL:-}
51
52 # Create an L2ARC vdev as follows.
53 L2ARC=${L2ARC:-}
54
55
56 raid10_setup() {
57         local RANKS=$1
58         local CHANNELS=$2
59         local IDX=0
60
61         RAID10S=()
62         for (( i=0, l=0 ; i<${RANKS}; i++ )); do
63                 RANK=${RANK_LIST[$i]}
64
65                 for (( j=0, k=1; j<${CHANNELS}; j+=2,k+=2,l++ )); do
66                         DISK1="${CHANNEL_LIST[$j]}${RANK}"
67                         DISK2="${CHANNEL_LIST[$k]}${RANK}"
68                         RAID10S[$l]="mirror ${DISK1} ${DISK2}"
69                 done
70         done
71
72         return 0
73 }
74
75 zpool_create() {
76         raid10_setup ${RANKS} ${CHANNELS}
77
78         ZPOOL_DEVICES="${RAID10S[*]} ${ZIL} ${L2ARC}"
79         msg ${ZPOOL} create ${FORCE_FLAG} ${ZPOOL_NAME} ${ZPOOL_DEVICES}
80         ${ZPOOL} create ${FORCE_FLAG} ${ZPOOL_NAME} ${ZPOOL_DEVICES} || exit 1
81 }
82
83 zpool_destroy() {
84         msg ${ZPOOL} destroy ${ZPOOL_NAME}
85         ${ZPOOL} destroy ${ZPOOL_NAME}
86 }