usr/src/uts/common/fs/zfs/zfs_ioctl.c
author amw
Thu, 25 Oct 2007 16:34:29 -0700
changeset 5331 3047ad28a67b
parent 5329 33cb98223b2d
child 5367 c40abbe796be
permissions -rw-r--r--
PSARC/2007/218 caller_context_t in all VOPs PSARC/2007/227 VFS Feature Registration and ACL on Create PSARC/2007/244 ZFS Case-insensitive support PSARC/2007/315 Extensible Attribute Interfaces PSARC/2007/394 ls(1) new command line options '-/' and '-%': CIFS system attributes support PSARC/2007/403 Modified Access Checks for CIFS PSARC/2007/410 Add system attribute support to chmod(1) PSARC/2007/432 CIFS system attributes support for cp(1), pack(1), unpack(1), compress(1) and uncompress(1) PSARC/2007/444 Rescind SETTABLE Attribute PSARC/2007/459 CIFS system attributes support for cpio(1), pax(1), tar(1) PSARC/2007/546 Update utilities to match CIFS system attributes changes. PSARC/2007/560 ZFS sharesmb property 4890717 want append-only files 6417428 Case-insensitive file system name lookup to support CIFS 6417435 DOS attributes and additional timestamps to support for CIFS 6417442 File system quarantined and modified attributes to support an integrated Anti-Virus service 6417453 FS boolean property for rejecting/allowing invalid UTF-8 sequences in file names 6473733 RFE: Need support for open-deny modes 6473755 RFE: Need ability to reconcile oplock and delegation conflicts 6494624 sharemgr needs to support CIFS shares better 6546705 All vnode operations need to pass caller_context_t 6546706 Need VOP_SETATTR/VOP_GETATTR to support new, optional attributes 6546893 Solaris system attribute support 6550962 ZFS ACL inheritance needs to be enhanced to support Automatic Inheritance 6553589 RFE: VFS Feature Registration facility 6553770 RFE: ZFS support for ACL-on-CREATE (PSARC 2007/227) 6565581 ls(1) should support file system attributes proposed in PSARC/2007/315 6566784 NTFS streams are not copied along with the files. 6576205 cp(1), pack(1) and compress(1) should support file system attributes proposed in PSARC/2007/315 6578875 RFE: kernel interfaces for nbmand need improvement 6578883 RFE: VOP_SHRLOCK needs additional access types 6578885 chmod(1) should support file system attributes proposed in PSARC/2007/315 6578886 RFE: disallow nbmand state to change on remount 6583349 ACL parser needs to support audit/alarm ACE types 6590347 tar(1) should support filesystem attributes proposed in PSARC/2007/315 6597357 *tar* xv@ doesn't show the hidden directory even though it is restored 6597360 *tar* should re-init xattr info if openat() fails during extraction of and extended attribute 6597368 *tar* cannot restore hard linked extended attributes 6597374 *tar* doesn't display "x " when hard linked attributes are restored 6597375 *tar* extended attribute header off by one 6614861 *cpio* incorrectly archives extended system attributes with -@ 6614896 *pax* incorrectly archives extended system attributes with -@ 6615225 *tar* incorrectly archives extended system attributes with -@ 6617183 CIFS Service - PSARC 2006/715
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>
5331
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
    41
#include <sys/zfs_i18n.h>
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
    42
#include <sys/zfs_znode.h>
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    43
#include <sys/zap.h>
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    44
#include <sys/spa.h>
3912
f6891a60bd72 PSARC 2007/083 ZFS bootable datasets
lling
parents: 3886
diff changeset
    45
#include <sys/spa_impl.h>
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    46
#include <sys/vdev.h>
3912
f6891a60bd72 PSARC 2007/083 ZFS bootable datasets
lling
parents: 3886
diff changeset
    47
#include <sys/vdev_impl.h>
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    48
#include <sys/dmu.h>
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    49
#include <sys/dsl_dir.h>
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    50
#include <sys/dsl_dataset.h>
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    51
#include <sys/dsl_prop.h>
4543
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
    52
#include <sys/dsl_deleg.h>
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
    53
#include <sys/dmu_objset.h>
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    54
#include <sys/ddi.h>
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    55
#include <sys/sunddi.h>
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    56
#include <sys/sunldi.h>
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    57
#include <sys/policy.h>
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    58
#include <sys/zone.h>
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    59
#include <sys/nvpair.h>
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    60
#include <sys/pathname.h>
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    61
#include <sys/mount.h>
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    62
#include <sys/sdt.h>
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    63
#include <sys/fs/zfs.h>
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    64
#include <sys/zfs_ctldir.h>
5331
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
    65
#include <sys/zfs_dir.h>
2885
c0259887ebbc 6460059 zfs destroy <snapshot> leaves behind kruft
ahrens
parents: 2856
diff changeset
    66
#include <sys/zvol.h>
4543
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
    67
#include <sharefs/share.h>
4577
ed36b0e652bc PSARC/2007/328 zfs upgrade
ahrens
parents: 4543
diff changeset
    68
#include <sys/zfs_znode.h>
5326
6752aa2bd5bc 6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents: 5147
diff changeset
    69
#include <sys/zfs_vfsops.h>
6752aa2bd5bc 6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents: 5147
diff changeset
    70
#include <sys/dmu_objset.h>
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    71
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    72
#include "zfs_namecheck.h"
2676
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
    73
#include "zfs_prop.h"
4543
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
    74
#include "zfs_deleg.h"
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    75
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    76
extern struct modlfs zfs_modlfs;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    77
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    78
extern void zfs_init(void);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    79
extern void zfs_fini(void);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    80
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    81
ldi_ident_t zfs_li = NULL;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    82
dev_info_t *zfs_dip;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    83
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    84
typedef int zfs_ioc_func_t(zfs_cmd_t *);
4543
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
    85
