usr/src/uts/common/fs/zfs/zfs_znode.c
author Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
Fri, 04 Dec 2009 09:22:59 -0700
changeset 11249 6c30f7dfc97b
parent 10938 270624bd70f1
child 11935 538c866aaac6
permissions -rw-r--r--
6906110 bad trap panic in zil_replay_log_record 6906946 zfs replay isn't handling uid/gid correctly
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
/*
8636
7e4ce9158df3 6551866 deadlock between zfs_write(), zfs_freesp(), and zfs_putapage()
Mark Maybee <Mark.Maybee@Sun.COM>
parents: 8227
diff changeset
    22
 * Copyright 2009 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
3444
dc160a70a50d 6410433 'zpool status -v' would be more useful with filenames
ek110237
parents: 3063
diff changeset
    28
#ifdef _KERNEL
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    29
#include <sys/types.h>
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    30
#include <sys/param.h>
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    31
#include <sys/time.h>
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    32
#include <sys/systm.h>
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    33
#include <sys/sysmacros.h>
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    34
#include <sys/resource.h>
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    35
#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
    36
#include <sys/mkdev.h>
5498
334b476844ca 6622831 normalization properties are not preserved by "zfs send"
timh
parents: 5446
diff changeset
    37
#include <sys/u8_textprep.h>
6492
903545192033 6654808 FIGNORECASE lookups in a zfs xattr dir don't provide 'realname' data
timh
parents: 5844
diff changeset
    38
#include <sys/dsl_dataset.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>
3444
dc160a70a50d 6410433 'zpool status -v' would be more useful with filenames
ek110237
parents: 3063
diff changeset
    55
#include <sys/fs/zfs.h>
5331
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5326
diff changeset
    56
#include <sys/kidmap.h>
3444
dc160a70a50d 6410433 'zpool status -v' would be more useful with filenames
ek110237
parents: 3063
diff changeset
    57
#endif /* _KERNEL */
dc160a70a50d 6410433 'zpool status -v' would be more useful with filenames
ek110237
parents: 3063
diff changeset
    58
dc160a70a50d 6410433 'zpool status -v' would be more useful with filenames
ek110237
parents: 3063
diff changeset
    59
#include <sys/dmu.h>
dc160a70a50d 6410433 'zpool status -v' would be more useful with filenames
ek110237
parents: 3063
diff changeset
    60
#include <sys/refcount.h>
dc160a70a50d 6410433 'zpool status -v' would be more useful with filenames
ek110237
parents: 3063
diff changeset
    61
#include <sys/stat.h>
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    62
#include <sys/zap.h>
3444
dc160a70a50d 6410433 'zpool status -v' would be more useful with filenames
ek110237
parents: 3063
diff changeset
    63
#include <sys/zfs_znode.h>
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    64
5498
334b476844ca 6622831 normalization properties are not preserved by "zfs send"
timh
parents: 5446
diff changeset
    65
#include "zfs_prop.h"
334b476844ca 6622831 normalization properties are not preserved by "zfs send"
timh
parents: 5446
diff changeset
    66
3444
dc160a70a50d 6410433 'zpool status -v' would be more useful with filenames
ek110237
parents: 3063
diff changeset
    67
/*
6712
79afecec3f3c 6554564 slab allocator cannot release slabs with lonely buffers
tomee
parents: 6492
diff changeset
    68
 * Define ZNODE_STATS to turn on statistic gathering. By default, it is only
79afecec3f3c 6554564 slab allocator cannot release slabs with lonely buffers
tomee
parents: 6492
diff changeset
    69
 * turned on when DEBUG is also defined.
79afecec3f3c 6554564 slab allocator cannot release slabs with lonely buffers
tomee
parents: 6492
diff changeset
    70
 */
79afecec3f3c 6554564 slab allocator cannot release slabs with lonely buffers
tomee
parents: 6492
diff changeset
    71
#ifdef	DEBUG
79afecec3f3c 6554564 slab allocator cannot release slabs with lonely buffers
tomee
parents: 6492
diff changeset
    72
#define	ZNODE_STATS
79afecec3f3c 6554564 slab allocator cannot release slabs with lonely buffers
tomee
parents: 6492
diff changeset
    73
#endif	/* DEBUG */
79afecec3f3c 6554564 slab allocator cannot release slabs with lonely buffers
tomee
parents: 6492
diff changeset
    74
79afecec3f3c 6554564 slab allocator cannot release slabs with lonely buffers
tomee
parents: 6492
diff changeset
    75
#ifdef	ZNODE_STATS
79afecec3f3c 6554564 slab allocator cannot release slabs with lonely buffers
tomee
parents: 6492
diff changeset
    76
#define	ZNODE_STAT_ADD(stat)			((stat)++)
79afecec3f3c 6554564 slab allocator cannot release slabs with lonely buffers
tomee
parents: 6492
diff changeset
    77
#else
79afecec3f3c 6554564 slab allocator cannot release slabs with lonely buffers
tomee
parents: 6492
diff changeset
    78
#define	ZNODE_STAT_ADD(stat)			/* nothing */
79afecec3f3c 6554564 slab allocator cannot release slabs with lonely buffers
tomee
parents: 6492
diff changeset
    79
#endif	/* ZNODE_STATS */
79afecec3f3c 6554564 slab allocator cannot release slabs with lonely buffers
tomee
parents: 6492
diff changeset
    80
79afecec3f3c 6554564 slab allocator cannot release slabs with lonely buffers
tomee
parents: 6492
diff changeset
    81
#define	POINTER_IS_VALID(p)	(!((uintptr_t)(p) & 0x3))
79afecec3f3c 6554564 slab allocator cannot release slabs with lonely buffers
tomee
parents: 6492
diff changeset
    82
#define	POINTER_INVALIDATE(pp)	(*(pp) = (void *)((uintptr_t)(*(pp)) | 0x1))
79afecec3f3c 6554564 slab allocator cannot release slabs with lonely buffers
tomee
parents: 6492
diff changeset
    83
79afecec3f3c 6554564 slab allocator cannot release slabs with lonely buffers
tomee
parents: 6492
diff changeset
    84
/*
3444
dc160a70a50d 6410433 'zpool status -v' would be more useful with filenames
ek110237
parents: 3063
diff changeset
    85
 * 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
    86
 * #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
    87
 * (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
    88
 */
dc160a70a50d 6410433 'zpool status -v' would be more useful with filenames
ek110237
parents: 3063
diff changeset
    89
#ifdef _KERNEL
9788
f660bc44f2e8 6843700 zfs_znode_move() does not ensure valid file system pointer
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 9396
diff changeset
    90
/*
f660bc44f2e8 6843700 zfs_znode_move() does not ensure valid file system pointer
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 9396
diff changeset
    91
 * Needed to close a small window in zfs_znode_move() that allows the zfsvfs to
f660bc44f2e8 6843700 zfs_znode_move() does not ensure valid file system pointer
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 9396
diff changeset
    92
 * be freed before it can be safely accessed.
f660bc44f2e8 6843700 zfs_znode_move() does not ensure valid file system pointer
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 9396
diff changeset
    93
 */
f660bc44f2e8 6843700 zfs_znode_move() does not ensure valid file system pointer
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 9396
diff changeset
    94
krwlock_t zfsvfs_lock;
f660bc44f2e8 6843700 zfs_znode_move() does not ensure valid file system pointer
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 9396
diff changeset
    95
6712
79afecec3f3c 6554564 slab allocator cannot release slabs with lonely buffers
tomee
parents: 6492
diff changeset
    96
static kmem_cache_t *znode_cache = NULL;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    97
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    98
/*ARGSUSED*/
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    99
static void
5642
504c84876fda 6513209 Destroying pools under stress caused a hang in arc_flush
maybee
parents: 5520
diff changeset
   100
