usr/src/uts/common/fs/zfs/zfs_ioctl.c
author lling
Fri, 21 Sep 2007 14:52:33 -0700
changeset 5118 c723b1aa9f79
parent 5094 71a3e95fb9e2
child 5147 5e950ccc9585
permissions -rw-r--r--
6607671 Able to zpool upgrade a pool to an unknown version number
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
/*
3444
dc160a70a50d 6410433 'zpool status -v' would be more useful with filenames
ek110237
parents: 3265
diff changeset
    22
 * Copyright 2007 Sun Microsystems, Inc.  All rights reserved.
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    23
 * Use is subject to license terms.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    24
 */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    25
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    26
#pragma ident	"%Z%%M%	%I%	%E% SMI"
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    27
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    28
#include <sys/types.h>
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    29
#include <sys/param.h>
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    30
#include <sys/errno.h>
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    31
#include <sys/uio.h>
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    32
#include <sys/buf.h>
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    33
#include <sys/modctl.h>
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    34
#include <sys/open.h>
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    35
#include <sys/file.h>
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    36
#include <sys/kmem.h>
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    37
#include <sys/conf.h>
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    38
#include <sys/cmn_err.h>
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    39
#include <sys/stat.h>
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    40
#include <sys/zfs_ioctl.h>
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>
2885
c0259887ebbc 6460059 zfs destroy <snapshot> leaves behind kruft
ahrens
parents: 2856
diff changeset
    63
#include <sys/zvol.h>
4543
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
    64
#include <sharefs/share.h>
4577
ed36b0e652bc PSARC/2007/328 zfs upgrade
ahrens
parents: 4543
diff changeset
    65
#include <sys/zfs_znode.h>
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    66
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    67
#include "zfs_namecheck.h"
2676
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
    68
#include "zfs_prop.h"
4543
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
    69
#include "zfs_deleg.h"
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    70
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    71
extern struct modlfs zfs_modlfs;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    72
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    73
extern void zfs_init(void);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    74
extern void zfs_fini(void);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    75
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    76
ldi_ident_t zfs_li = NULL;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    77
dev_info_t *zfs_dip;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    78
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    79
typedef int zfs_ioc_func_t(zfs_cmd_t *);
4543
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
    80
typedef int zfs_secpolicy_func_t(zfs_cmd_t *, cred_t *);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    81
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    82
typedef struct zfs_ioc_vec {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    83
	zfs_ioc_func_t		*zvec_func;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    84
	zfs_secpolicy_func_t	*zvec_secpolicy;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    85
	enum {
4577
ed36b0e652bc PSARC/2007/328 zfs upgrade
ahrens
parents: 4543
diff changeset
    86
		NO_NAME,
ed36b0e652bc PSARC/2007/328 zfs upgrade
ahrens
parents: 4543
diff changeset
    87
		POOL_NAME,
ed36b0e652bc PSARC/2007/328 zfs upgrade
ahrens
parents: 4543
diff changeset
    88
		DATASET_NAME
4543
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
    89
	} zvec_namecheck;
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
    90
	boolean_t		zvec_his_log;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    91
} zfs_ioc_vec_t;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    92
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    93
/* _NOTE(PRINTFLIKE(4)) - this is printf-like, but lint is too whiney */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    94
void
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    95
__dprintf(const char *file, const char *func, int line, const char *fmt, ...)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    96
{
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    97
	const char *newfile;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    98
	char buf[256];
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    99
	va_list adx;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   100
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   101
	/*
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   102
	 * Get rid of annoying "../common/" prefix to filename.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   103
	 */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   104
	newfile = strrchr(file, '/');
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   105
	if (newfile != NULL) {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   106
		newfile = newfile + 1; /* Get rid of leading / */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   107
	} else {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   108
		newfile = file;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   109
	}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   110
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   111
	va_start(adx, fmt);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   112
	(void) vsnprintf(buf, sizeof (buf), fmt, adx);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   113
	va_end(adx);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   114
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   115
	/*
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   116
	 * To get this data, use the zfs-dprintf probe as so:
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   117
	 * dtrace -q -n 'zfs-dprintf \
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   118
	 *	/stringof(arg0) == "dbuf.c"/ \
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   119
	 *	{printf("%s: %s", stringof(arg1), stringof(arg3))}'
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   120
	 * arg0 = file name
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   121
	 * arg1 = function name
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   122
	 * arg2 = line number
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   123
	 * arg3 = message
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   124
	 */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   125
	DTRACE_PROBE4(zfs__dprintf,
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   126
	    char *, newfile, char *, func, int, line, char *, buf);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   127
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   128
4543
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   129
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
   130
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
   131
{
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
   132
	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
   133
}
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
   134
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
   135
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
   136
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
   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
	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
   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
	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
   141
		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
   142
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
	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
   144
	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
   145
	    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
   146
		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
   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
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
	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
   151
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
	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
   153
}
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
static void
4543
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   156
zfs_log_history(zfs_cmd_t *zc)
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   157
{
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   158
	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
   159
	char *buf;
4543
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   160
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
   161
	if ((buf = history_str_get(zc)) == NULL)
4577
ed36b0e652bc PSARC/2007/328 zfs upgrade
ahrens
parents: 4543
diff changeset
   162
		return;
ed36b0e652bc PSARC/2007/328 zfs upgrade
ahrens
parents: 4543
diff changeset
   163
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
   164
	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
   165
		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
   166
			(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
   167
		spa_close(spa, FTAG);
4543
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   168
	}
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
   169
	history_str_free(buf);
4543
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   170
}
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   171
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   172
/*
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   173
 * Policy for top-level read operations (list pools).  Requires no privileges,
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   174
 * and can be used in the local zone, as there is no associated dataset.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   175
 */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   176