typedef int zfs_secpolicy_func_t(zfs_cmd_t *, cred_t *);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    86
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    87
typedef struct zfs_ioc_vec {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    88
	zfs_ioc_func_t		*zvec_func;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    89
	zfs_secpolicy_func_t	*zvec_secpolicy;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    90
	enum {
4577
ed36b0e652bc PSARC/2007/328 zfs upgrade
ahrens
parents: 4543
diff changeset
    91
		NO_NAME,
ed36b0e652bc PSARC/2007/328 zfs upgrade
ahrens
parents: 4543
diff changeset
    92
		POOL_NAME,
ed36b0e652bc PSARC/2007/328 zfs upgrade
ahrens
parents: 4543
diff changeset
    93
		DATASET_NAME
4543
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
    94
	} zvec_namecheck;
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
    95
	boolean_t		zvec_his_log;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    96
} zfs_ioc_vec_t;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    97
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    98
/* _NOTE(PRINTFLIKE(4)) - this is printf-like, but lint is too whiney */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    99
void
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   100
__dprintf(const char *file, const char *func, int line, const char *fmt, ...)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   101
{
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   102
	const char *newfile;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   103
	char buf[256];
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   104
	va_list adx;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   105
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   106
	/*
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   107
	 * Get rid of annoying "../common/" prefix to filename.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   108
	 */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   109
	newfile = strrchr(file, '/');
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   110
	if (newfile != NULL) {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   111
		newfile = newfile + 1; /* Get rid of leading / */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   112
	} else {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   113
		newfile = file;
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
	va_start(adx, fmt);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   117
	(void) vsnprintf(buf, sizeof (buf), fmt, adx);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   118
	va_end(adx);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   119
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   120
	/*
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   121
	 * To get this data, use the zfs-dprintf probe as so:
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   122
	 * dtrace -q -n 'zfs-dprintf \
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   123
	 *	/stringof(arg0) == "dbuf.c"/ \
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   124
	 *	{printf("%s: %s", stringof(arg1), stringof(arg3))}'
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   125
	 * arg0 = file name
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   126
	 * arg1 = function name
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   127
	 * arg2 = line number
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   128
	 * arg3 = message
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   129
	 */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   130
	DTRACE_PROBE4(zfs__dprintf,
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   131
	    char *, newfile, char *, func, int, line, char *, buf);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   132
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   133
4543
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   134
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
   135
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
   136
{
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
	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
   138
}
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
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
   141
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
   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
	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
   144
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
	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
   146
		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
   147
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
	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
   149
	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
   150
	    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
   151
		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
   152
		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
   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
	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
   156
e8d212dda064 6535695 Panic: shpp->sh_eof == shpp->sh_pool_create_len, file: ../../common/fs/zfs/spa_history.c, line: 235
ek110237
parents: 4670
diff changeset
   157
	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
   158
}
e8d212dda064 6535695 Panic: shpp->sh_eof == shpp->sh_pool_create_len, file: ../../common/fs/zfs/spa_history.c, line: 235
ek110237
parents: 4670
diff changeset
   159
5331
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
   160
static int
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
   161
zfs_check_version(const char *name, int version)
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
   162
{
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
   163
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
   164
	spa_t *spa;
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
   165
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
   166
	if (spa_open(name, &spa, FTAG) == 0) {
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
   167
		if (spa_version(spa) < version) {
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
   168
			spa_close(spa, FTAG);
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
   169
			return (1);
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
   170
		}
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
   171
		spa_close(spa, FTAG);
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
   172
	}
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
   173
	return (0);
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
   174
}
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
   175
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
   176
static void
4543
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   177
zfs_log_history(zfs_cmd_t *zc)
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   178
{
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   179
	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
   180
	char *buf;
4543
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   181
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
   182
	if ((buf = history_str_get(zc)) == NULL)
4577
ed36b0e652bc PSARC/2007/328 zfs upgrade
ahrens
parents: 4543
diff changeset
   183
		return;
ed36b0e652bc PSARC/2007/328 zfs upgrade
ahrens
parents: 4543
diff changeset
   184
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
   185
	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
   186
		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
   187
			(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
   188
		spa_close(spa, FTAG);
4543
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   189
	}
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
   190
	history_str_free(buf);
4543
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   191
}
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   192
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   193
/*
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   194
 * Policy for top-level read operations (list pools).  Requires no privileges,
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   195
 * and can be used in the local zone, as there is no associated dataset.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   196
 */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   197
/* ARGSUSED */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   198
static int
4543
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   199
zfs_secpolicy_none(zfs_cmd_t *zc, cred_t *cr)
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   200
{
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   201
	return (0);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   202
}
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
 * Policy for dataset read operations (list children, get statistics).  Requires
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   206
 * no privileges, but must be visible in the local zone.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   207
 */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   208
/* ARGSUSED */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   209
static int
4543
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   210
zfs_secpolicy_read(zfs_cmd_t *zc, cred_t *cr)
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   211
{
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   212
	if (INGLOBALZONE(curproc) ||
4543
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   213
	    zone_dataset_visible(zc->zc_name, NULL))
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   214
		return (0);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   215
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   216
	return (ENOENT);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   217
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   218
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   219
static int
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   220
zfs_dozonecheck(const char *dataset, cred_t *cr)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   221
{
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   222
	uint64_t zoned;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   223
	int writable = 1;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   224
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   225
	/*
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   226
	 * The dataset must be visible by this zone -- check this first
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   227
	 * so they don't see EPERM on something they shouldn't know about.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   228
	 */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   229
	if (!INGLOBALZONE(curproc) &&
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   230
	    !zone_dataset_visible(dataset, &writable))
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   231
		return (ENOENT);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   232
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   233
	if (dsl_prop_get_integer(dataset, "zoned", &zoned, NULL))
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   234
		return (ENOENT);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   235
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   236
	if (INGLOBALZONE(curproc)) {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   237
		/*
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   238
		 * If the fs is zoned, only root can access it from the
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   239
		 * global zone.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   240
		 */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   241
		if (secpolicy_zfs(cr) && zoned)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   242
			return (EPERM);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   243
	} else {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   244
		/*
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   245
		 * If we are in a local zone, the 'zoned' property must be set.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   246
		 */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   247
		if (!zoned)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   248
			return (EPERM);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   249
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   250
		/* must be writable by this zone */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   251
		if (!writable)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   252
			return (EPERM);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   253
	}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   254
	return (0);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   255
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   256
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   257
int
4543
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   258
zfs_secpolicy_write_perms(const char *name, const char *perm, cred_t *cr)
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   259
{
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   260
	int error;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   261
4543
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   262
	error = zfs_dozonecheck(name, cr);
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   263
	if (error == 0) {
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   264
		error = secpolicy_zfs(cr);
4670
002728040e28 6580745 "zfs inherit" can be executed by ordinary user
ahrens
parents: 4611
diff changeset
   265
		if (error)
4543
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   266
			error = dsl_deleg_access(name, perm, cr);
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   267
	}
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   268
	return (error);
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
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   271
static int
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   272
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
   273
{
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   274
	/*
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   275
	 * Check permissions for special properties.
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   276
	 */
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   277
	switch (prop) {
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   278
	case ZFS_PROP_ZONED:
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   279
		/*
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   280
		 * Disallow setting of 'zoned' from within a local zone.
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
		if (!INGLOBALZONE(curproc))
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   283
			return (EPERM);
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   284
		break;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   285
4543
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   286
	case ZFS_PROP_QUOTA:
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   287
		if (!INGLOBALZONE(curproc)) {
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   288
			uint64_t zoned;
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   289
			char setpoint[MAXNAMELEN];
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
			 * Unprivileged users are allowed to modify the
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   292
			 * quota on things *under* (ie. contained by)
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   293
			 * the thing they own.
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
			if (dsl_prop_get_integer(name, "zoned", &zoned,
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   296
			    setpoint))
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   297
				return (EPERM);
4670
002728040e28 6580745 "zfs inherit" can be executed by ordinary user
ahrens
parents: 4611
diff changeset
   298
			if (!zoned || strlen(name) <= strlen(setpoint))
4543
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   299
				return (EPERM);
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   300
		}
4670
002728040e28 6580745 "zfs inherit" can be executed by ordinary user
ahrens
parents: 4611
diff changeset
   301
		break;
4543
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   302
	}
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   303
4787
602d3f97842c 6393351 unique_* could be improved
ahrens
parents: 4720
diff changeset
   304
	return (zfs_secpolicy_write_perms(name, zfs_prop_to_name(prop), cr));
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   305
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   306
4543
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   307
int
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   308
zfs_secpolicy_fsacl(zfs_cmd_t *zc, cred_t *cr)
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   309
{
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   310
	int error;
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   311
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   312
	error = zfs_dozonecheck(zc->zc_name, cr);
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   313
	if (error)
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   314
		return (error);
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   315
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
	 * permission to set permissions will be evaluated later in
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   318
	 * dsl_deleg_can_allow()
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
	return (0);
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   321
}
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   322
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   323
int
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   324
zfs_secpolicy_rollback(zfs_cmd_t *zc, cred_t *cr)
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   325
{
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   326
	int error;
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   327
	error = zfs_secpolicy_write_perms(zc->zc_name,
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   328
	    ZFS_DELEG_PERM_ROLLBACK, cr);
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   329
	if (error == 0)
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   330
		error = zfs_secpolicy_write_perms(zc->zc_name,
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   331
		    ZFS_DELEG_PERM_MOUNT, cr);
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   332
	return (error);
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   333
}
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   334
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   335
int
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   336
zfs_secpolicy_send(zfs_cmd_t *zc, cred_t *cr)
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   337
{
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   338
	return (zfs_secpolicy_write_perms(zc->zc_name,
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   339
	    ZFS_DELEG_PERM_SEND, cr));
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   340
}
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   341
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   342
int
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   343
zfs_secpolicy_share(zfs_cmd_t *zc, cred_t *cr)
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
	if (!INGLOBALZONE(curproc))
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   346
		return (EPERM);
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   347
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   348
	if (secpolicy_nfs(CRED()) == 0) {
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   349
		return (0);
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   350
	} else {
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   351
		vnode_t *vp;
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   352
		int error;
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   353
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   354
		if ((error = lookupname(zc->zc_value, UIO_SYSSPACE,
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   355
		    NO_FOLLOW, NULL, &vp)) != 0)
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   356
			return (error);
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   357
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   358
		/* Now make sure mntpnt and dataset are ZFS */
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   359
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   360
		if (vp->v_vfsp->vfs_fstype != zfsfstype ||
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   361
		    (strcmp((char *)refstr_value(vp->v_vfsp->vfs_resource),
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   362
		    zc->zc_name) != 0)) {
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   363
			VN_RELE(vp);
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   364
			return (EPERM);
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   365
		}
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   366
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   367
		VN_RELE(vp);
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   368
		return (dsl_deleg_access(zc->zc_name,
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   369
		    ZFS_DELEG_PERM_SHARE, cr));
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   370
	}
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   371
}
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   372
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   373
static int
4543
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   374
zfs_get_parent(const char *datasetname, char *parent, int parentsize)
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   375
{
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   376
	char *cp;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   377
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   378
	/*
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   379
	 * Remove the @bla or /bla from the end of the name to get the parent.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   380
	 */
4543
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   381
	(void) strncpy(parent, datasetname, parentsize);
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   382
	cp = strrchr(parent, '@');
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   383
	if (cp != NULL) {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   384
		cp[0] = '\0';
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   385
	} else {
4543
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   386
		cp = strrchr(parent, '/');
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   387
		if (cp == NULL)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   388
			return (ENOENT);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   389
		cp[0] = '\0';
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   390
	}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   391
4543
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   392
	return (0);
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   393
}
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
int
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   396
zfs_secpolicy_destroy_perms(const char *name, cred_t *cr)
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   397
{
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   398
	int error;
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   399
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   400
	if ((error = zfs_secpolicy_write_perms(name,
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   401
	    ZFS_DELEG_PERM_MOUNT, cr)) != 0)
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   402
		return (error);
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   403
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   404
	return (zfs_secpolicy_write_perms(name, ZFS_DELEG_PERM_DESTROY, cr));
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   405
}
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   406
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   407
static int
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   408
zfs_secpolicy_destroy(zfs_cmd_t *zc, cred_t *cr)
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   409
{
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   410
	return (zfs_secpolicy_destroy_perms(zc->zc_name, cr));
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
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   413
/*
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   414
 * Must have sys_config privilege to check the iscsi permission
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
/* ARGSUSED */
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   417
static int
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   418
zfs_secpolicy_iscsi(zfs_cmd_t *zc, cred_t *cr)
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
	return (secpolicy_zfs(cr));
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   421
}
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   422
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   423
int
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   424
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
   425
{
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   426
	char 	parentname[MAXNAMELEN];
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   427
	int	error;
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   428
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   429
	if ((error = zfs_secpolicy_write_perms(from,
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   430
	    ZFS_DELEG_PERM_RENAME, cr)) != 0)
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   431
		return (error);
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   432
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   433
	if ((error = zfs_secpolicy_write_perms(from,
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   434
	    ZFS_DELEG_PERM_MOUNT, cr)) != 0)
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   435
		return (error);
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
	if ((error = zfs_get_parent(to, parentname,
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   438
	    sizeof (parentname))) != 0)
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   439
		return (error);
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   440
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   441
	if ((error = zfs_secpolicy_write_perms(parentname,
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   442
	    ZFS_DELEG_PERM_CREATE, cr)) != 0)
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   443
		return (error);
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   444
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   445
	if ((error = zfs_secpolicy_write_perms(parentname,
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   446
	    ZFS_DELEG_PERM_MOUNT, cr)) != 0)
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
	return (error);
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   450
}
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   451
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   452
static int
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   453
zfs_secpolicy_rename(zfs_cmd_t *zc, cred_t *cr)
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   454
{
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   455
	return (zfs_secpolicy_rename_perms(zc->zc_name, zc->zc_value, cr));
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   456
}
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   457
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   458
static int
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   459
zfs_secpolicy_promote(zfs_cmd_t *zc, cred_t *cr)
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   460
{
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   461
	char 	parentname[MAXNAMELEN];
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   462
	objset_t *clone;
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   463
	int error;
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   464
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   465
	error = zfs_secpolicy_write_perms(zc->zc_name,
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   466
	    ZFS_DELEG_PERM_PROMOTE, cr);
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   467
	if (error)
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   468
		return (error);
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
	error = dmu_objset_open(zc->zc_name, DMU_OST_ANY,
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   471
	    DS_MODE_STANDARD | DS_MODE_READONLY, &clone);
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   472
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   473
	if (error == 0) {
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   474
		dsl_dataset_t *pclone = NULL;
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   475
		dsl_dir_t *dd;
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   476
		dd = clone->os->os_dsl_dataset->ds_dir;
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   477
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   478
		rw_enter(&dd->dd_pool->dp_config_rwlock, RW_READER);
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   479
		error = dsl_dataset_open_obj(dd->dd_pool,
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   480
		    dd->dd_phys->dd_clone_parent_obj, NULL,
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   481
		    DS_MODE_NONE, FTAG, &pclone);
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   482
		rw_exit(&dd->dd_pool->dp_config_rwlock);
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   483
		if (error) {
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   484
			dmu_objset_close(clone);
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   485
			return (error);
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   486
		}
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   487
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   488
		error = zfs_secpolicy_write_perms(zc->zc_name,
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   489
		    ZFS_DELEG_PERM_MOUNT, cr);
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   490
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   491
		dsl_dataset_name(pclone, parentname);
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   492
		dmu_objset_close(clone);
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   493
		dsl_dataset_close(pclone, DS_MODE_NONE, FTAG);
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   494
		if (error == 0)
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   495
			error = zfs_secpolicy_write_perms(parentname,
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   496
			    ZFS_DELEG_PERM_PROMOTE, cr);
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   497
	}
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   498
	return (error);
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   499
}
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   500
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   501
static int
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   502
zfs_secpolicy_receive(zfs_cmd_t *zc, cred_t *cr)
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   503
{
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   504
	int 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
	if ((error = zfs_secpolicy_write_perms(zc->zc_name,
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   507
	    ZFS_DELEG_PERM_RECEIVE, cr)) != 0)
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   508
		return (error);
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   509
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   510
	if ((error = zfs_secpolicy_write_perms(zc->zc_name,
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   511
	    ZFS_DELEG_PERM_MOUNT, cr)) != 0)
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   512
		return (error);
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   513
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   514
	return (zfs_secpolicy_write_perms(zc->zc_name,
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   515
	    ZFS_DELEG_PERM_CREATE, cr));
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   516
}
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
int
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   519
zfs_secpolicy_snapshot_perms(const char *name, cred_t *cr)
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   520
{
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   521
	int error;
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   522
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   523
	if ((error = zfs_secpolicy_write_perms(name,
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   524
	    ZFS_DELEG_PERM_SNAPSHOT, cr)) != 0)
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   525
		return (error);
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   526
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   527
	error = zfs_secpolicy_write_perms(name,
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   528
	    ZFS_DELEG_PERM_MOUNT, cr);
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   529
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   530
	return (error);
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   531
}
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   532
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   533
static int
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   534
zfs_secpolicy_snapshot(zfs_cmd_t *zc, cred_t *cr)
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   535
{
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   536
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   537
	return (zfs_secpolicy_snapshot_perms(zc->zc_name, cr));
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
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   540
static int
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   541
zfs_secpolicy_create(zfs_cmd_t *zc, cred_t *cr)
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   542
{
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   543
	char 	parentname[MAXNAMELEN];
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   544
	int 	error;
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   545
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   546
	if ((error = zfs_get_parent(zc->zc_name, parentname,
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   547
	    sizeof (parentname))) != 0)
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   548
		return (error);
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   549
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   550
	if (zc->zc_value[0] != '\0') {
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   551
		if ((error = zfs_secpolicy_write_perms(zc->zc_value,
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   552
		    ZFS_DELEG_PERM_CLONE, cr)) != 0)
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   553
			return (error);
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   554
	}
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   555
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   556
	if ((error = zfs_secpolicy_write_perms(parentname,
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   557
	    ZFS_DELEG_PERM_CREATE, cr)) != 0)
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   558
		return (error);
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   559
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   560
	error = zfs_secpolicy_write_perms(parentname,
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   561
	    ZFS_DELEG_PERM_MOUNT, cr);
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   562
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   563
	return (error);
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   564
}
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   565
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   566
static int
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   567
zfs_secpolicy_umount(zfs_cmd_t *zc, cred_t *cr)
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   568
{
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   569
	int error;
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   570
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   571
	error = secpolicy_fs_unmount(cr, NULL);
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   572
	if (error) {
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   573
		error = dsl_deleg_access(zc->zc_name, ZFS_DELEG_PERM_MOUNT, cr);
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   574
	}
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   575
	return (error);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   576
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   577
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   578
/*
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   579
 * Policy for pool operations - create/destroy pools, add vdevs, etc.  Requires
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   580
 * SYS_CONFIG privilege, which is not available in a local zone.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   581
 */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   582
/* ARGSUSED */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   583
static int
4543
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   584
zfs_secpolicy_config(zfs_cmd_t *zc, cred_t *cr)
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   585
{
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   586
	if (secpolicy_sys_config(cr, B_FALSE) != 0)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   587
		return (EPERM);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   588
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   589
	return (0);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   590
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   591
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   592
/*
4543
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   593
 * Just like zfs_secpolicy_config, except that we will check for
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   594
 * mount permission on the dataset for permission to create/remove
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   595
 * the minor nodes.
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   596
 */
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   597
static int
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   598
zfs_secpolicy_minor(zfs_cmd_t *zc, cred_t *cr)
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   599
{
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   600
	if (secpolicy_sys_config(cr, B_FALSE) != 0) {
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   601
		return (dsl_deleg_access(zc->zc_name,
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   602
		    ZFS_DELEG_PERM_MOUNT, cr));
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   603
	}
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   604
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   605
	return (0);
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   606
}
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   607
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   608
/*
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
   609
 * Policy for fault injection.  Requires all privileges.
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
   610
 */
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
   611
/* ARGSUSED */
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
   612
static int
4543
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   613
zfs_secpolicy_inject(zfs_cmd_t *zc, cred_t *cr)
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
   614
{
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
   615
	return (secpolicy_zinject(cr));
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
   616
}
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
   617
4849
3a61e0a9a953 6536043 arc_byteswap_func_t and dmu_byteswap_func_t are redundant
ahrens
parents: 4808
diff changeset
   618
static int
3a61e0a9a953 6536043 arc_byteswap_func_t and dmu_byteswap_func_t are redundant
ahrens
parents: 4808
diff changeset
   619
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
   620
{
3a61e0a9a953 6536043 arc_byteswap_func_t and dmu_byteswap_func_t are redundant
ahrens
parents: 4808
diff changeset
   621
	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
   622
5094
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
   623
	if (prop == ZPROP_INVAL) {
4849
3a61e0a9a953 6536043 arc_byteswap_func_t and dmu_byteswap_func_t are redundant
ahrens
parents: 4808
diff changeset
   624
		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
   625
			return (EINVAL);
3a61e0a9a953 6536043 arc_byteswap_func_t and dmu_byteswap_func_t are redundant
ahrens
parents: 4808
diff changeset
   626
		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
   627
		    ZFS_DELEG_PERM_USERPROP, cr));
3a61e0a9a953 6536043 arc_byteswap_func_t and dmu_byteswap_func_t are redundant
ahrens
parents: 4808
diff changeset
   628
	} else {
3a61e0a9a953 6536043 arc_byteswap_func_t and dmu_byteswap_func_t are redundant
ahrens
parents: 4808
diff changeset
   629
		if (!zfs_prop_inheritable(prop))
3a61e0a9a953 6536043 arc_byteswap_func_t and dmu_byteswap_func_t are redundant
ahrens
parents: 4808
diff changeset
   630
			return (EINVAL);
3a61e0a9a953 6536043 arc_byteswap_func_t and dmu_byteswap_func_t are redundant
ahrens
parents: 4808
diff changeset
   631
		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
   632
	}
3a61e0a9a953 6536043 arc_byteswap_func_t and dmu_byteswap_func_t are redundant
ahrens
parents: 4808
diff changeset
   633
}
3a61e0a9a953 6536043 arc_byteswap_func_t and dmu_byteswap_func_t are redundant
ahrens
parents: 4808
diff changeset
   634
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
   635
/*
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   636
 * Returns the nvlist as specified by the user in the zfs_cmd_t.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   637
 */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   638
static int
5094
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
   639
get_nvlist(uint64_t nvl, uint64_t size, nvlist_t **nvp)
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   640
{
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   641
	char *packed;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   642
	int error;
5094
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
   643
	nvlist_t *list = NULL;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   644
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   645
	/*
2676
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
   646
	 * Read in and unpack the user-supplied nvlist.
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   647
	 */
5094
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
   648
	if (size == 0)
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   649
		return (EINVAL);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   650
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   651
	packed = kmem_alloc(size, KM_SLEEP);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   652
5094
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
   653
	if ((error = xcopyin((void *)(uintptr_t)nvl, packed, size)) != 0) {
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   654
		kmem_free(packed, size);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   655
		return (error);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   656
	}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   657
5094
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
   658
	if ((error = nvlist_unpack(packed, size, &list, 0)) != 0) {
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   659
		kmem_free(packed, size);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   660
		return (error);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   661
	}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   662
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   663
	kmem_free(packed, size);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   664
5094
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
   665
	*nvp = list;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   666
	return (0);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   667
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   668
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   669
static int
2676
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
   670
put_nvlist(zfs_cmd_t *zc, nvlist_t *nvl)
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
	char *packed = NULL;
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
   673
	size_t size;
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
   674
	int error;
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
   675
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
   676
	VERIFY(nvlist_size(nvl, &size, NV_ENCODE_NATIVE) == 0);
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
   677
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
   678
	if (size > zc->zc_nvlist_dst_size) {
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
   679
		error = ENOMEM;
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
   680
	} else {
4611
0960c3336815 6575997 Memory corruption while running ztest
marks
parents: 4603
diff changeset
   681
		packed = kmem_alloc(size, KM_SLEEP);
2676
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
   682
		VERIFY(nvlist_pack(nvl, &packed, &size, NV_ENCODE_NATIVE,
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
   683
		    KM_SLEEP) == 0);
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
   684
		error = xcopyout(packed, (void *)(uintptr_t)zc->zc_nvlist_dst,
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
   685
		    size);
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
   686
		kmem_free(packed, size);
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
   687
	}
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
   688
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
   689
	zc->zc_nvlist_dst_size = size;
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
   690
	return (error);
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
   691
}
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
   692
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
   693
static int
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   694
zfs_ioc_pool_create(zfs_cmd_t *zc)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   695
{
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   696
	int error;
5094
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
   697
	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
   698
	char *buf;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   699
5094
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
   700
	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
   701
	    &config))
4988
db8abd9846d4 6595467 libzfs consumers should be allowed to write their own history (or none at all)
ek110237
parents: 4849
diff changeset
   702
		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
   703
5094
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
   704
	if (zc->zc_nvlist_src_size != 0 && (error =
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
   705
	    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
   706
		nvlist_free(config);
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
   707
		return (error);
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
   708
	}
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
   709
4988
db8abd9846d4 6595467 libzfs consumers should be allowed to write their own history (or none at all)
ek110237
parents: 4849
diff changeset
   710
	buf = history_str_get(zc);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   711
5094
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
   712
	error = spa_create(zc->zc_name, config, props, buf);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   713
4988
db8abd9846d4 6595467 libzfs consumers should be allowed to write their own history (or none at all)
ek110237
parents: 4849
diff changeset
   714
	if (buf != NULL)
db8abd9846d4 6595467 libzfs consumers should be allowed to write their own history (or none at all)
ek110237
parents: 4849
diff changeset
   715
		history_str_free(buf);
5094
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
   716
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   717
	nvlist_free(config);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   718
5094
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
   719
	if (props)
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
   720
		nvlist_free(props);
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
   721
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   722
	return (error);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   723
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   724
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   725
static int
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   726
zfs_ioc_pool_destroy(zfs_cmd_t *zc)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   727
{
4543
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   728
	int error;
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   729
	zfs_log_history(zc);
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   730
	error = spa_destroy(zc->zc_name);
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   731
	return (error);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   732
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   733
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   734
static int
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   735
zfs_ioc_pool_import(zfs_cmd_t *zc)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   736
{
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   737
	int error;
5094
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
   738
	nvlist_t *config, *props = NULL;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   739
	uint64_t guid;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   740
5094
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
   741
	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
   742
	    &config)) != 0)
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   743
		return (error);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   744
5094
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
   745
	if (zc->zc_nvlist_src_size != 0 && (error =
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
   746
	    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
   747
		nvlist_free(config);
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
   748
		return (error);
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
   749
	}
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
   750
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   751
	if (nvlist_lookup_uint64(config, ZPOOL_CONFIG_POOL_GUID, &guid) != 0 ||
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
   752
	    guid != zc->zc_guid)
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   753
		error = EINVAL;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   754
	else
5094
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
   755
		error = spa_import(zc->zc_name, config, props);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   756
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   757
	nvlist_free(config);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   758
5094
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
   759
	if (props)
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
   760
		nvlist_free(props);
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
   761
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   762
	return (error);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   763
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   764
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   765
static int
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   766
zfs_ioc_pool_export(zfs_cmd_t *zc)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   767
{
4543
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   768
	int error;
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   769
	zfs_log_history(zc);
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   770
	error = spa_export(zc->zc_name, NULL);
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   771
	return (error);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   772
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   773
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   774
static int
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   775
zfs_ioc_pool_configs(zfs_cmd_t *zc)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   776
{
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   777
	nvlist_t *configs;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   778
	int error;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   779
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   780
	if ((configs = spa_all_configs(&zc->zc_cookie)) == NULL)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   781
		return (EEXIST);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   782
2676
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
   783
	error = put_nvlist(zc, configs);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   784
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   785
	nvlist_free(configs);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   786
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   787
	return (error);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   788
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   790
static int
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   791
zfs_ioc_pool_stats(zfs_cmd_t *zc)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   792
{
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   793
	nvlist_t *config;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   794
	int error;
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
   795
	int ret = 0;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   796
2676
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
   797
	error = spa_get_stats(zc->zc_name, &config, zc->zc_value,
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
   798
	    sizeof (zc->zc_value));
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   799
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   800
	if (config != NULL) {
2676
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
   801
		ret = put_nvlist(zc, config);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   802
		nvlist_free(config);
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
   803
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
   804
		/*
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
   805
		 * The config may be present even if 'error' is non-zero.
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
   806
		 * In this case we return success, and preserve the real errno
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
   807
		 * in 'zc_cookie'.
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
   808
		 */
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
   809
		zc->zc_cookie = error;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   810
	} else {
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
   811
		ret = error;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   812
	}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   813
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
   814
	return (ret);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   815
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   816
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   817
/*
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   818
 * Try to import the given pool, returning pool stats as appropriate so that
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   819
 * user land knows which devices are available and overall pool health.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   820
 */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   821
static int
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   822
zfs_ioc_pool_tryimport(zfs_cmd_t *zc)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   823
{
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   824
	nvlist_t *tryconfig, *config;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   825
	int error;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   826
5094
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
   827
	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
   828
	    &tryconfig)) != 0)
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   829
		return (error);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   830
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   831
	config = spa_tryimport(tryconfig);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   832
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   833
	nvlist_free(tryconfig);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   834
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   835
	if (config == NULL)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   836
		return (EINVAL);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   837
2676
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
   838
	error = put_nvlist(zc, config);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   839
	nvlist_free(config);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   840
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   841
	return (error);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   842
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   843
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   844
static int
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   845
zfs_ioc_pool_scrub(zfs_cmd_t *zc)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   846
{
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   847
	spa_t *spa;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   848
	int error;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   849
2926
acfcfefbc60d PSARC 2006/288 zpool history
ek110237
parents: 2885
diff changeset
   850
	if ((error = spa_open(zc->zc_name, &spa, FTAG)) != 0)
acfcfefbc60d PSARC 2006/288 zpool history
ek110237
parents: 2885
diff changeset
   851
		return (error);
acfcfefbc60d PSARC 2006/288 zpool history
ek110237
parents: 2885
diff changeset
   852
4808
63629eaeb41a 6498144 ::kmastat could be even easier to read
ek110237
parents: 4787
diff changeset
   853
	mutex_enter(&spa_namespace_lock);
2926
acfcfefbc60d PSARC 2006/288 zpool history
ek110237
parents: 2885
diff changeset
   854
	error = spa_scrub(spa, zc->zc_cookie, B_FALSE);
4808
63629eaeb41a 6498144 ::kmastat could be even easier to read
ek110237
parents: 4787
diff changeset
   855
	mutex_exit(&spa_namespace_lock);
2926
acfcfefbc60d PSARC 2006/288 zpool history
ek110237
parents: 2885
diff changeset
   856
acfcfefbc60d PSARC 2006/288 zpool history
ek110237
parents: 2885
diff changeset
   857
	spa_close(spa, FTAG);
acfcfefbc60d PSARC 2006/288 zpool history
ek110237
parents: 2885
diff changeset
   858
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   859
	return (error);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   860
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   861
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   862
static int
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   863
zfs_ioc_pool_freeze(zfs_cmd_t *zc)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   864
{
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   865
	spa_t *spa;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   866
	int error;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   867
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   868
	error = spa_open(zc->zc_name, &spa, FTAG);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   869
	if (error == 0) {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   870
		spa_freeze(spa);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   871
		spa_close(spa, FTAG);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   872
	}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   873
	return (error);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   874
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   875
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   876
static int
1760
e1ad2821c30d PSARC 2006/206 zpool upgrade
eschrock
parents: 1544
diff changeset
   877
zfs_ioc_pool_upgrade(zfs_cmd_t *zc)
e1ad2821c30d PSARC 2006/206 zpool upgrade
eschrock
parents: 1544
diff changeset
   878
{
e1ad2821c30d PSARC 2006/206 zpool upgrade
eschrock
parents: 1544
diff changeset
   879
	spa_t *spa;
e1ad2821c30d PSARC 2006/206 zpool upgrade
eschrock
parents: 1544
diff changeset
   880
	int error;
e1ad2821c30d PSARC 2006/206 zpool upgrade
eschrock
parents: 1544
diff changeset
   881
2926
acfcfefbc60d PSARC 2006/288 zpool history
ek110237
parents: 2885
diff changeset
   882
	if ((error = spa_open(zc->zc_name, &spa, FTAG)) != 0)
acfcfefbc60d PSARC 2006/288 zpool history
ek110237
parents: 2885
diff changeset
   883
		return (error);
acfcfefbc60d PSARC 2006/288 zpool history
ek110237
parents: 2885
diff changeset
   884
5118
c723b1aa9f79 6607671 Able to zpool upgrade a pool to an unknown version number
lling
parents: 5094
diff changeset
   885
	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
   886
		spa_close(spa, FTAG);
c723b1aa9f79 6607671 Able to zpool upgrade a pool to an unknown version number
lling
parents: 5094
diff changeset
   887
		return (EINVAL);
c723b1aa9f79 6607671 Able to zpool upgrade a pool to an unknown version number
lling
parents: 5094
diff changeset
   888
	}
c723b1aa9f79 6607671 Able to zpool upgrade a pool to an unknown version number
lling
parents: 5094
diff changeset
   889
5094
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
   890
	spa_upgrade(spa, zc->zc_cookie);
2926
acfcfefbc60d PSARC 2006/288 zpool history
ek110237
parents: 2885
diff changeset
   891
	spa_close(spa, FTAG);
acfcfefbc60d PSARC 2006/288 zpool history
ek110237
parents: 2885
diff changeset
   892
acfcfefbc60d PSARC 2006/288 zpool history
ek110237
parents: 2885
diff changeset
   893
	return (error);
acfcfefbc60d PSARC 2006/288 zpool history
ek110237
parents: 2885
diff changeset
   894
}
acfcfefbc60d PSARC 2006/288 zpool history
ek110237
parents: 2885
diff changeset
   895
acfcfefbc60d PSARC 2006/288 zpool history
ek110237
parents: 2885
diff changeset
   896
static int
acfcfefbc60d PSARC 2006/288 zpool history
ek110237
parents: 2885
diff changeset
   897
zfs_ioc_pool_get_history(zfs_cmd_t *zc)
acfcfefbc60d PSARC 2006/288 zpool history
ek110237
parents: 2885
diff changeset
   898
{
acfcfefbc60d PSARC 2006/288 zpool history
ek110237
parents: 2885
diff changeset
   899
	spa_t *spa;
acfcfefbc60d PSARC 2006/288 zpool history
ek110237
parents: 2885
diff changeset
   900
	char *hist_buf;
acfcfefbc60d PSARC 2006/288 zpool history
ek110237
parents: 2885
diff changeset
   901
	uint64_t size;
acfcfefbc60d PSARC 2006/288 zpool history
ek110237
parents: 2885
diff changeset
   902
	int error;
acfcfefbc60d PSARC 2006/288 zpool history
ek110237
parents: 2885
diff changeset
   903
acfcfefbc60d PSARC 2006/288 zpool history
ek110237
parents: 2885
diff changeset
   904
	if ((size = zc->zc_history_len) == 0)
acfcfefbc60d PSARC 2006/288 zpool history
ek110237
parents: 2885
diff changeset
   905
		return (EINVAL);
acfcfefbc60d PSARC 2006/288 zpool history
ek110237
parents: 2885
diff changeset
   906
acfcfefbc60d PSARC 2006/288 zpool history
ek110237
parents: 2885
diff changeset
   907
	if ((error = spa_open(zc->zc_name, &spa, FTAG)) != 0)
acfcfefbc60d PSARC 2006/288 zpool history
ek110237
parents: 2885
diff changeset
   908
		return (error);
acfcfefbc60d PSARC 2006/288 zpool history
ek110237
parents: 2885
diff changeset
   909
4577
ed36b0e652bc PSARC/2007/328 zfs upgrade
ahrens
parents: 4543
diff changeset
   910
	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
   911
		spa_close(spa, FTAG);
d56571426115 6529406 zpool history needs to bump the on-disk version
ek110237
parents: 3741
diff changeset
   912
		return (ENOTSUP);
d56571426115 6529406 zpool history needs to bump the on-disk version
ek110237
parents: 3741
diff changeset
   913
	}
d56571426115 6529406 zpool history needs to bump the on-disk version
ek110237
parents: 3741
diff changeset
   914
2926
acfcfefbc60d PSARC 2006/288 zpool history
ek110237
parents: 2885
diff changeset
   915
	hist_buf = kmem_alloc(size, KM_SLEEP);
acfcfefbc60d PSARC 2006/288 zpool history
ek110237
parents: 2885
diff changeset
   916
	if ((error = spa_history_get(spa, &zc->zc_history_offset,
acfcfefbc60d PSARC 2006/288 zpool history
ek110237
parents: 2885
diff changeset
   917
	    &zc->zc_history_len, hist_buf)) == 0) {
4543
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   918
		error = xcopyout(hist_buf,
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   919
		    (char *)(uintptr_t)zc->zc_history,
2926
acfcfefbc60d PSARC 2006/288 zpool history
ek110237
parents: 2885
diff changeset
   920
		    zc->zc_history_len);
acfcfefbc60d PSARC 2006/288 zpool history
ek110237
parents: 2885
diff changeset
   921
	}
acfcfefbc60d PSARC 2006/288 zpool history
ek110237
parents: 2885
diff changeset
   922
acfcfefbc60d PSARC 2006/288 zpool history
ek110237
parents: 2885
diff changeset
   923
	spa_close(spa, FTAG);
acfcfefbc60d PSARC 2006/288 zpool history
ek110237
parents: 2885
diff changeset
   924
	kmem_free(hist_buf, size);
acfcfefbc60d PSARC 2006/288 zpool history
ek110237
parents: 2885
diff changeset
   925
	return (error);
acfcfefbc60d PSARC 2006/288 zpool history
ek110237
parents: 2885
diff changeset
   926
}
acfcfefbc60d PSARC 2006/288 zpool history
ek110237
parents: 2885
diff changeset
   927
acfcfefbc60d PSARC 2006/288 zpool history
ek110237
parents: 2885
diff changeset
   928
static int
3444
dc160a70a50d 6410433 'zpool status -v' would be more useful with filenames
ek110237
parents: 3265
diff changeset
   929
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
   930
{
dc160a70a50d 6410433 'zpool status -v' would be more useful with filenames
ek110237
parents: 3265
diff changeset
   931
	int error;
dc160a70a50d 6410433 'zpool status -v' would be more useful with filenames
ek110237
parents: 3265
diff changeset
   932
3912
f6891a60bd72 PSARC 2007/083 ZFS bootable datasets
lling
parents: 3886
diff changeset
   933
	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
   934
		return (error);
dc160a70a50d 6410433 'zpool status -v' would be more useful with filenames
ek110237
parents: 3265
diff changeset
   935
dc160a70a50d 6410433 'zpool status -v' would be more useful with filenames
ek110237
parents: 3265
diff changeset
   936
	return (0);
dc160a70a50d 6410433 'zpool status -v' would be more useful with filenames
ek110237
parents: 3265
diff changeset
   937
}
dc160a70a50d 6410433 'zpool status -v' would be more useful with filenames
ek110237
parents: 3265
diff changeset
   938
dc160a70a50d 6410433 'zpool status -v' would be more useful with filenames
ek110237
parents: 3265
diff changeset
   939
static int
dc160a70a50d 6410433 'zpool status -v' would be more useful with filenames
ek110237
parents: 3265
diff changeset
   940
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
   941
{
dc160a70a50d 6410433 'zpool status -v' would be more useful with filenames
ek110237
parents: 3265
diff changeset
   942
	objset_t *osp;
dc160a70a50d 6410433 'zpool status -v' would be more useful with filenames
ek110237
parents: 3265
diff changeset
   943
	int error;
dc160a70a50d 6410433 'zpool status -v' would be more useful with filenames
ek110237
parents: 3265
diff changeset
   944
dc160a70a50d 6410433 'zpool status -v' would be more useful with filenames
ek110237
parents: 3265
diff changeset
   945
	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
   946
	    DS_MODE_NONE | DS_MODE_READONLY, &osp)) != 0)
dc160a70a50d 6410433 'zpool status -v' would be more useful with filenames
ek110237
parents: 3265
diff changeset
   947
		return (error);
dc160a70a50d 6410433 'zpool status -v' would be more useful with filenames
ek110237
parents: 3265
diff changeset
   948
dc160a70a50d 6410433 'zpool status -v' would be more useful with filenames
ek110237
parents: 3265
diff changeset
   949
	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
   950
	    sizeof (zc->zc_value));
dc160a70a50d 6410433 'zpool status -v' would be more useful with filenames
ek110237
parents: 3265
diff changeset
   951
	dmu_objset_close(osp);
dc160a70a50d 6410433 'zpool status -v' would be more useful with filenames
ek110237
parents: 3265
diff changeset
   952
dc160a70a50d 6410433 'zpool status -v' would be more useful with filenames
ek110237
parents: 3265
diff changeset
   953
	return (error);
dc160a70a50d 6410433 'zpool status -v' would be more useful with filenames
ek110237
parents: 3265
diff changeset
   954
}
dc160a70a50d 6410433 'zpool status -v' would be more useful with filenames
ek110237
parents: 3265
diff changeset
   955
dc160a70a50d 6410433 'zpool status -v' would be more useful with filenames
ek110237
parents: 3265
diff changeset
   956
static int
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   957
zfs_ioc_vdev_add(zfs_cmd_t *zc)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   958
{
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   959
	spa_t *spa;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   960
	int error;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   961
	nvlist_t *config;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   962
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   963
	error = spa_open(zc->zc_name, &spa, FTAG);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   964
	if (error != 0)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   965
		return (error);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   966
3912
f6891a60bd72 PSARC 2007/083 ZFS bootable datasets
lling
parents: 3886
diff changeset
   967
	/*
f6891a60bd72 PSARC 2007/083 ZFS bootable datasets
lling
parents: 3886
diff changeset
   968
	 * A root pool with concatenated devices is not supported.
f6891a60bd72 PSARC 2007/083 ZFS bootable datasets
lling
parents: 3886
diff changeset
   969
	 * 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
   970
	 */
f6891a60bd72 PSARC 2007/083 ZFS bootable datasets
lling
parents: 3886
diff changeset
   971
	if (spa->spa_root_vdev->vdev_children == 1 && spa->spa_bootfs != 0) {
f6891a60bd72 PSARC 2007/083 ZFS bootable datasets
lling
parents: 3886
diff changeset
   972
		spa_close(spa, FTAG);
f6891a60bd72 PSARC 2007/083 ZFS bootable datasets
lling
parents: 3886
diff changeset
   973
		return (EDOM);
f6891a60bd72 PSARC 2007/083 ZFS bootable datasets
lling
parents: 3886
diff changeset
   974
	}
f6891a60bd72 PSARC 2007/083 ZFS bootable datasets
lling
parents: 3886
diff changeset
   975
5094
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
   976
	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
   977
	    &config)) == 0) {
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   978
		error = spa_vdev_add(spa, config);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   979
		nvlist_free(config);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   980
	}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   981
	spa_close(spa, FTAG);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   982
	return (error);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   983
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   984
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   985
static int
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   986
zfs_ioc_vdev_remove(zfs_cmd_t *zc)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   987
{
2082
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1775
diff changeset
   988
	spa_t *spa;
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1775
diff changeset
   989
	int error;
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1775
diff changeset
   990
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1775
diff changeset
   991
	error = spa_open(zc->zc_name, &spa, FTAG);
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1775
diff changeset
   992
	if (error != 0)
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1775
diff changeset
   993
		return (error);
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1775
diff changeset
   994
	error = spa_vdev_remove(spa, zc->zc_guid, B_FALSE);
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1775
diff changeset
   995
	spa_close(spa, FTAG);
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1775
diff changeset
   996
	return (error);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   997
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   998
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   999
static int
4451
24fbf2d7a5d7 PSARC 2007/197 ZFS hotplug
eschrock
parents: 4098
diff changeset
  1000
zfs_ioc_vdev_set_state(zfs_cmd_t *zc)
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1001
{
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1002
	spa_t *spa;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1003
	int error;
4451
24fbf2d7a5d7 PSARC 2007/197 ZFS hotplug
eschrock
parents: 4098
diff changeset
  1004
	vdev_state_t newstate = VDEV_STATE_UNKNOWN;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1005
2926
acfcfefbc60d PSARC 2006/288 zpool history
ek110237
parents: 2885
diff changeset
  1006
	if ((error = spa_open(zc->zc_name, &spa, FTAG)) != 0)
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1007
		return (error);
4451
24fbf2d7a5d7 PSARC 2007/197 ZFS hotplug
eschrock
parents: 4098
diff changeset
  1008
	switch (zc->zc_cookie) {
24fbf2d7a5d7 PSARC 2007/197 ZFS hotplug
eschrock
parents: 4098
diff changeset
  1009
	case VDEV_STATE_ONLINE:
24fbf2d7a5d7 PSARC 2007/197 ZFS hotplug
eschrock
parents: 4098
diff changeset
  1010
		error = vdev_online(spa, zc->zc_guid, zc->zc_obj, &newstate);
24fbf2d7a5d7 PSARC 2007/197 ZFS hotplug
eschrock
parents: 4098
diff changeset
  1011
		break;
24fbf2d7a5d7 PSARC 2007/197 ZFS hotplug
eschrock
parents: 4098
diff changeset
  1012
24fbf2d7a5d7 PSARC 2007/197 ZFS hotplug
eschrock
parents: 4098
diff changeset
  1013
	case VDEV_STATE_OFFLINE:
24fbf2d7a5d7 PSARC 2007/197 ZFS hotplug
eschrock
parents: 4098
diff changeset
  1014
		error = vdev_offline(spa, zc->zc_guid, zc->zc_obj);
24fbf2d7a5d7 PSARC 2007/197 ZFS hotplug
eschrock
parents: 4098
diff changeset
  1015
		break;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1016
4451
24fbf2d7a5d7 PSARC 2007/197 ZFS hotplug
eschrock
parents: 4098
diff changeset
  1017
	case VDEV_STATE_FAULTED:
24fbf2d7a5d7 PSARC 2007/197 ZFS hotplug
eschrock
parents: 4098
diff changeset
  1018
		error = vdev_fault(spa, zc->zc_guid);
24fbf2d7a5d7 PSARC 2007/197 ZFS hotplug
eschrock
parents: 4098
diff changeset
  1019
		break;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1020
4451
24fbf2d7a5d7 PSARC 2007/197 ZFS hotplug
eschrock
parents: 4098
diff changeset
  1021
	case VDEV_STATE_DEGRADED:
24fbf2d7a5d7 PSARC 2007/197 ZFS hotplug
eschrock
parents: 4098
diff changeset
  1022
		error = vdev_degrade(spa, zc->zc_guid);
24fbf2d7a5d7 PSARC 2007/197 ZFS hotplug
eschrock
parents: 4098
diff changeset
  1023
		break;
24fbf2d7a5d7 PSARC 2007/197 ZFS hotplug
eschrock
parents: 4098
diff changeset
  1024
24fbf2d7a5d7 PSARC 2007/197 ZFS hotplug
eschrock
parents: 4098
diff changeset
  1025
	default:
24fbf2d7a5d7 PSARC 2007/197 ZFS hotplug
eschrock
parents: 4098
diff changeset
  1026
		error = EINVAL;
24fbf2d7a5d7 PSARC 2007/197 ZFS hotplug
eschrock
parents: 4098
diff changeset
  1027
	}
24fbf2d7a5d7 PSARC 2007/197 ZFS hotplug
eschrock
parents: 4098
diff changeset
  1028
	zc->zc_cookie = newstate;
789
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_attach(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 replacing = zc->zc_cookie;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1038
	nvlist_t *config;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1039
	int error;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1040
2926
acfcfefbc60d PSARC 2006/288 zpool history
ek110237
parents: 2885
diff changeset
  1041
	if ((error = spa_open(zc->zc_name, &spa, FTAG)) != 0)
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1042
		return (error);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1043
5094
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
  1044
	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
  1045
	    &config)) == 0) {
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
  1046
		error = spa_vdev_attach(spa, zc->zc_guid, config, replacing);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1047
		nvlist_free(config);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1048
	}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1049
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1050
	spa_close(spa, FTAG);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1051
	return (error);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1052
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1053
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1054
static int
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1055
zfs_ioc_vdev_detach(zfs_cmd_t *zc)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1056
{
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1057
	spa_t *spa;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1058
	int error;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1059
2926
acfcfefbc60d PSARC 2006/288 zpool history
ek110237
parents: 2885
diff changeset
  1060
	if ((error = spa_open(zc->zc_name, &spa, FTAG)) != 0)
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1061
		return (error);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1062
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
  1063
	error = spa_vdev_detach(spa, zc->zc_guid, B_FALSE);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1064
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1065
	spa_close(spa, FTAG);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1066
	return (error);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1067
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1068
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1069
static int
1354
81359ee1ee63 6362672 import gets confused about overlapping slices
eschrock
parents: 1133
diff changeset
  1070
zfs_ioc_vdev_setpath(zfs_cmd_t *zc)
81359ee1ee63 6362672 import gets confused about overlapping slices
eschrock
parents: 1133
diff changeset
  1071
{
81359ee1ee63 6362672 import gets confused about overlapping slices
eschrock
parents: 1133
diff changeset
  1072
	spa_t *spa;
2676
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  1073
	char *path = zc->zc_value;
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
  1074
	uint64_t guid = zc->zc_guid;
1354
81359ee1ee63 6362672 import gets confused about overlapping slices
eschrock
parents: 1133
diff changeset
  1075
	int error;
81359ee1ee63 6362672 import gets confused about overlapping slices
eschrock
parents: 1133
diff changeset
  1076
81359ee1ee63 6362672 import gets confused about overlapping slices
eschrock
parents: 1133
diff changeset
  1077
	error = spa_open(zc->zc_name, &spa, FTAG);
81359ee1ee63 6362672 import gets confused about overlapping slices
eschrock
parents: 1133
diff changeset
  1078
	if (error != 0)
81359ee1ee63 6362672 import gets confused about overlapping slices
eschrock
parents: 1133
diff changeset
  1079
		return (error);
81359ee1ee63 6362672 import gets confused about overlapping slices
eschrock
parents: 1133
diff changeset
  1080
81359ee1ee63 6362672 import gets confused about overlapping slices
eschrock
parents: 1133
diff changeset
  1081
	error = spa_vdev_setpath(spa, guid, path);
81359ee1ee63 6362672 import gets confused about overlapping slices
eschrock
parents: 1133
diff changeset
  1082
	spa_close(spa, FTAG);
81359ee1ee63 6362672 import gets confused about overlapping slices
eschrock
parents: 1133
diff changeset
  1083
	return (error);
81359ee1ee63 6362672 import gets confused about overlapping slices
eschrock
parents: 1133
diff changeset
  1084
}
81359ee1ee63 6362672 import gets confused about overlapping slices
eschrock
parents: 1133
diff changeset
  1085
81359ee1ee63 6362672 import gets confused about overlapping slices
eschrock
parents: 1133
diff changeset
  1086
static int
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1087
zfs_ioc_objset_stats(zfs_cmd_t *zc)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1088
{
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1089
	objset_t *os = NULL;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1090
	int error;
1356
e021b5e4aa0e 6377671 zfs mount -a shouldn't bother checking snapshots
eschrock
parents: 1354
diff changeset
  1091
	nvlist_t *nv;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1092
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1093
retry:
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1094
	error = dmu_objset_open(zc->zc_name, DMU_OST_ANY,
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1095
	    DS_MODE_STANDARD | DS_MODE_READONLY, &os);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1096
	if (error != 0) {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1097
		/*
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1098
		 * This is ugly: dmu_objset_open() can return EBUSY if
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1099
		 * the objset is held exclusively. Fortunately this hold is
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1100
		 * only for a short while, so we retry here.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1101
		 * This avoids user code having to handle EBUSY,
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1102
		 * for example for a "zfs list".
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1103
		 */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1104
		if (error == EBUSY) {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1105
			delay(1);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1106
			goto retry;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1107
		}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1108
		return (error);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1109
	}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1110
2885
c0259887ebbc 6460059 zfs destroy <snapshot> leaves behind kruft
ahrens
parents: 2856
diff changeset
  1111
	dmu_objset_fast_stat(os, &zc->zc_objset_stats);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1112
2856
6f4d5ee1906a 6463348 ZFS code could be more portable
nd150628
parents: 2717
diff changeset
  1113
	if (zc->zc_nvlist_dst != 0 &&
1356
e021b5e4aa0e 6377671 zfs mount -a shouldn't bother checking snapshots
eschrock
parents: 1354
diff changeset
  1114
	    (error = dsl_prop_get_all(os, &nv)) == 0) {
2885
c0259887ebbc 6460059 zfs destroy <snapshot> leaves behind kruft
ahrens
parents: 2856
diff changeset
  1115
		dmu_objset_stats(os, nv);
3087
62df4acfd5cb 6468748 assertion failure in dnode_sync
ahrens
parents: 2926
diff changeset
  1116
		/*
5147
5e950ccc9585 6596190 "zfs list" is slow due to version property
rm160521
parents: 5118
diff changeset
  1117
		 * NB: zvol_get_stats() will read the objset contents,
3087
62df4acfd5cb 6468748 assertion failure in dnode_sync
ahrens
parents: 2926
diff changeset
  1118
		 * which we aren't supposed to do with a
62df4acfd5cb 6468748 assertion failure in dnode_sync
ahrens
parents: 2926
diff changeset
  1119
		 * DS_MODE_STANDARD open, because it could be
62df4acfd5cb 6468748 assertion failure in dnode_sync
ahrens
parents: 2926
diff changeset
  1120
		 * inconsistent.  So this is a bit of a workaround...
62df4acfd5cb 6468748 assertion failure in dnode_sync
ahrens
parents: 2926
diff changeset
  1121
		 */
4577
ed36b0e652bc PSARC/2007/328 zfs upgrade
ahrens
parents: 4543
diff changeset
  1122
		if (!zc->zc_objset_stats.dds_inconsistent) {
ed36b0e652bc PSARC/2007/328 zfs upgrade
ahrens
parents: 4543
diff changeset
  1123
			if (dmu_objset_type(os) == DMU_OST_ZVOL)
ed36b0e652bc PSARC/2007/328 zfs upgrade
ahrens
parents: 4543
diff changeset
  1124
				VERIFY(zvol_get_stats(os, nv) == 0);
ed36b0e652bc PSARC/2007/328 zfs upgrade
ahrens
parents: 4543
diff changeset
  1125
		}
2676
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  1126
		error = put_nvlist(zc, nv);
1356
e021b5e4aa0e 6377671 zfs mount -a shouldn't bother checking snapshots
eschrock
parents: 1354
diff changeset
  1127
		nvlist_free(nv);
e021b5e4aa0e 6377671 zfs mount -a shouldn't bother checking snapshots
eschrock
parents: 1354
diff changeset
  1128
	}
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1129
2676
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  1130
	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
  1131
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1132
	dmu_objset_close(os);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1133
	return (error);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1134
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1135
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1136
static int
5147
5e950ccc9585 6596190 "zfs list" is slow due to version property
rm160521
parents: 5118
diff changeset
  1137
zfs_ioc_objset_version(zfs_cmd_t *zc)
5e950ccc9585 6596190 "zfs list" is slow due to version property
rm160521
parents: 5118
diff changeset
  1138
{
5e950ccc9585 6596190 "zfs list" is slow due to version property
rm160521
parents: 5118
diff changeset
  1139
	objset_t *os = NULL;
5e950ccc9585 6596190 "zfs list" is slow due to version property
rm160521
parents: 5118
diff changeset
  1140
	int error;
5e950ccc9585 6596190 "zfs list" is slow due to version property
rm160521
parents: 5118
diff changeset
  1141
5e950ccc9585 6596190 "zfs list" is slow due to version property
rm160521
parents: 5118
diff changeset
  1142
retry:
5e950ccc9585 6596190 "zfs list" is slow due to version property
rm160521
parents: 5118
diff changeset
  1143
	error = dmu_objset_open(zc->zc_name, DMU_OST_ANY,
5e950ccc9585 6596190 "zfs list" is slow due to version property
rm160521
parents: 5118
diff changeset
  1144
	    DS_MODE_STANDARD | DS_MODE_READONLY, &os);
5e950ccc9585 6596190 "zfs list" is slow due to version property
rm160521
parents: 5118
diff changeset
  1145
	if (error != 0) {
5e950ccc9585 6596190 "zfs list" is slow due to version property
rm160521
parents: 5118
diff changeset
  1146
		/*
5e950ccc9585 6596190 "zfs list" is slow due to version property
rm160521
parents: 5118
diff changeset
  1147
		 * This is ugly: dmu_objset_open() can return EBUSY if
5e950ccc9585 6596190 "zfs list" is slow due to version property
rm160521
parents: 5118
diff changeset
  1148
		 * the objset is held exclusively. Fortunately this hold is
5e950ccc9585 6596190 "zfs list" is slow due to version property
rm160521
parents: 5118
diff changeset
  1149
		 * only for a short while, so we retry here.
5e950ccc9585 6596190 "zfs list" is slow due to version property
rm160521
parents: 5118
diff changeset
  1150
		 * This avoids user code having to handle EBUSY,
5e950ccc9585 6596190 "zfs list" is slow due to version property
rm160521
parents: 5118
diff changeset
  1151
		 * for example for a "zfs list".
5e950ccc9585 6596190 "zfs list" is slow due to version property
rm160521
parents: 5118
diff changeset
  1152
		 */
5e950ccc9585 6596190 "zfs list" is slow due to version property
rm160521
parents: 5118
diff changeset
  1153
		if (error == EBUSY) {
5e950ccc9585 6596190 "zfs list" is slow due to version property
rm160521
parents: 5118
diff changeset
  1154
			delay(1);
5e950ccc9585 6596190 "zfs list" is slow due to version property
rm160521
parents: 5118
diff changeset
  1155
			goto retry;
5e950ccc9585 6596190 "zfs list" is slow due to version property
rm160521
parents: 5118
diff changeset
  1156
		}
5e950ccc9585 6596190 "zfs list" is slow due to version property
rm160521
parents: 5118
diff changeset
  1157
		return (error);
5e950ccc9585 6596190 "zfs list" is slow due to version property
rm160521
parents: 5118
diff changeset
  1158
	}
5e950ccc9585 6596190 "zfs list" is slow due to version property
rm160521
parents: 5118
diff changeset
  1159
5e950ccc9585 6596190 "zfs list" is slow due to version property
rm160521
parents: 5118
diff changeset
  1160
	dmu_objset_fast_stat(os, &zc->zc_objset_stats);
5e950ccc9585 6596190 "zfs list" is slow due to version property
rm160521
parents: 5118
diff changeset
  1161
5e950ccc9585 6596190 "zfs list" is slow due to version property
rm160521
parents: 5118
diff changeset
  1162
	/*
5e950ccc9585 6596190 "zfs list" is slow due to version property
rm160521
parents: 5118
diff changeset
  1163
	 * NB: zfs_get_version() will read the objset contents,
5e950ccc9585 6596190 "zfs list" is slow due to version property
rm160521
parents: 5118
diff changeset
  1164
	 * which we aren't supposed to do with a
5e950ccc9585 6596190 "zfs list" is slow due to version property
rm160521
parents: 5118
diff changeset
  1165
	 * DS_MODE_STANDARD open, because it could be
5e950ccc9585 6596190 "zfs list" is slow due to version property
rm160521
parents: 5118
diff changeset
  1166
	 * inconsistent.  So this is a bit of a workaround...
5e950ccc9585 6596190 "zfs list" is slow due to version property
rm160521
parents: 5118
diff changeset
  1167
	 */
5e950ccc9585 6596190 "zfs list" is slow due to version property
rm160521
parents: 5118
diff changeset
  1168
	zc->zc_cookie = 0;
5e950ccc9585 6596190 "zfs list" is slow due to version property
rm160521
parents: 5118
diff changeset
  1169
	if (!zc->zc_objset_stats.dds_inconsistent)
5e950ccc9585 6596190 "zfs list" is slow due to version property
rm160521
parents: 5118
diff changeset
  1170
		if (dmu_objset_type(os) == DMU_OST_ZFS)
5e950ccc9585 6596190 "zfs list" is slow due to version property
rm160521
parents: 5118
diff changeset
  1171
			(void) zfs_get_version(os, &zc->zc_cookie);
5e950ccc9585 6596190 "zfs list" is slow due to version property
rm160521
parents: 5118
diff changeset
  1172
5e950ccc9585 6596190 "zfs list" is slow due to version property
rm160521
parents: 5118
diff changeset
  1173
	dmu_objset_close(os);
5e950ccc9585 6596190 "zfs list" is slow due to version property
rm160521
parents: 5118
diff changeset
  1174
	return (0);
5e950ccc9585 6596190 "zfs list" is slow due to version property
rm160521
parents: 5118
diff changeset
  1175
}
5e950ccc9585 6596190 "zfs list" is slow due to version property
rm160521
parents: 5118
diff changeset
  1176
5e950ccc9585 6596190 "zfs list" is slow due to version property
rm160521
parents: 5118
diff changeset
  1177
static int
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1178
zfs_ioc_dataset_list_next(zfs_cmd_t *zc)
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
	objset_t *os;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1181
	int error;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1182
	char *p;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1183
885
d925b21dba78 6347493 tar of 25K empty directory entries in ZFS takes 30+ seconds ...
ahrens
parents: 849
diff changeset
  1184
retry:
d925b21dba78 6347493 tar of 25K empty directory entries in ZFS takes 30+ seconds ...
ahrens
parents: 849
diff changeset
  1185
	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
  1186
	    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
  1187
	if (error != 0) {
d925b21dba78 6347493 tar of 25K empty directory entries in ZFS takes 30+ seconds ...
ahrens
parents: 849
diff changeset
  1188
		/*
d925b21dba78 6347493 tar of 25K empty directory entries in ZFS takes 30+ seconds ...
ahrens
parents: 849
diff changeset
  1189
		 * 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
  1190
		 * 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
  1191
		 * 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
  1192
		 * 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
  1193
		 * for example for a "zfs list".
d925b21dba78 6347493 tar of 25K empty directory entries in ZFS takes 30+ seconds ...
ahrens
parents: 849
diff changeset
  1194
		 */
d925b21dba78 6347493 tar of 25K empty directory entries in ZFS takes 30+ seconds ...
ahrens
parents: 849
diff changeset
  1195
		if (error == EBUSY) {
d925b21dba78 6347493 tar of 25K empty directory entries in ZFS takes 30+ seconds ...
ahrens
parents: 849
diff changeset
  1196
			delay(1);
d925b21dba78 6347493 tar of 25K empty directory entries in ZFS takes 30+ seconds ...
ahrens
parents: 849
diff changeset
  1197
			goto retry;
d925b21dba78 6347493 tar of 25K empty directory entries in ZFS takes 30+ seconds ...
ahrens
parents: 849
diff changeset
  1198
		}
d925b21dba78 6347493 tar of 25K empty directory entries in ZFS takes 30+ seconds ...
ahrens
parents: 849
diff changeset
  1199
		if (error == ENOENT)
d925b21dba78 6347493 tar of 25K empty directory entries in ZFS takes 30+ seconds ...
ahrens
parents: 849
diff changeset
  1200
			error = ESRCH;
d925b21dba78 6347493 tar of 25K empty directory entries in ZFS takes 30+ seconds ...
ahrens
parents: 849
diff changeset
  1201
		return (error);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1202
	}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1203
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1204
	p = strrchr(zc->zc_name, '/');
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1205
	if (p == NULL || p[1] != '\0')
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1206
		(void) strlcat(zc->zc_name, "/", sizeof (zc->zc_name));
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1207
	p = zc->zc_name + strlen(zc->zc_name);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1208
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1209
	do {
885
d925b21dba78 6347493 tar of 25K empty directory entries in ZFS takes 30+ seconds ...
ahrens
parents: 849
diff changeset
  1210
		error = dmu_dir_list_next(os,
d925b21dba78 6347493 tar of 25K empty directory entries in ZFS takes 30+ seconds ...
ahrens
parents: 849
diff changeset
  1211
		    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
  1212
		    NULL, &zc->zc_cookie);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1213
		if (error == ENOENT)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1214
			error = ESRCH;
885
d925b21dba78 6347493 tar of 25K empty directory entries in ZFS takes 30+ seconds ...
ahrens
parents: 849
diff changeset
  1215
	} while (error == 0 && !INGLOBALZONE(curproc) &&
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1216
	    !zone_dataset_visible(zc->zc_name, NULL));
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1217
885
d925b21dba78 6347493 tar of 25K empty directory entries in ZFS takes 30+ seconds ...
ahrens
parents: 849
diff changeset
  1218
	/*
d925b21dba78 6347493 tar of 25K empty directory entries in ZFS takes 30+ seconds ...
ahrens
parents: 849
diff changeset
  1219
	 * 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
  1220
	 * 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
  1221
	 */
d925b21dba78 6347493 tar of 25K empty directory entries in ZFS takes 30+ seconds ...
ahrens
parents: 849
diff changeset
  1222
	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
  1223
		error = zfs_ioc_objset_stats(zc); /* fill in the stats */
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1224
885
d925b21dba78 6347493 tar of 25K empty directory entries in ZFS takes 30+ seconds ...
ahrens
parents: 849
diff changeset
  1225
	dmu_objset_close(os);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1226
	return (error);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1227
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1228
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1229
static int
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1230
zfs_ioc_snapshot_list_next(zfs_cmd_t *zc)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1231
{
885
d925b21dba78 6347493 tar of 25K empty directory entries in ZFS takes 30+ seconds ...
ahrens
parents: 849
diff changeset
  1232
	objset_t *os;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1233
	int error;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1234
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1235
retry:
885
d925b21dba78 6347493 tar of 25K empty directory entries in ZFS takes 30+ seconds ...
ahrens
parents: 849
diff changeset
  1236
	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
  1237
	    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
  1238
	if (error != 0) {
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1239
		/*
885
d925b21dba78 6347493 tar of 25K empty directory entries in ZFS takes 30+ seconds ...
ahrens
parents: 849
diff changeset
  1240
		 * This is ugly: dmu_objset_open() can return EBUSY if
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1241
		 * the objset is held exclusively. Fortunately this hold is
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1242
		 * only for a short while, so we retry here.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1243
		 * 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
  1244
		 * for example for a "zfs list".
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1245
		 */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1246
		if (error == EBUSY) {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1247
			delay(1);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1248
			goto retry;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1249
		}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1250
		if (error == ENOENT)
885
d925b21dba78 6347493 tar of 25K empty directory entries in ZFS takes 30+ seconds ...
ahrens
parents: 849
diff changeset
  1251
			error = ESRCH;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1252
		return (error);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1253
	}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1254
1003
ce99098d6a9b 6350417 long name will cause rename a dataset panic
lling
parents: 885
diff changeset
  1255
	/*
ce99098d6a9b 6350417 long name will cause rename a dataset panic
lling
parents: 885
diff changeset
  1256
	 * 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
  1257
	 * so exit immediately.
ce99098d6a9b 6350417 long name will cause rename a dataset panic
lling
parents: 885
diff changeset
  1258
	 */
ce99098d6a9b 6350417 long name will cause rename a dataset panic
lling
parents: 885
diff changeset
  1259
	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
  1260
		dmu_objset_close(os);
1003
ce99098d6a9b 6350417 long name will cause rename a dataset panic
lling
parents: 885
diff changeset
  1261
		return (ESRCH);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1262
	}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1263
885
d925b21dba78 6347493 tar of 25K empty directory entries in ZFS takes 30+ seconds ...
ahrens
parents: 849
diff changeset
  1264
	error = dmu_snapshot_list_next(os,
d925b21dba78 6347493 tar of 25K empty directory entries in ZFS takes 30+ seconds ...
ahrens
parents: 849
diff changeset
  1265
	    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
  1266
	    zc->zc_name + strlen(zc->zc_name), NULL, &zc->zc_cookie);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1267
	if (error == ENOENT)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1268
		error = ESRCH;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1269
885
d925b21dba78 6347493 tar of 25K empty directory entries in ZFS takes 30+ seconds ...
ahrens
parents: 849
diff changeset
  1270
	if (error == 0)
d925b21dba78 6347493 tar of 25K empty directory entries in ZFS takes 30+ seconds ...
ahrens
parents: 849
diff changeset
  1271
		error = zfs_ioc_objset_stats(zc); /* fill in the stats */
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1272
885
d925b21dba78 6347493 tar of 25K empty directory entries in ZFS takes 30+ seconds ...
ahrens
parents: 849
diff changeset
  1273
	dmu_objset_close(os);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1274
	return (error);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1275
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1276
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1277
static int
4787
602d3f97842c 6393351 unique_* could be improved
ahrens
parents: 4720
diff changeset
  1278
zfs_set_prop_nvlist(const char *name, nvlist_t *nvl)
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1279
{
2676
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  1280
	nvpair_t *elem;
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  1281
	int error;
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  1282
	uint64_t intval;
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  1283
	char *strval;
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  1284
4543
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  1285
	/*
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  1286
	 * First validate permission to set all of the properties
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  1287
	 */
2676
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  1288
	elem = NULL;
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  1289
	while ((elem = nvlist_next_nvpair(nvl, elem)) != NULL) {
4670
002728040e28 6580745 "zfs inherit" can be executed by ordinary user
ahrens
parents: 4611
diff changeset
  1290
		const char *propname = nvpair_name(elem);
002728040e28 6580745 "zfs inherit" can be executed by ordinary user
ahrens
parents: 4611
diff changeset
  1291
		zfs_prop_t prop = zfs_name_to_prop(propname);
2676
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  1292
5094
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
  1293
		if (prop == ZPROP_INVAL) {
2676
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  1294
			/*
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  1295
			 * If this is a user-defined property, it must be a
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  1296
			 * string, and there is no further validation to do.
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  1297
			 */
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  1298
			if (!zfs_prop_user(propname) ||
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  1299
			    nvpair_type(elem) != DATA_TYPE_STRING)
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  1300
				return (EINVAL);
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  1301
5331
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
  1302
			if (error = zfs_secpolicy_write_perms(name,
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
  1303
			    ZFS_DELEG_PERM_USERPROP, CRED()))
4670
002728040e28 6580745 "zfs inherit" can be executed by ordinary user
ahrens
parents: 4611
diff changeset
  1304
				return (error);
4543
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  1305
			continue;
2676
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  1306
		}
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  1307
4787
602d3f97842c 6393351 unique_* could be improved
ahrens
parents: 4720
diff changeset
  1308
		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
  1309
			return (error);
2676
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  1310
4670
002728040e28 6580745 "zfs inherit" can be executed by ordinary user
ahrens
parents: 4611
diff changeset
  1311
		/*
002728040e28 6580745 "zfs inherit" can be executed by ordinary user
ahrens
parents: 4611
diff changeset
  1312
		 * 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
  1313
		 */
002728040e28 6580745 "zfs inherit" can be executed by ordinary user
ahrens
parents: 4611
diff changeset
  1314
		switch (prop) {
3886
3291401d66a6 6536602 add zlib compression support and upgrade to version 1.2.3
ahl
parents: 3863
diff changeset
  1315
		case ZFS_PROP_COMPRESSION:
3291401d66a6 6536602 add zlib compression support and upgrade to version 1.2.3
ahl
parents: 3863
diff changeset
  1316
			/*
3291401d66a6 6536602 add zlib compression support and upgrade to version 1.2.3
ahl
parents: 3863
diff changeset
  1317
			 * 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
  1318
			 * 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
  1319
			 * we'll catch them later.
3291401d66a6 6536602 add zlib compression support and upgrade to version 1.2.3
ahl
parents: 3863
diff changeset
  1320
			 */
3291401d66a6 6536602 add zlib compression support and upgrade to version 1.2.3
ahl
parents: 3863
diff changeset
  1321
			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
  1322
			    nvpair_value_uint64(elem, &intval) == 0 &&
3291401d66a6 6536602 add zlib compression support and upgrade to version 1.2.3
ahl
parents: 3863
diff changeset
  1323
			    intval >= ZIO_COMPRESS_GZIP_1 &&
3291401d66a6 6536602 add zlib compression support and upgrade to version 1.2.3
ahl
parents: 3863
diff changeset
  1324
			    intval <= ZIO_COMPRESS_GZIP_9) {
5331
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
  1325
				if (zfs_check_version(name,
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
  1326
				    SPA_VERSION_GZIP_COMPRESSION))
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
  1327
					return (ENOTSUP);
3886
3291401d66a6 6536602 add zlib compression support and upgrade to version 1.2.3
ahl
parents: 3863
diff changeset
  1328
			}
3291401d66a6 6536602 add zlib compression support and upgrade to version 1.2.3
ahl
parents: 3863
diff changeset
  1329
			break;
4603
c7840c367d00 6494569 zfs recv -d pool/<doesn't exist> core dumps for top-level filesystem backups
ahrens
parents: 4577
diff changeset
  1330
c7840c367d00 6494569 zfs recv -d pool/<doesn't exist> core dumps for top-level filesystem backups
ahrens
parents: 4577
diff changeset
  1331
		case ZFS_PROP_COPIES:
5331
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
  1332
			if (zfs_check_version(name, SPA_VERSION_DITTO_BLOCKS))
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
  1333
				return (ENOTSUP);
4603
c7840c367d00 6494569 zfs recv -d pool/<doesn't exist> core dumps for top-level filesystem backups
ahrens
parents: 4577
diff changeset
  1334
			break;
5331
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
  1335
		case ZFS_PROP_NORMALIZE:
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
  1336
		case ZFS_PROP_UTF8ONLY:
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
  1337
		case ZFS_PROP_CASE:
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
  1338
			if (zfs_check_version(name, SPA_VERSION_NORMALIZATION))
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
  1339
				return (ENOTSUP);
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
  1340
4603
c7840c367d00 6494569 zfs recv -d pool/<doesn't exist> core dumps for top-level filesystem backups
ahrens
parents: 4577
diff changeset
  1341
		}
5331
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
  1342
		if ((error = zfs_secpolicy_setprop(name, prop, CRED())) != 0)
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
  1343
			return (error);
4543
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  1344
	}
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  1345
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  1346
	elem = NULL;
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  1347
	while ((elem = nvlist_next_nvpair(nvl, elem)) != NULL) {
4670
002728040e28 6580745 "zfs inherit" can be executed by ordinary user
ahrens
parents: 4611
diff changeset
  1348
		const char *propname = nvpair_name(elem);
002728040e28 6580745 "zfs inherit" can be executed by ordinary user
ahrens
parents: 4611
diff changeset
  1349
		zfs_prop_t prop = zfs_name_to_prop(propname);
4543
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  1350
5094
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
  1351
		if (prop == ZPROP_INVAL) {
4543
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  1352
			VERIFY(nvpair_value_string(elem, &strval) == 0);
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  1353
			error = dsl_prop_set(name, propname, 1,
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  1354
			    strlen(strval) + 1, strval);
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  1355
			if (error == 0)
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  1356
				continue;
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  1357
			else
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  1358
				return (error);
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  1359
		}
2676
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  1360
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  1361
		switch (prop) {
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  1362
		case ZFS_PROP_QUOTA:
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  1363
			if ((error = nvpair_value_uint64(elem, &intval)) != 0 ||
4577
ed36b0e652bc PSARC/2007/328 zfs upgrade
ahrens
parents: 4543
diff changeset
  1364
			    (error = dsl_dir_set_quota(name, intval)) != 0)
2676
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  1365
				return (error);
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  1366
			break;
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  1367
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  1368
		case ZFS_PROP_RESERVATION:
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  1369
			if ((error = nvpair_value_uint64(elem, &intval)) != 0 ||
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  1370
			    (error = dsl_dir_set_reservation(name,
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  1371
			    intval)) != 0)
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  1372
				return (error);
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  1373
			break;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1374
2676
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  1375
		case ZFS_PROP_VOLSIZE:
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  1376
			if ((error = nvpair_value_uint64(elem, &intval)) != 0 ||
4787
602d3f97842c 6393351 unique_* could be improved
ahrens
parents: 4720
diff changeset
  1377
			    (error = zvol_set_volsize(name,
602d3f97842c 6393351 unique_* could be improved
ahrens
parents: 4720
diff changeset
  1378
			    ddi_driver_major(zfs_dip), intval)) != 0)
2676
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  1379
				return (error);
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  1380
			break;
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
		case ZFS_PROP_VOLBLOCKSIZE:
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  1383
			if ((error = nvpair_value_uint64(elem, &intval)) != 0 ||
4577
ed36b0e652bc PSARC/2007/328 zfs upgrade
ahrens
parents: 4543
diff changeset
  1384
			    (error = zvol_set_volblocksize(name, intval)) != 0)
ed36b0e652bc PSARC/2007/328 zfs upgrade
ahrens
parents: 4543
diff changeset
  1385
				return (error);
ed36b0e652bc PSARC/2007/328 zfs upgrade
ahrens
parents: 4543
diff changeset
  1386
			break;
ed36b0e652bc PSARC/2007/328 zfs upgrade
ahrens
parents: 4543
diff changeset
  1387
ed36b0e652bc PSARC/2007/328 zfs upgrade
ahrens
parents: 4543
diff changeset
  1388
		case ZFS_PROP_VERSION:
ed36b0e652bc PSARC/2007/328 zfs upgrade
ahrens
parents: 4543
diff changeset
  1389
			if ((error = nvpair_value_uint64(elem, &intval)) != 0 ||
ed36b0e652bc PSARC/2007/328 zfs upgrade
ahrens
parents: 4543
diff changeset
  1390
			    (error = zfs_set_version(name, intval)) != 0)
2676
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  1391
				return (error);
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  1392
			break;
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  1393
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  1394
		default:
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  1395
			if (nvpair_type(elem) == DATA_TYPE_STRING) {
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  1396
				if (zfs_prop_get_type(prop) !=
4787
602d3f97842c 6393351 unique_* could be improved
ahrens
parents: 4720
diff changeset
  1397
				    PROP_TYPE_STRING)
2676
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  1398
					return (EINVAL);
2717
ed589a32259d 6469385 zfs_set_prop_nvlist range checking is busted
eschrock
parents: 2676
diff changeset
  1399
				VERIFY(nvpair_value_string(elem, &strval) == 0);
ed589a32259d 6469385 zfs_set_prop_nvlist range checking is busted
eschrock
parents: 2676
diff changeset
  1400
				if ((error = dsl_prop_set(name,
2676
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  1401
				    nvpair_name(elem), 1, strlen(strval) + 1,
2717
ed589a32259d 6469385 zfs_set_prop_nvlist range checking is busted
eschrock
parents: 2676
diff changeset
  1402
				    strval)) != 0)
ed589a32259d 6469385 zfs_set_prop_nvlist range checking is busted
eschrock
parents: 2676
diff changeset
  1403
					return (error);
2676
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  1404
			} else if (nvpair_type(elem) == DATA_TYPE_UINT64) {
2885
c0259887ebbc 6460059 zfs destroy <snapshot> leaves behind kruft
ahrens
parents: 2856
diff changeset
  1405
				const char *unused;
c0259887ebbc 6460059 zfs destroy <snapshot> leaves behind kruft
ahrens
parents: 2856
diff changeset
  1406
2717
ed589a32259d 6469385 zfs_set_prop_nvlist range checking is busted
eschrock
parents: 2676
diff changeset
  1407
				VERIFY(nvpair_value_uint64(elem, &intval) == 0);
2676
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  1408
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  1409
				switch (zfs_prop_get_type(prop)) {
4787
602d3f97842c 6393351 unique_* could be improved
ahrens
parents: 4720
diff changeset
  1410
				case PROP_TYPE_NUMBER:
2676
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  1411
					break;
4787
602d3f97842c 6393351 unique_* could be improved
ahrens
parents: 4720
diff changeset
  1412
				case PROP_TYPE_STRING:
2717
ed589a32259d 6469385 zfs_set_prop_nvlist range checking is busted
eschrock
parents: 2676
diff changeset
  1413
					return (EINVAL);
4787
602d3f97842c 6393351 unique_* could be improved
ahrens
parents: 4720
diff changeset
  1414
				case PROP_TYPE_INDEX:
2717
ed589a32259d 6469385 zfs_set_prop_nvlist range checking is busted
eschrock
parents: 2676
diff changeset
  1415
					if (zfs_prop_index_to_string(prop,
ed589a32259d 6469385 zfs_set_prop_nvlist range checking is busted
eschrock
parents: 2676
diff changeset
  1416
					    intval, &unused) != 0)
ed589a32259d 6469385 zfs_set_prop_nvlist range checking is busted
eschrock
parents: 2676
diff changeset
  1417
						return (EINVAL);
2676
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  1418
					break;
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  1419
				default:
4577
ed36b0e652bc PSARC/2007/328 zfs upgrade
ahrens
parents: 4543
diff changeset
  1420
					cmn_err(CE_PANIC,
ed36b0e652bc PSARC/2007/328 zfs upgrade
ahrens
parents: 4543
diff changeset
  1421
					    "unknown property type");
2676
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  1422
					break;
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  1423
				}
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  1424
2717
ed589a32259d 6469385 zfs_set_prop_nvlist range checking is busted
eschrock
parents: 2676
diff changeset
  1425
				if ((error = dsl_prop_set(name, propname,
ed589a32259d 6469385 zfs_set_prop_nvlist range checking is busted
eschrock
parents: 2676
diff changeset
  1426
				    8, 1, &intval)) != 0)
ed589a32259d 6469385 zfs_set_prop_nvlist range checking is busted
eschrock
parents: 2676
diff changeset
  1427
					return (error);
2676
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  1428
			} else {
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  1429
				return (EINVAL);
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  1430
			}
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  1431
			break;
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  1432
		}
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  1433
	}
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  1434
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  1435
	return (0);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1436
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1437
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1438
static int
2676
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  1439
zfs_ioc_set_prop(zfs_cmd_t *zc)
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1440
{
2676
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  1441
	nvlist_t *nvl;
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  1442
	int error;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1443
5094
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
  1444
	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
  1445
	    &nvl)) != 0)
