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 https://opensource.org/licenses/CDDL-1.0. 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# Create files on ufs|ext, copy those files to ZFS with appropriate cp flags, 37# and verify the xattrs will still be readable. 38# 39# STRATEGY: 40# 1. Create files in ufs|ext 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. 47verify_runnable "global" 48 49# Make sure we clean up properly 50function cleanup { 51 if ismounted /tmp/$NEWFS_DEFAULT_FS.$$ $NEWFS_DEFAULT_FS; then 52 log_must umount /tmp/$NEWFS_DEFAULT_FS.$$ 53 fi 54 log_must rm -rf /tmp/$NEWFS_DEFAULT_FS.$$ 55} 56 57log_assert "Files from $NEWFS_DEFAULT_FS with xattrs copied to zfs retain xattr info." 58log_onexit cleanup 59 60# Create a ufs|ext file system that we can work in 61log_must zfs create -V128m $TESTPOOL/$TESTFS/zvol 62block_device_wait 63log_must eval "new_fs $ZVOL_DEVDIR/$TESTPOOL/$TESTFS/zvol > /dev/null 2>&1" 64 65log_must mkdir /tmp/$NEWFS_DEFAULT_FS.$$ 66if is_illumos; then 67 log_must mount $ZVOL_DEVDIR/$TESTPOOL/$TESTFS/zvol \ 68 /tmp/$NEWFS_DEFAULT_FS.$$ 69 70 # Create files in ufs, and set some xattrs on them. 71 log_must touch /tmp/$NEWFS_DEFAULT_FS.$$/$NEWFS_DEFAULT_FS-file.$$ 72 73 log_must runat /tmp/$NEWFS_DEFAULT_FS.$$/$NEWFS_DEFAULT_FS-file.$$ \ 74 cp /etc/passwd . 75 76 # copy those files to ZFS 77 log_must cp -@ /tmp/$NEWFS_DEFAULT_FS.$$/$NEWFS_DEFAULT_FS-file.$$ \ 78 $TESTDIR 79 80 # ensure the xattr information has been copied correctly 81 log_must runat $TESTDIR/$NEWFS_DEFAULT_FS-file.$$ \ 82 diff passwd /etc/passwd 83 84 log_must umount /tmp/$NEWFS_DEFAULT_FS.$$ 85else 86 if is_linux; then 87 options="-o user_xattr" 88 fi 89 log_must mount ${options:+""} \ 90 $ZVOL_DEVDIR/$TESTPOOL/$TESTFS/zvol /tmp/$NEWFS_DEFAULT_FS.$$ 91 92 # Create files in ext, and set some xattrs on them. 93 # Use small values for xattrs for ext compatibility. 94 log_must touch /tmp/$NEWFS_DEFAULT_FS.$$/$NEWFS_DEFAULT_FS-file.$$ 95 96 echo "TEST XATTR" >/tmp/xattr1 97 98 log_must set_xattr_stdin xattr1 \ 99 /tmp/$NEWFS_DEFAULT_FS.$$/$NEWFS_DEFAULT_FS-file.$$ </tmp/xattr1 100 101 # copy those files to ZFS 102 if is_freebsd; then 103 # cp does not preserve extattrs on FreeBSD 104 export TAPE="-" 105 log_must eval "tar cC /tmp/$NEWFS_DEFAULT_FS.$$ \ 106 $NEWFS_DEFAULT_FS-file.$$ | tar xC $TESTDIR" 107 else 108 log_must cp -a \ 109 /tmp/$NEWFS_DEFAULT_FS.$$/$NEWFS_DEFAULT_FS-file.$$ \ 110 $TESTDIR 111 fi 112 113 # ensure the xattr information has been copied correctly 114 log_must eval "get_xattr xattr1 $TESTDIR/$NEWFS_DEFAULT_FS-file.$$ \ 115 >/tmp/xattr1.$$" 116 log_must diff /tmp/xattr1.$$ /tmp/xattr1 117 log_must rm $TESTDIR/$NEWFS_DEFAULT_FS-file.$$ 118 log_must rm /tmp/xattr1 /tmp/xattr1.$$ 119 120 log_must umount /tmp/$NEWFS_DEFAULT_FS.$$ 121fi 122 123log_pass "Files from $NEWFS_DEFAULT_FS with xattrs copied to zfs retain xattr info." 124