/* ARGSUSED */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   177
static int
4543
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   178
zfs_secpolicy_none(zfs_cmd_t *zc, cred_t *cr)
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   179
{
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   180
	return (0);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   181
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   182
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   183
/*
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   184
 * Policy for dataset read operations (list children, get statistics).  Requires
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   185
 * no privileges, but must be visible in the local zone.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   186
 */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   187
/* ARGSUSED */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   188
static int
4543
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   189
zfs_secpolicy_read(zfs_cmd_t *zc, cred_t *cr)
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   190
{
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   191
	if (INGLOBALZONE(curproc) ||
4543
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   192
	    zone_dataset_visible(zc->zc_name, NULL))
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   193
		return (0);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   194
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   195
	return (ENOENT);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   196
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   197
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   198
static int
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   199
zfs_dozonecheck(const char *dataset, cred_t *cr)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   200
{
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   201
	uint64_t zoned;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   202
	int writable = 1;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   203
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   204
	/*
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   205
	 * The dataset must be visible by this zone -- check this first
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   206
	 * so they don't see EPERM on something they shouldn't know about.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   207
	 */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   208
	if (!INGLOBALZONE(curproc) &&
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   209
	    !zone_dataset_visible(dataset, &writable))
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   210
		return (ENOENT);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   211
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   212
	if (dsl_prop_get_integer(dataset, "zoned", &zoned, NULL))
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   213
		return (ENOENT);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   214
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   215
	if (INGLOBALZONE(curproc)) {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   216
		/*
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   217
		 * If the fs is zoned, only root can access it from the
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   218
		 * global zone.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   219
		 */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   220
		if (secpolicy_zfs(cr) && zoned)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   221
			return (EPERM);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   222
	} else {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   223
		/*
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   224
		 * If we are in a local zone, the 'zoned' property must be set.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   225
		 */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   226
		if (!zoned)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   227
			return (EPERM);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   228
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   229
		/* must be writable by this zone */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   230
		if (!writable)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   231
			return (EPERM);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   232
	}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   233
	return (0);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   234
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   235
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   236
int
4543
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   237
zfs_secpolicy_write_perms(const char *name, const char *perm, cred_t *cr)
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   238
{
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   239
	int error;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   240
4543
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   241
	error = zfs_dozonecheck(name, cr);
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   242
	if (error == 0) {
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   243
		error = secpolicy_zfs(cr);
4670
002728040e28 6580745 "zfs inherit" can be executed by ordinary user
ahrens
parents: 4611
diff changeset
   244
		if (error)
4543
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   245
			error = dsl_deleg_access(name, perm, cr);
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   246
	}
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   247
	return (error);
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   248
}
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   249
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   250
static int
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   251
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
   252
{
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   253
	/*
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   254
	 * Check permissions for special properties.
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   255
	 */
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   256
	switch (prop) {
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   257
	case ZFS_PROP_ZONED:
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   258
		/*
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   259
		 * Disallow setting of 'zoned' from within a local zone.
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   260
		 */
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   261
		if (!INGLOBALZONE(curproc))
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   262
			return (EPERM);
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   263
		break;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   264
4543
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   265
	case ZFS_PROP_QUOTA:
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   266
		if (!INGLOBALZONE(curproc)) {
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   267
			uint64_t zoned;
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   268
			char setpoint[MAXNAMELEN];
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   269
			/*
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   270
			 * Unprivileged users are allowed to modify the
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   271
			 * quota on things *under* (ie. contained by)
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   272
			 * the thing they own.
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   273
			 */
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   274
			if (dsl_prop_get_integer(name, "zoned", &zoned,
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   275
			    setpoint))
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   276
				return (EPERM);
4670
002728040e28 6580745 "zfs inherit" can be executed by ordinary user
ahrens
parents: 4611
diff changeset
   277
			if (!zoned || strlen(name) <= strlen(setpoint))
4543
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   278
				return (EPERM);
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   279
		}
4670
002728040e28 6580745 "zfs inherit" can be executed by ordinary user
ahrens
parents: 4611
diff changeset
   280
		break;
4543
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   281
	}
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   282
4787
602d3f97842c 6393351 unique_* could be improved
ahrens
parents: 4720
diff changeset
   283
	return (zfs_secpolicy_write_perms(name, zfs_prop_to_name(prop), cr));
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   284
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   285
4543
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   286
int
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   287
zfs_secpolicy_fsacl(zfs_cmd_t *zc, cred_t *cr)
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   288
{
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   289
	int error;
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   290
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   291
	error = zfs_dozonecheck(zc->zc_name, cr);
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   292
	if (error)
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   293
		return (error);
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   294
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   295
	/*
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   296
	 * permission to set permissions will be evaluated later in
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   297
	 * dsl_deleg_can_allow()
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   298
	 */
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   299
	return (0);
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   300
}
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   301
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   302
int
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   303
zfs_secpolicy_rollback(zfs_cmd_t *zc, cred_t *cr)
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   304
{
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   305
	int error;
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   306
	error = zfs_secpolicy_write_perms(zc->zc_name,
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   307
	    ZFS_DELEG_PERM_ROLLBACK, cr);
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   308
	if (error == 0)
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   309
		error = zfs_secpolicy_write_perms(zc->zc_name,
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   310
		    ZFS_DELEG_PERM_MOUNT, cr);
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   311
	return (error);
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   312
}
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   313
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   314
int
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   315
zfs_secpolicy_send(zfs_cmd_t *zc, cred_t *cr)
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   316
{
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   317
	return (zfs_secpolicy_write_perms(zc->zc_name,
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   318
	    ZFS_DELEG_PERM_SEND, cr));
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   319
}
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
int
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   322
zfs_secpolicy_share(zfs_cmd_t *zc, cred_t *cr)
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   323
{
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   324
	if (!INGLOBALZONE(curproc))
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   325
		return (EPERM);
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   326
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   327
	if (secpolicy_nfs(CRED()) == 0) {
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   328
		return (0);
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   329
	} else {
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   330
		vnode_t *vp;
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   331
		int error;
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 ((error = lookupname(zc->zc_value, UIO_SYSSPACE,
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   334
		    NO_FOLLOW, NULL, &vp)) != 0)
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   335
			return (error);
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   336
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   337
		/* Now make sure mntpnt and dataset are ZFS */
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   338
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   339
		if (vp->v_vfsp->vfs_fstype != zfsfstype ||
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   340
		    (strcmp((char *)refstr_value(vp->v_vfsp->vfs_resource),
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   341
		    zc->zc_name) != 0)) {
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   342
			VN_RELE(vp);
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   343
			return (EPERM);
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   344
		}
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
		VN_RELE(vp);
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   347
		return (dsl_deleg_access(zc->zc_name,
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   348
		    ZFS_DELEG_PERM_SHARE, cr));
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   349
	}
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   350
}
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   351
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   352
static int
4543
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   353
zfs_get_parent(const char *datasetname, char *parent, int parentsize)
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   354
{
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   355
	char *cp;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   356
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   357
	/*
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   358
	 * Remove the @bla or /bla from the end of the name to get the parent.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   359
	 */
4543
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   360
	(void) strncpy(parent, datasetname, parentsize);
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   361
	cp = strrchr(parent, '@');
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   362
	if (cp != NULL) {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   363
		cp[0] = '\0';
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   364
	} else {
4543
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   365
		cp = strrchr(parent, '/');
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   366
		if (cp == NULL)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   367
			return (ENOENT);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   368
		cp[0] = '\0';
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   369
	}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   370
4543
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_destroy_perms(const char *name, 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
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   379
	if ((error = zfs_secpolicy_write_perms(name,
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   380
	    ZFS_DELEG_PERM_MOUNT, cr)) != 0)
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   381
		return (error);
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   382
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   383
	return (zfs_secpolicy_write_perms(name, ZFS_DELEG_PERM_DESTROY, cr));
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
static int
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   387
zfs_secpolicy_destroy(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_destroy_perms(zc->zc_name, cr));
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   390
}
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
 * Must have sys_config privilege to check the iscsi permission
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   394
 */
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   395
/* ARGSUSED */
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   396
static int
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   397
zfs_secpolicy_iscsi(zfs_cmd_t *zc, cred_t *cr)
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   398
{
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   399
	return (secpolicy_zfs(cr));
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   400
}
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   401
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   402
int
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   403
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
   404
{
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   405
	char 	parentname[MAXNAMELEN];
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   406
	int	error;
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   407
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   408
	if ((error = zfs_secpolicy_write_perms(from,
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   409
	    ZFS_DELEG_PERM_RENAME, cr)) != 0)
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   410
		return (error);
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   411
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   412
	if ((error = zfs_secpolicy_write_perms(from,
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   413
	    ZFS_DELEG_PERM_MOUNT, cr)) != 0)
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   414
		return (error);
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   415
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   416
	if ((error = zfs_get_parent(to, parentname,
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   417
	    sizeof (parentname))) != 0)
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   418
		return (error);
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   419
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   420
	if ((error = zfs_secpolicy_write_perms(parentname,
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   421
	    ZFS_DELEG_PERM_CREATE, cr)) != 0)
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   422
		return (error);
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   423
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   424
	if ((error = zfs_secpolicy_write_perms(parentname,
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   425
	    ZFS_DELEG_PERM_MOUNT, cr)) != 0)
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   426
		return (error);
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   427
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   428
	return (error);
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   429
}
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   430
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   431
static int
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   432
zfs_secpolicy_rename(zfs_cmd_t *zc, cred_t *cr)
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   433
{
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   434
	return (zfs_secpolicy_rename_perms(zc->zc_name, zc->zc_value, cr));
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   435
}
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   436
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   437
static int
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   438
zfs_secpolicy_promote(zfs_cmd_t *zc, cred_t *cr)
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   439
{
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   440
	char 	parentname[MAXNAMELEN];
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   441
	objset_t *clone;
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   442
	int error;
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   443
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   444
	error = zfs_secpolicy_write_perms(zc->zc_name,
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   445
	    ZFS_DELEG_PERM_PROMOTE, cr);
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   446
	if (error)
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   447
		return (error);
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
	error = dmu_objset_open(zc->zc_name, DMU_OST_ANY,
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   450
	    DS_MODE_STANDARD | DS_MODE_READONLY, &clone);
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   451
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   452
	if (error == 0) {
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   453
		dsl_dataset_t *pclone = NULL;
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   454
		dsl_dir_t *dd;
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   455
		dd = clone->os->os_dsl_dataset->ds_dir;
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
		rw_enter(&dd->dd_pool->dp_config_rwlock, RW_READER);
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   458
		error = dsl_dataset_open_obj(dd->dd_pool,
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   459
		    dd->dd_phys->dd_clone_parent_obj, NULL,
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   460
		    DS_MODE_NONE, FTAG, &pclone);
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   461
		rw_exit(&dd->dd_pool->dp_config_rwlock);
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   462
		if (error) {
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   463
			dmu_objset_close(clone);
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   464
			return (error);
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   465
		}
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
		error = zfs_secpolicy_write_perms(zc->zc_name,
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   468
		    ZFS_DELEG_PERM_MOUNT, cr);
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   469
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   470
		dsl_dataset_name(pclone, parentname);
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   471
		dmu_objset_close(clone);
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   472
		dsl_dataset_close(pclone, DS_MODE_NONE, FTAG);
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   473
		if (error == 0)
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   474
			error = zfs_secpolicy_write_perms(parentname,
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   475
			    ZFS_DELEG_PERM_PROMOTE, 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
	return (error);
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   478
}
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
static int
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   481
zfs_secpolicy_receive(zfs_cmd_t *zc, cred_t *cr)
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   482
{
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   483
	int error;
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   484
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   485
	if ((error = zfs_secpolicy_write_perms(zc->zc_name,
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   486
	    ZFS_DELEG_PERM_RECEIVE, cr)) != 0)
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   487
		return (error);
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   488
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   489
	if ((error = zfs_secpolicy_write_perms(zc->zc_name,
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   490
	    ZFS_DELEG_PERM_MOUNT, cr)) != 0)
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   491
		return (error);
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   492
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   493
	return (zfs_secpolicy_write_perms(zc->zc_name,
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   494
	    ZFS_DELEG_PERM_CREATE, cr));
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
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   497
int
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   498
zfs_secpolicy_snapshot_perms(const char *name, cred_t *cr)
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
	int 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
	if ((error = zfs_secpolicy_write_perms(name,
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   503
	    ZFS_DELEG_PERM_SNAPSHOT, cr)) != 0)
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   504
		return (error);
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
	error = zfs_secpolicy_write_perms(name,
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   507
	    ZFS_DELEG_PERM_MOUNT, cr);
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
	return (error);
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   510
}
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
static int
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   513
zfs_secpolicy_snapshot(zfs_cmd_t *zc, cred_t *cr)
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   514
{
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
	return (zfs_secpolicy_snapshot_perms(zc->zc_name, cr));
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   517
}
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   518
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   519
static int
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   520
zfs_secpolicy_create(zfs_cmd_t *zc, cred_t *cr)
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   521
{
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   522
	char 	parentname[MAXNAMELEN];
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   523
	int 	error;
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   524
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   525
	if ((error = zfs_get_parent(zc->zc_name, parentname,
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   526
	    sizeof (parentname))) != 0)
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   527
		return (error);
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
	if (zc->zc_value[0] != '\0') {
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   530
		if ((error = zfs_secpolicy_write_perms(zc->zc_value,
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   531
		    ZFS_DELEG_PERM_CLONE, cr)) != 0)
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   532
			return (error);
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   533
	}
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   534
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   535
	if ((error = zfs_secpolicy_write_perms(parentname,
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   536
	    ZFS_DELEG_PERM_CREATE, cr)) != 0)
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   537
		return (error);
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   538
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   539
	error = zfs_secpolicy_write_perms(parentname,
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   540
	    ZFS_DELEG_PERM_MOUNT, cr);
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   541
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   542
	return (error);
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   543
}
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   544
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   545
static int
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   546
zfs_secpolicy_umount(zfs_cmd_t *zc, cred_t *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
	int 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
	error = secpolicy_fs_unmount(cr, NULL);
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   551
	if (error) {
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   552
		error = dsl_deleg_access(zc->zc_name, ZFS_DELEG_PERM_MOUNT, 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
	return (error);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   555
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   556
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   557
/*
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   558
 * Policy for pool operations - create/destroy pools, add vdevs, etc.  Requires
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   559
 * SYS_CONFIG privilege, which is not available in a local zone.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   560
 */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   561
/* ARGSUSED */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   562
static int
4543
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   563
zfs_secpolicy_config(zfs_cmd_t *zc, cred_t *cr)
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   564
{
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   565
	if (secpolicy_sys_config(cr, B_FALSE) != 0)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   566
		return (EPERM);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   567
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   568
	return (0);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   569
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   570
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   571
/*
4543
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   572
 * Just like zfs_secpolicy_config, except that we will check for
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   573
 * mount permission on the dataset for permission to create/remove
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   574
 * the minor nodes.
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   575
 */
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   576
static int
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   577
zfs_secpolicy_minor(zfs_cmd_t *zc, cred_t *cr)
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   578
{
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   579
	if (secpolicy_sys_config(cr, B_FALSE) != 0) {
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   580
		return (dsl_deleg_access(zc->zc_name,
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   581
		    ZFS_DELEG_PERM_MOUNT, cr));
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
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   584
	return (0);
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
/*
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
   588
 * Policy for fault injection.  Requires all privileges.
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
   589
 */
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
   590
/* ARGSUSED */
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
   591
static int
4543
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   592
zfs_secpolicy_inject(zfs_cmd_t *zc, cred_t *cr)
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
   593
{
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
   594
	return (secpolicy_zinject(cr));
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
   595
}
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
   596
4849
3a61e0a9a953 6536043 arc_byteswap_func_t and dmu_byteswap_func_t are redundant
ahrens
parents: 4808
diff changeset
   597
static int
3a61e0a9a953 6536043 arc_byteswap_func_t and dmu_byteswap_func_t are redundant
ahrens
parents: 4808
diff changeset
   598
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
   599
{
3a61e0a9a953 6536043 arc_byteswap_func_t and dmu_byteswap_func_t are redundant
ahrens
parents: 4808
diff changeset
   600
	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
   601
5094
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
   602
	if (prop == ZPROP_INVAL) {
4849
3a61e0a9a953 6536043 arc_byteswap_func_t and dmu_byteswap_func_t are redundant
ahrens
parents: 4808
diff changeset
   603
		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
   604
			return (EINVAL);
3a61e0a9a953 6536043 arc_byteswap_func_t and dmu_byteswap_func_t are redundant
ahrens
parents: 4808
diff changeset
   605
		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
   606
		    ZFS_DELEG_PERM_USERPROP, cr));
3a61e0a9a953 6536043 arc_byteswap_func_t and dmu_byteswap_func_t are redundant
ahrens
parents: 4808
diff changeset
   607
	} else {
3a61e0a9a953 6536043 arc_byteswap_func_t and dmu_byteswap_func_t are redundant
ahrens
parents: 4808
diff changeset
   608
		if (!zfs_prop_inheritable(prop))
3a61e0a9a953 6536043 arc_byteswap_func_t and dmu_byteswap_func_t are redundant
ahrens
parents: 4808
diff changeset
   609
			return (EINVAL);
3a61e0a9a953 6536043 arc_byteswap_func_t and dmu_byteswap_func_t are redundant
ahrens
parents: 4808
diff changeset
   610
		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
   611
	}
3a61e0a9a953 6536043 arc_byteswap_func_t and dmu_byteswap_func_t are redundant
ahrens
parents: 4808
diff changeset
   612
}
3a61e0a9a953 6536043 arc_byteswap_func_t and dmu_byteswap_func_t are redundant
ahrens
parents: 4808
diff changeset
   613
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
   614
/*
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   615
 * Returns the nvlist as specified by the user in the zfs_cmd_t.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   616
 */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   617
static int
5094
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
   618
get_nvlist(uint64_t nvl, uint64_t size, nvlist_t **nvp)
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   619
{
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   620
	char *packed;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   621
	int error;
5094
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
   622
	nvlist_t *list = NULL;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   623
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   624
	/*
2676
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
   625
	 * Read in and unpack the user-supplied nvlist.
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   626
	 */
5094
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
   627
	if (size == 0)
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   628
		return (EINVAL);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   629
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   630
	packed = kmem_alloc(size, KM_SLEEP);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   631
5094
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
   632
	if ((error = xcopyin((void *)(uintptr_t)nvl, packed, size)) != 0) {
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   633
		kmem_free(packed, size);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   634
		return (error);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   635
	}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   636
5094
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
   637
	if ((error = nvlist_unpack(packed, size, &list, 0)) != 0) {
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   638
		kmem_free(packed, size);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   639
		return (error);
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
	kmem_free(packed, size);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   643
5094
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
   644
	*nvp = list;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   645
	return (0);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   646
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   647
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   648
static int
2676
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
   649
put_nvlist(zfs_cmd_t *zc, nvlist_t *nvl)
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
   650
{
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
   651
	char *packed = NULL;
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
   652
	size_t size;
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
   653
	int error;
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
   654
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
   655
	VERIFY(nvlist_size(nvl, &size, NV_ENCODE_NATIVE) == 0);
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
   656
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
   657
	if (size > zc->zc_nvlist_dst_size) {
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
   658
		error = ENOMEM;
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
   659
	} else {
4611
0960c3336815 6575997 Memory corruption while running ztest
marks
parents: 4603
diff changeset
   660
		packed = kmem_alloc(size, KM_SLEEP);
2676
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
   661
		VERIFY(nvlist_pack(nvl, &packed, &size, NV_ENCODE_NATIVE,
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
   662
		    KM_SLEEP) == 0);
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
   663
		error = xcopyout(packed, (void *)(uintptr_t)zc->zc_nvlist_dst,
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
   664
		    size);
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
   665
		kmem_free(packed, size);
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
   666
	}
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
   667
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
   668
	zc->zc_nvlist_dst_size = size;
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
   669
	return (error);
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
   670
}
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
   671
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
   672
static int
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   673
zfs_ioc_pool_create(zfs_cmd_t *zc)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   674
{
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   675
	int error;
5094
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
   676
	nvlist_t *config, *props = 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
   677
	char *buf;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   678
5094
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
   679
	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
   680
	    &config))
4988
db8abd9846d4 6595467 libzfs consumers should be allowed to write their own history (or none at all)
ek110237
parents: 4849
diff changeset
   681
		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
   682
5094
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
   683
	if (zc->zc_nvlist_src_size != 0 && (error =
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
   684
	    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
   685
		nvlist_free(config);
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
   686
		return (error);
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
   687
	}
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
   688
4988
db8abd9846d4 6595467 libzfs consumers should be allowed to write their own history (or none at all)
ek110237
parents: 4849
diff changeset
   689
	buf = history_str_get(zc);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   690
5094
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
   691
	error = spa_create(zc->zc_name, config, props, buf);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   692
4988
db8abd9846d4 6595467 libzfs consumers should be allowed to write their own history (or none at all)
ek110237
parents: 4849
diff changeset
   693
	if (buf != NULL)
db8abd9846d4 6595467 libzfs consumers should be allowed to write their own history (or none at all)
ek110237
parents: 4849
diff changeset
   694
		history_str_free(buf);
5094
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
   695
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   696
	nvlist_free(config);
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 (props)
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
   699
		nvlist_free(props);
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
   700
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   701
	return (error);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   702
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   703
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   704
static int
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   705
zfs_ioc_pool_destroy(zfs_cmd_t *zc)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   706
{
4543
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   707
	int error;
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   708
	zfs_log_history(zc);
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   709
	error = spa_destroy(zc->zc_name);
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   710
	return (error);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   711
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   712
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   713
static int
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   714
zfs_ioc_pool_import(zfs_cmd_t *zc)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   715
{
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   716
	int error;
5094
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
   717
	nvlist_t *config, *props = NULL;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   718
	uint64_t guid;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   719
5094
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
   720
	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
   721
	    &config)) != 0)
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   722
		return (error);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   723
5094
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
   724
	if (zc->zc_nvlist_src_size != 0 && (error =
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
   725
	    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
   726
		nvlist_free(config);
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
   727
		return (error);
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
   728
	}
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
   729
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   730
	if (nvlist_lookup_uint64(config, ZPOOL_CONFIG_POOL_GUID, &guid) != 0 ||
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
   731
	    guid != zc->zc_guid)
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   732
		error = EINVAL;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   733
	else
5094
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
   734
		error = spa_import(zc->zc_name, config, props);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   735
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   736
	nvlist_free(config);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   737
5094
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
   738
	if (props)
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
   739
		nvlist_free(props);
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
   740
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   741
	return (error);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   742
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   743
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   744
static int
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   745
zfs_ioc_pool_export(zfs_cmd_t *zc)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   746
{
4543
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   747
	int error;
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   748
	zfs_log_history(zc);
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   749
	error = spa_export(zc->zc_name, NULL);
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   750
	return (error);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   751
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   752
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   753
static int
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   754
zfs_ioc_pool_configs(zfs_cmd_t *zc)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   755
{
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   756
	nvlist_t *configs;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   757
	int error;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   758
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   759
	if ((configs = spa_all_configs(&zc->zc_cookie)) == NULL)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   760
		return (EEXIST);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   761
2676
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
   762
	error = put_nvlist(zc, configs);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   763
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   764
	nvlist_free(configs);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   765
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   766
	return (error);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   767
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   768
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   769
static int
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   770
zfs_ioc_pool_stats(zfs_cmd_t *zc)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   771
{
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   772
	nvlist_t *config;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   773
	int error;
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
   774
	int ret = 0;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   775
2676
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
   776
	error = spa_get_stats(zc->zc_name, &config, zc->zc_value,
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
   777
	    sizeof (zc->zc_value));
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   778
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   779
	if (config != NULL) {
2676
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
   780
		ret = put_nvlist(zc, config);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   781
		nvlist_free(config);
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
   782
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
   783
		/*
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
   784
		 * The config may be present even if 'error' is non-zero.
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
   785
		 * In this case we return success, and preserve the real errno
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
   786
		 * in 'zc_cookie'.
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
   787
		 */
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
   788
		zc->zc_cookie = error;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   789
	} else {
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
   790
		ret = error;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   791
	}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   792
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
   793
	return (ret);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   794
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   795
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   796
/*
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   797
 * Try to import the given pool, returning pool stats as appropriate so that
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   798
 * user land knows which devices are available and overall pool health.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   799
 */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   800
static int
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   801
zfs_ioc_pool_tryimport(zfs_cmd_t *zc)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   802
{
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   803
	nvlist_t *tryconfig, *config;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   804
	int error;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   805
5094
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
   806
	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
   807
	    &tryconfig)) != 0)
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   808
		return (error);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   809
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   810
	config = spa_tryimport(tryconfig);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   811
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   812
	nvlist_free(tryconfig);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   813
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   814
	if (config == NULL)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   815
		return (EINVAL);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   816
2676
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
   817
	error = put_nvlist(zc, config);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   818
	nvlist_free(config);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   819
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   820
	return (error);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   821
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   822
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   823
static int
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   824
zfs_ioc_pool_scrub(zfs_cmd_t *zc)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   825
{
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   826
	spa_t *spa;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   827
	int error;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   828
2926
acfcfefbc60d PSARC 2006/288 zpool history
ek110237
parents: 2885
diff changeset
   829
	if ((error = spa_open(zc->zc_name, &spa, FTAG)) != 0)
acfcfefbc60d PSARC 2006/288 zpool history
ek110237
parents: 2885
diff changeset
   830
		return (error);
acfcfefbc60d PSARC 2006/288 zpool history
ek110237
parents: 2885
diff changeset
   831
4808
63629eaeb41a 6498144 ::kmastat could be even easier to read
ek110237
parents: 4787
diff changeset
   832
	mutex_enter(&spa_namespace_lock);
2926
acfcfefbc60d PSARC 2006/288 zpool history
ek110237
parents: 2885
diff changeset
   833
	error = spa_scrub(spa, zc->zc_cookie, B_FALSE);
4808
63629eaeb41a 6498144 ::kmastat could be even easier to read
ek110237
parents: 4787
diff changeset
   834
	mutex_exit(&spa_namespace_lock);
2926
acfcfefbc60d PSARC 2006/288 zpool history
ek110237
parents: 2885
diff changeset
   835
acfcfefbc60d PSARC 2006/288 zpool history
ek110237
parents: 2885
diff changeset
   836
	spa_close(spa, FTAG);
acfcfefbc60d PSARC 2006/288 zpool history
ek110237
parents: 2885
diff changeset
   837
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   838
	return (error);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   839
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   840
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   841
static int
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   842
zfs_ioc_pool_freeze(zfs_cmd_t *zc)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   843
{
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   844
	spa_t *spa;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   845
	int error;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   846
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   847
	error = spa_open(zc->zc_name, &spa, FTAG);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   848
	if (error == 0) {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   849
		spa_freeze(spa);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   850
		spa_close(spa, FTAG);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   851
	}
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
1760
e1ad2821c30d PSARC 2006/206 zpool upgrade
eschrock
parents: 1544
diff changeset
   856
zfs_ioc_pool_upgrade(zfs_cmd_t *zc)
e1ad2821c30d PSARC 2006/206 zpool upgrade
eschrock
parents: 1544
diff changeset
   857
{
e1ad2821c30d PSARC 2006/206 zpool upgrade
eschrock
parents: 1544
diff changeset
   858
	spa_t *spa;
e1ad2821c30d PSARC 2006/206 zpool upgrade
eschrock
parents: 1544
diff changeset
   859
	int error;
e1ad2821c30d PSARC 2006/206 zpool upgrade
eschrock
parents: 1544
diff changeset
   860
2926
acfcfefbc60d PSARC 2006/288 zpool history
ek110237
parents: 2885
diff changeset
   861
	if ((error = spa_open(zc->zc_name, &spa, FTAG)) != 0)
acfcfefbc60d PSARC 2006/288 zpool history
ek110237
parents: 2885
diff changeset
   862
		return (error);
acfcfefbc60d PSARC 2006/288 zpool history
ek110237
parents: 2885
diff changeset
   863
5118
c723b1aa9f79 6607671 Able to zpool upgrade a pool to an unknown version number
lling
parents: 5094
diff changeset
   864
	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
   865
		spa_close(spa, FTAG);
c723b1aa9f79 6607671 Able to zpool upgrade a pool to an unknown version number
lling
parents: 5094
diff changeset
   866
		return (EINVAL);
c723b1aa9f79 6607671 Able to zpool upgrade a pool to an unknown version number
lling
parents: 5094
diff changeset
   867
	}
c723b1aa9f79 6607671 Able to zpool upgrade a pool to an unknown version number
lling
parents: 5094
diff changeset
   868
5094
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
   869
	spa_upgrade(spa, zc->zc_cookie);
2926
acfcfefbc60d PSARC 2006/288 zpool history
ek110237
parents: 2885
diff changeset
   870
	spa_close(spa, FTAG);
acfcfefbc60d PSARC 2006/288 zpool history
ek110237
parents: 2885
diff changeset
   871
acfcfefbc60d PSARC 2006/288 zpool history
ek110237
parents: 2885
diff changeset
   872
	return (error);
acfcfefbc60d PSARC 2006/288 zpool history
ek110237
parents: 2885
diff changeset
   873
}
acfcfefbc60d PSARC 2006/288 zpool history
ek110237
parents: 2885
diff changeset
   874
acfcfefbc60d PSARC 2006/288 zpool history
ek110237
parents: 2885
diff changeset
   875
static int
acfcfefbc60d PSARC 2006/288 zpool history
ek110237
parents: 2885
diff changeset
   876
zfs_ioc_pool_get_history(zfs_cmd_t *zc)
acfcfefbc60d PSARC 2006/288 zpool history
ek110237
parents: 2885
diff changeset
   877
{
acfcfefbc60d PSARC 2006/288 zpool history
ek110237
parents: 2885
diff changeset
   878
	spa_t *spa;
acfcfefbc60d PSARC 2006/288 zpool history
ek110237
parents: 2885
diff changeset
   879
	char *hist_buf;
acfcfefbc60d PSARC 2006/288 zpool history
ek110237
parents: 2885
diff changeset
   880
	uint64_t size;
acfcfefbc60d PSARC 2006/288 zpool history
ek110237
parents: 2885
diff changeset
   881
	int error;
acfcfefbc60d PSARC 2006/288 zpool history
ek110237
parents: 2885
diff changeset
   882
acfcfefbc60d PSARC 2006/288 zpool history
ek110237
parents: 2885
diff changeset
   883
	if ((size = zc->zc_history_len) == 0)
acfcfefbc60d PSARC 2006/288 zpool history
ek110237
parents: 2885
diff changeset
   884
		return (EINVAL);
acfcfefbc60d PSARC 2006/288 zpool history
ek110237
parents: 2885
diff changeset
   885
acfcfefbc60d PSARC 2006/288 zpool history
ek110237
parents: 2885
diff changeset
   886
	if ((error = spa_open(zc->zc_name, &spa, FTAG)) != 0)
acfcfefbc60d PSARC 2006/288 zpool history
ek110237
parents: 2885
diff changeset
   887
		return (error);
acfcfefbc60d PSARC 2006/288 zpool history
ek110237
parents: 2885
diff changeset
   888
4577
ed36b0e652bc PSARC/2007/328 zfs upgrade
ahrens
parents: 4543
diff changeset
   889
	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
   890
		spa_close(spa, FTAG);
d56571426115 6529406 zpool history needs to bump the on-disk version
ek110237
parents: 3741
diff changeset
   891
		return (ENOTSUP);
d56571426115 6529406 zpool history needs to bump the on-disk version
ek110237
parents: 3741
diff changeset
   892
	}
d56571426115 6529406 zpool history needs to bump the on-disk version
ek110237
parents: 3741
diff changeset
   893
2926
acfcfefbc60d PSARC 2006/288 zpool history
ek110237
parents: 2885
diff changeset
   894
	hist_buf = kmem_alloc(size, KM_SLEEP);
acfcfefbc60d PSARC 2006/288 zpool history
ek110237
parents: 2885
diff changeset
   895
	if ((error = spa_history_get(spa, &zc->zc_history_offset,
acfcfefbc60d PSARC 2006/288 zpool history
ek110237
parents: 2885
diff changeset
   896
	    &zc->zc_history_len, hist_buf)) == 0) {
4543
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   897
		error = xcopyout(hist_buf,
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   898
		    (char *)(uintptr_t)zc->zc_history,
2926
acfcfefbc60d PSARC 2006/288 zpool history
ek110237
parents: 2885
diff changeset
   899
		    zc->zc_history_len);
acfcfefbc60d PSARC 2006/288 zpool history
ek110237
parents: 2885
diff changeset
   900
	}
acfcfefbc60d PSARC 2006/288 zpool history
ek110237
parents: 2885
diff changeset
   901
acfcfefbc60d PSARC 2006/288 zpool history
ek110237
parents: 2885
diff changeset
   902
	spa_close(spa, FTAG);
acfcfefbc60d PSARC 2006/288 zpool history
ek110237
parents: 2885
diff changeset
   903
	kmem_free(hist_buf, size);
acfcfefbc60d PSARC 2006/288 zpool history
ek110237
parents: 2885
diff changeset
   904
	return (error);
acfcfefbc60d PSARC 2006/288 zpool history
ek110237
parents: 2885
diff changeset
   905
}
acfcfefbc60d PSARC 2006/288 zpool history
ek110237
parents: 2885
diff changeset
   906
acfcfefbc60d PSARC 2006/288 zpool history
ek110237
parents: 2885
diff changeset
   907
static int
3444
dc160a70a50d 6410433 'zpool status -v' would be more useful with filenames
ek110237
parents: 3265
diff changeset
   908
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
   909
{
dc160a70a50d 6410433 'zpool status -v' would be more useful with filenames
ek110237
parents: 3265
diff changeset
   910
	int error;
dc160a70a50d 6410433 'zpool status -v' would be more useful with filenames
ek110237
parents: 3265
diff changeset
   911
3912
f6891a60bd72 PSARC 2007/083 ZFS bootable datasets
lling
parents: 3886
diff changeset
   912
	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
   913
		return (error);
dc160a70a50d 6410433 'zpool status -v' would be more useful with filenames
ek110237
parents: 3265
diff changeset
   914
dc160a70a50d 6410433 'zpool status -v' would be more useful with filenames
ek110237
parents: 3265
diff changeset
   915
	return (0);
dc160a70a50d 6410433 'zpool status -v' would be more useful with filenames
ek110237
parents: 3265
diff changeset
   916
}
dc160a70a50d 6410433 'zpool status -v' would be more useful with filenames
ek110237
parents: 3265
diff changeset
   917
dc160a70a50d 6410433 'zpool status -v' would be more useful with filenames
ek110237
parents: 3265
diff changeset
   918
static int
dc160a70a50d 6410433 'zpool status -v' would be more useful with filenames
ek110237
parents: 3265
diff changeset
   919
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
   920
{
dc160a70a50d 6410433 'zpool status -v' would be more useful with filenames
ek110237
parents: 3265
diff changeset
   921
	objset_t *osp;
dc160a70a50d 6410433 'zpool status -v' would be more useful with filenames
ek110237
parents: 3265
diff changeset
   922
	int error;
dc160a70a50d 6410433 'zpool status -v' would be more useful with filenames
ek110237
parents: 3265
diff changeset
   923
dc160a70a50d 6410433 'zpool status -v' would be more useful with filenames
ek110237
parents: 3265
diff changeset
   924
	if ((error = dmu_objset_open(zc->zc_name, DMU_OST_ZFS,
dc160a70a50d 6410433 'zpool status -v' would be more useful with filenames
ek110237
parents: 3265
diff changeset
   925
	    DS_MODE_NONE | DS_MODE_READONLY, &osp)) != 0)
dc160a70a50d 6410433 'zpool status -v' would be more useful with filenames
ek110237
parents: 3265
diff changeset
   926
		return (error);
dc160a70a50d 6410433 'zpool status -v' would be more useful with filenames
ek110237
parents: 3265
diff changeset
   927
dc160a70a50d 6410433 'zpool status -v' would be more useful with filenames
ek110237
parents: 3265
diff changeset
   928
	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
   929
	    sizeof (zc->zc_value));
dc160a70a50d 6410433 'zpool status -v' would be more useful with filenames
ek110237
parents: 3265
diff changeset
   930
	dmu_objset_close(osp);
dc160a70a50d 6410433 'zpool status -v' would be more useful with filenames
ek110237
parents: 3265
diff changeset
   931
dc160a70a50d 6410433 'zpool status -v' would be more useful with filenames
ek110237
parents: 3265
diff changeset
   932
	return (error);
dc160a70a50d 6410433 'zpool status -v' would be more useful with filenames
ek110237
parents: 3265
diff changeset
   933
}
dc160a70a50d 6410433 'zpool status -v' would be more useful with filenames
ek110237
parents: 3265
diff changeset
   934
dc160a70a50d 6410433 'zpool status -v' would be more useful with filenames
ek110237
parents: 3265
diff changeset
   935
static int
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   936
zfs_ioc_vdev_add(zfs_cmd_t *zc)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   937
{
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   938
	spa_t *spa;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   939
	int error;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   940
	nvlist_t *config;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   941
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   942
	error = spa_open(zc->zc_name, &spa, FTAG);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   943
	if (error != 0)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   944
		return (error);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   945
3912
f6891a60bd72 PSARC 2007/083 ZFS bootable datasets
lling
parents: 3886
diff changeset
   946
	/*
f6891a60bd72 PSARC 2007/083 ZFS bootable datasets
lling
parents: 3886
diff changeset
   947
	 * A root pool with concatenated devices is not supported.
f6891a60bd72 PSARC 2007/083 ZFS bootable datasets
lling
parents: 3886
diff changeset
   948
	 * Thus, can not add a device to a root pool with one device.
f6891a60bd72 PSARC 2007/083 ZFS bootable datasets
lling
parents: 3886
diff changeset
   949
	 */
f6891a60bd72 PSARC 2007/083 ZFS bootable datasets
lling
parents: 3886
diff changeset
   950
	if (spa->spa_root_vdev->vdev_children == 1 && spa->spa_bootfs != 0) {
f6891a60bd72 PSARC 2007/083 ZFS bootable datasets
lling
parents: 3886
diff changeset
   951
		spa_close(spa, FTAG);
f6891a60bd72 PSARC 2007/083 ZFS bootable datasets
lling
parents: 3886
diff changeset
   952
		return (EDOM);
f6891a60bd72 PSARC 2007/083 ZFS bootable datasets
lling
parents: 3886
diff changeset
   953
	}
f6891a60bd72 PSARC 2007/083 ZFS bootable datasets
lling
parents: 3886
diff changeset
   954
5094
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
   955
	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
   956
	    &config)) == 0) {
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   957
		error = spa_vdev_add(spa, config);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   958
		nvlist_free(config);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   959
	}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   960
	spa_close(spa, FTAG);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   961
	return (error);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   962
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   963
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   964
static int
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   965
zfs_ioc_vdev_remove(zfs_cmd_t *zc)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   966
{
2082
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1775
diff changeset
   967
	spa_t *spa;
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1775
diff changeset
   968
	int error;
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1775
diff changeset
   969
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1775
diff changeset
   970
	error = spa_open(zc->zc_name, &spa, FTAG);
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1775
diff changeset
   971
	if (error != 0)
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1775
diff changeset
   972
		return (error);
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1775
diff changeset
   973
	error = spa_vdev_remove(spa, zc->zc_guid, B_FALSE);
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1775
diff changeset
   974
	spa_close(spa, FTAG);
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1775
diff changeset
   975
	return (error);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   976
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   977
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   978
static int
4451
24fbf2d7a5d7 PSARC 2007/197 ZFS hotplug
eschrock
parents: 4098
diff changeset
   979
zfs_ioc_vdev_set_state(zfs_cmd_t *zc)
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   980
{
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   981
	spa_t *spa;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   982
	int error;
4451
24fbf2d7a5d7 PSARC 2007/197 ZFS hotplug
eschrock
parents: 4098
diff changeset
   983
	vdev_state_t newstate = VDEV_STATE_UNKNOWN;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   984
2926
acfcfefbc60d PSARC 2006/288 zpool history
ek110237
parents: 2885
diff changeset
   985
	if ((error = spa_open(zc->zc_name, &spa, FTAG)) != 0)
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   986
		return (error);
4451
24fbf2d7a5d7 PSARC 2007/197 ZFS hotplug
eschrock
parents: 4098
diff changeset
   987
	switch (zc->zc_cookie) {
24fbf2d7a5d7 PSARC 2007/197 ZFS hotplug
eschrock
parents: 4098
diff changeset
   988
	case VDEV_STATE_ONLINE:
24fbf2d7a5d7 PSARC 2007/197 ZFS hotplug
eschrock
parents: 4098
diff changeset
   989
		error = vdev_online(spa, zc->zc_guid, zc->zc_obj, &newstate);
24fbf2d7a5d7 PSARC 2007/197 ZFS hotplug
eschrock
parents: 4098
diff changeset
   990
		break;
24fbf2d7a5d7 PSARC 2007/197 ZFS hotplug
eschrock
parents: 4098
diff changeset
   991
24fbf2d7a5d7 PSARC 2007/197 ZFS hotplug
eschrock
parents: 4098
diff changeset
   992
	case VDEV_STATE_OFFLINE:
24fbf2d7a5d7 PSARC 2007/197 ZFS hotplug
eschrock
parents: 4098
diff changeset
   993
		error = vdev_offline(spa, zc->zc_guid, zc->zc_obj);
24fbf2d7a5d7 PSARC 2007/197 ZFS hotplug
eschrock
parents: 4098
diff changeset
   994
		break;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   995
4451
24fbf2d7a5d7 PSARC 2007/197 ZFS hotplug
eschrock
parents: 4098
diff changeset
   996
	case VDEV_STATE_FAULTED:
24fbf2d7a5d7 PSARC 2007/197 ZFS hotplug
eschrock
parents: 4098
diff changeset
   997
		error = vdev_fault(spa, zc->zc_guid);
24fbf2d7a5d7 PSARC 2007/197 ZFS hotplug
eschrock
parents: 4098
diff changeset
   998
		break;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   999
4451
24fbf2d7a5d7 PSARC 2007/197 ZFS hotplug
eschrock
parents: 4098
diff changeset
  1000
	case VDEV_STATE_DEGRADED:
24fbf2d7a5d7 PSARC 2007/197 ZFS hotplug
eschrock
parents: 4098
diff changeset
  1001
		error = vdev_degrade(spa, zc->zc_guid);
24fbf2d7a5d7 PSARC 2007/197 ZFS hotplug
eschrock
parents: 4098
diff changeset
  1002
		break;
24fbf2d7a5d7 PSARC 2007/197 ZFS hotplug
eschrock
parents: 4098
diff changeset
  1003
24fbf2d7a5d7 PSARC 2007/197 ZFS hotplug
eschrock
parents: 4098
diff changeset
  1004
	default:
24fbf2d7a5d7 PSARC 2007/197 ZFS hotplug
eschrock
parents: 4098
diff changeset
  1005
		error = EINVAL;
24fbf2d7a5d7 PSARC 2007/197 ZFS hotplug
eschrock
parents: 4098
diff changeset
  1006
	}
24fbf2d7a5d7 PSARC 2007/197 ZFS hotplug
eschrock
parents: 4098
diff changeset
  1007
	zc->zc_cookie = newstate;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1008
	spa_close(spa, FTAG);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1009
	return (error);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1010
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1011
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1012
static int
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1013
zfs_ioc_vdev_attach(zfs_cmd_t *zc)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1014
{
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1015
	spa_t *spa;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1016
	int replacing = zc->zc_cookie;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1017
	nvlist_t *config;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1018
	int error;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1019
2926
acfcfefbc60d PSARC 2006/288 zpool history
ek110237
parents: 2885
diff changeset
  1020
	if ((error = spa_open(zc->zc_name, &spa, FTAG)) != 0)
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1021
		return (error);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1022
5094
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
  1023
	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
  1024
	    &config)) == 0) {
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
  1025
		error = spa_vdev_attach(spa, zc->zc_guid, config, replacing);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1026
		nvlist_free(config);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1027
	}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1028
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1029
	spa_close(spa, FTAG);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1030
	return (error);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1031
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1032
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1033
static int
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1034
zfs_ioc_vdev_detach(zfs_cmd_t *zc)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1035
{
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1036
	spa_t *spa;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1037
	int error;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1038
2926
acfcfefbc60d PSARC 2006/288 zpool history
ek110237
parents: 2885
diff changeset
  1039
	if ((error = spa_open(zc->zc_name, &spa, FTAG)) != 0)
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1040
		return (error);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1041
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
  1042
	error = spa_vdev_detach(spa, zc->zc_guid, B_FALSE);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1043
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1044
	spa_close(spa, FTAG);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1045
	return (error);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1046
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1047
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1048
static int
1354
81359ee1ee63 6362672 import gets confused about overlapping slices
eschrock
parents: 1133
diff changeset
  1049
zfs_ioc_vdev_setpath(zfs_cmd_t *zc)
81359ee1ee63 6362672 import gets confused about overlapping slices
eschrock
parents: 1133
diff changeset
  1050
{
81359ee1ee63 6362672 import gets confused about overlapping slices
eschrock
parents: 1133
diff changeset
  1051
	spa_t *spa;
2676
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  1052
	char *path = zc->zc_value;
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
  1053
	uint64_t guid = zc->zc_guid;
1354
81359ee1ee63 6362672 import gets confused about overlapping slices
eschrock
parents: 1133
diff changeset
  1054
	int error;
81359ee1ee63 6362672 import gets confused about overlapping slices
eschrock
parents: 1133
diff changeset
  1055
81359ee1ee63 6362672 import gets confused about overlapping slices
eschrock
parents: 1133
diff changeset
  1056
	error = spa_open(zc->zc_name, &spa, FTAG);
81359ee1ee63 6362672 import gets confused about overlapping slices
eschrock
parents: 1133
diff changeset
  1057
	if (error != 0)
81359ee1ee63 6362672 import gets confused about overlapping slices
eschrock
parents: 1133
diff changeset
  1058
		return (error);
81359ee1ee63 6362672 import gets confused about overlapping slices
eschrock
parents: 1133
diff changeset
  1059
81359ee1ee63 6362672 import gets confused about overlapping slices
eschrock
parents: 1133
diff changeset
  1060
	error = spa_vdev_setpath(spa, guid, path);
81359ee1ee63 6362672 import gets confused about overlapping slices
eschrock
parents: 1133
diff changeset
  1061
	spa_close(spa, FTAG);
81359ee1ee63 6362672 import gets confused about overlapping slices
eschrock
parents: 1133
diff changeset
  1062
	return (error);
81359ee1ee63 6362672 import gets confused about overlapping slices
eschrock
parents: 1133
diff changeset
  1063
}
81359ee1ee63 6362672 import gets confused about overlapping slices
eschrock
parents: 1133
diff changeset
  1064
81359ee1ee63 6362672 import gets confused about overlapping slices
eschrock
parents: 1133
diff changeset
  1065
static int
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1066
zfs_ioc_objset_stats(zfs_cmd_t *zc)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1067
{
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1068
	objset_t *os = NULL;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1069
	int error;
1356
e021b5e4aa0e 6377671 zfs mount -a shouldn't bother checking snapshots
eschrock
parents: 1354
diff changeset
  1070
	nvlist_t *nv;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1071
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1072
retry:
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1073
	error = dmu_objset_open(zc->zc_name, DMU_OST_ANY,
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1074
	    DS_MODE_STANDARD | DS_MODE_READONLY, &os);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1075
	if (error != 0) {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1076
		/*
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1077
		 * This is ugly: dmu_objset_open() can return EBUSY if
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1078
		 * the objset is held exclusively. Fortunately this hold is
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1079
		 * only for a short while, so we retry here.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1080
		 * This avoids user code having to handle EBUSY,
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1081
		 * for example for a "zfs list".
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1082
		 */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1083
		if (error == EBUSY) {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1084
			delay(1);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1085
			goto retry;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1086
		}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1087
		return (error);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1088
	}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1089
2885
c0259887ebbc 6460059 zfs destroy <snapshot> leaves behind kruft
ahrens
parents: 2856
diff changeset
  1090
	dmu_objset_fast_stat(os, &zc->zc_objset_stats);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1091
2856
6f4d5ee1906a 6463348 ZFS code could be more portable
nd150628
parents: 2717
diff changeset
  1092
	if (zc->zc_nvlist_dst != 0 &&
1356
e021b5e4aa0e 6377671 zfs mount -a shouldn't bother checking snapshots
eschrock
parents: 1354
diff changeset
  1093
	    (error = dsl_prop_get_all(os, &nv)) == 0) {
2885
c0259887ebbc 6460059 zfs destroy <snapshot> leaves behind kruft
ahrens
parents: 2856
diff changeset
  1094
		dmu_objset_stats(os, nv);
3087
62df4acfd5cb 6468748 assertion failure in dnode_sync
ahrens
parents: 2926
diff changeset
  1095
		/*
4577
ed36b0e652bc PSARC/2007/328 zfs upgrade
ahrens
parents: 4543
diff changeset
  1096
		 * NB: {zpl,zvol}_get_stats() will read the objset contents,
3087
62df4acfd5cb 6468748 assertion failure in dnode_sync
ahrens
parents: 2926
diff changeset
  1097
		 * which we aren't supposed to do with a
62df4acfd5cb 6468748 assertion failure in dnode_sync
ahrens
parents: 2926
diff changeset
  1098
		 * DS_MODE_STANDARD open, because it could be
62df4acfd5cb 6468748 assertion failure in dnode_sync
ahrens
parents: 2926
diff changeset
  1099
		 * inconsistent.  So this is a bit of a workaround...
62df4acfd5cb 6468748 assertion failure in dnode_sync
ahrens
parents: 2926
diff changeset
  1100
		 */
4577
ed36b0e652bc PSARC/2007/328 zfs upgrade
ahrens
parents: 4543
diff changeset
  1101
		if (!zc->zc_objset_stats.dds_inconsistent) {
ed36b0e652bc PSARC/2007/328 zfs upgrade
ahrens
parents: 4543
diff changeset
  1102
			if (dmu_objset_type(os) == DMU_OST_ZVOL)
ed36b0e652bc PSARC/2007/328 zfs upgrade
ahrens
parents: 4543
diff changeset
  1103
				VERIFY(zvol_get_stats(os, nv) == 0);
ed36b0e652bc PSARC/2007/328 zfs upgrade
ahrens
parents: 4543
diff changeset
  1104
			else if (dmu_objset_type(os) == DMU_OST_ZFS)
ed36b0e652bc PSARC/2007/328 zfs upgrade
ahrens
parents: 4543
diff changeset
  1105
				(void) zfs_get_stats(os, nv);
ed36b0e652bc PSARC/2007/328 zfs upgrade
ahrens
parents: 4543
diff changeset
  1106
		}
2676
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  1107
		error = put_nvlist(zc, nv);
1356
e021b5e4aa0e 6377671 zfs mount -a shouldn't bother checking snapshots
eschrock
parents: 1354
diff changeset
  1108
		nvlist_free(nv);
e021b5e4aa0e 6377671 zfs mount -a shouldn't bother checking snapshots
eschrock
parents: 1354
diff changeset
  1109
	}
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1110
2676
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  1111
	spa_altroot(dmu_objset_spa(os), zc->zc_value, sizeof (zc->zc_value));
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
  1112
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1113
	dmu_objset_close(os);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1114
	return (error);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1115
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1116
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1117
static int
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1118
zfs_ioc_dataset_list_next(zfs_cmd_t *zc)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1119
{
885
d925b21dba78 6347493 tar of 25K empty directory entries in ZFS takes 30+ seconds ...
ahrens
parents: 849
diff changeset
  1120
	objset_t *os;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1121
	int error;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1122
	char *p;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1123
885
d925b21dba78 6347493 tar of 25K empty directory entries in ZFS takes 30+ seconds ...
ahrens
parents: 849
diff changeset
  1124
retry:
d925b21dba78 6347493 tar of 25K empty directory entries in ZFS takes 30+ seconds ...
ahrens
parents: 849
diff changeset
  1125
	error = dmu_objset_open(zc->zc_name, DMU_OST_ANY,
d925b21dba78 6347493 tar of 25K empty directory entries in ZFS takes 30+ seconds ...
ahrens
parents: 849
diff changeset
  1126
	    DS_MODE_STANDARD | DS_MODE_READONLY, &os);
d925b21dba78 6347493 tar of 25K empty directory entries in ZFS takes 30+ seconds ...
ahrens
parents: 849
diff changeset
  1127
	if (error != 0) {
d925b21dba78 6347493 tar of 25K empty directory entries in ZFS takes 30+ seconds ...
ahrens
parents: 849
diff changeset
  1128
		/*
d925b21dba78 6347493 tar of 25K empty directory entries in ZFS takes 30+ seconds ...
ahrens
parents: 849
diff changeset
  1129
		 * This is ugly: dmu_objset_open() can return EBUSY if
d925b21dba78 6347493 tar of 25K empty directory entries in ZFS takes 30+ seconds ...
ahrens
parents: 849
diff changeset
  1130
		 * the objset is held exclusively. Fortunately this hold is
d925b21dba78 6347493 tar of 25K empty directory entries in ZFS takes 30+ seconds ...
ahrens
parents: 849
diff changeset
  1131
		 * only for a short while, so we retry here.
d925b21dba78 6347493 tar of 25K empty directory entries in ZFS takes 30+ seconds ...
ahrens
parents: 849
diff changeset
  1132
		 * This avoids user code having to handle EBUSY,
d925b21dba78 6347493 tar of 25K empty directory entries in ZFS takes 30+ seconds ...
ahrens
parents: 849
diff changeset
  1133
		 * for example for a "zfs list".
d925b21dba78 6347493 tar of 25K empty directory entries in ZFS takes 30+ seconds ...
ahrens
parents: 849
diff changeset
  1134
		 */
d925b21dba78 6347493 tar of 25K empty directory entries in ZFS takes 30+ seconds ...
ahrens
parents: 849
diff changeset
  1135
		if (error == EBUSY) {
d925b21dba78 6347493 tar of 25K empty directory entries in ZFS takes 30+ seconds ...
ahrens
parents: 849
diff changeset
  1136
			delay(1);
d925b21dba78 6347493 tar of 25K empty directory entries in ZFS takes 30+ seconds ...
ahrens
parents: 849
diff changeset
  1137
			goto retry;
d925b21dba78 6347493 tar of 25K empty directory entries in ZFS takes 30+ seconds ...
ahrens
parents: 849
diff changeset
  1138
		}
d925b21dba78 6347493 tar of 25K empty directory entries in ZFS takes 30+ seconds ...
ahrens
parents: 849
diff changeset
  1139
		if (error == ENOENT)
d925b21dba78 6347493 tar of 25K empty directory entries in ZFS takes 30+ seconds ...
ahrens
parents: 849
diff changeset
  1140
			error = ESRCH;
d925b21dba78 6347493 tar of 25K empty directory entries in ZFS takes 30+ seconds ...
ahrens
parents: 849
diff changeset
  1141
		return (error);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1142
	}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1143
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1144
	p = strrchr(zc->zc_name, '/');
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1145
	if (p == NULL || p[1] != '\0')
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1146
		(void) strlcat(zc->zc_name, "/", sizeof (zc->zc_name));
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1147
	p = zc->zc_name + strlen(zc->zc_name);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1148
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1149
	do {
885
d925b21dba78 6347493 tar of 25K empty directory entries in ZFS takes 30+ seconds ...
ahrens
parents: 849
diff changeset
  1150
		error = dmu_dir_list_next(os,
d925b21dba78 6347493 tar of 25K empty directory entries in ZFS takes 30+ seconds ...
ahrens
parents: 849
diff changeset
  1151
		    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
  1152
		    NULL, &zc->zc_cookie);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1153
		if (error == ENOENT)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1154
			error = ESRCH;
885
d925b21dba78 6347493 tar of 25K empty directory entries in ZFS takes 30+ seconds ...
ahrens
parents: 849
diff changeset
  1155
	} while (error == 0 && !INGLOBALZONE(curproc) &&
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1156
	    !zone_dataset_visible(zc->zc_name, NULL));
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1157
885
d925b21dba78 6347493 tar of 25K empty directory entries in ZFS takes 30+ seconds ...
ahrens
parents: 849
diff changeset
  1158
	/*
d925b21dba78 6347493 tar of 25K empty directory entries in ZFS takes 30+ seconds ...
ahrens
parents: 849
diff changeset
  1159
	 * 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
  1160
	 * 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
  1161
	 */
d925b21dba78 6347493 tar of 25K empty directory entries in ZFS takes 30+ seconds ...
ahrens
parents: 849
diff changeset
  1162
	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
  1163
		error = zfs_ioc_objset_stats(zc); /* fill in the stats */
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1164
885
d925b21dba78 6347493 tar of 25K empty directory entries in ZFS takes 30+ seconds ...
ahrens
parents: 849
diff changeset
  1165
	dmu_objset_close(os);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1166
	return (error);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1167
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1168
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1169
static int
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1170
zfs_ioc_snapshot_list_next(zfs_cmd_t *zc)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1171
{
885
d925b21dba78 6347493 tar of 25K empty directory entries in ZFS takes 30+ seconds ...
ahrens
parents: 849
diff changeset
  1172
	objset_t *os;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1173
	int error;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1174
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1175
retry:
885
d925b21dba78 6347493 tar of 25K empty directory entries in ZFS takes 30+ seconds ...
ahrens
parents: 849
diff changeset
  1176
	error = dmu_objset_open(zc->zc_name, DMU_OST_ANY,
d925b21dba78 6347493 tar of 25K empty directory entries in ZFS takes 30+ seconds ...
ahrens
parents: 849
diff changeset
  1177
	    DS_MODE_STANDARD | DS_MODE_READONLY, &os);
d925b21dba78 6347493 tar of 25K empty directory entries in ZFS takes 30+ seconds ...
ahrens
parents: 849
diff changeset
  1178
	if (error != 0) {
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1179
		/*
885
d925b21dba78 6347493 tar of 25K empty directory entries in ZFS takes 30+ seconds ...
ahrens
parents: 849
diff changeset
  1180
		 * This is ugly: dmu_objset_open() can return EBUSY if
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1181
		 * the objset is held exclusively. Fortunately this hold is
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1182
		 * only for a short while, so we retry here.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1183
		 * This avoids user code having to handle EBUSY,
885
d925b21dba78 6347493 tar of 25K empty directory entries in ZFS takes 30+ seconds ...
ahrens
parents: 849
diff changeset
  1184
		 * for example for a "zfs list".
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1185
		 */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1186
		if (error == EBUSY) {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1187
			delay(1);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1188
			goto retry;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1189
		}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1190
		if (error == ENOENT)
885
d925b21dba78 6347493 tar of 25K empty directory entries in ZFS takes 30+ seconds ...
ahrens
parents: 849
diff changeset
  1191
			error = ESRCH;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1192
		return (error);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1193
	}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1194
1003
ce99098d6a9b 6350417 long name will cause rename a dataset panic
lling
parents: 885
diff changeset
  1195
	/*
ce99098d6a9b 6350417 long name will cause rename a dataset panic
lling
parents: 885
diff changeset
  1196
	 * 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
  1197
	 * so exit immediately.
ce99098d6a9b 6350417 long name will cause rename a dataset panic
lling
parents: 885
diff changeset
  1198
	 */
ce99098d6a9b 6350417 long name will cause rename a dataset panic
lling
parents: 885
diff changeset
  1199
	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
  1200
		dmu_objset_close(os);
1003
ce99098d6a9b 6350417 long name will cause rename a dataset panic
lling
parents: 885
diff changeset
  1201
		return (ESRCH);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1202
	}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1203
885
d925b21dba78 6347493 tar of 25K empty directory entries in ZFS takes 30+ seconds ...
ahrens
parents: 849
diff changeset
  1204
	error = dmu_snapshot_list_next(os,
d925b21dba78 6347493 tar of 25K empty directory entries in ZFS takes 30+ seconds ...
ahrens
parents: 849
diff changeset
  1205
	    sizeof (zc->zc_name) - strlen(zc->zc_name),
d925b21dba78 6347493 tar of 25K empty directory entries in ZFS takes 30+ seconds ...
ahrens
parents: 849
diff changeset
  1206
	    zc->zc_name + strlen(zc->zc_name), NULL, &zc->zc_cookie);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1207
	if (error == ENOENT)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1208
		error = ESRCH;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1209
885
d925b21dba78 6347493 tar of 25K empty directory entries in ZFS takes 30+ seconds ...
ahrens
parents: 849
diff changeset
  1210
	if (error == 0)
d925b21dba78 6347493 tar of 25K empty directory entries in ZFS takes 30+ seconds ...
ahrens
parents: 849
diff changeset
  1211
		error = zfs_ioc_objset_stats(zc); /* fill in the stats */
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1212
885
d925b21dba78 6347493 tar of 25K empty directory entries in ZFS takes 30+ seconds ...
ahrens
parents: 849
diff changeset
  1213
	dmu_objset_close(os);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1214
	return (error);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1215
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1216
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1217
static int
4787
602d3f97842c 6393351 unique_* could be improved
ahrens
parents: 4720
diff changeset
  1218
zfs_set_prop_nvlist(const char *name, nvlist_t *nvl)
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1219
{
2676
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  1220
	nvpair_t *elem;
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  1221
	int error;
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  1222
	uint64_t intval;
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  1223
	char *strval;
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  1224
4543
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  1225
	/*
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  1226
	 * First validate permission to set all of the properties
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  1227
	 */
2676
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  1228
	elem = NULL;
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  1229
	while ((elem = nvlist_next_nvpair(nvl, elem)) != NULL) {
4670
002728040e28 6580745 "zfs inherit" can be executed by ordinary user
ahrens
parents: 4611
diff changeset
  1230
		const char *propname = nvpair_name(elem);
002728040e28 6580745 "zfs inherit" can be executed by ordinary user
ahrens
parents: 4611
diff changeset
  1231
		zfs_prop_t prop = zfs_name_to_prop(propname);
2676
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  1232
5094
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
  1233
		if (prop == ZPROP_INVAL) {
2676
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  1234
			/*
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  1235
			 * If this is a user-defined property, it must be a
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  1236
			 * string, and there is no further validation to do.
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  1237
			 */
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  1238
			if (!zfs_prop_user(propname) ||
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  1239
			    nvpair_type(elem) != DATA_TYPE_STRING)
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  1240
				return (EINVAL);
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  1241
4543
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  1242
			error = zfs_secpolicy_write_perms(name,
4787
602d3f97842c 6393351 unique_* could be improved
ahrens
parents: 4720
diff changeset
  1243
			    ZFS_DELEG_PERM_USERPROP, CRED());
4670
002728040e28 6580745 "zfs inherit" can be executed by ordinary user
ahrens
parents: 4611
diff changeset
  1244
			if (error)
002728040e28 6580745 "zfs inherit" can be executed by ordinary user
ahrens
parents: 4611
diff changeset
  1245
				return (error);
4543
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  1246
			continue;
2676
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  1247
		}
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  1248
4787
602d3f97842c 6393351 unique_* could be improved
ahrens
parents: 4720
diff changeset
  1249
		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
  1250
			return (error);
2676
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  1251
4670
002728040e28 6580745 "zfs inherit" can be executed by ordinary user
ahrens
parents: 4611
diff changeset
  1252
		/*
002728040e28 6580745 "zfs inherit" can be executed by ordinary user
ahrens
parents: 4611
diff changeset
  1253
		 * 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
  1254
		 */
002728040e28 6580745 "zfs inherit" can be executed by ordinary user
ahrens
parents: 4611
diff changeset
  1255
		switch (prop) {
3886
3291401d66a6 6536602 add zlib compression support and upgrade to version 1.2.3
ahl
parents: 3863
diff changeset
  1256
		case ZFS_PROP_COMPRESSION:
3291401d66a6 6536602 add zlib compression support and upgrade to version 1.2.3
ahl
parents: 3863
diff changeset
  1257
			/*
3291401d66a6 6536602 add zlib compression support and upgrade to version 1.2.3
ahl
parents: 3863
diff changeset
  1258
			 * 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
  1259
			 * 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
  1260
			 * we'll catch them later.
3291401d66a6 6536602 add zlib compression support and upgrade to version 1.2.3
ahl
parents: 3863
diff changeset
  1261
			 */
3291401d66a6 6536602 add zlib compression support and upgrade to version 1.2.3
ahl
parents: 3863
diff changeset
  1262
			if (nvpair_type(elem) == DATA_TYPE_UINT64 &&
3291401d66a6 6536602 add zlib compression support and upgrade to version 1.2.3
ahl
parents: 3863
diff changeset
  1263
			    nvpair_value_uint64(elem, &intval) == 0 &&
3291401d66a6 6536602 add zlib compression support and upgrade to version 1.2.3
ahl
parents: 3863
diff changeset
  1264
			    intval >= ZIO_COMPRESS_GZIP_1 &&
3291401d66a6 6536602 add zlib compression support and upgrade to version 1.2.3
ahl
parents: 3863
diff changeset
  1265
			    intval <= ZIO_COMPRESS_GZIP_9) {
4543
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  1266
				spa_t *spa;
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  1267
4603
c7840c367d00 6494569 zfs recv -d pool/<doesn't exist> core dumps for top-level filesystem backups
ahrens
parents: 4577
diff changeset
  1268
				if (spa_open(name, &spa, FTAG) == 0) {
3886
3291401d66a6 6536602 add zlib compression support and upgrade to version 1.2.3
ahl
parents: 3863
diff changeset
  1269
					if (spa_version(spa) <
4577
ed36b0e652bc PSARC/2007/328 zfs upgrade
ahrens
parents: 4543
diff changeset
  1270
					    SPA_VERSION_GZIP_COMPRESSION) {
3886
3291401d66a6 6536602 add zlib compression support and upgrade to version 1.2.3
ahl
parents: 3863
diff changeset
  1271
						spa_close(spa, FTAG);
3291401d66a6 6536602 add zlib compression support and upgrade to version 1.2.3
ahl
parents: 3863
diff changeset
  1272
						return (ENOTSUP);
3291401d66a6 6536602 add zlib compression support and upgrade to version 1.2.3
ahl
parents: 3863
diff changeset
  1273
					}
3291401d66a6 6536602 add zlib compression support and upgrade to version 1.2.3
ahl
parents: 3863
diff changeset
  1274
3291401d66a6 6536602 add zlib compression support and upgrade to version 1.2.3
ahl
parents: 3863
diff changeset
  1275
					spa_close(spa, FTAG);
3291401d66a6 6536602 add zlib compression support and upgrade to version 1.2.3
ahl
parents: 3863
diff changeset
  1276
				}
3291401d66a6 6536602 add zlib compression support and upgrade to version 1.2.3
ahl
parents: 3863
diff changeset
  1277
			}
3291401d66a6 6536602 add zlib compression support and upgrade to version 1.2.3
ahl
parents: 3863
diff changeset
  1278
			break;
4603
c7840c367d00 6494569 zfs recv -d pool/<doesn't exist> core dumps for top-level filesystem backups
ahrens
parents: 4577
diff changeset
  1279
c7840c367d00 6494569 zfs recv -d pool/<doesn't exist> core dumps for top-level filesystem backups
ahrens
parents: 4577
diff changeset
  1280
		case ZFS_PROP_COPIES:
c7840c367d00 6494569 zfs recv -d pool/<doesn't exist> core dumps for top-level filesystem backups
ahrens
parents: 4577
diff changeset
  1281
		{
c7840c367d00 6494569 zfs recv -d pool/<doesn't exist> core dumps for top-level filesystem backups
ahrens
parents: 4577
diff changeset
  1282
			spa_t *spa;
c7840c367d00 6494569 zfs recv -d pool/<doesn't exist> core dumps for top-level filesystem backups
ahrens
parents: 4577
diff changeset
  1283
c7840c367d00 6494569 zfs recv -d pool/<doesn't exist> core dumps for top-level filesystem backups
ahrens
parents: 4577
diff changeset
  1284
			if (spa_open(name, &spa, FTAG) == 0) {
c7840c367d00 6494569 zfs recv -d pool/<doesn't exist> core dumps for top-level filesystem backups
ahrens
parents: 4577
diff changeset
  1285
				if (spa_version(spa) <
c7840c367d00 6494569 zfs recv -d pool/<doesn't exist> core dumps for top-level filesystem backups
ahrens
parents: 4577
diff changeset
  1286
				    SPA_VERSION_DITTO_BLOCKS) {
c7840c367d00 6494569 zfs recv -d pool/<doesn't exist> core dumps for top-level filesystem backups
ahrens
parents: 4577
diff changeset
  1287
					spa_close(spa, FTAG);
c7840c367d00 6494569 zfs recv -d pool/<doesn't exist> core dumps for top-level filesystem backups
ahrens
parents: 4577
diff changeset
  1288
					return (ENOTSUP);
c7840c367d00 6494569 zfs recv -d pool/<doesn't exist> core dumps for top-level filesystem backups
ahrens
parents: 4577
diff changeset
  1289
				}
c7840c367d00 6494569 zfs recv -d pool/<doesn't exist> core dumps for top-level filesystem backups
ahrens
parents: 4577
diff changeset
  1290
				spa_close(spa, FTAG);
c7840c367d00 6494569 zfs recv -d pool/<doesn't exist> core dumps for top-level filesystem backups
ahrens
parents: 4577
diff changeset
  1291
			}
c7840c367d00 6494569 zfs recv -d pool/<doesn't exist> core dumps for top-level filesystem backups
ahrens
parents: 4577
diff changeset
  1292
			break;
c7840c367d00 6494569 zfs recv -d pool/<doesn't exist> core dumps for top-level filesystem backups
ahrens
parents: 4577
diff changeset
  1293
		}
2676
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  1294
		}
4543
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  1295
	}
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  1296
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  1297
	elem = NULL;
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  1298
	while ((elem = nvlist_next_nvpair(nvl, elem)) != NULL) {
4670
002728040e28 6580745 "zfs inherit" can be executed by ordinary user
ahrens
parents: 4611
diff changeset
  1299
		const char *propname = nvpair_name(elem);
002728040e28 6580745 "zfs inherit" can be executed by ordinary user
ahrens
parents: 4611
diff changeset
  1300
		zfs_prop_t prop = zfs_name_to_prop(propname);
4543
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  1301
5094
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
  1302
		if (prop == ZPROP_INVAL) {
4543
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  1303
			VERIFY(nvpair_value_string(elem, &strval) == 0);
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  1304
			error = dsl_prop_set(name, propname, 1,
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  1305
			    strlen(strval) + 1, strval);
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  1306
			if (error == 0)
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  1307
				continue;
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  1308
			else
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  1309
				return (error);
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  1310
		}
2676
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  1311
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  1312
		switch (prop) {
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  1313
		case ZFS_PROP_QUOTA:
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  1314
			if ((error = nvpair_value_uint64(elem, &intval)) != 0 ||
4577
ed36b0e652bc PSARC/2007/328 zfs upgrade
ahrens
parents: 4543
diff changeset
  1315
			    (error = dsl_dir_set_quota(name, intval)) != 0)
2676
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  1316
				return (error);
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  1317
			break;
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  1318
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  1319
		case ZFS_PROP_RESERVATION:
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  1320
			if ((error = nvpair_value_uint64(elem, &intval)) != 0 ||
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  1321
			    (error = dsl_dir_set_reservation(name,
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  1322
			    intval)) != 0)
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  1323
				return (error);
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  1324
			break;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1325
2676
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  1326
		case ZFS_PROP_VOLSIZE:
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  1327
			if ((error = nvpair_value_uint64(elem, &intval)) != 0 ||
4787
602d3f97842c 6393351 unique_* could be improved
ahrens
parents: 4720
diff changeset
  1328
			    (error = zvol_set_volsize(name,
602d3f97842c 6393351 unique_* could be improved
ahrens
parents: 4720
diff changeset
  1329
			    ddi_driver_major(zfs_dip), intval)) != 0)
2676
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  1330
				return (error);
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  1331
			break;
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  1332
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  1333
		case ZFS_PROP_VOLBLOCKSIZE:
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  1334
			if ((error = nvpair_value_uint64(elem, &intval)) != 0 ||
4577
ed36b0e652bc PSARC/2007/328 zfs upgrade
ahrens
parents: 4543
diff changeset
  1335
			    (error = zvol_set_volblocksize(name, intval)) != 0)
ed36b0e652bc PSARC/2007/328 zfs upgrade
ahrens
parents: 4543
diff changeset
  1336
				return (error);
ed36b0e652bc PSARC/2007/328 zfs upgrade
ahrens
parents: 4543
diff changeset
  1337
			break;
ed36b0e652bc PSARC/2007/328 zfs upgrade
ahrens
parents: 4543
diff changeset
  1338
ed36b0e652bc PSARC/2007/328 zfs upgrade
ahrens
parents: 4543
diff changeset
  1339
		case ZFS_PROP_VERSION:
ed36b0e652bc PSARC/2007/328 zfs upgrade
ahrens
parents: 4543
diff changeset
  1340
			if ((error = nvpair_value_uint64(elem, &intval)) != 0 ||
ed36b0e652bc PSARC/2007/328 zfs upgrade
ahrens
parents: 4543
diff changeset
  1341
			    (error = zfs_set_version(name, intval)) != 0)
2676
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  1342
				return (error);
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  1343
			break;
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  1344
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  1345
		default:
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  1346
			if (nvpair_type(elem) == DATA_TYPE_STRING) {
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  1347
				if (zfs_prop_get_type(prop) !=
4787
602d3f97842c 6393351 unique_* could be improved
ahrens
parents: 4720
diff changeset
  1348
				    PROP_TYPE_STRING)
2676
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  1349
					return (EINVAL);
2717
ed589a32259d 6469385 zfs_set_prop_nvlist range checking is busted
eschrock
parents: 2676
diff changeset
  1350
				VERIFY(nvpair_value_string(elem, &strval) == 0);
ed589a32259d 6469385 zfs_set_prop_nvlist range checking is busted
eschrock
parents: 2676
diff changeset
  1351
				if ((error = dsl_prop_set(name,
2676
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  1352
				    nvpair_name(elem), 1, strlen(strval) + 1,
2717
ed589a32259d 6469385 zfs_set_prop_nvlist range checking is busted
eschrock
parents: 2676
diff changeset
  1353
				    strval)) != 0)
ed589a32259d 6469385 zfs_set_prop_nvlist range checking is busted
eschrock
parents: 2676
diff changeset
  1354
					return (error);
2676
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  1355
			} else if (nvpair_type(elem) == DATA_TYPE_UINT64) {
2885
c0259887ebbc 6460059 zfs destroy <snapshot> leaves behind kruft
ahrens
parents: 2856
diff changeset
  1356
				const char *unused;
c0259887ebbc 6460059 zfs destroy <snapshot> leaves behind kruft
ahrens
parents: 2856
diff changeset
  1357
2717
ed589a32259d 6469385 zfs_set_prop_nvlist range checking is busted
eschrock
parents: 2676
diff changeset
  1358
				VERIFY(nvpair_value_uint64(elem, &intval) == 0);
2676
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  1359
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  1360
				switch (zfs_prop_get_type(prop)) {
4787
602d3f97842c 6393351 unique_* could be improved
ahrens
parents: 4720
diff changeset
  1361
				case PROP_TYPE_NUMBER:
2676
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  1362
					break;
4787
602d3f97842c 6393351 unique_* could be improved
ahrens
parents: 4720
diff changeset
  1363
				case PROP_TYPE_STRING:
2717
ed589a32259d 6469385 zfs_set_prop_nvlist range checking is busted
eschrock
parents: 2676
diff changeset
  1364
					return (EINVAL);
4787
602d3f97842c 6393351 unique_* could be improved
ahrens
parents: 4720
diff changeset
  1365
				case PROP_TYPE_INDEX:
2717
ed589a32259d 6469385 zfs_set_prop_nvlist range checking is busted
eschrock
parents: 2676
diff changeset
  1366
					if (zfs_prop_index_to_string(prop,
ed589a32259d 6469385 zfs_set_prop_nvlist range checking is busted
eschrock
parents: 2676
diff changeset
  1367
					    intval, &unused) != 0)
ed589a32259d 6469385 zfs_set_prop_nvlist range checking is busted
eschrock
parents: 2676
diff changeset
  1368
						return (EINVAL);
2676
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  1369
					break;
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  1370
				default:
4577
ed36b0e652bc PSARC/2007/328 zfs upgrade
ahrens
parents: 4543
diff changeset
  1371
					cmn_err(CE_PANIC,
ed36b0e652bc PSARC/2007/328 zfs upgrade
ahrens
parents: 4543
diff changeset
  1372
					    "unknown property type");
2676
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  1373
					break;
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  1374
				}
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  1375
2717
ed589a32259d 6469385 zfs_set_prop_nvlist range checking is busted
eschrock
parents: 2676
diff changeset
  1376
				if ((error = dsl_prop_set(name, propname,
ed589a32259d 6469385 zfs_set_prop_nvlist range checking is busted
eschrock
parents: 2676
diff changeset
  1377
				    8, 1, &intval)) != 0)
ed589a32259d 6469385 zfs_set_prop_nvlist range checking is busted
eschrock
parents: 2676
diff changeset
  1378
					return (error);
2676
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  1379
			} else {
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  1380
				return (EINVAL);
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  1381
			}
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  1382
			break;
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  1383
		}
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  1384
	}
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  1385
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  1386
	return (0);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1387
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1388
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1389
static int
2676
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  1390
zfs_ioc_set_prop(zfs_cmd_t *zc)
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1391
{
2676
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  1392
	nvlist_t *nvl;
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  1393
	int error;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1394
5094
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
  1395
	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
  1396
	    &nvl)) != 0)
2676
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  1397
		return (error);
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  1398
4787
602d3f97842c 6393351 unique_* could be improved
ahrens
parents: 4720
diff changeset
  1399
	error = zfs_set_prop_nvlist(zc->zc_name, nvl);
4543
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  1400
2676
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  1401
	nvlist_free(nvl);
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  1402
	return (error);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1403
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1404
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1405
static int
4849
3a61e0a9a953 6536043 arc_byteswap_func_t and dmu_byteswap_func_t are redundant
ahrens
parents: 4808
diff changeset
  1406
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
  1407
{
3a61e0a9a953 6536043 arc_byteswap_func_t and dmu_byteswap_func_t are redundant
ahrens
parents: 4808
diff changeset
  1408
	/* 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
  1409
	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
  1410
}
3a61e0a9a953 6536043 arc_byteswap_func_t and dmu_byteswap_func_t are redundant
ahrens
parents: 4808
diff changeset
  1411
3a61e0a9a953 6536043 arc_byteswap_func_t and dmu_byteswap_func_t are redundant
ahrens
parents: 4808
diff changeset
  1412
static int
4098
0a182c2128e6 6545726 make ZFS_IOC_POOL_*_PROPS in sync with zfs_ioc_pool_props_*
lling
parents: 4007
diff changeset
  1413
zfs_ioc_pool_set_props(zfs_cmd_t *zc)
3912
f6891a60bd72 PSARC 2007/083 ZFS bootable datasets
lling
parents: 3886
diff changeset
  1414
{
5094
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
  1415
	nvlist_t *props;
3912
f6891a60bd72 PSARC 2007/083 ZFS bootable datasets
lling
parents: 3886
diff changeset
  1416
	spa_t *spa;
5094
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
  1417
	int error;
3912
f6891a60bd72 PSARC 2007/083 ZFS bootable datasets
lling
parents: 3886
diff changeset
  1418
5094
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
  1419
	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
  1420
	    &props)))
3912
f6891a60bd72 PSARC 2007/083 ZFS bootable datasets
lling
parents: 3886
diff changeset
  1421
		return (error);
f6891a60bd72 PSARC 2007/083 ZFS bootable datasets
lling
parents: 3886
diff changeset
  1422
f6891a60bd72 PSARC 2007/083 ZFS bootable datasets
lling
parents: 3886
diff changeset
  1423
	if ((error = spa_open(zc->zc_name, &spa, FTAG)) != 0) {
5094
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
  1424
		nvlist_free(props);
3912
f6891a60bd72 PSARC 2007/083 ZFS bootable datasets
lling
parents: 3886
diff changeset
  1425
		return (error);
f6891a60bd72 PSARC 2007/083 ZFS bootable datasets
lling
parents: 3886
diff changeset
  1426
	}
f6891a60bd72 PSARC 2007/083 ZFS bootable datasets
lling
parents: 3886
diff changeset
  1427
5094
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
  1428
	error = spa_prop_set(spa, props);
3912
f6891a60bd72 PSARC 2007/083 ZFS bootable datasets
lling
parents: 3886
diff changeset
  1429
5094
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
  1430
	nvlist_free(props);
3912
f6891a60bd72 PSARC 2007/083 ZFS bootable datasets
lling
parents: 3886
diff changeset
  1431
	spa_close(spa, FTAG);
f6891a60bd72 PSARC 2007/083 ZFS bootable datasets
lling
parents: 3886
diff changeset
  1432
f6891a60bd72 PSARC 2007/083 ZFS bootable datasets
lling
parents: 3886
diff changeset
  1433
	return (error);
f6891a60bd72 PSARC 2007/083 ZFS bootable datasets
lling
parents: 3886
diff changeset
  1434
}
f6891a60bd72 PSARC 2007/083 ZFS bootable datasets
lling
parents: 3886
diff changeset
  1435
f6891a60bd72 PSARC 2007/083 ZFS bootable datasets
lling
parents: 3886
diff changeset
  1436
static int
4098
0a182c2128e6 6545726 make ZFS_IOC_POOL_*_PROPS in sync with zfs_ioc_pool_props_*
lling
parents: 4007
diff changeset
  1437
zfs_ioc_pool_get_props(zfs_cmd_t *zc)
3912
f6891a60bd72 PSARC 2007/083 ZFS bootable datasets
lling
parents: 3886
diff changeset
  1438
{
f6891a60bd72 PSARC 2007/083 ZFS bootable datasets
lling
parents: 3886
diff changeset
  1439
	spa_t *spa;
f6891a60bd72 PSARC 2007/083 ZFS bootable datasets
lling
parents: 3886
diff changeset
  1440
	int error;
f6891a60bd72 PSARC 2007/083 ZFS bootable datasets
lling
parents: 3886
diff changeset
  1441
	nvlist_t *nvp = NULL;
f6891a60bd72 PSARC 2007/083 ZFS bootable datasets
lling
parents: 3886
diff changeset
  1442
f6891a60bd72 PSARC 2007/083 ZFS bootable datasets
lling
parents: 3886
diff changeset
  1443
	if ((error = spa_open(zc->zc_name, &spa, FTAG)) != 0)
f6891a60bd72 PSARC 2007/083 ZFS bootable datasets
lling
parents: 3886
diff changeset
  1444
		return (error);
f6891a60bd72 PSARC 2007/083 ZFS bootable datasets
lling
parents: 3886
diff changeset
  1445
5094
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
  1446
	error = spa_prop_get(spa, &nvp);
3912
f6891a60bd72 PSARC 2007/083 ZFS bootable datasets
lling
parents: 3886
diff changeset
  1447
f6891a60bd72 PSARC 2007/083 ZFS bootable datasets
lling
parents: 3886
diff changeset
  1448
	if (error == 0 && zc->zc_nvlist_dst != NULL)
f6891a60bd72 PSARC 2007/083 ZFS bootable datasets
lling
parents: 3886
diff changeset
  1449
		error = put_nvlist(zc, nvp);
f6891a60bd72 PSARC 2007/083 ZFS bootable datasets
lling
parents: 3886
diff changeset
  1450
	else
f6891a60bd72 PSARC 2007/083 ZFS bootable datasets
lling
parents: 3886
diff changeset
  1451
		error = EFAULT;
f6891a60bd72 PSARC 2007/083 ZFS bootable datasets
lling
parents: 3886
diff changeset
  1452
f6891a60bd72 PSARC 2007/083 ZFS bootable datasets
lling
parents: 3886
diff changeset
  1453
	spa_close(spa, FTAG);
f6891a60bd72 PSARC 2007/083 ZFS bootable datasets
lling
parents: 3886
diff changeset
  1454
f6891a60bd72 PSARC 2007/083 ZFS bootable datasets
lling
parents: 3886
diff changeset
  1455
	if (nvp)
f6891a60bd72 PSARC 2007/083 ZFS bootable datasets
lling
parents: 3886
diff changeset
  1456
		nvlist_free(nvp);
f6891a60bd72 PSARC 2007/083 ZFS bootable datasets
lling
parents: 3886
diff changeset
  1457
	return (error);
f6891a60bd72 PSARC 2007/083 ZFS bootable datasets
lling
parents: 3886
diff changeset
  1458
}
f6891a60bd72 PSARC 2007/083 ZFS bootable datasets
lling
parents: 3886
diff changeset
  1459
f6891a60bd72 PSARC 2007/083 ZFS bootable datasets
lling
parents: 3886
diff changeset
  1460
static int
4543
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  1461
zfs_ioc_iscsi_perm_check(zfs_cmd_t *zc)
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  1462
{
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  1463
	nvlist_t *nvp;
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  1464
	int error;
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  1465
	uint32_t uid;
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  1466
	uint32_t gid;
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  1467
	uint32_t *groups;
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  1468
	uint_t group_cnt;
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  1469
	cred_t	*usercred;
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  1470
5094
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
  1471
	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
  1472
	    &nvp)) != 0) {
4543
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  1473
		return (error);
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  1474
	}
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  1475
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  1476
	if ((error = nvlist_lookup_uint32(nvp,
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  1477
	    ZFS_DELEG_PERM_UID, &uid)) != 0) {
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  1478
		nvlist_free(nvp);
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  1479
		return (EPERM);
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  1480
	}
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  1481
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  1482
	if ((error = nvlist_lookup_uint32(nvp,
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  1483
	    ZFS_DELEG_PERM_GID, &gid)) != 0) {
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  1484
		nvlist_free(nvp);
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  1485
		return (EPERM);
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  1486
	}
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  1487
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  1488
	if ((error = nvlist_lookup_uint32_array(nvp, ZFS_DELEG_PERM_GROUPS,
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  1489
	    &groups, &group_cnt)) != 0) {
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  1490
		nvlist_free(nvp);
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  1491
		return (EPERM);
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  1492
	}
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  1493
	usercred = cralloc();
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  1494
	if ((crsetugid(usercred, uid, gid) != 0) ||
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  1495
	    (crsetgroups(usercred, group_cnt, (gid_t *)groups) != 0)) {
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  1496
		nvlist_free(nvp);
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  1497
		crfree(usercred);
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  1498
		return (EPERM);
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  1499
	}
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  1500
	nvlist_free(nvp);
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  1501
	error = dsl_deleg_access(zc->zc_name,
4787
602d3f97842c 6393351 unique_* could be improved
ahrens
parents: 4720
diff changeset
  1502
	    zfs_prop_to_name(ZFS_PROP_SHAREISCSI), usercred);
4543
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  1503
	crfree(usercred);
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  1504
	return (error);
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  1505
}
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  1506
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  1507
static int
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  1508
zfs_ioc_set_fsacl(zfs_cmd_t *zc)
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  1509
{
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  1510
	int error;
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  1511
	nvlist_t *fsaclnv = NULL;
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  1512
5094
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
  1513
	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
  1514
	    &fsaclnv)) != 0)
4543
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  1515
		return (error);
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  1516
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  1517
	/*
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  1518
	 * Verify nvlist is constructed correctly
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  1519
	 */
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  1520
	if ((error = zfs_deleg_verify_nvlist(fsaclnv)) != 0) {
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  1521
		nvlist_free(fsaclnv);
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  1522
		return (EINVAL);
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  1523
	}
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  1524
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  1525
	/*
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  1526
	 * If we don't have PRIV_SYS_MOUNT, then validate
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  1527
	 * that user is allowed to hand out each permission in
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  1528
	 * the nvlist(s)
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  1529
	 */
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  1530
4787
602d3f97842c 6393351 unique_* could be improved
ahrens
parents: 4720
diff changeset
  1531
	error = secpolicy_zfs(CRED());
4543
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  1532
	if (error) {
4787
602d3f97842c 6393351 unique_* could be improved
ahrens
parents: 4720
diff changeset
  1533
		if (zc->zc_perm_action == B_FALSE) {
602d3f97842c 6393351 unique_* could be improved
ahrens
parents: 4720
diff changeset
  1534
			error = dsl_deleg_can_allow(zc->zc_name,
602d3f97842c 6393351 unique_* could be improved
ahrens
parents: 4720
diff changeset
  1535
			    fsaclnv, CRED());
602d3f97842c 6393351 unique_* could be improved
ahrens
parents: 4720
diff changeset
  1536
		} else {
602d3f97842c 6393351 unique_* could be improved
ahrens
parents: 4720
diff changeset
  1537
			error = dsl_deleg_can_unallow(zc->zc_name,
602d3f97842c 6393351 unique_* could be improved
ahrens
parents: 4720
diff changeset
  1538
			    fsaclnv, CRED());
602d3f97842c 6393351 unique_* could be improved
ahrens
parents: 4720
diff changeset
  1539
		}
4543
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  1540
	}
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  1541
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  1542
	if (error == 0)
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  1543
		error = dsl_deleg_set(zc->zc_name, fsaclnv, zc->zc_perm_action);
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  1544
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  1545
	nvlist_free(fsaclnv);
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  1546
	return (error);
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  1547
}
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  1548
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  1549
static int
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  1550
zfs_ioc_get_fsacl(zfs_cmd_t *zc)
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  1551
{
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  1552
	nvlist_t *nvp;
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  1553
	int error;
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  1554
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  1555
	if ((error = dsl_deleg_get(zc->zc_name, &nvp)) == 0) {
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  1556
		error = put_nvlist(zc, nvp);
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  1557
		nvlist_free(nvp);
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  1558
	}
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  1559
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  1560
	return (error);
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  1561
}
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  1562
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  1563
static int
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1564
zfs_ioc_create_minor(zfs_cmd_t *zc)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1565
{
4787
602d3f97842c 6393351 unique_* could be improved
ahrens
parents: 4720
diff changeset
  1566
	return (zvol_create_minor(zc->zc_name, ddi_driver_major(zfs_dip)));
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1567
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1568
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1569
static int
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1570
zfs_ioc_remove_minor(zfs_cmd_t *zc)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1571
{
2676
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  1572
	return (zvol_remove_minor(zc->zc_name));
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1573
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1574
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1575
/*
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1576
 * Search the vfs list for a specified resource.  Returns a pointer to it
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1577
 * or NULL if no suitable entry is found. The caller of this routine
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1578
 * is responsible for releasing the returned vfs pointer.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1579
 */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1580
static vfs_t *
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1581
zfs_get_vfs(const char *resource)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1582
{
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1583
	struct vfs *vfsp;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1584
	struct vfs *vfs_found = NULL;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1585
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1586
	vfs_list_read_lock();
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1587
	vfsp = rootvfs;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1588
	do {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1589
		if (strcmp(refstr_value(vfsp->vfs_resource), resource) == 0) {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1590
			VFS_HOLD(vfsp);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1591
			vfs_found = vfsp;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1592
			break;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1593
		}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1594
		vfsp = vfsp->vfs_next;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1595
	} while (vfsp != rootvfs);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1596
	vfs_list_unlock();
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1597
	return (vfs_found);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1598
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1599
4543
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  1600
/* ARGSUSED */
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1601
static void
4543
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  1602
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
  1603
{
4577
ed36b0e652bc PSARC/2007/328 zfs upgrade
ahrens
parents: 4543
diff changeset
  1604
	nvlist_t *nvprops = arg;
ed36b0e652bc PSARC/2007/328 zfs upgrade
ahrens
parents: 4543
diff changeset
  1605
	uint64_t version = ZPL_VERSION;
ed36b0e652bc PSARC/2007/328 zfs upgrade
ahrens
parents: 4543
diff changeset
  1606
ed36b0e652bc PSARC/2007/328 zfs upgrade
ahrens
parents: 4543
diff changeset
  1607
	(void) nvlist_lookup_uint64(nvprops,
ed36b0e652bc PSARC/2007/328 zfs upgrade
ahrens
parents: 4543
diff changeset
  1608
	    zfs_prop_to_name(ZFS_PROP_VERSION), &version);
ed36b0e652bc PSARC/2007/328 zfs upgrade
ahrens
parents: 4543
diff changeset
  1609
ed36b0e652bc PSARC/2007/328 zfs upgrade
ahrens
parents: 4543
diff changeset
  1610
	zfs_create_fs(os, cr, version, tx);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1611
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1612
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1613
static int
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1614
zfs_ioc_create(zfs_cmd_t *zc)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1615
{
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1616
	objset_t *clone;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1617
	int error = 0;
4543
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  1618
	nvlist_t *nvprops = NULL;
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  1619
	void (*cbfunc)(objset_t *os, void *arg, cred_t *cr, dmu_tx_t *tx);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1620
	dmu_objset_type_t type = zc->zc_objset_type;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1621
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1622
	switch (type) {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1623
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1624
	case DMU_OST_ZFS:
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1625
		cbfunc = zfs_create_cb;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1626
		break;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1627
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1628
	case DMU_OST_ZVOL:
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1629
		cbfunc = zvol_create_cb;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1630
		break;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1631
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1632
	default:
2199
712a788c2dfd PSARC 2006/388 snapshot -r
ahrens
parents: 2082
diff changeset
  1633
		cbfunc = NULL;
712a788c2dfd PSARC 2006/388 snapshot -r
ahrens
parents: 2082
diff changeset
  1634
	}
712a788c2dfd PSARC 2006/388 snapshot -r
ahrens
parents: 2082
diff changeset
  1635
	if (strchr(zc->zc_name, '@'))
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1636
		return (EINVAL);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1637
2676
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  1638
	if (zc->zc_nvlist_src != NULL &&
5094
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
  1639
	    (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
  1640
	    &nvprops)) != 0)
2676
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  1641
		return (error);
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  1642
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  1643
	if (zc->zc_value[0] != '\0') {
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1644
		/*
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1645
		 * We're creating a clone of an existing snapshot.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1646
		 */
2676
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  1647
		zc->zc_value[sizeof (zc->zc_value) - 1] = '\0';
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  1648
		if (dataset_namecheck(zc->zc_value, NULL, NULL) != 0) {
4543
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  1649
			nvlist_free(nvprops);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1650
			return (EINVAL);
2676
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  1651
		}
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1652
2676
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  1653
		error = dmu_objset_open(zc->zc_value, type,
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1654
		    DS_MODE_STANDARD | DS_MODE_READONLY, &clone);
2676
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  1655
		if (error) {
4543
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  1656
			nvlist_free(nvprops);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1657
			return (error);
2676
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  1658
		}
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1659
		error = dmu_objset_create(zc->zc_name, type, clone, NULL, NULL);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1660
		dmu_objset_close(clone);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1661
	} else {
2676
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  1662
		if (cbfunc == NULL) {
4543
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  1663
			nvlist_free(nvprops);
2199
712a788c2dfd PSARC 2006/388 snapshot -r
ahrens
parents: 2082
diff changeset
  1664
			return (EINVAL);
2676
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  1665
		}
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  1666
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1667
		if (type == DMU_OST_ZVOL) {
2676
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  1668
			uint64_t volsize, volblocksize;
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  1669
4543
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  1670
			if (nvprops == NULL ||
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  1671
			    nvlist_lookup_uint64(nvprops,
2676
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  1672
			    zfs_prop_to_name(ZFS_PROP_VOLSIZE),
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  1673
			    &volsize) != 0) {
4543
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  1674
				nvlist_free(nvprops);
2676
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  1675
				return (EINVAL);
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  1676
			}
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  1677
4543
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  1678
			if ((error = nvlist_lookup_uint64(nvprops,
2676
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  1679
			    zfs_prop_to_name(ZFS_PROP_VOLBLOCKSIZE),
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  1680
			    &volblocksize)) != 0 && error != ENOENT) {
4543
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  1681
				nvlist_free(nvprops);
2676
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  1682
				return (EINVAL);
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  1683
			}
1133
335d069294d1 6357470 vdev_raidz.c has unused RAIDZ_SINGLE define, code
eschrock
parents: 1003
diff changeset
  1684
2676
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  1685
			if (error != 0)
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  1686
				volblocksize = zfs_prop_default_numeric(
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  1687
				    ZFS_PROP_VOLBLOCKSIZE);
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  1688
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  1689
			if ((error = zvol_check_volblocksize(
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  1690
			    volblocksize)) != 0 ||
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  1691
			    (error = zvol_check_volsize(volsize,
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  1692
			    volblocksize)) != 0) {
4543
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  1693
				nvlist_free(nvprops);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1694
				return (error);
2676
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  1695
			}
4577
ed36b0e652bc PSARC/2007/328 zfs upgrade
ahrens
parents: 4543
diff changeset
  1696
		} else if (type == DMU_OST_ZFS) {
ed36b0e652bc PSARC/2007/328 zfs upgrade
ahrens
parents: 4543
diff changeset
  1697
			uint64_t version;
ed36b0e652bc PSARC/2007/328 zfs upgrade
ahrens
parents: 4543
diff changeset
  1698
ed36b0e652bc PSARC/2007/328 zfs upgrade
ahrens
parents: 4543
diff changeset
  1699
			if (0 == nvlist_lookup_uint64(nvprops,
ed36b0e652bc PSARC/2007/328 zfs upgrade
ahrens
parents: 4543
diff changeset
  1700
			    zfs_prop_to_name(ZFS_PROP_VERSION), &version) &&
ed36b0e652bc PSARC/2007/328 zfs upgrade
ahrens
parents: 4543
diff changeset
  1701
			    (version < ZPL_VERSION_INITIAL ||
ed36b0e652bc PSARC/2007/328 zfs upgrade
ahrens
parents: 4543
diff changeset
  1702
			    version > ZPL_VERSION)) {
ed36b0e652bc PSARC/2007/328 zfs upgrade
ahrens
parents: 4543
diff changeset
  1703
				nvlist_free(nvprops);
ed36b0e652bc PSARC/2007/328 zfs upgrade
ahrens
parents: 4543
diff changeset
  1704
				return (EINVAL);
ed36b0e652bc PSARC/2007/328 zfs upgrade
ahrens
parents: 4543
diff changeset
  1705
			}
2676
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  1706
		}
1133
335d069294d1 6357470 vdev_raidz.c has unused RAIDZ_SINGLE define, code
eschrock
parents: 1003
diff changeset
  1707
2676
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  1708
		error = dmu_objset_create(zc->zc_name, type, NULL, cbfunc,
4543
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  1709
		    nvprops);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1710
	}
2676
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  1711
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  1712
	/*
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  1713
	 * It would be nice to do this atomically.
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  1714
	 */
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  1715
	if (error == 0) {
4787
602d3f97842c 6393351 unique_* could be improved
ahrens
parents: 4720
diff changeset
  1716
		if ((error = zfs_set_prop_nvlist(zc->zc_name, nvprops)) != 0)
2676
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  1717
			(void) dmu_objset_destroy(zc->zc_name);
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  1718
	}
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  1719
4543
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  1720
	nvlist_free(nvprops);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1721
	return (error);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1722
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1723
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1724
static int
2199
712a788c2dfd PSARC 2006/388 snapshot -r
ahrens
parents: 2082
diff changeset
  1725
zfs_ioc_snapshot(zfs_cmd_t *zc)
712a788c2dfd PSARC 2006/388 snapshot -r
ahrens
parents: 2082
diff changeset
  1726
{
2676
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  1727
	if (snapshot_namecheck(zc->zc_value, NULL, NULL) != 0)
2199
712a788c2dfd PSARC 2006/388 snapshot -r
ahrens
parents: 2082
diff changeset
  1728
		return (EINVAL);
712a788c2dfd PSARC 2006/388 snapshot -r
ahrens
parents: 2082
diff changeset
  1729
	return (dmu_objset_snapshot(zc->zc_name,
2676
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  1730
	    zc->zc_value, zc->zc_cookie));
2199
712a788c2dfd PSARC 2006/388 snapshot -r
ahrens
parents: 2082
diff changeset
  1731
}
712a788c2dfd PSARC 2006/388 snapshot -r
ahrens
parents: 2082
diff changeset
  1732
4007
c6f5c6753018 PSARC 2007/142 zfs rename -r
mmusante
parents: 3912
diff changeset
  1733
int
2199
712a788c2dfd PSARC 2006/388 snapshot -r
ahrens
parents: 2082
diff changeset
  1734
zfs_unmount_snap(char *name, void *arg)
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1735
{
2199
712a788c2dfd PSARC 2006/388 snapshot -r
ahrens
parents: 2082
diff changeset
  1736
	char *snapname = arg;
712a788c2dfd PSARC 2006/388 snapshot -r
ahrens
parents: 2082
diff changeset
  1737
	char *cp;
2417
694d5de97348 6444346 zfs promote fails in zone
ahrens
parents: 2199
diff changeset
  1738
	vfs_t *vfsp = NULL;
2199
712a788c2dfd PSARC 2006/388 snapshot -r
ahrens
parents: 2082
diff changeset
  1739
712a788c2dfd PSARC 2006/388 snapshot -r
ahrens
parents: 2082
diff changeset
  1740
	/*
712a788c2dfd PSARC 2006/388 snapshot -r
ahrens
parents: 2082
diff changeset
  1741
	 * Snapshots (which are under .zfs control) must be unmounted
712a788c2dfd PSARC 2006/388 snapshot -r
ahrens
parents: 2082
diff changeset
  1742
	 * before they can be destroyed.
712a788c2dfd PSARC 2006/388 snapshot -r
ahrens
parents: 2082
diff changeset
  1743
	 */
712a788c2dfd PSARC 2006/388 snapshot -r
ahrens
parents: 2082
diff changeset
  1744
712a788c2dfd PSARC 2006/388 snapshot -r
ahrens
parents: 2082
diff changeset
  1745
	if (snapname) {
712a788c2dfd PSARC 2006/388 snapshot -r
ahrens
parents: 2082
diff changeset
  1746
		(void) strcat(name, "@");
712a788c2dfd PSARC 2006/388 snapshot -r
ahrens
parents: 2082
diff changeset
  1747
		(void) strcat(name, snapname);
712a788c2dfd PSARC 2006/388 snapshot -r
ahrens
parents: 2082
diff changeset
  1748
		vfsp = zfs_get_vfs(name);
712a788c2dfd PSARC 2006/388 snapshot -r
ahrens
parents: 2082
diff changeset
  1749
		cp = strchr(name, '@');
712a788c2dfd PSARC 2006/388 snapshot -r
ahrens
parents: 2082
diff changeset
  1750
		*cp = '\0';
2417
694d5de97348 6444346 zfs promote fails in zone
ahrens
parents: 2199
diff changeset
  1751
	} else if (strchr(name, '@')) {
2199
712a788c2dfd PSARC 2006/388 snapshot -r
ahrens
parents: 2082
diff changeset
  1752
		vfsp = zfs_get_vfs(name);
712a788c2dfd PSARC 2006/388 snapshot -r
ahrens
parents: 2082
diff changeset
  1753
	}
712a788c2dfd PSARC 2006/388 snapshot -r
ahrens
parents: 2082
diff changeset
  1754
712a788c2dfd PSARC 2006/388 snapshot -r
ahrens
parents: 2082
diff changeset
  1755
	if (vfsp) {
712a788c2dfd PSARC 2006/388 snapshot -r
ahrens
parents: 2082
diff changeset
  1756
		/*
712a788c2dfd PSARC 2006/388 snapshot -r
ahrens
parents: 2082
diff changeset
  1757
		 * Always force the unmount for snapshots.
712a788c2dfd PSARC 2006/388 snapshot -r
ahrens
parents: 2082
diff changeset
  1758
		 */
712a788c2dfd PSARC 2006/388 snapshot -r
ahrens
parents: 2082
diff changeset
  1759
		int flag = MS_FORCE;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1760
		int err;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1761
2199
712a788c2dfd PSARC 2006/388 snapshot -r
ahrens
parents: 2082
diff changeset
  1762
		if ((err = vn_vfswlock(vfsp->vfs_vnodecovered)) != 0) {
712a788c2dfd PSARC 2006/388 snapshot -r
ahrens
parents: 2082
diff changeset
  1763
			VFS_RELE(vfsp);
712a788c2dfd PSARC 2006/388 snapshot -r
ahrens
parents: 2082
diff changeset
  1764
			return (err);
712a788c2dfd PSARC 2006/388 snapshot -r
ahrens
parents: 2082
diff changeset
  1765
		}
712a788c2dfd PSARC 2006/388 snapshot -r
ahrens
parents: 2082
diff changeset
  1766
		VFS_RELE(vfsp);
712a788c2dfd PSARC 2006/388 snapshot -r
ahrens
parents: 2082
diff changeset
  1767
		if ((err = dounmount(vfsp, flag, kcred)) != 0)
712a788c2dfd PSARC 2006/388 snapshot -r
ahrens
parents: 2082
diff changeset
  1768
			return (err);
712a788c2dfd PSARC 2006/388 snapshot -r
ahrens
parents: 2082
diff changeset
  1769
	}
712a788c2dfd PSARC 2006/388 snapshot -r
ahrens
parents: 2082
diff changeset
  1770
	return (0);
712a788c2dfd PSARC 2006/388 snapshot -r
ahrens
parents: 2082
diff changeset
  1771
}
712a788c2dfd PSARC 2006/388 snapshot -r
ahrens
parents: 2082
diff changeset
  1772
712a788c2dfd PSARC 2006/388 snapshot -r
ahrens
parents: 2082
diff changeset
  1773
static int
712a788c2dfd PSARC 2006/388 snapshot -r
ahrens
parents: 2082
diff changeset
  1774
zfs_ioc_destroy_snaps(zfs_cmd_t *zc)
712a788c2dfd PSARC 2006/388 snapshot -r
ahrens
parents: 2082
diff changeset
  1775
{
712a788c2dfd PSARC 2006/388 snapshot -r
ahrens
parents: 2082
diff changeset
  1776
	int err;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1777
2676
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  1778
	if (snapshot_namecheck(zc->zc_value, NULL, NULL) != 0)
2199
712a788c2dfd PSARC 2006/388 snapshot -r
ahrens
parents: 2082
diff changeset
  1779
		return (EINVAL);
712a788c2dfd PSARC 2006/388 snapshot -r
ahrens
parents: 2082
diff changeset
  1780
	err = dmu_objset_find(zc->zc_name,
2676
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  1781
	    zfs_unmount_snap, zc->zc_value, DS_FIND_CHILDREN);
2199
712a788c2dfd PSARC 2006/388 snapshot -r
ahrens
parents: 2082
diff changeset
  1782
	if (err)
712a788c2dfd PSARC 2006/388 snapshot -r
ahrens
parents: 2082
diff changeset
  1783
		return (err);
2676
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  1784
	return (dmu_snapshots_destroy(zc->zc_name, zc->zc_value));
2199
712a788c2dfd PSARC 2006/388 snapshot -r
ahrens
parents: 2082
diff changeset
  1785
}
712a788c2dfd PSARC 2006/388 snapshot -r
ahrens
parents: 2082
diff changeset
  1786
712a788c2dfd PSARC 2006/388 snapshot -r
ahrens
parents: 2082
diff changeset
  1787
static int
712a788c2dfd PSARC 2006/388 snapshot -r
ahrens
parents: 2082
diff changeset
  1788
zfs_ioc_destroy(zfs_cmd_t *zc)
712a788c2dfd PSARC 2006/388 snapshot -r
ahrens
parents: 2082
diff changeset
  1789
{
712a788c2dfd PSARC 2006/388 snapshot -r
ahrens
parents: 2082
diff changeset
  1790
	if (strchr(zc->zc_name, '@') && zc->zc_objset_type == DMU_OST_ZFS) {
712a788c2dfd PSARC 2006/388 snapshot -r
ahrens
parents: 2082
diff changeset
  1791
		int err = zfs_unmount_snap(zc->zc_name, NULL);
712a788c2dfd PSARC 2006/388 snapshot -r
ahrens
parents: 2082
diff changeset
  1792
		if (err)
712a788c2dfd PSARC 2006/388 snapshot -r
ahrens
parents: 2082
diff changeset
  1793
			return (err);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1794
	}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1795
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1796
	return (dmu_objset_destroy(zc->zc_name));
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1797
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1798
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1799
static int
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1800
zfs_ioc_rollback(zfs_cmd_t *zc)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1801
{
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1802
	return (dmu_objset_rollback(zc->zc_name));
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1803
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1804
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1805
static int
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1806
zfs_ioc_rename(zfs_cmd_t *zc)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1807
{
4490
abf035049f7f PSARC 2007/199 zfs {create,clone,rename} -p
vb160487
parents: 4451
diff changeset
  1808
	boolean_t recursive = zc->zc_cookie & 1;
4007
c6f5c6753018 PSARC 2007/142 zfs rename -r
mmusante
parents: 3912
diff changeset
  1809
2676
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  1810
	zc->zc_value[sizeof (zc->zc_value) - 1] = '\0';
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  1811
	if (dataset_namecheck(zc->zc_value, NULL, NULL) != 0)
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1812
		return (EINVAL);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1813
4007
c6f5c6753018 PSARC 2007/142 zfs rename -r
mmusante
parents: 3912
diff changeset
  1814
	/*
c6f5c6753018 PSARC 2007/142 zfs rename -r
mmusante
parents: 3912
diff changeset
  1815
	 * Unmount snapshot unless we're doing a recursive rename,
c6f5c6753018 PSARC 2007/142 zfs rename -r
mmusante
parents: 3912
diff changeset
  1816
	 * in which case the dataset code figures out which snapshots
c6f5c6753018 PSARC 2007/142 zfs rename -r
mmusante
parents: 3912
diff changeset
  1817
	 * to unmount.
c6f5c6753018 PSARC 2007/142 zfs rename -r
mmusante
parents: 3912
diff changeset
  1818
	 */
c6f5c6753018 PSARC 2007/142 zfs rename -r
mmusante
parents: 3912
diff changeset
  1819
	if (!recursive && strchr(zc->zc_name, '@') != NULL &&
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1820
	    zc->zc_objset_type == DMU_OST_ZFS) {
2199
712a788c2dfd PSARC 2006/388 snapshot -r
ahrens
parents: 2082
diff changeset
  1821
		int err = zfs_unmount_snap(zc->zc_name, NULL);
712a788c2dfd PSARC 2006/388 snapshot -r
ahrens
parents: 2082
diff changeset
  1822
		if (err)
712a788c2dfd PSARC 2006/388 snapshot -r
ahrens
parents: 2082
diff changeset
  1823
			return (err);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1824
	}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1825
4007
c6f5c6753018 PSARC 2007/142 zfs rename -r
mmusante
parents: 3912
diff changeset
  1826
	return (dmu_objset_rename(zc->zc_name, zc->zc_value, recursive));
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1827
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1828
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1829
static int
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1830
zfs_ioc_recvbackup(zfs_cmd_t *zc)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1831
{
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1832
	file_t *fp;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1833
	int error, fd;
2885
c0259887ebbc 6460059 zfs destroy <snapshot> leaves behind kruft
ahrens
parents: 2856
diff changeset
  1834
	offset_t new_off;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1835
3265
967e0fca6143 6463140 zfs recv with a snapshot name that has 2 @@ in a row succeeds
ahrens
parents: 3087
diff changeset
  1836
	if (dataset_namecheck(zc->zc_value, NULL, NULL) != 0 ||
967e0fca6143 6463140 zfs recv with a snapshot name that has 2 @@ in a row succeeds
ahrens
parents: 3087
diff changeset
  1837
	    strchr(zc->zc_value, '@') == NULL)
967e0fca6143 6463140 zfs recv with a snapshot name that has 2 @@ in a row succeeds
ahrens
parents: 3087
diff changeset
  1838
		return (EINVAL);
967e0fca6143 6463140 zfs recv with a snapshot name that has 2 @@ in a row succeeds
ahrens
parents: 3087
diff changeset
  1839
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1840
	fd = zc->zc_cookie;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1841
	fp = getf(fd);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1842
	if (fp == NULL)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1843
		return (EBADF);
2676
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  1844
	error = dmu_recvbackup(zc->zc_value, &zc->zc_begin_record,
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  1845
	    &zc->zc_cookie, (boolean_t)zc->zc_guid, fp->f_vnode,
2665
7b208a92357b PSARC 2006/479 zfs receive -F
nd150628
parents: 2417
diff changeset
  1846
	    fp->f_offset);
2885
c0259887ebbc 6460059 zfs destroy <snapshot> leaves behind kruft
ahrens
parents: 2856
diff changeset
  1847
c0259887ebbc 6460059 zfs destroy <snapshot> leaves behind kruft
ahrens
parents: 2856
diff changeset
  1848
	new_off = fp->f_offset + zc->zc_cookie;
c0259887ebbc 6460059 zfs destroy <snapshot> leaves behind kruft
ahrens
parents: 2856
diff changeset
  1849
	if (VOP_SEEK(fp->f_vnode, fp->f_offset, &new_off) == 0)
c0259887ebbc 6460059 zfs destroy <snapshot> leaves behind kruft
ahrens
parents: 2856
diff changeset
  1850
		fp->f_offset = new_off;
c0259887ebbc 6460059 zfs destroy <snapshot> leaves behind kruft
ahrens
parents: 2856
diff changeset
  1851
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1852
	releasef(fd);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1853
	return (error);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1854
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1855
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1856
static int
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1857
zfs_ioc_sendbackup(zfs_cmd_t *zc)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1858
{
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1859
	objset_t *fromsnap = NULL;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1860
	objset_t *tosnap;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1861
	file_t *fp;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1862
	int error;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1863
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1864
	error = dmu_objset_open(zc->zc_name, DMU_OST_ANY,
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1865
	    DS_MODE_STANDARD | DS_MODE_READONLY, &tosnap);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1866
	if (error)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1867
		return (error);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1868
2676
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  1869
	if (zc->zc_value[0] != '\0') {
2885
c0259887ebbc 6460059 zfs destroy <snapshot> leaves behind kruft
ahrens
parents: 2856
diff changeset
  1870
		char buf[MAXPATHLEN];
c0259887ebbc 6460059 zfs destroy <snapshot> leaves behind kruft
ahrens
parents: 2856
diff changeset
  1871
		char *cp;
c0259887ebbc 6460059 zfs destroy <snapshot> leaves behind kruft
ahrens
parents: 2856
diff changeset
  1872
c0259887ebbc 6460059 zfs destroy <snapshot> leaves behind kruft
ahrens
parents: 2856
diff changeset
  1873
		(void) strncpy(buf, zc->zc_name, sizeof (buf));
c0259887ebbc 6460059 zfs destroy <snapshot> leaves behind kruft
ahrens
parents: 2856
diff changeset
  1874
		cp = strchr(buf, '@');
c0259887ebbc 6460059 zfs destroy <snapshot> leaves behind kruft
ahrens
parents: 2856
diff changeset
  1875
		if (cp)
c0259887ebbc 6460059 zfs destroy <snapshot> leaves behind kruft
ahrens
parents: 2856
diff changeset
  1876
			*(cp+1) = 0;
c0259887ebbc 6460059 zfs destroy <snapshot> leaves behind kruft
ahrens
parents: 2856
diff changeset
  1877
		(void) strncat(buf, zc->zc_value, sizeof (buf));
c0259887ebbc 6460059 zfs destroy <snapshot> leaves behind kruft
ahrens
parents: 2856
diff changeset
  1878
		error = dmu_objset_open(buf, DMU_OST_ANY,
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1879
		    DS_MODE_STANDARD | DS_MODE_READONLY, &fromsnap);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1880
		if (error) {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1881
			dmu_objset_close(tosnap);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1882
			return (error);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1883
		}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1884
	}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1885
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1886
	fp = getf(zc->zc_cookie);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1887
	if (fp == NULL) {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1888
		dmu_objset_close(tosnap);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1889
		if (fromsnap)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1890
			dmu_objset_close(fromsnap);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1891
		return (EBADF);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1892
	}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1893
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1894
	error = dmu_sendbackup(tosnap, fromsnap, fp->f_vnode);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1895
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1896
	releasef(zc->zc_cookie);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1897
	if (fromsnap)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1898
		dmu_objset_close(fromsnap);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1899
	dmu_objset_close(tosnap);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1900
	return (error);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1901
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1902
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
  1903
static int
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
  1904
zfs_ioc_inject_fault(zfs_cmd_t *zc)
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
  1905
{
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
  1906
	int id, error;
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
  1907
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
  1908
	error = zio_inject_fault(zc->zc_name, (int)zc->zc_guid, &id,
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
  1909
	    &zc->zc_inject_record);
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
  1910
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
  1911
	if (error == 0)
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
  1912
		zc->zc_guid = (uint64_t)id;
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
  1913
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
  1914
	return (error);
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
  1915
}
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
  1916
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
  1917
static int
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
  1918
zfs_ioc_clear_fault(zfs_cmd_t *zc)
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
  1919
{
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
  1920
	return (zio_clear_fault((int)zc->zc_guid));
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
  1921
}
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
  1922
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
  1923
static int
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
  1924
zfs_ioc_inject_list_next(zfs_cmd_t *zc)
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
  1925
{
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
  1926
	int id = (int)zc->zc_guid;
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
  1927
	int error;
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
  1928
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
  1929
	error = zio_inject_list_next(&id, zc->zc_name, sizeof (zc->zc_name),
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
  1930
	    &zc->zc_inject_record);
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
  1931
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
  1932
	zc->zc_guid = id;
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
  1933
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
  1934
	return (error);
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
  1935
}
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
  1936
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
  1937
static int
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
  1938
zfs_ioc_error_log(zfs_cmd_t *zc)
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
  1939
{
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
  1940
	spa_t *spa;
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
  1941
	int error;
2676
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  1942
	size_t count = (size_t)zc->zc_nvlist_dst_size;
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
  1943
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
  1944
	if ((error = spa_open(zc->zc_name, &spa, FTAG)) != 0)
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
  1945
		return (error);
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
  1946
2676
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  1947
	error = spa_get_errlog(spa, (void *)(uintptr_t)zc->zc_nvlist_dst,
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
  1948
	    &count);
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
  1949
	if (error == 0)
2676
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  1950
		zc->zc_nvlist_dst_size = count;
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
  1951
	else
2676
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  1952
		zc->zc_nvlist_dst_size = spa_get_errlog_size(spa);
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
  1953
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
  1954
	spa_close(spa, FTAG);
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
  1955
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
  1956
	return (error);
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
  1957
}
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
  1958
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
  1959
static int
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
  1960
zfs_ioc_clear(zfs_cmd_t *zc)
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
  1961
{
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
  1962
	spa_t *spa;
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
  1963
	vdev_t *vd;
4808
63629eaeb41a 6498144 ::kmastat could be even easier to read
ek110237
parents: 4787
diff changeset
  1964
	uint64_t txg;
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
  1965
	int error;
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
  1966
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
  1967
	if ((error = spa_open(zc->zc_name, &spa, FTAG)) != 0)
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
  1968
		return (error);
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
  1969
4451
24fbf2d7a5d7 PSARC 2007/197 ZFS hotplug
eschrock
parents: 4098
diff changeset
  1970
	txg = spa_vdev_enter(spa);
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
  1971
2676
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  1972
	if (zc->zc_guid == 0) {
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
  1973
		vd = NULL;
2676
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  1974
	} else if ((vd = spa_lookup_by_guid(spa, zc->zc_guid)) == NULL) {
4451
24fbf2d7a5d7 PSARC 2007/197 ZFS hotplug
eschrock
parents: 4098
diff changeset
  1975
		(void) spa_vdev_exit(spa, NULL, txg, ENODEV);
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
  1976
		spa_close(spa, FTAG);
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
  1977
		return (ENODEV);
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
  1978
	}
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
  1979
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
  1980
	vdev_clear(spa, vd);
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
  1981
4451
24fbf2d7a5d7 PSARC 2007/197 ZFS hotplug
eschrock
parents: 4098
diff changeset
  1982
	(void) spa_vdev_exit(spa, NULL, txg, 0);
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
  1983
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
  1984
	spa_close(spa, FTAG);
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
  1985
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
  1986
	return (0);
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
  1987
}
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
  1988
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
  1989
static int
2082
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1775
diff changeset
  1990
zfs_ioc_promote(zfs_cmd_t *zc)
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1775
diff changeset
  1991
{
2417
694d5de97348 6444346 zfs promote fails in zone
ahrens
parents: 2199
diff changeset
  1992
	char *cp;
694d5de97348 6444346 zfs promote fails in zone
ahrens
parents: 2199
diff changeset
  1993
694d5de97348 6444346 zfs promote fails in zone
ahrens
parents: 2199
diff changeset
  1994
	/*
694d5de97348 6444346 zfs promote fails in zone
ahrens
parents: 2199
diff changeset
  1995
	 * 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
  1996
	 * it's easier.
694d5de97348 6444346 zfs promote fails in zone
ahrens
parents: 2199
diff changeset
  1997
	 */
2676
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  1998
	cp = strchr(zc->zc_value, '@');
2417
694d5de97348 6444346 zfs promote fails in zone
ahrens
parents: 2199
diff changeset
  1999
	if (cp)
694d5de97348 6444346 zfs promote fails in zone
ahrens
parents: 2199
diff changeset
  2000
		*cp = '\0';
2676
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  2001
	(void) dmu_objset_find(zc->zc_value,
2417
694d5de97348 6444346 zfs promote fails in zone
ahrens
parents: 2199
diff changeset
  2002
	    zfs_unmount_snap, NULL, DS_FIND_SNAPSHOTS);
2082
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1775
diff changeset
  2003
	return (dsl_dataset_promote(zc->zc_name));
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1775
diff changeset
  2004
}
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1775
diff changeset
  2005
4543
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  2006
/*
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  2007
 * We don't want to have a hard dependency
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  2008
 * against some special symbols in sharefs
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  2009
 * and nfs.  Determine them if needed when
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  2010
 * the first file system is shared.
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  2011
 * Neither sharefs or nfs are unloadable modules.
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  2012
 */
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  2013
int (*zexport_fs)(void *arg);
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  2014
int (*zshare_fs)(enum sharefs_sys_op, share_t *, uint32_t);
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  2015
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  2016
int zfs_share_inited;
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  2017
ddi_modhandle_t nfs_mod;
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  2018
ddi_modhandle_t sharefs_mod;
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  2019
kmutex_t zfs_share_lock;
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  2020
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  2021
static int
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  2022
zfs_ioc_share(zfs_cmd_t *zc)
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  2023
{
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  2024
	int error;
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  2025
	int opcode;
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  2026
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  2027
	if (zfs_share_inited == 0) {
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  2028
		mutex_enter(&zfs_share_lock);
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  2029
		nfs_mod = ddi_modopen("fs/nfs", KRTLD_MODE_FIRST, &error);
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  2030
		sharefs_mod = ddi_modopen("fs/sharefs",
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  2031
		    KRTLD_MODE_FIRST, &error);
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  2032
		if (nfs_mod == NULL || sharefs_mod == NULL) {
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  2033
			mutex_exit(&zfs_share_lock);
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  2034
			return (ENOSYS);
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  2035
		}
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  2036
		if (zexport_fs == NULL && ((zexport_fs = (int (*)(void *))
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  2037
		    ddi_modsym(nfs_mod, "nfs_export", &error)) == NULL)) {
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  2038
			mutex_exit(&zfs_share_lock);
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  2039
			return (ENOSYS);
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  2040
		}
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  2041
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  2042
		if (zshare_fs == NULL && ((zshare_fs =
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  2043
		    (int (*)(enum sharefs_sys_op, share_t *, uint32_t))
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  2044
		    ddi_modsym(sharefs_mod, "sharefs_impl", &error)) == NULL)) {
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  2045
			mutex_exit(&zfs_share_lock);
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  2046
			return (ENOSYS);
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  2047
		}
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  2048
		zfs_share_inited = 1;
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  2049
		mutex_exit(&zfs_share_lock);
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  2050
	}
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  2051
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  2052
	if (error = zexport_fs((void *)(uintptr_t)zc->zc_share.z_exportdata))
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  2053
		return (error);
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  2054
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  2055
	opcode = (zc->zc_share.z_sharetype == B_TRUE) ?
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  2056
	    SHAREFS_ADD : SHAREFS_REMOVE;
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  2057
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  2058
	error = zshare_fs(opcode,
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  2059
	    (void *)(uintptr_t)zc->zc_share.z_sharedata,
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  2060
	    zc->zc_share.z_sharemax);
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  2061
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  2062
	return (error);
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  2063
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  2064
}
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  2065
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  2066
/*
4988
db8abd9846d4 6595467 libzfs consumers should be allowed to write their own history (or none at all)
ek110237
parents: 4849
diff changeset
  2067
 * 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
  2068
 * 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
  2069
 * do the logging of those commands.
4543
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  2070
 */
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2071
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
  2072
	{ zfs_ioc_pool_create, zfs_secpolicy_config, POOL_NAME, B_FALSE },
4577
ed36b0e652bc PSARC/2007/328 zfs upgrade
ahrens
parents: 4543
diff changeset
  2073
	{ zfs_ioc_pool_destroy,	zfs_secpolicy_config, POOL_NAME, B_FALSE },
ed36b0e652bc PSARC/2007/328 zfs upgrade
ahrens
parents: 4543
diff changeset
  2074
	{ zfs_ioc_pool_import, zfs_secpolicy_config, POOL_NAME, B_TRUE },
ed36b0e652bc PSARC/2007/328 zfs upgrade
ahrens
parents: 4543
diff changeset
  2075
	{ zfs_ioc_pool_export, zfs_secpolicy_config, POOL_NAME, B_FALSE },
ed36b0e652bc PSARC/2007/328 zfs upgrade
ahrens
parents: 4543
diff changeset
  2076
	{ zfs_ioc_pool_configs,	zfs_secpolicy_none, NO_NAME, B_FALSE },
ed36b0e652bc PSARC/2007/328 zfs upgrade
ahrens
parents: 4543
diff changeset
  2077
	{ zfs_ioc_pool_stats, zfs_secpolicy_read, POOL_NAME, B_FALSE },
ed36b0e652bc PSARC/2007/328 zfs upgrade
ahrens
parents: 4543
diff changeset
  2078
	{ zfs_ioc_pool_tryimport, zfs_secpolicy_config, NO_NAME, B_FALSE },
ed36b0e652bc PSARC/2007/328 zfs upgrade
ahrens
parents: 4543
diff changeset
  2079
	{ zfs_ioc_pool_scrub, zfs_secpolicy_config, POOL_NAME, B_TRUE },
ed36b0e652bc PSARC/2007/328 zfs upgrade
ahrens
parents: 4543
diff changeset
  2080
	{ zfs_ioc_pool_freeze, zfs_secpolicy_config, NO_NAME, B_FALSE },
ed36b0e652bc PSARC/2007/328 zfs upgrade
ahrens
parents: 4543
diff changeset
  2081
	{ zfs_ioc_pool_upgrade,	zfs_secpolicy_config, POOL_NAME, B_TRUE },
ed36b0e652bc PSARC/2007/328 zfs upgrade
ahrens
parents: 4543
diff changeset
  2082
	{ zfs_ioc_pool_get_history, zfs_secpolicy_config, POOL_NAME, B_FALSE },
ed36b0e652bc PSARC/2007/328 zfs upgrade
ahrens
parents: 4543
diff changeset
  2083
	{ zfs_ioc_vdev_add, zfs_secpolicy_config, POOL_NAME, B_TRUE },
ed36b0e652bc PSARC/2007/328 zfs upgrade
ahrens
parents: 4543
diff changeset
  2084
	{ zfs_ioc_vdev_remove, zfs_secpolicy_config, POOL_NAME, B_TRUE },
ed36b0e652bc PSARC/2007/328 zfs upgrade
ahrens
parents: 4543
diff changeset
  2085
	{ zfs_ioc_vdev_set_state, zfs_secpolicy_config,	POOL_NAME, B_TRUE },
ed36b0e652bc PSARC/2007/328 zfs upgrade
ahrens
parents: 4543
diff changeset
  2086
	{ zfs_ioc_vdev_attach, zfs_secpolicy_config, POOL_NAME, B_TRUE },
ed36b0e652bc PSARC/2007/328 zfs upgrade
ahrens
parents: 4543
diff changeset
  2087
	{ zfs_ioc_vdev_detach, zfs_secpolicy_config, POOL_NAME, B_TRUE },
ed36b0e652bc PSARC/2007/328 zfs upgrade
ahrens
parents: 4543
diff changeset
  2088
	{ zfs_ioc_vdev_setpath,	zfs_secpolicy_config, POOL_NAME, B_FALSE },
ed36b0e652bc PSARC/2007/328 zfs upgrade
ahrens
parents: 4543
diff changeset
  2089
	{ zfs_ioc_objset_stats,	zfs_secpolicy_read, DATASET_NAME, B_FALSE },
4543
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  2090
	{ zfs_ioc_dataset_list_next, zfs_secpolicy_read,
4577
ed36b0e652bc PSARC/2007/328 zfs upgrade
ahrens
parents: 4543
diff changeset
  2091
	    DATASET_NAME, B_FALSE },
4543
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  2092
	{ zfs_ioc_snapshot_list_next, zfs_secpolicy_read,
4577
ed36b0e652bc PSARC/2007/328 zfs upgrade
ahrens
parents: 4543
diff changeset
  2093
	    DATASET_NAME, B_FALSE },
ed36b0e652bc PSARC/2007/328 zfs upgrade
ahrens
parents: 4543
diff changeset
  2094
	{ zfs_ioc_set_prop, zfs_secpolicy_none, DATASET_NAME, B_TRUE },
ed36b0e652bc PSARC/2007/328 zfs upgrade
ahrens
parents: 4543
diff changeset
  2095
	{ zfs_ioc_create_minor,	zfs_secpolicy_minor, DATASET_NAME, B_FALSE },
ed36b0e652bc PSARC/2007/328 zfs upgrade
ahrens
parents: 4543
diff changeset
  2096
	{ zfs_ioc_remove_minor,	zfs_secpolicy_minor, DATASET_NAME, B_FALSE },
ed36b0e652bc PSARC/2007/328 zfs upgrade
ahrens
parents: 4543
diff changeset
  2097
	{ zfs_ioc_create, zfs_secpolicy_create, DATASET_NAME, B_TRUE },
ed36b0e652bc PSARC/2007/328 zfs upgrade
ahrens
parents: 4543
diff changeset
  2098
	{ zfs_ioc_destroy, zfs_secpolicy_destroy, DATASET_NAME, B_TRUE },
ed36b0e652bc PSARC/2007/328 zfs upgrade
ahrens
parents: 4543
diff changeset
  2099
	{ zfs_ioc_rollback, zfs_secpolicy_rollback, DATASET_NAME, B_TRUE },
ed36b0e652bc PSARC/2007/328 zfs upgrade
ahrens
parents: 4543
diff changeset
  2100
	{ zfs_ioc_rename, zfs_secpolicy_rename,	DATASET_NAME, B_TRUE },
ed36b0e652bc PSARC/2007/328 zfs upgrade
ahrens
parents: 4543
diff changeset
  2101
	{ zfs_ioc_recvbackup, zfs_secpolicy_receive, DATASET_NAME, B_TRUE },
ed36b0e652bc PSARC/2007/328 zfs upgrade
ahrens
parents: 4543
diff changeset
  2102
	{ zfs_ioc_sendbackup, zfs_secpolicy_send, DATASET_NAME, B_TRUE },
ed36b0e652bc PSARC/2007/328 zfs upgrade
ahrens
parents: 4543
diff changeset
  2103
	{ zfs_ioc_inject_fault,	zfs_secpolicy_inject, NO_NAME, B_FALSE },
ed36b0e652bc PSARC/2007/328 zfs upgrade
ahrens
parents: 4543
diff changeset
  2104
	{ zfs_ioc_clear_fault, zfs_secpolicy_inject, NO_NAME, B_FALSE },
ed36b0e652bc PSARC/2007/328 zfs upgrade
ahrens
parents: 4543
diff changeset
  2105
	{ zfs_ioc_inject_list_next, zfs_secpolicy_inject, NO_NAME, B_FALSE },
ed36b0e652bc PSARC/2007/328 zfs upgrade
ahrens
parents: 4543
diff changeset
  2106
	{ zfs_ioc_error_log, zfs_secpolicy_inject, POOL_NAME, B_FALSE },
ed36b0e652bc PSARC/2007/328 zfs upgrade
ahrens
parents: 4543
diff changeset
  2107
	{ zfs_ioc_clear, zfs_secpolicy_config, POOL_NAME, B_TRUE },
ed36b0e652bc PSARC/2007/328 zfs upgrade
ahrens
parents: 4543
diff changeset
  2108
	{ zfs_ioc_promote, zfs_secpolicy_promote, DATASET_NAME, B_TRUE },
ed36b0e652bc PSARC/2007/328 zfs upgrade
ahrens
parents: 4543
diff changeset
  2109
	{ zfs_ioc_destroy_snaps, zfs_secpolicy_destroy,	DATASET_NAME, B_TRUE },
ed36b0e652bc PSARC/2007/328 zfs upgrade
ahrens
parents: 4543
diff changeset
  2110
	{ zfs_ioc_snapshot, zfs_secpolicy_snapshot, DATASET_NAME, B_TRUE },
ed36b0e652bc PSARC/2007/328 zfs upgrade
ahrens
parents: 4543
diff changeset
  2111
	{ zfs_ioc_dsobj_to_dsname, zfs_secpolicy_config, POOL_NAME, B_FALSE },
ed36b0e652bc PSARC/2007/328 zfs upgrade
ahrens
parents: 4543
diff changeset
  2112
	{ zfs_ioc_obj_to_path, zfs_secpolicy_config, NO_NAME, B_FALSE },
ed36b0e652bc PSARC/2007/328 zfs upgrade
ahrens
parents: 4543
diff changeset
  2113
	{ zfs_ioc_pool_set_props, zfs_secpolicy_config,	POOL_NAME, B_TRUE },
ed36b0e652bc PSARC/2007/328 zfs upgrade
ahrens
parents: 4543
diff changeset
  2114
	{ zfs_ioc_pool_get_props, zfs_secpolicy_read, POOL_NAME, B_FALSE },
ed36b0e652bc PSARC/2007/328 zfs upgrade
ahrens
parents: 4543
diff changeset
  2115
	{ zfs_ioc_set_fsacl, zfs_secpolicy_fsacl, DATASET_NAME, B_TRUE },
ed36b0e652bc PSARC/2007/328 zfs upgrade
ahrens
parents: 4543
diff changeset
  2116
	{ zfs_ioc_get_fsacl, zfs_secpolicy_read, DATASET_NAME, B_FALSE },
4543
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  2117
	{ zfs_ioc_iscsi_perm_check, zfs_secpolicy_iscsi,
4577
ed36b0e652bc PSARC/2007/328 zfs upgrade
ahrens
parents: 4543
diff changeset
  2118
	    DATASET_NAME, B_FALSE },
4849
3a61e0a9a953 6536043 arc_byteswap_func_t and dmu_byteswap_func_t are redundant
ahrens
parents: 4808
diff changeset
  2119
	{ 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
  2120
	{ zfs_ioc_inherit_prop, zfs_secpolicy_inherit, DATASET_NAME, B_TRUE },
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2121
};
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2122
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2123
static int
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2124
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
  2125
{
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2126
	zfs_cmd_t *zc;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2127
	uint_t vec;
2199
712a788c2dfd PSARC 2006/388 snapshot -r
ahrens
parents: 2082
diff changeset
  2128
	int error, rc;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2129
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2130
	if (getminor(dev) != 0)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2131
		return (zvol_ioctl(dev, cmd, arg, flag, cr, rvalp));
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2132
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2133
	vec = cmd - ZFS_IOC;
4787
602d3f97842c 6393351 unique_* could be improved
ahrens
parents: 4720
diff changeset
  2134
	ASSERT3U(getmajor(dev), ==, ddi_driver_major(zfs_dip));
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2135
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2136
	if (vec >= sizeof (zfs_ioc_vec) / sizeof (zfs_ioc_vec[0]))
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2137
		return (EINVAL);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2138
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2139
	zc = kmem_zalloc(sizeof (zfs_cmd_t), KM_SLEEP);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2140
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2141
	error = xcopyin((void *)arg, zc, sizeof (zfs_cmd_t));
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2142
4787
602d3f97842c 6393351 unique_* could be improved
ahrens
parents: 4720
diff changeset
  2143
	if (error == 0)
4543
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  2144
		error = zfs_ioc_vec[vec].zvec_secpolicy(zc, cr);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2145
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2146
	/*
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2147
	 * Ensure that all pool/dataset names are valid before we pass down to
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2148
	 * the lower layers.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2149
	 */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2150
	if (error == 0) {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2151
		zc->zc_name[sizeof (zc->zc_name) - 1] = '\0';
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2152
		switch (zfs_ioc_vec[vec].zvec_namecheck) {
4577
ed36b0e652bc PSARC/2007/328 zfs upgrade
ahrens
parents: 4543
diff changeset
  2153
		case POOL_NAME:
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2154
			if (pool_namecheck(zc->zc_name, NULL, NULL) != 0)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2155
				error = EINVAL;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2156
			break;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2157
4577
ed36b0e652bc PSARC/2007/328 zfs upgrade
ahrens
parents: 4543
diff changeset
  2158
		case DATASET_NAME:
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2159
			if (dataset_namecheck(zc->zc_name, NULL, NULL) != 0)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2160
				error = EINVAL;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2161
			break;
2856
6f4d5ee1906a 6463348 ZFS code could be more portable
nd150628
parents: 2717
diff changeset
  2162
4577
ed36b0e652bc PSARC/2007/328 zfs upgrade
ahrens
parents: 4543
diff changeset
  2163
		case NO_NAME:
2856
6f4d5ee1906a 6463348 ZFS code could be more portable
nd150628
parents: 2717
diff changeset
  2164
			break;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2165
		}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2166
	}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2167
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2168
	if (error == 0)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2169
		error = zfs_ioc_vec[vec].zvec_func(zc);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2170
2199
712a788c2dfd PSARC 2006/388 snapshot -r
ahrens
parents: 2082
diff changeset
  2171
	rc = xcopyout(zc, (void *)arg, sizeof (zfs_cmd_t));
4543
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  2172
	if (error == 0) {
2199
712a788c2dfd PSARC 2006/388 snapshot -r
ahrens
parents: 2082
diff changeset
  2173
		error = rc;
4543
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  2174
		if (zfs_ioc_vec[vec].zvec_his_log == B_TRUE)
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  2175
			zfs_log_history(zc);
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  2176
	}
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2177
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2178
	kmem_free(zc, sizeof (zfs_cmd_t));
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2179
	return (error);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2180
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2181
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2182
static int
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2183
zfs_attach(dev_info_t *dip, ddi_attach_cmd_t cmd)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2184
{
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2185
	if (cmd != DDI_ATTACH)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2186
		return (DDI_FAILURE);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2187
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2188
	if (ddi_create_minor_node(dip, "zfs", S_IFCHR, 0,
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2189
	    DDI_PSEUDO, 0) == DDI_FAILURE)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2190
		return (DDI_FAILURE);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2191
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2192
	zfs_dip = dip;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2193
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2194
	ddi_report_dev(dip);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2195
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2196
	return (DDI_SUCCESS);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2197
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2198
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2199
static int
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2200
zfs_detach(dev_info_t *dip, ddi_detach_cmd_t cmd)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2201
{
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2202
	if (spa_busy() || zfs_busy() || zvol_busy())
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2203
		return (DDI_FAILURE);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2204
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2205
	if (cmd != DDI_DETACH)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2206
		return (DDI_FAILURE);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2207
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2208
	zfs_dip = NULL;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2209
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2210
	ddi_prop_remove_all(dip);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2211
	ddi_remove_minor_node(dip, NULL);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2212
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2213
	return (DDI_SUCCESS);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2214
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2215
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2216
/*ARGSUSED*/
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2217
static int
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2218
zfs_info(dev_info_t *dip, ddi_info_cmd_t infocmd, void *arg, void **result)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2219
{
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2220
	switch (infocmd) {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2221
	case DDI_INFO_DEVT2DEVINFO:
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2222
		*result = zfs_dip;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2223
		return (DDI_SUCCESS);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2224
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2225
	case DDI_INFO_DEVT2INSTANCE:
849
8d799fd81a9b 6345023 /dev/zfs fails to open once ZFS module is unloaded
bonwick
parents: 789
diff changeset
  2226
		*result = (void *)0;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2227
		return (DDI_SUCCESS);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2228
	}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2229
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2230
	return (DDI_FAILURE);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2231
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2232
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2233
/*
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2234
 * OK, so this is a little weird.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2235
 *
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2236
 * /dev/zfs is the control node, i.e. minor 0.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2237
 * /dev/zvol/[r]dsk/pool/dataset are the zvols, minor > 0.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2238
 *
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2239
 * /dev/zfs has basically nothing to do except serve up ioctls,
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2240
 * so most of the standard driver entry points are in zvol.c.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2241
 */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2242
static struct cb_ops zfs_cb_ops = {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2243
	zvol_open,	/* open */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2244
	zvol_close,	/* close */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2245
	zvol_strategy,	/* strategy */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2246
	nodev,		/* print */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2247
	nodev,		/* dump */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2248
	zvol_read,	/* read */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2249
	zvol_write,	/* write */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2250
	zfsdev_ioctl,	/* ioctl */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2251
	nodev,		/* devmap */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2252
	nodev,		/* mmap */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2253
	nodev,		/* segmap */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2254
	nochpoll,	/* poll */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2255
	ddi_prop_op,	/* prop_op */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2256
	NULL,		/* streamtab */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2257
	D_NEW | D_MP | D_64BIT,		/* Driver compatibility flag */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2258
	CB_REV,		/* version */
3638
6b28ebc717aa 6496357 spec_fsync() is useless on devices that do write caching
billm
parents: 3444
diff changeset
  2259
	nodev,		/* async read */
6b28ebc717aa 6496357 spec_fsync() is useless on devices that do write caching
billm
parents: 3444
diff changeset
  2260
	nodev,		/* async write */
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2261
};
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2262
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2263
static struct dev_ops zfs_dev_ops = {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2264
	DEVO_REV,	/* version */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2265
	0,		/* refcnt */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2266
	zfs_info,	/* info */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2267
	nulldev,	/* identify */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2268
	nulldev,	/* probe */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2269
	zfs_attach,	/* attach */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2270
	zfs_detach,	/* detach */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2271
	nodev,		/* reset */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2272
	&zfs_cb_ops,	/* driver operations */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2273
	NULL		/* no bus operations */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2274
};
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2275
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2276
static struct modldrv zfs_modldrv = {
4577
ed36b0e652bc PSARC/2007/328 zfs upgrade
ahrens
parents: 4543
diff changeset
  2277
	&mod_driverops, "ZFS storage pool version " SPA_VERSION_STRING,
2676
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  2278
	    &zfs_dev_ops
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2279
};
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2280
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2281
static struct modlinkage modlinkage = {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2282
	MODREV_1,
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2283
	(void *)&zfs_modlfs,
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2284
	(void *)&zfs_modldrv,
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2285
	NULL
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2286
};
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2287
4720
8edc0d2e6f3f 6535160 Lock contention on zl_lock from zil_commit
fr157268
parents: 4715
diff changeset
  2288
8edc0d2e6f3f 6535160 Lock contention on zl_lock from zil_commit
fr157268
parents: 4715
diff changeset
  2289
uint_t zfs_fsyncer_key;
8edc0d2e6f3f 6535160 Lock contention on zl_lock from zil_commit
fr157268
parents: 4715
diff changeset
  2290
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2291
int
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2292
_init(void)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2293
{
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2294
	int error;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2295
849
8d799fd81a9b 6345023 /dev/zfs fails to open once ZFS module is unloaded
bonwick
parents: 789
diff changeset
  2296
	spa_init(FREAD | FWRITE);
8d799fd81a9b 6345023 /dev/zfs fails to open once ZFS module is unloaded
bonwick
parents: 789
diff changeset
  2297
	zfs_init();
8d799fd81a9b 6345023 /dev/zfs fails to open once ZFS module is unloaded
bonwick
parents: 789
diff changeset
  2298
	zvol_init();
8d799fd81a9b 6345023 /dev/zfs fails to open once ZFS module is unloaded
bonwick
parents: 789
diff changeset
  2299
8d799fd81a9b 6345023 /dev/zfs fails to open once ZFS module is unloaded
bonwick
parents: 789
diff changeset
  2300
	if ((error = mod_install(&modlinkage)) != 0) {
8d799fd81a9b 6345023 /dev/zfs fails to open once ZFS module is unloaded
bonwick
parents: 789
diff changeset
  2301
		zvol_fini();
8d799fd81a9b 6345023 /dev/zfs fails to open once ZFS module is unloaded
bonwick
parents: 789
diff changeset
  2302
		zfs_fini();
8d799fd81a9b 6345023 /dev/zfs fails to open once ZFS module is unloaded
bonwick
parents: 789
diff changeset
  2303
		spa_fini();
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2304
		return (error);
849
8d799fd81a9b 6345023 /dev/zfs fails to open once ZFS module is unloaded
bonwick
parents: 789
diff changeset
  2305
	}
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2306
4720
8edc0d2e6f3f 6535160 Lock contention on zl_lock from zil_commit
fr157268
parents: 4715
diff changeset
  2307
	tsd_create(&zfs_fsyncer_key, NULL);
8edc0d2e6f3f 6535160 Lock contention on zl_lock from zil_commit
fr157268
parents: 4715
diff changeset
  2308
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2309
	error = ldi_ident_from_mod(&modlinkage, &zfs_li);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2310
	ASSERT(error == 0);
4543
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  2311
	mutex_init(&zfs_share_lock, NULL, MUTEX_DEFAULT, NULL);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2312
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2313
	return (0);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2314
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2315
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2316
int
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2317
_fini(void)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2318
{
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2319
	int error;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2320
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
  2321
	if (spa_busy() || zfs_busy() || zvol_busy() || zio_injection_enabled)
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2322
		return (EBUSY);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2323
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2324
	if ((error = mod_remove(&modlinkage)) != 0)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2325
		return (error);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2326
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2327
	zvol_fini();
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2328
	zfs_fini();
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2329
	spa_fini();
4543
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  2330
	if (zfs_share_inited) {
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  2331
		(void) ddi_modclose(nfs_mod);
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  2332
		(void) ddi_modclose(sharefs_mod);
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  2333
	}
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2334
4720
8edc0d2e6f3f 6535160 Lock contention on zl_lock from zil_commit
fr157268
parents: 4715
diff changeset
  2335
	tsd_destroy(&zfs_fsyncer_key);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2336
	ldi_ident_release(zfs_li);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2337
	zfs_li = NULL;
4543
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  2338
	mutex_destroy(&zfs_share_lock);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2339
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2340
	return (error);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2341
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2342
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2343
int
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2344
_info(struct modinfo *modinfop)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2345
{
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2346
	return (mod_info(&modlinkage, modinfop));
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2347
}