#! /bin/bash
# SPDX-License-Identifier: GPL-2.0
# Copyright (c) 2025 Chao Yu.  All Rights Reserved.
#
# FS QA Test No. f2fs/015
#
# This testcase tries to check stability of mount result
# w/ common mount option and their combination.
#
. ./common/preamble
_begin_fstest auto quick mount
_require_kernel_config CONFIG_F2FS_FS_XATTR
_require_kernel_config CONFIG_F2FS_FS_POSIX_ACL
_require_kernel_config CONFIG_F2FS_FAULT_INJECTION

options=(
#	mount_option			mkfs_option
	"background_gc=on"		""			\
	"background_gc=off"		""			\
	"background_gc=sync"		""			\
	"disable_roll_forward"		""			\
	"norecovery"			""			\
	"discard"			""			\
	"nodiscard"			""			\
	"no_heap"			""			\
	"heap"				""			\
	"user_xattr"			""			\
	"nouser_xattr"			""			\
	"acl"				""			\
	"noacl"				""			\
	"active_logs=2"			""			\
	"active_logs=4"			""			\
	"active_logs=6"			""			\
	"disable_ext_identify"		""			\
	"inline_xattr"			""			\
	"noinline_xattr"		""			\
	"inline_xattr_size=400"		""			\
	"inline_data"			""			\
	"noinline_dentry"		""			\
	"inline_dentry"			""			\
	"noinline_dentry"		""			\
	"flush_merge"			""			\
	"noflush_merge"			""			\
	"barrier"			""			\
	"nobarrier"			""			\
	"fastboot"			""			\
	"extent_cache"			""			\
	"noextent_cache"		""			\
	"data_flush"			""			\
	"reserve_root=32768"		""			\
	"resuid=1000"			""			\
	"resgid=1000"			""			\
	"fault_injection=100"		""			\
	"fault_type=4095"		""			\
	"mode=adaptive"			""			\
	"mode=lfs"			""			\
	"mode=fragment:segment"		""			\
	"mode=fragment:block"		""			\
	"usrquota"			""			\
	"grpquota"			""			\
	"prjquota"			""			\
	"usrjquota=ausrquota"		""			\
	"grpjquota=agrpquota"		""			\
	"prjjquota=aprjquota"		""			\
	"jqfmt=vfsold"			""			\
	"jqfmt=vfsv0"			""			\
	"jqfmt=vfsv1"			""			\
	"usrjquota="			""			\
	"grpjquota="			""			\
	"prjjquota="			""			\
	"quota"				""			\
	"noquota"			""			\
	"alloc_mode=reuse"		""			\
	"alloc_mode=default"		""			\
	"fsync_mode=posix"		""			\
	"fsync_mode=strict"		""			\
	"fsync_mode=nobarrier"		""			\
	"test_dummy_encryption"		""			\
	"test_dummy_encryption=v1"	""			\
	"test_dummy_encryption=v2"	""			\
	"checkpoint=enable"		""			\
	"checkpoint=disable"		""			\
	"checkpoint=disable:32768"	""			\
	"checkpoint=disable:50%"	""			\
	"checkpoint_merge"		""			\
	"nocheckpoint_merge"		""			\
	"compress_algorithm=lzo"	""			\
	"inlinecrypt"			""			\
	"atgc"				""			\
	"discard_unit=block"		""			\
	"discard_unit=segment"		""			\
	"discard_unit=section"		""			\
	"memory=normal"			""			\
	"memory=low"			""			\
	"age_extent_cache"		""			\
	"errors=panic"			""			\
	"errors=continue"		""			\
	"errors=remount-ro"		""			\
	"nat_bits"			""			\
	"atgc,mode=lfs"			""			\
	"ro,flush_merge"		""			\
	"rw"				"ro"			\
	"norecovery,ro"			""			\
)

for ((i=0;i<${#options[@]};i=i+2))
do
	echo "Option#$i: ${options[$i]} : ${options[$((i+1))]}"

	if [ "${options[$((i+1))]}" ]; then
		_scratch_mkfs "-O ${options[$((i+1))]}" >> $seqres.full || _fail "mkfs failed"
	else
		_scratch_mkfs >> $seqres.full || _fail "mkfs failed"
	fi
	_try_scratch_mount "-o ${options[$i]}" >> $seqres.full 2>&1
	echo $?
	_scratch_unmount >> $seqres.full 2>&1
done

status=0
exit
