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 # 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 128trap 'cleanup' EXIT 129 130# Create one temp file as test bdev 131dd if=/dev/zero of=${tmp_file} bs=4k count=1M 132 133jq . <<- 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 } 154JSON 155 156blobfs_detect_test 157 158# Clear blobfs on temp file 159dd if=/dev/zero of=${tmp_file} bs=4k count=1M 160 161blobfs_create_test 162 163# Create dir for FUSE mount 164mkdir -p $mount_dir 165blobfs_fuse_test 166