usr/src/lib/libzfs/common/libzfs_mount.c
author timh
Thu, 24 Jul 2008 15:04:31 -0700
changeset 7184 9508660f9c27
parent 6168 51c045dcc498
child 7366 33de5956afbb
permissions -rw-r--r--
PSARC 2008/223 Pool root file system properties via zpool(1M) 6647661 "set once" / "create time only" properties can't be set for pool level dataset
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: 2676
diff changeset
    21
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    22
/*
5951
c597da46efd6 6558321 zfs_share_nfs() fails the second time through
dougm
parents: 5367
diff changeset
    23
 * Copyright 2008 Sun Microsystems, Inc.  All rights reserved.
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    24
 * Use is subject to license terms.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    25
 */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    26
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    27
#pragma ident	"%Z%%M%	%I%	%E% SMI"
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    28
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    29
/*
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    30
 * Routines to manage ZFS mounts.  We separate all the nasty routines that have
3126
4f4fb617fdd0 PSARC 2006/622 iSCSI/ZFS Integration
ahl
parents: 2676
diff changeset
    31
 * to deal with the OS.  The following functions are the main entry points --
4f4fb617fdd0 PSARC 2006/622 iSCSI/ZFS Integration
ahl
parents: 2676
diff changeset
    32
 * they are used by mount and unmount and when changing a filesystem's
4f4fb617fdd0 PSARC 2006/622 iSCSI/ZFS Integration
ahl
parents: 2676
diff changeset
    33
 * mountpoint.
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    34
 *
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    35
 * 	zfs_is_mounted()
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    36
 * 	zfs_mount()
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    37
 * 	zfs_unmount()
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    38
 * 	zfs_unmountall()
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    39
 *
3126
4f4fb617fdd0 PSARC 2006/622 iSCSI/ZFS Integration
ahl
parents: 2676
diff changeset
    40
 * This file also contains the functions used to manage sharing filesystems via
4f4fb617fdd0 PSARC 2006/622 iSCSI/ZFS Integration
ahl
parents: 2676
diff changeset
    41
 * NFS and iSCSI:
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    42
 *
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    43
 * 	zfs_is_shared()
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    44
 * 	zfs_share()
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    45
 * 	zfs_unshare()
3126
4f4fb617fdd0 PSARC 2006/622 iSCSI/ZFS Integration
ahl
parents: 2676
diff changeset
    46
 *
4f4fb617fdd0 PSARC 2006/622 iSCSI/ZFS Integration
ahl
parents: 2676
diff changeset
    47
 * 	zfs_is_shared_nfs()
5331
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5094
diff changeset
    48
 * 	zfs_is_shared_smb()
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5094
diff changeset
    49
 * 	zfs_is_shared_iscsi()
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5094
diff changeset
    50
 * 	zfs_share_proto()
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5094
diff changeset
    51
 * 	zfs_shareall();
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5094
diff changeset
    52
 * 	zfs_share_iscsi()
3126
4f4fb617fdd0 PSARC 2006/622 iSCSI/ZFS Integration
ahl
parents: 2676
diff changeset
    53
 * 	zfs_unshare_nfs()
5331
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5094
diff changeset
    54
 * 	zfs_unshare_smb()
3126
4f4fb617fdd0 PSARC 2006/622 iSCSI/ZFS Integration
ahl
parents: 2676
diff changeset
    55
 * 	zfs_unshareall_nfs()
5331
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5094
diff changeset
    56
 *	zfs_unshareall_smb()
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5094
diff changeset
    57
 *	zfs_unshareall()
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5094
diff changeset
    58
 *	zfs_unshareall_bypath()
3126
4f4fb617fdd0 PSARC 2006/622 iSCSI/ZFS Integration
ahl
parents: 2676
diff changeset
    59
 * 	zfs_unshare_iscsi()
2474
c001ad7e0c25 6368751 libzfs interface for mount/umounting all the file systems for a given pool
eschrock
parents: 2082
diff changeset
    60
 *
c001ad7e0c25 6368751 libzfs interface for mount/umounting all the file systems for a given pool
eschrock
parents: 2082
diff changeset
    61
 * The following functions are available for pool consumers, and will
3126
4f4fb617fdd0 PSARC 2006/622 iSCSI/ZFS Integration
ahl
parents: 2676
diff changeset
    62
 * mount/unmount and share/unshare all datasets within pool:
2474
c001ad7e0c25 6368751 libzfs interface for mount/umounting all the file systems for a given pool
eschrock
parents: 2082
diff changeset
    63
 *
3126
4f4fb617fdd0 PSARC 2006/622 iSCSI/ZFS Integration
ahl
parents: 2676
diff changeset
    64
 * 	zpool_enable_datasets()
4f4fb617fdd0 PSARC 2006/622 iSCSI/ZFS Integration
ahl
parents: 2676
diff changeset
    65
 * 	zpool_disable_datasets()
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    66
 */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    67
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    68
#include <dirent.h>
3134
59cd24b2b5d6 6494840 libzfs should dlopen libiscsitgt rather than linking to it
ahl
parents: 3126
diff changeset
    69
#include <dlfcn.h>
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    70
#include <errno.h>
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    71
#include <libgen.h>
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    72
#include <libintl.h>
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    73
#include <stdio.h>
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    74
#include <stdlib.h>
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    75
#include <strings.h>
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    76
#include <unistd.h>
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    77
#include <zone.h>
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    78
#include <sys/mntent.h>
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    79
#include <sys/mnttab.h>
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    80
#include <sys/mount.h>
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    81
#include <sys/stat.h>
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    82
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    83
#include <libzfs.h>
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    84
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    85
#include "libzfs_impl.h"
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    86
4180
30b15f0bd3c9 6491973 sharemgr: zfs set sharenfs=on is slow with lots of zfs filesystems
dougm
parents: 3444
diff changeset
    87
#include <libshare.h>
30b15f0bd3c9 6491973 sharemgr: zfs set sharenfs=on is slow with lots of zfs filesystems
dougm
parents: 3444
diff changeset
    88
#include <sys/systeminfo.h>
30b15f0bd3c9 6491973 sharemgr: zfs set sharenfs=on is slow with lots of zfs filesystems
dougm
parents: 3444
diff changeset
    89
#define	MAXISALEN	257	/* based on sysinfo(2) man page */
30b15f0bd3c9 6491973 sharemgr: zfs set sharenfs=on is slow with lots of zfs filesystems
dougm
parents: 3444
diff changeset
    90
5331
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5094
diff changeset
    91
static int zfs_share_proto(zfs_handle_t *, zfs_share_proto_t *);
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5094
diff changeset
    92
zfs_share_type_t zfs_is_shared_proto(zfs_handle_t *, char **,
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5094
diff changeset
    93
    zfs_share_proto_t);
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5094
diff changeset
    94
3134
59cd24b2b5d6 6494840 libzfs should dlopen libiscsitgt rather than linking to it
ahl
parents: 3126
diff changeset
    95
static int (*iscsitgt_zfs_share)(const char *);
59cd24b2b5d6 6494840 libzfs should dlopen libiscsitgt rather than linking to it
ahl
parents: 3126
diff changeset
    96
static int (*iscsitgt_zfs_unshare)(const char *);
59cd24b2b5d6 6494840 libzfs should dlopen libiscsitgt rather than linking to it
ahl
parents: 3126
diff changeset
    97
static int (*iscsitgt_zfs_is_shared)(const char *);
4543
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4337
diff changeset
    98
static int (*iscsitgt_svc_online)();
3134
59cd24b2b5d6 6494840 libzfs should dlopen libiscsitgt rather than linking to it
ahl
parents: 3126
diff changeset
    99
5331
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5094
diff changeset
   100
/*
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5094
diff changeset
   101
 * The share protocols table must be in the same order as the zfs_share_prot_t
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5094
diff changeset
   102
 * enum in libzfs_impl.h
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5094
diff changeset
   103
 */
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5094
diff changeset
   104
typedef struct {
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5094
diff changeset
   105
	zfs_prop_t p_prop;
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5094
diff changeset
   106
	char *p_name;
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5094
diff changeset
   107
	int p_share_err;
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5094
diff changeset
   108
	int p_unshare_err;
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5094
diff changeset
   109
} proto_table_t;
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5094
diff changeset
   110
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5094
diff changeset
   111
proto_table_t proto_table[PROTO_END] = {
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5094
diff changeset
   112
	{ZFS_PROP_SHARENFS, "nfs", EZFS_SHARENFSFAILED, EZFS_UNSHARENFSFAILED},
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5094
diff changeset
   113
	{ZFS_PROP_SHARESMB, "smb", EZFS_SHARESMBFAILED, EZFS_UNSHARESMBFAILED},
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5094
diff changeset
   114
};
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5094
diff changeset
   115
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5094
diff changeset
   116
zfs_share_proto_t nfs_only[] = {
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5094
diff changeset
   117
	PROTO_NFS,
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5094
diff changeset
   118
	PROTO_END
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5094
diff changeset
   119
};
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5094
diff changeset
   120
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5094
diff changeset
   121
zfs_share_proto_t smb_only[] = {
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5094
diff changeset
   122
	PROTO_SMB,
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5094
diff changeset
   123
	PROTO_END
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5094
diff changeset
   124
};
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5094
diff changeset
   125
zfs_share_proto_t share_all_proto[] = {
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5094
diff changeset
   126
	PROTO_NFS,
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5094
diff changeset
   127
	PROTO_SMB,
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5094
diff changeset
   128
	PROTO_END
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5094
diff changeset
   129
};
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5094
diff changeset
   130
3134
59cd24b2b5d6 6494840 libzfs should dlopen libiscsitgt rather than linking to it
ahl
parents: 3126
diff changeset
   131
#pragma init(zfs_iscsi_init)
59cd24b2b5d6 6494840 libzfs should dlopen libiscsitgt rather than linking to it
ahl
parents: 3126
diff changeset
   132
static void
59cd24b2b5d6 6494840 libzfs should dlopen libiscsitgt rather than linking to it
ahl
parents: 3126
diff changeset
   133
zfs_iscsi_init(void)
59cd24b2b5d6 6494840 libzfs should dlopen libiscsitgt rather than linking to it
ahl
parents: 3126
diff changeset
   134
{
59cd24b2b5d6 6494840 libzfs should dlopen libiscsitgt rather than linking to it
ahl
parents: 3126
diff changeset
   135
	void *libiscsitgt;
59cd24b2b5d6 6494840 libzfs should dlopen libiscsitgt rather than linking to it
ahl
parents: 3126
diff changeset
   136
59cd24b2b5d6 6494840 libzfs should dlopen libiscsitgt rather than linking to it
ahl
parents: 3126
diff changeset
   137
	if ((libiscsitgt = dlopen("/lib/libiscsitgt.so.1",
59cd24b2b5d6 6494840 libzfs should dlopen libiscsitgt rather than linking to it
ahl
parents: 3126
diff changeset
   138
	    RTLD_LAZY | RTLD_GLOBAL)) == NULL ||
59cd24b2b5d6 6494840 libzfs should dlopen libiscsitgt rather than linking to it
ahl
parents: 3126
diff changeset
   139
	    (iscsitgt_zfs_share = (int (*)(const char *))dlsym(libiscsitgt,
59cd24b2b5d6 6494840 libzfs should dlopen libiscsitgt rather than linking to it
ahl
parents: 3126
diff changeset
   140
	    "iscsitgt_zfs_share")) == NULL ||
59cd24b2b5d6 6494840 libzfs should dlopen libiscsitgt rather than linking to it
ahl
parents: 3126
diff changeset
   141
	    (iscsitgt_zfs_unshare = (int (*)(const char *))dlsym(libiscsitgt,
59cd24b2b5d6 6494840 libzfs should dlopen libiscsitgt rather than linking to it
ahl
parents: 3126
diff changeset
   142
	    "iscsitgt_zfs_unshare")) == NULL ||
59cd24b2b5d6 6494840 libzfs should dlopen libiscsitgt rather than linking to it
ahl
parents: 3126
diff changeset
   143
	    (iscsitgt_zfs_is_shared = (int (*)(const char *))dlsym(libiscsitgt,
4543
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4337
diff changeset
   144
	    "iscsitgt_zfs_is_shared")) == NULL ||
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4337
diff changeset
   145
	    (iscsitgt_svc_online = (int (*)(const char *))dlsym(libiscsitgt,
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4337
diff changeset
   146
	    "iscsitgt_svc_online")) == NULL) {
3134
59cd24b2b5d6 6494840 libzfs should dlopen libiscsitgt rather than linking to it
ahl
parents: 3126
diff changeset
   147
		iscsitgt_zfs_share = NULL;
59cd24b2b5d6 6494840 libzfs should dlopen libiscsitgt rather than linking to it
ahl
parents: 3126
diff changeset
   148
		iscsitgt_zfs_unshare = NULL;
59cd24b2b5d6 6494840 libzfs should dlopen libiscsitgt rather than linking to it
ahl
parents: 3126
diff changeset
   149
		iscsitgt_zfs_is_shared = NULL;
4543
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4337
diff changeset
   150
		iscsitgt_svc_online = NULL;
3134
59cd24b2b5d6 6494840 libzfs should dlopen libiscsitgt rather than linking to it
ahl
parents: 3126
diff changeset
   151
	}
59cd24b2b5d6 6494840 libzfs should dlopen libiscsitgt rather than linking to it
ahl
parents: 3126
diff changeset
   152
}
59cd24b2b5d6 6494840 libzfs should dlopen libiscsitgt rather than linking to it
ahl
parents: 3126
diff changeset
   153
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   154
/*
5331
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5094
diff changeset
   155
 * Search the sharetab for the given mountpoint and protocol, returning
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5094
diff changeset
   156
 * a zfs_share_type_t value.
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   157
 */
5331
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5094
diff changeset
   158
static zfs_share_type_t
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5094
diff changeset
   159
