usr/src/uts/common/fs/zfs/zfs_ioctl.c
author Chris Kirby <Chris.Kirby@oracle.com>
Thu, 10 Jun 2010 15:46:47 -0600
changeset 12605 6790e683d5a5
parent 12527 693dd2cad55f
child 12620 12fcd99a642d
permissions -rw-r--r--
6959846 DMU traverse prefetch size should be a global tunable
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
/*
12296
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 11935
diff changeset
    22
 * Copyright (c) 2005, 2010, Oracle and/or its affiliates. All rights reserved.
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    23
 */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    24
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    25
#include <sys/types.h>
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    26
#include <sys/param.h>
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    27
#include <sys/errno.h>
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    28
#include <sys/uio.h>
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    29
#include <sys/buf.h>
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    30
#include <sys/modctl.h>
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    31
#include <sys/open.h>
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    32
#include <sys/file.h>
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    33
#include <sys/kmem.h>
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    34
#include <sys/conf.h>
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    35
#include <sys/cmn_err.h>
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    36
#include <sys/stat.h>
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    37
#include <sys/zfs_ioctl.h>
10972
807794d41b3a PSARC 2009/348 Security Labels for ZFS
Ric Aleshire <Ric.Aleshire@Sun.COM>
parents: 10969
diff changeset
    38
#include <sys/zfs_vfsops.h>
5331
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
    39
#include <sys/zfs_znode.h>
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    40
#include <sys/zap.h>
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    41
#include <sys/spa.h>
3912
f6891a60bd72 PSARC 2007/083 ZFS bootable datasets
lling
parents: 3886
diff changeset
    42
#include <sys/spa_impl.h>
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    43
#include <sys/vdev.h>
10972
807794d41b3a PSARC 2009/348 Security Labels for ZFS
Ric Aleshire <Ric.Aleshire@Sun.COM>
parents: 10969
diff changeset
    44
#include <sys/priv_impl.h>
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    45
#include <sys/dmu.h>
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    46
#include <sys/dsl_dir.h>
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    47
#include <sys/dsl_dataset.h>
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    48
#include <sys/dsl_prop.h>
4543
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
    49
#include <sys/dsl_deleg.h>
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
    50
#include <sys/dmu_objset.h>
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    51
#include <sys/ddi.h>
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    52
#include <sys/sunddi.h>
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    53
#include <sys/sunldi.h>
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    54
#include <sys/policy.h>
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    55
#include <sys/zone.h>
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    56
#include <sys/nvpair.h>
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    57
#include <sys/pathname.h>
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    58
#include <sys/mount.h>
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    59
#include <sys/sdt.h>
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    60
#include <sys/fs/zfs.h>
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    61
#include <sys/zfs_ctldir.h>
5331
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
    62
#include <sys/zfs_dir.h>
12527
693dd2cad55f 6884007 zfs_send() can leave temporary holds around
Chris Kirby <Chris.Kirby@oracle.com>
parents: 12296
diff changeset
    63
#include <sys/zfs_onexit.h>
2885
c0259887ebbc 6460059 zfs destroy <snapshot> leaves behind kruft
ahrens
parents: 2856
diff changeset
    64
#include <sys/zvol.h>
12296
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 11935
diff changeset
    65
#include <sys/dsl_scan.h>
4543
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
    66
#include <sharefs/share.h>
5326
6752aa2bd5bc 6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents: 5147
diff changeset
    67
#include <sys/dmu_objset.h>
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    68
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    69
#include "zfs_namecheck.h"
2676
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
    70
#include "zfs_prop.h"
4543
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
    71
#include "zfs_deleg.h"
11935
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11933
diff changeset
    72
#include "zfs_comutil.h"
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    73
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    74
extern struct modlfs zfs_modlfs;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    75
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    76
extern void zfs_init(void);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    77
extern void zfs_fini(void);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    78
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    79
ldi_ident_t zfs_li = NULL;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    80
dev_info_t *zfs_dip;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    81
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    82
typedef int zfs_ioc_func_t(zfs_cmd_t *);
4543
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
    83
typedef int zfs_secpolicy_func_t(zfs_cmd_t *, cred_t *);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    84
9234
bffdc4fc05c4 6792139 recovering from a suspended pool needs some work
George Wilson <George.Wilson@Sun.COM>
parents: 9179
diff changeset
    85
typedef enum {
bffdc4fc05c4 6792139 recovering from a suspended pool needs some work
George Wilson <George.Wilson@Sun.COM>
parents: 9179
diff changeset
    86
	NO_NAME,
bffdc4fc05c4 6792139 recovering from a suspended pool needs some work
George Wilson <George.Wilson@Sun.COM>
parents: 9179
diff changeset
    87
	POOL_NAME,
bffdc4fc05c4 6792139 recovering from a suspended pool needs some work
George Wilson <George.Wilson@Sun.COM>
parents: 9179
diff changeset
    88
	DATASET_NAME
bffdc4fc05c4 6792139 recovering from a suspended pool needs some work
George Wilson <George.Wilson@Sun.COM>
parents: 9179
diff changeset
    89
} zfs_ioc_namecheck_t;
bffdc4fc05c4 6792139 recovering from a suspended pool needs some work
George Wilson <George.Wilson@Sun.COM>
parents: 9179
diff changeset
    90
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    91
typedef struct zfs_ioc_vec {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    92
	zfs_ioc_func_t		*zvec_func;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    93
	zfs_secpolicy_func_t	*zvec_secpolicy;
9234
bffdc4fc05c4 6792139 recovering from a suspended pool needs some work
George Wilson <George.Wilson@Sun.COM>
parents: 9179
diff changeset
    94
	zfs_ioc_namecheck_t	zvec_namecheck;
4543
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
    95
	boolean_t		zvec_his_log;
9234
bffdc4fc05c4 6792139 recovering from a suspended pool needs some work
George Wilson <George.Wilson@Sun.COM>
parents: 9179
diff changeset
    96
	boolean_t		zvec_pool_check;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    97
} zfs_ioc_vec_t;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    98
9396
f41cf682d0d3 PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 9355
diff changeset
    99
/* This array is indexed by zfs_userquota_prop_t */
f41cf682d0d3 PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 9355
diff changeset
   100
static const char *userquota_perms[] = {
f41cf682d0d3 PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 9355
diff changeset
   101
	ZFS_DELEG_PERM_USERUSED,
f41cf682d0d3 PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 9355
diff changeset
   102
	ZFS_DELEG_PERM_USERQUOTA,
f41cf682d0d3 PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 9355
diff changeset
   103
	ZFS_DELEG_PERM_GROUPUSED,
f41cf682d0d3 PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 9355
diff changeset
   104
	ZFS_DELEG_PERM_GROUPQUOTA,
f41cf682d0d3 PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 9355
diff changeset
   105
};
f41cf682d0d3 PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 9355
diff changeset
   106
f41cf682d0d3 PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 9355
diff changeset
   107
static int zfs_ioc_userspace_upgrade(zfs_cmd_t *zc);
11022
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 11007
diff changeset
   108
static int zfs_check_settable(const char *name, nvpair_t *property,
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 11007
diff changeset
   109
    cred_t *cr);
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 11007
diff changeset
   110
static int zfs_check_clearable(char *dataset, nvlist_t *props,
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 11007
diff changeset
   111
    nvlist_t **errors);
7184
9508660f9c27 PSARC 2008/223 Pool root file system properties via zpool(1M)
timh
parents: 7046
diff changeset
   112
static int zfs_fill_zplprops_root(uint64_t, nvlist_t *, nvlist_t *,
9508660f9c27 PSARC 2008/223 Pool root file system properties via zpool(1M)
timh
parents: 7046
diff changeset
   113
    boolean_t *);
11022
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 11007
diff changeset
   114
int zfs_set_prop_nvlist(const char *, zprop_source_t, nvlist_t *, nvlist_t **);
7184
9508660f9c27 PSARC 2008/223 Pool root file system properties via zpool(1M)
timh
parents: 7046
diff changeset
   115
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   116
/* _NOTE(PRINTFLIKE(4)) - this is printf-like, but lint is too whiney */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   117
void
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   118
__dprintf(const char *file, const char *func, int line, const char *fmt, ...)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   119
{
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   120
	const char *newfile;
12296
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 11935
diff changeset
   121
	char buf[512];
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   122
	va_list adx;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   123
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   124
	/*
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   125
	 * Get rid of annoying "../common/" prefix to filename.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   126
	 */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   127
	newfile = strrchr(file, '/');
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   128
	if (newfile != NULL) {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   129
		newfile = newfile + 1; /* Get rid of leading / */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   130
	} else {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   131
		newfile = file;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   132
	}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   133
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   134
	va_start(adx, fmt);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   135
	(void) vsnprintf(buf, sizeof (buf), fmt, adx);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   136
	va_end(adx);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   137
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   138
	/*
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   139
	 * To get this data, use the zfs-dprintf probe as so:
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   140
	 * dtrace -q -n 'zfs-dprintf \
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   141
	 *	/stringof(arg0) == "dbuf.c"/ \
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   142
	 *	{printf("%s: %s", stringof(arg1), stringof(arg3))}'
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   143
	 * arg0 = file name
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   144
	 * arg1 = function name
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   145
	 * arg2 = line number
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   146
	 * arg3 = message
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   147
	 */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   148
	DTRACE_PROBE4(zfs__dprintf,
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   149
	    char *, newfile, char *, func, int, line, char *, buf);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   150
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   151
4543
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   152
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
   153
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
   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
	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
   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
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
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
   159
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
   160
{
e8d212dda064 6535695 Panic: shpp->sh_eof == shpp->sh_pool_create_len, file: ../../common/fs/zfs/spa_history.c, line: 235
ek110237
parents: 4670
diff changeset
   161
	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
   162
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
   163
	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
   164
		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
   165
e8d212dda064 6535695 Panic: shpp->sh_eof == shpp->sh_pool_create_len, file: ../../common/fs/zfs/spa_history.c, line: 235
ek110237
parents: 4670
diff changeset
   166
	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
   167
	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
   168
	    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
   169
		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
   170
		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
   171
	}
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
   172
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
   173
	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
   174
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
   175
	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
   176
}
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
   177
5375
c682f8c5f5e3 6622822 can not create clone on old version pool
timh
parents: 5367
diff changeset
   178
/*
7042
46fc4b6db23e 6721094 Setting certain properties on root pools should not be allowed
gw25295
parents: 6865
diff changeset
   179
 * Check to see if the named dataset is currently defined as bootable
46fc4b6db23e 6721094 Setting certain properties on root pools should not be allowed
gw25295
parents: 6865
diff changeset
   180
 */
46fc4b6db23e 6721094 Setting certain properties on root pools should not be allowed
gw25295
parents: 6865
diff changeset
   181
static boolean_t
46fc4b6db23e 6721094 Setting certain properties on root pools should not be allowed
gw25295
parents: 6865
diff changeset
   182
zfs_is_bootfs(const char *name)
46fc4b6db23e 6721094 Setting certain properties on root pools should not be allowed
gw25295
parents: 6865
diff changeset
   183
{
10298
a0d52501437c 6860996 %temporary clones are not automatically destroyed on error
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 10272
diff changeset
   184
	objset_t *os;
a0d52501437c 6860996 %temporary clones are not automatically destroyed on error
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 10272
diff changeset
   185
a0d52501437c 6860996 %temporary clones are not automatically destroyed on error
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 10272
diff changeset
   186
	if (dmu_objset_hold(name, FTAG, &os) == 0) {
a0d52501437c 6860996 %temporary clones are not automatically destroyed on error
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 10272
diff changeset
   187
		boolean_t ret;
10922
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
   188
		ret = (dmu_objset_id(os) == spa_bootfs(dmu_objset_spa(os)));
10298
a0d52501437c 6860996 %temporary clones are not automatically destroyed on error
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 10272
diff changeset
   189
		dmu_objset_rele(os, FTAG);
a0d52501437c 6860996 %temporary clones are not automatically destroyed on error
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 10272
diff changeset
   190
		return (ret);
7042
46fc4b6db23e 6721094 Setting certain properties on root pools should not be allowed
gw25295
parents: 6865
diff changeset
   191
	}
10298
a0d52501437c 6860996 %temporary clones are not automatically destroyed on error
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 10272
diff changeset
   192
	return (B_FALSE);
7042
46fc4b6db23e 6721094 Setting certain properties on root pools should not be allowed
gw25295
parents: 6865
diff changeset
   193
}
46fc4b6db23e 6721094 Setting certain properties on root pools should not be allowed
gw25295
parents: 6865
diff changeset
   194
46fc4b6db23e 6721094 Setting certain properties on root pools should not be allowed
gw25295
parents: 6865
diff changeset
   195
/*
7184
9508660f9c27 PSARC 2008/223 Pool root file system properties via zpool(1M)
timh
parents: 7046
diff changeset
   196
 * zfs_earlier_version
5375
c682f8c5f5e3 6622822 can not create clone on old version pool
timh
parents: 5367
diff changeset
   197
 *
c682f8c5f5e3 6622822 can not create clone on old version pool
timh
parents: 5367
diff changeset
   198
 *	Return non-zero if the spa version is less than requested version.
c682f8c5f5e3 6622822 can not create clone on old version pool
timh
parents: 5367
diff changeset
   199
 */
5331
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
   200
static int
7184
9508660f9c27 PSARC 2008/223 Pool root file system properties via zpool(1M)
timh
parents: 7046
diff changeset
   201
zfs_earlier_version(const char *name, int version)
5331
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
   202
{
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
   203
	spa_t *spa;
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
   204
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
   205
	if (spa_open(name, &spa, FTAG) == 0) {
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
   206
		if (spa_version(spa) < version) {
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
   207
			spa_close(spa, FTAG);
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
   208
			return (1);
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
   209
		}
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
   210
		spa_close(spa, FTAG);
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
   211
	}
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
   212
	return (0);
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
   213
}
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
   214
5977
33727f49aeaa 6654731 sharesmb property should only be settable on CIFS aware ZPL
marks
parents: 5663
diff changeset
   215
/*
6689
47572a2f5e73 6610506 Eliminate or improve retry logic from callers of dmu_objset_open()
maybee
parents: 6643
diff changeset
   216
 * zpl_earlier_version
5977
33727f49aeaa 6654731 sharesmb property should only be settable on CIFS aware ZPL
marks
parents: 5663
diff changeset
   217
 *
6689
47572a2f5e73 6610506 Eliminate or improve retry logic from callers of dmu_objset_open()
maybee
parents: 6643
diff changeset
   218
 * Return TRUE if the ZPL version is less than requested version.
5977
33727f49aeaa 6654731 sharesmb property should only be settable on CIFS aware ZPL
marks
parents: 5663
diff changeset
   219
 */
6689
47572a2f5e73 6610506 Eliminate or improve retry logic from callers of dmu_objset_open()
maybee
parents: 6643
diff changeset
   220
static boolean_t
47572a2f5e73 6610506 Eliminate or improve retry logic from callers of dmu_objset_open()
maybee
parents: 6643
diff changeset
   221
zpl_earlier_version(const char *name, int version)
5977
33727f49aeaa 6654731 sharesmb property should only be settable on CIFS aware ZPL
marks
parents: 5663
diff changeset
   222
{
33727f49aeaa 6654731 sharesmb property should only be settable on CIFS aware ZPL
marks
parents: 5663
diff changeset
   223
	objset_t *os;
6689
47572a2f5e73 6610506 Eliminate or improve retry logic from callers of dmu_objset_open()
maybee
parents: 6643
diff changeset
   224
	boolean_t rc = B_TRUE;
5977
33727f49aeaa 6654731 sharesmb property should only be settable on CIFS aware ZPL
marks
parents: 5663
diff changeset
   225
10298
a0d52501437c 6860996 %temporary clones are not automatically destroyed on error
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 10272
diff changeset
   226
	if (dmu_objset_hold(name, FTAG, &os) == 0) {
6689
47572a2f5e73 6610506 Eliminate or improve retry logic from callers of dmu_objset_open()
maybee
parents: 6643
diff changeset
   227
		uint64_t zplversion;
47572a2f5e73 6610506 Eliminate or improve retry logic from callers of dmu_objset_open()
maybee
parents: 6643
diff changeset
   228
10298
a0d52501437c 6860996 %temporary clones are not automatically destroyed on error
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 10272
diff changeset
   229
		if (dmu_objset_type(os) != DMU_OST_ZFS) {
a0d52501437c 6860996 %temporary clones are not automatically destroyed on error
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 10272
diff changeset
   230
			dmu_objset_rele(os, FTAG);
a0d52501437c 6860996 %temporary clones are not automatically destroyed on error
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 10272
diff changeset
   231
			return (B_TRUE);
a0d52501437c 6860996 %temporary clones are not automatically destroyed on error
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 10272
diff changeset
   232
		}
a0d52501437c 6860996 %temporary clones are not automatically destroyed on error
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 10272
diff changeset
   233
		/* XXX reading from non-owned objset */
6689
47572a2f5e73 6610506 Eliminate or improve retry logic from callers of dmu_objset_open()
maybee
parents: 6643
diff changeset
   234
		if (zfs_get_zplprop(os, ZFS_PROP_VERSION, &zplversion) == 0)
47572a2f5e73 6610506 Eliminate or improve retry logic from callers of dmu_objset_open()
maybee
parents: 6643
diff changeset
   235
			rc = zplversion < version;
10298
a0d52501437c 6860996 %temporary clones are not automatically destroyed on error
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 10272
diff changeset
   236
		dmu_objset_rele(os, FTAG);
5977
33727f49aeaa 6654731 sharesmb property should only be settable on CIFS aware ZPL
marks
parents: 5663
diff changeset
   237
	}
33727f49aeaa 6654731 sharesmb property should only be settable on CIFS aware ZPL
marks
parents: 5663
diff changeset
   238
	return (rc);
33727f49aeaa 6654731 sharesmb property should only be settable on CIFS aware ZPL
marks
parents: 5663
diff changeset
   239
}
33727f49aeaa 6654731 sharesmb property should only be settable on CIFS aware ZPL
marks
parents: 5663
diff changeset
   240
4715
e8d212dda064 6535695 Panic: shpp->sh_eof == shpp->sh_pool_create_len, file: ../../common/fs/zfs/spa_history.c, line: 235
ek110237
parents: 4670
diff changeset
   241
static void
4543
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   242
zfs_log_history(zfs_cmd_t *zc)
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   243
{
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   244
	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
   245
	char *buf;
4543
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   246
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
   247
	if ((buf = history_str_get(zc)) == NULL)
4577
ed36b0e652bc PSARC/2007/328 zfs upgrade
ahrens
parents: 4543
diff changeset
   248
		return;
ed36b0e652bc PSARC/2007/328 zfs upgrade
ahrens
parents: 4543
diff changeset
   249
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
   250
	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
   251
		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
   252
			(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
   253
		spa_close(spa, FTAG);
4543
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   254
	}
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
   255
	history_str_free(buf);
4543
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   256
}
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   257
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   258
/*
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   259
 * Policy for top-level read operations (list pools).  Requires no privileges,
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   260
 * and can be used in the local zone, as there is no associated dataset.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   261
 */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   262
/* ARGSUSED */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   263
static int
4543
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   264
zfs_secpolicy_none(zfs_cmd_t *zc, cred_t *cr)
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   265
{
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   266
	return (0);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   267
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   268
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   269
/*
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   270
 * Policy for dataset read operations (list children, get statistics).  Requires
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   271
 * no privileges, but must be visible in the local zone.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   272
 */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   273
/* ARGSUSED */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   274
static int
4543
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   275
zfs_secpolicy_read(zfs_cmd_t *zc, cred_t *cr)
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   276
{
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   277
	if (INGLOBALZONE(curproc) ||
4543
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   278
	    zone_dataset_visible(zc->zc_name, NULL))
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   279
		return (0);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   280
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   281
	return (ENOENT);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   282
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   283
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   284
static int
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   285
zfs_dozonecheck(const char *dataset, cred_t *cr)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   286
{
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   287
	uint64_t zoned;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   288
	int writable = 1;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   289
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   290
	/*
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   291
	 * The dataset must be visible by this zone -- check this first
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   292
	 * so they don't see EPERM on something they shouldn't know about.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   293
	 */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   294
	if (!INGLOBALZONE(curproc) &&
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   295
	    !zone_dataset_visible(dataset, &writable))
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   296
		return (ENOENT);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   297
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   298
	if (dsl_prop_get_integer(dataset, "zoned", &zoned, NULL))
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   299
		return (ENOENT);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   300
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   301
	if (INGLOBALZONE(curproc)) {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   302
		/*
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   303
		 * If the fs is zoned, only root can access it from the
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   304
		 * global zone.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   305
		 */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   306
		if (secpolicy_zfs(cr) && zoned)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   307
			return (EPERM);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   308
	} else {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   309
		/*
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   310
		 * If we are in a local zone, the 'zoned' property must be set.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   311
		 */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   312
		if (!zoned)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   313
			return (EPERM);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   314
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   315
		/* must be writable by this zone */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   316
		if (!writable)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   317
			return (EPERM);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   318
	}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   319
	return (0);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   320
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   321
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   322
int
4543
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   323
zfs_secpolicy_write_perms(const char *name, const char *perm, cred_t *cr)
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   324
{
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   325
	int error;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   326
4543
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   327
	error = zfs_dozonecheck(name, cr);
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   328
	if (error == 0) {
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   329
		error = secpolicy_zfs(cr);
4670
002728040e28 6580745 "zfs inherit" can be executed by ordinary user
ahrens
parents: 4611
diff changeset
   330
		if (error)
4543
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   331
			error = dsl_deleg_access(name, perm, cr);
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   332
	}
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   333
	return (error);
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
10972
807794d41b3a PSARC 2009/348 Security Labels for ZFS
Ric Aleshire <Ric.Aleshire@Sun.COM>
parents: 10969
diff changeset
   336
/*
807794d41b3a PSARC 2009/348 Security Labels for ZFS
Ric Aleshire <Ric.Aleshire@Sun.COM>
parents: 10969
diff changeset
   337
 * Policy for setting the security label property.
807794d41b3a PSARC 2009/348 Security Labels for ZFS
Ric Aleshire <Ric.Aleshire@Sun.COM>
parents: 10969
diff changeset
   338
 *
807794d41b3a PSARC 2009/348 Security Labels for ZFS
Ric Aleshire <Ric.Aleshire@Sun.COM>
parents: 10969
diff changeset
   339
 * Returns 0 for success, non-zero for access and other errors.
807794d41b3a PSARC 2009/348 Security Labels for ZFS
Ric Aleshire <Ric.Aleshire@Sun.COM>
parents: 10969
diff changeset
   340
 */
807794d41b3a PSARC 2009/348 Security Labels for ZFS
Ric Aleshire <Ric.Aleshire@Sun.COM>
parents: 10969
diff changeset
   341
static int
11022
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 11007
diff changeset
   342
zfs_set_slabel_policy(const char *name, char *strval, cred_t *cr)
10972
807794d41b3a PSARC 2009/348 Security Labels for ZFS
Ric Aleshire <Ric.Aleshire@Sun.COM>
parents: 10969
diff changeset
   343
{
807794d41b3a PSARC 2009/348 Security Labels for ZFS
Ric Aleshire <Ric.Aleshire@Sun.COM>
parents: 10969
diff changeset
   344
	char		ds_hexsl[MAXNAMELEN];
807794d41b3a PSARC 2009/348 Security Labels for ZFS
Ric Aleshire <Ric.Aleshire@Sun.COM>
parents: 10969
diff changeset
   345
	bslabel_t	ds_sl, new_sl;
807794d41b3a PSARC 2009/348 Security Labels for ZFS
Ric Aleshire <Ric.Aleshire@Sun.COM>
parents: 10969
diff changeset
   346
	boolean_t	new_default = FALSE;
807794d41b3a PSARC 2009/348 Security Labels for ZFS
Ric Aleshire <Ric.Aleshire@Sun.COM>
parents: 10969
diff changeset
   347
	uint64_t	zoned;
807794d41b3a PSARC 2009/348 Security Labels for ZFS
Ric Aleshire <Ric.Aleshire@Sun.COM>
parents: 10969
diff changeset
   348
	int		needed_priv = -1;
807794d41b3a PSARC 2009/348 Security Labels for ZFS
Ric Aleshire <Ric.Aleshire@Sun.COM>
parents: 10969
diff changeset
   349
	int		error;
807794d41b3a PSARC 2009/348 Security Labels for ZFS
Ric Aleshire <Ric.Aleshire@Sun.COM>
parents: 10969
diff changeset
   350
807794d41b3a PSARC 2009/348 Security Labels for ZFS
Ric Aleshire <Ric.Aleshire@Sun.COM>
parents: 10969
diff changeset
   351
	/* First get the existing dataset label. */
807794d41b3a PSARC 2009/348 Security Labels for ZFS
Ric Aleshire <Ric.Aleshire@Sun.COM>
parents: 10969
diff changeset
   352
	error = dsl_prop_get(name, zfs_prop_to_name(ZFS_PROP_MLSLABEL),
807794d41b3a PSARC 2009/348 Security Labels for ZFS
Ric Aleshire <Ric.Aleshire@Sun.COM>
parents: 10969
diff changeset
   353
	    1, sizeof (ds_hexsl), &ds_hexsl, NULL);
807794d41b3a PSARC 2009/348 Security Labels for ZFS
Ric Aleshire <Ric.Aleshire@Sun.COM>
parents: 10969
diff changeset
   354
	if (error)
807794d41b3a PSARC 2009/348 Security Labels for ZFS
Ric Aleshire <Ric.Aleshire@Sun.COM>
parents: 10969
diff changeset
   355
		return (EPERM);
807794d41b3a PSARC 2009/348 Security Labels for ZFS
Ric Aleshire <Ric.Aleshire@Sun.COM>
parents: 10969
diff changeset
   356
807794d41b3a PSARC 2009/348 Security Labels for ZFS
Ric Aleshire <Ric.Aleshire@Sun.COM>
parents: 10969
diff changeset
   357
	if (strcasecmp(strval, ZFS_MLSLABEL_DEFAULT) == 0)
807794d41b3a PSARC 2009/348 Security Labels for ZFS
Ric Aleshire <Ric.Aleshire@Sun.COM>
parents: 10969
diff changeset
   358
		new_default = TRUE;
807794d41b3a PSARC 2009/348 Security Labels for ZFS
Ric Aleshire <Ric.Aleshire@Sun.COM>
parents: 10969
diff changeset
   359
807794d41b3a PSARC 2009/348 Security Labels for ZFS
Ric Aleshire <Ric.Aleshire@Sun.COM>
parents: 10969
diff changeset
   360
	/* The label must be translatable */
807794d41b3a PSARC 2009/348 Security Labels for ZFS
Ric Aleshire <Ric.Aleshire@Sun.COM>
parents: 10969
diff changeset
   361
	if (!new_default && (hexstr_to_label(strval, &new_sl) != 0))
807794d41b3a PSARC 2009/348 Security Labels for ZFS
Ric Aleshire <Ric.Aleshire@Sun.COM>
parents: 10969
diff changeset
   362
		return (EINVAL);
807794d41b3a PSARC 2009/348 Security Labels for ZFS
Ric Aleshire <Ric.Aleshire@Sun.COM>
parents: 10969
diff changeset
   363
807794d41b3a PSARC 2009/348 Security Labels for ZFS
Ric Aleshire <Ric.Aleshire@Sun.COM>
parents: 10969
diff changeset
   364
	/*
807794d41b3a PSARC 2009/348 Security Labels for ZFS
Ric Aleshire <Ric.Aleshire@Sun.COM>
parents: 10969
diff changeset
   365
	 * In a non-global zone, disallow attempts to set a label that
807794d41b3a PSARC 2009/348 Security Labels for ZFS
Ric Aleshire <Ric.Aleshire@Sun.COM>
parents: 10969
diff changeset
   366
	 * doesn't match that of the zone; otherwise no other checks
807794d41b3a PSARC 2009/348 Security Labels for ZFS
Ric Aleshire <Ric.Aleshire@Sun.COM>
parents: 10969
diff changeset
   367
	 * are needed.
807794d41b3a PSARC 2009/348 Security Labels for ZFS
Ric Aleshire <Ric.Aleshire@Sun.COM>
parents: 10969
diff changeset
   368
	 */
807794d41b3a PSARC 2009/348 Security Labels for ZFS
Ric Aleshire <Ric.Aleshire@Sun.COM>
parents: 10969
diff changeset
   369
	if (!INGLOBALZONE(curproc)) {
807794d41b3a PSARC 2009/348 Security Labels for ZFS
Ric Aleshire <Ric.Aleshire@Sun.COM>
parents: 10969
diff changeset
   370
		if (new_default || !blequal(&new_sl, CR_SL(CRED())))
807794d41b3a PSARC 2009/348 Security Labels for ZFS
Ric Aleshire <Ric.Aleshire@Sun.COM>
parents: 10969
diff changeset
   371
			return (EPERM);
807794d41b3a PSARC 2009/348 Security Labels for ZFS
Ric Aleshire <Ric.Aleshire@Sun.COM>
parents: 10969
diff changeset
   372
		return (0);
807794d41b3a PSARC 2009/348 Security Labels for ZFS
Ric Aleshire <Ric.Aleshire@Sun.COM>
parents: 10969
diff changeset
   373
	}
807794d41b3a PSARC 2009/348 Security Labels for ZFS
Ric Aleshire <Ric.Aleshire@Sun.COM>
parents: 10969
diff changeset
   374
807794d41b3a PSARC 2009/348 Security Labels for ZFS
Ric Aleshire <Ric.Aleshire@Sun.COM>
parents: 10969
diff changeset
   375
	/*
807794d41b3a PSARC 2009/348 Security Labels for ZFS
Ric Aleshire <Ric.Aleshire@Sun.COM>
parents: 10969
diff changeset
   376
	 * For global-zone datasets (i.e., those whose zoned property is
807794d41b3a PSARC 2009/348 Security Labels for ZFS
Ric Aleshire <Ric.Aleshire@Sun.COM>
parents: 10969
diff changeset
   377
	 * "off", verify that the specified new label is valid for the
807794d41b3a PSARC 2009/348 Security Labels for ZFS
Ric Aleshire <Ric.Aleshire@Sun.COM>
parents: 10969
diff changeset
   378
	 * global zone.
807794d41b3a PSARC 2009/348 Security Labels for ZFS
Ric Aleshire <Ric.Aleshire@Sun.COM>
parents: 10969
diff changeset
   379
	 */
807794d41b3a PSARC 2009/348 Security Labels for ZFS
Ric Aleshire <Ric.Aleshire@Sun.COM>
parents: 10969
diff changeset
   380
	if (dsl_prop_get_integer(name,
807794d41b3a PSARC 2009/348 Security Labels for ZFS
Ric Aleshire <Ric.Aleshire@Sun.COM>
parents: 10969
diff changeset
   381
	    zfs_prop_to_name(ZFS_PROP_ZONED), &zoned, NULL))
807794d41b3a PSARC 2009/348 Security Labels for ZFS
Ric Aleshire <Ric.Aleshire@Sun.COM>
parents: 10969
diff changeset
   382
		return (EPERM);
807794d41b3a PSARC 2009/348 Security Labels for ZFS
Ric Aleshire <Ric.Aleshire@Sun.COM>
parents: 10969
diff changeset
   383
	if (!zoned) {
807794d41b3a PSARC 2009/348 Security Labels for ZFS
Ric Aleshire <Ric.Aleshire@Sun.COM>
parents: 10969
diff changeset
   384
		if (zfs_check_global_label(name, strval) != 0)
807794d41b3a PSARC 2009/348 Security Labels for ZFS
Ric Aleshire <Ric.Aleshire@Sun.COM>
parents: 10969
diff changeset
   385
			return (EPERM);
807794d41b3a PSARC 2009/348 Security Labels for ZFS
Ric Aleshire <Ric.Aleshire@Sun.COM>
parents: 10969
diff changeset
   386
	}
807794d41b3a PSARC 2009/348 Security Labels for ZFS
Ric Aleshire <Ric.Aleshire@Sun.COM>
parents: 10969
diff changeset
   387
807794d41b3a PSARC 2009/348 Security Labels for ZFS
Ric Aleshire <Ric.Aleshire@Sun.COM>
parents: 10969
diff changeset
   388
	/*
807794d41b3a PSARC 2009/348 Security Labels for ZFS
Ric Aleshire <Ric.Aleshire@Sun.COM>
parents: 10969
diff changeset
   389
	 * If the existing dataset label is nondefault, check if the
807794d41b3a PSARC 2009/348 Security Labels for ZFS
Ric Aleshire <Ric.Aleshire@Sun.COM>
parents: 10969
diff changeset
   390
	 * dataset is mounted (label cannot be changed while mounted).
807794d41b3a PSARC 2009/348 Security Labels for ZFS
Ric Aleshire <Ric.Aleshire@Sun.COM>
parents: 10969
diff changeset
   391
	 * Get the zfsvfs; if there isn't one, then the dataset isn't
807794d41b3a PSARC 2009/348 Security Labels for ZFS
Ric Aleshire <Ric.Aleshire@Sun.COM>
parents: 10969
diff changeset
   392
	 * mounted (or isn't a dataset, doesn't exist, ...).
807794d41b3a PSARC 2009/348 Security Labels for ZFS
Ric Aleshire <Ric.Aleshire@Sun.COM>
parents: 10969
diff changeset
   393
	 */
807794d41b3a PSARC 2009/348 Security Labels for ZFS
Ric Aleshire <Ric.Aleshire@Sun.COM>
parents: 10969
diff changeset
   394
	if (strcasecmp(ds_hexsl, ZFS_MLSLABEL_DEFAULT) != 0) {
11022
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 11007
diff changeset
   395
		objset_t *os;
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 11007
diff changeset
   396
		static char *setsl_tag = "setsl_tag";
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 11007
diff changeset
   397
10972
807794d41b3a PSARC 2009/348 Security Labels for ZFS
Ric Aleshire <Ric.Aleshire@Sun.COM>
parents: 10969
diff changeset
   398
		/*
807794d41b3a PSARC 2009/348 Security Labels for ZFS
Ric Aleshire <Ric.Aleshire@Sun.COM>
parents: 10969
diff changeset
   399
		 * Try to own the dataset; abort if there is any error,
807794d41b3a PSARC 2009/348 Security Labels for ZFS
Ric Aleshire <Ric.Aleshire@Sun.COM>
parents: 10969
diff changeset
   400
		 * (e.g., already mounted, in use, or other error).
807794d41b3a PSARC 2009/348 Security Labels for ZFS
Ric Aleshire <Ric.Aleshire@Sun.COM>
parents: 10969
diff changeset
   401
		 */
807794d41b3a PSARC 2009/348 Security Labels for ZFS
Ric Aleshire <Ric.Aleshire@Sun.COM>
parents: 10969
diff changeset
   402
		error = dmu_objset_own(name, DMU_OST_ZFS, B_TRUE,
11022
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 11007
diff changeset
   403
		    setsl_tag, &os);
10972
807794d41b3a PSARC 2009/348 Security Labels for ZFS
Ric Aleshire <Ric.Aleshire@Sun.COM>
parents: 10969
diff changeset
   404
		if (error)
807794d41b3a PSARC 2009/348 Security Labels for ZFS
Ric Aleshire <Ric.Aleshire@Sun.COM>
parents: 10969
diff changeset
   405
			return (EPERM);
807794d41b3a PSARC 2009/348 Security Labels for ZFS
Ric Aleshire <Ric.Aleshire@Sun.COM>
parents: 10969
diff changeset
   406
11022
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 11007
diff changeset
   407
		dmu_objset_disown(os, setsl_tag);
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 11007
diff changeset
   408
10972
807794d41b3a PSARC 2009/348 Security Labels for ZFS
Ric Aleshire <Ric.Aleshire@Sun.COM>
parents: 10969
diff changeset
   409
		if (new_default) {
807794d41b3a PSARC 2009/348 Security Labels for ZFS
Ric Aleshire <Ric.Aleshire@Sun.COM>
parents: 10969
diff changeset
   410
			needed_priv = PRIV_FILE_DOWNGRADE_SL;
807794d41b3a PSARC 2009/348 Security Labels for ZFS
Ric Aleshire <Ric.Aleshire@Sun.COM>
parents: 10969
diff changeset
   411
			goto out_check;
807794d41b3a PSARC 2009/348 Security Labels for ZFS
Ric Aleshire <Ric.Aleshire@Sun.COM>
parents: 10969
diff changeset
   412
		}
807794d41b3a PSARC 2009/348 Security Labels for ZFS
Ric Aleshire <Ric.Aleshire@Sun.COM>
parents: 10969
diff changeset
   413
807794d41b3a PSARC 2009/348 Security Labels for ZFS
Ric Aleshire <Ric.Aleshire@Sun.COM>
parents: 10969
diff changeset
   414
		if (hexstr_to_label(strval, &new_sl) != 0)
807794d41b3a PSARC 2009/348 Security Labels for ZFS
Ric Aleshire <Ric.Aleshire@Sun.COM>
parents: 10969
diff changeset
   415
			return (EPERM);
807794d41b3a PSARC 2009/348 Security Labels for ZFS
Ric Aleshire <Ric.Aleshire@Sun.COM>
parents: 10969
diff changeset
   416
807794d41b3a PSARC 2009/348 Security Labels for ZFS
Ric Aleshire <Ric.Aleshire@Sun.COM>
parents: 10969
diff changeset
   417
		if (blstrictdom(&ds_sl, &new_sl))
807794d41b3a PSARC 2009/348 Security Labels for ZFS
Ric Aleshire <Ric.Aleshire@Sun.COM>
parents: 10969
diff changeset
   418
			needed_priv = PRIV_FILE_DOWNGRADE_SL;
807794d41b3a PSARC 2009/348 Security Labels for ZFS
Ric Aleshire <Ric.Aleshire@Sun.COM>
parents: 10969
diff changeset
   419
		else if (blstrictdom(&new_sl, &ds_sl))
807794d41b3a PSARC 2009/348 Security Labels for ZFS
Ric Aleshire <Ric.Aleshire@Sun.COM>
parents: 10969
diff changeset
   420
			needed_priv = PRIV_FILE_UPGRADE_SL;
807794d41b3a PSARC 2009/348 Security Labels for ZFS
Ric Aleshire <Ric.Aleshire@Sun.COM>
parents: 10969
diff changeset
   421
	} else {
807794d41b3a PSARC 2009/348 Security Labels for ZFS
Ric Aleshire <Ric.Aleshire@Sun.COM>
parents: 10969
diff changeset
   422
		/* dataset currently has a default label */
807794d41b3a PSARC 2009/348 Security Labels for ZFS
Ric Aleshire <Ric.Aleshire@Sun.COM>
parents: 10969
diff changeset
   423
		if (!new_default)
807794d41b3a PSARC 2009/348 Security Labels for ZFS
Ric Aleshire <Ric.Aleshire@Sun.COM>
parents: 10969
diff changeset
   424
			needed_priv = PRIV_FILE_UPGRADE_SL;
807794d41b3a PSARC 2009/348 Security Labels for ZFS
Ric Aleshire <Ric.Aleshire@Sun.COM>
parents: 10969
diff changeset
   425
	}
807794d41b3a PSARC 2009/348 Security Labels for ZFS
Ric Aleshire <Ric.Aleshire@Sun.COM>
parents: 10969
diff changeset
   426
807794d41b3a PSARC 2009/348 Security Labels for ZFS
Ric Aleshire <Ric.Aleshire@Sun.COM>
parents: 10969
diff changeset
   427
out_check:
807794d41b3a PSARC 2009/348 Security Labels for ZFS
Ric Aleshire <Ric.Aleshire@Sun.COM>
parents: 10969
diff changeset
   428
	if (needed_priv != -1)
807794d41b3a PSARC 2009/348 Security Labels for ZFS
Ric Aleshire <Ric.Aleshire@Sun.COM>
parents: 10969
diff changeset
   429
		return (PRIV_POLICY(cr, needed_priv, B_FALSE, EPERM, NULL));
807794d41b3a PSARC 2009/348 Security Labels for ZFS
Ric Aleshire <Ric.Aleshire@Sun.COM>
parents: 10969
diff changeset
   430
	return (0);
807794d41b3a PSARC 2009/348 Security Labels for ZFS
Ric Aleshire <Ric.Aleshire@Sun.COM>
parents: 10969
diff changeset
   431
}
807794d41b3a PSARC 2009/348 Security Labels for ZFS
Ric Aleshire <Ric.Aleshire@Sun.COM>
parents: 10969
diff changeset
   432
4543
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   433
static int
11022
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 11007
diff changeset
   434
zfs_secpolicy_setprop(const char *dsname, zfs_prop_t prop, nvpair_t *propval,
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 11007
diff changeset
   435
    cred_t *cr)
4543
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   436
{
11022
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 11007
diff changeset
   437
	char *strval;
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 11007
diff changeset
   438
4543
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   439
	/*
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   440
	 * Check permissions for special properties.
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   441
	 */
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   442
	switch (prop) {
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   443
	case ZFS_PROP_ZONED:
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
		 * Disallow setting of 'zoned' from within a local zone.
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   446
		 */
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   447
		if (!INGLOBALZONE(curproc))
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   448
			return (EPERM);
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   449
		break;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   450
4543
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   451
	case ZFS_PROP_QUOTA:
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   452
		if (!INGLOBALZONE(curproc)) {
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   453
			uint64_t zoned;
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   454
			char setpoint[MAXNAMELEN];
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   455
			/*
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   456
			 * Unprivileged users are allowed to modify the
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   457
			 * quota on things *under* (ie. contained by)
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   458
			 * the thing they own.
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   459
			 */
11022
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 11007
diff changeset
   460
			if (dsl_prop_get_integer(dsname, "zoned", &zoned,
4543
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   461
			    setpoint))
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   462
				return (EPERM);
11022
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 11007
diff changeset
   463
			if (!zoned || strlen(dsname) <= strlen(setpoint))
4543
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   464
				return (EPERM);
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   465
		}
4670
002728040e28 6580745 "zfs inherit" can be executed by ordinary user
ahrens
parents: 4611
diff changeset
   466
		break;
10972
807794d41b3a PSARC 2009/348 Security Labels for ZFS
Ric Aleshire <Ric.Aleshire@Sun.COM>
parents: 10969
diff changeset
   467
807794d41b3a PSARC 2009/348 Security Labels for ZFS
Ric Aleshire <Ric.Aleshire@Sun.COM>
parents: 10969
diff changeset
   468
	case ZFS_PROP_MLSLABEL:
807794d41b3a PSARC 2009/348 Security Labels for ZFS
Ric Aleshire <Ric.Aleshire@Sun.COM>
parents: 10969
diff changeset
   469
		if (!is_system_labeled())
807794d41b3a PSARC 2009/348 Security Labels for ZFS
Ric Aleshire <Ric.Aleshire@Sun.COM>
parents: 10969
diff changeset
   470
			return (EPERM);
11022
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 11007
diff changeset
   471
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 11007
diff changeset
   472
		if (nvpair_value_string(propval, &strval) == 0) {
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 11007
diff changeset
   473
			int err;
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 11007
diff changeset
   474
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 11007
diff changeset
   475
			err = zfs_set_slabel_policy(dsname, strval, CRED());
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 11007
diff changeset
   476
			if (err != 0)
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 11007
diff changeset
   477
				return (err);
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 11007
diff changeset
   478
		}
10972
807794d41b3a PSARC 2009/348 Security Labels for ZFS
Ric Aleshire <Ric.Aleshire@Sun.COM>
parents: 10969
diff changeset
   479
		break;
4543
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   480
	}
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   481
11022
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 11007
diff changeset
   482
	return (zfs_secpolicy_write_perms(dsname, zfs_prop_to_name(prop), cr));
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   483
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   484
4543
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   485
int
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   486
zfs_secpolicy_fsacl(zfs_cmd_t *zc, cred_t *cr)
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
	int error;
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   489
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   490
	error = zfs_dozonecheck(zc->zc_name, cr);
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   491
	if (error)
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   492
		return (error);
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   493
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   494
	/*
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   495
	 * permission to set permissions will be evaluated later in
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   496
	 * dsl_deleg_can_allow()
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 (0);
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
int
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   502
zfs_secpolicy_rollback(zfs_cmd_t *zc, cred_t *cr)
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   503
{
10588
dc03f981ea18 6438937 if 'zfs destroy' fails, it can leave a zvol device link missing
Eric Taylor <Eric.Taylor@Sun.COM>
parents: 10474
diff changeset
   504
	return (zfs_secpolicy_write_perms(zc->zc_name,
dc03f981ea18 6438937 if 'zfs destroy' fails, it can leave a zvol device link missing
Eric Taylor <Eric.Taylor@Sun.COM>
parents: 10474
diff changeset
   505
	    ZFS_DELEG_PERM_ROLLBACK, cr));
4543
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   506
}
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   507
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   508
int
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   509
zfs_secpolicy_send(zfs_cmd_t *zc, cred_t *cr)
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   510
{
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   511
	return (zfs_secpolicy_write_perms(zc->zc_name,
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   512
	    ZFS_DELEG_PERM_SEND, cr));
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
8845
91af0d9c0790 6800942 smb_session_create() incorrectly stores IP addresses
Alan Wright <amw@Sun.COM>
parents: 8724
diff changeset
   515
static int
91af0d9c0790 6800942 smb_session_create() incorrectly stores IP addresses
Alan Wright <amw@Sun.COM>
parents: 8724
diff changeset
   516
zfs_secpolicy_deleg_share(zfs_cmd_t *zc, cred_t *cr)
91af0d9c0790 6800942 smb_session_create() incorrectly stores IP addresses
Alan Wright <amw@Sun.COM>
parents: 8724
diff changeset
   517
{
91af0d9c0790 6800942 smb_session_create() incorrectly stores IP addresses
Alan Wright <amw@Sun.COM>
parents: 8724
diff changeset
   518
	vnode_t *vp;
91af0d9c0790 6800942 smb_session_create() incorrectly stores IP addresses
Alan Wright <amw@Sun.COM>
parents: 8724
diff changeset
   519
	int error;
91af0d9c0790 6800942 smb_session_create() incorrectly stores IP addresses
Alan Wright <amw@Sun.COM>
parents: 8724
diff changeset
   520
91af0d9c0790 6800942 smb_session_create() incorrectly stores IP addresses
Alan Wright <amw@Sun.COM>
parents: 8724
diff changeset
   521
	if ((error = lookupname(zc->zc_value, UIO_SYSSPACE,
91af0d9c0790 6800942 smb_session_create() incorrectly stores IP addresses
Alan Wright <amw@Sun.COM>
parents: 8724
diff changeset
   522
	    NO_FOLLOW, NULL, &vp)) != 0)
91af0d9c0790 6800942 smb_session_create() incorrectly stores IP addresses
Alan Wright <amw@Sun.COM>
parents: 8724
diff changeset
   523
		return (error);
91af0d9c0790 6800942 smb_session_create() incorrectly stores IP addresses
Alan Wright <amw@Sun.COM>
parents: 8724
diff changeset
   524
91af0d9c0790 6800942 smb_session_create() incorrectly stores IP addresses
Alan Wright <amw@Sun.COM>
parents: 8724
diff changeset
   525
	/* Now make sure mntpnt and dataset are ZFS */
91af0d9c0790 6800942 smb_session_create() incorrectly stores IP addresses
Alan Wright <amw@Sun.COM>
parents: 8724
diff changeset
   526
91af0d9c0790 6800942 smb_session_create() incorrectly stores IP addresses
Alan Wright <amw@Sun.COM>
parents: 8724
diff changeset
   527
	if (vp->v_vfsp->vfs_fstype != zfsfstype ||
91af0d9c0790 6800942 smb_session_create() incorrectly stores IP addresses
Alan Wright <amw@Sun.COM>
parents: 8724
diff changeset
   528
	    (strcmp((char *)refstr_value(vp->v_vfsp->vfs_resource),
91af0d9c0790 6800942 smb_session_create() incorrectly stores IP addresses
Alan Wright <amw@Sun.COM>
parents: 8724
diff changeset
   529
	    zc->zc_name) != 0)) {
91af0d9c0790 6800942 smb_session_create() incorrectly stores IP addresses
Alan Wright <amw@Sun.COM>
parents: 8724
diff changeset
   530
		VN_RELE(vp);
91af0d9c0790 6800942 smb_session_create() incorrectly stores IP addresses
Alan Wright <amw@Sun.COM>
parents: 8724
diff changeset
   531
		return (EPERM);
91af0d9c0790 6800942 smb_session_create() incorrectly stores IP addresses
Alan Wright <amw@Sun.COM>
parents: 8724
diff changeset
   532
	}
91af0d9c0790 6800942 smb_session_create() incorrectly stores IP addresses
Alan Wright <amw@Sun.COM>
parents: 8724
diff changeset
   533
91af0d9c0790 6800942 smb_session_create() incorrectly stores IP addresses
Alan Wright <amw@Sun.COM>
parents: 8724
diff changeset
   534
	VN_RELE(vp);
91af0d9c0790 6800942 smb_session_create() incorrectly stores IP addresses
Alan Wright <amw@Sun.COM>
parents: 8724
diff changeset
   535
	return (dsl_deleg_access(zc->zc_name,
91af0d9c0790 6800942 smb_session_create() incorrectly stores IP addresses
Alan Wright <amw@Sun.COM>
parents: 8724
diff changeset
   536
	    ZFS_DELEG_PERM_SHARE, cr));
91af0d9c0790 6800942 smb_session_create() incorrectly stores IP addresses
Alan Wright <amw@Sun.COM>
parents: 8724
diff changeset
   537
}
91af0d9c0790 6800942 smb_session_create() incorrectly stores IP addresses
Alan Wright <amw@Sun.COM>
parents: 8724
diff changeset
   538
4543
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   539
int
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   540
zfs_secpolicy_share(zfs_cmd_t *zc, cred_t *cr)
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   541
{
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   542
	if (!INGLOBALZONE(curproc))
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   543
		return (EPERM);
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   544
5367
c40abbe796be PSARC/2007/574 zfs send -R
ahrens
parents: 5331
diff changeset
   545
	if (secpolicy_nfs(cr) == 0) {
4543
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   546
		return (0);
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   547
	} else {
8845
91af0d9c0790 6800942 smb_session_create() incorrectly stores IP addresses
Alan Wright <amw@Sun.COM>
parents: 8724
diff changeset
   548
		return (zfs_secpolicy_deleg_share(zc, cr));
91af0d9c0790 6800942 smb_session_create() incorrectly stores IP addresses
Alan Wright <amw@Sun.COM>
parents: 8724
diff changeset
   549
	}
91af0d9c0790 6800942 smb_session_create() incorrectly stores IP addresses
Alan Wright <amw@Sun.COM>
parents: 8724
diff changeset
   550
}
91af0d9c0790 6800942 smb_session_create() incorrectly stores IP addresses
Alan Wright <amw@Sun.COM>
parents: 8724
diff changeset
   551
91af0d9c0790 6800942 smb_session_create() incorrectly stores IP addresses
Alan Wright <amw@Sun.COM>
parents: 8724
diff changeset
   552
int
91af0d9c0790 6800942 smb_session_create() incorrectly stores IP addresses
Alan Wright <amw@Sun.COM>
parents: 8724
diff changeset
   553
zfs_secpolicy_smb_acl(zfs_cmd_t *zc, cred_t *cr)
91af0d9c0790 6800942 smb_session_create() incorrectly stores IP addresses
Alan Wright <amw@Sun.COM>
parents: 8724
diff changeset
   554
{
91af0d9c0790 6800942 smb_session_create() incorrectly stores IP addresses
Alan Wright <amw@Sun.COM>
parents: 8724
diff changeset
   555
	if (!INGLOBALZONE(curproc))
91af0d9c0790 6800942 smb_session_create() incorrectly stores IP addresses
Alan Wright <amw@Sun.COM>
parents: 8724
diff changeset
   556
		return (EPERM);
91af0d9c0790 6800942 smb_session_create() incorrectly stores IP addresses
Alan Wright <amw@Sun.COM>
parents: 8724
diff changeset
   557
91af0d9c0790 6800942 smb_session_create() incorrectly stores IP addresses
Alan Wright <amw@Sun.COM>
parents: 8724
diff changeset
   558
	if (secpolicy_smb(cr) == 0) {
91af0d9c0790 6800942 smb_session_create() incorrectly stores IP addresses
Alan Wright <amw@Sun.COM>
parents: 8724
diff changeset
   559
		return (0);
91af0d9c0790 6800942 smb_session_create() incorrectly stores IP addresses
Alan Wright <amw@Sun.COM>
parents: 8724
diff changeset
   560
	} else {
91af0d9c0790 6800942 smb_session_create() incorrectly stores IP addresses
Alan Wright <amw@Sun.COM>
parents: 8724
diff changeset
   561
		return (zfs_secpolicy_deleg_share(zc, cr));
4543
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
}
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   564
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   565
static int
4543
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   566
zfs_get_parent(const char *datasetname, char *parent, int parentsize)
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   567
{
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   568
	char *cp;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   569
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   570
	/*
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   571
	 * Remove the @bla or /bla from the end of the name to get the parent.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   572
	 */
4543
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   573
	(void) strncpy(parent, datasetname, parentsize);
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   574
	cp = strrchr(parent, '@');
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   575
	if (cp != NULL) {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   576
		cp[0] = '\0';
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   577
	} else {
4543
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   578
		cp = strrchr(parent, '/');
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   579
		if (cp == NULL)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   580
			return (ENOENT);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   581
		cp[0] = '\0';
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   582
	}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   583
4543
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   584
	return (0);
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   585
}
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   586
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   587
int
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   588
zfs_secpolicy_destroy_perms(const char *name, cred_t *cr)
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   589
{
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   590
	int error;
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   591
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   592
	if ((error = zfs_secpolicy_write_perms(name,
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   593
	    ZFS_DELEG_PERM_MOUNT, cr)) != 0)
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   594
		return (error);
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   595
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   596
	return (zfs_secpolicy_write_perms(name, ZFS_DELEG_PERM_DESTROY, cr));
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   597
}
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   598
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   599
static int
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   600
zfs_secpolicy_destroy(zfs_cmd_t *zc, cred_t *cr)
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   601
{
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   602
	return (zfs_secpolicy_destroy_perms(zc->zc_name, 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
/*
11314
489ae7372a1f 6901122 destroy snapshot by delegated user succeeds without descendent permissions when -r or -R used.
William Gorrell <william.gorrell@sun.com>
parents: 11209
diff changeset
   606
 * Destroying snapshots with delegated permissions requires
489ae7372a1f 6901122 destroy snapshot by delegated user succeeds without descendent permissions when -r or -R used.
William Gorrell <william.gorrell@sun.com>
parents: 11209
diff changeset
   607
 * descendent mount and destroy permissions.
489ae7372a1f 6901122 destroy snapshot by delegated user succeeds without descendent permissions when -r or -R used.
William Gorrell <william.gorrell@sun.com>
parents: 11209
diff changeset
   608
 * Reassemble the full filesystem@snap name so dsl_deleg_access()
489ae7372a1f 6901122 destroy snapshot by delegated user succeeds without descendent permissions when -r or -R used.
William Gorrell <william.gorrell@sun.com>
parents: 11209
diff changeset
   609
 * can do the correct permission check.
489ae7372a1f 6901122 destroy snapshot by delegated user succeeds without descendent permissions when -r or -R used.
William Gorrell <william.gorrell@sun.com>
parents: 11209
diff changeset
   610
 *
489ae7372a1f 6901122 destroy snapshot by delegated user succeeds without descendent permissions when -r or -R used.
William Gorrell <william.gorrell@sun.com>
parents: 11209
diff changeset
   611
 * Since this routine is used when doing a recursive destroy of snapshots
489ae7372a1f 6901122 destroy snapshot by delegated user succeeds without descendent permissions when -r or -R used.
William Gorrell <william.gorrell@sun.com>
parents: 11209
diff changeset
   612
 * and destroying snapshots requires descendent permissions, a successfull
489ae7372a1f 6901122 destroy snapshot by delegated user succeeds without descendent permissions when -r or -R used.
William Gorrell <william.gorrell@sun.com>
parents: 11209
diff changeset
   613
 * check of the top level snapshot applies to snapshots of all descendent
489ae7372a1f 6901122 destroy snapshot by delegated user succeeds without descendent permissions when -r or -R used.
William Gorrell <william.gorrell@sun.com>
parents: 11209
diff changeset
   614
 * datasets as well.
489ae7372a1f 6901122 destroy snapshot by delegated user succeeds without descendent permissions when -r or -R used.
William Gorrell <william.gorrell@sun.com>
parents: 11209
diff changeset
   615
 */
489ae7372a1f 6901122 destroy snapshot by delegated user succeeds without descendent permissions when -r or -R used.
William Gorrell <william.gorrell@sun.com>
parents: 11209
diff changeset
   616
static int
489ae7372a1f 6901122 destroy snapshot by delegated user succeeds without descendent permissions when -r or -R used.
William Gorrell <william.gorrell@sun.com>
parents: 11209
diff changeset
   617
zfs_secpolicy_destroy_snaps(zfs_cmd_t *zc, cred_t *cr)
489ae7372a1f 6901122 destroy snapshot by delegated user succeeds without descendent permissions when -r or -R used.
William Gorrell <william.gorrell@sun.com>
parents: 11209
diff changeset
   618
{
489ae7372a1f 6901122 destroy snapshot by delegated user succeeds without descendent permissions when -r or -R used.
William Gorrell <william.gorrell@sun.com>
parents: 11209
diff changeset
   619
	int error;
489ae7372a1f 6901122 destroy snapshot by delegated user succeeds without descendent permissions when -r or -R used.
William Gorrell <william.gorrell@sun.com>
parents: 11209
diff changeset
   620
	char *dsname;
489ae7372a1f 6901122 destroy snapshot by delegated user succeeds without descendent permissions when -r or -R used.
William Gorrell <william.gorrell@sun.com>
parents: 11209
diff changeset
   621
489ae7372a1f 6901122 destroy snapshot by delegated user succeeds without descendent permissions when -r or -R used.
William Gorrell <william.gorrell@sun.com>
parents: 11209
diff changeset
   622
	dsname = kmem_asprintf("%s@%s", zc->zc_name, zc->zc_value);
489ae7372a1f 6901122 destroy snapshot by delegated user succeeds without descendent permissions when -r or -R used.
William Gorrell <william.gorrell@sun.com>
parents: 11209
diff changeset
   623
489ae7372a1f 6901122 destroy snapshot by delegated user succeeds without descendent permissions when -r or -R used.
William Gorrell <william.gorrell@sun.com>
parents: 11209
diff changeset
   624
	error = zfs_secpolicy_destroy_perms(dsname, cr);
489ae7372a1f 6901122 destroy snapshot by delegated user succeeds without descendent permissions when -r or -R used.
William Gorrell <william.gorrell@sun.com>
parents: 11209
diff changeset
   625
489ae7372a1f 6901122 destroy snapshot by delegated user succeeds without descendent permissions when -r or -R used.
William Gorrell <william.gorrell@sun.com>
parents: 11209
diff changeset
   626
	strfree(dsname);
489ae7372a1f 6901122 destroy snapshot by delegated user succeeds without descendent permissions when -r or -R used.
William Gorrell <william.gorrell@sun.com>
parents: 11209
diff changeset
   627
	return (error);
489ae7372a1f 6901122 destroy snapshot by delegated user succeeds without descendent permissions when -r or -R used.
William Gorrell <william.gorrell@sun.com>
parents: 11209
diff changeset
   628
}
489ae7372a1f 6901122 destroy snapshot by delegated user succeeds without descendent permissions when -r or -R used.
William Gorrell <william.gorrell@sun.com>
parents: 11209
diff changeset
   629
4543
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   630
int
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   631
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
   632
{
11022
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 11007
diff changeset
   633
	char	parentname[MAXNAMELEN];
4543
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   634
	int	error;
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   635
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   636
	if ((error = zfs_secpolicy_write_perms(from,
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   637
	    ZFS_DELEG_PERM_RENAME, cr)) != 0)
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   638
		return (error);
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   639
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   640
	if ((error = zfs_secpolicy_write_perms(from,
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   641
	    ZFS_DELEG_PERM_MOUNT, cr)) != 0)
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   642
		return (error);
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   643
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   644
	if ((error = zfs_get_parent(to, parentname,
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   645
	    sizeof (parentname))) != 0)
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   646
		return (error);
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   647
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   648
	if ((error = zfs_secpolicy_write_perms(parentname,
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   649
	    ZFS_DELEG_PERM_CREATE, cr)) != 0)
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   650
		return (error);
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   651
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   652
	if ((error = zfs_secpolicy_write_perms(parentname,
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   653
	    ZFS_DELEG_PERM_MOUNT, cr)) != 0)
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   654
		return (error);
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   655
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   656
	return (error);
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   657
}
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   658
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   659
static int
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   660
zfs_secpolicy_rename(zfs_cmd_t *zc, cred_t *cr)
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   661
{
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   662
	return (zfs_secpolicy_rename_perms(zc->zc_name, zc->zc_value, cr));
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   663
}
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   664
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   665
static int
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   666
zfs_secpolicy_promote(zfs_cmd_t *zc, cred_t *cr)
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   667
{
11022
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 11007
diff changeset
   668
	char	parentname[MAXNAMELEN];
4543
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   669
	objset_t *clone;
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   670
	int error;
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   671
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   672
	error = zfs_secpolicy_write_perms(zc->zc_name,
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   673
	    ZFS_DELEG_PERM_PROMOTE, cr);
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   674
	if (error)
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   675
		return (error);
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   676
10298
a0d52501437c 6860996 %temporary clones are not automatically destroyed on error
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 10272
diff changeset
   677
	error = dmu_objset_hold(zc->zc_name, FTAG, &clone);
4543
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   678
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   679
	if (error == 0) {
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   680
		dsl_dataset_t *pclone = NULL;
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   681
		dsl_dir_t *dd;
10298
a0d52501437c 6860996 %temporary clones are not automatically destroyed on error
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 10272
diff changeset
   682
		dd = clone->os_dsl_dataset->ds_dir;
4543
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   683
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   684
		rw_enter(&dd->dd_pool->dp_config_rwlock, RW_READER);
6689
47572a2f5e73 6610506 Eliminate or improve retry logic from callers of dmu_objset_open()
maybee
parents: 6643
diff changeset
   685
		error = dsl_dataset_hold_obj(dd->dd_pool,
47572a2f5e73 6610506 Eliminate or improve retry logic from callers of dmu_objset_open()
maybee
parents: 6643
diff changeset
   686
		    dd->dd_phys->dd_origin_obj, FTAG, &pclone);
4543
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   687
		rw_exit(&dd->dd_pool->dp_config_rwlock);
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   688
		if (error) {
10298
a0d52501437c 6860996 %temporary clones are not automatically destroyed on error
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 10272
diff changeset
   689
			dmu_objset_rele(clone, FTAG);
4543
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   690
			return (error);
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   691
		}
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   692
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   693
		error = zfs_secpolicy_write_perms(zc->zc_name,
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   694
		    ZFS_DELEG_PERM_MOUNT, cr);
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   695
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   696
		dsl_dataset_name(pclone, parentname);
10298
a0d52501437c 6860996 %temporary clones are not automatically destroyed on error
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 10272
diff changeset
   697
		dmu_objset_rele(clone, FTAG);
6689
47572a2f5e73 6610506 Eliminate or improve retry logic from callers of dmu_objset_open()
maybee
parents: 6643
diff changeset
   698
		dsl_dataset_rele(pclone, FTAG);
4543
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   699
		if (error == 0)
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   700
			error = zfs_secpolicy_write_perms(parentname,
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   701
			    ZFS_DELEG_PERM_PROMOTE, cr);
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   702
	}
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   703
	return (error);
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   704
}
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   705
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   706
static int
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   707
zfs_secpolicy_receive(zfs_cmd_t *zc, cred_t *cr)
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   708
{
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   709
	int error;
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   710
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   711
	if ((error = zfs_secpolicy_write_perms(zc->zc_name,
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   712
	    ZFS_DELEG_PERM_RECEIVE, cr)) != 0)
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   713
		return (error);
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   714
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   715
	if ((error = zfs_secpolicy_write_perms(zc->zc_name,
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   716
	    ZFS_DELEG_PERM_MOUNT, cr)) != 0)
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   717
		return (error);
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   718
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   719
	return (zfs_secpolicy_write_perms(zc->zc_name,
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   720
	    ZFS_DELEG_PERM_CREATE, cr));
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   721
}
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   722
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   723
int
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   724
zfs_secpolicy_snapshot_perms(const char *name, cred_t *cr)
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   725
{
10588
dc03f981ea18 6438937 if 'zfs destroy' fails, it can leave a zvol device link missing
Eric Taylor <Eric.Taylor@Sun.COM>
parents: 10474
diff changeset
   726
	return (zfs_secpolicy_write_perms(name,
dc03f981ea18 6438937 if 'zfs destroy' fails, it can leave a zvol device link missing
Eric Taylor <Eric.Taylor@Sun.COM>
parents: 10474
diff changeset
   727
	    ZFS_DELEG_PERM_SNAPSHOT, cr));
4543
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   728
}
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   729
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   730
static int
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   731
zfs_secpolicy_snapshot(zfs_cmd_t *zc, cred_t *cr)
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   732
{
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   733
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   734
	return (zfs_secpolicy_snapshot_perms(zc->zc_name, cr));
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   735
}
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   736
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   737
static int
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   738
zfs_secpolicy_create(zfs_cmd_t *zc, cred_t *cr)
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   739
{
11022
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 11007
diff changeset
   740
	char	parentname[MAXNAMELEN];
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 11007
diff changeset
   741
	int	error;
4543
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   742
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   743
	if ((error = zfs_get_parent(zc->zc_name, parentname,
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   744
	    sizeof (parentname))) != 0)
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   745
		return (error);
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   746
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   747
	if (zc->zc_value[0] != '\0') {
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   748
		if ((error = zfs_secpolicy_write_perms(zc->zc_value,
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   749
		    ZFS_DELEG_PERM_CLONE, cr)) != 0)
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   750
			return (error);
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   751
	}
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   752
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   753
	if ((error = zfs_secpolicy_write_perms(parentname,
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   754
	    ZFS_DELEG_PERM_CREATE, cr)) != 0)
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   755
		return (error);
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   756
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   757
	error = zfs_secpolicy_write_perms(parentname,
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   758
	    ZFS_DELEG_PERM_MOUNT, cr);
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   759
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   760
	return (error);
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   761
}
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   762
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   763
static int
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   764
zfs_secpolicy_umount(zfs_cmd_t *zc, cred_t *cr)
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   765
{
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   766
	int error;
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   767
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   768
	error = secpolicy_fs_unmount(cr, NULL);
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   769
	if (error) {
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   770
		error = dsl_deleg_access(zc->zc_name, ZFS_DELEG_PERM_MOUNT, cr);
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   771
	}
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   772
	return (error);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   773
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   774
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   775
/*
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   776
 * Policy for pool operations - create/destroy pools, add vdevs, etc.  Requires
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   777
 * SYS_CONFIG privilege, which is not available in a local zone.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   778
 */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   779
/* ARGSUSED */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   780
static int
4543
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   781
zfs_secpolicy_config(zfs_cmd_t *zc, cred_t *cr)
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   782
{
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   783
	if (secpolicy_sys_config(cr, B_FALSE) != 0)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   784
		return (EPERM);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   785
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   786
	return (0);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   787
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   788
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   789
/*
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
   790
 * Policy for fault injection.  Requires all privileges.
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
   791
 */
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
   792
/* ARGSUSED */
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
   793
static int
4543
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   794
zfs_secpolicy_inject(zfs_cmd_t *zc, cred_t *cr)
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
   795
{
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
   796
	return (secpolicy_zinject(cr));
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
   797
}
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
   798
4849
3a61e0a9a953 6536043 arc_byteswap_func_t and dmu_byteswap_func_t are redundant
ahrens
parents: 4808
diff changeset
   799
static int
3a61e0a9a953 6536043 arc_byteswap_func_t and dmu_byteswap_func_t are redundant
ahrens
parents: 4808
diff changeset
   800
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
   801
{
3a61e0a9a953 6536043 arc_byteswap_func_t and dmu_byteswap_func_t are redundant
ahrens
parents: 4808
diff changeset
   802
	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
   803
5094
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
   804
	if (prop == ZPROP_INVAL) {
4849
3a61e0a9a953 6536043 arc_byteswap_func_t and dmu_byteswap_func_t are redundant
ahrens
parents: 4808
diff changeset
   805
		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
   806
			return (EINVAL);
3a61e0a9a953 6536043 arc_byteswap_func_t and dmu_byteswap_func_t are redundant
ahrens
parents: 4808
diff changeset
   807
		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
   808
		    ZFS_DELEG_PERM_USERPROP, cr));
3a61e0a9a953 6536043 arc_byteswap_func_t and dmu_byteswap_func_t are redundant
ahrens
parents: 4808
diff changeset
   809
	} else {
11022
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 11007
diff changeset
   810
		return (zfs_secpolicy_setprop(zc->zc_name, prop,
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 11007
diff changeset
   811
		    NULL, cr));
4849
3a61e0a9a953 6536043 arc_byteswap_func_t and dmu_byteswap_func_t are redundant
ahrens
parents: 4808
diff changeset
   812
	}
3a61e0a9a953 6536043 arc_byteswap_func_t and dmu_byteswap_func_t are redundant
ahrens
parents: 4808
diff changeset
   813
}
3a61e0a9a953 6536043 arc_byteswap_func_t and dmu_byteswap_func_t are redundant
ahrens
parents: 4808
diff changeset
   814
9396
f41cf682d0d3 PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 9355
diff changeset
   815
static int
f41cf682d0d3 PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 9355
diff changeset
   816
zfs_secpolicy_userspace_one(zfs_cmd_t *zc, cred_t *cr)
f41cf682d0d3 PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 9355
diff changeset
   817
{
f41cf682d0d3 PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 9355
diff changeset
   818
	int err = zfs_secpolicy_read(zc, cr);
f41cf682d0d3 PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 9355
diff changeset
   819
	if (err)
f41cf682d0d3 PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 9355
diff changeset
   820
		return (err);
f41cf682d0d3 PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 9355
diff changeset
   821
f41cf682d0d3 PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 9355
diff changeset
   822
	if (zc->zc_objset_type >= ZFS_NUM_USERQUOTA_PROPS)
f41cf682d0d3 PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 9355
diff changeset
   823
		return (EINVAL);
f41cf682d0d3 PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 9355
diff changeset
   824
f41cf682d0d3 PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 9355
diff changeset
   825
	if (zc->zc_value[0] == 0) {
f41cf682d0d3 PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 9355
diff changeset
   826
		/*
f41cf682d0d3 PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 9355
diff changeset
   827
		 * They are asking about a posix uid/gid.  If it's
f41cf682d0d3 PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 9355
diff changeset
   828
		 * themself, allow it.
f41cf682d0d3 PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 9355
diff changeset
   829
		 */
f41cf682d0d3 PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 9355
diff changeset
   830
		if (zc->zc_objset_type == ZFS_PROP_USERUSED ||
f41cf682d0d3 PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 9355
diff changeset
   831
		    zc->zc_objset_type == ZFS_PROP_USERQUOTA) {
f41cf682d0d3 PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 9355
diff changeset
   832
			if (zc->zc_guid == crgetuid(cr))
f41cf682d0d3 PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 9355
diff changeset
   833
				return (0);
f41cf682d0d3 PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 9355
diff changeset
   834
		} else {
f41cf682d0d3 PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 9355
diff changeset
   835
			if (groupmember(zc->zc_guid, cr))
f41cf682d0d3 PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 9355
diff changeset
   836
				return (0);
f41cf682d0d3 PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 9355
diff changeset
   837
		}
f41cf682d0d3 PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 9355
diff changeset
   838
	}
f41cf682d0d3 PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 9355
diff changeset
   839
f41cf682d0d3 PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 9355
diff changeset
   840
	return (zfs_secpolicy_write_perms(zc->zc_name,
f41cf682d0d3 PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 9355
diff changeset
   841
	    userquota_perms[zc->zc_objset_type], cr));
f41cf682d0d3 PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 9355
diff changeset
   842
}
f41cf682d0d3 PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 9355
diff changeset
   843
f41cf682d0d3 PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 9355
diff changeset
   844
static int
f41cf682d0d3 PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 9355
diff changeset
   845
zfs_secpolicy_userspace_many(zfs_cmd_t *zc, cred_t *cr)
f41cf682d0d3 PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 9355
diff changeset
   846
{
f41cf682d0d3 PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 9355
diff changeset
   847
	int err = zfs_secpolicy_read(zc, cr);
f41cf682d0d3 PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 9355
diff changeset
   848
	if (err)
f41cf682d0d3 PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 9355
diff changeset
   849
		return (err);
f41cf682d0d3 PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 9355
diff changeset
   850
f41cf682d0d3 PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 9355
diff changeset
   851
	if (zc->zc_objset_type >= ZFS_NUM_USERQUOTA_PROPS)
f41cf682d0d3 PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 9355
diff changeset
   852
		return (EINVAL);
f41cf682d0d3 PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 9355
diff changeset
   853
f41cf682d0d3 PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 9355
diff changeset
   854
	return (zfs_secpolicy_write_perms(zc->zc_name,
f41cf682d0d3 PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 9355
diff changeset
   855
	    userquota_perms[zc->zc_objset_type], cr));
f41cf682d0d3 PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 9355
diff changeset
   856
}
f41cf682d0d3 PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 9355
diff changeset
   857
f41cf682d0d3 PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 9355
diff changeset
   858
static int
f41cf682d0d3 PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 9355
diff changeset
   859
zfs_secpolicy_userspace_upgrade(zfs_cmd_t *zc, cred_t *cr)
f41cf682d0d3 PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 9355
diff changeset
   860
{
11022
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 11007
diff changeset
   861
	return (zfs_secpolicy_setprop(zc->zc_name, ZFS_PROP_VERSION,
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 11007
diff changeset
   862
	    NULL, cr));
9396
f41cf682d0d3 PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 9355
diff changeset
   863
}
f41cf682d0d3 PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 9355
diff changeset
   864
10242
c40d075fbca6 PSARC/2009/297 zfs snapshot holds
Chris Kirby <chris.kirby@sun.com>
parents: 10233
diff changeset
   865
static int
c40d075fbca6 PSARC/2009/297 zfs snapshot holds
Chris Kirby <chris.kirby@sun.com>
parents: 10233
diff changeset
   866
zfs_secpolicy_hold(zfs_cmd_t *zc, cred_t *cr)
c40d075fbca6 PSARC/2009/297 zfs snapshot holds
Chris Kirby <chris.kirby@sun.com>
parents: 10233
diff changeset
   867
{
c40d075fbca6 PSARC/2009/297 zfs snapshot holds
Chris Kirby <chris.kirby@sun.com>
parents: 10233
diff changeset
   868
	return (zfs_secpolicy_write_perms(zc->zc_name,
c40d075fbca6 PSARC/2009/297 zfs snapshot holds
Chris Kirby <chris.kirby@sun.com>
parents: 10233
diff changeset
   869
	    ZFS_DELEG_PERM_HOLD, cr));
c40d075fbca6 PSARC/2009/297 zfs snapshot holds
Chris Kirby <chris.kirby@sun.com>
parents: 10233
diff changeset
   870
}
c40d075fbca6 PSARC/2009/297 zfs snapshot holds
Chris Kirby <chris.kirby@sun.com>
parents: 10233
diff changeset
   871
c40d075fbca6 PSARC/2009/297 zfs snapshot holds
Chris Kirby <chris.kirby@sun.com>
parents: 10233
diff changeset
   872
static int
c40d075fbca6 PSARC/2009/297 zfs snapshot holds
Chris Kirby <chris.kirby@sun.com>
parents: 10233
diff changeset
   873
zfs_secpolicy_release(zfs_cmd_t *zc, cred_t *cr)
c40d075fbca6 PSARC/2009/297 zfs snapshot holds
Chris Kirby <chris.kirby@sun.com>
parents: 10233
diff changeset
   874
{
c40d075fbca6 PSARC/2009/297 zfs snapshot holds
Chris Kirby <chris.kirby@sun.com>
parents: 10233
diff changeset
   875
	return (zfs_secpolicy_write_perms(zc->zc_name,
c40d075fbca6 PSARC/2009/297 zfs snapshot holds
Chris Kirby <chris.kirby@sun.com>
parents: 10233
diff changeset
   876
	    ZFS_DELEG_PERM_RELEASE, cr));
c40d075fbca6 PSARC/2009/297 zfs snapshot holds
Chris Kirby <chris.kirby@sun.com>
parents: 10233
diff changeset
   877
}
c40d075fbca6 PSARC/2009/297 zfs snapshot holds
Chris Kirby <chris.kirby@sun.com>
parents: 10233
diff changeset
   878
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
   879
/*
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   880
 * Returns the nvlist as specified by the user in the zfs_cmd_t.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   881
 */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   882
static int
9643
ffd8e7765f02 6736004 zvols need an additional property for comstar support
Eric Taylor <Eric.Taylor@Sun.COM>
parents: 9425
diff changeset
   883
get_nvlist(uint64_t nvl, uint64_t size, int iflag, nvlist_t **nvp)
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   884
{
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   885
	char *packed;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   886
	int error;
5094
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
   887
	nvlist_t *list = NULL;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   888
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   889
	/*
2676
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
   890
	 * Read in and unpack the user-supplied nvlist.
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   891
	 */
5094
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
   892
	if (size == 0)
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   893
		return (EINVAL);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   894
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   895
	packed = kmem_alloc(size, KM_SLEEP);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   896
9643
ffd8e7765f02 6736004 zvols need an additional property for comstar support
Eric Taylor <Eric.Taylor@Sun.COM>
parents: 9425
diff changeset
   897
	if ((error = ddi_copyin((void *)(uintptr_t)nvl, packed, size,
ffd8e7765f02 6736004 zvols need an additional property for comstar support
Eric Taylor <Eric.Taylor@Sun.COM>
parents: 9425
diff changeset
   898
	    iflag)) != 0) {
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   899
		kmem_free(packed, size);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   900
		return (error);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   901
	}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   902
5094
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
   903
	if ((error = nvlist_unpack(packed, size, &list, 0)) != 0) {
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   904
		kmem_free(packed, size);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   905
		return (error);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   906
	}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   907
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   908
	kmem_free(packed, size);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   909
5094
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
   910
	*nvp = list;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   911
	return (0);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   912
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   913
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   914
static int
11022
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 11007
diff changeset
   915
fit_error_list(zfs_cmd_t *zc, nvlist_t **errors)
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 11007
diff changeset
   916
{
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 11007
diff changeset
   917
	size_t size;
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 11007
diff changeset
   918
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 11007
diff changeset
   919
	VERIFY(nvlist_size(*errors, &size, NV_ENCODE_NATIVE) == 0);
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 11007
diff changeset
   920
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 11007
diff changeset
   921
	if (size > zc->zc_nvlist_dst_size) {
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 11007
diff changeset
   922
		nvpair_t *more_errors;
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 11007
diff changeset
   923
		int n = 0;
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 11007
diff changeset
   924
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 11007
diff changeset
   925
		if (zc->zc_nvlist_dst_size < 1024)
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 11007
diff changeset
   926
			return (ENOMEM);
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 11007
diff changeset
   927
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 11007
diff changeset
   928
		VERIFY(nvlist_add_int32(*errors, ZPROP_N_MORE_ERRORS, 0) == 0);
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 11007
diff changeset
   929
		more_errors = nvlist_prev_nvpair(*errors, NULL);
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 11007
diff changeset
   930
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 11007
diff changeset
   931
		do {
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 11007
diff changeset
   932
			nvpair_t *pair = nvlist_prev_nvpair(*errors,
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 11007
diff changeset
   933
			    more_errors);
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 11007
diff changeset
   934
			VERIFY(nvlist_remove_nvpair(*errors, pair) == 0);
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 11007
diff changeset
   935
			n++;
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 11007
diff changeset
   936
			VERIFY(nvlist_size(*errors, &size,
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 11007
diff changeset
   937
			    NV_ENCODE_NATIVE) == 0);
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 11007
diff changeset
   938
		} while (size > zc->zc_nvlist_dst_size);
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 11007
diff changeset
   939
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 11007
diff changeset
   940
		VERIFY(nvlist_remove_nvpair(*errors, more_errors) == 0);
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 11007
diff changeset
   941
		VERIFY(nvlist_add_int32(*errors, ZPROP_N_MORE_ERRORS, n) == 0);
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 11007
diff changeset
   942
		ASSERT(nvlist_size(*errors, &size, NV_ENCODE_NATIVE) == 0);
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 11007
diff changeset
   943
		ASSERT(size <= zc->zc_nvlist_dst_size);
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 11007
diff changeset
   944
	}
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 11007
diff changeset
   945
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 11007
diff changeset
   946
	return (0);
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 11007
diff changeset
   947
}
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 11007
diff changeset
   948
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 11007
diff changeset
   949
static int
2676
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
   950
put_nvlist(zfs_cmd_t *zc, nvlist_t *nvl)
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
   951
{
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
   952
	char *packed = NULL;
11807
73a3c0d27389 6911541 'zfs mount' coredump
Sam Falkner <Sam.Falkner@Sun.COM>
parents: 11727
diff changeset
   953
	int error = 0;
2676
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
   954
	size_t size;
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
   955
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
   956
	VERIFY(nvlist_size(nvl, &size, NV_ENCODE_NATIVE) == 0);
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
   957
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
   958
	if (size > zc->zc_nvlist_dst_size) {
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
   959
		error = ENOMEM;
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
   960
	} else {
4611
0960c3336815 6575997 Memory corruption while running ztest
marks
parents: 4603
diff changeset
   961
		packed = kmem_alloc(size, KM_SLEEP);
2676
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
   962
		VERIFY(nvlist_pack(nvl, &packed, &size, NV_ENCODE_NATIVE,
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
   963
		    KM_SLEEP) == 0);
11807
73a3c0d27389 6911541 'zfs mount' coredump
Sam Falkner <Sam.Falkner@Sun.COM>
parents: 11727
diff changeset
   964
		if (ddi_copyout(packed, (void *)(uintptr_t)zc->zc_nvlist_dst,
73a3c0d27389 6911541 'zfs mount' coredump
Sam Falkner <Sam.Falkner@Sun.COM>
parents: 11727
diff changeset
   965
		    size, zc->zc_iflags) != 0)
73a3c0d27389 6911541 'zfs mount' coredump
Sam Falkner <Sam.Falkner@Sun.COM>
parents: 11727
diff changeset
   966
			error = EFAULT;
2676
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
   967
		kmem_free(packed, size);
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
   968
	}
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
   969
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
   970
	zc->zc_nvlist_dst_size = size;
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
   971
	return (error);
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
   972
}
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
   973
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
   974
static int
11185
f0c31008e395 6887924 PP_ISKAS needs to be defined in terms of VN_ISKAS for vnodes
Sean McEnroe <Sean.McEnroe@Sun.COM>
parents: 11181
diff changeset
   975
getzfsvfs(const char *dsname, zfsvfs_t **zfvp)
9396
f41cf682d0d3 PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 9355
diff changeset
   976
{
f41cf682d0d3 PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 9355
diff changeset
   977
	objset_t *os;
f41cf682d0d3 PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 9355
diff changeset
   978
	int error;
f41cf682d0d3 PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 9355
diff changeset
   979
10298
a0d52501437c 6860996 %temporary clones are not automatically destroyed on error
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 10272
diff changeset
   980
	error = dmu_objset_hold(dsname, FTAG, &os);
9396
f41cf682d0d3 PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 9355
diff changeset
   981
	if (error)
f41cf682d0d3 PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 9355
diff changeset
   982
		return (error);
10298
a0d52501437c 6860996 %temporary clones are not automatically destroyed on error
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 10272
diff changeset
   983
	if (dmu_objset_type(os) != DMU_OST_ZFS) {
a0d52501437c 6860996 %temporary clones are not automatically destroyed on error
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 10272
diff changeset
   984
		dmu_objset_rele(os, FTAG);
a0d52501437c 6860996 %temporary clones are not automatically destroyed on error
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 10272
diff changeset
   985
		return (EINVAL);
a0d52501437c 6860996 %temporary clones are not automatically destroyed on error
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 10272
diff changeset
   986
	}
a0d52501437c 6860996 %temporary clones are not automatically destroyed on error
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 10272
diff changeset
   987
a0d52501437c 6860996 %temporary clones are not automatically destroyed on error
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 10272
diff changeset
   988
	mutex_enter(&os->os_user_ptr_lock);
11185
f0c31008e395 6887924 PP_ISKAS needs to be defined in terms of VN_ISKAS for vnodes
Sean McEnroe <Sean.McEnroe@Sun.COM>
parents: 11181
diff changeset
   989
	*zfvp = dmu_objset_get_user(os);
f0c31008e395 6887924 PP_ISKAS needs to be defined in terms of VN_ISKAS for vnodes
Sean McEnroe <Sean.McEnroe@Sun.COM>
parents: 11181
diff changeset
   990
	if (*zfvp) {
f0c31008e395 6887924 PP_ISKAS needs to be defined in terms of VN_ISKAS for vnodes
Sean McEnroe <Sean.McEnroe@Sun.COM>
parents: 11181
diff changeset
   991
		VFS_HOLD((*zfvp)->z_vfs);
9396
f41cf682d0d3 PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 9355
diff changeset
   992
	} else {
f41cf682d0d3 PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 9355
diff changeset
   993
		error = ESRCH;
f41cf682d0d3 PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 9355
diff changeset
   994
	}
10298
a0d52501437c 6860996 %temporary clones are not automatically destroyed on error
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 10272
diff changeset
   995
	mutex_exit(&os->os_user_ptr_lock);
a0d52501437c 6860996 %temporary clones are not automatically destroyed on error
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 10272
diff changeset
   996
	dmu_objset_rele(os, FTAG);
9396
f41cf682d0d3 PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 9355
diff changeset
   997
	return (error);
f41cf682d0d3 PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 9355
diff changeset
   998
}
f41cf682d0d3 PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 9355
diff changeset
   999
f41cf682d0d3 PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 9355
diff changeset
  1000
/*
f41cf682d0d3 PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 9355
diff changeset
  1001
 * Find a zfsvfs_t for a mounted filesystem, or create our own, in which
f41cf682d0d3 PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 9355
diff changeset
  1002
 * case its z_vfs will be NULL, and it will be opened as the owner.
f41cf682d0d3 PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 9355
diff changeset
  1003
 */
f41cf682d0d3 PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 9355
diff changeset
  1004
static int
11185
f0c31008e395 6887924 PP_ISKAS needs to be defined in terms of VN_ISKAS for vnodes
Sean McEnroe <Sean.McEnroe@Sun.COM>
parents: 11181
diff changeset
  1005
zfsvfs_hold(const char *name, void *tag, zfsvfs_t **zfvp)
9396
f41cf682d0d3 PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 9355
diff changeset
  1006
{
f41cf682d0d3 PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 9355
diff changeset
  1007
	int error = 0;
f41cf682d0d3 PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 9355
diff changeset
  1008
11185
f0c31008e395 6887924 PP_ISKAS needs to be defined in terms of VN_ISKAS for vnodes
Sean McEnroe <Sean.McEnroe@Sun.COM>
parents: 11181
diff changeset
  1009
	if (getzfsvfs(name, zfvp) != 0)
f0c31008e395 6887924 PP_ISKAS needs to be defined in terms of VN_ISKAS for vnodes
Sean McEnroe <Sean.McEnroe@Sun.COM>
parents: 11181
diff changeset
  1010
		error = zfsvfs_create(name, zfvp);
9396
f41cf682d0d3 PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 9355
diff changeset
  1011
	if (error == 0) {
11185
f0c31008e395 6887924 PP_ISKAS needs to be defined in terms of VN_ISKAS for vnodes
Sean McEnroe <Sean.McEnroe@Sun.COM>
parents: 11181
diff changeset
  1012
		rrw_enter(&(*zfvp)->z_teardown_lock, RW_READER, tag);
f0c31008e395 6887924 PP_ISKAS needs to be defined in terms of VN_ISKAS for vnodes
Sean McEnroe <Sean.McEnroe@Sun.COM>
parents: 11181
diff changeset
  1013
		if ((*zfvp)->z_unmounted) {
9396
f41cf682d0d3 PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 9355
diff changeset
  1014
			/*
f41cf682d0d3 PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 9355
diff changeset
  1015
			 * XXX we could probably try again, since the unmounting
f41cf682d0d3 PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 9355
diff changeset
  1016
			 * thread should be just about to disassociate the
f41cf682d0d3 PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 9355
diff changeset
  1017
			 * objset from the zfsvfs.
f41cf682d0d3 PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 9355
diff changeset
  1018
			 */
11185
f0c31008e395 6887924 PP_ISKAS needs to be defined in terms of VN_ISKAS for vnodes
Sean McEnroe <Sean.McEnroe@Sun.COM>
parents: 11181
diff changeset
  1019
			rrw_exit(&(*zfvp)->z_teardown_lock, tag);
9396
f41cf682d0d3 PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 9355
diff changeset
  1020
			return (EBUSY);
f41cf682d0d3 PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 9355
diff changeset
  1021
		}
f41cf682d0d3 PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 9355
diff changeset
  1022
	}
f41cf682d0d3 PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 9355
diff changeset
  1023
	return (error);
f41cf682d0d3 PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 9355
diff changeset
  1024
}
f41cf682d0d3 PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 9355
diff changeset
  1025
f41cf682d0d3 PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 9355
diff changeset
  1026
static void
f41cf682d0d3 PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 9355
diff changeset
  1027
zfsvfs_rele(zfsvfs_t *zfsvfs, void *tag)
f41cf682d0d3 PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 9355
diff changeset
  1028
{
f41cf682d0d3 PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 9355
diff changeset
  1029
	rrw_exit(&zfsvfs->z_teardown_lock, tag);
f41cf682d0d3 PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 9355
diff changeset
  1030
f41cf682d0d3 PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 9355
diff changeset
  1031
	if (zfsvfs->z_vfs) {
f41cf682d0d3 PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 9355
diff changeset
  1032
		VFS_RELE(zfsvfs->z_vfs);
f41cf682d0d3 PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 9355
diff changeset
  1033
	} else {
10298
a0d52501437c 6860996 %temporary clones are not automatically destroyed on error
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 10272
diff changeset
  1034
		dmu_objset_disown(zfsvfs->z_os, zfsvfs);
9396
f41cf682d0d3 PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 9355
diff changeset
  1035
		zfsvfs_free(zfsvfs);
f41cf682d0d3 PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 9355
diff changeset
  1036
	}
f41cf682d0d3 PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 9355
diff changeset
  1037
}
f41cf682d0d3 PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 9355
diff changeset
  1038
f41cf682d0d3 PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 9355
diff changeset
  1039
static int
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1040
zfs_ioc_pool_create(zfs_cmd_t *zc)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1041
{
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1042
	int error;
5094
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
  1043
	nvlist_t *config, *props = NULL;
7184
9508660f9c27 PSARC 2008/223 Pool root file system properties via zpool(1M)
timh
parents: 7046
diff changeset
  1044
	nvlist_t *rootprops = NULL;
9508660f9c27 PSARC 2008/223 Pool root file system properties via zpool(1M)
timh
parents: 7046
diff changeset
  1045
	nvlist_t *zplprops = NULL;
4715
e8d212dda064 6535695 Panic: shpp->sh_eof == shpp->sh_pool_create_len, file: ../../common/fs/zfs/spa_history.c, line: 235
ek110237
parents: 4670
diff changeset
  1046
	char *buf;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1047
5094
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
  1048
	if (error = get_nvlist(zc->zc_nvlist_conf, zc->zc_nvlist_conf_size,
9643
ffd8e7765f02 6736004 zvols need an additional property for comstar support
Eric Taylor <Eric.Taylor@Sun.COM>
parents: 9425
diff changeset
  1049
	    zc->zc_iflags, &config))
4988
db8abd9846d4 6595467 libzfs consumers should be allowed to write their own history (or none at all)
ek110237
parents: 4849
diff changeset
  1050
		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
  1051
5094
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
  1052
	if (zc->zc_nvlist_src_size != 0 && (error =
9643
ffd8e7765f02 6736004 zvols need an additional property for comstar support
Eric Taylor <Eric.Taylor@Sun.COM>
parents: 9425
diff changeset
  1053
	    get_nvlist(zc->zc_nvlist_src, zc->zc_nvlist_src_size,
ffd8e7765f02 6736004 zvols need an additional property for comstar support
Eric Taylor <Eric.Taylor@Sun.COM>
parents: 9425
diff changeset
  1054
	    zc->zc_iflags, &props))) {
5094
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
  1055
		nvlist_free(config);
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
  1056
		return (error);
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
  1057
	}
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
  1058
7184
9508660f9c27 PSARC 2008/223 Pool root file system properties via zpool(1M)
timh
parents: 7046
diff changeset
  1059
	if (props) {
9508660f9c27 PSARC 2008/223 Pool root file system properties via zpool(1M)
timh
parents: 7046
diff changeset
  1060
		nvlist_t *nvl = NULL;
9508660f9c27 PSARC 2008/223 Pool root file system properties via zpool(1M)
timh
parents: 7046
diff changeset
  1061
		uint64_t version = SPA_VERSION;
9508660f9c27 PSARC 2008/223 Pool root file system properties via zpool(1M)
timh
parents: 7046
diff changeset
  1062
9508660f9c27 PSARC 2008/223 Pool root file system properties via zpool(1M)
timh
parents: 7046
diff changeset
  1063
		(void) nvlist_lookup_uint64(props,
9508660f9c27 PSARC 2008/223 Pool root file system properties via zpool(1M)
timh
parents: 7046
diff changeset
  1064
		    zpool_prop_to_name(ZPOOL_PROP_VERSION), &version);
9508660f9c27 PSARC 2008/223 Pool root file system properties via zpool(1M)
timh
parents: 7046
diff changeset
  1065
		if (version < SPA_VERSION_INITIAL || version > SPA_VERSION) {
9508660f9c27 PSARC 2008/223 Pool root file system properties via zpool(1M)
timh
parents: 7046
diff changeset
  1066
			error = EINVAL;
9508660f9c27 PSARC 2008/223 Pool root file system properties via zpool(1M)
timh
parents: 7046
diff changeset
  1067
			goto pool_props_bad;
9508660f9c27 PSARC 2008/223 Pool root file system properties via zpool(1M)
timh
parents: 7046
diff changeset
  1068
		}
9508660f9c27 PSARC 2008/223 Pool root file system properties via zpool(1M)
timh
parents: 7046
diff changeset
  1069
		(void) nvlist_lookup_nvlist(props, ZPOOL_ROOTFS_PROPS, &nvl);
9508660f9c27 PSARC 2008/223 Pool root file system properties via zpool(1M)
timh
parents: 7046
diff changeset
  1070
		if (nvl) {
9508660f9c27 PSARC 2008/223 Pool root file system properties via zpool(1M)
timh
parents: 7046
diff changeset
  1071
			error = nvlist_dup(nvl, &rootprops, KM_SLEEP);
9508660f9c27 PSARC 2008/223 Pool root file system properties via zpool(1M)
timh
parents: 7046
diff changeset
  1072
			if (error != 0) {
9508660f9c27 PSARC 2008/223 Pool root file system properties via zpool(1M)
timh
parents: 7046
diff changeset
  1073
				nvlist_free(config);
9508660f9c27 PSARC 2008/223 Pool root file system properties via zpool(1M)
timh
parents: 7046
diff changeset
  1074
				nvlist_free(props);
9508660f9c27 PSARC 2008/223 Pool root file system properties via zpool(1M)
timh
parents: 7046
diff changeset
  1075
				return (error);
9508660f9c27 PSARC 2008/223 Pool root file system properties via zpool(1M)
timh
parents: 7046
diff changeset
  1076
			}
9508660f9c27 PSARC 2008/223 Pool root file system properties via zpool(1M)
timh
parents: 7046
diff changeset
  1077
			(void) nvlist_remove_all(props, ZPOOL_ROOTFS_PROPS);
9508660f9c27 PSARC 2008/223 Pool root file system properties via zpool(1M)
timh
parents: 7046
diff changeset
  1078
		}
9508660f9c27 PSARC 2008/223 Pool root file system properties via zpool(1M)
timh
parents: 7046
diff changeset
  1079
		VERIFY(nvlist_alloc(&zplprops, NV_UNIQUE_NAME, KM_SLEEP) == 0);
9508660f9c27 PSARC 2008/223 Pool root file system properties via zpool(1M)
timh
parents: 7046
diff changeset
  1080
		error = zfs_fill_zplprops_root(version, rootprops,
9508660f9c27 PSARC 2008/223 Pool root file system properties via zpool(1M)
timh
parents: 7046
diff changeset
  1081
		    zplprops, NULL);
9508660f9c27 PSARC 2008/223 Pool root file system properties via zpool(1M)
timh
parents: 7046
diff changeset
  1082
		if (error)
9508660f9c27 PSARC 2008/223 Pool root file system properties via zpool(1M)
timh
parents: 7046
diff changeset
  1083
			goto pool_props_bad;
9508660f9c27 PSARC 2008/223 Pool root file system properties via zpool(1M)
timh
parents: 7046
diff changeset
  1084
	}
9508660f9c27 PSARC 2008/223 Pool root file system properties via zpool(1M)
timh
parents: 7046
diff changeset
  1085
4988
db8abd9846d4 6595467 libzfs consumers should be allowed to write their own history (or none at all)
ek110237
parents: 4849
diff changeset
  1086
	buf = history_str_get(zc);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1087
7184
9508660f9c27 PSARC 2008/223 Pool root file system properties via zpool(1M)
timh
parents: 7046
diff changeset
  1088
	error = spa_create(zc->zc_name, config, props, buf, zplprops);
9508660f9c27 PSARC 2008/223 Pool root file system properties via zpool(1M)
timh
parents: 7046
diff changeset
  1089
9508660f9c27 PSARC 2008/223 Pool root file system properties via zpool(1M)
timh
parents: 7046
diff changeset
  1090
	/*
9508660f9c27 PSARC 2008/223 Pool root file system properties via zpool(1M)
timh
parents: 7046
diff changeset
  1091
	 * Set the remaining root properties
9508660f9c27 PSARC 2008/223 Pool root file system properties via zpool(1M)
timh
parents: 7046
diff changeset
  1092
	 */
11022
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 11007
diff changeset
  1093
	if (!error && (error = zfs_set_prop_nvlist(zc->zc_name,
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 11007
diff changeset
  1094
	    ZPROP_SRC_LOCAL, rootprops, NULL)) != 0)
7184
9508660f9c27 PSARC 2008/223 Pool root file system properties via zpool(1M)
timh
parents: 7046
diff changeset
  1095
		(void) spa_destroy(zc->zc_name);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1096
4988
db8abd9846d4 6595467 libzfs consumers should be allowed to write their own history (or none at all)
ek110237
parents: 4849
diff changeset
  1097
	if (buf != NULL)
db8abd9846d4 6595467 libzfs consumers should be allowed to write their own history (or none at all)
ek110237
parents: 4849
diff changeset
  1098
		history_str_free(buf);
5094
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
  1099
7184
9508660f9c27 PSARC 2008/223 Pool root file system properties via zpool(1M)
timh
parents: 7046
diff changeset
  1100
pool_props_bad:
9508660f9c27 PSARC 2008/223 Pool root file system properties via zpool(1M)
timh
parents: 7046
diff changeset
  1101
	nvlist_free(rootprops);
9508660f9c27 PSARC 2008/223 Pool root file system properties via zpool(1M)
timh
parents: 7046
diff changeset
  1102
	nvlist_free(zplprops);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1103
	nvlist_free(config);
7184
9508660f9c27 PSARC 2008/223 Pool root file system properties via zpool(1M)
timh
parents: 7046
diff changeset
  1104
	nvlist_free(props);
5094
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
  1105
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1106
	return (error);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1107
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1108
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1109
static int
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1110
zfs_ioc_pool_destroy(zfs_cmd_t *zc)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1111
{
4543
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  1112
	int error;
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  1113
	zfs_log_history(zc);
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  1114
	error = spa_destroy(zc->zc_name);
10588
dc03f981ea18 6438937 if 'zfs destroy' fails, it can leave a zvol device link missing
Eric Taylor <Eric.Taylor@Sun.COM>
parents: 10474
diff changeset
  1115
	if (error == 0)
dc03f981ea18 6438937 if 'zfs destroy' fails, it can leave a zvol device link missing
Eric Taylor <Eric.Taylor@Sun.COM>
parents: 10474
diff changeset
  1116
		zvol_remove_minors(zc->zc_name);
4543
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  1117
	return (error);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1118
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1119
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1120
static int
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1121
zfs_ioc_pool_import(zfs_cmd_t *zc)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1122
{
5094
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
  1123
	nvlist_t *config, *props = NULL;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1124
	uint64_t guid;
10921
8aac17999e4d PSARC 2009/479 zpool recovery support
Tim Haley <Tim.Haley@Sun.COM>
parents: 10850
diff changeset
  1125
	int error;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1126
5094
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
  1127
	if ((error = get_nvlist(zc->zc_nvlist_conf, zc->zc_nvlist_conf_size,
9643
ffd8e7765f02 6736004 zvols need an additional property for comstar support
Eric Taylor <Eric.Taylor@Sun.COM>
parents: 9425
diff changeset
  1128
	    zc->zc_iflags, &config)) != 0)
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1129
		return (error);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1130
5094
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
  1131
	if (zc->zc_nvlist_src_size != 0 && (error =
9643
ffd8e7765f02 6736004 zvols need an additional property for comstar support
Eric Taylor <Eric.Taylor@Sun.COM>
parents: 9425
diff changeset
  1132
	    get_nvlist(zc->zc_nvlist_src, zc->zc_nvlist_src_size,
ffd8e7765f02 6736004 zvols need an additional property for comstar support
Eric Taylor <Eric.Taylor@Sun.COM>
parents: 9425
diff changeset
  1133
	    zc->zc_iflags, &props))) {
5094
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
  1134
		nvlist_free(config);
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
  1135
		return (error);
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
  1136
	}
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
  1137
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1138
	if (nvlist_lookup_uint64(config, ZPOOL_CONFIG_POOL_GUID, &guid) != 0 ||
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
  1139
	    guid != zc->zc_guid)
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1140
		error = EINVAL;
6643
3a34b0dbb107 6625086 changing cachefile doesn't remove old cache on last user
eschrock
parents: 6492
diff changeset
  1141
	else if (zc->zc_cookie)
10921
8aac17999e4d PSARC 2009/479 zpool recovery support
Tim Haley <Tim.Haley@Sun.COM>
parents: 10850
diff changeset
  1142
		error = spa_import_verbatim(zc->zc_name, config, props);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1143
	else
5094
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
  1144
		error = spa_import(zc->zc_name, config, props);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1145
10921
8aac17999e4d PSARC 2009/479 zpool recovery support
Tim Haley <Tim.Haley@Sun.COM>
parents: 10850
diff changeset
  1146
	if (zc->zc_nvlist_dst != 0)
8aac17999e4d PSARC 2009/479 zpool recovery support
Tim Haley <Tim.Haley@Sun.COM>
parents: 10850
diff changeset
  1147
		(void) put_nvlist(zc, config);
8aac17999e4d PSARC 2009/479 zpool recovery support
Tim Haley <Tim.Haley@Sun.COM>
parents: 10850
diff changeset
  1148
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1149
	nvlist_free(config);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1150
5094
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
  1151
	if (props)
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
  1152
		nvlist_free(props);
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
  1153
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1154
	return (error);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1155
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1156
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1157
static int
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1158
zfs_ioc_pool_export(zfs_cmd_t *zc)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1159
{
4543
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  1160
	int error;
7214
04c540040a32 6721908 A hot spare "in use" in an exported zpool, is stolen when a disk fails in an imported pool.
lling
parents: 7184
diff changeset
  1161
	boolean_t force = (boolean_t)zc->zc_cookie;
8211
32722be6ad3b 6775357 ZFS should have a way to export a pool without touching anything
George Wilson <George.Wilson@Sun.COM>
parents: 8080
diff changeset
  1162
	boolean_t hardforce = (boolean_t)zc->zc_guid;
7214
04c540040a32 6721908 A hot spare "in use" in an exported zpool, is stolen when a disk fails in an imported pool.
lling
parents: 7184
diff changeset
  1163
4543
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  1164
	zfs_log_history(zc);
8211
32722be6ad3b 6775357 ZFS should have a way to export a pool without touching anything
George Wilson <George.Wilson@Sun.COM>
parents: 8080
diff changeset
  1165
	error = spa_export(zc->zc_name, NULL, force, hardforce);
10588
dc03f981ea18 6438937 if 'zfs destroy' fails, it can leave a zvol device link missing
Eric Taylor <Eric.Taylor@Sun.COM>
parents: 10474
diff changeset
  1166
	if (error == 0)
dc03f981ea18 6438937 if 'zfs destroy' fails, it can leave a zvol device link missing
Eric Taylor <Eric.Taylor@Sun.COM>
parents: 10474
diff changeset
  1167
		zvol_remove_minors(zc->zc_name);
4543
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  1168
	return (error);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1169
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1170
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1171
static int
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1172
zfs_ioc_pool_configs(zfs_cmd_t *zc)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1173
{
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1174
	nvlist_t *configs;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1175
	int error;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1176
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1177
	if ((configs = spa_all_configs(&zc->zc_cookie)) == NULL)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1178
		return (EEXIST);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1179
2676
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  1180
	error = put_nvlist(zc, configs);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1181
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1182
	nvlist_free(configs);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1183
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1184
	return (error);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1185
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1186
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1187
static int
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1188
zfs_ioc_pool_stats(zfs_cmd_t *zc)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1189
{
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1190
	nvlist_t *config;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1191
	int error;
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
  1192
	int ret = 0;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1193
2676
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  1194
	error = spa_get_stats(zc->zc_name, &config, zc->zc_value,
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  1195
	    sizeof (zc->zc_value));
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1196
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1197
	if (config != NULL) {
2676
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  1198
		ret = put_nvlist(zc, config);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1199
		nvlist_free(config);
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
  1200
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
  1201
		/*
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
  1202
		 * The config may be present even if 'error' is non-zero.
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
  1203
		 * In this case we return success, and preserve the real errno
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
  1204
		 * in 'zc_cookie'.
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
  1205
		 */
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
  1206
		zc->zc_cookie = error;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1207
	} else {
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
  1208
		ret = error;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1209
	}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1210
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
  1211
	return (ret);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1212
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1213
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1214
/*
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1215
 * Try to import the given pool, returning pool stats as appropriate so that
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1216
 * user land knows which devices are available and overall pool health.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1217
 */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1218
static int
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1219
zfs_ioc_pool_tryimport(zfs_cmd_t *zc)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1220
{
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1221
	nvlist_t *tryconfig, *config;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1222
	int error;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1223
5094
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
  1224
	if ((error = get_nvlist(zc->zc_nvlist_conf, zc->zc_nvlist_conf_size,
9643
ffd8e7765f02 6736004 zvols need an additional property for comstar support
Eric Taylor <Eric.Taylor@Sun.COM>
parents: 9425
diff changeset
  1225
	    zc->zc_iflags, &tryconfig)) != 0)
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
	config = spa_tryimport(tryconfig);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1229
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1230
	nvlist_free(tryconfig);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1231
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1232
	if (config == NULL)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1233
		return (EINVAL);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1234
2676
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  1235
	error = put_nvlist(zc, config);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1236
	nvlist_free(config);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1237
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1238
	return (error);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1239
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1240
12296
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 11935
diff changeset
  1241
/*
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 11935
diff changeset
  1242
 * inputs:
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 11935
diff changeset
  1243
 * zc_name              name of the pool
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 11935
diff changeset
  1244
 * zc_cookie            scan func (pool_scan_func_t)
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 11935
diff changeset
  1245
 */
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1246
static int
12296
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 11935
diff changeset
  1247
zfs_ioc_pool_scan(zfs_cmd_t *zc)
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1248
{
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1249
	spa_t *spa;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1250
	int error;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1251
2926
acfcfefbc60d PSARC 2006/288 zpool history
ek110237
parents: 2885
diff changeset
  1252
	if ((error = spa_open(zc->zc_name, &spa, FTAG)) != 0)
acfcfefbc60d PSARC 2006/288 zpool history
ek110237
parents: 2885
diff changeset
  1253
		return (error);
acfcfefbc60d PSARC 2006/288 zpool history
ek110237
parents: 2885
diff changeset
  1254
12296
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 11935
diff changeset
  1255
	if (zc->zc_cookie == POOL_SCAN_NONE)
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 11935
diff changeset
  1256
		error = spa_scan_stop(spa);
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 11935
diff changeset
  1257
	else
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 11935
diff changeset
  1258
		error = spa_scan(spa, zc->zc_cookie);
2926
acfcfefbc60d PSARC 2006/288 zpool history
ek110237
parents: 2885
diff changeset
  1259
acfcfefbc60d PSARC 2006/288 zpool history
ek110237
parents: 2885
diff changeset
  1260
	spa_close(spa, FTAG);
acfcfefbc60d PSARC 2006/288 zpool history
ek110237
parents: 2885
diff changeset
  1261
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1262
	return (error);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1263
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1264
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1265
static int
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1266
zfs_ioc_pool_freeze(zfs_cmd_t *zc)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1267
{
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1268
	spa_t *spa;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1269
	int error;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1270
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1271
	error = spa_open(zc->zc_name, &spa, FTAG);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1272
	if (error == 0) {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1273
		spa_freeze(spa);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1274
		spa_close(spa, FTAG);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1275
	}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1276
	return (error);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1277
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1278
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1279
static int
1760
e1ad2821c30d PSARC 2006/206 zpool upgrade
eschrock
parents: 1544
diff changeset
  1280
zfs_ioc_pool_upgrade(zfs_cmd_t *zc)
e1ad2821c30d PSARC 2006/206 zpool upgrade
eschrock
parents: 1544
diff changeset
  1281
{
e1ad2821c30d PSARC 2006/206 zpool upgrade
eschrock
parents: 1544
diff changeset
  1282
	spa_t *spa;
e1ad2821c30d PSARC 2006/206 zpool upgrade
eschrock
parents: 1544
diff changeset
  1283
	int error;
e1ad2821c30d PSARC 2006/206 zpool upgrade
eschrock
parents: 1544
diff changeset
  1284
2926
acfcfefbc60d PSARC 2006/288 zpool history
ek110237
parents: 2885
diff changeset
  1285
	if ((error = spa_open(zc->zc_name, &spa, FTAG)) != 0)
acfcfefbc60d PSARC 2006/288 zpool history
ek110237
parents: 2885
diff changeset
  1286
		return (error);
acfcfefbc60d PSARC 2006/288 zpool history
ek110237
parents: 2885
diff changeset
  1287
5118
c723b1aa9f79 6607671 Able to zpool upgrade a pool to an unknown version number
lling
parents: 5094
diff changeset
  1288
	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
  1289
		spa_close(spa, FTAG);
c723b1aa9f79 6607671 Able to zpool upgrade a pool to an unknown version number
lling
parents: 5094
diff changeset
  1290
		return (EINVAL);
c723b1aa9f79 6607671 Able to zpool upgrade a pool to an unknown version number
lling
parents: 5094
diff changeset
  1291
	}
c723b1aa9f79 6607671 Able to zpool upgrade a pool to an unknown version number
lling
parents: 5094
diff changeset
  1292
5094
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
  1293
	spa_upgrade(spa, zc->zc_cookie);
2926
acfcfefbc60d PSARC 2006/288 zpool history
ek110237
parents: 2885
diff changeset
  1294
	spa_close(spa, FTAG);
acfcfefbc60d PSARC 2006/288 zpool history
ek110237
parents: 2885
diff changeset
  1295
acfcfefbc60d PSARC 2006/288 zpool history
ek110237
parents: 2885
diff changeset
  1296
	return (error);
acfcfefbc60d PSARC 2006/288 zpool history
ek110237
parents: 2885
diff changeset
  1297
}
acfcfefbc60d PSARC 2006/288 zpool history
ek110237
parents: 2885
diff changeset
  1298
acfcfefbc60d PSARC 2006/288 zpool history
ek110237
parents: 2885
diff changeset
  1299
static int
acfcfefbc60d PSARC 2006/288 zpool history
ek110237
parents: 2885
diff changeset
  1300
zfs_ioc_pool_get_history(zfs_cmd_t *zc)
acfcfefbc60d PSARC 2006/288 zpool history
ek110237
parents: 2885
diff changeset
  1301
{
acfcfefbc60d PSARC 2006/288 zpool history
ek110237
parents: 2885
diff changeset
  1302
	spa_t *spa;
acfcfefbc60d PSARC 2006/288 zpool history
ek110237
parents: 2885
diff changeset
  1303
	char *hist_buf;
acfcfefbc60d PSARC 2006/288 zpool history
ek110237
parents: 2885
diff changeset
  1304
	uint64_t size;
acfcfefbc60d PSARC 2006/288 zpool history
ek110237
parents: 2885
diff changeset
  1305
	int error;
acfcfefbc60d PSARC 2006/288 zpool history
ek110237
parents: 2885
diff changeset
  1306
acfcfefbc60d PSARC 2006/288 zpool history
ek110237
parents: 2885
diff changeset
  1307
	if ((size = zc->zc_history_len) == 0)
acfcfefbc60d PSARC 2006/288 zpool history
ek110237
parents: 2885
diff changeset
  1308
		return (EINVAL);
acfcfefbc60d PSARC 2006/288 zpool history
ek110237
parents: 2885
diff changeset
  1309
acfcfefbc60d PSARC 2006/288 zpool history
ek110237
parents: 2885
diff changeset
  1310
	if ((error = spa_open(zc->zc_name, &spa, FTAG)) != 0)
acfcfefbc60d PSARC 2006/288 zpool history
ek110237
parents: 2885
diff changeset
  1311
		return (error);
acfcfefbc60d PSARC 2006/288 zpool history
ek110237
parents: 2885
diff changeset
  1312
4577
ed36b0e652bc PSARC/2007/328 zfs upgrade
ahrens
parents: 4543
diff changeset
  1313
	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
  1314
		spa_close(spa, FTAG);
d56571426115 6529406 zpool history needs to bump the on-disk version
ek110237
parents: 3741
diff changeset
  1315
		return (ENOTSUP);
d56571426115 6529406 zpool history needs to bump the on-disk version
ek110237
parents: 3741
diff changeset
  1316
	}
d56571426115 6529406 zpool history needs to bump the on-disk version
ek110237
parents: 3741
diff changeset
  1317
2926
acfcfefbc60d PSARC 2006/288 zpool history
ek110237
parents: 2885
diff changeset
  1318
	hist_buf = kmem_alloc(size, KM_SLEEP);
acfcfefbc60d PSARC 2006/288 zpool history
ek110237
parents: 2885
diff changeset
  1319
	if ((error = spa_history_get(spa, &zc->zc_history_offset,
acfcfefbc60d PSARC 2006/288 zpool history
ek110237
parents: 2885
diff changeset
  1320
	    &zc->zc_history_len, hist_buf)) == 0) {
9643
ffd8e7765f02 6736004 zvols need an additional property for comstar support
Eric Taylor <Eric.Taylor@Sun.COM>
parents: 9425
diff changeset
  1321
		error = ddi_copyout(hist_buf,
ffd8e7765f02 6736004 zvols need an additional property for comstar support
Eric Taylor <Eric.Taylor@Sun.COM>
parents: 9425
diff changeset
  1322
		    (void *)(uintptr_t)zc->zc_history,
ffd8e7765f02 6736004 zvols need an additional property for comstar support
Eric Taylor <Eric.Taylor@Sun.COM>
parents: 9425
diff changeset
  1323
		    zc->zc_history_len, zc->zc_iflags);
2926
acfcfefbc60d PSARC 2006/288 zpool history
ek110237
parents: 2885
diff changeset
  1324
	}
acfcfefbc60d PSARC 2006/288 zpool history
ek110237
parents: 2885
diff changeset
  1325
acfcfefbc60d PSARC 2006/288 zpool history
ek110237
parents: 2885
diff changeset
  1326
	spa_close(spa, FTAG);
acfcfefbc60d PSARC 2006/288 zpool history
ek110237
parents: 2885
diff changeset
  1327
	kmem_free(hist_buf, size);
acfcfefbc60d PSARC 2006/288 zpool history
ek110237
parents: 2885
diff changeset
  1328
	return (error);
acfcfefbc60d PSARC 2006/288 zpool history
ek110237
parents: 2885
diff changeset
  1329
}
acfcfefbc60d PSARC 2006/288 zpool history
ek110237
parents: 2885
diff changeset
  1330
acfcfefbc60d PSARC 2006/288 zpool history
ek110237
parents: 2885
diff changeset
  1331
static int
3444
dc160a70a50d 6410433 'zpool status -v' would be more useful with filenames
ek110237
parents: 3265
diff changeset
  1332
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
  1333
{
dc160a70a50d 6410433 'zpool status -v' would be more useful with filenames
ek110237
parents: 3265
diff changeset
  1334
	int error;
dc160a70a50d 6410433 'zpool status -v' would be more useful with filenames
ek110237
parents: 3265
diff changeset
  1335
3912
f6891a60bd72 PSARC 2007/083 ZFS bootable datasets
lling
parents: 3886
diff changeset
  1336
	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
  1337
		return (error);
dc160a70a50d 6410433 'zpool status -v' would be more useful with filenames
ek110237
parents: 3265
diff changeset
  1338
dc160a70a50d 6410433 'zpool status -v' would be more useful with filenames
ek110237
parents: 3265
diff changeset
  1339
	return (0);
dc160a70a50d 6410433 'zpool status -v' would be more useful with filenames
ek110237
parents: 3265
diff changeset
  1340
}
dc160a70a50d 6410433 'zpool status -v' would be more useful with filenames
ek110237
parents: 3265
diff changeset
  1341
10298
a0d52501437c 6860996 %temporary clones are not automatically destroyed on error
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 10272
diff changeset
  1342
/*
a0d52501437c 6860996 %temporary clones are not automatically destroyed on error
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 10272
diff changeset
  1343
 * inputs:
a0d52501437c 6860996 %temporary clones are not automatically destroyed on error
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 10272
diff changeset
  1344
 * zc_name		name of filesystem
a0d52501437c 6860996 %temporary clones are not automatically destroyed on error
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 10272
diff changeset
  1345
 * zc_obj		object to find
a0d52501437c 6860996 %temporary clones are not automatically destroyed on error
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 10272
diff changeset
  1346
 *
a0d52501437c 6860996 %temporary clones are not automatically destroyed on error
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 10272
diff changeset
  1347
 * outputs:
a0d52501437c 6860996 %temporary clones are not automatically destroyed on error
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 10272
diff changeset
  1348
 * zc_value		name of object
a0d52501437c 6860996 %temporary clones are not automatically destroyed on error
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 10272
diff changeset
  1349
 */
3444
dc160a70a50d 6410433 'zpool status -v' would be more useful with filenames
ek110237
parents: 3265
diff changeset
  1350
static int
dc160a70a50d 6410433 'zpool status -v' would be more useful with filenames
ek110237
parents: 3265
diff changeset
  1351
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
  1352
{
10298
a0d52501437c 6860996 %temporary clones are not automatically destroyed on error
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 10272
diff changeset
  1353
	objset_t *os;
3444
dc160a70a50d 6410433 'zpool status -v' would be more useful with filenames
ek110237
parents: 3265
diff changeset
  1354
	int error;
dc160a70a50d 6410433 'zpool status -v' would be more useful with filenames
ek110237
parents: 3265
diff changeset
  1355
10298
a0d52501437c 6860996 %temporary clones are not automatically destroyed on error
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 10272
diff changeset
  1356
	/* XXX reading from objset not owned */
a0d52501437c 6860996 %temporary clones are not automatically destroyed on error
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 10272
diff changeset
  1357
	if ((error = dmu_objset_hold(zc->zc_name, FTAG, &os)) != 0)
3444
dc160a70a50d 6410433 'zpool status -v' would be more useful with filenames
ek110237
parents: 3265
diff changeset
  1358
		return (error);
10298
a0d52501437c 6860996 %temporary clones are not automatically destroyed on error
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 10272
diff changeset
  1359
	if (dmu_objset_type(os) != DMU_OST_ZFS) {
a0d52501437c 6860996 %temporary clones are not automatically destroyed on error
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 10272
diff changeset
  1360
		dmu_objset_rele(os, FTAG);
a0d52501437c 6860996 %temporary clones are not automatically destroyed on error
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 10272
diff changeset
  1361
		return (EINVAL);
a0d52501437c 6860996 %temporary clones are not automatically destroyed on error
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 10272
diff changeset
  1362
	}
a0d52501437c 6860996 %temporary clones are not automatically destroyed on error
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 10272
diff changeset
  1363
	error = zfs_obj_to_path(os, zc->zc_obj, zc->zc_value,
3444
dc160a70a50d 6410433 'zpool status -v' would be more useful with filenames
ek110237
parents: 3265
diff changeset
  1364
	    sizeof (zc->zc_value));
10298
a0d52501437c 6860996 %temporary clones are not automatically destroyed on error
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 10272
diff changeset
  1365
	dmu_objset_rele(os, FTAG);
3444
dc160a70a50d 6410433 'zpool status -v' would be more useful with filenames
ek110237
parents: 3265
diff changeset
  1366
dc160a70a50d 6410433 'zpool status -v' would be more useful with filenames
ek110237
parents: 3265
diff changeset
  1367
	return (error);
dc160a70a50d 6410433 'zpool status -v' would be more useful with filenames
ek110237
parents: 3265
diff changeset
  1368
}
dc160a70a50d 6410433 'zpool status -v' would be more useful with filenames
ek110237
parents: 3265
diff changeset
  1369
dc160a70a50d 6410433 'zpool status -v' would be more useful with filenames
ek110237
parents: 3265
diff changeset
  1370
static int
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1371
zfs_ioc_vdev_add(zfs_cmd_t *zc)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1372
{
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1373
	spa_t *spa;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1374
	int error;
6423
437422a29d3a PSARC 2006/370 ZFS Boot Support
gw25295
parents: 6139
diff changeset
  1375
	nvlist_t *config, **l2cache, **spares;
437422a29d3a PSARC 2006/370 ZFS Boot Support
gw25295
parents: 6139
diff changeset
  1376
	uint_t nl2cache = 0, nspares = 0;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1377
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1378
	error = spa_open(zc->zc_name, &spa, FTAG);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1379
	if (error != 0)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1380
		return (error);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1381
5450
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5446
diff changeset
  1382
	error = get_nvlist(zc->zc_nvlist_conf, zc->zc_nvlist_conf_size,
9643
ffd8e7765f02 6736004 zvols need an additional property for comstar support
Eric Taylor <Eric.Taylor@Sun.COM>
parents: 9425
diff changeset
  1383
	    zc->zc_iflags, &config);
5450
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5446
diff changeset
  1384
	(void) nvlist_lookup_nvlist_array(config, ZPOOL_CONFIG_L2CACHE,
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5446
diff changeset
  1385
	    &l2cache, &nl2cache);
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5446
diff changeset
  1386
6423
437422a29d3a PSARC 2006/370 ZFS Boot Support
gw25295
parents: 6139
diff changeset
  1387
	(void) nvlist_lookup_nvlist_array(config, ZPOOL_CONFIG_SPARES,
437422a29d3a PSARC 2006/370 ZFS Boot Support
gw25295
parents: 6139
diff changeset
  1388
	    &spares, &nspares);
437422a29d3a PSARC 2006/370 ZFS Boot Support
gw25295
parents: 6139
diff changeset
  1389
3912
f6891a60bd72 PSARC 2007/083 ZFS bootable datasets
lling
parents: 3886
diff changeset
  1390
	/*
f6891a60bd72 PSARC 2007/083 ZFS bootable datasets
lling
parents: 3886
diff changeset
  1391
	 * A root pool with concatenated devices is not supported.
6423
437422a29d3a PSARC 2006/370 ZFS Boot Support
gw25295
parents: 6139
diff changeset
  1392
	 * Thus, can not add a device to a root pool.
437422a29d3a PSARC 2006/370 ZFS Boot Support
gw25295
parents: 6139
diff changeset
  1393
	 *
437422a29d3a PSARC 2006/370 ZFS Boot Support
gw25295
parents: 6139
diff changeset
  1394
	 * Intent log device can not be added to a rootpool because
437422a29d3a PSARC 2006/370 ZFS Boot Support
gw25295
parents: 6139
diff changeset
  1395
	 * during mountroot, zil is replayed, a seperated log device
437422a29d3a PSARC 2006/370 ZFS Boot Support
gw25295
parents: 6139
diff changeset
  1396
	 * can not be accessed during the mountroot time.
437422a29d3a PSARC 2006/370 ZFS Boot Support
gw25295
parents: 6139
diff changeset
  1397
	 *
437422a29d3a PSARC 2006/370 ZFS Boot Support
gw25295
parents: 6139
diff changeset
  1398
	 * l2cache and spare devices are ok to be added to a rootpool.
3912
f6891a60bd72 PSARC 2007/083 ZFS bootable datasets
lling
parents: 3886
diff changeset
  1399
	 */
10922
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
  1400
	if (spa_bootfs(spa) != 0 && nl2cache == 0 && nspares == 0) {
11422
42768837421d PSARC/2009/511 zpool split
Mark J Musante <Mark.Musante@Sun.COM>
parents: 11314
diff changeset
  1401
		nvlist_free(config);
3912
f6891a60bd72 PSARC 2007/083 ZFS bootable datasets
lling
parents: 3886
diff changeset
  1402
		spa_close(spa, FTAG);
f6891a60bd72 PSARC 2007/083 ZFS bootable datasets
lling
parents: 3886
diff changeset
  1403
		return (EDOM);
f6891a60bd72 PSARC 2007/083 ZFS bootable datasets
lling
parents: 3886
diff changeset
  1404
	}
f6891a60bd72 PSARC 2007/083 ZFS bootable datasets
lling
parents: 3886
diff changeset
  1405
5450
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5446
diff changeset
  1406
	if (error == 0) {
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1407
		error = spa_vdev_add(spa, config);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1408
		nvlist_free(config);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1409
	}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1410
	spa_close(spa, FTAG);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1411
	return (error);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1412
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1413
12296
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 11935
diff changeset
  1414
/*
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 11935
diff changeset
  1415
 * inputs:
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 11935
diff changeset
  1416
 * zc_name		name of the pool
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 11935
diff changeset
  1417
 * zc_nvlist_conf	nvlist of devices to remove
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 11935
diff changeset
  1418
 * zc_cookie		to stop the remove?
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 11935
diff changeset
  1419
 */
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1420
static int
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1421
zfs_ioc_vdev_remove(zfs_cmd_t *zc)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1422
{
2082
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1775
diff changeset
  1423
	spa_t *spa;
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1775
diff changeset
  1424
	int error;
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1775
diff changeset
  1425
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1775
diff changeset
  1426
	error = spa_open(zc->zc_name, &spa, FTAG);
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1775
diff changeset
  1427
	if (error != 0)
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1775
diff changeset
  1428
		return (error);
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1775
diff changeset
  1429
	error = spa_vdev_remove(spa, zc->zc_guid, B_FALSE);
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1775
diff changeset
  1430
	spa_close(spa, FTAG);
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1775
diff changeset
  1431
	return (error);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1432
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1433
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1434
static int
4451
24fbf2d7a5d7 PSARC 2007/197 ZFS hotplug
eschrock
parents: 4098
diff changeset
  1435
zfs_ioc_vdev_set_state(zfs_cmd_t *zc)
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1436
{
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1437
	spa_t *spa;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1438
	int error;
4451
24fbf2d7a5d7 PSARC 2007/197 ZFS hotplug
eschrock
parents: 4098
diff changeset
  1439
	vdev_state_t newstate = VDEV_STATE_UNKNOWN;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1440
2926
acfcfefbc60d PSARC 2006/288 zpool history
ek110237
parents: 2885
diff changeset
  1441
	if ((error = spa_open(zc->zc_name, &spa, FTAG)) != 0)
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1442
		return (error);
4451
24fbf2d7a5d7 PSARC 2007/197 ZFS hotplug
eschrock
parents: 4098
diff changeset
  1443
	switch (zc->zc_cookie) {
24fbf2d7a5d7 PSARC 2007/197 ZFS hotplug
eschrock
parents: 4098
diff changeset
  1444
	case VDEV_STATE_ONLINE:
24fbf2d7a5d7 PSARC 2007/197 ZFS hotplug
eschrock
parents: 4098
diff changeset
  1445
		error = vdev_online(spa, zc->zc_guid, zc->zc_obj, &newstate);
24fbf2d7a5d7 PSARC 2007/197 ZFS hotplug
eschrock
parents: 4098
diff changeset
  1446
		break;
24fbf2d7a5d7 PSARC 2007/197 ZFS hotplug
eschrock
parents: 4098
diff changeset
  1447
24fbf2d7a5d7 PSARC 2007/197 ZFS hotplug
eschrock
parents: 4098
diff changeset
  1448
	case VDEV_STATE_OFFLINE:
24fbf2d7a5d7 PSARC 2007/197 ZFS hotplug
eschrock
parents: 4098
diff changeset
  1449
		error = vdev_offline(spa, zc->zc_guid, zc->zc_obj);
24fbf2d7a5d7 PSARC 2007/197 ZFS hotplug
eschrock
parents: 4098
diff changeset
  1450
		break;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1451
4451
24fbf2d7a5d7 PSARC 2007/197 ZFS hotplug
eschrock
parents: 4098
diff changeset
  1452
	case VDEV_STATE_FAULTED:
10817
7dfde45252f0 6889826 ZFS retire agent should be able to repair pools
Eric Schrock <Eric.Schrock@Sun.COM>
parents: 10693
diff changeset
  1453
		if (zc->zc_obj != VDEV_AUX_ERR_EXCEEDED &&
7dfde45252f0 6889826 ZFS retire agent should be able to repair pools
Eric Schrock <Eric.Schrock@Sun.COM>
parents: 10693
diff changeset
  1454
		    zc->zc_obj != VDEV_AUX_EXTERNAL)
7dfde45252f0 6889826 ZFS retire agent should be able to repair pools
Eric Schrock <Eric.Schrock@Sun.COM>
parents: 10693
diff changeset
  1455
			zc->zc_obj = VDEV_AUX_ERR_EXCEEDED;
7dfde45252f0 6889826 ZFS retire agent should be able to repair pools
Eric Schrock <Eric.Schrock@Sun.COM>
parents: 10693
diff changeset
  1456
7dfde45252f0 6889826 ZFS retire agent should be able to repair pools
Eric Schrock <Eric.Schrock@Sun.COM>
parents: 10693
diff changeset
  1457
		error = vdev_fault(spa, zc->zc_guid, zc->zc_obj);
4451
24fbf2d7a5d7 PSARC 2007/197 ZFS hotplug
eschrock
parents: 4098
diff changeset
  1458
		break;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1459
4451
24fbf2d7a5d7 PSARC 2007/197 ZFS hotplug
eschrock
parents: 4098
diff changeset
  1460
	case VDEV_STATE_DEGRADED:
10817
7dfde45252f0 6889826 ZFS retire agent should be able to repair pools
Eric Schrock <Eric.Schrock@Sun.COM>
parents: 10693
diff changeset
  1461
		if (zc->zc_obj != VDEV_AUX_ERR_EXCEEDED &&
7dfde45252f0 6889826 ZFS retire agent should be able to repair pools
Eric Schrock <Eric.Schrock@Sun.COM>
parents: 10693
diff changeset
  1462
		    zc->zc_obj != VDEV_AUX_EXTERNAL)
7dfde45252f0 6889826 ZFS retire agent should be able to repair pools
Eric Schrock <Eric.Schrock@Sun.COM>
parents: 10693
diff changeset
  1463
			zc->zc_obj = VDEV_AUX_ERR_EXCEEDED;
7dfde45252f0 6889826 ZFS retire agent should be able to repair pools
Eric Schrock <Eric.Schrock@Sun.COM>
parents: 10693
diff changeset
  1464
7dfde45252f0 6889826 ZFS retire agent should be able to repair pools
Eric Schrock <Eric.Schrock@Sun.COM>
parents: 10693
diff changeset
  1465
		error = vdev_degrade(spa, zc->zc_guid, zc->zc_obj);
4451
24fbf2d7a5d7 PSARC 2007/197 ZFS hotplug
eschrock
parents: 4098
diff changeset
  1466
		break;
24fbf2d7a5d7 PSARC 2007/197 ZFS hotplug
eschrock
parents: 4098
diff changeset
  1467
24fbf2d7a5d7 PSARC 2007/197 ZFS hotplug
eschrock
parents: 4098
diff changeset
  1468
	default:
24fbf2d7a5d7 PSARC 2007/197 ZFS hotplug
eschrock
parents: 4098
diff changeset
  1469
		error = EINVAL;
24fbf2d7a5d7 PSARC 2007/197 ZFS hotplug
eschrock
parents: 4098
diff changeset
  1470
	}
24fbf2d7a5d7 PSARC 2007/197 ZFS hotplug
eschrock
parents: 4098
diff changeset
  1471
	zc->zc_cookie = newstate;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1472
	spa_close(spa, FTAG);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1473
	return (error);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1474
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1475
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1476
static int
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1477
zfs_ioc_vdev_attach(zfs_cmd_t *zc)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1478
{
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1479
	spa_t *spa;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1480
	int replacing = zc->zc_cookie;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1481
	nvlist_t *config;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1482
	int error;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1483
2926
acfcfefbc60d PSARC 2006/288 zpool history
ek110237
parents: 2885
diff changeset
  1484
	if ((error = spa_open(zc->zc_name, &spa, FTAG)) != 0)
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1485
		return (error);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1486
5094
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
  1487
	if ((error = get_nvlist(zc->zc_nvlist_conf, zc->zc_nvlist_conf_size,
9643
ffd8e7765f02 6736004 zvols need an additional property for comstar support
Eric Taylor <Eric.Taylor@Sun.COM>
parents: 9425
diff changeset
  1488
	    zc->zc_iflags, &config)) == 0) {
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
  1489
		error = spa_vdev_attach(spa, zc->zc_guid, config, replacing);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1490
		nvlist_free(config);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1491
	}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1492
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1493
	spa_close(spa, FTAG);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1494
	return (error);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1495
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1496
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1497
static int
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1498
zfs_ioc_vdev_detach(zfs_cmd_t *zc)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1499
{
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1500
	spa_t *spa;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1501
	int error;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1502
2926
acfcfefbc60d PSARC 2006/288 zpool history
ek110237
parents: 2885
diff changeset
  1503
	if ((error = spa_open(zc->zc_name, &spa, FTAG)) != 0)
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1504
		return (error);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1505
8241
5a60f16123ba 6328632 zpool offline is a bit too conservative
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 8213
diff changeset
  1506
	error = spa_vdev_detach(spa, zc->zc_guid, 0, B_FALSE);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1507
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1508
	spa_close(spa, FTAG);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1509
	return (error);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1510
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1511
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1512
static int
11422
42768837421d PSARC/2009/511 zpool split
Mark J Musante <Mark.Musante@Sun.COM>
parents: 11314
diff changeset
  1513
zfs_ioc_vdev_split(zfs_cmd_t *zc)
42768837421d PSARC/2009/511 zpool split
Mark J Musante <Mark.Musante@Sun.COM>
parents: 11314
diff changeset
  1514
{
42768837421d PSARC/2009/511 zpool split
Mark J Musante <Mark.Musante@Sun.COM>
parents: 11314
diff changeset
  1515
	spa_t *spa;
42768837421d PSARC/2009/511 zpool split
Mark J Musante <Mark.Musante@Sun.COM>
parents: 11314
diff changeset
  1516
	nvlist_t *config, *props = NULL;
42768837421d PSARC/2009/511 zpool split
Mark J Musante <Mark.Musante@Sun.COM>
parents: 11314
diff changeset
  1517
	int error;
42768837421d PSARC/2009/511 zpool split
Mark J Musante <Mark.Musante@Sun.COM>
parents: 11314
diff changeset
  1518
	boolean_t exp = !!(zc->zc_cookie & ZPOOL_EXPORT_AFTER_SPLIT);
42768837421d PSARC/2009/511 zpool split
Mark J Musante <Mark.Musante@Sun.COM>
parents: 11314
diff changeset
  1519
42768837421d PSARC/2009/511 zpool split
Mark J Musante <Mark.Musante@Sun.COM>
parents: 11314
diff changeset
  1520
	if ((error = spa_open(zc->zc_name, &spa, FTAG)) != 0)
42768837421d PSARC/2009/511 zpool split
Mark J Musante <Mark.Musante@Sun.COM>
parents: 11314
diff changeset
  1521
		return (error);
42768837421d PSARC/2009/511 zpool split
Mark J Musante <Mark.Musante@Sun.COM>
parents: 11314
diff changeset
  1522
42768837421d PSARC/2009/511 zpool split
Mark J Musante <Mark.Musante@Sun.COM>
parents: 11314
diff changeset
  1523
	if (error = get_nvlist(zc->zc_nvlist_conf, zc->zc_nvlist_conf_size,
42768837421d PSARC/2009/511 zpool split
Mark J Musante <Mark.Musante@Sun.COM>
parents: 11314
diff changeset
  1524
	    zc->zc_iflags, &config)) {
42768837421d PSARC/2009/511 zpool split
Mark J Musante <Mark.Musante@Sun.COM>
parents: 11314
diff changeset
  1525
		spa_close(spa, FTAG);
42768837421d PSARC/2009/511 zpool split
Mark J Musante <Mark.Musante@Sun.COM>
parents: 11314
diff changeset
  1526
		return (error);
42768837421d PSARC/2009/511 zpool split
Mark J Musante <Mark.Musante@Sun.COM>
parents: 11314
diff changeset
  1527
	}
42768837421d PSARC/2009/511 zpool split
Mark J Musante <Mark.Musante@Sun.COM>
parents: 11314
diff changeset
  1528
42768837421d PSARC/2009/511 zpool split
Mark J Musante <Mark.Musante@Sun.COM>
parents: 11314
diff changeset
  1529
	if (zc->zc_nvlist_src_size != 0 && (error =
42768837421d PSARC/2009/511 zpool split
Mark J Musante <Mark.Musante@Sun.COM>
parents: 11314
diff changeset
  1530
	    get_nvlist(zc->zc_nvlist_src, zc->zc_nvlist_src_size,
42768837421d PSARC/2009/511 zpool split
Mark J Musante <Mark.Musante@Sun.COM>
parents: 11314
diff changeset
  1531
	    zc->zc_iflags, &props))) {
42768837421d PSARC/2009/511 zpool split
Mark J Musante <Mark.Musante@Sun.COM>
parents: 11314
diff changeset
  1532
		spa_close(spa, FTAG);
42768837421d PSARC/2009/511 zpool split
Mark J Musante <Mark.Musante@Sun.COM>
parents: 11314
diff changeset
  1533
		nvlist_free(config);
42768837421d PSARC/2009/511 zpool split
Mark J Musante <Mark.Musante@Sun.COM>
parents: 11314
diff changeset
  1534
		return (error);
42768837421d PSARC/2009/511 zpool split
Mark J Musante <Mark.Musante@Sun.COM>
parents: 11314
diff changeset
  1535
	}
42768837421d PSARC/2009/511 zpool split
Mark J Musante <Mark.Musante@Sun.COM>
parents: 11314
diff changeset
  1536
42768837421d PSARC/2009/511 zpool split
Mark J Musante <Mark.Musante@Sun.COM>
parents: 11314
diff changeset
  1537
	error = spa_vdev_split_mirror(spa, zc->zc_string, config, props, exp);
42768837421d PSARC/2009/511 zpool split
Mark J Musante <Mark.Musante@Sun.COM>
parents: 11314
diff changeset
  1538
42768837421d PSARC/2009/511 zpool split
Mark J Musante <Mark.Musante@Sun.COM>
parents: 11314
diff changeset
  1539
	spa_close(spa, FTAG);
42768837421d PSARC/2009/511 zpool split
Mark J Musante <Mark.Musante@Sun.COM>
parents: 11314
diff changeset
  1540
42768837421d PSARC/2009/511 zpool split
Mark J Musante <Mark.Musante@Sun.COM>
parents: 11314
diff changeset
  1541
	nvlist_free(config);
42768837421d PSARC/2009/511 zpool split
Mark J Musante <Mark.Musante@Sun.COM>
parents: 11314
diff changeset
  1542
	nvlist_free(props);
42768837421d PSARC/2009/511 zpool split
Mark J Musante <Mark.Musante@Sun.COM>
parents: 11314
diff changeset
  1543
42768837421d PSARC/2009/511 zpool split
Mark J Musante <Mark.Musante@Sun.COM>
parents: 11314
diff changeset
  1544
	return (error);
42768837421d PSARC/2009/511 zpool split
Mark J Musante <Mark.Musante@Sun.COM>
parents: 11314
diff changeset
  1545
}
42768837421d PSARC/2009/511 zpool split
Mark J Musante <Mark.Musante@Sun.COM>
parents: 11314
diff changeset
  1546
42768837421d PSARC/2009/511 zpool split
Mark J Musante <Mark.Musante@Sun.COM>
parents: 11314
diff changeset
  1547
static int
1354
81359ee1ee63 6362672 import gets confused about overlapping slices
eschrock
parents: 1133
diff changeset
  1548
zfs_ioc_vdev_setpath(zfs_cmd_t *zc)
81359ee1ee63 6362672 import gets confused about overlapping slices
eschrock
parents: 1133
diff changeset
  1549
{
81359ee1ee63 6362672 import gets confused about overlapping slices
eschrock
parents: 1133
diff changeset
  1550
	spa_t *spa;
2676
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  1551
	char *path = zc->zc_value;
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
  1552
	uint64_t guid = zc->zc_guid;
1354
81359ee1ee63 6362672 import gets confused about overlapping slices
eschrock
parents: 1133
diff changeset
  1553
	int error;
81359ee1ee63 6362672 import gets confused about overlapping slices
eschrock
parents: 1133
diff changeset
  1554
81359ee1ee63 6362672 import gets confused about overlapping slices
eschrock
parents: 1133
diff changeset
  1555
	error = spa_open(zc->zc_name, &spa, FTAG);
81359ee1ee63 6362672 import gets confused about overlapping slices
eschrock
parents: 1133
diff changeset
  1556
	if (error != 0)
81359ee1ee63 6362672 import gets confused about overlapping slices
eschrock
parents: 1133
diff changeset
  1557
		return (error);
81359ee1ee63 6362672 import gets confused about overlapping slices
eschrock
parents: 1133
diff changeset
  1558
81359ee1ee63 6362672 import gets confused about overlapping slices
eschrock
parents: 1133
diff changeset
  1559
	error = spa_vdev_setpath(spa, guid, path);
81359ee1ee63 6362672 import gets confused about overlapping slices
eschrock
parents: 1133
diff changeset
  1560
	spa_close(spa, FTAG);
81359ee1ee63 6362672 import gets confused about overlapping slices
eschrock
parents: 1133
diff changeset
  1561
	return (error);
81359ee1ee63 6362672 import gets confused about overlapping slices
eschrock
parents: 1133
diff changeset
  1562
}
81359ee1ee63 6362672 import gets confused about overlapping slices
eschrock
parents: 1133
diff changeset
  1563
9425
e7ffacaec3a8 6799895 spa_add_spares() needs to be protected by config lock
Eric Schrock <Eric.Schrock@Sun.COM>
parents: 9396
diff changeset
  1564
static int
e7ffacaec3a8 6799895 spa_add_spares() needs to be protected by config lock
Eric Schrock <Eric.Schrock@Sun.COM>
parents: 9396
diff changeset
  1565
zfs_ioc_vdev_setfru(zfs_cmd_t *zc)
e7ffacaec3a8 6799895 spa_add_spares() needs to be protected by config lock
Eric Schrock <Eric.Schrock@Sun.COM>
parents: 9396
diff changeset
  1566
{
e7ffacaec3a8 6799895 spa_add_spares() needs to be protected by config lock
Eric Schrock <Eric.Schrock@Sun.COM>
parents: 9396
diff changeset
  1567
	spa_t *spa;
e7ffacaec3a8 6799895 spa_add_spares() needs to be protected by config lock
Eric Schrock <Eric.Schrock@Sun.COM>
parents: 9396
diff changeset
  1568
	char *fru = zc->zc_value;
e7ffacaec3a8 6799895 spa_add_spares() needs to be protected by config lock
Eric Schrock <Eric.Schrock@Sun.COM>
parents: 9396
diff changeset
  1569
	uint64_t guid = zc->zc_guid;
e7ffacaec3a8 6799895 spa_add_spares() needs to be protected by config lock
Eric Schrock <Eric.Schrock@Sun.COM>
parents: 9396
diff changeset
  1570
	int error;
e7ffacaec3a8 6799895 spa_add_spares() needs to be protected by config lock
Eric Schrock <Eric.Schrock@Sun.COM>
parents: 9396
diff changeset
  1571
e7ffacaec3a8 6799895 spa_add_spares() needs to be protected by config lock
Eric Schrock <Eric.Schrock@Sun.COM>
parents: 9396
diff changeset
  1572
	error = spa_open(zc->zc_name, &spa, FTAG);
e7ffacaec3a8 6799895 spa_add_spares() needs to be protected by config lock
Eric Schrock <Eric.Schrock@Sun.COM>
parents: 9396
diff changeset
  1573
	if (error != 0)
e7ffacaec3a8 6799895 spa_add_spares() needs to be protected by config lock
Eric Schrock <Eric.Schrock@Sun.COM>
parents: 9396
diff changeset
  1574
		return (error);
e7ffacaec3a8 6799895 spa_add_spares() needs to be protected by config lock
Eric Schrock <Eric.Schrock@Sun.COM>
parents: 9396
diff changeset
  1575
e7ffacaec3a8 6799895 spa_add_spares() needs to be protected by config lock
Eric Schrock <Eric.Schrock@Sun.COM>
parents: 9396
diff changeset
  1576
	error = spa_vdev_setfru(spa, guid, fru);
e7ffacaec3a8 6799895 spa_add_spares() needs to be protected by config lock
Eric Schrock <Eric.Schrock@Sun.COM>
parents: 9396
diff changeset
  1577
	spa_close(spa, FTAG);
e7ffacaec3a8 6799895 spa_add_spares() needs to be protected by config lock
Eric Schrock <Eric.Schrock@Sun.COM>
parents: 9396
diff changeset
  1578
	return (error);
e7ffacaec3a8 6799895 spa_add_spares() needs to be protected by config lock
Eric Schrock <Eric.Schrock@Sun.COM>
parents: 9396
diff changeset
  1579
}
e7ffacaec3a8 6799895 spa_add_spares() needs to be protected by config lock
Eric Schrock <Eric.Schrock@Sun.COM>
parents: 9396
diff changeset
  1580
5367
c40abbe796be PSARC/2007/574 zfs send -R
ahrens
parents: 5331
diff changeset
  1581
/*
c40abbe796be PSARC/2007/574 zfs send -R
ahrens
parents: 5331
diff changeset
  1582
 * inputs:
c40abbe796be PSARC/2007/574 zfs send -R
ahrens
parents: 5331
diff changeset
  1583
 * zc_name		name of filesystem
c40abbe796be PSARC/2007/574 zfs send -R
ahrens
parents: 5331
diff changeset
  1584
 * zc_nvlist_dst_size	size of buffer for property nvlist
c40abbe796be PSARC/2007/574 zfs send -R
ahrens
parents: 5331
diff changeset
  1585
 *
c40abbe796be PSARC/2007/574 zfs send -R
ahrens
parents: 5331
diff changeset
  1586
 * outputs:
c40abbe796be PSARC/2007/574 zfs send -R
ahrens
parents: 5331
diff changeset
  1587
 * zc_objset_stats	stats
c40abbe796be PSARC/2007/574 zfs send -R
ahrens
parents: 5331
diff changeset
  1588
 * zc_nvlist_dst	property nvlist
c40abbe796be PSARC/2007/574 zfs send -R
ahrens
parents: 5331
diff changeset
  1589
 * zc_nvlist_dst_size	size of property nvlist
c40abbe796be PSARC/2007/574 zfs send -R
ahrens
parents: 5331
diff changeset
  1590
 */
1354
81359ee1ee63 6362672 import gets confused about overlapping slices
eschrock
parents: 1133
diff changeset
  1591
static int
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1592
zfs_ioc_objset_stats(zfs_cmd_t *zc)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1593
{
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1594
	objset_t *os = NULL;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1595
	int error;
1356
e021b5e4aa0e 6377671 zfs mount -a shouldn't bother checking snapshots
eschrock
parents: 1354
diff changeset
  1596
	nvlist_t *nv;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1597
10298
a0d52501437c 6860996 %temporary clones are not automatically destroyed on error
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 10272
diff changeset
  1598
	if (error = dmu_objset_hold(zc->zc_name, FTAG, &os))
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1599
		return (error);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1600
2885
c0259887ebbc 6460059 zfs destroy <snapshot> leaves behind kruft
ahrens
parents: 2856
diff changeset
  1601
	dmu_objset_fast_stat(os, &zc->zc_objset_stats);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1602
2856
6f4d5ee1906a 6463348 ZFS code could be more portable
nd150628
parents: 2717
diff changeset
  1603
	if (zc->zc_nvlist_dst != 0 &&
11022
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 11007
diff changeset
  1604
	    (error = dsl_prop_get_all(os, &nv)) == 0) {
2885
c0259887ebbc 6460059 zfs destroy <snapshot> leaves behind kruft
ahrens
parents: 2856
diff changeset
  1605
		dmu_objset_stats(os, nv);
3087
62df4acfd5cb 6468748 assertion failure in dnode_sync
ahrens
parents: 2926
diff changeset
  1606
		/*
5147
5e950ccc9585 6596190 "zfs list" is slow due to version property
rm160521
parents: 5118
diff changeset
  1607
		 * NB: zvol_get_stats() will read the objset contents,
3087
62df4acfd5cb 6468748 assertion failure in dnode_sync
ahrens
parents: 2926
diff changeset
  1608
		 * which we aren't supposed to do with a
6689
47572a2f5e73 6610506 Eliminate or improve retry logic from callers of dmu_objset_open()
maybee
parents: 6643
diff changeset
  1609
		 * DS_MODE_USER hold, because it could be
3087
62df4acfd5cb 6468748 assertion failure in dnode_sync
ahrens
parents: 2926
diff changeset
  1610
		 * inconsistent.  So this is a bit of a workaround...
10298
a0d52501437c 6860996 %temporary clones are not automatically destroyed on error
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 10272
diff changeset
  1611
		 * XXX reading with out owning
3087
62df4acfd5cb 6468748 assertion failure in dnode_sync
ahrens
parents: 2926
diff changeset
  1612
		 */
4577
ed36b0e652bc PSARC/2007/328 zfs upgrade
ahrens
parents: 4543
diff changeset
  1613
		if (!zc->zc_objset_stats.dds_inconsistent) {
ed36b0e652bc PSARC/2007/328 zfs upgrade
ahrens
parents: 4543
diff changeset
  1614
			if (dmu_objset_type(os) == DMU_OST_ZVOL)
ed36b0e652bc PSARC/2007/328 zfs upgrade
ahrens
parents: 4543
diff changeset
  1615
				VERIFY(zvol_get_stats(os, nv) == 0);
ed36b0e652bc PSARC/2007/328 zfs upgrade
ahrens
parents: 4543
diff changeset
  1616
		}
2676
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  1617
		error = put_nvlist(zc, nv);
1356
e021b5e4aa0e 6377671 zfs mount -a shouldn't bother checking snapshots
eschrock
parents: 1354
diff changeset
  1618
		nvlist_free(nv);
e021b5e4aa0e 6377671 zfs mount -a shouldn't bother checking snapshots
eschrock
parents: 1354
diff changeset
  1619
	}
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1620
10298
a0d52501437c 6860996 %temporary clones are not automatically destroyed on error
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 10272
diff changeset
  1621
	dmu_objset_rele(os, FTAG);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1622
	return (error);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1623
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1624
11022
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 11007
diff changeset
  1625
/*
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 11007
diff changeset
  1626
 * inputs:
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 11007
diff changeset
  1627
 * zc_name		name of filesystem
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 11007
diff changeset
  1628
 * zc_nvlist_dst_size	size of buffer for property nvlist
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 11007
diff changeset
  1629
 *
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 11007
diff changeset
  1630
 * outputs:
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 11007
diff changeset
  1631
 * zc_nvlist_dst	received property nvlist
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 11007
diff changeset
  1632
 * zc_nvlist_dst_size	size of received property nvlist
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 11007
diff changeset
  1633
 *
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 11007
diff changeset
  1634
 * Gets received properties (distinct from local properties on or after
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 11007
diff changeset
  1635
 * SPA_VERSION_RECVD_PROPS) for callers who want to differentiate received from
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 11007
diff changeset
  1636
 * local property values.
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 11007
diff changeset
  1637
 */
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 11007
diff changeset
  1638
static int
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 11007
diff changeset
  1639
zfs_ioc_objset_recvd_props(zfs_cmd_t *zc)
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 11007
diff changeset
  1640
{
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 11007
diff changeset
  1641
	objset_t *os = NULL;
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 11007
diff changeset
  1642
	int error;
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 11007
diff changeset
  1643
	nvlist_t *nv;
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 11007
diff changeset
  1644
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 11007
diff changeset
  1645
	if (error = dmu_objset_hold(zc->zc_name, FTAG, &os))
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 11007
diff changeset
  1646
		return (error);
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 11007
diff changeset
  1647
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 11007
diff changeset
  1648
	/*
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 11007
diff changeset
  1649
	 * Without this check, we would return local property values if the
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 11007
diff changeset
  1650
	 * caller has not already received properties on or after
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 11007
diff changeset
  1651
	 * SPA_VERSION_RECVD_PROPS.
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 11007
diff changeset
  1652
	 */
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 11007
diff changeset
  1653
	if (!dsl_prop_get_hasrecvd(os)) {
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 11007
diff changeset
  1654
		dmu_objset_rele(os, FTAG);
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 11007
diff changeset
  1655
		return (ENOTSUP);
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 11007
diff changeset
  1656
	}
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 11007
diff changeset
  1657
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 11007
diff changeset
  1658
	if (zc->zc_nvlist_dst != 0 &&
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 11007
diff changeset
  1659
	    (error = dsl_prop_get_received(os, &nv)) == 0) {
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 11007
diff changeset
  1660
		error = put_nvlist(zc, nv);
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 11007
diff changeset
  1661
		nvlist_free(nv);
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 11007
diff changeset
  1662
	}
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 11007
diff changeset
  1663
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 11007
diff changeset
  1664
	dmu_objset_rele(os, FTAG);
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 11007
diff changeset
  1665
	return (error);
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 11007
diff changeset
  1666
}
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 11007
diff changeset
  1667
5498
334b476844ca 6622831 normalization properties are not preserved by "zfs send"
timh
parents: 5450
diff changeset
  1668
static int
334b476844ca 6622831 normalization properties are not preserved by "zfs send"
timh
parents: 5450
diff changeset
  1669
nvl_add_zplprop(objset_t *os, nvlist_t *props, zfs_prop_t prop)
334b476844ca 6622831 normalization properties are not preserved by "zfs send"
timh
parents: 5450
diff changeset
  1670
{
334b476844ca 6622831 normalization properties are not preserved by "zfs send"
timh
parents: 5450
diff changeset
  1671
	uint64_t value;
334b476844ca 6622831 normalization properties are not preserved by "zfs send"
timh
parents: 5450
diff changeset
  1672
	int error;
334b476844ca 6622831 normalization properties are not preserved by "zfs send"
timh
parents: 5450
diff changeset
  1673
334b476844ca 6622831 normalization properties are not preserved by "zfs send"
timh
parents: 5450
diff changeset
  1674
	/*
334b476844ca 6622831 normalization properties are not preserved by "zfs send"
timh
parents: 5450
diff changeset
  1675
	 * zfs_get_zplprop() will either find a value or give us
334b476844ca 6622831 normalization properties are not preserved by "zfs send"
timh
parents: 5450
diff changeset
  1676
	 * the default value (if there is one).
334b476844ca 6622831 normalization properties are not preserved by "zfs send"
timh
parents: 5450
diff changeset
  1677
	 */
334b476844ca 6622831 normalization properties are not preserved by "zfs send"
timh
parents: 5450
diff changeset
  1678
	if ((error = zfs_get_zplprop(os, prop, &value)) != 0)
334b476844ca 6622831 normalization properties are not preserved by "zfs send"
timh
parents: 5450
diff changeset
  1679
		return (error);
334b476844ca 6622831 normalization properties are not preserved by "zfs send"
timh
parents: 5450
diff changeset
  1680
	VERIFY(nvlist_add_uint64(props, zfs_prop_to_name(prop), value) == 0);
334b476844ca 6622831 normalization properties are not preserved by "zfs send"
timh
parents: 5450
diff changeset
  1681
	return (0);
334b476844ca 6622831 normalization properties are not preserved by "zfs send"
timh
parents: 5450
diff changeset
  1682
}
334b476844ca 6622831 normalization properties are not preserved by "zfs send"
timh
parents: 5450
diff changeset
  1683
334b476844ca 6622831 normalization properties are not preserved by "zfs send"
timh
parents: 5450
diff changeset
  1684
/*
334b476844ca 6622831 normalization properties are not preserved by "zfs send"
timh
parents: 5450
diff changeset
  1685
 * inputs:
334b476844ca 6622831 normalization properties are not preserved by "zfs send"
timh
parents: 5450
diff changeset
  1686
 * zc_name		name of filesystem
334b476844ca 6622831 normalization properties are not preserved by "zfs send"
timh
parents: 5450
diff changeset
  1687
 * zc_nvlist_dst_size	size of buffer for zpl property nvlist
334b476844ca 6622831 normalization properties are not preserved by "zfs send"
timh
parents: 5450
diff changeset
  1688
 *
334b476844ca 6622831 normalization properties are not preserved by "zfs send"
timh
parents: 5450
diff changeset
  1689
 * outputs:
334b476844ca 6622831 normalization properties are not preserved by "zfs send"
timh
parents: 5450
diff changeset
  1690
 * zc_nvlist_dst	zpl property nvlist
334b476844ca 6622831 normalization properties are not preserved by "zfs send"
timh
parents: 5450
diff changeset
  1691
 * zc_nvlist_dst_size	size of zpl property nvlist
334b476844ca 6622831 normalization properties are not preserved by "zfs send"
timh
parents: 5450
diff changeset
  1692
 */
334b476844ca 6622831 normalization properties are not preserved by "zfs send"
timh
parents: 5450
diff changeset
  1693
static int
334b476844ca 6622831 normalization properties are not preserved by "zfs send"
timh
parents: 5450
diff changeset
  1694
zfs_ioc_objset_zplprops(zfs_cmd_t *zc)
334b476844ca 6622831 normalization properties are not preserved by "zfs send"
timh
parents: 5450
diff changeset
  1695
{
334b476844ca 6622831 normalization properties are not preserved by "zfs send"
timh
parents: 5450
diff changeset
  1696
	objset_t *os;
334b476844ca 6622831 normalization properties are not preserved by "zfs send"
timh
parents: 5450
diff changeset
  1697
	int err;
334b476844ca 6622831 normalization properties are not preserved by "zfs send"
timh
parents: 5450
diff changeset
  1698
10298
a0d52501437c 6860996 %temporary clones are not automatically destroyed on error
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 10272
diff changeset
  1699
	/* XXX reading without owning */
a0d52501437c 6860996 %temporary clones are not automatically destroyed on error
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 10272
diff changeset
  1700
	if (err = dmu_objset_hold(zc->zc_name, FTAG, &os))
5498
334b476844ca 6622831 normalization properties are not preserved by "zfs send"
timh
parents: 5450
diff changeset
  1701
		return (err);
334b476844ca 6622831 normalization properties are not preserved by "zfs send"
timh
parents: 5450
diff changeset
  1702
334b476844ca 6622831 normalization properties are not preserved by "zfs send"
timh
parents: 5450
diff changeset
  1703
	dmu_objset_fast_stat(os, &zc->zc_objset_stats);
334b476844ca 6622831 normalization properties are not preserved by "zfs send"
timh
parents: 5450
diff changeset
  1704
334b476844ca 6622831 normalization properties are not preserved by "zfs send"
timh
parents: 5450
diff changeset
  1705
	/*
334b476844ca 6622831 normalization properties are not preserved by "zfs send"
timh
parents: 5450
diff changeset
  1706
	 * NB: nvl_add_zplprop() will read the objset contents,
6689
47572a2f5e73 6610506 Eliminate or improve retry logic from callers of dmu_objset_open()
maybee
parents: 6643
diff changeset
  1707
	 * which we aren't supposed to do with a DS_MODE_USER
47572a2f5e73 6610506 Eliminate or improve retry logic from callers of dmu_objset_open()
maybee
parents: 6643
diff changeset
  1708
	 * hold, because it could be inconsistent.
5498
334b476844ca 6622831 normalization properties are not preserved by "zfs send"
timh
parents: 5450
diff changeset
  1709
	 */
334b476844ca 6622831 normalization properties are not preserved by "zfs send"
timh
parents: 5450
diff changeset
  1710
	if (zc->zc_nvlist_dst != NULL &&
334b476844ca 6622831 normalization properties are not preserved by "zfs send"
timh
parents: 5450
diff changeset
  1711
	    !zc->zc_objset_stats.dds_inconsistent &&
334b476844ca 6622831 normalization properties are not preserved by "zfs send"
timh
parents: 5450
diff changeset
  1712
	    dmu_objset_type(os) == DMU_OST_ZFS) {
334b476844ca 6622831 normalization properties are not preserved by "zfs send"
timh
parents: 5450
diff changeset
  1713
		nvlist_t *nv;
334b476844ca 6622831 normalization properties are not preserved by "zfs send"
timh
parents: 5450
diff changeset
  1714
334b476844ca 6622831 normalization properties are not preserved by "zfs send"
timh
parents: 5450
diff changeset
  1715
		VERIFY(nvlist_alloc(&nv, NV_UNIQUE_NAME, KM_SLEEP) == 0);
334b476844ca 6622831 normalization properties are not preserved by "zfs send"
timh
parents: 5450
diff changeset
  1716
		if ((err = nvl_add_zplprop(os, nv, ZFS_PROP_VERSION)) == 0 &&
334b476844ca 6622831 normalization properties are not preserved by "zfs send"
timh
parents: 5450
diff changeset
  1717
		    (err = nvl_add_zplprop(os, nv, ZFS_PROP_NORMALIZE)) == 0 &&
334b476844ca 6622831 normalization properties are not preserved by "zfs send"
timh
parents: 5450
diff changeset
  1718
		    (err = nvl_add_zplprop(os, nv, ZFS_PROP_UTF8ONLY)) == 0 &&
334b476844ca 6622831 normalization properties are not preserved by "zfs send"
timh
parents: 5450
diff changeset
  1719
		    (err = nvl_add_zplprop(os, nv, ZFS_PROP_CASE)) == 0)
334b476844ca 6622831 normalization properties are not preserved by "zfs send"
timh
parents: 5450
diff changeset
  1720
			err = put_nvlist(zc, nv);
334b476844ca 6622831 normalization properties are not preserved by "zfs send"
timh
parents: 5450
diff changeset
  1721
		nvlist_free(nv);
334b476844ca 6622831 normalization properties are not preserved by "zfs send"
timh
parents: 5450
diff changeset
  1722
	} else {
334b476844ca 6622831 normalization properties are not preserved by "zfs send"
timh
parents: 5450
diff changeset
  1723
		err = ENOENT;
334b476844ca 6622831 normalization properties are not preserved by "zfs send"
timh
parents: 5450
diff changeset
  1724
	}
10298
a0d52501437c 6860996 %temporary clones are not automatically destroyed on error
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 10272
diff changeset
  1725
	dmu_objset_rele(os, FTAG);
5498
334b476844ca 6622831 normalization properties are not preserved by "zfs send"
timh
parents: 5450
diff changeset
  1726
	return (err);
334b476844ca 6622831 normalization properties are not preserved by "zfs send"
timh
parents: 5450
diff changeset
  1727
}
334b476844ca 6622831 normalization properties are not preserved by "zfs send"
timh
parents: 5450
diff changeset
  1728
9396
f41cf682d0d3 PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 9355
diff changeset
  1729
static boolean_t
f41cf682d0d3 PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 9355
diff changeset
  1730
dataset_name_hidden(const char *name)
f41cf682d0d3 PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 9355
diff changeset
  1731
{
f41cf682d0d3 PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 9355
diff changeset
  1732
	/*
f41cf682d0d3 PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 9355
diff changeset
  1733
	 * Skip over datasets that are not visible in this zone,
f41cf682d0d3 PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 9355
diff changeset
  1734
	 * internal datasets (which have a $ in their name), and
f41cf682d0d3 PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 9355
diff changeset
  1735
	 * temporary datasets (which have a % in their name).
f41cf682d0d3 PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 9355
diff changeset
  1736
	 */
f41cf682d0d3 PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 9355
diff changeset
  1737
	if (strchr(name, '$') != NULL)
f41cf682d0d3 PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 9355
diff changeset
  1738
		return (B_TRUE);
f41cf682d0d3 PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 9355
diff changeset
  1739
	if (strchr(name, '%') != NULL)
f41cf682d0d3 PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 9355
diff changeset
  1740
		return (B_TRUE);
f41cf682d0d3 PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 9355
diff changeset
  1741
	if (!INGLOBALZONE(curproc) && !zone_dataset_visible(name, NULL))
f41cf682d0d3 PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 9355
diff changeset
  1742
		return (B_TRUE);
f41cf682d0d3 PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 9355
diff changeset
  1743
	return (B_FALSE);
f41cf682d0d3 PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 9355
diff changeset
  1744
}
f41cf682d0d3 PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 9355
diff changeset
  1745
5367
c40abbe796be PSARC/2007/574 zfs send -R
ahrens
parents: 5331
diff changeset
  1746
/*
c40abbe796be PSARC/2007/574 zfs send -R
ahrens
parents: 5331
diff changeset
  1747
 * inputs:
c40abbe796be PSARC/2007/574 zfs send -R
ahrens
parents: 5331
diff changeset
  1748
 * zc_name		name of filesystem
c40abbe796be PSARC/2007/574 zfs send -R
ahrens
parents: 5331
diff changeset
  1749
 * zc_cookie		zap cursor
c40abbe796be PSARC/2007/574 zfs send -R
ahrens
parents: 5331
diff changeset
  1750
 * zc_nvlist_dst_size	size of buffer for property nvlist
c40abbe796be PSARC/2007/574 zfs send -R
ahrens
parents: 5331
diff changeset
  1751
 *
c40abbe796be PSARC/2007/574 zfs send -R
ahrens
parents: 5331
diff changeset
  1752
 * outputs:
c40abbe796be PSARC/2007/574 zfs send -R
ahrens
parents: 5331
diff changeset
  1753
 * zc_name		name of next filesystem
9396
f41cf682d0d3 PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 9355
diff changeset
  1754
 * zc_cookie		zap cursor
5367
c40abbe796be PSARC/2007/574 zfs send -R
ahrens
parents: 5331
diff changeset
  1755
 * zc_objset_stats	stats
c40abbe796be PSARC/2007/574 zfs send -R
ahrens
parents: 5331
diff changeset
  1756
 * zc_nvlist_dst	property nvlist
c40abbe796be PSARC/2007/574 zfs send -R
ahrens
parents: 5331
diff changeset
  1757
 * zc_nvlist_dst_size	size of property nvlist
c40abbe796be PSARC/2007/574 zfs send -R
ahrens
parents: 5331
diff changeset
  1758
 */
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1759
static int
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1760
zfs_ioc_dataset_list_next(zfs_cmd_t *zc)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1761
{
885
d925b21dba78 6347493 tar of 25K empty directory entries in ZFS takes 30+ seconds ...
ahrens
parents: 849
diff changeset
  1762
	objset_t *os;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1763
	int error;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1764
	char *p;
11546
42ea6be8961b 6915111 zfs_iter_snapshots() can miss snapshots
Chris Kirby <Chris.Kirby@sun.com>
parents: 11515
diff changeset
  1765
	size_t orig_len = strlen(zc->zc_name);
42ea6be8961b 6915111 zfs_iter_snapshots() can miss snapshots
Chris Kirby <Chris.Kirby@sun.com>
parents: 11515
diff changeset
  1766
42ea6be8961b 6915111 zfs_iter_snapshots() can miss snapshots
Chris Kirby <Chris.Kirby@sun.com>
parents: 11515
diff changeset
  1767
top:
10298
a0d52501437c 6860996 %temporary clones are not automatically destroyed on error
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 10272
diff changeset
  1768
	if (error = dmu_objset_hold(zc->zc_name, FTAG, &os)) {
885
d925b21dba78 6347493 tar of 25K empty directory entries in ZFS takes 30+ seconds ...
ahrens
parents: 849
diff changeset
  1769
		if (error == ENOENT)
d925b21dba78 6347493 tar of 25K empty directory entries in ZFS takes 30+ seconds ...
ahrens
parents: 849
diff changeset
  1770
			error = ESRCH;
d925b21dba78 6347493 tar of 25K empty directory entries in ZFS takes 30+ seconds ...
ahrens
parents: 849
diff changeset
  1771
		return (error);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1772
	}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1773
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1774
	p = strrchr(zc->zc_name, '/');
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1775
	if (p == NULL || p[1] != '\0')
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1776
		(void) strlcat(zc->zc_name, "/", sizeof (zc->zc_name));
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1777
	p = zc->zc_name + strlen(zc->zc_name);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1778
8697
e62d2612c14d 6633095 creating a filesystem with many properties set is slow
Rich Morris <Richard.Morris@Sun.COM>
parents: 8536
diff changeset
  1779
	/*
e62d2612c14d 6633095 creating a filesystem with many properties set is slow
Rich Morris <Richard.Morris@Sun.COM>
parents: 8536
diff changeset
  1780
	 * Pre-fetch the datasets.  dmu_objset_prefetch() always returns 0
e62d2612c14d 6633095 creating a filesystem with many properties set is slow
Rich Morris <Richard.Morris@Sun.COM>
parents: 8536
diff changeset
  1781
	 * but is not declared void because its called by dmu_objset_find().
e62d2612c14d 6633095 creating a filesystem with many properties set is slow
Rich Morris <Richard.Morris@Sun.COM>
parents: 8536
diff changeset
  1782
	 */
8415
d5525cd1cbc2 6386929 initial "zfs list" is slow
Rich Morris <Richard.Morris@Sun.COM>
parents: 8241
diff changeset
  1783
	if (zc->zc_cookie == 0) {
d5525cd1cbc2 6386929 initial "zfs list" is slow
Rich Morris <Richard.Morris@Sun.COM>
parents: 8241
diff changeset
  1784
		uint64_t cookie = 0;
d5525cd1cbc2 6386929 initial "zfs list" is slow
Rich Morris <Richard.Morris@Sun.COM>
parents: 8241
diff changeset
  1785
		int len = sizeof (zc->zc_name) - (p - zc->zc_name);
d5525cd1cbc2 6386929 initial "zfs list" is slow
Rich Morris <Richard.Morris@Sun.COM>
parents: 8241
diff changeset
  1786
d5525cd1cbc2 6386929 initial "zfs list" is slow
Rich Morris <Richard.Morris@Sun.COM>
parents: 8241
diff changeset
  1787
		while (dmu_dir_list_next(os, len, p, NULL, &cookie) == 0)
8697
e62d2612c14d 6633095 creating a filesystem with many properties set is slow
Rich Morris <Richard.Morris@Sun.COM>
parents: 8536
diff changeset
  1788
			(void) dmu_objset_prefetch(p, NULL);
8415
d5525cd1cbc2 6386929 initial "zfs list" is slow
Rich Morris <Richard.Morris@Sun.COM>
parents: 8241
diff changeset
  1789
	}
d5525cd1cbc2 6386929 initial "zfs list" is slow
Rich Morris <Richard.Morris@Sun.COM>
parents: 8241
diff changeset
  1790
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1791
	do {
885
d925b21dba78 6347493 tar of 25K empty directory entries in ZFS takes 30+ seconds ...
ahrens
parents: 849
diff changeset
  1792
		error = dmu_dir_list_next(os,
d925b21dba78 6347493 tar of 25K empty directory entries in ZFS takes 30+ seconds ...
ahrens
parents: 849
diff changeset
  1793
		    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
  1794
		    NULL, &zc->zc_cookie);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1795
		if (error == ENOENT)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1796
			error = ESRCH;
10588
dc03f981ea18 6438937 if 'zfs destroy' fails, it can leave a zvol device link missing
Eric Taylor <Eric.Taylor@Sun.COM>
parents: 10474
diff changeset
  1797
	} while (error == 0 && dataset_name_hidden(zc->zc_name) &&
dc03f981ea18 6438937 if 'zfs destroy' fails, it can leave a zvol device link missing
Eric Taylor <Eric.Taylor@Sun.COM>
parents: 10474
diff changeset
  1798
	    !(zc->zc_iflags & FKIOCTL));
10298
a0d52501437c 6860996 %temporary clones are not automatically destroyed on error
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 10272
diff changeset
  1799
	dmu_objset_rele(os, FTAG);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1800
10588
dc03f981ea18 6438937 if 'zfs destroy' fails, it can leave a zvol device link missing
Eric Taylor <Eric.Taylor@Sun.COM>
parents: 10474
diff changeset
  1801
	/*
dc03f981ea18 6438937 if 'zfs destroy' fails, it can leave a zvol device link missing
Eric Taylor <Eric.Taylor@Sun.COM>
parents: 10474
diff changeset
  1802
	 * If it's an internal dataset (ie. with a '$' in its name),
dc03f981ea18 6438937 if 'zfs destroy' fails, it can leave a zvol device link missing
Eric Taylor <Eric.Taylor@Sun.COM>
parents: 10474
diff changeset
  1803
	 * don't try to get stats for it, otherwise we'll return ENOENT.
dc03f981ea18 6438937 if 'zfs destroy' fails, it can leave a zvol device link missing
Eric Taylor <Eric.Taylor@Sun.COM>
parents: 10474
diff changeset
  1804
	 */
11546
42ea6be8961b 6915111 zfs_iter_snapshots() can miss snapshots
Chris Kirby <Chris.Kirby@sun.com>
parents: 11515
diff changeset
  1805
	if (error == 0 && strchr(zc->zc_name, '$') == NULL) {
885
d925b21dba78 6347493 tar of 25K empty directory entries in ZFS takes 30+ seconds ...
ahrens
parents: 849
diff changeset
  1806
		error = zfs_ioc_objset_stats(zc); /* fill in the stats */
11546
42ea6be8961b 6915111 zfs_iter_snapshots() can miss snapshots
Chris Kirby <Chris.Kirby@sun.com>
parents: 11515
diff changeset
  1807
		if (error == ENOENT) {
42ea6be8961b 6915111 zfs_iter_snapshots() can miss snapshots
Chris Kirby <Chris.Kirby@sun.com>
parents: 11515
diff changeset
  1808
			/* We lost a race with destroy, get the next one. */
42ea6be8961b 6915111 zfs_iter_snapshots() can miss snapshots
Chris Kirby <Chris.Kirby@sun.com>
parents: 11515
diff changeset
  1809
			zc->zc_name[orig_len] = '\0';
42ea6be8961b 6915111 zfs_iter_snapshots() can miss snapshots
Chris Kirby <Chris.Kirby@sun.com>
parents: 11515
diff changeset
  1810
			goto top;
42ea6be8961b 6915111 zfs_iter_snapshots() can miss snapshots
Chris Kirby <Chris.Kirby@sun.com>
parents: 11515
diff changeset
  1811
		}
42ea6be8961b 6915111 zfs_iter_snapshots() can miss snapshots
Chris Kirby <Chris.Kirby@sun.com>
parents: 11515
diff changeset
  1812
	}
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1813
	return (error);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1814
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1815
5367
c40abbe796be PSARC/2007/574 zfs send -R
ahrens
parents: 5331
diff changeset
  1816
/*
c40abbe796be PSARC/2007/574 zfs send -R
ahrens
parents: 5331
diff changeset
  1817
 * inputs:
c40abbe796be PSARC/2007/574 zfs send -R
ahrens
parents: 5331
diff changeset
  1818
 * zc_name		name of filesystem
c40abbe796be PSARC/2007/574 zfs send -R
ahrens
parents: 5331
diff changeset
  1819
 * zc_cookie		zap cursor
c40abbe796be PSARC/2007/574 zfs send -R
ahrens
parents: 5331
diff changeset
  1820
 * zc_nvlist_dst_size	size of buffer for property nvlist
c40abbe796be PSARC/2007/574 zfs send -R
ahrens
parents: 5331
diff changeset
  1821
 *
c40abbe796be PSARC/2007/574 zfs send -R
ahrens
parents: 5331
diff changeset
  1822
 * outputs:
c40abbe796be PSARC/2007/574 zfs send -R
ahrens
parents: 5331
diff changeset
  1823
 * zc_name		name of next snapshot
c40abbe796be PSARC/2007/574 zfs send -R
ahrens
parents: 5331
diff changeset
  1824
 * zc_objset_stats	stats
c40abbe796be PSARC/2007/574 zfs send -R
ahrens
parents: 5331
diff changeset
  1825
 * zc_nvlist_dst	property nvlist
c40abbe796be PSARC/2007/574 zfs send -R
ahrens
parents: 5331
diff changeset
  1826
 * zc_nvlist_dst_size	size of property nvlist
c40abbe796be PSARC/2007/574 zfs send -R
ahrens
parents: 5331
diff changeset
  1827
 */
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1828
static int
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1829
zfs_ioc_snapshot_list_next(zfs_cmd_t *zc)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1830
{
885
d925b21dba78 6347493 tar of 25K empty directory entries in ZFS takes 30+ seconds ...
ahrens
parents: 849
diff changeset
  1831
	objset_t *os;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1832
	int error;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1833
11546
42ea6be8961b 6915111 zfs_iter_snapshots() can miss snapshots
Chris Kirby <Chris.Kirby@sun.com>
parents: 11515
diff changeset
  1834
top:
10474
0e96dd3b905a 6859997 zfs caching performance problem
Rich Morris <Richard.Morris@Sun.COM>
parents: 10342
diff changeset
  1835
	if (zc->zc_cookie == 0)
0e96dd3b905a 6859997 zfs caching performance problem
Rich Morris <Richard.Morris@Sun.COM>
parents: 10342
diff changeset
  1836
		(void) dmu_objset_find(zc->zc_name, dmu_objset_prefetch,
0e96dd3b905a 6859997 zfs caching performance problem
Rich Morris <Richard.Morris@Sun.COM>
parents: 10342
diff changeset
  1837
		    NULL, DS_FIND_SNAPSHOTS);
0e96dd3b905a 6859997 zfs caching performance problem
Rich Morris <Richard.Morris@Sun.COM>
parents: 10342
diff changeset
  1838
10298
a0d52501437c 6860996 %temporary clones are not automatically destroyed on error
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 10272
diff changeset
  1839
	error = dmu_objset_hold(zc->zc_name, FTAG, &os);
6689
47572a2f5e73 6610506 Eliminate or improve retry logic from callers of dmu_objset_open()
maybee
parents: 6643
diff changeset
  1840
	if (error)
47572a2f5e73 6610506 Eliminate or improve retry logic from callers of dmu_objset_open()
maybee
parents: 6643
diff changeset
  1841
		return (error == ENOENT ? ESRCH : error);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1842
1003
ce99098d6a9b 6350417 long name will cause rename a dataset panic
lling
parents: 885
diff changeset
  1843
	/*
ce99098d6a9b 6350417 long name will cause rename a dataset panic
lling
parents: 885
diff changeset
  1844
	 * 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
  1845
	 * so exit immediately.
ce99098d6a9b 6350417 long name will cause rename a dataset panic
lling
parents: 885
diff changeset
  1846
	 */
ce99098d6a9b 6350417 long name will cause rename a dataset panic
lling
parents: 885
diff changeset
  1847
	if (strlcat(zc->zc_name, "@", sizeof (zc->zc_name)) >= MAXNAMELEN) {
10298
a0d52501437c 6860996 %temporary clones are not automatically destroyed on error
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 10272
diff changeset
  1848
		dmu_objset_rele(os, FTAG);
1003
ce99098d6a9b 6350417 long name will cause rename a dataset panic
lling
parents: 885
diff changeset
  1849
		return (ESRCH);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1850
	}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1851
885
d925b21dba78 6347493 tar of 25K empty directory entries in ZFS takes 30+ seconds ...
ahrens
parents: 849
diff changeset
  1852
	error = dmu_snapshot_list_next(os,
d925b21dba78 6347493 tar of 25K empty directory entries in ZFS takes 30+ seconds ...
ahrens
parents: 849
diff changeset
  1853
	    sizeof (zc->zc_name) - strlen(zc->zc_name),
5663
029cc4273b57 6627223 gfs needs to support extended dirent flags
ck153898
parents: 5498
diff changeset
  1854
	    zc->zc_name + strlen(zc->zc_name), NULL, &zc->zc_cookie, NULL);
10298
a0d52501437c 6860996 %temporary clones are not automatically destroyed on error
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 10272
diff changeset
  1855
	dmu_objset_rele(os, FTAG);
11546
42ea6be8961b 6915111 zfs_iter_snapshots() can miss snapshots
Chris Kirby <Chris.Kirby@sun.com>
parents: 11515
diff changeset
  1856
	if (error == 0) {
885
d925b21dba78 6347493 tar of 25K empty directory entries in ZFS takes 30+ seconds ...
ahrens
parents: 849
diff changeset
  1857
		error = zfs_ioc_objset_stats(zc); /* fill in the stats */
11546
42ea6be8961b 6915111 zfs_iter_snapshots() can miss snapshots
Chris Kirby <Chris.Kirby@sun.com>
parents: 11515
diff changeset
  1858
		if (error == ENOENT)  {
42ea6be8961b 6915111 zfs_iter_snapshots() can miss snapshots
Chris Kirby <Chris.Kirby@sun.com>
parents: 11515
diff changeset
  1859
			/* We lost a race with destroy, get the next one. */
42ea6be8961b 6915111 zfs_iter_snapshots() can miss snapshots
Chris Kirby <Chris.Kirby@sun.com>
parents: 11515
diff changeset
  1860
			*strchr(zc->zc_name, '@') = '\0';
42ea6be8961b 6915111 zfs_iter_snapshots() can miss snapshots
Chris Kirby <Chris.Kirby@sun.com>
parents: 11515
diff changeset
  1861
			goto top;
42ea6be8961b 6915111 zfs_iter_snapshots() can miss snapshots
Chris Kirby <Chris.Kirby@sun.com>
parents: 11515
diff changeset
  1862
		}
42ea6be8961b 6915111 zfs_iter_snapshots() can miss snapshots
Chris Kirby <Chris.Kirby@sun.com>
parents: 11515
diff changeset
  1863
	} else if (error == ENOENT) {
6689
47572a2f5e73 6610506 Eliminate or improve retry logic from callers of dmu_objset_open()
maybee
parents: 6643
diff changeset
  1864
		error = ESRCH;
11546
42ea6be8961b 6915111 zfs_iter_snapshots() can miss snapshots
Chris Kirby <Chris.Kirby@sun.com>
parents: 11515
diff changeset
  1865
	}
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1866
5367
c40abbe796be PSARC/2007/574 zfs send -R
ahrens
parents: 5331
diff changeset
  1867
	/* if we failed, undo the @ that we tacked on to zc_name */
6689
47572a2f5e73 6610506 Eliminate or improve retry logic from callers of dmu_objset_open()
maybee
parents: 6643
diff changeset
  1868
	if (error)
5367
c40abbe796be PSARC/2007/574 zfs send -R
ahrens
parents: 5331
diff changeset
  1869
		*strchr(zc->zc_name, '@') = '\0';
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1870
	return (error);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1871
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1872
11022
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 11007
diff changeset
  1873
static int
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 11007
diff changeset
  1874
zfs_prop_set_userquota(const char *dsname, nvpair_t *pair)
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 11007
diff changeset
  1875
{
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 11007
diff changeset
  1876
	const char *propname = nvpair_name(pair);
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 11007
diff changeset
  1877
	uint64_t *valary;
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 11007
diff changeset
  1878
	unsigned int vallen;
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 11007
diff changeset
  1879
	const char *domain;
11933
76670fc4178f 6931083 incorrect zfs userquota nvlist propnames can break Solaris 10 Containers and panic systems
Tim Haley <Tim.Haley@Sun.COM>
parents: 11889
diff changeset
  1880
	char *dash;
11022
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 11007
diff changeset
  1881
	zfs_userquota_prop_t type;
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 11007
diff changeset
  1882
	uint64_t rid;
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 11007
diff changeset
  1883
	uint64_t quota;
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 11007
diff changeset
  1884
	zfsvfs_t *zfsvfs;
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 11007
diff changeset
  1885
	int err;
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 11007
diff changeset
  1886
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 11007
diff changeset
  1887
	if (nvpair_type(pair) == DATA_TYPE_NVLIST) {
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 11007
diff changeset
  1888
		nvlist_t *attrs;
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 11007
diff changeset
  1889
		VERIFY(nvpair_value_nvlist(pair, &attrs) == 0);
11933
76670fc4178f 6931083 incorrect zfs userquota nvlist propnames can break Solaris 10 Containers and panic systems
Tim Haley <Tim.Haley@Sun.COM>
parents: 11889
diff changeset
  1890
		if (nvlist_lookup_nvpair(attrs, ZPROP_VALUE,
76670fc4178f 6931083 incorrect zfs userquota nvlist propnames can break Solaris 10 Containers and panic systems
Tim Haley <Tim.Haley@Sun.COM>
parents: 11889
diff changeset
  1891
		    &pair) != 0)
76670fc4178f 6931083 incorrect zfs userquota nvlist propnames can break Solaris 10 Containers and panic systems
Tim Haley <Tim.Haley@Sun.COM>
parents: 11889
diff changeset
  1892
			return (EINVAL);
11022
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 11007
diff changeset
  1893
	}
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 11007
diff changeset
  1894
11933
76670fc4178f 6931083 incorrect zfs userquota nvlist propnames can break Solaris 10 Containers and panic systems
Tim Haley <Tim.Haley@Sun.COM>
parents: 11889
diff changeset
  1895
	/*
76670fc4178f 6931083 incorrect zfs userquota nvlist propnames can break Solaris 10 Containers and panic systems
Tim Haley <Tim.Haley@Sun.COM>
parents: 11889
diff changeset
  1896
	 * A correctly constructed propname is encoded as
76670fc4178f 6931083 incorrect zfs userquota nvlist propnames can break Solaris 10 Containers and panic systems
Tim Haley <Tim.Haley@Sun.COM>
parents: 11889
diff changeset
  1897
	 * userquota@<rid>-<domain>.
76670fc4178f 6931083 incorrect zfs userquota nvlist propnames can break Solaris 10 Containers and panic systems
Tim Haley <Tim.Haley@Sun.COM>
parents: 11889
diff changeset
  1898
	 */
76670fc4178f 6931083 incorrect zfs userquota nvlist propnames can break Solaris 10 Containers and panic systems
Tim Haley <Tim.Haley@Sun.COM>
parents: 11889
diff changeset
  1899
	if ((dash = strchr(propname, '-')) == NULL ||
76670fc4178f 6931083 incorrect zfs userquota nvlist propnames can break Solaris 10 Containers and panic systems
Tim Haley <Tim.Haley@Sun.COM>
parents: 11889
diff changeset
  1900
	    nvpair_value_uint64_array(pair, &valary, &vallen) != 0 ||
76670fc4178f 6931083 incorrect zfs userquota nvlist propnames can break Solaris 10 Containers and panic systems
Tim Haley <Tim.Haley@Sun.COM>
parents: 11889
diff changeset
  1901
	    vallen != 3)
76670fc4178f 6931083 incorrect zfs userquota nvlist propnames can break Solaris 10 Containers and panic systems
Tim Haley <Tim.Haley@Sun.COM>
parents: 11889
diff changeset
  1902
		return (EINVAL);
76670fc4178f 6931083 incorrect zfs userquota nvlist propnames can break Solaris 10 Containers and panic systems
Tim Haley <Tim.Haley@Sun.COM>
parents: 11889
diff changeset
  1903
76670fc4178f 6931083 incorrect zfs userquota nvlist propnames can break Solaris 10 Containers and panic systems
Tim Haley <Tim.Haley@Sun.COM>
parents: 11889
diff changeset
  1904
	domain = dash + 1;
11022
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 11007
diff changeset
  1905
	type = valary[0];
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 11007
diff changeset
  1906
	rid = valary[1];
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 11007
diff changeset
  1907
	quota = valary[2];
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 11007
diff changeset
  1908
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 11007
diff changeset
  1909
	err = zfsvfs_hold(dsname, FTAG, &zfsvfs);
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 11007
diff changeset
  1910
	if (err == 0) {
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 11007
diff changeset
  1911
		err = zfs_set_userquota(zfsvfs, type, domain, rid, quota);
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 11007
diff changeset
  1912
		zfsvfs_rele(zfsvfs, FTAG);
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 11007
diff changeset
  1913
	}
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 11007
diff changeset
  1914
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 11007
diff changeset
  1915
	return (err);
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 11007
diff changeset
  1916
}
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 11007
diff changeset
  1917
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 11007
diff changeset
  1918
/*
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 11007
diff changeset
  1919
 * If the named property is one that has a special function to set its value,
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 11007
diff changeset
  1920
 * return 0 on success and a positive error code on failure; otherwise if it is
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 11007
diff changeset
  1921
 * not one of the special properties handled by this function, return -1.
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 11007
diff changeset
  1922
 *
11933
76670fc4178f 6931083 incorrect zfs userquota nvlist propnames can break Solaris 10 Containers and panic systems
Tim Haley <Tim.Haley@Sun.COM>
parents: 11889
diff changeset
  1923
 * XXX: It would be better for callers of the property interface if we handled
11022
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 11007
diff changeset
  1924
 * these special cases in dsl_prop.c (in the dsl layer).
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 11007
diff changeset
  1925
 */
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 11007
diff changeset
  1926
static int
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 11007
diff changeset
  1927
zfs_prop_set_special(const char *dsname, zprop_source_t source,
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 11007
diff changeset
  1928
    nvpair_t *pair)
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1929
{
11022
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 11007
diff changeset
  1930
	const char *propname = nvpair_name(pair);
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 11007
diff changeset
  1931
	zfs_prop_t prop = zfs_name_to_prop(propname);
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 11007
diff changeset
  1932
	uint64_t intval;
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 11007
diff changeset
  1933
	int err;
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 11007
diff changeset
  1934
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 11007
diff changeset
  1935
	if (prop == ZPROP_INVAL) {
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 11007
diff changeset
  1936
		if (zfs_prop_userquota(propname))
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 11007
diff changeset
  1937
			return (zfs_prop_set_userquota(dsname, pair));
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 11007
diff changeset
  1938
		return (-1);
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 11007
diff changeset
  1939
	}
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 11007
diff changeset
  1940
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 11007
diff changeset
  1941
	if (nvpair_type(pair) == DATA_TYPE_NVLIST) {
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 11007
diff changeset
  1942
		nvlist_t *attrs;
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 11007
diff changeset
  1943
		VERIFY(nvpair_value_nvlist(pair, &attrs) == 0);
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 11007
diff changeset
  1944
		VERIFY(nvlist_lookup_nvpair(attrs, ZPROP_VALUE,
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 11007
diff changeset
  1945
		    &pair) == 0);
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 11007
diff changeset
  1946
	}
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 11007
diff changeset
  1947
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 11007
diff changeset
  1948
	if (zfs_prop_get_type(prop) == PROP_TYPE_STRING)
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 11007
diff changeset
  1949
		return (-1);
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 11007
diff changeset
  1950
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 11007
diff changeset
  1951
	VERIFY(0 == nvpair_value_uint64(pair, &intval));
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 11007
diff changeset
  1952
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 11007
diff changeset
  1953
	switch (prop) {
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 11007
diff changeset
  1954
	case ZFS_PROP_QUOTA:
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 11007
diff changeset
  1955
		err = dsl_dir_set_quota(dsname, source, intval);
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 11007
diff changeset
  1956
		break;
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 11007
diff changeset
  1957
	case ZFS_PROP_REFQUOTA:
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 11007
diff changeset
  1958
		err = dsl_dataset_set_quota(dsname, source, intval);
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 11007
diff changeset
  1959
		break;
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 11007
diff changeset
  1960
	case ZFS_PROP_RESERVATION:
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 11007
diff changeset
  1961
		err = dsl_dir_set_reservation(dsname, source, intval);
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 11007
diff changeset
  1962
		break;
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 11007
diff changeset
  1963
	case ZFS_PROP_REFRESERVATION:
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 11007
diff changeset
  1964
		err = dsl_dataset_set_reservation(dsname, source, intval);
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 11007
diff changeset
  1965
		break;
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 11007
diff changeset
  1966
	case ZFS_PROP_VOLSIZE:
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 11007
diff changeset
  1967
		err = zvol_set_volsize(dsname, ddi_driver_major(zfs_dip),
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 11007
diff changeset
  1968
		    intval);
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 11007
diff changeset
  1969
		break;
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 11007
diff changeset
  1970
	case ZFS_PROP_VERSION:
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 11007
diff changeset
  1971
	{
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 11007
diff changeset
  1972
		zfsvfs_t *zfsvfs;
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 11007
diff changeset
  1973
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 11007
diff changeset
  1974
		if ((err = zfsvfs_hold(dsname, FTAG, &zfsvfs)) != 0)
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 11007
diff changeset
  1975
			break;
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 11007
diff changeset
  1976
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 11007
diff changeset
  1977
		err = zfs_set_version(zfsvfs, intval);
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 11007
diff changeset
  1978
		zfsvfs_rele(zfsvfs, FTAG);
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 11007
diff changeset
  1979
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 11007
diff changeset
  1980
		if (err == 0 && intval >= ZPL_VERSION_USERSPACE) {
11147
74e8c05021f1 6678033 resilver code should prefetch
George Wilson <George.Wilson@Sun.COM>
parents: 11045
diff changeset
  1981
			zfs_cmd_t *zc;
74e8c05021f1 6678033 resilver code should prefetch
George Wilson <George.Wilson@Sun.COM>
parents: 11045
diff changeset
  1982
74e8c05021f1 6678033 resilver code should prefetch
George Wilson <George.Wilson@Sun.COM>
parents: 11045
diff changeset
  1983
			zc = kmem_zalloc(sizeof (zfs_cmd_t), KM_SLEEP);
74e8c05021f1 6678033 resilver code should prefetch
George Wilson <George.Wilson@Sun.COM>
parents: 11045
diff changeset
  1984
			(void) strcpy(zc->zc_name, dsname);
74e8c05021f1 6678033 resilver code should prefetch
George Wilson <George.Wilson@Sun.COM>
parents: 11045
diff changeset
  1985
			(void) zfs_ioc_userspace_upgrade(zc);
74e8c05021f1 6678033 resilver code should prefetch
George Wilson <George.Wilson@Sun.COM>
parents: 11045
diff changeset
  1986
			kmem_free(zc, sizeof (zfs_cmd_t));
11022
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 11007
diff changeset
  1987
		}
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 11007
diff changeset
  1988
		break;
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 11007
diff changeset
  1989
	}
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 11007
diff changeset
  1990
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 11007
diff changeset
  1991
	default:
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 11007
diff changeset
  1992
		err = -1;
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 11007
diff changeset
  1993
	}
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 11007
diff changeset
  1994
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 11007
diff changeset
  1995
	return (err);
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 11007
diff changeset
  1996
}
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 11007
diff changeset
  1997
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 11007
diff changeset
  1998
/*
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 11007
diff changeset
  1999
 * This function is best effort. If it fails to set any of the given properties,
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 11007
diff changeset
  2000
 * it continues to set as many as it can and returns the first error
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 11007
diff changeset
  2001
 * encountered. If the caller provides a non-NULL errlist, it also gives the
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 11007
diff changeset
  2002
 * complete list of names of all the properties it failed to set along with the
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 11007
diff changeset
  2003
 * corresponding error numbers. The caller is responsible for freeing the
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 11007
diff changeset
  2004
 * returned errlist.
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 11007
diff changeset
  2005
 *
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 11007
diff changeset
  2006
 * If every property is set successfully, zero is returned and the list pointed
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 11007
diff changeset
  2007
 * at by errlist is NULL.
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 11007
diff changeset
  2008
 */
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 11007
diff changeset
  2009
int
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 11007
diff changeset
  2010
zfs_set_prop_nvlist(const char *dsname, zprop_source_t source, nvlist_t *nvl,
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 11007
diff changeset
  2011
    nvlist_t **errlist)
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 11007
diff changeset
  2012
{
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 11007
diff changeset
  2013
	nvpair_t *pair;
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 11007
diff changeset
  2014
	nvpair_t *propval;
11045
0db6e4248051 6900437 uninitialized variable in zfs_set_prop_nvlist() panics 'zpool create' during installation of zfsroot
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 11022
diff changeset
  2015
	int rv = 0;
2676
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  2016
	uint64_t intval;
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  2017
	char *strval;
8697
e62d2612c14d 6633095 creating a filesystem with many properties set is slow
Rich Morris <Richard.Morris@Sun.COM>
parents: 8536
diff changeset
  2018
	nvlist_t *genericnvl;
11022
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 11007
diff changeset
  2019
	nvlist_t *errors;
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 11007
diff changeset
  2020
	nvlist_t *retrynvl;
4543
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  2021
8697
e62d2612c14d 6633095 creating a filesystem with many properties set is slow
Rich Morris <Richard.Morris@Sun.COM>
parents: 8536
diff changeset
  2022
	VERIFY(nvlist_alloc(&genericnvl, NV_UNIQUE_NAME, KM_SLEEP) == 0);
11022
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 11007
diff changeset
  2023
	VERIFY(nvlist_alloc(&errors, NV_UNIQUE_NAME, KM_SLEEP) == 0);
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 11007
diff changeset
  2024
	VERIFY(nvlist_alloc(&retrynvl, NV_UNIQUE_NAME, KM_SLEEP) == 0);
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 11007
diff changeset
  2025
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 11007
diff changeset
  2026
retry:
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 11007
diff changeset
  2027
	pair = NULL;
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 11007
diff changeset
  2028
	while ((pair = nvlist_next_nvpair(nvl, pair)) != NULL) {
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 11007
diff changeset
  2029
		const char *propname = nvpair_name(pair);
4670
002728040e28 6580745 "zfs inherit" can be executed by ordinary user
ahrens
parents: 4611
diff changeset
  2030
		zfs_prop_t prop = zfs_name_to_prop(propname);
11181
daeb45eeb9fb 6904147 spurious 'zfs receive' errors when receiving properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 11147
diff changeset
  2031
		int err = 0;
4543
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  2032
11022
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 11007
diff changeset
  2033
		/* decode the property value */
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 11007
diff changeset
  2034
		propval = pair;
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 11007
diff changeset
  2035
		if (nvpair_type(pair) == DATA_TYPE_NVLIST) {
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 11007
diff changeset
  2036
			nvlist_t *attrs;
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 11007
diff changeset
  2037
			VERIFY(nvpair_value_nvlist(pair, &attrs) == 0);
11933
76670fc4178f 6931083 incorrect zfs userquota nvlist propnames can break Solaris 10 Containers and panic systems
Tim Haley <Tim.Haley@Sun.COM>
parents: 11889
diff changeset
  2038
			if (nvlist_lookup_nvpair(attrs, ZPROP_VALUE,
76670fc4178f 6931083 incorrect zfs userquota nvlist propnames can break Solaris 10 Containers and panic systems
Tim Haley <Tim.Haley@Sun.COM>
parents: 11889
diff changeset
  2039
			    &propval) != 0)
76670fc4178f 6931083 incorrect zfs userquota nvlist propnames can break Solaris 10 Containers and panic systems
Tim Haley <Tim.Haley@Sun.COM>
parents: 11889
diff changeset
  2040
				err = EINVAL;
4543
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  2041
		}
2676
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  2042
11022
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 11007
diff changeset
  2043
		/* Validate value type */
11933
76670fc4178f 6931083 incorrect zfs userquota nvlist propnames can break Solaris 10 Containers and panic systems
Tim Haley <Tim.Haley@Sun.COM>
parents: 11889
diff changeset
  2044
		if (err == 0 && prop == ZPROP_INVAL) {
11022
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 11007
diff changeset
  2045
			if (zfs_prop_user(propname)) {
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 11007
diff changeset
  2046
				if (nvpair_type(propval) != DATA_TYPE_STRING)
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 11007
diff changeset
  2047
					err = EINVAL;
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 11007
diff changeset
  2048
			} else if (zfs_prop_userquota(propname)) {
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 11007
diff changeset
  2049
				if (nvpair_type(propval) !=
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 11007
diff changeset
  2050
				    DATA_TYPE_UINT64_ARRAY)
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 11007
diff changeset
  2051
					err = EINVAL;
9396
f41cf682d0d3 PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 9355
diff changeset
  2052
			}
11933
76670fc4178f 6931083 incorrect zfs userquota nvlist propnames can break Solaris 10 Containers and panic systems
Tim Haley <Tim.Haley@Sun.COM>
parents: 11889
diff changeset
  2053
		} else if (err == 0) {
11022
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 11007
diff changeset
  2054
			if (nvpair_type(propval) == DATA_TYPE_STRING) {
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 11007
diff changeset
  2055
				if (zfs_prop_get_type(prop) != PROP_TYPE_STRING)
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 11007
diff changeset
  2056
					err = EINVAL;
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 11007
diff changeset
  2057
			} else if (nvpair_type(propval) == DATA_TYPE_UINT64) {
2885
c0259887ebbc 6460059 zfs destroy <snapshot> leaves behind kruft
ahrens
parents: 2856
diff changeset
  2058
				const char *unused;
c0259887ebbc 6460059 zfs destroy <snapshot> leaves behind kruft
ahrens
parents: 2856
diff changeset
  2059
11022
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 11007
diff changeset
  2060
				VERIFY(nvpair_value_uint64(propval,
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 11007
diff changeset
  2061
				    &intval) == 0);
2676
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  2062
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  2063
				switch (zfs_prop_get_type(prop)) {
4787
602d3f97842c 6393351 unique_* could be improved
ahrens
parents: 4720
diff changeset
  2064
				case PROP_TYPE_NUMBER:
2676
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  2065
					break;
4787
602d3f97842c 6393351 unique_* could be improved
ahrens
parents: 4720
diff changeset
  2066
				case PROP_TYPE_STRING:
11022
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 11007
diff changeset
  2067
					err = EINVAL;
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 11007
diff changeset
  2068
					break;
4787
602d3f97842c 6393351 unique_* could be improved
ahrens
parents: 4720
diff changeset
  2069
				case PROP_TYPE_INDEX:
2717
ed589a32259d 6469385 zfs_set_prop_nvlist range checking is busted
eschrock
parents: 2676
diff changeset
  2070
					if (zfs_prop_index_to_string(prop,
11022
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 11007
diff changeset
  2071
					    intval, &unused) != 0)
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 11007
diff changeset
  2072
						err = EINVAL;
2676
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  2073
					break;
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  2074
				default:
4577
ed36b0e652bc PSARC/2007/328 zfs upgrade
ahrens
parents: 4543
diff changeset
  2075
					cmn_err(CE_PANIC,
ed36b0e652bc PSARC/2007/328 zfs upgrade
ahrens
parents: 4543
diff changeset
  2076
					    "unknown property type");
2676
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  2077
				}
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  2078
			} else {
11022
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 11007
diff changeset
  2079
				err = EINVAL;
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 11007
diff changeset
  2080
			}
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 11007
diff changeset
  2081
		}
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 11007
diff changeset
  2082
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 11007
diff changeset
  2083
		/* Validate permissions */
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 11007
diff changeset
  2084
		if (err == 0)
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 11007
diff changeset
  2085
			err = zfs_check_settable(dsname, pair, CRED());
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 11007
diff changeset
  2086
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 11007
diff changeset
  2087
		if (err == 0) {
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 11007
diff changeset
  2088
			err = zfs_prop_set_special(dsname, source, pair);
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 11007
diff changeset
  2089
			if (err == -1) {
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 11007
diff changeset
  2090
				/*
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 11007
diff changeset
  2091
				 * For better performance we build up a list of
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 11007
diff changeset
  2092
				 * properties to set in a single transaction.
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 11007
diff changeset
  2093
				 */
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 11007
diff changeset
  2094
				err = nvlist_add_nvpair(genericnvl, pair);
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 11007
diff changeset
  2095
			} else if (err != 0 && nvl != retrynvl) {
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 11007
diff changeset
  2096
				/*
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 11007
diff changeset
  2097
				 * This may be a spurious error caused by
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 11007
diff changeset
  2098
				 * receiving quota and reservation out of order.
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 11007
diff changeset
  2099
				 * Try again in a second pass.
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 11007
diff changeset
  2100
				 */
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 11007
diff changeset
  2101
				err = nvlist_add_nvpair(retrynvl, pair);
2676
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  2102
			}
11022
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 11007
diff changeset
  2103
		}
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 11007
diff changeset
  2104
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 11007
diff changeset
  2105
		if (err != 0)
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 11007
diff changeset
  2106
			VERIFY(nvlist_add_int32(errors, propname, err) == 0);
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 11007
diff changeset
  2107
	}
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 11007
diff changeset
  2108
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 11007
diff changeset
  2109
	if (nvl != retrynvl && !nvlist_empty(retrynvl)) {
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 11007
diff changeset
  2110
		nvl = retrynvl;
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 11007
diff changeset
  2111
		goto retry;
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 11007
diff changeset
  2112
	}
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 11007
diff changeset
  2113
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 11007
diff changeset
  2114
	if (!nvlist_empty(genericnvl) &&
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 11007
diff changeset
  2115
	    dsl_props_set(dsname, source, genericnvl) != 0) {
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 11007
diff changeset
  2116
		/*
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 11007
diff changeset
  2117
		 * If this fails, we still want to set as many properties as we
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 11007
diff changeset
  2118
		 * can, so try setting them individually.
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 11007
diff changeset
  2119
		 */
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 11007
diff changeset
  2120
		pair = NULL;
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 11007
diff changeset
  2121
		while ((pair = nvlist_next_nvpair(genericnvl, pair)) != NULL) {
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 11007
diff changeset
  2122
			const char *propname = nvpair_name(pair);
11181
daeb45eeb9fb 6904147 spurious 'zfs receive' errors when receiving properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 11147
diff changeset
  2123
			int err = 0;
11022
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 11007
diff changeset
  2124
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 11007
diff changeset
  2125
			propval = pair;
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 11007
diff changeset
  2126
			if (nvpair_type(pair) == DATA_TYPE_NVLIST) {
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 11007
diff changeset
  2127
				nvlist_t *attrs;
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 11007
diff changeset
  2128
				VERIFY(nvpair_value_nvlist(pair, &attrs) == 0);
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 11007
diff changeset
  2129
				VERIFY(nvlist_lookup_nvpair(attrs, ZPROP_VALUE,
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 11007
diff changeset
  2130
				    &propval) == 0);
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 11007
diff changeset
  2131
			}
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 11007
diff changeset
  2132
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 11007
diff changeset
  2133
			if (nvpair_type(propval) == DATA_TYPE_STRING) {
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 11007
diff changeset
  2134
				VERIFY(nvpair_value_string(propval,
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 11007
diff changeset
  2135
				    &strval) == 0);
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 11007
diff changeset
  2136
				err = dsl_prop_set(dsname, propname, source, 1,
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 11007
diff changeset
  2137
				    strlen(strval) + 1, strval);
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 11007
diff changeset
  2138
			} else {
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 11007
diff changeset
  2139
				VERIFY(nvpair_value_uint64(propval,
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 11007
diff changeset
  2140
				    &intval) == 0);
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 11007
diff changeset
  2141
				err = dsl_prop_set(dsname, propname, source, 8,
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 11007
diff changeset
  2142
				    1, &intval);
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 11007
diff changeset
  2143
			}
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 11007
diff changeset
  2144
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 11007
diff changeset
  2145
			if (err != 0) {
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 11007
diff changeset
  2146
				VERIFY(nvlist_add_int32(errors, propname,
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 11007
diff changeset
  2147
				    err) == 0);
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 11007
diff changeset
  2148
			}
2676
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  2149
		}
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  2150
	}
11022
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 11007
diff changeset
  2151
	nvlist_free(genericnvl);
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 11007
diff changeset
  2152
	nvlist_free(retrynvl);
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 11007
diff changeset
  2153
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 11007
diff changeset
  2154
	if ((pair = nvlist_next_nvpair(errors, NULL)) == NULL) {
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 11007
diff changeset
  2155
		nvlist_free(errors);
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 11007
diff changeset
  2156
		errors = NULL;
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 11007
diff changeset
  2157
	} else {
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 11007
diff changeset
  2158
		VERIFY(nvpair_value_int32(pair, &rv) == 0);
8697
e62d2612c14d 6633095 creating a filesystem with many properties set is slow
Rich Morris <Richard.Morris@Sun.COM>
parents: 8536
diff changeset
  2159
	}
11022
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 11007
diff changeset
  2160
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 11007
diff changeset
  2161
	if (errlist == NULL)
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 11007
diff changeset
  2162
		nvlist_free(errors);
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 11007
diff changeset
  2163
	else
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 11007
diff changeset
  2164
		*errlist = errors;
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 11007
diff changeset
  2165
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 11007
diff changeset
  2166
	return (rv);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2167
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2168
5367
c40abbe796be PSARC/2007/574 zfs send -R
ahrens
parents: 5331
diff changeset
  2169
/*
9355
09928982c591 6818183 zfs snapshot -r is slow due to set_snap_props() doing txg_wait_synced() for each new snapshot
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 9234
diff changeset
  2170
 * Check that all the properties are valid user properties.
09928982c591 6818183 zfs snapshot -r is slow due to set_snap_props() doing txg_wait_synced() for each new snapshot
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 9234
diff changeset
  2171
 */
09928982c591 6818183 zfs snapshot -r is slow due to set_snap_props() doing txg_wait_synced() for each new snapshot
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 9234
diff changeset
  2172
static int
09928982c591 6818183 zfs snapshot -r is slow due to set_snap_props() doing txg_wait_synced() for each new snapshot
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 9234
diff changeset
  2173
zfs_check_userprops(char *fsname, nvlist_t *nvl)
09928982c591 6818183 zfs snapshot -r is slow due to set_snap_props() doing txg_wait_synced() for each new snapshot
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 9234
diff changeset
  2174
{
11022
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 11007
diff changeset
  2175
	nvpair_t *pair = NULL;
9355
09928982c591 6818183 zfs snapshot -r is slow due to set_snap_props() doing txg_wait_synced() for each new snapshot
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 9234
diff changeset
  2176
	int error = 0;
09928982c591 6818183 zfs snapshot -r is slow due to set_snap_props() doing txg_wait_synced() for each new snapshot
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 9234
diff changeset
  2177
11022
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 11007
diff changeset
  2178
	while ((pair = nvlist_next_nvpair(nvl, pair)) != NULL) {
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 11007
diff changeset
  2179
		const char *propname = nvpair_name(pair);
9355
09928982c591 6818183 zfs snapshot -r is slow due to set_snap_props() doing txg_wait_synced() for each new snapshot
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 9234
diff changeset
  2180
		char *valstr;
09928982c591 6818183 zfs snapshot -r is slow due to set_snap_props() doing txg_wait_synced() for each new snapshot
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 9234
diff changeset
  2181
09928982c591 6818183 zfs snapshot -r is slow due to set_snap_props() doing txg_wait_synced() for each new snapshot
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 9234
diff changeset
  2182
		if (!zfs_prop_user(propname) ||
11022
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 11007
diff changeset
  2183
		    nvpair_type(pair) != DATA_TYPE_STRING)
9355
09928982c591 6818183 zfs snapshot -r is slow due to set_snap_props() doing txg_wait_synced() for each new snapshot
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 9234
diff changeset
  2184
			return (EINVAL);
09928982c591 6818183 zfs snapshot -r is slow due to set_snap_props() doing txg_wait_synced() for each new snapshot
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 9234
diff changeset
  2185
09928982c591 6818183 zfs snapshot -r is slow due to set_snap_props() doing txg_wait_synced() for each new snapshot
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 9234
diff changeset
  2186
		if (error = zfs_secpolicy_write_perms(fsname,
09928982c591 6818183 zfs snapshot -r is slow due to set_snap_props() doing txg_wait_synced() for each new snapshot
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 9234
diff changeset
  2187
		    ZFS_DELEG_PERM_USERPROP, CRED()))
09928982c591 6818183 zfs snapshot -r is slow due to set_snap_props() doing txg_wait_synced() for each new snapshot
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 9234
diff changeset
  2188
			return (error);
09928982c591 6818183 zfs snapshot -r is slow due to set_snap_props() doing txg_wait_synced() for each new snapshot
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 9234
diff changeset
  2189
09928982c591 6818183 zfs snapshot -r is slow due to set_snap_props() doing txg_wait_synced() for each new snapshot
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 9234
diff changeset
  2190
		if (strlen(propname) >= ZAP_MAXNAMELEN)
09928982c591 6818183 zfs snapshot -r is slow due to set_snap_props() doing txg_wait_synced() for each new snapshot
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 9234
diff changeset
  2191
			return (ENAMETOOLONG);
09928982c591 6818183 zfs snapshot -r is slow due to set_snap_props() doing txg_wait_synced() for each new snapshot
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 9234
diff changeset
  2192
11022
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 11007
diff changeset
  2193
		VERIFY(nvpair_value_string(pair, &valstr) == 0);
9355
09928982c591 6818183 zfs snapshot -r is slow due to set_snap_props() doing txg_wait_synced() for each new snapshot
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 9234
diff changeset
  2194
		if (strlen(valstr) >= ZAP_MAXVALUELEN)
09928982c591 6818183 zfs snapshot -r is slow due to set_snap_props() doing txg_wait_synced() for each new snapshot
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 9234
diff changeset
  2195
			return (E2BIG);
09928982c591 6818183 zfs snapshot -r is slow due to set_snap_props() doing txg_wait_synced() for each new snapshot
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 9234
diff changeset
  2196
	}
09928982c591 6818183 zfs snapshot -r is slow due to set_snap_props() doing txg_wait_synced() for each new snapshot
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 9234
diff changeset
  2197
	return (0);
09928982c591 6818183 zfs snapshot -r is slow due to set_snap_props() doing txg_wait_synced() for each new snapshot
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 9234
diff changeset
  2198
}
09928982c591 6818183 zfs snapshot -r is slow due to set_snap_props() doing txg_wait_synced() for each new snapshot
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 9234
diff changeset
  2199
11022
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 11007
diff changeset
  2200
static void
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 11007
diff changeset
  2201
props_skip(nvlist_t *props, nvlist_t *skipped, nvlist_t **newprops)
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 11007
diff changeset
  2202
{
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 11007
diff changeset
  2203
	nvpair_t *pair;
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 11007
diff changeset
  2204
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 11007
diff changeset
  2205
	VERIFY(nvlist_alloc(newprops, NV_UNIQUE_NAME, KM_SLEEP) == 0);
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 11007
diff changeset
  2206
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 11007
diff changeset
  2207
	pair = NULL;
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 11007
diff changeset
  2208
	while ((pair = nvlist_next_nvpair(props, pair)) != NULL) {
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 11007
diff changeset
  2209
		if (nvlist_exists(skipped, nvpair_name(pair)))
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 11007
diff changeset
  2210
			continue;
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 11007
diff changeset
  2211
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 11007
diff changeset
  2212
		VERIFY(nvlist_add_nvpair(*newprops, pair) == 0);
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 11007
diff changeset
  2213
	}
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 11007
diff changeset
  2214
}
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 11007
diff changeset
  2215
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 11007
diff changeset
  2216
static int
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 11007
diff changeset
  2217
clear_received_props(objset_t *os, const char *fs, nvlist_t *props,
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 11007
diff changeset
  2218
    nvlist_t *skipped)
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 11007
diff changeset
  2219
{
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 11007
diff changeset
  2220
	int err = 0;
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 11007
diff changeset
  2221
	nvlist_t *cleared_props = NULL;
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 11007
diff changeset
  2222
	props_skip(props, skipped, &cleared_props);
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 11007
diff changeset
  2223
	if (!nvlist_empty(cleared_props)) {
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 11007
diff changeset
  2224
		/*
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 11007
diff changeset
  2225
		 * Acts on local properties until the dataset has received
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 11007
diff changeset
  2226
		 * properties at least once on or after SPA_VERSION_RECVD_PROPS.
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 11007
diff changeset
  2227
		 */
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 11007
diff changeset
  2228
		zprop_source_t flags = (ZPROP_SRC_NONE |
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 11007
diff changeset
  2229
		    (dsl_prop_get_hasrecvd(os) ? ZPROP_SRC_RECEIVED : 0));
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 11007
diff changeset
  2230
		err = zfs_set_prop_nvlist(fs, flags, cleared_props, NULL);
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 11007
diff changeset
  2231
	}
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 11007
diff changeset
  2232
	nvlist_free(cleared_props);
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 11007
diff changeset
  2233
	return (err);
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 11007
diff changeset
  2234
}
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 11007
diff changeset
  2235
9355
09928982c591 6818183 zfs snapshot -r is slow due to set_snap_props() doing txg_wait_synced() for each new snapshot
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 9234
diff changeset
  2236
/*
5367
c40abbe796be PSARC/2007/574 zfs send -R
ahrens
parents: 5331
diff changeset
  2237
 * inputs:
c40abbe796be PSARC/2007/574 zfs send -R
ahrens
parents: 5331
diff changeset
  2238
 * zc_name		name of filesystem
8697
e62d2612c14d 6633095 creating a filesystem with many properties set is slow
Rich Morris <Richard.Morris@Sun.COM>
parents: 8536
diff changeset
  2239
 * zc_value		name of property to set
5367
c40abbe796be PSARC/2007/574 zfs send -R
ahrens
parents: 5331
diff changeset
  2240
 * zc_nvlist_src{_size}	nvlist of properties to apply
11022
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 11007
diff changeset
  2241
 * zc_cookie		received properties flag
5367
c40abbe796be PSARC/2007/574 zfs send -R
ahrens
parents: 5331
diff changeset
  2242
 *
11022
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 11007
diff changeset
  2243
 * outputs:
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 11007
diff changeset
  2244
 * zc_nvlist_dst{_size} error for each unapplied received property
5367
c40abbe796be PSARC/2007/574 zfs send -R
ahrens
parents: 5331
diff changeset
  2245
 */
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2246
static int
2676
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  2247
zfs_ioc_set_prop(zfs_cmd_t *zc)
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2248
{
2676
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  2249
	nvlist_t *nvl;
11022
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 11007
diff changeset
  2250
	boolean_t received = zc->zc_cookie;
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 11007
diff changeset
  2251
	zprop_source_t source = (received ? ZPROP_SRC_RECEIVED :
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 11007
diff changeset
  2252
	    ZPROP_SRC_LOCAL);
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 11007
diff changeset
  2253
	nvlist_t *errors = NULL;
2676
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  2254
	int error;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2255
5094
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
  2256
	if ((error = get_nvlist(zc->zc_nvlist_src, zc->zc_nvlist_src_size,
9643
ffd8e7765f02 6736004 zvols need an additional property for comstar support
Eric Taylor <Eric.Taylor@Sun.COM>
parents: 9425
diff changeset
  2257
	    zc->zc_iflags, &nvl)) != 0)
2676
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  2258
		return (error);
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  2259
11022
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 11007
diff changeset
  2260
	if (received) {
7265
cc18862247da PSARC/2008/483 ZFS clone -o
ahrens
parents: 7214
diff changeset
  2261
		nvlist_t *origprops;
cc18862247da PSARC/2008/483 ZFS clone -o
ahrens
parents: 7214
diff changeset
  2262
		objset_t *os;
cc18862247da PSARC/2008/483 ZFS clone -o
ahrens
parents: 7214
diff changeset
  2263
10298
a0d52501437c 6860996 %temporary clones are not automatically destroyed on error
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 10272
diff changeset
  2264
		if (dmu_objset_hold(zc->zc_name, FTAG, &os) == 0) {
11022
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 11007
diff changeset
  2265
			if (dsl_prop_get_received(os, &origprops) == 0) {
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 11007
diff changeset
  2266
				(void) clear_received_props(os,
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 11007
diff changeset
  2267
				    zc->zc_name, origprops, nvl);
7265
cc18862247da PSARC/2008/483 ZFS clone -o
ahrens
parents: 7214
diff changeset
  2268
				nvlist_free(origprops);
cc18862247da PSARC/2008/483 ZFS clone -o
ahrens
parents: 7214
diff changeset
  2269
			}
11022
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 11007
diff changeset
  2270
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 11007
diff changeset
  2271
			dsl_prop_set_hasrecvd(os);
10298
a0d52501437c 6860996 %temporary clones are not automatically destroyed on error
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 10272
diff changeset
  2272
			dmu_objset_rele(os, FTAG);
7265
cc18862247da PSARC/2008/483 ZFS clone -o
ahrens
parents: 7214
diff changeset
  2273
		}
cc18862247da PSARC/2008/483 ZFS clone -o
ahrens
parents: 7214
diff changeset
  2274
	}
cc18862247da PSARC/2008/483 ZFS clone -o
ahrens
parents: 7214
diff changeset
  2275
11022
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 11007
diff changeset
  2276
	error = zfs_set_prop_nvlist(zc->zc_name, source, nvl, &errors);
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 11007
diff changeset
  2277
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 11007
diff changeset
  2278
	if (zc->zc_nvlist_dst != NULL && errors != NULL) {
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 11007
diff changeset
  2279
		(void) put_nvlist(zc, errors);
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 11007
diff changeset
  2280
	}
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 11007
diff changeset
  2281
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 11007
diff changeset
  2282
	nvlist_free(errors);
2676
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  2283
	nvlist_free(nvl);
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  2284
	return (error);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2285
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2286
5367
c40abbe796be PSARC/2007/574 zfs send -R
ahrens
parents: 5331
diff changeset
  2287
/*
c40abbe796be PSARC/2007/574 zfs send -R
ahrens
parents: 5331
diff changeset
  2288
 * inputs:
c40abbe796be PSARC/2007/574 zfs send -R
ahrens
parents: 5331
diff changeset
  2289
 * zc_name		name of filesystem
c40abbe796be PSARC/2007/574 zfs send -R
ahrens
parents: 5331
diff changeset
  2290
 * zc_value		name of property to inherit
11022
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 11007
diff changeset
  2291
 * zc_cookie		revert to received value if TRUE
5367
c40abbe796be PSARC/2007/574 zfs send -R
ahrens
parents: 5331
diff changeset
  2292
 *
c40abbe796be PSARC/2007/574 zfs send -R
ahrens
parents: 5331
diff changeset
  2293
 * outputs:		none
c40abbe796be PSARC/2007/574 zfs send -R
ahrens
parents: 5331
diff changeset
  2294
 */
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2295
static int
4849
3a61e0a9a953 6536043 arc_byteswap_func_t and dmu_byteswap_func_t are redundant
ahrens
parents: 4808
diff changeset
  2296
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
  2297
{
11022
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 11007
diff changeset
  2298
	const char *propname = zc->zc_value;
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 11007
diff changeset
  2299
	zfs_prop_t prop = zfs_name_to_prop(propname);
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 11007
diff changeset
  2300
	boolean_t received = zc->zc_cookie;
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 11007
diff changeset
  2301
	zprop_source_t source = (received
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 11007
diff changeset
  2302
	    ? ZPROP_SRC_NONE		/* revert to received value, if any */
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 11007
diff changeset
  2303
	    : ZPROP_SRC_INHERITED);	/* explicitly inherit */
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 11007
diff changeset
  2304
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 11007
diff changeset
  2305
	if (received) {
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 11007
diff changeset
  2306
		nvlist_t *dummy;
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 11007
diff changeset
  2307
		nvpair_t *pair;
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 11007
diff changeset
  2308
		zprop_type_t type;
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 11007
diff changeset
  2309
		int err;
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 11007
diff changeset
  2310
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 11007
diff changeset
  2311
		/*
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 11007
diff changeset
  2312
		 * zfs_prop_set_special() expects properties in the form of an
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 11007
diff changeset
  2313
		 * nvpair with type info.
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 11007
diff changeset
  2314
		 */
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 11007
diff changeset
  2315
		if (prop == ZPROP_INVAL) {
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 11007
diff changeset
  2316
			if (!zfs_prop_user(propname))
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 11007
diff changeset
  2317
				return (EINVAL);
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 11007
diff changeset
  2318
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 11007
diff changeset
  2319
			type = PROP_TYPE_STRING;
11515
a122949107d4 6908211 'zfs inherit -S volsize <volume>' core dumps
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 11454
diff changeset
  2320
		} else if (prop == ZFS_PROP_VOLSIZE ||
a122949107d4 6908211 'zfs inherit -S volsize <volume>' core dumps
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 11454
diff changeset
  2321
		    prop == ZFS_PROP_VERSION) {
a122949107d4 6908211 'zfs inherit -S volsize <volume>' core dumps
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 11454
diff changeset
  2322
			return (EINVAL);
11022
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 11007
diff changeset
  2323
		} else {
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 11007
diff changeset
  2324
			type = zfs_prop_get_type(prop);
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 11007
diff changeset
  2325
		}
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 11007
diff changeset
  2326
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 11007
diff changeset
  2327
		VERIFY(nvlist_alloc(&dummy, NV_UNIQUE_NAME, KM_SLEEP) == 0);
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 11007
diff changeset
  2328
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 11007
diff changeset
  2329
		switch (type) {
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 11007
diff changeset
  2330
		case PROP_TYPE_STRING:
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 11007
diff changeset
  2331
			VERIFY(0 == nvlist_add_string(dummy, propname, ""));
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 11007
diff changeset
  2332
			break;
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 11007
diff changeset
  2333
		case PROP_TYPE_NUMBER:
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 11007
diff changeset
  2334
		case PROP_TYPE_INDEX:
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 11007
diff changeset
  2335
			VERIFY(0 == nvlist_add_uint64(dummy, propname, 0));
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 11007
diff changeset
  2336
			break;
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 11007
diff changeset
  2337
		default:
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 11007
diff changeset
  2338
			nvlist_free(dummy);
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 11007
diff changeset
  2339
			return (EINVAL);
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 11007
diff changeset
  2340
		}
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 11007
diff changeset
  2341
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 11007
diff changeset
  2342
		pair = nvlist_next_nvpair(dummy, NULL);
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 11007
diff changeset
  2343
		err = zfs_prop_set_special(zc->zc_name, source, pair);
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 11007
diff changeset
  2344
		nvlist_free(dummy);
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 11007
diff changeset
  2345
		if (err != -1)
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 11007
diff changeset
  2346
			return (err); /* special property already handled */
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 11007
diff changeset
  2347
	} else {
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 11007
diff changeset
  2348
		/*
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 11007
diff changeset
  2349
		 * Only check this in the non-received case. We want to allow
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 11007
diff changeset
  2350
		 * 'inherit -S' to revert non-inheritable properties like quota
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 11007
diff changeset
  2351
		 * and reservation to the received or default values even though
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 11007
diff changeset
  2352
		 * they are not considered inheritable.
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 11007
diff changeset
  2353
		 */
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 11007
diff changeset
  2354
		if (prop != ZPROP_INVAL && !zfs_prop_inheritable(prop))
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 11007
diff changeset
  2355
			return (EINVAL);
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 11007
diff changeset
  2356
	}
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 11007
diff changeset
  2357
4849
3a61e0a9a953 6536043 arc_byteswap_func_t and dmu_byteswap_func_t are redundant
ahrens
parents: 4808
diff changeset
  2358
	/* the property name has been validated by zfs_secpolicy_inherit() */
11022
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 11007
diff changeset
  2359
	return (dsl_prop_set(zc->zc_name, zc->zc_value, source, 0, 0, NULL));
4849
3a61e0a9a953 6536043 arc_byteswap_func_t and dmu_byteswap_func_t are redundant
ahrens
parents: 4808
diff changeset
  2360
}
3a61e0a9a953 6536043 arc_byteswap_func_t and dmu_byteswap_func_t are redundant
ahrens
parents: 4808
diff changeset
  2361
3a61e0a9a953 6536043 arc_byteswap_func_t and dmu_byteswap_func_t are redundant
ahrens
parents: 4808
diff changeset
  2362
static int
4098
0a182c2128e6 6545726 make ZFS_IOC_POOL_*_PROPS in sync with zfs_ioc_pool_props_*
lling
parents: 4007
diff changeset
  2363
zfs_ioc_pool_set_props(zfs_cmd_t *zc)
3912
f6891a60bd72 PSARC 2007/083 ZFS bootable datasets
lling
parents: 3886
diff changeset
  2364
{
5094
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
  2365
	nvlist_t *props;
3912
f6891a60bd72 PSARC 2007/083 ZFS bootable datasets
lling
parents: 3886
diff changeset
  2366
	spa_t *spa;
5094
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
  2367
	int error;
11022
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 11007
diff changeset
  2368
	nvpair_t *pair;
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 11007
diff changeset
  2369
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 11007
diff changeset
  2370
	if (error = get_nvlist(zc->zc_nvlist_src, zc->zc_nvlist_src_size,
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 11007
diff changeset
  2371
	    zc->zc_iflags, &props))
3912
f6891a60bd72 PSARC 2007/083 ZFS bootable datasets
lling
parents: 3886
diff changeset
  2372
		return (error);
f6891a60bd72 PSARC 2007/083 ZFS bootable datasets
lling
parents: 3886
diff changeset
  2373
8525
e0e0e525d0f8 6788830 set large value to reservation cause core dump
Eric Schrock <Eric.Schrock@Sun.COM>
parents: 8415
diff changeset
  2374
	/*
e0e0e525d0f8 6788830 set large value to reservation cause core dump
Eric Schrock <Eric.Schrock@Sun.COM>
parents: 8415
diff changeset
  2375
	 * If the only property is the configfile, then just do a spa_lookup()
e0e0e525d0f8 6788830 set large value to reservation cause core dump
Eric Schrock <Eric.Schrock@Sun.COM>
parents: 8415
diff changeset
  2376
	 * to handle the faulted case.
e0e0e525d0f8 6788830 set large value to reservation cause core dump
Eric Schrock <Eric.Schrock@Sun.COM>
parents: 8415
diff changeset
  2377
	 */
11022
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 11007
diff changeset
  2378
	pair = nvlist_next_nvpair(props, NULL);
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 11007
diff changeset
  2379
	if (pair != NULL && strcmp(nvpair_name(pair),
8525
e0e0e525d0f8 6788830 set large value to reservation cause core dump
Eric Schrock <Eric.Schrock@Sun.COM>
parents: 8415
diff changeset
  2380
	    zpool_prop_to_name(ZPOOL_PROP_CACHEFILE)) == 0 &&
11022
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 11007
diff changeset
  2381
	    nvlist_next_nvpair(props, pair) == NULL) {
8525
e0e0e525d0f8 6788830 set large value to reservation cause core dump
Eric Schrock <Eric.Schrock@Sun.COM>
parents: 8415
diff changeset
  2382
		mutex_enter(&spa_namespace_lock);
e0e0e525d0f8 6788830 set large value to reservation cause core dump
Eric Schrock <Eric.Schrock@Sun.COM>
parents: 8415
diff changeset
  2383
		if ((spa = spa_lookup(zc->zc_name)) != NULL) {
e0e0e525d0f8 6788830 set large value to reservation cause core dump
Eric Schrock <Eric.Schrock@Sun.COM>
parents: 8415
diff changeset
  2384
			spa_configfile_set(spa, props, B_FALSE);
e0e0e525d0f8 6788830 set large value to reservation cause core dump
Eric Schrock <Eric.Schrock@Sun.COM>
parents: 8415
diff changeset
  2385
			spa_config_sync(spa, B_FALSE, B_TRUE);
e0e0e525d0f8 6788830 set large value to reservation cause core dump
Eric Schrock <Eric.Schrock@Sun.COM>
parents: 8415
diff changeset
  2386
		}
e0e0e525d0f8 6788830 set large value to reservation cause core dump
Eric Schrock <Eric.Schrock@Sun.COM>
parents: 8415
diff changeset
  2387
		mutex_exit(&spa_namespace_lock);
10672
cee5a0f557db 6836743 zfs_ioc_pool_set_props() leaks nvlist if configfile is only property
Eric Schrock <Eric.Schrock@Sun.COM>
parents: 10588
diff changeset
  2388
		if (spa != NULL) {
cee5a0f557db 6836743 zfs_ioc_pool_set_props() leaks nvlist if configfile is only property
Eric Schrock <Eric.Schrock@Sun.COM>
parents: 10588
diff changeset
  2389
			nvlist_free(props);
8525
e0e0e525d0f8 6788830 set large value to reservation cause core dump
Eric Schrock <Eric.Schrock@Sun.COM>
parents: 8415
diff changeset
  2390
			return (0);
10672
cee5a0f557db 6836743 zfs_ioc_pool_set_props() leaks nvlist if configfile is only property
Eric Schrock <Eric.Schrock@Sun.COM>
parents: 10588
diff changeset
  2391
		}
8525
e0e0e525d0f8 6788830 set large value to reservation cause core dump
Eric Schrock <Eric.Schrock@Sun.COM>
parents: 8415
diff changeset
  2392
	}
e0e0e525d0f8 6788830 set large value to reservation cause core dump
Eric Schrock <Eric.Schrock@Sun.COM>
parents: 8415
diff changeset
  2393
3912
f6891a60bd72 PSARC 2007/083 ZFS bootable datasets
lling
parents: 3886
diff changeset
  2394
	if ((error = spa_open(zc->zc_name, &spa, FTAG)) != 0) {
5094
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
  2395
		nvlist_free(props);
3912
f6891a60bd72 PSARC 2007/083 ZFS bootable datasets
lling
parents: 3886
diff changeset
  2396
		return (error);
f6891a60bd72 PSARC 2007/083 ZFS bootable datasets
lling
parents: 3886
diff changeset
  2397
	}
f6891a60bd72 PSARC 2007/083 ZFS bootable datasets
lling
parents: 3886
diff changeset
  2398
5094
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
  2399
	error = spa_prop_set(spa, props);
3912
f6891a60bd72 PSARC 2007/083 ZFS bootable datasets
lling
parents: 3886
diff changeset
  2400
5094
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
  2401
	nvlist_free(props);
3912
f6891a60bd72 PSARC 2007/083 ZFS bootable datasets
lling
parents: 3886
diff changeset
  2402
	spa_close(spa, FTAG);
f6891a60bd72 PSARC 2007/083 ZFS bootable datasets
lling
parents: 3886
diff changeset
  2403
f6891a60bd72 PSARC 2007/083 ZFS bootable datasets
lling
parents: 3886
diff changeset
  2404
	return (error);
f6891a60bd72 PSARC 2007/083 ZFS bootable datasets
lling
parents: 3886
diff changeset
  2405
}
f6891a60bd72 PSARC 2007/083 ZFS bootable datasets
lling
parents: 3886
diff changeset
  2406
f6891a60bd72 PSARC 2007/083 ZFS bootable datasets
lling
parents: 3886
diff changeset
  2407
static int
4098
0a182c2128e6 6545726 make ZFS_IOC_POOL_*_PROPS in sync with zfs_ioc_pool_props_*
lling
parents: 4007
diff changeset
  2408
zfs_ioc_pool_get_props(zfs_cmd_t *zc)
3912
f6891a60bd72 PSARC 2007/083 ZFS bootable datasets
lling
parents: 3886
diff changeset
  2409
{
f6891a60bd72 PSARC 2007/083 ZFS bootable datasets
lling
parents: 3886
diff changeset
  2410
	spa_t *spa;
f6891a60bd72 PSARC 2007/083 ZFS bootable datasets
lling
parents: 3886
diff changeset
  2411
	int error;
f6891a60bd72 PSARC 2007/083 ZFS bootable datasets
lling
parents: 3886
diff changeset
  2412
	nvlist_t *nvp = NULL;
f6891a60bd72 PSARC 2007/083 ZFS bootable datasets
lling
parents: 3886
diff changeset
  2413
8525
e0e0e525d0f8 6788830 set large value to reservation cause core dump
Eric Schrock <Eric.Schrock@Sun.COM>
parents: 8415
diff changeset
  2414
	if ((error = spa_open(zc->zc_name, &spa, FTAG)) != 0) {
e0e0e525d0f8 6788830 set large value to reservation cause core dump
Eric Schrock <Eric.Schrock@Sun.COM>
parents: 8415
diff changeset
  2415
		/*
e0e0e525d0f8 6788830 set large value to reservation cause core dump
Eric Schrock <Eric.Schrock@Sun.COM>
parents: 8415
diff changeset
  2416
		 * If the pool is faulted, there may be properties we can still
e0e0e525d0f8 6788830 set large value to reservation cause core dump
Eric Schrock <Eric.Schrock@Sun.COM>
parents: 8415
diff changeset
  2417
		 * get (such as altroot and cachefile), so attempt to get them
e0e0e525d0f8 6788830 set large value to reservation cause core dump
Eric Schrock <Eric.Schrock@Sun.COM>
parents: 8415
diff changeset
  2418
		 * anyway.
e0e0e525d0f8 6788830 set large value to reservation cause core dump
Eric Schrock <Eric.Schrock@Sun.COM>
parents: 8415
diff changeset
  2419
		 */
e0e0e525d0f8 6788830 set large value to reservation cause core dump
Eric Schrock <Eric.Schrock@Sun.COM>
parents: 8415
diff changeset
  2420
		mutex_enter(&spa_namespace_lock);
e0e0e525d0f8 6788830 set large value to reservation cause core dump
Eric Schrock <Eric.Schrock@Sun.COM>
parents: 8415
diff changeset
  2421
		if ((spa = spa_lookup(zc->zc_name)) != NULL)
e0e0e525d0f8 6788830 set large value to reservation cause core dump
Eric Schrock <Eric.Schrock@Sun.COM>
parents: 8415
diff changeset
  2422
			error = spa_prop_get(spa, &nvp);
e0e0e525d0f8 6788830 set large value to reservation cause core dump
Eric Schrock <Eric.Schrock@Sun.COM>
parents: 8415
diff changeset
  2423
		mutex_exit(&spa_namespace_lock);
e0e0e525d0f8 6788830 set large value to reservation cause core dump
Eric Schrock <Eric.Schrock@Sun.COM>
parents: 8415
diff changeset
  2424
	} else {
e0e0e525d0f8 6788830 set large value to reservation cause core dump
Eric Schrock <Eric.Schrock@Sun.COM>
parents: 8415
diff changeset
  2425
		error = spa_prop_get(spa, &nvp);
e0e0e525d0f8 6788830 set large value to reservation cause core dump
Eric Schrock <Eric.Schrock@Sun.COM>
parents: 8415
diff changeset
  2426
		spa_close(spa, FTAG);
e0e0e525d0f8 6788830 set large value to reservation cause core dump
Eric Schrock <Eric.Schrock@Sun.COM>
parents: 8415
diff changeset
  2427
	}
3912
f6891a60bd72 PSARC 2007/083 ZFS bootable datasets
lling
parents: 3886
diff changeset
  2428
f6891a60bd72 PSARC 2007/083 ZFS bootable datasets
lling
parents: 3886
diff changeset
  2429
	if (error == 0 && zc->zc_nvlist_dst != NULL)
f6891a60bd72 PSARC 2007/083 ZFS bootable datasets
lling
parents: 3886
diff changeset
  2430
		error = put_nvlist(zc, nvp);
f6891a60bd72 PSARC 2007/083 ZFS bootable datasets
lling
parents: 3886
diff changeset
  2431
	else
f6891a60bd72 PSARC 2007/083 ZFS bootable datasets
lling
parents: 3886
diff changeset
  2432
		error = EFAULT;
f6891a60bd72 PSARC 2007/083 ZFS bootable datasets
lling
parents: 3886
diff changeset
  2433
8525
e0e0e525d0f8 6788830 set large value to reservation cause core dump
Eric Schrock <Eric.Schrock@Sun.COM>
parents: 8415
diff changeset
  2434
	nvlist_free(nvp);
3912
f6891a60bd72 PSARC 2007/083 ZFS bootable datasets
lling
parents: 3886
diff changeset
  2435
	return (error);
f6891a60bd72 PSARC 2007/083 ZFS bootable datasets
lling
parents: 3886
diff changeset
  2436
}
f6891a60bd72 PSARC 2007/083 ZFS bootable datasets
lling
parents: 3886
diff changeset
  2437
5367
c40abbe796be PSARC/2007/574 zfs send -R
ahrens
parents: 5331
diff changeset
  2438
/*
c40abbe796be PSARC/2007/574 zfs send -R
ahrens
parents: 5331
diff changeset
  2439
 * inputs:
c40abbe796be PSARC/2007/574 zfs send -R
ahrens
parents: 5331
diff changeset
  2440
 * zc_name		name of filesystem
c40abbe796be PSARC/2007/574 zfs send -R
ahrens
parents: 5331
diff changeset
  2441
 * zc_nvlist_src{_size}	nvlist of delegated permissions
c40abbe796be PSARC/2007/574 zfs send -R
ahrens
parents: 5331
diff changeset
  2442
 * zc_perm_action	allow/unallow flag
c40abbe796be PSARC/2007/574 zfs send -R
ahrens
parents: 5331
diff changeset
  2443
 *
c40abbe796be PSARC/2007/574 zfs send -R
ahrens
parents: 5331
diff changeset
  2444
 * outputs:		none
c40abbe796be PSARC/2007/574 zfs send -R
ahrens
parents: 5331
diff changeset
  2445
 */
4543
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  2446
static int
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  2447
zfs_ioc_set_fsacl(zfs_cmd_t *zc)
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  2448
{
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  2449
	int error;
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  2450
	nvlist_t *fsaclnv = NULL;
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  2451
5094
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
  2452
	if ((error = get_nvlist(zc->zc_nvlist_src, zc->zc_nvlist_src_size,
9643
ffd8e7765f02 6736004 zvols need an additional property for comstar support
Eric Taylor <Eric.Taylor@Sun.COM>
parents: 9425
diff changeset
  2453
	    zc->zc_iflags, &fsaclnv)) != 0)
4543
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  2454
		return (error);
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  2455
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  2456
	/*
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  2457
	 * Verify nvlist is constructed correctly
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  2458
	 */
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  2459
	if ((error = zfs_deleg_verify_nvlist(fsaclnv)) != 0) {
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  2460
		nvlist_free(fsaclnv);
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  2461
		return (EINVAL);
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
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
	 * If we don't have PRIV_SYS_MOUNT, then validate
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  2466
	 * that user is allowed to hand out each permission in
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  2467
	 * the nvlist(s)
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  2468
	 */
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  2469
4787
602d3f97842c 6393351 unique_* could be improved
ahrens
parents: 4720
diff changeset
  2470
	error = secpolicy_zfs(CRED());
4543
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  2471
	if (error) {
4787
602d3f97842c 6393351 unique_* could be improved
ahrens
parents: 4720
diff changeset
  2472
		if (zc->zc_perm_action == B_FALSE) {
602d3f97842c 6393351 unique_* could be improved
ahrens
parents: 4720
diff changeset
  2473
			error = dsl_deleg_can_allow(zc->zc_name,
602d3f97842c 6393351 unique_* could be improved
ahrens
parents: 4720
diff changeset
  2474
			    fsaclnv, CRED());
602d3f97842c 6393351 unique_* could be improved
ahrens
parents: 4720
diff changeset
  2475
		} else {
602d3f97842c 6393351 unique_* could be improved
ahrens
parents: 4720
diff changeset
  2476
			error = dsl_deleg_can_unallow(zc->zc_name,
602d3f97842c 6393351 unique_* could be improved
ahrens
parents: 4720
diff changeset
  2477
			    fsaclnv, CRED());
602d3f97842c 6393351 unique_* could be improved
ahrens
parents: 4720
diff changeset
  2478
		}
4543
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  2479
	}
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  2480
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  2481
	if (error == 0)
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  2482
		error = dsl_deleg_set(zc->zc_name, fsaclnv, zc->zc_perm_action);
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  2483
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  2484
	nvlist_free(fsaclnv);
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  2485
	return (error);
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  2486
}
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  2487
5367
c40abbe796be PSARC/2007/574 zfs send -R
ahrens
parents: 5331
diff changeset
  2488
/*
c40abbe796be PSARC/2007/574 zfs send -R
ahrens
parents: 5331
diff changeset
  2489
 * inputs:
c40abbe796be PSARC/2007/574 zfs send -R
ahrens
parents: 5331
diff changeset
  2490
 * zc_name		name of filesystem
c40abbe796be PSARC/2007/574 zfs send -R
ahrens
parents: 5331
diff changeset
  2491
 *
c40abbe796be PSARC/2007/574 zfs send -R
ahrens
parents: 5331
diff changeset
  2492
 * outputs:
c40abbe796be PSARC/2007/574 zfs send -R
ahrens
parents: 5331
diff changeset
  2493
 * zc_nvlist_src{_size}	nvlist of delegated permissions
c40abbe796be PSARC/2007/574 zfs send -R
ahrens
parents: 5331
diff changeset
  2494
 */
4543
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  2495
static int
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  2496
zfs_ioc_get_fsacl(zfs_cmd_t *zc)
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  2497
{
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  2498
	nvlist_t *nvp;
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  2499
	int error;
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  2500
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  2501
	if ((error = dsl_deleg_get(zc->zc_name, &nvp)) == 0) {
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  2502
		error = put_nvlist(zc, nvp);
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  2503
		nvlist_free(nvp);
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  2504
	}
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  2505
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  2506
	return (error);
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  2507
}
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  2508
5367
c40abbe796be PSARC/2007/574 zfs send -R
ahrens
parents: 5331
diff changeset
  2509
/*
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2510
 * Search the vfs list for a specified resource.  Returns a pointer to it
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2511
 * or NULL if no suitable entry is found. The caller of this routine
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2512
 * is responsible for releasing the returned vfs pointer.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2513
 */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2514
static vfs_t *
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2515
zfs_get_vfs(const char *resource)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2516
{
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2517
	struct vfs *vfsp;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2518
	struct vfs *vfs_found = NULL;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2519
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2520
	vfs_list_read_lock();
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2521
	vfsp = rootvfs;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2522
	do {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2523
		if (strcmp(refstr_value(vfsp->vfs_resource), resource) == 0) {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2524
			VFS_HOLD(vfsp);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2525
			vfs_found = vfsp;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2526
			break;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2527
		}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2528
		vfsp = vfsp->vfs_next;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2529
	} while (vfsp != rootvfs);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2530
	vfs_list_unlock();
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2531
	return (vfs_found);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2532
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2533
4543
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  2534
/* ARGSUSED */
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2535
static void
4543
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  2536
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
  2537
{
5331
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
  2538
	zfs_creat_t *zct = arg;
5498
334b476844ca 6622831 normalization properties are not preserved by "zfs send"
timh
parents: 5450
diff changeset
  2539
334b476844ca 6622831 normalization properties are not preserved by "zfs send"
timh
parents: 5450
diff changeset
  2540
	zfs_create_fs(os, cr, zct->zct_zplprops, tx);
5331
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
  2541
}
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
  2542
5498
334b476844ca 6622831 normalization properties are not preserved by "zfs send"
timh
parents: 5450
diff changeset
  2543
#define	ZFS_PROP_UNDEFINED	((uint64_t)-1)
334b476844ca 6622831 normalization properties are not preserved by "zfs send"
timh
parents: 5450
diff changeset
  2544
5331
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
  2545
/*
5498
334b476844ca 6622831 normalization properties are not preserved by "zfs send"
timh
parents: 5450
diff changeset
  2546
 * inputs:
7184
9508660f9c27 PSARC 2008/223 Pool root file system properties via zpool(1M)
timh
parents: 7046
diff changeset
  2547
 * createprops		list of properties requested by creator
9508660f9c27 PSARC 2008/223 Pool root file system properties via zpool(1M)
timh
parents: 7046
diff changeset
  2548
 * default_zplver	zpl version to use if unspecified in createprops
9508660f9c27 PSARC 2008/223 Pool root file system properties via zpool(1M)
timh
parents: 7046
diff changeset
  2549
 * fuids_ok		fuids allowed in this version of the spa?
9508660f9c27 PSARC 2008/223 Pool root file system properties via zpool(1M)
timh
parents: 7046
diff changeset
  2550
 * os			parent objset pointer (NULL if root fs)
5331
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
  2551
 *
5498
334b476844ca 6622831 normalization properties are not preserved by "zfs send"
timh
parents: 5450
diff changeset
  2552
 * outputs:
334b476844ca 6622831 normalization properties are not preserved by "zfs send"
timh
parents: 5450
diff changeset
  2553
 * zplprops	values for the zplprops we attach to the master node object
7184
9508660f9c27 PSARC 2008/223 Pool root file system properties via zpool(1M)
timh
parents: 7046
diff changeset
  2554
 * is_ci	true if requested file system will be purely case-insensitive
5331
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
  2555
 *
5498
334b476844ca 6622831 normalization properties are not preserved by "zfs send"
timh
parents: 5450
diff changeset
  2556
 * Determine the settings for utf8only, normalization and
334b476844ca 6622831 normalization properties are not preserved by "zfs send"
timh
parents: 5450
diff changeset
  2557
 * casesensitivity.  Specific values may have been requested by the
334b476844ca 6622831 normalization properties are not preserved by "zfs send"
timh
parents: 5450
diff changeset
  2558
 * creator and/or we can inherit values from the parent dataset.  If
334b476844ca 6622831 normalization properties are not preserved by "zfs send"
timh
parents: 5450
diff changeset
  2559
 * the file system is of too early a vintage, a creator can not
334b476844ca 6622831 normalization properties are not preserved by "zfs send"
timh
parents: 5450
diff changeset
  2560
 * request settings for these properties, even if the requested
334b476844ca 6622831 normalization properties are not preserved by "zfs send"
timh
parents: 5450
diff changeset
  2561
 * setting is the default value.  We don't actually want to create dsl
334b476844ca 6622831 normalization properties are not preserved by "zfs send"
timh
parents: 5450
diff changeset
  2562
 * properties for these, so remove them from the source nvlist after
334b476844ca 6622831 normalization properties are not preserved by "zfs send"
timh
parents: 5450
diff changeset
  2563
 * processing.
5331
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
  2564
 */
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
  2565
static int
9396
f41cf682d0d3 PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 9355
diff changeset
  2566
zfs_fill_zplprops_impl(objset_t *os, uint64_t zplver,
11935
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11933
diff changeset
  2567
    boolean_t fuids_ok, boolean_t sa_ok, nvlist_t *createprops,
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11933
diff changeset
  2568
    nvlist_t *zplprops, boolean_t *is_ci)
5331
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
  2569
{
5498
334b476844ca 6622831 normalization properties are not preserved by "zfs send"
timh
parents: 5450
diff changeset
  2570
	uint64_t sense = ZFS_PROP_UNDEFINED;
334b476844ca 6622831 normalization properties are not preserved by "zfs send"
timh
parents: 5450
diff changeset
  2571
	uint64_t norm = ZFS_PROP_UNDEFINED;
334b476844ca 6622831 normalization properties are not preserved by "zfs send"
timh
parents: 5450
diff changeset
  2572
	uint64_t u8 = ZFS_PROP_UNDEFINED;
334b476844ca 6622831 normalization properties are not preserved by "zfs send"
timh
parents: 5450
diff changeset
  2573
334b476844ca 6622831 normalization properties are not preserved by "zfs send"
timh
parents: 5450
diff changeset
  2574
	ASSERT(zplprops != NULL);
334b476844ca 6622831 normalization properties are not preserved by "zfs send"
timh
parents: 5450
diff changeset
  2575
5375
c682f8c5f5e3 6622822 can not create clone on old version pool
timh
parents: 5367
diff changeset
  2576
	/*
5498
334b476844ca 6622831 normalization properties are not preserved by "zfs send"
timh
parents: 5450
diff changeset
  2577
	 * Pull out creator prop choices, if any.
5375
c682f8c5f5e3 6622822 can not create clone on old version pool
timh
parents: 5367
diff changeset
  2578
	 */
5498
334b476844ca 6622831 normalization properties are not preserved by "zfs send"
timh
parents: 5450
diff changeset
  2579
	if (createprops) {
334b476844ca 6622831 normalization properties are not preserved by "zfs send"
timh
parents: 5450
diff changeset
  2580
		(void) nvlist_lookup_uint64(createprops,
7184
9508660f9c27 PSARC 2008/223 Pool root file system properties via zpool(1M)
timh
parents: 7046
diff changeset
  2581
		    zfs_prop_to_name(ZFS_PROP_VERSION), &zplver);
9508660f9c27 PSARC 2008/223 Pool root file system properties via zpool(1M)
timh
parents: 7046
diff changeset
  2582
		(void) nvlist_lookup_uint64(createprops,
5498
334b476844ca 6622831 normalization properties are not preserved by "zfs send"
timh
parents: 5450
diff changeset
  2583
		    zfs_prop_to_name(ZFS_PROP_NORMALIZE), &norm);
334b476844ca 6622831 normalization properties are not preserved by "zfs send"
timh
parents: 5450
diff changeset
  2584
		(void) nvlist_remove_all(createprops,
334b476844ca 6622831 normalization properties are not preserved by "zfs send"
timh
parents: 5450
diff changeset
  2585
		    zfs_prop_to_name(ZFS_PROP_NORMALIZE));
334b476844ca 6622831 normalization properties are not preserved by "zfs send"
timh
parents: 5450
diff changeset
  2586
		(void) nvlist_lookup_uint64(createprops,
334b476844ca 6622831 normalization properties are not preserved by "zfs send"
timh
parents: 5450
diff changeset
  2587
		    zfs_prop_to_name(ZFS_PROP_UTF8ONLY), &u8);
334b476844ca 6622831 normalization properties are not preserved by "zfs send"
timh
parents: 5450
diff changeset
  2588
		(void) nvlist_remove_all(createprops,
334b476844ca 6622831 normalization properties are not preserved by "zfs send"
timh
parents: 5450
diff changeset
  2589
		    zfs_prop_to_name(ZFS_PROP_UTF8ONLY));
334b476844ca 6622831 normalization properties are not preserved by "zfs send"
timh
parents: 5450
diff changeset
  2590
		(void) nvlist_lookup_uint64(createprops,
334b476844ca 6622831 normalization properties are not preserved by "zfs send"
timh
parents: 5450
diff changeset
  2591
		    zfs_prop_to_name(ZFS_PROP_CASE), &sense);
334b476844ca 6622831 normalization properties are not preserved by "zfs send"
timh
parents: 5450
diff changeset
  2592
		(void) nvlist_remove_all(createprops,
334b476844ca 6622831 normalization properties are not preserved by "zfs send"
timh
parents: 5450
diff changeset
  2593
		    zfs_prop_to_name(ZFS_PROP_CASE));
5331
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
  2594
	}
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
  2595
5375
c682f8c5f5e3 6622822 can not create clone on old version pool
timh
parents: 5367
diff changeset
  2596
	/*
7184
9508660f9c27 PSARC 2008/223 Pool root file system properties via zpool(1M)
timh
parents: 7046
diff changeset
  2597
	 * If the zpl version requested is whacky or the file system
9508660f9c27 PSARC 2008/223 Pool root file system properties via zpool(1M)
timh
parents: 7046
diff changeset
  2598
	 * or pool is version is too "young" to support normalization
9508660f9c27 PSARC 2008/223 Pool root file system properties via zpool(1M)
timh
parents: 7046
diff changeset
  2599
	 * and the creator tried to set a value for one of the props,
9508660f9c27 PSARC 2008/223 Pool root file system properties via zpool(1M)
timh
parents: 7046
diff changeset
  2600
	 * error out.
5498
334b476844ca 6622831 normalization properties are not preserved by "zfs send"
timh
parents: 5450
diff changeset
  2601
	 */
7184
9508660f9c27 PSARC 2008/223 Pool root file system properties via zpool(1M)
timh
parents: 7046
diff changeset
  2602
	if ((zplver < ZPL_VERSION_INITIAL || zplver > ZPL_VERSION) ||
9508660f9c27 PSARC 2008/223 Pool root file system properties via zpool(1M)
timh
parents: 7046
diff changeset
  2603
	    (zplver >= ZPL_VERSION_FUID && !fuids_ok) ||
11935
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11933
diff changeset
  2604
	    (zplver >= ZPL_VERSION_SA && !sa_ok) ||
7184
9508660f9c27 PSARC 2008/223 Pool root file system properties via zpool(1M)
timh
parents: 7046
diff changeset
  2605
	    (zplver < ZPL_VERSION_NORMALIZATION &&
5498
334b476844ca 6622831 normalization properties are not preserved by "zfs send"
timh
parents: 5450
diff changeset
  2606
	    (norm != ZFS_PROP_UNDEFINED || u8 != ZFS_PROP_UNDEFINED ||
7184
9508660f9c27 PSARC 2008/223 Pool root file system properties via zpool(1M)
timh
parents: 7046
diff changeset
  2607
	    sense != ZFS_PROP_UNDEFINED)))
5498
334b476844ca 6622831 normalization properties are not preserved by "zfs send"
timh
parents: 5450
diff changeset
  2608
		return (ENOTSUP);
334b476844ca 6622831 normalization properties are not preserved by "zfs send"
timh
parents: 5450
diff changeset
  2609
334b476844ca 6622831 normalization properties are not preserved by "zfs send"
timh
parents: 5450
diff changeset
  2610
	/*
334b476844ca 6622831 normalization properties are not preserved by "zfs send"
timh
parents: 5450
diff changeset
  2611
	 * Put the version in the zplprops
334b476844ca 6622831 normalization properties are not preserved by "zfs send"
timh
parents: 5450
diff changeset
  2612
	 */
334b476844ca 6622831 normalization properties are not preserved by "zfs send"
timh
parents: 5450
diff changeset
  2613
	VERIFY(nvlist_add_uint64(zplprops,
334b476844ca 6622831 normalization properties are not preserved by "zfs send"
timh
parents: 5450
diff changeset
  2614
	    zfs_prop_to_name(ZFS_PROP_VERSION), zplver) == 0);
334b476844ca 6622831 normalization properties are not preserved by "zfs send"
timh
parents: 5450
diff changeset
  2615
334b476844ca 6622831 normalization properties are not preserved by "zfs send"
timh
parents: 5450
diff changeset
  2616
	if (norm == ZFS_PROP_UNDEFINED)
334b476844ca 6622831 normalization properties are not preserved by "zfs send"
timh
parents: 5450
diff changeset
  2617
		VERIFY(zfs_get_zplprop(os, ZFS_PROP_NORMALIZE, &norm) == 0);
334b476844ca 6622831 normalization properties are not preserved by "zfs send"
timh
parents: 5450
diff changeset
  2618
	VERIFY(nvlist_add_uint64(zplprops,
334b476844ca 6622831 normalization properties are not preserved by "zfs send"
timh
parents: 5450
diff changeset
  2619
	    zfs_prop_to_name(ZFS_PROP_NORMALIZE), norm) == 0);
334b476844ca 6622831 normalization properties are not preserved by "zfs send"
timh
parents: 5450
diff changeset
  2620
334b476844ca 6622831 normalization properties are not preserved by "zfs send"
timh
parents: 5450
diff changeset
  2621
	/*
334b476844ca 6622831 normalization properties are not preserved by "zfs send"
timh
parents: 5450
diff changeset
  2622
	 * If we're normalizing, names must always be valid UTF-8 strings.
334b476844ca 6622831 normalization properties are not preserved by "zfs send"
timh
parents: 5450
diff changeset
  2623
	 */
334b476844ca 6622831 normalization properties are not preserved by "zfs send"
timh
parents: 5450
diff changeset
  2624
	if (norm)
334b476844ca 6622831 normalization properties are not preserved by "zfs send"
timh
parents: 5450
diff changeset
  2625
		u8 = 1;
334b476844ca 6622831 normalization properties are not preserved by "zfs send"
timh
parents: 5450
diff changeset
  2626
	if (u8 == ZFS_PROP_UNDEFINED)
334b476844ca 6622831 normalization properties are not preserved by "zfs send"
timh
parents: 5450
diff changeset
  2627
		VERIFY(zfs_get_zplprop(os, ZFS_PROP_UTF8ONLY, &u8) == 0);
334b476844ca 6622831 normalization properties are not preserved by "zfs send"
timh
parents: 5450
diff changeset
  2628
	VERIFY(nvlist_add_uint64(zplprops,
334b476844ca 6622831 normalization properties are not preserved by "zfs send"
timh
parents: 5450
diff changeset
  2629
	    zfs_prop_to_name(ZFS_PROP_UTF8ONLY), u8) == 0);
334b476844ca 6622831 normalization properties are not preserved by "zfs send"
timh
parents: 5450
diff changeset
  2630
334b476844ca 6622831 normalization properties are not preserved by "zfs send"
timh
parents: 5450
diff changeset
  2631
	if (sense == ZFS_PROP_UNDEFINED)
334b476844ca 6622831 normalization properties are not preserved by "zfs send"
timh
parents: 5450
diff changeset
  2632
		VERIFY(zfs_get_zplprop(os, ZFS_PROP_CASE, &sense) == 0);
334b476844ca 6622831 normalization properties are not preserved by "zfs send"
timh
parents: 5450
diff changeset
  2633
	VERIFY(nvlist_add_uint64(zplprops,
334b476844ca 6622831 normalization properties are not preserved by "zfs send"
timh
parents: 5450
diff changeset
  2634
	    zfs_prop_to_name(ZFS_PROP_CASE), sense) == 0);
334b476844ca 6622831 normalization properties are not preserved by "zfs send"
timh
parents: 5450
diff changeset
  2635
6492
903545192033 6654808 FIGNORECASE lookups in a zfs xattr dir don't provide 'realname' data
timh
parents: 6423
diff changeset
  2636
	if (is_ci)
903545192033 6654808 FIGNORECASE lookups in a zfs xattr dir don't provide 'realname' data
timh
parents: 6423
diff changeset
  2637
		*is_ci = (sense == ZFS_CASE_INSENSITIVE);
903545192033 6654808 FIGNORECASE lookups in a zfs xattr dir don't provide 'realname' data
timh
parents: 6423
diff changeset
  2638
7184
9508660f9c27 PSARC 2008/223 Pool root file system properties via zpool(1M)
timh
parents: 7046
diff changeset
  2639
	return (0);
9508660f9c27 PSARC 2008/223 Pool root file system properties via zpool(1M)
timh
parents: 7046
diff changeset
  2640
}
9508660f9c27 PSARC 2008/223 Pool root file system properties via zpool(1M)
timh
parents: 7046
diff changeset
  2641
9508660f9c27 PSARC 2008/223 Pool root file system properties via zpool(1M)
timh
parents: 7046
diff changeset
  2642
static int
9508660f9c27 PSARC 2008/223 Pool root file system properties via zpool(1M)
timh
parents: 7046
diff changeset
  2643
zfs_fill_zplprops(const char *dataset, nvlist_t *createprops,
9508660f9c27 PSARC 2008/223 Pool root file system properties via zpool(1M)
timh
parents: 7046
diff changeset
  2644
    nvlist_t *zplprops, boolean_t *is_ci)
9508660f9c27 PSARC 2008/223 Pool root file system properties via zpool(1M)
timh
parents: 7046
diff changeset
  2645
{
11935
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11933
diff changeset
  2646
	boolean_t fuids_ok, sa_ok;
7184
9508660f9c27 PSARC 2008/223 Pool root file system properties via zpool(1M)
timh
parents: 7046
diff changeset
  2647
	uint64_t zplver = ZPL_VERSION;
9508660f9c27 PSARC 2008/223 Pool root file system properties via zpool(1M)
timh
parents: 7046
diff changeset
  2648
	objset_t *os = NULL;
9508660f9c27 PSARC 2008/223 Pool root file system properties via zpool(1M)
timh
parents: 7046
diff changeset
  2649
	char parentname[MAXNAMELEN];
9508660f9c27 PSARC 2008/223 Pool root file system properties via zpool(1M)
timh
parents: 7046
diff changeset
  2650
	char *cp;
11935
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11933
diff changeset
  2651
	spa_t *spa;
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11933
diff changeset
  2652
	uint64_t spa_vers;
7184
9508660f9c27 PSARC 2008/223 Pool root file system properties via zpool(1M)
timh
parents: 7046
diff changeset
  2653
	int error;
9508660f9c27 PSARC 2008/223 Pool root file system properties via zpool(1M)
timh
parents: 7046
diff changeset
  2654
9508660f9c27 PSARC 2008/223 Pool root file system properties via zpool(1M)
timh
parents: 7046
diff changeset
  2655
	(void) strlcpy(parentname, dataset, sizeof (parentname));
9508660f9c27 PSARC 2008/223 Pool root file system properties via zpool(1M)
timh
parents: 7046
diff changeset
  2656
	cp = strrchr(parentname, '/');
9508660f9c27 PSARC 2008/223 Pool root file system properties via zpool(1M)
timh
parents: 7046
diff changeset
  2657
	ASSERT(cp != NULL);
9508660f9c27 PSARC 2008/223 Pool root file system properties via zpool(1M)
timh
parents: 7046
diff changeset
  2658
	cp[0] = '\0';
9508660f9c27 PSARC 2008/223 Pool root file system properties via zpool(1M)
timh
parents: 7046
diff changeset
  2659
11935
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11933
diff changeset
  2660
	if ((error = spa_open(dataset, &spa, FTAG)) != 0)
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11933
diff changeset
  2661
		return (error);
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11933
diff changeset
  2662
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11933
diff changeset
  2663
	spa_vers = spa_version(spa);
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11933
diff changeset
  2664
	spa_close(spa, FTAG);
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11933
diff changeset
  2665
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11933
diff changeset
  2666
	zplver = zfs_zpl_version_map(spa_vers);
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11933
diff changeset
  2667
	fuids_ok = (zplver >= ZPL_VERSION_FUID);
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11933
diff changeset
  2668
	sa_ok = (zplver >= ZPL_VERSION_SA);
7184
9508660f9c27 PSARC 2008/223 Pool root file system properties via zpool(1M)
timh
parents: 7046
diff changeset
  2669
9508660f9c27 PSARC 2008/223 Pool root file system properties via zpool(1M)
timh
parents: 7046
diff changeset
  2670
	/*
9508660f9c27 PSARC 2008/223 Pool root file system properties via zpool(1M)
timh
parents: 7046
diff changeset
  2671
	 * Open parent object set so we can inherit zplprop values.
9508660f9c27 PSARC 2008/223 Pool root file system properties via zpool(1M)
timh
parents: 7046
diff changeset
  2672
	 */
10298
a0d52501437c 6860996 %temporary clones are not automatically destroyed on error
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 10272
diff changeset
  2673
	if ((error = dmu_objset_hold(parentname, FTAG, &os)) != 0)
7184
9508660f9c27 PSARC 2008/223 Pool root file system properties via zpool(1M)
timh
parents: 7046
diff changeset
  2674
		return (error);
9508660f9c27 PSARC 2008/223 Pool root file system properties via zpool(1M)
timh
parents: 7046
diff changeset
  2675
11935
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11933
diff changeset
  2676
	error = zfs_fill_zplprops_impl(os, zplver, fuids_ok, sa_ok, createprops,
7184
9508660f9c27 PSARC 2008/223 Pool root file system properties via zpool(1M)
timh
parents: 7046
diff changeset
  2677
	    zplprops, is_ci);
10298
a0d52501437c 6860996 %temporary clones are not automatically destroyed on error
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 10272
diff changeset
  2678
	dmu_objset_rele(os, FTAG);
7184
9508660f9c27 PSARC 2008/223 Pool root file system properties via zpool(1M)
timh
parents: 7046
diff changeset
  2679
	return (error);
9508660f9c27 PSARC 2008/223 Pool root file system properties via zpool(1M)
timh
parents: 7046
diff changeset
  2680
}
9508660f9c27 PSARC 2008/223 Pool root file system properties via zpool(1M)
timh
parents: 7046
diff changeset
  2681
9508660f9c27 PSARC 2008/223 Pool root file system properties via zpool(1M)
timh
parents: 7046
diff changeset
  2682
static int
9508660f9c27 PSARC 2008/223 Pool root file system properties via zpool(1M)
timh
parents: 7046
diff changeset
  2683
zfs_fill_zplprops_root(uint64_t spa_vers, nvlist_t *createprops,
9508660f9c27 PSARC 2008/223 Pool root file system properties via zpool(1M)
timh
parents: 7046
diff changeset
  2684
    nvlist_t *zplprops, boolean_t *is_ci)
9508660f9c27 PSARC 2008/223 Pool root file system properties via zpool(1M)
timh
parents: 7046
diff changeset
  2685
{
11935
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11933
diff changeset
  2686
	boolean_t fuids_ok;
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11933
diff changeset
  2687
	boolean_t sa_ok;
7184
9508660f9c27 PSARC 2008/223 Pool root file system properties via zpool(1M)
timh
parents: 7046
diff changeset
  2688
	uint64_t zplver = ZPL_VERSION;
9508660f9c27 PSARC 2008/223 Pool root file system properties via zpool(1M)
timh
parents: 7046
diff changeset
  2689
	int error;
9508660f9c27 PSARC 2008/223 Pool root file system properties via zpool(1M)
timh
parents: 7046
diff changeset
  2690
11935
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11933
diff changeset
  2691
	zplver = zfs_zpl_version_map(spa_vers);
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11933
diff changeset
  2692
	fuids_ok = (zplver >= ZPL_VERSION_FUID);
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11933
diff changeset
  2693
	sa_ok = (zplver >= ZPL_VERSION_SA);
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11933
diff changeset
  2694
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11933
diff changeset
  2695
	error = zfs_fill_zplprops_impl(NULL, zplver, fuids_ok, sa_ok,
538c866aaac6 6716117 ZFS needs native system attribute infrastructure
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 11933
diff changeset
  2696
	    createprops, zplprops, is_ci);
7184
9508660f9c27 PSARC 2008/223 Pool root file system properties via zpool(1M)
timh
parents: 7046
diff changeset
  2697
	return (error);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2698
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2699
5367
c40abbe796be PSARC/2007/574 zfs send -R
ahrens
parents: 5331
diff changeset
  2700
/*
c40abbe796be PSARC/2007/574 zfs send -R
ahrens
parents: 5331
diff changeset
  2701
 * inputs:
c40abbe796be PSARC/2007/574 zfs send -R
ahrens
parents: 5331
diff changeset
  2702
 * zc_objset_type	type of objset to create (fs vs zvol)
c40abbe796be PSARC/2007/574 zfs send -R
ahrens
parents: 5331
diff changeset
  2703
 * zc_name		name of new objset
c40abbe796be PSARC/2007/574 zfs send -R
ahrens
parents: 5331
diff changeset
  2704
 * zc_value		name of snapshot to clone from (may be empty)
c40abbe796be PSARC/2007/574 zfs send -R
ahrens
parents: 5331
diff changeset
  2705
 * zc_nvlist_src{_size}	nvlist of properties to apply
c40abbe796be PSARC/2007/574 zfs send -R
ahrens
parents: 5331
diff changeset
  2706
 *
5498
334b476844ca 6622831 normalization properties are not preserved by "zfs send"
timh
parents: 5450
diff changeset
  2707
 * outputs: none
5367
c40abbe796be PSARC/2007/574 zfs send -R
ahrens
parents: 5331
diff changeset
  2708
 */
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2709
static int
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2710
zfs_ioc_create(zfs_cmd_t *zc)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2711
{
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2712
	objset_t *clone;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2713
	int error = 0;
5331
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
  2714
	zfs_creat_t zct;
4543
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  2715
	nvlist_t *nvprops = NULL;
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  2716
	void (*cbfunc)(objset_t *os, void *arg, cred_t *cr, dmu_tx_t *tx);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2717
	dmu_objset_type_t type = zc->zc_objset_type;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2718
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2719
	switch (type) {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2720
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2721
	case DMU_OST_ZFS:
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2722
		cbfunc = zfs_create_cb;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2723
		break;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2724
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2725
	case DMU_OST_ZVOL:
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2726
		cbfunc = zvol_create_cb;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2727
		break;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2728
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2729
	default:
2199
712a788c2dfd PSARC 2006/388 snapshot -r
ahrens
parents: 2082
diff changeset
  2730
		cbfunc = NULL;
6423
437422a29d3a PSARC 2006/370 ZFS Boot Support
gw25295
parents: 6139
diff changeset
  2731
		break;
2199
712a788c2dfd PSARC 2006/388 snapshot -r
ahrens
parents: 2082
diff changeset
  2732
	}
5326
6752aa2bd5bc 6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents: 5147
diff changeset
  2733
	if (strchr(zc->zc_name, '@') ||
6752aa2bd5bc 6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents: 5147
diff changeset
  2734
	    strchr(zc->zc_name, '%'))
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2735
		return (EINVAL);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2736
2676
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  2737
	if (zc->zc_nvlist_src != NULL &&
5094
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4988
diff changeset
  2738
	    (error = get_nvlist(zc->zc_nvlist_src, zc->zc_nvlist_src_size,
9643
ffd8e7765f02 6736004 zvols need an additional property for comstar support
Eric Taylor <Eric.Taylor@Sun.COM>
parents: 9425
diff changeset
  2739
	    zc->zc_iflags, &nvprops)) != 0)
2676
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  2740
		return (error);
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  2741
5498
334b476844ca 6622831 normalization properties are not preserved by "zfs send"
timh
parents: 5450
diff changeset
  2742
	zct.zct_zplprops = NULL;
5331
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
  2743
	zct.zct_props = nvprops;
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
  2744
2676
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  2745
	if (zc->zc_value[0] != '\0') {
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2746
		/*
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2747
		 * We're creating a clone of an existing snapshot.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2748
		 */
2676
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  2749
		zc->zc_value[sizeof (zc->zc_value) - 1] = '\0';
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  2750
		if (dataset_namecheck(zc->zc_value, NULL, NULL) != 0) {
4543
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  2751
			nvlist_free(nvprops);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2752
			return (EINVAL);
2676
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  2753
		}
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2754
10298
a0d52501437c 6860996 %temporary clones are not automatically destroyed on error
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 10272
diff changeset
  2755
		error = dmu_objset_hold(zc->zc_value, FTAG, &clone);
2676
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  2756
		if (error) {
4543
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  2757
			nvlist_free(nvprops);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2758
			return (error);
2676
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  2759
		}
6492
903545192033 6654808 FIGNORECASE lookups in a zfs xattr dir don't provide 'realname' data
timh
parents: 6423
diff changeset
  2760
10272
a0669934e974 6861581 ZFS frees in synching context during rollback
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 10242
diff changeset
  2761
		error = dmu_objset_clone(zc->zc_name, dmu_objset_ds(clone), 0);
10298
a0d52501437c 6860996 %temporary clones are not automatically destroyed on error
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 10272
diff changeset
  2762
		dmu_objset_rele(clone, FTAG);
5331
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
  2763
		if (error) {
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
  2764
			nvlist_free(nvprops);
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
  2765
			return (error);
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
  2766
		}
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2767
	} else {
6492
903545192033 6654808 FIGNORECASE lookups in a zfs xattr dir don't provide 'realname' data
timh
parents: 6423
diff changeset
  2768
		boolean_t is_insensitive = B_FALSE;
903545192033 6654808 FIGNORECASE lookups in a zfs xattr dir don't provide 'realname' data
timh
parents: 6423
diff changeset
  2769
2676
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  2770
		if (cbfunc == NULL) {
4543
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  2771
			nvlist_free(nvprops);
2199
712a788c2dfd PSARC 2006/388 snapshot -r
ahrens
parents: 2082
diff changeset
  2772
			return (EINVAL);
2676
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  2773
		}
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  2774
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2775
		if (type == DMU_OST_ZVOL) {
2676
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  2776
			uint64_t volsize, volblocksize;
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  2777
4543
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  2778
			if (nvprops == NULL ||
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  2779
			    nvlist_lookup_uint64(nvprops,
2676
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  2780
			    zfs_prop_to_name(ZFS_PROP_VOLSIZE),
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  2781
			    &volsize) != 0) {
4543
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  2782
				nvlist_free(nvprops);
2676
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  2783
				return (EINVAL);
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  2784
			}
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  2785
4543
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  2786
			if ((error = nvlist_lookup_uint64(nvprops,
2676
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  2787
			    zfs_prop_to_name(ZFS_PROP_VOLBLOCKSIZE),
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  2788
			    &volblocksize)) != 0 && error != ENOENT) {
4543
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  2789
				nvlist_free(nvprops);
2676
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  2790
				return (EINVAL);
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  2791
			}
1133
335d069294d1 6357470 vdev_raidz.c has unused RAIDZ_SINGLE define, code
eschrock
parents: 1003
diff changeset
  2792
2676
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  2793
			if (error != 0)
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  2794
				volblocksize = zfs_prop_default_numeric(
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  2795
				    ZFS_PROP_VOLBLOCKSIZE);
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  2796
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  2797
			if ((error = zvol_check_volblocksize(
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  2798
			    volblocksize)) != 0 ||
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  2799
			    (error = zvol_check_volsize(volsize,
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  2800
			    volblocksize)) != 0) {
4543
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  2801
				nvlist_free(nvprops);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2802
				return (error);
2676
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  2803
			}
4577
ed36b0e652bc PSARC/2007/328 zfs upgrade
ahrens
parents: 4543
diff changeset
  2804
		} else if (type == DMU_OST_ZFS) {
5331
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
  2805
			int error;
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
  2806
5498
334b476844ca 6622831 normalization properties are not preserved by "zfs send"
timh
parents: 5450
diff changeset
  2807
			/*
5331
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
  2808
			 * We have to have normalization and
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
  2809
			 * case-folding flags correct when we do the
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
  2810
			 * file system creation, so go figure them out
5498
334b476844ca 6622831 normalization properties are not preserved by "zfs send"
timh
parents: 5450
diff changeset
  2811
			 * now.
5331
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
  2812
			 */
5498
334b476844ca 6622831 normalization properties are not preserved by "zfs send"
timh
parents: 5450
diff changeset
  2813
			VERIFY(nvlist_alloc(&zct.zct_zplprops,
334b476844ca 6622831 normalization properties are not preserved by "zfs send"
timh
parents: 5450
diff changeset
  2814
			    NV_UNIQUE_NAME, KM_SLEEP) == 0);
334b476844ca 6622831 normalization properties are not preserved by "zfs send"
timh
parents: 5450
diff changeset
  2815
			error = zfs_fill_zplprops(zc->zc_name, nvprops,
7184
9508660f9c27 PSARC 2008/223 Pool root file system properties via zpool(1M)
timh
parents: 7046
diff changeset
  2816
			    zct.zct_zplprops, &is_insensitive);
5331
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
  2817
			if (error != 0) {
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
  2818
				nvlist_free(nvprops);
5498
334b476844ca 6622831 normalization properties are not preserved by "zfs send"
timh
parents: 5450
diff changeset
  2819
				nvlist_free(zct.zct_zplprops);
5331
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
  2820
				return (error);
4577
ed36b0e652bc PSARC/2007/328 zfs upgrade
ahrens
parents: 4543
diff changeset
  2821
			}
2676
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  2822
		}
10272
a0669934e974 6861581 ZFS frees in synching context during rollback
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 10242
diff changeset
  2823
		error = dmu_objset_create(zc->zc_name, type,
6492
903545192033 6654808 FIGNORECASE lookups in a zfs xattr dir don't provide 'realname' data
timh
parents: 6423
diff changeset
  2824
		    is_insensitive ? DS_FLAG_CI_DATASET : 0, cbfunc, &zct);
5498
334b476844ca 6622831 normalization properties are not preserved by "zfs send"
timh
parents: 5450
diff changeset
  2825
		nvlist_free(zct.zct_zplprops);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2826
	}
2676
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  2827
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  2828
	/*
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  2829
	 * It would be nice to do this atomically.
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  2830
	 */
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  2831
	if (error == 0) {
11022
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 11007
diff changeset
  2832
		error = zfs_set_prop_nvlist(zc->zc_name, ZPROP_SRC_LOCAL,
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 11007
diff changeset
  2833
		    nvprops, NULL);
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 11007
diff changeset
  2834
		if (error != 0)
10242
c40d075fbca6 PSARC/2009/297 zfs snapshot holds
Chris Kirby <chris.kirby@sun.com>
parents: 10233
diff changeset
  2835
			(void) dmu_objset_destroy(zc->zc_name, B_FALSE);
2676
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  2836
	}
4543
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  2837
	nvlist_free(nvprops);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2838
	return (error);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2839
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2840
5367
c40abbe796be PSARC/2007/574 zfs send -R
ahrens
parents: 5331
diff changeset
  2841
/*
c40abbe796be PSARC/2007/574 zfs send -R
ahrens
parents: 5331
diff changeset
  2842
 * inputs:
c40abbe796be PSARC/2007/574 zfs send -R
ahrens
parents: 5331
diff changeset
  2843
 * zc_name	name of filesystem
c40abbe796be PSARC/2007/574 zfs send -R
ahrens
parents: 5331
diff changeset
  2844
 * zc_value	short name of snapshot
c40abbe796be PSARC/2007/574 zfs send -R
ahrens
parents: 5331
diff changeset
  2845
 * zc_cookie	recursive flag
9396
f41cf682d0d3 PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 9355
diff changeset
  2846
 * zc_nvlist_src[_size] property list
5367
c40abbe796be PSARC/2007/574 zfs send -R
ahrens
parents: 5331
diff changeset
  2847
 *
10588
dc03f981ea18 6438937 if 'zfs destroy' fails, it can leave a zvol device link missing
Eric Taylor <Eric.Taylor@Sun.COM>
parents: 10474
diff changeset
  2848
 * outputs:
dc03f981ea18 6438937 if 'zfs destroy' fails, it can leave a zvol device link missing
Eric Taylor <Eric.Taylor@Sun.COM>
parents: 10474
diff changeset
  2849
 * zc_value	short snapname (i.e. part after the '@')
5367
c40abbe796be PSARC/2007/574 zfs send -R
ahrens
parents: 5331
diff changeset
  2850
 */
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2851
static int
2199
712a788c2dfd PSARC 2006/388 snapshot -r
ahrens
parents: 2082
diff changeset
  2852
zfs_ioc_snapshot(zfs_cmd_t *zc)
712a788c2dfd PSARC 2006/388 snapshot -r
ahrens
parents: 2082
diff changeset
  2853
{
7265
cc18862247da PSARC/2008/483 ZFS clone -o
ahrens
parents: 7214
diff changeset
  2854
	nvlist_t *nvprops = NULL;
cc18862247da PSARC/2008/483 ZFS clone -o
ahrens
parents: 7214
diff changeset
  2855
	int error;
cc18862247da PSARC/2008/483 ZFS clone -o
ahrens
parents: 7214
diff changeset
  2856
	boolean_t recursive = zc->zc_cookie;
cc18862247da PSARC/2008/483 ZFS clone -o
ahrens
parents: 7214
diff changeset
  2857
2676
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  2858
	if (snapshot_namecheck(zc->zc_value, NULL, NULL) != 0)
2199
712a788c2dfd PSARC 2006/388 snapshot -r
ahrens
parents: 2082
diff changeset
  2859
		return (EINVAL);
7265
cc18862247da PSARC/2008/483 ZFS clone -o
ahrens
parents: 7214
diff changeset
  2860
cc18862247da PSARC/2008/483 ZFS clone -o
ahrens
parents: 7214
diff changeset
  2861
	if (zc->zc_nvlist_src != NULL &&
cc18862247da PSARC/2008/483 ZFS clone -o
ahrens
parents: 7214
diff changeset
  2862
	    (error = get_nvlist(zc->zc_nvlist_src, zc->zc_nvlist_src_size,
9643
ffd8e7765f02 6736004 zvols need an additional property for comstar support
Eric Taylor <Eric.Taylor@Sun.COM>
parents: 9425
diff changeset
  2863
	    zc->zc_iflags, &nvprops)) != 0)
7265
cc18862247da PSARC/2008/483 ZFS clone -o
ahrens
parents: 7214
diff changeset
  2864
		return (error);
cc18862247da PSARC/2008/483 ZFS clone -o
ahrens
parents: 7214
diff changeset
  2865
9355
09928982c591 6818183 zfs snapshot -r is slow due to set_snap_props() doing txg_wait_synced() for each new snapshot
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 9234
diff changeset
  2866
	error = zfs_check_userprops(zc->zc_name, nvprops);
09928982c591 6818183 zfs snapshot -r is slow due to set_snap_props() doing txg_wait_synced() for each new snapshot
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 9234
diff changeset
  2867
	if (error)
09928982c591 6818183 zfs snapshot -r is slow due to set_snap_props() doing txg_wait_synced() for each new snapshot
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 9234
diff changeset
  2868
		goto out;
09928982c591 6818183 zfs snapshot -r is slow due to set_snap_props() doing txg_wait_synced() for each new snapshot
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 9234
diff changeset
  2869
11022
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 11007
diff changeset
  2870
	if (!nvlist_empty(nvprops) &&
9355
09928982c591 6818183 zfs snapshot -r is slow due to set_snap_props() doing txg_wait_synced() for each new snapshot
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 9234
diff changeset
  2871
	    zfs_earlier_version(zc->zc_name, SPA_VERSION_SNAP_PROPS)) {
09928982c591 6818183 zfs snapshot -r is slow due to set_snap_props() doing txg_wait_synced() for each new snapshot
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 9234
diff changeset
  2872
		error = ENOTSUP;
09928982c591 6818183 zfs snapshot -r is slow due to set_snap_props() doing txg_wait_synced() for each new snapshot
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 9234
diff changeset
  2873
		goto out;
7265
cc18862247da PSARC/2008/483 ZFS clone -o
ahrens
parents: 7214
diff changeset
  2874
	}
9355
09928982c591 6818183 zfs snapshot -r is slow due to set_snap_props() doing txg_wait_synced() for each new snapshot
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 9234
diff changeset
  2875
09928982c591 6818183 zfs snapshot -r is slow due to set_snap_props() doing txg_wait_synced() for each new snapshot
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 9234
diff changeset
  2876
	error = dmu_objset_snapshot(zc->zc_name, zc->zc_value,
09928982c591 6818183 zfs snapshot -r is slow due to set_snap_props() doing txg_wait_synced() for each new snapshot
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 9234
diff changeset
  2877
	    nvprops, recursive);
09928982c591 6818183 zfs snapshot -r is slow due to set_snap_props() doing txg_wait_synced() for each new snapshot
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 9234
diff changeset
  2878
09928982c591 6818183 zfs snapshot -r is slow due to set_snap_props() doing txg_wait_synced() for each new snapshot
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 9234
diff changeset
  2879
out:
7265
cc18862247da PSARC/2008/483 ZFS clone -o
ahrens
parents: 7214
diff changeset
  2880
	nvlist_free(nvprops);
cc18862247da PSARC/2008/483 ZFS clone -o
ahrens
parents: 7214
diff changeset
  2881
	return (error);
2199
712a788c2dfd PSARC 2006/388 snapshot -r
ahrens
parents: 2082
diff changeset
  2882
}
712a788c2dfd PSARC 2006/388 snapshot -r
ahrens
parents: 2082
diff changeset
  2883
4007
c6f5c6753018 PSARC 2007/142 zfs rename -r
mmusante
parents: 3912
diff changeset
  2884
int
11209
462283cb4096 6905188 panic: kernel heap corruption when doing "zfs rename -r"
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 11185
diff changeset
  2885
zfs_unmount_snap(const char *name, void *arg)
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2886
{
2417
694d5de97348 6444346 zfs promote fails in zone
ahrens
parents: 2199
diff changeset
  2887
	vfs_t *vfsp = NULL;
2199
712a788c2dfd PSARC 2006/388 snapshot -r
ahrens
parents: 2082
diff changeset
  2888
6689
47572a2f5e73 6610506 Eliminate or improve retry logic from callers of dmu_objset_open()
maybee
parents: 6643
diff changeset
  2889
	if (arg) {
47572a2f5e73 6610506 Eliminate or improve retry logic from callers of dmu_objset_open()
maybee
parents: 6643
diff changeset
  2890
		char *snapname = arg;
11209
462283cb4096 6905188 panic: kernel heap corruption when doing "zfs rename -r"
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 11185
diff changeset
  2891
		char *fullname = kmem_asprintf("%s@%s", name, snapname);
462283cb4096 6905188 panic: kernel heap corruption when doing "zfs rename -r"
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 11185
diff changeset
  2892
		vfsp = zfs_get_vfs(fullname);
462283cb4096 6905188 panic: kernel heap corruption when doing "zfs rename -r"
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 11185
diff changeset
  2893
		strfree(fullname);
2417
694d5de97348 6444346 zfs promote fails in zone
ahrens
parents: 2199
diff changeset
  2894
	} else if (strchr(name, '@')) {
2199
712a788c2dfd PSARC 2006/388 snapshot -r
ahrens
parents: 2082
diff changeset
  2895
		vfsp = zfs_get_vfs(name);
712a788c2dfd PSARC 2006/388 snapshot -r
ahrens
parents: 2082
diff changeset
  2896
	}
712a788c2dfd PSARC 2006/388 snapshot -r
ahrens
parents: 2082
diff changeset
  2897
712a788c2dfd PSARC 2006/388 snapshot -r
ahrens
parents: 2082
diff changeset
  2898
	if (vfsp) {
712a788c2dfd PSARC 2006/388 snapshot -r
ahrens
parents: 2082
diff changeset
  2899
		/*
712a788c2dfd PSARC 2006/388 snapshot -r
ahrens
parents: 2082
diff changeset
  2900
		 * Always force the unmount for snapshots.
712a788c2dfd PSARC 2006/388 snapshot -r
ahrens
parents: 2082
diff changeset
  2901
		 */
712a788c2dfd PSARC 2006/388 snapshot -r
ahrens
parents: 2082
diff changeset
  2902
		int flag = MS_FORCE;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2903
		int err;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2904
2199
712a788c2dfd PSARC 2006/388 snapshot -r
ahrens
parents: 2082
diff changeset
  2905
		if ((err = vn_vfswlock(vfsp->vfs_vnodecovered)) != 0) {
712a788c2dfd PSARC 2006/388 snapshot -r
ahrens
parents: 2082
diff changeset
  2906
			VFS_RELE(vfsp);
712a788c2dfd PSARC 2006/388 snapshot -r
ahrens
parents: 2082
diff changeset
  2907
			return (err);
712a788c2dfd PSARC 2006/388 snapshot -r
ahrens
parents: 2082
diff changeset
  2908
		}
712a788c2dfd PSARC 2006/388 snapshot -r
ahrens
parents: 2082
diff changeset
  2909
		VFS_RELE(vfsp);
712a788c2dfd PSARC 2006/388 snapshot -r
ahrens
parents: 2082
diff changeset
  2910
		if ((err = dounmount(vfsp, flag, kcred)) != 0)
712a788c2dfd PSARC 2006/388 snapshot -r
ahrens
parents: 2082
diff changeset
  2911
			return (err);
712a788c2dfd PSARC 2006/388 snapshot -r
ahrens
parents: 2082
diff changeset
  2912
	}
712a788c2dfd PSARC 2006/388 snapshot -r
ahrens
parents: 2082
diff changeset
  2913
	return (0);
712a788c2dfd PSARC 2006/388 snapshot -r
ahrens
parents: 2082
diff changeset
  2914
}
712a788c2dfd PSARC 2006/388 snapshot -r
ahrens
parents: 2082
diff changeset
  2915
5367
c40abbe796be PSARC/2007/574 zfs send -R
ahrens
parents: 5331
diff changeset
  2916
/*
c40abbe796be PSARC/2007/574 zfs send -R
ahrens
parents: 5331
diff changeset
  2917
 * inputs:
10242
c40d075fbca6 PSARC/2009/297 zfs snapshot holds
Chris Kirby <chris.kirby@sun.com>
parents: 10233
diff changeset
  2918
 * zc_name		name of filesystem
c40d075fbca6 PSARC/2009/297 zfs snapshot holds
Chris Kirby <chris.kirby@sun.com>
parents: 10233
diff changeset
  2919
 * zc_value		short name of snapshot
c40d075fbca6 PSARC/2009/297 zfs snapshot holds
Chris Kirby <chris.kirby@sun.com>
parents: 10233
diff changeset
  2920
 * zc_defer_destroy	mark for deferred destroy
5367
c40abbe796be PSARC/2007/574 zfs send -R
ahrens
parents: 5331
diff changeset
  2921
 *
c40abbe796be PSARC/2007/574 zfs send -R
ahrens
parents: 5331
diff changeset
  2922
 * outputs:	none
c40abbe796be PSARC/2007/574 zfs send -R
ahrens
parents: 5331
diff changeset
  2923
 */
2199
712a788c2dfd PSARC 2006/388 snapshot -r
ahrens
parents: 2082
diff changeset
  2924
static int
712a788c2dfd PSARC 2006/388 snapshot -r
ahrens
parents: 2082
diff changeset
  2925
zfs_ioc_destroy_snaps(zfs_cmd_t *zc)
712a788c2dfd PSARC 2006/388 snapshot -r
ahrens
parents: 2082
diff changeset
  2926
{
712a788c2dfd PSARC 2006/388 snapshot -r
ahrens
parents: 2082
diff changeset
  2927
	int err;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2928
2676
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  2929
	if (snapshot_namecheck(zc->zc_value, NULL, NULL) != 0)
2199
712a788c2dfd PSARC 2006/388 snapshot -r
ahrens
parents: 2082
diff changeset
  2930
		return (EINVAL);
712a788c2dfd PSARC 2006/388 snapshot -r
ahrens
parents: 2082
diff changeset
  2931
	err = dmu_objset_find(zc->zc_name,
2676
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  2932
	    zfs_unmount_snap, zc->zc_value, DS_FIND_CHILDREN);
2199
712a788c2dfd PSARC 2006/388 snapshot -r
ahrens
parents: 2082
diff changeset
  2933
	if (err)
712a788c2dfd PSARC 2006/388 snapshot -r
ahrens
parents: 2082
diff changeset
  2934
		return (err);
10242
c40d075fbca6 PSARC/2009/297 zfs snapshot holds
Chris Kirby <chris.kirby@sun.com>
parents: 10233
diff changeset
  2935
	return (dmu_snapshots_destroy(zc->zc_name, zc->zc_value,
c40d075fbca6 PSARC/2009/297 zfs snapshot holds
Chris Kirby <chris.kirby@sun.com>
parents: 10233
diff changeset
  2936
	    zc->zc_defer_destroy));
2199
712a788c2dfd PSARC 2006/388 snapshot -r
ahrens
parents: 2082
diff changeset
  2937
}
712a788c2dfd PSARC 2006/388 snapshot -r
ahrens
parents: 2082
diff changeset
  2938
5367
c40abbe796be PSARC/2007/574 zfs send -R
ahrens
parents: 5331
diff changeset
  2939
/*
c40abbe796be PSARC/2007/574 zfs send -R
ahrens
parents: 5331
diff changeset
  2940
 * inputs:
c40abbe796be PSARC/2007/574 zfs send -R
ahrens
parents: 5331
diff changeset
  2941
 * zc_name		name of dataset to destroy
c40abbe796be PSARC/2007/574 zfs send -R
ahrens
parents: 5331
diff changeset
  2942
 * zc_objset_type	type of objset
10242
c40d075fbca6 PSARC/2009/297 zfs snapshot holds
Chris Kirby <chris.kirby@sun.com>
parents: 10233
diff changeset
  2943
 * zc_defer_destroy	mark for deferred destroy
5367
c40abbe796be PSARC/2007/574 zfs send -R
ahrens
parents: 5331
diff changeset
  2944
 *
c40abbe796be PSARC/2007/574 zfs send -R
ahrens
parents: 5331
diff changeset
  2945
 * outputs:		none
c40abbe796be PSARC/2007/574 zfs send -R
ahrens
parents: 5331
diff changeset
  2946
 */
2199
712a788c2dfd PSARC 2006/388 snapshot -r
ahrens
parents: 2082
diff changeset
  2947
static int
712a788c2dfd PSARC 2006/388 snapshot -r
ahrens
parents: 2082
diff changeset
  2948
zfs_ioc_destroy(zfs_cmd_t *zc)
712a788c2dfd PSARC 2006/388 snapshot -r
ahrens
parents: 2082
diff changeset
  2949
{
10588
dc03f981ea18 6438937 if 'zfs destroy' fails, it can leave a zvol device link missing
Eric Taylor <Eric.Taylor@Sun.COM>
parents: 10474
diff changeset
  2950
	int err;
2199
712a788c2dfd PSARC 2006/388 snapshot -r
ahrens
parents: 2082
diff changeset
  2951
	if (strchr(zc->zc_name, '@') && zc->zc_objset_type == DMU_OST_ZFS) {
10588
dc03f981ea18 6438937 if 'zfs destroy' fails, it can leave a zvol device link missing
Eric Taylor <Eric.Taylor@Sun.COM>
parents: 10474
diff changeset
  2952
		err = zfs_unmount_snap(zc->zc_name, NULL);
2199
712a788c2dfd PSARC 2006/388 snapshot -r
ahrens
parents: 2082
diff changeset
  2953
		if (err)
712a788c2dfd PSARC 2006/388 snapshot -r
ahrens
parents: 2082
diff changeset
  2954
			return (err);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2955
	}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2956
10588
dc03f981ea18 6438937 if 'zfs destroy' fails, it can leave a zvol device link missing
Eric Taylor <Eric.Taylor@Sun.COM>
parents: 10474
diff changeset
  2957
	err = dmu_objset_destroy(zc->zc_name, zc->zc_defer_destroy);
dc03f981ea18 6438937 if 'zfs destroy' fails, it can leave a zvol device link missing
Eric Taylor <Eric.Taylor@Sun.COM>
parents: 10474
diff changeset
  2958
	if (zc->zc_objset_type == DMU_OST_ZVOL && err == 0)
10693
aaa91fcac595 6871683 ztest should exercise deferred destroy
Chris Kirby <chris.kirby@sun.com>
parents: 10685
diff changeset
  2959
		(void) zvol_remove_minor(zc->zc_name);
10588
dc03f981ea18 6438937 if 'zfs destroy' fails, it can leave a zvol device link missing
Eric Taylor <Eric.Taylor@Sun.COM>
parents: 10474
diff changeset
  2960
	return (err);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2961
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2962
5367
c40abbe796be PSARC/2007/574 zfs send -R
ahrens
parents: 5331
diff changeset
  2963
/*
c40abbe796be PSARC/2007/574 zfs send -R
ahrens
parents: 5331
diff changeset
  2964
 * inputs:
5446
51fbc14b301d 6421210 zfs rollback without unmounting
ahrens
parents: 5378
diff changeset
  2965
 * zc_name	name of dataset to rollback (to most recent snapshot)
5367
c40abbe796be PSARC/2007/574 zfs send -R
ahrens
parents: 5331
diff changeset
  2966
 *
c40abbe796be PSARC/2007/574 zfs send -R
ahrens
parents: 5331
diff changeset
  2967
 * outputs:	none
c40abbe796be PSARC/2007/574 zfs send -R
ahrens
parents: 5331
diff changeset
  2968
 */
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2969
static int
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2970
zfs_ioc_rollback(zfs_cmd_t *zc)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2971
{
10272
a0669934e974 6861581 ZFS frees in synching context during rollback
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 10242
diff changeset
  2972
	dsl_dataset_t *ds, *clone;
5446
51fbc14b301d 6421210 zfs rollback without unmounting
ahrens
parents: 5378
diff changeset
  2973
	int error;
10272
a0669934e974 6861581 ZFS frees in synching context during rollback
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 10242
diff changeset
  2974
	zfsvfs_t *zfsvfs;
a0669934e974 6861581 ZFS frees in synching context during rollback
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 10242
diff changeset
  2975
	char *clone_name;
a0669934e974 6861581 ZFS frees in synching context during rollback
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 10242
diff changeset
  2976
a0669934e974 6861581 ZFS frees in synching context during rollback
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 10242
diff changeset
  2977
	error = dsl_dataset_hold(zc->zc_name, FTAG, &ds);
a0669934e974 6861581 ZFS frees in synching context during rollback
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 10242
diff changeset
  2978
	if (error)
a0669934e974 6861581 ZFS frees in synching context during rollback
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 10242
diff changeset
  2979
		return (error);
a0669934e974 6861581 ZFS frees in synching context during rollback
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 10242
diff changeset
  2980
a0669934e974 6861581 ZFS frees in synching context during rollback
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 10242
diff changeset
  2981
	/* must not be a snapshot */
a0669934e974 6861581 ZFS frees in synching context during rollback
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 10242
diff changeset
  2982
	if (dsl_dataset_is_snapshot(ds)) {
a0669934e974 6861581 ZFS frees in synching context during rollback
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 10242
diff changeset
  2983
		dsl_dataset_rele(ds, FTAG);
a0669934e974 6861581 ZFS frees in synching context during rollback
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 10242
diff changeset
  2984
		return (EINVAL);
a0669934e974 6861581 ZFS frees in synching context during rollback
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 10242
diff changeset
  2985
	}
a0669934e974 6861581 ZFS frees in synching context during rollback
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 10242
diff changeset
  2986
a0669934e974 6861581 ZFS frees in synching context during rollback
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 10242
diff changeset
  2987
	/* must have a most recent snapshot */
a0669934e974 6861581 ZFS frees in synching context during rollback
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 10242
diff changeset
  2988
	if (ds->ds_phys->ds_prev_snap_txg < TXG_INITIAL) {
a0669934e974 6861581 ZFS frees in synching context during rollback
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 10242
diff changeset
  2989
		dsl_dataset_rele(ds, FTAG);
a0669934e974 6861581 ZFS frees in synching context during rollback
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 10242
diff changeset
  2990
		return (EINVAL);
a0669934e974 6861581 ZFS frees in synching context during rollback
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 10242
diff changeset
  2991
	}
5446
51fbc14b301d 6421210 zfs rollback without unmounting
ahrens
parents: 5378
diff changeset
  2992
51fbc14b301d 6421210 zfs rollback without unmounting
ahrens
parents: 5378
diff changeset
  2993
	/*
10272
a0669934e974 6861581 ZFS frees in synching context during rollback
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 10242
diff changeset
  2994
	 * Create clone of most recent snapshot.
5446
51fbc14b301d 6421210 zfs rollback without unmounting
ahrens
parents: 5378
diff changeset
  2995
	 */
10272
a0669934e974 6861581 ZFS frees in synching context during rollback
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 10242
diff changeset
  2996
	clone_name = kmem_asprintf("%s/%%rollback", zc->zc_name);
a0669934e974 6861581 ZFS frees in synching context during rollback
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 10242
diff changeset
  2997
	error = dmu_objset_clone(clone_name, ds->ds_prev, DS_FLAG_INCONSISTENT);
5446
51fbc14b301d 6421210 zfs rollback without unmounting
ahrens
parents: 5378
diff changeset
  2998
	if (error)
10272
a0669934e974 6861581 ZFS frees in synching context during rollback
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 10242
diff changeset
  2999
		goto out;
a0669934e974 6861581 ZFS frees in synching context during rollback
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 10242
diff changeset
  3000
10298
a0d52501437c 6860996 %temporary clones are not automatically destroyed on error
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 10272
diff changeset
  3001
	error = dsl_dataset_own(clone_name, B_TRUE, FTAG, &clone);
10272
a0669934e974 6861581 ZFS frees in synching context during rollback
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 10242
diff changeset
  3002
	if (error)
a0669934e974 6861581 ZFS frees in synching context during rollback
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 10242
diff changeset
  3003
		goto out;
a0669934e974 6861581 ZFS frees in synching context during rollback
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 10242
diff changeset
  3004
a0669934e974 6861581 ZFS frees in synching context during rollback
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 10242
diff changeset
  3005
	/*
a0669934e974 6861581 ZFS frees in synching context during rollback
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 10242
diff changeset
  3006
	 * Do clone swap.
a0669934e974 6861581 ZFS frees in synching context during rollback
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 10242
diff changeset
  3007
	 */
9396
f41cf682d0d3 PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 9355
diff changeset
  3008
	if (getzfsvfs(zc->zc_name, &zfsvfs) == 0) {
10298
a0d52501437c 6860996 %temporary clones are not automatically destroyed on error
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 10272
diff changeset
  3009
		error = zfs_suspend_fs(zfsvfs);
6083
23e77aa611b1 6655963 Panic: 0 == zap_add(mos, pds->dd_phys->dd_child_dir_zapobj, name, sizeof (uint64_t), 1, &ddobj, tx)
ek110237
parents: 5977
diff changeset
  3010
		if (error == 0) {
23e77aa611b1 6655963 Panic: 0 == zap_add(mos, pds->dd_phys->dd_child_dir_zapobj, name, sizeof (uint64_t), 1, &ddobj, tx)
ek110237
parents: 5977
diff changeset
  3011
			int resume_err;
23e77aa611b1 6655963 Panic: 0 == zap_add(mos, pds->dd_phys->dd_child_dir_zapobj, name, sizeof (uint64_t), 1, &ddobj, tx)
ek110237
parents: 5977
diff changeset
  3012
10272
a0669934e974 6861581 ZFS frees in synching context during rollback
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 10242
diff changeset
  3013
			if (dsl_dataset_tryown(ds, B_FALSE, FTAG)) {
a0669934e974 6861581 ZFS frees in synching context during rollback
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 10242
diff changeset
  3014
				error = dsl_dataset_clone_swap(clone, ds,
a0669934e974 6861581 ZFS frees in synching context during rollback
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 10242
diff changeset
  3015
				    B_TRUE);
a0669934e974 6861581 ZFS frees in synching context during rollback
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 10242
diff changeset
  3016
				dsl_dataset_disown(ds, FTAG);
a0669934e974 6861581 ZFS frees in synching context during rollback
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 10242
diff changeset
  3017
				ds = NULL;
a0669934e974 6861581 ZFS frees in synching context during rollback
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 10242
diff changeset
  3018
			} else {
a0669934e974 6861581 ZFS frees in synching context during rollback
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 10242
diff changeset
  3019
				error = EBUSY;
a0669934e974 6861581 ZFS frees in synching context during rollback
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 10242
diff changeset
  3020
			}
10298
a0d52501437c 6860996 %temporary clones are not automatically destroyed on error
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 10272
diff changeset
  3021
			resume_err = zfs_resume_fs(zfsvfs, zc->zc_name);
6083
23e77aa611b1 6655963 Panic: 0 == zap_add(mos, pds->dd_phys->dd_child_dir_zapobj, name, sizeof (uint64_t), 1, &ddobj, tx)
ek110237
parents: 5977
diff changeset
  3022
			error = error ? error : resume_err;
23e77aa611b1 6655963 Panic: 0 == zap_add(mos, pds->dd_phys->dd_child_dir_zapobj, name, sizeof (uint64_t), 1, &ddobj, tx)
ek110237
parents: 5977
diff changeset
  3023
		}
5446
51fbc14b301d 6421210 zfs rollback without unmounting
ahrens
parents: 5378
diff changeset
  3024
		VFS_RELE(zfsvfs->z_vfs);
51fbc14b301d 6421210 zfs rollback without unmounting
ahrens
parents: 5378
diff changeset
  3025
	} else {
10272
a0669934e974 6861581 ZFS frees in synching context during rollback
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 10242
diff changeset
  3026
		if (dsl_dataset_tryown(ds, B_FALSE, FTAG)) {
a0669934e974 6861581 ZFS frees in synching context during rollback
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 10242
diff changeset
  3027
			error = dsl_dataset_clone_swap(clone, ds, B_TRUE);
a0669934e974 6861581 ZFS frees in synching context during rollback
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 10242
diff changeset
  3028
			dsl_dataset_disown(ds, FTAG);
a0669934e974 6861581 ZFS frees in synching context during rollback
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 10242
diff changeset
  3029
			ds = NULL;
a0669934e974 6861581 ZFS frees in synching context during rollback
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 10242
diff changeset
  3030
		} else {
a0669934e974 6861581 ZFS frees in synching context during rollback
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 10242
diff changeset
  3031
			error = EBUSY;
a0669934e974 6861581 ZFS frees in synching context during rollback
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 10242
diff changeset
  3032
		}
5446
51fbc14b301d 6421210 zfs rollback without unmounting
ahrens
parents: 5378
diff changeset
  3033
	}
10272
a0669934e974 6861581 ZFS frees in synching context during rollback
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 10242
diff changeset
  3034
a0669934e974 6861581 ZFS frees in synching context during rollback
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 10242
diff changeset
  3035
	/*
a0669934e974 6861581 ZFS frees in synching context during rollback
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 10242
diff changeset
  3036
	 * Destroy clone (which also closes it).
a0669934e974 6861581 ZFS frees in synching context during rollback
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 10242
diff changeset
  3037
	 */
a0669934e974 6861581 ZFS frees in synching context during rollback
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 10242
diff changeset
  3038
	(void) dsl_dataset_destroy(clone, FTAG, B_FALSE);
a0669934e974 6861581 ZFS frees in synching context during rollback
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 10242
diff changeset
  3039
a0669934e974 6861581 ZFS frees in synching context during rollback
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 10242
diff changeset
  3040
out:
a0669934e974 6861581 ZFS frees in synching context during rollback
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 10242
diff changeset
  3041
	strfree(clone_name);
a0669934e974 6861581 ZFS frees in synching context during rollback
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 10242
diff changeset
  3042
	if (ds)
a0669934e974 6861581 ZFS frees in synching context during rollback
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 10242
diff changeset
  3043
		dsl_dataset_rele(ds, FTAG);
5446
51fbc14b301d 6421210 zfs rollback without unmounting
ahrens
parents: 5378
diff changeset
  3044
	return (error);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3045
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3046
5367
c40abbe796be PSARC/2007/574 zfs send -R
ahrens
parents: 5331
diff changeset
  3047
/*
c40abbe796be PSARC/2007/574 zfs send -R
ahrens
parents: 5331
diff changeset
  3048
 * inputs:
c40abbe796be PSARC/2007/574 zfs send -R
ahrens
parents: 5331
diff changeset
  3049
 * zc_name	old name of dataset
c40abbe796be PSARC/2007/574 zfs send -R
ahrens
parents: 5331
diff changeset
  3050
 * zc_value	new name of dataset
c40abbe796be PSARC/2007/574 zfs send -R
ahrens
parents: 5331
diff changeset
  3051
 * zc_cookie	recursive flag (only valid for snapshots)
c40abbe796be PSARC/2007/574 zfs send -R
ahrens
parents: 5331
diff changeset
  3052
 *
c40abbe796be PSARC/2007/574 zfs send -R
ahrens
parents: 5331
diff changeset
  3053
 * outputs:	none
c40abbe796be PSARC/2007/574 zfs send -R
ahrens
parents: 5331
diff changeset
  3054
 */
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3055
static int
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3056
zfs_ioc_rename(zfs_cmd_t *zc)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3057
{
4490
abf035049f7f PSARC 2007/199 zfs {create,clone,rename} -p
vb160487
parents: 4451
diff changeset
  3058
	boolean_t recursive = zc->zc_cookie & 1;
4007
c6f5c6753018 PSARC 2007/142 zfs rename -r
mmusante
parents: 3912
diff changeset
  3059
2676
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  3060
	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
  3061
	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
  3062
	    strchr(zc->zc_value, '%'))
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3063
		return (EINVAL);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3064
4007
c6f5c6753018 PSARC 2007/142 zfs rename -r
mmusante
parents: 3912
diff changeset
  3065
	/*
c6f5c6753018 PSARC 2007/142 zfs rename -r
mmusante
parents: 3912
diff changeset
  3066
	 * Unmount snapshot unless we're doing a recursive rename,
c6f5c6753018 PSARC 2007/142 zfs rename -r
mmusante
parents: 3912
diff changeset
  3067
	 * in which case the dataset code figures out which snapshots
c6f5c6753018 PSARC 2007/142 zfs rename -r
mmusante
parents: 3912
diff changeset
  3068
	 * to unmount.
c6f5c6753018 PSARC 2007/142 zfs rename -r
mmusante
parents: 3912
diff changeset
  3069
	 */
c6f5c6753018 PSARC 2007/142 zfs rename -r
mmusante
parents: 3912
diff changeset
  3070
	if (!recursive && strchr(zc->zc_name, '@') != NULL &&
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3071
	    zc->zc_objset_type == DMU_OST_ZFS) {
2199
712a788c2dfd PSARC 2006/388 snapshot -r
ahrens
parents: 2082
diff changeset
  3072
		int err = zfs_unmount_snap(zc->zc_name, NULL);
712a788c2dfd PSARC 2006/388 snapshot -r
ahrens
parents: 2082
diff changeset
  3073
		if (err)
712a788c2dfd PSARC 2006/388 snapshot -r
ahrens
parents: 2082
diff changeset
  3074
			return (err);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3075
	}
10588
dc03f981ea18 6438937 if 'zfs destroy' fails, it can leave a zvol device link missing
Eric Taylor <Eric.Taylor@Sun.COM>
parents: 10474
diff changeset
  3076
	if (zc->zc_objset_type == DMU_OST_ZVOL)
dc03f981ea18 6438937 if 'zfs destroy' fails, it can leave a zvol device link missing
Eric Taylor <Eric.Taylor@Sun.COM>
parents: 10474
diff changeset
  3077
		(void) zvol_remove_minor(zc->zc_name);
4007
c6f5c6753018 PSARC 2007/142 zfs rename -r
mmusante
parents: 3912
diff changeset
  3078
	return (dmu_objset_rename(zc->zc_name, zc->zc_value, recursive));
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3079
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3080
11022
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 11007
diff changeset
  3081
static int
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 11007
diff changeset
  3082
zfs_check_settable(const char *dsname, nvpair_t *pair, cred_t *cr)
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 11007
diff changeset
  3083
{
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 11007
diff changeset
  3084
	const char *propname = nvpair_name(pair);
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 11007
diff changeset
  3085
	boolean_t issnap = (strchr(dsname, '@') != NULL);
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 11007
diff changeset
  3086
	zfs_prop_t prop = zfs_name_to_prop(propname);
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 11007
diff changeset
  3087
	uint64_t intval;
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 11007
diff changeset
  3088
	int err;
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 11007
diff changeset
  3089
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 11007
diff changeset
  3090
	if (prop == ZPROP_INVAL) {
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 11007
diff changeset
  3091
		if (zfs_prop_user(propname)) {
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 11007
diff changeset
  3092
			if (err = zfs_secpolicy_write_perms(dsname,
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 11007
diff changeset
  3093
			    ZFS_DELEG_PERM_USERPROP, cr))
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 11007
diff changeset
  3094
				return (err);
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 11007
diff changeset
  3095
			return (0);
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 11007
diff changeset
  3096
		}
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 11007
diff changeset
  3097
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 11007
diff changeset
  3098
		if (!issnap && zfs_prop_userquota(propname)) {
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 11007
diff changeset
  3099
			const char *perm = NULL;
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 11007
diff changeset
  3100
			const char *uq_prefix =
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 11007
diff changeset
  3101
			    zfs_userquota_prop_prefixes[ZFS_PROP_USERQUOTA];
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 11007
diff changeset
  3102
			const char *gq_prefix =
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 11007
diff changeset
  3103
			    zfs_userquota_prop_prefixes[ZFS_PROP_GROUPQUOTA];
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 11007
diff changeset
  3104
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 11007
diff changeset
  3105
			if (strncmp(propname, uq_prefix,
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 11007
diff changeset
  3106
			    strlen(uq_prefix)) == 0) {
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 11007
diff changeset
  3107
				perm = ZFS_DELEG_PERM_USERQUOTA;
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 11007
diff changeset
  3108
			} else if (strncmp(propname, gq_prefix,
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 11007
diff changeset
  3109
			    strlen(gq_prefix)) == 0) {
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 11007
diff changeset
  3110
				perm = ZFS_DELEG_PERM_GROUPQUOTA;
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 11007
diff changeset
  3111
			} else {
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 11007
diff changeset
  3112
				/* USERUSED and GROUPUSED are read-only */
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 11007
diff changeset
  3113
				return (EINVAL);
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 11007
diff changeset
  3114
			}
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 11007
diff changeset
  3115
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 11007
diff changeset
  3116
			if (err = zfs_secpolicy_write_perms(dsname, perm, cr))
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 11007
diff changeset
  3117
				return (err);
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 11007
diff changeset
  3118
			return (0);
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 11007
diff changeset
  3119
		}
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 11007
diff changeset
  3120
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 11007
diff changeset
  3121
		return (EINVAL);
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 11007
diff changeset
  3122
	}
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 11007
diff changeset
  3123
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 11007
diff changeset
  3124
	if (issnap)
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 11007
diff changeset
  3125
		return (EINVAL);
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 11007
diff changeset
  3126
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 11007
diff changeset
  3127
	if (nvpair_type(pair) == DATA_TYPE_NVLIST) {
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 11007
diff changeset
  3128
		/*
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 11007
diff changeset
  3129
		 * dsl_prop_get_all_impl() returns properties in this
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 11007
diff changeset
  3130
		 * format.
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 11007
diff changeset
  3131
		 */
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 11007
diff changeset
  3132
		nvlist_t *attrs;
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 11007
diff changeset
  3133
		VERIFY(nvpair_value_nvlist(pair, &attrs) == 0);
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 11007
diff changeset
  3134
		VERIFY(nvlist_lookup_nvpair(attrs, ZPROP_VALUE,
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 11007
diff changeset
  3135
		    &pair) == 0);
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 11007
diff changeset
  3136
	}
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 11007
diff changeset
  3137
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 11007
diff changeset
  3138
	/*
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 11007
diff changeset
  3139
	 * Check that this value is valid for this pool version
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 11007
diff changeset
  3140
	 */
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 11007
diff changeset
  3141
	switch (prop) {
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 11007
diff changeset
  3142
	case ZFS_PROP_COMPRESSION:
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 11007
diff changeset
  3143
		/*
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 11007
diff changeset
  3144
		 * If the user specified gzip compression, make sure
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 11007
diff changeset
  3145
		 * the SPA supports it. We ignore any errors here since
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 11007
diff changeset
  3146
		 * we'll catch them later.
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 11007
diff changeset
  3147
		 */
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 11007
diff changeset
  3148
		if (nvpair_type(pair) == DATA_TYPE_UINT64 &&
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 11007
diff changeset
  3149
		    nvpair_value_uint64(pair, &intval) == 0) {
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 11007
diff changeset
  3150
			if (intval >= ZIO_COMPRESS_GZIP_1 &&
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 11007
diff changeset
  3151
			    intval <= ZIO_COMPRESS_GZIP_9 &&
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 11007
diff changeset
  3152
			    zfs_earlier_version(dsname,
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 11007
diff changeset
  3153
			    SPA_VERSION_GZIP_COMPRESSION)) {
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 11007
diff changeset
  3154
				return (ENOTSUP);
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 11007
diff changeset
  3155
			}
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 11007
diff changeset
  3156
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 11007
diff changeset
  3157
			if (intval == ZIO_COMPRESS_ZLE &&
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 11007
diff changeset
  3158
			    zfs_earlier_version(dsname,
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 11007
diff changeset
  3159
			    SPA_VERSION_ZLE_COMPRESSION))
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 11007
diff changeset
  3160
				return (ENOTSUP);
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 11007
diff changeset
  3161
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 11007
diff changeset
  3162
			/*
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 11007
diff changeset
  3163
			 * If this is a bootable dataset then
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 11007
diff changeset
  3164
			 * verify that the compression algorithm
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 11007
diff changeset
  3165
			 * is supported for booting. We must return
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 11007
diff changeset
  3166
			 * something other than ENOTSUP since it
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 11007
diff changeset
  3167
			 * implies a downrev pool version.
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 11007
diff changeset
  3168
			 */
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 11007
diff changeset
  3169
			if (zfs_is_bootfs(dsname) &&
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 11007
diff changeset
  3170
			    !BOOTFS_COMPRESS_VALID(intval)) {
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 11007
diff changeset
  3171
				return (ERANGE);
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 11007
diff changeset
  3172
			}
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 11007
diff changeset
  3173
		}
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 11007
diff changeset
  3174
		break;
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 11007
diff changeset
  3175
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 11007
diff changeset
  3176
	case ZFS_PROP_COPIES:
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 11007
diff changeset
  3177
		if (zfs_earlier_version(dsname, SPA_VERSION_DITTO_BLOCKS))
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 11007
diff changeset
  3178
			return (ENOTSUP);
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 11007
diff changeset
  3179
		break;
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 11007
diff changeset
  3180
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 11007
diff changeset
  3181
	case ZFS_PROP_DEDUP:
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 11007
diff changeset
  3182
		if (zfs_earlier_version(dsname, SPA_VERSION_DEDUP))
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 11007
diff changeset
  3183
			return (ENOTSUP);
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 11007
diff changeset
  3184
		break;
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 11007
diff changeset
  3185
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 11007
diff changeset
  3186
	case ZFS_PROP_SHARESMB:
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 11007
diff changeset
  3187
		if (zpl_earlier_version(dsname, ZPL_VERSION_FUID))
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 11007
diff changeset
  3188
			return (ENOTSUP);
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 11007
diff changeset
  3189
		break;
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 11007
diff changeset
  3190
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 11007
diff changeset
  3191
	case ZFS_PROP_ACLINHERIT:
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 11007
diff changeset
  3192
		if (nvpair_type(pair) == DATA_TYPE_UINT64 &&
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 11007
diff changeset
  3193
		    nvpair_value_uint64(pair, &intval) == 0) {
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 11007
diff changeset
  3194
			if (intval == ZFS_ACL_PASSTHROUGH_X &&
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 11007
diff changeset
  3195
			    zfs_earlier_version(dsname,
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 11007
diff changeset
  3196
			    SPA_VERSION_PASSTHROUGH_X))
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 11007
diff changeset
  3197
				return (ENOTSUP);
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 11007
diff changeset
  3198
		}
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 11007
diff changeset
  3199
		break;
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 11007
diff changeset
  3200
	}
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 11007
diff changeset
  3201
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 11007
diff changeset
  3202
	return (zfs_secpolicy_setprop(dsname, prop, pair, CRED()));
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 11007
diff changeset
  3203
}
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 11007
diff changeset
  3204
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 11007
diff changeset
  3205
/*
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 11007
diff changeset
  3206
 * Removes properties from the given props list that fail permission checks
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 11007
diff changeset
  3207
 * needed to clear them and to restore them in case of a receive error. For each
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 11007
diff changeset
  3208
 * property, make sure we have both set and inherit permissions.
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 11007
diff changeset
  3209
 *
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 11007
diff changeset
  3210
 * Returns the first error encountered if any permission checks fail. If the
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 11007
diff changeset
  3211
 * caller provides a non-NULL errlist, it also gives the complete list of names
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 11007
diff changeset
  3212
 * of all the properties that failed a permission check along with the
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 11007
diff changeset
  3213
 * corresponding error numbers. The caller is responsible for freeing the
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 11007
diff changeset
  3214
 * returned errlist.
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 11007
diff changeset
  3215
 *
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 11007
diff changeset
  3216
 * If every property checks out successfully, zero is returned and the list
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 11007
diff changeset
  3217
 * pointed at by errlist is NULL.
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 11007
diff changeset
  3218
 */
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 11007
diff changeset
  3219
static int
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 11007
diff changeset
  3220
zfs_check_clearable(char *dataset, nvlist_t *props, nvlist_t **errlist)
6689
47572a2f5e73 6610506 Eliminate or improve retry logic from callers of dmu_objset_open()
maybee
parents: 6643
diff changeset
  3221
{
47572a2f5e73 6610506 Eliminate or improve retry logic from callers of dmu_objset_open()
maybee
parents: 6643
diff changeset
  3222
	zfs_cmd_t *zc;
11022
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 11007
diff changeset
  3223
	nvpair_t *pair, *next_pair;
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 11007
diff changeset
  3224
	nvlist_t *errors;
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 11007
diff changeset
  3225
	int err, rv = 0;
6689
47572a2f5e73 6610506 Eliminate or improve retry logic from callers of dmu_objset_open()
maybee
parents: 6643
diff changeset
  3226
47572a2f5e73 6610506 Eliminate or improve retry logic from callers of dmu_objset_open()
maybee
parents: 6643
diff changeset
  3227
	if (props == NULL)
11022
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 11007
diff changeset
  3228
		return (0);
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 11007
diff changeset
  3229
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 11007
diff changeset
  3230
	VERIFY(nvlist_alloc(&errors, NV_UNIQUE_NAME, KM_SLEEP) == 0);
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 11007
diff changeset
  3231
6689
47572a2f5e73 6610506 Eliminate or improve retry logic from callers of dmu_objset_open()
maybee
parents: 6643
diff changeset
  3232
	zc = kmem_alloc(sizeof (zfs_cmd_t), KM_SLEEP);
47572a2f5e73 6610506 Eliminate or improve retry logic from callers of dmu_objset_open()
maybee
parents: 6643
diff changeset
  3233
	(void) strcpy(zc->zc_name, dataset);
11022
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 11007
diff changeset
  3234
	pair = nvlist_next_nvpair(props, NULL);
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 11007
diff changeset
  3235
	while (pair != NULL) {
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 11007
diff changeset
  3236
		next_pair = nvlist_next_nvpair(props, pair);
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 11007
diff changeset
  3237
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 11007
diff changeset
  3238
		(void) strcpy(zc->zc_value, nvpair_name(pair));
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 11007
diff changeset
  3239
		if ((err = zfs_check_settable(dataset, pair, CRED())) != 0 ||
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 11007
diff changeset
  3240
		    (err = zfs_secpolicy_inherit(zc, CRED())) != 0) {
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 11007
diff changeset
  3241
			VERIFY(nvlist_remove_nvpair(props, pair) == 0);
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 11007
diff changeset
  3242
			VERIFY(nvlist_add_int32(errors,
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 11007
diff changeset
  3243
			    zc->zc_value, err) == 0);
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 11007
diff changeset
  3244
		}
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 11007
diff changeset
  3245
		pair = next_pair;
6689
47572a2f5e73 6610506 Eliminate or improve retry logic from callers of dmu_objset_open()
maybee
parents: 6643
diff changeset
  3246
	}
47572a2f5e73 6610506 Eliminate or improve retry logic from callers of dmu_objset_open()
maybee
parents: 6643
diff changeset
  3247
	kmem_free(zc, sizeof (zfs_cmd_t));
11022
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 11007
diff changeset
  3248
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 11007
diff changeset
  3249
	if ((pair = nvlist_next_nvpair(errors, NULL)) == NULL) {
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 11007
diff changeset
  3250
		nvlist_free(errors);
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 11007
diff changeset
  3251
		errors = NULL;
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 11007
diff changeset
  3252
	} else {
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 11007
diff changeset
  3253
		VERIFY(nvpair_value_int32(pair, &rv) == 0);
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 11007
diff changeset
  3254
	}
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 11007
diff changeset
  3255
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 11007
diff changeset
  3256
	if (errlist == NULL)
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 11007
diff changeset
  3257
		nvlist_free(errors);
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 11007
diff changeset
  3258
	else
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 11007
diff changeset
  3259
		*errlist = errors;
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 11007
diff changeset
  3260
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 11007
diff changeset
  3261
	return (rv);
6689
47572a2f5e73 6610506 Eliminate or improve retry logic from callers of dmu_objset_open()
maybee
parents: 6643
diff changeset
  3262
}
47572a2f5e73 6610506 Eliminate or improve retry logic from callers of dmu_objset_open()
maybee
parents: 6643
diff changeset
  3263
11022
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 11007
diff changeset
  3264
static boolean_t
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 11007
diff changeset
  3265
propval_equals(nvpair_t *p1, nvpair_t *p2)
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 11007
diff changeset
  3266
{
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 11007
diff changeset
  3267
	if (nvpair_type(p1) == DATA_TYPE_NVLIST) {
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 11007
diff changeset
  3268
		/* dsl_prop_get_all_impl() format */
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 11007
diff changeset
  3269
		nvlist_t *attrs;
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 11007
diff changeset
  3270
		VERIFY(nvpair_value_nvlist(p1, &attrs) == 0);
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 11007
diff changeset
  3271
		VERIFY(nvlist_lookup_nvpair(attrs, ZPROP_VALUE,
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 11007
diff changeset
  3272
		    &p1) == 0);
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 11007
diff changeset
  3273
	}
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 11007
diff changeset
  3274
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 11007
diff changeset
  3275
	if (nvpair_type(p2) == DATA_TYPE_NVLIST) {
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 11007
diff changeset
  3276
		nvlist_t *attrs;
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 11007
diff changeset
  3277
		VERIFY(nvpair_value_nvlist(p2, &attrs) == 0);
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 11007
diff changeset
  3278
		VERIFY(nvlist_lookup_nvpair(attrs, ZPROP_VALUE,
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 11007
diff changeset
  3279
		    &p2) == 0);
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 11007
diff changeset
  3280
	}
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 11007
diff changeset
  3281
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 11007
diff changeset
  3282
	if (nvpair_type(p1) != nvpair_type(p2))
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 11007
diff changeset
  3283
		return (B_FALSE);
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 11007
diff changeset
  3284
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 11007
diff changeset
  3285
	if (nvpair_type(p1) == DATA_TYPE_STRING) {
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 11007
diff changeset
  3286
		char *valstr1, *valstr2;
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 11007
diff changeset
  3287
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 11007
diff changeset
  3288
		VERIFY(nvpair_value_string(p1, (char **)&valstr1) == 0);
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 11007
diff changeset
  3289
		VERIFY(nvpair_value_string(p2, (char **)&valstr2) == 0);
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 11007
diff changeset
  3290
		return (strcmp(valstr1, valstr2) == 0);
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 11007
diff changeset
  3291
	} else {
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 11007
diff changeset
  3292
		uint64_t intval1, intval2;
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 11007
diff changeset
  3293
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 11007
diff changeset
  3294
		VERIFY(nvpair_value_uint64(p1, &intval1) == 0);
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 11007
diff changeset
  3295
		VERIFY(nvpair_value_uint64(p2, &intval2) == 0);
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 11007
diff changeset
  3296
		return (intval1 == intval2);
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 11007
diff changeset
  3297
	}
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 11007
diff changeset
  3298
}
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 11007
diff changeset
  3299
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 11007
diff changeset
  3300
/*
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 11007
diff changeset
  3301
 * Remove properties from props if they are not going to change (as determined
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 11007
diff changeset
  3302
 * by comparison with origprops). Remove them from origprops as well, since we
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 11007
diff changeset
  3303
 * do not need to clear or restore properties that won't change.
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 11007
diff changeset
  3304
 */
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 11007
diff changeset
  3305
static void
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 11007
diff changeset
  3306
props_reduce(nvlist_t *props, nvlist_t *origprops)
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 11007
diff changeset
  3307
{
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 11007
diff changeset
  3308
	nvpair_t *pair, *next_pair;
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 11007
diff changeset
  3309
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 11007
diff changeset
  3310
	if (origprops == NULL)
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 11007
diff changeset
  3311
		return; /* all props need to be received */
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 11007
diff changeset
  3312
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 11007
diff changeset
  3313
	pair = nvlist_next_nvpair(props, NULL);
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 11007
diff changeset
  3314
	while (pair != NULL) {
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 11007
diff changeset
  3315
		const char *propname = nvpair_name(pair);
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 11007
diff changeset
  3316
		nvpair_t *match;
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 11007
diff changeset
  3317
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 11007
diff changeset
  3318
		next_pair = nvlist_next_nvpair(props, pair);
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 11007
diff changeset
  3319
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 11007
diff changeset
  3320
		if ((nvlist_lookup_nvpair(origprops, propname,
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 11007
diff changeset
  3321
		    &match) != 0) || !propval_equals(pair, match))
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 11007
diff changeset
  3322
			goto next; /* need to set received value */
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 11007
diff changeset
  3323
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 11007
diff changeset
  3324
		/* don't clear the existing received value */
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 11007
diff changeset
  3325
		(void) nvlist_remove_nvpair(origprops, match);
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 11007
diff changeset
  3326
		/* don't bother receiving the property */
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 11007
diff changeset
  3327
		(void) nvlist_remove_nvpair(props, pair);
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 11007
diff changeset
  3328
next:
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 11007
diff changeset
  3329
		pair = next_pair;
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 11007
diff changeset
  3330
	}
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 11007
diff changeset
  3331
}
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 11007
diff changeset
  3332
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 11007
diff changeset
  3333
#ifdef	DEBUG
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 11007
diff changeset
  3334
static boolean_t zfs_ioc_recv_inject_err;
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 11007
diff changeset
  3335
#endif
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 11007
diff changeset
  3336
5367
c40abbe796be PSARC/2007/574 zfs send -R
ahrens
parents: 5331
diff changeset
  3337
/*
c40abbe796be PSARC/2007/574 zfs send -R
ahrens
parents: 5331
diff changeset
  3338
 * inputs:
c40abbe796be PSARC/2007/574 zfs send -R
ahrens
parents: 5331
diff changeset
  3339
 * zc_name		name of containing filesystem
c40abbe796be PSARC/2007/574 zfs send -R
ahrens
parents: 5331
diff changeset
  3340
 * zc_nvlist_src{_size}	nvlist of properties to apply
c40abbe796be PSARC/2007/574 zfs send -R
ahrens
parents: 5331
diff changeset
  3341
 * zc_value		name of snapshot to create
c40abbe796be PSARC/2007/574 zfs send -R
ahrens
parents: 5331
diff changeset
  3342
 * zc_string		name of clone origin (if DRR_FLAG_CLONE)
c40abbe796be PSARC/2007/574 zfs send -R
ahrens
parents: 5331
diff changeset
  3343
 * zc_cookie		file descriptor to recv from
c40abbe796be PSARC/2007/574 zfs send -R
ahrens
parents: 5331
diff changeset
  3344
 * zc_begin_record	the BEGIN record of the stream (not byteswapped)
c40abbe796be PSARC/2007/574 zfs send -R
ahrens
parents: 5331
diff changeset
  3345
 * zc_guid		force flag
12527
693dd2cad55f 6884007 zfs_send() can leave temporary holds around
Chris Kirby <Chris.Kirby@oracle.com>
parents: 12296
diff changeset
  3346
 * zc_cleanup_fd	cleanup-on-exit file descriptor
693dd2cad55f 6884007 zfs_send() can leave temporary holds around
Chris Kirby <Chris.Kirby@oracle.com>
parents: 12296
diff changeset
  3347
 * zc_action_handle	handle for this guid/ds mapping (or zero on first call)
5367
c40abbe796be PSARC/2007/574 zfs send -R
ahrens
parents: 5331
diff changeset
  3348
 *
c40abbe796be PSARC/2007/574 zfs send -R
ahrens
parents: 5331
diff changeset
  3349
 * outputs:
c40abbe796be PSARC/2007/574 zfs send -R
ahrens
parents: 5331
diff changeset
  3350
 * zc_cookie		number of bytes read
11022
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 11007
diff changeset
  3351
 * zc_nvlist_dst{_size} error for each unapplied received property
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 11007
diff changeset
  3352
 * zc_obj		zprop_errflags_t
12527
693dd2cad55f 6884007 zfs_send() can leave temporary holds around
Chris Kirby <Chris.Kirby@oracle.com>
parents: 12296
diff changeset
  3353
 * zc_action_handle	handle for this guid/ds mapping
5367
c40abbe796be PSARC/2007/574 zfs send -R
ahrens
parents: 5331
diff changeset
  3354
 */
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3355
static int
5367
c40abbe796be PSARC/2007/574 zfs send -R
ahrens
parents: 5331
diff changeset
  3356
zfs_ioc_recv(zfs_cmd_t *zc)
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3357
{
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3358
	file_t *fp;
5326
6752aa2bd5bc 6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents: 5147
diff changeset
  3359
	objset_t *os;
5367
c40abbe796be PSARC/2007/574 zfs send -R
ahrens
parents: 5331
diff changeset
  3360
	dmu_recv_cookie_t drc;
5326
6752aa2bd5bc 6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents: 5147
diff changeset
  3361
	boolean_t force = (boolean_t)zc->zc_guid;
11022
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 11007
diff changeset
  3362
	int fd;
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 11007
diff changeset
  3363
	int error = 0;
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 11007
diff changeset
  3364
	int props_error = 0;
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 11007
diff changeset
  3365
	nvlist_t *errors;
5367
c40abbe796be PSARC/2007/574 zfs send -R
ahrens
parents: 5331
diff changeset
  3366
	offset_t off;
11022
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 11007
diff changeset
  3367
	nvlist_t *props = NULL; /* sent properties */
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 11007
diff changeset
  3368
	nvlist_t *origprops = NULL; /* existing properties */
5367
c40abbe796be PSARC/2007/574 zfs send -R
ahrens
parents: 5331
diff changeset
  3369
	objset_t *origin = NULL;
c40abbe796be PSARC/2007/574 zfs send -R
ahrens
parents: 5331
diff changeset
  3370
	char *tosnap;
c40abbe796be PSARC/2007/574 zfs send -R
ahrens
parents: 5331
diff changeset
  3371
	char tofs[ZFS_MAXNAMELEN];
11022
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 11007
diff changeset
  3372
	boolean_t first_recvd_props = B_FALSE;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3373
3265
967e0fca6143 6463140 zfs recv with a snapshot name that has 2 @@ in a row succeeds
ahrens
parents: 3087
diff changeset
  3374
	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
  3375
	    strchr(zc->zc_value, '@') == NULL ||
6752aa2bd5bc 6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents: 5147
diff changeset
  3376
	    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
  3377
		return (EINVAL);
967e0fca6143 6463140 zfs recv with a snapshot name that has 2 @@ in a row succeeds
ahrens
parents: 3087
diff changeset
  3378
5367
c40abbe796be PSARC/2007/574 zfs send -R
ahrens
parents: 5331
diff changeset
  3379
	(void) strcpy(tofs, zc->zc_value);
c40abbe796be PSARC/2007/574 zfs send -R
ahrens
parents: 5331
diff changeset
  3380
	tosnap = strchr(tofs, '@');
11022
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 11007
diff changeset
  3381
	*tosnap++ = '\0';
5367
c40abbe796be PSARC/2007/574 zfs send -R
ahrens
parents: 5331
diff changeset
  3382
c40abbe796be PSARC/2007/574 zfs send -R
ahrens
parents: 5331
diff changeset
  3383
	if (zc->zc_nvlist_src != NULL &&
c40abbe796be PSARC/2007/574 zfs send -R
ahrens
parents: 5331
diff changeset
  3384
	    (error = get_nvlist(zc->zc_nvlist_src, zc->zc_nvlist_src_size,
9643
ffd8e7765f02 6736004 zvols need an additional property for comstar support
Eric Taylor <Eric.Taylor@Sun.COM>
parents: 9425
diff changeset
  3385
	    zc->zc_iflags, &props)) != 0)
5367
c40abbe796be PSARC/2007/574 zfs send -R
ahrens
parents: 5331
diff changeset
  3386
		return (error);
c40abbe796be PSARC/2007/574 zfs send -R
ahrens
parents: 5331
diff changeset
  3387
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3388
	fd = zc->zc_cookie;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3389
	fp = getf(fd);
5367
c40abbe796be PSARC/2007/574 zfs send -R
ahrens
parents: 5331
diff changeset
  3390
	if (fp == NULL) {
c40abbe796be PSARC/2007/574 zfs send -R
ahrens
parents: 5331
diff changeset
  3391
		nvlist_free(props);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3392
		return (EBADF);
5367
c40abbe796be PSARC/2007/574 zfs send -R
ahrens
parents: 5331
diff changeset
  3393
	}
5326
6752aa2bd5bc 6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents: 5147
diff changeset
  3394
11022
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 11007
diff changeset
  3395
	VERIFY(nvlist_alloc(&errors, NV_UNIQUE_NAME, KM_SLEEP) == 0);
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 11007
diff changeset
  3396
10298
a0d52501437c 6860996 %temporary clones are not automatically destroyed on error
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 10272
diff changeset
  3397
	if (props && dmu_objset_hold(tofs, FTAG, &os) == 0) {
11022
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 11007
diff changeset
  3398
		if ((spa_version(os->os_spa) >= SPA_VERSION_RECVD_PROPS) &&
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 11007
diff changeset
  3399
		    !dsl_prop_get_hasrecvd(os)) {
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 11007
diff changeset
  3400
			first_recvd_props = B_TRUE;
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 11007
diff changeset
  3401
		}
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 11007
diff changeset
  3402
6689
47572a2f5e73 6610506 Eliminate or improve retry logic from callers of dmu_objset_open()
maybee
parents: 6643
diff changeset
  3403
		/*
11022
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 11007
diff changeset
  3404
		 * If new received properties are supplied, they are to
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 11007
diff changeset
  3405
		 * completely replace the existing received properties, so stash
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 11007
diff changeset
  3406
		 * away the existing ones.
6689
47572a2f5e73 6610506 Eliminate or improve retry logic from callers of dmu_objset_open()
maybee
parents: 6643
diff changeset
  3407
		 */
11022
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 11007
diff changeset
  3408
		if (dsl_prop_get_received(os, &origprops) == 0) {
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 11007
diff changeset
  3409
			nvlist_t *errlist = NULL;
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 11007
diff changeset
  3410
			/*
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 11007
diff changeset
  3411
			 * Don't bother writing a property if its value won't
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 11007
diff changeset
  3412
			 * change (and avoid the unnecessary security checks).
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 11007
diff changeset
  3413
			 *
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 11007
diff changeset
  3414
			 * The first receive after SPA_VERSION_RECVD_PROPS is a
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 11007
diff changeset
  3415
			 * special case where we blow away all local properties
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 11007
diff changeset
  3416
			 * regardless.
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 11007
diff changeset
  3417
			 */
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 11007
diff changeset
  3418
			if (!first_recvd_props)
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 11007
diff changeset
  3419
				props_reduce(props, origprops);
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 11007
diff changeset
  3420
			if (zfs_check_clearable(tofs, origprops,
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 11007
diff changeset
  3421
			    &errlist) != 0)
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 11007
diff changeset
  3422
				(void) nvlist_merge(errors, errlist, 0);
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 11007
diff changeset
  3423
			nvlist_free(errlist);
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 11007
diff changeset
  3424
		}
10298
a0d52501437c 6860996 %temporary clones are not automatically destroyed on error
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 10272
diff changeset
  3425
a0d52501437c 6860996 %temporary clones are not automatically destroyed on error
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 10272
diff changeset
  3426
		dmu_objset_rele(os, FTAG);
5326
6752aa2bd5bc 6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents: 5147
diff changeset
  3427
	}
6752aa2bd5bc 6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents: 5147
diff changeset
  3428
5367
c40abbe796be PSARC/2007/574 zfs send -R
ahrens
parents: 5331
diff changeset
  3429
	if (zc->zc_string[0]) {
10298
a0d52501437c 6860996 %temporary clones are not automatically destroyed on error
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 10272
diff changeset
  3430
		error = dmu_objset_hold(zc->zc_string, FTAG, &origin);
6689
47572a2f5e73 6610506 Eliminate or improve retry logic from callers of dmu_objset_open()
maybee
parents: 6643
diff changeset
  3431
		if (error)
47572a2f5e73 6610506 Eliminate or improve retry logic from callers of dmu_objset_open()
maybee
parents: 6643
diff changeset
  3432
			goto out;
5367
c40abbe796be PSARC/2007/574 zfs send -R
ahrens
parents: 5331
diff changeset
  3433
	}
c40abbe796be PSARC/2007/574 zfs send -R
ahrens
parents: 5331
diff changeset
  3434
11007
216d8396182e PSARC/2009/557 ZFS send dedup
Lori Alt <Lori.Alt@Sun.COM>
parents: 10972
diff changeset
  3435
	error = dmu_recv_begin(tofs, tosnap, zc->zc_top_ds,
216d8396182e PSARC/2009/557 ZFS send dedup
Lori Alt <Lori.Alt@Sun.COM>
parents: 10972
diff changeset
  3436
	    &zc->zc_begin_record, force, origin, &drc);
5367
c40abbe796be PSARC/2007/574 zfs send -R
ahrens
parents: 5331
diff changeset
  3437
	if (origin)
10298
a0d52501437c 6860996 %temporary clones are not automatically destroyed on error
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 10272
diff changeset
  3438
		dmu_objset_rele(origin, FTAG);
6689
47572a2f5e73 6610506 Eliminate or improve retry logic from callers of dmu_objset_open()
maybee
parents: 6643
diff changeset
  3439
	if (error)
47572a2f5e73 6610506 Eliminate or improve retry logic from callers of dmu_objset_open()
maybee
parents: 6643
diff changeset
  3440
		goto out;
5326
6752aa2bd5bc 6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents: 5147
diff changeset
  3441
6752aa2bd5bc 6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents: 5147
diff changeset
  3442
	/*
11022
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 11007
diff changeset
  3443
	 * Set properties before we receive the stream so that they are applied
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 11007
diff changeset
  3444
	 * to the new data. Note that we must call dmu_recv_stream() if
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 11007
diff changeset
  3445
	 * dmu_recv_begin() succeeds.
5326
6752aa2bd5bc 6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents: 5147
diff changeset
  3446
	 */
5367
c40abbe796be PSARC/2007/574 zfs send -R
ahrens
parents: 5331
diff changeset
  3447
	if (props) {
11022
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 11007
diff changeset
  3448
		nvlist_t *errlist;
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 11007
diff changeset
  3449
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 11007
diff changeset
  3450
		if (dmu_objset_from_ds(drc.drc_logical_ds, &os) == 0) {
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 11007
diff changeset
  3451
			if (drc.drc_newfs) {
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 11007
diff changeset
  3452
				if (spa_version(os->os_spa) >=
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 11007
diff changeset
  3453
				    SPA_VERSION_RECVD_PROPS)
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 11007
diff changeset
  3454
					first_recvd_props = B_TRUE;
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 11007
diff changeset
  3455
			} else if (origprops != NULL) {
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 11007
diff changeset
  3456
				if (clear_received_props(os, tofs, origprops,
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 11007
diff changeset
  3457
				    first_recvd_props ? NULL : props) != 0)
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 11007
diff changeset
  3458
					zc->zc_obj |= ZPROP_ERR_NOCLEAR;
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 11007
diff changeset
  3459
			} else {
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 11007
diff changeset
  3460
				zc->zc_obj |= ZPROP_ERR_NOCLEAR;
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 11007
diff changeset
  3461
			}
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 11007
diff changeset
  3462
			dsl_prop_set_hasrecvd(os);
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 11007
diff changeset
  3463
		} else if (!drc.drc_newfs) {
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 11007
diff changeset
  3464
			zc->zc_obj |= ZPROP_ERR_NOCLEAR;
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 11007
diff changeset
  3465
		}
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 11007
diff changeset
  3466
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 11007
diff changeset
  3467
		(void) zfs_set_prop_nvlist(tofs, ZPROP_SRC_RECEIVED,
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 11007
diff changeset
  3468
		    props, &errlist);
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 11007
diff changeset
  3469
		(void) nvlist_merge(errors, errlist, 0);
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 11007
diff changeset
  3470
		nvlist_free(errlist);
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 11007
diff changeset
  3471
	}
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 11007
diff changeset
  3472
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 11007
diff changeset
  3473
	if (fit_error_list(zc, &errors) != 0 || put_nvlist(zc, errors) != 0) {
6689
47572a2f5e73 6610506 Eliminate or improve retry logic from callers of dmu_objset_open()
maybee
parents: 6643
diff changeset
  3474
		/*
11022
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 11007
diff changeset
  3475
		 * Caller made zc->zc_nvlist_dst less than the minimum expected
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 11007
diff changeset
  3476
		 * size or supplied an invalid address.
6689
47572a2f5e73 6610506 Eliminate or improve retry logic from callers of dmu_objset_open()
maybee
parents: 6643
diff changeset
  3477
		 */
11022
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 11007
diff changeset
  3478
		props_error = EINVAL;
5367
c40abbe796be PSARC/2007/574 zfs send -R
ahrens
parents: 5331
diff changeset
  3479
	}
c40abbe796be PSARC/2007/574 zfs send -R
ahrens
parents: 5331
diff changeset
  3480
c40abbe796be PSARC/2007/574 zfs send -R
ahrens
parents: 5331
diff changeset
  3481
	off = fp->f_offset;
12527
693dd2cad55f 6884007 zfs_send() can leave temporary holds around
Chris Kirby <Chris.Kirby@oracle.com>
parents: 12296
diff changeset
  3482
	error = dmu_recv_stream(&drc, fp->f_vnode, &off, zc->zc_cleanup_fd,
693dd2cad55f 6884007 zfs_send() can leave temporary holds around
Chris Kirby <Chris.Kirby@oracle.com>
parents: 12296
diff changeset
  3483
	    &zc->zc_action_handle);
5367
c40abbe796be PSARC/2007/574 zfs send -R
ahrens
parents: 5331
diff changeset
  3484
10204
83c3a84aecef 6760420 zfs unmount -f causes recv to fail
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 9643
diff changeset
  3485
	if (error == 0) {
83c3a84aecef 6760420 zfs unmount -f causes recv to fail
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 9643
diff changeset
  3486
		zfsvfs_t *zfsvfs = NULL;
83c3a84aecef 6760420 zfs unmount -f causes recv to fail
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 9643
diff changeset
  3487
83c3a84aecef 6760420 zfs unmount -f causes recv to fail
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 9643
diff changeset
  3488
		if (getzfsvfs(tofs, &zfsvfs) == 0) {
83c3a84aecef 6760420 zfs unmount -f causes recv to fail
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 9643
diff changeset
  3489
			/* online recv */
83c3a84aecef 6760420 zfs unmount -f causes recv to fail
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 9643
diff changeset
  3490
			int end_err;
10298
a0d52501437c 6860996 %temporary clones are not automatically destroyed on error
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 10272
diff changeset
  3491
a0d52501437c 6860996 %temporary clones are not automatically destroyed on error
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 10272
diff changeset
  3492
			error = zfs_suspend_fs(zfsvfs);
10204
83c3a84aecef 6760420 zfs unmount -f causes recv to fail
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 9643
diff changeset
  3493
			/*
83c3a84aecef 6760420 zfs unmount -f causes recv to fail
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 9643
diff changeset
  3494
			 * If the suspend fails, then the recv_end will
83c3a84aecef 6760420 zfs unmount -f causes recv to fail
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 9643
diff changeset
  3495
			 * likely also fail, and clean up after itself.
83c3a84aecef 6760420 zfs unmount -f causes recv to fail
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 9643
diff changeset
  3496
			 */
83c3a84aecef 6760420 zfs unmount -f causes recv to fail
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 9643
diff changeset
  3497
			end_err = dmu_recv_end(&drc);
11812
453b88fd62f1 6891437 DEADCODE in zfs_ioc_recv after dmu_recv_end.
George Wilson <George.Wilson@Sun.COM>
parents: 11807
diff changeset
  3498
			if (error == 0)
453b88fd62f1 6891437 DEADCODE in zfs_ioc_recv after dmu_recv_end.
George Wilson <George.Wilson@Sun.COM>
parents: 11807
diff changeset
  3499
				error = zfs_resume_fs(zfsvfs, tofs);
10204
83c3a84aecef 6760420 zfs unmount -f causes recv to fail
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 9643
diff changeset
  3500
			error = error ? error : end_err;
83c3a84aecef 6760420 zfs unmount -f causes recv to fail
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 9643
diff changeset
  3501
			VFS_RELE(zfsvfs->z_vfs);
83c3a84aecef 6760420 zfs unmount -f causes recv to fail
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 9643
diff changeset
  3502
		} else {
6689
47572a2f5e73 6610506 Eliminate or improve retry logic from callers of dmu_objset_open()
maybee
parents: 6643
diff changeset
  3503
			error = dmu_recv_end(&drc);
5367
c40abbe796be PSARC/2007/574 zfs send -R
ahrens
parents: 5331
diff changeset
  3504
		}
6083
23e77aa611b1 6655963 Panic: 0 == zap_add(mos, pds->dd_phys->dd_child_dir_zapobj, name, sizeof (uint64_t), 1, &ddobj, tx)
ek110237
parents: 5977
diff changeset
  3505
	}
5367
c40abbe796be PSARC/2007/574 zfs send -R
ahrens
parents: 5331
diff changeset
  3506
c40abbe796be PSARC/2007/574 zfs send -R
ahrens
parents: 5331
diff changeset
  3507
	zc->zc_cookie = off - fp->f_offset;
c40abbe796be PSARC/2007/574 zfs send -R
ahrens
parents: 5331
diff changeset
  3508
	if (VOP_SEEK(fp->f_vnode, fp->f_offset, &off, NULL) == 0)
c40abbe796be PSARC/2007/574 zfs send -R
ahrens
parents: 5331
diff changeset
  3509
		fp->f_offset = off;
2885
c0259887ebbc 6460059 zfs destroy <snapshot> leaves behind kruft
ahrens
parents: 2856
diff changeset
  3510
11022
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 11007
diff changeset
  3511
#ifdef	DEBUG
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 11007
diff changeset
  3512
	if (zfs_ioc_recv_inject_err) {
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 11007
diff changeset
  3513
		zfs_ioc_recv_inject_err = B_FALSE;
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 11007
diff changeset
  3514
		error = 1;
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 11007
diff changeset
  3515
	}
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 11007
diff changeset
  3516
#endif
6689
47572a2f5e73 6610506 Eliminate or improve retry logic from callers of dmu_objset_open()
maybee
parents: 6643
diff changeset
  3517
	/*
47572a2f5e73 6610506 Eliminate or improve retry logic from callers of dmu_objset_open()
maybee
parents: 6643
diff changeset
  3518
	 * On error, restore the original props.
47572a2f5e73 6610506 Eliminate or improve retry logic from callers of dmu_objset_open()
maybee
parents: 6643
diff changeset
  3519
	 */
47572a2f5e73 6610506 Eliminate or improve retry logic from callers of dmu_objset_open()
maybee
parents: 6643
diff changeset
  3520
	if (error && props) {
11022
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 11007
diff changeset
  3521
		if (dmu_objset_hold(tofs, FTAG, &os) == 0) {
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 11007
diff changeset
  3522
			if (clear_received_props(os, tofs, props, NULL) != 0) {
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 11007
diff changeset
  3523
				/*
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 11007
diff changeset
  3524
				 * We failed to clear the received properties.
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 11007
diff changeset
  3525
				 * Since we may have left a $recvd value on the
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 11007
diff changeset
  3526
				 * system, we can't clear the $hasrecvd flag.
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 11007
diff changeset
  3527
				 */
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 11007
diff changeset
  3528
				zc->zc_obj |= ZPROP_ERR_NORESTORE;
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 11007
diff changeset
  3529
			} else if (first_recvd_props) {
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 11007
diff changeset
  3530
				dsl_prop_unset_hasrecvd(os);
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 11007
diff changeset
  3531
			}
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 11007
diff changeset
  3532
			dmu_objset_rele(os, FTAG);
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 11007
diff changeset
  3533
		} else if (!drc.drc_newfs) {
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 11007
diff changeset
  3534
			/* We failed to clear the received properties. */
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 11007
diff changeset
  3535
			zc->zc_obj |= ZPROP_ERR_NORESTORE;
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 11007
diff changeset
  3536
		}
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 11007
diff changeset
  3537
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 11007
diff changeset
  3538
		if (origprops == NULL && !drc.drc_newfs) {
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 11007
diff changeset
  3539
			/* We failed to stash the original properties. */
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 11007
diff changeset
  3540
			zc->zc_obj |= ZPROP_ERR_NORESTORE;
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 11007
diff changeset
  3541
		}
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 11007
diff changeset
  3542
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 11007
diff changeset
  3543
		/*
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 11007
diff changeset
  3544
		 * dsl_props_set() will not convert RECEIVED to LOCAL on or
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 11007
diff changeset
  3545
		 * after SPA_VERSION_RECVD_PROPS, so we need to specify LOCAL
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 11007
diff changeset
  3546
		 * explictly if we're restoring local properties cleared in the
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 11007
diff changeset
  3547
		 * first new-style receive.
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 11007
diff changeset
  3548
		 */
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 11007
diff changeset
  3549
		if (origprops != NULL &&
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 11007
diff changeset
  3550
		    zfs_set_prop_nvlist(tofs, (first_recvd_props ?
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 11007
diff changeset
  3551
		    ZPROP_SRC_LOCAL : ZPROP_SRC_RECEIVED),
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 11007
diff changeset
  3552
		    origprops, NULL) != 0) {
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 11007
diff changeset
  3553
			/*
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 11007
diff changeset
  3554
			 * We stashed the original properties but failed to
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 11007
diff changeset
  3555
			 * restore them.
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 11007
diff changeset
  3556
			 */
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 11007
diff changeset
  3557
			zc->zc_obj |= ZPROP_ERR_NORESTORE;
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 11007
diff changeset
  3558
		}
6689
47572a2f5e73 6610506 Eliminate or improve retry logic from callers of dmu_objset_open()
maybee
parents: 6643
diff changeset
  3559
	}
47572a2f5e73 6610506 Eliminate or improve retry logic from callers of dmu_objset_open()
maybee
parents: 6643
diff changeset
  3560
out:
47572a2f5e73 6610506 Eliminate or improve retry logic from callers of dmu_objset_open()
maybee
parents: 6643
diff changeset
  3561
	nvlist_free(props);
47572a2f5e73 6610506 Eliminate or improve retry logic from callers of dmu_objset_open()
maybee
parents: 6643
diff changeset
  3562
	nvlist_free(origprops);
11022
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 11007
diff changeset
  3563
	nvlist_free(errors);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3564
	releasef(fd);
11022
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 11007
diff changeset
  3565
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 11007
diff changeset
  3566
	if (error == 0)
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 11007
diff changeset
  3567
		error = props_error;
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 11007
diff changeset
  3568
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3569
	return (error);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3570
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3571
5367
c40abbe796be PSARC/2007/574 zfs send -R
ahrens
parents: 5331
diff changeset
  3572
/*
c40abbe796be PSARC/2007/574 zfs send -R
ahrens
parents: 5331
diff changeset
  3573
 * inputs:
c40abbe796be PSARC/2007/574 zfs send -R
ahrens
parents: 5331
diff changeset
  3574
 * zc_name	name of snapshot to send
c40abbe796be PSARC/2007/574 zfs send -R
ahrens
parents: 5331
diff changeset
  3575
 * zc_value	short name of incremental fromsnap (may be empty)
c40abbe796be PSARC/2007/574 zfs send -R
ahrens
parents: 5331
diff changeset
  3576
 * zc_cookie	file descriptor to send stream to
c40abbe796be PSARC/2007/574 zfs send -R
ahrens
parents: 5331
diff changeset
  3577
 * zc_obj	fromorigin flag (mutually exclusive with zc_value)
c40abbe796be PSARC/2007/574 zfs send -R
ahrens
parents: 5331
diff changeset
  3578
 *
c40abbe796be PSARC/2007/574 zfs send -R
ahrens
parents: 5331
diff changeset
  3579
 * outputs: none
c40abbe796be PSARC/2007/574 zfs send -R
ahrens
parents: 5331
diff changeset
  3580
 */
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3581
static int
5367
c40abbe796be PSARC/2007/574 zfs send -R
ahrens
parents: 5331
diff changeset
  3582
zfs_ioc_send(zfs_cmd_t *zc)
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3583
{
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3584
	objset_t *fromsnap = NULL;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3585
	objset_t *tosnap;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3586
	file_t *fp;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3587
	int error;
5367
c40abbe796be PSARC/2007/574 zfs send -R
ahrens
parents: 5331
diff changeset
  3588
	offset_t off;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3589
10298
a0d52501437c 6860996 %temporary clones are not automatically destroyed on error
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 10272
diff changeset
  3590
	error = dmu_objset_hold(zc->zc_name, FTAG, &tosnap);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3591
	if (error)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3592
		return (error);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3593
2676
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  3594
	if (zc->zc_value[0] != '\0') {
8012
8ea30813950f 6765626 zfs send takes up too much stack space
Eric Taylor <Eric.Taylor@Sun.COM>
parents: 7754
diff changeset
  3595
		char *buf;
2885
c0259887ebbc 6460059 zfs destroy <snapshot> leaves behind kruft
ahrens
parents: 2856
diff changeset
  3596
		char *cp;
c0259887ebbc 6460059 zfs destroy <snapshot> leaves behind kruft
ahrens
parents: 2856
diff changeset
  3597
8012
8ea30813950f 6765626 zfs send takes up too much stack space
Eric Taylor <Eric.Taylor@Sun.COM>
parents: 7754
diff changeset
  3598
		buf = kmem_alloc(MAXPATHLEN, KM_SLEEP);
8ea30813950f 6765626 zfs send takes up too much stack space
Eric Taylor <Eric.Taylor@Sun.COM>
parents: 7754
diff changeset
  3599
		(void) strncpy(buf, zc->zc_name, MAXPATHLEN);
2885
c0259887ebbc 6460059 zfs destroy <snapshot> leaves behind kruft
ahrens
parents: 2856
diff changeset
  3600
		cp = strchr(buf, '@');
c0259887ebbc 6460059 zfs destroy <snapshot> leaves behind kruft
ahrens
parents: 2856
diff changeset
  3601
		if (cp)
c0259887ebbc 6460059 zfs destroy <snapshot> leaves behind kruft
ahrens
parents: 2856
diff changeset
  3602
			*(cp+1) = 0;
8012
8ea30813950f 6765626 zfs send takes up too much stack space
Eric Taylor <Eric.Taylor@Sun.COM>
parents: 7754
diff changeset
  3603
		(void) strncat(buf, zc->zc_value, MAXPATHLEN);
10298
a0d52501437c 6860996 %temporary clones are not automatically destroyed on error
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 10272
diff changeset
  3604
		error = dmu_objset_hold(buf, FTAG, &fromsnap);
8012
8ea30813950f 6765626 zfs send takes up too much stack space
Eric Taylor <Eric.Taylor@Sun.COM>
parents: 7754
diff changeset
  3605
		kmem_free(buf, MAXPATHLEN);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3606
		if (error) {
10298
a0d52501437c 6860996 %temporary clones are not automatically destroyed on error
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 10272
diff changeset
  3607
			dmu_objset_rele(tosnap, FTAG);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3608
			return (error);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3609
		}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3610
	}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3611
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3612
	fp = getf(zc->zc_cookie);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3613
	if (fp == NULL) {
10298
a0d52501437c 6860996 %temporary clones are not automatically destroyed on error
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 10272
diff changeset
  3614
		dmu_objset_rele(tosnap, FTAG);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3615
		if (fromsnap)
10298
a0d52501437c 6860996 %temporary clones are not automatically destroyed on error
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 10272
diff changeset
  3616
			dmu_objset_rele(fromsnap, FTAG);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3617
		return (EBADF);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3618
	}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3619
5367
c40abbe796be PSARC/2007/574 zfs send -R
ahrens
parents: 5331
diff changeset
  3620
	off = fp->f_offset;
c40abbe796be PSARC/2007/574 zfs send -R
ahrens
parents: 5331
diff changeset
  3621
	error = dmu_sendbackup(tosnap, fromsnap, zc->zc_obj, fp->f_vnode, &off);
c40abbe796be PSARC/2007/574 zfs send -R
ahrens
parents: 5331
diff changeset
  3622
c40abbe796be PSARC/2007/574 zfs send -R
ahrens
parents: 5331
diff changeset
  3623
	if (VOP_SEEK(fp->f_vnode, fp->f_offset, &off, NULL) == 0)
c40abbe796be PSARC/2007/574 zfs send -R
ahrens
parents: 5331
diff changeset
  3624
		fp->f_offset = off;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3625
	releasef(zc->zc_cookie);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3626
	if (fromsnap)
10298
a0d52501437c 6860996 %temporary clones are not automatically destroyed on error
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 10272
diff changeset
  3627
		dmu_objset_rele(fromsnap, FTAG);
a0d52501437c 6860996 %temporary clones are not automatically destroyed on error
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 10272
diff changeset
  3628
	dmu_objset_rele(tosnap, FTAG);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3629
	return (error);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3630
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3631
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
  3632
static int
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
  3633
zfs_ioc_inject_fault(zfs_cmd_t *zc)
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
  3634
{
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
  3635
	int id, error;
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
  3636
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
  3637
	error = zio_inject_fault(zc->zc_name, (int)zc->zc_guid, &id,
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
  3638
	    &zc->zc_inject_record);
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
  3639
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
  3640
	if (error == 0)
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
  3641
		zc->zc_guid = (uint64_t)id;
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
  3642
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
  3643
	return (error);
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
  3644
}
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
  3645
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
  3646
static int
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
  3647
zfs_ioc_clear_fault(zfs_cmd_t *zc)
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
  3648
{
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
  3649
	return (zio_clear_fault((int)zc->zc_guid));
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
  3650
}
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
  3651
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
  3652
static int
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
  3653
zfs_ioc_inject_list_next(zfs_cmd_t *zc)
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
  3654
{
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
  3655
	int id = (int)zc->zc_guid;
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
  3656
	int error;
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
  3657
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
  3658
	error = zio_inject_list_next(&id, zc->zc_name, sizeof (zc->zc_name),
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
  3659
	    &zc->zc_inject_record);
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
  3660
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
  3661
	zc->zc_guid = id;
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
  3662
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
  3663
	return (error);
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
  3664
}
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
  3665
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
  3666
static int
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
  3667
zfs_ioc_error_log(zfs_cmd_t *zc)
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
  3668
{
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
  3669
	spa_t *spa;
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
  3670
	int error;
2676
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  3671
	size_t count = (size_t)zc->zc_nvlist_dst_size;
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
  3672
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
  3673
	if ((error = spa_open(zc->zc_name, &spa, FTAG)) != 0)
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
  3674
		return (error);
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
  3675
2676
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  3676
	error = spa_get_errlog(spa, (void *)(uintptr_t)zc->zc_nvlist_dst,
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
  3677
	    &count);
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
  3678
	if (error == 0)
2676
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  3679
		zc->zc_nvlist_dst_size = count;
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
  3680
	else
2676
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  3681
		zc->zc_nvlist_dst_size = spa_get_errlog_size(spa);
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
  3682
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
  3683
	spa_close(spa, FTAG);
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
  3684
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
  3685
	return (error);
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
  3686
}
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
  3687
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
  3688
static int
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
  3689
zfs_ioc_clear(zfs_cmd_t *zc)
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
  3690
{
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
  3691
	spa_t *spa;
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
  3692
	vdev_t *vd;
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
  3693
	int error;
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
  3694
7294
c9c31ef4c960 PSARC 2008/486 Intent log replay failure handling
perrin
parents: 7265
diff changeset
  3695
	/*
c9c31ef4c960 PSARC 2008/486 Intent log replay failure handling
perrin
parents: 7265
diff changeset
  3696
	 * On zpool clear we also fix up missing slogs
c9c31ef4c960 PSARC 2008/486 Intent log replay failure handling
perrin
parents: 7265
diff changeset
  3697
	 */
c9c31ef4c960 PSARC 2008/486 Intent log replay failure handling
perrin
parents: 7265
diff changeset
  3698
	mutex_enter(&spa_namespace_lock);
c9c31ef4c960 PSARC 2008/486 Intent log replay failure handling
perrin
parents: 7265
diff changeset
  3699
	spa = spa_lookup(zc->zc_name);
c9c31ef4c960 PSARC 2008/486 Intent log replay failure handling
perrin
parents: 7265
diff changeset
  3700
	if (spa == NULL) {
c9c31ef4c960 PSARC 2008/486 Intent log replay failure handling
perrin
parents: 7265
diff changeset
  3701
		mutex_exit(&spa_namespace_lock);
c9c31ef4c960 PSARC 2008/486 Intent log replay failure handling
perrin
parents: 7265
diff changeset
  3702
		return (EIO);
c9c31ef4c960 PSARC 2008/486 Intent log replay failure handling
perrin
parents: 7265
diff changeset
  3703
	}
10922
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
  3704
	if (spa_get_log_state(spa) == SPA_LOG_MISSING) {
7294
c9c31ef4c960 PSARC 2008/486 Intent log replay failure handling
perrin
parents: 7265
diff changeset
  3705
		/* we need to let spa_open/spa_load clear the chains */
10922
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10921
diff changeset
  3706
		spa_set_log_state(spa, SPA_LOG_CLEAR);
7294
c9c31ef4c960 PSARC 2008/486 Intent log replay failure handling
perrin
parents: 7265
diff changeset
  3707
	}
10921
8aac17999e4d PSARC 2009/479 zpool recovery support
Tim Haley <Tim.Haley@Sun.COM>
parents: 10850
diff changeset
  3708
	spa->spa_last_open_failed = 0;
7294
c9c31ef4c960 PSARC 2008/486 Intent log replay failure handling
perrin
parents: 7265
diff changeset
  3709
	mutex_exit(&spa_namespace_lock);
c9c31ef4c960 PSARC 2008/486 Intent log replay failure handling
perrin
parents: 7265
diff changeset
  3710
11727
497d03ab2824 6900971 zdb rewind behavior needs to be revisited
Victor Latushkin <Victor.Latushkin@Sun.COM>
parents: 11546
diff changeset
  3711
	if (zc->zc_cookie & ZPOOL_NO_REWIND) {
10921
8aac17999e4d PSARC 2009/479 zpool recovery support
Tim Haley <Tim.Haley@Sun.COM>
parents: 10850
diff changeset
  3712
		error = spa_open(zc->zc_name, &spa, FTAG);
8aac17999e4d PSARC 2009/479 zpool recovery support
Tim Haley <Tim.Haley@Sun.COM>
parents: 10850
diff changeset
  3713
	} else {
8aac17999e4d PSARC 2009/479 zpool recovery support
Tim Haley <Tim.Haley@Sun.COM>
parents: 10850
diff changeset
  3714
		nvlist_t *policy;
8aac17999e4d PSARC 2009/479 zpool recovery support
Tim Haley <Tim.Haley@Sun.COM>
parents: 10850
diff changeset
  3715
		nvlist_t *config = NULL;
8aac17999e4d PSARC 2009/479 zpool recovery support
Tim Haley <Tim.Haley@Sun.COM>
parents: 10850
diff changeset
  3716
8aac17999e4d PSARC 2009/479 zpool recovery support
Tim Haley <Tim.Haley@Sun.COM>
parents: 10850
diff changeset
  3717
		if (zc->zc_nvlist_src == NULL)
8aac17999e4d PSARC 2009/479 zpool recovery support
Tim Haley <Tim.Haley@Sun.COM>
parents: 10850
diff changeset
  3718
			return (EINVAL);
8aac17999e4d PSARC 2009/479 zpool recovery support
Tim Haley <Tim.Haley@Sun.COM>
parents: 10850
diff changeset
  3719
8aac17999e4d PSARC 2009/479 zpool recovery support
Tim Haley <Tim.Haley@Sun.COM>
parents: 10850
diff changeset
  3720
		if ((error = get_nvlist(zc->zc_nvlist_src,
8aac17999e4d PSARC 2009/479 zpool recovery support
Tim Haley <Tim.Haley@Sun.COM>
parents: 10850
diff changeset
  3721
		    zc->zc_nvlist_src_size, zc->zc_iflags, &policy)) == 0) {
8aac17999e4d PSARC 2009/479 zpool recovery support
Tim Haley <Tim.Haley@Sun.COM>
parents: 10850
diff changeset
  3722
			error = spa_open_rewind(zc->zc_name, &spa, FTAG,
8aac17999e4d PSARC 2009/479 zpool recovery support
Tim Haley <Tim.Haley@Sun.COM>
parents: 10850
diff changeset
  3723
			    policy, &config);
8aac17999e4d PSARC 2009/479 zpool recovery support
Tim Haley <Tim.Haley@Sun.COM>
parents: 10850
diff changeset
  3724
			if (config != NULL) {
8aac17999e4d PSARC 2009/479 zpool recovery support
Tim Haley <Tim.Haley@Sun.COM>
parents: 10850
diff changeset
  3725
				(void) put_nvlist(zc, config);
8aac17999e4d PSARC 2009/479 zpool recovery support
Tim Haley <Tim.Haley@Sun.COM>
parents: 10850
diff changeset
  3726
				nvlist_free(config);
8aac17999e4d PSARC 2009/479 zpool recovery support
Tim Haley <Tim.Haley@Sun.COM>
parents: 10850
diff changeset
  3727
			}
8aac17999e4d PSARC 2009/479 zpool recovery support
Tim Haley <Tim.Haley@Sun.COM>
parents: 10850
diff changeset
  3728
			nvlist_free(policy);
8aac17999e4d PSARC 2009/479 zpool recovery support
Tim Haley <Tim.Haley@Sun.COM>
parents: 10850
diff changeset
  3729
		}
8aac17999e4d PSARC 2009/479 zpool recovery support
Tim Haley <Tim.Haley@Sun.COM>
parents: 10850
diff changeset
  3730
	}
8aac17999e4d PSARC 2009/479 zpool recovery support
Tim Haley <Tim.Haley@Sun.COM>
parents: 10850
diff changeset
  3731
8aac17999e4d PSARC 2009/479 zpool recovery support
Tim Haley <Tim.Haley@Sun.COM>
parents: 10850
diff changeset
  3732
	if (error)
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
  3733
		return (error);
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
  3734
10685
931790026ac6 6846163 ZFS continues to use faulted logzilla, bringing system to a crawl
George Wilson <George.Wilson@Sun.COM>
parents: 10672
diff changeset
  3735
	spa_vdev_state_enter(spa, SCL_NONE);
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
  3736
2676
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  3737
	if (zc->zc_guid == 0) {
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
  3738
		vd = NULL;
6643
3a34b0dbb107 6625086 changing cachefile doesn't remove old cache on last user
eschrock
parents: 6492
diff changeset
  3739
	} else {
3a34b0dbb107 6625086 changing cachefile doesn't remove old cache on last user
eschrock
parents: 6492
diff changeset
  3740
		vd = spa_lookup_by_guid(spa, zc->zc_guid, B_TRUE);
5450
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5446
diff changeset
  3741
		if (vd == NULL) {
7754
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7656
diff changeset
  3742
			(void) spa_vdev_state_exit(spa, NULL, ENODEV);
5450
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5446
diff changeset
  3743
			spa_close(spa, FTAG);
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5446
diff changeset
  3744
			return (ENODEV);
b25030891c44 PSARC 2007/618 ZFS L2ARC
brendan
parents: 5446
diff changeset
  3745
		}
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
  3746
	}
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
  3747
7754
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7656
diff changeset
  3748
	vdev_clear(spa, vd);
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7656
diff changeset
  3749
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7656
diff changeset
  3750
	(void) spa_vdev_state_exit(spa, NULL, 0);
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7656
diff changeset
  3751
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7656
diff changeset
  3752
	/*
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7656
diff changeset
  3753
	 * Resume any suspended I/Os.
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7656
diff changeset
  3754
	 */
9234
bffdc4fc05c4 6792139 recovering from a suspended pool needs some work
George Wilson <George.Wilson@Sun.COM>
parents: 9179
diff changeset
  3755
	if (zio_resume(spa) != 0)
bffdc4fc05c4 6792139 recovering from a suspended pool needs some work
George Wilson <George.Wilson@Sun.COM>
parents: 9179
diff changeset
  3756
		error = EIO;
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
  3757
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
  3758
	spa_close(spa, FTAG);
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
  3759
9234
bffdc4fc05c4 6792139 recovering from a suspended pool needs some work
George Wilson <George.Wilson@Sun.COM>
parents: 9179
diff changeset
  3760
	return (error);
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
  3761
}
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
  3762
5367
c40abbe796be PSARC/2007/574 zfs send -R
ahrens
parents: 5331
diff changeset
  3763
/*
c40abbe796be PSARC/2007/574 zfs send -R
ahrens
parents: 5331
diff changeset
  3764
 * inputs:
c40abbe796be PSARC/2007/574 zfs send -R
ahrens
parents: 5331
diff changeset
  3765
 * zc_name	name of filesystem
c40abbe796be PSARC/2007/574 zfs send -R
ahrens
parents: 5331
diff changeset
  3766
 * zc_value	name of origin snapshot
c40abbe796be PSARC/2007/574 zfs send -R
ahrens
parents: 5331
diff changeset
  3767
 *
10588
dc03f981ea18 6438937 if 'zfs destroy' fails, it can leave a zvol device link missing
Eric Taylor <Eric.Taylor@Sun.COM>
parents: 10474
diff changeset
  3768
 * outputs:
dc03f981ea18 6438937 if 'zfs destroy' fails, it can leave a zvol device link missing
Eric Taylor <Eric.Taylor@Sun.COM>
parents: 10474
diff changeset
  3769
 * zc_string	name of conflicting snapshot, if there is one
5367
c40abbe796be PSARC/2007/574 zfs send -R
ahrens
parents: 5331
diff changeset
  3770
 */
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
  3771
static int
2082
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1775
diff changeset
  3772
zfs_ioc_promote(zfs_cmd_t *zc)
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1775
diff changeset
  3773
{
2417
694d5de97348 6444346 zfs promote fails in zone
ahrens
parents: 2199
diff changeset
  3774
	char *cp;
694d5de97348 6444346 zfs promote fails in zone
ahrens
parents: 2199
diff changeset
  3775
694d5de97348 6444346 zfs promote fails in zone
ahrens
parents: 2199
diff changeset
  3776
	/*
694d5de97348 6444346 zfs promote fails in zone
ahrens
parents: 2199
diff changeset
  3777
	 * 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
  3778
	 * it's easier.
694d5de97348 6444346 zfs promote fails in zone
ahrens
parents: 2199
diff changeset
  3779
	 */
2676
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  3780
	cp = strchr(zc->zc_value, '@');
2417
694d5de97348 6444346 zfs promote fails in zone
ahrens
parents: 2199
diff changeset
  3781
	if (cp)
694d5de97348 6444346 zfs promote fails in zone
ahrens
parents: 2199
diff changeset
  3782
		*cp = '\0';
2676
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  3783
	(void) dmu_objset_find(zc->zc_value,
2417
694d5de97348 6444346 zfs promote fails in zone
ahrens
parents: 2199
diff changeset
  3784
	    zfs_unmount_snap, NULL, DS_FIND_SNAPSHOTS);
10588
dc03f981ea18 6438937 if 'zfs destroy' fails, it can leave a zvol device link missing
Eric Taylor <Eric.Taylor@Sun.COM>
parents: 10474
diff changeset
  3785
	return (dsl_dataset_promote(zc->zc_name, zc->zc_string));
2082
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1775
diff changeset
  3786
}
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1775
diff changeset
  3787
4543
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  3788
/*
9396
f41cf682d0d3 PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 9355
diff changeset
  3789
 * Retrieve a single {user|group}{used|quota}@... property.
f41cf682d0d3 PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 9355
diff changeset
  3790
 *
f41cf682d0d3 PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 9355
diff changeset
  3791
 * inputs:
f41cf682d0d3 PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 9355
diff changeset
  3792
 * zc_name	name of filesystem
f41cf682d0d3 PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 9355
diff changeset
  3793
 * zc_objset_type zfs_userquota_prop_t
f41cf682d0d3 PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 9355
diff changeset
  3794
 * zc_value	domain name (eg. "S-1-234-567-89")
f41cf682d0d3 PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 9355
diff changeset
  3795
 * zc_guid	RID/UID/GID
f41cf682d0d3 PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 9355
diff changeset
  3796
 *
f41cf682d0d3 PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 9355
diff changeset
  3797
 * outputs:
f41cf682d0d3 PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 9355
diff changeset
  3798
 * zc_cookie	property value
f41cf682d0d3 PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 9355
diff changeset
  3799
 */
f41cf682d0d3 PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 9355
diff changeset
  3800
static int
f41cf682d0d3 PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 9355
diff changeset
  3801
zfs_ioc_userspace_one(zfs_cmd_t *zc)
f41cf682d0d3 PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 9355
diff changeset
  3802
{
f41cf682d0d3 PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 9355
diff changeset
  3803
	zfsvfs_t *zfsvfs;
f41cf682d0d3 PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 9355
diff changeset
  3804
	int error;
f41cf682d0d3 PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 9355
diff changeset
  3805
f41cf682d0d3 PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 9355
diff changeset
  3806
	if (zc->zc_objset_type >= ZFS_NUM_USERQUOTA_PROPS)
f41cf682d0d3 PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 9355
diff changeset
  3807
		return (EINVAL);
f41cf682d0d3 PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 9355
diff changeset
  3808
10298
a0d52501437c 6860996 %temporary clones are not automatically destroyed on error
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 10272
diff changeset
  3809
	error = zfsvfs_hold(zc->zc_name, FTAG, &zfsvfs);
9396
f41cf682d0d3 PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 9355
diff changeset
  3810
	if (error)
f41cf682d0d3 PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 9355
diff changeset
  3811
		return (error);
f41cf682d0d3 PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 9355
diff changeset
  3812
f41cf682d0d3 PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 9355
diff changeset
  3813
	error = zfs_userspace_one(zfsvfs,
f41cf682d0d3 PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 9355
diff changeset
  3814
	    zc->zc_objset_type, zc->zc_value, zc->zc_guid, &zc->zc_cookie);
f41cf682d0d3 PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 9355
diff changeset
  3815
	zfsvfs_rele(zfsvfs, FTAG);
f41cf682d0d3 PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 9355
diff changeset
  3816
f41cf682d0d3 PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 9355
diff changeset
  3817
	return (error);
f41cf682d0d3 PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 9355
diff changeset
  3818
}
f41cf682d0d3 PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 9355
diff changeset
  3819
f41cf682d0d3 PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 9355
diff changeset
  3820
/*
f41cf682d0d3 PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 9355
diff changeset
  3821
 * inputs:
f41cf682d0d3 PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 9355
diff changeset
  3822
 * zc_name		name of filesystem
f41cf682d0d3 PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 9355
diff changeset
  3823
 * zc_cookie		zap cursor
f41cf682d0d3 PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 9355
diff changeset
  3824
 * zc_objset_type	zfs_userquota_prop_t
f41cf682d0d3 PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 9355
diff changeset
  3825
 * zc_nvlist_dst[_size] buffer to fill (not really an nvlist)
f41cf682d0d3 PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 9355
diff changeset
  3826
 *
f41cf682d0d3 PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 9355
diff changeset
  3827
 * outputs:
f41cf682d0d3 PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 9355
diff changeset
  3828
 * zc_nvlist_dst[_size]	data buffer (array of zfs_useracct_t)
f41cf682d0d3 PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 9355
diff changeset
  3829
 * zc_cookie	zap cursor
f41cf682d0d3 PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 9355
diff changeset
  3830
 */
f41cf682d0d3 PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 9355
diff changeset
  3831
static int
f41cf682d0d3 PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 9355
diff changeset
  3832
zfs_ioc_userspace_many(zfs_cmd_t *zc)
f41cf682d0d3 PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 9355
diff changeset
  3833
{
f41cf682d0d3 PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 9355
diff changeset
  3834
	zfsvfs_t *zfsvfs;
11933
76670fc4178f 6931083 incorrect zfs userquota nvlist propnames can break Solaris 10 Containers and panic systems
Tim Haley <Tim.Haley@Sun.COM>
parents: 11889
diff changeset
  3835
	int bufsize = zc->zc_nvlist_dst_size;
76670fc4178f 6931083 incorrect zfs userquota nvlist propnames can break Solaris 10 Containers and panic systems
Tim Haley <Tim.Haley@Sun.COM>
parents: 11889
diff changeset
  3836
76670fc4178f 6931083 incorrect zfs userquota nvlist propnames can break Solaris 10 Containers and panic systems
Tim Haley <Tim.Haley@Sun.COM>
parents: 11889
diff changeset
  3837
	if (bufsize <= 0)
76670fc4178f 6931083 incorrect zfs userquota nvlist propnames can break Solaris 10 Containers and panic systems
Tim Haley <Tim.Haley@Sun.COM>
parents: 11889
diff changeset
  3838
		return (ENOMEM);
76670fc4178f 6931083 incorrect zfs userquota nvlist propnames can break Solaris 10 Containers and panic systems
Tim Haley <Tim.Haley@Sun.COM>
parents: 11889
diff changeset
  3839
76670fc4178f 6931083 incorrect zfs userquota nvlist propnames can break Solaris 10 Containers and panic systems
Tim Haley <Tim.Haley@Sun.COM>
parents: 11889
diff changeset
  3840
	int error = zfsvfs_hold(zc->zc_name, FTAG, &zfsvfs);
9396
f41cf682d0d3 PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 9355
diff changeset
  3841
	if (error)
f41cf682d0d3 PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 9355
diff changeset
  3842
		return (error);
f41cf682d0d3 PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 9355
diff changeset
  3843
f41cf682d0d3 PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 9355
diff changeset
  3844
	void *buf = kmem_alloc(bufsize, KM_SLEEP);
f41cf682d0d3 PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 9355
diff changeset
  3845
f41cf682d0d3 PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 9355
diff changeset
  3846
	error = zfs_userspace_many(zfsvfs, zc->zc_objset_type, &zc->zc_cookie,
f41cf682d0d3 PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 9355
diff changeset
  3847
	    buf, &zc->zc_nvlist_dst_size);
f41cf682d0d3 PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 9355
diff changeset
  3848
f41cf682d0d3 PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 9355
diff changeset
  3849
	if (error == 0) {
f41cf682d0d3 PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 9355
diff changeset
  3850
		error = xcopyout(buf,
f41cf682d0d3 PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 9355
diff changeset
  3851
		    (void *)(uintptr_t)zc->zc_nvlist_dst,
f41cf682d0d3 PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 9355
diff changeset
  3852
		    zc->zc_nvlist_dst_size);
f41cf682d0d3 PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 9355
diff changeset
  3853
	}
f41cf682d0d3 PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 9355
diff changeset
  3854
	kmem_free(buf, bufsize);
f41cf682d0d3 PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 9355
diff changeset
  3855
	zfsvfs_rele(zfsvfs, FTAG);
f41cf682d0d3 PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 9355
diff changeset
  3856
f41cf682d0d3 PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 9355
diff changeset
  3857
	return (error);
f41cf682d0d3 PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 9355
diff changeset
  3858
}
f41cf682d0d3 PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 9355
diff changeset
  3859
f41cf682d0d3 PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 9355
diff changeset
  3860
/*
f41cf682d0d3 PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 9355
diff changeset
  3861
 * inputs:
f41cf682d0d3 PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 9355
diff changeset
  3862
 * zc_name		name of filesystem
f41cf682d0d3 PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 9355
diff changeset
  3863
 *
f41cf682d0d3 PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 9355
diff changeset
  3864
 * outputs:
f41cf682d0d3 PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 9355
diff changeset
  3865
 * none
f41cf682d0d3 PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 9355
diff changeset
  3866
 */
f41cf682d0d3 PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 9355
diff changeset
  3867
static int
f41cf682d0d3 PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 9355
diff changeset
  3868
zfs_ioc_userspace_upgrade(zfs_cmd_t *zc)
f41cf682d0d3 PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 9355
diff changeset
  3869
{
f41cf682d0d3 PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 9355
diff changeset
  3870
	objset_t *os;
11422
42768837421d PSARC/2009/511 zpool split
Mark J Musante <Mark.Musante@Sun.COM>
parents: 11314
diff changeset
  3871
	int error = 0;
9396
f41cf682d0d3 PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 9355
diff changeset
  3872
	zfsvfs_t *zfsvfs;
f41cf682d0d3 PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 9355
diff changeset
  3873
f41cf682d0d3 PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 9355
diff changeset
  3874
	if (getzfsvfs(zc->zc_name, &zfsvfs) == 0) {
10298
a0d52501437c 6860996 %temporary clones are not automatically destroyed on error
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 10272
diff changeset
  3875
		if (!dmu_objset_userused_enabled(zfsvfs->z_os)) {
9396
f41cf682d0d3 PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 9355
diff changeset
  3876
			/*
f41cf682d0d3 PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 9355
diff changeset
  3877
			 * If userused is not enabled, it may be because the
f41cf682d0d3 PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 9355
diff changeset
  3878
			 * objset needs to be closed & reopened (to grow the
f41cf682d0d3 PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 9355
diff changeset
  3879
			 * objset_phys_t).  Suspend/resume the fs will do that.
f41cf682d0d3 PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 9355
diff changeset
  3880
			 */
10298
a0d52501437c 6860996 %temporary clones are not automatically destroyed on error
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 10272
diff changeset
  3881
			error = zfs_suspend_fs(zfsvfs);
a0d52501437c 6860996 %temporary clones are not automatically destroyed on error
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 10272
diff changeset
  3882
			if (error == 0)
a0d52501437c 6860996 %temporary clones are not automatically destroyed on error
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 10272
diff changeset
  3883
				error = zfs_resume_fs(zfsvfs, zc->zc_name);
9396
f41cf682d0d3 PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 9355
diff changeset
  3884
		}
f41cf682d0d3 PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 9355
diff changeset
  3885
		if (error == 0)
f41cf682d0d3 PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 9355
diff changeset
  3886
			error = dmu_objset_userspace_upgrade(zfsvfs->z_os);
f41cf682d0d3 PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 9355
diff changeset
  3887
		VFS_RELE(zfsvfs->z_vfs);
f41cf682d0d3 PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 9355
diff changeset
  3888
	} else {
10298
a0d52501437c 6860996 %temporary clones are not automatically destroyed on error
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 10272
diff changeset
  3889
		/* XXX kind of reading contents without owning */
a0d52501437c 6860996 %temporary clones are not automatically destroyed on error
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 10272
diff changeset
  3890
		error = dmu_objset_hold(zc->zc_name, FTAG, &os);
9396
f41cf682d0d3 PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 9355
diff changeset
  3891
		if (error)
f41cf682d0d3 PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 9355
diff changeset
  3892
			return (error);
f41cf682d0d3 PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 9355
diff changeset
  3893
f41cf682d0d3 PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 9355
diff changeset
  3894
		error = dmu_objset_userspace_upgrade(os);
10298
a0d52501437c 6860996 %temporary clones are not automatically destroyed on error
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 10272
diff changeset
  3895
		dmu_objset_rele(os, FTAG);
9396
f41cf682d0d3 PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 9355
diff changeset
  3896
	}
f41cf682d0d3 PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 9355
diff changeset
  3897
f41cf682d0d3 PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 9355
diff changeset
  3898
	return (error);
f41cf682d0d3 PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 9355
diff changeset
  3899
}
f41cf682d0d3 PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 9355
diff changeset
  3900
f41cf682d0d3 PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 9355
diff changeset
  3901
/*
4543
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  3902
 * We don't want to have a hard dependency
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  3903
 * against some special symbols in sharefs
5331
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
  3904
 * nfs, and smbsrv.  Determine them if needed when
4543
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  3905
 * the first file system is shared.
5331
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
  3906
 * Neither sharefs, nfs or smbsrv are unloadable modules.
4543
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  3907
 */
5331
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
  3908
int (*znfsexport_fs)(void *arg);
4543
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  3909
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
  3910
int (*zsmbexport_fs)(void *arg, boolean_t add_share);
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
  3911
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
  3912
int zfs_nfsshare_inited;
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
  3913
int zfs_smbshare_inited;
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
  3914
4543
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  3915
ddi_modhandle_t nfs_mod;
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  3916
ddi_modhandle_t sharefs_mod;
5331
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
  3917
ddi_modhandle_t smbsrv_mod;
4543
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  3918
kmutex_t zfs_share_lock;
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  3919
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  3920
static int
5331
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
  3921
zfs_init_sharefs()
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
  3922
{
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
  3923
	int error;
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
  3924
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
  3925
	ASSERT(MUTEX_HELD(&zfs_share_lock));
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
  3926
	/* Both NFS and SMB shares also require sharetab support. */
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
  3927
	if (sharefs_mod == NULL && ((sharefs_mod =
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
  3928
	    ddi_modopen("fs/sharefs",
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
  3929
	    KRTLD_MODE_FIRST, &error)) == NULL)) {
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
  3930
		return (ENOSYS);
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
  3931
	}
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
  3932
	if (zshare_fs == NULL && ((zshare_fs =
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
  3933
	    (int (*)(enum sharefs_sys_op, share_t *, uint32_t))
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
  3934
	    ddi_modsym(sharefs_mod, "sharefs_impl", &error)) == NULL)) {
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
  3935
		return (ENOSYS);
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
  3936
	}
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
  3937
	return (0);
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
  3938
}
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
  3939
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
  3940
static int
4543
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  3941
zfs_ioc_share(zfs_cmd_t *zc)
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  3942
{
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  3943
	int error;
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  3944
	int opcode;
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  3945
5331
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
  3946
	switch (zc->zc_share.z_sharetype) {
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
  3947
	case ZFS_SHARE_NFS:
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
  3948
	case ZFS_UNSHARE_NFS:
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
  3949
		if (zfs_nfsshare_inited == 0) {
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
  3950
			mutex_enter(&zfs_share_lock);
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
  3951
			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
  3952
			    KRTLD_MODE_FIRST, &error)) == NULL)) {
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
  3953
				mutex_exit(&zfs_share_lock);
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
  3954
				return (ENOSYS);
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
  3955
			}
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
  3956
			if (znfsexport_fs == NULL &&
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
  3957
			    ((znfsexport_fs = (int (*)(void *))
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
  3958
			    ddi_modsym(nfs_mod,
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
  3959
			    "nfs_export", &error)) == NULL)) {
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
  3960
				mutex_exit(&zfs_share_lock);
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
  3961
				return (ENOSYS);
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
  3962
			}
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
  3963
			error = zfs_init_sharefs();
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
  3964
			if (error) {
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
  3965
				mutex_exit(&zfs_share_lock);
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
  3966
				return (ENOSYS);
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
  3967
			}
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
  3968
			zfs_nfsshare_inited = 1;
4543
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  3969
			mutex_exit(&zfs_share_lock);
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  3970
		}
5331
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
  3971
		break;
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
  3972
	case ZFS_SHARE_SMB:
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
  3973
	case ZFS_UNSHARE_SMB:
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
  3974
		if (zfs_smbshare_inited == 0) {
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
  3975
			mutex_enter(&zfs_share_lock);
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
  3976
			if (smbsrv_mod == NULL && ((smbsrv_mod =
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
  3977
			    ddi_modopen("drv/smbsrv",
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
  3978
			    KRTLD_MODE_FIRST, &error)) == NULL)) {
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
  3979
				mutex_exit(&zfs_share_lock);
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
  3980
				return (ENOSYS);
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
  3981
			}
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
  3982
			if (zsmbexport_fs == NULL && ((zsmbexport_fs =
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
  3983
			    (int (*)(void *, boolean_t))ddi_modsym(smbsrv_mod,
6139
5c743b207bf9 6541120 Configuration is not propagated to SMB kernel module
jb150015
parents: 6083
diff changeset
  3984
			    "smb_server_share", &error)) == NULL)) {
5331
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
  3985
				mutex_exit(&zfs_share_lock);
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
  3986
				return (ENOSYS);
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
  3987
			}
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
  3988
			error = zfs_init_sharefs();
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
  3989
			if (error) {
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
  3990
				mutex_exit(&zfs_share_lock);
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
  3991
				return (ENOSYS);
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
  3992
			}
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
  3993
			zfs_smbshare_inited = 1;
4543
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  3994
			mutex_exit(&zfs_share_lock);
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  3995
		}
5331
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
  3996
		break;
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
  3997
	default:
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
  3998
		return (EINVAL);
4543
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  3999
	}
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  4000
5331
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
  4001
	switch (zc->zc_share.z_sharetype) {
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
  4002
	case ZFS_SHARE_NFS:
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
  4003
	case ZFS_UNSHARE_NFS:
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
  4004
		if (error =
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
  4005
		    znfsexport_fs((void *)
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
  4006
		    (uintptr_t)zc->zc_share.z_exportdata))
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
  4007
			return (error);
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
  4008
		break;
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
  4009
	case ZFS_SHARE_SMB:
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
  4010
	case ZFS_UNSHARE_SMB:
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
  4011
		if (error = zsmbexport_fs((void *)
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
  4012
		    (uintptr_t)zc->zc_share.z_exportdata,
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
  4013
		    zc->zc_share.z_sharetype == ZFS_SHARE_SMB ?
8845
91af0d9c0790 6800942 smb_session_create() incorrectly stores IP addresses
Alan Wright <amw@Sun.COM>
parents: 8724
diff changeset
  4014
		    B_TRUE: B_FALSE)) {
5331
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
  4015
			return (error);
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
  4016
		}
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
  4017
		break;
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
  4018
	}
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
  4019
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
  4020
	opcode = (zc->zc_share.z_sharetype == ZFS_SHARE_NFS ||
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
  4021
	    zc->zc_share.z_sharetype == ZFS_SHARE_SMB) ?
4543
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  4022
	    SHAREFS_ADD : SHAREFS_REMOVE;
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  4023
5331
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
  4024
	/*
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
  4025
	 * Add or remove share from sharetab
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
  4026
	 */
4543
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  4027
	error = zshare_fs(opcode,
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  4028
	    (void *)(uintptr_t)zc->zc_share.z_sharedata,
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  4029
	    zc->zc_share.z_sharemax);
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  4030
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  4031
	return (error);
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  4032
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  4033
}
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  4034
8845
91af0d9c0790 6800942 smb_session_create() incorrectly stores IP addresses
Alan Wright <amw@Sun.COM>
parents: 8724
diff changeset
  4035
ace_t full_access[] = {
91af0d9c0790 6800942 smb_session_create() incorrectly stores IP addresses
Alan Wright <amw@Sun.COM>
parents: 8724
diff changeset
  4036
	{(uid_t)-1, ACE_ALL_PERMS, ACE_EVERYONE, 0}
91af0d9c0790 6800942 smb_session_create() incorrectly stores IP addresses
Alan Wright <amw@Sun.COM>
parents: 8724
diff changeset
  4037
};
91af0d9c0790 6800942 smb_session_create() incorrectly stores IP addresses
Alan Wright <amw@Sun.COM>
parents: 8724
diff changeset
  4038
91af0d9c0790 6800942 smb_session_create() incorrectly stores IP addresses
Alan Wright <amw@Sun.COM>
parents: 8724
diff changeset
  4039
/*
91af0d9c0790 6800942 smb_session_create() incorrectly stores IP addresses
Alan Wright <amw@Sun.COM>
parents: 8724
diff changeset
  4040
 * Remove all ACL files in shares dir
91af0d9c0790 6800942 smb_session_create() incorrectly stores IP addresses
Alan Wright <amw@Sun.COM>
parents: 8724
diff changeset
  4041
 */
91af0d9c0790 6800942 smb_session_create() incorrectly stores IP addresses
Alan Wright <amw@Sun.COM>
parents: 8724
diff changeset
  4042
static int
91af0d9c0790 6800942 smb_session_create() incorrectly stores IP addresses
Alan Wright <amw@Sun.COM>
parents: 8724
diff changeset
  4043
zfs_smb_acl_purge(znode_t *dzp)
91af0d9c0790 6800942 smb_session_create() incorrectly stores IP addresses
Alan Wright <amw@Sun.COM>
parents: 8724
diff changeset
  4044
{
91af0d9c0790 6800942 smb_session_create() incorrectly stores IP addresses
Alan Wright <amw@Sun.COM>
parents: 8724
diff changeset
  4045
	zap_cursor_t	zc;
91af0d9c0790 6800942 smb_session_create() incorrectly stores IP addresses
Alan Wright <amw@Sun.COM>
parents: 8724
diff changeset
  4046
	zap_attribute_t	zap;
91af0d9c0790 6800942 smb_session_create() incorrectly stores IP addresses
Alan Wright <amw@Sun.COM>
parents: 8724
diff changeset
  4047
	zfsvfs_t *zfsvfs = dzp->z_zfsvfs;
91af0d9c0790 6800942 smb_session_create() incorrectly stores IP addresses
Alan Wright <amw@Sun.COM>
parents: 8724
diff changeset
  4048
	int error;
91af0d9c0790 6800942 smb_session_create() incorrectly stores IP addresses
Alan Wright <amw@Sun.COM>
parents: 8724
diff changeset
  4049
91af0d9c0790 6800942 smb_session_create() incorrectly stores IP addresses
Alan Wright <amw@Sun.COM>
parents: 8724
diff changeset
  4050
	for (zap_cursor_init(&zc, zfsvfs->z_os, dzp->z_id);
91af0d9c0790 6800942 smb_session_create() incorrectly stores IP addresses
Alan Wright <amw@Sun.COM>
parents: 8724
diff changeset
  4051
	    (error = zap_cursor_retrieve(&zc, &zap)) == 0;
91af0d9c0790 6800942 smb_session_create() incorrectly stores IP addresses
Alan Wright <amw@Sun.COM>
parents: 8724
diff changeset
  4052
	    zap_cursor_advance(&zc)) {
91af0d9c0790 6800942 smb_session_create() incorrectly stores IP addresses
Alan Wright <amw@Sun.COM>
parents: 8724
diff changeset
  4053
		if ((error = VOP_REMOVE(ZTOV(dzp), zap.za_name, kcred,
91af0d9c0790 6800942 smb_session_create() incorrectly stores IP addresses
Alan Wright <amw@Sun.COM>
parents: 8724
diff changeset
  4054
		    NULL, 0)) != 0)
91af0d9c0790 6800942 smb_session_create() incorrectly stores IP addresses
Alan Wright <amw@Sun.COM>
parents: 8724
diff changeset
  4055
			break;
91af0d9c0790 6800942 smb_session_create() incorrectly stores IP addresses
Alan Wright <amw@Sun.COM>
parents: 8724
diff changeset
  4056
	}
91af0d9c0790 6800942 smb_session_create() incorrectly stores IP addresses
Alan Wright <amw@Sun.COM>
parents: 8724
diff changeset
  4057
	zap_cursor_fini(&zc);
91af0d9c0790 6800942 smb_session_create() incorrectly stores IP addresses
Alan Wright <amw@Sun.COM>
parents: 8724
diff changeset
  4058
	return (error);
91af0d9c0790 6800942 smb_session_create() incorrectly stores IP addresses
Alan Wright <amw@Sun.COM>
parents: 8724
diff changeset
  4059
}
91af0d9c0790 6800942 smb_session_create() incorrectly stores IP addresses
Alan Wright <amw@Sun.COM>
parents: 8724
diff changeset
  4060
91af0d9c0790 6800942 smb_session_create() incorrectly stores IP addresses
Alan Wright <amw@Sun.COM>
parents: 8724
diff changeset
  4061
static int
91af0d9c0790 6800942 smb_session_create() incorrectly stores IP addresses
Alan Wright <amw@Sun.COM>
parents: 8724
diff changeset
  4062
zfs_ioc_smb_acl(zfs_cmd_t *zc)
91af0d9c0790 6800942 smb_session_create() incorrectly stores IP addresses
Alan Wright <amw@Sun.COM>
parents: 8724
diff changeset
  4063
{
91af0d9c0790 6800942 smb_session_create() incorrectly stores IP addresses
Alan Wright <amw@Sun.COM>
parents: 8724
diff changeset
  4064
	vnode_t *vp;
91af0d9c0790 6800942 smb_session_create() incorrectly stores IP addresses
Alan Wright <amw@Sun.COM>
parents: 8724
diff changeset
  4065
	znode_t *dzp;
91af0d9c0790 6800942 smb_session_create() incorrectly stores IP addresses
Alan Wright <amw@Sun.COM>
parents: 8724
diff changeset
  4066
	vnode_t *resourcevp = NULL;
91af0d9c0790 6800942 smb_session_create() incorrectly stores IP addresses
Alan Wright <amw@Sun.COM>
parents: 8724
diff changeset
  4067
	znode_t *sharedir;
91af0d9c0790 6800942 smb_session_create() incorrectly stores IP addresses
Alan Wright <amw@Sun.COM>
parents: 8724
diff changeset
  4068
	zfsvfs_t *zfsvfs;
91af0d9c0790 6800942 smb_session_create() incorrectly stores IP addresses
Alan Wright <amw@Sun.COM>
parents: 8724
diff changeset
  4069
	nvlist_t *nvlist;
91af0d9c0790 6800942 smb_session_create() incorrectly stores IP addresses
Alan Wright <amw@Sun.COM>
parents: 8724
diff changeset
  4070
	char *src, *target;
91af0d9c0790 6800942 smb_session_create() incorrectly stores IP addresses
Alan Wright <amw@Sun.COM>
parents: 8724
diff changeset
  4071
	vattr_t vattr;
91af0d9c0790 6800942 smb_session_create() incorrectly stores IP addresses
Alan Wright <amw@Sun.COM>
parents: 8724
diff changeset
  4072
	vsecattr_t vsec;
91af0d9c0790 6800942 smb_session_create() incorrectly stores IP addresses
Alan Wright <amw@Sun.COM>
parents: 8724
diff changeset
  4073
	int error = 0;
91af0d9c0790 6800942 smb_session_create() incorrectly stores IP addresses
Alan Wright <amw@Sun.COM>
parents: 8724
diff changeset
  4074
91af0d9c0790 6800942 smb_session_create() incorrectly stores IP addresses
Alan Wright <amw@Sun.COM>
parents: 8724
diff changeset
  4075
	if ((error = lookupname(zc->zc_value, UIO_SYSSPACE,
91af0d9c0790 6800942 smb_session_create() incorrectly stores IP addresses
Alan Wright <amw@Sun.COM>
parents: 8724
diff changeset
  4076
	    NO_FOLLOW, NULL, &vp)) != 0)
91af0d9c0790 6800942 smb_session_create() incorrectly stores IP addresses
Alan Wright <amw@Sun.COM>
parents: 8724
diff changeset
  4077
		return (error);
91af0d9c0790 6800942 smb_session_create() incorrectly stores IP addresses
Alan Wright <amw@Sun.COM>
parents: 8724
diff changeset
  4078
91af0d9c0790 6800942 smb_session_create() incorrectly stores IP addresses
Alan Wright <amw@Sun.COM>
parents: 8724
diff changeset
  4079
	/* Now make sure mntpnt and dataset are ZFS */
91af0d9c0790 6800942 smb_session_create() incorrectly stores IP addresses
Alan Wright <amw@Sun.COM>
parents: 8724
diff changeset
  4080
91af0d9c0790 6800942 smb_session_create() incorrectly stores IP addresses
Alan Wright <amw@Sun.COM>
parents: 8724
diff changeset
  4081
	if (vp->v_vfsp->vfs_fstype != zfsfstype ||
91af0d9c0790 6800942 smb_session_create() incorrectly stores IP addresses
Alan Wright <amw@Sun.COM>
parents: 8724
diff changeset
  4082
	    (strcmp((char *)refstr_value(vp->v_vfsp->vfs_resource),
91af0d9c0790 6800942 smb_session_create() incorrectly stores IP addresses
Alan Wright <amw@Sun.COM>
parents: 8724
diff changeset
  4083
	    zc->zc_name) != 0)) {
91af0d9c0790 6800942 smb_session_create() incorrectly stores IP addresses
Alan Wright <amw@Sun.COM>
parents: 8724
diff changeset
  4084
		VN_RELE(vp);
91af0d9c0790 6800942 smb_session_create() incorrectly stores IP addresses
Alan Wright <amw@Sun.COM>
parents: 8724
diff changeset
  4085
		return (EINVAL);
91af0d9c0790 6800942 smb_session_create() incorrectly stores IP addresses
Alan Wright <amw@Sun.COM>
parents: 8724
diff changeset
  4086
	}
91af0d9c0790 6800942 smb_session_create() incorrectly stores IP addresses
Alan Wright <amw@Sun.COM>
parents: 8724
diff changeset
  4087
91af0d9c0790 6800942 smb_session_create() incorrectly stores IP addresses
Alan Wright <amw@Sun.COM>
parents: 8724
diff changeset
  4088
	dzp = VTOZ(vp);
91af0d9c0790 6800942 smb_session_create() incorrectly stores IP addresses
Alan Wright <amw@Sun.COM>
parents: 8724
diff changeset
  4089
	zfsvfs = dzp->z_zfsvfs;
91af0d9c0790 6800942 smb_session_create() incorrectly stores IP addresses
Alan Wright <amw@Sun.COM>
parents: 8724
diff changeset
  4090
	ZFS_ENTER(zfsvfs);
91af0d9c0790 6800942 smb_session_create() incorrectly stores IP addresses
Alan Wright <amw@Sun.COM>
parents: 8724
diff changeset
  4091
9030
243fd360d81f 6815893 hang mounting a dataset after booting into a new boot environment
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 8845
diff changeset
  4092
	/*
243fd360d81f 6815893 hang mounting a dataset after booting into a new boot environment
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 8845
diff changeset
  4093
	 * Create share dir if its missing.
243fd360d81f 6815893 hang mounting a dataset after booting into a new boot environment
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 8845
diff changeset
  4094
	 */
243fd360d81f 6815893 hang mounting a dataset after booting into a new boot environment
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 8845
diff changeset
  4095
	mutex_enter(&zfsvfs->z_lock);
243fd360d81f 6815893 hang mounting a dataset after booting into a new boot environment
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 8845
diff changeset
  4096
	if (zfsvfs->z_shares_dir == 0) {
243fd360d81f 6815893 hang mounting a dataset after booting into a new boot environment
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 8845
diff changeset
  4097
		dmu_tx_t *tx;
243fd360d81f 6815893 hang mounting a dataset after booting into a new boot environment
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 8845
diff changeset
  4098
243fd360d81f 6815893 hang mounting a dataset after booting into a new boot environment
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 8845
diff changeset
  4099
		tx = dmu_tx_create(zfsvfs->z_os);
243fd360d81f 6815893 hang mounting a dataset after booting into a new boot environment
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 8845
diff changeset
  4100
		dmu_tx_hold_zap(tx, MASTER_NODE_OBJ, TRUE,
243fd360d81f 6815893 hang mounting a dataset after booting into a new boot environment
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 8845
diff changeset
  4101
		    ZFS_SHARES_DIR);
243fd360d81f 6815893 hang mounting a dataset after booting into a new boot environment
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 8845
diff changeset
  4102
		dmu_tx_hold_zap(tx, DMU_NEW_OBJECT, FALSE, NULL);
243fd360d81f 6815893 hang mounting a dataset after booting into a new boot environment
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 8845
diff changeset
  4103
		error = dmu_tx_assign(tx, TXG_WAIT);
243fd360d81f 6815893 hang mounting a dataset after booting into a new boot environment
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 8845
diff changeset
  4104
		if (error) {
243fd360d81f 6815893 hang mounting a dataset after booting into a new boot environment
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 8845
diff changeset
  4105
			dmu_tx_abort(tx);
243fd360d81f 6815893 hang mounting a dataset after booting into a new boot environment
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 8845
diff changeset
  4106
		} else {
243fd360d81f 6815893 hang mounting a dataset after booting into a new boot environment
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 8845
diff changeset
  4107
			error = zfs_create_share_dir(zfsvfs, tx);
243fd360d81f 6815893 hang mounting a dataset after booting into a new boot environment
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 8845
diff changeset
  4108
			dmu_tx_commit(tx);
243fd360d81f 6815893 hang mounting a dataset after booting into a new boot environment
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 8845
diff changeset
  4109
		}
243fd360d81f 6815893 hang mounting a dataset after booting into a new boot environment
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 8845
diff changeset
  4110
		if (error) {
243fd360d81f 6815893 hang mounting a dataset after booting into a new boot environment
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 8845
diff changeset
  4111
			mutex_exit(&zfsvfs->z_lock);
243fd360d81f 6815893 hang mounting a dataset after booting into a new boot environment
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 8845
diff changeset
  4112
			VN_RELE(vp);
243fd360d81f 6815893 hang mounting a dataset after booting into a new boot environment
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 8845
diff changeset
  4113
			ZFS_EXIT(zfsvfs);
243fd360d81f 6815893 hang mounting a dataset after booting into a new boot environment
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 8845
diff changeset
  4114
			return (error);
243fd360d81f 6815893 hang mounting a dataset after booting into a new boot environment
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 8845
diff changeset
  4115
		}
243fd360d81f 6815893 hang mounting a dataset after booting into a new boot environment
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 8845
diff changeset
  4116
	}
243fd360d81f 6815893 hang mounting a dataset after booting into a new boot environment
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 8845
diff changeset
  4117
	mutex_exit(&zfsvfs->z_lock);
243fd360d81f 6815893 hang mounting a dataset after booting into a new boot environment
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 8845
diff changeset
  4118
243fd360d81f 6815893 hang mounting a dataset after booting into a new boot environment
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 8845
diff changeset
  4119
	ASSERT(zfsvfs->z_shares_dir);
8845
91af0d9c0790 6800942 smb_session_create() incorrectly stores IP addresses
Alan Wright <amw@Sun.COM>
parents: 8724
diff changeset
  4120
	if ((error = zfs_zget(zfsvfs, zfsvfs->z_shares_dir, &sharedir)) != 0) {
9030
243fd360d81f 6815893 hang mounting a dataset after booting into a new boot environment
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 8845
diff changeset
  4121
		VN_RELE(vp);
8845
91af0d9c0790 6800942 smb_session_create() incorrectly stores IP addresses
Alan Wright <amw@Sun.COM>
parents: 8724
diff changeset
  4122
		ZFS_EXIT(zfsvfs);
91af0d9c0790 6800942 smb_session_create() incorrectly stores IP addresses
Alan Wright <amw@Sun.COM>
parents: 8724
diff changeset
  4123
		return (error);
91af0d9c0790 6800942 smb_session_create() incorrectly stores IP addresses
Alan Wright <amw@Sun.COM>
parents: 8724
diff changeset
  4124
	}
91af0d9c0790 6800942 smb_session_create() incorrectly stores IP addresses
Alan Wright <amw@Sun.COM>
parents: 8724
diff changeset
  4125
91af0d9c0790 6800942 smb_session_create() incorrectly stores IP addresses
Alan Wright <amw@Sun.COM>
parents: 8724
diff changeset
  4126
	switch (zc->zc_cookie) {
91af0d9c0790 6800942 smb_session_create() incorrectly stores IP addresses
Alan Wright <amw@Sun.COM>
parents: 8724
diff changeset
  4127
	case ZFS_SMB_ACL_ADD:
91af0d9c0790 6800942 smb_session_create() incorrectly stores IP addresses
Alan Wright <amw@Sun.COM>
parents: 8724
diff changeset
  4128
		vattr.va_mask = AT_MODE|AT_UID|AT_GID|AT_TYPE;
91af0d9c0790 6800942 smb_session_create() incorrectly stores IP addresses
Alan Wright <amw@Sun.COM>
parents: 8724
diff changeset
  4129
		vattr.va_type = VREG;
91af0d9c0790 6800942 smb_session_create() incorrectly stores IP addresses
Alan Wright <amw@Sun.COM>
parents: 8724
diff changeset
  4130
		vattr.va_mode = S_IFREG|0777;
91af0d9c0790 6800942 smb_session_create() incorrectly stores IP addresses
Alan Wright <amw@Sun.COM>
parents: 8724
diff changeset
  4131
		vattr.va_uid = 0;
91af0d9c0790 6800942 smb_session_create() incorrectly stores IP addresses
Alan Wright <amw@Sun.COM>
parents: 8724
diff changeset
  4132
		vattr.va_gid = 0;
91af0d9c0790 6800942 smb_session_create() incorrectly stores IP addresses
Alan Wright <amw@Sun.COM>
parents: 8724
diff changeset
  4133
91af0d9c0790 6800942 smb_session_create() incorrectly stores IP addresses
Alan Wright <amw@Sun.COM>
parents: 8724
diff changeset
  4134
		vsec.vsa_mask = VSA_ACE;
91af0d9c0790 6800942 smb_session_create() incorrectly stores IP addresses
Alan Wright <amw@Sun.COM>
parents: 8724
diff changeset
  4135
		vsec.vsa_aclentp = &full_access;
91af0d9c0790 6800942 smb_session_create() incorrectly stores IP addresses
Alan Wright <amw@Sun.COM>
parents: 8724
diff changeset
  4136
		vsec.vsa_aclentsz = sizeof (full_access);
91af0d9c0790 6800942 smb_session_create() incorrectly stores IP addresses
Alan Wright <amw@Sun.COM>
parents: 8724
diff changeset
  4137
		vsec.vsa_aclcnt = 1;
91af0d9c0790 6800942 smb_session_create() incorrectly stores IP addresses
Alan Wright <amw@Sun.COM>
parents: 8724
diff changeset
  4138
91af0d9c0790 6800942 smb_session_create() incorrectly stores IP addresses
Alan Wright <amw@Sun.COM>
parents: 8724
diff changeset
  4139
		error = VOP_CREATE(ZTOV(sharedir), zc->zc_string,
91af0d9c0790 6800942 smb_session_create() incorrectly stores IP addresses
Alan Wright <amw@Sun.COM>
parents: 8724
diff changeset
  4140
		    &vattr, EXCL, 0, &resourcevp, kcred, 0, NULL, &vsec);
91af0d9c0790 6800942 smb_session_create() incorrectly stores IP addresses
Alan Wright <amw@Sun.COM>
parents: 8724
diff changeset
  4141
		if (resourcevp)
91af0d9c0790 6800942 smb_session_create() incorrectly stores IP addresses
Alan Wright <amw@Sun.COM>
parents: 8724
diff changeset
  4142
			VN_RELE(resourcevp);
91af0d9c0790 6800942 smb_session_create() incorrectly stores IP addresses
Alan Wright <amw@Sun.COM>
parents: 8724
diff changeset
  4143
		break;
91af0d9c0790 6800942 smb_session_create() incorrectly stores IP addresses
Alan Wright <amw@Sun.COM>
parents: 8724
diff changeset
  4144
91af0d9c0790 6800942 smb_session_create() incorrectly stores IP addresses
Alan Wright <amw@Sun.COM>
parents: 8724
diff changeset
  4145
	case ZFS_SMB_ACL_REMOVE:
91af0d9c0790 6800942 smb_session_create() incorrectly stores IP addresses
Alan Wright <amw@Sun.COM>
parents: 8724
diff changeset
  4146
		error = VOP_REMOVE(ZTOV(sharedir), zc->zc_string, kcred,
91af0d9c0790 6800942 smb_session_create() incorrectly stores IP addresses
Alan Wright <amw@Sun.COM>
parents: 8724
diff changeset
  4147
		    NULL, 0);
91af0d9c0790 6800942 smb_session_create() incorrectly stores IP addresses
Alan Wright <amw@Sun.COM>
parents: 8724
diff changeset
  4148
		break;
91af0d9c0790 6800942 smb_session_create() incorrectly stores IP addresses
Alan Wright <amw@Sun.COM>
parents: 8724
diff changeset
  4149
91af0d9c0790 6800942 smb_session_create() incorrectly stores IP addresses
Alan Wright <amw@Sun.COM>
parents: 8724
diff changeset
  4150
	case ZFS_SMB_ACL_RENAME:
91af0d9c0790 6800942 smb_session_create() incorrectly stores IP addresses
Alan Wright <amw@Sun.COM>
parents: 8724
diff changeset
  4151
		if ((error = get_nvlist(zc->zc_nvlist_src,
9643
ffd8e7765f02 6736004 zvols need an additional property for comstar support
Eric Taylor <Eric.Taylor@Sun.COM>
parents: 9425
diff changeset
  4152
		    zc->zc_nvlist_src_size, zc->zc_iflags, &nvlist)) != 0) {
8845
91af0d9c0790 6800942 smb_session_create() incorrectly stores IP addresses
Alan Wright <amw@Sun.COM>
parents: 8724
diff changeset
  4153
			VN_RELE(vp);
91af0d9c0790 6800942 smb_session_create() incorrectly stores IP addresses
Alan Wright <amw@Sun.COM>
parents: 8724
diff changeset
  4154
			ZFS_EXIT(zfsvfs);
91af0d9c0790 6800942 smb_session_create() incorrectly stores IP addresses
Alan Wright <amw@Sun.COM>
parents: 8724
diff changeset
  4155
			return (error);
91af0d9c0790 6800942 smb_session_create() incorrectly stores IP addresses
Alan Wright <amw@Sun.COM>
parents: 8724
diff changeset
  4156
		}
91af0d9c0790 6800942 smb_session_create() incorrectly stores IP addresses
Alan Wright <amw@Sun.COM>
parents: 8724
diff changeset
  4157
		if (nvlist_lookup_string(nvlist, ZFS_SMB_ACL_SRC, &src) ||
91af0d9c0790 6800942 smb_session_create() incorrectly stores IP addresses
Alan Wright <amw@Sun.COM>
parents: 8724
diff changeset
  4158
		    nvlist_lookup_string(nvlist, ZFS_SMB_ACL_TARGET,
91af0d9c0790 6800942 smb_session_create() incorrectly stores IP addresses
Alan Wright <amw@Sun.COM>
parents: 8724
diff changeset
  4159
		    &target)) {
91af0d9c0790 6800942 smb_session_create() incorrectly stores IP addresses
Alan Wright <amw@Sun.COM>
parents: 8724
diff changeset
  4160
			VN_RELE(vp);
9179
d8fbd96b79b3 6790064 zfs needs to determine uid and gid earlier in create process
Mark Shellenbaum <Mark.Shellenbaum@Sun.COM>
parents: 9030
diff changeset
  4161
			VN_RELE(ZTOV(sharedir));
8845
91af0d9c0790 6800942 smb_session_create() incorrectly stores IP addresses
Alan Wright <amw@Sun.COM>
parents: 8724
diff changeset
  4162
			ZFS_EXIT(zfsvfs);
11422
42768837421d PSARC/2009/511 zpool split
Mark J Musante <Mark.Musante@Sun.COM>
parents: 11314
diff changeset
  4163
			nvlist_free(nvlist);
8845
91af0d9c0790 6800942 smb_session_create() incorrectly stores IP addresses
Alan Wright <amw@Sun.COM>
parents: 8724
diff changeset
  4164
			return (error);
91af0d9c0790 6800942 smb_session_create() incorrectly stores IP addresses
Alan Wright <amw@Sun.COM>
parents: 8724
diff changeset
  4165
		}
91af0d9c0790 6800942 smb_session_create() incorrectly stores IP addresses
Alan Wright <amw@Sun.COM>
parents: 8724
diff changeset
  4166
		error = VOP_RENAME(ZTOV(sharedir), src, ZTOV(sharedir), target,
91af0d9c0790 6800942 smb_session_create() incorrectly stores IP addresses
Alan Wright <amw@Sun.COM>
parents: 8724
diff changeset
  4167
		    kcred, NULL, 0);
91af0d9c0790 6800942 smb_session_create() incorrectly stores IP addresses
Alan Wright <amw@Sun.COM>
parents: 8724
diff changeset
  4168
		nvlist_free(nvlist);
91af0d9c0790 6800942 smb_session_create() incorrectly stores IP addresses
Alan Wright <amw@Sun.COM>
parents: 8724
diff changeset
  4169
		break;
91af0d9c0790 6800942 smb_session_create() incorrectly stores IP addresses
Alan Wright <amw@Sun.COM>
parents: 8724
diff changeset
  4170
91af0d9c0790 6800942 smb_session_create() incorrectly stores IP addresses
Alan Wright <amw@Sun.COM>
parents: 8724
diff changeset
  4171
	case ZFS_SMB_ACL_PURGE:
91af0d9c0790 6800942 smb_session_create() incorrectly stores IP addresses
Alan Wright <amw@Sun.COM>
parents: 8724
diff changeset
  4172
		error = zfs_smb_acl_purge(sharedir);
91af0d9c0790 6800942 smb_session_create() incorrectly stores IP addresses
Alan Wright <amw@Sun.COM>
parents: 8724
diff changeset
  4173
		break;
91af0d9c0790 6800942 smb_session_create() incorrectly stores IP addresses
Alan Wright <amw@Sun.COM>
parents: 8724
diff changeset
  4174
91af0d9c0790 6800942 smb_session_create() incorrectly stores IP addresses
Alan Wright <amw@Sun.COM>
parents: 8724
diff changeset
  4175
	default:
91af0d9c0790 6800942 smb_session_create() incorrectly stores IP addresses
Alan Wright <amw@Sun.COM>
parents: 8724
diff changeset
  4176
		error = EINVAL;
91af0d9c0790 6800942 smb_session_create() incorrectly stores IP addresses
Alan Wright <amw@Sun.COM>
parents: 8724
diff changeset
  4177
		break;
91af0d9c0790 6800942 smb_session_create() incorrectly stores IP addresses
Alan Wright <amw@Sun.COM>
parents: 8724
diff changeset
  4178
	}
91af0d9c0790 6800942 smb_session_create() incorrectly stores IP addresses
Alan Wright <amw@Sun.COM>
parents: 8724
diff changeset
  4179
91af0d9c0790 6800942 smb_session_create() incorrectly stores IP addresses
Alan Wright <amw@Sun.COM>
parents: 8724
diff changeset
  4180
	VN_RELE(vp);
91af0d9c0790 6800942 smb_session_create() incorrectly stores IP addresses
Alan Wright <amw@Sun.COM>
parents: 8724
diff changeset
  4181
	VN_RELE(ZTOV(sharedir));
91af0d9c0790 6800942 smb_session_create() incorrectly stores IP addresses
Alan Wright <amw@Sun.COM>
parents: 8724
diff changeset
  4182
91af0d9c0790 6800942 smb_session_create() incorrectly stores IP addresses
Alan Wright <amw@Sun.COM>
parents: 8724
diff changeset
  4183
	ZFS_EXIT(zfsvfs);
91af0d9c0790 6800942 smb_session_create() incorrectly stores IP addresses
Alan Wright <amw@Sun.COM>
parents: 8724
diff changeset
  4184
91af0d9c0790 6800942 smb_session_create() incorrectly stores IP addresses
Alan Wright <amw@Sun.COM>
parents: 8724
diff changeset
  4185
	return (error);
91af0d9c0790 6800942 smb_session_create() incorrectly stores IP addresses
Alan Wright <amw@Sun.COM>
parents: 8724
diff changeset
  4186
}
91af0d9c0790 6800942 smb_session_create() incorrectly stores IP addresses
Alan Wright <amw@Sun.COM>
parents: 8724
diff changeset
  4187
4543
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  4188
/*
10242
c40d075fbca6 PSARC/2009/297 zfs snapshot holds
Chris Kirby <chris.kirby@sun.com>
parents: 10233
diff changeset
  4189
 * inputs:
12527
693dd2cad55f 6884007 zfs_send() can leave temporary holds around
Chris Kirby <Chris.Kirby@oracle.com>
parents: 12296
diff changeset
  4190
 * zc_name		name of filesystem
693dd2cad55f 6884007 zfs_send() can leave temporary holds around
Chris Kirby <Chris.Kirby@oracle.com>
parents: 12296
diff changeset
  4191
 * zc_value		short name of snap
693dd2cad55f 6884007 zfs_send() can leave temporary holds around
Chris Kirby <Chris.Kirby@oracle.com>
parents: 12296
diff changeset
  4192
 * zc_string		user-supplied tag for this hold
693dd2cad55f 6884007 zfs_send() can leave temporary holds around
Chris Kirby <Chris.Kirby@oracle.com>
parents: 12296
diff changeset
  4193
 * zc_cookie		recursive flag
693dd2cad55f 6884007 zfs_send() can leave temporary holds around
Chris Kirby <Chris.Kirby@oracle.com>
parents: 12296
diff changeset
  4194
 * zc_temphold		set if hold is temporary
693dd2cad55f 6884007 zfs_send() can leave temporary holds around
Chris Kirby <Chris.Kirby@oracle.com>
parents: 12296
diff changeset
  4195
 * zc_cleanup_fd	cleanup-on-exit file descriptor for calling process
10242
c40d075fbca6 PSARC/2009/297 zfs snapshot holds
Chris Kirby <chris.kirby@sun.com>
parents: 10233
diff changeset
  4196
 *
c40d075fbca6 PSARC/2009/297 zfs snapshot holds
Chris Kirby <chris.kirby@sun.com>
parents: 10233
diff changeset
  4197
 * outputs:		none
c40d075fbca6 PSARC/2009/297 zfs snapshot holds
Chris Kirby <chris.kirby@sun.com>
parents: 10233
diff changeset
  4198
 */
c40d075fbca6 PSARC/2009/297 zfs snapshot holds
Chris Kirby <chris.kirby@sun.com>
parents: 10233
diff changeset
  4199
static int
c40d075fbca6 PSARC/2009/297 zfs snapshot holds
Chris Kirby <chris.kirby@sun.com>
parents: 10233
diff changeset
  4200
zfs_ioc_hold(zfs_cmd_t *zc)
c40d075fbca6 PSARC/2009/297 zfs snapshot holds
Chris Kirby <chris.kirby@sun.com>
parents: 10233
diff changeset
  4201
{
c40d075fbca6 PSARC/2009/297 zfs snapshot holds
Chris Kirby <chris.kirby@sun.com>
parents: 10233
diff changeset
  4202
	boolean_t recursive = zc->zc_cookie;
c40d075fbca6 PSARC/2009/297 zfs snapshot holds
Chris Kirby <chris.kirby@sun.com>
parents: 10233
diff changeset
  4203
c40d075fbca6 PSARC/2009/297 zfs snapshot holds
Chris Kirby <chris.kirby@sun.com>
parents: 10233
diff changeset
  4204
	if (snapshot_namecheck(zc->zc_value, NULL, NULL) != 0)
c40d075fbca6 PSARC/2009/297 zfs snapshot holds
Chris Kirby <chris.kirby@sun.com>
parents: 10233
diff changeset
  4205
		return (EINVAL);
c40d075fbca6 PSARC/2009/297 zfs snapshot holds
Chris Kirby <chris.kirby@sun.com>
parents: 10233
diff changeset
  4206
c40d075fbca6 PSARC/2009/297 zfs snapshot holds
Chris Kirby <chris.kirby@sun.com>
parents: 10233
diff changeset
  4207
	return (dsl_dataset_user_hold(zc->zc_name, zc->zc_value,
12527
693dd2cad55f 6884007 zfs_send() can leave temporary holds around
Chris Kirby <Chris.Kirby@oracle.com>
parents: 12296
diff changeset
  4208
	    zc->zc_string, recursive, zc->zc_temphold, zc->zc_cleanup_fd));
10242
c40d075fbca6 PSARC/2009/297 zfs snapshot holds
Chris Kirby <chris.kirby@sun.com>
parents: 10233
diff changeset
  4209
}
c40d075fbca6 PSARC/2009/297 zfs snapshot holds
Chris Kirby <chris.kirby@sun.com>
parents: 10233
diff changeset
  4210
c40d075fbca6 PSARC/2009/297 zfs snapshot holds
Chris Kirby <chris.kirby@sun.com>
parents: 10233
diff changeset
  4211
/*
c40d075fbca6 PSARC/2009/297 zfs snapshot holds
Chris Kirby <chris.kirby@sun.com>
parents: 10233
diff changeset
  4212
 * inputs:
12527
693dd2cad55f 6884007 zfs_send() can leave temporary holds around
Chris Kirby <Chris.Kirby@oracle.com>
parents: 12296
diff changeset
  4213
 * zc_name	name of dataset from which we're releasing a user hold
10242
c40d075fbca6 PSARC/2009/297 zfs snapshot holds
Chris Kirby <chris.kirby@sun.com>
parents: 10233
diff changeset
  4214
 * zc_value	short name of snap
12527
693dd2cad55f 6884007 zfs_send() can leave temporary holds around
Chris Kirby <Chris.Kirby@oracle.com>
parents: 12296
diff changeset
  4215
 * zc_string	user-supplied tag for this hold
10242
c40d075fbca6 PSARC/2009/297 zfs snapshot holds
Chris Kirby <chris.kirby@sun.com>
parents: 10233
diff changeset
  4216
 * zc_cookie	recursive flag
c40d075fbca6 PSARC/2009/297 zfs snapshot holds
Chris Kirby <chris.kirby@sun.com>
parents: 10233
diff changeset
  4217
 *
12527
693dd2cad55f 6884007 zfs_send() can leave temporary holds around
Chris Kirby <Chris.Kirby@oracle.com>
parents: 12296
diff changeset
  4218
 * outputs:	none
10242
c40d075fbca6 PSARC/2009/297 zfs snapshot holds
Chris Kirby <chris.kirby@sun.com>
parents: 10233
diff changeset
  4219
 */
c40d075fbca6 PSARC/2009/297 zfs snapshot holds
Chris Kirby <chris.kirby@sun.com>
parents: 10233
diff changeset
  4220
static int
c40d075fbca6 PSARC/2009/297 zfs snapshot holds
Chris Kirby <chris.kirby@sun.com>
parents: 10233
diff changeset
  4221
zfs_ioc_release(zfs_cmd_t *zc)
c40d075fbca6 PSARC/2009/297 zfs snapshot holds
Chris Kirby <chris.kirby@sun.com>
parents: 10233
diff changeset
  4222
{
c40d075fbca6 PSARC/2009/297 zfs snapshot holds
Chris Kirby <chris.kirby@sun.com>
parents: 10233
diff changeset
  4223
	boolean_t recursive = zc->zc_cookie;
c40d075fbca6 PSARC/2009/297 zfs snapshot holds
Chris Kirby <chris.kirby@sun.com>
parents: 10233
diff changeset
  4224
c40d075fbca6 PSARC/2009/297 zfs snapshot holds
Chris Kirby <chris.kirby@sun.com>
parents: 10233
diff changeset
  4225
	if (snapshot_namecheck(zc->zc_value, NULL, NULL) != 0)
c40d075fbca6 PSARC/2009/297 zfs snapshot holds
Chris Kirby <chris.kirby@sun.com>
parents: 10233
diff changeset
  4226
		return (EINVAL);
c40d075fbca6 PSARC/2009/297 zfs snapshot holds
Chris Kirby <chris.kirby@sun.com>
parents: 10233
diff changeset
  4227
c40d075fbca6 PSARC/2009/297 zfs snapshot holds
Chris Kirby <chris.kirby@sun.com>
parents: 10233
diff changeset
  4228
	return (dsl_dataset_user_release(zc->zc_name, zc->zc_value,
c40d075fbca6 PSARC/2009/297 zfs snapshot holds
Chris Kirby <chris.kirby@sun.com>
parents: 10233
diff changeset
  4229
	    zc->zc_string, recursive));
c40d075fbca6 PSARC/2009/297 zfs snapshot holds
Chris Kirby <chris.kirby@sun.com>
parents: 10233
diff changeset
  4230
}
c40d075fbca6 PSARC/2009/297 zfs snapshot holds
Chris Kirby <chris.kirby@sun.com>
parents: 10233
diff changeset
  4231
c40d075fbca6 PSARC/2009/297 zfs snapshot holds
Chris Kirby <chris.kirby@sun.com>
parents: 10233
diff changeset
  4232
/*
c40d075fbca6 PSARC/2009/297 zfs snapshot holds
Chris Kirby <chris.kirby@sun.com>
parents: 10233
diff changeset
  4233
 * inputs:
c40d075fbca6 PSARC/2009/297 zfs snapshot holds
Chris Kirby <chris.kirby@sun.com>
parents: 10233
diff changeset
  4234
 * zc_name		name of filesystem
c40d075fbca6 PSARC/2009/297 zfs snapshot holds
Chris Kirby <chris.kirby@sun.com>
parents: 10233
diff changeset
  4235
 *
c40d075fbca6 PSARC/2009/297 zfs snapshot holds
Chris Kirby <chris.kirby@sun.com>
parents: 10233
diff changeset
  4236
 * outputs:
c40d075fbca6 PSARC/2009/297 zfs snapshot holds
Chris Kirby <chris.kirby@sun.com>
parents: 10233
diff changeset
  4237
 * zc_nvlist_src{_size}	nvlist of snapshot holds
c40d075fbca6 PSARC/2009/297 zfs snapshot holds
Chris Kirby <chris.kirby@sun.com>
parents: 10233
diff changeset
  4238
 */
c40d075fbca6 PSARC/2009/297 zfs snapshot holds
Chris Kirby <chris.kirby@sun.com>
parents: 10233
diff changeset
  4239
static int
c40d075fbca6 PSARC/2009/297 zfs snapshot holds
Chris Kirby <chris.kirby@sun.com>
parents: 10233
diff changeset
  4240
zfs_ioc_get_holds(zfs_cmd_t *zc)
c40d075fbca6 PSARC/2009/297 zfs snapshot holds
Chris Kirby <chris.kirby@sun.com>
parents: 10233
diff changeset
  4241
{
c40d075fbca6 PSARC/2009/297 zfs snapshot holds
Chris Kirby <chris.kirby@sun.com>
parents: 10233
diff changeset
  4242
	nvlist_t *nvp;
c40d075fbca6 PSARC/2009/297 zfs snapshot holds
Chris Kirby <chris.kirby@sun.com>
parents: 10233
diff changeset
  4243
	int error;
c40d075fbca6 PSARC/2009/297 zfs snapshot holds
Chris Kirby <chris.kirby@sun.com>
parents: 10233
diff changeset
  4244
c40d075fbca6 PSARC/2009/297 zfs snapshot holds
Chris Kirby <chris.kirby@sun.com>
parents: 10233
diff changeset
  4245
	if ((error = dsl_dataset_get_holds(zc->zc_name, &nvp)) == 0) {
c40d075fbca6 PSARC/2009/297 zfs snapshot holds
Chris Kirby <chris.kirby@sun.com>
parents: 10233
diff changeset
  4246
		error = put_nvlist(zc, nvp);
c40d075fbca6 PSARC/2009/297 zfs snapshot holds
Chris Kirby <chris.kirby@sun.com>
parents: 10233
diff changeset
  4247
		nvlist_free(nvp);
c40d075fbca6 PSARC/2009/297 zfs snapshot holds
Chris Kirby <chris.kirby@sun.com>
parents: 10233
diff changeset
  4248
	}
c40d075fbca6 PSARC/2009/297 zfs snapshot holds
Chris Kirby <chris.kirby@sun.com>
parents: 10233
diff changeset
  4249
c40d075fbca6 PSARC/2009/297 zfs snapshot holds
Chris Kirby <chris.kirby@sun.com>
parents: 10233
diff changeset
  4250
	return (error);
c40d075fbca6 PSARC/2009/297 zfs snapshot holds
Chris Kirby <chris.kirby@sun.com>
parents: 10233
diff changeset
  4251
}
c40d075fbca6 PSARC/2009/297 zfs snapshot holds
Chris Kirby <chris.kirby@sun.com>
parents: 10233
diff changeset
  4252
c40d075fbca6 PSARC/2009/297 zfs snapshot holds
Chris Kirby <chris.kirby@sun.com>
parents: 10233
diff changeset
  4253
/*
4988
db8abd9846d4 6595467 libzfs consumers should be allowed to write their own history (or none at all)
ek110237
parents: 4849
diff changeset
  4254
 * 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
  4255
 * 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
  4256
 * do the logging of those commands.
4543
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  4257
 */
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  4258
static zfs_ioc_vec_t zfs_ioc_vec[] = {
9234
bffdc4fc05c4 6792139 recovering from a suspended pool needs some work
George Wilson <George.Wilson@Sun.COM>
parents: 9179
diff changeset
  4259
	{ zfs_ioc_pool_create, zfs_secpolicy_config, POOL_NAME, B_FALSE,
bffdc4fc05c4 6792139 recovering from a suspended pool needs some work
George Wilson <George.Wilson@Sun.COM>
parents: 9179
diff changeset
  4260
	    B_FALSE },
bffdc4fc05c4 6792139 recovering from a suspended pool needs some work
George Wilson <George.Wilson@Sun.COM>
parents: 9179
diff changeset
  4261
	{ zfs_ioc_pool_destroy,	zfs_secpolicy_config, POOL_NAME, B_FALSE,
bffdc4fc05c4 6792139 recovering from a suspended pool needs some work
George Wilson <George.Wilson@Sun.COM>
parents: 9179
diff changeset
  4262
	    B_FALSE },
bffdc4fc05c4 6792139 recovering from a suspended pool needs some work
George Wilson <George.Wilson@Sun.COM>
parents: 9179
diff changeset
  4263
	{ zfs_ioc_pool_import, zfs_secpolicy_config, POOL_NAME, B_TRUE,
bffdc4fc05c4 6792139 recovering from a suspended pool needs some work
George Wilson <George.Wilson@Sun.COM>
parents: 9179
diff changeset
  4264
	    B_FALSE },
bffdc4fc05c4 6792139 recovering from a suspended pool needs some work
George Wilson <George.Wilson@Sun.COM>
parents: 9179
diff changeset
  4265
	{ zfs_ioc_pool_export, zfs_secpolicy_config, POOL_NAME, B_FALSE,
bffdc4fc05c4 6792139 recovering from a suspended pool needs some work
George Wilson <George.Wilson@Sun.COM>
parents: 9179
diff changeset
  4266
	    B_FALSE },
bffdc4fc05c4 6792139 recovering from a suspended pool needs some work
George Wilson <George.Wilson@Sun.COM>
parents: 9179
diff changeset
  4267
	{ zfs_ioc_pool_configs,	zfs_secpolicy_none, NO_NAME, B_FALSE,
bffdc4fc05c4 6792139 recovering from a suspended pool needs some work
George Wilson <George.Wilson@Sun.COM>
parents: 9179
diff changeset
  4268
	    B_FALSE },
bffdc4fc05c4 6792139 recovering from a suspended pool needs some work
George Wilson <George.Wilson@Sun.COM>
parents: 9179
diff changeset
  4269
	{ zfs_ioc_pool_stats, zfs_secpolicy_read, POOL_NAME, B_FALSE,
bffdc4fc05c4 6792139 recovering from a suspended pool needs some work
George Wilson <George.Wilson@Sun.COM>
parents: 9179
diff changeset
  4270
	    B_FALSE },
bffdc4fc05c4 6792139 recovering from a suspended pool needs some work
George Wilson <George.Wilson@Sun.COM>
parents: 9179
diff changeset
  4271
	{ zfs_ioc_pool_tryimport, zfs_secpolicy_config, NO_NAME, B_FALSE,
bffdc4fc05c4 6792139 recovering from a suspended pool needs some work
George Wilson <George.Wilson@Sun.COM>
parents: 9179
diff changeset
  4272
	    B_FALSE },
12296
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 11935
diff changeset
  4273
	{ zfs_ioc_pool_scan, zfs_secpolicy_config, POOL_NAME, B_TRUE,
9234
bffdc4fc05c4 6792139 recovering from a suspended pool needs some work
George Wilson <George.Wilson@Sun.COM>
parents: 9179
diff changeset
  4274
	    B_TRUE },
bffdc4fc05c4 6792139 recovering from a suspended pool needs some work
George Wilson <George.Wilson@Sun.COM>
parents: 9179
diff changeset
  4275
	{ zfs_ioc_pool_freeze, zfs_secpolicy_config, NO_NAME, B_FALSE,
bffdc4fc05c4 6792139 recovering from a suspended pool needs some work
George Wilson <George.Wilson@Sun.COM>
parents: 9179
diff changeset
  4276
	    B_FALSE },
bffdc4fc05c4 6792139 recovering from a suspended pool needs some work
George Wilson <George.Wilson@Sun.COM>
parents: 9179
diff changeset
  4277
	{ zfs_ioc_pool_upgrade,	zfs_secpolicy_config, POOL_NAME, B_TRUE,
bffdc4fc05c4 6792139 recovering from a suspended pool needs some work
George Wilson <George.Wilson@Sun.COM>
parents: 9179
diff changeset
  4278
	    B_TRUE },
bffdc4fc05c4 6792139 recovering from a suspended pool needs some work
George Wilson <George.Wilson@Sun.COM>
parents: 9179
diff changeset
  4279
	{ zfs_ioc_pool_get_history, zfs_secpolicy_config, POOL_NAME, B_FALSE,
bffdc4fc05c4 6792139 recovering from a suspended pool needs some work
George Wilson <George.Wilson@Sun.COM>
parents: 9179
diff changeset
  4280
	    B_FALSE },
bffdc4fc05c4 6792139 recovering from a suspended pool needs some work
George Wilson <George.Wilson@Sun.COM>
parents: 9179
diff changeset
  4281
	{ zfs_ioc_vdev_add, zfs_secpolicy_config, POOL_NAME, B_TRUE,
bffdc4fc05c4 6792139 recovering from a suspended pool needs some work
George Wilson <George.Wilson@Sun.COM>
parents: 9179
diff changeset
  4282
	    B_TRUE },
bffdc4fc05c4 6792139 recovering from a suspended pool needs some work
George Wilson <George.Wilson@Sun.COM>
parents: 9179
diff changeset
  4283
	{ zfs_ioc_vdev_remove, zfs_secpolicy_config, POOL_NAME, B_TRUE,
bffdc4fc05c4 6792139 recovering from a suspended pool needs some work
George Wilson <George.Wilson@Sun.COM>
parents: 9179
diff changeset
  4284
	    B_TRUE },
bffdc4fc05c4 6792139 recovering from a suspended pool needs some work
George Wilson <George.Wilson@Sun.COM>
parents: 9179
diff changeset
  4285
	{ zfs_ioc_vdev_set_state, zfs_secpolicy_config,	POOL_NAME, B_TRUE,
bffdc4fc05c4 6792139 recovering from a suspended pool needs some work
George Wilson <George.Wilson@Sun.COM>
parents: 9179
diff changeset
  4286
	    B_FALSE },
bffdc4fc05c4 6792139 recovering from a suspended pool needs some work
George Wilson <George.Wilson@Sun.COM>
parents: 9179
diff changeset
  4287
	{ zfs_ioc_vdev_attach, zfs_secpolicy_config, POOL_NAME, B_TRUE,
bffdc4fc05c4 6792139 recovering from a suspended pool needs some work
George Wilson <George.Wilson@Sun.COM>
parents: 9179
diff changeset
  4288
	    B_TRUE },
bffdc4fc05c4 6792139 recovering from a suspended pool needs some work
George Wilson <George.Wilson@Sun.COM>
parents: 9179
diff changeset
  4289
	{ zfs_ioc_vdev_detach, zfs_secpolicy_config, POOL_NAME, B_TRUE,
bffdc4fc05c4 6792139 recovering from a suspended pool needs some work
George Wilson <George.Wilson@Sun.COM>
parents: 9179
diff changeset
  4290
	    B_TRUE },
bffdc4fc05c4 6792139 recovering from a suspended pool needs some work
George Wilson <George.Wilson@Sun.COM>
parents: 9179
diff changeset
  4291
	{ zfs_ioc_vdev_setpath,	zfs_secpolicy_config, POOL_NAME, B_FALSE,
bffdc4fc05c4 6792139 recovering from a suspended pool needs some work
George Wilson <George.Wilson@Sun.COM>
parents: 9179
diff changeset
  4292
	    B_TRUE },
9425
e7ffacaec3a8 6799895 spa_add_spares() needs to be protected by config lock
Eric Schrock <Eric.Schrock@Sun.COM>
parents: 9396
diff changeset
  4293
	{ zfs_ioc_vdev_setfru,	zfs_secpolicy_config, POOL_NAME, B_FALSE,
e7ffacaec3a8 6799895 spa_add_spares() needs to be protected by config lock
Eric Schrock <Eric.Schrock@Sun.COM>
parents: 9396
diff changeset
  4294
	    B_TRUE },
9234
bffdc4fc05c4 6792139 recovering from a suspended pool needs some work
George Wilson <George.Wilson@Sun.COM>
parents: 9179
diff changeset
  4295
	{ zfs_ioc_objset_stats,	zfs_secpolicy_read, DATASET_NAME, B_FALSE,
11454
6e69bacc1a5a 6898245 suspended zpool should not cause rest of the zfs/zpool commands to hang
Sanjeev Bagewadi <Sanjeev.Bagewadi@Sun.COM>
parents: 11422
diff changeset
  4296
	    B_TRUE },
9234
bffdc4fc05c4 6792139 recovering from a suspended pool needs some work
George Wilson <George.Wilson@Sun.COM>
parents: 9179
diff changeset
  4297
	{ zfs_ioc_objset_zplprops, zfs_secpolicy_read, DATASET_NAME, B_FALSE,
bffdc4fc05c4 6792139 recovering from a suspended pool needs some work
George Wilson <George.Wilson@Sun.COM>
parents: 9179
diff changeset
  4298
	    B_FALSE },
bffdc4fc05c4 6792139 recovering from a suspended pool needs some work
George Wilson <George.Wilson@Sun.COM>
parents: 9179
diff changeset
  4299
	{ zfs_ioc_dataset_list_next, zfs_secpolicy_read, DATASET_NAME, B_FALSE,
11454
6e69bacc1a5a 6898245 suspended zpool should not cause rest of the zfs/zpool commands to hang
Sanjeev Bagewadi <Sanjeev.Bagewadi@Sun.COM>
parents: 11422
diff changeset
  4300
	    B_TRUE },
9234
bffdc4fc05c4 6792139 recovering from a suspended pool needs some work
George Wilson <George.Wilson@Sun.COM>
parents: 9179
diff changeset
  4301
	{ zfs_ioc_snapshot_list_next, zfs_secpolicy_read, DATASET_NAME, B_FALSE,
11454
6e69bacc1a5a 6898245 suspended zpool should not cause rest of the zfs/zpool commands to hang
Sanjeev Bagewadi <Sanjeev.Bagewadi@Sun.COM>
parents: 11422
diff changeset
  4302
	    B_TRUE },
9234
bffdc4fc05c4 6792139 recovering from a suspended pool needs some work
George Wilson <George.Wilson@Sun.COM>
parents: 9179
diff changeset
  4303
	{ zfs_ioc_set_prop, zfs_secpolicy_none, DATASET_NAME, B_TRUE, B_TRUE },
bffdc4fc05c4 6792139 recovering from a suspended pool needs some work
George Wilson <George.Wilson@Sun.COM>
parents: 9179
diff changeset
  4304
	{ zfs_ioc_create, zfs_secpolicy_create, DATASET_NAME, B_TRUE, B_TRUE },
bffdc4fc05c4 6792139 recovering from a suspended pool needs some work
George Wilson <George.Wilson@Sun.COM>
parents: 9179
diff changeset
  4305
	{ zfs_ioc_destroy, zfs_secpolicy_destroy, DATASET_NAME, B_TRUE,
bffdc4fc05c4 6792139 recovering from a suspended pool needs some work
George Wilson <George.Wilson@Sun.COM>
parents: 9179
diff changeset
  4306
	    B_TRUE},
bffdc4fc05c4 6792139 recovering from a suspended pool needs some work
George Wilson <George.Wilson@Sun.COM>
parents: 9179
diff changeset
  4307
	{ zfs_ioc_rollback, zfs_secpolicy_rollback, DATASET_NAME, B_TRUE,
bffdc4fc05c4 6792139 recovering from a suspended pool needs some work
George Wilson <George.Wilson@Sun.COM>
parents: 9179
diff changeset
  4308
	    B_TRUE },
bffdc4fc05c4 6792139 recovering from a suspended pool needs some work
George Wilson <George.Wilson@Sun.COM>
parents: 9179
diff changeset
  4309
	{ zfs_ioc_rename, zfs_secpolicy_rename,	DATASET_NAME, B_TRUE, B_TRUE },
bffdc4fc05c4 6792139 recovering from a suspended pool needs some work
George Wilson <George.Wilson@Sun.COM>
parents: 9179
diff changeset
  4310
	{ zfs_ioc_recv, zfs_secpolicy_receive, DATASET_NAME, B_TRUE, B_TRUE },
bffdc4fc05c4 6792139 recovering from a suspended pool needs some work
George Wilson <George.Wilson@Sun.COM>
parents: 9179
diff changeset
  4311
	{ zfs_ioc_send, zfs_secpolicy_send, DATASET_NAME, B_TRUE, B_FALSE },
bffdc4fc05c4 6792139 recovering from a suspended pool needs some work
George Wilson <George.Wilson@Sun.COM>
parents: 9179
diff changeset
  4312
	{ zfs_ioc_inject_fault,	zfs_secpolicy_inject, NO_NAME, B_FALSE,
bffdc4fc05c4 6792139 recovering from a suspended pool needs some work
George Wilson <George.Wilson@Sun.COM>
parents: 9179
diff changeset
  4313
	    B_FALSE },
bffdc4fc05c4 6792139 recovering from a suspended pool needs some work
George Wilson <George.Wilson@Sun.COM>
parents: 9179
diff changeset
  4314
	{ zfs_ioc_clear_fault, zfs_secpolicy_inject, NO_NAME, B_FALSE,
bffdc4fc05c4 6792139 recovering from a suspended pool needs some work
George Wilson <George.Wilson@Sun.COM>
parents: 9179
diff changeset
  4315
	    B_FALSE },
bffdc4fc05c4 6792139 recovering from a suspended pool needs some work
George Wilson <George.Wilson@Sun.COM>
parents: 9179
diff changeset
  4316
	{ zfs_ioc_inject_list_next, zfs_secpolicy_inject, NO_NAME, B_FALSE,
bffdc4fc05c4 6792139 recovering from a suspended pool needs some work
George Wilson <George.Wilson@Sun.COM>
parents: 9179
diff changeset
  4317
	    B_FALSE },
bffdc4fc05c4 6792139 recovering from a suspended pool needs some work
George Wilson <George.Wilson@Sun.COM>
parents: 9179
diff changeset
  4318
	{ zfs_ioc_error_log, zfs_secpolicy_inject, POOL_NAME, B_FALSE,
bffdc4fc05c4 6792139 recovering from a suspended pool needs some work
George Wilson <George.Wilson@Sun.COM>
parents: 9179
diff changeset
  4319
	    B_FALSE },
bffdc4fc05c4 6792139 recovering from a suspended pool needs some work
George Wilson <George.Wilson@Sun.COM>
parents: 9179
diff changeset
  4320
	{ zfs_ioc_clear, zfs_secpolicy_config, POOL_NAME, B_TRUE, B_FALSE },
bffdc4fc05c4 6792139 recovering from a suspended pool needs some work
George Wilson <George.Wilson@Sun.COM>
parents: 9179
diff changeset
  4321
	{ zfs_ioc_promote, zfs_secpolicy_promote, DATASET_NAME, B_TRUE,
bffdc4fc05c4 6792139 recovering from a suspended pool needs some work
George Wilson <George.Wilson@Sun.COM>
parents: 9179
diff changeset
  4322
	    B_TRUE },
11314
489ae7372a1f 6901122 destroy snapshot by delegated user succeeds without descendent permissions when -r or -R used.
William Gorrell <william.gorrell@sun.com>
parents: 11209
diff changeset
  4323
	{ zfs_ioc_destroy_snaps, zfs_secpolicy_destroy_snaps, DATASET_NAME,
489ae7372a1f 6901122 destroy snapshot by delegated user succeeds without descendent permissions when -r or -R used.
William Gorrell <william.gorrell@sun.com>
parents: 11209
diff changeset
  4324
	    B_TRUE, B_TRUE },
9234
bffdc4fc05c4 6792139 recovering from a suspended pool needs some work
George Wilson <George.Wilson@Sun.COM>
parents: 9179
diff changeset
  4325
	{ zfs_ioc_snapshot, zfs_secpolicy_snapshot, DATASET_NAME, B_TRUE,
bffdc4fc05c4 6792139 recovering from a suspended pool needs some work
George Wilson <George.Wilson@Sun.COM>
parents: 9179
diff changeset
  4326
	    B_TRUE },
bffdc4fc05c4 6792139 recovering from a suspended pool needs some work
George Wilson <George.Wilson@Sun.COM>
parents: 9179
diff changeset
  4327
	{ zfs_ioc_dsobj_to_dsname, zfs_secpolicy_config, POOL_NAME, B_FALSE,
bffdc4fc05c4 6792139 recovering from a suspended pool needs some work
George Wilson <George.Wilson@Sun.COM>
parents: 9179
diff changeset
  4328
	    B_FALSE },
10233
620468fcb233 6843474 zpool status -v hangs when all disks are unavailable
George Wilson <George.Wilson@Sun.COM>
parents: 10204
diff changeset
  4329
	{ zfs_ioc_obj_to_path, zfs_secpolicy_config, DATASET_NAME, B_FALSE,
620468fcb233 6843474 zpool status -v hangs when all disks are unavailable
George Wilson <George.Wilson@Sun.COM>
parents: 10204
diff changeset
  4330
	    B_TRUE },
9234
bffdc4fc05c4 6792139 recovering from a suspended pool needs some work
George Wilson <George.Wilson@Sun.COM>
parents: 9179
diff changeset
  4331
	{ zfs_ioc_pool_set_props, zfs_secpolicy_config,	POOL_NAME, B_TRUE,
bffdc4fc05c4 6792139 recovering from a suspended pool needs some work
George Wilson <George.Wilson@Sun.COM>
parents: 9179
diff changeset
  4332
	    B_TRUE },
bffdc4fc05c4 6792139 recovering from a suspended pool needs some work
George Wilson <George.Wilson@Sun.COM>
parents: 9179
diff changeset
  4333
	{ zfs_ioc_pool_get_props, zfs_secpolicy_read, POOL_NAME, B_FALSE,
bffdc4fc05c4 6792139 recovering from a suspended pool needs some work
George Wilson <George.Wilson@Sun.COM>
parents: 9179
diff changeset
  4334
	    B_FALSE },
bffdc4fc05c4 6792139 recovering from a suspended pool needs some work
George Wilson <George.Wilson@Sun.COM>
parents: 9179
diff changeset
  4335
	{ zfs_ioc_set_fsacl, zfs_secpolicy_fsacl, DATASET_NAME, B_TRUE,
bffdc4fc05c4 6792139 recovering from a suspended pool needs some work
George Wilson <George.Wilson@Sun.COM>
parents: 9179
diff changeset
  4336
	    B_TRUE },
bffdc4fc05c4 6792139 recovering from a suspended pool needs some work
George Wilson <George.Wilson@Sun.COM>
parents: 9179
diff changeset
  4337
	{ zfs_ioc_get_fsacl, zfs_secpolicy_read, DATASET_NAME, B_FALSE,
bffdc4fc05c4 6792139 recovering from a suspended pool needs some work
George Wilson <George.Wilson@Sun.COM>
parents: 9179
diff changeset
  4338
	    B_FALSE },
bffdc4fc05c4 6792139 recovering from a suspended pool needs some work
George Wilson <George.Wilson@Sun.COM>
parents: 9179
diff changeset
  4339
	{ zfs_ioc_share, zfs_secpolicy_share, DATASET_NAME, B_FALSE, B_FALSE },
bffdc4fc05c4 6792139 recovering from a suspended pool needs some work
George Wilson <George.Wilson@Sun.COM>
parents: 9179
diff changeset
  4340
	{ zfs_ioc_inherit_prop, zfs_secpolicy_inherit, DATASET_NAME, B_TRUE,
bffdc4fc05c4 6792139 recovering from a suspended pool needs some work
George Wilson <George.Wilson@Sun.COM>
parents: 9179
diff changeset
  4341
	    B_TRUE },
bffdc4fc05c4 6792139 recovering from a suspended pool needs some work
George Wilson <George.Wilson@Sun.COM>
parents: 9179
diff changeset
  4342
	{ zfs_ioc_smb_acl, zfs_secpolicy_smb_acl, DATASET_NAME, B_FALSE,
9396
f41cf682d0d3 PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 9355
diff changeset
  4343
	    B_FALSE },
f41cf682d0d3 PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 9355
diff changeset
  4344
	{ zfs_ioc_userspace_one, zfs_secpolicy_userspace_one,
f41cf682d0d3 PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 9355
diff changeset
  4345
	    DATASET_NAME, B_FALSE, B_FALSE },
f41cf682d0d3 PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 9355
diff changeset
  4346
	{ zfs_ioc_userspace_many, zfs_secpolicy_userspace_many,
f41cf682d0d3 PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 9355
diff changeset
  4347
	    DATASET_NAME, B_FALSE, B_FALSE },
f41cf682d0d3 PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 9355
diff changeset
  4348
	{ zfs_ioc_userspace_upgrade, zfs_secpolicy_userspace_upgrade,
f41cf682d0d3 PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 9355
diff changeset
  4349
	    DATASET_NAME, B_FALSE, B_TRUE },
10242
c40d075fbca6 PSARC/2009/297 zfs snapshot holds
Chris Kirby <chris.kirby@sun.com>
parents: 10233
diff changeset
  4350
	{ zfs_ioc_hold, zfs_secpolicy_hold, DATASET_NAME, B_TRUE, B_TRUE },
c40d075fbca6 PSARC/2009/297 zfs snapshot holds
Chris Kirby <chris.kirby@sun.com>
parents: 10233
diff changeset
  4351
	{ zfs_ioc_release, zfs_secpolicy_release, DATASET_NAME, B_TRUE,
c40d075fbca6 PSARC/2009/297 zfs snapshot holds
Chris Kirby <chris.kirby@sun.com>
parents: 10233
diff changeset
  4352
	    B_TRUE },
c40d075fbca6 PSARC/2009/297 zfs snapshot holds
Chris Kirby <chris.kirby@sun.com>
parents: 10233
diff changeset
  4353
	{ zfs_ioc_get_holds, zfs_secpolicy_read, DATASET_NAME, B_FALSE,
11022
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 11007
diff changeset
  4354
	    B_TRUE },
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 11007
diff changeset
  4355
	{ zfs_ioc_objset_recvd_props, zfs_secpolicy_read, DATASET_NAME, B_FALSE,
11422
42768837421d PSARC/2009/511 zpool split
Mark J Musante <Mark.Musante@Sun.COM>
parents: 11314
diff changeset
  4356
	    B_FALSE },
42768837421d PSARC/2009/511 zpool split
Mark J Musante <Mark.Musante@Sun.COM>
parents: 11314
diff changeset
  4357
	{ zfs_ioc_vdev_split, zfs_secpolicy_config, POOL_NAME, B_TRUE,
42768837421d PSARC/2009/511 zpool split
Mark J Musante <Mark.Musante@Sun.COM>
parents: 11314
diff changeset
  4358
	    B_TRUE }
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  4359
};
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  4360
9234
bffdc4fc05c4 6792139 recovering from a suspended pool needs some work
George Wilson <George.Wilson@Sun.COM>
parents: 9179
diff changeset
  4361
int
bffdc4fc05c4 6792139 recovering from a suspended pool needs some work
George Wilson <George.Wilson@Sun.COM>
parents: 9179
diff changeset
  4362
pool_status_check(const char *name, zfs_ioc_namecheck_t type)
bffdc4fc05c4 6792139 recovering from a suspended pool needs some work
George Wilson <George.Wilson@Sun.COM>
parents: 9179
diff changeset
  4363
{
bffdc4fc05c4 6792139 recovering from a suspended pool needs some work
George Wilson <George.Wilson@Sun.COM>
parents: 9179
diff changeset
  4364
	spa_t *spa;
bffdc4fc05c4 6792139 recovering from a suspended pool needs some work
George Wilson <George.Wilson@Sun.COM>
parents: 9179
diff changeset
  4365
	int error;
bffdc4fc05c4 6792139 recovering from a suspended pool needs some work
George Wilson <George.Wilson@Sun.COM>
parents: 9179
diff changeset
  4366
bffdc4fc05c4 6792139 recovering from a suspended pool needs some work
George Wilson <George.Wilson@Sun.COM>
parents: 9179
diff changeset
  4367
	ASSERT(type == POOL_NAME || type == DATASET_NAME);
bffdc4fc05c4 6792139 recovering from a suspended pool needs some work
George Wilson <George.Wilson@Sun.COM>
parents: 9179
diff changeset
  4368
9396
f41cf682d0d3 PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 9355
diff changeset
  4369
	error = spa_open(name, &spa, FTAG);
9234
bffdc4fc05c4 6792139 recovering from a suspended pool needs some work
George Wilson <George.Wilson@Sun.COM>
parents: 9179
diff changeset
  4370
	if (error == 0) {
bffdc4fc05c4 6792139 recovering from a suspended pool needs some work
George Wilson <George.Wilson@Sun.COM>
parents: 9179
diff changeset
  4371
		if (spa_suspended(spa))
bffdc4fc05c4 6792139 recovering from a suspended pool needs some work
George Wilson <George.Wilson@Sun.COM>
parents: 9179
diff changeset
  4372
			error = EAGAIN;
bffdc4fc05c4 6792139 recovering from a suspended pool needs some work
George Wilson <George.Wilson@Sun.COM>
parents: 9179
diff changeset
  4373
		spa_close(spa, FTAG);
bffdc4fc05c4 6792139 recovering from a suspended pool needs some work
George Wilson <George.Wilson@Sun.COM>
parents: 9179
diff changeset
  4374
	}
bffdc4fc05c4 6792139 recovering from a suspended pool needs some work
George Wilson <George.Wilson@Sun.COM>
parents: 9179
diff changeset
  4375
	return (error);
bffdc4fc05c4 6792139 recovering from a suspended pool needs some work
George Wilson <George.Wilson@Sun.COM>
parents: 9179
diff changeset
  4376
}
bffdc4fc05c4 6792139 recovering from a suspended pool needs some work
George Wilson <George.Wilson@Sun.COM>
parents: 9179
diff changeset
  4377
12527
693dd2cad55f 6884007 zfs_send() can leave temporary holds around
Chris Kirby <Chris.Kirby@oracle.com>
parents: 12296
diff changeset
  4378
/*
693dd2cad55f 6884007 zfs_send() can leave temporary holds around
Chris Kirby <Chris.Kirby@oracle.com>
parents: 12296
diff changeset
  4379
 * Find a free minor number.
693dd2cad55f 6884007 zfs_send() can leave temporary holds around
Chris Kirby <Chris.Kirby@oracle.com>
parents: 12296
diff changeset
  4380
 */
693dd2cad55f 6884007 zfs_send() can leave temporary holds around
Chris Kirby <Chris.Kirby@oracle.com>
parents: 12296
diff changeset
  4381
minor_t
693dd2cad55f 6884007 zfs_send() can leave temporary holds around
Chris Kirby <Chris.Kirby@oracle.com>
parents: 12296
diff changeset
  4382
zfsdev_minor_alloc(void)
693dd2cad55f 6884007 zfs_send() can leave temporary holds around
Chris Kirby <Chris.Kirby@oracle.com>
parents: 12296
diff changeset
  4383
{
693dd2cad55f 6884007 zfs_send() can leave temporary holds around
Chris Kirby <Chris.Kirby@oracle.com>
parents: 12296
diff changeset
  4384
	static minor_t last_minor;
693dd2cad55f 6884007 zfs_send() can leave temporary holds around
Chris Kirby <Chris.Kirby@oracle.com>
parents: 12296
diff changeset
  4385
	minor_t m;
693dd2cad55f 6884007 zfs_send() can leave temporary holds around
Chris Kirby <Chris.Kirby@oracle.com>
parents: 12296
diff changeset
  4386
693dd2cad55f 6884007 zfs_send() can leave temporary holds around
Chris Kirby <Chris.Kirby@oracle.com>
parents: 12296
diff changeset
  4387
	ASSERT(MUTEX_HELD(&zfsdev_state_lock));
693dd2cad55f 6884007 zfs_send() can leave temporary holds around
Chris Kirby <Chris.Kirby@oracle.com>
parents: 12296
diff changeset
  4388
693dd2cad55f 6884007 zfs_send() can leave temporary holds around
Chris Kirby <Chris.Kirby@oracle.com>
parents: 12296
diff changeset
  4389
	for (m = last_minor + 1; m != last_minor; m++) {
693dd2cad55f 6884007 zfs_send() can leave temporary holds around
Chris Kirby <Chris.Kirby@oracle.com>
parents: 12296
diff changeset
  4390
		if (m > ZFSDEV_MAX_MINOR)
693dd2cad55f 6884007 zfs_send() can leave temporary holds around
Chris Kirby <Chris.Kirby@oracle.com>
parents: 12296
diff changeset
  4391
			m = 1;
693dd2cad55f 6884007 zfs_send() can leave temporary holds around
Chris Kirby <Chris.Kirby@oracle.com>
parents: 12296
diff changeset
  4392
		if (ddi_get_soft_state(zfsdev_state, m) == NULL) {
693dd2cad55f 6884007 zfs_send() can leave temporary holds around
Chris Kirby <Chris.Kirby@oracle.com>
parents: 12296
diff changeset
  4393
			last_minor = m;
693dd2cad55f 6884007 zfs_send() can leave temporary holds around
Chris Kirby <Chris.Kirby@oracle.com>
parents: 12296
diff changeset
  4394
			return (m);
693dd2cad55f 6884007 zfs_send() can leave temporary holds around
Chris Kirby <Chris.Kirby@oracle.com>
parents: 12296
diff changeset
  4395
		}
693dd2cad55f 6884007 zfs_send() can leave temporary holds around
Chris Kirby <Chris.Kirby@oracle.com>
parents: 12296
diff changeset
  4396
	}
693dd2cad55f 6884007 zfs_send() can leave temporary holds around
Chris Kirby <Chris.Kirby@oracle.com>
parents: 12296
diff changeset
  4397
693dd2cad55f 6884007 zfs_send() can leave temporary holds around
Chris Kirby <Chris.Kirby@oracle.com>
parents: 12296
diff changeset
  4398
	return (0);
693dd2cad55f 6884007 zfs_send() can leave temporary holds around
Chris Kirby <Chris.Kirby@oracle.com>
parents: 12296
diff changeset
  4399
}
693dd2cad55f 6884007 zfs_send() can leave temporary holds around
Chris Kirby <Chris.Kirby@oracle.com>
parents: 12296
diff changeset
  4400
693dd2cad55f 6884007 zfs_send() can leave temporary holds around
Chris Kirby <Chris.Kirby@oracle.com>
parents: 12296
diff changeset
  4401
static int
693dd2cad55f 6884007 zfs_send() can leave temporary holds around
Chris Kirby <Chris.Kirby@oracle.com>
parents: 12296
diff changeset
  4402
zfs_ctldev_init(dev_t *devp)
693dd2cad55f 6884007 zfs_send() can leave temporary holds around
Chris Kirby <Chris.Kirby@oracle.com>
parents: 12296
diff changeset
  4403
{
693dd2cad55f 6884007 zfs_send() can leave temporary holds around
Chris Kirby <Chris.Kirby@oracle.com>
parents: 12296
diff changeset
  4404
	minor_t minor;
693dd2cad55f 6884007 zfs_send() can leave temporary holds around
Chris Kirby <Chris.Kirby@oracle.com>
parents: 12296
diff changeset
  4405
	zfs_soft_state_t *zs;
693dd2cad55f 6884007 zfs_send() can leave temporary holds around
Chris Kirby <Chris.Kirby@oracle.com>
parents: 12296
diff changeset
  4406
693dd2cad55f 6884007 zfs_send() can leave temporary holds around
Chris Kirby <Chris.Kirby@oracle.com>
parents: 12296
diff changeset
  4407
	ASSERT(MUTEX_HELD(&zfsdev_state_lock));
693dd2cad55f 6884007 zfs_send() can leave temporary holds around
Chris Kirby <Chris.Kirby@oracle.com>
parents: 12296
diff changeset
  4408
	ASSERT(getminor(*devp) == 0);
693dd2cad55f 6884007 zfs_send() can leave temporary holds around
Chris Kirby <Chris.Kirby@oracle.com>
parents: 12296
diff changeset
  4409
693dd2cad55f 6884007 zfs_send() can leave temporary holds around
Chris Kirby <Chris.Kirby@oracle.com>
parents: 12296
diff changeset
  4410
	minor = zfsdev_minor_alloc();
693dd2cad55f 6884007 zfs_send() can leave temporary holds around
Chris Kirby <Chris.Kirby@oracle.com>
parents: 12296
diff changeset
  4411
	if (minor == 0)
693dd2cad55f 6884007 zfs_send() can leave temporary holds around
Chris Kirby <Chris.Kirby@oracle.com>
parents: 12296
diff changeset
  4412
		return (ENXIO);
693dd2cad55f 6884007 zfs_send() can leave temporary holds around
Chris Kirby <Chris.Kirby@oracle.com>
parents: 12296
diff changeset
  4413
693dd2cad55f 6884007 zfs_send() can leave temporary holds around
Chris Kirby <Chris.Kirby@oracle.com>
parents: 12296
diff changeset
  4414
	if (ddi_soft_state_zalloc(zfsdev_state, minor) != DDI_SUCCESS)
693dd2cad55f 6884007 zfs_send() can leave temporary holds around
Chris Kirby <Chris.Kirby@oracle.com>
parents: 12296
diff changeset
  4415
		return (EAGAIN);
693dd2cad55f 6884007 zfs_send() can leave temporary holds around
Chris Kirby <Chris.Kirby@oracle.com>
parents: 12296
diff changeset
  4416
693dd2cad55f 6884007 zfs_send() can leave temporary holds around
Chris Kirby <Chris.Kirby@oracle.com>
parents: 12296
diff changeset
  4417
	*devp = makedevice(getemajor(*devp), minor);
693dd2cad55f 6884007 zfs_send() can leave temporary holds around
Chris Kirby <Chris.Kirby@oracle.com>
parents: 12296
diff changeset
  4418
693dd2cad55f 6884007 zfs_send() can leave temporary holds around
Chris Kirby <Chris.Kirby@oracle.com>
parents: 12296
diff changeset
  4419
	zs = ddi_get_soft_state(zfsdev_state, minor);
693dd2cad55f 6884007 zfs_send() can leave temporary holds around
Chris Kirby <Chris.Kirby@oracle.com>
parents: 12296
diff changeset
  4420
	zs->zss_type = ZSST_CTLDEV;
693dd2cad55f 6884007 zfs_send() can leave temporary holds around
Chris Kirby <Chris.Kirby@oracle.com>
parents: 12296
diff changeset
  4421
	zfs_onexit_init((zfs_onexit_t **)&zs->zss_data);
693dd2cad55f 6884007 zfs_send() can leave temporary holds around
Chris Kirby <Chris.Kirby@oracle.com>
parents: 12296
diff changeset
  4422
693dd2cad55f 6884007 zfs_send() can leave temporary holds around
Chris Kirby <Chris.Kirby@oracle.com>
parents: 12296
diff changeset
  4423
	return (0);
693dd2cad55f 6884007 zfs_send() can leave temporary holds around
Chris Kirby <Chris.Kirby@oracle.com>
parents: 12296
diff changeset
  4424
}
693dd2cad55f 6884007 zfs_send() can leave temporary holds around
Chris Kirby <Chris.Kirby@oracle.com>
parents: 12296
diff changeset
  4425
693dd2cad55f 6884007 zfs_send() can leave temporary holds around
Chris Kirby <Chris.Kirby@oracle.com>
parents: 12296
diff changeset
  4426
static void
693dd2cad55f 6884007 zfs_send() can leave temporary holds around
Chris Kirby <Chris.Kirby@oracle.com>
parents: 12296
diff changeset
  4427
zfs_ctldev_destroy(zfs_onexit_t *zo, minor_t minor)
693dd2cad55f 6884007 zfs_send() can leave temporary holds around
Chris Kirby <Chris.Kirby@oracle.com>
parents: 12296
diff changeset
  4428
{
693dd2cad55f 6884007 zfs_send() can leave temporary holds around
Chris Kirby <Chris.Kirby@oracle.com>
parents: 12296
diff changeset
  4429
	ASSERT(MUTEX_HELD(&zfsdev_state_lock));
693dd2cad55f 6884007 zfs_send() can leave temporary holds around
Chris Kirby <Chris.Kirby@oracle.com>
parents: 12296
diff changeset
  4430
693dd2cad55f 6884007 zfs_send() can leave temporary holds around
Chris Kirby <Chris.Kirby@oracle.com>
parents: 12296
diff changeset
  4431
	zfs_onexit_destroy(zo);
693dd2cad55f 6884007 zfs_send() can leave temporary holds around
Chris Kirby <Chris.Kirby@oracle.com>
parents: 12296
diff changeset
  4432
	ddi_soft_state_free(zfsdev_state, minor);
693dd2cad55f 6884007 zfs_send() can leave temporary holds around
Chris Kirby <Chris.Kirby@oracle.com>
parents: 12296
diff changeset
  4433
}
693dd2cad55f 6884007 zfs_send() can leave temporary holds around
Chris Kirby <Chris.Kirby@oracle.com>
parents: 12296
diff changeset
  4434
693dd2cad55f 6884007 zfs_send() can leave temporary holds around
Chris Kirby <Chris.Kirby@oracle.com>
parents: 12296
diff changeset
  4435
void *
693dd2cad55f 6884007 zfs_send() can leave temporary holds around
Chris Kirby <Chris.Kirby@oracle.com>
parents: 12296
diff changeset
  4436
zfsdev_get_soft_state(minor_t minor, enum zfs_soft_state_type which)
693dd2cad55f 6884007 zfs_send() can leave temporary holds around
Chris Kirby <Chris.Kirby@oracle.com>
parents: 12296
diff changeset
  4437
{
693dd2cad55f 6884007 zfs_send() can leave temporary holds around
Chris Kirby <Chris.Kirby@oracle.com>
parents: 12296
diff changeset
  4438
	zfs_soft_state_t *zp;
693dd2cad55f 6884007 zfs_send() can leave temporary holds around
Chris Kirby <Chris.Kirby@oracle.com>
parents: 12296
diff changeset
  4439
693dd2cad55f 6884007 zfs_send() can leave temporary holds around
Chris Kirby <Chris.Kirby@oracle.com>
parents: 12296
diff changeset
  4440
	zp = ddi_get_soft_state(zfsdev_state, minor);
693dd2cad55f 6884007 zfs_send() can leave temporary holds around
Chris Kirby <Chris.Kirby@oracle.com>
parents: 12296
diff changeset
  4441
	if (zp == NULL || zp->zss_type != which)
693dd2cad55f 6884007 zfs_send() can leave temporary holds around
Chris Kirby <Chris.Kirby@oracle.com>
parents: 12296
diff changeset
  4442
		return (NULL);
693dd2cad55f 6884007 zfs_send() can leave temporary holds around
Chris Kirby <Chris.Kirby@oracle.com>
parents: 12296
diff changeset
  4443
693dd2cad55f 6884007 zfs_send() can leave temporary holds around
Chris Kirby <Chris.Kirby@oracle.com>
parents: 12296
diff changeset
  4444
	return (zp->zss_data);
693dd2cad55f 6884007 zfs_send() can leave temporary holds around
Chris Kirby <Chris.Kirby@oracle.com>
parents: 12296
diff changeset
  4445
}
693dd2cad55f 6884007 zfs_send() can leave temporary holds around
Chris Kirby <Chris.Kirby@oracle.com>
parents: 12296
diff changeset
  4446
693dd2cad55f 6884007 zfs_send() can leave temporary holds around
Chris Kirby <Chris.Kirby@oracle.com>
parents: 12296
diff changeset
  4447
static int
693dd2cad55f 6884007 zfs_send() can leave temporary holds around
Chris Kirby <Chris.Kirby@oracle.com>
parents: 12296
diff changeset
  4448
zfsdev_open(dev_t *devp, int flag, int otyp, cred_t *cr)
693dd2cad55f 6884007 zfs_send() can leave temporary holds around
Chris Kirby <Chris.Kirby@oracle.com>
parents: 12296
diff changeset
  4449
{
693dd2cad55f 6884007 zfs_send() can leave temporary holds around
Chris Kirby <Chris.Kirby@oracle.com>
parents: 12296
diff changeset
  4450
	int error = 0;
693dd2cad55f 6884007 zfs_send() can leave temporary holds around
Chris Kirby <Chris.Kirby@oracle.com>
parents: 12296
diff changeset
  4451
693dd2cad55f 6884007 zfs_send() can leave temporary holds around
Chris Kirby <Chris.Kirby@oracle.com>
parents: 12296
diff changeset
  4452
	if (getminor(*devp) != 0)
693dd2cad55f 6884007 zfs_send() can leave temporary holds around
Chris Kirby <Chris.Kirby@oracle.com>
parents: 12296
diff changeset
  4453
		return (zvol_open(devp, flag, otyp, cr));
693dd2cad55f 6884007 zfs_send() can leave temporary holds around
Chris Kirby <Chris.Kirby@oracle.com>
parents: 12296
diff changeset
  4454
693dd2cad55f 6884007 zfs_send() can leave temporary holds around
Chris Kirby <Chris.Kirby@oracle.com>
parents: 12296
diff changeset
  4455
	/* This is the control device. Allocate a new minor if requested. */
693dd2cad55f 6884007 zfs_send() can leave temporary holds around
Chris Kirby <Chris.Kirby@oracle.com>
parents: 12296
diff changeset
  4456
	if (flag & FEXCL) {
693dd2cad55f 6884007 zfs_send() can leave temporary holds around
Chris Kirby <Chris.Kirby@oracle.com>
parents: 12296
diff changeset
  4457
		mutex_enter(&zfsdev_state_lock);
693dd2cad55f 6884007 zfs_send() can leave temporary holds around
Chris Kirby <Chris.Kirby@oracle.com>
parents: 12296
diff changeset
  4458
		error = zfs_ctldev_init(devp);
693dd2cad55f 6884007 zfs_send() can leave temporary holds around
Chris Kirby <Chris.Kirby@oracle.com>
parents: 12296
diff changeset
  4459
		mutex_exit(&zfsdev_state_lock);
693dd2cad55f 6884007 zfs_send() can leave temporary holds around
Chris Kirby <Chris.Kirby@oracle.com>
parents: 12296
diff changeset
  4460
	}
693dd2cad55f 6884007 zfs_send() can leave temporary holds around
Chris Kirby <Chris.Kirby@oracle.com>
parents: 12296
diff changeset
  4461
693dd2cad55f 6884007 zfs_send() can leave temporary holds around
Chris Kirby <Chris.Kirby@oracle.com>
parents: 12296
diff changeset
  4462
	return (error);
693dd2cad55f 6884007 zfs_send() can leave temporary holds around
Chris Kirby <Chris.Kirby@oracle.com>
parents: 12296
diff changeset
  4463
}
693dd2cad55f 6884007 zfs_send() can leave temporary holds around
Chris Kirby <Chris.Kirby@oracle.com>
parents: 12296
diff changeset
  4464
693dd2cad55f 6884007 zfs_send() can leave temporary holds around
Chris Kirby <Chris.Kirby@oracle.com>
parents: 12296
diff changeset
  4465
static int
693dd2cad55f 6884007 zfs_send() can leave temporary holds around
Chris Kirby <Chris.Kirby@oracle.com>
parents: 12296
diff changeset
  4466
zfsdev_close(dev_t dev, int flag, int otyp, cred_t *cr)
693dd2cad55f 6884007 zfs_send() can leave temporary holds around
Chris Kirby <Chris.Kirby@oracle.com>
parents: 12296
diff changeset
  4467
{
693dd2cad55f 6884007 zfs_send() can leave temporary holds around
Chris Kirby <Chris.Kirby@oracle.com>
parents: 12296
diff changeset
  4468
	zfs_onexit_t *zo;
693dd2cad55f 6884007 zfs_send() can leave temporary holds around
Chris Kirby <Chris.Kirby@oracle.com>
parents: 12296
diff changeset
  4469
	minor_t minor = getminor(dev);
693dd2cad55f 6884007 zfs_send() can leave temporary holds around
Chris Kirby <Chris.Kirby@oracle.com>
parents: 12296
diff changeset
  4470
693dd2cad55f 6884007 zfs_send() can leave temporary holds around
Chris Kirby <Chris.Kirby@oracle.com>
parents: 12296
diff changeset
  4471
	if (minor == 0)
693dd2cad55f 6884007 zfs_send() can leave temporary holds around
Chris Kirby <Chris.Kirby@oracle.com>
parents: 12296
diff changeset
  4472
		return (0);
693dd2cad55f 6884007 zfs_send() can leave temporary holds around
Chris Kirby <Chris.Kirby@oracle.com>
parents: 12296
diff changeset
  4473
693dd2cad55f 6884007 zfs_send() can leave temporary holds around
Chris Kirby <Chris.Kirby@oracle.com>
parents: 12296
diff changeset
  4474
	mutex_enter(&zfsdev_state_lock);
693dd2cad55f 6884007 zfs_send() can leave temporary holds around
Chris Kirby <Chris.Kirby@oracle.com>
parents: 12296
diff changeset
  4475
	zo = zfsdev_get_soft_state(minor, ZSST_CTLDEV);
693dd2cad55f 6884007 zfs_send() can leave temporary holds around
Chris Kirby <Chris.Kirby@oracle.com>
parents: 12296
diff changeset
  4476
	if (zo == NULL) {
693dd2cad55f 6884007 zfs_send() can leave temporary holds around
Chris Kirby <Chris.Kirby@oracle.com>
parents: 12296
diff changeset
  4477
		mutex_exit(&zfsdev_state_lock);
693dd2cad55f 6884007 zfs_send() can leave temporary holds around
Chris Kirby <Chris.Kirby@oracle.com>
parents: 12296
diff changeset
  4478
		return (zvol_close(dev, flag, otyp, cr));
693dd2cad55f 6884007 zfs_send() can leave temporary holds around
Chris Kirby <Chris.Kirby@oracle.com>
parents: 12296
diff changeset
  4479
	}
693dd2cad55f 6884007 zfs_send() can leave temporary holds around
Chris Kirby <Chris.Kirby@oracle.com>
parents: 12296
diff changeset
  4480
	zfs_ctldev_destroy(zo, minor);
693dd2cad55f 6884007 zfs_send() can leave temporary holds around
Chris Kirby <Chris.Kirby@oracle.com>
parents: 12296
diff changeset
  4481
	mutex_exit(&zfsdev_state_lock);
693dd2cad55f 6884007 zfs_send() can leave temporary holds around
Chris Kirby <Chris.Kirby@oracle.com>
parents: 12296
diff changeset
  4482
693dd2cad55f 6884007 zfs_send() can leave temporary holds around
Chris Kirby <Chris.Kirby@oracle.com>
parents: 12296
diff changeset
  4483
	return (0);
693dd2cad55f 6884007 zfs_send() can leave temporary holds around
Chris Kirby <Chris.Kirby@oracle.com>
parents: 12296
diff changeset
  4484
}
693dd2cad55f 6884007 zfs_send() can leave temporary holds around
Chris Kirby <Chris.Kirby@oracle.com>
parents: 12296
diff changeset
  4485
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  4486
static int
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  4487
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
  4488
{
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  4489
	zfs_cmd_t *zc;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  4490
	uint_t vec;
2199
712a788c2dfd PSARC 2006/388 snapshot -r
ahrens
parents: 2082
diff changeset
  4491
	int error, rc;
12527
693dd2cad55f 6884007 zfs_send() can leave temporary holds around
Chris Kirby <Chris.Kirby@oracle.com>
parents: 12296
diff changeset
  4492
	minor_t minor = getminor(dev);
693dd2cad55f 6884007 zfs_send() can leave temporary holds around
Chris Kirby <Chris.Kirby@oracle.com>
parents: 12296
diff changeset
  4493
693dd2cad55f 6884007 zfs_send() can leave temporary holds around
Chris Kirby <Chris.Kirby@oracle.com>
parents: 12296
diff changeset
  4494
	if (minor != 0 &&
693dd2cad55f 6884007 zfs_send() can leave temporary holds around
Chris Kirby <Chris.Kirby@oracle.com>
parents: 12296
diff changeset
  4495
	    zfsdev_get_soft_state(minor, ZSST_CTLDEV) == NULL)
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  4496
		return (zvol_ioctl(dev, cmd, arg, flag, cr, rvalp));
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  4497
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  4498
	vec = cmd - ZFS_IOC;
4787
602d3f97842c 6393351 unique_* could be improved
ahrens
parents: 4720
diff changeset
  4499
	ASSERT3U(getmajor(dev), ==, ddi_driver_major(zfs_dip));
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  4500
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  4501
	if (vec >= sizeof (zfs_ioc_vec) / sizeof (zfs_ioc_vec[0]))
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  4502
		return (EINVAL);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  4503
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  4504
	zc = kmem_zalloc(sizeof (zfs_cmd_t), KM_SLEEP);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  4505
9643
ffd8e7765f02 6736004 zvols need an additional property for comstar support
Eric Taylor <Eric.Taylor@Sun.COM>
parents: 9425
diff changeset
  4506
	error = ddi_copyin((void *)arg, zc, sizeof (zfs_cmd_t), flag);
11807
73a3c0d27389 6911541 'zfs mount' coredump
Sam Falkner <Sam.Falkner@Sun.COM>
parents: 11727
diff changeset
  4507
	if (error != 0)
73a3c0d27389 6911541 'zfs mount' coredump
Sam Falkner <Sam.Falkner@Sun.COM>
parents: 11727
diff changeset
  4508
		error = EFAULT;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  4509
10588
dc03f981ea18 6438937 if 'zfs destroy' fails, it can leave a zvol device link missing
Eric Taylor <Eric.Taylor@Sun.COM>
parents: 10474
diff changeset
  4510
	if ((error == 0) && !(flag & FKIOCTL))
4543
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  4511
		error = zfs_ioc_vec[vec].zvec_secpolicy(zc, cr);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  4512
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  4513
	/*
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  4514
	 * Ensure that all pool/dataset names are valid before we pass down to
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  4515
	 * the lower layers.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  4516
	 */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  4517
	if (error == 0) {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  4518
		zc->zc_name[sizeof (zc->zc_name) - 1] = '\0';
9643
ffd8e7765f02 6736004 zvols need an additional property for comstar support
Eric Taylor <Eric.Taylor@Sun.COM>
parents: 9425
diff changeset
  4519
		zc->zc_iflags = flag & FKIOCTL;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  4520
		switch (zfs_ioc_vec[vec].zvec_namecheck) {
4577
ed36b0e652bc PSARC/2007/328 zfs upgrade
ahrens
parents: 4543
diff changeset
  4521
		case POOL_NAME:
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  4522
			if (pool_namecheck(zc->zc_name, NULL, NULL) != 0)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  4523
				error = EINVAL;
9234
bffdc4fc05c4 6792139 recovering from a suspended pool needs some work
George Wilson <George.Wilson@Sun.COM>
parents: 9179
diff changeset
  4524
			if (zfs_ioc_vec[vec].zvec_pool_check)
bffdc4fc05c4 6792139 recovering from a suspended pool needs some work
George Wilson <George.Wilson@Sun.COM>
parents: 9179
diff changeset
  4525
				error = pool_status_check(zc->zc_name,
bffdc4fc05c4 6792139 recovering from a suspended pool needs some work
George Wilson <George.Wilson@Sun.COM>
parents: 9179
diff changeset
  4526
				    zfs_ioc_vec[vec].zvec_namecheck);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  4527
			break;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  4528
4577
ed36b0e652bc PSARC/2007/328 zfs upgrade
ahrens
parents: 4543
diff changeset
  4529
		case DATASET_NAME:
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  4530
			if (dataset_namecheck(zc->zc_name, NULL, NULL) != 0)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  4531
				error = EINVAL;
9234
bffdc4fc05c4 6792139 recovering from a suspended pool needs some work
George Wilson <George.Wilson@Sun.COM>
parents: 9179
diff changeset
  4532
			if (zfs_ioc_vec[vec].zvec_pool_check)
bffdc4fc05c4 6792139 recovering from a suspended pool needs some work
George Wilson <George.Wilson@Sun.COM>
parents: 9179
diff changeset
  4533
				error = pool_status_check(zc->zc_name,
bffdc4fc05c4 6792139 recovering from a suspended pool needs some work
George Wilson <George.Wilson@Sun.COM>
parents: 9179
diff changeset
  4534
				    zfs_ioc_vec[vec].zvec_namecheck);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  4535
			break;
2856
6f4d5ee1906a 6463348 ZFS code could be more portable
nd150628
parents: 2717
diff changeset
  4536
4577
ed36b0e652bc PSARC/2007/328 zfs upgrade
ahrens
parents: 4543
diff changeset
  4537
		case NO_NAME:
2856
6f4d5ee1906a 6463348 ZFS code could be more portable
nd150628
parents: 2717
diff changeset
  4538
			break;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  4539
		}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  4540
	}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  4541
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  4542
	if (error == 0)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  4543
		error = zfs_ioc_vec[vec].zvec_func(zc);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  4544
9643
ffd8e7765f02 6736004 zvols need an additional property for comstar support
Eric Taylor <Eric.Taylor@Sun.COM>
parents: 9425
diff changeset
  4545
	rc = ddi_copyout(zc, (void *)arg, sizeof (zfs_cmd_t), flag);
4543
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  4546
	if (error == 0) {
11807
73a3c0d27389 6911541 'zfs mount' coredump
Sam Falkner <Sam.Falkner@Sun.COM>
parents: 11727
diff changeset
  4547
		if (rc != 0)
73a3c0d27389 6911541 'zfs mount' coredump
Sam Falkner <Sam.Falkner@Sun.COM>
parents: 11727
diff changeset
  4548
			error = EFAULT;
9396
f41cf682d0d3 PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 9355
diff changeset
  4549
		if (zfs_ioc_vec[vec].zvec_his_log)
4543
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  4550
			zfs_log_history(zc);
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  4551
	}
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  4552
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  4553
	kmem_free(zc, sizeof (zfs_cmd_t));
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  4554
	return (error);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  4555
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  4556
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  4557
static int
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  4558
zfs_attach(dev_info_t *dip, ddi_attach_cmd_t cmd)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  4559
{
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  4560
	if (cmd != DDI_ATTACH)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  4561
		return (DDI_FAILURE);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  4562
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  4563
	if (ddi_create_minor_node(dip, "zfs", S_IFCHR, 0,
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  4564
	    DDI_PSEUDO, 0) == DDI_FAILURE)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  4565
		return (DDI_FAILURE);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  4566
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  4567
	zfs_dip = dip;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  4568
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  4569
	ddi_report_dev(dip);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  4570
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  4571
	return (DDI_SUCCESS);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  4572
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  4573
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  4574
static int
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  4575
zfs_detach(dev_info_t *dip, ddi_detach_cmd_t cmd)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  4576
{
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  4577
	if (spa_busy() || zfs_busy() || zvol_busy())
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  4578
		return (DDI_FAILURE);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  4579
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  4580
	if (cmd != DDI_DETACH)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  4581
		return (DDI_FAILURE);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  4582
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  4583
	zfs_dip = NULL;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  4584
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  4585
	ddi_prop_remove_all(dip);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  4586
	ddi_remove_minor_node(dip, NULL);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  4587
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  4588
	return (DDI_SUCCESS);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  4589
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  4590
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  4591
/*ARGSUSED*/
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  4592
static int
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  4593
zfs_info(dev_info_t *dip, ddi_info_cmd_t infocmd, void *arg, void **result)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  4594
{
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  4595
	switch (infocmd) {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  4596
	case DDI_INFO_DEVT2DEVINFO:
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  4597
		*result = zfs_dip;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  4598
		return (DDI_SUCCESS);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  4599
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  4600
	case DDI_INFO_DEVT2INSTANCE:
849
8d799fd81a9b 6345023 /dev/zfs fails to open once ZFS module is unloaded
bonwick
parents: 789
diff changeset
  4601
		*result = (void *)0;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  4602
		return (DDI_SUCCESS);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  4603
	}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  4604
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  4605
	return (DDI_FAILURE);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  4606
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  4607
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  4608
/*
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  4609
 * OK, so this is a little weird.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  4610
 *
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  4611
 * /dev/zfs is the control node, i.e. minor 0.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  4612
 * /dev/zvol/[r]dsk/pool/dataset are the zvols, minor > 0.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  4613
 *
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  4614
 * /dev/zfs has basically nothing to do except serve up ioctls,
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  4615
 * so most of the standard driver entry points are in zvol.c.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  4616
 */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  4617
static struct cb_ops zfs_cb_ops = {
12527
693dd2cad55f 6884007 zfs_send() can leave temporary holds around
Chris Kirby <Chris.Kirby@oracle.com>
parents: 12296
diff changeset
  4618
	zfsdev_open,	/* open */
693dd2cad55f 6884007 zfs_send() can leave temporary holds around
Chris Kirby <Chris.Kirby@oracle.com>
parents: 12296
diff changeset
  4619
	zfsdev_close,	/* close */
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  4620
	zvol_strategy,	/* strategy */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  4621
	nodev,		/* print */
6423
437422a29d3a PSARC 2006/370 ZFS Boot Support
gw25295
parents: 6139
diff changeset
  4622
	zvol_dump,	/* dump */
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  4623
	zvol_read,	/* read */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  4624
	zvol_write,	/* write */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  4625
	zfsdev_ioctl,	/* ioctl */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  4626
	nodev,		/* devmap */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  4627
	nodev,		/* mmap */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  4628
	nodev,		/* segmap */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  4629
	nochpoll,	/* poll */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  4630
	ddi_prop_op,	/* prop_op */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  4631
	NULL,		/* streamtab */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  4632
	D_NEW | D_MP | D_64BIT,		/* Driver compatibility flag */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  4633
	CB_REV,		/* version */
3638
6b28ebc717aa 6496357 spec_fsync() is useless on devices that do write caching
billm
parents: 3444
diff changeset
  4634
	nodev,		/* async read */
6b28ebc717aa 6496357 spec_fsync() is useless on devices that do write caching
billm
parents: 3444
diff changeset
  4635
	nodev,		/* async write */
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  4636
};
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  4637
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  4638
static struct dev_ops zfs_dev_ops = {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  4639
	DEVO_REV,	/* version */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  4640
	0,		/* refcnt */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  4641
	zfs_info,	/* info */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  4642
	nulldev,	/* identify */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  4643
	nulldev,	/* probe */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  4644
	zfs_attach,	/* attach */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  4645
	zfs_detach,	/* detach */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  4646
	nodev,		/* reset */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  4647
	&zfs_cb_ops,	/* driver operations */
7656
2621e50fdf4a PSARC 2008/382 Fast Reboot
Sherry Moore <Sherry.Moore@Sun.COM>
parents: 7294
diff changeset
  4648
	NULL,		/* no bus operations */
2621e50fdf4a PSARC 2008/382 Fast Reboot
Sherry Moore <Sherry.Moore@Sun.COM>
parents: 7294
diff changeset
  4649
	NULL,		/* power */
2621e50fdf4a PSARC 2008/382 Fast Reboot
Sherry Moore <Sherry.Moore@Sun.COM>
parents: 7294
diff changeset
  4650
	ddi_quiesce_not_needed,	/* quiesce */
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  4651
};
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  4652
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  4653
static struct modldrv zfs_modldrv = {
7656
2621e50fdf4a PSARC 2008/382 Fast Reboot
Sherry Moore <Sherry.Moore@Sun.COM>
parents: 7294
diff changeset
  4654
	&mod_driverops,
2621e50fdf4a PSARC 2008/382 Fast Reboot
Sherry Moore <Sherry.Moore@Sun.COM>
parents: 7294
diff changeset
  4655
	"ZFS storage pool",
2621e50fdf4a PSARC 2008/382 Fast Reboot
Sherry Moore <Sherry.Moore@Sun.COM>
parents: 7294
diff changeset
  4656
	&zfs_dev_ops
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  4657
};
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  4658
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  4659
static struct modlinkage modlinkage = {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  4660
	MODREV_1,
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  4661
	(void *)&zfs_modlfs,
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  4662
	(void *)&zfs_modldrv,
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  4663
	NULL
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  4664
};
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  4665
4720
8edc0d2e6f3f 6535160 Lock contention on zl_lock from zil_commit
fr157268
parents: 4715
diff changeset
  4666
8edc0d2e6f3f 6535160 Lock contention on zl_lock from zil_commit
fr157268
parents: 4715
diff changeset
  4667
uint_t zfs_fsyncer_key;
5326
6752aa2bd5bc 6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents: 5147
diff changeset
  4668
extern uint_t rrw_tsd_key;
4720
8edc0d2e6f3f 6535160 Lock contention on zl_lock from zil_commit
fr157268
parents: 4715
diff changeset
  4669
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  4670
int
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  4671
_init(void)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  4672
{
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  4673
	int error;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  4674
849
8d799fd81a9b 6345023 /dev/zfs fails to open once ZFS module is unloaded
bonwick
parents: 789
diff changeset
  4675
	spa_init(FREAD | FWRITE);
8d799fd81a9b 6345023 /dev/zfs fails to open once ZFS module is unloaded
bonwick
parents: 789
diff changeset
  4676
	zfs_init();
8d799fd81a9b 6345023 /dev/zfs fails to open once ZFS module is unloaded
bonwick
parents: 789
diff changeset
  4677
	zvol_init();
8d799fd81a9b 6345023 /dev/zfs fails to open once ZFS module is unloaded
bonwick
parents: 789
diff changeset
  4678
8d799fd81a9b 6345023 /dev/zfs fails to open once ZFS module is unloaded
bonwick
parents: 789
diff changeset
  4679
	if ((error = mod_install(&modlinkage)) != 0) {
8d799fd81a9b 6345023 /dev/zfs fails to open once ZFS module is unloaded
bonwick
parents: 789
diff changeset
  4680
		zvol_fini();
8d799fd81a9b 6345023 /dev/zfs fails to open once ZFS module is unloaded
bonwick
parents: 789
diff changeset
  4681
		zfs_fini();
8d799fd81a9b 6345023 /dev/zfs fails to open once ZFS module is unloaded
bonwick
parents: 789
diff changeset
  4682
		spa_fini();
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  4683
		return (error);
849
8d799fd81a9b 6345023 /dev/zfs fails to open once ZFS module is unloaded
bonwick
parents: 789
diff changeset
  4684
	}
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  4685
4720
8edc0d2e6f3f 6535160 Lock contention on zl_lock from zil_commit
fr157268
parents: 4715
diff changeset
  4686
	tsd_create(&zfs_fsyncer_key, NULL);
5326
6752aa2bd5bc 6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents: 5147
diff changeset
  4687
	tsd_create(&rrw_tsd_key, NULL);
4720
8edc0d2e6f3f 6535160 Lock contention on zl_lock from zil_commit
fr157268
parents: 4715
diff changeset
  4688
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  4689
	error = ldi_ident_from_mod(&modlinkage, &zfs_li);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  4690
	ASSERT(error == 0);
4543
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  4691
	mutex_init(&zfs_share_lock, NULL, MUTEX_DEFAULT, NULL);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  4692
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  4693
	return (0);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  4694
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  4695
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  4696
int
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  4697
_fini(void)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  4698
{
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  4699
	int error;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  4700
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1485
diff changeset
  4701
	if (spa_busy() || zfs_busy() || zvol_busy() || zio_injection_enabled)
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  4702
		return (EBUSY);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  4703
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  4704
	if ((error = mod_remove(&modlinkage)) != 0)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  4705
		return (error);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  4706
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  4707
	zvol_fini();
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  4708
	zfs_fini();
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  4709
	spa_fini();
5331
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
  4710
	if (zfs_nfsshare_inited)
4543
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  4711
		(void) ddi_modclose(nfs_mod);
5331
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
  4712
	if (zfs_smbshare_inited)
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
  4713
		(void) ddi_modclose(smbsrv_mod);
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5329
diff changeset
  4714
	if (zfs_nfsshare_inited || zfs_smbshare_inited)
4543
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  4715
		(void) ddi_modclose(sharefs_mod);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  4716
4720
8edc0d2e6f3f 6535160 Lock contention on zl_lock from zil_commit
fr157268
parents: 4715
diff changeset
  4717
	tsd_destroy(&zfs_fsyncer_key);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  4718
	ldi_ident_release(zfs_li);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  4719
	zfs_li = NULL;
4543
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  4720
	mutex_destroy(&zfs_share_lock);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  4721
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  4722
	return (error);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  4723
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  4724
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  4725
int
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  4726
_info(struct modinfo *modinfop)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  4727
{
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  4728
	return (mod_info(&modlinkage, modinfop));
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  4729
}