Print this page
7203 unlinking a directory on tmpfs does not remove the directory entries
Reviewed by: Robert Mustacchi <rm@joyent.com>
Reviewed by: Alexander Stetsenko <astetsenko@racktopsystems.com>


  10  * See the License for the specific language governing permissions
  11  * and limitations under the License.
  12  *
  13  * When distributing Covered Code, include this CDDL HEADER in each
  14  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
  15  * If applicable, add the following below this CDDL HEADER, with the
  16  * fields enclosed by brackets "[]" replaced with your own identifying
  17  * information: Portions Copyright [yyyy] [name of copyright owner]
  18  *
  19  * CDDL HEADER END
  20  */
  21 
  22 /*
  23  * Copyright 2009 Sun Microsystems, Inc.  All rights reserved.
  24  * Use is subject to license terms.
  25  */
  26 
  27 /*
  28  * Copyright (c) 2015, Joyent, Inc. All rights reserved.
  29  * Copyright 2015 Nexenta Systems, Inc.  All rights reserved.

  30  */
  31 
  32 #include <sys/types.h>
  33 #include <sys/param.h>
  34 #include <sys/t_lock.h>
  35 #include <sys/systm.h>
  36 #include <sys/sysmacros.h>
  37 #include <sys/user.h>
  38 #include <sys/time.h>
  39 #include <sys/vfs.h>
  40 #include <sys/vfs_opreg.h>
  41 #include <sys/vnode.h>
  42 #include <sys/file.h>
  43 #include <sys/fcntl.h>
  44 #include <sys/flock.h>
  45 #include <sys/kmem.h>
  46 #include <sys/uio.h>
  47 #include <sys/errno.h>
  48 #include <sys/stat.h>
  49 #include <sys/cred.h>


1087         struct vnode *dvp,
1088         char *nm,
1089         struct cred *cred,
1090         caller_context_t *ct,
1091         int flags)
1092 {
1093         struct tmpnode *parent = (struct tmpnode *)VTOTN(dvp);
1094         int error;
1095         struct tmpnode *tp = NULL;
1096 
1097         error = tdirlookup(parent, nm, &tp, cred);
1098         if (error)
1099                 return (error);
1100 
1101         ASSERT(tp);
1102         rw_enter(&parent->tn_rwlock, RW_WRITER);
1103         rw_enter(&tp->tn_rwlock, RW_WRITER);
1104 
1105         if (tp->tn_type != VDIR ||
1106             (error = secpolicy_fs_linkdir(cred, dvp->v_vfsp)) == 0)
1107                 error = tdirdelete(parent, tp, nm, DR_REMOVE, cred);

1108 
1109         rw_exit(&tp->tn_rwlock);
1110         rw_exit(&parent->tn_rwlock);
1111         vnevent_remove(TNTOV(tp), dvp, nm, ct);
1112         tmpnode_rele(tp);
1113 
1114         TRACE_3(TR_FAC_TMPFS, TR_TMPFS_REMOVE,
1115             "tmpfs remove:dvp %p nm %s error %d", dvp, nm, error);
1116         return (error);
1117 }
1118 
1119 /* ARGSUSED4 */
1120 static int
1121 tmp_link(
1122         struct vnode *dvp,
1123         struct vnode *srcvp,
1124         char *tnm,
1125         struct cred *cred,
1126         caller_context_t *ct,
1127         int flags)




  10  * See the License for the specific language governing permissions
  11  * and limitations under the License.
  12  *
  13  * When distributing Covered Code, include this CDDL HEADER in each
  14  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
  15  * If applicable, add the following below this CDDL HEADER, with the
  16  * fields enclosed by brackets "[]" replaced with your own identifying
  17  * information: Portions Copyright [yyyy] [name of copyright owner]
  18  *
  19  * CDDL HEADER END
  20  */
  21 
  22 /*
  23  * Copyright 2009 Sun Microsystems, Inc.  All rights reserved.
  24  * Use is subject to license terms.
  25  */
  26 
  27 /*
  28  * Copyright (c) 2015, Joyent, Inc. All rights reserved.
  29  * Copyright 2015 Nexenta Systems, Inc.  All rights reserved.
  30  * Copyright 2016 RackTop Systems.
  31  */
  32 
  33 #include <sys/types.h>
  34 #include <sys/param.h>
  35 #include <sys/t_lock.h>
  36 #include <sys/systm.h>
  37 #include <sys/sysmacros.h>
  38 #include <sys/user.h>
  39 #include <sys/time.h>
  40 #include <sys/vfs.h>
  41 #include <sys/vfs_opreg.h>
  42 #include <sys/vnode.h>
  43 #include <sys/file.h>
  44 #include <sys/fcntl.h>
  45 #include <sys/flock.h>
  46 #include <sys/kmem.h>
  47 #include <sys/uio.h>
  48 #include <sys/errno.h>
  49 #include <sys/stat.h>
  50 #include <sys/cred.h>


1088         struct vnode *dvp,
1089         char *nm,
1090         struct cred *cred,
1091         caller_context_t *ct,
1092         int flags)
1093 {
1094         struct tmpnode *parent = (struct tmpnode *)VTOTN(dvp);
1095         int error;
1096         struct tmpnode *tp = NULL;
1097 
1098         error = tdirlookup(parent, nm, &tp, cred);
1099         if (error)
1100                 return (error);
1101 
1102         ASSERT(tp);
1103         rw_enter(&parent->tn_rwlock, RW_WRITER);
1104         rw_enter(&tp->tn_rwlock, RW_WRITER);
1105 
1106         if (tp->tn_type != VDIR ||
1107             (error = secpolicy_fs_linkdir(cred, dvp->v_vfsp)) == 0)
1108                 error = tdirdelete(parent, tp, nm, tp->tn_type == VDIR ?
1109                     DR_RMDIR : DR_REMOVE, cred);
1110 
1111         rw_exit(&tp->tn_rwlock);
1112         rw_exit(&parent->tn_rwlock);
1113         vnevent_remove(TNTOV(tp), dvp, nm, ct);
1114         tmpnode_rele(tp);
1115 
1116         TRACE_3(TR_FAC_TMPFS, TR_TMPFS_REMOVE,
1117             "tmpfs remove:dvp %p nm %s error %d", dvp, nm, error);
1118         return (error);
1119 }
1120 
1121 /* ARGSUSED4 */
1122 static int
1123 tmp_link(
1124         struct vnode *dvp,
1125         struct vnode *srcvp,
1126         char *tnm,
1127         struct cred *cred,
1128         caller_context_t *ct,
1129         int flags)