2676
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  1446
		return (error);
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  1447
4787
602d3f97842c 6393351 unique_* could be improved
ahrens
parents: 4720
diff changeset
  1448
	error = zfs_set_prop_nvlist(zc->zc_name, nvl);
4543
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  1449
2676
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  1450
	nvlist_free(nvl);
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  1451
	return (error);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1452
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1453
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1454
static int
4849
3a61e0a9a953 6536043 arc_byteswap_func_t and dmu_byteswap_func_t are redundant
ahrens
parents: 4808
diff changeset
  1455
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
  1456
{
3a61e0a9a953 6536043 arc_byteswap_func_t and dmu_byteswap_func_t are redundant
ahrens
parents: 4808
diff changeset
  1457
	/* 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
  1458
	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
  1459
}
3a61e0a9a953 6536043 arc_byteswap_func_t and dmu_byteswap_func_t are redundant
ahrens
parents: 4808
diff changeset
  1460
3a61e0a9a953 6536043 arc_byteswap_func_t and dmu_byteswap_func_t are redundant
ahrens
parents: 4808
diff changeset
  1461
static int
4098
0a182c2128e6 6545726 make ZFS_IOC_POOL_*_PROPS in sync with zfs_ioc_pool_props_*
lling
parents: 4007
diff changeset
  1462
zfs_ioc_pool_set_props(zfs_cmd_t *zc)
3912
f6891a60bd72 PSARC 2007/083 ZFS bootable datasets
lling
parents: 3886
diff changeset
  1463
{
5094
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
  1464
	nvlist_t *props;
3912
f6891a60bd72 PSARC 2007/083 ZFS bootable datasets
lling
parents: 3886
diff changeset
  1465
	spa_t *spa;
5094
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
  1466
	int error;
3912
f6891a60bd72 PSARC 2007/083 ZFS bootable datasets
lling
parents: 3886
diff changeset
  1467
5094
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
  1468
	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
  1469
	    &props)))
3912
f6891a60bd72 PSARC 2007/083 ZFS bootable datasets
lling
parents: 3886
diff changeset
  1470
		return (error);
f6891a60bd72 PSARC 2007/083 ZFS bootable datasets
lling
parents: 3886
diff changeset
  1471
f6891a60bd72 PSARC 2007/083 ZFS bootable datasets
lling
parents: 3886
diff changeset
  1472
	if ((error = spa_open(zc->zc_name, &spa, FTAG)) != 0) {
5094
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
  1473
		nvlist_free(props);
3912
f6891a60bd72 PSARC 2007/083 ZFS bootable datasets
lling
parents: 3886
diff changeset
  1474
		return (error);
f6891a60bd72 PSARC 2007/083 ZFS bootable datasets
lling
parents: 3886
diff changeset
  1475
	}
f6891a60bd72 PSARC 2007/083 ZFS bootable datasets
lling
parents: 3886
diff changeset
  1476
5094
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
  1477
	error = spa_prop_set(spa, props);
3912
f6891a60bd72 PSARC 2007/083 ZFS bootable datasets
lling
parents: 3886
diff changeset
  1478
5094
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
  1479
	nvlist_free(props);
3912
f6891a60bd72 PSARC 2007/083 ZFS bootable datasets
lling
parents: 3886
diff changeset
  1480
	spa_close(spa, FTAG);
f6891a60bd72 PSARC 2007/083 ZFS bootable datasets
lling
parents: 3886
diff changeset
  1481
f6891a60bd72 PSARC 2007/083 ZFS bootable datasets
lling
parents: 3886
diff changeset
  1482
	return (error);
f6891a60bd72 PSARC 2007/083 ZFS bootable datasets
lling
parents: 3886
diff changeset
  1483
}
f6891a60bd72 PSARC 2007/083 ZFS bootable datasets
lling
parents: 3886
diff changeset
  1484
f6891a60bd72 PSARC 2007/083 ZFS bootable datasets
lling
parents: 3886
diff changeset
  1485
static int
4098
0a182c2128e6 6545726 make ZFS_IOC_POOL_*_PROPS in sync with zfs_ioc_pool_props_*
lling
parents: 4007
diff changeset
  1486
zfs_ioc_pool_get_props(zfs_cmd_t *zc)
3912
f6891a60bd72 PSARC 2007/083 ZFS bootable datasets
lling
parents: 3886
diff changeset
  1487
{
f6891a60bd72 PSARC 2007/083 ZFS bootable datasets
lling
parents: 3886
diff changeset
  1488
	spa_t *spa;
f6891a60bd72 PSARC 2007/083 ZFS bootable datasets
lling
parents: 3886
diff changeset
  1489
	int error;
f6891a60bd72 PSARC 2007/083 ZFS bootable datasets
lling
parents: 3886
diff changeset
  1490
	nvlist_t *nvp = NULL;
f6891a60bd72 PSARC 2007/083 ZFS bootable datasets
lling
parents: 3886
diff changeset
  1491
f6891a60bd72 PSARC 2007/083 ZFS bootable datasets
lling
parents: 3886
diff changeset
  1492
	if ((error = spa_open(zc->zc_name, &spa, FTAG)) != 0)
f6891a60bd72 PSARC 2007/083 ZFS bootable datasets
lling
parents: 3886
diff changeset
  1493
		return (error);
f6891a60bd72 PSARC 2007/083 ZFS bootable datasets
lling
parents: 3886
diff changeset
  1494
5094
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
  1495
	error = spa_prop_get(spa, &nvp);
3912
f6891a60bd72 PSARC 2007/083 ZFS bootable datasets
lling
parents: 3886
diff changeset
  1496
f6891a60bd72 PSARC 2007/083 ZFS bootable datasets
lling
parents: 3886
diff changeset
  1497
	if (error == 0 && zc->zc_nvlist_dst != NULL)
f6891a60bd72 PSARC 2007/083 ZFS bootable datasets
lling
parents: 3886
diff changeset
  1498
		error = put_nvlist(zc, nvp);
f6891a60bd72 PSARC 2007/083 ZFS bootable datasets
lling
parents: 3886
diff changeset
  1499
	else
f6891a60bd72 PSARC 2007/083 ZFS bootable datasets
lling
parents: 3886
diff changeset
  1500
		error = EFAULT;
f6891a60bd72 PSARC 2007/083 ZFS bootable datasets
lling
parents: 3886
diff changeset
  1501
f6891a60bd72 PSARC 2007/083 ZFS bootable datasets
lling
parents: 3886
diff changeset
  1502
	spa_close(spa, FTAG);
f6891a60bd72 PSARC 2007/083 ZFS bootable datasets
lling
parents: 3886
diff changeset
  1503
f6891a60bd72 PSARC 2007/083 ZFS bootable datasets
lling
parents: 3886
diff changeset
  1504
	if (nvp)
f6891a60bd72 PSARC 2007/083 ZFS bootable datasets
lling
parents: 3886
diff changeset
  1505
		nvlist_free(nvp);
f6891a60bd72 PSARC 2007/083 ZFS bootable datasets
lling
parents: 3886
diff changeset
  1506
	return (error);
f6891a60bd72 PSARC 2007/083 ZFS bootable datasets
lling
parents: 3886
diff changeset
  1507
}
f6891a60bd72 PSARC 2007/083 ZFS bootable datasets
lling
parents: 3886
diff changeset
  1508
f6891a60bd72 PSARC 2007/083 ZFS bootable datasets
lling
parents: 3886
diff changeset
  1509
static int
4543
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  1510
zfs_ioc_iscsi_perm_check(zfs_cmd_t *zc)
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  1511
{
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  1512
	nvlist_t *nvp;
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  1513
	int error;
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  1514
	uint32_t uid;
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  1515
	uint32_t gid;
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  1516
	uint32_t *groups;
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  1517
	uint_t group_cnt;
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  1518
	cred_t	*usercred;
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  1519
5094
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
  1520
	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
  1521
	    &nvp)) != 0) {
4543
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  1522
		return (error);
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
	if ((error = nvlist_lookup_uint32(nvp,
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  1526
	    ZFS_DELEG_PERM_UID, &uid)) != 0) {
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  1527
		nvlist_free(nvp);
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  1528
		return (EPERM);
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
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  1531
	if ((error = nvlist_lookup_uint32(nvp,
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  1532
	    ZFS_DELEG_PERM_GID, &gid)) != 0) {
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  1533
		nvlist_free(nvp);
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  1534
		return (EPERM);
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  1535
	}
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  1536
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  1537
	if ((error = nvlist_lookup_uint32_array(nvp, ZFS_DELEG_PERM_GROUPS,
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  1538
	    &groups, &group_cnt)) != 0) {
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  1539
		nvlist_free(nvp);
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  1540
		return (EPERM);
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
	usercred = cralloc();
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  1543
	if ((crsetugid(usercred, uid, gid) != 0) ||
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  1544
	    (crsetgroups(usercred, group_cnt, (gid_t *)groups) != 0)) {
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  1545
		nvlist_free(nvp);
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  1546
		crfree(usercred);
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  1547
		return (EPERM);
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
	nvlist_free(nvp);
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  1550
	error = dsl_deleg_access(zc->zc_name,
4787
602d3f97842c 6393351 unique_* could be improved
ahrens
parents: 4720
diff changeset
  1551
	    zfs_prop_to_name(ZFS_PROP_SHAREISCSI), usercred);
4543
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  1552
	crfree(usercred);
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  1553
	return (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
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  1556
static int
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  1557
zfs_ioc_set_fsacl(zfs_cmd_t *zc)
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
	int error;
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  1560
	nvlist_t *fsaclnv = NULL;
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  1561
5094
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
  1562
	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
  1563
	    &fsaclnv)) != 0)
4543
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  1564
		return (error);
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  1565
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  1566
	/*
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  1567
	 * Verify nvlist is constructed correctly
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  1568
	 */
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  1569
	if ((error = zfs_deleg_verify_nvlist(fsaclnv)) != 0) {
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  1570
		nvlist_free(fsaclnv);
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  1571
		return (EINVAL);
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  1572
	}
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  1573
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  1574
	/*
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  1575
	 * If we don't have PRIV_SYS_MOUNT, then validate
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  1576
	 * that user is allowed to hand out each permission in
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  1577
	 * the nvlist(s)
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  1578
	 */
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  1579
4787
602d3f97842c 6393351 unique_* could be improved
ahrens
parents: 4720
diff changeset
  1580
	error = secpolicy_zfs(CRED());
4543
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  1581
	if (error) {
4787
602d3f97842c 6393351 unique_* could be improved
ahrens
parents: 4720
diff changeset
  1582
		if (zc->zc_perm_action == B_FALSE) {
602d3f97842c 6393351 unique_* could be improved
ahrens
parents: 4720
diff changeset
  1583
			error = dsl_deleg_can_allow(zc->zc_name,
602d3f97842c 6393351 unique_* could be improved
ahrens
parents: 4720
diff changeset
  1584
			    fsaclnv, CRED());
602d3f97842c 6393351 unique_* could be improved
ahrens
parents: 4720
diff changeset
  1585
		} else {
602d3f97842c 6393351 unique_* could be improved
ahrens
parents: 4720
diff changeset
  1586
			error = dsl_deleg_can_unallow(zc->zc_name,
602d3f97842c 6393351 unique_* could be improved
ahrens
parents: 4720
diff changeset
  1587
			    fsaclnv, CRED());
602d3f97842c 6393351 unique_* could be improved
ahrens
parents: 4720
diff changeset
  1588
		}
4543
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  1589
	}
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  1590
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  1591
	if (error == 0)
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  1592
		error = dsl_deleg_set(zc->zc_name, fsaclnv, zc->zc_perm_action);
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  1593
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  1594
	nvlist_free(fsaclnv);
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  1595
	return (error);
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  1596
}
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  1597
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  1598
static int
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  1599
zfs_ioc_get_fsacl(zfs_cmd_t *zc)
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  1600
{
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  1601
	nvlist_t *nvp;
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  1602
	int error;
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  1603
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  1604
	if ((error = dsl_deleg_get(zc->zc_name, &nvp)) == 0) {
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  1605
		error = put_nvlist(zc, nvp);
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  1606
		nvlist_free(nvp);
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  1607
	}
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  1608
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  1609
	return (error);
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  1610
}
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  1611
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  1612
static int
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1613
zfs_ioc_create_minor(zfs_cmd_t *zc)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1614
{
4787
602d3f97842c 6393351 unique_* could be improved
ahrens
parents: 4720
diff changeset
  1615
	return (zvol_create_minor(zc->zc_name, ddi_driver_major(zfs_dip)));
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1616
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1617
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1618
static int
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1619
zfs_ioc_remove_minor(zfs_cmd_t *zc)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1620
{
2676
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  1621
	return (zvol_remove_minor(zc->zc_name));
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1622
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1623
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1624
/*
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1625
 * Search the vfs list for a specified resource.  Returns a pointer to it
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1626
 * or NULL if no suitable entry is found. The caller of this routine
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1627
 * is responsible for releasing the returned vfs pointer.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1628
 */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1629
static vfs_t *
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1630
zfs_get_vfs(const char *resource)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1631
{
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1632
	struct vfs *vfsp;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1633
	struct vfs *vfs_found = NULL;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1634
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1635
	vfs_list_read_lock();
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1636
	vfsp = rootvfs;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1637
	do {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1638
		if (strcmp(refstr_value(vfsp->vfs_resource), resource) == 0) {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1639
			VFS_HOLD(vfsp);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1640
			vfs_found = vfsp;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1641
			break;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1642
		}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1643
		vfsp = vfsp->vfs_next;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1644
	} while (vfsp != rootvfs);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1645
	vfs_list_unlock();
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1646
	return (vfs_found);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1647
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1648
4543
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  1649
/* ARGSUSED */
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1650
static void
4543
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  1651
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
  1652
{
5331
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
  1653
	zfs_creat_t *zct = arg;
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
  1654
	uint64_t version;
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
  1655
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
  1656
	if (spa_version(dmu_objset_spa(os)) >= SPA_VERSION_FUID)
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
  1657
		version = ZPL_VERSION;
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
  1658
	else
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
  1659
		version = ZPL_VERSION_FUID - 1;
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
  1660
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
  1661
	(void) nvlist_lookup_uint64(zct->zct_props,
4577
ed36b0e652bc PSARC/2007/328 zfs upgrade
ahrens
parents: 4543
diff changeset
  1662
	    zfs_prop_to_name(ZFS_PROP_VERSION), &version);
ed36b0e652bc PSARC/2007/328 zfs upgrade
ahrens
parents: 4543
diff changeset
  1663
5331
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
  1664
	zfs_create_fs(os, cr, version, zct->zct_norm, tx);
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
  1665
}
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
  1666
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
  1667
/*
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
  1668
 * zfs_prop_lookup()
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
  1669
 *
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
  1670
 * Look for the property first in the existing property nvlist.  If
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
  1671
 * it's already present, you're done.  If it's not there, attempt to
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
  1672
 * find the property value from a parent dataset.  If that fails, fall
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
  1673
 * back to the property's default value.  In either of these two
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
  1674
 * cases, if update is TRUE, add a value for the property to the
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
  1675
 * property nvlist.
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
  1676
 *
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
  1677
 * If the rval pointer is non-NULL, copy the discovered value to rval.
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
  1678
 *
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
  1679
 * If we get any unexpected errors, bail and return the error number
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
  1680
 * to the caller.
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
  1681
 *
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
  1682
 * If we succeed, return 0.
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
  1683
 */
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
  1684
static int
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
  1685
zfs_prop_lookup(const char *parentname, zfs_prop_t propnum,
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
  1686
    nvlist_t *proplist, uint64_t *rval, boolean_t update)
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
  1687
{
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
  1688
	const char *propname;
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
  1689
	uint64_t value;
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
  1690
	int error = ENOENT;
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
  1691
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
  1692
	propname = zfs_prop_to_name(propnum);
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
  1693
	if (proplist != NULL)
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
  1694
		error = nvlist_lookup_uint64(proplist, propname, &value);
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
  1695
	if (error == ENOENT) {
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
  1696
		error = dsl_prop_get_integer(parentname, propname,
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
  1697
		    &value, NULL);
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
  1698
		if (error == ENOENT)
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
  1699
			value = zfs_prop_default_numeric(propnum);
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
  1700
		else if (error != 0)
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
  1701
			return (error);
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
  1702
		if (update) {
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
  1703
			ASSERT(proplist != NULL);
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
  1704
			error = nvlist_add_uint64(proplist, propname, value);
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
  1705
		}
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
  1706
	}
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
  1707
	if (error == 0 && rval)
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
  1708
		*rval = value;
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
  1709
	return (error);
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
  1710
}
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
  1711
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
  1712
/*
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
  1713
 * zfs_normalization_get
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
  1714
 *
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
  1715
 * Get the normalization flag value.  If the properties have
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
  1716
 * non-default values, make sure the pool version is recent enough to
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
  1717
 * support these choices.
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
  1718
 */
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
  1719
static int
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
  1720
zfs_normalization_get(const char *dataset, nvlist_t *proplist, int *norm,
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
  1721
    boolean_t update)
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
  1722
{
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
  1723
	char parentname[MAXNAMELEN];
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
  1724
	char poolname[MAXNAMELEN];
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
  1725
	char *cp;
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
  1726
	uint64_t value;
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
  1727
	int check = 0;
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
  1728
	int error;
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
  1729
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
  1730
	ASSERT(norm != NULL);
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
  1731
	*norm = 0;
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
  1732
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
  1733
	(void) strncpy(parentname, dataset, sizeof (parentname));
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
  1734
	cp = strrchr(parentname, '@');
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
  1735
	if (cp != NULL) {
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
  1736
		cp[0] = '\0';
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
  1737
	} else {
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
  1738
		cp = strrchr(parentname, '/');
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
  1739
		if (cp == NULL)
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
  1740
			return (ENOENT);
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
  1741
		cp[0] = '\0';
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
  1742
	}
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
  1743
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
  1744
	(void) strncpy(poolname, dataset, sizeof (poolname));
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
  1745
	cp = strchr(poolname, '/');
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
  1746
	if (cp != NULL)
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
  1747
		cp[0] = '\0';
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
  1748
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
  1749
	error = zfs_prop_lookup(parentname, ZFS_PROP_UTF8ONLY,
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
  1750
	    proplist, &value, update);
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
  1751
	if (error != 0)
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
  1752
		return (error);
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
  1753
	if (value != zfs_prop_default_numeric(ZFS_PROP_UTF8ONLY))
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
  1754
		check = 1;
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
  1755
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
  1756
	error = zfs_prop_lookup(parentname, ZFS_PROP_NORMALIZE,
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
  1757
	    proplist, &value, update);
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
  1758
	if (error != 0)
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
  1759
		return (error);
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
  1760
	if (value != zfs_prop_default_numeric(ZFS_PROP_NORMALIZE)) {
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
  1761
		check = 1;
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
  1762
		switch ((int)value) {
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
  1763
		case ZFS_NORMALIZE_NONE:
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
  1764
			break;
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
  1765
		case ZFS_NORMALIZE_C:
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
  1766
			*norm |= U8_TEXTPREP_NFC;
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
  1767
			break;
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
  1768
		case ZFS_NORMALIZE_D:
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
  1769
			*norm |= U8_TEXTPREP_NFD;
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
  1770
			break;
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
  1771
		case ZFS_NORMALIZE_KC:
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
  1772
			*norm |= U8_TEXTPREP_NFKC;
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
  1773
			break;
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
  1774
		case ZFS_NORMALIZE_KD:
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
  1775
			*norm |= U8_TEXTPREP_NFKD;
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
  1776
			break;
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
  1777
		default:
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
  1778
			ASSERT((int)value >= ZFS_NORMALIZE_NONE);
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
  1779
			ASSERT((int)value <= ZFS_NORMALIZE_KD);
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
  1780
			break;
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
  1781
		}
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
  1782
	}
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
  1783
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
  1784
	error = zfs_prop_lookup(parentname, ZFS_PROP_CASE,
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
  1785
	    proplist, &value, update);
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
  1786
	if (error != 0)
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
  1787
		return (error);
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
  1788
	if (value != zfs_prop_default_numeric(ZFS_PROP_CASE)) {
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
  1789
		check = 1;
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
  1790
		switch ((int)value) {
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
  1791
		case ZFS_CASE_SENSITIVE:
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
  1792
			break;
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
  1793
		case ZFS_CASE_INSENSITIVE:
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
  1794
			*norm |= U8_TEXTPREP_TOUPPER;
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
  1795
			break;
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
  1796
		case ZFS_CASE_MIXED:
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
  1797
			*norm |= U8_TEXTPREP_TOUPPER;
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
  1798
			break;
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
  1799
		default:
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
  1800
			ASSERT((int)value >= ZFS_CASE_SENSITIVE);
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
  1801
			ASSERT((int)value <= ZFS_CASE_MIXED);
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
  1802
			break;
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
  1803
		}
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
  1804
	}
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
  1805
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
  1806
	if (check == 1)
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
  1807
		if (zfs_check_version(poolname, SPA_VERSION_NORMALIZATION))
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
  1808
			return (ENOTSUP);
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
  1809
	return (0);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1810
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1811
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1812
static int
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1813
zfs_ioc_create(zfs_cmd_t *zc)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1814
{
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1815
	objset_t *clone;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1816
	int error = 0;
5331
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
  1817
	zfs_creat_t zct;
4543
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  1818
	nvlist_t *nvprops = NULL;
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  1819
	void (*cbfunc)(objset_t *os, void *arg, cred_t *cr, dmu_tx_t *tx);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1820
	dmu_objset_type_t type = zc->zc_objset_type;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1821
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1822
	switch (type) {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1823
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1824
	case DMU_OST_ZFS:
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1825
		cbfunc = zfs_create_cb;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1826
		break;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1827
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1828
	case DMU_OST_ZVOL:
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1829
		cbfunc = zvol_create_cb;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1830
		break;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1831
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1832
	default:
2199
712a788c2dfd PSARC 2006/388 snapshot -r
ahrens
parents: 2082
diff changeset
  1833
		cbfunc = NULL;
712a788c2dfd PSARC 2006/388 snapshot -r
ahrens
parents: 2082
diff changeset
  1834
	}
5326
6752aa2bd5bc 6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents: 5147
diff changeset
  1835
	if (strchr(zc->zc_name, '@') ||
6752aa2bd5bc 6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents: 5147
diff changeset
  1836
	    strchr(zc->zc_name, '%'))
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1837
		return (EINVAL);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1838
2676
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  1839
	if (zc->zc_nvlist_src != NULL &&
5094
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
  1840
	    (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
  1841
	    &nvprops)) != 0)
2676
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  1842
		return (error);
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  1843
5331
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
  1844
	zct.zct_norm = 0;
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
  1845
	zct.zct_props = nvprops;
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
  1846
2676
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  1847
	if (zc->zc_value[0] != '\0') {
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1848
		/*
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1849
		 * We're creating a clone of an existing snapshot.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1850
		 */
2676
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  1851
		zc->zc_value[sizeof (zc->zc_value) - 1] = '\0';
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  1852
		if (dataset_namecheck(zc->zc_value, NULL, NULL) != 0) {
4543
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  1853
			nvlist_free(nvprops);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1854
			return (EINVAL);
2676
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  1855
		}
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1856
2676
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  1857
		error = dmu_objset_open(zc->zc_value, type,
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1858
		    DS_MODE_STANDARD | DS_MODE_READONLY, &clone);
2676
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  1859
		if (error) {
4543
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  1860
			nvlist_free(nvprops);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1861
			return (error);
2676
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  1862
		}
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1863
		error = dmu_objset_create(zc->zc_name, type, clone, NULL, NULL);
5331
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
  1864
		if (error) {
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
  1865
			dmu_objset_close(clone);
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
  1866
			nvlist_free(nvprops);
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
  1867
			return (error);
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
  1868
		}
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
  1869
		/*
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
  1870
		 * If caller did not provide any properties, allocate
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
  1871
		 * an nvlist for properties, as we will be adding our set-once
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
  1872
		 * properties to it.  This carries the choices made on the
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
  1873
		 * original file system into the clone.
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
  1874
		 */
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
  1875
		if (nvprops == NULL)
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
  1876
			VERIFY(nvlist_alloc(&nvprops,
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
  1877
			    NV_UNIQUE_NAME, KM_SLEEP) == 0);
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
  1878
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
  1879
		/*
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
  1880
		 * We have to have normalization and case-folding
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
  1881
		 * flags correct when we do the file system creation,
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
  1882
		 * so go figure them out now.  All we really care about
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
  1883
		 * here is getting these values into the property list.
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
  1884
		 */
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
  1885
		error = zfs_normalization_get(zc->zc_value, nvprops,
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
  1886
		    &zct.zct_norm, B_TRUE);
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
  1887
		if (error != 0) {
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
  1888
			dmu_objset_close(clone);
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
  1889
			nvlist_free(nvprops);
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
  1890
			return (error);
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
  1891
		}
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1892
		dmu_objset_close(clone);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1893
	} else {
2676
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  1894
		if (cbfunc == NULL) {
4543
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  1895
			nvlist_free(nvprops);
2199
712a788c2dfd PSARC 2006/388 snapshot -r
ahrens
parents: 2082
diff changeset
  1896
			return (EINVAL);
2676
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  1897
		}
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  1898
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1899
		if (type == DMU_OST_ZVOL) {
2676
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  1900
			uint64_t volsize, volblocksize;
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  1901
4543
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  1902
			if (nvprops == NULL ||
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  1903
			    nvlist_lookup_uint64(nvprops,
2676
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  1904
			    zfs_prop_to_name(ZFS_PROP_VOLSIZE),
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  1905
			    &volsize) != 0) {
4543
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  1906
				nvlist_free(nvprops);
2676
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  1907
				return (EINVAL);
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  1908
			}
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  1909
4543
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  1910
			if ((error = nvlist_lookup_uint64(nvprops,
2676
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  1911
			    zfs_prop_to_name(ZFS_PROP_VOLBLOCKSIZE),
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  1912
			    &volblocksize)) != 0 && error != ENOENT) {
4543
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  1913
				nvlist_free(nvprops);
2676
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  1914
				return (EINVAL);
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  1915
			}
1133
335d069294d1 6357470 vdev_raidz.c has unused RAIDZ_SINGLE define, code
eschrock
parents: 1003
diff changeset
  1916
2676
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  1917
			if (error != 0)
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  1918
				volblocksize = zfs_prop_default_numeric(
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  1919
				    ZFS_PROP_VOLBLOCKSIZE);
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  1920
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  1921
			if ((error = zvol_check_volblocksize(
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  1922
			    volblocksize)) != 0 ||
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  1923
			    (error = zvol_check_volsize(volsize,
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  1924
			    volblocksize)) != 0) {
4543
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  1925
				nvlist_free(nvprops);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1926
				return (error);
2676
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  1927
			}
4577
ed36b0e652bc PSARC/2007/328 zfs upgrade
ahrens
parents: 4543
diff changeset
  1928
		} else if (type == DMU_OST_ZFS) {
ed36b0e652bc PSARC/2007/328 zfs upgrade
ahrens
parents: 4543
diff changeset
  1929
			uint64_t version;
5331
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
  1930
			int error;
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
  1931
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
  1932
			error = nvlist_lookup_uint64(nvprops,
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
  1933
			    zfs_prop_to_name(ZFS_PROP_VERSION), &version);
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
  1934
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
  1935
			if (error == 0 && (version < ZPL_VERSION_INITIAL ||
4577
ed36b0e652bc PSARC/2007/328 zfs upgrade
ahrens
parents: 4543
diff changeset
  1936
			    version > ZPL_VERSION)) {
ed36b0e652bc PSARC/2007/328 zfs upgrade
ahrens
parents: 4543
diff changeset
  1937
				nvlist_free(nvprops);
5331
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
  1938
				return (ENOTSUP);
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
  1939
			} else if (error == 0 && version >= ZPL_VERSION_FUID &&
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
  1940
			    zfs_check_version(zc->zc_name, SPA_VERSION_FUID)) {
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
  1941
				nvlist_free(nvprops);
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
  1942
				return (ENOTSUP);
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
  1943
			}
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
  1944
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
  1945
			/*
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
  1946
			 * We have to have normalization and
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
  1947
			 * case-folding flags correct when we do the
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
  1948
			 * file system creation, so go figure them out
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
  1949
			 * now.  The final argument to zfs_normalization_get()
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
  1950
			 * tells that routine not to update the nvprops
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
  1951
			 * list.
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
  1952
			 */
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
  1953
			error = zfs_normalization_get(zc->zc_name, nvprops,
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
  1954
			    &zct.zct_norm, B_FALSE);
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
  1955
			if (error != 0) {
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
  1956
				nvlist_free(nvprops);
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
  1957
				return (error);
4577
ed36b0e652bc PSARC/2007/328 zfs upgrade
ahrens
parents: 4543
diff changeset
  1958
			}
2676
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  1959
		}
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  1960
		error = dmu_objset_create(zc->zc_name, type, NULL, cbfunc,
5331
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
  1961
		    &zct);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1962
	}
2676
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  1963
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  1964
	/*
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  1965
	 * It would be nice to do this atomically.
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  1966
	 */
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  1967
	if (error == 0) {
4787
602d3f97842c 6393351 unique_* could be improved
ahrens
parents: 4720
diff changeset
  1968
		if ((error = zfs_set_prop_nvlist(zc->zc_name, nvprops)) != 0)
2676
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  1969
			(void) dmu_objset_destroy(zc->zc_name);
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  1970
	}
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  1971
4543
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  1972
	nvlist_free(nvprops);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1973
	return (error);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1974
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1975
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1976
static int
2199
712a788c2dfd PSARC 2006/388 snapshot -r
ahrens
parents: 2082
diff changeset
  1977
zfs_ioc_snapshot(zfs_cmd_t *zc)
712a788c2dfd PSARC 2006/388 snapshot -r
ahrens
parents: 2082
diff changeset
  1978
{
2676
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  1979
	if (snapshot_namecheck(zc->zc_value, NULL, NULL) != 0)
2199
712a788c2dfd PSARC 2006/388 snapshot -r
ahrens
parents: 2082
diff changeset
  1980
		return (EINVAL);
712a788c2dfd PSARC 2006/388 snapshot -r
ahrens
parents: 2082
diff changeset
  1981
	return (dmu_objset_snapshot(zc->zc_name,
2676
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  1982
	    zc->zc_value, zc->zc_cookie));
2199
712a788c2dfd PSARC 2006/388 snapshot -r
ahrens
parents: 2082
diff changeset
  1983
}
712a788c2dfd PSARC 2006/388 snapshot -r
ahrens
parents: 2082
diff changeset
  1984
4007
c6f5c6753018 PSARC 2007/142 zfs rename -r
mmusante
parents: 3912
diff changeset
  1985
int
2199
712a788c2dfd PSARC 2006/388 snapshot -r
ahrens
parents: 2082
diff changeset
  1986
zfs_unmount_snap(char *name, void *arg)
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1987
{
2199
712a788c2dfd PSARC 2006/388 snapshot -r
ahrens
parents: 2082
diff changeset
  1988
	char *snapname = arg;
712a788c2dfd PSARC 2006/388 snapshot -r
ahrens
parents: 2082
diff changeset
  1989
	char *cp;
2417
694d5de97348 6444346 zfs promote fails in zone
ahrens
parents: 2199
diff changeset
  1990
	vfs_t *vfsp = NULL;
2199
712a788c2dfd PSARC 2006/388 snapshot -r
ahrens
parents: 2082
diff changeset
  1991
712a788c2dfd PSARC 2006/388 snapshot -r
ahrens
parents: 2082
diff changeset
  1992
	/*
712a788c2dfd PSARC 2006/388 snapshot -r
ahrens
parents: 2082
diff changeset
  1993
	 * Snapshots (which are under .zfs control) must be unmounted
712a788c2dfd PSARC 2006/388 snapshot -r
ahrens
parents: 2082
diff changeset
  1994
	 * before they can be destroyed.
712a788c2dfd PSARC 2006/388 snapshot -r
ahrens
parents: 2082
diff changeset
  1995
	 */
712a788c2dfd PSARC 2006/388 snapshot -r
ahrens
parents: 2082
diff changeset
  1996
712a788c2dfd PSARC 2006/388 snapshot -r
ahrens
parents: 2082
diff changeset
  1997
	if (snapname) {
712a788c2dfd PSARC 2006/388 snapshot -r
ahrens
parents: 2082
diff changeset
  1998
		(void) strcat(name, "@");
712a788c2dfd PSARC 2006/388 snapshot -r
ahrens
parents: 2082
diff changeset
  1999
		(void) strcat(name, snapname);
712a788c2dfd PSARC 2006/388 snapshot -r
ahrens
parents: 2082
diff changeset
  2000
		vfsp = zfs_get_vfs(name);
712a788c2dfd PSARC 2006/388 snapshot -r
ahrens
parents: 2082
diff changeset
  2001
		cp = strchr(name, '@');
712a788c2dfd PSARC 2006/388 snapshot -r
ahrens
parents: 2082
diff changeset
  2002
		*cp = '\0';
2417
694d5de97348 6444346 zfs promote fails in zone
ahrens
parents: 2199
diff changeset
  2003
	} else if (strchr(name, '@')) {
2199
712a788c2dfd PSARC 2006/388 snapshot -r
ahrens
parents: 2082
diff changeset
  2004
		vfsp = zfs_get_vfs(name);
712a788c2dfd PSARC 2006/388 snapshot -r
ahrens
parents: 2082
diff changeset
  2005
	}
712a788c2dfd PSARC 2006/388 snapshot -r
ahrens
parents: 2082
diff changeset
  2006
712a788c2dfd PSARC 2006/388 snapshot -r
ahrens
parents: 2082
diff changeset
  2007
	if (vfsp) {
712a788c2dfd PSARC 2006/388 snapshot -r
ahrens
parents: 2082
diff changeset
  2008
		/*
712a788c2dfd PSARC 2006/388 snapshot -r
ahrens
parents: 2082
diff changeset
  2009
		 * Always force the unmount for snapshots.
712a788c2dfd PSARC 2006/388 snapshot -r
ahrens
parents: 2082
diff changeset
  2010
		 */
712a788c2dfd PSARC 2006/388 snapshot -r
ahrens
parents: 2082
diff changeset
  2011
		int flag = MS_FORCE;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2012
		int err;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2013
2199
712a788c2dfd PSARC 2006/388 snapshot -r
ahrens
parents: 2082
diff changeset
  2014
		if ((err = vn_vfswlock(vfsp->vfs_vnodecovered)) != 0) {
712a788c2dfd PSARC 2006/388 snapshot -r
ahrens
parents: 2082
diff changeset
  2015
			VFS_RELE(vfsp);
712a788c2dfd PSARC 2006/388 snapshot -r
ahrens
parents: 2082
diff changeset
  2016
			return (err);
712a788c2dfd PSARC 2006/388 snapshot -r
ahrens
parents: 2082
diff changeset
  2017
		}
712a788c2dfd PSARC 2006/388 snapshot -r
ahrens
parents: 2082
diff changeset
  2018
		VFS_RELE(vfsp);
712a788c2dfd PSARC 2006/388 snapshot -r
ahrens
parents: 2082
diff changeset
  2019
		if ((err = dounmount(vfsp, flag, kcred)) != 0)
712a788c2dfd PSARC 2006/388 snapshot -r
ahrens
parents: 2082
diff changeset
  2020
			return (err);
712a788c2dfd PSARC 2006/388 snapshot -r
ahrens
parents: 2082
diff changeset
  2021
	}
712a788c2dfd PSARC 2006/388 snapshot -r
ahrens
parents: 2082
diff changeset
  2022
	return (0);
712a788c2dfd PSARC 2006/388 snapshot -r
ahrens
parents: 2082
diff changeset
  2023
}
712a788c2dfd PSARC 2006/388 snapshot -r
ahrens
parents: 2082
diff changeset
  2024
712a788c2dfd PSARC 2006/388 snapshot -r
ahrens
parents: 2082
diff changeset
  2025
static int
712a788c2dfd PSARC 2006/388 snapshot -r
ahrens
parents: 2082
diff changeset
  2026
zfs_ioc_destroy_snaps(zfs_cmd_t *zc)
712a788c2dfd PSARC 2006/388 snapshot -r
ahrens
parents: 2082
diff changeset
  2027
{
712a788c2dfd PSARC 2006/388 snapshot -r
ahrens
parents: 2082
diff changeset
  2028
	int err;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2029
2676
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  2030
	if (snapshot_namecheck(zc->zc_value, NULL, NULL) != 0)
2199
712a788c2dfd PSARC 2006/388 snapshot -r
ahrens
parents: 2082
diff changeset
  2031
		return (EINVAL);
712a788c2dfd PSARC 2006/388 snapshot -r
ahrens
parents: 2082
diff changeset
  2032
	err = dmu_objset_find(zc->zc_name,
2676
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  2033
	    zfs_unmount_snap, zc->zc_value, DS_FIND_CHILDREN);
2199
712a788c2dfd PSARC 2006/388 snapshot -r
ahrens
parents: 2082
diff changeset
  2034
	if (err)
712a788c2dfd PSARC 2006/388 snapshot -r
ahrens
parents: 2082
diff changeset
  2035
		return (err);
2676
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  2036
	return (dmu_snapshots_destroy(zc->zc_name, zc->zc_value));
2199
712a788c2dfd PSARC 2006/388 snapshot -r
ahrens
parents: 2082
diff changeset
  2037
}
712a788c2dfd PSARC 2006/388 snapshot -r
ahrens
parents: 2082
diff changeset
  2038
712a788c2dfd PSARC 2006/388 snapshot -r
ahrens
parents: 2082
diff changeset
  2039
static int
712a788c2dfd PSARC 2006/388 snapshot -r
ahrens
parents: 2082
diff changeset
  2040
zfs_ioc_destroy(zfs_cmd_t *zc)
712a788c2dfd PSARC 2006/388 snapshot -r
ahrens
parents: 2082
diff changeset
  2041
{
712a788c2dfd PSARC 2006/388 snapshot -r
ahrens
parents: 2082
diff changeset
  2042
	if (strchr(zc->zc_name, '@') && zc->zc_objset_type == DMU_OST_ZFS) {
712a788c2dfd PSARC 2006/388 snapshot -r
ahrens
parents: 2082
diff changeset
  2043
		int err = zfs_unmount_snap(zc->zc_name, NULL);
712a788c2dfd PSARC 2006/388 snapshot -r
ahrens
parents: 2082
diff changeset
  2044
		if (err)
712a788c2dfd PSARC 2006/388 snapshot -r
ahrens
parents: 2082
diff changeset
  2045
			return (err);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2046
	}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2047
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2048
	return (dmu_objset_destroy(zc->zc_name));
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2049
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2050
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2051
static int
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2052
zfs_ioc_rollback(zfs_cmd_t *zc)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2053
{
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2054
	return (dmu_objset_rollback(zc->zc_name));
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2055
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2056
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2057
static int
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2058
zfs_ioc_rename(zfs_cmd_t *zc)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2059
{
4490
abf035049f7f PSARC 2007/199 zfs {create,clone,rename} -p
vb160487
parents: 4451
diff changeset
  2060
	boolean_t recursive = zc->zc_cookie & 1;
4007
c6f5c6753018 PSARC 2007/142 zfs rename -r
mmusante
parents: 3912
diff changeset
  2061
2676
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  2062
	zc->zc_value[sizeof (zc->zc_value) - 1] = '\0';
5326
6752aa2bd5bc 6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents: 5147
diff changeset
  2063
	if (dataset_namecheck(zc->zc_value, NULL, NULL) != 0 ||
6752aa2bd5bc 6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents: 5147
diff changeset
  2064
	    strchr(zc->zc_value, '%'))
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2065
		return (EINVAL);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2066
4007
c6f5c6753018 PSARC 2007/142 zfs rename -r
mmusante
parents: 3912
diff changeset
  2067
	/*
c6f5c6753018 PSARC 2007/142 zfs rename -r
mmusante
parents: 3912
diff changeset
  2068
	 * Unmount snapshot unless we're doing a recursive rename,
c6f5c6753018 PSARC 2007/142 zfs rename -r
mmusante
parents: 3912
diff changeset
  2069
	 * in which case the dataset code figures out which snapshots
c6f5c6753018 PSARC 2007/142 zfs rename -r
mmusante
parents: 3912
diff changeset
  2070
	 * to unmount.
c6f5c6753018 PSARC 2007/142 zfs rename -r
mmusante
parents: 3912
diff changeset
  2071
	 */
c6f5c6753018 PSARC 2007/142 zfs rename -r
mmusante
parents: 3912
diff changeset
  2072
	if (!recursive && strchr(zc->zc_name, '@') != NULL &&
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2073
	    zc->zc_objset_type == DMU_OST_ZFS) {
2199
712a788c2dfd PSARC 2006/388 snapshot -r
ahrens
parents: 2082
diff changeset
  2074
		int err = zfs_unmount_snap(zc->zc_name, NULL);
712a788c2dfd PSARC 2006/388 snapshot -r
ahrens
parents: 2082
diff changeset
  2075
		if (err)
712a788c2dfd PSARC 2006/388 snapshot -r
ahrens
parents: 2082
diff changeset
  2076
			return (err);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2077
	}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2078
4007
c6f5c6753018 PSARC 2007/142 zfs rename -r
mmusante
parents: 3912
diff changeset
  2079
	return (dmu_objset_rename(zc->zc_name, zc->zc_value, recursive));
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2080
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2081
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2082
static int
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2083
zfs_ioc_recvbackup(zfs_cmd_t *zc)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2084
{
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2085
	file_t *fp;
5326
6752aa2bd5bc 6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents: 5147
diff changeset
  2086
	offset_t new_off;
6752aa2bd5bc 6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents: 5147
diff changeset
  2087
	objset_t *os;
6752aa2bd5bc 6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents: 5147
diff changeset
  2088
	zfsvfs_t *zfsvfs = NULL;
6752aa2bd5bc 6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents: 5147
diff changeset
  2089
	char *cp;
6752aa2bd5bc 6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents: 5147
diff changeset
  2090
	char cosname[MAXNAMELEN];
6752aa2bd5bc 6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents: 5147
diff changeset
  2091
	boolean_t force = (boolean_t)zc->zc_guid;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2092
	int error, fd;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2093
3265
967e0fca6143 6463140 zfs recv with a snapshot name that has 2 @@ in a row succeeds
ahrens
parents: 3087
diff changeset
  2094
	if (dataset_namecheck(zc->zc_value, NULL, NULL) != 0 ||
5326
6752aa2bd5bc 6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents: 5147
diff changeset
  2095
	    strchr(zc->zc_value, '@') == NULL ||
6752aa2bd5bc 6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents: 5147
diff changeset
  2096
	    strchr(zc->zc_value, '%'))
3265
967e0fca6143 6463140 zfs recv with a snapshot name that has 2 @@ in a row succeeds
ahrens
parents: 3087
diff changeset
  2097
		return (EINVAL);
967e0fca6143 6463140 zfs recv with a snapshot name that has 2 @@ in a row succeeds
ahrens
parents: 3087
diff changeset
  2098
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2099
	fd = zc->zc_cookie;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2100
	fp = getf(fd);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2101
	if (fp == NULL)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2102
		return (EBADF);
5326
6752aa2bd5bc 6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents: 5147
diff changeset
  2103
6752aa2bd5bc 6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents: 5147
diff changeset
  2104
	/*
6752aa2bd5bc 6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents: 5147
diff changeset
  2105
	 * Get the zfsvfs for the receiving objset. There
6752aa2bd5bc 6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents: 5147
diff changeset
  2106
	 * won't be one if we're operating on a zvol, if the
6752aa2bd5bc 6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents: 5147
diff changeset
  2107
	 * objset doesn't exist yet, or is not mounted.
6752aa2bd5bc 6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents: 5147
diff changeset
  2108
	 */
6752aa2bd5bc 6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents: 5147
diff changeset
  2109
	cp = strchr(zc->zc_value, '@');
6752aa2bd5bc 6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents: 5147
diff changeset
  2110
	*cp = '\0';
6752aa2bd5bc 6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents: 5147
diff changeset
  2111
	error = dmu_objset_open(zc->zc_value, DMU_OST_ANY,
6752aa2bd5bc 6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents: 5147
diff changeset
  2112
	    DS_MODE_STANDARD | DS_MODE_READONLY, &os);
6752aa2bd5bc 6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents: 5147
diff changeset
  2113
	*cp = '@';
6752aa2bd5bc 6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents: 5147
diff changeset
  2114
	if (!error) {
6752aa2bd5bc 6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents: 5147
diff changeset
  2115
		if (dmu_objset_type(os) == DMU_OST_ZFS) {
6752aa2bd5bc 6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents: 5147
diff changeset
  2116
			mutex_enter(&os->os->os_user_ptr_lock);
6752aa2bd5bc 6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents: 5147
diff changeset
  2117
			zfsvfs = dmu_objset_get_user(os);
6752aa2bd5bc 6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents: 5147
diff changeset
  2118
			if (zfsvfs != NULL)
6752aa2bd5bc 6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents: 5147
diff changeset
  2119
				VFS_HOLD(zfsvfs->z_vfs);
6752aa2bd5bc 6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents: 5147
diff changeset
  2120
			mutex_exit(&os->os->os_user_ptr_lock);
6752aa2bd5bc 6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents: 5147
diff changeset
  2121
		}
6752aa2bd5bc 6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents: 5147
diff changeset
  2122
		dmu_objset_close(os);
6752aa2bd5bc 6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents: 5147
diff changeset
  2123
	}
6752aa2bd5bc 6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents: 5147
diff changeset
  2124
2676
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  2125
	error = dmu_recvbackup(zc->zc_value, &zc->zc_begin_record,
5326
6752aa2bd5bc 6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents: 5147
diff changeset
  2126
	    &zc->zc_cookie, force, zfsvfs != NULL, fp->f_vnode,
6752aa2bd5bc 6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents: 5147
diff changeset
  2127
	    fp->f_offset, cosname);
6752aa2bd5bc 6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents: 5147
diff changeset
  2128
6752aa2bd5bc 6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents: 5147
diff changeset
  2129
	/*
6752aa2bd5bc 6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents: 5147
diff changeset
  2130
	 * For incremental snapshots where we created a
6752aa2bd5bc 6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents: 5147
diff changeset
  2131
	 * temporary clone, we now swap zfsvfs::z_os with
6752aa2bd5bc 6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents: 5147
diff changeset
  2132
	 * the newly created and received "cosname".
6752aa2bd5bc 6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents: 5147
diff changeset
  2133
	 */
6752aa2bd5bc 6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents: 5147
diff changeset
  2134
	if (!error && zfsvfs != NULL) {
6752aa2bd5bc 6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents: 5147
diff changeset
  2135
		char osname[MAXNAMELEN];
6752aa2bd5bc 6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents: 5147
diff changeset
  2136
		int mode;
6752aa2bd5bc 6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents: 5147
diff changeset
  2137
6752aa2bd5bc 6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents: 5147
diff changeset
  2138
		error = zfs_suspend_fs(zfsvfs, osname, &mode);
6752aa2bd5bc 6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents: 5147
diff changeset
  2139
		if (!error) {
6752aa2bd5bc 6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents: 5147
diff changeset
  2140
			int swap_err;
6752aa2bd5bc 6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents: 5147
diff changeset
  2141
			int snap_err = 0;
2885
c0259887ebbc 6460059 zfs destroy <snapshot> leaves behind kruft
ahrens
parents: 2856
diff changeset
  2142
5326
6752aa2bd5bc 6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents: 5147
diff changeset
  2143
			swap_err = dsl_dataset_clone_swap(cosname, force);
6752aa2bd5bc 6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents: 5147
diff changeset
  2144
			if (!swap_err) {
6752aa2bd5bc 6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents: 5147
diff changeset
  2145
				char *cp = strrchr(zc->zc_value, '@');
6752aa2bd5bc 6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents: 5147
diff changeset
  2146
6752aa2bd5bc 6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents: 5147
diff changeset
  2147
				*cp = '\0';
6752aa2bd5bc 6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents: 5147
diff changeset
  2148
				snap_err = dmu_replay_end_snapshot(zc->zc_value,
6752aa2bd5bc 6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents: 5147
diff changeset
  2149
				    &zc->zc_begin_record);
6752aa2bd5bc 6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents: 5147
diff changeset
  2150
				*cp = '@';
6752aa2bd5bc 6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents: 5147
diff changeset
  2151
			}
6752aa2bd5bc 6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents: 5147
diff changeset
  2152
			error = zfs_resume_fs(zfsvfs, osname, mode);
6752aa2bd5bc 6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents: 5147
diff changeset
  2153
			if (!error)
6752aa2bd5bc 6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents: 5147
diff changeset
  2154
				error = swap_err;
6752aa2bd5bc 6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents: 5147
diff changeset
  2155
			if (!error)
6752aa2bd5bc 6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents: 5147
diff changeset
  2156
				error = snap_err;
6752aa2bd5bc 6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents: 5147
diff changeset
  2157
		}
6752aa2bd5bc 6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents: 5147
diff changeset
  2158
6752aa2bd5bc 6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents: 5147
diff changeset
  2159
		/* destroy the clone we created */
6752aa2bd5bc 6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents: 5147
diff changeset
  2160
		(void) dmu_objset_destroy(cosname);
6752aa2bd5bc 6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents: 5147
diff changeset
  2161
	}
6752aa2bd5bc 6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents: 5147
diff changeset
  2162
	if (zfsvfs != NULL)
6752aa2bd5bc 6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents: 5147
diff changeset
  2163
		VFS_RELE(zfsvfs->z_vfs);
2885
c0259887ebbc 6460059 zfs destroy <snapshot> leaves behind kruft
ahrens
parents: 2856
diff changeset
  2164
	new_off = fp->f_offset + zc->zc_cookie;
5331
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
  2165
	if (VOP_SEEK(fp->f_vnode, fp->f_offset, &new_off, NULL) == 0)
2885
c0259887ebbc 6460059 zfs destroy <snapshot> leaves behind kruft
ahrens
parents: 2856
diff changeset
  2166
		fp->f_offset = new_off;
c0259887ebbc 6460059 zfs destroy <snapshot> leaves behind kruft
ahrens
parents: 2856
diff changeset
  2167
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2168
	releasef(fd);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2169
	return (error);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2170
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2171
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2172
static int
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2173
zfs_ioc_sendbackup(zfs_cmd_t *zc)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2174
{
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2175
	objset_t *fromsnap = NULL;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2176
	objset_t *tosnap;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2177
	file_t *fp;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2178
	int error;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2179
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2180
	error = dmu_objset_open(zc->zc_name, DMU_OST_ANY,
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2181
	    DS_MODE_STANDARD | DS_MODE_READONLY, &tosnap);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2182
	if (error)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2183
		return (error);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2184
2676
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  2185
	if (zc->zc_value[0] != '\0') {
2885
c0259887ebbc 6460059 zfs destroy <snapshot> leaves behind kruft
ahrens
parents: 2856
diff changeset
  2186
		char buf[MAXPATHLEN];
c0259887ebbc 6460059 zfs destroy <snapshot> leaves behind kruft
ahrens
parents: 2856
diff changeset
  2187
		char *cp;
c0259887ebbc 6460059 zfs destroy <snapshot> leaves behind kruft
ahrens
parents: 2856
diff changeset
  2188
c0259887ebbc 6460059 zfs destroy <snapshot> leaves behind kruft
ahrens
parents: 2856
diff changeset
  2189
		(void) strncpy(buf, zc->zc_name, sizeof (buf));
c0259887ebbc 6460059 zfs destroy <snapshot> leaves behind kruft
ahrens
parents: 2856
diff changeset
  2190
		cp = strchr(buf, '@');
c0259887ebbc 6460059 zfs destroy <snapshot> leaves behind kruft
ahrens
parents: 2856
diff changeset
  2191
		if (cp)
c0259887ebbc 6460059 zfs destroy <snapshot> leaves behind kruft
ahrens
parents: 2856
diff changeset
  2192
			*(cp+1) = 0;
c0259887ebbc 6460059 zfs destroy <snapshot> leaves behind kruft
ahrens
parents: 2856
diff changeset
  2193
		(void) strncat(buf, zc->zc_value, sizeof (buf));
c0259887ebbc 6460059 zfs destroy <snapshot> leaves behind kruft
ahrens
parents: 2856
diff changeset
  2194
		error = dmu_objset_open(buf, DMU_OST_ANY,
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2195
		    DS_MODE_STANDARD | DS_MODE_READONLY, &fromsnap);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2196
		if (error) {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2197
			dmu_objset_close(tosnap);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2198
			return (error);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2199
		}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2200
	}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2201
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2202
	fp = getf(zc->zc_cookie);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2203
	if (fp == NULL) {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2204
		dmu_objset_close(tosnap);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2205
		if (fromsnap)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2206
			dmu_objset_close(fromsnap);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2207
		return (EBADF);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2208
	}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2209
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2210
	error = dmu_sendbackup(tosnap, fromsnap, fp->f_vnode);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2211
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2212
	releasef(zc->zc_cookie);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2213
	if (fromsnap)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2214
		dmu_objset_close(fromsnap);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2215
	dmu_objset_close(tosnap);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2216
	return (error);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2217
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2218
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
  2219
static int
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
  2220
zfs_ioc_inject_fault(zfs_cmd_t *zc)
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
  2221
{
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
  2222
	int id, error;
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
  2223
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
  2224
	error = zio_inject_fault(zc->zc_name, (int)zc->zc_guid, &id,
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
  2225
	    &zc->zc_inject_record);
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
  2226
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
  2227
	if (error == 0)
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
  2228
		zc->zc_guid = (uint64_t)id;
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
  2229
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
  2230
	return (error);
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
  2231
}
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
  2232
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
  2233
static int
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
  2234
zfs_ioc_clear_fault(zfs_cmd_t *zc)
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
  2235
{
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
  2236
	return (zio_clear_fault((int)zc->zc_guid));
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
  2237
}
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
  2238
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
  2239
static int
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
  2240
zfs_ioc_inject_list_next(zfs_cmd_t *zc)
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
  2241
{
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
  2242
	int id = (int)zc->zc_guid;
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
  2243
	int error;
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
  2244
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
  2245
	error = zio_inject_list_next(&id, zc->zc_name, sizeof (zc->zc_name),
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
  2246
	    &zc->zc_inject_record);
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
  2247
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
  2248
	zc->zc_guid = id;
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
  2249
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
  2250
	return (error);
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
  2251
}
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
  2252
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
  2253
static int
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
  2254
zfs_ioc_error_log(zfs_cmd_t *zc)
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
  2255
{
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
  2256
	spa_t *spa;
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
  2257
	int error;
2676
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  2258
	size_t count = (size_t)zc->zc_nvlist_dst_size;
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
  2259
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
  2260
	if ((error = spa_open(zc->zc_name, &spa, FTAG)) != 0)
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
  2261
		return (error);
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
  2262
2676
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  2263
	error = spa_get_errlog(spa, (void *)(uintptr_t)zc->zc_nvlist_dst,
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
  2264
	    &count);
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
  2265
	if (error == 0)
2676
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  2266
		zc->zc_nvlist_dst_size = count;
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
  2267
	else
2676
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  2268
		zc->zc_nvlist_dst_size = spa_get_errlog_size(spa);
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
  2269
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
  2270
	spa_close(spa, FTAG);
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
  2271
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
  2272
	return (error);
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
  2273
}
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
  2274
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
  2275
static int
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
  2276
zfs_ioc_clear(zfs_cmd_t *zc)
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
  2277
{
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
  2278
	spa_t *spa;
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
  2279
	vdev_t *vd;
4808
63629eaeb41a 6498144 ::kmastat could be even easier to read
ek110237
parents: 4787
diff changeset
  2280
	uint64_t txg;
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
  2281
	int error;
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
  2282
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
  2283
	if ((error = spa_open(zc->zc_name, &spa, FTAG)) != 0)
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
  2284
		return (error);
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
  2285
5329
33cb98223b2d PSARC 2007/567 zpool failmode property
gw25295
parents: 5326
diff changeset
  2286
	/*
33cb98223b2d PSARC 2007/567 zpool failmode property
gw25295
parents: 5326
diff changeset
  2287
	 * Try to resume any I/Os which may have been suspended
33cb98223b2d PSARC 2007/567 zpool failmode property
gw25295
parents: 5326
diff changeset
  2288
	 * as a result of a complete pool failure.
33cb98223b2d PSARC 2007/567 zpool failmode property
gw25295
parents: 5326
diff changeset
  2289
	 */
33cb98223b2d PSARC 2007/567 zpool failmode property
gw25295
parents: 5326
diff changeset
  2290
	if (!list_is_empty(&spa->spa_zio_list)) {
33cb98223b2d PSARC 2007/567 zpool failmode property
gw25295
parents: 5326
diff changeset
  2291
		if (zio_vdev_resume_io(spa) != 0) {
33cb98223b2d PSARC 2007/567 zpool failmode property
gw25295
parents: 5326
diff changeset
  2292
			spa_close(spa, FTAG);
33cb98223b2d PSARC 2007/567 zpool failmode property
gw25295
parents: 5326
diff changeset
  2293
			return (EIO);
33cb98223b2d PSARC 2007/567 zpool failmode property
gw25295
parents: 5326
diff changeset
  2294
		}
33cb98223b2d PSARC 2007/567 zpool failmode property
gw25295
parents: 5326
diff changeset
  2295
	}
33cb98223b2d PSARC 2007/567 zpool failmode property
gw25295
parents: 5326
diff changeset
  2296
4451
24fbf2d7a5d7 PSARC 2007/197 ZFS hotplug
eschrock
parents: 4098
diff changeset
  2297
	txg = spa_vdev_enter(spa);
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
  2298
2676
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  2299
	if (zc->zc_guid == 0) {
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
  2300
		vd = NULL;
2676
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  2301
	} else if ((vd = spa_lookup_by_guid(spa, zc->zc_guid)) == NULL) {
4451
24fbf2d7a5d7 PSARC 2007/197 ZFS hotplug
eschrock
parents: 4098
diff changeset
  2302
		(void) spa_vdev_exit(spa, NULL, txg, ENODEV);
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
  2303
		spa_close(spa, FTAG);
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
  2304
		return (ENODEV);
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
  2305
	}
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
  2306
5329
33cb98223b2d PSARC 2007/567 zpool failmode property
gw25295
parents: 5326
diff changeset
  2307
	vdev_clear(spa, vd, B_TRUE);
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
  2308
4451
24fbf2d7a5d7 PSARC 2007/197 ZFS hotplug
eschrock
parents: 4098
diff changeset
  2309
	(void) spa_vdev_exit(spa, NULL, txg, 0);
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
  2310
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
  2311
	spa_close(spa, FTAG);
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
  2312
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
  2313
	return (0);
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
  2314
}
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
  2315
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
  2316
static int
2082
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1775
diff changeset
  2317
zfs_ioc_promote(zfs_cmd_t *zc)
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1775
diff changeset
  2318
{
2417
694d5de97348 6444346 zfs promote fails in zone
ahrens
parents: 2199
diff changeset
  2319
	char *cp;
694d5de97348 6444346 zfs promote fails in zone
ahrens
parents: 2199
diff changeset
  2320
694d5de97348 6444346 zfs promote fails in zone
ahrens
parents: 2199
diff changeset
  2321
	/*
694d5de97348 6444346 zfs promote fails in zone
ahrens
parents: 2199
diff changeset
  2322
	 * 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
  2323
	 * it's easier.
694d5de97348 6444346 zfs promote fails in zone
ahrens
parents: 2199
diff changeset
  2324
	 */
2676
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  2325
	cp = strchr(zc->zc_value, '@');
2417
694d5de97348 6444346 zfs promote fails in zone
ahrens
parents: 2199
diff changeset
  2326
	if (cp)
694d5de97348 6444346 zfs promote fails in zone
ahrens
parents: 2199
diff changeset
  2327
		*cp = '\0';
2676
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  2328
	(void) dmu_objset_find(zc->zc_value,
2417
694d5de97348 6444346 zfs promote fails in zone
ahrens
parents: 2199
diff changeset
  2329
	    zfs_unmount_snap, NULL, DS_FIND_SNAPSHOTS);
2082
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1775
diff changeset
  2330
	return (dsl_dataset_promote(zc->zc_name));
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1775
diff changeset
  2331
}
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1775
diff changeset
  2332
4543
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  2333
/*
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  2334
 * We don't want to have a hard dependency
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  2335
 * against some special symbols in sharefs
5331
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
  2336
 * nfs, and smbsrv.  Determine them if needed when
4543
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  2337
 * the first file system is shared.
5331
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
  2338
 * Neither sharefs, nfs or smbsrv are unloadable modules.
4543
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  2339
 */
5331
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
  2340
int (*znfsexport_fs)(void *arg);
4543
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  2341
int (*zshare_fs)(enum sharefs_sys_op, share_t *, uint32_t);
5331
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
  2342
int (*zsmbexport_fs)(void *arg, boolean_t add_share);
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
  2343
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
  2344
int zfs_nfsshare_inited;
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
  2345
int zfs_smbshare_inited;
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
  2346
4543
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  2347
ddi_modhandle_t nfs_mod;
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  2348
ddi_modhandle_t sharefs_mod;
5331
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
  2349
ddi_modhandle_t smbsrv_mod;
4543
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  2350
kmutex_t zfs_share_lock;
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  2351
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  2352
static int
5331
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
  2353
zfs_init_sharefs()
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
  2354
{
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
  2355
	int error;
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
  2356
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
  2357
	ASSERT(MUTEX_HELD(&zfs_share_lock));
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
  2358
	/* Both NFS and SMB shares also require sharetab support. */
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
  2359
	if (sharefs_mod == NULL && ((sharefs_mod =
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
  2360
	    ddi_modopen("fs/sharefs",
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
  2361
	    KRTLD_MODE_FIRST, &error)) == NULL)) {
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
  2362
		return (ENOSYS);
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
  2363
	}
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
  2364
	if (zshare_fs == NULL && ((zshare_fs =
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
  2365
	    (int (*)(enum sharefs_sys_op, share_t *, uint32_t))
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
  2366
	    ddi_modsym(sharefs_mod, "sharefs_impl", &error)) == NULL)) {
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
  2367
		return (ENOSYS);
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
  2368
	}
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
  2369
	return (0);
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
  2370
}
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
  2371
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
  2372
static int
4543
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  2373
zfs_ioc_share(zfs_cmd_t *zc)
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  2374
{
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  2375
	int error;
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  2376
	int opcode;
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  2377
5331
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
  2378
	switch (zc->zc_share.z_sharetype) {
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
  2379
	case ZFS_SHARE_NFS:
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
  2380
	case ZFS_UNSHARE_NFS:
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
  2381
		if (zfs_nfsshare_inited == 0) {
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
  2382
			mutex_enter(&zfs_share_lock);
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
  2383
			if (nfs_mod == NULL && ((nfs_mod = ddi_modopen("fs/nfs",
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
  2384
			    KRTLD_MODE_FIRST, &error)) == NULL)) {
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
  2385
				mutex_exit(&zfs_share_lock);
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
  2386
				return (ENOSYS);
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
  2387
			}
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
  2388
			if (znfsexport_fs == NULL &&
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
  2389
			    ((znfsexport_fs = (int (*)(void *))
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
  2390
			    ddi_modsym(nfs_mod,
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
  2391
			    "nfs_export", &error)) == NULL)) {
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
  2392
				mutex_exit(&zfs_share_lock);
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
  2393
				return (ENOSYS);
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
  2394
			}
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
  2395
			error = zfs_init_sharefs();
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
  2396
			if (error) {
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
  2397
				mutex_exit(&zfs_share_lock);
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
  2398
				return (ENOSYS);
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
  2399
			}
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
  2400
			zfs_nfsshare_inited = 1;
4543
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  2401
			mutex_exit(&zfs_share_lock);
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  2402
		}
5331
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
  2403
		break;
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
  2404
	case ZFS_SHARE_SMB:
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
  2405
	case ZFS_UNSHARE_SMB:
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
  2406
		if (zfs_smbshare_inited == 0) {
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
  2407
			mutex_enter(&zfs_share_lock);
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
  2408
			if (smbsrv_mod == NULL && ((smbsrv_mod =
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
  2409
			    ddi_modopen("drv/smbsrv",
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
  2410
			    KRTLD_MODE_FIRST, &error)) == NULL)) {
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
  2411
				mutex_exit(&zfs_share_lock);
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
  2412
				return (ENOSYS);
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
  2413
			}
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
  2414
			if (zsmbexport_fs == NULL && ((zsmbexport_fs =
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
  2415
			    (int (*)(void *, boolean_t))ddi_modsym(smbsrv_mod,
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
  2416
			    "lmshrd_share_upcall", &error)) == NULL)) {
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
  2417
				mutex_exit(&zfs_share_lock);
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
  2418
				return (ENOSYS);
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
  2419
			}
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
  2420
			error = zfs_init_sharefs();
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
  2421
			if (error) {
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
  2422
				mutex_exit(&zfs_share_lock);
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
  2423
				return (ENOSYS);
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
  2424
			}
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
  2425
			zfs_smbshare_inited = 1;
4543
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  2426
			mutex_exit(&zfs_share_lock);
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  2427
		}
5331
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
  2428
		break;
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
  2429
	default:
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
  2430
		return (EINVAL);
4543
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  2431
	}
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  2432
5331
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
  2433
	switch (zc->zc_share.z_sharetype) {
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
  2434
	case ZFS_SHARE_NFS:
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
  2435
	case ZFS_UNSHARE_NFS:
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
  2436
		if (error =
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
  2437
		    znfsexport_fs((void *)
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
  2438
		    (uintptr_t)zc->zc_share.z_exportdata))
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
  2439
			return (error);
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
  2440
		break;
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
  2441
	case ZFS_SHARE_SMB:
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
  2442
	case ZFS_UNSHARE_SMB:
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
  2443
		if (error = zsmbexport_fs((void *)
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
  2444
		    (uintptr_t)zc->zc_share.z_exportdata,
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
  2445
		    zc->zc_share.z_sharetype == ZFS_SHARE_SMB ?
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
  2446
		    B_TRUE : B_FALSE)) {
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
  2447
			return (error);
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
  2448
		}
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
  2449
		break;
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
  2450
	}
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
  2451
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
  2452
	opcode = (zc->zc_share.z_sharetype == ZFS_SHARE_NFS ||
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
  2453
	    zc->zc_share.z_sharetype == ZFS_SHARE_SMB) ?
4543
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  2454
	    SHAREFS_ADD : SHAREFS_REMOVE;
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  2455
5331
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
  2456
	/*
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
  2457
	 * Add or remove share from sharetab
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
  2458
	 */
4543
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  2459
	error = zshare_fs(opcode,
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  2460
	    (void *)(uintptr_t)zc->zc_share.z_sharedata,
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  2461
	    zc->zc_share.z_sharemax);
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  2462
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  2463
	return (error);
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  2464
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  2465
}
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  2466
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  2467
/*
4988
db8abd9846d4 6595467 libzfs consumers should be allowed to write their own history (or none at all)
ek110237
parents: 4849
diff changeset
  2468
 * 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
  2469
 * 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
  2470
 * do the logging of those commands.
4543
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  2471
 */
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2472
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
  2473
	{ zfs_ioc_pool_create, zfs_secpolicy_config, POOL_NAME, B_FALSE },
4577
ed36b0e652bc PSARC/2007/328 zfs upgrade
ahrens
parents: 4543
diff changeset
  2474
	{ zfs_ioc_pool_destroy,	zfs_secpolicy_config, POOL_NAME, B_FALSE },
ed36b0e652bc PSARC/2007/328 zfs upgrade
ahrens
parents: 4543
diff changeset
  2475
	{ zfs_ioc_pool_import, zfs_secpolicy_config, POOL_NAME, B_TRUE },
ed36b0e652bc PSARC/2007/328 zfs upgrade
ahrens
parents: 4543
diff changeset
  2476
	{ zfs_ioc_pool_export, zfs_secpolicy_config, POOL_NAME, B_FALSE },
ed36b0e652bc PSARC/2007/328 zfs upgrade
ahrens
parents: 4543
diff changeset
  2477
	{ zfs_ioc_pool_configs,	zfs_secpolicy_none, NO_NAME, B_FALSE },
ed36b0e652bc PSARC/2007/328 zfs upgrade
ahrens
parents: 4543
diff changeset
  2478
	{ zfs_ioc_pool_stats, zfs_secpolicy_read, POOL_NAME, B_FALSE },
ed36b0e652bc PSARC/2007/328 zfs upgrade
ahrens
parents: 4543
diff changeset
  2479
	{ zfs_ioc_pool_tryimport, zfs_secpolicy_config, NO_NAME, B_FALSE },
ed36b0e652bc PSARC/2007/328 zfs upgrade
ahrens
parents: 4543
diff changeset
  2480
	{ zfs_ioc_pool_scrub, zfs_secpolicy_config, POOL_NAME, B_TRUE },
ed36b0e652bc PSARC/2007/328 zfs upgrade
ahrens
parents: 4543
diff changeset
  2481
	{ zfs_ioc_pool_freeze, zfs_secpolicy_config, NO_NAME, B_FALSE },
ed36b0e652bc PSARC/2007/328 zfs upgrade
ahrens
parents: 4543
diff changeset
  2482
	{ zfs_ioc_pool_upgrade,	zfs_secpolicy_config, POOL_NAME, B_TRUE },
ed36b0e652bc PSARC/2007/328 zfs upgrade
ahrens
parents: 4543
diff changeset
  2483
	{ zfs_ioc_pool_get_history, zfs_secpolicy_config, POOL_NAME, B_FALSE },
ed36b0e652bc PSARC/2007/328 zfs upgrade
ahrens
parents: 4543
diff changeset
  2484
	{ zfs_ioc_vdev_add, zfs_secpolicy_config, POOL_NAME, B_TRUE },
ed36b0e652bc PSARC/2007/328 zfs upgrade
ahrens
parents: 4543
diff changeset
  2485
	{ zfs_ioc_vdev_remove, zfs_secpolicy_config, POOL_NAME, B_TRUE },
ed36b0e652bc PSARC/2007/328 zfs upgrade
ahrens
parents: 4543
diff changeset
  2486
	{ zfs_ioc_vdev_set_state, zfs_secpolicy_config,	POOL_NAME, B_TRUE },
ed36b0e652bc PSARC/2007/328 zfs upgrade
ahrens
parents: 4543
diff changeset
  2487
	{ zfs_ioc_vdev_attach, zfs_secpolicy_config, POOL_NAME, B_TRUE },
ed36b0e652bc PSARC/2007/328 zfs upgrade
ahrens
parents: 4543
diff changeset
  2488
	{ zfs_ioc_vdev_detach, zfs_secpolicy_config, POOL_NAME, B_TRUE },
ed36b0e652bc PSARC/2007/328 zfs upgrade
ahrens
parents: 4543
diff changeset
  2489
	{ zfs_ioc_vdev_setpath,	zfs_secpolicy_config, POOL_NAME, B_FALSE },
ed36b0e652bc PSARC/2007/328 zfs upgrade
ahrens
parents: 4543
diff changeset
  2490
	{ zfs_ioc_objset_stats,	zfs_secpolicy_read, DATASET_NAME, B_FALSE },
5147
5e950ccc9585 6596190 "zfs list" is slow due to version property
rm160521
parents: 5118
diff changeset
  2491
	{ zfs_ioc_objset_version, zfs_secpolicy_read, DATASET_NAME, B_FALSE },
4543
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  2492
	{ zfs_ioc_dataset_list_next, zfs_secpolicy_read,
4577
ed36b0e652bc PSARC/2007/328 zfs upgrade
ahrens
parents: 4543
diff changeset
  2493
	    DATASET_NAME, B_FALSE },
4543
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  2494
	{ zfs_ioc_snapshot_list_next, zfs_secpolicy_read,
4577
ed36b0e652bc PSARC/2007/328 zfs upgrade
ahrens
parents: 4543
diff changeset
  2495
	    DATASET_NAME, B_FALSE },
ed36b0e652bc PSARC/2007/328 zfs upgrade
ahrens
parents: 4543
diff changeset
  2496
	{ zfs_ioc_set_prop, zfs_secpolicy_none, DATASET_NAME, B_TRUE },
ed36b0e652bc PSARC/2007/328 zfs upgrade
ahrens
parents: 4543
diff changeset
  2497
	{ zfs_ioc_create_minor,	zfs_secpolicy_minor, DATASET_NAME, B_FALSE },
ed36b0e652bc PSARC/2007/328 zfs upgrade
ahrens
parents: 4543
diff changeset
  2498
	{ zfs_ioc_remove_minor,	zfs_secpolicy_minor, DATASET_NAME, B_FALSE },
ed36b0e652bc PSARC/2007/328 zfs upgrade
ahrens
parents: 4543
diff changeset
  2499
	{ zfs_ioc_create, zfs_secpolicy_create, DATASET_NAME, B_TRUE },
ed36b0e652bc PSARC/2007/328 zfs upgrade
ahrens
parents: 4543
diff changeset
  2500
	{ zfs_ioc_destroy, zfs_secpolicy_destroy, DATASET_NAME, B_TRUE },
ed36b0e652bc PSARC/2007/328 zfs upgrade
ahrens
parents: 4543
diff changeset
  2501
	{ zfs_ioc_rollback, zfs_secpolicy_rollback, DATASET_NAME, B_TRUE },
ed36b0e652bc PSARC/2007/328 zfs upgrade
ahrens
parents: 4543
diff changeset
  2502
	{ zfs_ioc_rename, zfs_secpolicy_rename,	DATASET_NAME, B_TRUE },
ed36b0e652bc PSARC/2007/328 zfs upgrade
ahrens
parents: 4543
diff changeset
  2503
	{ zfs_ioc_recvbackup, zfs_secpolicy_receive, DATASET_NAME, B_TRUE },
ed36b0e652bc PSARC/2007/328 zfs upgrade
ahrens
parents: 4543
diff changeset
  2504
	{ zfs_ioc_sendbackup, zfs_secpolicy_send, DATASET_NAME, B_TRUE },
ed36b0e652bc PSARC/2007/328 zfs upgrade
ahrens
parents: 4543
diff changeset
  2505
	{ zfs_ioc_inject_fault,	zfs_secpolicy_inject, NO_NAME, B_FALSE },
ed36b0e652bc PSARC/2007/328 zfs upgrade
ahrens
parents: 4543
diff changeset
  2506
	{ zfs_ioc_clear_fault, zfs_secpolicy_inject, NO_NAME, B_FALSE },
ed36b0e652bc PSARC/2007/328 zfs upgrade
ahrens
parents: 4543
diff changeset
  2507
	{ zfs_ioc_inject_list_next, zfs_secpolicy_inject, NO_NAME, B_FALSE },
ed36b0e652bc PSARC/2007/328 zfs upgrade
ahrens
parents: 4543
diff changeset
  2508
	{ zfs_ioc_error_log, zfs_secpolicy_inject, POOL_NAME, B_FALSE },
ed36b0e652bc PSARC/2007/328 zfs upgrade
ahrens
parents: 4543
diff changeset
  2509
	{ zfs_ioc_clear, zfs_secpolicy_config, POOL_NAME, B_TRUE },
ed36b0e652bc PSARC/2007/328 zfs upgrade
ahrens
parents: 4543
diff changeset
  2510
	{ zfs_ioc_promote, zfs_secpolicy_promote, DATASET_NAME, B_TRUE },
ed36b0e652bc PSARC/2007/328 zfs upgrade
ahrens
parents: 4543
diff changeset
  2511
	{ zfs_ioc_destroy_snaps, zfs_secpolicy_destroy,	DATASET_NAME, B_TRUE },
ed36b0e652bc PSARC/2007/328 zfs upgrade
ahrens
parents: 4543
diff changeset
  2512
	{ zfs_ioc_snapshot, zfs_secpolicy_snapshot, DATASET_NAME, B_TRUE },
ed36b0e652bc PSARC/2007/328 zfs upgrade
ahrens
parents: 4543
diff changeset
  2513
	{ zfs_ioc_dsobj_to_dsname, zfs_secpolicy_config, POOL_NAME, B_FALSE },
ed36b0e652bc PSARC/2007/328 zfs upgrade
ahrens
parents: 4543
diff changeset
  2514
	{ zfs_ioc_obj_to_path, zfs_secpolicy_config, NO_NAME, B_FALSE },
ed36b0e652bc PSARC/2007/328 zfs upgrade
ahrens
parents: 4543
diff changeset
  2515
	{ zfs_ioc_pool_set_props, zfs_secpolicy_config,	POOL_NAME, B_TRUE },
ed36b0e652bc PSARC/2007/328 zfs upgrade
ahrens
parents: 4543
diff changeset
  2516
	{ zfs_ioc_pool_get_props, zfs_secpolicy_read, POOL_NAME, B_FALSE },
ed36b0e652bc PSARC/2007/328 zfs upgrade
ahrens
parents: 4543
diff changeset
  2517
	{ zfs_ioc_set_fsacl, zfs_secpolicy_fsacl, DATASET_NAME, B_TRUE },
ed36b0e652bc PSARC/2007/328 zfs upgrade
ahrens
parents: 4543
diff changeset
  2518
	{ zfs_ioc_get_fsacl, zfs_secpolicy_read, DATASET_NAME, B_FALSE },
4543
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  2519
	{ zfs_ioc_iscsi_perm_check, zfs_secpolicy_iscsi,
4577
ed36b0e652bc PSARC/2007/328 zfs upgrade
ahrens
parents: 4543
diff changeset
  2520
	    DATASET_NAME, B_FALSE },
4849
3a61e0a9a953 6536043 arc_byteswap_func_t and dmu_byteswap_func_t are redundant
ahrens
parents: 4808
diff changeset
  2521
	{ 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
  2522
	{ zfs_ioc_inherit_prop, zfs_secpolicy_inherit, DATASET_NAME, B_TRUE },
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2523
};
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2524
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2525
static int
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2526
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
  2527
{
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2528
	zfs_cmd_t *zc;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2529
	uint_t vec;
2199
712a788c2dfd PSARC 2006/388 snapshot -r
ahrens
parents: 2082
diff changeset
  2530
	int error, rc;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2531
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2532
	if (getminor(dev) != 0)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2533
		return (zvol_ioctl(dev, cmd, arg, flag, cr, rvalp));
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2534
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2535
	vec = cmd - ZFS_IOC;
4787
602d3f97842c 6393351 unique_* could be improved
ahrens
parents: 4720
diff changeset
  2536
	ASSERT3U(getmajor(dev), ==, ddi_driver_major(zfs_dip));
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2537
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2538
	if (vec >= sizeof (zfs_ioc_vec) / sizeof (zfs_ioc_vec[0]))
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2539
		return (EINVAL);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2540
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2541
	zc = kmem_zalloc(sizeof (zfs_cmd_t), KM_SLEEP);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2542
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2543
	error = xcopyin((void *)arg, zc, sizeof (zfs_cmd_t));
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2544
4787
602d3f97842c 6393351 unique_* could be improved
ahrens
parents: 4720
diff changeset
  2545
	if (error == 0)
4543
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  2546
		error = zfs_ioc_vec[vec].zvec_secpolicy(zc, cr);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2547
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2548
	/*
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2549
	 * Ensure that all pool/dataset names are valid before we pass down to
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2550
	 * the lower layers.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2551
	 */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2552
	if (error == 0) {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2553
		zc->zc_name[sizeof (zc->zc_name) - 1] = '\0';
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2554
		switch (zfs_ioc_vec[vec].zvec_namecheck) {
4577
ed36b0e652bc PSARC/2007/328 zfs upgrade
ahrens
parents: 4543
diff changeset
  2555
		case POOL_NAME:
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2556
			if (pool_namecheck(zc->zc_name, NULL, NULL) != 0)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2557
				error = EINVAL;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2558
			break;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2559
4577
ed36b0e652bc PSARC/2007/328 zfs upgrade
ahrens
parents: 4543
diff changeset
  2560
		case DATASET_NAME:
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2561
			if (dataset_namecheck(zc->zc_name, NULL, NULL) != 0)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2562
				error = EINVAL;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2563
			break;
2856
6f4d5ee1906a 6463348 ZFS code could be more portable
nd150628
parents: 2717
diff changeset
  2564
4577
ed36b0e652bc PSARC/2007/328 zfs upgrade
ahrens
parents: 4543
diff changeset
  2565
		case NO_NAME:
2856
6f4d5ee1906a 6463348 ZFS code could be more portable
nd150628
parents: 2717
diff changeset
  2566
			break;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2567
		}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2568
	}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2569
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2570
	if (error == 0)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2571
		error = zfs_ioc_vec[vec].zvec_func(zc);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2572
2199
712a788c2dfd PSARC 2006/388 snapshot -r
ahrens
parents: 2082
diff changeset
  2573
	rc = xcopyout(zc, (void *)arg, sizeof (zfs_cmd_t));
4543
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  2574
	if (error == 0) {
2199
712a788c2dfd PSARC 2006/388 snapshot -r
ahrens
parents: 2082
diff changeset
  2575
		error = rc;
4543
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  2576
		if (zfs_ioc_vec[vec].zvec_his_log == B_TRUE)
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  2577
			zfs_log_history(zc);
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  2578
	}
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2579
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2580
	kmem_free(zc, sizeof (zfs_cmd_t));
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2581
	return (error);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2582
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2583
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2584
static int
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2585
zfs_attach(dev_info_t *dip, ddi_attach_cmd_t cmd)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2586
{
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2587
	if (cmd != DDI_ATTACH)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2588
		return (DDI_FAILURE);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2589
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2590
	if (ddi_create_minor_node(dip, "zfs", S_IFCHR, 0,
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2591
	    DDI_PSEUDO, 0) == DDI_FAILURE)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2592
		return (DDI_FAILURE);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2593
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2594
	zfs_dip = dip;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2595
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2596
	ddi_report_dev(dip);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2597
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2598
	return (DDI_SUCCESS);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2599
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2600
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2601
static int
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2602
zfs_detach(dev_info_t *dip, ddi_detach_cmd_t cmd)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2603
{
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2604
	if (spa_busy() || zfs_busy() || zvol_busy())
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2605
		return (DDI_FAILURE);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2606
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2607
	if (cmd != DDI_DETACH)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2608
		return (DDI_FAILURE);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2609
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2610
	zfs_dip = NULL;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2611
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2612
	ddi_prop_remove_all(dip);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2613
	ddi_remove_minor_node(dip, NULL);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2614
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2615
	return (DDI_SUCCESS);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2616
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2617
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2618
/*ARGSUSED*/
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2619
static int
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2620
zfs_info(dev_info_t *dip, ddi_info_cmd_t infocmd, void *arg, void **result)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2621
{
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2622
	switch (infocmd) {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2623
	case DDI_INFO_DEVT2DEVINFO:
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2624
		*result = zfs_dip;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2625
		return (DDI_SUCCESS);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2626
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2627
	case DDI_INFO_DEVT2INSTANCE:
849
8d799fd81a9b 6345023 /dev/zfs fails to open once ZFS module is unloaded
bonwick
parents: 789
diff changeset
  2628
		*result = (void *)0;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2629
		return (DDI_SUCCESS);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2630
	}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2631
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2632
	return (DDI_FAILURE);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2633
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2634
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2635
/*
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2636
 * OK, so this is a little weird.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2637
 *
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2638
 * /dev/zfs is the control node, i.e. minor 0.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2639
 * /dev/zvol/[r]dsk/pool/dataset are the zvols, minor > 0.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2640
 *
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2641
 * /dev/zfs has basically nothing to do except serve up ioctls,
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2642
 * so most of the standard driver entry points are in zvol.c.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2643
 */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2644
static struct cb_ops zfs_cb_ops = {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2645
	zvol_open,	/* open */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2646
	zvol_close,	/* close */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2647
	zvol_strategy,	/* strategy */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2648
	nodev,		/* print */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2649
	nodev,		/* dump */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2650
	zvol_read,	/* read */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2651
	zvol_write,	/* write */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2652
	zfsdev_ioctl,	/* ioctl */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2653
	nodev,		/* devmap */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2654
	nodev,		/* mmap */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2655
	nodev,		/* segmap */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2656
	nochpoll,	/* poll */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2657
	ddi_prop_op,	/* prop_op */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2658
	NULL,		/* streamtab */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2659
	D_NEW | D_MP | D_64BIT,		/* Driver compatibility flag */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2660
	CB_REV,		/* version */
3638
6b28ebc717aa 6496357 spec_fsync() is useless on devices that do write caching
billm
parents: 3444
diff changeset
  2661
	nodev,		/* async read */
6b28ebc717aa 6496357 spec_fsync() is useless on devices that do write caching
billm
parents: 3444
diff changeset
  2662
	nodev,		/* async write */
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2663
};
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2664
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2665
static struct dev_ops zfs_dev_ops = {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2666
	DEVO_REV,	/* version */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2667
	0,		/* refcnt */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2668
	zfs_info,	/* info */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2669
	nulldev,	/* identify */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2670
	nulldev,	/* probe */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2671
	zfs_attach,	/* attach */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2672
	zfs_detach,	/* detach */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2673
	nodev,		/* reset */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2674
	&zfs_cb_ops,	/* driver operations */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2675
	NULL		/* no bus operations */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2676
};
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2677
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2678
static struct modldrv zfs_modldrv = {
4577
ed36b0e652bc PSARC/2007/328 zfs upgrade
ahrens
parents: 4543
diff changeset
  2679
	&mod_driverops, "ZFS storage pool version " SPA_VERSION_STRING,
2676
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  2680
	    &zfs_dev_ops
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2681
};
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2682
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2683
static struct modlinkage modlinkage = {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2684
	MODREV_1,
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2685
	(void *)&zfs_modlfs,
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2686
	(void *)&zfs_modldrv,
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2687
	NULL
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2688
};
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2689
4720
8edc0d2e6f3f 6535160 Lock contention on zl_lock from zil_commit
fr157268
parents: 4715
diff changeset
  2690
8edc0d2e6f3f 6535160 Lock contention on zl_lock from zil_commit
fr157268
parents: 4715
diff changeset
  2691
uint_t zfs_fsyncer_key;
5326
6752aa2bd5bc 6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents: 5147
diff changeset
  2692
extern uint_t rrw_tsd_key;
4720
8edc0d2e6f3f 6535160 Lock contention on zl_lock from zil_commit
fr157268
parents: 4715
diff changeset
  2693
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2694
int
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2695
_init(void)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2696
{
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2697
	int error;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2698
849
8d799fd81a9b 6345023 /dev/zfs fails to open once ZFS module is unloaded
bonwick
parents: 789
diff changeset
  2699
	spa_init(FREAD | FWRITE);
8d799fd81a9b 6345023 /dev/zfs fails to open once ZFS module is unloaded
bonwick
parents: 789
diff changeset
  2700
	zfs_init();
8d799fd81a9b 6345023 /dev/zfs fails to open once ZFS module is unloaded
bonwick
parents: 789
diff changeset
  2701
	zvol_init();
8d799fd81a9b 6345023 /dev/zfs fails to open once ZFS module is unloaded
bonwick
parents: 789
diff changeset
  2702
8d799fd81a9b 6345023 /dev/zfs fails to open once ZFS module is unloaded
bonwick
parents: 789
diff changeset
  2703
	if ((error = mod_install(&modlinkage)) != 0) {
8d799fd81a9b 6345023 /dev/zfs fails to open once ZFS module is unloaded
bonwick
parents: 789
diff changeset
  2704
		zvol_fini();
8d799fd81a9b 6345023 /dev/zfs fails to open once ZFS module is unloaded
bonwick
parents: 789
diff changeset
  2705
		zfs_fini();
8d799fd81a9b 6345023 /dev/zfs fails to open once ZFS module is unloaded
bonwick
parents: 789
diff changeset
  2706
		spa_fini();
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2707
		return (error);
849
8d799fd81a9b 6345023 /dev/zfs fails to open once ZFS module is unloaded
bonwick
parents: 789
diff changeset
  2708
	}
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2709
4720
8edc0d2e6f3f 6535160 Lock contention on zl_lock from zil_commit
fr157268
parents: 4715
diff changeset
  2710
	tsd_create(&zfs_fsyncer_key, NULL);
5326
6752aa2bd5bc 6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents: 5147
diff changeset
  2711
	tsd_create(&rrw_tsd_key, NULL);
4720
8edc0d2e6f3f 6535160 Lock contention on zl_lock from zil_commit
fr157268
parents: 4715
diff changeset
  2712
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2713
	error = ldi_ident_from_mod(&modlinkage, &zfs_li);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2714
	ASSERT(error == 0);
4543
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  2715
	mutex_init(&zfs_share_lock, NULL, MUTEX_DEFAULT, NULL);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2716
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2717
	return (0);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2718
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2719
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2720
int
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2721
_fini(void)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2722
{
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2723
	int error;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2724
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
  2725
	if (spa_busy() || zfs_busy() || zvol_busy() || zio_injection_enabled)
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2726
		return (EBUSY);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2727
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2728
	if ((error = mod_remove(&modlinkage)) != 0)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2729
		return (error);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2730
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2731
	zvol_fini();
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2732
	zfs_fini();
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2733
	spa_fini();
5331
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
  2734
	if (zfs_nfsshare_inited)
4543
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  2735
		(void) ddi_modclose(nfs_mod);
5331
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
  2736
	if (zfs_smbshare_inited)
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
  2737
		(void) ddi_modclose(smbsrv_mod);
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
  2738
	if (zfs_nfsshare_inited || zfs_smbshare_inited)
4543
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  2739
		(void) ddi_modclose(sharefs_mod);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2740
4720
8edc0d2e6f3f 6535160 Lock contention on zl_lock from zil_commit
fr157268
parents: 4715
diff changeset
  2741
	tsd_destroy(&zfs_fsyncer_key);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2742
	ldi_ident_release(zfs_li);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2743
	zfs_li = NULL;
4543
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  2744
	mutex_destroy(&zfs_share_lock);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2745
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2746
	return (error);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2747
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2748
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2749
int
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2750
_info(struct modinfo *modinfop)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2751
{
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2752
	return (mod_info(&modlinkage, modinfop));
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2753
}