xref: /onnv-gate/usr/src/uts/common/fs/ufs/ufs_xattr.c (revision 4662:9c48274ded8b)
10Sstevel@tonic-gate /*
20Sstevel@tonic-gate  * CDDL HEADER START
30Sstevel@tonic-gate  *
40Sstevel@tonic-gate  * The contents of this file are subject to the terms of the
5*4662Sfrankho  * Common Development and Distribution License (the "License").
6*4662Sfrankho  * You may not use this file except in compliance with the License.
70Sstevel@tonic-gate  *
80Sstevel@tonic-gate  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
90Sstevel@tonic-gate  * or http://www.opensolaris.org/os/licensing.
100Sstevel@tonic-gate  * See the License for the specific language governing permissions
110Sstevel@tonic-gate  * and limitations under the License.
120Sstevel@tonic-gate  *
130Sstevel@tonic-gate  * When distributing Covered Code, include this CDDL HEADER in each
140Sstevel@tonic-gate  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
150Sstevel@tonic-gate  * If applicable, add the following below this CDDL HEADER, with the
160Sstevel@tonic-gate  * fields enclosed by brackets "[]" replaced with your own identifying
170Sstevel@tonic-gate  * information: Portions Copyright [yyyy] [name of copyright owner]
180Sstevel@tonic-gate  *
190Sstevel@tonic-gate  * CDDL HEADER END
200Sstevel@tonic-gate  */
210Sstevel@tonic-gate /*
22*4662Sfrankho  * Copyright 2007 Sun Microsystems, Inc.  All rights reserved.
230Sstevel@tonic-gate  * Use is subject to license terms.
240Sstevel@tonic-gate  */
250Sstevel@tonic-gate 
260Sstevel@tonic-gate #pragma ident	"%Z%%M%	%I%	%E% SMI"
270Sstevel@tonic-gate 
280Sstevel@tonic-gate #include <sys/t_lock.h>
290Sstevel@tonic-gate #include <sys/param.h>
300Sstevel@tonic-gate #include <sys/systm.h>
310Sstevel@tonic-gate #include <sys/signal.h>
320Sstevel@tonic-gate #include <sys/cred.h>
330Sstevel@tonic-gate #include <sys/proc.h>
340Sstevel@tonic-gate #include <sys/disp.h>
350Sstevel@tonic-gate #include <sys/user.h>
360Sstevel@tonic-gate #include <sys/vfs.h>
370Sstevel@tonic-gate #include <sys/vnode.h>
380Sstevel@tonic-gate #include <sys/stat.h>
390Sstevel@tonic-gate #include <sys/mode.h>
400Sstevel@tonic-gate #include <sys/buf.h>
410Sstevel@tonic-gate #include <sys/uio.h>
420Sstevel@tonic-gate #include <sys/dnlc.h>
430Sstevel@tonic-gate #include <sys/pathname.h>
440Sstevel@tonic-gate #include <sys/fs/ufs_inode.h>
450Sstevel@tonic-gate #include <sys/fs/ufs_fs.h>
460Sstevel@tonic-gate #include <sys/mount.h>
470Sstevel@tonic-gate #include <sys/fs/ufs_fsdir.h>
480Sstevel@tonic-gate #include <sys/fs/ufs_trans.h>
490Sstevel@tonic-gate #include <sys/fs/ufs_panic.h>
500Sstevel@tonic-gate #include <sys/fs/ufs_quota.h>
510Sstevel@tonic-gate #include <sys/errno.h>
520Sstevel@tonic-gate #include <sys/debug.h>
530Sstevel@tonic-gate #include <vm/seg.h>
540Sstevel@tonic-gate #include <sys/sysmacros.h>
550Sstevel@tonic-gate #include <sys/cmn_err.h>
560Sstevel@tonic-gate #include <sys/cpuvar.h>
570Sstevel@tonic-gate #include <sys/unistd.h>
580Sstevel@tonic-gate 
590Sstevel@tonic-gate int
ufs_xattr_getattrdir(vnode_t * dvp,struct inode ** sip,int flags,struct cred * cr)600Sstevel@tonic-gate ufs_xattr_getattrdir(
610Sstevel@tonic-gate 	vnode_t *dvp,
620Sstevel@tonic-gate 	struct inode **sip,
630Sstevel@tonic-gate 	int flags,
640Sstevel@tonic-gate 	struct cred *cr)
650Sstevel@tonic-gate {
660Sstevel@tonic-gate 	struct vfs	*vfsp;
670Sstevel@tonic-gate 	struct inode	*ip, *sdp;
680Sstevel@tonic-gate 	int		error;
690Sstevel@tonic-gate 
700Sstevel@tonic-gate 	ip = VTOI(dvp);
710Sstevel@tonic-gate 	if (flags & LOOKUP_XATTR) {
720Sstevel@tonic-gate 		if (ip && ((ip->i_oeftflag) != 0)) {
730Sstevel@tonic-gate 			vfsp = dvp->v_vfsp;
740Sstevel@tonic-gate 
750Sstevel@tonic-gate 			error = ufs_iget(vfsp, ip->i_oeftflag, sip, cr);
760Sstevel@tonic-gate 			if (error)
770Sstevel@tonic-gate 				return (error);
780Sstevel@tonic-gate 
790Sstevel@tonic-gate 			sdp = *sip;
800Sstevel@tonic-gate 
810Sstevel@tonic-gate 			/*
820Sstevel@tonic-gate 			 * Make sure it really is an ATTRDIR
830Sstevel@tonic-gate 			 */
840Sstevel@tonic-gate 			if ((sdp->i_mode & IFMT) != IFATTRDIR) {
850Sstevel@tonic-gate 				cmn_err(CE_NOTE, "ufs_getattrdir: inode %d"
86*4662Sfrankho 				    " points to attribute directory %d "
87*4662Sfrankho 				    "which is not an attribute directory;"
88*4662Sfrankho 				    "run fsck on file system",
89*4662Sfrankho 				    (int)ip->i_number, (int)sdp->i_number);
900Sstevel@tonic-gate 				VN_RELE(ITOV(sdp));
910Sstevel@tonic-gate 				return (ENOENT);
920Sstevel@tonic-gate 			}
930Sstevel@tonic-gate 			ITOV(sdp)->v_type = VDIR;
940Sstevel@tonic-gate 			ITOV(sdp)->v_flag |= V_XATTRDIR;
950Sstevel@tonic-gate 			error = 0;
960Sstevel@tonic-gate 			goto out;
970Sstevel@tonic-gate 		} else if (flags & CREATE_XATTR_DIR) {
980Sstevel@tonic-gate 			error = ufs_xattrmkdir(ip, sip, 1, cr);
990Sstevel@tonic-gate 		} else {
1000Sstevel@tonic-gate 			error = ENOENT;
1010Sstevel@tonic-gate 				goto out;
1020Sstevel@tonic-gate 		}
1030Sstevel@tonic-gate 
1040Sstevel@tonic-gate 	} else if (flags & CREATE_XATTR_DIR) {
1050Sstevel@tonic-gate 		error = ufs_xattrmkdir(ip, sip, 1, cr);
1060Sstevel@tonic-gate 	} else {
1070Sstevel@tonic-gate 		error = ENOENT;
1080Sstevel@tonic-gate 	}
1090Sstevel@tonic-gate out:
1100Sstevel@tonic-gate 	return (error);
1110Sstevel@tonic-gate }
1120Sstevel@tonic-gate 
1130Sstevel@tonic-gate 
1140Sstevel@tonic-gate /*
1150Sstevel@tonic-gate  * Unhook an attribute directory from a parent file/dir
1160Sstevel@tonic-gate  * Only do so, if we are the only user of the vnode.
1170Sstevel@tonic-gate  */
1180Sstevel@tonic-gate void
ufs_unhook_shadow(struct inode * ip,struct inode * sip)1190Sstevel@tonic-gate ufs_unhook_shadow(struct inode *ip, struct inode *sip)
1200Sstevel@tonic-gate {
1210Sstevel@tonic-gate 	struct vnode		*datavp = ITOV(ip);
1220Sstevel@tonic-gate 	struct vnode		*dirvp = ITOV(sip);
1230Sstevel@tonic-gate 	int			hno;
1240Sstevel@tonic-gate 	kmutex_t		*ihm;
1250Sstevel@tonic-gate 
1260Sstevel@tonic-gate 	ASSERT(RW_WRITE_HELD(&sip->i_contents));
1270Sstevel@tonic-gate 	ASSERT(RW_WRITE_HELD(&ip->i_contents));
1280Sstevel@tonic-gate 
1290Sstevel@tonic-gate 	if (vn_is_readonly(ITOV(ip)))
1300Sstevel@tonic-gate 		return;
1310Sstevel@tonic-gate 
1320Sstevel@tonic-gate 	if (ip->i_ufsvfs == NULL || sip->i_ufsvfs == NULL)
1330Sstevel@tonic-gate 		return;
1340Sstevel@tonic-gate 
1350Sstevel@tonic-gate 	hno = INOHASH(ip->i_number);
1360Sstevel@tonic-gate 	ihm = &ih_lock[hno];
1370Sstevel@tonic-gate 	mutex_enter(ihm);
1380Sstevel@tonic-gate 
1390Sstevel@tonic-gate 	mutex_enter(&datavp->v_lock);
1400Sstevel@tonic-gate 	mutex_enter(&dirvp->v_lock);
1410Sstevel@tonic-gate 
1420Sstevel@tonic-gate 	if (dirvp->v_count != 1 && datavp->v_count != 1) {
1430Sstevel@tonic-gate 		mutex_exit(&dirvp->v_lock);
1440Sstevel@tonic-gate 		mutex_exit(&datavp->v_lock);
1450Sstevel@tonic-gate 		mutex_exit(ihm);
1460Sstevel@tonic-gate 		return;
1470Sstevel@tonic-gate 	}
1480Sstevel@tonic-gate 
1490Sstevel@tonic-gate 	/*
1500Sstevel@tonic-gate 	 * Delete shadow from ip
1510Sstevel@tonic-gate 	 */
1520Sstevel@tonic-gate 
1530Sstevel@tonic-gate 	sip->i_nlink -= 2;
1540Sstevel@tonic-gate 	ufs_setreclaim(sip);
1550Sstevel@tonic-gate 	TRANS_INODE(sip->i_ufsvfs, sip);
1560Sstevel@tonic-gate 	sip->i_flag |= ICHG;
1570Sstevel@tonic-gate 	sip->i_seq++;
1580Sstevel@tonic-gate 	ITIMES_NOLOCK(sip);
1590Sstevel@tonic-gate 
1600Sstevel@tonic-gate 	/*
1610Sstevel@tonic-gate 	 * Update src file
1620Sstevel@tonic-gate 	 */
1630Sstevel@tonic-gate 	ip->i_oeftflag = 0;
1640Sstevel@tonic-gate 	TRANS_INODE(ip->i_ufsvfs, ip);
1650Sstevel@tonic-gate 	ip->i_flag |= ICHG;
1660Sstevel@tonic-gate 	ip->i_seq++;
1670Sstevel@tonic-gate 	ufs_iupdat(ip, 1);
1680Sstevel@tonic-gate 	mutex_exit(&dirvp->v_lock);
1690Sstevel@tonic-gate 	mutex_exit(&datavp->v_lock);
1700Sstevel@tonic-gate 	mutex_exit(ihm);
1710Sstevel@tonic-gate }
172