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 2008 Sun Microsystems, Inc. All rights reserved. 23# Use is subject to license terms. 24# 25 26# 27# Copyright (c) 2013 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 /tmp/output.$$ 53 [[ -e /tmp/expected_output.$$ ]] && log_must $RM \ 54 /tmp/expected_output.$$ 55 56} 57 58log_assert "create/write xattr on a snapshot fails" 59log_onexit cleanup 60 61# create a file, and an xattr on it 62log_must $TOUCH $TESTDIR/myfile.$$ 63create_xattr $TESTDIR/myfile.$$ passwd /etc/passwd 64 65# create another file that doesn't have an xattr 66log_must $TOUCH $TESTDIR/myfile2.$$ 67 68# snapshot the filesystem 69log_must $ZFS snapshot $TESTPOOL/$TESTFS@snap 70 71# we shouldn't be able to alter the first file's xattr 72log_mustnot eval " $RUNAT $TESTDIR/.zfs/snapshot/snap/myfile.$$ \ 73 $CP /etc/passwd . >/tmp/output.$$ 2>&1" 74log_must $GREP -i Read-only /tmp/output.$$ 75 76log_must eval "$RUNAT $TESTDIR/.zfs/snapshot/snap/myfile2.$$ \ 77 $LS >/tmp/output.$$ 2>&1" 78create_expected_output /tmp/expected_output.$$ SUNWattr_ro SUNWattr_rw 79log_must $DIFF /tmp/output.$$ /tmp/expected_output.$$ 80 81log_pass "create/write xattr on a snapshot fails" 82