xref: /linux/tools/testing/selftests/ublk/test_shmemzc_03.sh (revision f3e3dbcea15e20f7413afd8c791a496f0b80e80b)
112075992SMing Lei#!/bin/bash
212075992SMing Lei# SPDX-License-Identifier: GPL-2.0
312075992SMing Lei# Test: shmem_zc with fio verify over filesystem on loop target
412075992SMing Lei#
512075992SMing Lei# mkfs + mount ext4 on the ublk device, then run fio verify on a
612075992SMing Lei# file inside that filesystem.  Exercises the full stack:
712075992SMing Lei# filesystem -> block layer -> ublk shmem_zc -> loop target backing file.
812075992SMing Lei
912075992SMing Lei. "$(cd "$(dirname "$0")" && pwd)"/test_common.sh
1012075992SMing Lei
1112075992SMing LeiERR_CODE=0
1212075992SMing Lei
1312075992SMing Lei_prep_test "shmem_zc" "loop target hugetlbfs shmem zero-copy fs verify test"
1412075992SMing Lei
1512075992SMing Leiif ! _have_program fio; then
1612075992SMing Lei	echo "SKIP: fio not available"
1712075992SMing Lei	exit "$UBLK_SKIP_CODE"
1812075992SMing Leifi
1912075992SMing Lei
2012075992SMing Leiif ! grep -q hugetlbfs /proc/filesystems; then
2112075992SMing Lei	echo "SKIP: hugetlbfs not supported"
2212075992SMing Lei	exit "$UBLK_SKIP_CODE"
2312075992SMing Leifi
2412075992SMing Lei
2512075992SMing Lei# Allocate hugepages
2612075992SMing LeiOLD_NR_HP=$(cat /proc/sys/vm/nr_hugepages)
2712075992SMing Leiecho 10 > /proc/sys/vm/nr_hugepages
2812075992SMing LeiNR_HP=$(cat /proc/sys/vm/nr_hugepages)
2912075992SMing Leiif [ "$NR_HP" -lt 2 ]; then
3012075992SMing Lei	echo "SKIP: cannot allocate hugepages"
3112075992SMing Lei	echo "$OLD_NR_HP" > /proc/sys/vm/nr_hugepages
3212075992SMing Lei	exit "$UBLK_SKIP_CODE"
3312075992SMing Leifi
3412075992SMing Lei
3512075992SMing Lei# Mount hugetlbfs
3612075992SMing LeiHTLB_MNT=$(mktemp -d "${UBLK_TEST_DIR}/htlb_mnt_XXXXXX")
3712075992SMing Leiif ! mount -t hugetlbfs none "$HTLB_MNT"; then
3812075992SMing Lei	echo "SKIP: cannot mount hugetlbfs"
3912075992SMing Lei	rmdir "$HTLB_MNT"
4012075992SMing Lei	echo "$OLD_NR_HP" > /proc/sys/vm/nr_hugepages
4112075992SMing Lei	exit "$UBLK_SKIP_CODE"
4212075992SMing Leifi
4312075992SMing Lei
4412075992SMing LeiHTLB_FILE="$HTLB_MNT/ublk_buf"
4512075992SMing Leifallocate -l 4M "$HTLB_FILE"
4612075992SMing Lei
4712075992SMing Lei_create_backfile 0 256M
4812075992SMing LeiBACKFILE="${UBLK_BACKFILES[0]}"
4912075992SMing Lei
5012075992SMing Leidev_id=$(_add_ublk_dev -t loop --shmem_zc --htlb "$HTLB_FILE" "$BACKFILE")
5112075992SMing Lei_check_add_dev $TID $?
5212075992SMing Lei
5312075992SMing Lei_mkfs_mount_test /dev/ublkb"${dev_id}" \
5412075992SMing Lei	_run_fio_verify_io --filename=testfile \
5512075992SMing Lei		--size=128M \
5612075992SMing Lei		--mem=mmaphuge:"$HTLB_FILE"
5712075992SMing LeiERR_CODE=$?
5812075992SMing Lei
5912075992SMing Lei# Delete device first so daemon releases the htlb mmap
6012075992SMing Lei_ublk_del_dev "${dev_id}"
6112075992SMing Lei
6212075992SMing Leirm -f "$HTLB_FILE"
6312075992SMing Leiumount "$HTLB_MNT"
6412075992SMing Leirmdir "$HTLB_MNT"
6512075992SMing Leiecho "$OLD_NR_HP" > /proc/sys/vm/nr_hugepages
6612075992SMing Lei
67*eac857a1SCaleb Sander Mateos_cleanup_test
6812075992SMing Lei
6912075992SMing Lei_show_result $TID $ERR_CODE
70