]> git.proxmox.com Git - ceph.git/blob - ceph/src/spdk/test/ftl/restore.sh
7b6b0ef0570c9b5bf0cadbf749a01a267a6b6732
[ceph.git] / ceph / src / spdk / test / ftl / restore.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 source $testdir/common.sh
7
8 rpc_py=$rootdir/scripts/rpc.py
9
10 mount_dir=$(mktemp -d)
11
12 while getopts ':u:c:' opt; do
13 case $opt in
14 u) uuid=$OPTARG ;;
15 c) nv_cache=$OPTARG ;;
16 ?) echo "Usage: $0 [-u UUID] [-c NV_CACHE_PCI_BDF] OCSSD_PCI_BDF" && exit 1 ;;
17 esac
18 done
19 shift $((OPTIND - 1))
20 device=$1
21 num_group=$(get_num_group $device)
22 num_pu=$(get_num_pu $device)
23 pu_count=$((num_group * num_pu))
24
25 restore_kill() {
26 if mount | grep $mount_dir; then
27 umount $mount_dir
28 fi
29 rm -rf $mount_dir
30 rm -f $testdir/testfile.md5
31 rm -f $testdir/testfile2.md5
32 rm -f $testdir/config/ftl.json
33
34 killprocess $svcpid
35 rmmod nbd || true
36 }
37
38 trap "restore_kill; exit 1" SIGINT SIGTERM EXIT
39
40 "$SPDK_BIN_DIR/spdk_tgt" --json <(gen_ftl_nvme_conf) &
41 svcpid=$!
42 # Wait until spdk_tgt starts
43 waitforlisten $svcpid
44
45 if [ -n "$nv_cache" ]; then
46 nvc_bdev=$(create_nv_cache_bdev nvc0 $device $nv_cache $pu_count)
47 fi
48
49 $rpc_py bdev_nvme_attach_controller -b nvme0 -a $device -t pcie
50 $rpc_py bdev_ocssd_create -c nvme0 -b nvme0n1 -n 1
51 ftl_construct_args="bdev_ftl_create -b ftl0 -d nvme0n1"
52
53 [ -n "$uuid" ] && ftl_construct_args+=" -u $uuid"
54 [ -n "$nv_cache" ] && ftl_construct_args+=" -c $nvc_bdev"
55
56 $rpc_py $ftl_construct_args
57
58 # Load the nbd driver
59 modprobe nbd
60 $rpc_py nbd_start_disk ftl0 /dev/nbd0
61 waitfornbd nbd0
62
63 $rpc_py save_config > $testdir/config/ftl.json
64
65 # Prepare the disk by creating ext4 fs and putting a file on it
66 make_filesystem ext4 /dev/nbd0
67 mount /dev/nbd0 $mount_dir
68 dd if=/dev/urandom of=$mount_dir/testfile bs=4K count=256K
69 sync
70 mount -o remount /dev/nbd0 $mount_dir
71 md5sum $mount_dir/testfile > $testdir/testfile.md5
72
73 # Kill bdev service and start it again
74 umount $mount_dir
75 killprocess $svcpid
76
77 "$SPDK_BIN_DIR/spdk_tgt" --json <(gen_ftl_nvme_conf) -L ftl_init &
78 svcpid=$!
79 # Wait until spdk_tgt starts
80 waitforlisten $svcpid
81
82 $rpc_py load_config < $testdir/config/ftl.json
83 waitfornbd nbd0
84
85 mount /dev/nbd0 $mount_dir
86
87 # Write second file, to make sure writer thread has restored properly
88 dd if=/dev/urandom of=$mount_dir/testfile2 bs=4K count=256K
89 md5sum $mount_dir/testfile2 > $testdir/testfile2.md5
90
91 # Make sure second file will be read from disk
92 echo 3 > /proc/sys/vm/drop_caches
93
94 # Check both files have proper data
95 md5sum -c $testdir/testfile.md5
96 md5sum -c $testdir/testfile2.md5
97
98 trap - SIGINT SIGTERM EXIT
99 restore_kill