xref: /spdk/test/blobfs/blobfs.sh (revision be4a5602ce7d3e2d9cc7ff6cde0b0dcb99d647c8)
1#!/usr/bin/env bash
2
3SYSTEM=$(uname -s)
4if [ $SYSTEM = "FreeBSD" ] ; then
5    echo "blobfs.sh cannot run on FreeBSD currently."
6    exit 0
7fi
8
9testdir=$(readlink -f $(dirname $0))
10rootdir=$(readlink -f $testdir/../..)
11rpc_server=/var/tmp/spdk-blobfs.sock
12rpc_py="$rootdir/scripts/rpc.py -s $rpc_server"
13tmp_file=/tmp/blobfs_file
14conf_file=/tmp/blobfs.conf
15bdevname=BlobfsBdev
16mount_dir=/tmp/spdk_tmp_mount
17test_cache_size=512
18
19source $rootdir/test/common/autotest_common.sh
20
21function on_error_exit() {
22	if [ -n "$blobfs_pid" ]; then
23		killprocess $blobfs_pid
24	fi
25
26	rm -rf $mount_dir
27	rm -f $tmp_file
28	rm -f $conf_file
29	print_backtrace
30	exit 1
31}
32
33function blobfs_start_app {
34	$rootdir/test/app/bdev_svc/bdev_svc -r $rpc_server -c ${conf_file} &
35	blobfs_pid=$!
36
37	echo "Process blobfs pid: $blobfs_pid"
38	waitforlisten $blobfs_pid $rpc_server
39
40	result=$($rpc_py blobfs_set_cache_size ${test_cache_size})
41	if [ "${result}" != "True" ]; then
42		false
43	fi
44}
45
46function blobfs_detect_test() {
47	# Detect out there is no blobfs on test bdev
48	blobfs_start_app
49	result=$($rpc_py blobfs_detect ${bdevname})
50	if [ "${result}" != "False" ]; then
51		false
52	fi
53
54	killprocess $blobfs_pid
55
56	# Create blobfs on test bdev
57	$rootdir/test/blobfs/mkfs/mkfs ${conf_file} ${bdevname}
58
59	# Detect out there is a blobfs on test bdev
60	blobfs_start_app
61	result=$($rpc_py blobfs_detect ${bdevname})
62	if [ "${result}" != "True" ]; then
63		false
64	fi
65
66	killprocess $blobfs_pid
67}
68
69function blobfs_create_test() {
70	blobfs_start_app
71
72	# Create blobfs on test bdev
73	$rpc_py blobfs_create ${bdevname}
74
75	# Detect out there is a blobfs on test bdev
76	result=$($rpc_py blobfs_detect ${bdevname})
77	if [ "${result}" != "True" ]; then
78		false
79	fi
80
81	killprocess $blobfs_pid
82}
83
84function blobfs_fuse_test() {
85	if [ ! -d /usr/include/fuse3 ] && [ ! -d /usr/local/include/fuse3 ]; then
86		echo "libfuse3 is not installed which is required to this test."
87		return 0
88	fi
89
90	# mount blobfs on test dir
91	$rootdir/test/blobfs/fuse/fuse ${conf_file} ${bdevname} $mount_dir &
92	blobfs_pid=$!
93	echo "Process blobfs pid: $blobfs_pid"
94
95	# Currently blobfs fuse APP doesn't support specific path of RPC sock.
96	# So directly use default sock path.
97	waitforlisten $blobfs_pid /var/tmp/spdk.sock
98
99	# check mount status
100	mount || grep $mount_dir
101
102	# create a rand file in mount dir
103	dd if=/dev/urandom of=${mount_dir}/rand_file bs=4k count=32
104
105	umount ${mount_dir}
106	killprocess $blobfs_pid
107
108	# Verify there is no file in mount dir now
109	if [ -f ${mount_dir}/rand_file ]; then
110		false
111	fi
112
113	# use blobfs mount RPC
114	blobfs_start_app
115	$rpc_py blobfs_mount ${bdevname} $mount_dir
116
117	# read and delete the rand file
118	md5sum ${mount_dir}/rand_file
119	rm ${mount_dir}/rand_file
120
121	umount ${mount_dir}
122	killprocess $blobfs_pid
123}
124
125trap 'on_error_exit;' ERR
126
127# Create one temp file as test bdev
128dd if=/dev/zero of=${tmp_file} bs=4k count=1M
129echo "[AIO]" > ${conf_file}
130echo "AIO ${tmp_file} ${bdevname} 4096" >> ${conf_file}
131
132blobfs_detect_test
133
134# Clear blobfs on temp file
135dd if=/dev/zero of=${tmp_file} bs=4k count=1M
136
137blobfs_create_test
138
139# Create dir for FUSE mount
140mkdir -p $mount_dir
141blobfs_fuse_test
142
143
144rm -rf $mount_dir
145rm -f $tmp_file
146report_test_completion "blobfs"
147