usr/src/uts/common/fs/zfs/zfs_znode.c
author ck153898
Mon, 29 Oct 2007 22:45:33 -0700
changeset 5378 111aa1baa84a
parent 5331 3047ad28a67b
child 5446 51fbc14b301d
permissions -rw-r--r--
PSARC 2007/555 zfs fs-only quotas and reservations 6431277 want filesystem-only quotas 6483677 need immediate reservation
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
     1
/*
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
     2
 * CDDL HEADER START
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
     3
 *
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
     4
 * The contents of this file are subject to the terms of the
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1394
diff changeset
     5
 * Common Development and Distribution License (the "License").
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1394
diff changeset
     6
 * You may not use this file except in compliance with the License.
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
     7
 *
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
     8
 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
     9
 * or http://www.opensolaris.org/os/licensing.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    10
 * See the License for the specific language governing permissions
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    11
 * and limitations under the License.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    12
 *
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    13
 * When distributing Covered Code, include this CDDL HEADER in each
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    14
 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    15
 * If applicable, add the following below this CDDL HEADER, with the
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    16
 * fields enclosed by brackets "[]" replaced with your own identifying
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    17
 * information: Portions Copyright [yyyy] [name of copyright owner]
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    18
 *
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    19
 * CDDL HEADER END
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    20
 */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    21
/*
3444
dc160a70a50d 6410433 'zpool status -v' would be more useful with filenames
ek110237
parents: 3063
diff changeset
    22
 * Copyright 2007 Sun Microsystems, Inc.  All rights reserved.
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    23
 * Use is subject to license terms.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    24
 */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    25
4144
068f395736ad 6465105 ZFS does not update timestamps upon the creat() of an existing file
peteh
parents: 4105
diff changeset
    26
/* Portions Copyright 2007 Jeremy Teo */
068f395736ad 6465105 ZFS does not update timestamps upon the creat() of an existing file
peteh
parents: 4105
diff changeset
    27
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    28
#pragma ident	"%Z%%M%	%I%	%E% SMI"
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    29
3444
dc160a70a50d 6410433 'zpool status -v' would be more useful with filenames
ek110237
parents: 3063
diff changeset
    30
#ifdef _KERNEL
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    31
#include <sys/types.h>
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    32
#include <sys/param.h>
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    33
#include <sys/time.h>
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    34
#include <sys/systm.h>
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    35
#include <sys/sysmacros.h>
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    36
#include <sys/resource.h>
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    37
#include <sys/mntent.h>
1816
8c14b56c8515 6408482 64-bit system can't read some 32-bit dev_ts created on zfs
marks
parents: 1760
diff changeset
    38
#include <sys/mkdev.h>
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    39
#include <sys/vfs.h>
3898
c788126f2a20 PSARC/2007/124 Strong Type-Checking for VFS Operation Registration Mechanism
rsb
parents: 3897
diff changeset
    40
#include <sys/vfs_opreg.h>
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    41
#include <sys/vnode.h>
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    42
#include <sys/file.h>
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    43
#include <sys/kmem.h>
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    44
#include <sys/errno.h>
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    45
#include <sys/unistd.h>
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    46
#include <sys/mode.h>
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    47
#include <sys/atomic.h>
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    48
#include <vm/pvn.h>
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    49
#include "fs/fs_subr.h"
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    50
#include <sys/zfs_dir.h>
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    51
#include <sys/zfs_acl.h>
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    52
#include <sys/zfs_ioctl.h>
1669
3521dbbcb2e8 6343608 ZFS file range locking
perrin
parents: 1544
diff changeset
    53
#include <sys/zfs_rlock.h>
5331
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5326
diff changeset
    54
#include <sys/zfs_fuid.h>
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5326
diff changeset
    55
#include <sys/zfs_i18n.h>
3444
dc160a70a50d 6410433 'zpool status -v' would be more useful with filenames
ek110237
parents: 3063
diff changeset
    56
#include <sys/fs/zfs.h>
5331
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5326
diff changeset
    57
#include <sys/kidmap.h>
3444
dc160a70a50d 6410433 'zpool status -v' would be more useful with filenames
ek110237
parents: 3063
diff changeset
    58
#endif /* _KERNEL */
dc160a70a50d 6410433 'zpool status -v' would be more useful with filenames
ek110237
parents: 3063
diff changeset
    59
dc160a70a50d 6410433 'zpool status -v' would be more useful with filenames
ek110237
parents: 3063
diff changeset
    60
#include <sys/dmu.h>
dc160a70a50d 6410433 'zpool status -v' would be more useful with filenames
ek110237
parents: 3063
diff changeset
    61
#include <sys/refcount.h>
dc160a70a50d 6410433 'zpool status -v' would be more useful with filenames
ek110237
parents: 3063
diff changeset
    62
#include <sys/stat.h>
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    63
#include <sys/zap.h>
3444
dc160a70a50d 6410433 'zpool status -v' would be more useful with filenames
ek110237
parents: 3063
diff changeset
    64
#include <sys/zfs_znode.h>
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    65
3444
dc160a70a50d 6410433 'zpool status -v' would be more useful with filenames
ek110237
parents: 3063
diff changeset
    66
/*
dc160a70a50d 6410433 'zpool status -v' would be more useful with filenames
ek110237
parents: 3063
diff changeset
    67
 * Functions needed for userland (ie: libzpool) are not put under
dc160a70a50d 6410433 'zpool status -v' would be more useful with filenames
ek110237
parents: 3063
diff changeset
    68
 * #ifdef_KERNEL; the rest of the functions have dependencies
dc160a70a50d 6410433 'zpool status -v' would be more useful with filenames
ek110237
parents: 3063
diff changeset
    69
 * (such as VFS logic) that will not compile easily in userland.
dc160a70a50d 6410433 'zpool status -v' would be more useful with filenames
ek110237
parents: 3063
diff changeset
    70
 */
dc160a70a50d 6410433 'zpool status -v' would be more useful with filenames
ek110237
parents: 3063
diff changeset
    71
