xref: /spdk/test/blobfs/blobfs.sh (revision 7506a7aa53d239f533af3bc768f0d2af55e735fe)
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=$testdir/config
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 --json ${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	sleep 1
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	sleep 1
107	killprocess $blobfs_pid
108
109	# Verify there is no file in mount dir now
110	if [ -f ${mount_dir}/rand_file ]; then
111		false
112	fi
113
114	# use blobfs mount RPC
115	blobfs_start_app
116	$rpc_py blobfs_mount ${bdevname} $mount_dir
117
118	# read and delete the rand file
119	md5sum ${mount_dir}/rand_file
120	rm ${mount_dir}/rand_file
121
122	umount ${mount_dir}
123	sleep 1
124	killprocess $blobfs_pid
125}
126
127trap 'cleanup' EXIT
128
129# Create one temp file as test bdev
130dd if=/dev/zero of=${tmp_file} bs=4k count=1M
131
132jq . <<- JSON > ${conf_file}
133	{
134	  "subsystems": [
135	    {
136	      "subsystem": "bdev",
137	      "config": [
138	        {
139	          "method": "bdev_aio_create",
140	          "params": {
141	            "name": "${bdevname}",
142	            "block_size": 512,
143	            "filename": "${tmp_file}"
144	          }
145	        },
146	        {
147	          "method": "bdev_wait_for_examine"
148		}
149	      ]
150	    }
151	  ]
152	}
153JSON
154
155blobfs_detect_test
156
157# Clear blobfs on temp file
158dd if=/dev/zero of=${tmp_file} bs=4k count=1M
159
160blobfs_create_test
161
162# Create dir for FUSE mount
163mkdir -p $mount_dir
164blobfs_fuse_test
165