usr/src/lib/libzfs/common/libzfs_changelist.c
author Rich Morris <Richard.Morris@Sun.COM>
Wed, 10 Sep 2008 10:59:12 -0400
changeset 7538 18c2451107fd
parent 7366 33de5956afbb
child 9396 f41cf682d0d3
permissions -rw-r--r--
PSARC 2008/469 Excluding snapshot info from 'zfs list' 6734916 zfs list should omit snapshots by default 6734907 zfs list -t all would be useful once snapshots are omitted by default
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
2082
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1294
diff changeset
     5
 * Common Development and Distribution License (the "License").
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1294
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: 2676
diff changeset
    21
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    22
/*
6027
68b03551f113 6609196 'zfs destroy -r' can needlessly iterate over all filesystems in pool
rm160521
parents: 5610
diff changeset
    23
 * Copyright 2008 Sun Microsystems, Inc.  All rights reserved.
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    24
 * Use is subject to license terms.
5542
bf520ef4fd90 6428435 zfs rename failure can leave file systems unmounted.
mmusante
parents: 5473
diff changeset
    25
 *
bf520ef4fd90 6428435 zfs rename failure can leave file systems unmounted.
mmusante
parents: 5473
diff changeset
    26
 * Portions Copyright 2007 Ramprakash Jelari
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    27
 */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    28
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    29
#include <libintl.h>
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    30
#include <libuutil.h>
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    31
#include <stddef.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 <string.h>
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    34
#include <unistd.h>
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    35
#include <zone.h>
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    36
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    37
#include <libzfs.h>
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    38
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    39
#include "libzfs_impl.h"
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    40
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    41
/*
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    42
 * Structure to keep track of dataset state.  Before changing the 'sharenfs' or
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    43
 * 'mountpoint' property, we record whether the filesystem was previously
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    44
 * mounted/shared.  This prior state dictates whether we remount/reshare the
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    45
 * dataset after the property has been changed.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    46
 *
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    47
 * The interface consists of the following sequence of functions:
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    48
 *
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    49
 * 	changelist_gather()
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    50
 * 	changelist_prefix()
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    51
 * 	< change property >
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    52
 * 	changelist_postfix()
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    53
 * 	changelist_free()
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    54
 *
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    55
 * Other interfaces:
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    56
 *
1294
87b43e5de5ee 6364129 need to unmount any child datasets before doing the rollback
lling
parents: 789
diff changeset
    57
 * changelist_remove() - remove a node from a gathered list
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    58
 * changelist_rename() - renames all datasets appropriately when doing a rename
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    59
 * changelist_unshare() - unshares all the nodes in a given changelist
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    60
 * changelist_haszonedchild() - check if there is any child exported to
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    61
 *				a local zone
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    62
 */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    63
typedef struct prop_changenode {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    64
	zfs_handle_t		*cn_handle;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    65
	int			cn_shared;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    66
	int			cn_mounted;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    67
	int			cn_zoned;
5542
bf520ef4fd90 6428435 zfs rename failure can leave file systems unmounted.
mmusante
parents: 5473
diff changeset
    68
	boolean_t		cn_needpost;	/* is postfix() needed? */
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    69
	uu_list_node_t		cn_listnode;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    70
} prop_changenode_t;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    71
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    72
struct prop_changelist {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    73
	zfs_prop_t		cl_prop;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    74
	zfs_prop_t		cl_realprop;
5331
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5094
diff changeset
    75
	zfs_prop_t		cl_shareprop;  /* used with sharenfs/sharesmb */
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    76
	uu_list_pool_t		*cl_pool;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    77
	uu_list_t		*cl_list;
2082
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1294
diff changeset
    78
	boolean_t		cl_waslegacy;
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1294
diff changeset
    79
	boolean_t		cl_allchildren;
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1294
diff changeset
    80
	boolean_t		cl_alldependents;
7366
33de5956afbb 6678308 zfs receive dumps core when -n is used, fails on replication stream
Tim Haley <Tim.Haley@Sun.COM>
parents: 6168
diff changeset
    81
	int			cl_mflags;	/* Mount flags */
33de5956afbb 6678308 zfs receive dumps core when -n is used, fails on replication stream
Tim Haley <Tim.Haley@Sun.COM>
parents: 6168
diff changeset
    82
	int			cl_gflags;	/* Gather request flags */
2082
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1294
diff changeset
    83
	boolean_t		cl_haszonedchild;
2474
c001ad7e0c25 6368751 libzfs interface for mount/umounting all the file systems for a given pool
eschrock
parents: 2142
diff changeset
    84
	boolean_t		cl_sorted;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    85
};
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    86
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    87
/*
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    88
 * If the property is 'mountpoint', go through and unmount filesystems as
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    89
 * necessary.  We don't do the same for 'sharenfs', because we can just re-share
6113
700d1435ce0c 6660651 Modifying a CIFS Resource Name causes share to become available to CIFS clients by either name
dougm
parents: 6027
diff changeset
    90
 * with different options without interrupting service. We do handle 'sharesmb'
700d1435ce0c 6660651 Modifying a CIFS Resource Name causes share to become available to CIFS clients by either name
dougm
parents: 6027
diff changeset
    91
 * since there may be old resource names that need to be removed.
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    92
 */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    93
