usr/src/uts/common/fs/zfs/zfs_ioctl.c
author Sherry Moore <Sherry.Moore@Sun.COM>
Mon, 22 Sep 2008 16:30:26 -0700
changeset 7656 2621e50fdf4a
parent 7294 c9c31ef4c960
child 7754 b80e4842ad54
permissions -rw-r--r--
PSARC 2008/382 Fast Reboot 6714038 Fast Reboot support for x86 platforms
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
1485
e971e58d18f6 6322005 support for persistent offline
lling
parents: 1356
diff changeset
     5
 * Common Development and Distribution License (the "License").
e971e58d18f6 6322005 support for persistent offline
lling
parents: 1356
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
/*
5977
33727f49aeaa 6654731 sharesmb property should only be settable on CIFS aware ZPL
marks
parents: 5663
diff changeset
    22
 * Copyright 2008 Sun Microsystems, Inc.  All rights reserved.
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    23
 * Use is subject to license terms.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    24
 */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    25
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    26
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    27
#include <sys/types.h>
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    28
#include <sys/param.h>
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    29
#include <sys/errno.h>
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    30
#include <sys/uio.h>
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    31
#include <sys/buf.h>
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    32
#include <sys/modctl.h>
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    33
#include <sys/open.h>
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    34
#include <sys/file.h>
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    35
#include <sys/kmem.h>
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    36
#include <sys/conf.h>
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    37
#include <sys/cmn_err.h>
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    38
#include <sys/stat.h>
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    39
#include <sys/zfs_ioctl.h>
5331
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
    40
#include <sys/zfs_znode.h>
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    41
#include <sys/zap.h>
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    42
#include <sys/spa.h>
3912
f6891a60bd72 PSARC 2007/083 ZFS bootable datasets
lling
parents: 3886
diff changeset
    43
#include <sys/spa_impl.h>
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    44
#include <sys/vdev.h>
3912
f6891a60bd72 PSARC 2007/083 ZFS bootable datasets
lling
parents: 3886
diff changeset
    45
#include <sys/vdev_impl.h>
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    46
#include <sys/dmu.h>
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    47
#include <sys/dsl_dir.h>
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    48
#include <sys/dsl_dataset.h>
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    49
#include <sys/dsl_prop.h>
4543
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
    50
#include <sys/dsl_deleg.h>
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
    51
#include <sys/dmu_objset.h>
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    52
#include <sys/ddi.h>
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    53
#include <sys/sunddi.h>
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    54
#include <sys/sunldi.h>
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    55
#include <sys/policy.h>
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    56
#include <sys/zone.h>
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    57
#include <sys/nvpair.h>
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    58
#include <sys/pathname.h>
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    59
#include <sys/mount.h>
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    60
#include <sys/sdt.h>
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    61
#include <sys/fs/zfs.h>
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    62
#include <sys/zfs_ctldir.h>
5331
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
    63
#include <sys/zfs_dir.h>
2885
c0259887ebbc 6460059 zfs destroy <snapshot> leaves behind kruft
ahrens
parents: 2856
diff changeset
    64
#include <sys/zvol.h>
4543
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
    65
#include <sharefs/share.h>
5326
6752aa2bd5bc 6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents: 5147
diff changeset
    66
#include <sys/dmu_objset.h>
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    67
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    68
#include "zfs_namecheck.h"
2676
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
    69
#include "zfs_prop.h"
4543
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
    70
#include "zfs_deleg.h"
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    71
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    72
extern struct modlfs zfs_modlfs;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    73
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    74
extern void zfs_init(void);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    75
extern void zfs_fini(void);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    76
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    77
ldi_ident_t zfs_li = NULL;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    78
dev_info_t *zfs_dip;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    79
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    80
typedef int zfs_ioc_func_t(zfs_cmd_t *);
4543
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
    81
typedef int zfs_secpolicy_func_t(zfs_cmd_t *, cred_t *);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    82
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    83
typedef struct zfs_ioc_vec {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    84
	zfs_ioc_func_t		*zvec_func;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    85
	zfs_secpolicy_func_t	*zvec_secpolicy;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    86
	enum {
4577
ed36b0e652bc PSARC/2007/328 zfs upgrade
ahrens
parents: 4543
diff changeset
    87
		NO_NAME,
ed36b0e652bc PSARC/2007/328 zfs upgrade
ahrens
parents: 4543
diff changeset
    88
		POOL_NAME,
ed36b0e652bc PSARC/2007/328 zfs upgrade
ahrens
parents: 4543
diff changeset
    89
		DATASET_NAME
4543
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
    90
	} zvec_namecheck;
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
    91
	boolean_t		zvec_his_log;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    92
} zfs_ioc_vec_t;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    93
7265
cc18862247da PSARC/2008/483 ZFS clone -o
ahrens
parents: 7214
diff changeset
    94
static void clear_props(char *dataset, nvlist_t *props);
7184
9508660f9c27 PSARC 2008/223 Pool root file system properties via zpool(1M)
timh
parents: 7046
diff changeset
    95
static int zfs_fill_zplprops_root(uint64_t, nvlist_t *, nvlist_t *,
9508660f9c27 PSARC 2008/223 Pool root file system properties via zpool(1M)
timh
parents: 7046
diff changeset
    96
    boolean_t *);
9508660f9c27 PSARC 2008/223 Pool root file system properties via zpool(1M)
timh
parents: 7046
diff changeset
    97
