usr/src/uts/common/fs/zfs/zfs_znode.c
changeset 3461 c19b22f347d6
parent 3444 dc160a70a50d
child 3897 278bade789ba
equal deleted inserted replaced
3460:e7801868c7bc 3461:c19b22f347d6
   243 zfs_init_fs(zfsvfs_t *zfsvfs, znode_t **zpp, cred_t *cr)
   243 zfs_init_fs(zfsvfs_t *zfsvfs, znode_t **zpp, cred_t *cr)
   244 {
   244 {
   245 	extern int zfsfstype;
   245 	extern int zfsfstype;
   246 
   246 
   247 	objset_t	*os = zfsvfs->z_os;
   247 	objset_t	*os = zfsvfs->z_os;
   248 	uint64_t	zoid;
       
   249 	uint64_t	version = ZPL_VERSION;
   248 	uint64_t	version = ZPL_VERSION;
   250 	int		i, error;
   249 	int		i, error;
   251 	dmu_object_info_t doi;
   250 	dmu_object_info_t doi;
   252 	uint64_t fsid_guid;
   251 	uint64_t fsid_guid;
   253 
   252 
   293 	ASSERT((fsid_guid & ~((1ULL<<56)-1)) == 0);
   292 	ASSERT((fsid_guid & ~((1ULL<<56)-1)) == 0);
   294 	zfsvfs->z_vfs->vfs_fsid.val[0] = fsid_guid;
   293 	zfsvfs->z_vfs->vfs_fsid.val[0] = fsid_guid;
   295 	zfsvfs->z_vfs->vfs_fsid.val[1] = ((fsid_guid>>32) << 8) |
   294 	zfsvfs->z_vfs->vfs_fsid.val[1] = ((fsid_guid>>32) << 8) |
   296 	    zfsfstype & 0xFF;
   295 	    zfsfstype & 0xFF;
   297 
   296 
   298 	error = zap_lookup(os, MASTER_NODE_OBJ, ZFS_ROOT_OBJ, 8, 1, &zoid);
   297 	error = zap_lookup(os, MASTER_NODE_OBJ, ZFS_ROOT_OBJ, 8, 1,
       
   298 	    &zfsvfs->z_root);
   299 	if (error)
   299 	if (error)
   300 		return (error);
   300 		return (error);
   301 	ASSERT(zoid != 0);
   301 	ASSERT(zfsvfs->z_root != 0);
   302 	zfsvfs->z_root = zoid;
       
   303 
   302 
   304 	/*
   303 	/*
   305 	 * Create the per mount vop tables.
   304 	 * Create the per mount vop tables.
   306 	 */
   305 	 */
   307 
   306 
   309 	 * Initialize zget mutex's
   308 	 * Initialize zget mutex's
   310 	 */
   309 	 */
   311 	for (i = 0; i != ZFS_OBJ_MTX_SZ; i++)
   310 	for (i = 0; i != ZFS_OBJ_MTX_SZ; i++)
   312 		mutex_init(&zfsvfs->z_hold_mtx[i], NULL, MUTEX_DEFAULT, NULL);
   311 		mutex_init(&zfsvfs->z_hold_mtx[i], NULL, MUTEX_DEFAULT, NULL);
   313 
   312 
   314 	error = zfs_zget(zfsvfs, zoid, zpp);
   313 	error = zfs_zget(zfsvfs, zfsvfs->z_root, zpp);
   315 	if (error)
   314 	if (error)
   316 		return (error);
   315 		return (error);
   317 	ASSERT3U((*zpp)->z_id, ==, zoid);
   316 	ASSERT3U((*zpp)->z_id, ==, zfsvfs->z_root);
   318 
   317 
   319 	error = zap_lookup(os, MASTER_NODE_OBJ, ZFS_DELETE_QUEUE, 8, 1, &zoid);
   318 	error = zap_lookup(os, MASTER_NODE_OBJ, ZFS_UNLINKED_SET, 8, 1,
       
   319 	    &zfsvfs->z_unlinkedobj);
   320 	if (error)
   320 	if (error)
   321 		return (error);
   321 		return (error);
   322 
       
   323 	zfsvfs->z_dqueue = zoid;
       
   324 
       
   325 	/*
       
   326 	 * Initialize delete head structure
       
   327 	 * Thread(s) will be started/stopped via
       
   328 	 * readonly_changed_cb() depending
       
   329 	 * on whether this is rw/ro mount.
       
   330 	 */
       
   331 	list_create(&zfsvfs->z_delete_head.z_znodes,
       
   332 	    sizeof (znode_t), offsetof(znode_t, z_list_node));
       
   333 	/* Mutex never destroyed. */
       
   334 	mutex_init(&zfsvfs->z_delete_head.z_mutex, NULL, MUTEX_DEFAULT, NULL);
       
   335 
   322 
   336 	return (0);
   323 	return (0);
   337 }
   324 }
   338 
   325 
   339 /*
   326 /*
   410 
   397 
   411 	ASSERT(zp->z_dirlocks == NULL);
   398 	ASSERT(zp->z_dirlocks == NULL);
   412 
   399 
   413 	zp->z_phys = db->db_data;
   400 	zp->z_phys = db->db_data;
   414 	zp->z_zfsvfs = zfsvfs;
   401 	zp->z_zfsvfs = zfsvfs;
   415 	zp->z_reap = 0;
   402 	zp->z_unlinked = 0;
   416 	zp->z_atime_dirty = 0;
   403 	zp->z_atime_dirty = 0;
   417 	zp->z_dbuf_held = 0;
   404 	zp->z_dbuf_held = 0;
   418 	zp->z_mapcnt = 0;
   405 	zp->z_mapcnt = 0;
   419 	zp->z_last_itx = 0;
   406 	zp->z_last_itx = 0;
   420 	zp->z_dbuf = db;
   407 	zp->z_dbuf = db;
   678 
   665 
   679 	if (zp != NULL) {
   666 	if (zp != NULL) {
   680 		mutex_enter(&zp->z_lock);
   667 		mutex_enter(&zp->z_lock);
   681 
   668 
   682 		ASSERT3U(zp->z_id, ==, obj_num);
   669 		ASSERT3U(zp->z_id, ==, obj_num);
   683 		if (zp->z_reap) {
   670 		if (zp->z_unlinked) {
   684 			dmu_buf_rele(db, NULL);
   671 			dmu_buf_rele(db, NULL);
   685 			mutex_exit(&zp->z_lock);
   672 			mutex_exit(&zp->z_lock);
   686 			ZFS_OBJ_HOLD_EXIT(zfsvfs, obj_num);
   673 			ZFS_OBJ_HOLD_EXIT(zfsvfs, obj_num);
   687 			return (ENOENT);
   674 			return (ENOENT);
   688 		} else if (zp->z_dbuf_held) {
   675 		} else if (zp->z_dbuf_held) {
   768 
   755 
   769 	/*
   756 	/*
   770 	 * If this was the last reference to a file with no links,
   757 	 * If this was the last reference to a file with no links,
   771 	 * remove the file from the file system.
   758 	 * remove the file from the file system.
   772 	 */
   759 	 */
   773 	if (zp->z_reap) {
   760 	if (zp->z_unlinked) {
   774 		mutex_exit(&zp->z_lock);
   761 		mutex_exit(&zp->z_lock);
   775 		ZFS_OBJ_HOLD_EXIT(zfsvfs, z_id);
   762 		ZFS_OBJ_HOLD_EXIT(zfsvfs, z_id);
   776 		/* XATTR files are not put on the delete queue */
   763 		zfs_rmnode(zp);
   777 		if (zp->z_phys->zp_flags & ZFS_XATTR) {
       
   778 			zfs_rmnode(zp);
       
   779 		} else {
       
   780 			mutex_enter(&zfsvfs->z_delete_head.z_mutex);
       
   781 			list_insert_tail(&zfsvfs->z_delete_head.z_znodes, zp);
       
   782 			zfsvfs->z_delete_head.z_znode_count++;
       
   783 			cv_broadcast(&zfsvfs->z_delete_head.z_cv);
       
   784 			mutex_exit(&zfsvfs->z_delete_head.z_mutex);
       
   785 		}
       
   786 		VFS_RELE(zfsvfs->z_vfs);
   764 		VFS_RELE(zfsvfs->z_vfs);
   787 		return;
   765 		return;
   788 	}
   766 	}
   789 	ASSERT(zp->z_phys);
   767 	ASSERT(zp->z_phys);
   790 	ASSERT(zp->z_dbuf_held);
   768 	ASSERT(zp->z_dbuf_held);
  1091 	ASSERT(error == 0);
  1069 	ASSERT(error == 0);
  1092 
  1070 
  1093 	/*
  1071 	/*
  1094 	 * Create a delete queue.
  1072 	 * Create a delete queue.
  1095 	 */
  1073 	 */
  1096 	doid = zap_create(os, DMU_OT_DELETE_QUEUE, DMU_OT_NONE, 0, tx);
  1074 	doid = zap_create(os, DMU_OT_UNLINKED_SET, DMU_OT_NONE, 0, tx);
  1097 
  1075 
  1098 	error = zap_add(os, moid, ZFS_DELETE_QUEUE, 8, 1, &doid, tx);
  1076 	error = zap_add(os, moid, ZFS_UNLINKED_SET, 8, 1, &doid, tx);
  1099 	ASSERT(error == 0);
  1077 	ASSERT(error == 0);
  1100 
  1078 
  1101 	/*
  1079 	/*
  1102 	 * Create root znode.  Create minimal znode/vnode/zfsvfs
  1080 	 * Create root znode.  Create minimal znode/vnode/zfsvfs
  1103 	 * to allow zfs_mknode to work.
  1081 	 * to allow zfs_mknode to work.
  1108 	vattr.va_uid = 0;
  1086 	vattr.va_uid = 0;
  1109 	vattr.va_gid = 3;
  1087 	vattr.va_gid = 3;
  1110 
  1088 
  1111 	rootzp = kmem_cache_alloc(znode_cache, KM_SLEEP);
  1089 	rootzp = kmem_cache_alloc(znode_cache, KM_SLEEP);
  1112 	rootzp->z_zfsvfs = &zfsvfs;
  1090 	rootzp->z_zfsvfs = &zfsvfs;
  1113 	rootzp->z_reap = 0;
  1091 	rootzp->z_unlinked = 0;
  1114 	rootzp->z_atime_dirty = 0;
  1092 	rootzp->z_atime_dirty = 0;
  1115 	rootzp->z_dbuf_held = 0;
  1093 	rootzp->z_dbuf_held = 0;
  1116 
  1094 
  1117 	vp = ZTOV(rootzp);
  1095 	vp = ZTOV(rootzp);
  1118 	vn_reinit(vp);
  1096 	vn_reinit(vp);