/tests/zfs-tests/tests/functional/alloc_class/alloc_class_012_pos.ksh

https://github.com/adilger/zfs · Korn Shell · 122 lines · 70 code · 18 blank · 34 comment · 4 complexity · ede3969dedcfd729e9e3fefcc44053af MD5 · raw file

  1. #!/bin/ksh -p
  2. #
  3. # This file and its contents are supplied under the terms of the
  4. # Common Development and Distribution License ("CDDL"), version 1.0.
  5. # You may only use this file in accordance with the terms of version
  6. # 1.0 of the CDDL.
  7. #
  8. # A full copy of the text of the CDDL should have accompanied this
  9. # source. A copy of the CDDL is also available via the Internet at
  10. # http://www.illumos.org/license/CDDL.
  11. #
  12. #
  13. # Copyright (c) 2018 by Delphix. All rights reserved.
  14. #
  15. . $STF_SUITE/tests/functional/alloc_class/alloc_class.kshlib
  16. #
  17. # DESCRIPTION:
  18. # Removing a special device from a pool succeeds.
  19. #
  20. verify_runnable "global"
  21. #
  22. # Verify the file identified by the input <inode> is written on a special vdev
  23. # According to the pool layout used in this test vdev_id 3 and 4 are special
  24. # XXX: move this function to libtest.shlib once we get "Vdev Properties"
  25. #
  26. function file_in_special_vdev # <dataset> <inode>
  27. {
  28. typeset dataset="$1"
  29. typeset inum="$2"
  30. zdb -dddddd $dataset $inum | awk '{
  31. # find DVAs from string "offset level dva" only for L0 (data) blocks
  32. if (match($0,"L0 [0-9]+")) {
  33. dvas[0]=$3
  34. dvas[1]=$4
  35. dvas[2]=$5
  36. for (i = 0; i < 3; ++i) {
  37. if (match(dvas[i],"([^:]+):.*")) {
  38. dva = substr(dvas[i], RSTART, RLENGTH);
  39. # parse DVA from string "vdev:offset:asize"
  40. if (split(dva,arr,":") != 3) {
  41. print "Error parsing DVA: <" dva ">";
  42. exit 1;
  43. }
  44. # verify vdev is "special"
  45. if (arr[1] < 3) {
  46. exit 1;
  47. }
  48. }
  49. }
  50. }}'
  51. }
  52. #
  53. # Check that device removal works for special class vdevs
  54. #
  55. function check_removal
  56. {
  57. #
  58. # Create a non-raidz pool so we can remove top-level vdevs
  59. #
  60. log_must disk_setup
  61. log_must zpool create $TESTPOOL $ZPOOL_DISKS \
  62. special $CLASS_DISK0 special $CLASS_DISK1
  63. log_must display_status "$TESTPOOL"
  64. #
  65. # Generate some metadata and small blocks in the special class vdev
  66. # before removal
  67. #
  68. typeset -l i=1
  69. typeset -l blocks=25
  70. log_must zfs create -o special_small_blocks=32K -o recordsize=32K \
  71. $TESTPOOL/$TESTFS
  72. for i in 1 2 3 4; do
  73. log_must dd if=/dev/urandom of=/$TESTPOOL/$TESTFS/testfile.$i \
  74. bs=1M count=$blocks
  75. ((blocks = blocks + 25))
  76. done
  77. log_must sync_pool $TESTPOOL
  78. log_must zpool list -v $TESTPOOL
  79. # Verify the files were written in the special class vdevs
  80. for i in 1 2 3 4; do
  81. dataset="$TESTPOOL/$TESTFS"
  82. inum="$(get_objnum /$TESTPOOL/$TESTFS/testfile.$i)"
  83. log_must file_in_special_vdev $dataset $inum
  84. done
  85. log_must zpool remove $TESTPOOL $CLASS_DISK0
  86. sleep 5
  87. log_must sync_pool $TESTPOOL
  88. sleep 1
  89. log_must zdb -bbcc $TESTPOOL
  90. log_must zpool list -v $TESTPOOL
  91. log_must zpool destroy -f "$TESTPOOL"
  92. log_must disk_cleanup
  93. }
  94. claim="Removing a special device from a pool succeeds."
  95. log_assert $claim
  96. log_onexit cleanup
  97. typeset CLASS_DEVSIZE=$CLASS_DEVSIZE
  98. for CLASS_DEVSIZE in $CLASS_DEVSIZE $ZPOOL_DEVSIZE; do
  99. typeset ZPOOL_DISKS=$ZPOOL_DISKS
  100. for ZPOOL_DISKS in "$ZPOOL_DISKS" $ZPOOL_DISK0; do
  101. check_removal
  102. done
  103. done
  104. log_pass $claim