usr/src/lib/libzpool/common/kernel.c
author Matthew Ahrens <mahrens@delphix.com>
Sat, 30 Jun 2012 13:00:47 -0700
changeset 13743 95aba6e49b9f
parent 13700 2889e2596bd6
child 13869 921a99998bb4
permissions -rw-r--r--
2882 implement libzfs_core 2883 changing "canmount" property to "on" should not always remount dataset 2900 "zfs snapshot" should be able to create multiple, arbitrary snapshots at once Reviewed by: George Wilson <[email protected]> Reviewed by: Chris Siden <[email protected]> Reviewed by: Garrett D'Amore <[email protected]> Reviewed by: Bill Pijewski <[email protected]> Reviewed by: Dan Kruchinin <[email protected]> Approved by: Eric Schrock <[email protected]>
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: 789
diff changeset
     5
 * Common Development and Distribution License (the "License").
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 789
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
/*
12527
693dd2cad55f 6884007 zfs_send() can leave temporary holds around
Chris Kirby <Chris.Kirby@oracle.com>
parents: 11935
diff changeset
    22
 * Copyright (c) 2005, 2010, Oracle and/or its affiliates. All rights reserved.
13682
e7836650181b 1618 zfs causing system to hang in vmem_xalloc()
George Wilson <gwilson@delphix.com>
parents: 12798
diff changeset
    23
 * Copyright (c) 2012 by Delphix. All rights reserved.
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    24
 */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    25
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    26
#include <assert.h>
3886
3291401d66a6 6536602 add zlib compression support and upgrade to version 1.2.3
ahl
parents: 3713
diff changeset
    27
#include <fcntl.h>
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    28
#include <poll.h>
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    29
#include <stdio.h>
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    30
#include <stdlib.h>
3886
3291401d66a6 6536602 add zlib compression support and upgrade to version 1.2.3
ahl
parents: 3713
diff changeset
    31
#include <string.h>
3291401d66a6 6536602 add zlib compression support and upgrade to version 1.2.3
ahl
parents: 3713
diff changeset
    32
#include <zlib.h>
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    33
#include <sys/spa.h>
3886
3291401d66a6 6536602 add zlib compression support and upgrade to version 1.2.3
ahl
parents: 3713
diff changeset
    34
#include <sys/stat.h>
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    35
#include <sys/processor.h>
3886
3291401d66a6 6536602 add zlib compression support and upgrade to version 1.2.3
ahl
parents: 3713
diff changeset
    36
#include <sys/zfs_context.h>
3291401d66a6 6536602 add zlib compression support and upgrade to version 1.2.3
ahl
parents: 3713
diff changeset
    37
#include <sys/zmod.h>
3975
6674f5d79069 6282725 hostname/hostid should be stored in the label
ek110237
parents: 3912
diff changeset
    38
#include <sys/utsname.h>
8662
18153249ee93 PSARC/2008/647 Configurable Hostids for Non-Global Zones
jv227347 <Jordan.Vaughan@Sun.com>
parents: 7837
diff changeset
    39
#include <sys/systeminfo.h>
2856
6f4d5ee1906a 6463348 ZFS code could be more portable
nd150628
parents: 1635
diff changeset
    40
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    41
/*
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    42
 * Emulation of kernel services in userland.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    43
 */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    44
11726
9686f6127423 6896791 want zdb option to set aok and zfs_recover
Victor Latushkin <Victor.Latushkin@Sun.COM>
parents: 11173
diff changeset
    45
int aok;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    46
uint64_t physmem;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    47
vnode_t *rootdir = (vnode_t *)0xabcd1234;
8662
18153249ee93 PSARC/2008/647 Configurable Hostids for Non-Global Zones
jv227347 <Jordan.Vaughan@Sun.com>
parents: 7837
diff changeset
    48
char hw_serial[HW_HOSTID_LEN];
13682
e7836650181b 1618 zfs causing system to hang in vmem_xalloc()
George Wilson <gwilson@delphix.com>
parents: 12798
diff changeset
    49
vmem_t *zio_arena = NULL;
3975
6674f5d79069 6282725 hostname/hostid should be stored in the label
ek110237
parents: 3912
diff changeset
    50
6674f5d79069 6282725 hostname/hostid should be stored in the label
ek110237
parents: 3912
diff changeset
    51
struct utsname utsname = {
6674f5d79069 6282725 hostname/hostid should be stored in the label
ek110237
parents: 3912
diff changeset
    52
	"userland", "libzpool", "1", "1", "na"
6674f5d79069 6282725 hostname/hostid should be stored in the label
ek110237
parents: 3912
diff changeset
    53
};
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    54
11173
87f3734e64df 6881015 ZFS write activity prevents other threads from running in a timely manner
Jonathan Adams <Jonathan.Adams@Sun.COM>
parents: 11066
diff changeset
    55
/* this only exists to have its address taken */
87f3734e64df 6881015 ZFS write activity prevents other threads from running in a timely manner
Jonathan Adams <Jonathan.Adams@Sun.COM>
parents: 11066
diff changeset
    56
struct proc p0;
87f3734e64df 6881015 ZFS write activity prevents other threads from running in a timely manner
Jonathan Adams <Jonathan.Adams@Sun.COM>
parents: 11066
diff changeset
    57
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    58
/*
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    59
 * =========================================================================
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    60
 * threads
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    61
 * =========================================================================
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    62
 */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    63
