17c478bd9Sstevel@tonic-gate /*
27c478bd9Sstevel@tonic-gate * CDDL HEADER START
37c478bd9Sstevel@tonic-gate *
47c478bd9Sstevel@tonic-gate * The contents of this file are subject to the terms of the
5*80d34432Sfrankho * Common Development and Distribution License (the "License").
6*80d34432Sfrankho * You may not use this file except in compliance with the License.
77c478bd9Sstevel@tonic-gate *
87c478bd9Sstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
97c478bd9Sstevel@tonic-gate * or http://www.opensolaris.org/os/licensing.
107c478bd9Sstevel@tonic-gate * See the License for the specific language governing permissions
117c478bd9Sstevel@tonic-gate * and limitations under the License.
127c478bd9Sstevel@tonic-gate *
137c478bd9Sstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each
147c478bd9Sstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
157c478bd9Sstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the
167c478bd9Sstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying
177c478bd9Sstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner]
187c478bd9Sstevel@tonic-gate *
197c478bd9Sstevel@tonic-gate * CDDL HEADER END
207c478bd9Sstevel@tonic-gate */
217c478bd9Sstevel@tonic-gate /*
22*80d34432Sfrankho * Copyright 2007 Sun Microsystems, Inc. All rights reserved.
237c478bd9Sstevel@tonic-gate * Use is subject to license terms.
247c478bd9Sstevel@tonic-gate */
257c478bd9Sstevel@tonic-gate
267c478bd9Sstevel@tonic-gate #pragma ident "%Z%%M% %I% %E% SMI"
277c478bd9Sstevel@tonic-gate
287c478bd9Sstevel@tonic-gate #include <sys/t_lock.h>
297c478bd9Sstevel@tonic-gate #include <sys/param.h>
307c478bd9Sstevel@tonic-gate #include <sys/systm.h>
317c478bd9Sstevel@tonic-gate #include <sys/signal.h>
327c478bd9Sstevel@tonic-gate #include <sys/cred.h>
337c478bd9Sstevel@tonic-gate #include <sys/proc.h>
347c478bd9Sstevel@tonic-gate #include <sys/disp.h>
357c478bd9Sstevel@tonic-gate #include <sys/user.h>
367c478bd9Sstevel@tonic-gate #include <sys/vfs.h>
377c478bd9Sstevel@tonic-gate #include <sys/vnode.h>
387c478bd9Sstevel@tonic-gate #include <sys/stat.h>
397c478bd9Sstevel@tonic-gate #include <sys/mode.h>
407c478bd9Sstevel@tonic-gate #include <sys/buf.h>
417c478bd9Sstevel@tonic-gate #include <sys/uio.h>
427c478bd9Sstevel@tonic-gate #include <sys/dnlc.h>
437c478bd9Sstevel@tonic-gate #include <sys/pathname.h>
447c478bd9Sstevel@tonic-gate #include <sys/fs/ufs_inode.h>
457c478bd9Sstevel@tonic-gate #include <sys/fs/ufs_fs.h>
467c478bd9Sstevel@tonic-gate #include <sys/mount.h>
477c478bd9Sstevel@tonic-gate #include <sys/fs/ufs_fsdir.h>
487c478bd9Sstevel@tonic-gate #include <sys/fs/ufs_trans.h>
497c478bd9Sstevel@tonic-gate #include <sys/fs/ufs_panic.h>
507c478bd9Sstevel@tonic-gate #include <sys/fs/ufs_quota.h>
517c478bd9Sstevel@tonic-gate #include <sys/errno.h>
527c478bd9Sstevel@tonic-gate #include <sys/debug.h>
537c478bd9Sstevel@tonic-gate #include <vm/seg.h>
547c478bd9Sstevel@tonic-gate #include <sys/sysmacros.h>
557c478bd9Sstevel@tonic-gate #include <sys/cmn_err.h>
567c478bd9Sstevel@tonic-gate #include <sys/cpuvar.h>
577c478bd9Sstevel@tonic-gate #include <sys/unistd.h>
587c478bd9Sstevel@tonic-gate
597c478bd9Sstevel@tonic-gate int
ufs_xattr_getattrdir(vnode_t * dvp,struct inode ** sip,int flags,struct cred * cr)607c478bd9Sstevel@tonic-gate ufs_xattr_getattrdir(
617c478bd9Sstevel@tonic-gate vnode_t *dvp,
627c478bd9Sstevel@tonic-gate struct inode **sip,
637c478bd9Sstevel@tonic-gate int flags,
647c478bd9Sstevel@tonic-gate struct cred *cr)
657c478bd9Sstevel@tonic-gate {
667c478bd9Sstevel@tonic-gate struct vfs *vfsp;
677c478bd9Sstevel@tonic-gate struct inode *ip, *sdp;
687c478bd9Sstevel@tonic-gate int error;
697c478bd9Sstevel@tonic-gate
707c478bd9Sstevel@tonic-gate ip = VTOI(dvp);
717c478bd9Sstevel@tonic-gate if (flags & LOOKUP_XATTR) {
727c478bd9Sstevel@tonic-gate if (ip && ((ip->i_oeftflag) != 0)) {
737c478bd9Sstevel@tonic-gate vfsp = dvp->v_vfsp;
747c478bd9Sstevel@tonic-gate
757c478bd9Sstevel@tonic-gate error = ufs_iget(vfsp, ip->i_oeftflag, sip, cr);
767c478bd9Sstevel@tonic-gate if (error)
777c478bd9Sstevel@tonic-gate return (error);
787c478bd9Sstevel@tonic-gate
797c478bd9Sstevel@tonic-gate sdp = *sip;
807c478bd9Sstevel@tonic-gate
817c478bd9Sstevel@tonic-gate /*
827c478bd9Sstevel@tonic-gate * Make sure it really is an ATTRDIR
837c478bd9Sstevel@tonic-gate */
847c478bd9Sstevel@tonic-gate if ((sdp->i_mode & IFMT) != IFATTRDIR) {
857c478bd9Sstevel@tonic-gate cmn_err(CE_NOTE, "ufs_getattrdir: inode %d"
867c478bd9Sstevel@tonic-gate " points to attribute directory %d "
877c478bd9Sstevel@tonic-gate "which is not an attribute directory;"
887c478bd9Sstevel@tonic-gate "run fsck on file system",
897c478bd9Sstevel@tonic-gate (int)ip->i_number, (int)sdp->i_number);
907c478bd9Sstevel@tonic-gate VN_RELE(ITOV(sdp));
917c478bd9Sstevel@tonic-gate return (ENOENT);
927c478bd9Sstevel@tonic-gate }
937c478bd9Sstevel@tonic-gate ITOV(sdp)->v_type = VDIR;
947c478bd9Sstevel@tonic-gate ITOV(sdp)->v_flag |= V_XATTRDIR;
957c478bd9Sstevel@tonic-gate error = 0;
967c478bd9Sstevel@tonic-gate goto out;
977c478bd9Sstevel@tonic-gate } else if (flags & CREATE_XATTR_DIR) {
987c478bd9Sstevel@tonic-gate error = ufs_xattrmkdir(ip, sip, 1, cr);
997c478bd9Sstevel@tonic-gate } else {
1007c478bd9Sstevel@tonic-gate error = ENOENT;
1017c478bd9Sstevel@tonic-gate goto out;
1027c478bd9Sstevel@tonic-gate }
1037c478bd9Sstevel@tonic-gate
1047c478bd9Sstevel@tonic-gate } else if (flags & CREATE_XATTR_DIR) {
1057c478bd9Sstevel@tonic-gate error = ufs_xattrmkdir(ip, sip, 1, cr);
1067c478bd9Sstevel@tonic-gate } else {
1077c478bd9Sstevel@tonic-gate error = ENOENT;
1087c478bd9Sstevel@tonic-gate }
1097c478bd9Sstevel@tonic-gate out:
1107c478bd9Sstevel@tonic-gate return (error);
1117c478bd9Sstevel@tonic-gate }
1127c478bd9Sstevel@tonic-gate
1137c478bd9Sstevel@tonic-gate
1147c478bd9Sstevel@tonic-gate /*
1157c478bd9Sstevel@tonic-gate * Unhook an attribute directory from a parent file/dir
1167c478bd9Sstevel@tonic-gate * Only do so, if we are the only user of the vnode.
1177c478bd9Sstevel@tonic-gate */
1187c478bd9Sstevel@tonic-gate void
ufs_unhook_shadow(struct inode * ip,struct inode * sip)1197c478bd9Sstevel@tonic-gate ufs_unhook_shadow(struct inode *ip, struct inode *sip)
1207c478bd9Sstevel@tonic-gate {
1217c478bd9Sstevel@tonic-gate struct vnode *datavp = ITOV(ip);
1227c478bd9Sstevel@tonic-gate struct vnode *dirvp = ITOV(sip);
1237c478bd9Sstevel@tonic-gate int hno;
1247c478bd9Sstevel@tonic-gate kmutex_t *ihm;
1257c478bd9Sstevel@tonic-gate
1267c478bd9Sstevel@tonic-gate ASSERT(RW_WRITE_HELD(&sip->i_contents));
1277c478bd9Sstevel@tonic-gate ASSERT(RW_WRITE_HELD(&ip->i_contents));
1287c478bd9Sstevel@tonic-gate
1297c478bd9Sstevel@tonic-gate if (vn_is_readonly(ITOV(ip)))
1307c478bd9Sstevel@tonic-gate return;
1317c478bd9Sstevel@tonic-gate
1327c478bd9Sstevel@tonic-gate if (ip->i_ufsvfs == NULL || sip->i_ufsvfs == NULL)
1337c478bd9Sstevel@tonic-gate return;
1347c478bd9Sstevel@tonic-gate
1357c478bd9Sstevel@tonic-gate hno = INOHASH(ip->i_number);
1367c478bd9Sstevel@tonic-gate ihm = &ih_lock[hno];
1377c478bd9Sstevel@tonic-gate mutex_enter(ihm);
1387c478bd9Sstevel@tonic-gate
1397c478bd9Sstevel@tonic-gate mutex_enter(&datavp->v_lock);
1407c478bd9Sstevel@tonic-gate mutex_enter(&dirvp->v_lock);
1417c478bd9Sstevel@tonic-gate
1427c478bd9Sstevel@tonic-gate if (dirvp->v_count != 1 && datavp->v_count != 1) {
1437c478bd9Sstevel@tonic-gate mutex_exit(&dirvp->v_lock);
1447c478bd9Sstevel@tonic-gate mutex_exit(&datavp->v_lock);
1457c478bd9Sstevel@tonic-gate mutex_exit(ihm);
1467c478bd9Sstevel@tonic-gate return;
1477c478bd9Sstevel@tonic-gate }
1487c478bd9Sstevel@tonic-gate
1497c478bd9Sstevel@tonic-gate /*
1507c478bd9Sstevel@tonic-gate * Delete shadow from ip
1517c478bd9Sstevel@tonic-gate */
1527c478bd9Sstevel@tonic-gate
1537c478bd9Sstevel@tonic-gate sip->i_nlink -= 2;
1547c478bd9Sstevel@tonic-gate ufs_setreclaim(sip);
1557c478bd9Sstevel@tonic-gate TRANS_INODE(sip->i_ufsvfs, sip);
1567c478bd9Sstevel@tonic-gate sip->i_flag |= ICHG;
1577c478bd9Sstevel@tonic-gate sip->i_seq++;
1587c478bd9Sstevel@tonic-gate ITIMES_NOLOCK(sip);
1597c478bd9Sstevel@tonic-gate
1607c478bd9Sstevel@tonic-gate /*
1617c478bd9Sstevel@tonic-gate * Update src file
1627c478bd9Sstevel@tonic-gate */
1637c478bd9Sstevel@tonic-gate ip->i_oeftflag = 0;
1647c478bd9Sstevel@tonic-gate TRANS_INODE(ip->i_ufsvfs, ip);
1657c478bd9Sstevel@tonic-gate ip->i_flag |= ICHG;
1667c478bd9Sstevel@tonic-gate ip->i_seq++;
1677c478bd9Sstevel@tonic-gate ufs_iupdat(ip, 1);
1687c478bd9Sstevel@tonic-gate mutex_exit(&dirvp->v_lock);
1697c478bd9Sstevel@tonic-gate mutex_exit(&datavp->v_lock);
1707c478bd9Sstevel@tonic-gate mutex_exit(ihm);
1717c478bd9Sstevel@tonic-gate }
172