]> git.proxmox.com Git - ceph.git/blob - ceph/src/spdk/test/nvme/hotplug.sh
update source to Ceph Pacific 16.2.2
[ceph.git] / ceph / src / spdk / test / nvme / hotplug.sh
1 #!/usr/bin/env bash
2
3 testdir=$(readlink -f $(dirname $0))
4 rootdir=$(readlink -f $testdir/../..)
5 source $rootdir/test/common/autotest_common.sh
6
7 if [ -z "${DEPENDENCY_DIR}" ]; then
8 echo DEPENDENCY_DIR not defined!
9 exit 1
10 fi
11
12 function ssh_vm() {
13 xtrace_disable
14 sshpass -p "$password" ssh -o PubkeyAuthentication=no \
15 -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null -p 10022 root@localhost "$@"
16 xtrace_restore
17 }
18
19 function monitor_cmd() {
20 echo "$@" | nc localhost 4444 | tail --lines=+2 | (grep -v '^(qemu) ' || true)
21 }
22
23 function get_online_devices_count() {
24 ssh_vm "lspci | grep -c NVM"
25 }
26
27 function wait_for_devices_ready() {
28 count=$(get_online_devices_count)
29
30 while [ $count -ne 4 ]; do
31 echo "waitting for all devices online"
32 count=$(get_online_devices_count)
33 done
34 }
35
36 function insert_devices() {
37 for i in {0..3}; do
38 monitor_cmd "device_add nvme,drive=drive$i,id=nvme$i,serial=nvme$i"
39 done
40 wait_for_devices_ready
41 ssh_vm "scripts/setup.sh"
42 }
43
44 function remove_devices() {
45 for i in {0..3}; do
46 monitor_cmd "device_del nvme$i"
47 done
48 }
49
50 function devices_delete() {
51 for i in {0..3}; do
52 rm "$SPDK_TEST_STORAGE/nvme$i.img"
53 done
54 }
55
56 password=$1
57 base_img=${DEPENDENCY_DIR}/fedora-hotplug.qcow2
58 test_img=${DEPENDENCY_DIR}/fedora-hotplug-test.qcow2
59 qemu_pidfile=${DEPENDENCY_DIR}/qemupid
60
61 if [ ! -e "$base_img" ]; then
62 echo "Hotplug VM image not found; skipping test"
63 exit 0
64 fi
65
66 timing_enter start_qemu
67
68 qemu-img create -b "$base_img" -f qcow2 "$test_img"
69
70 for i in {0..3}; do
71 dd if=/dev/zero of="$SPDK_TEST_STORAGE/nvme$i.img" bs=1M count=1024
72 done
73
74 qemu-system-x86_64 \
75 -daemonize -display none -m 8192 \
76 -pidfile "$qemu_pidfile" \
77 -hda "$test_img" \
78 -net user,hostfwd=tcp::10022-:22 \
79 -net nic \
80 -cpu host \
81 -smp cores=16,sockets=1 \
82 --enable-kvm \
83 -chardev socket,id=mon0,host=localhost,port=4444,server,nowait \
84 -mon chardev=mon0,mode=readline \
85 -drive format=raw,file="$SPDK_TEST_STORAGE/nvme0.img",if=none,id=drive0 \
86 -drive format=raw,file="$SPDK_TEST_STORAGE/nvme1.img",if=none,id=drive1 \
87 -drive format=raw,file="$SPDK_TEST_STORAGE/nvme2.img",if=none,id=drive2 \
88 -drive format=raw,file="$SPDK_TEST_STORAGE/nvme3.img",if=none,id=drive3
89
90 timing_exit start_qemu
91
92 timing_enter wait_for_vm
93 ssh_vm 'echo ready'
94 timing_exit wait_for_vm
95
96 timing_enter copy_repo
97 files_to_copy="scripts "
98 files_to_copy+="include/spdk/pci_ids.h "
99 files_to_copy+="build/examples/hotplug "
100 files_to_copy+="build/lib "
101 files_to_copy+="dpdk/build/lib "
102 (
103 cd "$rootdir"
104 tar -cf - $files_to_copy
105 ) | (ssh_vm "tar -xf -")
106 timing_exit copy_repo
107
108 insert_devices
109
110 timing_enter hotplug_test
111
112 ssh_vm "LD_LIBRARY_PATH=/root//build/lib:/root/dpdk/build/lib:$LD_LIBRARY_PATH build/examples/hotplug -i 0 -t 25 -n 4 -r 8" &
113 example_pid=$!
114
115 sleep 6
116 remove_devices
117 sleep 4
118 insert_devices
119 sleep 6
120 remove_devices
121 devices_delete
122
123 timing_enter wait_for_example
124 wait $example_pid
125 timing_exit wait_for_example
126
127 trap - SIGINT SIGTERM EXIT
128
129 qemupid=$(awk '{printf $0}' "$qemu_pidfile")
130 kill -9 $qemupid
131 rm "$qemu_pidfile"
132 rm "$test_img"
133
134 timing_exit hotplug_test