1#!/bin/ksh -p 2# 3# CDDL HEADER START 4# 5# The contents of this file are subject to the terms of the 6# Common Development and Distribution License (the "License"). 7# You may not use this file except in compliance with the License. 8# 9# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 10# or https://opensource.org/licenses/CDDL-1.0. 11# See the License for the specific language governing permissions 12# and limitations under the License. 13# 14# When distributing Covered Code, include this CDDL HEADER in each 15# file and include the License file at usr/src/OPENSOLARIS.LICENSE. 16# If applicable, add the following below this CDDL HEADER, with the 17# fields enclosed by brackets "[]" replaced with your own identifying 18# information: Portions Copyright [yyyy] [name of copyright owner] 19# 20# CDDL HEADER END 21# 22 23# 24# Portions Copyright (c) 2022 Information2 Software, Inc. 25# 26 27. $STF_SUITE/include/libtest.shlib 28. $STF_SUITE/include/math.shlib 29 30# 31# DESCRIPTION: 32# Test posix_fadvise. 33# 34# STRATEGY: 35# 1. Set primarycache to metadata in order to disable prefetch 36# 2. Write some data to file 37# 3. get data_size field from arcstat 38# 4. call file_fadvise with POSIX_FADV_SEQUENTIAL 39# 5. get data_size field from arcstat again 40# 6. latter data_size should be bigger than former one 41# 42 43# NOTE: if HAVE_FILE_FADVISE is not defined former data_size 44# should less or eaqul to latter one 45 46verify_runnable "global" 47 48FILE=$TESTDIR/$TESTFILE0 49BLKSZ=$(get_prop recordsize $TESTPOOL) 50 51function cleanup 52{ 53 log_must zfs set primarycache=all $TESTPOOL 54 [[ -e $TESTDIR ]] && log_must rm -Rf $TESTDIR/* 55} 56 57getstat() { 58 awk -v c="$1" '$1 == c {print $3; exit}' /proc/spl/kstat/zfs/arcstats 59} 60 61log_assert "Ensure fadvise prefetch data" 62 63log_onexit cleanup 64 65log_must zfs set primarycache=metadata $TESTPOOL 66 67log_must file_write -o create -f $FILE -b $BLKSZ -c 1000 68sync_pool $TESTPOOL 69 70data_size1=$(getstat data_size) 71 72log_must file_fadvise -f $FILE -a 2 73sleep 10 74 75data_size2=$(getstat data_size) 76log_note "original data_size is $data_size1, final data_size is $data_size2" 77 78log_must [ $data_size1 -le $data_size2 ] 79 80log_pass "Ensure data could be prefetched" 81