znode_evict_error(dmu_buf_t *dbuf, void *user_ptr)
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   101
{
5642
504c84876fda 6513209 Destroying pools under stress caused a hang in arc_flush
maybee
parents: 5520
diff changeset
   102
	/*
504c84876fda 6513209 Destroying pools under stress caused a hang in arc_flush
maybee
parents: 5520
diff changeset
   103
	 * We should never drop all dbuf refs without first clearing
504c84876fda 6513209 Destroying pools under stress caused a hang in arc_flush
maybee
parents: 5520
diff changeset
   104
	 * the eviction callback.
504c84876fda 6513209 Destroying pools under stress caused a hang in arc_flush
maybee
parents: 5520
diff changeset
   105
	 */
504c84876fda 6513209 Destroying pools under stress caused a hang in arc_flush
maybee
parents: 5520
diff changeset
   106
	panic("evicting znode %p\n", user_ptr);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   107
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   108
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   109
/*ARGSUSED*/
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   110
static int
6712
79afecec3f3c 6554564 slab allocator cannot release slabs with lonely buffers
tomee
parents: 6492
diff changeset
   111
zfs_znode_cache_constructor(void *buf, void *arg, int kmflags)
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   112
{
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   113
	znode_t *zp = buf;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   114
6712
79afecec3f3c 6554564 slab allocator cannot release slabs with lonely buffers
tomee
parents: 6492
diff changeset
   115
	ASSERT(!POINTER_IS_VALID(zp->z_zfsvfs));
79afecec3f3c 6554564 slab allocator cannot release slabs with lonely buffers
tomee
parents: 6492
diff changeset
   116
79afecec3f3c 6554564 slab allocator cannot release slabs with lonely buffers
tomee
parents: 6492
diff changeset
   117
	zp->z_vnode = vn_alloc(kmflags);
79afecec3f3c 6554564 slab allocator cannot release slabs with lonely buffers
tomee
parents: 6492
diff changeset
   118
	if (zp->z_vnode == NULL) {
79afecec3f3c 6554564 slab allocator cannot release slabs with lonely buffers
tomee
parents: 6492
diff changeset
   119
		return (-1);
79afecec3f3c 6554564 slab allocator cannot release slabs with lonely buffers
tomee
parents: 6492
diff changeset
   120
	}
79afecec3f3c 6554564 slab allocator cannot release slabs with lonely buffers
tomee
parents: 6492
diff changeset
   121
	ZTOV(zp)->v_data = zp;
79afecec3f3c 6554564 slab allocator cannot release slabs with lonely buffers
tomee
parents: 6492
diff changeset
   122
79afecec3f3c 6554564 slab allocator cannot release slabs with lonely buffers
tomee
parents: 6492
diff changeset
   123
	list_link_init(&zp->z_link_node);
79afecec3f3c 6554564 slab allocator cannot release slabs with lonely buffers
tomee
parents: 6492
diff changeset
   124
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   125
	mutex_init(&zp->z_lock, NULL, MUTEX_DEFAULT, NULL);
1669
3521dbbcb2e8 6343608 ZFS file range locking
perrin
parents: 1544
diff changeset
   126
	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
   127
	rw_init(&zp->z_name_lock, NULL, RW_DEFAULT, NULL);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   128
	mutex_init(&zp->z_acl_lock, NULL, MUTEX_DEFAULT, NULL);
1669
3521dbbcb2e8 6343608 ZFS file range locking
perrin
parents: 1544
diff changeset
   129
3521dbbcb2e8 6343608 ZFS file range locking
perrin
parents: 1544
diff changeset
   130
	mutex_init(&zp->z_range_lock, NULL, MUTEX_DEFAULT, NULL);
3521dbbcb2e8 6343608 ZFS file range locking
perrin
parents: 1544
diff changeset
   131
	avl_create(&zp->z_range_avl, zfs_range_compare,
3521dbbcb2e8 6343608 ZFS file range locking
perrin
parents: 1544
diff changeset
   132
	    sizeof (rl_t), offsetof(rl_t, r_node));
3521dbbcb2e8 6343608 ZFS file range locking
perrin
parents: 1544
diff changeset
   133
5446
51fbc14b301d 6421210 zfs rollback without unmounting
ahrens
parents: 5331
diff changeset
   134
	zp->z_dbuf = NULL;
6712
79afecec3f3c 6554564 slab allocator cannot release slabs with lonely buffers
tomee
parents: 6492
diff changeset
   135
	zp->z_dirlocks = NULL;
9981
b4907297e740 6775100 stat() performance on files on zfs should be improved
Tim Haley <Tim.Haley@Sun.COM>
parents: 9788
diff changeset
   136
	zp->z_acl_cached = NULL;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   137
	return (0);
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
/*ARGSUSED*/
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   141
static void
6712
79afecec3f3c 6554564 slab allocator cannot release slabs with lonely buffers
tomee
parents: 6492
diff changeset
   142
zfs_znode_cache_destructor(void *buf, void *arg)
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   143
{
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   144
	znode_t *zp = buf;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   145
6712
79afecec3f3c 6554564 slab allocator cannot release slabs with lonely buffers
tomee
parents: 6492
diff changeset
   146
	ASSERT(!POINTER_IS_VALID(zp->z_zfsvfs));
79afecec3f3c 6554564 slab allocator cannot release slabs with lonely buffers
tomee
parents: 6492
diff changeset
   147
	ASSERT(ZTOV(zp)->v_data == zp);
79afecec3f3c 6554564 slab allocator cannot release slabs with lonely buffers
tomee
parents: 6492
diff changeset
   148
	vn_free(ZTOV(zp));
79afecec3f3c 6554564 slab allocator cannot release slabs with lonely buffers
tomee
parents: 6492
diff changeset
   149
	ASSERT(!list_link_active(&zp->z_link_node));
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   150
	mutex_destroy(&zp->z_lock);
1669
3521dbbcb2e8 6343608 ZFS file range locking
perrin
parents: 1544
diff changeset
   151
	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
   152
	rw_destroy(&zp->z_name_lock);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   153
	mutex_destroy(&zp->z_acl_lock);
1669
3521dbbcb2e8 6343608 ZFS file range locking
perrin
parents: 1544
diff changeset
   154
	avl_destroy(&zp->z_range_avl);
4831
41ec732c6d9f 6584470 zdb needs to initialize the bpl_lock mutex
gw25295
parents: 4577
diff changeset
   155
	mutex_destroy(&zp->z_range_lock);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   156
5446
51fbc14b301d 6421210 zfs rollback without unmounting
ahrens
parents: 5331
diff changeset
   157
	ASSERT(zp->z_dbuf == NULL);
6712
79afecec3f3c 6554564 slab allocator cannot release slabs with lonely buffers
tomee
parents: 6492
diff changeset
   158
	ASSERT(zp->z_dirlocks == NULL);
10143
d2d432dfe597 6857433 memory leaks found at: zfs_acl_alloc/zfs_acl_node_alloc
Tim Haley <Tim.Haley@Sun.COM>
parents: 9981
diff changeset
   159
	ASSERT(zp->z_acl_cached == NULL);
6712
79afecec3f3c 6554564 slab allocator cannot release slabs with lonely buffers
tomee
parents: 6492
diff changeset
   160
}
79afecec3f3c 6554564 slab allocator cannot release slabs with lonely buffers
tomee
parents: 6492
diff changeset
   161
79afecec3f3c 6554564 slab allocator cannot release slabs with lonely buffers
tomee
parents: 6492
diff changeset
   162
#ifdef	ZNODE_STATS
79afecec3f3c 6554564 slab allocator cannot release slabs with lonely buffers
tomee
parents: 6492
diff changeset
   163
static struct {
79afecec3f3c 6554564 slab allocator cannot release slabs with lonely buffers
tomee
parents: 6492
diff changeset
   164
	uint64_t zms_zfsvfs_invalid;
9788
f660bc44f2e8 6843700 zfs_znode_move() does not ensure valid file system pointer
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 9396
diff changeset
   165
	uint64_t zms_zfsvfs_recheck1;
6712
79afecec3f3c 6554564 slab allocator cannot release slabs with lonely buffers
tomee
parents: 6492
diff changeset
   166
	uint64_t zms_zfsvfs_unmounted;
9788
f660bc44f2e8 6843700 zfs_znode_move() does not ensure valid file system pointer
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 9396
diff changeset
   167
	uint64_t zms_zfsvfs_recheck2;
7579
c91803605019 6744863 race between zfs_znode_move() and zfs_zget()
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 7240
diff changeset
   168
	uint64_t zms_obj_held;
6712
79afecec3f3c 6554564 slab allocator cannot release slabs with lonely buffers
tomee
parents: 6492
diff changeset
   169
	uint64_t zms_vnode_locked;
7579
c91803605019 6744863 race between zfs_znode_move() and zfs_zget()
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 7240
diff changeset
   170
	uint64_t zms_not_only_dnlc;
6712
79afecec3f3c 6554564 slab allocator cannot release slabs with lonely buffers
tomee
parents: 6492
diff changeset
   171
} znode_move_stats;
79afecec3f3c 6554564 slab allocator cannot release slabs with lonely buffers
tomee
parents: 6492
diff changeset
   172
#endif	/* ZNODE_STATS */
79afecec3f3c 6554564 slab allocator cannot release slabs with lonely buffers
tomee
parents: 6492
diff changeset
   173
79afecec3f3c 6554564 slab allocator cannot release slabs with lonely buffers
tomee
parents: 6492
diff changeset
   174
static void
79afecec3f3c 6554564 slab allocator cannot release slabs with lonely buffers
tomee
parents: 6492
diff changeset
   175
zfs_znode_move_impl(znode_t *ozp, znode_t *nzp)
79afecec3f3c 6554564 slab allocator cannot release slabs with lonely buffers
tomee
parents: 6492
diff changeset
   176
{
79afecec3f3c 6554564 slab allocator cannot release slabs with lonely buffers
tomee
parents: 6492
diff changeset
   177
	vnode_t *vp;
79afecec3f3c 6554564 slab allocator cannot release slabs with lonely buffers
tomee
parents: 6492
diff changeset
   178
79afecec3f3c 6554564 slab allocator cannot release slabs with lonely buffers
tomee
parents: 6492
diff changeset
   179
	/* Copy fields. */
79afecec3f3c 6554564 slab allocator cannot release slabs with lonely buffers
tomee
parents: 6492
diff changeset
   180
	nzp->z_zfsvfs = ozp->z_zfsvfs;
79afecec3f3c 6554564 slab allocator cannot release slabs with lonely buffers
tomee
parents: 6492
diff changeset
   181
79afecec3f3c 6554564 slab allocator cannot release slabs with lonely buffers
tomee
parents: 6492
diff changeset
   182
	/* Swap vnodes. */
79afecec3f3c 6554564 slab allocator cannot release slabs with lonely buffers
tomee
parents: 6492
diff changeset
   183
	vp = nzp->z_vnode;
79afecec3f3c 6554564 slab allocator cannot release slabs with lonely buffers
tomee
parents: 6492
diff changeset
   184
	nzp->z_vnode = ozp->z_vnode;
79afecec3f3c 6554564 slab allocator cannot release slabs with lonely buffers
tomee
parents: 6492
diff changeset
   185
	ozp->z_vnode = vp; /* let destructor free the overwritten vnode */
79afecec3f3c 6554564 slab allocator cannot release slabs with lonely buffers
tomee
parents: 6492
diff changeset
   186
	ZTOV(ozp)->v_data = ozp;
79afecec3f3c 6554564 slab allocator cannot release slabs with lonely buffers
tomee
parents: 6492
diff changeset
   187
	ZTOV(nzp)->v_data = nzp;
79afecec3f3c 6554564 slab allocator cannot release slabs with lonely buffers
tomee
parents: 6492
diff changeset
   188
79afecec3f3c 6554564 slab allocator cannot release slabs with lonely buffers
tomee
parents: 6492
diff changeset
   189
	nzp->z_id = ozp->z_id;
79afecec3f3c 6554564 slab allocator cannot release slabs with lonely buffers
tomee
parents: 6492
diff changeset
   190
	ASSERT(ozp->z_dirlocks == NULL); /* znode not in use */
79afecec3f3c 6554564 slab allocator cannot release slabs with lonely buffers
tomee
parents: 6492
diff changeset
   191
	ASSERT(avl_numnodes(&ozp->z_range_avl) == 0);
79afecec3f3c 6554564 slab allocator cannot release slabs with lonely buffers
tomee
parents: 6492
diff changeset
   192
	nzp->z_unlinked = ozp->z_unlinked;
79afecec3f3c 6554564 slab allocator cannot release slabs with lonely buffers
tomee
parents: 6492
diff changeset
   193
	nzp->z_atime_dirty = ozp->z_atime_dirty;
79afecec3f3c 6554564 slab allocator cannot release slabs with lonely buffers
tomee
parents: 6492
diff changeset
   194
	nzp->z_zn_prefetch = ozp->z_zn_prefetch;
79afecec3f3c 6554564 slab allocator cannot release slabs with lonely buffers
tomee
parents: 6492
diff changeset
   195
	nzp->z_blksz = ozp->z_blksz;
79afecec3f3c 6554564 slab allocator cannot release slabs with lonely buffers
tomee
parents: 6492
diff changeset
   196
	nzp->z_seq = ozp->z_seq;
79afecec3f3c 6554564 slab allocator cannot release slabs with lonely buffers
tomee
parents: 6492
diff changeset
   197
	nzp->z_mapcnt = ozp->z_mapcnt;
79afecec3f3c 6554564 slab allocator cannot release slabs with lonely buffers
tomee
parents: 6492
diff changeset
   198
	nzp->z_last_itx = ozp->z_last_itx;
79afecec3f3c 6554564 slab allocator cannot release slabs with lonely buffers
tomee
parents: 6492
diff changeset
   199
	nzp->z_gen = ozp->z_gen;
79afecec3f3c 6554564 slab allocator cannot release slabs with lonely buffers
tomee
parents: 6492
diff changeset
   200
	nzp->z_sync_cnt = ozp->z_sync_cnt;
79afecec3f3c 6554564 slab allocator cannot release slabs with lonely buffers
tomee
parents: 6492
diff changeset
   201
	nzp->z_phys = ozp->z_phys;
79afecec3f3c 6554564 slab allocator cannot release slabs with lonely buffers
tomee
parents: 6492
diff changeset
   202
	nzp->z_dbuf = ozp->z_dbuf;
10250
b179ceb34b62 6867395 zpool_upgrade_007_pos testcase panic'd with BAD TRAP: type=e (#pf Page fault)
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 10143
diff changeset
   203
b179ceb34b62 6867395 zpool_upgrade_007_pos testcase panic'd with BAD TRAP: type=e (#pf Page fault)
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 10143
diff changeset
   204
	/*
10269
2788675568fd 6868276 zfs_rezget() can be hazardous when znode has a cached ACL
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 10250
diff changeset
   205
	 * Since this is just an idle znode and kmem is already dealing with
2788675568fd 6868276 zfs_rezget() can be hazardous when znode has a cached ACL
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 10250
diff changeset
   206
	 * memory pressure, release any cached ACL.
10250
b179ceb34b62 6867395 zpool_upgrade_007_pos testcase panic'd with BAD TRAP: type=e (#pf Page fault)
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 10143
diff changeset
   207
	 */
b179ceb34b62 6867395 zpool_upgrade_007_pos testcase panic'd with BAD TRAP: type=e (#pf Page fault)
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 10143
diff changeset
   208
	if (ozp->z_acl_cached) {
b179ceb34b62 6867395 zpool_upgrade_007_pos testcase panic'd with BAD TRAP: type=e (#pf Page fault)
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 10143
diff changeset
   209
		zfs_acl_free(ozp->z_acl_cached);
b179ceb34b62 6867395 zpool_upgrade_007_pos testcase panic'd with BAD TRAP: type=e (#pf Page fault)
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 10143
diff changeset
   210
		ozp->z_acl_cached = NULL;
b179ceb34b62 6867395 zpool_upgrade_007_pos testcase panic'd with BAD TRAP: type=e (#pf Page fault)
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 10143
diff changeset
   211
	}
6712
79afecec3f3c 6554564 slab allocator cannot release slabs with lonely buffers
tomee
parents: 6492
diff changeset
   212
79afecec3f3c 6554564 slab allocator cannot release slabs with lonely buffers
tomee
parents: 6492
diff changeset
   213
	/* Update back pointers. */
79afecec3f3c 6554564 slab allocator cannot release slabs with lonely buffers
tomee
parents: 6492
diff changeset
   214
	(void) dmu_buf_update_user(nzp->z_dbuf, ozp, nzp, &nzp->z_phys,
79afecec3f3c 6554564 slab allocator cannot release slabs with lonely buffers
tomee
parents: 6492
diff changeset
   215
	    znode_evict_error);
79afecec3f3c 6554564 slab allocator cannot release slabs with lonely buffers
tomee
parents: 6492
diff changeset
   216
79afecec3f3c 6554564 slab allocator cannot release slabs with lonely buffers
tomee
parents: 6492
diff changeset
   217
	/*
79afecec3f3c 6554564 slab allocator cannot release slabs with lonely buffers
tomee
parents: 6492
diff changeset
   218
	 * Invalidate the original znode by clearing fields that provide a
79afecec3f3c 6554564 slab allocator cannot release slabs with lonely buffers
tomee
parents: 6492
diff changeset
   219
	 * pointer back to the znode. Set the low bit of the vfs pointer to
79afecec3f3c 6554564 slab allocator cannot release slabs with lonely buffers
tomee
parents: 6492
diff changeset
   220
	 * ensure that zfs_znode_move() recognizes the znode as invalid in any
79afecec3f3c 6554564 slab allocator cannot release slabs with lonely buffers
tomee
parents: 6492
diff changeset
   221
	 * subsequent callback.
79afecec3f3c 6554564 slab allocator cannot release slabs with lonely buffers
tomee
parents: 6492
diff changeset
   222
	 */
79afecec3f3c 6554564 slab allocator cannot release slabs with lonely buffers
tomee
parents: 6492
diff changeset
   223
	ozp->z_dbuf = NULL;
79afecec3f3c 6554564 slab allocator cannot release slabs with lonely buffers
tomee
parents: 6492
diff changeset
   224
	POINTER_INVALIDATE(&ozp->z_zfsvfs);
79afecec3f3c 6554564 slab allocator cannot release slabs with lonely buffers
tomee
parents: 6492
diff changeset
   225
}
79afecec3f3c 6554564 slab allocator cannot release slabs with lonely buffers
tomee
parents: 6492
diff changeset
   226
79afecec3f3c 6554564 slab allocator cannot release slabs with lonely buffers
tomee
parents: 6492
diff changeset
   227
/*ARGSUSED*/
79afecec3f3c 6554564 slab allocator cannot release slabs with lonely buffers
tomee
parents: 6492
diff changeset
   228
static kmem_cbrc_t
79afecec3f3c 6554564 slab allocator cannot release slabs with lonely buffers
tomee
parents: 6492
diff changeset
   229
zfs_znode_move(void *buf, void *newbuf, size_t size, void *arg)
79afecec3f3c 6554564 slab allocator cannot release slabs with lonely buffers
tomee
parents: 6492
diff changeset
   230
{
79afecec3f3c 6554564 slab allocator cannot release slabs with lonely buffers
tomee
parents: 6492
diff changeset
   231
	znode_t *ozp = buf, *nzp = newbuf;
79afecec3f3c 6554564 slab allocator cannot release slabs with lonely buffers
tomee
parents: 6492
diff changeset
   232
	zfsvfs_t *zfsvfs;
79afecec3f3c 6554564 slab allocator cannot release slabs with lonely buffers
tomee
parents: 6492
diff changeset
   233
	vnode_t *vp;
79afecec3f3c 6554564 slab allocator cannot release slabs with lonely buffers
tomee
parents: 6492
diff changeset
   234
79afecec3f3c 6554564 slab allocator cannot release slabs with lonely buffers
tomee
parents: 6492
diff changeset
   235
	/*
79afecec3f3c 6554564 slab allocator cannot release slabs with lonely buffers
tomee
parents: 6492
diff changeset
   236
	 * The znode is on the file system's list of known znodes if the vfs
79afecec3f3c 6554564 slab allocator cannot release slabs with lonely buffers
tomee
parents: 6492
diff changeset
   237
	 * pointer is valid. We set the low bit of the vfs pointer when freeing
79afecec3f3c 6554564 slab allocator cannot release slabs with lonely buffers
tomee
parents: 6492
diff changeset
   238
	 * the znode to invalidate it, and the memory patterns written by kmem
79afecec3f3c 6554564 slab allocator cannot release slabs with lonely buffers
tomee
parents: 6492
diff changeset
   239
	 * (baddcafe and deadbeef) set at least one of the two low bits. A newly
79afecec3f3c 6554564 slab allocator cannot release slabs with lonely buffers
tomee
parents: 6492
diff changeset
   240
	 * created znode sets the vfs pointer last of all to indicate that the
79afecec3f3c 6554564 slab allocator cannot release slabs with lonely buffers
tomee
parents: 6492
diff changeset
   241
	 * znode is known and in a valid state to be moved by this function.
79afecec3f3c 6554564 slab allocator cannot release slabs with lonely buffers
tomee
parents: 6492
diff changeset
   242
	 */
79afecec3f3c 6554564 slab allocator cannot release slabs with lonely buffers
tomee
parents: 6492
diff changeset
   243
	zfsvfs = ozp->z_zfsvfs;
79afecec3f3c 6554564 slab allocator cannot release slabs with lonely buffers
tomee
parents: 6492
diff changeset
   244
	if (!POINTER_IS_VALID(zfsvfs)) {
79afecec3f3c 6554564 slab allocator cannot release slabs with lonely buffers
tomee
parents: 6492
diff changeset
   245
		ZNODE_STAT_ADD(znode_move_stats.zms_zfsvfs_invalid);
79afecec3f3c 6554564 slab allocator cannot release slabs with lonely buffers
tomee
parents: 6492
diff changeset
   246
		return (KMEM_CBRC_DONT_KNOW);
79afecec3f3c 6554564 slab allocator cannot release slabs with lonely buffers
tomee
parents: 6492
diff changeset
   247
	}
79afecec3f3c 6554564 slab allocator cannot release slabs with lonely buffers
tomee
parents: 6492
diff changeset
   248
79afecec3f3c 6554564 slab allocator cannot release slabs with lonely buffers
tomee
parents: 6492
diff changeset
   249
	/*
9788
f660bc44f2e8 6843700 zfs_znode_move() does not ensure valid file system pointer
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 9396
diff changeset
   250
	 * Close a small window in which it's possible that the filesystem could
f660bc44f2e8 6843700 zfs_znode_move() does not ensure valid file system pointer
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 9396
diff changeset
   251
	 * be unmounted and freed, and zfsvfs, though valid in the previous
f660bc44f2e8 6843700 zfs_znode_move() does not ensure valid file system pointer
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 9396
diff changeset
   252
	 * statement, could point to unrelated memory by the time we try to
f660bc44f2e8 6843700 zfs_znode_move() does not ensure valid file system pointer
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 9396
diff changeset
   253
	 * prevent the filesystem from being unmounted.
f660bc44f2e8 6843700 zfs_znode_move() does not ensure valid file system pointer
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 9396
diff changeset
   254
	 */
f660bc44f2e8 6843700 zfs_znode_move() does not ensure valid file system pointer
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 9396
diff changeset
   255
	rw_enter(&zfsvfs_lock, RW_WRITER);
f660bc44f2e8 6843700 zfs_znode_move() does not ensure valid file system pointer
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 9396
diff changeset
   256
	if (zfsvfs != ozp->z_zfsvfs) {
f660bc44f2e8 6843700 zfs_znode_move() does not ensure valid file system pointer
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 9396
diff changeset
   257
		rw_exit(&zfsvfs_lock);
f660bc44f2e8 6843700 zfs_znode_move() does not ensure valid file system pointer
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 9396
diff changeset
   258
		ZNODE_STAT_ADD(znode_move_stats.zms_zfsvfs_recheck1);
f660bc44f2e8 6843700 zfs_znode_move() does not ensure valid file system pointer
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 9396
diff changeset
   259
		return (KMEM_CBRC_DONT_KNOW);
f660bc44f2e8 6843700 zfs_znode_move() does not ensure valid file system pointer
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 9396
diff changeset
   260
	}
f660bc44f2e8 6843700 zfs_znode_move() does not ensure valid file system pointer
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 9396
diff changeset
   261
f660bc44f2e8 6843700 zfs_znode_move() does not ensure valid file system pointer
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 9396
diff changeset
   262
	/*
f660bc44f2e8 6843700 zfs_znode_move() does not ensure valid file system pointer
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 9396
diff changeset
   263
	 * If the znode is still valid, then so is the file system. We know that
f660bc44f2e8 6843700 zfs_znode_move() does not ensure valid file system pointer
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 9396
diff changeset
   264
	 * no valid file system can be freed while we hold zfsvfs_lock, so we
f660bc44f2e8 6843700 zfs_znode_move() does not ensure valid file system pointer
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 9396
diff changeset
   265
	 * can safely ensure that the filesystem is not and will not be
f660bc44f2e8 6843700 zfs_znode_move() does not ensure valid file system pointer
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 9396
diff changeset
   266
	 * unmounted. The next statement is equivalent to ZFS_ENTER().
6712
79afecec3f3c 6554564 slab allocator cannot release slabs with lonely buffers
tomee
parents: 6492
diff changeset
   267
	 */
9396
f41cf682d0d3 PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 9179
diff changeset
   268
	rrw_enter(&zfsvfs->z_teardown_lock, RW_READER, FTAG);
f41cf682d0d3 PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 9179
diff changeset
   269
	if (zfsvfs->z_unmounted) {
f41cf682d0d3 PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 9179
diff changeset
   270
		ZFS_EXIT(zfsvfs);
9788
f660bc44f2e8 6843700 zfs_znode_move() does not ensure valid file system pointer
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 9396
diff changeset
   271
		rw_exit(&zfsvfs_lock);
6712
79afecec3f3c 6554564 slab allocator cannot release slabs with lonely buffers
tomee
parents: 6492
diff changeset
   272
		ZNODE_STAT_ADD(znode_move_stats.zms_zfsvfs_unmounted);
79afecec3f3c 6554564 slab allocator cannot release slabs with lonely buffers
tomee
parents: 6492
diff changeset
   273
		return (KMEM_CBRC_DONT_KNOW);
79afecec3f3c 6554564 slab allocator cannot release slabs with lonely buffers
tomee
parents: 6492
diff changeset
   274
	}
9788
f660bc44f2e8 6843700 zfs_znode_move() does not ensure valid file system pointer
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 9396
diff changeset
   275
	rw_exit(&zfsvfs_lock);
6712
79afecec3f3c 6554564 slab allocator cannot release slabs with lonely buffers
tomee
parents: 6492
diff changeset
   276
79afecec3f3c 6554564 slab allocator cannot release slabs with lonely buffers
tomee
parents: 6492
diff changeset
   277
	mutex_enter(&zfsvfs->z_znodes_lock);
79afecec3f3c 6554564 slab allocator cannot release slabs with lonely buffers
tomee
parents: 6492
diff changeset
   278
	/*
79afecec3f3c 6554564 slab allocator cannot release slabs with lonely buffers
tomee
parents: 6492
diff changeset
   279
	 * Recheck the vfs pointer in case the znode was removed just before
79afecec3f3c 6554564 slab allocator cannot release slabs with lonely buffers
tomee
parents: 6492
diff changeset
   280
	 * acquiring the lock.
79afecec3f3c 6554564 slab allocator cannot release slabs with lonely buffers
tomee
parents: 6492
diff changeset
   281
	 */
79afecec3f3c 6554564 slab allocator cannot release slabs with lonely buffers
tomee
parents: 6492
diff changeset
   282
	if (zfsvfs != ozp->z_zfsvfs) {
79afecec3f3c 6554564 slab allocator cannot release slabs with lonely buffers
tomee
parents: 6492
diff changeset
   283
		mutex_exit(&zfsvfs->z_znodes_lock);
79afecec3f3c 6554564 slab allocator cannot release slabs with lonely buffers
tomee
parents: 6492
diff changeset
   284
		ZFS_EXIT(zfsvfs);
9788
f660bc44f2e8 6843700 zfs_znode_move() does not ensure valid file system pointer
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 9396
diff changeset
   285
		ZNODE_STAT_ADD(znode_move_stats.zms_zfsvfs_recheck2);
6712
79afecec3f3c 6554564 slab allocator cannot release slabs with lonely buffers
tomee
parents: 6492
diff changeset
   286
		return (KMEM_CBRC_DONT_KNOW);
79afecec3f3c 6554564 slab allocator cannot release slabs with lonely buffers
tomee
parents: 6492
diff changeset
   287
	}
79afecec3f3c 6554564 slab allocator cannot release slabs with lonely buffers
tomee
parents: 6492
diff changeset
   288
79afecec3f3c 6554564 slab allocator cannot release slabs with lonely buffers
tomee
parents: 6492
diff changeset
   289
	/*
79afecec3f3c 6554564 slab allocator cannot release slabs with lonely buffers
tomee
parents: 6492
diff changeset
   290
	 * At this point we know that as long as we hold z_znodes_lock, the
79afecec3f3c 6554564 slab allocator cannot release slabs with lonely buffers
tomee
parents: 6492
diff changeset
   291
	 * znode cannot be freed and fields within the znode can be safely
7579
c91803605019 6744863 race between zfs_znode_move() and zfs_zget()
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 7240
diff changeset
   292
	 * accessed. Now, prevent a race with zfs_zget().
6712
79afecec3f3c 6554564 slab allocator cannot release slabs with lonely buffers
tomee
parents: 6492
diff changeset
   293
	 */
7579
c91803605019 6744863 race between zfs_znode_move() and zfs_zget()
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 7240
diff changeset
   294
	if (ZFS_OBJ_HOLD_TRYENTER(zfsvfs, ozp->z_id) == 0) {
c91803605019 6744863 race between zfs_znode_move() and zfs_zget()
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 7240
diff changeset
   295
		mutex_exit(&zfsvfs->z_znodes_lock);
c91803605019 6744863 race between zfs_znode_move() and zfs_zget()
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 7240
diff changeset
   296
		ZFS_EXIT(zfsvfs);
c91803605019 6744863 race between zfs_znode_move() and zfs_zget()
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 7240
diff changeset
   297
		ZNODE_STAT_ADD(znode_move_stats.zms_obj_held);
c91803605019 6744863 race between zfs_znode_move() and zfs_zget()
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 7240
diff changeset
   298
		return (KMEM_CBRC_LATER);
c91803605019 6744863 race between zfs_znode_move() and zfs_zget()
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 7240
diff changeset
   299
	}
c91803605019 6744863 race between zfs_znode_move() and zfs_zget()
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 7240
diff changeset
   300
6712
79afecec3f3c 6554564 slab allocator cannot release slabs with lonely buffers
tomee
parents: 6492
diff changeset
   301
	vp = ZTOV(ozp);
79afecec3f3c 6554564 slab allocator cannot release slabs with lonely buffers
tomee
parents: 6492
diff changeset
   302
	if (mutex_tryenter(&vp->v_lock) == 0) {
7579
c91803605019 6744863 race between zfs_znode_move() and zfs_zget()
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 7240
diff changeset
   303
		ZFS_OBJ_HOLD_EXIT(zfsvfs, ozp->z_id);
6712
79afecec3f3c 6554564 slab allocator cannot release slabs with lonely buffers
tomee
parents: 6492
diff changeset
   304
		mutex_exit(&zfsvfs->z_znodes_lock);
79afecec3f3c 6554564 slab allocator cannot release slabs with lonely buffers
tomee
parents: 6492
diff changeset
   305
		ZFS_EXIT(zfsvfs);
79afecec3f3c 6554564 slab allocator cannot release slabs with lonely buffers
tomee
parents: 6492
diff changeset
   306
		ZNODE_STAT_ADD(znode_move_stats.zms_vnode_locked);
79afecec3f3c 6554564 slab allocator cannot release slabs with lonely buffers
tomee
parents: 6492
diff changeset
   307
		return (KMEM_CBRC_LATER);
79afecec3f3c 6554564 slab allocator cannot release slabs with lonely buffers
tomee
parents: 6492
diff changeset
   308
	}
7579
c91803605019 6744863 race between zfs_znode_move() and zfs_zget()
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 7240
diff changeset
   309
6712
79afecec3f3c 6554564 slab allocator cannot release slabs with lonely buffers
tomee
parents: 6492
diff changeset
   310
	/* Only move znodes that are referenced _only_ by the DNLC. */
79afecec3f3c 6554564 slab allocator cannot release slabs with lonely buffers
tomee
parents: 6492
diff changeset
   311
	if (vp->v_count != 1 || !vn_in_dnlc(vp)) {
79afecec3f3c 6554564 slab allocator cannot release slabs with lonely buffers
tomee
parents: 6492
diff changeset
   312
		mutex_exit(&vp->v_lock);
7579
c91803605019 6744863 race between zfs_znode_move() and zfs_zget()
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 7240
diff changeset
   313
		ZFS_OBJ_HOLD_EXIT(zfsvfs, ozp->z_id);
6712
79afecec3f3c 6554564 slab allocator cannot release slabs with lonely buffers
tomee
parents: 6492
diff changeset
   314
		mutex_exit(&zfsvfs->z_znodes_lock);
79afecec3f3c 6554564 slab allocator cannot release slabs with lonely buffers
tomee
parents: 6492
diff changeset
   315
		ZFS_EXIT(zfsvfs);
7579
c91803605019 6744863 race between zfs_znode_move() and zfs_zget()
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 7240
diff changeset
   316
		ZNODE_STAT_ADD(znode_move_stats.zms_not_only_dnlc);
6712
79afecec3f3c 6554564 slab allocator cannot release slabs with lonely buffers
tomee
parents: 6492
diff changeset
   317
		return (KMEM_CBRC_LATER);
79afecec3f3c 6554564 slab allocator cannot release slabs with lonely buffers
tomee
parents: 6492
diff changeset
   318
	}
79afecec3f3c 6554564 slab allocator cannot release slabs with lonely buffers
tomee
parents: 6492
diff changeset
   319
79afecec3f3c 6554564 slab allocator cannot release slabs with lonely buffers
tomee
parents: 6492
diff changeset
   320
	/*
79afecec3f3c 6554564 slab allocator cannot release slabs with lonely buffers
tomee
parents: 6492
diff changeset
   321
	 * The znode is known and in a valid state to move. We're holding the
79afecec3f3c 6554564 slab allocator cannot release slabs with lonely buffers
tomee
parents: 6492
diff changeset
   322
	 * locks needed to execute the critical section.
79afecec3f3c 6554564 slab allocator cannot release slabs with lonely buffers
tomee
parents: 6492
diff changeset
   323
	 */
79afecec3f3c 6554564 slab allocator cannot release slabs with lonely buffers
tomee
parents: 6492
diff changeset
   324
	zfs_znode_move_impl(ozp, nzp);
79afecec3f3c 6554564 slab allocator cannot release slabs with lonely buffers
tomee
parents: 6492
diff changeset
   325
	mutex_exit(&vp->v_lock);
7579
c91803605019 6744863 race between zfs_znode_move() and zfs_zget()
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 7240
diff changeset
   326
	ZFS_OBJ_HOLD_EXIT(zfsvfs, ozp->z_id);
6712
79afecec3f3c 6554564 slab allocator cannot release slabs with lonely buffers
tomee
parents: 6492
diff changeset
   327
79afecec3f3c 6554564 slab allocator cannot release slabs with lonely buffers
tomee
parents: 6492
diff changeset
   328
	list_link_replace(&ozp->z_link_node, &nzp->z_link_node);
79afecec3f3c 6554564 slab allocator cannot release slabs with lonely buffers
tomee
parents: 6492
diff changeset
   329
	mutex_exit(&zfsvfs->z_znodes_lock);
79afecec3f3c 6554564 slab allocator cannot release slabs with lonely buffers
tomee
parents: 6492
diff changeset
   330
	ZFS_EXIT(zfsvfs);
79afecec3f3c 6554564 slab allocator cannot release slabs with lonely buffers
tomee
parents: 6492
diff changeset
   331
79afecec3f3c 6554564 slab allocator cannot release slabs with lonely buffers
tomee
parents: 6492
diff changeset
   332
	return (KMEM_CBRC_YES);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   333
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   334
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   335
void
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   336
zfs_znode_init(void)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   337
{
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   338
	/*
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   339
	 * Initialize zcache
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   340
	 */
9788
f660bc44f2e8 6843700 zfs_znode_move() does not ensure valid file system pointer
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 9396
diff changeset
   341
	rw_init(&zfsvfs_lock, NULL, RW_DEFAULT, NULL);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   342
	ASSERT(znode_cache == NULL);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   343
	znode_cache = kmem_cache_create("zfs_znode_cache",
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   344
	    sizeof (znode_t), 0, zfs_znode_cache_constructor,
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   345
	    zfs_znode_cache_destructor, NULL, NULL, NULL, 0);
6712
79afecec3f3c 6554564 slab allocator cannot release slabs with lonely buffers
tomee
parents: 6492
diff changeset
   346
	kmem_cache_set_move(znode_cache, zfs_znode_move);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   347
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   348
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   349
void
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   350
zfs_znode_fini(void)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   351
{
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   352
	/*
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   353
	 * Cleanup vfs & vnode ops
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   354
	 */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   355
	zfs_remove_op_tables();
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   356
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   357
	/*
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   358
	 * Cleanup zcache
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   359
	 */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   360
	if (znode_cache)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   361
		kmem_cache_destroy(znode_cache);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   362
	znode_cache = NULL;
9788
f660bc44f2e8 6843700 zfs_znode_move() does not ensure valid file system pointer
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 9396
diff changeset
   363
	rw_destroy(&zfsvfs_lock);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   364
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   365
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   366
struct vnodeops *zfs_dvnodeops;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   367
struct vnodeops *zfs_fvnodeops;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   368
struct vnodeops *zfs_symvnodeops;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   369
struct vnodeops *zfs_xdvnodeops;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   370
struct vnodeops *zfs_evnodeops;
8845
91af0d9c0790 6800942 smb_session_create() incorrectly stores IP addresses
Alan Wright <amw@Sun.COM>
parents: 8636
diff changeset
   371
struct vnodeops *zfs_sharevnodeops;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   372
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   373
void
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   374
zfs_remove_op_tables()
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   375
{
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   376
	/*
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   377
	 * Remove vfs ops
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   378
	 */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   379
	ASSERT(zfsfstype);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   380
	(void) vfs_freevfsops_by_type(zfsfstype);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   381
	zfsfstype = 0;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   382
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   383
	/*
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   384
	 * Remove vnode ops
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   385
	 */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   386
	if (zfs_dvnodeops)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   387
		vn_freevnodeops(zfs_dvnodeops);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   388
	if (zfs_fvnodeops)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   389
		vn_freevnodeops(zfs_fvnodeops);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   390
	if (zfs_symvnodeops)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   391
		vn_freevnodeops(zfs_symvnodeops);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   392
	if (zfs_xdvnodeops)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   393
		vn_freevnodeops(zfs_xdvnodeops);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   394
	if (zfs_evnodeops)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   395
		vn_freevnodeops(zfs_evnodeops);
8845
91af0d9c0790 6800942 smb_session_create() incorrectly stores IP addresses
Alan Wright <amw@Sun.COM>
parents: 8636
diff changeset
   396
	if (zfs_sharevnodeops)
91af0d9c0790 6800942 smb_session_create() incorrectly stores IP addresses
Alan Wright <amw@Sun.COM>
parents: 8636
diff changeset
   397
		vn_freevnodeops(zfs_sharevnodeops);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   398
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   399
	zfs_dvnodeops = NULL;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   400
	zfs_fvnodeops = NULL;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   401
	zfs_symvnodeops = NULL;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   402
	zfs_xdvnodeops = NULL;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   403
	zfs_evnodeops = NULL;
8845
91af0d9c0790 6800942 smb_session_create() incorrectly stores IP addresses
Alan Wright <amw@Sun.COM>
parents: 8636
diff changeset
   404
	zfs_sharevnodeops = NULL;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   405
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   406
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   407
extern const fs_operation_def_t zfs_dvnodeops_template[];
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   408
extern const fs_operation_def_t zfs_fvnodeops_template[];
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   409
extern const fs_operation_def_t zfs_xdvnodeops_template[];
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   410
extern const fs_operation_def_t zfs_symvnodeops_template[];
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   411
extern const fs_operation_def_t zfs_evnodeops_template[];
8845
91af0d9c0790 6800942 smb_session_create() incorrectly stores IP addresses
Alan Wright <amw@Sun.COM>
parents: 8636
diff changeset
   412
extern const fs_operation_def_t zfs_sharevnodeops_template[];
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   413
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   414
int
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   415
zfs_create_op_tables()
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   416
{
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   417
	int error;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   418
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   419
	/*
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   420
	 * zfs_dvnodeops can be set if mod_remove() calls mod_installfs()
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   421
	 * due to a failure to remove the the 2nd modlinkage (zfs_modldrv).
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   422
	 * In this case we just return as the ops vectors are already set up.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   423
	 */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   424
	if (zfs_dvnodeops)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   425
		return (0);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   426
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   427
	error = vn_make_ops(MNTTYPE_ZFS, zfs_dvnodeops_template,
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   428
	    &zfs_dvnodeops);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   429
	if (error)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   430
		return (error);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   431
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   432
	error = vn_make_ops(MNTTYPE_ZFS, zfs_fvnodeops_template,
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   433
	    &zfs_fvnodeops);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   434
	if (error)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   435
		return (error);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   436
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   437
	error = vn_make_ops(MNTTYPE_ZFS, zfs_symvnodeops_template,
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   438
	    &zfs_symvnodeops);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   439
	if (error)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   440
		return (error);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   441
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   442
	error = vn_make_ops(MNTTYPE_ZFS, zfs_xdvnodeops_template,
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   443
	    &zfs_xdvnodeops);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   444
	if (error)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   445
		return (error);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   446
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   447
	error = vn_make_ops(MNTTYPE_ZFS, zfs_evnodeops_template,
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   448
	    &zfs_evnodeops);
8845
91af0d9c0790 6800942 smb_session_create() incorrectly stores IP addresses
Alan Wright <amw@Sun.COM>
parents: 8636
diff changeset
   449
	if (error)
91af0d9c0790 6800942 smb_session_create() incorrectly stores IP addresses
Alan Wright <amw@Sun.COM>
parents: 8636
diff changeset
   450
		return (error);
91af0d9c0790 6800942 smb_session_create() incorrectly stores IP addresses
Alan Wright <amw@Sun.COM>
parents: 8636
diff changeset
   451
91af0d9c0790 6800942 smb_session_create() incorrectly stores IP addresses
Alan Wright <amw@Sun.COM>
parents: 8636
diff changeset
   452
	error = vn_make_ops(MNTTYPE_ZFS, zfs_sharevnodeops_template,
91af0d9c0790 6800942 smb_session_create() incorrectly stores IP addresses
Alan Wright <amw@Sun.COM>
parents: 8636
diff changeset
   453
	    &zfs_sharevnodeops);
91af0d9c0790 6800942 smb_session_create() incorrectly stores IP addresses
Alan Wright <amw@Sun.COM>
parents: 8636
diff changeset
   454
91af0d9c0790 6800942 smb_session_create() incorrectly stores IP addresses
Alan Wright <amw@Sun.COM>
parents: 8636
diff changeset
   455
	return (error);
91af0d9c0790 6800942 smb_session_create() incorrectly stores IP addresses
Alan Wright <amw@Sun.COM>
parents: 8636
diff changeset
   456
}
91af0d9c0790 6800942 smb_session_create() incorrectly stores IP addresses
Alan Wright <amw@Sun.COM>
parents: 8636
diff changeset
   457
9030
243fd360d81f 6815893 hang mounting a dataset after booting into a new boot environment
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 8845
diff changeset
   458
int
8845
91af0d9c0790 6800942 smb_session_create() incorrectly stores IP addresses
Alan Wright <amw@Sun.COM>
parents: 8636
diff changeset
   459
zfs_create_share_dir(zfsvfs_t *zfsvfs, dmu_tx_t *tx)
91af0d9c0790 6800942 smb_session_create() incorrectly stores IP addresses
Alan Wright <amw@Sun.COM>
parents: 8636
diff changeset
   460
{
9179
d8fbd96b79b3 6790064 zfs needs to determine uid and gid earlier in create process
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 9030
diff changeset
   461
	zfs_acl_ids_t acl_ids;
8845
91af0d9c0790 6800942 smb_session_create() incorrectly stores IP addresses
Alan Wright <amw@Sun.COM>
parents: 8636
diff changeset
   462
	vattr_t vattr;
91af0d9c0790 6800942 smb_session_create() incorrectly stores IP addresses
Alan Wright <amw@Sun.COM>
parents: 8636
diff changeset
   463
	znode_t *sharezp;
91af0d9c0790 6800942 smb_session_create() incorrectly stores IP addresses
Alan Wright <amw@Sun.COM>
parents: 8636
diff changeset
   464
	vnode_t *vp;
91af0d9c0790 6800942 smb_session_create() incorrectly stores IP addresses
Alan Wright <amw@Sun.COM>
parents: 8636
diff changeset
   465
	znode_t *zp;
91af0d9c0790 6800942 smb_session_create() incorrectly stores IP addresses
Alan Wright <amw@Sun.COM>
parents: 8636
diff changeset
   466
	int error;
91af0d9c0790 6800942 smb_session_create() incorrectly stores IP addresses
Alan Wright <amw@Sun.COM>
parents: 8636
diff changeset
   467
91af0d9c0790 6800942 smb_session_create() incorrectly stores IP addresses
Alan Wright <amw@Sun.COM>
parents: 8636
diff changeset
   468
	vattr.va_mask = AT_MODE|AT_UID|AT_GID|AT_TYPE;
91af0d9c0790 6800942 smb_session_create() incorrectly stores IP addresses
Alan Wright <amw@Sun.COM>
parents: 8636
diff changeset
   469
	vattr.va_type = VDIR;
91af0d9c0790 6800942 smb_session_create() incorrectly stores IP addresses
Alan Wright <amw@Sun.COM>
parents: 8636
diff changeset
   470
	vattr.va_mode = S_IFDIR|0555;
91af0d9c0790 6800942 smb_session_create() incorrectly stores IP addresses
Alan Wright <amw@Sun.COM>
parents: 8636
diff changeset
   471
	vattr.va_uid = crgetuid(kcred);
91af0d9c0790 6800942 smb_session_create() incorrectly stores IP addresses
Alan Wright <amw@Sun.COM>
parents: 8636
diff changeset
   472
	vattr.va_gid = crgetgid(kcred);
91af0d9c0790 6800942 smb_session_create() incorrectly stores IP addresses
Alan Wright <amw@Sun.COM>
parents: 8636
diff changeset
   473
91af0d9c0790 6800942 smb_session_create() incorrectly stores IP addresses
Alan Wright <amw@Sun.COM>
parents: 8636
diff changeset
   474
	sharezp = kmem_cache_alloc(znode_cache, KM_SLEEP);
91af0d9c0790 6800942 smb_session_create() incorrectly stores IP addresses
Alan Wright <amw@Sun.COM>
parents: 8636
diff changeset
   475
	sharezp->z_unlinked = 0;
91af0d9c0790 6800942 smb_session_create() incorrectly stores IP addresses
Alan Wright <amw@Sun.COM>
parents: 8636
diff changeset
   476
	sharezp->z_atime_dirty = 0;
91af0d9c0790 6800942 smb_session_create() incorrectly stores IP addresses
Alan Wright <amw@Sun.COM>
parents: 8636
diff changeset
   477
	sharezp->z_zfsvfs = zfsvfs;
91af0d9c0790 6800942 smb_session_create() incorrectly stores IP addresses
Alan Wright <amw@Sun.COM>
parents: 8636
diff changeset
   478
91af0d9c0790 6800942 smb_session_create() incorrectly stores IP addresses
Alan Wright <amw@Sun.COM>
parents: 8636
diff changeset
   479
	vp = ZTOV(sharezp);
91af0d9c0790 6800942 smb_session_create() incorrectly stores IP addresses
Alan Wright <amw@Sun.COM>
parents: 8636
diff changeset
   480
	vn_reinit(vp);
91af0d9c0790 6800942 smb_session_create() incorrectly stores IP addresses
Alan Wright <amw@Sun.COM>
parents: 8636
diff changeset
   481
	vp->v_type = VDIR;
91af0d9c0790 6800942 smb_session_create() incorrectly stores IP addresses
Alan Wright <amw@Sun.COM>
parents: 8636
diff changeset
   482
9179
d8fbd96b79b3 6790064 zfs needs to determine uid and gid earlier in create process
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 9030
diff changeset
   483
	VERIFY(0 == zfs_acl_ids_create(sharezp, IS_ROOT_NODE, &vattr,
d8fbd96b79b3 6790064 zfs needs to determine uid and gid earlier in create process
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 9030
diff changeset
   484
	    kcred, NULL, &acl_ids));
8845
91af0d9c0790 6800942 smb_session_create() incorrectly stores IP addresses
Alan Wright <amw@Sun.COM>
parents: 8636
diff changeset
   485
	zfs_mknode(sharezp, &vattr, tx, kcred, IS_ROOT_NODE,
9179
d8fbd96b79b3 6790064 zfs needs to determine uid and gid earlier in create process
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 9030
diff changeset
   486
	    &zp, 0, &acl_ids);
8845
91af0d9c0790 6800942 smb_session_create() incorrectly stores IP addresses
Alan Wright <amw@Sun.COM>
parents: 8636
diff changeset
   487
	ASSERT3P(zp, ==, sharezp);
91af0d9c0790 6800942 smb_session_create() incorrectly stores IP addresses
Alan Wright <amw@Sun.COM>
parents: 8636
diff changeset
   488
	ASSERT(!vn_in_dnlc(ZTOV(sharezp))); /* not valid to move */
91af0d9c0790 6800942 smb_session_create() incorrectly stores IP addresses
Alan Wright <amw@Sun.COM>
parents: 8636
diff changeset
   489
	POINTER_INVALIDATE(&sharezp->z_zfsvfs);
91af0d9c0790 6800942 smb_session_create() incorrectly stores IP addresses
Alan Wright <amw@Sun.COM>
parents: 8636
diff changeset
   490
	error = zap_add(zfsvfs->z_os, MASTER_NODE_OBJ,
91af0d9c0790 6800942 smb_session_create() incorrectly stores IP addresses
Alan Wright <amw@Sun.COM>
parents: 8636
diff changeset
   491
	    ZFS_SHARES_DIR, 8, 1, &sharezp->z_id, tx);
91af0d9c0790 6800942 smb_session_create() incorrectly stores IP addresses
Alan Wright <amw@Sun.COM>
parents: 8636
diff changeset
   492
	zfsvfs->z_shares_dir = sharezp->z_id;
91af0d9c0790 6800942 smb_session_create() incorrectly stores IP addresses
Alan Wright <amw@Sun.COM>
parents: 8636
diff changeset
   493
9179
d8fbd96b79b3 6790064 zfs needs to determine uid and gid earlier in create process
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 9030
diff changeset
   494
	zfs_acl_ids_free(&acl_ids);
8845
91af0d9c0790 6800942 smb_session_create() incorrectly stores IP addresses
Alan Wright <amw@Sun.COM>
parents: 8636
diff changeset
   495
	ZTOV(sharezp)->v_count = 0;
91af0d9c0790 6800942 smb_session_create() incorrectly stores IP addresses
Alan Wright <amw@Sun.COM>
parents: 8636
diff changeset
   496
	dmu_buf_rele(sharezp->z_dbuf, NULL);
91af0d9c0790 6800942 smb_session_create() incorrectly stores IP addresses
Alan Wright <amw@Sun.COM>
parents: 8636
diff changeset
   497
	sharezp->z_dbuf = NULL;
91af0d9c0790 6800942 smb_session_create() incorrectly stores IP addresses
Alan Wright <amw@Sun.COM>
parents: 8636
diff changeset
   498
	kmem_cache_free(znode_cache, sharezp);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   499
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   500
	return (error);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   501
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   502
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   503
/*
1816
8c14b56c8515 6408482 64-bit system can't read some 32-bit dev_ts created on zfs
marks
parents: 1760
diff changeset
   504
 * 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
   505
 * 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
   506
 */
8c14b56c8515 6408482 64-bit system can't read some 32-bit dev_ts created on zfs
marks
parents: 1760
diff changeset
   507
#ifndef NBITSMINOR64
8c14b56c8515 6408482 64-bit system can't read some 32-bit dev_ts created on zfs
marks
parents: 1760
diff changeset
   508
#define	NBITSMINOR64	32
8c14b56c8515 6408482 64-bit system can't read some 32-bit dev_ts created on zfs
marks
parents: 1760
diff changeset
   509
#endif
8c14b56c8515 6408482 64-bit system can't read some 32-bit dev_ts created on zfs
marks
parents: 1760
diff changeset
   510
#ifndef MAXMAJ64
8c14b56c8515 6408482 64-bit system can't read some 32-bit dev_ts created on zfs
marks
parents: 1760
diff changeset
   511
#define	MAXMAJ64	0xffffffffUL
8c14b56c8515 6408482 64-bit system can't read some 32-bit dev_ts created on zfs
marks
parents: 1760
diff changeset
   512
#endif
8c14b56c8515 6408482 64-bit system can't read some 32-bit dev_ts created on zfs
marks
parents: 1760
diff changeset
   513
#ifndef	MAXMIN64
8c14b56c8515 6408482 64-bit system can't read some 32-bit dev_ts created on zfs
marks
parents: 1760
diff changeset
   514
#define	MAXMIN64	0xffffffffUL
8c14b56c8515 6408482 64-bit system can't read some 32-bit dev_ts created on zfs
marks
parents: 1760
diff changeset
   515
#endif
8c14b56c8515 6408482 64-bit system can't read some 32-bit dev_ts created on zfs
marks
parents: 1760
diff changeset
   516
8c14b56c8515 6408482 64-bit system can't read some 32-bit dev_ts created on zfs
marks
parents: 1760
diff changeset
   517
/*
8c14b56c8515 6408482 64-bit system can't read some 32-bit dev_ts created on zfs
marks
parents: 1760
diff changeset
   518
 * 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
   519
 * 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
   520
 * 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
   521
 * 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
   522
 * 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
   523
 * 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
   524
 */
8c14b56c8515 6408482 64-bit system can't read some 32-bit dev_ts created on zfs
marks
parents: 1760
diff changeset
   525
static uint64_t
8c14b56c8515 6408482 64-bit system can't read some 32-bit dev_ts created on zfs
marks
parents: 1760
diff changeset
   526
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
   527
{
8c14b56c8515 6408482 64-bit system can't read some 32-bit dev_ts created on zfs
marks
parents: 1760
diff changeset
   528
#ifndef _LP64
8c14b56c8515 6408482 64-bit system can't read some 32-bit dev_ts created on zfs
marks
parents: 1760
diff changeset
   529
	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
   530
	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
   531
	    ((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
   532
#else
8c14b56c8515 6408482 64-bit system can't read some 32-bit dev_ts created on zfs
marks
parents: 1760
diff changeset
   533
	return (dev);
8c14b56c8515 6408482 64-bit system can't read some 32-bit dev_ts created on zfs
marks
parents: 1760
diff changeset
   534
#endif
8c14b56c8515 6408482 64-bit system can't read some 32-bit dev_ts created on zfs
marks
parents: 1760
diff changeset
   535
}
8c14b56c8515 6408482 64-bit system can't read some 32-bit dev_ts created on zfs
marks
parents: 1760
diff changeset
   536
8c14b56c8515 6408482 64-bit system can't read some 32-bit dev_ts created on zfs
marks
parents: 1760
diff changeset
   537
/*
8c14b56c8515 6408482 64-bit system can't read some 32-bit dev_ts created on zfs
marks
parents: 1760
diff changeset
   538
 * 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
   539
 * 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
   540
 * 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
   541
 * 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
   542
 * 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
   543
 */
8c14b56c8515 6408482 64-bit system can't read some 32-bit dev_ts created on zfs
marks
parents: 1760
diff changeset
   544
dev_t
8c14b56c8515 6408482 64-bit system can't read some 32-bit dev_ts created on zfs
marks
parents: 1760
diff changeset
   545
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
   546
{
8c14b56c8515 6408482 64-bit system can't read some 32-bit dev_ts created on zfs
marks
parents: 1760
diff changeset
   547
#ifndef _LP64
8c14b56c8515 6408482 64-bit system can't read some 32-bit dev_ts created on zfs
marks
parents: 1760
diff changeset
   548
	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
   549
	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
   550
8c14b56c8515 6408482 64-bit system can't read some 32-bit dev_ts created on zfs
marks
parents: 1760
diff changeset
   551
	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
   552
		return (NODEV32);
8c14b56c8515 6408482 64-bit system can't read some 32-bit dev_ts created on zfs
marks
parents: 1760
diff changeset
   553
8c14b56c8515 6408482 64-bit system can't read some 32-bit dev_ts created on zfs
marks
parents: 1760
diff changeset
   554
	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
   555
#else
8c14b56c8515 6408482 64-bit system can't read some 32-bit dev_ts created on zfs
marks
parents: 1760
diff changeset
   556
	return (dev);
8c14b56c8515 6408482 64-bit system can't read some 32-bit dev_ts created on zfs
marks
parents: 1760
diff changeset
   557
#endif
8c14b56c8515 6408482 64-bit system can't read some 32-bit dev_ts created on zfs
marks
parents: 1760
diff changeset
   558
}
8c14b56c8515 6408482 64-bit system can't read some 32-bit dev_ts created on zfs
marks
parents: 1760
diff changeset
   559
5446
51fbc14b301d 6421210 zfs rollback without unmounting
ahrens
parents: 5331
diff changeset
   560
static void
6712
79afecec3f3c 6554564 slab allocator cannot release slabs with lonely buffers
tomee
parents: 6492
diff changeset
   561
zfs_znode_dmu_init(zfsvfs_t *zfsvfs, znode_t *zp, dmu_buf_t *db)
5446
51fbc14b301d 6421210 zfs rollback without unmounting
ahrens
parents: 5331
diff changeset
   562
{
51fbc14b301d 6421210 zfs rollback without unmounting
ahrens
parents: 5331
diff changeset
   563
	znode_t		*nzp;
51fbc14b301d 6421210 zfs rollback without unmounting
ahrens
parents: 5331
diff changeset
   564
6712
79afecec3f3c 6554564 slab allocator cannot release slabs with lonely buffers
tomee
parents: 6492
diff changeset
   565
	ASSERT(!POINTER_IS_VALID(zp->z_zfsvfs) || (zfsvfs == zp->z_zfsvfs));
79afecec3f3c 6554564 slab allocator cannot release slabs with lonely buffers
tomee
parents: 6492
diff changeset
   566
	ASSERT(MUTEX_HELD(ZFS_OBJ_MUTEX(zfsvfs, zp->z_id)));
5446
51fbc14b301d 6421210 zfs rollback without unmounting
ahrens
parents: 5331
diff changeset
   567
51fbc14b301d 6421210 zfs rollback without unmounting
ahrens
parents: 5331
diff changeset
   568
	mutex_enter(&zp->z_lock);
51fbc14b301d 6421210 zfs rollback without unmounting
ahrens
parents: 5331
diff changeset
   569
51fbc14b301d 6421210 zfs rollback without unmounting
ahrens
parents: 5331
diff changeset
   570
	ASSERT(zp->z_dbuf == NULL);
10269
2788675568fd 6868276 zfs_rezget() can be hazardous when znode has a cached ACL
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 10250
diff changeset
   571
	ASSERT(zp->z_acl_cached == NULL);
5446
51fbc14b301d 6421210 zfs rollback without unmounting
ahrens
parents: 5331
diff changeset
   572
	zp->z_dbuf = db;
5642
504c84876fda 6513209 Destroying pools under stress caused a hang in arc_flush
maybee
parents: 5520
diff changeset
   573
	nzp = dmu_buf_set_user_ie(db, zp, &zp->z_phys, znode_evict_error);
5446
51fbc14b301d 6421210 zfs rollback without unmounting
ahrens
parents: 5331
diff changeset
   574
51fbc14b301d 6421210 zfs rollback without unmounting
ahrens
parents: 5331
diff changeset
   575
	/*
51fbc14b301d 6421210 zfs rollback without unmounting
ahrens
parents: 5331
diff changeset
   576
	 * there should be no
51fbc14b301d 6421210 zfs rollback without unmounting
ahrens
parents: 5331
diff changeset
   577
	 * concurrent zgets on this object.
51fbc14b301d 6421210 zfs rollback without unmounting
ahrens
parents: 5331
diff changeset
   578
	 */
51fbc14b301d 6421210 zfs rollback without unmounting
ahrens
parents: 5331
diff changeset
   579
	if (nzp != NULL)
7240
c4957ab6a78e 6698108 Sun Studio 12 finds many lint errors in ON source.
rh87107
parents: 7046
diff changeset
   580
		panic("existing znode %p for dbuf %p", (void *)nzp, (void *)db);
5446
51fbc14b301d 6421210 zfs rollback without unmounting
ahrens
parents: 5331
diff changeset
   581
51fbc14b301d 6421210 zfs rollback without unmounting
ahrens
parents: 5331
diff changeset
   582
	/*
51fbc14b301d 6421210 zfs rollback without unmounting
ahrens
parents: 5331
diff changeset
   583
	 * Slap on VROOT if we are the root znode
51fbc14b301d 6421210 zfs rollback without unmounting
ahrens
parents: 5331
diff changeset
   584
	 */
51fbc14b301d 6421210 zfs rollback without unmounting
ahrens
parents: 5331
diff changeset
   585
	if (zp->z_id == zfsvfs->z_root)
51fbc14b301d 6421210 zfs rollback without unmounting
ahrens
parents: 5331
diff changeset
   586
		ZTOV(zp)->v_flag |= VROOT;
51fbc14b301d 6421210 zfs rollback without unmounting
ahrens
parents: 5331
diff changeset
   587
51fbc14b301d 6421210 zfs rollback without unmounting
ahrens
parents: 5331
diff changeset
   588
	mutex_exit(&zp->z_lock);
51fbc14b301d 6421210 zfs rollback without unmounting
ahrens
parents: 5331
diff changeset
   589
	vn_exists(ZTOV(zp));
51fbc14b301d 6421210 zfs rollback without unmounting
ahrens
parents: 5331
diff changeset
   590
}
51fbc14b301d 6421210 zfs rollback without unmounting
ahrens
parents: 5331
diff changeset
   591
5642
504c84876fda 6513209 Destroying pools under stress caused a hang in arc_flush
maybee
parents: 5520
diff changeset
   592
void
5446
51fbc14b301d 6421210 zfs rollback without unmounting
ahrens
parents: 5331
diff changeset
   593
zfs_znode_dmu_fini(znode_t *zp)
51fbc14b301d 6421210 zfs rollback without unmounting
ahrens
parents: 5331
diff changeset
   594
{
51fbc14b301d 6421210 zfs rollback without unmounting
ahrens
parents: 5331
diff changeset
   595
	dmu_buf_t *db = zp->z_dbuf;
6712
79afecec3f3c 6554564 slab allocator cannot release slabs with lonely buffers
tomee
parents: 6492
diff changeset
   596
	ASSERT(MUTEX_HELD(ZFS_OBJ_MUTEX(zp->z_zfsvfs, zp->z_id)) ||
79afecec3f3c 6554564 slab allocator cannot release slabs with lonely buffers
tomee
parents: 6492
diff changeset
   597
	    zp->z_unlinked ||
5642
504c84876fda 6513209 Destroying pools under stress caused a hang in arc_flush
maybee
parents: 5520
diff changeset
   598
	    RW_WRITE_HELD(&zp->z_zfsvfs->z_teardown_inactive_lock));
5446
51fbc14b301d 6421210 zfs rollback without unmounting
ahrens
parents: 5331
diff changeset
   599
	ASSERT(zp->z_dbuf != NULL);
51fbc14b301d 6421210 zfs rollback without unmounting
ahrens
parents: 5331
diff changeset
   600
	zp->z_dbuf = NULL;
5642
504c84876fda 6513209 Destroying pools under stress caused a hang in arc_flush
maybee
parents: 5520
diff changeset
   601
	VERIFY(zp == dmu_buf_update_user(db, zp, NULL, NULL, NULL));
5446
51fbc14b301d 6421210 zfs rollback without unmounting
ahrens
parents: 5331
diff changeset
   602
	dmu_buf_rele(db, NULL);
51fbc14b301d 6421210 zfs rollback without unmounting
ahrens
parents: 5331
diff changeset
   603
}
51fbc14b301d 6421210 zfs rollback without unmounting
ahrens
parents: 5331
diff changeset
   604
1816
8c14b56c8515 6408482 64-bit system can't read some 32-bit dev_ts created on zfs
marks
parents: 1760
diff changeset
   605
/*
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   606
 * Construct a new znode/vnode and intialize.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   607
 *
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   608
 * This does not do a call to dmu_set_user() that is
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   609
 * up to the caller to do, in case you don't want to
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   610
 * return the znode
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   611
 */
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1394
diff changeset
   612
static znode_t *
5446
51fbc14b301d 6421210 zfs rollback without unmounting
ahrens
parents: 5331
diff changeset
   613
zfs_znode_alloc(zfsvfs_t *zfsvfs, dmu_buf_t *db, int blksz)
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   614
{
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   615
	znode_t	*zp;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   616
	vnode_t *vp;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   617
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   618
	zp = kmem_cache_alloc(znode_cache, KM_SLEEP);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   619
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   620
	ASSERT(zp->z_dirlocks == NULL);
5446
51fbc14b301d 6421210 zfs rollback without unmounting
ahrens
parents: 5331
diff changeset
   621
	ASSERT(zp->z_dbuf == NULL);
6712
79afecec3f3c 6554564 slab allocator cannot release slabs with lonely buffers
tomee
parents: 6492
diff changeset
   622
	ASSERT(!POINTER_IS_VALID(zp->z_zfsvfs));
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   623
6712
79afecec3f3c 6554564 slab allocator cannot release slabs with lonely buffers
tomee
parents: 6492
diff changeset
   624
	/*
79afecec3f3c 6554564 slab allocator cannot release slabs with lonely buffers
tomee
parents: 6492
diff changeset
   625
	 * Defer setting z_zfsvfs until the znode is ready to be a candidate for
79afecec3f3c 6554564 slab allocator cannot release slabs with lonely buffers
tomee
parents: 6492
diff changeset
   626
	 * the zfs_znode_move() callback.
79afecec3f3c 6554564 slab allocator cannot release slabs with lonely buffers
tomee
parents: 6492
diff changeset
   627
	 */
5446
51fbc14b301d 6421210 zfs rollback without unmounting
ahrens
parents: 5331
diff changeset
   628
	zp->z_phys = NULL;
3461
c19b22f347d6 6514331 in-memory delete queue is not needed
ahrens
parents: 3444
diff changeset
   629
	zp->z_unlinked = 0;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   630
	zp->z_atime_dirty = 0;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   631
	zp->z_mapcnt = 0;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   632
	zp->z_last_itx = 0;
5446
51fbc14b301d 6421210 zfs rollback without unmounting
ahrens
parents: 5331
diff changeset
   633
	zp->z_id = db->db_object;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   634
	zp->z_blksz = blksz;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   635
	zp->z_seq = 0x7A4653;
3063
b252896b372b 6341569 zio_alloc_blk() vdev distribution performs badly
perrin
parents: 2885
diff changeset
   636
	zp->z_sync_cnt = 0;
5446
51fbc14b301d 6421210 zfs rollback without unmounting
ahrens
parents: 5331
diff changeset
   637
51fbc14b301d 6421210 zfs rollback without unmounting
ahrens
parents: 5331
diff changeset
   638
	vp = ZTOV(zp);
51fbc14b301d 6421210 zfs rollback without unmounting
ahrens
parents: 5331
diff changeset
   639
	vn_reinit(vp);
51fbc14b301d 6421210 zfs rollback without unmounting
ahrens
parents: 5331
diff changeset
   640
6712
79afecec3f3c 6554564 slab allocator cannot release slabs with lonely buffers
tomee
parents: 6492
diff changeset
   641
	zfs_znode_dmu_init(zfsvfs, zp, db);
5446
51fbc14b301d 6421210 zfs rollback without unmounting
ahrens
parents: 5331
diff changeset
   642
5326
6752aa2bd5bc 6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents: 4831
diff changeset
   643
	zp->z_gen = zp->z_phys->zp_gen;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   644
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   645
	vp->v_vfsp = zfsvfs->z_parent->z_vfs;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   646
	vp->v_type = IFTOVT((mode_t)zp->z_phys->zp_mode);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   647
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   648
	switch (vp->v_type) {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   649
	case VDIR:
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   650
		if (zp->z_phys->zp_flags & ZFS_XATTR) {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   651
			vn_setops(vp, zfs_xdvnodeops);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   652
			vp->v_flag |= V_XATTRDIR;
5446
51fbc14b301d 6421210 zfs rollback without unmounting
ahrens
parents: 5331
diff changeset
   653
		} else {
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   654
			vn_setops(vp, zfs_dvnodeops);
5446
51fbc14b301d 6421210 zfs rollback without unmounting
ahrens
parents: 5331
diff changeset
   655
		}
869
dc133b87dfb3 6297285 znode prefetching in zfs_readdir causes 5x performance degradation for 'ls'
perrin
parents: 789
diff changeset
   656
		zp->z_zn_prefetch = B_TRUE; /* z_prefetch default is enabled */
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   657
		break;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   658
	case VBLK:
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   659
	case VCHR:
1816
8c14b56c8515 6408482 64-bit system can't read some 32-bit dev_ts created on zfs
marks
parents: 1760
diff changeset
   660
		vp->v_rdev = zfs_cmpldev(zp->z_phys->zp_rdev);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   661
		/*FALLTHROUGH*/
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   662
	case VFIFO:
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   663
	case VSOCK:
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   664
	case VDOOR:
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   665
		vn_setops(vp, zfs_fvnodeops);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   666
		break;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   667
	case VREG:
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   668
		vp->v_flag |= VMODSORT;
8845
91af0d9c0790 6800942 smb_session_create() incorrectly stores IP addresses
Alan Wright <amw@Sun.COM>
parents: 8636
diff changeset
   669
		if (zp->z_phys->zp_parent == zfsvfs->z_shares_dir)
91af0d9c0790 6800942 smb_session_create() incorrectly stores IP addresses
Alan Wright <amw@Sun.COM>
parents: 8636
diff changeset
   670
			vn_setops(vp, zfs_sharevnodeops);
91af0d9c0790 6800942 smb_session_create() incorrectly stores IP addresses
Alan Wright <amw@Sun.COM>
parents: 8636
diff changeset
   671
		else
91af0d9c0790 6800942 smb_session_create() incorrectly stores IP addresses
Alan Wright <amw@Sun.COM>
parents: 8636
diff changeset
   672
			vn_setops(vp, zfs_fvnodeops);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   673
		break;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   674
	case VLNK:
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   675
		vn_setops(vp, zfs_symvnodeops);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   676
		break;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   677
	default:
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   678
		vn_setops(vp, zfs_evnodeops);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   679
		break;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   680
	}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   681
6712
79afecec3f3c 6554564 slab allocator cannot release slabs with lonely buffers
tomee
parents: 6492
diff changeset
   682
	mutex_enter(&zfsvfs->z_znodes_lock);
79afecec3f3c 6554564 slab allocator cannot release slabs with lonely buffers
tomee
parents: 6492
diff changeset
   683
	list_insert_tail(&zfsvfs->z_all_znodes, zp);
79afecec3f3c 6554564 slab allocator cannot release slabs with lonely buffers
tomee
parents: 6492
diff changeset
   684
	membar_producer();
79afecec3f3c 6554564 slab allocator cannot release slabs with lonely buffers
tomee
parents: 6492
diff changeset
   685
	/*
79afecec3f3c 6554564 slab allocator cannot release slabs with lonely buffers
tomee
parents: 6492
diff changeset
   686
	 * Everything else must be valid before assigning z_zfsvfs makes the
79afecec3f3c 6554564 slab allocator cannot release slabs with lonely buffers
tomee
parents: 6492
diff changeset
   687
	 * znode eligible for zfs_znode_move().
79afecec3f3c 6554564 slab allocator cannot release slabs with lonely buffers
tomee
parents: 6492
diff changeset
   688
	 */
79afecec3f3c 6554564 slab allocator cannot release slabs with lonely buffers
tomee
parents: 6492
diff changeset
   689
	zp->z_zfsvfs = zfsvfs;
79afecec3f3c 6554564 slab allocator cannot release slabs with lonely buffers
tomee
parents: 6492
diff changeset
   690
	mutex_exit(&zfsvfs->z_znodes_lock);
79afecec3f3c 6554564 slab allocator cannot release slabs with lonely buffers
tomee
parents: 6492
diff changeset
   691
5642
504c84876fda 6513209 Destroying pools under stress caused a hang in arc_flush
maybee
parents: 5520
diff changeset
   692
	VFS_HOLD(zfsvfs->z_vfs);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   693
	return (zp);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   694
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   695
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   696
/*
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   697
 * Create a new DMU object to hold a zfs znode.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   698
 *
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   699
 *	IN:	dzp	- parent directory for new znode
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   700
 *		vap	- file attributes for new znode
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   701
 *		tx	- dmu transaction id for zap operations
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   702
 *		cr	- credentials of caller
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   703
 *		flag	- flags:
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   704
 *			  IS_ROOT_NODE	- new object will be root
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   705
 *			  IS_XATTR	- new object is an attribute
5331
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5326
diff changeset
   706
 *		bonuslen - length of bonus buffer
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5326
diff changeset
   707
 *		setaclp  - File/Dir initial ACL
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5326
diff changeset
   708
 *		fuidp	 - Tracks fuid allocation.
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   709
 *
5446
51fbc14b301d 6421210 zfs rollback without unmounting
ahrens
parents: 5331
diff changeset
   710
 *	OUT:	zpp	- allocated znode
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   711
 *
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   712
 */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   713
void
5446
51fbc14b301d 6421210 zfs rollback without unmounting
ahrens
parents: 5331
diff changeset
   714
zfs_mknode(znode_t *dzp, vattr_t *vap, dmu_tx_t *tx, cred_t *cr,
9179
d8fbd96b79b3 6790064 zfs needs to determine uid and gid earlier in create process
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 9030
diff changeset
   715
    uint_t flag, znode_t **zpp, int bonuslen, zfs_acl_ids_t *acl_ids)
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   716
{
5446
51fbc14b301d 6421210 zfs rollback without unmounting
ahrens
parents: 5331
diff changeset
   717
	dmu_buf_t	*db;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   718
	znode_phys_t	*pzp;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   719
	zfsvfs_t	*zfsvfs = dzp->z_zfsvfs;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   720
	timestruc_t	now;
5446
51fbc14b301d 6421210 zfs rollback without unmounting
ahrens
parents: 5331
diff changeset
   721
	uint64_t	gen, obj;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   722
	int		err;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   723
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   724
	ASSERT(vap && (vap->va_mask & (AT_TYPE|AT_MODE)) == (AT_TYPE|AT_MODE));
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   725
8227
f7d7be9b1f56 6765294 Refactor replay
Neil Perrin <Neil.Perrin@Sun.COM>
parents: 7579
diff changeset
   726
	if (zfsvfs->z_replay) {
5446
51fbc14b301d 6421210 zfs rollback without unmounting
ahrens
parents: 5331
diff changeset
   727
		obj = vap->va_nodeid;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   728
		now = vap->va_ctime;		/* see zfs_replay_create() */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   729
		gen = vap->va_nblocks;		/* ditto */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   730
	} else {
5446
51fbc14b301d 6421210 zfs rollback without unmounting
ahrens
parents: 5331
diff changeset
   731
		obj = 0;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   732
		gethrestime(&now);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   733
		gen = dmu_tx_get_txg(tx);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   734
	}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   735
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   736
	/*
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   737
	 * Create a new DMU object.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   738
	 */
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1394
diff changeset
   739
	/*
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1394
diff changeset
   740
	 * There's currently no mechanism for pre-reading the blocks that will
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1394
diff changeset
   741
	 * be to needed allocate a new object, so we accept the small chance
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1394
diff changeset
   742
	 * 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
   743
	 * assertions below.
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1394
diff changeset
   744
	 */
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   745
	if (vap->va_type == VDIR) {
11249
6c30f7dfc97b 6906110 bad trap panic in zil_replay_log_record
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 10938
diff changeset
   746
		if (zfsvfs->z_replay) {
5446
51fbc14b301d 6421210 zfs rollback without unmounting
ahrens
parents: 5331
diff changeset
   747
			err = zap_create_claim_norm(zfsvfs->z_os, obj,
5331
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5326
diff changeset
   748
			    zfsvfs->z_norm, DMU_OT_DIRECTORY_CONTENTS,
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   749
			    DMU_OT_ZNODE, sizeof (znode_phys_t) + bonuslen, tx);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   750
			ASSERT3U(err, ==, 0);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   751
		} else {
5446
51fbc14b301d 6421210 zfs rollback without unmounting
ahrens
parents: 5331
diff changeset
   752
			obj = zap_create_norm(zfsvfs->z_os,
5331
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5326
diff changeset
   753
			    zfsvfs->z_norm, DMU_OT_DIRECTORY_CONTENTS,
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   754
			    DMU_OT_ZNODE, sizeof (znode_phys_t) + bonuslen, tx);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   755
		}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   756
	} else {
11249
6c30f7dfc97b 6906110 bad trap panic in zil_replay_log_record
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 10938
diff changeset
   757
		if (zfsvfs->z_replay) {
5446
51fbc14b301d 6421210 zfs rollback without unmounting
ahrens
parents: 5331
diff changeset
   758
			err = dmu_object_claim(zfsvfs->z_os, obj,
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   759
			    DMU_OT_PLAIN_FILE_CONTENTS, 0,
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   760
			    DMU_OT_ZNODE, sizeof (znode_phys_t) + bonuslen, tx);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   761
			ASSERT3U(err, ==, 0);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   762
		} else {
5446
51fbc14b301d 6421210 zfs rollback without unmounting
ahrens
parents: 5331
diff changeset
   763
			obj = dmu_object_alloc(zfsvfs->z_os,
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   764
			    DMU_OT_PLAIN_FILE_CONTENTS, 0,
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   765
			    DMU_OT_ZNODE, sizeof (znode_phys_t) + bonuslen, tx);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   766
		}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   767
	}
10938
270624bd70f1 6895088 panic: existing znode ffffff84e4747da0 for dbuf ffffff8271678e18
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 10793
diff changeset
   768
270624bd70f1 6895088 panic: existing znode ffffff84e4747da0 for dbuf ffffff8271678e18
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 10793
diff changeset
   769
	ZFS_OBJ_HOLD_ENTER(zfsvfs, obj);
5446
51fbc14b301d 6421210 zfs rollback without unmounting
ahrens
parents: 5331
diff changeset
   770
	VERIFY(0 == dmu_bonus_hold(zfsvfs->z_os, obj, NULL, &db));
51fbc14b301d 6421210 zfs rollback without unmounting
ahrens
parents: 5331
diff changeset
   771
	dmu_buf_will_dirty(db, tx);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   772
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   773
	/*
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   774
	 * Initialize the znode physical data to zero.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   775
	 */
5446
51fbc14b301d 6421210 zfs rollback without unmounting
ahrens
parents: 5331
diff changeset
   776
	ASSERT(db->db_size >= sizeof (znode_phys_t));
51fbc14b301d 6421210 zfs rollback without unmounting
ahrens
parents: 5331
diff changeset
   777
	bzero(db->db_data, db->db_size);
51fbc14b301d 6421210 zfs rollback without unmounting
ahrens
parents: 5331
diff changeset
   778
	pzp = db->db_data;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   779
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   780
	/*
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   781
	 * If this is the root, fix up the half-initialized parent pointer
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   782
	 * to reference the just-allocated physical data area.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   783
	 */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   784
	if (flag & IS_ROOT_NODE) {
5642
504c84876fda 6513209 Destroying pools under stress caused a hang in arc_flush
maybee
parents: 5520
diff changeset
   785
		dzp->z_dbuf = db;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   786
		dzp->z_phys = pzp;
5446
51fbc14b301d 6421210 zfs rollback without unmounting
ahrens
parents: 5331
diff changeset
   787
		dzp->z_id = obj;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   788
	}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   790
	/*
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   791
	 * If parent is an xattr, so am I.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   792
	 */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   793
	if (dzp->z_phys->zp_flags & ZFS_XATTR)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   794
		flag |= IS_XATTR;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   795
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   796
	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
   797
		pzp->zp_rdev = zfs_expldev(vap->va_rdev);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   798
	}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   799
5331
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5326
diff changeset
   800
	if (zfsvfs->z_use_fuids)
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5326
diff changeset
   801
		pzp->zp_flags = ZFS_ARCHIVE | ZFS_AV_MODIFIED;
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5326
diff changeset
   802
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   803
	if (vap->va_type == VDIR) {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   804
		pzp->zp_size = 2;		/* contents ("." and "..") */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   805
		pzp->zp_links = (flag & (IS_ROOT_NODE | IS_XATTR)) ? 2 : 1;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   806
	}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   807
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   808
	pzp->zp_parent = dzp->z_id;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   809
	if (flag & IS_XATTR)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   810
		pzp->zp_flags |= ZFS_XATTR;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   811
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   812
	pzp->zp_gen = gen;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   813
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   814
	ZFS_TIME_ENCODE(&now, pzp->zp_crtime);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   815
	ZFS_TIME_ENCODE(&now, pzp->zp_ctime);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   816
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   817
	if (vap->va_mask & AT_ATIME) {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   818
		ZFS_TIME_ENCODE(&vap->va_atime, pzp->zp_atime);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   819
	} else {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   820
		ZFS_TIME_ENCODE(&now, pzp->zp_atime);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   821
	}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   822
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   823
	if (vap->va_mask & AT_MTIME) {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   824
		ZFS_TIME_ENCODE(&vap->va_mtime, pzp->zp_mtime);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   825
	} else {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   826
		ZFS_TIME_ENCODE(&now, pzp->zp_mtime);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   827
	}
10938
270624bd70f1 6895088 panic: existing znode ffffff84e4747da0 for dbuf ffffff8271678e18
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 10793
diff changeset
   828
	pzp->zp_uid = acl_ids->z_fuid;
270624bd70f1 6895088 panic: existing znode ffffff84e4747da0 for dbuf ffffff8271678e18
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 10793
diff changeset
   829
	pzp->zp_gid = acl_ids->z_fgid;
270624bd70f1 6895088 panic: existing znode ffffff84e4747da0 for dbuf ffffff8271678e18
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 10793
diff changeset
   830
	pzp->zp_mode = acl_ids->z_mode;
5642
504c84876fda 6513209 Destroying pools under stress caused a hang in arc_flush
maybee
parents: 5520
diff changeset
   831
	if (!(flag & IS_ROOT_NODE)) {
504c84876fda 6513209 Destroying pools under stress caused a hang in arc_flush
maybee
parents: 5520
diff changeset
   832
		*zpp = zfs_znode_alloc(zfsvfs, db, 0);
504c84876fda 6513209 Destroying pools under stress caused a hang in arc_flush
maybee
parents: 5520
diff changeset
   833
	} else {
504c84876fda 6513209 Destroying pools under stress caused a hang in arc_flush
maybee
parents: 5520
diff changeset
   834
		/*
504c84876fda 6513209 Destroying pools under stress caused a hang in arc_flush
maybee
parents: 5520
diff changeset
   835
		 * If we are creating the root node, the "parent" we
504c84876fda 6513209 Destroying pools under stress caused a hang in arc_flush
maybee
parents: 5520
diff changeset
   836
		 * passed in is the znode for the root.
504c84876fda 6513209 Destroying pools under stress caused a hang in arc_flush
maybee
parents: 5520
diff changeset
   837
		 */
504c84876fda 6513209 Destroying pools under stress caused a hang in arc_flush
maybee
parents: 5520
diff changeset
   838
		*zpp = dzp;
504c84876fda 6513209 Destroying pools under stress caused a hang in arc_flush
maybee
parents: 5520
diff changeset
   839
	}
9179
d8fbd96b79b3 6790064 zfs needs to determine uid and gid earlier in create process
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 9030
diff changeset
   840
	VERIFY(0 == zfs_aclset_common(*zpp, acl_ids->z_aclp, cr, tx));
d8fbd96b79b3 6790064 zfs needs to determine uid and gid earlier in create process
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 9030
diff changeset
   841
	if (vap->va_mask & AT_XVATTR)
d8fbd96b79b3 6790064 zfs needs to determine uid and gid earlier in create process
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 9030
diff changeset
   842
		zfs_xvattr_set(*zpp, (xvattr_t *)vap);
10938
270624bd70f1 6895088 panic: existing znode ffffff84e4747da0 for dbuf ffffff8271678e18
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 10793
diff changeset
   843
270624bd70f1 6895088 panic: existing znode ffffff84e4747da0 for dbuf ffffff8271678e18
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 10793
diff changeset
   844
	ZFS_OBJ_HOLD_EXIT(zfsvfs, obj);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   845
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   846
5331
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5326
diff changeset
   847
void
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5326
diff changeset
   848
zfs_xvattr_set(znode_t *zp, xvattr_t *xvap)
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5326
diff changeset
   849
{
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5326
diff changeset
   850
	xoptattr_t *xoap;
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5326
diff changeset
   851
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5326
diff changeset
   852
	xoap = xva_getxoptattr(xvap);
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5326
diff changeset
   853
	ASSERT(xoap);
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5326
diff changeset
   854
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5326
diff changeset
   855
	if (XVA_ISSET_REQ(xvap, XAT_CREATETIME)) {
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5326
diff changeset
   856
		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
   857
		XVA_SET_RTN(xvap, XAT_CREATETIME);
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5326
diff changeset
   858
	}
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5326
diff changeset
   859
	if (XVA_ISSET_REQ(xvap, XAT_READONLY)) {
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5326
diff changeset
   860
		ZFS_ATTR_SET(zp, ZFS_READONLY, xoap->xoa_readonly);
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5326
diff changeset
   861
		XVA_SET_RTN(xvap, XAT_READONLY);
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5326
diff changeset
   862
	}
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5326
diff changeset
   863
	if (XVA_ISSET_REQ(xvap, XAT_HIDDEN)) {
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5326
diff changeset
   864
		ZFS_ATTR_SET(zp, ZFS_HIDDEN, xoap->xoa_hidden);
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5326
diff changeset
   865
		XVA_SET_RTN(xvap, XAT_HIDDEN);
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5326
diff changeset
   866
	}
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5326
diff changeset
   867
	if (XVA_ISSET_REQ(xvap, XAT_SYSTEM)) {
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5326
diff changeset
   868
		ZFS_ATTR_SET(zp, ZFS_SYSTEM, xoap->xoa_system);
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5326
diff changeset
   869
		XVA_SET_RTN(xvap, XAT_SYSTEM);
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5326
diff changeset
   870
	}
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5326
diff changeset
   871
	if (XVA_ISSET_REQ(xvap, XAT_ARCHIVE)) {
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5326
diff changeset
   872
		ZFS_ATTR_SET(zp, ZFS_ARCHIVE, xoap->xoa_archive);
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5326
diff changeset
   873
		XVA_SET_RTN(xvap, XAT_ARCHIVE);
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5326
diff changeset
   874
	}
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5326
diff changeset
   875
	if (XVA_ISSET_REQ(xvap, XAT_IMMUTABLE)) {
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5326
diff changeset
   876
		ZFS_ATTR_SET(zp, ZFS_IMMUTABLE, xoap->xoa_immutable);
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5326
diff changeset
   877
		XVA_SET_RTN(xvap, XAT_IMMUTABLE);
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5326
diff changeset
   878
	}
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5326
diff changeset
   879
	if (XVA_ISSET_REQ(xvap, XAT_NOUNLINK)) {
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5326
diff changeset
   880
		ZFS_ATTR_SET(zp, ZFS_NOUNLINK, xoap->xoa_nounlink);
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5326
diff changeset
   881
		XVA_SET_RTN(xvap, XAT_NOUNLINK);
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5326
diff changeset
   882
	}
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5326
diff changeset
   883
	if (XVA_ISSET_REQ(xvap, XAT_APPENDONLY)) {
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5326
diff changeset
   884
		ZFS_ATTR_SET(zp, ZFS_APPENDONLY, xoap->xoa_appendonly);
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5326
diff changeset
   885
		XVA_SET_RTN(xvap, XAT_APPENDONLY);
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5326
diff changeset
   886
	}
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5326
diff changeset
   887
	if (XVA_ISSET_REQ(xvap, XAT_NODUMP)) {
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5326
diff changeset
   888
		ZFS_ATTR_SET(zp, ZFS_NODUMP, xoap->xoa_nodump);
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5326
diff changeset
   889
		XVA_SET_RTN(xvap, XAT_NODUMP);
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5326
diff changeset
   890
	}
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5326
diff changeset
   891
	if (XVA_ISSET_REQ(xvap, XAT_OPAQUE)) {
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5326
diff changeset
   892
		ZFS_ATTR_SET(zp, ZFS_OPAQUE, xoap->xoa_opaque);
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5326
diff changeset
   893
		XVA_SET_RTN(xvap, XAT_OPAQUE);
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5326
diff changeset
   894
	}
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5326
diff changeset
   895
	if (XVA_ISSET_REQ(xvap, XAT_AV_QUARANTINED)) {
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5326
diff changeset
   896
		ZFS_ATTR_SET(zp, ZFS_AV_QUARANTINED,
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5326
diff changeset
   897
		    xoap->xoa_av_quarantined);
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5326
diff changeset
   898
		XVA_SET_RTN(xvap, XAT_AV_QUARANTINED);
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5326
diff changeset
   899
	}
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5326
diff changeset
   900
	if (XVA_ISSET_REQ(xvap, XAT_AV_MODIFIED)) {
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5326
diff changeset
   901
		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
   902
		XVA_SET_RTN(xvap, XAT_AV_MODIFIED);
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5326
diff changeset
   903
	}
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5326
diff changeset
   904
	if (XVA_ISSET_REQ(xvap, XAT_AV_SCANSTAMP)) {
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5326
diff changeset
   905
		(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
   906
		    sizeof (xoap->xoa_av_scanstamp));
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5326
diff changeset
   907
		zp->z_phys->zp_flags |= ZFS_BONUS_SCANSTAMP;
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5326
diff changeset
   908
		XVA_SET_RTN(xvap, XAT_AV_SCANSTAMP);
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5326
diff changeset
   909
	}
10793
34709091de6d 6886081 Solaris needs reparse point support (PSARC 2009/387)
Dai Ngo <dai.ngo@sun.com>
parents: 10269
diff changeset
   910
	if (XVA_ISSET_REQ(xvap, XAT_REPARSE)) {
34709091de6d 6886081 Solaris needs reparse point support (PSARC 2009/387)
Dai Ngo <dai.ngo@sun.com>
parents: 10269
diff changeset
   911
		ZFS_ATTR_SET(zp, ZFS_REPARSE, xoap->xoa_reparse);
34709091de6d 6886081 Solaris needs reparse point support (PSARC 2009/387)
Dai Ngo <dai.ngo@sun.com>
parents: 10269
diff changeset
   912
		XVA_SET_RTN(xvap, XAT_REPARSE);
34709091de6d 6886081 Solaris needs reparse point support (PSARC 2009/387)
Dai Ngo <dai.ngo@sun.com>
parents: 10269
diff changeset
   913
	}
5331
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5326
diff changeset
   914
}
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5326
diff changeset
   915
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   916
int
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   917
zfs_zget(zfsvfs_t *zfsvfs, uint64_t obj_num, znode_t **zpp)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   918
{
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   919
	dmu_object_info_t doi;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   920
	dmu_buf_t	*db;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   921
	znode_t		*zp;
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1394
diff changeset
   922
	int err;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   923
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   924
	*zpp = NULL;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   925
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   926
	ZFS_OBJ_HOLD_ENTER(zfsvfs, obj_num);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   927
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1394
diff changeset
   928
	err = dmu_bonus_hold(zfsvfs->z_os, obj_num, NULL, &db);
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1394
diff changeset
   929
	if (err) {
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   930
		ZFS_OBJ_HOLD_EXIT(zfsvfs, obj_num);
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1394
diff changeset
   931
		return (err);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   932
	}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   933
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   934
	dmu_object_info_from_db(db, &doi);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   935
	if (doi.doi_bonus_type != DMU_OT_ZNODE ||
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   936
	    doi.doi_bonus_size < sizeof (znode_phys_t)) {
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1394
diff changeset
   937
		dmu_buf_rele(db, NULL);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   938
		ZFS_OBJ_HOLD_EXIT(zfsvfs, obj_num);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   939
		return (EINVAL);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   940
	}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   941
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   942
	zp = dmu_buf_get_user(db);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   943
	if (zp != NULL) {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   944
		mutex_enter(&zp->z_lock);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   945
5446
51fbc14b301d 6421210 zfs rollback without unmounting
ahrens
parents: 5331
diff changeset
   946
		/*
51fbc14b301d 6421210 zfs rollback without unmounting
ahrens
parents: 5331
diff changeset
   947
		 * Since we do immediate eviction of the z_dbuf, we
51fbc14b301d 6421210 zfs rollback without unmounting
ahrens
parents: 5331
diff changeset
   948
		 * should never find a dbuf with a znode that doesn't
51fbc14b301d 6421210 zfs rollback without unmounting
ahrens
parents: 5331
diff changeset
   949
		 * know about the dbuf.
51fbc14b301d 6421210 zfs rollback without unmounting
ahrens
parents: 5331
diff changeset
   950
		 */
51fbc14b301d 6421210 zfs rollback without unmounting
ahrens
parents: 5331
diff changeset
   951
		ASSERT3P(zp->z_dbuf, ==, db);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   952
		ASSERT3U(zp->z_id, ==, obj_num);
3461
c19b22f347d6 6514331 in-memory delete queue is not needed
ahrens
parents: 3444
diff changeset
   953
		if (zp->z_unlinked) {
5446
51fbc14b301d 6421210 zfs rollback without unmounting
ahrens
parents: 5331
diff changeset
   954
			err = ENOENT;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   955
		} else {
5446
51fbc14b301d 6421210 zfs rollback without unmounting
ahrens
parents: 5331
diff changeset
   956
			VN_HOLD(ZTOV(zp));
51fbc14b301d 6421210 zfs rollback without unmounting
ahrens
parents: 5331
diff changeset
   957
			*zpp = zp;
51fbc14b301d 6421210 zfs rollback without unmounting
ahrens
parents: 5331
diff changeset
   958
			err = 0;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   959
		}
5446
51fbc14b301d 6421210 zfs rollback without unmounting
ahrens
parents: 5331
diff changeset
   960
		dmu_buf_rele(db, NULL);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   961
		mutex_exit(&zp->z_lock);
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1394
diff changeset
   962
		ZFS_OBJ_HOLD_EXIT(zfsvfs, obj_num);
5446
51fbc14b301d 6421210 zfs rollback without unmounting
ahrens
parents: 5331
diff changeset
   963
		return (err);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   964
	}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   965
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   966
	/*
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   967
	 * Not found create new znode/vnode
10938
270624bd70f1 6895088 panic: existing znode ffffff84e4747da0 for dbuf ffffff8271678e18
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 10793
diff changeset
   968
	 * but only if file exists.
270624bd70f1 6895088 panic: existing znode ffffff84e4747da0 for dbuf ffffff8271678e18
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 10793
diff changeset
   969
	 *
270624bd70f1 6895088 panic: existing znode ffffff84e4747da0 for dbuf ffffff8271678e18
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 10793
diff changeset
   970
	 * There is a small window where zfs_vget() could
270624bd70f1 6895088 panic: existing znode ffffff84e4747da0 for dbuf ffffff8271678e18
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 10793
diff changeset
   971
	 * find this object while a file create is still in
270624bd70f1 6895088 panic: existing znode ffffff84e4747da0 for dbuf ffffff8271678e18
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 10793
diff changeset
   972
	 * progress.  Since a gen number can never be zero
270624bd70f1 6895088 panic: existing znode ffffff84e4747da0 for dbuf ffffff8271678e18
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 10793
diff changeset
   973
	 * we will check that to determine if its an allocated
270624bd70f1 6895088 panic: existing znode ffffff84e4747da0 for dbuf ffffff8271678e18
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 10793
diff changeset
   974
	 * file.
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   975
	 */
10938
270624bd70f1 6895088 panic: existing znode ffffff84e4747da0 for dbuf ffffff8271678e18
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 10793
diff changeset
   976
270624bd70f1 6895088 panic: existing znode ffffff84e4747da0 for dbuf ffffff8271678e18
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 10793
diff changeset
   977
	if (((znode_phys_t *)db->db_data)->zp_gen != 0) {
270624bd70f1 6895088 panic: existing znode ffffff84e4747da0 for dbuf ffffff8271678e18
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 10793
diff changeset
   978
		zp = zfs_znode_alloc(zfsvfs, db, doi.doi_data_block_size);
270624bd70f1 6895088 panic: existing znode ffffff84e4747da0 for dbuf ffffff8271678e18
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 10793
diff changeset
   979
		*zpp = zp;
270624bd70f1 6895088 panic: existing znode ffffff84e4747da0 for dbuf ffffff8271678e18
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 10793
diff changeset
   980
		err = 0;
270624bd70f1 6895088 panic: existing znode ffffff84e4747da0 for dbuf ffffff8271678e18
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 10793
diff changeset
   981
	} else {
270624bd70f1 6895088 panic: existing znode ffffff84e4747da0 for dbuf ffffff8271678e18
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 10793
diff changeset
   982
		dmu_buf_rele(db, NULL);
270624bd70f1 6895088 panic: existing znode ffffff84e4747da0 for dbuf ffffff8271678e18
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 10793
diff changeset
   983
		err = ENOENT;
270624bd70f1 6895088 panic: existing znode ffffff84e4747da0 for dbuf ffffff8271678e18
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 10793
diff changeset
   984
	}
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1394
diff changeset
   985
	ZFS_OBJ_HOLD_EXIT(zfsvfs, obj_num);
10938
270624bd70f1 6895088 panic: existing znode ffffff84e4747da0 for dbuf ffffff8271678e18
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 10793
diff changeset
   986
	return (err);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   987
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   988
5326
6752aa2bd5bc 6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents: 4831
diff changeset
   989
int
6752aa2bd5bc 6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents: 4831
diff changeset
   990
zfs_rezget(znode_t *zp)
6752aa2bd5bc 6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents: 4831
diff changeset
   991
{
6752aa2bd5bc 6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents: 4831
diff changeset
   992
	zfsvfs_t *zfsvfs = zp->z_zfsvfs;
6752aa2bd5bc 6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents: 4831
diff changeset
   993
	dmu_object_info_t doi;
6752aa2bd5bc 6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents: 4831
diff changeset
   994
	dmu_buf_t *db;
6752aa2bd5bc 6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents: 4831
diff changeset
   995
	uint64_t obj_num = zp->z_id;
6752aa2bd5bc 6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents: 4831
diff changeset
   996
	int err;
6752aa2bd5bc 6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents: 4831
diff changeset
   997
6752aa2bd5bc 6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents: 4831
diff changeset
   998
	ZFS_OBJ_HOLD_ENTER(zfsvfs, obj_num);
6752aa2bd5bc 6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents: 4831
diff changeset
   999
6752aa2bd5bc 6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents: 4831
diff changeset
  1000
	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
  1001
	if (err) {
6752aa2bd5bc 6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents: 4831
diff changeset
  1002
		ZFS_OBJ_HOLD_EXIT(zfsvfs, obj_num);
6752aa2bd5bc 6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents: 4831
diff changeset
  1003
		return (err);
6752aa2bd5bc 6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents: 4831
diff changeset
  1004
	}
6752aa2bd5bc 6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents: 4831
diff changeset
  1005
6752aa2bd5bc 6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents: 4831
diff changeset
  1006
	dmu_object_info_from_db(db, &doi);
6752aa2bd5bc 6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents: 4831
diff changeset
  1007
	if (doi.doi_bonus_type != DMU_OT_ZNODE ||
6752aa2bd5bc 6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents: 4831
diff changeset
  1008
	    doi.doi_bonus_size < sizeof (znode_phys_t)) {
6752aa2bd5bc 6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents: 4831
diff changeset
  1009
		dmu_buf_rele(db, NULL);
6752aa2bd5bc 6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents: 4831
diff changeset
  1010
		ZFS_OBJ_HOLD_EXIT(zfsvfs, obj_num);
6752aa2bd5bc 6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents: 4831
diff changeset
  1011
		return (EINVAL);
6752aa2bd5bc 6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents: 4831
diff changeset
  1012
	}
6752aa2bd5bc 6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents: 4831
diff changeset
  1013
6752aa2bd5bc 6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents: 4831
diff changeset
  1014
	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
  1015
		dmu_buf_rele(db, NULL);
6752aa2bd5bc 6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents: 4831
diff changeset
  1016
		ZFS_OBJ_HOLD_EXIT(zfsvfs, obj_num);
6752aa2bd5bc 6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents: 4831
diff changeset
  1017
		return (EIO);
6752aa2bd5bc 6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents: 4831
diff changeset
  1018
	}
6752aa2bd5bc 6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents: 4831
diff changeset
  1019
10269
2788675568fd 6868276 zfs_rezget() can be hazardous when znode has a cached ACL
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 10250
diff changeset
  1020
	mutex_enter(&zp->z_acl_lock);
2788675568fd 6868276 zfs_rezget() can be hazardous when znode has a cached ACL
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 10250
diff changeset
  1021
	if (zp->z_acl_cached) {
2788675568fd 6868276 zfs_rezget() can be hazardous when znode has a cached ACL
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 10250
diff changeset
  1022
		zfs_acl_free(zp->z_acl_cached);
2788675568fd 6868276 zfs_rezget() can be hazardous when znode has a cached ACL
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 10250
diff changeset
  1023
		zp->z_acl_cached = NULL;
2788675568fd 6868276 zfs_rezget() can be hazardous when znode has a cached ACL
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 10250
diff changeset
  1024
	}
2788675568fd 6868276 zfs_rezget() can be hazardous when znode has a cached ACL
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 10250
diff changeset
  1025
	mutex_exit(&zp->z_acl_lock);
2788675568fd 6868276 zfs_rezget() can be hazardous when znode has a cached ACL
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 10250
diff changeset
  1026
6712
79afecec3f3c 6554564 slab allocator cannot release slabs with lonely buffers
tomee
parents: 6492
diff changeset
  1027
	zfs_znode_dmu_init(zfsvfs, zp, db);
5326
6752aa2bd5bc 6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents: 4831
diff changeset
  1028
	zp->z_unlinked = (zp->z_phys->zp_links == 0);
5844
51eed00be2b0 6649002 panic "accessing past end of object" after online recv/rollback
ek110237
parents: 5745
diff changeset
  1029
	zp->z_blksz = doi.doi_data_block_size;
5326
6752aa2bd5bc 6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents: 4831
diff changeset
  1030
6752aa2bd5bc 6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents: 4831
diff changeset
  1031
	ZFS_OBJ_HOLD_EXIT(zfsvfs, obj_num);
6752aa2bd5bc 6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents: 4831
diff changeset
  1032
6752aa2bd5bc 6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents: 4831
diff changeset
  1033
	return (0);
6752aa2bd5bc 6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents: 4831
diff changeset
  1034
}
6752aa2bd5bc 6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents: 4831
diff changeset
  1035
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1036
void
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1037
zfs_znode_delete(znode_t *zp, dmu_tx_t *tx)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1038
{
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1039
	zfsvfs_t *zfsvfs = zp->z_zfsvfs;
6992
20c04e18c58c 6573681 deleting a very large file can be slow
maybee
parents: 6712
diff changeset
  1040
	objset_t *os = zfsvfs->z_os;
5446
51fbc14b301d 6421210 zfs rollback without unmounting
ahrens
parents: 5331
diff changeset
  1041
	uint64_t obj = zp->z_id;
6992
20c04e18c58c 6573681 deleting a very large file can be slow
maybee
parents: 6712
diff changeset
  1042
	uint64_t acl_obj = zp->z_phys->zp_acl.z_acl_extern_obj;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1043
5446
51fbc14b301d 6421210 zfs rollback without unmounting
ahrens
parents: 5331
diff changeset
  1044
	ZFS_OBJ_HOLD_ENTER(zfsvfs, obj);
6992
20c04e18c58c 6573681 deleting a very large file can be slow
maybee
parents: 6712
diff changeset
  1045
	if (acl_obj)
20c04e18c58c 6573681 deleting a very large file can be slow
maybee
parents: 6712
diff changeset
  1046
		VERIFY(0 == dmu_object_free(os, acl_obj, tx));
20c04e18c58c 6573681 deleting a very large file can be slow
maybee
parents: 6712
diff changeset
  1047
	VERIFY(0 == dmu_object_free(os, obj, tx));
5446
51fbc14b301d 6421210 zfs rollback without unmounting
ahrens
parents: 5331
diff changeset
  1048
	zfs_znode_dmu_fini(zp);
51fbc14b301d 6421210 zfs rollback without unmounting
ahrens
parents: 5331
diff changeset
  1049
	ZFS_OBJ_HOLD_EXIT(zfsvfs, obj);
5642
504c84876fda 6513209 Destroying pools under stress caused a hang in arc_flush
maybee
parents: 5520
diff changeset
  1050
	zfs_znode_free(zp);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1051
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1052
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1053
void
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1054
zfs_zinactive(znode_t *zp)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1055
{
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1056
	vnode_t	*vp = ZTOV(zp);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1057
	zfsvfs_t *zfsvfs = zp->z_zfsvfs;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1058
	uint64_t z_id = zp->z_id;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1059
5446
51fbc14b301d 6421210 zfs rollback without unmounting
ahrens
parents: 5331
diff changeset
  1060
	ASSERT(zp->z_dbuf && zp->z_phys);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1061
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1062
	/*
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1063
	 * Don't allow a zfs_zget() while were trying to release this znode
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1064
	 */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1065
	ZFS_OBJ_HOLD_ENTER(zfsvfs, z_id);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1066
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1067
	mutex_enter(&zp->z_lock);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1068
	mutex_enter(&vp->v_lock);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1069
	vp->v_count--;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1070
	if (vp->v_count > 0 || vn_has_cached_data(vp)) {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1071
		/*
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1072
		 * If the hold count is greater than zero, somebody has
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1073
		 * obtained a new reference on this znode while we were
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1074
		 * processing it here, so we are done.  If we still have
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1075
		 * mapped pages then we are also done, since we don't
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1076
		 * want to inactivate the znode until the pages get pushed.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1077
		 *
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1078
		 * XXX - if vn_has_cached_data(vp) is true, but count == 0,
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1079
		 * this seems like it would leave the znode hanging with
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1080
		 * no chance to go inactive...
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1081
		 */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1082
		mutex_exit(&vp->v_lock);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1083
		mutex_exit(&zp->z_lock);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1084
		ZFS_OBJ_HOLD_EXIT(zfsvfs, z_id);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1085
		return;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1086
	}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1087
	mutex_exit(&vp->v_lock);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1088
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1089
	/*
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1090
	 * If this was the last reference to a file with no links,
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1091
	 * remove the file from the file system.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1092
	 */
3461
c19b22f347d6 6514331 in-memory delete queue is not needed
ahrens
parents: 3444
diff changeset
  1093
	if (zp->z_unlinked) {
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1094
		mutex_exit(&zp->z_lock);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1095
		ZFS_OBJ_HOLD_EXIT(zfsvfs, z_id);
3461
c19b22f347d6 6514331 in-memory delete queue is not needed
ahrens
parents: 3444
diff changeset
  1096
		zfs_rmnode(zp);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1097
		return;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1098
	}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1099
	mutex_exit(&zp->z_lock);
5446
51fbc14b301d 6421210 zfs rollback without unmounting
ahrens
parents: 5331
diff changeset
  1100
	zfs_znode_dmu_fini(zp);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1101
	ZFS_OBJ_HOLD_EXIT(zfsvfs, z_id);
5642
504c84876fda 6513209 Destroying pools under stress caused a hang in arc_flush
maybee
parents: 5520
diff changeset
  1102
	zfs_znode_free(zp);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1103
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1104
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1105
void
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1106
zfs_znode_free(znode_t *zp)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1107
{
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1108
	zfsvfs_t *zfsvfs = zp->z_zfsvfs;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1109
5642
504c84876fda 6513209 Destroying pools under stress caused a hang in arc_flush
maybee
parents: 5520
diff changeset
  1110
	vn_invalid(ZTOV(zp));
504c84876fda 6513209 Destroying pools under stress caused a hang in arc_flush
maybee
parents: 5520
diff changeset
  1111
6712
79afecec3f3c 6554564 slab allocator cannot release slabs with lonely buffers
tomee
parents: 6492
diff changeset
  1112
	ASSERT(ZTOV(zp)->v_count == 0);
79afecec3f3c 6554564 slab allocator cannot release slabs with lonely buffers
tomee
parents: 6492
diff changeset
  1113
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1114
	mutex_enter(&zfsvfs->z_znodes_lock);
6712
79afecec3f3c 6554564 slab allocator cannot release slabs with lonely buffers
tomee
parents: 6492
diff changeset
  1115
	POINTER_INVALIDATE(&zp->z_zfsvfs);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1116
	list_remove(&zfsvfs->z_all_znodes, zp);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1117
	mutex_exit(&zfsvfs->z_znodes_lock);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1118
9981
b4907297e740 6775100 stat() performance on files on zfs should be improved
Tim Haley <Tim.Haley@Sun.COM>
parents: 9788
diff changeset
  1119
	if (zp->z_acl_cached) {
b4907297e740 6775100 stat() performance on files on zfs should be improved
Tim Haley <Tim.Haley@Sun.COM>
parents: 9788
diff changeset
  1120
		zfs_acl_free(zp->z_acl_cached);
b4907297e740 6775100 stat() performance on files on zfs should be improved
Tim Haley <Tim.Haley@Sun.COM>
parents: 9788
diff changeset
  1121
		zp->z_acl_cached = NULL;
b4907297e740 6775100 stat() performance on files on zfs should be improved
Tim Haley <Tim.Haley@Sun.COM>
parents: 9788
diff changeset
  1122
	}
b4907297e740 6775100 stat() performance on files on zfs should be improved
Tim Haley <Tim.Haley@Sun.COM>
parents: 9788
diff changeset
  1123
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1124
	kmem_cache_free(znode_cache, zp);
5642
504c84876fda 6513209 Destroying pools under stress caused a hang in arc_flush
maybee
parents: 5520
diff changeset
  1125
504c84876fda 6513209 Destroying pools under stress caused a hang in arc_flush
maybee
parents: 5520
diff changeset
  1126
	VFS_RELE(zfsvfs->z_vfs);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1127
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1128
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1129
void
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1130
zfs_time_stamper_locked(znode_t *zp, uint_t flag, dmu_tx_t *tx)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1131
{
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1132
	timestruc_t	now;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1133
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1134
	ASSERT(MUTEX_HELD(&zp->z_lock));
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1135
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1136
	gethrestime(&now);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1137
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1138
	if (tx) {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1139
		dmu_buf_will_dirty(zp->z_dbuf, tx);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1140
		zp->z_atime_dirty = 0;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1141
		zp->z_seq++;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1142
	} else {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1143
		zp->z_atime_dirty = 1;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1144
	}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1145
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1146
	if (flag & AT_ATIME)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1147
		ZFS_TIME_ENCODE(&now, zp->z_phys->zp_atime);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1148
5331
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5326
diff changeset
  1149
	if (flag & AT_MTIME) {
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1150
		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
  1151
		if (zp->z_zfsvfs->z_use_fuids)
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5326
diff changeset
  1152
			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
  1153
	}
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1154
5331
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5326
diff changeset
  1155
	if (flag & AT_CTIME) {
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1156
		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
  1157
		if (zp->z_zfsvfs->z_use_fuids)
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5326
diff changeset
  1158
			zp->z_phys->zp_flags |= ZFS_ARCHIVE;
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5326
diff changeset
  1159
	}
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1160
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1161
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1162
/*
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1163
 * Update the requested znode timestamps with the current time.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1164
 * If we are in a transaction, then go ahead and mark the znode
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1165
 * dirty in the transaction so the timestamps will go to disk.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1166
 * Otherwise, we will get pushed next time the znode is updated
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1167
 * in a transaction, or when this znode eventually goes inactive.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1168
 *
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1169
 * Why is this OK?
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1170
 *  1 - Only the ACCESS time is ever updated outside of a transaction.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1171
 *  2 - Multiple consecutive updates will be collapsed into a single
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1172
 *	znode update by the transaction grouping semantics of the DMU.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1173
 */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1174
void
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1175
zfs_time_stamper(znode_t *zp, uint_t flag, dmu_tx_t *tx)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1176
{
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1177
	mutex_enter(&zp->z_lock);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1178
	zfs_time_stamper_locked(zp, flag, tx);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1179
	mutex_exit(&zp->z_lock);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1180
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1181
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1182
/*
1669
3521dbbcb2e8 6343608 ZFS file range locking
perrin
parents: 1544
diff changeset
  1183
 * Grow the block size for a file.
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1184
 *
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1185
 *	IN:	zp	- znode of file to free data in.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1186
 *		size	- requested block size
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1187
 *		tx	- open transaction.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1188
 *
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1189
 * NOTE: this function assumes that the znode is write locked.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1190
 */
1669
3521dbbcb2e8 6343608 ZFS file range locking
perrin
parents: 1544
diff changeset
  1191
void
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1192
zfs_grow_blocksize(znode_t *zp, uint64_t size, dmu_tx_t *tx)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1193
{
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1194
	int		error;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1195
	u_longlong_t	dummy;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1196
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1197
	if (size <= zp->z_blksz)
1669
3521dbbcb2e8 6343608 ZFS file range locking
perrin
parents: 1544
diff changeset
  1198
		return;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1199
	/*
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1200
	 * If the file size is already greater than the current blocksize,
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1201
	 * we will not grow.  If there is more than one block in a file,
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1202
	 * the blocksize cannot change.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1203
	 */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1204
	if (zp->z_blksz && zp->z_phys->zp_size > zp->z_blksz)
1669
3521dbbcb2e8 6343608 ZFS file range locking
perrin
parents: 1544
diff changeset
  1205
		return;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1206
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1207
	error = dmu_object_set_blocksize(zp->z_zfsvfs->z_os, zp->z_id,
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1208
	    size, 0, tx);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1209
	if (error == ENOTSUP)
1669
3521dbbcb2e8 6343608 ZFS file range locking
perrin
parents: 1544
diff changeset
  1210
		return;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1211
	ASSERT3U(error, ==, 0);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1212
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1213
	/* What blocksize did we actually get? */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1214
	dmu_object_size_from_db(zp->z_dbuf, &zp->z_blksz, &dummy);
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
/*
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1218
 * This is a dummy interface used when pvn_vplist_dirty() should *not*
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1219
 * be calling back into the fs for a putpage().  E.g.: when truncating
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1220
 * a file, the pages being "thrown away* don't need to be written out.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1221
 */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1222
/* ARGSUSED */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1223
static int
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1224
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
  1225
    int flags, cred_t *cr)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1226
{
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1227
	ASSERT(0);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1228
	return (0);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1229
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1230
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1231
/*
6992
20c04e18c58c 6573681 deleting a very large file can be slow
maybee
parents: 6712
diff changeset
  1232
 * Increase the file length
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1233
 *
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1234
 *	IN:	zp	- znode of file to free data in.
6992
20c04e18c58c 6573681 deleting a very large file can be slow
maybee
parents: 6712
diff changeset
  1235
 *		end	- new end-of-file
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1236
 *
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1237
 * 	RETURN:	0 if success
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1238
 *		error code if failure
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1239
 */
6992
20c04e18c58c 6573681 deleting a very large file can be slow
maybee
parents: 6712
diff changeset
  1240
static int
20c04e18c58c 6573681 deleting a very large file can be slow
maybee
parents: 6712
diff changeset
  1241
zfs_extend(znode_t *zp, uint64_t end)
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1242
{
1878
c22df0f5603f 6413573 deadlock between fsflush() and zfs_create()
maybee
parents: 1816
diff changeset
  1243
	zfsvfs_t *zfsvfs = zp->z_zfsvfs;
6992
20c04e18c58c 6573681 deleting a very large file can be slow
maybee
parents: 6712
diff changeset
  1244
	dmu_tx_t *tx;
1878
c22df0f5603f 6413573 deadlock between fsflush() and zfs_create()
maybee
parents: 1816
diff changeset
  1245
	rl_t *rl;
6992
20c04e18c58c 6573681 deleting a very large file can be slow
maybee
parents: 6712
diff changeset
  1246
	uint64_t newblksz;
1669
3521dbbcb2e8 6343608 ZFS file range locking
perrin
parents: 1544
diff changeset
  1247
	int error;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1248
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1249
	/*
6992
20c04e18c58c 6573681 deleting a very large file can be slow
maybee
parents: 6712
diff changeset
  1250
	 * We will change zp_size, lock the whole file.
1878
c22df0f5603f 6413573 deadlock between fsflush() and zfs_create()
maybee
parents: 1816
diff changeset
  1251
	 */
6992
20c04e18c58c 6573681 deleting a very large file can be slow
maybee
parents: 6712
diff changeset
  1252
	rl = zfs_range_lock(zp, 0, UINT64_MAX, RL_WRITER);
1878
c22df0f5603f 6413573 deadlock between fsflush() and zfs_create()
maybee
parents: 1816
diff changeset
  1253
c22df0f5603f 6413573 deadlock between fsflush() and zfs_create()
maybee
parents: 1816
diff changeset
  1254
	/*
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1255
	 * Nothing to do if file already at desired length.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1256
	 */
6992
20c04e18c58c 6573681 deleting a very large file can be slow
maybee
parents: 6712
diff changeset
  1257
	if (end <= zp->z_phys->zp_size) {
2237
45affe88ed99 6416482 filebench oltp workload hangs in zfs
maybee
parents: 2113
diff changeset
  1258
		zfs_range_unlock(rl);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1259
		return (0);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1260
	}
6992
20c04e18c58c 6573681 deleting a very large file can be slow
maybee
parents: 6712
diff changeset
  1261
top:
1878
c22df0f5603f 6413573 deadlock between fsflush() and zfs_create()
maybee
parents: 1816
diff changeset
  1262
	tx = dmu_tx_create(zfsvfs->z_os);
c22df0f5603f 6413573 deadlock between fsflush() and zfs_create()
maybee
parents: 1816
diff changeset
  1263
	dmu_tx_hold_bonus(tx, zp->z_id);
6992
20c04e18c58c 6573681 deleting a very large file can be slow
maybee
parents: 6712
diff changeset
  1264
	if (end > zp->z_blksz &&
1878
c22df0f5603f 6413573 deadlock between fsflush() and zfs_create()
maybee
parents: 1816
diff changeset
  1265
	    (!ISP2(zp->z_blksz) || zp->z_blksz < zfsvfs->z_max_blksz)) {
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1266
		/*
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1267
		 * We are growing the file past the current block size.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1268
		 */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1269
		if (zp->z_blksz > zp->z_zfsvfs->z_max_blksz) {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1270
			ASSERT(!ISP2(zp->z_blksz));
6992
20c04e18c58c 6573681 deleting a very large file can be slow
maybee
parents: 6712
diff changeset
  1271
			newblksz = MIN(end, SPA_MAXBLOCKSIZE);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1272
		} else {
6992
20c04e18c58c 6573681 deleting a very large file can be slow
maybee
parents: 6712
diff changeset
  1273
			newblksz = MIN(end, zp->z_zfsvfs->z_max_blksz);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1274
		}
6992
20c04e18c58c 6573681 deleting a very large file can be slow
maybee
parents: 6712
diff changeset
  1275
		dmu_tx_hold_write(tx, zp->z_id, 0, newblksz);
20c04e18c58c 6573681 deleting a very large file can be slow
maybee
parents: 6712
diff changeset
  1276
	} else {
20c04e18c58c 6573681 deleting a very large file can be slow
maybee
parents: 6712
diff changeset
  1277
		newblksz = 0;
1878
c22df0f5603f 6413573 deadlock between fsflush() and zfs_create()
maybee
parents: 1816
diff changeset
  1278
	}
c22df0f5603f 6413573 deadlock between fsflush() and zfs_create()
maybee
parents: 1816
diff changeset
  1279
8227
f7d7be9b1f56 6765294 Refactor replay
Neil Perrin <Neil.Perrin@Sun.COM>
parents: 7579
diff changeset
  1280
	error = dmu_tx_assign(tx, TXG_NOWAIT);
1878
c22df0f5603f 6413573 deadlock between fsflush() and zfs_create()
maybee
parents: 1816
diff changeset
  1281
	if (error) {
8227
f7d7be9b1f56 6765294 Refactor replay
Neil Perrin <Neil.Perrin@Sun.COM>
parents: 7579
diff changeset
  1282
		if (error == ERESTART) {
2113
0510bb40c993 6430121 3-way deadlock involving tc_lock within zfs
ahrens
parents: 1936
diff changeset
  1283
			dmu_tx_wait(tx);
6992
20c04e18c58c 6573681 deleting a very large file can be slow
maybee
parents: 6712
diff changeset
  1284
			dmu_tx_abort(tx);
20c04e18c58c 6573681 deleting a very large file can be slow
maybee
parents: 6712
diff changeset
  1285
			goto top;
20c04e18c58c 6573681 deleting a very large file can be slow
maybee
parents: 6712
diff changeset
  1286
		}
1878
c22df0f5603f 6413573 deadlock between fsflush() and zfs_create()
maybee
parents: 1816
diff changeset
  1287
		dmu_tx_abort(tx);
2237
45affe88ed99 6416482 filebench oltp workload hangs in zfs
maybee
parents: 2113
diff changeset
  1288
		zfs_range_unlock(rl);
1878
c22df0f5603f 6413573 deadlock between fsflush() and zfs_create()
maybee
parents: 1816
diff changeset
  1289
		return (error);
c22df0f5603f 6413573 deadlock between fsflush() and zfs_create()
maybee
parents: 1816
diff changeset
  1290
	}
6992
20c04e18c58c 6573681 deleting a very large file can be slow
maybee
parents: 6712
diff changeset
  1291
	dmu_buf_will_dirty(zp->z_dbuf, tx);
1878
c22df0f5603f 6413573 deadlock between fsflush() and zfs_create()
maybee
parents: 1816
diff changeset
  1292
6992
20c04e18c58c 6573681 deleting a very large file can be slow
maybee
parents: 6712
diff changeset
  1293
	if (newblksz)
20c04e18c58c 6573681 deleting a very large file can be slow
maybee
parents: 6712
diff changeset
  1294
		zfs_grow_blocksize(zp, newblksz, tx);
1878
c22df0f5603f 6413573 deadlock between fsflush() and zfs_create()
maybee
parents: 1816
diff changeset
  1295
6992
20c04e18c58c 6573681 deleting a very large file can be slow
maybee
parents: 6712
diff changeset
  1296
	zp->z_phys->zp_size = end;
1878
c22df0f5603f 6413573 deadlock between fsflush() and zfs_create()
maybee
parents: 1816
diff changeset
  1297
2237
45affe88ed99 6416482 filebench oltp workload hangs in zfs
maybee
parents: 2113
diff changeset
  1298
	zfs_range_unlock(rl);
1878
c22df0f5603f 6413573 deadlock between fsflush() and zfs_create()
maybee
parents: 1816
diff changeset
  1299
c22df0f5603f 6413573 deadlock between fsflush() and zfs_create()
maybee
parents: 1816
diff changeset
  1300
	dmu_tx_commit(tx);
c22df0f5603f 6413573 deadlock between fsflush() and zfs_create()
maybee
parents: 1816
diff changeset
  1301
6992
20c04e18c58c 6573681 deleting a very large file can be slow
maybee
parents: 6712
diff changeset
  1302
	return (0);
20c04e18c58c 6573681 deleting a very large file can be slow
maybee
parents: 6712
diff changeset
  1303
}
20c04e18c58c 6573681 deleting a very large file can be slow
maybee
parents: 6712
diff changeset
  1304
20c04e18c58c 6573681 deleting a very large file can be slow
maybee
parents: 6712
diff changeset
  1305
/*
20c04e18c58c 6573681 deleting a very large file can be slow
maybee
parents: 6712
diff changeset
  1306
 * Free space in a file.
20c04e18c58c 6573681 deleting a very large file can be slow
maybee
parents: 6712
diff changeset
  1307
 *
20c04e18c58c 6573681 deleting a very large file can be slow
maybee
parents: 6712
diff changeset
  1308
 *	IN:	zp	- znode of file to free data in.
20c04e18c58c 6573681 deleting a very large file can be slow
maybee
parents: 6712
diff changeset
  1309
 *		off	- start of section to free.
20c04e18c58c 6573681 deleting a very large file can be slow
maybee
parents: 6712
diff changeset
  1310
 *		len	- length of section to free.
20c04e18c58c 6573681 deleting a very large file can be slow
maybee
parents: 6712
diff changeset
  1311
 *
20c04e18c58c 6573681 deleting a very large file can be slow
maybee
parents: 6712
diff changeset
  1312
 * 	RETURN:	0 if success
20c04e18c58c 6573681 deleting a very large file can be slow
maybee
parents: 6712
diff changeset
  1313
 *		error code if failure
20c04e18c58c 6573681 deleting a very large file can be slow
maybee
parents: 6712
diff changeset
  1314
 */
20c04e18c58c 6573681 deleting a very large file can be slow
maybee
parents: 6712
diff changeset
  1315
static int
20c04e18c58c 6573681 deleting a very large file can be slow
maybee
parents: 6712
diff changeset
  1316
zfs_free_range(znode_t *zp, uint64_t off, uint64_t len)
20c04e18c58c 6573681 deleting a very large file can be slow
maybee
parents: 6712
diff changeset
  1317
{
20c04e18c58c 6573681 deleting a very large file can be slow
maybee
parents: 6712
diff changeset
  1318
	zfsvfs_t *zfsvfs = zp->z_zfsvfs;
20c04e18c58c 6573681 deleting a very large file can be slow
maybee
parents: 6712
diff changeset
  1319
	rl_t *rl;
20c04e18c58c 6573681 deleting a very large file can be slow
maybee
parents: 6712
diff changeset
  1320
	int error;
20c04e18c58c 6573681 deleting a very large file can be slow
maybee
parents: 6712
diff changeset
  1321
20c04e18c58c 6573681 deleting a very large file can be slow
maybee
parents: 6712
diff changeset
  1322
	/*
20c04e18c58c 6573681 deleting a very large file can be slow
maybee
parents: 6712
diff changeset
  1323
	 * Lock the range being freed.
20c04e18c58c 6573681 deleting a very large file can be slow
maybee
parents: 6712
diff changeset
  1324
	 */
20c04e18c58c 6573681 deleting a very large file can be slow
maybee
parents: 6712
diff changeset
  1325
	rl = zfs_range_lock(zp, off, len, RL_WRITER);
20c04e18c58c 6573681 deleting a very large file can be slow
maybee
parents: 6712
diff changeset
  1326
20c04e18c58c 6573681 deleting a very large file can be slow
maybee
parents: 6712
diff changeset
  1327
	/*
20c04e18c58c 6573681 deleting a very large file can be slow
maybee
parents: 6712
diff changeset
  1328
	 * Nothing to do if file already at desired length.
20c04e18c58c 6573681 deleting a very large file can be slow
maybee
parents: 6712
diff changeset
  1329
	 */
20c04e18c58c 6573681 deleting a very large file can be slow
maybee
parents: 6712
diff changeset
  1330
	if (off >= zp->z_phys->zp_size) {
20c04e18c58c 6573681 deleting a very large file can be slow
maybee
parents: 6712
diff changeset
  1331
		zfs_range_unlock(rl);
20c04e18c58c 6573681 deleting a very large file can be slow
maybee
parents: 6712
diff changeset
  1332
		return (0);
20c04e18c58c 6573681 deleting a very large file can be slow
maybee
parents: 6712
diff changeset
  1333
	}
20c04e18c58c 6573681 deleting a very large file can be slow
maybee
parents: 6712
diff changeset
  1334
20c04e18c58c 6573681 deleting a very large file can be slow
maybee
parents: 6712
diff changeset
  1335
	if (off + len > zp->z_phys->zp_size)
20c04e18c58c 6573681 deleting a very large file can be slow
maybee
parents: 6712
diff changeset
  1336
		len = zp->z_phys->zp_size - off;
20c04e18c58c 6573681 deleting a very large file can be slow
maybee
parents: 6712
diff changeset
  1337
20c04e18c58c 6573681 deleting a very large file can be slow
maybee
parents: 6712
diff changeset
  1338
	error = dmu_free_long_range(zfsvfs->z_os, zp->z_id, off, len);
20c04e18c58c 6573681 deleting a very large file can be slow
maybee
parents: 6712
diff changeset
  1339
20c04e18c58c 6573681 deleting a very large file can be slow
maybee
parents: 6712
diff changeset
  1340
	zfs_range_unlock(rl);
20c04e18c58c 6573681 deleting a very large file can be slow
maybee
parents: 6712
diff changeset
  1341
20c04e18c58c 6573681 deleting a very large file can be slow
maybee
parents: 6712
diff changeset
  1342
	return (error);
20c04e18c58c 6573681 deleting a very large file can be slow
maybee
parents: 6712
diff changeset
  1343
}
20c04e18c58c 6573681 deleting a very large file can be slow
maybee
parents: 6712
diff changeset
  1344
20c04e18c58c 6573681 deleting a very large file can be slow
maybee
parents: 6712
diff changeset
  1345
/*
20c04e18c58c 6573681 deleting a very large file can be slow
maybee
parents: 6712
diff changeset
  1346
 * Truncate a file
20c04e18c58c 6573681 deleting a very large file can be slow
maybee
parents: 6712
diff changeset
  1347
 *
20c04e18c58c 6573681 deleting a very large file can be slow
maybee
parents: 6712
diff changeset
  1348
 *	IN:	zp	- znode of file to free data in.
20c04e18c58c 6573681 deleting a very large file can be slow
maybee
parents: 6712
diff changeset
  1349
 *		end	- new end-of-file.
20c04e18c58c 6573681 deleting a very large file can be slow
maybee
parents: 6712
diff changeset
  1350
 *
20c04e18c58c 6573681 deleting a very large file can be slow
maybee
parents: 6712
diff changeset
  1351
 * 	RETURN:	0 if success
20c04e18c58c 6573681 deleting a very large file can be slow
maybee
parents: 6712
diff changeset
  1352
 *		error code if failure
20c04e18c58c 6573681 deleting a very large file can be slow
maybee
parents: 6712
diff changeset
  1353
 */
20c04e18c58c 6573681 deleting a very large file can be slow
maybee
parents: 6712
diff changeset
  1354
static int
20c04e18c58c 6573681 deleting a very large file can be slow
maybee
parents: 6712
diff changeset
  1355
zfs_trunc(znode_t *zp, uint64_t end)
20c04e18c58c 6573681 deleting a very large file can be slow
maybee
parents: 6712
diff changeset
  1356
{
20c04e18c58c 6573681 deleting a very large file can be slow
maybee
parents: 6712
diff changeset
  1357
	zfsvfs_t *zfsvfs = zp->z_zfsvfs;
20c04e18c58c 6573681 deleting a very large file can be slow
maybee
parents: 6712
diff changeset
  1358
	vnode_t *vp = ZTOV(zp);
20c04e18c58c 6573681 deleting a very large file can be slow
maybee
parents: 6712
diff changeset
  1359
	dmu_tx_t *tx;
20c04e18c58c 6573681 deleting a very large file can be slow
maybee
parents: 6712
diff changeset
  1360
	rl_t *rl;
20c04e18c58c 6573681 deleting a very large file can be slow
maybee
parents: 6712
diff changeset
  1361
	int error;
20c04e18c58c 6573681 deleting a very large file can be slow
maybee
parents: 6712
diff changeset
  1362
20c04e18c58c 6573681 deleting a very large file can be slow
maybee
parents: 6712
diff changeset
  1363
	/*
20c04e18c58c 6573681 deleting a very large file can be slow
maybee
parents: 6712
diff changeset
  1364
	 * We will change zp_size, lock the whole file.
20c04e18c58c 6573681 deleting a very large file can be slow
maybee
parents: 6712
diff changeset
  1365
	 */
20c04e18c58c 6573681 deleting a very large file can be slow
maybee
parents: 6712
diff changeset
  1366
	rl = zfs_range_lock(zp, 0, UINT64_MAX, RL_WRITER);
20c04e18c58c 6573681 deleting a very large file can be slow
maybee
parents: 6712
diff changeset
  1367
20c04e18c58c 6573681 deleting a very large file can be slow
maybee
parents: 6712
diff changeset
  1368
	/*
20c04e18c58c 6573681 deleting a very large file can be slow
maybee
parents: 6712
diff changeset
  1369
	 * Nothing to do if file already at desired length.
20c04e18c58c 6573681 deleting a very large file can be slow
maybee
parents: 6712
diff changeset
  1370
	 */
20c04e18c58c 6573681 deleting a very large file can be slow
maybee
parents: 6712
diff changeset
  1371
	if (end >= zp->z_phys->zp_size) {
20c04e18c58c 6573681 deleting a very large file can be slow
maybee
parents: 6712
diff changeset
  1372
		zfs_range_unlock(rl);
20c04e18c58c 6573681 deleting a very large file can be slow
maybee
parents: 6712
diff changeset
  1373
		return (0);
20c04e18c58c 6573681 deleting a very large file can be slow
maybee
parents: 6712
diff changeset
  1374
	}
20c04e18c58c 6573681 deleting a very large file can be slow
maybee
parents: 6712
diff changeset
  1375
20c04e18c58c 6573681 deleting a very large file can be slow
maybee
parents: 6712
diff changeset
  1376
	error = dmu_free_long_range(zfsvfs->z_os, zp->z_id, end,  -1);
20c04e18c58c 6573681 deleting a very large file can be slow
maybee
parents: 6712
diff changeset
  1377
	if (error) {
20c04e18c58c 6573681 deleting a very large file can be slow
maybee
parents: 6712
diff changeset
  1378
		zfs_range_unlock(rl);
20c04e18c58c 6573681 deleting a very large file can be slow
maybee
parents: 6712
diff changeset
  1379
		return (error);
20c04e18c58c 6573681 deleting a very large file can be slow
maybee
parents: 6712
diff changeset
  1380
	}
20c04e18c58c 6573681 deleting a very large file can be slow
maybee
parents: 6712
diff changeset
  1381
top:
20c04e18c58c 6573681 deleting a very large file can be slow
maybee
parents: 6712
diff changeset
  1382
	tx = dmu_tx_create(zfsvfs->z_os);
20c04e18c58c 6573681 deleting a very large file can be slow
maybee
parents: 6712
diff changeset
  1383
	dmu_tx_hold_bonus(tx, zp->z_id);
8227
f7d7be9b1f56 6765294 Refactor replay
Neil Perrin <Neil.Perrin@Sun.COM>
parents: 7579
diff changeset
  1384
	error = dmu_tx_assign(tx, TXG_NOWAIT);
6992
20c04e18c58c 6573681 deleting a very large file can be slow
maybee
parents: 6712
diff changeset
  1385
	if (error) {
8227
f7d7be9b1f56 6765294 Refactor replay
Neil Perrin <Neil.Perrin@Sun.COM>
parents: 7579
diff changeset
  1386
		if (error == ERESTART) {
6992
20c04e18c58c 6573681 deleting a very large file can be slow
maybee
parents: 6712
diff changeset
  1387
			dmu_tx_wait(tx);
20c04e18c58c 6573681 deleting a very large file can be slow
maybee
parents: 6712
diff changeset
  1388
			dmu_tx_abort(tx);
20c04e18c58c 6573681 deleting a very large file can be slow
maybee
parents: 6712
diff changeset
  1389
			goto top;
20c04e18c58c 6573681 deleting a very large file can be slow
maybee
parents: 6712
diff changeset
  1390
		}
20c04e18c58c 6573681 deleting a very large file can be slow
maybee
parents: 6712
diff changeset
  1391
		dmu_tx_abort(tx);
20c04e18c58c 6573681 deleting a very large file can be slow
maybee
parents: 6712
diff changeset
  1392
		zfs_range_unlock(rl);
20c04e18c58c 6573681 deleting a very large file can be slow
maybee
parents: 6712
diff changeset
  1393
		return (error);
20c04e18c58c 6573681 deleting a very large file can be slow
maybee
parents: 6712
diff changeset
  1394
	}
20c04e18c58c 6573681 deleting a very large file can be slow
maybee
parents: 6712
diff changeset
  1395
	dmu_buf_will_dirty(zp->z_dbuf, tx);
20c04e18c58c 6573681 deleting a very large file can be slow
maybee
parents: 6712
diff changeset
  1396
20c04e18c58c 6573681 deleting a very large file can be slow
maybee
parents: 6712
diff changeset
  1397
	zp->z_phys->zp_size = end;
20c04e18c58c 6573681 deleting a very large file can be slow
maybee
parents: 6712
diff changeset
  1398
20c04e18c58c 6573681 deleting a very large file can be slow
maybee
parents: 6712
diff changeset
  1399
	dmu_tx_commit(tx);
20c04e18c58c 6573681 deleting a very large file can be slow
maybee
parents: 6712
diff changeset
  1400
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1401
	/*
1878
c22df0f5603f 6413573 deadlock between fsflush() and zfs_create()
maybee
parents: 1816
diff changeset
  1402
	 * Clear any mapped pages in the truncated region.  This has to
c22df0f5603f 6413573 deadlock between fsflush() and zfs_create()
maybee
parents: 1816
diff changeset
  1403
	 * happen outside of the transaction to avoid the possibility of
c22df0f5603f 6413573 deadlock between fsflush() and zfs_create()
maybee
parents: 1816
diff changeset
  1404
	 * 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
  1405
	 * about to invalidate.
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1406
	 */
6992
20c04e18c58c 6573681 deleting a very large file can be slow
maybee
parents: 6712
diff changeset
  1407
	if (vn_has_cached_data(vp)) {
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1408
		page_t *pp;
6992
20c04e18c58c 6573681 deleting a very large file can be slow
maybee
parents: 6712
diff changeset
  1409
		uint64_t start = end & PAGEMASK;
20c04e18c58c 6573681 deleting a very large file can be slow
maybee
parents: 6712
diff changeset
  1410
		int poff = end & PAGEOFFSET;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1411
1878
c22df0f5603f 6413573 deadlock between fsflush() and zfs_create()
maybee
parents: 1816
diff changeset
  1412
		if (poff != 0 && (pp = page_lookup(vp, start, SE_SHARED))) {
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1413
			/*
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1414
			 * We need to zero a partial page.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1415
			 */
1878
c22df0f5603f 6413573 deadlock between fsflush() and zfs_create()
maybee
parents: 1816
diff changeset
  1416
			pagezero(pp, poff, PAGESIZE - poff);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1417
			start += PAGESIZE;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1418
			page_unlock(pp);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1419
		}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1420
		error = pvn_vplist_dirty(vp, start, zfs_no_putpage,
1878
c22df0f5603f 6413573 deadlock between fsflush() and zfs_create()
maybee
parents: 1816
diff changeset
  1421
		    B_INVAL | B_TRUNC, NULL);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1422
		ASSERT(error == 0);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1423
	}
8636
7e4ce9158df3 6551866 deadlock between zfs_write(), zfs_freesp(), and zfs_putapage()
Mark Maybee <Mark.Maybee@Sun.COM>
parents: 8227
diff changeset
  1424
7e4ce9158df3 6551866 deadlock between zfs_write(), zfs_freesp(), and zfs_putapage()
Mark Maybee <Mark.Maybee@Sun.COM>
parents: 8227
diff changeset
  1425
	zfs_range_unlock(rl);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1426
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1427
	return (0);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1428
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1429
6992
20c04e18c58c 6573681 deleting a very large file can be slow
maybee
parents: 6712
diff changeset
  1430
/*
20c04e18c58c 6573681 deleting a very large file can be slow
maybee
parents: 6712
diff changeset
  1431
 * Free space in a file
20c04e18c58c 6573681 deleting a very large file can be slow
maybee
parents: 6712
diff changeset
  1432
 *
20c04e18c58c 6573681 deleting a very large file can be slow
maybee
parents: 6712
diff changeset
  1433
 *	IN:	zp	- znode of file to free data in.
20c04e18c58c 6573681 deleting a very large file can be slow
maybee
parents: 6712
diff changeset
  1434
 *		off	- start of range
20c04e18c58c 6573681 deleting a very large file can be slow
maybee
parents: 6712
diff changeset
  1435
 *		len	- end of range (0 => EOF)
20c04e18c58c 6573681 deleting a very large file can be slow
maybee
parents: 6712
diff changeset
  1436
 *		flag	- current file open mode flags.
20c04e18c58c 6573681 deleting a very large file can be slow
maybee
parents: 6712
diff changeset
  1437
 *		log	- TRUE if this action should be logged
20c04e18c58c 6573681 deleting a very large file can be slow
maybee
parents: 6712
diff changeset
  1438
 *
20c04e18c58c 6573681 deleting a very large file can be slow
maybee
parents: 6712
diff changeset
  1439
 * 	RETURN:	0 if success
20c04e18c58c 6573681 deleting a very large file can be slow
maybee
parents: 6712
diff changeset
  1440
 *		error code if failure
20c04e18c58c 6573681 deleting a very large file can be slow
maybee
parents: 6712
diff changeset
  1441
 */
20c04e18c58c 6573681 deleting a very large file can be slow
maybee
parents: 6712
diff changeset
  1442
int
20c04e18c58c 6573681 deleting a very large file can be slow
maybee
parents: 6712
diff changeset
  1443
zfs_freesp(znode_t *zp, uint64_t off, uint64_t len, int flag, boolean_t log)
20c04e18c58c 6573681 deleting a very large file can be slow
maybee
parents: 6712
diff changeset
  1444
{
20c04e18c58c 6573681 deleting a very large file can be slow
maybee
parents: 6712
diff changeset
  1445
	vnode_t *vp = ZTOV(zp);
20c04e18c58c 6573681 deleting a very large file can be slow
maybee
parents: 6712
diff changeset
  1446
	dmu_tx_t *tx;
20c04e18c58c 6573681 deleting a very large file can be slow
maybee
parents: 6712
diff changeset
  1447
	zfsvfs_t *zfsvfs = zp->z_zfsvfs;
20c04e18c58c 6573681 deleting a very large file can be slow
maybee
parents: 6712
diff changeset
  1448
	zilog_t *zilog = zfsvfs->z_log;
20c04e18c58c 6573681 deleting a very large file can be slow
maybee
parents: 6712
diff changeset
  1449
	int error;
20c04e18c58c 6573681 deleting a very large file can be slow
maybee
parents: 6712
diff changeset
  1450
20c04e18c58c 6573681 deleting a very large file can be slow
maybee
parents: 6712
diff changeset
  1451
	if (off > zp->z_phys->zp_size) {
20c04e18c58c 6573681 deleting a very large file can be slow
maybee
parents: 6712
diff changeset
  1452
		error =  zfs_extend(zp, off+len);
20c04e18c58c 6573681 deleting a very large file can be slow
maybee
parents: 6712
diff changeset
  1453
		if (error == 0 && log)
20c04e18c58c 6573681 deleting a very large file can be slow
maybee
parents: 6712
diff changeset
  1454
			goto log;
20c04e18c58c 6573681 deleting a very large file can be slow
maybee
parents: 6712
diff changeset
  1455
		else
20c04e18c58c 6573681 deleting a very large file can be slow
maybee
parents: 6712
diff changeset
  1456
			return (error);
20c04e18c58c 6573681 deleting a very large file can be slow
maybee
parents: 6712
diff changeset
  1457
	}
20c04e18c58c 6573681 deleting a very large file can be slow
maybee
parents: 6712
diff changeset
  1458
20c04e18c58c 6573681 deleting a very large file can be slow
maybee
parents: 6712
diff changeset
  1459
	/*
20c04e18c58c 6573681 deleting a very large file can be slow
maybee
parents: 6712
diff changeset
  1460
	 * Check for any locks in the region to be freed.
20c04e18c58c 6573681 deleting a very large file can be slow
maybee
parents: 6712
diff changeset
  1461
	 */
20c04e18c58c 6573681 deleting a very large file can be slow
maybee
parents: 6712
diff changeset
  1462
	if (MANDLOCK(vp, (mode_t)zp->z_phys->zp_mode)) {
20c04e18c58c 6573681 deleting a very large file can be slow
maybee
parents: 6712
diff changeset
  1463
		uint64_t length = (len ? len : zp->z_phys->zp_size - off);
20c04e18c58c 6573681 deleting a very large file can be slow
maybee
parents: 6712
diff changeset
  1464
		if (error = chklock(vp, FWRITE, off, length, flag, NULL))
20c04e18c58c 6573681 deleting a very large file can be slow
maybee
parents: 6712
diff changeset
  1465
			return (error);
20c04e18c58c 6573681 deleting a very large file can be slow
maybee
parents: 6712
diff changeset
  1466
	}
20c04e18c58c 6573681 deleting a very large file can be slow
maybee
parents: 6712
diff changeset
  1467
20c04e18c58c 6573681 deleting a very large file can be slow
maybee
parents: 6712
diff changeset
  1468
	if (len == 0) {
20c04e18c58c 6573681 deleting a very large file can be slow
maybee
parents: 6712
diff changeset
  1469
		error = zfs_trunc(zp, off);
20c04e18c58c 6573681 deleting a very large file can be slow
maybee
parents: 6712
diff changeset
  1470
	} else {
20c04e18c58c 6573681 deleting a very large file can be slow
maybee
parents: 6712
diff changeset
  1471
		if ((error = zfs_free_range(zp, off, len)) == 0 &&
20c04e18c58c 6573681 deleting a very large file can be slow
maybee
parents: 6712
diff changeset
  1472
		    off + len > zp->z_phys->zp_size)
20c04e18c58c 6573681 deleting a very large file can be slow
maybee
parents: 6712
diff changeset
  1473
			error = zfs_extend(zp, off+len);
20c04e18c58c 6573681 deleting a very large file can be slow
maybee
parents: 6712
diff changeset
  1474
	}
20c04e18c58c 6573681 deleting a very large file can be slow
maybee
parents: 6712
diff changeset
  1475
	if (error || !log)
20c04e18c58c 6573681 deleting a very large file can be slow
maybee
parents: 6712
diff changeset
  1476
		return (error);
20c04e18c58c 6573681 deleting a very large file can be slow
maybee
parents: 6712
diff changeset
  1477
log:
20c04e18c58c 6573681 deleting a very large file can be slow
maybee
parents: 6712
diff changeset
  1478
	tx = dmu_tx_create(zfsvfs->z_os);
20c04e18c58c 6573681 deleting a very large file can be slow
maybee
parents: 6712
diff changeset
  1479
	dmu_tx_hold_bonus(tx, zp->z_id);
8227
f7d7be9b1f56 6765294 Refactor replay
Neil Perrin <Neil.Perrin@Sun.COM>
parents: 7579
diff changeset
  1480
	error = dmu_tx_assign(tx, TXG_NOWAIT);
6992
20c04e18c58c 6573681 deleting a very large file can be slow
maybee
parents: 6712
diff changeset
  1481
	if (error) {
8227
f7d7be9b1f56 6765294 Refactor replay
Neil Perrin <Neil.Perrin@Sun.COM>
parents: 7579
diff changeset
  1482
		if (error == ERESTART) {
6992
20c04e18c58c 6573681 deleting a very large file can be slow
maybee
parents: 6712
diff changeset
  1483
			dmu_tx_wait(tx);
20c04e18c58c 6573681 deleting a very large file can be slow
maybee
parents: 6712
diff changeset
  1484
			dmu_tx_abort(tx);
20c04e18c58c 6573681 deleting a very large file can be slow
maybee
parents: 6712
diff changeset
  1485
			goto log;
20c04e18c58c 6573681 deleting a very large file can be slow
maybee
parents: 6712
diff changeset
  1486
		}
20c04e18c58c 6573681 deleting a very large file can be slow
maybee
parents: 6712
diff changeset
  1487
		dmu_tx_abort(tx);
20c04e18c58c 6573681 deleting a very large file can be slow
maybee
parents: 6712
diff changeset
  1488
		return (error);
20c04e18c58c 6573681 deleting a very large file can be slow
maybee
parents: 6712
diff changeset
  1489
	}
20c04e18c58c 6573681 deleting a very large file can be slow
maybee
parents: 6712
diff changeset
  1490
20c04e18c58c 6573681 deleting a very large file can be slow
maybee
parents: 6712
diff changeset
  1491
	zfs_time_stamper(zp, CONTENT_MODIFIED, tx);
20c04e18c58c 6573681 deleting a very large file can be slow
maybee
parents: 6712
diff changeset
  1492
	zfs_log_truncate(zilog, tx, TX_TRUNCATE, zp, off, len);
20c04e18c58c 6573681 deleting a very large file can be slow
maybee
parents: 6712
diff changeset
  1493
20c04e18c58c 6573681 deleting a very large file can be slow
maybee
parents: 6712
diff changeset
  1494
	dmu_tx_commit(tx);
20c04e18c58c 6573681 deleting a very large file can be slow
maybee
parents: 6712
diff changeset
  1495
	return (0);
20c04e18c58c 6573681 deleting a very large file can be slow
maybee
parents: 6712
diff changeset
  1496
}
20c04e18c58c 6573681 deleting a very large file can be slow
maybee
parents: 6712
diff changeset
  1497
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1498
void
5498
334b476844ca 6622831 normalization properties are not preserved by "zfs send"
timh
parents: 5446
diff changeset
  1499
zfs_create_fs(objset_t *os, cred_t *cr, nvlist_t *zplprops, dmu_tx_t *tx)
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1500
{
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1501
	zfsvfs_t	zfsvfs;
9396
f41cf682d0d3 PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 9179
diff changeset
  1502
	uint64_t	moid, obj, version;
5498
334b476844ca 6622831 normalization properties are not preserved by "zfs send"
timh
parents: 5446
diff changeset
  1503
	uint64_t	sense = ZFS_CASE_SENSITIVE;
334b476844ca 6622831 normalization properties are not preserved by "zfs send"
timh
parents: 5446
diff changeset
  1504
	uint64_t	norm = 0;
334b476844ca 6622831 normalization properties are not preserved by "zfs send"
timh
parents: 5446
diff changeset
  1505
	nvpair_t	*elem;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1506
	int		error;
10938
270624bd70f1 6895088 panic: existing znode ffffff84e4747da0 for dbuf ffffff8271678e18
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 10793
diff changeset
  1507
	int		i;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1508
	znode_t		*rootzp = NULL;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1509
	vnode_t		*vp;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1510
	vattr_t		vattr;
5446
51fbc14b301d 6421210 zfs rollback without unmounting
ahrens
parents: 5331
diff changeset
  1511
	znode_t		*zp;
9179
d8fbd96b79b3 6790064 zfs needs to determine uid and gid earlier in create process
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 9030
diff changeset
  1512
	zfs_acl_ids_t	acl_ids;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1513
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1514
	/*
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1515
	 * First attempt to create master node.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1516
	 */
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1394
diff changeset
  1517
	/*
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1394
diff changeset
  1518
	 * In an empty objset, there are no blocks to read and thus
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1394
diff changeset
  1519
	 * there can be no i/o errors (which we assert below).
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1394
diff changeset
  1520
	 */
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1521
	moid = MASTER_NODE_OBJ;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1522
	error = zap_create_claim(os, moid, DMU_OT_MASTER_NODE,
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1523
	    DMU_OT_NONE, 0, tx);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1524
	ASSERT(error == 0);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1525
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1526
	/*
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1527
	 * Set starting attributes.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1528
	 */
9396
f41cf682d0d3 PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 9179
diff changeset
  1529
	if (spa_version(dmu_objset_spa(os)) >= SPA_VERSION_USERSPACE)
7046
361307ae060d 6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents: 6992
diff changeset
  1530
		version = ZPL_VERSION;
9396
f41cf682d0d3 PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 9179
diff changeset
  1531
	else if (spa_version(dmu_objset_spa(os)) >= SPA_VERSION_FUID)
f41cf682d0d3 PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 9179
diff changeset
  1532
		version = ZPL_VERSION_USERSPACE - 1;
7046
361307ae060d 6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents: 6992
diff changeset
  1533
	else
361307ae060d 6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents: 6992
diff changeset
  1534
		version = ZPL_VERSION_FUID - 1;
5498
334b476844ca 6622831 normalization properties are not preserved by "zfs send"
timh
parents: 5446
diff changeset
  1535
	elem = NULL;
334b476844ca 6622831 normalization properties are not preserved by "zfs send"
timh
parents: 5446
diff changeset
  1536
	while ((elem = nvlist_next_nvpair(zplprops, elem)) != NULL) {
334b476844ca 6622831 normalization properties are not preserved by "zfs send"
timh
parents: 5446
diff changeset
  1537
		/* For the moment we expect all zpl props to be uint64_ts */
334b476844ca 6622831 normalization properties are not preserved by "zfs send"
timh
parents: 5446
diff changeset
  1538
		uint64_t val;
334b476844ca 6622831 normalization properties are not preserved by "zfs send"
timh
parents: 5446
diff changeset
  1539
		char *name;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1540
5498
334b476844ca 6622831 normalization properties are not preserved by "zfs send"
timh
parents: 5446
diff changeset
  1541
		ASSERT(nvpair_type(elem) == DATA_TYPE_UINT64);
5520
70184f49637e 6633610 cannot successfully 'zpool create' on non-debug bits after 6622831
timh
parents: 5498
diff changeset
  1542
		VERIFY(nvpair_value_uint64(elem, &val) == 0);
5498
334b476844ca 6622831 normalization properties are not preserved by "zfs send"
timh
parents: 5446
diff changeset
  1543
		name = nvpair_name(elem);
334b476844ca 6622831 normalization properties are not preserved by "zfs send"
timh
parents: 5446
diff changeset
  1544
		if (strcmp(name, zfs_prop_to_name(ZFS_PROP_VERSION)) == 0) {
9396
f41cf682d0d3 PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 9179
diff changeset
  1545
			if (val < version)
f41cf682d0d3 PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 9179
diff changeset
  1546
				version = val;
5498
334b476844ca 6622831 normalization properties are not preserved by "zfs send"
timh
parents: 5446
diff changeset
  1547
		} else {
334b476844ca 6622831 normalization properties are not preserved by "zfs send"
timh
parents: 5446
diff changeset
  1548
			error = zap_update(os, moid, name, 8, 1, &val, tx);
334b476844ca 6622831 normalization properties are not preserved by "zfs send"
timh
parents: 5446
diff changeset
  1549
		}
334b476844ca 6622831 normalization properties are not preserved by "zfs send"
timh
parents: 5446
diff changeset
  1550
		ASSERT(error == 0);
334b476844ca 6622831 normalization properties are not preserved by "zfs send"
timh
parents: 5446
diff changeset
  1551
		if (strcmp(name, zfs_prop_to_name(ZFS_PROP_NORMALIZE)) == 0)
334b476844ca 6622831 normalization properties are not preserved by "zfs send"
timh
parents: 5446
diff changeset
  1552
			norm = val;
334b476844ca 6622831 normalization properties are not preserved by "zfs send"
timh
parents: 5446
diff changeset
  1553
		else if (strcmp(name, zfs_prop_to_name(ZFS_PROP_CASE)) == 0)
334b476844ca 6622831 normalization properties are not preserved by "zfs send"
timh
parents: 5446
diff changeset
  1554
			sense = val;
334b476844ca 6622831 normalization properties are not preserved by "zfs send"
timh
parents: 5446
diff changeset
  1555
	}
334b476844ca 6622831 normalization properties are not preserved by "zfs send"
timh
parents: 5446
diff changeset
  1556
	ASSERT(version != 0);
9396
f41cf682d0d3 PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 9179
diff changeset
  1557
	error = zap_update(os, moid, ZPL_VERSION_STR, 8, 1, &version, tx);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1558
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1559
	/*
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1560
	 * Create a delete queue.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1561
	 */
9396
f41cf682d0d3 PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 9179
diff changeset
  1562
	obj = zap_create(os, DMU_OT_UNLINKED_SET, DMU_OT_NONE, 0, tx);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1563
9396
f41cf682d0d3 PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 9179
diff changeset
  1564
	error = zap_add(os, moid, ZFS_UNLINKED_SET, 8, 1, &obj, tx);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1565
	ASSERT(error == 0);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1566
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1567
	/*
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1568
	 * Create root znode.  Create minimal znode/vnode/zfsvfs
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1569
	 * to allow zfs_mknode to work.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1570
	 */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1571
	vattr.va_mask = AT_MODE|AT_UID|AT_GID|AT_TYPE;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1572
	vattr.va_type = VDIR;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1573
	vattr.va_mode = S_IFDIR|0755;
4543
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4144
diff changeset
  1574
	vattr.va_uid = crgetuid(cr);
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4144
diff changeset
  1575
	vattr.va_gid = crgetgid(cr);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1576
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1577
	rootzp = kmem_cache_alloc(znode_cache, KM_SLEEP);
3461
c19b22f347d6 6514331 in-memory delete queue is not needed
ahrens
parents: 3444
diff changeset
  1578
	rootzp->z_unlinked = 0;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1579
	rootzp->z_atime_dirty = 0;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1580
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1581
	vp = ZTOV(rootzp);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1582
	vn_reinit(vp);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1583
	vp->v_type = VDIR;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1584
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1585
	bzero(&zfsvfs, sizeof (zfsvfs_t));
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1586
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1587
	zfsvfs.z_os = os;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1588
	zfsvfs.z_parent = &zfsvfs;
5331
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5326
diff changeset
  1589
	zfsvfs.z_version = version;
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5326
diff changeset
  1590
	zfsvfs.z_use_fuids = USE_FUIDS(version, os);
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5326
diff changeset
  1591
	zfsvfs.z_norm = norm;
5498
334b476844ca 6622831 normalization properties are not preserved by "zfs send"
timh
parents: 5446
diff changeset
  1592
	/*
334b476844ca 6622831 normalization properties are not preserved by "zfs send"
timh
parents: 5446
diff changeset
  1593
	 * Fold case on file systems that are always or sometimes case
334b476844ca 6622831 normalization properties are not preserved by "zfs send"
timh
parents: 5446
diff changeset
  1594
	 * insensitive.
334b476844ca 6622831 normalization properties are not preserved by "zfs send"
timh
parents: 5446
diff changeset
  1595
	 */
334b476844ca 6622831 normalization properties are not preserved by "zfs send"
timh
parents: 5446
diff changeset
  1596
	if (sense == ZFS_CASE_INSENSITIVE || sense == ZFS_CASE_MIXED)
334b476844ca 6622831 normalization properties are not preserved by "zfs send"
timh
parents: 5446
diff changeset
  1597
		zfsvfs.z_norm |= U8_TEXTPREP_TOUPPER;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1598
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1599
	mutex_init(&zfsvfs.z_znodes_lock, NULL, MUTEX_DEFAULT, NULL);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1600
	list_create(&zfsvfs.z_all_znodes, sizeof (znode_t),
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1601
	    offsetof(znode_t, z_link_node));
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1602
10938
270624bd70f1 6895088 panic: existing znode ffffff84e4747da0 for dbuf ffffff8271678e18
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 10793
diff changeset
  1603
	for (i = 0; i != ZFS_OBJ_MTX_SZ; i++)
270624bd70f1 6895088 panic: existing znode ffffff84e4747da0 for dbuf ffffff8271678e18
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 10793
diff changeset
  1604
		mutex_init(&zfsvfs.z_hold_mtx[i], NULL, MUTEX_DEFAULT, NULL);
270624bd70f1 6895088 panic: existing znode ffffff84e4747da0 for dbuf ffffff8271678e18
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 10793
diff changeset
  1605
6712
79afecec3f3c 6554564 slab allocator cannot release slabs with lonely buffers
tomee
parents: 6492
diff changeset
  1606
	ASSERT(!POINTER_IS_VALID(rootzp->z_zfsvfs));
79afecec3f3c 6554564 slab allocator cannot release slabs with lonely buffers
tomee
parents: 6492
diff changeset
  1607
	rootzp->z_zfsvfs = &zfsvfs;
9179
d8fbd96b79b3 6790064 zfs needs to determine uid and gid earlier in create process
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 9030
diff changeset
  1608
	VERIFY(0 == zfs_acl_ids_create(rootzp, IS_ROOT_NODE, &vattr,
d8fbd96b79b3 6790064 zfs needs to determine uid and gid earlier in create process
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 9030
diff changeset
  1609
	    cr, NULL, &acl_ids));
d8fbd96b79b3 6790064 zfs needs to determine uid and gid earlier in create process
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 9030
diff changeset
  1610
	zfs_mknode(rootzp, &vattr, tx, cr, IS_ROOT_NODE, &zp, 0, &acl_ids);
5642
504c84876fda 6513209 Destroying pools under stress caused a hang in arc_flush
maybee
parents: 5520
diff changeset
  1611
	ASSERT3P(zp, ==, rootzp);
6712
79afecec3f3c 6554564 slab allocator cannot release slabs with lonely buffers
tomee
parents: 6492
diff changeset
  1612
	ASSERT(!vn_in_dnlc(ZTOV(rootzp))); /* not valid to move */
5446
51fbc14b301d 6421210 zfs rollback without unmounting
ahrens
parents: 5331
diff changeset
  1613
	error = zap_add(os, moid, ZFS_ROOT_OBJ, 8, 1, &rootzp->z_id, tx);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1614
	ASSERT(error == 0);
9179
d8fbd96b79b3 6790064 zfs needs to determine uid and gid earlier in create process
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 9030
diff changeset
  1615
	zfs_acl_ids_free(&acl_ids);
6712
79afecec3f3c 6554564 slab allocator cannot release slabs with lonely buffers
tomee
parents: 6492
diff changeset
  1616
	POINTER_INVALIDATE(&rootzp->z_zfsvfs);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1617
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1618
	ZTOV(rootzp)->v_count = 0;
5642
504c84876fda 6513209 Destroying pools under stress caused a hang in arc_flush
maybee
parents: 5520
diff changeset
  1619
	dmu_buf_rele(rootzp->z_dbuf, NULL);
504c84876fda 6513209 Destroying pools under stress caused a hang in arc_flush
maybee
parents: 5520
diff changeset
  1620
	rootzp->z_dbuf = NULL;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1621
	kmem_cache_free(znode_cache, rootzp);
8845
91af0d9c0790 6800942 smb_session_create() incorrectly stores IP addresses
Alan Wright <amw@Sun.COM>
parents: 8636
diff changeset
  1622
91af0d9c0790 6800942 smb_session_create() incorrectly stores IP addresses
Alan Wright <amw@Sun.COM>
parents: 8636
diff changeset
  1623
	/*
91af0d9c0790 6800942 smb_session_create() incorrectly stores IP addresses
Alan Wright <amw@Sun.COM>
parents: 8636
diff changeset
  1624
	 * Create shares directory
91af0d9c0790 6800942 smb_session_create() incorrectly stores IP addresses
Alan Wright <amw@Sun.COM>
parents: 8636
diff changeset
  1625
	 */
91af0d9c0790 6800942 smb_session_create() incorrectly stores IP addresses
Alan Wright <amw@Sun.COM>
parents: 8636
diff changeset
  1626
91af0d9c0790 6800942 smb_session_create() incorrectly stores IP addresses
Alan Wright <amw@Sun.COM>
parents: 8636
diff changeset
  1627
	error = zfs_create_share_dir(&zfsvfs, tx);
9179
d8fbd96b79b3 6790064 zfs needs to determine uid and gid earlier in create process
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 9030
diff changeset
  1628
8845
91af0d9c0790 6800942 smb_session_create() incorrectly stores IP addresses
Alan Wright <amw@Sun.COM>
parents: 8636
diff changeset
  1629
	ASSERT(error == 0);
10938
270624bd70f1 6895088 panic: existing znode ffffff84e4747da0 for dbuf ffffff8271678e18
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 10793
diff changeset
  1630
270624bd70f1 6895088 panic: existing znode ffffff84e4747da0 for dbuf ffffff8271678e18
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 10793
diff changeset
  1631
	for (i = 0; i != ZFS_OBJ_MTX_SZ; i++)
270624bd70f1 6895088 panic: existing znode ffffff84e4747da0 for dbuf ffffff8271678e18
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 10793
diff changeset
  1632
		mutex_destroy(&zfsvfs.z_hold_mtx[i]);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1633
}
5331
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5326
diff changeset
  1634
3444
dc160a70a50d 6410433 'zpool status -v' would be more useful with filenames
ek110237
parents: 3063
diff changeset
  1635
#endif /* _KERNEL */
dc160a70a50d 6410433 'zpool status -v' would be more useful with filenames
ek110237
parents: 3063
diff changeset
  1636
/*
dc160a70a50d 6410433 'zpool status -v' would be more useful with filenames
ek110237
parents: 3063
diff changeset
  1637
 * 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
  1638
 * 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
  1639
 */
dc160a70a50d 6410433 'zpool status -v' would be more useful with filenames
ek110237
parents: 3063
diff changeset
  1640
static int
dc160a70a50d 6410433 'zpool status -v' would be more useful with filenames
ek110237
parents: 3063
diff changeset
  1641
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
  1642
{
dc160a70a50d 6410433 'zpool status -v' would be more useful with filenames
ek110237
parents: 3063
diff changeset
  1643
	dmu_buf_t *db;
dc160a70a50d 6410433 'zpool status -v' would be more useful with filenames
ek110237
parents: 3063
diff changeset
  1644
	dmu_object_info_t doi;
dc160a70a50d 6410433 'zpool status -v' would be more useful with filenames
ek110237
parents: 3063
diff changeset
  1645
	znode_phys_t *zp;
dc160a70a50d 6410433 'zpool status -v' would be more useful with filenames
ek110237
parents: 3063
diff changeset
  1646
	int error;
dc160a70a50d 6410433 'zpool status -v' would be more useful with filenames
ek110237
parents: 3063
diff changeset
  1647
dc160a70a50d 6410433 'zpool status -v' would be more useful with filenames
ek110237
parents: 3063
diff changeset
  1648
	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
  1649
		return (error);
dc160a70a50d 6410433 'zpool status -v' would be more useful with filenames
ek110237
parents: 3063
diff changeset
  1650
dc160a70a50d 6410433 'zpool status -v' would be more useful with filenames
ek110237
parents: 3063
diff changeset
  1651
	dmu_object_info_from_db(db, &doi);
dc160a70a50d 6410433 'zpool status -v' would be more useful with filenames
ek110237
parents: 3063
diff changeset
  1652
	if (doi.doi_bonus_type != DMU_OT_ZNODE ||
dc160a70a50d 6410433 'zpool status -v' would be more useful with filenames
ek110237
parents: 3063
diff changeset
  1653
	    doi.doi_bonus_size < sizeof (znode_phys_t)) {
dc160a70a50d 6410433 'zpool status -v' would be more useful with filenames
ek110237
parents: 3063
diff changeset
  1654
		dmu_buf_rele(db, FTAG);
dc160a70a50d 6410433 'zpool status -v' would be more useful with filenames
ek110237
parents: 3063
diff changeset
  1655
		return (EINVAL);
dc160a70a50d 6410433 'zpool status -v' would be more useful with filenames
ek110237
parents: 3063
diff changeset
  1656
	}
dc160a70a50d 6410433 'zpool status -v' would be more useful with filenames
ek110237
parents: 3063
diff changeset
  1657
dc160a70a50d 6410433 'zpool status -v' would be more useful with filenames
ek110237
parents: 3063
diff changeset
  1658
	zp = db->db_data;
dc160a70a50d 6410433 'zpool status -v' would be more useful with filenames
ek110237
parents: 3063
diff changeset
  1659
	*pobjp = zp->zp_parent;
dc160a70a50d 6410433 'zpool status -v' would be more useful with filenames
ek110237
parents: 3063
diff changeset
  1660
	*is_xattrdir = ((zp->zp_flags & ZFS_XATTR) != 0) &&
dc160a70a50d 6410433 'zpool status -v' would be more useful with filenames
ek110237
parents: 3063
diff changeset
  1661
	    S_ISDIR(zp->zp_mode);
dc160a70a50d 6410433 'zpool status -v' would be more useful with filenames
ek110237
parents: 3063
diff changeset
  1662
	dmu_buf_rele(db, FTAG);
dc160a70a50d 6410433 'zpool status -v' would be more useful with filenames
ek110237
parents: 3063
diff changeset
  1663
dc160a70a50d 6410433 'zpool status -v' would be more useful with filenames
ek110237
parents: 3063
diff changeset
  1664
	return (0);
dc160a70a50d 6410433 'zpool status -v' would be more useful with filenames
ek110237
parents: 3063
diff changeset
  1665
}
dc160a70a50d 6410433 'zpool status -v' would be more useful with filenames
ek110237
parents: 3063
diff changeset
  1666
dc160a70a50d 6410433 'zpool status -v' would be more useful with filenames
ek110237
parents: 3063
diff changeset
  1667
int
dc160a70a50d 6410433 'zpool status -v' would be more useful with filenames
ek110237
parents: 3063
diff changeset
  1668
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
  1669
{
dc160a70a50d 6410433 'zpool status -v' would be more useful with filenames
ek110237
parents: 3063
diff changeset
  1670
	char *path = buf + len - 1;
dc160a70a50d 6410433 'zpool status -v' would be more useful with filenames
ek110237
parents: 3063
diff changeset
  1671
	int error;
dc160a70a50d 6410433 'zpool status -v' would be more useful with filenames
ek110237
parents: 3063
diff changeset
  1672
dc160a70a50d 6410433 'zpool status -v' would be more useful with filenames
ek110237
parents: 3063
diff changeset
  1673
	*path = '\0';
dc160a70a50d 6410433 'zpool status -v' would be more useful with filenames
ek110237
parents: 3063
diff changeset
  1674
dc160a70a50d 6410433 'zpool status -v' would be more useful with filenames
ek110237
parents: 3063
diff changeset
  1675
	for (;;) {
dc160a70a50d 6410433 'zpool status -v' would be more useful with filenames
ek110237
parents: 3063
diff changeset
  1676
		uint64_t pobj;
dc160a70a50d 6410433 'zpool status -v' would be more useful with filenames
ek110237
parents: 3063
diff changeset
  1677
		char component[MAXNAMELEN + 2];
dc160a70a50d 6410433 'zpool status -v' would be more useful with filenames
ek110237
parents: 3063
diff changeset
  1678
		size_t complen;
dc160a70a50d 6410433 'zpool status -v' would be more useful with filenames
ek110237
parents: 3063
diff changeset
  1679
		int is_xattrdir;
dc160a70a50d 6410433 'zpool status -v' would be more useful with filenames
ek110237
parents: 3063
diff changeset
  1680
dc160a70a50d 6410433 'zpool status -v' would be more useful with filenames
ek110237
parents: 3063
diff changeset
  1681
		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
  1682
		    &is_xattrdir)) != 0)
dc160a70a50d 6410433 'zpool status -v' would be more useful with filenames
ek110237
parents: 3063
diff changeset
  1683
			break;
dc160a70a50d 6410433 'zpool status -v' would be more useful with filenames
ek110237
parents: 3063
diff changeset
  1684
dc160a70a50d 6410433 'zpool status -v' would be more useful with filenames
ek110237
parents: 3063
diff changeset
  1685
		if (pobj == obj) {
dc160a70a50d 6410433 'zpool status -v' would be more useful with filenames
ek110237
parents: 3063
diff changeset
  1686
			if (path[0] != '/')
dc160a70a50d 6410433 'zpool status -v' would be more useful with filenames
ek110237
parents: 3063
diff changeset
  1687
				*--path = '/';
dc160a70a50d 6410433 'zpool status -v' would be more useful with filenames
ek110237
parents: 3063
diff changeset
  1688
			break;
dc160a70a50d 6410433 'zpool status -v' would be more useful with filenames
ek110237
parents: 3063
diff changeset
  1689
		}
dc160a70a50d 6410433 'zpool status -v' would be more useful with filenames
ek110237
parents: 3063
diff changeset
  1690
dc160a70a50d 6410433 'zpool status -v' would be more useful with filenames
ek110237
parents: 3063
diff changeset
  1691
		component[0] = '/';
dc160a70a50d 6410433 'zpool status -v' would be more useful with filenames
ek110237
parents: 3063
diff changeset
  1692
		if (is_xattrdir) {
dc160a70a50d 6410433 'zpool status -v' would be more useful with filenames
ek110237
parents: 3063
diff changeset
  1693
			(void) sprintf(component + 1, "<xattrdir>");
dc160a70a50d 6410433 'zpool status -v' would be more useful with filenames
ek110237
parents: 3063
diff changeset
  1694
		} else {
4577
ed36b0e652bc PSARC/2007/328 zfs upgrade
ahrens
parents: 4543
diff changeset
  1695
			error = zap_value_search(osp, pobj, obj,
ed36b0e652bc PSARC/2007/328 zfs upgrade
ahrens
parents: 4543
diff changeset
  1696
			    ZFS_DIRENT_OBJ(-1ULL), component + 1);
3444
dc160a70a50d 6410433 'zpool status -v' would be more useful with filenames
ek110237
parents: 3063
diff changeset
  1697
			if (error != 0)
dc160a70a50d 6410433 'zpool status -v' would be more useful with filenames
ek110237
parents: 3063
diff changeset
  1698
				break;
dc160a70a50d 6410433 'zpool status -v' would be more useful with filenames
ek110237
parents: 3063
diff changeset
  1699
		}
dc160a70a50d 6410433 'zpool status -v' would be more useful with filenames
ek110237
parents: 3063
diff changeset
  1700
dc160a70a50d 6410433 'zpool status -v' would be more useful with filenames
ek110237
parents: 3063
diff changeset
  1701
		complen = strlen(component);
dc160a70a50d 6410433 'zpool status -v' would be more useful with filenames
ek110237
parents: 3063
diff changeset
  1702
		path -= complen;
dc160a70a50d 6410433 'zpool status -v' would be more useful with filenames
ek110237
parents: 3063
diff changeset
  1703
		ASSERT(path >= buf);
dc160a70a50d 6410433 'zpool status -v' would be more useful with filenames
ek110237
parents: 3063
diff changeset
  1704
		bcopy(component, path, complen);
dc160a70a50d 6410433 'zpool status -v' would be more useful with filenames
ek110237
parents: 3063
diff changeset
  1705
		obj = pobj;
dc160a70a50d 6410433 'zpool status -v' would be more useful with filenames
ek110237
parents: 3063
diff changeset
  1706
	}
dc160a70a50d 6410433 'zpool status -v' would be more useful with filenames
ek110237
parents: 3063
diff changeset
  1707
dc160a70a50d 6410433 'zpool status -v' would be more useful with filenames
ek110237
parents: 3063
diff changeset
  1708
	if (error == 0)
dc160a70a50d 6410433 'zpool status -v' would be more useful with filenames
ek110237
parents: 3063
diff changeset
  1709
		(void) memmove(buf, path, buf + len - path);
dc160a70a50d 6410433 'zpool status -v' would be more useful with filenames
ek110237
parents: 3063
diff changeset
  1710
	return (error);
dc160a70a50d 6410433 'zpool status -v' would be more useful with filenames
ek110237
parents: 3063
diff changeset
  1711
}