/tests/zfs-tests/tests/functional/casenorm/mixed_create_failure.ksh

https://github.com/adilger/zfs · Korn Shell · 136 lines · 71 code · 19 blank · 46 comment · 12 complexity · c978d778c38d538dcce41d1128029cc5 MD5 · raw file

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