/*ARGSUSED*/
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    64
kthread_t *
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    65
zk_thread_create(void (*func)(), void *arg)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    66
{
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    67
	thread_t tid;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    68
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    69
	VERIFY(thr_create(0, 0, (void *(*)(void *))func, arg, THR_DETACHED,
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    70
	    &tid) == 0);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    71
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    72
	return ((void *)(uintptr_t)tid);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    73
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    74
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    75
/*
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    76
 * =========================================================================
3403
e52013d23622 6510807 ARC statistics should be exported via kstat
bmc
parents: 2856
diff changeset
    77
 * kstats
e52013d23622 6510807 ARC statistics should be exported via kstat
bmc
parents: 2856
diff changeset
    78
 * =========================================================================
e52013d23622 6510807 ARC statistics should be exported via kstat
bmc
parents: 2856
diff changeset
    79
 */
e52013d23622 6510807 ARC statistics should be exported via kstat
bmc
parents: 2856
diff changeset
    80
/*ARGSUSED*/
e52013d23622 6510807 ARC statistics should be exported via kstat
bmc
parents: 2856
diff changeset
    81
kstat_t *
e52013d23622 6510807 ARC statistics should be exported via kstat
bmc
parents: 2856
diff changeset
    82
kstat_create(char *module, int instance, char *name, char *class,
e52013d23622 6510807 ARC statistics should be exported via kstat
bmc
parents: 2856
diff changeset
    83
    uchar_t type, ulong_t ndata, uchar_t ks_flag)
e52013d23622 6510807 ARC statistics should be exported via kstat
bmc
parents: 2856
diff changeset
    84
{
e52013d23622 6510807 ARC statistics should be exported via kstat
bmc
parents: 2856
diff changeset
    85
	return (NULL);
e52013d23622 6510807 ARC statistics should be exported via kstat
bmc
parents: 2856
diff changeset
    86
}
e52013d23622 6510807 ARC statistics should be exported via kstat
bmc
parents: 2856
diff changeset
    87
e52013d23622 6510807 ARC statistics should be exported via kstat
bmc
parents: 2856
diff changeset
    88
/*ARGSUSED*/
e52013d23622 6510807 ARC statistics should be exported via kstat
bmc
parents: 2856
diff changeset
    89
void
e52013d23622 6510807 ARC statistics should be exported via kstat
bmc
parents: 2856
diff changeset
    90
kstat_install(kstat_t *ksp)
e52013d23622 6510807 ARC statistics should be exported via kstat
bmc
parents: 2856
diff changeset
    91
{}
e52013d23622 6510807 ARC statistics should be exported via kstat
bmc
parents: 2856
diff changeset
    92
e52013d23622 6510807 ARC statistics should be exported via kstat
bmc
parents: 2856
diff changeset
    93
/*ARGSUSED*/
e52013d23622 6510807 ARC statistics should be exported via kstat
bmc
parents: 2856
diff changeset
    94
void
e52013d23622 6510807 ARC statistics should be exported via kstat
bmc
parents: 2856
diff changeset
    95
kstat_delete(kstat_t *ksp)
e52013d23622 6510807 ARC statistics should be exported via kstat
bmc
parents: 2856
diff changeset
    96
{}
e52013d23622 6510807 ARC statistics should be exported via kstat
bmc
parents: 2856
diff changeset
    97
e52013d23622 6510807 ARC statistics should be exported via kstat
bmc
parents: 2856
diff changeset
    98
/*
e52013d23622 6510807 ARC statistics should be exported via kstat
bmc
parents: 2856
diff changeset
    99
 * =========================================================================
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   100
 * mutexes
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   101
 * =========================================================================
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   102
 */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   103
void
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   104
zmutex_init(kmutex_t *mp)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   105
{
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   106
	mp->m_owner = NULL;
4831
41ec732c6d9f 6584470 zdb needs to initialize the bpl_lock mutex
gw25295
parents: 4543
diff changeset
   107
	mp->initialized = B_TRUE;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   108
	(void) _mutex_init(&mp->m_lock, USYNC_THREAD, NULL);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   109
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   110
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   111
void
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   112
zmutex_destroy(kmutex_t *mp)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   113
{
4831
41ec732c6d9f 6584470 zdb needs to initialize the bpl_lock mutex
gw25295
parents: 4543
diff changeset
   114
	ASSERT(mp->initialized == B_TRUE);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   115
	ASSERT(mp->m_owner == NULL);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   116
	(void) _mutex_destroy(&(mp)->m_lock);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   117
	mp->m_owner = (void *)-1UL;
4831
41ec732c6d9f 6584470 zdb needs to initialize the bpl_lock mutex
gw25295
parents: 4543
diff changeset
   118
	mp->initialized = B_FALSE;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   119
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   120
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   121
void
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   122
mutex_enter(kmutex_t *mp)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   123
{
4831
41ec732c6d9f 6584470 zdb needs to initialize the bpl_lock mutex
gw25295
parents: 4543
diff changeset
   124
	ASSERT(mp->initialized == B_TRUE);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   125
	ASSERT(mp->m_owner != (void *)-1UL);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   126
	ASSERT(mp->m_owner != curthread);
2856
6f4d5ee1906a 6463348 ZFS code could be more portable
nd150628
parents: 1635
diff changeset
   127
	VERIFY(mutex_lock(&mp->m_lock) == 0);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   128
	ASSERT(mp->m_owner == NULL);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   129
	mp->m_owner = curthread;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   130
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   131
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   132
int
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   133
mutex_tryenter(kmutex_t *mp)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   134
{
4831
41ec732c6d9f 6584470 zdb needs to initialize the bpl_lock mutex
gw25295
parents: 4543
diff changeset
   135
	ASSERT(mp->initialized == B_TRUE);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   136
	ASSERT(mp->m_owner != (void *)-1UL);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   137
	if (0 == mutex_trylock(&mp->m_lock)) {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   138
		ASSERT(mp->m_owner == NULL);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   139
		mp->m_owner = curthread;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   140
		return (1);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   141
	} else {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   142
		return (0);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   143
	}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   144
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   145
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   146
void
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   147
mutex_exit(kmutex_t *mp)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   148
{
4831
41ec732c6d9f 6584470 zdb needs to initialize the bpl_lock mutex
gw25295
parents: 4543
diff changeset
   149
	ASSERT(mp->initialized == B_TRUE);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   150
	ASSERT(mutex_owner(mp) == curthread);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   151
	mp->m_owner = NULL;
2856
6f4d5ee1906a 6463348 ZFS code could be more portable
nd150628
parents: 1635
diff changeset
   152
	VERIFY(mutex_unlock(&mp->m_lock) == 0);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   153
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   154
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   155
void *
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   156
mutex_owner(kmutex_t *mp)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   157
{
4831
41ec732c6d9f 6584470 zdb needs to initialize the bpl_lock mutex
gw25295
parents: 4543
diff changeset
   158
	ASSERT(mp->initialized == B_TRUE);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   159
	return (mp->m_owner);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   160
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   161
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   162
/*
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   163
 * =========================================================================
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   164
 * rwlocks
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   165
 * =========================================================================
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   166
 */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   167
/*ARGSUSED*/
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   168
void
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   169
rw_init(krwlock_t *rwlp, char *name, int type, void *arg)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   170
{
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   171
	rwlock_init(&rwlp->rw_lock, USYNC_THREAD, NULL);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   172
	rwlp->rw_owner = NULL;
4831
41ec732c6d9f 6584470 zdb needs to initialize the bpl_lock mutex
gw25295
parents: 4543
diff changeset
   173
	rwlp->initialized = B_TRUE;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   174
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   175
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   176
void
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   177
rw_destroy(krwlock_t *rwlp)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   178
{
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   179
	rwlock_destroy(&rwlp->rw_lock);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   180
	rwlp->rw_owner = (void *)-1UL;
4831
41ec732c6d9f 6584470 zdb needs to initialize the bpl_lock mutex
gw25295
parents: 4543
diff changeset
   181
	rwlp->initialized = B_FALSE;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   182
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   183
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   184
void
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   185
rw_enter(krwlock_t *rwlp, krw_t rw)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   186
{
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   187
	ASSERT(!RW_LOCK_HELD(rwlp));
4831
41ec732c6d9f 6584470 zdb needs to initialize the bpl_lock mutex
gw25295
parents: 4543
diff changeset
   188
	ASSERT(rwlp->initialized == B_TRUE);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   189
	ASSERT(rwlp->rw_owner != (void *)-1UL);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   190
	ASSERT(rwlp->rw_owner != curthread);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   191
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   192
	if (rw == RW_READER)
6689
47572a2f5e73 6610506 Eliminate or improve retry logic from callers of dmu_objset_open()
maybee
parents: 6492
diff changeset
   193
		VERIFY(rw_rdlock(&rwlp->rw_lock) == 0);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   194
	else
6689
47572a2f5e73 6610506 Eliminate or improve retry logic from callers of dmu_objset_open()
maybee
parents: 6492
diff changeset
   195
		VERIFY(rw_wrlock(&rwlp->rw_lock) == 0);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   196
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   197
	rwlp->rw_owner = curthread;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   198
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   199
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   200
void
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   201
rw_exit(krwlock_t *rwlp)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   202
{
4831
41ec732c6d9f 6584470 zdb needs to initialize the bpl_lock mutex
gw25295
parents: 4543
diff changeset
   203
	ASSERT(rwlp->initialized == B_TRUE);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   204
	ASSERT(rwlp->rw_owner != (void *)-1UL);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   205
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   206
	rwlp->rw_owner = NULL;
6689
47572a2f5e73 6610506 Eliminate or improve retry logic from callers of dmu_objset_open()
maybee
parents: 6492
diff changeset
   207
	VERIFY(rw_unlock(&rwlp->rw_lock) == 0);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   208
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   209
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   210
int
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   211
rw_tryenter(krwlock_t *rwlp, krw_t rw)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   212
{
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   213
	int rv;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   214
4831
41ec732c6d9f 6584470 zdb needs to initialize the bpl_lock mutex
gw25295
parents: 4543
diff changeset
   215
	ASSERT(rwlp->initialized == B_TRUE);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   216
	ASSERT(rwlp->rw_owner != (void *)-1UL);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   217
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   218
	if (rw == RW_READER)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   219
		rv = rw_tryrdlock(&rwlp->rw_lock);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   220
	else
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   221
		rv = rw_trywrlock(&rwlp->rw_lock);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   222
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   223
	if (rv == 0) {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   224
		rwlp->rw_owner = curthread;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   225
		return (1);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   226
	}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   227
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   228
	return (0);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   229
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   230
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   231
/*ARGSUSED*/
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   232
int
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   233
rw_tryupgrade(krwlock_t *rwlp)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   234
{
4831
41ec732c6d9f 6584470 zdb needs to initialize the bpl_lock mutex
gw25295
parents: 4543
diff changeset
   235
	ASSERT(rwlp->initialized == B_TRUE);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   236
	ASSERT(rwlp->rw_owner != (void *)-1UL);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   237
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   238
	return (0);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   239
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   240
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   241
/*
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   242
 * =========================================================================
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   243
 * condition variables
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   244
 * =========================================================================
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   245
 */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   246
/*ARGSUSED*/
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   247
void
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   248
cv_init(kcondvar_t *cv, char *name, int type, void *arg)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   249
{
2856
6f4d5ee1906a 6463348 ZFS code could be more portable
nd150628
parents: 1635
diff changeset
   250
	VERIFY(cond_init(cv, type, NULL) == 0);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   251
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   252
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   253
void
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   254
cv_destroy(kcondvar_t *cv)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   255
{
2856
6f4d5ee1906a 6463348 ZFS code could be more portable
nd150628
parents: 1635
diff changeset
   256
	VERIFY(cond_destroy(cv) == 0);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   257
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   258
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   259
void
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   260
cv_wait(kcondvar_t *cv, kmutex_t *mp)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   261
{
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   262
	ASSERT(mutex_owner(mp) == curthread);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   263
	mp->m_owner = NULL;
2856
6f4d5ee1906a 6463348 ZFS code could be more portable
nd150628
parents: 1635
diff changeset
   264
	int ret = cond_wait(cv, &mp->m_lock);
6f4d5ee1906a 6463348 ZFS code could be more portable
nd150628
parents: 1635
diff changeset
   265
	VERIFY(ret == 0 || ret == EINTR);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   266
	mp->m_owner = curthread;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   267
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   268
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   269
clock_t
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   270
cv_timedwait(kcondvar_t *cv, kmutex_t *mp, clock_t abstime)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   271
{
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   272
	int error;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   273
	timestruc_t ts;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   274
	clock_t delta;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   275
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   276
top:
11066
cebb50cbe4f9 PSARC/2009/396 Tickless Kernel Architecture / lbolt decoupling
Rafael Vanoni <rafael.vanoni@sun.com>
parents: 10858
diff changeset
   277
	delta = abstime - ddi_get_lbolt();
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   278
	if (delta <= 0)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   279
		return (-1);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   280
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   281
	ts.tv_sec = delta / hz;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   282
	ts.tv_nsec = (delta % hz) * (NANOSEC / hz);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   283
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   284
	ASSERT(mutex_owner(mp) == curthread);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   285
	mp->m_owner = NULL;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   286
	error = cond_reltimedwait(cv, &mp->m_lock, &ts);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   287
	mp->m_owner = curthread;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   288
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   289
	if (error == ETIME)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   290
		return (-1);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   291
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   292
	if (error == EINTR)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   293
		goto top;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   294
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   295
	ASSERT(error == 0);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   296
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   297
	return (1);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   298
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   299
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   300
void
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   301
cv_signal(kcondvar_t *cv)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   302
{
2856
6f4d5ee1906a 6463348 ZFS code could be more portable
nd150628
parents: 1635
diff changeset
   303
	VERIFY(cond_signal(cv) == 0);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   304
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   305
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   306
void
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   307
cv_broadcast(kcondvar_t *cv)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   308
{
2856
6f4d5ee1906a 6463348 ZFS code could be more portable
nd150628
parents: 1635
diff changeset
   309
	VERIFY(cond_broadcast(cv) == 0);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   310
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   311
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   312
/*
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   313
 * =========================================================================
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   314
 * vnode operations
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   315
 * =========================================================================
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   316
 */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   317
/*
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   318
 * Note: for the xxxat() versions of these functions, we assume that the
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   319
 * starting vp is always rootdir (which is true for spa_directory.c, the only
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   320
 * ZFS consumer of these interfaces).  We assert this is true, and then emulate
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   321
 * them by adding '/' in front of the path.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   322
 */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   323
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   324
/*ARGSUSED*/
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   325
int
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   326
vn_open(char *path, int x1, int flags, int mode, vnode_t **vpp, int x2, int x3)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   327
{
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   328
	int fd;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   329
	vnode_t *vp;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   330
	int old_umask;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   331
	char realpath[MAXPATHLEN];
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   332
	struct stat64 st;
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
	 * If we're accessing a real disk from userland, we need to use
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   336
	 * the character interface to avoid caching.  This is particularly
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   337
	 * important if we're trying to look at a real in-kernel storage
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   338
	 * pool from userland, e.g. via zdb, because otherwise we won't
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   339
	 * see the changes occurring under the segmap cache.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   340
	 * On the other hand, the stupid character device returns zero
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   341
	 * for its size.  So -- gag -- we open the block device to get
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   342
	 * its size, and remember it for subsequent VOP_GETATTR().
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   343
	 */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   344
	if (strncmp(path, "/dev/", 5) == 0) {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   345
		char *dsk;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   346
		fd = open64(path, O_RDONLY);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   347
		if (fd == -1)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   348
			return (errno);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   349
		if (fstat64(fd, &st) == -1) {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   350
			close(fd);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   351
			return (errno);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   352
		}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   353
		close(fd);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   354
		(void) sprintf(realpath, "%s", path);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   355
		dsk = strstr(path, "/dsk/");
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   356
		if (dsk != NULL)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   357
			(void) sprintf(realpath + (dsk - path) + 1, "r%s",
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   358
			    dsk + 1);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   359
	} else {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   360
		(void) sprintf(realpath, "%s", path);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   361
		if (!(flags & FCREAT) && stat64(realpath, &st) == -1)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   362
			return (errno);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   363
	}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   364
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   365
	if (flags & FCREAT)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   366
		old_umask = umask(0);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   367
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   368
	/*
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   369
	 * The construct 'flags - FREAD' conveniently maps combinations of
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   370
	 * FREAD and FWRITE to the corresponding O_RDONLY, O_WRONLY, and O_RDWR.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   371
	 */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   372
	fd = open64(realpath, flags - FREAD, mode);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   373
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   374
	if (flags & FCREAT)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   375
		(void) umask(old_umask);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   376
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   377
	if (fd == -1)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   378
		return (errno);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   379
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   380
	if (fstat64(fd, &st) == -1) {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   381
		close(fd);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   382
		return (errno);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   383
	}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   384
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   385
	(void) fcntl(fd, F_SETFD, FD_CLOEXEC);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   386
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   387
	*vpp = vp = umem_zalloc(sizeof (vnode_t), UMEM_NOFAIL);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   388
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   389
	vp->v_fd = fd;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   390
	vp->v_size = st.st_size;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   391
	vp->v_path = spa_strdup(path);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   392
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   393
	return (0);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   394
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   395
5331
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4831
diff changeset
   396
/*ARGSUSED*/
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   397
int
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   398
vn_openat(char *path, int x1, int flags, int mode, vnode_t **vpp, int x2,
5331
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4831
diff changeset
   399
    int x3, vnode_t *startvp, int fd)
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   400
{
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   401
	char *realpath = umem_alloc(strlen(path) + 2, UMEM_NOFAIL);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   402
	int ret;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   403
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   404
	ASSERT(startvp == rootdir);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   405
	(void) sprintf(realpath, "/%s", path);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   406
5331
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4831
diff changeset
   407
	/* fd ignored for now, need if want to simulate nbmand support */
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   408
	ret = vn_open(realpath, x1, flags, mode, vpp, x2, x3);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   409
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   410
	umem_free(realpath, strlen(path) + 2);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   411
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   412
	return (ret);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   413
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   414
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   415
/*ARGSUSED*/
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   416
int
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   417
vn_rdwr(int uio, vnode_t *vp, void *addr, ssize_t len, offset_t offset,
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   418
	int x1, int x2, rlim64_t x3, void *x4, ssize_t *residp)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   419
{
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   420
	ssize_t iolen, split;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   421
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   422
	if (uio == UIO_READ) {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   423
		iolen = pread64(vp->v_fd, addr, len, offset);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   424
	} else {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   425
		/*
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   426
		 * To simulate partial disk writes, we split writes into two
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   427
		 * system calls so that the process can be killed in between.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   428
		 */
13700
2889e2596bd6 2619 asynchronous destruction of ZFS file systems
Christopher Siden <chris.siden@delphix.com>
parents: 13682
diff changeset
   429
		int sectors = len >> SPA_MINBLOCKSHIFT;
2889e2596bd6 2619 asynchronous destruction of ZFS file systems
Christopher Siden <chris.siden@delphix.com>
parents: 13682
diff changeset
   430
		split = (sectors > 0 ? rand() % sectors : 0) <<
2889e2596bd6 2619 asynchronous destruction of ZFS file systems
Christopher Siden <chris.siden@delphix.com>
parents: 13682
diff changeset
   431
		    SPA_MINBLOCKSHIFT;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   432
		iolen = pwrite64(vp->v_fd, addr, split, offset);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   433
		iolen += pwrite64(vp->v_fd, (char *)addr + split,
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   434
		    len - split, offset + split);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   435
	}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   436
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   437
	if (iolen == -1)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   438
		return (errno);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   439
	if (residp)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   440
		*residp = len - iolen;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   441
	else if (iolen != len)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   442
		return (EIO);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   443
	return (0);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   444
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   445
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   446
void
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   447
vn_close(vnode_t *vp)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   448
{
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   449
	close(vp->v_fd);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   450
	spa_strfree(vp->v_path);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   451
	umem_free(vp, sizeof (vnode_t));
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   452
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   453
10850
bb29ac73664d 6840704 osol_0906 PV guests sometimes hang at login prompt
George Wilson <George.Wilson@Sun.COM>
parents: 10612
diff changeset
   454
/*
bb29ac73664d 6840704 osol_0906 PV guests sometimes hang at login prompt
George Wilson <George.Wilson@Sun.COM>
parents: 10612
diff changeset
   455
 * At a minimum we need to update the size since vdev_reopen()
bb29ac73664d 6840704 osol_0906 PV guests sometimes hang at login prompt
George Wilson <George.Wilson@Sun.COM>
parents: 10612
diff changeset
   456
 * will no longer call vn_openat().
bb29ac73664d 6840704 osol_0906 PV guests sometimes hang at login prompt
George Wilson <George.Wilson@Sun.COM>
parents: 10612
diff changeset
   457
 */
bb29ac73664d 6840704 osol_0906 PV guests sometimes hang at login prompt
George Wilson <George.Wilson@Sun.COM>
parents: 10612
diff changeset
   458
int
bb29ac73664d 6840704 osol_0906 PV guests sometimes hang at login prompt
George Wilson <George.Wilson@Sun.COM>
parents: 10612
diff changeset
   459
fop_getattr(vnode_t *vp, vattr_t *vap)
bb29ac73664d 6840704 osol_0906 PV guests sometimes hang at login prompt
George Wilson <George.Wilson@Sun.COM>
parents: 10612
diff changeset
   460
{
bb29ac73664d 6840704 osol_0906 PV guests sometimes hang at login prompt
George Wilson <George.Wilson@Sun.COM>
parents: 10612
diff changeset
   461
	struct stat64 st;
bb29ac73664d 6840704 osol_0906 PV guests sometimes hang at login prompt
George Wilson <George.Wilson@Sun.COM>
parents: 10612
diff changeset
   462
bb29ac73664d 6840704 osol_0906 PV guests sometimes hang at login prompt
George Wilson <George.Wilson@Sun.COM>
parents: 10612
diff changeset
   463
	if (fstat64(vp->v_fd, &st) == -1) {
bb29ac73664d 6840704 osol_0906 PV guests sometimes hang at login prompt
George Wilson <George.Wilson@Sun.COM>
parents: 10612
diff changeset
   464
		close(vp->v_fd);
bb29ac73664d 6840704 osol_0906 PV guests sometimes hang at login prompt
George Wilson <George.Wilson@Sun.COM>
parents: 10612
diff changeset
   465
		return (errno);
bb29ac73664d 6840704 osol_0906 PV guests sometimes hang at login prompt
George Wilson <George.Wilson@Sun.COM>
parents: 10612
diff changeset
   466
	}
bb29ac73664d 6840704 osol_0906 PV guests sometimes hang at login prompt
George Wilson <George.Wilson@Sun.COM>
parents: 10612
diff changeset
   467
bb29ac73664d 6840704 osol_0906 PV guests sometimes hang at login prompt
George Wilson <George.Wilson@Sun.COM>
parents: 10612
diff changeset
   468
	vap->va_size = st.st_size;
bb29ac73664d 6840704 osol_0906 PV guests sometimes hang at login prompt
George Wilson <George.Wilson@Sun.COM>
parents: 10612
diff changeset
   469
	return (0);
bb29ac73664d 6840704 osol_0906 PV guests sometimes hang at login prompt
George Wilson <George.Wilson@Sun.COM>
parents: 10612
diff changeset
   470
}
bb29ac73664d 6840704 osol_0906 PV guests sometimes hang at login prompt
George Wilson <George.Wilson@Sun.COM>
parents: 10612
diff changeset
   471
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   472
#ifdef ZFS_DEBUG
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   473
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   474
/*
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   475
 * =========================================================================
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   476
 * Figure out which debugging statements to print
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   477
 * =========================================================================
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   478
 */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   479
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   480
static char *dprintf_string;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   481
static int dprintf_print_all;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   482
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   483
int
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   484
dprintf_find_string(const char *string)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   485
{
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   486
	char *tmp_str = dprintf_string;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   487
	int len = strlen(string);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   488
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   489
	/*
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   490
	 * Find out if this is a string we want to print.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   491
	 * String format: file1.c,function_name1,file2.c,file3.c
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   492
	 */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   493
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   494
	while (tmp_str != NULL) {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   495
		if (strncmp(tmp_str, string, len) == 0 &&
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   496
		    (tmp_str[len] == ',' || tmp_str[len] == '\0'))
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   497
			return (1);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   498
		tmp_str = strchr(tmp_str, ',');
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   499
		if (tmp_str != NULL)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   500
			tmp_str++; /* Get rid of , */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   501
	}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   502
	return (0);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   503
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   504
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   505
void
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   506
dprintf_setup(int *argc, char **argv)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   507
{
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   508
	int i, j;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   509
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   510
	/*
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   511
	 * Debugging can be specified two ways: by setting the
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   512
	 * environment variable ZFS_DEBUG, or by including a
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   513
	 * "debug=..."  argument on the command line.  The command
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   514
	 * line setting overrides the environment variable.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   515
	 */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   516
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   517
	for (i = 1; i < *argc; i++) {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   518
		int len = strlen("debug=");
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   519
		/* First look for a command line argument */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   520
		if (strncmp("debug=", argv[i], len) == 0) {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   521
			dprintf_string = argv[i] + len;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   522
			/* Remove from args */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   523
			for (j = i; j < *argc; j++)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   524
				argv[j] = argv[j+1];
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   525
			argv[j] = NULL;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   526
			(*argc)--;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   527
		}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   528
	}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   529
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   530
	if (dprintf_string == NULL) {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   531
		/* Look for ZFS_DEBUG environment variable */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   532
		dprintf_string = getenv("ZFS_DEBUG");
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   533
	}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   534
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   535
	/*
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   536
	 * Are we just turning on all debugging?
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   537
	 */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   538
	if (dprintf_find_string("on"))
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   539
		dprintf_print_all = 1;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   540
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   541
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   542
/*
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   543
 * =========================================================================
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   544
 * debug printfs
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   545
 * =========================================================================
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   546
 */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   547
void
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   548
__dprintf(const char *file, const char *func, int line, const char *fmt, ...)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   549
{
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   550
	const char *newfile;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   551
	va_list adx;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   552
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   553
	/*
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   554
	 * Get rid of annoying "../common/" prefix to filename.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   555
	 */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   556
	newfile = strrchr(file, '/');
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   557
	if (newfile != NULL) {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   558
		newfile = newfile + 1; /* Get rid of leading / */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   559
	} else {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   560
		newfile = file;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   561
	}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   562
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   563
	if (dprintf_print_all ||
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   564
	    dprintf_find_string(newfile) ||
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   565
	    dprintf_find_string(func)) {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   566
		/* Print out just the function name if requested */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   567
		flockfile(stdout);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   568
		if (dprintf_find_string("pid"))
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   569
			(void) printf("%d ", getpid());
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   570
		if (dprintf_find_string("tid"))
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   571
			(void) printf("%u ", thr_self());
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   572
		if (dprintf_find_string("cpu"))
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   573
			(void) printf("%u ", getcpuid());
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   574
		if (dprintf_find_string("time"))
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   575
			(void) printf("%llu ", gethrtime());
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   576
		if (dprintf_find_string("long"))
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   577
			(void) printf("%s, line %d: ", newfile, line);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   578
		(void) printf("%s: ", func);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   579
		va_start(adx, fmt);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   580
		(void) vprintf(fmt, adx);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   581
		va_end(adx);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   582
		funlockfile(stdout);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   583
	}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   584
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   585
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   586
#endif /* ZFS_DEBUG */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   587
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   588
/*
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   589
 * =========================================================================
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   590
 * cmn_err() and panic()
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   591
 * =========================================================================
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   592
 */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   593
static char ce_prefix[CE_IGNORE][10] = { "", "NOTICE: ", "WARNING: ", "" };
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   594
static char ce_suffix[CE_IGNORE][2] = { "", "\n", "\n", "" };
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   595
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   596
void
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   597
vpanic(const char *fmt, va_list adx)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   598
{
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   599
	(void) fprintf(stderr, "error: ");
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   600
	(void) vfprintf(stderr, fmt, adx);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   601
	(void) fprintf(stderr, "\n");
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   602
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   603
	abort();	/* think of it as a "user-level crash dump" */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   604
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   605
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   606
void
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   607
panic(const char *fmt, ...)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   608
{
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   609
	va_list adx;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   610
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   611
	va_start(adx, fmt);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   612
	vpanic(fmt, adx);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   613
	va_end(adx);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   614
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   615
3713
00e75dc8b749 6527325 want more assertions in space map code
ahrens
parents: 3403
diff changeset
   616
void
00e75dc8b749 6527325 want more assertions in space map code
ahrens
parents: 3403
diff changeset
   617
vcmn_err(int ce, const char *fmt, va_list adx)
00e75dc8b749 6527325 want more assertions in space map code
ahrens
parents: 3403
diff changeset
   618
{
00e75dc8b749 6527325 want more assertions in space map code
ahrens
parents: 3403
diff changeset
   619
	if (ce == CE_PANIC)
00e75dc8b749 6527325 want more assertions in space map code
ahrens
parents: 3403
diff changeset
   620
		vpanic(fmt, adx);
00e75dc8b749 6527325 want more assertions in space map code
ahrens
parents: 3403
diff changeset
   621
	if (ce != CE_NOTE) {	/* suppress noise in userland stress testing */
00e75dc8b749 6527325 want more assertions in space map code
ahrens
parents: 3403
diff changeset
   622
		(void) fprintf(stderr, "%s", ce_prefix[ce]);
00e75dc8b749 6527325 want more assertions in space map code
ahrens
parents: 3403
diff changeset
   623
		(void) vfprintf(stderr, fmt, adx);
00e75dc8b749 6527325 want more assertions in space map code
ahrens
parents: 3403
diff changeset
   624
		(void) fprintf(stderr, "%s", ce_suffix[ce]);
00e75dc8b749 6527325 want more assertions in space map code
ahrens
parents: 3403
diff changeset
   625
	}
00e75dc8b749 6527325 want more assertions in space map code
ahrens
parents: 3403
diff changeset
   626
}
00e75dc8b749 6527325 want more assertions in space map code
ahrens
parents: 3403
diff changeset
   627
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   628
/*PRINTFLIKE2*/
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   629
void
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   630
cmn_err(int ce, const char *fmt, ...)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   631
{
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   632
	va_list adx;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   633
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   634
	va_start(adx, fmt);
3713
00e75dc8b749 6527325 want more assertions in space map code
ahrens
parents: 3403
diff changeset
   635
	vcmn_err(ce, fmt, adx);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   636
	va_end(adx);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   637
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   638
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   639
/*
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   640
 * =========================================================================
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 789
diff changeset
   641
 * kobj interfaces
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 789
diff changeset
   642
 * =========================================================================
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 789
diff changeset
   643
 */
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 789
diff changeset
   644
struct _buf *
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 789
diff changeset
   645
kobj_open_file(char *name)
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 789
diff changeset
   646
{
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 789
diff changeset
   647
	struct _buf *file;
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 789
diff changeset
   648
	vnode_t *vp;
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 789
diff changeset
   649
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 789
diff changeset
   650
	/* set vp as the _fd field of the file */
5331
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4831
diff changeset
   651
	if (vn_openat(name, UIO_SYSSPACE, FREAD, 0, &vp, 0, 0, rootdir,
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 4831
diff changeset
   652
	    -1) != 0)
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 789
diff changeset
   653
		return ((void *)-1UL);
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 789
diff changeset
   654
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 789
diff changeset
   655
	file = umem_zalloc(sizeof (struct _buf), UMEM_NOFAIL);
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 789
diff changeset
   656
	file->_fd = (intptr_t)vp;
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 789
diff changeset
   657
	return (file);
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 789
diff changeset
   658
}
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 789
diff changeset
   659
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 789
diff changeset
   660
int
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 789
diff changeset
   661
kobj_read_file(struct _buf *file, char *buf, unsigned size, unsigned off)
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 789
diff changeset
   662
{
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 789
diff changeset
   663
	ssize_t resid;
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 789
diff changeset
   664
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 789
diff changeset
   665
	vn_rdwr(UIO_READ, (vnode_t *)file->_fd, buf, size, (offset_t)off,
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 789
diff changeset
   666
	    UIO_SYSSPACE, 0, 0, 0, &resid);
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 789
diff changeset
   667
3912
f6891a60bd72 PSARC 2007/083 ZFS bootable datasets
lling
parents: 3886
diff changeset
   668
	return (size - resid);
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 789
diff changeset
   669
}
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 789
diff changeset
   670
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 789
diff changeset
   671
void
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 789
diff changeset
   672
kobj_close_file(struct _buf *file)
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 789
diff changeset
   673
{
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 789
diff changeset
   674
	vn_close((vnode_t *)file->_fd);
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 789
diff changeset
   675
	umem_free(file, sizeof (struct _buf));
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 789
diff changeset
   676
}
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 789
diff changeset
   677
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 789
diff changeset
   678
int
3912
f6891a60bd72 PSARC 2007/083 ZFS bootable datasets
lling
parents: 3886
diff changeset
   679
kobj_get_filesize(struct _buf *file, uint64_t *size)
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 789
diff changeset
   680
{
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 789
diff changeset
   681
	struct stat64 st;
3912
f6891a60bd72 PSARC 2007/083 ZFS bootable datasets
lling
parents: 3886
diff changeset
   682
	vnode_t *vp = (vnode_t *)file->_fd;
f6891a60bd72 PSARC 2007/083 ZFS bootable datasets
lling
parents: 3886
diff changeset
   683
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 789
diff changeset
   684
	if (fstat64(vp->v_fd, &st) == -1) {
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 789
diff changeset
   685
		vn_close(vp);
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 789
diff changeset
   686
		return (errno);
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 789
diff changeset
   687
	}
3912
f6891a60bd72 PSARC 2007/083 ZFS bootable datasets
lling
parents: 3886
diff changeset
   688
	*size = st.st_size;
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 789
diff changeset
   689
	return (0);
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 789
diff changeset
   690
}
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 789
diff changeset
   691
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 789
diff changeset
   692
/*
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 789
diff changeset
   693
 * =========================================================================
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   694
 * misc routines
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
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   698
void
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   699
delay(clock_t ticks)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   700
{
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   701
	poll(0, 0, ticks * (1000 / hz));
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   702
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   703
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   704
/*
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   705
 * Find highest one bit set.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   706
 *	Returns bit number + 1 of highest bit that is set, otherwise returns 0.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   707
 * High order bit is 31 (or 63 in _LP64 kernel).
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   708
 */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   709
int
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   710
highbit(ulong_t i)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   711
{
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   712
	register int h = 1;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   713
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   714
	if (i == 0)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   715
		return (0);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   716
#ifdef _LP64
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   717
	if (i & 0xffffffff00000000ul) {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   718
		h += 32; i >>= 32;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   719
	}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   720
#endif
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   721
	if (i & 0xffff0000) {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   722
		h += 16; i >>= 16;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   723
	}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   724
	if (i & 0xff00) {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   725
		h += 8; i >>= 8;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   726
	}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   727
	if (i & 0xf0) {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   728
		h += 4; i >>= 4;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   729
	}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   730
	if (i & 0xc) {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   731
		h += 2; i >>= 2;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   732
	}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   733
	if (i & 0x2) {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   734
		h += 1;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   735
	}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   736
	return (h);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   737
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   738
5688
c0b02c8fd2c0 6640580 spa_get_random() is insanely slow in userland
bonwick
parents: 5331
diff changeset
   739
static int random_fd = -1, urandom_fd = -1;
c0b02c8fd2c0 6640580 spa_get_random() is insanely slow in userland
bonwick
parents: 5331
diff changeset
   740
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   741
static int
5688
c0b02c8fd2c0 6640580 spa_get_random() is insanely slow in userland
bonwick
parents: 5331
diff changeset
   742
random_get_bytes_common(uint8_t *ptr, size_t len, int fd)
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   743
{
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   744
	size_t resid = len;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   745
	ssize_t bytes;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   746
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   747
	ASSERT(fd != -1);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   748
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   749
	while (resid != 0) {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   750
		bytes = read(fd, ptr, resid);
5688
c0b02c8fd2c0 6640580 spa_get_random() is insanely slow in userland
bonwick
parents: 5331
diff changeset
   751
		ASSERT3S(bytes, >=, 0);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   752
		ptr += bytes;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   753
		resid -= bytes;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   754
	}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   755
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   756
	return (0);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   757
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   758
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   759
int
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   760
random_get_bytes(uint8_t *ptr, size_t len)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   761
{
5688
c0b02c8fd2c0 6640580 spa_get_random() is insanely slow in userland
bonwick
parents: 5331
diff changeset
   762
	return (random_get_bytes_common(ptr, len, random_fd));
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   763
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   764
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   765
int
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   766
random_get_pseudo_bytes(uint8_t *ptr, size_t len)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   767
{
5688
c0b02c8fd2c0 6640580 spa_get_random() is insanely slow in userland
bonwick
parents: 5331
diff changeset
   768
	return (random_get_bytes_common(ptr, len, urandom_fd));
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   769
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   770
3975
6674f5d79069 6282725 hostname/hostid should be stored in the label
ek110237
parents: 3912
diff changeset
   771
int
6674f5d79069 6282725 hostname/hostid should be stored in the label
ek110237
parents: 3912
diff changeset
   772
ddi_strtoul(const char *hw_serial, char **nptr, int base, unsigned long *result)
6674f5d79069 6282725 hostname/hostid should be stored in the label
ek110237
parents: 3912
diff changeset
   773
{
6674f5d79069 6282725 hostname/hostid should be stored in the label
ek110237
parents: 3912
diff changeset
   774
	char *end;
6674f5d79069 6282725 hostname/hostid should be stored in the label
ek110237
parents: 3912
diff changeset
   775
6674f5d79069 6282725 hostname/hostid should be stored in the label
ek110237
parents: 3912
diff changeset
   776
	*result = strtoul(hw_serial, &end, base);
6674f5d79069 6282725 hostname/hostid should be stored in the label
ek110237
parents: 3912
diff changeset
   777
	if (*result == 0)
6674f5d79069 6282725 hostname/hostid should be stored in the label
ek110237
parents: 3912
diff changeset
   778
		return (errno);
6674f5d79069 6282725 hostname/hostid should be stored in the label
ek110237
parents: 3912
diff changeset
   779
	return (0);
6674f5d79069 6282725 hostname/hostid should be stored in the label
ek110237
parents: 3912
diff changeset
   780
}
6674f5d79069 6282725 hostname/hostid should be stored in the label
ek110237
parents: 3912
diff changeset
   781
11935
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11726
diff changeset
   782
int
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11726
diff changeset
   783
ddi_strtoull(const char *str, char **nptr, int base, u_longlong_t *result)
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11726
diff changeset
   784
{
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11726
diff changeset
   785
	char *end;
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11726
diff changeset
   786
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11726
diff changeset
   787
	*result = strtoull(str, &end, base);
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11726
diff changeset
   788
	if (*result == 0)
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11726
diff changeset
   789
		return (errno);
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11726
diff changeset
   790
	return (0);
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11726
diff changeset
   791
}
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11726
diff changeset
   792
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   793
/*
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   794
 * =========================================================================
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   795
 * kernel emulation setup & teardown
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   796
 * =========================================================================
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   797
 */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   798
static int
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   799
umem_out_of_memory(void)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   800
{
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   801
	char errmsg[] = "out of memory -- generating core dump\n";
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   802
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   803
	write(fileno(stderr), errmsg, sizeof (errmsg));
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   804
	abort();
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   805
	return (0);
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
void
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   809
kernel_init(int mode)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   810
{
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   811
	umem_nofail_callback(umem_out_of_memory);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   812
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   813
	physmem = sysconf(_SC_PHYS_PAGES);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   814
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   815
	dprintf("physmem = %llu pages (%.2f GB)\n", physmem,
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   816
	    (double)physmem * sysconf(_SC_PAGE_SIZE) / (1ULL << 30));
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   817
10858
9efff268b959 6709782 issues using zdb with -e option
Victor Latushkin <Victor.Latushkin@Sun.COM>
parents: 10850
diff changeset
   818
	(void) snprintf(hw_serial, sizeof (hw_serial), "%ld",
9efff268b959 6709782 issues using zdb with -e option
Victor Latushkin <Victor.Latushkin@Sun.COM>
parents: 10850
diff changeset
   819
	    (mode & FWRITE) ? gethostid() : 0);
3975
6674f5d79069 6282725 hostname/hostid should be stored in the label
ek110237
parents: 3912
diff changeset
   820
5688
c0b02c8fd2c0 6640580 spa_get_random() is insanely slow in userland
bonwick
parents: 5331
diff changeset
   821
	VERIFY((random_fd = open("/dev/random", O_RDONLY)) != -1);
c0b02c8fd2c0 6640580 spa_get_random() is insanely slow in userland
bonwick
parents: 5331
diff changeset
   822
	VERIFY((urandom_fd = open("/dev/urandom", O_RDONLY)) != -1);
c0b02c8fd2c0 6640580 spa_get_random() is insanely slow in userland
bonwick
parents: 5331
diff changeset
   823
7837
001de5627df3 6333409 traversal code should be able to issue multiple reads in parallel
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 6689
diff changeset
   824
	system_taskq_init();
001de5627df3 6333409 traversal code should be able to issue multiple reads in parallel
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 6689
diff changeset
   825
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   826
	spa_init(mode);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   827
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   828
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   829
void
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   830
kernel_fini(void)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   831
{
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   832
	spa_fini();
5688
c0b02c8fd2c0 6640580 spa_get_random() is insanely slow in userland
bonwick
parents: 5331
diff changeset
   833
10612
89423355fa6f 6650218 Commit callbacks API for the DMU
Ricardo M. Correia <Ricardo.M.Correia@Sun.COM>
parents: 10272
diff changeset
   834
	system_taskq_fini();
89423355fa6f 6650218 Commit callbacks API for the DMU
Ricardo M. Correia <Ricardo.M.Correia@Sun.COM>
parents: 10272
diff changeset
   835
5688
c0b02c8fd2c0 6640580 spa_get_random() is insanely slow in userland
bonwick
parents: 5331
diff changeset
   836
	close(random_fd);
c0b02c8fd2c0 6640580 spa_get_random() is insanely slow in userland
bonwick
parents: 5331
diff changeset
   837
	close(urandom_fd);
c0b02c8fd2c0 6640580 spa_get_random() is insanely slow in userland
bonwick
parents: 5331
diff changeset
   838
c0b02c8fd2c0 6640580 spa_get_random() is insanely slow in userland
bonwick
parents: 5331
diff changeset
   839
	random_fd = -1;
c0b02c8fd2c0 6640580 spa_get_random() is insanely slow in userland
bonwick
parents: 5331
diff changeset
   840
	urandom_fd = -1;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   841
}
3886
3291401d66a6 6536602 add zlib compression support and upgrade to version 1.2.3
ahl
parents: 3713
diff changeset
   842
3291401d66a6 6536602 add zlib compression support and upgrade to version 1.2.3
ahl
parents: 3713
diff changeset
   843
int
3291401d66a6 6536602 add zlib compression support and upgrade to version 1.2.3
ahl
parents: 3713
diff changeset
   844
z_uncompress(void *dst, size_t *dstlen, const void *src, size_t srclen)
3291401d66a6 6536602 add zlib compression support and upgrade to version 1.2.3
ahl
parents: 3713
diff changeset
   845
{
3291401d66a6 6536602 add zlib compression support and upgrade to version 1.2.3
ahl
parents: 3713
diff changeset
   846
	int ret;
3291401d66a6 6536602 add zlib compression support and upgrade to version 1.2.3
ahl
parents: 3713
diff changeset
   847
	uLongf len = *dstlen;
3291401d66a6 6536602 add zlib compression support and upgrade to version 1.2.3
ahl
parents: 3713
diff changeset
   848
3291401d66a6 6536602 add zlib compression support and upgrade to version 1.2.3
ahl
parents: 3713
diff changeset
   849
	if ((ret = uncompress(dst, &len, src, srclen)) == Z_OK)
3291401d66a6 6536602 add zlib compression support and upgrade to version 1.2.3
ahl
parents: 3713
diff changeset
   850
		*dstlen = (size_t)len;
3291401d66a6 6536602 add zlib compression support and upgrade to version 1.2.3
ahl
parents: 3713
diff changeset
   851
3291401d66a6 6536602 add zlib compression support and upgrade to version 1.2.3
ahl
parents: 3713
diff changeset
   852
	return (ret);
3291401d66a6 6536602 add zlib compression support and upgrade to version 1.2.3
ahl
parents: 3713
diff changeset
   853
}
3291401d66a6 6536602 add zlib compression support and upgrade to version 1.2.3
ahl
parents: 3713
diff changeset
   854
3291401d66a6 6536602 add zlib compression support and upgrade to version 1.2.3
ahl
parents: 3713
diff changeset
   855
int
3291401d66a6 6536602 add zlib compression support and upgrade to version 1.2.3
ahl
parents: 3713
diff changeset
   856
z_compress_level(void *dst, size_t *dstlen, const void *src, size_t srclen,
3291401d66a6 6536602 add zlib compression support and upgrade to version 1.2.3
ahl
parents: 3713
diff changeset
   857
    int level)
3291401d66a6 6536602 add zlib compression support and upgrade to version 1.2.3
ahl
parents: 3713
diff changeset
   858
{
3291401d66a6 6536602 add zlib compression support and upgrade to version 1.2.3
ahl
parents: 3713
diff changeset
   859
	int ret;
3291401d66a6 6536602 add zlib compression support and upgrade to version 1.2.3
ahl
parents: 3713
diff changeset
   860
	uLongf len = *dstlen;
3291401d66a6 6536602 add zlib compression support and upgrade to version 1.2.3
ahl
parents: 3713
diff changeset
   861
3291401d66a6 6536602 add zlib compression support and upgrade to version 1.2.3
ahl
parents: 3713
diff changeset
   862
	if ((ret = compress2(dst, &len, src, srclen, level)) == Z_OK)
3291401d66a6 6536602 add zlib compression support and upgrade to version 1.2.3
ahl
parents: 3713
diff changeset
   863
		*dstlen = (size_t)len;
3291401d66a6 6536602 add zlib compression support and upgrade to version 1.2.3
ahl
parents: 3713
diff changeset
   864
3291401d66a6 6536602 add zlib compression support and upgrade to version 1.2.3
ahl
parents: 3713
diff changeset
   865
	return (ret);
3291401d66a6 6536602 add zlib compression support and upgrade to version 1.2.3
ahl
parents: 3713
diff changeset
   866
}
4543
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 3975
diff changeset
   867
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 3975
diff changeset
   868
uid_t
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 3975
diff changeset
   869
crgetuid(cred_t *cr)
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 3975
diff changeset
   870
{
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 3975
diff changeset
   871
	return (0);
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 3975
diff changeset
   872
}
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 3975
diff changeset
   873
13743
95aba6e49b9f 2882 implement libzfs_core
Matthew Ahrens <mahrens@delphix.com>
parents: 13700
diff changeset
   874
uid_t
95aba6e49b9f 2882 implement libzfs_core
Matthew Ahrens <mahrens@delphix.com>
parents: 13700
diff changeset
   875
crgetruid(cred_t *cr)
95aba6e49b9f 2882 implement libzfs_core
Matthew Ahrens <mahrens@delphix.com>
parents: 13700
diff changeset
   876
{
95aba6e49b9f 2882 implement libzfs_core
Matthew Ahrens <mahrens@delphix.com>
parents: 13700
diff changeset
   877
	return (0);
95aba6e49b9f 2882 implement libzfs_core
Matthew Ahrens <mahrens@delphix.com>
parents: 13700
diff changeset
   878
}
95aba6e49b9f 2882 implement libzfs_core
Matthew Ahrens <mahrens@delphix.com>
parents: 13700
diff changeset
   879
4543
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 3975
diff changeset
   880
gid_t
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 3975
diff changeset
   881
crgetgid(cred_t *cr)
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 3975
diff changeset
   882
{
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 3975
diff changeset
   883
	return (0);
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 3975
diff changeset
   884
}
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 3975
diff changeset
   885
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 3975
diff changeset
   886
int
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 3975
diff changeset
   887
crgetngroups(cred_t *cr)
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 3975
diff changeset
   888
{
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 3975
diff changeset
   889
	return (0);
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 3975
diff changeset
   890
}
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 3975
diff changeset
   891
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 3975
diff changeset
   892
gid_t *
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 3975
diff changeset
   893
crgetgroups(cred_t *cr)
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 3975
diff changeset
   894
{
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 3975
diff changeset
   895
	return (NULL);
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 3975
diff changeset
   896
}
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 3975
diff changeset
   897
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 3975
diff changeset
   898
int
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 3975
diff changeset
   899
zfs_secpolicy_snapshot_perms(const char *name, cred_t *cr)
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 3975
diff changeset
   900
{
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 3975
diff changeset
   901
	return (0);
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 3975
diff changeset
   902
}
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 3975
diff changeset
   903
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 3975
diff changeset
   904
int
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 3975
diff changeset
   905
zfs_secpolicy_rename_perms(const char *from, const char *to, cred_t *cr)
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 3975
diff changeset
   906
{
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 3975
diff changeset
   907
	return (0);
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 3975
diff changeset
   908
}
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 3975
diff changeset
   909
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 3975
diff changeset
   910
int
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 3975
diff changeset
   911
zfs_secpolicy_destroy_perms(const char *name, cred_t *cr)
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 3975
diff changeset
   912
{
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 3975
diff changeset
   913
	return (0);
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 3975
diff changeset
   914
}
5959
1e1904b8526d 6650192 zfs ACL/fuid code could use some minor cleanup
marks
parents: 5688
diff changeset
   915
1e1904b8526d 6650192 zfs ACL/fuid code could use some minor cleanup
marks
parents: 5688
diff changeset
   916
ksiddomain_t *
1e1904b8526d 6650192 zfs ACL/fuid code could use some minor cleanup
marks
parents: 5688
diff changeset
   917
ksid_lookupdomain(const char *dom)
1e1904b8526d 6650192 zfs ACL/fuid code could use some minor cleanup
marks
parents: 5688
diff changeset
   918
{
1e1904b8526d 6650192 zfs ACL/fuid code could use some minor cleanup
marks
parents: 5688
diff changeset
   919
	ksiddomain_t *kd;
1e1904b8526d 6650192 zfs ACL/fuid code could use some minor cleanup
marks
parents: 5688
diff changeset
   920
1e1904b8526d 6650192 zfs ACL/fuid code could use some minor cleanup
marks
parents: 5688
diff changeset
   921
	kd = umem_zalloc(sizeof (ksiddomain_t), UMEM_NOFAIL);
1e1904b8526d 6650192 zfs ACL/fuid code could use some minor cleanup
marks
parents: 5688
diff changeset
   922
	kd->kd_name = spa_strdup(dom);
1e1904b8526d 6650192 zfs ACL/fuid code could use some minor cleanup
marks
parents: 5688
diff changeset
   923
	return (kd);
1e1904b8526d 6650192 zfs ACL/fuid code could use some minor cleanup
marks
parents: 5688
diff changeset
   924
}
1e1904b8526d 6650192 zfs ACL/fuid code could use some minor cleanup
marks
parents: 5688
diff changeset
   925
1e1904b8526d 6650192 zfs ACL/fuid code could use some minor cleanup
marks
parents: 5688
diff changeset
   926
void
1e1904b8526d 6650192 zfs ACL/fuid code could use some minor cleanup
marks
parents: 5688
diff changeset
   927
ksiddomain_rele(ksiddomain_t *ksid)
1e1904b8526d 6650192 zfs ACL/fuid code could use some minor cleanup
marks
parents: 5688
diff changeset
   928
{
1e1904b8526d 6650192 zfs ACL/fuid code could use some minor cleanup
marks
parents: 5688
diff changeset
   929
	spa_strfree(ksid->kd_name);
1e1904b8526d 6650192 zfs ACL/fuid code could use some minor cleanup
marks
parents: 5688
diff changeset
   930
	umem_free(ksid, sizeof (ksiddomain_t));
1e1904b8526d 6650192 zfs ACL/fuid code could use some minor cleanup
marks
parents: 5688
diff changeset
   931
}
10272
a0669934e974 6861581 ZFS frees in synching context during rollback
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 8662
diff changeset
   932
a0669934e974 6861581 ZFS frees in synching context during rollback
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 8662
diff changeset
   933
/*
a0669934e974 6861581 ZFS frees in synching context during rollback
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 8662
diff changeset
   934
 * Do not change the length of the returned string; it must be freed
a0669934e974 6861581 ZFS frees in synching context during rollback
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 8662
diff changeset
   935
 * with strfree().
a0669934e974 6861581 ZFS frees in synching context during rollback
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 8662
diff changeset
   936
 */
a0669934e974 6861581 ZFS frees in synching context during rollback
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 8662
diff changeset
   937
char *
a0669934e974 6861581 ZFS frees in synching context during rollback
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 8662
diff changeset
   938
kmem_asprintf(const char *fmt, ...)
a0669934e974 6861581 ZFS frees in synching context during rollback
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 8662
diff changeset
   939
{
a0669934e974 6861581 ZFS frees in synching context during rollback
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 8662
diff changeset
   940
	int size;
a0669934e974 6861581 ZFS frees in synching context during rollback
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 8662
diff changeset
   941
	va_list adx;
a0669934e974 6861581 ZFS frees in synching context during rollback
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 8662
diff changeset
   942
	char *buf;
a0669934e974 6861581 ZFS frees in synching context during rollback
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 8662
diff changeset
   943
a0669934e974 6861581 ZFS frees in synching context during rollback
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 8662
diff changeset
   944
	va_start(adx, fmt);
a0669934e974 6861581 ZFS frees in synching context during rollback
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 8662
diff changeset
   945
	size = vsnprintf(NULL, 0, fmt, adx) + 1;
a0669934e974 6861581 ZFS frees in synching context during rollback
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 8662
diff changeset
   946
	va_end(adx);
a0669934e974 6861581 ZFS frees in synching context during rollback
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 8662
diff changeset
   947
a0669934e974 6861581 ZFS frees in synching context during rollback
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 8662
diff changeset
   948
	buf = kmem_alloc(size, KM_SLEEP);
a0669934e974 6861581 ZFS frees in synching context during rollback
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 8662
diff changeset
   949
a0669934e974 6861581 ZFS frees in synching context during rollback
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 8662
diff changeset
   950
	va_start(adx, fmt);
a0669934e974 6861581 ZFS frees in synching context during rollback
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 8662
diff changeset
   951
	size = vsnprintf(buf, size, fmt, adx);
a0669934e974 6861581 ZFS frees in synching context during rollback
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 8662
diff changeset
   952
	va_end(adx);
a0669934e974 6861581 ZFS frees in synching context during rollback
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 8662
diff changeset
   953
a0669934e974 6861581 ZFS frees in synching context during rollback
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 8662
diff changeset
   954
	return (buf);
a0669934e974 6861581 ZFS frees in synching context during rollback
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 8662
diff changeset
   955
}
12527
693dd2cad55f 6884007 zfs_send() can leave temporary holds around
Chris Kirby <Chris.Kirby@oracle.com>
parents: 11935
diff changeset
   956
693dd2cad55f 6884007 zfs_send() can leave temporary holds around
Chris Kirby <Chris.Kirby@oracle.com>
parents: 11935
diff changeset
   957
/* ARGSUSED */
693dd2cad55f 6884007 zfs_send() can leave temporary holds around
Chris Kirby <Chris.Kirby@oracle.com>
parents: 11935
diff changeset
   958
int
12798
f6c8601080b4 6938335 zfs send -R can still miss renamed snapshots
Chris Kirby <Chris.Kirby@oracle.com>
parents: 12527
diff changeset
   959
zfs_onexit_fd_hold(int fd, minor_t *minorp)
f6c8601080b4 6938335 zfs send -R can still miss renamed snapshots
Chris Kirby <Chris.Kirby@oracle.com>
parents: 12527
diff changeset
   960
{
f6c8601080b4 6938335 zfs send -R can still miss renamed snapshots
Chris Kirby <Chris.Kirby@oracle.com>
parents: 12527
diff changeset
   961
	*minorp = 0;
f6c8601080b4 6938335 zfs send -R can still miss renamed snapshots
Chris Kirby <Chris.Kirby@oracle.com>
parents: 12527
diff changeset
   962
	return (0);
f6c8601080b4 6938335 zfs send -R can still miss renamed snapshots
Chris Kirby <Chris.Kirby@oracle.com>
parents: 12527
diff changeset
   963
}
f6c8601080b4 6938335 zfs send -R can still miss renamed snapshots
Chris Kirby <Chris.Kirby@oracle.com>
parents: 12527
diff changeset
   964
f6c8601080b4 6938335 zfs send -R can still miss renamed snapshots
Chris Kirby <Chris.Kirby@oracle.com>
parents: 12527
diff changeset
   965
/* ARGSUSED */
f6c8601080b4 6938335 zfs send -R can still miss renamed snapshots
Chris Kirby <Chris.Kirby@oracle.com>
parents: 12527
diff changeset
   966
void
f6c8601080b4 6938335 zfs send -R can still miss renamed snapshots
Chris Kirby <Chris.Kirby@oracle.com>
parents: 12527
diff changeset
   967
zfs_onexit_fd_rele(int fd)
f6c8601080b4 6938335 zfs send -R can still miss renamed snapshots
Chris Kirby <Chris.Kirby@oracle.com>
parents: 12527
diff changeset
   968
{
f6c8601080b4 6938335 zfs send -R can still miss renamed snapshots
Chris Kirby <Chris.Kirby@oracle.com>
parents: 12527
diff changeset
   969
}
f6c8601080b4 6938335 zfs send -R can still miss renamed snapshots
Chris Kirby <Chris.Kirby@oracle.com>
parents: 12527
diff changeset
   970
f6c8601080b4 6938335 zfs send -R can still miss renamed snapshots
Chris Kirby <Chris.Kirby@oracle.com>
parents: 12527
diff changeset
   971
/* ARGSUSED */
f6c8601080b4 6938335 zfs send -R can still miss renamed snapshots
Chris Kirby <Chris.Kirby@oracle.com>
parents: 12527
diff changeset
   972
int
f6c8601080b4 6938335 zfs send -R can still miss renamed snapshots
Chris Kirby <Chris.Kirby@oracle.com>
parents: 12527
diff changeset
   973
zfs_onexit_add_cb(minor_t minor, void (*func)(void *), void *data,
12527
693dd2cad55f 6884007 zfs_send() can leave temporary holds around
Chris Kirby <Chris.Kirby@oracle.com>
parents: 11935
diff changeset
   974
    uint64_t *action_handle)
693dd2cad55f 6884007 zfs_send() can leave temporary holds around
Chris Kirby <Chris.Kirby@oracle.com>
parents: 11935
diff changeset
   975
{
693dd2cad55f 6884007 zfs_send() can leave temporary holds around
Chris Kirby <Chris.Kirby@oracle.com>
parents: 11935
diff changeset
   976
	return (0);
693dd2cad55f 6884007 zfs_send() can leave temporary holds around
Chris Kirby <Chris.Kirby@oracle.com>
parents: 11935
diff changeset
   977
}
693dd2cad55f 6884007 zfs_send() can leave temporary holds around
Chris Kirby <Chris.Kirby@oracle.com>
parents: 11935
diff changeset
   978
693dd2cad55f 6884007 zfs_send() can leave temporary holds around
Chris Kirby <Chris.Kirby@oracle.com>
parents: 11935
diff changeset
   979
/* ARGSUSED */
693dd2cad55f 6884007 zfs_send() can leave temporary holds around
Chris Kirby <Chris.Kirby@oracle.com>
parents: 11935
diff changeset
   980
int
12798
f6c8601080b4 6938335 zfs send -R can still miss renamed snapshots
Chris Kirby <Chris.Kirby@oracle.com>
parents: 12527
diff changeset
   981
zfs_onexit_del_cb(minor_t minor, uint64_t action_handle, boolean_t fire)
12527
693dd2cad55f 6884007 zfs_send() can leave temporary holds around
Chris Kirby <Chris.Kirby@oracle.com>
parents: 11935
diff changeset
   982
{
693dd2cad55f 6884007 zfs_send() can leave temporary holds around
Chris Kirby <Chris.Kirby@oracle.com>
parents: 11935
diff changeset
   983
	return (0);
693dd2cad55f 6884007 zfs_send() can leave temporary holds around
Chris Kirby <Chris.Kirby@oracle.com>
parents: 11935
diff changeset
   984
}
693dd2cad55f 6884007 zfs_send() can leave temporary holds around
Chris Kirby <Chris.Kirby@oracle.com>
parents: 11935
diff changeset
   985
693dd2cad55f 6884007 zfs_send() can leave temporary holds around
Chris Kirby <Chris.Kirby@oracle.com>
parents: 11935
diff changeset
   986
/* ARGSUSED */
693dd2cad55f 6884007 zfs_send() can leave temporary holds around
Chris Kirby <Chris.Kirby@oracle.com>
parents: 11935
diff changeset
   987
int
12798
f6c8601080b4 6938335 zfs send -R can still miss renamed snapshots
Chris Kirby <Chris.Kirby@oracle.com>
parents: 12527
diff changeset
   988
zfs_onexit_cb_data(minor_t minor, uint64_t action_handle, void **data)
12527
693dd2cad55f 6884007 zfs_send() can leave temporary holds around
Chris Kirby <Chris.Kirby@oracle.com>
parents: 11935
diff changeset
   989
{
693dd2cad55f 6884007 zfs_send() can leave temporary holds around
Chris Kirby <Chris.Kirby@oracle.com>
parents: 11935
diff changeset
   990
	return (0);
693dd2cad55f 6884007 zfs_send() can leave temporary holds around
Chris Kirby <Chris.Kirby@oracle.com>
parents: 11935
diff changeset
   991
}