int zfs_set_prop_nvlist(const char *, nvlist_t *);
9508660f9c27 PSARC 2008/223 Pool root file system properties via zpool(1M)
timh
parents: 7046
diff changeset
    98
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    99
/* _NOTE(PRINTFLIKE(4)) - this is printf-like, but lint is too whiney */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   100
void
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   101
__dprintf(const char *file, const char *func, int line, const char *fmt, ...)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   102
{
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   103
	const char *newfile;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   104
	char buf[256];
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   105
	va_list adx;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   106
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   107
	/*
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   108
	 * Get rid of annoying "../common/" prefix to filename.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   109
	 */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   110
	newfile = strrchr(file, '/');
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   111
	if (newfile != NULL) {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   112
		newfile = newfile + 1; /* Get rid of leading / */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   113
	} else {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   114
		newfile = file;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   115
	}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   116
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   117
	va_start(adx, fmt);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   118
	(void) vsnprintf(buf, sizeof (buf), fmt, adx);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   119
	va_end(adx);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   120
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   121
	/*
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   122
	 * To get this data, use the zfs-dprintf probe as so:
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   123
	 * dtrace -q -n 'zfs-dprintf \
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   124
	 *	/stringof(arg0) == "dbuf.c"/ \
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   125
	 *	{printf("%s: %s", stringof(arg1), stringof(arg3))}'
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   126
	 * arg0 = file name
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   127
	 * arg1 = function name
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   128
	 * arg2 = line number
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   129
	 * arg3 = message
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   130
	 */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   131
	DTRACE_PROBE4(zfs__dprintf,
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   132
	    char *, newfile, char *, func, int, line, char *, buf);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   133
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   134
4543
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   135
static void
4715
e8d212dda064 6535695 Panic: shpp->sh_eof == shpp->sh_pool_create_len, file: ../../common/fs/zfs/spa_history.c, line: 235
ek110237
parents: 4670
diff changeset
   136
history_str_free(char *buf)
e8d212dda064 6535695 Panic: shpp->sh_eof == shpp->sh_pool_create_len, file: ../../common/fs/zfs/spa_history.c, line: 235
ek110237
parents: 4670
diff changeset
   137
{
e8d212dda064 6535695 Panic: shpp->sh_eof == shpp->sh_pool_create_len, file: ../../common/fs/zfs/spa_history.c, line: 235
ek110237
parents: 4670
diff changeset
   138
	kmem_free(buf, HIS_MAX_RECORD_LEN);
e8d212dda064 6535695 Panic: shpp->sh_eof == shpp->sh_pool_create_len, file: ../../common/fs/zfs/spa_history.c, line: 235
ek110237
parents: 4670
diff changeset
   139
}
e8d212dda064 6535695 Panic: shpp->sh_eof == shpp->sh_pool_create_len, file: ../../common/fs/zfs/spa_history.c, line: 235
ek110237
parents: 4670
diff changeset
   140
e8d212dda064 6535695 Panic: shpp->sh_eof == shpp->sh_pool_create_len, file: ../../common/fs/zfs/spa_history.c, line: 235
ek110237
parents: 4670
diff changeset
   141
static char *
e8d212dda064 6535695 Panic: shpp->sh_eof == shpp->sh_pool_create_len, file: ../../common/fs/zfs/spa_history.c, line: 235
ek110237
parents: 4670
diff changeset
   142
history_str_get(zfs_cmd_t *zc)
e8d212dda064 6535695 Panic: shpp->sh_eof == shpp->sh_pool_create_len, file: ../../common/fs/zfs/spa_history.c, line: 235
ek110237
parents: 4670
diff changeset
   143
{
e8d212dda064 6535695 Panic: shpp->sh_eof == shpp->sh_pool_create_len, file: ../../common/fs/zfs/spa_history.c, line: 235
ek110237
parents: 4670
diff changeset
   144
	char *buf;
e8d212dda064 6535695 Panic: shpp->sh_eof == shpp->sh_pool_create_len, file: ../../common/fs/zfs/spa_history.c, line: 235
ek110237
parents: 4670
diff changeset
   145
e8d212dda064 6535695 Panic: shpp->sh_eof == shpp->sh_pool_create_len, file: ../../common/fs/zfs/spa_history.c, line: 235
ek110237
parents: 4670
diff changeset
   146
	if (zc->zc_history == NULL)
e8d212dda064 6535695 Panic: shpp->sh_eof == shpp->sh_pool_create_len, file: ../../common/fs/zfs/spa_history.c, line: 235
ek110237
parents: 4670
diff changeset
   147
		return (NULL);
e8d212dda064 6535695 Panic: shpp->sh_eof == shpp->sh_pool_create_len, file: ../../common/fs/zfs/spa_history.c, line: 235
ek110237
parents: 4670
diff changeset
   148
e8d212dda064 6535695 Panic: shpp->sh_eof == shpp->sh_pool_create_len, file: ../../common/fs/zfs/spa_history.c, line: 235
ek110237
parents: 4670
diff changeset
   149
	buf = kmem_alloc(HIS_MAX_RECORD_LEN, KM_SLEEP);
e8d212dda064 6535695 Panic: shpp->sh_eof == shpp->sh_pool_create_len, file: ../../common/fs/zfs/spa_history.c, line: 235
ek110237
parents: 4670
diff changeset
   150
	if (copyinstr((void *)(uintptr_t)zc->zc_history,
e8d212dda064 6535695 Panic: shpp->sh_eof == shpp->sh_pool_create_len, file: ../../common/fs/zfs/spa_history.c, line: 235
ek110237
parents: 4670
diff changeset
   151
	    buf, HIS_MAX_RECORD_LEN, NULL) != 0) {
e8d212dda064 6535695 Panic: shpp->sh_eof == shpp->sh_pool_create_len, file: ../../common/fs/zfs/spa_history.c, line: 235
ek110237
parents: 4670
diff changeset
   152
		history_str_free(buf);
e8d212dda064 6535695 Panic: shpp->sh_eof == shpp->sh_pool_create_len, file: ../../common/fs/zfs/spa_history.c, line: 235
ek110237
parents: 4670
diff changeset
   153
		return (NULL);
e8d212dda064 6535695 Panic: shpp->sh_eof == shpp->sh_pool_create_len, file: ../../common/fs/zfs/spa_history.c, line: 235
ek110237
parents: 4670
diff changeset
   154
	}
e8d212dda064 6535695 Panic: shpp->sh_eof == shpp->sh_pool_create_len, file: ../../common/fs/zfs/spa_history.c, line: 235
ek110237
parents: 4670
diff changeset
   155
e8d212dda064 6535695 Panic: shpp->sh_eof == shpp->sh_pool_create_len, file: ../../common/fs/zfs/spa_history.c, line: 235
ek110237
parents: 4670
diff changeset
   156
	buf[HIS_MAX_RECORD_LEN -1] = '\0';
e8d212dda064 6535695 Panic: shpp->sh_eof == shpp->sh_pool_create_len, file: ../../common/fs/zfs/spa_history.c, line: 235
ek110237
parents: 4670
diff changeset
   157
e8d212dda064 6535695 Panic: shpp->sh_eof == shpp->sh_pool_create_len, file: ../../common/fs/zfs/spa_history.c, line: 235
ek110237
parents: 4670
diff changeset
   158
	return (buf);
e8d212dda064 6535695 Panic: shpp->sh_eof == shpp->sh_pool_create_len, file: ../../common/fs/zfs/spa_history.c, line: 235
ek110237
parents: 4670
diff changeset
   159
}
e8d212dda064 6535695 Panic: shpp->sh_eof == shpp->sh_pool_create_len, file: ../../common/fs/zfs/spa_history.c, line: 235
ek110237
parents: 4670
diff changeset
   160
5375
c682f8c5f5e3 6622822 can not create clone on old version pool
timh
parents: 5367
diff changeset
   161
/*
7042
46fc4b6db23e 6721094 Setting certain properties on root pools should not be allowed
gw25295
parents: 6865
diff changeset
   162
 * Check to see if the named dataset is currently defined as bootable
46fc4b6db23e 6721094 Setting certain properties on root pools should not be allowed
gw25295
parents: 6865
diff changeset
   163
 */
46fc4b6db23e 6721094 Setting certain properties on root pools should not be allowed
gw25295
parents: 6865
diff changeset
   164
static boolean_t
46fc4b6db23e 6721094 Setting certain properties on root pools should not be allowed
gw25295
parents: 6865
diff changeset
   165
zfs_is_bootfs(const char *name)
46fc4b6db23e 6721094 Setting certain properties on root pools should not be allowed
gw25295
parents: 6865
diff changeset
   166
{
46fc4b6db23e 6721094 Setting certain properties on root pools should not be allowed
gw25295
parents: 6865
diff changeset
   167
	spa_t *spa;
46fc4b6db23e 6721094 Setting certain properties on root pools should not be allowed
gw25295
parents: 6865
diff changeset
   168
	boolean_t ret = B_FALSE;
46fc4b6db23e 6721094 Setting certain properties on root pools should not be allowed
gw25295
parents: 6865
diff changeset
   169
46fc4b6db23e 6721094 Setting certain properties on root pools should not be allowed
gw25295
parents: 6865
diff changeset
   170
	if (spa_open(name, &spa, FTAG) == 0) {
46fc4b6db23e 6721094 Setting certain properties on root pools should not be allowed
gw25295
parents: 6865
diff changeset
   171
		if (spa->spa_bootfs) {
46fc4b6db23e 6721094 Setting certain properties on root pools should not be allowed
gw25295
parents: 6865
diff changeset
   172
			objset_t *os;
46fc4b6db23e 6721094 Setting certain properties on root pools should not be allowed
gw25295
parents: 6865
diff changeset
   173
46fc4b6db23e 6721094 Setting certain properties on root pools should not be allowed
gw25295
parents: 6865
diff changeset
   174
			if (dmu_objset_open(name, DMU_OST_ZFS,
46fc4b6db23e 6721094 Setting certain properties on root pools should not be allowed
gw25295
parents: 6865
diff changeset
   175
			    DS_MODE_USER | DS_MODE_READONLY, &os) == 0) {
46fc4b6db23e 6721094 Setting certain properties on root pools should not be allowed
gw25295
parents: 6865
diff changeset
   176
				ret = (dmu_objset_id(os) == spa->spa_bootfs);
46fc4b6db23e 6721094 Setting certain properties on root pools should not be allowed
gw25295
parents: 6865
diff changeset
   177
				dmu_objset_close(os);
46fc4b6db23e 6721094 Setting certain properties on root pools should not be allowed
gw25295
parents: 6865
diff changeset
   178
			}
46fc4b6db23e 6721094 Setting certain properties on root pools should not be allowed
gw25295
parents: 6865
diff changeset
   179
		}
46fc4b6db23e 6721094 Setting certain properties on root pools should not be allowed
gw25295
parents: 6865
diff changeset
   180
		spa_close(spa, FTAG);
46fc4b6db23e 6721094 Setting certain properties on root pools should not be allowed
gw25295
parents: 6865
diff changeset
   181
	}
46fc4b6db23e 6721094 Setting certain properties on root pools should not be allowed
gw25295
parents: 6865
diff changeset
   182
	return (ret);
46fc4b6db23e 6721094 Setting certain properties on root pools should not be allowed
gw25295
parents: 6865
diff changeset
   183
}
46fc4b6db23e 6721094 Setting certain properties on root pools should not be allowed
gw25295
parents: 6865
diff changeset
   184
46fc4b6db23e 6721094 Setting certain properties on root pools should not be allowed
gw25295
parents: 6865
diff changeset
   185
/*
7184
9508660f9c27 PSARC 2008/223 Pool root file system properties via zpool(1M)
timh
parents: 7046
diff changeset
   186
 * zfs_earlier_version
5375
c682f8c5f5e3 6622822 can not create clone on old version pool
timh
parents: 5367
diff changeset
   187
 *
c682f8c5f5e3 6622822 can not create clone on old version pool
timh
parents: 5367
diff changeset
   188
 *	Return non-zero if the spa version is less than requested version.
c682f8c5f5e3 6622822 can not create clone on old version pool
timh
parents: 5367
diff changeset
   189
 */
5331
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
   190
static int
7184
9508660f9c27 PSARC 2008/223 Pool root file system properties via zpool(1M)
timh
parents: 7046
diff changeset
   191
zfs_earlier_version(const char *name, int version)
5331
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
   192
{
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
   193
	spa_t *spa;
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
   194
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
   195
	if (spa_open(name, &spa, FTAG) == 0) {
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
   196
		if (spa_version(spa) < version) {
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
   197
			spa_close(spa, FTAG);
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
   198
			return (1);
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
   199
		}
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
   200
		spa_close(spa, FTAG);
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
   201
	}
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
   202
	return (0);
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
   203
}
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
   204
5977
33727f49aeaa 6654731 sharesmb property should only be settable on CIFS aware ZPL
marks
parents: 5663
diff changeset
   205
/*
6689
47572a2f5e73 6610506 Eliminate or improve retry logic from callers of dmu_objset_open()
maybee
parents: 6643
diff changeset
   206
 * zpl_earlier_version
5977
33727f49aeaa 6654731 sharesmb property should only be settable on CIFS aware ZPL
marks
parents: 5663
diff changeset
   207
 *
6689
47572a2f5e73 6610506 Eliminate or improve retry logic from callers of dmu_objset_open()
maybee
parents: 6643
diff changeset
   208
 * Return TRUE if the ZPL version is less than requested version.
5977
33727f49aeaa 6654731 sharesmb property should only be settable on CIFS aware ZPL
marks
parents: 5663
diff changeset
   209
 */
6689
47572a2f5e73 6610506 Eliminate or improve retry logic from callers of dmu_objset_open()
maybee
parents: 6643
diff changeset
   210
static boolean_t
47572a2f5e73 6610506 Eliminate or improve retry logic from callers of dmu_objset_open()
maybee
parents: 6643
diff changeset
   211
zpl_earlier_version(const char *name, int version)
5977
33727f49aeaa 6654731 sharesmb property should only be settable on CIFS aware ZPL
marks
parents: 5663
diff changeset
   212
{
33727f49aeaa 6654731 sharesmb property should only be settable on CIFS aware ZPL
marks
parents: 5663
diff changeset
   213
	objset_t *os;
6689
47572a2f5e73 6610506 Eliminate or improve retry logic from callers of dmu_objset_open()
maybee
parents: 6643
diff changeset
   214
	boolean_t rc = B_TRUE;
5977
33727f49aeaa 6654731 sharesmb property should only be settable on CIFS aware ZPL
marks
parents: 5663
diff changeset
   215
33727f49aeaa 6654731 sharesmb property should only be settable on CIFS aware ZPL
marks
parents: 5663
diff changeset
   216
	if (dmu_objset_open(name, DMU_OST_ANY,
6689
47572a2f5e73 6610506 Eliminate or improve retry logic from callers of dmu_objset_open()
maybee
parents: 6643
diff changeset
   217
	    DS_MODE_USER | DS_MODE_READONLY, &os) == 0) {
47572a2f5e73 6610506 Eliminate or improve retry logic from callers of dmu_objset_open()
maybee
parents: 6643
diff changeset
   218
		uint64_t zplversion;
47572a2f5e73 6610506 Eliminate or improve retry logic from callers of dmu_objset_open()
maybee
parents: 6643
diff changeset
   219
47572a2f5e73 6610506 Eliminate or improve retry logic from callers of dmu_objset_open()
maybee
parents: 6643
diff changeset
   220
		if (zfs_get_zplprop(os, ZFS_PROP_VERSION, &zplversion) == 0)
47572a2f5e73 6610506 Eliminate or improve retry logic from callers of dmu_objset_open()
maybee
parents: 6643
diff changeset
   221
			rc = zplversion < version;
5977
33727f49aeaa 6654731 sharesmb property should only be settable on CIFS aware ZPL
marks
parents: 5663
diff changeset
   222
		dmu_objset_close(os);
33727f49aeaa 6654731 sharesmb property should only be settable on CIFS aware ZPL
marks
parents: 5663
diff changeset
   223
	}
33727f49aeaa 6654731 sharesmb property should only be settable on CIFS aware ZPL
marks
parents: 5663
diff changeset
   224
	return (rc);
33727f49aeaa 6654731 sharesmb property should only be settable on CIFS aware ZPL
marks
parents: 5663
diff changeset
   225
}
33727f49aeaa 6654731 sharesmb property should only be settable on CIFS aware ZPL
marks
parents: 5663
diff changeset
   226
4715
e8d212dda064 6535695 Panic: shpp->sh_eof == shpp->sh_pool_create_len, file: ../../common/fs/zfs/spa_history.c, line: 235
ek110237
parents: 4670
diff changeset
   227
static void
4543
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   228
zfs_log_history(zfs_cmd_t *zc)
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   229
{
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   230
	spa_t *spa;
4603
c7840c367d00 6494569 zfs recv -d pool/<doesn't exist> core dumps for top-level filesystem backups
ahrens
parents: 4577
diff changeset
   231
	char *buf;
4543
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   232
4715
e8d212dda064 6535695 Panic: shpp->sh_eof == shpp->sh_pool_create_len, file: ../../common/fs/zfs/spa_history.c, line: 235
ek110237
parents: 4670
diff changeset
   233
	if ((buf = history_str_get(zc)) == NULL)
4577
ed36b0e652bc PSARC/2007/328 zfs upgrade
ahrens
parents: 4543
diff changeset
   234
		return;
ed36b0e652bc PSARC/2007/328 zfs upgrade
ahrens
parents: 4543
diff changeset
   235
4715
e8d212dda064 6535695 Panic: shpp->sh_eof == shpp->sh_pool_create_len, file: ../../common/fs/zfs/spa_history.c, line: 235
ek110237
parents: 4670
diff changeset
   236
	if (spa_open(zc->zc_name, &spa, FTAG) == 0) {
e8d212dda064 6535695 Panic: shpp->sh_eof == shpp->sh_pool_create_len, file: ../../common/fs/zfs/spa_history.c, line: 235
ek110237
parents: 4670
diff changeset
   237
		if (spa_version(spa) >= SPA_VERSION_ZPOOL_HISTORY)
e8d212dda064 6535695 Panic: shpp->sh_eof == shpp->sh_pool_create_len, file: ../../common/fs/zfs/spa_history.c, line: 235
ek110237
parents: 4670
diff changeset
   238
			(void) spa_history_log(spa, buf, LOG_CMD_NORMAL);
e8d212dda064 6535695 Panic: shpp->sh_eof == shpp->sh_pool_create_len, file: ../../common/fs/zfs/spa_history.c, line: 235
ek110237
parents: 4670
diff changeset
   239
		spa_close(spa, FTAG);
4543
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   240
	}
4715
e8d212dda064 6535695 Panic: shpp->sh_eof == shpp->sh_pool_create_len, file: ../../common/fs/zfs/spa_history.c, line: 235
ek110237
parents: 4670
diff changeset
   241
	history_str_free(buf);
4543
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   242
}
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   243
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   244
/*
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   245
 * Policy for top-level read operations (list pools).  Requires no privileges,
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   246
 * and can be used in the local zone, as there is no associated dataset.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   247
 */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   248
/* ARGSUSED */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   249
static int
4543
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   250
zfs_secpolicy_none(zfs_cmd_t *zc, cred_t *cr)
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   251
{
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   252
	return (0);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   253
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   254
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   255
/*
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   256
 * Policy for dataset read operations (list children, get statistics).  Requires
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   257
 * no privileges, but must be visible in the local zone.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   258
 */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   259
/* ARGSUSED */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   260
static int
4543
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   261
zfs_secpolicy_read(zfs_cmd_t *zc, cred_t *cr)
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   262
{
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   263
	if (INGLOBALZONE(curproc) ||
4543
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   264
	    zone_dataset_visible(zc->zc_name, NULL))
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   265
		return (0);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   266
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   267
	return (ENOENT);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   268
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   269
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   270
static int
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   271
zfs_dozonecheck(const char *dataset, cred_t *cr)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   272
{
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   273
	uint64_t zoned;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   274
	int writable = 1;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   275
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   276
	/*
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   277
	 * The dataset must be visible by this zone -- check this first
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   278
	 * so they don't see EPERM on something they shouldn't know about.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   279
	 */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   280
	if (!INGLOBALZONE(curproc) &&
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   281
	    !zone_dataset_visible(dataset, &writable))
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   282
		return (ENOENT);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   283
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   284
	if (dsl_prop_get_integer(dataset, "zoned", &zoned, NULL))
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   285
		return (ENOENT);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   286
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   287
	if (INGLOBALZONE(curproc)) {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   288
		/*
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   289
		 * If the fs is zoned, only root can access it from the
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   290
		 * global zone.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   291
		 */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   292
		if (secpolicy_zfs(cr) && zoned)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   293
			return (EPERM);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   294
	} else {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   295
		/*
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   296
		 * If we are in a local zone, the 'zoned' property must be set.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   297
		 */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   298
		if (!zoned)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   299
			return (EPERM);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   300
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   301
		/* must be writable by this zone */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   302
		if (!writable)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   303
			return (EPERM);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   304
	}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   305
	return (0);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   306
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   307
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   308
int
4543
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   309
zfs_secpolicy_write_perms(const char *name, const char *perm, cred_t *cr)
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   310
{
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   311
	int error;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   312
4543
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   313
	error = zfs_dozonecheck(name, cr);
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   314
	if (error == 0) {
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   315
		error = secpolicy_zfs(cr);
4670
002728040e28 6580745 "zfs inherit" can be executed by ordinary user
ahrens
parents: 4611
diff changeset
   316
		if (error)
4543
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   317
			error = dsl_deleg_access(name, perm, cr);
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   318
	}
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   319
	return (error);
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   320
}
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   321
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   322
static int
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   323
zfs_secpolicy_setprop(const char *name, zfs_prop_t prop, cred_t *cr)
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   324
{
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   325
	/*
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   326
	 * Check permissions for special properties.
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   327
	 */
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   328
	switch (prop) {
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   329
	case ZFS_PROP_ZONED:
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   330
		/*
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   331
		 * Disallow setting of 'zoned' from within a local zone.
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   332
		 */
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   333
		if (!INGLOBALZONE(curproc))
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   334
			return (EPERM);
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   335
		break;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   336
4543
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   337
	case ZFS_PROP_QUOTA:
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   338
		if (!INGLOBALZONE(curproc)) {
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   339
			uint64_t zoned;
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   340
			char setpoint[MAXNAMELEN];
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   341
			/*
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   342
			 * Unprivileged users are allowed to modify the
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   343
			 * quota on things *under* (ie. contained by)
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   344
			 * the thing they own.
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   345
			 */
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   346
			if (dsl_prop_get_integer(name, "zoned", &zoned,
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   347
			    setpoint))
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   348
				return (EPERM);
4670
002728040e28 6580745 "zfs inherit" can be executed by ordinary user
ahrens
parents: 4611
diff changeset
   349
			if (!zoned || strlen(name) <= strlen(setpoint))
4543
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   350
				return (EPERM);
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   351
		}
4670
002728040e28 6580745 "zfs inherit" can be executed by ordinary user
ahrens
parents: 4611
diff changeset
   352
		break;
4543
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   353
	}
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   354
4787
602d3f97842c 6393351 unique_* could be improved
ahrens
parents: 4720
diff changeset
   355
	return (zfs_secpolicy_write_perms(name, zfs_prop_to_name(prop), cr));
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   356
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   357
4543
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   358
int
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   359
zfs_secpolicy_fsacl(zfs_cmd_t *zc, cred_t *cr)
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   360
{
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   361
	int error;
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   362
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   363
	error = zfs_dozonecheck(zc->zc_name, cr);
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   364
	if (error)
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   365
		return (error);
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   366
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   367
	/*
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   368
	 * permission to set permissions will be evaluated later in
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   369
	 * dsl_deleg_can_allow()
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   370
	 */
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   371
	return (0);
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   372
}
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   373
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   374
int
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   375
zfs_secpolicy_rollback(zfs_cmd_t *zc, cred_t *cr)
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   376
{
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   377
	int error;
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   378
	error = zfs_secpolicy_write_perms(zc->zc_name,
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   379
	    ZFS_DELEG_PERM_ROLLBACK, cr);
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   380
	if (error == 0)
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   381
		error = zfs_secpolicy_write_perms(zc->zc_name,
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   382
		    ZFS_DELEG_PERM_MOUNT, cr);
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   383
	return (error);
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   384
}
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   385
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   386
int
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   387
zfs_secpolicy_send(zfs_cmd_t *zc, cred_t *cr)
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   388
{
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   389
	return (zfs_secpolicy_write_perms(zc->zc_name,
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   390
	    ZFS_DELEG_PERM_SEND, cr));
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   391
}
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   392
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   393
int
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   394
zfs_secpolicy_share(zfs_cmd_t *zc, cred_t *cr)
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   395
{
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   396
	if (!INGLOBALZONE(curproc))
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   397
		return (EPERM);
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   398
5367
c40abbe796be PSARC/2007/574 zfs send -R
ahrens
parents: 5331
diff changeset
   399
	if (secpolicy_nfs(cr) == 0) {
4543
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   400
		return (0);
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   401
	} else {
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   402
		vnode_t *vp;
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   403
		int error;
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   404
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   405
		if ((error = lookupname(zc->zc_value, UIO_SYSSPACE,
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   406
		    NO_FOLLOW, NULL, &vp)) != 0)
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   407
			return (error);
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   408
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   409
		/* Now make sure mntpnt and dataset are ZFS */
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   410
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   411
		if (vp->v_vfsp->vfs_fstype != zfsfstype ||
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   412
		    (strcmp((char *)refstr_value(vp->v_vfsp->vfs_resource),
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   413
		    zc->zc_name) != 0)) {
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   414
			VN_RELE(vp);
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   415
			return (EPERM);
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   416
		}
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   417
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   418
		VN_RELE(vp);
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   419
		return (dsl_deleg_access(zc->zc_name,
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   420
		    ZFS_DELEG_PERM_SHARE, cr));
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   421
	}
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   422
}
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   423
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   424
static int
4543
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   425
zfs_get_parent(const char *datasetname, char *parent, int parentsize)
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   426
{
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   427
	char *cp;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   428
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   429
	/*
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   430
	 * Remove the @bla or /bla from the end of the name to get the parent.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   431
	 */
4543
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   432
	(void) strncpy(parent, datasetname, parentsize);
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   433
	cp = strrchr(parent, '@');
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   434
	if (cp != NULL) {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   435
		cp[0] = '\0';
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   436
	} else {
4543
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   437
		cp = strrchr(parent, '/');
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   438
		if (cp == NULL)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   439
			return (ENOENT);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   440
		cp[0] = '\0';
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   441
	}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   442
4543
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   443
	return (0);
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   444
}
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   445
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   446
int
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   447
zfs_secpolicy_destroy_perms(const char *name, cred_t *cr)
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   448
{
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   449
	int error;
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   450
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   451
	if ((error = zfs_secpolicy_write_perms(name,
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   452
	    ZFS_DELEG_PERM_MOUNT, cr)) != 0)
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   453
		return (error);
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   454
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   455
	return (zfs_secpolicy_write_perms(name, ZFS_DELEG_PERM_DESTROY, cr));
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   456
}
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   457
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   458
static int
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   459
zfs_secpolicy_destroy(zfs_cmd_t *zc, cred_t *cr)
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   460
{
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   461
	return (zfs_secpolicy_destroy_perms(zc->zc_name, cr));
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   462
}
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   463
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   464
/*
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   465
 * Must have sys_config privilege to check the iscsi permission
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   466
 */
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   467
/* ARGSUSED */
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   468
static int
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   469
zfs_secpolicy_iscsi(zfs_cmd_t *zc, cred_t *cr)
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   470
{
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   471
	return (secpolicy_zfs(cr));
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   472
}
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   473
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   474
int
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   475
zfs_secpolicy_rename_perms(const char *from, const char *to, cred_t *cr)
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   476
{
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   477
	char 	parentname[MAXNAMELEN];
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   478
	int	error;
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   479
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   480
	if ((error = zfs_secpolicy_write_perms(from,
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   481
	    ZFS_DELEG_PERM_RENAME, cr)) != 0)
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   482
		return (error);
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   483
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   484
	if ((error = zfs_secpolicy_write_perms(from,
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   485
	    ZFS_DELEG_PERM_MOUNT, cr)) != 0)
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   486
		return (error);
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   487
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   488
	if ((error = zfs_get_parent(to, parentname,
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   489
	    sizeof (parentname))) != 0)
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   490
		return (error);
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   491
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   492
	if ((error = zfs_secpolicy_write_perms(parentname,
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   493
	    ZFS_DELEG_PERM_CREATE, cr)) != 0)
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   494
		return (error);
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   495
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   496
	if ((error = zfs_secpolicy_write_perms(parentname,
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   497
	    ZFS_DELEG_PERM_MOUNT, cr)) != 0)
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   498
		return (error);
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   499
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   500
	return (error);
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   501
}
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   502
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   503
static int
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   504
zfs_secpolicy_rename(zfs_cmd_t *zc, cred_t *cr)
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   505
{
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   506
	return (zfs_secpolicy_rename_perms(zc->zc_name, zc->zc_value, cr));
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   507
}
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   508
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   509
static int
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   510
zfs_secpolicy_promote(zfs_cmd_t *zc, cred_t *cr)
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   511
{
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   512
	char 	parentname[MAXNAMELEN];
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   513
	objset_t *clone;
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   514
	int error;
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   515
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   516
	error = zfs_secpolicy_write_perms(zc->zc_name,
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   517
	    ZFS_DELEG_PERM_PROMOTE, cr);
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   518
	if (error)
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   519
		return (error);
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   520
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   521
	error = dmu_objset_open(zc->zc_name, DMU_OST_ANY,
6689
47572a2f5e73 6610506 Eliminate or improve retry logic from callers of dmu_objset_open()
maybee
parents: 6643
diff changeset
   522
	    DS_MODE_USER | DS_MODE_READONLY, &clone);
4543
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   523
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   524
	if (error == 0) {
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   525
		dsl_dataset_t *pclone = NULL;
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   526
		dsl_dir_t *dd;
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   527
		dd = clone->os->os_dsl_dataset->ds_dir;
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   528
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   529
		rw_enter(&dd->dd_pool->dp_config_rwlock, RW_READER);
6689
47572a2f5e73 6610506 Eliminate or improve retry logic from callers of dmu_objset_open()
maybee
parents: 6643
diff changeset
   530
		error = dsl_dataset_hold_obj(dd->dd_pool,
47572a2f5e73 6610506 Eliminate or improve retry logic from callers of dmu_objset_open()
maybee
parents: 6643
diff changeset
   531
		    dd->dd_phys->dd_origin_obj, FTAG, &pclone);
4543
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   532
		rw_exit(&dd->dd_pool->dp_config_rwlock);
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   533
		if (error) {
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   534
			dmu_objset_close(clone);
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   535
			return (error);
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   536
		}
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   537
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   538
		error = zfs_secpolicy_write_perms(zc->zc_name,
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   539
		    ZFS_DELEG_PERM_MOUNT, cr);
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   540
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   541
		dsl_dataset_name(pclone, parentname);
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   542
		dmu_objset_close(clone);
6689
47572a2f5e73 6610506 Eliminate or improve retry logic from callers of dmu_objset_open()
maybee
parents: 6643
diff changeset
   543
		dsl_dataset_rele(pclone, FTAG);
4543
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   544
		if (error == 0)
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   545
			error = zfs_secpolicy_write_perms(parentname,
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   546
			    ZFS_DELEG_PERM_PROMOTE, cr);
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   547
	}
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   548
	return (error);
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   549
}
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   550
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   551
static int
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   552
zfs_secpolicy_receive(zfs_cmd_t *zc, cred_t *cr)
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   553
{
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   554
	int error;
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   555
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   556
	if ((error = zfs_secpolicy_write_perms(zc->zc_name,
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   557
	    ZFS_DELEG_PERM_RECEIVE, cr)) != 0)
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   558
		return (error);
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   559
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   560
	if ((error = zfs_secpolicy_write_perms(zc->zc_name,
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   561
	    ZFS_DELEG_PERM_MOUNT, cr)) != 0)
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   562
		return (error);
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   563
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   564
	return (zfs_secpolicy_write_perms(zc->zc_name,
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   565
	    ZFS_DELEG_PERM_CREATE, cr));
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   566
}
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   567
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   568
int
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   569
zfs_secpolicy_snapshot_perms(const char *name, cred_t *cr)
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   570
{
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   571
	int error;
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   572
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   573
	if ((error = zfs_secpolicy_write_perms(name,
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   574
	    ZFS_DELEG_PERM_SNAPSHOT, cr)) != 0)
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   575
		return (error);
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   576
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   577
	error = zfs_secpolicy_write_perms(name,
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   578
	    ZFS_DELEG_PERM_MOUNT, cr);
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   579
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   580
	return (error);
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   581
}
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   582
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   583
static int
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   584
zfs_secpolicy_snapshot(zfs_cmd_t *zc, cred_t *cr)
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   585
{
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   586
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   587
	return (zfs_secpolicy_snapshot_perms(zc->zc_name, cr));
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   588
}
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   589
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   590
static int
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   591
zfs_secpolicy_create(zfs_cmd_t *zc, cred_t *cr)
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   592
{
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   593
	char 	parentname[MAXNAMELEN];
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   594
	int 	error;
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   595
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   596
	if ((error = zfs_get_parent(zc->zc_name, parentname,
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   597
	    sizeof (parentname))) != 0)
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   598
		return (error);
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   599
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   600
	if (zc->zc_value[0] != '\0') {
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   601
		if ((error = zfs_secpolicy_write_perms(zc->zc_value,
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   602
		    ZFS_DELEG_PERM_CLONE, cr)) != 0)
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   603
			return (error);
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   604
	}
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   605
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   606
	if ((error = zfs_secpolicy_write_perms(parentname,
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   607
	    ZFS_DELEG_PERM_CREATE, cr)) != 0)
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   608
		return (error);
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   609
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   610
	error = zfs_secpolicy_write_perms(parentname,
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   611
	    ZFS_DELEG_PERM_MOUNT, cr);
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   612
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   613
	return (error);
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   614
}
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   615
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   616
static int
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   617
zfs_secpolicy_umount(zfs_cmd_t *zc, cred_t *cr)
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   618
{
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   619
	int error;
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   620
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   621
	error = secpolicy_fs_unmount(cr, NULL);
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   622
	if (error) {
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   623
		error = dsl_deleg_access(zc->zc_name, ZFS_DELEG_PERM_MOUNT, cr);
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   624
	}
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   625
	return (error);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   626
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   627
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   628
/*
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   629
 * Policy for pool operations - create/destroy pools, add vdevs, etc.  Requires
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   630
 * SYS_CONFIG privilege, which is not available in a local zone.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   631
 */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   632
/* ARGSUSED */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   633
static int
4543
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   634
zfs_secpolicy_config(zfs_cmd_t *zc, cred_t *cr)
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   635
{
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   636
	if (secpolicy_sys_config(cr, B_FALSE) != 0)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   637
		return (EPERM);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   638
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   639
	return (0);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   640
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   641
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   642
/*
4543
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   643
 * Just like zfs_secpolicy_config, except that we will check for
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   644
 * mount permission on the dataset for permission to create/remove
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   645
 * the minor nodes.
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   646
 */
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   647
static int
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   648
zfs_secpolicy_minor(zfs_cmd_t *zc, cred_t *cr)
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   649
{
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   650
	if (secpolicy_sys_config(cr, B_FALSE) != 0) {
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   651
		return (dsl_deleg_access(zc->zc_name,
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   652
		    ZFS_DELEG_PERM_MOUNT, cr));
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   653
	}
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   654
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   655
	return (0);
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   656
}
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   657
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   658
/*
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
   659
 * Policy for fault injection.  Requires all privileges.
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
   660
 */
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
   661
/* ARGSUSED */
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
   662
static int
4543
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   663
zfs_secpolicy_inject(zfs_cmd_t *zc, cred_t *cr)
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
   664
{
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
   665
	return (secpolicy_zinject(cr));
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
   666
}
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
   667
4849
3a61e0a9a953 6536043 arc_byteswap_func_t and dmu_byteswap_func_t are redundant
ahrens
parents: 4808
diff changeset
   668
static int
3a61e0a9a953 6536043 arc_byteswap_func_t and dmu_byteswap_func_t are redundant
ahrens
parents: 4808
diff changeset
   669
zfs_secpolicy_inherit(zfs_cmd_t *zc, cred_t *cr)
3a61e0a9a953 6536043 arc_byteswap_func_t and dmu_byteswap_func_t are redundant
ahrens
parents: 4808
diff changeset
   670
{
3a61e0a9a953 6536043 arc_byteswap_func_t and dmu_byteswap_func_t are redundant
ahrens
parents: 4808
diff changeset
   671
	zfs_prop_t prop = zfs_name_to_prop(zc->zc_value);
3a61e0a9a953 6536043 arc_byteswap_func_t and dmu_byteswap_func_t are redundant
ahrens
parents: 4808
diff changeset
   672
5094
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
   673
	if (prop == ZPROP_INVAL) {
4849
3a61e0a9a953 6536043 arc_byteswap_func_t and dmu_byteswap_func_t are redundant
ahrens
parents: 4808
diff changeset
   674
		if (!zfs_prop_user(zc->zc_value))
3a61e0a9a953 6536043 arc_byteswap_func_t and dmu_byteswap_func_t are redundant
ahrens
parents: 4808
diff changeset
   675
			return (EINVAL);
3a61e0a9a953 6536043 arc_byteswap_func_t and dmu_byteswap_func_t are redundant
ahrens
parents: 4808
diff changeset
   676
		return (zfs_secpolicy_write_perms(zc->zc_name,
3a61e0a9a953 6536043 arc_byteswap_func_t and dmu_byteswap_func_t are redundant
ahrens
parents: 4808
diff changeset
   677
		    ZFS_DELEG_PERM_USERPROP, cr));
3a61e0a9a953 6536043 arc_byteswap_func_t and dmu_byteswap_func_t are redundant
ahrens
parents: 4808
diff changeset
   678
	} else {
3a61e0a9a953 6536043 arc_byteswap_func_t and dmu_byteswap_func_t are redundant
ahrens
parents: 4808
diff changeset
   679
		if (!zfs_prop_inheritable(prop))
3a61e0a9a953 6536043 arc_byteswap_func_t and dmu_byteswap_func_t are redundant
ahrens
parents: 4808
diff changeset
   680
			return (EINVAL);
3a61e0a9a953 6536043 arc_byteswap_func_t and dmu_byteswap_func_t are redundant
ahrens
parents: 4808
diff changeset
   681
		return (zfs_secpolicy_setprop(zc->zc_name, prop, cr));
3a61e0a9a953 6536043 arc_byteswap_func_t and dmu_byteswap_func_t are redundant
ahrens
parents: 4808
diff changeset
   682
	}
3a61e0a9a953 6536043 arc_byteswap_func_t and dmu_byteswap_func_t are redundant
ahrens
parents: 4808
diff changeset
   683
}
3a61e0a9a953 6536043 arc_byteswap_func_t and dmu_byteswap_func_t are redundant
ahrens
parents: 4808
diff changeset
   684
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
   685
/*
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   686
 * Returns the nvlist as specified by the user in the zfs_cmd_t.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   687
 */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   688
static int
5094
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
   689
get_nvlist(uint64_t nvl, uint64_t size, nvlist_t **nvp)
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   690
{
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   691
	char *packed;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   692
	int error;
5094
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
   693
	nvlist_t *list = NULL;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   694
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   695
	/*
2676
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
   696
	 * Read in and unpack the user-supplied nvlist.
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   697
	 */
5094
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
   698
	if (size == 0)
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   699
		return (EINVAL);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   700
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   701
	packed = kmem_alloc(size, KM_SLEEP);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   702
5094
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
   703
	if ((error = xcopyin((void *)(uintptr_t)nvl, packed, size)) != 0) {
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   704
		kmem_free(packed, size);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   705
		return (error);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   706
	}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   707
5094
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
   708
	if ((error = nvlist_unpack(packed, size, &list, 0)) != 0) {
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   709
		kmem_free(packed, size);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   710
		return (error);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   711
	}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   712
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   713
	kmem_free(packed, size);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   714
5094
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
   715
	*nvp = list;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   716
	return (0);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   717
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   718
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   719
static int
2676
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
   720
put_nvlist(zfs_cmd_t *zc, nvlist_t *nvl)
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
   721
{
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
   722
	char *packed = NULL;
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
   723
	size_t size;
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
   724
	int error;
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
   725
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
   726
	VERIFY(nvlist_size(nvl, &size, NV_ENCODE_NATIVE) == 0);
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
   727
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
   728
	if (size > zc->zc_nvlist_dst_size) {
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
   729
		error = ENOMEM;
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
   730
	} else {
4611
0960c3336815 6575997 Memory corruption while running ztest
marks
parents: 4603
diff changeset
   731
		packed = kmem_alloc(size, KM_SLEEP);
2676
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
   732
		VERIFY(nvlist_pack(nvl, &packed, &size, NV_ENCODE_NATIVE,
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
   733
		    KM_SLEEP) == 0);
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
   734
		error = xcopyout(packed, (void *)(uintptr_t)zc->zc_nvlist_dst,
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
   735
		    size);
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
   736
		kmem_free(packed, size);
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
   737
	}
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
   738
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
   739
	zc->zc_nvlist_dst_size = size;
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
   740
	return (error);
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
   741
}
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
   742
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
   743
static int
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   744
zfs_ioc_pool_create(zfs_cmd_t *zc)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   745
{
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   746
	int error;
5094
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
   747
	nvlist_t *config, *props = NULL;
7184
9508660f9c27 PSARC 2008/223 Pool root file system properties via zpool(1M)
timh
parents: 7046
diff changeset
   748
	nvlist_t *rootprops = NULL;
9508660f9c27 PSARC 2008/223 Pool root file system properties via zpool(1M)
timh
parents: 7046
diff changeset
   749
	nvlist_t *zplprops = NULL;
4715
e8d212dda064 6535695 Panic: shpp->sh_eof == shpp->sh_pool_create_len, file: ../../common/fs/zfs/spa_history.c, line: 235
ek110237
parents: 4670
diff changeset
   750
	char *buf;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   751
5094
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
   752
	if (error = get_nvlist(zc->zc_nvlist_conf, zc->zc_nvlist_conf_size,
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
   753
	    &config))
4988
db8abd9846d4 6595467 libzfs consumers should be allowed to write their own history (or none at all)
ek110237
parents: 4849
diff changeset
   754
		return (error);
4715
e8d212dda064 6535695 Panic: shpp->sh_eof == shpp->sh_pool_create_len, file: ../../common/fs/zfs/spa_history.c, line: 235
ek110237
parents: 4670
diff changeset
   755
5094
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
   756
	if (zc->zc_nvlist_src_size != 0 && (error =
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
   757
	    get_nvlist(zc->zc_nvlist_src, zc->zc_nvlist_src_size, &props))) {
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
   758
		nvlist_free(config);
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
   759
		return (error);
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
   760
	}
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
   761
7184
9508660f9c27 PSARC 2008/223 Pool root file system properties via zpool(1M)
timh
parents: 7046
diff changeset
   762
	if (props) {
9508660f9c27 PSARC 2008/223 Pool root file system properties via zpool(1M)
timh
parents: 7046
diff changeset
   763
		nvlist_t *nvl = NULL;
9508660f9c27 PSARC 2008/223 Pool root file system properties via zpool(1M)
timh
parents: 7046
diff changeset
   764
		uint64_t version = SPA_VERSION;
9508660f9c27 PSARC 2008/223 Pool root file system properties via zpool(1M)
timh
parents: 7046
diff changeset
   765
9508660f9c27 PSARC 2008/223 Pool root file system properties via zpool(1M)
timh
parents: 7046
diff changeset
   766
		(void) nvlist_lookup_uint64(props,
9508660f9c27 PSARC 2008/223 Pool root file system properties via zpool(1M)
timh
parents: 7046
diff changeset
   767
		    zpool_prop_to_name(ZPOOL_PROP_VERSION), &version);
9508660f9c27 PSARC 2008/223 Pool root file system properties via zpool(1M)
timh
parents: 7046
diff changeset
   768
		if (version < SPA_VERSION_INITIAL || version > SPA_VERSION) {
9508660f9c27 PSARC 2008/223 Pool root file system properties via zpool(1M)
timh
parents: 7046
diff changeset
   769
			error = EINVAL;
9508660f9c27 PSARC 2008/223 Pool root file system properties via zpool(1M)
timh
parents: 7046
diff changeset
   770
			goto pool_props_bad;
9508660f9c27 PSARC 2008/223 Pool root file system properties via zpool(1M)
timh
parents: 7046
diff changeset
   771
		}
9508660f9c27 PSARC 2008/223 Pool root file system properties via zpool(1M)
timh
parents: 7046
diff changeset
   772
		(void) nvlist_lookup_nvlist(props, ZPOOL_ROOTFS_PROPS, &nvl);
9508660f9c27 PSARC 2008/223 Pool root file system properties via zpool(1M)
timh
parents: 7046
diff changeset
   773
		if (nvl) {
9508660f9c27 PSARC 2008/223 Pool root file system properties via zpool(1M)
timh
parents: 7046
diff changeset
   774
			error = nvlist_dup(nvl, &rootprops, KM_SLEEP);
9508660f9c27 PSARC 2008/223 Pool root file system properties via zpool(1M)
timh
parents: 7046
diff changeset
   775
			if (error != 0) {
9508660f9c27 PSARC 2008/223 Pool root file system properties via zpool(1M)
timh
parents: 7046
diff changeset
   776
				nvlist_free(config);
9508660f9c27 PSARC 2008/223 Pool root file system properties via zpool(1M)
timh
parents: 7046
diff changeset
   777
				nvlist_free(props);
9508660f9c27 PSARC 2008/223 Pool root file system properties via zpool(1M)
timh
parents: 7046
diff changeset
   778
				return (error);
9508660f9c27 PSARC 2008/223 Pool root file system properties via zpool(1M)
timh
parents: 7046
diff changeset
   779
			}
9508660f9c27 PSARC 2008/223 Pool root file system properties via zpool(1M)
timh
parents: 7046
diff changeset
   780
			(void) nvlist_remove_all(props, ZPOOL_ROOTFS_PROPS);
9508660f9c27 PSARC 2008/223 Pool root file system properties via zpool(1M)
timh
parents: 7046
diff changeset
   781
		}
9508660f9c27 PSARC 2008/223 Pool root file system properties via zpool(1M)
timh
parents: 7046
diff changeset
   782
		VERIFY(nvlist_alloc(&zplprops, NV_UNIQUE_NAME, KM_SLEEP) == 0);
9508660f9c27 PSARC 2008/223 Pool root file system properties via zpool(1M)
timh
parents: 7046
diff changeset
   783
		error = zfs_fill_zplprops_root(version, rootprops,
9508660f9c27 PSARC 2008/223 Pool root file system properties via zpool(1M)
timh
parents: 7046
diff changeset
   784
		    zplprops, NULL);
9508660f9c27 PSARC 2008/223 Pool root file system properties via zpool(1M)
timh
parents: 7046
diff changeset
   785
		if (error)
9508660f9c27 PSARC 2008/223 Pool root file system properties via zpool(1M)
timh
parents: 7046
diff changeset
   786
			goto pool_props_bad;
9508660f9c27 PSARC 2008/223 Pool root file system properties via zpool(1M)
timh
parents: 7046
diff changeset
   787
	}
9508660f9c27 PSARC 2008/223 Pool root file system properties via zpool(1M)
timh
parents: 7046
diff changeset
   788
4988
db8abd9846d4 6595467 libzfs consumers should be allowed to write their own history (or none at all)
ek110237
parents: 4849
diff changeset
   789
	buf = history_str_get(zc);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   790
7184
9508660f9c27 PSARC 2008/223 Pool root file system properties via zpool(1M)
timh
parents: 7046
diff changeset
   791
	error = spa_create(zc->zc_name, config, props, buf, zplprops);
9508660f9c27 PSARC 2008/223 Pool root file system properties via zpool(1M)
timh
parents: 7046
diff changeset
   792
9508660f9c27 PSARC 2008/223 Pool root file system properties via zpool(1M)
timh
parents: 7046
diff changeset
   793
	/*
9508660f9c27 PSARC 2008/223 Pool root file system properties via zpool(1M)
timh
parents: 7046
diff changeset
   794
	 * Set the remaining root properties
9508660f9c27 PSARC 2008/223 Pool root file system properties via zpool(1M)
timh
parents: 7046
diff changeset
   795
	 */
9508660f9c27 PSARC 2008/223 Pool root file system properties via zpool(1M)
timh
parents: 7046
diff changeset
   796
	if (!error &&
9508660f9c27 PSARC 2008/223 Pool root file system properties via zpool(1M)
timh
parents: 7046
diff changeset
   797
	    (error = zfs_set_prop_nvlist(zc->zc_name, rootprops)) != 0)
9508660f9c27 PSARC 2008/223 Pool root file system properties via zpool(1M)
timh
parents: 7046
diff changeset
   798
		(void) spa_destroy(zc->zc_name);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   799
4988
db8abd9846d4 6595467 libzfs consumers should be allowed to write their own history (or none at all)
ek110237
parents: 4849
diff changeset
   800
	if (buf != NULL)
db8abd9846d4 6595467 libzfs consumers should be allowed to write their own history (or none at all)
ek110237
parents: 4849
diff changeset
   801
		history_str_free(buf);
5094
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
   802
7184
9508660f9c27 PSARC 2008/223 Pool root file system properties via zpool(1M)
timh
parents: 7046
diff changeset
   803
pool_props_bad:
9508660f9c27 PSARC 2008/223 Pool root file system properties via zpool(1M)
timh
parents: 7046
diff changeset
   804
	nvlist_free(rootprops);
9508660f9c27 PSARC 2008/223 Pool root file system properties via zpool(1M)
timh
parents: 7046
diff changeset
   805
	nvlist_free(zplprops);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   806
	nvlist_free(config);
7184
9508660f9c27 PSARC 2008/223 Pool root file system properties via zpool(1M)
timh
parents: 7046
diff changeset
   807
	nvlist_free(props);
5094
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
   808
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   809
	return (error);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   810
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   811
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   812
static int
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   813
zfs_ioc_pool_destroy(zfs_cmd_t *zc)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   814
{
4543
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   815
	int error;
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   816
	zfs_log_history(zc);
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   817
	error = spa_destroy(zc->zc_name);
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   818
	return (error);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   819
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   820
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   821
static int
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   822
zfs_ioc_pool_import(zfs_cmd_t *zc)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   823
{
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   824
	int error;
5094
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
   825
	nvlist_t *config, *props = NULL;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   826
	uint64_t guid;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   827
5094
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
   828
	if ((error = get_nvlist(zc->zc_nvlist_conf, zc->zc_nvlist_conf_size,
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
   829
	    &config)) != 0)
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   830
		return (error);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   831
5094
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
   832
	if (zc->zc_nvlist_src_size != 0 && (error =
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
   833
	    get_nvlist(zc->zc_nvlist_src, zc->zc_nvlist_src_size, &props))) {
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
   834
		nvlist_free(config);
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
   835
		return (error);
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
   836
	}
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
   837
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   838
	if (nvlist_lookup_uint64(config, ZPOOL_CONFIG_POOL_GUID, &guid) != 0 ||
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
   839
	    guid != zc->zc_guid)
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   840
		error = EINVAL;
6643
3a34b0dbb107 6625086 changing cachefile doesn't remove old cache on last user
eschrock
parents: 6492
diff changeset
   841
	else if (zc->zc_cookie)
3a34b0dbb107 6625086 changing cachefile doesn't remove old cache on last user
eschrock
parents: 6492
diff changeset
   842
		error = spa_import_faulted(zc->zc_name, config,
3a34b0dbb107 6625086 changing cachefile doesn't remove old cache on last user
eschrock
parents: 6492
diff changeset
   843
		    props);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   844
	else
5094
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
   845
		error = spa_import(zc->zc_name, config, props);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   846
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   847
	nvlist_free(config);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   848
5094
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
   849
	if (props)
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
   850
		nvlist_free(props);
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
   851
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   852
	return (error);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   853
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   854
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   855
static int
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   856
zfs_ioc_pool_export(zfs_cmd_t *zc)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   857
{
4543
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   858
	int error;
7214
04c540040a32 6721908 A hot spare "in use" in an exported zpool, is stolen when a disk fails in an imported pool.
lling
parents: 7184
diff changeset
   859
	boolean_t force = (boolean_t)zc->zc_cookie;
04c540040a32 6721908 A hot spare "in use" in an exported zpool, is stolen when a disk fails in an imported pool.
lling
parents: 7184
diff changeset
   860
4543
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   861
	zfs_log_history(zc);
7214
04c540040a32 6721908 A hot spare "in use" in an exported zpool, is stolen when a disk fails in an imported pool.
lling
parents: 7184
diff changeset
   862
	error = spa_export(zc->zc_name, NULL, force);
4543
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   863
	return (error);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   864
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   865
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   866
static int
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   867
zfs_ioc_pool_configs(zfs_cmd_t *zc)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   868
{
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   869
	nvlist_t *configs;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   870
	int error;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   871
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   872
	if ((configs = spa_all_configs(&zc->zc_cookie)) == NULL)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   873
		return (EEXIST);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   874
2676
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
   875
	error = put_nvlist(zc, configs);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   876
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   877
	nvlist_free(configs);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   878
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   879
	return (error);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   880
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   881
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   882
static int
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   883
zfs_ioc_pool_stats(zfs_cmd_t *zc)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   884
{
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   885
	nvlist_t *config;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   886
	int error;
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
   887
	int ret = 0;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   888
2676
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
   889
	error = spa_get_stats(zc->zc_name, &config, zc->zc_value,
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
   890
	    sizeof (zc->zc_value));
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   891
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   892
	if (config != NULL) {
2676
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
   893
		ret = put_nvlist(zc, config);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   894
		nvlist_free(config);
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
   895
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
   896
		/*
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
   897
		 * The config may be present even if 'error' is non-zero.
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
   898
		 * In this case we return success, and preserve the real errno
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
   899
		 * in 'zc_cookie'.
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
   900
		 */
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
   901
		zc->zc_cookie = error;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   902
	} else {
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
   903
		ret = error;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   904
	}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   905
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
   906
	return (ret);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   907
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   908
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   909
/*
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   910
 * Try to import the given pool, returning pool stats as appropriate so that
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   911
 * user land knows which devices are available and overall pool health.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   912
 */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   913
static int
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   914
zfs_ioc_pool_tryimport(zfs_cmd_t *zc)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   915
{
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   916
	nvlist_t *tryconfig, *config;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   917
	int error;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   918
5094
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
   919
	if ((error = get_nvlist(zc->zc_nvlist_conf, zc->zc_nvlist_conf_size,
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
   920
	    &tryconfig)) != 0)
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   921
		return (error);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   922
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   923
	config = spa_tryimport(tryconfig);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   924
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   925
	nvlist_free(tryconfig);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   926
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   927
	if (config == NULL)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   928
		return (EINVAL);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   929
2676
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
   930
	error = put_nvlist(zc, config);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   931
	nvlist_free(config);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   932
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   933
	return (error);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   934
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   935
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   936
static int
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   937
zfs_ioc_pool_scrub(zfs_cmd_t *zc)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   938
{
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   939
	spa_t *spa;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   940
	int error;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   941
2926
acfcfefbc60d PSARC 2006/288 zpool history
ek110237
parents: 2885
diff changeset
   942
	if ((error = spa_open(zc->zc_name, &spa, FTAG)) != 0)
acfcfefbc60d PSARC 2006/288 zpool history
ek110237
parents: 2885
diff changeset
   943
		return (error);
acfcfefbc60d PSARC 2006/288 zpool history
ek110237
parents: 2885
diff changeset
   944
7046
361307ae060d 6343667 scrub/resilver has to start over when a snapshot is taken
ahrens
parents: 7042
diff changeset
   945
	error = spa_scrub(spa, zc->zc_cookie);
2926
acfcfefbc60d PSARC 2006/288 zpool history
ek110237
parents: 2885
diff changeset
   946
acfcfefbc60d PSARC 2006/288 zpool history
ek110237
parents: 2885
diff changeset
   947
	spa_close(spa, FTAG);
acfcfefbc60d PSARC 2006/288 zpool history
ek110237
parents: 2885
diff changeset
   948
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   949
	return (error);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   950
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   951
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   952
static int
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   953
zfs_ioc_pool_freeze(zfs_cmd_t *zc)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   954
{
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   955
	spa_t *spa;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   956
	int error;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   957
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   958
	error = spa_open(zc->zc_name, &spa, FTAG);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   959
	if (error == 0) {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   960
		spa_freeze(spa);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   961
		spa_close(spa, FTAG);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   962
	}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   963
	return (error);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   964
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   965
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   966
static int
1760
e1ad2821c30d PSARC 2006/206 zpool upgrade
eschrock
parents: 1544
diff changeset
   967
zfs_ioc_pool_upgrade(zfs_cmd_t *zc)
e1ad2821c30d PSARC 2006/206 zpool upgrade
eschrock
parents: 1544
diff changeset
   968
{
e1ad2821c30d PSARC 2006/206 zpool upgrade
eschrock
parents: 1544
diff changeset
   969
	spa_t *spa;
e1ad2821c30d PSARC 2006/206 zpool upgrade
eschrock
parents: 1544
diff changeset
   970
	int error;
e1ad2821c30d PSARC 2006/206 zpool upgrade
eschrock
parents: 1544
diff changeset
   971
2926
acfcfefbc60d PSARC 2006/288 zpool history
ek110237
parents: 2885
diff changeset
   972
	if ((error = spa_open(zc->zc_name, &spa, FTAG)) != 0)
acfcfefbc60d PSARC 2006/288 zpool history
ek110237
parents: 2885
diff changeset
   973
		return (error);
acfcfefbc60d PSARC 2006/288 zpool history
ek110237
parents: 2885
diff changeset
   974
5118
c723b1aa9f79 6607671 Able to zpool upgrade a pool to an unknown version number
lling
parents: 5094
diff changeset
   975
	if (zc->zc_cookie < spa_version(spa) || zc->zc_cookie > SPA_VERSION) {
c723b1aa9f79 6607671 Able to zpool upgrade a pool to an unknown version number
lling
parents: 5094
diff changeset
   976
		spa_close(spa, FTAG);
c723b1aa9f79 6607671 Able to zpool upgrade a pool to an unknown version number
lling
parents: 5094
diff changeset
   977
		return (EINVAL);
c723b1aa9f79 6607671 Able to zpool upgrade a pool to an unknown version number
lling
parents: 5094
diff changeset
   978
	}
c723b1aa9f79 6607671 Able to zpool upgrade a pool to an unknown version number
lling
parents: 5094
diff changeset
   979
5094
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
   980
	spa_upgrade(spa, zc->zc_cookie);
2926
acfcfefbc60d PSARC 2006/288 zpool history
ek110237
parents: 2885
diff changeset
   981
	spa_close(spa, FTAG);
acfcfefbc60d PSARC 2006/288 zpool history
ek110237
parents: 2885
diff changeset
   982
acfcfefbc60d PSARC 2006/288 zpool history
ek110237
parents: 2885
diff changeset
   983
	return (error);
acfcfefbc60d PSARC 2006/288 zpool history
ek110237
parents: 2885
diff changeset
   984
}
acfcfefbc60d PSARC 2006/288 zpool history
ek110237
parents: 2885
diff changeset
   985
acfcfefbc60d PSARC 2006/288 zpool history
ek110237
parents: 2885
diff changeset
   986
static int
acfcfefbc60d PSARC 2006/288 zpool history
ek110237
parents: 2885
diff changeset
   987
zfs_ioc_pool_get_history(zfs_cmd_t *zc)
acfcfefbc60d PSARC 2006/288 zpool history
ek110237
parents: 2885
diff changeset
   988
{
acfcfefbc60d PSARC 2006/288 zpool history
ek110237
parents: 2885
diff changeset
   989
	spa_t *spa;
acfcfefbc60d PSARC 2006/288 zpool history
ek110237
parents: 2885
diff changeset
   990
	char *hist_buf;
acfcfefbc60d PSARC 2006/288 zpool history
ek110237
parents: 2885
diff changeset
   991
	uint64_t size;
acfcfefbc60d PSARC 2006/288 zpool history
ek110237
parents: 2885
diff changeset
   992
	int error;
acfcfefbc60d PSARC 2006/288 zpool history
ek110237
parents: 2885
diff changeset
   993
acfcfefbc60d PSARC 2006/288 zpool history
ek110237
parents: 2885
diff changeset
   994
	if ((size = zc->zc_history_len) == 0)
acfcfefbc60d PSARC 2006/288 zpool history
ek110237
parents: 2885
diff changeset
   995
		return (EINVAL);
acfcfefbc60d PSARC 2006/288 zpool history
ek110237
parents: 2885
diff changeset
   996
acfcfefbc60d PSARC 2006/288 zpool history
ek110237
parents: 2885
diff changeset
   997
	if ((error = spa_open(zc->zc_name, &spa, FTAG)) != 0)
acfcfefbc60d PSARC 2006/288 zpool history
ek110237
parents: 2885
diff changeset
   998
		return (error);
acfcfefbc60d PSARC 2006/288 zpool history
ek110237
parents: 2885
diff changeset
   999
4577
ed36b0e652bc PSARC/2007/328 zfs upgrade
ahrens
parents: 4543
diff changeset
  1000
	if (spa_version(spa) < SPA_VERSION_ZPOOL_HISTORY) {
3863
d56571426115 6529406 zpool history needs to bump the on-disk version
ek110237
parents: 3741
diff changeset
  1001
		spa_close(spa, FTAG);
d56571426115 6529406 zpool history needs to bump the on-disk version
ek110237
parents: 3741
diff changeset
  1002
		return (ENOTSUP);
d56571426115 6529406 zpool history needs to bump the on-disk version
ek110237
parents: 3741
diff changeset
  1003
	}
d56571426115 6529406 zpool history needs to bump the on-disk version
ek110237
parents: 3741
diff changeset
  1004
2926
acfcfefbc60d PSARC 2006/288 zpool history
ek110237
parents: 2885
diff changeset
  1005
	hist_buf = kmem_alloc(size, KM_SLEEP);
acfcfefbc60d PSARC 2006/288 zpool history
ek110237
parents: 2885
diff changeset
  1006
	if ((error = spa_history_get(spa, &zc->zc_history_offset,
acfcfefbc60d PSARC 2006/288 zpool history
ek110237
parents: 2885
diff changeset
  1007
	    &zc->zc_history_len, hist_buf)) == 0) {
4543
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  1008
		error = xcopyout(hist_buf,
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  1009
		    (char *)(uintptr_t)zc->zc_history,
2926
acfcfefbc60d PSARC 2006/288 zpool history
ek110237
parents: 2885
diff changeset
  1010
		    zc->zc_history_len);
acfcfefbc60d PSARC 2006/288 zpool history
ek110237
parents: 2885
diff changeset
  1011
	}
acfcfefbc60d PSARC 2006/288 zpool history
ek110237
parents: 2885
diff changeset
  1012
acfcfefbc60d PSARC 2006/288 zpool history
ek110237
parents: 2885
diff changeset
  1013
	spa_close(spa, FTAG);
acfcfefbc60d PSARC 2006/288 zpool history
ek110237
parents: 2885
diff changeset
  1014
	kmem_free(hist_buf, size);
acfcfefbc60d PSARC 2006/288 zpool history
ek110237
parents: 2885
diff changeset
  1015
	return (error);
acfcfefbc60d PSARC 2006/288 zpool history
ek110237
parents: 2885
diff changeset
  1016
}
acfcfefbc60d PSARC 2006/288 zpool history
ek110237
parents: 2885
diff changeset
  1017
acfcfefbc60d PSARC 2006/288 zpool history
ek110237
parents: 2885
diff changeset
  1018
static int
3444
dc160a70a50d 6410433 'zpool status -v' would be more useful with filenames
ek110237
parents: 3265
diff changeset
  1019
zfs_ioc_dsobj_to_dsname(zfs_cmd_t *zc)
dc160a70a50d 6410433 'zpool status -v' would be more useful with filenames
ek110237
parents: 3265
diff changeset
  1020
{
dc160a70a50d 6410433 'zpool status -v' would be more useful with filenames
ek110237
parents: 3265
diff changeset
  1021
	int error;
dc160a70a50d 6410433 'zpool status -v' would be more useful with filenames
ek110237
parents: 3265
diff changeset
  1022
3912
f6891a60bd72 PSARC 2007/083 ZFS bootable datasets
lling
parents: 3886
diff changeset
  1023
	if (error = dsl_dsobj_to_dsname(zc->zc_name, zc->zc_obj, zc->zc_value))
3444
dc160a70a50d 6410433 'zpool status -v' would be more useful with filenames
ek110237
parents: 3265
diff changeset
  1024
		return (error);
dc160a70a50d 6410433 'zpool status -v' would be more useful with filenames
ek110237
parents: 3265
diff changeset
  1025
dc160a70a50d 6410433 'zpool status -v' would be more useful with filenames
ek110237
parents: 3265
diff changeset
  1026
	return (0);
dc160a70a50d 6410433 'zpool status -v' would be more useful with filenames
ek110237
parents: 3265
diff changeset
  1027
}
dc160a70a50d 6410433 'zpool status -v' would be more useful with filenames
ek110237
parents: 3265
diff changeset
  1028
dc160a70a50d 6410433 'zpool status -v' would be more useful with filenames
ek110237
parents: 3265
diff changeset
  1029
static int
dc160a70a50d 6410433 'zpool status -v' would be more useful with filenames
ek110237
parents: 3265
diff changeset
  1030
zfs_ioc_obj_to_path(zfs_cmd_t *zc)
dc160a70a50d 6410433 'zpool status -v' would be more useful with filenames
ek110237
parents: 3265
diff changeset
  1031
{
dc160a70a50d 6410433 'zpool status -v' would be more useful with filenames
ek110237
parents: 3265
diff changeset
  1032
	objset_t *osp;
dc160a70a50d 6410433 'zpool status -v' would be more useful with filenames
ek110237
parents: 3265
diff changeset
  1033
	int error;
dc160a70a50d 6410433 'zpool status -v' would be more useful with filenames
ek110237
parents: 3265
diff changeset
  1034
dc160a70a50d 6410433 'zpool status -v' would be more useful with filenames
ek110237
parents: 3265
diff changeset
  1035
	if ((error = dmu_objset_open(zc->zc_name, DMU_OST_ZFS,
6689
47572a2f5e73 6610506 Eliminate or improve retry logic from callers of dmu_objset_open()
maybee
parents: 6643
diff changeset
  1036
	    DS_MODE_USER | DS_MODE_READONLY, &osp)) != 0)
3444
dc160a70a50d 6410433 'zpool status -v' would be more useful with filenames
ek110237
parents: 3265
diff changeset
  1037
		return (error);
dc160a70a50d 6410433 'zpool status -v' would be more useful with filenames
ek110237
parents: 3265
diff changeset
  1038
	error = zfs_obj_to_path(osp, zc->zc_obj, zc->zc_value,
dc160a70a50d 6410433 'zpool status -v' would be more useful with filenames
ek110237
parents: 3265
diff changeset
  1039
	    sizeof (zc->zc_value));
dc160a70a50d 6410433 'zpool status -v' would be more useful with filenames
ek110237
parents: 3265
diff changeset
  1040
	dmu_objset_close(osp);
dc160a70a50d 6410433 'zpool status -v' would be more useful with filenames
ek110237
parents: 3265
diff changeset
  1041
dc160a70a50d 6410433 'zpool status -v' would be more useful with filenames
ek110237
parents: 3265
diff changeset
  1042
	return (error);
dc160a70a50d 6410433 'zpool status -v' would be more useful with filenames
ek110237
parents: 3265
diff changeset
  1043
}
dc160a70a50d 6410433 'zpool status -v' would be more useful with filenames
ek110237
parents: 3265
diff changeset
  1044
dc160a70a50d 6410433 'zpool status -v' would be more useful with filenames
ek110237
parents: 3265
diff changeset
  1045
static int
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1046
zfs_ioc_vdev_add(zfs_cmd_t *zc)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1047
{
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1048
	spa_t *spa;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1049
	int error;
6423
437422a29d3a PSARC 2006/370 ZFS Boot Support
gw25295
parents: 6139
diff changeset
  1050
	nvlist_t *config, **l2cache, **spares;
437422a29d3a PSARC 2006/370 ZFS Boot Support
gw25295
parents: 6139
diff changeset
  1051
	uint_t nl2cache = 0, nspares = 0;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1052
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1053
	error = spa_open(zc->zc_name, &spa, FTAG);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1054
	if (error != 0)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1055
		return (error);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1056
5450
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5446
diff changeset
  1057
	error = get_nvlist(zc->zc_nvlist_conf, zc->zc_nvlist_conf_size,
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5446
diff changeset
  1058
	    &config);
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5446
diff changeset
  1059
	(void) nvlist_lookup_nvlist_array(config, ZPOOL_CONFIG_L2CACHE,
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5446
diff changeset
  1060
	    &l2cache, &nl2cache);
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5446
diff changeset
  1061
6423
437422a29d3a PSARC 2006/370 ZFS Boot Support
gw25295
parents: 6139
diff changeset
  1062
	(void) nvlist_lookup_nvlist_array(config, ZPOOL_CONFIG_SPARES,
437422a29d3a PSARC 2006/370 ZFS Boot Support
gw25295
parents: 6139
diff changeset
  1063
	    &spares, &nspares);
437422a29d3a PSARC 2006/370 ZFS Boot Support
gw25295
parents: 6139
diff changeset
  1064
3912
f6891a60bd72 PSARC 2007/083 ZFS bootable datasets
lling
parents: 3886
diff changeset
  1065
	/*
f6891a60bd72 PSARC 2007/083 ZFS bootable datasets
lling
parents: 3886
diff changeset
  1066
	 * A root pool with concatenated devices is not supported.
6423
437422a29d3a PSARC 2006/370 ZFS Boot Support
gw25295
parents: 6139
diff changeset
  1067
	 * Thus, can not add a device to a root pool.
437422a29d3a PSARC 2006/370 ZFS Boot Support
gw25295
parents: 6139
diff changeset
  1068
	 *
437422a29d3a PSARC 2006/370 ZFS Boot Support
gw25295
parents: 6139
diff changeset
  1069
	 * Intent log device can not be added to a rootpool because
437422a29d3a PSARC 2006/370 ZFS Boot Support
gw25295
parents: 6139
diff changeset
  1070
	 * during mountroot, zil is replayed, a seperated log device
437422a29d3a PSARC 2006/370 ZFS Boot Support
gw25295
parents: 6139
diff changeset
  1071
	 * can not be accessed during the mountroot time.
437422a29d3a PSARC 2006/370 ZFS Boot Support
gw25295
parents: 6139
diff changeset
  1072
	 *
437422a29d3a PSARC 2006/370 ZFS Boot Support
gw25295
parents: 6139
diff changeset
  1073
	 * l2cache and spare devices are ok to be added to a rootpool.
3912
f6891a60bd72 PSARC 2007/083 ZFS bootable datasets
lling
parents: 3886
diff changeset
  1074
	 */
6423
437422a29d3a PSARC 2006/370 ZFS Boot Support
gw25295
parents: 6139
diff changeset
  1075
	if (spa->spa_bootfs != 0 && nl2cache == 0 && nspares == 0) {
3912
f6891a60bd72 PSARC 2007/083 ZFS bootable datasets
lling
parents: 3886
diff changeset
  1076
		spa_close(spa, FTAG);
f6891a60bd72 PSARC 2007/083 ZFS bootable datasets
lling
parents: 3886
diff changeset
  1077
		return (EDOM);
f6891a60bd72 PSARC 2007/083 ZFS bootable datasets
lling
parents: 3886
diff changeset
  1078
	}
f6891a60bd72 PSARC 2007/083 ZFS bootable datasets
lling
parents: 3886
diff changeset
  1079
5450
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5446
diff changeset
  1080
	if (error == 0) {
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1081
		error = spa_vdev_add(spa, config);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1082
		nvlist_free(config);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1083
	}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1084
	spa_close(spa, FTAG);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1085
	return (error);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1086
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1087
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1088
static int
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1089
zfs_ioc_vdev_remove(zfs_cmd_t *zc)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1090
{
2082
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1775
diff changeset
  1091
	spa_t *spa;
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1775
diff changeset
  1092
	int error;
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1775
diff changeset
  1093
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1775
diff changeset
  1094
	error = spa_open(zc->zc_name, &spa, FTAG);
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1775
diff changeset
  1095
	if (error != 0)
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1775
diff changeset
  1096
		return (error);
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1775
diff changeset
  1097
	error = spa_vdev_remove(spa, zc->zc_guid, B_FALSE);
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1775
diff changeset
  1098
	spa_close(spa, FTAG);
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1775
diff changeset
  1099
	return (error);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1100
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1101
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1102
static int
4451
24fbf2d7a5d7 PSARC 2007/197 ZFS hotplug
eschrock
parents: 4098
diff changeset
  1103
zfs_ioc_vdev_set_state(zfs_cmd_t *zc)
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1104
{
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1105
	spa_t *spa;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1106
	int error;
4451
24fbf2d7a5d7 PSARC 2007/197 ZFS hotplug
eschrock
parents: 4098
diff changeset
  1107
	vdev_state_t newstate = VDEV_STATE_UNKNOWN;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1108
2926
acfcfefbc60d PSARC 2006/288 zpool history
ek110237
parents: 2885
diff changeset
  1109
	if ((error = spa_open(zc->zc_name, &spa, FTAG)) != 0)
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1110
		return (error);
4451
24fbf2d7a5d7 PSARC 2007/197 ZFS hotplug
eschrock
parents: 4098
diff changeset
  1111
	switch (zc->zc_cookie) {
24fbf2d7a5d7 PSARC 2007/197 ZFS hotplug
eschrock
parents: 4098
diff changeset
  1112
	case VDEV_STATE_ONLINE:
24fbf2d7a5d7 PSARC 2007/197 ZFS hotplug
eschrock
parents: 4098
diff changeset
  1113
		error = vdev_online(spa, zc->zc_guid, zc->zc_obj, &newstate);
24fbf2d7a5d7 PSARC 2007/197 ZFS hotplug
eschrock
parents: 4098
diff changeset
  1114
		break;
24fbf2d7a5d7 PSARC 2007/197 ZFS hotplug
eschrock
parents: 4098
diff changeset
  1115
24fbf2d7a5d7 PSARC 2007/197 ZFS hotplug
eschrock
parents: 4098
diff changeset
  1116
	case VDEV_STATE_OFFLINE:
24fbf2d7a5d7 PSARC 2007/197 ZFS hotplug
eschrock
parents: 4098
diff changeset
  1117
		error = vdev_offline(spa, zc->zc_guid, zc->zc_obj);
24fbf2d7a5d7 PSARC 2007/197 ZFS hotplug
eschrock
parents: 4098
diff changeset
  1118
		break;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1119
4451
24fbf2d7a5d7 PSARC 2007/197 ZFS hotplug
eschrock
parents: 4098
diff changeset
  1120
	case VDEV_STATE_FAULTED:
24fbf2d7a5d7 PSARC 2007/197 ZFS hotplug
eschrock
parents: 4098
diff changeset
  1121
		error = vdev_fault(spa, zc->zc_guid);
24fbf2d7a5d7 PSARC 2007/197 ZFS hotplug
eschrock
parents: 4098
diff changeset
  1122
		break;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1123
4451
24fbf2d7a5d7 PSARC 2007/197 ZFS hotplug
eschrock
parents: 4098
diff changeset
  1124
	case VDEV_STATE_DEGRADED:
24fbf2d7a5d7 PSARC 2007/197 ZFS hotplug
eschrock
parents: 4098
diff changeset
  1125
		error = vdev_degrade(spa, zc->zc_guid);
24fbf2d7a5d7 PSARC 2007/197 ZFS hotplug
eschrock
parents: 4098
diff changeset
  1126
		break;
24fbf2d7a5d7 PSARC 2007/197 ZFS hotplug
eschrock
parents: 4098
diff changeset
  1127
24fbf2d7a5d7 PSARC 2007/197 ZFS hotplug
eschrock
parents: 4098
diff changeset
  1128
	default:
24fbf2d7a5d7 PSARC 2007/197 ZFS hotplug
eschrock
parents: 4098
diff changeset
  1129
		error = EINVAL;
24fbf2d7a5d7 PSARC 2007/197 ZFS hotplug
eschrock
parents: 4098
diff changeset
  1130
	}
24fbf2d7a5d7 PSARC 2007/197 ZFS hotplug
eschrock
parents: 4098
diff changeset
  1131
	zc->zc_cookie = newstate;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1132
	spa_close(spa, FTAG);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1133
	return (error);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1134
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1135
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1136
static int
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1137
zfs_ioc_vdev_attach(zfs_cmd_t *zc)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1138
{
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1139
	spa_t *spa;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1140
	int replacing = zc->zc_cookie;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1141
	nvlist_t *config;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1142
	int error;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1143
2926
acfcfefbc60d PSARC 2006/288 zpool history
ek110237
parents: 2885
diff changeset
  1144
	if ((error = spa_open(zc->zc_name, &spa, FTAG)) != 0)
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1145
		return (error);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1146
5094
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
  1147
	if ((error = get_nvlist(zc->zc_nvlist_conf, zc->zc_nvlist_conf_size,
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
  1148
	    &config)) == 0) {
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
  1149
		error = spa_vdev_attach(spa, zc->zc_guid, config, replacing);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1150
		nvlist_free(config);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1151
	}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1152
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1153
	spa_close(spa, FTAG);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1154
	return (error);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1155
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1156
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1157
static int
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1158
zfs_ioc_vdev_detach(zfs_cmd_t *zc)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1159
{
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1160
	spa_t *spa;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1161
	int error;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1162
2926
acfcfefbc60d PSARC 2006/288 zpool history
ek110237
parents: 2885
diff changeset
  1163
	if ((error = spa_open(zc->zc_name, &spa, FTAG)) != 0)
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1164
		return (error);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1165
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
  1166
	error = spa_vdev_detach(spa, zc->zc_guid, B_FALSE);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1167
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1168
	spa_close(spa, FTAG);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1169
	return (error);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1170
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1171
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1172
static int
1354
81359ee1ee63 6362672 import gets confused about overlapping slices
eschrock
parents: 1133
diff changeset
  1173
zfs_ioc_vdev_setpath(zfs_cmd_t *zc)
81359ee1ee63 6362672 import gets confused about overlapping slices
eschrock
parents: 1133
diff changeset
  1174
{
81359ee1ee63 6362672 import gets confused about overlapping slices
eschrock
parents: 1133
diff changeset
  1175
	spa_t *spa;
2676
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  1176
	char *path = zc->zc_value;
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
  1177
	uint64_t guid = zc->zc_guid;
1354
81359ee1ee63 6362672 import gets confused about overlapping slices
eschrock
parents: 1133
diff changeset
  1178
	int error;
81359ee1ee63 6362672 import gets confused about overlapping slices
eschrock
parents: 1133
diff changeset
  1179
81359ee1ee63 6362672 import gets confused about overlapping slices
eschrock
parents: 1133
diff changeset
  1180
	error = spa_open(zc->zc_name, &spa, FTAG);
81359ee1ee63 6362672 import gets confused about overlapping slices
eschrock
parents: 1133
diff changeset
  1181
	if (error != 0)
81359ee1ee63 6362672 import gets confused about overlapping slices
eschrock
parents: 1133
diff changeset
  1182
		return (error);
81359ee1ee63 6362672 import gets confused about overlapping slices
eschrock
parents: 1133
diff changeset
  1183
81359ee1ee63 6362672 import gets confused about overlapping slices
eschrock
parents: 1133
diff changeset
  1184
	error = spa_vdev_setpath(spa, guid, path);
81359ee1ee63 6362672 import gets confused about overlapping slices
eschrock
parents: 1133
diff changeset
  1185
	spa_close(spa, FTAG);
81359ee1ee63 6362672 import gets confused about overlapping slices
eschrock
parents: 1133
diff changeset
  1186
	return (error);
81359ee1ee63 6362672 import gets confused about overlapping slices
eschrock
parents: 1133
diff changeset
  1187
}
81359ee1ee63 6362672 import gets confused about overlapping slices
eschrock
parents: 1133
diff changeset
  1188
5367
c40abbe796be PSARC/2007/574 zfs send -R
ahrens
parents: 5331
diff changeset
  1189
/*
c40abbe796be PSARC/2007/574 zfs send -R
ahrens
parents: 5331
diff changeset
  1190
 * inputs:
c40abbe796be PSARC/2007/574 zfs send -R
ahrens
parents: 5331
diff changeset
  1191
 * zc_name		name of filesystem
c40abbe796be PSARC/2007/574 zfs send -R
ahrens
parents: 5331
diff changeset
  1192
 * zc_nvlist_dst_size	size of buffer for property nvlist
c40abbe796be PSARC/2007/574 zfs send -R
ahrens
parents: 5331
diff changeset
  1193
 *
c40abbe796be PSARC/2007/574 zfs send -R
ahrens
parents: 5331
diff changeset
  1194
 * outputs:
c40abbe796be PSARC/2007/574 zfs send -R
ahrens
parents: 5331
diff changeset
  1195
 * zc_objset_stats	stats
c40abbe796be PSARC/2007/574 zfs send -R
ahrens
parents: 5331
diff changeset
  1196
 * zc_nvlist_dst	property nvlist
c40abbe796be PSARC/2007/574 zfs send -R
ahrens
parents: 5331
diff changeset
  1197
 * zc_nvlist_dst_size	size of property nvlist
c40abbe796be PSARC/2007/574 zfs send -R
ahrens
parents: 5331
diff changeset
  1198
 */
1354
81359ee1ee63 6362672 import gets confused about overlapping slices
eschrock
parents: 1133
diff changeset
  1199
static int
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1200
zfs_ioc_objset_stats(zfs_cmd_t *zc)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1201
{
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1202
	objset_t *os = NULL;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1203
	int error;
1356
e021b5e4aa0e 6377671 zfs mount -a shouldn't bother checking snapshots
eschrock
parents: 1354
diff changeset
  1204
	nvlist_t *nv;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1205
6689
47572a2f5e73 6610506 Eliminate or improve retry logic from callers of dmu_objset_open()
maybee
parents: 6643
diff changeset
  1206
	if (error = dmu_objset_open(zc->zc_name,
47572a2f5e73 6610506 Eliminate or improve retry logic from callers of dmu_objset_open()
maybee
parents: 6643
diff changeset
  1207
	    DMU_OST_ANY, DS_MODE_USER | DS_MODE_READONLY, &os))
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1208
		return (error);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1209
2885
c0259887ebbc 6460059 zfs destroy <snapshot> leaves behind kruft
ahrens
parents: 2856
diff changeset
  1210
	dmu_objset_fast_stat(os, &zc->zc_objset_stats);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1211
2856
6f4d5ee1906a 6463348 ZFS code could be more portable
nd150628
parents: 2717
diff changeset
  1212
	if (zc->zc_nvlist_dst != 0 &&
6689
47572a2f5e73 6610506 Eliminate or improve retry logic from callers of dmu_objset_open()
maybee
parents: 6643
diff changeset
  1213
	    (error = dsl_prop_get_all(os, &nv, FALSE)) == 0) {
2885
c0259887ebbc 6460059 zfs destroy <snapshot> leaves behind kruft
ahrens
parents: 2856
diff changeset
  1214
		dmu_objset_stats(os, nv);
3087
62df4acfd5cb 6468748 assertion failure in dnode_sync
ahrens
parents: 2926
diff changeset
  1215
		/*
5147
5e950ccc9585 6596190 "zfs list" is slow due to version property
rm160521
parents: 5118
diff changeset
  1216
		 * NB: zvol_get_stats() will read the objset contents,
3087
62df4acfd5cb 6468748 assertion failure in dnode_sync
ahrens
parents: 2926
diff changeset
  1217
		 * which we aren't supposed to do with a
6689
47572a2f5e73 6610506 Eliminate or improve retry logic from callers of dmu_objset_open()
maybee
parents: 6643
diff changeset
  1218
		 * DS_MODE_USER hold, because it could be
3087
62df4acfd5cb 6468748 assertion failure in dnode_sync
ahrens
parents: 2926
diff changeset
  1219
		 * inconsistent.  So this is a bit of a workaround...
62df4acfd5cb 6468748 assertion failure in dnode_sync
ahrens
parents: 2926
diff changeset
  1220
		 */
4577
ed36b0e652bc PSARC/2007/328 zfs upgrade
ahrens
parents: 4543
diff changeset
  1221
		if (!zc->zc_objset_stats.dds_inconsistent) {
ed36b0e652bc PSARC/2007/328 zfs upgrade
ahrens
parents: 4543
diff changeset
  1222
			if (dmu_objset_type(os) == DMU_OST_ZVOL)
ed36b0e652bc PSARC/2007/328 zfs upgrade
ahrens
parents: 4543
diff changeset
  1223
				VERIFY(zvol_get_stats(os, nv) == 0);
ed36b0e652bc PSARC/2007/328 zfs upgrade
ahrens
parents: 4543
diff changeset
  1224
		}
2676
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  1225
		error = put_nvlist(zc, nv);
1356
e021b5e4aa0e 6377671 zfs mount -a shouldn't bother checking snapshots
eschrock
parents: 1354
diff changeset
  1226
		nvlist_free(nv);
e021b5e4aa0e 6377671 zfs mount -a shouldn't bother checking snapshots
eschrock
parents: 1354
diff changeset
  1227
	}
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1228
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1229
	dmu_objset_close(os);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1230
	return (error);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1231
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1232
5498
334b476844ca 6622831 normalization properties are not preserved by "zfs send"
timh
parents: 5450
diff changeset
  1233
static int
334b476844ca 6622831 normalization properties are not preserved by "zfs send"
timh
parents: 5450
diff changeset
  1234
nvl_add_zplprop(objset_t *os, nvlist_t *props, zfs_prop_t prop)
334b476844ca 6622831 normalization properties are not preserved by "zfs send"
timh
parents: 5450
diff changeset
  1235
{
334b476844ca 6622831 normalization properties are not preserved by "zfs send"
timh
parents: 5450
diff changeset
  1236
	uint64_t value;
334b476844ca 6622831 normalization properties are not preserved by "zfs send"
timh
parents: 5450
diff changeset
  1237
	int error;
334b476844ca 6622831 normalization properties are not preserved by "zfs send"
timh
parents: 5450
diff changeset
  1238
334b476844ca 6622831 normalization properties are not preserved by "zfs send"
timh
parents: 5450
diff changeset
  1239
	/*
334b476844ca 6622831 normalization properties are not preserved by "zfs send"
timh
parents: 5450
diff changeset
  1240
	 * zfs_get_zplprop() will either find a value or give us
334b476844ca 6622831 normalization properties are not preserved by "zfs send"
timh
parents: 5450
diff changeset
  1241
	 * the default value (if there is one).
334b476844ca 6622831 normalization properties are not preserved by "zfs send"
timh
parents: 5450
diff changeset
  1242
	 */
334b476844ca 6622831 normalization properties are not preserved by "zfs send"
timh
parents: 5450
diff changeset
  1243
	if ((error = zfs_get_zplprop(os, prop, &value)) != 0)
334b476844ca 6622831 normalization properties are not preserved by "zfs send"
timh
parents: 5450
diff changeset
  1244
		return (error);
334b476844ca 6622831 normalization properties are not preserved by "zfs send"
timh
parents: 5450
diff changeset
  1245
	VERIFY(nvlist_add_uint64(props, zfs_prop_to_name(prop), value) == 0);
334b476844ca 6622831 normalization properties are not preserved by "zfs send"
timh
parents: 5450
diff changeset
  1246
	return (0);
334b476844ca 6622831 normalization properties are not preserved by "zfs send"
timh
parents: 5450
diff changeset
  1247
}
334b476844ca 6622831 normalization properties are not preserved by "zfs send"
timh
parents: 5450
diff changeset
  1248
334b476844ca 6622831 normalization properties are not preserved by "zfs send"
timh
parents: 5450
diff changeset
  1249
/*
334b476844ca 6622831 normalization properties are not preserved by "zfs send"
timh
parents: 5450
diff changeset
  1250
 * inputs:
334b476844ca 6622831 normalization properties are not preserved by "zfs send"
timh
parents: 5450
diff changeset
  1251
 * zc_name		name of filesystem
334b476844ca 6622831 normalization properties are not preserved by "zfs send"
timh
parents: 5450
diff changeset
  1252
 * zc_nvlist_dst_size	size of buffer for zpl property nvlist
334b476844ca 6622831 normalization properties are not preserved by "zfs send"
timh
parents: 5450
diff changeset
  1253
 *
334b476844ca 6622831 normalization properties are not preserved by "zfs send"
timh
parents: 5450
diff changeset
  1254
 * outputs:
334b476844ca 6622831 normalization properties are not preserved by "zfs send"
timh
parents: 5450
diff changeset
  1255
 * zc_nvlist_dst	zpl property nvlist
334b476844ca 6622831 normalization properties are not preserved by "zfs send"
timh
parents: 5450
diff changeset
  1256
 * zc_nvlist_dst_size	size of zpl property nvlist
334b476844ca 6622831 normalization properties are not preserved by "zfs send"
timh
parents: 5450
diff changeset
  1257
 */
334b476844ca 6622831 normalization properties are not preserved by "zfs send"
timh
parents: 5450
diff changeset
  1258
static int
334b476844ca 6622831 normalization properties are not preserved by "zfs send"
timh
parents: 5450
diff changeset
  1259
zfs_ioc_objset_zplprops(zfs_cmd_t *zc)
334b476844ca 6622831 normalization properties are not preserved by "zfs send"
timh
parents: 5450
diff changeset
  1260
{
334b476844ca 6622831 normalization properties are not preserved by "zfs send"
timh
parents: 5450
diff changeset
  1261
	objset_t *os;
334b476844ca 6622831 normalization properties are not preserved by "zfs send"
timh
parents: 5450
diff changeset
  1262
	int err;
334b476844ca 6622831 normalization properties are not preserved by "zfs send"
timh
parents: 5450
diff changeset
  1263
6689
47572a2f5e73 6610506 Eliminate or improve retry logic from callers of dmu_objset_open()
maybee
parents: 6643
diff changeset
  1264
	if (err = dmu_objset_open(zc->zc_name,
47572a2f5e73 6610506 Eliminate or improve retry logic from callers of dmu_objset_open()
maybee
parents: 6643
diff changeset
  1265
	    DMU_OST_ANY, DS_MODE_USER | DS_MODE_READONLY, &os))
5498
334b476844ca 6622831 normalization properties are not preserved by "zfs send"
timh
parents: 5450
diff changeset
  1266
		return (err);
334b476844ca 6622831 normalization properties are not preserved by "zfs send"
timh
parents: 5450
diff changeset
  1267
334b476844ca 6622831 normalization properties are not preserved by "zfs send"
timh
parents: 5450
diff changeset
  1268
	dmu_objset_fast_stat(os, &zc->zc_objset_stats);
334b476844ca 6622831 normalization properties are not preserved by "zfs send"
timh
parents: 5450
diff changeset
  1269
334b476844ca 6622831 normalization properties are not preserved by "zfs send"
timh
parents: 5450
diff changeset
  1270
	/*
334b476844ca 6622831 normalization properties are not preserved by "zfs send"
timh
parents: 5450
diff changeset
  1271
	 * NB: nvl_add_zplprop() will read the objset contents,
6689
47572a2f5e73 6610506 Eliminate or improve retry logic from callers of dmu_objset_open()
maybee
parents: 6643
diff changeset
  1272
	 * which we aren't supposed to do with a DS_MODE_USER
47572a2f5e73 6610506 Eliminate or improve retry logic from callers of dmu_objset_open()
maybee
parents: 6643
diff changeset
  1273
	 * hold, because it could be inconsistent.
5498
334b476844ca 6622831 normalization properties are not preserved by "zfs send"
timh
parents: 5450
diff changeset
  1274
	 */
334b476844ca 6622831 normalization properties are not preserved by "zfs send"
timh
parents: 5450
diff changeset
  1275
	if (zc->zc_nvlist_dst != NULL &&
334b476844ca 6622831 normalization properties are not preserved by "zfs send"
timh
parents: 5450
diff changeset
  1276
	    !zc->zc_objset_stats.dds_inconsistent &&
334b476844ca 6622831 normalization properties are not preserved by "zfs send"
timh
parents: 5450
diff changeset
  1277
	    dmu_objset_type(os) == DMU_OST_ZFS) {
334b476844ca 6622831 normalization properties are not preserved by "zfs send"
timh
parents: 5450
diff changeset
  1278
		nvlist_t *nv;
334b476844ca 6622831 normalization properties are not preserved by "zfs send"
timh
parents: 5450
diff changeset
  1279
334b476844ca 6622831 normalization properties are not preserved by "zfs send"
timh
parents: 5450
diff changeset
  1280
		VERIFY(nvlist_alloc(&nv, NV_UNIQUE_NAME, KM_SLEEP) == 0);
334b476844ca 6622831 normalization properties are not preserved by "zfs send"
timh
parents: 5450
diff changeset
  1281
		if ((err = nvl_add_zplprop(os, nv, ZFS_PROP_VERSION)) == 0 &&
334b476844ca 6622831 normalization properties are not preserved by "zfs send"
timh
parents: 5450
diff changeset
  1282
		    (err = nvl_add_zplprop(os, nv, ZFS_PROP_NORMALIZE)) == 0 &&
334b476844ca 6622831 normalization properties are not preserved by "zfs send"
timh
parents: 5450
diff changeset
  1283
		    (err = nvl_add_zplprop(os, nv, ZFS_PROP_UTF8ONLY)) == 0 &&
334b476844ca 6622831 normalization properties are not preserved by "zfs send"
timh
parents: 5450
diff changeset
  1284
		    (err = nvl_add_zplprop(os, nv, ZFS_PROP_CASE)) == 0)
334b476844ca 6622831 normalization properties are not preserved by "zfs send"
timh
parents: 5450
diff changeset
  1285
			err = put_nvlist(zc, nv);
334b476844ca 6622831 normalization properties are not preserved by "zfs send"
timh
parents: 5450
diff changeset
  1286
		nvlist_free(nv);
334b476844ca 6622831 normalization properties are not preserved by "zfs send"
timh
parents: 5450
diff changeset
  1287
	} else {
334b476844ca 6622831 normalization properties are not preserved by "zfs send"
timh
parents: 5450
diff changeset
  1288
		err = ENOENT;
334b476844ca 6622831 normalization properties are not preserved by "zfs send"
timh
parents: 5450
diff changeset
  1289
	}
334b476844ca 6622831 normalization properties are not preserved by "zfs send"
timh
parents: 5450
diff changeset
  1290
	dmu_objset_close(os);
334b476844ca 6622831 normalization properties are not preserved by "zfs send"
timh
parents: 5450
diff changeset
  1291
	return (err);
334b476844ca 6622831 normalization properties are not preserved by "zfs send"
timh
parents: 5450
diff changeset
  1292
}
334b476844ca 6622831 normalization properties are not preserved by "zfs send"
timh
parents: 5450
diff changeset
  1293
5367
c40abbe796be PSARC/2007/574 zfs send -R
ahrens
parents: 5331
diff changeset
  1294
/*
c40abbe796be PSARC/2007/574 zfs send -R
ahrens
parents: 5331
diff changeset
  1295
 * inputs:
c40abbe796be PSARC/2007/574 zfs send -R
ahrens
parents: 5331
diff changeset
  1296
 * zc_name		name of filesystem
c40abbe796be PSARC/2007/574 zfs send -R
ahrens
parents: 5331
diff changeset
  1297
 * zc_cookie		zap cursor
c40abbe796be PSARC/2007/574 zfs send -R
ahrens
parents: 5331
diff changeset
  1298
 * zc_nvlist_dst_size	size of buffer for property nvlist
c40abbe796be PSARC/2007/574 zfs send -R
ahrens
parents: 5331
diff changeset
  1299
 *
c40abbe796be PSARC/2007/574 zfs send -R
ahrens
parents: 5331
diff changeset
  1300
 * outputs:
c40abbe796be PSARC/2007/574 zfs send -R
ahrens
parents: 5331
diff changeset
  1301
 * zc_name		name of next filesystem
c40abbe796be PSARC/2007/574 zfs send -R
ahrens
parents: 5331
diff changeset
  1302
 * zc_objset_stats	stats
c40abbe796be PSARC/2007/574 zfs send -R
ahrens
parents: 5331
diff changeset
  1303
 * zc_nvlist_dst	property nvlist
c40abbe796be PSARC/2007/574 zfs send -R
ahrens
parents: 5331
diff changeset
  1304
 * zc_nvlist_dst_size	size of property nvlist
c40abbe796be PSARC/2007/574 zfs send -R
ahrens
parents: 5331
diff changeset
  1305
 */
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1306
static int
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1307
zfs_ioc_dataset_list_next(zfs_cmd_t *zc)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1308
{
885
d925b21dba78 6347493 tar of 25K empty directory entries in ZFS takes 30+ seconds ...
ahrens
parents: 849
diff changeset
  1309
	objset_t *os;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1310
	int error;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1311
	char *p;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1312
6689
47572a2f5e73 6610506 Eliminate or improve retry logic from callers of dmu_objset_open()
maybee
parents: 6643
diff changeset
  1313
	if (error = dmu_objset_open(zc->zc_name,
47572a2f5e73 6610506 Eliminate or improve retry logic from callers of dmu_objset_open()
maybee
parents: 6643
diff changeset
  1314
	    DMU_OST_ANY, DS_MODE_USER | DS_MODE_READONLY, &os)) {
885
d925b21dba78 6347493 tar of 25K empty directory entries in ZFS takes 30+ seconds ...
ahrens
parents: 849
diff changeset
  1315
		if (error == ENOENT)
d925b21dba78 6347493 tar of 25K empty directory entries in ZFS takes 30+ seconds ...
ahrens
parents: 849
diff changeset
  1316
			error = ESRCH;
d925b21dba78 6347493 tar of 25K empty directory entries in ZFS takes 30+ seconds ...
ahrens
parents: 849
diff changeset
  1317
		return (error);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1318
	}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1319
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1320
	p = strrchr(zc->zc_name, '/');
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1321
	if (p == NULL || p[1] != '\0')
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1322
		(void) strlcat(zc->zc_name, "/", sizeof (zc->zc_name));
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1323
	p = zc->zc_name + strlen(zc->zc_name);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1324
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1325
	do {
885
d925b21dba78 6347493 tar of 25K empty directory entries in ZFS takes 30+ seconds ...
ahrens
parents: 849
diff changeset
  1326
		error = dmu_dir_list_next(os,
d925b21dba78 6347493 tar of 25K empty directory entries in ZFS takes 30+ seconds ...
ahrens
parents: 849
diff changeset
  1327
		    sizeof (zc->zc_name) - (p - zc->zc_name), p,
d925b21dba78 6347493 tar of 25K empty directory entries in ZFS takes 30+ seconds ...
ahrens
parents: 849
diff changeset
  1328
		    NULL, &zc->zc_cookie);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1329
		if (error == ENOENT)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1330
			error = ESRCH;
885
d925b21dba78 6347493 tar of 25K empty directory entries in ZFS takes 30+ seconds ...
ahrens
parents: 849
diff changeset
  1331
	} while (error == 0 && !INGLOBALZONE(curproc) &&
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1332
	    !zone_dataset_visible(zc->zc_name, NULL));
6689
47572a2f5e73 6610506 Eliminate or improve retry logic from callers of dmu_objset_open()
maybee
parents: 6643
diff changeset
  1333
	dmu_objset_close(os);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1334
885
d925b21dba78 6347493 tar of 25K empty directory entries in ZFS takes 30+ seconds ...
ahrens
parents: 849
diff changeset
  1335
	/*
d925b21dba78 6347493 tar of 25K empty directory entries in ZFS takes 30+ seconds ...
ahrens
parents: 849
diff changeset
  1336
	 * If it's a hidden dataset (ie. with a '$' in its name), don't
d925b21dba78 6347493 tar of 25K empty directory entries in ZFS takes 30+ seconds ...
ahrens
parents: 849
diff changeset
  1337
	 * try to get stats for it.  Userland will skip over it.
d925b21dba78 6347493 tar of 25K empty directory entries in ZFS takes 30+ seconds ...
ahrens
parents: 849
diff changeset
  1338
	 */
d925b21dba78 6347493 tar of 25K empty directory entries in ZFS takes 30+ seconds ...
ahrens
parents: 849
diff changeset
  1339
	if (error == 0 && strchr(zc->zc_name, '$') == NULL)
d925b21dba78 6347493 tar of 25K empty directory entries in ZFS takes 30+ seconds ...
ahrens
parents: 849
diff changeset
  1340
		error = zfs_ioc_objset_stats(zc); /* fill in the stats */
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1341
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1342
	return (error);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1343
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1344
5367
c40abbe796be PSARC/2007/574 zfs send -R
ahrens
parents: 5331
diff changeset
  1345
/*
c40abbe796be PSARC/2007/574 zfs send -R
ahrens
parents: 5331
diff changeset
  1346
 * inputs:
c40abbe796be PSARC/2007/574 zfs send -R
ahrens
parents: 5331
diff changeset
  1347
 * zc_name		name of filesystem
c40abbe796be PSARC/2007/574 zfs send -R
ahrens
parents: 5331
diff changeset
  1348
 * zc_cookie		zap cursor
c40abbe796be PSARC/2007/574 zfs send -R
ahrens
parents: 5331
diff changeset
  1349
 * zc_nvlist_dst_size	size of buffer for property nvlist
c40abbe796be PSARC/2007/574 zfs send -R
ahrens
parents: 5331
diff changeset
  1350
 *
c40abbe796be PSARC/2007/574 zfs send -R
ahrens
parents: 5331
diff changeset
  1351
 * outputs:
c40abbe796be PSARC/2007/574 zfs send -R
ahrens
parents: 5331
diff changeset
  1352
 * zc_name		name of next snapshot
c40abbe796be PSARC/2007/574 zfs send -R
ahrens
parents: 5331
diff changeset
  1353
 * zc_objset_stats	stats
c40abbe796be PSARC/2007/574 zfs send -R
ahrens
parents: 5331
diff changeset
  1354
 * zc_nvlist_dst	property nvlist
c40abbe796be PSARC/2007/574 zfs send -R
ahrens
parents: 5331
diff changeset
  1355
 * zc_nvlist_dst_size	size of property nvlist
c40abbe796be PSARC/2007/574 zfs send -R
ahrens
parents: 5331
diff changeset
  1356
 */
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1357
static int
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1358
zfs_ioc_snapshot_list_next(zfs_cmd_t *zc)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1359
{
885
d925b21dba78 6347493 tar of 25K empty directory entries in ZFS takes 30+ seconds ...
ahrens
parents: 849
diff changeset
  1360
	objset_t *os;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1361
	int error;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1362
6689
47572a2f5e73 6610506 Eliminate or improve retry logic from callers of dmu_objset_open()
maybee
parents: 6643
diff changeset
  1363
	error = dmu_objset_open(zc->zc_name,
47572a2f5e73 6610506 Eliminate or improve retry logic from callers of dmu_objset_open()
maybee
parents: 6643
diff changeset
  1364
	    DMU_OST_ANY, DS_MODE_USER | DS_MODE_READONLY, &os);
47572a2f5e73 6610506 Eliminate or improve retry logic from callers of dmu_objset_open()
maybee
parents: 6643
diff changeset
  1365
	if (error)
47572a2f5e73 6610506 Eliminate or improve retry logic from callers of dmu_objset_open()
maybee
parents: 6643
diff changeset
  1366
		return (error == ENOENT ? ESRCH : error);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1367
1003
ce99098d6a9b 6350417 long name will cause rename a dataset panic
lling
parents: 885
diff changeset
  1368
	/*
ce99098d6a9b 6350417 long name will cause rename a dataset panic
lling
parents: 885
diff changeset
  1369
	 * A dataset name of maximum length cannot have any snapshots,
ce99098d6a9b 6350417 long name will cause rename a dataset panic
lling
parents: 885
diff changeset
  1370
	 * so exit immediately.
ce99098d6a9b 6350417 long name will cause rename a dataset panic
lling
parents: 885
diff changeset
  1371
	 */
ce99098d6a9b 6350417 long name will cause rename a dataset panic
lling
parents: 885
diff changeset
  1372
	if (strlcat(zc->zc_name, "@", sizeof (zc->zc_name)) >= MAXNAMELEN) {
885
d925b21dba78 6347493 tar of 25K empty directory entries in ZFS takes 30+ seconds ...
ahrens
parents: 849
diff changeset
  1373
		dmu_objset_close(os);
1003
ce99098d6a9b 6350417 long name will cause rename a dataset panic
lling
parents: 885
diff changeset
  1374
		return (ESRCH);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1375
	}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1376
885
d925b21dba78 6347493 tar of 25K empty directory entries in ZFS takes 30+ seconds ...
ahrens
parents: 849
diff changeset
  1377
	error = dmu_snapshot_list_next(os,
d925b21dba78 6347493 tar of 25K empty directory entries in ZFS takes 30+ seconds ...
ahrens
parents: 849
diff changeset
  1378
	    sizeof (zc->zc_name) - strlen(zc->zc_name),
5663
029cc4273b57 6627223 gfs needs to support extended dirent flags
ck153898
parents: 5498
diff changeset
  1379
	    zc->zc_name + strlen(zc->zc_name), NULL, &zc->zc_cookie, NULL);
6689
47572a2f5e73 6610506 Eliminate or improve retry logic from callers of dmu_objset_open()
maybee
parents: 6643
diff changeset
  1380
	dmu_objset_close(os);
885
d925b21dba78 6347493 tar of 25K empty directory entries in ZFS takes 30+ seconds ...
ahrens
parents: 849
diff changeset
  1381
	if (error == 0)
d925b21dba78 6347493 tar of 25K empty directory entries in ZFS takes 30+ seconds ...
ahrens
parents: 849
diff changeset
  1382
		error = zfs_ioc_objset_stats(zc); /* fill in the stats */
6689
47572a2f5e73 6610506 Eliminate or improve retry logic from callers of dmu_objset_open()
maybee
parents: 6643
diff changeset
  1383
	else if (error == ENOENT)
47572a2f5e73 6610506 Eliminate or improve retry logic from callers of dmu_objset_open()
maybee
parents: 6643
diff changeset
  1384
		error = ESRCH;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1385
5367
c40abbe796be PSARC/2007/574 zfs send -R
ahrens
parents: 5331
diff changeset
  1386
	/* if we failed, undo the @ that we tacked on to zc_name */
6689
47572a2f5e73 6610506 Eliminate or improve retry logic from callers of dmu_objset_open()
maybee
parents: 6643
diff changeset
  1387
	if (error)
5367
c40abbe796be PSARC/2007/574 zfs send -R
ahrens
parents: 5331
diff changeset
  1388
		*strchr(zc->zc_name, '@') = '\0';
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1389
	return (error);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1390
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1391
6423
437422a29d3a PSARC 2006/370 ZFS Boot Support
gw25295
parents: 6139
diff changeset
  1392
int
4787
602d3f97842c 6393351 unique_* could be improved
ahrens
parents: 4720
diff changeset
  1393
zfs_set_prop_nvlist(const char *name, nvlist_t *nvl)
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1394
{
2676
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  1395
	nvpair_t *elem;
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  1396
	int error;
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  1397
	uint64_t intval;
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  1398
	char *strval;
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  1399
4543
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  1400
	/*
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  1401
	 * First validate permission to set all of the properties
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  1402
	 */
2676
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  1403
	elem = NULL;
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  1404
	while ((elem = nvlist_next_nvpair(nvl, elem)) != NULL) {
4670
002728040e28 6580745 "zfs inherit" can be executed by ordinary user
ahrens
parents: 4611
diff changeset
  1405
		const char *propname = nvpair_name(elem);
002728040e28 6580745 "zfs inherit" can be executed by ordinary user
ahrens
parents: 4611
diff changeset
  1406
		zfs_prop_t prop = zfs_name_to_prop(propname);
2676
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  1407
5094
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
  1408
		if (prop == ZPROP_INVAL) {
2676
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  1409
			/*
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  1410
			 * If this is a user-defined property, it must be a
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  1411
			 * string, and there is no further validation to do.
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  1412
			 */
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  1413
			if (!zfs_prop_user(propname) ||
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  1414
			    nvpair_type(elem) != DATA_TYPE_STRING)
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  1415
				return (EINVAL);
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  1416
5331
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
  1417
			if (error = zfs_secpolicy_write_perms(name,
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
  1418
			    ZFS_DELEG_PERM_USERPROP, CRED()))
4670
002728040e28 6580745 "zfs inherit" can be executed by ordinary user
ahrens
parents: 4611
diff changeset
  1419
				return (error);
4543
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  1420
			continue;
2676
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  1421
		}
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  1422
4787
602d3f97842c 6393351 unique_* could be improved
ahrens
parents: 4720
diff changeset
  1423
		if ((error = zfs_secpolicy_setprop(name, prop, CRED())) != 0)
4670
002728040e28 6580745 "zfs inherit" can be executed by ordinary user
ahrens
parents: 4611
diff changeset
  1424
			return (error);
2676
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  1425
4670
002728040e28 6580745 "zfs inherit" can be executed by ordinary user
ahrens
parents: 4611
diff changeset
  1426
		/*
002728040e28 6580745 "zfs inherit" can be executed by ordinary user
ahrens
parents: 4611
diff changeset
  1427
		 * Check that this value is valid for this pool version
002728040e28 6580745 "zfs inherit" can be executed by ordinary user
ahrens
parents: 4611
diff changeset
  1428
		 */
002728040e28 6580745 "zfs inherit" can be executed by ordinary user
ahrens
parents: 4611
diff changeset
  1429
		switch (prop) {
3886
3291401d66a6 6536602 add zlib compression support and upgrade to version 1.2.3
ahl
parents: 3863
diff changeset
  1430
		case ZFS_PROP_COMPRESSION:
3291401d66a6 6536602 add zlib compression support and upgrade to version 1.2.3
ahl
parents: 3863
diff changeset
  1431
			/*
3291401d66a6 6536602 add zlib compression support and upgrade to version 1.2.3
ahl
parents: 3863
diff changeset
  1432
			 * If the user specified gzip compression, make sure
3291401d66a6 6536602 add zlib compression support and upgrade to version 1.2.3
ahl
parents: 3863
diff changeset
  1433
			 * the SPA supports it. We ignore any errors here since
3291401d66a6 6536602 add zlib compression support and upgrade to version 1.2.3
ahl
parents: 3863
diff changeset
  1434
			 * we'll catch them later.
3291401d66a6 6536602 add zlib compression support and upgrade to version 1.2.3
ahl
parents: 3863
diff changeset
  1435
			 */
3291401d66a6 6536602 add zlib compression support and upgrade to version 1.2.3
ahl
parents: 3863
diff changeset
  1436
			if (nvpair_type(elem) == DATA_TYPE_UINT64 &&
7042
46fc4b6db23e 6721094 Setting certain properties on root pools should not be allowed
gw25295
parents: 6865
diff changeset
  1437
			    nvpair_value_uint64(elem, &intval) == 0) {
46fc4b6db23e 6721094 Setting certain properties on root pools should not be allowed
gw25295
parents: 6865
diff changeset
  1438
				if (intval >= ZIO_COMPRESS_GZIP_1 &&
46fc4b6db23e 6721094 Setting certain properties on root pools should not be allowed
gw25295
parents: 6865
diff changeset
  1439
				    intval <= ZIO_COMPRESS_GZIP_9 &&
7184
9508660f9c27 PSARC 2008/223 Pool root file system properties via zpool(1M)
timh
parents: 7046
diff changeset
  1440
				    zfs_earlier_version(name,
5331
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
  1441
				    SPA_VERSION_GZIP_COMPRESSION))
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
  1442
					return (ENOTSUP);
7042
46fc4b6db23e 6721094 Setting certain properties on root pools should not be allowed
gw25295
parents: 6865
diff changeset
  1443
46fc4b6db23e 6721094 Setting certain properties on root pools should not be allowed
gw25295
parents: 6865
diff changeset
  1444
				/*
46fc4b6db23e 6721094 Setting certain properties on root pools should not be allowed
gw25295
parents: 6865
diff changeset
  1445
				 * If this is a bootable dataset then
46fc4b6db23e 6721094 Setting certain properties on root pools should not be allowed
gw25295
parents: 6865
diff changeset
  1446
				 * verify that the compression algorithm
46fc4b6db23e 6721094 Setting certain properties on root pools should not be allowed
gw25295
parents: 6865
diff changeset
  1447
				 * is supported for booting. We must return
46fc4b6db23e 6721094 Setting certain properties on root pools should not be allowed
gw25295
parents: 6865
diff changeset
  1448
				 * something other than ENOTSUP since it
46fc4b6db23e 6721094 Setting certain properties on root pools should not be allowed
gw25295
parents: 6865
diff changeset
  1449
				 * implies a downrev pool version.
46fc4b6db23e 6721094 Setting certain properties on root pools should not be allowed
gw25295
parents: 6865
diff changeset
  1450
				 */
46fc4b6db23e 6721094 Setting certain properties on root pools should not be allowed
gw25295
parents: 6865
diff changeset
  1451
				if (zfs_is_bootfs(name) &&
46fc4b6db23e 6721094 Setting certain properties on root pools should not be allowed
gw25295
parents: 6865
diff changeset
  1452
				    !BOOTFS_COMPRESS_VALID(intval))
46fc4b6db23e 6721094 Setting certain properties on root pools should not be allowed
gw25295
parents: 6865
diff changeset
  1453
					return (ERANGE);
3886
3291401d66a6 6536602 add zlib compression support and upgrade to version 1.2.3
ahl
parents: 3863
diff changeset
  1454
			}
3291401d66a6 6536602 add zlib compression support and upgrade to version 1.2.3
ahl
parents: 3863
diff changeset
  1455
			break;
4603
c7840c367d00 6494569 zfs recv -d pool/<doesn't exist> core dumps for top-level filesystem backups
ahrens
parents: 4577
diff changeset
  1456
c7840c367d00 6494569 zfs recv -d pool/<doesn't exist> core dumps for top-level filesystem backups
ahrens
parents: 4577
diff changeset
  1457
		case ZFS_PROP_COPIES:
7184
9508660f9c27 PSARC 2008/223 Pool root file system properties via zpool(1M)
timh
parents: 7046
diff changeset
  1458
			if (zfs_earlier_version(name,
9508660f9c27 PSARC 2008/223 Pool root file system properties via zpool(1M)
timh
parents: 7046
diff changeset
  1459
			    SPA_VERSION_DITTO_BLOCKS))
5331
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
  1460
				return (ENOTSUP);
4603
c7840c367d00 6494569 zfs recv -d pool/<doesn't exist> core dumps for top-level filesystem backups
ahrens
parents: 4577
diff changeset
  1461
			break;
5977
33727f49aeaa 6654731 sharesmb property should only be settable on CIFS aware ZPL
marks
parents: 5663
diff changeset
  1462
33727f49aeaa 6654731 sharesmb property should only be settable on CIFS aware ZPL
marks
parents: 5663
diff changeset
  1463
		case ZFS_PROP_SHARESMB:
6689
47572a2f5e73 6610506 Eliminate or improve retry logic from callers of dmu_objset_open()
maybee
parents: 6643
diff changeset
  1464
			if (zpl_earlier_version(name, ZPL_VERSION_FUID))
5977
33727f49aeaa 6654731 sharesmb property should only be settable on CIFS aware ZPL
marks
parents: 5663
diff changeset
  1465
				return (ENOTSUP);
33727f49aeaa 6654731 sharesmb property should only be settable on CIFS aware ZPL
marks
parents: 5663
diff changeset
  1466
			break;
4603
c7840c367d00 6494569 zfs recv -d pool/<doesn't exist> core dumps for top-level filesystem backups
ahrens
parents: 4577
diff changeset
  1467
		}
4543
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  1468
	}
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  1469
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  1470
	elem = NULL;
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  1471
	while ((elem = nvlist_next_nvpair(nvl, elem)) != NULL) {
4670
002728040e28 6580745 "zfs inherit" can be executed by ordinary user
ahrens
parents: 4611
diff changeset
  1472
		const char *propname = nvpair_name(elem);
002728040e28 6580745 "zfs inherit" can be executed by ordinary user
ahrens
parents: 4611
diff changeset
  1473
		zfs_prop_t prop = zfs_name_to_prop(propname);
4543
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  1474
5094
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
  1475
		if (prop == ZPROP_INVAL) {
4543
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  1476
			VERIFY(nvpair_value_string(elem, &strval) == 0);
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  1477
			error = dsl_prop_set(name, propname, 1,
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  1478
			    strlen(strval) + 1, strval);
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  1479
			if (error == 0)
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  1480
				continue;
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  1481
			else
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  1482
				return (error);
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  1483
		}
2676
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  1484
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  1485
		switch (prop) {
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  1486
		case ZFS_PROP_QUOTA:
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  1487
			if ((error = nvpair_value_uint64(elem, &intval)) != 0 ||
4577
ed36b0e652bc PSARC/2007/328 zfs upgrade
ahrens
parents: 4543
diff changeset
  1488
			    (error = dsl_dir_set_quota(name, intval)) != 0)
2676
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  1489
				return (error);
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  1490
			break;
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  1491
5378
111aa1baa84a PSARC 2007/555 zfs fs-only quotas and reservations
ck153898
parents: 5375
diff changeset
  1492
		case ZFS_PROP_REFQUOTA:
111aa1baa84a PSARC 2007/555 zfs fs-only quotas and reservations
ck153898
parents: 5375
diff changeset
  1493
			if ((error = nvpair_value_uint64(elem, &intval)) != 0 ||
111aa1baa84a PSARC 2007/555 zfs fs-only quotas and reservations
ck153898
parents: 5375
diff changeset
  1494
			    (error = dsl_dataset_set_quota(name, intval)) != 0)
111aa1baa84a PSARC 2007/555 zfs fs-only quotas and reservations
ck153898
parents: 5375
diff changeset
  1495
				return (error);
111aa1baa84a PSARC 2007/555 zfs fs-only quotas and reservations
ck153898
parents: 5375
diff changeset
  1496
			break;
111aa1baa84a PSARC 2007/555 zfs fs-only quotas and reservations
ck153898
parents: 5375
diff changeset
  1497
2676
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  1498
		case ZFS_PROP_RESERVATION:
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  1499
			if ((error = nvpair_value_uint64(elem, &intval)) != 0 ||
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  1500
			    (error = dsl_dir_set_reservation(name,
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  1501
			    intval)) != 0)
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  1502
				return (error);
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  1503
			break;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1504
5378
111aa1baa84a PSARC 2007/555 zfs fs-only quotas and reservations
ck153898
parents: 5375
diff changeset
  1505
		case ZFS_PROP_REFRESERVATION:
111aa1baa84a PSARC 2007/555 zfs fs-only quotas and reservations
ck153898
parents: 5375
diff changeset
  1506
			if ((error = nvpair_value_uint64(elem, &intval)) != 0 ||
111aa1baa84a PSARC 2007/555 zfs fs-only quotas and reservations
ck153898
parents: 5375
diff changeset
  1507
			    (error = dsl_dataset_set_reservation(name,
111aa1baa84a PSARC 2007/555 zfs fs-only quotas and reservations
ck153898
parents: 5375
diff changeset
  1508
			    intval)) != 0)
111aa1baa84a PSARC 2007/555 zfs fs-only quotas and reservations
ck153898
parents: 5375
diff changeset
  1509
				return (error);
111aa1baa84a PSARC 2007/555 zfs fs-only quotas and reservations
ck153898
parents: 5375
diff changeset
  1510
			break;
111aa1baa84a PSARC 2007/555 zfs fs-only quotas and reservations
ck153898
parents: 5375
diff changeset
  1511
2676
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  1512
		case ZFS_PROP_VOLSIZE:
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  1513
			if ((error = nvpair_value_uint64(elem, &intval)) != 0 ||
4787
602d3f97842c 6393351 unique_* could be improved
ahrens
parents: 4720
diff changeset
  1514
			    (error = zvol_set_volsize(name,
602d3f97842c 6393351 unique_* could be improved
ahrens
parents: 4720
diff changeset
  1515
			    ddi_driver_major(zfs_dip), intval)) != 0)
2676
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  1516
				return (error);
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  1517
			break;
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  1518
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  1519
		case ZFS_PROP_VOLBLOCKSIZE:
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  1520
			if ((error = nvpair_value_uint64(elem, &intval)) != 0 ||
4577
ed36b0e652bc PSARC/2007/328 zfs upgrade
ahrens
parents: 4543
diff changeset
  1521
			    (error = zvol_set_volblocksize(name, intval)) != 0)
ed36b0e652bc PSARC/2007/328 zfs upgrade
ahrens
parents: 4543
diff changeset
  1522
				return (error);
ed36b0e652bc PSARC/2007/328 zfs upgrade
ahrens
parents: 4543
diff changeset
  1523
			break;
ed36b0e652bc PSARC/2007/328 zfs upgrade
ahrens
parents: 4543
diff changeset
  1524
ed36b0e652bc PSARC/2007/328 zfs upgrade
ahrens
parents: 4543
diff changeset
  1525
		case ZFS_PROP_VERSION:
ed36b0e652bc PSARC/2007/328 zfs upgrade
ahrens
parents: 4543
diff changeset
  1526
			if ((error = nvpair_value_uint64(elem, &intval)) != 0 ||
ed36b0e652bc PSARC/2007/328 zfs upgrade
ahrens
parents: 4543
diff changeset
  1527
			    (error = zfs_set_version(name, intval)) != 0)
2676
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  1528
				return (error);
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  1529
			break;
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  1530
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  1531
		default:
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  1532
			if (nvpair_type(elem) == DATA_TYPE_STRING) {
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  1533
				if (zfs_prop_get_type(prop) !=
4787
602d3f97842c 6393351 unique_* could be improved
ahrens
parents: 4720
diff changeset
  1534
				    PROP_TYPE_STRING)
2676
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  1535
					return (EINVAL);
2717
ed589a32259d 6469385 zfs_set_prop_nvlist range checking is busted
eschrock
parents: 2676
diff changeset
  1536
				VERIFY(nvpair_value_string(elem, &strval) == 0);
ed589a32259d 6469385 zfs_set_prop_nvlist range checking is busted
eschrock
parents: 2676
diff changeset
  1537
				if ((error = dsl_prop_set(name,
2676
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  1538
				    nvpair_name(elem), 1, strlen(strval) + 1,
2717
ed589a32259d 6469385 zfs_set_prop_nvlist range checking is busted
eschrock
parents: 2676
diff changeset
  1539
				    strval)) != 0)
ed589a32259d 6469385 zfs_set_prop_nvlist range checking is busted
eschrock
parents: 2676
diff changeset
  1540
					return (error);
2676
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  1541
			} else if (nvpair_type(elem) == DATA_TYPE_UINT64) {
2885
c0259887ebbc 6460059 zfs destroy <snapshot> leaves behind kruft
ahrens
parents: 2856
diff changeset
  1542
				const char *unused;
c0259887ebbc 6460059 zfs destroy <snapshot> leaves behind kruft
ahrens
parents: 2856
diff changeset
  1543
2717
ed589a32259d 6469385 zfs_set_prop_nvlist range checking is busted
eschrock
parents: 2676
diff changeset
  1544
				VERIFY(nvpair_value_uint64(elem, &intval) == 0);
2676
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  1545
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  1546
				switch (zfs_prop_get_type(prop)) {
4787
602d3f97842c 6393351 unique_* could be improved
ahrens
parents: 4720
diff changeset
  1547
				case PROP_TYPE_NUMBER:
2676
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  1548
					break;
4787
602d3f97842c 6393351 unique_* could be improved
ahrens
parents: 4720
diff changeset
  1549
				case PROP_TYPE_STRING:
2717
ed589a32259d 6469385 zfs_set_prop_nvlist range checking is busted
eschrock
parents: 2676
diff changeset
  1550
					return (EINVAL);
4787
602d3f97842c 6393351 unique_* could be improved
ahrens
parents: 4720
diff changeset
  1551
				case PROP_TYPE_INDEX:
2717
ed589a32259d 6469385 zfs_set_prop_nvlist range checking is busted
eschrock
parents: 2676
diff changeset
  1552
					if (zfs_prop_index_to_string(prop,
ed589a32259d 6469385 zfs_set_prop_nvlist range checking is busted
eschrock
parents: 2676
diff changeset
  1553
					    intval, &unused) != 0)
ed589a32259d 6469385 zfs_set_prop_nvlist range checking is busted
eschrock
parents: 2676
diff changeset
  1554
						return (EINVAL);
2676
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  1555
					break;
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  1556
				default:
4577
ed36b0e652bc PSARC/2007/328 zfs upgrade
ahrens
parents: 4543
diff changeset
  1557
					cmn_err(CE_PANIC,
ed36b0e652bc PSARC/2007/328 zfs upgrade
ahrens
parents: 4543
diff changeset
  1558
					    "unknown property type");
2676
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  1559
					break;
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  1560
				}
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  1561
2717
ed589a32259d 6469385 zfs_set_prop_nvlist range checking is busted
eschrock
parents: 2676
diff changeset
  1562
				if ((error = dsl_prop_set(name, propname,
ed589a32259d 6469385 zfs_set_prop_nvlist range checking is busted
eschrock
parents: 2676
diff changeset
  1563
				    8, 1, &intval)) != 0)
ed589a32259d 6469385 zfs_set_prop_nvlist range checking is busted
eschrock
parents: 2676
diff changeset
  1564
					return (error);
2676
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  1565
			} else {
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  1566
				return (EINVAL);
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  1567
			}
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  1568
			break;
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  1569
		}
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  1570
	}
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  1571
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  1572
	return (0);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1573
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1574
5367
c40abbe796be PSARC/2007/574 zfs send -R
ahrens
parents: 5331
diff changeset
  1575
/*
c40abbe796be PSARC/2007/574 zfs send -R
ahrens
parents: 5331
diff changeset
  1576
 * inputs:
c40abbe796be PSARC/2007/574 zfs send -R
ahrens
parents: 5331
diff changeset
  1577
 * zc_name		name of filesystem
c40abbe796be PSARC/2007/574 zfs send -R
ahrens
parents: 5331
diff changeset
  1578
 * zc_value		name of property to inherit
c40abbe796be PSARC/2007/574 zfs send -R
ahrens
parents: 5331
diff changeset
  1579
 * zc_nvlist_src{_size}	nvlist of properties to apply
7265
cc18862247da PSARC/2008/483 ZFS clone -o
ahrens
parents: 7214
diff changeset
  1580
 * zc_cookie		clear existing local props?
5367
c40abbe796be PSARC/2007/574 zfs send -R
ahrens
parents: 5331
diff changeset
  1581
 *
c40abbe796be PSARC/2007/574 zfs send -R
ahrens
parents: 5331
diff changeset
  1582
 * outputs:		none
c40abbe796be PSARC/2007/574 zfs send -R
ahrens
parents: 5331
diff changeset
  1583
 */
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1584
static int
2676
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  1585
zfs_ioc_set_prop(zfs_cmd_t *zc)
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1586
{
2676
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  1587
	nvlist_t *nvl;
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  1588
	int error;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1589
5094
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
  1590
	if ((error = get_nvlist(zc->zc_nvlist_src, zc->zc_nvlist_src_size,
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
  1591
	    &nvl)) != 0)
2676
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  1592
		return (error);
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  1593
7265
cc18862247da PSARC/2008/483 ZFS clone -o
ahrens
parents: 7214
diff changeset
  1594
	if (zc->zc_cookie) {
cc18862247da PSARC/2008/483 ZFS clone -o
ahrens
parents: 7214
diff changeset
  1595
		nvlist_t *origprops;
cc18862247da PSARC/2008/483 ZFS clone -o
ahrens
parents: 7214
diff changeset
  1596
		objset_t *os;
cc18862247da PSARC/2008/483 ZFS clone -o
ahrens
parents: 7214
diff changeset
  1597
cc18862247da PSARC/2008/483 ZFS clone -o
ahrens
parents: 7214
diff changeset
  1598
		if (dmu_objset_open(zc->zc_name, DMU_OST_ANY,
cc18862247da PSARC/2008/483 ZFS clone -o
ahrens
parents: 7214
diff changeset
  1599
		    DS_MODE_USER | DS_MODE_READONLY, &os) == 0) {
cc18862247da PSARC/2008/483 ZFS clone -o
ahrens
parents: 7214
diff changeset
  1600
			if (dsl_prop_get_all(os, &origprops, TRUE) == 0) {
cc18862247da PSARC/2008/483 ZFS clone -o
ahrens
parents: 7214
diff changeset
  1601
				clear_props(zc->zc_name, origprops);
cc18862247da PSARC/2008/483 ZFS clone -o
ahrens
parents: 7214
diff changeset
  1602
				nvlist_free(origprops);
cc18862247da PSARC/2008/483 ZFS clone -o
ahrens
parents: 7214
diff changeset
  1603
			}
cc18862247da PSARC/2008/483 ZFS clone -o
ahrens
parents: 7214
diff changeset
  1604
			dmu_objset_close(os);
cc18862247da PSARC/2008/483 ZFS clone -o
ahrens
parents: 7214
diff changeset
  1605
		}
cc18862247da PSARC/2008/483 ZFS clone -o
ahrens
parents: 7214
diff changeset
  1606
cc18862247da PSARC/2008/483 ZFS clone -o
ahrens
parents: 7214
diff changeset
  1607
	}
cc18862247da PSARC/2008/483 ZFS clone -o
ahrens
parents: 7214
diff changeset
  1608
4787
602d3f97842c 6393351 unique_* could be improved
ahrens
parents: 4720
diff changeset
  1609
	error = zfs_set_prop_nvlist(zc->zc_name, nvl);
4543
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  1610
2676
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  1611
	nvlist_free(nvl);
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  1612
	return (error);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1613
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1614
5367
c40abbe796be PSARC/2007/574 zfs send -R
ahrens
parents: 5331
diff changeset
  1615
/*
c40abbe796be PSARC/2007/574 zfs send -R
ahrens
parents: 5331
diff changeset
  1616
 * inputs:
c40abbe796be PSARC/2007/574 zfs send -R
ahrens
parents: 5331
diff changeset
  1617
 * zc_name		name of filesystem
c40abbe796be PSARC/2007/574 zfs send -R
ahrens
parents: 5331
diff changeset
  1618
 * zc_value		name of property to inherit
c40abbe796be PSARC/2007/574 zfs send -R
ahrens
parents: 5331
diff changeset
  1619
 *
c40abbe796be PSARC/2007/574 zfs send -R
ahrens
parents: 5331
diff changeset
  1620
 * outputs:		none
c40abbe796be PSARC/2007/574 zfs send -R
ahrens
parents: 5331
diff changeset
  1621
 */
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1622
static int
4849
3a61e0a9a953 6536043 arc_byteswap_func_t and dmu_byteswap_func_t are redundant
ahrens
parents: 4808
diff changeset
  1623
zfs_ioc_inherit_prop(zfs_cmd_t *zc)
3a61e0a9a953 6536043 arc_byteswap_func_t and dmu_byteswap_func_t are redundant
ahrens
parents: 4808
diff changeset
  1624
{
3a61e0a9a953 6536043 arc_byteswap_func_t and dmu_byteswap_func_t are redundant
ahrens
parents: 4808
diff changeset
  1625
	/* the property name has been validated by zfs_secpolicy_inherit() */
3a61e0a9a953 6536043 arc_byteswap_func_t and dmu_byteswap_func_t are redundant
ahrens
parents: 4808
diff changeset
  1626
	return (dsl_prop_set(zc->zc_name, zc->zc_value, 0, 0, NULL));
3a61e0a9a953 6536043 arc_byteswap_func_t and dmu_byteswap_func_t are redundant
ahrens
parents: 4808
diff changeset
  1627
}
3a61e0a9a953 6536043 arc_byteswap_func_t and dmu_byteswap_func_t are redundant
ahrens
parents: 4808
diff changeset
  1628
3a61e0a9a953 6536043 arc_byteswap_func_t and dmu_byteswap_func_t are redundant
ahrens
parents: 4808
diff changeset
  1629
static int
4098
0a182c2128e6 6545726 make ZFS_IOC_POOL_*_PROPS in sync with zfs_ioc_pool_props_*
lling
parents: 4007
diff changeset
  1630
zfs_ioc_pool_set_props(zfs_cmd_t *zc)
3912
f6891a60bd72 PSARC 2007/083 ZFS bootable datasets
lling
parents: 3886
diff changeset
  1631
{
5094
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
  1632
	nvlist_t *props;
3912
f6891a60bd72 PSARC 2007/083 ZFS bootable datasets
lling
parents: 3886
diff changeset
  1633
	spa_t *spa;
5094
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
  1634
	int error;
3912
f6891a60bd72 PSARC 2007/083 ZFS bootable datasets
lling
parents: 3886
diff changeset
  1635
5094
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
  1636
	if ((error = get_nvlist(zc->zc_nvlist_src, zc->zc_nvlist_src_size,
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
  1637
	    &props)))
3912
f6891a60bd72 PSARC 2007/083 ZFS bootable datasets
lling
parents: 3886
diff changeset
  1638
		return (error);
f6891a60bd72 PSARC 2007/083 ZFS bootable datasets
lling
parents: 3886
diff changeset
  1639
f6891a60bd72 PSARC 2007/083 ZFS bootable datasets
lling
parents: 3886
diff changeset
  1640
	if ((error = spa_open(zc->zc_name, &spa, FTAG)) != 0) {
5094
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
  1641
		nvlist_free(props);
3912
f6891a60bd72 PSARC 2007/083 ZFS bootable datasets
lling
parents: 3886
diff changeset
  1642
		return (error);
f6891a60bd72 PSARC 2007/083 ZFS bootable datasets
lling
parents: 3886
diff changeset
  1643
	}
f6891a60bd72 PSARC 2007/083 ZFS bootable datasets
lling
parents: 3886
diff changeset
  1644
5094
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
  1645
	error = spa_prop_set(spa, props);
3912
f6891a60bd72 PSARC 2007/083 ZFS bootable datasets
lling
parents: 3886
diff changeset
  1646
5094
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
  1647
	nvlist_free(props);
3912
f6891a60bd72 PSARC 2007/083 ZFS bootable datasets
lling
parents: 3886
diff changeset
  1648
	spa_close(spa, FTAG);
f6891a60bd72 PSARC 2007/083 ZFS bootable datasets
lling
parents: 3886
diff changeset
  1649
f6891a60bd72 PSARC 2007/083 ZFS bootable datasets
lling
parents: 3886
diff changeset
  1650
	return (error);
f6891a60bd72 PSARC 2007/083 ZFS bootable datasets
lling
parents: 3886
diff changeset
  1651
}
f6891a60bd72 PSARC 2007/083 ZFS bootable datasets
lling
parents: 3886
diff changeset
  1652
f6891a60bd72 PSARC 2007/083 ZFS bootable datasets
lling
parents: 3886
diff changeset
  1653
static int
4098
0a182c2128e6 6545726 make ZFS_IOC_POOL_*_PROPS in sync with zfs_ioc_pool_props_*
lling
parents: 4007
diff changeset
  1654
zfs_ioc_pool_get_props(zfs_cmd_t *zc)
3912
f6891a60bd72 PSARC 2007/083 ZFS bootable datasets
lling
parents: 3886
diff changeset
  1655
{
f6891a60bd72 PSARC 2007/083 ZFS bootable datasets
lling
parents: 3886
diff changeset
  1656
	spa_t *spa;
f6891a60bd72 PSARC 2007/083 ZFS bootable datasets
lling
parents: 3886
diff changeset
  1657
	int error;
f6891a60bd72 PSARC 2007/083 ZFS bootable datasets
lling
parents: 3886
diff changeset
  1658
	nvlist_t *nvp = NULL;
f6891a60bd72 PSARC 2007/083 ZFS bootable datasets
lling
parents: 3886
diff changeset
  1659
f6891a60bd72 PSARC 2007/083 ZFS bootable datasets
lling
parents: 3886
diff changeset
  1660
	if ((error = spa_open(zc->zc_name, &spa, FTAG)) != 0)
f6891a60bd72 PSARC 2007/083 ZFS bootable datasets
lling
parents: 3886
diff changeset
  1661
		return (error);
f6891a60bd72 PSARC 2007/083 ZFS bootable datasets
lling
parents: 3886
diff changeset
  1662
5094
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
  1663
	error = spa_prop_get(spa, &nvp);
3912
f6891a60bd72 PSARC 2007/083 ZFS bootable datasets
lling
parents: 3886
diff changeset
  1664
f6891a60bd72 PSARC 2007/083 ZFS bootable datasets
lling
parents: 3886
diff changeset
  1665
	if (error == 0 && zc->zc_nvlist_dst != NULL)
f6891a60bd72 PSARC 2007/083 ZFS bootable datasets
lling
parents: 3886
diff changeset
  1666
		error = put_nvlist(zc, nvp);
f6891a60bd72 PSARC 2007/083 ZFS bootable datasets
lling
parents: 3886
diff changeset
  1667
	else
f6891a60bd72 PSARC 2007/083 ZFS bootable datasets
lling
parents: 3886
diff changeset
  1668
		error = EFAULT;
f6891a60bd72 PSARC 2007/083 ZFS bootable datasets
lling
parents: 3886
diff changeset
  1669
f6891a60bd72 PSARC 2007/083 ZFS bootable datasets
lling
parents: 3886
diff changeset
  1670
	spa_close(spa, FTAG);
f6891a60bd72 PSARC 2007/083 ZFS bootable datasets
lling
parents: 3886
diff changeset
  1671
f6891a60bd72 PSARC 2007/083 ZFS bootable datasets
lling
parents: 3886
diff changeset
  1672
	if (nvp)
f6891a60bd72 PSARC 2007/083 ZFS bootable datasets
lling
parents: 3886
diff changeset
  1673
		nvlist_free(nvp);
f6891a60bd72 PSARC 2007/083 ZFS bootable datasets
lling
parents: 3886
diff changeset
  1674
	return (error);
f6891a60bd72 PSARC 2007/083 ZFS bootable datasets
lling
parents: 3886
diff changeset
  1675
}
f6891a60bd72 PSARC 2007/083 ZFS bootable datasets
lling
parents: 3886
diff changeset
  1676
f6891a60bd72 PSARC 2007/083 ZFS bootable datasets
lling
parents: 3886
diff changeset
  1677
static int
4543
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  1678
zfs_ioc_iscsi_perm_check(zfs_cmd_t *zc)
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  1679
{
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  1680
	nvlist_t *nvp;
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  1681
	int error;
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  1682
	uint32_t uid;
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  1683
	uint32_t gid;
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  1684
	uint32_t *groups;
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  1685
	uint_t group_cnt;
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  1686
	cred_t	*usercred;
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  1687
5094
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
  1688
	if ((error = get_nvlist(zc->zc_nvlist_src, zc->zc_nvlist_src_size,
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
  1689
	    &nvp)) != 0) {
4543
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  1690
		return (error);
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  1691
	}
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  1692
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  1693
	if ((error = nvlist_lookup_uint32(nvp,
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  1694
	    ZFS_DELEG_PERM_UID, &uid)) != 0) {
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  1695
		nvlist_free(nvp);
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  1696
		return (EPERM);
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  1697
	}
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  1698
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  1699
	if ((error = nvlist_lookup_uint32(nvp,
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  1700
	    ZFS_DELEG_PERM_GID, &gid)) != 0) {
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  1701
		nvlist_free(nvp);
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  1702
		return (EPERM);
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  1703
	}
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  1704
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  1705
	if ((error = nvlist_lookup_uint32_array(nvp, ZFS_DELEG_PERM_GROUPS,
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  1706
	    &groups, &group_cnt)) != 0) {
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  1707
		nvlist_free(nvp);
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  1708
		return (EPERM);
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  1709
	}
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  1710
	usercred = cralloc();
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  1711
	if ((crsetugid(usercred, uid, gid) != 0) ||
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  1712
	    (crsetgroups(usercred, group_cnt, (gid_t *)groups) != 0)) {
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  1713
		nvlist_free(nvp);
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  1714
		crfree(usercred);
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  1715
		return (EPERM);
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  1716
	}
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  1717
	nvlist_free(nvp);
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  1718
	error = dsl_deleg_access(zc->zc_name,
4787
602d3f97842c 6393351 unique_* could be improved
ahrens
parents: 4720
diff changeset
  1719
	    zfs_prop_to_name(ZFS_PROP_SHAREISCSI), usercred);
4543
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  1720
	crfree(usercred);
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  1721
	return (error);
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  1722
}
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  1723
5367
c40abbe796be PSARC/2007/574 zfs send -R
ahrens
parents: 5331
diff changeset
  1724
/*
c40abbe796be PSARC/2007/574 zfs send -R
ahrens
parents: 5331
diff changeset
  1725
 * inputs:
c40abbe796be PSARC/2007/574 zfs send -R
ahrens
parents: 5331
diff changeset
  1726
 * zc_name		name of filesystem
c40abbe796be PSARC/2007/574 zfs send -R
ahrens
parents: 5331
diff changeset
  1727
 * zc_nvlist_src{_size}	nvlist of delegated permissions
c40abbe796be PSARC/2007/574 zfs send -R
ahrens
parents: 5331
diff changeset
  1728
 * zc_perm_action	allow/unallow flag
c40abbe796be PSARC/2007/574 zfs send -R
ahrens
parents: 5331
diff changeset
  1729
 *
c40abbe796be PSARC/2007/574 zfs send -R
ahrens
parents: 5331
diff changeset
  1730
 * outputs:		none
c40abbe796be PSARC/2007/574 zfs send -R
ahrens
parents: 5331
diff changeset
  1731
 */
4543
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  1732
static int
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  1733
zfs_ioc_set_fsacl(zfs_cmd_t *zc)
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  1734
{
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  1735
	int error;
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  1736
	nvlist_t *fsaclnv = NULL;
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  1737
5094
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
  1738
	if ((error = get_nvlist(zc->zc_nvlist_src, zc->zc_nvlist_src_size,
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
  1739
	    &fsaclnv)) != 0)
4543
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  1740
		return (error);
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  1741
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  1742
	/*
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  1743
	 * Verify nvlist is constructed correctly
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  1744
	 */
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  1745
	if ((error = zfs_deleg_verify_nvlist(fsaclnv)) != 0) {
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  1746
		nvlist_free(fsaclnv);
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  1747
		return (EINVAL);
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  1748
	}
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  1749
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  1750
	/*
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  1751
	 * If we don't have PRIV_SYS_MOUNT, then validate
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  1752
	 * that user is allowed to hand out each permission in
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  1753
	 * the nvlist(s)
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  1754
	 */
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  1755
4787
602d3f97842c 6393351 unique_* could be improved
ahrens
parents: 4720
diff changeset
  1756
	error = secpolicy_zfs(CRED());
4543
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  1757
	if (error) {
4787
602d3f97842c 6393351 unique_* could be improved
ahrens
parents: 4720
diff changeset
  1758
		if (zc->zc_perm_action == B_FALSE) {
602d3f97842c 6393351 unique_* could be improved
ahrens
parents: 4720
diff changeset
  1759
			error = dsl_deleg_can_allow(zc->zc_name,
602d3f97842c 6393351 unique_* could be improved
ahrens
parents: 4720
diff changeset
  1760
			    fsaclnv, CRED());
602d3f97842c 6393351 unique_* could be improved
ahrens
parents: 4720
diff changeset
  1761
		} else {
602d3f97842c 6393351 unique_* could be improved
ahrens
parents: 4720
diff changeset
  1762
			error = dsl_deleg_can_unallow(zc->zc_name,
602d3f97842c 6393351 unique_* could be improved
ahrens
parents: 4720
diff changeset
  1763
			    fsaclnv, CRED());
602d3f97842c 6393351 unique_* could be improved
ahrens
parents: 4720
diff changeset
  1764
		}
4543
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  1765
	}
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  1766
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  1767
	if (error == 0)
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  1768
		error = dsl_deleg_set(zc->zc_name, fsaclnv, zc->zc_perm_action);
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  1769
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  1770
	nvlist_free(fsaclnv);
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  1771
	return (error);
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  1772
}
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  1773
5367
c40abbe796be PSARC/2007/574 zfs send -R
ahrens
parents: 5331
diff changeset
  1774
/*
c40abbe796be PSARC/2007/574 zfs send -R
ahrens
parents: 5331
diff changeset
  1775
 * inputs:
c40abbe796be PSARC/2007/574 zfs send -R
ahrens
parents: 5331
diff changeset
  1776
 * zc_name		name of filesystem
c40abbe796be PSARC/2007/574 zfs send -R
ahrens
parents: 5331
diff changeset
  1777
 *
c40abbe796be PSARC/2007/574 zfs send -R
ahrens
parents: 5331
diff changeset
  1778
 * outputs:
c40abbe796be PSARC/2007/574 zfs send -R
ahrens
parents: 5331
diff changeset
  1779
 * zc_nvlist_src{_size}	nvlist of delegated permissions
c40abbe796be PSARC/2007/574 zfs send -R
ahrens
parents: 5331
diff changeset
  1780
 */
4543
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  1781
static int
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  1782
zfs_ioc_get_fsacl(zfs_cmd_t *zc)
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  1783
{
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  1784
	nvlist_t *nvp;
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  1785
	int error;
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  1786
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  1787
	if ((error = dsl_deleg_get(zc->zc_name, &nvp)) == 0) {
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  1788
		error = put_nvlist(zc, nvp);
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  1789
		nvlist_free(nvp);
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  1790
	}
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  1791
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  1792
	return (error);
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  1793
}
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  1794
5367
c40abbe796be PSARC/2007/574 zfs send -R
ahrens
parents: 5331
diff changeset
  1795
/*
c40abbe796be PSARC/2007/574 zfs send -R
ahrens
parents: 5331
diff changeset
  1796
 * inputs:
c40abbe796be PSARC/2007/574 zfs send -R
ahrens
parents: 5331
diff changeset
  1797
 * zc_name		name of volume
c40abbe796be PSARC/2007/574 zfs send -R
ahrens
parents: 5331
diff changeset
  1798
 *
c40abbe796be PSARC/2007/574 zfs send -R
ahrens
parents: 5331
diff changeset
  1799
 * outputs:		none
c40abbe796be PSARC/2007/574 zfs send -R
ahrens
parents: 5331
diff changeset
  1800
 */
4543
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  1801
static int
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1802
zfs_ioc_create_minor(zfs_cmd_t *zc)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1803
{
4787
602d3f97842c 6393351 unique_* could be improved
ahrens
parents: 4720
diff changeset
  1804
	return (zvol_create_minor(zc->zc_name, ddi_driver_major(zfs_dip)));
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1805
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1806
5367
c40abbe796be PSARC/2007/574 zfs send -R
ahrens
parents: 5331
diff changeset
  1807
/*
c40abbe796be PSARC/2007/574 zfs send -R
ahrens
parents: 5331
diff changeset
  1808
 * inputs:
c40abbe796be PSARC/2007/574 zfs send -R
ahrens
parents: 5331
diff changeset
  1809
 * zc_name		name of volume
c40abbe796be PSARC/2007/574 zfs send -R
ahrens
parents: 5331
diff changeset
  1810
 *
c40abbe796be PSARC/2007/574 zfs send -R
ahrens
parents: 5331
diff changeset
  1811
 * outputs:		none
c40abbe796be PSARC/2007/574 zfs send -R
ahrens
parents: 5331
diff changeset
  1812
 */
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1813
static int
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1814
zfs_ioc_remove_minor(zfs_cmd_t *zc)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1815
{
2676
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  1816
	return (zvol_remove_minor(zc->zc_name));
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1817
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1818
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1819
/*
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1820
 * Search the vfs list for a specified resource.  Returns a pointer to it
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1821
 * or NULL if no suitable entry is found. The caller of this routine
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1822
 * is responsible for releasing the returned vfs pointer.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1823
 */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1824
static vfs_t *
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1825
zfs_get_vfs(const char *resource)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1826
{
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1827
	struct vfs *vfsp;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1828
	struct vfs *vfs_found = NULL;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1829
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1830
	vfs_list_read_lock();
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1831
	vfsp = rootvfs;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1832
	do {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1833
		if (strcmp(refstr_value(vfsp->vfs_resource), resource) == 0) {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1834
			VFS_HOLD(vfsp);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1835
			vfs_found = vfsp;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1836
			break;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1837
		}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1838
		vfsp = vfsp->vfs_next;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1839
	} while (vfsp != rootvfs);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1840
	vfs_list_unlock();
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1841
	return (vfs_found);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1842
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1843
4543
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  1844
/* ARGSUSED */
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1845
static void
4543
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  1846
zfs_create_cb(objset_t *os, void *arg, cred_t *cr, dmu_tx_t *tx)
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1847
{
5331
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
  1848
	zfs_creat_t *zct = arg;
5498
334b476844ca 6622831 normalization properties are not preserved by "zfs send"
timh
parents: 5450
diff changeset
  1849
334b476844ca 6622831 normalization properties are not preserved by "zfs send"
timh
parents: 5450
diff changeset
  1850
	zfs_create_fs(os, cr, zct->zct_zplprops, tx);
5331
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
  1851
}
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
  1852
5498
334b476844ca 6622831 normalization properties are not preserved by "zfs send"
timh
parents: 5450
diff changeset
  1853
#define	ZFS_PROP_UNDEFINED	((uint64_t)-1)
334b476844ca 6622831 normalization properties are not preserved by "zfs send"
timh
parents: 5450
diff changeset
  1854
5331
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
  1855
/*
5498
334b476844ca 6622831 normalization properties are not preserved by "zfs send"
timh
parents: 5450
diff changeset
  1856
 * inputs:
7184
9508660f9c27 PSARC 2008/223 Pool root file system properties via zpool(1M)
timh
parents: 7046
diff changeset
  1857
 * createprops		list of properties requested by creator
9508660f9c27 PSARC 2008/223 Pool root file system properties via zpool(1M)
timh
parents: 7046
diff changeset
  1858
 * default_zplver	zpl version to use if unspecified in createprops
9508660f9c27 PSARC 2008/223 Pool root file system properties via zpool(1M)
timh
parents: 7046
diff changeset
  1859
 * fuids_ok		fuids allowed in this version of the spa?
9508660f9c27 PSARC 2008/223 Pool root file system properties via zpool(1M)
timh
parents: 7046
diff changeset
  1860
 * os			parent objset pointer (NULL if root fs)
5331
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
  1861
 *
5498
334b476844ca 6622831 normalization properties are not preserved by "zfs send"
timh
parents: 5450
diff changeset
  1862
 * outputs:
334b476844ca 6622831 normalization properties are not preserved by "zfs send"
timh
parents: 5450
diff changeset
  1863
 * zplprops	values for the zplprops we attach to the master node object
7184
9508660f9c27 PSARC 2008/223 Pool root file system properties via zpool(1M)
timh
parents: 7046
diff changeset
  1864
 * is_ci	true if requested file system will be purely case-insensitive
5331
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
  1865
 *
5498
334b476844ca 6622831 normalization properties are not preserved by "zfs send"
timh
parents: 5450
diff changeset
  1866
 * Determine the settings for utf8only, normalization and
334b476844ca 6622831 normalization properties are not preserved by "zfs send"
timh
parents: 5450
diff changeset
  1867
 * casesensitivity.  Specific values may have been requested by the
334b476844ca 6622831 normalization properties are not preserved by "zfs send"
timh
parents: 5450
diff changeset
  1868
 * creator and/or we can inherit values from the parent dataset.  If
334b476844ca 6622831 normalization properties are not preserved by "zfs send"
timh
parents: 5450
diff changeset
  1869
 * the file system is of too early a vintage, a creator can not
334b476844ca 6622831 normalization properties are not preserved by "zfs send"
timh
parents: 5450
diff changeset
  1870
 * request settings for these properties, even if the requested
334b476844ca 6622831 normalization properties are not preserved by "zfs send"
timh
parents: 5450
diff changeset
  1871
 * setting is the default value.  We don't actually want to create dsl
334b476844ca 6622831 normalization properties are not preserved by "zfs send"
timh
parents: 5450
diff changeset
  1872
 * properties for these, so remove them from the source nvlist after
334b476844ca 6622831 normalization properties are not preserved by "zfs send"
timh
parents: 5450
diff changeset
  1873
 * processing.
5331
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
  1874
 */
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
  1875
static int
7184
9508660f9c27 PSARC 2008/223 Pool root file system properties via zpool(1M)
timh
parents: 7046
diff changeset
  1876
zfs_fill_zplprops_impl(objset_t *os, uint64_t default_zplver,
9508660f9c27 PSARC 2008/223 Pool root file system properties via zpool(1M)
timh
parents: 7046
diff changeset
  1877
    boolean_t fuids_ok, nvlist_t *createprops, nvlist_t *zplprops,
9508660f9c27 PSARC 2008/223 Pool root file system properties via zpool(1M)
timh
parents: 7046
diff changeset
  1878
    boolean_t *is_ci)
5331
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
  1879
{
7184
9508660f9c27 PSARC 2008/223 Pool root file system properties via zpool(1M)
timh
parents: 7046
diff changeset
  1880
	uint64_t zplver = default_zplver;
5498
334b476844ca 6622831 normalization properties are not preserved by "zfs send"
timh
parents: 5450
diff changeset
  1881
	uint64_t sense = ZFS_PROP_UNDEFINED;
334b476844ca 6622831 normalization properties are not preserved by "zfs send"
timh
parents: 5450
diff changeset
  1882
	uint64_t norm = ZFS_PROP_UNDEFINED;
334b476844ca 6622831 normalization properties are not preserved by "zfs send"
timh
parents: 5450
diff changeset
  1883
	uint64_t u8 = ZFS_PROP_UNDEFINED;
334b476844ca 6622831 normalization properties are not preserved by "zfs send"
timh
parents: 5450
diff changeset
  1884
334b476844ca 6622831 normalization properties are not preserved by "zfs send"
timh
parents: 5450
diff changeset
  1885
	ASSERT(zplprops != NULL);
334b476844ca 6622831 normalization properties are not preserved by "zfs send"
timh
parents: 5450
diff changeset
  1886
5375
c682f8c5f5e3 6622822 can not create clone on old version pool
timh
parents: 5367
diff changeset
  1887
	/*
5498
334b476844ca 6622831 normalization properties are not preserved by "zfs send"
timh
parents: 5450
diff changeset
  1888
	 * Pull out creator prop choices, if any.
5375
c682f8c5f5e3 6622822 can not create clone on old version pool
timh
parents: 5367
diff changeset
  1889
	 */
5498
334b476844ca 6622831 normalization properties are not preserved by "zfs send"
timh
parents: 5450
diff changeset
  1890
	if (createprops) {
334b476844ca 6622831 normalization properties are not preserved by "zfs send"
timh
parents: 5450
diff changeset
  1891
		(void) nvlist_lookup_uint64(createprops,
7184
9508660f9c27 PSARC 2008/223 Pool root file system properties via zpool(1M)
timh
parents: 7046
diff changeset
  1892
		    zfs_prop_to_name(ZFS_PROP_VERSION), &zplver);
9508660f9c27 PSARC 2008/223 Pool root file system properties via zpool(1M)
timh
parents: 7046
diff changeset
  1893
		(void) nvlist_lookup_uint64(createprops,
5498
334b476844ca 6622831 normalization properties are not preserved by "zfs send"
timh
parents: 5450
diff changeset
  1894
		    zfs_prop_to_name(ZFS_PROP_NORMALIZE), &norm);
334b476844ca 6622831 normalization properties are not preserved by "zfs send"
timh
parents: 5450
diff changeset
  1895
		(void) nvlist_remove_all(createprops,
334b476844ca 6622831 normalization properties are not preserved by "zfs send"
timh
parents: 5450
diff changeset
  1896
		    zfs_prop_to_name(ZFS_PROP_NORMALIZE));
334b476844ca 6622831 normalization properties are not preserved by "zfs send"
timh
parents: 5450
diff changeset
  1897
		(void) nvlist_lookup_uint64(createprops,
334b476844ca 6622831 normalization properties are not preserved by "zfs send"
timh
parents: 5450
diff changeset
  1898
		    zfs_prop_to_name(ZFS_PROP_UTF8ONLY), &u8);
334b476844ca 6622831 normalization properties are not preserved by "zfs send"
timh
parents: 5450
diff changeset
  1899
		(void) nvlist_remove_all(createprops,
334b476844ca 6622831 normalization properties are not preserved by "zfs send"
timh
parents: 5450
diff changeset
  1900
		    zfs_prop_to_name(ZFS_PROP_UTF8ONLY));
334b476844ca 6622831 normalization properties are not preserved by "zfs send"
timh
parents: 5450
diff changeset
  1901
		(void) nvlist_lookup_uint64(createprops,
334b476844ca 6622831 normalization properties are not preserved by "zfs send"
timh
parents: 5450
diff changeset
  1902
		    zfs_prop_to_name(ZFS_PROP_CASE), &sense);
334b476844ca 6622831 normalization properties are not preserved by "zfs send"
timh
parents: 5450
diff changeset
  1903
		(void) nvlist_remove_all(createprops,
334b476844ca 6622831 normalization properties are not preserved by "zfs send"
timh
parents: 5450
diff changeset
  1904
		    zfs_prop_to_name(ZFS_PROP_CASE));
5331
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
  1905
	}
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
  1906
5375
c682f8c5f5e3 6622822 can not create clone on old version pool
timh
parents: 5367
diff changeset
  1907
	/*
7184
9508660f9c27 PSARC 2008/223 Pool root file system properties via zpool(1M)
timh
parents: 7046
diff changeset
  1908
	 * If the zpl version requested is whacky or the file system
9508660f9c27 PSARC 2008/223 Pool root file system properties via zpool(1M)
timh
parents: 7046
diff changeset
  1909
	 * or pool is version is too "young" to support normalization
9508660f9c27 PSARC 2008/223 Pool root file system properties via zpool(1M)
timh
parents: 7046
diff changeset
  1910
	 * and the creator tried to set a value for one of the props,
9508660f9c27 PSARC 2008/223 Pool root file system properties via zpool(1M)
timh
parents: 7046
diff changeset
  1911
	 * error out.
5498
334b476844ca 6622831 normalization properties are not preserved by "zfs send"
timh
parents: 5450
diff changeset
  1912
	 */
7184
9508660f9c27 PSARC 2008/223 Pool root file system properties via zpool(1M)
timh
parents: 7046
diff changeset
  1913
	if ((zplver < ZPL_VERSION_INITIAL || zplver > ZPL_VERSION) ||
9508660f9c27 PSARC 2008/223 Pool root file system properties via zpool(1M)
timh
parents: 7046
diff changeset
  1914
	    (zplver >= ZPL_VERSION_FUID && !fuids_ok) ||
9508660f9c27 PSARC 2008/223 Pool root file system properties via zpool(1M)
timh
parents: 7046
diff changeset
  1915
	    (zplver < ZPL_VERSION_NORMALIZATION &&
5498
334b476844ca 6622831 normalization properties are not preserved by "zfs send"
timh
parents: 5450
diff changeset
  1916
	    (norm != ZFS_PROP_UNDEFINED || u8 != ZFS_PROP_UNDEFINED ||
7184
9508660f9c27 PSARC 2008/223 Pool root file system properties via zpool(1M)
timh
parents: 7046
diff changeset
  1917
	    sense != ZFS_PROP_UNDEFINED)))
5498
334b476844ca 6622831 normalization properties are not preserved by "zfs send"
timh
parents: 5450
diff changeset
  1918
		return (ENOTSUP);
334b476844ca 6622831 normalization properties are not preserved by "zfs send"
timh
parents: 5450
diff changeset
  1919
334b476844ca 6622831 normalization properties are not preserved by "zfs send"
timh
parents: 5450
diff changeset
  1920
	/*
334b476844ca 6622831 normalization properties are not preserved by "zfs send"
timh
parents: 5450
diff changeset
  1921
	 * Put the version in the zplprops
334b476844ca 6622831 normalization properties are not preserved by "zfs send"
timh
parents: 5450
diff changeset
  1922
	 */
334b476844ca 6622831 normalization properties are not preserved by "zfs send"
timh
parents: 5450
diff changeset
  1923
	VERIFY(nvlist_add_uint64(zplprops,
334b476844ca 6622831 normalization properties are not preserved by "zfs send"
timh
parents: 5450
diff changeset
  1924
	    zfs_prop_to_name(ZFS_PROP_VERSION), zplver) == 0);
334b476844ca 6622831 normalization properties are not preserved by "zfs send"
timh
parents: 5450
diff changeset
  1925
334b476844ca 6622831 normalization properties are not preserved by "zfs send"
timh
parents: 5450
diff changeset
  1926
	if (norm == ZFS_PROP_UNDEFINED)
334b476844ca 6622831 normalization properties are not preserved by "zfs send"
timh
parents: 5450
diff changeset
  1927
		VERIFY(zfs_get_zplprop(os, ZFS_PROP_NORMALIZE, &norm) == 0);
334b476844ca 6622831 normalization properties are not preserved by "zfs send"
timh
parents: 5450
diff changeset
  1928
	VERIFY(nvlist_add_uint64(zplprops,
334b476844ca 6622831 normalization properties are not preserved by "zfs send"
timh
parents: 5450
diff changeset
  1929
	    zfs_prop_to_name(ZFS_PROP_NORMALIZE), norm) == 0);
334b476844ca 6622831 normalization properties are not preserved by "zfs send"
timh
parents: 5450
diff changeset
  1930
334b476844ca 6622831 normalization properties are not preserved by "zfs send"
timh
parents: 5450
diff changeset
  1931
	/*
334b476844ca 6622831 normalization properties are not preserved by "zfs send"
timh
parents: 5450
diff changeset
  1932
	 * If we're normalizing, names must always be valid UTF-8 strings.
334b476844ca 6622831 normalization properties are not preserved by "zfs send"
timh
parents: 5450
diff changeset
  1933
	 */
334b476844ca 6622831 normalization properties are not preserved by "zfs send"
timh
parents: 5450
diff changeset
  1934
	if (norm)
334b476844ca 6622831 normalization properties are not preserved by "zfs send"
timh
parents: 5450
diff changeset
  1935
		u8 = 1;
334b476844ca 6622831 normalization properties are not preserved by "zfs send"
timh
parents: 5450
diff changeset
  1936
	if (u8 == ZFS_PROP_UNDEFINED)
334b476844ca 6622831 normalization properties are not preserved by "zfs send"
timh
parents: 5450
diff changeset
  1937
		VERIFY(zfs_get_zplprop(os, ZFS_PROP_UTF8ONLY, &u8) == 0);
334b476844ca 6622831 normalization properties are not preserved by "zfs send"
timh
parents: 5450
diff changeset
  1938
	VERIFY(nvlist_add_uint64(zplprops,
334b476844ca 6622831 normalization properties are not preserved by "zfs send"
timh
parents: 5450
diff changeset
  1939
	    zfs_prop_to_name(ZFS_PROP_UTF8ONLY), u8) == 0);
334b476844ca 6622831 normalization properties are not preserved by "zfs send"
timh
parents: 5450
diff changeset
  1940
334b476844ca 6622831 normalization properties are not preserved by "zfs send"
timh
parents: 5450
diff changeset
  1941
	if (sense == ZFS_PROP_UNDEFINED)
334b476844ca 6622831 normalization properties are not preserved by "zfs send"
timh
parents: 5450
diff changeset
  1942
		VERIFY(zfs_get_zplprop(os, ZFS_PROP_CASE, &sense) == 0);
334b476844ca 6622831 normalization properties are not preserved by "zfs send"
timh
parents: 5450
diff changeset
  1943
	VERIFY(nvlist_add_uint64(zplprops,
334b476844ca 6622831 normalization properties are not preserved by "zfs send"
timh
parents: 5450
diff changeset
  1944
	    zfs_prop_to_name(ZFS_PROP_CASE), sense) == 0);
334b476844ca 6622831 normalization properties are not preserved by "zfs send"
timh
parents: 5450
diff changeset
  1945
6492
903545192033 6654808 FIGNORECASE lookups in a zfs xattr dir don't provide 'realname' data
timh
parents: 6423
diff changeset
  1946
	if (is_ci)
903545192033 6654808 FIGNORECASE lookups in a zfs xattr dir don't provide 'realname' data
timh
parents: 6423
diff changeset
  1947
		*is_ci = (sense == ZFS_CASE_INSENSITIVE);
903545192033 6654808 FIGNORECASE lookups in a zfs xattr dir don't provide 'realname' data
timh
parents: 6423
diff changeset
  1948
7184
9508660f9c27 PSARC 2008/223 Pool root file system properties via zpool(1M)
timh
parents: 7046
diff changeset
  1949
	return (0);
9508660f9c27 PSARC 2008/223 Pool root file system properties via zpool(1M)
timh
parents: 7046
diff changeset
  1950
}
9508660f9c27 PSARC 2008/223 Pool root file system properties via zpool(1M)
timh
parents: 7046
diff changeset
  1951
9508660f9c27 PSARC 2008/223 Pool root file system properties via zpool(1M)
timh
parents: 7046
diff changeset
  1952
static int
9508660f9c27 PSARC 2008/223 Pool root file system properties via zpool(1M)
timh
parents: 7046
diff changeset
  1953
zfs_fill_zplprops(const char *dataset, nvlist_t *createprops,
9508660f9c27 PSARC 2008/223 Pool root file system properties via zpool(1M)
timh
parents: 7046
diff changeset
  1954
    nvlist_t *zplprops, boolean_t *is_ci)
9508660f9c27 PSARC 2008/223 Pool root file system properties via zpool(1M)
timh
parents: 7046
diff changeset
  1955
{
9508660f9c27 PSARC 2008/223 Pool root file system properties via zpool(1M)
timh
parents: 7046
diff changeset
  1956
	boolean_t fuids_ok = B_TRUE;
9508660f9c27 PSARC 2008/223 Pool root file system properties via zpool(1M)
timh
parents: 7046
diff changeset
  1957
	uint64_t zplver = ZPL_VERSION;
9508660f9c27 PSARC 2008/223 Pool root file system properties via zpool(1M)
timh
parents: 7046
diff changeset
  1958
	objset_t *os = NULL;
9508660f9c27 PSARC 2008/223 Pool root file system properties via zpool(1M)
timh
parents: 7046
diff changeset
  1959
	char parentname[MAXNAMELEN];
9508660f9c27 PSARC 2008/223 Pool root file system properties via zpool(1M)
timh
parents: 7046
diff changeset
  1960
	char *cp;
9508660f9c27 PSARC 2008/223 Pool root file system properties via zpool(1M)
timh
parents: 7046
diff changeset
  1961
	int error;
9508660f9c27 PSARC 2008/223 Pool root file system properties via zpool(1M)
timh
parents: 7046
diff changeset
  1962
9508660f9c27 PSARC 2008/223 Pool root file system properties via zpool(1M)
timh
parents: 7046
diff changeset
  1963
	(void) strlcpy(parentname, dataset, sizeof (parentname));
9508660f9c27 PSARC 2008/223 Pool root file system properties via zpool(1M)
timh
parents: 7046
diff changeset
  1964
	cp = strrchr(parentname, '/');
9508660f9c27 PSARC 2008/223 Pool root file system properties via zpool(1M)
timh
parents: 7046
diff changeset
  1965
	ASSERT(cp != NULL);
9508660f9c27 PSARC 2008/223 Pool root file system properties via zpool(1M)
timh
parents: 7046
diff changeset
  1966
	cp[0] = '\0';
9508660f9c27 PSARC 2008/223 Pool root file system properties via zpool(1M)
timh
parents: 7046
diff changeset
  1967
9508660f9c27 PSARC 2008/223 Pool root file system properties via zpool(1M)
timh
parents: 7046
diff changeset
  1968
	if (zfs_earlier_version(dataset, SPA_VERSION_FUID)) {
9508660f9c27 PSARC 2008/223 Pool root file system properties via zpool(1M)
timh
parents: 7046
diff changeset
  1969
		zplver = ZPL_VERSION_FUID - 1;
9508660f9c27 PSARC 2008/223 Pool root file system properties via zpool(1M)
timh
parents: 7046
diff changeset
  1970
		fuids_ok = B_FALSE;
9508660f9c27 PSARC 2008/223 Pool root file system properties via zpool(1M)
timh
parents: 7046
diff changeset
  1971
	}
9508660f9c27 PSARC 2008/223 Pool root file system properties via zpool(1M)
timh
parents: 7046
diff changeset
  1972
9508660f9c27 PSARC 2008/223 Pool root file system properties via zpool(1M)
timh
parents: 7046
diff changeset
  1973
	/*
9508660f9c27 PSARC 2008/223 Pool root file system properties via zpool(1M)
timh
parents: 7046
diff changeset
  1974
	 * Open parent object set so we can inherit zplprop values.
9508660f9c27 PSARC 2008/223 Pool root file system properties via zpool(1M)
timh
parents: 7046
diff changeset
  1975
	 */
9508660f9c27 PSARC 2008/223 Pool root file system properties via zpool(1M)
timh
parents: 7046
diff changeset
  1976
	if ((error = dmu_objset_open(parentname, DMU_OST_ANY,
9508660f9c27 PSARC 2008/223 Pool root file system properties via zpool(1M)
timh
parents: 7046
diff changeset
  1977
	    DS_MODE_USER | DS_MODE_READONLY, &os)) != 0)
9508660f9c27 PSARC 2008/223 Pool root file system properties via zpool(1M)
timh
parents: 7046
diff changeset
  1978
		return (error);
9508660f9c27 PSARC 2008/223 Pool root file system properties via zpool(1M)
timh
parents: 7046
diff changeset
  1979
9508660f9c27 PSARC 2008/223 Pool root file system properties via zpool(1M)
timh
parents: 7046
diff changeset
  1980
	error = zfs_fill_zplprops_impl(os, zplver, fuids_ok, createprops,
9508660f9c27 PSARC 2008/223 Pool root file system properties via zpool(1M)
timh
parents: 7046
diff changeset
  1981
	    zplprops, is_ci);
5498
334b476844ca 6622831 normalization properties are not preserved by "zfs send"
timh
parents: 5450
diff changeset
  1982
	dmu_objset_close(os);
7184
9508660f9c27 PSARC 2008/223 Pool root file system properties via zpool(1M)
timh
parents: 7046
diff changeset
  1983
	return (error);
9508660f9c27 PSARC 2008/223 Pool root file system properties via zpool(1M)
timh
parents: 7046
diff changeset
  1984
}
9508660f9c27 PSARC 2008/223 Pool root file system properties via zpool(1M)
timh
parents: 7046
diff changeset
  1985
9508660f9c27 PSARC 2008/223 Pool root file system properties via zpool(1M)
timh
parents: 7046
diff changeset
  1986
static int
9508660f9c27 PSARC 2008/223 Pool root file system properties via zpool(1M)
timh
parents: 7046
diff changeset
  1987
zfs_fill_zplprops_root(uint64_t spa_vers, nvlist_t *createprops,
9508660f9c27 PSARC 2008/223 Pool root file system properties via zpool(1M)
timh
parents: 7046
diff changeset
  1988
    nvlist_t *zplprops, boolean_t *is_ci)
9508660f9c27 PSARC 2008/223 Pool root file system properties via zpool(1M)
timh
parents: 7046
diff changeset
  1989
{
9508660f9c27 PSARC 2008/223 Pool root file system properties via zpool(1M)
timh
parents: 7046
diff changeset
  1990
	boolean_t fuids_ok = B_TRUE;
9508660f9c27 PSARC 2008/223 Pool root file system properties via zpool(1M)
timh
parents: 7046
diff changeset
  1991
	uint64_t zplver = ZPL_VERSION;
9508660f9c27 PSARC 2008/223 Pool root file system properties via zpool(1M)
timh
parents: 7046
diff changeset
  1992
	int error;
9508660f9c27 PSARC 2008/223 Pool root file system properties via zpool(1M)
timh
parents: 7046
diff changeset
  1993
9508660f9c27 PSARC 2008/223 Pool root file system properties via zpool(1M)
timh
parents: 7046
diff changeset
  1994
	if (spa_vers < SPA_VERSION_FUID) {
9508660f9c27 PSARC 2008/223 Pool root file system properties via zpool(1M)
timh
parents: 7046
diff changeset
  1995
		zplver = ZPL_VERSION_FUID - 1;
9508660f9c27 PSARC 2008/223 Pool root file system properties via zpool(1M)
timh
parents: 7046
diff changeset
  1996
		fuids_ok = B_FALSE;
9508660f9c27 PSARC 2008/223 Pool root file system properties via zpool(1M)
timh
parents: 7046
diff changeset
  1997
	}
9508660f9c27 PSARC 2008/223 Pool root file system properties via zpool(1M)
timh
parents: 7046
diff changeset
  1998
9508660f9c27 PSARC 2008/223 Pool root file system properties via zpool(1M)
timh
parents: 7046
diff changeset
  1999
	error = zfs_fill_zplprops_impl(NULL, zplver, fuids_ok, createprops,
9508660f9c27 PSARC 2008/223 Pool root file system properties via zpool(1M)
timh
parents: 7046
diff changeset
  2000
	    zplprops, is_ci);
9508660f9c27 PSARC 2008/223 Pool root file system properties via zpool(1M)
timh
parents: 7046
diff changeset
  2001
	return (error);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2002
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2003
5367
c40abbe796be PSARC/2007/574 zfs send -R
ahrens
parents: 5331
diff changeset
  2004
/*
c40abbe796be PSARC/2007/574 zfs send -R
ahrens
parents: 5331
diff changeset
  2005
 * inputs:
c40abbe796be PSARC/2007/574 zfs send -R
ahrens
parents: 5331
diff changeset
  2006
 * zc_objset_type	type of objset to create (fs vs zvol)
c40abbe796be PSARC/2007/574 zfs send -R
ahrens
parents: 5331
diff changeset
  2007
 * zc_name		name of new objset
c40abbe796be PSARC/2007/574 zfs send -R
ahrens
parents: 5331
diff changeset
  2008
 * zc_value		name of snapshot to clone from (may be empty)
c40abbe796be PSARC/2007/574 zfs send -R
ahrens
parents: 5331
diff changeset
  2009
 * zc_nvlist_src{_size}	nvlist of properties to apply
c40abbe796be PSARC/2007/574 zfs send -R
ahrens
parents: 5331
diff changeset
  2010
 *
5498
334b476844ca 6622831 normalization properties are not preserved by "zfs send"
timh
parents: 5450
diff changeset
  2011
 * outputs: none
5367
c40abbe796be PSARC/2007/574 zfs send -R
ahrens
parents: 5331
diff changeset
  2012
 */
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2013
static int
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2014
zfs_ioc_create(zfs_cmd_t *zc)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2015
{
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2016
	objset_t *clone;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2017
	int error = 0;
5331
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
  2018
	zfs_creat_t zct;
4543
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  2019
	nvlist_t *nvprops = NULL;
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  2020
	void (*cbfunc)(objset_t *os, void *arg, cred_t *cr, dmu_tx_t *tx);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2021
	dmu_objset_type_t type = zc->zc_objset_type;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2022
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2023
	switch (type) {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2024
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2025
	case DMU_OST_ZFS:
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2026
		cbfunc = zfs_create_cb;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2027
		break;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2028
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2029
	case DMU_OST_ZVOL:
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2030
		cbfunc = zvol_create_cb;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2031
		break;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2032
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2033
	default:
2199
712a788c2dfd PSARC 2006/388 snapshot -r
ahrens
parents: 2082
diff changeset
  2034
		cbfunc = NULL;
6423
437422a29d3a PSARC 2006/370 ZFS Boot Support
gw25295
parents: 6139
diff changeset
  2035
		break;
2199
712a788c2dfd PSARC 2006/388 snapshot -r
ahrens
parents: 2082
diff changeset
  2036
	}
5326
6752aa2bd5bc 6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents: 5147
diff changeset
  2037
	if (strchr(zc->zc_name, '@') ||
6752aa2bd5bc 6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents: 5147
diff changeset
  2038
	    strchr(zc->zc_name, '%'))
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2039
		return (EINVAL);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2040
2676
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  2041
	if (zc->zc_nvlist_src != NULL &&
5094
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
  2042
	    (error = get_nvlist(zc->zc_nvlist_src, zc->zc_nvlist_src_size,
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
  2043
	    &nvprops)) != 0)
2676
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  2044
		return (error);
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  2045
5498
334b476844ca 6622831 normalization properties are not preserved by "zfs send"
timh
parents: 5450
diff changeset
  2046
	zct.zct_zplprops = NULL;
5331
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
  2047
	zct.zct_props = nvprops;
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
  2048
2676
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  2049
	if (zc->zc_value[0] != '\0') {
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2050
		/*
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2051
		 * We're creating a clone of an existing snapshot.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2052
		 */
2676
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  2053
		zc->zc_value[sizeof (zc->zc_value) - 1] = '\0';
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  2054
		if (dataset_namecheck(zc->zc_value, NULL, NULL) != 0) {
4543
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  2055
			nvlist_free(nvprops);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2056
			return (EINVAL);
2676
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  2057
		}
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2058
2676
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  2059
		error = dmu_objset_open(zc->zc_value, type,
6689
47572a2f5e73 6610506 Eliminate or improve retry logic from callers of dmu_objset_open()
maybee
parents: 6643
diff changeset
  2060
		    DS_MODE_USER | DS_MODE_READONLY, &clone);
2676
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  2061
		if (error) {
4543
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  2062
			nvlist_free(nvprops);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2063
			return (error);
2676
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  2064
		}
6492
903545192033 6654808 FIGNORECASE lookups in a zfs xattr dir don't provide 'realname' data
timh
parents: 6423
diff changeset
  2065
903545192033 6654808 FIGNORECASE lookups in a zfs xattr dir don't provide 'realname' data
timh
parents: 6423
diff changeset
  2066
		error = dmu_objset_create(zc->zc_name, type, clone, 0,
903545192033 6654808 FIGNORECASE lookups in a zfs xattr dir don't provide 'realname' data
timh
parents: 6423
diff changeset
  2067
		    NULL, NULL);
5331
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
  2068
		if (error) {
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
  2069
			dmu_objset_close(clone);
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
  2070
			nvlist_free(nvprops);
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
  2071
			return (error);
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
  2072
		}
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2073
		dmu_objset_close(clone);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2074
	} else {
6492
903545192033 6654808 FIGNORECASE lookups in a zfs xattr dir don't provide 'realname' data
timh
parents: 6423
diff changeset
  2075
		boolean_t is_insensitive = B_FALSE;
903545192033 6654808 FIGNORECASE lookups in a zfs xattr dir don't provide 'realname' data
timh
parents: 6423
diff changeset
  2076
2676
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  2077
		if (cbfunc == NULL) {
4543
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  2078
			nvlist_free(nvprops);
2199
712a788c2dfd PSARC 2006/388 snapshot -r
ahrens
parents: 2082
diff changeset
  2079
			return (EINVAL);
2676
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  2080
		}
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  2081
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2082
		if (type == DMU_OST_ZVOL) {
2676
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  2083
			uint64_t volsize, volblocksize;
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  2084
4543
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  2085
			if (nvprops == NULL ||
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  2086
			    nvlist_lookup_uint64(nvprops,
2676
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  2087
			    zfs_prop_to_name(ZFS_PROP_VOLSIZE),
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  2088
			    &volsize) != 0) {
4543
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  2089
				nvlist_free(nvprops);
2676
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  2090
				return (EINVAL);
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  2091
			}
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  2092
4543
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  2093
			if ((error = nvlist_lookup_uint64(nvprops,
2676
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  2094
			    zfs_prop_to_name(ZFS_PROP_VOLBLOCKSIZE),
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  2095
			    &volblocksize)) != 0 && error != ENOENT) {
4543
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  2096
				nvlist_free(nvprops);
2676
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  2097
				return (EINVAL);
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  2098
			}
1133
335d069294d1 6357470 vdev_raidz.c has unused RAIDZ_SINGLE define, code
eschrock
parents: 1003
diff changeset
  2099
2676
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  2100
			if (error != 0)
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  2101
				volblocksize = zfs_prop_default_numeric(
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  2102
				    ZFS_PROP_VOLBLOCKSIZE);
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  2103
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  2104
			if ((error = zvol_check_volblocksize(
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  2105
			    volblocksize)) != 0 ||
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  2106
			    (error = zvol_check_volsize(volsize,
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  2107
			    volblocksize)) != 0) {
4543
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  2108
				nvlist_free(nvprops);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2109
				return (error);
2676
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  2110
			}
4577
ed36b0e652bc PSARC/2007/328 zfs upgrade
ahrens
parents: 4543
diff changeset
  2111
		} else if (type == DMU_OST_ZFS) {
5331
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
  2112
			int error;
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
  2113
5498
334b476844ca 6622831 normalization properties are not preserved by "zfs send"
timh
parents: 5450
diff changeset
  2114
			/*
5331
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
  2115
			 * We have to have normalization and
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
  2116
			 * case-folding flags correct when we do the
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
  2117
			 * file system creation, so go figure them out
5498
334b476844ca 6622831 normalization properties are not preserved by "zfs send"
timh
parents: 5450
diff changeset
  2118
			 * now.
5331
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
  2119
			 */
5498
334b476844ca 6622831 normalization properties are not preserved by "zfs send"
timh
parents: 5450
diff changeset
  2120
			VERIFY(nvlist_alloc(&zct.zct_zplprops,
334b476844ca 6622831 normalization properties are not preserved by "zfs send"
timh
parents: 5450
diff changeset
  2121
			    NV_UNIQUE_NAME, KM_SLEEP) == 0);
334b476844ca 6622831 normalization properties are not preserved by "zfs send"
timh
parents: 5450
diff changeset
  2122
			error = zfs_fill_zplprops(zc->zc_name, nvprops,
7184
9508660f9c27 PSARC 2008/223 Pool root file system properties via zpool(1M)
timh
parents: 7046
diff changeset
  2123
			    zct.zct_zplprops, &is_insensitive);
5331
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
  2124
			if (error != 0) {
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
  2125
				nvlist_free(nvprops);
5498
334b476844ca 6622831 normalization properties are not preserved by "zfs send"
timh
parents: 5450
diff changeset
  2126
				nvlist_free(zct.zct_zplprops);
5331
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
  2127
				return (error);
4577
ed36b0e652bc PSARC/2007/328 zfs upgrade
ahrens
parents: 4543
diff changeset
  2128
			}
2676
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  2129
		}
6492
903545192033 6654808 FIGNORECASE lookups in a zfs xattr dir don't provide 'realname' data
timh
parents: 6423
diff changeset
  2130
		error = dmu_objset_create(zc->zc_name, type, NULL,
903545192033 6654808 FIGNORECASE lookups in a zfs xattr dir don't provide 'realname' data
timh
parents: 6423
diff changeset
  2131
		    is_insensitive ? DS_FLAG_CI_DATASET : 0, cbfunc, &zct);
5498
334b476844ca 6622831 normalization properties are not preserved by "zfs send"
timh
parents: 5450
diff changeset
  2132
		nvlist_free(zct.zct_zplprops);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2133
	}
2676
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  2134
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  2135
	/*
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  2136
	 * It would be nice to do this atomically.
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  2137
	 */
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  2138
	if (error == 0) {
4787
602d3f97842c 6393351 unique_* could be improved
ahrens
parents: 4720
diff changeset
  2139
		if ((error = zfs_set_prop_nvlist(zc->zc_name, nvprops)) != 0)
2676
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  2140
			(void) dmu_objset_destroy(zc->zc_name);
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  2141
	}
4543
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  2142
	nvlist_free(nvprops);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2143
	return (error);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2144
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2145
7265
cc18862247da PSARC/2008/483 ZFS clone -o
ahrens
parents: 7214
diff changeset
  2146
struct snap_prop_arg {
cc18862247da PSARC/2008/483 ZFS clone -o
ahrens
parents: 7214
diff changeset
  2147
	nvlist_t *nvprops;
cc18862247da PSARC/2008/483 ZFS clone -o
ahrens
parents: 7214
diff changeset
  2148
	const char *snapname;
cc18862247da PSARC/2008/483 ZFS clone -o
ahrens
parents: 7214
diff changeset
  2149
};
cc18862247da PSARC/2008/483 ZFS clone -o
ahrens
parents: 7214
diff changeset
  2150
cc18862247da PSARC/2008/483 ZFS clone -o
ahrens
parents: 7214
diff changeset
  2151
static int
cc18862247da PSARC/2008/483 ZFS clone -o
ahrens
parents: 7214
diff changeset
  2152
set_snap_props(char *name, void *arg)
cc18862247da PSARC/2008/483 ZFS clone -o
ahrens
parents: 7214
diff changeset
  2153
{
cc18862247da PSARC/2008/483 ZFS clone -o
ahrens
parents: 7214
diff changeset
  2154
	struct snap_prop_arg *snpa = arg;
cc18862247da PSARC/2008/483 ZFS clone -o
ahrens
parents: 7214
diff changeset
  2155
	int len = strlen(name) + strlen(snpa->snapname) + 2;
cc18862247da PSARC/2008/483 ZFS clone -o
ahrens
parents: 7214
diff changeset
  2156
	char *buf = kmem_alloc(len, KM_SLEEP);
cc18862247da PSARC/2008/483 ZFS clone -o
ahrens
parents: 7214
diff changeset
  2157
	int err;
cc18862247da PSARC/2008/483 ZFS clone -o
ahrens
parents: 7214
diff changeset
  2158
cc18862247da PSARC/2008/483 ZFS clone -o
ahrens
parents: 7214
diff changeset
  2159
	(void) snprintf(buf, len, "%s@%s", name, snpa->snapname);
cc18862247da PSARC/2008/483 ZFS clone -o
ahrens
parents: 7214
diff changeset
  2160
	err = zfs_set_prop_nvlist(buf, snpa->nvprops);
cc18862247da PSARC/2008/483 ZFS clone -o
ahrens
parents: 7214
diff changeset
  2161
	if (err)
cc18862247da PSARC/2008/483 ZFS clone -o
ahrens
parents: 7214
diff changeset
  2162
		(void) dmu_objset_destroy(buf);
cc18862247da PSARC/2008/483 ZFS clone -o
ahrens
parents: 7214
diff changeset
  2163
	kmem_free(buf, len);
cc18862247da PSARC/2008/483 ZFS clone -o
ahrens
parents: 7214
diff changeset
  2164
	return (err);
cc18862247da PSARC/2008/483 ZFS clone -o
ahrens
parents: 7214
diff changeset
  2165
}
cc18862247da PSARC/2008/483 ZFS clone -o
ahrens
parents: 7214
diff changeset
  2166
5367
c40abbe796be PSARC/2007/574 zfs send -R
ahrens
parents: 5331
diff changeset
  2167
/*
c40abbe796be PSARC/2007/574 zfs send -R
ahrens
parents: 5331
diff changeset
  2168
 * inputs:
c40abbe796be PSARC/2007/574 zfs send -R
ahrens
parents: 5331
diff changeset
  2169
 * zc_name	name of filesystem
c40abbe796be PSARC/2007/574 zfs send -R
ahrens
parents: 5331
diff changeset
  2170
 * zc_value	short name of snapshot
c40abbe796be PSARC/2007/574 zfs send -R
ahrens
parents: 5331
diff changeset
  2171
 * zc_cookie	recursive flag
c40abbe796be PSARC/2007/574 zfs send -R
ahrens
parents: 5331
diff changeset
  2172
 *
c40abbe796be PSARC/2007/574 zfs send -R
ahrens
parents: 5331
diff changeset
  2173
 * outputs:	none
c40abbe796be PSARC/2007/574 zfs send -R
ahrens
parents: 5331
diff changeset
  2174
 */
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2175
static int
2199
712a788c2dfd PSARC 2006/388 snapshot -r
ahrens
parents: 2082
diff changeset
  2176
zfs_ioc_snapshot(zfs_cmd_t *zc)
712a788c2dfd PSARC 2006/388 snapshot -r
ahrens
parents: 2082
diff changeset
  2177
{
7265
cc18862247da PSARC/2008/483 ZFS clone -o
ahrens
parents: 7214
diff changeset
  2178
	nvlist_t *nvprops = NULL;
cc18862247da PSARC/2008/483 ZFS clone -o
ahrens
parents: 7214
diff changeset
  2179
	int error;
cc18862247da PSARC/2008/483 ZFS clone -o
ahrens
parents: 7214
diff changeset
  2180
	boolean_t recursive = zc->zc_cookie;
cc18862247da PSARC/2008/483 ZFS clone -o
ahrens
parents: 7214
diff changeset
  2181
2676
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  2182
	if (snapshot_namecheck(zc->zc_value, NULL, NULL) != 0)
2199
712a788c2dfd PSARC 2006/388 snapshot -r
ahrens
parents: 2082
diff changeset
  2183
		return (EINVAL);
7265
cc18862247da PSARC/2008/483 ZFS clone -o
ahrens
parents: 7214
diff changeset
  2184
cc18862247da PSARC/2008/483 ZFS clone -o
ahrens
parents: 7214
diff changeset
  2185
	if (zc->zc_nvlist_src != NULL &&
cc18862247da PSARC/2008/483 ZFS clone -o
ahrens
parents: 7214
diff changeset
  2186
	    (error = get_nvlist(zc->zc_nvlist_src, zc->zc_nvlist_src_size,
cc18862247da PSARC/2008/483 ZFS clone -o
ahrens
parents: 7214
diff changeset
  2187
	    &nvprops)) != 0)
cc18862247da PSARC/2008/483 ZFS clone -o
ahrens
parents: 7214
diff changeset
  2188
		return (error);
cc18862247da PSARC/2008/483 ZFS clone -o
ahrens
parents: 7214
diff changeset
  2189
cc18862247da PSARC/2008/483 ZFS clone -o
ahrens
parents: 7214
diff changeset
  2190
	error = dmu_objset_snapshot(zc->zc_name, zc->zc_value, recursive);
cc18862247da PSARC/2008/483 ZFS clone -o
ahrens
parents: 7214
diff changeset
  2191
cc18862247da PSARC/2008/483 ZFS clone -o
ahrens
parents: 7214
diff changeset
  2192
	/*
cc18862247da PSARC/2008/483 ZFS clone -o
ahrens
parents: 7214
diff changeset
  2193
	 * It would be nice to do this atomically.
cc18862247da PSARC/2008/483 ZFS clone -o
ahrens
parents: 7214
diff changeset
  2194
	 */
cc18862247da PSARC/2008/483 ZFS clone -o
ahrens
parents: 7214
diff changeset
  2195
	if (error == 0) {
cc18862247da PSARC/2008/483 ZFS clone -o
ahrens
parents: 7214
diff changeset
  2196
		struct snap_prop_arg snpa;
cc18862247da PSARC/2008/483 ZFS clone -o
ahrens
parents: 7214
diff changeset
  2197
		snpa.nvprops = nvprops;
cc18862247da PSARC/2008/483 ZFS clone -o
ahrens
parents: 7214
diff changeset
  2198
		snpa.snapname = zc->zc_value;
cc18862247da PSARC/2008/483 ZFS clone -o
ahrens
parents: 7214
diff changeset
  2199
		if (recursive) {
cc18862247da PSARC/2008/483 ZFS clone -o
ahrens
parents: 7214
diff changeset
  2200
			error = dmu_objset_find(zc->zc_name,
cc18862247da PSARC/2008/483 ZFS clone -o
ahrens
parents: 7214
diff changeset
  2201
			    set_snap_props, &snpa, DS_FIND_CHILDREN);
cc18862247da PSARC/2008/483 ZFS clone -o
ahrens
parents: 7214
diff changeset
  2202
			if (error) {
cc18862247da PSARC/2008/483 ZFS clone -o
ahrens
parents: 7214
diff changeset
  2203
				(void) dmu_snapshots_destroy(zc->zc_name,
cc18862247da PSARC/2008/483 ZFS clone -o
ahrens
parents: 7214
diff changeset
  2204
				    zc->zc_value);
cc18862247da PSARC/2008/483 ZFS clone -o
ahrens
parents: 7214
diff changeset
  2205
			}
cc18862247da PSARC/2008/483 ZFS clone -o
ahrens
parents: 7214
diff changeset
  2206
		} else {
cc18862247da PSARC/2008/483 ZFS clone -o
ahrens
parents: 7214
diff changeset
  2207
			error = set_snap_props(zc->zc_name, &snpa);
cc18862247da PSARC/2008/483 ZFS clone -o
ahrens
parents: 7214
diff changeset
  2208
		}
cc18862247da PSARC/2008/483 ZFS clone -o
ahrens
parents: 7214
diff changeset
  2209
	}
cc18862247da PSARC/2008/483 ZFS clone -o
ahrens
parents: 7214
diff changeset
  2210
	nvlist_free(nvprops);
cc18862247da PSARC/2008/483 ZFS clone -o
ahrens
parents: 7214
diff changeset
  2211
	return (error);
2199
712a788c2dfd PSARC 2006/388 snapshot -r
ahrens
parents: 2082
diff changeset
  2212
}
712a788c2dfd PSARC 2006/388 snapshot -r
ahrens
parents: 2082
diff changeset
  2213
4007
c6f5c6753018 PSARC 2007/142 zfs rename -r
mmusante
parents: 3912
diff changeset
  2214
int
2199
712a788c2dfd PSARC 2006/388 snapshot -r
ahrens
parents: 2082
diff changeset
  2215
zfs_unmount_snap(char *name, void *arg)
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2216
{
2417
694d5de97348 6444346 zfs promote fails in zone
ahrens
parents: 2199
diff changeset
  2217
	vfs_t *vfsp = NULL;
2199
712a788c2dfd PSARC 2006/388 snapshot -r
ahrens
parents: 2082
diff changeset
  2218
6689
47572a2f5e73 6610506 Eliminate or improve retry logic from callers of dmu_objset_open()
maybee
parents: 6643
diff changeset
  2219
	if (arg) {
47572a2f5e73 6610506 Eliminate or improve retry logic from callers of dmu_objset_open()
maybee
parents: 6643
diff changeset
  2220
		char *snapname = arg;
47572a2f5e73 6610506 Eliminate or improve retry logic from callers of dmu_objset_open()
maybee
parents: 6643
diff changeset
  2221
		int len = strlen(name) + strlen(snapname) + 2;
47572a2f5e73 6610506 Eliminate or improve retry logic from callers of dmu_objset_open()
maybee
parents: 6643
diff changeset
  2222
		char *buf = kmem_alloc(len, KM_SLEEP);
47572a2f5e73 6610506 Eliminate or improve retry logic from callers of dmu_objset_open()
maybee
parents: 6643
diff changeset
  2223
47572a2f5e73 6610506 Eliminate or improve retry logic from callers of dmu_objset_open()
maybee
parents: 6643
diff changeset
  2224
		(void) strcpy(buf, name);
47572a2f5e73 6610506 Eliminate or improve retry logic from callers of dmu_objset_open()
maybee
parents: 6643
diff changeset
  2225
		(void) strcat(buf, "@");
47572a2f5e73 6610506 Eliminate or improve retry logic from callers of dmu_objset_open()
maybee
parents: 6643
diff changeset
  2226
		(void) strcat(buf, snapname);
47572a2f5e73 6610506 Eliminate or improve retry logic from callers of dmu_objset_open()
maybee
parents: 6643
diff changeset
  2227
		vfsp = zfs_get_vfs(buf);
47572a2f5e73 6610506 Eliminate or improve retry logic from callers of dmu_objset_open()
maybee
parents: 6643
diff changeset
  2228
		kmem_free(buf, len);
2417
694d5de97348 6444346 zfs promote fails in zone
ahrens
parents: 2199
diff changeset
  2229
	} else if (strchr(name, '@')) {
2199
712a788c2dfd PSARC 2006/388 snapshot -r
ahrens
parents: 2082
diff changeset
  2230
		vfsp = zfs_get_vfs(name);
712a788c2dfd PSARC 2006/388 snapshot -r
ahrens
parents: 2082
diff changeset
  2231
	}
712a788c2dfd PSARC 2006/388 snapshot -r
ahrens
parents: 2082
diff changeset
  2232
712a788c2dfd PSARC 2006/388 snapshot -r
ahrens
parents: 2082
diff changeset
  2233
	if (vfsp) {
712a788c2dfd PSARC 2006/388 snapshot -r
ahrens
parents: 2082
diff changeset
  2234
		/*
712a788c2dfd PSARC 2006/388 snapshot -r
ahrens
parents: 2082
diff changeset
  2235
		 * Always force the unmount for snapshots.
712a788c2dfd PSARC 2006/388 snapshot -r
ahrens
parents: 2082
diff changeset
  2236
		 */
712a788c2dfd PSARC 2006/388 snapshot -r
ahrens
parents: 2082
diff changeset
  2237
		int flag = MS_FORCE;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2238
		int err;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2239
2199
712a788c2dfd PSARC 2006/388 snapshot -r
ahrens
parents: 2082
diff changeset
  2240
		if ((err = vn_vfswlock(vfsp->vfs_vnodecovered)) != 0) {
712a788c2dfd PSARC 2006/388 snapshot -r
ahrens
parents: 2082
diff changeset
  2241
			VFS_RELE(vfsp);
712a788c2dfd PSARC 2006/388 snapshot -r
ahrens
parents: 2082
diff changeset
  2242
			return (err);
712a788c2dfd PSARC 2006/388 snapshot -r
ahrens
parents: 2082
diff changeset
  2243
		}
712a788c2dfd PSARC 2006/388 snapshot -r
ahrens
parents: 2082
diff changeset
  2244
		VFS_RELE(vfsp);
712a788c2dfd PSARC 2006/388 snapshot -r
ahrens
parents: 2082
diff changeset
  2245
		if ((err = dounmount(vfsp, flag, kcred)) != 0)
712a788c2dfd PSARC 2006/388 snapshot -r
ahrens
parents: 2082
diff changeset
  2246
			return (err);
712a788c2dfd PSARC 2006/388 snapshot -r
ahrens
parents: 2082
diff changeset
  2247
	}
712a788c2dfd PSARC 2006/388 snapshot -r
ahrens
parents: 2082
diff changeset
  2248
	return (0);
712a788c2dfd PSARC 2006/388 snapshot -r
ahrens
parents: 2082
diff changeset
  2249
}
712a788c2dfd PSARC 2006/388 snapshot -r
ahrens
parents: 2082
diff changeset
  2250
5367
c40abbe796be PSARC/2007/574 zfs send -R
ahrens
parents: 5331
diff changeset
  2251
/*
c40abbe796be PSARC/2007/574 zfs send -R
ahrens
parents: 5331
diff changeset
  2252
 * inputs:
c40abbe796be PSARC/2007/574 zfs send -R
ahrens
parents: 5331
diff changeset
  2253
 * zc_name	name of filesystem
c40abbe796be PSARC/2007/574 zfs send -R
ahrens
parents: 5331
diff changeset
  2254
 * zc_value	short name of snapshot
c40abbe796be PSARC/2007/574 zfs send -R
ahrens
parents: 5331
diff changeset
  2255
 *
c40abbe796be PSARC/2007/574 zfs send -R
ahrens
parents: 5331
diff changeset
  2256
 * outputs:	none
c40abbe796be PSARC/2007/574 zfs send -R
ahrens
parents: 5331
diff changeset
  2257
 */
2199
712a788c2dfd PSARC 2006/388 snapshot -r
ahrens
parents: 2082
diff changeset
  2258
static int
712a788c2dfd PSARC 2006/388 snapshot -r
ahrens
parents: 2082
diff changeset
  2259
zfs_ioc_destroy_snaps(zfs_cmd_t *zc)
712a788c2dfd PSARC 2006/388 snapshot -r
ahrens
parents: 2082
diff changeset
  2260
{
712a788c2dfd PSARC 2006/388 snapshot -r
ahrens
parents: 2082
diff changeset
  2261
	int err;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2262
2676
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  2263
	if (snapshot_namecheck(zc->zc_value, NULL, NULL) != 0)
2199
712a788c2dfd PSARC 2006/388 snapshot -r
ahrens
parents: 2082
diff changeset
  2264
		return (EINVAL);
712a788c2dfd PSARC 2006/388 snapshot -r
ahrens
parents: 2082
diff changeset
  2265
	err = dmu_objset_find(zc->zc_name,
2676
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  2266
	    zfs_unmount_snap, zc->zc_value, DS_FIND_CHILDREN);
2199
712a788c2dfd PSARC 2006/388 snapshot -r
ahrens
parents: 2082
diff changeset
  2267
	if (err)
712a788c2dfd PSARC 2006/388 snapshot -r
ahrens
parents: 2082
diff changeset
  2268
		return (err);
2676
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  2269
	return (dmu_snapshots_destroy(zc->zc_name, zc->zc_value));
2199
712a788c2dfd PSARC 2006/388 snapshot -r
ahrens
parents: 2082
diff changeset
  2270
}
712a788c2dfd PSARC 2006/388 snapshot -r
ahrens
parents: 2082
diff changeset
  2271
5367
c40abbe796be PSARC/2007/574 zfs send -R
ahrens
parents: 5331
diff changeset
  2272
/*
c40abbe796be PSARC/2007/574 zfs send -R
ahrens
parents: 5331
diff changeset
  2273
 * inputs:
c40abbe796be PSARC/2007/574 zfs send -R
ahrens
parents: 5331
diff changeset
  2274
 * zc_name		name of dataset to destroy
c40abbe796be PSARC/2007/574 zfs send -R
ahrens
parents: 5331
diff changeset
  2275
 * zc_objset_type	type of objset
c40abbe796be PSARC/2007/574 zfs send -R
ahrens
parents: 5331
diff changeset
  2276
 *
c40abbe796be PSARC/2007/574 zfs send -R
ahrens
parents: 5331
diff changeset
  2277
 * outputs:		none
c40abbe796be PSARC/2007/574 zfs send -R
ahrens
parents: 5331
diff changeset
  2278
 */
2199
712a788c2dfd PSARC 2006/388 snapshot -r
ahrens
parents: 2082
diff changeset
  2279
static int
712a788c2dfd PSARC 2006/388 snapshot -r
ahrens
parents: 2082
diff changeset
  2280
zfs_ioc_destroy(zfs_cmd_t *zc)
712a788c2dfd PSARC 2006/388 snapshot -r
ahrens
parents: 2082
diff changeset
  2281
{
712a788c2dfd PSARC 2006/388 snapshot -r
ahrens
parents: 2082
diff changeset
  2282
	if (strchr(zc->zc_name, '@') && zc->zc_objset_type == DMU_OST_ZFS) {
712a788c2dfd PSARC 2006/388 snapshot -r
ahrens
parents: 2082
diff changeset
  2283
		int err = zfs_unmount_snap(zc->zc_name, NULL);
712a788c2dfd PSARC 2006/388 snapshot -r
ahrens
parents: 2082
diff changeset
  2284
		if (err)
712a788c2dfd PSARC 2006/388 snapshot -r
ahrens
parents: 2082
diff changeset
  2285
			return (err);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2286
	}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2287
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2288
	return (dmu_objset_destroy(zc->zc_name));
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2289
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2290
5367
c40abbe796be PSARC/2007/574 zfs send -R
ahrens
parents: 5331
diff changeset
  2291
/*
c40abbe796be PSARC/2007/574 zfs send -R
ahrens
parents: 5331
diff changeset
  2292
 * inputs:
5446
51fbc14b301d 6421210 zfs rollback without unmounting
ahrens
parents: 5378
diff changeset
  2293
 * zc_name	name of dataset to rollback (to most recent snapshot)
5367
c40abbe796be PSARC/2007/574 zfs send -R
ahrens
parents: 5331
diff changeset
  2294
 *
c40abbe796be PSARC/2007/574 zfs send -R
ahrens
parents: 5331
diff changeset
  2295
 * outputs:	none
c40abbe796be PSARC/2007/574 zfs send -R
ahrens
parents: 5331
diff changeset
  2296
 */
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2297
static int
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2298
zfs_ioc_rollback(zfs_cmd_t *zc)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2299
{
5446
51fbc14b301d 6421210 zfs rollback without unmounting
ahrens
parents: 5378
diff changeset
  2300
	objset_t *os;
51fbc14b301d 6421210 zfs rollback without unmounting
ahrens
parents: 5378
diff changeset
  2301
	int error;
51fbc14b301d 6421210 zfs rollback without unmounting
ahrens
parents: 5378
diff changeset
  2302
	zfsvfs_t *zfsvfs = NULL;
51fbc14b301d 6421210 zfs rollback without unmounting
ahrens
parents: 5378
diff changeset
  2303
51fbc14b301d 6421210 zfs rollback without unmounting
ahrens
parents: 5378
diff changeset
  2304
	/*
51fbc14b301d 6421210 zfs rollback without unmounting
ahrens
parents: 5378
diff changeset
  2305
	 * Get the zfsvfs for the receiving objset. There
51fbc14b301d 6421210 zfs rollback without unmounting
ahrens
parents: 5378
diff changeset
  2306
	 * won't be one if we're operating on a zvol, if the
51fbc14b301d 6421210 zfs rollback without unmounting
ahrens
parents: 5378
diff changeset
  2307
	 * objset doesn't exist yet, or is not mounted.
51fbc14b301d 6421210 zfs rollback without unmounting
ahrens
parents: 5378
diff changeset
  2308
	 */
6689
47572a2f5e73 6610506 Eliminate or improve retry logic from callers of dmu_objset_open()
maybee
parents: 6643
diff changeset
  2309
	error = dmu_objset_open(zc->zc_name, DMU_OST_ANY, DS_MODE_USER, &os);
5446
51fbc14b301d 6421210 zfs rollback without unmounting
ahrens
parents: 5378
diff changeset
  2310
	if (error)
51fbc14b301d 6421210 zfs rollback without unmounting
ahrens
parents: 5378
diff changeset
  2311
		return (error);
51fbc14b301d 6421210 zfs rollback without unmounting
ahrens
parents: 5378
diff changeset
  2312
51fbc14b301d 6421210 zfs rollback without unmounting
ahrens
parents: 5378
diff changeset
  2313
	if (dmu_objset_type(os) == DMU_OST_ZFS) {
51fbc14b301d 6421210 zfs rollback without unmounting
ahrens
parents: 5378
diff changeset
  2314
		mutex_enter(&os->os->os_user_ptr_lock);
51fbc14b301d 6421210 zfs rollback without unmounting
ahrens
parents: 5378
diff changeset
  2315
		zfsvfs = dmu_objset_get_user(os);
51fbc14b301d 6421210 zfs rollback without unmounting
ahrens
parents: 5378
diff changeset
  2316
		if (zfsvfs != NULL)
51fbc14b301d 6421210 zfs rollback without unmounting
ahrens
parents: 5378
diff changeset
  2317
			VFS_HOLD(zfsvfs->z_vfs);
51fbc14b301d 6421210 zfs rollback without unmounting
ahrens
parents: 5378
diff changeset
  2318
		mutex_exit(&os->os->os_user_ptr_lock);
51fbc14b301d 6421210 zfs rollback without unmounting
ahrens
parents: 5378
diff changeset
  2319
	}
51fbc14b301d 6421210 zfs rollback without unmounting
ahrens
parents: 5378
diff changeset
  2320
51fbc14b301d 6421210 zfs rollback without unmounting
ahrens
parents: 5378
diff changeset
  2321
	if (zfsvfs != NULL) {
51fbc14b301d 6421210 zfs rollback without unmounting
ahrens
parents: 5378
diff changeset
  2322
		char osname[MAXNAMELEN];
51fbc14b301d 6421210 zfs rollback without unmounting
ahrens
parents: 5378
diff changeset
  2323
		int mode;
51fbc14b301d 6421210 zfs rollback without unmounting
ahrens
parents: 5378
diff changeset
  2324
6083
23e77aa611b1 6655963 Panic: 0 == zap_add(mos, pds->dd_phys->dd_child_dir_zapobj, name, sizeof (uint64_t), 1, &ddobj, tx)
ek110237
parents: 5977
diff changeset
  2325
		error = zfs_suspend_fs(zfsvfs, osname, &mode);
23e77aa611b1 6655963 Panic: 0 == zap_add(mos, pds->dd_phys->dd_child_dir_zapobj, name, sizeof (uint64_t), 1, &ddobj, tx)
ek110237
parents: 5977
diff changeset
  2326
		if (error == 0) {
23e77aa611b1 6655963 Panic: 0 == zap_add(mos, pds->dd_phys->dd_child_dir_zapobj, name, sizeof (uint64_t), 1, &ddobj, tx)
ek110237
parents: 5977
diff changeset
  2327
			int resume_err;
23e77aa611b1 6655963 Panic: 0 == zap_add(mos, pds->dd_phys->dd_child_dir_zapobj, name, sizeof (uint64_t), 1, &ddobj, tx)
ek110237
parents: 5977
diff changeset
  2328
23e77aa611b1 6655963 Panic: 0 == zap_add(mos, pds->dd_phys->dd_child_dir_zapobj, name, sizeof (uint64_t), 1, &ddobj, tx)
ek110237
parents: 5977
diff changeset
  2329
			ASSERT(strcmp(osname, zc->zc_name) == 0);
23e77aa611b1 6655963 Panic: 0 == zap_add(mos, pds->dd_phys->dd_child_dir_zapobj, name, sizeof (uint64_t), 1, &ddobj, tx)
ek110237
parents: 5977
diff changeset
  2330
			error = dmu_objset_rollback(os);
23e77aa611b1 6655963 Panic: 0 == zap_add(mos, pds->dd_phys->dd_child_dir_zapobj, name, sizeof (uint64_t), 1, &ddobj, tx)
ek110237
parents: 5977
diff changeset
  2331
			resume_err = zfs_resume_fs(zfsvfs, osname, mode);
23e77aa611b1 6655963 Panic: 0 == zap_add(mos, pds->dd_phys->dd_child_dir_zapobj, name, sizeof (uint64_t), 1, &ddobj, tx)
ek110237
parents: 5977
diff changeset
  2332
			error = error ? error : resume_err;
23e77aa611b1 6655963 Panic: 0 == zap_add(mos, pds->dd_phys->dd_child_dir_zapobj, name, sizeof (uint64_t), 1, &ddobj, tx)
ek110237
parents: 5977
diff changeset
  2333
		} else {
23e77aa611b1 6655963 Panic: 0 == zap_add(mos, pds->dd_phys->dd_child_dir_zapobj, name, sizeof (uint64_t), 1, &ddobj, tx)
ek110237
parents: 5977
diff changeset
  2334
			dmu_objset_close(os);
23e77aa611b1 6655963 Panic: 0 == zap_add(mos, pds->dd_phys->dd_child_dir_zapobj, name, sizeof (uint64_t), 1, &ddobj, tx)
ek110237
parents: 5977
diff changeset
  2335
		}
5446
51fbc14b301d 6421210 zfs rollback without unmounting
ahrens
parents: 5378
diff changeset
  2336
		VFS_RELE(zfsvfs->z_vfs);
51fbc14b301d 6421210 zfs rollback without unmounting
ahrens
parents: 5378
diff changeset
  2337
	} else {
51fbc14b301d 6421210 zfs rollback without unmounting
ahrens
parents: 5378
diff changeset
  2338
		error = dmu_objset_rollback(os);
51fbc14b301d 6421210 zfs rollback without unmounting
ahrens
parents: 5378
diff changeset
  2339
	}
6689
47572a2f5e73 6610506 Eliminate or improve retry logic from callers of dmu_objset_open()
maybee
parents: 6643
diff changeset
  2340
	/* Note, the dmu_objset_rollback() releases the objset for us. */
5446
51fbc14b301d 6421210 zfs rollback without unmounting
ahrens
parents: 5378
diff changeset
  2341
51fbc14b301d 6421210 zfs rollback without unmounting
ahrens
parents: 5378
diff changeset
  2342
	return (error);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2343
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2344
5367
c40abbe796be PSARC/2007/574 zfs send -R
ahrens
parents: 5331
diff changeset
  2345
/*
c40abbe796be PSARC/2007/574 zfs send -R
ahrens
parents: 5331
diff changeset
  2346
 * inputs:
c40abbe796be PSARC/2007/574 zfs send -R
ahrens
parents: 5331
diff changeset
  2347
 * zc_name	old name of dataset
c40abbe796be PSARC/2007/574 zfs send -R
ahrens
parents: 5331
diff changeset
  2348
 * zc_value	new name of dataset
c40abbe796be PSARC/2007/574 zfs send -R
ahrens
parents: 5331
diff changeset
  2349
 * zc_cookie	recursive flag (only valid for snapshots)
c40abbe796be PSARC/2007/574 zfs send -R
ahrens
parents: 5331
diff changeset
  2350
 *
c40abbe796be PSARC/2007/574 zfs send -R
ahrens
parents: 5331
diff changeset
  2351
 * outputs:	none
c40abbe796be PSARC/2007/574 zfs send -R
ahrens
parents: 5331
diff changeset
  2352
 */
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2353
static int
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2354
zfs_ioc_rename(zfs_cmd_t *zc)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2355
{
4490
abf035049f7f PSARC 2007/199 zfs {create,clone,rename} -p
vb160487
parents: 4451
diff changeset
  2356
	boolean_t recursive = zc->zc_cookie & 1;
4007
c6f5c6753018 PSARC 2007/142 zfs rename -r
mmusante
parents: 3912
diff changeset
  2357
2676
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  2358
	zc->zc_value[sizeof (zc->zc_value) - 1] = '\0';
5326
6752aa2bd5bc 6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents: 5147
diff changeset
  2359
	if (dataset_namecheck(zc->zc_value, NULL, NULL) != 0 ||
6752aa2bd5bc 6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents: 5147
diff changeset
  2360
	    strchr(zc->zc_value, '%'))
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2361
		return (EINVAL);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2362
4007
c6f5c6753018 PSARC 2007/142 zfs rename -r
mmusante
parents: 3912
diff changeset
  2363
	/*
c6f5c6753018 PSARC 2007/142 zfs rename -r
mmusante
parents: 3912
diff changeset
  2364
	 * Unmount snapshot unless we're doing a recursive rename,
c6f5c6753018 PSARC 2007/142 zfs rename -r
mmusante
parents: 3912
diff changeset
  2365
	 * in which case the dataset code figures out which snapshots
c6f5c6753018 PSARC 2007/142 zfs rename -r
mmusante
parents: 3912
diff changeset
  2366
	 * to unmount.
c6f5c6753018 PSARC 2007/142 zfs rename -r
mmusante
parents: 3912
diff changeset
  2367
	 */
c6f5c6753018 PSARC 2007/142 zfs rename -r
mmusante
parents: 3912
diff changeset
  2368
	if (!recursive && strchr(zc->zc_name, '@') != NULL &&
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2369
	    zc->zc_objset_type == DMU_OST_ZFS) {
2199
712a788c2dfd PSARC 2006/388 snapshot -r
ahrens
parents: 2082
diff changeset
  2370
		int err = zfs_unmount_snap(zc->zc_name, NULL);
712a788c2dfd PSARC 2006/388 snapshot -r
ahrens
parents: 2082
diff changeset
  2371
		if (err)
712a788c2dfd PSARC 2006/388 snapshot -r
ahrens
parents: 2082
diff changeset
  2372
			return (err);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2373
	}
4007
c6f5c6753018 PSARC 2007/142 zfs rename -r
mmusante
parents: 3912
diff changeset
  2374
	return (dmu_objset_rename(zc->zc_name, zc->zc_value, recursive));
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2375
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2376
6689
47572a2f5e73 6610506 Eliminate or improve retry logic from callers of dmu_objset_open()
maybee
parents: 6643
diff changeset
  2377
static void
47572a2f5e73 6610506 Eliminate or improve retry logic from callers of dmu_objset_open()
maybee
parents: 6643
diff changeset
  2378
clear_props(char *dataset, nvlist_t *props)
47572a2f5e73 6610506 Eliminate or improve retry logic from callers of dmu_objset_open()
maybee
parents: 6643
diff changeset
  2379
{
47572a2f5e73 6610506 Eliminate or improve retry logic from callers of dmu_objset_open()
maybee
parents: 6643
diff changeset
  2380
	zfs_cmd_t *zc;
47572a2f5e73 6610506 Eliminate or improve retry logic from callers of dmu_objset_open()
maybee
parents: 6643
diff changeset
  2381
	nvpair_t *prop;
47572a2f5e73 6610506 Eliminate or improve retry logic from callers of dmu_objset_open()
maybee
parents: 6643
diff changeset
  2382
47572a2f5e73 6610506 Eliminate or improve retry logic from callers of dmu_objset_open()
maybee
parents: 6643
diff changeset
  2383
	if (props == NULL)
47572a2f5e73 6610506 Eliminate or improve retry logic from callers of dmu_objset_open()
maybee
parents: 6643
diff changeset
  2384
		return;
47572a2f5e73 6610506 Eliminate or improve retry logic from callers of dmu_objset_open()
maybee
parents: 6643
diff changeset
  2385
	zc = kmem_alloc(sizeof (zfs_cmd_t), KM_SLEEP);
47572a2f5e73 6610506 Eliminate or improve retry logic from callers of dmu_objset_open()
maybee
parents: 6643
diff changeset
  2386
	(void) strcpy(zc->zc_name, dataset);
47572a2f5e73 6610506 Eliminate or improve retry logic from callers of dmu_objset_open()
maybee
parents: 6643
diff changeset
  2387
	for (prop = nvlist_next_nvpair(props, NULL); prop;
47572a2f5e73 6610506 Eliminate or improve retry logic from callers of dmu_objset_open()
maybee
parents: 6643
diff changeset
  2388
	    prop = nvlist_next_nvpair(props, prop)) {
47572a2f5e73 6610506 Eliminate or improve retry logic from callers of dmu_objset_open()
maybee
parents: 6643
diff changeset
  2389
		(void) strcpy(zc->zc_value, nvpair_name(prop));
47572a2f5e73 6610506 Eliminate or improve retry logic from callers of dmu_objset_open()
maybee
parents: 6643
diff changeset
  2390
		if (zfs_secpolicy_inherit(zc, CRED()) == 0)
47572a2f5e73 6610506 Eliminate or improve retry logic from callers of dmu_objset_open()
maybee
parents: 6643
diff changeset
  2391
			(void) zfs_ioc_inherit_prop(zc);
47572a2f5e73 6610506 Eliminate or improve retry logic from callers of dmu_objset_open()
maybee
parents: 6643
diff changeset
  2392
	}
47572a2f5e73 6610506 Eliminate or improve retry logic from callers of dmu_objset_open()
maybee
parents: 6643
diff changeset
  2393
	kmem_free(zc, sizeof (zfs_cmd_t));
47572a2f5e73 6610506 Eliminate or improve retry logic from callers of dmu_objset_open()
maybee
parents: 6643
diff changeset
  2394
}
47572a2f5e73 6610506 Eliminate or improve retry logic from callers of dmu_objset_open()
maybee
parents: 6643
diff changeset
  2395
5367
c40abbe796be PSARC/2007/574 zfs send -R
ahrens
parents: 5331
diff changeset
  2396
/*
c40abbe796be PSARC/2007/574 zfs send -R
ahrens
parents: 5331
diff changeset
  2397
 * inputs:
c40abbe796be PSARC/2007/574 zfs send -R
ahrens
parents: 5331
diff changeset
  2398
 * zc_name		name of containing filesystem
c40abbe796be PSARC/2007/574 zfs send -R
ahrens
parents: 5331
diff changeset
  2399
 * zc_nvlist_src{_size}	nvlist of properties to apply
c40abbe796be PSARC/2007/574 zfs send -R
ahrens
parents: 5331
diff changeset
  2400
 * zc_value		name of snapshot to create
c40abbe796be PSARC/2007/574 zfs send -R
ahrens
parents: 5331
diff changeset
  2401
 * zc_string		name of clone origin (if DRR_FLAG_CLONE)
c40abbe796be PSARC/2007/574 zfs send -R
ahrens
parents: 5331
diff changeset
  2402
 * zc_cookie		file descriptor to recv from
c40abbe796be PSARC/2007/574 zfs send -R
ahrens
parents: 5331
diff changeset
  2403
 * zc_begin_record	the BEGIN record of the stream (not byteswapped)
c40abbe796be PSARC/2007/574 zfs send -R
ahrens
parents: 5331
diff changeset
  2404
 * zc_guid		force flag
c40abbe796be PSARC/2007/574 zfs send -R
ahrens
parents: 5331
diff changeset
  2405
 *
c40abbe796be PSARC/2007/574 zfs send -R
ahrens
parents: 5331
diff changeset
  2406
 * outputs:
c40abbe796be PSARC/2007/574 zfs send -R
ahrens
parents: 5331
diff changeset
  2407
 * zc_cookie		number of bytes read
c40abbe796be PSARC/2007/574 zfs send -R
ahrens
parents: 5331
diff changeset
  2408
 */
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2409
static int
5367
c40abbe796be PSARC/2007/574 zfs send -R
ahrens
parents: 5331
diff changeset
  2410
zfs_ioc_recv(zfs_cmd_t *zc)
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2411
{
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2412
	file_t *fp;
5326
6752aa2bd5bc 6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents: 5147
diff changeset
  2413
	objset_t *os;
5367
c40abbe796be PSARC/2007/574 zfs send -R
ahrens
parents: 5331
diff changeset
  2414
	dmu_recv_cookie_t drc;
5326
6752aa2bd5bc 6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents: 5147
diff changeset
  2415
	zfsvfs_t *zfsvfs = NULL;
6752aa2bd5bc 6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents: 5147
diff changeset
  2416
	boolean_t force = (boolean_t)zc->zc_guid;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2417
	int error, fd;
5367
c40abbe796be PSARC/2007/574 zfs send -R
ahrens
parents: 5331
diff changeset
  2418
	offset_t off;
c40abbe796be PSARC/2007/574 zfs send -R
ahrens
parents: 5331
diff changeset
  2419
	nvlist_t *props = NULL;
6689
47572a2f5e73 6610506 Eliminate or improve retry logic from callers of dmu_objset_open()
maybee
parents: 6643
diff changeset
  2420
	nvlist_t *origprops = NULL;
5367
c40abbe796be PSARC/2007/574 zfs send -R
ahrens
parents: 5331
diff changeset
  2421
	objset_t *origin = NULL;
c40abbe796be PSARC/2007/574 zfs send -R
ahrens
parents: 5331
diff changeset
  2422
	char *tosnap;
c40abbe796be PSARC/2007/574 zfs send -R
ahrens
parents: 5331
diff changeset
  2423
	char tofs[ZFS_MAXNAMELEN];
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2424
3265
967e0fca6143 6463140 zfs recv with a snapshot name that has 2 @@ in a row succeeds
ahrens
parents: 3087
diff changeset
  2425
	if (dataset_namecheck(zc->zc_value, NULL, NULL) != 0 ||
5326
6752aa2bd5bc 6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents: 5147
diff changeset
  2426
	    strchr(zc->zc_value, '@') == NULL ||
6752aa2bd5bc 6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents: 5147
diff changeset
  2427
	    strchr(zc->zc_value, '%'))
3265
967e0fca6143 6463140 zfs recv with a snapshot name that has 2 @@ in a row succeeds
ahrens
parents: 3087
diff changeset
  2428
		return (EINVAL);
967e0fca6143 6463140 zfs recv with a snapshot name that has 2 @@ in a row succeeds
ahrens
parents: 3087
diff changeset
  2429
5367
c40abbe796be PSARC/2007/574 zfs send -R
ahrens
parents: 5331
diff changeset
  2430
	(void) strcpy(tofs, zc->zc_value);
c40abbe796be PSARC/2007/574 zfs send -R
ahrens
parents: 5331
diff changeset
  2431
	tosnap = strchr(tofs, '@');
c40abbe796be PSARC/2007/574 zfs send -R
ahrens
parents: 5331
diff changeset
  2432
	*tosnap = '\0';
c40abbe796be PSARC/2007/574 zfs send -R
ahrens
parents: 5331
diff changeset
  2433
	tosnap++;
c40abbe796be PSARC/2007/574 zfs send -R
ahrens
parents: 5331
diff changeset
  2434
c40abbe796be PSARC/2007/574 zfs send -R
ahrens
parents: 5331
diff changeset
  2435
	if (zc->zc_nvlist_src != NULL &&
c40abbe796be PSARC/2007/574 zfs send -R
ahrens
parents: 5331
diff changeset
  2436
	    (error = get_nvlist(zc->zc_nvlist_src, zc->zc_nvlist_src_size,
c40abbe796be PSARC/2007/574 zfs send -R
ahrens
parents: 5331
diff changeset
  2437
	    &props)) != 0)
c40abbe796be PSARC/2007/574 zfs send -R
ahrens
parents: 5331
diff changeset
  2438
		return (error);
c40abbe796be PSARC/2007/574 zfs send -R
ahrens
parents: 5331
diff changeset
  2439
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2440
	fd = zc->zc_cookie;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2441
	fp = getf(fd);
5367
c40abbe796be PSARC/2007/574 zfs send -R
ahrens
parents: 5331
diff changeset
  2442
	if (fp == NULL) {
c40abbe796be PSARC/2007/574 zfs send -R
ahrens
parents: 5331
diff changeset
  2443
		nvlist_free(props);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2444
		return (EBADF);
5367
c40abbe796be PSARC/2007/574 zfs send -R
ahrens
parents: 5331
diff changeset
  2445
	}
5326
6752aa2bd5bc 6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents: 5147
diff changeset
  2446
6689
47572a2f5e73 6610506 Eliminate or improve retry logic from callers of dmu_objset_open()
maybee
parents: 6643
diff changeset
  2447
	if (dmu_objset_open(tofs, DMU_OST_ANY,
47572a2f5e73 6610506 Eliminate or improve retry logic from callers of dmu_objset_open()
maybee
parents: 6643
diff changeset
  2448
	    DS_MODE_USER | DS_MODE_READONLY, &os) == 0) {
47572a2f5e73 6610506 Eliminate or improve retry logic from callers of dmu_objset_open()
maybee
parents: 6643
diff changeset
  2449
		/*
47572a2f5e73 6610506 Eliminate or improve retry logic from callers of dmu_objset_open()
maybee
parents: 6643
diff changeset
  2450
		 * Try to get the zfsvfs for the receiving objset.
47572a2f5e73 6610506 Eliminate or improve retry logic from callers of dmu_objset_open()
maybee
parents: 6643
diff changeset
  2451
		 * There won't be one if we're operating on a zvol,
47572a2f5e73 6610506 Eliminate or improve retry logic from callers of dmu_objset_open()
maybee
parents: 6643
diff changeset
  2452
		 * if the objset doesn't exist yet, or is not mounted.
47572a2f5e73 6610506 Eliminate or improve retry logic from callers of dmu_objset_open()
maybee
parents: 6643
diff changeset
  2453
		 */
5446
51fbc14b301d 6421210 zfs rollback without unmounting
ahrens
parents: 5378
diff changeset
  2454
		mutex_enter(&os->os->os_user_ptr_lock);
6689
47572a2f5e73 6610506 Eliminate or improve retry logic from callers of dmu_objset_open()
maybee
parents: 6643
diff changeset
  2455
		if (zfsvfs = dmu_objset_get_user(os)) {
6083
23e77aa611b1 6655963 Panic: 0 == zap_add(mos, pds->dd_phys->dd_child_dir_zapobj, name, sizeof (uint64_t), 1, &ddobj, tx)
ek110237
parents: 5977
diff changeset
  2456
			if (!mutex_tryenter(&zfsvfs->z_online_recv_lock)) {
6689
47572a2f5e73 6610506 Eliminate or improve retry logic from callers of dmu_objset_open()
maybee
parents: 6643
diff changeset
  2457
				mutex_exit(&os->os->os_user_ptr_lock);
6083
23e77aa611b1 6655963 Panic: 0 == zap_add(mos, pds->dd_phys->dd_child_dir_zapobj, name, sizeof (uint64_t), 1, &ddobj, tx)
ek110237
parents: 5977
diff changeset
  2458
				dmu_objset_close(os);
6689
47572a2f5e73 6610506 Eliminate or improve retry logic from callers of dmu_objset_open()
maybee
parents: 6643
diff changeset
  2459
				zfsvfs = NULL;
47572a2f5e73 6610506 Eliminate or improve retry logic from callers of dmu_objset_open()
maybee
parents: 6643
diff changeset
  2460
				error = EBUSY;
47572a2f5e73 6610506 Eliminate or improve retry logic from callers of dmu_objset_open()
maybee
parents: 6643
diff changeset
  2461
				goto out;
6083
23e77aa611b1 6655963 Panic: 0 == zap_add(mos, pds->dd_phys->dd_child_dir_zapobj, name, sizeof (uint64_t), 1, &ddobj, tx)
ek110237
parents: 5977
diff changeset
  2462
			}
6689
47572a2f5e73 6610506 Eliminate or improve retry logic from callers of dmu_objset_open()
maybee
parents: 6643
diff changeset
  2463
			VFS_HOLD(zfsvfs->z_vfs);
6083
23e77aa611b1 6655963 Panic: 0 == zap_add(mos, pds->dd_phys->dd_child_dir_zapobj, name, sizeof (uint64_t), 1, &ddobj, tx)
ek110237
parents: 5977
diff changeset
  2464
		}
6689
47572a2f5e73 6610506 Eliminate or improve retry logic from callers of dmu_objset_open()
maybee
parents: 6643
diff changeset
  2465
		mutex_exit(&os->os->os_user_ptr_lock);
47572a2f5e73 6610506 Eliminate or improve retry logic from callers of dmu_objset_open()
maybee
parents: 6643
diff changeset
  2466
47572a2f5e73 6610506 Eliminate or improve retry logic from callers of dmu_objset_open()
maybee
parents: 6643
diff changeset
  2467
		/*
47572a2f5e73 6610506 Eliminate or improve retry logic from callers of dmu_objset_open()
maybee
parents: 6643
diff changeset
  2468
		 * If new properties are supplied, they are to completely
47572a2f5e73 6610506 Eliminate or improve retry logic from callers of dmu_objset_open()
maybee
parents: 6643
diff changeset
  2469
		 * replace the existing ones, so stash away the existing ones.
47572a2f5e73 6610506 Eliminate or improve retry logic from callers of dmu_objset_open()
maybee
parents: 6643
diff changeset
  2470
		 */
47572a2f5e73 6610506 Eliminate or improve retry logic from callers of dmu_objset_open()
maybee
parents: 6643
diff changeset
  2471
		if (props)
47572a2f5e73 6610506 Eliminate or improve retry logic from callers of dmu_objset_open()
maybee
parents: 6643
diff changeset
  2472
			(void) dsl_prop_get_all(os, &origprops, TRUE);
47572a2f5e73 6610506 Eliminate or improve retry logic from callers of dmu_objset_open()
maybee
parents: 6643
diff changeset
  2473
5326
6752aa2bd5bc 6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents: 5147
diff changeset
  2474
		dmu_objset_close(os);
6752aa2bd5bc 6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents: 5147
diff changeset
  2475
	}
6752aa2bd5bc 6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents: 5147
diff changeset
  2476
5367
c40abbe796be PSARC/2007/574 zfs send -R
ahrens
parents: 5331
diff changeset
  2477
	if (zc->zc_string[0]) {
c40abbe796be PSARC/2007/574 zfs send -R
ahrens
parents: 5331
diff changeset
  2478
		error = dmu_objset_open(zc->zc_string, DMU_OST_ANY,
6689
47572a2f5e73 6610506 Eliminate or improve retry logic from callers of dmu_objset_open()
maybee
parents: 6643
diff changeset
  2479
		    DS_MODE_USER | DS_MODE_READONLY, &origin);
47572a2f5e73 6610506 Eliminate or improve retry logic from callers of dmu_objset_open()
maybee
parents: 6643
diff changeset
  2480
		if (error)
47572a2f5e73 6610506 Eliminate or improve retry logic from callers of dmu_objset_open()
maybee
parents: 6643
diff changeset
  2481
			goto out;
5367
c40abbe796be PSARC/2007/574 zfs send -R
ahrens
parents: 5331
diff changeset
  2482
	}
c40abbe796be PSARC/2007/574 zfs send -R
ahrens
parents: 5331
diff changeset
  2483
c40abbe796be PSARC/2007/574 zfs send -R
ahrens
parents: 5331
diff changeset
  2484
	error = dmu_recv_begin(tofs, tosnap, &zc->zc_begin_record,
c40abbe796be PSARC/2007/574 zfs send -R
ahrens
parents: 5331
diff changeset
  2485
	    force, origin, zfsvfs != NULL, &drc);
c40abbe796be PSARC/2007/574 zfs send -R
ahrens
parents: 5331
diff changeset
  2486
	if (origin)
c40abbe796be PSARC/2007/574 zfs send -R
ahrens
parents: 5331
diff changeset
  2487
		dmu_objset_close(origin);
6689
47572a2f5e73 6610506 Eliminate or improve retry logic from callers of dmu_objset_open()
maybee
parents: 6643
diff changeset
  2488
	if (error)
47572a2f5e73 6610506 Eliminate or improve retry logic from callers of dmu_objset_open()
maybee
parents: 6643
diff changeset
  2489
		goto out;
5326
6752aa2bd5bc 6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents: 5147
diff changeset
  2490
6752aa2bd5bc 6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents: 5147
diff changeset
  2491
	/*
6689
47572a2f5e73 6610506 Eliminate or improve retry logic from callers of dmu_objset_open()
maybee
parents: 6643
diff changeset
  2492
	 * Reset properties.  We do this before we receive the stream
47572a2f5e73 6610506 Eliminate or improve retry logic from callers of dmu_objset_open()
maybee
parents: 6643
diff changeset
  2493
	 * so that the properties are applied to the new data.
5326
6752aa2bd5bc 6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents: 5147
diff changeset
  2494
	 */
5367
c40abbe796be PSARC/2007/574 zfs send -R
ahrens
parents: 5331
diff changeset
  2495
	if (props) {
6689
47572a2f5e73 6610506 Eliminate or improve retry logic from callers of dmu_objset_open()
maybee
parents: 6643
diff changeset
  2496
		clear_props(tofs, origprops);
47572a2f5e73 6610506 Eliminate or improve retry logic from callers of dmu_objset_open()
maybee
parents: 6643
diff changeset
  2497
		/*
47572a2f5e73 6610506 Eliminate or improve retry logic from callers of dmu_objset_open()
maybee
parents: 6643
diff changeset
  2498
		 * XXX - Note, this is all-or-nothing; should be best-effort.
47572a2f5e73 6610506 Eliminate or improve retry logic from callers of dmu_objset_open()
maybee
parents: 6643
diff changeset
  2499
		 */
47572a2f5e73 6610506 Eliminate or improve retry logic from callers of dmu_objset_open()
maybee
parents: 6643
diff changeset
  2500
		(void) zfs_set_prop_nvlist(tofs, props);
5367
c40abbe796be PSARC/2007/574 zfs send -R
ahrens
parents: 5331
diff changeset
  2501
	}
c40abbe796be PSARC/2007/574 zfs send -R
ahrens
parents: 5331
diff changeset
  2502
c40abbe796be PSARC/2007/574 zfs send -R
ahrens
parents: 5331
diff changeset
  2503
	off = fp->f_offset;
c40abbe796be PSARC/2007/574 zfs send -R
ahrens
parents: 5331
diff changeset
  2504
	error = dmu_recv_stream(&drc, fp->f_vnode, &off);
c40abbe796be PSARC/2007/574 zfs send -R
ahrens
parents: 5331
diff changeset
  2505
6689
47572a2f5e73 6610506 Eliminate or improve retry logic from callers of dmu_objset_open()
maybee
parents: 6643
diff changeset
  2506
	if (error == 0 && zfsvfs) {
47572a2f5e73 6610506 Eliminate or improve retry logic from callers of dmu_objset_open()
maybee
parents: 6643
diff changeset
  2507
		char osname[MAXNAMELEN];
47572a2f5e73 6610506 Eliminate or improve retry logic from callers of dmu_objset_open()
maybee
parents: 6643
diff changeset
  2508
		int mode;
47572a2f5e73 6610506 Eliminate or improve retry logic from callers of dmu_objset_open()
maybee
parents: 6643
diff changeset
  2509
47572a2f5e73 6610506 Eliminate or improve retry logic from callers of dmu_objset_open()
maybee
parents: 6643
diff changeset
  2510
		/* online recv */
47572a2f5e73 6610506 Eliminate or improve retry logic from callers of dmu_objset_open()
maybee
parents: 6643
diff changeset
  2511
		error = zfs_suspend_fs(zfsvfs, osname, &mode);
47572a2f5e73 6610506 Eliminate or improve retry logic from callers of dmu_objset_open()
maybee
parents: 6643
diff changeset
  2512
		if (error == 0) {
47572a2f5e73 6610506 Eliminate or improve retry logic from callers of dmu_objset_open()
maybee
parents: 6643
diff changeset
  2513
			int resume_err;
47572a2f5e73 6610506 Eliminate or improve retry logic from callers of dmu_objset_open()
maybee
parents: 6643
diff changeset
  2514
47572a2f5e73 6610506 Eliminate or improve retry logic from callers of dmu_objset_open()
maybee
parents: 6643
diff changeset
  2515
			error = dmu_recv_end(&drc);
47572a2f5e73 6610506 Eliminate or improve retry logic from callers of dmu_objset_open()
maybee
parents: 6643
diff changeset
  2516
			resume_err = zfs_resume_fs(zfsvfs, osname, mode);
47572a2f5e73 6610506 Eliminate or improve retry logic from callers of dmu_objset_open()
maybee
parents: 6643
diff changeset
  2517
			error = error ? error : resume_err;
5367
c40abbe796be PSARC/2007/574 zfs send -R
ahrens
parents: 5331
diff changeset
  2518
		} else {
6689
47572a2f5e73 6610506 Eliminate or improve retry logic from callers of dmu_objset_open()
maybee
parents: 6643
diff changeset
  2519
			dmu_recv_abort_cleanup(&drc);
5367
c40abbe796be PSARC/2007/574 zfs send -R
ahrens
parents: 5331
diff changeset
  2520
		}
6689
47572a2f5e73 6610506 Eliminate or improve retry logic from callers of dmu_objset_open()
maybee
parents: 6643
diff changeset
  2521
	} else if (error == 0) {
47572a2f5e73 6610506 Eliminate or improve retry logic from callers of dmu_objset_open()
maybee
parents: 6643
diff changeset
  2522
		error = dmu_recv_end(&drc);
6083
23e77aa611b1 6655963 Panic: 0 == zap_add(mos, pds->dd_phys->dd_child_dir_zapobj, name, sizeof (uint64_t), 1, &ddobj, tx)
ek110237
parents: 5977
diff changeset
  2523
	}
5367
c40abbe796be PSARC/2007/574 zfs send -R
ahrens
parents: 5331
diff changeset
  2524
c40abbe796be PSARC/2007/574 zfs send -R
ahrens
parents: 5331
diff changeset
  2525
	zc->zc_cookie = off - fp->f_offset;
c40abbe796be PSARC/2007/574 zfs send -R
ahrens
parents: 5331
diff changeset
  2526
	if (VOP_SEEK(fp->f_vnode, fp->f_offset, &off, NULL) == 0)
c40abbe796be PSARC/2007/574 zfs send -R
ahrens
parents: 5331
diff changeset
  2527
		fp->f_offset = off;
2885
c0259887ebbc 6460059 zfs destroy <snapshot> leaves behind kruft
ahrens
parents: 2856
diff changeset
  2528
6689
47572a2f5e73 6610506 Eliminate or improve retry logic from callers of dmu_objset_open()
maybee
parents: 6643
diff changeset
  2529
	/*
47572a2f5e73 6610506 Eliminate or improve retry logic from callers of dmu_objset_open()
maybee
parents: 6643
diff changeset
  2530
	 * On error, restore the original props.
47572a2f5e73 6610506 Eliminate or improve retry logic from callers of dmu_objset_open()
maybee
parents: 6643
diff changeset
  2531
	 */
47572a2f5e73 6610506 Eliminate or improve retry logic from callers of dmu_objset_open()
maybee
parents: 6643
diff changeset
  2532
	if (error && props) {
47572a2f5e73 6610506 Eliminate or improve retry logic from callers of dmu_objset_open()
maybee
parents: 6643
diff changeset
  2533
		clear_props(tofs, props);
47572a2f5e73 6610506 Eliminate or improve retry logic from callers of dmu_objset_open()
maybee
parents: 6643
diff changeset
  2534
		(void) zfs_set_prop_nvlist(tofs, origprops);
47572a2f5e73 6610506 Eliminate or improve retry logic from callers of dmu_objset_open()
maybee
parents: 6643
diff changeset
  2535
	}
47572a2f5e73 6610506 Eliminate or improve retry logic from callers of dmu_objset_open()
maybee
parents: 6643
diff changeset
  2536
out:
47572a2f5e73 6610506 Eliminate or improve retry logic from callers of dmu_objset_open()
maybee
parents: 6643
diff changeset
  2537
	if (zfsvfs) {
47572a2f5e73 6610506 Eliminate or improve retry logic from callers of dmu_objset_open()
maybee
parents: 6643
diff changeset
  2538
		mutex_exit(&zfsvfs->z_online_recv_lock);
47572a2f5e73 6610506 Eliminate or improve retry logic from callers of dmu_objset_open()
maybee
parents: 6643
diff changeset
  2539
		VFS_RELE(zfsvfs->z_vfs);
47572a2f5e73 6610506 Eliminate or improve retry logic from callers of dmu_objset_open()
maybee
parents: 6643
diff changeset
  2540
	}
47572a2f5e73 6610506 Eliminate or improve retry logic from callers of dmu_objset_open()
maybee
parents: 6643
diff changeset
  2541
	nvlist_free(props);
47572a2f5e73 6610506 Eliminate or improve retry logic from callers of dmu_objset_open()
maybee
parents: 6643
diff changeset
  2542
	nvlist_free(origprops);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2543
	releasef(fd);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2544
	return (error);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2545
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2546
5367
c40abbe796be PSARC/2007/574 zfs send -R
ahrens
parents: 5331
diff changeset
  2547
/*
c40abbe796be PSARC/2007/574 zfs send -R
ahrens
parents: 5331
diff changeset
  2548
 * inputs:
c40abbe796be PSARC/2007/574 zfs send -R
ahrens
parents: 5331
diff changeset
  2549
 * zc_name	name of snapshot to send
c40abbe796be PSARC/2007/574 zfs send -R
ahrens
parents: 5331
diff changeset
  2550
 * zc_value	short name of incremental fromsnap (may be empty)
c40abbe796be PSARC/2007/574 zfs send -R
ahrens
parents: 5331
diff changeset
  2551
 * zc_cookie	file descriptor to send stream to
c40abbe796be PSARC/2007/574 zfs send -R
ahrens
parents: 5331
diff changeset
  2552
 * zc_obj	fromorigin flag (mutually exclusive with zc_value)
c40abbe796be PSARC/2007/574 zfs send -R
ahrens
parents: 5331
diff changeset
  2553
 *
c40abbe796be PSARC/2007/574 zfs send -R
ahrens
parents: 5331
diff changeset
  2554
 * outputs: none
c40abbe796be PSARC/2007/574 zfs send -R
ahrens
parents: 5331
diff changeset
  2555
 */
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2556
static int
5367
c40abbe796be PSARC/2007/574 zfs send -R
ahrens
parents: 5331
diff changeset
  2557
zfs_ioc_send(zfs_cmd_t *zc)
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2558
{
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2559
	objset_t *fromsnap = NULL;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2560
	objset_t *tosnap;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2561
	file_t *fp;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2562
	int error;
5367
c40abbe796be PSARC/2007/574 zfs send -R
ahrens
parents: 5331
diff changeset
  2563
	offset_t off;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2564
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2565
	error = dmu_objset_open(zc->zc_name, DMU_OST_ANY,
6689
47572a2f5e73 6610506 Eliminate or improve retry logic from callers of dmu_objset_open()
maybee
parents: 6643
diff changeset
  2566
	    DS_MODE_USER | DS_MODE_READONLY, &tosnap);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2567
	if (error)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2568
		return (error);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2569
2676
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  2570
	if (zc->zc_value[0] != '\0') {
2885
c0259887ebbc 6460059 zfs destroy <snapshot> leaves behind kruft
ahrens
parents: 2856
diff changeset
  2571
		char buf[MAXPATHLEN];
c0259887ebbc 6460059 zfs destroy <snapshot> leaves behind kruft
ahrens
parents: 2856
diff changeset
  2572
		char *cp;
c0259887ebbc 6460059 zfs destroy <snapshot> leaves behind kruft
ahrens
parents: 2856
diff changeset
  2573
c0259887ebbc 6460059 zfs destroy <snapshot> leaves behind kruft
ahrens
parents: 2856
diff changeset
  2574
		(void) strncpy(buf, zc->zc_name, sizeof (buf));
c0259887ebbc 6460059 zfs destroy <snapshot> leaves behind kruft
ahrens
parents: 2856
diff changeset
  2575
		cp = strchr(buf, '@');
c0259887ebbc 6460059 zfs destroy <snapshot> leaves behind kruft
ahrens
parents: 2856
diff changeset
  2576
		if (cp)
c0259887ebbc 6460059 zfs destroy <snapshot> leaves behind kruft
ahrens
parents: 2856
diff changeset
  2577
			*(cp+1) = 0;
c0259887ebbc 6460059 zfs destroy <snapshot> leaves behind kruft
ahrens
parents: 2856
diff changeset
  2578
		(void) strncat(buf, zc->zc_value, sizeof (buf));
c0259887ebbc 6460059 zfs destroy <snapshot> leaves behind kruft
ahrens
parents: 2856
diff changeset
  2579
		error = dmu_objset_open(buf, DMU_OST_ANY,
6689
47572a2f5e73 6610506 Eliminate or improve retry logic from callers of dmu_objset_open()
maybee
parents: 6643
diff changeset
  2580
		    DS_MODE_USER | DS_MODE_READONLY, &fromsnap);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2581
		if (error) {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2582
			dmu_objset_close(tosnap);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2583
			return (error);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2584
		}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2585
	}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2586
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2587
	fp = getf(zc->zc_cookie);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2588
	if (fp == NULL) {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2589
		dmu_objset_close(tosnap);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2590
		if (fromsnap)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2591
			dmu_objset_close(fromsnap);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2592
		return (EBADF);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2593
	}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2594
5367
c40abbe796be PSARC/2007/574 zfs send -R
ahrens
parents: 5331
diff changeset
  2595
	off = fp->f_offset;
c40abbe796be PSARC/2007/574 zfs send -R
ahrens
parents: 5331
diff changeset
  2596
	error = dmu_sendbackup(tosnap, fromsnap, zc->zc_obj, fp->f_vnode, &off);
c40abbe796be PSARC/2007/574 zfs send -R
ahrens
parents: 5331
diff changeset
  2597
c40abbe796be PSARC/2007/574 zfs send -R
ahrens
parents: 5331
diff changeset
  2598
	if (VOP_SEEK(fp->f_vnode, fp->f_offset, &off, NULL) == 0)
c40abbe796be PSARC/2007/574 zfs send -R
ahrens
parents: 5331
diff changeset
  2599
		fp->f_offset = off;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2600
	releasef(zc->zc_cookie);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2601
	if (fromsnap)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2602
		dmu_objset_close(fromsnap);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2603
	dmu_objset_close(tosnap);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2604
	return (error);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2605
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2606
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
  2607
static int
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
  2608
zfs_ioc_inject_fault(zfs_cmd_t *zc)
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
  2609
{
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
  2610
	int id, error;
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
  2611
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
  2612
	error = zio_inject_fault(zc->zc_name, (int)zc->zc_guid, &id,
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
  2613
	    &zc->zc_inject_record);
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
  2614
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
  2615
	if (error == 0)
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
  2616
		zc->zc_guid = (uint64_t)id;
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
  2617
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
  2618
	return (error);
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
  2619
}
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
  2620
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
  2621
static int
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
  2622
zfs_ioc_clear_fault(zfs_cmd_t *zc)
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
  2623
{
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
  2624
	return (zio_clear_fault((int)zc->zc_guid));
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
  2625
}
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
  2626
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
  2627
static int
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
  2628
zfs_ioc_inject_list_next(zfs_cmd_t *zc)
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
  2629
{
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
  2630
	int id = (int)zc->zc_guid;
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
  2631
	int error;
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
  2632
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
  2633
	error = zio_inject_list_next(&id, zc->zc_name, sizeof (zc->zc_name),
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
  2634
	    &zc->zc_inject_record);
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
  2635
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
  2636
	zc->zc_guid = id;
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
  2637
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
  2638
	return (error);
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
  2639
}
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
  2640
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
  2641
static int
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
  2642
zfs_ioc_error_log(zfs_cmd_t *zc)
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
  2643
{
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
  2644
	spa_t *spa;
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
  2645
	int error;
2676
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  2646
	size_t count = (size_t)zc->zc_nvlist_dst_size;
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
  2647
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
  2648
	if ((error = spa_open(zc->zc_name, &spa, FTAG)) != 0)
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
  2649
		return (error);
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
  2650
2676
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  2651
	error = spa_get_errlog(spa, (void *)(uintptr_t)zc->zc_nvlist_dst,
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
  2652
	    &count);
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
  2653
	if (error == 0)
2676
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  2654
		zc->zc_nvlist_dst_size = count;
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
  2655
	else
2676
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  2656
		zc->zc_nvlist_dst_size = spa_get_errlog_size(spa);
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
  2657
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
  2658
	spa_close(spa, FTAG);
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
  2659
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
  2660
	return (error);
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
  2661
}
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
  2662
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
  2663
static int
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
  2664
zfs_ioc_clear(zfs_cmd_t *zc)
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
  2665
{
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
  2666
	spa_t *spa;
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
  2667
	vdev_t *vd;
4808
63629eaeb41a 6498144 ::kmastat could be even easier to read
ek110237
parents: 4787
diff changeset
  2668
	uint64_t txg;
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
  2669
	int error;
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
  2670
7294
c9c31ef4c960 PSARC 2008/486 Intent log replay failure handling
perrin
parents: 7265
diff changeset
  2671
	/*
c9c31ef4c960 PSARC 2008/486 Intent log replay failure handling
perrin
parents: 7265
diff changeset
  2672
	 * On zpool clear we also fix up missing slogs
c9c31ef4c960 PSARC 2008/486 Intent log replay failure handling
perrin
parents: 7265
diff changeset
  2673
	 */
c9c31ef4c960 PSARC 2008/486 Intent log replay failure handling
perrin
parents: 7265
diff changeset
  2674
	mutex_enter(&spa_namespace_lock);
c9c31ef4c960 PSARC 2008/486 Intent log replay failure handling
perrin
parents: 7265
diff changeset
  2675
	spa = spa_lookup(zc->zc_name);
c9c31ef4c960 PSARC 2008/486 Intent log replay failure handling
perrin
parents: 7265
diff changeset
  2676
	if (spa == NULL) {
c9c31ef4c960 PSARC 2008/486 Intent log replay failure handling
perrin
parents: 7265
diff changeset
  2677
		mutex_exit(&spa_namespace_lock);
c9c31ef4c960 PSARC 2008/486 Intent log replay failure handling
perrin
parents: 7265
diff changeset
  2678
		return (EIO);
c9c31ef4c960 PSARC 2008/486 Intent log replay failure handling
perrin
parents: 7265
diff changeset
  2679
	}
c9c31ef4c960 PSARC 2008/486 Intent log replay failure handling
perrin
parents: 7265
diff changeset
  2680
	if (spa->spa_log_state == SPA_LOG_MISSING) {
c9c31ef4c960 PSARC 2008/486 Intent log replay failure handling
perrin
parents: 7265
diff changeset
  2681
		/* we need to let spa_open/spa_load clear the chains */
c9c31ef4c960 PSARC 2008/486 Intent log replay failure handling
perrin
parents: 7265
diff changeset
  2682
		spa->spa_log_state = SPA_LOG_CLEAR;
c9c31ef4c960 PSARC 2008/486 Intent log replay failure handling
perrin
parents: 7265
diff changeset
  2683
	}
c9c31ef4c960 PSARC 2008/486 Intent log replay failure handling
perrin
parents: 7265
diff changeset
  2684
	mutex_exit(&spa_namespace_lock);
c9c31ef4c960 PSARC 2008/486 Intent log replay failure handling
perrin
parents: 7265
diff changeset
  2685
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
  2686
	if ((error = spa_open(zc->zc_name, &spa, FTAG)) != 0)
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
  2687
		return (error);
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
  2688
5329
33cb98223b2d PSARC 2007/567 zpool failmode property
gw25295
parents: 5326
diff changeset
  2689
	/*
33cb98223b2d PSARC 2007/567 zpool failmode property
gw25295
parents: 5326
diff changeset
  2690
	 * Try to resume any I/Os which may have been suspended
33cb98223b2d PSARC 2007/567 zpool failmode property
gw25295
parents: 5326
diff changeset
  2691
	 * as a result of a complete pool failure.
33cb98223b2d PSARC 2007/567 zpool failmode property
gw25295
parents: 5326
diff changeset
  2692
	 */
33cb98223b2d PSARC 2007/567 zpool failmode property
gw25295
parents: 5326
diff changeset
  2693
	if (!list_is_empty(&spa->spa_zio_list)) {
33cb98223b2d PSARC 2007/567 zpool failmode property
gw25295
parents: 5326
diff changeset
  2694
		if (zio_vdev_resume_io(spa) != 0) {
33cb98223b2d PSARC 2007/567 zpool failmode property
gw25295
parents: 5326
diff changeset
  2695
			spa_close(spa, FTAG);
33cb98223b2d PSARC 2007/567 zpool failmode property
gw25295
parents: 5326
diff changeset
  2696
			return (EIO);
33cb98223b2d PSARC 2007/567 zpool failmode property
gw25295
parents: 5326
diff changeset
  2697
		}
33cb98223b2d PSARC 2007/567 zpool failmode property
gw25295
parents: 5326
diff changeset
  2698
	}
33cb98223b2d PSARC 2007/567 zpool failmode property
gw25295
parents: 5326
diff changeset
  2699
4451
24fbf2d7a5d7 PSARC 2007/197 ZFS hotplug
eschrock
parents: 4098
diff changeset
  2700
	txg = spa_vdev_enter(spa);
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
  2701
2676
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  2702
	if (zc->zc_guid == 0) {
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
  2703
		vd = NULL;
6643
3a34b0dbb107 6625086 changing cachefile doesn't remove old cache on last user
eschrock
parents: 6492
diff changeset
  2704
	} else {
3a34b0dbb107 6625086 changing cachefile doesn't remove old cache on last user
eschrock
parents: 6492
diff changeset
  2705
		vd = spa_lookup_by_guid(spa, zc->zc_guid, B_TRUE);
5450
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5446
diff changeset
  2706
		if (vd == NULL) {
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5446
diff changeset
  2707
			(void) spa_vdev_exit(spa, NULL, txg, ENODEV);
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5446
diff changeset
  2708
			spa_close(spa, FTAG);
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5446
diff changeset
  2709
			return (ENODEV);
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5446
diff changeset
  2710
		}
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
  2711
	}
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
  2712
5329
33cb98223b2d PSARC 2007/567 zpool failmode property
gw25295
parents: 5326
diff changeset
  2713
	vdev_clear(spa, vd, B_TRUE);
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
  2714
4451
24fbf2d7a5d7 PSARC 2007/197 ZFS hotplug
eschrock
parents: 4098
diff changeset
  2715
	(void) spa_vdev_exit(spa, NULL, txg, 0);
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
  2716
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
  2717
	spa_close(spa, FTAG);
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
  2718
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
  2719
	return (0);
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
  2720
}
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
  2721
5367
c40abbe796be PSARC/2007/574 zfs send -R
ahrens
parents: 5331
diff changeset
  2722
/*
c40abbe796be PSARC/2007/574 zfs send -R
ahrens
parents: 5331
diff changeset
  2723
 * inputs:
c40abbe796be PSARC/2007/574 zfs send -R
ahrens
parents: 5331
diff changeset
  2724
 * zc_name	name of filesystem
c40abbe796be PSARC/2007/574 zfs send -R
ahrens
parents: 5331
diff changeset
  2725
 * zc_value	name of origin snapshot
c40abbe796be PSARC/2007/574 zfs send -R
ahrens
parents: 5331
diff changeset
  2726
 *
c40abbe796be PSARC/2007/574 zfs send -R
ahrens
parents: 5331
diff changeset
  2727
 * outputs:	none
c40abbe796be PSARC/2007/574 zfs send -R
ahrens
parents: 5331
diff changeset
  2728
 */
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
  2729
static int
2082
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1775
diff changeset
  2730
zfs_ioc_promote(zfs_cmd_t *zc)
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1775
diff changeset
  2731
{
2417
694d5de97348 6444346 zfs promote fails in zone
ahrens
parents: 2199
diff changeset
  2732
	char *cp;
694d5de97348 6444346 zfs promote fails in zone
ahrens
parents: 2199
diff changeset
  2733
694d5de97348 6444346 zfs promote fails in zone
ahrens
parents: 2199
diff changeset
  2734
	/*
694d5de97348 6444346 zfs promote fails in zone
ahrens
parents: 2199
diff changeset
  2735
	 * We don't need to unmount *all* the origin fs's snapshots, but
694d5de97348 6444346 zfs promote fails in zone
ahrens
parents: 2199
diff changeset
  2736
	 * it's easier.
694d5de97348 6444346 zfs promote fails in zone
ahrens
parents: 2199
diff changeset
  2737
	 */
2676
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  2738
	cp = strchr(zc->zc_value, '@');
2417
694d5de97348 6444346 zfs promote fails in zone
ahrens
parents: 2199
diff changeset
  2739
	if (cp)
694d5de97348 6444346 zfs promote fails in zone
ahrens
parents: 2199
diff changeset
  2740
		*cp = '\0';
2676
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  2741
	(void) dmu_objset_find(zc->zc_value,
2417
694d5de97348 6444346 zfs promote fails in zone
ahrens
parents: 2199
diff changeset
  2742
	    zfs_unmount_snap, NULL, DS_FIND_SNAPSHOTS);
2082
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1775
diff changeset
  2743
	return (dsl_dataset_promote(zc->zc_name));
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1775
diff changeset
  2744
}
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1775
diff changeset
  2745
4543
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  2746
/*
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  2747
 * We don't want to have a hard dependency
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  2748
 * against some special symbols in sharefs
5331
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
  2749
 * nfs, and smbsrv.  Determine them if needed when
4543
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  2750
 * the first file system is shared.
5331
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
  2751
 * Neither sharefs, nfs or smbsrv are unloadable modules.
4543
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  2752
 */
5331
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
  2753
int (*znfsexport_fs)(void *arg);
4543
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  2754
int (*zshare_fs)(enum sharefs_sys_op, share_t *, uint32_t);
5331
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
  2755
int (*zsmbexport_fs)(void *arg, boolean_t add_share);
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
  2756
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
  2757
int zfs_nfsshare_inited;
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
  2758
int zfs_smbshare_inited;
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
  2759
4543
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  2760
ddi_modhandle_t nfs_mod;
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  2761
ddi_modhandle_t sharefs_mod;
5331
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
  2762
ddi_modhandle_t smbsrv_mod;
4543
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  2763
kmutex_t zfs_share_lock;
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  2764
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  2765
static int
5331
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
  2766
zfs_init_sharefs()
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
  2767
{
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
  2768
	int error;
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
  2769
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
  2770
	ASSERT(MUTEX_HELD(&zfs_share_lock));
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
  2771
	/* Both NFS and SMB shares also require sharetab support. */
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
  2772
	if (sharefs_mod == NULL && ((sharefs_mod =
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
  2773
	    ddi_modopen("fs/sharefs",
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
  2774
	    KRTLD_MODE_FIRST, &error)) == NULL)) {
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
  2775
		return (ENOSYS);
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
  2776
	}
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
  2777
	if (zshare_fs == NULL && ((zshare_fs =
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
  2778
	    (int (*)(enum sharefs_sys_op, share_t *, uint32_t))
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
  2779
	    ddi_modsym(sharefs_mod, "sharefs_impl", &error)) == NULL)) {
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
  2780
		return (ENOSYS);
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
  2781
	}
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
  2782
	return (0);
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
  2783
}
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
  2784
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
  2785
static int
4543
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  2786
zfs_ioc_share(zfs_cmd_t *zc)
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  2787
{
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  2788
	int error;
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  2789
	int opcode;
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  2790
5331
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
  2791
	switch (zc->zc_share.z_sharetype) {
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
  2792
	case ZFS_SHARE_NFS:
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
  2793
	case ZFS_UNSHARE_NFS:
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
  2794
		if (zfs_nfsshare_inited == 0) {
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
  2795
			mutex_enter(&zfs_share_lock);
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
  2796
			if (nfs_mod == NULL && ((nfs_mod = ddi_modopen("fs/nfs",
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
  2797
			    KRTLD_MODE_FIRST, &error)) == NULL)) {
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
  2798
				mutex_exit(&zfs_share_lock);
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
  2799
				return (ENOSYS);
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
  2800
			}
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
  2801
			if (znfsexport_fs == NULL &&
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
  2802
			    ((znfsexport_fs = (int (*)(void *))
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
  2803
			    ddi_modsym(nfs_mod,
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
  2804
			    "nfs_export", &error)) == NULL)) {
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
  2805
				mutex_exit(&zfs_share_lock);
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
  2806
				return (ENOSYS);
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
  2807
			}
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
  2808
			error = zfs_init_sharefs();
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
  2809
			if (error) {
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
  2810
				mutex_exit(&zfs_share_lock);
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
  2811
				return (ENOSYS);
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
  2812
			}
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
  2813
			zfs_nfsshare_inited = 1;
4543
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  2814
			mutex_exit(&zfs_share_lock);
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  2815
		}
5331
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
  2816
		break;
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
  2817
	case ZFS_SHARE_SMB:
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
  2818
	case ZFS_UNSHARE_SMB:
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
  2819
		if (zfs_smbshare_inited == 0) {
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
  2820
			mutex_enter(&zfs_share_lock);
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
  2821
			if (smbsrv_mod == NULL && ((smbsrv_mod =
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
  2822
			    ddi_modopen("drv/smbsrv",
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
  2823
			    KRTLD_MODE_FIRST, &error)) == NULL)) {
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
  2824
				mutex_exit(&zfs_share_lock);
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
  2825
				return (ENOSYS);
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
  2826
			}
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
  2827
			if (zsmbexport_fs == NULL && ((zsmbexport_fs =
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
  2828
			    (int (*)(void *, boolean_t))ddi_modsym(smbsrv_mod,
6139
5c743b207bf9 6541120 Configuration is not propagated to SMB kernel module
jb150015
parents: 6083
diff changeset
  2829
			    "smb_server_share", &error)) == NULL)) {
5331
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
  2830
				mutex_exit(&zfs_share_lock);
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
  2831
				return (ENOSYS);
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
  2832
			}
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
  2833
			error = zfs_init_sharefs();
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
  2834
			if (error) {
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
  2835
				mutex_exit(&zfs_share_lock);
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
  2836
				return (ENOSYS);
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
  2837
			}
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
  2838
			zfs_smbshare_inited = 1;
4543
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  2839
			mutex_exit(&zfs_share_lock);
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  2840
		}
5331
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
  2841
		break;
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
  2842
	default:
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
  2843
		return (EINVAL);
4543
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  2844
	}
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  2845
5331
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
  2846
	switch (zc->zc_share.z_sharetype) {
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
  2847
	case ZFS_SHARE_NFS:
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
  2848
	case ZFS_UNSHARE_NFS:
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
  2849
		if (error =
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
  2850
		    znfsexport_fs((void *)
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
  2851
		    (uintptr_t)zc->zc_share.z_exportdata))
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
  2852
			return (error);
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
  2853
		break;
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
  2854
	case ZFS_SHARE_SMB:
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
  2855
	case ZFS_UNSHARE_SMB:
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
  2856
		if (error = zsmbexport_fs((void *)
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
  2857
		    (uintptr_t)zc->zc_share.z_exportdata,
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
  2858
		    zc->zc_share.z_sharetype == ZFS_SHARE_SMB ?
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
  2859
		    B_TRUE : B_FALSE)) {
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
  2860
			return (error);
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
  2861
		}
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
  2862
		break;
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
  2863
	}
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
  2864
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
  2865
	opcode = (zc->zc_share.z_sharetype == ZFS_SHARE_NFS ||
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
  2866
	    zc->zc_share.z_sharetype == ZFS_SHARE_SMB) ?
4543
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  2867
	    SHAREFS_ADD : SHAREFS_REMOVE;
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  2868
5331
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
  2869
	/*
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
  2870
	 * Add or remove share from sharetab
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
  2871
	 */
4543
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  2872
	error = zshare_fs(opcode,
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  2873
	    (void *)(uintptr_t)zc->zc_share.z_sharedata,
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  2874
	    zc->zc_share.z_sharemax);
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  2875
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  2876
	return (error);
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  2877
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  2878
}
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  2879
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  2880
/*
4988
db8abd9846d4 6595467 libzfs consumers should be allowed to write their own history (or none at all)
ek110237
parents: 4849
diff changeset
  2881
 * pool create, destroy, and export don't log the history as part of
db8abd9846d4 6595467 libzfs consumers should be allowed to write their own history (or none at all)
ek110237
parents: 4849
diff changeset
  2882
 * zfsdev_ioctl, but rather zfs_ioc_pool_create, and zfs_ioc_pool_export
db8abd9846d4 6595467 libzfs consumers should be allowed to write their own history (or none at all)
ek110237
parents: 4849
diff changeset
  2883
 * do the logging of those commands.
4543
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  2884
 */
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2885
static zfs_ioc_vec_t zfs_ioc_vec[] = {
4715
e8d212dda064 6535695 Panic: shpp->sh_eof == shpp->sh_pool_create_len, file: ../../common/fs/zfs/spa_history.c, line: 235
ek110237
parents: 4670
diff changeset
  2886
	{ zfs_ioc_pool_create, zfs_secpolicy_config, POOL_NAME, B_FALSE },
4577
ed36b0e652bc PSARC/2007/328 zfs upgrade
ahrens
parents: 4543
diff changeset
  2887
	{ zfs_ioc_pool_destroy,	zfs_secpolicy_config, POOL_NAME, B_FALSE },
ed36b0e652bc PSARC/2007/328 zfs upgrade
ahrens
parents: 4543
diff changeset
  2888
	{ zfs_ioc_pool_import, zfs_secpolicy_config, POOL_NAME, B_TRUE },
ed36b0e652bc PSARC/2007/328 zfs upgrade
ahrens
parents: 4543
diff changeset
  2889
	{ zfs_ioc_pool_export, zfs_secpolicy_config, POOL_NAME, B_FALSE },
ed36b0e652bc PSARC/2007/328 zfs upgrade
ahrens
parents: 4543
diff changeset
  2890
	{ zfs_ioc_pool_configs,	zfs_secpolicy_none, NO_NAME, B_FALSE },
ed36b0e652bc PSARC/2007/328 zfs upgrade
ahrens
parents: 4543
diff changeset
  2891
	{ zfs_ioc_pool_stats, zfs_secpolicy_read, POOL_NAME, B_FALSE },
ed36b0e652bc PSARC/2007/328 zfs upgrade
ahrens
parents: 4543
diff changeset
  2892
	{ zfs_ioc_pool_tryimport, zfs_secpolicy_config, NO_NAME, B_FALSE },
ed36b0e652bc PSARC/2007/328 zfs upgrade
ahrens
parents: 4543
diff changeset
  2893
	{ zfs_ioc_pool_scrub, zfs_secpolicy_config, POOL_NAME, B_TRUE },
ed36b0e652bc PSARC/2007/328 zfs upgrade
ahrens
parents: 4543
diff changeset
  2894
	{ zfs_ioc_pool_freeze, zfs_secpolicy_config, NO_NAME, B_FALSE },
ed36b0e652bc PSARC/2007/328 zfs upgrade
ahrens
parents: 4543
diff changeset
  2895
	{ zfs_ioc_pool_upgrade,	zfs_secpolicy_config, POOL_NAME, B_TRUE },
ed36b0e652bc PSARC/2007/328 zfs upgrade
ahrens
parents: 4543
diff changeset
  2896
	{ zfs_ioc_pool_get_history, zfs_secpolicy_config, POOL_NAME, B_FALSE },
ed36b0e652bc PSARC/2007/328 zfs upgrade
ahrens
parents: 4543
diff changeset
  2897
	{ zfs_ioc_vdev_add, zfs_secpolicy_config, POOL_NAME, B_TRUE },
ed36b0e652bc PSARC/2007/328 zfs upgrade
ahrens
parents: 4543
diff changeset
  2898
	{ zfs_ioc_vdev_remove, zfs_secpolicy_config, POOL_NAME, B_TRUE },
ed36b0e652bc PSARC/2007/328 zfs upgrade
ahrens
parents: 4543
diff changeset
  2899
	{ zfs_ioc_vdev_set_state, zfs_secpolicy_config,	POOL_NAME, B_TRUE },
ed36b0e652bc PSARC/2007/328 zfs upgrade
ahrens
parents: 4543
diff changeset
  2900
	{ zfs_ioc_vdev_attach, zfs_secpolicy_config, POOL_NAME, B_TRUE },
ed36b0e652bc PSARC/2007/328 zfs upgrade
ahrens
parents: 4543
diff changeset
  2901
	{ zfs_ioc_vdev_detach, zfs_secpolicy_config, POOL_NAME, B_TRUE },
ed36b0e652bc PSARC/2007/328 zfs upgrade
ahrens
parents: 4543
diff changeset
  2902
	{ zfs_ioc_vdev_setpath,	zfs_secpolicy_config, POOL_NAME, B_FALSE },
ed36b0e652bc PSARC/2007/328 zfs upgrade
ahrens
parents: 4543
diff changeset
  2903
	{ zfs_ioc_objset_stats,	zfs_secpolicy_read, DATASET_NAME, B_FALSE },
5498
334b476844ca 6622831 normalization properties are not preserved by "zfs send"
timh
parents: 5450
diff changeset
  2904
	{ zfs_ioc_objset_zplprops, zfs_secpolicy_read, DATASET_NAME, B_FALSE },
4543
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  2905
	{ zfs_ioc_dataset_list_next, zfs_secpolicy_read,
4577
ed36b0e652bc PSARC/2007/328 zfs upgrade
ahrens
parents: 4543
diff changeset
  2906
	    DATASET_NAME, B_FALSE },
4543
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  2907
	{ zfs_ioc_snapshot_list_next, zfs_secpolicy_read,
4577
ed36b0e652bc PSARC/2007/328 zfs upgrade
ahrens
parents: 4543
diff changeset
  2908
	    DATASET_NAME, B_FALSE },
ed36b0e652bc PSARC/2007/328 zfs upgrade
ahrens
parents: 4543
diff changeset
  2909
	{ zfs_ioc_set_prop, zfs_secpolicy_none, DATASET_NAME, B_TRUE },
ed36b0e652bc PSARC/2007/328 zfs upgrade
ahrens
parents: 4543
diff changeset
  2910
	{ zfs_ioc_create_minor,	zfs_secpolicy_minor, DATASET_NAME, B_FALSE },
ed36b0e652bc PSARC/2007/328 zfs upgrade
ahrens
parents: 4543
diff changeset
  2911
	{ zfs_ioc_remove_minor,	zfs_secpolicy_minor, DATASET_NAME, B_FALSE },
ed36b0e652bc PSARC/2007/328 zfs upgrade
ahrens
parents: 4543
diff changeset
  2912
	{ zfs_ioc_create, zfs_secpolicy_create, DATASET_NAME, B_TRUE },
ed36b0e652bc PSARC/2007/328 zfs upgrade
ahrens
parents: 4543
diff changeset
  2913
	{ zfs_ioc_destroy, zfs_secpolicy_destroy, DATASET_NAME, B_TRUE },
ed36b0e652bc PSARC/2007/328 zfs upgrade
ahrens
parents: 4543
diff changeset
  2914
	{ zfs_ioc_rollback, zfs_secpolicy_rollback, DATASET_NAME, B_TRUE },
ed36b0e652bc PSARC/2007/328 zfs upgrade
ahrens
parents: 4543
diff changeset
  2915
	{ zfs_ioc_rename, zfs_secpolicy_rename,	DATASET_NAME, B_TRUE },
5367
c40abbe796be PSARC/2007/574 zfs send -R
ahrens
parents: 5331
diff changeset
  2916
	{ zfs_ioc_recv, zfs_secpolicy_receive, DATASET_NAME, B_TRUE },
c40abbe796be PSARC/2007/574 zfs send -R
ahrens
parents: 5331
diff changeset
  2917
	{ zfs_ioc_send, zfs_secpolicy_send, DATASET_NAME, B_TRUE },
4577
ed36b0e652bc PSARC/2007/328 zfs upgrade
ahrens
parents: 4543
diff changeset
  2918
	{ zfs_ioc_inject_fault,	zfs_secpolicy_inject, NO_NAME, B_FALSE },
ed36b0e652bc PSARC/2007/328 zfs upgrade
ahrens
parents: 4543
diff changeset
  2919
	{ zfs_ioc_clear_fault, zfs_secpolicy_inject, NO_NAME, B_FALSE },
ed36b0e652bc PSARC/2007/328 zfs upgrade
ahrens
parents: 4543
diff changeset
  2920
	{ zfs_ioc_inject_list_next, zfs_secpolicy_inject, NO_NAME, B_FALSE },
ed36b0e652bc PSARC/2007/328 zfs upgrade
ahrens
parents: 4543
diff changeset
  2921
	{ zfs_ioc_error_log, zfs_secpolicy_inject, POOL_NAME, B_FALSE },
ed36b0e652bc PSARC/2007/328 zfs upgrade
ahrens
parents: 4543
diff changeset
  2922
	{ zfs_ioc_clear, zfs_secpolicy_config, POOL_NAME, B_TRUE },
ed36b0e652bc PSARC/2007/328 zfs upgrade
ahrens
parents: 4543
diff changeset
  2923
	{ zfs_ioc_promote, zfs_secpolicy_promote, DATASET_NAME, B_TRUE },
ed36b0e652bc PSARC/2007/328 zfs upgrade
ahrens
parents: 4543
diff changeset
  2924
	{ zfs_ioc_destroy_snaps, zfs_secpolicy_destroy,	DATASET_NAME, B_TRUE },
ed36b0e652bc PSARC/2007/328 zfs upgrade
ahrens
parents: 4543
diff changeset
  2925
	{ zfs_ioc_snapshot, zfs_secpolicy_snapshot, DATASET_NAME, B_TRUE },
ed36b0e652bc PSARC/2007/328 zfs upgrade
ahrens
parents: 4543
diff changeset
  2926
	{ zfs_ioc_dsobj_to_dsname, zfs_secpolicy_config, POOL_NAME, B_FALSE },
ed36b0e652bc PSARC/2007/328 zfs upgrade
ahrens
parents: 4543
diff changeset
  2927
	{ zfs_ioc_obj_to_path, zfs_secpolicy_config, NO_NAME, B_FALSE },
ed36b0e652bc PSARC/2007/328 zfs upgrade
ahrens
parents: 4543
diff changeset
  2928
	{ zfs_ioc_pool_set_props, zfs_secpolicy_config,	POOL_NAME, B_TRUE },
ed36b0e652bc PSARC/2007/328 zfs upgrade
ahrens
parents: 4543
diff changeset
  2929
	{ zfs_ioc_pool_get_props, zfs_secpolicy_read, POOL_NAME, B_FALSE },
ed36b0e652bc PSARC/2007/328 zfs upgrade
ahrens
parents: 4543
diff changeset
  2930
	{ zfs_ioc_set_fsacl, zfs_secpolicy_fsacl, DATASET_NAME, B_TRUE },
ed36b0e652bc PSARC/2007/328 zfs upgrade
ahrens
parents: 4543
diff changeset
  2931
	{ zfs_ioc_get_fsacl, zfs_secpolicy_read, DATASET_NAME, B_FALSE },
4543
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  2932
	{ zfs_ioc_iscsi_perm_check, zfs_secpolicy_iscsi,
4577
ed36b0e652bc PSARC/2007/328 zfs upgrade
ahrens
parents: 4543
diff changeset
  2933
	    DATASET_NAME, B_FALSE },
4849
3a61e0a9a953 6536043 arc_byteswap_func_t and dmu_byteswap_func_t are redundant
ahrens
parents: 4808
diff changeset
  2934
	{ zfs_ioc_share, zfs_secpolicy_share, DATASET_NAME, B_FALSE },
3a61e0a9a953 6536043 arc_byteswap_func_t and dmu_byteswap_func_t are redundant
ahrens
parents: 4808
diff changeset
  2935
	{ zfs_ioc_inherit_prop, zfs_secpolicy_inherit, DATASET_NAME, B_TRUE },
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2936
};
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2937
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2938
static int
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2939
zfsdev_ioctl(dev_t dev, int cmd, intptr_t arg, int flag, cred_t *cr, int *rvalp)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2940
{
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2941
	zfs_cmd_t *zc;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2942
	uint_t vec;
2199
712a788c2dfd PSARC 2006/388 snapshot -r
ahrens
parents: 2082
diff changeset
  2943
	int error, rc;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2944
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2945
	if (getminor(dev) != 0)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2946
		return (zvol_ioctl(dev, cmd, arg, flag, cr, rvalp));
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2947
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2948
	vec = cmd - ZFS_IOC;
4787
602d3f97842c 6393351 unique_* could be improved
ahrens
parents: 4720
diff changeset
  2949
	ASSERT3U(getmajor(dev), ==, ddi_driver_major(zfs_dip));
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2950
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2951
	if (vec >= sizeof (zfs_ioc_vec) / sizeof (zfs_ioc_vec[0]))
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2952
		return (EINVAL);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2953
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2954
	zc = kmem_zalloc(sizeof (zfs_cmd_t), KM_SLEEP);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2955
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2956
	error = xcopyin((void *)arg, zc, sizeof (zfs_cmd_t));
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2957
4787
602d3f97842c 6393351 unique_* could be improved
ahrens
parents: 4720
diff changeset
  2958
	if (error == 0)
4543
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  2959
		error = zfs_ioc_vec[vec].zvec_secpolicy(zc, cr);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2960
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2961
	/*
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2962
	 * Ensure that all pool/dataset names are valid before we pass down to
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2963
	 * the lower layers.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2964
	 */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2965
	if (error == 0) {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2966
		zc->zc_name[sizeof (zc->zc_name) - 1] = '\0';
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2967
		switch (zfs_ioc_vec[vec].zvec_namecheck) {
4577
ed36b0e652bc PSARC/2007/328 zfs upgrade
ahrens
parents: 4543
diff changeset
  2968
		case POOL_NAME:
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2969
			if (pool_namecheck(zc->zc_name, NULL, NULL) != 0)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2970
				error = EINVAL;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2971
			break;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2972
4577
ed36b0e652bc PSARC/2007/328 zfs upgrade
ahrens
parents: 4543
diff changeset
  2973
		case DATASET_NAME:
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2974
			if (dataset_namecheck(zc->zc_name, NULL, NULL) != 0)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2975
				error = EINVAL;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2976
			break;
2856
6f4d5ee1906a 6463348 ZFS code could be more portable
nd150628
parents: 2717
diff changeset
  2977
4577
ed36b0e652bc PSARC/2007/328 zfs upgrade
ahrens
parents: 4543
diff changeset
  2978
		case NO_NAME:
2856
6f4d5ee1906a 6463348 ZFS code could be more portable
nd150628
parents: 2717
diff changeset
  2979
			break;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2980
		}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2981
	}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2982
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2983
	if (error == 0)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2984
		error = zfs_ioc_vec[vec].zvec_func(zc);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2985
2199
712a788c2dfd PSARC 2006/388 snapshot -r
ahrens
parents: 2082
diff changeset
  2986
	rc = xcopyout(zc, (void *)arg, sizeof (zfs_cmd_t));
4543
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  2987
	if (error == 0) {
2199
712a788c2dfd PSARC 2006/388 snapshot -r
ahrens
parents: 2082
diff changeset
  2988
		error = rc;
4543
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  2989
		if (zfs_ioc_vec[vec].zvec_his_log == B_TRUE)
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  2990
			zfs_log_history(zc);
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  2991
	}
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2992
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2993
	kmem_free(zc, sizeof (zfs_cmd_t));
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2994
	return (error);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2995
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2996
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2997
static int
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2998
zfs_attach(dev_info_t *dip, ddi_attach_cmd_t cmd)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2999
{
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3000
	if (cmd != DDI_ATTACH)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3001
		return (DDI_FAILURE);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3002
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3003
	if (ddi_create_minor_node(dip, "zfs", S_IFCHR, 0,
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3004
	    DDI_PSEUDO, 0) == DDI_FAILURE)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3005
		return (DDI_FAILURE);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3006
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3007
	zfs_dip = dip;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3008
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3009
	ddi_report_dev(dip);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3010
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3011
	return (DDI_SUCCESS);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3012
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3013
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3014
static int
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3015
zfs_detach(dev_info_t *dip, ddi_detach_cmd_t cmd)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3016
{
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3017
	if (spa_busy() || zfs_busy() || zvol_busy())
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3018
		return (DDI_FAILURE);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3019
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3020
	if (cmd != DDI_DETACH)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3021
		return (DDI_FAILURE);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3022
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3023
	zfs_dip = NULL;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3024
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3025
	ddi_prop_remove_all(dip);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3026
	ddi_remove_minor_node(dip, NULL);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3027
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3028
	return (DDI_SUCCESS);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3029
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3030
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3031
/*ARGSUSED*/
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3032
static int
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3033
zfs_info(dev_info_t *dip, ddi_info_cmd_t infocmd, void *arg, void **result)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3034
{
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3035
	switch (infocmd) {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3036
	case DDI_INFO_DEVT2DEVINFO:
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3037
		*result = zfs_dip;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3038
		return (DDI_SUCCESS);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3039
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3040
	case DDI_INFO_DEVT2INSTANCE:
849
8d799fd81a9b 6345023 /dev/zfs fails to open once ZFS module is unloaded
bonwick
parents: 789
diff changeset
  3041
		*result = (void *)0;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3042
		return (DDI_SUCCESS);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3043
	}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3044
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3045
	return (DDI_FAILURE);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3046
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3047
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3048
/*
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3049
 * OK, so this is a little weird.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3050
 *
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3051
 * /dev/zfs is the control node, i.e. minor 0.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3052
 * /dev/zvol/[r]dsk/pool/dataset are the zvols, minor > 0.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3053
 *
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3054
 * /dev/zfs has basically nothing to do except serve up ioctls,
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3055
 * so most of the standard driver entry points are in zvol.c.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3056
 */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3057
static struct cb_ops zfs_cb_ops = {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3058
	zvol_open,	/* open */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3059
	zvol_close,	/* close */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3060
	zvol_strategy,	/* strategy */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3061
	nodev,		/* print */
6423
437422a29d3a PSARC 2006/370 ZFS Boot Support
gw25295
parents: 6139
diff changeset
  3062
	zvol_dump,	/* dump */
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3063
	zvol_read,	/* read */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3064
	zvol_write,	/* write */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3065
	zfsdev_ioctl,	/* ioctl */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3066
	nodev,		/* devmap */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3067
	nodev,		/* mmap */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3068
	nodev,		/* segmap */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3069
	nochpoll,	/* poll */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3070
	ddi_prop_op,	/* prop_op */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3071
	NULL,		/* streamtab */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3072
	D_NEW | D_MP | D_64BIT,		/* Driver compatibility flag */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3073
	CB_REV,		/* version */
3638
6b28ebc717aa 6496357 spec_fsync() is useless on devices that do write caching
billm
parents: 3444
diff changeset
  3074
	nodev,		/* async read */
6b28ebc717aa 6496357 spec_fsync() is useless on devices that do write caching
billm
parents: 3444
diff changeset
  3075
	nodev,		/* async write */
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3076
};
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3077
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3078
static struct dev_ops zfs_dev_ops = {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3079
	DEVO_REV,	/* version */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3080
	0,		/* refcnt */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3081
	zfs_info,	/* info */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3082
	nulldev,	/* identify */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3083
	nulldev,	/* probe */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3084
	zfs_attach,	/* attach */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3085
	zfs_detach,	/* detach */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3086
	nodev,		/* reset */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3087
	&zfs_cb_ops,	/* driver operations */
7656
2621e50fdf4a PSARC 2008/382 Fast Reboot
Sherry Moore <Sherry.Moore@Sun.COM>
parents: 7294
diff changeset
  3088
	NULL,		/* no bus operations */
2621e50fdf4a PSARC 2008/382 Fast Reboot
Sherry Moore <Sherry.Moore@Sun.COM>
parents: 7294
diff changeset
  3089
	NULL,		/* power */
2621e50fdf4a PSARC 2008/382 Fast Reboot
Sherry Moore <Sherry.Moore@Sun.COM>
parents: 7294
diff changeset
  3090
	ddi_quiesce_not_needed,	/* quiesce */
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3091
};
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3092
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3093
static struct modldrv zfs_modldrv = {
7656
2621e50fdf4a PSARC 2008/382 Fast Reboot
Sherry Moore <Sherry.Moore@Sun.COM>
parents: 7294
diff changeset
  3094
	&mod_driverops,
2621e50fdf4a PSARC 2008/382 Fast Reboot
Sherry Moore <Sherry.Moore@Sun.COM>
parents: 7294
diff changeset
  3095
	"ZFS storage pool",
2621e50fdf4a PSARC 2008/382 Fast Reboot
Sherry Moore <Sherry.Moore@Sun.COM>
parents: 7294
diff changeset
  3096
	&zfs_dev_ops
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3097
};
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3098
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3099
static struct modlinkage modlinkage = {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3100
	MODREV_1,
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3101
	(void *)&zfs_modlfs,
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3102
	(void *)&zfs_modldrv,
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3103
	NULL
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3104
};
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3105
4720
8edc0d2e6f3f 6535160 Lock contention on zl_lock from zil_commit
fr157268
parents: 4715
diff changeset
  3106
8edc0d2e6f3f 6535160 Lock contention on zl_lock from zil_commit
fr157268
parents: 4715
diff changeset
  3107
uint_t zfs_fsyncer_key;
5326
6752aa2bd5bc 6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents: 5147
diff changeset
  3108
extern uint_t rrw_tsd_key;
4720
8edc0d2e6f3f 6535160 Lock contention on zl_lock from zil_commit
fr157268
parents: 4715
diff changeset
  3109
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3110
int
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3111
_init(void)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3112
{
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3113
	int error;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3114
849
8d799fd81a9b 6345023 /dev/zfs fails to open once ZFS module is unloaded
bonwick
parents: 789
diff changeset
  3115
	spa_init(FREAD | FWRITE);
8d799fd81a9b 6345023 /dev/zfs fails to open once ZFS module is unloaded
bonwick
parents: 789
diff changeset
  3116
	zfs_init();
8d799fd81a9b 6345023 /dev/zfs fails to open once ZFS module is unloaded
bonwick
parents: 789
diff changeset
  3117
	zvol_init();
8d799fd81a9b 6345023 /dev/zfs fails to open once ZFS module is unloaded
bonwick
parents: 789
diff changeset
  3118
8d799fd81a9b 6345023 /dev/zfs fails to open once ZFS module is unloaded
bonwick
parents: 789
diff changeset
  3119
	if ((error = mod_install(&modlinkage)) != 0) {
8d799fd81a9b 6345023 /dev/zfs fails to open once ZFS module is unloaded
bonwick
parents: 789
diff changeset
  3120
		zvol_fini();
8d799fd81a9b 6345023 /dev/zfs fails to open once ZFS module is unloaded
bonwick
parents: 789
diff changeset
  3121
		zfs_fini();
8d799fd81a9b 6345023 /dev/zfs fails to open once ZFS module is unloaded
bonwick
parents: 789
diff changeset
  3122
		spa_fini();
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3123
		return (error);
849
8d799fd81a9b 6345023 /dev/zfs fails to open once ZFS module is unloaded
bonwick
parents: 789
diff changeset
  3124
	}
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3125
4720
8edc0d2e6f3f 6535160 Lock contention on zl_lock from zil_commit
fr157268
parents: 4715
diff changeset
  3126
	tsd_create(&zfs_fsyncer_key, NULL);
5326
6752aa2bd5bc 6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents: 5147
diff changeset
  3127
	tsd_create(&rrw_tsd_key, NULL);
4720
8edc0d2e6f3f 6535160 Lock contention on zl_lock from zil_commit
fr157268
parents: 4715
diff changeset
  3128
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3129
	error = ldi_ident_from_mod(&modlinkage, &zfs_li);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3130
	ASSERT(error == 0);
4543
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  3131
	mutex_init(&zfs_share_lock, NULL, MUTEX_DEFAULT, NULL);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3132
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3133
	return (0);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3134
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3135
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3136
int
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3137
_fini(void)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3138
{
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3139
	int error;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3140
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
  3141
	if (spa_busy() || zfs_busy() || zvol_busy() || zio_injection_enabled)
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3142
		return (EBUSY);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3143
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3144
	if ((error = mod_remove(&modlinkage)) != 0)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3145
		return (error);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3146
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3147
	zvol_fini();
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3148
	zfs_fini();
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3149
	spa_fini();
5331
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
  3150
	if (zfs_nfsshare_inited)
4543
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  3151
		(void) ddi_modclose(nfs_mod);
5331
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
  3152
	if (zfs_smbshare_inited)
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
  3153
		(void) ddi_modclose(smbsrv_mod);
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
  3154
	if (zfs_nfsshare_inited || zfs_smbshare_inited)
4543
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  3155
		(void) ddi_modclose(sharefs_mod);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3156
4720
8edc0d2e6f3f 6535160 Lock contention on zl_lock from zil_commit
fr157268
parents: 4715
diff changeset
  3157
	tsd_destroy(&zfs_fsyncer_key);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3158
	ldi_ident_release(zfs_li);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3159
	zfs_li = NULL;
4543
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  3160
	mutex_destroy(&zfs_share_lock);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3161
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3162
	return (error);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3163
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3164
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3165
int
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3166
_info(struct modinfo *modinfop)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3167
{
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3168
	return (mod_info(&modlinkage, modinfop));
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3169
}