]> git.proxmox.com Git - ceph.git/blob - ceph/src/spdk/test/pmem/common.sh
update sources to ceph Nautilus 14.2.1
[ceph.git] / ceph / src / spdk / test / pmem / common.sh
1 BASE_DIR=$(readlink -f $(dirname $0))
2 [[ -z "$TEST_DIR" ]] && TEST_DIR="$(cd $BASE_DIR/../../ && pwd)"
3 rpc_py="$TEST_DIR/scripts/rpc.py "
4
5 source $TEST_DIR/test/common/autotest_common.sh
6
7 # Prints error message and return error code, closes vhost app and remove
8 # pmem pool file
9 # input: error message, error code
10 function error()
11 {
12 local error_code=${2:-1}
13 echo "==========="
14 echo -e "ERROR: $1"
15 echo "error code: $error_code"
16 echo "==========="
17 vhost_kill
18 pmem_clean_pool_file
19 return $error_code
20 }
21
22 # check if there is pool file & remove it
23 # input: path to pool file
24 # default: $TEST_DIR/test/pmem/pool_file
25 function pmem_clean_pool_file()
26 {
27 local pool_file=${1:-$TEST_DIR/test/pmem/pool_file}
28
29 if [ -f $pool_file ]; then
30 echo "Deleting old pool_file"
31 rm $pool_file
32 fi
33 }
34
35 # create new pmem file
36 # input: path to pool file, size in MB, block_size
37 # default: $TEST_DIR/test/pmem/pool_file 32 512
38 function pmem_create_pool_file()
39 {
40 local pool_file=${1:-$TEST_DIR/test/pmem/pool_file}
41 local size=${2:-32}
42 local block_size=${3:-512}
43
44 pmem_clean_pool_file $pool_file
45 echo "Creating new pool file"
46 if ! $rpc_py create_pmem_pool $pool_file $size $block_size; then
47 error "Creating pool_file failed!"
48 fi
49
50 if [ ! -f $pool_file ]; then
51 error "Creating pool_file failed!"
52 fi
53 }
54
55 function pmem_unmount_ramspace
56 {
57 if [ -d "$TEST_DIR/test/pmem/ramspace" ]; then
58 if mount | grep -q "$TEST_DIR/test/pmem/ramspace"; then
59 umount $TEST_DIR/test/pmem/ramspace
60 fi
61
62 rm -rf $TEST_DIR/test/pmem/ramspace
63 fi
64 }
65
66 function pmem_print_tc_name
67 {
68 echo ""
69 echo "==============================================================="
70 echo "Now running: $1"
71 echo "==============================================================="
72 }
73
74 function vhost_start()
75 {
76 local vhost_pid
77
78 $TEST_DIR/app/vhost/vhost &
79 if [ $? != 0 ]; then
80 echo -e "ERROR: Failed to launch vhost!"
81 return 1
82 fi
83
84 vhost_pid=$!
85 echo $vhost_pid > $TEST_DIR/test/pmem/vhost.pid
86 waitforlisten $vhost_pid
87 }
88
89 function vhost_kill()
90 {
91 local vhost_pid_file="$TEST_DIR/test/pmem/vhost.pid"
92 local vhost_pid="$(cat $vhost_pid_file)"
93
94 if [[ ! -f $TEST_DIR/test/pmem/vhost.pid ]]; then
95 echo -e "ERROR: No vhost pid file found!"
96 return 1
97 fi
98
99 if ! kill -s INT $vhost_pid; then
100 echo -e "ERROR: Failed to exit vhost / invalid pid!"
101 rm $vhost_pid_file
102 return 1
103 fi
104
105 sleep 1
106 rm $vhost_pid_file
107 }