]> git.proxmox.com Git - mirror_zfs.git/blob - tests/zfs-tests/tests/functional/xattr/xattr_004_pos.ksh
Update ZTS to work on FreeBSD
[mirror_zfs.git] / tests / zfs-tests / tests / functional / xattr / xattr_004_pos.ksh
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 #
27 # Copyright (c) 2013, 2016 by Delphix. All rights reserved.
28 #
29
30 . $STF_SUITE/include/libtest.shlib
31 . $STF_SUITE/tests/functional/xattr/xattr_common.kshlib
32
33 #
34 # DESCRIPTION:
35 #
36 # Creating files on ufs|ext and tmpfs, and copying those files to ZFS with
37 # appropriate cp flags, the xattrs will still be readable.
38 #
39 # STRATEGY:
40 # 1. Create files in ufs|ext and tmpfs with xattrs
41 # 2. Copy those files to zfs
42 # 3. Ensure the xattrs can be read and written
43 # 4. Do the same in reverse.
44 #
45
46 # we need to be able to create zvols to hold our test ufs|ext filesystem.
47 verify_runnable "global"
48
49 # Make sure we clean up properly
50 function cleanup {
51 if ismounted /tmp/$NEWFS_DEFAULT_FS.$$ $NEWFS_DEFAULT_FS; then
52 log_must umount /tmp/$NEWFS_DEFAULT_FS.$$
53 log_must rm -rf /tmp/$NEWFS_DEFAULT_FS.$$
54 fi
55 }
56
57 log_assert "Files from $NEWFS_DEFAULT_FS,tmpfs with xattrs copied to zfs retain xattr info."
58 log_onexit cleanup
59
60 # Create a ufs|ext file system that we can work in
61 log_must zfs create -V128m $TESTPOOL/$TESTFS/zvol
62 block_device_wait
63 log_must eval "new_fs $ZVOL_DEVDIR/$TESTPOOL/$TESTFS/zvol > /dev/null 2>&1"
64
65 log_must mkdir /tmp/$NEWFS_DEFAULT_FS.$$
66 if is_linux; then
67 log_must mount -o user_xattr \
68 $ZVOL_DEVDIR/$TESTPOOL/$TESTFS/zvol /tmp/$NEWFS_DEFAULT_FS.$$
69
70 # Create files in ext and tmpfs, and set some xattrs on them.
71 # Use small values for xattrs for ext compatibility.
72 log_must touch /tmp/$NEWFS_DEFAULT_FS.$$/$NEWFS_DEFAULT_FS-file.$$
73
74 log_must touch /tmp/tmpfs-file.$$
75 echo "TEST XATTR" >/tmp/xattr1
76 echo "1234567890" >/tmp/xattr2
77 log_must attr -q -s xattr1 \
78 /tmp/$NEWFS_DEFAULT_FS.$$/$NEWFS_DEFAULT_FS-file.$$ </tmp/xattr1
79 log_must attr -q -s xattr2 /tmp/tmpfs-file.$$ </tmp/xattr2
80
81 # copy those files to ZFS
82 log_must cp -a /tmp/$NEWFS_DEFAULT_FS.$$/$NEWFS_DEFAULT_FS-file.$$ \
83 $TESTDIR
84 log_must cp -a /tmp/tmpfs-file.$$ $TESTDIR
85
86 # ensure the xattr information has been copied correctly
87 log_must eval "attr -q -g xattr1 $TESTDIR/$NEWFS_DEFAULT_FS-file.$$ \
88 >/tmp/xattr1.$$"
89
90 log_must diff /tmp/xattr1.$$ /tmp/xattr1
91 log_must eval "attr -q -g xattr2 $TESTDIR/tmpfs-file.$$ >/tmp/xattr2.$$"
92 log_must diff /tmp/xattr2.$$ /tmp/xattr2
93 log_must rm /tmp/xattr1 /tmp/xattr1.$$ /tmp/xattr2 /tmp/xattr2.$$
94
95 log_must umount /tmp/$NEWFS_DEFAULT_FS.$$
96 else
97 log_must mount $ZVOL_DEVDIR/$TESTPOOL/$TESTFS/zvol \
98 /tmp/$NEWFS_DEFAULT_FS.$$
99
100 # Create files in ufs and tmpfs, and set some xattrs on them.
101 log_must touch /tmp/$NEWFS_DEFAULT_FS.$$/$NEWFS_DEFAULT_FS-file.$$
102 log_must touch /tmp/tmpfs-file.$$
103
104 log_must runat /tmp/$NEWFS_DEFAULT_FS.$$/$NEWFS_DEFAULT_FS-file.$$ \
105 cp /etc/passwd .
106 log_must runat /tmp/tmpfs-file.$$ cp /etc/group .
107
108 # copy those files to ZFS
109 log_must cp -@ /tmp/$NEWFS_DEFAULT_FS.$$/$NEWFS_DEFAULT_FS-file.$$ \
110 $TESTDIR
111 log_must cp -@ /tmp/tmpfs-file.$$ $TESTDIR
112
113 # ensure the xattr information has been copied correctly
114 log_must runat $TESTDIR/$NEWFS_DEFAULT_FS-file.$$ \
115 diff passwd /etc/passwd
116 log_must runat $TESTDIR/tmpfs-file.$$ diff group /etc/group
117
118 log_must umount /tmp/$NEWFS_DEFAULT_FS.$$
119 fi
120
121 log_pass "Files from $NEWFS_DEFAULT_FS,tmpfs with xattrs copied to zfs retain xattr info."