int
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    94
changelist_prefix(prop_changelist_t *clp)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    95
{
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    96
	prop_changenode_t *cn;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    97
	int ret = 0;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    98
6113
700d1435ce0c 6660651 Modifying a CIFS Resource Name causes share to become available to CIFS clients by either name
dougm
parents: 6027
diff changeset
    99
	if (clp->cl_prop != ZFS_PROP_MOUNTPOINT &&
700d1435ce0c 6660651 Modifying a CIFS Resource Name causes share to become available to CIFS clients by either name
dougm
parents: 6027
diff changeset
   100
	    clp->cl_prop != ZFS_PROP_SHARESMB)
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   101
		return (0);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   102
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   103
	for (cn = uu_list_first(clp->cl_list); cn != NULL;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   104
	    cn = uu_list_next(clp->cl_list, cn)) {
5610
8ae7d76356bb 6636423 'zfs set sharenfs=on' broken
mmusante
parents: 5542
diff changeset
   105
8ae7d76356bb 6636423 'zfs set sharenfs=on' broken
mmusante
parents: 5542
diff changeset
   106
		/* if a previous loop failed, set the remaining to false */
8ae7d76356bb 6636423 'zfs set sharenfs=on' broken
mmusante
parents: 5542
diff changeset
   107
		if (ret == -1) {
8ae7d76356bb 6636423 'zfs set sharenfs=on' broken
mmusante
parents: 5542
diff changeset
   108
			cn->cn_needpost = B_FALSE;
8ae7d76356bb 6636423 'zfs set sharenfs=on' broken
mmusante
parents: 5542
diff changeset
   109
			continue;
8ae7d76356bb 6636423 'zfs set sharenfs=on' broken
mmusante
parents: 5542
diff changeset
   110
		}
8ae7d76356bb 6636423 'zfs set sharenfs=on' broken
mmusante
parents: 5542
diff changeset
   111
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   112
		/*
3126
4f4fb617fdd0 PSARC 2006/622 iSCSI/ZFS Integration
ahl
parents: 2676
diff changeset
   113
		 * If we are in the global zone, but this dataset is exported
4f4fb617fdd0 PSARC 2006/622 iSCSI/ZFS Integration
ahl
parents: 2676
diff changeset
   114
		 * to a local zone, do nothing.
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   115
		 */
3126
4f4fb617fdd0 PSARC 2006/622 iSCSI/ZFS Integration
ahl
parents: 2676
diff changeset
   116
		if (getzoneid() == GLOBAL_ZONEID && cn->cn_zoned)
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   117
			continue;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   118
3126
4f4fb617fdd0 PSARC 2006/622 iSCSI/ZFS Integration
ahl
parents: 2676
diff changeset
   119
		if (ZFS_IS_VOLUME(cn->cn_handle)) {
4f4fb617fdd0 PSARC 2006/622 iSCSI/ZFS Integration
ahl
parents: 2676
diff changeset
   120
			switch (clp->cl_realprop) {
4f4fb617fdd0 PSARC 2006/622 iSCSI/ZFS Integration
ahl
parents: 2676
diff changeset
   121
			case ZFS_PROP_NAME:
4f4fb617fdd0 PSARC 2006/622 iSCSI/ZFS Integration
ahl
parents: 2676
diff changeset
   122
				/*
4f4fb617fdd0 PSARC 2006/622 iSCSI/ZFS Integration
ahl
parents: 2676
diff changeset
   123
				 * If this was a rename, unshare the zvol, and
4f4fb617fdd0 PSARC 2006/622 iSCSI/ZFS Integration
ahl
parents: 2676
diff changeset
   124
				 * remove the /dev/zvol links.
4f4fb617fdd0 PSARC 2006/622 iSCSI/ZFS Integration
ahl
parents: 2676
diff changeset
   125
				 */
4f4fb617fdd0 PSARC 2006/622 iSCSI/ZFS Integration
ahl
parents: 2676
diff changeset
   126
				(void) zfs_unshare_iscsi(cn->cn_handle);
4f4fb617fdd0 PSARC 2006/622 iSCSI/ZFS Integration
ahl
parents: 2676
diff changeset
   127
4f4fb617fdd0 PSARC 2006/622 iSCSI/ZFS Integration
ahl
parents: 2676
diff changeset
   128
				if (zvol_remove_link(cn->cn_handle->zfs_hdl,
5542
bf520ef4fd90 6428435 zfs rename failure can leave file systems unmounted.
mmusante
parents: 5473
diff changeset
   129
				    cn->cn_handle->zfs_name) != 0) {
3126
4f4fb617fdd0 PSARC 2006/622 iSCSI/ZFS Integration
ahl
parents: 2676
diff changeset
   130
					ret = -1;
5610
8ae7d76356bb 6636423 'zfs set sharenfs=on' broken
mmusante
parents: 5542
diff changeset
   131
					cn->cn_needpost = B_FALSE;
5542
bf520ef4fd90 6428435 zfs rename failure can leave file systems unmounted.
mmusante
parents: 5473
diff changeset
   132
					(void) zfs_share_iscsi(cn->cn_handle);
bf520ef4fd90 6428435 zfs rename failure can leave file systems unmounted.
mmusante
parents: 5473
diff changeset
   133
				}
3126
4f4fb617fdd0 PSARC 2006/622 iSCSI/ZFS Integration
ahl
parents: 2676
diff changeset
   134
				break;
4f4fb617fdd0 PSARC 2006/622 iSCSI/ZFS Integration
ahl
parents: 2676
diff changeset
   135
4f4fb617fdd0 PSARC 2006/622 iSCSI/ZFS Integration
ahl
parents: 2676
diff changeset
   136
			case ZFS_PROP_VOLSIZE:
4f4fb617fdd0 PSARC 2006/622 iSCSI/ZFS Integration
ahl
parents: 2676
diff changeset
   137
				/*
4f4fb617fdd0 PSARC 2006/622 iSCSI/ZFS Integration
ahl
parents: 2676
diff changeset
   138
				 * If this was a change to the volume size, we
4f4fb617fdd0 PSARC 2006/622 iSCSI/ZFS Integration
ahl
parents: 2676
diff changeset
   139
				 * need to unshare and reshare the volume.
4f4fb617fdd0 PSARC 2006/622 iSCSI/ZFS Integration
ahl
parents: 2676
diff changeset
   140
				 */
4f4fb617fdd0 PSARC 2006/622 iSCSI/ZFS Integration
ahl
parents: 2676
diff changeset
   141
				(void) zfs_unshare_iscsi(cn->cn_handle);
4f4fb617fdd0 PSARC 2006/622 iSCSI/ZFS Integration
ahl
parents: 2676
diff changeset
   142
				break;
4f4fb617fdd0 PSARC 2006/622 iSCSI/ZFS Integration
ahl
parents: 2676
diff changeset
   143
			}
6113
700d1435ce0c 6660651 Modifying a CIFS Resource Name causes share to become available to CIFS clients by either name
dougm
parents: 6027
diff changeset
   144
		} else {
700d1435ce0c 6660651 Modifying a CIFS Resource Name causes share to become available to CIFS clients by either name
dougm
parents: 6027
diff changeset
   145
			/*
700d1435ce0c 6660651 Modifying a CIFS Resource Name causes share to become available to CIFS clients by either name
dougm
parents: 6027
diff changeset
   146
			 * Do the property specific processing.
700d1435ce0c 6660651 Modifying a CIFS Resource Name causes share to become available to CIFS clients by either name
dougm
parents: 6027
diff changeset
   147
			 */
700d1435ce0c 6660651 Modifying a CIFS Resource Name causes share to become available to CIFS clients by either name
dougm
parents: 6027
diff changeset
   148
			switch (clp->cl_prop) {
700d1435ce0c 6660651 Modifying a CIFS Resource Name causes share to become available to CIFS clients by either name
dougm
parents: 6027
diff changeset
   149
			case ZFS_PROP_MOUNTPOINT:
700d1435ce0c 6660651 Modifying a CIFS Resource Name causes share to become available to CIFS clients by either name
dougm
parents: 6027
diff changeset
   150
				if (zfs_unmount(cn->cn_handle, NULL,
7366
33de5956afbb 6678308 zfs receive dumps core when -n is used, fails on replication stream
Tim Haley <Tim.Haley@Sun.COM>
parents: 6168
diff changeset
   151
				    clp->cl_mflags) != 0) {
6113
700d1435ce0c 6660651 Modifying a CIFS Resource Name causes share to become available to CIFS clients by either name
dougm
parents: 6027
diff changeset
   152
					ret = -1;
700d1435ce0c 6660651 Modifying a CIFS Resource Name causes share to become available to CIFS clients by either name
dougm
parents: 6027
diff changeset
   153
					cn->cn_needpost = B_FALSE;
700d1435ce0c 6660651 Modifying a CIFS Resource Name causes share to become available to CIFS clients by either name
dougm
parents: 6027
diff changeset
   154
				}
700d1435ce0c 6660651 Modifying a CIFS Resource Name causes share to become available to CIFS clients by either name
dougm
parents: 6027
diff changeset
   155
				break;
700d1435ce0c 6660651 Modifying a CIFS Resource Name causes share to become available to CIFS clients by either name
dougm
parents: 6027
diff changeset
   156
			case ZFS_PROP_SHARESMB:
700d1435ce0c 6660651 Modifying a CIFS Resource Name causes share to become available to CIFS clients by either name
dougm
parents: 6027
diff changeset
   157
				(void) zfs_unshare_smb(cn->cn_handle, NULL);
700d1435ce0c 6660651 Modifying a CIFS Resource Name causes share to become available to CIFS clients by either name
dougm
parents: 6027
diff changeset
   158
				break;
700d1435ce0c 6660651 Modifying a CIFS Resource Name causes share to become available to CIFS clients by either name
dougm
parents: 6027
diff changeset
   159
			}
4577
ed36b0e652bc PSARC/2007/328 zfs upgrade
ahrens
parents: 4302
diff changeset
   160
		}
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   161
	}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   162
5542
bf520ef4fd90 6428435 zfs rename failure can leave file systems unmounted.
mmusante
parents: 5473
diff changeset
   163
	if (ret == -1)
bf520ef4fd90 6428435 zfs rename failure can leave file systems unmounted.
mmusante
parents: 5473
diff changeset
   164
		(void) changelist_postfix(clp);
bf520ef4fd90 6428435 zfs rename failure can leave file systems unmounted.
mmusante
parents: 5473
diff changeset
   165
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   166
	return (ret);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   167
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   168
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   169
/*
3126
4f4fb617fdd0 PSARC 2006/622 iSCSI/ZFS Integration
ahl
parents: 2676
diff changeset
   170
 * If the property is 'mountpoint' or 'sharenfs', go through and remount and/or
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   171
 * reshare the filesystems as necessary.  In changelist_gather() we recorded
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   172
 * whether the filesystem was previously shared or mounted.  The action we take
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   173
 * depends on the previous state, and whether the value was previously 'legacy'.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   174
 * For non-legacy properties, we only remount/reshare the filesystem if it was
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   175
 * previously mounted/shared.  Otherwise, we always remount/reshare the
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   176
 * filesystem.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   177
 */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   178
int
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   179
changelist_postfix(prop_changelist_t *clp)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   180
{
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   181
	prop_changenode_t *cn;
3126
4f4fb617fdd0 PSARC 2006/622 iSCSI/ZFS Integration
ahl
parents: 2676
diff changeset
   182
	char shareopts[ZFS_MAXPROPLEN];
5473
fcdd1931b3aa 6590941 zfs set mountpoint should not return 0 when it fails
rm160521
parents: 5367
diff changeset
   183
	int errors = 0;
4180
30b15f0bd3c9 6491973 sharemgr: zfs set sharenfs=on is slow with lots of zfs filesystems
dougm
parents: 4074
diff changeset
   184
	libzfs_handle_t *hdl;
789
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
	 * If we're changing the mountpoint, attempt to destroy the underlying
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   188
	 * mountpoint.  All other datasets will have inherited from this dataset
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   189
	 * (in which case their mountpoints exist in the filesystem in the new
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   190
	 * location), or have explicit mountpoints set (in which case they won't
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   191
	 * be in the changelist).
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   192
	 */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   193
	if ((cn = uu_list_last(clp->cl_list)) == NULL)
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
	if (clp->cl_prop == ZFS_PROP_MOUNTPOINT)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   197
		remove_mountpoint(cn->cn_handle);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   198
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   199
	/*
4180
30b15f0bd3c9 6491973 sharemgr: zfs set sharenfs=on is slow with lots of zfs filesystems
dougm
parents: 4074
diff changeset
   200
	 * It is possible that the changelist_prefix() used libshare
30b15f0bd3c9 6491973 sharemgr: zfs set sharenfs=on is slow with lots of zfs filesystems
dougm
parents: 4074
diff changeset
   201
	 * to unshare some entries. Since libshare caches data, an
30b15f0bd3c9 6491973 sharemgr: zfs set sharenfs=on is slow with lots of zfs filesystems
dougm
parents: 4074
diff changeset
   202
	 * attempt to reshare during postfix can fail unless libshare
30b15f0bd3c9 6491973 sharemgr: zfs set sharenfs=on is slow with lots of zfs filesystems
dougm
parents: 4074
diff changeset
   203
	 * is uninitialized here so that it will reinitialize later.
30b15f0bd3c9 6491973 sharemgr: zfs set sharenfs=on is slow with lots of zfs filesystems
dougm
parents: 4074
diff changeset
   204
	 */
30b15f0bd3c9 6491973 sharemgr: zfs set sharenfs=on is slow with lots of zfs filesystems
dougm
parents: 4074
diff changeset
   205
	if (cn->cn_handle != NULL) {
4302
8e8bdcde8406 6558325 6491973 sprinkled bad cstyle in libzfs
dougm
parents: 4180
diff changeset
   206
		hdl = cn->cn_handle->zfs_hdl;
8e8bdcde8406 6558325 6491973 sprinkled bad cstyle in libzfs
dougm
parents: 4180
diff changeset
   207
		assert(hdl != NULL);
8e8bdcde8406 6558325 6491973 sprinkled bad cstyle in libzfs
dougm
parents: 4180
diff changeset
   208
		zfs_uninit_libshare(hdl);
4180
30b15f0bd3c9 6491973 sharemgr: zfs set sharenfs=on is slow with lots of zfs filesystems
dougm
parents: 4074
diff changeset
   209
	}
30b15f0bd3c9 6491973 sharemgr: zfs set sharenfs=on is slow with lots of zfs filesystems
dougm
parents: 4074
diff changeset
   210
30b15f0bd3c9 6491973 sharemgr: zfs set sharenfs=on is slow with lots of zfs filesystems
dougm
parents: 4074
diff changeset
   211
	/*
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   212
	 * We walk the datasets in reverse, because we want to mount any parent
5473
fcdd1931b3aa 6590941 zfs set mountpoint should not return 0 when it fails
rm160521
parents: 5367
diff changeset
   213
	 * datasets before mounting the children.  We walk all datasets even if
fcdd1931b3aa 6590941 zfs set mountpoint should not return 0 when it fails
rm160521
parents: 5367
diff changeset
   214
	 * there are errors.
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   215
	 */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   216
	for (cn = uu_list_last(clp->cl_list); cn != NULL;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   217
	    cn = uu_list_prev(clp->cl_list, cn)) {
4840
cb7aae35fdf7 6589962 set sharenfs=on does not work on onnv 0805 build
rm160521
parents: 4778
diff changeset
   218
cb7aae35fdf7 6589962 set sharenfs=on does not work on onnv 0805 build
rm160521
parents: 4778
diff changeset
   219
		boolean_t sharenfs;
5331
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5094
diff changeset
   220
		boolean_t sharesmb;
4840
cb7aae35fdf7 6589962 set sharenfs=on does not work on onnv 0805 build
rm160521
parents: 4778
diff changeset
   221
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   222
		/*
3126
4f4fb617fdd0 PSARC 2006/622 iSCSI/ZFS Integration
ahl
parents: 2676
diff changeset
   223
		 * If we are in the global zone, but this dataset is exported
4f4fb617fdd0 PSARC 2006/622 iSCSI/ZFS Integration
ahl
parents: 2676
diff changeset
   224
		 * to a local zone, do nothing.
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   225
		 */
3126
4f4fb617fdd0 PSARC 2006/622 iSCSI/ZFS Integration
ahl
parents: 2676
diff changeset
   226
		if (getzoneid() == GLOBAL_ZONEID && cn->cn_zoned)
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   227
			continue;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   228
5610
8ae7d76356bb 6636423 'zfs set sharenfs=on' broken
mmusante
parents: 5542
diff changeset
   229
		/* Only do post-processing if it's required */
5542
bf520ef4fd90 6428435 zfs rename failure can leave file systems unmounted.
mmusante
parents: 5473
diff changeset
   230
		if (!cn->cn_needpost)
bf520ef4fd90 6428435 zfs rename failure can leave file systems unmounted.
mmusante
parents: 5473
diff changeset
   231
			continue;
bf520ef4fd90 6428435 zfs rename failure can leave file systems unmounted.
mmusante
parents: 5473
diff changeset
   232
		cn->cn_needpost = B_FALSE;
bf520ef4fd90 6428435 zfs rename failure can leave file systems unmounted.
mmusante
parents: 5473
diff changeset
   233
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   234
		zfs_refresh_properties(cn->cn_handle);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   235
3126
4f4fb617fdd0 PSARC 2006/622 iSCSI/ZFS Integration
ahl
parents: 2676
diff changeset
   236
		if (ZFS_IS_VOLUME(cn->cn_handle)) {
4f4fb617fdd0 PSARC 2006/622 iSCSI/ZFS Integration
ahl
parents: 2676
diff changeset
   237
			/*
4f4fb617fdd0 PSARC 2006/622 iSCSI/ZFS Integration
ahl
parents: 2676
diff changeset
   238
			 * If we're doing a rename, recreate the /dev/zvol
4f4fb617fdd0 PSARC 2006/622 iSCSI/ZFS Integration
ahl
parents: 2676
diff changeset
   239
			 * links.
4f4fb617fdd0 PSARC 2006/622 iSCSI/ZFS Integration
ahl
parents: 2676
diff changeset
   240
			 */
4f4fb617fdd0 PSARC 2006/622 iSCSI/ZFS Integration
ahl
parents: 2676
diff changeset
   241
			if (clp->cl_realprop == ZFS_PROP_NAME &&
4f4fb617fdd0 PSARC 2006/622 iSCSI/ZFS Integration
ahl
parents: 2676
diff changeset
   242
			    zvol_create_link(cn->cn_handle->zfs_hdl,
4f4fb617fdd0 PSARC 2006/622 iSCSI/ZFS Integration
ahl
parents: 2676
diff changeset
   243
			    cn->cn_handle->zfs_name) != 0) {
5473
fcdd1931b3aa 6590941 zfs set mountpoint should not return 0 when it fails
rm160521
parents: 5367
diff changeset
   244
				errors++;
3126
4f4fb617fdd0 PSARC 2006/622 iSCSI/ZFS Integration
ahl
parents: 2676
diff changeset
   245
			} else if (cn->cn_shared ||
4f4fb617fdd0 PSARC 2006/622 iSCSI/ZFS Integration
ahl
parents: 2676
diff changeset
   246
			    clp->cl_prop == ZFS_PROP_SHAREISCSI) {
4f4fb617fdd0 PSARC 2006/622 iSCSI/ZFS Integration
ahl
parents: 2676
diff changeset
   247
				if (zfs_prop_get(cn->cn_handle,
4f4fb617fdd0 PSARC 2006/622 iSCSI/ZFS Integration
ahl
parents: 2676
diff changeset
   248
				    ZFS_PROP_SHAREISCSI, shareopts,
4f4fb617fdd0 PSARC 2006/622 iSCSI/ZFS Integration
ahl
parents: 2676
diff changeset
   249
				    sizeof (shareopts), NULL, NULL, 0,
4f4fb617fdd0 PSARC 2006/622 iSCSI/ZFS Integration
ahl
parents: 2676
diff changeset
   250
				    B_FALSE) == 0 &&
4f4fb617fdd0 PSARC 2006/622 iSCSI/ZFS Integration
ahl
parents: 2676
diff changeset
   251
				    strcmp(shareopts, "off") == 0) {
5473
fcdd1931b3aa 6590941 zfs set mountpoint should not return 0 when it fails
rm160521
parents: 5367
diff changeset
   252
					errors +=
fcdd1931b3aa 6590941 zfs set mountpoint should not return 0 when it fails
rm160521
parents: 5367
diff changeset
   253
					    zfs_unshare_iscsi(cn->cn_handle);
3126
4f4fb617fdd0 PSARC 2006/622 iSCSI/ZFS Integration
ahl
parents: 2676
diff changeset
   254
				} else {
5473
fcdd1931b3aa 6590941 zfs set mountpoint should not return 0 when it fails
rm160521
parents: 5367
diff changeset
   255
					errors +=
fcdd1931b3aa 6590941 zfs set mountpoint should not return 0 when it fails
rm160521
parents: 5367
diff changeset
   256
					    zfs_share_iscsi(cn->cn_handle);
3126
4f4fb617fdd0 PSARC 2006/622 iSCSI/ZFS Integration
ahl
parents: 2676
diff changeset
   257
				}
4f4fb617fdd0 PSARC 2006/622 iSCSI/ZFS Integration
ahl
parents: 2676
diff changeset
   258
			}
4f4fb617fdd0 PSARC 2006/622 iSCSI/ZFS Integration
ahl
parents: 2676
diff changeset
   259
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   260
			continue;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   261
		}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   262
4840
cb7aae35fdf7 6589962 set sharenfs=on does not work on onnv 0805 build
rm160521
parents: 4778
diff changeset
   263
		/*
cb7aae35fdf7 6589962 set sharenfs=on does not work on onnv 0805 build
rm160521
parents: 4778
diff changeset
   264
		 * Remount if previously mounted or mountpoint was legacy,
5331
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5094
diff changeset
   265
		 * or sharenfs or sharesmb  property is set.
4840
cb7aae35fdf7 6589962 set sharenfs=on does not work on onnv 0805 build
rm160521
parents: 4778
diff changeset
   266
		 */
cb7aae35fdf7 6589962 set sharenfs=on does not work on onnv 0805 build
rm160521
parents: 4778
diff changeset
   267
		sharenfs = ((zfs_prop_get(cn->cn_handle, ZFS_PROP_SHARENFS,
cb7aae35fdf7 6589962 set sharenfs=on does not work on onnv 0805 build
rm160521
parents: 4778
diff changeset
   268
		    shareopts, sizeof (shareopts), NULL, NULL, 0,
cb7aae35fdf7 6589962 set sharenfs=on does not work on onnv 0805 build
rm160521
parents: 4778
diff changeset
   269
		    B_FALSE) == 0) && (strcmp(shareopts, "off") != 0));
cb7aae35fdf7 6589962 set sharenfs=on does not work on onnv 0805 build
rm160521
parents: 4778
diff changeset
   270
5331
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5094
diff changeset
   271
		sharesmb = ((zfs_prop_get(cn->cn_handle, ZFS_PROP_SHARESMB,
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5094
diff changeset
   272
		    shareopts, sizeof (shareopts), NULL, NULL, 0,
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5094
diff changeset
   273
		    B_FALSE) == 0) && (strcmp(shareopts, "off") != 0));
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5094
diff changeset
   274
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5094
diff changeset
   275
		if ((cn->cn_mounted || clp->cl_waslegacy || sharenfs ||
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5094
diff changeset
   276
		    sharesmb) && !zfs_is_mounted(cn->cn_handle, NULL) &&
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   277
		    zfs_mount(cn->cn_handle, NULL, 0) != 0)
5473
fcdd1931b3aa 6590941 zfs set mountpoint should not return 0 when it fails
rm160521
parents: 5367
diff changeset
   278
			errors++;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   279
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   280
		/*
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   281
		 * We always re-share even if the filesystem is currently
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   282
		 * shared, so that we can adopt any new options.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   283
		 */
5473
fcdd1931b3aa 6590941 zfs set mountpoint should not return 0 when it fails
rm160521
parents: 5367
diff changeset
   284
		if (sharenfs)
fcdd1931b3aa 6590941 zfs set mountpoint should not return 0 when it fails
rm160521
parents: 5367
diff changeset
   285
			errors += zfs_share_nfs(cn->cn_handle);
fcdd1931b3aa 6590941 zfs set mountpoint should not return 0 when it fails
rm160521
parents: 5367
diff changeset
   286
		else if (cn->cn_shared || clp->cl_waslegacy)
fcdd1931b3aa 6590941 zfs set mountpoint should not return 0 when it fails
rm160521
parents: 5367
diff changeset
   287
			errors += zfs_unshare_nfs(cn->cn_handle, NULL);
fcdd1931b3aa 6590941 zfs set mountpoint should not return 0 when it fails
rm160521
parents: 5367
diff changeset
   288
		if (sharesmb)
fcdd1931b3aa 6590941 zfs set mountpoint should not return 0 when it fails
rm160521
parents: 5367
diff changeset
   289
			errors += zfs_share_smb(cn->cn_handle);
fcdd1931b3aa 6590941 zfs set mountpoint should not return 0 when it fails
rm160521
parents: 5367
diff changeset
   290
		else if (cn->cn_shared || clp->cl_waslegacy)
fcdd1931b3aa 6590941 zfs set mountpoint should not return 0 when it fails
rm160521
parents: 5367
diff changeset
   291
			errors += zfs_unshare_smb(cn->cn_handle, NULL);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   292
	}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   293
5473
fcdd1931b3aa 6590941 zfs set mountpoint should not return 0 when it fails
rm160521
parents: 5367
diff changeset
   294
	return (errors ? -1 : 0);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   295
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   296
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   297
/*
1294
87b43e5de5ee 6364129 need to unmount any child datasets before doing the rollback
lling
parents: 789
diff changeset
   298
 * Is this "dataset" a child of "parent"?
87b43e5de5ee 6364129 need to unmount any child datasets before doing the rollback
lling
parents: 789
diff changeset
   299
 */
6027
68b03551f113 6609196 'zfs destroy -r' can needlessly iterate over all filesystems in pool
rm160521
parents: 5610
diff changeset
   300
boolean_t
3841
496dd81e3d5c 6449807 'zfs rename <vol@snap>' does not re-create device link
mmusante
parents: 3126
diff changeset
   301
isa_child_of(const char *dataset, const char *parent)
1294
87b43e5de5ee 6364129 need to unmount any child datasets before doing the rollback
lling
parents: 789
diff changeset
   302
{
87b43e5de5ee 6364129 need to unmount any child datasets before doing the rollback
lling
parents: 789
diff changeset
   303
	int len;
87b43e5de5ee 6364129 need to unmount any child datasets before doing the rollback
lling
parents: 789
diff changeset
   304
87b43e5de5ee 6364129 need to unmount any child datasets before doing the rollback
lling
parents: 789
diff changeset
   305
	len = strlen(parent);
87b43e5de5ee 6364129 need to unmount any child datasets before doing the rollback
lling
parents: 789
diff changeset
   306
87b43e5de5ee 6364129 need to unmount any child datasets before doing the rollback
lling
parents: 789
diff changeset
   307
	if (strncmp(dataset, parent, len) == 0 &&
3841
496dd81e3d5c 6449807 'zfs rename <vol@snap>' does not re-create device link
mmusante
parents: 3126
diff changeset
   308
	    (dataset[len] == '@' || dataset[len] == '/' ||
496dd81e3d5c 6449807 'zfs rename <vol@snap>' does not re-create device link
mmusante
parents: 3126
diff changeset
   309
	    dataset[len] == '\0'))
2082
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1294
diff changeset
   310
		return (B_TRUE);
1294
87b43e5de5ee 6364129 need to unmount any child datasets before doing the rollback
lling
parents: 789
diff changeset
   311
	else
2082
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1294
diff changeset
   312
		return (B_FALSE);
1294
87b43e5de5ee 6364129 need to unmount any child datasets before doing the rollback
lling
parents: 789
diff changeset
   313
87b43e5de5ee 6364129 need to unmount any child datasets before doing the rollback
lling
parents: 789
diff changeset
   314
}
87b43e5de5ee 6364129 need to unmount any child datasets before doing the rollback
lling
parents: 789
diff changeset
   315
87b43e5de5ee 6364129 need to unmount any child datasets before doing the rollback
lling
parents: 789
diff changeset
   316
/*
3126
4f4fb617fdd0 PSARC 2006/622 iSCSI/ZFS Integration
ahl
parents: 2676
diff changeset
   317
 * If we rename a filesystem, child filesystem handles are no longer valid
4f4fb617fdd0 PSARC 2006/622 iSCSI/ZFS Integration
ahl
parents: 2676
diff changeset
   318
 * since we identify each dataset by its name in the ZFS namespace.  As a
4f4fb617fdd0 PSARC 2006/622 iSCSI/ZFS Integration
ahl
parents: 2676
diff changeset
   319
 * result, we have to go through and fix up all the names appropriately.  We
4f4fb617fdd0 PSARC 2006/622 iSCSI/ZFS Integration
ahl
parents: 2676
diff changeset
   320
 * could do this automatically if libzfs kept track of all open handles, but
4f4fb617fdd0 PSARC 2006/622 iSCSI/ZFS Integration
ahl
parents: 2676
diff changeset
   321
 * this is a lot less work.
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   322
 */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   323
void
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   324
changelist_rename(prop_changelist_t *clp, const char *src, const char *dst)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   325
{
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   326
	prop_changenode_t *cn;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   327
	char newname[ZFS_MAXNAMELEN];
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   328
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   329
	for (cn = uu_list_first(clp->cl_list); cn != NULL;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   330
	    cn = uu_list_next(clp->cl_list, cn)) {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   331
		/*
1294
87b43e5de5ee 6364129 need to unmount any child datasets before doing the rollback
lling
parents: 789
diff changeset
   332
		 * Do not rename a clone that's not in the source hierarchy.
87b43e5de5ee 6364129 need to unmount any child datasets before doing the rollback
lling
parents: 789
diff changeset
   333
		 */
87b43e5de5ee 6364129 need to unmount any child datasets before doing the rollback
lling
parents: 789
diff changeset
   334
		if (!isa_child_of(cn->cn_handle->zfs_name, src))
87b43e5de5ee 6364129 need to unmount any child datasets before doing the rollback
lling
parents: 789
diff changeset
   335
			continue;
87b43e5de5ee 6364129 need to unmount any child datasets before doing the rollback
lling
parents: 789
diff changeset
   336
87b43e5de5ee 6364129 need to unmount any child datasets before doing the rollback
lling
parents: 789
diff changeset
   337
		/*
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   338
		 * Destroy the previous mountpoint if needed.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   339
		 */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   340
		remove_mountpoint(cn->cn_handle);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   341
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   342
		(void) strlcpy(newname, dst, sizeof (newname));
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   343
		(void) strcat(newname, cn->cn_handle->zfs_name + strlen(src));
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   344
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   345
		(void) strlcpy(cn->cn_handle->zfs_name, newname,
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   346
		    sizeof (cn->cn_handle->zfs_name));
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   347
	}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   348
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   349
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   350
/*
5331
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5094
diff changeset
   351
 * Given a gathered changelist for the 'sharenfs' or 'sharesmb' property,
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5094
diff changeset
   352
 * unshare all the datasets in the list.
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   353
 */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   354
int
5331
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5094
diff changeset
   355
changelist_unshare(prop_changelist_t *clp, zfs_share_proto_t *proto)
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   356
{
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   357
	prop_changenode_t *cn;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   358
	int ret = 0;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   359
5331
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5094
diff changeset
   360
	if (clp->cl_prop != ZFS_PROP_SHARENFS &&
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5094
diff changeset
   361
	    clp->cl_prop != ZFS_PROP_SHARESMB)
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   362
		return (0);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   363
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   364
	for (cn = uu_list_first(clp->cl_list); cn != NULL;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   365
	    cn = uu_list_next(clp->cl_list, cn)) {
5331
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5094
diff changeset
   366
		if (zfs_unshare_proto(cn->cn_handle, NULL, proto) != 0)
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   367
			ret = -1;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   368
	}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   369
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   370
	return (ret);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   371
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   372
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   373
/*
3126
4f4fb617fdd0 PSARC 2006/622 iSCSI/ZFS Integration
ahl
parents: 2676
diff changeset
   374
 * Check if there is any child exported to a local zone in a given changelist.
4f4fb617fdd0 PSARC 2006/622 iSCSI/ZFS Integration
ahl
parents: 2676
diff changeset
   375
 * This information has already been recorded while gathering the changelist
4f4fb617fdd0 PSARC 2006/622 iSCSI/ZFS Integration
ahl
parents: 2676
diff changeset
   376
 * via changelist_gather().
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   377
 */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   378
int
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   379
changelist_haszonedchild(prop_changelist_t *clp)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   380
{
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   381
	return (clp->cl_haszonedchild);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   382
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   383
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   384
/*
1294
87b43e5de5ee 6364129 need to unmount any child datasets before doing the rollback
lling
parents: 789
diff changeset
   385
 * Remove a node from a gathered list.
87b43e5de5ee 6364129 need to unmount any child datasets before doing the rollback
lling
parents: 789
diff changeset
   386
 */
87b43e5de5ee 6364129 need to unmount any child datasets before doing the rollback
lling
parents: 789
diff changeset
   387
void
5367
c40abbe796be PSARC/2007/574 zfs send -R
ahrens
parents: 5331
diff changeset
   388
changelist_remove(prop_changelist_t *clp, const char *name)
1294
87b43e5de5ee 6364129 need to unmount any child datasets before doing the rollback
lling
parents: 789
diff changeset
   389
{
87b43e5de5ee 6364129 need to unmount any child datasets before doing the rollback
lling
parents: 789
diff changeset
   390
	prop_changenode_t *cn;
87b43e5de5ee 6364129 need to unmount any child datasets before doing the rollback
lling
parents: 789
diff changeset
   391
87b43e5de5ee 6364129 need to unmount any child datasets before doing the rollback
lling
parents: 789
diff changeset
   392
	for (cn = uu_list_first(clp->cl_list); cn != NULL;
87b43e5de5ee 6364129 need to unmount any child datasets before doing the rollback
lling
parents: 789
diff changeset
   393
	    cn = uu_list_next(clp->cl_list, cn)) {
87b43e5de5ee 6364129 need to unmount any child datasets before doing the rollback
lling
parents: 789
diff changeset
   394
5367
c40abbe796be PSARC/2007/574 zfs send -R
ahrens
parents: 5331
diff changeset
   395
		if (strcmp(cn->cn_handle->zfs_name, name) == 0) {
1294
87b43e5de5ee 6364129 need to unmount any child datasets before doing the rollback
lling
parents: 789
diff changeset
   396
			uu_list_remove(clp->cl_list, cn);
87b43e5de5ee 6364129 need to unmount any child datasets before doing the rollback
lling
parents: 789
diff changeset
   397
			zfs_close(cn->cn_handle);
87b43e5de5ee 6364129 need to unmount any child datasets before doing the rollback
lling
parents: 789
diff changeset
   398
			free(cn);
87b43e5de5ee 6364129 need to unmount any child datasets before doing the rollback
lling
parents: 789
diff changeset
   399
			return;
87b43e5de5ee 6364129 need to unmount any child datasets before doing the rollback
lling
parents: 789
diff changeset
   400
		}
87b43e5de5ee 6364129 need to unmount any child datasets before doing the rollback
lling
parents: 789
diff changeset
   401
	}
87b43e5de5ee 6364129 need to unmount any child datasets before doing the rollback
lling
parents: 789
diff changeset
   402
}
87b43e5de5ee 6364129 need to unmount any child datasets before doing the rollback
lling
parents: 789
diff changeset
   403
87b43e5de5ee 6364129 need to unmount any child datasets before doing the rollback
lling
parents: 789
diff changeset
   404
/*
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   405
 * Release any memory associated with a changelist.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   406
 */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   407
void
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   408
changelist_free(prop_changelist_t *clp)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   409
{
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   410
	prop_changenode_t *cn;
4074
58874e1ba2ef 6547185 libzfs should make use of uu_{list,avl}_teardown
eschrock
parents: 3841
diff changeset
   411
	void *cookie;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   412
2142
f6e0487aa9a3 6433264 crash when adding spare: nvlist_lookup_string(cnv, "path", &path) == 0
eschrock
parents: 2082
diff changeset
   413
	if (clp->cl_list) {
4074
58874e1ba2ef 6547185 libzfs should make use of uu_{list,avl}_teardown
eschrock
parents: 3841
diff changeset
   414
		cookie = NULL;
58874e1ba2ef 6547185 libzfs should make use of uu_{list,avl}_teardown
eschrock
parents: 3841
diff changeset
   415
		while ((cn = uu_list_teardown(clp->cl_list, &cookie)) != NULL) {
2142
f6e0487aa9a3 6433264 crash when adding spare: nvlist_lookup_string(cnv, "path", &path) == 0
eschrock
parents: 2082
diff changeset
   416
			zfs_close(cn->cn_handle);
f6e0487aa9a3 6433264 crash when adding spare: nvlist_lookup_string(cnv, "path", &path) == 0
eschrock
parents: 2082
diff changeset
   417
			free(cn);
f6e0487aa9a3 6433264 crash when adding spare: nvlist_lookup_string(cnv, "path", &path) == 0
eschrock
parents: 2082
diff changeset
   418
		}
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   419
2142
f6e0487aa9a3 6433264 crash when adding spare: nvlist_lookup_string(cnv, "path", &path) == 0
eschrock
parents: 2082
diff changeset
   420
		uu_list_destroy(clp->cl_list);
f6e0487aa9a3 6433264 crash when adding spare: nvlist_lookup_string(cnv, "path", &path) == 0
eschrock
parents: 2082
diff changeset
   421
	}
f6e0487aa9a3 6433264 crash when adding spare: nvlist_lookup_string(cnv, "path", &path) == 0
eschrock
parents: 2082
diff changeset
   422
	if (clp->cl_pool)
f6e0487aa9a3 6433264 crash when adding spare: nvlist_lookup_string(cnv, "path", &path) == 0
eschrock
parents: 2082
diff changeset
   423
		uu_list_pool_destroy(clp->cl_pool);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   424
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   425
	free(clp);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   426
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   427
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   428
static int
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   429
change_one(zfs_handle_t *zhp, void *data)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   430
{
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   431
	prop_changelist_t *clp = data;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   432
	char property[ZFS_MAXPROPLEN];
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   433
	char where[64];
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   434
	prop_changenode_t *cn;
5094
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4840
diff changeset
   435
	zprop_source_t sourcetype;
5331
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5094
diff changeset
   436
	zprop_source_t share_sourcetype;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   437
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   438
	/*
3126
4f4fb617fdd0 PSARC 2006/622 iSCSI/ZFS Integration
ahl
parents: 2676
diff changeset
   439
	 * We only want to unmount/unshare those filesystems that may inherit
4f4fb617fdd0 PSARC 2006/622 iSCSI/ZFS Integration
ahl
parents: 2676
diff changeset
   440
	 * from the target filesystem.  If we find any filesystem with a
4f4fb617fdd0 PSARC 2006/622 iSCSI/ZFS Integration
ahl
parents: 2676
diff changeset
   441
	 * locally set mountpoint, we ignore any children since changing the
4f4fb617fdd0 PSARC 2006/622 iSCSI/ZFS Integration
ahl
parents: 2676
diff changeset
   442
	 * property will not affect them.  If this is a rename, we iterate
4f4fb617fdd0 PSARC 2006/622 iSCSI/ZFS Integration
ahl
parents: 2676
diff changeset
   443
	 * over all children regardless, since we need them unmounted in
4f4fb617fdd0 PSARC 2006/622 iSCSI/ZFS Integration
ahl
parents: 2676
diff changeset
   444
	 * order to do the rename.  Also, if this is a volume and we're doing
4f4fb617fdd0 PSARC 2006/622 iSCSI/ZFS Integration
ahl
parents: 2676
diff changeset
   445
	 * a rename, then always add it to the changelist.
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   446
	 */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   447
2676
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2474
diff changeset
   448
	if (!(ZFS_IS_VOLUME(zhp) && clp->cl_realprop == ZFS_PROP_NAME) &&
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   449
	    zfs_prop_get(zhp, clp->cl_prop, property,
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   450
	    sizeof (property), &sourcetype, where, sizeof (where),
2082
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1294
diff changeset
   451
	    B_FALSE) != 0) {
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1294
diff changeset
   452
		zfs_close(zhp);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   453
		return (0);
2082
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1294
diff changeset
   454
	}
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   455
5331
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5094
diff changeset
   456
	/*
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5094
diff changeset
   457
	 * If we are "watching" sharenfs or sharesmb
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5094
diff changeset
   458
	 * then check out the companion property which is tracked
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5094
diff changeset
   459
	 * in cl_shareprop
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5094
diff changeset
   460
	 */
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5094
diff changeset
   461
	if (clp->cl_shareprop != ZPROP_INVAL &&
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5094
diff changeset
   462
	    zfs_prop_get(zhp, clp->cl_shareprop, property,
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5094
diff changeset
   463
	    sizeof (property), &share_sourcetype, where, sizeof (where),
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5094
diff changeset
   464
	    B_FALSE) != 0) {
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5094
diff changeset
   465
		zfs_close(zhp);
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5094
diff changeset
   466
		return (0);
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5094
diff changeset
   467
	}
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5094
diff changeset
   468
1294
87b43e5de5ee 6364129 need to unmount any child datasets before doing the rollback
lling
parents: 789
diff changeset
   469
	if (clp->cl_alldependents || clp->cl_allchildren ||
5094
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4840
diff changeset
   470
	    sourcetype == ZPROP_SRC_DEFAULT ||
5331
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5094
diff changeset
   471
	    sourcetype == ZPROP_SRC_INHERITED ||
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5094
diff changeset
   472
	    (clp->cl_shareprop != ZPROP_INVAL &&
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5094
diff changeset
   473
	    (share_sourcetype == ZPROP_SRC_DEFAULT ||
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5094
diff changeset
   474
	    share_sourcetype == ZPROP_SRC_INHERITED))) {
2082
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1294
diff changeset
   475
		if ((cn = zfs_alloc(zfs_get_handle(zhp),
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1294
diff changeset
   476
		    sizeof (prop_changenode_t))) == NULL) {
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1294
diff changeset
   477
			zfs_close(zhp);
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1294
diff changeset
   478
			return (-1);
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1294
diff changeset
   479
		}
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   480
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   481
		cn->cn_handle = zhp;
7366
33de5956afbb 6678308 zfs receive dumps core when -n is used, fails on replication stream
Tim Haley <Tim.Haley@Sun.COM>
parents: 6168
diff changeset
   482
		cn->cn_mounted = (clp->cl_gflags & CL_GATHER_MOUNT_ALWAYS) ||
33de5956afbb 6678308 zfs receive dumps core when -n is used, fails on replication stream
Tim Haley <Tim.Haley@Sun.COM>
parents: 6168
diff changeset
   483
		    zfs_is_mounted(zhp, NULL);
3126
4f4fb617fdd0 PSARC 2006/622 iSCSI/ZFS Integration
ahl
parents: 2676
diff changeset
   484
		cn->cn_shared = zfs_is_shared(zhp);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   485
		cn->cn_zoned = zfs_prop_get_int(zhp, ZFS_PROP_ZONED);
5610
8ae7d76356bb 6636423 'zfs set sharenfs=on' broken
mmusante
parents: 5542
diff changeset
   486
		cn->cn_needpost = B_TRUE;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   487
3126
4f4fb617fdd0 PSARC 2006/622 iSCSI/ZFS Integration
ahl
parents: 2676
diff changeset
   488
		/* Indicate if any child is exported to a local zone. */
4f4fb617fdd0 PSARC 2006/622 iSCSI/ZFS Integration
ahl
parents: 2676
diff changeset
   489
		if (getzoneid() == GLOBAL_ZONEID && cn->cn_zoned)
2082
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1294
diff changeset
   490
			clp->cl_haszonedchild = B_TRUE;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   491
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   492
		uu_list_node_init(cn, &cn->cn_listnode, clp->cl_pool);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   493
2474
c001ad7e0c25 6368751 libzfs interface for mount/umounting all the file systems for a given pool
eschrock
parents: 2142
diff changeset
   494
		if (clp->cl_sorted) {
c001ad7e0c25 6368751 libzfs interface for mount/umounting all the file systems for a given pool
eschrock
parents: 2142
diff changeset
   495
			uu_list_index_t idx;
c001ad7e0c25 6368751 libzfs interface for mount/umounting all the file systems for a given pool
eschrock
parents: 2142
diff changeset
   496
c001ad7e0c25 6368751 libzfs interface for mount/umounting all the file systems for a given pool
eschrock
parents: 2142
diff changeset
   497
			(void) uu_list_find(clp->cl_list, cn, NULL,
c001ad7e0c25 6368751 libzfs interface for mount/umounting all the file systems for a given pool
eschrock
parents: 2142
diff changeset
   498
			    &idx);
c001ad7e0c25 6368751 libzfs interface for mount/umounting all the file systems for a given pool
eschrock
parents: 2142
diff changeset
   499
			uu_list_insert(clp->cl_list, cn, idx);
1294
87b43e5de5ee 6364129 need to unmount any child datasets before doing the rollback
lling
parents: 789
diff changeset
   500
		} else {
2474
c001ad7e0c25 6368751 libzfs interface for mount/umounting all the file systems for a given pool
eschrock
parents: 2142
diff changeset
   501
			ASSERT(!clp->cl_alldependents);
1294
87b43e5de5ee 6364129 need to unmount any child datasets before doing the rollback
lling
parents: 789
diff changeset
   502
			verify(uu_list_insert_before(clp->cl_list,
4074
58874e1ba2ef 6547185 libzfs should make use of uu_{list,avl}_teardown
eschrock
parents: 3841
diff changeset
   503
			    uu_list_first(clp->cl_list), cn) == 0);
2474
c001ad7e0c25 6368751 libzfs interface for mount/umounting all the file systems for a given pool
eschrock
parents: 2142
diff changeset
   504
		}
c001ad7e0c25 6368751 libzfs interface for mount/umounting all the file systems for a given pool
eschrock
parents: 2142
diff changeset
   505
c001ad7e0c25 6368751 libzfs interface for mount/umounting all the file systems for a given pool
eschrock
parents: 2142
diff changeset
   506
		if (!clp->cl_alldependents)
1294
87b43e5de5ee 6364129 need to unmount any child datasets before doing the rollback
lling
parents: 789
diff changeset
   507
			return (zfs_iter_children(zhp, change_one, data));
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   508
	} else {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   509
		zfs_close(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
	return (0);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   513
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   514
2474
c001ad7e0c25 6368751 libzfs interface for mount/umounting all the file systems for a given pool
eschrock
parents: 2142
diff changeset
   515
/*ARGSUSED*/
c001ad7e0c25 6368751 libzfs interface for mount/umounting all the file systems for a given pool
eschrock
parents: 2142
diff changeset
   516
static int
c001ad7e0c25 6368751 libzfs interface for mount/umounting all the file systems for a given pool
eschrock
parents: 2142
diff changeset
   517
compare_mountpoints(const void *a, const void *b, void *unused)
c001ad7e0c25 6368751 libzfs interface for mount/umounting all the file systems for a given pool
eschrock
parents: 2142
diff changeset
   518
{
c001ad7e0c25 6368751 libzfs interface for mount/umounting all the file systems for a given pool
eschrock
parents: 2142
diff changeset
   519
	const prop_changenode_t *ca = a;
c001ad7e0c25 6368751 libzfs interface for mount/umounting all the file systems for a given pool
eschrock
parents: 2142
diff changeset
   520
	const prop_changenode_t *cb = b;
c001ad7e0c25 6368751 libzfs interface for mount/umounting all the file systems for a given pool
eschrock
parents: 2142
diff changeset
   521
c001ad7e0c25 6368751 libzfs interface for mount/umounting all the file systems for a given pool
eschrock
parents: 2142
diff changeset
   522
	char mounta[MAXPATHLEN];
c001ad7e0c25 6368751 libzfs interface for mount/umounting all the file systems for a given pool
eschrock
parents: 2142
diff changeset
   523
	char mountb[MAXPATHLEN];
c001ad7e0c25 6368751 libzfs interface for mount/umounting all the file systems for a given pool
eschrock
parents: 2142
diff changeset
   524
c001ad7e0c25 6368751 libzfs interface for mount/umounting all the file systems for a given pool
eschrock
parents: 2142
diff changeset
   525
	boolean_t hasmounta, hasmountb;
c001ad7e0c25 6368751 libzfs interface for mount/umounting all the file systems for a given pool
eschrock
parents: 2142
diff changeset
   526
c001ad7e0c25 6368751 libzfs interface for mount/umounting all the file systems for a given pool
eschrock
parents: 2142
diff changeset
   527
	/*
c001ad7e0c25 6368751 libzfs interface for mount/umounting all the file systems for a given pool
eschrock
parents: 2142
diff changeset
   528
	 * When unsharing or unmounting filesystems, we need to do it in
c001ad7e0c25 6368751 libzfs interface for mount/umounting all the file systems for a given pool
eschrock
parents: 2142
diff changeset
   529
	 * mountpoint order.  This allows the user to have a mountpoint
c001ad7e0c25 6368751 libzfs interface for mount/umounting all the file systems for a given pool
eschrock
parents: 2142
diff changeset
   530
	 * hierarchy that is different from the dataset hierarchy, and still
c001ad7e0c25 6368751 libzfs interface for mount/umounting all the file systems for a given pool
eschrock
parents: 2142
diff changeset
   531
	 * allow it to be changed.  However, if either dataset doesn't have a
c001ad7e0c25 6368751 libzfs interface for mount/umounting all the file systems for a given pool
eschrock
parents: 2142
diff changeset
   532
	 * mountpoint (because it is a volume or a snapshot), we place it at the
c001ad7e0c25 6368751 libzfs interface for mount/umounting all the file systems for a given pool
eschrock
parents: 2142
diff changeset
   533
	 * end of the list, because it doesn't affect our change at all.
c001ad7e0c25 6368751 libzfs interface for mount/umounting all the file systems for a given pool
eschrock
parents: 2142
diff changeset
   534
	 */
c001ad7e0c25 6368751 libzfs interface for mount/umounting all the file systems for a given pool
eschrock
parents: 2142
diff changeset
   535
	hasmounta = (zfs_prop_get(ca->cn_handle, ZFS_PROP_MOUNTPOINT, mounta,
c001ad7e0c25 6368751 libzfs interface for mount/umounting all the file systems for a given pool
eschrock
parents: 2142
diff changeset
   536
	    sizeof (mounta), NULL, NULL, 0, B_FALSE) == 0);
c001ad7e0c25 6368751 libzfs interface for mount/umounting all the file systems for a given pool
eschrock
parents: 2142
diff changeset
   537
	hasmountb = (zfs_prop_get(cb->cn_handle, ZFS_PROP_MOUNTPOINT, mountb,
c001ad7e0c25 6368751 libzfs interface for mount/umounting all the file systems for a given pool
eschrock
parents: 2142
diff changeset
   538
	    sizeof (mountb), NULL, NULL, 0, B_FALSE) == 0);
c001ad7e0c25 6368751 libzfs interface for mount/umounting all the file systems for a given pool
eschrock
parents: 2142
diff changeset
   539
c001ad7e0c25 6368751 libzfs interface for mount/umounting all the file systems for a given pool
eschrock
parents: 2142
diff changeset
   540
	if (!hasmounta && hasmountb)
c001ad7e0c25 6368751 libzfs interface for mount/umounting all the file systems for a given pool
eschrock
parents: 2142
diff changeset
   541
		return (-1);
c001ad7e0c25 6368751 libzfs interface for mount/umounting all the file systems for a given pool
eschrock
parents: 2142
diff changeset
   542
	else if (hasmounta && !hasmountb)
c001ad7e0c25 6368751 libzfs interface for mount/umounting all the file systems for a given pool
eschrock
parents: 2142
diff changeset
   543
		return (1);
c001ad7e0c25 6368751 libzfs interface for mount/umounting all the file systems for a given pool
eschrock
parents: 2142
diff changeset
   544
	else if (!hasmounta && !hasmountb)
c001ad7e0c25 6368751 libzfs interface for mount/umounting all the file systems for a given pool
eschrock
parents: 2142
diff changeset
   545
		return (0);
c001ad7e0c25 6368751 libzfs interface for mount/umounting all the file systems for a given pool
eschrock
parents: 2142
diff changeset
   546
	else
c001ad7e0c25 6368751 libzfs interface for mount/umounting all the file systems for a given pool
eschrock
parents: 2142
diff changeset
   547
		return (strcmp(mountb, mounta));
c001ad7e0c25 6368751 libzfs interface for mount/umounting all the file systems for a given pool
eschrock
parents: 2142
diff changeset
   548
}
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   549
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   550
/*
3126
4f4fb617fdd0 PSARC 2006/622 iSCSI/ZFS Integration
ahl
parents: 2676
diff changeset
   551
 * Given a ZFS handle and a property, construct a complete list of datasets
4f4fb617fdd0 PSARC 2006/622 iSCSI/ZFS Integration
ahl
parents: 2676
diff changeset
   552
 * that need to be modified as part of this process.  For anything but the
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   553
 * 'mountpoint' and 'sharenfs' properties, this just returns an empty list.
3126
4f4fb617fdd0 PSARC 2006/622 iSCSI/ZFS Integration
ahl
parents: 2676
diff changeset
   554
 * Otherwise, we iterate over all children and look for any datasets that
4f4fb617fdd0 PSARC 2006/622 iSCSI/ZFS Integration
ahl
parents: 2676
diff changeset
   555
 * inherit the property.  For each such dataset, we add it to the list and
4f4fb617fdd0 PSARC 2006/622 iSCSI/ZFS Integration
ahl
parents: 2676
diff changeset
   556
 * mark whether it was shared beforehand.
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   557
 */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   558
prop_changelist_t *
7366
33de5956afbb 6678308 zfs receive dumps core when -n is used, fails on replication stream
Tim Haley <Tim.Haley@Sun.COM>
parents: 6168
diff changeset
   559
changelist_gather(zfs_handle_t *zhp, zfs_prop_t prop, int gather_flags,
33de5956afbb 6678308 zfs receive dumps core when -n is used, fails on replication stream
Tim Haley <Tim.Haley@Sun.COM>
parents: 6168
diff changeset
   560
    int mnt_flags)
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   561
{
2082
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1294
diff changeset
   562
	prop_changelist_t *clp;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   563
	prop_changenode_t *cn;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   564
	zfs_handle_t *temp;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   565
	char property[ZFS_MAXPROPLEN];
2474
c001ad7e0c25 6368751 libzfs interface for mount/umounting all the file systems for a given pool
eschrock
parents: 2142
diff changeset
   566
	uu_compare_fn_t *compare = NULL;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   567
2082
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1294
diff changeset
   568
	if ((clp = zfs_alloc(zhp->zfs_hdl, sizeof (prop_changelist_t))) == NULL)
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1294
diff changeset
   569
		return (NULL);
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1294
diff changeset
   570
2474
c001ad7e0c25 6368751 libzfs interface for mount/umounting all the file systems for a given pool
eschrock
parents: 2142
diff changeset
   571
	/*
c001ad7e0c25 6368751 libzfs interface for mount/umounting all the file systems for a given pool
eschrock
parents: 2142
diff changeset
   572
	 * For mountpoint-related tasks, we want to sort everything by
c001ad7e0c25 6368751 libzfs interface for mount/umounting all the file systems for a given pool
eschrock
parents: 2142
diff changeset
   573
	 * mountpoint, so that we mount and unmount them in the appropriate
c001ad7e0c25 6368751 libzfs interface for mount/umounting all the file systems for a given pool
eschrock
parents: 2142
diff changeset
   574
	 * order, regardless of their position in the hierarchy.
c001ad7e0c25 6368751 libzfs interface for mount/umounting all the file systems for a given pool
eschrock
parents: 2142
diff changeset
   575
	 */
c001ad7e0c25 6368751 libzfs interface for mount/umounting all the file systems for a given pool
eschrock
parents: 2142
diff changeset
   576
	if (prop == ZFS_PROP_NAME || prop == ZFS_PROP_ZONED ||
5331
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5094
diff changeset
   577
	    prop == ZFS_PROP_MOUNTPOINT || prop == ZFS_PROP_SHARENFS ||
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5094
diff changeset
   578
	    prop == ZFS_PROP_SHARESMB) {
2474
c001ad7e0c25 6368751 libzfs interface for mount/umounting all the file systems for a given pool
eschrock
parents: 2142
diff changeset
   579
		compare = compare_mountpoints;
c001ad7e0c25 6368751 libzfs interface for mount/umounting all the file systems for a given pool
eschrock
parents: 2142
diff changeset
   580
		clp->cl_sorted = B_TRUE;
c001ad7e0c25 6368751 libzfs interface for mount/umounting all the file systems for a given pool
eschrock
parents: 2142
diff changeset
   581
	}
c001ad7e0c25 6368751 libzfs interface for mount/umounting all the file systems for a given pool
eschrock
parents: 2142
diff changeset
   582
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   583
	clp->cl_pool = uu_list_pool_create("changelist_pool",
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   584
	    sizeof (prop_changenode_t),
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   585
	    offsetof(prop_changenode_t, cn_listnode),
2474
c001ad7e0c25 6368751 libzfs interface for mount/umounting all the file systems for a given pool
eschrock
parents: 2142
diff changeset
   586
	    compare, 0);
2142
f6e0487aa9a3 6433264 crash when adding spare: nvlist_lookup_string(cnv, "path", &path) == 0
eschrock
parents: 2082
diff changeset
   587
	if (clp->cl_pool == NULL) {
f6e0487aa9a3 6433264 crash when adding spare: nvlist_lookup_string(cnv, "path", &path) == 0
eschrock
parents: 2082
diff changeset
   588
		assert(uu_error() == UU_ERROR_NO_MEMORY);
f6e0487aa9a3 6433264 crash when adding spare: nvlist_lookup_string(cnv, "path", &path) == 0
eschrock
parents: 2082
diff changeset
   589
		(void) zfs_error(zhp->zfs_hdl, EZFS_NOMEM, "internal error");
f6e0487aa9a3 6433264 crash when adding spare: nvlist_lookup_string(cnv, "path", &path) == 0
eschrock
parents: 2082
diff changeset
   590
		changelist_free(clp);
f6e0487aa9a3 6433264 crash when adding spare: nvlist_lookup_string(cnv, "path", &path) == 0
eschrock
parents: 2082
diff changeset
   591
		return (NULL);
f6e0487aa9a3 6433264 crash when adding spare: nvlist_lookup_string(cnv, "path", &path) == 0
eschrock
parents: 2082
diff changeset
   592
	}
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   593
2474
c001ad7e0c25 6368751 libzfs interface for mount/umounting all the file systems for a given pool
eschrock
parents: 2142
diff changeset
   594
	clp->cl_list = uu_list_create(clp->cl_pool, NULL,
c001ad7e0c25 6368751 libzfs interface for mount/umounting all the file systems for a given pool
eschrock
parents: 2142
diff changeset
   595
	    clp->cl_sorted ? UU_LIST_SORTED : 0);
7366
33de5956afbb 6678308 zfs receive dumps core when -n is used, fails on replication stream
Tim Haley <Tim.Haley@Sun.COM>
parents: 6168
diff changeset
   596
	clp->cl_gflags = gather_flags;
33de5956afbb 6678308 zfs receive dumps core when -n is used, fails on replication stream
Tim Haley <Tim.Haley@Sun.COM>
parents: 6168
diff changeset
   597
	clp->cl_mflags = mnt_flags;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   598
2142
f6e0487aa9a3 6433264 crash when adding spare: nvlist_lookup_string(cnv, "path", &path) == 0
eschrock
parents: 2082
diff changeset
   599
	if (clp->cl_list == NULL) {
f6e0487aa9a3 6433264 crash when adding spare: nvlist_lookup_string(cnv, "path", &path) == 0
eschrock
parents: 2082
diff changeset
   600
		assert(uu_error() == UU_ERROR_NO_MEMORY);
f6e0487aa9a3 6433264 crash when adding spare: nvlist_lookup_string(cnv, "path", &path) == 0
eschrock
parents: 2082
diff changeset
   601
		(void) zfs_error(zhp->zfs_hdl, EZFS_NOMEM, "internal error");
f6e0487aa9a3 6433264 crash when adding spare: nvlist_lookup_string(cnv, "path", &path) == 0
eschrock
parents: 2082
diff changeset
   602
		changelist_free(clp);
f6e0487aa9a3 6433264 crash when adding spare: nvlist_lookup_string(cnv, "path", &path) == 0
eschrock
parents: 2082
diff changeset
   603
		return (NULL);
f6e0487aa9a3 6433264 crash when adding spare: nvlist_lookup_string(cnv, "path", &path) == 0
eschrock
parents: 2082
diff changeset
   604
	}
f6e0487aa9a3 6433264 crash when adding spare: nvlist_lookup_string(cnv, "path", &path) == 0
eschrock
parents: 2082
diff changeset
   605
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   606
	/*
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   607
	 * If this is a rename or the 'zoned' property, we pretend we're
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   608
	 * changing the mountpoint and flag it so we can catch all children in
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   609
	 * change_one().
1294
87b43e5de5ee 6364129 need to unmount any child datasets before doing the rollback
lling
parents: 789
diff changeset
   610
	 *
3126
4f4fb617fdd0 PSARC 2006/622 iSCSI/ZFS Integration
ahl
parents: 2676
diff changeset
   611
	 * Flag cl_alldependents to catch all children plus the dependents
4f4fb617fdd0 PSARC 2006/622 iSCSI/ZFS Integration
ahl
parents: 2676
diff changeset
   612
	 * (clones) that are not in the hierarchy.
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   613
	 */
1294
87b43e5de5ee 6364129 need to unmount any child datasets before doing the rollback
lling
parents: 789
diff changeset
   614
	if (prop == ZFS_PROP_NAME) {
87b43e5de5ee 6364129 need to unmount any child datasets before doing the rollback
lling
parents: 789
diff changeset
   615
		clp->cl_prop = ZFS_PROP_MOUNTPOINT;
2082
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1294
diff changeset
   616
		clp->cl_alldependents = B_TRUE;
1294
87b43e5de5ee 6364129 need to unmount any child datasets before doing the rollback
lling
parents: 789
diff changeset
   617
	} else if (prop == ZFS_PROP_ZONED) {
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   618
		clp->cl_prop = ZFS_PROP_MOUNTPOINT;
2082
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1294
diff changeset
   619
		clp->cl_allchildren = B_TRUE;
2676
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2474
diff changeset
   620
	} else if (prop == ZFS_PROP_CANMOUNT) {
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2474
diff changeset
   621
		clp->cl_prop = ZFS_PROP_MOUNTPOINT;
3126
4f4fb617fdd0 PSARC 2006/622 iSCSI/ZFS Integration
ahl
parents: 2676
diff changeset
   622
	} else if (prop == ZFS_PROP_VOLSIZE) {
4f4fb617fdd0 PSARC 2006/622 iSCSI/ZFS Integration
ahl
parents: 2676
diff changeset
   623
		clp->cl_prop = ZFS_PROP_MOUNTPOINT;
4577
ed36b0e652bc PSARC/2007/328 zfs upgrade
ahrens
parents: 4302
diff changeset
   624
	} else if (prop == ZFS_PROP_VERSION) {
ed36b0e652bc PSARC/2007/328 zfs upgrade
ahrens
parents: 4302
diff changeset
   625
		clp->cl_prop = ZFS_PROP_MOUNTPOINT;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   626
	} else {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   627
		clp->cl_prop = prop;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   628
	}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   629
	clp->cl_realprop = prop;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   630
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   631
	if (clp->cl_prop != ZFS_PROP_MOUNTPOINT &&
3126
4f4fb617fdd0 PSARC 2006/622 iSCSI/ZFS Integration
ahl
parents: 2676
diff changeset
   632
	    clp->cl_prop != ZFS_PROP_SHARENFS &&
5331
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5094
diff changeset
   633
	    clp->cl_prop != ZFS_PROP_SHARESMB &&
3126
4f4fb617fdd0 PSARC 2006/622 iSCSI/ZFS Integration
ahl
parents: 2676
diff changeset
   634
	    clp->cl_prop != ZFS_PROP_SHAREISCSI)
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   635
		return (clp);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   636
5331
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5094
diff changeset
   637
	/*
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5094
diff changeset
   638
	 * If watching SHARENFS or SHARESMB then
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5094
diff changeset
   639
	 * also watch its companion property.
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5094
diff changeset
   640
	 */
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5094
diff changeset
   641
	if (clp->cl_prop == ZFS_PROP_SHARENFS)
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5094
diff changeset
   642
		clp->cl_shareprop = ZFS_PROP_SHARESMB;
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5094
diff changeset
   643
	else if (clp->cl_prop == ZFS_PROP_SHARESMB)
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5094
diff changeset
   644
		clp->cl_shareprop = ZFS_PROP_SHARENFS;
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5094
diff changeset
   645
1294
87b43e5de5ee 6364129 need to unmount any child datasets before doing the rollback
lling
parents: 789
diff changeset
   646
	if (clp->cl_alldependents) {
2474
c001ad7e0c25 6368751 libzfs interface for mount/umounting all the file systems for a given pool
eschrock
parents: 2142
diff changeset
   647
		if (zfs_iter_dependents(zhp, B_TRUE, change_one, clp) != 0) {
1294
87b43e5de5ee 6364129 need to unmount any child datasets before doing the rollback
lling
parents: 789
diff changeset
   648
			changelist_free(clp);
87b43e5de5ee 6364129 need to unmount any child datasets before doing the rollback
lling
parents: 789
diff changeset
   649
			return (NULL);
87b43e5de5ee 6364129 need to unmount any child datasets before doing the rollback
lling
parents: 789
diff changeset
   650
		}
87b43e5de5ee 6364129 need to unmount any child datasets before doing the rollback
lling
parents: 789
diff changeset
   651
	} else if (zfs_iter_children(zhp, change_one, clp) != 0) {
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   652
		changelist_free(clp);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   653
		return (NULL);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   654
	}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   655
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   656
	/*
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   657
	 * We have to re-open ourselves because we auto-close all the handles
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   658
	 * and can't tell the difference.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   659
	 */
2082
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1294
diff changeset
   660
	if ((temp = zfs_open(zhp->zfs_hdl, zfs_get_name(zhp),
5094
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4840
diff changeset
   661
	    ZFS_TYPE_DATASET)) == NULL) {
2082
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1294
diff changeset
   662
		changelist_free(clp);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   663
		return (NULL);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   664
	}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   665
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   666
	/*
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   667
	 * Always add ourself to the list.  We add ourselves to the end so that
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   668
	 * we're the last to be unmounted.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   669
	 */
2082
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1294
diff changeset
   670
	if ((cn = zfs_alloc(zhp->zfs_hdl,
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1294
diff changeset
   671
	    sizeof (prop_changenode_t))) == NULL) {
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1294
diff changeset
   672
		zfs_close(temp);
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1294
diff changeset
   673
		changelist_free(clp);
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1294
diff changeset
   674
		return (NULL);
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1294
diff changeset
   675
	}
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1294
diff changeset
   676
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   677
	cn->cn_handle = temp;
7366
33de5956afbb 6678308 zfs receive dumps core when -n is used, fails on replication stream
Tim Haley <Tim.Haley@Sun.COM>
parents: 6168
diff changeset
   678
	cn->cn_mounted = (clp->cl_gflags & CL_GATHER_MOUNT_ALWAYS) ||
33de5956afbb 6678308 zfs receive dumps core when -n is used, fails on replication stream
Tim Haley <Tim.Haley@Sun.COM>
parents: 6168
diff changeset
   679
	    zfs_is_mounted(temp, NULL);
3126
4f4fb617fdd0 PSARC 2006/622 iSCSI/ZFS Integration
ahl
parents: 2676
diff changeset
   680
	cn->cn_shared = zfs_is_shared(temp);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   681
	cn->cn_zoned = zfs_prop_get_int(zhp, ZFS_PROP_ZONED);
5610
8ae7d76356bb 6636423 'zfs set sharenfs=on' broken
mmusante
parents: 5542
diff changeset
   682
	cn->cn_needpost = B_TRUE;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   683
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   684
	uu_list_node_init(cn, &cn->cn_listnode, clp->cl_pool);
2474
c001ad7e0c25 6368751 libzfs interface for mount/umounting all the file systems for a given pool
eschrock
parents: 2142
diff changeset
   685
	if (clp->cl_sorted) {
c001ad7e0c25 6368751 libzfs interface for mount/umounting all the file systems for a given pool
eschrock
parents: 2142
diff changeset
   686
		uu_list_index_t idx;
c001ad7e0c25 6368751 libzfs interface for mount/umounting all the file systems for a given pool
eschrock
parents: 2142
diff changeset
   687
		(void) uu_list_find(clp->cl_list, cn, NULL, &idx);
c001ad7e0c25 6368751 libzfs interface for mount/umounting all the file systems for a given pool
eschrock
parents: 2142
diff changeset
   688
		uu_list_insert(clp->cl_list, cn, idx);
c001ad7e0c25 6368751 libzfs interface for mount/umounting all the file systems for a given pool
eschrock
parents: 2142
diff changeset
   689
	} else {
c001ad7e0c25 6368751 libzfs interface for mount/umounting all the file systems for a given pool
eschrock
parents: 2142
diff changeset
   690
		verify(uu_list_insert_after(clp->cl_list,
c001ad7e0c25 6368751 libzfs interface for mount/umounting all the file systems for a given pool
eschrock
parents: 2142
diff changeset
   691
		    uu_list_last(clp->cl_list), cn) == 0);
c001ad7e0c25 6368751 libzfs interface for mount/umounting all the file systems for a given pool
eschrock
parents: 2142
diff changeset
   692
	}
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   693
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   694
	/*
4840
cb7aae35fdf7 6589962 set sharenfs=on does not work on onnv 0805 build
rm160521
parents: 4778
diff changeset
   695
	 * If the mountpoint property was previously 'legacy', or 'none',
cb7aae35fdf7 6589962 set sharenfs=on does not work on onnv 0805 build
rm160521
parents: 4778
diff changeset
   696
	 * record it as the behavior of changelist_postfix() will be different.
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   697
	 */
4840
cb7aae35fdf7 6589962 set sharenfs=on does not work on onnv 0805 build
rm160521
parents: 4778
diff changeset
   698
	if ((clp->cl_prop == ZFS_PROP_MOUNTPOINT) &&
cb7aae35fdf7 6589962 set sharenfs=on does not work on onnv 0805 build
rm160521
parents: 4778
diff changeset
   699
	    (zfs_prop_get(zhp, prop, property, sizeof (property),
2082
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1294
diff changeset
   700
	    NULL, NULL, 0, B_FALSE) == 0 &&
6168
51c045dcc498 PSARC 2008/168 Support for ZFS property value canmount=noauto
hs24103
parents: 6113
diff changeset
   701
	    (strcmp(property, "legacy") == 0 ||
51c045dcc498 PSARC 2008/168 Support for ZFS property value canmount=noauto
hs24103
parents: 6113
diff changeset
   702
	    strcmp(property, "none") == 0))) {
51c045dcc498 PSARC 2008/168 Support for ZFS property value canmount=noauto
hs24103
parents: 6113
diff changeset
   703
		/*
51c045dcc498 PSARC 2008/168 Support for ZFS property value canmount=noauto
hs24103
parents: 6113
diff changeset
   704
		 * do not automatically mount ex-legacy datasets if
51c045dcc498 PSARC 2008/168 Support for ZFS property value canmount=noauto
hs24103
parents: 6113
diff changeset
   705
		 * we specifically set canmount to noauto
51c045dcc498 PSARC 2008/168 Support for ZFS property value canmount=noauto
hs24103
parents: 6113
diff changeset
   706
		 */
51c045dcc498 PSARC 2008/168 Support for ZFS property value canmount=noauto
hs24103
parents: 6113
diff changeset
   707
		if (zfs_prop_get_int(zhp, ZFS_PROP_CANMOUNT) !=
51c045dcc498 PSARC 2008/168 Support for ZFS property value canmount=noauto
hs24103
parents: 6113
diff changeset
   708
		    ZFS_CANMOUNT_NOAUTO)
51c045dcc498 PSARC 2008/168 Support for ZFS property value canmount=noauto
hs24103
parents: 6113
diff changeset
   709
			clp->cl_waslegacy = B_TRUE;
51c045dcc498 PSARC 2008/168 Support for ZFS property value canmount=noauto
hs24103
parents: 6113
diff changeset
   710
	}
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   711
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   712
	return (clp);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   713
}