]> git.proxmox.com Git - ceph.git/blob - ceph/src/spdk/test/ftl/restore.sh
import 15.2.0 Octopus source
[ceph.git] / ceph / src / spdk / test / ftl / restore.sh
1 #!/usr/bin/env bash
2
3 set -e
4
5 testdir=$(readlink -f $(dirname $0))
6 rootdir=$(readlink -f $testdir/../..)
7 rpc_py=$rootdir/scripts/rpc.py
8
9 source $rootdir/test/common/autotest_common.sh
10
11 mount_dir=$(mktemp -d)
12 device=$1
13 uuid=$2
14
15 restore_kill() {
16 if mount | grep $mount_dir; then
17 umount $mount_dir
18 fi
19 rm -rf $mount_dir
20 rm -f $testdir/testfile.md5
21 rm -f $testdir/config/ftl.json
22
23 $rpc_py delete_ftl_bdev -b nvme0
24 killprocess $svcpid
25 rmmod nbd || true
26 }
27
28 trap "restore_kill; exit 1" SIGINT SIGTERM EXIT
29
30 $rootdir/test/app/bdev_svc/bdev_svc & svcpid=$!
31 # Wait until bdev_svc starts
32 waitforlisten $svcpid
33
34 if [ -n "$uuid" ]; then
35 $rpc_py construct_ftl_bdev -b nvme0 -a $device -l 0-3 -u $uuid
36 else
37 $rpc_py construct_ftl_bdev -b nvme0 -a $device -l 0-3
38 fi
39
40 # Load the nbd driver
41 modprobe nbd
42 $rpc_py start_nbd_disk nvme0 /dev/nbd0
43 waitfornbd nbd0
44
45 $rpc_py save_config > $testdir/config/ftl.json
46
47 # Prepare the disk by creating ext4 fs and putting a file on it
48 mkfs.ext4 -F /dev/nbd0
49 mount /dev/nbd0 $mount_dir
50 dd if=/dev/urandom of=$mount_dir/testfile bs=4K count=256K
51 sync
52 mount -o remount /dev/nbd0 $mount_dir
53 md5sum $mount_dir/testfile > $testdir/testfile.md5
54
55 # Kill bdev service and start it again
56 umount $mount_dir
57 killprocess $svcpid
58
59 $rootdir/test/app/bdev_svc/bdev_svc & svcpid=$!
60 # Wait until bdev_svc starts
61 waitforlisten $svcpid
62
63 $rpc_py load_config < $testdir/config/ftl.json
64
65 mount /dev/nbd0 $mount_dir
66 md5sum -c $testdir/testfile.md5
67
68 report_test_completion occsd_restore
69
70 trap - SIGINT SIGTERM EXIT
71 restore_kill