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 2008 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# Creating and writing xattrs on files in snapshot directories fails. Also, 36# we shouldn't be able to list the xattrs of files in snapshots who didn't have 37# xattrs when the snapshot was created (the xattr namespace wouldn't have been 38# created yet, and snapshots are read-only) See fsattr(5) for more details. 39# 40# STRATEGY: 41# 1. Create a file and add an xattr to it. 42# 2. Create another file, but don't add an xattr to it. 43# 3. Snapshot the filesystem 44# 4. Verify we're unable to alter the xattr on the first file 45# 5. Verify we're unable to list the xattrs on the second file 46# 47 48function cleanup { 49 log_must zfs destroy $TESTPOOL/$TESTFS@snap 50 log_must rm $TESTDIR/myfile2.$$ 51 log_must rm $TESTDIR/myfile.$$ 52 log_must rm $TEST_BASE_DIR/output.$$ 53 [[ -e $TEST_BASE_DIR/expected_output.$$ ]] && log_must rm \ 54 $TEST_BASE_DIR/expected_output.$$ 55} 56 57log_assert "create/write xattr on a snapshot fails" 58log_onexit cleanup 59 60# create a file, and an xattr on it 61log_must touch $TESTDIR/myfile.$$ 62create_xattr $TESTDIR/myfile.$$ passwd /etc/passwd 63 64# create another file that doesn't have an xattr 65log_must touch $TESTDIR/myfile2.$$ 66 67# snapshot the filesystem 68log_must zfs snapshot $TESTPOOL/$TESTFS@snap 69 70# we shouldn't be able to alter the first file's xattr 71if is_illumos; then 72 log_mustnot eval " runat $TESTDIR/.zfs/snapshot/snap/myfile.$$ \ 73 cp /etc/passwd . > $TEST_BASE_DIR/output.$$ 2>&1" 74 log_must grep -i Read-only $TEST_BASE_DIR/output.$$ 75 log_must eval "runat $TESTDIR/.zfs/snapshot/snap/myfile2.$$ \ 76 ls > $TEST_BASE_DIR/output.$$ 2>&1" 77 create_expected_output $TEST_BASE_DIR/expected_output.$$ SUNWattr_ro SUNWattr_rw 78else 79 log_mustnot eval "set_xattr_stdin cp $TESTDIR/.zfs/snapshot/snap/myfile.$$ \ 80 </etc/passwd > $TEST_BASE_DIR/output.$$ 2>&1" 81 log_must grep -i Read-only $TEST_BASE_DIR/output.$$ 82 log_must eval "ls_xattr $TESTDIR/.zfs/snapshot/snap/myfile2.$$ \ 83 > $TEST_BASE_DIR/output.$$ 2>&1" 84 log_must eval "ls_xattr $TESTDIR/myfile2.$$ > $TEST_BASE_DIR/expected_output.$$" 85fi 86 87log_must diff $TEST_BASE_DIR/output.$$ $TEST_BASE_DIR/expected_output.$$ 88 89log_pass "create/write xattr on a snapshot fails" 90