xref: /spdk/test/blobfs/blobfs.sh (revision 0ed85362c8132a2d1927757fbcade66b6660d26a)
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/../..)
11source $rootdir/test/common/autotest_common.sh
12
13rpc_server=/var/tmp/spdk-blobfs.sock
14rpc_py="$rootdir/scripts/rpc.py -s $rpc_server"
15tmp_file=$SPDK_TEST_STORAGE/blobfs_file
16conf_file=/tmp/blobfs.conf
17bdevname=BlobfsBdev
18mount_dir=/tmp/spdk_tmp_mount
19test_cache_size=512
20
21function cleanup() {
22	if [[ -n $blobfs_pid && -e /proc/$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}
30
31function blobfs_start_app() {
32	$rootdir/test/app/bdev_svc/bdev_svc -r $rpc_server -c ${conf_file} &
33	blobfs_pid=$!
34
35	echo "Process blobfs pid: $blobfs_pid"
36	waitforlisten $blobfs_pid $rpc_server
37
38	result=$($rpc_py blobfs_set_cache_size ${test_cache_size})
39	if [ "${result}" != "True" ]; then
40		false
41	fi
42}
43
44function blobfs_detect_test() {
45	# Detect out there is no blobfs on test bdev
46	blobfs_start_app
47	result=$($rpc_py blobfs_detect ${bdevname})
48	if [ "${result}" != "False" ]; then
49		false
50	fi
51
52	killprocess $blobfs_pid
53
54	# Create blobfs on test bdev
55	$rootdir/test/blobfs/mkfs/mkfs ${conf_file} ${bdevname}
56
57	# Detect out there is a blobfs on test bdev
58	blobfs_start_app
59	result=$($rpc_py blobfs_detect ${bdevname})
60	if [ "${result}" != "True" ]; then
61		false
62	fi
63
64	killprocess $blobfs_pid
65}
66
67function blobfs_create_test() {
68	blobfs_start_app
69
70	# Create blobfs on test bdev
71	$rpc_py blobfs_create ${bdevname}
72
73	# Detect out there is a blobfs on test bdev
74	result=$($rpc_py blobfs_detect ${bdevname})
75	if [ "${result}" != "True" ]; then
76		false
77	fi
78
79	killprocess $blobfs_pid
80}
81
82function blobfs_fuse_test() {
83	if [ ! -d /usr/include/fuse3 ] && [ ! -d /usr/local/include/fuse3 ]; then
84		echo "libfuse3 is not installed which is required to this test."
85		return 0
86	fi
87
88	# mount blobfs on test dir
89	$rootdir/test/blobfs/fuse/fuse ${conf_file} ${bdevname} $mount_dir &
90	blobfs_pid=$!
91	echo "Process blobfs pid: $blobfs_pid"
92
93	# Currently blobfs fuse APP doesn't support specific path of RPC sock.
94	# So directly use default sock path.
95	waitforlisten $blobfs_pid /var/tmp/spdk.sock
96
97	# check mount status
98	mount | grep "$mount_dir"
99
100	# create a rand file in mount dir
101	dd if=/dev/urandom of=${mount_dir}/rand_file bs=4k count=32
102
103	umount ${mount_dir}
104	sleep 1
105	killprocess $blobfs_pid
106
107	# Verify there is no file in mount dir now
108	if [ -f ${mount_dir}/rand_file ]; then
109		false
110	fi
111
112	# use blobfs mount RPC
113	blobfs_start_app
114	$rpc_py blobfs_mount ${bdevname} $mount_dir
115
116	# read and delete the rand file
117	md5sum ${mount_dir}/rand_file
118	rm ${mount_dir}/rand_file
119
120	umount ${mount_dir}
121	sleep 1
122	killprocess $blobfs_pid
123}
124
125trap 'cleanup' EXIT
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} 512" >> ${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