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