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