#ifdef _KERNEL
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    72
struct kmem_cache *znode_cache = NULL;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    73
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    74
/*ARGSUSED*/
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    75
static void
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    76
znode_pageout_func(dmu_buf_t *dbuf, void *user_ptr)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    77
{
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    78
	znode_t *zp = user_ptr;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    79
	vnode_t *vp = ZTOV(zp);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    80
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1394
diff changeset
    81
	mutex_enter(&zp->z_lock);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    82
	if (vp->v_count == 0) {
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1394
diff changeset
    83
		mutex_exit(&zp->z_lock);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    84
		vn_invalid(vp);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    85
		zfs_znode_free(zp);
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1394
diff changeset
    86
	} else {
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1394
diff changeset
    87
		/* signal force unmount that this znode can be freed */
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1394
diff changeset
    88
		zp->z_dbuf = NULL;
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1394
diff changeset
    89
		mutex_exit(&zp->z_lock);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    90
	}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    91
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    92
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    93
/*ARGSUSED*/
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    94
static int
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    95
zfs_znode_cache_constructor(void *buf, void *cdrarg, int kmflags)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    96
{
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    97
	znode_t *zp = buf;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    98
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    99
	zp->z_vnode = vn_alloc(KM_SLEEP);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   100
	zp->z_vnode->v_data = (caddr_t)zp;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   101
	mutex_init(&zp->z_lock, NULL, MUTEX_DEFAULT, NULL);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   102
	rw_init(&zp->z_map_lock, NULL, RW_DEFAULT, NULL);
1669
3521dbbcb2e8 6343608 ZFS file range locking
perrin
parents: 1544
diff changeset
   103
	rw_init(&zp->z_parent_lock, NULL, RW_DEFAULT, NULL);
3897
278bade789ba 6437750 panic: db->db_buf==0||arc_referenced(db->db_buf), file: dbuf.c,line:1539
maybee
parents: 3461
diff changeset
   104
	rw_init(&zp->z_name_lock, NULL, RW_DEFAULT, NULL);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   105
	mutex_init(&zp->z_acl_lock, NULL, MUTEX_DEFAULT, NULL);
1669
3521dbbcb2e8 6343608 ZFS file range locking
perrin
parents: 1544
diff changeset
   106
3521dbbcb2e8 6343608 ZFS file range locking
perrin
parents: 1544
diff changeset
   107
	mutex_init(&zp->z_range_lock, NULL, MUTEX_DEFAULT, NULL);
3521dbbcb2e8 6343608 ZFS file range locking
perrin
parents: 1544
diff changeset
   108
	avl_create(&zp->z_range_avl, zfs_range_compare,
3521dbbcb2e8 6343608 ZFS file range locking
perrin
parents: 1544
diff changeset
   109
	    sizeof (rl_t), offsetof(rl_t, r_node));
3521dbbcb2e8 6343608 ZFS file range locking
perrin
parents: 1544
diff changeset
   110
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   111
	zp->z_dbuf_held = 0;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   112
	zp->z_dirlocks = 0;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   113
	return (0);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   114
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   115
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   116
/*ARGSUSED*/
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   117
static void
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   118
zfs_znode_cache_destructor(void *buf, void *cdarg)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   119
{
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   120
	znode_t *zp = buf;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   121
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   122
	ASSERT(zp->z_dirlocks == 0);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   123
	mutex_destroy(&zp->z_lock);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   124
	rw_destroy(&zp->z_map_lock);
1669
3521dbbcb2e8 6343608 ZFS file range locking
perrin
parents: 1544
diff changeset
   125
	rw_destroy(&zp->z_parent_lock);
3897
278bade789ba 6437750 panic: db->db_buf==0||arc_referenced(db->db_buf), file: dbuf.c,line:1539
maybee
parents: 3461
diff changeset
   126
	rw_destroy(&zp->z_name_lock);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   127
	mutex_destroy(&zp->z_acl_lock);
1669
3521dbbcb2e8 6343608 ZFS file range locking
perrin
parents: 1544
diff changeset
   128
	avl_destroy(&zp->z_range_avl);
4831
41ec732c6d9f 6584470 zdb needs to initialize the bpl_lock mutex
gw25295
parents: 4577
diff changeset
   129
	mutex_destroy(&zp->z_range_lock);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   130
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   131
	ASSERT(zp->z_dbuf_held == 0);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   132
	ASSERT(ZTOV(zp)->v_count == 0);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   133
	vn_free(ZTOV(zp));
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   134
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   135
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   136
void
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   137
zfs_znode_init(void)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   138
{
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   139
	/*
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   140
	 * Initialize zcache
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   141
	 */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   142
	ASSERT(znode_cache == NULL);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   143
	znode_cache = kmem_cache_create("zfs_znode_cache",
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   144
	    sizeof (znode_t), 0, zfs_znode_cache_constructor,
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   145
	    zfs_znode_cache_destructor, NULL, NULL, NULL, 0);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   146
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   147
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   148
void
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   149
zfs_znode_fini(void)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   150
{
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   151
	/*
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   152
	 * Cleanup vfs & vnode ops
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   153
	 */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   154
	zfs_remove_op_tables();
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   155
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   156
	/*
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   157
	 * Cleanup zcache
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   158
	 */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   159
	if (znode_cache)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   160
		kmem_cache_destroy(znode_cache);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   161
	znode_cache = NULL;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   162
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   163
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   164
struct vnodeops *zfs_dvnodeops;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   165
struct vnodeops *zfs_fvnodeops;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   166
struct vnodeops *zfs_symvnodeops;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   167
struct vnodeops *zfs_xdvnodeops;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   168
struct vnodeops *zfs_evnodeops;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   169
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   170
void
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   171
zfs_remove_op_tables()
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   172
{
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   173
	/*
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   174
	 * Remove vfs ops
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   175
	 */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   176
	ASSERT(zfsfstype);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   177
	(void) vfs_freevfsops_by_type(zfsfstype);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   178
	zfsfstype = 0;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   179
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   180
	/*
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   181
	 * Remove vnode ops
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   182
	 */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   183
	if (zfs_dvnodeops)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   184
		vn_freevnodeops(zfs_dvnodeops);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   185
	if (zfs_fvnodeops)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   186
		vn_freevnodeops(zfs_fvnodeops);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   187
	if (zfs_symvnodeops)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   188
		vn_freevnodeops(zfs_symvnodeops);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   189
	if (zfs_xdvnodeops)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   190
		vn_freevnodeops(zfs_xdvnodeops);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   191
	if (zfs_evnodeops)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   192
		vn_freevnodeops(zfs_evnodeops);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   193
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   194
	zfs_dvnodeops = NULL;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   195
	zfs_fvnodeops = NULL;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   196
	zfs_symvnodeops = NULL;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   197
	zfs_xdvnodeops = NULL;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   198
	zfs_evnodeops = NULL;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   199
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   200
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   201
extern const fs_operation_def_t zfs_dvnodeops_template[];
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   202
extern const fs_operation_def_t zfs_fvnodeops_template[];
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   203
extern const fs_operation_def_t zfs_xdvnodeops_template[];
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   204
extern const fs_operation_def_t zfs_symvnodeops_template[];
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   205
extern const fs_operation_def_t zfs_evnodeops_template[];
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   206
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   207
int
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   208
zfs_create_op_tables()
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   209
{
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   210
	int error;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   211
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   212
	/*
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   213
	 * zfs_dvnodeops can be set if mod_remove() calls mod_installfs()
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   214
	 * due to a failure to remove the the 2nd modlinkage (zfs_modldrv).
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   215
	 * In this case we just return as the ops vectors are already set up.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   216
	 */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   217
	if (zfs_dvnodeops)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   218
		return (0);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   219
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   220
	error = vn_make_ops(MNTTYPE_ZFS, zfs_dvnodeops_template,
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   221
	    &zfs_dvnodeops);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   222
	if (error)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   223
		return (error);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   224
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   225
	error = vn_make_ops(MNTTYPE_ZFS, zfs_fvnodeops_template,
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   226
	    &zfs_fvnodeops);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   227
	if (error)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   228
		return (error);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   229
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   230
	error = vn_make_ops(MNTTYPE_ZFS, zfs_symvnodeops_template,
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   231
	    &zfs_symvnodeops);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   232
	if (error)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   233
		return (error);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   234
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   235
	error = vn_make_ops(MNTTYPE_ZFS, zfs_xdvnodeops_template,
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   236
	    &zfs_xdvnodeops);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   237
	if (error)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   238
		return (error);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   239
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   240
	error = vn_make_ops(MNTTYPE_ZFS, zfs_evnodeops_template,
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   241
	    &zfs_evnodeops);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   242
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   243
	return (error);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   244
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   245
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   246
/*
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   247
 * zfs_init_fs - Initialize the zfsvfs struct and the file system
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   248
 *	incore "master" object.  Verify version compatibility.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   249
 */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   250
int
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   251
zfs_init_fs(zfsvfs_t *zfsvfs, znode_t **zpp, cred_t *cr)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   252
{
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   253
	extern int zfsfstype;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   254
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   255
	objset_t	*os = zfsvfs->z_os;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   256
	int		i, error;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   257
	dmu_object_info_t doi;
2885
c0259887ebbc 6460059 zfs destroy <snapshot> leaves behind kruft
ahrens
parents: 2856
diff changeset
   258
	uint64_t fsid_guid;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   259
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   260
	*zpp = NULL;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   261
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   262
	/*
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   263
	 * XXX - hack to auto-create the pool root filesystem at
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   264
	 * the first attempted mount.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   265
	 */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   266
	if (dmu_object_info(os, MASTER_NODE_OBJ, &doi) == ENOENT) {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   267
		dmu_tx_t *tx = dmu_tx_create(os);
5331
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5326
diff changeset
   268
		uint64_t zpl_version;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   269
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1394
diff changeset
   270
		dmu_tx_hold_zap(tx, DMU_NEW_OBJECT, TRUE, NULL); /* master */
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1394
diff changeset
   271
		dmu_tx_hold_zap(tx, DMU_NEW_OBJECT, TRUE, NULL); /* del queue */
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   272
		dmu_tx_hold_bonus(tx, DMU_NEW_OBJECT); /* root node */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   273
		error = dmu_tx_assign(tx, TXG_WAIT);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   274
		ASSERT3U(error, ==, 0);
5331
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5326
diff changeset
   275
		if (spa_version(dmu_objset_spa(os)) >= SPA_VERSION_FUID)
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5326
diff changeset
   276
			zpl_version = ZPL_VERSION;
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5326
diff changeset
   277
		else
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5326
diff changeset
   278
			zpl_version = ZPL_VERSION_FUID - 1;
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5326
diff changeset
   279
		zfs_create_fs(os, cr, zpl_version, 0, tx);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   280
		dmu_tx_commit(tx);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   281
	}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   282
4577
ed36b0e652bc PSARC/2007/328 zfs upgrade
ahrens
parents: 4543
diff changeset
   283
	error = zap_lookup(os, MASTER_NODE_OBJ, ZPL_VERSION_STR, 8, 1,
ed36b0e652bc PSARC/2007/328 zfs upgrade
ahrens
parents: 4543
diff changeset
   284
	    &zfsvfs->z_version);
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1394
diff changeset
   285
	if (error) {
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1394
diff changeset
   286
		return (error);
4577
ed36b0e652bc PSARC/2007/328 zfs upgrade
ahrens
parents: 4543
diff changeset
   287
	} else if (zfsvfs->z_version > ZPL_VERSION) {
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   288
		(void) printf("Mismatched versions:  File system "
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   289
		    "is version %lld on-disk format, which is "
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   290
		    "incompatible with this software version %lld!",
4577
ed36b0e652bc PSARC/2007/328 zfs upgrade
ahrens
parents: 4543
diff changeset
   291
		    (u_longlong_t)zfsvfs->z_version, ZPL_VERSION);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   292
		return (ENOTSUP);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   293
	}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   294
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   295
	/*
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   296
	 * The fsid is 64 bits, composed of an 8-bit fs type, which
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   297
	 * separates our fsid from any other filesystem types, and a
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   298
	 * 56-bit objset unique ID.  The objset unique ID is unique to
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   299
	 * all objsets open on this system, provided by unique_create().
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   300
	 * The 8-bit fs type must be put in the low bits of fsid[1]
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   301
	 * because that's where other Solaris filesystems put it.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   302
	 */
2885
c0259887ebbc 6460059 zfs destroy <snapshot> leaves behind kruft
ahrens
parents: 2856
diff changeset
   303
	fsid_guid = dmu_objset_fsid_guid(os);
c0259887ebbc 6460059 zfs destroy <snapshot> leaves behind kruft
ahrens
parents: 2856
diff changeset
   304
	ASSERT((fsid_guid & ~((1ULL<<56)-1)) == 0);
c0259887ebbc 6460059 zfs destroy <snapshot> leaves behind kruft
ahrens
parents: 2856
diff changeset
   305
	zfsvfs->z_vfs->vfs_fsid.val[0] = fsid_guid;
c0259887ebbc 6460059 zfs destroy <snapshot> leaves behind kruft
ahrens
parents: 2856
diff changeset
   306
	zfsvfs->z_vfs->vfs_fsid.val[1] = ((fsid_guid>>32) << 8) |
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   307
	    zfsfstype & 0xFF;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   308
3461
c19b22f347d6 6514331 in-memory delete queue is not needed
ahrens
parents: 3444
diff changeset
   309
	error = zap_lookup(os, MASTER_NODE_OBJ, ZFS_ROOT_OBJ, 8, 1,
c19b22f347d6 6514331 in-memory delete queue is not needed
ahrens
parents: 3444
diff changeset
   310
	    &zfsvfs->z_root);
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1394
diff changeset
   311
	if (error)
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1394
diff changeset
   312
		return (error);
3461
c19b22f347d6 6514331 in-memory delete queue is not needed
ahrens
parents: 3444
diff changeset
   313
	ASSERT(zfsvfs->z_root != 0);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   314
4831
41ec732c6d9f 6584470 zdb needs to initialize the bpl_lock mutex
gw25295
parents: 4577
diff changeset
   315
	error = zap_lookup(os, MASTER_NODE_OBJ, ZFS_UNLINKED_SET, 8, 1,
41ec732c6d9f 6584470 zdb needs to initialize the bpl_lock mutex
gw25295
parents: 4577
diff changeset
   316
	    &zfsvfs->z_unlinkedobj);
41ec732c6d9f 6584470 zdb needs to initialize the bpl_lock mutex
gw25295
parents: 4577
diff changeset
   317
	if (error)
41ec732c6d9f 6584470 zdb needs to initialize the bpl_lock mutex
gw25295
parents: 4577
diff changeset
   318
		return (error);
41ec732c6d9f 6584470 zdb needs to initialize the bpl_lock mutex
gw25295
parents: 4577
diff changeset
   319
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   320
	/*
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   321
	 * Initialize zget mutex's
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   322
	 */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   323
	for (i = 0; i != ZFS_OBJ_MTX_SZ; i++)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   324
		mutex_init(&zfsvfs->z_hold_mtx[i], NULL, MUTEX_DEFAULT, NULL);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   325
3461
c19b22f347d6 6514331 in-memory delete queue is not needed
ahrens
parents: 3444
diff changeset
   326
	error = zfs_zget(zfsvfs, zfsvfs->z_root, zpp);
4831
41ec732c6d9f 6584470 zdb needs to initialize the bpl_lock mutex
gw25295
parents: 4577
diff changeset
   327
	if (error) {
41ec732c6d9f 6584470 zdb needs to initialize the bpl_lock mutex
gw25295
parents: 4577
diff changeset
   328
		/*
41ec732c6d9f 6584470 zdb needs to initialize the bpl_lock mutex
gw25295
parents: 4577
diff changeset
   329
		 * On error, we destroy the mutexes here since it's not
41ec732c6d9f 6584470 zdb needs to initialize the bpl_lock mutex
gw25295
parents: 4577
diff changeset
   330
		 * possible for the caller to determine if the mutexes were
41ec732c6d9f 6584470 zdb needs to initialize the bpl_lock mutex
gw25295
parents: 4577
diff changeset
   331
		 * initialized properly.
41ec732c6d9f 6584470 zdb needs to initialize the bpl_lock mutex
gw25295
parents: 4577
diff changeset
   332
		 */
41ec732c6d9f 6584470 zdb needs to initialize the bpl_lock mutex
gw25295
parents: 4577
diff changeset
   333
		for (i = 0; i != ZFS_OBJ_MTX_SZ; i++)
41ec732c6d9f 6584470 zdb needs to initialize the bpl_lock mutex
gw25295
parents: 4577
diff changeset
   334
			mutex_destroy(&zfsvfs->z_hold_mtx[i]);
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1394
diff changeset
   335
		return (error);
4831
41ec732c6d9f 6584470 zdb needs to initialize the bpl_lock mutex
gw25295
parents: 4577
diff changeset
   336
	}
3461
c19b22f347d6 6514331 in-memory delete queue is not needed
ahrens
parents: 3444
diff changeset
   337
	ASSERT3U((*zpp)->z_id, ==, zfsvfs->z_root);
5331
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5326
diff changeset
   338
	error = zap_lookup(os, MASTER_NODE_OBJ, ZFS_FUID_TABLES, 8, 1,
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5326
diff changeset
   339
	    &zfsvfs->z_fuid_obj);
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5326
diff changeset
   340
	if (error == ENOENT)
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5326
diff changeset
   341
		error = 0;
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5326
diff changeset
   342
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   343
	return (0);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   344
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   345
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   346
/*
1816
8c14b56c8515 6408482 64-bit system can't read some 32-bit dev_ts created on zfs
marks
parents: 1760
diff changeset
   347
 * define a couple of values we need available
8c14b56c8515 6408482 64-bit system can't read some 32-bit dev_ts created on zfs
marks
parents: 1760
diff changeset
   348
 * for both 64 and 32 bit environments.
8c14b56c8515 6408482 64-bit system can't read some 32-bit dev_ts created on zfs
marks
parents: 1760
diff changeset
   349
 */
8c14b56c8515 6408482 64-bit system can't read some 32-bit dev_ts created on zfs
marks
parents: 1760
diff changeset
   350
#ifndef NBITSMINOR64
8c14b56c8515 6408482 64-bit system can't read some 32-bit dev_ts created on zfs
marks
parents: 1760
diff changeset
   351
#define	NBITSMINOR64	32
8c14b56c8515 6408482 64-bit system can't read some 32-bit dev_ts created on zfs
marks
parents: 1760
diff changeset
   352
#endif
8c14b56c8515 6408482 64-bit system can't read some 32-bit dev_ts created on zfs
marks
parents: 1760
diff changeset
   353
#ifndef MAXMAJ64
8c14b56c8515 6408482 64-bit system can't read some 32-bit dev_ts created on zfs
marks
parents: 1760
diff changeset
   354
#define	MAXMAJ64	0xffffffffUL
8c14b56c8515 6408482 64-bit system can't read some 32-bit dev_ts created on zfs
marks
parents: 1760
diff changeset
   355
#endif
8c14b56c8515 6408482 64-bit system can't read some 32-bit dev_ts created on zfs
marks
parents: 1760
diff changeset
   356
#ifndef	MAXMIN64
8c14b56c8515 6408482 64-bit system can't read some 32-bit dev_ts created on zfs
marks
parents: 1760
diff changeset
   357
#define	MAXMIN64	0xffffffffUL
8c14b56c8515 6408482 64-bit system can't read some 32-bit dev_ts created on zfs
marks
parents: 1760
diff changeset
   358
#endif
8c14b56c8515 6408482 64-bit system can't read some 32-bit dev_ts created on zfs
marks
parents: 1760
diff changeset
   359
8c14b56c8515 6408482 64-bit system can't read some 32-bit dev_ts created on zfs
marks
parents: 1760
diff changeset
   360
/*
8c14b56c8515 6408482 64-bit system can't read some 32-bit dev_ts created on zfs
marks
parents: 1760
diff changeset
   361
 * Create special expldev for ZFS private use.
8c14b56c8515 6408482 64-bit system can't read some 32-bit dev_ts created on zfs
marks
parents: 1760
diff changeset
   362
 * Can't use standard expldev since it doesn't do
8c14b56c8515 6408482 64-bit system can't read some 32-bit dev_ts created on zfs
marks
parents: 1760
diff changeset
   363
 * what we want.  The standard expldev() takes a
8c14b56c8515 6408482 64-bit system can't read some 32-bit dev_ts created on zfs
marks
parents: 1760
diff changeset
   364
 * dev32_t in LP64 and expands it to a long dev_t.
8c14b56c8515 6408482 64-bit system can't read some 32-bit dev_ts created on zfs
marks
parents: 1760
diff changeset
   365
 * We need an interface that takes a dev32_t in ILP32
8c14b56c8515 6408482 64-bit system can't read some 32-bit dev_ts created on zfs
marks
parents: 1760
diff changeset
   366
 * and expands it to a long dev_t.
8c14b56c8515 6408482 64-bit system can't read some 32-bit dev_ts created on zfs
marks
parents: 1760
diff changeset
   367
 */
8c14b56c8515 6408482 64-bit system can't read some 32-bit dev_ts created on zfs
marks
parents: 1760
diff changeset
   368
static uint64_t
8c14b56c8515 6408482 64-bit system can't read some 32-bit dev_ts created on zfs
marks
parents: 1760
diff changeset
   369
zfs_expldev(dev_t dev)
8c14b56c8515 6408482 64-bit system can't read some 32-bit dev_ts created on zfs
marks
parents: 1760
diff changeset
   370
{
8c14b56c8515 6408482 64-bit system can't read some 32-bit dev_ts created on zfs
marks
parents: 1760
diff changeset
   371
#ifndef _LP64
8c14b56c8515 6408482 64-bit system can't read some 32-bit dev_ts created on zfs
marks
parents: 1760
diff changeset
   372
	major_t major = (major_t)dev >> NBITSMINOR32 & MAXMAJ32;
8c14b56c8515 6408482 64-bit system can't read some 32-bit dev_ts created on zfs
marks
parents: 1760
diff changeset
   373
	return (((uint64_t)major << NBITSMINOR64) |
8c14b56c8515 6408482 64-bit system can't read some 32-bit dev_ts created on zfs
marks
parents: 1760
diff changeset
   374
	    ((minor_t)dev & MAXMIN32));
8c14b56c8515 6408482 64-bit system can't read some 32-bit dev_ts created on zfs
marks
parents: 1760
diff changeset
   375
#else
8c14b56c8515 6408482 64-bit system can't read some 32-bit dev_ts created on zfs
marks
parents: 1760
diff changeset
   376
	return (dev);
8c14b56c8515 6408482 64-bit system can't read some 32-bit dev_ts created on zfs
marks
parents: 1760
diff changeset
   377
#endif
8c14b56c8515 6408482 64-bit system can't read some 32-bit dev_ts created on zfs
marks
parents: 1760
diff changeset
   378
}
8c14b56c8515 6408482 64-bit system can't read some 32-bit dev_ts created on zfs
marks
parents: 1760
diff changeset
   379
8c14b56c8515 6408482 64-bit system can't read some 32-bit dev_ts created on zfs
marks
parents: 1760
diff changeset
   380
/*
8c14b56c8515 6408482 64-bit system can't read some 32-bit dev_ts created on zfs
marks
parents: 1760
diff changeset
   381
 * Special cmpldev for ZFS private use.
8c14b56c8515 6408482 64-bit system can't read some 32-bit dev_ts created on zfs
marks
parents: 1760
diff changeset
   382
 * Can't use standard cmpldev since it takes
8c14b56c8515 6408482 64-bit system can't read some 32-bit dev_ts created on zfs
marks
parents: 1760
diff changeset
   383
 * a long dev_t and compresses it to dev32_t in
8c14b56c8515 6408482 64-bit system can't read some 32-bit dev_ts created on zfs
marks
parents: 1760
diff changeset
   384
 * LP64.  We need to do a compaction of a long dev_t
8c14b56c8515 6408482 64-bit system can't read some 32-bit dev_ts created on zfs
marks
parents: 1760
diff changeset
   385
 * to a dev32_t in ILP32.
8c14b56c8515 6408482 64-bit system can't read some 32-bit dev_ts created on zfs
marks
parents: 1760
diff changeset
   386
 */
8c14b56c8515 6408482 64-bit system can't read some 32-bit dev_ts created on zfs
marks
parents: 1760
diff changeset
   387
dev_t
8c14b56c8515 6408482 64-bit system can't read some 32-bit dev_ts created on zfs
marks
parents: 1760
diff changeset
   388
zfs_cmpldev(uint64_t dev)
8c14b56c8515 6408482 64-bit system can't read some 32-bit dev_ts created on zfs
marks
parents: 1760
diff changeset
   389
{
8c14b56c8515 6408482 64-bit system can't read some 32-bit dev_ts created on zfs
marks
parents: 1760
diff changeset
   390
#ifndef _LP64
8c14b56c8515 6408482 64-bit system can't read some 32-bit dev_ts created on zfs
marks
parents: 1760
diff changeset
   391
	minor_t minor = (minor_t)dev & MAXMIN64;
8c14b56c8515 6408482 64-bit system can't read some 32-bit dev_ts created on zfs
marks
parents: 1760
diff changeset
   392
	major_t major = (major_t)(dev >> NBITSMINOR64) & MAXMAJ64;
8c14b56c8515 6408482 64-bit system can't read some 32-bit dev_ts created on zfs
marks
parents: 1760
diff changeset
   393
8c14b56c8515 6408482 64-bit system can't read some 32-bit dev_ts created on zfs
marks
parents: 1760
diff changeset
   394
	if (major > MAXMAJ32 || minor > MAXMIN32)
8c14b56c8515 6408482 64-bit system can't read some 32-bit dev_ts created on zfs
marks
parents: 1760
diff changeset
   395
		return (NODEV32);
8c14b56c8515 6408482 64-bit system can't read some 32-bit dev_ts created on zfs
marks
parents: 1760
diff changeset
   396
8c14b56c8515 6408482 64-bit system can't read some 32-bit dev_ts created on zfs
marks
parents: 1760
diff changeset
   397
	return (((dev32_t)major << NBITSMINOR32) | minor);
8c14b56c8515 6408482 64-bit system can't read some 32-bit dev_ts created on zfs
marks
parents: 1760
diff changeset
   398
#else
8c14b56c8515 6408482 64-bit system can't read some 32-bit dev_ts created on zfs
marks
parents: 1760
diff changeset
   399
	return (dev);
8c14b56c8515 6408482 64-bit system can't read some 32-bit dev_ts created on zfs
marks
parents: 1760
diff changeset
   400
#endif
8c14b56c8515 6408482 64-bit system can't read some 32-bit dev_ts created on zfs
marks
parents: 1760
diff changeset
   401
}
8c14b56c8515 6408482 64-bit system can't read some 32-bit dev_ts created on zfs
marks
parents: 1760
diff changeset
   402
8c14b56c8515 6408482 64-bit system can't read some 32-bit dev_ts created on zfs
marks
parents: 1760
diff changeset
   403
/*
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   404
 * Construct a new znode/vnode and intialize.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   405
 *
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   406
 * This does not do a call to dmu_set_user() that is
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   407
 * up to the caller to do, in case you don't want to
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   408
 * return the znode
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   409
 */
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1394
diff changeset
   410
static znode_t *
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   411
zfs_znode_alloc(zfsvfs_t *zfsvfs, dmu_buf_t *db, uint64_t obj_num, int blksz)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   412
{
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   413
	znode_t	*zp;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   414
	vnode_t *vp;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   415
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   416
	zp = kmem_cache_alloc(znode_cache, KM_SLEEP);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   417
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   418
	ASSERT(zp->z_dirlocks == NULL);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   419
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   420
	zp->z_phys = db->db_data;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   421
	zp->z_zfsvfs = zfsvfs;
3461
c19b22f347d6 6514331 in-memory delete queue is not needed
ahrens
parents: 3444
diff changeset
   422
	zp->z_unlinked = 0;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   423
	zp->z_atime_dirty = 0;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   424
	zp->z_dbuf_held = 0;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   425
	zp->z_mapcnt = 0;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   426
	zp->z_last_itx = 0;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   427
	zp->z_dbuf = db;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   428
	zp->z_id = obj_num;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   429
	zp->z_blksz = blksz;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   430
	zp->z_seq = 0x7A4653;
3063
b252896b372b 6341569 zio_alloc_blk() vdev distribution performs badly
perrin
parents: 2885
diff changeset
   431
	zp->z_sync_cnt = 0;
5326
6752aa2bd5bc 6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents: 4831
diff changeset
   432
	zp->z_gen = zp->z_phys->zp_gen;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   433
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   434
	mutex_enter(&zfsvfs->z_znodes_lock);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   435
	list_insert_tail(&zfsvfs->z_all_znodes, zp);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   436
	mutex_exit(&zfsvfs->z_znodes_lock);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   437
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   438
	vp = ZTOV(zp);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   439
	vn_reinit(vp);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   440
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   441
	vp->v_vfsp = zfsvfs->z_parent->z_vfs;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   442
	vp->v_type = IFTOVT((mode_t)zp->z_phys->zp_mode);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   443
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   444
	switch (vp->v_type) {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   445
	case VDIR:
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   446
		if (zp->z_phys->zp_flags & ZFS_XATTR) {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   447
			vn_setops(vp, zfs_xdvnodeops);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   448
			vp->v_flag |= V_XATTRDIR;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   449
		} else
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   450
			vn_setops(vp, zfs_dvnodeops);
869
dc133b87dfb3 6297285 znode prefetching in zfs_readdir causes 5x performance degradation for 'ls'
perrin
parents: 789
diff changeset
   451
		zp->z_zn_prefetch = B_TRUE; /* z_prefetch default is enabled */
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   452
		break;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   453
	case VBLK:
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   454
	case VCHR:
1816
8c14b56c8515 6408482 64-bit system can't read some 32-bit dev_ts created on zfs
marks
parents: 1760
diff changeset
   455
		vp->v_rdev = zfs_cmpldev(zp->z_phys->zp_rdev);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   456
		/*FALLTHROUGH*/
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   457
	case VFIFO:
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   458
	case VSOCK:
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   459
	case VDOOR:
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   460
		vn_setops(vp, zfs_fvnodeops);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   461
		break;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   462
	case VREG:
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   463
		vp->v_flag |= VMODSORT;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   464
		vn_setops(vp, zfs_fvnodeops);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   465
		break;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   466
	case VLNK:
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   467
		vn_setops(vp, zfs_symvnodeops);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   468
		break;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   469
	default:
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   470
		vn_setops(vp, zfs_evnodeops);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   471
		break;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   472
	}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   473
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   474
	return (zp);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   475
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   476
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   477
static void
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   478
zfs_znode_dmu_init(znode_t *zp)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   479
{
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   480
	znode_t		*nzp;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   481
	zfsvfs_t	*zfsvfs = zp->z_zfsvfs;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   482
	dmu_buf_t	*db = zp->z_dbuf;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   483
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   484
	mutex_enter(&zp->z_lock);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   485
4105
d90754357495 6543706 znodes should be immediatley freed, allowing the ARC to hold onto less memory
ek110237
parents: 3898
diff changeset
   486
	nzp = dmu_buf_set_user_ie(db, zp, &zp->z_phys, znode_pageout_func);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   487
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   488
	/*
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   489
	 * there should be no
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   490
	 * concurrent zgets on this object.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   491
	 */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   492
	ASSERT3P(nzp, ==, NULL);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   493
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   494
	/*
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   495
	 * Slap on VROOT if we are the root znode
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   496
	 */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   497
	if (zp->z_id == zfsvfs->z_root) {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   498
		ZTOV(zp)->v_flag |= VROOT;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   499
	}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   500
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   501
	ASSERT(zp->z_dbuf_held == 0);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   502
	zp->z_dbuf_held = 1;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   503
	VFS_HOLD(zfsvfs->z_vfs);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   504
	mutex_exit(&zp->z_lock);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   505
	vn_exists(ZTOV(zp));
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   506
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   507
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   508
/*
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   509
 * Create a new DMU object to hold a zfs znode.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   510
 *
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   511
 *	IN:	dzp	- parent directory for new znode
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   512
 *		vap	- file attributes for new znode
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   513
 *		tx	- dmu transaction id for zap operations
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   514
 *		cr	- credentials of caller
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   515
 *		flag	- flags:
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   516
 *			  IS_ROOT_NODE	- new object will be root
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   517
 *			  IS_XATTR	- new object is an attribute
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   518
 *			  IS_REPLAY	- intent log replay
5331
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5326
diff changeset
   519
 *		bonuslen - length of bonus buffer
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5326
diff changeset
   520
 *		setaclp  - File/Dir initial ACL
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5326
diff changeset
   521
 *		fuidp	 - Tracks fuid allocation.
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   522
 *
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   523
 *	OUT:	oid	- ID of created object
5331
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5326
diff changeset
   524
 *		zpp	- allocated znode
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   525
 *
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   526
 */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   527
void
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   528
zfs_mknode(znode_t *dzp, vattr_t *vap, uint64_t *oid, dmu_tx_t *tx, cred_t *cr,
5331
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5326
diff changeset
   529
    uint_t flag, znode_t **zpp, int bonuslen, zfs_acl_t *setaclp,
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5326
diff changeset
   530
    zfs_fuid_info_t **fuidp)
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   531
{
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   532
	dmu_buf_t	*dbp;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   533
	znode_phys_t	*pzp;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   534
	znode_t		*zp;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   535
	zfsvfs_t	*zfsvfs = dzp->z_zfsvfs;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   536
	timestruc_t	now;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   537
	uint64_t	gen;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   538
	int		err;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   539
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   540
	ASSERT(vap && (vap->va_mask & (AT_TYPE|AT_MODE)) == (AT_TYPE|AT_MODE));
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   541
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   542
	if (zfsvfs->z_assign >= TXG_INITIAL) {		/* ZIL replay */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   543
		*oid = vap->va_nodeid;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   544
		flag |= IS_REPLAY;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   545
		now = vap->va_ctime;		/* see zfs_replay_create() */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   546
		gen = vap->va_nblocks;		/* ditto */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   547
	} else {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   548
		*oid = 0;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   549
		gethrestime(&now);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   550
		gen = dmu_tx_get_txg(tx);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   551
	}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   552
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   553
	/*
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   554
	 * Create a new DMU object.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   555
	 */
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1394
diff changeset
   556
	/*
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1394
diff changeset
   557
	 * There's currently no mechanism for pre-reading the blocks that will
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1394
diff changeset
   558
	 * be to needed allocate a new object, so we accept the small chance
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1394
diff changeset
   559
	 * that there will be an i/o error and we will fail one of the
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1394
diff changeset
   560
	 * assertions below.
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1394
diff changeset
   561
	 */
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   562
	if (vap->va_type == VDIR) {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   563
		if (flag & IS_REPLAY) {
5331
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5326
diff changeset
   564
			err = zap_create_claim_norm(zfsvfs->z_os, *oid,
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5326
diff changeset
   565
			    zfsvfs->z_norm, DMU_OT_DIRECTORY_CONTENTS,
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   566
			    DMU_OT_ZNODE, sizeof (znode_phys_t) + bonuslen, tx);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   567
			ASSERT3U(err, ==, 0);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   568
		} else {
5331
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5326
diff changeset
   569
			*oid = zap_create_norm(zfsvfs->z_os,
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5326
diff changeset
   570
			    zfsvfs->z_norm, DMU_OT_DIRECTORY_CONTENTS,
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   571
			    DMU_OT_ZNODE, sizeof (znode_phys_t) + bonuslen, tx);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   572
		}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   573
	} else {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   574
		if (flag & IS_REPLAY) {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   575
			err = dmu_object_claim(zfsvfs->z_os, *oid,
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   576
			    DMU_OT_PLAIN_FILE_CONTENTS, 0,
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   577
			    DMU_OT_ZNODE, sizeof (znode_phys_t) + bonuslen, tx);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   578
			ASSERT3U(err, ==, 0);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   579
		} else {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   580
			*oid = dmu_object_alloc(zfsvfs->z_os,
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   581
			    DMU_OT_PLAIN_FILE_CONTENTS, 0,
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   582
			    DMU_OT_ZNODE, sizeof (znode_phys_t) + bonuslen, tx);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   583
		}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   584
	}
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1394
diff changeset
   585
	VERIFY(0 == dmu_bonus_hold(zfsvfs->z_os, *oid, NULL, &dbp));
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   586
	dmu_buf_will_dirty(dbp, tx);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   587
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   588
	/*
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   589
	 * Initialize the znode physical data to zero.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   590
	 */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   591
	ASSERT(dbp->db_size >= sizeof (znode_phys_t));
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   592
	bzero(dbp->db_data, dbp->db_size);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   593
	pzp = dbp->db_data;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   594
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   595
	/*
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   596
	 * If this is the root, fix up the half-initialized parent pointer
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   597
	 * to reference the just-allocated physical data area.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   598
	 */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   599
	if (flag & IS_ROOT_NODE) {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   600
		dzp->z_phys = pzp;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   601
		dzp->z_id = *oid;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   602
	}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   603
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   604
	/*
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   605
	 * If parent is an xattr, so am I.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   606
	 */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   607
	if (dzp->z_phys->zp_flags & ZFS_XATTR)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   608
		flag |= IS_XATTR;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   609
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   610
	if (vap->va_type == VBLK || vap->va_type == VCHR) {
1816
8c14b56c8515 6408482 64-bit system can't read some 32-bit dev_ts created on zfs
marks
parents: 1760
diff changeset
   611
		pzp->zp_rdev = zfs_expldev(vap->va_rdev);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   612
	}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   613
5331
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5326
diff changeset
   614
	if (zfsvfs->z_use_fuids)
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5326
diff changeset
   615
		pzp->zp_flags = ZFS_ARCHIVE | ZFS_AV_MODIFIED;
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5326
diff changeset
   616
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   617
	if (vap->va_type == VDIR) {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   618
		pzp->zp_size = 2;		/* contents ("." and "..") */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   619
		pzp->zp_links = (flag & (IS_ROOT_NODE | IS_XATTR)) ? 2 : 1;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   620
	}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   621
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   622
	pzp->zp_parent = dzp->z_id;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   623
	if (flag & IS_XATTR)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   624
		pzp->zp_flags |= ZFS_XATTR;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   625
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   626
	pzp->zp_gen = gen;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   627
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   628
	ZFS_TIME_ENCODE(&now, pzp->zp_crtime);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   629
	ZFS_TIME_ENCODE(&now, pzp->zp_ctime);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   630
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   631
	if (vap->va_mask & AT_ATIME) {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   632
		ZFS_TIME_ENCODE(&vap->va_atime, pzp->zp_atime);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   633
	} else {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   634
		ZFS_TIME_ENCODE(&now, pzp->zp_atime);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   635
	}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   636
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   637
	if (vap->va_mask & AT_MTIME) {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   638
		ZFS_TIME_ENCODE(&vap->va_mtime, pzp->zp_mtime);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   639
	} else {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   640
		ZFS_TIME_ENCODE(&now, pzp->zp_mtime);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   641
	}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   642
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   643
	pzp->zp_mode = MAKEIMODE(vap->va_type, vap->va_mode);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   644
	zp = zfs_znode_alloc(zfsvfs, dbp, *oid, 0);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   645
5331
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5326
diff changeset
   646
	zfs_perm_init(zp, dzp, flag, vap, tx, cr, setaclp, fuidp);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   647
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   648
	if (zpp) {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   649
		kmutex_t *hash_mtx = ZFS_OBJ_MUTEX(zp);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   650
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   651
		mutex_enter(hash_mtx);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   652
		zfs_znode_dmu_init(zp);
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1394
diff changeset
   653
		mutex_exit(hash_mtx);
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1394
diff changeset
   654
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   655
		*zpp = zp;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   656
	} else {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   657
		ZTOV(zp)->v_count = 0;
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1394
diff changeset
   658
		dmu_buf_rele(dbp, NULL);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   659
		zfs_znode_free(zp);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   660
	}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   661
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   662
5331
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5326
diff changeset
   663
void
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5326
diff changeset
   664
zfs_xvattr_set(znode_t *zp, xvattr_t *xvap)
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5326
diff changeset
   665
{
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5326
diff changeset
   666
	xoptattr_t *xoap;
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5326
diff changeset
   667
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5326
diff changeset
   668
	xoap = xva_getxoptattr(xvap);
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5326
diff changeset
   669
	ASSERT(xoap);
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5326
diff changeset
   670
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5326
diff changeset
   671
	if (XVA_ISSET_REQ(xvap, XAT_CREATETIME)) {
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5326
diff changeset
   672
		ZFS_TIME_ENCODE(&xoap->xoa_createtime, zp->z_phys->zp_crtime);
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5326
diff changeset
   673
		XVA_SET_RTN(xvap, XAT_CREATETIME);
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5326
diff changeset
   674
	}
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5326
diff changeset
   675
	if (XVA_ISSET_REQ(xvap, XAT_READONLY)) {
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5326
diff changeset
   676
		ZFS_ATTR_SET(zp, ZFS_READONLY, xoap->xoa_readonly);
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5326
diff changeset
   677
		XVA_SET_RTN(xvap, XAT_READONLY);
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5326
diff changeset
   678
	}
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5326
diff changeset
   679
	if (XVA_ISSET_REQ(xvap, XAT_HIDDEN)) {
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5326
diff changeset
   680
		ZFS_ATTR_SET(zp, ZFS_HIDDEN, xoap->xoa_hidden);
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5326
diff changeset
   681
		XVA_SET_RTN(xvap, XAT_HIDDEN);
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5326
diff changeset
   682
	}
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5326
diff changeset
   683
	if (XVA_ISSET_REQ(xvap, XAT_SYSTEM)) {
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5326
diff changeset
   684
		ZFS_ATTR_SET(zp, ZFS_SYSTEM, xoap->xoa_system);
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5326
diff changeset
   685
		XVA_SET_RTN(xvap, XAT_SYSTEM);
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5326
diff changeset
   686
	}
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5326
diff changeset
   687
	if (XVA_ISSET_REQ(xvap, XAT_ARCHIVE)) {
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5326
diff changeset
   688
		ZFS_ATTR_SET(zp, ZFS_ARCHIVE, xoap->xoa_archive);
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5326
diff changeset
   689
		XVA_SET_RTN(xvap, XAT_ARCHIVE);
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5326
diff changeset
   690
	}
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5326
diff changeset
   691
	if (XVA_ISSET_REQ(xvap, XAT_IMMUTABLE)) {
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5326
diff changeset
   692
		ZFS_ATTR_SET(zp, ZFS_IMMUTABLE, xoap->xoa_immutable);
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5326
diff changeset
   693
		XVA_SET_RTN(xvap, XAT_IMMUTABLE);
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5326
diff changeset
   694
	}
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5326
diff changeset
   695
	if (XVA_ISSET_REQ(xvap, XAT_NOUNLINK)) {
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5326
diff changeset
   696
		ZFS_ATTR_SET(zp, ZFS_NOUNLINK, xoap->xoa_nounlink);
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5326
diff changeset
   697
		XVA_SET_RTN(xvap, XAT_NOUNLINK);
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5326
diff changeset
   698
	}
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5326
diff changeset
   699
	if (XVA_ISSET_REQ(xvap, XAT_APPENDONLY)) {
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5326
diff changeset
   700
		ZFS_ATTR_SET(zp, ZFS_APPENDONLY, xoap->xoa_appendonly);
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5326
diff changeset
   701
		XVA_SET_RTN(xvap, XAT_APPENDONLY);
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5326
diff changeset
   702
	}
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5326
diff changeset
   703
	if (XVA_ISSET_REQ(xvap, XAT_NODUMP)) {
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5326
diff changeset
   704
		ZFS_ATTR_SET(zp, ZFS_NODUMP, xoap->xoa_nodump);
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5326
diff changeset
   705
		XVA_SET_RTN(xvap, XAT_NODUMP);
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5326
diff changeset
   706
	}
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5326
diff changeset
   707
	if (XVA_ISSET_REQ(xvap, XAT_OPAQUE)) {
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5326
diff changeset
   708
		ZFS_ATTR_SET(zp, ZFS_OPAQUE, xoap->xoa_opaque);
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5326
diff changeset
   709
		XVA_SET_RTN(xvap, XAT_OPAQUE);
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5326
diff changeset
   710
	}
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5326
diff changeset
   711
	if (XVA_ISSET_REQ(xvap, XAT_AV_QUARANTINED)) {
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5326
diff changeset
   712
		ZFS_ATTR_SET(zp, ZFS_AV_QUARANTINED,
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5326
diff changeset
   713
		    xoap->xoa_av_quarantined);
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5326
diff changeset
   714
		XVA_SET_RTN(xvap, XAT_AV_QUARANTINED);
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5326
diff changeset
   715
	}
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5326
diff changeset
   716
	if (XVA_ISSET_REQ(xvap, XAT_AV_MODIFIED)) {
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5326
diff changeset
   717
		ZFS_ATTR_SET(zp, ZFS_AV_MODIFIED, xoap->xoa_av_modified);
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5326
diff changeset
   718
		XVA_SET_RTN(xvap, XAT_AV_MODIFIED);
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5326
diff changeset
   719
	}
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5326
diff changeset
   720
	if (XVA_ISSET_REQ(xvap, XAT_AV_SCANSTAMP)) {
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5326
diff changeset
   721
		(void) memcpy(zp->z_phys + 1, xoap->xoa_av_scanstamp,
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5326
diff changeset
   722
		    sizeof (xoap->xoa_av_scanstamp));
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5326
diff changeset
   723
		zp->z_phys->zp_flags |= ZFS_BONUS_SCANSTAMP;
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5326
diff changeset
   724
		XVA_SET_RTN(xvap, XAT_AV_SCANSTAMP);
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5326
diff changeset
   725
	}
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5326
diff changeset
   726
}
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5326
diff changeset
   727
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   728
int
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   729
zfs_zget(zfsvfs_t *zfsvfs, uint64_t obj_num, znode_t **zpp)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   730
{
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   731
	dmu_object_info_t doi;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   732
	dmu_buf_t	*db;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   733
	znode_t		*zp;
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1394
diff changeset
   734
	int err;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   735
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   736
	*zpp = NULL;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   737
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   738
	ZFS_OBJ_HOLD_ENTER(zfsvfs, obj_num);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   739
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1394
diff changeset
   740
	err = dmu_bonus_hold(zfsvfs->z_os, obj_num, NULL, &db);
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1394
diff changeset
   741
	if (err) {
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   742
		ZFS_OBJ_HOLD_EXIT(zfsvfs, obj_num);
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1394
diff changeset
   743
		return (err);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   744
	}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   745
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   746
	dmu_object_info_from_db(db, &doi);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   747
	if (doi.doi_bonus_type != DMU_OT_ZNODE ||
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   748
	    doi.doi_bonus_size < sizeof (znode_phys_t)) {
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1394
diff changeset
   749
		dmu_buf_rele(db, NULL);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   750
		ZFS_OBJ_HOLD_EXIT(zfsvfs, obj_num);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   751
		return (EINVAL);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   752
	}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   753
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   754
	ASSERT(db->db_object == obj_num);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   755
	ASSERT(db->db_offset == -1);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   756
	ASSERT(db->db_data != NULL);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   757
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   758
	zp = dmu_buf_get_user(db);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   759
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   760
	if (zp != NULL) {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   761
		mutex_enter(&zp->z_lock);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   762
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   763
		ASSERT3U(zp->z_id, ==, obj_num);
3461
c19b22f347d6 6514331 in-memory delete queue is not needed
ahrens
parents: 3444
diff changeset
   764
		if (zp->z_unlinked) {
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1394
diff changeset
   765
			dmu_buf_rele(db, NULL);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   766
			mutex_exit(&zp->z_lock);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   767
			ZFS_OBJ_HOLD_EXIT(zfsvfs, obj_num);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   768
			return (ENOENT);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   769
		} else if (zp->z_dbuf_held) {
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1394
diff changeset
   770
			dmu_buf_rele(db, NULL);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   771
		} else {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   772
			zp->z_dbuf_held = 1;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   773
			VFS_HOLD(zfsvfs->z_vfs);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   774
		}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   775
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1394
diff changeset
   776
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   777
		VN_HOLD(ZTOV(zp));
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   778
		mutex_exit(&zp->z_lock);
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1394
diff changeset
   779
		ZFS_OBJ_HOLD_EXIT(zfsvfs, obj_num);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   780
		*zpp = zp;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   781
		return (0);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   782
	}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   783
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   784
	/*
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   785
	 * Not found create new znode/vnode
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   786
	 */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   787
	zp = zfs_znode_alloc(zfsvfs, db, obj_num, doi.doi_data_block_size);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   788
	ASSERT3U(zp->z_id, ==, obj_num);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   789
	zfs_znode_dmu_init(zp);
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1394
diff changeset
   790
	ZFS_OBJ_HOLD_EXIT(zfsvfs, obj_num);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   791
	*zpp = zp;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   792
	return (0);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   793
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   794
5326
6752aa2bd5bc 6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents: 4831
diff changeset
   795
int
6752aa2bd5bc 6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents: 4831
diff changeset
   796
zfs_rezget(znode_t *zp)
6752aa2bd5bc 6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents: 4831
diff changeset
   797
{
6752aa2bd5bc 6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents: 4831
diff changeset
   798
	zfsvfs_t *zfsvfs = zp->z_zfsvfs;
6752aa2bd5bc 6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents: 4831
diff changeset
   799
	dmu_object_info_t doi;
6752aa2bd5bc 6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents: 4831
diff changeset
   800
	dmu_buf_t *db;
6752aa2bd5bc 6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents: 4831
diff changeset
   801
	uint64_t obj_num = zp->z_id;
6752aa2bd5bc 6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents: 4831
diff changeset
   802
	int err;
6752aa2bd5bc 6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents: 4831
diff changeset
   803
6752aa2bd5bc 6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents: 4831
diff changeset
   804
	ZFS_OBJ_HOLD_ENTER(zfsvfs, obj_num);
6752aa2bd5bc 6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents: 4831
diff changeset
   805
6752aa2bd5bc 6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents: 4831
diff changeset
   806
	err = dmu_bonus_hold(zfsvfs->z_os, obj_num, NULL, &db);
6752aa2bd5bc 6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents: 4831
diff changeset
   807
	if (err) {
6752aa2bd5bc 6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents: 4831
diff changeset
   808
		ZFS_OBJ_HOLD_EXIT(zfsvfs, obj_num);
6752aa2bd5bc 6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents: 4831
diff changeset
   809
		return (err);
6752aa2bd5bc 6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents: 4831
diff changeset
   810
	}
6752aa2bd5bc 6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents: 4831
diff changeset
   811
6752aa2bd5bc 6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents: 4831
diff changeset
   812
	dmu_object_info_from_db(db, &doi);
6752aa2bd5bc 6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents: 4831
diff changeset
   813
	if (doi.doi_bonus_type != DMU_OT_ZNODE ||
6752aa2bd5bc 6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents: 4831
diff changeset
   814
	    doi.doi_bonus_size < sizeof (znode_phys_t)) {
6752aa2bd5bc 6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents: 4831
diff changeset
   815
		dmu_buf_rele(db, NULL);
6752aa2bd5bc 6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents: 4831
diff changeset
   816
		ZFS_OBJ_HOLD_EXIT(zfsvfs, obj_num);
6752aa2bd5bc 6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents: 4831
diff changeset
   817
		return (EINVAL);
6752aa2bd5bc 6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents: 4831
diff changeset
   818
	}
6752aa2bd5bc 6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents: 4831
diff changeset
   819
6752aa2bd5bc 6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents: 4831
diff changeset
   820
	ASSERT(db->db_object == obj_num);
6752aa2bd5bc 6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents: 4831
diff changeset
   821
	ASSERT(db->db_offset == -1);
6752aa2bd5bc 6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents: 4831
diff changeset
   822
	ASSERT(db->db_data != NULL);
6752aa2bd5bc 6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents: 4831
diff changeset
   823
6752aa2bd5bc 6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents: 4831
diff changeset
   824
	if (((znode_phys_t *)db->db_data)->zp_gen != zp->z_gen) {
6752aa2bd5bc 6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents: 4831
diff changeset
   825
		dmu_buf_rele(db, NULL);
6752aa2bd5bc 6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents: 4831
diff changeset
   826
		ZFS_OBJ_HOLD_EXIT(zfsvfs, obj_num);
6752aa2bd5bc 6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents: 4831
diff changeset
   827
		return (EIO);
6752aa2bd5bc 6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents: 4831
diff changeset
   828
	}
6752aa2bd5bc 6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents: 4831
diff changeset
   829
6752aa2bd5bc 6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents: 4831
diff changeset
   830
	zp->z_dbuf = db;
6752aa2bd5bc 6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents: 4831
diff changeset
   831
	zp->z_phys = db->db_data;
6752aa2bd5bc 6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents: 4831
diff changeset
   832
	zfs_znode_dmu_init(zp);
6752aa2bd5bc 6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents: 4831
diff changeset
   833
	zp->z_unlinked = (zp->z_phys->zp_links == 0);
6752aa2bd5bc 6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents: 4831
diff changeset
   834
6752aa2bd5bc 6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents: 4831
diff changeset
   835
	/* release the hold from zfs_znode_dmu_init() */
6752aa2bd5bc 6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents: 4831
diff changeset
   836
	VFS_RELE(zfsvfs->z_vfs);
6752aa2bd5bc 6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents: 4831
diff changeset
   837
	ZFS_OBJ_HOLD_EXIT(zfsvfs, obj_num);
6752aa2bd5bc 6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents: 4831
diff changeset
   838
6752aa2bd5bc 6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents: 4831
diff changeset
   839
	return (0);
6752aa2bd5bc 6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents: 4831
diff changeset
   840
}
6752aa2bd5bc 6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents: 4831
diff changeset
   841
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   842
void
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   843
zfs_znode_delete(znode_t *zp, dmu_tx_t *tx)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   844
{
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   845
	zfsvfs_t *zfsvfs = zp->z_zfsvfs;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   846
	int error;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   847
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   848
	ZFS_OBJ_HOLD_ENTER(zfsvfs, zp->z_id);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   849
	if (zp->z_phys->zp_acl.z_acl_extern_obj) {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   850
		error = dmu_object_free(zfsvfs->z_os,
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   851
		    zp->z_phys->zp_acl.z_acl_extern_obj, tx);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   852
		ASSERT3U(error, ==, 0);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   853
	}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   854
	error = dmu_object_free(zfsvfs->z_os, zp->z_id, tx);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   855
	ASSERT3U(error, ==, 0);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   856
	zp->z_dbuf_held = 0;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   857
	ZFS_OBJ_HOLD_EXIT(zfsvfs, zp->z_id);
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1394
diff changeset
   858
	dmu_buf_rele(zp->z_dbuf, NULL);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   859
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   860
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   861
void
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   862
zfs_zinactive(znode_t *zp)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   863
{
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   864
	vnode_t	*vp = ZTOV(zp);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   865
	zfsvfs_t *zfsvfs = zp->z_zfsvfs;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   866
	uint64_t z_id = zp->z_id;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   867
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   868
	ASSERT(zp->z_dbuf_held && zp->z_phys);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   869
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   870
	/*
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   871
	 * Don't allow a zfs_zget() while were trying to release this znode
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   872
	 */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   873
	ZFS_OBJ_HOLD_ENTER(zfsvfs, z_id);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   874
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   875
	mutex_enter(&zp->z_lock);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   876
	mutex_enter(&vp->v_lock);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   877
	vp->v_count--;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   878
	if (vp->v_count > 0 || vn_has_cached_data(vp)) {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   879
		/*
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   880
		 * If the hold count is greater than zero, somebody has
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   881
		 * obtained a new reference on this znode while we were
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   882
		 * processing it here, so we are done.  If we still have
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   883
		 * mapped pages then we are also done, since we don't
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   884
		 * want to inactivate the znode until the pages get pushed.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   885
		 *
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   886
		 * XXX - if vn_has_cached_data(vp) is true, but count == 0,
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   887
		 * this seems like it would leave the znode hanging with
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   888
		 * no chance to go inactive...
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   889
		 */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   890
		mutex_exit(&vp->v_lock);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   891
		mutex_exit(&zp->z_lock);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   892
		ZFS_OBJ_HOLD_EXIT(zfsvfs, z_id);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   893
		return;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   894
	}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   895
	mutex_exit(&vp->v_lock);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   896
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   897
	/*
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   898
	 * If this was the last reference to a file with no links,
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   899
	 * remove the file from the file system.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   900
	 */
3461
c19b22f347d6 6514331 in-memory delete queue is not needed
ahrens
parents: 3444
diff changeset
   901
	if (zp->z_unlinked) {
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   902
		mutex_exit(&zp->z_lock);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   903
		ZFS_OBJ_HOLD_EXIT(zfsvfs, z_id);
3461
c19b22f347d6 6514331 in-memory delete queue is not needed
ahrens
parents: 3444
diff changeset
   904
		zfs_rmnode(zp);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   905
		VFS_RELE(zfsvfs->z_vfs);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   906
		return;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   907
	}
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1394
diff changeset
   908
	ASSERT(zp->z_phys);
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1394
diff changeset
   909
	ASSERT(zp->z_dbuf_held);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   910
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1394
diff changeset
   911
	zp->z_dbuf_held = 0;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   912
	mutex_exit(&zp->z_lock);
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1394
diff changeset
   913
	dmu_buf_rele(zp->z_dbuf, NULL);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   914
	ZFS_OBJ_HOLD_EXIT(zfsvfs, z_id);
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1394
diff changeset
   915
	VFS_RELE(zfsvfs->z_vfs);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   916
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   917
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   918
void
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   919
zfs_znode_free(znode_t *zp)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   920
{
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   921
	zfsvfs_t *zfsvfs = zp->z_zfsvfs;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   922
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   923
	mutex_enter(&zfsvfs->z_znodes_lock);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   924
	list_remove(&zfsvfs->z_all_znodes, zp);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   925
	mutex_exit(&zfsvfs->z_znodes_lock);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   926
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   927
	kmem_cache_free(znode_cache, zp);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   928
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   929
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   930
void
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   931
zfs_time_stamper_locked(znode_t *zp, uint_t flag, dmu_tx_t *tx)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   932
{
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   933
	timestruc_t	now;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   934
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   935
	ASSERT(MUTEX_HELD(&zp->z_lock));
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   936
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   937
	gethrestime(&now);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   938
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   939
	if (tx) {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   940
		dmu_buf_will_dirty(zp->z_dbuf, tx);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   941
		zp->z_atime_dirty = 0;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   942
		zp->z_seq++;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   943
	} else {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   944
		zp->z_atime_dirty = 1;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   945
	}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   946
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   947
	if (flag & AT_ATIME)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   948
		ZFS_TIME_ENCODE(&now, zp->z_phys->zp_atime);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   949
5331
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5326
diff changeset
   950
	if (flag & AT_MTIME) {
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   951
		ZFS_TIME_ENCODE(&now, zp->z_phys->zp_mtime);
5331
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5326
diff changeset
   952
		if (zp->z_zfsvfs->z_use_fuids)
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5326
diff changeset
   953
			zp->z_phys->zp_flags |= (ZFS_ARCHIVE | ZFS_AV_MODIFIED);
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5326
diff changeset
   954
	}
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   955
5331
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5326
diff changeset
   956
	if (flag & AT_CTIME) {
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   957
		ZFS_TIME_ENCODE(&now, zp->z_phys->zp_ctime);
5331
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5326
diff changeset
   958
		if (zp->z_zfsvfs->z_use_fuids)
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5326
diff changeset
   959
			zp->z_phys->zp_flags |= ZFS_ARCHIVE;
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5326
diff changeset
   960
	}
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   961
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   962
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   963
/*
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   964
 * Update the requested znode timestamps with the current time.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   965
 * If we are in a transaction, then go ahead and mark the znode
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   966
 * dirty in the transaction so the timestamps will go to disk.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   967
 * Otherwise, we will get pushed next time the znode is updated
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   968
 * in a transaction, or when this znode eventually goes inactive.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   969
 *
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   970
 * Why is this OK?
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   971
 *  1 - Only the ACCESS time is ever updated outside of a transaction.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   972
 *  2 - Multiple consecutive updates will be collapsed into a single
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   973
 *	znode update by the transaction grouping semantics of the DMU.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   974
 */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   975
void
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   976
zfs_time_stamper(znode_t *zp, uint_t flag, dmu_tx_t *tx)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   977
{
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   978
	mutex_enter(&zp->z_lock);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   979
	zfs_time_stamper_locked(zp, flag, tx);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   980
	mutex_exit(&zp->z_lock);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   981
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   982
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   983
/*
1669
3521dbbcb2e8 6343608 ZFS file range locking
perrin
parents: 1544
diff changeset
   984
 * Grow the block size for a file.
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   985
 *
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   986
 *	IN:	zp	- znode of file to free data in.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   987
 *		size	- requested block size
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   988
 *		tx	- open transaction.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   989
 *
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   990
 * NOTE: this function assumes that the znode is write locked.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   991
 */
1669
3521dbbcb2e8 6343608 ZFS file range locking
perrin
parents: 1544
diff changeset
   992
void
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   993
zfs_grow_blocksize(znode_t *zp, uint64_t size, dmu_tx_t *tx)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   994
{
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   995
	int		error;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   996
	u_longlong_t	dummy;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   997
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   998
	if (size <= zp->z_blksz)
1669
3521dbbcb2e8 6343608 ZFS file range locking
perrin
parents: 1544
diff changeset
   999
		return;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1000
	/*
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1001
	 * If the file size is already greater than the current blocksize,
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1002
	 * we will not grow.  If there is more than one block in a file,
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1003
	 * the blocksize cannot change.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1004
	 */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1005
	if (zp->z_blksz && zp->z_phys->zp_size > zp->z_blksz)
1669
3521dbbcb2e8 6343608 ZFS file range locking
perrin
parents: 1544
diff changeset
  1006
		return;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1007
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1008
	error = dmu_object_set_blocksize(zp->z_zfsvfs->z_os, zp->z_id,
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1009
	    size, 0, tx);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1010
	if (error == ENOTSUP)
1669
3521dbbcb2e8 6343608 ZFS file range locking
perrin
parents: 1544
diff changeset
  1011
		return;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1012
	ASSERT3U(error, ==, 0);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1013
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1014
	/* What blocksize did we actually get? */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1015
	dmu_object_size_from_db(zp->z_dbuf, &zp->z_blksz, &dummy);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1016
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1017
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1018
/*
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1019
 * This is a dummy interface used when pvn_vplist_dirty() should *not*
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1020
 * be calling back into the fs for a putpage().  E.g.: when truncating
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1021
 * a file, the pages being "thrown away* don't need to be written out.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1022
 */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1023
/* ARGSUSED */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1024
static int
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1025
zfs_no_putpage(vnode_t *vp, page_t *pp, u_offset_t *offp, size_t *lenp,
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1026
    int flags, cred_t *cr)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1027
{
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1028
	ASSERT(0);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1029
	return (0);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1030
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1031
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1032
/*
1669
3521dbbcb2e8 6343608 ZFS file range locking
perrin
parents: 1544
diff changeset
  1033
 * Free space in a file.
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1034
 *
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1035
 *	IN:	zp	- znode of file to free data in.
1878
c22df0f5603f 6413573 deadlock between fsflush() and zfs_create()
maybee
parents: 1816
diff changeset
  1036
 *		off	- start of section to free.
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1037
 *		len	- length of section to free (0 => to EOF).
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1038
 *		flag	- current file open mode flags.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1039
 *
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1040
 * 	RETURN:	0 if success
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1041
 *		error code if failure
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1042
 */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1043
int
1878
c22df0f5603f 6413573 deadlock between fsflush() and zfs_create()
maybee
parents: 1816
diff changeset
  1044
zfs_freesp(znode_t *zp, uint64_t off, uint64_t len, int flag, boolean_t log)
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1045
{
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1046
	vnode_t *vp = ZTOV(zp);
1878
c22df0f5603f 6413573 deadlock between fsflush() and zfs_create()
maybee
parents: 1816
diff changeset
  1047
	dmu_tx_t *tx;
c22df0f5603f 6413573 deadlock between fsflush() and zfs_create()
maybee
parents: 1816
diff changeset
  1048
	zfsvfs_t *zfsvfs = zp->z_zfsvfs;
c22df0f5603f 6413573 deadlock between fsflush() and zfs_create()
maybee
parents: 1816
diff changeset
  1049
	zilog_t *zilog = zfsvfs->z_log;
c22df0f5603f 6413573 deadlock between fsflush() and zfs_create()
maybee
parents: 1816
diff changeset
  1050
	rl_t *rl;
c22df0f5603f 6413573 deadlock between fsflush() and zfs_create()
maybee
parents: 1816
diff changeset
  1051
	uint64_t end = off + len;
c22df0f5603f 6413573 deadlock between fsflush() and zfs_create()
maybee
parents: 1816
diff changeset
  1052
	uint64_t size, new_blksz;
5331
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5326
diff changeset
  1053
	uint64_t pflags = zp->z_phys->zp_flags;
1669
3521dbbcb2e8 6343608 ZFS file range locking
perrin
parents: 1544
diff changeset
  1054
	int error;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1055
5331
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5326
diff changeset
  1056
	if ((pflags & (ZFS_IMMUTABLE|ZFS_READONLY)) ||
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5326
diff changeset
  1057
	    off < zp->z_phys->zp_size && (pflags & ZFS_APPENDONLY))
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5326
diff changeset
  1058
		return (EPERM);
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5326
diff changeset
  1059
1394
e8d500b79ced 6381600 tc_open.021 in mstc testsuite is returning -1 when run on a zfs
marks
parents: 869
diff changeset
  1060
	if (ZTOV(zp)->v_type == VFIFO)
e8d500b79ced 6381600 tc_open.021 in mstc testsuite is returning -1 when run on a zfs
marks
parents: 869
diff changeset
  1061
		return (0);
e8d500b79ced 6381600 tc_open.021 in mstc testsuite is returning -1 when run on a zfs
marks
parents: 869
diff changeset
  1062
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1063
	/*
1878
c22df0f5603f 6413573 deadlock between fsflush() and zfs_create()
maybee
parents: 1816
diff changeset
  1064
	 * If we will change zp_size then lock the whole file,
c22df0f5603f 6413573 deadlock between fsflush() and zfs_create()
maybee
parents: 1816
diff changeset
  1065
	 * otherwise just lock the range being freed.
c22df0f5603f 6413573 deadlock between fsflush() and zfs_create()
maybee
parents: 1816
diff changeset
  1066
	 */
c22df0f5603f 6413573 deadlock between fsflush() and zfs_create()
maybee
parents: 1816
diff changeset
  1067
	if (len == 0 || off + len > zp->z_phys->zp_size) {
c22df0f5603f 6413573 deadlock between fsflush() and zfs_create()
maybee
parents: 1816
diff changeset
  1068
		rl = zfs_range_lock(zp, 0, UINT64_MAX, RL_WRITER);
c22df0f5603f 6413573 deadlock between fsflush() and zfs_create()
maybee
parents: 1816
diff changeset
  1069
	} else {
c22df0f5603f 6413573 deadlock between fsflush() and zfs_create()
maybee
parents: 1816
diff changeset
  1070
		rl = zfs_range_lock(zp, off, len, RL_WRITER);
c22df0f5603f 6413573 deadlock between fsflush() and zfs_create()
maybee
parents: 1816
diff changeset
  1071
		/* recheck, in case zp_size changed */
c22df0f5603f 6413573 deadlock between fsflush() and zfs_create()
maybee
parents: 1816
diff changeset
  1072
		if (off + len > zp->z_phys->zp_size) {
c22df0f5603f 6413573 deadlock between fsflush() and zfs_create()
maybee
parents: 1816
diff changeset
  1073
			/* lost race: file size changed, lock whole file */
2237
45affe88ed99 6416482 filebench oltp workload hangs in zfs
maybee
parents: 2113
diff changeset
  1074
			zfs_range_unlock(rl);
1878
c22df0f5603f 6413573 deadlock between fsflush() and zfs_create()
maybee
parents: 1816
diff changeset
  1075
			rl = zfs_range_lock(zp, 0, UINT64_MAX, RL_WRITER);
c22df0f5603f 6413573 deadlock between fsflush() and zfs_create()
maybee
parents: 1816
diff changeset
  1076
		}
c22df0f5603f 6413573 deadlock between fsflush() and zfs_create()
maybee
parents: 1816
diff changeset
  1077
	}
c22df0f5603f 6413573 deadlock between fsflush() and zfs_create()
maybee
parents: 1816
diff changeset
  1078
c22df0f5603f 6413573 deadlock between fsflush() and zfs_create()
maybee
parents: 1816
diff changeset
  1079
	/*
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1080
	 * Nothing to do if file already at desired length.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1081
	 */
1878
c22df0f5603f 6413573 deadlock between fsflush() and zfs_create()
maybee
parents: 1816
diff changeset
  1082
	size = zp->z_phys->zp_size;
4144
068f395736ad 6465105 ZFS does not update timestamps upon the creat() of an existing file
peteh
parents: 4105
diff changeset
  1083
	if (len == 0 && size == off && off != 0) {
2237
45affe88ed99 6416482 filebench oltp workload hangs in zfs
maybee
parents: 2113
diff changeset
  1084
		zfs_range_unlock(rl);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1085
		return (0);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1086
	}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1087
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1088
	/*
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1089
	 * Check for any locks in the region to be freed.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1090
	 */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1091
	if (MANDLOCK(vp, (mode_t)zp->z_phys->zp_mode)) {
1878
c22df0f5603f 6413573 deadlock between fsflush() and zfs_create()
maybee
parents: 1816
diff changeset
  1092
		uint64_t start = off;
c22df0f5603f 6413573 deadlock between fsflush() and zfs_create()
maybee
parents: 1816
diff changeset
  1093
		uint64_t extent = len;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1094
1878
c22df0f5603f 6413573 deadlock between fsflush() and zfs_create()
maybee
parents: 1816
diff changeset
  1095
		if (off > size) {
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1096
			start = size;
1878
c22df0f5603f 6413573 deadlock between fsflush() and zfs_create()
maybee
parents: 1816
diff changeset
  1097
			extent += off - size;
c22df0f5603f 6413573 deadlock between fsflush() and zfs_create()
maybee
parents: 1816
diff changeset
  1098
		} else if (len == 0) {
c22df0f5603f 6413573 deadlock between fsflush() and zfs_create()
maybee
parents: 1816
diff changeset
  1099
			extent = size - off;
c22df0f5603f 6413573 deadlock between fsflush() and zfs_create()
maybee
parents: 1816
diff changeset
  1100
		}
c22df0f5603f 6413573 deadlock between fsflush() and zfs_create()
maybee
parents: 1816
diff changeset
  1101
		if (error = chklock(vp, FWRITE, start, extent, flag, NULL)) {
2237
45affe88ed99 6416482 filebench oltp workload hangs in zfs
maybee
parents: 2113
diff changeset
  1102
			zfs_range_unlock(rl);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1103
			return (error);
1878
c22df0f5603f 6413573 deadlock between fsflush() and zfs_create()
maybee
parents: 1816
diff changeset
  1104
		}
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1105
	}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1106
1878
c22df0f5603f 6413573 deadlock between fsflush() and zfs_create()
maybee
parents: 1816
diff changeset
  1107
	tx = dmu_tx_create(zfsvfs->z_os);
c22df0f5603f 6413573 deadlock between fsflush() and zfs_create()
maybee
parents: 1816
diff changeset
  1108
	dmu_tx_hold_bonus(tx, zp->z_id);
c22df0f5603f 6413573 deadlock between fsflush() and zfs_create()
maybee
parents: 1816
diff changeset
  1109
	new_blksz = 0;
c22df0f5603f 6413573 deadlock between fsflush() and zfs_create()
maybee
parents: 1816
diff changeset
  1110
	if (end > size &&
c22df0f5603f 6413573 deadlock between fsflush() and zfs_create()
maybee
parents: 1816
diff changeset
  1111
	    (!ISP2(zp->z_blksz) || zp->z_blksz < zfsvfs->z_max_blksz)) {
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1112
		/*
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1113
		 * We are growing the file past the current block size.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1114
		 */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1115
		if (zp->z_blksz > zp->z_zfsvfs->z_max_blksz) {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1116
			ASSERT(!ISP2(zp->z_blksz));
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1117
			new_blksz = MIN(end, SPA_MAXBLOCKSIZE);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1118
		} else {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1119
			new_blksz = MIN(end, zp->z_zfsvfs->z_max_blksz);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1120
		}
1878
c22df0f5603f 6413573 deadlock between fsflush() and zfs_create()
maybee
parents: 1816
diff changeset
  1121
		dmu_tx_hold_write(tx, zp->z_id, 0, MIN(end, new_blksz));
c22df0f5603f 6413573 deadlock between fsflush() and zfs_create()
maybee
parents: 1816
diff changeset
  1122
	} else if (off < size) {
c22df0f5603f 6413573 deadlock between fsflush() and zfs_create()
maybee
parents: 1816
diff changeset
  1123
		/*
c22df0f5603f 6413573 deadlock between fsflush() and zfs_create()
maybee
parents: 1816
diff changeset
  1124
		 * If len == 0, we are truncating the file.
c22df0f5603f 6413573 deadlock between fsflush() and zfs_create()
maybee
parents: 1816
diff changeset
  1125
		 */
c22df0f5603f 6413573 deadlock between fsflush() and zfs_create()
maybee
parents: 1816
diff changeset
  1126
		dmu_tx_hold_free(tx, zp->z_id, off, len ? len : DMU_OBJECT_END);
c22df0f5603f 6413573 deadlock between fsflush() and zfs_create()
maybee
parents: 1816
diff changeset
  1127
	}
c22df0f5603f 6413573 deadlock between fsflush() and zfs_create()
maybee
parents: 1816
diff changeset
  1128
c22df0f5603f 6413573 deadlock between fsflush() and zfs_create()
maybee
parents: 1816
diff changeset
  1129
	error = dmu_tx_assign(tx, zfsvfs->z_assign);
c22df0f5603f 6413573 deadlock between fsflush() and zfs_create()
maybee
parents: 1816
diff changeset
  1130
	if (error) {
2113
0510bb40c993 6430121 3-way deadlock involving tc_lock within zfs
ahrens
parents: 1936
diff changeset
  1131
		if (error == ERESTART && zfsvfs->z_assign == TXG_NOWAIT)
0510bb40c993 6430121 3-way deadlock involving tc_lock within zfs
ahrens
parents: 1936
diff changeset
  1132
			dmu_tx_wait(tx);
1878
c22df0f5603f 6413573 deadlock between fsflush() and zfs_create()
maybee
parents: 1816
diff changeset
  1133
		dmu_tx_abort(tx);
2237
45affe88ed99 6416482 filebench oltp workload hangs in zfs
maybee
parents: 2113
diff changeset
  1134
		zfs_range_unlock(rl);
1878
c22df0f5603f 6413573 deadlock between fsflush() and zfs_create()
maybee
parents: 1816
diff changeset
  1135
		return (error);
c22df0f5603f 6413573 deadlock between fsflush() and zfs_create()
maybee
parents: 1816
diff changeset
  1136
	}
c22df0f5603f 6413573 deadlock between fsflush() and zfs_create()
maybee
parents: 1816
diff changeset
  1137
c22df0f5603f 6413573 deadlock between fsflush() and zfs_create()
maybee
parents: 1816
diff changeset
  1138
	if (new_blksz)
1669
3521dbbcb2e8 6343608 ZFS file range locking
perrin
parents: 1544
diff changeset
  1139
		zfs_grow_blocksize(zp, new_blksz, tx);
1878
c22df0f5603f 6413573 deadlock between fsflush() and zfs_create()
maybee
parents: 1816
diff changeset
  1140
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1141
	if (end > size || len == 0)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1142
		zp->z_phys->zp_size = end;
1878
c22df0f5603f 6413573 deadlock between fsflush() and zfs_create()
maybee
parents: 1816
diff changeset
  1143
c22df0f5603f 6413573 deadlock between fsflush() and zfs_create()
maybee
parents: 1816
diff changeset
  1144
	if (off < size) {
c22df0f5603f 6413573 deadlock between fsflush() and zfs_create()
maybee
parents: 1816
diff changeset
  1145
		objset_t *os = zfsvfs->z_os;
1936
b6ded90e4d4b 6398177 zfs: poor nightly build performance in 32-bit mode (high disk activity)
maybee
parents: 1878
diff changeset
  1146
		uint64_t rlen = len;
1878
c22df0f5603f 6413573 deadlock between fsflush() and zfs_create()
maybee
parents: 1816
diff changeset
  1147
c22df0f5603f 6413573 deadlock between fsflush() and zfs_create()
maybee
parents: 1816
diff changeset
  1148
		if (len == 0)
1936
b6ded90e4d4b 6398177 zfs: poor nightly build performance in 32-bit mode (high disk activity)
maybee
parents: 1878
diff changeset
  1149
			rlen = -1;
1878
c22df0f5603f 6413573 deadlock between fsflush() and zfs_create()
maybee
parents: 1816
diff changeset
  1150
		else if (end > size)
1936
b6ded90e4d4b 6398177 zfs: poor nightly build performance in 32-bit mode (high disk activity)
maybee
parents: 1878
diff changeset
  1151
			rlen = size - off;
b6ded90e4d4b 6398177 zfs: poor nightly build performance in 32-bit mode (high disk activity)
maybee
parents: 1878
diff changeset
  1152
		VERIFY(0 == dmu_free_range(os, zp->z_id, off, rlen, tx));
1878
c22df0f5603f 6413573 deadlock between fsflush() and zfs_create()
maybee
parents: 1816
diff changeset
  1153
	}
c22df0f5603f 6413573 deadlock between fsflush() and zfs_create()
maybee
parents: 1816
diff changeset
  1154
c22df0f5603f 6413573 deadlock between fsflush() and zfs_create()
maybee
parents: 1816
diff changeset
  1155
	if (log) {
c22df0f5603f 6413573 deadlock between fsflush() and zfs_create()
maybee
parents: 1816
diff changeset
  1156
		zfs_time_stamper(zp, CONTENT_MODIFIED, tx);
2638
4f583dfeae92 6413510 zfs: writing to ZFS filesystem slows down fsync() on other files in the same FS
perrin
parents: 2597
diff changeset
  1157
		zfs_log_truncate(zilog, tx, TX_TRUNCATE, zp, off, len);
1878
c22df0f5603f 6413573 deadlock between fsflush() and zfs_create()
maybee
parents: 1816
diff changeset
  1158
	}
c22df0f5603f 6413573 deadlock between fsflush() and zfs_create()
maybee
parents: 1816
diff changeset
  1159
2237
45affe88ed99 6416482 filebench oltp workload hangs in zfs
maybee
parents: 2113
diff changeset
  1160
	zfs_range_unlock(rl);
1878
c22df0f5603f 6413573 deadlock between fsflush() and zfs_create()
maybee
parents: 1816
diff changeset
  1161
c22df0f5603f 6413573 deadlock between fsflush() and zfs_create()
maybee
parents: 1816
diff changeset
  1162
	dmu_tx_commit(tx);
c22df0f5603f 6413573 deadlock between fsflush() and zfs_create()
maybee
parents: 1816
diff changeset
  1163
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1164
	/*
1878
c22df0f5603f 6413573 deadlock between fsflush() and zfs_create()
maybee
parents: 1816
diff changeset
  1165
	 * Clear any mapped pages in the truncated region.  This has to
c22df0f5603f 6413573 deadlock between fsflush() and zfs_create()
maybee
parents: 1816
diff changeset
  1166
	 * happen outside of the transaction to avoid the possibility of
c22df0f5603f 6413573 deadlock between fsflush() and zfs_create()
maybee
parents: 1816
diff changeset
  1167
	 * a deadlock with someone trying to push a page that we are
c22df0f5603f 6413573 deadlock between fsflush() and zfs_create()
maybee
parents: 1816
diff changeset
  1168
	 * about to invalidate.
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1169
	 */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1170
	rw_enter(&zp->z_map_lock, RW_WRITER);
1878
c22df0f5603f 6413573 deadlock between fsflush() and zfs_create()
maybee
parents: 1816
diff changeset
  1171
	if (off < size && vn_has_cached_data(vp)) {
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1172
		page_t *pp;
1878
c22df0f5603f 6413573 deadlock between fsflush() and zfs_create()
maybee
parents: 1816
diff changeset
  1173
		uint64_t start = off & PAGEMASK;
c22df0f5603f 6413573 deadlock between fsflush() and zfs_create()
maybee
parents: 1816
diff changeset
  1174
		int poff = off & PAGEOFFSET;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1175
1878
c22df0f5603f 6413573 deadlock between fsflush() and zfs_create()
maybee
parents: 1816
diff changeset
  1176
		if (poff != 0 && (pp = page_lookup(vp, start, SE_SHARED))) {
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1177
			/*
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1178
			 * We need to zero a partial page.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1179
			 */
1878
c22df0f5603f 6413573 deadlock between fsflush() and zfs_create()
maybee
parents: 1816
diff changeset
  1180
			pagezero(pp, poff, PAGESIZE - poff);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1181
			start += PAGESIZE;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1182
			page_unlock(pp);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1183
		}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1184
		error = pvn_vplist_dirty(vp, start, zfs_no_putpage,
1878
c22df0f5603f 6413573 deadlock between fsflush() and zfs_create()
maybee
parents: 1816
diff changeset
  1185
		    B_INVAL | B_TRUNC, NULL);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1186
		ASSERT(error == 0);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1187
	}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1188
	rw_exit(&zp->z_map_lock);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1189
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1190
	return (0);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1191
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1192
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1193
void
5331
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5326
diff changeset
  1194
zfs_create_fs(objset_t *os, cred_t *cr, uint64_t version,
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5326
diff changeset
  1195
    int norm, dmu_tx_t *tx)
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1196
{
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1197
	zfsvfs_t	zfsvfs;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1198
	uint64_t	moid, doid, roid = 0;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1199
	int		error;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1200
	znode_t		*rootzp = NULL;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1201
	vnode_t		*vp;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1202
	vattr_t		vattr;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1203
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1204
	/*
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1205
	 * First attempt to create master node.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1206
	 */
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1394
diff changeset
  1207
	/*
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1394
diff changeset
  1208
	 * In an empty objset, there are no blocks to read and thus
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1394
diff changeset
  1209
	 * there can be no i/o errors (which we assert below).
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1394
diff changeset
  1210
	 */
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1211
	moid = MASTER_NODE_OBJ;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1212
	error = zap_create_claim(os, moid, DMU_OT_MASTER_NODE,
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1213
	    DMU_OT_NONE, 0, tx);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1214
	ASSERT(error == 0);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1215
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1216
	/*
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1217
	 * Set starting attributes.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1218
	 */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1219
4577
ed36b0e652bc PSARC/2007/328 zfs upgrade
ahrens
parents: 4543
diff changeset
  1220
	error = zap_update(os, moid, ZPL_VERSION_STR, 8, 1, &version, tx);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1221
	ASSERT(error == 0);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1222
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1223
	/*
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1224
	 * Create a delete queue.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1225
	 */
3461
c19b22f347d6 6514331 in-memory delete queue is not needed
ahrens
parents: 3444
diff changeset
  1226
	doid = zap_create(os, DMU_OT_UNLINKED_SET, DMU_OT_NONE, 0, tx);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1227
3461
c19b22f347d6 6514331 in-memory delete queue is not needed
ahrens
parents: 3444
diff changeset
  1228
	error = zap_add(os, moid, ZFS_UNLINKED_SET, 8, 1, &doid, tx);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1229
	ASSERT(error == 0);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1230
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1231
	/*
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1232
	 * Create root znode.  Create minimal znode/vnode/zfsvfs
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1233
	 * to allow zfs_mknode to work.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1234
	 */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1235
	vattr.va_mask = AT_MODE|AT_UID|AT_GID|AT_TYPE;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1236
	vattr.va_type = VDIR;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1237
	vattr.va_mode = S_IFDIR|0755;
4543
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4144
diff changeset
  1238
	vattr.va_uid = crgetuid(cr);
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4144
diff changeset
  1239
	vattr.va_gid = crgetgid(cr);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1240
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1241
	rootzp = kmem_cache_alloc(znode_cache, KM_SLEEP);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1242
	rootzp->z_zfsvfs = &zfsvfs;
3461
c19b22f347d6 6514331 in-memory delete queue is not needed
ahrens
parents: 3444
diff changeset
  1243
	rootzp->z_unlinked = 0;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1244
	rootzp->z_atime_dirty = 0;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1245
	rootzp->z_dbuf_held = 0;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1246
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1247
	vp = ZTOV(rootzp);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1248
	vn_reinit(vp);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1249
	vp->v_type = VDIR;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1250
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1251
	bzero(&zfsvfs, sizeof (zfsvfs_t));
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1252
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1253
	zfsvfs.z_os = os;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1254
	zfsvfs.z_assign = TXG_NOWAIT;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1255
	zfsvfs.z_parent = &zfsvfs;
5331
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5326
diff changeset
  1256
	zfsvfs.z_version = version;
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5326
diff changeset
  1257
	zfsvfs.z_use_fuids = USE_FUIDS(version, os);
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5326
diff changeset
  1258
	zfsvfs.z_norm = norm;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1259
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1260
	mutex_init(&zfsvfs.z_znodes_lock, NULL, MUTEX_DEFAULT, NULL);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1261
	list_create(&zfsvfs.z_all_znodes, sizeof (znode_t),
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1262
	    offsetof(znode_t, z_link_node));
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1263
5331
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5326
diff changeset
  1264
	zfs_mknode(rootzp, &vattr, &roid, tx, cr, IS_ROOT_NODE,
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5326
diff changeset
  1265
	    NULL, 0, NULL, NULL);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1266
	ASSERT3U(rootzp->z_id, ==, roid);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1267
	error = zap_add(os, moid, ZFS_ROOT_OBJ, 8, 1, &roid, tx);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1268
	ASSERT(error == 0);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1269
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1270
	ZTOV(rootzp)->v_count = 0;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1271
	kmem_cache_free(znode_cache, rootzp);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1272
}
5331
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5326
diff changeset
  1273
3444
dc160a70a50d 6410433 'zpool status -v' would be more useful with filenames
ek110237
parents: 3063
diff changeset
  1274
#endif /* _KERNEL */
dc160a70a50d 6410433 'zpool status -v' would be more useful with filenames
ek110237
parents: 3063
diff changeset
  1275
/*
dc160a70a50d 6410433 'zpool status -v' would be more useful with filenames
ek110237
parents: 3063
diff changeset
  1276
 * Given an object number, return its parent object number and whether
dc160a70a50d 6410433 'zpool status -v' would be more useful with filenames
ek110237
parents: 3063
diff changeset
  1277
 * or not the object is an extended attribute directory.
dc160a70a50d 6410433 'zpool status -v' would be more useful with filenames
ek110237
parents: 3063
diff changeset
  1278
 */
dc160a70a50d 6410433 'zpool status -v' would be more useful with filenames
ek110237
parents: 3063
diff changeset
  1279
static int
dc160a70a50d 6410433 'zpool status -v' would be more useful with filenames
ek110237
parents: 3063
diff changeset
  1280
zfs_obj_to_pobj(objset_t *osp, uint64_t obj, uint64_t *pobjp, int *is_xattrdir)
dc160a70a50d 6410433 'zpool status -v' would be more useful with filenames
ek110237
parents: 3063
diff changeset
  1281
{
dc160a70a50d 6410433 'zpool status -v' would be more useful with filenames
ek110237
parents: 3063
diff changeset
  1282
	dmu_buf_t *db;
dc160a70a50d 6410433 'zpool status -v' would be more useful with filenames
ek110237
parents: 3063
diff changeset
  1283
	dmu_object_info_t doi;
dc160a70a50d 6410433 'zpool status -v' would be more useful with filenames
ek110237
parents: 3063
diff changeset
  1284
	znode_phys_t *zp;
dc160a70a50d 6410433 'zpool status -v' would be more useful with filenames
ek110237
parents: 3063
diff changeset
  1285
	int error;
dc160a70a50d 6410433 'zpool status -v' would be more useful with filenames
ek110237
parents: 3063
diff changeset
  1286
dc160a70a50d 6410433 'zpool status -v' would be more useful with filenames
ek110237
parents: 3063
diff changeset
  1287
	if ((error = dmu_bonus_hold(osp, obj, FTAG, &db)) != 0)
dc160a70a50d 6410433 'zpool status -v' would be more useful with filenames
ek110237
parents: 3063
diff changeset
  1288
		return (error);
dc160a70a50d 6410433 'zpool status -v' would be more useful with filenames
ek110237
parents: 3063
diff changeset
  1289
dc160a70a50d 6410433 'zpool status -v' would be more useful with filenames
ek110237
parents: 3063
diff changeset
  1290
	dmu_object_info_from_db(db, &doi);
dc160a70a50d 6410433 'zpool status -v' would be more useful with filenames
ek110237
parents: 3063
diff changeset
  1291
	if (doi.doi_bonus_type != DMU_OT_ZNODE ||
dc160a70a50d 6410433 'zpool status -v' would be more useful with filenames
ek110237
parents: 3063
diff changeset
  1292
	    doi.doi_bonus_size < sizeof (znode_phys_t)) {
dc160a70a50d 6410433 'zpool status -v' would be more useful with filenames
ek110237
parents: 3063
diff changeset
  1293
		dmu_buf_rele(db, FTAG);
dc160a70a50d 6410433 'zpool status -v' would be more useful with filenames
ek110237
parents: 3063
diff changeset
  1294
		return (EINVAL);
dc160a70a50d 6410433 'zpool status -v' would be more useful with filenames
ek110237
parents: 3063
diff changeset
  1295
	}
dc160a70a50d 6410433 'zpool status -v' would be more useful with filenames
ek110237
parents: 3063
diff changeset
  1296
dc160a70a50d 6410433 'zpool status -v' would be more useful with filenames
ek110237
parents: 3063
diff changeset
  1297
	zp = db->db_data;
dc160a70a50d 6410433 'zpool status -v' would be more useful with filenames
ek110237
parents: 3063
diff changeset
  1298
	*pobjp = zp->zp_parent;
dc160a70a50d 6410433 'zpool status -v' would be more useful with filenames
ek110237
parents: 3063
diff changeset
  1299
	*is_xattrdir = ((zp->zp_flags & ZFS_XATTR) != 0) &&
dc160a70a50d 6410433 'zpool status -v' would be more useful with filenames
ek110237
parents: 3063
diff changeset
  1300
	    S_ISDIR(zp->zp_mode);
dc160a70a50d 6410433 'zpool status -v' would be more useful with filenames
ek110237
parents: 3063
diff changeset
  1301
	dmu_buf_rele(db, FTAG);
dc160a70a50d 6410433 'zpool status -v' would be more useful with filenames
ek110237
parents: 3063
diff changeset
  1302
dc160a70a50d 6410433 'zpool status -v' would be more useful with filenames
ek110237
parents: 3063
diff changeset
  1303
	return (0);
dc160a70a50d 6410433 'zpool status -v' would be more useful with filenames
ek110237
parents: 3063
diff changeset
  1304
}
dc160a70a50d 6410433 'zpool status -v' would be more useful with filenames
ek110237
parents: 3063
diff changeset
  1305
dc160a70a50d 6410433 'zpool status -v' would be more useful with filenames
ek110237
parents: 3063
diff changeset
  1306
int
dc160a70a50d 6410433 'zpool status -v' would be more useful with filenames
ek110237
parents: 3063
diff changeset
  1307
zfs_obj_to_path(objset_t *osp, uint64_t obj, char *buf, int len)
dc160a70a50d 6410433 'zpool status -v' would be more useful with filenames
ek110237
parents: 3063
diff changeset
  1308
{
dc160a70a50d 6410433 'zpool status -v' would be more useful with filenames
ek110237
parents: 3063
diff changeset
  1309
	char *path = buf + len - 1;
dc160a70a50d 6410433 'zpool status -v' would be more useful with filenames
ek110237
parents: 3063
diff changeset
  1310
	int error;
dc160a70a50d 6410433 'zpool status -v' would be more useful with filenames
ek110237
parents: 3063
diff changeset
  1311
dc160a70a50d 6410433 'zpool status -v' would be more useful with filenames
ek110237
parents: 3063
diff changeset
  1312
	*path = '\0';
dc160a70a50d 6410433 'zpool status -v' would be more useful with filenames
ek110237
parents: 3063
diff changeset
  1313
dc160a70a50d 6410433 'zpool status -v' would be more useful with filenames
ek110237
parents: 3063
diff changeset
  1314
	for (;;) {
dc160a70a50d 6410433 'zpool status -v' would be more useful with filenames
ek110237
parents: 3063
diff changeset
  1315
		uint64_t pobj;
dc160a70a50d 6410433 'zpool status -v' would be more useful with filenames
ek110237
parents: 3063
diff changeset
  1316
		char component[MAXNAMELEN + 2];
dc160a70a50d 6410433 'zpool status -v' would be more useful with filenames
ek110237
parents: 3063
diff changeset
  1317
		size_t complen;
dc160a70a50d 6410433 'zpool status -v' would be more useful with filenames
ek110237
parents: 3063
diff changeset
  1318
		int is_xattrdir;
dc160a70a50d 6410433 'zpool status -v' would be more useful with filenames
ek110237
parents: 3063
diff changeset
  1319
dc160a70a50d 6410433 'zpool status -v' would be more useful with filenames
ek110237
parents: 3063
diff changeset
  1320
		if ((error = zfs_obj_to_pobj(osp, obj, &pobj,
dc160a70a50d 6410433 'zpool status -v' would be more useful with filenames
ek110237
parents: 3063
diff changeset
  1321
		    &is_xattrdir)) != 0)
dc160a70a50d 6410433 'zpool status -v' would be more useful with filenames
ek110237
parents: 3063
diff changeset
  1322
			break;
dc160a70a50d 6410433 'zpool status -v' would be more useful with filenames
ek110237
parents: 3063
diff changeset
  1323
dc160a70a50d 6410433 'zpool status -v' would be more useful with filenames
ek110237
parents: 3063
diff changeset
  1324
		if (pobj == obj) {
dc160a70a50d 6410433 'zpool status -v' would be more useful with filenames
ek110237
parents: 3063
diff changeset
  1325
			if (path[0] != '/')
dc160a70a50d 6410433 'zpool status -v' would be more useful with filenames
ek110237
parents: 3063
diff changeset
  1326
				*--path = '/';
dc160a70a50d 6410433 'zpool status -v' would be more useful with filenames
ek110237
parents: 3063
diff changeset
  1327
			break;
dc160a70a50d 6410433 'zpool status -v' would be more useful with filenames
ek110237
parents: 3063
diff changeset
  1328
		}
dc160a70a50d 6410433 'zpool status -v' would be more useful with filenames
ek110237
parents: 3063
diff changeset
  1329
dc160a70a50d 6410433 'zpool status -v' would be more useful with filenames
ek110237
parents: 3063
diff changeset
  1330
		component[0] = '/';
dc160a70a50d 6410433 'zpool status -v' would be more useful with filenames
ek110237
parents: 3063
diff changeset
  1331
		if (is_xattrdir) {
dc160a70a50d 6410433 'zpool status -v' would be more useful with filenames
ek110237
parents: 3063
diff changeset
  1332
			(void) sprintf(component + 1, "<xattrdir>");
dc160a70a50d 6410433 'zpool status -v' would be more useful with filenames
ek110237
parents: 3063
diff changeset
  1333
		} else {
4577
ed36b0e652bc PSARC/2007/328 zfs upgrade
ahrens
parents: 4543
diff changeset
  1334
			error = zap_value_search(osp, pobj, obj,
ed36b0e652bc PSARC/2007/328 zfs upgrade
ahrens
parents: 4543
diff changeset
  1335
			    ZFS_DIRENT_OBJ(-1ULL), component + 1);
3444
dc160a70a50d 6410433 'zpool status -v' would be more useful with filenames
ek110237
parents: 3063
diff changeset
  1336
			if (error != 0)
dc160a70a50d 6410433 'zpool status -v' would be more useful with filenames
ek110237
parents: 3063
diff changeset
  1337
				break;
dc160a70a50d 6410433 'zpool status -v' would be more useful with filenames
ek110237
parents: 3063
diff changeset
  1338
		}
dc160a70a50d 6410433 'zpool status -v' would be more useful with filenames
ek110237
parents: 3063
diff changeset
  1339
dc160a70a50d 6410433 'zpool status -v' would be more useful with filenames
ek110237
parents: 3063
diff changeset
  1340
		complen = strlen(component);
dc160a70a50d 6410433 'zpool status -v' would be more useful with filenames
ek110237
parents: 3063
diff changeset
  1341
		path -= complen;
dc160a70a50d 6410433 'zpool status -v' would be more useful with filenames
ek110237
parents: 3063
diff changeset
  1342
		ASSERT(path >= buf);
dc160a70a50d 6410433 'zpool status -v' would be more useful with filenames
ek110237
parents: 3063
diff changeset
  1343
		bcopy(component, path, complen);
dc160a70a50d 6410433 'zpool status -v' would be more useful with filenames
ek110237
parents: 3063
diff changeset
  1344
		obj = pobj;
dc160a70a50d 6410433 'zpool status -v' would be more useful with filenames
ek110237
parents: 3063
diff changeset
  1345
	}
dc160a70a50d 6410433 'zpool status -v' would be more useful with filenames
ek110237
parents: 3063
diff changeset
  1346
dc160a70a50d 6410433 'zpool status -v' would be more useful with filenames
ek110237
parents: 3063
diff changeset
  1347
	if (error == 0)
dc160a70a50d 6410433 'zpool status -v' would be more useful with filenames
ek110237
parents: 3063
diff changeset
  1348
		(void) memmove(buf, path, buf + len - path);
dc160a70a50d 6410433 'zpool status -v' would be more useful with filenames
ek110237
parents: 3063
diff changeset
  1349
	return (error);
dc160a70a50d 6410433 'zpool status -v' would be more useful with filenames
ek110237
parents: 3063
diff changeset
  1350
}