usr/src/lib/libzfs/common/libzfs_dataset.c
author Mark J Musante <Mark.Musante@Sun.COM>
Thu, 14 Jan 2010 13:19:41 -0700
changeset 11497 69b45e632792
parent 11449 a6be67f77b9f
child 11515 a122949107d4
permissions -rw-r--r--
6698011 zfs incorrectly reports file systems as children when attempting a rename 6730529 trying to import a pool that is already imported should have a better error message 6468151 inconsistent behaviour with volsize property 6914241 In ztest_vdev_attach_detach() the code is choosing a random leaf incorrectly 6915030 A race condition in ztest can end up causing spa_vdev_split_mirror() to offline a replacing vdev
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
/*
11417
de9a68916900 6911611 zfs_send()'s use of snapshot holds is still racy
Chris Kirby <Chris.Kirby@sun.com>
parents: 11080
diff changeset
    23
 * Copyright 2010 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 <ctype.h>
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    28
#include <errno.h>
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    29
#include <libintl.h>
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    30
#include <math.h>
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    31
#include <stdio.h>
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    32
#include <stdlib.h>
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    33
#include <strings.h>
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    34
#include <unistd.h>
5367
c40abbe796be PSARC/2007/574 zfs send -R
ahrens
parents: 5331
diff changeset
    35
#include <stddef.h>
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    36
#include <zone.h>
2082
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1793
diff changeset
    37
#include <fcntl.h>
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    38
#include <sys/mntent.h>
1294
87b43e5de5ee 6364129 need to unmount any child datasets before doing the rollback
lling
parents: 1175
diff changeset
    39
#include <sys/mount.h>
4543
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
    40
#include <priv.h>
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
    41
#include <pwd.h>
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
    42
#include <grp.h>
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
    43
#include <stddef.h>
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
    44
#include <ucred.h>
9396
f41cf682d0d3 PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 8845
diff changeset
    45
#include <idmap.h>
f41cf682d0d3 PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 8845
diff changeset
    46
#include <aclutils.h>
10160
a45b03783d44 6861983 zfs should use new name <-> SID interfaces
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 9688
diff changeset
    47
#include <directory.h>
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    48
11449
a6be67f77b9f 6429996 zvols don't reserve enough space for requisite meta data
Eric Taylor <Eric.Taylor@Sun.COM>
parents: 11417
diff changeset
    49
#include <sys/dnode.h>
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    50
#include <sys/spa.h>
2676
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
    51
#include <sys/zap.h>
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    52
#include <libzfs.h>
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    53
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    54
#include "zfs_namecheck.h"
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    55
#include "zfs_prop.h"
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    56
#include "libzfs_impl.h"
4543
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
    57
#include "zfs_deleg.h"
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    58
9396
f41cf682d0d3 PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 8845
diff changeset
    59
static int userquota_propname_decode(const char *propname, boolean_t zoned,
f41cf682d0d3 PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 8845
diff changeset
    60
    zfs_userquota_prop_t *typep, char *domain, int domainlen, uint64_t *ridp);
4007
c6f5c6753018 PSARC 2007/142 zfs rename -r
mmusante
parents: 3912
diff changeset
    61
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    62
/*
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    63
 * Given a single type (not a mask of types), return the type in a human
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    64
 * readable form.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    65
 */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    66
const char *
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    67
zfs_type_to_name(zfs_type_t type)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    68
{
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    69
	switch (type) {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    70
	case ZFS_TYPE_FILESYSTEM:
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    71
		return (dgettext(TEXT_DOMAIN, "filesystem"));
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    72
	case ZFS_TYPE_SNAPSHOT:
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    73
		return (dgettext(TEXT_DOMAIN, "snapshot"));
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    74
	case ZFS_TYPE_VOLUME:
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    75
		return (dgettext(TEXT_DOMAIN, "volume"));
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    76
	}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    77
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    78
	return (NULL);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    79
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    80
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    81
/*
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    82
 * Given a path and mask of ZFS types, return a string describing this dataset.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    83
 * 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
    84
 * 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
    85
 * acceptable types.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    86
 */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    87
static const char *
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    88
path_to_str(const char *path, int types)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    89
{
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    90
	/*
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    91
	 * When given a single type, always report the exact type.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    92
	 */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    93
	if (types == ZFS_TYPE_SNAPSHOT)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    94
		return (dgettext(TEXT_DOMAIN, "snapshot"));
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    95
	if (types == ZFS_TYPE_FILESYSTEM)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    96
		return (dgettext(TEXT_DOMAIN, "filesystem"));
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    97
	if (types == ZFS_TYPE_VOLUME)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    98
		return (dgettext(TEXT_DOMAIN, "volume"));
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    99
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   100
	/*
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   101
	 * The user is requesting more than one type of dataset.  If this is the
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   102
	 * case, consult the path itself.  If we're looking for a snapshot, and
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   103
	 * a '@' is found, then report it as "snapshot".  Otherwise, remove the
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   104
	 * snapshot attribute and try again.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   105
	 */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   106
	if (types & ZFS_TYPE_SNAPSHOT) {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   107
		if (strchr(path, '@') != NULL)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   108
			return (dgettext(TEXT_DOMAIN, "snapshot"));
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   109
		return (path_to_str(path, types & ~ZFS_TYPE_SNAPSHOT));
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   110
	}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   111
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   112
	/*
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   113
	 * The user has requested either filesystems or volumes.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   114
	 * We have no way of knowing a priori what type this would be, so always
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   115
	 * report it as "filesystem" or "volume", our two primitive types.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   116
	 */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   117
	if (types & ZFS_TYPE_FILESYSTEM)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   118
		return (dgettext(TEXT_DOMAIN, "filesystem"));
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   119
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   120
	assert(types & ZFS_TYPE_VOLUME);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   121
	return (dgettext(TEXT_DOMAIN, "volume"));
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   122
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   123
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   124
/*
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   125
 * Validate a ZFS path.  This is used even before trying to open the dataset, to
9396
f41cf682d0d3 PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 8845
diff changeset
   126
 * provide a more meaningful error message.  We call zfs_error_aux() to
f41cf682d0d3 PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 8845
diff changeset
   127
 * explain exactly why the name was not valid.
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   128
 */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   129
static int
5326
6752aa2bd5bc 6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents: 5147
diff changeset
   130
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
   131
    boolean_t modifying)
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   132
{
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   133
	namecheck_err_t why;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   134
	char what;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   135
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   136
	if (dataset_namecheck(path, &why, &what) != 0) {
2082
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1793
diff changeset
   137
		if (hdl != NULL) {
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   138
			switch (why) {
1003
ce99098d6a9b 6350417 long name will cause rename a dataset panic
lling
parents: 905
diff changeset
   139
			case NAME_ERR_TOOLONG:
2082
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1793
diff changeset
   140
				zfs_error_aux(hdl, dgettext(TEXT_DOMAIN,
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1793
diff changeset
   141
				    "name is too long"));
1003
ce99098d6a9b 6350417 long name will cause rename a dataset panic
lling
parents: 905
diff changeset
   142
				break;
ce99098d6a9b 6350417 long name will cause rename a dataset panic
lling
parents: 905
diff changeset
   143
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   144
			case NAME_ERR_LEADING_SLASH:
2082
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1793
diff changeset
   145
				zfs_error_aux(hdl, dgettext(TEXT_DOMAIN,
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1793
diff changeset
   146
				    "leading slash in name"));
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   147
				break;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   148
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   149
			case NAME_ERR_EMPTY_COMPONENT:
2082
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1793
diff changeset
   150
				zfs_error_aux(hdl, dgettext(TEXT_DOMAIN,
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1793
diff changeset
   151
				    "empty component in name"));
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   152
				break;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   153
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   154
			case NAME_ERR_TRAILING_SLASH:
2082
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1793
diff changeset
   155
				zfs_error_aux(hdl, dgettext(TEXT_DOMAIN,
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1793
diff changeset
   156
				    "trailing slash in name"));
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   157
				break;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   158
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   159
			case NAME_ERR_INVALCHAR:
2082
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1793
diff changeset
   160
				zfs_error_aux(hdl,
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   161
				    dgettext(TEXT_DOMAIN, "invalid character "
2082
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1793
diff changeset
   162
				    "'%c' in name"), what);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   163
				break;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   164
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   165
			case NAME_ERR_MULTIPLE_AT:
2082
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1793
diff changeset
   166
				zfs_error_aux(hdl, dgettext(TEXT_DOMAIN,
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1793
diff changeset
   167
				    "multiple '@' delimiters in name"));
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   168
				break;
2856
6f4d5ee1906a 6463348 ZFS code could be more portable
nd150628
parents: 2744
diff changeset
   169
6f4d5ee1906a 6463348 ZFS code could be more portable
nd150628
parents: 2744
diff changeset
   170
			case NAME_ERR_NOLETTER:
6f4d5ee1906a 6463348 ZFS code could be more portable
nd150628
parents: 2744
diff changeset
   171
				zfs_error_aux(hdl, dgettext(TEXT_DOMAIN,
6f4d5ee1906a 6463348 ZFS code could be more portable
nd150628
parents: 2744
diff changeset
   172
				    "pool doesn't begin with a letter"));
6f4d5ee1906a 6463348 ZFS code could be more portable
nd150628
parents: 2744
diff changeset
   173
				break;
6f4d5ee1906a 6463348 ZFS code could be more portable
nd150628
parents: 2744
diff changeset
   174
6f4d5ee1906a 6463348 ZFS code could be more portable
nd150628
parents: 2744
diff changeset
   175
			case NAME_ERR_RESERVED:
6f4d5ee1906a 6463348 ZFS code could be more portable
nd150628
parents: 2744
diff changeset
   176
				zfs_error_aux(hdl, dgettext(TEXT_DOMAIN,
6f4d5ee1906a 6463348 ZFS code could be more portable
nd150628
parents: 2744
diff changeset
   177
				    "name is reserved"));
6f4d5ee1906a 6463348 ZFS code could be more portable
nd150628
parents: 2744
diff changeset
   178
				break;
6f4d5ee1906a 6463348 ZFS code could be more portable
nd150628
parents: 2744
diff changeset
   179
6f4d5ee1906a 6463348 ZFS code could be more portable
nd150628
parents: 2744
diff changeset
   180
			case NAME_ERR_DISKLIKE:
6f4d5ee1906a 6463348 ZFS code could be more portable
nd150628
parents: 2744
diff changeset
   181
				zfs_error_aux(hdl, dgettext(TEXT_DOMAIN,
6f4d5ee1906a 6463348 ZFS code could be more portable
nd150628
parents: 2744
diff changeset
   182
				    "reserved disk name"));
6f4d5ee1906a 6463348 ZFS code could be more portable
nd150628
parents: 2744
diff changeset
   183
				break;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   184
			}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   185
		}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   186
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   187
		return (0);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   188
	}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   189
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   190
	if (!(type & ZFS_TYPE_SNAPSHOT) && strchr(path, '@') != NULL) {
2082
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1793
diff changeset
   191
		if (hdl != NULL)
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1793
diff changeset
   192
			zfs_error_aux(hdl, dgettext(TEXT_DOMAIN,
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1793
diff changeset
   193
			    "snapshot delimiter '@' in filesystem name"));
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   194
		return (0);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   195
	}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   196
2199
712a788c2dfd PSARC 2006/388 snapshot -r
ahrens
parents: 2169
diff changeset
   197
	if (type == ZFS_TYPE_SNAPSHOT && strchr(path, '@') == NULL) {
712a788c2dfd PSARC 2006/388 snapshot -r
ahrens
parents: 2169
diff changeset
   198
		if (hdl != NULL)
712a788c2dfd PSARC 2006/388 snapshot -r
ahrens
parents: 2169
diff changeset
   199
			zfs_error_aux(hdl, dgettext(TEXT_DOMAIN,
3413
f4cbe0204ab7 6471255 Some ZFS error messages contain spelling errors
mmusante
parents: 3377
diff changeset
   200
			    "missing '@' delimiter in snapshot name"));
2199
712a788c2dfd PSARC 2006/388 snapshot -r
ahrens
parents: 2169
diff changeset
   201
		return (0);
712a788c2dfd PSARC 2006/388 snapshot -r
ahrens
parents: 2169
diff changeset
   202
	}
712a788c2dfd PSARC 2006/388 snapshot -r
ahrens
parents: 2169
diff changeset
   203
5326
6752aa2bd5bc 6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents: 5147
diff changeset
   204
	if (modifying && strchr(path, '%') != NULL) {
6752aa2bd5bc 6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents: 5147
diff changeset
   205
		if (hdl != NULL)
6752aa2bd5bc 6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents: 5147
diff changeset
   206
			zfs_error_aux(hdl, dgettext(TEXT_DOMAIN,
6752aa2bd5bc 6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents: 5147
diff changeset
   207
			    "invalid character %c in name"), '%');
6752aa2bd5bc 6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents: 5147
diff changeset
   208
		return (0);
6752aa2bd5bc 6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents: 5147
diff changeset
   209
	}
6752aa2bd5bc 6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents: 5147
diff changeset
   210
2082
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1793
diff changeset
   211
	return (-1);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   212
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   213
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   214
int
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   215
zfs_name_valid(const char *name, zfs_type_t type)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   216
{
6423
437422a29d3a PSARC 2006/370 ZFS Boot Support
gw25295
parents: 6168
diff changeset
   217
	if (type == ZFS_TYPE_POOL)
437422a29d3a PSARC 2006/370 ZFS Boot Support
gw25295
parents: 6168
diff changeset
   218
		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
   219
	return (zfs_validate_name(NULL, name, type, B_FALSE));
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   220
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   221
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   222
/*
2676
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
   223
 * 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
   224
 * properties into a separate nvlist.
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
   225
 */
4217
3411a82f178f 6552521 truss dumps core with multibyte characters in syscall args
eschrock
parents: 4183
diff changeset
   226
static nvlist_t *
3411a82f178f 6552521 truss dumps core with multibyte characters in syscall args
eschrock
parents: 4183
diff changeset
   227
process_user_props(zfs_handle_t *zhp, nvlist_t *props)
2676
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
   228
{
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
   229
	libzfs_handle_t *hdl = zhp->zfs_hdl;
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
   230
	nvpair_t *elem;
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
   231
	nvlist_t *propval;
4217
3411a82f178f 6552521 truss dumps core with multibyte characters in syscall args
eschrock
parents: 4183
diff changeset
   232
	nvlist_t *nvl;
3411a82f178f 6552521 truss dumps core with multibyte characters in syscall args
eschrock
parents: 4183
diff changeset
   233
3411a82f178f 6552521 truss dumps core with multibyte characters in syscall args
eschrock
parents: 4183
diff changeset
   234
	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
   235
		(void) no_memory(hdl);
3411a82f178f 6552521 truss dumps core with multibyte characters in syscall args
eschrock
parents: 4183
diff changeset
   236
		return (NULL);
3411a82f178f 6552521 truss dumps core with multibyte characters in syscall args
eschrock
parents: 4183
diff changeset
   237
	}
2676
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
   238
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
   239
	elem = NULL;
4217
3411a82f178f 6552521 truss dumps core with multibyte characters in syscall args
eschrock
parents: 4183
diff changeset
   240
	while ((elem = nvlist_next_nvpair(props, elem)) != NULL) {
2676
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
   241
		if (!zfs_prop_user(nvpair_name(elem)))
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
   242
			continue;
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
   243
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
   244
		verify(nvpair_value_nvlist(elem, &propval) == 0);
4217
3411a82f178f 6552521 truss dumps core with multibyte characters in syscall args
eschrock
parents: 4183
diff changeset
   245
		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
   246
			nvlist_free(nvl);
3411a82f178f 6552521 truss dumps core with multibyte characters in syscall args
eschrock
parents: 4183
diff changeset
   247
			(void) no_memory(hdl);
3411a82f178f 6552521 truss dumps core with multibyte characters in syscall args
eschrock
parents: 4183
diff changeset
   248
			return (NULL);
3411a82f178f 6552521 truss dumps core with multibyte characters in syscall args
eschrock
parents: 4183
diff changeset
   249
		}
2676
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
   250
	}
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
   251
4217
3411a82f178f 6552521 truss dumps core with multibyte characters in syscall args
eschrock
parents: 4183
diff changeset
   252
	return (nvl);
2676
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
   253
}
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
   254
6865
176d18c623cc 6539380 zfs list uses too much memory
rm160521
parents: 6612
diff changeset
   255
static zpool_handle_t *
176d18c623cc 6539380 zfs list uses too much memory
rm160521
parents: 6612
diff changeset
   256
zpool_add_handle(zfs_handle_t *zhp, const char *pool_name)
176d18c623cc 6539380 zfs list uses too much memory
rm160521
parents: 6612
diff changeset
   257
{
176d18c623cc 6539380 zfs list uses too much memory
rm160521
parents: 6612
diff changeset
   258
	libzfs_handle_t *hdl = zhp->zfs_hdl;
176d18c623cc 6539380 zfs list uses too much memory
rm160521
parents: 6612
diff changeset
   259
	zpool_handle_t *zph;
176d18c623cc 6539380 zfs list uses too much memory
rm160521
parents: 6612
diff changeset
   260
176d18c623cc 6539380 zfs list uses too much memory
rm160521
parents: 6612
diff changeset
   261
	if ((zph = zpool_open_canfail(hdl, pool_name)) != NULL) {
176d18c623cc 6539380 zfs list uses too much memory
rm160521
parents: 6612
diff changeset
   262
		if (hdl->libzfs_pool_handles != NULL)
176d18c623cc 6539380 zfs list uses too much memory
rm160521
parents: 6612
diff changeset
   263
			zph->zpool_next = hdl->libzfs_pool_handles;
176d18c623cc 6539380 zfs list uses too much memory
rm160521
parents: 6612
diff changeset
   264
		hdl->libzfs_pool_handles = 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
	return (zph);
176d18c623cc 6539380 zfs list uses too much memory
rm160521
parents: 6612
diff changeset
   267
}
176d18c623cc 6539380 zfs list uses too much memory
rm160521
parents: 6612
diff changeset
   268
176d18c623cc 6539380 zfs list uses too much memory
rm160521
parents: 6612
diff changeset
   269
static zpool_handle_t *
176d18c623cc 6539380 zfs list uses too much memory
rm160521
parents: 6612
diff changeset
   270
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
   271
{
176d18c623cc 6539380 zfs list uses too much memory
rm160521
parents: 6612
diff changeset
   272
	libzfs_handle_t *hdl = zhp->zfs_hdl;
176d18c623cc 6539380 zfs list uses too much memory
rm160521
parents: 6612
diff changeset
   273
	zpool_handle_t *zph = hdl->libzfs_pool_handles;
176d18c623cc 6539380 zfs list uses too much memory
rm160521
parents: 6612
diff changeset
   274
176d18c623cc 6539380 zfs list uses too much memory
rm160521
parents: 6612
diff changeset
   275
	while ((zph != NULL) &&
176d18c623cc 6539380 zfs list uses too much memory
rm160521
parents: 6612
diff changeset
   276
	    (strncmp(pool_name, zpool_get_name(zph), len) != 0))
176d18c623cc 6539380 zfs list uses too much memory
rm160521
parents: 6612
diff changeset
   277
		zph = zph->zpool_next;
176d18c623cc 6539380 zfs list uses too much memory
rm160521
parents: 6612
diff changeset
   278
	return (zph);
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
176d18c623cc 6539380 zfs list uses too much memory
rm160521
parents: 6612
diff changeset
   281
/*
176d18c623cc 6539380 zfs list uses too much memory
rm160521
parents: 6612
diff changeset
   282
 * Returns a handle to the pool that contains the provided dataset.
176d18c623cc 6539380 zfs list uses too much memory
rm160521
parents: 6612
diff changeset
   283
 * 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
   284
 * 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
   285
 */
176d18c623cc 6539380 zfs list uses too much memory
rm160521
parents: 6612
diff changeset
   286
static zpool_handle_t *
176d18c623cc 6539380 zfs list uses too much memory
rm160521
parents: 6612
diff changeset
   287
zpool_handle(zfs_handle_t *zhp)
176d18c623cc 6539380 zfs list uses too much memory
rm160521
parents: 6612
diff changeset
   288
{
176d18c623cc 6539380 zfs list uses too much memory
rm160521
parents: 6612
diff changeset
   289
	char *pool_name;
176d18c623cc 6539380 zfs list uses too much memory
rm160521
parents: 6612
diff changeset
   290
	int len;
176d18c623cc 6539380 zfs list uses too much memory
rm160521
parents: 6612
diff changeset
   291
	zpool_handle_t *zph;
176d18c623cc 6539380 zfs list uses too much memory
rm160521
parents: 6612
diff changeset
   292
176d18c623cc 6539380 zfs list uses too much memory
rm160521
parents: 6612
diff changeset
   293
	len = strcspn(zhp->zfs_name, "/@") + 1;
176d18c623cc 6539380 zfs list uses too much memory
rm160521
parents: 6612
diff changeset
   294
	pool_name = zfs_alloc(zhp->zfs_hdl, len);
176d18c623cc 6539380 zfs list uses too much memory
rm160521
parents: 6612
diff changeset
   295
	(void) strlcpy(pool_name, zhp->zfs_name, len);
176d18c623cc 6539380 zfs list uses too much memory
rm160521
parents: 6612
diff changeset
   296
176d18c623cc 6539380 zfs list uses too much memory
rm160521
parents: 6612
diff changeset
   297
	zph = zpool_find_handle(zhp, pool_name, len);
176d18c623cc 6539380 zfs list uses too much memory
rm160521
parents: 6612
diff changeset
   298
	if (zph == NULL)
176d18c623cc 6539380 zfs list uses too much memory
rm160521
parents: 6612
diff changeset
   299
		zph = zpool_add_handle(zhp, pool_name);
176d18c623cc 6539380 zfs list uses too much memory
rm160521
parents: 6612
diff changeset
   300
176d18c623cc 6539380 zfs list uses too much memory
rm160521
parents: 6612
diff changeset
   301
	free(pool_name);
176d18c623cc 6539380 zfs list uses too much memory
rm160521
parents: 6612
diff changeset
   302
	return (zph);
176d18c623cc 6539380 zfs list uses too much memory
rm160521
parents: 6612
diff changeset
   303
}
176d18c623cc 6539380 zfs list uses too much memory
rm160521
parents: 6612
diff changeset
   304
176d18c623cc 6539380 zfs list uses too much memory
rm160521
parents: 6612
diff changeset
   305
void
176d18c623cc 6539380 zfs list uses too much memory
rm160521
parents: 6612
diff changeset
   306
zpool_free_handles(libzfs_handle_t *hdl)
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
	zpool_handle_t *next, *zph = hdl->libzfs_pool_handles;
176d18c623cc 6539380 zfs list uses too much memory
rm160521
parents: 6612
diff changeset
   309
176d18c623cc 6539380 zfs list uses too much memory
rm160521
parents: 6612
diff changeset
   310
	while (zph != NULL) {
176d18c623cc 6539380 zfs list uses too much memory
rm160521
parents: 6612
diff changeset
   311
		next = zph->zpool_next;
176d18c623cc 6539380 zfs list uses too much memory
rm160521
parents: 6612
diff changeset
   312
		zpool_close(zph);
176d18c623cc 6539380 zfs list uses too much memory
rm160521
parents: 6612
diff changeset
   313
		zph = next;
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
	hdl->libzfs_pool_handles = NULL;
176d18c623cc 6539380 zfs list uses too much memory
rm160521
parents: 6612
diff changeset
   316
}
176d18c623cc 6539380 zfs list uses too much memory
rm160521
parents: 6612
diff changeset
   317
2676
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
   318
/*
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   319
 * Utility function to gather stats (objset and zpl) for the given object.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   320
 */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   321
static int
8228
51e9ca9ee3a5 6572357 libzfs should do more to avoid mnttab lookups
Eric Taylor <Eric.Taylor@Sun.COM>
parents: 7509
diff changeset
   322
get_stats_ioctl(zfs_handle_t *zhp, zfs_cmd_t *zc)
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   323
{
2676
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
   324
	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
   325
51e9ca9ee3a5 6572357 libzfs should do more to avoid mnttab lookups
Eric Taylor <Eric.Taylor@Sun.COM>
parents: 7509
diff changeset
   326
	(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
   327
51e9ca9ee3a5 6572357 libzfs should do more to avoid mnttab lookups
Eric Taylor <Eric.Taylor@Sun.COM>
parents: 7509
diff changeset
   328
	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
   329
		if (errno == ENOMEM) {
8228
51e9ca9ee3a5 6572357 libzfs should do more to avoid mnttab lookups
Eric Taylor <Eric.Taylor@Sun.COM>
parents: 7509
diff changeset
   330
			if (zcmd_expand_dst_nvlist(hdl, zc) != 0) {
2082
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1793
diff changeset
   331
				return (-1);
2676
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
   332
			}
1356
e021b5e4aa0e 6377671 zfs mount -a shouldn't bother checking snapshots
eschrock
parents: 1294
diff changeset
   333
		} else {
e021b5e4aa0e 6377671 zfs mount -a shouldn't bother checking snapshots
eschrock
parents: 1294
diff changeset
   334
			return (-1);
e021b5e4aa0e 6377671 zfs mount -a shouldn't bother checking snapshots
eschrock
parents: 1294
diff changeset
   335
		}
e021b5e4aa0e 6377671 zfs mount -a shouldn't bother checking snapshots
eschrock
parents: 1294
diff changeset
   336
	}
8228
51e9ca9ee3a5 6572357 libzfs should do more to avoid mnttab lookups
Eric Taylor <Eric.Taylor@Sun.COM>
parents: 7509
diff changeset
   337
	return (0);
51e9ca9ee3a5 6572357 libzfs should do more to avoid mnttab lookups
Eric Taylor <Eric.Taylor@Sun.COM>
parents: 7509
diff changeset
   338
}
51e9ca9ee3a5 6572357 libzfs should do more to avoid mnttab lookups
Eric Taylor <Eric.Taylor@Sun.COM>
parents: 7509
diff changeset
   339
11022
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 10984
diff changeset
   340
/*
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 10984
diff changeset
   341
 * Utility function to get the received properties of the given object.
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 10984
diff changeset
   342
 */
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 10984
diff changeset
   343
static int
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 10984
diff changeset
   344
get_recvd_props_ioctl(zfs_handle_t *zhp)
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 10984
diff changeset
   345
{
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 10984
diff changeset
   346
	libzfs_handle_t *hdl = zhp->zfs_hdl;
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 10984
diff changeset
   347
	nvlist_t *recvdprops;
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 10984
diff changeset
   348
	zfs_cmd_t zc = { 0 };
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 10984
diff changeset
   349
	int err;
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 10984
diff changeset
   350
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 10984
diff changeset
   351
	if (zcmd_alloc_dst_nvlist(hdl, &zc, 0) != 0)
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 10984
diff changeset
   352
		return (-1);
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 10984
diff changeset
   353
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 10984
diff changeset
   354
	(void) strlcpy(zc.zc_name, zhp->zfs_name, sizeof (zc.zc_name));
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 10984
diff changeset
   355
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 10984
diff changeset
   356
	while (ioctl(hdl->libzfs_fd, ZFS_IOC_OBJSET_RECVD_PROPS, &zc) != 0) {
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 10984
diff changeset
   357
		if (errno == ENOMEM) {
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 10984
diff changeset
   358
			if (zcmd_expand_dst_nvlist(hdl, &zc) != 0) {
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 10984
diff changeset
   359
				return (-1);
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 10984
diff changeset
   360
			}
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 10984
diff changeset
   361
		} else {
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 10984
diff changeset
   362
			zcmd_free_nvlists(&zc);
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 10984
diff changeset
   363
			return (-1);
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 10984
diff changeset
   364
		}
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 10984
diff changeset
   365
	}
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 10984
diff changeset
   366
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 10984
diff changeset
   367
	err = zcmd_read_dst_nvlist(zhp->zfs_hdl, &zc, &recvdprops);
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 10984
diff changeset
   368
	zcmd_free_nvlists(&zc);
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 10984
diff changeset
   369
	if (err != 0)
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 10984
diff changeset
   370
		return (-1);
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 10984
diff changeset
   371
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 10984
diff changeset
   372
	nvlist_free(zhp->zfs_recvd_props);
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 10984
diff changeset
   373
	zhp->zfs_recvd_props = recvdprops;
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 10984
diff changeset
   374
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 10984
diff changeset
   375
	return (0);
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 10984
diff changeset
   376
}
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 10984
diff changeset
   377
8228
51e9ca9ee3a5 6572357 libzfs should do more to avoid mnttab lookups
Eric Taylor <Eric.Taylor@Sun.COM>
parents: 7509
diff changeset
   378
static int
51e9ca9ee3a5 6572357 libzfs should do more to avoid mnttab lookups
Eric Taylor <Eric.Taylor@Sun.COM>
parents: 7509
diff changeset
   379
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
   380
{
51e9ca9ee3a5 6572357 libzfs should do more to avoid mnttab lookups
Eric Taylor <Eric.Taylor@Sun.COM>
parents: 7509
diff changeset
   381
	nvlist_t *allprops, *userprops;
51e9ca9ee3a5 6572357 libzfs should do more to avoid mnttab lookups
Eric Taylor <Eric.Taylor@Sun.COM>
parents: 7509
diff changeset
   382
51e9ca9ee3a5 6572357 libzfs should do more to avoid mnttab lookups
Eric Taylor <Eric.Taylor@Sun.COM>
parents: 7509
diff changeset
   383
	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
   384
51e9ca9ee3a5 6572357 libzfs should do more to avoid mnttab lookups
Eric Taylor <Eric.Taylor@Sun.COM>
parents: 7509
diff changeset
   385
	if (zcmd_read_dst_nvlist(zhp->zfs_hdl, zc, &allprops) != 0) {
2082
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1793
diff changeset
   386
		return (-1);
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1793
diff changeset
   387
	}
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   388
9396
f41cf682d0d3 PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 8845
diff changeset
   389
	/*
f41cf682d0d3 PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 8845
diff changeset
   390
	 * XXX Why do we store the user props separately, in addition to
f41cf682d0d3 PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 8845
diff changeset
   391
	 * storing them in zfs_props?
f41cf682d0d3 PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 8845
diff changeset
   392
	 */
4217
3411a82f178f 6552521 truss dumps core with multibyte characters in syscall args
eschrock
parents: 4183
diff changeset
   393
	if ((userprops = process_user_props(zhp, allprops)) == NULL) {
3411a82f178f 6552521 truss dumps core with multibyte characters in syscall args
eschrock
parents: 4183
diff changeset
   394
		nvlist_free(allprops);
2676
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
   395
		return (-1);
4217
3411a82f178f 6552521 truss dumps core with multibyte characters in syscall args
eschrock
parents: 4183
diff changeset
   396
	}
3411a82f178f 6552521 truss dumps core with multibyte characters in syscall args
eschrock
parents: 4183
diff changeset
   397
3411a82f178f 6552521 truss dumps core with multibyte characters in syscall args
eschrock
parents: 4183
diff changeset
   398
	nvlist_free(zhp->zfs_props);
3411a82f178f 6552521 truss dumps core with multibyte characters in syscall args
eschrock
parents: 4183
diff changeset
   399
	nvlist_free(zhp->zfs_user_props);
3411a82f178f 6552521 truss dumps core with multibyte characters in syscall args
eschrock
parents: 4183
diff changeset
   400
3411a82f178f 6552521 truss dumps core with multibyte characters in syscall args
eschrock
parents: 4183
diff changeset
   401
	zhp->zfs_props = allprops;
3411a82f178f 6552521 truss dumps core with multibyte characters in syscall args
eschrock
parents: 4183
diff changeset
   402
	zhp->zfs_user_props = userprops;
2082
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1793
diff changeset
   403
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   404
	return (0);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   405
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   406
8228
51e9ca9ee3a5 6572357 libzfs should do more to avoid mnttab lookups
Eric Taylor <Eric.Taylor@Sun.COM>
parents: 7509
diff changeset
   407
static int
51e9ca9ee3a5 6572357 libzfs should do more to avoid mnttab lookups
Eric Taylor <Eric.Taylor@Sun.COM>
parents: 7509
diff changeset
   408
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
   409
{
51e9ca9ee3a5 6572357 libzfs should do more to avoid mnttab lookups
Eric Taylor <Eric.Taylor@Sun.COM>
parents: 7509
diff changeset
   410
	int rc = 0;
51e9ca9ee3a5 6572357 libzfs should do more to avoid mnttab lookups
Eric Taylor <Eric.Taylor@Sun.COM>
parents: 7509
diff changeset
   411
	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
   412
51e9ca9ee3a5 6572357 libzfs should do more to avoid mnttab lookups
Eric Taylor <Eric.Taylor@Sun.COM>
parents: 7509
diff changeset
   413
	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
   414
		return (-1);
51e9ca9ee3a5 6572357 libzfs should do more to avoid mnttab lookups
Eric Taylor <Eric.Taylor@Sun.COM>
parents: 7509
diff changeset
   415
	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
   416
		rc = -1;
51e9ca9ee3a5 6572357 libzfs should do more to avoid mnttab lookups
Eric Taylor <Eric.Taylor@Sun.COM>
parents: 7509
diff changeset
   417
	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
   418
		rc = -1;
51e9ca9ee3a5 6572357 libzfs should do more to avoid mnttab lookups
Eric Taylor <Eric.Taylor@Sun.COM>
parents: 7509
diff changeset
   419
	zcmd_free_nvlists(&zc);
51e9ca9ee3a5 6572357 libzfs should do more to avoid mnttab lookups
Eric Taylor <Eric.Taylor@Sun.COM>
parents: 7509
diff changeset
   420
	return (rc);
51e9ca9ee3a5 6572357 libzfs should do more to avoid mnttab lookups
Eric Taylor <Eric.Taylor@Sun.COM>
parents: 7509
diff changeset
   421
}
51e9ca9ee3a5 6572357 libzfs should do more to avoid mnttab lookups
Eric Taylor <Eric.Taylor@Sun.COM>
parents: 7509
diff changeset
   422
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   423
/*
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   424
 * Refresh the properties currently stored in the handle.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   425
 */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   426
void
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   427
zfs_refresh_properties(zfs_handle_t *zhp)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   428
{
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   429
	(void) get_stats(zhp);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   430
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   431
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   432
/*
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   433
 * Makes a handle from the given dataset name.  Used by zfs_open() and
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   434
 * zfs_iter_* to create child handles on the fly.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   435
 */
8228
51e9ca9ee3a5 6572357 libzfs should do more to avoid mnttab lookups
Eric Taylor <Eric.Taylor@Sun.COM>
parents: 7509
diff changeset
   436
static int
51e9ca9ee3a5 6572357 libzfs should do more to avoid mnttab lookups
Eric Taylor <Eric.Taylor@Sun.COM>
parents: 7509
diff changeset
   437
make_dataset_handle_common(zfs_handle_t *zhp, zfs_cmd_t *zc)
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   438
{
10298
a0d52501437c 6860996 %temporary clones are not automatically destroyed on error
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 10242
diff changeset
   439
	if (put_stats_zhdl(zhp, zc) != 0)
8228
51e9ca9ee3a5 6572357 libzfs should do more to avoid mnttab lookups
Eric Taylor <Eric.Taylor@Sun.COM>
parents: 7509
diff changeset
   440
		return (-1);
1758
d0750a16db04 6397267 assertion failed: (link->list_next == 0) == (link->list_prev == 0)
ahrens
parents: 1749
diff changeset
   441
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   442
	/*
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   443
	 * We've managed to open the dataset and gather statistics.  Determine
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   444
	 * the high-level type.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   445
	 */
2885
c0259887ebbc 6460059 zfs destroy <snapshot> leaves behind kruft
ahrens
parents: 2856
diff changeset
   446
	if (zhp->zfs_dmustats.dds_type == DMU_OST_ZVOL)
c0259887ebbc 6460059 zfs destroy <snapshot> leaves behind kruft
ahrens
parents: 2856
diff changeset
   447
		zhp->zfs_head_type = ZFS_TYPE_VOLUME;
c0259887ebbc 6460059 zfs destroy <snapshot> leaves behind kruft
ahrens
parents: 2856
diff changeset
   448
	else if (zhp->zfs_dmustats.dds_type == DMU_OST_ZFS)
c0259887ebbc 6460059 zfs destroy <snapshot> leaves behind kruft
ahrens
parents: 2856
diff changeset
   449
		zhp->zfs_head_type = ZFS_TYPE_FILESYSTEM;
c0259887ebbc 6460059 zfs destroy <snapshot> leaves behind kruft
ahrens
parents: 2856
diff changeset
   450
	else
c0259887ebbc 6460059 zfs destroy <snapshot> leaves behind kruft
ahrens
parents: 2856
diff changeset
   451
		abort();
c0259887ebbc 6460059 zfs destroy <snapshot> leaves behind kruft
ahrens
parents: 2856
diff changeset
   452
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   453
	if (zhp->zfs_dmustats.dds_is_snapshot)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   454
		zhp->zfs_type = ZFS_TYPE_SNAPSHOT;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   455
	else if (zhp->zfs_dmustats.dds_type == DMU_OST_ZVOL)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   456
		zhp->zfs_type = ZFS_TYPE_VOLUME;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   457
	else if (zhp->zfs_dmustats.dds_type == DMU_OST_ZFS)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   458
		zhp->zfs_type = ZFS_TYPE_FILESYSTEM;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   459
	else
2082
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1793
diff changeset
   460
		abort();	/* we should never see any other types */
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   461
6865
176d18c623cc 6539380 zfs list uses too much memory
rm160521
parents: 6612
diff changeset
   462
	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
   463
	return (0);
51e9ca9ee3a5 6572357 libzfs should do more to avoid mnttab lookups
Eric Taylor <Eric.Taylor@Sun.COM>
parents: 7509
diff changeset
   464
}
51e9ca9ee3a5 6572357 libzfs should do more to avoid mnttab lookups
Eric Taylor <Eric.Taylor@Sun.COM>
parents: 7509
diff changeset
   465
51e9ca9ee3a5 6572357 libzfs should do more to avoid mnttab lookups
Eric Taylor <Eric.Taylor@Sun.COM>
parents: 7509
diff changeset
   466
zfs_handle_t *
51e9ca9ee3a5 6572357 libzfs should do more to avoid mnttab lookups
Eric Taylor <Eric.Taylor@Sun.COM>
parents: 7509
diff changeset
   467
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
   468
{
51e9ca9ee3a5 6572357 libzfs should do more to avoid mnttab lookups
Eric Taylor <Eric.Taylor@Sun.COM>
parents: 7509
diff changeset
   469
	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
   470
51e9ca9ee3a5 6572357 libzfs should do more to avoid mnttab lookups
Eric Taylor <Eric.Taylor@Sun.COM>
parents: 7509
diff changeset
   471
	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
   472
51e9ca9ee3a5 6572357 libzfs should do more to avoid mnttab lookups
Eric Taylor <Eric.Taylor@Sun.COM>
parents: 7509
diff changeset
   473
	if (zhp == NULL)
51e9ca9ee3a5 6572357 libzfs should do more to avoid mnttab lookups
Eric Taylor <Eric.Taylor@Sun.COM>
parents: 7509
diff changeset
   474
		return (NULL);
51e9ca9ee3a5 6572357 libzfs should do more to avoid mnttab lookups
Eric Taylor <Eric.Taylor@Sun.COM>
parents: 7509
diff changeset
   475
51e9ca9ee3a5 6572357 libzfs should do more to avoid mnttab lookups
Eric Taylor <Eric.Taylor@Sun.COM>
parents: 7509
diff changeset
   476
	zhp->zfs_hdl = hdl;
51e9ca9ee3a5 6572357 libzfs should do more to avoid mnttab lookups
Eric Taylor <Eric.Taylor@Sun.COM>
parents: 7509
diff changeset
   477
	(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
   478
	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
   479
		free(zhp);
51e9ca9ee3a5 6572357 libzfs should do more to avoid mnttab lookups
Eric Taylor <Eric.Taylor@Sun.COM>
parents: 7509
diff changeset
   480
		return (NULL);
51e9ca9ee3a5 6572357 libzfs should do more to avoid mnttab lookups
Eric Taylor <Eric.Taylor@Sun.COM>
parents: 7509
diff changeset
   481
	}
51e9ca9ee3a5 6572357 libzfs should do more to avoid mnttab lookups
Eric Taylor <Eric.Taylor@Sun.COM>
parents: 7509
diff changeset
   482
	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
   483
		zcmd_free_nvlists(&zc);
51e9ca9ee3a5 6572357 libzfs should do more to avoid mnttab lookups
Eric Taylor <Eric.Taylor@Sun.COM>
parents: 7509
diff changeset
   484
		free(zhp);
51e9ca9ee3a5 6572357 libzfs should do more to avoid mnttab lookups
Eric Taylor <Eric.Taylor@Sun.COM>
parents: 7509
diff changeset
   485
		return (NULL);
51e9ca9ee3a5 6572357 libzfs should do more to avoid mnttab lookups
Eric Taylor <Eric.Taylor@Sun.COM>
parents: 7509
diff changeset
   486
	}
51e9ca9ee3a5 6572357 libzfs should do more to avoid mnttab lookups
Eric Taylor <Eric.Taylor@Sun.COM>
parents: 7509
diff changeset
   487
	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
   488
		free(zhp);
51e9ca9ee3a5 6572357 libzfs should do more to avoid mnttab lookups
Eric Taylor <Eric.Taylor@Sun.COM>
parents: 7509
diff changeset
   489
		zhp = NULL;
51e9ca9ee3a5 6572357 libzfs should do more to avoid mnttab lookups
Eric Taylor <Eric.Taylor@Sun.COM>
parents: 7509
diff changeset
   490
	}
51e9ca9ee3a5 6572357 libzfs should do more to avoid mnttab lookups
Eric Taylor <Eric.Taylor@Sun.COM>
parents: 7509
diff changeset
   491
	zcmd_free_nvlists(&zc);
51e9ca9ee3a5 6572357 libzfs should do more to avoid mnttab lookups
Eric Taylor <Eric.Taylor@Sun.COM>
parents: 7509
diff changeset
   492
	return (zhp);
51e9ca9ee3a5 6572357 libzfs should do more to avoid mnttab lookups
Eric Taylor <Eric.Taylor@Sun.COM>
parents: 7509
diff changeset
   493
}
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
static zfs_handle_t *
51e9ca9ee3a5 6572357 libzfs should do more to avoid mnttab lookups
Eric Taylor <Eric.Taylor@Sun.COM>
parents: 7509
diff changeset
   496
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
   497
{
51e9ca9ee3a5 6572357 libzfs should do more to avoid mnttab lookups
Eric Taylor <Eric.Taylor@Sun.COM>
parents: 7509
diff changeset
   498
	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
   499
51e9ca9ee3a5 6572357 libzfs should do more to avoid mnttab lookups
Eric Taylor <Eric.Taylor@Sun.COM>
parents: 7509
diff changeset
   500
	if (zhp == NULL)
51e9ca9ee3a5 6572357 libzfs should do more to avoid mnttab lookups
Eric Taylor <Eric.Taylor@Sun.COM>
parents: 7509
diff changeset
   501
		return (NULL);
51e9ca9ee3a5 6572357 libzfs should do more to avoid mnttab lookups
Eric Taylor <Eric.Taylor@Sun.COM>
parents: 7509
diff changeset
   502
51e9ca9ee3a5 6572357 libzfs should do more to avoid mnttab lookups
Eric Taylor <Eric.Taylor@Sun.COM>
parents: 7509
diff changeset
   503
	zhp->zfs_hdl = hdl;
51e9ca9ee3a5 6572357 libzfs should do more to avoid mnttab lookups
Eric Taylor <Eric.Taylor@Sun.COM>
parents: 7509
diff changeset
   504
	(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
   505
	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
   506
		free(zhp);
51e9ca9ee3a5 6572357 libzfs should do more to avoid mnttab lookups
Eric Taylor <Eric.Taylor@Sun.COM>
parents: 7509
diff changeset
   507
		return (NULL);
51e9ca9ee3a5 6572357 libzfs should do more to avoid mnttab lookups
Eric Taylor <Eric.Taylor@Sun.COM>
parents: 7509
diff changeset
   508
	}
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   509
	return (zhp);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   510
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   511
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   512
/*
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   513
 * Opens the given snapshot, filesystem, or volume.   The 'types'
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   514
 * argument is a mask of acceptable types.  The function will print an
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   515
 * appropriate error message and return NULL if it can't be opened.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   516
 */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   517
zfs_handle_t *
2082
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1793
diff changeset
   518
zfs_open(libzfs_handle_t *hdl, const char *path, int types)
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   519
{
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   520
	zfs_handle_t *zhp;
2082
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1793
diff changeset
   521
	char errbuf[1024];
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1793
diff changeset
   522
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1793
diff changeset
   523
	(void) snprintf(errbuf, sizeof (errbuf),
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1793
diff changeset
   524
	    dgettext(TEXT_DOMAIN, "cannot open '%s'"), path);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   525
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   526
	/*
2082
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1793
diff changeset
   527
	 * Validate the name before we even try to open it.
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   528
	 */
5326
6752aa2bd5bc 6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents: 5147
diff changeset
   529
	if (!zfs_validate_name(hdl, path, ZFS_TYPE_DATASET, B_FALSE)) {
2082
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1793
diff changeset
   530
		zfs_error_aux(hdl, dgettext(TEXT_DOMAIN,
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1793
diff changeset
   531
		    "invalid dataset name"));
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1793
diff changeset
   532
		(void) zfs_error(hdl, EZFS_INVALIDNAME, errbuf);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   533
		return (NULL);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   534
	}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   535
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   536
	/*
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   537
	 * Try to get stats for the dataset, which will tell us if it exists.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   538
	 */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   539
	errno = 0;
2082
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1793
diff changeset
   540
	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
   541
		(void) zfs_standard_error(hdl, errno, errbuf);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   542
		return (NULL);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   543
	}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   544
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   545
	if (!(types & zhp->zfs_type)) {
2082
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1793
diff changeset
   546
		(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
   547
		zfs_close(zhp);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   548
		return (NULL);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   549
	}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   550
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   551
	return (zhp);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   552
}
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
 * Release a ZFS handle.  Nothing to do but free the associated memory.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   556
 */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   557
void
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   558
zfs_close(zfs_handle_t *zhp)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   559
{
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   560
	if (zhp->zfs_mntopts)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   561
		free(zhp->zfs_mntopts);
2676
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
   562
	nvlist_free(zhp->zfs_props);
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
   563
	nvlist_free(zhp->zfs_user_props);
11022
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 10984
diff changeset
   564
	nvlist_free(zhp->zfs_recvd_props);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   565
	free(zhp);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   566
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   567
8228
51e9ca9ee3a5 6572357 libzfs should do more to avoid mnttab lookups
Eric Taylor <Eric.Taylor@Sun.COM>
parents: 7509
diff changeset
   568
typedef struct mnttab_node {
51e9ca9ee3a5 6572357 libzfs should do more to avoid mnttab lookups
Eric Taylor <Eric.Taylor@Sun.COM>
parents: 7509
diff changeset
   569
	struct mnttab mtn_mt;
51e9ca9ee3a5 6572357 libzfs should do more to avoid mnttab lookups
Eric Taylor <Eric.Taylor@Sun.COM>
parents: 7509
diff changeset
   570
	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
   571
} mnttab_node_t;
51e9ca9ee3a5 6572357 libzfs should do more to avoid mnttab lookups
Eric Taylor <Eric.Taylor@Sun.COM>
parents: 7509
diff changeset
   572
51e9ca9ee3a5 6572357 libzfs should do more to avoid mnttab lookups
Eric Taylor <Eric.Taylor@Sun.COM>
parents: 7509
diff changeset
   573
static int
51e9ca9ee3a5 6572357 libzfs should do more to avoid mnttab lookups
Eric Taylor <Eric.Taylor@Sun.COM>
parents: 7509
diff changeset
   574
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
   575
{
51e9ca9ee3a5 6572357 libzfs should do more to avoid mnttab lookups
Eric Taylor <Eric.Taylor@Sun.COM>
parents: 7509
diff changeset
   576
	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
   577
	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
   578
	int rv;
51e9ca9ee3a5 6572357 libzfs should do more to avoid mnttab lookups
Eric Taylor <Eric.Taylor@Sun.COM>
parents: 7509
diff changeset
   579
51e9ca9ee3a5 6572357 libzfs should do more to avoid mnttab lookups
Eric Taylor <Eric.Taylor@Sun.COM>
parents: 7509
diff changeset
   580
	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
   581
51e9ca9ee3a5 6572357 libzfs should do more to avoid mnttab lookups
Eric Taylor <Eric.Taylor@Sun.COM>
parents: 7509
diff changeset
   582
	if (rv == 0)
51e9ca9ee3a5 6572357 libzfs should do more to avoid mnttab lookups
Eric Taylor <Eric.Taylor@Sun.COM>
parents: 7509
diff changeset
   583
		return (0);
51e9ca9ee3a5 6572357 libzfs should do more to avoid mnttab lookups
Eric Taylor <Eric.Taylor@Sun.COM>
parents: 7509
diff changeset
   584
	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
   585
}
51e9ca9ee3a5 6572357 libzfs should do more to avoid mnttab lookups
Eric Taylor <Eric.Taylor@Sun.COM>
parents: 7509
diff changeset
   586
51e9ca9ee3a5 6572357 libzfs should do more to avoid mnttab lookups
Eric Taylor <Eric.Taylor@Sun.COM>
parents: 7509
diff changeset
   587
void
51e9ca9ee3a5 6572357 libzfs should do more to avoid mnttab lookups
Eric Taylor <Eric.Taylor@Sun.COM>
parents: 7509
diff changeset
   588
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
   589
{
51e9ca9ee3a5 6572357 libzfs should do more to avoid mnttab lookups
Eric Taylor <Eric.Taylor@Sun.COM>
parents: 7509
diff changeset
   590
	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
   591
	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
   592
	    sizeof (mnttab_node_t), offsetof(mnttab_node_t, mtn_node));
8811
f8deccf701cf 6790687 libzfs mnttab caching ignores external changes
Eric Taylor <Eric.Taylor@Sun.COM>
parents: 8802
diff changeset
   593
}
f8deccf701cf 6790687 libzfs mnttab caching ignores external changes
Eric Taylor <Eric.Taylor@Sun.COM>
parents: 8802
diff changeset
   594
f8deccf701cf 6790687 libzfs mnttab caching ignores external changes
Eric Taylor <Eric.Taylor@Sun.COM>
parents: 8802
diff changeset
   595
void
f8deccf701cf 6790687 libzfs mnttab caching ignores external changes
Eric Taylor <Eric.Taylor@Sun.COM>
parents: 8802
diff changeset
   596
libzfs_mnttab_update(libzfs_handle_t *hdl)
f8deccf701cf 6790687 libzfs mnttab caching ignores external changes
Eric Taylor <Eric.Taylor@Sun.COM>
parents: 8802
diff changeset
   597
{
f8deccf701cf 6790687 libzfs mnttab caching ignores external changes
Eric Taylor <Eric.Taylor@Sun.COM>
parents: 8802
diff changeset
   598
	struct mnttab entry;
8228
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
	rewind(hdl->libzfs_mnttab);
51e9ca9ee3a5 6572357 libzfs should do more to avoid mnttab lookups
Eric Taylor <Eric.Taylor@Sun.COM>
parents: 7509
diff changeset
   601
	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
   602
		mnttab_node_t *mtn;
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
		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
   605
			continue;
51e9ca9ee3a5 6572357 libzfs should do more to avoid mnttab lookups
Eric Taylor <Eric.Taylor@Sun.COM>
parents: 7509
diff changeset
   606
		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
   607
		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
   608
		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
   609
		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
   610
		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
   611
		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
   612
	}
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
51e9ca9ee3a5 6572357 libzfs should do more to avoid mnttab lookups
Eric Taylor <Eric.Taylor@Sun.COM>
parents: 7509
diff changeset
   615
void
51e9ca9ee3a5 6572357 libzfs should do more to avoid mnttab lookups
Eric Taylor <Eric.Taylor@Sun.COM>
parents: 7509
diff changeset
   616
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
   617
{
51e9ca9ee3a5 6572357 libzfs should do more to avoid mnttab lookups
Eric Taylor <Eric.Taylor@Sun.COM>
parents: 7509
diff changeset
   618
	void *cookie = NULL;
51e9ca9ee3a5 6572357 libzfs should do more to avoid mnttab lookups
Eric Taylor <Eric.Taylor@Sun.COM>
parents: 7509
diff changeset
   619
	mnttab_node_t *mtn;
51e9ca9ee3a5 6572357 libzfs should do more to avoid mnttab lookups
Eric Taylor <Eric.Taylor@Sun.COM>
parents: 7509
diff changeset
   620
51e9ca9ee3a5 6572357 libzfs should do more to avoid mnttab lookups
Eric Taylor <Eric.Taylor@Sun.COM>
parents: 7509
diff changeset
   621
	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
   622
		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
   623
		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
   624
		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
   625
		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
   626
		free(mtn);
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
	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
   629
}
51e9ca9ee3a5 6572357 libzfs should do more to avoid mnttab lookups
Eric Taylor <Eric.Taylor@Sun.COM>
parents: 7509
diff changeset
   630
8811
f8deccf701cf 6790687 libzfs mnttab caching ignores external changes
Eric Taylor <Eric.Taylor@Sun.COM>
parents: 8802
diff changeset
   631
void
f8deccf701cf 6790687 libzfs mnttab caching ignores external changes
Eric Taylor <Eric.Taylor@Sun.COM>
parents: 8802
diff changeset
   632
libzfs_mnttab_cache(libzfs_handle_t *hdl, boolean_t enable)
f8deccf701cf 6790687 libzfs mnttab caching ignores external changes
Eric Taylor <Eric.Taylor@Sun.COM>
parents: 8802
diff changeset
   633
{
f8deccf701cf 6790687 libzfs mnttab caching ignores external changes
Eric Taylor <Eric.Taylor@Sun.COM>
parents: 8802
diff changeset
   634
	hdl->libzfs_mnttab_enable = enable;
f8deccf701cf 6790687 libzfs mnttab caching ignores external changes
Eric Taylor <Eric.Taylor@Sun.COM>
parents: 8802
diff changeset
   635
}
f8deccf701cf 6790687 libzfs mnttab caching ignores external changes
Eric Taylor <Eric.Taylor@Sun.COM>
parents: 8802
diff changeset
   636
8228
51e9ca9ee3a5 6572357 libzfs should do more to avoid mnttab lookups
Eric Taylor <Eric.Taylor@Sun.COM>
parents: 7509
diff changeset
   637
int
51e9ca9ee3a5 6572357 libzfs should do more to avoid mnttab lookups
Eric Taylor <Eric.Taylor@Sun.COM>
parents: 7509
diff changeset
   638
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
   639
    struct mnttab *entry)
51e9ca9ee3a5 6572357 libzfs should do more to avoid mnttab lookups
Eric Taylor <Eric.Taylor@Sun.COM>
parents: 7509
diff changeset
   640
{
51e9ca9ee3a5 6572357 libzfs should do more to avoid mnttab lookups
Eric Taylor <Eric.Taylor@Sun.COM>
parents: 7509
diff changeset
   641
	mnttab_node_t find;
51e9ca9ee3a5 6572357 libzfs should do more to avoid mnttab lookups
Eric Taylor <Eric.Taylor@Sun.COM>
parents: 7509
diff changeset
   642
	mnttab_node_t *mtn;
51e9ca9ee3a5 6572357 libzfs should do more to avoid mnttab lookups
Eric Taylor <Eric.Taylor@Sun.COM>
parents: 7509
diff changeset
   643
8811
f8deccf701cf 6790687 libzfs mnttab caching ignores external changes
Eric Taylor <Eric.Taylor@Sun.COM>
parents: 8802
diff changeset
   644
	if (!hdl->libzfs_mnttab_enable) {
f8deccf701cf 6790687 libzfs mnttab caching ignores external changes
Eric Taylor <Eric.Taylor@Sun.COM>
parents: 8802
diff changeset
   645
		struct mnttab srch = { 0 };
f8deccf701cf 6790687 libzfs mnttab caching ignores external changes
Eric Taylor <Eric.Taylor@Sun.COM>
parents: 8802
diff changeset
   646
f8deccf701cf 6790687 libzfs mnttab caching ignores external changes
Eric Taylor <Eric.Taylor@Sun.COM>
parents: 8802
diff changeset
   647
		if (avl_numnodes(&hdl->libzfs_mnttab_cache))
f8deccf701cf 6790687 libzfs mnttab caching ignores external changes
Eric Taylor <Eric.Taylor@Sun.COM>
parents: 8802
diff changeset
   648
			libzfs_mnttab_fini(hdl);
f8deccf701cf 6790687 libzfs mnttab caching ignores external changes
Eric Taylor <Eric.Taylor@Sun.COM>
parents: 8802
diff changeset
   649
		rewind(hdl->libzfs_mnttab);
f8deccf701cf 6790687 libzfs mnttab caching ignores external changes
Eric Taylor <Eric.Taylor@Sun.COM>
parents: 8802
diff changeset
   650
		srch.mnt_special = (char *)fsname;
f8deccf701cf 6790687 libzfs mnttab caching ignores external changes
Eric Taylor <Eric.Taylor@Sun.COM>
parents: 8802
diff changeset
   651
		srch.mnt_fstype = MNTTYPE_ZFS;
f8deccf701cf 6790687 libzfs mnttab caching ignores external changes
Eric Taylor <Eric.Taylor@Sun.COM>
parents: 8802
diff changeset
   652
		if (getmntany(hdl->libzfs_mnttab, entry, &srch) == 0)
f8deccf701cf 6790687 libzfs mnttab caching ignores external changes
Eric Taylor <Eric.Taylor@Sun.COM>
parents: 8802
diff changeset
   653
			return (0);
f8deccf701cf 6790687 libzfs mnttab caching ignores external changes
Eric Taylor <Eric.Taylor@Sun.COM>
parents: 8802
diff changeset
   654
		else
f8deccf701cf 6790687 libzfs mnttab caching ignores external changes
Eric Taylor <Eric.Taylor@Sun.COM>
parents: 8802
diff changeset
   655
			return (ENOENT);
f8deccf701cf 6790687 libzfs mnttab caching ignores external changes
Eric Taylor <Eric.Taylor@Sun.COM>
parents: 8802
diff changeset
   656
	}
f8deccf701cf 6790687 libzfs mnttab caching ignores external changes
Eric Taylor <Eric.Taylor@Sun.COM>
parents: 8802
diff changeset
   657
8228
51e9ca9ee3a5 6572357 libzfs should do more to avoid mnttab lookups
Eric Taylor <Eric.Taylor@Sun.COM>
parents: 7509
diff changeset
   658
	if (avl_numnodes(&hdl->libzfs_mnttab_cache) == 0)
8811
f8deccf701cf 6790687 libzfs mnttab caching ignores external changes
Eric Taylor <Eric.Taylor@Sun.COM>
parents: 8802
diff changeset
   659
		libzfs_mnttab_update(hdl);
8228
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
	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
   662
	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
   663
	if (mtn) {
51e9ca9ee3a5 6572357 libzfs should do more to avoid mnttab lookups
Eric Taylor <Eric.Taylor@Sun.COM>
parents: 7509
diff changeset
   664
		*entry = mtn->mtn_mt;
51e9ca9ee3a5 6572357 libzfs should do more to avoid mnttab lookups
Eric Taylor <Eric.Taylor@Sun.COM>
parents: 7509
diff changeset
   665
		return (0);
51e9ca9ee3a5 6572357 libzfs should do more to avoid mnttab lookups
Eric Taylor <Eric.Taylor@Sun.COM>
parents: 7509
diff changeset
   666
	}
51e9ca9ee3a5 6572357 libzfs should do more to avoid mnttab lookups
Eric Taylor <Eric.Taylor@Sun.COM>
parents: 7509
diff changeset
   667
	return (ENOENT);
51e9ca9ee3a5 6572357 libzfs should do more to avoid mnttab lookups
Eric Taylor <Eric.Taylor@Sun.COM>
parents: 7509
diff changeset
   668
}
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
void
51e9ca9ee3a5 6572357 libzfs should do more to avoid mnttab lookups
Eric Taylor <Eric.Taylor@Sun.COM>
parents: 7509
diff changeset
   671
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
   672
    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
   673
{
51e9ca9ee3a5 6572357 libzfs should do more to avoid mnttab lookups
Eric Taylor <Eric.Taylor@Sun.COM>
parents: 7509
diff changeset
   674
	mnttab_node_t *mtn;
51e9ca9ee3a5 6572357 libzfs should do more to avoid mnttab lookups
Eric Taylor <Eric.Taylor@Sun.COM>
parents: 7509
diff changeset
   675
51e9ca9ee3a5 6572357 libzfs should do more to avoid mnttab lookups
Eric Taylor <Eric.Taylor@Sun.COM>
parents: 7509
diff changeset
   676
	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
   677
		return;
51e9ca9ee3a5 6572357 libzfs should do more to avoid mnttab lookups
Eric Taylor <Eric.Taylor@Sun.COM>
parents: 7509
diff changeset
   678
	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
   679
	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
   680
	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
   681
	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
   682
	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
   683
	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
   684
}
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
void
51e9ca9ee3a5 6572357 libzfs should do more to avoid mnttab lookups
Eric Taylor <Eric.Taylor@Sun.COM>
parents: 7509
diff changeset
   687
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
   688
{
51e9ca9ee3a5 6572357 libzfs should do more to avoid mnttab lookups
Eric Taylor <Eric.Taylor@Sun.COM>
parents: 7509
diff changeset
   689
	mnttab_node_t find;
51e9ca9ee3a5 6572357 libzfs should do more to avoid mnttab lookups
Eric Taylor <Eric.Taylor@Sun.COM>
parents: 7509
diff changeset
   690
	mnttab_node_t *ret;
51e9ca9ee3a5 6572357 libzfs should do more to avoid mnttab lookups
Eric Taylor <Eric.Taylor@Sun.COM>
parents: 7509
diff changeset
   691
51e9ca9ee3a5 6572357 libzfs should do more to avoid mnttab lookups
Eric Taylor <Eric.Taylor@Sun.COM>
parents: 7509
diff changeset
   692
	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
   693
	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
   694
		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
   695
		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
   696
		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
   697
		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
   698
		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
   699
		free(ret);
51e9ca9ee3a5 6572357 libzfs should do more to avoid mnttab lookups
Eric Taylor <Eric.Taylor@Sun.COM>
parents: 7509
diff changeset
   700
	}
51e9ca9ee3a5 6572357 libzfs should do more to avoid mnttab lookups
Eric Taylor <Eric.Taylor@Sun.COM>
parents: 7509
diff changeset
   701
}
51e9ca9ee3a5 6572357 libzfs should do more to avoid mnttab lookups
Eric Taylor <Eric.Taylor@Sun.COM>
parents: 7509
diff changeset
   702
5713
f9b7933f3770 PSARC/2007/675 A_MDEV Removal
rm160521
parents: 5592
diff changeset
   703
int
f9b7933f3770 PSARC/2007/675 A_MDEV Removal
rm160521
parents: 5592
diff changeset
   704
zfs_spa_version(zfs_handle_t *zhp, int *spa_version)
f9b7933f3770 PSARC/2007/675 A_MDEV Removal
rm160521
parents: 5592
diff changeset
   705
{
6865
176d18c623cc 6539380 zfs list uses too much memory
rm160521
parents: 6612
diff changeset
   706
	zpool_handle_t *zpool_handle = zhp->zpool_hdl;
176d18c623cc 6539380 zfs list uses too much memory
rm160521
parents: 6612
diff changeset
   707
5713
f9b7933f3770 PSARC/2007/675 A_MDEV Removal
rm160521
parents: 5592
diff changeset
   708
	if (zpool_handle == NULL)
f9b7933f3770 PSARC/2007/675 A_MDEV Removal
rm160521
parents: 5592
diff changeset
   709
		return (-1);
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
	*spa_version = zpool_get_prop_int(zpool_handle,
f9b7933f3770 PSARC/2007/675 A_MDEV Removal
rm160521
parents: 5592
diff changeset
   712
	    ZPOOL_PROP_VERSION, NULL);
f9b7933f3770 PSARC/2007/675 A_MDEV Removal
rm160521
parents: 5592
diff changeset
   713
	return (0);
f9b7933f3770 PSARC/2007/675 A_MDEV Removal
rm160521
parents: 5592
diff changeset
   714
}
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
/*
f9b7933f3770 PSARC/2007/675 A_MDEV Removal
rm160521
parents: 5592
diff changeset
   717
 * The choice of reservation property depends on the SPA version.
f9b7933f3770 PSARC/2007/675 A_MDEV Removal
rm160521
parents: 5592
diff changeset
   718
 */
f9b7933f3770 PSARC/2007/675 A_MDEV Removal
rm160521
parents: 5592
diff changeset
   719
static int
f9b7933f3770 PSARC/2007/675 A_MDEV Removal
rm160521
parents: 5592
diff changeset
   720
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
   721
{
f9b7933f3770 PSARC/2007/675 A_MDEV Removal
rm160521
parents: 5592
diff changeset
   722
	int spa_version;
f9b7933f3770 PSARC/2007/675 A_MDEV Removal
rm160521
parents: 5592
diff changeset
   723
f9b7933f3770 PSARC/2007/675 A_MDEV Removal
rm160521
parents: 5592
diff changeset
   724
	if (zfs_spa_version(zhp, &spa_version) < 0)
f9b7933f3770 PSARC/2007/675 A_MDEV Removal
rm160521
parents: 5592
diff changeset
   725
		return (-1);
f9b7933f3770 PSARC/2007/675 A_MDEV Removal
rm160521
parents: 5592
diff changeset
   726
f9b7933f3770 PSARC/2007/675 A_MDEV Removal
rm160521
parents: 5592
diff changeset
   727
	if (spa_version >= SPA_VERSION_REFRESERVATION)
f9b7933f3770 PSARC/2007/675 A_MDEV Removal
rm160521
parents: 5592
diff changeset
   728
		*resv_prop = ZFS_PROP_REFRESERVATION;
f9b7933f3770 PSARC/2007/675 A_MDEV Removal
rm160521
parents: 5592
diff changeset
   729
	else
f9b7933f3770 PSARC/2007/675 A_MDEV Removal
rm160521
parents: 5592
diff changeset
   730
		*resv_prop = ZFS_PROP_RESERVATION;
f9b7933f3770 PSARC/2007/675 A_MDEV Removal
rm160521
parents: 5592
diff changeset
   731
f9b7933f3770 PSARC/2007/675 A_MDEV Removal
rm160521
parents: 5592
diff changeset
   732
	return (0);
f9b7933f3770 PSARC/2007/675 A_MDEV Removal
rm160521
parents: 5592
diff changeset
   733
}
f9b7933f3770 PSARC/2007/675 A_MDEV Removal
rm160521
parents: 5592
diff changeset
   734
3912
f6891a60bd72 PSARC 2007/083 ZFS bootable datasets
lling
parents: 3886
diff changeset
   735
/*
2676
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
   736
 * 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
   737
 * parses any numeric properties (index, boolean, etc) if they are specified as
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
   738
 * strings.
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   739
 */
7184
9508660f9c27 PSARC 2008/223 Pool root file system properties via zpool(1M)
timh
parents: 7042
diff changeset
   740
nvlist_t *
9508660f9c27 PSARC 2008/223 Pool root file system properties via zpool(1M)
timh
parents: 7042
diff changeset
   741
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
   742
    uint64_t zoned, zfs_handle_t *zhp, const char *errbuf)
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   743
{
2676
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
   744
	nvpair_t *elem;
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
   745
	uint64_t intval;
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
   746
	char *strval;
5094
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4861
diff changeset
   747
	zfs_prop_t prop;
2676
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
   748
	nvlist_t *ret;
5331
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5326
diff changeset
   749
	int chosen_normal = -1;
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5326
diff changeset
   750
	int chosen_utf = -1;
2676
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
   751
5094
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4861
diff changeset
   752
	if (nvlist_alloc(&ret, NV_UNIQUE_NAME, 0) != 0) {
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4861
diff changeset
   753
		(void) no_memory(hdl);
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4861
diff changeset
   754
		return (NULL);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   755
	}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   756
9396
f41cf682d0d3 PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 8845
diff changeset
   757
	/*
f41cf682d0d3 PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 8845
diff changeset
   758
	 * Make sure this property is valid and applies to this type.
f41cf682d0d3 PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 8845
diff changeset
   759
	 */
f41cf682d0d3 PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 8845
diff changeset
   760
2676
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
   761
	elem = NULL;
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
   762
	while ((elem = nvlist_next_nvpair(nvl, elem)) != NULL) {
5094
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4861
diff changeset
   763
		const char *propname = nvpair_name(elem);
2676
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
   764
9396
f41cf682d0d3 PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 8845
diff changeset
   765
		prop = zfs_name_to_prop(propname);
f41cf682d0d3 PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 8845
diff changeset
   766
		if (prop == ZPROP_INVAL && zfs_prop_user(propname)) {
5094
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4861
diff changeset
   767
			/*
9396
f41cf682d0d3 PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 8845
diff changeset
   768
			 * This is a user property: make sure it's a
5094
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4861
diff changeset
   769
			 * string, and that it's less than ZAP_MAXNAMELEN.
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4861
diff changeset
   770
			 */
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4861
diff changeset
   771
			if (nvpair_type(elem) != DATA_TYPE_STRING) {
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4861
diff changeset
   772
				zfs_error_aux(hdl, dgettext(TEXT_DOMAIN,
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4861
diff changeset
   773
				    "'%s' must be a string"), propname);
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4861
diff changeset
   774
				(void) zfs_error(hdl, EZFS_BADPROP, errbuf);
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4861
diff changeset
   775
				goto error;
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
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4861
diff changeset
   778
			if (strlen(nvpair_name(elem)) >= ZAP_MAXNAMELEN) {
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4861
diff changeset
   779
				zfs_error_aux(hdl, dgettext(TEXT_DOMAIN,
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4861
diff changeset
   780
				    "property name '%s' is too long"),
2676
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
   781
				    propname);
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
   782
				(void) zfs_error(hdl, EZFS_BADPROP, errbuf);
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
   783
				goto error;
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
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
   786
			(void) nvpair_value_string(elem, &strval);
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
   787
			if (nvlist_add_string(ret, propname, strval) != 0) {
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
   788
				(void) no_memory(hdl);
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
   789
				goto error;
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
   790
			}
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
   791
			continue;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   792
		}
2676
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
   793
9396
f41cf682d0d3 PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 8845
diff changeset
   794
		/*
f41cf682d0d3 PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 8845
diff changeset
   795
		 * Currently, only user properties can be modified on
f41cf682d0d3 PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 8845
diff changeset
   796
		 * snapshots.
f41cf682d0d3 PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 8845
diff changeset
   797
		 */
7265
cc18862247da PSARC/2008/483 ZFS clone -o
ahrens
parents: 7184
diff changeset
   798
		if (type == ZFS_TYPE_SNAPSHOT) {
cc18862247da PSARC/2008/483 ZFS clone -o
ahrens
parents: 7184
diff changeset
   799
			zfs_error_aux(hdl, dgettext(TEXT_DOMAIN,
cc18862247da PSARC/2008/483 ZFS clone -o
ahrens
parents: 7184
diff changeset
   800
			    "this property can not be modified for snapshots"));
cc18862247da PSARC/2008/483 ZFS clone -o
ahrens
parents: 7184
diff changeset
   801
			(void) zfs_error(hdl, EZFS_PROPTYPE, errbuf);
cc18862247da PSARC/2008/483 ZFS clone -o
ahrens
parents: 7184
diff changeset
   802
			goto error;
cc18862247da PSARC/2008/483 ZFS clone -o
ahrens
parents: 7184
diff changeset
   803
		}
cc18862247da PSARC/2008/483 ZFS clone -o
ahrens
parents: 7184
diff changeset
   804
9396
f41cf682d0d3 PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 8845
diff changeset
   805
		if (prop == ZPROP_INVAL && zfs_prop_userquota(propname)) {
f41cf682d0d3 PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 8845
diff changeset
   806
			zfs_userquota_prop_t uqtype;
f41cf682d0d3 PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 8845
diff changeset
   807
			char newpropname[128];
f41cf682d0d3 PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 8845
diff changeset
   808
			char domain[128];
f41cf682d0d3 PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 8845
diff changeset
   809
			uint64_t rid;
f41cf682d0d3 PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 8845
diff changeset
   810
			uint64_t valary[3];
f41cf682d0d3 PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 8845
diff changeset
   811
f41cf682d0d3 PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 8845
diff changeset
   812
			if (userquota_propname_decode(propname, zoned,
f41cf682d0d3 PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 8845
diff changeset
   813
			    &uqtype, domain, sizeof (domain), &rid) != 0) {
f41cf682d0d3 PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 8845
diff changeset
   814
				zfs_error_aux(hdl,
f41cf682d0d3 PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 8845
diff changeset
   815
				    dgettext(TEXT_DOMAIN,
f41cf682d0d3 PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 8845
diff changeset
   816
				    "'%s' has an invalid user/group name"),
f41cf682d0d3 PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 8845
diff changeset
   817
				    propname);
f41cf682d0d3 PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 8845
diff changeset
   818
				(void) zfs_error(hdl, EZFS_BADPROP, errbuf);
f41cf682d0d3 PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 8845
diff changeset
   819
				goto error;
f41cf682d0d3 PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 8845
diff changeset
   820
			}
f41cf682d0d3 PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 8845
diff changeset
   821
f41cf682d0d3 PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 8845
diff changeset
   822
			if (uqtype != ZFS_PROP_USERQUOTA &&
f41cf682d0d3 PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 8845
diff changeset
   823
			    uqtype != ZFS_PROP_GROUPQUOTA) {
f41cf682d0d3 PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 8845
diff changeset
   824
				zfs_error_aux(hdl,
f41cf682d0d3 PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 8845
diff changeset
   825
				    dgettext(TEXT_DOMAIN, "'%s' is readonly"),
f41cf682d0d3 PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 8845
diff changeset
   826
				    propname);
f41cf682d0d3 PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 8845
diff changeset
   827
				(void) zfs_error(hdl, EZFS_PROPREADONLY,
f41cf682d0d3 PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 8845
diff changeset
   828
				    errbuf);
f41cf682d0d3 PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 8845
diff changeset
   829
				goto error;
f41cf682d0d3 PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 8845
diff changeset
   830
			}
f41cf682d0d3 PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 8845
diff changeset
   831
f41cf682d0d3 PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 8845
diff changeset
   832
			if (nvpair_type(elem) == DATA_TYPE_STRING) {
f41cf682d0d3 PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 8845
diff changeset
   833
				(void) nvpair_value_string(elem, &strval);
f41cf682d0d3 PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 8845
diff changeset
   834
				if (strcmp(strval, "none") == 0) {
f41cf682d0d3 PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 8845
diff changeset
   835
					intval = 0;
f41cf682d0d3 PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 8845
diff changeset
   836
				} else if (zfs_nicestrtonum(hdl,
f41cf682d0d3 PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 8845
diff changeset
   837
				    strval, &intval) != 0) {
f41cf682d0d3 PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 8845
diff changeset
   838
					(void) zfs_error(hdl,
f41cf682d0d3 PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 8845
diff changeset
   839
					    EZFS_BADPROP, errbuf);
f41cf682d0d3 PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 8845
diff changeset
   840
					goto error;
f41cf682d0d3 PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 8845
diff changeset
   841
				}
f41cf682d0d3 PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 8845
diff changeset
   842
			} else if (nvpair_type(elem) ==
f41cf682d0d3 PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 8845
diff changeset
   843
			    DATA_TYPE_UINT64) {
f41cf682d0d3 PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 8845
diff changeset
   844
				(void) nvpair_value_uint64(elem, &intval);
f41cf682d0d3 PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 8845
diff changeset
   845
				if (intval == 0) {
f41cf682d0d3 PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 8845
diff changeset
   846
					zfs_error_aux(hdl, dgettext(TEXT_DOMAIN,
f41cf682d0d3 PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 8845
diff changeset
   847
					    "use 'none' to disable "
f41cf682d0d3 PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 8845
diff changeset
   848
					    "userquota/groupquota"));
f41cf682d0d3 PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 8845
diff changeset
   849
					goto error;
f41cf682d0d3 PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 8845
diff changeset
   850
				}
f41cf682d0d3 PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 8845
diff changeset
   851
			} else {
f41cf682d0d3 PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 8845
diff changeset
   852
				zfs_error_aux(hdl, dgettext(TEXT_DOMAIN,
f41cf682d0d3 PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 8845
diff changeset
   853
				    "'%s' must be a number"), propname);
f41cf682d0d3 PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 8845
diff changeset
   854
				(void) zfs_error(hdl, EZFS_BADPROP, errbuf);
f41cf682d0d3 PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 8845
diff changeset
   855
				goto error;
f41cf682d0d3 PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 8845
diff changeset
   856
			}
f41cf682d0d3 PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 8845
diff changeset
   857
10969
ed9b19e85c90 6893929 User/group quotas passed to "zfs create" are not properly set
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 10960
diff changeset
   858
			/*
ed9b19e85c90 6893929 User/group quotas passed to "zfs create" are not properly set
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 10960
diff changeset
   859
			 * Encode the prop name as
ed9b19e85c90 6893929 User/group quotas passed to "zfs create" are not properly set
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 10960
diff changeset
   860
			 * userquota@<hex-rid>-domain, to make it easy
ed9b19e85c90 6893929 User/group quotas passed to "zfs create" are not properly set
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 10960
diff changeset
   861
			 * for the kernel to decode.
ed9b19e85c90 6893929 User/group quotas passed to "zfs create" are not properly set
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 10960
diff changeset
   862
			 */
9396
f41cf682d0d3 PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 8845
diff changeset
   863
			(void) snprintf(newpropname, sizeof (newpropname),
10969
ed9b19e85c90 6893929 User/group quotas passed to "zfs create" are not properly set
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 10960
diff changeset
   864
			    "%s%llx-%s", zfs_userquota_prop_prefixes[uqtype],
ed9b19e85c90 6893929 User/group quotas passed to "zfs create" are not properly set
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 10960
diff changeset
   865
			    (longlong_t)rid, domain);
9396
f41cf682d0d3 PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 8845
diff changeset
   866
			valary[0] = uqtype;
f41cf682d0d3 PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 8845
diff changeset
   867
			valary[1] = rid;
f41cf682d0d3 PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 8845
diff changeset
   868
			valary[2] = intval;
f41cf682d0d3 PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 8845
diff changeset
   869
			if (nvlist_add_uint64_array(ret, newpropname,
f41cf682d0d3 PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 8845
diff changeset
   870
			    valary, 3) != 0) {
f41cf682d0d3 PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 8845
diff changeset
   871
				(void) no_memory(hdl);
f41cf682d0d3 PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 8845
diff changeset
   872
				goto error;
f41cf682d0d3 PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 8845
diff changeset
   873
			}
f41cf682d0d3 PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 8845
diff changeset
   874
			continue;
f41cf682d0d3 PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 8845
diff changeset
   875
		}
f41cf682d0d3 PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 8845
diff changeset
   876
f41cf682d0d3 PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 8845
diff changeset
   877
		if (prop == ZPROP_INVAL) {
f41cf682d0d3 PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 8845
diff changeset
   878
			zfs_error_aux(hdl, dgettext(TEXT_DOMAIN,
f41cf682d0d3 PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 8845
diff changeset
   879
			    "invalid property '%s'"), propname);
f41cf682d0d3 PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 8845
diff changeset
   880
			(void) zfs_error(hdl, EZFS_BADPROP, errbuf);
f41cf682d0d3 PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 8845
diff changeset
   881
			goto error;
f41cf682d0d3 PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 8845
diff changeset
   882
		}
f41cf682d0d3 PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 8845
diff changeset
   883
2676
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
   884
		if (!zfs_prop_valid_for_type(prop, type)) {
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
   885
			zfs_error_aux(hdl,
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
   886
			    dgettext(TEXT_DOMAIN, "'%s' does not "
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
   887
			    "apply to datasets of this type"), propname);
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
   888
			(void) zfs_error(hdl, EZFS_PROPTYPE, errbuf);
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
   889
			goto error;
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
   890
		}
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
   891
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
   892
		if (zfs_prop_readonly(prop) &&
5331
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5326
diff changeset
   893
		    (!zfs_prop_setonce(prop) || zhp != NULL)) {
2676
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
   894
			zfs_error_aux(hdl,
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
   895
			    dgettext(TEXT_DOMAIN, "'%s' is readonly"),
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
   896
			    propname);
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
   897
			(void) zfs_error(hdl, EZFS_PROPREADONLY, errbuf);
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
   898
			goto error;
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
   899
		}
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
   900
5094
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4861
diff changeset
   901
		if (zprop_parse_value(hdl, elem, prop, type, ret,
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4861
diff changeset
   902
		    &strval, &intval, errbuf) != 0)
2676
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
   903
			goto error;
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
   904
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
   905
		/*
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
   906
		 * Perform some additional checks for specific properties.
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
   907
		 */
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
   908
		switch (prop) {
4577
ed36b0e652bc PSARC/2007/328 zfs upgrade
ahrens
parents: 4543
diff changeset
   909
		case ZFS_PROP_VERSION:
ed36b0e652bc PSARC/2007/328 zfs upgrade
ahrens
parents: 4543
diff changeset
   910
		{
ed36b0e652bc PSARC/2007/328 zfs upgrade
ahrens
parents: 4543
diff changeset
   911
			int version;
ed36b0e652bc PSARC/2007/328 zfs upgrade
ahrens
parents: 4543
diff changeset
   912
ed36b0e652bc PSARC/2007/328 zfs upgrade
ahrens
parents: 4543
diff changeset
   913
			if (zhp == NULL)
ed36b0e652bc PSARC/2007/328 zfs upgrade
ahrens
parents: 4543
diff changeset
   914
				break;
ed36b0e652bc PSARC/2007/328 zfs upgrade
ahrens
parents: 4543
diff changeset
   915
			version = zfs_prop_get_int(zhp, ZFS_PROP_VERSION);
ed36b0e652bc PSARC/2007/328 zfs upgrade
ahrens
parents: 4543
diff changeset
   916
			if (intval < version) {
ed36b0e652bc PSARC/2007/328 zfs upgrade
ahrens
parents: 4543
diff changeset
   917
				zfs_error_aux(hdl, dgettext(TEXT_DOMAIN,
ed36b0e652bc PSARC/2007/328 zfs upgrade
ahrens
parents: 4543
diff changeset
   918
				    "Can not downgrade; already at version %u"),
ed36b0e652bc PSARC/2007/328 zfs upgrade
ahrens
parents: 4543
diff changeset
   919
				    version);
ed36b0e652bc PSARC/2007/328 zfs upgrade
ahrens
parents: 4543
diff changeset
   920
				(void) zfs_error(hdl, EZFS_BADPROP, errbuf);
ed36b0e652bc PSARC/2007/328 zfs upgrade
ahrens
parents: 4543
diff changeset
   921
				goto error;
ed36b0e652bc PSARC/2007/328 zfs upgrade
ahrens
parents: 4543
diff changeset
   922
			}
ed36b0e652bc PSARC/2007/328 zfs upgrade
ahrens
parents: 4543
diff changeset
   923
			break;
ed36b0e652bc PSARC/2007/328 zfs upgrade
ahrens
parents: 4543
diff changeset
   924
		}
ed36b0e652bc PSARC/2007/328 zfs upgrade
ahrens
parents: 4543
diff changeset
   925
2676
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
   926
		case ZFS_PROP_RECORDSIZE:
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
   927
		case ZFS_PROP_VOLBLOCKSIZE:
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
   928
			/* must be power of two within SPA_{MIN,MAX}BLOCKSIZE */
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
   929
			if (intval < SPA_MINBLOCKSIZE ||
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
   930
			    intval > SPA_MAXBLOCKSIZE || !ISP2(intval)) {
2082
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1793
diff changeset
   931
				zfs_error_aux(hdl, dgettext(TEXT_DOMAIN,
2676
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
   932
				    "'%s' must be power of 2 from %u "
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
   933
				    "to %uk"), propname,
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
   934
				    (uint_t)SPA_MINBLOCKSIZE,
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
   935
				    (uint_t)SPA_MAXBLOCKSIZE >> 10);
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
   936
				(void) zfs_error(hdl, EZFS_BADPROP, errbuf);
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
   937
				goto error;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   938
			}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   939
			break;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   940
3126
4f4fb617fdd0 PSARC 2006/622 iSCSI/ZFS Integration
ahl
parents: 2885
diff changeset
   941
		case ZFS_PROP_SHAREISCSI:
4f4fb617fdd0 PSARC 2006/622 iSCSI/ZFS Integration
ahl
parents: 2885
diff changeset
   942
			if (strcmp(strval, "off") != 0 &&
4f4fb617fdd0 PSARC 2006/622 iSCSI/ZFS Integration
ahl
parents: 2885
diff changeset
   943
			    strcmp(strval, "on") != 0 &&
4f4fb617fdd0 PSARC 2006/622 iSCSI/ZFS Integration
ahl
parents: 2885
diff changeset
   944
			    strcmp(strval, "type=disk") != 0) {
4f4fb617fdd0 PSARC 2006/622 iSCSI/ZFS Integration
ahl
parents: 2885
diff changeset
   945
				zfs_error_aux(hdl, dgettext(TEXT_DOMAIN,
4f4fb617fdd0 PSARC 2006/622 iSCSI/ZFS Integration
ahl
parents: 2885
diff changeset
   946
				    "'%s' must be 'on', 'off', or 'type=disk'"),
4f4fb617fdd0 PSARC 2006/622 iSCSI/ZFS Integration
ahl
parents: 2885
diff changeset
   947
				    propname);
4f4fb617fdd0 PSARC 2006/622 iSCSI/ZFS Integration
ahl
parents: 2885
diff changeset
   948
				(void) zfs_error(hdl, EZFS_BADPROP, errbuf);
4f4fb617fdd0 PSARC 2006/622 iSCSI/ZFS Integration
ahl
parents: 2885
diff changeset
   949
				goto error;
4f4fb617fdd0 PSARC 2006/622 iSCSI/ZFS Integration
ahl
parents: 2885
diff changeset
   950
			}
4f4fb617fdd0 PSARC 2006/622 iSCSI/ZFS Integration
ahl
parents: 2885
diff changeset
   951
4f4fb617fdd0 PSARC 2006/622 iSCSI/ZFS Integration
ahl
parents: 2885
diff changeset
   952
			break;
4f4fb617fdd0 PSARC 2006/622 iSCSI/ZFS Integration
ahl
parents: 2885
diff changeset
   953
10972
807794d41b3a PSARC 2009/348 Security Labels for ZFS
Ric Aleshire <Ric.Aleshire@Sun.COM>
parents: 10969
diff changeset
   954
		case ZFS_PROP_MLSLABEL:
807794d41b3a PSARC 2009/348 Security Labels for ZFS
Ric Aleshire <Ric.Aleshire@Sun.COM>
parents: 10969
diff changeset
   955
		{
807794d41b3a PSARC 2009/348 Security Labels for ZFS
Ric Aleshire <Ric.Aleshire@Sun.COM>
parents: 10969
diff changeset
   956
			/*
807794d41b3a PSARC 2009/348 Security Labels for ZFS
Ric Aleshire <Ric.Aleshire@Sun.COM>
parents: 10969
diff changeset
   957
			 * Verify the mlslabel string and convert to
807794d41b3a PSARC 2009/348 Security Labels for ZFS
Ric Aleshire <Ric.Aleshire@Sun.COM>
parents: 10969
diff changeset
   958
			 * internal hex label string.
807794d41b3a PSARC 2009/348 Security Labels for ZFS
Ric Aleshire <Ric.Aleshire@Sun.COM>
parents: 10969
diff changeset
   959
			 */
807794d41b3a PSARC 2009/348 Security Labels for ZFS
Ric Aleshire <Ric.Aleshire@Sun.COM>
parents: 10969
diff changeset
   960
807794d41b3a PSARC 2009/348 Security Labels for ZFS
Ric Aleshire <Ric.Aleshire@Sun.COM>
parents: 10969
diff changeset
   961
			m_label_t *new_sl;
807794d41b3a PSARC 2009/348 Security Labels for ZFS
Ric Aleshire <Ric.Aleshire@Sun.COM>
parents: 10969
diff changeset
   962
			char *hex = NULL;	/* internal label string */
807794d41b3a PSARC 2009/348 Security Labels for ZFS
Ric Aleshire <Ric.Aleshire@Sun.COM>
parents: 10969
diff changeset
   963
807794d41b3a PSARC 2009/348 Security Labels for ZFS
Ric Aleshire <Ric.Aleshire@Sun.COM>
parents: 10969
diff changeset
   964
			/* Default value is already OK. */
807794d41b3a PSARC 2009/348 Security Labels for ZFS
Ric Aleshire <Ric.Aleshire@Sun.COM>
parents: 10969
diff changeset
   965
			if (strcasecmp(strval, ZFS_MLSLABEL_DEFAULT) == 0)
807794d41b3a PSARC 2009/348 Security Labels for ZFS
Ric Aleshire <Ric.Aleshire@Sun.COM>
parents: 10969
diff changeset
   966
				break;
807794d41b3a PSARC 2009/348 Security Labels for ZFS
Ric Aleshire <Ric.Aleshire@Sun.COM>
parents: 10969
diff changeset
   967
807794d41b3a PSARC 2009/348 Security Labels for ZFS
Ric Aleshire <Ric.Aleshire@Sun.COM>
parents: 10969
diff changeset
   968
			/* Verify the label can be converted to binary form */
807794d41b3a PSARC 2009/348 Security Labels for ZFS
Ric Aleshire <Ric.Aleshire@Sun.COM>
parents: 10969
diff changeset
   969
			if (((new_sl = m_label_alloc(MAC_LABEL)) == NULL) ||
807794d41b3a PSARC 2009/348 Security Labels for ZFS
Ric Aleshire <Ric.Aleshire@Sun.COM>
parents: 10969
diff changeset
   970
			    (str_to_label(strval, &new_sl, MAC_LABEL,
807794d41b3a PSARC 2009/348 Security Labels for ZFS
Ric Aleshire <Ric.Aleshire@Sun.COM>
parents: 10969
diff changeset
   971
			    L_NO_CORRECTION, NULL) == -1)) {
807794d41b3a PSARC 2009/348 Security Labels for ZFS
Ric Aleshire <Ric.Aleshire@Sun.COM>
parents: 10969
diff changeset
   972
				goto badlabel;
807794d41b3a PSARC 2009/348 Security Labels for ZFS
Ric Aleshire <Ric.Aleshire@Sun.COM>
parents: 10969
diff changeset
   973
			}
807794d41b3a PSARC 2009/348 Security Labels for ZFS
Ric Aleshire <Ric.Aleshire@Sun.COM>
parents: 10969
diff changeset
   974
807794d41b3a PSARC 2009/348 Security Labels for ZFS
Ric Aleshire <Ric.Aleshire@Sun.COM>
parents: 10969
diff changeset
   975
			/* Now translate to hex internal label string */
807794d41b3a PSARC 2009/348 Security Labels for ZFS
Ric Aleshire <Ric.Aleshire@Sun.COM>
parents: 10969
diff changeset
   976
			if (label_to_str(new_sl, &hex, M_INTERNAL,
807794d41b3a PSARC 2009/348 Security Labels for ZFS
Ric Aleshire <Ric.Aleshire@Sun.COM>
parents: 10969
diff changeset
   977
			    DEF_NAMES) != 0) {
807794d41b3a PSARC 2009/348 Security Labels for ZFS
Ric Aleshire <Ric.Aleshire@Sun.COM>
parents: 10969
diff changeset
   978
				if (hex)
807794d41b3a PSARC 2009/348 Security Labels for ZFS
Ric Aleshire <Ric.Aleshire@Sun.COM>
parents: 10969
diff changeset
   979
					free(hex);
807794d41b3a PSARC 2009/348 Security Labels for ZFS
Ric Aleshire <Ric.Aleshire@Sun.COM>
parents: 10969
diff changeset
   980
				goto badlabel;
807794d41b3a PSARC 2009/348 Security Labels for ZFS
Ric Aleshire <Ric.Aleshire@Sun.COM>
parents: 10969
diff changeset
   981
			}
807794d41b3a PSARC 2009/348 Security Labels for ZFS
Ric Aleshire <Ric.Aleshire@Sun.COM>
parents: 10969
diff changeset
   982
			m_label_free(new_sl);
807794d41b3a PSARC 2009/348 Security Labels for ZFS
Ric Aleshire <Ric.Aleshire@Sun.COM>
parents: 10969
diff changeset
   983
807794d41b3a PSARC 2009/348 Security Labels for ZFS
Ric Aleshire <Ric.Aleshire@Sun.COM>
parents: 10969
diff changeset
   984
			/* If string is already in internal form, we're done. */
807794d41b3a PSARC 2009/348 Security Labels for ZFS
Ric Aleshire <Ric.Aleshire@Sun.COM>
parents: 10969
diff changeset
   985
			if (strcmp(strval, hex) == 0) {
807794d41b3a PSARC 2009/348 Security Labels for ZFS
Ric Aleshire <Ric.Aleshire@Sun.COM>
parents: 10969
diff changeset
   986
				free(hex);
807794d41b3a PSARC 2009/348 Security Labels for ZFS
Ric Aleshire <Ric.Aleshire@Sun.COM>
parents: 10969
diff changeset
   987
				break;
807794d41b3a PSARC 2009/348 Security Labels for ZFS
Ric Aleshire <Ric.Aleshire@Sun.COM>
parents: 10969
diff changeset
   988
			}
807794d41b3a PSARC 2009/348 Security Labels for ZFS
Ric Aleshire <Ric.Aleshire@Sun.COM>
parents: 10969
diff changeset
   989
807794d41b3a PSARC 2009/348 Security Labels for ZFS
Ric Aleshire <Ric.Aleshire@Sun.COM>
parents: 10969
diff changeset
   990
			/* Replace the label string with the internal form. */
10984
bf1fc133a515 6795907 Add label attribute to ZFS datasets (fix check_rtime and lint)
Ric Aleshire <Ric.Aleshire@Sun.COM>
parents: 10972
diff changeset
   991
			(void) nvlist_remove(ret, zfs_prop_to_name(prop),
10972
807794d41b3a PSARC 2009/348 Security Labels for ZFS
Ric Aleshire <Ric.Aleshire@Sun.COM>
parents: 10969
diff changeset
   992
			    DATA_TYPE_STRING);
807794d41b3a PSARC 2009/348 Security Labels for ZFS
Ric Aleshire <Ric.Aleshire@Sun.COM>
parents: 10969
diff changeset
   993
			verify(nvlist_add_string(ret, zfs_prop_to_name(prop),
807794d41b3a PSARC 2009/348 Security Labels for ZFS
Ric Aleshire <Ric.Aleshire@Sun.COM>
parents: 10969
diff changeset
   994
			    hex) == 0);
807794d41b3a PSARC 2009/348 Security Labels for ZFS
Ric Aleshire <Ric.Aleshire@Sun.COM>
parents: 10969
diff changeset
   995
			free(hex);
807794d41b3a PSARC 2009/348 Security Labels for ZFS
Ric Aleshire <Ric.Aleshire@Sun.COM>
parents: 10969
diff changeset
   996
807794d41b3a PSARC 2009/348 Security Labels for ZFS
Ric Aleshire <Ric.Aleshire@Sun.COM>
parents: 10969
diff changeset
   997
			break;
807794d41b3a PSARC 2009/348 Security Labels for ZFS
Ric Aleshire <Ric.Aleshire@Sun.COM>
parents: 10969
diff changeset
   998
807794d41b3a PSARC 2009/348 Security Labels for ZFS
Ric Aleshire <Ric.Aleshire@Sun.COM>
parents: 10969
diff changeset
   999
badlabel:
807794d41b3a PSARC 2009/348 Security Labels for ZFS
Ric Aleshire <Ric.Aleshire@Sun.COM>
parents: 10969
diff changeset
  1000
			zfs_error_aux(hdl, dgettext(TEXT_DOMAIN,
807794d41b3a PSARC 2009/348 Security Labels for ZFS
Ric Aleshire <Ric.Aleshire@Sun.COM>
parents: 10969
diff changeset
  1001
			    "invalid mlslabel '%s'"), strval);
807794d41b3a PSARC 2009/348 Security Labels for ZFS
Ric Aleshire <Ric.Aleshire@Sun.COM>
parents: 10969
diff changeset
  1002
			(void) zfs_error(hdl, EZFS_BADPROP, errbuf);
807794d41b3a PSARC 2009/348 Security Labels for ZFS
Ric Aleshire <Ric.Aleshire@Sun.COM>
parents: 10969
diff changeset
  1003
			m_label_free(new_sl);	/* OK if null */
807794d41b3a PSARC 2009/348 Security Labels for ZFS
Ric Aleshire <Ric.Aleshire@Sun.COM>
parents: 10969
diff changeset
  1004
			goto error;
807794d41b3a PSARC 2009/348 Security Labels for ZFS
Ric Aleshire <Ric.Aleshire@Sun.COM>
parents: 10969
diff changeset
  1005
807794d41b3a PSARC 2009/348 Security Labels for ZFS
Ric Aleshire <Ric.Aleshire@Sun.COM>
parents: 10969
diff changeset
  1006
		}
807794d41b3a PSARC 2009/348 Security Labels for ZFS
Ric Aleshire <Ric.Aleshire@Sun.COM>
parents: 10969
diff changeset
  1007
2676
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  1008
		case ZFS_PROP_MOUNTPOINT:
4778
068cf1db91f1 6446301 ZFS mountpoint reverted back from legacy but sharenfs property not honored
rm160521
parents: 4603
diff changeset
  1009
		{
068cf1db91f1 6446301 ZFS mountpoint reverted back from legacy but sharenfs property not honored
rm160521
parents: 4603
diff changeset
  1010
			namecheck_err_t why;
068cf1db91f1 6446301 ZFS mountpoint reverted back from legacy but sharenfs property not honored
rm160521
parents: 4603
diff changeset
  1011
2676
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  1012
			if (strcmp(strval, ZFS_MOUNTPOINT_NONE) == 0 ||
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  1013
			    strcmp(strval, ZFS_MOUNTPOINT_LEGACY) == 0)
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  1014
				break;
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  1015
4778
068cf1db91f1 6446301 ZFS mountpoint reverted back from legacy but sharenfs property not honored
rm160521
parents: 4603
diff changeset
  1016
			if (mountpoint_namecheck(strval, &why)) {
068cf1db91f1 6446301 ZFS mountpoint reverted back from legacy but sharenfs property not honored
rm160521
parents: 4603
diff changeset
  1017
				switch (why) {
068cf1db91f1 6446301 ZFS mountpoint reverted back from legacy but sharenfs property not honored
rm160521
parents: 4603
diff changeset
  1018
				case NAME_ERR_LEADING_SLASH:
068cf1db91f1 6446301 ZFS mountpoint reverted back from legacy but sharenfs property not honored
rm160521
parents: 4603
diff changeset
  1019
					zfs_error_aux(hdl,
068cf1db91f1 6446301 ZFS mountpoint reverted back from legacy but sharenfs property not honored
rm160521
parents: 4603
diff changeset
  1020
					    dgettext(TEXT_DOMAIN,
068cf1db91f1 6446301 ZFS mountpoint reverted back from legacy but sharenfs property not honored
rm160521
parents: 4603
diff changeset
  1021
					    "'%s' must be an absolute path, "
068cf1db91f1 6446301 ZFS mountpoint reverted back from legacy but sharenfs property not honored
rm160521
parents: 4603
diff changeset
  1022
					    "'none', or 'legacy'"), propname);
068cf1db91f1 6446301 ZFS mountpoint reverted back from legacy but sharenfs property not honored
rm160521
parents: 4603
diff changeset
  1023
					break;
068cf1db91f1 6446301 ZFS mountpoint reverted back from legacy but sharenfs property not honored
rm160521
parents: 4603
diff changeset
  1024
				case NAME_ERR_TOOLONG:
068cf1db91f1 6446301 ZFS mountpoint reverted back from legacy but sharenfs property not honored
rm160521
parents: 4603
diff changeset
  1025
					zfs_error_aux(hdl,
068cf1db91f1 6446301 ZFS mountpoint reverted back from legacy but sharenfs property not honored
rm160521
parents: 4603
diff changeset
  1026
					    dgettext(TEXT_DOMAIN,
068cf1db91f1 6446301 ZFS mountpoint reverted back from legacy but sharenfs property not honored
rm160521
parents: 4603
diff changeset
  1027
					    "component of '%s' is too long"),
068cf1db91f1 6446301 ZFS mountpoint reverted back from legacy but sharenfs property not honored
rm160521
parents: 4603
diff changeset
  1028
					    propname);
068cf1db91f1 6446301 ZFS mountpoint reverted back from legacy but sharenfs property not honored
rm160521
parents: 4603
diff changeset
  1029
					break;
068cf1db91f1 6446301 ZFS mountpoint reverted back from legacy but sharenfs property not honored
rm160521
parents: 4603
diff changeset
  1030
				}
2676
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  1031
				(void) zfs_error(hdl, EZFS_BADPROP, errbuf);
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  1032
				goto error;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1033
			}
4778
068cf1db91f1 6446301 ZFS mountpoint reverted back from legacy but sharenfs property not honored
rm160521
parents: 4603
diff changeset
  1034
		}
068cf1db91f1 6446301 ZFS mountpoint reverted back from legacy but sharenfs property not honored
rm160521
parents: 4603
diff changeset
  1035
3126
4f4fb617fdd0 PSARC 2006/622 iSCSI/ZFS Integration
ahl
parents: 2885
diff changeset
  1036
			/*FALLTHRU*/
4f4fb617fdd0 PSARC 2006/622 iSCSI/ZFS Integration
ahl
parents: 2885
diff changeset
  1037
5331
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5326
diff changeset
  1038
		case ZFS_PROP_SHARESMB:
3126
4f4fb617fdd0 PSARC 2006/622 iSCSI/ZFS Integration
ahl
parents: 2885
diff changeset
  1039
		case ZFS_PROP_SHARENFS:
4f4fb617fdd0 PSARC 2006/622 iSCSI/ZFS Integration
ahl
parents: 2885
diff changeset
  1040
			/*
5331
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5326
diff changeset
  1041
			 * For the mountpoint and sharenfs or sharesmb
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5326
diff changeset
  1042
			 * properties, check if it can be set in a
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5326
diff changeset
  1043
			 * global/non-global zone based on
3126
4f4fb617fdd0 PSARC 2006/622 iSCSI/ZFS Integration
ahl
parents: 2885
diff changeset
  1044
			 * the zoned property value:
4f4fb617fdd0 PSARC 2006/622 iSCSI/ZFS Integration
ahl
parents: 2885
diff changeset
  1045
			 *
4f4fb617fdd0 PSARC 2006/622 iSCSI/ZFS Integration
ahl
parents: 2885
diff changeset
  1046
			 *		global zone	    non-global zone
4f4fb617fdd0 PSARC 2006/622 iSCSI/ZFS Integration
ahl
parents: 2885
diff changeset
  1047
			 * --------------------------------------------------
4f4fb617fdd0 PSARC 2006/622 iSCSI/ZFS Integration
ahl
parents: 2885
diff changeset
  1048
			 * zoned=on	mountpoint (no)	    mountpoint (yes)
4f4fb617fdd0 PSARC 2006/622 iSCSI/ZFS Integration
ahl
parents: 2885
diff changeset
  1049
			 *		sharenfs (no)	    sharenfs (no)
5331
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5326
diff changeset
  1050
			 *		sharesmb (no)	    sharesmb (no)
3126
4f4fb617fdd0 PSARC 2006/622 iSCSI/ZFS Integration
ahl
parents: 2885
diff changeset
  1051
			 *
4f4fb617fdd0 PSARC 2006/622 iSCSI/ZFS Integration
ahl
parents: 2885
diff changeset
  1052
			 * zoned=off	mountpoint (yes)	N/A
4f4fb617fdd0 PSARC 2006/622 iSCSI/ZFS Integration
ahl
parents: 2885
diff changeset
  1053
			 *		sharenfs (yes)
5331
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5326
diff changeset
  1054
			 *		sharesmb (yes)
3126
4f4fb617fdd0 PSARC 2006/622 iSCSI/ZFS Integration
ahl
parents: 2885
diff changeset
  1055
			 */
2676
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  1056
			if (zoned) {
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  1057
				if (getzoneid() == GLOBAL_ZONEID) {
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  1058
					zfs_error_aux(hdl, dgettext(TEXT_DOMAIN,
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  1059
					    "'%s' cannot be set on "
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  1060
					    "dataset in a non-global zone"),
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  1061
					    propname);
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  1062
					(void) zfs_error(hdl, EZFS_ZONED,
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  1063
					    errbuf);
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  1064
					goto error;
5331
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5326
diff changeset
  1065
				} else if (prop == ZFS_PROP_SHARENFS ||
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5326
diff changeset
  1066
				    prop == ZFS_PROP_SHARESMB) {
2676
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  1067
					zfs_error_aux(hdl, dgettext(TEXT_DOMAIN,
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  1068
					    "'%s' cannot be set in "
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  1069
					    "a non-global zone"), propname);
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  1070
					(void) zfs_error(hdl, EZFS_ZONED,
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  1071
					    errbuf);
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  1072
					goto error;
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  1073
				}
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  1074
			} else if (getzoneid() != GLOBAL_ZONEID) {
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  1075
				/*
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  1076
				 * If zoned property is 'off', this must be in
9396
f41cf682d0d3 PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 8845
diff changeset
  1077
				 * a global zone. If not, something is wrong.
2676
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  1078
				 */
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  1079
				zfs_error_aux(hdl, dgettext(TEXT_DOMAIN,
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  1080
				    "'%s' cannot be set while dataset "
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  1081
				    "'zoned' property is set"), propname);
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  1082
				(void) zfs_error(hdl, EZFS_ZONED, errbuf);
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  1083
				goto error;
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  1084
			}
3126
4f4fb617fdd0 PSARC 2006/622 iSCSI/ZFS Integration
ahl
parents: 2885
diff changeset
  1085
4180
30b15f0bd3c9 6491973 sharemgr: zfs set sharenfs=on is slow with lots of zfs filesystems
dougm
parents: 4007
diff changeset
  1086
			/*
30b15f0bd3c9 6491973 sharemgr: zfs set sharenfs=on is slow with lots of zfs filesystems
dougm
parents: 4007
diff changeset
  1087
			 * 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
  1088
			 * 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
  1089
			 * 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
  1090
			 */
5331
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5326
diff changeset
  1091
			if ((prop == ZFS_PROP_SHARENFS ||
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5326
diff changeset
  1092
			    prop == ZFS_PROP_SHARESMB) &&
4217
3411a82f178f 6552521 truss dumps core with multibyte characters in syscall args
eschrock
parents: 4183
diff changeset
  1093
			    strcmp(strval, "on") != 0 &&
3411a82f178f 6552521 truss dumps core with multibyte characters in syscall args
eschrock
parents: 4183
diff changeset
  1094
			    strcmp(strval, "off") != 0) {
5331
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5326
diff changeset
  1095
				zfs_share_proto_t proto;
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5326
diff changeset
  1096
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5326
diff changeset
  1097
				if (prop == ZFS_PROP_SHARESMB)
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5326
diff changeset
  1098
					proto = PROTO_SMB;
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5326
diff changeset
  1099
				else
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5326
diff changeset
  1100
					proto = PROTO_NFS;
4180
30b15f0bd3c9 6491973 sharemgr: zfs set sharenfs=on is slow with lots of zfs filesystems
dougm
parents: 4007
diff changeset
  1101
30b15f0bd3c9 6491973 sharemgr: zfs set sharenfs=on is slow with lots of zfs filesystems
dougm
parents: 4007
diff changeset
  1102
				/*
5331
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5326
diff changeset
  1103
				 * Must be an valid sharing protocol
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5326
diff changeset
  1104
				 * option string so init the libshare
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5326
diff changeset
  1105
				 * in order to enable the parser and
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5326
diff changeset
  1106
				 * then parse the options. We use the
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5326
diff changeset
  1107
				 * control API since we don't care about
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5326
diff changeset
  1108
				 * 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
  1109
				 * 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
  1110
				 * until we actually do something.
30b15f0bd3c9 6491973 sharemgr: zfs set sharenfs=on is slow with lots of zfs filesystems
dougm
parents: 4007
diff changeset
  1111
				 */
30b15f0bd3c9 6491973 sharemgr: zfs set sharenfs=on is slow with lots of zfs filesystems
dougm
parents: 4007
diff changeset
  1112
4217
3411a82f178f 6552521 truss dumps core with multibyte characters in syscall args
eschrock
parents: 4183
diff changeset
  1113
				if (zfs_init_libshare(hdl,
3411a82f178f 6552521 truss dumps core with multibyte characters in syscall args
eschrock
parents: 4183
diff changeset
  1114
				    SA_INIT_CONTROL_API) != SA_OK) {
3411a82f178f 6552521 truss dumps core with multibyte characters in syscall args
eschrock
parents: 4183
diff changeset
  1115
					/*
3411a82f178f 6552521 truss dumps core with multibyte characters in syscall args
eschrock
parents: 4183
diff changeset
  1116
					 * An error occurred so we can't do
3411a82f178f 6552521 truss dumps core with multibyte characters in syscall args
eschrock
parents: 4183
diff changeset
  1117
					 * anything
3411a82f178f 6552521 truss dumps core with multibyte characters in syscall args
eschrock
parents: 4183
diff changeset
  1118
					 */
3411a82f178f 6552521 truss dumps core with multibyte characters in syscall args
eschrock
parents: 4183
diff changeset
  1119
					zfs_error_aux(hdl, dgettext(TEXT_DOMAIN,
3411a82f178f 6552521 truss dumps core with multibyte characters in syscall args
eschrock
parents: 4183
diff changeset
  1120
					    "'%s' cannot be set: problem "
3411a82f178f 6552521 truss dumps core with multibyte characters in syscall args
eschrock
parents: 4183
diff changeset
  1121
					    "in share initialization"),
3411a82f178f 6552521 truss dumps core with multibyte characters in syscall args
eschrock
parents: 4183
diff changeset
  1122
					    propname);
3411a82f178f 6552521 truss dumps core with multibyte characters in syscall args
eschrock
parents: 4183
diff changeset
  1123
					(void) zfs_error(hdl, EZFS_BADPROP,
3411a82f178f 6552521 truss dumps core with multibyte characters in syscall args
eschrock
parents: 4183
diff changeset
  1124
					    errbuf);
3411a82f178f 6552521 truss dumps core with multibyte characters in syscall args
eschrock
parents: 4183
diff changeset
  1125
					goto error;
3411a82f178f 6552521 truss dumps core with multibyte characters in syscall args
eschrock
parents: 4183
diff changeset
  1126
				}
3411a82f178f 6552521 truss dumps core with multibyte characters in syscall args
eschrock
parents: 4183
diff changeset
  1127
5331
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5326
diff changeset
  1128
				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
  1129
					/*
3411a82f178f 6552521 truss dumps core with multibyte characters in syscall args
eschrock
parents: 4183
diff changeset
  1130
					 * There was an error in parsing so
3411a82f178f 6552521 truss dumps core with multibyte characters in syscall args
eschrock
parents: 4183
diff changeset
  1131
					 * deal with it by issuing an error
3411a82f178f 6552521 truss dumps core with multibyte characters in syscall args
eschrock
parents: 4183
diff changeset
  1132
					 * message and leaving after
3411a82f178f 6552521 truss dumps core with multibyte characters in syscall args
eschrock
parents: 4183
diff changeset
  1133
					 * uninitializing the the libshare
3411a82f178f 6552521 truss dumps core with multibyte characters in syscall args
eschrock
parents: 4183
diff changeset
  1134
					 * interface.
3411a82f178f 6552521 truss dumps core with multibyte characters in syscall args
eschrock
parents: 4183
diff changeset
  1135
					 */
3411a82f178f 6552521 truss dumps core with multibyte characters in syscall args
eschrock
parents: 4183
diff changeset
  1136
					zfs_error_aux(hdl, dgettext(TEXT_DOMAIN,
3411a82f178f 6552521 truss dumps core with multibyte characters in syscall args
eschrock
parents: 4183
diff changeset
  1137
					    "'%s' cannot be set to invalid "
3411a82f178f 6552521 truss dumps core with multibyte characters in syscall args
eschrock
parents: 4183
diff changeset
  1138
					    "options"), propname);
3411a82f178f 6552521 truss dumps core with multibyte characters in syscall args
eschrock
parents: 4183
diff changeset
  1139
					(void) zfs_error(hdl, EZFS_BADPROP,
3411a82f178f 6552521 truss dumps core with multibyte characters in syscall args
eschrock
parents: 4183
diff changeset
  1140
					    errbuf);
3411a82f178f 6552521 truss dumps core with multibyte characters in syscall args
eschrock
parents: 4183
diff changeset
  1141
					zfs_uninit_libshare(hdl);
3411a82f178f 6552521 truss dumps core with multibyte characters in syscall args
eschrock
parents: 4183
diff changeset
  1142
					goto error;
3411a82f178f 6552521 truss dumps core with multibyte characters in syscall args
eschrock
parents: 4183
diff changeset
  1143
				}
4180
30b15f0bd3c9 6491973 sharemgr: zfs set sharenfs=on is slow with lots of zfs filesystems
dougm
parents: 4007
diff changeset
  1144
				zfs_uninit_libshare(hdl);
30b15f0bd3c9 6491973 sharemgr: zfs set sharenfs=on is slow with lots of zfs filesystems
dougm
parents: 4007
diff changeset
  1145
			}
30b15f0bd3c9 6491973 sharemgr: zfs set sharenfs=on is slow with lots of zfs filesystems
dougm
parents: 4007
diff changeset
  1146
3126
4f4fb617fdd0 PSARC 2006/622 iSCSI/ZFS Integration
ahl
parents: 2885
diff changeset
  1147
			break;
5331
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5326
diff changeset
  1148
		case ZFS_PROP_UTF8ONLY:
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5326
diff changeset
  1149
			chosen_utf = (int)intval;
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5326
diff changeset
  1150
			break;
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5326
diff changeset
  1151
		case ZFS_PROP_NORMALIZE:
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5326
diff changeset
  1152
			chosen_normal = (int)intval;
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5326
diff changeset
  1153
			break;
2676
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  1154
		}
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  1155
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  1156
		/*
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  1157
		 * For changes to existing volumes, we have some additional
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  1158
		 * checks to enforce.
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  1159
		 */
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  1160
		if (type == ZFS_TYPE_VOLUME && zhp != NULL) {
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  1161
			uint64_t volsize = zfs_prop_get_int(zhp,
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  1162
			    ZFS_PROP_VOLSIZE);
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  1163
			uint64_t blocksize = zfs_prop_get_int(zhp,
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  1164
			    ZFS_PROP_VOLBLOCKSIZE);
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  1165
			char buf[64];
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  1166
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  1167
			switch (prop) {
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  1168
			case ZFS_PROP_RESERVATION:
5378
111aa1baa84a PSARC 2007/555 zfs fs-only quotas and reservations
ck153898
parents: 5375
diff changeset
  1169
			case ZFS_PROP_REFRESERVATION:
2676
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  1170
				if (intval > volsize) {
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  1171
					zfs_error_aux(hdl, dgettext(TEXT_DOMAIN,
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  1172
					    "'%s' is greater than current "
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  1173
					    "volume size"), propname);
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  1174
					(void) zfs_error(hdl, EZFS_BADPROP,
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  1175
					    errbuf);
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  1176
					goto error;
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  1177
				}
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  1178
				break;
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  1179
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  1180
			case ZFS_PROP_VOLSIZE:
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  1181
				if (intval % blocksize != 0) {
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  1182
					zfs_nicenum(blocksize, buf,
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  1183
					    sizeof (buf));
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  1184
					zfs_error_aux(hdl, dgettext(TEXT_DOMAIN,
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  1185
					    "'%s' must be a multiple of "
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  1186
					    "volume block size (%s)"),
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  1187
					    propname, buf);
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  1188
					(void) zfs_error(hdl, EZFS_BADPROP,
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  1189
					    errbuf);
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  1190
					goto error;
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  1191
				}
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  1192
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  1193
				if (intval == 0) {
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  1194
					zfs_error_aux(hdl, dgettext(TEXT_DOMAIN,
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  1195
					    "'%s' cannot be zero"),
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  1196
					    propname);
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  1197
					(void) zfs_error(hdl, EZFS_BADPROP,
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  1198
					    errbuf);
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  1199
					goto error;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1200
				}
3126
4f4fb617fdd0 PSARC 2006/622 iSCSI/ZFS Integration
ahl
parents: 2885
diff changeset
  1201
				break;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1202
			}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1203
		}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1204
	}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1205
2676
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  1206
	/*
5331
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5326
diff changeset
  1207
	 * 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
  1208
	 * enforce rejection of non-UTF8 names.
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5326
diff changeset
  1209
	 *
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5326
diff changeset
  1210
	 * If normalization was chosen, but rejecting non-UTF8 names
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5326
diff changeset
  1211
	 * was explicitly not chosen, it is an error.
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5326
diff changeset
  1212
	 */
5498
334b476844ca 6622831 normalization properties are not preserved by "zfs send"
timh
parents: 5481
diff changeset
  1213
	if (chosen_normal > 0 && chosen_utf < 0) {
5331
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5326
diff changeset
  1214
		if (nvlist_add_uint64(ret,
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5326
diff changeset
  1215
		    zfs_prop_to_name(ZFS_PROP_UTF8ONLY), 1) != 0) {
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5326
diff changeset
  1216
			(void) no_memory(hdl);
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5326
diff changeset
  1217
			goto error;
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5326
diff changeset
  1218
		}
5498
334b476844ca 6622831 normalization properties are not preserved by "zfs send"
timh
parents: 5481
diff changeset
  1219
	} else if (chosen_normal > 0 && chosen_utf == 0) {
5331
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5326
diff changeset
  1220
		zfs_error_aux(hdl, dgettext(TEXT_DOMAIN,
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5326
diff changeset
  1221
		    "'%s' must be set 'on' if normalization chosen"),
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5326
diff changeset
  1222
		    zfs_prop_to_name(ZFS_PROP_UTF8ONLY));
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5326
diff changeset
  1223
		(void) zfs_error(hdl, EZFS_BADPROP, errbuf);
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5326
diff changeset
  1224
		goto error;
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5326
diff changeset
  1225
	}
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5326
diff changeset
  1226
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5326
diff changeset
  1227
	/*
2676
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  1228
	 * If this is an existing volume, and someone is setting the volsize,
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  1229
	 * make sure that it matches the reservation, or add it if necessary.
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  1230
	 */
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  1231
	if (zhp != NULL && type == ZFS_TYPE_VOLUME &&
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  1232
	    nvlist_lookup_uint64(ret, zfs_prop_to_name(ZFS_PROP_VOLSIZE),
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  1233
	    &intval) == 0) {
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  1234
		uint64_t old_volsize = zfs_prop_get_int(zhp,
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  1235
		    ZFS_PROP_VOLSIZE);
5481
1364fb7de75d 6619182 new non-sparse zvols should get refreservations
ck153898
parents: 5473
diff changeset
  1236
		uint64_t old_reservation;
2676
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  1237
		uint64_t new_reservation;
5481
1364fb7de75d 6619182 new non-sparse zvols should get refreservations
ck153898
parents: 5473
diff changeset
  1238
		zfs_prop_t resv_prop;
5713
f9b7933f3770 PSARC/2007/675 A_MDEV Removal
rm160521
parents: 5592
diff changeset
  1239
f9b7933f3770 PSARC/2007/675 A_MDEV Removal
rm160521
parents: 5592
diff changeset
  1240
		if (zfs_which_resv_prop(zhp, &resv_prop) < 0)
5481
1364fb7de75d 6619182 new non-sparse zvols should get refreservations
ck153898
parents: 5473
diff changeset
  1241
			goto error;
1364fb7de75d 6619182 new non-sparse zvols should get refreservations
ck153898
parents: 5473
diff changeset
  1242
		old_reservation = zfs_prop_get_int(zhp, resv_prop);
2676
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  1243
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  1244
		if (old_volsize == old_reservation &&
5481
1364fb7de75d 6619182 new non-sparse zvols should get refreservations
ck153898
parents: 5473
diff changeset
  1245
		    nvlist_lookup_uint64(ret, zfs_prop_to_name(resv_prop),
2676
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  1246
		    &new_reservation) != 0) {
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  1247
			if (nvlist_add_uint64(ret,
5481
1364fb7de75d 6619182 new non-sparse zvols should get refreservations
ck153898
parents: 5473
diff changeset
  1248
			    zfs_prop_to_name(resv_prop), intval) != 0) {
2676
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  1249
				(void) no_memory(hdl);
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  1250
				goto error;
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  1251
			}
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  1252
		}
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  1253
	}
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  1254
	return (ret);
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  1255
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  1256
error:
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  1257
	nvlist_free(ret);
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  1258
	return (NULL);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1259
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1260
11022
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 10984
diff changeset
  1261
void
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 10984
diff changeset
  1262
zfs_setprop_error(libzfs_handle_t *hdl, zfs_prop_t prop, int err,
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 10984
diff changeset
  1263
    char *errbuf)
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 10984
diff changeset
  1264
{
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 10984
diff changeset
  1265
	switch (err) {
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 10984
diff changeset
  1266
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 10984
diff changeset
  1267
	case ENOSPC:
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 10984
diff changeset
  1268
		/*
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 10984
diff changeset
  1269
		 * For quotas and reservations, ENOSPC indicates
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 10984
diff changeset
  1270
		 * something different; setting a quota or reservation
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 10984
diff changeset
  1271
		 * doesn't use any disk space.
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 10984
diff changeset
  1272
		 */
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 10984
diff changeset
  1273
		switch (prop) {
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 10984
diff changeset
  1274
		case ZFS_PROP_QUOTA:
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 10984
diff changeset
  1275
		case ZFS_PROP_REFQUOTA:
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 10984
diff changeset
  1276
			zfs_error_aux(hdl, dgettext(TEXT_DOMAIN,
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 10984
diff changeset
  1277
			    "size is less than current used or "
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 10984
diff changeset
  1278
			    "reserved space"));
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 10984
diff changeset
  1279
			(void) zfs_error(hdl, EZFS_PROPSPACE, errbuf);
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 10984
diff changeset
  1280
			break;
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 10984
diff changeset
  1281
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 10984
diff changeset
  1282
		case ZFS_PROP_RESERVATION:
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 10984
diff changeset
  1283
		case ZFS_PROP_REFRESERVATION:
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 10984
diff changeset
  1284
			zfs_error_aux(hdl, dgettext(TEXT_DOMAIN,
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 10984
diff changeset
  1285
			    "size is greater than available space"));
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 10984
diff changeset
  1286
			(void) zfs_error(hdl, EZFS_PROPSPACE, errbuf);
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 10984
diff changeset
  1287
			break;
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 10984
diff changeset
  1288
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 10984
diff changeset
  1289
		default:
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 10984
diff changeset
  1290
			(void) zfs_standard_error(hdl, err, errbuf);
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 10984
diff changeset
  1291
			break;
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 10984
diff changeset
  1292
		}
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 10984
diff changeset
  1293
		break;
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 10984
diff changeset
  1294
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 10984
diff changeset
  1295
	case EBUSY:
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 10984
diff changeset
  1296
		(void) zfs_standard_error(hdl, EBUSY, errbuf);
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 10984
diff changeset
  1297
		break;
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 10984
diff changeset
  1298
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 10984
diff changeset
  1299
	case EROFS:
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 10984
diff changeset
  1300
		(void) zfs_error(hdl, EZFS_DSREADONLY, errbuf);
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 10984
diff changeset
  1301
		break;
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 10984
diff changeset
  1302
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 10984
diff changeset
  1303
	case ENOTSUP:
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 10984
diff changeset
  1304
		zfs_error_aux(hdl, dgettext(TEXT_DOMAIN,
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 10984
diff changeset
  1305
		    "pool and or dataset must be upgraded to set this "
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 10984
diff changeset
  1306
		    "property or value"));
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 10984
diff changeset
  1307
		(void) zfs_error(hdl, EZFS_BADVERSION, errbuf);
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 10984
diff changeset
  1308
		break;
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 10984
diff changeset
  1309
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 10984
diff changeset
  1310
	case ERANGE:
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 10984
diff changeset
  1311
		if (prop == ZFS_PROP_COMPRESSION) {
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 10984
diff changeset
  1312
			(void) zfs_error_aux(hdl, dgettext(TEXT_DOMAIN,
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 10984
diff changeset
  1313
			    "property setting is not allowed on "
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 10984
diff changeset
  1314
			    "bootable datasets"));
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 10984
diff changeset
  1315
			(void) zfs_error(hdl, EZFS_NOTSUP, errbuf);
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 10984
diff changeset
  1316
		} else {
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 10984
diff changeset
  1317
			(void) zfs_standard_error(hdl, err, errbuf);
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 10984
diff changeset
  1318
		}
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 10984
diff changeset
  1319
		break;
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 10984
diff changeset
  1320
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 10984
diff changeset
  1321
	case EOVERFLOW:
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 10984
diff changeset
  1322
		/*
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 10984
diff changeset
  1323
		 * This platform can't address a volume this big.
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 10984
diff changeset
  1324
		 */
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 10984
diff changeset
  1325
#ifdef _ILP32
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 10984
diff changeset
  1326
		if (prop == ZFS_PROP_VOLSIZE) {
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 10984
diff changeset
  1327
			(void) zfs_error(hdl, EZFS_VOLTOOBIG, errbuf);
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 10984
diff changeset
  1328
			break;
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 10984
diff changeset
  1329
		}
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 10984
diff changeset
  1330
#endif
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 10984
diff changeset
  1331
		/* FALLTHROUGH */
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 10984
diff changeset
  1332
	default:
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 10984
diff changeset
  1333
		(void) zfs_standard_error(hdl, err, errbuf);
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 10984
diff changeset
  1334
	}
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 10984
diff changeset
  1335
}
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 10984
diff changeset
  1336
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1337
/*
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1338
 * Given a property name and value, set the property for the given dataset.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1339
 */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1340
int
2676
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  1341
zfs_prop_set(zfs_handle_t *zhp, const char *propname, const char *propval)
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1342
{
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1343
	zfs_cmd_t zc = { 0 };
2676
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  1344
	int ret = -1;
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  1345
	prop_changelist_t *cl = NULL;
2082
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1793
diff changeset
  1346
	char errbuf[1024];
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1793
diff changeset
  1347
	libzfs_handle_t *hdl = zhp->zfs_hdl;
2676
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  1348
	nvlist_t *nvl = NULL, *realprops;
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  1349
	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
  1350
	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
  1351
	uint64_t idx;
2082
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1793
diff changeset
  1352
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1793
diff changeset
  1353
	(void) snprintf(errbuf, sizeof (errbuf),
2676
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  1354
	    dgettext(TEXT_DOMAIN, "cannot set property for '%s'"),
2082
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1793
diff changeset
  1355
	    zhp->zfs_name);
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1793
diff changeset
  1356
2676
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  1357
	if (nvlist_alloc(&nvl, NV_UNIQUE_NAME, 0) != 0 ||
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  1358
	    nvlist_add_string(nvl, propname, propval) != 0) {
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  1359
		(void) no_memory(hdl);
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  1360
		goto error;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1361
	}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1362
7184
9508660f9c27 PSARC 2008/223 Pool root file system properties via zpool(1M)
timh
parents: 7042
diff changeset
  1363
	if ((realprops = zfs_valid_proplist(hdl, zhp->zfs_type, nvl,
2676
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  1364
	    zfs_prop_get_int(zhp, ZFS_PROP_ZONED), zhp, errbuf)) == NULL)
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  1365
		goto error;
5094
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4861
diff changeset
  1366
2676
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  1367
	nvlist_free(nvl);
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  1368
	nvl = realprops;
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  1369
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  1370
	prop = zfs_name_to_prop(propname);
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  1371
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
  1372
	if ((cl = changelist_gather(zhp, prop, 0, 0)) == NULL)
2676
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  1373
		goto error;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1374
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1375
	if (prop == ZFS_PROP_MOUNTPOINT && changelist_haszonedchild(cl)) {
2082
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1793
diff changeset
  1376
		zfs_error_aux(hdl, dgettext(TEXT_DOMAIN,
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1793
diff changeset
  1377
		    "child dataset with inherited mountpoint is used "
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1793
diff changeset
  1378
		    "in a non-global zone"));
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1793
diff changeset
  1379
		ret = zfs_error(hdl, EZFS_ZONED, errbuf);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1380
		goto error;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1381
	}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1382
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
  1383
	/*
24f6b0f4654f 6739303 Setting canmount=noauto should not require unmounting and remounting a dataset
Mark J Musante <Mark.Musante@Sun.COM>
parents: 7390
diff changeset
  1384
	 * 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
  1385
	 * 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
  1386
	 */
24f6b0f4654f 6739303 Setting canmount=noauto should not require unmounting and remounting a dataset
Mark J Musante <Mark.Musante@Sun.COM>
parents: 7390
diff changeset
  1387
	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
  1388
	    (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
  1389
	    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
  1390
51c045dcc498 PSARC 2008/168 Support for ZFS property value canmount=noauto
hs24103
parents: 5993
diff changeset
  1391
	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
  1392
		goto error;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1393
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1394
	/*
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1395
	 * Execute the corresponding ioctl() to set this property.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1396
	 */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1397
	(void) strlcpy(zc.zc_name, zhp->zfs_name, sizeof (zc.zc_name));
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1398
5094
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4861
diff changeset
  1399
	if (zcmd_write_src_nvlist(hdl, &zc, nvl) != 0)
2676
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  1400
		goto error;
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  1401
4543
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  1402
	ret = zfs_ioctl(hdl, ZFS_IOC_SET_PROP, &zc);
8845
91af0d9c0790 6800942 smb_session_create() incorrectly stores IP addresses
Alan Wright <amw@Sun.COM>
parents: 8811
diff changeset
  1403
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1404
	if (ret != 0) {
11022
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 10984
diff changeset
  1405
		zfs_setprop_error(hdl, prop, errno, errbuf);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1406
	} else {
6168
51c045dcc498 PSARC 2008/168 Support for ZFS property value canmount=noauto
hs24103
parents: 5993
diff changeset
  1407
		if (do_prefix)
51c045dcc498 PSARC 2008/168 Support for ZFS property value canmount=noauto
hs24103
parents: 5993
diff changeset
  1408
			ret = changelist_postfix(cl);
51c045dcc498 PSARC 2008/168 Support for ZFS property value canmount=noauto
hs24103
parents: 5993
diff changeset
  1409
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1410
		/*
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1411
		 * Refresh the statistics so the new property value
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1412
		 * is reflected.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1413
		 */
6168
51c045dcc498 PSARC 2008/168 Support for ZFS property value canmount=noauto
hs24103
parents: 5993
diff changeset
  1414
		if (ret == 0)
2676
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  1415
			(void) get_stats(zhp);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1416
	}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1417
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1418
error:
2676
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  1419
	nvlist_free(nvl);
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  1420
	zcmd_free_nvlists(&zc);
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  1421
	if (cl)
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  1422
		changelist_free(cl);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1423
	return (ret);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1424
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1425
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1426
/*
11022
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 10984
diff changeset
  1427
 * Given a property, inherit the value from the parent dataset, or if received
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 10984
diff changeset
  1428
 * is TRUE, revert to the received value, if any.
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1429
 */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1430
int
11022
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 10984
diff changeset
  1431
zfs_prop_inherit(zfs_handle_t *zhp, const char *propname, boolean_t received)
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1432
{
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1433
	zfs_cmd_t zc = { 0 };
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1434
	int ret;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1435
	prop_changelist_t *cl;
2082
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1793
diff changeset
  1436
	libzfs_handle_t *hdl = zhp->zfs_hdl;
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1793
diff changeset
  1437
	char errbuf[1024];
2676
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  1438
	zfs_prop_t prop;
2082
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1793
diff changeset
  1439
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1793
diff changeset
  1440
	(void) snprintf(errbuf, sizeof (errbuf), dgettext(TEXT_DOMAIN,
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1793
diff changeset
  1441
	    "cannot inherit %s for '%s'"), propname, zhp->zfs_name);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1442
11022
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 10984
diff changeset
  1443
	zc.zc_cookie = received;
5094
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4861
diff changeset
  1444
	if ((prop = zfs_name_to_prop(propname)) == ZPROP_INVAL) {
2676
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  1445
		/*
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  1446
		 * 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
  1447
		 * small, so just do it here.
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  1448
		 */
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  1449
		if (!zfs_prop_user(propname)) {
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  1450
			zfs_error_aux(hdl, dgettext(TEXT_DOMAIN,
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  1451
			    "invalid property"));
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  1452
			return (zfs_error(hdl, EZFS_BADPROP, errbuf));
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  1453
		}
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  1454
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  1455
		(void) strlcpy(zc.zc_name, zhp->zfs_name, sizeof (zc.zc_name));
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  1456
		(void) strlcpy(zc.zc_value, propname, sizeof (zc.zc_value));
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  1457
4849
3a61e0a9a953 6536043 arc_byteswap_func_t and dmu_byteswap_func_t are redundant
ahrens
parents: 4801
diff changeset
  1458
		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
  1459
			return (zfs_standard_error(hdl, errno, errbuf));
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  1460
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  1461
		return (0);
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  1462
	}
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  1463
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1464
	/*
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1465
	 * Verify that this property is inheritable.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1466
	 */
2082
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1793
diff changeset
  1467
	if (zfs_prop_readonly(prop))
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1793
diff changeset
  1468
		return (zfs_error(hdl, EZFS_PROPREADONLY, errbuf));
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1793
diff changeset
  1469
11022
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 10984
diff changeset
  1470
	if (!zfs_prop_inheritable(prop) && !received)
2082
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1793
diff changeset
  1471
		return (zfs_error(hdl, EZFS_PROPNONINHERIT, errbuf));
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1472
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1473
	/*
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1474
	 * Check to see if the value applies to this type
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1475
	 */
2082
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1793
diff changeset
  1476
	if (!zfs_prop_valid_for_type(prop, zhp->zfs_type))
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1793
diff changeset
  1477
		return (zfs_error(hdl, EZFS_PROPTYPE, errbuf));
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1478
3443
e0e00ef6cee8 6494654 zfs inherit can't handle property short names
rm160521
parents: 3417
diff changeset
  1479
	/*
e0e00ef6cee8 6494654 zfs inherit can't handle property short names
rm160521
parents: 3417
diff changeset
  1480
	 * Normalize the name, to get rid of shorthand abbrevations.
e0e00ef6cee8 6494654 zfs inherit can't handle property short names
rm160521
parents: 3417
diff changeset
  1481
	 */
e0e00ef6cee8 6494654 zfs inherit can't handle property short names
rm160521
parents: 3417
diff changeset
  1482
	propname = zfs_prop_to_name(prop);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1483
	(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
  1484
	(void) strlcpy(zc.zc_value, propname, sizeof (zc.zc_value));
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1485
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1486
	if (prop == ZFS_PROP_MOUNTPOINT && getzoneid() == GLOBAL_ZONEID &&
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1487
	    zfs_prop_get_int(zhp, ZFS_PROP_ZONED)) {
2082
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1793
diff changeset
  1488
		zfs_error_aux(hdl, dgettext(TEXT_DOMAIN,
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1793
diff changeset
  1489
		    "dataset is used in a non-global zone"));
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1793
diff changeset
  1490
		return (zfs_error(hdl, EZFS_ZONED, errbuf));
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1491
	}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1492
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1493
	/*
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1494
	 * Determine datasets which will be affected by this change, if any.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1495
	 */
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
  1496
	if ((cl = changelist_gather(zhp, prop, 0, 0)) == NULL)
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1497
		return (-1);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1498
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1499
	if (prop == ZFS_PROP_MOUNTPOINT && changelist_haszonedchild(cl)) {
2082
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1793
diff changeset
  1500
		zfs_error_aux(hdl, dgettext(TEXT_DOMAIN,
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1793
diff changeset
  1501
		    "child dataset with inherited mountpoint is used "
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1793
diff changeset
  1502
		    "in a non-global zone"));
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1793
diff changeset
  1503
		ret = zfs_error(hdl, EZFS_ZONED, errbuf);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1504
		goto error;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1505
	}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1506
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1507
	if ((ret = changelist_prefix(cl)) != 0)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1508
		goto error;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1509
4849
3a61e0a9a953 6536043 arc_byteswap_func_t and dmu_byteswap_func_t are redundant
ahrens
parents: 4801
diff changeset
  1510
	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
  1511
		return (zfs_standard_error(hdl, errno, errbuf));
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1512
	} else {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1513
2169
0152c8ed1663 6385436 zfs set <property> returns an error, but still sets property value (fix build)
nd150628
parents: 2166
diff changeset
  1514
		if ((ret = changelist_postfix(cl)) != 0)
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1515
			goto error;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1516
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1517
		/*
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1518
		 * Refresh the statistics so the new property is reflected.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1519
		 */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1520
		(void) get_stats(zhp);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1521
	}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1522
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1523
error:
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1524
	changelist_free(cl);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1525
	return (ret);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1526
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1527
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1528
/*
1356
e021b5e4aa0e 6377671 zfs mount -a shouldn't bother checking snapshots
eschrock
parents: 1294
diff changeset
  1529
 * 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
  1530
 * extract them appropriately.
e021b5e4aa0e 6377671 zfs mount -a shouldn't bother checking snapshots
eschrock
parents: 1294
diff changeset
  1531
 */
e021b5e4aa0e 6377671 zfs mount -a shouldn't bother checking snapshots
eschrock
parents: 1294
diff changeset
  1532
static uint64_t
e021b5e4aa0e 6377671 zfs mount -a shouldn't bother checking snapshots
eschrock
parents: 1294
diff changeset
  1533
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
  1534
{
e021b5e4aa0e 6377671 zfs mount -a shouldn't bother checking snapshots
eschrock
parents: 1294
diff changeset
  1535
	nvlist_t *nv;
e021b5e4aa0e 6377671 zfs mount -a shouldn't bother checking snapshots
eschrock
parents: 1294
diff changeset
  1536
	uint64_t value;
e021b5e4aa0e 6377671 zfs mount -a shouldn't bother checking snapshots
eschrock
parents: 1294
diff changeset
  1537
2885
c0259887ebbc 6460059 zfs destroy <snapshot> leaves behind kruft
ahrens
parents: 2856
diff changeset
  1538
	*source = NULL;
1356
e021b5e4aa0e 6377671 zfs mount -a shouldn't bother checking snapshots
eschrock
parents: 1294
diff changeset
  1539
	if (nvlist_lookup_nvlist(zhp->zfs_props,
e021b5e4aa0e 6377671 zfs mount -a shouldn't bother checking snapshots
eschrock
parents: 1294
diff changeset
  1540
	    zfs_prop_to_name(prop), &nv) == 0) {
5094
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4861
diff changeset
  1541
		verify(nvlist_lookup_uint64(nv, ZPROP_VALUE, &value) == 0);
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4861
diff changeset
  1542
		(void) nvlist_lookup_string(nv, ZPROP_SOURCE, source);
1356
e021b5e4aa0e 6377671 zfs mount -a shouldn't bother checking snapshots
eschrock
parents: 1294
diff changeset
  1543
	} else {
8802
010b31dd4c53 6773366 "zfs list" memory consumption can be further reduced
Sanjeev Bagewadi <Sanjeev.Bagewadi@Sun.COM>
parents: 8269
diff changeset
  1544
		verify(!zhp->zfs_props_table ||
010b31dd4c53 6773366 "zfs list" memory consumption can be further reduced
Sanjeev Bagewadi <Sanjeev.Bagewadi@Sun.COM>
parents: 8269
diff changeset
  1545
		    zhp->zfs_props_table[prop] == B_TRUE);
1356
e021b5e4aa0e 6377671 zfs mount -a shouldn't bother checking snapshots
eschrock
parents: 1294
diff changeset
  1546
		value = zfs_prop_default_numeric(prop);
e021b5e4aa0e 6377671 zfs mount -a shouldn't bother checking snapshots
eschrock
parents: 1294
diff changeset
  1547
		*source = "";
e021b5e4aa0e 6377671 zfs mount -a shouldn't bother checking snapshots
eschrock
parents: 1294
diff changeset
  1548
	}
e021b5e4aa0e 6377671 zfs mount -a shouldn't bother checking snapshots
eschrock
parents: 1294
diff changeset
  1549
e021b5e4aa0e 6377671 zfs mount -a shouldn't bother checking snapshots
eschrock
parents: 1294
diff changeset
  1550
	return (value);
e021b5e4aa0e 6377671 zfs mount -a shouldn't bother checking snapshots
eschrock
parents: 1294
diff changeset
  1551
}
e021b5e4aa0e 6377671 zfs mount -a shouldn't bother checking snapshots
eschrock
parents: 1294
diff changeset
  1552
e021b5e4aa0e 6377671 zfs mount -a shouldn't bother checking snapshots
eschrock
parents: 1294
diff changeset
  1553
static char *
e021b5e4aa0e 6377671 zfs mount -a shouldn't bother checking snapshots
eschrock
parents: 1294
diff changeset
  1554
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
  1555
{
e021b5e4aa0e 6377671 zfs mount -a shouldn't bother checking snapshots
eschrock
parents: 1294
diff changeset
  1556
	nvlist_t *nv;
e021b5e4aa0e 6377671 zfs mount -a shouldn't bother checking snapshots
eschrock
parents: 1294
diff changeset
  1557
	char *value;
e021b5e4aa0e 6377671 zfs mount -a shouldn't bother checking snapshots
eschrock
parents: 1294
diff changeset
  1558
2885
c0259887ebbc 6460059 zfs destroy <snapshot> leaves behind kruft
ahrens
parents: 2856
diff changeset
  1559
	*source = NULL;
1356
e021b5e4aa0e 6377671 zfs mount -a shouldn't bother checking snapshots
eschrock
parents: 1294
diff changeset
  1560
	if (nvlist_lookup_nvlist(zhp->zfs_props,
e021b5e4aa0e 6377671 zfs mount -a shouldn't bother checking snapshots
eschrock
parents: 1294
diff changeset
  1561
	    zfs_prop_to_name(prop), &nv) == 0) {
5094
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4861
diff changeset
  1562
		verify(nvlist_lookup_string(nv, ZPROP_VALUE, &value) == 0);
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4861
diff changeset
  1563
		(void) nvlist_lookup_string(nv, ZPROP_SOURCE, source);
1356
e021b5e4aa0e 6377671 zfs mount -a shouldn't bother checking snapshots
eschrock
parents: 1294
diff changeset
  1564
	} else {
8802
010b31dd4c53 6773366 "zfs list" memory consumption can be further reduced
Sanjeev Bagewadi <Sanjeev.Bagewadi@Sun.COM>
parents: 8269
diff changeset
  1565
		verify(!zhp->zfs_props_table ||
010b31dd4c53 6773366 "zfs list" memory consumption can be further reduced
Sanjeev Bagewadi <Sanjeev.Bagewadi@Sun.COM>
parents: 8269
diff changeset
  1566
		    zhp->zfs_props_table[prop] == B_TRUE);
1356
e021b5e4aa0e 6377671 zfs mount -a shouldn't bother checking snapshots
eschrock
parents: 1294
diff changeset
  1567
		if ((value = (char *)zfs_prop_default_string(prop)) == NULL)
e021b5e4aa0e 6377671 zfs mount -a shouldn't bother checking snapshots
eschrock
parents: 1294
diff changeset
  1568
			value = "";
e021b5e4aa0e 6377671 zfs mount -a shouldn't bother checking snapshots
eschrock
parents: 1294
diff changeset
  1569
		*source = "";
e021b5e4aa0e 6377671 zfs mount -a shouldn't bother checking snapshots
eschrock
parents: 1294
diff changeset
  1570
	}
e021b5e4aa0e 6377671 zfs mount -a shouldn't bother checking snapshots
eschrock
parents: 1294
diff changeset
  1571
e021b5e4aa0e 6377671 zfs mount -a shouldn't bother checking snapshots
eschrock
parents: 1294
diff changeset
  1572
	return (value);
e021b5e4aa0e 6377671 zfs mount -a shouldn't bother checking snapshots
eschrock
parents: 1294
diff changeset
  1573
}
e021b5e4aa0e 6377671 zfs mount -a shouldn't bother checking snapshots
eschrock
parents: 1294
diff changeset
  1574
11022
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 10984
diff changeset
  1575
static boolean_t
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 10984
diff changeset
  1576
zfs_is_recvd_props_mode(zfs_handle_t *zhp)
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 10984
diff changeset
  1577
{
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 10984
diff changeset
  1578
	return (zhp->zfs_props == zhp->zfs_recvd_props);
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 10984
diff changeset
  1579
}
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 10984
diff changeset
  1580
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 10984
diff changeset
  1581
static void
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 10984
diff changeset
  1582
zfs_set_recvd_props_mode(zfs_handle_t *zhp, uint64_t *cookie)
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 10984
diff changeset
  1583
{
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 10984
diff changeset
  1584
	*cookie = (uint64_t)(uintptr_t)zhp->zfs_props;
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 10984
diff changeset
  1585
	zhp->zfs_props = zhp->zfs_recvd_props;
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 10984
diff changeset
  1586
}
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 10984
diff changeset
  1587
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 10984
diff changeset
  1588
static void
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 10984
diff changeset
  1589
zfs_unset_recvd_props_mode(zfs_handle_t *zhp, uint64_t *cookie)
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 10984
diff changeset
  1590
{
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 10984
diff changeset
  1591
	zhp->zfs_props = (nvlist_t *)(uintptr_t)*cookie;
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 10984
diff changeset
  1592
	*cookie = 0;
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 10984
diff changeset
  1593
}
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 10984
diff changeset
  1594
1356
e021b5e4aa0e 6377671 zfs mount -a shouldn't bother checking snapshots
eschrock
parents: 1294
diff changeset
  1595
/*
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1596
 * Internal function for getting a numeric property.  Both zfs_prop_get() and
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1597
 * zfs_prop_get_int() are built using this interface.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1598
 *
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1599
 * Certain properties can be overridden using 'mount -o'.  In this case, scan
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1600
 * the contents of the /etc/mnttab entry, searching for the appropriate options.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1601
 * If they differ from the on-disk values, report the current values and mark
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1602
 * the source "temporary".
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1603
 */
2082
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1793
diff changeset
  1604
static int
5094
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4861
diff changeset
  1605
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
  1606
    char **source, uint64_t *val)
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1607
{
5147
5e950ccc9585 6596190 "zfs list" is slow due to version property
rm160521
parents: 5094
diff changeset
  1608
	zfs_cmd_t zc = { 0 };
5592
1b20f93ffca0 6637425 memory leak in get_numeric_property()
timh
parents: 5498
diff changeset
  1609
	nvlist_t *zplprops = NULL;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1610
	struct mnttab mnt;
3265
967e0fca6143 6463140 zfs recv with a snapshot name that has 2 @@ in a row succeeds
ahrens
parents: 3237
diff changeset
  1611
	char *mntopt_on = NULL;
967e0fca6143 6463140 zfs recv with a snapshot name that has 2 @@ in a row succeeds
ahrens
parents: 3237
diff changeset
  1612
	char *mntopt_off = NULL;
11022
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 10984
diff changeset
  1613
	boolean_t received = zfs_is_recvd_props_mode(zhp);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1614
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1615
	*source = NULL;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1616
3265
967e0fca6143 6463140 zfs recv with a snapshot name that has 2 @@ in a row succeeds
ahrens
parents: 3237
diff changeset
  1617
	switch (prop) {
967e0fca6143 6463140 zfs recv with a snapshot name that has 2 @@ in a row succeeds
ahrens
parents: 3237
diff changeset
  1618
	case ZFS_PROP_ATIME:
967e0fca6143 6463140 zfs recv with a snapshot name that has 2 @@ in a row succeeds
ahrens
parents: 3237
diff changeset
  1619
		mntopt_on = MNTOPT_ATIME;
967e0fca6143 6463140 zfs recv with a snapshot name that has 2 @@ in a row succeeds
ahrens
parents: 3237
diff changeset
  1620
		mntopt_off = MNTOPT_NOATIME;
967e0fca6143 6463140 zfs recv with a snapshot name that has 2 @@ in a row succeeds
ahrens
parents: 3237
diff changeset
  1621
		break;
967e0fca6143 6463140 zfs recv with a snapshot name that has 2 @@ in a row succeeds
ahrens
parents: 3237
diff changeset
  1622
967e0fca6143 6463140 zfs recv with a snapshot name that has 2 @@ in a row succeeds
ahrens
parents: 3237
diff changeset
  1623
	case ZFS_PROP_DEVICES:
967e0fca6143 6463140 zfs recv with a snapshot name that has 2 @@ in a row succeeds
ahrens
parents: 3237
diff changeset
  1624
		mntopt_on = MNTOPT_DEVICES;
967e0fca6143 6463140 zfs recv with a snapshot name that has 2 @@ in a row succeeds
ahrens
parents: 3237
diff changeset
  1625
		mntopt_off = MNTOPT_NODEVICES;
967e0fca6143 6463140 zfs recv with a snapshot name that has 2 @@ in a row succeeds
ahrens
parents: 3237
diff changeset
  1626
		break;
967e0fca6143 6463140 zfs recv with a snapshot name that has 2 @@ in a row succeeds
ahrens
parents: 3237
diff changeset
  1627
967e0fca6143 6463140 zfs recv with a snapshot name that has 2 @@ in a row succeeds
ahrens
parents: 3237
diff changeset
  1628
	case ZFS_PROP_EXEC:
967e0fca6143 6463140 zfs recv with a snapshot name that has 2 @@ in a row succeeds
ahrens
parents: 3237
diff changeset
  1629
		mntopt_on = MNTOPT_EXEC;
967e0fca6143 6463140 zfs recv with a snapshot name that has 2 @@ in a row succeeds
ahrens
parents: 3237
diff changeset
  1630
		mntopt_off = MNTOPT_NOEXEC;
967e0fca6143 6463140 zfs recv with a snapshot name that has 2 @@ in a row succeeds
ahrens
parents: 3237
diff changeset
  1631
		break;
967e0fca6143 6463140 zfs recv with a snapshot name that has 2 @@ in a row succeeds
ahrens
parents: 3237
diff changeset
  1632
967e0fca6143 6463140 zfs recv with a snapshot name that has 2 @@ in a row succeeds
ahrens
parents: 3237
diff changeset
  1633
	case ZFS_PROP_READONLY:
967e0fca6143 6463140 zfs recv with a snapshot name that has 2 @@ in a row succeeds
ahrens
parents: 3237
diff changeset
  1634
		mntopt_on = MNTOPT_RO;
967e0fca6143 6463140 zfs recv with a snapshot name that has 2 @@ in a row succeeds
ahrens
parents: 3237
diff changeset
  1635
		mntopt_off = MNTOPT_RW;
967e0fca6143 6463140 zfs recv with a snapshot name that has 2 @@ in a row succeeds
ahrens
parents: 3237
diff changeset
  1636
		break;
967e0fca6143 6463140 zfs recv with a snapshot name that has 2 @@ in a row succeeds
ahrens
parents: 3237
diff changeset
  1637
967e0fca6143 6463140 zfs recv with a snapshot name that has 2 @@ in a row succeeds
ahrens
parents: 3237
diff changeset
  1638
	case ZFS_PROP_SETUID:
967e0fca6143 6463140 zfs recv with a snapshot name that has 2 @@ in a row succeeds
ahrens
parents: 3237
diff changeset
  1639
		mntopt_on = MNTOPT_SETUID;
967e0fca6143 6463140 zfs recv with a snapshot name that has 2 @@ in a row succeeds
ahrens
parents: 3237
diff changeset
  1640
		mntopt_off = MNTOPT_NOSETUID;
967e0fca6143 6463140 zfs recv with a snapshot name that has 2 @@ in a row succeeds
ahrens
parents: 3237
diff changeset
  1641
		break;
967e0fca6143 6463140 zfs recv with a snapshot name that has 2 @@ in a row succeeds
ahrens
parents: 3237
diff changeset
  1642
967e0fca6143 6463140 zfs recv with a snapshot name that has 2 @@ in a row succeeds
ahrens
parents: 3237
diff changeset
  1643
	case ZFS_PROP_XATTR:
967e0fca6143 6463140 zfs recv with a snapshot name that has 2 @@ in a row succeeds
ahrens
parents: 3237
diff changeset
  1644
		mntopt_on = MNTOPT_XATTR;
967e0fca6143 6463140 zfs recv with a snapshot name that has 2 @@ in a row succeeds
ahrens
parents: 3237
diff changeset
  1645
		mntopt_off = MNTOPT_NOXATTR;
967e0fca6143 6463140 zfs recv with a snapshot name that has 2 @@ in a row succeeds
ahrens
parents: 3237
diff changeset
  1646
		break;
5331
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5326
diff changeset
  1647
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5326
diff changeset
  1648
	case ZFS_PROP_NBMAND:
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5326
diff changeset
  1649
		mntopt_on = MNTOPT_NBMAND;
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5326
diff changeset
  1650
		mntopt_off = MNTOPT_NONBMAND;
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5326
diff changeset
  1651
		break;
3265
967e0fca6143 6463140 zfs recv with a snapshot name that has 2 @@ in a row succeeds
ahrens
parents: 3237
diff changeset
  1652
	}
967e0fca6143 6463140 zfs recv with a snapshot name that has 2 @@ in a row succeeds
ahrens
parents: 3237
diff changeset
  1653
2474
c001ad7e0c25 6368751 libzfs interface for mount/umounting all the file systems for a given pool
eschrock
parents: 2440
diff changeset
  1654
	/*
c001ad7e0c25 6368751 libzfs interface for mount/umounting all the file systems for a given pool
eschrock
parents: 2440
diff changeset
  1655
	 * 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
  1656
	 * (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
  1657
	 * 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
  1658
	 */
c001ad7e0c25 6368751 libzfs interface for mount/umounting all the file systems for a given pool
eschrock
parents: 2440
diff changeset
  1659
	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
  1660
	    (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
  1661
		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
  1662
		struct mnttab entry;
51e9ca9ee3a5 6572357 libzfs should do more to avoid mnttab lookups
Eric Taylor <Eric.Taylor@Sun.COM>
parents: 7509
diff changeset
  1663
51e9ca9ee3a5 6572357 libzfs should do more to avoid mnttab lookups
Eric Taylor <Eric.Taylor@Sun.COM>
parents: 7509
diff changeset
  1664
		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
  1665
			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
  1666
			    entry.mnt_mntopts);
967e0fca6143 6463140 zfs recv with a snapshot name that has 2 @@ in a row succeeds
ahrens
parents: 3237
diff changeset
  1667
			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
  1668
				return (-1);
967e0fca6143 6463140 zfs recv with a snapshot name that has 2 @@ in a row succeeds
ahrens
parents: 3237
diff changeset
  1669
		}
2474
c001ad7e0c25 6368751 libzfs interface for mount/umounting all the file systems for a given pool
eschrock
parents: 2440
diff changeset
  1670
c001ad7e0c25 6368751 libzfs interface for mount/umounting all the file systems for a given pool
eschrock
parents: 2440
diff changeset
  1671
		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
  1672
	}
c001ad7e0c25 6368751 libzfs interface for mount/umounting all the file systems for a given pool
eschrock
parents: 2440
diff changeset
  1673
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1674
	if (zhp->zfs_mntopts == NULL)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1675
		mnt.mnt_mntopts = "";
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1676
	else
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1677
		mnt.mnt_mntopts = zhp->zfs_mntopts;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1678
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1679
	switch (prop) {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1680
	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
  1681
	case ZFS_PROP_DEVICES:
967e0fca6143 6463140 zfs recv with a snapshot name that has 2 @@ in a row succeeds
ahrens
parents: 3237
diff changeset
  1682
	case ZFS_PROP_EXEC:
967e0fca6143 6463140 zfs recv with a snapshot name that has 2 @@ in a row succeeds
ahrens
parents: 3237
diff changeset
  1683
	case ZFS_PROP_READONLY:
967e0fca6143 6463140 zfs recv with a snapshot name that has 2 @@ in a row succeeds
ahrens
parents: 3237
diff changeset
  1684
	case ZFS_PROP_SETUID:
967e0fca6143 6463140 zfs recv with a snapshot name that has 2 @@ in a row succeeds
ahrens
parents: 3237
diff changeset
  1685
	case ZFS_PROP_XATTR:
5331
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5326
diff changeset
  1686
	case ZFS_PROP_NBMAND:
2082
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1793
diff changeset
  1687
		*val = getprop_uint64(zhp, prop, source);
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1793
diff changeset
  1688
11022
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 10984
diff changeset
  1689
		if (received)
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 10984
diff changeset
  1690
			break;
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 10984
diff changeset
  1691
3265
967e0fca6143 6463140 zfs recv with a snapshot name that has 2 @@ in a row succeeds
ahrens
parents: 3237
diff changeset
  1692
		if (hasmntopt(&mnt, mntopt_on) && !*val) {
2082
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1793
diff changeset
  1693
			*val = B_TRUE;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1694
			if (src)
5094
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4861
diff changeset
  1695
				*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
  1696
		} else if (hasmntopt(&mnt, mntopt_off) && *val) {
2082
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1793
diff changeset
  1697
			*val = B_FALSE;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1698
			if (src)
5094
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4861
diff changeset
  1699
				*src = ZPROP_SRC_TEMPORARY;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1700
		}
2082
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1793
diff changeset
  1701
		break;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1702
3265
967e0fca6143 6463140 zfs recv with a snapshot name that has 2 @@ in a row succeeds
ahrens
parents: 3237
diff changeset
  1703
	case ZFS_PROP_CANMOUNT:
11497
69b45e632792 6698011 zfs incorrectly reports file systems as children when attempting a rename
Mark J Musante <Mark.Musante@Sun.COM>
parents: 11449
diff changeset
  1704
	case ZFS_PROP_VOLSIZE:
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1705
	case ZFS_PROP_QUOTA:
5378
111aa1baa84a PSARC 2007/555 zfs fs-only quotas and reservations
ck153898
parents: 5375
diff changeset
  1706
	case ZFS_PROP_REFQUOTA:
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1707
	case ZFS_PROP_RESERVATION:
5378
111aa1baa84a PSARC 2007/555 zfs fs-only quotas and reservations
ck153898
parents: 5375
diff changeset
  1708
	case ZFS_PROP_REFRESERVATION:
2885
c0259887ebbc 6460059 zfs destroy <snapshot> leaves behind kruft
ahrens
parents: 2856
diff changeset
  1709
		*val = getprop_uint64(zhp, prop, source);
11022
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 10984
diff changeset
  1710
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 10984
diff changeset
  1711
		if (*source == NULL) {
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 10984
diff changeset
  1712
			/* not default, must be local */
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1713
			*source = zhp->zfs_name;
11022
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 10984
diff changeset
  1714
		}
2082
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1793
diff changeset
  1715
		break;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1716
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1717
	case ZFS_PROP_MOUNTED:
2082
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1793
diff changeset
  1718
		*val = (zhp->zfs_mntopts != NULL);
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1793
diff changeset
  1719
		break;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1720
3377
a2fa338530c1 6393525 vdev_reopen() should verify that it's still the same device
eschrock
parents: 3363
diff changeset
  1721
	case ZFS_PROP_NUMCLONES:
a2fa338530c1 6393525 vdev_reopen() should verify that it's still the same device
eschrock
parents: 3363
diff changeset
  1722
		*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
  1723
		break;
a2fa338530c1 6393525 vdev_reopen() should verify that it's still the same device
eschrock
parents: 3363
diff changeset
  1724
5147
5e950ccc9585 6596190 "zfs list" is slow due to version property
rm160521
parents: 5094
diff changeset
  1725
	case ZFS_PROP_VERSION:
5498
334b476844ca 6622831 normalization properties are not preserved by "zfs send"
timh
parents: 5481
diff changeset
  1726
	case ZFS_PROP_NORMALIZE:
334b476844ca 6622831 normalization properties are not preserved by "zfs send"
timh
parents: 5481
diff changeset
  1727
	case ZFS_PROP_UTF8ONLY:
334b476844ca 6622831 normalization properties are not preserved by "zfs send"
timh
parents: 5481
diff changeset
  1728
	case ZFS_PROP_CASE:
334b476844ca 6622831 normalization properties are not preserved by "zfs send"
timh
parents: 5481
diff changeset
  1729
		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
  1730
		    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
  1731
			return (-1);
5147
5e950ccc9585 6596190 "zfs list" is slow due to version property
rm160521
parents: 5094
diff changeset
  1732
		(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
  1733
		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
  1734
			zcmd_free_nvlists(&zc);
10204
83c3a84aecef 6760420 zfs unmount -f causes recv to fail
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 10160
diff changeset
  1735
			return (-1);
5147
5e950ccc9585 6596190 "zfs list" is slow due to version property
rm160521
parents: 5094
diff changeset
  1736
		}
5498
334b476844ca 6622831 normalization properties are not preserved by "zfs send"
timh
parents: 5481
diff changeset
  1737
		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
  1738
		    nvlist_lookup_uint64(zplprops, zfs_prop_to_name(prop),
334b476844ca 6622831 normalization properties are not preserved by "zfs send"
timh
parents: 5481
diff changeset
  1739
		    val) != 0) {
334b476844ca 6622831 normalization properties are not preserved by "zfs send"
timh
parents: 5481
diff changeset
  1740
			zcmd_free_nvlists(&zc);
10204
83c3a84aecef 6760420 zfs unmount -f causes recv to fail
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 10160
diff changeset
  1741
			return (-1);
5498
334b476844ca 6622831 normalization properties are not preserved by "zfs send"
timh
parents: 5481
diff changeset
  1742
		}
5592
1b20f93ffca0 6637425 memory leak in get_numeric_property()
timh
parents: 5498
diff changeset
  1743
		if (zplprops)
1b20f93ffca0 6637425 memory leak in get_numeric_property()
timh
parents: 5498
diff changeset
  1744
			nvlist_free(zplprops);
5498
334b476844ca 6622831 normalization properties are not preserved by "zfs send"
timh
parents: 5481
diff changeset
  1745
		zcmd_free_nvlists(&zc);
5147
5e950ccc9585 6596190 "zfs list" is slow due to version property
rm160521
parents: 5094
diff changeset
  1746
		break;
5e950ccc9585 6596190 "zfs list" is slow due to version property
rm160521
parents: 5094
diff changeset
  1747
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1748
	default:
4577
ed36b0e652bc PSARC/2007/328 zfs upgrade
ahrens
parents: 4543
diff changeset
  1749
		switch (zfs_prop_get_type(prop)) {
4787
602d3f97842c 6393351 unique_* could be improved
ahrens
parents: 4778
diff changeset
  1750
		case PROP_TYPE_NUMBER:
602d3f97842c 6393351 unique_* could be improved
ahrens
parents: 4778
diff changeset
  1751
		case PROP_TYPE_INDEX:
4577
ed36b0e652bc PSARC/2007/328 zfs upgrade
ahrens
parents: 4543
diff changeset
  1752
			*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
  1753
			/*
9396
f41cf682d0d3 PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 8845
diff changeset
  1754
			 * If we tried to use a default value for a
7390
6d408f0a5fbd PSARC/2008/518 ZFS space accounting enhancements
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 7366
diff changeset
  1755
			 * readonly property, it means that it was not
11080
368ac1f03f55 6900484 default volblocksize is no longer being reported correctly
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 11022
diff changeset
  1756
			 * present.
7390
6d408f0a5fbd PSARC/2008/518 ZFS space accounting enhancements
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 7366
diff changeset
  1757
			 */
6d408f0a5fbd PSARC/2008/518 ZFS space accounting enhancements
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 7366
diff changeset
  1758
			if (zfs_prop_readonly(prop) &&
11080
368ac1f03f55 6900484 default volblocksize is no longer being reported correctly
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 11022
diff changeset
  1759
			    *source != NULL && (*source)[0] == '\0') {
368ac1f03f55 6900484 default volblocksize is no longer being reported correctly
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 11022
diff changeset
  1760
				*source = NULL;
7390
6d408f0a5fbd PSARC/2008/518 ZFS space accounting enhancements
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 7366
diff changeset
  1761
			}
4577
ed36b0e652bc PSARC/2007/328 zfs upgrade
ahrens
parents: 4543
diff changeset
  1762
			break;
ed36b0e652bc PSARC/2007/328 zfs upgrade
ahrens
parents: 4543
diff changeset
  1763
4787
602d3f97842c 6393351 unique_* could be improved
ahrens
parents: 4778
diff changeset
  1764
		case PROP_TYPE_STRING:
4577
ed36b0e652bc PSARC/2007/328 zfs upgrade
ahrens
parents: 4543
diff changeset
  1765
		default:
ed36b0e652bc PSARC/2007/328 zfs upgrade
ahrens
parents: 4543
diff changeset
  1766
			zfs_error_aux(zhp->zfs_hdl, dgettext(TEXT_DOMAIN,
ed36b0e652bc PSARC/2007/328 zfs upgrade
ahrens
parents: 4543
diff changeset
  1767
			    "cannot get non-numeric property"));
ed36b0e652bc PSARC/2007/328 zfs upgrade
ahrens
parents: 4543
diff changeset
  1768
			return (zfs_error(zhp->zfs_hdl, EZFS_BADPROP,
ed36b0e652bc PSARC/2007/328 zfs upgrade
ahrens
parents: 4543
diff changeset
  1769
			    dgettext(TEXT_DOMAIN, "internal error")));
ed36b0e652bc PSARC/2007/328 zfs upgrade
ahrens
parents: 4543
diff changeset
  1770
		}
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1771
	}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1772
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1773
	return (0);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1774
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1775
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1776
/*
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1777
 * Calculate the source type, given the raw source string.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1778
 */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1779
static void
5094
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4861
diff changeset
  1780
get_source(zfs_handle_t *zhp, zprop_source_t *srctype, char *source,
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1781
    char *statbuf, size_t statlen)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1782
{
5094
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4861
diff changeset
  1783
	if (statbuf == NULL || *srctype == ZPROP_SRC_TEMPORARY)
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1784
		return;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1785
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1786
	if (source == NULL) {
5094
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4861
diff changeset
  1787
		*srctype = ZPROP_SRC_NONE;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1788
	} else if (source[0] == '\0') {
5094
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4861
diff changeset
  1789
		*srctype = ZPROP_SRC_DEFAULT;
11022
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 10984
diff changeset
  1790
	} else if (strstr(source, ZPROP_SOURCE_VAL_RECVD) != NULL) {
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 10984
diff changeset
  1791
		*srctype = ZPROP_SRC_RECEIVED;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1792
	} else {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1793
		if (strcmp(source, zhp->zfs_name) == 0) {
5094
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4861
diff changeset
  1794
			*srctype = ZPROP_SRC_LOCAL;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1795
		} else {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1796
			(void) strlcpy(statbuf, source, statlen);
5094
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4861
diff changeset
  1797
			*srctype = ZPROP_SRC_INHERITED;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1798
		}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1799
	}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1800
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1801
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1802
11022
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 10984
diff changeset
  1803
int
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 10984
diff changeset
  1804
zfs_prop_get_recvd(zfs_handle_t *zhp, const char *propname, char *propbuf,
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 10984
diff changeset
  1805
    size_t proplen, boolean_t literal)
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 10984
diff changeset
  1806
{
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 10984
diff changeset
  1807
	zfs_prop_t prop;
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 10984
diff changeset
  1808
	int err = 0;
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 10984
diff changeset
  1809
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 10984
diff changeset
  1810
	if (zhp->zfs_recvd_props == NULL)
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 10984
diff changeset
  1811
		if (get_recvd_props_ioctl(zhp) != 0)
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 10984
diff changeset
  1812
			return (-1);
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 10984
diff changeset
  1813
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 10984
diff changeset
  1814
	prop = zfs_name_to_prop(propname);
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 10984
diff changeset
  1815
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 10984
diff changeset
  1816
	if (prop != ZPROP_INVAL) {
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 10984
diff changeset
  1817
		uint64_t cookie;
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 10984
diff changeset
  1818
		if (!nvlist_exists(zhp->zfs_recvd_props, propname))
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 10984
diff changeset
  1819
			return (-1);
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 10984
diff changeset
  1820
		zfs_set_recvd_props_mode(zhp, &cookie);
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 10984
diff changeset
  1821
		err = zfs_prop_get(zhp, prop, propbuf, proplen,
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 10984
diff changeset
  1822
		    NULL, NULL, 0, literal);
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 10984
diff changeset
  1823
		zfs_unset_recvd_props_mode(zhp, &cookie);
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 10984
diff changeset
  1824
	} else if (zfs_prop_userquota(propname)) {
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 10984
diff changeset
  1825
		return (-1);
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 10984
diff changeset
  1826
	} else {
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 10984
diff changeset
  1827
		nvlist_t *propval;
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 10984
diff changeset
  1828
		char *recvdval;
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 10984
diff changeset
  1829
		if (nvlist_lookup_nvlist(zhp->zfs_recvd_props,
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 10984
diff changeset
  1830
		    propname, &propval) != 0)
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 10984
diff changeset
  1831
			return (-1);
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 10984
diff changeset
  1832
		verify(nvlist_lookup_string(propval, ZPROP_VALUE,
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 10984
diff changeset
  1833
		    &recvdval) == 0);
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 10984
diff changeset
  1834
		(void) strlcpy(propbuf, recvdval, proplen);
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 10984
diff changeset
  1835
	}
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 10984
diff changeset
  1836
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 10984
diff changeset
  1837
	return (err == 0 ? 0 : -1);
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 10984
diff changeset
  1838
}
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 10984
diff changeset
  1839
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1840
/*
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1841
 * Retrieve a property from the given object.  If 'literal' is specified, then
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1842
 * numbers are left as exact values.  Otherwise, numbers are converted to a
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1843
 * human-readable form.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1844
 *
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1845
 * Returns 0 on success, or -1 on error.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1846
 */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1847
int
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1848
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
  1849
    zprop_source_t *src, char *statbuf, size_t statlen, boolean_t literal)
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1850
{
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1851
	char *source = NULL;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1852
	uint64_t val;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1853
	char *str;
2676
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  1854
	const char *strval;
11022
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 10984
diff changeset
  1855
	boolean_t received = zfs_is_recvd_props_mode(zhp);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1856
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1857
	/*
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1858
	 * Check to see if this property applies to our object
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1859
	 */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1860
	if (!zfs_prop_valid_for_type(prop, zhp->zfs_type))
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1861
		return (-1);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1862
11022
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 10984
diff changeset
  1863
	if (received && zfs_prop_readonly(prop))
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 10984
diff changeset
  1864
		return (-1);
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 10984
diff changeset
  1865
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1866
	if (src)
5094
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4861
diff changeset
  1867
		*src = ZPROP_SRC_NONE;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1868
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1869
	switch (prop) {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1870
	case ZFS_PROP_CREATION:
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1871
		/*
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1872
		 * 'creation' is a time_t stored in the statistics.  We convert
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1873
		 * this into a string unless 'literal' is specified.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1874
		 */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1875
		{
2885
c0259887ebbc 6460059 zfs destroy <snapshot> leaves behind kruft
ahrens
parents: 2856
diff changeset
  1876
			val = getprop_uint64(zhp, prop, &source);
c0259887ebbc 6460059 zfs destroy <snapshot> leaves behind kruft
ahrens
parents: 2856
diff changeset
  1877
			time_t time = (time_t)val;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1878
			struct tm t;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1879
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1880
			if (literal ||
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1881
			    localtime_r(&time, &t) == NULL ||
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1882
			    strftime(propbuf, proplen, "%a %b %e %k:%M %Y",
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1883
			    &t) == 0)
2885
c0259887ebbc 6460059 zfs destroy <snapshot> leaves behind kruft
ahrens
parents: 2856
diff changeset
  1884
				(void) snprintf(propbuf, proplen, "%llu", val);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1885
		}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1886
		break;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1887
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1888
	case ZFS_PROP_MOUNTPOINT:
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1889
		/*
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1890
		 * Getting the precise mountpoint can be tricky.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1891
		 *
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1892
		 *  - for 'none' or 'legacy', return those values.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1893
		 *  - for inherited mountpoints, we want to take everything
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1894
		 *    after our ancestor and append it to the inherited value.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1895
		 *
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1896
		 * If the pool has an alternate root, we want to prepend that
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1897
		 * root to any values we return.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1898
		 */
6865
176d18c623cc 6539380 zfs list uses too much memory
rm160521
parents: 6612
diff changeset
  1899
1356
e021b5e4aa0e 6377671 zfs mount -a shouldn't bother checking snapshots
eschrock
parents: 1294
diff changeset
  1900
		str = getprop_string(zhp, prop, &source);
e021b5e4aa0e 6377671 zfs mount -a shouldn't bother checking snapshots
eschrock
parents: 1294
diff changeset
  1901
6612
bed68cb8aa8c 6668667 mountpoint is displayed incorrectly by zfs list when the mountpoint is "/"
gw25295
parents: 6423
diff changeset
  1902
		if (str[0] == '/') {
6865
176d18c623cc 6539380 zfs list uses too much memory
rm160521
parents: 6612
diff changeset
  1903
			char buf[MAXPATHLEN];
176d18c623cc 6539380 zfs list uses too much memory
rm160521
parents: 6612
diff changeset
  1904
			char *root = buf;
1356
e021b5e4aa0e 6377671 zfs mount -a shouldn't bother checking snapshots
eschrock
parents: 1294
diff changeset
  1905
			const char *relpath = zhp->zfs_name + strlen(source);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1906
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1907
			if (relpath[0] == '/')
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1908
				relpath++;
6612
bed68cb8aa8c 6668667 mountpoint is displayed incorrectly by zfs list when the mountpoint is "/"
gw25295
parents: 6423
diff changeset
  1909
6865
176d18c623cc 6539380 zfs list uses too much memory
rm160521
parents: 6612
diff changeset
  1910
			if ((zpool_get_prop(zhp->zpool_hdl,
176d18c623cc 6539380 zfs list uses too much memory
rm160521
parents: 6612
diff changeset
  1911
			    ZPOOL_PROP_ALTROOT, buf, MAXPATHLEN, NULL)) ||
176d18c623cc 6539380 zfs list uses too much memory
rm160521
parents: 6612
diff changeset
  1912
			    (strcmp(root, "-") == 0))
176d18c623cc 6539380 zfs list uses too much memory
rm160521
parents: 6612
diff changeset
  1913
				root[0] = '\0';
6612
bed68cb8aa8c 6668667 mountpoint is displayed incorrectly by zfs list when the mountpoint is "/"
gw25295
parents: 6423
diff changeset
  1914
			/*
bed68cb8aa8c 6668667 mountpoint is displayed incorrectly by zfs list when the mountpoint is "/"
gw25295
parents: 6423
diff changeset
  1915
			 * 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
  1916
			 * 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
  1917
			 * mountpoint path.
bed68cb8aa8c 6668667 mountpoint is displayed incorrectly by zfs list when the mountpoint is "/"
gw25295
parents: 6423
diff changeset
  1918
			 */
bed68cb8aa8c 6668667 mountpoint is displayed incorrectly by zfs list when the mountpoint is "/"
gw25295
parents: 6423
diff changeset
  1919
			if (strcmp(root, "/") == 0)
bed68cb8aa8c 6668667 mountpoint is displayed incorrectly by zfs list when the mountpoint is "/"
gw25295
parents: 6423
diff changeset
  1920
				root++;
bed68cb8aa8c 6668667 mountpoint is displayed incorrectly by zfs list when the mountpoint is "/"
gw25295
parents: 6423
diff changeset
  1921
bed68cb8aa8c 6668667 mountpoint is displayed incorrectly by zfs list when the mountpoint is "/"
gw25295
parents: 6423
diff changeset
  1922
			/*
bed68cb8aa8c 6668667 mountpoint is displayed incorrectly by zfs list when the mountpoint is "/"
gw25295
parents: 6423
diff changeset
  1923
			 * 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
  1924
			 * 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
  1925
			 * an inherited mountpoint.
bed68cb8aa8c 6668667 mountpoint is displayed incorrectly by zfs list when the mountpoint is "/"
gw25295
parents: 6423
diff changeset
  1926
			 */
bed68cb8aa8c 6668667 mountpoint is displayed incorrectly by zfs list when the mountpoint is "/"
gw25295
parents: 6423
diff changeset
  1927
			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
  1928
			    relpath[0] != '\0'))
1356
e021b5e4aa0e 6377671 zfs mount -a shouldn't bother checking snapshots
eschrock
parents: 1294
diff changeset
  1929
				str++;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1930
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1931
			if (relpath[0] == '\0')
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1932
				(void) snprintf(propbuf, proplen, "%s%s",
1356
e021b5e4aa0e 6377671 zfs mount -a shouldn't bother checking snapshots
eschrock
parents: 1294
diff changeset
  1933
				    root, str);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1934
			else
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1935
				(void) snprintf(propbuf, proplen, "%s%s%s%s",
1356
e021b5e4aa0e 6377671 zfs mount -a shouldn't bother checking snapshots
eschrock
parents: 1294
diff changeset
  1936
				    root, str, relpath[0] == '@' ? "" : "/",
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1937
				    relpath);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1938
		} else {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1939
			/* 'legacy' or 'none' */
1356
e021b5e4aa0e 6377671 zfs mount -a shouldn't bother checking snapshots
eschrock
parents: 1294
diff changeset
  1940
			(void) strlcpy(propbuf, str, proplen);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1941
		}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1942
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1943
		break;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1944
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1945
	case ZFS_PROP_ORIGIN:
2885
c0259887ebbc 6460059 zfs destroy <snapshot> leaves behind kruft
ahrens
parents: 2856
diff changeset
  1946
		(void) strlcpy(propbuf, getprop_string(zhp, prop, &source),
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1947
		    proplen);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1948
		/*
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1949
		 * If there is no parent at all, return failure to indicate that
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1950
		 * it doesn't apply to this dataset.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1951
		 */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1952
		if (propbuf[0] == '\0')
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1953
			return (-1);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1954
		break;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1955
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1956
	case ZFS_PROP_QUOTA:
5378
111aa1baa84a PSARC 2007/555 zfs fs-only quotas and reservations
ck153898
parents: 5375
diff changeset
  1957
	case ZFS_PROP_REFQUOTA:
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1958
	case ZFS_PROP_RESERVATION:
5378
111aa1baa84a PSARC 2007/555 zfs fs-only quotas and reservations
ck153898
parents: 5375
diff changeset
  1959
	case ZFS_PROP_REFRESERVATION:
111aa1baa84a PSARC 2007/555 zfs fs-only quotas and reservations
ck153898
parents: 5375
diff changeset
  1960
2082
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1793
diff changeset
  1961
		if (get_numeric_property(zhp, prop, src, &source, &val) != 0)
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1793
diff changeset
  1962
			return (-1);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1963
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1964
		/*
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1965
		 * If quota or reservation is 0, we translate this into 'none'
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1966
		 * (unless literal is set), and indicate that it's the default
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1967
		 * value.  Otherwise, we print the number nicely and indicate
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1968
		 * that its set locally.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1969
		 */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1970
		if (val == 0) {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1971
			if (literal)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1972
				(void) strlcpy(propbuf, "0", proplen);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1973
			else
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1974
				(void) strlcpy(propbuf, "none", proplen);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1975
		} else {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1976
			if (literal)
2856
6f4d5ee1906a 6463348 ZFS code could be more portable
nd150628
parents: 2744
diff changeset
  1977
				(void) snprintf(propbuf, proplen, "%llu",
3912
f6891a60bd72 PSARC 2007/083 ZFS bootable datasets
lling
parents: 3886
diff changeset
  1978
				    (u_longlong_t)val);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1979
			else
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1980
				zfs_nicenum(val, propbuf, proplen);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1981
		}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1982
		break;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1983
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1984
	case ZFS_PROP_COMPRESSRATIO:
2082
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1793
diff changeset
  1985
		if (get_numeric_property(zhp, prop, src, &source, &val) != 0)
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1793
diff changeset
  1986
			return (-1);
10922
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10588
diff changeset
  1987
		(void) snprintf(propbuf, proplen, "%llu.%02llux",
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10588
diff changeset
  1988
		    (u_longlong_t)(val / 100),
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10588
diff changeset
  1989
		    (u_longlong_t)(val % 100));
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1990
		break;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1991
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1992
	case ZFS_PROP_TYPE:
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1993
		switch (zhp->zfs_type) {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1994
		case ZFS_TYPE_FILESYSTEM:
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1995
			str = "filesystem";
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1996
			break;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1997
		case ZFS_TYPE_VOLUME:
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1998
			str = "volume";
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1999
			break;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2000
		case ZFS_TYPE_SNAPSHOT:
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2001
			str = "snapshot";
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2002
			break;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2003
		default:
2082
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1793
diff changeset
  2004
			abort();
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2005
		}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2006
		(void) snprintf(propbuf, proplen, "%s", str);
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_MOUNTED:
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2010
		/*
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2011
		 * The 'mounted' property is a pseudo-property that described
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2012
		 * whether the filesystem is currently mounted.  Even though
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2013
		 * it's a boolean value, the typical values of "on" and "off"
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2014
		 * don't make sense, so we translate to "yes" and "no".
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2015
		 */
2082
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1793
diff changeset
  2016
		if (get_numeric_property(zhp, ZFS_PROP_MOUNTED,
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1793
diff changeset
  2017
		    src, &source, &val) != 0)
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1793
diff changeset
  2018
			return (-1);
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1793
diff changeset
  2019
		if (val)
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2020
			(void) strlcpy(propbuf, "yes", proplen);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2021
		else
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2022
			(void) strlcpy(propbuf, "no", proplen);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2023
		break;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2024
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2025
	case ZFS_PROP_NAME:
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2026
		/*
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2027
		 * The 'name' property is a pseudo-property derived from the
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2028
		 * dataset name.  It is presented as a real property to simplify
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2029
		 * consumers.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2030
		 */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2031
		(void) strlcpy(propbuf, zhp->zfs_name, proplen);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2032
		break;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2033
10972
807794d41b3a PSARC 2009/348 Security Labels for ZFS
Ric Aleshire <Ric.Aleshire@Sun.COM>
parents: 10969
diff changeset
  2034
	case ZFS_PROP_MLSLABEL:
807794d41b3a PSARC 2009/348 Security Labels for ZFS
Ric Aleshire <Ric.Aleshire@Sun.COM>
parents: 10969
diff changeset
  2035
		{
807794d41b3a PSARC 2009/348 Security Labels for ZFS
Ric Aleshire <Ric.Aleshire@Sun.COM>
parents: 10969
diff changeset
  2036
			m_label_t *new_sl = NULL;
807794d41b3a PSARC 2009/348 Security Labels for ZFS
Ric Aleshire <Ric.Aleshire@Sun.COM>
parents: 10969
diff changeset
  2037
			char *ascii = NULL;	/* human readable label */
807794d41b3a PSARC 2009/348 Security Labels for ZFS
Ric Aleshire <Ric.Aleshire@Sun.COM>
parents: 10969
diff changeset
  2038
807794d41b3a PSARC 2009/348 Security Labels for ZFS
Ric Aleshire <Ric.Aleshire@Sun.COM>
parents: 10969
diff changeset
  2039
			(void) strlcpy(propbuf,
807794d41b3a PSARC 2009/348 Security Labels for ZFS
Ric Aleshire <Ric.Aleshire@Sun.COM>
parents: 10969
diff changeset
  2040
			    getprop_string(zhp, prop, &source), proplen);
807794d41b3a PSARC 2009/348 Security Labels for ZFS
Ric Aleshire <Ric.Aleshire@Sun.COM>
parents: 10969
diff changeset
  2041
807794d41b3a PSARC 2009/348 Security Labels for ZFS
Ric Aleshire <Ric.Aleshire@Sun.COM>
parents: 10969
diff changeset
  2042
			if (literal || (strcasecmp(propbuf,
807794d41b3a PSARC 2009/348 Security Labels for ZFS
Ric Aleshire <Ric.Aleshire@Sun.COM>
parents: 10969
diff changeset
  2043
			    ZFS_MLSLABEL_DEFAULT) == 0))
807794d41b3a PSARC 2009/348 Security Labels for ZFS
Ric Aleshire <Ric.Aleshire@Sun.COM>
parents: 10969
diff changeset
  2044
				break;
807794d41b3a PSARC 2009/348 Security Labels for ZFS
Ric Aleshire <Ric.Aleshire@Sun.COM>
parents: 10969
diff changeset
  2045
807794d41b3a PSARC 2009/348 Security Labels for ZFS
Ric Aleshire <Ric.Aleshire@Sun.COM>
parents: 10969
diff changeset
  2046
			/*
807794d41b3a PSARC 2009/348 Security Labels for ZFS
Ric Aleshire <Ric.Aleshire@Sun.COM>
parents: 10969
diff changeset
  2047
			 * Try to translate the internal hex string to
807794d41b3a PSARC 2009/348 Security Labels for ZFS
Ric Aleshire <Ric.Aleshire@Sun.COM>
parents: 10969
diff changeset
  2048
			 * human-readable output.  If there are any
807794d41b3a PSARC 2009/348 Security Labels for ZFS
Ric Aleshire <Ric.Aleshire@Sun.COM>
parents: 10969
diff changeset
  2049
			 * problems just use the hex string.
807794d41b3a PSARC 2009/348 Security Labels for ZFS
Ric Aleshire <Ric.Aleshire@Sun.COM>
parents: 10969
diff changeset
  2050
			 */
807794d41b3a PSARC 2009/348 Security Labels for ZFS
Ric Aleshire <Ric.Aleshire@Sun.COM>
parents: 10969
diff changeset
  2051
807794d41b3a PSARC 2009/348 Security Labels for ZFS
Ric Aleshire <Ric.Aleshire@Sun.COM>
parents: 10969
diff changeset
  2052
			if (str_to_label(propbuf, &new_sl, MAC_LABEL,
807794d41b3a PSARC 2009/348 Security Labels for ZFS
Ric Aleshire <Ric.Aleshire@Sun.COM>
parents: 10969
diff changeset
  2053
			    L_NO_CORRECTION, NULL) == -1) {
807794d41b3a PSARC 2009/348 Security Labels for ZFS
Ric Aleshire <Ric.Aleshire@Sun.COM>
parents: 10969
diff changeset
  2054
				m_label_free(new_sl);
807794d41b3a PSARC 2009/348 Security Labels for ZFS
Ric Aleshire <Ric.Aleshire@Sun.COM>
parents: 10969
diff changeset
  2055
				break;
807794d41b3a PSARC 2009/348 Security Labels for ZFS
Ric Aleshire <Ric.Aleshire@Sun.COM>
parents: 10969
diff changeset
  2056
			}
807794d41b3a PSARC 2009/348 Security Labels for ZFS
Ric Aleshire <Ric.Aleshire@Sun.COM>
parents: 10969
diff changeset
  2057
807794d41b3a PSARC 2009/348 Security Labels for ZFS
Ric Aleshire <Ric.Aleshire@Sun.COM>
parents: 10969
diff changeset
  2058
			if (label_to_str(new_sl, &ascii, M_LABEL,
807794d41b3a PSARC 2009/348 Security Labels for ZFS
Ric Aleshire <Ric.Aleshire@Sun.COM>
parents: 10969
diff changeset
  2059
			    DEF_NAMES) != 0) {
807794d41b3a PSARC 2009/348 Security Labels for ZFS
Ric Aleshire <Ric.Aleshire@Sun.COM>
parents: 10969
diff changeset
  2060
				if (ascii)
807794d41b3a PSARC 2009/348 Security Labels for ZFS
Ric Aleshire <Ric.Aleshire@Sun.COM>
parents: 10969
diff changeset
  2061
					free(ascii);
807794d41b3a PSARC 2009/348 Security Labels for ZFS
Ric Aleshire <Ric.Aleshire@Sun.COM>
parents: 10969
diff changeset
  2062
				m_label_free(new_sl);
807794d41b3a PSARC 2009/348 Security Labels for ZFS
Ric Aleshire <Ric.Aleshire@Sun.COM>
parents: 10969
diff changeset
  2063
				break;
807794d41b3a PSARC 2009/348 Security Labels for ZFS
Ric Aleshire <Ric.Aleshire@Sun.COM>
parents: 10969
diff changeset
  2064
			}
807794d41b3a PSARC 2009/348 Security Labels for ZFS
Ric Aleshire <Ric.Aleshire@Sun.COM>
parents: 10969
diff changeset
  2065
			m_label_free(new_sl);
807794d41b3a PSARC 2009/348 Security Labels for ZFS
Ric Aleshire <Ric.Aleshire@Sun.COM>
parents: 10969
diff changeset
  2066
807794d41b3a PSARC 2009/348 Security Labels for ZFS
Ric Aleshire <Ric.Aleshire@Sun.COM>
parents: 10969
diff changeset
  2067
			(void) strlcpy(propbuf, ascii, proplen);
807794d41b3a PSARC 2009/348 Security Labels for ZFS
Ric Aleshire <Ric.Aleshire@Sun.COM>
parents: 10969
diff changeset
  2068
			free(ascii);
807794d41b3a PSARC 2009/348 Security Labels for ZFS
Ric Aleshire <Ric.Aleshire@Sun.COM>
parents: 10969
diff changeset
  2069
		}
807794d41b3a PSARC 2009/348 Security Labels for ZFS
Ric Aleshire <Ric.Aleshire@Sun.COM>
parents: 10969
diff changeset
  2070
		break;
807794d41b3a PSARC 2009/348 Security Labels for ZFS
Ric Aleshire <Ric.Aleshire@Sun.COM>
parents: 10969
diff changeset
  2071
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2072
	default:
4577
ed36b0e652bc PSARC/2007/328 zfs upgrade
ahrens
parents: 4543
diff changeset
  2073
		switch (zfs_prop_get_type(prop)) {
4787
602d3f97842c 6393351 unique_* could be improved
ahrens
parents: 4778
diff changeset
  2074
		case PROP_TYPE_NUMBER:
4577
ed36b0e652bc PSARC/2007/328 zfs upgrade
ahrens
parents: 4543
diff changeset
  2075
			if (get_numeric_property(zhp, prop, src,
ed36b0e652bc PSARC/2007/328 zfs upgrade
ahrens
parents: 4543
diff changeset
  2076
			    &source, &val) != 0)
ed36b0e652bc PSARC/2007/328 zfs upgrade
ahrens
parents: 4543
diff changeset
  2077
				return (-1);
ed36b0e652bc PSARC/2007/328 zfs upgrade
ahrens
parents: 4543
diff changeset
  2078
			if (literal)
ed36b0e652bc PSARC/2007/328 zfs upgrade
ahrens
parents: 4543
diff changeset
  2079
				(void) snprintf(propbuf, proplen, "%llu",
ed36b0e652bc PSARC/2007/328 zfs upgrade
ahrens
parents: 4543
diff changeset
  2080
				    (u_longlong_t)val);
ed36b0e652bc PSARC/2007/328 zfs upgrade
ahrens
parents: 4543
diff changeset
  2081
			else
ed36b0e652bc PSARC/2007/328 zfs upgrade
ahrens
parents: 4543
diff changeset
  2082
				zfs_nicenum(val, propbuf, proplen);
ed36b0e652bc PSARC/2007/328 zfs upgrade
ahrens
parents: 4543
diff changeset
  2083
			break;
ed36b0e652bc PSARC/2007/328 zfs upgrade
ahrens
parents: 4543
diff changeset
  2084
4787
602d3f97842c 6393351 unique_* could be improved
ahrens
parents: 4778
diff changeset
  2085
		case PROP_TYPE_STRING:
4577
ed36b0e652bc PSARC/2007/328 zfs upgrade
ahrens
parents: 4543
diff changeset
  2086
			(void) strlcpy(propbuf,
ed36b0e652bc PSARC/2007/328 zfs upgrade
ahrens
parents: 4543
diff changeset
  2087
			    getprop_string(zhp, prop, &source), proplen);
ed36b0e652bc PSARC/2007/328 zfs upgrade
ahrens
parents: 4543
diff changeset
  2088
			break;
ed36b0e652bc PSARC/2007/328 zfs upgrade
ahrens
parents: 4543
diff changeset
  2089
4787
602d3f97842c 6393351 unique_* could be improved
ahrens
parents: 4778
diff changeset
  2090
		case PROP_TYPE_INDEX:
4861
fa5be10d6612 6592018 "zfs get" does not display temporary property
ahrens
parents: 4849
diff changeset
  2091
			if (get_numeric_property(zhp, prop, src,
fa5be10d6612 6592018 "zfs get" does not display temporary property
ahrens
parents: 4849
diff changeset
  2092
			    &source, &val) != 0)
fa5be10d6612 6592018 "zfs get" does not display temporary property
ahrens
parents: 4849
diff changeset
  2093
				return (-1);
fa5be10d6612 6592018 "zfs get" does not display temporary property
ahrens
parents: 4849
diff changeset
  2094
			if (zfs_prop_index_to_string(prop, val, &strval) != 0)
4577
ed36b0e652bc PSARC/2007/328 zfs upgrade
ahrens
parents: 4543
diff changeset
  2095
				return (-1);
ed36b0e652bc PSARC/2007/328 zfs upgrade
ahrens
parents: 4543
diff changeset
  2096
			(void) strlcpy(propbuf, strval, proplen);
ed36b0e652bc PSARC/2007/328 zfs upgrade
ahrens
parents: 4543
diff changeset
  2097
			break;
ed36b0e652bc PSARC/2007/328 zfs upgrade
ahrens
parents: 4543
diff changeset
  2098
ed36b0e652bc PSARC/2007/328 zfs upgrade
ahrens
parents: 4543
diff changeset
  2099
		default:
ed36b0e652bc PSARC/2007/328 zfs upgrade
ahrens
parents: 4543
diff changeset
  2100
			abort();
ed36b0e652bc PSARC/2007/328 zfs upgrade
ahrens
parents: 4543
diff changeset
  2101
		}
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2102
	}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2103
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2104
	get_source(zhp, src, source, statbuf, statlen);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2105
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2106
	return (0);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2107
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2108
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2109
/*
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2110
 * Utility function to get the given numeric property.  Does no validation that
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2111
 * the given property is the appropriate type; should only be used with
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2112
 * hard-coded property types.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2113
 */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2114
uint64_t
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2115
zfs_prop_get_int(zfs_handle_t *zhp, zfs_prop_t prop)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2116
{
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2117
	char *source;
2082
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1793
diff changeset
  2118
	uint64_t val;
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1793
diff changeset
  2119
5367
c40abbe796be PSARC/2007/574 zfs send -R
ahrens
parents: 5331
diff changeset
  2120
	(void) get_numeric_property(zhp, prop, NULL, &source, &val);
2082
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1793
diff changeset
  2121
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1793
diff changeset
  2122
	return (val);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2123
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2124
5713
f9b7933f3770 PSARC/2007/675 A_MDEV Removal
rm160521
parents: 5592
diff changeset
  2125
int
f9b7933f3770 PSARC/2007/675 A_MDEV Removal
rm160521
parents: 5592
diff changeset
  2126
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
  2127
{
f9b7933f3770 PSARC/2007/675 A_MDEV Removal
rm160521
parents: 5592
diff changeset
  2128
	char buf[64];
f9b7933f3770 PSARC/2007/675 A_MDEV Removal
rm160521
parents: 5592
diff changeset
  2129
9396
f41cf682d0d3 PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 8845
diff changeset
  2130
	(void) snprintf(buf, sizeof (buf), "%llu", (longlong_t)val);
5713
f9b7933f3770 PSARC/2007/675 A_MDEV Removal
rm160521
parents: 5592
diff changeset
  2131
	return (zfs_prop_set(zhp, zfs_prop_to_name(prop), buf));
f9b7933f3770 PSARC/2007/675 A_MDEV Removal
rm160521
parents: 5592
diff changeset
  2132
}
f9b7933f3770 PSARC/2007/675 A_MDEV Removal
rm160521
parents: 5592
diff changeset
  2133
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2134
/*
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2135
 * Similar to zfs_prop_get(), but returns the value as an integer.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2136
 */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2137
int
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2138
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
  2139
    zprop_source_t *src, char *statbuf, size_t statlen)
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2140
{
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2141
	char *source;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2142
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2143
	/*
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2144
	 * Check to see if this property applies to our object
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2145
	 */
4849
3a61e0a9a953 6536043 arc_byteswap_func_t and dmu_byteswap_func_t are redundant
ahrens
parents: 4801
diff changeset
  2146
	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
  2147
		return (zfs_error_fmt(zhp->zfs_hdl, EZFS_PROPTYPE,
2082
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1793
diff changeset
  2148
		    dgettext(TEXT_DOMAIN, "cannot get property '%s'"),
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1793
diff changeset
  2149
		    zfs_prop_to_name(prop)));
4849
3a61e0a9a953 6536043 arc_byteswap_func_t and dmu_byteswap_func_t are redundant
ahrens
parents: 4801
diff changeset
  2150
	}
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2151
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2152
	if (src)
5094
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4861
diff changeset
  2153
		*src = ZPROP_SRC_NONE;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2154
2082
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1793
diff changeset
  2155
	if (get_numeric_property(zhp, prop, src, &source, value) != 0)
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1793
diff changeset
  2156
		return (-1);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2157
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2158
	get_source(zhp, src, source, statbuf, statlen);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2159
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2160
	return (0);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2161
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2162
9396
f41cf682d0d3 PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 8845
diff changeset
  2163
static int
f41cf682d0d3 PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 8845
diff changeset
  2164
idmap_id_to_numeric_domain_rid(uid_t id, boolean_t isuser,
f41cf682d0d3 PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 8845
diff changeset
  2165
    char **domainp, idmap_rid_t *ridp)
f41cf682d0d3 PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 8845
diff changeset
  2166
{
f41cf682d0d3 PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 8845
diff changeset
  2167
	idmap_handle_t *idmap_hdl = NULL;
f41cf682d0d3 PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 8845
diff changeset
  2168
	idmap_get_handle_t *get_hdl = NULL;
f41cf682d0d3 PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 8845
diff changeset
  2169
	idmap_stat status;
f41cf682d0d3 PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 8845
diff changeset
  2170
	int err = EINVAL;
f41cf682d0d3 PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 8845
diff changeset
  2171
f41cf682d0d3 PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 8845
diff changeset
  2172
	if (idmap_init(&idmap_hdl) != IDMAP_SUCCESS)
f41cf682d0d3 PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 8845
diff changeset
  2173
		goto out;
f41cf682d0d3 PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 8845
diff changeset
  2174
	if (idmap_get_create(idmap_hdl, &get_hdl) != IDMAP_SUCCESS)
f41cf682d0d3 PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 8845
diff changeset
  2175
		goto out;
f41cf682d0d3 PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 8845
diff changeset
  2176
f41cf682d0d3 PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 8845
diff changeset
  2177
	if (isuser) {
f41cf682d0d3 PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 8845
diff changeset
  2178
		err = idmap_get_sidbyuid(get_hdl, id,
f41cf682d0d3 PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 8845
diff changeset
  2179
		    IDMAP_REQ_FLG_USE_CACHE, domainp, ridp, &status);
f41cf682d0d3 PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 8845
diff changeset
  2180
	} else {
f41cf682d0d3 PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 8845
diff changeset
  2181
		err = idmap_get_sidbygid(get_hdl, id,
f41cf682d0d3 PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 8845
diff changeset
  2182
		    IDMAP_REQ_FLG_USE_CACHE, domainp, ridp, &status);
f41cf682d0d3 PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 8845
diff changeset
  2183
	}
f41cf682d0d3 PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 8845
diff changeset
  2184
	if (err == IDMAP_SUCCESS &&
f41cf682d0d3 PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 8845
diff changeset
  2185
	    idmap_get_mappings(get_hdl) == IDMAP_SUCCESS &&
f41cf682d0d3 PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 8845
diff changeset
  2186
	    status == IDMAP_SUCCESS)
f41cf682d0d3 PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 8845
diff changeset
  2187
		err = 0;
f41cf682d0d3 PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 8845
diff changeset
  2188
	else
f41cf682d0d3 PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 8845
diff changeset
  2189
		err = EINVAL;
f41cf682d0d3 PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 8845
diff changeset
  2190
out:
f41cf682d0d3 PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 8845
diff changeset
  2191
	if (get_hdl)
f41cf682d0d3 PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 8845
diff changeset
  2192
		idmap_get_destroy(get_hdl);
f41cf682d0d3 PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 8845
diff changeset
  2193
	if (idmap_hdl)
f41cf682d0d3 PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 8845
diff changeset
  2194
		(void) idmap_fini(idmap_hdl);
f41cf682d0d3 PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 8845
diff changeset
  2195
	return (err);
f41cf682d0d3 PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 8845
diff changeset
  2196
}
f41cf682d0d3 PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 8845
diff changeset
  2197
f41cf682d0d3 PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 8845
diff changeset
  2198
/*
f41cf682d0d3 PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 8845
diff changeset
  2199
 * convert the propname into parameters needed by kernel
f41cf682d0d3 PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 8845
diff changeset
  2200
 * Eg: userquota@ahrens -> ZFS_PROP_USERQUOTA, "", 126829
f41cf682d0d3 PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 8845
diff changeset
  2201
 * Eg: userused@matt@domain -> ZFS_PROP_USERUSED, "S-1-123-456", 789
f41cf682d0d3 PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 8845
diff changeset
  2202
 */
f41cf682d0d3 PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 8845
diff changeset
  2203
static int
f41cf682d0d3 PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 8845
diff changeset
  2204
userquota_propname_decode(const char *propname, boolean_t zoned,
f41cf682d0d3 PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 8845
diff changeset
  2205
    zfs_userquota_prop_t *typep, char *domain, int domainlen, uint64_t *ridp)
f41cf682d0d3 PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 8845
diff changeset
  2206
{
f41cf682d0d3 PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 8845
diff changeset
  2207
	zfs_userquota_prop_t type;
f41cf682d0d3 PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 8845
diff changeset
  2208
	char *cp, *end;
10160
a45b03783d44 6861983 zfs should use new name <-> SID interfaces
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 9688
diff changeset
  2209
	char *numericsid = NULL;
9396
f41cf682d0d3 PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 8845
diff changeset
  2210
	boolean_t isuser;
f41cf682d0d3 PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 8845
diff changeset
  2211
f41cf682d0d3 PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 8845
diff changeset
  2212
	domain[0] = '\0';
f41cf682d0d3 PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 8845
diff changeset
  2213
f41cf682d0d3 PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 8845
diff changeset
  2214
	/* Figure out the property type ({user|group}{quota|space}) */
f41cf682d0d3 PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 8845
diff changeset
  2215
	for (type = 0; type < ZFS_NUM_USERQUOTA_PROPS; type++) {
f41cf682d0d3 PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 8845
diff changeset
  2216
		if (strncmp(propname, zfs_userquota_prop_prefixes[type],
f41cf682d0d3 PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 8845
diff changeset
  2217
		    strlen(zfs_userquota_prop_prefixes[type])) == 0)
f41cf682d0d3 PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 8845
diff changeset
  2218
			break;
f41cf682d0d3 PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 8845
diff changeset
  2219
	}
f41cf682d0d3 PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 8845
diff changeset
  2220
	if (type == ZFS_NUM_USERQUOTA_PROPS)
f41cf682d0d3 PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 8845
diff changeset
  2221
		return (EINVAL);
f41cf682d0d3 PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 8845
diff changeset
  2222
	*typep = type;
f41cf682d0d3 PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 8845
diff changeset
  2223
f41cf682d0d3 PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 8845
diff changeset
  2224
	isuser = (type == ZFS_PROP_USERQUOTA ||
f41cf682d0d3 PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 8845
diff changeset
  2225
	    type == ZFS_PROP_USERUSED);
f41cf682d0d3 PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 8845
diff changeset
  2226
f41cf682d0d3 PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 8845
diff changeset
  2227
	cp = strchr(propname, '@') + 1;
f41cf682d0d3 PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 8845
diff changeset
  2228
f41cf682d0d3 PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 8845
diff changeset
  2229
	if (strchr(cp, '@')) {
f41cf682d0d3 PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 8845
diff changeset
  2230
		/*
f41cf682d0d3 PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 8845
diff changeset
  2231
		 * It's a SID name (eg "user@domain") that needs to be
10160
a45b03783d44 6861983 zfs should use new name <-> SID interfaces
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 9688
diff changeset
  2232
		 * turned into S-1-domainID-RID.
9396
f41cf682d0d3 PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 8845
diff changeset
  2233
		 */
10160
a45b03783d44 6861983 zfs should use new name <-> SID interfaces
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 9688
diff changeset
  2234
		directory_error_t e;
9396
f41cf682d0d3 PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 8845
diff changeset
  2235
		if (zoned && getzoneid() == GLOBAL_ZONEID)
f41cf682d0d3 PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 8845
diff changeset
  2236
			return (ENOENT);
10160
a45b03783d44 6861983 zfs should use new name <-> SID interfaces
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 9688
diff changeset
  2237
		if (isuser) {
a45b03783d44 6861983 zfs should use new name <-> SID interfaces
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 9688
diff changeset
  2238
			e = directory_sid_from_user_name(NULL,
a45b03783d44 6861983 zfs should use new name <-> SID interfaces
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 9688
diff changeset
  2239
			    cp, &numericsid);
a45b03783d44 6861983 zfs should use new name <-> SID interfaces
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 9688
diff changeset
  2240
		} else {
a45b03783d44 6861983 zfs should use new name <-> SID interfaces
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 9688
diff changeset
  2241
			e = directory_sid_from_group_name(NULL,
a45b03783d44 6861983 zfs should use new name <-> SID interfaces
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 9688
diff changeset
  2242
			    cp, &numericsid);
a45b03783d44 6861983 zfs should use new name <-> SID interfaces
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 9688
diff changeset
  2243
		}
a45b03783d44 6861983 zfs should use new name <-> SID interfaces
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 9688
diff changeset
  2244
		if (e != NULL) {
a45b03783d44 6861983 zfs should use new name <-> SID interfaces
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 9688
diff changeset
  2245
			directory_error_free(e);
9396
f41cf682d0d3 PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 8845
diff changeset
  2246
			return (ENOENT);
10160
a45b03783d44 6861983 zfs should use new name <-> SID interfaces
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 9688
diff changeset
  2247
		}
a45b03783d44 6861983 zfs should use new name <-> SID interfaces
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 9688
diff changeset
  2248
		if (numericsid == NULL)
a45b03783d44 6861983 zfs should use new name <-> SID interfaces
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 9688
diff changeset
  2249
			return (ENOENT);
a45b03783d44 6861983 zfs should use new name <-> SID interfaces
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 9688
diff changeset
  2250
		cp = numericsid;
a45b03783d44 6861983 zfs should use new name <-> SID interfaces
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 9688
diff changeset
  2251
		/* will be further decoded below */
a45b03783d44 6861983 zfs should use new name <-> SID interfaces
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 9688
diff changeset
  2252
	}
a45b03783d44 6861983 zfs should use new name <-> SID interfaces
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 9688
diff changeset
  2253
a45b03783d44 6861983 zfs should use new name <-> SID interfaces
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 9688
diff changeset
  2254
	if (strncmp(cp, "S-1-", 4) == 0) {
9396
f41cf682d0d3 PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 8845
diff changeset
  2255
		/* It's a numeric SID (eg "S-1-234-567-89") */
10160
a45b03783d44 6861983 zfs should use new name <-> SID interfaces
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 9688
diff changeset
  2256
		(void) strlcpy(domain, cp, domainlen);
9396
f41cf682d0d3 PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 8845
diff changeset
  2257
		cp = strrchr(domain, '-');
f41cf682d0d3 PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 8845
diff changeset
  2258
		*cp = '\0';
f41cf682d0d3 PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 8845
diff changeset
  2259
		cp++;
f41cf682d0d3 PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 8845
diff changeset
  2260
f41cf682d0d3 PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 8845
diff changeset
  2261
		errno = 0;
f41cf682d0d3 PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 8845
diff changeset
  2262
		*ridp = strtoull(cp, &end, 10);
10160
a45b03783d44 6861983 zfs should use new name <-> SID interfaces
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 9688
diff changeset
  2263
		if (numericsid) {
a45b03783d44 6861983 zfs should use new name <-> SID interfaces
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 9688
diff changeset
  2264
			free(numericsid);
a45b03783d44 6861983 zfs should use new name <-> SID interfaces
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 9688
diff changeset
  2265
			numericsid = NULL;
a45b03783d44 6861983 zfs should use new name <-> SID interfaces
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 9688
diff changeset
  2266
		}
9688
127be1845343 6841321 zfs userspace / zfs get userused@ doesn't work on mounted snapshot
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 9554
diff changeset
  2267
		if (errno != 0 || *end != '\0')
9396
f41cf682d0d3 PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 8845
diff changeset
  2268
			return (EINVAL);
f41cf682d0d3 PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 8845
diff changeset
  2269
	} else if (!isdigit(*cp)) {
f41cf682d0d3 PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 8845
diff changeset
  2270
		/*
f41cf682d0d3 PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 8845
diff changeset
  2271
		 * It's a user/group name (eg "user") that needs to be
f41cf682d0d3 PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 8845
diff changeset
  2272
		 * turned into a uid/gid
f41cf682d0d3 PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 8845
diff changeset
  2273
		 */
f41cf682d0d3 PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 8845
diff changeset
  2274
		if (zoned && getzoneid() == GLOBAL_ZONEID)
f41cf682d0d3 PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 8845
diff changeset
  2275
			return (ENOENT);
f41cf682d0d3 PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 8845
diff changeset
  2276
		if (isuser) {
f41cf682d0d3 PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 8845
diff changeset
  2277
			struct passwd *pw;
f41cf682d0d3 PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 8845
diff changeset
  2278
			pw = getpwnam(cp);
f41cf682d0d3 PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 8845
diff changeset
  2279
			if (pw == NULL)
f41cf682d0d3 PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 8845
diff changeset
  2280
				return (ENOENT);
f41cf682d0d3 PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 8845
diff changeset
  2281
			*ridp = pw->pw_uid;
f41cf682d0d3 PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 8845
diff changeset
  2282
		} else {
f41cf682d0d3 PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 8845
diff changeset
  2283
			struct group *gr;
f41cf682d0d3 PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 8845
diff changeset
  2284
			gr = getgrnam(cp);
f41cf682d0d3 PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 8845
diff changeset
  2285
			if (gr == NULL)
f41cf682d0d3 PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 8845
diff changeset
  2286
				return (ENOENT);
f41cf682d0d3 PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 8845
diff changeset
  2287
			*ridp = gr->gr_gid;
f41cf682d0d3 PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 8845
diff changeset
  2288
		}
f41cf682d0d3 PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 8845
diff changeset
  2289
	} else {
f41cf682d0d3 PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 8845
diff changeset
  2290
		/* It's a user/group ID (eg "12345"). */
f41cf682d0d3 PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 8845
diff changeset
  2291
		uid_t id = strtoul(cp, &end, 10);
f41cf682d0d3 PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 8845
diff changeset
  2292
		idmap_rid_t rid;
f41cf682d0d3 PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 8845
diff changeset
  2293
		char *mapdomain;
f41cf682d0d3 PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 8845
diff changeset
  2294
f41cf682d0d3 PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 8845
diff changeset
  2295
		if (*end != '\0')
f41cf682d0d3 PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 8845
diff changeset
  2296
			return (EINVAL);
f41cf682d0d3 PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 8845
diff changeset
  2297
		if (id > MAXUID) {
f41cf682d0d3 PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 8845
diff changeset
  2298
			/* It's an ephemeral ID. */
f41cf682d0d3 PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 8845
diff changeset
  2299
			if (idmap_id_to_numeric_domain_rid(id, isuser,
f41cf682d0d3 PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 8845
diff changeset
  2300
			    &mapdomain, &rid) != 0)
f41cf682d0d3 PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 8845
diff changeset
  2301
				return (ENOENT);
10160
a45b03783d44 6861983 zfs should use new name <-> SID interfaces
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 9688
diff changeset
  2302
			(void) strlcpy(domain, mapdomain, domainlen);
9396
f41cf682d0d3 PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 8845
diff changeset
  2303
			*ridp = rid;
f41cf682d0d3 PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 8845
diff changeset
  2304
		} else {
f41cf682d0d3 PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 8845
diff changeset
  2305
			*ridp = id;
f41cf682d0d3 PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 8845
diff changeset
  2306
		}
f41cf682d0d3 PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 8845
diff changeset
  2307
	}
f41cf682d0d3 PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 8845
diff changeset
  2308
10160
a45b03783d44 6861983 zfs should use new name <-> SID interfaces
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 9688
diff changeset
  2309
	ASSERT3P(numericsid, ==, NULL);
9396
f41cf682d0d3 PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 8845
diff changeset
  2310
	return (0);
f41cf682d0d3 PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 8845
diff changeset
  2311
}
f41cf682d0d3 PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 8845
diff changeset
  2312
9469
4f68f041ddcd 6824968 add ZFS userquota support to rquotad
Lin Ling <Lin.Ling@Sun.COM>
parents: 9396
diff changeset
  2313
static int
4f68f041ddcd 6824968 add ZFS userquota support to rquotad
Lin Ling <Lin.Ling@Sun.COM>
parents: 9396
diff changeset
  2314
zfs_prop_get_userquota_common(zfs_handle_t *zhp, const char *propname,
4f68f041ddcd 6824968 add ZFS userquota support to rquotad
Lin Ling <Lin.Ling@Sun.COM>
parents: 9396
diff changeset
  2315
    uint64_t *propvalue, zfs_userquota_prop_t *typep)
9396
f41cf682d0d3 PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 8845
diff changeset
  2316
{
f41cf682d0d3 PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 8845
diff changeset
  2317
	int err;
f41cf682d0d3 PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 8845
diff changeset
  2318
	zfs_cmd_t zc = { 0 };
f41cf682d0d3 PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 8845
diff changeset
  2319
f41cf682d0d3 PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 8845
diff changeset
  2320
	(void) strncpy(zc.zc_name, zhp->zfs_name, sizeof (zc.zc_name));
f41cf682d0d3 PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 8845
diff changeset
  2321
f41cf682d0d3 PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 8845
diff changeset
  2322
	err = userquota_propname_decode(propname,
f41cf682d0d3 PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 8845
diff changeset
  2323
	    zfs_prop_get_int(zhp, ZFS_PROP_ZONED),
9469
4f68f041ddcd 6824968 add ZFS userquota support to rquotad
Lin Ling <Lin.Ling@Sun.COM>
parents: 9396
diff changeset
  2324
	    typep, zc.zc_value, sizeof (zc.zc_value), &zc.zc_guid);
4f68f041ddcd 6824968 add ZFS userquota support to rquotad
Lin Ling <Lin.Ling@Sun.COM>
parents: 9396
diff changeset
  2325
	zc.zc_objset_type = *typep;
9396
f41cf682d0d3 PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 8845
diff changeset
  2326
	if (err)
f41cf682d0d3 PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 8845
diff changeset
  2327
		return (err);
f41cf682d0d3 PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 8845
diff changeset
  2328
f41cf682d0d3 PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 8845
diff changeset
  2329
	err = ioctl(zhp->zfs_hdl->libzfs_fd, ZFS_IOC_USERSPACE_ONE, &zc);
f41cf682d0d3 PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 8845
diff changeset
  2330
	if (err)
f41cf682d0d3 PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 8845
diff changeset
  2331
		return (err);
f41cf682d0d3 PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 8845
diff changeset
  2332
9469
4f68f041ddcd 6824968 add ZFS userquota support to rquotad
Lin Ling <Lin.Ling@Sun.COM>
parents: 9396
diff changeset
  2333
	*propvalue = zc.zc_cookie;
4f68f041ddcd 6824968 add ZFS userquota support to rquotad
Lin Ling <Lin.Ling@Sun.COM>
parents: 9396
diff changeset
  2334
	return (0);
4f68f041ddcd 6824968 add ZFS userquota support to rquotad
Lin Ling <Lin.Ling@Sun.COM>
parents: 9396
diff changeset
  2335
}
4f68f041ddcd 6824968 add ZFS userquota support to rquotad
Lin Ling <Lin.Ling@Sun.COM>
parents: 9396
diff changeset
  2336
4f68f041ddcd 6824968 add ZFS userquota support to rquotad
Lin Ling <Lin.Ling@Sun.COM>
parents: 9396
diff changeset
  2337
int
4f68f041ddcd 6824968 add ZFS userquota support to rquotad
Lin Ling <Lin.Ling@Sun.COM>
parents: 9396
diff changeset
  2338
zfs_prop_get_userquota_int(zfs_handle_t *zhp, const char *propname,
4f68f041ddcd 6824968 add ZFS userquota support to rquotad
Lin Ling <Lin.Ling@Sun.COM>
parents: 9396
diff changeset
  2339
    uint64_t *propvalue)
4f68f041ddcd 6824968 add ZFS userquota support to rquotad
Lin Ling <Lin.Ling@Sun.COM>
parents: 9396
diff changeset
  2340
{
4f68f041ddcd 6824968 add ZFS userquota support to rquotad
Lin Ling <Lin.Ling@Sun.COM>
parents: 9396
diff changeset
  2341
	zfs_userquota_prop_t type;
4f68f041ddcd 6824968 add ZFS userquota support to rquotad
Lin Ling <Lin.Ling@Sun.COM>
parents: 9396
diff changeset
  2342
4f68f041ddcd 6824968 add ZFS userquota support to rquotad
Lin Ling <Lin.Ling@Sun.COM>
parents: 9396
diff changeset
  2343
	return (zfs_prop_get_userquota_common(zhp, propname, propvalue,
4f68f041ddcd 6824968 add ZFS userquota support to rquotad
Lin Ling <Lin.Ling@Sun.COM>
parents: 9396
diff changeset
  2344
	    &type));
4f68f041ddcd 6824968 add ZFS userquota support to rquotad
Lin Ling <Lin.Ling@Sun.COM>
parents: 9396
diff changeset
  2345
}
4f68f041ddcd 6824968 add ZFS userquota support to rquotad
Lin Ling <Lin.Ling@Sun.COM>
parents: 9396
diff changeset
  2346
4f68f041ddcd 6824968 add ZFS userquota support to rquotad
Lin Ling <Lin.Ling@Sun.COM>
parents: 9396
diff changeset
  2347
int
4f68f041ddcd 6824968 add ZFS userquota support to rquotad
Lin Ling <Lin.Ling@Sun.COM>
parents: 9396
diff changeset
  2348
zfs_prop_get_userquota(zfs_handle_t *zhp, const char *propname,
4f68f041ddcd 6824968 add ZFS userquota support to rquotad
Lin Ling <Lin.Ling@Sun.COM>
parents: 9396
diff changeset
  2349
    char *propbuf, int proplen, boolean_t literal)
4f68f041ddcd 6824968 add ZFS userquota support to rquotad
Lin Ling <Lin.Ling@Sun.COM>
parents: 9396
diff changeset
  2350
{
4f68f041ddcd 6824968 add ZFS userquota support to rquotad
Lin Ling <Lin.Ling@Sun.COM>
parents: 9396
diff changeset
  2351
	int err;
4f68f041ddcd 6824968 add ZFS userquota support to rquotad
Lin Ling <Lin.Ling@Sun.COM>
parents: 9396
diff changeset
  2352
	uint64_t propvalue;
4f68f041ddcd 6824968 add ZFS userquota support to rquotad
Lin Ling <Lin.Ling@Sun.COM>
parents: 9396
diff changeset
  2353
	zfs_userquota_prop_t type;
4f68f041ddcd 6824968 add ZFS userquota support to rquotad
Lin Ling <Lin.Ling@Sun.COM>
parents: 9396
diff changeset
  2354
4f68f041ddcd 6824968 add ZFS userquota support to rquotad
Lin Ling <Lin.Ling@Sun.COM>
parents: 9396
diff changeset
  2355
	err = zfs_prop_get_userquota_common(zhp, propname, &propvalue,
4f68f041ddcd 6824968 add ZFS userquota support to rquotad
Lin Ling <Lin.Ling@Sun.COM>
parents: 9396
diff changeset
  2356
	    &type);
4f68f041ddcd 6824968 add ZFS userquota support to rquotad
Lin Ling <Lin.Ling@Sun.COM>
parents: 9396
diff changeset
  2357
4f68f041ddcd 6824968 add ZFS userquota support to rquotad
Lin Ling <Lin.Ling@Sun.COM>
parents: 9396
diff changeset
  2358
	if (err)
4f68f041ddcd 6824968 add ZFS userquota support to rquotad
Lin Ling <Lin.Ling@Sun.COM>
parents: 9396
diff changeset
  2359
		return (err);
4f68f041ddcd 6824968 add ZFS userquota support to rquotad
Lin Ling <Lin.Ling@Sun.COM>
parents: 9396
diff changeset
  2360
9396
f41cf682d0d3 PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 8845
diff changeset
  2361
	if (literal) {
9469
4f68f041ddcd 6824968 add ZFS userquota support to rquotad
Lin Ling <Lin.Ling@Sun.COM>
parents: 9396
diff changeset
  2362
		(void) snprintf(propbuf, proplen, "%llu", propvalue);
4f68f041ddcd 6824968 add ZFS userquota support to rquotad
Lin Ling <Lin.Ling@Sun.COM>
parents: 9396
diff changeset
  2363
	} else if (propvalue == 0 &&
9396
f41cf682d0d3 PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 8845
diff changeset
  2364
	    (type == ZFS_PROP_USERQUOTA || type == ZFS_PROP_GROUPQUOTA)) {
f41cf682d0d3 PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 8845
diff changeset
  2365
		(void) strlcpy(propbuf, "none", proplen);
f41cf682d0d3 PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 8845
diff changeset
  2366
	} else {
9469
4f68f041ddcd 6824968 add ZFS userquota support to rquotad
Lin Ling <Lin.Ling@Sun.COM>
parents: 9396
diff changeset
  2367
		zfs_nicenum(propvalue, propbuf, proplen);
9396
f41cf682d0d3 PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 8845
diff changeset
  2368
	}
f41cf682d0d3 PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 8845
diff changeset
  2369
	return (0);
f41cf682d0d3 PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 8845
diff changeset
  2370
}
f41cf682d0d3 PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 8845
diff changeset
  2371
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2372
/*
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2373
 * Returns the name of the given zfs handle.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2374
 */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2375
const char *
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2376
zfs_get_name(const zfs_handle_t *zhp)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2377
{
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2378
	return (zhp->zfs_name);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2379
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2380
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2381
/*
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2382
 * Returns the type of the given zfs handle.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2383
 */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2384
zfs_type_t
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2385
zfs_get_type(const zfs_handle_t *zhp)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2386
{
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2387
	return (zhp->zfs_type);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2388
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2389
8228
51e9ca9ee3a5 6572357 libzfs should do more to avoid mnttab lookups
Eric Taylor <Eric.Taylor@Sun.COM>
parents: 7509
diff changeset
  2390
static int
51e9ca9ee3a5 6572357 libzfs should do more to avoid mnttab lookups
Eric Taylor <Eric.Taylor@Sun.COM>
parents: 7509
diff changeset
  2391
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
  2392
{
51e9ca9ee3a5 6572357 libzfs should do more to avoid mnttab lookups
Eric Taylor <Eric.Taylor@Sun.COM>
parents: 7509
diff changeset
  2393
	int rc;
51e9ca9ee3a5 6572357 libzfs should do more to avoid mnttab lookups
Eric Taylor <Eric.Taylor@Sun.COM>
parents: 7509
diff changeset
  2394
	uint64_t	orig_cookie;
51e9ca9ee3a5 6572357 libzfs should do more to avoid mnttab lookups
Eric Taylor <Eric.Taylor@Sun.COM>
parents: 7509
diff changeset
  2395
51e9ca9ee3a5 6572357 libzfs should do more to avoid mnttab lookups
Eric Taylor <Eric.Taylor@Sun.COM>
parents: 7509
diff changeset
  2396
	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
  2397
top:
51e9ca9ee3a5 6572357 libzfs should do more to avoid mnttab lookups
Eric Taylor <Eric.Taylor@Sun.COM>
parents: 7509
diff changeset
  2398
	(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
  2399
	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
  2400
51e9ca9ee3a5 6572357 libzfs should do more to avoid mnttab lookups
Eric Taylor <Eric.Taylor@Sun.COM>
parents: 7509
diff changeset
  2401
	if (rc == -1) {
51e9ca9ee3a5 6572357 libzfs should do more to avoid mnttab lookups
Eric Taylor <Eric.Taylor@Sun.COM>
parents: 7509
diff changeset
  2402
		switch (errno) {
51e9ca9ee3a5 6572357 libzfs should do more to avoid mnttab lookups
Eric Taylor <Eric.Taylor@Sun.COM>
parents: 7509
diff changeset
  2403
		case ENOMEM:
51e9ca9ee3a5 6572357 libzfs should do more to avoid mnttab lookups
Eric Taylor <Eric.Taylor@Sun.COM>
parents: 7509
diff changeset
  2404
			/* 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
  2405
			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
  2406
				zcmd_free_nvlists(zc);
51e9ca9ee3a5 6572357 libzfs should do more to avoid mnttab lookups
Eric Taylor <Eric.Taylor@Sun.COM>
parents: 7509
diff changeset
  2407
				return (-1);
51e9ca9ee3a5 6572357 libzfs should do more to avoid mnttab lookups
Eric Taylor <Eric.Taylor@Sun.COM>
parents: 7509
diff changeset
  2408
			}
51e9ca9ee3a5 6572357 libzfs should do more to avoid mnttab lookups
Eric Taylor <Eric.Taylor@Sun.COM>
parents: 7509
diff changeset
  2409
			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
  2410
			goto top;
51e9ca9ee3a5 6572357 libzfs should do more to avoid mnttab lookups
Eric Taylor <Eric.Taylor@Sun.COM>
parents: 7509
diff changeset
  2411
		/*
51e9ca9ee3a5 6572357 libzfs should do more to avoid mnttab lookups
Eric Taylor <Eric.Taylor@Sun.COM>
parents: 7509
diff changeset
  2412
		 * 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
  2413
		 * 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
  2414
		 * 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
  2415
		 */
51e9ca9ee3a5 6572357 libzfs should do more to avoid mnttab lookups
Eric Taylor <Eric.Taylor@Sun.COM>
parents: 7509
diff changeset
  2416
		case ESRCH:
51e9ca9ee3a5 6572357 libzfs should do more to avoid mnttab lookups
Eric Taylor <Eric.Taylor@Sun.COM>
parents: 7509
diff changeset
  2417
		case ENOENT:
51e9ca9ee3a5 6572357 libzfs should do more to avoid mnttab lookups
Eric Taylor <Eric.Taylor@Sun.COM>
parents: 7509
diff changeset
  2418
			rc = 1;
51e9ca9ee3a5 6572357 libzfs should do more to avoid mnttab lookups
Eric Taylor <Eric.Taylor@Sun.COM>
parents: 7509
diff changeset
  2419
			break;
51e9ca9ee3a5 6572357 libzfs should do more to avoid mnttab lookups
Eric Taylor <Eric.Taylor@Sun.COM>
parents: 7509
diff changeset
  2420
		default:
51e9ca9ee3a5 6572357 libzfs should do more to avoid mnttab lookups
Eric Taylor <Eric.Taylor@Sun.COM>
parents: 7509
diff changeset
  2421
			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
  2422
			    dgettext(TEXT_DOMAIN,
51e9ca9ee3a5 6572357 libzfs should do more to avoid mnttab lookups
Eric Taylor <Eric.Taylor@Sun.COM>
parents: 7509
diff changeset
  2423
			    "cannot iterate filesystems"));
51e9ca9ee3a5 6572357 libzfs should do more to avoid mnttab lookups
Eric Taylor <Eric.Taylor@Sun.COM>
parents: 7509
diff changeset
  2424
			break;
51e9ca9ee3a5 6572357 libzfs should do more to avoid mnttab lookups
Eric Taylor <Eric.Taylor@Sun.COM>
parents: 7509
diff changeset
  2425
		}
51e9ca9ee3a5 6572357 libzfs should do more to avoid mnttab lookups
Eric Taylor <Eric.Taylor@Sun.COM>
parents: 7509
diff changeset
  2426
	}
51e9ca9ee3a5 6572357 libzfs should do more to avoid mnttab lookups
Eric Taylor <Eric.Taylor@Sun.COM>
parents: 7509
diff changeset
  2427
	return (rc);
51e9ca9ee3a5 6572357 libzfs should do more to avoid mnttab lookups
Eric Taylor <Eric.Taylor@Sun.COM>
parents: 7509
diff changeset
  2428
}
51e9ca9ee3a5 6572357 libzfs should do more to avoid mnttab lookups
Eric Taylor <Eric.Taylor@Sun.COM>
parents: 7509
diff changeset
  2429
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2430
/*
1356
e021b5e4aa0e 6377671 zfs mount -a shouldn't bother checking snapshots
eschrock
parents: 1294
diff changeset
  2431
 * Iterate over all child filesystems
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2432
 */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2433
int
1356
e021b5e4aa0e 6377671 zfs mount -a shouldn't bother checking snapshots
eschrock
parents: 1294
diff changeset
  2434
zfs_iter_filesystems(zfs_handle_t *zhp, zfs_iter_f func, void *data)
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2435
{
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2436
	zfs_cmd_t zc = { 0 };
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2437
	zfs_handle_t *nzhp;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2438
	int ret;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2439
5367
c40abbe796be PSARC/2007/574 zfs send -R
ahrens
parents: 5331
diff changeset
  2440
	if (zhp->zfs_type != ZFS_TYPE_FILESYSTEM)
c40abbe796be PSARC/2007/574 zfs send -R
ahrens
parents: 5331
diff changeset
  2441
		return (0);
c40abbe796be PSARC/2007/574 zfs send -R
ahrens
parents: 5331
diff changeset
  2442
8228
51e9ca9ee3a5 6572357 libzfs should do more to avoid mnttab lookups
Eric Taylor <Eric.Taylor@Sun.COM>
parents: 7509
diff changeset
  2443
	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
  2444
		return (-1);
51e9ca9ee3a5 6572357 libzfs should do more to avoid mnttab lookups
Eric Taylor <Eric.Taylor@Sun.COM>
parents: 7509
diff changeset
  2445
51e9ca9ee3a5 6572357 libzfs should do more to avoid mnttab lookups
Eric Taylor <Eric.Taylor@Sun.COM>
parents: 7509
diff changeset
  2446
	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
  2447
	    &zc)) == 0) {
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2448
		/*
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2449
		 * Silently ignore errors, as the only plausible explanation is
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2450
		 * that the pool has since been removed.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2451
		 */
8228
51e9ca9ee3a5 6572357 libzfs should do more to avoid mnttab lookups
Eric Taylor <Eric.Taylor@Sun.COM>
parents: 7509
diff changeset
  2452
		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
  2453
		    &zc)) == NULL) {
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2454
			continue;
8228
51e9ca9ee3a5 6572357 libzfs should do more to avoid mnttab lookups
Eric Taylor <Eric.Taylor@Sun.COM>
parents: 7509
diff changeset
  2455
		}
51e9ca9ee3a5 6572357 libzfs should do more to avoid mnttab lookups
Eric Taylor <Eric.Taylor@Sun.COM>
parents: 7509
diff changeset
  2456
51e9ca9ee3a5 6572357 libzfs should do more to avoid mnttab lookups
Eric Taylor <Eric.Taylor@Sun.COM>
parents: 7509
diff changeset
  2457
		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
  2458
			zcmd_free_nvlists(&zc);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2459
			return (ret);
8228
51e9ca9ee3a5 6572357 libzfs should do more to avoid mnttab lookups
Eric Taylor <Eric.Taylor@Sun.COM>
parents: 7509
diff changeset
  2460
		}
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2461
	}
8228
51e9ca9ee3a5 6572357 libzfs should do more to avoid mnttab lookups
Eric Taylor <Eric.Taylor@Sun.COM>
parents: 7509
diff changeset
  2462
	zcmd_free_nvlists(&zc);
51e9ca9ee3a5 6572357 libzfs should do more to avoid mnttab lookups
Eric Taylor <Eric.Taylor@Sun.COM>
parents: 7509
diff changeset
  2463
	return ((ret < 0) ? ret : 0);
1356
e021b5e4aa0e 6377671 zfs mount -a shouldn't bother checking snapshots
eschrock
parents: 1294
diff changeset
  2464
}
e021b5e4aa0e 6377671 zfs mount -a shouldn't bother checking snapshots
eschrock
parents: 1294
diff changeset
  2465
e021b5e4aa0e 6377671 zfs mount -a shouldn't bother checking snapshots
eschrock
parents: 1294
diff changeset
  2466
/*
e021b5e4aa0e 6377671 zfs mount -a shouldn't bother checking snapshots
eschrock
parents: 1294
diff changeset
  2467
 * Iterate over all snapshots
e021b5e4aa0e 6377671 zfs mount -a shouldn't bother checking snapshots
eschrock
parents: 1294
diff changeset
  2468
 */
e021b5e4aa0e 6377671 zfs mount -a shouldn't bother checking snapshots
eschrock
parents: 1294
diff changeset
  2469
int
e021b5e4aa0e 6377671 zfs mount -a shouldn't bother checking snapshots
eschrock
parents: 1294
diff changeset
  2470
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
  2471
{
e021b5e4aa0e 6377671 zfs mount -a shouldn't bother checking snapshots
eschrock
parents: 1294
diff changeset
  2472
	zfs_cmd_t zc = { 0 };
e021b5e4aa0e 6377671 zfs mount -a shouldn't bother checking snapshots
eschrock
parents: 1294
diff changeset
  2473
	zfs_handle_t *nzhp;
e021b5e4aa0e 6377671 zfs mount -a shouldn't bother checking snapshots
eschrock
parents: 1294
diff changeset
  2474
	int ret;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2475
5367
c40abbe796be PSARC/2007/574 zfs send -R
ahrens
parents: 5331
diff changeset
  2476
	if (zhp->zfs_type == ZFS_TYPE_SNAPSHOT)
c40abbe796be PSARC/2007/574 zfs send -R
ahrens
parents: 5331
diff changeset
  2477
		return (0);
c40abbe796be PSARC/2007/574 zfs send -R
ahrens
parents: 5331
diff changeset
  2478
8228
51e9ca9ee3a5 6572357 libzfs should do more to avoid mnttab lookups
Eric Taylor <Eric.Taylor@Sun.COM>
parents: 7509
diff changeset
  2479
	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
  2480
		return (-1);
51e9ca9ee3a5 6572357 libzfs should do more to avoid mnttab lookups
Eric Taylor <Eric.Taylor@Sun.COM>
parents: 7509
diff changeset
  2481
	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
  2482
	    &zc)) == 0) {
51e9ca9ee3a5 6572357 libzfs should do more to avoid mnttab lookups
Eric Taylor <Eric.Taylor@Sun.COM>
parents: 7509
diff changeset
  2483
51e9ca9ee3a5 6572357 libzfs should do more to avoid mnttab lookups
Eric Taylor <Eric.Taylor@Sun.COM>
parents: 7509
diff changeset
  2484
		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
  2485
		    &zc)) == NULL) {
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2486
			continue;
8228
51e9ca9ee3a5 6572357 libzfs should do more to avoid mnttab lookups
Eric Taylor <Eric.Taylor@Sun.COM>
parents: 7509
diff changeset
  2487
		}
51e9ca9ee3a5 6572357 libzfs should do more to avoid mnttab lookups
Eric Taylor <Eric.Taylor@Sun.COM>
parents: 7509
diff changeset
  2488
51e9ca9ee3a5 6572357 libzfs should do more to avoid mnttab lookups
Eric Taylor <Eric.Taylor@Sun.COM>
parents: 7509
diff changeset
  2489
		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
  2490
			zcmd_free_nvlists(&zc);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2491
			return (ret);
8228
51e9ca9ee3a5 6572357 libzfs should do more to avoid mnttab lookups
Eric Taylor <Eric.Taylor@Sun.COM>
parents: 7509
diff changeset
  2492
		}
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2493
	}
8228
51e9ca9ee3a5 6572357 libzfs should do more to avoid mnttab lookups
Eric Taylor <Eric.Taylor@Sun.COM>
parents: 7509
diff changeset
  2494
	zcmd_free_nvlists(&zc);
51e9ca9ee3a5 6572357 libzfs should do more to avoid mnttab lookups
Eric Taylor <Eric.Taylor@Sun.COM>
parents: 7509
diff changeset
  2495
	return ((ret < 0) ? ret : 0);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2496
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2497
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2498
/*
1356
e021b5e4aa0e 6377671 zfs mount -a shouldn't bother checking snapshots
eschrock
parents: 1294
diff changeset
  2499
 * Iterate over all children, snapshots and filesystems
e021b5e4aa0e 6377671 zfs mount -a shouldn't bother checking snapshots
eschrock
parents: 1294
diff changeset
  2500
 */
e021b5e4aa0e 6377671 zfs mount -a shouldn't bother checking snapshots
eschrock
parents: 1294
diff changeset
  2501
int
e021b5e4aa0e 6377671 zfs mount -a shouldn't bother checking snapshots
eschrock
parents: 1294
diff changeset
  2502
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
  2503
{
e021b5e4aa0e 6377671 zfs mount -a shouldn't bother checking snapshots
eschrock
parents: 1294
diff changeset
  2504
	int ret;
e021b5e4aa0e 6377671 zfs mount -a shouldn't bother checking snapshots
eschrock
parents: 1294
diff changeset
  2505
e021b5e4aa0e 6377671 zfs mount -a shouldn't bother checking snapshots
eschrock
parents: 1294
diff changeset
  2506
	if ((ret = zfs_iter_filesystems(zhp, func, data)) != 0)
e021b5e4aa0e 6377671 zfs mount -a shouldn't bother checking snapshots
eschrock
parents: 1294
diff changeset
  2507
		return (ret);
e021b5e4aa0e 6377671 zfs mount -a shouldn't bother checking snapshots
eschrock
parents: 1294
diff changeset
  2508
e021b5e4aa0e 6377671 zfs mount -a shouldn't bother checking snapshots
eschrock
parents: 1294
diff changeset
  2509
	return (zfs_iter_snapshots(zhp, func, data));
e021b5e4aa0e 6377671 zfs mount -a shouldn't bother checking snapshots
eschrock
parents: 1294
diff changeset
  2510
}
e021b5e4aa0e 6377671 zfs mount -a shouldn't bother checking snapshots
eschrock
parents: 1294
diff changeset
  2511
e021b5e4aa0e 6377671 zfs mount -a shouldn't bother checking snapshots
eschrock
parents: 1294
diff changeset
  2512
/*
11497
69b45e632792 6698011 zfs incorrectly reports file systems as children when attempting a rename
Mark J Musante <Mark.Musante@Sun.COM>
parents: 11449
diff changeset
  2513
 * Is one dataset name a child dataset of another?
69b45e632792 6698011 zfs incorrectly reports file systems as children when attempting a rename
Mark J Musante <Mark.Musante@Sun.COM>
parents: 11449
diff changeset
  2514
 *
69b45e632792 6698011 zfs incorrectly reports file systems as children when attempting a rename
Mark J Musante <Mark.Musante@Sun.COM>
parents: 11449
diff changeset
  2515
 * Needs to handle these cases:
69b45e632792 6698011 zfs incorrectly reports file systems as children when attempting a rename
Mark J Musante <Mark.Musante@Sun.COM>
parents: 11449
diff changeset
  2516
 * Dataset 1	"a/foo"		"a/foo"		"a/foo"		"a/foo"
69b45e632792 6698011 zfs incorrectly reports file systems as children when attempting a rename
Mark J Musante <Mark.Musante@Sun.COM>
parents: 11449
diff changeset
  2517
 * Dataset 2	"a/fo"		"a/foobar"	"a/bar/baz"	"a/foo/bar"
69b45e632792 6698011 zfs incorrectly reports file systems as children when attempting a rename
Mark J Musante <Mark.Musante@Sun.COM>
parents: 11449
diff changeset
  2518
 * Descendant?	No.		No.		No.		Yes.
69b45e632792 6698011 zfs incorrectly reports file systems as children when attempting a rename
Mark J Musante <Mark.Musante@Sun.COM>
parents: 11449
diff changeset
  2519
 */
69b45e632792 6698011 zfs incorrectly reports file systems as children when attempting a rename
Mark J Musante <Mark.Musante@Sun.COM>
parents: 11449
diff changeset
  2520
static boolean_t
69b45e632792 6698011 zfs incorrectly reports file systems as children when attempting a rename
Mark J Musante <Mark.Musante@Sun.COM>
parents: 11449
diff changeset
  2521
is_descendant(const char *ds1, const char *ds2)
69b45e632792 6698011 zfs incorrectly reports file systems as children when attempting a rename
Mark J Musante <Mark.Musante@Sun.COM>
parents: 11449
diff changeset
  2522
{
69b45e632792 6698011 zfs incorrectly reports file systems as children when attempting a rename
Mark J Musante <Mark.Musante@Sun.COM>
parents: 11449
diff changeset
  2523
	size_t d1len = strlen(ds1);
69b45e632792 6698011 zfs incorrectly reports file systems as children when attempting a rename
Mark J Musante <Mark.Musante@Sun.COM>
parents: 11449
diff changeset
  2524
69b45e632792 6698011 zfs incorrectly reports file systems as children when attempting a rename
Mark J Musante <Mark.Musante@Sun.COM>
parents: 11449
diff changeset
  2525
	/* ds2 can't be a descendant if it's smaller */
69b45e632792 6698011 zfs incorrectly reports file systems as children when attempting a rename
Mark J Musante <Mark.Musante@Sun.COM>
parents: 11449
diff changeset
  2526
	if (strlen(ds2) < d1len)
69b45e632792 6698011 zfs incorrectly reports file systems as children when attempting a rename
Mark J Musante <Mark.Musante@Sun.COM>
parents: 11449
diff changeset
  2527
		return (B_FALSE);
69b45e632792 6698011 zfs incorrectly reports file systems as children when attempting a rename
Mark J Musante <Mark.Musante@Sun.COM>
parents: 11449
diff changeset
  2528
69b45e632792 6698011 zfs incorrectly reports file systems as children when attempting a rename
Mark J Musante <Mark.Musante@Sun.COM>
parents: 11449
diff changeset
  2529
	/* otherwise, compare strings and verify that there's a '/' char */
69b45e632792 6698011 zfs incorrectly reports file systems as children when attempting a rename
Mark J Musante <Mark.Musante@Sun.COM>
parents: 11449
diff changeset
  2530
	return (ds2[d1len] == '/' && (strncmp(ds1, ds2, d1len) == 0));
69b45e632792 6698011 zfs incorrectly reports file systems as children when attempting a rename
Mark J Musante <Mark.Musante@Sun.COM>
parents: 11449
diff changeset
  2531
}
69b45e632792 6698011 zfs incorrectly reports file systems as children when attempting a rename
Mark J Musante <Mark.Musante@Sun.COM>
parents: 11449
diff changeset
  2532
69b45e632792 6698011 zfs incorrectly reports file systems as children when attempting a rename
Mark J Musante <Mark.Musante@Sun.COM>
parents: 11449
diff changeset
  2533
/*
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2534
 * Given a complete name, return just the portion that refers to the parent.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2535
 * Can return NULL if this is a pool.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2536
 */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2537
static int
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2538
parent_name(const char *path, char *buf, size_t buflen)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2539
{
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2540
	char *loc;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2541
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2542
	if ((loc = strrchr(path, '/')) == NULL)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2543
		return (-1);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2544
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2545
	(void) strncpy(buf, path, MIN(buflen, loc - path));
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2546
	buf[loc - path] = '\0';
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2547
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2548
	return (0);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2549
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2550
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2551
/*
4490
abf035049f7f PSARC 2007/199 zfs {create,clone,rename} -p
vb160487
parents: 4451
diff changeset
  2552
 * 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
  2553
 * 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
  2554
 * 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
  2555
 * 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
  2556
 * '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
  2557
 * new datasets.
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2558
 */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2559
static int
4490
abf035049f7f PSARC 2007/199 zfs {create,clone,rename} -p
vb160487
parents: 4451
diff changeset
  2560
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
  2561
    boolean_t accept_ancestor, int *prefixlen)
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2562
{
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2563
	zfs_cmd_t zc = { 0 };
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2564
	char parent[ZFS_MAXNAMELEN];
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2565
	char *slash;
1356
e021b5e4aa0e 6377671 zfs mount -a shouldn't bother checking snapshots
eschrock
parents: 1294
diff changeset
  2566
	zfs_handle_t *zhp;
2082
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1793
diff changeset
  2567
	char errbuf[1024];
11497
69b45e632792 6698011 zfs incorrectly reports file systems as children when attempting a rename
Mark J Musante <Mark.Musante@Sun.COM>
parents: 11449
diff changeset
  2568
	uint64_t is_zoned;
2082
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1793
diff changeset
  2569
8269
03a7e9050cfd 6674216 "zfs share" doesn't work, but "zfs set sharenfs=on" does
Mark J Musante <Mark.Musante@Sun.COM>
parents: 8228
diff changeset
  2570
	(void) snprintf(errbuf, sizeof (errbuf),
03a7e9050cfd 6674216 "zfs share" doesn't work, but "zfs set sharenfs=on" does
Mark J Musante <Mark.Musante@Sun.COM>
parents: 8228
diff changeset
  2571
	    dgettext(TEXT_DOMAIN, "cannot create '%s'"), path);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2572
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2573
	/* get parent, and check to see if this is just a pool */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2574
	if (parent_name(path, parent, sizeof (parent)) != 0) {
2082
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1793
diff changeset
  2575
		zfs_error_aux(hdl, dgettext(TEXT_DOMAIN,
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1793
diff changeset
  2576
		    "missing dataset name"));
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1793
diff changeset
  2577
		return (zfs_error(hdl, EZFS_INVALIDNAME, errbuf));
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2578
	}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2579
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2580
	/* check to see if the pool exists */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2581
	if ((slash = strchr(parent, '/')) == NULL)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2582
		slash = parent + strlen(parent);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2583
	(void) strncpy(zc.zc_name, parent, slash - parent);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2584
	zc.zc_name[slash - parent] = '\0';
2082
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1793
diff changeset
  2585
	if (ioctl(hdl->libzfs_fd, ZFS_IOC_OBJSET_STATS, &zc) != 0 &&
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2586
	    errno == ENOENT) {
2082
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1793
diff changeset
  2587
		zfs_error_aux(hdl, dgettext(TEXT_DOMAIN,
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1793
diff changeset
  2588
		    "no such pool '%s'"), zc.zc_name);
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1793
diff changeset
  2589
		return (zfs_error(hdl, EZFS_NOENT, errbuf));
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2590
	}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2591
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2592
	/* check to see if the parent dataset exists */
4490
abf035049f7f PSARC 2007/199 zfs {create,clone,rename} -p
vb160487
parents: 4451
diff changeset
  2593
	while ((zhp = make_dataset_handle(hdl, parent)) == NULL) {
abf035049f7f PSARC 2007/199 zfs {create,clone,rename} -p
vb160487
parents: 4451
diff changeset
  2594
		if (errno == ENOENT && accept_ancestor) {
abf035049f7f PSARC 2007/199 zfs {create,clone,rename} -p
vb160487
parents: 4451
diff changeset
  2595
			/*
abf035049f7f PSARC 2007/199 zfs {create,clone,rename} -p
vb160487
parents: 4451
diff changeset
  2596
			 * 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
  2597
			 */
abf035049f7f PSARC 2007/199 zfs {create,clone,rename} -p
vb160487
parents: 4451
diff changeset
  2598
			if (parent_name(parent, parent, sizeof (parent)) != 0) {
abf035049f7f PSARC 2007/199 zfs {create,clone,rename} -p
vb160487
parents: 4451
diff changeset
  2599
				zfs_error_aux(hdl, dgettext(TEXT_DOMAIN,
abf035049f7f PSARC 2007/199 zfs {create,clone,rename} -p
vb160487
parents: 4451
diff changeset
  2600
				    "no such pool '%s'"), zc.zc_name);
abf035049f7f PSARC 2007/199 zfs {create,clone,rename} -p
vb160487
parents: 4451
diff changeset
  2601
				return (zfs_error(hdl, EZFS_NOENT, errbuf));
abf035049f7f PSARC 2007/199 zfs {create,clone,rename} -p
vb160487
parents: 4451
diff changeset
  2602
			}
abf035049f7f PSARC 2007/199 zfs {create,clone,rename} -p
vb160487
parents: 4451
diff changeset
  2603
		} else if (errno == ENOENT) {
2082
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1793
diff changeset
  2604
			zfs_error_aux(hdl, dgettext(TEXT_DOMAIN,
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1793
diff changeset
  2605
			    "parent does not exist"));
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1793
diff changeset
  2606
			return (zfs_error(hdl, EZFS_NOENT, errbuf));
4490
abf035049f7f PSARC 2007/199 zfs {create,clone,rename} -p
vb160487
parents: 4451
diff changeset
  2607
		} else
2082
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1793
diff changeset
  2608
			return (zfs_standard_error(hdl, errno, errbuf));
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2609
	}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2610
11497
69b45e632792 6698011 zfs incorrectly reports file systems as children when attempting a rename
Mark J Musante <Mark.Musante@Sun.COM>
parents: 11449
diff changeset
  2611
	is_zoned = zfs_prop_get_int(zhp, ZFS_PROP_ZONED);
69b45e632792 6698011 zfs incorrectly reports file systems as children when attempting a rename
Mark J Musante <Mark.Musante@Sun.COM>
parents: 11449
diff changeset
  2612
	if (zoned != NULL)
69b45e632792 6698011 zfs incorrectly reports file systems as children when attempting a rename
Mark J Musante <Mark.Musante@Sun.COM>
parents: 11449
diff changeset
  2613
		*zoned = is_zoned;
69b45e632792 6698011 zfs incorrectly reports file systems as children when attempting a rename
Mark J Musante <Mark.Musante@Sun.COM>
parents: 11449
diff changeset
  2614
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2615
	/* we are in a non-global zone, but parent is in the global zone */
11497
69b45e632792 6698011 zfs incorrectly reports file systems as children when attempting a rename
Mark J Musante <Mark.Musante@Sun.COM>
parents: 11449
diff changeset
  2616
	if (getzoneid() != GLOBAL_ZONEID && !is_zoned) {
2082
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1793
diff changeset
  2617
		(void) zfs_standard_error(hdl, EPERM, errbuf);
1356
e021b5e4aa0e 6377671 zfs mount -a shouldn't bother checking snapshots
eschrock
parents: 1294
diff changeset
  2618
		zfs_close(zhp);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2619
		return (-1);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2620
	}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2621
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2622
	/* make sure parent is a filesystem */
1356
e021b5e4aa0e 6377671 zfs mount -a shouldn't bother checking snapshots
eschrock
parents: 1294
diff changeset
  2623
	if (zfs_get_type(zhp) != ZFS_TYPE_FILESYSTEM) {
2082
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1793
diff changeset
  2624
		zfs_error_aux(hdl, dgettext(TEXT_DOMAIN,
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1793
diff changeset
  2625
		    "parent is not a filesystem"));
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1793
diff changeset
  2626
		(void) zfs_error(hdl, EZFS_BADTYPE, errbuf);
1356
e021b5e4aa0e 6377671 zfs mount -a shouldn't bother checking snapshots
eschrock
parents: 1294
diff changeset
  2627
		zfs_close(zhp);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2628
		return (-1);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2629
	}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2630
1356
e021b5e4aa0e 6377671 zfs mount -a shouldn't bother checking snapshots
eschrock
parents: 1294
diff changeset
  2631
	zfs_close(zhp);
4490
abf035049f7f PSARC 2007/199 zfs {create,clone,rename} -p
vb160487
parents: 4451
diff changeset
  2632
	if (prefixlen != NULL)
abf035049f7f PSARC 2007/199 zfs {create,clone,rename} -p
vb160487
parents: 4451
diff changeset
  2633
		*prefixlen = strlen(parent);
abf035049f7f PSARC 2007/199 zfs {create,clone,rename} -p
vb160487
parents: 4451
diff changeset
  2634
	return (0);
abf035049f7f PSARC 2007/199 zfs {create,clone,rename} -p
vb160487
parents: 4451
diff changeset
  2635
}
abf035049f7f PSARC 2007/199 zfs {create,clone,rename} -p
vb160487
parents: 4451
diff changeset
  2636
abf035049f7f PSARC 2007/199 zfs {create,clone,rename} -p
vb160487
parents: 4451
diff changeset
  2637
/*
abf035049f7f PSARC 2007/199 zfs {create,clone,rename} -p
vb160487
parents: 4451
diff changeset
  2638
 * Finds whether the dataset of the given type(s) exists.
abf035049f7f PSARC 2007/199 zfs {create,clone,rename} -p
vb160487
parents: 4451
diff changeset
  2639
 */
abf035049f7f PSARC 2007/199 zfs {create,clone,rename} -p
vb160487
parents: 4451
diff changeset
  2640
boolean_t
abf035049f7f PSARC 2007/199 zfs {create,clone,rename} -p
vb160487
parents: 4451
diff changeset
  2641
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
  2642
{
abf035049f7f PSARC 2007/199 zfs {create,clone,rename} -p
vb160487
parents: 4451
diff changeset
  2643
	zfs_handle_t *zhp;
abf035049f7f PSARC 2007/199 zfs {create,clone,rename} -p
vb160487
parents: 4451
diff changeset
  2644
5326
6752aa2bd5bc 6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents: 5147
diff changeset
  2645
	if (!zfs_validate_name(hdl, path, types, B_FALSE))
4490
abf035049f7f PSARC 2007/199 zfs {create,clone,rename} -p
vb160487
parents: 4451
diff changeset
  2646
		return (B_FALSE);
abf035049f7f PSARC 2007/199 zfs {create,clone,rename} -p
vb160487
parents: 4451
diff changeset
  2647
abf035049f7f PSARC 2007/199 zfs {create,clone,rename} -p
vb160487
parents: 4451
diff changeset
  2648
	/*
abf035049f7f PSARC 2007/199 zfs {create,clone,rename} -p
vb160487
parents: 4451
diff changeset
  2649
	 * 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
  2650
	 */
abf035049f7f PSARC 2007/199 zfs {create,clone,rename} -p
vb160487
parents: 4451
diff changeset
  2651
	if ((zhp = make_dataset_handle(hdl, path)) != NULL) {
abf035049f7f PSARC 2007/199 zfs {create,clone,rename} -p
vb160487
parents: 4451
diff changeset
  2652
		int ds_type = zhp->zfs_type;
abf035049f7f PSARC 2007/199 zfs {create,clone,rename} -p
vb160487
parents: 4451
diff changeset
  2653
abf035049f7f PSARC 2007/199 zfs {create,clone,rename} -p
vb160487
parents: 4451
diff changeset
  2654
		zfs_close(zhp);
abf035049f7f PSARC 2007/199 zfs {create,clone,rename} -p
vb160487
parents: 4451
diff changeset
  2655
		if (types & ds_type)
abf035049f7f PSARC 2007/199 zfs {create,clone,rename} -p
vb160487
parents: 4451
diff changeset
  2656
			return (B_TRUE);
abf035049f7f PSARC 2007/199 zfs {create,clone,rename} -p
vb160487
parents: 4451
diff changeset
  2657
	}
abf035049f7f PSARC 2007/199 zfs {create,clone,rename} -p
vb160487
parents: 4451
diff changeset
  2658
	return (B_FALSE);
abf035049f7f PSARC 2007/199 zfs {create,clone,rename} -p
vb160487
parents: 4451
diff changeset
  2659
}
abf035049f7f PSARC 2007/199 zfs {create,clone,rename} -p
vb160487
parents: 4451
diff changeset
  2660
abf035049f7f PSARC 2007/199 zfs {create,clone,rename} -p
vb160487
parents: 4451
diff changeset
  2661
/*
5367
c40abbe796be PSARC/2007/574 zfs send -R
ahrens
parents: 5331
diff changeset
  2662
 * Given a path to 'target', create all the ancestors between
c40abbe796be PSARC/2007/574 zfs send -R
ahrens
parents: 5331
diff changeset
  2663
 * the prefixlen portion of the path, and the target itself.
c40abbe796be PSARC/2007/574 zfs send -R
ahrens
parents: 5331
diff changeset
  2664
 * Fail if the initial prefixlen-ancestor does not already exist.
c40abbe796be PSARC/2007/574 zfs send -R
ahrens
parents: 5331
diff changeset
  2665
 */
c40abbe796be PSARC/2007/574 zfs send -R
ahrens
parents: 5331
diff changeset
  2666
int
c40abbe796be PSARC/2007/574 zfs send -R
ahrens
parents: 5331
diff changeset
  2667
create_parents(libzfs_handle_t *hdl, char *target, int prefixlen)
c40abbe796be PSARC/2007/574 zfs send -R
ahrens
parents: 5331
diff changeset
  2668
{
c40abbe796be PSARC/2007/574 zfs send -R
ahrens
parents: 5331
diff changeset
  2669
	zfs_handle_t *h;
c40abbe796be PSARC/2007/574 zfs send -R
ahrens
parents: 5331
diff changeset
  2670
	char *cp;
c40abbe796be PSARC/2007/574 zfs send -R
ahrens
parents: 5331
diff changeset
  2671
	const char *opname;
c40abbe796be PSARC/2007/574 zfs send -R
ahrens
parents: 5331
diff changeset
  2672
c40abbe796be PSARC/2007/574 zfs send -R
ahrens
parents: 5331
diff changeset
  2673
	/* make sure prefix exists */
c40abbe796be PSARC/2007/574 zfs send -R
ahrens
parents: 5331
diff changeset
  2674
	cp = target + prefixlen;
c40abbe796be PSARC/2007/574 zfs send -R
ahrens
parents: 5331
diff changeset
  2675
	if (*cp != '/') {
c40abbe796be PSARC/2007/574 zfs send -R
ahrens
parents: 5331
diff changeset
  2676
		assert(strchr(cp, '/') == NULL);
c40abbe796be PSARC/2007/574 zfs send -R
ahrens
parents: 5331
diff changeset
  2677
		h = zfs_open(hdl, target, ZFS_TYPE_FILESYSTEM);
c40abbe796be PSARC/2007/574 zfs send -R
ahrens
parents: 5331
diff changeset
  2678
	} else {
c40abbe796be PSARC/2007/574 zfs send -R
ahrens
parents: 5331
diff changeset
  2679
		*cp = '\0';
c40abbe796be PSARC/2007/574 zfs send -R
ahrens
parents: 5331
diff changeset
  2680
		h = zfs_open(hdl, target, ZFS_TYPE_FILESYSTEM);
c40abbe796be PSARC/2007/574 zfs send -R
ahrens
parents: 5331
diff changeset
  2681
		*cp = '/';
c40abbe796be PSARC/2007/574 zfs send -R
ahrens
parents: 5331
diff changeset
  2682
	}
c40abbe796be PSARC/2007/574 zfs send -R
ahrens
parents: 5331
diff changeset
  2683
	if (h == NULL)
c40abbe796be PSARC/2007/574 zfs send -R
ahrens
parents: 5331
diff changeset
  2684
		return (-1);
c40abbe796be PSARC/2007/574 zfs send -R
ahrens
parents: 5331
diff changeset
  2685
	zfs_close(h);
c40abbe796be PSARC/2007/574 zfs send -R
ahrens
parents: 5331
diff changeset
  2686
c40abbe796be PSARC/2007/574 zfs send -R
ahrens
parents: 5331
diff changeset
  2687
	/*
c40abbe796be PSARC/2007/574 zfs send -R
ahrens
parents: 5331
diff changeset
  2688
	 * Attempt to create, mount, and share any ancestor filesystems,
c40abbe796be PSARC/2007/574 zfs send -R
ahrens
parents: 5331
diff changeset
  2689
	 * up to the prefixlen-long one.
c40abbe796be PSARC/2007/574 zfs send -R
ahrens
parents: 5331
diff changeset
  2690
	 */
c40abbe796be PSARC/2007/574 zfs send -R
ahrens
parents: 5331
diff changeset
  2691
	for (cp = target + prefixlen + 1;
c40abbe796be PSARC/2007/574 zfs send -R
ahrens
parents: 5331
diff changeset
  2692
	    cp = strchr(cp, '/'); *cp = '/', cp++) {
c40abbe796be PSARC/2007/574 zfs send -R
ahrens
parents: 5331
diff changeset
  2693
		char *logstr;
c40abbe796be PSARC/2007/574 zfs send -R
ahrens
parents: 5331
diff changeset
  2694
c40abbe796be PSARC/2007/574 zfs send -R
ahrens
parents: 5331
diff changeset
  2695
		*cp = '\0';
c40abbe796be PSARC/2007/574 zfs send -R
ahrens
parents: 5331
diff changeset
  2696
c40abbe796be PSARC/2007/574 zfs send -R
ahrens
parents: 5331
diff changeset
  2697
		h = make_dataset_handle(hdl, target);
c40abbe796be PSARC/2007/574 zfs send -R
ahrens
parents: 5331
diff changeset
  2698
		if (h) {
c40abbe796be PSARC/2007/574 zfs send -R
ahrens
parents: 5331
diff changeset
  2699
			/* it already exists, nothing to do here */
c40abbe796be PSARC/2007/574 zfs send -R
ahrens
parents: 5331
diff changeset
  2700
			zfs_close(h);
c40abbe796be PSARC/2007/574 zfs send -R
ahrens
parents: 5331
diff changeset
  2701
			continue;
c40abbe796be PSARC/2007/574 zfs send -R
ahrens
parents: 5331
diff changeset
  2702
		}
c40abbe796be PSARC/2007/574 zfs send -R
ahrens
parents: 5331
diff changeset
  2703
c40abbe796be PSARC/2007/574 zfs send -R
ahrens
parents: 5331
diff changeset
  2704
		logstr = hdl->libzfs_log_str;
c40abbe796be PSARC/2007/574 zfs send -R
ahrens
parents: 5331
diff changeset
  2705
		hdl->libzfs_log_str = NULL;
c40abbe796be PSARC/2007/574 zfs send -R
ahrens
parents: 5331
diff changeset
  2706
		if (zfs_create(hdl, target, ZFS_TYPE_FILESYSTEM,
c40abbe796be PSARC/2007/574 zfs send -R
ahrens
parents: 5331
diff changeset
  2707
		    NULL) != 0) {
c40abbe796be PSARC/2007/574 zfs send -R
ahrens
parents: 5331
diff changeset
  2708
			hdl->libzfs_log_str = logstr;
c40abbe796be PSARC/2007/574 zfs send -R
ahrens
parents: 5331
diff changeset
  2709
			opname = dgettext(TEXT_DOMAIN, "create");
c40abbe796be PSARC/2007/574 zfs send -R
ahrens
parents: 5331
diff changeset
  2710
			goto ancestorerr;
c40abbe796be PSARC/2007/574 zfs send -R
ahrens
parents: 5331
diff changeset
  2711
		}
c40abbe796be PSARC/2007/574 zfs send -R
ahrens
parents: 5331
diff changeset
  2712
c40abbe796be PSARC/2007/574 zfs send -R
ahrens
parents: 5331
diff changeset
  2713
		hdl->libzfs_log_str = logstr;
c40abbe796be PSARC/2007/574 zfs send -R
ahrens
parents: 5331
diff changeset
  2714
		h = zfs_open(hdl, target, ZFS_TYPE_FILESYSTEM);
c40abbe796be PSARC/2007/574 zfs send -R
ahrens
parents: 5331
diff changeset
  2715
		if (h == NULL) {
c40abbe796be PSARC/2007/574 zfs send -R
ahrens
parents: 5331
diff changeset
  2716
			opname = dgettext(TEXT_DOMAIN, "open");
c40abbe796be PSARC/2007/574 zfs send -R
ahrens
parents: 5331
diff changeset
  2717
			goto ancestorerr;
c40abbe796be PSARC/2007/574 zfs send -R
ahrens
parents: 5331
diff changeset
  2718
		}
c40abbe796be PSARC/2007/574 zfs send -R
ahrens
parents: 5331
diff changeset
  2719
c40abbe796be PSARC/2007/574 zfs send -R
ahrens
parents: 5331
diff changeset
  2720
		if (zfs_mount(h, NULL, 0) != 0) {
c40abbe796be PSARC/2007/574 zfs send -R
ahrens
parents: 5331
diff changeset
  2721
			opname = dgettext(TEXT_DOMAIN, "mount");
c40abbe796be PSARC/2007/574 zfs send -R
ahrens
parents: 5331
diff changeset
  2722
			goto ancestorerr;
c40abbe796be PSARC/2007/574 zfs send -R
ahrens
parents: 5331
diff changeset
  2723
		}
c40abbe796be PSARC/2007/574 zfs send -R
ahrens
parents: 5331
diff changeset
  2724
c40abbe796be PSARC/2007/574 zfs send -R
ahrens
parents: 5331
diff changeset
  2725
		if (zfs_share(h) != 0) {
c40abbe796be PSARC/2007/574 zfs send -R
ahrens
parents: 5331
diff changeset
  2726
			opname = dgettext(TEXT_DOMAIN, "share");
c40abbe796be PSARC/2007/574 zfs send -R
ahrens
parents: 5331
diff changeset
  2727
			goto ancestorerr;
c40abbe796be PSARC/2007/574 zfs send -R
ahrens
parents: 5331
diff changeset
  2728
		}
c40abbe796be PSARC/2007/574 zfs send -R
ahrens
parents: 5331
diff changeset
  2729
c40abbe796be PSARC/2007/574 zfs send -R
ahrens
parents: 5331
diff changeset
  2730
		zfs_close(h);
c40abbe796be PSARC/2007/574 zfs send -R
ahrens
parents: 5331
diff changeset
  2731
	}
c40abbe796be PSARC/2007/574 zfs send -R
ahrens
parents: 5331
diff changeset
  2732
c40abbe796be PSARC/2007/574 zfs send -R
ahrens
parents: 5331
diff changeset
  2733
	return (0);
c40abbe796be PSARC/2007/574 zfs send -R
ahrens
parents: 5331
diff changeset
  2734
c40abbe796be PSARC/2007/574 zfs send -R
ahrens
parents: 5331
diff changeset
  2735
ancestorerr:
c40abbe796be PSARC/2007/574 zfs send -R
ahrens
parents: 5331
diff changeset
  2736
	zfs_error_aux(hdl, dgettext(TEXT_DOMAIN,
c40abbe796be PSARC/2007/574 zfs send -R
ahrens
parents: 5331
diff changeset
  2737
	    "failed to %s ancestor '%s'"), opname, target);
c40abbe796be PSARC/2007/574 zfs send -R
ahrens
parents: 5331
diff changeset
  2738
	return (-1);
c40abbe796be PSARC/2007/574 zfs send -R
ahrens
parents: 5331
diff changeset
  2739
}
c40abbe796be PSARC/2007/574 zfs send -R
ahrens
parents: 5331
diff changeset
  2740
c40abbe796be PSARC/2007/574 zfs send -R
ahrens
parents: 5331
diff changeset
  2741
/*
4490
abf035049f7f PSARC 2007/199 zfs {create,clone,rename} -p
vb160487
parents: 4451
diff changeset
  2742
 * Creates non-existing ancestors of the given path.
abf035049f7f PSARC 2007/199 zfs {create,clone,rename} -p
vb160487
parents: 4451
diff changeset
  2743
 */
abf035049f7f PSARC 2007/199 zfs {create,clone,rename} -p
vb160487
parents: 4451
diff changeset
  2744
int
abf035049f7f PSARC 2007/199 zfs {create,clone,rename} -p
vb160487
parents: 4451
diff changeset
  2745
zfs_create_ancestors(libzfs_handle_t *hdl, const char *path)
abf035049f7f PSARC 2007/199 zfs {create,clone,rename} -p
vb160487
parents: 4451
diff changeset
  2746
{
abf035049f7f PSARC 2007/199 zfs {create,clone,rename} -p
vb160487
parents: 4451
diff changeset
  2747
	int prefix;
abf035049f7f PSARC 2007/199 zfs {create,clone,rename} -p
vb160487
parents: 4451
diff changeset
  2748
	char *path_copy;
abf035049f7f PSARC 2007/199 zfs {create,clone,rename} -p
vb160487
parents: 4451
diff changeset
  2749
	int rc;
abf035049f7f PSARC 2007/199 zfs {create,clone,rename} -p
vb160487
parents: 4451
diff changeset
  2750
11497
69b45e632792 6698011 zfs incorrectly reports file systems as children when attempting a rename
Mark J Musante <Mark.Musante@Sun.COM>
parents: 11449
diff changeset
  2751
	if (check_parents(hdl, path, NULL, B_TRUE, &prefix) != 0)
4490
abf035049f7f PSARC 2007/199 zfs {create,clone,rename} -p
vb160487
parents: 4451
diff changeset
  2752
		return (-1);
abf035049f7f PSARC 2007/199 zfs {create,clone,rename} -p
vb160487
parents: 4451
diff changeset
  2753
abf035049f7f PSARC 2007/199 zfs {create,clone,rename} -p
vb160487
parents: 4451
diff changeset
  2754
	if ((path_copy = strdup(path)) != NULL) {
abf035049f7f PSARC 2007/199 zfs {create,clone,rename} -p
vb160487
parents: 4451
diff changeset
  2755
		rc = create_parents(hdl, path_copy, prefix);
abf035049f7f PSARC 2007/199 zfs {create,clone,rename} -p
vb160487
parents: 4451
diff changeset
  2756
		free(path_copy);
abf035049f7f PSARC 2007/199 zfs {create,clone,rename} -p
vb160487
parents: 4451
diff changeset
  2757
	}
abf035049f7f PSARC 2007/199 zfs {create,clone,rename} -p
vb160487
parents: 4451
diff changeset
  2758
	if (path_copy == NULL || rc != 0)
abf035049f7f PSARC 2007/199 zfs {create,clone,rename} -p
vb160487
parents: 4451
diff changeset
  2759
		return (-1);
abf035049f7f PSARC 2007/199 zfs {create,clone,rename} -p
vb160487
parents: 4451
diff changeset
  2760
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2761
	return (0);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2762
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2763
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2764
/*
2676
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  2765
 * Create a new filesystem or volume.
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2766
 */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2767
int
2082
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1793
diff changeset
  2768
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
  2769
    nvlist_t *props)
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2770
{
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2771
	zfs_cmd_t zc = { 0 };
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2772
	int ret;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2773
	uint64_t size = 0;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2774
	uint64_t blocksize = zfs_prop_default_numeric(ZFS_PROP_VOLBLOCKSIZE);
2082
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1793
diff changeset
  2775
	char errbuf[1024];
2676
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  2776
	uint64_t zoned;
2082
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1793
diff changeset
  2777
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1793
diff changeset
  2778
	(void) snprintf(errbuf, sizeof (errbuf), dgettext(TEXT_DOMAIN,
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1793
diff changeset
  2779
	    "cannot create '%s'"), path);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2780
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2781
	/* 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
  2782
	if (!zfs_validate_name(hdl, path, type, B_TRUE))
2082
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1793
diff changeset
  2783
		return (zfs_error(hdl, EZFS_INVALIDNAME, errbuf));
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2784
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2785
	/* validate parents exist */
4490
abf035049f7f PSARC 2007/199 zfs {create,clone,rename} -p
vb160487
parents: 4451
diff changeset
  2786
	if (check_parents(hdl, path, &zoned, B_FALSE, NULL) != 0)
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2787
		return (-1);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2788
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2789
	/*
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2790
	 * The failure modes when creating a dataset of a different type over
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2791
	 * one that already exists is a little strange.  In particular, if you
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2792
	 * try to create a dataset on top of an existing dataset, the ioctl()
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2793
	 * will return ENOENT, not EEXIST.  To prevent this from happening, we
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2794
	 * first try to see if the dataset exists.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2795
	 */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2796
	(void) strlcpy(zc.zc_name, path, sizeof (zc.zc_name));
5094
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4861
diff changeset
  2797
	if (zfs_dataset_exists(hdl, zc.zc_name, ZFS_TYPE_DATASET)) {
2082
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1793
diff changeset
  2798
		zfs_error_aux(hdl, dgettext(TEXT_DOMAIN,
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1793
diff changeset
  2799
		    "dataset already exists"));
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1793
diff changeset
  2800
		return (zfs_error(hdl, EZFS_EXISTS, errbuf));
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2801
	}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2802
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2803
	if (type == ZFS_TYPE_VOLUME)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2804
		zc.zc_objset_type = DMU_OST_ZVOL;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2805
	else
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2806
		zc.zc_objset_type = DMU_OST_ZFS;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2807
7184
9508660f9c27 PSARC 2008/223 Pool root file system properties via zpool(1M)
timh
parents: 7042
diff changeset
  2808
	if (props && (props = zfs_valid_proplist(hdl, type, props,
3912
f6891a60bd72 PSARC 2007/083 ZFS bootable datasets
lling
parents: 3886
diff changeset
  2809
	    zoned, NULL, errbuf)) == 0)
2676
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  2810
		return (-1);
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  2811
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2812
	if (type == ZFS_TYPE_VOLUME) {
1133
335d069294d1 6357470 vdev_raidz.c has unused RAIDZ_SINGLE define, code
eschrock
parents: 1003
diff changeset
  2813
		/*
335d069294d1 6357470 vdev_raidz.c has unused RAIDZ_SINGLE define, code
eschrock
parents: 1003
diff changeset
  2814
		 * 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
  2815
		 * 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
  2816
		 * 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
  2817
		 * 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
  2818
		 * zero.
335d069294d1 6357470 vdev_raidz.c has unused RAIDZ_SINGLE define, code
eschrock
parents: 1003
diff changeset
  2819
		 */
2676
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  2820
		if (props == NULL || nvlist_lookup_uint64(props,
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  2821
		    zfs_prop_to_name(ZFS_PROP_VOLSIZE), &size) != 0) {
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  2822
			nvlist_free(props);
2082
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1793
diff changeset
  2823
			zfs_error_aux(hdl, dgettext(TEXT_DOMAIN,
2676
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  2824
			    "missing volume size"));
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  2825
			return (zfs_error(hdl, EZFS_BADPROP, errbuf));
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2826
		}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2827
2676
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  2828
		if ((ret = nvlist_lookup_uint64(props,
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  2829
		    zfs_prop_to_name(ZFS_PROP_VOLBLOCKSIZE),
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  2830
		    &blocksize)) != 0) {
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  2831
			if (ret == ENOENT) {
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  2832
				blocksize = zfs_prop_default_numeric(
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  2833
				    ZFS_PROP_VOLBLOCKSIZE);
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  2834
			} else {
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  2835
				nvlist_free(props);
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  2836
				zfs_error_aux(hdl, dgettext(TEXT_DOMAIN,
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  2837
				    "missing volume block size"));
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  2838
				return (zfs_error(hdl, EZFS_BADPROP, errbuf));
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  2839
			}
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  2840
		}
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  2841
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  2842
		if (size == 0) {
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  2843
			nvlist_free(props);
2082
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1793
diff changeset
  2844
			zfs_error_aux(hdl, dgettext(TEXT_DOMAIN,
2676
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  2845
			    "volume size cannot be zero"));
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  2846
			return (zfs_error(hdl, EZFS_BADPROP, errbuf));
1133
335d069294d1 6357470 vdev_raidz.c has unused RAIDZ_SINGLE define, code
eschrock
parents: 1003
diff changeset
  2847
		}
335d069294d1 6357470 vdev_raidz.c has unused RAIDZ_SINGLE define, code
eschrock
parents: 1003
diff changeset
  2848
335d069294d1 6357470 vdev_raidz.c has unused RAIDZ_SINGLE define, code
eschrock
parents: 1003
diff changeset
  2849
		if (size % blocksize != 0) {
2676
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  2850
			nvlist_free(props);
2082
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1793
diff changeset
  2851
			zfs_error_aux(hdl, dgettext(TEXT_DOMAIN,
2676
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  2852
			    "volume size must be a multiple of volume block "
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  2853
			    "size"));
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  2854
			return (zfs_error(hdl, EZFS_BADPROP, errbuf));
1133
335d069294d1 6357470 vdev_raidz.c has unused RAIDZ_SINGLE define, code
eschrock
parents: 1003
diff changeset
  2855
		}
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2856
	}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2857
5094
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4861
diff changeset
  2858
	if (props && zcmd_write_src_nvlist(hdl, &zc, props) != 0)
2676
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  2859
		return (-1);
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  2860
	nvlist_free(props);
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  2861
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2862
	/* create the dataset */
4543
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  2863
	ret = zfs_ioctl(hdl, ZFS_IOC_CREATE, &zc);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2864
2676
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  2865
	zcmd_free_nvlists(&zc);
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  2866
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2867
	/* check for failure */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2868
	if (ret != 0) {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2869
		char parent[ZFS_MAXNAMELEN];
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2870
		(void) parent_name(path, parent, sizeof (parent));
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2871
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2872
		switch (errno) {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2873
		case ENOENT:
2082
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1793
diff changeset
  2874
			zfs_error_aux(hdl, dgettext(TEXT_DOMAIN,
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1793
diff changeset
  2875
			    "no such parent '%s'"), parent);
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1793
diff changeset
  2876
			return (zfs_error(hdl, EZFS_NOENT, errbuf));
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2877
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2878
		case EINVAL:
2082
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1793
diff changeset
  2879
			zfs_error_aux(hdl, dgettext(TEXT_DOMAIN,
3413
f4cbe0204ab7 6471255 Some ZFS error messages contain spelling errors
mmusante
parents: 3377
diff changeset
  2880
			    "parent '%s' is not a filesystem"), parent);
2082
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1793
diff changeset
  2881
			return (zfs_error(hdl, EZFS_BADTYPE, errbuf));
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2882
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2883
		case EDOM:
2082
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1793
diff changeset
  2884
			zfs_error_aux(hdl, dgettext(TEXT_DOMAIN,
2676
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  2885
			    "volume block size must be power of 2 from "
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  2886
			    "%u to %uk"),
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2887
			    (uint_t)SPA_MINBLOCKSIZE,
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2888
			    (uint_t)SPA_MAXBLOCKSIZE >> 10);
2082
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1793
diff changeset
  2889
2676
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  2890
			return (zfs_error(hdl, EZFS_BADPROP, errbuf));
2082
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1793
diff changeset
  2891
4603
c7840c367d00 6494569 zfs recv -d pool/<doesn't exist> core dumps for top-level filesystem backups
ahrens
parents: 4597
diff changeset
  2892
		case ENOTSUP:
c7840c367d00 6494569 zfs recv -d pool/<doesn't exist> core dumps for top-level filesystem backups
ahrens
parents: 4597
diff changeset
  2893
			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
  2894
			    "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
  2895
			    "property or value"));
c7840c367d00 6494569 zfs recv -d pool/<doesn't exist> core dumps for top-level filesystem backups
ahrens
parents: 4597
diff changeset
  2896
			return (zfs_error(hdl, EZFS_BADVERSION, errbuf));
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2897
#ifdef _ILP32
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2898
		case EOVERFLOW:
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2899
			/*
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2900
			 * This platform can't address a volume this big.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2901
			 */
2082
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1793
diff changeset
  2902
			if (type == ZFS_TYPE_VOLUME)
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1793
diff changeset
  2903
				return (zfs_error(hdl, EZFS_VOLTOOBIG,
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1793
diff changeset
  2904
				    errbuf));
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2905
#endif
2082
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1793
diff changeset
  2906
			/* FALLTHROUGH */
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2907
		default:
2082
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1793
diff changeset
  2908
			return (zfs_standard_error(hdl, errno, errbuf));
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2909
		}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2910
	}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2911
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2912
	return (0);
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
/*
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2916
 * Destroys the given dataset.  The caller must make sure that the filesystem
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2917
 * isn't mounted, and that there are no active dependents.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2918
 */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2919
int
10242
c40d075fbca6 PSARC/2009/297 zfs snapshot holds
Chris Kirby <chris.kirby@sun.com>
parents: 10204
diff changeset
  2920
zfs_destroy(zfs_handle_t *zhp, boolean_t defer)
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2921
{
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2922
	zfs_cmd_t zc = { 0 };
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2923
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2924
	(void) strlcpy(zc.zc_name, zhp->zfs_name, sizeof (zc.zc_name));
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2925
2676
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  2926
	if (ZFS_IS_VOLUME(zhp)) {
3126
4f4fb617fdd0 PSARC 2006/622 iSCSI/ZFS Integration
ahl
parents: 2885
diff changeset
  2927
		/*
4543
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  2928
		 * If user doesn't have permissions to unshare volume, then
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  2929
		 * abort the request.  This would only happen for a
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  2930
		 * non-privileged user.
3126
4f4fb617fdd0 PSARC 2006/622 iSCSI/ZFS Integration
ahl
parents: 2885
diff changeset
  2931
		 */
4543
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  2932
		if (zfs_unshare_iscsi(zhp) != 0) {
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  2933
			return (-1);
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  2934
		}
3126
4f4fb617fdd0 PSARC 2006/622 iSCSI/ZFS Integration
ahl
parents: 2885
diff changeset
  2935
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2936
		zc.zc_objset_type = DMU_OST_ZVOL;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2937
	} else {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2938
		zc.zc_objset_type = DMU_OST_ZFS;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2939
	}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2940
10242
c40d075fbca6 PSARC/2009/297 zfs snapshot holds
Chris Kirby <chris.kirby@sun.com>
parents: 10204
diff changeset
  2941
	zc.zc_defer_destroy = defer;
4543
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  2942
	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
  2943
		return (zfs_standard_error_fmt(zhp->zfs_hdl, errno,
2082
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1793
diff changeset
  2944
		    dgettext(TEXT_DOMAIN, "cannot destroy '%s'"),
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1793
diff changeset
  2945
		    zhp->zfs_name));
2199
712a788c2dfd PSARC 2006/388 snapshot -r
ahrens
parents: 2169
diff changeset
  2946
	}
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2947
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2948
	remove_mountpoint(zhp);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2949
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2950
	return (0);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2951
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2952
2199
712a788c2dfd PSARC 2006/388 snapshot -r
ahrens
parents: 2169
diff changeset
  2953
struct destroydata {
712a788c2dfd PSARC 2006/388 snapshot -r
ahrens
parents: 2169
diff changeset
  2954
	char *snapname;
712a788c2dfd PSARC 2006/388 snapshot -r
ahrens
parents: 2169
diff changeset
  2955
	boolean_t gotone;
3265
967e0fca6143 6463140 zfs recv with a snapshot name that has 2 @@ in a row succeeds
ahrens
parents: 3237
diff changeset
  2956
	boolean_t closezhp;
2199
712a788c2dfd PSARC 2006/388 snapshot -r
ahrens
parents: 2169
diff changeset
  2957
};
712a788c2dfd PSARC 2006/388 snapshot -r
ahrens
parents: 2169
diff changeset
  2958
712a788c2dfd PSARC 2006/388 snapshot -r
ahrens
parents: 2169
diff changeset
  2959
static int
10588
dc03f981ea18 6438937 if 'zfs destroy' fails, it can leave a zvol device link missing
Eric Taylor <Eric.Taylor@Sun.COM>
parents: 10342
diff changeset
  2960
zfs_check_snap_cb(zfs_handle_t *zhp, void *arg)
2199
712a788c2dfd PSARC 2006/388 snapshot -r
ahrens
parents: 2169
diff changeset
  2961
{
712a788c2dfd PSARC 2006/388 snapshot -r
ahrens
parents: 2169
diff changeset
  2962
	struct destroydata *dd = arg;
712a788c2dfd PSARC 2006/388 snapshot -r
ahrens
parents: 2169
diff changeset
  2963
	zfs_handle_t *szhp;
712a788c2dfd PSARC 2006/388 snapshot -r
ahrens
parents: 2169
diff changeset
  2964
	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
  2965
	boolean_t closezhp = dd->closezhp;
10588
dc03f981ea18 6438937 if 'zfs destroy' fails, it can leave a zvol device link missing
Eric Taylor <Eric.Taylor@Sun.COM>
parents: 10342
diff changeset
  2966
	int rv = 0;
2199
712a788c2dfd PSARC 2006/388 snapshot -r
ahrens
parents: 2169
diff changeset
  2967
2676
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  2968
	(void) strlcpy(name, zhp->zfs_name, sizeof (name));
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  2969
	(void) strlcat(name, "@", sizeof (name));
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  2970
	(void) strlcat(name, dd->snapname, sizeof (name));
2199
712a788c2dfd PSARC 2006/388 snapshot -r
ahrens
parents: 2169
diff changeset
  2971
712a788c2dfd PSARC 2006/388 snapshot -r
ahrens
parents: 2169
diff changeset
  2972
	szhp = make_dataset_handle(zhp->zfs_hdl, name);
712a788c2dfd PSARC 2006/388 snapshot -r
ahrens
parents: 2169
diff changeset
  2973
	if (szhp) {
712a788c2dfd PSARC 2006/388 snapshot -r
ahrens
parents: 2169
diff changeset
  2974
		dd->gotone = B_TRUE;
712a788c2dfd PSARC 2006/388 snapshot -r
ahrens
parents: 2169
diff changeset
  2975
		zfs_close(szhp);
712a788c2dfd PSARC 2006/388 snapshot -r
ahrens
parents: 2169
diff changeset
  2976
	}
712a788c2dfd PSARC 2006/388 snapshot -r
ahrens
parents: 2169
diff changeset
  2977
3265
967e0fca6143 6463140 zfs recv with a snapshot name that has 2 @@ in a row succeeds
ahrens
parents: 3237
diff changeset
  2978
	dd->closezhp = B_TRUE;
10588
dc03f981ea18 6438937 if 'zfs destroy' fails, it can leave a zvol device link missing
Eric Taylor <Eric.Taylor@Sun.COM>
parents: 10342
diff changeset
  2979
	if (!dd->gotone)
dc03f981ea18 6438937 if 'zfs destroy' fails, it can leave a zvol device link missing
Eric Taylor <Eric.Taylor@Sun.COM>
parents: 10342
diff changeset
  2980
		rv = zfs_iter_filesystems(zhp, zfs_check_snap_cb, arg);
3265
967e0fca6143 6463140 zfs recv with a snapshot name that has 2 @@ in a row succeeds
ahrens
parents: 3237
diff changeset
  2981
	if (closezhp)
967e0fca6143 6463140 zfs recv with a snapshot name that has 2 @@ in a row succeeds
ahrens
parents: 3237
diff changeset
  2982
		zfs_close(zhp);
967e0fca6143 6463140 zfs recv with a snapshot name that has 2 @@ in a row succeeds
ahrens
parents: 3237
diff changeset
  2983
	return (rv);
2199
712a788c2dfd PSARC 2006/388 snapshot -r
ahrens
parents: 2169
diff changeset
  2984
}
712a788c2dfd PSARC 2006/388 snapshot -r
ahrens
parents: 2169
diff changeset
  2985
712a788c2dfd PSARC 2006/388 snapshot -r
ahrens
parents: 2169
diff changeset
  2986
/*
712a788c2dfd PSARC 2006/388 snapshot -r
ahrens
parents: 2169
diff changeset
  2987
 * Destroys all snapshots with the given name in zhp & descendants.
712a788c2dfd PSARC 2006/388 snapshot -r
ahrens
parents: 2169
diff changeset
  2988
 */
712a788c2dfd PSARC 2006/388 snapshot -r
ahrens
parents: 2169
diff changeset
  2989
int
10242
c40d075fbca6 PSARC/2009/297 zfs snapshot holds
Chris Kirby <chris.kirby@sun.com>
parents: 10204
diff changeset
  2990
zfs_destroy_snaps(zfs_handle_t *zhp, char *snapname, boolean_t defer)
2199
712a788c2dfd PSARC 2006/388 snapshot -r
ahrens
parents: 2169
diff changeset
  2991
{
712a788c2dfd PSARC 2006/388 snapshot -r
ahrens
parents: 2169
diff changeset
  2992
	zfs_cmd_t zc = { 0 };
712a788c2dfd PSARC 2006/388 snapshot -r
ahrens
parents: 2169
diff changeset
  2993
	int ret;
712a788c2dfd PSARC 2006/388 snapshot -r
ahrens
parents: 2169
diff changeset
  2994
	struct destroydata dd = { 0 };
712a788c2dfd PSARC 2006/388 snapshot -r
ahrens
parents: 2169
diff changeset
  2995
712a788c2dfd PSARC 2006/388 snapshot -r
ahrens
parents: 2169
diff changeset
  2996
	dd.snapname = snapname;
10588
dc03f981ea18 6438937 if 'zfs destroy' fails, it can leave a zvol device link missing
Eric Taylor <Eric.Taylor@Sun.COM>
parents: 10342
diff changeset
  2997
	(void) zfs_check_snap_cb(zhp, &dd);
2199
712a788c2dfd PSARC 2006/388 snapshot -r
ahrens
parents: 2169
diff changeset
  2998
712a788c2dfd PSARC 2006/388 snapshot -r
ahrens
parents: 2169
diff changeset
  2999
	if (!dd.gotone) {
3237
98d0c28f2f5e 6480245 renaming a dataset to something with '%s' will cause segfault
lling
parents: 3234
diff changeset
  3000
		return (zfs_standard_error_fmt(zhp->zfs_hdl, ENOENT,
2199
712a788c2dfd PSARC 2006/388 snapshot -r
ahrens
parents: 2169
diff changeset
  3001
		    dgettext(TEXT_DOMAIN, "cannot destroy '%s@%s'"),
712a788c2dfd PSARC 2006/388 snapshot -r
ahrens
parents: 2169
diff changeset
  3002
		    zhp->zfs_name, snapname));
712a788c2dfd PSARC 2006/388 snapshot -r
ahrens
parents: 2169
diff changeset
  3003
	}
712a788c2dfd PSARC 2006/388 snapshot -r
ahrens
parents: 2169
diff changeset
  3004
712a788c2dfd PSARC 2006/388 snapshot -r
ahrens
parents: 2169
diff changeset
  3005
	(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
  3006
	(void) strlcpy(zc.zc_value, snapname, sizeof (zc.zc_value));
10242
c40d075fbca6 PSARC/2009/297 zfs snapshot holds
Chris Kirby <chris.kirby@sun.com>
parents: 10204
diff changeset
  3007
	zc.zc_defer_destroy = defer;
2199
712a788c2dfd PSARC 2006/388 snapshot -r
ahrens
parents: 2169
diff changeset
  3008
4543
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  3009
	ret = zfs_ioctl(zhp->zfs_hdl, ZFS_IOC_DESTROY_SNAPS, &zc);
2199
712a788c2dfd PSARC 2006/388 snapshot -r
ahrens
parents: 2169
diff changeset
  3010
	if (ret != 0) {
712a788c2dfd PSARC 2006/388 snapshot -r
ahrens
parents: 2169
diff changeset
  3011
		char errbuf[1024];
712a788c2dfd PSARC 2006/388 snapshot -r
ahrens
parents: 2169
diff changeset
  3012
712a788c2dfd PSARC 2006/388 snapshot -r
ahrens
parents: 2169
diff changeset
  3013
		(void) snprintf(errbuf, sizeof (errbuf), dgettext(TEXT_DOMAIN,
712a788c2dfd PSARC 2006/388 snapshot -r
ahrens
parents: 2169
diff changeset
  3014
		    "cannot destroy '%s@%s'"), zc.zc_name, snapname);
712a788c2dfd PSARC 2006/388 snapshot -r
ahrens
parents: 2169
diff changeset
  3015
712a788c2dfd PSARC 2006/388 snapshot -r
ahrens
parents: 2169
diff changeset
  3016
		switch (errno) {
712a788c2dfd PSARC 2006/388 snapshot -r
ahrens
parents: 2169
diff changeset
  3017
		case EEXIST:
712a788c2dfd PSARC 2006/388 snapshot -r
ahrens
parents: 2169
diff changeset
  3018
			zfs_error_aux(zhp->zfs_hdl, dgettext(TEXT_DOMAIN,
712a788c2dfd PSARC 2006/388 snapshot -r
ahrens
parents: 2169
diff changeset
  3019
			    "snapshot is cloned"));
712a788c2dfd PSARC 2006/388 snapshot -r
ahrens
parents: 2169
diff changeset
  3020
			return (zfs_error(zhp->zfs_hdl, EZFS_EXISTS, errbuf));
712a788c2dfd PSARC 2006/388 snapshot -r
ahrens
parents: 2169
diff changeset
  3021
712a788c2dfd PSARC 2006/388 snapshot -r
ahrens
parents: 2169
diff changeset
  3022
		default:
712a788c2dfd PSARC 2006/388 snapshot -r
ahrens
parents: 2169
diff changeset
  3023
			return (zfs_standard_error(zhp->zfs_hdl, errno,
712a788c2dfd PSARC 2006/388 snapshot -r
ahrens
parents: 2169
diff changeset
  3024
			    errbuf));
712a788c2dfd PSARC 2006/388 snapshot -r
ahrens
parents: 2169
diff changeset
  3025
		}
712a788c2dfd PSARC 2006/388 snapshot -r
ahrens
parents: 2169
diff changeset
  3026
	}
712a788c2dfd PSARC 2006/388 snapshot -r
ahrens
parents: 2169
diff changeset
  3027
712a788c2dfd PSARC 2006/388 snapshot -r
ahrens
parents: 2169
diff changeset
  3028
	return (0);
712a788c2dfd PSARC 2006/388 snapshot -r
ahrens
parents: 2169
diff changeset
  3029
}
712a788c2dfd PSARC 2006/388 snapshot -r
ahrens
parents: 2169
diff changeset
  3030
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3031
/*
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3032
 * Clones the given dataset.  The target must be of the same type as the source.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3033
 */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3034
int
2676
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  3035
zfs_clone(zfs_handle_t *zhp, const char *target, nvlist_t *props)
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3036
{
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3037
	zfs_cmd_t zc = { 0 };
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3038
	char parent[ZFS_MAXNAMELEN];
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3039
	int ret;
2082
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1793
diff changeset
  3040
	char errbuf[1024];
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1793
diff changeset
  3041
	libzfs_handle_t *hdl = zhp->zfs_hdl;
2676
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  3042
	zfs_type_t type;
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  3043
	uint64_t zoned;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3044
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3045
	assert(zhp->zfs_type == ZFS_TYPE_SNAPSHOT);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3046
2082
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1793
diff changeset
  3047
	(void) snprintf(errbuf, sizeof (errbuf), dgettext(TEXT_DOMAIN,
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1793
diff changeset
  3048
	    "cannot create '%s'"), target);
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1793
diff changeset
  3049
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3050
	/* validate the target name */
5326
6752aa2bd5bc 6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents: 5147
diff changeset
  3051
	if (!zfs_validate_name(hdl, target, ZFS_TYPE_FILESYSTEM, B_TRUE))
2082
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1793
diff changeset
  3052
		return (zfs_error(hdl, EZFS_INVALIDNAME, errbuf));
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3053
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3054
	/* validate parents exist */
4490
abf035049f7f PSARC 2007/199 zfs {create,clone,rename} -p
vb160487
parents: 4451
diff changeset
  3055
	if (check_parents(hdl, target, &zoned, B_FALSE, NULL) != 0)
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3056
		return (-1);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3057
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3058
	(void) parent_name(target, parent, sizeof (parent));
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3059
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3060
	/* do the clone */
2676
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  3061
	if (ZFS_IS_VOLUME(zhp)) {
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3062
		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
  3063
		type = ZFS_TYPE_VOLUME;
2676
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  3064
	} else {
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3065
		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
  3066
		type = ZFS_TYPE_FILESYSTEM;
2676
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  3067
	}
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  3068
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  3069
	if (props) {
7184
9508660f9c27 PSARC 2008/223 Pool root file system properties via zpool(1M)
timh
parents: 7042
diff changeset
  3070
		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
  3071
		    zhp, errbuf)) == NULL)
2676
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  3072
			return (-1);
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  3073
5094
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4861
diff changeset
  3074
		if (zcmd_write_src_nvlist(hdl, &zc, props) != 0) {
2676
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  3075
			nvlist_free(props);
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  3076
			return (-1);
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  3077
		}
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  3078
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  3079
		nvlist_free(props);
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  3080
	}
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3081
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3082
	(void) strlcpy(zc.zc_name, target, sizeof (zc.zc_name));
2676
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  3083
	(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
  3084
	ret = zfs_ioctl(zhp->zfs_hdl, ZFS_IOC_CREATE, &zc);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3085
2676
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  3086
	zcmd_free_nvlists(&zc);
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  3087
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3088
	if (ret != 0) {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3089
		switch (errno) {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3090
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3091
		case ENOENT:
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3092
			/*
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3093
			 * The parent doesn't exist.  We should have caught this
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3094
			 * above, but there may a race condition that has since
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3095
			 * destroyed the parent.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3096
			 *
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3097
			 * At this point, we don't know whether it's the source
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3098
			 * that doesn't exist anymore, or whether the target
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3099
			 * dataset doesn't exist.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3100
			 */
2082
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1793
diff changeset
  3101
			zfs_error_aux(zhp->zfs_hdl, dgettext(TEXT_DOMAIN,
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1793
diff changeset
  3102
			    "no such parent '%s'"), parent);
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1793
diff changeset
  3103
			return (zfs_error(zhp->zfs_hdl, EZFS_NOENT, errbuf));
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1793
diff changeset
  3104
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1793
diff changeset
  3105
		case EXDEV:
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1793
diff changeset
  3106
			zfs_error_aux(zhp->zfs_hdl, dgettext(TEXT_DOMAIN,
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1793
diff changeset
  3107
			    "source and target pools differ"));
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1793
diff changeset
  3108
			return (zfs_error(zhp->zfs_hdl, EZFS_CROSSTARGET,
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1793
diff changeset
  3109
			    errbuf));
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
		default:
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1793
diff changeset
  3112
			return (zfs_standard_error(zhp->zfs_hdl, errno,
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1793
diff changeset
  3113
			    errbuf));
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1793
diff changeset
  3114
		}
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1793
diff changeset
  3115
	}
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1793
diff changeset
  3116
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1793
diff changeset
  3117
	return (ret);
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1793
diff changeset
  3118
}
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1793
diff changeset
  3119
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1793
diff changeset
  3120
/*
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1793
diff changeset
  3121
 * Promotes the given clone fs to be the clone parent.
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1793
diff changeset
  3122
 */
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1793
diff changeset
  3123
int
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1793
diff changeset
  3124
zfs_promote(zfs_handle_t *zhp)
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1793
diff changeset
  3125
{
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1793
diff changeset
  3126
	libzfs_handle_t *hdl = zhp->zfs_hdl;
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1793
diff changeset
  3127
	zfs_cmd_t zc = { 0 };
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1793
diff changeset
  3128
	char parent[MAXPATHLEN];
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1793
diff changeset
  3129
	int ret;
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1793
diff changeset
  3130
	char errbuf[1024];
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1793
diff changeset
  3131
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1793
diff changeset
  3132
	(void) snprintf(errbuf, sizeof (errbuf), dgettext(TEXT_DOMAIN,
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1793
diff changeset
  3133
	    "cannot promote '%s'"), zhp->zfs_name);
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1793
diff changeset
  3134
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1793
diff changeset
  3135
	if (zhp->zfs_type == ZFS_TYPE_SNAPSHOT) {
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1793
diff changeset
  3136
		zfs_error_aux(hdl, dgettext(TEXT_DOMAIN,
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1793
diff changeset
  3137
		    "snapshots can not be promoted"));
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1793
diff changeset
  3138
		return (zfs_error(hdl, EZFS_BADTYPE, errbuf));
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1793
diff changeset
  3139
	}
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1793
diff changeset
  3140
5367
c40abbe796be PSARC/2007/574 zfs send -R
ahrens
parents: 5331
diff changeset
  3141
	(void) strlcpy(parent, zhp->zfs_dmustats.dds_origin, sizeof (parent));
2082
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1793
diff changeset
  3142
	if (parent[0] == '\0') {
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1793
diff changeset
  3143
		zfs_error_aux(hdl, dgettext(TEXT_DOMAIN,
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1793
diff changeset
  3144
		    "not a cloned filesystem"));
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1793
diff changeset
  3145
		return (zfs_error(hdl, EZFS_BADTYPE, errbuf));
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1793
diff changeset
  3146
	}
10588
dc03f981ea18 6438937 if 'zfs destroy' fails, it can leave a zvol device link missing
Eric Taylor <Eric.Taylor@Sun.COM>
parents: 10342
diff changeset
  3147
5367
c40abbe796be PSARC/2007/574 zfs send -R
ahrens
parents: 5331
diff changeset
  3148
	(void) strlcpy(zc.zc_value, zhp->zfs_dmustats.dds_origin,
2676
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  3149
	    sizeof (zc.zc_value));
2082
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1793
diff changeset
  3150
	(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
  3151
	ret = zfs_ioctl(hdl, ZFS_IOC_PROMOTE, &zc);
2082
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1793
diff changeset
  3152
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1793
diff changeset
  3153
	if (ret != 0) {
2417
694d5de97348 6444346 zfs promote fails in zone
ahrens
parents: 2199
diff changeset
  3154
		int save_errno = errno;
694d5de97348 6444346 zfs promote fails in zone
ahrens
parents: 2199
diff changeset
  3155
694d5de97348 6444346 zfs promote fails in zone
ahrens
parents: 2199
diff changeset
  3156
		switch (save_errno) {
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3157
		case EEXIST:
10588
dc03f981ea18 6438937 if 'zfs destroy' fails, it can leave a zvol device link missing
Eric Taylor <Eric.Taylor@Sun.COM>
parents: 10342
diff changeset
  3158
			/* There is a conflicting snapshot name. */
2082
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1793
diff changeset
  3159
			zfs_error_aux(hdl, dgettext(TEXT_DOMAIN,
10588
dc03f981ea18 6438937 if 'zfs destroy' fails, it can leave a zvol device link missing
Eric Taylor <Eric.Taylor@Sun.COM>
parents: 10342
diff changeset
  3160
			    "conflicting snapshot '%s' from parent '%s'"),
dc03f981ea18 6438937 if 'zfs destroy' fails, it can leave a zvol device link missing
Eric Taylor <Eric.Taylor@Sun.COM>
parents: 10342
diff changeset
  3161
			    zc.zc_string, parent);
2082
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1793
diff changeset
  3162
			return (zfs_error(hdl, EZFS_EXISTS, errbuf));
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3163
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3164
		default:
2417
694d5de97348 6444346 zfs promote fails in zone
ahrens
parents: 2199
diff changeset
  3165
			return (zfs_standard_error(hdl, save_errno, errbuf));
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3166
		}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3167
	}
2676
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  3168
	return (ret);
2199
712a788c2dfd PSARC 2006/388 snapshot -r
ahrens
parents: 2169
diff changeset
  3169
}
712a788c2dfd PSARC 2006/388 snapshot -r
ahrens
parents: 2169
diff changeset
  3170
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3171
/*
3504
6eb2466ff1c9 6516175 zfs_send()/zfs_receive() should take file descriptor arguments
ahl
parents: 3443
diff changeset
  3172
 * Takes a snapshot of the given dataset.
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3173
 */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3174
int
7265
cc18862247da PSARC/2008/483 ZFS clone -o
ahrens
parents: 7184
diff changeset
  3175
zfs_snapshot(libzfs_handle_t *hdl, const char *path, boolean_t recursive,
cc18862247da PSARC/2008/483 ZFS clone -o
ahrens
parents: 7184
diff changeset
  3176
    nvlist_t *props)
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3177
{
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3178
	const char *delim;
7265
cc18862247da PSARC/2008/483 ZFS clone -o
ahrens
parents: 7184
diff changeset
  3179
	char parent[ZFS_MAXNAMELEN];
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3180
	zfs_handle_t *zhp;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3181
	zfs_cmd_t zc = { 0 };
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3182
	int ret;
2082
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1793
diff changeset
  3183
	char errbuf[1024];
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1793
diff changeset
  3184
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1793
diff changeset
  3185
	(void) snprintf(errbuf, sizeof (errbuf), dgettext(TEXT_DOMAIN,
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1793
diff changeset
  3186
	    "cannot snapshot '%s'"), path);
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1793
diff changeset
  3187
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1793
diff changeset
  3188
	/* validate the target name */
5326
6752aa2bd5bc 6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents: 5147
diff changeset
  3189
	if (!zfs_validate_name(hdl, path, ZFS_TYPE_SNAPSHOT, B_TRUE))
2082
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1793
diff changeset
  3190
		return (zfs_error(hdl, EZFS_INVALIDNAME, errbuf));
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3191
7265
cc18862247da PSARC/2008/483 ZFS clone -o
ahrens
parents: 7184
diff changeset
  3192
	if (props) {
cc18862247da PSARC/2008/483 ZFS clone -o
ahrens
parents: 7184
diff changeset
  3193
		if ((props = zfs_valid_proplist(hdl, ZFS_TYPE_SNAPSHOT,
cc18862247da PSARC/2008/483 ZFS clone -o
ahrens
parents: 7184
diff changeset
  3194
		    props, B_FALSE, NULL, errbuf)) == NULL)
cc18862247da PSARC/2008/483 ZFS clone -o
ahrens
parents: 7184
diff changeset
  3195
			return (-1);
cc18862247da PSARC/2008/483 ZFS clone -o
ahrens
parents: 7184
diff changeset
  3196
cc18862247da PSARC/2008/483 ZFS clone -o
ahrens
parents: 7184
diff changeset
  3197
		if (zcmd_write_src_nvlist(hdl, &zc, props) != 0) {
cc18862247da PSARC/2008/483 ZFS clone -o
ahrens
parents: 7184
diff changeset
  3198
			nvlist_free(props);
cc18862247da PSARC/2008/483 ZFS clone -o
ahrens
parents: 7184
diff changeset
  3199
			return (-1);
cc18862247da PSARC/2008/483 ZFS clone -o
ahrens
parents: 7184
diff changeset
  3200
		}
cc18862247da PSARC/2008/483 ZFS clone -o
ahrens
parents: 7184
diff changeset
  3201
cc18862247da PSARC/2008/483 ZFS clone -o
ahrens
parents: 7184
diff changeset
  3202
		nvlist_free(props);
cc18862247da PSARC/2008/483 ZFS clone -o
ahrens
parents: 7184
diff changeset
  3203
	}
cc18862247da PSARC/2008/483 ZFS clone -o
ahrens
parents: 7184
diff changeset
  3204
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3205
	/* make sure the parent exists and is of the appropriate type */
2199
712a788c2dfd PSARC 2006/388 snapshot -r
ahrens
parents: 2169
diff changeset
  3206
	delim = strchr(path, '@');
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3207
	(void) strncpy(parent, path, delim - path);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3208
	parent[delim - path] = '\0';
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3209
2082
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1793
diff changeset
  3210
	if ((zhp = zfs_open(hdl, parent, ZFS_TYPE_FILESYSTEM |
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3211
	    ZFS_TYPE_VOLUME)) == NULL) {
7265
cc18862247da PSARC/2008/483 ZFS clone -o
ahrens
parents: 7184
diff changeset
  3212
		zcmd_free_nvlists(&zc);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3213
		return (-1);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3214
	}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3215
2199
712a788c2dfd PSARC 2006/388 snapshot -r
ahrens
parents: 2169
diff changeset
  3216
	(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
  3217
	(void) strlcpy(zc.zc_value, delim+1, sizeof (zc.zc_value));
4543
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  3218
	if (ZFS_IS_VOLUME(zhp))
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  3219
		zc.zc_objset_type = DMU_OST_ZVOL;
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  3220
	else
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  3221
		zc.zc_objset_type = DMU_OST_ZFS;
2199
712a788c2dfd PSARC 2006/388 snapshot -r
ahrens
parents: 2169
diff changeset
  3222
	zc.zc_cookie = recursive;
4543
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  3223
	ret = zfs_ioctl(zhp->zfs_hdl, ZFS_IOC_SNAPSHOT, &zc);
2199
712a788c2dfd PSARC 2006/388 snapshot -r
ahrens
parents: 2169
diff changeset
  3224
7265
cc18862247da PSARC/2008/483 ZFS clone -o
ahrens
parents: 7184
diff changeset
  3225
	zcmd_free_nvlists(&zc);
cc18862247da PSARC/2008/483 ZFS clone -o
ahrens
parents: 7184
diff changeset
  3226
2199
712a788c2dfd PSARC 2006/388 snapshot -r
ahrens
parents: 2169
diff changeset
  3227
	/*
712a788c2dfd PSARC 2006/388 snapshot -r
ahrens
parents: 2169
diff changeset
  3228
	 * if it was recursive, the one that actually failed will be in
712a788c2dfd PSARC 2006/388 snapshot -r
ahrens
parents: 2169
diff changeset
  3229
	 * zc.zc_name.
712a788c2dfd PSARC 2006/388 snapshot -r
ahrens
parents: 2169
diff changeset
  3230
	 */
10588
dc03f981ea18 6438937 if 'zfs destroy' fails, it can leave a zvol device link missing
Eric Taylor <Eric.Taylor@Sun.COM>
parents: 10342
diff changeset
  3231
	if (ret != 0) {
4543
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  3232
		(void) snprintf(errbuf, sizeof (errbuf), dgettext(TEXT_DOMAIN,
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  3233
		    "cannot create snapshot '%s@%s'"), zc.zc_name, zc.zc_value);
10588
dc03f981ea18 6438937 if 'zfs destroy' fails, it can leave a zvol device link missing
Eric Taylor <Eric.Taylor@Sun.COM>
parents: 10342
diff changeset
  3234
		(void) zfs_standard_error(hdl, errno, errbuf);
2199
712a788c2dfd PSARC 2006/388 snapshot -r
ahrens
parents: 2169
diff changeset
  3235
	}
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3236
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3237
	zfs_close(zhp);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3238
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3239
	return (ret);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3240
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3241
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3242
/*
1294
87b43e5de5ee 6364129 need to unmount any child datasets before doing the rollback
lling
parents: 1175
diff changeset
  3243
 * 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
  3244
 * 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
  3245
 * 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
  3246
 * group.
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3247
 */
1294
87b43e5de5ee 6364129 need to unmount any child datasets before doing the rollback
lling
parents: 1175
diff changeset
  3248
typedef struct rollback_data {
87b43e5de5ee 6364129 need to unmount any child datasets before doing the rollback
lling
parents: 1175
diff changeset
  3249
	const char	*cb_target;		/* the snapshot */
87b43e5de5ee 6364129 need to unmount any child datasets before doing the rollback
lling
parents: 1175
diff changeset
  3250
	uint64_t	cb_create;		/* creation time reference */
5749
78a7afaea267 PSARC/2007/699 zfs rollback -f operative
ahrens
parents: 5717
diff changeset
  3251
	boolean_t	cb_error;
2082
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1793
diff changeset
  3252
	boolean_t	cb_dependent;
5749
78a7afaea267 PSARC/2007/699 zfs rollback -f operative
ahrens
parents: 5717
diff changeset
  3253
	boolean_t	cb_force;
1294
87b43e5de5ee 6364129 need to unmount any child datasets before doing the rollback
lling
parents: 1175
diff changeset
  3254
} rollback_data_t;
87b43e5de5ee 6364129 need to unmount any child datasets before doing the rollback
lling
parents: 1175
diff changeset
  3255
87b43e5de5ee 6364129 need to unmount any child datasets before doing the rollback
lling
parents: 1175
diff changeset
  3256
static int
87b43e5de5ee 6364129 need to unmount any child datasets before doing the rollback
lling
parents: 1175
diff changeset
  3257
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
  3258
{
87b43e5de5ee 6364129 need to unmount any child datasets before doing the rollback
lling
parents: 1175
diff changeset
  3259
	rollback_data_t *cbp = data;
87b43e5de5ee 6364129 need to unmount any child datasets before doing the rollback
lling
parents: 1175
diff changeset
  3260
87b43e5de5ee 6364129 need to unmount any child datasets before doing the rollback
lling
parents: 1175
diff changeset
  3261
	if (!cbp->cb_dependent) {
87b43e5de5ee 6364129 need to unmount any child datasets before doing the rollback
lling
parents: 1175
diff changeset
  3262
		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
  3263
		    zfs_get_type(zhp) == ZFS_TYPE_SNAPSHOT &&
87b43e5de5ee 6364129 need to unmount any child datasets before doing the rollback
lling
parents: 1175
diff changeset
  3264
		    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
  3265
		    cbp->cb_create) {
4543
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  3266
			char *logstr;
1294
87b43e5de5ee 6364129 need to unmount any child datasets before doing the rollback
lling
parents: 1175
diff changeset
  3267
2082
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1793
diff changeset
  3268
			cbp->cb_dependent = B_TRUE;
5446
51fbc14b301d 6421210 zfs rollback without unmounting
ahrens
parents: 5378
diff changeset
  3269
			cbp->cb_error |= zfs_iter_dependents(zhp, B_FALSE,
51fbc14b301d 6421210 zfs rollback without unmounting
ahrens
parents: 5378
diff changeset
  3270
			    rollback_destroy, cbp);
2082
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1793
diff changeset
  3271
			cbp->cb_dependent = B_FALSE;
1294
87b43e5de5ee 6364129 need to unmount any child datasets before doing the rollback
lling
parents: 1175
diff changeset
  3272
4543
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  3273
			logstr = zhp->zfs_hdl->libzfs_log_str;
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  3274
			zhp->zfs_hdl->libzfs_log_str = NULL;
10242
c40d075fbca6 PSARC/2009/297 zfs snapshot holds
Chris Kirby <chris.kirby@sun.com>
parents: 10204
diff changeset
  3275
			cbp->cb_error |= zfs_destroy(zhp, B_FALSE);
4543
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  3276
			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
  3277
		}
87b43e5de5ee 6364129 need to unmount any child datasets before doing the rollback
lling
parents: 1175
diff changeset
  3278
	} else {
5749
78a7afaea267 PSARC/2007/699 zfs rollback -f operative
ahrens
parents: 5717
diff changeset
  3279
		/* We must destroy this clone; first unmount it */
78a7afaea267 PSARC/2007/699 zfs rollback -f operative
ahrens
parents: 5717
diff changeset
  3280
		prop_changelist_t *clp;
78a7afaea267 PSARC/2007/699 zfs rollback -f operative
ahrens
parents: 5717
diff changeset
  3281
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
  3282
		clp = changelist_gather(zhp, ZFS_PROP_NAME, 0,
5749
78a7afaea267 PSARC/2007/699 zfs rollback -f operative
ahrens
parents: 5717
diff changeset
  3283
		    cbp->cb_force ? MS_FORCE: 0);
78a7afaea267 PSARC/2007/699 zfs rollback -f operative
ahrens
parents: 5717
diff changeset
  3284
		if (clp == NULL || changelist_prefix(clp) != 0) {
78a7afaea267 PSARC/2007/699 zfs rollback -f operative
ahrens
parents: 5717
diff changeset
  3285
			cbp->cb_error = B_TRUE;
78a7afaea267 PSARC/2007/699 zfs rollback -f operative
ahrens
parents: 5717
diff changeset
  3286
			zfs_close(zhp);
78a7afaea267 PSARC/2007/699 zfs rollback -f operative
ahrens
parents: 5717
diff changeset
  3287
			return (0);
78a7afaea267 PSARC/2007/699 zfs rollback -f operative
ahrens
parents: 5717
diff changeset
  3288
		}
10242
c40d075fbca6 PSARC/2009/297 zfs snapshot holds
Chris Kirby <chris.kirby@sun.com>
parents: 10204
diff changeset
  3289
		if (zfs_destroy(zhp, B_FALSE) != 0)
5749
78a7afaea267 PSARC/2007/699 zfs rollback -f operative
ahrens
parents: 5717
diff changeset
  3290
			cbp->cb_error = B_TRUE;
78a7afaea267 PSARC/2007/699 zfs rollback -f operative
ahrens
parents: 5717
diff changeset
  3291
		else
78a7afaea267 PSARC/2007/699 zfs rollback -f operative
ahrens
parents: 5717
diff changeset
  3292
			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
  3293
		(void) changelist_postfix(clp);
5749
78a7afaea267 PSARC/2007/699 zfs rollback -f operative
ahrens
parents: 5717
diff changeset
  3294
		changelist_free(clp);
1294
87b43e5de5ee 6364129 need to unmount any child datasets before doing the rollback
lling
parents: 1175
diff changeset
  3295
	}
87b43e5de5ee 6364129 need to unmount any child datasets before doing the rollback
lling
parents: 1175
diff changeset
  3296
87b43e5de5ee 6364129 need to unmount any child datasets before doing the rollback
lling
parents: 1175
diff changeset
  3297
	zfs_close(zhp);
87b43e5de5ee 6364129 need to unmount any child datasets before doing the rollback
lling
parents: 1175
diff changeset
  3298
	return (0);
87b43e5de5ee 6364129 need to unmount any child datasets before doing the rollback
lling
parents: 1175
diff changeset
  3299
}
87b43e5de5ee 6364129 need to unmount any child datasets before doing the rollback
lling
parents: 1175
diff changeset
  3300
87b43e5de5ee 6364129 need to unmount any child datasets before doing the rollback
lling
parents: 1175
diff changeset
  3301
/*
5446
51fbc14b301d 6421210 zfs rollback without unmounting
ahrens
parents: 5378
diff changeset
  3302
 * Given a dataset, rollback to a specific snapshot, discarding any
51fbc14b301d 6421210 zfs rollback without unmounting
ahrens
parents: 5378
diff changeset
  3303
 * data changes since then and making it the active dataset.
51fbc14b301d 6421210 zfs rollback without unmounting
ahrens
parents: 5378
diff changeset
  3304
 *
51fbc14b301d 6421210 zfs rollback without unmounting
ahrens
parents: 5378
diff changeset
  3305
 * Any snapshots more recent than the target are destroyed, along with
51fbc14b301d 6421210 zfs rollback without unmounting
ahrens
parents: 5378
diff changeset
  3306
 * their dependents.
1294
87b43e5de5ee 6364129 need to unmount any child datasets before doing the rollback
lling
parents: 1175
diff changeset
  3307
 */
5446
51fbc14b301d 6421210 zfs rollback without unmounting
ahrens
parents: 5378
diff changeset
  3308
int
5749
78a7afaea267 PSARC/2007/699 zfs rollback -f operative
ahrens
parents: 5717
diff changeset
  3309
zfs_rollback(zfs_handle_t *zhp, zfs_handle_t *snap, boolean_t force)
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3310
{
5446
51fbc14b301d 6421210 zfs rollback without unmounting
ahrens
parents: 5378
diff changeset
  3311
	rollback_data_t cb = { 0 };
51fbc14b301d 6421210 zfs rollback without unmounting
ahrens
parents: 5378
diff changeset
  3312
	int err;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3313
	zfs_cmd_t zc = { 0 };
5713
f9b7933f3770 PSARC/2007/675 A_MDEV Removal
rm160521
parents: 5592
diff changeset
  3314
	boolean_t restore_resv = 0;
f9b7933f3770 PSARC/2007/675 A_MDEV Removal
rm160521
parents: 5592
diff changeset
  3315
	uint64_t old_volsize, new_volsize;
f9b7933f3770 PSARC/2007/675 A_MDEV Removal
rm160521
parents: 5592
diff changeset
  3316
	zfs_prop_t resv_prop;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3317
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3318
	assert(zhp->zfs_type == ZFS_TYPE_FILESYSTEM ||
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3319
	    zhp->zfs_type == ZFS_TYPE_VOLUME);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3320
5446
51fbc14b301d 6421210 zfs rollback without unmounting
ahrens
parents: 5378
diff changeset
  3321
	/*
51fbc14b301d 6421210 zfs rollback without unmounting
ahrens
parents: 5378
diff changeset
  3322
	 * Destroy all recent snapshots and its dependends.
51fbc14b301d 6421210 zfs rollback without unmounting
ahrens
parents: 5378
diff changeset
  3323
	 */
5749
78a7afaea267 PSARC/2007/699 zfs rollback -f operative
ahrens
parents: 5717
diff changeset
  3324
	cb.cb_force = force;
5446
51fbc14b301d 6421210 zfs rollback without unmounting
ahrens
parents: 5378
diff changeset
  3325
	cb.cb_target = snap->zfs_name;
51fbc14b301d 6421210 zfs rollback without unmounting
ahrens
parents: 5378
diff changeset
  3326
	cb.cb_create = zfs_prop_get_int(snap, ZFS_PROP_CREATETXG);
51fbc14b301d 6421210 zfs rollback without unmounting
ahrens
parents: 5378
diff changeset
  3327
	(void) zfs_iter_children(zhp, rollback_destroy, &cb);
51fbc14b301d 6421210 zfs rollback without unmounting
ahrens
parents: 5378
diff changeset
  3328
5749
78a7afaea267 PSARC/2007/699 zfs rollback -f operative
ahrens
parents: 5717
diff changeset
  3329
	if (cb.cb_error)
78a7afaea267 PSARC/2007/699 zfs rollback -f operative
ahrens
parents: 5717
diff changeset
  3330
		return (-1);
5446
51fbc14b301d 6421210 zfs rollback without unmounting
ahrens
parents: 5378
diff changeset
  3331
51fbc14b301d 6421210 zfs rollback without unmounting
ahrens
parents: 5378
diff changeset
  3332
	/*
51fbc14b301d 6421210 zfs rollback without unmounting
ahrens
parents: 5378
diff changeset
  3333
	 * Now that we have verified that the snapshot is the latest,
51fbc14b301d 6421210 zfs rollback without unmounting
ahrens
parents: 5378
diff changeset
  3334
	 * rollback to the given snapshot.
51fbc14b301d 6421210 zfs rollback without unmounting
ahrens
parents: 5378
diff changeset
  3335
	 */
51fbc14b301d 6421210 zfs rollback without unmounting
ahrens
parents: 5378
diff changeset
  3336
5713
f9b7933f3770 PSARC/2007/675 A_MDEV Removal
rm160521
parents: 5592
diff changeset
  3337
	if (zhp->zfs_type == ZFS_TYPE_VOLUME) {
f9b7933f3770 PSARC/2007/675 A_MDEV Removal
rm160521
parents: 5592
diff changeset
  3338
		if (zfs_which_resv_prop(zhp, &resv_prop) < 0)
f9b7933f3770 PSARC/2007/675 A_MDEV Removal
rm160521
parents: 5592
diff changeset
  3339
			return (-1);
f9b7933f3770 PSARC/2007/675 A_MDEV Removal
rm160521
parents: 5592
diff changeset
  3340
		old_volsize = zfs_prop_get_int(zhp, ZFS_PROP_VOLSIZE);
f9b7933f3770 PSARC/2007/675 A_MDEV Removal
rm160521
parents: 5592
diff changeset
  3341
		restore_resv =
f9b7933f3770 PSARC/2007/675 A_MDEV Removal
rm160521
parents: 5592
diff changeset
  3342
		    (old_volsize == zfs_prop_get_int(zhp, resv_prop));
f9b7933f3770 PSARC/2007/675 A_MDEV Removal
rm160521
parents: 5592
diff changeset
  3343
	}
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3344
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3345
	(void) strlcpy(zc.zc_name, zhp->zfs_name, sizeof (zc.zc_name));
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3346
2676
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  3347
	if (ZFS_IS_VOLUME(zhp))
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3348
		zc.zc_objset_type = DMU_OST_ZVOL;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3349
	else
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3350
		zc.zc_objset_type = DMU_OST_ZFS;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3351
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3352
	/*
5446
51fbc14b301d 6421210 zfs rollback without unmounting
ahrens
parents: 5378
diff changeset
  3353
	 * We rely on zfs_iter_children() to verify that there are no
51fbc14b301d 6421210 zfs rollback without unmounting
ahrens
parents: 5378
diff changeset
  3354
	 * newer snapshots for the given dataset.  Therefore, we can
51fbc14b301d 6421210 zfs rollback without unmounting
ahrens
parents: 5378
diff changeset
  3355
	 * simply pass the name on to the ioctl() call.  There is still
51fbc14b301d 6421210 zfs rollback without unmounting
ahrens
parents: 5378
diff changeset
  3356
	 * an unlikely race condition where the user has taken a
51fbc14b301d 6421210 zfs rollback without unmounting
ahrens
parents: 5378
diff changeset
  3357
	 * snapshot since we verified that this was the most recent.
5713
f9b7933f3770 PSARC/2007/675 A_MDEV Removal
rm160521
parents: 5592
diff changeset
  3358
	 *
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3359
	 */
5446
51fbc14b301d 6421210 zfs rollback without unmounting
ahrens
parents: 5378
diff changeset
  3360
	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
  3361
		(void) zfs_standard_error_fmt(zhp->zfs_hdl, errno,
2082
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1793
diff changeset
  3362
		    dgettext(TEXT_DOMAIN, "cannot rollback '%s'"),
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1793
diff changeset
  3363
		    zhp->zfs_name);
5717
b163be0bb014 6419176 'zfs rollback <volume@snap>' does not lower reservation (fix lint)
rm160521
parents: 5713
diff changeset
  3364
		return (err);
b163be0bb014 6419176 'zfs rollback <volume@snap>' does not lower reservation (fix lint)
rm160521
parents: 5713
diff changeset
  3365
	}
5713
f9b7933f3770 PSARC/2007/675 A_MDEV Removal
rm160521
parents: 5592
diff changeset
  3366
f9b7933f3770 PSARC/2007/675 A_MDEV Removal
rm160521
parents: 5592
diff changeset
  3367
	/*
f9b7933f3770 PSARC/2007/675 A_MDEV Removal
rm160521
parents: 5592
diff changeset
  3368
	 * For volumes, if the pre-rollback volsize matched the pre-
f9b7933f3770 PSARC/2007/675 A_MDEV Removal
rm160521
parents: 5592
diff changeset
  3369
	 * rollback reservation and the volsize has changed then set
f9b7933f3770 PSARC/2007/675 A_MDEV Removal
rm160521
parents: 5592
diff changeset
  3370
	 * the reservation property to the post-rollback volsize.
f9b7933f3770 PSARC/2007/675 A_MDEV Removal
rm160521
parents: 5592
diff changeset
  3371
	 * Make a new handle since the rollback closed the dataset.
f9b7933f3770 PSARC/2007/675 A_MDEV Removal
rm160521
parents: 5592
diff changeset
  3372
	 */
5717
b163be0bb014 6419176 'zfs rollback <volume@snap>' does not lower reservation (fix lint)
rm160521
parents: 5713
diff changeset
  3373
	if ((zhp->zfs_type == ZFS_TYPE_VOLUME) &&
b163be0bb014 6419176 'zfs rollback <volume@snap>' does not lower reservation (fix lint)
rm160521
parents: 5713
diff changeset
  3374
	    (zhp = make_dataset_handle(zhp->zfs_hdl, zhp->zfs_name))) {
5713
f9b7933f3770 PSARC/2007/675 A_MDEV Removal
rm160521
parents: 5592
diff changeset
  3375
		if (restore_resv) {
f9b7933f3770 PSARC/2007/675 A_MDEV Removal
rm160521
parents: 5592
diff changeset
  3376
			new_volsize = zfs_prop_get_int(zhp, ZFS_PROP_VOLSIZE);
f9b7933f3770 PSARC/2007/675 A_MDEV Removal
rm160521
parents: 5592
diff changeset
  3377
			if (old_volsize != new_volsize)
5717
b163be0bb014 6419176 'zfs rollback <volume@snap>' does not lower reservation (fix lint)
rm160521
parents: 5713
diff changeset
  3378
				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
  3379
				    new_volsize);
5713
f9b7933f3770 PSARC/2007/675 A_MDEV Removal
rm160521
parents: 5592
diff changeset
  3380
		}
f9b7933f3770 PSARC/2007/675 A_MDEV Removal
rm160521
parents: 5592
diff changeset
  3381
		zfs_close(zhp);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3382
	}
5446
51fbc14b301d 6421210 zfs rollback without unmounting
ahrens
parents: 5378
diff changeset
  3383
	return (err);
1294
87b43e5de5ee 6364129 need to unmount any child datasets before doing the rollback
lling
parents: 1175
diff changeset
  3384
}
87b43e5de5ee 6364129 need to unmount any child datasets before doing the rollback
lling
parents: 1175
diff changeset
  3385
87b43e5de5ee 6364129 need to unmount any child datasets before doing the rollback
lling
parents: 1175
diff changeset
  3386
/*
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3387
 * Iterate over all dependents for a given dataset.  This includes both
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3388
 * hierarchical dependents (children) and data dependents (snapshots and
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3389
 * clones).  The bulk of the processing occurs in get_dependents() in
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3390
 * libzfs_graph.c.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3391
 */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3392
int
2474
c001ad7e0c25 6368751 libzfs interface for mount/umounting all the file systems for a given pool
eschrock
parents: 2440
diff changeset
  3393
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
  3394
    zfs_iter_f func, void *data)
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3395
{
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3396
	char **dependents;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3397
	size_t count;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3398
	int i;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3399
	zfs_handle_t *child;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3400
	int ret = 0;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3401
2474
c001ad7e0c25 6368751 libzfs interface for mount/umounting all the file systems for a given pool
eschrock
parents: 2440
diff changeset
  3402
	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
  3403
	    &dependents, &count) != 0)
c001ad7e0c25 6368751 libzfs interface for mount/umounting all the file systems for a given pool
eschrock
parents: 2440
diff changeset
  3404
		return (-1);
c001ad7e0c25 6368751 libzfs interface for mount/umounting all the file systems for a given pool
eschrock
parents: 2440
diff changeset
  3405
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3406
	for (i = 0; i < count; i++) {
2082
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1793
diff changeset
  3407
		if ((child = make_dataset_handle(zhp->zfs_hdl,
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1793
diff changeset
  3408
		    dependents[i])) == NULL)
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3409
			continue;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3410
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3411
		if ((ret = func(child, data)) != 0)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3412
			break;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3413
	}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3414
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3415
	for (i = 0; i < count; i++)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3416
		free(dependents[i]);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3417
	free(dependents);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3418
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3419
	return (ret);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3420
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3421
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3422
/*
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3423
 * Renames the given dataset.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3424
 */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3425
int
4490
abf035049f7f PSARC 2007/199 zfs {create,clone,rename} -p
vb160487
parents: 4451
diff changeset
  3426
zfs_rename(zfs_handle_t *zhp, const char *target, boolean_t recursive)
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3427
{
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3428
	int ret;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3429
	zfs_cmd_t zc = { 0 };
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3430
	char *delim;
4007
c6f5c6753018 PSARC 2007/142 zfs rename -r
mmusante
parents: 3912
diff changeset
  3431
	prop_changelist_t *cl = NULL;
c6f5c6753018 PSARC 2007/142 zfs rename -r
mmusante
parents: 3912
diff changeset
  3432
	zfs_handle_t *zhrp = NULL;
c6f5c6753018 PSARC 2007/142 zfs rename -r
mmusante
parents: 3912
diff changeset
  3433
	char *parentname = NULL;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3434
	char parent[ZFS_MAXNAMELEN];
2082
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1793
diff changeset
  3435
	libzfs_handle_t *hdl = zhp->zfs_hdl;
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1793
diff changeset
  3436
	char errbuf[1024];
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3437
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3438
	/* if we have the same exact name, just return success */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3439
	if (strcmp(zhp->zfs_name, target) == 0)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3440
		return (0);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3441
2082
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1793
diff changeset
  3442
	(void) snprintf(errbuf, sizeof (errbuf), dgettext(TEXT_DOMAIN,
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1793
diff changeset
  3443
	    "cannot rename to '%s'"), target);
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1793
diff changeset
  3444
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3445
	/*
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3446
	 * Make sure the target name is valid
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3447
	 */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3448
	if (zhp->zfs_type == ZFS_TYPE_SNAPSHOT) {
2665
7b208a92357b PSARC 2006/479 zfs receive -F
nd150628
parents: 2474
diff changeset
  3449
		if ((strchr(target, '@') == NULL) ||
7b208a92357b PSARC 2006/479 zfs receive -F
nd150628
parents: 2474
diff changeset
  3450
		    *target == '@') {
7b208a92357b PSARC 2006/479 zfs receive -F
nd150628
parents: 2474
diff changeset
  3451
			/*
7b208a92357b PSARC 2006/479 zfs receive -F
nd150628
parents: 2474
diff changeset
  3452
			 * Snapshot target name is abbreviated,
7b208a92357b PSARC 2006/479 zfs receive -F
nd150628
parents: 2474
diff changeset
  3453
			 * reconstruct full dataset name
7b208a92357b PSARC 2006/479 zfs receive -F
nd150628
parents: 2474
diff changeset
  3454
			 */
7b208a92357b PSARC 2006/479 zfs receive -F
nd150628
parents: 2474
diff changeset
  3455
			(void) strlcpy(parent, zhp->zfs_name,
7b208a92357b PSARC 2006/479 zfs receive -F
nd150628
parents: 2474
diff changeset
  3456
			    sizeof (parent));
7b208a92357b PSARC 2006/479 zfs receive -F
nd150628
parents: 2474
diff changeset
  3457
			delim = strchr(parent, '@');
7b208a92357b PSARC 2006/479 zfs receive -F
nd150628
parents: 2474
diff changeset
  3458
			if (strchr(target, '@') == NULL)
7b208a92357b PSARC 2006/479 zfs receive -F
nd150628
parents: 2474
diff changeset
  3459
				*(++delim) = '\0';
7b208a92357b PSARC 2006/479 zfs receive -F
nd150628
parents: 2474
diff changeset
  3460
			else
7b208a92357b PSARC 2006/479 zfs receive -F
nd150628
parents: 2474
diff changeset
  3461
				*delim = '\0';
7b208a92357b PSARC 2006/479 zfs receive -F
nd150628
parents: 2474
diff changeset
  3462
			(void) strlcat(parent, target, sizeof (parent));
7b208a92357b PSARC 2006/479 zfs receive -F
nd150628
parents: 2474
diff changeset
  3463
			target = parent;
7b208a92357b PSARC 2006/479 zfs receive -F
nd150628
parents: 2474
diff changeset
  3464
		} else {
7b208a92357b PSARC 2006/479 zfs receive -F
nd150628
parents: 2474
diff changeset
  3465
			/*
7b208a92357b PSARC 2006/479 zfs receive -F
nd150628
parents: 2474
diff changeset
  3466
			 * Make sure we're renaming within the same dataset.
7b208a92357b PSARC 2006/479 zfs receive -F
nd150628
parents: 2474
diff changeset
  3467
			 */
7b208a92357b PSARC 2006/479 zfs receive -F
nd150628
parents: 2474
diff changeset
  3468
			delim = strchr(target, '@');
7b208a92357b PSARC 2006/479 zfs receive -F
nd150628
parents: 2474
diff changeset
  3469
			if (strncmp(zhp->zfs_name, target, delim - target)
7b208a92357b PSARC 2006/479 zfs receive -F
nd150628
parents: 2474
diff changeset
  3470
			    != 0 || zhp->zfs_name[delim - target] != '@') {
7b208a92357b PSARC 2006/479 zfs receive -F
nd150628
parents: 2474
diff changeset
  3471
				zfs_error_aux(hdl, dgettext(TEXT_DOMAIN,
7b208a92357b PSARC 2006/479 zfs receive -F
nd150628
parents: 2474
diff changeset
  3472
				    "snapshots must be part of same "
7b208a92357b PSARC 2006/479 zfs receive -F
nd150628
parents: 2474
diff changeset
  3473
				    "dataset"));
7b208a92357b PSARC 2006/479 zfs receive -F
nd150628
parents: 2474
diff changeset
  3474
				return (zfs_error(hdl, EZFS_CROSSTARGET,
3912
f6891a60bd72 PSARC 2007/083 ZFS bootable datasets
lling
parents: 3886
diff changeset
  3475
				    errbuf));
2665
7b208a92357b PSARC 2006/479 zfs receive -F
nd150628
parents: 2474
diff changeset
  3476
			}
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3477
		}
5326
6752aa2bd5bc 6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents: 5147
diff changeset
  3478
		if (!zfs_validate_name(hdl, target, zhp->zfs_type, B_TRUE))
2665
7b208a92357b PSARC 2006/479 zfs receive -F
nd150628
parents: 2474
diff changeset
  3479
			return (zfs_error(hdl, EZFS_INVALIDNAME, errbuf));
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3480
	} else {
4007
c6f5c6753018 PSARC 2007/142 zfs rename -r
mmusante
parents: 3912
diff changeset
  3481
		if (recursive) {
c6f5c6753018 PSARC 2007/142 zfs rename -r
mmusante
parents: 3912
diff changeset
  3482
			zfs_error_aux(hdl, dgettext(TEXT_DOMAIN,
c6f5c6753018 PSARC 2007/142 zfs rename -r
mmusante
parents: 3912
diff changeset
  3483
			    "recursive rename must be a snapshot"));
c6f5c6753018 PSARC 2007/142 zfs rename -r
mmusante
parents: 3912
diff changeset
  3484
			return (zfs_error(hdl, EZFS_BADTYPE, errbuf));
c6f5c6753018 PSARC 2007/142 zfs rename -r
mmusante
parents: 3912
diff changeset
  3485
		}
c6f5c6753018 PSARC 2007/142 zfs rename -r
mmusante
parents: 3912
diff changeset
  3486
5326
6752aa2bd5bc 6425096 want online 'zfs recv' (read only and read/write)
ek110237
parents: 5147
diff changeset
  3487
		if (!zfs_validate_name(hdl, target, zhp->zfs_type, B_TRUE))
2665
7b208a92357b PSARC 2006/479 zfs receive -F
nd150628
parents: 2474
diff changeset
  3488
			return (zfs_error(hdl, EZFS_INVALIDNAME, errbuf));
2676
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  3489
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3490
		/* validate parents */
11497
69b45e632792 6698011 zfs incorrectly reports file systems as children when attempting a rename
Mark J Musante <Mark.Musante@Sun.COM>
parents: 11449
diff changeset
  3491
		if (check_parents(hdl, target, NULL, B_FALSE, NULL) != 0)
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3492
			return (-1);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3493
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3494
		/* make sure we're in the same pool */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3495
		verify((delim = strchr(target, '/')) != NULL);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3496
		if (strncmp(zhp->zfs_name, target, delim - target) != 0 ||
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3497
		    zhp->zfs_name[delim - target] != '/') {
2082
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1793
diff changeset
  3498
			zfs_error_aux(hdl, dgettext(TEXT_DOMAIN,
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1793
diff changeset
  3499
			    "datasets must be within same pool"));
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1793
diff changeset
  3500
			return (zfs_error(hdl, EZFS_CROSSTARGET, errbuf));
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3501
		}
2440
9281a87e8a9e 6451860 zfs rename' a filesystem|clone to its direct child will cause internal error
nd150628
parents: 2417
diff changeset
  3502
9281a87e8a9e 6451860 zfs rename' a filesystem|clone to its direct child will cause internal error
nd150628
parents: 2417
diff changeset
  3503
		/* new name cannot be a child of the current dataset name */
11497
69b45e632792 6698011 zfs incorrectly reports file systems as children when attempting a rename
Mark J Musante <Mark.Musante@Sun.COM>
parents: 11449
diff changeset
  3504
		if (is_descendant(zhp->zfs_name, target)) {
2440
9281a87e8a9e 6451860 zfs rename' a filesystem|clone to its direct child will cause internal error
nd150628
parents: 2417
diff changeset
  3505
			zfs_error_aux(hdl, dgettext(TEXT_DOMAIN,
11497
69b45e632792 6698011 zfs incorrectly reports file systems as children when attempting a rename
Mark J Musante <Mark.Musante@Sun.COM>
parents: 11449
diff changeset
  3506
			    "New dataset name cannot be a descendant of "
2440
9281a87e8a9e 6451860 zfs rename' a filesystem|clone to its direct child will cause internal error
nd150628
parents: 2417
diff changeset
  3507
			    "current dataset name"));
9281a87e8a9e 6451860 zfs rename' a filesystem|clone to its direct child will cause internal error
nd150628
parents: 2417
diff changeset
  3508
			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
  3509
		}
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3510
	}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3511
2082
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1793
diff changeset
  3512
	(void) snprintf(errbuf, sizeof (errbuf),
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1793
diff changeset
  3513
	    dgettext(TEXT_DOMAIN, "cannot rename '%s'"), zhp->zfs_name);
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1793
diff changeset
  3514
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3515
	if (getzoneid() == GLOBAL_ZONEID &&
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3516
	    zfs_prop_get_int(zhp, ZFS_PROP_ZONED)) {
2082
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1793
diff changeset
  3517
		zfs_error_aux(hdl, dgettext(TEXT_DOMAIN,
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1793
diff changeset
  3518
		    "dataset is used in a non-global zone"));
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1793
diff changeset
  3519
		return (zfs_error(hdl, EZFS_ZONED, errbuf));
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3520
	}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3521
4007
c6f5c6753018 PSARC 2007/142 zfs rename -r
mmusante
parents: 3912
diff changeset
  3522
	if (recursive) {
c6f5c6753018 PSARC 2007/142 zfs rename -r
mmusante
parents: 3912
diff changeset
  3523
4183
8dbff10731ef 6550857 recursive rename leaks memory and segfaults on failure
mmusante
parents: 4180
diff changeset
  3524
		parentname = zfs_strdup(zhp->zfs_hdl, zhp->zfs_name);
8dbff10731ef 6550857 recursive rename leaks memory and segfaults on failure
mmusante
parents: 4180
diff changeset
  3525
		if (parentname == NULL) {
8dbff10731ef 6550857 recursive rename leaks memory and segfaults on failure
mmusante
parents: 4180
diff changeset
  3526
			ret = -1;
8dbff10731ef 6550857 recursive rename leaks memory and segfaults on failure
mmusante
parents: 4180
diff changeset
  3527
			goto error;
8dbff10731ef 6550857 recursive rename leaks memory and segfaults on failure
mmusante
parents: 4180
diff changeset
  3528
		}
4007
c6f5c6753018 PSARC 2007/142 zfs rename -r
mmusante
parents: 3912
diff changeset
  3529
		delim = strchr(parentname, '@');
c6f5c6753018 PSARC 2007/142 zfs rename -r
mmusante
parents: 3912
diff changeset
  3530
		*delim = '\0';
5094
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4861
diff changeset
  3531
		zhrp = zfs_open(zhp->zfs_hdl, parentname, ZFS_TYPE_DATASET);
4007
c6f5c6753018 PSARC 2007/142 zfs rename -r
mmusante
parents: 3912
diff changeset
  3532
		if (zhrp == NULL) {
4183
8dbff10731ef 6550857 recursive rename leaks memory and segfaults on failure
mmusante
parents: 4180
diff changeset
  3533
			ret = -1;
8dbff10731ef 6550857 recursive rename leaks memory and segfaults on failure
mmusante
parents: 4180
diff changeset
  3534
			goto error;
4007
c6f5c6753018 PSARC 2007/142 zfs rename -r
mmusante
parents: 3912
diff changeset
  3535
		}
c6f5c6753018 PSARC 2007/142 zfs rename -r
mmusante
parents: 3912
diff changeset
  3536
c6f5c6753018 PSARC 2007/142 zfs rename -r
mmusante
parents: 3912
diff changeset
  3537
	} 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
  3538
		if ((cl = changelist_gather(zhp, ZFS_PROP_NAME, 0, 0)) == NULL)
4007
c6f5c6753018 PSARC 2007/142 zfs rename -r
mmusante
parents: 3912
diff changeset
  3539
			return (-1);
c6f5c6753018 PSARC 2007/142 zfs rename -r
mmusante
parents: 3912
diff changeset
  3540
c6f5c6753018 PSARC 2007/142 zfs rename -r
mmusante
parents: 3912
diff changeset
  3541
		if (changelist_haszonedchild(cl)) {
c6f5c6753018 PSARC 2007/142 zfs rename -r
mmusante
parents: 3912
diff changeset
  3542
			zfs_error_aux(hdl, dgettext(TEXT_DOMAIN,
c6f5c6753018 PSARC 2007/142 zfs rename -r
mmusante
parents: 3912
diff changeset
  3543
			    "child dataset with inherited mountpoint is used "
c6f5c6753018 PSARC 2007/142 zfs rename -r
mmusante
parents: 3912
diff changeset
  3544
			    "in a non-global zone"));
c6f5c6753018 PSARC 2007/142 zfs rename -r
mmusante
parents: 3912
diff changeset
  3545
			(void) zfs_error(hdl, EZFS_ZONED, errbuf);
c6f5c6753018 PSARC 2007/142 zfs rename -r
mmusante
parents: 3912
diff changeset
  3546
			goto error;
c6f5c6753018 PSARC 2007/142 zfs rename -r
mmusante
parents: 3912
diff changeset
  3547
		}
c6f5c6753018 PSARC 2007/142 zfs rename -r
mmusante
parents: 3912
diff changeset
  3548
c6f5c6753018 PSARC 2007/142 zfs rename -r
mmusante
parents: 3912
diff changeset
  3549
		if ((ret = changelist_prefix(cl)) != 0)
c6f5c6753018 PSARC 2007/142 zfs rename -r
mmusante
parents: 3912
diff changeset
  3550
			goto error;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3551
	}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3552
2676
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  3553
	if (ZFS_IS_VOLUME(zhp))
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3554
		zc.zc_objset_type = DMU_OST_ZVOL;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3555
	else
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3556
		zc.zc_objset_type = DMU_OST_ZFS;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3557
2665
7b208a92357b PSARC 2006/479 zfs receive -F
nd150628
parents: 2474
diff changeset
  3558
	(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
  3559
	(void) strlcpy(zc.zc_value, target, sizeof (zc.zc_value));
2665
7b208a92357b PSARC 2006/479 zfs receive -F
nd150628
parents: 2474
diff changeset
  3560
4007
c6f5c6753018 PSARC 2007/142 zfs rename -r
mmusante
parents: 3912
diff changeset
  3561
	zc.zc_cookie = recursive;
c6f5c6753018 PSARC 2007/142 zfs rename -r
mmusante
parents: 3912
diff changeset
  3562
4543
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  3563
	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
  3564
		/*
c6f5c6753018 PSARC 2007/142 zfs rename -r
mmusante
parents: 3912
diff changeset
  3565
		 * if it was recursive, the one that actually failed will
c6f5c6753018 PSARC 2007/142 zfs rename -r
mmusante
parents: 3912
diff changeset
  3566
		 * be in zc.zc_name
c6f5c6753018 PSARC 2007/142 zfs rename -r
mmusante
parents: 3912
diff changeset
  3567
		 */
c6f5c6753018 PSARC 2007/142 zfs rename -r
mmusante
parents: 3912
diff changeset
  3568
		(void) snprintf(errbuf, sizeof (errbuf), dgettext(TEXT_DOMAIN,
5367
c40abbe796be PSARC/2007/574 zfs send -R
ahrens
parents: 5331
diff changeset
  3569
		    "cannot rename '%s'"), zc.zc_name);
4007
c6f5c6753018 PSARC 2007/142 zfs rename -r
mmusante
parents: 3912
diff changeset
  3570
c6f5c6753018 PSARC 2007/142 zfs rename -r
mmusante
parents: 3912
diff changeset
  3571
		if (recursive && errno == EEXIST) {
c6f5c6753018 PSARC 2007/142 zfs rename -r
mmusante
parents: 3912
diff changeset
  3572
			zfs_error_aux(hdl, dgettext(TEXT_DOMAIN,
c6f5c6753018 PSARC 2007/142 zfs rename -r
mmusante
parents: 3912
diff changeset
  3573
			    "a child dataset already has a snapshot "
c6f5c6753018 PSARC 2007/142 zfs rename -r
mmusante
parents: 3912
diff changeset
  3574
			    "with the new name"));
4801
5cd7916484a5 4687827 dumpadm should be more tolerant of a read-only /etc/dumpadm.conf
eschrock
parents: 4787
diff changeset
  3575
			(void) zfs_error(hdl, EZFS_EXISTS, errbuf);
4007
c6f5c6753018 PSARC 2007/142 zfs rename -r
mmusante
parents: 3912
diff changeset
  3576
		} else {
c6f5c6753018 PSARC 2007/142 zfs rename -r
mmusante
parents: 3912
diff changeset
  3577
			(void) zfs_standard_error(zhp->zfs_hdl, errno, errbuf);
c6f5c6753018 PSARC 2007/142 zfs rename -r
mmusante
parents: 3912
diff changeset
  3578
		}
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3579
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3580
		/*
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3581
		 * On failure, we still want to remount any filesystems that
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3582
		 * were previously mounted, so we don't alter the system state.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3583
		 */
10588
dc03f981ea18 6438937 if 'zfs destroy' fails, it can leave a zvol device link missing
Eric Taylor <Eric.Taylor@Sun.COM>
parents: 10342
diff changeset
  3584
		if (!recursive)
4007
c6f5c6753018 PSARC 2007/142 zfs rename -r
mmusante
parents: 3912
diff changeset
  3585
			(void) changelist_postfix(cl);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3586
	} else {
10588
dc03f981ea18 6438937 if 'zfs destroy' fails, it can leave a zvol device link missing
Eric Taylor <Eric.Taylor@Sun.COM>
parents: 10342
diff changeset
  3587
		if (!recursive) {
4007
c6f5c6753018 PSARC 2007/142 zfs rename -r
mmusante
parents: 3912
diff changeset
  3588
			changelist_rename(cl, zfs_get_name(zhp), target);
c6f5c6753018 PSARC 2007/142 zfs rename -r
mmusante
parents: 3912
diff changeset
  3589
			ret = changelist_postfix(cl);
c6f5c6753018 PSARC 2007/142 zfs rename -r
mmusante
parents: 3912
diff changeset
  3590
		}
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3591
	}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3592
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3593
error:
4007
c6f5c6753018 PSARC 2007/142 zfs rename -r
mmusante
parents: 3912
diff changeset
  3594
	if (parentname) {
c6f5c6753018 PSARC 2007/142 zfs rename -r
mmusante
parents: 3912
diff changeset
  3595
		free(parentname);
c6f5c6753018 PSARC 2007/142 zfs rename -r
mmusante
parents: 3912
diff changeset
  3596
	}
c6f5c6753018 PSARC 2007/142 zfs rename -r
mmusante
parents: 3912
diff changeset
  3597
	if (zhrp) {
c6f5c6753018 PSARC 2007/142 zfs rename -r
mmusante
parents: 3912
diff changeset
  3598
		zfs_close(zhrp);
c6f5c6753018 PSARC 2007/142 zfs rename -r
mmusante
parents: 3912
diff changeset
  3599
	}
c6f5c6753018 PSARC 2007/142 zfs rename -r
mmusante
parents: 3912
diff changeset
  3600
	if (cl) {
c6f5c6753018 PSARC 2007/142 zfs rename -r
mmusante
parents: 3912
diff changeset
  3601
		changelist_free(cl);
c6f5c6753018 PSARC 2007/142 zfs rename -r
mmusante
parents: 3912
diff changeset
  3602
	}
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3603
	return (ret);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3604
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  3605
2676
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  3606
nvlist_t *
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  3607
zfs_get_user_props(zfs_handle_t *zhp)
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  3608
{
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  3609
	return (zhp->zfs_user_props);
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  3610
}
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  3611
11022
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 10984
diff changeset
  3612
nvlist_t *
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 10984
diff changeset
  3613
zfs_get_recvd_props(zfs_handle_t *zhp)
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 10984
diff changeset
  3614
{
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 10984
diff changeset
  3615
	if (zhp->zfs_recvd_props == NULL)
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 10984
diff changeset
  3616
		if (get_recvd_props_ioctl(zhp) != 0)
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 10984
diff changeset
  3617
			return (NULL);
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 10984
diff changeset
  3618
	return (zhp->zfs_recvd_props);
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 10984
diff changeset
  3619
}
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 10984
diff changeset
  3620
2676
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  3621
/*
3912
f6891a60bd72 PSARC 2007/083 ZFS bootable datasets
lling
parents: 3886
diff changeset
  3622
 * 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
  3623
 * display, and their maximum widths.  This does two main things:
f6891a60bd72 PSARC 2007/083 ZFS bootable datasets
lling
parents: 3886
diff changeset
  3624
 *
f6891a60bd72 PSARC 2007/083 ZFS bootable datasets
lling
parents: 3886
diff changeset
  3625
 *      - 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
  3626
 *        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
  3627
 *        for new unique user properties and add them to the list.
f6891a60bd72 PSARC 2007/083 ZFS bootable datasets
lling
parents: 3886
diff changeset
  3628
 *
f6891a60bd72 PSARC 2007/083 ZFS bootable datasets
lling
parents: 3886
diff changeset
  3629
 *      - For non fixed-width properties, keep track of the maximum width seen
11022
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 10984
diff changeset
  3630
 *        so that we can size the column appropriately. If the user has
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 10984
diff changeset
  3631
 *        requested received property values, we also need to compute the width
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 10984
diff changeset
  3632
 *        of the RECEIVED column.
3912
f6891a60bd72 PSARC 2007/083 ZFS bootable datasets
lling
parents: 3886
diff changeset
  3633
 */
f6891a60bd72 PSARC 2007/083 ZFS bootable datasets
lling
parents: 3886
diff changeset
  3634
int
11022
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 10984
diff changeset
  3635
zfs_expand_proplist(zfs_handle_t *zhp, zprop_list_t **plp, boolean_t received)
3912
f6891a60bd72 PSARC 2007/083 ZFS bootable datasets
lling
parents: 3886
diff changeset
  3636
{
f6891a60bd72 PSARC 2007/083 ZFS bootable datasets
lling
parents: 3886
diff changeset
  3637
	libzfs_handle_t *hdl = zhp->zfs_hdl;
5094
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4861
diff changeset
  3638
	zprop_list_t *entry;
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4861
diff changeset
  3639
	zprop_list_t **last, **start;
3912
f6891a60bd72 PSARC 2007/083 ZFS bootable datasets
lling
parents: 3886
diff changeset
  3640
	nvlist_t *userprops, *propval;
f6891a60bd72 PSARC 2007/083 ZFS bootable datasets
lling
parents: 3886
diff changeset
  3641
	nvpair_t *elem;
f6891a60bd72 PSARC 2007/083 ZFS bootable datasets
lling
parents: 3886
diff changeset
  3642
	char *strval;
f6891a60bd72 PSARC 2007/083 ZFS bootable datasets
lling
parents: 3886
diff changeset
  3643
	char buf[ZFS_MAXPROPLEN];
f6891a60bd72 PSARC 2007/083 ZFS bootable datasets
lling
parents: 3886
diff changeset
  3644
5094
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4861
diff changeset
  3645
	if (zprop_expand_list(hdl, plp, ZFS_TYPE_DATASET) != 0)
3912
f6891a60bd72 PSARC 2007/083 ZFS bootable datasets
lling
parents: 3886
diff changeset
  3646
		return (-1);
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
	userprops = zfs_get_user_props(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
	entry = *plp;
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  3651
	if (entry->pl_all && nvlist_next_nvpair(userprops, NULL) != NULL) {
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  3652
		/*
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  3653
		 * Go through and add any user properties as necessary.  We
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  3654
		 * start by incrementing our list pointer to the first
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  3655
		 * non-native property.
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  3656
		 */
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  3657
		start = plp;
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  3658
		while (*start != NULL) {
5094
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4861
diff changeset
  3659
			if ((*start)->pl_prop == ZPROP_INVAL)
2676
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  3660
				break;
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  3661
			start = &(*start)->pl_next;
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  3662
		}
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  3663
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  3664
		elem = NULL;
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  3665
		while ((elem = nvlist_next_nvpair(userprops, elem)) != NULL) {
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  3666
			/*
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  3667
			 * See if we've already found this property in our list.
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  3668
			 */
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  3669
			for (last = start; *last != NULL;
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  3670
			    last = &(*last)->pl_next) {
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  3671
				if (strcmp((*last)->pl_user_prop,
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  3672
				    nvpair_name(elem)) == 0)
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  3673
					break;
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  3674
			}
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  3675
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  3676
			if (*last == NULL) {
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  3677
				if ((entry = zfs_alloc(hdl,
5094
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4861
diff changeset
  3678
				    sizeof (zprop_list_t))) == NULL ||
2676
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  3679
				    ((entry->pl_user_prop = zfs_strdup(hdl,
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  3680
				    nvpair_name(elem)))) == NULL) {
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  3681
					free(entry);
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  3682
					return (-1);
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  3683
				}
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  3684
5094
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4861
diff changeset
  3685
				entry->pl_prop = ZPROP_INVAL;
2676
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  3686
				entry->pl_width = strlen(nvpair_name(elem));
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  3687
				entry->pl_all = B_TRUE;
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  3688
				*last = entry;
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  3689
			}
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  3690
		}
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  3691
	}
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  3692
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  3693
	/*
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  3694
	 * Now go through and check the width of any non-fixed columns
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  3695
	 */
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  3696
	for (entry = *plp; entry != NULL; entry = entry->pl_next) {
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  3697
		if (entry->pl_fixed)
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  3698
			continue;
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  3699
5094
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4861
diff changeset
  3700
		if (entry->pl_prop != ZPROP_INVAL) {
2676
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  3701
			if (zfs_prop_get(zhp, entry->pl_prop,
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  3702
			    buf, sizeof (buf), NULL, NULL, 0, B_FALSE) == 0) {
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  3703
				if (strlen(buf) > entry->pl_width)
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  3704
					entry->pl_width = strlen(buf);
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  3705
			}
11022
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 10984
diff changeset
  3706
			if (received && zfs_prop_get_recvd(zhp,
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 10984
diff changeset
  3707
			    zfs_prop_to_name(entry->pl_prop),
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 10984
diff changeset
  3708
			    buf, sizeof (buf), B_FALSE) == 0)
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 10984
diff changeset
  3709
				if (strlen(buf) > entry->pl_recvd_width)
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 10984
diff changeset
  3710
					entry->pl_recvd_width = strlen(buf);
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 10984
diff changeset
  3711
		} else {
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 10984
diff changeset
  3712
			if (nvlist_lookup_nvlist(userprops, entry->pl_user_prop,
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 10984
diff changeset
  3713
			    &propval) == 0) {
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 10984
diff changeset
  3714
				verify(nvlist_lookup_string(propval,
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 10984
diff changeset
  3715
				    ZPROP_VALUE, &strval) == 0);
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 10984
diff changeset
  3716
				if (strlen(strval) > entry->pl_width)
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 10984
diff changeset
  3717
					entry->pl_width = strlen(strval);
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 10984
diff changeset
  3718
			}
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 10984
diff changeset
  3719
			if (received && zfs_prop_get_recvd(zhp,
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 10984
diff changeset
  3720
			    entry->pl_user_prop,
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 10984
diff changeset
  3721
			    buf, sizeof (buf), B_FALSE) == 0)
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 10984
diff changeset
  3722
				if (strlen(buf) > entry->pl_recvd_width)
63ab26072e41 PSARC 2009/510 ZFS received properties
Tom Erickson <Tom.Erickson@Sun.COM>
parents: 10984
diff changeset
  3723
					entry->pl_recvd_width = strlen(buf);
2676
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  3724
		}
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  3725
	}
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  3726
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  3727
	return (0);
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2665
diff changeset
  3728
}
4543
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  3729
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  3730
int
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  3731
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
  3732
{
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  3733
	zfs_cmd_t zc = { 0 };
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  3734
	nvlist_t *nvp;
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  3735
	gid_t gid;
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  3736
	uid_t uid;
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  3737
	const gid_t *groups;
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  3738
	int group_cnt;
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  3739
	int error;
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  3740
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  3741
	if (nvlist_alloc(&nvp, NV_UNIQUE_NAME, 0) != 0)
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  3742
		return (no_memory(hdl));
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  3743
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  3744
	uid = ucred_geteuid(cred);
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  3745
	gid = ucred_getegid(cred);
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  3746
	group_cnt = ucred_getgroups(cred, &groups);
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  3747
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  3748
	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
  3749
		return (1);
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  3750
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  3751
	if (nvlist_add_uint32(nvp, ZFS_DELEG_PERM_UID, uid) != 0) {
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  3752
		nvlist_free(nvp);
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  3753
		return (1);
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  3754
	}
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  3755
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  3756
	if (nvlist_add_uint32(nvp, ZFS_DELEG_PERM_GID, gid) != 0) {
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  3757
		nvlist_free(nvp);
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  3758
		return (1);
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  3759
	}
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  3760
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  3761
	if (nvlist_add_uint32_array(nvp,
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  3762
	    ZFS_DELEG_PERM_GROUPS, (uint32_t *)groups, group_cnt) != 0) {
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  3763
		nvlist_free(nvp);
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  3764
		return (1);
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  3765
	}
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  3766
	(void) strlcpy(zc.zc_name, dataset, sizeof (zc.zc_name));
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  3767
5094
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4861
diff changeset
  3768
	if (zcmd_write_src_nvlist(hdl, &zc, nvp))
4543
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  3769
		return (-1);
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  3770
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  3771
	error = ioctl(hdl->libzfs_fd, ZFS_IOC_ISCSI_PERM_CHECK, &zc);
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  3772
	nvlist_free(nvp);
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  3773
	return (error);
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  3774
}
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  3775
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  3776
int
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  3777
zfs_deleg_share_nfs(libzfs_handle_t *hdl, char *dataset, char *path,
8845
91af0d9c0790 6800942 smb_session_create() incorrectly stores IP addresses
Alan Wright <amw@Sun.COM>
parents: 8811
diff changeset
  3778
    char *resource, void *export, void *sharetab,
91af0d9c0790 6800942 smb_session_create() incorrectly stores IP addresses
Alan Wright <amw@Sun.COM>
parents: 8811
diff changeset
  3779
    int sharemax, zfs_share_op_t operation)
4543
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  3780
{
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  3781
	zfs_cmd_t zc = { 0 };
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  3782
	int error;
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  3783
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  3784
	(void) strlcpy(zc.zc_name, dataset, sizeof (zc.zc_name));
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  3785
	(void) strlcpy(zc.zc_value, path, sizeof (zc.zc_value));
8845
91af0d9c0790 6800942 smb_session_create() incorrectly stores IP addresses
Alan Wright <amw@Sun.COM>
parents: 8811
diff changeset
  3786
	if (resource)
91af0d9c0790 6800942 smb_session_create() incorrectly stores IP addresses
Alan Wright <amw@Sun.COM>
parents: 8811
diff changeset
  3787
		(void) strlcpy(zc.zc_string, resource, sizeof (zc.zc_string));
4543
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  3788
	zc.zc_share.z_sharedata = (uint64_t)(uintptr_t)sharetab;
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  3789
	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
  3790
	zc.zc_share.z_sharetype = operation;
4543
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  3791
	zc.zc_share.z_sharemax = sharemax;
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  3792
	error = ioctl(hdl->libzfs_fd, ZFS_IOC_SHARE, &zc);
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  3793
	return (error);
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4490
diff changeset
  3794
}
8802
010b31dd4c53 6773366 "zfs list" memory consumption can be further reduced
Sanjeev Bagewadi <Sanjeev.Bagewadi@Sun.COM>
parents: 8269
diff changeset
  3795
010b31dd4c53 6773366 "zfs list" memory consumption can be further reduced
Sanjeev Bagewadi <Sanjeev.Bagewadi@Sun.COM>
parents: 8269
diff changeset
  3796
void
010b31dd4c53 6773366 "zfs list" memory consumption can be further reduced
Sanjeev Bagewadi <Sanjeev.Bagewadi@Sun.COM>
parents: 8269
diff changeset
  3797
zfs_prune_proplist(zfs_handle_t *zhp, uint8_t *props)
010b31dd4c53 6773366 "zfs list" memory consumption can be further reduced
Sanjeev Bagewadi <Sanjeev.Bagewadi@Sun.COM>
parents: 8269
diff changeset
  3798
{
010b31dd4c53 6773366 "zfs list" memory consumption can be further reduced
Sanjeev Bagewadi <Sanjeev.Bagewadi@Sun.COM>
parents: 8269
diff changeset
  3799
	nvpair_t *curr;
010b31dd4c53 6773366 "zfs list" memory consumption can be further reduced
Sanjeev Bagewadi <Sanjeev.Bagewadi@Sun.COM>
parents: 8269
diff changeset
  3800
010b31dd4c53 6773366 "zfs list" memory consumption can be further reduced
Sanjeev Bagewadi <Sanjeev.Bagewadi@Sun.COM>
parents: 8269
diff changeset
  3801
	/*
010b31dd4c53 6773366 "zfs list" memory consumption can be further reduced
Sanjeev Bagewadi <Sanjeev.Bagewadi@Sun.COM>
parents: 8269
diff changeset
  3802
	 * Keep a reference to the props-table against which we prune the
010b31dd4c53 6773366 "zfs list" memory consumption can be further reduced
Sanjeev Bagewadi <Sanjeev.Bagewadi@Sun.COM>
parents: 8269
diff changeset
  3803
	 * properties.
010b31dd4c53 6773366 "zfs list" memory consumption can be further reduced
Sanjeev Bagewadi <Sanjeev.Bagewadi@Sun.COM>
parents: 8269
diff changeset
  3804
	 */
010b31dd4c53 6773366 "zfs list" memory consumption can be further reduced
Sanjeev Bagewadi <Sanjeev.Bagewadi@Sun.COM>
parents: 8269
diff changeset
  3805
	zhp->zfs_props_table = props;
010b31dd4c53 6773366 "zfs list" memory consumption can be further reduced
Sanjeev Bagewadi <Sanjeev.Bagewadi@Sun.COM>
parents: 8269
diff changeset
  3806
010b31dd4c53 6773366 "zfs list" memory consumption can be further reduced
Sanjeev Bagewadi <Sanjeev.Bagewadi@Sun.COM>
parents: 8269
diff changeset
  3807
	curr = nvlist_next_nvpair(zhp->zfs_props, NULL);
010b31dd4c53 6773366 "zfs list" memory consumption can be further reduced
Sanjeev Bagewadi <Sanjeev.Bagewadi@Sun.COM>
parents: 8269
diff changeset
  3808
010b31dd4c53 6773366 "zfs list" memory consumption can be further reduced
Sanjeev Bagewadi <Sanjeev.Bagewadi@Sun.COM>
parents: 8269
diff changeset
  3809
	while (curr) {
010b31dd4c53 6773366 "zfs list" memory consumption can be further reduced
Sanjeev Bagewadi <Sanjeev.Bagewadi@Sun.COM>
parents: 8269
diff changeset
  3810
		zfs_prop_t zfs_prop = zfs_name_to_prop(nvpair_name(curr));
010b31dd4c53 6773366 "zfs list" memory consumption can be further reduced
Sanjeev Bagewadi <Sanjeev.Bagewadi@Sun.COM>
parents: 8269
diff changeset
  3811
		nvpair_t *next = nvlist_next_nvpair(zhp->zfs_props, curr);
010b31dd4c53 6773366 "zfs list" memory consumption can be further reduced
Sanjeev Bagewadi <Sanjeev.Bagewadi@Sun.COM>
parents: 8269
diff changeset
  3812
9396
f41cf682d0d3 PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 8845
diff changeset
  3813
		/*
10960
dcc7d6f9faa8 6897978 zfs send should ignore unknown properties
Eric Schrock <Eric.Schrock@Sun.COM>
parents: 10951
diff changeset
  3814
		 * User properties will result in ZPROP_INVAL, and since we
dcc7d6f9faa8 6897978 zfs send should ignore unknown properties
Eric Schrock <Eric.Schrock@Sun.COM>
parents: 10951
diff changeset
  3815
		 * only know how to prune standard ZFS properties, we always
dcc7d6f9faa8 6897978 zfs send should ignore unknown properties
Eric Schrock <Eric.Schrock@Sun.COM>
parents: 10951
diff changeset
  3816
		 * leave these in the list.  This can also happen if we
dcc7d6f9faa8 6897978 zfs send should ignore unknown properties
Eric Schrock <Eric.Schrock@Sun.COM>
parents: 10951
diff changeset
  3817
		 * encounter an unknown DSL property (when running older
dcc7d6f9faa8 6897978 zfs send should ignore unknown properties
Eric Schrock <Eric.Schrock@Sun.COM>
parents: 10951
diff changeset
  3818
		 * software, for example).
9396
f41cf682d0d3 PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 8845
diff changeset
  3819
		 */
f41cf682d0d3 PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 8845
diff changeset
  3820
		if (zfs_prop != ZPROP_INVAL && props[zfs_prop] == B_FALSE)
8802
010b31dd4c53 6773366 "zfs list" memory consumption can be further reduced
Sanjeev Bagewadi <Sanjeev.Bagewadi@Sun.COM>
parents: 8269
diff changeset
  3821
			(void) nvlist_remove(zhp->zfs_props,
010b31dd4c53 6773366 "zfs list" memory consumption can be further reduced
Sanjeev Bagewadi <Sanjeev.Bagewadi@Sun.COM>
parents: 8269
diff changeset
  3822
			    nvpair_name(curr), nvpair_type(curr));
010b31dd4c53 6773366 "zfs list" memory consumption can be further reduced
Sanjeev Bagewadi <Sanjeev.Bagewadi@Sun.COM>
parents: 8269
diff changeset
  3823
		curr = next;
010b31dd4c53 6773366 "zfs list" memory consumption can be further reduced
Sanjeev Bagewadi <Sanjeev.Bagewadi@Sun.COM>
parents: 8269
diff changeset
  3824
	}
010b31dd4c53 6773366 "zfs list" memory consumption can be further reduced
Sanjeev Bagewadi <Sanjeev.Bagewadi@Sun.COM>
parents: 8269
diff changeset
  3825
}
8845
91af0d9c0790 6800942 smb_session_create() incorrectly stores IP addresses
Alan Wright <amw@Sun.COM>
parents: 8811
diff changeset
  3826
91af0d9c0790 6800942 smb_session_create() incorrectly stores IP addresses
Alan Wright <amw@Sun.COM>
parents: 8811
diff changeset
  3827
static int
91af0d9c0790 6800942 smb_session_create() incorrectly stores IP addresses
Alan Wright <amw@Sun.COM>
parents: 8811
diff changeset
  3828
zfs_smb_acl_mgmt(libzfs_handle_t *hdl, char *dataset, char *path,
91af0d9c0790 6800942 smb_session_create() incorrectly stores IP addresses
Alan Wright <amw@Sun.COM>
parents: 8811
diff changeset
  3829
    zfs_smb_acl_op_t cmd, char *resource1, char *resource2)
91af0d9c0790 6800942 smb_session_create() incorrectly stores IP addresses
Alan Wright <amw@Sun.COM>
parents: 8811
diff changeset
  3830
{
91af0d9c0790 6800942 smb_session_create() incorrectly stores IP addresses
Alan Wright <amw@Sun.COM>
parents: 8811
diff changeset
  3831
	zfs_cmd_t zc = { 0 };
91af0d9c0790 6800942 smb_session_create() incorrectly stores IP addresses
Alan Wright <amw@Sun.COM>
parents: 8811
diff changeset
  3832
	nvlist_t *nvlist = NULL;
91af0d9c0790 6800942 smb_session_create() incorrectly stores IP addresses
Alan Wright <amw@Sun.COM>
parents: 8811
diff changeset
  3833
	int error;
91af0d9c0790 6800942 smb_session_create() incorrectly stores IP addresses
Alan Wright <amw@Sun.COM>
parents: 8811
diff changeset
  3834
91af0d9c0790 6800942 smb_session_create() incorrectly stores IP addresses
Alan Wright <amw@Sun.COM>
parents: 8811
diff changeset
  3835
	(void) strlcpy(zc.zc_name, dataset, sizeof (zc.zc_name));
91af0d9c0790 6800942 smb_session_create() incorrectly stores IP addresses
Alan Wright <amw@Sun.COM>
parents: 8811
diff changeset
  3836
	(void) strlcpy(zc.zc_value, path, sizeof (zc.zc_value));
91af0d9c0790 6800942 smb_session_create() incorrectly stores IP addresses
Alan Wright <amw@Sun.COM>
parents: 8811
diff changeset
  3837
	zc.zc_cookie = (uint64_t)cmd;
91af0d9c0790 6800942 smb_session_create() incorrectly stores IP addresses
Alan Wright <amw@Sun.COM>
parents: 8811
diff changeset
  3838
91af0d9c0790 6800942 smb_session_create() incorrectly stores IP addresses
Alan Wright <amw@Sun.COM>
parents: 8811
diff changeset
  3839
	if (cmd == ZFS_SMB_ACL_RENAME) {
91af0d9c0790 6800942 smb_session_create() incorrectly stores IP addresses
Alan Wright <amw@Sun.COM>
parents: 8811
diff changeset
  3840
		if (nvlist_alloc(&nvlist, NV_UNIQUE_NAME, 0) != 0) {
91af0d9c0790 6800942 smb_session_create() incorrectly stores IP addresses
Alan Wright <amw@Sun.COM>
parents: 8811
diff changeset
  3841
			(void) no_memory(hdl);
91af0d9c0790 6800942 smb_session_create() incorrectly stores IP addresses
Alan Wright <amw@Sun.COM>
parents: 8811
diff changeset
  3842
			return (NULL);
91af0d9c0790 6800942 smb_session_create() incorrectly stores IP addresses
Alan Wright <amw@Sun.COM>
parents: 8811
diff changeset
  3843
		}
91af0d9c0790 6800942 smb_session_create() incorrectly stores IP addresses
Alan Wright <amw@Sun.COM>
parents: 8811
diff changeset
  3844
	}
91af0d9c0790 6800942 smb_session_create() incorrectly stores IP addresses
Alan Wright <amw@Sun.COM>
parents: 8811
diff changeset
  3845
91af0d9c0790 6800942 smb_session_create() incorrectly stores IP addresses
Alan Wright <amw@Sun.COM>
parents: 8811
diff changeset
  3846
	switch (cmd) {
91af0d9c0790 6800942 smb_session_create() incorrectly stores IP addresses
Alan Wright <amw@Sun.COM>
parents: 8811
diff changeset
  3847
	case ZFS_SMB_ACL_ADD:
91af0d9c0790 6800942 smb_session_create() incorrectly stores IP addresses
Alan Wright <amw@Sun.COM>
parents: 8811
diff changeset
  3848
	case ZFS_SMB_ACL_REMOVE:
91af0d9c0790 6800942 smb_session_create() incorrectly stores IP addresses
Alan Wright <amw@Sun.COM>
parents: 8811
diff changeset
  3849
		(void) strlcpy(zc.zc_string, resource1, sizeof (zc.zc_string));
91af0d9c0790 6800942 smb_session_create() incorrectly stores IP addresses
Alan Wright <amw@Sun.COM>
parents: 8811
diff changeset
  3850
		break;
91af0d9c0790 6800942 smb_session_create() incorrectly stores IP addresses
Alan Wright <amw@Sun.COM>
parents: 8811
diff changeset
  3851
	case ZFS_SMB_ACL_RENAME:
91af0d9c0790 6800942 smb_session_create() incorrectly stores IP addresses
Alan Wright <amw@Sun.COM>
parents: 8811
diff changeset
  3852
		if (nvlist_add_string(nvlist, ZFS_SMB_ACL_SRC,
91af0d9c0790 6800942 smb_session_create() incorrectly stores IP addresses
Alan Wright <amw@Sun.COM>
parents: 8811
diff changeset
  3853
		    resource1) != 0) {
91af0d9c0790 6800942 smb_session_create() incorrectly stores IP addresses
Alan Wright <amw@Sun.COM>
parents: 8811
diff changeset
  3854
				(void) no_memory(hdl);
91af0d9c0790 6800942 smb_session_create() incorrectly stores IP addresses
Alan Wright <amw@Sun.COM>
parents: 8811
diff changeset
  3855
				return (-1);
91af0d9c0790 6800942 smb_session_create() incorrectly stores IP addresses
Alan Wright <amw@Sun.COM>
parents: 8811
diff changeset
  3856
		}
91af0d9c0790 6800942 smb_session_create() incorrectly stores IP addresses
Alan Wright <amw@Sun.COM>
parents: 8811
diff changeset
  3857
		if (nvlist_add_string(nvlist, ZFS_SMB_ACL_TARGET,
91af0d9c0790 6800942 smb_session_create() incorrectly stores IP addresses
Alan Wright <amw@Sun.COM>
parents: 8811
diff changeset
  3858
		    resource2) != 0) {
91af0d9c0790 6800942 smb_session_create() incorrectly stores IP addresses
Alan Wright <amw@Sun.COM>
parents: 8811
diff changeset
  3859
				(void) no_memory(hdl);
91af0d9c0790 6800942 smb_session_create() incorrectly stores IP addresses
Alan Wright <amw@Sun.COM>
parents: 8811
diff changeset
  3860
				return (-1);
91af0d9c0790 6800942 smb_session_create() incorrectly stores IP addresses
Alan Wright <amw@Sun.COM>
parents: 8811
diff changeset
  3861
		}
91af0d9c0790 6800942 smb_session_create() incorrectly stores IP addresses
Alan Wright <amw@Sun.COM>
parents: 8811
diff changeset
  3862
		if (zcmd_write_src_nvlist(hdl, &zc, nvlist) != 0) {
91af0d9c0790 6800942 smb_session_create() incorrectly stores IP addresses
Alan Wright <amw@Sun.COM>
parents: 8811
diff changeset
  3863
			nvlist_free(nvlist);
91af0d9c0790 6800942 smb_session_create() incorrectly stores IP addresses
Alan Wright <amw@Sun.COM>
parents: 8811
diff changeset
  3864
			return (-1);
91af0d9c0790 6800942 smb_session_create() incorrectly stores IP addresses
Alan Wright <amw@Sun.COM>
parents: 8811
diff changeset
  3865
		}
91af0d9c0790 6800942 smb_session_create() incorrectly stores IP addresses
Alan Wright <amw@Sun.COM>
parents: 8811
diff changeset
  3866
		break;
91af0d9c0790 6800942 smb_session_create() incorrectly stores IP addresses
Alan Wright <amw@Sun.COM>
parents: 8811
diff changeset
  3867
	case ZFS_SMB_ACL_PURGE:
91af0d9c0790 6800942 smb_session_create() incorrectly stores IP addresses
Alan Wright <amw@Sun.COM>
parents: 8811
diff changeset
  3868
		break;
91af0d9c0790 6800942 smb_session_create() incorrectly stores IP addresses
Alan Wright <amw@Sun.COM>
parents: 8811
diff changeset
  3869
	default:
91af0d9c0790 6800942 smb_session_create() incorrectly stores IP addresses
Alan Wright <amw@Sun.COM>
parents: 8811
diff changeset
  3870
		return (-1);
91af0d9c0790 6800942 smb_session_create() incorrectly stores IP addresses
Alan Wright <amw@Sun.COM>
parents: 8811
diff changeset
  3871
	}
91af0d9c0790 6800942 smb_session_create() incorrectly stores IP addresses
Alan Wright <amw@Sun.COM>
parents: 8811
diff changeset
  3872
	error = ioctl(hdl->libzfs_fd, ZFS_IOC_SMB_ACL, &zc);
91af0d9c0790 6800942 smb_session_create() incorrectly stores IP addresses
Alan Wright <amw@Sun.COM>
parents: 8811
diff changeset
  3873
	if (nvlist)
91af0d9c0790 6800942 smb_session_create() incorrectly stores IP addresses
Alan Wright <amw@Sun.COM>
parents: 8811
diff changeset
  3874
		nvlist_free(nvlist);
91af0d9c0790 6800942 smb_session_create() incorrectly stores IP addresses
Alan Wright <amw@Sun.COM>
parents: 8811
diff changeset
  3875
	return (error);
91af0d9c0790 6800942 smb_session_create() incorrectly stores IP addresses
Alan Wright <amw@Sun.COM>
parents: 8811
diff changeset
  3876
}
91af0d9c0790 6800942 smb_session_create() incorrectly stores IP addresses
Alan Wright <amw@Sun.COM>
parents: 8811
diff changeset
  3877
91af0d9c0790 6800942 smb_session_create() incorrectly stores IP addresses
Alan Wright <amw@Sun.COM>
parents: 8811
diff changeset
  3878
int
91af0d9c0790 6800942 smb_session_create() incorrectly stores IP addresses
Alan Wright <amw@Sun.COM>
parents: 8811
diff changeset
  3879
zfs_smb_acl_add(libzfs_handle_t *hdl, char *dataset,
91af0d9c0790 6800942 smb_session_create() incorrectly stores IP addresses
Alan Wright <amw@Sun.COM>
parents: 8811
diff changeset
  3880
    char *path, char *resource)
91af0d9c0790 6800942 smb_session_create() incorrectly stores IP addresses
Alan Wright <amw@Sun.COM>
parents: 8811
diff changeset
  3881
{
91af0d9c0790 6800942 smb_session_create() incorrectly stores IP addresses
Alan Wright <amw@Sun.COM>
parents: 8811
diff changeset
  3882
	return (zfs_smb_acl_mgmt(hdl, dataset, path, ZFS_SMB_ACL_ADD,
91af0d9c0790 6800942 smb_session_create() incorrectly stores IP addresses
Alan Wright <amw@Sun.COM>
parents: 8811
diff changeset
  3883
	    resource, NULL));
91af0d9c0790 6800942 smb_session_create() incorrectly stores IP addresses
Alan Wright <amw@Sun.COM>
parents: 8811
diff changeset
  3884
}
91af0d9c0790 6800942 smb_session_create() incorrectly stores IP addresses
Alan Wright <amw@Sun.COM>
parents: 8811
diff changeset
  3885
91af0d9c0790 6800942 smb_session_create() incorrectly stores IP addresses
Alan Wright <amw@Sun.COM>
parents: 8811
diff changeset
  3886
int
91af0d9c0790 6800942 smb_session_create() incorrectly stores IP addresses
Alan Wright <amw@Sun.COM>
parents: 8811
diff changeset
  3887
zfs_smb_acl_remove(libzfs_handle_t *hdl, char *dataset,
91af0d9c0790 6800942 smb_session_create() incorrectly stores IP addresses
Alan Wright <amw@Sun.COM>
parents: 8811
diff changeset
  3888
    char *path, char *resource)
91af0d9c0790 6800942 smb_session_create() incorrectly stores IP addresses
Alan Wright <amw@Sun.COM>
parents: 8811
diff changeset
  3889
{
91af0d9c0790 6800942 smb_session_create() incorrectly stores IP addresses
Alan Wright <amw@Sun.COM>
parents: 8811
diff changeset
  3890
	return (zfs_smb_acl_mgmt(hdl, dataset, path, ZFS_SMB_ACL_REMOVE,
91af0d9c0790 6800942 smb_session_create() incorrectly stores IP addresses
Alan Wright <amw@Sun.COM>
parents: 8811
diff changeset
  3891
	    resource, NULL));
91af0d9c0790 6800942 smb_session_create() incorrectly stores IP addresses
Alan Wright <amw@Sun.COM>
parents: 8811
diff changeset
  3892
}
91af0d9c0790 6800942 smb_session_create() incorrectly stores IP addresses
Alan Wright <amw@Sun.COM>
parents: 8811
diff changeset
  3893
91af0d9c0790 6800942 smb_session_create() incorrectly stores IP addresses
Alan Wright <amw@Sun.COM>
parents: 8811
diff changeset
  3894
int
91af0d9c0790 6800942 smb_session_create() incorrectly stores IP addresses
Alan Wright <amw@Sun.COM>
parents: 8811
diff changeset
  3895
zfs_smb_acl_purge(libzfs_handle_t *hdl, char *dataset, char *path)
91af0d9c0790 6800942 smb_session_create() incorrectly stores IP addresses
Alan Wright <amw@Sun.COM>
parents: 8811
diff changeset
  3896
{
91af0d9c0790 6800942 smb_session_create() incorrectly stores IP addresses
Alan Wright <amw@Sun.COM>
parents: 8811
diff changeset
  3897
	return (zfs_smb_acl_mgmt(hdl, dataset, path, ZFS_SMB_ACL_PURGE,
91af0d9c0790 6800942 smb_session_create() incorrectly stores IP addresses
Alan Wright <amw@Sun.COM>
parents: 8811
diff changeset
  3898
	    NULL, NULL));
91af0d9c0790 6800942 smb_session_create() incorrectly stores IP addresses
Alan Wright <amw@Sun.COM>
parents: 8811
diff changeset
  3899
}
91af0d9c0790 6800942 smb_session_create() incorrectly stores IP addresses
Alan Wright <amw@Sun.COM>
parents: 8811
diff changeset
  3900
91af0d9c0790 6800942 smb_session_create() incorrectly stores IP addresses
Alan Wright <amw@Sun.COM>
parents: 8811
diff changeset
  3901
int
91af0d9c0790 6800942 smb_session_create() incorrectly stores IP addresses
Alan Wright <amw@Sun.COM>
parents: 8811
diff changeset
  3902
zfs_smb_acl_rename(libzfs_handle_t *hdl, char *dataset, char *path,
91af0d9c0790 6800942 smb_session_create() incorrectly stores IP addresses
Alan Wright <amw@Sun.COM>
parents: 8811
diff changeset
  3903
    char *oldname, char *newname)
91af0d9c0790 6800942 smb_session_create() incorrectly stores IP addresses
Alan Wright <amw@Sun.COM>
parents: 8811
diff changeset
  3904
{
91af0d9c0790 6800942 smb_session_create() incorrectly stores IP addresses
Alan Wright <amw@Sun.COM>
parents: 8811
diff changeset
  3905
	return (zfs_smb_acl_mgmt(hdl, dataset, path, ZFS_SMB_ACL_RENAME,
91af0d9c0790 6800942 smb_session_create() incorrectly stores IP addresses
Alan Wright <amw@Sun.COM>
parents: 8811
diff changeset
  3906
	    oldname, newname));
91af0d9c0790 6800942 smb_session_create() incorrectly stores IP addresses
Alan Wright <amw@Sun.COM>
parents: 8811
diff changeset
  3907
}
9396
f41cf682d0d3 PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 8845
diff changeset
  3908
f41cf682d0d3 PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 8845
diff changeset
  3909
int
f41cf682d0d3 PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 8845
diff changeset
  3910
zfs_userspace(zfs_handle_t *zhp, zfs_userquota_prop_t type,
f41cf682d0d3 PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 8845
diff changeset
  3911
    zfs_userspace_cb_t func, void *arg)
f41cf682d0d3 PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 8845
diff changeset
  3912
{
f41cf682d0d3 PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 8845
diff changeset
  3913
	zfs_cmd_t zc = { 0 };
f41cf682d0d3 PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 8845
diff changeset
  3914
	int error;
f41cf682d0d3 PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 8845
diff changeset
  3915
	zfs_useracct_t buf[100];
f41cf682d0d3 PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 8845
diff changeset
  3916
f41cf682d0d3 PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 8845
diff changeset
  3917
	(void) strncpy(zc.zc_name, zhp->zfs_name, sizeof (zc.zc_name));
f41cf682d0d3 PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 8845
diff changeset
  3918
f41cf682d0d3 PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 8845
diff changeset
  3919
	zc.zc_objset_type = type;
f41cf682d0d3 PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 8845
diff changeset
  3920
	zc.zc_nvlist_dst = (uintptr_t)buf;
f41cf682d0d3 PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 8845
diff changeset
  3921
f41cf682d0d3 PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 8845
diff changeset
  3922
	/* CONSTCOND */
f41cf682d0d3 PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 8845
diff changeset
  3923
	while (1) {
f41cf682d0d3 PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 8845
diff changeset
  3924
		zfs_useracct_t *zua = buf;
f41cf682d0d3 PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 8845
diff changeset
  3925
f41cf682d0d3 PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 8845
diff changeset
  3926
		zc.zc_nvlist_dst_size = sizeof (buf);
f41cf682d0d3 PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 8845
diff changeset
  3927
		error = ioctl(zhp->zfs_hdl->libzfs_fd,
f41cf682d0d3 PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 8845
diff changeset
  3928
		    ZFS_IOC_USERSPACE_MANY, &zc);
f41cf682d0d3 PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 8845
diff changeset
  3929
		if (error || zc.zc_nvlist_dst_size == 0)
f41cf682d0d3 PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 8845
diff changeset
  3930
			break;
f41cf682d0d3 PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 8845
diff changeset
  3931
f41cf682d0d3 PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 8845
diff changeset
  3932
		while (zc.zc_nvlist_dst_size > 0) {
9554
787363635b6a 6837523 gnu xgettext's useless comments should be filtered
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 9469
diff changeset
  3933
			error = func(arg, zua->zu_domain, zua->zu_rid,
787363635b6a 6837523 gnu xgettext's useless comments should be filtered
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 9469
diff changeset
  3934
			    zua->zu_space);
787363635b6a 6837523 gnu xgettext's useless comments should be filtered
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 9469
diff changeset
  3935
			if (error != 0)
787363635b6a 6837523 gnu xgettext's useless comments should be filtered
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 9469
diff changeset
  3936
				return (error);
9396
f41cf682d0d3 PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 8845
diff changeset
  3937
			zua++;
f41cf682d0d3 PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 8845
diff changeset
  3938
			zc.zc_nvlist_dst_size -= sizeof (zfs_useracct_t);
f41cf682d0d3 PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 8845
diff changeset
  3939
		}
f41cf682d0d3 PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 8845
diff changeset
  3940
	}
f41cf682d0d3 PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 8845
diff changeset
  3941
f41cf682d0d3 PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 8845
diff changeset
  3942
	return (error);
f41cf682d0d3 PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents: 8845
diff changeset
  3943
}
10242
c40d075fbca6 PSARC/2009/297 zfs snapshot holds
Chris Kirby <chris.kirby@sun.com>
parents: 10204
diff changeset
  3944
c40d075fbca6 PSARC/2009/297 zfs snapshot holds
Chris Kirby <chris.kirby@sun.com>
parents: 10204
diff changeset
  3945
int
c40d075fbca6 PSARC/2009/297 zfs snapshot holds
Chris Kirby <chris.kirby@sun.com>
parents: 10204
diff changeset
  3946
zfs_hold(zfs_handle_t *zhp, const char *snapname, const char *tag,
11417
de9a68916900 6911611 zfs_send()'s use of snapshot holds is still racy
Chris Kirby <Chris.Kirby@sun.com>
parents: 11080
diff changeset
  3947
    boolean_t recursive, boolean_t temphold, boolean_t enoent_ok)
10242
c40d075fbca6 PSARC/2009/297 zfs snapshot holds
Chris Kirby <chris.kirby@sun.com>
parents: 10204
diff changeset
  3948
{
c40d075fbca6 PSARC/2009/297 zfs snapshot holds
Chris Kirby <chris.kirby@sun.com>
parents: 10204
diff changeset
  3949
	zfs_cmd_t zc = { 0 };
c40d075fbca6 PSARC/2009/297 zfs snapshot holds
Chris Kirby <chris.kirby@sun.com>
parents: 10204
diff changeset
  3950
	libzfs_handle_t *hdl = zhp->zfs_hdl;
c40d075fbca6 PSARC/2009/297 zfs snapshot holds
Chris Kirby <chris.kirby@sun.com>
parents: 10204
diff changeset
  3951
c40d075fbca6 PSARC/2009/297 zfs snapshot holds
Chris Kirby <chris.kirby@sun.com>
parents: 10204
diff changeset
  3952
	(void) strlcpy(zc.zc_name, zhp->zfs_name, sizeof (zc.zc_name));
c40d075fbca6 PSARC/2009/297 zfs snapshot holds
Chris Kirby <chris.kirby@sun.com>
parents: 10204
diff changeset
  3953
	(void) strlcpy(zc.zc_value, snapname, sizeof (zc.zc_value));
10342
108f0058f837 6833815 scheduled snapshots deleted per snapshot policy can lead to replication failures
Chris Kirby <chris.kirby@sun.com>
parents: 10298
diff changeset
  3954
	if (strlcpy(zc.zc_string, tag, sizeof (zc.zc_string))
108f0058f837 6833815 scheduled snapshots deleted per snapshot policy can lead to replication failures
Chris Kirby <chris.kirby@sun.com>
parents: 10298
diff changeset
  3955
	    >= sizeof (zc.zc_string))
108f0058f837 6833815 scheduled snapshots deleted per snapshot policy can lead to replication failures
Chris Kirby <chris.kirby@sun.com>
parents: 10298
diff changeset
  3956
		return (zfs_error(hdl, EZFS_TAGTOOLONG, tag));
10242
c40d075fbca6 PSARC/2009/297 zfs snapshot holds
Chris Kirby <chris.kirby@sun.com>
parents: 10204
diff changeset
  3957
	zc.zc_cookie = recursive;
10342
108f0058f837 6833815 scheduled snapshots deleted per snapshot policy can lead to replication failures
Chris Kirby <chris.kirby@sun.com>
parents: 10298
diff changeset
  3958
	zc.zc_temphold = temphold;
10242
c40d075fbca6 PSARC/2009/297 zfs snapshot holds
Chris Kirby <chris.kirby@sun.com>
parents: 10204
diff changeset
  3959
c40d075fbca6 PSARC/2009/297 zfs snapshot holds
Chris Kirby <chris.kirby@sun.com>
parents: 10204
diff changeset
  3960
	if (zfs_ioctl(hdl, ZFS_IOC_HOLD, &zc) != 0) {
c40d075fbca6 PSARC/2009/297 zfs snapshot holds
Chris Kirby <chris.kirby@sun.com>
parents: 10204
diff changeset
  3961
		char errbuf[ZFS_MAXNAMELEN+32];
c40d075fbca6 PSARC/2009/297 zfs snapshot holds
Chris Kirby <chris.kirby@sun.com>
parents: 10204
diff changeset
  3962
c40d075fbca6 PSARC/2009/297 zfs snapshot holds
Chris Kirby <chris.kirby@sun.com>
parents: 10204
diff changeset
  3963
		/*
c40d075fbca6 PSARC/2009/297 zfs snapshot holds
Chris Kirby <chris.kirby@sun.com>
parents: 10204
diff changeset
  3964
		 * if it was recursive, the one that actually failed will be in
c40d075fbca6 PSARC/2009/297 zfs snapshot holds
Chris Kirby <chris.kirby@sun.com>
parents: 10204
diff changeset
  3965
		 * zc.zc_name.
c40d075fbca6 PSARC/2009/297 zfs snapshot holds
Chris Kirby <chris.kirby@sun.com>
parents: 10204
diff changeset
  3966
		 */
c40d075fbca6 PSARC/2009/297 zfs snapshot holds
Chris Kirby <chris.kirby@sun.com>
parents: 10204
diff changeset
  3967
		(void) snprintf(errbuf, sizeof (errbuf), dgettext(TEXT_DOMAIN,
c40d075fbca6 PSARC/2009/297 zfs snapshot holds
Chris Kirby <chris.kirby@sun.com>
parents: 10204
diff changeset
  3968
		    "cannot hold '%s@%s'"), zc.zc_name, snapname);
c40d075fbca6 PSARC/2009/297 zfs snapshot holds
Chris Kirby <chris.kirby@sun.com>
parents: 10204
diff changeset
  3969
		switch (errno) {
10951
56fd5475e8fe 6896756 assertion failed: 0 == dsl_pool_user_hold(dp, ds->ds_object, htag, &now, tx)
Chris Kirby <Chris.Kirby@sun.com>
parents: 10922
diff changeset
  3970
		case E2BIG:
56fd5475e8fe 6896756 assertion failed: 0 == dsl_pool_user_hold(dp, ds->ds_object, htag, &now, tx)
Chris Kirby <Chris.Kirby@sun.com>
parents: 10922
diff changeset
  3971
			/*
56fd5475e8fe 6896756 assertion failed: 0 == dsl_pool_user_hold(dp, ds->ds_object, htag, &now, tx)
Chris Kirby <Chris.Kirby@sun.com>
parents: 10922
diff changeset
  3972
			 * Temporary tags wind up having the ds object id
56fd5475e8fe 6896756 assertion failed: 0 == dsl_pool_user_hold(dp, ds->ds_object, htag, &now, tx)
Chris Kirby <Chris.Kirby@sun.com>
parents: 10922
diff changeset
  3973
			 * prepended. So even if we passed the length check
56fd5475e8fe 6896756 assertion failed: 0 == dsl_pool_user_hold(dp, ds->ds_object, htag, &now, tx)
Chris Kirby <Chris.Kirby@sun.com>
parents: 10922
diff changeset
  3974
			 * above, it's still possible for the tag to wind
56fd5475e8fe 6896756 assertion failed: 0 == dsl_pool_user_hold(dp, ds->ds_object, htag, &now, tx)
Chris Kirby <Chris.Kirby@sun.com>
parents: 10922
diff changeset
  3975
			 * up being slightly too long.
56fd5475e8fe 6896756 assertion failed: 0 == dsl_pool_user_hold(dp, ds->ds_object, htag, &now, tx)
Chris Kirby <Chris.Kirby@sun.com>
parents: 10922
diff changeset
  3976
			 */
56fd5475e8fe 6896756 assertion failed: 0 == dsl_pool_user_hold(dp, ds->ds_object, htag, &now, tx)
Chris Kirby <Chris.Kirby@sun.com>
parents: 10922
diff changeset
  3977
			return (zfs_error(hdl, EZFS_TAGTOOLONG, errbuf));
10242
c40d075fbca6 PSARC/2009/297 zfs snapshot holds
Chris Kirby <chris.kirby@sun.com>
parents: 10204
diff changeset
  3978
		case ENOTSUP:
c40d075fbca6 PSARC/2009/297 zfs snapshot holds
Chris Kirby <chris.kirby@sun.com>
parents: 10204
diff changeset
  3979
			zfs_error_aux(hdl, dgettext(TEXT_DOMAIN,
c40d075fbca6 PSARC/2009/297 zfs snapshot holds
Chris Kirby <chris.kirby@sun.com>
parents: 10204
diff changeset
  3980
			    "pool must be upgraded"));
c40d075fbca6 PSARC/2009/297 zfs snapshot holds
Chris Kirby <chris.kirby@sun.com>
parents: 10204
diff changeset
  3981
			return (zfs_error(hdl, EZFS_BADVERSION, errbuf));
c40d075fbca6 PSARC/2009/297 zfs snapshot holds
Chris Kirby <chris.kirby@sun.com>
parents: 10204
diff changeset
  3982
		case EINVAL:
c40d075fbca6 PSARC/2009/297 zfs snapshot holds
Chris Kirby <chris.kirby@sun.com>
parents: 10204
diff changeset
  3983
			return (zfs_error(hdl, EZFS_BADTYPE, errbuf));
c40d075fbca6 PSARC/2009/297 zfs snapshot holds
Chris Kirby <chris.kirby@sun.com>
parents: 10204
diff changeset
  3984
		case EEXIST:
c40d075fbca6 PSARC/2009/297 zfs snapshot holds
Chris Kirby <chris.kirby@sun.com>
parents: 10204
diff changeset
  3985
			return (zfs_error(hdl, EZFS_REFTAG_HOLD, errbuf));
11417
de9a68916900 6911611 zfs_send()'s use of snapshot holds is still racy
Chris Kirby <Chris.Kirby@sun.com>
parents: 11080
diff changeset
  3986
		case ENOENT:
de9a68916900 6911611 zfs_send()'s use of snapshot holds is still racy
Chris Kirby <Chris.Kirby@sun.com>
parents: 11080
diff changeset
  3987
			if (enoent_ok)
de9a68916900 6911611 zfs_send()'s use of snapshot holds is still racy
Chris Kirby <Chris.Kirby@sun.com>
parents: 11080
diff changeset
  3988
				return (0);
de9a68916900 6911611 zfs_send()'s use of snapshot holds is still racy
Chris Kirby <Chris.Kirby@sun.com>
parents: 11080
diff changeset
  3989
			/* FALLTHROUGH */
10242
c40d075fbca6 PSARC/2009/297 zfs snapshot holds
Chris Kirby <chris.kirby@sun.com>
parents: 10204
diff changeset
  3990
		default:
c40d075fbca6 PSARC/2009/297 zfs snapshot holds
Chris Kirby <chris.kirby@sun.com>
parents: 10204
diff changeset
  3991
			return (zfs_standard_error_fmt(hdl, errno, errbuf));
c40d075fbca6 PSARC/2009/297 zfs snapshot holds
Chris Kirby <chris.kirby@sun.com>
parents: 10204
diff changeset
  3992
		}
c40d075fbca6 PSARC/2009/297 zfs snapshot holds
Chris Kirby <chris.kirby@sun.com>
parents: 10204
diff changeset
  3993
	}
c40d075fbca6 PSARC/2009/297 zfs snapshot holds
Chris Kirby <chris.kirby@sun.com>
parents: 10204
diff changeset
  3994
c40d075fbca6 PSARC/2009/297 zfs snapshot holds
Chris Kirby <chris.kirby@sun.com>
parents: 10204
diff changeset
  3995
	return (0);
c40d075fbca6 PSARC/2009/297 zfs snapshot holds
Chris Kirby <chris.kirby@sun.com>
parents: 10204
diff changeset
  3996
}
c40d075fbca6 PSARC/2009/297 zfs snapshot holds
Chris Kirby <chris.kirby@sun.com>
parents: 10204
diff changeset
  3997
10342
108f0058f837 6833815 scheduled snapshots deleted per snapshot policy can lead to replication failures
Chris Kirby <chris.kirby@sun.com>
parents: 10298
diff changeset
  3998
struct hold_range_arg {
108f0058f837 6833815 scheduled snapshots deleted per snapshot policy can lead to replication failures
Chris Kirby <chris.kirby@sun.com>
parents: 10298
diff changeset
  3999
	zfs_handle_t	*origin;
108f0058f837 6833815 scheduled snapshots deleted per snapshot policy can lead to replication failures
Chris Kirby <chris.kirby@sun.com>
parents: 10298
diff changeset
  4000
	const char	*fromsnap;
108f0058f837 6833815 scheduled snapshots deleted per snapshot policy can lead to replication failures
Chris Kirby <chris.kirby@sun.com>
parents: 10298
diff changeset
  4001
	const char	*tosnap;
108f0058f837 6833815 scheduled snapshots deleted per snapshot policy can lead to replication failures
Chris Kirby <chris.kirby@sun.com>
parents: 10298
diff changeset
  4002
	char		lastsnapheld[ZFS_MAXNAMELEN];
108f0058f837 6833815 scheduled snapshots deleted per snapshot policy can lead to replication failures
Chris Kirby <chris.kirby@sun.com>
parents: 10298
diff changeset
  4003
	const char	*tag;
108f0058f837 6833815 scheduled snapshots deleted per snapshot policy can lead to replication failures
Chris Kirby <chris.kirby@sun.com>
parents: 10298
diff changeset
  4004
	boolean_t	temphold;
108f0058f837 6833815 scheduled snapshots deleted per snapshot policy can lead to replication failures
Chris Kirby <chris.kirby@sun.com>
parents: 10298
diff changeset
  4005
	boolean_t	seento;
108f0058f837 6833815 scheduled snapshots deleted per snapshot policy can lead to replication failures
Chris Kirby <chris.kirby@sun.com>
parents: 10298
diff changeset
  4006
	boolean_t	seenfrom;
108f0058f837 6833815 scheduled snapshots deleted per snapshot policy can lead to replication failures
Chris Kirby <chris.kirby@sun.com>
parents: 10298
diff changeset
  4007
	boolean_t	holding;
108f0058f837 6833815 scheduled snapshots deleted per snapshot policy can lead to replication failures
Chris Kirby <chris.kirby@sun.com>
parents: 10298
diff changeset
  4008
};
108f0058f837 6833815 scheduled snapshots deleted per snapshot policy can lead to replication failures
Chris Kirby <chris.kirby@sun.com>
parents: 10298
diff changeset
  4009
108f0058f837 6833815 scheduled snapshots deleted per snapshot policy can lead to replication failures
Chris Kirby <chris.kirby@sun.com>
parents: 10298
diff changeset
  4010
static int
108f0058f837 6833815 scheduled snapshots deleted per snapshot policy can lead to replication failures
Chris Kirby <chris.kirby@sun.com>
parents: 10298
diff changeset
  4011
zfs_hold_range_one(zfs_handle_t *zhp, void *arg)
108f0058f837 6833815 scheduled snapshots deleted per snapshot policy can lead to replication failures
Chris Kirby <chris.kirby@sun.com>
parents: 10298
diff changeset
  4012
{
108f0058f837 6833815 scheduled snapshots deleted per snapshot policy can lead to replication failures
Chris Kirby <chris.kirby@sun.com>
parents: 10298
diff changeset
  4013
	struct hold_range_arg *hra = arg;
108f0058f837 6833815 scheduled snapshots deleted per snapshot policy can lead to replication failures
Chris Kirby <chris.kirby@sun.com>
parents: 10298
diff changeset
  4014
	const char *thissnap;
108f0058f837 6833815 scheduled snapshots deleted per snapshot policy can lead to replication failures
Chris Kirby <chris.kirby@sun.com>
parents: 10298
diff changeset
  4015
	int error;
108f0058f837 6833815 scheduled snapshots deleted per snapshot policy can lead to replication failures
Chris Kirby <chris.kirby@sun.com>
parents: 10298
diff changeset
  4016
108f0058f837 6833815 scheduled snapshots deleted per snapshot policy can lead to replication failures
Chris Kirby <chris.kirby@sun.com>
parents: 10298
diff changeset
  4017
	thissnap = strchr(zfs_get_name(zhp), '@') + 1;
108f0058f837 6833815 scheduled snapshots deleted per snapshot policy can lead to replication failures
Chris Kirby <chris.kirby@sun.com>
parents: 10298
diff changeset
  4018
108f0058f837 6833815 scheduled snapshots deleted per snapshot policy can lead to replication failures
Chris Kirby <chris.kirby@sun.com>
parents: 10298
diff changeset
  4019
	if (hra->fromsnap && !hra->seenfrom &&
108f0058f837 6833815 scheduled snapshots deleted per snapshot policy can lead to replication failures
Chris Kirby <chris.kirby@sun.com>
parents: 10298
diff changeset
  4020
	    strcmp(hra->fromsnap, thissnap) == 0)
108f0058f837 6833815 scheduled snapshots deleted per snapshot policy can lead to replication failures
Chris Kirby <chris.kirby@sun.com>
parents: 10298
diff changeset
  4021
		hra->seenfrom = B_TRUE;
108f0058f837 6833815 scheduled snapshots deleted per snapshot policy can lead to replication failures
Chris Kirby <chris.kirby@sun.com>
parents: 10298
diff changeset
  4022
108f0058f837 6833815 scheduled snapshots deleted per snapshot policy can lead to replication failures
Chris Kirby <chris.kirby@sun.com>
parents: 10298
diff changeset
  4023
	/* snap is older or newer than the desired range, ignore it */
108f0058f837 6833815 scheduled snapshots deleted per snapshot policy can lead to replication failures
Chris Kirby <chris.kirby@sun.com>
parents: 10298
diff changeset
  4024
	if (hra->seento || !hra->seenfrom) {
108f0058f837 6833815 scheduled snapshots deleted per snapshot policy can lead to replication failures
Chris Kirby <chris.kirby@sun.com>
parents: 10298
diff changeset
  4025
		zfs_close(zhp);
108f0058f837 6833815 scheduled snapshots deleted per snapshot policy can lead to replication failures
Chris Kirby <chris.kirby@sun.com>
parents: 10298
diff changeset
  4026
		return (0);
108f0058f837 6833815 scheduled snapshots deleted per snapshot policy can lead to replication failures
Chris Kirby <chris.kirby@sun.com>
parents: 10298
diff changeset
  4027
	}
108f0058f837 6833815 scheduled snapshots deleted per snapshot policy can lead to replication failures
Chris Kirby <chris.kirby@sun.com>
parents: 10298
diff changeset
  4028
108f0058f837 6833815 scheduled snapshots deleted per snapshot policy can lead to replication failures
Chris Kirby <chris.kirby@sun.com>
parents: 10298
diff changeset
  4029
	if (hra->holding) {
11417
de9a68916900 6911611 zfs_send()'s use of snapshot holds is still racy
Chris Kirby <Chris.Kirby@sun.com>
parents: 11080
diff changeset
  4030
		/* We could be racing with destroy, so ignore ENOENT. */
10342
108f0058f837 6833815 scheduled snapshots deleted per snapshot policy can lead to replication failures
Chris Kirby <chris.kirby@sun.com>
parents: 10298
diff changeset
  4031
		error = zfs_hold(hra->origin, thissnap, hra->tag, B_FALSE,
11417
de9a68916900 6911611 zfs_send()'s use of snapshot holds is still racy
Chris Kirby <Chris.Kirby@sun.com>
parents: 11080
diff changeset
  4032
		    hra->temphold, B_TRUE);
10342
108f0058f837 6833815 scheduled snapshots deleted per snapshot policy can lead to replication failures
Chris Kirby <chris.kirby@sun.com>
parents: 10298
diff changeset
  4033
		if (error == 0) {
108f0058f837 6833815 scheduled snapshots deleted per snapshot policy can lead to replication failures
Chris Kirby <chris.kirby@sun.com>
parents: 10298
diff changeset
  4034
			(void) strlcpy(hra->lastsnapheld, zfs_get_name(zhp),
108f0058f837 6833815 scheduled snapshots deleted per snapshot policy can lead to replication failures
Chris Kirby <chris.kirby@sun.com>
parents: 10298
diff changeset
  4035
			    sizeof (hra->lastsnapheld));
108f0058f837 6833815 scheduled snapshots deleted per snapshot policy can lead to replication failures
Chris Kirby <chris.kirby@sun.com>
parents: 10298
diff changeset
  4036
		}
108f0058f837 6833815 scheduled snapshots deleted per snapshot policy can lead to replication failures
Chris Kirby <chris.kirby@sun.com>
parents: 10298
diff changeset
  4037
	} else {
108f0058f837 6833815 scheduled snapshots deleted per snapshot policy can lead to replication failures
Chris Kirby <chris.kirby@sun.com>
parents: 10298
diff changeset
  4038
		error = zfs_release(hra->origin, thissnap, hra->tag, B_FALSE);
108f0058f837 6833815 scheduled snapshots deleted per snapshot policy can lead to replication failures
Chris Kirby <chris.kirby@sun.com>
parents: 10298
diff changeset
  4039
	}
108f0058f837 6833815 scheduled snapshots deleted per snapshot policy can lead to replication failures
Chris Kirby <chris.kirby@sun.com>
parents: 10298
diff changeset
  4040
108f0058f837 6833815 scheduled snapshots deleted per snapshot policy can lead to replication failures
Chris Kirby <chris.kirby@sun.com>
parents: 10298
diff changeset
  4041
	if (!hra->seento && strcmp(hra->tosnap, thissnap) == 0)
108f0058f837 6833815 scheduled snapshots deleted per snapshot policy can lead to replication failures
Chris Kirby <chris.kirby@sun.com>
parents: 10298
diff changeset
  4042
		hra->seento = B_TRUE;
108f0058f837 6833815 scheduled snapshots deleted per snapshot policy can lead to replication failures
Chris Kirby <chris.kirby@sun.com>
parents: 10298
diff changeset
  4043
108f0058f837 6833815 scheduled snapshots deleted per snapshot policy can lead to replication failures
Chris Kirby <chris.kirby@sun.com>
parents: 10298
diff changeset
  4044
	zfs_close(zhp);
108f0058f837 6833815 scheduled snapshots deleted per snapshot policy can lead to replication failures
Chris Kirby <chris.kirby@sun.com>
parents: 10298
diff changeset
  4045
	return (error);
108f0058f837 6833815 scheduled snapshots deleted per snapshot policy can lead to replication failures
Chris Kirby <chris.kirby@sun.com>
parents: 10298
diff changeset
  4046
}
108f0058f837 6833815 scheduled snapshots deleted per snapshot policy can lead to replication failures
Chris Kirby <chris.kirby@sun.com>
parents: 10298
diff changeset
  4047
108f0058f837 6833815 scheduled snapshots deleted per snapshot policy can lead to replication failures
Chris Kirby <chris.kirby@sun.com>
parents: 10298
diff changeset
  4048
/*
108f0058f837 6833815 scheduled snapshots deleted per snapshot policy can lead to replication failures
Chris Kirby <chris.kirby@sun.com>
parents: 10298
diff changeset
  4049
 * Add a user hold on the set of snapshots starting with fromsnap up to
108f0058f837 6833815 scheduled snapshots deleted per snapshot policy can lead to replication failures
Chris Kirby <chris.kirby@sun.com>
parents: 10298
diff changeset
  4050
 * and including tosnap. If we're unable to to acquire a particular hold,
108f0058f837 6833815 scheduled snapshots deleted per snapshot policy can lead to replication failures
Chris Kirby <chris.kirby@sun.com>
parents: 10298
diff changeset
  4051
 * undo any holds up to that point.
108f0058f837 6833815 scheduled snapshots deleted per snapshot policy can lead to replication failures
Chris Kirby <chris.kirby@sun.com>
parents: 10298
diff changeset
  4052
 */
108f0058f837 6833815 scheduled snapshots deleted per snapshot policy can lead to replication failures
Chris Kirby <chris.kirby@sun.com>
parents: 10298
diff changeset
  4053
int
108f0058f837 6833815 scheduled snapshots deleted per snapshot policy can lead to replication failures
Chris Kirby <chris.kirby@sun.com>
parents: 10298
diff changeset
  4054
zfs_hold_range(zfs_handle_t *zhp, const char *fromsnap, const char *tosnap,
108f0058f837 6833815 scheduled snapshots deleted per snapshot policy can lead to replication failures
Chris Kirby <chris.kirby@sun.com>
parents: 10298
diff changeset
  4055
    const char *tag, boolean_t temphold)
108f0058f837 6833815 scheduled snapshots deleted per snapshot policy can lead to replication failures
Chris Kirby <chris.kirby@sun.com>
parents: 10298
diff changeset
  4056
{
108f0058f837 6833815 scheduled snapshots deleted per snapshot policy can lead to replication failures
Chris Kirby <chris.kirby@sun.com>
parents: 10298
diff changeset
  4057
	struct hold_range_arg arg = { 0 };
108f0058f837 6833815 scheduled snapshots deleted per snapshot policy can lead to replication failures
Chris Kirby <chris.kirby@sun.com>
parents: 10298
diff changeset
  4058
	int error;
108f0058f837 6833815 scheduled snapshots deleted per snapshot policy can lead to replication failures
Chris Kirby <chris.kirby@sun.com>
parents: 10298
diff changeset
  4059
108f0058f837 6833815 scheduled snapshots deleted per snapshot policy can lead to replication failures
Chris Kirby <chris.kirby@sun.com>
parents: 10298
diff changeset
  4060
	arg.origin = zhp;
108f0058f837 6833815 scheduled snapshots deleted per snapshot policy can lead to replication failures
Chris Kirby <chris.kirby@sun.com>
parents: 10298
diff changeset
  4061
	arg.fromsnap = fromsnap;
108f0058f837 6833815 scheduled snapshots deleted per snapshot policy can lead to replication failures
Chris Kirby <chris.kirby@sun.com>
parents: 10298
diff changeset
  4062
	arg.tosnap = tosnap;
108f0058f837 6833815 scheduled snapshots deleted per snapshot policy can lead to replication failures
Chris Kirby <chris.kirby@sun.com>
parents: 10298
diff changeset
  4063
	arg.tag = tag;
108f0058f837 6833815 scheduled snapshots deleted per snapshot policy can lead to replication failures
Chris Kirby <chris.kirby@sun.com>
parents: 10298
diff changeset
  4064
	arg.temphold = temphold;
108f0058f837 6833815 scheduled snapshots deleted per snapshot policy can lead to replication failures
Chris Kirby <chris.kirby@sun.com>
parents: 10298
diff changeset
  4065
	arg.holding = B_TRUE;
108f0058f837 6833815 scheduled snapshots deleted per snapshot policy can lead to replication failures
Chris Kirby <chris.kirby@sun.com>
parents: 10298
diff changeset
  4066
108f0058f837 6833815 scheduled snapshots deleted per snapshot policy can lead to replication failures
Chris Kirby <chris.kirby@sun.com>
parents: 10298
diff changeset
  4067
	error = zfs_iter_snapshots_sorted(zhp, zfs_hold_range_one, &arg);
108f0058f837 6833815 scheduled snapshots deleted per snapshot policy can lead to replication failures
Chris Kirby <chris.kirby@sun.com>
parents: 10298
diff changeset
  4068
108f0058f837 6833815 scheduled snapshots deleted per snapshot policy can lead to replication failures
Chris Kirby <chris.kirby@sun.com>
parents: 10298
diff changeset
  4069
	/*
108f0058f837 6833815 scheduled snapshots deleted per snapshot policy can lead to replication failures
Chris Kirby <chris.kirby@sun.com>
parents: 10298
diff changeset
  4070
	 * Make sure we either hold the entire range or none.
108f0058f837 6833815 scheduled snapshots deleted per snapshot policy can lead to replication failures
Chris Kirby <chris.kirby@sun.com>
parents: 10298
diff changeset
  4071
	 */
108f0058f837 6833815 scheduled snapshots deleted per snapshot policy can lead to replication failures
Chris Kirby <chris.kirby@sun.com>
parents: 10298
diff changeset
  4072
	if (error && arg.lastsnapheld[0] != '\0') {
108f0058f837 6833815 scheduled snapshots deleted per snapshot policy can lead to replication failures
Chris Kirby <chris.kirby@sun.com>
parents: 10298
diff changeset
  4073
		(void) zfs_release_range(zhp, fromsnap,
108f0058f837 6833815 scheduled snapshots deleted per snapshot policy can lead to replication failures
Chris Kirby <chris.kirby@sun.com>
parents: 10298
diff changeset
  4074
		    (const char *)arg.lastsnapheld, tag);
108f0058f837 6833815 scheduled snapshots deleted per snapshot policy can lead to replication failures
Chris Kirby <chris.kirby@sun.com>
parents: 10298
diff changeset
  4075
	}
108f0058f837 6833815 scheduled snapshots deleted per snapshot policy can lead to replication failures
Chris Kirby <chris.kirby@sun.com>
parents: 10298
diff changeset
  4076
	return (error);
108f0058f837 6833815 scheduled snapshots deleted per snapshot policy can lead to replication failures
Chris Kirby <chris.kirby@sun.com>
parents: 10298
diff changeset
  4077
}
108f0058f837 6833815 scheduled snapshots deleted per snapshot policy can lead to replication failures
Chris Kirby <chris.kirby@sun.com>
parents: 10298
diff changeset
  4078
10242
c40d075fbca6 PSARC/2009/297 zfs snapshot holds
Chris Kirby <chris.kirby@sun.com>
parents: 10204
diff changeset
  4079
int
c40d075fbca6 PSARC/2009/297 zfs snapshot holds
Chris Kirby <chris.kirby@sun.com>
parents: 10204
diff changeset
  4080
zfs_release(zfs_handle_t *zhp, const char *snapname, const char *tag,
c40d075fbca6 PSARC/2009/297 zfs snapshot holds
Chris Kirby <chris.kirby@sun.com>
parents: 10204
diff changeset
  4081
    boolean_t recursive)
c40d075fbca6 PSARC/2009/297 zfs snapshot holds
Chris Kirby <chris.kirby@sun.com>
parents: 10204
diff changeset
  4082
{
c40d075fbca6 PSARC/2009/297 zfs snapshot holds
Chris Kirby <chris.kirby@sun.com>
parents: 10204
diff changeset
  4083
	zfs_cmd_t zc = { 0 };
c40d075fbca6 PSARC/2009/297 zfs snapshot holds
Chris Kirby <chris.kirby@sun.com>
parents: 10204
diff changeset
  4084
	libzfs_handle_t *hdl = zhp->zfs_hdl;
c40d075fbca6 PSARC/2009/297 zfs snapshot holds
Chris Kirby <chris.kirby@sun.com>
parents: 10204
diff changeset
  4085
c40d075fbca6 PSARC/2009/297 zfs snapshot holds
Chris Kirby <chris.kirby@sun.com>
parents: 10204
diff changeset
  4086
	(void) strlcpy(zc.zc_name, zhp->zfs_name, sizeof (zc.zc_name));
c40d075fbca6 PSARC/2009/297 zfs snapshot holds
Chris Kirby <chris.kirby@sun.com>
parents: 10204
diff changeset
  4087
	(void) strlcpy(zc.zc_value, snapname, sizeof (zc.zc_value));
10342
108f0058f837 6833815 scheduled snapshots deleted per snapshot policy can lead to replication failures
Chris Kirby <chris.kirby@sun.com>
parents: 10298
diff changeset
  4088
	if (strlcpy(zc.zc_string, tag, sizeof (zc.zc_string))
108f0058f837 6833815 scheduled snapshots deleted per snapshot policy can lead to replication failures
Chris Kirby <chris.kirby@sun.com>
parents: 10298
diff changeset
  4089
	    >= sizeof (zc.zc_string))
108f0058f837 6833815 scheduled snapshots deleted per snapshot policy can lead to replication failures
Chris Kirby <chris.kirby@sun.com>
parents: 10298
diff changeset
  4090
		return (zfs_error(hdl, EZFS_TAGTOOLONG, tag));
10242
c40d075fbca6 PSARC/2009/297 zfs snapshot holds
Chris Kirby <chris.kirby@sun.com>
parents: 10204
diff changeset
  4091
	zc.zc_cookie = recursive;
c40d075fbca6 PSARC/2009/297 zfs snapshot holds
Chris Kirby <chris.kirby@sun.com>
parents: 10204
diff changeset
  4092
c40d075fbca6 PSARC/2009/297 zfs snapshot holds
Chris Kirby <chris.kirby@sun.com>
parents: 10204
diff changeset
  4093
	if (zfs_ioctl(hdl, ZFS_IOC_RELEASE, &zc) != 0) {
c40d075fbca6 PSARC/2009/297 zfs snapshot holds
Chris Kirby <chris.kirby@sun.com>
parents: 10204
diff changeset
  4094
		char errbuf[ZFS_MAXNAMELEN+32];
c40d075fbca6 PSARC/2009/297 zfs snapshot holds
Chris Kirby <chris.kirby@sun.com>
parents: 10204
diff changeset
  4095
c40d075fbca6 PSARC/2009/297 zfs snapshot holds
Chris Kirby <chris.kirby@sun.com>
parents: 10204
diff changeset
  4096
		/*
c40d075fbca6 PSARC/2009/297 zfs snapshot holds
Chris Kirby <chris.kirby@sun.com>
parents: 10204
diff changeset
  4097
		 * if it was recursive, the one that actually failed will be in
c40d075fbca6 PSARC/2009/297 zfs snapshot holds
Chris Kirby <chris.kirby@sun.com>
parents: 10204
diff changeset
  4098
		 * zc.zc_name.
c40d075fbca6 PSARC/2009/297 zfs snapshot holds
Chris Kirby <chris.kirby@sun.com>
parents: 10204
diff changeset
  4099
		 */
c40d075fbca6 PSARC/2009/297 zfs snapshot holds
Chris Kirby <chris.kirby@sun.com>
parents: 10204
diff changeset
  4100
		(void) snprintf(errbuf, sizeof (errbuf), dgettext(TEXT_DOMAIN,
c40d075fbca6 PSARC/2009/297 zfs snapshot holds
Chris Kirby <chris.kirby@sun.com>
parents: 10204
diff changeset
  4101
		    "cannot release '%s@%s'"), zc.zc_name, snapname);
c40d075fbca6 PSARC/2009/297 zfs snapshot holds
Chris Kirby <chris.kirby@sun.com>
parents: 10204
diff changeset
  4102
		switch (errno) {
c40d075fbca6 PSARC/2009/297 zfs snapshot holds
Chris Kirby <chris.kirby@sun.com>
parents: 10204
diff changeset
  4103
		case ESRCH:
c40d075fbca6 PSARC/2009/297 zfs snapshot holds
Chris Kirby <chris.kirby@sun.com>
parents: 10204
diff changeset
  4104
			return (zfs_error(hdl, EZFS_REFTAG_RELE, errbuf));
c40d075fbca6 PSARC/2009/297 zfs snapshot holds
Chris Kirby <chris.kirby@sun.com>
parents: 10204
diff changeset
  4105
		case ENOTSUP:
c40d075fbca6 PSARC/2009/297 zfs snapshot holds
Chris Kirby <chris.kirby@sun.com>
parents: 10204
diff changeset
  4106
			zfs_error_aux(hdl, dgettext(TEXT_DOMAIN,
c40d075fbca6 PSARC/2009/297 zfs snapshot holds
Chris Kirby <chris.kirby@sun.com>
parents: 10204
diff changeset
  4107
			    "pool must be upgraded"));
c40d075fbca6 PSARC/2009/297 zfs snapshot holds
Chris Kirby <chris.kirby@sun.com>
parents: 10204
diff changeset
  4108
			return (zfs_error(hdl, EZFS_BADVERSION, errbuf));
c40d075fbca6 PSARC/2009/297 zfs snapshot holds
Chris Kirby <chris.kirby@sun.com>
parents: 10204
diff changeset
  4109
		case EINVAL:
c40d075fbca6 PSARC/2009/297 zfs snapshot holds
Chris Kirby <chris.kirby@sun.com>
parents: 10204
diff changeset
  4110
			return (zfs_error(hdl, EZFS_BADTYPE, errbuf));
c40d075fbca6 PSARC/2009/297 zfs snapshot holds
Chris Kirby <chris.kirby@sun.com>
parents: 10204
diff changeset
  4111
		default:
c40d075fbca6 PSARC/2009/297 zfs snapshot holds
Chris Kirby <chris.kirby@sun.com>
parents: 10204
diff changeset
  4112
			return (zfs_standard_error_fmt(hdl, errno, errbuf));
c40d075fbca6 PSARC/2009/297 zfs snapshot holds
Chris Kirby <chris.kirby@sun.com>
parents: 10204
diff changeset
  4113
		}
c40d075fbca6 PSARC/2009/297 zfs snapshot holds
Chris Kirby <chris.kirby@sun.com>
parents: 10204
diff changeset
  4114
	}
c40d075fbca6 PSARC/2009/297 zfs snapshot holds
Chris Kirby <chris.kirby@sun.com>
parents: 10204
diff changeset
  4115
c40d075fbca6 PSARC/2009/297 zfs snapshot holds
Chris Kirby <chris.kirby@sun.com>
parents: 10204
diff changeset
  4116
	return (0);
c40d075fbca6 PSARC/2009/297 zfs snapshot holds
Chris Kirby <chris.kirby@sun.com>
parents: 10204
diff changeset
  4117
}
10342
108f0058f837 6833815 scheduled snapshots deleted per snapshot policy can lead to replication failures
Chris Kirby <chris.kirby@sun.com>
parents: 10298
diff changeset
  4118
108f0058f837 6833815 scheduled snapshots deleted per snapshot policy can lead to replication failures
Chris Kirby <chris.kirby@sun.com>
parents: 10298
diff changeset
  4119
/*
108f0058f837 6833815 scheduled snapshots deleted per snapshot policy can lead to replication failures
Chris Kirby <chris.kirby@sun.com>
parents: 10298
diff changeset
  4120
 * Release a user hold from the set of snapshots starting with fromsnap
108f0058f837 6833815 scheduled snapshots deleted per snapshot policy can lead to replication failures
Chris Kirby <chris.kirby@sun.com>
parents: 10298
diff changeset
  4121
 * up to and including tosnap.
108f0058f837 6833815 scheduled snapshots deleted per snapshot policy can lead to replication failures
Chris Kirby <chris.kirby@sun.com>
parents: 10298
diff changeset
  4122
 */
108f0058f837 6833815 scheduled snapshots deleted per snapshot policy can lead to replication failures
Chris Kirby <chris.kirby@sun.com>
parents: 10298
diff changeset
  4123
int
108f0058f837 6833815 scheduled snapshots deleted per snapshot policy can lead to replication failures
Chris Kirby <chris.kirby@sun.com>
parents: 10298
diff changeset
  4124
zfs_release_range(zfs_handle_t *zhp, const char *fromsnap, const char *tosnap,
108f0058f837 6833815 scheduled snapshots deleted per snapshot policy can lead to replication failures
Chris Kirby <chris.kirby@sun.com>
parents: 10298
diff changeset
  4125
    const char *tag)
108f0058f837 6833815 scheduled snapshots deleted per snapshot policy can lead to replication failures
Chris Kirby <chris.kirby@sun.com>
parents: 10298
diff changeset
  4126
{
108f0058f837 6833815 scheduled snapshots deleted per snapshot policy can lead to replication failures
Chris Kirby <chris.kirby@sun.com>
parents: 10298
diff changeset
  4127
	struct hold_range_arg arg = { 0 };
108f0058f837 6833815 scheduled snapshots deleted per snapshot policy can lead to replication failures
Chris Kirby <chris.kirby@sun.com>
parents: 10298
diff changeset
  4128
108f0058f837 6833815 scheduled snapshots deleted per snapshot policy can lead to replication failures
Chris Kirby <chris.kirby@sun.com>
parents: 10298
diff changeset
  4129
	arg.origin = zhp;
108f0058f837 6833815 scheduled snapshots deleted per snapshot policy can lead to replication failures
Chris Kirby <chris.kirby@sun.com>
parents: 10298
diff changeset
  4130
	arg.fromsnap = fromsnap;
108f0058f837 6833815 scheduled snapshots deleted per snapshot policy can lead to replication failures
Chris Kirby <chris.kirby@sun.com>
parents: 10298
diff changeset
  4131
	arg.tosnap = tosnap;
108f0058f837 6833815 scheduled snapshots deleted per snapshot policy can lead to replication failures
Chris Kirby <chris.kirby@sun.com>
parents: 10298
diff changeset
  4132
	arg.tag = tag;
108f0058f837 6833815 scheduled snapshots deleted per snapshot policy can lead to replication failures
Chris Kirby <chris.kirby@sun.com>
parents: 10298
diff changeset
  4133
108f0058f837 6833815 scheduled snapshots deleted per snapshot policy can lead to replication failures
Chris Kirby <chris.kirby@sun.com>
parents: 10298
diff changeset
  4134
	return (zfs_iter_snapshots_sorted(zhp, zfs_hold_range_one, &arg));
108f0058f837 6833815 scheduled snapshots deleted per snapshot policy can lead to replication failures
Chris Kirby <chris.kirby@sun.com>
parents: 10298
diff changeset
  4135
}
11449
a6be67f77b9f 6429996 zvols don't reserve enough space for requisite meta data
Eric Taylor <Eric.Taylor@Sun.COM>
parents: 11417
diff changeset
  4136
a6be67f77b9f 6429996 zvols don't reserve enough space for requisite meta data
Eric Taylor <Eric.Taylor@Sun.COM>
parents: 11417
diff changeset
  4137
uint64_t
a6be67f77b9f 6429996 zvols don't reserve enough space for requisite meta data
Eric Taylor <Eric.Taylor@Sun.COM>
parents: 11417
diff changeset
  4138
zvol_volsize_to_reservation(uint64_t volsize, nvlist_t *props)
a6be67f77b9f 6429996 zvols don't reserve enough space for requisite meta data
Eric Taylor <Eric.Taylor@Sun.COM>
parents: 11417
diff changeset
  4139
{
a6be67f77b9f 6429996 zvols don't reserve enough space for requisite meta data
Eric Taylor <Eric.Taylor@Sun.COM>
parents: 11417
diff changeset
  4140
	uint64_t numdb;
a6be67f77b9f 6429996 zvols don't reserve enough space for requisite meta data
Eric Taylor <Eric.Taylor@Sun.COM>
parents: 11417
diff changeset
  4141
	uint64_t nblocks, volblocksize;
a6be67f77b9f 6429996 zvols don't reserve enough space for requisite meta data
Eric Taylor <Eric.Taylor@Sun.COM>
parents: 11417
diff changeset
  4142
	int ncopies;
a6be67f77b9f 6429996 zvols don't reserve enough space for requisite meta data
Eric Taylor <Eric.Taylor@Sun.COM>
parents: 11417
diff changeset
  4143
	char *strval;
a6be67f77b9f 6429996 zvols don't reserve enough space for requisite meta data
Eric Taylor <Eric.Taylor@Sun.COM>
parents: 11417
diff changeset
  4144
a6be67f77b9f 6429996 zvols don't reserve enough space for requisite meta data
Eric Taylor <Eric.Taylor@Sun.COM>
parents: 11417
diff changeset
  4145
	if (nvlist_lookup_string(props,
a6be67f77b9f 6429996 zvols don't reserve enough space for requisite meta data
Eric Taylor <Eric.Taylor@Sun.COM>
parents: 11417
diff changeset
  4146
	    zfs_prop_to_name(ZFS_PROP_COPIES), &strval) == 0)
a6be67f77b9f 6429996 zvols don't reserve enough space for requisite meta data
Eric Taylor <Eric.Taylor@Sun.COM>
parents: 11417
diff changeset
  4147
		ncopies = atoi(strval);
a6be67f77b9f 6429996 zvols don't reserve enough space for requisite meta data
Eric Taylor <Eric.Taylor@Sun.COM>
parents: 11417
diff changeset
  4148
	else
a6be67f77b9f 6429996 zvols don't reserve enough space for requisite meta data
Eric Taylor <Eric.Taylor@Sun.COM>
parents: 11417
diff changeset
  4149
		ncopies = 1;
a6be67f77b9f 6429996 zvols don't reserve enough space for requisite meta data
Eric Taylor <Eric.Taylor@Sun.COM>
parents: 11417
diff changeset
  4150
	if (nvlist_lookup_uint64(props,
a6be67f77b9f 6429996 zvols don't reserve enough space for requisite meta data
Eric Taylor <Eric.Taylor@Sun.COM>
parents: 11417
diff changeset
  4151
	    zfs_prop_to_name(ZFS_PROP_VOLBLOCKSIZE),
a6be67f77b9f 6429996 zvols don't reserve enough space for requisite meta data
Eric Taylor <Eric.Taylor@Sun.COM>
parents: 11417
diff changeset
  4152
	    &volblocksize) != 0)
a6be67f77b9f 6429996 zvols don't reserve enough space for requisite meta data
Eric Taylor <Eric.Taylor@Sun.COM>
parents: 11417
diff changeset
  4153
		volblocksize = ZVOL_DEFAULT_BLOCKSIZE;
a6be67f77b9f 6429996 zvols don't reserve enough space for requisite meta data
Eric Taylor <Eric.Taylor@Sun.COM>
parents: 11417
diff changeset
  4154
	nblocks = volsize/volblocksize;
a6be67f77b9f 6429996 zvols don't reserve enough space for requisite meta data
Eric Taylor <Eric.Taylor@Sun.COM>
parents: 11417
diff changeset
  4155
	/* start with metadnode L0-L6 */
a6be67f77b9f 6429996 zvols don't reserve enough space for requisite meta data
Eric Taylor <Eric.Taylor@Sun.COM>
parents: 11417
diff changeset
  4156
	numdb = 7;
a6be67f77b9f 6429996 zvols don't reserve enough space for requisite meta data
Eric Taylor <Eric.Taylor@Sun.COM>
parents: 11417
diff changeset
  4157
	/* calculate number of indirects */
a6be67f77b9f 6429996 zvols don't reserve enough space for requisite meta data
Eric Taylor <Eric.Taylor@Sun.COM>
parents: 11417
diff changeset
  4158
	while (nblocks > 1) {
a6be67f77b9f 6429996 zvols don't reserve enough space for requisite meta data
Eric Taylor <Eric.Taylor@Sun.COM>
parents: 11417
diff changeset
  4159
		nblocks += DNODES_PER_LEVEL - 1;
a6be67f77b9f 6429996 zvols don't reserve enough space for requisite meta data
Eric Taylor <Eric.Taylor@Sun.COM>
parents: 11417
diff changeset
  4160
		nblocks /= DNODES_PER_LEVEL;
a6be67f77b9f 6429996 zvols don't reserve enough space for requisite meta data
Eric Taylor <Eric.Taylor@Sun.COM>
parents: 11417
diff changeset
  4161
		numdb += nblocks;
a6be67f77b9f 6429996 zvols don't reserve enough space for requisite meta data
Eric Taylor <Eric.Taylor@Sun.COM>
parents: 11417
diff changeset
  4162
	}
a6be67f77b9f 6429996 zvols don't reserve enough space for requisite meta data
Eric Taylor <Eric.Taylor@Sun.COM>
parents: 11417
diff changeset
  4163
	numdb *= MIN(SPA_DVAS_PER_BP, ncopies + 1);
a6be67f77b9f 6429996 zvols don't reserve enough space for requisite meta data
Eric Taylor <Eric.Taylor@Sun.COM>
parents: 11417
diff changeset
  4164
	volsize *= ncopies;
a6be67f77b9f 6429996 zvols don't reserve enough space for requisite meta data
Eric Taylor <Eric.Taylor@Sun.COM>
parents: 11417
diff changeset
  4165
	/*
a6be67f77b9f 6429996 zvols don't reserve enough space for requisite meta data
Eric Taylor <Eric.Taylor@Sun.COM>
parents: 11417
diff changeset
  4166
	 * this is exactly DN_MAX_INDBLKSHIFT when metadata isn't
a6be67f77b9f 6429996 zvols don't reserve enough space for requisite meta data
Eric Taylor <Eric.Taylor@Sun.COM>
parents: 11417
diff changeset
  4167
	 * compressed, but in practice they compress down to about
a6be67f77b9f 6429996 zvols don't reserve enough space for requisite meta data
Eric Taylor <Eric.Taylor@Sun.COM>
parents: 11417
diff changeset
  4168
	 * 1100 bytes
a6be67f77b9f 6429996 zvols don't reserve enough space for requisite meta data
Eric Taylor <Eric.Taylor@Sun.COM>
parents: 11417
diff changeset
  4169
	 */
a6be67f77b9f 6429996 zvols don't reserve enough space for requisite meta data
Eric Taylor <Eric.Taylor@Sun.COM>
parents: 11417
diff changeset
  4170
	numdb *= 1ULL << DN_MAX_INDBLKSHIFT;
a6be67f77b9f 6429996 zvols don't reserve enough space for requisite meta data
Eric Taylor <Eric.Taylor@Sun.COM>
parents: 11417
diff changeset
  4171
	volsize += numdb;
a6be67f77b9f 6429996 zvols don't reserve enough space for requisite meta data
Eric Taylor <Eric.Taylor@Sun.COM>
parents: 11417
diff changeset
  4172
	return (volsize);
a6be67f77b9f 6429996 zvols don't reserve enough space for requisite meta data
Eric Taylor <Eric.Taylor@Sun.COM>
parents: 11417
diff changeset
  4173
}