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