is_shared(libzfs_handle_t *hdl, const char *mountpoint, zfs_share_proto_t proto)
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   160
{
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   161
	char buf[MAXPATHLEN], *tab;
5331
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5094
diff changeset
   162
	char *ptr;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   163
2082
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1544
diff changeset
   164
	if (hdl->libzfs_sharetab == NULL)
5331
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5094
diff changeset
   165
		return (SHARED_NOT_SHARED);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   166
2082
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1544
diff changeset
   167
	(void) fseek(hdl->libzfs_sharetab, 0, SEEK_SET);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   168
2082
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1544
diff changeset
   169
	while (fgets(buf, sizeof (buf), hdl->libzfs_sharetab) != NULL) {
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   170
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   171
		/* the mountpoint is the first entry on each line */
5331
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5094
diff changeset
   172
		if ((tab = strchr(buf, '\t')) == NULL)
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5094
diff changeset
   173
			continue;
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5094
diff changeset
   174
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5094
diff changeset
   175
		*tab = '\0';
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5094
diff changeset
   176
		if (strcmp(buf, mountpoint) == 0) {
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5094
diff changeset
   177
			/*
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5094
diff changeset
   178
			 * the protocol field is the third field
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5094
diff changeset
   179
			 * skip over second field
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5094
diff changeset
   180
			 */
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5094
diff changeset
   181
			ptr = ++tab;
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5094
diff changeset
   182
			if ((tab = strchr(ptr, '\t')) == NULL)
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5094
diff changeset
   183
				continue;
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5094
diff changeset
   184
			ptr = ++tab;
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5094
diff changeset
   185
			if ((tab = strchr(ptr, '\t')) == NULL)
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5094
diff changeset
   186
				continue;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   187
			*tab = '\0';
5331
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5094
diff changeset
   188
			if (strcmp(ptr,
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5094
diff changeset
   189
			    proto_table[proto].p_name) == 0) {
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5094
diff changeset
   190
				switch (proto) {
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5094
diff changeset
   191
				case PROTO_NFS:
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5094
diff changeset
   192
					return (SHARED_NFS);
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5094
diff changeset
   193
				case PROTO_SMB:
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5094
diff changeset
   194
					return (SHARED_SMB);
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5094
diff changeset
   195
				default:
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5094
diff changeset
   196
					return (0);
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5094
diff changeset
   197
				}
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5094
diff changeset
   198
			}
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   199
		}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   200
	}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   201
5331
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5094
diff changeset
   202
	return (SHARED_NOT_SHARED);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   203
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   204
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   205
/*
2082
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1544
diff changeset
   206
 * Returns true if the specified directory is empty.  If we can't open the
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1544
diff changeset
   207
 * directory at all, return true so that the mount can fail with a more
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   208
 * informative error message.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   209
 */
2082
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1544
diff changeset
   210
static boolean_t
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   211
dir_is_empty(const char *dirname)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   212
{
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   213
	DIR *dirp;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   214
	struct dirent64 *dp;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   215
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   216
	if ((dirp = opendir(dirname)) == NULL)
2082
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1544
diff changeset
   217
		return (B_TRUE);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   218
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   219
	while ((dp = readdir64(dirp)) != NULL) {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   220
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   221
		if (strcmp(dp->d_name, ".") == 0 ||
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   222
		    strcmp(dp->d_name, "..") == 0)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   223
			continue;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   224
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   225
		(void) closedir(dirp);
2082
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1544
diff changeset
   226
		return (B_FALSE);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   227
	}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   228
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   229
	(void) closedir(dirp);
2082
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1544
diff changeset
   230
	return (B_TRUE);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   231
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   232
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   233
/*
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   234
 * Checks to see if the mount is active.  If the filesystem is mounted, we fill
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   235
 * in 'where' with the current mountpoint, and return 1.  Otherwise, we return
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   236
 * 0.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   237
 */
2082
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1544
diff changeset
   238
boolean_t
3444
dc160a70a50d 6410433 'zpool status -v' would be more useful with filenames
ek110237
parents: 3380
diff changeset
   239
is_mounted(libzfs_handle_t *zfs_hdl, const char *special, char **where)
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   240
{
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   241
	struct mnttab search = { 0 }, entry;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   242
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   243
	/*
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   244
	 * Search for the entry in /etc/mnttab.  We don't bother getting the
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   245
	 * mountpoint, as we can just search for the special device.  This will
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   246
	 * also let us find mounts when the mountpoint is 'legacy'.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   247
	 */
3444
dc160a70a50d 6410433 'zpool status -v' would be more useful with filenames
ek110237
parents: 3380
diff changeset
   248
	search.mnt_special = (char *)special;
1407
f178d5f7681f 6381720 zfs_unmount() not checking fstype in /etc/mnttab
nd150628
parents: 1371
diff changeset
   249
	search.mnt_fstype = MNTTYPE_ZFS;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   250
3444
dc160a70a50d 6410433 'zpool status -v' would be more useful with filenames
ek110237
parents: 3380
diff changeset
   251
	rewind(zfs_hdl->libzfs_mnttab);
dc160a70a50d 6410433 'zpool status -v' would be more useful with filenames
ek110237
parents: 3380
diff changeset
   252
	if (getmntany(zfs_hdl->libzfs_mnttab, &entry, &search) != 0)
2082
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1544
diff changeset
   253
		return (B_FALSE);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   254
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   255
	if (where != NULL)
3444
dc160a70a50d 6410433 'zpool status -v' would be more useful with filenames
ek110237
parents: 3380
diff changeset
   256
		*where = zfs_strdup(zfs_hdl, entry.mnt_mountp);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   257
2082
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1544
diff changeset
   258
	return (B_TRUE);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   259
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   260
3444
dc160a70a50d 6410433 'zpool status -v' would be more useful with filenames
ek110237
parents: 3380
diff changeset
   261
boolean_t
dc160a70a50d 6410433 'zpool status -v' would be more useful with filenames
ek110237
parents: 3380
diff changeset
   262
zfs_is_mounted(zfs_handle_t *zhp, char **where)
dc160a70a50d 6410433 'zpool status -v' would be more useful with filenames
ek110237
parents: 3380
diff changeset
   263
{
dc160a70a50d 6410433 'zpool status -v' would be more useful with filenames
ek110237
parents: 3380
diff changeset
   264
	return (is_mounted(zhp->zfs_hdl, zfs_get_name(zhp), where));
dc160a70a50d 6410433 'zpool status -v' would be more useful with filenames
ek110237
parents: 3380
diff changeset
   265
}
dc160a70a50d 6410433 'zpool status -v' would be more useful with filenames
ek110237
parents: 3380
diff changeset
   266
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   267
/*
2676
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2500
diff changeset
   268
 * Returns true if the given dataset is mountable, false otherwise.  Returns the
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2500
diff changeset
   269
 * mountpoint in 'buf'.
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2500
diff changeset
   270
 */
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2500
diff changeset
   271
static boolean_t
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2500
diff changeset
   272
zfs_is_mountable(zfs_handle_t *zhp, char *buf, size_t buflen,
5094
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4543
diff changeset
   273
    zprop_source_t *source)
2676
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2500
diff changeset
   274
{
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2500
diff changeset
   275
	char sourceloc[ZFS_MAXNAMELEN];
5094
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4543
diff changeset
   276
	zprop_source_t sourcetype;
2676
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2500
diff changeset
   277
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2500
diff changeset
   278
	if (!zfs_prop_valid_for_type(ZFS_PROP_MOUNTPOINT, zhp->zfs_type))
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2500
diff changeset
   279
		return (B_FALSE);
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2500
diff changeset
   280
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2500
diff changeset
   281
	verify(zfs_prop_get(zhp, ZFS_PROP_MOUNTPOINT, buf, buflen,
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2500
diff changeset
   282
	    &sourcetype, sourceloc, sizeof (sourceloc), B_FALSE) == 0);
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2500
diff changeset
   283
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2500
diff changeset
   284
	if (strcmp(buf, ZFS_MOUNTPOINT_NONE) == 0 ||
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2500
diff changeset
   285
	    strcmp(buf, ZFS_MOUNTPOINT_LEGACY) == 0)
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2500
diff changeset
   286
		return (B_FALSE);
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2500
diff changeset
   287
6168
51c045dcc498 PSARC 2008/168 Support for ZFS property value canmount=noauto
hs24103
parents: 6027
diff changeset
   288
	if (zfs_prop_get_int(zhp, ZFS_PROP_CANMOUNT) == ZFS_CANMOUNT_OFF)
2676
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2500
diff changeset
   289
		return (B_FALSE);
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2500
diff changeset
   290
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2500
diff changeset
   291
	if (zfs_prop_get_int(zhp, ZFS_PROP_ZONED) &&
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2500
diff changeset
   292
	    getzoneid() == GLOBAL_ZONEID)
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2500
diff changeset
   293
		return (B_FALSE);
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2500
diff changeset
   294
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2500
diff changeset
   295
	if (source)
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2500
diff changeset
   296
		*source = sourcetype;
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2500
diff changeset
   297
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2500
diff changeset
   298
	return (B_TRUE);
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2500
diff changeset
   299
}
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2500
diff changeset
   300
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2500
diff changeset
   301
/*
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   302
 * Mount the given filesystem.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   303
 */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   304
int
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   305
zfs_mount(zfs_handle_t *zhp, const char *options, int flags)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   306
{
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   307
	struct stat buf;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   308
	char mountpoint[ZFS_MAXPROPLEN];
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   309
	char mntopts[MNT_LINE_MAX];
2082
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1544
diff changeset
   310
	libzfs_handle_t *hdl = zhp->zfs_hdl;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   311
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   312
	if (options == NULL)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   313
		mntopts[0] = '\0';
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   314
	else
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   315
		(void) strlcpy(mntopts, options, sizeof (mntopts));
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   316
2676
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2500
diff changeset
   317
	if (!zfs_is_mountable(zhp, mountpoint, sizeof (mountpoint), NULL))
2082
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1544
diff changeset
   318
		return (0);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   319
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   320
	/* Create the directory if it doesn't already exist */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   321
	if (lstat(mountpoint, &buf) != 0) {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   322
		if (mkdirp(mountpoint, 0755) != 0) {
2082
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1544
diff changeset
   323
			zfs_error_aux(hdl, dgettext(TEXT_DOMAIN,
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1544
diff changeset
   324
			    "failed to create mountpoint"));
3237
98d0c28f2f5e 6480245 renaming a dataset to something with '%s' will cause segfault
lling
parents: 3134
diff changeset
   325
			return (zfs_error_fmt(hdl, EZFS_MOUNTFAILED,
2082
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1544
diff changeset
   326
			    dgettext(TEXT_DOMAIN, "cannot mount '%s'"),
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1544
diff changeset
   327
			    mountpoint));
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   328
		}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   329
	}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   330
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   331
	/*
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   332
	 * Determine if the mountpoint is empty.  If so, refuse to perform the
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   333
	 * mount.  We don't perform this check if MS_OVERLAY is specified, which
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   334
	 * would defeat the point.  We also avoid this check if 'remount' is
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   335
	 * specified.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   336
	 */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   337
	if ((flags & MS_OVERLAY) == 0 &&
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   338
	    strstr(mntopts, MNTOPT_REMOUNT) == NULL &&
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   339
	    !dir_is_empty(mountpoint)) {
2082
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1544
diff changeset
   340
		zfs_error_aux(hdl, dgettext(TEXT_DOMAIN,
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1544
diff changeset
   341
		    "directory is not empty"));
3237
98d0c28f2f5e 6480245 renaming a dataset to something with '%s' will cause segfault
lling
parents: 3134
diff changeset
   342
		return (zfs_error_fmt(hdl, EZFS_MOUNTFAILED,
2082
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1544
diff changeset
   343
		    dgettext(TEXT_DOMAIN, "cannot mount '%s'"), mountpoint));
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   344
	}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   345
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   346
	/* perform the mount */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   347
	if (mount(zfs_get_name(zhp), mountpoint, MS_OPTIONSTR | flags,
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   348
	    MNTTYPE_ZFS, NULL, 0, mntopts, sizeof (mntopts)) != 0) {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   349
		/*
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   350
		 * Generic errors are nasty, but there are just way too many
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   351
		 * from mount(), and they're well-understood.  We pick a few
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   352
		 * common ones to improve upon.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   353
		 */
4302
8e8bdcde8406 6558325 6491973 sprinkled bad cstyle in libzfs
dougm
parents: 4180
diff changeset
   354
		if (errno == EBUSY) {
2082
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1544
diff changeset
   355
			zfs_error_aux(hdl, dgettext(TEXT_DOMAIN,
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1544
diff changeset
   356
			    "mountpoint or dataset is busy"));
4543
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4337
diff changeset
   357
		} else if (errno == EPERM) {
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4337
diff changeset
   358
			zfs_error_aux(hdl, dgettext(TEXT_DOMAIN,
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4337
diff changeset
   359
			    "Insufficient privileges"));
4302
8e8bdcde8406 6558325 6491973 sprinkled bad cstyle in libzfs
dougm
parents: 4180
diff changeset
   360
		} else {
2082
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1544
diff changeset
   361
			zfs_error_aux(hdl, strerror(errno));
4302
8e8bdcde8406 6558325 6491973 sprinkled bad cstyle in libzfs
dougm
parents: 4180
diff changeset
   362
		}
2082
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1544
diff changeset
   363
3237
98d0c28f2f5e 6480245 renaming a dataset to something with '%s' will cause segfault
lling
parents: 3134
diff changeset
   364
		return (zfs_error_fmt(hdl, EZFS_MOUNTFAILED,
2082
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1544
diff changeset
   365
		    dgettext(TEXT_DOMAIN, "cannot mount '%s'"),
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1544
diff changeset
   366
		    zhp->zfs_name));
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   367
	}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   368
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   369
	return (0);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   370
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   371
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   372
/*
2474
c001ad7e0c25 6368751 libzfs interface for mount/umounting all the file systems for a given pool
eschrock
parents: 2082
diff changeset
   373
 * Unmount a single filesystem.
c001ad7e0c25 6368751 libzfs interface for mount/umounting all the file systems for a given pool
eschrock
parents: 2082
diff changeset
   374
 */
c001ad7e0c25 6368751 libzfs interface for mount/umounting all the file systems for a given pool
eschrock
parents: 2082
diff changeset
   375
static int
c001ad7e0c25 6368751 libzfs interface for mount/umounting all the file systems for a given pool
eschrock
parents: 2082
diff changeset
   376
unmount_one(libzfs_handle_t *hdl, const char *mountpoint, int flags)
c001ad7e0c25 6368751 libzfs interface for mount/umounting all the file systems for a given pool
eschrock
parents: 2082
diff changeset
   377
{
c001ad7e0c25 6368751 libzfs interface for mount/umounting all the file systems for a given pool
eschrock
parents: 2082
diff changeset
   378
	if (umount2(mountpoint, flags) != 0) {
c001ad7e0c25 6368751 libzfs interface for mount/umounting all the file systems for a given pool
eschrock
parents: 2082
diff changeset
   379
		zfs_error_aux(hdl, strerror(errno));
3237
98d0c28f2f5e 6480245 renaming a dataset to something with '%s' will cause segfault
lling
parents: 3134
diff changeset
   380
		return (zfs_error_fmt(hdl, EZFS_UMOUNTFAILED,
2474
c001ad7e0c25 6368751 libzfs interface for mount/umounting all the file systems for a given pool
eschrock
parents: 2082
diff changeset
   381
		    dgettext(TEXT_DOMAIN, "cannot unmount '%s'"),
c001ad7e0c25 6368751 libzfs interface for mount/umounting all the file systems for a given pool
eschrock
parents: 2082
diff changeset
   382
		    mountpoint));
c001ad7e0c25 6368751 libzfs interface for mount/umounting all the file systems for a given pool
eschrock
parents: 2082
diff changeset
   383
	}
c001ad7e0c25 6368751 libzfs interface for mount/umounting all the file systems for a given pool
eschrock
parents: 2082
diff changeset
   384
c001ad7e0c25 6368751 libzfs interface for mount/umounting all the file systems for a given pool
eschrock
parents: 2082
diff changeset
   385
	return (0);
c001ad7e0c25 6368751 libzfs interface for mount/umounting all the file systems for a given pool
eschrock
parents: 2082
diff changeset
   386
}
c001ad7e0c25 6368751 libzfs interface for mount/umounting all the file systems for a given pool
eschrock
parents: 2082
diff changeset
   387
c001ad7e0c25 6368751 libzfs interface for mount/umounting all the file systems for a given pool
eschrock
parents: 2082
diff changeset
   388
/*
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   389
 * Unmount the given filesystem.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   390
 */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   391
int
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   392
zfs_unmount(zfs_handle_t *zhp, const char *mountpoint, int flags)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   393
{
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   394
	struct mnttab search = { 0 }, entry;
4180
30b15f0bd3c9 6491973 sharemgr: zfs set sharenfs=on is slow with lots of zfs filesystems
dougm
parents: 3444
diff changeset
   395
	char *mntpt = NULL;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   396
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   397
	/* check to see if need to unmount the filesystem */
2474
c001ad7e0c25 6368751 libzfs interface for mount/umounting all the file systems for a given pool
eschrock
parents: 2082
diff changeset
   398
	search.mnt_special = zhp->zfs_name;
1407
f178d5f7681f 6381720 zfs_unmount() not checking fstype in /etc/mnttab
nd150628
parents: 1371
diff changeset
   399
	search.mnt_fstype = MNTTYPE_ZFS;
2082
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1544
diff changeset
   400
	rewind(zhp->zfs_hdl->libzfs_mnttab);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   401
	if (mountpoint != NULL || ((zfs_get_type(zhp) == ZFS_TYPE_FILESYSTEM) &&
2082
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1544
diff changeset
   402
	    getmntany(zhp->zfs_hdl->libzfs_mnttab, &entry, &search) == 0)) {
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   403
4180
30b15f0bd3c9 6491973 sharemgr: zfs set sharenfs=on is slow with lots of zfs filesystems
dougm
parents: 3444
diff changeset
   404
		/*
30b15f0bd3c9 6491973 sharemgr: zfs set sharenfs=on is slow with lots of zfs filesystems
dougm
parents: 3444
diff changeset
   405
		 * mountpoint may have come from a call to
30b15f0bd3c9 6491973 sharemgr: zfs set sharenfs=on is slow with lots of zfs filesystems
dougm
parents: 3444
diff changeset
   406
		 * getmnt/getmntany if it isn't NULL. If it is NULL,
30b15f0bd3c9 6491973 sharemgr: zfs set sharenfs=on is slow with lots of zfs filesystems
dougm
parents: 3444
diff changeset
   407
		 * we know it comes from getmntany which can then get
30b15f0bd3c9 6491973 sharemgr: zfs set sharenfs=on is slow with lots of zfs filesystems
dougm
parents: 3444
diff changeset
   408
		 * overwritten later. We strdup it to play it safe.
30b15f0bd3c9 6491973 sharemgr: zfs set sharenfs=on is slow with lots of zfs filesystems
dougm
parents: 3444
diff changeset
   409
		 */
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   410
		if (mountpoint == NULL)
4302
8e8bdcde8406 6558325 6491973 sprinkled bad cstyle in libzfs
dougm
parents: 4180
diff changeset
   411
			mntpt = zfs_strdup(zhp->zfs_hdl, entry.mnt_mountp);
4180
30b15f0bd3c9 6491973 sharemgr: zfs set sharenfs=on is slow with lots of zfs filesystems
dougm
parents: 3444
diff changeset
   412
		else
4302
8e8bdcde8406 6558325 6491973 sprinkled bad cstyle in libzfs
dougm
parents: 4180
diff changeset
   413
			mntpt = zfs_strdup(zhp->zfs_hdl, mountpoint);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   414
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   415
		/*
2474
c001ad7e0c25 6368751 libzfs interface for mount/umounting all the file systems for a given pool
eschrock
parents: 2082
diff changeset
   416
		 * Unshare and unmount the filesystem
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   417
		 */
5331
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5094
diff changeset
   418
		if (zfs_unshare_proto(zhp, mntpt, share_all_proto) != 0)
4331
f784727d3d6a 6537472 If zfs unmount fails it leaves the file system unshared.
th199096
parents: 4327
diff changeset
   419
			return (-1);
f784727d3d6a 6537472 If zfs unmount fails it leaves the file system unshared.
th199096
parents: 4327
diff changeset
   420
f784727d3d6a 6537472 If zfs unmount fails it leaves the file system unshared.
th199096
parents: 4327
diff changeset
   421
		if (unmount_one(zhp->zfs_hdl, mntpt, flags) != 0) {
4180
30b15f0bd3c9 6491973 sharemgr: zfs set sharenfs=on is slow with lots of zfs filesystems
dougm
parents: 3444
diff changeset
   422
			free(mntpt);
5331
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5094
diff changeset
   423
			(void) zfs_shareall(zhp);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   424
			return (-1);
4180
30b15f0bd3c9 6491973 sharemgr: zfs set sharenfs=on is slow with lots of zfs filesystems
dougm
parents: 3444
diff changeset
   425
		}
30b15f0bd3c9 6491973 sharemgr: zfs set sharenfs=on is slow with lots of zfs filesystems
dougm
parents: 3444
diff changeset
   426
		free(mntpt);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   427
	}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   428
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   429
	return (0);
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
 * Unmount this filesystem and any children inheriting the mountpoint property.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   434
 * To do this, just act like we're changing the mountpoint property, but don't
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   435
 * remount the filesystems afterwards.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   436
 */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   437
int
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   438
zfs_unmountall(zfs_handle_t *zhp, int flags)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   439
{
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   440
	prop_changelist_t *clp;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   441
	int ret;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   442
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   443
	clp = changelist_gather(zhp, ZFS_PROP_MOUNTPOINT, flags);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   444
	if (clp == NULL)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   445
		return (-1);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   446
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   447
	ret = changelist_prefix(clp);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   448
	changelist_free(clp);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   449
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   450
	return (ret);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   451
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   452
3126
4f4fb617fdd0 PSARC 2006/622 iSCSI/ZFS Integration
ahl
parents: 2676
diff changeset
   453
boolean_t
4f4fb617fdd0 PSARC 2006/622 iSCSI/ZFS Integration
ahl
parents: 2676
diff changeset
   454
zfs_is_shared(zfs_handle_t *zhp)
4f4fb617fdd0 PSARC 2006/622 iSCSI/ZFS Integration
ahl
parents: 2676
diff changeset
   455
{
5331
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5094
diff changeset
   456
	zfs_share_type_t rc = 0;
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5094
diff changeset
   457
	zfs_share_proto_t *curr_proto;
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5094
diff changeset
   458
3126
4f4fb617fdd0 PSARC 2006/622 iSCSI/ZFS Integration
ahl
parents: 2676
diff changeset
   459
	if (ZFS_IS_VOLUME(zhp))
4f4fb617fdd0 PSARC 2006/622 iSCSI/ZFS Integration
ahl
parents: 2676
diff changeset
   460
		return (zfs_is_shared_iscsi(zhp));
4f4fb617fdd0 PSARC 2006/622 iSCSI/ZFS Integration
ahl
parents: 2676
diff changeset
   461
5331
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5094
diff changeset
   462
	for (curr_proto = share_all_proto; *curr_proto != PROTO_END;
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5094
diff changeset
   463
	    curr_proto++)
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5094
diff changeset
   464
		rc |= zfs_is_shared_proto(zhp, NULL, *curr_proto);
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5094
diff changeset
   465
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5094
diff changeset
   466
	return (rc ? B_TRUE : B_FALSE);
3126
4f4fb617fdd0 PSARC 2006/622 iSCSI/ZFS Integration
ahl
parents: 2676
diff changeset
   467
}
4f4fb617fdd0 PSARC 2006/622 iSCSI/ZFS Integration
ahl
parents: 2676
diff changeset
   468
4f4fb617fdd0 PSARC 2006/622 iSCSI/ZFS Integration
ahl
parents: 2676
diff changeset
   469
int
4f4fb617fdd0 PSARC 2006/622 iSCSI/ZFS Integration
ahl
parents: 2676
diff changeset
   470
zfs_share(zfs_handle_t *zhp)
4f4fb617fdd0 PSARC 2006/622 iSCSI/ZFS Integration
ahl
parents: 2676
diff changeset
   471
{
4f4fb617fdd0 PSARC 2006/622 iSCSI/ZFS Integration
ahl
parents: 2676
diff changeset
   472
	if (ZFS_IS_VOLUME(zhp))
4f4fb617fdd0 PSARC 2006/622 iSCSI/ZFS Integration
ahl
parents: 2676
diff changeset
   473
		return (zfs_share_iscsi(zhp));
4f4fb617fdd0 PSARC 2006/622 iSCSI/ZFS Integration
ahl
parents: 2676
diff changeset
   474
5331
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5094
diff changeset
   475
	return (zfs_share_proto(zhp, share_all_proto));
3126
4f4fb617fdd0 PSARC 2006/622 iSCSI/ZFS Integration
ahl
parents: 2676
diff changeset
   476
}
4f4fb617fdd0 PSARC 2006/622 iSCSI/ZFS Integration
ahl
parents: 2676
diff changeset
   477
4f4fb617fdd0 PSARC 2006/622 iSCSI/ZFS Integration
ahl
parents: 2676
diff changeset
   478
int
4f4fb617fdd0 PSARC 2006/622 iSCSI/ZFS Integration
ahl
parents: 2676
diff changeset
   479
zfs_unshare(zfs_handle_t *zhp)
4f4fb617fdd0 PSARC 2006/622 iSCSI/ZFS Integration
ahl
parents: 2676
diff changeset
   480
{
4f4fb617fdd0 PSARC 2006/622 iSCSI/ZFS Integration
ahl
parents: 2676
diff changeset
   481
	if (ZFS_IS_VOLUME(zhp))
4f4fb617fdd0 PSARC 2006/622 iSCSI/ZFS Integration
ahl
parents: 2676
diff changeset
   482
		return (zfs_unshare_iscsi(zhp));
4f4fb617fdd0 PSARC 2006/622 iSCSI/ZFS Integration
ahl
parents: 2676
diff changeset
   483
5331
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5094
diff changeset
   484
	return (zfs_unshareall(zhp));
3126
4f4fb617fdd0 PSARC 2006/622 iSCSI/ZFS Integration
ahl
parents: 2676
diff changeset
   485
}
4f4fb617fdd0 PSARC 2006/622 iSCSI/ZFS Integration
ahl
parents: 2676
diff changeset
   486
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   487
/*
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   488
 * Check to see if the filesystem is currently shared.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   489
 */
5331
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5094
diff changeset
   490
zfs_share_type_t
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5094
diff changeset
   491
zfs_is_shared_proto(zfs_handle_t *zhp, char **where, zfs_share_proto_t proto)
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   492
{
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   493
	char *mountpoint;
5331
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5094
diff changeset
   494
	zfs_share_type_t rc;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   495
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   496
	if (!zfs_is_mounted(zhp, &mountpoint))
5331
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5094
diff changeset
   497
		return (SHARED_NOT_SHARED);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   498
5331
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5094
diff changeset
   499
	if (rc = is_shared(zhp->zfs_hdl, mountpoint, proto)) {
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   500
		if (where != NULL)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   501
			*where = mountpoint;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   502
		else
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   503
			free(mountpoint);
5331
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5094
diff changeset
   504
		return (rc);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   505
	} else {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   506
		free(mountpoint);
5331
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5094
diff changeset
   507
		return (SHARED_NOT_SHARED);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   508
	}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   509
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   510
5331
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5094
diff changeset
   511
boolean_t
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5094
diff changeset
   512
zfs_is_shared_nfs(zfs_handle_t *zhp, char **where)
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5094
diff changeset
   513
{
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5094
diff changeset
   514
	return (zfs_is_shared_proto(zhp, where,
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5094
diff changeset
   515
	    PROTO_NFS) != SHARED_NOT_SHARED);
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5094
diff changeset
   516
}
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5094
diff changeset
   517
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5094
diff changeset
   518
boolean_t
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5094
diff changeset
   519
zfs_is_shared_smb(zfs_handle_t *zhp, char **where)
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5094
diff changeset
   520
{
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5094
diff changeset
   521
	return (zfs_is_shared_proto(zhp, where,
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5094
diff changeset
   522
	    PROTO_SMB) != SHARED_NOT_SHARED);
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5094
diff changeset
   523
}
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5094
diff changeset
   524
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   525
/*
4180
30b15f0bd3c9 6491973 sharemgr: zfs set sharenfs=on is slow with lots of zfs filesystems
dougm
parents: 3444
diff changeset
   526
 * Make sure things will work if libshare isn't installed by using
30b15f0bd3c9 6491973 sharemgr: zfs set sharenfs=on is slow with lots of zfs filesystems
dougm
parents: 3444
diff changeset
   527
 * wrapper functions that check to see that the pointers to functions
30b15f0bd3c9 6491973 sharemgr: zfs set sharenfs=on is slow with lots of zfs filesystems
dougm
parents: 3444
diff changeset
   528
 * initialized in _zfs_init_libshare() are actually present.
30b15f0bd3c9 6491973 sharemgr: zfs set sharenfs=on is slow with lots of zfs filesystems
dougm
parents: 3444
diff changeset
   529
 */
30b15f0bd3c9 6491973 sharemgr: zfs set sharenfs=on is slow with lots of zfs filesystems
dougm
parents: 3444
diff changeset
   530
30b15f0bd3c9 6491973 sharemgr: zfs set sharenfs=on is slow with lots of zfs filesystems
dougm
parents: 3444
diff changeset
   531
static sa_handle_t (*_sa_init)(int);
30b15f0bd3c9 6491973 sharemgr: zfs set sharenfs=on is slow with lots of zfs filesystems
dougm
parents: 3444
diff changeset
   532
static void (*_sa_fini)(sa_handle_t);
30b15f0bd3c9 6491973 sharemgr: zfs set sharenfs=on is slow with lots of zfs filesystems
dougm
parents: 3444
diff changeset
   533
static sa_share_t (*_sa_find_share)(sa_handle_t, char *);
30b15f0bd3c9 6491973 sharemgr: zfs set sharenfs=on is slow with lots of zfs filesystems
dougm
parents: 3444
diff changeset
   534
static int (*_sa_enable_share)(sa_share_t, char *);
30b15f0bd3c9 6491973 sharemgr: zfs set sharenfs=on is slow with lots of zfs filesystems
dougm
parents: 3444
diff changeset
   535
static int (*_sa_disable_share)(sa_share_t, char *);
30b15f0bd3c9 6491973 sharemgr: zfs set sharenfs=on is slow with lots of zfs filesystems
dougm
parents: 3444
diff changeset
   536
static char *(*_sa_errorstr)(int);
30b15f0bd3c9 6491973 sharemgr: zfs set sharenfs=on is slow with lots of zfs filesystems
dougm
parents: 3444
diff changeset
   537
static int (*_sa_parse_legacy_options)(sa_group_t, char *, char *);
5951
c597da46efd6 6558321 zfs_share_nfs() fails the second time through
dougm
parents: 5367
diff changeset
   538
static boolean_t (*_sa_needs_refresh)(sa_handle_t *);
c597da46efd6 6558321 zfs_share_nfs() fails the second time through
dougm
parents: 5367
diff changeset
   539
static libzfs_handle_t *(*_sa_get_zfs_handle)(sa_handle_t);
c597da46efd6 6558321 zfs_share_nfs() fails the second time through
dougm
parents: 5367
diff changeset
   540
static int (*_sa_zfs_process_share)(sa_handle_t, sa_group_t, sa_share_t,
c597da46efd6 6558321 zfs_share_nfs() fails the second time through
dougm
parents: 5367
diff changeset
   541
    char *, char *, zprop_source_t, char *, char *, char *);
c597da46efd6 6558321 zfs_share_nfs() fails the second time through
dougm
parents: 5367
diff changeset
   542
static void (*_sa_update_sharetab_ts)(sa_handle_t);
4180
30b15f0bd3c9 6491973 sharemgr: zfs set sharenfs=on is slow with lots of zfs filesystems
dougm
parents: 3444
diff changeset
   543
30b15f0bd3c9 6491973 sharemgr: zfs set sharenfs=on is slow with lots of zfs filesystems
dougm
parents: 3444
diff changeset
   544
/*
30b15f0bd3c9 6491973 sharemgr: zfs set sharenfs=on is slow with lots of zfs filesystems
dougm
parents: 3444
diff changeset
   545
 * _zfs_init_libshare()
30b15f0bd3c9 6491973 sharemgr: zfs set sharenfs=on is slow with lots of zfs filesystems
dougm
parents: 3444
diff changeset
   546
 *
30b15f0bd3c9 6491973 sharemgr: zfs set sharenfs=on is slow with lots of zfs filesystems
dougm
parents: 3444
diff changeset
   547
 * Find the libshare.so.1 entry points that we use here and save the
30b15f0bd3c9 6491973 sharemgr: zfs set sharenfs=on is slow with lots of zfs filesystems
dougm
parents: 3444
diff changeset
   548
 * values to be used later. This is triggered by the runtime loader.
30b15f0bd3c9 6491973 sharemgr: zfs set sharenfs=on is slow with lots of zfs filesystems
dougm
parents: 3444
diff changeset
   549
 * Make sure the correct ISA version is loaded.
30b15f0bd3c9 6491973 sharemgr: zfs set sharenfs=on is slow with lots of zfs filesystems
dougm
parents: 3444
diff changeset
   550
 */
5951
c597da46efd6 6558321 zfs_share_nfs() fails the second time through
dougm
parents: 5367
diff changeset
   551
4180
30b15f0bd3c9 6491973 sharemgr: zfs set sharenfs=on is slow with lots of zfs filesystems
dougm
parents: 3444
diff changeset
   552
#pragma init(_zfs_init_libshare)
30b15f0bd3c9 6491973 sharemgr: zfs set sharenfs=on is slow with lots of zfs filesystems
dougm
parents: 3444
diff changeset
   553
static void
30b15f0bd3c9 6491973 sharemgr: zfs set sharenfs=on is slow with lots of zfs filesystems
dougm
parents: 3444
diff changeset
   554
_zfs_init_libshare(void)
30b15f0bd3c9 6491973 sharemgr: zfs set sharenfs=on is slow with lots of zfs filesystems
dougm
parents: 3444
diff changeset
   555
{
30b15f0bd3c9 6491973 sharemgr: zfs set sharenfs=on is slow with lots of zfs filesystems
dougm
parents: 3444
diff changeset
   556
	void *libshare;
30b15f0bd3c9 6491973 sharemgr: zfs set sharenfs=on is slow with lots of zfs filesystems
dougm
parents: 3444
diff changeset
   557
	char path[MAXPATHLEN];
30b15f0bd3c9 6491973 sharemgr: zfs set sharenfs=on is slow with lots of zfs filesystems
dougm
parents: 3444
diff changeset
   558
	char isa[MAXISALEN];
30b15f0bd3c9 6491973 sharemgr: zfs set sharenfs=on is slow with lots of zfs filesystems
dougm
parents: 3444
diff changeset
   559
30b15f0bd3c9 6491973 sharemgr: zfs set sharenfs=on is slow with lots of zfs filesystems
dougm
parents: 3444
diff changeset
   560
#if defined(_LP64)
30b15f0bd3c9 6491973 sharemgr: zfs set sharenfs=on is slow with lots of zfs filesystems
dougm
parents: 3444
diff changeset
   561
	if (sysinfo(SI_ARCHITECTURE_64, isa, MAXISALEN) == -1)
4302
8e8bdcde8406 6558325 6491973 sprinkled bad cstyle in libzfs
dougm
parents: 4180
diff changeset
   562
		isa[0] = '\0';
4180
30b15f0bd3c9 6491973 sharemgr: zfs set sharenfs=on is slow with lots of zfs filesystems
dougm
parents: 3444
diff changeset
   563
#else
30b15f0bd3c9 6491973 sharemgr: zfs set sharenfs=on is slow with lots of zfs filesystems
dougm
parents: 3444
diff changeset
   564
	isa[0] = '\0';
30b15f0bd3c9 6491973 sharemgr: zfs set sharenfs=on is slow with lots of zfs filesystems
dougm
parents: 3444
diff changeset
   565
#endif
30b15f0bd3c9 6491973 sharemgr: zfs set sharenfs=on is slow with lots of zfs filesystems
dougm
parents: 3444
diff changeset
   566
	(void) snprintf(path, MAXPATHLEN,
4302
8e8bdcde8406 6558325 6491973 sprinkled bad cstyle in libzfs
dougm
parents: 4180
diff changeset
   567
	    "/usr/lib/%s/libshare.so.1", isa);
4180
30b15f0bd3c9 6491973 sharemgr: zfs set sharenfs=on is slow with lots of zfs filesystems
dougm
parents: 3444
diff changeset
   568
30b15f0bd3c9 6491973 sharemgr: zfs set sharenfs=on is slow with lots of zfs filesystems
dougm
parents: 3444
diff changeset
   569
	if ((libshare = dlopen(path, RTLD_LAZY | RTLD_GLOBAL)) != NULL) {
4302
8e8bdcde8406 6558325 6491973 sprinkled bad cstyle in libzfs
dougm
parents: 4180
diff changeset
   570
		_sa_init = (sa_handle_t (*)(int))dlsym(libshare, "sa_init");
8e8bdcde8406 6558325 6491973 sprinkled bad cstyle in libzfs
dougm
parents: 4180
diff changeset
   571
		_sa_fini = (void (*)(sa_handle_t))dlsym(libshare, "sa_fini");
8e8bdcde8406 6558325 6491973 sprinkled bad cstyle in libzfs
dougm
parents: 4180
diff changeset
   572
		_sa_find_share = (sa_share_t (*)(sa_handle_t, char *))
8e8bdcde8406 6558325 6491973 sprinkled bad cstyle in libzfs
dougm
parents: 4180
diff changeset
   573
		    dlsym(libshare, "sa_find_share");
8e8bdcde8406 6558325 6491973 sprinkled bad cstyle in libzfs
dougm
parents: 4180
diff changeset
   574
		_sa_enable_share = (int (*)(sa_share_t, char *))dlsym(libshare,
8e8bdcde8406 6558325 6491973 sprinkled bad cstyle in libzfs
dougm
parents: 4180
diff changeset
   575
		    "sa_enable_share");
8e8bdcde8406 6558325 6491973 sprinkled bad cstyle in libzfs
dougm
parents: 4180
diff changeset
   576
		_sa_disable_share = (int (*)(sa_share_t, char *))dlsym(libshare,
8e8bdcde8406 6558325 6491973 sprinkled bad cstyle in libzfs
dougm
parents: 4180
diff changeset
   577
		    "sa_disable_share");
8e8bdcde8406 6558325 6491973 sprinkled bad cstyle in libzfs
dougm
parents: 4180
diff changeset
   578
		_sa_errorstr = (char *(*)(int))dlsym(libshare, "sa_errorstr");
8e8bdcde8406 6558325 6491973 sprinkled bad cstyle in libzfs
dougm
parents: 4180
diff changeset
   579
		_sa_parse_legacy_options = (int (*)(sa_group_t, char *, char *))
8e8bdcde8406 6558325 6491973 sprinkled bad cstyle in libzfs
dougm
parents: 4180
diff changeset
   580
		    dlsym(libshare, "sa_parse_legacy_options");
5951
c597da46efd6 6558321 zfs_share_nfs() fails the second time through
dougm
parents: 5367
diff changeset
   581
		_sa_needs_refresh = (boolean_t (*)(sa_handle_t *))
c597da46efd6 6558321 zfs_share_nfs() fails the second time through
dougm
parents: 5367
diff changeset
   582
		    dlsym(libshare, "sa_needs_refresh");
c597da46efd6 6558321 zfs_share_nfs() fails the second time through
dougm
parents: 5367
diff changeset
   583
		_sa_get_zfs_handle = (libzfs_handle_t *(*)(sa_handle_t))
c597da46efd6 6558321 zfs_share_nfs() fails the second time through
dougm
parents: 5367
diff changeset
   584
		    dlsym(libshare, "sa_get_zfs_handle");
c597da46efd6 6558321 zfs_share_nfs() fails the second time through
dougm
parents: 5367
diff changeset
   585
		_sa_zfs_process_share = (int (*)(sa_handle_t, sa_group_t,
c597da46efd6 6558321 zfs_share_nfs() fails the second time through
dougm
parents: 5367
diff changeset
   586
		    sa_share_t, char *, char *, zprop_source_t, char *,
c597da46efd6 6558321 zfs_share_nfs() fails the second time through
dougm
parents: 5367
diff changeset
   587
		    char *, char *))dlsym(libshare, "sa_zfs_process_share");
c597da46efd6 6558321 zfs_share_nfs() fails the second time through
dougm
parents: 5367
diff changeset
   588
		_sa_update_sharetab_ts = (void (*)(sa_handle_t))
c597da46efd6 6558321 zfs_share_nfs() fails the second time through
dougm
parents: 5367
diff changeset
   589
		    dlsym(libshare, "sa_update_sharetab_ts");
4327
4ca5d5f63ada 6556719 sharemgr: sa_zfs_init() dumps core on failure
dougm
parents: 4302
diff changeset
   590
		if (_sa_init == NULL || _sa_fini == NULL ||
4ca5d5f63ada 6556719 sharemgr: sa_zfs_init() dumps core on failure
dougm
parents: 4302
diff changeset
   591
		    _sa_find_share == NULL || _sa_enable_share == NULL ||
4ca5d5f63ada 6556719 sharemgr: sa_zfs_init() dumps core on failure
dougm
parents: 4302
diff changeset
   592
		    _sa_disable_share == NULL || _sa_errorstr == NULL ||
5951
c597da46efd6 6558321 zfs_share_nfs() fails the second time through
dougm
parents: 5367
diff changeset
   593
		    _sa_parse_legacy_options == NULL ||
c597da46efd6 6558321 zfs_share_nfs() fails the second time through
dougm
parents: 5367
diff changeset
   594
		    _sa_needs_refresh == NULL || _sa_get_zfs_handle == NULL ||
c597da46efd6 6558321 zfs_share_nfs() fails the second time through
dougm
parents: 5367
diff changeset
   595
		    _sa_zfs_process_share == NULL ||
c597da46efd6 6558321 zfs_share_nfs() fails the second time through
dougm
parents: 5367
diff changeset
   596
		    _sa_update_sharetab_ts == NULL) {
4327
4ca5d5f63ada 6556719 sharemgr: sa_zfs_init() dumps core on failure
dougm
parents: 4302
diff changeset
   597
			_sa_init = NULL;
4ca5d5f63ada 6556719 sharemgr: sa_zfs_init() dumps core on failure
dougm
parents: 4302
diff changeset
   598
			_sa_fini = NULL;
4ca5d5f63ada 6556719 sharemgr: sa_zfs_init() dumps core on failure
dougm
parents: 4302
diff changeset
   599
			_sa_disable_share = NULL;
4ca5d5f63ada 6556719 sharemgr: sa_zfs_init() dumps core on failure
dougm
parents: 4302
diff changeset
   600
			_sa_enable_share = NULL;
4ca5d5f63ada 6556719 sharemgr: sa_zfs_init() dumps core on failure
dougm
parents: 4302
diff changeset
   601
			_sa_errorstr = NULL;
4ca5d5f63ada 6556719 sharemgr: sa_zfs_init() dumps core on failure
dougm
parents: 4302
diff changeset
   602
			_sa_parse_legacy_options = NULL;
4ca5d5f63ada 6556719 sharemgr: sa_zfs_init() dumps core on failure
dougm
parents: 4302
diff changeset
   603
			(void) dlclose(libshare);
5951
c597da46efd6 6558321 zfs_share_nfs() fails the second time through
dougm
parents: 5367
diff changeset
   604
			_sa_needs_refresh = NULL;
c597da46efd6 6558321 zfs_share_nfs() fails the second time through
dougm
parents: 5367
diff changeset
   605
			_sa_get_zfs_handle = NULL;
c597da46efd6 6558321 zfs_share_nfs() fails the second time through
dougm
parents: 5367
diff changeset
   606
			_sa_zfs_process_share = NULL;
c597da46efd6 6558321 zfs_share_nfs() fails the second time through
dougm
parents: 5367
diff changeset
   607
			_sa_update_sharetab_ts = NULL;
4327
4ca5d5f63ada 6556719 sharemgr: sa_zfs_init() dumps core on failure
dougm
parents: 4302
diff changeset
   608
		}
4180
30b15f0bd3c9 6491973 sharemgr: zfs set sharenfs=on is slow with lots of zfs filesystems
dougm
parents: 3444
diff changeset
   609
	}
30b15f0bd3c9 6491973 sharemgr: zfs set sharenfs=on is slow with lots of zfs filesystems
dougm
parents: 3444
diff changeset
   610
}
30b15f0bd3c9 6491973 sharemgr: zfs set sharenfs=on is slow with lots of zfs filesystems
dougm
parents: 3444
diff changeset
   611
30b15f0bd3c9 6491973 sharemgr: zfs set sharenfs=on is slow with lots of zfs filesystems
dougm
parents: 3444
diff changeset
   612
/*
30b15f0bd3c9 6491973 sharemgr: zfs set sharenfs=on is slow with lots of zfs filesystems
dougm
parents: 3444
diff changeset
   613
 * zfs_init_libshare(zhandle, service)
30b15f0bd3c9 6491973 sharemgr: zfs set sharenfs=on is slow with lots of zfs filesystems
dougm
parents: 3444
diff changeset
   614
 *
30b15f0bd3c9 6491973 sharemgr: zfs set sharenfs=on is slow with lots of zfs filesystems
dougm
parents: 3444
diff changeset
   615
 * Initialize the libshare API if it hasn't already been initialized.
30b15f0bd3c9 6491973 sharemgr: zfs set sharenfs=on is slow with lots of zfs filesystems
dougm
parents: 3444
diff changeset
   616
 * In all cases it returns 0 if it succeeded and an error if not. The
30b15f0bd3c9 6491973 sharemgr: zfs set sharenfs=on is slow with lots of zfs filesystems
dougm
parents: 3444
diff changeset
   617
 * service value is which part(s) of the API to initialize and is a
30b15f0bd3c9 6491973 sharemgr: zfs set sharenfs=on is slow with lots of zfs filesystems
dougm
parents: 3444
diff changeset
   618
 * direct map to the libshare sa_init(service) interface.
30b15f0bd3c9 6491973 sharemgr: zfs set sharenfs=on is slow with lots of zfs filesystems
dougm
parents: 3444
diff changeset
   619
 */
30b15f0bd3c9 6491973 sharemgr: zfs set sharenfs=on is slow with lots of zfs filesystems
dougm
parents: 3444
diff changeset
   620
int
30b15f0bd3c9 6491973 sharemgr: zfs set sharenfs=on is slow with lots of zfs filesystems
dougm
parents: 3444
diff changeset
   621
zfs_init_libshare(libzfs_handle_t *zhandle, int service)
30b15f0bd3c9 6491973 sharemgr: zfs set sharenfs=on is slow with lots of zfs filesystems
dougm
parents: 3444
diff changeset
   622
{
30b15f0bd3c9 6491973 sharemgr: zfs set sharenfs=on is slow with lots of zfs filesystems
dougm
parents: 3444
diff changeset
   623
	int ret = SA_OK;
30b15f0bd3c9 6491973 sharemgr: zfs set sharenfs=on is slow with lots of zfs filesystems
dougm
parents: 3444
diff changeset
   624
4302
8e8bdcde8406 6558325 6491973 sprinkled bad cstyle in libzfs
dougm
parents: 4180
diff changeset
   625
	if (_sa_init == NULL)
8e8bdcde8406 6558325 6491973 sprinkled bad cstyle in libzfs
dougm
parents: 4180
diff changeset
   626
		ret = SA_CONFIG_ERR;
8e8bdcde8406 6558325 6491973 sprinkled bad cstyle in libzfs
dougm
parents: 4180
diff changeset
   627
5951
c597da46efd6 6558321 zfs_share_nfs() fails the second time through
dougm
parents: 5367
diff changeset
   628
	if (ret == SA_OK && zhandle->libzfs_shareflags & ZFSSHARE_MISS) {
c597da46efd6 6558321 zfs_share_nfs() fails the second time through
dougm
parents: 5367
diff changeset
   629
		/*
c597da46efd6 6558321 zfs_share_nfs() fails the second time through
dougm
parents: 5367
diff changeset
   630
		 * We had a cache miss. Most likely it is a new ZFS
c597da46efd6 6558321 zfs_share_nfs() fails the second time through
dougm
parents: 5367
diff changeset
   631
		 * dataset that was just created. We want to make sure
c597da46efd6 6558321 zfs_share_nfs() fails the second time through
dougm
parents: 5367
diff changeset
   632
		 * so check timestamps to see if a different process
c597da46efd6 6558321 zfs_share_nfs() fails the second time through
dougm
parents: 5367
diff changeset
   633
		 * has updated any of the configuration. If there was
c597da46efd6 6558321 zfs_share_nfs() fails the second time through
dougm
parents: 5367
diff changeset
   634
		 * some non-ZFS change, we need to re-initialize the
c597da46efd6 6558321 zfs_share_nfs() fails the second time through
dougm
parents: 5367
diff changeset
   635
		 * internal cache.
c597da46efd6 6558321 zfs_share_nfs() fails the second time through
dougm
parents: 5367
diff changeset
   636
		 */
c597da46efd6 6558321 zfs_share_nfs() fails the second time through
dougm
parents: 5367
diff changeset
   637
		zhandle->libzfs_shareflags &= ~ZFSSHARE_MISS;
c597da46efd6 6558321 zfs_share_nfs() fails the second time through
dougm
parents: 5367
diff changeset
   638
		if (_sa_needs_refresh != NULL &&
c597da46efd6 6558321 zfs_share_nfs() fails the second time through
dougm
parents: 5367
diff changeset
   639
		    _sa_needs_refresh(zhandle->libzfs_sharehdl)) {
c597da46efd6 6558321 zfs_share_nfs() fails the second time through
dougm
parents: 5367
diff changeset
   640
			zfs_uninit_libshare(zhandle);
c597da46efd6 6558321 zfs_share_nfs() fails the second time through
dougm
parents: 5367
diff changeset
   641
			zhandle->libzfs_sharehdl = _sa_init(service);
c597da46efd6 6558321 zfs_share_nfs() fails the second time through
dougm
parents: 5367
diff changeset
   642
		}
c597da46efd6 6558321 zfs_share_nfs() fails the second time through
dougm
parents: 5367
diff changeset
   643
	}
c597da46efd6 6558321 zfs_share_nfs() fails the second time through
dougm
parents: 5367
diff changeset
   644
4302
8e8bdcde8406 6558325 6491973 sprinkled bad cstyle in libzfs
dougm
parents: 4180
diff changeset
   645
	if (ret == SA_OK && zhandle && zhandle->libzfs_sharehdl == NULL)
8e8bdcde8406 6558325 6491973 sprinkled bad cstyle in libzfs
dougm
parents: 4180
diff changeset
   646
		zhandle->libzfs_sharehdl = _sa_init(service);
8e8bdcde8406 6558325 6491973 sprinkled bad cstyle in libzfs
dougm
parents: 4180
diff changeset
   647
8e8bdcde8406 6558325 6491973 sprinkled bad cstyle in libzfs
dougm
parents: 4180
diff changeset
   648
	if (ret == SA_OK && zhandle->libzfs_sharehdl == NULL)
8e8bdcde8406 6558325 6491973 sprinkled bad cstyle in libzfs
dougm
parents: 4180
diff changeset
   649
		ret = SA_NO_MEMORY;
8e8bdcde8406 6558325 6491973 sprinkled bad cstyle in libzfs
dougm
parents: 4180
diff changeset
   650
4180
30b15f0bd3c9 6491973 sharemgr: zfs set sharenfs=on is slow with lots of zfs filesystems
dougm
parents: 3444
diff changeset
   651
	return (ret);
30b15f0bd3c9 6491973 sharemgr: zfs set sharenfs=on is slow with lots of zfs filesystems
dougm
parents: 3444
diff changeset
   652
}
30b15f0bd3c9 6491973 sharemgr: zfs set sharenfs=on is slow with lots of zfs filesystems
dougm
parents: 3444
diff changeset
   653
30b15f0bd3c9 6491973 sharemgr: zfs set sharenfs=on is slow with lots of zfs filesystems
dougm
parents: 3444
diff changeset
   654
/*
30b15f0bd3c9 6491973 sharemgr: zfs set sharenfs=on is slow with lots of zfs filesystems
dougm
parents: 3444
diff changeset
   655
 * zfs_uninit_libshare(zhandle)
30b15f0bd3c9 6491973 sharemgr: zfs set sharenfs=on is slow with lots of zfs filesystems
dougm
parents: 3444
diff changeset
   656
 *
30b15f0bd3c9 6491973 sharemgr: zfs set sharenfs=on is slow with lots of zfs filesystems
dougm
parents: 3444
diff changeset
   657
 * Uninitialize the libshare API if it hasn't already been
30b15f0bd3c9 6491973 sharemgr: zfs set sharenfs=on is slow with lots of zfs filesystems
dougm
parents: 3444
diff changeset
   658
 * uninitialized. It is OK to call multiple times.
30b15f0bd3c9 6491973 sharemgr: zfs set sharenfs=on is slow with lots of zfs filesystems
dougm
parents: 3444
diff changeset
   659
 */
30b15f0bd3c9 6491973 sharemgr: zfs set sharenfs=on is slow with lots of zfs filesystems
dougm
parents: 3444
diff changeset
   660
void
30b15f0bd3c9 6491973 sharemgr: zfs set sharenfs=on is slow with lots of zfs filesystems
dougm
parents: 3444
diff changeset
   661
zfs_uninit_libshare(libzfs_handle_t *zhandle)
30b15f0bd3c9 6491973 sharemgr: zfs set sharenfs=on is slow with lots of zfs filesystems
dougm
parents: 3444
diff changeset
   662
{
30b15f0bd3c9 6491973 sharemgr: zfs set sharenfs=on is slow with lots of zfs filesystems
dougm
parents: 3444
diff changeset
   663
	if (zhandle != NULL && zhandle->libzfs_sharehdl != NULL) {
4302
8e8bdcde8406 6558325 6491973 sprinkled bad cstyle in libzfs
dougm
parents: 4180
diff changeset
   664
		if (_sa_fini != NULL)
8e8bdcde8406 6558325 6491973 sprinkled bad cstyle in libzfs
dougm
parents: 4180
diff changeset
   665
			_sa_fini(zhandle->libzfs_sharehdl);
8e8bdcde8406 6558325 6491973 sprinkled bad cstyle in libzfs
dougm
parents: 4180
diff changeset
   666
		zhandle->libzfs_sharehdl = NULL;
4180
30b15f0bd3c9 6491973 sharemgr: zfs set sharenfs=on is slow with lots of zfs filesystems
dougm
parents: 3444
diff changeset
   667
	}
30b15f0bd3c9 6491973 sharemgr: zfs set sharenfs=on is slow with lots of zfs filesystems
dougm
parents: 3444
diff changeset
   668
}
30b15f0bd3c9 6491973 sharemgr: zfs set sharenfs=on is slow with lots of zfs filesystems
dougm
parents: 3444
diff changeset
   669
30b15f0bd3c9 6491973 sharemgr: zfs set sharenfs=on is slow with lots of zfs filesystems
dougm
parents: 3444
diff changeset
   670
/*
30b15f0bd3c9 6491973 sharemgr: zfs set sharenfs=on is slow with lots of zfs filesystems
dougm
parents: 3444
diff changeset
   671
 * zfs_parse_options(options, proto)
30b15f0bd3c9 6491973 sharemgr: zfs set sharenfs=on is slow with lots of zfs filesystems
dougm
parents: 3444
diff changeset
   672
 *
30b15f0bd3c9 6491973 sharemgr: zfs set sharenfs=on is slow with lots of zfs filesystems
dougm
parents: 3444
diff changeset
   673
 * Call the legacy parse interface to get the protocol specific
30b15f0bd3c9 6491973 sharemgr: zfs set sharenfs=on is slow with lots of zfs filesystems
dougm
parents: 3444
diff changeset
   674
 * options using the NULL arg to indicate that this is a "parse" only.
30b15f0bd3c9 6491973 sharemgr: zfs set sharenfs=on is slow with lots of zfs filesystems
dougm
parents: 3444
diff changeset
   675
 */
30b15f0bd3c9 6491973 sharemgr: zfs set sharenfs=on is slow with lots of zfs filesystems
dougm
parents: 3444
diff changeset
   676
int
5331
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5094
diff changeset
   677
zfs_parse_options(char *options, zfs_share_proto_t proto)
4180
30b15f0bd3c9 6491973 sharemgr: zfs set sharenfs=on is slow with lots of zfs filesystems
dougm
parents: 3444
diff changeset
   678
{
5367
c40abbe796be PSARC/2007/574 zfs send -R
ahrens
parents: 5331
diff changeset
   679
	if (_sa_parse_legacy_options != NULL) {
c40abbe796be PSARC/2007/574 zfs send -R
ahrens
parents: 5331
diff changeset
   680
		return (_sa_parse_legacy_options(NULL, options,
c40abbe796be PSARC/2007/574 zfs send -R
ahrens
parents: 5331
diff changeset
   681
		    proto_table[proto].p_name));
c40abbe796be PSARC/2007/574 zfs send -R
ahrens
parents: 5331
diff changeset
   682
	}
c40abbe796be PSARC/2007/574 zfs send -R
ahrens
parents: 5331
diff changeset
   683
	return (SA_CONFIG_ERR);
4180
30b15f0bd3c9 6491973 sharemgr: zfs set sharenfs=on is slow with lots of zfs filesystems
dougm
parents: 3444
diff changeset
   684
}
30b15f0bd3c9 6491973 sharemgr: zfs set sharenfs=on is slow with lots of zfs filesystems
dougm
parents: 3444
diff changeset
   685
30b15f0bd3c9 6491973 sharemgr: zfs set sharenfs=on is slow with lots of zfs filesystems
dougm
parents: 3444
diff changeset
   686
/*
30b15f0bd3c9 6491973 sharemgr: zfs set sharenfs=on is slow with lots of zfs filesystems
dougm
parents: 3444
diff changeset
   687
 * zfs_sa_find_share(handle, path)
30b15f0bd3c9 6491973 sharemgr: zfs set sharenfs=on is slow with lots of zfs filesystems
dougm
parents: 3444
diff changeset
   688
 *
30b15f0bd3c9 6491973 sharemgr: zfs set sharenfs=on is slow with lots of zfs filesystems
dougm
parents: 3444
diff changeset
   689
 * wrapper around sa_find_share to find a share path in the
30b15f0bd3c9 6491973 sharemgr: zfs set sharenfs=on is slow with lots of zfs filesystems
dougm
parents: 3444
diff changeset
   690
 * configuration.
30b15f0bd3c9 6491973 sharemgr: zfs set sharenfs=on is slow with lots of zfs filesystems
dougm
parents: 3444
diff changeset
   691
 */
30b15f0bd3c9 6491973 sharemgr: zfs set sharenfs=on is slow with lots of zfs filesystems
dougm
parents: 3444
diff changeset
   692
static sa_share_t
30b15f0bd3c9 6491973 sharemgr: zfs set sharenfs=on is slow with lots of zfs filesystems
dougm
parents: 3444
diff changeset
   693
zfs_sa_find_share(sa_handle_t handle, char *path)
30b15f0bd3c9 6491973 sharemgr: zfs set sharenfs=on is slow with lots of zfs filesystems
dougm
parents: 3444
diff changeset
   694
{
30b15f0bd3c9 6491973 sharemgr: zfs set sharenfs=on is slow with lots of zfs filesystems
dougm
parents: 3444
diff changeset
   695
	if (_sa_find_share != NULL)
4302
8e8bdcde8406 6558325 6491973 sprinkled bad cstyle in libzfs
dougm
parents: 4180
diff changeset
   696
		return (_sa_find_share(handle, path));
4180
30b15f0bd3c9 6491973 sharemgr: zfs set sharenfs=on is slow with lots of zfs filesystems
dougm
parents: 3444
diff changeset
   697
	return (NULL);
30b15f0bd3c9 6491973 sharemgr: zfs set sharenfs=on is slow with lots of zfs filesystems
dougm
parents: 3444
diff changeset
   698
}
30b15f0bd3c9 6491973 sharemgr: zfs set sharenfs=on is slow with lots of zfs filesystems
dougm
parents: 3444
diff changeset
   699
30b15f0bd3c9 6491973 sharemgr: zfs set sharenfs=on is slow with lots of zfs filesystems
dougm
parents: 3444
diff changeset
   700
/*
30b15f0bd3c9 6491973 sharemgr: zfs set sharenfs=on is slow with lots of zfs filesystems
dougm
parents: 3444
diff changeset
   701
 * zfs_sa_enable_share(share, proto)
30b15f0bd3c9 6491973 sharemgr: zfs set sharenfs=on is slow with lots of zfs filesystems
dougm
parents: 3444
diff changeset
   702
 *
30b15f0bd3c9 6491973 sharemgr: zfs set sharenfs=on is slow with lots of zfs filesystems
dougm
parents: 3444
diff changeset
   703
 * Wrapper for sa_enable_share which enables a share for a specified
30b15f0bd3c9 6491973 sharemgr: zfs set sharenfs=on is slow with lots of zfs filesystems
dougm
parents: 3444
diff changeset
   704
 * protocol.
30b15f0bd3c9 6491973 sharemgr: zfs set sharenfs=on is slow with lots of zfs filesystems
dougm
parents: 3444
diff changeset
   705
 */
30b15f0bd3c9 6491973 sharemgr: zfs set sharenfs=on is slow with lots of zfs filesystems
dougm
parents: 3444
diff changeset
   706
static int
30b15f0bd3c9 6491973 sharemgr: zfs set sharenfs=on is slow with lots of zfs filesystems
dougm
parents: 3444
diff changeset
   707
zfs_sa_enable_share(sa_share_t share, char *proto)
30b15f0bd3c9 6491973 sharemgr: zfs set sharenfs=on is slow with lots of zfs filesystems
dougm
parents: 3444
diff changeset
   708
{
30b15f0bd3c9 6491973 sharemgr: zfs set sharenfs=on is slow with lots of zfs filesystems
dougm
parents: 3444
diff changeset
   709
	if (_sa_enable_share != NULL)
4302
8e8bdcde8406 6558325 6491973 sprinkled bad cstyle in libzfs
dougm
parents: 4180
diff changeset
   710
		return (_sa_enable_share(share, proto));
4180
30b15f0bd3c9 6491973 sharemgr: zfs set sharenfs=on is slow with lots of zfs filesystems
dougm
parents: 3444
diff changeset
   711
	return (SA_CONFIG_ERR);
30b15f0bd3c9 6491973 sharemgr: zfs set sharenfs=on is slow with lots of zfs filesystems
dougm
parents: 3444
diff changeset
   712
}
30b15f0bd3c9 6491973 sharemgr: zfs set sharenfs=on is slow with lots of zfs filesystems
dougm
parents: 3444
diff changeset
   713
30b15f0bd3c9 6491973 sharemgr: zfs set sharenfs=on is slow with lots of zfs filesystems
dougm
parents: 3444
diff changeset
   714
/*
30b15f0bd3c9 6491973 sharemgr: zfs set sharenfs=on is slow with lots of zfs filesystems
dougm
parents: 3444
diff changeset
   715
 * zfs_sa_disable_share(share, proto)
30b15f0bd3c9 6491973 sharemgr: zfs set sharenfs=on is slow with lots of zfs filesystems
dougm
parents: 3444
diff changeset
   716
 *
30b15f0bd3c9 6491973 sharemgr: zfs set sharenfs=on is slow with lots of zfs filesystems
dougm
parents: 3444
diff changeset
   717
 * Wrapper for sa_enable_share which disables a share for a specified
30b15f0bd3c9 6491973 sharemgr: zfs set sharenfs=on is slow with lots of zfs filesystems
dougm
parents: 3444
diff changeset
   718
 * protocol.
30b15f0bd3c9 6491973 sharemgr: zfs set sharenfs=on is slow with lots of zfs filesystems
dougm
parents: 3444
diff changeset
   719
 */
30b15f0bd3c9 6491973 sharemgr: zfs set sharenfs=on is slow with lots of zfs filesystems
dougm
parents: 3444
diff changeset
   720
static int
30b15f0bd3c9 6491973 sharemgr: zfs set sharenfs=on is slow with lots of zfs filesystems
dougm
parents: 3444
diff changeset
   721
zfs_sa_disable_share(sa_share_t share, char *proto)
30b15f0bd3c9 6491973 sharemgr: zfs set sharenfs=on is slow with lots of zfs filesystems
dougm
parents: 3444
diff changeset
   722
{
30b15f0bd3c9 6491973 sharemgr: zfs set sharenfs=on is slow with lots of zfs filesystems
dougm
parents: 3444
diff changeset
   723
	if (_sa_disable_share != NULL)
4302
8e8bdcde8406 6558325 6491973 sprinkled bad cstyle in libzfs
dougm
parents: 4180
diff changeset
   724
		return (_sa_disable_share(share, proto));
4180
30b15f0bd3c9 6491973 sharemgr: zfs set sharenfs=on is slow with lots of zfs filesystems
dougm
parents: 3444
diff changeset
   725
	return (SA_CONFIG_ERR);
30b15f0bd3c9 6491973 sharemgr: zfs set sharenfs=on is slow with lots of zfs filesystems
dougm
parents: 3444
diff changeset
   726
}
30b15f0bd3c9 6491973 sharemgr: zfs set sharenfs=on is slow with lots of zfs filesystems
dougm
parents: 3444
diff changeset
   727
30b15f0bd3c9 6491973 sharemgr: zfs set sharenfs=on is slow with lots of zfs filesystems
dougm
parents: 3444
diff changeset
   728
/*
5331
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5094
diff changeset
   729
 * Share the given filesystem according to the options in the specified
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5094
diff changeset
   730
 * protocol specific properties (sharenfs, sharesmb).  We rely
4180
30b15f0bd3c9 6491973 sharemgr: zfs set sharenfs=on is slow with lots of zfs filesystems
dougm
parents: 3444
diff changeset
   731
 * on "libshare" to the dirty work for us.
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   732
 */
5331
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5094
diff changeset
   733
static int
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5094
diff changeset
   734
zfs_share_proto(zfs_handle_t *zhp, zfs_share_proto_t *proto)
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   735
{
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   736
	char mountpoint[ZFS_MAXPROPLEN];
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   737
	char shareopts[ZFS_MAXPROPLEN];
5951
c597da46efd6 6558321 zfs_share_nfs() fails the second time through
dougm
parents: 5367
diff changeset
   738
	char sourcestr[ZFS_MAXPROPLEN];
2082
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1544
diff changeset
   739
	libzfs_handle_t *hdl = zhp->zfs_hdl;
4180
30b15f0bd3c9 6491973 sharemgr: zfs set sharenfs=on is slow with lots of zfs filesystems
dougm
parents: 3444
diff changeset
   740
	sa_share_t share;
5331
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5094
diff changeset
   741
	zfs_share_proto_t *curr_proto;
5951
c597da46efd6 6558321 zfs_share_nfs() fails the second time through
dougm
parents: 5367
diff changeset
   742
	zprop_source_t sourcetype;
4180
30b15f0bd3c9 6491973 sharemgr: zfs set sharenfs=on is slow with lots of zfs filesystems
dougm
parents: 3444
diff changeset
   743
	int ret;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   744
2676
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2500
diff changeset
   745
	if (!zfs_is_mountable(zhp, mountpoint, sizeof (mountpoint), NULL))
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   746
		return (0);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   747
4180
30b15f0bd3c9 6491973 sharemgr: zfs set sharenfs=on is slow with lots of zfs filesystems
dougm
parents: 3444
diff changeset
   748
	if ((ret = zfs_init_libshare(hdl, SA_INIT_SHARE_API)) != SA_OK) {
4302
8e8bdcde8406 6558325 6491973 sprinkled bad cstyle in libzfs
dougm
parents: 4180
diff changeset
   749
		(void) zfs_error_fmt(hdl, EZFS_SHARENFSFAILED,
8e8bdcde8406 6558325 6491973 sprinkled bad cstyle in libzfs
dougm
parents: 4180
diff changeset
   750
		    dgettext(TEXT_DOMAIN, "cannot share '%s': %s"),
5951
c597da46efd6 6558321 zfs_share_nfs() fails the second time through
dougm
parents: 5367
diff changeset
   751
		    zfs_get_name(zhp), _sa_errorstr != NULL ?
c597da46efd6 6558321 zfs_share_nfs() fails the second time through
dougm
parents: 5367
diff changeset
   752
		    _sa_errorstr(ret) : "");
4302
8e8bdcde8406 6558325 6491973 sprinkled bad cstyle in libzfs
dougm
parents: 4180
diff changeset
   753
		return (-1);
4180
30b15f0bd3c9 6491973 sharemgr: zfs set sharenfs=on is slow with lots of zfs filesystems
dougm
parents: 3444
diff changeset
   754
	}
5331
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5094
diff changeset
   755
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5094
diff changeset
   756
	for (curr_proto = proto; *curr_proto != PROTO_END; curr_proto++) {
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5094
diff changeset
   757
		/*
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5094
diff changeset
   758
		 * Return success if there are no share options.
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5094
diff changeset
   759
		 */
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5094
diff changeset
   760
		if (zfs_prop_get(zhp, proto_table[*curr_proto].p_prop,
5951
c597da46efd6 6558321 zfs_share_nfs() fails the second time through
dougm
parents: 5367
diff changeset
   761
		    shareopts, sizeof (shareopts), &sourcetype, sourcestr,
c597da46efd6 6558321 zfs_share_nfs() fails the second time through
dougm
parents: 5367
diff changeset
   762
		    ZFS_MAXPROPLEN, B_FALSE) != 0 ||
c597da46efd6 6558321 zfs_share_nfs() fails the second time through
dougm
parents: 5367
diff changeset
   763
		    strcmp(shareopts, "off") == 0)
5331
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5094
diff changeset
   764
			continue;
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5094
diff changeset
   765
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5094
diff changeset
   766
		/*
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5094
diff changeset
   767
		 * If the 'zoned' property is set, then zfs_is_mountable()
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5094
diff changeset
   768
		 * will have already bailed out if we are in the global zone.
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5094
diff changeset
   769
		 * But local zones cannot be NFS servers, so we ignore it for
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5094
diff changeset
   770
		 * local zones as well.
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5094
diff changeset
   771
		 */
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5094
diff changeset
   772
		if (zfs_prop_get_int(zhp, ZFS_PROP_ZONED))
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5094
diff changeset
   773
			continue;
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5094
diff changeset
   774
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5094
diff changeset
   775
		share = zfs_sa_find_share(hdl->libzfs_sharehdl, mountpoint);
5951
c597da46efd6 6558321 zfs_share_nfs() fails the second time through
dougm
parents: 5367
diff changeset
   776
		if (share == NULL) {
c597da46efd6 6558321 zfs_share_nfs() fails the second time through
dougm
parents: 5367
diff changeset
   777
			/*
c597da46efd6 6558321 zfs_share_nfs() fails the second time through
dougm
parents: 5367
diff changeset
   778
			 * This may be a new file system that was just
c597da46efd6 6558321 zfs_share_nfs() fails the second time through
dougm
parents: 5367
diff changeset
   779
			 * created so isn't in the internal cache
c597da46efd6 6558321 zfs_share_nfs() fails the second time through
dougm
parents: 5367
diff changeset
   780
			 * (second time through). Rather than
c597da46efd6 6558321 zfs_share_nfs() fails the second time through
dougm
parents: 5367
diff changeset
   781
			 * reloading the entire configuration, we can
c597da46efd6 6558321 zfs_share_nfs() fails the second time through
dougm
parents: 5367
diff changeset
   782
			 * assume ZFS has done the checking and it is
c597da46efd6 6558321 zfs_share_nfs() fails the second time through
dougm
parents: 5367
diff changeset
   783
			 * safe to add this to the internal
c597da46efd6 6558321 zfs_share_nfs() fails the second time through
dougm
parents: 5367
diff changeset
   784
			 * configuration.
c597da46efd6 6558321 zfs_share_nfs() fails the second time through
dougm
parents: 5367
diff changeset
   785
			 */
c597da46efd6 6558321 zfs_share_nfs() fails the second time through
dougm
parents: 5367
diff changeset
   786
			if (_sa_zfs_process_share(hdl->libzfs_sharehdl,
c597da46efd6 6558321 zfs_share_nfs() fails the second time through
dougm
parents: 5367
diff changeset
   787
			    NULL, NULL, mountpoint,
c597da46efd6 6558321 zfs_share_nfs() fails the second time through
dougm
parents: 5367
diff changeset
   788
			    proto_table[*curr_proto].p_name, sourcetype,
c597da46efd6 6558321 zfs_share_nfs() fails the second time through
dougm
parents: 5367
diff changeset
   789
			    shareopts, sourcestr, zhp->zfs_name) != SA_OK) {
c597da46efd6 6558321 zfs_share_nfs() fails the second time through
dougm
parents: 5367
diff changeset
   790
				(void) zfs_error_fmt(hdl,
c597da46efd6 6558321 zfs_share_nfs() fails the second time through
dougm
parents: 5367
diff changeset
   791
				    proto_table[*curr_proto].p_share_err,
c597da46efd6 6558321 zfs_share_nfs() fails the second time through
dougm
parents: 5367
diff changeset
   792
				    dgettext(TEXT_DOMAIN, "cannot share '%s'"),
c597da46efd6 6558321 zfs_share_nfs() fails the second time through
dougm
parents: 5367
diff changeset
   793
				    zfs_get_name(zhp));
c597da46efd6 6558321 zfs_share_nfs() fails the second time through
dougm
parents: 5367
diff changeset
   794
				return (-1);
c597da46efd6 6558321 zfs_share_nfs() fails the second time through
dougm
parents: 5367
diff changeset
   795
			}
c597da46efd6 6558321 zfs_share_nfs() fails the second time through
dougm
parents: 5367
diff changeset
   796
			hdl->libzfs_shareflags |= ZFSSHARE_MISS;
c597da46efd6 6558321 zfs_share_nfs() fails the second time through
dougm
parents: 5367
diff changeset
   797
			share = zfs_sa_find_share(hdl->libzfs_sharehdl,
c597da46efd6 6558321 zfs_share_nfs() fails the second time through
dougm
parents: 5367
diff changeset
   798
			    mountpoint);
c597da46efd6 6558321 zfs_share_nfs() fails the second time through
dougm
parents: 5367
diff changeset
   799
		}
5331
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5094
diff changeset
   800
		if (share != NULL) {
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5094
diff changeset
   801
			int err;
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5094
diff changeset
   802
			err = zfs_sa_enable_share(share,
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5094
diff changeset
   803
			    proto_table[*curr_proto].p_name);
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5094
diff changeset
   804
			if (err != SA_OK) {
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5094
diff changeset
   805
				(void) zfs_error_fmt(hdl,
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5094
diff changeset
   806
				    proto_table[*curr_proto].p_share_err,
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5094
diff changeset
   807
				    dgettext(TEXT_DOMAIN, "cannot share '%s'"),
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5094
diff changeset
   808
				    zfs_get_name(zhp));
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5094
diff changeset
   809
				return (-1);
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5094
diff changeset
   810
			}
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5094
diff changeset
   811
		} else {
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5094
diff changeset
   812
			(void) zfs_error_fmt(hdl,
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5094
diff changeset
   813
			    proto_table[*curr_proto].p_share_err,
4302
8e8bdcde8406 6558325 6491973 sprinkled bad cstyle in libzfs
dougm
parents: 4180
diff changeset
   814
			    dgettext(TEXT_DOMAIN, "cannot share '%s'"),
8e8bdcde8406 6558325 6491973 sprinkled bad cstyle in libzfs
dougm
parents: 4180
diff changeset
   815
			    zfs_get_name(zhp));
8e8bdcde8406 6558325 6491973 sprinkled bad cstyle in libzfs
dougm
parents: 4180
diff changeset
   816
			return (-1);
8e8bdcde8406 6558325 6491973 sprinkled bad cstyle in libzfs
dougm
parents: 4180
diff changeset
   817
		}
5331
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5094
diff changeset
   818
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   819
	}
5331
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5094
diff changeset
   820
	return (0);
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5094
diff changeset
   821
}
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   822
5331
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5094
diff changeset
   823
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5094
diff changeset
   824
int
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5094
diff changeset
   825
zfs_share_nfs(zfs_handle_t *zhp)
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5094
diff changeset
   826
{
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5094
diff changeset
   827
	return (zfs_share_proto(zhp, nfs_only));
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5094
diff changeset
   828
}
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5094
diff changeset
   829
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5094
diff changeset
   830
int
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5094
diff changeset
   831
zfs_share_smb(zfs_handle_t *zhp)
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5094
diff changeset
   832
{
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5094
diff changeset
   833
	return (zfs_share_proto(zhp, smb_only));
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5094
diff changeset
   834
}
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5094
diff changeset
   835
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5094
diff changeset
   836
int
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5094
diff changeset
   837
zfs_shareall(zfs_handle_t *zhp)
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5094
diff changeset
   838
{
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5094
diff changeset
   839
	return (zfs_share_proto(zhp, share_all_proto));
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   840
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   841
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   842
/*
2474
c001ad7e0c25 6368751 libzfs interface for mount/umounting all the file systems for a given pool
eschrock
parents: 2082
diff changeset
   843
 * Unshare a filesystem by mountpoint.
c001ad7e0c25 6368751 libzfs interface for mount/umounting all the file systems for a given pool
eschrock
parents: 2082
diff changeset
   844
 */
c001ad7e0c25 6368751 libzfs interface for mount/umounting all the file systems for a given pool
eschrock
parents: 2082
diff changeset
   845
static int
5331
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5094
diff changeset
   846
unshare_one(libzfs_handle_t *hdl, const char *name, const char *mountpoint,
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5094
diff changeset
   847
    zfs_share_proto_t proto)
2474
c001ad7e0c25 6368751 libzfs interface for mount/umounting all the file systems for a given pool
eschrock
parents: 2082
diff changeset
   848
{
4180
30b15f0bd3c9 6491973 sharemgr: zfs set sharenfs=on is slow with lots of zfs filesystems
dougm
parents: 3444
diff changeset
   849
	sa_share_t share;
30b15f0bd3c9 6491973 sharemgr: zfs set sharenfs=on is slow with lots of zfs filesystems
dougm
parents: 3444
diff changeset
   850
	int err;
30b15f0bd3c9 6491973 sharemgr: zfs set sharenfs=on is slow with lots of zfs filesystems
dougm
parents: 3444
diff changeset
   851
	char *mntpt;
2474
c001ad7e0c25 6368751 libzfs interface for mount/umounting all the file systems for a given pool
eschrock
parents: 2082
diff changeset
   852
	/*
4180
30b15f0bd3c9 6491973 sharemgr: zfs set sharenfs=on is slow with lots of zfs filesystems
dougm
parents: 3444
diff changeset
   853
	 * Mountpoint could get trashed if libshare calls getmntany
30b15f0bd3c9 6491973 sharemgr: zfs set sharenfs=on is slow with lots of zfs filesystems
dougm
parents: 3444
diff changeset
   854
	 * which id does during API initialization, so strdup the
30b15f0bd3c9 6491973 sharemgr: zfs set sharenfs=on is slow with lots of zfs filesystems
dougm
parents: 3444
diff changeset
   855
	 * value.
2474
c001ad7e0c25 6368751 libzfs interface for mount/umounting all the file systems for a given pool
eschrock
parents: 2082
diff changeset
   856
	 */
4180
30b15f0bd3c9 6491973 sharemgr: zfs set sharenfs=on is slow with lots of zfs filesystems
dougm
parents: 3444
diff changeset
   857
	mntpt = zfs_strdup(hdl, mountpoint);
2474
c001ad7e0c25 6368751 libzfs interface for mount/umounting all the file systems for a given pool
eschrock
parents: 2082
diff changeset
   858
4180
30b15f0bd3c9 6491973 sharemgr: zfs set sharenfs=on is slow with lots of zfs filesystems
dougm
parents: 3444
diff changeset
   859
	/* make sure libshare initialized */
30b15f0bd3c9 6491973 sharemgr: zfs set sharenfs=on is slow with lots of zfs filesystems
dougm
parents: 3444
diff changeset
   860
	if ((err = zfs_init_libshare(hdl, SA_INIT_SHARE_API)) != SA_OK) {
30b15f0bd3c9 6491973 sharemgr: zfs set sharenfs=on is slow with lots of zfs filesystems
dougm
parents: 3444
diff changeset
   861
		free(mntpt);	/* don't need the copy anymore */
30b15f0bd3c9 6491973 sharemgr: zfs set sharenfs=on is slow with lots of zfs filesystems
dougm
parents: 3444
diff changeset
   862
		return (zfs_error_fmt(hdl, EZFS_SHARENFSFAILED,
4302
8e8bdcde8406 6558325 6491973 sprinkled bad cstyle in libzfs
dougm
parents: 4180
diff changeset
   863
		    dgettext(TEXT_DOMAIN, "cannot unshare '%s': %s"),
8e8bdcde8406 6558325 6491973 sprinkled bad cstyle in libzfs
dougm
parents: 4180
diff changeset
   864
		    name, _sa_errorstr(err)));
2474
c001ad7e0c25 6368751 libzfs interface for mount/umounting all the file systems for a given pool
eschrock
parents: 2082
diff changeset
   865
	}
c001ad7e0c25 6368751 libzfs interface for mount/umounting all the file systems for a given pool
eschrock
parents: 2082
diff changeset
   866
4180
30b15f0bd3c9 6491973 sharemgr: zfs set sharenfs=on is slow with lots of zfs filesystems
dougm
parents: 3444
diff changeset
   867
	share = zfs_sa_find_share(hdl->libzfs_sharehdl, mntpt);
30b15f0bd3c9 6491973 sharemgr: zfs set sharenfs=on is slow with lots of zfs filesystems
dougm
parents: 3444
diff changeset
   868
	free(mntpt);	/* don't need the copy anymore */
2474
c001ad7e0c25 6368751 libzfs interface for mount/umounting all the file systems for a given pool
eschrock
parents: 2082
diff changeset
   869
4180
30b15f0bd3c9 6491973 sharemgr: zfs set sharenfs=on is slow with lots of zfs filesystems
dougm
parents: 3444
diff changeset
   870
	if (share != NULL) {
5331
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5094
diff changeset
   871
		err = zfs_sa_disable_share(share, proto_table[proto].p_name);
4180
30b15f0bd3c9 6491973 sharemgr: zfs set sharenfs=on is slow with lots of zfs filesystems
dougm
parents: 3444
diff changeset
   872
		if (err != SA_OK) {
4302
8e8bdcde8406 6558325 6491973 sprinkled bad cstyle in libzfs
dougm
parents: 4180
diff changeset
   873
			return (zfs_error_fmt(hdl, EZFS_UNSHARENFSFAILED,
8e8bdcde8406 6558325 6491973 sprinkled bad cstyle in libzfs
dougm
parents: 4180
diff changeset
   874
			    dgettext(TEXT_DOMAIN, "cannot unshare '%s': %s"),
8e8bdcde8406 6558325 6491973 sprinkled bad cstyle in libzfs
dougm
parents: 4180
diff changeset
   875
			    name, _sa_errorstr(err)));
4180
30b15f0bd3c9 6491973 sharemgr: zfs set sharenfs=on is slow with lots of zfs filesystems
dougm
parents: 3444
diff changeset
   876
		}
30b15f0bd3c9 6491973 sharemgr: zfs set sharenfs=on is slow with lots of zfs filesystems
dougm
parents: 3444
diff changeset
   877
	} else {
30b15f0bd3c9 6491973 sharemgr: zfs set sharenfs=on is slow with lots of zfs filesystems
dougm
parents: 3444
diff changeset
   878
		return (zfs_error_fmt(hdl, EZFS_UNSHARENFSFAILED,
4302
8e8bdcde8406 6558325 6491973 sprinkled bad cstyle in libzfs
dougm
parents: 4180
diff changeset
   879
		    dgettext(TEXT_DOMAIN, "cannot unshare '%s': not found"),
8e8bdcde8406 6558325 6491973 sprinkled bad cstyle in libzfs
dougm
parents: 4180
diff changeset
   880
		    name));
4180
30b15f0bd3c9 6491973 sharemgr: zfs set sharenfs=on is slow with lots of zfs filesystems
dougm
parents: 3444
diff changeset
   881
	}
2474
c001ad7e0c25 6368751 libzfs interface for mount/umounting all the file systems for a given pool
eschrock
parents: 2082
diff changeset
   882
	return (0);
c001ad7e0c25 6368751 libzfs interface for mount/umounting all the file systems for a given pool
eschrock
parents: 2082
diff changeset
   883
}
c001ad7e0c25 6368751 libzfs interface for mount/umounting all the file systems for a given pool
eschrock
parents: 2082
diff changeset
   884
c001ad7e0c25 6368751 libzfs interface for mount/umounting all the file systems for a given pool
eschrock
parents: 2082
diff changeset
   885
/*
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   886
 * Unshare the given filesystem.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   887
 */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   888
int
5331
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5094
diff changeset
   889
zfs_unshare_proto(zfs_handle_t *zhp, const char *mountpoint,
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5094
diff changeset
   890
    zfs_share_proto_t *proto)
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   891
{
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   892
	struct mnttab search = { 0 }, entry;
4180
30b15f0bd3c9 6491973 sharemgr: zfs set sharenfs=on is slow with lots of zfs filesystems
dougm
parents: 3444
diff changeset
   893
	char *mntpt = NULL;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   894
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   895
	/* check to see if need to unmount the filesystem */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   896
	search.mnt_special = (char *)zfs_get_name(zhp);
1407
f178d5f7681f 6381720 zfs_unmount() not checking fstype in /etc/mnttab
nd150628
parents: 1371
diff changeset
   897
	search.mnt_fstype = MNTTYPE_ZFS;
2082
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1544
diff changeset
   898
	rewind(zhp->zfs_hdl->libzfs_mnttab);
4302
8e8bdcde8406 6558325 6491973 sprinkled bad cstyle in libzfs
dougm
parents: 4180
diff changeset
   899
	if (mountpoint != NULL)
5331
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5094
diff changeset
   900
		mntpt = zfs_strdup(zhp->zfs_hdl, mountpoint);
4302
8e8bdcde8406 6558325 6491973 sprinkled bad cstyle in libzfs
dougm
parents: 4180
diff changeset
   901
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   902
	if (mountpoint != NULL || ((zfs_get_type(zhp) == ZFS_TYPE_FILESYSTEM) &&
2082
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1544
diff changeset
   903
	    getmntany(zhp->zfs_hdl->libzfs_mnttab, &entry, &search) == 0)) {
5331
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5094
diff changeset
   904
		zfs_share_proto_t *curr_proto;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   905
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   906
		if (mountpoint == NULL)
5331
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5094
diff changeset
   907
			mntpt = zfs_strdup(zhp->zfs_hdl, entry.mnt_mountp);
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5094
diff changeset
   908
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5094
diff changeset
   909
		for (curr_proto = proto; *curr_proto != PROTO_END;
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5094
diff changeset
   910
		    curr_proto++) {
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   911
5331
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5094
diff changeset
   912
			if (is_shared(zhp->zfs_hdl, mntpt, *curr_proto) &&
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5094
diff changeset
   913
			    unshare_one(zhp->zfs_hdl, zhp->zfs_name,
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5094
diff changeset
   914
			    mntpt, *curr_proto) != 0) {
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5094
diff changeset
   915
				if (mntpt != NULL)
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5094
diff changeset
   916
					free(mntpt);
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5094
diff changeset
   917
				return (-1);
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5094
diff changeset
   918
			}
4180
30b15f0bd3c9 6491973 sharemgr: zfs set sharenfs=on is slow with lots of zfs filesystems
dougm
parents: 3444
diff changeset
   919
		}
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   920
	}
4180
30b15f0bd3c9 6491973 sharemgr: zfs set sharenfs=on is slow with lots of zfs filesystems
dougm
parents: 3444
diff changeset
   921
	if (mntpt != NULL)
4302
8e8bdcde8406 6558325 6491973 sprinkled bad cstyle in libzfs
dougm
parents: 4180
diff changeset
   922
		free(mntpt);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   923
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   924
	return (0);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   925
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   926
5331
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5094
diff changeset
   927
int
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5094
diff changeset
   928
zfs_unshare_nfs(zfs_handle_t *zhp, const char *mountpoint)
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5094
diff changeset
   929
{
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5094
diff changeset
   930
	return (zfs_unshare_proto(zhp, mountpoint, nfs_only));
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5094
diff changeset
   931
}
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5094
diff changeset
   932
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5094
diff changeset
   933
int
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5094
diff changeset
   934
zfs_unshare_smb(zfs_handle_t *zhp, const char *mountpoint)
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5094
diff changeset
   935
{
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5094
diff changeset
   936
	return (zfs_unshare_proto(zhp, mountpoint, smb_only));
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5094
diff changeset
   937
}
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5094
diff changeset
   938
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   939
/*
5331
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5094
diff changeset
   940
 * Same as zfs_unmountall(), but for NFS and SMB unshares.
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   941
 */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   942
int
5331
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5094
diff changeset
   943
zfs_unshareall_proto(zfs_handle_t *zhp, zfs_share_proto_t *proto)
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   944
{
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   945
	prop_changelist_t *clp;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   946
	int ret;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   947
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   948
	clp = changelist_gather(zhp, ZFS_PROP_SHARENFS, 0);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   949
	if (clp == NULL)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   950
		return (-1);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   951
5331
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5094
diff changeset
   952
	ret = changelist_unshare(clp, proto);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   953
	changelist_free(clp);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   954
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   955
	return (ret);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   956
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   957
5331
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5094
diff changeset
   958
int
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5094
diff changeset
   959
zfs_unshareall_nfs(zfs_handle_t *zhp)
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5094
diff changeset
   960
{
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5094
diff changeset
   961
	return (zfs_unshareall_proto(zhp, nfs_only));
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5094
diff changeset
   962
}
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5094
diff changeset
   963
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5094
diff changeset
   964
int
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5094
diff changeset
   965
zfs_unshareall_smb(zfs_handle_t *zhp)
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5094
diff changeset
   966
{
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5094
diff changeset
   967
	return (zfs_unshareall_proto(zhp, smb_only));
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5094
diff changeset
   968
}
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5094
diff changeset
   969
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5094
diff changeset
   970
int
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5094
diff changeset
   971
zfs_unshareall(zfs_handle_t *zhp)
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5094
diff changeset
   972
{
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5094
diff changeset
   973
	return (zfs_unshareall_proto(zhp, share_all_proto));
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5094
diff changeset
   974
}
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5094
diff changeset
   975
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5094
diff changeset
   976
int
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5094
diff changeset
   977
zfs_unshareall_bypath(zfs_handle_t *zhp, const char *mountpoint)
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5094
diff changeset
   978
{
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5094
diff changeset
   979
	return (zfs_unshare_proto(zhp, mountpoint, share_all_proto));
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5094
diff changeset
   980
}
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5094
diff changeset
   981
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   982
/*
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   983
 * Remove the mountpoint associated with the current dataset, if necessary.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   984
 * We only remove the underlying directory if:
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   985
 *
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   986
 *	- The mountpoint is not 'none' or 'legacy'
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   987
 *	- The mountpoint is non-empty
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   988
 *	- The mountpoint is the default or inherited
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   989
 *	- The 'zoned' property is set, or we're in a local zone
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   990
 *
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   991
 * Any other directories we leave alone.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   992
 */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   993
void
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   994
remove_mountpoint(zfs_handle_t *zhp)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   995
{
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   996
	char mountpoint[ZFS_MAXPROPLEN];
5094
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4543
diff changeset
   997
	zprop_source_t source;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   998
2676
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2500
diff changeset
   999
	if (!zfs_is_mountable(zhp, mountpoint, sizeof (mountpoint),
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2500
diff changeset
  1000
	    &source))
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1001
		return;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1002
5094
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4543
diff changeset
  1003
	if (source == ZPROP_SRC_DEFAULT ||
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4543
diff changeset
  1004
	    source == ZPROP_SRC_INHERITED) {
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1005
		/*
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1006
		 * Try to remove the directory, silently ignoring any errors.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1007
		 * The filesystem may have since been removed or moved around,
2676
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2500
diff changeset
  1008
		 * and this error isn't really useful to the administrator in
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2500
diff changeset
  1009
		 * any way.
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1010
		 */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1011
		(void) rmdir(mountpoint);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1012
	}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1013
}
2474
c001ad7e0c25 6368751 libzfs interface for mount/umounting all the file systems for a given pool
eschrock
parents: 2082
diff changeset
  1014
3126
4f4fb617fdd0 PSARC 2006/622 iSCSI/ZFS Integration
ahl
parents: 2676
diff changeset
  1015
boolean_t
4f4fb617fdd0 PSARC 2006/622 iSCSI/ZFS Integration
ahl
parents: 2676
diff changeset
  1016
zfs_is_shared_iscsi(zfs_handle_t *zhp)
4f4fb617fdd0 PSARC 2006/622 iSCSI/ZFS Integration
ahl
parents: 2676
diff changeset
  1017
{
4543
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4337
diff changeset
  1018
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4337
diff changeset
  1019
	/*
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4337
diff changeset
  1020
	 * If iscsi deamon isn't running then we aren't shared
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4337
diff changeset
  1021
	 */
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4337
diff changeset
  1022
	if (iscsitgt_svc_online && iscsitgt_svc_online() == 1)
5331
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5094
diff changeset
  1023
		return (B_FALSE);
4543
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4337
diff changeset
  1024
	else
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4337
diff changeset
  1025
		return (iscsitgt_zfs_is_shared != NULL &&
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4337
diff changeset
  1026
		    iscsitgt_zfs_is_shared(zhp->zfs_name) != 0);
3126
4f4fb617fdd0 PSARC 2006/622 iSCSI/ZFS Integration
ahl
parents: 2676
diff changeset
  1027
}
4f4fb617fdd0 PSARC 2006/622 iSCSI/ZFS Integration
ahl
parents: 2676
diff changeset
  1028
4f4fb617fdd0 PSARC 2006/622 iSCSI/ZFS Integration
ahl
parents: 2676
diff changeset
  1029
int
4f4fb617fdd0 PSARC 2006/622 iSCSI/ZFS Integration
ahl
parents: 2676
diff changeset
  1030
zfs_share_iscsi(zfs_handle_t *zhp)
4f4fb617fdd0 PSARC 2006/622 iSCSI/ZFS Integration
ahl
parents: 2676
diff changeset
  1031
{
4f4fb617fdd0 PSARC 2006/622 iSCSI/ZFS Integration
ahl
parents: 2676
diff changeset
  1032
	char shareopts[ZFS_MAXPROPLEN];
4f4fb617fdd0 PSARC 2006/622 iSCSI/ZFS Integration
ahl
parents: 2676
diff changeset
  1033
	const char *dataset = zhp->zfs_name;
4f4fb617fdd0 PSARC 2006/622 iSCSI/ZFS Integration
ahl
parents: 2676
diff changeset
  1034
	libzfs_handle_t *hdl = zhp->zfs_hdl;
4f4fb617fdd0 PSARC 2006/622 iSCSI/ZFS Integration
ahl
parents: 2676
diff changeset
  1035
4f4fb617fdd0 PSARC 2006/622 iSCSI/ZFS Integration
ahl
parents: 2676
diff changeset
  1036
	/*
4f4fb617fdd0 PSARC 2006/622 iSCSI/ZFS Integration
ahl
parents: 2676
diff changeset
  1037
	 * Return success if there are no share options.
4f4fb617fdd0 PSARC 2006/622 iSCSI/ZFS Integration
ahl
parents: 2676
diff changeset
  1038
	 */
4f4fb617fdd0 PSARC 2006/622 iSCSI/ZFS Integration
ahl
parents: 2676
diff changeset
  1039
	if (zfs_prop_get(zhp, ZFS_PROP_SHAREISCSI, shareopts,
4f4fb617fdd0 PSARC 2006/622 iSCSI/ZFS Integration
ahl
parents: 2676
diff changeset
  1040
	    sizeof (shareopts), NULL, NULL, 0, B_FALSE) != 0 ||
4f4fb617fdd0 PSARC 2006/622 iSCSI/ZFS Integration
ahl
parents: 2676
diff changeset
  1041
	    strcmp(shareopts, "off") == 0)
4f4fb617fdd0 PSARC 2006/622 iSCSI/ZFS Integration
ahl
parents: 2676
diff changeset
  1042
		return (0);
4f4fb617fdd0 PSARC 2006/622 iSCSI/ZFS Integration
ahl
parents: 2676
diff changeset
  1043
4543
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4337
diff changeset
  1044
	if (iscsitgt_zfs_share == NULL || iscsitgt_zfs_share(dataset) != 0) {
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4337
diff changeset
  1045
		int error = EZFS_SHAREISCSIFAILED;
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4337
diff changeset
  1046
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4337
diff changeset
  1047
		/*
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4337
diff changeset
  1048
		 * If service isn't availabele and EPERM was
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4337
diff changeset
  1049
		 * returned then use special error.
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4337
diff changeset
  1050
		 */
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4337
diff changeset
  1051
		if (iscsitgt_svc_online && errno == EPERM &&
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4337
diff changeset
  1052
		    (iscsitgt_svc_online() != 0))
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4337
diff changeset
  1053
			error = EZFS_ISCSISVCUNAVAIL;
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4337
diff changeset
  1054
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4337
diff changeset
  1055
		return (zfs_error_fmt(hdl, error,
3126
4f4fb617fdd0 PSARC 2006/622 iSCSI/ZFS Integration
ahl
parents: 2676
diff changeset
  1056
		    dgettext(TEXT_DOMAIN, "cannot share '%s'"), dataset));
4543
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4337
diff changeset
  1057
	}
3126
4f4fb617fdd0 PSARC 2006/622 iSCSI/ZFS Integration
ahl
parents: 2676
diff changeset
  1058
4f4fb617fdd0 PSARC 2006/622 iSCSI/ZFS Integration
ahl
parents: 2676
diff changeset
  1059
	return (0);
4f4fb617fdd0 PSARC 2006/622 iSCSI/ZFS Integration
ahl
parents: 2676
diff changeset
  1060
}
4f4fb617fdd0 PSARC 2006/622 iSCSI/ZFS Integration
ahl
parents: 2676
diff changeset
  1061
4f4fb617fdd0 PSARC 2006/622 iSCSI/ZFS Integration
ahl
parents: 2676
diff changeset
  1062
int
4f4fb617fdd0 PSARC 2006/622 iSCSI/ZFS Integration
ahl
parents: 2676
diff changeset
  1063
zfs_unshare_iscsi(zfs_handle_t *zhp)
4f4fb617fdd0 PSARC 2006/622 iSCSI/ZFS Integration
ahl
parents: 2676
diff changeset
  1064
{
4f4fb617fdd0 PSARC 2006/622 iSCSI/ZFS Integration
ahl
parents: 2676
diff changeset
  1065
	const char *dataset = zfs_get_name(zhp);
4f4fb617fdd0 PSARC 2006/622 iSCSI/ZFS Integration
ahl
parents: 2676
diff changeset
  1066
	libzfs_handle_t *hdl = zhp->zfs_hdl;
4f4fb617fdd0 PSARC 2006/622 iSCSI/ZFS Integration
ahl
parents: 2676
diff changeset
  1067
4f4fb617fdd0 PSARC 2006/622 iSCSI/ZFS Integration
ahl
parents: 2676
diff changeset
  1068
	/*
3380
c121b2a2bd0e 6510448 zfs_unshare_iscsi() gives bogus error message when libiscsitgt cannot be opened or is missing
gw25295
parents: 3237
diff changeset
  1069
	 * Return if the volume is not shared
c121b2a2bd0e 6510448 zfs_unshare_iscsi() gives bogus error message when libiscsitgt cannot be opened or is missing
gw25295
parents: 3237
diff changeset
  1070
	 */
5331
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5094
diff changeset
  1071
	if (zfs_is_shared_iscsi(zhp) != SHARED_ISCSI)
3380
c121b2a2bd0e 6510448 zfs_unshare_iscsi() gives bogus error message when libiscsitgt cannot be opened or is missing
gw25295
parents: 3237
diff changeset
  1072
		return (0);
c121b2a2bd0e 6510448 zfs_unshare_iscsi() gives bogus error message when libiscsitgt cannot be opened or is missing
gw25295
parents: 3237
diff changeset
  1073
c121b2a2bd0e 6510448 zfs_unshare_iscsi() gives bogus error message when libiscsitgt cannot be opened or is missing
gw25295
parents: 3237
diff changeset
  1074
	/*
3126
4f4fb617fdd0 PSARC 2006/622 iSCSI/ZFS Integration
ahl
parents: 2676
diff changeset
  1075
	 * If this fails with ENODEV it indicates that zvol wasn't shared so
4f4fb617fdd0 PSARC 2006/622 iSCSI/ZFS Integration
ahl
parents: 2676
diff changeset
  1076
	 * we should return success in that case.
4f4fb617fdd0 PSARC 2006/622 iSCSI/ZFS Integration
ahl
parents: 2676
diff changeset
  1077
	 */
3134
59cd24b2b5d6 6494840 libzfs should dlopen libiscsitgt rather than linking to it
ahl
parents: 3126
diff changeset
  1078
	if (iscsitgt_zfs_unshare == NULL ||
4543
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4337
diff changeset
  1079
	    (iscsitgt_zfs_unshare(dataset) != 0 && errno != ENODEV)) {
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4337
diff changeset
  1080
		if (errno == EPERM)
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4337
diff changeset
  1081
			zfs_error_aux(hdl, dgettext(TEXT_DOMAIN,
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4337
diff changeset
  1082
			    "Insufficient privileges to unshare iscsi"));
3237
98d0c28f2f5e 6480245 renaming a dataset to something with '%s' will cause segfault
lling
parents: 3134
diff changeset
  1083
		return (zfs_error_fmt(hdl, EZFS_UNSHAREISCSIFAILED,
3126
4f4fb617fdd0 PSARC 2006/622 iSCSI/ZFS Integration
ahl
parents: 2676
diff changeset
  1084
		    dgettext(TEXT_DOMAIN, "cannot unshare '%s'"), dataset));
4543
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4337
diff changeset
  1085
	}
3126
4f4fb617fdd0 PSARC 2006/622 iSCSI/ZFS Integration
ahl
parents: 2676
diff changeset
  1086
4f4fb617fdd0 PSARC 2006/622 iSCSI/ZFS Integration
ahl
parents: 2676
diff changeset
  1087
	return (0);
4f4fb617fdd0 PSARC 2006/622 iSCSI/ZFS Integration
ahl
parents: 2676
diff changeset
  1088
}
4f4fb617fdd0 PSARC 2006/622 iSCSI/ZFS Integration
ahl
parents: 2676
diff changeset
  1089
2474
c001ad7e0c25 6368751 libzfs interface for mount/umounting all the file systems for a given pool
eschrock
parents: 2082
diff changeset
  1090
typedef struct mount_cbdata {
c001ad7e0c25 6368751 libzfs interface for mount/umounting all the file systems for a given pool
eschrock
parents: 2082
diff changeset
  1091
	zfs_handle_t	**cb_datasets;
c001ad7e0c25 6368751 libzfs interface for mount/umounting all the file systems for a given pool
eschrock
parents: 2082
diff changeset
  1092
	int 		cb_used;
c001ad7e0c25 6368751 libzfs interface for mount/umounting all the file systems for a given pool
eschrock
parents: 2082
diff changeset
  1093
	int		cb_alloc;
c001ad7e0c25 6368751 libzfs interface for mount/umounting all the file systems for a given pool
eschrock
parents: 2082
diff changeset
  1094
} mount_cbdata_t;
c001ad7e0c25 6368751 libzfs interface for mount/umounting all the file systems for a given pool
eschrock
parents: 2082
diff changeset
  1095
c001ad7e0c25 6368751 libzfs interface for mount/umounting all the file systems for a given pool
eschrock
parents: 2082
diff changeset
  1096
static int
c001ad7e0c25 6368751 libzfs interface for mount/umounting all the file systems for a given pool
eschrock
parents: 2082
diff changeset
  1097
mount_cb(zfs_handle_t *zhp, void *data)
c001ad7e0c25 6368751 libzfs interface for mount/umounting all the file systems for a given pool
eschrock
parents: 2082
diff changeset
  1098
{
c001ad7e0c25 6368751 libzfs interface for mount/umounting all the file systems for a given pool
eschrock
parents: 2082
diff changeset
  1099
	mount_cbdata_t *cbp = data;
c001ad7e0c25 6368751 libzfs interface for mount/umounting all the file systems for a given pool
eschrock
parents: 2082
diff changeset
  1100
3126
4f4fb617fdd0 PSARC 2006/622 iSCSI/ZFS Integration
ahl
parents: 2676
diff changeset
  1101
	if (!(zfs_get_type(zhp) & (ZFS_TYPE_FILESYSTEM | ZFS_TYPE_VOLUME))) {
2474
c001ad7e0c25 6368751 libzfs interface for mount/umounting all the file systems for a given pool
eschrock
parents: 2082
diff changeset
  1102
		zfs_close(zhp);
c001ad7e0c25 6368751 libzfs interface for mount/umounting all the file systems for a given pool
eschrock
parents: 2082
diff changeset
  1103
		return (0);
c001ad7e0c25 6368751 libzfs interface for mount/umounting all the file systems for a given pool
eschrock
parents: 2082
diff changeset
  1104
	}
c001ad7e0c25 6368751 libzfs interface for mount/umounting all the file systems for a given pool
eschrock
parents: 2082
diff changeset
  1105
6168
51c045dcc498 PSARC 2008/168 Support for ZFS property value canmount=noauto
hs24103
parents: 6027
diff changeset
  1106
	if (zfs_prop_get_int(zhp, ZFS_PROP_CANMOUNT) == ZFS_CANMOUNT_NOAUTO) {
51c045dcc498 PSARC 2008/168 Support for ZFS property value canmount=noauto
hs24103
parents: 6027
diff changeset
  1107
		zfs_close(zhp);
51c045dcc498 PSARC 2008/168 Support for ZFS property value canmount=noauto
hs24103
parents: 6027
diff changeset
  1108
		return (0);
51c045dcc498 PSARC 2008/168 Support for ZFS property value canmount=noauto
hs24103
parents: 6027
diff changeset
  1109
	}
51c045dcc498 PSARC 2008/168 Support for ZFS property value canmount=noauto
hs24103
parents: 6027
diff changeset
  1110
2474
c001ad7e0c25 6368751 libzfs interface for mount/umounting all the file systems for a given pool
eschrock
parents: 2082
diff changeset
  1111
	if (cbp->cb_alloc == cbp->cb_used) {
2676
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2500
diff changeset
  1112
		void *ptr;
2474
c001ad7e0c25 6368751 libzfs interface for mount/umounting all the file systems for a given pool
eschrock
parents: 2082
diff changeset
  1113
2676
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2500
diff changeset
  1114
		if ((ptr = zfs_realloc(zhp->zfs_hdl,
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2500
diff changeset
  1115
		    cbp->cb_datasets, cbp->cb_alloc * sizeof (void *),
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2500
diff changeset
  1116
		    cbp->cb_alloc * 2 * sizeof (void *))) == NULL)
2474
c001ad7e0c25 6368751 libzfs interface for mount/umounting all the file systems for a given pool
eschrock
parents: 2082
diff changeset
  1117
			return (-1);
2676
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2500
diff changeset
  1118
		cbp->cb_datasets = ptr;
2474
c001ad7e0c25 6368751 libzfs interface for mount/umounting all the file systems for a given pool
eschrock
parents: 2082
diff changeset
  1119
2676
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2500
diff changeset
  1120
		cbp->cb_alloc *= 2;
2474
c001ad7e0c25 6368751 libzfs interface for mount/umounting all the file systems for a given pool
eschrock
parents: 2082
diff changeset
  1121
	}
c001ad7e0c25 6368751 libzfs interface for mount/umounting all the file systems for a given pool
eschrock
parents: 2082
diff changeset
  1122
c001ad7e0c25 6368751 libzfs interface for mount/umounting all the file systems for a given pool
eschrock
parents: 2082
diff changeset
  1123
	cbp->cb_datasets[cbp->cb_used++] = zhp;
3126
4f4fb617fdd0 PSARC 2006/622 iSCSI/ZFS Integration
ahl
parents: 2676
diff changeset
  1124
6027
68b03551f113 6609196 'zfs destroy -r' can needlessly iterate over all filesystems in pool
rm160521
parents: 5951
diff changeset
  1125
	return (zfs_iter_filesystems(zhp, mount_cb, cbp));
2474
c001ad7e0c25 6368751 libzfs interface for mount/umounting all the file systems for a given pool
eschrock
parents: 2082
diff changeset
  1126
}
c001ad7e0c25 6368751 libzfs interface for mount/umounting all the file systems for a given pool
eschrock
parents: 2082
diff changeset
  1127
c001ad7e0c25 6368751 libzfs interface for mount/umounting all the file systems for a given pool
eschrock
parents: 2082
diff changeset
  1128
static int
3126
4f4fb617fdd0 PSARC 2006/622 iSCSI/ZFS Integration
ahl
parents: 2676
diff changeset
  1129
dataset_cmp(const void *a, const void *b)
2474
c001ad7e0c25 6368751 libzfs interface for mount/umounting all the file systems for a given pool
eschrock
parents: 2082
diff changeset
  1130
{
c001ad7e0c25 6368751 libzfs interface for mount/umounting all the file systems for a given pool
eschrock
parents: 2082
diff changeset
  1131
	zfs_handle_t **za = (zfs_handle_t **)a;
c001ad7e0c25 6368751 libzfs interface for mount/umounting all the file systems for a given pool
eschrock
parents: 2082
diff changeset
  1132
	zfs_handle_t **zb = (zfs_handle_t **)b;
c001ad7e0c25 6368751 libzfs interface for mount/umounting all the file systems for a given pool
eschrock
parents: 2082
diff changeset
  1133
	char mounta[MAXPATHLEN];
c001ad7e0c25 6368751 libzfs interface for mount/umounting all the file systems for a given pool
eschrock
parents: 2082
diff changeset
  1134
	char mountb[MAXPATHLEN];
3126
4f4fb617fdd0 PSARC 2006/622 iSCSI/ZFS Integration
ahl
parents: 2676
diff changeset
  1135
	boolean_t gota, gotb;
2474
c001ad7e0c25 6368751 libzfs interface for mount/umounting all the file systems for a given pool
eschrock
parents: 2082
diff changeset
  1136
3126
4f4fb617fdd0 PSARC 2006/622 iSCSI/ZFS Integration
ahl
parents: 2676
diff changeset
  1137
	if ((gota = (zfs_get_type(*za) == ZFS_TYPE_FILESYSTEM)) != 0)
4f4fb617fdd0 PSARC 2006/622 iSCSI/ZFS Integration
ahl
parents: 2676
diff changeset
  1138
		verify(zfs_prop_get(*za, ZFS_PROP_MOUNTPOINT, mounta,
4f4fb617fdd0 PSARC 2006/622 iSCSI/ZFS Integration
ahl
parents: 2676
diff changeset
  1139
		    sizeof (mounta), NULL, NULL, 0, B_FALSE) == 0);
4f4fb617fdd0 PSARC 2006/622 iSCSI/ZFS Integration
ahl
parents: 2676
diff changeset
  1140
	if ((gotb = (zfs_get_type(*zb) == ZFS_TYPE_FILESYSTEM)) != 0)
4f4fb617fdd0 PSARC 2006/622 iSCSI/ZFS Integration
ahl
parents: 2676
diff changeset
  1141
		verify(zfs_prop_get(*zb, ZFS_PROP_MOUNTPOINT, mountb,
4f4fb617fdd0 PSARC 2006/622 iSCSI/ZFS Integration
ahl
parents: 2676
diff changeset
  1142
		    sizeof (mountb), NULL, NULL, 0, B_FALSE) == 0);
2474
c001ad7e0c25 6368751 libzfs interface for mount/umounting all the file systems for a given pool
eschrock
parents: 2082
diff changeset
  1143
3126
4f4fb617fdd0 PSARC 2006/622 iSCSI/ZFS Integration
ahl
parents: 2676
diff changeset
  1144
	if (gota && gotb)
4f4fb617fdd0 PSARC 2006/622 iSCSI/ZFS Integration
ahl
parents: 2676
diff changeset
  1145
		return (strcmp(mounta, mountb));
4f4fb617fdd0 PSARC 2006/622 iSCSI/ZFS Integration
ahl
parents: 2676
diff changeset
  1146
4f4fb617fdd0 PSARC 2006/622 iSCSI/ZFS Integration
ahl
parents: 2676
diff changeset
  1147
	if (gota)
4f4fb617fdd0 PSARC 2006/622 iSCSI/ZFS Integration
ahl
parents: 2676
diff changeset
  1148
		return (-1);
4f4fb617fdd0 PSARC 2006/622 iSCSI/ZFS Integration
ahl
parents: 2676
diff changeset
  1149
	if (gotb)
4f4fb617fdd0 PSARC 2006/622 iSCSI/ZFS Integration
ahl
parents: 2676
diff changeset
  1150
		return (1);
4f4fb617fdd0 PSARC 2006/622 iSCSI/ZFS Integration
ahl
parents: 2676
diff changeset
  1151
4f4fb617fdd0 PSARC 2006/622 iSCSI/ZFS Integration
ahl
parents: 2676
diff changeset
  1152
	return (strcmp(zfs_get_name(a), zfs_get_name(b)));
2474
c001ad7e0c25 6368751 libzfs interface for mount/umounting all the file systems for a given pool
eschrock
parents: 2082
diff changeset
  1153
}
c001ad7e0c25 6368751 libzfs interface for mount/umounting all the file systems for a given pool
eschrock
parents: 2082
diff changeset
  1154
3126
4f4fb617fdd0 PSARC 2006/622 iSCSI/ZFS Integration
ahl
parents: 2676
diff changeset
  1155
/*
4f4fb617fdd0 PSARC 2006/622 iSCSI/ZFS Integration
ahl
parents: 2676
diff changeset
  1156
 * Mount and share all datasets within the given pool.  This assumes that no
4f4fb617fdd0 PSARC 2006/622 iSCSI/ZFS Integration
ahl
parents: 2676
diff changeset
  1157
 * datasets within the pool are currently mounted.  Because users can create
4f4fb617fdd0 PSARC 2006/622 iSCSI/ZFS Integration
ahl
parents: 2676
diff changeset
  1158
 * complicated nested hierarchies of mountpoints, we first gather all the
4f4fb617fdd0 PSARC 2006/622 iSCSI/ZFS Integration
ahl
parents: 2676
diff changeset
  1159
 * datasets and mountpoints within the pool, and sort them by mountpoint.  Once
4f4fb617fdd0 PSARC 2006/622 iSCSI/ZFS Integration
ahl
parents: 2676
diff changeset
  1160
 * we have the list of all filesystems, we iterate over them in order and mount
4f4fb617fdd0 PSARC 2006/622 iSCSI/ZFS Integration
ahl
parents: 2676
diff changeset
  1161
 * and/or share each one.
4f4fb617fdd0 PSARC 2006/622 iSCSI/ZFS Integration
ahl
parents: 2676
diff changeset
  1162
 */
4f4fb617fdd0 PSARC 2006/622 iSCSI/ZFS Integration
ahl
parents: 2676
diff changeset
  1163
#pragma weak zpool_mount_datasets = zpool_enable_datasets
2474
c001ad7e0c25 6368751 libzfs interface for mount/umounting all the file systems for a given pool
eschrock
parents: 2082
diff changeset
  1164
int
3126
4f4fb617fdd0 PSARC 2006/622 iSCSI/ZFS Integration
ahl
parents: 2676
diff changeset
  1165
zpool_enable_datasets(zpool_handle_t *zhp, const char *mntopts, int flags)
2474
c001ad7e0c25 6368751 libzfs interface for mount/umounting all the file systems for a given pool
eschrock
parents: 2082
diff changeset
  1166
{
c001ad7e0c25 6368751 libzfs interface for mount/umounting all the file systems for a given pool
eschrock
parents: 2082
diff changeset
  1167
	mount_cbdata_t cb = { 0 };
c001ad7e0c25 6368751 libzfs interface for mount/umounting all the file systems for a given pool
eschrock
parents: 2082
diff changeset
  1168
	libzfs_handle_t *hdl = zhp->zpool_hdl;
c001ad7e0c25 6368751 libzfs interface for mount/umounting all the file systems for a given pool
eschrock
parents: 2082
diff changeset
  1169
	zfs_handle_t *zfsp;
c001ad7e0c25 6368751 libzfs interface for mount/umounting all the file systems for a given pool
eschrock
parents: 2082
diff changeset
  1170
	int i, ret = -1;
4180
30b15f0bd3c9 6491973 sharemgr: zfs set sharenfs=on is slow with lots of zfs filesystems
dougm
parents: 3444
diff changeset
  1171
	int *good;
2474
c001ad7e0c25 6368751 libzfs interface for mount/umounting all the file systems for a given pool
eschrock
parents: 2082
diff changeset
  1172
c001ad7e0c25 6368751 libzfs interface for mount/umounting all the file systems for a given pool
eschrock
parents: 2082
diff changeset
  1173
	/*
6027
68b03551f113 6609196 'zfs destroy -r' can needlessly iterate over all filesystems in pool
rm160521
parents: 5951
diff changeset
  1174
	 * Gather all non-snap datasets within the pool.
2474
c001ad7e0c25 6368751 libzfs interface for mount/umounting all the file systems for a given pool
eschrock
parents: 2082
diff changeset
  1175
	 */
c001ad7e0c25 6368751 libzfs interface for mount/umounting all the file systems for a given pool
eschrock
parents: 2082
diff changeset
  1176
	if ((cb.cb_datasets = zfs_alloc(hdl, 4 * sizeof (void *))) == NULL)
c001ad7e0c25 6368751 libzfs interface for mount/umounting all the file systems for a given pool
eschrock
parents: 2082
diff changeset
  1177
		return (-1);
c001ad7e0c25 6368751 libzfs interface for mount/umounting all the file systems for a given pool
eschrock
parents: 2082
diff changeset
  1178
	cb.cb_alloc = 4;
c001ad7e0c25 6368751 libzfs interface for mount/umounting all the file systems for a given pool
eschrock
parents: 2082
diff changeset
  1179
5094
71a3e95fb9e2 PSARC 2007/342 Enhanced ZFS Pool Properties
lling
parents: 4543
diff changeset
  1180
	if ((zfsp = zfs_open(hdl, zhp->zpool_name, ZFS_TYPE_DATASET)) == NULL)
2474
c001ad7e0c25 6368751 libzfs interface for mount/umounting all the file systems for a given pool
eschrock
parents: 2082
diff changeset
  1181
		goto out;
c001ad7e0c25 6368751 libzfs interface for mount/umounting all the file systems for a given pool
eschrock
parents: 2082
diff changeset
  1182
c001ad7e0c25 6368751 libzfs interface for mount/umounting all the file systems for a given pool
eschrock
parents: 2082
diff changeset
  1183
	cb.cb_datasets[0] = zfsp;
c001ad7e0c25 6368751 libzfs interface for mount/umounting all the file systems for a given pool
eschrock
parents: 2082
diff changeset
  1184
	cb.cb_used = 1;
c001ad7e0c25 6368751 libzfs interface for mount/umounting all the file systems for a given pool
eschrock
parents: 2082
diff changeset
  1185
6027
68b03551f113 6609196 'zfs destroy -r' can needlessly iterate over all filesystems in pool
rm160521
parents: 5951
diff changeset
  1186
	if (zfs_iter_filesystems(zfsp, mount_cb, &cb) != 0)
2474
c001ad7e0c25 6368751 libzfs interface for mount/umounting all the file systems for a given pool
eschrock
parents: 2082
diff changeset
  1187
		goto out;
c001ad7e0c25 6368751 libzfs interface for mount/umounting all the file systems for a given pool
eschrock
parents: 2082
diff changeset
  1188
c001ad7e0c25 6368751 libzfs interface for mount/umounting all the file systems for a given pool
eschrock
parents: 2082
diff changeset
  1189
	/*
c001ad7e0c25 6368751 libzfs interface for mount/umounting all the file systems for a given pool
eschrock
parents: 2082
diff changeset
  1190
	 * Sort the datasets by mountpoint.
c001ad7e0c25 6368751 libzfs interface for mount/umounting all the file systems for a given pool
eschrock
parents: 2082
diff changeset
  1191
	 */
3126
4f4fb617fdd0 PSARC 2006/622 iSCSI/ZFS Integration
ahl
parents: 2676
diff changeset
  1192
	qsort(cb.cb_datasets, cb.cb_used, sizeof (void *), dataset_cmp);
2474
c001ad7e0c25 6368751 libzfs interface for mount/umounting all the file systems for a given pool
eschrock
parents: 2082
diff changeset
  1193
c001ad7e0c25 6368751 libzfs interface for mount/umounting all the file systems for a given pool
eschrock
parents: 2082
diff changeset
  1194
	/*
4180
30b15f0bd3c9 6491973 sharemgr: zfs set sharenfs=on is slow with lots of zfs filesystems
dougm
parents: 3444
diff changeset
  1195
	 * And mount all the datasets, keeping track of which ones
30b15f0bd3c9 6491973 sharemgr: zfs set sharenfs=on is slow with lots of zfs filesystems
dougm
parents: 3444
diff changeset
  1196
	 * succeeded or failed. By using zfs_alloc(), the good pointer
30b15f0bd3c9 6491973 sharemgr: zfs set sharenfs=on is slow with lots of zfs filesystems
dougm
parents: 3444
diff changeset
  1197
	 * will always be non-NULL.
2474
c001ad7e0c25 6368751 libzfs interface for mount/umounting all the file systems for a given pool
eschrock
parents: 2082
diff changeset
  1198
	 */
4180
30b15f0bd3c9 6491973 sharemgr: zfs set sharenfs=on is slow with lots of zfs filesystems
dougm
parents: 3444
diff changeset
  1199
	good = zfs_alloc(zhp->zpool_hdl, cb.cb_used * sizeof (int));
2474
c001ad7e0c25 6368751 libzfs interface for mount/umounting all the file systems for a given pool
eschrock
parents: 2082
diff changeset
  1200
	ret = 0;
c001ad7e0c25 6368751 libzfs interface for mount/umounting all the file systems for a given pool
eschrock
parents: 2082
diff changeset
  1201
	for (i = 0; i < cb.cb_used; i++) {
4302
8e8bdcde8406 6558325 6491973 sprinkled bad cstyle in libzfs
dougm
parents: 4180
diff changeset
  1202
		if (zfs_mount(cb.cb_datasets[i], mntopts, flags) != 0)
4180
30b15f0bd3c9 6491973 sharemgr: zfs set sharenfs=on is slow with lots of zfs filesystems
dougm
parents: 3444
diff changeset
  1203
			ret = -1;
4302
8e8bdcde8406 6558325 6491973 sprinkled bad cstyle in libzfs
dougm
parents: 4180
diff changeset
  1204
		else
4180
30b15f0bd3c9 6491973 sharemgr: zfs set sharenfs=on is slow with lots of zfs filesystems
dougm
parents: 3444
diff changeset
  1205
			good[i] = 1;
30b15f0bd3c9 6491973 sharemgr: zfs set sharenfs=on is slow with lots of zfs filesystems
dougm
parents: 3444
diff changeset
  1206
	}
5951
c597da46efd6 6558321 zfs_share_nfs() fails the second time through
dougm
parents: 5367
diff changeset
  1207
4180
30b15f0bd3c9 6491973 sharemgr: zfs set sharenfs=on is slow with lots of zfs filesystems
dougm
parents: 3444
diff changeset
  1208
	/*
30b15f0bd3c9 6491973 sharemgr: zfs set sharenfs=on is slow with lots of zfs filesystems
dougm
parents: 3444
diff changeset
  1209
	 * Then share all the ones that need to be shared. This needs
30b15f0bd3c9 6491973 sharemgr: zfs set sharenfs=on is slow with lots of zfs filesystems
dougm
parents: 3444
diff changeset
  1210
	 * to be a separate pass in order to avoid excessive reloading
30b15f0bd3c9 6491973 sharemgr: zfs set sharenfs=on is slow with lots of zfs filesystems
dougm
parents: 3444
diff changeset
  1211
	 * of the configuration. Good should never be NULL since
30b15f0bd3c9 6491973 sharemgr: zfs set sharenfs=on is slow with lots of zfs filesystems
dougm
parents: 3444
diff changeset
  1212
	 * zfs_alloc is supposed to exit if memory isn't available.
30b15f0bd3c9 6491973 sharemgr: zfs set sharenfs=on is slow with lots of zfs filesystems
dougm
parents: 3444
diff changeset
  1213
	 */
30b15f0bd3c9 6491973 sharemgr: zfs set sharenfs=on is slow with lots of zfs filesystems
dougm
parents: 3444
diff changeset
  1214
	for (i = 0; i < cb.cb_used; i++) {
30b15f0bd3c9 6491973 sharemgr: zfs set sharenfs=on is slow with lots of zfs filesystems
dougm
parents: 3444
diff changeset
  1215
		if (good[i] && zfs_share(cb.cb_datasets[i]) != 0)
2474
c001ad7e0c25 6368751 libzfs interface for mount/umounting all the file systems for a given pool
eschrock
parents: 2082
diff changeset
  1216
			ret = -1;
c001ad7e0c25 6368751 libzfs interface for mount/umounting all the file systems for a given pool
eschrock
parents: 2082
diff changeset
  1217
	}
c001ad7e0c25 6368751 libzfs interface for mount/umounting all the file systems for a given pool
eschrock
parents: 2082
diff changeset
  1218
4180
30b15f0bd3c9 6491973 sharemgr: zfs set sharenfs=on is slow with lots of zfs filesystems
dougm
parents: 3444
diff changeset
  1219
	free(good);
30b15f0bd3c9 6491973 sharemgr: zfs set sharenfs=on is slow with lots of zfs filesystems
dougm
parents: 3444
diff changeset
  1220
2474
c001ad7e0c25 6368751 libzfs interface for mount/umounting all the file systems for a given pool
eschrock
parents: 2082
diff changeset
  1221
out:
c001ad7e0c25 6368751 libzfs interface for mount/umounting all the file systems for a given pool
eschrock
parents: 2082
diff changeset
  1222
	for (i = 0; i < cb.cb_used; i++)
c001ad7e0c25 6368751 libzfs interface for mount/umounting all the file systems for a given pool
eschrock
parents: 2082
diff changeset
  1223
		zfs_close(cb.cb_datasets[i]);
c001ad7e0c25 6368751 libzfs interface for mount/umounting all the file systems for a given pool
eschrock
parents: 2082
diff changeset
  1224
	free(cb.cb_datasets);
c001ad7e0c25 6368751 libzfs interface for mount/umounting all the file systems for a given pool
eschrock
parents: 2082
diff changeset
  1225
c001ad7e0c25 6368751 libzfs interface for mount/umounting all the file systems for a given pool
eschrock
parents: 2082
diff changeset
  1226
	return (ret);
c001ad7e0c25 6368751 libzfs interface for mount/umounting all the file systems for a given pool
eschrock
parents: 2082
diff changeset
  1227
}
c001ad7e0c25 6368751 libzfs interface for mount/umounting all the file systems for a given pool
eschrock
parents: 2082
diff changeset
  1228
3126
4f4fb617fdd0 PSARC 2006/622 iSCSI/ZFS Integration
ahl
parents: 2676
diff changeset
  1229
4f4fb617fdd0 PSARC 2006/622 iSCSI/ZFS Integration
ahl
parents: 2676
diff changeset
  1230
static int
4f4fb617fdd0 PSARC 2006/622 iSCSI/ZFS Integration
ahl
parents: 2676
diff changeset
  1231
zvol_cb(const char *dataset, void *data)
4f4fb617fdd0 PSARC 2006/622 iSCSI/ZFS Integration
ahl
parents: 2676
diff changeset
  1232
{
4f4fb617fdd0 PSARC 2006/622 iSCSI/ZFS Integration
ahl
parents: 2676
diff changeset
  1233
	libzfs_handle_t *hdl = data;
4f4fb617fdd0 PSARC 2006/622 iSCSI/ZFS Integration
ahl
parents: 2676
diff changeset
  1234
	zfs_handle_t *zhp;
4f4fb617fdd0 PSARC 2006/622 iSCSI/ZFS Integration
ahl
parents: 2676
diff changeset
  1235
4f4fb617fdd0 PSARC 2006/622 iSCSI/ZFS Integration
ahl
parents: 2676
diff changeset
  1236
	/*
4f4fb617fdd0 PSARC 2006/622 iSCSI/ZFS Integration
ahl
parents: 2676
diff changeset
  1237
	 * Ignore snapshots and ignore failures from non-existant datasets.
4f4fb617fdd0 PSARC 2006/622 iSCSI/ZFS Integration
ahl
parents: 2676
diff changeset
  1238
	 */
4f4fb617fdd0 PSARC 2006/622 iSCSI/ZFS Integration
ahl
parents: 2676
diff changeset
  1239
	if (strchr(dataset, '@') != NULL ||
4f4fb617fdd0 PSARC 2006/622 iSCSI/ZFS Integration
ahl
parents: 2676
diff changeset
  1240
	    (zhp = zfs_open(hdl, dataset, ZFS_TYPE_VOLUME)) == NULL)
4f4fb617fdd0 PSARC 2006/622 iSCSI/ZFS Integration
ahl
parents: 2676
diff changeset
  1241
		return (0);
4f4fb617fdd0 PSARC 2006/622 iSCSI/ZFS Integration
ahl
parents: 2676
diff changeset
  1242
4543
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4337
diff changeset
  1243
	if (zfs_unshare_iscsi(zhp) != 0)
12bb2876a62e PSARC/2006/465 ZFS Delegated Administration
marks
parents: 4337
diff changeset
  1244
		return (-1);
3126
4f4fb617fdd0 PSARC 2006/622 iSCSI/ZFS Integration
ahl
parents: 2676
diff changeset
  1245
4f4fb617fdd0 PSARC 2006/622 iSCSI/ZFS Integration
ahl
parents: 2676
diff changeset
  1246
	zfs_close(zhp);
4f4fb617fdd0 PSARC 2006/622 iSCSI/ZFS Integration
ahl
parents: 2676
diff changeset
  1247
4f4fb617fdd0 PSARC 2006/622 iSCSI/ZFS Integration
ahl
parents: 2676
diff changeset
  1248
	return (0);
4f4fb617fdd0 PSARC 2006/622 iSCSI/ZFS Integration
ahl
parents: 2676
diff changeset
  1249
}
4f4fb617fdd0 PSARC 2006/622 iSCSI/ZFS Integration
ahl
parents: 2676
diff changeset
  1250
2474
c001ad7e0c25 6368751 libzfs interface for mount/umounting all the file systems for a given pool
eschrock
parents: 2082
diff changeset
  1251
static int
c001ad7e0c25 6368751 libzfs interface for mount/umounting all the file systems for a given pool
eschrock
parents: 2082
diff changeset
  1252
mountpoint_compare(const void *a, const void *b)
c001ad7e0c25 6368751 libzfs interface for mount/umounting all the file systems for a given pool
eschrock
parents: 2082
diff changeset
  1253
{
c001ad7e0c25 6368751 libzfs interface for mount/umounting all the file systems for a given pool
eschrock
parents: 2082
diff changeset
  1254
	const char *mounta = *((char **)a);
c001ad7e0c25 6368751 libzfs interface for mount/umounting all the file systems for a given pool
eschrock
parents: 2082
diff changeset
  1255
	const char *mountb = *((char **)b);
c001ad7e0c25 6368751 libzfs interface for mount/umounting all the file systems for a given pool
eschrock
parents: 2082
diff changeset
  1256
c001ad7e0c25 6368751 libzfs interface for mount/umounting all the file systems for a given pool
eschrock
parents: 2082
diff changeset
  1257
	return (strcmp(mountb, mounta));
c001ad7e0c25 6368751 libzfs interface for mount/umounting all the file systems for a given pool
eschrock
parents: 2082
diff changeset
  1258
}
c001ad7e0c25 6368751 libzfs interface for mount/umounting all the file systems for a given pool
eschrock
parents: 2082
diff changeset
  1259
3126
4f4fb617fdd0 PSARC 2006/622 iSCSI/ZFS Integration
ahl
parents: 2676
diff changeset
  1260
/*
4f4fb617fdd0 PSARC 2006/622 iSCSI/ZFS Integration
ahl
parents: 2676
diff changeset
  1261
 * Unshare and unmount all datasets within the given pool.  We don't want to
4f4fb617fdd0 PSARC 2006/622 iSCSI/ZFS Integration
ahl
parents: 2676
diff changeset
  1262
 * rely on traversing the DSL to discover the filesystems within the pool,
4f4fb617fdd0 PSARC 2006/622 iSCSI/ZFS Integration
ahl
parents: 2676
diff changeset
  1263
 * because this may be expensive (if not all of them are mounted), and can fail
4f4fb617fdd0 PSARC 2006/622 iSCSI/ZFS Integration
ahl
parents: 2676
diff changeset
  1264
 * arbitrarily (on I/O error, for example).  Instead, we walk /etc/mnttab and
4f4fb617fdd0 PSARC 2006/622 iSCSI/ZFS Integration
ahl
parents: 2676
diff changeset
  1265
 * gather all the filesystems that are currently mounted.
4f4fb617fdd0 PSARC 2006/622 iSCSI/ZFS Integration
ahl
parents: 2676
diff changeset
  1266
 */
4f4fb617fdd0 PSARC 2006/622 iSCSI/ZFS Integration
ahl
parents: 2676
diff changeset
  1267
#pragma weak zpool_unmount_datasets = zpool_disable_datasets
2474
c001ad7e0c25 6368751 libzfs interface for mount/umounting all the file systems for a given pool
eschrock
parents: 2082
diff changeset
  1268
int
3126
4f4fb617fdd0 PSARC 2006/622 iSCSI/ZFS Integration
ahl
parents: 2676
diff changeset
  1269
zpool_disable_datasets(zpool_handle_t *zhp, boolean_t force)
2474
c001ad7e0c25 6368751 libzfs interface for mount/umounting all the file systems for a given pool
eschrock
parents: 2082
diff changeset
  1270
{
c001ad7e0c25 6368751 libzfs interface for mount/umounting all the file systems for a given pool
eschrock
parents: 2082
diff changeset
  1271
	int used, alloc;
c001ad7e0c25 6368751 libzfs interface for mount/umounting all the file systems for a given pool
eschrock
parents: 2082
diff changeset
  1272
	struct mnttab entry;
c001ad7e0c25 6368751 libzfs interface for mount/umounting all the file systems for a given pool
eschrock
parents: 2082
diff changeset
  1273
	size_t namelen;
c001ad7e0c25 6368751 libzfs interface for mount/umounting all the file systems for a given pool
eschrock
parents: 2082
diff changeset
  1274
	char **mountpoints = NULL;
c001ad7e0c25 6368751 libzfs interface for mount/umounting all the file systems for a given pool
eschrock
parents: 2082
diff changeset
  1275
	zfs_handle_t **datasets = NULL;
c001ad7e0c25 6368751 libzfs interface for mount/umounting all the file systems for a given pool
eschrock
parents: 2082
diff changeset
  1276
	libzfs_handle_t *hdl = zhp->zpool_hdl;
c001ad7e0c25 6368751 libzfs interface for mount/umounting all the file systems for a given pool
eschrock
parents: 2082
diff changeset
  1277
	int i;
c001ad7e0c25 6368751 libzfs interface for mount/umounting all the file systems for a given pool
eschrock
parents: 2082
diff changeset
  1278
	int ret = -1;
c001ad7e0c25 6368751 libzfs interface for mount/umounting all the file systems for a given pool
eschrock
parents: 2082
diff changeset
  1279
	int flags = (force ? MS_FORCE : 0);
c001ad7e0c25 6368751 libzfs interface for mount/umounting all the file systems for a given pool
eschrock
parents: 2082
diff changeset
  1280
3126
4f4fb617fdd0 PSARC 2006/622 iSCSI/ZFS Integration
ahl
parents: 2676
diff changeset
  1281
	/*
4f4fb617fdd0 PSARC 2006/622 iSCSI/ZFS Integration
ahl
parents: 2676
diff changeset
  1282
	 * First unshare all zvols.
4f4fb617fdd0 PSARC 2006/622 iSCSI/ZFS Integration
ahl
parents: 2676
diff changeset
  1283
	 */
4f4fb617fdd0 PSARC 2006/622 iSCSI/ZFS Integration
ahl
parents: 2676
diff changeset
  1284
	if (zpool_iter_zvol(zhp, zvol_cb, hdl) != 0)
4f4fb617fdd0 PSARC 2006/622 iSCSI/ZFS Integration
ahl
parents: 2676
diff changeset
  1285
		return (-1);
4f4fb617fdd0 PSARC 2006/622 iSCSI/ZFS Integration
ahl
parents: 2676
diff changeset
  1286
2474
c001ad7e0c25 6368751 libzfs interface for mount/umounting all the file systems for a given pool
eschrock
parents: 2082
diff changeset
  1287
	namelen = strlen(zhp->zpool_name);
c001ad7e0c25 6368751 libzfs interface for mount/umounting all the file systems for a given pool
eschrock
parents: 2082
diff changeset
  1288
c001ad7e0c25 6368751 libzfs interface for mount/umounting all the file systems for a given pool
eschrock
parents: 2082
diff changeset
  1289
	rewind(hdl->libzfs_mnttab);
c001ad7e0c25 6368751 libzfs interface for mount/umounting all the file systems for a given pool
eschrock
parents: 2082
diff changeset
  1290
	used = alloc = 0;
c001ad7e0c25 6368751 libzfs interface for mount/umounting all the file systems for a given pool
eschrock
parents: 2082
diff changeset
  1291
	while (getmntent(hdl->libzfs_mnttab, &entry) == 0) {
c001ad7e0c25 6368751 libzfs interface for mount/umounting all the file systems for a given pool
eschrock
parents: 2082
diff changeset
  1292
		/*
c001ad7e0c25 6368751 libzfs interface for mount/umounting all the file systems for a given pool
eschrock
parents: 2082
diff changeset
  1293
		 * Ignore non-ZFS entries.
c001ad7e0c25 6368751 libzfs interface for mount/umounting all the file systems for a given pool
eschrock
parents: 2082
diff changeset
  1294
		 */
c001ad7e0c25 6368751 libzfs interface for mount/umounting all the file systems for a given pool
eschrock
parents: 2082
diff changeset
  1295
		if (entry.mnt_fstype == NULL ||
c001ad7e0c25 6368751 libzfs interface for mount/umounting all the file systems for a given pool
eschrock
parents: 2082
diff changeset
  1296
		    strcmp(entry.mnt_fstype, MNTTYPE_ZFS) != 0)
c001ad7e0c25 6368751 libzfs interface for mount/umounting all the file systems for a given pool
eschrock
parents: 2082
diff changeset
  1297
			continue;
c001ad7e0c25 6368751 libzfs interface for mount/umounting all the file systems for a given pool
eschrock
parents: 2082
diff changeset
  1298
c001ad7e0c25 6368751 libzfs interface for mount/umounting all the file systems for a given pool
eschrock
parents: 2082
diff changeset
  1299
		/*
c001ad7e0c25 6368751 libzfs interface for mount/umounting all the file systems for a given pool
eschrock
parents: 2082
diff changeset
  1300
		 * Ignore filesystems not within this pool.
c001ad7e0c25 6368751 libzfs interface for mount/umounting all the file systems for a given pool
eschrock
parents: 2082
diff changeset
  1301
		 */
c001ad7e0c25 6368751 libzfs interface for mount/umounting all the file systems for a given pool
eschrock
parents: 2082
diff changeset
  1302
		if (entry.mnt_mountp == NULL ||
c001ad7e0c25 6368751 libzfs interface for mount/umounting all the file systems for a given pool
eschrock
parents: 2082
diff changeset
  1303
		    strncmp(entry.mnt_special, zhp->zpool_name, namelen) != 0 ||
c001ad7e0c25 6368751 libzfs interface for mount/umounting all the file systems for a given pool
eschrock
parents: 2082
diff changeset
  1304
		    (entry.mnt_special[namelen] != '/' &&
c001ad7e0c25 6368751 libzfs interface for mount/umounting all the file systems for a given pool
eschrock
parents: 2082
diff changeset
  1305
		    entry.mnt_special[namelen] != '\0'))
c001ad7e0c25 6368751 libzfs interface for mount/umounting all the file systems for a given pool
eschrock
parents: 2082
diff changeset
  1306
			continue;
c001ad7e0c25 6368751 libzfs interface for mount/umounting all the file systems for a given pool
eschrock
parents: 2082
diff changeset
  1307
c001ad7e0c25 6368751 libzfs interface for mount/umounting all the file systems for a given pool
eschrock
parents: 2082
diff changeset
  1308
		/*
c001ad7e0c25 6368751 libzfs interface for mount/umounting all the file systems for a given pool
eschrock
parents: 2082
diff changeset
  1309
		 * At this point we've found a filesystem within our pool.  Add
c001ad7e0c25 6368751 libzfs interface for mount/umounting all the file systems for a given pool
eschrock
parents: 2082
diff changeset
  1310
		 * it to our growing list.
c001ad7e0c25 6368751 libzfs interface for mount/umounting all the file systems for a given pool
eschrock
parents: 2082
diff changeset
  1311
		 */
c001ad7e0c25 6368751 libzfs interface for mount/umounting all the file systems for a given pool
eschrock
parents: 2082
diff changeset
  1312
		if (used == alloc) {
c001ad7e0c25 6368751 libzfs interface for mount/umounting all the file systems for a given pool
eschrock
parents: 2082
diff changeset
  1313
			if (alloc == 0) {
c001ad7e0c25 6368751 libzfs interface for mount/umounting all the file systems for a given pool
eschrock
parents: 2082
diff changeset
  1314
				if ((mountpoints = zfs_alloc(hdl,
c001ad7e0c25 6368751 libzfs interface for mount/umounting all the file systems for a given pool
eschrock
parents: 2082
diff changeset
  1315
				    8 * sizeof (void *))) == NULL)
c001ad7e0c25 6368751 libzfs interface for mount/umounting all the file systems for a given pool
eschrock
parents: 2082
diff changeset
  1316
					goto out;
c001ad7e0c25 6368751 libzfs interface for mount/umounting all the file systems for a given pool
eschrock
parents: 2082
diff changeset
  1317
c001ad7e0c25 6368751 libzfs interface for mount/umounting all the file systems for a given pool
eschrock
parents: 2082
diff changeset
  1318
				if ((datasets = zfs_alloc(hdl,
c001ad7e0c25 6368751 libzfs interface for mount/umounting all the file systems for a given pool
eschrock
parents: 2082
diff changeset
  1319
				    8 * sizeof (void *))) == NULL)
c001ad7e0c25 6368751 libzfs interface for mount/umounting all the file systems for a given pool
eschrock
parents: 2082
diff changeset
  1320
					goto out;
c001ad7e0c25 6368751 libzfs interface for mount/umounting all the file systems for a given pool
eschrock
parents: 2082
diff changeset
  1321
c001ad7e0c25 6368751 libzfs interface for mount/umounting all the file systems for a given pool
eschrock
parents: 2082
diff changeset
  1322
				alloc = 8;
c001ad7e0c25 6368751 libzfs interface for mount/umounting all the file systems for a given pool
eschrock
parents: 2082
diff changeset
  1323
			} else {
2676
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2500
diff changeset
  1324
				void *ptr;
2474
c001ad7e0c25 6368751 libzfs interface for mount/umounting all the file systems for a given pool
eschrock
parents: 2082
diff changeset
  1325
2676
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2500
diff changeset
  1326
				if ((ptr = zfs_realloc(hdl, mountpoints,
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2500
diff changeset
  1327
				    alloc * sizeof (void *),
2474
c001ad7e0c25 6368751 libzfs interface for mount/umounting all the file systems for a given pool
eschrock
parents: 2082
diff changeset
  1328
				    alloc * 2 * sizeof (void *))) == NULL)
c001ad7e0c25 6368751 libzfs interface for mount/umounting all the file systems for a given pool
eschrock
parents: 2082
diff changeset
  1329
					goto out;
2676
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2500
diff changeset
  1330
				mountpoints = ptr;
2474
c001ad7e0c25 6368751 libzfs interface for mount/umounting all the file systems for a given pool
eschrock
parents: 2082
diff changeset
  1331
2676
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2500
diff changeset
  1332
				if ((ptr = zfs_realloc(hdl, datasets,
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2500
diff changeset
  1333
				    alloc * sizeof (void *),
2474
c001ad7e0c25 6368751 libzfs interface for mount/umounting all the file systems for a given pool
eschrock
parents: 2082
diff changeset
  1334
				    alloc * 2 * sizeof (void *))) == NULL)
c001ad7e0c25 6368751 libzfs interface for mount/umounting all the file systems for a given pool
eschrock
parents: 2082
diff changeset
  1335
					goto out;
2676
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2500
diff changeset
  1336
				datasets = ptr;
2474
c001ad7e0c25 6368751 libzfs interface for mount/umounting all the file systems for a given pool
eschrock
parents: 2082
diff changeset
  1337
c001ad7e0c25 6368751 libzfs interface for mount/umounting all the file systems for a given pool
eschrock
parents: 2082
diff changeset
  1338
				alloc *= 2;
c001ad7e0c25 6368751 libzfs interface for mount/umounting all the file systems for a given pool
eschrock
parents: 2082
diff changeset
  1339
			}
c001ad7e0c25 6368751 libzfs interface for mount/umounting all the file systems for a given pool
eschrock
parents: 2082
diff changeset
  1340
		}
c001ad7e0c25 6368751 libzfs interface for mount/umounting all the file systems for a given pool
eschrock
parents: 2082
diff changeset
  1341
c001ad7e0c25 6368751 libzfs interface for mount/umounting all the file systems for a given pool
eschrock
parents: 2082
diff changeset
  1342
		if ((mountpoints[used] = zfs_strdup(hdl,
c001ad7e0c25 6368751 libzfs interface for mount/umounting all the file systems for a given pool
eschrock
parents: 2082
diff changeset
  1343
		    entry.mnt_mountp)) == NULL)
c001ad7e0c25 6368751 libzfs interface for mount/umounting all the file systems for a given pool
eschrock
parents: 2082
diff changeset
  1344
			goto out;
c001ad7e0c25 6368751 libzfs interface for mount/umounting all the file systems for a given pool
eschrock
parents: 2082
diff changeset
  1345
c001ad7e0c25 6368751 libzfs interface for mount/umounting all the file systems for a given pool
eschrock
parents: 2082
diff changeset
  1346
		/*
c001ad7e0c25 6368751 libzfs interface for mount/umounting all the file systems for a given pool
eschrock
parents: 2082
diff changeset
  1347
		 * This is allowed to fail, in case there is some I/O error.  It
c001ad7e0c25 6368751 libzfs interface for mount/umounting all the file systems for a given pool
eschrock
parents: 2082
diff changeset
  1348
		 * is only used to determine if we need to remove the underlying
c001ad7e0c25 6368751 libzfs interface for mount/umounting all the file systems for a given pool
eschrock
parents: 2082
diff changeset
  1349
		 * mountpoint, so failure is not fatal.
c001ad7e0c25 6368751 libzfs interface for mount/umounting all the file systems for a given pool
eschrock
parents: 2082
diff changeset
  1350
		 */
c001ad7e0c25 6368751 libzfs interface for mount/umounting all the file systems for a given pool
eschrock
parents: 2082
diff changeset
  1351
		datasets[used] = make_dataset_handle(hdl, entry.mnt_special);
c001ad7e0c25 6368751 libzfs interface for mount/umounting all the file systems for a given pool
eschrock
parents: 2082
diff changeset
  1352
c001ad7e0c25 6368751 libzfs interface for mount/umounting all the file systems for a given pool
eschrock
parents: 2082
diff changeset
  1353
		used++;
c001ad7e0c25 6368751 libzfs interface for mount/umounting all the file systems for a given pool
eschrock
parents: 2082
diff changeset
  1354
	}
c001ad7e0c25 6368751 libzfs interface for mount/umounting all the file systems for a given pool
eschrock
parents: 2082
diff changeset
  1355
c001ad7e0c25 6368751 libzfs interface for mount/umounting all the file systems for a given pool
eschrock
parents: 2082
diff changeset
  1356
	/*
c001ad7e0c25 6368751 libzfs interface for mount/umounting all the file systems for a given pool
eschrock
parents: 2082
diff changeset
  1357
	 * At this point, we have the entire list of filesystems, so sort it by
c001ad7e0c25 6368751 libzfs interface for mount/umounting all the file systems for a given pool
eschrock
parents: 2082
diff changeset
  1358
	 * mountpoint.
c001ad7e0c25 6368751 libzfs interface for mount/umounting all the file systems for a given pool
eschrock
parents: 2082
diff changeset
  1359
	 */
c001ad7e0c25 6368751 libzfs interface for mount/umounting all the file systems for a given pool
eschrock
parents: 2082
diff changeset
  1360
	qsort(mountpoints, used, sizeof (char *), mountpoint_compare);
c001ad7e0c25 6368751 libzfs interface for mount/umounting all the file systems for a given pool
eschrock
parents: 2082
diff changeset
  1361
c001ad7e0c25 6368751 libzfs interface for mount/umounting all the file systems for a given pool
eschrock
parents: 2082
diff changeset
  1362
	/*
c001ad7e0c25 6368751 libzfs interface for mount/umounting all the file systems for a given pool
eschrock
parents: 2082
diff changeset
  1363
	 * Walk through and first unshare everything.
c001ad7e0c25 6368751 libzfs interface for mount/umounting all the file systems for a given pool
eschrock
parents: 2082
diff changeset
  1364
	 */
c001ad7e0c25 6368751 libzfs interface for mount/umounting all the file systems for a given pool
eschrock
parents: 2082
diff changeset
  1365
	for (i = 0; i < used; i++) {
5331
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5094
diff changeset
  1366
		zfs_share_proto_t *curr_proto;
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5094
diff changeset
  1367
		for (curr_proto = share_all_proto; *curr_proto != PROTO_END;
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5094
diff changeset
  1368
		    curr_proto++) {
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5094
diff changeset
  1369
			if (is_shared(hdl, mountpoints[i], *curr_proto) &&
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5094
diff changeset
  1370
			    unshare_one(hdl, mountpoints[i],
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5094
diff changeset
  1371
			    mountpoints[i], *curr_proto) != 0)
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5094
diff changeset
  1372
				goto out;
3047ad28a67b PSARC/2007/218 caller_context_t in all VOPs
amw
parents: 5094
diff changeset
  1373
		}
2474
c001ad7e0c25 6368751 libzfs interface for mount/umounting all the file systems for a given pool
eschrock
parents: 2082
diff changeset
  1374
	}
c001ad7e0c25 6368751 libzfs interface for mount/umounting all the file systems for a given pool
eschrock
parents: 2082
diff changeset
  1375
c001ad7e0c25 6368751 libzfs interface for mount/umounting all the file systems for a given pool
eschrock
parents: 2082
diff changeset
  1376
	/*
c001ad7e0c25 6368751 libzfs interface for mount/umounting all the file systems for a given pool
eschrock
parents: 2082
diff changeset
  1377
	 * Now unmount everything, removing the underlying directories as
c001ad7e0c25 6368751 libzfs interface for mount/umounting all the file systems for a given pool
eschrock
parents: 2082
diff changeset
  1378
	 * appropriate.
c001ad7e0c25 6368751 libzfs interface for mount/umounting all the file systems for a given pool
eschrock
parents: 2082
diff changeset
  1379
	 */
c001ad7e0c25 6368751 libzfs interface for mount/umounting all the file systems for a given pool
eschrock
parents: 2082
diff changeset
  1380
	for (i = 0; i < used; i++) {
c001ad7e0c25 6368751 libzfs interface for mount/umounting all the file systems for a given pool
eschrock
parents: 2082
diff changeset
  1381
		if (unmount_one(hdl, mountpoints[i], flags) != 0)
c001ad7e0c25 6368751 libzfs interface for mount/umounting all the file systems for a given pool
eschrock
parents: 2082
diff changeset
  1382
			goto out;
2676
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2500
diff changeset
  1383
	}
2474
c001ad7e0c25 6368751 libzfs interface for mount/umounting all the file systems for a given pool
eschrock
parents: 2082
diff changeset
  1384
2676
5cee47eddab6 PSARC 2006/486 ZFS canmount property
eschrock
parents: 2500
diff changeset
  1385
	for (i = 0; i < used; i++) {
2474
c001ad7e0c25 6368751 libzfs interface for mount/umounting all the file systems for a given pool
eschrock
parents: 2082
diff changeset
  1386
		if (datasets[i])
c001ad7e0c25 6368751 libzfs interface for mount/umounting all the file systems for a given pool
eschrock
parents: 2082
diff changeset
  1387
			remove_mountpoint(datasets[i]);
c001ad7e0c25 6368751 libzfs interface for mount/umounting all the file systems for a given pool
eschrock
parents: 2082
diff changeset
  1388
	}
c001ad7e0c25 6368751 libzfs interface for mount/umounting all the file systems for a given pool
eschrock
parents: 2082
diff changeset
  1389
c001ad7e0c25 6368751 libzfs interface for mount/umounting all the file systems for a given pool
eschrock
parents: 2082
diff changeset
  1390
	ret = 0;
c001ad7e0c25 6368751 libzfs interface for mount/umounting all the file systems for a given pool
eschrock
parents: 2082
diff changeset
  1391
out:
c001ad7e0c25 6368751 libzfs interface for mount/umounting all the file systems for a given pool
eschrock
parents: 2082
diff changeset
  1392
	for (i = 0; i < used; i++) {
c001ad7e0c25 6368751 libzfs interface for mount/umounting all the file systems for a given pool
eschrock
parents: 2082
diff changeset
  1393
		if (datasets[i])
c001ad7e0c25 6368751 libzfs interface for mount/umounting all the file systems for a given pool
eschrock
parents: 2082
diff changeset
  1394
			zfs_close(datasets[i]);
c001ad7e0c25 6368751 libzfs interface for mount/umounting all the file systems for a given pool
eschrock
parents: 2082
diff changeset
  1395
		free(mountpoints[i]);
c001ad7e0c25 6368751 libzfs interface for mount/umounting all the file systems for a given pool
eschrock
parents: 2082
diff changeset
  1396
	}
c001ad7e0c25 6368751 libzfs interface for mount/umounting all the file systems for a given pool
eschrock
parents: 2082
diff changeset
  1397
	free(datasets);
c001ad7e0c25 6368751 libzfs interface for mount/umounting all the file systems for a given pool
eschrock
parents: 2082
diff changeset
  1398
	free(mountpoints);
c001ad7e0c25 6368751 libzfs interface for mount/umounting all the file systems for a given pool
eschrock
parents: 2082
diff changeset
  1399
c001ad7e0c25 6368751 libzfs interface for mount/umounting all the file systems for a given pool
eschrock
parents: 2082
diff changeset
  1400
	return (ret);
c001ad7e0c25 6368751 libzfs interface for mount/umounting all the file systems for a given pool
eschrock
parents: 2082
diff changeset
  1401
}