1#!/bin/ksh -p 2# SPDX-License-Identifier: CDDL-1.0 3# 4# 5# This file and its contents are supplied under the terms of the 6# Common Development and Distribution License ("CDDL"), version 1.0. 7# You may only use this file in accordance with the terms of version 8# 1.0 of the CDDL. 9# 10# A full copy of the text of the CDDL should have accompanied this 11# source. A copy of the CDDL is also available via the Internet at 12# http://www.illumos.org/license/CDDL. 13# 14# 15# Copyright 2018 Nutanix Inc. All rights reserved. 16# 17 18. $STF_SUITE/tests/functional/casenorm/casenorm.kshlib 19 20# DESCRIPTION: 21# For the filesystem with casesensitivity=mixed, normalization=none, 22# when multiple files with the same name (differing only in case) are created, 23# the number of files is limited to what can fit in a fatzap leaf-block. 24# And beyond that, it fails with ENOSPC. 25# 26# Ensure that the create/rename operations fail gracefully and not trigger an 27# ASSERT. 28# 29# STRATEGY: 30# Repeat the below steps for objects: files, directories, symlinks and hardlinks 31# 1. Create objects with same name but varying in case. 32# E.g. 'abcdefghijklmnop', 'Abcdefghijklmnop', 'ABcdefghijklmnop' etc. 33# The create should fail with ENOSPC. 34# 2. Create an object with name 'tmp_obj' and try to rename it to name that we 35# failed to add in step 1 above. 36# This should fail as well. 37 38verify_runnable "global" 39 40function cleanup 41{ 42 destroy_testfs 43} 44 45log_onexit cleanup 46log_assert "With mixed mode: ensure create fails with ENOSPC beyond a certain limit" 47 48create_testfs "-o casesensitivity=mixed -o normalization=none" 49 50# Different object types 51obj_type=('file' 'dir' 'symlink' 'hardlink') 52 53# Commands to create different object types 54typeset -A ops 55ops['file']='touch' 56ops['dir']='mkdir' 57ops['symlink']='ln -s' 58ops['hardlink']='ln' 59 60# This function tests the following for a give object type : 61# - Create multiple objects with the same name (varying only in case). 62# Ensure that it eventually fails once the leaf-block limit is exceeded. 63# - Create another object with a different name. And attempt rename it to the 64# name (for which the create had failed in the previous step). 65# This should fail as well. 66# Args : 67# $1 - object type (file/dir/symlink/hardlink) 68# $2 - test directory 69# 70function test_ops 71{ 72 typeset obj_type=$1 73 typeset testdir=$2 74 typeset save_name= 75 76 target_obj='target-file' 77 78 op="${ops[$obj_type]}" 79 80 log_note "The op : $op" 81 log_note "testdir=$testdir obj_type=$obj_type" 82 83 test_path="$testdir/$obj_type" 84 mkdir $test_path 85 log_note "Created test dir $test_path" 86 87 if [[ $obj_type = "symlink" || $obj_type = "hardlink" ]]; then 88 > $test_path/$target_obj 89 log_note "Created target: $test_path/$target_obj" 90 op="$op $test_path/$target_obj" 91 fi 92 93 log_note "op : $op" 94 names='{a,A}{b,B}{c,C}{d,D}{e,E}{f,F}{g,G}{h,H}{i,I}{j,J}{k,K}{l,L}' 95 for name in $names; do 96 cmd="$op $test_path/$name" 97 out=$($cmd 2>&1) 98 ret=$? 99 log_note "cmd: $cmd ret: $ret out=$out" 100 if (($ret != 0)); then 101 if [[ $out = *@(No space left on device)* ]]; then 102 save_name="$test_path/$name" 103 break; 104 else 105 log_fail "$cmd failed: $out" 106 fi 107 fi 108 done 109 [ -n "$save_name" ] || log_fail "Didn't ENOSPC!" 110 111 log_note 'Test rename "sample_name" rename' 112 TMP_OBJ="$test_path/tmp_obj" 113 cmd="$op $TMP_OBJ" 114 log_must $cmd 115 116 # Now, try to rename the tmp_obj to the name which we failed to add earlier. 117 # This should fail as well. 118 if ! out=$(mv $TMP_OBJ $save_name 2>&1); then 119 if [[ $out = *@(No space left on device)* ]]; then 120 log_note "$cmd failed as expected: $out" 121 else 122 log_fail "$cmd failed: $out" 123 fi 124 fi 125} 126 127for obj_type in ${obj_type[*]}; 128do 129 log_note "Testing create of $obj_type" 130 test_ops $obj_type $TESTDIR 131done 132 133log_pass "Mixed mode FS: Ops on large number of colliding names fail gracefully" 134