1#!/usr/bin/env bash 2# SPDX-License-Identifier: BSD-3-Clause 3# Copyright (C) 2019 Intel Corporation 4# All rights reserved. 5# 6SYSTEM=$(uname -s) 7if [ $SYSTEM = "FreeBSD" ]; then 8 echo "blobfs.sh cannot run on FreeBSD currently." 9 exit 0 10fi 11 12testdir=$(readlink -f $(dirname $0)) 13rootdir=$(readlink -f $testdir/../..) 14source $rootdir/test/common/autotest_common.sh 15 16rpc_server=/var/tmp/spdk-blobfs.sock 17rpc_py="$rootdir/scripts/rpc.py -s $rpc_server" 18tmp_file=$SPDK_TEST_STORAGE/blobfs_file 19conf_file=$testdir/config 20bdevname=BlobfsBdev 21mount_dir=/tmp/spdk_tmp_mount 22test_cache_size=512 23 24function 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 34function 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 47function 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 70function 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 85function 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 /var/tmp/spdk.sock 99 100 sleep 1 101 102 # check mount status 103 mount | grep "$mount_dir" 104 105 # create a rand file in mount dir 106 dd if=/dev/urandom of=${mount_dir}/rand_file bs=4k count=32 107 108 umount ${mount_dir} 109 sleep 1 110 killprocess $blobfs_pid 111 112 # Verify there is no file in mount dir now 113 if [ -f ${mount_dir}/rand_file ]; then 114 false 115 fi 116 117 # use blobfs mount RPC 118 blobfs_start_app 119 $rpc_py blobfs_mount ${bdevname} $mount_dir 120 121 # read and delete the rand file 122 md5sum ${mount_dir}/rand_file 123 rm ${mount_dir}/rand_file 124 125 umount ${mount_dir} 126 sleep 1 127 killprocess $blobfs_pid 128} 129 130trap 'cleanup' EXIT 131 132# Create one temp file as test bdev 133dd if=/dev/zero of=${tmp_file} bs=4k count=1M 134 135jq . <<- JSON > ${conf_file} 136 { 137 "subsystems": [ 138 { 139 "subsystem": "bdev", 140 "config": [ 141 { 142 "method": "bdev_aio_create", 143 "params": { 144 "name": "${bdevname}", 145 "block_size": 512, 146 "filename": "${tmp_file}" 147 } 148 }, 149 { 150 "method": "bdev_wait_for_examine" 151 } 152 ] 153 } 154 ] 155 } 156JSON 157 158blobfs_detect_test 159 160# Clear blobfs on temp file 161dd if=/dev/zero of=${tmp_file} bs=4k count=1M 162 163blobfs_create_test 164 165# Create dir for FUSE mount 166mkdir -p $mount_dir 167blobfs_fuse_test 168