/tests/zfs-tests/tests/functional/xattr/xattr_011_pos.ksh

https://github.com/adilger/zfs · Korn Shell · 241 lines · 129 code · 42 blank · 70 comment · 6 complexity · 27fe71d54477778227651f44f473dfe4 MD5 · raw file

  1. #!/bin/ksh -p
  2. #
  3. # CDDL HEADER START
  4. #
  5. # The contents of this file are subject to the terms of the
  6. # Common Development and Distribution License (the "License").
  7. # You may not use this file except in compliance with the License.
  8. #
  9. # You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
  10. # or http://www.opensolaris.org/os/licensing.
  11. # See the License for the specific language governing permissions
  12. # and limitations under the License.
  13. #
  14. # When distributing Covered Code, include this CDDL HEADER in each
  15. # file and include the License file at usr/src/OPENSOLARIS.LICENSE.
  16. # If applicable, add the following below this CDDL HEADER, with the
  17. # fields enclosed by brackets "[]" replaced with your own identifying
  18. # information: Portions Copyright [yyyy] [name of copyright owner]
  19. #
  20. # CDDL HEADER END
  21. #
  22. # Copyright 2007 Sun Microsystems, Inc. All rights reserved.
  23. # Use is subject to license terms.
  24. #
  25. #
  26. # Copyright (c) 2012, 2016 by Delphix. All rights reserved.
  27. #
  28. #
  29. # Copyright (c) 2013, 2016 by Delphix. All rights reserved.
  30. #
  31. . $STF_SUITE/include/libtest.shlib
  32. . $STF_SUITE/tests/functional/xattr/xattr_common.kshlib
  33. #
  34. # DESCRIPTION:
  35. #
  36. # Basic applications work with xattrs: cpio cp find mv pax tar
  37. #
  38. # STRATEGY:
  39. # 1. For each application
  40. # 2. Create an xattr and archive/move/copy/find files with xattr support
  41. # 3. Also check that when appropriate flag is not used, the xattr
  42. # doesn't get copied
  43. #
  44. function cleanup {
  45. log_must rm $TESTDIR/myfile.$$
  46. }
  47. log_assert "Basic applications work with xattrs: cpio cp find mv pax tar"
  48. log_onexit cleanup
  49. # Create a file, and set an xattr on it. This file is used in several of the
  50. # test scenarios below.
  51. log_must touch $TESTDIR/myfile.$$
  52. create_xattr $TESTDIR/myfile.$$ passwd /etc/passwd
  53. # For the archive applications below (tar, cpio, pax)
  54. # we create two archives, one with xattrs, one without
  55. # and try various cpio options extracting the archives
  56. # with and without xattr support, checking for correct behaviour
  57. if is_illumos; then
  58. log_note "Checking cpio"
  59. log_must touch $TESTDIR/cpio.$$
  60. create_xattr $TESTDIR/cpio.$$ passwd /etc/passwd
  61. echo $TESTDIR/cpio.$$ | cpio -o@ > $TEST_BASE_DIR/xattr.$$.cpio
  62. echo $TESTDIR/cpio.$$ | cpio -o > $TEST_BASE_DIR/noxattr.$$.cpio
  63. # we should have no xattr here
  64. log_must cpio -iu < $TEST_BASE_DIR/xattr.$$.cpio
  65. log_mustnot eval "runat $TESTDIR/cpio.$$ cat passwd > /dev/null 2>&1"
  66. # we should have an xattr here
  67. log_must cpio -iu@ < $TEST_BASE_DIR/xattr.$$.cpio
  68. log_must eval "runat $TESTDIR/cpio.$$ cat passwd > /dev/null 2>&1"
  69. # we should have no xattr here
  70. log_must cpio -iu < $TEST_BASE_DIR/noxattr.$$.cpio
  71. log_mustnot eval "runat $TESTDIR/cpio.$$ cat passwd > /dev/null 2>&1"
  72. # we should have no xattr here
  73. log_must cpio -iu@ < $TEST_BASE_DIR/noxattr.$$.cpio
  74. log_mustnot eval "runat $TESTDIR/cpio.$$ cat passwd > /dev/null 2>&1"
  75. log_must rm $TESTDIR/cpio.$$ $TEST_BASE_DIR/xattr.$$.cpio $TEST_BASE_DIR/noxattr.$$.cpio
  76. else
  77. log_note "Checking cpio - unsupported"
  78. fi
  79. # check that with the right flag, the xattr is preserved
  80. if is_freebsd; then
  81. log_note "Checking cp - unsupported"
  82. elif is_linux; then
  83. log_note "Checking cp"
  84. log_must cp -a $TESTDIR/myfile.$$ $TESTDIR/myfile2.$$
  85. compare_xattrs $TESTDIR/myfile.$$ $TESTDIR/myfile2.$$ passwd
  86. log_must rm $TESTDIR/myfile2.$$
  87. # without the right flag, there should be no xattr
  88. log_must cp $TESTDIR/myfile.$$ $TESTDIR/myfile2.$$
  89. log_mustnot get_xattr passwd $TESTDIR/myfile2.$$
  90. log_must rm $TESTDIR/myfile2.$$
  91. else
  92. log_note "Checking cp"
  93. log_must cp -@ $TESTDIR/myfile.$$ $TESTDIR/myfile2.$$
  94. compare_xattrs $TESTDIR/myfile.$$ $TESTDIR/myfile2.$$ passwd
  95. log_must rm $TESTDIR/myfile2.$$
  96. # without the right flag, there should be no xattr
  97. log_must cp $TESTDIR/myfile.$$ $TESTDIR/myfile2.$$
  98. log_mustnot eval "runat $TESTDIR/myfile2.$$ ls passwd > /dev/null 2>&1"
  99. log_must rm $TESTDIR/myfile2.$$
  100. fi
  101. # create a file without xattrs, and check that find -xattr only finds
  102. # our test file that has an xattr.
  103. if is_illumos; then
  104. log_note "Checking find"
  105. log_must mkdir $TESTDIR/noxattrs
  106. log_must touch $TESTDIR/noxattrs/no-xattr
  107. find $TESTDIR -xattr | grep myfile.$$
  108. [[ $? -ne 0 ]] && \
  109. log_fail "find -xattr didn't find our file that had an xattr."
  110. find $TESTDIR -xattr | grep no-xattr
  111. [[ $? -eq 0 ]] && \
  112. log_fail "find -xattr found a file that didn't have an xattr."
  113. log_must rm -rf $TESTDIR/noxattrs
  114. else
  115. log_note "Checking find - unsupported"
  116. fi
  117. log_note "Checking mv"
  118. # mv doesn't have any flags to preserve/omit xattrs - they're
  119. # always moved.
  120. log_must touch $TESTDIR/mvfile.$$
  121. create_xattr $TESTDIR/mvfile.$$ passwd /etc/passwd
  122. log_must mv $TESTDIR/mvfile.$$ $TESTDIR/mvfile2.$$
  123. verify_xattr $TESTDIR/mvfile2.$$ passwd /etc/passwd
  124. log_must rm $TESTDIR/mvfile2.$$
  125. if is_illumos; then
  126. log_note "Checking pax"
  127. log_must touch $TESTDIR/pax.$$
  128. create_xattr $TESTDIR/pax.$$ passwd /etc/passwd
  129. log_must pax -w -f $TESTDIR/noxattr.pax $TESTDIR/pax.$$
  130. log_must pax -w@ -f $TESTDIR/xattr.pax $TESTDIR/pax.$$
  131. log_must rm $TESTDIR/pax.$$
  132. # we should have no xattr here
  133. log_must pax -r -f $TESTDIR/noxattr.pax
  134. log_mustnot eval "runat $TESTDIR/pax.$$ cat passwd > /dev/null 2>&1"
  135. log_must rm $TESTDIR/pax.$$
  136. # we should have no xattr here
  137. log_must pax -r@ -f $TESTDIR/noxattr.pax
  138. log_mustnot eval "runat $TESTDIR/pax.$$ cat passwd > /dev/null 2>&1"
  139. log_must rm $TESTDIR/pax.$$
  140. # we should have an xattr here
  141. log_must pax -r@ -f $TESTDIR/xattr.pax
  142. verify_xattr $TESTDIR/pax.$$ passwd /etc/passwd
  143. log_must rm $TESTDIR/pax.$$
  144. # we should have no xattr here
  145. log_must pax -r -f $TESTDIR/xattr.pax $TESTDIR
  146. log_mustnot eval "runat $TESTDIR/pax.$$ cat passwd > /dev/null 2>&1"
  147. log_must rm $TESTDIR/pax.$$ $TESTDIR/noxattr.pax $TESTDIR/xattr.pax
  148. else
  149. log_note "Checking pax - unsupported"
  150. fi
  151. log_note "Checking tar"
  152. if is_illumos; then
  153. log_must touch $TESTDIR/tar.$$
  154. create_xattr $TESTDIR/tar.$$ passwd /etc/passwd
  155. log_must cd $TESTDIR
  156. log_must tar cf noxattr.tar tar.$$
  157. log_must tar c@f xattr.tar tar.$$
  158. log_must rm $TESTDIR/tar.$$
  159. # we should have no xattr here
  160. log_must tar xf xattr.tar
  161. log_mustnot eval "runat $TESTDIR/tar.$$ cat passwd > /dev/null 2>&1"
  162. log_must rm $TESTDIR/tar.$$
  163. # we should have an xattr here
  164. log_must tar x@f xattr.tar
  165. verify_xattr tar.$$ passwd /etc/passwd
  166. log_must rm $TESTDIR/tar.$$
  167. # we should have no xattr here
  168. log_must tar xf $TESTDIR/noxattr.tar
  169. log_mustnot eval "runat $TESTDIR/tar.$$ cat passwd > /dev/null 2>&1"
  170. log_must rm $TESTDIR/tar.$$
  171. # we should have no xattr here
  172. log_must tar x@f $TESTDIR/noxattr.tar
  173. log_mustnot eval "runat $TESTDIR/tar.$$ cat passwd > /dev/null 2>&1"
  174. log_must rm $TESTDIR/tar.$$ $TESTDIR/noxattr.tar $TESTDIR/xattr.tar
  175. else
  176. log_must touch $TESTDIR/tar.$$
  177. create_xattr $TESTDIR/tar.$$ passwd /etc/passwd
  178. log_must cd $TESTDIR
  179. log_must tar --no-xattrs -cf noxattr.tar tar.$$
  180. log_must tar --xattrs -cf xattr.tar tar.$$
  181. log_must rm $TESTDIR/tar.$$
  182. # we should have no xattr here
  183. log_must tar --no-xattrs -xf xattr.tar
  184. log_mustnot get_xattr passwd $TESTDIR/tar.$$
  185. log_must rm $TESTDIR/tar.$$
  186. # we should have an xattr here
  187. log_must tar --xattrs -xf xattr.tar
  188. verify_xattr tar.$$ passwd /etc/passwd
  189. log_must rm $TESTDIR/tar.$$
  190. # we should have no xattr here
  191. log_must tar --no-xattrs -xf $TESTDIR/noxattr.tar
  192. log_mustnot get_xattr passwd $TESTDIR/tar.$$
  193. log_must rm $TESTDIR/tar.$$
  194. # we should have no xattr here
  195. log_must tar --xattrs -xf $TESTDIR/noxattr.tar
  196. log_mustnot get_xattr passwd $TESTDIR/tar.$$
  197. log_must rm $TESTDIR/tar.$$ $TESTDIR/noxattr.tar $TESTDIR/xattr.tar
  198. fi
  199. log_assert "Basic applications work with xattrs: cpio cp find mv pax tar"