usr/src/lib/libzfs/common/libzfs_dataset.c
author Eric Taylor <Eric.Taylor@Sun.COM>
Tue, 25 Nov 2008 13:36:43 -0700
changeset 8228 51e9ca9ee3a5
parent 7509 24f6b0f4654f
child 8269 03a7e9050cfd
permissions -rw-r--r--
6572357 libzfs should do more to avoid mnttab lookups 6572376 zfs_iter_filesystems and zfs_iter_snapshots get objset stats twice
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
     1
/*
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
     2
 * CDDL HEADER START
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
     3
 *
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
     4
 * The contents of this file are subject to the terms of the
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1407
diff changeset
     5
 * Common Development and Distribution License (the "License").
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1407
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
 */
3126
4f4fb617fdd0 PSARC 2006/622 iSCSI/ZFS Integration
ahl
parents: 2885
diff changeset
    21
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    22
/*
5977
33727f49aeaa 6654731 sharesmb property should only be settable on CIFS aware ZPL
marks
parents: 5751
diff changeset
    23
 * Copyright 2008 Sun Microsystems, Inc.  All rights reserved.
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    24
 * Use is subject to license terms.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    25
 */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    26
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    27
#include <assert.h>
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    28
#include <ctype.h>
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    29
#include <errno.h>
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    30
#include <libdevinfo.h>
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    31
#include <libintl.h>
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    32
#include <math.h>
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    33
#include <stdio.h>
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    34
#include <stdlib.h>
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    35
#include <strings.h>
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    36
#include <unistd.h>
5367
c40abbe796be PSARC/2007/574 zfs send -R
ahrens
parents: 5331
diff changeset
    37
#include <stddef.h>
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    38
#include <zone.h>
2082
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1793
diff changeset
    39
#include <fcntl.h>
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    40
#include <sys/mntent.h>
1294
87b43e5de5ee 6364129 need to unmount any child datasets before doing the rollback
lling
parents: 1175
diff changeset
    41
#include <sys/mount.h>
4543
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
    42
#include <sys/avl.h>
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
    43
#include <priv.h>
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
    44
#include <pwd.h>
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
    45
#include <grp.h>
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
    46
#include <stddef.h>
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
    47
#include <ucred.h>
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    48
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    49
#include <sys/spa.h>
2676
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
    50
#include <sys/zap.h>
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    51
#include <libzfs.h>
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    52
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    53
#include "zfs_namecheck.h"
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    54
#include "zfs_prop.h"
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    55
#include "libzfs_impl.h"
4543
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
    56
#include "zfs_deleg.h"
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    57
4007
c6f5c6753018 PSARC 2007/142 zfs rename -r
mmusante
parents: 3912
diff changeset
    58
static int zvol_create_link_common(libzfs_handle_t *, const char *, int);
c6f5c6753018 PSARC 2007/142 zfs rename -r
mmusante
parents: 3912
diff changeset
    59
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    60
/*
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    61
 * Given a single type (not a mask of types), return the type in a human
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    62
 * readable form.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    63
 */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    64
const char *
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    65
zfs_type_to_name(zfs_type_t type)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    66
{
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    67
	switch (type) {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    68
	case ZFS_TYPE_FILESYSTEM:
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    69
		return (dgettext(TEXT_DOMAIN, "filesystem"));
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    70
	case ZFS_TYPE_SNAPSHOT:
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    71
		return (dgettext(TEXT_DOMAIN, "snapshot"));
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    72
	case ZFS_TYPE_VOLUME:
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    73
		return (dgettext(TEXT_DOMAIN, "volume"));
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    74
	}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    75
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    76
	return (NULL);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    77
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    78
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    79
/*
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    80
 * Given a path and mask of ZFS types, return a string describing this dataset.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    81
 * This is used when we fail to open a dataset and we cannot get an exact type.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    82
 * We guess what the type would have been based on the path and the mask of
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    83
 * acceptable types.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    84
 */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    85
static const char *
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    86
path_to_str(const char *path, int types)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    87
{
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    88
	/*
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    89
	 * When given a single type, always report the exact type.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    90
	 */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    91
	if (types == ZFS_TYPE_SNAPSHOT)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    92
		return (dgettext(TEXT_DOMAIN, "snapshot"));
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    93
	if (types == ZFS_TYPE_FILESYSTEM)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    94
		return (dgettext(TEXT_DOMAIN, "filesystem"));
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    95
	if (types == ZFS_TYPE_VOLUME)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    96
		return (dgettext(TEXT_DOMAIN, "volume"));
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    97
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    98
	/*
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    99
	 * The user is requesting more than one type of dataset.  If this is the
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   100
	 * case, consult the path itself.  If we're looking for a snapshot, and
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   101
	 * a '@' is found, then report it as "snapshot".  Otherwise, remove the
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   102
	 * snapshot attribute and try again.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   103
	 */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   104
	if (types & ZFS_TYPE_SNAPSHOT) {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   105
		if (strchr(path, '@') != NULL)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   106
			return (dgettext(TEXT_DOMAIN, "snapshot"));
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   107
		return (path_to_str(path, types & ~ZFS_TYPE_SNAPSHOT));
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   108
	}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   109
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   110
	/*
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   111
	 * The user has requested either filesystems or volumes.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   112
	 * We have no way of knowing a priori what type this would be, so always
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   113
	 * report it as "filesystem" or "volume", our two primitive types.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   114
	 */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   115
	if (types & ZFS_TYPE_FILESYSTEM)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   116
		return (dgettext(TEXT_DOMAIN, "filesystem"));
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   117
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   118
	assert(types & ZFS_TYPE_VOLUME);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   119
	return (dgettext(TEXT_DOMAIN, "volume"));
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   120
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   121
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   122
/*
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   123
 * Validate a ZFS path.  This is used even before trying to open the dataset, to
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   124
 * provide a more meaningful error message.  We place a more useful message in
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   125
 * 'buf' detailing exactly why the name was not valid.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   126
 */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   127
static int
5326
6752aa2bd5bc 6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents: 5147
diff changeset
   128
zfs_validate_name(libzfs_handle_t *hdl, const char *path, int type,
6752aa2bd5bc 6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents: 5147
diff changeset
   129
    boolean_t modifying)
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   130
{
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   131
	namecheck_err_t why;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   132
	char what;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   133
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   134
	if (dataset_namecheck(path, &why, &what) != 0) {
2082
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1793
diff changeset
   135
		if (hdl != NULL) {
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   136
			switch (why) {
1003
ce99098d6a9b 6350417 long name will cause rename a dataset panic
lling
parents: 905
diff changeset
   137
			case NAME_ERR_TOOLONG:
2082
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1793
diff changeset
   138
				zfs_error_aux(hdl, dgettext(TEXT_DOMAIN,
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1793
diff changeset
   139
				    "name is too long"));
1003
ce99098d6a9b 6350417 long name will cause rename a dataset panic
lling
parents: 905
diff changeset
   140
				break;
ce99098d6a9b 6350417 long name will cause rename a dataset panic
lling
parents: 905
diff changeset
   141
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   142
			case NAME_ERR_LEADING_SLASH:
2082
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1793
diff changeset
   143
				zfs_error_aux(hdl, dgettext(TEXT_DOMAIN,
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1793
diff changeset
   144
				    "leading slash in name"));
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   145
				break;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   146
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   147
			case NAME_ERR_EMPTY_COMPONENT:
2082
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1793
diff changeset
   148
				zfs_error_aux(hdl, dgettext(TEXT_DOMAIN,
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1793
diff changeset
   149
				    "empty component in name"));
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   150
				break;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   151
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   152
			case NAME_ERR_TRAILING_SLASH:
2082
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1793
diff changeset
   153
				zfs_error_aux(hdl, dgettext(TEXT_DOMAIN,
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1793
diff changeset
   154
				    "trailing slash in name"));
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   155
				break;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   156
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   157
			case NAME_ERR_INVALCHAR:
2082
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1793
diff changeset
   158
				zfs_error_aux(hdl,
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   159
				    dgettext(TEXT_DOMAIN, "invalid character "
2082
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1793
diff changeset
   160
				    "'%c' in name"), what);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   161
				break;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   162
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   163
			case NAME_ERR_MULTIPLE_AT:
2082
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1793
diff changeset
   164
				zfs_error_aux(hdl, dgettext(TEXT_DOMAIN,
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1793
diff changeset
   165
				    "multiple '@' delimiters in name"));
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   166
				break;
2856
6f4d5ee1906a 6463348 ZFS code could be more portable
nd150628
parents: 2744
diff changeset
   167
6f4d5ee1906a 6463348 ZFS code could be more portable
nd150628
parents: 2744
diff changeset
   168
			case NAME_ERR_NOLETTER:
6f4d5ee1906a 6463348 ZFS code could be more portable
nd150628
parents: 2744
diff changeset
   169
				zfs_error_aux(hdl, dgettext(TEXT_DOMAIN,
6f4d5ee1906a 6463348 ZFS code could be more portable
nd150628
parents: 2744
diff changeset
   170
				    "pool doesn't begin with a letter"));
6f4d5ee1906a 6463348 ZFS code could be more portable
nd150628
parents: 2744
diff changeset
   171
				break;
6f4d5ee1906a 6463348 ZFS code could be more portable
nd150628
parents: 2744
diff changeset
   172
6f4d5ee1906a 6463348 ZFS code could be more portable
nd150628
parents: 2744
diff changeset
   173
			case NAME_ERR_RESERVED:
6f4d5ee1906a 6463348 ZFS code could be more portable
nd150628
parents: 2744
diff changeset
   174
				zfs_error_aux(hdl, dgettext(TEXT_DOMAIN,
6f4d5ee1906a 6463348 ZFS code could be more portable
nd150628
parents: 2744
diff changeset
   175
				    "name is reserved"));
6f4d5ee1906a 6463348 ZFS code could be more portable
nd150628
parents: 2744
diff changeset
   176
				break;
6f4d5ee1906a 6463348 ZFS code could be more portable
nd150628
parents: 2744
diff changeset
   177
6f4d5ee1906a 6463348 ZFS code could be more portable
nd150628
parents: 2744
diff changeset
   178
			case NAME_ERR_DISKLIKE:
6f4d5ee1906a 6463348 ZFS code could be more portable
nd150628
parents: 2744
diff changeset
   179
				zfs_error_aux(hdl, dgettext(TEXT_DOMAIN,
6f4d5ee1906a 6463348 ZFS code could be more portable
nd150628
parents: 2744
diff changeset
   180
				    "reserved disk name"));
6f4d5ee1906a 6463348 ZFS code could be more portable
nd150628
parents: 2744
diff changeset
   181
				break;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   182
			}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   183
		}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   184
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   185
		return (0);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   186
	}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   187
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   188
	if (!(type & ZFS_TYPE_SNAPSHOT) && strchr(path, '@') != NULL) {
2082
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1793
diff changeset
   189
		if (hdl != NULL)
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1793
diff changeset
   190
			zfs_error_aux(hdl, dgettext(TEXT_DOMAIN,
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1793
diff changeset
   191
			    "snapshot delimiter '@' in filesystem name"));
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   192
		return (0);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   193
	}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   194
2199
712a788c2dfd PSARC 2006/388 snapshot -r
ahrens
parents: 2169
diff changeset
   195
	if (type == ZFS_TYPE_SNAPSHOT && strchr(path, '@') == NULL) {
712a788c2dfd PSARC 2006/388 snapshot -r
ahrens
parents: 2169
diff changeset
   196
		if (hdl != NULL)
712a788c2dfd PSARC 2006/388 snapshot -r
ahrens
parents: 2169
diff changeset
   197
			zfs_error_aux(hdl, dgettext(TEXT_DOMAIN,
3413
f4cbe0204ab7 6471255 Some ZFS error messages contain spelling errors
mmusante
parents: 3377
diff changeset
   198
			    "missing '@' delimiter in snapshot name"));
2199
712a788c2dfd PSARC 2006/388 snapshot -r
ahrens
parents: 2169
diff changeset
   199
		return (0);
712a788c2dfd PSARC 2006/388 snapshot -r
ahrens
parents: 2169
diff changeset
   200
	}
712a788c2dfd PSARC 2006/388 snapshot -r
ahrens
parents: 2169
diff changeset
   201
5326
6752aa2bd5bc 6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents: 5147
diff changeset
   202
	if (modifying && strchr(path, '%') != NULL) {
6752aa2bd5bc 6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents: 5147
diff changeset
   203
		if (hdl != NULL)
6752aa2bd5bc 6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents: 5147
diff changeset
   204
			zfs_error_aux(hdl, dgettext(TEXT_DOMAIN,
6752aa2bd5bc 6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents: 5147
diff changeset
   205
			    "invalid character %c in name"), '%');
6752aa2bd5bc 6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents: 5147
diff changeset
   206
		return (0);
6752aa2bd5bc 6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents: 5147
diff changeset
   207
	}
6752aa2bd5bc 6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents: 5147
diff changeset
   208
2082
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1793
diff changeset
   209
	return (-1);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   210
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   211
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   212
int
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   213
zfs_name_valid(const char *name, zfs_type_t type)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   214
{
6423
437422a29d3a PSARC 2006/370 ZFS Boot Support
gw25295
parents: 6168
diff changeset
   215
	if (type == ZFS_TYPE_POOL)
437422a29d3a PSARC 2006/370 ZFS Boot Support
gw25295
parents: 6168
diff changeset
   216
		return (zpool_name_valid(NULL, B_FALSE, name));
5326
6752aa2bd5bc 6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents: 5147
diff changeset
   217
	return (zfs_validate_name(NULL, name, type, B_FALSE));
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   218
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   219
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   220
/*
2676
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
   221
 * This function takes the raw DSL properties, and filters out the user-defined
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
   222
 * properties into a separate nvlist.
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
   223
 */
4217
3411a82f178f 6552521 truss dumps core with multibyte characters in syscall args
eschrock
parents: 4183
diff changeset
   224
static nvlist_t *
3411a82f178f 6552521 truss dumps core with multibyte characters in syscall args
eschrock
parents: 4183
diff changeset
   225
process_user_props(zfs_handle_t *zhp, nvlist_t *props)
2676
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
   226
{
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
   227
	libzfs_handle_t *hdl = zhp->zfs_hdl;
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
   228
	nvpair_t *elem;
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
   229
	nvlist_t *propval;
4217
3411a82f178f 6552521 truss dumps core with multibyte characters in syscall args
eschrock
parents: 4183
diff changeset
   230
	nvlist_t *nvl;
3411a82f178f 6552521 truss dumps core with multibyte characters in syscall args
eschrock
parents: 4183
diff changeset
   231
3411a82f178f 6552521 truss dumps core with multibyte characters in syscall args
eschrock
parents: 4183
diff changeset
   232
	if (nvlist_alloc(&nvl, NV_UNIQUE_NAME, 0) != 0) {
3411a82f178f 6552521 truss dumps core with multibyte characters in syscall args
eschrock
parents: 4183
diff changeset
   233
		(void) no_memory(hdl);
3411a82f178f 6552521 truss dumps core with multibyte characters in syscall args
eschrock
parents: 4183
diff changeset
   234
		return (NULL);
3411a82f178f 6552521 truss dumps core with multibyte characters in syscall args
eschrock
parents: 4183
diff changeset
   235
	}
2676
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
   236
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
   237
	elem = NULL;
4217
3411a82f178f 6552521 truss dumps core with multibyte characters in syscall args
eschrock
parents: 4183
diff changeset
   238
	while ((elem = nvlist_next_nvpair(props, elem)) != NULL) {
2676
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
   239
		if (!zfs_prop_user(nvpair_name(elem)))
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
   240
			continue;
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
   241
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
   242
		verify(nvpair_value_nvlist(elem, &propval) == 0);
4217
3411a82f178f 6552521 truss dumps core with multibyte characters in syscall args
eschrock
parents: 4183
diff changeset
   243
		if (nvlist_add_nvlist(nvl, nvpair_name(elem), propval) != 0) {
3411a82f178f 6552521 truss dumps core with multibyte characters in syscall args
eschrock
parents: 4183
diff changeset
   244
			nvlist_free(nvl);
3411a82f178f 6552521 truss dumps core with multibyte characters in syscall args
eschrock
parents: 4183
diff changeset
   245
			(void) no_memory(hdl);
3411a82f178f 6552521 truss dumps core with multibyte characters in syscall args
eschrock
parents: 4183
diff changeset
   246
			return (NULL);
3411a82f178f 6552521 truss dumps core with multibyte characters in syscall args
eschrock
parents: 4183
diff changeset
   247
		}
2676
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
   248
	}
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
   249
4217
3411a82f178f 6552521 truss dumps core with multibyte characters in syscall args
eschrock
parents: 4183
diff changeset
   250
	return (nvl);
2676
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
   251
}
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
   252
6865
176d18c623cc 6539380 zfs list uses too much memory
rm160521
parents: 6612
diff changeset
   253
static zpool_handle_t *
176d18c623cc 6539380 zfs list uses too much memory
rm160521
parents: 6612
diff changeset
   254
zpool_add_handle(zfs_handle_t *zhp, const char *pool_name)
176d18c623cc 6539380 zfs list uses too much memory
rm160521
parents: 6612
diff changeset
   255
{
176d18c623cc 6539380 zfs list uses too much memory
rm160521
parents: 6612
diff changeset
   256
	libzfs_handle_t *hdl = zhp->zfs_hdl;
176d18c623cc 6539380 zfs list uses too much memory
rm160521
parents: 6612
diff changeset
   257
	zpool_handle_t *zph;
176d18c623cc 6539380 zfs list uses too much memory
rm160521
parents: 6612
diff changeset
   258
176d18c623cc 6539380 zfs list uses too much memory
rm160521
parents: 6612
diff changeset
   259
	if ((zph = zpool_open_canfail(hdl, pool_name)) != NULL) {
176d18c623cc 6539380 zfs list uses too much memory
rm160521
parents: 6612
diff changeset
   260
		if (hdl->libzfs_pool_handles != NULL)
176d18c623cc 6539380 zfs list uses too much memory
rm160521
parents: 6612
diff changeset
   261
			zph->zpool_next = hdl->libzfs_pool_handles;
176d18c623cc 6539380 zfs list uses too much memory
rm160521
parents: 6612
diff changeset
   262
		hdl->libzfs_pool_handles = zph;
176d18c623cc 6539380 zfs list uses too much memory
rm160521
parents: 6612
diff changeset
   263
	}
176d18c623cc 6539380 zfs list uses too much memory
rm160521
parents: 6612
diff changeset
   264
	return (zph);
176d18c623cc 6539380 zfs list uses too much memory
rm160521
parents: 6612
diff changeset
   265
}
176d18c623cc 6539380 zfs list uses too much memory
rm160521
parents: 6612
diff changeset
   266
176d18c623cc 6539380 zfs list uses too much memory
rm160521
parents: 6612
diff changeset
   267
static zpool_handle_t *
176d18c623cc 6539380 zfs list uses too much memory
rm160521
parents: 6612
diff changeset
   268
zpool_find_handle(zfs_handle_t *zhp, const char *pool_name, int len)
176d18c623cc 6539380 zfs list uses too much memory
rm160521
parents: 6612
diff changeset
   269
{
176d18c623cc 6539380 zfs list uses too much memory
rm160521
parents: 6612
diff changeset
   270
	libzfs_handle_t *hdl = zhp->zfs_hdl;
176d18c623cc 6539380 zfs list uses too much memory
rm160521
parents: 6612
diff changeset
   271
	zpool_handle_t *zph = hdl->libzfs_pool_handles;
176d18c623cc 6539380 zfs list uses too much memory
rm160521
parents: 6612
diff changeset
   272
176d18c623cc 6539380 zfs list uses too much memory
rm160521
parents: 6612
diff changeset
   273
	while ((zph != NULL) &&
176d18c623cc 6539380 zfs list uses too much memory
rm160521
parents: 6612
diff changeset
   274
	    (strncmp(pool_name, zpool_get_name(zph), len) != 0))
176d18c623cc 6539380 zfs list uses too much memory
rm160521
parents: 6612
diff changeset
   275
		zph = zph->zpool_next;
176d18c623cc 6539380 zfs list uses too much memory
rm160521
parents: 6612
diff changeset
   276
	return (zph);
176d18c623cc 6539380 zfs list uses too much memory
rm160521
parents: 6612
diff changeset
   277
}
176d18c623cc 6539380 zfs list uses too much memory
rm160521
parents: 6612
diff changeset
   278
176d18c623cc 6539380 zfs list uses too much memory
rm160521
parents: 6612
diff changeset
   279
/*
176d18c623cc 6539380 zfs list uses too much memory
rm160521
parents: 6612
diff changeset
   280
 * Returns a handle to the pool that contains the provided dataset.
176d18c623cc 6539380 zfs list uses too much memory
rm160521
parents: 6612
diff changeset
   281
 * If a handle to that pool already exists then that handle is returned.
176d18c623cc 6539380 zfs list uses too much memory
rm160521
parents: 6612
diff changeset
   282
 * Otherwise, a new handle is created and added to the list of handles.
176d18c623cc 6539380 zfs list uses too much memory
rm160521
parents: 6612
diff changeset
   283
 */
176d18c623cc 6539380 zfs list uses too much memory
rm160521
parents: 6612
diff changeset
   284
static zpool_handle_t *
176d18c623cc 6539380 zfs list uses too much memory
rm160521
parents: 6612
diff changeset
   285
zpool_handle(zfs_handle_t *zhp)
176d18c623cc 6539380 zfs list uses too much memory
rm160521
parents: 6612
diff changeset
   286
{
176d18c623cc 6539380 zfs list uses too much memory
rm160521
parents: 6612
diff changeset
   287
	char *pool_name;
176d18c623cc 6539380 zfs list uses too much memory
rm160521
parents: 6612
diff changeset
   288
	int len;
176d18c623cc 6539380 zfs list uses too much memory
rm160521
parents: 6612
diff changeset
   289
	zpool_handle_t *zph;
176d18c623cc 6539380 zfs list uses too much memory
rm160521
parents: 6612
diff changeset
   290
176d18c623cc 6539380 zfs list uses too much memory
rm160521
parents: 6612
diff changeset
   291
	len = strcspn(zhp->zfs_name, "/@") + 1;
176d18c623cc 6539380 zfs list uses too much memory
rm160521
parents: 6612
diff changeset
   292
	pool_name = zfs_alloc(zhp->zfs_hdl, len);
176d18c623cc 6539380 zfs list uses too much memory
rm160521
parents: 6612
diff changeset
   293
	(void) strlcpy(pool_name, zhp->zfs_name, len);
176d18c623cc 6539380 zfs list uses too much memory
rm160521
parents: 6612
diff changeset
   294
176d18c623cc 6539380 zfs list uses too much memory
rm160521
parents: 6612
diff changeset
   295
	zph = zpool_find_handle(zhp, pool_name, len);
176d18c623cc 6539380 zfs list uses too much memory
rm160521
parents: 6612
diff changeset
   296
	if (zph == NULL)
176d18c623cc 6539380 zfs list uses too much memory
rm160521
parents: 6612
diff changeset
   297
		zph = zpool_add_handle(zhp, pool_name);
176d18c623cc 6539380 zfs list uses too much memory
rm160521
parents: 6612
diff changeset
   298
176d18c623cc 6539380 zfs list uses too much memory
rm160521
parents: 6612
diff changeset
   299
	free(pool_name);
176d18c623cc 6539380 zfs list uses too much memory
rm160521
parents: 6612
diff changeset
   300
	return (zph);
176d18c623cc 6539380 zfs list uses too much memory
rm160521
parents: 6612
diff changeset
   301
}
176d18c623cc 6539380 zfs list uses too much memory
rm160521
parents: 6612
diff changeset
   302
176d18c623cc 6539380 zfs list uses too much memory
rm160521
parents: 6612
diff changeset
   303
void
176d18c623cc 6539380 zfs list uses too much memory
rm160521
parents: 6612
diff changeset
   304
zpool_free_handles(libzfs_handle_t *hdl)
176d18c623cc 6539380 zfs list uses too much memory
rm160521
parents: 6612
diff changeset
   305
{
176d18c623cc 6539380 zfs list uses too much memory
rm160521
parents: 6612
diff changeset
   306
	zpool_handle_t *next, *zph = hdl->libzfs_pool_handles;
176d18c623cc 6539380 zfs list uses too much memory
rm160521
parents: 6612
diff changeset
   307
176d18c623cc 6539380 zfs list uses too much memory
rm160521
parents: 6612
diff changeset
   308
	while (zph != NULL) {
176d18c623cc 6539380 zfs list uses too much memory
rm160521
parents: 6612
diff changeset
   309
		next = zph->zpool_next;
176d18c623cc 6539380 zfs list uses too much memory
rm160521
parents: 6612
diff changeset
   310
		zpool_close(zph);
176d18c623cc 6539380 zfs list uses too much memory
rm160521
parents: 6612
diff changeset
   311
		zph = next;
176d18c623cc 6539380 zfs list uses too much memory
rm160521
parents: 6612
diff changeset
   312
	}
176d18c623cc 6539380 zfs list uses too much memory
rm160521
parents: 6612
diff changeset
   313
	hdl->libzfs_pool_handles = NULL;
176d18c623cc 6539380 zfs list uses too much memory
rm160521
parents: 6612
diff changeset
   314
}
176d18c623cc 6539380 zfs list uses too much memory
rm160521
parents: 6612
diff changeset
   315
2676
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
   316
/*
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   317
 * Utility function to gather stats (objset and zpl) for the given object.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   318
 */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   319
static int
8228
51e9ca9ee3a5 6572357 libzfs should do more to avoid mnttab lookups
Eric Taylor <Eric.Taylor@Sun.COM>
parents: 7509
diff changeset
   320
get_stats_ioctl(zfs_handle_t *zhp, zfs_cmd_t *zc)
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   321
{
2676
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
   322
	libzfs_handle_t *hdl = zhp->zfs_hdl;
8228
51e9ca9ee3a5 6572357 libzfs should do more to avoid mnttab lookups
Eric Taylor <Eric.Taylor@Sun.COM>
parents: 7509
diff changeset
   323
51e9ca9ee3a5 6572357 libzfs should do more to avoid mnttab lookups
Eric Taylor <Eric.Taylor@Sun.COM>
parents: 7509
diff changeset
   324
	(void) strlcpy(zc->zc_name, zhp->zfs_name, sizeof (zc->zc_name));
51e9ca9ee3a5 6572357 libzfs should do more to avoid mnttab lookups
Eric Taylor <Eric.Taylor@Sun.COM>
parents: 7509
diff changeset
   325
51e9ca9ee3a5 6572357 libzfs should do more to avoid mnttab lookups
Eric Taylor <Eric.Taylor@Sun.COM>
parents: 7509
diff changeset
   326
	while (ioctl(hdl->libzfs_fd, ZFS_IOC_OBJSET_STATS, zc) != 0) {
1356
e021b5e4aa0e 6377671 zfs mount -a shouldn't bother checking snapshots
eschrock
parents: 1294
diff changeset
   327
		if (errno == ENOMEM) {
8228
51e9ca9ee3a5 6572357 libzfs should do more to avoid mnttab lookups
Eric Taylor <Eric.Taylor@Sun.COM>
parents: 7509
diff changeset
   328
			if (zcmd_expand_dst_nvlist(hdl, zc) != 0) {
2082
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1793
diff changeset
   329
				return (-1);
2676
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
   330
			}
1356
e021b5e4aa0e 6377671 zfs mount -a shouldn't bother checking snapshots
eschrock
parents: 1294
diff changeset
   331
		} else {
e021b5e4aa0e 6377671 zfs mount -a shouldn't bother checking snapshots
eschrock
parents: 1294
diff changeset
   332
			return (-1);
e021b5e4aa0e 6377671 zfs mount -a shouldn't bother checking snapshots
eschrock
parents: 1294
diff changeset
   333
		}
e021b5e4aa0e 6377671 zfs mount -a shouldn't bother checking snapshots
eschrock
parents: 1294
diff changeset
   334
	}
8228
51e9ca9ee3a5 6572357 libzfs should do more to avoid mnttab lookups
Eric Taylor <Eric.Taylor@Sun.COM>
parents: 7509
diff changeset
   335
	return (0);
51e9ca9ee3a5 6572357 libzfs should do more to avoid mnttab lookups
Eric Taylor <Eric.Taylor@Sun.COM>
parents: 7509
diff changeset
   336
}
51e9ca9ee3a5 6572357 libzfs should do more to avoid mnttab lookups
Eric Taylor <Eric.Taylor@Sun.COM>
parents: 7509
diff changeset
   337
51e9ca9ee3a5 6572357 libzfs should do more to avoid mnttab lookups
Eric Taylor <Eric.Taylor@Sun.COM>
parents: 7509
diff changeset
   338
static int
51e9ca9ee3a5 6572357 libzfs should do more to avoid mnttab lookups
Eric Taylor <Eric.Taylor@Sun.COM>
parents: 7509
diff changeset
   339
put_stats_zhdl(zfs_handle_t *zhp, zfs_cmd_t *zc)
51e9ca9ee3a5 6572357 libzfs should do more to avoid mnttab lookups
Eric Taylor <Eric.Taylor@Sun.COM>
parents: 7509
diff changeset
   340
{
51e9ca9ee3a5 6572357 libzfs should do more to avoid mnttab lookups
Eric Taylor <Eric.Taylor@Sun.COM>
parents: 7509
diff changeset
   341
	nvlist_t *allprops, *userprops;
51e9ca9ee3a5 6572357 libzfs should do more to avoid mnttab lookups
Eric Taylor <Eric.Taylor@Sun.COM>
parents: 7509
diff changeset
   342
51e9ca9ee3a5 6572357 libzfs should do more to avoid mnttab lookups
Eric Taylor <Eric.Taylor@Sun.COM>
parents: 7509
diff changeset
   343
	zhp->zfs_dmustats = zc->zc_objset_stats; /* structure assignment */
51e9ca9ee3a5 6572357 libzfs should do more to avoid mnttab lookups
Eric Taylor <Eric.Taylor@Sun.COM>
parents: 7509
diff changeset
   344
51e9ca9ee3a5 6572357 libzfs should do more to avoid mnttab lookups
Eric Taylor <Eric.Taylor@Sun.COM>
parents: 7509
diff changeset
   345
	if (zcmd_read_dst_nvlist(zhp->zfs_hdl, zc, &allprops) != 0) {
2082
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1793
diff changeset
   346
		return (-1);
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1793
diff changeset
   347
	}
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   348
4217
3411a82f178f 6552521 truss dumps core with multibyte characters in syscall args
eschrock
parents: 4183
diff changeset
   349
	if ((userprops = process_user_props(zhp, allprops)) == NULL) {
3411a82f178f 6552521 truss dumps core with multibyte characters in syscall args
eschrock
parents: 4183
diff changeset
   350
		nvlist_free(allprops);
2676
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
   351
		return (-1);
4217
3411a82f178f 6552521 truss dumps core with multibyte characters in syscall args
eschrock
parents: 4183
diff changeset
   352
	}
3411a82f178f 6552521 truss dumps core with multibyte characters in syscall args
eschrock
parents: 4183
diff changeset
   353
3411a82f178f 6552521 truss dumps core with multibyte characters in syscall args
eschrock
parents: 4183
diff changeset
   354
	nvlist_free(zhp->zfs_props);
3411a82f178f 6552521 truss dumps core with multibyte characters in syscall args
eschrock
parents: 4183
diff changeset
   355
	nvlist_free(zhp->zfs_user_props);
3411a82f178f 6552521 truss dumps core with multibyte characters in syscall args
eschrock
parents: 4183
diff changeset
   356
3411a82f178f 6552521 truss dumps core with multibyte characters in syscall args
eschrock
parents: 4183
diff changeset
   357
	zhp->zfs_props = allprops;
3411a82f178f 6552521 truss dumps core with multibyte characters in syscall args
eschrock
parents: 4183
diff changeset
   358
	zhp->zfs_user_props = userprops;
2082
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1793
diff changeset
   359
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   360
	return (0);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   361
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   362
8228
51e9ca9ee3a5 6572357 libzfs should do more to avoid mnttab lookups
Eric Taylor <Eric.Taylor@Sun.COM>
parents: 7509
diff changeset
   363
static int
51e9ca9ee3a5 6572357 libzfs should do more to avoid mnttab lookups
Eric Taylor <Eric.Taylor@Sun.COM>
parents: 7509
diff changeset
   364
get_stats(zfs_handle_t *zhp)
51e9ca9ee3a5 6572357 libzfs should do more to avoid mnttab lookups
Eric Taylor <Eric.Taylor@Sun.COM>
parents: 7509
diff changeset
   365
{
51e9ca9ee3a5 6572357 libzfs should do more to avoid mnttab lookups
Eric Taylor <Eric.Taylor@Sun.COM>
parents: 7509
diff changeset
   366
	int rc = 0;
51e9ca9ee3a5 6572357 libzfs should do more to avoid mnttab lookups
Eric Taylor <Eric.Taylor@Sun.COM>
parents: 7509
diff changeset
   367
	zfs_cmd_t zc = { 0 };
51e9ca9ee3a5 6572357 libzfs should do more to avoid mnttab lookups
Eric Taylor <Eric.Taylor@Sun.COM>
parents: 7509
diff changeset
   368
51e9ca9ee3a5 6572357 libzfs should do more to avoid mnttab lookups
Eric Taylor <Eric.Taylor@Sun.COM>
parents: 7509
diff changeset
   369
	if (zcmd_alloc_dst_nvlist(zhp->zfs_hdl, &zc, 0) != 0)
51e9ca9ee3a5 6572357 libzfs should do more to avoid mnttab lookups
Eric Taylor <Eric.Taylor@Sun.COM>
parents: 7509
diff changeset
   370
		return (-1);
51e9ca9ee3a5 6572357 libzfs should do more to avoid mnttab lookups
Eric Taylor <Eric.Taylor@Sun.COM>
parents: 7509
diff changeset
   371
	if (get_stats_ioctl(zhp, &zc) != 0)
51e9ca9ee3a5 6572357 libzfs should do more to avoid mnttab lookups
Eric Taylor <Eric.Taylor@Sun.COM>
parents: 7509
diff changeset
   372
		rc = -1;
51e9ca9ee3a5 6572357 libzfs should do more to avoid mnttab lookups
Eric Taylor <Eric.Taylor@Sun.COM>
parents: 7509
diff changeset
   373
	else if (put_stats_zhdl(zhp, &zc) != 0)
51e9ca9ee3a5 6572357 libzfs should do more to avoid mnttab lookups
Eric Taylor <Eric.Taylor@Sun.COM>
parents: 7509
diff changeset
   374
		rc = -1;
51e9ca9ee3a5 6572357 libzfs should do more to avoid mnttab lookups
Eric Taylor <Eric.Taylor@Sun.COM>
parents: 7509
diff changeset
   375
	zcmd_free_nvlists(&zc);
51e9ca9ee3a5 6572357 libzfs should do more to avoid mnttab lookups
Eric Taylor <Eric.Taylor@Sun.COM>
parents: 7509
diff changeset
   376
	return (rc);
51e9ca9ee3a5 6572357 libzfs should do more to avoid mnttab lookups
Eric Taylor <Eric.Taylor@Sun.COM>
parents: 7509
diff changeset
   377
}
51e9ca9ee3a5 6572357 libzfs should do more to avoid mnttab lookups
Eric Taylor <Eric.Taylor@Sun.COM>
parents: 7509
diff changeset
   378
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   379
/*
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   380
 * Refresh the properties currently stored in the handle.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   381
 */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   382
void
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   383
zfs_refresh_properties(zfs_handle_t *zhp)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   384
{
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   385
	(void) get_stats(zhp);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   386
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   387
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   388
/*
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   389
 * Makes a handle from the given dataset name.  Used by zfs_open() and
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   390
 * zfs_iter_* to create child handles on the fly.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   391
 */
8228
51e9ca9ee3a5 6572357 libzfs should do more to avoid mnttab lookups
Eric Taylor <Eric.Taylor@Sun.COM>
parents: 7509
diff changeset
   392
static int
51e9ca9ee3a5 6572357 libzfs should do more to avoid mnttab lookups
Eric Taylor <Eric.Taylor@Sun.COM>
parents: 7509
diff changeset
   393
make_dataset_handle_common(zfs_handle_t *zhp, zfs_cmd_t *zc)
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   394
{
4543
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   395
	char *logstr;
8228
51e9ca9ee3a5 6572357 libzfs should do more to avoid mnttab lookups
Eric Taylor <Eric.Taylor@Sun.COM>
parents: 7509
diff changeset
   396
	libzfs_handle_t *hdl = zhp->zfs_hdl;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   397
4543
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   398
	/*
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   399
	 * Preserve history log string.
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   400
	 * any changes performed here will be
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   401
	 * logged as an internal event.
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   402
	 */
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   403
	logstr = zhp->zfs_hdl->libzfs_log_str;
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   404
	zhp->zfs_hdl->libzfs_log_str = NULL;
8228
51e9ca9ee3a5 6572357 libzfs should do more to avoid mnttab lookups
Eric Taylor <Eric.Taylor@Sun.COM>
parents: 7509
diff changeset
   405
1758
d0750a16db04 6397267 assertion failed: (link->list_next == 0) == (link->list_prev == 0)
ahrens
parents: 1749
diff changeset
   406
top:
8228
51e9ca9ee3a5 6572357 libzfs should do more to avoid mnttab lookups
Eric Taylor <Eric.Taylor@Sun.COM>
parents: 7509
diff changeset
   407
	if (put_stats_zhdl(zhp, zc) != 0) {
4543
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   408
		zhp->zfs_hdl->libzfs_log_str = logstr;
8228
51e9ca9ee3a5 6572357 libzfs should do more to avoid mnttab lookups
Eric Taylor <Eric.Taylor@Sun.COM>
parents: 7509
diff changeset
   409
		return (-1);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   410
	}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   411
8228
51e9ca9ee3a5 6572357 libzfs should do more to avoid mnttab lookups
Eric Taylor <Eric.Taylor@Sun.COM>
parents: 7509
diff changeset
   412
1758
d0750a16db04 6397267 assertion failed: (link->list_next == 0) == (link->list_prev == 0)
ahrens
parents: 1749
diff changeset
   413
	if (zhp->zfs_dmustats.dds_inconsistent) {
8228
51e9ca9ee3a5 6572357 libzfs should do more to avoid mnttab lookups
Eric Taylor <Eric.Taylor@Sun.COM>
parents: 7509
diff changeset
   414
		zfs_cmd_t zc2 = { 0 };
1758
d0750a16db04 6397267 assertion failed: (link->list_next == 0) == (link->list_prev == 0)
ahrens
parents: 1749
diff changeset
   415
d0750a16db04 6397267 assertion failed: (link->list_next == 0) == (link->list_prev == 0)
ahrens
parents: 1749
diff changeset
   416
		/*
d0750a16db04 6397267 assertion failed: (link->list_next == 0) == (link->list_prev == 0)
ahrens
parents: 1749
diff changeset
   417
		 * If it is dds_inconsistent, then we've caught it in
d0750a16db04 6397267 assertion failed: (link->list_next == 0) == (link->list_prev == 0)
ahrens
parents: 1749
diff changeset
   418
		 * the middle of a 'zfs receive' or 'zfs destroy', and
d0750a16db04 6397267 assertion failed: (link->list_next == 0) == (link->list_prev == 0)
ahrens
parents: 1749
diff changeset
   419
		 * it is inconsistent from the ZPL's point of view, so
d0750a16db04 6397267 assertion failed: (link->list_next == 0) == (link->list_prev == 0)
ahrens
parents: 1749
diff changeset
   420
		 * can't be mounted.  However, it could also be that we
d0750a16db04 6397267 assertion failed: (link->list_next == 0) == (link->list_prev == 0)
ahrens
parents: 1749
diff changeset
   421
		 * have crashed in the middle of one of those
d0750a16db04 6397267 assertion failed: (link->list_next == 0) == (link->list_prev == 0)
ahrens
parents: 1749
diff changeset
   422
		 * operations, in which case we need to get rid of the
d0750a16db04 6397267 assertion failed: (link->list_next == 0) == (link->list_prev == 0)
ahrens
parents: 1749
diff changeset
   423
		 * inconsistent state.  We do that by either rolling
d0750a16db04 6397267 assertion failed: (link->list_next == 0) == (link->list_prev == 0)
ahrens
parents: 1749
diff changeset
   424
		 * back to the previous snapshot (which will fail if
d0750a16db04 6397267 assertion failed: (link->list_next == 0) == (link->list_prev == 0)
ahrens
parents: 1749
diff changeset
   425
		 * there is none), or destroying the filesystem.  Note
d0750a16db04 6397267 assertion failed: (link->list_next == 0) == (link->list_prev == 0)
ahrens
parents: 1749
diff changeset
   426
		 * that if we are still in the middle of an active
d0750a16db04 6397267 assertion failed: (link->list_next == 0) == (link->list_prev == 0)
ahrens
parents: 1749
diff changeset
   427
		 * 'receive' or 'destroy', then the rollback and destroy
d0750a16db04 6397267 assertion failed: (link->list_next == 0) == (link->list_prev == 0)
ahrens
parents: 1749
diff changeset
   428
		 * will fail with EBUSY and we will drive on as usual.
d0750a16db04 6397267 assertion failed: (link->list_next == 0) == (link->list_prev == 0)
ahrens
parents: 1749
diff changeset
   429
		 */
d0750a16db04 6397267 assertion failed: (link->list_next == 0) == (link->list_prev == 0)
ahrens
parents: 1749
diff changeset
   430
8228
51e9ca9ee3a5 6572357 libzfs should do more to avoid mnttab lookups
Eric Taylor <Eric.Taylor@Sun.COM>
parents: 7509
diff changeset
   431
		(void) strlcpy(zc2.zc_name, zhp->zfs_name,
51e9ca9ee3a5 6572357 libzfs should do more to avoid mnttab lookups
Eric Taylor <Eric.Taylor@Sun.COM>
parents: 7509
diff changeset
   432
		    sizeof (zc2.zc_name));
1758
d0750a16db04 6397267 assertion failed: (link->list_next == 0) == (link->list_prev == 0)
ahrens
parents: 1749
diff changeset
   433
2885
c0259887ebbc 6460059 zfs destroy <snapshot> leaves behind kruft
ahrens
parents: 2856
diff changeset
   434
		if (zhp->zfs_dmustats.dds_type == DMU_OST_ZVOL) {
2082
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1793
diff changeset
   435
			(void) zvol_remove_link(hdl, zhp->zfs_name);
8228
51e9ca9ee3a5 6572357 libzfs should do more to avoid mnttab lookups
Eric Taylor <Eric.Taylor@Sun.COM>
parents: 7509
diff changeset
   436
			zc2.zc_objset_type = DMU_OST_ZVOL;
1758
d0750a16db04 6397267 assertion failed: (link->list_next == 0) == (link->list_prev == 0)
ahrens
parents: 1749
diff changeset
   437
		} else {
8228
51e9ca9ee3a5 6572357 libzfs should do more to avoid mnttab lookups
Eric Taylor <Eric.Taylor@Sun.COM>
parents: 7509
diff changeset
   438
			zc2.zc_objset_type = DMU_OST_ZFS;
1758
d0750a16db04 6397267 assertion failed: (link->list_next == 0) == (link->list_prev == 0)
ahrens
parents: 1749
diff changeset
   439
		}
d0750a16db04 6397267 assertion failed: (link->list_next == 0) == (link->list_prev == 0)
ahrens
parents: 1749
diff changeset
   440
d0750a16db04 6397267 assertion failed: (link->list_next == 0) == (link->list_prev == 0)
ahrens
parents: 1749
diff changeset
   441
		/*
5331
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5326
diff changeset
   442
		 * If we can successfully destroy it, pretend that it
1758
d0750a16db04 6397267 assertion failed: (link->list_next == 0) == (link->list_prev == 0)
ahrens
parents: 1749
diff changeset
   443
		 * never existed.
d0750a16db04 6397267 assertion failed: (link->list_next == 0) == (link->list_prev == 0)
ahrens
parents: 1749
diff changeset
   444
		 */
8228
51e9ca9ee3a5 6572357 libzfs should do more to avoid mnttab lookups
Eric Taylor <Eric.Taylor@Sun.COM>
parents: 7509
diff changeset
   445
		if (ioctl(hdl->libzfs_fd, ZFS_IOC_DESTROY, &zc2) == 0) {
4543
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   446
			zhp->zfs_hdl->libzfs_log_str = logstr;
1758
d0750a16db04 6397267 assertion failed: (link->list_next == 0) == (link->list_prev == 0)
ahrens
parents: 1749
diff changeset
   447
			errno = ENOENT;
8228
51e9ca9ee3a5 6572357 libzfs should do more to avoid mnttab lookups
Eric Taylor <Eric.Taylor@Sun.COM>
parents: 7509
diff changeset
   448
			return (-1);
1758
d0750a16db04 6397267 assertion failed: (link->list_next == 0) == (link->list_prev == 0)
ahrens
parents: 1749
diff changeset
   449
		}
8228
51e9ca9ee3a5 6572357 libzfs should do more to avoid mnttab lookups
Eric Taylor <Eric.Taylor@Sun.COM>
parents: 7509
diff changeset
   450
		/* If we can successfully roll it back, reset the stats */
51e9ca9ee3a5 6572357 libzfs should do more to avoid mnttab lookups
Eric Taylor <Eric.Taylor@Sun.COM>
parents: 7509
diff changeset
   451
		if (ioctl(hdl->libzfs_fd, ZFS_IOC_ROLLBACK, &zc2) == 0) {
51e9ca9ee3a5 6572357 libzfs should do more to avoid mnttab lookups
Eric Taylor <Eric.Taylor@Sun.COM>
parents: 7509
diff changeset
   452
			if (get_stats_ioctl(zhp, zc) != 0) {
51e9ca9ee3a5 6572357 libzfs should do more to avoid mnttab lookups
Eric Taylor <Eric.Taylor@Sun.COM>
parents: 7509
diff changeset
   453
				zhp->zfs_hdl->libzfs_log_str = logstr;
51e9ca9ee3a5 6572357 libzfs should do more to avoid mnttab lookups
Eric Taylor <Eric.Taylor@Sun.COM>
parents: 7509
diff changeset
   454
				return (-1);
51e9ca9ee3a5 6572357 libzfs should do more to avoid mnttab lookups
Eric Taylor <Eric.Taylor@Sun.COM>
parents: 7509
diff changeset
   455
			}
5367
c40abbe796be PSARC/2007/574 zfs send -R
ahrens
parents: 5331
diff changeset
   456
			goto top;
8228
51e9ca9ee3a5 6572357 libzfs should do more to avoid mnttab lookups
Eric Taylor <Eric.Taylor@Sun.COM>
parents: 7509
diff changeset
   457
		}
1758
d0750a16db04 6397267 assertion failed: (link->list_next == 0) == (link->list_prev == 0)
ahrens
parents: 1749
diff changeset
   458
	}
d0750a16db04 6397267 assertion failed: (link->list_next == 0) == (link->list_prev == 0)
ahrens
parents: 1749
diff changeset
   459
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   460
	/*
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   461
	 * We've managed to open the dataset and gather statistics.  Determine
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   462
	 * the high-level type.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   463
	 */
2885
c0259887ebbc 6460059 zfs destroy <snapshot> leaves behind kruft
ahrens
parents: 2856
diff changeset
   464
	if (zhp->zfs_dmustats.dds_type == DMU_OST_ZVOL)
c0259887ebbc 6460059 zfs destroy <snapshot> leaves behind kruft
ahrens
parents: 2856
diff changeset
   465
		zhp->zfs_head_type = ZFS_TYPE_VOLUME;
c0259887ebbc 6460059 zfs destroy <snapshot> leaves behind kruft
ahrens
parents: 2856
diff changeset
   466
	else if (zhp->zfs_dmustats.dds_type == DMU_OST_ZFS)
c0259887ebbc 6460059 zfs destroy <snapshot> leaves behind kruft
ahrens
parents: 2856
diff changeset
   467
		zhp->zfs_head_type = ZFS_TYPE_FILESYSTEM;
c0259887ebbc 6460059 zfs destroy <snapshot> leaves behind kruft
ahrens
parents: 2856
diff changeset
   468
	else
c0259887ebbc 6460059 zfs destroy <snapshot> leaves behind kruft
ahrens
parents: 2856
diff changeset
   469
		abort();
c0259887ebbc 6460059 zfs destroy <snapshot> leaves behind kruft
ahrens
parents: 2856
diff changeset
   470
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   471
	if (zhp->zfs_dmustats.dds_is_snapshot)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   472
		zhp->zfs_type = ZFS_TYPE_SNAPSHOT;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   473
	else if (zhp->zfs_dmustats.dds_type == DMU_OST_ZVOL)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   474
		zhp->zfs_type = ZFS_TYPE_VOLUME;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   475
	else if (zhp->zfs_dmustats.dds_type == DMU_OST_ZFS)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   476
		zhp->zfs_type = ZFS_TYPE_FILESYSTEM;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   477
	else
2082
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1793
diff changeset
   478
		abort();	/* we should never see any other types */
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   479
4543
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
   480
	zhp->zfs_hdl->libzfs_log_str = logstr;
6865
176d18c623cc 6539380 zfs list uses too much memory
rm160521
parents: 6612
diff changeset
   481
	zhp->zpool_hdl = zpool_handle(zhp);
8228
51e9ca9ee3a5 6572357 libzfs should do more to avoid mnttab lookups
Eric Taylor <Eric.Taylor@Sun.COM>
parents: 7509
diff changeset
   482
	return (0);
51e9ca9ee3a5 6572357 libzfs should do more to avoid mnttab lookups
Eric Taylor <Eric.Taylor@Sun.COM>
parents: 7509
diff changeset
   483
}
51e9ca9ee3a5 6572357 libzfs should do more to avoid mnttab lookups
Eric Taylor <Eric.Taylor@Sun.COM>
parents: 7509
diff changeset
   484
51e9ca9ee3a5 6572357 libzfs should do more to avoid mnttab lookups
Eric Taylor <Eric.Taylor@Sun.COM>
parents: 7509
diff changeset
   485
zfs_handle_t *
51e9ca9ee3a5 6572357 libzfs should do more to avoid mnttab lookups
Eric Taylor <Eric.Taylor@Sun.COM>
parents: 7509
diff changeset
   486
make_dataset_handle(libzfs_handle_t *hdl, const char *path)
51e9ca9ee3a5 6572357 libzfs should do more to avoid mnttab lookups
Eric Taylor <Eric.Taylor@Sun.COM>
parents: 7509
diff changeset
   487
{
51e9ca9ee3a5 6572357 libzfs should do more to avoid mnttab lookups
Eric Taylor <Eric.Taylor@Sun.COM>
parents: 7509
diff changeset
   488
	zfs_cmd_t zc = { 0 };
51e9ca9ee3a5 6572357 libzfs should do more to avoid mnttab lookups
Eric Taylor <Eric.Taylor@Sun.COM>
parents: 7509
diff changeset
   489
51e9ca9ee3a5 6572357 libzfs should do more to avoid mnttab lookups
Eric Taylor <Eric.Taylor@Sun.COM>
parents: 7509
diff changeset
   490
	zfs_handle_t *zhp = calloc(sizeof (zfs_handle_t), 1);
51e9ca9ee3a5 6572357 libzfs should do more to avoid mnttab lookups
Eric Taylor <Eric.Taylor@Sun.COM>
parents: 7509
diff changeset
   491
51e9ca9ee3a5 6572357 libzfs should do more to avoid mnttab lookups
Eric Taylor <Eric.Taylor@Sun.COM>
parents: 7509
diff changeset
   492
	if (zhp == NULL)
51e9ca9ee3a5 6572357 libzfs should do more to avoid mnttab lookups
Eric Taylor <Eric.Taylor@Sun.COM>
parents: 7509
diff changeset
   493
		return (NULL);
51e9ca9ee3a5 6572357 libzfs should do more to avoid mnttab lookups
Eric Taylor <Eric.Taylor@Sun.COM>
parents: 7509
diff changeset
   494
51e9ca9ee3a5 6572357 libzfs should do more to avoid mnttab lookups
Eric Taylor <Eric.Taylor@Sun.COM>
parents: 7509
diff changeset
   495
	zhp->zfs_hdl = hdl;
51e9ca9ee3a5 6572357 libzfs should do more to avoid mnttab lookups
Eric Taylor <Eric.Taylor@Sun.COM>
parents: 7509
diff changeset
   496
	(void) strlcpy(zhp->zfs_name, path, sizeof (zhp->zfs_name));
51e9ca9ee3a5 6572357 libzfs should do more to avoid mnttab lookups
Eric Taylor <Eric.Taylor@Sun.COM>
parents: 7509
diff changeset
   497
	if (zcmd_alloc_dst_nvlist(hdl, &zc, 0) != 0) {
51e9ca9ee3a5 6572357 libzfs should do more to avoid mnttab lookups
Eric Taylor <Eric.Taylor@Sun.COM>
parents: 7509
diff changeset
   498
		free(zhp);
51e9ca9ee3a5 6572357 libzfs should do more to avoid mnttab lookups
Eric Taylor <Eric.Taylor@Sun.COM>
parents: 7509
diff changeset
   499
		return (NULL);
51e9ca9ee3a5 6572357 libzfs should do more to avoid mnttab lookups
Eric Taylor <Eric.Taylor@Sun.COM>
parents: 7509
diff changeset
   500
	}
51e9ca9ee3a5 6572357 libzfs should do more to avoid mnttab lookups
Eric Taylor <Eric.Taylor@Sun.COM>
parents: 7509
diff changeset
   501
	if (get_stats_ioctl(zhp, &zc) == -1) {
51e9ca9ee3a5 6572357 libzfs should do more to avoid mnttab lookups
Eric Taylor <Eric.Taylor@Sun.COM>
parents: 7509
diff changeset
   502
		zcmd_free_nvlists(&zc);
51e9ca9ee3a5 6572357 libzfs should do more to avoid mnttab lookups
Eric Taylor <Eric.Taylor@Sun.COM>
parents: 7509
diff changeset
   503
		free(zhp);
51e9ca9ee3a5 6572357 libzfs should do more to avoid mnttab lookups
Eric Taylor <Eric.Taylor@Sun.COM>
parents: 7509
diff changeset
   504
		return (NULL);
51e9ca9ee3a5 6572357 libzfs should do more to avoid mnttab lookups
Eric Taylor <Eric.Taylor@Sun.COM>
parents: 7509
diff changeset
   505
	}
51e9ca9ee3a5 6572357 libzfs should do more to avoid mnttab lookups
Eric Taylor <Eric.Taylor@Sun.COM>
parents: 7509
diff changeset
   506
	if (make_dataset_handle_common(zhp, &zc) == -1) {
51e9ca9ee3a5 6572357 libzfs should do more to avoid mnttab lookups
Eric Taylor <Eric.Taylor@Sun.COM>
parents: 7509
diff changeset
   507
		free(zhp);
51e9ca9ee3a5 6572357 libzfs should do more to avoid mnttab lookups
Eric Taylor <Eric.Taylor@Sun.COM>
parents: 7509
diff changeset
   508
		zhp = NULL;
51e9ca9ee3a5 6572357 libzfs should do more to avoid mnttab lookups
Eric Taylor <Eric.Taylor@Sun.COM>
parents: 7509
diff changeset
   509
	}
51e9ca9ee3a5 6572357 libzfs should do more to avoid mnttab lookups
Eric Taylor <Eric.Taylor@Sun.COM>
parents: 7509
diff changeset
   510
	zcmd_free_nvlists(&zc);
51e9ca9ee3a5 6572357 libzfs should do more to avoid mnttab lookups
Eric Taylor <Eric.Taylor@Sun.COM>
parents: 7509
diff changeset
   511
	return (zhp);
51e9ca9ee3a5 6572357 libzfs should do more to avoid mnttab lookups
Eric Taylor <Eric.Taylor@Sun.COM>
parents: 7509
diff changeset
   512
}
51e9ca9ee3a5 6572357 libzfs should do more to avoid mnttab lookups
Eric Taylor <Eric.Taylor@Sun.COM>
parents: 7509
diff changeset
   513
51e9ca9ee3a5 6572357 libzfs should do more to avoid mnttab lookups
Eric Taylor <Eric.Taylor@Sun.COM>
parents: 7509
diff changeset
   514
static zfs_handle_t *
51e9ca9ee3a5 6572357 libzfs should do more to avoid mnttab lookups
Eric Taylor <Eric.Taylor@Sun.COM>
parents: 7509
diff changeset
   515
make_dataset_handle_zc(libzfs_handle_t *hdl, zfs_cmd_t *zc)
51e9ca9ee3a5 6572357 libzfs should do more to avoid mnttab lookups
Eric Taylor <Eric.Taylor@Sun.COM>
parents: 7509
diff changeset
   516
{
51e9ca9ee3a5 6572357 libzfs should do more to avoid mnttab lookups
Eric Taylor <Eric.Taylor@Sun.COM>
parents: 7509
diff changeset
   517
	zfs_handle_t *zhp = calloc(sizeof (zfs_handle_t), 1);
51e9ca9ee3a5 6572357 libzfs should do more to avoid mnttab lookups
Eric Taylor <Eric.Taylor@Sun.COM>
parents: 7509
diff changeset
   518
51e9ca9ee3a5 6572357 libzfs should do more to avoid mnttab lookups
Eric Taylor <Eric.Taylor@Sun.COM>
parents: 7509
diff changeset
   519
	if (zhp == NULL)
51e9ca9ee3a5 6572357 libzfs should do more to avoid mnttab lookups
Eric Taylor <Eric.Taylor@Sun.COM>
parents: 7509
diff changeset
   520
		return (NULL);
51e9ca9ee3a5 6572357 libzfs should do more to avoid mnttab lookups
Eric Taylor <Eric.Taylor@Sun.COM>
parents: 7509
diff changeset
   521
51e9ca9ee3a5 6572357 libzfs should do more to avoid mnttab lookups
Eric Taylor <Eric.Taylor@Sun.COM>
parents: 7509
diff changeset
   522
	zhp->zfs_hdl = hdl;
51e9ca9ee3a5 6572357 libzfs should do more to avoid mnttab lookups
Eric Taylor <Eric.Taylor@Sun.COM>
parents: 7509
diff changeset
   523
	(void) strlcpy(zhp->zfs_name, zc->zc_name, sizeof (zhp->zfs_name));
51e9ca9ee3a5 6572357 libzfs should do more to avoid mnttab lookups
Eric Taylor <Eric.Taylor@Sun.COM>
parents: 7509
diff changeset
   524
	if (make_dataset_handle_common(zhp, zc) == -1) {
51e9ca9ee3a5 6572357 libzfs should do more to avoid mnttab lookups
Eric Taylor <Eric.Taylor@Sun.COM>
parents: 7509
diff changeset
   525
		free(zhp);
51e9ca9ee3a5 6572357 libzfs should do more to avoid mnttab lookups
Eric Taylor <Eric.Taylor@Sun.COM>
parents: 7509
diff changeset
   526
		return (NULL);
51e9ca9ee3a5 6572357 libzfs should do more to avoid mnttab lookups
Eric Taylor <Eric.Taylor@Sun.COM>
parents: 7509
diff changeset
   527
	}
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   528
	return (zhp);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   529
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   530
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   531
/*
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   532
 * Opens the given snapshot, filesystem, or volume.   The 'types'
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   533
 * argument is a mask of acceptable types.  The function will print an
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   534
 * appropriate error message and return NULL if it can't be opened.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   535
 */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   536
zfs_handle_t *
2082
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1793
diff changeset
   537
zfs_open(libzfs_handle_t *hdl, const char *path, int types)
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   538
{
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   539
	zfs_handle_t *zhp;
2082
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1793
diff changeset
   540
	char errbuf[1024];
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1793
diff changeset
   541
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1793
diff changeset
   542
	(void) snprintf(errbuf, sizeof (errbuf),
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1793
diff changeset
   543
	    dgettext(TEXT_DOMAIN, "cannot open '%s'"), path);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   544
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   545
	/*
2082
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1793
diff changeset
   546
	 * Validate the name before we even try to open it.
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   547
	 */
5326
6752aa2bd5bc 6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents: 5147
diff changeset
   548
	if (!zfs_validate_name(hdl, path, ZFS_TYPE_DATASET, B_FALSE)) {
2082
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1793
diff changeset
   549
		zfs_error_aux(hdl, dgettext(TEXT_DOMAIN,
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1793
diff changeset
   550
		    "invalid dataset name"));
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1793
diff changeset
   551
		(void) zfs_error(hdl, EZFS_INVALIDNAME, errbuf);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   552
		return (NULL);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   553
	}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   554
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   555
	/*
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   556
	 * Try to get stats for the dataset, which will tell us if it exists.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   557
	 */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   558
	errno = 0;
2082
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1793
diff changeset
   559
	if ((zhp = make_dataset_handle(hdl, path)) == NULL) {
3237
98d0c28f2f5e 6480245 renaming a dataset to something with '%s' will cause segfault
lling
parents: 3234
diff changeset
   560
		(void) zfs_standard_error(hdl, errno, errbuf);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   561
		return (NULL);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   562
	}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   563
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   564
	if (!(types & zhp->zfs_type)) {
2082
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1793
diff changeset
   565
		(void) zfs_error(hdl, EZFS_BADTYPE, errbuf);
2142
f6e0487aa9a3 6433264 crash when adding spare: nvlist_lookup_string(cnv, "path", &path) == 0
eschrock
parents: 2082
diff changeset
   566
		zfs_close(zhp);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   567
		return (NULL);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   568
	}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   569
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   570
	return (zhp);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   571
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   572
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   573
/*
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   574
 * Release a ZFS handle.  Nothing to do but free the associated memory.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   575
 */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   576
void
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   577
zfs_close(zfs_handle_t *zhp)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   578
{
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   579
	if (zhp->zfs_mntopts)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   580
		free(zhp->zfs_mntopts);
2676
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
   581
	nvlist_free(zhp->zfs_props);
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
   582
	nvlist_free(zhp->zfs_user_props);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   583
	free(zhp);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   584
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   585
8228
51e9ca9ee3a5 6572357 libzfs should do more to avoid mnttab lookups
Eric Taylor <Eric.Taylor@Sun.COM>
parents: 7509
diff changeset
   586
typedef struct mnttab_node {
51e9ca9ee3a5 6572357 libzfs should do more to avoid mnttab lookups
Eric Taylor <Eric.Taylor@Sun.COM>
parents: 7509
diff changeset
   587
	struct mnttab mtn_mt;
51e9ca9ee3a5 6572357 libzfs should do more to avoid mnttab lookups
Eric Taylor <Eric.Taylor@Sun.COM>
parents: 7509
diff changeset
   588
	avl_node_t mtn_node;
51e9ca9ee3a5 6572357 libzfs should do more to avoid mnttab lookups
Eric Taylor <Eric.Taylor@Sun.COM>
parents: 7509
diff changeset
   589
} mnttab_node_t;
51e9ca9ee3a5 6572357 libzfs should do more to avoid mnttab lookups
Eric Taylor <Eric.Taylor@Sun.COM>
parents: 7509
diff changeset
   590
51e9ca9ee3a5 6572357 libzfs should do more to avoid mnttab lookups
Eric Taylor <Eric.Taylor@Sun.COM>
parents: 7509
diff changeset
   591
static int
51e9ca9ee3a5 6572357 libzfs should do more to avoid mnttab lookups
Eric Taylor <Eric.Taylor@Sun.COM>
parents: 7509
diff changeset
   592
libzfs_mnttab_cache_compare(const void *arg1, const void *arg2)
51e9ca9ee3a5 6572357 libzfs should do more to avoid mnttab lookups
Eric Taylor <Eric.Taylor@Sun.COM>
parents: 7509
diff changeset
   593
{
51e9ca9ee3a5 6572357 libzfs should do more to avoid mnttab lookups
Eric Taylor <Eric.Taylor@Sun.COM>
parents: 7509
diff changeset
   594
	const mnttab_node_t *mtn1 = arg1;
51e9ca9ee3a5 6572357 libzfs should do more to avoid mnttab lookups
Eric Taylor <Eric.Taylor@Sun.COM>
parents: 7509
diff changeset
   595
	const mnttab_node_t *mtn2 = arg2;
51e9ca9ee3a5 6572357 libzfs should do more to avoid mnttab lookups
Eric Taylor <Eric.Taylor@Sun.COM>
parents: 7509
diff changeset
   596
	int rv;
51e9ca9ee3a5 6572357 libzfs should do more to avoid mnttab lookups
Eric Taylor <Eric.Taylor@Sun.COM>
parents: 7509
diff changeset
   597
51e9ca9ee3a5 6572357 libzfs should do more to avoid mnttab lookups
Eric Taylor <Eric.Taylor@Sun.COM>
parents: 7509
diff changeset
   598
	rv = strcmp(mtn1->mtn_mt.mnt_special, mtn2->mtn_mt.mnt_special);
51e9ca9ee3a5 6572357 libzfs should do more to avoid mnttab lookups
Eric Taylor <Eric.Taylor@Sun.COM>
parents: 7509
diff changeset
   599
51e9ca9ee3a5 6572357 libzfs should do more to avoid mnttab lookups
Eric Taylor <Eric.Taylor@Sun.COM>
parents: 7509
diff changeset
   600
	if (rv == 0)
51e9ca9ee3a5 6572357 libzfs should do more to avoid mnttab lookups
Eric Taylor <Eric.Taylor@Sun.COM>
parents: 7509
diff changeset
   601
		return (0);
51e9ca9ee3a5 6572357 libzfs should do more to avoid mnttab lookups
Eric Taylor <Eric.Taylor@Sun.COM>
parents: 7509
diff changeset
   602
	return (rv > 0 ? 1 : -1);
51e9ca9ee3a5 6572357 libzfs should do more to avoid mnttab lookups
Eric Taylor <Eric.Taylor@Sun.COM>
parents: 7509
diff changeset
   603
}
51e9ca9ee3a5 6572357 libzfs should do more to avoid mnttab lookups
Eric Taylor <Eric.Taylor@Sun.COM>
parents: 7509
diff changeset
   604
51e9ca9ee3a5 6572357 libzfs should do more to avoid mnttab lookups
Eric Taylor <Eric.Taylor@Sun.COM>
parents: 7509
diff changeset
   605
void
51e9ca9ee3a5 6572357 libzfs should do more to avoid mnttab lookups
Eric Taylor <Eric.Taylor@Sun.COM>
parents: 7509
diff changeset
   606
libzfs_mnttab_init(libzfs_handle_t *hdl)
51e9ca9ee3a5 6572357 libzfs should do more to avoid mnttab lookups
Eric Taylor <Eric.Taylor@Sun.COM>
parents: 7509
diff changeset
   607
{
51e9ca9ee3a5 6572357 libzfs should do more to avoid mnttab lookups
Eric Taylor <Eric.Taylor@Sun.COM>
parents: 7509
diff changeset
   608
	struct mnttab entry;
51e9ca9ee3a5 6572357 libzfs should do more to avoid mnttab lookups
Eric Taylor <Eric.Taylor@Sun.COM>
parents: 7509
diff changeset
   609
51e9ca9ee3a5 6572357 libzfs should do more to avoid mnttab lookups
Eric Taylor <Eric.Taylor@Sun.COM>
parents: 7509
diff changeset
   610
	assert(avl_numnodes(&hdl->libzfs_mnttab_cache) == 0);
51e9ca9ee3a5 6572357 libzfs should do more to avoid mnttab lookups
Eric Taylor <Eric.Taylor@Sun.COM>
parents: 7509
diff changeset
   611
	avl_create(&hdl->libzfs_mnttab_cache, libzfs_mnttab_cache_compare,
51e9ca9ee3a5 6572357 libzfs should do more to avoid mnttab lookups
Eric Taylor <Eric.Taylor@Sun.COM>
parents: 7509
diff changeset
   612
	    sizeof (mnttab_node_t), offsetof(mnttab_node_t, mtn_node));
51e9ca9ee3a5 6572357 libzfs should do more to avoid mnttab lookups
Eric Taylor <Eric.Taylor@Sun.COM>
parents: 7509
diff changeset
   613
51e9ca9ee3a5 6572357 libzfs should do more to avoid mnttab lookups
Eric Taylor <Eric.Taylor@Sun.COM>
parents: 7509
diff changeset
   614
	rewind(hdl->libzfs_mnttab);
51e9ca9ee3a5 6572357 libzfs should do more to avoid mnttab lookups
Eric Taylor <Eric.Taylor@Sun.COM>
parents: 7509
diff changeset
   615
	while (getmntent(hdl->libzfs_mnttab, &entry) == 0) {
51e9ca9ee3a5 6572357 libzfs should do more to avoid mnttab lookups
Eric Taylor <Eric.Taylor@Sun.COM>
parents: 7509
diff changeset
   616
		mnttab_node_t *mtn;
51e9ca9ee3a5 6572357 libzfs should do more to avoid mnttab lookups
Eric Taylor <Eric.Taylor@Sun.COM>
parents: 7509
diff changeset
   617
51e9ca9ee3a5 6572357 libzfs should do more to avoid mnttab lookups
Eric Taylor <Eric.Taylor@Sun.COM>
parents: 7509
diff changeset
   618
		if (strcmp(entry.mnt_fstype, MNTTYPE_ZFS) != 0)
51e9ca9ee3a5 6572357 libzfs should do more to avoid mnttab lookups
Eric Taylor <Eric.Taylor@Sun.COM>
parents: 7509
diff changeset
   619
			continue;
51e9ca9ee3a5 6572357 libzfs should do more to avoid mnttab lookups
Eric Taylor <Eric.Taylor@Sun.COM>
parents: 7509
diff changeset
   620
		mtn = zfs_alloc(hdl, sizeof (mnttab_node_t));
51e9ca9ee3a5 6572357 libzfs should do more to avoid mnttab lookups
Eric Taylor <Eric.Taylor@Sun.COM>
parents: 7509
diff changeset
   621
		mtn->mtn_mt.mnt_special = zfs_strdup(hdl, entry.mnt_special);
51e9ca9ee3a5 6572357 libzfs should do more to avoid mnttab lookups
Eric Taylor <Eric.Taylor@Sun.COM>
parents: 7509
diff changeset
   622
		mtn->mtn_mt.mnt_mountp = zfs_strdup(hdl, entry.mnt_mountp);
51e9ca9ee3a5 6572357 libzfs should do more to avoid mnttab lookups
Eric Taylor <Eric.Taylor@Sun.COM>
parents: 7509
diff changeset
   623
		mtn->mtn_mt.mnt_fstype = zfs_strdup(hdl, entry.mnt_fstype);
51e9ca9ee3a5 6572357 libzfs should do more to avoid mnttab lookups
Eric Taylor <Eric.Taylor@Sun.COM>
parents: 7509
diff changeset
   624
		mtn->mtn_mt.mnt_mntopts = zfs_strdup(hdl, entry.mnt_mntopts);
51e9ca9ee3a5 6572357 libzfs should do more to avoid mnttab lookups
Eric Taylor <Eric.Taylor@Sun.COM>
parents: 7509
diff changeset
   625
		avl_add(&hdl->libzfs_mnttab_cache, mtn);
51e9ca9ee3a5 6572357 libzfs should do more to avoid mnttab lookups
Eric Taylor <Eric.Taylor@Sun.COM>
parents: 7509
diff changeset
   626
	}
51e9ca9ee3a5 6572357 libzfs should do more to avoid mnttab lookups
Eric Taylor <Eric.Taylor@Sun.COM>
parents: 7509
diff changeset
   627
}
51e9ca9ee3a5 6572357 libzfs should do more to avoid mnttab lookups
Eric Taylor <Eric.Taylor@Sun.COM>
parents: 7509
diff changeset
   628
51e9ca9ee3a5 6572357 libzfs should do more to avoid mnttab lookups
Eric Taylor <Eric.Taylor@Sun.COM>
parents: 7509
diff changeset
   629
void
51e9ca9ee3a5 6572357 libzfs should do more to avoid mnttab lookups
Eric Taylor <Eric.Taylor@Sun.COM>
parents: 7509
diff changeset
   630
libzfs_mnttab_fini(libzfs_handle_t *hdl)
51e9ca9ee3a5 6572357 libzfs should do more to avoid mnttab lookups
Eric Taylor <Eric.Taylor@Sun.COM>
parents: 7509
diff changeset
   631
{
51e9ca9ee3a5 6572357 libzfs should do more to avoid mnttab lookups
Eric Taylor <Eric.Taylor@Sun.COM>
parents: 7509
diff changeset
   632
	void *cookie = NULL;
51e9ca9ee3a5 6572357 libzfs should do more to avoid mnttab lookups
Eric Taylor <Eric.Taylor@Sun.COM>
parents: 7509
diff changeset
   633
	mnttab_node_t *mtn;
51e9ca9ee3a5 6572357 libzfs should do more to avoid mnttab lookups
Eric Taylor <Eric.Taylor@Sun.COM>
parents: 7509
diff changeset
   634
51e9ca9ee3a5 6572357 libzfs should do more to avoid mnttab lookups
Eric Taylor <Eric.Taylor@Sun.COM>
parents: 7509
diff changeset
   635
	while (mtn = avl_destroy_nodes(&hdl->libzfs_mnttab_cache, &cookie)) {
51e9ca9ee3a5 6572357 libzfs should do more to avoid mnttab lookups
Eric Taylor <Eric.Taylor@Sun.COM>
parents: 7509
diff changeset
   636
		free(mtn->mtn_mt.mnt_special);
51e9ca9ee3a5 6572357 libzfs should do more to avoid mnttab lookups
Eric Taylor <Eric.Taylor@Sun.COM>
parents: 7509
diff changeset
   637
		free(mtn->mtn_mt.mnt_mountp);
51e9ca9ee3a5 6572357 libzfs should do more to avoid mnttab lookups
Eric Taylor <Eric.Taylor@Sun.COM>
parents: 7509
diff changeset
   638
		free(mtn->mtn_mt.mnt_fstype);
51e9ca9ee3a5 6572357 libzfs should do more to avoid mnttab lookups
Eric Taylor <Eric.Taylor@Sun.COM>
parents: 7509
diff changeset
   639
		free(mtn->mtn_mt.mnt_mntopts);
51e9ca9ee3a5 6572357 libzfs should do more to avoid mnttab lookups
Eric Taylor <Eric.Taylor@Sun.COM>
parents: 7509
diff changeset
   640
		free(mtn);
51e9ca9ee3a5 6572357 libzfs should do more to avoid mnttab lookups
Eric Taylor <Eric.Taylor@Sun.COM>
parents: 7509
diff changeset
   641
	}
51e9ca9ee3a5 6572357 libzfs should do more to avoid mnttab lookups
Eric Taylor <Eric.Taylor@Sun.COM>
parents: 7509
diff changeset
   642
	avl_destroy(&hdl->libzfs_mnttab_cache);
51e9ca9ee3a5 6572357 libzfs should do more to avoid mnttab lookups
Eric Taylor <Eric.Taylor@Sun.COM>
parents: 7509
diff changeset
   643
}
51e9ca9ee3a5 6572357 libzfs should do more to avoid mnttab lookups
Eric Taylor <Eric.Taylor@Sun.COM>
parents: 7509
diff changeset
   644
51e9ca9ee3a5 6572357 libzfs should do more to avoid mnttab lookups
Eric Taylor <Eric.Taylor@Sun.COM>
parents: 7509
diff changeset
   645
int
51e9ca9ee3a5 6572357 libzfs should do more to avoid mnttab lookups
Eric Taylor <Eric.Taylor@Sun.COM>
parents: 7509
diff changeset
   646
libzfs_mnttab_find(libzfs_handle_t *hdl, const char *fsname,
51e9ca9ee3a5 6572357 libzfs should do more to avoid mnttab lookups
Eric Taylor <Eric.Taylor@Sun.COM>
parents: 7509
diff changeset
   647
    struct mnttab *entry)
51e9ca9ee3a5 6572357 libzfs should do more to avoid mnttab lookups
Eric Taylor <Eric.Taylor@Sun.COM>
parents: 7509
diff changeset
   648
{
51e9ca9ee3a5 6572357 libzfs should do more to avoid mnttab lookups
Eric Taylor <Eric.Taylor@Sun.COM>
parents: 7509
diff changeset
   649
	mnttab_node_t find;
51e9ca9ee3a5 6572357 libzfs should do more to avoid mnttab lookups
Eric Taylor <Eric.Taylor@Sun.COM>
parents: 7509
diff changeset
   650
	mnttab_node_t *mtn;
51e9ca9ee3a5 6572357 libzfs should do more to avoid mnttab lookups
Eric Taylor <Eric.Taylor@Sun.COM>
parents: 7509
diff changeset
   651
51e9ca9ee3a5 6572357 libzfs should do more to avoid mnttab lookups
Eric Taylor <Eric.Taylor@Sun.COM>
parents: 7509
diff changeset
   652
	if (avl_numnodes(&hdl->libzfs_mnttab_cache) == 0)
51e9ca9ee3a5 6572357 libzfs should do more to avoid mnttab lookups
Eric Taylor <Eric.Taylor@Sun.COM>
parents: 7509
diff changeset
   653
		libzfs_mnttab_init(hdl);
51e9ca9ee3a5 6572357 libzfs should do more to avoid mnttab lookups
Eric Taylor <Eric.Taylor@Sun.COM>
parents: 7509
diff changeset
   654
51e9ca9ee3a5 6572357 libzfs should do more to avoid mnttab lookups
Eric Taylor <Eric.Taylor@Sun.COM>
parents: 7509
diff changeset
   655
	find.mtn_mt.mnt_special = (char *)fsname;
51e9ca9ee3a5 6572357 libzfs should do more to avoid mnttab lookups
Eric Taylor <Eric.Taylor@Sun.COM>
parents: 7509
diff changeset
   656
	mtn = avl_find(&hdl->libzfs_mnttab_cache, &find, NULL);
51e9ca9ee3a5 6572357 libzfs should do more to avoid mnttab lookups
Eric Taylor <Eric.Taylor@Sun.COM>
parents: 7509
diff changeset
   657
	if (mtn) {
51e9ca9ee3a5 6572357 libzfs should do more to avoid mnttab lookups
Eric Taylor <Eric.Taylor@Sun.COM>
parents: 7509
diff changeset
   658
		*entry = mtn->mtn_mt;
51e9ca9ee3a5 6572357 libzfs should do more to avoid mnttab lookups
Eric Taylor <Eric.Taylor@Sun.COM>
parents: 7509
diff changeset
   659
		return (0);
51e9ca9ee3a5 6572357 libzfs should do more to avoid mnttab lookups
Eric Taylor <Eric.Taylor@Sun.COM>
parents: 7509
diff changeset
   660
	}
51e9ca9ee3a5 6572357 libzfs should do more to avoid mnttab lookups
Eric Taylor <Eric.Taylor@Sun.COM>
parents: 7509
diff changeset
   661
	return (ENOENT);
51e9ca9ee3a5 6572357 libzfs should do more to avoid mnttab lookups
Eric Taylor <Eric.Taylor@Sun.COM>
parents: 7509
diff changeset
   662
}
51e9ca9ee3a5 6572357 libzfs should do more to avoid mnttab lookups
Eric Taylor <Eric.Taylor@Sun.COM>
parents: 7509
diff changeset
   663
51e9ca9ee3a5 6572357 libzfs should do more to avoid mnttab lookups
Eric Taylor <Eric.Taylor@Sun.COM>
parents: 7509
diff changeset
   664
void
51e9ca9ee3a5 6572357 libzfs should do more to avoid mnttab lookups
Eric Taylor <Eric.Taylor@Sun.COM>
parents: 7509
diff changeset
   665
libzfs_mnttab_add(libzfs_handle_t *hdl, const char *special,
51e9ca9ee3a5 6572357 libzfs should do more to avoid mnttab lookups
Eric Taylor <Eric.Taylor@Sun.COM>
parents: 7509
diff changeset
   666
    const char *mountp, const char *mntopts)
51e9ca9ee3a5 6572357 libzfs should do more to avoid mnttab lookups
Eric Taylor <Eric.Taylor@Sun.COM>
parents: 7509
diff changeset
   667
{
51e9ca9ee3a5 6572357 libzfs should do more to avoid mnttab lookups
Eric Taylor <Eric.Taylor@Sun.COM>
parents: 7509
diff changeset
   668
	mnttab_node_t *mtn;
51e9ca9ee3a5 6572357 libzfs should do more to avoid mnttab lookups
Eric Taylor <Eric.Taylor@Sun.COM>
parents: 7509
diff changeset
   669
51e9ca9ee3a5 6572357 libzfs should do more to avoid mnttab lookups
Eric Taylor <Eric.Taylor@Sun.COM>
parents: 7509
diff changeset
   670
	if (avl_numnodes(&hdl->libzfs_mnttab_cache) == 0)
51e9ca9ee3a5 6572357 libzfs should do more to avoid mnttab lookups
Eric Taylor <Eric.Taylor@Sun.COM>
parents: 7509
diff changeset
   671
		return;
51e9ca9ee3a5 6572357 libzfs should do more to avoid mnttab lookups
Eric Taylor <Eric.Taylor@Sun.COM>
parents: 7509
diff changeset
   672
	mtn = zfs_alloc(hdl, sizeof (mnttab_node_t));
51e9ca9ee3a5 6572357 libzfs should do more to avoid mnttab lookups
Eric Taylor <Eric.Taylor@Sun.COM>
parents: 7509
diff changeset
   673
	mtn->mtn_mt.mnt_special = zfs_strdup(hdl, special);
51e9ca9ee3a5 6572357 libzfs should do more to avoid mnttab lookups
Eric Taylor <Eric.Taylor@Sun.COM>
parents: 7509
diff changeset
   674
	mtn->mtn_mt.mnt_mountp = zfs_strdup(hdl, mountp);
51e9ca9ee3a5 6572357 libzfs should do more to avoid mnttab lookups
Eric Taylor <Eric.Taylor@Sun.COM>
parents: 7509
diff changeset
   675
	mtn->mtn_mt.mnt_fstype = zfs_strdup(hdl, MNTTYPE_ZFS);
51e9ca9ee3a5 6572357 libzfs should do more to avoid mnttab lookups
Eric Taylor <Eric.Taylor@Sun.COM>
parents: 7509
diff changeset
   676
	mtn->mtn_mt.mnt_mntopts = zfs_strdup(hdl, mntopts);
51e9ca9ee3a5 6572357 libzfs should do more to avoid mnttab lookups
Eric Taylor <Eric.Taylor@Sun.COM>
parents: 7509
diff changeset
   677
	avl_add(&hdl->libzfs_mnttab_cache, mtn);
51e9ca9ee3a5 6572357 libzfs should do more to avoid mnttab lookups
Eric Taylor <Eric.Taylor@Sun.COM>
parents: 7509
diff changeset
   678
}
51e9ca9ee3a5 6572357 libzfs should do more to avoid mnttab lookups
Eric Taylor <Eric.Taylor@Sun.COM>
parents: 7509
diff changeset
   679
51e9ca9ee3a5 6572357 libzfs should do more to avoid mnttab lookups
Eric Taylor <Eric.Taylor@Sun.COM>
parents: 7509
diff changeset
   680
void
51e9ca9ee3a5 6572357 libzfs should do more to avoid mnttab lookups
Eric Taylor <Eric.Taylor@Sun.COM>
parents: 7509
diff changeset
   681
libzfs_mnttab_remove(libzfs_handle_t *hdl, const char *fsname)
51e9ca9ee3a5 6572357 libzfs should do more to avoid mnttab lookups
Eric Taylor <Eric.Taylor@Sun.COM>
parents: 7509
diff changeset
   682
{
51e9ca9ee3a5 6572357 libzfs should do more to avoid mnttab lookups
Eric Taylor <Eric.Taylor@Sun.COM>
parents: 7509
diff changeset
   683
	mnttab_node_t find;
51e9ca9ee3a5 6572357 libzfs should do more to avoid mnttab lookups
Eric Taylor <Eric.Taylor@Sun.COM>
parents: 7509
diff changeset
   684
	mnttab_node_t *ret;
51e9ca9ee3a5 6572357 libzfs should do more to avoid mnttab lookups
Eric Taylor <Eric.Taylor@Sun.COM>
parents: 7509
diff changeset
   685
51e9ca9ee3a5 6572357 libzfs should do more to avoid mnttab lookups
Eric Taylor <Eric.Taylor@Sun.COM>
parents: 7509
diff changeset
   686
	find.mtn_mt.mnt_special = (char *)fsname;
51e9ca9ee3a5 6572357 libzfs should do more to avoid mnttab lookups
Eric Taylor <Eric.Taylor@Sun.COM>
parents: 7509
diff changeset
   687
	if (ret = avl_find(&hdl->libzfs_mnttab_cache, (void *)&find, NULL)) {
51e9ca9ee3a5 6572357 libzfs should do more to avoid mnttab lookups
Eric Taylor <Eric.Taylor@Sun.COM>
parents: 7509
diff changeset
   688
		avl_remove(&hdl->libzfs_mnttab_cache, ret);
51e9ca9ee3a5 6572357 libzfs should do more to avoid mnttab lookups
Eric Taylor <Eric.Taylor@Sun.COM>
parents: 7509
diff changeset
   689
		free(ret->mtn_mt.mnt_special);
51e9ca9ee3a5 6572357 libzfs should do more to avoid mnttab lookups
Eric Taylor <Eric.Taylor@Sun.COM>
parents: 7509
diff changeset
   690
		free(ret->mtn_mt.mnt_mountp);
51e9ca9ee3a5 6572357 libzfs should do more to avoid mnttab lookups
Eric Taylor <Eric.Taylor@Sun.COM>
parents: 7509
diff changeset
   691
		free(ret->mtn_mt.mnt_fstype);
51e9ca9ee3a5 6572357 libzfs should do more to avoid mnttab lookups
Eric Taylor <Eric.Taylor@Sun.COM>
parents: 7509
diff changeset
   692
		free(ret->mtn_mt.mnt_mntopts);
51e9ca9ee3a5 6572357 libzfs should do more to avoid mnttab lookups
Eric Taylor <Eric.Taylor@Sun.COM>
parents: 7509
diff changeset
   693
		free(ret);
51e9ca9ee3a5 6572357 libzfs should do more to avoid mnttab lookups
Eric Taylor <Eric.Taylor@Sun.COM>
parents: 7509
diff changeset
   694
	}
51e9ca9ee3a5 6572357 libzfs should do more to avoid mnttab lookups
Eric Taylor <Eric.Taylor@Sun.COM>
parents: 7509
diff changeset
   695
}
51e9ca9ee3a5 6572357 libzfs should do more to avoid mnttab lookups
Eric Taylor <Eric.Taylor@Sun.COM>
parents: 7509
diff changeset
   696
5713
f9b7933f3770 PSARC/2007/675 A_MDEV Removal
rm160521
parents: 5592
diff changeset
   697
int
f9b7933f3770 PSARC/2007/675 A_MDEV Removal
rm160521
parents: 5592
diff changeset
   698
zfs_spa_version(zfs_handle_t *zhp, int *spa_version)
f9b7933f3770 PSARC/2007/675 A_MDEV Removal
rm160521
parents: 5592
diff changeset
   699
{
6865
176d18c623cc 6539380 zfs list uses too much memory
rm160521
parents: 6612
diff changeset
   700
	zpool_handle_t *zpool_handle = zhp->zpool_hdl;
176d18c623cc 6539380 zfs list uses too much memory
rm160521
parents: 6612
diff changeset
   701
5713
f9b7933f3770 PSARC/2007/675 A_MDEV Removal
rm160521
parents: 5592
diff changeset
   702
	if (zpool_handle == NULL)
f9b7933f3770 PSARC/2007/675 A_MDEV Removal
rm160521
parents: 5592
diff changeset
   703
		return (-1);
f9b7933f3770 PSARC/2007/675 A_MDEV Removal
rm160521
parents: 5592
diff changeset
   704
f9b7933f3770 PSARC/2007/675 A_MDEV Removal
rm160521
parents: 5592
diff changeset
   705
	*spa_version = zpool_get_prop_int(zpool_handle,
f9b7933f3770 PSARC/2007/675 A_MDEV Removal
rm160521
parents: 5592
diff changeset
   706
	    ZPOOL_PROP_VERSION, NULL);
f9b7933f3770 PSARC/2007/675 A_MDEV Removal
rm160521
parents: 5592
diff changeset
   707
	return (0);
f9b7933f3770 PSARC/2007/675 A_MDEV Removal
rm160521
parents: 5592
diff changeset
   708
}
f9b7933f3770 PSARC/2007/675 A_MDEV Removal
rm160521
parents: 5592
diff changeset
   709
f9b7933f3770 PSARC/2007/675 A_MDEV Removal
rm160521
parents: 5592
diff changeset
   710
/*
f9b7933f3770 PSARC/2007/675 A_MDEV Removal
rm160521
parents: 5592
diff changeset
   711
 * The choice of reservation property depends on the SPA version.
f9b7933f3770 PSARC/2007/675 A_MDEV Removal
rm160521
parents: 5592
diff changeset
   712
 */
f9b7933f3770 PSARC/2007/675 A_MDEV Removal
rm160521
parents: 5592
diff changeset
   713
static int
f9b7933f3770 PSARC/2007/675 A_MDEV Removal
rm160521
parents: 5592
diff changeset
   714
zfs_which_resv_prop(zfs_handle_t *zhp, zfs_prop_t *resv_prop)
f9b7933f3770 PSARC/2007/675 A_MDEV Removal
rm160521
parents: 5592
diff changeset
   715
{
f9b7933f3770 PSARC/2007/675 A_MDEV Removal
rm160521
parents: 5592
diff changeset
   716
	int spa_version;
f9b7933f3770 PSARC/2007/675 A_MDEV Removal
rm160521
parents: 5592
diff changeset
   717
f9b7933f3770 PSARC/2007/675 A_MDEV Removal
rm160521
parents: 5592
diff changeset
   718
	if (zfs_spa_version(zhp, &spa_version) < 0)
f9b7933f3770 PSARC/2007/675 A_MDEV Removal
rm160521
parents: 5592
diff changeset
   719
		return (-1);
f9b7933f3770 PSARC/2007/675 A_MDEV Removal
rm160521
parents: 5592
diff changeset
   720
f9b7933f3770 PSARC/2007/675 A_MDEV Removal
rm160521
parents: 5592
diff changeset
   721
	if (spa_version >= SPA_VERSION_REFRESERVATION)
f9b7933f3770 PSARC/2007/675 A_MDEV Removal
rm160521
parents: 5592
diff changeset
   722
		*resv_prop = ZFS_PROP_REFRESERVATION;
f9b7933f3770 PSARC/2007/675 A_MDEV Removal
rm160521
parents: 5592
diff changeset
   723
	else
f9b7933f3770 PSARC/2007/675 A_MDEV Removal
rm160521
parents: 5592
diff changeset
   724
		*resv_prop = ZFS_PROP_RESERVATION;
f9b7933f3770 PSARC/2007/675 A_MDEV Removal
rm160521
parents: 5592
diff changeset
   725
f9b7933f3770 PSARC/2007/675 A_MDEV Removal
rm160521
parents: 5592
diff changeset
   726
	return (0);
f9b7933f3770 PSARC/2007/675 A_MDEV Removal
rm160521
parents: 5592
diff changeset
   727
}
f9b7933f3770 PSARC/2007/675 A_MDEV Removal
rm160521
parents: 5592
diff changeset
   728
3912
f6891a60bd72 PSARC 2007/083 ZFS bootable datasets
lling
parents: 3886
diff changeset
   729
/*
2676
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
   730
 * Given an nvlist of properties to set, validates that they are correct, and
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
   731
 * parses any numeric properties (index, boolean, etc) if they are specified as
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
   732
 * strings.
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   733
 */
7184
9508660f9c27 PSARC 2008/223 Pool root file system properties via zpool(1M)
timh
parents: 7042
diff changeset
   734
nvlist_t *
9508660f9c27 PSARC 2008/223 Pool root file system properties via zpool(1M)
timh
parents: 7042
diff changeset
   735
zfs_valid_proplist(libzfs_handle_t *hdl, zfs_type_t type, nvlist_t *nvl,
5094
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4861
diff changeset
   736
    uint64_t zoned, zfs_handle_t *zhp, const char *errbuf)
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   737
{
2676
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
   738
	nvpair_t *elem;
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
   739
	uint64_t intval;
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
   740
	char *strval;
5094
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4861
diff changeset
   741
	zfs_prop_t prop;
2676
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
   742
	nvlist_t *ret;
5331
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5326
diff changeset
   743
	int chosen_normal = -1;
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5326
diff changeset
   744
	int chosen_utf = -1;
2676
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
   745
5094
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4861
diff changeset
   746
	if (nvlist_alloc(&ret, NV_UNIQUE_NAME, 0) != 0) {
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4861
diff changeset
   747
		(void) no_memory(hdl);
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4861
diff changeset
   748
		return (NULL);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   749
	}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   750
2676
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
   751
	elem = NULL;
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
   752
	while ((elem = nvlist_next_nvpair(nvl, elem)) != NULL) {
5094
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4861
diff changeset
   753
		const char *propname = nvpair_name(elem);
2676
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
   754
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
   755
		/*
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
   756
		 * Make sure this property is valid and applies to this type.
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
   757
		 */
5094
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4861
diff changeset
   758
		if ((prop = zfs_name_to_prop(propname)) == ZPROP_INVAL) {
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4861
diff changeset
   759
			if (!zfs_prop_user(propname)) {
2676
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
   760
				zfs_error_aux(hdl, dgettext(TEXT_DOMAIN,
5094
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4861
diff changeset
   761
				    "invalid property '%s'"), propname);
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4861
diff changeset
   762
				(void) zfs_error(hdl, EZFS_BADPROP, errbuf);
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4861
diff changeset
   763
				goto error;
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4861
diff changeset
   764
			}
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4861
diff changeset
   765
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4861
diff changeset
   766
			/*
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4861
diff changeset
   767
			 * If this is a user property, make sure it's a
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4861
diff changeset
   768
			 * string, and that it's less than ZAP_MAXNAMELEN.
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4861
diff changeset
   769
			 */
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4861
diff changeset
   770
			if (nvpair_type(elem) != DATA_TYPE_STRING) {
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4861
diff changeset
   771
				zfs_error_aux(hdl, dgettext(TEXT_DOMAIN,
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4861
diff changeset
   772
				    "'%s' must be a string"), propname);
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4861
diff changeset
   773
				(void) zfs_error(hdl, EZFS_BADPROP, errbuf);
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4861
diff changeset
   774
				goto error;
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4861
diff changeset
   775
			}
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4861
diff changeset
   776
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4861
diff changeset
   777
			if (strlen(nvpair_name(elem)) >= ZAP_MAXNAMELEN) {
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4861
diff changeset
   778
				zfs_error_aux(hdl, dgettext(TEXT_DOMAIN,
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4861
diff changeset
   779
				    "property name '%s' is too long"),
2676
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
   780
				    propname);
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
   781
				(void) zfs_error(hdl, EZFS_BADPROP, errbuf);
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
   782
				goto error;
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
   783
			}
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
   784
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
   785
			(void) nvpair_value_string(elem, &strval);
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
   786
			if (nvlist_add_string(ret, propname, strval) != 0) {
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
   787
				(void) no_memory(hdl);
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
   788
				goto error;
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
   789
			}
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
   790
			continue;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   791
		}
2676
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
   792
7265
cc18862247da PSARC/2008/483 ZFS clone -o
ahrens
parents: 7184
diff changeset
   793
		if (type == ZFS_TYPE_SNAPSHOT) {
cc18862247da PSARC/2008/483 ZFS clone -o
ahrens
parents: 7184
diff changeset
   794
			zfs_error_aux(hdl, dgettext(TEXT_DOMAIN,
cc18862247da PSARC/2008/483 ZFS clone -o
ahrens
parents: 7184
diff changeset
   795
			    "this property can not be modified for snapshots"));
cc18862247da PSARC/2008/483 ZFS clone -o
ahrens
parents: 7184
diff changeset
   796
			(void) zfs_error(hdl, EZFS_PROPTYPE, errbuf);
cc18862247da PSARC/2008/483 ZFS clone -o
ahrens
parents: 7184
diff changeset
   797
			goto error;
cc18862247da PSARC/2008/483 ZFS clone -o
ahrens
parents: 7184
diff changeset
   798
		}
cc18862247da PSARC/2008/483 ZFS clone -o
ahrens
parents: 7184
diff changeset
   799
2676
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
   800
		if (!zfs_prop_valid_for_type(prop, type)) {
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
   801
			zfs_error_aux(hdl,
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
   802
			    dgettext(TEXT_DOMAIN, "'%s' does not "
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
   803
			    "apply to datasets of this type"), propname);
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
   804
			(void) zfs_error(hdl, EZFS_PROPTYPE, errbuf);
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
   805
			goto error;
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
   806
		}
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
   807
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
   808
		if (zfs_prop_readonly(prop) &&
5331
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5326
diff changeset
   809
		    (!zfs_prop_setonce(prop) || zhp != NULL)) {
2676
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
   810
			zfs_error_aux(hdl,
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
   811
			    dgettext(TEXT_DOMAIN, "'%s' is readonly"),
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
   812
			    propname);
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
   813
			(void) zfs_error(hdl, EZFS_PROPREADONLY, errbuf);
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
   814
			goto error;
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
   815
		}
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
   816
5094
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4861
diff changeset
   817
		if (zprop_parse_value(hdl, elem, prop, type, ret,
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4861
diff changeset
   818
		    &strval, &intval, errbuf) != 0)
2676
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
   819
			goto error;
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
   820
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
   821
		/*
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
   822
		 * Perform some additional checks for specific properties.
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
   823
		 */
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
   824
		switch (prop) {
4577
ed36b0e652bc PSARC/2007/328 zfs upgrade
ahrens
parents: 4543
diff changeset
   825
		case ZFS_PROP_VERSION:
ed36b0e652bc PSARC/2007/328 zfs upgrade
ahrens
parents: 4543
diff changeset
   826
		{
ed36b0e652bc PSARC/2007/328 zfs upgrade
ahrens
parents: 4543
diff changeset
   827
			int version;
ed36b0e652bc PSARC/2007/328 zfs upgrade
ahrens
parents: 4543
diff changeset
   828
ed36b0e652bc PSARC/2007/328 zfs upgrade
ahrens
parents: 4543
diff changeset
   829
			if (zhp == NULL)
ed36b0e652bc PSARC/2007/328 zfs upgrade
ahrens
parents: 4543
diff changeset
   830
				break;
ed36b0e652bc PSARC/2007/328 zfs upgrade
ahrens
parents: 4543
diff changeset
   831
			version = zfs_prop_get_int(zhp, ZFS_PROP_VERSION);
ed36b0e652bc PSARC/2007/328 zfs upgrade
ahrens
parents: 4543
diff changeset
   832
			if (intval < version) {
ed36b0e652bc PSARC/2007/328 zfs upgrade
ahrens
parents: 4543
diff changeset
   833
				zfs_error_aux(hdl, dgettext(TEXT_DOMAIN,
ed36b0e652bc PSARC/2007/328 zfs upgrade
ahrens
parents: 4543
diff changeset
   834
				    "Can not downgrade; already at version %u"),
ed36b0e652bc PSARC/2007/328 zfs upgrade
ahrens
parents: 4543
diff changeset
   835
				    version);
ed36b0e652bc PSARC/2007/328 zfs upgrade
ahrens
parents: 4543
diff changeset
   836
				(void) zfs_error(hdl, EZFS_BADPROP, errbuf);
ed36b0e652bc PSARC/2007/328 zfs upgrade
ahrens
parents: 4543
diff changeset
   837
				goto error;
ed36b0e652bc PSARC/2007/328 zfs upgrade
ahrens
parents: 4543
diff changeset
   838
			}
ed36b0e652bc PSARC/2007/328 zfs upgrade
ahrens
parents: 4543
diff changeset
   839
			break;
ed36b0e652bc PSARC/2007/328 zfs upgrade
ahrens
parents: 4543
diff changeset
   840
		}
ed36b0e652bc PSARC/2007/328 zfs upgrade
ahrens
parents: 4543
diff changeset
   841
2676
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
   842
		case ZFS_PROP_RECORDSIZE:
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
   843
		case ZFS_PROP_VOLBLOCKSIZE:
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
   844
			/* must be power of two within SPA_{MIN,MAX}BLOCKSIZE */
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
   845
			if (intval < SPA_MINBLOCKSIZE ||
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
   846
			    intval > SPA_MAXBLOCKSIZE || !ISP2(intval)) {
2082
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1793
diff changeset
   847
				zfs_error_aux(hdl, dgettext(TEXT_DOMAIN,
2676
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
   848
				    "'%s' must be power of 2 from %u "
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
   849
				    "to %uk"), propname,
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
   850
				    (uint_t)SPA_MINBLOCKSIZE,
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
   851
				    (uint_t)SPA_MAXBLOCKSIZE >> 10);
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
   852
				(void) zfs_error(hdl, EZFS_BADPROP, errbuf);
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
   853
				goto error;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   854
			}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   855
			break;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   856
3126
4f4fb617fdd0 PSARC 2006/622 iSCSI/ZFS Integration
ahl
parents: 2885
diff changeset
   857
		case ZFS_PROP_SHAREISCSI:
4f4fb617fdd0 PSARC 2006/622 iSCSI/ZFS Integration
ahl
parents: 2885
diff changeset
   858
			if (strcmp(strval, "off") != 0 &&
4f4fb617fdd0 PSARC 2006/622 iSCSI/ZFS Integration
ahl
parents: 2885
diff changeset
   859
			    strcmp(strval, "on") != 0 &&
4f4fb617fdd0 PSARC 2006/622 iSCSI/ZFS Integration
ahl
parents: 2885
diff changeset
   860
			    strcmp(strval, "type=disk") != 0) {
4f4fb617fdd0 PSARC 2006/622 iSCSI/ZFS Integration
ahl
parents: 2885
diff changeset
   861
				zfs_error_aux(hdl, dgettext(TEXT_DOMAIN,
4f4fb617fdd0 PSARC 2006/622 iSCSI/ZFS Integration
ahl
parents: 2885
diff changeset
   862
				    "'%s' must be 'on', 'off', or 'type=disk'"),
4f4fb617fdd0 PSARC 2006/622 iSCSI/ZFS Integration
ahl
parents: 2885
diff changeset
   863
				    propname);
4f4fb617fdd0 PSARC 2006/622 iSCSI/ZFS Integration
ahl
parents: 2885
diff changeset
   864
				(void) zfs_error(hdl, EZFS_BADPROP, errbuf);
4f4fb617fdd0 PSARC 2006/622 iSCSI/ZFS Integration
ahl
parents: 2885
diff changeset
   865
				goto error;
4f4fb617fdd0 PSARC 2006/622 iSCSI/ZFS Integration
ahl
parents: 2885
diff changeset
   866
			}
4f4fb617fdd0 PSARC 2006/622 iSCSI/ZFS Integration
ahl
parents: 2885
diff changeset
   867
4f4fb617fdd0 PSARC 2006/622 iSCSI/ZFS Integration
ahl
parents: 2885
diff changeset
   868
			break;
4f4fb617fdd0 PSARC 2006/622 iSCSI/ZFS Integration
ahl
parents: 2885
diff changeset
   869
2676
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
   870
		case ZFS_PROP_MOUNTPOINT:
4778
068cf1db91f1 6446301 ZFS mountpoint reverted back from legacy but sharenfs property not honored
rm160521
parents: 4603
diff changeset
   871
		{
068cf1db91f1 6446301 ZFS mountpoint reverted back from legacy but sharenfs property not honored
rm160521
parents: 4603
diff changeset
   872
			namecheck_err_t why;
068cf1db91f1 6446301 ZFS mountpoint reverted back from legacy but sharenfs property not honored
rm160521
parents: 4603
diff changeset
   873
2676
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
   874
			if (strcmp(strval, ZFS_MOUNTPOINT_NONE) == 0 ||
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
   875
			    strcmp(strval, ZFS_MOUNTPOINT_LEGACY) == 0)
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
   876
				break;
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
   877
4778
068cf1db91f1 6446301 ZFS mountpoint reverted back from legacy but sharenfs property not honored
rm160521
parents: 4603
diff changeset
   878
			if (mountpoint_namecheck(strval, &why)) {
068cf1db91f1 6446301 ZFS mountpoint reverted back from legacy but sharenfs property not honored
rm160521
parents: 4603
diff changeset
   879
				switch (why) {
068cf1db91f1 6446301 ZFS mountpoint reverted back from legacy but sharenfs property not honored
rm160521
parents: 4603
diff changeset
   880
				case NAME_ERR_LEADING_SLASH:
068cf1db91f1 6446301 ZFS mountpoint reverted back from legacy but sharenfs property not honored
rm160521
parents: 4603
diff changeset
   881
					zfs_error_aux(hdl,
068cf1db91f1 6446301 ZFS mountpoint reverted back from legacy but sharenfs property not honored
rm160521
parents: 4603
diff changeset
   882
					    dgettext(TEXT_DOMAIN,
068cf1db91f1 6446301 ZFS mountpoint reverted back from legacy but sharenfs property not honored
rm160521
parents: 4603
diff changeset
   883
					    "'%s' must be an absolute path, "
068cf1db91f1 6446301 ZFS mountpoint reverted back from legacy but sharenfs property not honored
rm160521
parents: 4603
diff changeset
   884
					    "'none', or 'legacy'"), propname);
068cf1db91f1 6446301 ZFS mountpoint reverted back from legacy but sharenfs property not honored
rm160521
parents: 4603
diff changeset
   885
					break;
068cf1db91f1 6446301 ZFS mountpoint reverted back from legacy but sharenfs property not honored
rm160521
parents: 4603
diff changeset
   886
				case NAME_ERR_TOOLONG:
068cf1db91f1 6446301 ZFS mountpoint reverted back from legacy but sharenfs property not honored
rm160521
parents: 4603
diff changeset
   887
					zfs_error_aux(hdl,
068cf1db91f1 6446301 ZFS mountpoint reverted back from legacy but sharenfs property not honored
rm160521
parents: 4603
diff changeset
   888
					    dgettext(TEXT_DOMAIN,
068cf1db91f1 6446301 ZFS mountpoint reverted back from legacy but sharenfs property not honored
rm160521
parents: 4603
diff changeset
   889
					    "component of '%s' is too long"),
068cf1db91f1 6446301 ZFS mountpoint reverted back from legacy but sharenfs property not honored
rm160521
parents: 4603
diff changeset
   890
					    propname);
068cf1db91f1 6446301 ZFS mountpoint reverted back from legacy but sharenfs property not honored
rm160521
parents: 4603
diff changeset
   891
					break;
068cf1db91f1 6446301 ZFS mountpoint reverted back from legacy but sharenfs property not honored
rm160521
parents: 4603
diff changeset
   892
				}
2676
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
   893
				(void) zfs_error(hdl, EZFS_BADPROP, errbuf);
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
   894
				goto error;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   895
			}
4778
068cf1db91f1 6446301 ZFS mountpoint reverted back from legacy but sharenfs property not honored
rm160521
parents: 4603
diff changeset
   896
		}
068cf1db91f1 6446301 ZFS mountpoint reverted back from legacy but sharenfs property not honored
rm160521
parents: 4603
diff changeset
   897
3126
4f4fb617fdd0 PSARC 2006/622 iSCSI/ZFS Integration
ahl
parents: 2885
diff changeset
   898
			/*FALLTHRU*/
4f4fb617fdd0 PSARC 2006/622 iSCSI/ZFS Integration
ahl
parents: 2885
diff changeset
   899
5331
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5326
diff changeset
   900
		case ZFS_PROP_SHARESMB:
3126
4f4fb617fdd0 PSARC 2006/622 iSCSI/ZFS Integration
ahl
parents: 2885
diff changeset
   901
		case ZFS_PROP_SHARENFS:
4f4fb617fdd0 PSARC 2006/622 iSCSI/ZFS Integration
ahl
parents: 2885
diff changeset
   902
			/*
5331
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5326
diff changeset
   903
			 * For the mountpoint and sharenfs or sharesmb
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5326
diff changeset
   904
			 * properties, check if it can be set in a
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5326
diff changeset
   905
			 * global/non-global zone based on
3126
4f4fb617fdd0 PSARC 2006/622 iSCSI/ZFS Integration
ahl
parents: 2885
diff changeset
   906
			 * the zoned property value:
4f4fb617fdd0 PSARC 2006/622 iSCSI/ZFS Integration
ahl
parents: 2885
diff changeset
   907
			 *
4f4fb617fdd0 PSARC 2006/622 iSCSI/ZFS Integration
ahl
parents: 2885
diff changeset
   908
			 *		global zone	    non-global zone
4f4fb617fdd0 PSARC 2006/622 iSCSI/ZFS Integration
ahl
parents: 2885
diff changeset
   909
			 * --------------------------------------------------
4f4fb617fdd0 PSARC 2006/622 iSCSI/ZFS Integration
ahl
parents: 2885
diff changeset
   910
			 * zoned=on	mountpoint (no)	    mountpoint (yes)
4f4fb617fdd0 PSARC 2006/622 iSCSI/ZFS Integration
ahl
parents: 2885
diff changeset
   911
			 *		sharenfs (no)	    sharenfs (no)
5331
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5326
diff changeset
   912
			 *		sharesmb (no)	    sharesmb (no)
3126
4f4fb617fdd0 PSARC 2006/622 iSCSI/ZFS Integration
ahl
parents: 2885
diff changeset
   913
			 *
4f4fb617fdd0 PSARC 2006/622 iSCSI/ZFS Integration
ahl
parents: 2885
diff changeset
   914
			 * zoned=off	mountpoint (yes)	N/A
4f4fb617fdd0 PSARC 2006/622 iSCSI/ZFS Integration
ahl
parents: 2885
diff changeset
   915
			 *		sharenfs (yes)
5331
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5326
diff changeset
   916
			 *		sharesmb (yes)
3126
4f4fb617fdd0 PSARC 2006/622 iSCSI/ZFS Integration
ahl
parents: 2885
diff changeset
   917
			 */
2676
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
   918
			if (zoned) {
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
   919
				if (getzoneid() == GLOBAL_ZONEID) {
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
   920
					zfs_error_aux(hdl, dgettext(TEXT_DOMAIN,
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
   921
					    "'%s' cannot be set on "
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
   922
					    "dataset in a non-global zone"),
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
   923
					    propname);
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
   924
					(void) zfs_error(hdl, EZFS_ZONED,
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
   925
					    errbuf);
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
   926
					goto error;
5331
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5326
diff changeset
   927
				} else if (prop == ZFS_PROP_SHARENFS ||
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5326
diff changeset
   928
				    prop == ZFS_PROP_SHARESMB) {
2676
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
   929
					zfs_error_aux(hdl, dgettext(TEXT_DOMAIN,
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
   930
					    "'%s' cannot be set in "
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
   931
					    "a non-global zone"), propname);
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
   932
					(void) zfs_error(hdl, EZFS_ZONED,
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
   933
					    errbuf);
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
   934
					goto error;
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
   935
				}
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
   936
			} else if (getzoneid() != GLOBAL_ZONEID) {
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
   937
				/*
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
   938
				 * If zoned property is 'off', this must be in
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
   939
				 * a globle zone. If not, something is wrong.
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
   940
				 */
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
   941
				zfs_error_aux(hdl, dgettext(TEXT_DOMAIN,
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
   942
				    "'%s' cannot be set while dataset "
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
   943
				    "'zoned' property is set"), propname);
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
   944
				(void) zfs_error(hdl, EZFS_ZONED, errbuf);
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
   945
				goto error;
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
   946
			}
3126
4f4fb617fdd0 PSARC 2006/622 iSCSI/ZFS Integration
ahl
parents: 2885
diff changeset
   947
4180
30b15f0bd3c9 6491973 sharemgr: zfs set sharenfs=on is slow with lots of zfs filesystems
dougm
parents: 4007
diff changeset
   948
			/*
30b15f0bd3c9 6491973 sharemgr: zfs set sharenfs=on is slow with lots of zfs filesystems
dougm
parents: 4007
diff changeset
   949
			 * At this point, it is legitimate to set the
30b15f0bd3c9 6491973 sharemgr: zfs set sharenfs=on is slow with lots of zfs filesystems
dougm
parents: 4007
diff changeset
   950
			 * property. Now we want to make sure that the
30b15f0bd3c9 6491973 sharemgr: zfs set sharenfs=on is slow with lots of zfs filesystems
dougm
parents: 4007
diff changeset
   951
			 * property value is valid if it is sharenfs.
30b15f0bd3c9 6491973 sharemgr: zfs set sharenfs=on is slow with lots of zfs filesystems
dougm
parents: 4007
diff changeset
   952
			 */
5331
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5326
diff changeset
   953
			if ((prop == ZFS_PROP_SHARENFS ||
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5326
diff changeset
   954
			    prop == ZFS_PROP_SHARESMB) &&
4217
3411a82f178f 6552521 truss dumps core with multibyte characters in syscall args
eschrock
parents: 4183
diff changeset
   955
			    strcmp(strval, "on") != 0 &&
3411a82f178f 6552521 truss dumps core with multibyte characters in syscall args
eschrock
parents: 4183
diff changeset
   956
			    strcmp(strval, "off") != 0) {
5331
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5326
diff changeset
   957
				zfs_share_proto_t proto;
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5326
diff changeset
   958
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5326
diff changeset
   959
				if (prop == ZFS_PROP_SHARESMB)
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5326
diff changeset
   960
					proto = PROTO_SMB;
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5326
diff changeset
   961
				else
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5326
diff changeset
   962
					proto = PROTO_NFS;
4180
30b15f0bd3c9 6491973 sharemgr: zfs set sharenfs=on is slow with lots of zfs filesystems
dougm
parents: 4007
diff changeset
   963
30b15f0bd3c9 6491973 sharemgr: zfs set sharenfs=on is slow with lots of zfs filesystems
dougm
parents: 4007
diff changeset
   964
				/*
5331
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5326
diff changeset
   965
				 * Must be an valid sharing protocol
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5326
diff changeset
   966
				 * option string so init the libshare
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5326
diff changeset
   967
				 * in order to enable the parser and
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5326
diff changeset
   968
				 * then parse the options. We use the
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5326
diff changeset
   969
				 * control API since we don't care about
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5326
diff changeset
   970
				 * the current configuration and don't
4180
30b15f0bd3c9 6491973 sharemgr: zfs set sharenfs=on is slow with lots of zfs filesystems
dougm
parents: 4007
diff changeset
   971
				 * want the overhead of loading it
30b15f0bd3c9 6491973 sharemgr: zfs set sharenfs=on is slow with lots of zfs filesystems
dougm
parents: 4007
diff changeset
   972
				 * until we actually do something.
30b15f0bd3c9 6491973 sharemgr: zfs set sharenfs=on is slow with lots of zfs filesystems
dougm
parents: 4007
diff changeset
   973
				 */
30b15f0bd3c9 6491973 sharemgr: zfs set sharenfs=on is slow with lots of zfs filesystems
dougm
parents: 4007
diff changeset
   974
4217
3411a82f178f 6552521 truss dumps core with multibyte characters in syscall args
eschrock
parents: 4183
diff changeset
   975
				if (zfs_init_libshare(hdl,
3411a82f178f 6552521 truss dumps core with multibyte characters in syscall args
eschrock
parents: 4183
diff changeset
   976
				    SA_INIT_CONTROL_API) != SA_OK) {
3411a82f178f 6552521 truss dumps core with multibyte characters in syscall args
eschrock
parents: 4183
diff changeset
   977
					/*
3411a82f178f 6552521 truss dumps core with multibyte characters in syscall args
eschrock
parents: 4183
diff changeset
   978
					 * An error occurred so we can't do
3411a82f178f 6552521 truss dumps core with multibyte characters in syscall args
eschrock
parents: 4183
diff changeset
   979
					 * anything
3411a82f178f 6552521 truss dumps core with multibyte characters in syscall args
eschrock
parents: 4183
diff changeset
   980
					 */
3411a82f178f 6552521 truss dumps core with multibyte characters in syscall args
eschrock
parents: 4183
diff changeset
   981
					zfs_error_aux(hdl, dgettext(TEXT_DOMAIN,
3411a82f178f 6552521 truss dumps core with multibyte characters in syscall args
eschrock
parents: 4183
diff changeset
   982
					    "'%s' cannot be set: problem "
3411a82f178f 6552521 truss dumps core with multibyte characters in syscall args
eschrock
parents: 4183
diff changeset
   983
					    "in share initialization"),
3411a82f178f 6552521 truss dumps core with multibyte characters in syscall args
eschrock
parents: 4183
diff changeset
   984
					    propname);
3411a82f178f 6552521 truss dumps core with multibyte characters in syscall args
eschrock
parents: 4183
diff changeset
   985
					(void) zfs_error(hdl, EZFS_BADPROP,
3411a82f178f 6552521 truss dumps core with multibyte characters in syscall args
eschrock
parents: 4183
diff changeset
   986
					    errbuf);
3411a82f178f 6552521 truss dumps core with multibyte characters in syscall args
eschrock
parents: 4183
diff changeset
   987
					goto error;
3411a82f178f 6552521 truss dumps core with multibyte characters in syscall args
eschrock
parents: 4183
diff changeset
   988
				}
3411a82f178f 6552521 truss dumps core with multibyte characters in syscall args
eschrock
parents: 4183
diff changeset
   989
5331
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5326
diff changeset
   990
				if (zfs_parse_options(strval, proto) != SA_OK) {
4217
3411a82f178f 6552521 truss dumps core with multibyte characters in syscall args
eschrock
parents: 4183
diff changeset
   991
					/*
3411a82f178f 6552521 truss dumps core with multibyte characters in syscall args
eschrock
parents: 4183
diff changeset
   992
					 * There was an error in parsing so
3411a82f178f 6552521 truss dumps core with multibyte characters in syscall args
eschrock
parents: 4183
diff changeset
   993
					 * deal with it by issuing an error
3411a82f178f 6552521 truss dumps core with multibyte characters in syscall args
eschrock
parents: 4183
diff changeset
   994
					 * message and leaving after
3411a82f178f 6552521 truss dumps core with multibyte characters in syscall args
eschrock
parents: 4183
diff changeset
   995
					 * uninitializing the the libshare
3411a82f178f 6552521 truss dumps core with multibyte characters in syscall args
eschrock
parents: 4183
diff changeset
   996
					 * interface.
3411a82f178f 6552521 truss dumps core with multibyte characters in syscall args
eschrock
parents: 4183
diff changeset
   997
					 */
3411a82f178f 6552521 truss dumps core with multibyte characters in syscall args
eschrock
parents: 4183
diff changeset
   998
					zfs_error_aux(hdl, dgettext(TEXT_DOMAIN,
3411a82f178f 6552521 truss dumps core with multibyte characters in syscall args
eschrock
parents: 4183
diff changeset
   999
					    "'%s' cannot be set to invalid "
3411a82f178f 6552521 truss dumps core with multibyte characters in syscall args
eschrock
parents: 4183
diff changeset
  1000
					    "options"), propname);
3411a82f178f 6552521 truss dumps core with multibyte characters in syscall args
eschrock
parents: 4183
diff changeset
  1001
					(void) zfs_error(hdl, EZFS_BADPROP,
3411a82f178f 6552521 truss dumps core with multibyte characters in syscall args
eschrock
parents: 4183
diff changeset
  1002
					    errbuf);
3411a82f178f 6552521 truss dumps core with multibyte characters in syscall args
eschrock
parents: 4183
diff changeset
  1003
					zfs_uninit_libshare(hdl);
3411a82f178f 6552521 truss dumps core with multibyte characters in syscall args
eschrock
parents: 4183
diff changeset
  1004
					goto error;
3411a82f178f 6552521 truss dumps core with multibyte characters in syscall args
eschrock
parents: 4183
diff changeset
  1005
				}
4180
30b15f0bd3c9 6491973 sharemgr: zfs set sharenfs=on is slow with lots of zfs filesystems
dougm
parents: 4007
diff changeset
  1006
				zfs_uninit_libshare(hdl);
30b15f0bd3c9 6491973 sharemgr: zfs set sharenfs=on is slow with lots of zfs filesystems
dougm
parents: 4007
diff changeset
  1007
			}
30b15f0bd3c9 6491973 sharemgr: zfs set sharenfs=on is slow with lots of zfs filesystems
dougm
parents: 4007
diff changeset
  1008
3126
4f4fb617fdd0 PSARC 2006/622 iSCSI/ZFS Integration
ahl
parents: 2885
diff changeset
  1009
			break;
5331
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5326
diff changeset
  1010
		case ZFS_PROP_UTF8ONLY:
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5326
diff changeset
  1011
			chosen_utf = (int)intval;
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5326
diff changeset
  1012
			break;
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5326
diff changeset
  1013
		case ZFS_PROP_NORMALIZE:
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5326
diff changeset
  1014
			chosen_normal = (int)intval;
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5326
diff changeset
  1015
			break;
2676
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  1016
		}
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  1017
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  1018
		/*
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  1019
		 * For changes to existing volumes, we have some additional
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  1020
		 * checks to enforce.
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  1021
		 */
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  1022
		if (type == ZFS_TYPE_VOLUME && zhp != NULL) {
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  1023
			uint64_t volsize = zfs_prop_get_int(zhp,
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  1024
			    ZFS_PROP_VOLSIZE);
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  1025
			uint64_t blocksize = zfs_prop_get_int(zhp,
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  1026
			    ZFS_PROP_VOLBLOCKSIZE);
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  1027
			char buf[64];
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  1028
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  1029
			switch (prop) {
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  1030
			case ZFS_PROP_RESERVATION:
5378
111aa1baa84a PSARC 2007/555 zfs fs-only quotas and reservations
ck153898
parents: 5375
diff changeset
  1031
			case ZFS_PROP_REFRESERVATION:
2676
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  1032
				if (intval > volsize) {
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  1033
					zfs_error_aux(hdl, dgettext(TEXT_DOMAIN,
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  1034
					    "'%s' is greater than current "
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  1035
					    "volume size"), propname);
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  1036
					(void) zfs_error(hdl, EZFS_BADPROP,
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  1037
					    errbuf);
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  1038
					goto error;
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  1039
				}
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  1040
				break;
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  1041
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  1042
			case ZFS_PROP_VOLSIZE:
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  1043
				if (intval % blocksize != 0) {
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  1044
					zfs_nicenum(blocksize, buf,
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  1045
					    sizeof (buf));
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  1046
					zfs_error_aux(hdl, dgettext(TEXT_DOMAIN,
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  1047
					    "'%s' must be a multiple of "
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  1048
					    "volume block size (%s)"),
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  1049
					    propname, buf);
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  1050
					(void) zfs_error(hdl, EZFS_BADPROP,
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  1051
					    errbuf);
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  1052
					goto error;
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  1053
				}
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  1054
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  1055
				if (intval == 0) {
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  1056
					zfs_error_aux(hdl, dgettext(TEXT_DOMAIN,
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  1057
					    "'%s' cannot be zero"),
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  1058
					    propname);
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  1059
					(void) zfs_error(hdl, EZFS_BADPROP,
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  1060
					    errbuf);
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  1061
					goto error;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1062
				}
3126
4f4fb617fdd0 PSARC 2006/622 iSCSI/ZFS Integration
ahl
parents: 2885
diff changeset
  1063
				break;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1064
			}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1065
		}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1066
	}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1067
2676
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  1068
	/*
5331
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5326
diff changeset
  1069
	 * If normalization was chosen, but no UTF8 choice was made,
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5326
diff changeset
  1070
	 * enforce rejection of non-UTF8 names.
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5326
diff changeset
  1071
	 *
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5326
diff changeset
  1072
	 * If normalization was chosen, but rejecting non-UTF8 names
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5326
diff changeset
  1073
	 * was explicitly not chosen, it is an error.
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5326
diff changeset
  1074
	 */
5498
334b476844ca 6622831 normalization properties are not preserved by "zfs send"
timh
parents: 5481
diff changeset
  1075
	if (chosen_normal > 0 && chosen_utf < 0) {
5331
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5326
diff changeset
  1076
		if (nvlist_add_uint64(ret,
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5326
diff changeset
  1077
		    zfs_prop_to_name(ZFS_PROP_UTF8ONLY), 1) != 0) {
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5326
diff changeset
  1078
			(void) no_memory(hdl);
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5326
diff changeset
  1079
			goto error;
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5326
diff changeset
  1080
		}
5498
334b476844ca 6622831 normalization properties are not preserved by "zfs send"
timh
parents: 5481
diff changeset
  1081
	} else if (chosen_normal > 0 && chosen_utf == 0) {
5331
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5326
diff changeset
  1082
		zfs_error_aux(hdl, dgettext(TEXT_DOMAIN,
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5326
diff changeset
  1083
		    "'%s' must be set 'on' if normalization chosen"),
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5326
diff changeset
  1084
		    zfs_prop_to_name(ZFS_PROP_UTF8ONLY));
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5326
diff changeset
  1085
		(void) zfs_error(hdl, EZFS_BADPROP, errbuf);
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5326
diff changeset
  1086
		goto error;
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5326
diff changeset
  1087
	}
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5326
diff changeset
  1088
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5326
diff changeset
  1089
	/*
2676
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  1090
	 * If this is an existing volume, and someone is setting the volsize,
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  1091
	 * make sure that it matches the reservation, or add it if necessary.
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  1092
	 */
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  1093
	if (zhp != NULL && type == ZFS_TYPE_VOLUME &&
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  1094
	    nvlist_lookup_uint64(ret, zfs_prop_to_name(ZFS_PROP_VOLSIZE),
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  1095
	    &intval) == 0) {
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  1096
		uint64_t old_volsize = zfs_prop_get_int(zhp,
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  1097
		    ZFS_PROP_VOLSIZE);
5481
1364fb7de75d 6619182 new non-sparse zvols should get refreservations
ck153898
parents: 5473
diff changeset
  1098
		uint64_t old_reservation;
2676
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  1099
		uint64_t new_reservation;
5481
1364fb7de75d 6619182 new non-sparse zvols should get refreservations
ck153898
parents: 5473
diff changeset
  1100
		zfs_prop_t resv_prop;
5713
f9b7933f3770 PSARC/2007/675 A_MDEV Removal
rm160521
parents: 5592
diff changeset
  1101
f9b7933f3770 PSARC/2007/675 A_MDEV Removal
rm160521
parents: 5592
diff changeset
  1102
		if (zfs_which_resv_prop(zhp, &resv_prop) < 0)
5481
1364fb7de75d 6619182 new non-sparse zvols should get refreservations
ck153898
parents: 5473
diff changeset
  1103
			goto error;
1364fb7de75d 6619182 new non-sparse zvols should get refreservations
ck153898
parents: 5473
diff changeset
  1104
		old_reservation = zfs_prop_get_int(zhp, resv_prop);
2676
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  1105
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  1106
		if (old_volsize == old_reservation &&
5481
1364fb7de75d 6619182 new non-sparse zvols should get refreservations
ck153898
parents: 5473
diff changeset
  1107
		    nvlist_lookup_uint64(ret, zfs_prop_to_name(resv_prop),
2676
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  1108
		    &new_reservation) != 0) {
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  1109
			if (nvlist_add_uint64(ret,
5481
1364fb7de75d 6619182 new non-sparse zvols should get refreservations
ck153898
parents: 5473
diff changeset
  1110
			    zfs_prop_to_name(resv_prop), intval) != 0) {
2676
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  1111
				(void) no_memory(hdl);
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  1112
				goto error;
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  1113
			}
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  1114
		}
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  1115
	}
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  1116
	return (ret);
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  1117
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  1118
error:
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  1119
	nvlist_free(ret);
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  1120
	return (NULL);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1121
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1122
4543
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  1123
static int
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  1124
zfs_get_perm_who(const char *who, zfs_deleg_who_type_t *who_type,
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  1125
    uint64_t *ret_who)
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  1126
{
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  1127
	struct passwd *pwd;
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  1128
	struct group *grp;
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  1129
	uid_t id;
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  1130
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  1131
	if (*who_type == ZFS_DELEG_EVERYONE || *who_type == ZFS_DELEG_CREATE ||
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  1132
	    *who_type == ZFS_DELEG_NAMED_SET) {
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  1133
		*ret_who = -1;
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  1134
		return (0);
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  1135
	}
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  1136
	if (who == NULL && !(*who_type == ZFS_DELEG_EVERYONE))
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  1137
		return (EZFS_BADWHO);
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  1138
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  1139
	if (*who_type == ZFS_DELEG_WHO_UNKNOWN &&
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  1140
	    strcmp(who, "everyone") == 0) {
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  1141
		*ret_who = -1;
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  1142
		*who_type = ZFS_DELEG_EVERYONE;
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  1143
		return (0);
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  1144
	}
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  1145
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  1146
	pwd = getpwnam(who);
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  1147
	grp = getgrnam(who);
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  1148
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  1149
	if ((*who_type == ZFS_DELEG_USER) && pwd) {
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  1150
		*ret_who = pwd->pw_uid;
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  1151
	} else if ((*who_type == ZFS_DELEG_GROUP) && grp) {
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  1152
		*ret_who = grp->gr_gid;
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  1153
	} else if (pwd) {
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  1154
		*ret_who = pwd->pw_uid;
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  1155
		*who_type = ZFS_DELEG_USER;
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  1156
	} else if (grp) {
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  1157
		*ret_who = grp->gr_gid;
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  1158
		*who_type = ZFS_DELEG_GROUP;
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  1159
	} else {
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  1160
		char *end;
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  1161
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  1162
		id = strtol(who, &end, 10);
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  1163
		if (errno != 0 || *end != '\0') {
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  1164
			return (EZFS_BADWHO);
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  1165
		} else {
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  1166
			*ret_who = id;
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  1167
			if (*who_type == ZFS_DELEG_WHO_UNKNOWN)
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  1168
				*who_type = ZFS_DELEG_USER;
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  1169
		}
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  1170
	}
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  1171
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  1172
	return (0);
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  1173
}
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  1174
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  1175
static void
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  1176
zfs_perms_add_to_nvlist(nvlist_t *who_nvp, char *name, nvlist_t *perms_nvp)
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  1177
{
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  1178
	if (perms_nvp != NULL) {
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  1179
		verify(nvlist_add_nvlist(who_nvp,
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  1180
		    name, perms_nvp) == 0);
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  1181
	} else {
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  1182
		verify(nvlist_add_boolean(who_nvp, name) == 0);
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  1183
	}
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  1184
}
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  1185
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  1186
static void
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  1187
helper(zfs_deleg_who_type_t who_type, uint64_t whoid, char *whostr,
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  1188
    zfs_deleg_inherit_t inherit, nvlist_t *who_nvp, nvlist_t *perms_nvp,
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  1189
    nvlist_t *sets_nvp)
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  1190
{
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  1191
	boolean_t do_perms, do_sets;
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  1192
	char name[ZFS_MAX_DELEG_NAME];
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  1193
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  1194
	do_perms = (nvlist_next_nvpair(perms_nvp, NULL) != NULL);
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  1195
	do_sets = (nvlist_next_nvpair(sets_nvp, NULL) != NULL);
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  1196
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  1197
	if (!do_perms && !do_sets)
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  1198
		do_perms = do_sets = B_TRUE;
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  1199
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  1200
	if (do_perms) {
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  1201
		zfs_deleg_whokey(name, who_type, inherit,
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  1202
		    (who_type == ZFS_DELEG_NAMED_SET) ?
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  1203
		    whostr : (void *)&whoid);
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  1204
		zfs_perms_add_to_nvlist(who_nvp, name, perms_nvp);
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  1205
	}
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  1206
	if (do_sets) {
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  1207
		zfs_deleg_whokey(name, toupper(who_type), inherit,
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  1208
		    (who_type == ZFS_DELEG_NAMED_SET) ?
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  1209
		    whostr : (void *)&whoid);
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  1210
		zfs_perms_add_to_nvlist(who_nvp, name, sets_nvp);
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  1211
	}
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  1212
}
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  1213
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  1214
static void
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  1215
zfs_perms_add_who_nvlist(nvlist_t *who_nvp, uint64_t whoid, void *whostr,
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  1216
    nvlist_t *perms_nvp, nvlist_t *sets_nvp,
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  1217
    zfs_deleg_who_type_t who_type, zfs_deleg_inherit_t inherit)
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  1218
{
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  1219
	if (who_type == ZFS_DELEG_NAMED_SET || who_type == ZFS_DELEG_CREATE) {
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  1220
		helper(who_type, whoid, whostr, 0,
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  1221
		    who_nvp, perms_nvp, sets_nvp);
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  1222
	} else {
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  1223
		if (inherit & ZFS_DELEG_PERM_LOCAL) {
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  1224
			helper(who_type, whoid, whostr, ZFS_DELEG_LOCAL,
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  1225
			    who_nvp, perms_nvp, sets_nvp);
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  1226
		}
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  1227
		if (inherit & ZFS_DELEG_PERM_DESCENDENT) {
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  1228
			helper(who_type, whoid, whostr, ZFS_DELEG_DESCENDENT,
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  1229
			    who_nvp, perms_nvp, sets_nvp);
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  1230
		}
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  1231
	}
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  1232
}
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  1233
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  1234
/*
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  1235
 * Construct nvlist to pass down to kernel for setting/removing permissions.
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  1236
 *
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  1237
 * The nvlist is constructed as a series of nvpairs with an optional embedded
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  1238
 * nvlist of permissions to remove or set.  The topmost nvpairs are the actual
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  1239
 * base attribute named stored in the dsl.
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  1240
 * Arguments:
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  1241
 *
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  1242
 * whostr:   is a comma separated list of users, groups, or a single set name.
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  1243
 *           whostr may be null for everyone or create perms.
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  1244
 * who_type: is the type of entry in whostr.  Typically this will be
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  1245
 *           ZFS_DELEG_WHO_UNKNOWN.
5331
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5326
diff changeset
  1246
 * perms:    common separated list of permissions.  May be null if user
4543
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  1247
 *           is requested to remove permissions by who.
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  1248
 * inherit:  Specifies the inheritance of the permissions.  Will be either
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  1249
 *           ZFS_DELEG_PERM_LOCAL and/or  ZFS_DELEG_PERM_DESCENDENT.
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  1250
 * nvp       The constructed nvlist to pass to zfs_perm_set().
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  1251
 *           The output nvp will look something like this.
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  1252
 *              ul$1234 -> {create ; destroy }
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  1253
 *              Ul$1234 -> { @myset }
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  1254
 *              s-$@myset - { snapshot; checksum; compression }
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  1255
 */
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  1256
int
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  1257
zfs_build_perms(zfs_handle_t *zhp, char *whostr, char *perms,
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  1258
    zfs_deleg_who_type_t who_type, zfs_deleg_inherit_t inherit, nvlist_t **nvp)
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  1259
{
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  1260
	nvlist_t *who_nvp;
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  1261
	nvlist_t *perms_nvp = NULL;
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  1262
	nvlist_t *sets_nvp = NULL;
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  1263
	char errbuf[1024];
4787
602d3f97842c 6393351 unique_* could be improved
ahrens
parents: 4778
diff changeset
  1264
	char *who_tok, *perm;
4543
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  1265
	int error;
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  1266
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  1267
	*nvp = NULL;
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  1268
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  1269
	if (perms) {
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  1270
		if ((error = nvlist_alloc(&perms_nvp,
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  1271
		    NV_UNIQUE_NAME, 0)) != 0) {
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  1272
			return (1);
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  1273
		}
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  1274
		if ((error = nvlist_alloc(&sets_nvp,
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  1275
		    NV_UNIQUE_NAME, 0)) != 0) {
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  1276
			nvlist_free(perms_nvp);
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  1277
			return (1);
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  1278
		}
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  1279
	}
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  1280
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  1281
	if ((error = nvlist_alloc(&who_nvp, NV_UNIQUE_NAME, 0)) != 0) {
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  1282
		if (perms_nvp)
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  1283
			nvlist_free(perms_nvp);
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  1284
		if (sets_nvp)
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  1285
			nvlist_free(sets_nvp);
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  1286
		return (1);
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  1287
	}
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  1288
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  1289
	if (who_type == ZFS_DELEG_NAMED_SET) {
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  1290
		namecheck_err_t why;
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  1291
		char what;
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  1292
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  1293
		if ((error = permset_namecheck(whostr, &why, &what)) != 0) {
4787
602d3f97842c 6393351 unique_* could be improved
ahrens
parents: 4778
diff changeset
  1294
			nvlist_free(who_nvp);
602d3f97842c 6393351 unique_* could be improved
ahrens
parents: 4778
diff changeset
  1295
			if (perms_nvp)
602d3f97842c 6393351 unique_* could be improved
ahrens
parents: 4778
diff changeset
  1296
				nvlist_free(perms_nvp);
602d3f97842c 6393351 unique_* could be improved
ahrens
parents: 4778
diff changeset
  1297
			if (sets_nvp)
602d3f97842c 6393351 unique_* could be improved
ahrens
parents: 4778
diff changeset
  1298
				nvlist_free(sets_nvp);
602d3f97842c 6393351 unique_* could be improved
ahrens
parents: 4778
diff changeset
  1299
4543
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  1300
			switch (why) {
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  1301
			case NAME_ERR_NO_AT:
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  1302
				zfs_error_aux(zhp->zfs_hdl,
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  1303
				    dgettext(TEXT_DOMAIN,
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  1304
				    "set definition must begin with an '@' "
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  1305
				    "character"));
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  1306
			}
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  1307
			return (zfs_error(zhp->zfs_hdl,
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  1308
			    EZFS_BADPERMSET, whostr));
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  1309
		}
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  1310
	}
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  1311
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  1312
	/*
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  1313
	 * Build up nvlist(s) of permissions.  Two nvlists are maintained.
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  1314
	 * The first nvlist perms_nvp will have normal permissions and the
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  1315
	 * other sets_nvp will have only permssion set names in it.
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  1316
	 */
4787
602d3f97842c 6393351 unique_* could be improved
ahrens
parents: 4778
diff changeset
  1317
	for (perm = strtok(perms, ","); perm; perm = strtok(NULL, ",")) {
602d3f97842c 6393351 unique_* could be improved
ahrens
parents: 4778
diff changeset
  1318
		const char *perm_canonical = zfs_deleg_canonicalize_perm(perm);
602d3f97842c 6393351 unique_* could be improved
ahrens
parents: 4778
diff changeset
  1319
602d3f97842c 6393351 unique_* could be improved
ahrens
parents: 4778
diff changeset
  1320
		if (perm_canonical) {
602d3f97842c 6393351 unique_* could be improved
ahrens
parents: 4778
diff changeset
  1321
			verify(nvlist_add_boolean(perms_nvp,
602d3f97842c 6393351 unique_* could be improved
ahrens
parents: 4778
diff changeset
  1322
			    perm_canonical) == 0);
602d3f97842c 6393351 unique_* could be improved
ahrens
parents: 4778
diff changeset
  1323
		} else if (perm[0] == '@') {
602d3f97842c 6393351 unique_* could be improved
ahrens
parents: 4778
diff changeset
  1324
			verify(nvlist_add_boolean(sets_nvp, perm) == 0);
602d3f97842c 6393351 unique_* could be improved
ahrens
parents: 4778
diff changeset
  1325
		} else {
602d3f97842c 6393351 unique_* could be improved
ahrens
parents: 4778
diff changeset
  1326
			nvlist_free(who_nvp);
602d3f97842c 6393351 unique_* could be improved
ahrens
parents: 4778
diff changeset
  1327
			nvlist_free(perms_nvp);
602d3f97842c 6393351 unique_* could be improved
ahrens
parents: 4778
diff changeset
  1328
			nvlist_free(sets_nvp);
602d3f97842c 6393351 unique_* could be improved
ahrens
parents: 4778
diff changeset
  1329
			return (zfs_error(zhp->zfs_hdl, EZFS_BADPERM, perm));
4543
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  1330
		}
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  1331
	}
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  1332
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  1333
	if (whostr && who_type != ZFS_DELEG_CREATE) {
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  1334
		who_tok = strtok(whostr, ",");
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  1335
		if (who_tok == NULL) {
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  1336
			nvlist_free(who_nvp);
4787
602d3f97842c 6393351 unique_* could be improved
ahrens
parents: 4778
diff changeset
  1337
			if (perms_nvp)
602d3f97842c 6393351 unique_* could be improved
ahrens
parents: 4778
diff changeset
  1338
				nvlist_free(perms_nvp);
4543
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  1339
			if (sets_nvp)
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  1340
				nvlist_free(sets_nvp);
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  1341
			(void) snprintf(errbuf, sizeof (errbuf),
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  1342
			    dgettext(TEXT_DOMAIN, "Who string is NULL"),
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  1343
			    whostr);
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  1344
			return (zfs_error(zhp->zfs_hdl, EZFS_BADWHO, errbuf));
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  1345
		}
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  1346
	}
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  1347
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  1348
	/*
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  1349
	 * Now create the nvlist(s)
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  1350
	 */
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  1351
	do {
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  1352
		uint64_t who_id;
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  1353
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  1354
		error = zfs_get_perm_who(who_tok, &who_type,
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  1355
		    &who_id);
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  1356
		if (error) {
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  1357
			nvlist_free(who_nvp);
4787
602d3f97842c 6393351 unique_* could be improved
ahrens
parents: 4778
diff changeset
  1358
			if (perms_nvp)
602d3f97842c 6393351 unique_* could be improved
ahrens
parents: 4778
diff changeset
  1359
				nvlist_free(perms_nvp);
4543
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  1360
			if (sets_nvp)
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  1361
				nvlist_free(sets_nvp);
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  1362
			(void) snprintf(errbuf, sizeof (errbuf),
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  1363
			    dgettext(TEXT_DOMAIN,
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  1364
			    "Unable to determine uid/gid for "
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  1365
			    "%s "), who_tok);
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  1366
			return (zfs_error(zhp->zfs_hdl, EZFS_BADWHO, errbuf));
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  1367
		}
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  1368
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  1369
		/*
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  1370
		 * add entries for both local and descendent when required
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  1371
		 */
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  1372
		zfs_perms_add_who_nvlist(who_nvp, who_id, who_tok,
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  1373
		    perms_nvp, sets_nvp, who_type, inherit);
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  1374
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  1375
	} while (who_tok = strtok(NULL, ","));
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  1376
	*nvp = who_nvp;
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  1377
	return (0);
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  1378
}
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  1379
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  1380
static int
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  1381
zfs_perm_set_common(zfs_handle_t *zhp, nvlist_t *nvp, boolean_t unset)
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  1382
{
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  1383
	zfs_cmd_t zc = { 0 };
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  1384
	int error;
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  1385
	char errbuf[1024];
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  1386
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  1387
	(void) snprintf(errbuf, sizeof (errbuf),
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  1388
	    dgettext(TEXT_DOMAIN, "Cannot update 'allows' for '%s'"),
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  1389
	    zhp->zfs_name);
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  1390
5094
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4861
diff changeset
  1391
	if (zcmd_write_src_nvlist(zhp->zfs_hdl, &zc, nvp))
4543
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  1392
		return (-1);
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  1393
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  1394
	(void) strlcpy(zc.zc_name, zhp->zfs_name, sizeof (zc.zc_name));
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  1395
	zc.zc_perm_action = unset;
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  1396
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  1397
	error = zfs_ioctl(zhp->zfs_hdl, ZFS_IOC_SET_FSACL, &zc);
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  1398
	if (error && errno == ENOTSUP) {
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  1399
		(void) snprintf(errbuf, sizeof (errbuf),
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  1400
		    gettext("Pool must be upgraded to use 'allow/unallow'"));
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  1401
		zcmd_free_nvlists(&zc);
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  1402
		return (zfs_error(zhp->zfs_hdl, EZFS_BADVERSION, errbuf));
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  1403
	} else if (error) {
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  1404
		return (zfs_standard_error(zhp->zfs_hdl, errno, errbuf));
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  1405
	}
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  1406
	zcmd_free_nvlists(&zc);
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  1407
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  1408
	return (error);
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  1409
}
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  1410
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  1411
int
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  1412
zfs_perm_set(zfs_handle_t *zhp, nvlist_t *nvp)
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  1413
{
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  1414
	return (zfs_perm_set_common(zhp, nvp, B_FALSE));
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  1415
}
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  1416
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  1417
int
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  1418
zfs_perm_remove(zfs_handle_t *zhp, nvlist_t *perms)
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  1419
{
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  1420
	return (zfs_perm_set_common(zhp, perms, B_TRUE));
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  1421
}
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  1422
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  1423
static int
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  1424
perm_compare(const void *arg1, const void *arg2)
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  1425
{
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  1426
	const zfs_perm_node_t *node1 = arg1;
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  1427
	const zfs_perm_node_t *node2 = arg2;
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  1428
	int ret;
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  1429
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  1430
	ret = strcmp(node1->z_pname, node2->z_pname);
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  1431
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  1432
	if (ret > 0)
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  1433
		return (1);
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  1434
	if (ret < 0)
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  1435
		return (-1);
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  1436
	else
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  1437
		return (0);
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  1438
}
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  1439
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  1440
static void
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  1441
zfs_destroy_perm_tree(avl_tree_t *tree)
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  1442
{
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  1443
	zfs_perm_node_t *permnode;
5367
c40abbe796be PSARC/2007/574 zfs send -R
ahrens
parents: 5331
diff changeset
  1444
	void *cookie = NULL;
c40abbe796be PSARC/2007/574 zfs send -R
ahrens
parents: 5331
diff changeset
  1445
c40abbe796be PSARC/2007/574 zfs send -R
ahrens
parents: 5331
diff changeset
  1446
	while ((permnode = avl_destroy_nodes(tree,  &cookie)) != NULL)
4543
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  1447
		free(permnode);
5367
c40abbe796be PSARC/2007/574 zfs send -R
ahrens
parents: 5331
diff changeset
  1448
	avl_destroy(tree);
4543
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  1449
}
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  1450
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  1451
static void
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  1452
zfs_destroy_tree(avl_tree_t *tree)
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  1453
{
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  1454
	zfs_allow_node_t *allownode;
5367
c40abbe796be PSARC/2007/574 zfs send -R
ahrens
parents: 5331
diff changeset
  1455
	void *cookie = NULL;
c40abbe796be PSARC/2007/574 zfs send -R
ahrens
parents: 5331
diff changeset
  1456
4543
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  1457
	while ((allownode = avl_destroy_nodes(tree, &cookie)) != NULL) {
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  1458
		zfs_destroy_perm_tree(&allownode->z_localdescend);
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  1459
		zfs_destroy_perm_tree(&allownode->z_local);
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  1460
		zfs_destroy_perm_tree(&allownode->z_descend);
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  1461
		free(allownode);
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  1462
	}
5367
c40abbe796be PSARC/2007/574 zfs send -R
ahrens
parents: 5331
diff changeset
  1463
	avl_destroy(tree);
4543
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  1464
}
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  1465
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  1466
void
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  1467
zfs_free_allows(zfs_allow_t *allow)
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  1468
{
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  1469
	zfs_allow_t *allownext;
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  1470
	zfs_allow_t *freeallow;
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  1471
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  1472
	allownext = allow;
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  1473
	while (allownext) {
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  1474
		zfs_destroy_tree(&allownext->z_sets);
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  1475
		zfs_destroy_tree(&allownext->z_crperms);
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  1476
		zfs_destroy_tree(&allownext->z_user);
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  1477
		zfs_destroy_tree(&allownext->z_group);
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  1478
		zfs_destroy_tree(&allownext->z_everyone);
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  1479
		freeallow = allownext;
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  1480
		allownext = allownext->z_next;
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  1481
		free(freeallow);
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  1482
	}
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  1483
}
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  1484
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  1485
static zfs_allow_t *
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  1486
zfs_alloc_perm_tree(zfs_handle_t *zhp, zfs_allow_t *prev, char *setpoint)
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  1487
{
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  1488
	zfs_allow_t *ptree;
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  1489
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  1490
	if ((ptree = zfs_alloc(zhp->zfs_hdl,
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  1491
	    sizeof (zfs_allow_t))) == NULL) {
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  1492
		return (NULL);
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  1493
	}
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  1494
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  1495
	(void) strlcpy(ptree->z_setpoint, setpoint, sizeof (ptree->z_setpoint));
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  1496
	avl_create(&ptree->z_sets,
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  1497
	    perm_compare, sizeof (zfs_allow_node_t),
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  1498
	    offsetof(zfs_allow_node_t, z_node));
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  1499
	avl_create(&ptree->z_crperms,
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  1500
	    perm_compare, sizeof (zfs_allow_node_t),
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  1501
	    offsetof(zfs_allow_node_t, z_node));
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  1502
	avl_create(&ptree->z_user,
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  1503
	    perm_compare, sizeof (zfs_allow_node_t),
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  1504
	    offsetof(zfs_allow_node_t, z_node));
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  1505
	avl_create(&ptree->z_group,
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  1506
	    perm_compare, sizeof (zfs_allow_node_t),
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  1507
	    offsetof(zfs_allow_node_t, z_node));
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  1508
	avl_create(&ptree->z_everyone,
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  1509
	    perm_compare, sizeof (zfs_allow_node_t),
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  1510
	    offsetof(zfs_allow_node_t, z_node));
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  1511
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  1512
	if (prev)
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  1513
		prev->z_next = ptree;
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  1514
	ptree->z_next = NULL;
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  1515
	return (ptree);
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  1516
}
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  1517
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  1518
/*
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  1519
 * Add permissions to the appropriate AVL permission tree.
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  1520
 * The appropriate tree may not be the requested tree.
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  1521
 * For example if ld indicates a local permission, but
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  1522
 * same permission also exists as a descendent permission
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  1523
 * then the permission will be removed from the descendent
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  1524
 * tree and add the the local+descendent tree.
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  1525
 */
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  1526
static int
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  1527
zfs_coalesce_perm(zfs_handle_t *zhp, zfs_allow_node_t *allownode,
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  1528
    char *perm, char ld)
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  1529
{
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  1530
	zfs_perm_node_t pnode, *permnode, *permnode2;
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  1531
	zfs_perm_node_t *newnode;
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  1532
	avl_index_t where, where2;
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  1533
	avl_tree_t *tree, *altree;
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  1534
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  1535
	(void) strlcpy(pnode.z_pname, perm, sizeof (pnode.z_pname));
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  1536
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  1537
	if (ld == ZFS_DELEG_NA) {
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  1538
		tree =  &allownode->z_localdescend;
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  1539
		altree = &allownode->z_descend;
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  1540
	} else if (ld == ZFS_DELEG_LOCAL) {
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  1541
		tree = &allownode->z_local;
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  1542
		altree = &allownode->z_descend;
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  1543
	} else {
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  1544
		tree = &allownode->z_descend;
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  1545
		altree = &allownode->z_local;
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  1546
	}
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  1547
	permnode = avl_find(tree, &pnode, &where);
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  1548
	permnode2 = avl_find(altree, &pnode, &where2);
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  1549
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  1550
	if (permnode2) {
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  1551
		avl_remove(altree, permnode2);
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  1552
		free(permnode2);
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  1553
		if (permnode == NULL) {
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  1554
			tree =  &allownode->z_localdescend;
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  1555
		}
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  1556
	}
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  1557
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  1558
	/*
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  1559
	 * Now insert new permission in either requested location
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  1560
	 * local/descendent or into ld when perm will exist in both.
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  1561
	 */
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  1562
	if (permnode == NULL) {
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  1563
		if ((newnode = zfs_alloc(zhp->zfs_hdl,
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  1564
		    sizeof (zfs_perm_node_t))) == NULL) {
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  1565
			return (-1);
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  1566
		}
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  1567
		*newnode = pnode;
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  1568
		avl_add(tree, newnode);
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  1569
	}
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  1570
	return (0);
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  1571
}
4577
ed36b0e652bc PSARC/2007/328 zfs upgrade
ahrens
parents: 4543
diff changeset
  1572
4543
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  1573
/*
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  1574
 * Uggh, this is going to be a bit complicated.
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  1575
 * we have an nvlist coming out of the kernel that
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  1576
 * will indicate where the permission is set and then
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  1577
 * it will contain allow of the various "who's", and what
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  1578
 * their permissions are.  To further complicate this
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  1579
 * we will then have to coalesce the local,descendent
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  1580
 * and local+descendent permissions where appropriate.
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  1581
 * The kernel only knows about a permission as being local
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  1582
 * or descendent, but not both.
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  1583
 *
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  1584
 * In order to make this easier for zfs_main to deal with
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  1585
 * a series of AVL trees will be used to maintain
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  1586
 * all of this, primarily for sorting purposes as well
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  1587
 * as the ability to quickly locate a specific entry.
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  1588
 *
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  1589
 * What we end up with are tree's for sets, create perms,
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  1590
 * user, groups and everyone.  With each of those trees
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  1591
 * we have subtrees for local, descendent and local+descendent
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  1592
 * permissions.
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  1593
 */
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  1594
int
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  1595
zfs_perm_get(zfs_handle_t *zhp, zfs_allow_t **zfs_perms)
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  1596
{
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  1597
	zfs_cmd_t zc = { 0 };
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  1598
	int error;
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  1599
	nvlist_t *nvlist;
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  1600
	nvlist_t *permnv, *sourcenv;
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  1601
	nvpair_t *who_pair, *source_pair;
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  1602
	nvpair_t *perm_pair;
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  1603
	char errbuf[1024];
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  1604
	zfs_allow_t *zallowp, *newallowp;
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  1605
	char  ld;
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  1606
	char *nvpname;
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  1607
	uid_t	uid;
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  1608
	gid_t	gid;
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  1609
	avl_tree_t *tree;
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  1610
	avl_index_t where;
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  1611
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  1612
	(void) strlcpy(zc.zc_name, zhp->zfs_name, sizeof (zc.zc_name));
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  1613
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  1614
	if (zcmd_alloc_dst_nvlist(zhp->zfs_hdl, &zc, 0) != 0)
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  1615
		return (-1);
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  1616
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  1617
	while (ioctl(zhp->zfs_hdl->libzfs_fd, ZFS_IOC_GET_FSACL, &zc) != 0) {
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  1618
		if (errno == ENOMEM) {
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  1619
			if (zcmd_expand_dst_nvlist(zhp->zfs_hdl, &zc) != 0) {
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  1620
				zcmd_free_nvlists(&zc);
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  1621
				return (-1);
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  1622
			}
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  1623
		} else if (errno == ENOTSUP) {
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  1624
			zcmd_free_nvlists(&zc);
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  1625
			(void) snprintf(errbuf, sizeof (errbuf),
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  1626
			    gettext("Pool must be upgraded to use 'allow'"));
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  1627
			return (zfs_error(zhp->zfs_hdl,
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  1628
			    EZFS_BADVERSION, errbuf));
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  1629
		} else {
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  1630
			zcmd_free_nvlists(&zc);
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  1631
			return (-1);
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  1632
		}
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  1633
	}
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  1634
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  1635
	if (zcmd_read_dst_nvlist(zhp->zfs_hdl, &zc, &nvlist) != 0) {
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  1636
		zcmd_free_nvlists(&zc);
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  1637
		return (-1);
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  1638
	}
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  1639
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  1640
	zcmd_free_nvlists(&zc);
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  1641
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  1642
	source_pair = nvlist_next_nvpair(nvlist, NULL);
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  1643
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  1644
	if (source_pair == NULL) {
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  1645
		*zfs_perms = NULL;
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  1646
		return (0);
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  1647
	}
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  1648
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  1649
	*zfs_perms = zfs_alloc_perm_tree(zhp, NULL, nvpair_name(source_pair));
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  1650
	if (*zfs_perms == NULL) {
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  1651
		return (0);
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  1652
	}
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  1653
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  1654
	zallowp = *zfs_perms;
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  1655
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  1656
	for (;;) {
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  1657
		struct passwd *pwd;
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  1658
		struct group *grp;
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  1659
		zfs_allow_node_t *allownode;
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  1660
		zfs_allow_node_t  findallownode;
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  1661
		zfs_allow_node_t *newallownode;
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  1662
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  1663
		(void) strlcpy(zallowp->z_setpoint,
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  1664
		    nvpair_name(source_pair),
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  1665
		    sizeof (zallowp->z_setpoint));
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  1666
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  1667
		if ((error = nvpair_value_nvlist(source_pair, &sourcenv)) != 0)
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  1668
			goto abort;
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  1669
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  1670
		/*
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  1671
		 * Make sure nvlist is composed correctly
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  1672
		 */
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  1673
		if (zfs_deleg_verify_nvlist(sourcenv)) {
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  1674
			goto abort;
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  1675
		}
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  1676
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  1677
		who_pair = nvlist_next_nvpair(sourcenv, NULL);
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  1678
		if (who_pair == NULL) {
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  1679
			goto abort;
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  1680
		}
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  1681
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  1682
		do {
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  1683
			error = nvpair_value_nvlist(who_pair, &permnv);
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  1684
			if (error) {
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  1685
				goto abort;
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  1686
			}
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  1687
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  1688
			/*
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  1689
			 * First build up the key to use
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  1690
			 * for looking up in the various
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  1691
			 * who trees.
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  1692
			 */
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  1693
			ld = nvpair_name(who_pair)[1];
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  1694
			nvpname = nvpair_name(who_pair);
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  1695
			switch (nvpair_name(who_pair)[0]) {
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  1696
			case ZFS_DELEG_USER:
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  1697
			case ZFS_DELEG_USER_SETS:
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  1698
				tree = &zallowp->z_user;
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  1699
				uid = atol(&nvpname[3]);
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  1700
				pwd = getpwuid(uid);
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  1701
				(void) snprintf(findallownode.z_key,
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  1702
				    sizeof (findallownode.z_key), "user %s",
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  1703
				    (pwd) ? pwd->pw_name :
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  1704
				    &nvpair_name(who_pair)[3]);
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  1705
				break;
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  1706
			case ZFS_DELEG_GROUP:
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  1707
			case ZFS_DELEG_GROUP_SETS:
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  1708
				tree = &zallowp->z_group;
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  1709
				gid = atol(&nvpname[3]);
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  1710
				grp = getgrgid(gid);
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  1711
				(void) snprintf(findallownode.z_key,
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  1712
				    sizeof (findallownode.z_key), "group %s",
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  1713
				    (grp) ? grp->gr_name :
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  1714
				    &nvpair_name(who_pair)[3]);
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  1715
				break;
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  1716
			case ZFS_DELEG_CREATE:
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  1717
			case ZFS_DELEG_CREATE_SETS:
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  1718
				tree = &zallowp->z_crperms;
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  1719
				(void) strlcpy(findallownode.z_key, "",
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  1720
				    sizeof (findallownode.z_key));
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  1721
				break;
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  1722
			case ZFS_DELEG_EVERYONE:
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  1723
			case ZFS_DELEG_EVERYONE_SETS:
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  1724
				(void) snprintf(findallownode.z_key,
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  1725
				    sizeof (findallownode.z_key), "everyone");
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  1726
				tree = &zallowp->z_everyone;
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  1727
				break;
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  1728
			case ZFS_DELEG_NAMED_SET:
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  1729
			case ZFS_DELEG_NAMED_SET_SETS:
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  1730
				(void) snprintf(findallownode.z_key,
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  1731
				    sizeof (findallownode.z_key), "%s",
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  1732
				    &nvpair_name(who_pair)[3]);
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  1733
				tree = &zallowp->z_sets;
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  1734
				break;
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  1735
			}
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  1736
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  1737
			/*
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  1738
			 * Place who in tree
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  1739
			 */
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  1740
			allownode = avl_find(tree, &findallownode, &where);
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  1741
			if (allownode == NULL) {
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  1742
				if ((newallownode = zfs_alloc(zhp->zfs_hdl,
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  1743
				    sizeof (zfs_allow_node_t))) == NULL) {
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  1744
					goto abort;
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  1745
				}
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  1746
				avl_create(&newallownode->z_localdescend,
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  1747
				    perm_compare,
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  1748
				    sizeof (zfs_perm_node_t),
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  1749
				    offsetof(zfs_perm_node_t, z_node));
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  1750
				avl_create(&newallownode->z_local,
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  1751
				    perm_compare,
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  1752
				    sizeof (zfs_perm_node_t),
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  1753
				    offsetof(zfs_perm_node_t, z_node));
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  1754
				avl_create(&newallownode->z_descend,
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  1755
				    perm_compare,
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  1756
				    sizeof (zfs_perm_node_t),
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  1757
				    offsetof(zfs_perm_node_t, z_node));
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  1758
				(void) strlcpy(newallownode->z_key,
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  1759
				    findallownode.z_key,
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  1760
				    sizeof (findallownode.z_key));
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  1761
				avl_insert(tree, newallownode, where);
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  1762
				allownode = newallownode;
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  1763
			}
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  1764
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  1765
			/*
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  1766
			 * Now iterate over the permissions and
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  1767
			 * place them in the appropriate local,
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  1768
			 * descendent or local+descendent tree.
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  1769
			 *
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  1770
			 * The permissions are added to the tree
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  1771
			 * via zfs_coalesce_perm().
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  1772
			 */
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  1773
			perm_pair = nvlist_next_nvpair(permnv, NULL);
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  1774
			if (perm_pair == NULL)
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  1775
				goto abort;
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  1776
			do {
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  1777
				if (zfs_coalesce_perm(zhp, allownode,
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  1778
				    nvpair_name(perm_pair), ld) != 0)
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  1779
					goto abort;
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  1780
			} while (perm_pair = nvlist_next_nvpair(permnv,
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  1781
			    perm_pair));
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  1782
		} while (who_pair = nvlist_next_nvpair(sourcenv, who_pair));
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  1783
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  1784
		source_pair = nvlist_next_nvpair(nvlist, source_pair);
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  1785
		if (source_pair == NULL)
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  1786
			break;
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  1787
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  1788
		/*
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  1789
		 * allocate another node from the link list of
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  1790
		 * zfs_allow_t structures
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  1791
		 */
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  1792
		newallowp = zfs_alloc_perm_tree(zhp, zallowp,
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  1793
		    nvpair_name(source_pair));
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  1794
		if (newallowp == NULL) {
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  1795
			goto abort;
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  1796
		}
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  1797
		zallowp = newallowp;
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  1798
	}
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  1799
	nvlist_free(nvlist);
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  1800
	return (0);
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  1801
abort:
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  1802
	zfs_free_allows(*zfs_perms);
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  1803
	nvlist_free(nvlist);
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  1804
	return (-1);
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  1805
}
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  1806
5993
6309c3c0a28f 6576659 zfs allow should list delegatable perms
marks
parents: 5977
diff changeset
  1807
static char *
6309c3c0a28f 6576659 zfs allow should list delegatable perms
marks
parents: 5977
diff changeset
  1808
zfs_deleg_perm_note(zfs_deleg_note_t note)
6309c3c0a28f 6576659 zfs allow should list delegatable perms
marks
parents: 5977
diff changeset
  1809
{
6309c3c0a28f 6576659 zfs allow should list delegatable perms
marks
parents: 5977
diff changeset
  1810
	/*
6309c3c0a28f 6576659 zfs allow should list delegatable perms
marks
parents: 5977
diff changeset
  1811
	 * Don't put newlines on end of lines
6309c3c0a28f 6576659 zfs allow should list delegatable perms
marks
parents: 5977
diff changeset
  1812
	 */
6309c3c0a28f 6576659 zfs allow should list delegatable perms
marks
parents: 5977
diff changeset
  1813
	switch (note) {
6309c3c0a28f 6576659 zfs allow should list delegatable perms
marks
parents: 5977
diff changeset
  1814
	case ZFS_DELEG_NOTE_CREATE:
6309c3c0a28f 6576659 zfs allow should list delegatable perms
marks
parents: 5977
diff changeset
  1815
		return (dgettext(TEXT_DOMAIN,
6309c3c0a28f 6576659 zfs allow should list delegatable perms
marks
parents: 5977
diff changeset
  1816
		    "Must also have the 'mount' ability"));
6309c3c0a28f 6576659 zfs allow should list delegatable perms
marks
parents: 5977
diff changeset
  1817
	case ZFS_DELEG_NOTE_DESTROY:
6309c3c0a28f 6576659 zfs allow should list delegatable perms
marks
parents: 5977
diff changeset
  1818
		return (dgettext(TEXT_DOMAIN,
6309c3c0a28f 6576659 zfs allow should list delegatable perms
marks
parents: 5977
diff changeset
  1819
		    "Must also have the 'mount' ability"));
6309c3c0a28f 6576659 zfs allow should list delegatable perms
marks
parents: 5977
diff changeset
  1820
	case ZFS_DELEG_NOTE_SNAPSHOT:
6309c3c0a28f 6576659 zfs allow should list delegatable perms
marks
parents: 5977
diff changeset
  1821
		return (dgettext(TEXT_DOMAIN,
6309c3c0a28f 6576659 zfs allow should list delegatable perms
marks
parents: 5977
diff changeset
  1822
		    "Must also have the 'mount' ability"));
6309c3c0a28f 6576659 zfs allow should list delegatable perms
marks
parents: 5977
diff changeset
  1823
	case ZFS_DELEG_NOTE_ROLLBACK:
6309c3c0a28f 6576659 zfs allow should list delegatable perms
marks
parents: 5977
diff changeset
  1824
		return (dgettext(TEXT_DOMAIN,
6309c3c0a28f 6576659 zfs allow should list delegatable perms
marks
parents: 5977
diff changeset
  1825
		    "Must also have the 'mount' ability"));
6309c3c0a28f 6576659 zfs allow should list delegatable perms
marks
parents: 5977
diff changeset
  1826
	case ZFS_DELEG_NOTE_CLONE:
6309c3c0a28f 6576659 zfs allow should list delegatable perms
marks
parents: 5977
diff changeset
  1827
		return (dgettext(TEXT_DOMAIN, "Must also have the 'create' "
6309c3c0a28f 6576659 zfs allow should list delegatable perms
marks
parents: 5977
diff changeset
  1828
		    "ability and 'mount'\n"
6309c3c0a28f 6576659 zfs allow should list delegatable perms
marks
parents: 5977
diff changeset
  1829
		    "\t\t\t\tability in the origin file system"));
6309c3c0a28f 6576659 zfs allow should list delegatable perms
marks
parents: 5977
diff changeset
  1830
	case ZFS_DELEG_NOTE_PROMOTE:
6309c3c0a28f 6576659 zfs allow should list delegatable perms
marks
parents: 5977
diff changeset
  1831
		return (dgettext(TEXT_DOMAIN, "Must also have the 'mount'\n"
6309c3c0a28f 6576659 zfs allow should list delegatable perms
marks
parents: 5977
diff changeset
  1832
		    "\t\t\t\tand 'promote' ability in the origin file system"));
6309c3c0a28f 6576659 zfs allow should list delegatable perms
marks
parents: 5977
diff changeset
  1833
	case ZFS_DELEG_NOTE_RENAME:
6309c3c0a28f 6576659 zfs allow should list delegatable perms
marks
parents: 5977
diff changeset
  1834
		return (dgettext(TEXT_DOMAIN, "Must also have the 'mount' "
6309c3c0a28f 6576659 zfs allow should list delegatable perms
marks
parents: 5977
diff changeset
  1835
		    "and 'create' \n\t\t\t\tability in the new parent"));
6309c3c0a28f 6576659 zfs allow should list delegatable perms
marks
parents: 5977
diff changeset
  1836
	case ZFS_DELEG_NOTE_RECEIVE:
6309c3c0a28f 6576659 zfs allow should list delegatable perms
marks
parents: 5977
diff changeset
  1837
		return (dgettext(TEXT_DOMAIN, "Must also have the 'mount'"
6309c3c0a28f 6576659 zfs allow should list delegatable perms
marks
parents: 5977
diff changeset
  1838
		    " and 'create' ability"));
6309c3c0a28f 6576659 zfs allow should list delegatable perms
marks
parents: 5977
diff changeset
  1839
	case ZFS_DELEG_NOTE_USERPROP:
6309c3c0a28f 6576659 zfs allow should list delegatable perms
marks
parents: 5977
diff changeset
  1840
		return (dgettext(TEXT_DOMAIN,
6309c3c0a28f 6576659 zfs allow should list delegatable perms
marks
parents: 5977
diff changeset
  1841
		    "Allows changing any user property"));
6309c3c0a28f 6576659 zfs allow should list delegatable perms
marks
parents: 5977
diff changeset
  1842
	case ZFS_DELEG_NOTE_ALLOW:
6309c3c0a28f 6576659 zfs allow should list delegatable perms
marks
parents: 5977
diff changeset
  1843
		return (dgettext(TEXT_DOMAIN,
6309c3c0a28f 6576659 zfs allow should list delegatable perms
marks
parents: 5977
diff changeset
  1844
		    "Must also have the permission that is being\n"
6309c3c0a28f 6576659 zfs allow should list delegatable perms
marks
parents: 5977
diff changeset
  1845
		    "\t\t\t\tallowed"));
6309c3c0a28f 6576659 zfs allow should list delegatable perms
marks
parents: 5977
diff changeset
  1846
	case ZFS_DELEG_NOTE_MOUNT:
6309c3c0a28f 6576659 zfs allow should list delegatable perms
marks
parents: 5977
diff changeset
  1847
		return (dgettext(TEXT_DOMAIN,
6309c3c0a28f 6576659 zfs allow should list delegatable perms
marks
parents: 5977
diff changeset
  1848
		    "Allows mount/umount of ZFS datasets"));
6309c3c0a28f 6576659 zfs allow should list delegatable perms
marks
parents: 5977
diff changeset
  1849
	case ZFS_DELEG_NOTE_SHARE:
6309c3c0a28f 6576659 zfs allow should list delegatable perms
marks
parents: 5977
diff changeset
  1850
		return (dgettext(TEXT_DOMAIN,
6309c3c0a28f 6576659 zfs allow should list delegatable perms
marks
parents: 5977
diff changeset
  1851
		    "Allows sharing file systems over NFS or SMB\n"
6309c3c0a28f 6576659 zfs allow should list delegatable perms
marks
parents: 5977
diff changeset
  1852
		    "\t\t\t\tprotocols"));
6309c3c0a28f 6576659 zfs allow should list delegatable perms
marks
parents: 5977
diff changeset
  1853
	case ZFS_DELEG_NOTE_NONE:
6309c3c0a28f 6576659 zfs allow should list delegatable perms
marks
parents: 5977
diff changeset
  1854
	default:
6309c3c0a28f 6576659 zfs allow should list delegatable perms
marks
parents: 5977
diff changeset
  1855
		return (dgettext(TEXT_DOMAIN, ""));
6309c3c0a28f 6576659 zfs allow should list delegatable perms
marks
parents: 5977
diff changeset
  1856
	}
6309c3c0a28f 6576659 zfs allow should list delegatable perms
marks
parents: 5977
diff changeset
  1857
}
6309c3c0a28f 6576659 zfs allow should list delegatable perms
marks
parents: 5977
diff changeset
  1858
6309c3c0a28f 6576659 zfs allow should list delegatable perms
marks
parents: 5977
diff changeset
  1859
typedef enum {
6309c3c0a28f 6576659 zfs allow should list delegatable perms
marks
parents: 5977
diff changeset
  1860
	ZFS_DELEG_SUBCOMMAND,
6309c3c0a28f 6576659 zfs allow should list delegatable perms
marks
parents: 5977
diff changeset
  1861
	ZFS_DELEG_PROP,
6309c3c0a28f 6576659 zfs allow should list delegatable perms
marks
parents: 5977
diff changeset
  1862
	ZFS_DELEG_OTHER
6309c3c0a28f 6576659 zfs allow should list delegatable perms
marks
parents: 5977
diff changeset
  1863
} zfs_deleg_perm_type_t;
6309c3c0a28f 6576659 zfs allow should list delegatable perms
marks
parents: 5977
diff changeset
  1864
6309c3c0a28f 6576659 zfs allow should list delegatable perms
marks
parents: 5977
diff changeset
  1865
/*
6309c3c0a28f 6576659 zfs allow should list delegatable perms
marks
parents: 5977
diff changeset
  1866
 * is the permission a subcommand or other?
6309c3c0a28f 6576659 zfs allow should list delegatable perms
marks
parents: 5977
diff changeset
  1867
 */
6309c3c0a28f 6576659 zfs allow should list delegatable perms
marks
parents: 5977
diff changeset
  1868
zfs_deleg_perm_type_t
6309c3c0a28f 6576659 zfs allow should list delegatable perms
marks
parents: 5977
diff changeset
  1869
zfs_deleg_perm_type(const char *perm)
6309c3c0a28f 6576659 zfs allow should list delegatable perms
marks
parents: 5977
diff changeset
  1870
{
6309c3c0a28f 6576659 zfs allow should list delegatable perms
marks
parents: 5977
diff changeset
  1871
	if (strcmp(perm, "userprop") == 0)
6309c3c0a28f 6576659 zfs allow should list delegatable perms
marks
parents: 5977
diff changeset
  1872
		return (ZFS_DELEG_OTHER);
6309c3c0a28f 6576659 zfs allow should list delegatable perms
marks
parents: 5977
diff changeset
  1873
	else
6309c3c0a28f 6576659 zfs allow should list delegatable perms
marks
parents: 5977
diff changeset
  1874
		return (ZFS_DELEG_SUBCOMMAND);
6309c3c0a28f 6576659 zfs allow should list delegatable perms
marks
parents: 5977
diff changeset
  1875
}
6309c3c0a28f 6576659 zfs allow should list delegatable perms
marks
parents: 5977
diff changeset
  1876
6309c3c0a28f 6576659 zfs allow should list delegatable perms
marks
parents: 5977
diff changeset
  1877
static char *
6309c3c0a28f 6576659 zfs allow should list delegatable perms
marks
parents: 5977
diff changeset
  1878
zfs_deleg_perm_type_str(zfs_deleg_perm_type_t type)
6309c3c0a28f 6576659 zfs allow should list delegatable perms
marks
parents: 5977
diff changeset
  1879
{
6309c3c0a28f 6576659 zfs allow should list delegatable perms
marks
parents: 5977
diff changeset
  1880
	switch (type) {
6309c3c0a28f 6576659 zfs allow should list delegatable perms
marks
parents: 5977
diff changeset
  1881
	case ZFS_DELEG_SUBCOMMAND:
6309c3c0a28f 6576659 zfs allow should list delegatable perms
marks
parents: 5977
diff changeset
  1882
		return (dgettext(TEXT_DOMAIN, "subcommand"));
6309c3c0a28f 6576659 zfs allow should list delegatable perms
marks
parents: 5977
diff changeset
  1883
	case ZFS_DELEG_PROP:
6309c3c0a28f 6576659 zfs allow should list delegatable perms
marks
parents: 5977
diff changeset
  1884
		return (dgettext(TEXT_DOMAIN, "property"));
6309c3c0a28f 6576659 zfs allow should list delegatable perms
marks
parents: 5977
diff changeset
  1885
	case ZFS_DELEG_OTHER:
6309c3c0a28f 6576659 zfs allow should list delegatable perms
marks
parents: 5977
diff changeset
  1886
		return (dgettext(TEXT_DOMAIN, "other"));
6309c3c0a28f 6576659 zfs allow should list delegatable perms
marks
parents: 5977
diff changeset
  1887
	}
6309c3c0a28f 6576659 zfs allow should list delegatable perms
marks
parents: 5977
diff changeset
  1888
	return ("");
6309c3c0a28f 6576659 zfs allow should list delegatable perms
marks
parents: 5977
diff changeset
  1889
}
6309c3c0a28f 6576659 zfs allow should list delegatable perms
marks
parents: 5977
diff changeset
  1890
6309c3c0a28f 6576659 zfs allow should list delegatable perms
marks
parents: 5977
diff changeset
  1891
/*ARGSUSED*/
6309c3c0a28f 6576659 zfs allow should list delegatable perms
marks
parents: 5977
diff changeset
  1892
static int
6309c3c0a28f 6576659 zfs allow should list delegatable perms
marks
parents: 5977
diff changeset
  1893
zfs_deleg_prop_cb(int prop, void *cb)
6309c3c0a28f 6576659 zfs allow should list delegatable perms
marks
parents: 5977
diff changeset
  1894
{
6309c3c0a28f 6576659 zfs allow should list delegatable perms
marks
parents: 5977
diff changeset
  1895
	if (zfs_prop_delegatable(prop))
6309c3c0a28f 6576659 zfs allow should list delegatable perms
marks
parents: 5977
diff changeset
  1896
		(void) fprintf(stderr, "%-15s %-15s\n", zfs_prop_to_name(prop),
6309c3c0a28f 6576659 zfs allow should list delegatable perms
marks
parents: 5977
diff changeset
  1897
		    zfs_deleg_perm_type_str(ZFS_DELEG_PROP));
6309c3c0a28f 6576659 zfs allow should list delegatable perms
marks
parents: 5977
diff changeset
  1898
6309c3c0a28f 6576659 zfs allow should list delegatable perms
marks
parents: 5977
diff changeset
  1899
	return (ZPROP_CONT);
6309c3c0a28f 6576659 zfs allow should list delegatable perms
marks
parents: 5977
diff changeset
  1900
}
6309c3c0a28f 6576659 zfs allow should list delegatable perms
marks
parents: 5977
diff changeset
  1901
6309c3c0a28f 6576659 zfs allow should list delegatable perms
marks
parents: 5977
diff changeset
  1902
void
6309c3c0a28f 6576659 zfs allow should list delegatable perms
marks
parents: 5977
diff changeset
  1903
zfs_deleg_permissions(void)
6309c3c0a28f 6576659 zfs allow should list delegatable perms
marks
parents: 5977
diff changeset
  1904
{
6309c3c0a28f 6576659 zfs allow should list delegatable perms
marks
parents: 5977
diff changeset
  1905
	int i;
6309c3c0a28f 6576659 zfs allow should list delegatable perms
marks
parents: 5977
diff changeset
  1906
6309c3c0a28f 6576659 zfs allow should list delegatable perms
marks
parents: 5977
diff changeset
  1907
	(void) fprintf(stderr, "\n%-15s %-15s\t%s\n\n", "NAME",
6309c3c0a28f 6576659 zfs allow should list delegatable perms
marks
parents: 5977
diff changeset
  1908
	    "TYPE", "NOTES");
6309c3c0a28f 6576659 zfs allow should list delegatable perms
marks
parents: 5977
diff changeset
  1909
6309c3c0a28f 6576659 zfs allow should list delegatable perms
marks
parents: 5977
diff changeset
  1910
	/*
6309c3c0a28f 6576659 zfs allow should list delegatable perms
marks
parents: 5977
diff changeset
  1911
	 * First print out the subcommands
6309c3c0a28f 6576659 zfs allow should list delegatable perms
marks
parents: 5977
diff changeset
  1912
	 */
6309c3c0a28f 6576659 zfs allow should list delegatable perms
marks
parents: 5977
diff changeset
  1913
	for (i = 0; zfs_deleg_perm_tab[i].z_perm != NULL; i++) {
6309c3c0a28f 6576659 zfs allow should list delegatable perms
marks
parents: 5977
diff changeset
  1914
		(void) fprintf(stderr, "%-15s %-15s\t%s\n",
6309c3c0a28f 6576659 zfs allow should list delegatable perms
marks
parents: 5977
diff changeset
  1915
		    zfs_deleg_perm_tab[i].z_perm,
6309c3c0a28f 6576659 zfs allow should list delegatable perms
marks
parents: 5977
diff changeset
  1916
		    zfs_deleg_perm_type_str(
6309c3c0a28f 6576659 zfs allow should list delegatable perms
marks
parents: 5977
diff changeset
  1917
		    zfs_deleg_perm_type(zfs_deleg_perm_tab[i].z_perm)),
6309c3c0a28f 6576659 zfs allow should list delegatable perms
marks
parents: 5977
diff changeset
  1918
		    zfs_deleg_perm_note(zfs_deleg_perm_tab[i].z_note));
6309c3c0a28f 6576659 zfs allow should list delegatable perms
marks
parents: 5977
diff changeset
  1919
	}
6309c3c0a28f 6576659 zfs allow should list delegatable perms
marks
parents: 5977
diff changeset
  1920
6309c3c0a28f 6576659 zfs allow should list delegatable perms
marks
parents: 5977
diff changeset
  1921
	(void) zprop_iter(zfs_deleg_prop_cb, NULL, B_FALSE, B_TRUE,
6309c3c0a28f 6576659 zfs allow should list delegatable perms
marks
parents: 5977
diff changeset
  1922
	    ZFS_TYPE_DATASET|ZFS_TYPE_VOLUME);
6309c3c0a28f 6576659 zfs allow should list delegatable perms
marks
parents: 5977
diff changeset
  1923
}
6309c3c0a28f 6576659 zfs allow should list delegatable perms
marks
parents: 5977
diff changeset
  1924
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1925
/*
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1926
 * Given a property name and value, set the property for the given dataset.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1927
 */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1928
int
2676
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  1929
zfs_prop_set(zfs_handle_t *zhp, const char *propname, const char *propval)
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1930
{
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1931
	zfs_cmd_t zc = { 0 };
2676
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  1932
	int ret = -1;
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  1933
	prop_changelist_t *cl = NULL;
2082
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1793
diff changeset
  1934
	char errbuf[1024];
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1793
diff changeset
  1935
	libzfs_handle_t *hdl = zhp->zfs_hdl;
2676
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  1936
	nvlist_t *nvl = NULL, *realprops;
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  1937
	zfs_prop_t prop;
7509
24f6b0f4654f 6739303 Setting canmount=noauto should not require unmounting and remounting a dataset
Mark J Musante <Mark.Musante@Sun.COM>
parents: 7390
diff changeset
  1938
	boolean_t do_prefix;
24f6b0f4654f 6739303 Setting canmount=noauto should not require unmounting and remounting a dataset
Mark J Musante <Mark.Musante@Sun.COM>
parents: 7390
diff changeset
  1939
	uint64_t idx;
2082
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1793
diff changeset
  1940
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1793
diff changeset
  1941
	(void) snprintf(errbuf, sizeof (errbuf),
2676
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  1942
	    dgettext(TEXT_DOMAIN, "cannot set property for '%s'"),
2082
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1793
diff changeset
  1943
	    zhp->zfs_name);
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1793
diff changeset
  1944
2676
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  1945
	if (nvlist_alloc(&nvl, NV_UNIQUE_NAME, 0) != 0 ||
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  1946
	    nvlist_add_string(nvl, propname, propval) != 0) {
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  1947
		(void) no_memory(hdl);
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  1948
		goto error;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1949
	}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1950
7184
9508660f9c27 PSARC 2008/223 Pool root file system properties via zpool(1M)
timh
parents: 7042
diff changeset
  1951
	if ((realprops = zfs_valid_proplist(hdl, zhp->zfs_type, nvl,
2676
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  1952
	    zfs_prop_get_int(zhp, ZFS_PROP_ZONED), zhp, errbuf)) == NULL)
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  1953
		goto error;
5094
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4861
diff changeset
  1954
2676
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  1955
	nvlist_free(nvl);
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  1956
	nvl = realprops;
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  1957
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  1958
	prop = zfs_name_to_prop(propname);
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  1959
7366
33de5956afbb 6678308 zfs receive dumps core when -n is used, fails on replication stream
Tim Haley <Tim.Haley@Sun.COM>
parents: 7301
diff changeset
  1960
	if ((cl = changelist_gather(zhp, prop, 0, 0)) == NULL)
2676
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  1961
		goto error;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1962
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1963
	if (prop == ZFS_PROP_MOUNTPOINT && changelist_haszonedchild(cl)) {
2082
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1793
diff changeset
  1964
		zfs_error_aux(hdl, dgettext(TEXT_DOMAIN,
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1793
diff changeset
  1965
		    "child dataset with inherited mountpoint is used "
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1793
diff changeset
  1966
		    "in a non-global zone"));
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1793
diff changeset
  1967
		ret = zfs_error(hdl, EZFS_ZONED, errbuf);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1968
		goto error;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1969
	}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1970
7509
24f6b0f4654f 6739303 Setting canmount=noauto should not require unmounting and remounting a dataset
Mark J Musante <Mark.Musante@Sun.COM>
parents: 7390
diff changeset
  1971
	/*
24f6b0f4654f 6739303 Setting canmount=noauto should not require unmounting and remounting a dataset
Mark J Musante <Mark.Musante@Sun.COM>
parents: 7390
diff changeset
  1972
	 * If the dataset's canmount property is being set to noauto,
24f6b0f4654f 6739303 Setting canmount=noauto should not require unmounting and remounting a dataset
Mark J Musante <Mark.Musante@Sun.COM>
parents: 7390
diff changeset
  1973
	 * then we want to prevent unmounting & remounting it.
24f6b0f4654f 6739303 Setting canmount=noauto should not require unmounting and remounting a dataset
Mark J Musante <Mark.Musante@Sun.COM>
parents: 7390
diff changeset
  1974
	 */
24f6b0f4654f 6739303 Setting canmount=noauto should not require unmounting and remounting a dataset
Mark J Musante <Mark.Musante@Sun.COM>
parents: 7390
diff changeset
  1975
	do_prefix = !((prop == ZFS_PROP_CANMOUNT) &&
24f6b0f4654f 6739303 Setting canmount=noauto should not require unmounting and remounting a dataset
Mark J Musante <Mark.Musante@Sun.COM>
parents: 7390
diff changeset
  1976
	    (zprop_string_to_index(prop, propval, &idx,
24f6b0f4654f 6739303 Setting canmount=noauto should not require unmounting and remounting a dataset
Mark J Musante <Mark.Musante@Sun.COM>
parents: 7390
diff changeset
  1977
	    ZFS_TYPE_DATASET) == 0) && (idx == ZFS_CANMOUNT_NOAUTO));
6168
51c045dcc498 PSARC 2008/168 Support for ZFS property value canmount=noauto
hs24103
parents: 5993
diff changeset
  1978
51c045dcc498 PSARC 2008/168 Support for ZFS property value canmount=noauto
hs24103
parents: 5993
diff changeset
  1979
	if (do_prefix && (ret = changelist_prefix(cl)) != 0)
7509
24f6b0f4654f 6739303 Setting canmount=noauto should not require unmounting and remounting a dataset
Mark J Musante <Mark.Musante@Sun.COM>
parents: 7390
diff changeset
  1980
		goto error;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1981
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1982
	/*
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1983
	 * Execute the corresponding ioctl() to set this property.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1984
	 */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1985
	(void) strlcpy(zc.zc_name, zhp->zfs_name, sizeof (zc.zc_name));
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1986
5094
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4861
diff changeset
  1987
	if (zcmd_write_src_nvlist(hdl, &zc, nvl) != 0)
2676
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  1988
		goto error;
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  1989
4543
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  1990
	ret = zfs_ioctl(hdl, ZFS_IOC_SET_PROP, &zc);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1991
	if (ret != 0) {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1992
		switch (errno) {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1993
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1994
		case ENOSPC:
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1995
			/*
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1996
			 * For quotas and reservations, ENOSPC indicates
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1997
			 * something different; setting a quota or reservation
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1998
			 * doesn't use any disk space.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1999
			 */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2000
			switch (prop) {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2001
			case ZFS_PROP_QUOTA:
5378
111aa1baa84a PSARC 2007/555 zfs fs-only quotas and reservations
ck153898
parents: 5375
diff changeset
  2002
			case ZFS_PROP_REFQUOTA:
2082
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1793
diff changeset
  2003
				zfs_error_aux(hdl, dgettext(TEXT_DOMAIN,
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1793
diff changeset
  2004
				    "size is less than current used or "
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1793
diff changeset
  2005
				    "reserved space"));
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1793
diff changeset
  2006
				(void) zfs_error(hdl, EZFS_PROPSPACE, errbuf);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2007
				break;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2008
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2009
			case ZFS_PROP_RESERVATION:
5378
111aa1baa84a PSARC 2007/555 zfs fs-only quotas and reservations
ck153898
parents: 5375
diff changeset
  2010
			case ZFS_PROP_REFRESERVATION:
2082
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1793
diff changeset
  2011
				zfs_error_aux(hdl, dgettext(TEXT_DOMAIN,
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1793
diff changeset
  2012
				    "size is greater than available space"));
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1793
diff changeset
  2013
				(void) zfs_error(hdl, EZFS_PROPSPACE, errbuf);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2014
				break;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2015
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2016
			default:
2082
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1793
diff changeset
  2017
				(void) zfs_standard_error(hdl, errno, errbuf);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2018
				break;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2019
			}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2020
			break;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2021
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2022
		case EBUSY:
2082
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1793
diff changeset
  2023
			if (prop == ZFS_PROP_VOLBLOCKSIZE)
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1793
diff changeset
  2024
				(void) zfs_error(hdl, EZFS_VOLHASDATA, errbuf);
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1793
diff changeset
  2025
			else
2676
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  2026
				(void) zfs_standard_error(hdl, EBUSY, errbuf);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2027
			break;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2028
1175
759d20c7e57b 6366265 attach/replace should allow a new device size at least the min of all devs in a mirror/raidz
lling
parents: 1133
diff changeset
  2029
		case EROFS:
2082
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1793
diff changeset
  2030
			(void) zfs_error(hdl, EZFS_DSREADONLY, errbuf);
1175
759d20c7e57b 6366265 attach/replace should allow a new device size at least the min of all devs in a mirror/raidz
lling
parents: 1133
diff changeset
  2031
			break;
759d20c7e57b 6366265 attach/replace should allow a new device size at least the min of all devs in a mirror/raidz
lling
parents: 1133
diff changeset
  2032
3886
3291401d66a6 6536602 add zlib compression support and upgrade to version 1.2.3
ahl
parents: 3835
diff changeset
  2033
		case ENOTSUP:
3291401d66a6 6536602 add zlib compression support and upgrade to version 1.2.3
ahl
parents: 3835
diff changeset
  2034
			zfs_error_aux(hdl, dgettext(TEXT_DOMAIN,
5977
33727f49aeaa 6654731 sharesmb property should only be settable on CIFS aware ZPL
marks
parents: 5751
diff changeset
  2035
			    "pool and or dataset must be upgraded to set this "
4603
c7840c367d00 6494569 zfs recv -d pool/<doesn't exist> core dumps for top-level filesystem backups
ahrens
parents: 4597
diff changeset
  2036
			    "property or value"));
3886
3291401d66a6 6536602 add zlib compression support and upgrade to version 1.2.3
ahl
parents: 3835
diff changeset
  2037
			(void) zfs_error(hdl, EZFS_BADVERSION, errbuf);
3291401d66a6 6536602 add zlib compression support and upgrade to version 1.2.3
ahl
parents: 3835
diff changeset
  2038
			break;
3291401d66a6 6536602 add zlib compression support and upgrade to version 1.2.3
ahl
parents: 3835
diff changeset
  2039
7042
46fc4b6db23e 6721094 Setting certain properties on root pools should not be allowed
gw25295
parents: 6865
diff changeset
  2040
		case ERANGE:
46fc4b6db23e 6721094 Setting certain properties on root pools should not be allowed
gw25295
parents: 6865
diff changeset
  2041
			if (prop == ZFS_PROP_COMPRESSION) {
46fc4b6db23e 6721094 Setting certain properties on root pools should not be allowed
gw25295
parents: 6865
diff changeset
  2042
				(void) zfs_error_aux(hdl, dgettext(TEXT_DOMAIN,
46fc4b6db23e 6721094 Setting certain properties on root pools should not be allowed
gw25295
parents: 6865
diff changeset
  2043
				    "property setting is not allowed on "
46fc4b6db23e 6721094 Setting certain properties on root pools should not be allowed
gw25295
parents: 6865
diff changeset
  2044
				    "bootable datasets"));
46fc4b6db23e 6721094 Setting certain properties on root pools should not be allowed
gw25295
parents: 6865
diff changeset
  2045
				(void) zfs_error(hdl, EZFS_NOTSUP, errbuf);
46fc4b6db23e 6721094 Setting certain properties on root pools should not be allowed
gw25295
parents: 6865
diff changeset
  2046
			} else {
46fc4b6db23e 6721094 Setting certain properties on root pools should not be allowed
gw25295
parents: 6865
diff changeset
  2047
				(void) zfs_standard_error(hdl, errno, errbuf);
46fc4b6db23e 6721094 Setting certain properties on root pools should not be allowed
gw25295
parents: 6865
diff changeset
  2048
			}
46fc4b6db23e 6721094 Setting certain properties on root pools should not be allowed
gw25295
parents: 6865
diff changeset
  2049
			break;
46fc4b6db23e 6721094 Setting certain properties on root pools should not be allowed
gw25295
parents: 6865
diff changeset
  2050
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2051
		case EOVERFLOW:
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2052
			/*
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2053
			 * This platform can't address a volume this big.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2054
			 */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2055
#ifdef _ILP32
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2056
			if (prop == ZFS_PROP_VOLSIZE) {
2082
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1793
diff changeset
  2057
				(void) zfs_error(hdl, EZFS_VOLTOOBIG, errbuf);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2058
				break;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2059
			}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2060
#endif
2082
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1793
diff changeset
  2061
			/* FALLTHROUGH */
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2062
		default:
2082
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1793
diff changeset
  2063
			(void) zfs_standard_error(hdl, errno, errbuf);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2064
		}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2065
	} else {
6168
51c045dcc498 PSARC 2008/168 Support for ZFS property value canmount=noauto
hs24103
parents: 5993
diff changeset
  2066
		if (do_prefix)
51c045dcc498 PSARC 2008/168 Support for ZFS property value canmount=noauto
hs24103
parents: 5993
diff changeset
  2067
			ret = changelist_postfix(cl);
51c045dcc498 PSARC 2008/168 Support for ZFS property value canmount=noauto
hs24103
parents: 5993
diff changeset
  2068
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2069
		/*
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2070
		 * Refresh the statistics so the new property value
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2071
		 * is reflected.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2072
		 */
6168
51c045dcc498 PSARC 2008/168 Support for ZFS property value canmount=noauto
hs24103
parents: 5993
diff changeset
  2073
		if (ret == 0)
2676
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  2074
			(void) get_stats(zhp);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2075
	}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2076
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2077
error:
2676
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  2078
	nvlist_free(nvl);
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  2079
	zcmd_free_nvlists(&zc);
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  2080
	if (cl)
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  2081
		changelist_free(cl);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2082
	return (ret);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2083
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2084
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2085
/*
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2086
 * Given a property, inherit the value from the parent dataset.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2087
 */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2088
int
2676
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  2089
zfs_prop_inherit(zfs_handle_t *zhp, const char *propname)
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2090
{
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2091
	zfs_cmd_t zc = { 0 };
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2092
	int ret;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2093
	prop_changelist_t *cl;
2082
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1793
diff changeset
  2094
	libzfs_handle_t *hdl = zhp->zfs_hdl;
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1793
diff changeset
  2095
	char errbuf[1024];
2676
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  2096
	zfs_prop_t prop;
2082
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1793
diff changeset
  2097
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1793
diff changeset
  2098
	(void) snprintf(errbuf, sizeof (errbuf), dgettext(TEXT_DOMAIN,
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1793
diff changeset
  2099
	    "cannot inherit %s for '%s'"), propname, zhp->zfs_name);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2100
5094
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4861
diff changeset
  2101
	if ((prop = zfs_name_to_prop(propname)) == ZPROP_INVAL) {
2676
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  2102
		/*
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  2103
		 * For user properties, the amount of work we have to do is very
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  2104
		 * small, so just do it here.
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  2105
		 */
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  2106
		if (!zfs_prop_user(propname)) {
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  2107
			zfs_error_aux(hdl, dgettext(TEXT_DOMAIN,
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  2108
			    "invalid property"));
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  2109
			return (zfs_error(hdl, EZFS_BADPROP, errbuf));
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  2110
		}
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  2111
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  2112
		(void) strlcpy(zc.zc_name, zhp->zfs_name, sizeof (zc.zc_name));
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  2113
		(void) strlcpy(zc.zc_value, propname, sizeof (zc.zc_value));
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  2114
4849
3a61e0a9a953 6536043 arc_byteswap_func_t and dmu_byteswap_func_t are redundant
ahrens
parents: 4801
diff changeset
  2115
		if (zfs_ioctl(zhp->zfs_hdl, ZFS_IOC_INHERIT_PROP, &zc) != 0)
2676
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  2116
			return (zfs_standard_error(hdl, errno, errbuf));
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  2117
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  2118
		return (0);
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  2119
	}
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  2120
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2121
	/*
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2122
	 * Verify that this property is inheritable.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2123
	 */
2082
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1793
diff changeset
  2124
	if (zfs_prop_readonly(prop))
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1793
diff changeset
  2125
		return (zfs_error(hdl, EZFS_PROPREADONLY, errbuf));
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1793
diff changeset
  2126
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1793
diff changeset
  2127
	if (!zfs_prop_inheritable(prop))
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1793
diff changeset
  2128
		return (zfs_error(hdl, EZFS_PROPNONINHERIT, errbuf));
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2129
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2130
	/*
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2131
	 * Check to see if the value applies to this type
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2132
	 */
2082
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1793
diff changeset
  2133
	if (!zfs_prop_valid_for_type(prop, zhp->zfs_type))
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1793
diff changeset
  2134
		return (zfs_error(hdl, EZFS_PROPTYPE, errbuf));
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2135
3443
e0e00ef6cee8 6494654 zfs inherit can't handle property short names
rm160521
parents: 3417
diff changeset
  2136
	/*
e0e00ef6cee8 6494654 zfs inherit can't handle property short names
rm160521
parents: 3417
diff changeset
  2137
	 * Normalize the name, to get rid of shorthand abbrevations.
e0e00ef6cee8 6494654 zfs inherit can't handle property short names
rm160521
parents: 3417
diff changeset
  2138
	 */
e0e00ef6cee8 6494654 zfs inherit can't handle property short names
rm160521
parents: 3417
diff changeset
  2139
	propname = zfs_prop_to_name(prop);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2140
	(void) strlcpy(zc.zc_name, zhp->zfs_name, sizeof (zc.zc_name));
2676
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  2141
	(void) strlcpy(zc.zc_value, propname, sizeof (zc.zc_value));
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2142
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2143
	if (prop == ZFS_PROP_MOUNTPOINT && getzoneid() == GLOBAL_ZONEID &&
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2144
	    zfs_prop_get_int(zhp, ZFS_PROP_ZONED)) {
2082
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1793
diff changeset
  2145
		zfs_error_aux(hdl, dgettext(TEXT_DOMAIN,
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1793
diff changeset
  2146
		    "dataset is used in a non-global zone"));
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1793
diff changeset
  2147
		return (zfs_error(hdl, EZFS_ZONED, errbuf));
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2148
	}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2149
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2150
	/*
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2151
	 * Determine datasets which will be affected by this change, if any.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2152
	 */
7366
33de5956afbb 6678308 zfs receive dumps core when -n is used, fails on replication stream
Tim Haley <Tim.Haley@Sun.COM>
parents: 7301
diff changeset
  2153
	if ((cl = changelist_gather(zhp, prop, 0, 0)) == NULL)
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2154
		return (-1);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2155
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2156
	if (prop == ZFS_PROP_MOUNTPOINT && changelist_haszonedchild(cl)) {
2082
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1793
diff changeset
  2157
		zfs_error_aux(hdl, dgettext(TEXT_DOMAIN,
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1793
diff changeset
  2158
		    "child dataset with inherited mountpoint is used "
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1793
diff changeset
  2159
		    "in a non-global zone"));
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1793
diff changeset
  2160
		ret = zfs_error(hdl, EZFS_ZONED, errbuf);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2161
		goto error;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2162
	}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2163
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2164
	if ((ret = changelist_prefix(cl)) != 0)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2165
		goto error;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2166
4849
3a61e0a9a953 6536043 arc_byteswap_func_t and dmu_byteswap_func_t are redundant
ahrens
parents: 4801
diff changeset
  2167
	if ((ret = zfs_ioctl(zhp->zfs_hdl, ZFS_IOC_INHERIT_PROP, &zc)) != 0) {
2082
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1793
diff changeset
  2168
		return (zfs_standard_error(hdl, errno, errbuf));
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2169
	} else {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2170
2169
0152c8ed1663 6385436 zfs set <property> returns an error, but still sets property value (fix build)
nd150628
parents: 2166
diff changeset
  2171
		if ((ret = changelist_postfix(cl)) != 0)
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2172
			goto error;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2173
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2174
		/*
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2175
		 * Refresh the statistics so the new property is reflected.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2176
		 */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2177
		(void) get_stats(zhp);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2178
	}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2179
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2180
error:
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2181
	changelist_free(cl);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2182
	return (ret);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2183
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2184
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2185
/*
1356
e021b5e4aa0e 6377671 zfs mount -a shouldn't bother checking snapshots
eschrock
parents: 1294
diff changeset
  2186
 * True DSL properties are stored in an nvlist.  The following two functions
e021b5e4aa0e 6377671 zfs mount -a shouldn't bother checking snapshots
eschrock
parents: 1294
diff changeset
  2187
 * extract them appropriately.
e021b5e4aa0e 6377671 zfs mount -a shouldn't bother checking snapshots
eschrock
parents: 1294
diff changeset
  2188
 */
e021b5e4aa0e 6377671 zfs mount -a shouldn't bother checking snapshots
eschrock
parents: 1294
diff changeset
  2189
static uint64_t
e021b5e4aa0e 6377671 zfs mount -a shouldn't bother checking snapshots
eschrock
parents: 1294
diff changeset
  2190
getprop_uint64(zfs_handle_t *zhp, zfs_prop_t prop, char **source)
e021b5e4aa0e 6377671 zfs mount -a shouldn't bother checking snapshots
eschrock
parents: 1294
diff changeset
  2191
{
e021b5e4aa0e 6377671 zfs mount -a shouldn't bother checking snapshots
eschrock
parents: 1294
diff changeset
  2192
	nvlist_t *nv;
e021b5e4aa0e 6377671 zfs mount -a shouldn't bother checking snapshots
eschrock
parents: 1294
diff changeset
  2193
	uint64_t value;
e021b5e4aa0e 6377671 zfs mount -a shouldn't bother checking snapshots
eschrock
parents: 1294
diff changeset
  2194
2885
c0259887ebbc 6460059 zfs destroy <snapshot> leaves behind kruft
ahrens
parents: 2856
diff changeset
  2195
	*source = NULL;
1356
e021b5e4aa0e 6377671 zfs mount -a shouldn't bother checking snapshots
eschrock
parents: 1294
diff changeset
  2196
	if (nvlist_lookup_nvlist(zhp->zfs_props,
e021b5e4aa0e 6377671 zfs mount -a shouldn't bother checking snapshots
eschrock
parents: 1294
diff changeset
  2197
	    zfs_prop_to_name(prop), &nv) == 0) {
5094
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4861
diff changeset
  2198
		verify(nvlist_lookup_uint64(nv, ZPROP_VALUE, &value) == 0);
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4861
diff changeset
  2199
		(void) nvlist_lookup_string(nv, ZPROP_SOURCE, source);
1356
e021b5e4aa0e 6377671 zfs mount -a shouldn't bother checking snapshots
eschrock
parents: 1294
diff changeset
  2200
	} else {
e021b5e4aa0e 6377671 zfs mount -a shouldn't bother checking snapshots
eschrock
parents: 1294
diff changeset
  2201
		value = zfs_prop_default_numeric(prop);
e021b5e4aa0e 6377671 zfs mount -a shouldn't bother checking snapshots
eschrock
parents: 1294
diff changeset
  2202
		*source = "";
e021b5e4aa0e 6377671 zfs mount -a shouldn't bother checking snapshots
eschrock
parents: 1294
diff changeset
  2203
	}
e021b5e4aa0e 6377671 zfs mount -a shouldn't bother checking snapshots
eschrock
parents: 1294
diff changeset
  2204
e021b5e4aa0e 6377671 zfs mount -a shouldn't bother checking snapshots
eschrock
parents: 1294
diff changeset
  2205
	return (value);
e021b5e4aa0e 6377671 zfs mount -a shouldn't bother checking snapshots
eschrock
parents: 1294
diff changeset
  2206
}
e021b5e4aa0e 6377671 zfs mount -a shouldn't bother checking snapshots
eschrock
parents: 1294
diff changeset
  2207
e021b5e4aa0e 6377671 zfs mount -a shouldn't bother checking snapshots
eschrock
parents: 1294
diff changeset
  2208
static char *
e021b5e4aa0e 6377671 zfs mount -a shouldn't bother checking snapshots
eschrock
parents: 1294
diff changeset
  2209
getprop_string(zfs_handle_t *zhp, zfs_prop_t prop, char **source)
e021b5e4aa0e 6377671 zfs mount -a shouldn't bother checking snapshots
eschrock
parents: 1294
diff changeset
  2210
{
e021b5e4aa0e 6377671 zfs mount -a shouldn't bother checking snapshots
eschrock
parents: 1294
diff changeset
  2211
	nvlist_t *nv;
e021b5e4aa0e 6377671 zfs mount -a shouldn't bother checking snapshots
eschrock
parents: 1294
diff changeset
  2212
	char *value;
e021b5e4aa0e 6377671 zfs mount -a shouldn't bother checking snapshots
eschrock
parents: 1294
diff changeset
  2213
2885
c0259887ebbc 6460059 zfs destroy <snapshot> leaves behind kruft
ahrens
parents: 2856
diff changeset
  2214
	*source = NULL;
1356
e021b5e4aa0e 6377671 zfs mount -a shouldn't bother checking snapshots
eschrock
parents: 1294
diff changeset
  2215
	if (nvlist_lookup_nvlist(zhp->zfs_props,
e021b5e4aa0e 6377671 zfs mount -a shouldn't bother checking snapshots
eschrock
parents: 1294
diff changeset
  2216
	    zfs_prop_to_name(prop), &nv) == 0) {
5094
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4861
diff changeset
  2217
		verify(nvlist_lookup_string(nv, ZPROP_VALUE, &value) == 0);
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4861
diff changeset
  2218
		(void) nvlist_lookup_string(nv, ZPROP_SOURCE, source);
1356
e021b5e4aa0e 6377671 zfs mount -a shouldn't bother checking snapshots
eschrock
parents: 1294
diff changeset
  2219
	} else {
e021b5e4aa0e 6377671 zfs mount -a shouldn't bother checking snapshots
eschrock
parents: 1294
diff changeset
  2220
		if ((value = (char *)zfs_prop_default_string(prop)) == NULL)
e021b5e4aa0e 6377671 zfs mount -a shouldn't bother checking snapshots
eschrock
parents: 1294
diff changeset
  2221
			value = "";
e021b5e4aa0e 6377671 zfs mount -a shouldn't bother checking snapshots
eschrock
parents: 1294
diff changeset
  2222
		*source = "";
e021b5e4aa0e 6377671 zfs mount -a shouldn't bother checking snapshots
eschrock
parents: 1294
diff changeset
  2223
	}
e021b5e4aa0e 6377671 zfs mount -a shouldn't bother checking snapshots
eschrock
parents: 1294
diff changeset
  2224
e021b5e4aa0e 6377671 zfs mount -a shouldn't bother checking snapshots
eschrock
parents: 1294
diff changeset
  2225
	return (value);
e021b5e4aa0e 6377671 zfs mount -a shouldn't bother checking snapshots
eschrock
parents: 1294
diff changeset
  2226
}
e021b5e4aa0e 6377671 zfs mount -a shouldn't bother checking snapshots
eschrock
parents: 1294
diff changeset
  2227
e021b5e4aa0e 6377671 zfs mount -a shouldn't bother checking snapshots
eschrock
parents: 1294
diff changeset
  2228
/*
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2229
 * Internal function for getting a numeric property.  Both zfs_prop_get() and
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2230
 * zfs_prop_get_int() are built using this interface.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2231
 *
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2232
 * Certain properties can be overridden using 'mount -o'.  In this case, scan
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2233
 * the contents of the /etc/mnttab entry, searching for the appropriate options.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2234
 * If they differ from the on-disk values, report the current values and mark
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2235
 * the source "temporary".
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2236
 */
2082
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1793
diff changeset
  2237
static int
5094
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4861
diff changeset
  2238
get_numeric_property(zfs_handle_t *zhp, zfs_prop_t prop, zprop_source_t *src,
2082
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1793
diff changeset
  2239
    char **source, uint64_t *val)
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2240
{
5147
5e950ccc9585 6596190 "zfs list" is slow due to version property
rm160521
parents: 5094
diff changeset
  2241
	zfs_cmd_t zc = { 0 };
5592
1b20f93ffca0 6637425 memory leak in get_numeric_property()
timh
parents: 5498
diff changeset
  2242
	nvlist_t *zplprops = NULL;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2243
	struct mnttab mnt;
3265
967e0fca6143 6463140 zfs recv with a snapshot name that has 2 @@ in a row succeeds
ahrens
parents: 3237
diff changeset
  2244
	char *mntopt_on = NULL;
967e0fca6143 6463140 zfs recv with a snapshot name that has 2 @@ in a row succeeds
ahrens
parents: 3237
diff changeset
  2245
	char *mntopt_off = NULL;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2246
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2247
	*source = NULL;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2248
3265
967e0fca6143 6463140 zfs recv with a snapshot name that has 2 @@ in a row succeeds
ahrens
parents: 3237
diff changeset
  2249
	switch (prop) {
967e0fca6143 6463140 zfs recv with a snapshot name that has 2 @@ in a row succeeds
ahrens
parents: 3237
diff changeset
  2250
	case ZFS_PROP_ATIME:
967e0fca6143 6463140 zfs recv with a snapshot name that has 2 @@ in a row succeeds
ahrens
parents: 3237
diff changeset
  2251
		mntopt_on = MNTOPT_ATIME;
967e0fca6143 6463140 zfs recv with a snapshot name that has 2 @@ in a row succeeds
ahrens
parents: 3237
diff changeset
  2252
		mntopt_off = MNTOPT_NOATIME;
967e0fca6143 6463140 zfs recv with a snapshot name that has 2 @@ in a row succeeds
ahrens
parents: 3237
diff changeset
  2253
		break;
967e0fca6143 6463140 zfs recv with a snapshot name that has 2 @@ in a row succeeds
ahrens
parents: 3237
diff changeset
  2254
967e0fca6143 6463140 zfs recv with a snapshot name that has 2 @@ in a row succeeds
ahrens
parents: 3237
diff changeset
  2255
	case ZFS_PROP_DEVICES:
967e0fca6143 6463140 zfs recv with a snapshot name that has 2 @@ in a row succeeds
ahrens
parents: 3237
diff changeset
  2256
		mntopt_on = MNTOPT_DEVICES;
967e0fca6143 6463140 zfs recv with a snapshot name that has 2 @@ in a row succeeds
ahrens
parents: 3237
diff changeset
  2257
		mntopt_off = MNTOPT_NODEVICES;
967e0fca6143 6463140 zfs recv with a snapshot name that has 2 @@ in a row succeeds
ahrens
parents: 3237
diff changeset
  2258
		break;
967e0fca6143 6463140 zfs recv with a snapshot name that has 2 @@ in a row succeeds
ahrens
parents: 3237
diff changeset
  2259
967e0fca6143 6463140 zfs recv with a snapshot name that has 2 @@ in a row succeeds
ahrens
parents: 3237
diff changeset
  2260
	case ZFS_PROP_EXEC:
967e0fca6143 6463140 zfs recv with a snapshot name that has 2 @@ in a row succeeds
ahrens
parents: 3237
diff changeset
  2261
		mntopt_on = MNTOPT_EXEC;
967e0fca6143 6463140 zfs recv with a snapshot name that has 2 @@ in a row succeeds
ahrens
parents: 3237
diff changeset
  2262
		mntopt_off = MNTOPT_NOEXEC;
967e0fca6143 6463140 zfs recv with a snapshot name that has 2 @@ in a row succeeds
ahrens
parents: 3237
diff changeset
  2263
		break;
967e0fca6143 6463140 zfs recv with a snapshot name that has 2 @@ in a row succeeds
ahrens
parents: 3237
diff changeset
  2264
967e0fca6143 6463140 zfs recv with a snapshot name that has 2 @@ in a row succeeds
ahrens
parents: 3237
diff changeset
  2265
	case ZFS_PROP_READONLY:
967e0fca6143 6463140 zfs recv with a snapshot name that has 2 @@ in a row succeeds
ahrens
parents: 3237
diff changeset
  2266
		mntopt_on = MNTOPT_RO;
967e0fca6143 6463140 zfs recv with a snapshot name that has 2 @@ in a row succeeds
ahrens
parents: 3237
diff changeset
  2267
		mntopt_off = MNTOPT_RW;
967e0fca6143 6463140 zfs recv with a snapshot name that has 2 @@ in a row succeeds
ahrens
parents: 3237
diff changeset
  2268
		break;
967e0fca6143 6463140 zfs recv with a snapshot name that has 2 @@ in a row succeeds
ahrens
parents: 3237
diff changeset
  2269
967e0fca6143 6463140 zfs recv with a snapshot name that has 2 @@ in a row succeeds
ahrens
parents: 3237
diff changeset
  2270
	case ZFS_PROP_SETUID:
967e0fca6143 6463140 zfs recv with a snapshot name that has 2 @@ in a row succeeds
ahrens
parents: 3237
diff changeset
  2271
		mntopt_on = MNTOPT_SETUID;
967e0fca6143 6463140 zfs recv with a snapshot name that has 2 @@ in a row succeeds
ahrens
parents: 3237
diff changeset
  2272
		mntopt_off = MNTOPT_NOSETUID;
967e0fca6143 6463140 zfs recv with a snapshot name that has 2 @@ in a row succeeds
ahrens
parents: 3237
diff changeset
  2273
		break;
967e0fca6143 6463140 zfs recv with a snapshot name that has 2 @@ in a row succeeds
ahrens
parents: 3237
diff changeset
  2274
967e0fca6143 6463140 zfs recv with a snapshot name that has 2 @@ in a row succeeds
ahrens
parents: 3237
diff changeset
  2275
	case ZFS_PROP_XATTR:
967e0fca6143 6463140 zfs recv with a snapshot name that has 2 @@ in a row succeeds
ahrens
parents: 3237
diff changeset
  2276
		mntopt_on = MNTOPT_XATTR;
967e0fca6143 6463140 zfs recv with a snapshot name that has 2 @@ in a row succeeds
ahrens
parents: 3237
diff changeset
  2277
		mntopt_off = MNTOPT_NOXATTR;
967e0fca6143 6463140 zfs recv with a snapshot name that has 2 @@ in a row succeeds
ahrens
parents: 3237
diff changeset
  2278
		break;
5331
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5326
diff changeset
  2279
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5326
diff changeset
  2280
	case ZFS_PROP_NBMAND:
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5326
diff changeset
  2281
		mntopt_on = MNTOPT_NBMAND;
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5326
diff changeset
  2282
		mntopt_off = MNTOPT_NONBMAND;
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5326
diff changeset
  2283
		break;
3265
967e0fca6143 6463140 zfs recv with a snapshot name that has 2 @@ in a row succeeds
ahrens
parents: 3237
diff changeset
  2284
	}
967e0fca6143 6463140 zfs recv with a snapshot name that has 2 @@ in a row succeeds
ahrens
parents: 3237
diff changeset
  2285
2474
c001ad7e0c25 6368751 libzfs interface for mount/umounting all the file systems for a given pool
eschrock
parents: 2440
diff changeset
  2286
	/*
c001ad7e0c25 6368751 libzfs interface for mount/umounting all the file systems for a given pool
eschrock
parents: 2440
diff changeset
  2287
	 * Because looking up the mount options is potentially expensive
c001ad7e0c25 6368751 libzfs interface for mount/umounting all the file systems for a given pool
eschrock
parents: 2440
diff changeset
  2288
	 * (iterating over all of /etc/mnttab), we defer its calculation until
c001ad7e0c25 6368751 libzfs interface for mount/umounting all the file systems for a given pool
eschrock
parents: 2440
diff changeset
  2289
	 * we're looking up a property which requires its presence.
c001ad7e0c25 6368751 libzfs interface for mount/umounting all the file systems for a given pool
eschrock
parents: 2440
diff changeset
  2290
	 */
c001ad7e0c25 6368751 libzfs interface for mount/umounting all the file systems for a given pool
eschrock
parents: 2440
diff changeset
  2291
	if (!zhp->zfs_mntcheck &&
3265
967e0fca6143 6463140 zfs recv with a snapshot name that has 2 @@ in a row succeeds
ahrens
parents: 3237
diff changeset
  2292
	    (mntopt_on != NULL || prop == ZFS_PROP_MOUNTED)) {
8228
51e9ca9ee3a5 6572357 libzfs should do more to avoid mnttab lookups
Eric Taylor <Eric.Taylor@Sun.COM>
parents: 7509
diff changeset
  2293
		libzfs_handle_t *hdl = zhp->zfs_hdl;
51e9ca9ee3a5 6572357 libzfs should do more to avoid mnttab lookups
Eric Taylor <Eric.Taylor@Sun.COM>
parents: 7509
diff changeset
  2294
		struct mnttab entry;
51e9ca9ee3a5 6572357 libzfs should do more to avoid mnttab lookups
Eric Taylor <Eric.Taylor@Sun.COM>
parents: 7509
diff changeset
  2295
51e9ca9ee3a5 6572357 libzfs should do more to avoid mnttab lookups
Eric Taylor <Eric.Taylor@Sun.COM>
parents: 7509
diff changeset
  2296
		if (libzfs_mnttab_find(hdl, zhp->zfs_name, &entry) == 0) {
51e9ca9ee3a5 6572357 libzfs should do more to avoid mnttab lookups
Eric Taylor <Eric.Taylor@Sun.COM>
parents: 7509
diff changeset
  2297
			zhp->zfs_mntopts = zfs_strdup(hdl,
3265
967e0fca6143 6463140 zfs recv with a snapshot name that has 2 @@ in a row succeeds
ahrens
parents: 3237
diff changeset
  2298
			    entry.mnt_mntopts);
967e0fca6143 6463140 zfs recv with a snapshot name that has 2 @@ in a row succeeds
ahrens
parents: 3237
diff changeset
  2299
			if (zhp->zfs_mntopts == NULL)
967e0fca6143 6463140 zfs recv with a snapshot name that has 2 @@ in a row succeeds
ahrens
parents: 3237
diff changeset
  2300
				return (-1);
967e0fca6143 6463140 zfs recv with a snapshot name that has 2 @@ in a row succeeds
ahrens
parents: 3237
diff changeset
  2301
		}
2474
c001ad7e0c25 6368751 libzfs interface for mount/umounting all the file systems for a given pool
eschrock
parents: 2440
diff changeset
  2302
c001ad7e0c25 6368751 libzfs interface for mount/umounting all the file systems for a given pool
eschrock
parents: 2440
diff changeset
  2303
		zhp->zfs_mntcheck = B_TRUE;
c001ad7e0c25 6368751 libzfs interface for mount/umounting all the file systems for a given pool
eschrock
parents: 2440
diff changeset
  2304
	}
c001ad7e0c25 6368751 libzfs interface for mount/umounting all the file systems for a given pool
eschrock
parents: 2440
diff changeset
  2305
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2306
	if (zhp->zfs_mntopts == NULL)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2307
		mnt.mnt_mntopts = "";
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2308
	else
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2309
		mnt.mnt_mntopts = zhp->zfs_mntopts;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2310
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2311
	switch (prop) {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2312
	case ZFS_PROP_ATIME:
3265
967e0fca6143 6463140 zfs recv with a snapshot name that has 2 @@ in a row succeeds
ahrens
parents: 3237
diff changeset
  2313
	case ZFS_PROP_DEVICES:
967e0fca6143 6463140 zfs recv with a snapshot name that has 2 @@ in a row succeeds
ahrens
parents: 3237
diff changeset
  2314
	case ZFS_PROP_EXEC:
967e0fca6143 6463140 zfs recv with a snapshot name that has 2 @@ in a row succeeds
ahrens
parents: 3237
diff changeset
  2315
	case ZFS_PROP_READONLY:
967e0fca6143 6463140 zfs recv with a snapshot name that has 2 @@ in a row succeeds
ahrens
parents: 3237
diff changeset
  2316
	case ZFS_PROP_SETUID:
967e0fca6143 6463140 zfs recv with a snapshot name that has 2 @@ in a row succeeds
ahrens
parents: 3237
diff changeset
  2317
	case ZFS_PROP_XATTR:
5331
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5326
diff changeset
  2318
	case ZFS_PROP_NBMAND:
2082
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1793
diff changeset
  2319
		*val = getprop_uint64(zhp, prop, source);
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1793
diff changeset
  2320
3265
967e0fca6143 6463140 zfs recv with a snapshot name that has 2 @@ in a row succeeds
ahrens
parents: 3237
diff changeset
  2321
		if (hasmntopt(&mnt, mntopt_on) && !*val) {
2082
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1793
diff changeset
  2322
			*val = B_TRUE;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2323
			if (src)
5094
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4861
diff changeset
  2324
				*src = ZPROP_SRC_TEMPORARY;
3265
967e0fca6143 6463140 zfs recv with a snapshot name that has 2 @@ in a row succeeds
ahrens
parents: 3237
diff changeset
  2325
		} else if (hasmntopt(&mnt, mntopt_off) && *val) {
2082
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1793
diff changeset
  2326
			*val = B_FALSE;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2327
			if (src)
5094
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4861
diff changeset
  2328
				*src = ZPROP_SRC_TEMPORARY;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2329
		}
2082
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1793
diff changeset
  2330
		break;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2331
3265
967e0fca6143 6463140 zfs recv with a snapshot name that has 2 @@ in a row succeeds
ahrens
parents: 3237
diff changeset
  2332
	case ZFS_PROP_CANMOUNT:
2082
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1793
diff changeset
  2333
		*val = getprop_uint64(zhp, prop, source);
6168
51c045dcc498 PSARC 2008/168 Support for ZFS property value canmount=noauto
hs24103
parents: 5993
diff changeset
  2334
		if (*val != ZFS_CANMOUNT_ON)
3417
0630f537a7e5 6480849 source of canmount property needs improvement
rm160521
parents: 3413
diff changeset
  2335
			*source = zhp->zfs_name;
0630f537a7e5 6480849 source of canmount property needs improvement
rm160521
parents: 3413
diff changeset
  2336
		else
0630f537a7e5 6480849 source of canmount property needs improvement
rm160521
parents: 3413
diff changeset
  2337
			*source = "";	/* default */
2082
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1793
diff changeset
  2338
		break;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2339
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2340
	case ZFS_PROP_QUOTA:
5378
111aa1baa84a PSARC 2007/555 zfs fs-only quotas and reservations
ck153898
parents: 5375
diff changeset
  2341
	case ZFS_PROP_REFQUOTA:
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2342
	case ZFS_PROP_RESERVATION:
5378
111aa1baa84a PSARC 2007/555 zfs fs-only quotas and reservations
ck153898
parents: 5375
diff changeset
  2343
	case ZFS_PROP_REFRESERVATION:
2885
c0259887ebbc 6460059 zfs destroy <snapshot> leaves behind kruft
ahrens
parents: 2856
diff changeset
  2344
		*val = getprop_uint64(zhp, prop, source);
c0259887ebbc 6460059 zfs destroy <snapshot> leaves behind kruft
ahrens
parents: 2856
diff changeset
  2345
		if (*val == 0)
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2346
			*source = "";	/* default */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2347
		else
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2348
			*source = zhp->zfs_name;
2082
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1793
diff changeset
  2349
		break;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2350
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2351
	case ZFS_PROP_MOUNTED:
2082
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1793
diff changeset
  2352
		*val = (zhp->zfs_mntopts != NULL);
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1793
diff changeset
  2353
		break;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2354
3377
a2fa338530c1 6393525 vdev_reopen() should verify that it's still the same device
eschrock
parents: 3363
diff changeset
  2355
	case ZFS_PROP_NUMCLONES:
a2fa338530c1 6393525 vdev_reopen() should verify that it's still the same device
eschrock
parents: 3363
diff changeset
  2356
		*val = zhp->zfs_dmustats.dds_num_clones;
a2fa338530c1 6393525 vdev_reopen() should verify that it's still the same device
eschrock
parents: 3363
diff changeset
  2357
		break;
a2fa338530c1 6393525 vdev_reopen() should verify that it's still the same device
eschrock
parents: 3363
diff changeset
  2358
5147
5e950ccc9585 6596190 "zfs list" is slow due to version property
rm160521
parents: 5094
diff changeset
  2359
	case ZFS_PROP_VERSION:
5498
334b476844ca 6622831 normalization properties are not preserved by "zfs send"
timh
parents: 5481
diff changeset
  2360
	case ZFS_PROP_NORMALIZE:
334b476844ca 6622831 normalization properties are not preserved by "zfs send"
timh
parents: 5481
diff changeset
  2361
	case ZFS_PROP_UTF8ONLY:
334b476844ca 6622831 normalization properties are not preserved by "zfs send"
timh
parents: 5481
diff changeset
  2362
	case ZFS_PROP_CASE:
334b476844ca 6622831 normalization properties are not preserved by "zfs send"
timh
parents: 5481
diff changeset
  2363
		if (!zfs_prop_valid_for_type(prop, zhp->zfs_head_type) ||
334b476844ca 6622831 normalization properties are not preserved by "zfs send"
timh
parents: 5481
diff changeset
  2364
		    zcmd_alloc_dst_nvlist(zhp->zfs_hdl, &zc, 0) != 0)
5473
fcdd1931b3aa 6590941 zfs set mountpoint should not return 0 when it fails
rm160521
parents: 5446
diff changeset
  2365
			return (-1);
5147
5e950ccc9585 6596190 "zfs list" is slow due to version property
rm160521
parents: 5094
diff changeset
  2366
		(void) strlcpy(zc.zc_name, zhp->zfs_name, sizeof (zc.zc_name));
5498
334b476844ca 6622831 normalization properties are not preserved by "zfs send"
timh
parents: 5481
diff changeset
  2367
		if (zfs_ioctl(zhp->zfs_hdl, ZFS_IOC_OBJSET_ZPLPROPS, &zc)) {
334b476844ca 6622831 normalization properties are not preserved by "zfs send"
timh
parents: 5481
diff changeset
  2368
			zcmd_free_nvlists(&zc);
5147
5e950ccc9585 6596190 "zfs list" is slow due to version property
rm160521
parents: 5094
diff changeset
  2369
			zfs_error_aux(zhp->zfs_hdl, dgettext(TEXT_DOMAIN,
5498
334b476844ca 6622831 normalization properties are not preserved by "zfs send"
timh
parents: 5481
diff changeset
  2370
			    "unable to get %s property"),
334b476844ca 6622831 normalization properties are not preserved by "zfs send"
timh
parents: 5481
diff changeset
  2371
			    zfs_prop_to_name(prop));
5147
5e950ccc9585 6596190 "zfs list" is slow due to version property
rm160521
parents: 5094
diff changeset
  2372
			return (zfs_error(zhp->zfs_hdl, EZFS_BADVERSION,
5e950ccc9585 6596190 "zfs list" is slow due to version property
rm160521
parents: 5094
diff changeset
  2373
			    dgettext(TEXT_DOMAIN, "internal error")));
5e950ccc9585 6596190 "zfs list" is slow due to version property
rm160521
parents: 5094
diff changeset
  2374
		}
5498
334b476844ca 6622831 normalization properties are not preserved by "zfs send"
timh
parents: 5481
diff changeset
  2375
		if (zcmd_read_dst_nvlist(zhp->zfs_hdl, &zc, &zplprops) != 0 ||
334b476844ca 6622831 normalization properties are not preserved by "zfs send"
timh
parents: 5481
diff changeset
  2376
		    nvlist_lookup_uint64(zplprops, zfs_prop_to_name(prop),
334b476844ca 6622831 normalization properties are not preserved by "zfs send"
timh
parents: 5481
diff changeset
  2377
		    val) != 0) {
334b476844ca 6622831 normalization properties are not preserved by "zfs send"
timh
parents: 5481
diff changeset
  2378
			zcmd_free_nvlists(&zc);
334b476844ca 6622831 normalization properties are not preserved by "zfs send"
timh
parents: 5481
diff changeset
  2379
			zfs_error_aux(zhp->zfs_hdl, dgettext(TEXT_DOMAIN,
334b476844ca 6622831 normalization properties are not preserved by "zfs send"
timh
parents: 5481
diff changeset
  2380
			    "unable to get %s property"),
334b476844ca 6622831 normalization properties are not preserved by "zfs send"
timh
parents: 5481
diff changeset
  2381
			    zfs_prop_to_name(prop));
334b476844ca 6622831 normalization properties are not preserved by "zfs send"
timh
parents: 5481
diff changeset
  2382
			return (zfs_error(zhp->zfs_hdl, EZFS_NOMEM,
334b476844ca 6622831 normalization properties are not preserved by "zfs send"
timh
parents: 5481
diff changeset
  2383
			    dgettext(TEXT_DOMAIN, "internal error")));
334b476844ca 6622831 normalization properties are not preserved by "zfs send"
timh
parents: 5481
diff changeset
  2384
		}
5592
1b20f93ffca0 6637425 memory leak in get_numeric_property()
timh
parents: 5498
diff changeset
  2385
		if (zplprops)
1b20f93ffca0 6637425 memory leak in get_numeric_property()
timh
parents: 5498
diff changeset
  2386
			nvlist_free(zplprops);
5498
334b476844ca 6622831 normalization properties are not preserved by "zfs send"
timh
parents: 5481
diff changeset
  2387
		zcmd_free_nvlists(&zc);
5147
5e950ccc9585 6596190 "zfs list" is slow due to version property
rm160521
parents: 5094
diff changeset
  2388
		break;
5e950ccc9585 6596190 "zfs list" is slow due to version property
rm160521
parents: 5094
diff changeset
  2389
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2390
	default:
4577
ed36b0e652bc PSARC/2007/328 zfs upgrade
ahrens
parents: 4543
diff changeset
  2391
		switch (zfs_prop_get_type(prop)) {
4787
602d3f97842c 6393351 unique_* could be improved
ahrens
parents: 4778
diff changeset
  2392
		case PROP_TYPE_NUMBER:
602d3f97842c 6393351 unique_* could be improved
ahrens
parents: 4778
diff changeset
  2393
		case PROP_TYPE_INDEX:
4577
ed36b0e652bc PSARC/2007/328 zfs upgrade
ahrens
parents: 4543
diff changeset
  2394
			*val = getprop_uint64(zhp, prop, source);
7390
6d408f0a5fbd PSARC/2008/518 ZFS space accounting enhancements
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 7366
diff changeset
  2395
			/*
6d408f0a5fbd PSARC/2008/518 ZFS space accounting enhancements
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 7366
diff changeset
  2396
			 * If we tried to use a defalut value for a
6d408f0a5fbd PSARC/2008/518 ZFS space accounting enhancements
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 7366
diff changeset
  2397
			 * readonly property, it means that it was not
6d408f0a5fbd PSARC/2008/518 ZFS space accounting enhancements
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 7366
diff changeset
  2398
			 * present; return an error.
6d408f0a5fbd PSARC/2008/518 ZFS space accounting enhancements
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 7366
diff changeset
  2399
			 */
6d408f0a5fbd PSARC/2008/518 ZFS space accounting enhancements
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 7366
diff changeset
  2400
			if (zfs_prop_readonly(prop) &&
6d408f0a5fbd PSARC/2008/518 ZFS space accounting enhancements
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 7366
diff changeset
  2401
			    *source && (*source)[0] == '\0') {
6d408f0a5fbd PSARC/2008/518 ZFS space accounting enhancements
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 7366
diff changeset
  2402
				return (-1);
6d408f0a5fbd PSARC/2008/518 ZFS space accounting enhancements
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 7366
diff changeset
  2403
			}
4577
ed36b0e652bc PSARC/2007/328 zfs upgrade
ahrens
parents: 4543
diff changeset
  2404
			break;
ed36b0e652bc PSARC/2007/328 zfs upgrade
ahrens
parents: 4543
diff changeset
  2405
4787
602d3f97842c 6393351 unique_* could be improved
ahrens
parents: 4778
diff changeset
  2406
		case PROP_TYPE_STRING:
4577
ed36b0e652bc PSARC/2007/328 zfs upgrade
ahrens
parents: 4543
diff changeset
  2407
		default:
ed36b0e652bc PSARC/2007/328 zfs upgrade
ahrens
parents: 4543
diff changeset
  2408
			zfs_error_aux(zhp->zfs_hdl, dgettext(TEXT_DOMAIN,
ed36b0e652bc PSARC/2007/328 zfs upgrade
ahrens
parents: 4543
diff changeset
  2409
			    "cannot get non-numeric property"));
ed36b0e652bc PSARC/2007/328 zfs upgrade
ahrens
parents: 4543
diff changeset
  2410
			return (zfs_error(zhp->zfs_hdl, EZFS_BADPROP,
ed36b0e652bc PSARC/2007/328 zfs upgrade
ahrens
parents: 4543
diff changeset
  2411
			    dgettext(TEXT_DOMAIN, "internal error")));
ed36b0e652bc PSARC/2007/328 zfs upgrade
ahrens
parents: 4543
diff changeset
  2412
		}
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2413
	}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2414
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2415
	return (0);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2416
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2417
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2418
/*
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2419
 * Calculate the source type, given the raw source string.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2420
 */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2421
static void
5094
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4861
diff changeset
  2422
get_source(zfs_handle_t *zhp, zprop_source_t *srctype, char *source,
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2423
    char *statbuf, size_t statlen)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2424
{
5094
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4861
diff changeset
  2425
	if (statbuf == NULL || *srctype == ZPROP_SRC_TEMPORARY)
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2426
		return;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2427
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2428
	if (source == NULL) {
5094
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4861
diff changeset
  2429
		*srctype = ZPROP_SRC_NONE;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2430
	} else if (source[0] == '\0') {
5094
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4861
diff changeset
  2431
		*srctype = ZPROP_SRC_DEFAULT;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2432
	} else {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2433
		if (strcmp(source, zhp->zfs_name) == 0) {
5094
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4861
diff changeset
  2434
			*srctype = ZPROP_SRC_LOCAL;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2435
		} else {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2436
			(void) strlcpy(statbuf, source, statlen);
5094
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4861
diff changeset
  2437
			*srctype = ZPROP_SRC_INHERITED;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2438
		}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2439
	}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2440
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2441
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2442
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2443
/*
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2444
 * Retrieve a property from the given object.  If 'literal' is specified, then
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2445
 * numbers are left as exact values.  Otherwise, numbers are converted to a
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2446
 * human-readable form.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2447
 *
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2448
 * Returns 0 on success, or -1 on error.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2449
 */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2450
int
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2451
zfs_prop_get(zfs_handle_t *zhp, zfs_prop_t prop, char *propbuf, size_t proplen,
5094
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4861
diff changeset
  2452
    zprop_source_t *src, char *statbuf, size_t statlen, boolean_t literal)
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2453
{
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2454
	char *source = NULL;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2455
	uint64_t val;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2456
	char *str;
2676
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  2457
	const char *strval;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2458
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2459
	/*
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2460
	 * Check to see if this property applies to our object
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2461
	 */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2462
	if (!zfs_prop_valid_for_type(prop, zhp->zfs_type))
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2463
		return (-1);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2464
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2465
	if (src)
5094
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4861
diff changeset
  2466
		*src = ZPROP_SRC_NONE;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2467
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2468
	switch (prop) {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2469
	case ZFS_PROP_CREATION:
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2470
		/*
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2471
		 * 'creation' is a time_t stored in the statistics.  We convert
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2472
		 * this into a string unless 'literal' is specified.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2473
		 */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2474
		{
2885
c0259887ebbc 6460059 zfs destroy <snapshot> leaves behind kruft
ahrens
parents: 2856
diff changeset
  2475
			val = getprop_uint64(zhp, prop, &source);
c0259887ebbc 6460059 zfs destroy <snapshot> leaves behind kruft
ahrens
parents: 2856
diff changeset
  2476
			time_t time = (time_t)val;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2477
			struct tm t;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2478
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2479
			if (literal ||
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2480
			    localtime_r(&time, &t) == NULL ||
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2481
			    strftime(propbuf, proplen, "%a %b %e %k:%M %Y",
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2482
			    &t) == 0)
2885
c0259887ebbc 6460059 zfs destroy <snapshot> leaves behind kruft
ahrens
parents: 2856
diff changeset
  2483
				(void) snprintf(propbuf, proplen, "%llu", val);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2484
		}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2485
		break;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2486
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2487
	case ZFS_PROP_MOUNTPOINT:
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2488
		/*
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2489
		 * Getting the precise mountpoint can be tricky.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2490
		 *
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2491
		 *  - for 'none' or 'legacy', return those values.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2492
		 *  - for inherited mountpoints, we want to take everything
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2493
		 *    after our ancestor and append it to the inherited value.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2494
		 *
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2495
		 * If the pool has an alternate root, we want to prepend that
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2496
		 * root to any values we return.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2497
		 */
6865
176d18c623cc 6539380 zfs list uses too much memory
rm160521
parents: 6612
diff changeset
  2498
1356
e021b5e4aa0e 6377671 zfs mount -a shouldn't bother checking snapshots
eschrock
parents: 1294
diff changeset
  2499
		str = getprop_string(zhp, prop, &source);
e021b5e4aa0e 6377671 zfs mount -a shouldn't bother checking snapshots
eschrock
parents: 1294
diff changeset
  2500
6612
bed68cb8aa8c 6668667 mountpoint is displayed incorrectly by zfs list when the mountpoint is "/"
gw25295
parents: 6423
diff changeset
  2501
		if (str[0] == '/') {
6865
176d18c623cc 6539380 zfs list uses too much memory
rm160521
parents: 6612
diff changeset
  2502
			char buf[MAXPATHLEN];
176d18c623cc 6539380 zfs list uses too much memory
rm160521
parents: 6612
diff changeset
  2503
			char *root = buf;
1356
e021b5e4aa0e 6377671 zfs mount -a shouldn't bother checking snapshots
eschrock
parents: 1294
diff changeset
  2504
			const char *relpath = zhp->zfs_name + strlen(source);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2505
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2506
			if (relpath[0] == '/')
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2507
				relpath++;
6612
bed68cb8aa8c 6668667 mountpoint is displayed incorrectly by zfs list when the mountpoint is "/"
gw25295
parents: 6423
diff changeset
  2508
6865
176d18c623cc 6539380 zfs list uses too much memory
rm160521
parents: 6612
diff changeset
  2509
			if ((zpool_get_prop(zhp->zpool_hdl,
176d18c623cc 6539380 zfs list uses too much memory
rm160521
parents: 6612
diff changeset
  2510
			    ZPOOL_PROP_ALTROOT, buf, MAXPATHLEN, NULL)) ||
176d18c623cc 6539380 zfs list uses too much memory
rm160521
parents: 6612
diff changeset
  2511
			    (strcmp(root, "-") == 0))
176d18c623cc 6539380 zfs list uses too much memory
rm160521
parents: 6612
diff changeset
  2512
				root[0] = '\0';
6612
bed68cb8aa8c 6668667 mountpoint is displayed incorrectly by zfs list when the mountpoint is "/"
gw25295
parents: 6423
diff changeset
  2513
			/*
bed68cb8aa8c 6668667 mountpoint is displayed incorrectly by zfs list when the mountpoint is "/"
gw25295
parents: 6423
diff changeset
  2514
			 * Special case an alternate root of '/'. This will
bed68cb8aa8c 6668667 mountpoint is displayed incorrectly by zfs list when the mountpoint is "/"
gw25295
parents: 6423
diff changeset
  2515
			 * avoid having multiple leading slashes in the
bed68cb8aa8c 6668667 mountpoint is displayed incorrectly by zfs list when the mountpoint is "/"
gw25295
parents: 6423
diff changeset
  2516
			 * mountpoint path.
bed68cb8aa8c 6668667 mountpoint is displayed incorrectly by zfs list when the mountpoint is "/"
gw25295
parents: 6423
diff changeset
  2517
			 */
bed68cb8aa8c 6668667 mountpoint is displayed incorrectly by zfs list when the mountpoint is "/"
gw25295
parents: 6423
diff changeset
  2518
			if (strcmp(root, "/") == 0)
bed68cb8aa8c 6668667 mountpoint is displayed incorrectly by zfs list when the mountpoint is "/"
gw25295
parents: 6423
diff changeset
  2519
				root++;
bed68cb8aa8c 6668667 mountpoint is displayed incorrectly by zfs list when the mountpoint is "/"
gw25295
parents: 6423
diff changeset
  2520
bed68cb8aa8c 6668667 mountpoint is displayed incorrectly by zfs list when the mountpoint is "/"
gw25295
parents: 6423
diff changeset
  2521
			/*
bed68cb8aa8c 6668667 mountpoint is displayed incorrectly by zfs list when the mountpoint is "/"
gw25295
parents: 6423
diff changeset
  2522
			 * If the mountpoint is '/' then skip over this
bed68cb8aa8c 6668667 mountpoint is displayed incorrectly by zfs list when the mountpoint is "/"
gw25295
parents: 6423
diff changeset
  2523
			 * if we are obtaining either an alternate root or
bed68cb8aa8c 6668667 mountpoint is displayed incorrectly by zfs list when the mountpoint is "/"
gw25295
parents: 6423
diff changeset
  2524
			 * an inherited mountpoint.
bed68cb8aa8c 6668667 mountpoint is displayed incorrectly by zfs list when the mountpoint is "/"
gw25295
parents: 6423
diff changeset
  2525
			 */
bed68cb8aa8c 6668667 mountpoint is displayed incorrectly by zfs list when the mountpoint is "/"
gw25295
parents: 6423
diff changeset
  2526
			if (str[1] == '\0' && (root[0] != '\0' ||
bed68cb8aa8c 6668667 mountpoint is displayed incorrectly by zfs list when the mountpoint is "/"
gw25295
parents: 6423
diff changeset
  2527
			    relpath[0] != '\0'))
1356
e021b5e4aa0e 6377671 zfs mount -a shouldn't bother checking snapshots
eschrock
parents: 1294
diff changeset
  2528
				str++;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2529
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2530
			if (relpath[0] == '\0')
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2531
				(void) snprintf(propbuf, proplen, "%s%s",
1356
e021b5e4aa0e 6377671 zfs mount -a shouldn't bother checking snapshots
eschrock
parents: 1294
diff changeset
  2532
				    root, str);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2533
			else
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2534
				(void) snprintf(propbuf, proplen, "%s%s%s%s",
1356
e021b5e4aa0e 6377671 zfs mount -a shouldn't bother checking snapshots
eschrock
parents: 1294
diff changeset
  2535
				    root, str, relpath[0] == '@' ? "" : "/",
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2536
				    relpath);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2537
		} else {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2538
			/* 'legacy' or 'none' */
1356
e021b5e4aa0e 6377671 zfs mount -a shouldn't bother checking snapshots
eschrock
parents: 1294
diff changeset
  2539
			(void) strlcpy(propbuf, str, proplen);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2540
		}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2541
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2542
		break;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2543
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2544
	case ZFS_PROP_ORIGIN:
2885
c0259887ebbc 6460059 zfs destroy <snapshot> leaves behind kruft
ahrens
parents: 2856
diff changeset
  2545
		(void) strlcpy(propbuf, getprop_string(zhp, prop, &source),
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2546
		    proplen);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2547
		/*
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2548
		 * If there is no parent at all, return failure to indicate that
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2549
		 * it doesn't apply to this dataset.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2550
		 */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2551
		if (propbuf[0] == '\0')
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2552
			return (-1);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2553
		break;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2554
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2555
	case ZFS_PROP_QUOTA:
5378
111aa1baa84a PSARC 2007/555 zfs fs-only quotas and reservations
ck153898
parents: 5375
diff changeset
  2556
	case ZFS_PROP_REFQUOTA:
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2557
	case ZFS_PROP_RESERVATION:
5378
111aa1baa84a PSARC 2007/555 zfs fs-only quotas and reservations
ck153898
parents: 5375
diff changeset
  2558
	case ZFS_PROP_REFRESERVATION:
111aa1baa84a PSARC 2007/555 zfs fs-only quotas and reservations
ck153898
parents: 5375
diff changeset
  2559
2082
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1793
diff changeset
  2560
		if (get_numeric_property(zhp, prop, src, &source, &val) != 0)
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1793
diff changeset
  2561
			return (-1);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2562
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2563
		/*
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2564
		 * If quota or reservation is 0, we translate this into 'none'
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2565
		 * (unless literal is set), and indicate that it's the default
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2566
		 * value.  Otherwise, we print the number nicely and indicate
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2567
		 * that its set locally.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2568
		 */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2569
		if (val == 0) {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2570
			if (literal)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2571
				(void) strlcpy(propbuf, "0", proplen);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2572
			else
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2573
				(void) strlcpy(propbuf, "none", proplen);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2574
		} else {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2575
			if (literal)
2856
6f4d5ee1906a 6463348 ZFS code could be more portable
nd150628
parents: 2744
diff changeset
  2576
				(void) snprintf(propbuf, proplen, "%llu",
3912
f6891a60bd72 PSARC 2007/083 ZFS bootable datasets
lling
parents: 3886
diff changeset
  2577
				    (u_longlong_t)val);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2578
			else
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2579
				zfs_nicenum(val, propbuf, proplen);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2580
		}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2581
		break;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2582
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2583
	case ZFS_PROP_COMPRESSRATIO:
2082
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1793
diff changeset
  2584
		if (get_numeric_property(zhp, prop, src, &source, &val) != 0)
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1793
diff changeset
  2585
			return (-1);
2856
6f4d5ee1906a 6463348 ZFS code could be more portable
nd150628
parents: 2744
diff changeset
  2586
		(void) snprintf(propbuf, proplen, "%lld.%02lldx", (longlong_t)
6f4d5ee1906a 6463348 ZFS code could be more portable
nd150628
parents: 2744
diff changeset
  2587
		    val / 100, (longlong_t)val % 100);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2588
		break;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2589
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2590
	case ZFS_PROP_TYPE:
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2591
		switch (zhp->zfs_type) {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2592
		case ZFS_TYPE_FILESYSTEM:
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2593
			str = "filesystem";
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2594
			break;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2595
		case ZFS_TYPE_VOLUME:
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2596
			str = "volume";
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2597
			break;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2598
		case ZFS_TYPE_SNAPSHOT:
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2599
			str = "snapshot";
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2600
			break;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2601
		default:
2082
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1793
diff changeset
  2602
			abort();
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2603
		}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2604
		(void) snprintf(propbuf, proplen, "%s", str);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2605
		break;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2606
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2607
	case ZFS_PROP_MOUNTED:
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2608
		/*
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2609
		 * The 'mounted' property is a pseudo-property that described
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2610
		 * whether the filesystem is currently mounted.  Even though
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2611
		 * it's a boolean value, the typical values of "on" and "off"
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2612
		 * don't make sense, so we translate to "yes" and "no".
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2613
		 */
2082
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1793
diff changeset
  2614
		if (get_numeric_property(zhp, ZFS_PROP_MOUNTED,
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1793
diff changeset
  2615
		    src, &source, &val) != 0)
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1793
diff changeset
  2616
			return (-1);
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1793
diff changeset
  2617
		if (val)
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2618
			(void) strlcpy(propbuf, "yes", proplen);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2619
		else
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2620
			(void) strlcpy(propbuf, "no", proplen);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2621
		break;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2622
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2623
	case ZFS_PROP_NAME:
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2624
		/*
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2625
		 * The 'name' property is a pseudo-property derived from the
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2626
		 * dataset name.  It is presented as a real property to simplify
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2627
		 * consumers.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2628
		 */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2629
		(void) strlcpy(propbuf, zhp->zfs_name, proplen);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2630
		break;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2631
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2632
	default:
4577
ed36b0e652bc PSARC/2007/328 zfs upgrade
ahrens
parents: 4543
diff changeset
  2633
		switch (zfs_prop_get_type(prop)) {
4787
602d3f97842c 6393351 unique_* could be improved
ahrens
parents: 4778
diff changeset
  2634
		case PROP_TYPE_NUMBER:
4577
ed36b0e652bc PSARC/2007/328 zfs upgrade
ahrens
parents: 4543
diff changeset
  2635
			if (get_numeric_property(zhp, prop, src,
ed36b0e652bc PSARC/2007/328 zfs upgrade
ahrens
parents: 4543
diff changeset
  2636
			    &source, &val) != 0)
ed36b0e652bc PSARC/2007/328 zfs upgrade
ahrens
parents: 4543
diff changeset
  2637
				return (-1);
ed36b0e652bc PSARC/2007/328 zfs upgrade
ahrens
parents: 4543
diff changeset
  2638
			if (literal)
ed36b0e652bc PSARC/2007/328 zfs upgrade
ahrens
parents: 4543
diff changeset
  2639
				(void) snprintf(propbuf, proplen, "%llu",
ed36b0e652bc PSARC/2007/328 zfs upgrade
ahrens
parents: 4543
diff changeset
  2640
				    (u_longlong_t)val);
ed36b0e652bc PSARC/2007/328 zfs upgrade
ahrens
parents: 4543
diff changeset
  2641
			else
ed36b0e652bc PSARC/2007/328 zfs upgrade
ahrens
parents: 4543
diff changeset
  2642
				zfs_nicenum(val, propbuf, proplen);
ed36b0e652bc PSARC/2007/328 zfs upgrade
ahrens
parents: 4543
diff changeset
  2643
			break;
ed36b0e652bc PSARC/2007/328 zfs upgrade
ahrens
parents: 4543
diff changeset
  2644
4787
602d3f97842c 6393351 unique_* could be improved
ahrens
parents: 4778
diff changeset
  2645
		case PROP_TYPE_STRING:
4577
ed36b0e652bc PSARC/2007/328 zfs upgrade
ahrens
parents: 4543
diff changeset
  2646
			(void) strlcpy(propbuf,
ed36b0e652bc PSARC/2007/328 zfs upgrade
ahrens
parents: 4543
diff changeset
  2647
			    getprop_string(zhp, prop, &source), proplen);
ed36b0e652bc PSARC/2007/328 zfs upgrade
ahrens
parents: 4543
diff changeset
  2648
			break;
ed36b0e652bc PSARC/2007/328 zfs upgrade
ahrens
parents: 4543
diff changeset
  2649
4787
602d3f97842c 6393351 unique_* could be improved
ahrens
parents: 4778
diff changeset
  2650
		case PROP_TYPE_INDEX:
4861
fa5be10d6612 6592018 "zfs get" does not display temporary property
ahrens
parents: 4849
diff changeset
  2651
			if (get_numeric_property(zhp, prop, src,
fa5be10d6612 6592018 "zfs get" does not display temporary property
ahrens
parents: 4849
diff changeset
  2652
			    &source, &val) != 0)
fa5be10d6612 6592018 "zfs get" does not display temporary property
ahrens
parents: 4849
diff changeset
  2653
				return (-1);
fa5be10d6612 6592018 "zfs get" does not display temporary property
ahrens
parents: 4849
diff changeset
  2654
			if (zfs_prop_index_to_string(prop, val, &strval) != 0)
4577
ed36b0e652bc PSARC/2007/328 zfs upgrade
ahrens
parents: 4543
diff changeset
  2655
				return (-1);
ed36b0e652bc PSARC/2007/328 zfs upgrade
ahrens
parents: 4543
diff changeset
  2656
			(void) strlcpy(propbuf, strval, proplen);
ed36b0e652bc PSARC/2007/328 zfs upgrade
ahrens
parents: 4543
diff changeset
  2657
			break;
ed36b0e652bc PSARC/2007/328 zfs upgrade
ahrens
parents: 4543
diff changeset
  2658
ed36b0e652bc PSARC/2007/328 zfs upgrade
ahrens
parents: 4543
diff changeset
  2659
		default:
ed36b0e652bc PSARC/2007/328 zfs upgrade
ahrens
parents: 4543
diff changeset
  2660
			abort();
ed36b0e652bc PSARC/2007/328 zfs upgrade
ahrens
parents: 4543
diff changeset
  2661
		}
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2662
	}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2663
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2664
	get_source(zhp, src, source, statbuf, statlen);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2665
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2666
	return (0);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2667
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2668
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2669
/*
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2670
 * Utility function to get the given numeric property.  Does no validation that
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2671
 * the given property is the appropriate type; should only be used with
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2672
 * hard-coded property types.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2673
 */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2674
uint64_t
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2675
zfs_prop_get_int(zfs_handle_t *zhp, zfs_prop_t prop)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2676
{
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2677
	char *source;
2082
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1793
diff changeset
  2678
	uint64_t val;
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1793
diff changeset
  2679
5367
c40abbe796be PSARC/2007/574 zfs send -R
ahrens
parents: 5331
diff changeset
  2680
	(void) get_numeric_property(zhp, prop, NULL, &source, &val);
2082
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1793
diff changeset
  2681
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1793
diff changeset
  2682
	return (val);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2683
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2684
5713
f9b7933f3770 PSARC/2007/675 A_MDEV Removal
rm160521
parents: 5592
diff changeset
  2685
int
f9b7933f3770 PSARC/2007/675 A_MDEV Removal
rm160521
parents: 5592
diff changeset
  2686
zfs_prop_set_int(zfs_handle_t *zhp, zfs_prop_t prop, uint64_t val)
f9b7933f3770 PSARC/2007/675 A_MDEV Removal
rm160521
parents: 5592
diff changeset
  2687
{
f9b7933f3770 PSARC/2007/675 A_MDEV Removal
rm160521
parents: 5592
diff changeset
  2688
	char buf[64];
f9b7933f3770 PSARC/2007/675 A_MDEV Removal
rm160521
parents: 5592
diff changeset
  2689
f9b7933f3770 PSARC/2007/675 A_MDEV Removal
rm160521
parents: 5592
diff changeset
  2690
	zfs_nicenum(val, buf, sizeof (buf));
f9b7933f3770 PSARC/2007/675 A_MDEV Removal
rm160521
parents: 5592
diff changeset
  2691
	return (zfs_prop_set(zhp, zfs_prop_to_name(prop), buf));
f9b7933f3770 PSARC/2007/675 A_MDEV Removal
rm160521
parents: 5592
diff changeset
  2692
}
f9b7933f3770 PSARC/2007/675 A_MDEV Removal
rm160521
parents: 5592
diff changeset
  2693
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2694
/*
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2695
 * Similar to zfs_prop_get(), but returns the value as an integer.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2696
 */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2697
int
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2698
zfs_prop_get_numeric(zfs_handle_t *zhp, zfs_prop_t prop, uint64_t *value,
5094
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4861
diff changeset
  2699
    zprop_source_t *src, char *statbuf, size_t statlen)
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2700
{
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2701
	char *source;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2702
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2703
	/*
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2704
	 * Check to see if this property applies to our object
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2705
	 */
4849
3a61e0a9a953 6536043 arc_byteswap_func_t and dmu_byteswap_func_t are redundant
ahrens
parents: 4801
diff changeset
  2706
	if (!zfs_prop_valid_for_type(prop, zhp->zfs_type)) {
3237
98d0c28f2f5e 6480245 renaming a dataset to something with '%s' will cause segfault
lling
parents: 3234
diff changeset
  2707
		return (zfs_error_fmt(zhp->zfs_hdl, EZFS_PROPTYPE,
2082
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1793
diff changeset
  2708
		    dgettext(TEXT_DOMAIN, "cannot get property '%s'"),
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1793
diff changeset
  2709
		    zfs_prop_to_name(prop)));
4849
3a61e0a9a953 6536043 arc_byteswap_func_t and dmu_byteswap_func_t are redundant
ahrens
parents: 4801
diff changeset
  2710
	}
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2711
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2712
	if (src)
5094
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4861
diff changeset
  2713
		*src = ZPROP_SRC_NONE;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2714
2082
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1793
diff changeset
  2715
	if (get_numeric_property(zhp, prop, src, &source, value) != 0)
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1793
diff changeset
  2716
		return (-1);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2717
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2718
	get_source(zhp, src, source, statbuf, statlen);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2719
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2720
	return (0);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2721
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2722
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2723
/*
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2724
 * Returns the name of the given zfs handle.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2725
 */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2726
const char *
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2727
zfs_get_name(const zfs_handle_t *zhp)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2728
{
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2729
	return (zhp->zfs_name);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2730
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2731
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2732
/*
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2733
 * Returns the type of the given zfs handle.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2734
 */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2735
zfs_type_t
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2736
zfs_get_type(const zfs_handle_t *zhp)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2737
{
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2738
	return (zhp->zfs_type);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2739
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2740
8228
51e9ca9ee3a5 6572357 libzfs should do more to avoid mnttab lookups
Eric Taylor <Eric.Taylor@Sun.COM>
parents: 7509
diff changeset
  2741
static int
51e9ca9ee3a5 6572357 libzfs should do more to avoid mnttab lookups
Eric Taylor <Eric.Taylor@Sun.COM>
parents: 7509
diff changeset
  2742
zfs_do_list_ioctl(zfs_handle_t *zhp, int arg, zfs_cmd_t *zc)
51e9ca9ee3a5 6572357 libzfs should do more to avoid mnttab lookups
Eric Taylor <Eric.Taylor@Sun.COM>
parents: 7509
diff changeset
  2743
{
51e9ca9ee3a5 6572357 libzfs should do more to avoid mnttab lookups
Eric Taylor <Eric.Taylor@Sun.COM>
parents: 7509
diff changeset
  2744
	int rc;
51e9ca9ee3a5 6572357 libzfs should do more to avoid mnttab lookups
Eric Taylor <Eric.Taylor@Sun.COM>
parents: 7509
diff changeset
  2745
	uint64_t	orig_cookie;
51e9ca9ee3a5 6572357 libzfs should do more to avoid mnttab lookups
Eric Taylor <Eric.Taylor@Sun.COM>
parents: 7509
diff changeset
  2746
51e9ca9ee3a5 6572357 libzfs should do more to avoid mnttab lookups
Eric Taylor <Eric.Taylor@Sun.COM>
parents: 7509
diff changeset
  2747
	orig_cookie = zc->zc_cookie;
51e9ca9ee3a5 6572357 libzfs should do more to avoid mnttab lookups
Eric Taylor <Eric.Taylor@Sun.COM>
parents: 7509
diff changeset
  2748
top:
51e9ca9ee3a5 6572357 libzfs should do more to avoid mnttab lookups
Eric Taylor <Eric.Taylor@Sun.COM>
parents: 7509
diff changeset
  2749
	(void) strlcpy(zc->zc_name, zhp->zfs_name, sizeof (zc->zc_name));
51e9ca9ee3a5 6572357 libzfs should do more to avoid mnttab lookups
Eric Taylor <Eric.Taylor@Sun.COM>
parents: 7509
diff changeset
  2750
	rc = ioctl(zhp->zfs_hdl->libzfs_fd, arg, zc);
51e9ca9ee3a5 6572357 libzfs should do more to avoid mnttab lookups
Eric Taylor <Eric.Taylor@Sun.COM>
parents: 7509
diff changeset
  2751
51e9ca9ee3a5 6572357 libzfs should do more to avoid mnttab lookups
Eric Taylor <Eric.Taylor@Sun.COM>
parents: 7509
diff changeset
  2752
	if (rc == -1) {
51e9ca9ee3a5 6572357 libzfs should do more to avoid mnttab lookups
Eric Taylor <Eric.Taylor@Sun.COM>
parents: 7509
diff changeset
  2753
		switch (errno) {
51e9ca9ee3a5 6572357 libzfs should do more to avoid mnttab lookups
Eric Taylor <Eric.Taylor@Sun.COM>
parents: 7509
diff changeset
  2754
		case ENOMEM:
51e9ca9ee3a5 6572357 libzfs should do more to avoid mnttab lookups
Eric Taylor <Eric.Taylor@Sun.COM>
parents: 7509
diff changeset
  2755
			/* expand nvlist memory and try again */
51e9ca9ee3a5 6572357 libzfs should do more to avoid mnttab lookups
Eric Taylor <Eric.Taylor@Sun.COM>
parents: 7509
diff changeset
  2756
			if (zcmd_expand_dst_nvlist(zhp->zfs_hdl, zc) != 0) {
51e9ca9ee3a5 6572357 libzfs should do more to avoid mnttab lookups
Eric Taylor <Eric.Taylor@Sun.COM>
parents: 7509
diff changeset
  2757
				zcmd_free_nvlists(zc);
51e9ca9ee3a5 6572357 libzfs should do more to avoid mnttab lookups
Eric Taylor <Eric.Taylor@Sun.COM>
parents: 7509
diff changeset
  2758
				return (-1);
51e9ca9ee3a5 6572357 libzfs should do more to avoid mnttab lookups
Eric Taylor <Eric.Taylor@Sun.COM>
parents: 7509
diff changeset
  2759
			}
51e9ca9ee3a5 6572357 libzfs should do more to avoid mnttab lookups
Eric Taylor <Eric.Taylor@Sun.COM>
parents: 7509
diff changeset
  2760
			zc->zc_cookie = orig_cookie;
51e9ca9ee3a5 6572357 libzfs should do more to avoid mnttab lookups
Eric Taylor <Eric.Taylor@Sun.COM>
parents: 7509
diff changeset
  2761
			goto top;
51e9ca9ee3a5 6572357 libzfs should do more to avoid mnttab lookups
Eric Taylor <Eric.Taylor@Sun.COM>
parents: 7509
diff changeset
  2762
		/*
51e9ca9ee3a5 6572357 libzfs should do more to avoid mnttab lookups
Eric Taylor <Eric.Taylor@Sun.COM>
parents: 7509
diff changeset
  2763
		 * An errno value of ESRCH indicates normal completion.
51e9ca9ee3a5 6572357 libzfs should do more to avoid mnttab lookups
Eric Taylor <Eric.Taylor@Sun.COM>
parents: 7509
diff changeset
  2764
		 * If ENOENT is returned, then the underlying dataset
51e9ca9ee3a5 6572357 libzfs should do more to avoid mnttab lookups
Eric Taylor <Eric.Taylor@Sun.COM>
parents: 7509
diff changeset
  2765
		 * has been removed since we obtained the handle.
51e9ca9ee3a5 6572357 libzfs should do more to avoid mnttab lookups
Eric Taylor <Eric.Taylor@Sun.COM>
parents: 7509
diff changeset
  2766
		 */
51e9ca9ee3a5 6572357 libzfs should do more to avoid mnttab lookups
Eric Taylor <Eric.Taylor@Sun.COM>
parents: 7509
diff changeset
  2767
		case ESRCH:
51e9ca9ee3a5 6572357 libzfs should do more to avoid mnttab lookups
Eric Taylor <Eric.Taylor@Sun.COM>
parents: 7509
diff changeset
  2768
		case ENOENT:
51e9ca9ee3a5 6572357 libzfs should do more to avoid mnttab lookups
Eric Taylor <Eric.Taylor@Sun.COM>
parents: 7509
diff changeset
  2769
			rc = 1;
51e9ca9ee3a5 6572357 libzfs should do more to avoid mnttab lookups
Eric Taylor <Eric.Taylor@Sun.COM>
parents: 7509
diff changeset
  2770
			break;
51e9ca9ee3a5 6572357 libzfs should do more to avoid mnttab lookups
Eric Taylor <Eric.Taylor@Sun.COM>
parents: 7509
diff changeset
  2771
		default:
51e9ca9ee3a5 6572357 libzfs should do more to avoid mnttab lookups
Eric Taylor <Eric.Taylor@Sun.COM>
parents: 7509
diff changeset
  2772
			rc = zfs_standard_error(zhp->zfs_hdl, errno,
51e9ca9ee3a5 6572357 libzfs should do more to avoid mnttab lookups
Eric Taylor <Eric.Taylor@Sun.COM>
parents: 7509
diff changeset
  2773
			    dgettext(TEXT_DOMAIN,
51e9ca9ee3a5 6572357 libzfs should do more to avoid mnttab lookups
Eric Taylor <Eric.Taylor@Sun.COM>
parents: 7509
diff changeset
  2774
			    "cannot iterate filesystems"));
51e9ca9ee3a5 6572357 libzfs should do more to avoid mnttab lookups
Eric Taylor <Eric.Taylor@Sun.COM>
parents: 7509
diff changeset
  2775
			break;
51e9ca9ee3a5 6572357 libzfs should do more to avoid mnttab lookups
Eric Taylor <Eric.Taylor@Sun.COM>
parents: 7509
diff changeset
  2776
		}
51e9ca9ee3a5 6572357 libzfs should do more to avoid mnttab lookups
Eric Taylor <Eric.Taylor@Sun.COM>
parents: 7509
diff changeset
  2777
	}
51e9ca9ee3a5 6572357 libzfs should do more to avoid mnttab lookups
Eric Taylor <Eric.Taylor@Sun.COM>
parents: 7509
diff changeset
  2778
	return (rc);
51e9ca9ee3a5 6572357 libzfs should do more to avoid mnttab lookups
Eric Taylor <Eric.Taylor@Sun.COM>
parents: 7509
diff changeset
  2779
}
51e9ca9ee3a5 6572357 libzfs should do more to avoid mnttab lookups
Eric Taylor <Eric.Taylor@Sun.COM>
parents: 7509
diff changeset
  2780
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2781
/*
1356
e021b5e4aa0e 6377671 zfs mount -a shouldn't bother checking snapshots
eschrock
parents: 1294
diff changeset
  2782
 * Iterate over all child filesystems
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2783
 */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2784
int
1356
e021b5e4aa0e 6377671 zfs mount -a shouldn't bother checking snapshots
eschrock
parents: 1294
diff changeset
  2785
zfs_iter_filesystems(zfs_handle_t *zhp, zfs_iter_f func, void *data)
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2786
{
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2787
	zfs_cmd_t zc = { 0 };
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2788
	zfs_handle_t *nzhp;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2789
	int ret;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2790
5367
c40abbe796be PSARC/2007/574 zfs send -R
ahrens
parents: 5331
diff changeset
  2791
	if (zhp->zfs_type != ZFS_TYPE_FILESYSTEM)
c40abbe796be PSARC/2007/574 zfs send -R
ahrens
parents: 5331
diff changeset
  2792
		return (0);
c40abbe796be PSARC/2007/574 zfs send -R
ahrens
parents: 5331
diff changeset
  2793
8228
51e9ca9ee3a5 6572357 libzfs should do more to avoid mnttab lookups
Eric Taylor <Eric.Taylor@Sun.COM>
parents: 7509
diff changeset
  2794
	if (zcmd_alloc_dst_nvlist(zhp->zfs_hdl, &zc, 0) != 0)
51e9ca9ee3a5 6572357 libzfs should do more to avoid mnttab lookups
Eric Taylor <Eric.Taylor@Sun.COM>
parents: 7509
diff changeset
  2795
		return (-1);
51e9ca9ee3a5 6572357 libzfs should do more to avoid mnttab lookups
Eric Taylor <Eric.Taylor@Sun.COM>
parents: 7509
diff changeset
  2796
51e9ca9ee3a5 6572357 libzfs should do more to avoid mnttab lookups
Eric Taylor <Eric.Taylor@Sun.COM>
parents: 7509
diff changeset
  2797
	while ((ret = zfs_do_list_ioctl(zhp, ZFS_IOC_DATASET_LIST_NEXT,
51e9ca9ee3a5 6572357 libzfs should do more to avoid mnttab lookups
Eric Taylor <Eric.Taylor@Sun.COM>
parents: 7509
diff changeset
  2798
	    &zc)) == 0) {
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2799
		/*
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2800
		 * Ignore private dataset names.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2801
		 */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2802
		if (dataset_name_hidden(zc.zc_name))
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2803
			continue;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2804
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2805
		/*
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2806
		 * Silently ignore errors, as the only plausible explanation is
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2807
		 * that the pool has since been removed.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2808
		 */
8228
51e9ca9ee3a5 6572357 libzfs should do more to avoid mnttab lookups
Eric Taylor <Eric.Taylor@Sun.COM>
parents: 7509
diff changeset
  2809
		if ((nzhp = make_dataset_handle_zc(zhp->zfs_hdl,
51e9ca9ee3a5 6572357 libzfs should do more to avoid mnttab lookups
Eric Taylor <Eric.Taylor@Sun.COM>
parents: 7509
diff changeset
  2810
		    &zc)) == NULL) {
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2811
			continue;
8228
51e9ca9ee3a5 6572357 libzfs should do more to avoid mnttab lookups
Eric Taylor <Eric.Taylor@Sun.COM>
parents: 7509
diff changeset
  2812
		}
51e9ca9ee3a5 6572357 libzfs should do more to avoid mnttab lookups
Eric Taylor <Eric.Taylor@Sun.COM>
parents: 7509
diff changeset
  2813
51e9ca9ee3a5 6572357 libzfs should do more to avoid mnttab lookups
Eric Taylor <Eric.Taylor@Sun.COM>
parents: 7509
diff changeset
  2814
		if ((ret = func(nzhp, data)) != 0) {
51e9ca9ee3a5 6572357 libzfs should do more to avoid mnttab lookups
Eric Taylor <Eric.Taylor@Sun.COM>
parents: 7509
diff changeset
  2815
			zcmd_free_nvlists(&zc);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2816
			return (ret);
8228
51e9ca9ee3a5 6572357 libzfs should do more to avoid mnttab lookups
Eric Taylor <Eric.Taylor@Sun.COM>
parents: 7509
diff changeset
  2817
		}
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2818
	}
8228
51e9ca9ee3a5 6572357 libzfs should do more to avoid mnttab lookups
Eric Taylor <Eric.Taylor@Sun.COM>
parents: 7509
diff changeset
  2819
	zcmd_free_nvlists(&zc);
51e9ca9ee3a5 6572357 libzfs should do more to avoid mnttab lookups
Eric Taylor <Eric.Taylor@Sun.COM>
parents: 7509
diff changeset
  2820
	return ((ret < 0) ? ret : 0);
1356
e021b5e4aa0e 6377671 zfs mount -a shouldn't bother checking snapshots
eschrock
parents: 1294
diff changeset
  2821
}
e021b5e4aa0e 6377671 zfs mount -a shouldn't bother checking snapshots
eschrock
parents: 1294
diff changeset
  2822
e021b5e4aa0e 6377671 zfs mount -a shouldn't bother checking snapshots
eschrock
parents: 1294
diff changeset
  2823
/*
e021b5e4aa0e 6377671 zfs mount -a shouldn't bother checking snapshots
eschrock
parents: 1294
diff changeset
  2824
 * Iterate over all snapshots
e021b5e4aa0e 6377671 zfs mount -a shouldn't bother checking snapshots
eschrock
parents: 1294
diff changeset
  2825
 */
e021b5e4aa0e 6377671 zfs mount -a shouldn't bother checking snapshots
eschrock
parents: 1294
diff changeset
  2826
int
e021b5e4aa0e 6377671 zfs mount -a shouldn't bother checking snapshots
eschrock
parents: 1294
diff changeset
  2827
zfs_iter_snapshots(zfs_handle_t *zhp, zfs_iter_f func, void *data)
e021b5e4aa0e 6377671 zfs mount -a shouldn't bother checking snapshots
eschrock
parents: 1294
diff changeset
  2828
{
e021b5e4aa0e 6377671 zfs mount -a shouldn't bother checking snapshots
eschrock
parents: 1294
diff changeset
  2829
	zfs_cmd_t zc = { 0 };
e021b5e4aa0e 6377671 zfs mount -a shouldn't bother checking snapshots
eschrock
parents: 1294
diff changeset
  2830
	zfs_handle_t *nzhp;
e021b5e4aa0e 6377671 zfs mount -a shouldn't bother checking snapshots
eschrock
parents: 1294
diff changeset
  2831
	int ret;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2832
5367
c40abbe796be PSARC/2007/574 zfs send -R
ahrens
parents: 5331
diff changeset
  2833
	if (zhp->zfs_type == ZFS_TYPE_SNAPSHOT)
c40abbe796be PSARC/2007/574 zfs send -R
ahrens
parents: 5331
diff changeset
  2834
		return (0);
c40abbe796be PSARC/2007/574 zfs send -R
ahrens
parents: 5331
diff changeset
  2835
8228
51e9ca9ee3a5 6572357 libzfs should do more to avoid mnttab lookups
Eric Taylor <Eric.Taylor@Sun.COM>
parents: 7509
diff changeset
  2836
	if (zcmd_alloc_dst_nvlist(zhp->zfs_hdl, &zc, 0) != 0)
51e9ca9ee3a5 6572357 libzfs should do more to avoid mnttab lookups
Eric Taylor <Eric.Taylor@Sun.COM>
parents: 7509
diff changeset
  2837
		return (-1);
51e9ca9ee3a5 6572357 libzfs should do more to avoid mnttab lookups
Eric Taylor <Eric.Taylor@Sun.COM>
parents: 7509
diff changeset
  2838
	while ((ret = zfs_do_list_ioctl(zhp, ZFS_IOC_SNAPSHOT_LIST_NEXT,
51e9ca9ee3a5 6572357 libzfs should do more to avoid mnttab lookups
Eric Taylor <Eric.Taylor@Sun.COM>
parents: 7509
diff changeset
  2839
	    &zc)) == 0) {
51e9ca9ee3a5 6572357 libzfs should do more to avoid mnttab lookups
Eric Taylor <Eric.Taylor@Sun.COM>
parents: 7509
diff changeset
  2840
51e9ca9ee3a5 6572357 libzfs should do more to avoid mnttab lookups
Eric Taylor <Eric.Taylor@Sun.COM>
parents: 7509
diff changeset
  2841
		if ((nzhp = make_dataset_handle_zc(zhp->zfs_hdl,
51e9ca9ee3a5 6572357 libzfs should do more to avoid mnttab lookups
Eric Taylor <Eric.Taylor@Sun.COM>
parents: 7509
diff changeset
  2842
		    &zc)) == NULL) {
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2843
			continue;
8228
51e9ca9ee3a5 6572357 libzfs should do more to avoid mnttab lookups
Eric Taylor <Eric.Taylor@Sun.COM>
parents: 7509
diff changeset
  2844
		}
51e9ca9ee3a5 6572357 libzfs should do more to avoid mnttab lookups
Eric Taylor <Eric.Taylor@Sun.COM>
parents: 7509
diff changeset
  2845
51e9ca9ee3a5 6572357 libzfs should do more to avoid mnttab lookups
Eric Taylor <Eric.Taylor@Sun.COM>
parents: 7509
diff changeset
  2846
		if ((ret = func(nzhp, data)) != 0) {
51e9ca9ee3a5 6572357 libzfs should do more to avoid mnttab lookups
Eric Taylor <Eric.Taylor@Sun.COM>
parents: 7509
diff changeset
  2847
			zcmd_free_nvlists(&zc);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2848
			return (ret);
8228
51e9ca9ee3a5 6572357 libzfs should do more to avoid mnttab lookups
Eric Taylor <Eric.Taylor@Sun.COM>
parents: 7509
diff changeset
  2849
		}
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2850
	}
8228
51e9ca9ee3a5 6572357 libzfs should do more to avoid mnttab lookups
Eric Taylor <Eric.Taylor@Sun.COM>
parents: 7509
diff changeset
  2851
	zcmd_free_nvlists(&zc);
51e9ca9ee3a5 6572357 libzfs should do more to avoid mnttab lookups
Eric Taylor <Eric.Taylor@Sun.COM>
parents: 7509
diff changeset
  2852
	return ((ret < 0) ? ret : 0);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2853
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2854
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2855
/*
1356
e021b5e4aa0e 6377671 zfs mount -a shouldn't bother checking snapshots
eschrock
parents: 1294
diff changeset
  2856
 * Iterate over all children, snapshots and filesystems
e021b5e4aa0e 6377671 zfs mount -a shouldn't bother checking snapshots
eschrock
parents: 1294
diff changeset
  2857
 */
e021b5e4aa0e 6377671 zfs mount -a shouldn't bother checking snapshots
eschrock
parents: 1294
diff changeset
  2858
int
e021b5e4aa0e 6377671 zfs mount -a shouldn't bother checking snapshots
eschrock
parents: 1294
diff changeset
  2859
zfs_iter_children(zfs_handle_t *zhp, zfs_iter_f func, void *data)
e021b5e4aa0e 6377671 zfs mount -a shouldn't bother checking snapshots
eschrock
parents: 1294
diff changeset
  2860
{
e021b5e4aa0e 6377671 zfs mount -a shouldn't bother checking snapshots
eschrock
parents: 1294
diff changeset
  2861
	int ret;
e021b5e4aa0e 6377671 zfs mount -a shouldn't bother checking snapshots
eschrock
parents: 1294
diff changeset
  2862
e021b5e4aa0e 6377671 zfs mount -a shouldn't bother checking snapshots
eschrock
parents: 1294
diff changeset
  2863
	if ((ret = zfs_iter_filesystems(zhp, func, data)) != 0)
e021b5e4aa0e 6377671 zfs mount -a shouldn't bother checking snapshots
eschrock
parents: 1294
diff changeset
  2864
		return (ret);
e021b5e4aa0e 6377671 zfs mount -a shouldn't bother checking snapshots
eschrock
parents: 1294
diff changeset
  2865
e021b5e4aa0e 6377671 zfs mount -a shouldn't bother checking snapshots
eschrock
parents: 1294
diff changeset
  2866
	return (zfs_iter_snapshots(zhp, func, data));
e021b5e4aa0e 6377671 zfs mount -a shouldn't bother checking snapshots
eschrock
parents: 1294
diff changeset
  2867
}
e021b5e4aa0e 6377671 zfs mount -a shouldn't bother checking snapshots
eschrock
parents: 1294
diff changeset
  2868
e021b5e4aa0e 6377671 zfs mount -a shouldn't bother checking snapshots
eschrock
parents: 1294
diff changeset
  2869
/*
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2870
 * Given a complete name, return just the portion that refers to the parent.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2871
 * Can return NULL if this is a pool.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2872
 */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2873
static int
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2874
parent_name(const char *path, char *buf, size_t buflen)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2875
{
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2876
	char *loc;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2877
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2878
	if ((loc = strrchr(path, '/')) == NULL)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2879
		return (-1);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2880
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2881
	(void) strncpy(buf, path, MIN(buflen, loc - path));
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2882
	buf[loc - path] = '\0';
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2883
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2884
	return (0);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2885
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2886
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2887
/*
4490
abf035049f7f PSARC 2007/199 zfs {create,clone,rename} -p
vb160487
parents: 4451
diff changeset
  2888
 * If accept_ancestor is false, then check to make sure that the given path has
abf035049f7f PSARC 2007/199 zfs {create,clone,rename} -p
vb160487
parents: 4451
diff changeset
  2889
 * a parent, and that it exists.  If accept_ancestor is true, then find the
abf035049f7f PSARC 2007/199 zfs {create,clone,rename} -p
vb160487
parents: 4451
diff changeset
  2890
 * closest existing ancestor for the given path.  In prefixlen return the
abf035049f7f PSARC 2007/199 zfs {create,clone,rename} -p
vb160487
parents: 4451
diff changeset
  2891
 * length of already existing prefix of the given path.  We also fetch the
abf035049f7f PSARC 2007/199 zfs {create,clone,rename} -p
vb160487
parents: 4451
diff changeset
  2892
 * 'zoned' property, which is used to validate property settings when creating
abf035049f7f PSARC 2007/199 zfs {create,clone,rename} -p
vb160487
parents: 4451
diff changeset
  2893
 * new datasets.
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2894
 */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2895
static int
4490
abf035049f7f PSARC 2007/199 zfs {create,clone,rename} -p
vb160487
parents: 4451
diff changeset
  2896
check_parents(libzfs_handle_t *hdl, const char *path, uint64_t *zoned,
abf035049f7f PSARC 2007/199 zfs {create,clone,rename} -p
vb160487
parents: 4451
diff changeset
  2897
    boolean_t accept_ancestor, int *prefixlen)
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2898
{
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2899
	zfs_cmd_t zc = { 0 };
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2900
	char parent[ZFS_MAXNAMELEN];
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2901
	char *slash;
1356
e021b5e4aa0e 6377671 zfs mount -a shouldn't bother checking snapshots
eschrock
parents: 1294
diff changeset
  2902
	zfs_handle_t *zhp;
2082
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1793
diff changeset
  2903
	char errbuf[1024];
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1793
diff changeset
  2904
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1793
diff changeset
  2905
	(void) snprintf(errbuf, sizeof (errbuf), "cannot create '%s'",
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1793
diff changeset
  2906
	    path);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2907
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2908
	/* get parent, and check to see if this is just a pool */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2909
	if (parent_name(path, parent, sizeof (parent)) != 0) {
2082
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1793
diff changeset
  2910
		zfs_error_aux(hdl, dgettext(TEXT_DOMAIN,
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1793
diff changeset
  2911
		    "missing dataset name"));
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1793
diff changeset
  2912
		return (zfs_error(hdl, EZFS_INVALIDNAME, errbuf));
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2913
	}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2914
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2915
	/* check to see if the pool exists */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2916
	if ((slash = strchr(parent, '/')) == NULL)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2917
		slash = parent + strlen(parent);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2918
	(void) strncpy(zc.zc_name, parent, slash - parent);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2919
	zc.zc_name[slash - parent] = '\0';
2082
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1793
diff changeset
  2920
	if (ioctl(hdl->libzfs_fd, ZFS_IOC_OBJSET_STATS, &zc) != 0 &&
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2921
	    errno == ENOENT) {
2082
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1793
diff changeset
  2922
		zfs_error_aux(hdl, dgettext(TEXT_DOMAIN,
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1793
diff changeset
  2923
		    "no such pool '%s'"), zc.zc_name);
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1793
diff changeset
  2924
		return (zfs_error(hdl, EZFS_NOENT, errbuf));
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2925
	}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2926
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2927
	/* check to see if the parent dataset exists */
4490
abf035049f7f PSARC 2007/199 zfs {create,clone,rename} -p
vb160487
parents: 4451
diff changeset
  2928
	while ((zhp = make_dataset_handle(hdl, parent)) == NULL) {
abf035049f7f PSARC 2007/199 zfs {create,clone,rename} -p
vb160487
parents: 4451
diff changeset
  2929
		if (errno == ENOENT && accept_ancestor) {
abf035049f7f PSARC 2007/199 zfs {create,clone,rename} -p
vb160487
parents: 4451
diff changeset
  2930
			/*
abf035049f7f PSARC 2007/199 zfs {create,clone,rename} -p
vb160487
parents: 4451
diff changeset
  2931
			 * Go deeper to find an ancestor, give up on top level.
abf035049f7f PSARC 2007/199 zfs {create,clone,rename} -p
vb160487
parents: 4451
diff changeset
  2932
			 */
abf035049f7f PSARC 2007/199 zfs {create,clone,rename} -p
vb160487
parents: 4451
diff changeset
  2933
			if (parent_name(parent, parent, sizeof (parent)) != 0) {
abf035049f7f PSARC 2007/199 zfs {create,clone,rename} -p
vb160487
parents: 4451
diff changeset
  2934
				zfs_error_aux(hdl, dgettext(TEXT_DOMAIN,
abf035049f7f PSARC 2007/199 zfs {create,clone,rename} -p
vb160487
parents: 4451
diff changeset
  2935
				    "no such pool '%s'"), zc.zc_name);
abf035049f7f PSARC 2007/199 zfs {create,clone,rename} -p
vb160487
parents: 4451
diff changeset
  2936
				return (zfs_error(hdl, EZFS_NOENT, errbuf));
abf035049f7f PSARC 2007/199 zfs {create,clone,rename} -p
vb160487
parents: 4451
diff changeset
  2937
			}
abf035049f7f PSARC 2007/199 zfs {create,clone,rename} -p
vb160487
parents: 4451
diff changeset
  2938
		} else if (errno == ENOENT) {
2082
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1793
diff changeset
  2939
			zfs_error_aux(hdl, dgettext(TEXT_DOMAIN,
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1793
diff changeset
  2940
			    "parent does not exist"));
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1793
diff changeset
  2941
			return (zfs_error(hdl, EZFS_NOENT, errbuf));
4490
abf035049f7f PSARC 2007/199 zfs {create,clone,rename} -p
vb160487
parents: 4451
diff changeset
  2942
		} else
2082
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1793
diff changeset
  2943
			return (zfs_standard_error(hdl, errno, errbuf));
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2944
	}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2945
2676
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  2946
	*zoned = zfs_prop_get_int(zhp, ZFS_PROP_ZONED);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2947
	/* we are in a non-global zone, but parent is in the global zone */
2676
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  2948
	if (getzoneid() != GLOBAL_ZONEID && !(*zoned)) {
2082
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1793
diff changeset
  2949
		(void) zfs_standard_error(hdl, EPERM, errbuf);
1356
e021b5e4aa0e 6377671 zfs mount -a shouldn't bother checking snapshots
eschrock
parents: 1294
diff changeset
  2950
		zfs_close(zhp);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2951
		return (-1);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2952
	}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2953
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2954
	/* make sure parent is a filesystem */
1356
e021b5e4aa0e 6377671 zfs mount -a shouldn't bother checking snapshots
eschrock
parents: 1294
diff changeset
  2955
	if (zfs_get_type(zhp) != ZFS_TYPE_FILESYSTEM) {
2082
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1793
diff changeset
  2956
		zfs_error_aux(hdl, dgettext(TEXT_DOMAIN,
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1793
diff changeset
  2957
		    "parent is not a filesystem"));
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1793
diff changeset
  2958
		(void) zfs_error(hdl, EZFS_BADTYPE, errbuf);
1356
e021b5e4aa0e 6377671 zfs mount -a shouldn't bother checking snapshots
eschrock
parents: 1294
diff changeset
  2959
		zfs_close(zhp);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2960
		return (-1);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2961
	}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2962
1356
e021b5e4aa0e 6377671 zfs mount -a shouldn't bother checking snapshots
eschrock
parents: 1294
diff changeset
  2963
	zfs_close(zhp);
4490
abf035049f7f PSARC 2007/199 zfs {create,clone,rename} -p
vb160487
parents: 4451
diff changeset
  2964
	if (prefixlen != NULL)
abf035049f7f PSARC 2007/199 zfs {create,clone,rename} -p
vb160487
parents: 4451
diff changeset
  2965
		*prefixlen = strlen(parent);
abf035049f7f PSARC 2007/199 zfs {create,clone,rename} -p
vb160487
parents: 4451
diff changeset
  2966
	return (0);
abf035049f7f PSARC 2007/199 zfs {create,clone,rename} -p
vb160487
parents: 4451
diff changeset
  2967
}
abf035049f7f PSARC 2007/199 zfs {create,clone,rename} -p
vb160487
parents: 4451
diff changeset
  2968
abf035049f7f PSARC 2007/199 zfs {create,clone,rename} -p
vb160487
parents: 4451
diff changeset
  2969
/*
abf035049f7f PSARC 2007/199 zfs {create,clone,rename} -p
vb160487
parents: 4451
diff changeset
  2970
 * Finds whether the dataset of the given type(s) exists.
abf035049f7f PSARC 2007/199 zfs {create,clone,rename} -p
vb160487
parents: 4451
diff changeset
  2971
 */
abf035049f7f PSARC 2007/199 zfs {create,clone,rename} -p
vb160487
parents: 4451
diff changeset
  2972
boolean_t
abf035049f7f PSARC 2007/199 zfs {create,clone,rename} -p
vb160487
parents: 4451
diff changeset
  2973
zfs_dataset_exists(libzfs_handle_t *hdl, const char *path, zfs_type_t types)
abf035049f7f PSARC 2007/199 zfs {create,clone,rename} -p
vb160487
parents: 4451
diff changeset
  2974
{
abf035049f7f PSARC 2007/199 zfs {create,clone,rename} -p
vb160487
parents: 4451
diff changeset
  2975
	zfs_handle_t *zhp;
abf035049f7f PSARC 2007/199 zfs {create,clone,rename} -p
vb160487
parents: 4451
diff changeset
  2976
5326
6752aa2bd5bc 6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents: 5147
diff changeset
  2977
	if (!zfs_validate_name(hdl, path, types, B_FALSE))
4490
abf035049f7f PSARC 2007/199 zfs {create,clone,rename} -p
vb160487
parents: 4451
diff changeset
  2978
		return (B_FALSE);
abf035049f7f PSARC 2007/199 zfs {create,clone,rename} -p
vb160487
parents: 4451
diff changeset
  2979
abf035049f7f PSARC 2007/199 zfs {create,clone,rename} -p
vb160487
parents: 4451
diff changeset
  2980
	/*
abf035049f7f PSARC 2007/199 zfs {create,clone,rename} -p
vb160487
parents: 4451
diff changeset
  2981
	 * Try to get stats for the dataset, which will tell us if it exists.
abf035049f7f PSARC 2007/199 zfs {create,clone,rename} -p
vb160487
parents: 4451
diff changeset
  2982
	 */
abf035049f7f PSARC 2007/199 zfs {create,clone,rename} -p
vb160487
parents: 4451
diff changeset
  2983
	if ((zhp = make_dataset_handle(hdl, path)) != NULL) {
abf035049f7f PSARC 2007/199 zfs {create,clone,rename} -p
vb160487
parents: 4451
diff changeset
  2984
		int ds_type = zhp->zfs_type;
abf035049f7f PSARC 2007/199 zfs {create,clone,rename} -p
vb160487
parents: 4451
diff changeset
  2985
abf035049f7f PSARC 2007/199 zfs {create,clone,rename} -p
vb160487
parents: 4451
diff changeset
  2986
		zfs_close(zhp);
abf035049f7f PSARC 2007/199 zfs {create,clone,rename} -p
vb160487
parents: 4451
diff changeset
  2987
		if (types & ds_type)
abf035049f7f PSARC 2007/199 zfs {create,clone,rename} -p
vb160487
parents: 4451
diff changeset
  2988
			return (B_TRUE);
abf035049f7f PSARC 2007/199 zfs {create,clone,rename} -p
vb160487
parents: 4451
diff changeset
  2989
	}
abf035049f7f PSARC 2007/199 zfs {create,clone,rename} -p
vb160487
parents: 4451
diff changeset
  2990
	return (B_FALSE);
abf035049f7f PSARC 2007/199 zfs {create,clone,rename} -p
vb160487
parents: 4451
diff changeset
  2991
}
abf035049f7f PSARC 2007/199 zfs {create,clone,rename} -p
vb160487
parents: 4451
diff changeset
  2992
abf035049f7f PSARC 2007/199 zfs {create,clone,rename} -p
vb160487
parents: 4451
diff changeset
  2993
/*
5367
c40abbe796be PSARC/2007/574 zfs send -R
ahrens
parents: 5331
diff changeset
  2994
 * Given a path to 'target', create all the ancestors between
c40abbe796be PSARC/2007/574 zfs send -R
ahrens
parents: 5331
diff changeset
  2995
 * the prefixlen portion of the path, and the target itself.
c40abbe796be PSARC/2007/574 zfs send -R
ahrens
parents: 5331
diff changeset
  2996
 * Fail if the initial prefixlen-ancestor does not already exist.
c40abbe796be PSARC/2007/574 zfs send -R
ahrens
parents: 5331
diff changeset
  2997
 */
c40abbe796be PSARC/2007/574 zfs send -R
ahrens
parents: 5331
diff changeset
  2998
int
c40abbe796be PSARC/2007/574 zfs send -R
ahrens
parents: 5331
diff changeset
  2999
create_parents(libzfs_handle_t *hdl, char *target, int prefixlen)
c40abbe796be PSARC/2007/574 zfs send -R
ahrens
parents: 5331
diff changeset
  3000
{
c40abbe796be PSARC/2007/574 zfs send -R
ahrens
parents: 5331
diff changeset
  3001
	zfs_handle_t *h;
c40abbe796be PSARC/2007/574 zfs send -R
ahrens
parents: 5331
diff changeset
  3002
	char *cp;
c40abbe796be PSARC/2007/574 zfs send -R
ahrens
parents: 5331
diff changeset
  3003
	const char *opname;
c40abbe796be PSARC/2007/574 zfs send -R
ahrens
parents: 5331
diff changeset
  3004
c40abbe796be PSARC/2007/574 zfs send -R
ahrens
parents: 5331
diff changeset
  3005
	/* make sure prefix exists */
c40abbe796be PSARC/2007/574 zfs send -R
ahrens
parents: 5331
diff changeset
  3006
	cp = target + prefixlen;
c40abbe796be PSARC/2007/574 zfs send -R
ahrens
parents: 5331
diff changeset
  3007
	if (*cp != '/') {
c40abbe796be PSARC/2007/574 zfs send -R
ahrens
parents: 5331
diff changeset
  3008
		assert(strchr(cp, '/') == NULL);
c40abbe796be PSARC/2007/574 zfs send -R
ahrens
parents: 5331
diff changeset
  3009
		h = zfs_open(hdl, target, ZFS_TYPE_FILESYSTEM);
c40abbe796be PSARC/2007/574 zfs send -R
ahrens
parents: 5331
diff changeset
  3010
	} else {
c40abbe796be PSARC/2007/574 zfs send -R
ahrens
parents: 5331
diff changeset
  3011
		*cp = '\0';
c40abbe796be PSARC/2007/574 zfs send -R
ahrens
parents: 5331
diff changeset
  3012
		h = zfs_open(hdl, target, ZFS_TYPE_FILESYSTEM);
c40abbe796be PSARC/2007/574 zfs send -R
ahrens
parents: 5331
diff changeset
  3013
		*cp = '/';
c40abbe796be PSARC/2007/574 zfs send -R
ahrens
parents: 5331
diff changeset
  3014
	}
c40abbe796be PSARC/2007/574 zfs send -R
ahrens
parents: 5331
diff changeset
  3015
	if (h == NULL)
c40abbe796be PSARC/2007/574 zfs send -R
ahrens
parents: 5331
diff changeset
  3016
		return (-1);
c40abbe796be PSARC/2007/574 zfs send -R
ahrens
parents: 5331
diff changeset
  3017
	zfs_close(h);
c40abbe796be PSARC/2007/574 zfs send -R
ahrens
parents: 5331
diff changeset
  3018
c40abbe796be PSARC/2007/574 zfs send -R
ahrens
parents: 5331
diff changeset
  3019
	/*
c40abbe796be PSARC/2007/574 zfs send -R
ahrens
parents: 5331
diff changeset
  3020
	 * Attempt to create, mount, and share any ancestor filesystems,
c40abbe796be PSARC/2007/574 zfs send -R
ahrens
parents: 5331
diff changeset
  3021
	 * up to the prefixlen-long one.
c40abbe796be PSARC/2007/574 zfs send -R
ahrens
parents: 5331
diff changeset
  3022
	 */
c40abbe796be PSARC/2007/574 zfs send -R
ahrens
parents: 5331
diff changeset
  3023
	for (cp = target + prefixlen + 1;
c40abbe796be PSARC/2007/574 zfs send -R
ahrens
parents: 5331
diff changeset
  3024
	    cp = strchr(cp, '/'); *cp = '/', cp++) {
c40abbe796be PSARC/2007/574 zfs send -R
ahrens
parents: 5331
diff changeset
  3025
		char *logstr;
c40abbe796be PSARC/2007/574 zfs send -R
ahrens
parents: 5331
diff changeset
  3026
c40abbe796be PSARC/2007/574 zfs send -R
ahrens
parents: 5331
diff changeset
  3027
		*cp = '\0';
c40abbe796be PSARC/2007/574 zfs send -R
ahrens
parents: 5331
diff changeset
  3028
c40abbe796be PSARC/2007/574 zfs send -R
ahrens
parents: 5331
diff changeset
  3029
		h = make_dataset_handle(hdl, target);
c40abbe796be PSARC/2007/574 zfs send -R
ahrens
parents: 5331
diff changeset
  3030
		if (h) {
c40abbe796be PSARC/2007/574 zfs send -R
ahrens
parents: 5331
diff changeset
  3031
			/* it already exists, nothing to do here */
c40abbe796be PSARC/2007/574 zfs send -R
ahrens
parents: 5331
diff changeset
  3032
			zfs_close(h);
c40abbe796be PSARC/2007/574 zfs send -R
ahrens
parents: 5331
diff changeset
  3033
			continue;
c40abbe796be PSARC/2007/574 zfs send -R
ahrens
parents: 5331
diff changeset
  3034
		}
c40abbe796be PSARC/2007/574 zfs send -R
ahrens
parents: 5331
diff changeset
  3035
c40abbe796be PSARC/2007/574 zfs send -R
ahrens
parents: 5331
diff changeset
  3036
		logstr = hdl->libzfs_log_str;
c40abbe796be PSARC/2007/574 zfs send -R
ahrens
parents: 5331
diff changeset
  3037
		hdl->libzfs_log_str = NULL;
c40abbe796be PSARC/2007/574 zfs send -R
ahrens
parents: 5331
diff changeset
  3038
		if (zfs_create(hdl, target, ZFS_TYPE_FILESYSTEM,
c40abbe796be PSARC/2007/574 zfs send -R
ahrens
parents: 5331
diff changeset
  3039
		    NULL) != 0) {
c40abbe796be PSARC/2007/574 zfs send -R
ahrens
parents: 5331
diff changeset
  3040
			hdl->libzfs_log_str = logstr;
c40abbe796be PSARC/2007/574 zfs send -R
ahrens
parents: 5331
diff changeset
  3041
			opname = dgettext(TEXT_DOMAIN, "create");
c40abbe796be PSARC/2007/574 zfs send -R
ahrens
parents: 5331
diff changeset
  3042
			goto ancestorerr;
c40abbe796be PSARC/2007/574 zfs send -R
ahrens
parents: 5331
diff changeset
  3043
		}
c40abbe796be PSARC/2007/574 zfs send -R
ahrens
parents: 5331
diff changeset
  3044
c40abbe796be PSARC/2007/574 zfs send -R
ahrens
parents: 5331
diff changeset
  3045
		hdl->libzfs_log_str = logstr;
c40abbe796be PSARC/2007/574 zfs send -R
ahrens
parents: 5331
diff changeset
  3046
		h = zfs_open(hdl, target, ZFS_TYPE_FILESYSTEM);
c40abbe796be PSARC/2007/574 zfs send -R
ahrens
parents: 5331
diff changeset
  3047
		if (h == NULL) {
c40abbe796be PSARC/2007/574 zfs send -R
ahrens
parents: 5331
diff changeset
  3048
			opname = dgettext(TEXT_DOMAIN, "open");
c40abbe796be PSARC/2007/574 zfs send -R
ahrens
parents: 5331
diff changeset
  3049
			goto ancestorerr;
c40abbe796be PSARC/2007/574 zfs send -R
ahrens
parents: 5331
diff changeset
  3050
		}
c40abbe796be PSARC/2007/574 zfs send -R
ahrens
parents: 5331
diff changeset
  3051
c40abbe796be PSARC/2007/574 zfs send -R
ahrens
parents: 5331
diff changeset
  3052
		if (zfs_mount(h, NULL, 0) != 0) {
c40abbe796be PSARC/2007/574 zfs send -R
ahrens
parents: 5331
diff changeset
  3053
			opname = dgettext(TEXT_DOMAIN, "mount");
c40abbe796be PSARC/2007/574 zfs send -R
ahrens
parents: 5331
diff changeset
  3054
			goto ancestorerr;
c40abbe796be PSARC/2007/574 zfs send -R
ahrens
parents: 5331
diff changeset
  3055
		}
c40abbe796be PSARC/2007/574 zfs send -R
ahrens
parents: 5331
diff changeset
  3056
c40abbe796be PSARC/2007/574 zfs send -R
ahrens
parents: 5331
diff changeset
  3057
		if (zfs_share(h) != 0) {
c40abbe796be PSARC/2007/574 zfs send -R
ahrens
parents: 5331
diff changeset
  3058
			opname = dgettext(TEXT_DOMAIN, "share");
c40abbe796be PSARC/2007/574 zfs send -R
ahrens
parents: 5331
diff changeset
  3059
			goto ancestorerr;
c40abbe796be PSARC/2007/574 zfs send -R
ahrens
parents: 5331
diff changeset
  3060
		}
c40abbe796be PSARC/2007/574 zfs send -R
ahrens
parents: 5331
diff changeset
  3061
c40abbe796be PSARC/2007/574 zfs send -R
ahrens
parents: 5331
diff changeset
  3062
		zfs_close(h);
c40abbe796be PSARC/2007/574 zfs send -R
ahrens
parents: 5331
diff changeset
  3063
	}
c40abbe796be PSARC/2007/574 zfs send -R
ahrens
parents: 5331
diff changeset
  3064
c40abbe796be PSARC/2007/574 zfs send -R
ahrens
parents: 5331
diff changeset
  3065
	return (0);
c40abbe796be PSARC/2007/574 zfs send -R
ahrens
parents: 5331
diff changeset
  3066
c40abbe796be PSARC/2007/574 zfs send -R
ahrens
parents: 5331
diff changeset
  3067
ancestorerr:
c40abbe796be PSARC/2007/574 zfs send -R
ahrens
parents: 5331
diff changeset
  3068
	zfs_error_aux(hdl, dgettext(TEXT_DOMAIN,
c40abbe796be PSARC/2007/574 zfs send -R
ahrens
parents: 5331
diff changeset
  3069
	    "failed to %s ancestor '%s'"), opname, target);
c40abbe796be PSARC/2007/574 zfs send -R
ahrens
parents: 5331
diff changeset
  3070
	return (-1);
c40abbe796be PSARC/2007/574 zfs send -R
ahrens
parents: 5331
diff changeset
  3071
}
c40abbe796be PSARC/2007/574 zfs send -R
ahrens
parents: 5331
diff changeset
  3072
c40abbe796be PSARC/2007/574 zfs send -R
ahrens
parents: 5331
diff changeset
  3073
/*
4490
abf035049f7f PSARC 2007/199 zfs {create,clone,rename} -p
vb160487
parents: 4451
diff changeset
  3074
 * Creates non-existing ancestors of the given path.
abf035049f7f PSARC 2007/199 zfs {create,clone,rename} -p
vb160487
parents: 4451
diff changeset
  3075
 */
abf035049f7f PSARC 2007/199 zfs {create,clone,rename} -p
vb160487
parents: 4451
diff changeset
  3076
int
abf035049f7f PSARC 2007/199 zfs {create,clone,rename} -p
vb160487
parents: 4451
diff changeset
  3077
zfs_create_ancestors(libzfs_handle_t *hdl, const char *path)
abf035049f7f PSARC 2007/199 zfs {create,clone,rename} -p
vb160487
parents: 4451
diff changeset
  3078
{
abf035049f7f PSARC 2007/199 zfs {create,clone,rename} -p
vb160487
parents: 4451
diff changeset
  3079
	int prefix;
abf035049f7f PSARC 2007/199 zfs {create,clone,rename} -p
vb160487
parents: 4451
diff changeset
  3080
	uint64_t zoned;
abf035049f7f PSARC 2007/199 zfs {create,clone,rename} -p
vb160487
parents: 4451
diff changeset
  3081
	char *path_copy;
abf035049f7f PSARC 2007/199 zfs {create,clone,rename} -p
vb160487
parents: 4451
diff changeset
  3082
	int rc;
abf035049f7f PSARC 2007/199 zfs {create,clone,rename} -p
vb160487
parents: 4451
diff changeset
  3083
abf035049f7f PSARC 2007/199 zfs {create,clone,rename} -p
vb160487
parents: 4451
diff changeset
  3084
	if (check_parents(hdl, path, &zoned, B_TRUE, &prefix) != 0)
abf035049f7f PSARC 2007/199 zfs {create,clone,rename} -p
vb160487
parents: 4451
diff changeset
  3085
		return (-1);
abf035049f7f PSARC 2007/199 zfs {create,clone,rename} -p
vb160487
parents: 4451
diff changeset
  3086
abf035049f7f PSARC 2007/199 zfs {create,clone,rename} -p
vb160487
parents: 4451
diff changeset
  3087
	if ((path_copy = strdup(path)) != NULL) {
abf035049f7f PSARC 2007/199 zfs {create,clone,rename} -p
vb160487
parents: 4451
diff changeset
  3088
		rc = create_parents(hdl, path_copy, prefix);
abf035049f7f PSARC 2007/199 zfs {create,clone,rename} -p
vb160487
parents: 4451
diff changeset
  3089
		free(path_copy);
abf035049f7f PSARC 2007/199 zfs {create,clone,rename} -p
vb160487
parents: 4451
diff changeset
  3090
	}
abf035049f7f PSARC 2007/199 zfs {create,clone,rename} -p
vb160487
parents: 4451
diff changeset
  3091
	if (path_copy == NULL || rc != 0)
abf035049f7f PSARC 2007/199 zfs {create,clone,rename} -p
vb160487
parents: 4451
diff changeset
  3092
		return (-1);
abf035049f7f PSARC 2007/199 zfs {create,clone,rename} -p
vb160487
parents: 4451
diff changeset
  3093
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3094
	return (0);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3095
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3096
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3097
/*
2676
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  3098
 * Create a new filesystem or volume.
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3099
 */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3100
int
2082
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1793
diff changeset
  3101
zfs_create(libzfs_handle_t *hdl, const char *path, zfs_type_t type,
2676
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  3102
    nvlist_t *props)
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3103
{
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3104
	zfs_cmd_t zc = { 0 };
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3105
	int ret;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3106
	uint64_t size = 0;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3107
	uint64_t blocksize = zfs_prop_default_numeric(ZFS_PROP_VOLBLOCKSIZE);
2082
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1793
diff changeset
  3108
	char errbuf[1024];
2676
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  3109
	uint64_t zoned;
2082
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1793
diff changeset
  3110
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1793
diff changeset
  3111
	(void) snprintf(errbuf, sizeof (errbuf), dgettext(TEXT_DOMAIN,
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1793
diff changeset
  3112
	    "cannot create '%s'"), path);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3113
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3114
	/* validate the path, taking care to note the extended error message */
5326
6752aa2bd5bc 6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents: 5147
diff changeset
  3115
	if (!zfs_validate_name(hdl, path, type, B_TRUE))
2082
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1793
diff changeset
  3116
		return (zfs_error(hdl, EZFS_INVALIDNAME, errbuf));
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3117
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3118
	/* validate parents exist */
4490
abf035049f7f PSARC 2007/199 zfs {create,clone,rename} -p
vb160487
parents: 4451
diff changeset
  3119
	if (check_parents(hdl, path, &zoned, B_FALSE, NULL) != 0)
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3120
		return (-1);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3121
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3122
	/*
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3123
	 * The failure modes when creating a dataset of a different type over
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3124
	 * one that already exists is a little strange.  In particular, if you
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3125
	 * try to create a dataset on top of an existing dataset, the ioctl()
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3126
	 * will return ENOENT, not EEXIST.  To prevent this from happening, we
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3127
	 * first try to see if the dataset exists.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3128
	 */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3129
	(void) strlcpy(zc.zc_name, path, sizeof (zc.zc_name));
5094
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4861
diff changeset
  3130
	if (zfs_dataset_exists(hdl, zc.zc_name, ZFS_TYPE_DATASET)) {
2082
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1793
diff changeset
  3131
		zfs_error_aux(hdl, dgettext(TEXT_DOMAIN,
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1793
diff changeset
  3132
		    "dataset already exists"));
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1793
diff changeset
  3133
		return (zfs_error(hdl, EZFS_EXISTS, errbuf));
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3134
	}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3135
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3136
	if (type == ZFS_TYPE_VOLUME)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3137
		zc.zc_objset_type = DMU_OST_ZVOL;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3138
	else
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3139
		zc.zc_objset_type = DMU_OST_ZFS;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3140
7184
9508660f9c27 PSARC 2008/223 Pool root file system properties via zpool(1M)
timh
parents: 7042
diff changeset
  3141
	if (props && (props = zfs_valid_proplist(hdl, type, props,
3912
f6891a60bd72 PSARC 2007/083 ZFS bootable datasets
lling
parents: 3886
diff changeset
  3142
	    zoned, NULL, errbuf)) == 0)
2676
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  3143
		return (-1);
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  3144
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3145
	if (type == ZFS_TYPE_VOLUME) {
1133
335d069294d1 6357470 vdev_raidz.c has unused RAIDZ_SINGLE define, code
eschrock
parents: 1003
diff changeset
  3146
		/*
335d069294d1 6357470 vdev_raidz.c has unused RAIDZ_SINGLE define, code
eschrock
parents: 1003
diff changeset
  3147
		 * If we are creating a volume, the size and block size must
335d069294d1 6357470 vdev_raidz.c has unused RAIDZ_SINGLE define, code
eschrock
parents: 1003
diff changeset
  3148
		 * satisfy a few restraints.  First, the blocksize must be a
335d069294d1 6357470 vdev_raidz.c has unused RAIDZ_SINGLE define, code
eschrock
parents: 1003
diff changeset
  3149
		 * valid block size between SPA_{MIN,MAX}BLOCKSIZE.  Second, the
335d069294d1 6357470 vdev_raidz.c has unused RAIDZ_SINGLE define, code
eschrock
parents: 1003
diff changeset
  3150
		 * volsize must be a multiple of the block size, and cannot be
335d069294d1 6357470 vdev_raidz.c has unused RAIDZ_SINGLE define, code
eschrock
parents: 1003
diff changeset
  3151
		 * zero.
335d069294d1 6357470 vdev_raidz.c has unused RAIDZ_SINGLE define, code
eschrock
parents: 1003
diff changeset
  3152
		 */
2676
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  3153
		if (props == NULL || nvlist_lookup_uint64(props,
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  3154
		    zfs_prop_to_name(ZFS_PROP_VOLSIZE), &size) != 0) {
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  3155
			nvlist_free(props);
2082
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1793
diff changeset
  3156
			zfs_error_aux(hdl, dgettext(TEXT_DOMAIN,
2676
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  3157
			    "missing volume size"));
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  3158
			return (zfs_error(hdl, EZFS_BADPROP, errbuf));
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3159
		}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3160
2676
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  3161
		if ((ret = nvlist_lookup_uint64(props,
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  3162
		    zfs_prop_to_name(ZFS_PROP_VOLBLOCKSIZE),
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  3163
		    &blocksize)) != 0) {
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  3164
			if (ret == ENOENT) {
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  3165
				blocksize = zfs_prop_default_numeric(
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  3166
				    ZFS_PROP_VOLBLOCKSIZE);
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  3167
			} else {
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  3168
				nvlist_free(props);
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  3169
				zfs_error_aux(hdl, dgettext(TEXT_DOMAIN,
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  3170
				    "missing volume block size"));
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  3171
				return (zfs_error(hdl, EZFS_BADPROP, errbuf));
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  3172
			}
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  3173
		}
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  3174
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  3175
		if (size == 0) {
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  3176
			nvlist_free(props);
2082
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1793
diff changeset
  3177
			zfs_error_aux(hdl, dgettext(TEXT_DOMAIN,
2676
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  3178
			    "volume size cannot be zero"));
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  3179
			return (zfs_error(hdl, EZFS_BADPROP, errbuf));
1133
335d069294d1 6357470 vdev_raidz.c has unused RAIDZ_SINGLE define, code
eschrock
parents: 1003
diff changeset
  3180
		}
335d069294d1 6357470 vdev_raidz.c has unused RAIDZ_SINGLE define, code
eschrock
parents: 1003
diff changeset
  3181
335d069294d1 6357470 vdev_raidz.c has unused RAIDZ_SINGLE define, code
eschrock
parents: 1003
diff changeset
  3182
		if (size % blocksize != 0) {
2676
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  3183
			nvlist_free(props);
2082
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1793
diff changeset
  3184
			zfs_error_aux(hdl, dgettext(TEXT_DOMAIN,
2676
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  3185
			    "volume size must be a multiple of volume block "
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  3186
			    "size"));
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  3187
			return (zfs_error(hdl, EZFS_BADPROP, errbuf));
1133
335d069294d1 6357470 vdev_raidz.c has unused RAIDZ_SINGLE define, code
eschrock
parents: 1003
diff changeset
  3188
		}
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3189
	}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3190
5094
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4861
diff changeset
  3191
	if (props && zcmd_write_src_nvlist(hdl, &zc, props) != 0)
2676
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  3192
		return (-1);
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  3193
	nvlist_free(props);
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  3194
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3195
	/* create the dataset */
4543
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  3196
	ret = zfs_ioctl(hdl, ZFS_IOC_CREATE, &zc);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3197
3912
f6891a60bd72 PSARC 2007/083 ZFS bootable datasets
lling
parents: 3886
diff changeset
  3198
	if (ret == 0 && type == ZFS_TYPE_VOLUME) {
2082
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1793
diff changeset
  3199
		ret = zvol_create_link(hdl, path);
3912
f6891a60bd72 PSARC 2007/083 ZFS bootable datasets
lling
parents: 3886
diff changeset
  3200
		if (ret) {
f6891a60bd72 PSARC 2007/083 ZFS bootable datasets
lling
parents: 3886
diff changeset
  3201
			(void) zfs_standard_error(hdl, errno,
f6891a60bd72 PSARC 2007/083 ZFS bootable datasets
lling
parents: 3886
diff changeset
  3202
			    dgettext(TEXT_DOMAIN,
f6891a60bd72 PSARC 2007/083 ZFS bootable datasets
lling
parents: 3886
diff changeset
  3203
			    "Volume successfully created, but device links "
f6891a60bd72 PSARC 2007/083 ZFS bootable datasets
lling
parents: 3886
diff changeset
  3204
			    "were not created"));
f6891a60bd72 PSARC 2007/083 ZFS bootable datasets
lling
parents: 3886
diff changeset
  3205
			zcmd_free_nvlists(&zc);
f6891a60bd72 PSARC 2007/083 ZFS bootable datasets
lling
parents: 3886
diff changeset
  3206
			return (-1);
f6891a60bd72 PSARC 2007/083 ZFS bootable datasets
lling
parents: 3886
diff changeset
  3207
		}
f6891a60bd72 PSARC 2007/083 ZFS bootable datasets
lling
parents: 3886
diff changeset
  3208
	}
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3209
2676
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  3210
	zcmd_free_nvlists(&zc);
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  3211
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3212
	/* check for failure */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3213
	if (ret != 0) {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3214
		char parent[ZFS_MAXNAMELEN];
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3215
		(void) parent_name(path, parent, sizeof (parent));
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3216
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3217
		switch (errno) {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3218
		case ENOENT:
2082
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1793
diff changeset
  3219
			zfs_error_aux(hdl, dgettext(TEXT_DOMAIN,
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1793
diff changeset
  3220
			    "no such parent '%s'"), parent);
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1793
diff changeset
  3221
			return (zfs_error(hdl, EZFS_NOENT, errbuf));
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3222
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3223
		case EINVAL:
2082
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1793
diff changeset
  3224
			zfs_error_aux(hdl, dgettext(TEXT_DOMAIN,
3413
f4cbe0204ab7 6471255 Some ZFS error messages contain spelling errors
mmusante
parents: 3377
diff changeset
  3225
			    "parent '%s' is not a filesystem"), parent);
2082
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1793
diff changeset
  3226
			return (zfs_error(hdl, EZFS_BADTYPE, errbuf));
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3227
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3228
		case EDOM:
2082
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1793
diff changeset
  3229
			zfs_error_aux(hdl, dgettext(TEXT_DOMAIN,
2676
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  3230
			    "volume block size must be power of 2 from "
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  3231
			    "%u to %uk"),
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3232
			    (uint_t)SPA_MINBLOCKSIZE,
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3233
			    (uint_t)SPA_MAXBLOCKSIZE >> 10);
2082
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1793
diff changeset
  3234
2676
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  3235
			return (zfs_error(hdl, EZFS_BADPROP, errbuf));
2082
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1793
diff changeset
  3236
4603
c7840c367d00 6494569 zfs recv -d pool/<doesn't exist> core dumps for top-level filesystem backups
ahrens
parents: 4597
diff changeset
  3237
		case ENOTSUP:
c7840c367d00 6494569 zfs recv -d pool/<doesn't exist> core dumps for top-level filesystem backups
ahrens
parents: 4597
diff changeset
  3238
			zfs_error_aux(hdl, dgettext(TEXT_DOMAIN,
c7840c367d00 6494569 zfs recv -d pool/<doesn't exist> core dumps for top-level filesystem backups
ahrens
parents: 4597
diff changeset
  3239
			    "pool must be upgraded to set this "
c7840c367d00 6494569 zfs recv -d pool/<doesn't exist> core dumps for top-level filesystem backups
ahrens
parents: 4597
diff changeset
  3240
			    "property or value"));
c7840c367d00 6494569 zfs recv -d pool/<doesn't exist> core dumps for top-level filesystem backups
ahrens
parents: 4597
diff changeset
  3241
			return (zfs_error(hdl, EZFS_BADVERSION, errbuf));
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3242
#ifdef _ILP32
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3243
		case EOVERFLOW:
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3244
			/*
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3245
			 * This platform can't address a volume this big.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3246
			 */
2082
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1793
diff changeset
  3247
			if (type == ZFS_TYPE_VOLUME)
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1793
diff changeset
  3248
				return (zfs_error(hdl, EZFS_VOLTOOBIG,
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1793
diff changeset
  3249
				    errbuf));
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3250
#endif
2082
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1793
diff changeset
  3251
			/* FALLTHROUGH */
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3252
		default:
2082
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1793
diff changeset
  3253
			return (zfs_standard_error(hdl, errno, errbuf));
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3254
		}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3255
	}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3256
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3257
	return (0);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3258
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3259
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3260
/*
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3261
 * Destroys the given dataset.  The caller must make sure that the filesystem
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3262
 * isn't mounted, and that there are no active dependents.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3263
 */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3264
int
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3265
zfs_destroy(zfs_handle_t *zhp)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3266
{
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3267
	zfs_cmd_t zc = { 0 };
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3268
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3269
	(void) strlcpy(zc.zc_name, zhp->zfs_name, sizeof (zc.zc_name));
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3270
2676
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  3271
	if (ZFS_IS_VOLUME(zhp)) {
3126
4f4fb617fdd0 PSARC 2006/622 iSCSI/ZFS Integration
ahl
parents: 2885
diff changeset
  3272
		/*
4543
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  3273
		 * If user doesn't have permissions to unshare volume, then
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  3274
		 * abort the request.  This would only happen for a
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  3275
		 * non-privileged user.
3126
4f4fb617fdd0 PSARC 2006/622 iSCSI/ZFS Integration
ahl
parents: 2885
diff changeset
  3276
		 */
4543
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  3277
		if (zfs_unshare_iscsi(zhp) != 0) {
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  3278
			return (-1);
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  3279
		}
3126
4f4fb617fdd0 PSARC 2006/622 iSCSI/ZFS Integration
ahl
parents: 2885
diff changeset
  3280
2082
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1793
diff changeset
  3281
		if (zvol_remove_link(zhp->zfs_hdl, zhp->zfs_name) != 0)
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3282
			return (-1);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3283
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3284
		zc.zc_objset_type = DMU_OST_ZVOL;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3285
	} else {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3286
		zc.zc_objset_type = DMU_OST_ZFS;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3287
	}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3288
4543
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  3289
	if (zfs_ioctl(zhp->zfs_hdl, ZFS_IOC_DESTROY, &zc) != 0) {
3237
98d0c28f2f5e 6480245 renaming a dataset to something with '%s' will cause segfault
lling
parents: 3234
diff changeset
  3290
		return (zfs_standard_error_fmt(zhp->zfs_hdl, errno,
2082
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1793
diff changeset
  3291
		    dgettext(TEXT_DOMAIN, "cannot destroy '%s'"),
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1793
diff changeset
  3292
		    zhp->zfs_name));
2199
712a788c2dfd PSARC 2006/388 snapshot -r
ahrens
parents: 2169
diff changeset
  3293
	}
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3294
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3295
	remove_mountpoint(zhp);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3296
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3297
	return (0);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3298
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3299
2199
712a788c2dfd PSARC 2006/388 snapshot -r
ahrens
parents: 2169
diff changeset
  3300
struct destroydata {
712a788c2dfd PSARC 2006/388 snapshot -r
ahrens
parents: 2169
diff changeset
  3301
	char *snapname;
712a788c2dfd PSARC 2006/388 snapshot -r
ahrens
parents: 2169
diff changeset
  3302
	boolean_t gotone;
3265
967e0fca6143 6463140 zfs recv with a snapshot name that has 2 @@ in a row succeeds
ahrens
parents: 3237
diff changeset
  3303
	boolean_t closezhp;
2199
712a788c2dfd PSARC 2006/388 snapshot -r
ahrens
parents: 2169
diff changeset
  3304
};
712a788c2dfd PSARC 2006/388 snapshot -r
ahrens
parents: 2169
diff changeset
  3305
712a788c2dfd PSARC 2006/388 snapshot -r
ahrens
parents: 2169
diff changeset
  3306
static int
712a788c2dfd PSARC 2006/388 snapshot -r
ahrens
parents: 2169
diff changeset
  3307
zfs_remove_link_cb(zfs_handle_t *zhp, void *arg)
712a788c2dfd PSARC 2006/388 snapshot -r
ahrens
parents: 2169
diff changeset
  3308
{
712a788c2dfd PSARC 2006/388 snapshot -r
ahrens
parents: 2169
diff changeset
  3309
	struct destroydata *dd = arg;
712a788c2dfd PSARC 2006/388 snapshot -r
ahrens
parents: 2169
diff changeset
  3310
	zfs_handle_t *szhp;
712a788c2dfd PSARC 2006/388 snapshot -r
ahrens
parents: 2169
diff changeset
  3311
	char name[ZFS_MAXNAMELEN];
3265
967e0fca6143 6463140 zfs recv with a snapshot name that has 2 @@ in a row succeeds
ahrens
parents: 3237
diff changeset
  3312
	boolean_t closezhp = dd->closezhp;
967e0fca6143 6463140 zfs recv with a snapshot name that has 2 @@ in a row succeeds
ahrens
parents: 3237
diff changeset
  3313
	int rv;
2199
712a788c2dfd PSARC 2006/388 snapshot -r
ahrens
parents: 2169
diff changeset
  3314
2676
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  3315
	(void) strlcpy(name, zhp->zfs_name, sizeof (name));
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  3316
	(void) strlcat(name, "@", sizeof (name));
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  3317
	(void) strlcat(name, dd->snapname, sizeof (name));
2199
712a788c2dfd PSARC 2006/388 snapshot -r
ahrens
parents: 2169
diff changeset
  3318
712a788c2dfd PSARC 2006/388 snapshot -r
ahrens
parents: 2169
diff changeset
  3319
	szhp = make_dataset_handle(zhp->zfs_hdl, name);
712a788c2dfd PSARC 2006/388 snapshot -r
ahrens
parents: 2169
diff changeset
  3320
	if (szhp) {
712a788c2dfd PSARC 2006/388 snapshot -r
ahrens
parents: 2169
diff changeset
  3321
		dd->gotone = B_TRUE;
712a788c2dfd PSARC 2006/388 snapshot -r
ahrens
parents: 2169
diff changeset
  3322
		zfs_close(szhp);
712a788c2dfd PSARC 2006/388 snapshot -r
ahrens
parents: 2169
diff changeset
  3323
	}
712a788c2dfd PSARC 2006/388 snapshot -r
ahrens
parents: 2169
diff changeset
  3324
712a788c2dfd PSARC 2006/388 snapshot -r
ahrens
parents: 2169
diff changeset
  3325
	if (zhp->zfs_type == ZFS_TYPE_VOLUME) {
712a788c2dfd PSARC 2006/388 snapshot -r
ahrens
parents: 2169
diff changeset
  3326
		(void) zvol_remove_link(zhp->zfs_hdl, name);
712a788c2dfd PSARC 2006/388 snapshot -r
ahrens
parents: 2169
diff changeset
  3327
		/*
712a788c2dfd PSARC 2006/388 snapshot -r
ahrens
parents: 2169
diff changeset
  3328
		 * NB: this is simply a best-effort.  We don't want to
712a788c2dfd PSARC 2006/388 snapshot -r
ahrens
parents: 2169
diff changeset
  3329
		 * return an error, because then we wouldn't visit all
712a788c2dfd PSARC 2006/388 snapshot -r
ahrens
parents: 2169
diff changeset
  3330
		 * the volumes.
712a788c2dfd PSARC 2006/388 snapshot -r
ahrens
parents: 2169
diff changeset
  3331
		 */
712a788c2dfd PSARC 2006/388 snapshot -r
ahrens
parents: 2169
diff changeset
  3332
	}
712a788c2dfd PSARC 2006/388 snapshot -r
ahrens
parents: 2169
diff changeset
  3333
3265
967e0fca6143 6463140 zfs recv with a snapshot name that has 2 @@ in a row succeeds
ahrens
parents: 3237
diff changeset
  3334
	dd->closezhp = B_TRUE;
967e0fca6143 6463140 zfs recv with a snapshot name that has 2 @@ in a row succeeds
ahrens
parents: 3237
diff changeset
  3335
	rv = zfs_iter_filesystems(zhp, zfs_remove_link_cb, arg);
967e0fca6143 6463140 zfs recv with a snapshot name that has 2 @@ in a row succeeds
ahrens
parents: 3237
diff changeset
  3336
	if (closezhp)
967e0fca6143 6463140 zfs recv with a snapshot name that has 2 @@ in a row succeeds
ahrens
parents: 3237
diff changeset
  3337
		zfs_close(zhp);
967e0fca6143 6463140 zfs recv with a snapshot name that has 2 @@ in a row succeeds
ahrens
parents: 3237
diff changeset
  3338
	return (rv);
2199
712a788c2dfd PSARC 2006/388 snapshot -r
ahrens
parents: 2169
diff changeset
  3339
}
712a788c2dfd PSARC 2006/388 snapshot -r
ahrens
parents: 2169
diff changeset
  3340
712a788c2dfd PSARC 2006/388 snapshot -r
ahrens
parents: 2169
diff changeset
  3341
/*
712a788c2dfd PSARC 2006/388 snapshot -r
ahrens
parents: 2169
diff changeset
  3342
 * Destroys all snapshots with the given name in zhp & descendants.
712a788c2dfd PSARC 2006/388 snapshot -r
ahrens
parents: 2169
diff changeset
  3343
 */
712a788c2dfd PSARC 2006/388 snapshot -r
ahrens
parents: 2169
diff changeset
  3344
int
712a788c2dfd PSARC 2006/388 snapshot -r
ahrens
parents: 2169
diff changeset
  3345
zfs_destroy_snaps(zfs_handle_t *zhp, char *snapname)
712a788c2dfd PSARC 2006/388 snapshot -r
ahrens
parents: 2169
diff changeset
  3346
{
712a788c2dfd PSARC 2006/388 snapshot -r
ahrens
parents: 2169
diff changeset
  3347
	zfs_cmd_t zc = { 0 };
712a788c2dfd PSARC 2006/388 snapshot -r
ahrens
parents: 2169
diff changeset
  3348
	int ret;
712a788c2dfd PSARC 2006/388 snapshot -r
ahrens
parents: 2169
diff changeset
  3349
	struct destroydata dd = { 0 };
712a788c2dfd PSARC 2006/388 snapshot -r
ahrens
parents: 2169
diff changeset
  3350
712a788c2dfd PSARC 2006/388 snapshot -r
ahrens
parents: 2169
diff changeset
  3351
	dd.snapname = snapname;
712a788c2dfd PSARC 2006/388 snapshot -r
ahrens
parents: 2169
diff changeset
  3352
	(void) zfs_remove_link_cb(zhp, &dd);
712a788c2dfd PSARC 2006/388 snapshot -r
ahrens
parents: 2169
diff changeset
  3353
712a788c2dfd PSARC 2006/388 snapshot -r
ahrens
parents: 2169
diff changeset
  3354
	if (!dd.gotone) {
3237
98d0c28f2f5e 6480245 renaming a dataset to something with '%s' will cause segfault
lling
parents: 3234
diff changeset
  3355
		return (zfs_standard_error_fmt(zhp->zfs_hdl, ENOENT,
2199
712a788c2dfd PSARC 2006/388 snapshot -r
ahrens
parents: 2169
diff changeset
  3356
		    dgettext(TEXT_DOMAIN, "cannot destroy '%s@%s'"),
712a788c2dfd PSARC 2006/388 snapshot -r
ahrens
parents: 2169
diff changeset
  3357
		    zhp->zfs_name, snapname));
712a788c2dfd PSARC 2006/388 snapshot -r
ahrens
parents: 2169
diff changeset
  3358
	}
712a788c2dfd PSARC 2006/388 snapshot -r
ahrens
parents: 2169
diff changeset
  3359
712a788c2dfd PSARC 2006/388 snapshot -r
ahrens
parents: 2169
diff changeset
  3360
	(void) strlcpy(zc.zc_name, zhp->zfs_name, sizeof (zc.zc_name));
2676
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  3361
	(void) strlcpy(zc.zc_value, snapname, sizeof (zc.zc_value));
2199
712a788c2dfd PSARC 2006/388 snapshot -r
ahrens
parents: 2169
diff changeset
  3362
4543
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  3363
	ret = zfs_ioctl(zhp->zfs_hdl, ZFS_IOC_DESTROY_SNAPS, &zc);
2199
712a788c2dfd PSARC 2006/388 snapshot -r
ahrens
parents: 2169
diff changeset
  3364
	if (ret != 0) {
712a788c2dfd PSARC 2006/388 snapshot -r
ahrens
parents: 2169
diff changeset
  3365
		char errbuf[1024];
712a788c2dfd PSARC 2006/388 snapshot -r
ahrens
parents: 2169
diff changeset
  3366
712a788c2dfd PSARC 2006/388 snapshot -r
ahrens
parents: 2169
diff changeset
  3367
		(void) snprintf(errbuf, sizeof (errbuf), dgettext(TEXT_DOMAIN,
712a788c2dfd PSARC 2006/388 snapshot -r
ahrens
parents: 2169
diff changeset
  3368
		    "cannot destroy '%s@%s'"), zc.zc_name, snapname);
712a788c2dfd PSARC 2006/388 snapshot -r
ahrens
parents: 2169
diff changeset
  3369
712a788c2dfd PSARC 2006/388 snapshot -r
ahrens
parents: 2169
diff changeset
  3370
		switch (errno) {
712a788c2dfd PSARC 2006/388 snapshot -r
ahrens
parents: 2169
diff changeset
  3371
		case EEXIST:
712a788c2dfd PSARC 2006/388 snapshot -r
ahrens
parents: 2169
diff changeset
  3372
			zfs_error_aux(zhp->zfs_hdl, dgettext(TEXT_DOMAIN,
712a788c2dfd PSARC 2006/388 snapshot -r
ahrens
parents: 2169
diff changeset
  3373
			    "snapshot is cloned"));
712a788c2dfd PSARC 2006/388 snapshot -r
ahrens
parents: 2169
diff changeset
  3374
			return (zfs_error(zhp->zfs_hdl, EZFS_EXISTS, errbuf));
712a788c2dfd PSARC 2006/388 snapshot -r
ahrens
parents: 2169
diff changeset
  3375
712a788c2dfd PSARC 2006/388 snapshot -r
ahrens
parents: 2169
diff changeset
  3376
		default:
712a788c2dfd PSARC 2006/388 snapshot -r
ahrens
parents: 2169
diff changeset
  3377
			return (zfs_standard_error(zhp->zfs_hdl, errno,
712a788c2dfd PSARC 2006/388 snapshot -r
ahrens
parents: 2169
diff changeset
  3378
			    errbuf));
712a788c2dfd PSARC 2006/388 snapshot -r
ahrens
parents: 2169
diff changeset
  3379
		}
712a788c2dfd PSARC 2006/388 snapshot -r
ahrens
parents: 2169
diff changeset
  3380
	}
712a788c2dfd PSARC 2006/388 snapshot -r
ahrens
parents: 2169
diff changeset
  3381
712a788c2dfd PSARC 2006/388 snapshot -r
ahrens
parents: 2169
diff changeset
  3382
	return (0);
712a788c2dfd PSARC 2006/388 snapshot -r
ahrens
parents: 2169
diff changeset
  3383
}
712a788c2dfd PSARC 2006/388 snapshot -r
ahrens
parents: 2169
diff changeset
  3384
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3385
/*
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3386
 * Clones the given dataset.  The target must be of the same type as the source.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3387
 */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3388
int
2676
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  3389
zfs_clone(zfs_handle_t *zhp, const char *target, nvlist_t *props)
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3390
{
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3391
	zfs_cmd_t zc = { 0 };
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3392
	char parent[ZFS_MAXNAMELEN];
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3393
	int ret;
2082
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1793
diff changeset
  3394
	char errbuf[1024];
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1793
diff changeset
  3395
	libzfs_handle_t *hdl = zhp->zfs_hdl;
2676
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  3396
	zfs_type_t type;
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  3397
	uint64_t zoned;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3398
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3399
	assert(zhp->zfs_type == ZFS_TYPE_SNAPSHOT);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3400
2082
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1793
diff changeset
  3401
	(void) snprintf(errbuf, sizeof (errbuf), dgettext(TEXT_DOMAIN,
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1793
diff changeset
  3402
	    "cannot create '%s'"), target);
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1793
diff changeset
  3403
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3404
	/* validate the target name */
5326
6752aa2bd5bc 6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents: 5147
diff changeset
  3405
	if (!zfs_validate_name(hdl, target, ZFS_TYPE_FILESYSTEM, B_TRUE))
2082
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1793
diff changeset
  3406
		return (zfs_error(hdl, EZFS_INVALIDNAME, errbuf));
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3407
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3408
	/* validate parents exist */
4490
abf035049f7f PSARC 2007/199 zfs {create,clone,rename} -p
vb160487
parents: 4451
diff changeset
  3409
	if (check_parents(hdl, target, &zoned, B_FALSE, NULL) != 0)
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3410
		return (-1);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3411
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3412
	(void) parent_name(target, parent, sizeof (parent));
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3413
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3414
	/* do the clone */
2676
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  3415
	if (ZFS_IS_VOLUME(zhp)) {
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3416
		zc.zc_objset_type = DMU_OST_ZVOL;
2744
0a6f00b6a209 6468554 zone install with a zfs zonepath could not create a dataset
nn35248
parents: 2676
diff changeset
  3417
		type = ZFS_TYPE_VOLUME;
2676
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  3418
	} else {
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3419
		zc.zc_objset_type = DMU_OST_ZFS;
2744
0a6f00b6a209 6468554 zone install with a zfs zonepath could not create a dataset
nn35248
parents: 2676
diff changeset
  3420
		type = ZFS_TYPE_FILESYSTEM;
2676
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  3421
	}
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  3422
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  3423
	if (props) {
7184
9508660f9c27 PSARC 2008/223 Pool root file system properties via zpool(1M)
timh
parents: 7042
diff changeset
  3424
		if ((props = zfs_valid_proplist(hdl, type, props, zoned,
9508660f9c27 PSARC 2008/223 Pool root file system properties via zpool(1M)
timh
parents: 7042
diff changeset
  3425
		    zhp, errbuf)) == NULL)
2676
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  3426
			return (-1);
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  3427
5094
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4861
diff changeset
  3428
		if (zcmd_write_src_nvlist(hdl, &zc, props) != 0) {
2676
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  3429
			nvlist_free(props);
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  3430
			return (-1);
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  3431
		}
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  3432
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  3433
		nvlist_free(props);
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  3434
	}
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3435
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3436
	(void) strlcpy(zc.zc_name, target, sizeof (zc.zc_name));
2676
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  3437
	(void) strlcpy(zc.zc_value, zhp->zfs_name, sizeof (zc.zc_value));
4543
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  3438
	ret = zfs_ioctl(zhp->zfs_hdl, ZFS_IOC_CREATE, &zc);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3439
2676
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  3440
	zcmd_free_nvlists(&zc);
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  3441
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3442
	if (ret != 0) {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3443
		switch (errno) {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3444
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3445
		case ENOENT:
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3446
			/*
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3447
			 * The parent doesn't exist.  We should have caught this
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3448
			 * above, but there may a race condition that has since
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3449
			 * destroyed the parent.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3450
			 *
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3451
			 * At this point, we don't know whether it's the source
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3452
			 * that doesn't exist anymore, or whether the target
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3453
			 * dataset doesn't exist.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3454
			 */
2082
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1793
diff changeset
  3455
			zfs_error_aux(zhp->zfs_hdl, dgettext(TEXT_DOMAIN,
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1793
diff changeset
  3456
			    "no such parent '%s'"), parent);
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1793
diff changeset
  3457
			return (zfs_error(zhp->zfs_hdl, EZFS_NOENT, errbuf));
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1793
diff changeset
  3458
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1793
diff changeset
  3459
		case EXDEV:
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1793
diff changeset
  3460
			zfs_error_aux(zhp->zfs_hdl, dgettext(TEXT_DOMAIN,
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1793
diff changeset
  3461
			    "source and target pools differ"));
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1793
diff changeset
  3462
			return (zfs_error(zhp->zfs_hdl, EZFS_CROSSTARGET,
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1793
diff changeset
  3463
			    errbuf));
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1793
diff changeset
  3464
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1793
diff changeset
  3465
		default:
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1793
diff changeset
  3466
			return (zfs_standard_error(zhp->zfs_hdl, errno,
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1793
diff changeset
  3467
			    errbuf));
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1793
diff changeset
  3468
		}
2676
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  3469
	} else if (ZFS_IS_VOLUME(zhp)) {
2082
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1793
diff changeset
  3470
		ret = zvol_create_link(zhp->zfs_hdl, target);
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1793
diff changeset
  3471
	}
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1793
diff changeset
  3472
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1793
diff changeset
  3473
	return (ret);
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1793
diff changeset
  3474
}
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1793
diff changeset
  3475
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1793
diff changeset
  3476
typedef struct promote_data {
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1793
diff changeset
  3477
	char cb_mountpoint[MAXPATHLEN];
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1793
diff changeset
  3478
	const char *cb_target;
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1793
diff changeset
  3479
	const char *cb_errbuf;
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1793
diff changeset
  3480
	uint64_t cb_pivot_txg;
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1793
diff changeset
  3481
} promote_data_t;
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1793
diff changeset
  3482
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1793
diff changeset
  3483
static int
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1793
diff changeset
  3484
promote_snap_cb(zfs_handle_t *zhp, void *data)
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1793
diff changeset
  3485
{
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1793
diff changeset
  3486
	promote_data_t *pd = data;
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1793
diff changeset
  3487
	zfs_handle_t *szhp;
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1793
diff changeset
  3488
	char snapname[MAXPATHLEN];
3265
967e0fca6143 6463140 zfs recv with a snapshot name that has 2 @@ in a row succeeds
ahrens
parents: 3237
diff changeset
  3489
	int rv = 0;
2082
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1793
diff changeset
  3490
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1793
diff changeset
  3491
	/* We don't care about snapshots after the pivot point */
3265
967e0fca6143 6463140 zfs recv with a snapshot name that has 2 @@ in a row succeeds
ahrens
parents: 3237
diff changeset
  3492
	if (zfs_prop_get_int(zhp, ZFS_PROP_CREATETXG) > pd->cb_pivot_txg) {
967e0fca6143 6463140 zfs recv with a snapshot name that has 2 @@ in a row succeeds
ahrens
parents: 3237
diff changeset
  3493
		zfs_close(zhp);
2082
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1793
diff changeset
  3494
		return (0);
3265
967e0fca6143 6463140 zfs recv with a snapshot name that has 2 @@ in a row succeeds
ahrens
parents: 3237
diff changeset
  3495
	}
2082
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1793
diff changeset
  3496
2417
694d5de97348 6444346 zfs promote fails in zone
ahrens
parents: 2199
diff changeset
  3497
	/* Remove the device link if it's a zvol. */
2676
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  3498
	if (ZFS_IS_VOLUME(zhp))
2417
694d5de97348 6444346 zfs promote fails in zone
ahrens
parents: 2199
diff changeset
  3499
		(void) zvol_remove_link(zhp->zfs_hdl, zhp->zfs_name);
2082
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1793
diff changeset
  3500
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1793
diff changeset
  3501
	/* Check for conflicting names */
2676
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  3502
	(void) strlcpy(snapname, pd->cb_target, sizeof (snapname));
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  3503
	(void) strlcat(snapname, strchr(zhp->zfs_name, '@'), sizeof (snapname));
2082
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1793
diff changeset
  3504
	szhp = make_dataset_handle(zhp->zfs_hdl, snapname);
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1793
diff changeset
  3505
	if (szhp != NULL) {
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1793
diff changeset
  3506
		zfs_close(szhp);
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1793
diff changeset
  3507
		zfs_error_aux(zhp->zfs_hdl, dgettext(TEXT_DOMAIN,
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1793
diff changeset
  3508
		    "snapshot name '%s' from origin \n"
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1793
diff changeset
  3509
		    "conflicts with '%s' from target"),
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1793
diff changeset
  3510
		    zhp->zfs_name, snapname);
3265
967e0fca6143 6463140 zfs recv with a snapshot name that has 2 @@ in a row succeeds
ahrens
parents: 3237
diff changeset
  3511
		rv = zfs_error(zhp->zfs_hdl, EZFS_EXISTS, pd->cb_errbuf);
2082
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1793
diff changeset
  3512
	}
3265
967e0fca6143 6463140 zfs recv with a snapshot name that has 2 @@ in a row succeeds
ahrens
parents: 3237
diff changeset
  3513
	zfs_close(zhp);
967e0fca6143 6463140 zfs recv with a snapshot name that has 2 @@ in a row succeeds
ahrens
parents: 3237
diff changeset
  3514
	return (rv);
2082
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1793
diff changeset
  3515
}
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1793
diff changeset
  3516
2417
694d5de97348 6444346 zfs promote fails in zone
ahrens
parents: 2199
diff changeset
  3517
static int
694d5de97348 6444346 zfs promote fails in zone
ahrens
parents: 2199
diff changeset
  3518
promote_snap_done_cb(zfs_handle_t *zhp, void *data)
694d5de97348 6444346 zfs promote fails in zone
ahrens
parents: 2199
diff changeset
  3519
{
694d5de97348 6444346 zfs promote fails in zone
ahrens
parents: 2199
diff changeset
  3520
	promote_data_t *pd = data;
694d5de97348 6444346 zfs promote fails in zone
ahrens
parents: 2199
diff changeset
  3521
694d5de97348 6444346 zfs promote fails in zone
ahrens
parents: 2199
diff changeset
  3522
	/* We don't care about snapshots after the pivot point */
3265
967e0fca6143 6463140 zfs recv with a snapshot name that has 2 @@ in a row succeeds
ahrens
parents: 3237
diff changeset
  3523
	if (zfs_prop_get_int(zhp, ZFS_PROP_CREATETXG) <= pd->cb_pivot_txg) {
967e0fca6143 6463140 zfs recv with a snapshot name that has 2 @@ in a row succeeds
ahrens
parents: 3237
diff changeset
  3524
		/* Create the device link if it's a zvol. */
967e0fca6143 6463140 zfs recv with a snapshot name that has 2 @@ in a row succeeds
ahrens
parents: 3237
diff changeset
  3525
		if (ZFS_IS_VOLUME(zhp))
967e0fca6143 6463140 zfs recv with a snapshot name that has 2 @@ in a row succeeds
ahrens
parents: 3237
diff changeset
  3526
			(void) zvol_create_link(zhp->zfs_hdl, zhp->zfs_name);
967e0fca6143 6463140 zfs recv with a snapshot name that has 2 @@ in a row succeeds
ahrens
parents: 3237
diff changeset
  3527
	}
967e0fca6143 6463140 zfs recv with a snapshot name that has 2 @@ in a row succeeds
ahrens
parents: 3237
diff changeset
  3528
967e0fca6143 6463140 zfs recv with a snapshot name that has 2 @@ in a row succeeds
ahrens
parents: 3237
diff changeset
  3529
	zfs_close(zhp);
2417
694d5de97348 6444346 zfs promote fails in zone
ahrens
parents: 2199
diff changeset
  3530
	return (0);
694d5de97348 6444346 zfs promote fails in zone
ahrens
parents: 2199
diff changeset
  3531
}
694d5de97348 6444346 zfs promote fails in zone
ahrens
parents: 2199
diff changeset
  3532
2082
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1793
diff changeset
  3533
/*
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1793
diff changeset
  3534
 * Promotes the given clone fs to be the clone parent.
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1793
diff changeset
  3535
 */
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1793
diff changeset
  3536
int
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1793
diff changeset
  3537
zfs_promote(zfs_handle_t *zhp)
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1793
diff changeset
  3538
{
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1793
diff changeset
  3539
	libzfs_handle_t *hdl = zhp->zfs_hdl;
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1793
diff changeset
  3540
	zfs_cmd_t zc = { 0 };
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1793
diff changeset
  3541
	char parent[MAXPATHLEN];
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1793
diff changeset
  3542
	char *cp;
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1793
diff changeset
  3543
	int ret;
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1793
diff changeset
  3544
	zfs_handle_t *pzhp;
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1793
diff changeset
  3545
	promote_data_t pd;
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1793
diff changeset
  3546
	char errbuf[1024];
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1793
diff changeset
  3547
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1793
diff changeset
  3548
	(void) snprintf(errbuf, sizeof (errbuf), dgettext(TEXT_DOMAIN,
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1793
diff changeset
  3549
	    "cannot promote '%s'"), zhp->zfs_name);
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1793
diff changeset
  3550
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1793
diff changeset
  3551
	if (zhp->zfs_type == ZFS_TYPE_SNAPSHOT) {
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1793
diff changeset
  3552
		zfs_error_aux(hdl, dgettext(TEXT_DOMAIN,
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1793
diff changeset
  3553
		    "snapshots can not be promoted"));
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1793
diff changeset
  3554
		return (zfs_error(hdl, EZFS_BADTYPE, errbuf));
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1793
diff changeset
  3555
	}
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1793
diff changeset
  3556
5367
c40abbe796be PSARC/2007/574 zfs send -R
ahrens
parents: 5331
diff changeset
  3557
	(void) strlcpy(parent, zhp->zfs_dmustats.dds_origin, sizeof (parent));
2082
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1793
diff changeset
  3558
	if (parent[0] == '\0') {
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1793
diff changeset
  3559
		zfs_error_aux(hdl, dgettext(TEXT_DOMAIN,
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1793
diff changeset
  3560
		    "not a cloned filesystem"));
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1793
diff changeset
  3561
		return (zfs_error(hdl, EZFS_BADTYPE, errbuf));
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1793
diff changeset
  3562
	}
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1793
diff changeset
  3563
	cp = strchr(parent, '@');
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1793
diff changeset
  3564
	*cp = '\0';
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1793
diff changeset
  3565
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1793
diff changeset
  3566
	/* Walk the snapshots we will be moving */
5367
c40abbe796be PSARC/2007/574 zfs send -R
ahrens
parents: 5331
diff changeset
  3567
	pzhp = zfs_open(hdl, zhp->zfs_dmustats.dds_origin, ZFS_TYPE_SNAPSHOT);
2082
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1793
diff changeset
  3568
	if (pzhp == NULL)
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1793
diff changeset
  3569
		return (-1);
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1793
diff changeset
  3570
	pd.cb_pivot_txg = zfs_prop_get_int(pzhp, ZFS_PROP_CREATETXG);
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1793
diff changeset
  3571
	zfs_close(pzhp);
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1793
diff changeset
  3572
	pd.cb_target = zhp->zfs_name;
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1793
diff changeset
  3573
	pd.cb_errbuf = errbuf;
5094
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4861
diff changeset
  3574
	pzhp = zfs_open(hdl, parent, ZFS_TYPE_DATASET);
2082
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1793
diff changeset
  3575
	if (pzhp == NULL)
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1793
diff changeset
  3576
		return (-1);
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1793
diff changeset
  3577
	(void) zfs_prop_get(pzhp, ZFS_PROP_MOUNTPOINT, pd.cb_mountpoint,
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1793
diff changeset
  3578
	    sizeof (pd.cb_mountpoint), NULL, NULL, 0, FALSE);
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1793
diff changeset
  3579
	ret = zfs_iter_snapshots(pzhp, promote_snap_cb, &pd);
2417
694d5de97348 6444346 zfs promote fails in zone
ahrens
parents: 2199
diff changeset
  3580
	if (ret != 0) {
694d5de97348 6444346 zfs promote fails in zone
ahrens
parents: 2199
diff changeset
  3581
		zfs_close(pzhp);
2082
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1793
diff changeset
  3582
		return (-1);
2417
694d5de97348 6444346 zfs promote fails in zone
ahrens
parents: 2199
diff changeset
  3583
	}
2082
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1793
diff changeset
  3584
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1793
diff changeset
  3585
	/* issue the ioctl */
5367
c40abbe796be PSARC/2007/574 zfs send -R
ahrens
parents: 5331
diff changeset
  3586
	(void) strlcpy(zc.zc_value, zhp->zfs_dmustats.dds_origin,
2676
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  3587
	    sizeof (zc.zc_value));
2082
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1793
diff changeset
  3588
	(void) strlcpy(zc.zc_name, zhp->zfs_name, sizeof (zc.zc_name));
4543
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  3589
	ret = zfs_ioctl(hdl, ZFS_IOC_PROMOTE, &zc);
2082
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1793
diff changeset
  3590
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1793
diff changeset
  3591
	if (ret != 0) {
2417
694d5de97348 6444346 zfs promote fails in zone
ahrens
parents: 2199
diff changeset
  3592
		int save_errno = errno;
694d5de97348 6444346 zfs promote fails in zone
ahrens
parents: 2199
diff changeset
  3593
694d5de97348 6444346 zfs promote fails in zone
ahrens
parents: 2199
diff changeset
  3594
		(void) zfs_iter_snapshots(pzhp, promote_snap_done_cb, &pd);
694d5de97348 6444346 zfs promote fails in zone
ahrens
parents: 2199
diff changeset
  3595
		zfs_close(pzhp);
694d5de97348 6444346 zfs promote fails in zone
ahrens
parents: 2199
diff changeset
  3596
694d5de97348 6444346 zfs promote fails in zone
ahrens
parents: 2199
diff changeset
  3597
		switch (save_errno) {
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3598
		case EEXIST:
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3599
			/*
2082
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1793
diff changeset
  3600
			 * There is a conflicting snapshot name.  We
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1793
diff changeset
  3601
			 * should have caught this above, but they could
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1793
diff changeset
  3602
			 * have renamed something in the mean time.
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3603
			 */
2082
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1793
diff changeset
  3604
			zfs_error_aux(hdl, dgettext(TEXT_DOMAIN,
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1793
diff changeset
  3605
			    "conflicting snapshot name from parent '%s'"),
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1793
diff changeset
  3606
			    parent);
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1793
diff changeset
  3607
			return (zfs_error(hdl, EZFS_EXISTS, errbuf));
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3608
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3609
		default:
2417
694d5de97348 6444346 zfs promote fails in zone
ahrens
parents: 2199
diff changeset
  3610
			return (zfs_standard_error(hdl, save_errno, errbuf));
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3611
		}
2417
694d5de97348 6444346 zfs promote fails in zone
ahrens
parents: 2199
diff changeset
  3612
	} else {
694d5de97348 6444346 zfs promote fails in zone
ahrens
parents: 2199
diff changeset
  3613
		(void) zfs_iter_snapshots(zhp, promote_snap_done_cb, &pd);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3614
	}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3615
2417
694d5de97348 6444346 zfs promote fails in zone
ahrens
parents: 2199
diff changeset
  3616
	zfs_close(pzhp);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3617
	return (ret);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3618
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3619
4007
c6f5c6753018 PSARC 2007/142 zfs rename -r
mmusante
parents: 3912
diff changeset
  3620
struct createdata {
c6f5c6753018 PSARC 2007/142 zfs rename -r
mmusante
parents: 3912
diff changeset
  3621
	const char *cd_snapname;
c6f5c6753018 PSARC 2007/142 zfs rename -r
mmusante
parents: 3912
diff changeset
  3622
	int cd_ifexists;
c6f5c6753018 PSARC 2007/142 zfs rename -r
mmusante
parents: 3912
diff changeset
  3623
};
c6f5c6753018 PSARC 2007/142 zfs rename -r
mmusante
parents: 3912
diff changeset
  3624
2199
712a788c2dfd PSARC 2006/388 snapshot -r
ahrens
parents: 2169
diff changeset
  3625
static int
712a788c2dfd PSARC 2006/388 snapshot -r
ahrens
parents: 2169
diff changeset
  3626
zfs_create_link_cb(zfs_handle_t *zhp, void *arg)
712a788c2dfd PSARC 2006/388 snapshot -r
ahrens
parents: 2169
diff changeset
  3627
{
4007
c6f5c6753018 PSARC 2007/142 zfs rename -r
mmusante
parents: 3912
diff changeset
  3628
	struct createdata *cd = arg;
2676
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  3629
	int ret;
2199
712a788c2dfd PSARC 2006/388 snapshot -r
ahrens
parents: 2169
diff changeset
  3630
712a788c2dfd PSARC 2006/388 snapshot -r
ahrens
parents: 2169
diff changeset
  3631
	if (zhp->zfs_type == ZFS_TYPE_VOLUME) {
712a788c2dfd PSARC 2006/388 snapshot -r
ahrens
parents: 2169
diff changeset
  3632
		char name[MAXPATHLEN];
712a788c2dfd PSARC 2006/388 snapshot -r
ahrens
parents: 2169
diff changeset
  3633
2676
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  3634
		(void) strlcpy(name, zhp->zfs_name, sizeof (name));
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  3635
		(void) strlcat(name, "@", sizeof (name));
4007
c6f5c6753018 PSARC 2007/142 zfs rename -r
mmusante
parents: 3912
diff changeset
  3636
		(void) strlcat(name, cd->cd_snapname, sizeof (name));
c6f5c6753018 PSARC 2007/142 zfs rename -r
mmusante
parents: 3912
diff changeset
  3637
		(void) zvol_create_link_common(zhp->zfs_hdl, name,
c6f5c6753018 PSARC 2007/142 zfs rename -r
mmusante
parents: 3912
diff changeset
  3638
		    cd->cd_ifexists);
2199
712a788c2dfd PSARC 2006/388 snapshot -r
ahrens
parents: 2169
diff changeset
  3639
		/*
712a788c2dfd PSARC 2006/388 snapshot -r
ahrens
parents: 2169
diff changeset
  3640
		 * NB: this is simply a best-effort.  We don't want to
712a788c2dfd PSARC 2006/388 snapshot -r
ahrens
parents: 2169
diff changeset
  3641
		 * return an error, because then we wouldn't visit all
712a788c2dfd PSARC 2006/388 snapshot -r
ahrens
parents: 2169
diff changeset
  3642
		 * the volumes.
712a788c2dfd PSARC 2006/388 snapshot -r
ahrens
parents: 2169
diff changeset
  3643
		 */
712a788c2dfd PSARC 2006/388 snapshot -r
ahrens
parents: 2169
diff changeset
  3644
	}
2676
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  3645
4007
c6f5c6753018 PSARC 2007/142 zfs rename -r
mmusante
parents: 3912
diff changeset
  3646
	ret = zfs_iter_filesystems(zhp, zfs_create_link_cb, cd);
2676
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  3647
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  3648
	zfs_close(zhp);
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  3649
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  3650
	return (ret);
2199
712a788c2dfd PSARC 2006/388 snapshot -r
ahrens
parents: 2169
diff changeset
  3651
}
712a788c2dfd PSARC 2006/388 snapshot -r
ahrens
parents: 2169
diff changeset
  3652
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3653
/*
3504
6eb2466ff1c9 6516175 zfs_send()/zfs_receive() should take file descriptor arguments
ahl
parents: 3443
diff changeset
  3654
 * Takes a snapshot of the given dataset.
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3655
 */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3656
int
7265
cc18862247da PSARC/2008/483 ZFS clone -o
ahrens
parents: 7184
diff changeset
  3657
zfs_snapshot(libzfs_handle_t *hdl, const char *path, boolean_t recursive,
cc18862247da PSARC/2008/483 ZFS clone -o
ahrens
parents: 7184
diff changeset
  3658
    nvlist_t *props)
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3659
{
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3660
	const char *delim;
7265
cc18862247da PSARC/2008/483 ZFS clone -o
ahrens
parents: 7184
diff changeset
  3661
	char parent[ZFS_MAXNAMELEN];
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3662
	zfs_handle_t *zhp;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3663
	zfs_cmd_t zc = { 0 };
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3664
	int ret;
2082
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1793
diff changeset
  3665
	char errbuf[1024];
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1793
diff changeset
  3666
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1793
diff changeset
  3667
	(void) snprintf(errbuf, sizeof (errbuf), dgettext(TEXT_DOMAIN,
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1793
diff changeset
  3668
	    "cannot snapshot '%s'"), path);
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1793
diff changeset
  3669
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1793
diff changeset
  3670
	/* validate the target name */
5326
6752aa2bd5bc 6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents: 5147
diff changeset
  3671
	if (!zfs_validate_name(hdl, path, ZFS_TYPE_SNAPSHOT, B_TRUE))
2082
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1793
diff changeset
  3672
		return (zfs_error(hdl, EZFS_INVALIDNAME, errbuf));
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3673
7265
cc18862247da PSARC/2008/483 ZFS clone -o
ahrens
parents: 7184
diff changeset
  3674
	if (props) {
cc18862247da PSARC/2008/483 ZFS clone -o
ahrens
parents: 7184
diff changeset
  3675
		if ((props = zfs_valid_proplist(hdl, ZFS_TYPE_SNAPSHOT,
cc18862247da PSARC/2008/483 ZFS clone -o
ahrens
parents: 7184
diff changeset
  3676
		    props, B_FALSE, NULL, errbuf)) == NULL)
cc18862247da PSARC/2008/483 ZFS clone -o
ahrens
parents: 7184
diff changeset
  3677
			return (-1);
cc18862247da PSARC/2008/483 ZFS clone -o
ahrens
parents: 7184
diff changeset
  3678
cc18862247da PSARC/2008/483 ZFS clone -o
ahrens
parents: 7184
diff changeset
  3679
		if (zcmd_write_src_nvlist(hdl, &zc, props) != 0) {
cc18862247da PSARC/2008/483 ZFS clone -o
ahrens
parents: 7184
diff changeset
  3680
			nvlist_free(props);
cc18862247da PSARC/2008/483 ZFS clone -o
ahrens
parents: 7184
diff changeset
  3681
			return (-1);
cc18862247da PSARC/2008/483 ZFS clone -o
ahrens
parents: 7184
diff changeset
  3682
		}
cc18862247da PSARC/2008/483 ZFS clone -o
ahrens
parents: 7184
diff changeset
  3683
cc18862247da PSARC/2008/483 ZFS clone -o
ahrens
parents: 7184
diff changeset
  3684
		nvlist_free(props);
cc18862247da PSARC/2008/483 ZFS clone -o
ahrens
parents: 7184
diff changeset
  3685
	}
cc18862247da PSARC/2008/483 ZFS clone -o
ahrens
parents: 7184
diff changeset
  3686
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3687
	/* make sure the parent exists and is of the appropriate type */
2199
712a788c2dfd PSARC 2006/388 snapshot -r
ahrens
parents: 2169
diff changeset
  3688
	delim = strchr(path, '@');
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3689
	(void) strncpy(parent, path, delim - path);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3690
	parent[delim - path] = '\0';
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3691
2082
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1793
diff changeset
  3692
	if ((zhp = zfs_open(hdl, parent, ZFS_TYPE_FILESYSTEM |
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3693
	    ZFS_TYPE_VOLUME)) == NULL) {
7265
cc18862247da PSARC/2008/483 ZFS clone -o
ahrens
parents: 7184
diff changeset
  3694
		zcmd_free_nvlists(&zc);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3695
		return (-1);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3696
	}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3697
2199
712a788c2dfd PSARC 2006/388 snapshot -r
ahrens
parents: 2169
diff changeset
  3698
	(void) strlcpy(zc.zc_name, zhp->zfs_name, sizeof (zc.zc_name));
2676
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  3699
	(void) strlcpy(zc.zc_value, delim+1, sizeof (zc.zc_value));
4543
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  3700
	if (ZFS_IS_VOLUME(zhp))
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  3701
		zc.zc_objset_type = DMU_OST_ZVOL;
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  3702
	else
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  3703
		zc.zc_objset_type = DMU_OST_ZFS;
2199
712a788c2dfd PSARC 2006/388 snapshot -r
ahrens
parents: 2169
diff changeset
  3704
	zc.zc_cookie = recursive;
4543
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  3705
	ret = zfs_ioctl(zhp->zfs_hdl, ZFS_IOC_SNAPSHOT, &zc);
2199
712a788c2dfd PSARC 2006/388 snapshot -r
ahrens
parents: 2169
diff changeset
  3706
7265
cc18862247da PSARC/2008/483 ZFS clone -o
ahrens
parents: 7184
diff changeset
  3707
	zcmd_free_nvlists(&zc);
cc18862247da PSARC/2008/483 ZFS clone -o
ahrens
parents: 7184
diff changeset
  3708
2199
712a788c2dfd PSARC 2006/388 snapshot -r
ahrens
parents: 2169
diff changeset
  3709
	/*
712a788c2dfd PSARC 2006/388 snapshot -r
ahrens
parents: 2169
diff changeset
  3710
	 * if it was recursive, the one that actually failed will be in
712a788c2dfd PSARC 2006/388 snapshot -r
ahrens
parents: 2169
diff changeset
  3711
	 * zc.zc_name.
712a788c2dfd PSARC 2006/388 snapshot -r
ahrens
parents: 2169
diff changeset
  3712
	 */
4543
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  3713
	if (ret != 0)
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  3714
		(void) snprintf(errbuf, sizeof (errbuf), dgettext(TEXT_DOMAIN,
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  3715
		    "cannot create snapshot '%s@%s'"), zc.zc_name, zc.zc_value);
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  3716
2199
712a788c2dfd PSARC 2006/388 snapshot -r
ahrens
parents: 2169
diff changeset
  3717
	if (ret == 0 && recursive) {
4007
c6f5c6753018 PSARC 2007/142 zfs rename -r
mmusante
parents: 3912
diff changeset
  3718
		struct createdata cd;
c6f5c6753018 PSARC 2007/142 zfs rename -r
mmusante
parents: 3912
diff changeset
  3719
c6f5c6753018 PSARC 2007/142 zfs rename -r
mmusante
parents: 3912
diff changeset
  3720
		cd.cd_snapname = delim + 1;
c6f5c6753018 PSARC 2007/142 zfs rename -r
mmusante
parents: 3912
diff changeset
  3721
		cd.cd_ifexists = B_FALSE;
c6f5c6753018 PSARC 2007/142 zfs rename -r
mmusante
parents: 3912
diff changeset
  3722
		(void) zfs_iter_filesystems(zhp, zfs_create_link_cb, &cd);
2199
712a788c2dfd PSARC 2006/388 snapshot -r
ahrens
parents: 2169
diff changeset
  3723
	}
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3724
	if (ret == 0 && zhp->zfs_type == ZFS_TYPE_VOLUME) {
2082
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1793
diff changeset
  3725
		ret = zvol_create_link(zhp->zfs_hdl, path);
2199
712a788c2dfd PSARC 2006/388 snapshot -r
ahrens
parents: 2169
diff changeset
  3726
		if (ret != 0) {
4543
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  3727
			(void) zfs_standard_error(hdl, errno,
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  3728
			    dgettext(TEXT_DOMAIN,
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  3729
			    "Volume successfully snapshotted, but device links "
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  3730
			    "were not created"));
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  3731
			zfs_close(zhp);
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  3732
			return (-1);
2199
712a788c2dfd PSARC 2006/388 snapshot -r
ahrens
parents: 2169
diff changeset
  3733
		}
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3734
	}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3735
2082
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1793
diff changeset
  3736
	if (ret != 0)
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1793
diff changeset
  3737
		(void) zfs_standard_error(hdl, errno, errbuf);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3738
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3739
	zfs_close(zhp);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3740
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3741
	return (ret);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3742
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3743
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3744
/*
1294
87b43e5de5ee 6364129 need to unmount any child datasets before doing the rollback
lling
parents: 1175
diff changeset
  3745
 * Destroy any more recent snapshots.  We invoke this callback on any dependents
87b43e5de5ee 6364129 need to unmount any child datasets before doing the rollback
lling
parents: 1175
diff changeset
  3746
 * of the snapshot first.  If the 'cb_dependent' member is non-zero, then this
87b43e5de5ee 6364129 need to unmount any child datasets before doing the rollback
lling
parents: 1175
diff changeset
  3747
 * is a dependent and we should just destroy it without checking the transaction
87b43e5de5ee 6364129 need to unmount any child datasets before doing the rollback
lling
parents: 1175
diff changeset
  3748
 * group.
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3749
 */
1294
87b43e5de5ee 6364129 need to unmount any child datasets before doing the rollback
lling
parents: 1175
diff changeset
  3750
typedef struct rollback_data {
87b43e5de5ee 6364129 need to unmount any child datasets before doing the rollback
lling
parents: 1175
diff changeset
  3751
	const char	*cb_target;		/* the snapshot */
87b43e5de5ee 6364129 need to unmount any child datasets before doing the rollback
lling
parents: 1175
diff changeset
  3752
	uint64_t	cb_create;		/* creation time reference */
5749
78a7afaea267 PSARC/2007/699 zfs rollback -f operative
ahrens
parents: 5717
diff changeset
  3753
	boolean_t	cb_error;
2082
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1793
diff changeset
  3754
	boolean_t	cb_dependent;
5749
78a7afaea267 PSARC/2007/699 zfs rollback -f operative
ahrens
parents: 5717
diff changeset
  3755
	boolean_t	cb_force;
1294
87b43e5de5ee 6364129 need to unmount any child datasets before doing the rollback
lling
parents: 1175
diff changeset
  3756
} rollback_data_t;
87b43e5de5ee 6364129 need to unmount any child datasets before doing the rollback
lling
parents: 1175
diff changeset
  3757
87b43e5de5ee 6364129 need to unmount any child datasets before doing the rollback
lling
parents: 1175
diff changeset
  3758
static int
87b43e5de5ee 6364129 need to unmount any child datasets before doing the rollback
lling
parents: 1175
diff changeset
  3759
rollback_destroy(zfs_handle_t *zhp, void *data)
87b43e5de5ee 6364129 need to unmount any child datasets before doing the rollback
lling
parents: 1175
diff changeset
  3760
{
87b43e5de5ee 6364129 need to unmount any child datasets before doing the rollback
lling
parents: 1175
diff changeset
  3761
	rollback_data_t *cbp = data;
87b43e5de5ee 6364129 need to unmount any child datasets before doing the rollback
lling
parents: 1175
diff changeset
  3762
87b43e5de5ee 6364129 need to unmount any child datasets before doing the rollback
lling
parents: 1175
diff changeset
  3763
	if (!cbp->cb_dependent) {
87b43e5de5ee 6364129 need to unmount any child datasets before doing the rollback
lling
parents: 1175
diff changeset
  3764
		if (strcmp(zhp->zfs_name, cbp->cb_target) != 0 &&
87b43e5de5ee 6364129 need to unmount any child datasets before doing the rollback
lling
parents: 1175
diff changeset
  3765
		    zfs_get_type(zhp) == ZFS_TYPE_SNAPSHOT &&
87b43e5de5ee 6364129 need to unmount any child datasets before doing the rollback
lling
parents: 1175
diff changeset
  3766
		    zfs_prop_get_int(zhp, ZFS_PROP_CREATETXG) >
87b43e5de5ee 6364129 need to unmount any child datasets before doing the rollback
lling
parents: 1175
diff changeset
  3767
		    cbp->cb_create) {
4543
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  3768
			char *logstr;
1294
87b43e5de5ee 6364129 need to unmount any child datasets before doing the rollback
lling
parents: 1175
diff changeset
  3769
2082
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1793
diff changeset
  3770
			cbp->cb_dependent = B_TRUE;
5446
51fbc14b301d 6421210 zfs rollback without unmounting
ahrens
parents: 5378
diff changeset
  3771
			cbp->cb_error |= zfs_iter_dependents(zhp, B_FALSE,
51fbc14b301d 6421210 zfs rollback without unmounting
ahrens
parents: 5378
diff changeset
  3772
			    rollback_destroy, cbp);
2082
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1793
diff changeset
  3773
			cbp->cb_dependent = B_FALSE;
1294
87b43e5de5ee 6364129 need to unmount any child datasets before doing the rollback
lling
parents: 1175
diff changeset
  3774
4543
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  3775
			logstr = zhp->zfs_hdl->libzfs_log_str;
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  3776
			zhp->zfs_hdl->libzfs_log_str = NULL;
5446
51fbc14b301d 6421210 zfs rollback without unmounting
ahrens
parents: 5378
diff changeset
  3777
			cbp->cb_error |= zfs_destroy(zhp);
4543
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  3778
			zhp->zfs_hdl->libzfs_log_str = logstr;
1294
87b43e5de5ee 6364129 need to unmount any child datasets before doing the rollback
lling
parents: 1175
diff changeset
  3779
		}
87b43e5de5ee 6364129 need to unmount any child datasets before doing the rollback
lling
parents: 1175
diff changeset
  3780
	} else {
5749
78a7afaea267 PSARC/2007/699 zfs rollback -f operative
ahrens
parents: 5717
diff changeset
  3781
		/* We must destroy this clone; first unmount it */
78a7afaea267 PSARC/2007/699 zfs rollback -f operative
ahrens
parents: 5717
diff changeset
  3782
		prop_changelist_t *clp;
78a7afaea267 PSARC/2007/699 zfs rollback -f operative
ahrens
parents: 5717
diff changeset
  3783
7366
33de5956afbb 6678308 zfs receive dumps core when -n is used, fails on replication stream
Tim Haley <Tim.Haley@Sun.COM>
parents: 7301
diff changeset
  3784
		clp = changelist_gather(zhp, ZFS_PROP_NAME, 0,
5749
78a7afaea267 PSARC/2007/699 zfs rollback -f operative
ahrens
parents: 5717
diff changeset
  3785
		    cbp->cb_force ? MS_FORCE: 0);
78a7afaea267 PSARC/2007/699 zfs rollback -f operative
ahrens
parents: 5717
diff changeset
  3786
		if (clp == NULL || changelist_prefix(clp) != 0) {
78a7afaea267 PSARC/2007/699 zfs rollback -f operative
ahrens
parents: 5717
diff changeset
  3787
			cbp->cb_error = B_TRUE;
78a7afaea267 PSARC/2007/699 zfs rollback -f operative
ahrens
parents: 5717
diff changeset
  3788
			zfs_close(zhp);
78a7afaea267 PSARC/2007/699 zfs rollback -f operative
ahrens
parents: 5717
diff changeset
  3789
			return (0);
78a7afaea267 PSARC/2007/699 zfs rollback -f operative
ahrens
parents: 5717
diff changeset
  3790
		}
78a7afaea267 PSARC/2007/699 zfs rollback -f operative
ahrens
parents: 5717
diff changeset
  3791
		if (zfs_destroy(zhp) != 0)
78a7afaea267 PSARC/2007/699 zfs rollback -f operative
ahrens
parents: 5717
diff changeset
  3792
			cbp->cb_error = B_TRUE;
78a7afaea267 PSARC/2007/699 zfs rollback -f operative
ahrens
parents: 5717
diff changeset
  3793
		else
78a7afaea267 PSARC/2007/699 zfs rollback -f operative
ahrens
parents: 5717
diff changeset
  3794
			changelist_remove(clp, zhp->zfs_name);
5751
86c712b1b536 6641210 zfs rollback -R fails with EBUSY if there is a clone (fix lint)
ahrens
parents: 5749
diff changeset
  3795
		(void) changelist_postfix(clp);
5749
78a7afaea267 PSARC/2007/699 zfs rollback -f operative
ahrens
parents: 5717
diff changeset
  3796
		changelist_free(clp);
1294
87b43e5de5ee 6364129 need to unmount any child datasets before doing the rollback
lling
parents: 1175
diff changeset
  3797
	}
87b43e5de5ee 6364129 need to unmount any child datasets before doing the rollback
lling
parents: 1175
diff changeset
  3798
87b43e5de5ee 6364129 need to unmount any child datasets before doing the rollback
lling
parents: 1175
diff changeset
  3799
	zfs_close(zhp);
87b43e5de5ee 6364129 need to unmount any child datasets before doing the rollback
lling
parents: 1175
diff changeset
  3800
	return (0);
87b43e5de5ee 6364129 need to unmount any child datasets before doing the rollback
lling
parents: 1175
diff changeset
  3801
}
87b43e5de5ee 6364129 need to unmount any child datasets before doing the rollback
lling
parents: 1175
diff changeset
  3802
87b43e5de5ee 6364129 need to unmount any child datasets before doing the rollback
lling
parents: 1175
diff changeset
  3803
/*
5446
51fbc14b301d 6421210 zfs rollback without unmounting
ahrens
parents: 5378
diff changeset
  3804
 * Given a dataset, rollback to a specific snapshot, discarding any
51fbc14b301d 6421210 zfs rollback without unmounting
ahrens
parents: 5378
diff changeset
  3805
 * data changes since then and making it the active dataset.
51fbc14b301d 6421210 zfs rollback without unmounting
ahrens
parents: 5378
diff changeset
  3806
 *
51fbc14b301d 6421210 zfs rollback without unmounting
ahrens
parents: 5378
diff changeset
  3807
 * Any snapshots more recent than the target are destroyed, along with
51fbc14b301d 6421210 zfs rollback without unmounting
ahrens
parents: 5378
diff changeset
  3808
 * their dependents.
1294
87b43e5de5ee 6364129 need to unmount any child datasets before doing the rollback
lling
parents: 1175
diff changeset
  3809
 */
5446
51fbc14b301d 6421210 zfs rollback without unmounting
ahrens
parents: 5378
diff changeset
  3810
int
5749
78a7afaea267 PSARC/2007/699 zfs rollback -f operative
ahrens
parents: 5717
diff changeset
  3811
zfs_rollback(zfs_handle_t *zhp, zfs_handle_t *snap, boolean_t force)
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3812
{
5446
51fbc14b301d 6421210 zfs rollback without unmounting
ahrens
parents: 5378
diff changeset
  3813
	rollback_data_t cb = { 0 };
51fbc14b301d 6421210 zfs rollback without unmounting
ahrens
parents: 5378
diff changeset
  3814
	int err;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3815
	zfs_cmd_t zc = { 0 };
5713
f9b7933f3770 PSARC/2007/675 A_MDEV Removal
rm160521
parents: 5592
diff changeset
  3816
	boolean_t restore_resv = 0;
f9b7933f3770 PSARC/2007/675 A_MDEV Removal
rm160521
parents: 5592
diff changeset
  3817
	uint64_t old_volsize, new_volsize;
f9b7933f3770 PSARC/2007/675 A_MDEV Removal
rm160521
parents: 5592
diff changeset
  3818
	zfs_prop_t resv_prop;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3819
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3820
	assert(zhp->zfs_type == ZFS_TYPE_FILESYSTEM ||
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3821
	    zhp->zfs_type == ZFS_TYPE_VOLUME);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3822
5446
51fbc14b301d 6421210 zfs rollback without unmounting
ahrens
parents: 5378
diff changeset
  3823
	/*
51fbc14b301d 6421210 zfs rollback without unmounting
ahrens
parents: 5378
diff changeset
  3824
	 * Destroy all recent snapshots and its dependends.
51fbc14b301d 6421210 zfs rollback without unmounting
ahrens
parents: 5378
diff changeset
  3825
	 */
5749
78a7afaea267 PSARC/2007/699 zfs rollback -f operative
ahrens
parents: 5717
diff changeset
  3826
	cb.cb_force = force;
5446
51fbc14b301d 6421210 zfs rollback without unmounting
ahrens
parents: 5378
diff changeset
  3827
	cb.cb_target = snap->zfs_name;
51fbc14b301d 6421210 zfs rollback without unmounting
ahrens
parents: 5378
diff changeset
  3828
	cb.cb_create = zfs_prop_get_int(snap, ZFS_PROP_CREATETXG);
51fbc14b301d 6421210 zfs rollback without unmounting
ahrens
parents: 5378
diff changeset
  3829
	(void) zfs_iter_children(zhp, rollback_destroy, &cb);
51fbc14b301d 6421210 zfs rollback without unmounting
ahrens
parents: 5378
diff changeset
  3830
5749
78a7afaea267 PSARC/2007/699 zfs rollback -f operative
ahrens
parents: 5717
diff changeset
  3831
	if (cb.cb_error)
78a7afaea267 PSARC/2007/699 zfs rollback -f operative
ahrens
parents: 5717
diff changeset
  3832
		return (-1);
5446
51fbc14b301d 6421210 zfs rollback without unmounting
ahrens
parents: 5378
diff changeset
  3833
51fbc14b301d 6421210 zfs rollback without unmounting
ahrens
parents: 5378
diff changeset
  3834
	/*
51fbc14b301d 6421210 zfs rollback without unmounting
ahrens
parents: 5378
diff changeset
  3835
	 * Now that we have verified that the snapshot is the latest,
51fbc14b301d 6421210 zfs rollback without unmounting
ahrens
parents: 5378
diff changeset
  3836
	 * rollback to the given snapshot.
51fbc14b301d 6421210 zfs rollback without unmounting
ahrens
parents: 5378
diff changeset
  3837
	 */
51fbc14b301d 6421210 zfs rollback without unmounting
ahrens
parents: 5378
diff changeset
  3838
5713
f9b7933f3770 PSARC/2007/675 A_MDEV Removal
rm160521
parents: 5592
diff changeset
  3839
	if (zhp->zfs_type == ZFS_TYPE_VOLUME) {
f9b7933f3770 PSARC/2007/675 A_MDEV Removal
rm160521
parents: 5592
diff changeset
  3840
		if (zvol_remove_link(zhp->zfs_hdl, zhp->zfs_name) != 0)
f9b7933f3770 PSARC/2007/675 A_MDEV Removal
rm160521
parents: 5592
diff changeset
  3841
			return (-1);
f9b7933f3770 PSARC/2007/675 A_MDEV Removal
rm160521
parents: 5592
diff changeset
  3842
		if (zfs_which_resv_prop(zhp, &resv_prop) < 0)
f9b7933f3770 PSARC/2007/675 A_MDEV Removal
rm160521
parents: 5592
diff changeset
  3843
			return (-1);
f9b7933f3770 PSARC/2007/675 A_MDEV Removal
rm160521
parents: 5592
diff changeset
  3844
		old_volsize = zfs_prop_get_int(zhp, ZFS_PROP_VOLSIZE);
f9b7933f3770 PSARC/2007/675 A_MDEV Removal
rm160521
parents: 5592
diff changeset
  3845
		restore_resv =
f9b7933f3770 PSARC/2007/675 A_MDEV Removal
rm160521
parents: 5592
diff changeset
  3846
		    (old_volsize == zfs_prop_get_int(zhp, resv_prop));
f9b7933f3770 PSARC/2007/675 A_MDEV Removal
rm160521
parents: 5592
diff changeset
  3847
	}
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3848
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3849
	(void) strlcpy(zc.zc_name, zhp->zfs_name, sizeof (zc.zc_name));
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3850
2676
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  3851
	if (ZFS_IS_VOLUME(zhp))
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3852
		zc.zc_objset_type = DMU_OST_ZVOL;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3853
	else
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3854
		zc.zc_objset_type = DMU_OST_ZFS;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3855
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3856
	/*
5446
51fbc14b301d 6421210 zfs rollback without unmounting
ahrens
parents: 5378
diff changeset
  3857
	 * We rely on zfs_iter_children() to verify that there are no
51fbc14b301d 6421210 zfs rollback without unmounting
ahrens
parents: 5378
diff changeset
  3858
	 * newer snapshots for the given dataset.  Therefore, we can
51fbc14b301d 6421210 zfs rollback without unmounting
ahrens
parents: 5378
diff changeset
  3859
	 * simply pass the name on to the ioctl() call.  There is still
51fbc14b301d 6421210 zfs rollback without unmounting
ahrens
parents: 5378
diff changeset
  3860
	 * an unlikely race condition where the user has taken a
51fbc14b301d 6421210 zfs rollback without unmounting
ahrens
parents: 5378
diff changeset
  3861
	 * snapshot since we verified that this was the most recent.
5713
f9b7933f3770 PSARC/2007/675 A_MDEV Removal
rm160521
parents: 5592
diff changeset
  3862
	 *
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3863
	 */
5446
51fbc14b301d 6421210 zfs rollback without unmounting
ahrens
parents: 5378
diff changeset
  3864
	if ((err = zfs_ioctl(zhp->zfs_hdl, ZFS_IOC_ROLLBACK, &zc)) != 0) {
3237
98d0c28f2f5e 6480245 renaming a dataset to something with '%s' will cause segfault
lling
parents: 3234
diff changeset
  3865
		(void) zfs_standard_error_fmt(zhp->zfs_hdl, errno,
2082
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1793
diff changeset
  3866
		    dgettext(TEXT_DOMAIN, "cannot rollback '%s'"),
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1793
diff changeset
  3867
		    zhp->zfs_name);
5717
b163be0bb014 6419176 'zfs rollback <volume@snap>' does not lower reservation (fix lint)
rm160521
parents: 5713
diff changeset
  3868
		return (err);
b163be0bb014 6419176 'zfs rollback <volume@snap>' does not lower reservation (fix lint)
rm160521
parents: 5713
diff changeset
  3869
	}
5713
f9b7933f3770 PSARC/2007/675 A_MDEV Removal
rm160521
parents: 5592
diff changeset
  3870
f9b7933f3770 PSARC/2007/675 A_MDEV Removal
rm160521
parents: 5592
diff changeset
  3871
	/*
f9b7933f3770 PSARC/2007/675 A_MDEV Removal
rm160521
parents: 5592
diff changeset
  3872
	 * For volumes, if the pre-rollback volsize matched the pre-
f9b7933f3770 PSARC/2007/675 A_MDEV Removal
rm160521
parents: 5592
diff changeset
  3873
	 * rollback reservation and the volsize has changed then set
f9b7933f3770 PSARC/2007/675 A_MDEV Removal
rm160521
parents: 5592
diff changeset
  3874
	 * the reservation property to the post-rollback volsize.
f9b7933f3770 PSARC/2007/675 A_MDEV Removal
rm160521
parents: 5592
diff changeset
  3875
	 * Make a new handle since the rollback closed the dataset.
f9b7933f3770 PSARC/2007/675 A_MDEV Removal
rm160521
parents: 5592
diff changeset
  3876
	 */
5717
b163be0bb014 6419176 'zfs rollback <volume@snap>' does not lower reservation (fix lint)
rm160521
parents: 5713
diff changeset
  3877
	if ((zhp->zfs_type == ZFS_TYPE_VOLUME) &&
b163be0bb014 6419176 'zfs rollback <volume@snap>' does not lower reservation (fix lint)
rm160521
parents: 5713
diff changeset
  3878
	    (zhp = make_dataset_handle(zhp->zfs_hdl, zhp->zfs_name))) {
b163be0bb014 6419176 'zfs rollback <volume@snap>' does not lower reservation (fix lint)
rm160521
parents: 5713
diff changeset
  3879
		if (err = zvol_create_link(zhp->zfs_hdl, zhp->zfs_name)) {
b163be0bb014 6419176 'zfs rollback <volume@snap>' does not lower reservation (fix lint)
rm160521
parents: 5713
diff changeset
  3880
			zfs_close(zhp);
5713
f9b7933f3770 PSARC/2007/675 A_MDEV Removal
rm160521
parents: 5592
diff changeset
  3881
			return (err);
5717
b163be0bb014 6419176 'zfs rollback <volume@snap>' does not lower reservation (fix lint)
rm160521
parents: 5713
diff changeset
  3882
		}
5713
f9b7933f3770 PSARC/2007/675 A_MDEV Removal
rm160521
parents: 5592
diff changeset
  3883
		if (restore_resv) {
f9b7933f3770 PSARC/2007/675 A_MDEV Removal
rm160521
parents: 5592
diff changeset
  3884
			new_volsize = zfs_prop_get_int(zhp, ZFS_PROP_VOLSIZE);
f9b7933f3770 PSARC/2007/675 A_MDEV Removal
rm160521
parents: 5592
diff changeset
  3885
			if (old_volsize != new_volsize)
5717
b163be0bb014 6419176 'zfs rollback <volume@snap>' does not lower reservation (fix lint)
rm160521
parents: 5713
diff changeset
  3886
				err = zfs_prop_set_int(zhp, resv_prop,
b163be0bb014 6419176 'zfs rollback <volume@snap>' does not lower reservation (fix lint)
rm160521
parents: 5713
diff changeset
  3887
				    new_volsize);
5713
f9b7933f3770 PSARC/2007/675 A_MDEV Removal
rm160521
parents: 5592
diff changeset
  3888
		}
f9b7933f3770 PSARC/2007/675 A_MDEV Removal
rm160521
parents: 5592
diff changeset
  3889
		zfs_close(zhp);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3890
	}
5446
51fbc14b301d 6421210 zfs rollback without unmounting
ahrens
parents: 5378
diff changeset
  3891
	return (err);
1294
87b43e5de5ee 6364129 need to unmount any child datasets before doing the rollback
lling
parents: 1175
diff changeset
  3892
}
87b43e5de5ee 6364129 need to unmount any child datasets before doing the rollback
lling
parents: 1175
diff changeset
  3893
87b43e5de5ee 6364129 need to unmount any child datasets before doing the rollback
lling
parents: 1175
diff changeset
  3894
/*
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3895
 * Iterate over all dependents for a given dataset.  This includes both
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3896
 * hierarchical dependents (children) and data dependents (snapshots and
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3897
 * clones).  The bulk of the processing occurs in get_dependents() in
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3898
 * libzfs_graph.c.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3899
 */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3900
int
2474
c001ad7e0c25 6368751 libzfs interface for mount/umounting all the file systems for a given pool
eschrock
parents: 2440
diff changeset
  3901
zfs_iter_dependents(zfs_handle_t *zhp, boolean_t allowrecursion,
c001ad7e0c25 6368751 libzfs interface for mount/umounting all the file systems for a given pool
eschrock
parents: 2440
diff changeset
  3902
    zfs_iter_f func, void *data)
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3903
{
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3904
	char **dependents;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3905
	size_t count;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3906
	int i;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3907
	zfs_handle_t *child;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3908
	int ret = 0;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3909
2474
c001ad7e0c25 6368751 libzfs interface for mount/umounting all the file systems for a given pool
eschrock
parents: 2440
diff changeset
  3910
	if (get_dependents(zhp->zfs_hdl, allowrecursion, zhp->zfs_name,
c001ad7e0c25 6368751 libzfs interface for mount/umounting all the file systems for a given pool
eschrock
parents: 2440
diff changeset
  3911
	    &dependents, &count) != 0)
c001ad7e0c25 6368751 libzfs interface for mount/umounting all the file systems for a given pool
eschrock
parents: 2440
diff changeset
  3912
		return (-1);
c001ad7e0c25 6368751 libzfs interface for mount/umounting all the file systems for a given pool
eschrock
parents: 2440
diff changeset
  3913
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3914
	for (i = 0; i < count; i++) {
2082
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1793
diff changeset
  3915
		if ((child = make_dataset_handle(zhp->zfs_hdl,
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1793
diff changeset
  3916
		    dependents[i])) == NULL)
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3917
			continue;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3918
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3919
		if ((ret = func(child, data)) != 0)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3920
			break;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3921
	}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3922
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3923
	for (i = 0; i < count; i++)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3924
		free(dependents[i]);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3925
	free(dependents);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3926
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3927
	return (ret);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3928
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3929
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3930
/*
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3931
 * Renames the given dataset.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3932
 */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3933
int
4490
abf035049f7f PSARC 2007/199 zfs {create,clone,rename} -p
vb160487
parents: 4451
diff changeset
  3934
zfs_rename(zfs_handle_t *zhp, const char *target, boolean_t recursive)
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3935
{
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3936
	int ret;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3937
	zfs_cmd_t zc = { 0 };
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3938
	char *delim;
4007
c6f5c6753018 PSARC 2007/142 zfs rename -r
mmusante
parents: 3912
diff changeset
  3939
	prop_changelist_t *cl = NULL;
c6f5c6753018 PSARC 2007/142 zfs rename -r
mmusante
parents: 3912
diff changeset
  3940
	zfs_handle_t *zhrp = NULL;
c6f5c6753018 PSARC 2007/142 zfs rename -r
mmusante
parents: 3912
diff changeset
  3941
	char *parentname = NULL;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3942
	char parent[ZFS_MAXNAMELEN];
2082
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1793
diff changeset
  3943
	libzfs_handle_t *hdl = zhp->zfs_hdl;
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1793
diff changeset
  3944
	char errbuf[1024];
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3945
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3946
	/* if we have the same exact name, just return success */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3947
	if (strcmp(zhp->zfs_name, target) == 0)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3948
		return (0);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3949
2082
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1793
diff changeset
  3950
	(void) snprintf(errbuf, sizeof (errbuf), dgettext(TEXT_DOMAIN,
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1793
diff changeset
  3951
	    "cannot rename to '%s'"), target);
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1793
diff changeset
  3952
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3953
	/*
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3954
	 * Make sure the target name is valid
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3955
	 */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3956
	if (zhp->zfs_type == ZFS_TYPE_SNAPSHOT) {
2665
7b208a92357b PSARC 2006/479 zfs receive -F
nd150628
parents: 2474
diff changeset
  3957
		if ((strchr(target, '@') == NULL) ||
7b208a92357b PSARC 2006/479 zfs receive -F
nd150628
parents: 2474
diff changeset
  3958
		    *target == '@') {
7b208a92357b PSARC 2006/479 zfs receive -F
nd150628
parents: 2474
diff changeset
  3959
			/*
7b208a92357b PSARC 2006/479 zfs receive -F
nd150628
parents: 2474
diff changeset
  3960
			 * Snapshot target name is abbreviated,
7b208a92357b PSARC 2006/479 zfs receive -F
nd150628
parents: 2474
diff changeset
  3961
			 * reconstruct full dataset name
7b208a92357b PSARC 2006/479 zfs receive -F
nd150628
parents: 2474
diff changeset
  3962
			 */
7b208a92357b PSARC 2006/479 zfs receive -F
nd150628
parents: 2474
diff changeset
  3963
			(void) strlcpy(parent, zhp->zfs_name,
7b208a92357b PSARC 2006/479 zfs receive -F
nd150628
parents: 2474
diff changeset
  3964
			    sizeof (parent));
7b208a92357b PSARC 2006/479 zfs receive -F
nd150628
parents: 2474
diff changeset
  3965
			delim = strchr(parent, '@');
7b208a92357b PSARC 2006/479 zfs receive -F
nd150628
parents: 2474
diff changeset
  3966
			if (strchr(target, '@') == NULL)
7b208a92357b PSARC 2006/479 zfs receive -F
nd150628
parents: 2474
diff changeset
  3967
				*(++delim) = '\0';
7b208a92357b PSARC 2006/479 zfs receive -F
nd150628
parents: 2474
diff changeset
  3968
			else
7b208a92357b PSARC 2006/479 zfs receive -F
nd150628
parents: 2474
diff changeset
  3969
				*delim = '\0';
7b208a92357b PSARC 2006/479 zfs receive -F
nd150628
parents: 2474
diff changeset
  3970
			(void) strlcat(parent, target, sizeof (parent));
7b208a92357b PSARC 2006/479 zfs receive -F
nd150628
parents: 2474
diff changeset
  3971
			target = parent;
7b208a92357b PSARC 2006/479 zfs receive -F
nd150628
parents: 2474
diff changeset
  3972
		} else {
7b208a92357b PSARC 2006/479 zfs receive -F
nd150628
parents: 2474
diff changeset
  3973
			/*
7b208a92357b PSARC 2006/479 zfs receive -F
nd150628
parents: 2474
diff changeset
  3974
			 * Make sure we're renaming within the same dataset.
7b208a92357b PSARC 2006/479 zfs receive -F
nd150628
parents: 2474
diff changeset
  3975
			 */
7b208a92357b PSARC 2006/479 zfs receive -F
nd150628
parents: 2474
diff changeset
  3976
			delim = strchr(target, '@');
7b208a92357b PSARC 2006/479 zfs receive -F
nd150628
parents: 2474
diff changeset
  3977
			if (strncmp(zhp->zfs_name, target, delim - target)
7b208a92357b PSARC 2006/479 zfs receive -F
nd150628
parents: 2474
diff changeset
  3978
			    != 0 || zhp->zfs_name[delim - target] != '@') {
7b208a92357b PSARC 2006/479 zfs receive -F
nd150628
parents: 2474
diff changeset
  3979
				zfs_error_aux(hdl, dgettext(TEXT_DOMAIN,
7b208a92357b PSARC 2006/479 zfs receive -F
nd150628
parents: 2474
diff changeset
  3980
				    "snapshots must be part of same "
7b208a92357b PSARC 2006/479 zfs receive -F
nd150628
parents: 2474
diff changeset
  3981
				    "dataset"));
7b208a92357b PSARC 2006/479 zfs receive -F
nd150628
parents: 2474
diff changeset
  3982
				return (zfs_error(hdl, EZFS_CROSSTARGET,
3912
f6891a60bd72 PSARC 2007/083 ZFS bootable datasets
lling
parents: 3886
diff changeset
  3983
				    errbuf));
2665
7b208a92357b PSARC 2006/479 zfs receive -F
nd150628
parents: 2474
diff changeset
  3984
			}
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3985
		}
5326
6752aa2bd5bc 6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents: 5147
diff changeset
  3986
		if (!zfs_validate_name(hdl, target, zhp->zfs_type, B_TRUE))
2665
7b208a92357b PSARC 2006/479 zfs receive -F
nd150628
parents: 2474
diff changeset
  3987
			return (zfs_error(hdl, EZFS_INVALIDNAME, errbuf));
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3988
	} else {
4007
c6f5c6753018 PSARC 2007/142 zfs rename -r
mmusante
parents: 3912
diff changeset
  3989
		if (recursive) {
c6f5c6753018 PSARC 2007/142 zfs rename -r
mmusante
parents: 3912
diff changeset
  3990
			zfs_error_aux(hdl, dgettext(TEXT_DOMAIN,
c6f5c6753018 PSARC 2007/142 zfs rename -r
mmusante
parents: 3912
diff changeset
  3991
			    "recursive rename must be a snapshot"));
c6f5c6753018 PSARC 2007/142 zfs rename -r
mmusante
parents: 3912
diff changeset
  3992
			return (zfs_error(hdl, EZFS_BADTYPE, errbuf));
c6f5c6753018 PSARC 2007/142 zfs rename -r
mmusante
parents: 3912
diff changeset
  3993
		}
c6f5c6753018 PSARC 2007/142 zfs rename -r
mmusante
parents: 3912
diff changeset
  3994
5326
6752aa2bd5bc 6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents: 5147
diff changeset
  3995
		if (!zfs_validate_name(hdl, target, zhp->zfs_type, B_TRUE))
2665
7b208a92357b PSARC 2006/479 zfs receive -F
nd150628
parents: 2474
diff changeset
  3996
			return (zfs_error(hdl, EZFS_INVALIDNAME, errbuf));
2676
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  3997
		uint64_t unused;
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  3998
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3999
		/* validate parents */
4490
abf035049f7f PSARC 2007/199 zfs {create,clone,rename} -p
vb160487
parents: 4451
diff changeset
  4000
		if (check_parents(hdl, target, &unused, B_FALSE, NULL) != 0)
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  4001
			return (-1);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  4002
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  4003
		(void) parent_name(target, parent, sizeof (parent));
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  4004
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  4005
		/* make sure we're in the same pool */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  4006
		verify((delim = strchr(target, '/')) != NULL);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  4007
		if (strncmp(zhp->zfs_name, target, delim - target) != 0 ||
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  4008
		    zhp->zfs_name[delim - target] != '/') {
2082
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1793
diff changeset
  4009
			zfs_error_aux(hdl, dgettext(TEXT_DOMAIN,
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1793
diff changeset
  4010
			    "datasets must be within same pool"));
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1793
diff changeset
  4011
			return (zfs_error(hdl, EZFS_CROSSTARGET, errbuf));
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  4012
		}
2440
9281a87e8a9e 6451860 zfs rename' a filesystem|clone to its direct child will cause internal error
nd150628
parents: 2417
diff changeset
  4013
9281a87e8a9e 6451860 zfs rename' a filesystem|clone to its direct child will cause internal error
nd150628
parents: 2417
diff changeset
  4014
		/* new name cannot be a child of the current dataset name */
9281a87e8a9e 6451860 zfs rename' a filesystem|clone to its direct child will cause internal error
nd150628
parents: 2417
diff changeset
  4015
		if (strncmp(parent, zhp->zfs_name,
3912
f6891a60bd72 PSARC 2007/083 ZFS bootable datasets
lling
parents: 3886
diff changeset
  4016
		    strlen(zhp->zfs_name)) == 0) {
2440
9281a87e8a9e 6451860 zfs rename' a filesystem|clone to its direct child will cause internal error
nd150628
parents: 2417
diff changeset
  4017
			zfs_error_aux(hdl, dgettext(TEXT_DOMAIN,
9281a87e8a9e 6451860 zfs rename' a filesystem|clone to its direct child will cause internal error
nd150628
parents: 2417
diff changeset
  4018
			    "New dataset name cannot be a descendent of "
9281a87e8a9e 6451860 zfs rename' a filesystem|clone to its direct child will cause internal error
nd150628
parents: 2417
diff changeset
  4019
			    "current dataset name"));
9281a87e8a9e 6451860 zfs rename' a filesystem|clone to its direct child will cause internal error
nd150628
parents: 2417
diff changeset
  4020
			return (zfs_error(hdl, EZFS_INVALIDNAME, errbuf));
9281a87e8a9e 6451860 zfs rename' a filesystem|clone to its direct child will cause internal error
nd150628
parents: 2417
diff changeset
  4021
		}
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  4022
	}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  4023
2082
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1793
diff changeset
  4024
	(void) snprintf(errbuf, sizeof (errbuf),
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1793
diff changeset
  4025
	    dgettext(TEXT_DOMAIN, "cannot rename '%s'"), zhp->zfs_name);
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1793
diff changeset
  4026
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  4027
	if (getzoneid() == GLOBAL_ZONEID &&
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  4028
	    zfs_prop_get_int(zhp, ZFS_PROP_ZONED)) {
2082
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1793
diff changeset
  4029
		zfs_error_aux(hdl, dgettext(TEXT_DOMAIN,
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1793
diff changeset
  4030
		    "dataset is used in a non-global zone"));
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1793
diff changeset
  4031
		return (zfs_error(hdl, EZFS_ZONED, errbuf));
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  4032
	}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  4033
4007
c6f5c6753018 PSARC 2007/142 zfs rename -r
mmusante
parents: 3912
diff changeset
  4034
	if (recursive) {
c6f5c6753018 PSARC 2007/142 zfs rename -r
mmusante
parents: 3912
diff changeset
  4035
		struct destroydata dd;
c6f5c6753018 PSARC 2007/142 zfs rename -r
mmusante
parents: 3912
diff changeset
  4036
4183
8dbff10731ef 6550857 recursive rename leaks memory and segfaults on failure
mmusante
parents: 4180
diff changeset
  4037
		parentname = zfs_strdup(zhp->zfs_hdl, zhp->zfs_name);
8dbff10731ef 6550857 recursive rename leaks memory and segfaults on failure
mmusante
parents: 4180
diff changeset
  4038
		if (parentname == NULL) {
8dbff10731ef 6550857 recursive rename leaks memory and segfaults on failure
mmusante
parents: 4180
diff changeset
  4039
			ret = -1;
8dbff10731ef 6550857 recursive rename leaks memory and segfaults on failure
mmusante
parents: 4180
diff changeset
  4040
			goto error;
8dbff10731ef 6550857 recursive rename leaks memory and segfaults on failure
mmusante
parents: 4180
diff changeset
  4041
		}
4007
c6f5c6753018 PSARC 2007/142 zfs rename -r
mmusante
parents: 3912
diff changeset
  4042
		delim = strchr(parentname, '@');
c6f5c6753018 PSARC 2007/142 zfs rename -r
mmusante
parents: 3912
diff changeset
  4043
		*delim = '\0';
5094
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4861
diff changeset
  4044
		zhrp = zfs_open(zhp->zfs_hdl, parentname, ZFS_TYPE_DATASET);
4007
c6f5c6753018 PSARC 2007/142 zfs rename -r
mmusante
parents: 3912
diff changeset
  4045
		if (zhrp == NULL) {
4183
8dbff10731ef 6550857 recursive rename leaks memory and segfaults on failure
mmusante
parents: 4180
diff changeset
  4046
			ret = -1;
8dbff10731ef 6550857 recursive rename leaks memory and segfaults on failure
mmusante
parents: 4180
diff changeset
  4047
			goto error;
4007
c6f5c6753018 PSARC 2007/142 zfs rename -r
mmusante
parents: 3912
diff changeset
  4048
		}
c6f5c6753018 PSARC 2007/142 zfs rename -r
mmusante
parents: 3912
diff changeset
  4049
c6f5c6753018 PSARC 2007/142 zfs rename -r
mmusante
parents: 3912
diff changeset
  4050
		dd.snapname = delim + 1;
c6f5c6753018 PSARC 2007/142 zfs rename -r
mmusante
parents: 3912
diff changeset
  4051
		dd.gotone = B_FALSE;
4183
8dbff10731ef 6550857 recursive rename leaks memory and segfaults on failure
mmusante
parents: 4180
diff changeset
  4052
		dd.closezhp = B_TRUE;
4007
c6f5c6753018 PSARC 2007/142 zfs rename -r
mmusante
parents: 3912
diff changeset
  4053
c6f5c6753018 PSARC 2007/142 zfs rename -r
mmusante
parents: 3912
diff changeset
  4054
		/* We remove any zvol links prior to renaming them */
c6f5c6753018 PSARC 2007/142 zfs rename -r
mmusante
parents: 3912
diff changeset
  4055
		ret = zfs_iter_filesystems(zhrp, zfs_remove_link_cb, &dd);
c6f5c6753018 PSARC 2007/142 zfs rename -r
mmusante
parents: 3912
diff changeset
  4056
		if (ret) {
c6f5c6753018 PSARC 2007/142 zfs rename -r
mmusante
parents: 3912
diff changeset
  4057
			goto error;
c6f5c6753018 PSARC 2007/142 zfs rename -r
mmusante
parents: 3912
diff changeset
  4058
		}
c6f5c6753018 PSARC 2007/142 zfs rename -r
mmusante
parents: 3912
diff changeset
  4059
	} else {
7366
33de5956afbb 6678308 zfs receive dumps core when -n is used, fails on replication stream
Tim Haley <Tim.Haley@Sun.COM>
parents: 7301
diff changeset
  4060
		if ((cl = changelist_gather(zhp, ZFS_PROP_NAME, 0, 0)) == NULL)
4007
c6f5c6753018 PSARC 2007/142 zfs rename -r
mmusante
parents: 3912
diff changeset
  4061
			return (-1);
c6f5c6753018 PSARC 2007/142 zfs rename -r
mmusante
parents: 3912
diff changeset
  4062
c6f5c6753018 PSARC 2007/142 zfs rename -r
mmusante
parents: 3912
diff changeset
  4063
		if (changelist_haszonedchild(cl)) {
c6f5c6753018 PSARC 2007/142 zfs rename -r
mmusante
parents: 3912
diff changeset
  4064
			zfs_error_aux(hdl, dgettext(TEXT_DOMAIN,
c6f5c6753018 PSARC 2007/142 zfs rename -r
mmusante
parents: 3912
diff changeset
  4065
			    "child dataset with inherited mountpoint is used "
c6f5c6753018 PSARC 2007/142 zfs rename -r
mmusante
parents: 3912
diff changeset
  4066
			    "in a non-global zone"));
c6f5c6753018 PSARC 2007/142 zfs rename -r
mmusante
parents: 3912
diff changeset
  4067
			(void) zfs_error(hdl, EZFS_ZONED, errbuf);
c6f5c6753018 PSARC 2007/142 zfs rename -r
mmusante
parents: 3912
diff changeset
  4068
			goto error;
c6f5c6753018 PSARC 2007/142 zfs rename -r
mmusante
parents: 3912
diff changeset
  4069
		}
c6f5c6753018 PSARC 2007/142 zfs rename -r
mmusante
parents: 3912
diff changeset
  4070
c6f5c6753018 PSARC 2007/142 zfs rename -r
mmusante
parents: 3912
diff changeset
  4071
		if ((ret = changelist_prefix(cl)) != 0)
c6f5c6753018 PSARC 2007/142 zfs rename -r
mmusante
parents: 3912
diff changeset
  4072
			goto error;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  4073
	}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  4074
2676
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  4075
	if (ZFS_IS_VOLUME(zhp))
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  4076
		zc.zc_objset_type = DMU_OST_ZVOL;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  4077
	else
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  4078
		zc.zc_objset_type = DMU_OST_ZFS;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  4079
2665
7b208a92357b PSARC 2006/479 zfs receive -F
nd150628
parents: 2474
diff changeset
  4080
	(void) strlcpy(zc.zc_name, zhp->zfs_name, sizeof (zc.zc_name));
2676
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  4081
	(void) strlcpy(zc.zc_value, target, sizeof (zc.zc_value));
2665
7b208a92357b PSARC 2006/479 zfs receive -F
nd150628
parents: 2474
diff changeset
  4082
4007
c6f5c6753018 PSARC 2007/142 zfs rename -r
mmusante
parents: 3912
diff changeset
  4083
	zc.zc_cookie = recursive;
c6f5c6753018 PSARC 2007/142 zfs rename -r
mmusante
parents: 3912
diff changeset
  4084
4543
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  4085
	if ((ret = zfs_ioctl(zhp->zfs_hdl, ZFS_IOC_RENAME, &zc)) != 0) {
4007
c6f5c6753018 PSARC 2007/142 zfs rename -r
mmusante
parents: 3912
diff changeset
  4086
		/*
c6f5c6753018 PSARC 2007/142 zfs rename -r
mmusante
parents: 3912
diff changeset
  4087
		 * if it was recursive, the one that actually failed will
c6f5c6753018 PSARC 2007/142 zfs rename -r
mmusante
parents: 3912
diff changeset
  4088
		 * be in zc.zc_name
c6f5c6753018 PSARC 2007/142 zfs rename -r
mmusante
parents: 3912
diff changeset
  4089
		 */
c6f5c6753018 PSARC 2007/142 zfs rename -r
mmusante
parents: 3912
diff changeset
  4090
		(void) snprintf(errbuf, sizeof (errbuf), dgettext(TEXT_DOMAIN,
5367
c40abbe796be PSARC/2007/574 zfs send -R
ahrens
parents: 5331
diff changeset
  4091
		    "cannot rename '%s'"), zc.zc_name);
4007
c6f5c6753018 PSARC 2007/142 zfs rename -r
mmusante
parents: 3912
diff changeset
  4092
c6f5c6753018 PSARC 2007/142 zfs rename -r
mmusante
parents: 3912
diff changeset
  4093
		if (recursive && errno == EEXIST) {
c6f5c6753018 PSARC 2007/142 zfs rename -r
mmusante
parents: 3912
diff changeset
  4094
			zfs_error_aux(hdl, dgettext(TEXT_DOMAIN,
c6f5c6753018 PSARC 2007/142 zfs rename -r
mmusante
parents: 3912
diff changeset
  4095
			    "a child dataset already has a snapshot "
c6f5c6753018 PSARC 2007/142 zfs rename -r
mmusante
parents: 3912
diff changeset
  4096
			    "with the new name"));
4801
5cd7916484a5 4687827 dumpadm should be more tolerant of a read-only /etc/dumpadm.conf
eschrock
parents: 4787
diff changeset
  4097
			(void) zfs_error(hdl, EZFS_EXISTS, errbuf);
4007
c6f5c6753018 PSARC 2007/142 zfs rename -r
mmusante
parents: 3912
diff changeset
  4098
		} else {
c6f5c6753018 PSARC 2007/142 zfs rename -r
mmusante
parents: 3912
diff changeset
  4099
			(void) zfs_standard_error(zhp->zfs_hdl, errno, errbuf);
c6f5c6753018 PSARC 2007/142 zfs rename -r
mmusante
parents: 3912
diff changeset
  4100
		}
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  4101
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  4102
		/*
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  4103
		 * On failure, we still want to remount any filesystems that
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  4104
		 * were previously mounted, so we don't alter the system state.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  4105
		 */
4007
c6f5c6753018 PSARC 2007/142 zfs rename -r
mmusante
parents: 3912
diff changeset
  4106
		if (recursive) {
c6f5c6753018 PSARC 2007/142 zfs rename -r
mmusante
parents: 3912
diff changeset
  4107
			struct createdata cd;
c6f5c6753018 PSARC 2007/142 zfs rename -r
mmusante
parents: 3912
diff changeset
  4108
c6f5c6753018 PSARC 2007/142 zfs rename -r
mmusante
parents: 3912
diff changeset
  4109
			/* only create links for datasets that had existed */
c6f5c6753018 PSARC 2007/142 zfs rename -r
mmusante
parents: 3912
diff changeset
  4110
			cd.cd_snapname = delim + 1;
c6f5c6753018 PSARC 2007/142 zfs rename -r
mmusante
parents: 3912
diff changeset
  4111
			cd.cd_ifexists = B_TRUE;
c6f5c6753018 PSARC 2007/142 zfs rename -r
mmusante
parents: 3912
diff changeset
  4112
			(void) zfs_iter_filesystems(zhrp, zfs_create_link_cb,
c6f5c6753018 PSARC 2007/142 zfs rename -r
mmusante
parents: 3912
diff changeset
  4113
			    &cd);
c6f5c6753018 PSARC 2007/142 zfs rename -r
mmusante
parents: 3912
diff changeset
  4114
		} else {
c6f5c6753018 PSARC 2007/142 zfs rename -r
mmusante
parents: 3912
diff changeset
  4115
			(void) changelist_postfix(cl);
c6f5c6753018 PSARC 2007/142 zfs rename -r
mmusante
parents: 3912
diff changeset
  4116
		}
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  4117
	} else {
4007
c6f5c6753018 PSARC 2007/142 zfs rename -r
mmusante
parents: 3912
diff changeset
  4118
		if (recursive) {
c6f5c6753018 PSARC 2007/142 zfs rename -r
mmusante
parents: 3912
diff changeset
  4119
			struct createdata cd;
c6f5c6753018 PSARC 2007/142 zfs rename -r
mmusante
parents: 3912
diff changeset
  4120
c6f5c6753018 PSARC 2007/142 zfs rename -r
mmusante
parents: 3912
diff changeset
  4121
			/* only create links for datasets that had existed */
c6f5c6753018 PSARC 2007/142 zfs rename -r
mmusante
parents: 3912
diff changeset
  4122
			cd.cd_snapname = strchr(target, '@') + 1;
c6f5c6753018 PSARC 2007/142 zfs rename -r
mmusante
parents: 3912
diff changeset
  4123
			cd.cd_ifexists = B_TRUE;
c6f5c6753018 PSARC 2007/142 zfs rename -r
mmusante
parents: 3912
diff changeset
  4124
			ret = zfs_iter_filesystems(zhrp, zfs_create_link_cb,
c6f5c6753018 PSARC 2007/142 zfs rename -r
mmusante
parents: 3912
diff changeset
  4125
			    &cd);
c6f5c6753018 PSARC 2007/142 zfs rename -r
mmusante
parents: 3912
diff changeset
  4126
		} else {
c6f5c6753018 PSARC 2007/142 zfs rename -r
mmusante
parents: 3912
diff changeset
  4127
			changelist_rename(cl, zfs_get_name(zhp), target);
c6f5c6753018 PSARC 2007/142 zfs rename -r
mmusante
parents: 3912
diff changeset
  4128
			ret = changelist_postfix(cl);
c6f5c6753018 PSARC 2007/142 zfs rename -r
mmusante
parents: 3912
diff changeset
  4129
		}
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  4130
	}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  4131
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  4132
error:
4007
c6f5c6753018 PSARC 2007/142 zfs rename -r
mmusante
parents: 3912
diff changeset
  4133
	if (parentname) {
c6f5c6753018 PSARC 2007/142 zfs rename -r
mmusante
parents: 3912
diff changeset
  4134
		free(parentname);
c6f5c6753018 PSARC 2007/142 zfs rename -r
mmusante
parents: 3912
diff changeset
  4135
	}
c6f5c6753018 PSARC 2007/142 zfs rename -r
mmusante
parents: 3912
diff changeset
  4136
	if (zhrp) {
c6f5c6753018 PSARC 2007/142 zfs rename -r
mmusante
parents: 3912
diff changeset
  4137
		zfs_close(zhrp);
c6f5c6753018 PSARC 2007/142 zfs rename -r
mmusante
parents: 3912
diff changeset
  4138
	}
c6f5c6753018 PSARC 2007/142 zfs rename -r
mmusante
parents: 3912
diff changeset
  4139
	if (cl) {
c6f5c6753018 PSARC 2007/142 zfs rename -r
mmusante
parents: 3912
diff changeset
  4140
		changelist_free(cl);
c6f5c6753018 PSARC 2007/142 zfs rename -r
mmusante
parents: 3912
diff changeset
  4141
	}
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  4142
	return (ret);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  4143
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  4144
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  4145
/*
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  4146
 * Given a zvol dataset, issue the ioctl to create the appropriate minor node,
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  4147
 * poke devfsadm to create the /dev link, and then wait for the link to appear.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  4148
 */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  4149
int
2082
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1793
diff changeset
  4150
zvol_create_link(libzfs_handle_t *hdl, const char *dataset)
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  4151
{
4007
c6f5c6753018 PSARC 2007/142 zfs rename -r
mmusante
parents: 3912
diff changeset
  4152
	return (zvol_create_link_common(hdl, dataset, B_FALSE));
c6f5c6753018 PSARC 2007/142 zfs rename -r
mmusante
parents: 3912
diff changeset
  4153
}
c6f5c6753018 PSARC 2007/142 zfs rename -r
mmusante
parents: 3912
diff changeset
  4154
c6f5c6753018 PSARC 2007/142 zfs rename -r
mmusante
parents: 3912
diff changeset
  4155
static int
c6f5c6753018 PSARC 2007/142 zfs rename -r
mmusante
parents: 3912
diff changeset
  4156
zvol_create_link_common(libzfs_handle_t *hdl, const char *dataset, int ifexists)
c6f5c6753018 PSARC 2007/142 zfs rename -r
mmusante
parents: 3912
diff changeset
  4157
{
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  4158
	zfs_cmd_t zc = { 0 };
2082
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1793
diff changeset
  4159
	di_devlink_handle_t dhdl;
4543
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  4160
	priv_set_t *priv_effective;
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  4161
	int privileged;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  4162
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  4163
	(void) strlcpy(zc.zc_name, dataset, sizeof (zc.zc_name));
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  4164
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  4165
	/*
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  4166
	 * Issue the appropriate ioctl.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  4167
	 */
2082
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1793
diff changeset
  4168
	if (ioctl(hdl->libzfs_fd, ZFS_IOC_CREATE_MINOR, &zc) != 0) {
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  4169
		switch (errno) {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  4170
		case EEXIST:
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  4171
			/*
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  4172
			 * Silently ignore the case where the link already
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  4173
			 * exists.  This allows 'zfs volinit' to be run multiple
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  4174
			 * times without errors.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  4175
			 */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  4176
			return (0);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  4177
4007
c6f5c6753018 PSARC 2007/142 zfs rename -r
mmusante
parents: 3912
diff changeset
  4178
		case ENOENT:
c6f5c6753018 PSARC 2007/142 zfs rename -r
mmusante
parents: 3912
diff changeset
  4179
			/*
c6f5c6753018 PSARC 2007/142 zfs rename -r
mmusante
parents: 3912
diff changeset
  4180
			 * Dataset does not exist in the kernel.  If we
c6f5c6753018 PSARC 2007/142 zfs rename -r
mmusante
parents: 3912
diff changeset
  4181
			 * don't care (see zfs_rename), then ignore the
c6f5c6753018 PSARC 2007/142 zfs rename -r
mmusante
parents: 3912
diff changeset
  4182
			 * error quietly.
c6f5c6753018 PSARC 2007/142 zfs rename -r
mmusante
parents: 3912
diff changeset
  4183
			 */
c6f5c6753018 PSARC 2007/142 zfs rename -r
mmusante
parents: 3912
diff changeset
  4184
			if (ifexists) {
c6f5c6753018 PSARC 2007/142 zfs rename -r
mmusante
parents: 3912
diff changeset
  4185
				return (0);
c6f5c6753018 PSARC 2007/142 zfs rename -r
mmusante
parents: 3912
diff changeset
  4186
			}
c6f5c6753018 PSARC 2007/142 zfs rename -r
mmusante
parents: 3912
diff changeset
  4187
c6f5c6753018 PSARC 2007/142 zfs rename -r
mmusante
parents: 3912
diff changeset
  4188
			/* FALLTHROUGH */
c6f5c6753018 PSARC 2007/142 zfs rename -r
mmusante
parents: 3912
diff changeset
  4189
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  4190
		default:
3237
98d0c28f2f5e 6480245 renaming a dataset to something with '%s' will cause segfault
lling
parents: 3234
diff changeset
  4191
			return (zfs_standard_error_fmt(hdl, errno,
2082
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1793
diff changeset
  4192
			    dgettext(TEXT_DOMAIN, "cannot create device links "
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1793
diff changeset
  4193
			    "for '%s'"), dataset));
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  4194
		}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  4195
	}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  4196
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  4197
	/*
4543
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  4198
	 * If privileged call devfsadm and wait for the links to
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  4199
	 * magically appear.
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  4200
	 * Otherwise, print out an informational message.
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  4201
	 */
4543
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  4202
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  4203
	priv_effective = priv_allocset();
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  4204
	(void) getppriv(PRIV_EFFECTIVE, priv_effective);
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  4205
	privileged = (priv_isfullset(priv_effective) == B_TRUE);
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  4206
	priv_freeset(priv_effective);
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  4207
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  4208
	if (privileged) {
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  4209
		if ((dhdl = di_devlink_init(ZFS_DRIVER,
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  4210
		    DI_MAKE_LINK)) == NULL) {
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  4211
			zfs_error_aux(hdl, strerror(errno));
7301
fc54ebb42916 6667976 support booting up a snapshot root dataset (fix lint)
Eric Taylor <Eric.Taylor@Sun.COM>
parents: 7300
diff changeset
  4212
			(void) zfs_error_fmt(hdl, errno,
4543
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  4213
			    dgettext(TEXT_DOMAIN, "cannot create device links "
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  4214
			    "for '%s'"), dataset);
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  4215
			(void) ioctl(hdl->libzfs_fd, ZFS_IOC_REMOVE_MINOR, &zc);
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  4216
			return (-1);
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  4217
		} else {
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  4218
			(void) di_devlink_fini(&dhdl);
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  4219
		}
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  4220
	} else {
4543
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  4221
		char pathname[MAXPATHLEN];
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  4222
		struct stat64 statbuf;
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  4223
		int i;
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  4224
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  4225
#define	MAX_WAIT	10
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  4226
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  4227
		/*
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  4228
		 * This is the poor mans way of waiting for the link
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  4229
		 * to show up.  If after 10 seconds we still don't
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  4230
		 * have it, then print out a message.
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  4231
		 */
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  4232
		(void) snprintf(pathname, sizeof (pathname), "/dev/zvol/dsk/%s",
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  4233
		    dataset);
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  4234
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  4235
		for (i = 0; i != MAX_WAIT; i++) {
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  4236
			if (stat64(pathname, &statbuf) == 0)
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  4237
				break;
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  4238
			(void) sleep(1);
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  4239
		}
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  4240
		if (i == MAX_WAIT)
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  4241
			(void) printf(gettext("%s may not be immediately "
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  4242
			    "available\n"), pathname);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  4243
	}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  4244
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  4245
	return (0);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  4246
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  4247
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  4248
/*
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  4249
 * Remove a minor node for the given zvol and the associated /dev links.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  4250
 */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  4251
int
2082
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1793
diff changeset
  4252
zvol_remove_link(libzfs_handle_t *hdl, const char *dataset)
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  4253
{
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  4254
	zfs_cmd_t zc = { 0 };
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  4255
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  4256
	(void) strlcpy(zc.zc_name, dataset, sizeof (zc.zc_name));
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  4257
2082
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1793
diff changeset
  4258
	if (ioctl(hdl->libzfs_fd, ZFS_IOC_REMOVE_MINOR, &zc) != 0) {
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  4259
		switch (errno) {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  4260
		case ENXIO:
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  4261
			/*
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  4262
			 * Silently ignore the case where the link no longer
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  4263
			 * exists, so that 'zfs volfini' can be run multiple
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  4264
			 * times without errors.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  4265
			 */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  4266
			return (0);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  4267
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  4268
		default:
3237
98d0c28f2f5e 6480245 renaming a dataset to something with '%s' will cause segfault
lling
parents: 3234
diff changeset
  4269
			return (zfs_standard_error_fmt(hdl, errno,
2082
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1793
diff changeset
  4270
			    dgettext(TEXT_DOMAIN, "cannot remove device "
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1793
diff changeset
  4271
			    "links for '%s'"), dataset));
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  4272
		}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  4273
	}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  4274
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  4275
	return (0);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  4276
}
2676
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  4277
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  4278
nvlist_t *
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  4279
zfs_get_user_props(zfs_handle_t *zhp)
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  4280
{
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  4281
	return (zhp->zfs_user_props);
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  4282
}
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  4283
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  4284
/*
3912
f6891a60bd72 PSARC 2007/083 ZFS bootable datasets
lling
parents: 3886
diff changeset
  4285
 * This function is used by 'zfs list' to determine the exact set of columns to
f6891a60bd72 PSARC 2007/083 ZFS bootable datasets
lling
parents: 3886
diff changeset
  4286
 * display, and their maximum widths.  This does two main things:
f6891a60bd72 PSARC 2007/083 ZFS bootable datasets
lling
parents: 3886
diff changeset
  4287
 *
f6891a60bd72 PSARC 2007/083 ZFS bootable datasets
lling
parents: 3886
diff changeset
  4288
 *      - If this is a list of all properties, then expand the list to include
f6891a60bd72 PSARC 2007/083 ZFS bootable datasets
lling
parents: 3886
diff changeset
  4289
 *        all native properties, and set a flag so that for each dataset we look
f6891a60bd72 PSARC 2007/083 ZFS bootable datasets
lling
parents: 3886
diff changeset
  4290
 *        for new unique user properties and add them to the list.
f6891a60bd72 PSARC 2007/083 ZFS bootable datasets
lling
parents: 3886
diff changeset
  4291
 *
f6891a60bd72 PSARC 2007/083 ZFS bootable datasets
lling
parents: 3886
diff changeset
  4292
 *      - For non fixed-width properties, keep track of the maximum width seen
f6891a60bd72 PSARC 2007/083 ZFS bootable datasets
lling
parents: 3886
diff changeset
  4293
 *        so that we can size the column appropriately.
f6891a60bd72 PSARC 2007/083 ZFS bootable datasets
lling
parents: 3886
diff changeset
  4294
 */
f6891a60bd72 PSARC 2007/083 ZFS bootable datasets
lling
parents: 3886
diff changeset
  4295
int
5094
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4861
diff changeset
  4296
zfs_expand_proplist(zfs_handle_t *zhp, zprop_list_t **plp)
3912
f6891a60bd72 PSARC 2007/083 ZFS bootable datasets
lling
parents: 3886
diff changeset
  4297
{
f6891a60bd72 PSARC 2007/083 ZFS bootable datasets
lling
parents: 3886
diff changeset
  4298
	libzfs_handle_t *hdl = zhp->zfs_hdl;
5094
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4861
diff changeset
  4299
	zprop_list_t *entry;
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4861
diff changeset
  4300
	zprop_list_t **last, **start;
3912
f6891a60bd72 PSARC 2007/083 ZFS bootable datasets
lling
parents: 3886
diff changeset
  4301
	nvlist_t *userprops, *propval;
f6891a60bd72 PSARC 2007/083 ZFS bootable datasets
lling
parents: 3886
diff changeset
  4302
	nvpair_t *elem;
f6891a60bd72 PSARC 2007/083 ZFS bootable datasets
lling
parents: 3886
diff changeset
  4303
	char *strval;
f6891a60bd72 PSARC 2007/083 ZFS bootable datasets
lling
parents: 3886
diff changeset
  4304
	char buf[ZFS_MAXPROPLEN];
f6891a60bd72 PSARC 2007/083 ZFS bootable datasets
lling
parents: 3886
diff changeset
  4305
5094
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4861
diff changeset
  4306
	if (zprop_expand_list(hdl, plp, ZFS_TYPE_DATASET) != 0)
3912
f6891a60bd72 PSARC 2007/083 ZFS bootable datasets
lling
parents: 3886
diff changeset
  4307
		return (-1);
2676
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  4308
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  4309
	userprops = zfs_get_user_props(zhp);
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  4310
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  4311
	entry = *plp;
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  4312
	if (entry->pl_all && nvlist_next_nvpair(userprops, NULL) != NULL) {
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  4313
		/*
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  4314
		 * Go through and add any user properties as necessary.  We
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  4315
		 * start by incrementing our list pointer to the first
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  4316
		 * non-native property.
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  4317
		 */
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  4318
		start = plp;
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  4319
		while (*start != NULL) {
5094
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4861
diff changeset
  4320
			if ((*start)->pl_prop == ZPROP_INVAL)
2676
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  4321
				break;
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  4322
			start = &(*start)->pl_next;
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  4323
		}
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  4324
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  4325
		elem = NULL;
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  4326
		while ((elem = nvlist_next_nvpair(userprops, elem)) != NULL) {
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  4327
			/*
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  4328
			 * See if we've already found this property in our list.
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  4329
			 */
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  4330
			for (last = start; *last != NULL;
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  4331
			    last = &(*last)->pl_next) {
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  4332
				if (strcmp((*last)->pl_user_prop,
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  4333
				    nvpair_name(elem)) == 0)
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  4334
					break;
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  4335
			}
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  4336
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  4337
			if (*last == NULL) {
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  4338
				if ((entry = zfs_alloc(hdl,
5094
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4861
diff changeset
  4339
				    sizeof (zprop_list_t))) == NULL ||
2676
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  4340
				    ((entry->pl_user_prop = zfs_strdup(hdl,
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  4341
				    nvpair_name(elem)))) == NULL) {
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  4342
					free(entry);
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  4343
					return (-1);
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  4344
				}
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  4345
5094
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4861
diff changeset
  4346
				entry->pl_prop = ZPROP_INVAL;
2676
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  4347
				entry->pl_width = strlen(nvpair_name(elem));
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  4348
				entry->pl_all = B_TRUE;
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  4349
				*last = entry;
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  4350
			}
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  4351
		}
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  4352
	}
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  4353
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  4354
	/*
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  4355
	 * Now go through and check the width of any non-fixed columns
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  4356
	 */
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  4357
	for (entry = *plp; entry != NULL; entry = entry->pl_next) {
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  4358
		if (entry->pl_fixed)
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  4359
			continue;
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  4360
5094
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4861
diff changeset
  4361
		if (entry->pl_prop != ZPROP_INVAL) {
2676
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  4362
			if (zfs_prop_get(zhp, entry->pl_prop,
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  4363
			    buf, sizeof (buf), NULL, NULL, 0, B_FALSE) == 0) {
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  4364
				if (strlen(buf) > entry->pl_width)
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  4365
					entry->pl_width = strlen(buf);
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  4366
			}
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  4367
		} else if (nvlist_lookup_nvlist(userprops,
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  4368
		    entry->pl_user_prop, &propval)  == 0) {
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  4369
			verify(nvlist_lookup_string(propval,
5094
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4861
diff changeset
  4370
			    ZPROP_VALUE, &strval) == 0);
2676
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  4371
			if (strlen(strval) > entry->pl_width)
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  4372
				entry->pl_width = strlen(strval);
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  4373
		}
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  4374
	}
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  4375
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  4376
	return (0);
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  4377
}
4543
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  4378
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  4379
int
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  4380
zfs_iscsi_perm_check(libzfs_handle_t *hdl, char *dataset, ucred_t *cred)
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  4381
{
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  4382
	zfs_cmd_t zc = { 0 };
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  4383
	nvlist_t *nvp;
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  4384
	gid_t gid;
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  4385
	uid_t uid;
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  4386
	const gid_t *groups;
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  4387
	int group_cnt;
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  4388
	int error;
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  4389
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  4390
	if (nvlist_alloc(&nvp, NV_UNIQUE_NAME, 0) != 0)
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  4391
		return (no_memory(hdl));
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  4392
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  4393
	uid = ucred_geteuid(cred);
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  4394
	gid = ucred_getegid(cred);
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  4395
	group_cnt = ucred_getgroups(cred, &groups);
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  4396
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  4397
	if (uid == (uid_t)-1 || gid == (uid_t)-1 || group_cnt == (uid_t)-1)
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  4398
		return (1);
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  4399
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  4400
	if (nvlist_add_uint32(nvp, ZFS_DELEG_PERM_UID, uid) != 0) {
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  4401
		nvlist_free(nvp);
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  4402
		return (1);
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  4403
	}
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  4404
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  4405
	if (nvlist_add_uint32(nvp, ZFS_DELEG_PERM_GID, gid) != 0) {
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  4406
		nvlist_free(nvp);
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  4407
		return (1);
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  4408
	}
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  4409
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  4410
	if (nvlist_add_uint32_array(nvp,
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  4411
	    ZFS_DELEG_PERM_GROUPS, (uint32_t *)groups, group_cnt) != 0) {
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  4412
		nvlist_free(nvp);
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  4413
		return (1);
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  4414
	}
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  4415
	(void) strlcpy(zc.zc_name, dataset, sizeof (zc.zc_name));
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  4416
5094
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4861
diff changeset
  4417
	if (zcmd_write_src_nvlist(hdl, &zc, nvp))
4543
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  4418
		return (-1);
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  4419
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  4420
	error = ioctl(hdl->libzfs_fd, ZFS_IOC_ISCSI_PERM_CHECK, &zc);
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  4421
	nvlist_free(nvp);
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  4422
	return (error);
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  4423
}
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  4424
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  4425
int
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  4426
zfs_deleg_share_nfs(libzfs_handle_t *hdl, char *dataset, char *path,
5331
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5326
diff changeset
  4427
    void *export, void *sharetab, int sharemax, zfs_share_op_t operation)
4543
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  4428
{
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  4429
	zfs_cmd_t zc = { 0 };
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  4430
	int error;
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  4431
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  4432
	(void) strlcpy(zc.zc_name, dataset, sizeof (zc.zc_name));
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  4433
	(void) strlcpy(zc.zc_value, path, sizeof (zc.zc_value));
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  4434
	zc.zc_share.z_sharedata = (uint64_t)(uintptr_t)sharetab;
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  4435
	zc.zc_share.z_exportdata = (uint64_t)(uintptr_t)export;
5331
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5326
diff changeset
  4436
	zc.zc_share.z_sharetype = operation;
4543
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  4437
	zc.zc_share.z_sharemax = sharemax;
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  4438
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  4439
	error = ioctl(hdl->libzfs_fd, ZFS_IOC_SHARE, &zc);
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  4440
	return (error);
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  4441
}