8fc257994d
in Solaris 10 updates 141445-09 and 142901-14.
Detailed information:
(OpenSolaris revisions and Bug IDs, Solaris 10 patch numbers)
7844:effed23820ae
6755435 zfs_open() and zfs_close() needs to use ZFS_ENTER/ZFS_VERIFY_ZP (141445-01)
7897:e520d8258820
6748436 inconsistent zpool.cache in boot_archive could panic a zfs root filesystem upon boot-up (141445-01)
7965:b795da521357
6740164 zpool attach can create an illegal root pool (141909-02)
8084:b811cc60d650
6769612 zpool_import() will continue to write to cachefile even if altroot is set (N/A)
8121:7fd09d4ebd9c
6757430 want an option for zdb to disable space map loading and leak tracking (141445-01)
8129:e4f45a0bfbb0
6542860 ASSERT: reason != VDEV_LABEL_REMOVE||vdev_inuse(vd, crtxg, reason, 0) (141445-01)
8188:fd00c0a81e80
6761100 want zdb option to select older uberblocks (141445-01)
8190:6eeea43ced42
6774886 zfs_setattr() won't allow ndmp to restore SUNWattr_rw (141445-01)
8225:59a9961c2aeb
6737463 panic while trying to write out config file if root pool import fails (141445-01)
8227:f7d7be9b1f56
6765294 Refactor replay (141445-01)
8228:51e9ca9ee3a5
6572357 libzfs should do more to avoid mnttab lookups (141909-01)
6572376 zfs_iter_filesystems and zfs_iter_snapshots get objset stats twice (141909-01)
8241:5a60f16123ba
6328632 zpool offline is a bit too conservative (141445-01)
6739487 ASSERT: txg <= spa_final_txg due to scrub/export race (141445-01)
6767129 ASSERT: cvd->vdev_isspare, in spa_vdev_detach() (141445-01)
6747698 checksum failures after offline -t / export / import / scrub (141445-01)
6745863 ZFS writes to disk after it has been offlined (141445-01)
6722540 50% slowdown on scrub/resilver with certain vdev configurations (141445-01)
6759999 resilver logic rewrites ditto blocks on both source and destination (141445-01)
6758107 I/O should never suspend during spa_load() (141445-01)
6776548 codereview(1) runs off the page when faced with multi-line comments (N/A)
6761406 AMD errata 91 workaround doesn't work on 64-bit systems (141445-01)
8242:e46e4b2f0a03
6770866 GRUB/ZFS should require physical path or devid, but not both (141445-01)
8269:03a7e9050cfd
6674216 "zfs share" doesn't work, but "zfs set sharenfs=on" does (141445-01)
6621164 $SRC/cmd/zfs/zfs_main.c seems to have a syntax error in the translation note (141445-01)
6635482 i18n problems in libzfs_dataset.c and zfs_main.c (141445-01)
6595194 "zfs get" VALUE column is as wide as NAME (141445-01)
6722991 vdev_disk.c: error checking for ddi_pathname_to_dev_t() must test for NODEV (141445-01)
6396518 ASSERT strings shouldn't be pre-processed (141445-01)
8274:846b39508aff
6713916 scrub/resilver needlessly decompress data (141445-01)
8343:655db2375fed
6739553 libzfs_status msgid table is out of sync (141445-01)
6784104 libzfs unfairly rejects numerical values greater than 2^63 (141445-01)
6784108 zfs_realloc() should not free original memory on failure (141445-01)
8525:e0e0e525d0f8
6788830 set large value to reservation cause core dump (141445-01)
6791064 want sysevents for ZFS scrub (141445-01)
6791066 need to be able to set cachefile on faulted pools (141445-01)
6791071 zpool_do_import() should not enable datasets on faulted pools (141445-01)
6792134 getting multiple properties on a faulted pool leads to confusion (141445-01)
8547:bcc7b46e5ff7
6792884 Vista clients cannot access .zfs (141445-01)
8632:36ef517870a3
6798384 It can take a village to raise a zio (141445-01)
8636:7e4ce9158df3
6551866 deadlock between zfs_write(), zfs_freesp(), and zfs_putapage() (141909-01)
6504953 zfs_getpage() misunderstands VOP_GETPAGE() interface (141909-01)
6702206 ZFS read/writer lock contention throttles sendfile() benchmark (141445-01)
6780491 Zone on a ZFS filesystem has poor fork/exec performance (141445-01)
6747596 assertion failed: DVA_EQUAL(BP_IDENTITY(&zio->io_bp_orig), BP_IDENTITY(zio->io_bp))); (141445-01)
8692:692d4668b40d
6801507 ZFS read aggregation should not mind the gap (141445-01)
8697:e62d2612c14d
6633095 creating a filesystem with many properties set is slow (141445-01)
8768:dfecfdbb27ed
6775697 oracle crashes when overwriting after hitting quota on zfs (141909-01)
8811:f8deccf701cf
6790687 libzfs mnttab caching ignores external changes (141445-01)
6791101 memory leak from libzfs_mnttab_init (141445-01)
8845:91af0d9c0790
6800942 smb_session_create() incorrectly stores IP addresses (N/A)
6582163 Access Control List (ACL) for shares (141445-01)
6804954 smb_search - shortname field should be space padded following the NULL terminator (N/A)
6800184 Panic at smb_oplock_conflict+0x35() (N/A)
8876:59d2e67b4b65
6803822 Reboot after replacement of system disk in a ZFS mirror drops to grub> prompt (141445-01)
8924:5af812f84759
6789318 coredump when issue zdb -uuuu poolname/ (141445-01)
6790345 zdb -dddd -e poolname coredump (141445-01)
6797109 zdb: 'zdb -dddddd pool_name/fs_name inode' coredump if the file with inode was deleted (141445-01)
6797118
zdb: 'zdb -dddddd poolname inum' coredump if I miss the fs name (141445-01)
6803343 shareiscsi=on failed, iscsitgtd failed request to share (141445-01)
9030:243fd360d81f
6815893 hang mounting a dataset after booting into a new boot environment (141445-01)
9056:826e1858a846
6809691 'zpool create -f' no longer overwrites ufs infomation (141445-01)
9179:d8fbd96b79b3
6790064 zfs needs to determine uid and gid earlier in create process (141445-01)
9214:8d350e5d04aa
6604992 forced unmount + being in .zfs/snapshot/<snap1> = not happy (141909-01)
6810367 assertion failed: dvp->v_flag & VROOT, file: ../../common/fs/gfs.c, line: 426 (141909-01)
9229:e3f8b41e5db4
6807765 ztest_dsl_dataset_promote_busy needs to clean up after ENOSPC (141445-01)
9230:e4561e3eb1ef
6821169 offlining a device results in checksum errors (141445-01)
6821170 ZFS should not increment error stats for unavailable devices (141445-01)
6824006 need to increase issue and interrupt taskqs threads in zfs (141445-01)
9234:bffdc4fc05c4
6792139 recovering from a suspended pool needs some work (141445-01)
6794830 reboot command hangs on a failed zfs pool (141445-01)
9246:67c03c93c071
6824062 System panicked in zfs_mount due to NULL pointer dereference when running btts and svvs tests (141909-01)
9276:a8a7fc849933
6816124 System crash running zpool destroy on broken zpool (141445-03)
9355:09928982c591
6818183 zfs snapshot -r is slow due to set_snap_props() doing txg_wait_synced() for each new snapshot (141445-03)
9391:413d0661ef33
6710376 log device can show incorrect status when other parts of pool are degraded (141445-03)
9396:f41cf682d0d3 (part already merged)
6501037 want user/group quotas on ZFS (141445-03)
6827260 assertion failed in arc_read(): hdr == pbuf->b_hdr (141445-03)
6815592 panic: No such hold X on refcount Y from zfs_znode_move (141445-03)
6759986 zfs list shows temporary %clone when doing online zfs recv (141445-03)
9404:319573cd93f8
6774713 zfs ignores canmount=noauto when sharenfs property != off (141445-03)
9412:4aefd8704ce0
6717022 ZFS DMU needs zero-copy support (141445-03)
9425:e7ffacaec3a8
6799895 spa_add_spares() needs to be protected by config lock (141445-03)
6826466 want to post sysevents on hot spare activation (141445-03)
6826468 spa 'allowfaulted' needs some work (141445-03)
6826469 kernel support for storing vdev FRU information (141445-03)
6826470 skip posting checksum errors from DTL regions of leaf vdevs (141445-03)
6826471 I/O errors after device remove probe can confuse FMA (141445-03)
6826472 spares should enjoy some of the benefits of cache devices (141445-03)
9443:2a96d8478e95
6833711 gang leaders shouldn't have to be logical (141445-03)
9463:d0bd231c7518
6764124 want zdb to be able to checksum metadata blocks only (141445-03)
9465:8372081b8019
6830237 zfs panic in zfs_groupmember() (141445-03)
9466:1fdfd1fed9c4
6833162 phantom log device in zpool status (141445-03)
9469:4f68f041ddcd
6824968 add ZFS userquota support to rquotad (141445-03)
9470:6d827468d7b5
6834217 godfather I/O should reexecute (141445-03)
9480:fcff33da767f
6596237 Stop looking and start ganging (141909-02)
9493:9933d599bc93
6623978 lwb->lwb_buf != NULL, file ../../../uts/common/fs/zfs/zil.c, line 787, function zil_lwb_commit (141445-06)
9512:64cafcbcc337
6801810 Commit of aligned streaming rewrites to ZIL device causes unwanted disk reads (N/A)
9515:d3b739d9d043
6586537 async zio taskqs can block out userland commands (142901-09)
9554:787363635b6a
6836768 zfs_userspace() callback has no way to indicate failure (N/A)
9574:1eb6a6ab2c57
6838062 zfs panics when an error is encountered in space_map_load() (141909-02)
9583:b0696cd037cc
6794136 Panic BAD TRAP: type=e when importing degraded zraid pool. (141909-03)
9630:e25a03f552e0
6776104 "zfs import" deadlock between spa_unload() and spa_async_thread() (141445-06)
9653:a70048a304d1
6664765 Unable to remove files when using fat-zap and quota exceeded on ZFS filesystem (141445-06)
9688:127be1845343
6841321 zfs userspace / zfs get userused@ doesn't work on mounted snapshot (N/A)
6843069 zfs get userused@S-1-... doesn't work (N/A)
9873:8ddc892eca6e
6847229 assertion failed: refcount_count(&tx->tx_space_written) + delta <= tx->tx_space_towrite in dmu_tx.c (141445-06)
9904:d260bd3fd47c
6838344 kernel heap corruption detected on zil while stress testing (141445-06)
9951:a4895b3dd543
6844900 zfs_ioc_userspace_upgrade leaks (N/A)
10040:38b25aeeaf7a
6857012 zfs panics on zpool import (141445-06)
10000:241a51d8720c
6848242 zdb -e no longer works as expected (N/A)
10100:4a6965f6bef8
6856634 snv_117 not booting: zfs_parse_bootfs: error2 (141445-07)
10160:a45b03783d44
6861983 zfs should use new name <-> SID interfaces (N/A)
6862984 userquota commands can hang (141445-06)
10299:80845694147f
6696858 zfs receive of incremental replication stream can dereference NULL pointer and crash (N/A)
10302:a9e3d1987706
6696858 zfs receive of incremental replication stream can dereference NULL pointer and crash (fix lint) (N/A)
10575:2a8816c5173b (partial merge)
6882227 spa_async_remove() shouldn't do a full clear (142901-14)
10800:469478b180d9
6880764 fsync on zfs is broken if writes are greater than 32kb on a hard crash and no log attached (142901-09)
6793430 zdb -ivvvv assertion failure: bp->blk_cksum.zc_word[2] == dmu_objset_id(zilog->zl_os) (N/A)
10801:e0bf032e8673 (partial merge)
6822816 assertion failed: zap_remove_int(ds_next_clones_obj) returns ENOENT (142901-09)
10810:b6b161a6ae4a
6892298 buf->b_hdr->b_state != arc_anon, file: ../../common/fs/zfs/arc.c, line: 2849 (142901-09)
10890:499786962772
6807339 spurious checksum errors when replacing a vdev (142901-13)
11249:6c30f7dfc97b
6906110 bad trap panic in zil_replay_log_record (142901-13)
6906946 zfs replay isn't handling uid/gid correctly (142901-13)
11454:6e69bacc1a5a
6898245 suspended zpool should not cause rest of the zfs/zpool commands to hang (142901-10)
11546:42ea6be8961b (partial merge)
6833999 3-way deadlock in dsl_dataset_hold_ref() and dsl_sync_task_group_sync() (142901-09)
Discussed with: pjd
Approved by: delphij (mentor)
Obtained from: OpenSolaris (multiple Bug IDs)
MFC after: 2 months
1410 lines
34 KiB
C
1410 lines
34 KiB
C
/*
|
|
* CDDL HEADER START
|
|
*
|
|
* The contents of this file are subject to the terms of the
|
|
* Common Development and Distribution License (the "License").
|
|
* You may not use this file except in compliance with the License.
|
|
*
|
|
* You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
|
|
* or http://www.opensolaris.org/os/licensing.
|
|
* See the License for the specific language governing permissions
|
|
* and limitations under the License.
|
|
*
|
|
* When distributing Covered Code, include this CDDL HEADER in each
|
|
* file and include the License file at usr/src/OPENSOLARIS.LICENSE.
|
|
* If applicable, add the following below this CDDL HEADER, with the
|
|
* fields enclosed by brackets "[]" replaced with your own identifying
|
|
* information: Portions Copyright [yyyy] [name of copyright owner]
|
|
*
|
|
* CDDL HEADER END
|
|
*/
|
|
|
|
/*
|
|
* Copyright 2009 Sun Microsystems, Inc. All rights reserved.
|
|
* Use is subject to license terms.
|
|
*/
|
|
|
|
/*
|
|
* Routines to manage ZFS mounts. We separate all the nasty routines that have
|
|
* to deal with the OS. The following functions are the main entry points --
|
|
* they are used by mount and unmount and when changing a filesystem's
|
|
* mountpoint.
|
|
*
|
|
* zfs_is_mounted()
|
|
* zfs_mount()
|
|
* zfs_unmount()
|
|
* zfs_unmountall()
|
|
*
|
|
* This file also contains the functions used to manage sharing filesystems via
|
|
* NFS and iSCSI:
|
|
*
|
|
* zfs_is_shared()
|
|
* zfs_share()
|
|
* zfs_unshare()
|
|
*
|
|
* zfs_is_shared_nfs()
|
|
* zfs_is_shared_smb()
|
|
* zfs_is_shared_iscsi()
|
|
* zfs_share_proto()
|
|
* zfs_shareall();
|
|
* zfs_share_iscsi()
|
|
* zfs_unshare_nfs()
|
|
* zfs_unshare_smb()
|
|
* zfs_unshareall_nfs()
|
|
* zfs_unshareall_smb()
|
|
* zfs_unshareall()
|
|
* zfs_unshareall_bypath()
|
|
* zfs_unshare_iscsi()
|
|
*
|
|
* The following functions are available for pool consumers, and will
|
|
* mount/unmount and share/unshare all datasets within pool:
|
|
*
|
|
* zpool_enable_datasets()
|
|
* zpool_disable_datasets()
|
|
*/
|
|
|
|
#include <dirent.h>
|
|
#include <dlfcn.h>
|
|
#include <errno.h>
|
|
#include <libgen.h>
|
|
#include <libintl.h>
|
|
#include <stdio.h>
|
|
#include <stdlib.h>
|
|
#include <strings.h>
|
|
#include <unistd.h>
|
|
#include <zone.h>
|
|
#include <sys/mntent.h>
|
|
#include <sys/mount.h>
|
|
#include <sys/stat.h>
|
|
|
|
#include <libzfs.h>
|
|
|
|
#include "libzfs_impl.h"
|
|
|
|
#include <libshare.h>
|
|
|
|
#define MAXISALEN 257 /* based on sysinfo(2) man page */
|
|
|
|
static int zfs_share_proto(zfs_handle_t *, zfs_share_proto_t *);
|
|
zfs_share_type_t zfs_is_shared_proto(zfs_handle_t *, char **,
|
|
zfs_share_proto_t);
|
|
|
|
static int (*iscsitgt_zfs_share)(const char *);
|
|
static int (*iscsitgt_zfs_unshare)(const char *);
|
|
static int (*iscsitgt_zfs_is_shared)(const char *);
|
|
static int (*iscsitgt_svc_online)();
|
|
|
|
/*
|
|
* The share protocols table must be in the same order as the zfs_share_prot_t
|
|
* enum in libzfs_impl.h
|
|
*/
|
|
typedef struct {
|
|
zfs_prop_t p_prop;
|
|
char *p_name;
|
|
int p_share_err;
|
|
int p_unshare_err;
|
|
} proto_table_t;
|
|
|
|
proto_table_t proto_table[PROTO_END] = {
|
|
{ZFS_PROP_SHARENFS, "nfs", EZFS_SHARENFSFAILED, EZFS_UNSHARENFSFAILED},
|
|
{ZFS_PROP_SHARESMB, "smb", EZFS_SHARESMBFAILED, EZFS_UNSHARESMBFAILED},
|
|
};
|
|
|
|
zfs_share_proto_t nfs_only[] = {
|
|
PROTO_NFS,
|
|
PROTO_END
|
|
};
|
|
|
|
zfs_share_proto_t smb_only[] = {
|
|
PROTO_SMB,
|
|
PROTO_END
|
|
};
|
|
zfs_share_proto_t share_all_proto[] = {
|
|
PROTO_NFS,
|
|
PROTO_SMB,
|
|
PROTO_END
|
|
};
|
|
|
|
#pragma init(zfs_iscsi_init)
|
|
static void
|
|
zfs_iscsi_init(void)
|
|
{
|
|
void *libiscsitgt;
|
|
|
|
if ((libiscsitgt = dlopen("/lib/libiscsitgt.so.1",
|
|
RTLD_LAZY | RTLD_GLOBAL)) == NULL ||
|
|
(iscsitgt_zfs_share = (int (*)(const char *))dlsym(libiscsitgt,
|
|
"iscsitgt_zfs_share")) == NULL ||
|
|
(iscsitgt_zfs_unshare = (int (*)(const char *))dlsym(libiscsitgt,
|
|
"iscsitgt_zfs_unshare")) == NULL ||
|
|
(iscsitgt_zfs_is_shared = (int (*)(const char *))dlsym(libiscsitgt,
|
|
"iscsitgt_zfs_is_shared")) == NULL ||
|
|
(iscsitgt_svc_online = (int (*)(const char *))dlsym(libiscsitgt,
|
|
"iscsitgt_svc_online")) == NULL) {
|
|
iscsitgt_zfs_share = NULL;
|
|
iscsitgt_zfs_unshare = NULL;
|
|
iscsitgt_zfs_is_shared = NULL;
|
|
iscsitgt_svc_online = NULL;
|
|
}
|
|
}
|
|
|
|
/*
|
|
* Search the sharetab for the given mountpoint and protocol, returning
|
|
* a zfs_share_type_t value.
|
|
*/
|
|
static zfs_share_type_t
|
|
is_shared(libzfs_handle_t *hdl, const char *mountpoint, zfs_share_proto_t proto)
|
|
{
|
|
char buf[MAXPATHLEN], *tab;
|
|
char *ptr;
|
|
|
|
if (hdl->libzfs_sharetab == NULL)
|
|
return (SHARED_NOT_SHARED);
|
|
|
|
(void) fseek(hdl->libzfs_sharetab, 0, SEEK_SET);
|
|
|
|
while (fgets(buf, sizeof (buf), hdl->libzfs_sharetab) != NULL) {
|
|
|
|
/* the mountpoint is the first entry on each line */
|
|
if ((tab = strchr(buf, '\t')) == NULL)
|
|
continue;
|
|
|
|
*tab = '\0';
|
|
if (strcmp(buf, mountpoint) == 0) {
|
|
#if defined(sun)
|
|
/*
|
|
* the protocol field is the third field
|
|
* skip over second field
|
|
*/
|
|
ptr = ++tab;
|
|
if ((tab = strchr(ptr, '\t')) == NULL)
|
|
continue;
|
|
ptr = ++tab;
|
|
if ((tab = strchr(ptr, '\t')) == NULL)
|
|
continue;
|
|
*tab = '\0';
|
|
if (strcmp(ptr,
|
|
proto_table[proto].p_name) == 0) {
|
|
switch (proto) {
|
|
case PROTO_NFS:
|
|
return (SHARED_NFS);
|
|
case PROTO_SMB:
|
|
return (SHARED_SMB);
|
|
default:
|
|
return (0);
|
|
}
|
|
}
|
|
#else
|
|
if (proto == PROTO_NFS)
|
|
return (SHARED_NFS);
|
|
#endif
|
|
}
|
|
}
|
|
|
|
return (SHARED_NOT_SHARED);
|
|
}
|
|
|
|
#if 0
|
|
/*
|
|
* Returns true if the specified directory is empty. If we can't open the
|
|
* directory at all, return true so that the mount can fail with a more
|
|
* informative error message.
|
|
*/
|
|
static boolean_t
|
|
dir_is_empty(const char *dirname)
|
|
{
|
|
DIR *dirp;
|
|
struct dirent64 *dp;
|
|
|
|
if ((dirp = opendir(dirname)) == NULL)
|
|
return (B_TRUE);
|
|
|
|
while ((dp = readdir64(dirp)) != NULL) {
|
|
|
|
if (strcmp(dp->d_name, ".") == 0 ||
|
|
strcmp(dp->d_name, "..") == 0)
|
|
continue;
|
|
|
|
(void) closedir(dirp);
|
|
return (B_FALSE);
|
|
}
|
|
|
|
(void) closedir(dirp);
|
|
return (B_TRUE);
|
|
}
|
|
#endif
|
|
|
|
/*
|
|
* Checks to see if the mount is active. If the filesystem is mounted, we fill
|
|
* in 'where' with the current mountpoint, and return 1. Otherwise, we return
|
|
* 0.
|
|
*/
|
|
boolean_t
|
|
is_mounted(libzfs_handle_t *zfs_hdl, const char *special, char **where)
|
|
{
|
|
struct mnttab entry;
|
|
|
|
if (libzfs_mnttab_find(zfs_hdl, special, &entry) != 0)
|
|
return (B_FALSE);
|
|
|
|
if (where != NULL)
|
|
*where = zfs_strdup(zfs_hdl, entry.mnt_mountp);
|
|
|
|
return (B_TRUE);
|
|
}
|
|
|
|
boolean_t
|
|
zfs_is_mounted(zfs_handle_t *zhp, char **where)
|
|
{
|
|
return (is_mounted(zhp->zfs_hdl, zfs_get_name(zhp), where));
|
|
}
|
|
|
|
/*
|
|
* Returns true if the given dataset is mountable, false otherwise. Returns the
|
|
* mountpoint in 'buf'.
|
|
*/
|
|
static boolean_t
|
|
zfs_is_mountable(zfs_handle_t *zhp, char *buf, size_t buflen,
|
|
zprop_source_t *source)
|
|
{
|
|
char sourceloc[ZFS_MAXNAMELEN];
|
|
zprop_source_t sourcetype;
|
|
|
|
if (!zfs_prop_valid_for_type(ZFS_PROP_MOUNTPOINT, zhp->zfs_type))
|
|
return (B_FALSE);
|
|
|
|
verify(zfs_prop_get(zhp, ZFS_PROP_MOUNTPOINT, buf, buflen,
|
|
&sourcetype, sourceloc, sizeof (sourceloc), B_FALSE) == 0);
|
|
|
|
if (strcmp(buf, ZFS_MOUNTPOINT_NONE) == 0 ||
|
|
strcmp(buf, ZFS_MOUNTPOINT_LEGACY) == 0)
|
|
return (B_FALSE);
|
|
|
|
if (zfs_prop_get_int(zhp, ZFS_PROP_CANMOUNT) == ZFS_CANMOUNT_OFF)
|
|
return (B_FALSE);
|
|
|
|
if (zfs_prop_get_int(zhp, ZFS_PROP_ZONED) &&
|
|
getzoneid() == GLOBAL_ZONEID)
|
|
return (B_FALSE);
|
|
|
|
if (source)
|
|
*source = sourcetype;
|
|
|
|
return (B_TRUE);
|
|
}
|
|
|
|
/*
|
|
* Mount the given filesystem.
|
|
*/
|
|
int
|
|
zfs_mount(zfs_handle_t *zhp, const char *options, int flags)
|
|
{
|
|
struct stat buf;
|
|
char mountpoint[ZFS_MAXPROPLEN];
|
|
char mntopts[MNT_LINE_MAX];
|
|
libzfs_handle_t *hdl = zhp->zfs_hdl;
|
|
|
|
if (options == NULL)
|
|
mntopts[0] = '\0';
|
|
else
|
|
(void) strlcpy(mntopts, options, sizeof (mntopts));
|
|
|
|
if (!zfs_is_mountable(zhp, mountpoint, sizeof (mountpoint), NULL))
|
|
return (0);
|
|
|
|
/* Create the directory if it doesn't already exist */
|
|
if (lstat(mountpoint, &buf) != 0) {
|
|
if (mkdirp(mountpoint, 0755) != 0) {
|
|
zfs_error_aux(hdl, dgettext(TEXT_DOMAIN,
|
|
"failed to create mountpoint"));
|
|
return (zfs_error_fmt(hdl, EZFS_MOUNTFAILED,
|
|
dgettext(TEXT_DOMAIN, "cannot mount '%s'"),
|
|
mountpoint));
|
|
}
|
|
}
|
|
|
|
#if 0 /* FreeBSD: overlay mounts are not checked. */
|
|
/*
|
|
* Determine if the mountpoint is empty. If so, refuse to perform the
|
|
* mount. We don't perform this check if MS_OVERLAY is specified, which
|
|
* would defeat the point. We also avoid this check if 'remount' is
|
|
* specified.
|
|
*/
|
|
if ((flags & MS_OVERLAY) == 0 &&
|
|
strstr(mntopts, MNTOPT_REMOUNT) == NULL &&
|
|
!dir_is_empty(mountpoint)) {
|
|
zfs_error_aux(hdl, dgettext(TEXT_DOMAIN,
|
|
"directory is not empty"));
|
|
return (zfs_error_fmt(hdl, EZFS_MOUNTFAILED,
|
|
dgettext(TEXT_DOMAIN, "cannot mount '%s'"), mountpoint));
|
|
}
|
|
#endif
|
|
|
|
/* perform the mount */
|
|
if (zmount(zfs_get_name(zhp), mountpoint, flags,
|
|
MNTTYPE_ZFS, NULL, 0, mntopts, sizeof (mntopts)) != 0) {
|
|
/*
|
|
* Generic errors are nasty, but there are just way too many
|
|
* from mount(), and they're well-understood. We pick a few
|
|
* common ones to improve upon.
|
|
*/
|
|
if (errno == EBUSY) {
|
|
zfs_error_aux(hdl, dgettext(TEXT_DOMAIN,
|
|
"mountpoint or dataset is busy"));
|
|
} else if (errno == EPERM) {
|
|
zfs_error_aux(hdl, dgettext(TEXT_DOMAIN,
|
|
"Insufficient privileges"));
|
|
} else {
|
|
zfs_error_aux(hdl, strerror(errno));
|
|
}
|
|
return (zfs_error_fmt(hdl, EZFS_MOUNTFAILED,
|
|
dgettext(TEXT_DOMAIN, "cannot mount '%s'"),
|
|
zhp->zfs_name));
|
|
}
|
|
|
|
/* add the mounted entry into our cache */
|
|
libzfs_mnttab_add(hdl, zfs_get_name(zhp), mountpoint,
|
|
mntopts);
|
|
return (0);
|
|
}
|
|
|
|
/*
|
|
* Unmount a single filesystem.
|
|
*/
|
|
static int
|
|
unmount_one(libzfs_handle_t *hdl, const char *mountpoint, int flags)
|
|
{
|
|
if (unmount(mountpoint, flags) != 0) {
|
|
zfs_error_aux(hdl, strerror(errno));
|
|
return (zfs_error_fmt(hdl, EZFS_UMOUNTFAILED,
|
|
dgettext(TEXT_DOMAIN, "cannot unmount '%s'"),
|
|
mountpoint));
|
|
}
|
|
|
|
return (0);
|
|
}
|
|
|
|
/*
|
|
* Unmount the given filesystem.
|
|
*/
|
|
int
|
|
zfs_unmount(zfs_handle_t *zhp, const char *mountpoint, int flags)
|
|
{
|
|
libzfs_handle_t *hdl = zhp->zfs_hdl;
|
|
struct mnttab entry;
|
|
char *mntpt = NULL;
|
|
|
|
/* check to see if we need to unmount the filesystem */
|
|
if (mountpoint != NULL || ((zfs_get_type(zhp) == ZFS_TYPE_FILESYSTEM) &&
|
|
libzfs_mnttab_find(hdl, zhp->zfs_name, &entry) == 0)) {
|
|
/*
|
|
* mountpoint may have come from a call to
|
|
* getmnt/getmntany if it isn't NULL. If it is NULL,
|
|
* we know it comes from libzfs_mnttab_find which can
|
|
* then get freed later. We strdup it to play it safe.
|
|
*/
|
|
if (mountpoint == NULL)
|
|
mntpt = zfs_strdup(hdl, entry.mnt_mountp);
|
|
else
|
|
mntpt = zfs_strdup(hdl, mountpoint);
|
|
|
|
/*
|
|
* Unshare and unmount the filesystem
|
|
*/
|
|
if (zfs_unshare_proto(zhp, mntpt, share_all_proto) != 0)
|
|
return (-1);
|
|
|
|
if (unmount_one(hdl, mntpt, flags) != 0) {
|
|
free(mntpt);
|
|
(void) zfs_shareall(zhp);
|
|
return (-1);
|
|
}
|
|
libzfs_mnttab_remove(hdl, zhp->zfs_name);
|
|
free(mntpt);
|
|
}
|
|
|
|
return (0);
|
|
}
|
|
|
|
/*
|
|
* Unmount this filesystem and any children inheriting the mountpoint property.
|
|
* To do this, just act like we're changing the mountpoint property, but don't
|
|
* remount the filesystems afterwards.
|
|
*/
|
|
int
|
|
zfs_unmountall(zfs_handle_t *zhp, int flags)
|
|
{
|
|
prop_changelist_t *clp;
|
|
int ret;
|
|
|
|
clp = changelist_gather(zhp, ZFS_PROP_MOUNTPOINT, 0, flags);
|
|
if (clp == NULL)
|
|
return (-1);
|
|
|
|
ret = changelist_prefix(clp);
|
|
changelist_free(clp);
|
|
|
|
return (ret);
|
|
}
|
|
|
|
boolean_t
|
|
zfs_is_shared(zfs_handle_t *zhp)
|
|
{
|
|
zfs_share_type_t rc = 0;
|
|
zfs_share_proto_t *curr_proto;
|
|
|
|
if (ZFS_IS_VOLUME(zhp))
|
|
return (zfs_is_shared_iscsi(zhp));
|
|
|
|
for (curr_proto = share_all_proto; *curr_proto != PROTO_END;
|
|
curr_proto++)
|
|
rc |= zfs_is_shared_proto(zhp, NULL, *curr_proto);
|
|
|
|
return (rc ? B_TRUE : B_FALSE);
|
|
}
|
|
|
|
int
|
|
zfs_share(zfs_handle_t *zhp)
|
|
{
|
|
if (ZFS_IS_VOLUME(zhp))
|
|
return (zfs_share_iscsi(zhp));
|
|
|
|
return (zfs_share_proto(zhp, share_all_proto));
|
|
}
|
|
|
|
int
|
|
zfs_unshare(zfs_handle_t *zhp)
|
|
{
|
|
if (ZFS_IS_VOLUME(zhp))
|
|
return (zfs_unshare_iscsi(zhp));
|
|
|
|
return (zfs_unshareall(zhp));
|
|
}
|
|
|
|
/*
|
|
* Check to see if the filesystem is currently shared.
|
|
*/
|
|
zfs_share_type_t
|
|
zfs_is_shared_proto(zfs_handle_t *zhp, char **where, zfs_share_proto_t proto)
|
|
{
|
|
char *mountpoint;
|
|
zfs_share_type_t rc;
|
|
|
|
if (!zfs_is_mounted(zhp, &mountpoint))
|
|
return (SHARED_NOT_SHARED);
|
|
|
|
if (rc = is_shared(zhp->zfs_hdl, mountpoint, proto)) {
|
|
if (where != NULL)
|
|
*where = mountpoint;
|
|
else
|
|
free(mountpoint);
|
|
return (rc);
|
|
} else {
|
|
free(mountpoint);
|
|
return (SHARED_NOT_SHARED);
|
|
}
|
|
}
|
|
|
|
boolean_t
|
|
zfs_is_shared_nfs(zfs_handle_t *zhp, char **where)
|
|
{
|
|
return (zfs_is_shared_proto(zhp, where,
|
|
PROTO_NFS) != SHARED_NOT_SHARED);
|
|
}
|
|
|
|
boolean_t
|
|
zfs_is_shared_smb(zfs_handle_t *zhp, char **where)
|
|
{
|
|
return (zfs_is_shared_proto(zhp, where,
|
|
PROTO_SMB) != SHARED_NOT_SHARED);
|
|
}
|
|
|
|
/*
|
|
* Make sure things will work if libshare isn't installed by using
|
|
* wrapper functions that check to see that the pointers to functions
|
|
* initialized in _zfs_init_libshare() are actually present.
|
|
*/
|
|
|
|
#if 0
|
|
static sa_handle_t (*_sa_init)(int);
|
|
static void (*_sa_fini)(sa_handle_t);
|
|
static sa_share_t (*_sa_find_share)(sa_handle_t, char *);
|
|
static int (*_sa_enable_share)(sa_share_t, char *);
|
|
static int (*_sa_disable_share)(sa_share_t, char *);
|
|
static char *(*_sa_errorstr)(int);
|
|
static int (*_sa_parse_legacy_options)(sa_group_t, char *, char *);
|
|
static boolean_t (*_sa_needs_refresh)(sa_handle_t *);
|
|
static libzfs_handle_t *(*_sa_get_zfs_handle)(sa_handle_t);
|
|
static int (*_sa_zfs_process_share)(sa_handle_t, sa_group_t, sa_share_t,
|
|
char *, char *, zprop_source_t, char *, char *, char *);
|
|
static void (*_sa_update_sharetab_ts)(sa_handle_t);
|
|
#endif
|
|
|
|
/*
|
|
* _zfs_init_libshare()
|
|
*
|
|
* Find the libshare.so.1 entry points that we use here and save the
|
|
* values to be used later. This is triggered by the runtime loader.
|
|
* Make sure the correct ISA version is loaded.
|
|
*/
|
|
|
|
#pragma init(_zfs_init_libshare)
|
|
static void
|
|
_zfs_init_libshare(void)
|
|
{
|
|
#if 0
|
|
void *libshare;
|
|
char path[MAXPATHLEN];
|
|
char isa[MAXISALEN];
|
|
|
|
#if defined(_LP64)
|
|
if (sysinfo(SI_ARCHITECTURE_64, isa, MAXISALEN) == -1)
|
|
isa[0] = '\0';
|
|
#else
|
|
isa[0] = '\0';
|
|
#endif
|
|
(void) snprintf(path, MAXPATHLEN,
|
|
"/usr/lib/%s/libshare.so.1", isa);
|
|
|
|
if ((libshare = dlopen(path, RTLD_LAZY | RTLD_GLOBAL)) != NULL) {
|
|
_sa_init = (sa_handle_t (*)(int))dlsym(libshare, "sa_init");
|
|
_sa_fini = (void (*)(sa_handle_t))dlsym(libshare, "sa_fini");
|
|
_sa_find_share = (sa_share_t (*)(sa_handle_t, char *))
|
|
dlsym(libshare, "sa_find_share");
|
|
_sa_enable_share = (int (*)(sa_share_t, char *))dlsym(libshare,
|
|
"sa_enable_share");
|
|
_sa_disable_share = (int (*)(sa_share_t, char *))dlsym(libshare,
|
|
"sa_disable_share");
|
|
_sa_errorstr = (char *(*)(int))dlsym(libshare, "sa_errorstr");
|
|
_sa_parse_legacy_options = (int (*)(sa_group_t, char *, char *))
|
|
dlsym(libshare, "sa_parse_legacy_options");
|
|
_sa_needs_refresh = (boolean_t (*)(sa_handle_t *))
|
|
dlsym(libshare, "sa_needs_refresh");
|
|
_sa_get_zfs_handle = (libzfs_handle_t *(*)(sa_handle_t))
|
|
dlsym(libshare, "sa_get_zfs_handle");
|
|
_sa_zfs_process_share = (int (*)(sa_handle_t, sa_group_t,
|
|
sa_share_t, char *, char *, zprop_source_t, char *,
|
|
char *, char *))dlsym(libshare, "sa_zfs_process_share");
|
|
_sa_update_sharetab_ts = (void (*)(sa_handle_t))
|
|
dlsym(libshare, "sa_update_sharetab_ts");
|
|
if (_sa_init == NULL || _sa_fini == NULL ||
|
|
_sa_find_share == NULL || _sa_enable_share == NULL ||
|
|
_sa_disable_share == NULL || _sa_errorstr == NULL ||
|
|
_sa_parse_legacy_options == NULL ||
|
|
_sa_needs_refresh == NULL || _sa_get_zfs_handle == NULL ||
|
|
_sa_zfs_process_share == NULL ||
|
|
_sa_update_sharetab_ts == NULL) {
|
|
_sa_init = NULL;
|
|
_sa_fini = NULL;
|
|
_sa_disable_share = NULL;
|
|
_sa_enable_share = NULL;
|
|
_sa_errorstr = NULL;
|
|
_sa_parse_legacy_options = NULL;
|
|
(void) dlclose(libshare);
|
|
_sa_needs_refresh = NULL;
|
|
_sa_get_zfs_handle = NULL;
|
|
_sa_zfs_process_share = NULL;
|
|
_sa_update_sharetab_ts = NULL;
|
|
}
|
|
}
|
|
#endif
|
|
}
|
|
|
|
/*
|
|
* zfs_init_libshare(zhandle, service)
|
|
*
|
|
* Initialize the libshare API if it hasn't already been initialized.
|
|
* In all cases it returns 0 if it succeeded and an error if not. The
|
|
* service value is which part(s) of the API to initialize and is a
|
|
* direct map to the libshare sa_init(service) interface.
|
|
*/
|
|
int
|
|
zfs_init_libshare(libzfs_handle_t *zhandle, int service)
|
|
{
|
|
int ret = SA_OK;
|
|
|
|
#if 0
|
|
if (_sa_init == NULL)
|
|
ret = SA_CONFIG_ERR;
|
|
|
|
if (ret == SA_OK && zhandle->libzfs_shareflags & ZFSSHARE_MISS) {
|
|
/*
|
|
* We had a cache miss. Most likely it is a new ZFS
|
|
* dataset that was just created. We want to make sure
|
|
* so check timestamps to see if a different process
|
|
* has updated any of the configuration. If there was
|
|
* some non-ZFS change, we need to re-initialize the
|
|
* internal cache.
|
|
*/
|
|
zhandle->libzfs_shareflags &= ~ZFSSHARE_MISS;
|
|
if (_sa_needs_refresh != NULL &&
|
|
_sa_needs_refresh(zhandle->libzfs_sharehdl)) {
|
|
zfs_uninit_libshare(zhandle);
|
|
zhandle->libzfs_sharehdl = _sa_init(service);
|
|
}
|
|
}
|
|
|
|
if (ret == SA_OK && zhandle && zhandle->libzfs_sharehdl == NULL)
|
|
zhandle->libzfs_sharehdl = _sa_init(service);
|
|
|
|
if (ret == SA_OK && zhandle->libzfs_sharehdl == NULL)
|
|
ret = SA_NO_MEMORY;
|
|
#endif
|
|
|
|
return (ret);
|
|
}
|
|
|
|
/*
|
|
* zfs_uninit_libshare(zhandle)
|
|
*
|
|
* Uninitialize the libshare API if it hasn't already been
|
|
* uninitialized. It is OK to call multiple times.
|
|
*/
|
|
void
|
|
zfs_uninit_libshare(libzfs_handle_t *zhandle)
|
|
{
|
|
if (zhandle != NULL && zhandle->libzfs_sharehdl != NULL) {
|
|
#if 0
|
|
if (_sa_fini != NULL)
|
|
_sa_fini(zhandle->libzfs_sharehdl);
|
|
#endif
|
|
zhandle->libzfs_sharehdl = NULL;
|
|
}
|
|
}
|
|
|
|
/*
|
|
* zfs_parse_options(options, proto)
|
|
*
|
|
* Call the legacy parse interface to get the protocol specific
|
|
* options using the NULL arg to indicate that this is a "parse" only.
|
|
*/
|
|
int
|
|
zfs_parse_options(char *options, zfs_share_proto_t proto)
|
|
{
|
|
#if 0
|
|
if (_sa_parse_legacy_options != NULL) {
|
|
return (_sa_parse_legacy_options(NULL, options,
|
|
proto_table[proto].p_name));
|
|
}
|
|
return (SA_CONFIG_ERR);
|
|
#else
|
|
return (SA_OK);
|
|
#endif
|
|
}
|
|
|
|
#if 0
|
|
/*
|
|
* zfs_sa_find_share(handle, path)
|
|
*
|
|
* wrapper around sa_find_share to find a share path in the
|
|
* configuration.
|
|
*/
|
|
static sa_share_t
|
|
zfs_sa_find_share(sa_handle_t handle, char *path)
|
|
{
|
|
if (_sa_find_share != NULL)
|
|
return (_sa_find_share(handle, path));
|
|
return (NULL);
|
|
}
|
|
|
|
/*
|
|
* zfs_sa_enable_share(share, proto)
|
|
*
|
|
* Wrapper for sa_enable_share which enables a share for a specified
|
|
* protocol.
|
|
*/
|
|
static int
|
|
zfs_sa_enable_share(sa_share_t share, char *proto)
|
|
{
|
|
if (_sa_enable_share != NULL)
|
|
return (_sa_enable_share(share, proto));
|
|
return (SA_CONFIG_ERR);
|
|
}
|
|
|
|
/*
|
|
* zfs_sa_disable_share(share, proto)
|
|
*
|
|
* Wrapper for sa_enable_share which disables a share for a specified
|
|
* protocol.
|
|
*/
|
|
static int
|
|
zfs_sa_disable_share(sa_share_t share, char *proto)
|
|
{
|
|
if (_sa_disable_share != NULL)
|
|
return (_sa_disable_share(share, proto));
|
|
return (SA_CONFIG_ERR);
|
|
}
|
|
#endif
|
|
|
|
/*
|
|
* Share the given filesystem according to the options in the specified
|
|
* protocol specific properties (sharenfs, sharesmb). We rely
|
|
* on "libshare" to the dirty work for us.
|
|
*/
|
|
static int
|
|
zfs_share_proto(zfs_handle_t *zhp, zfs_share_proto_t *proto)
|
|
{
|
|
char mountpoint[ZFS_MAXPROPLEN];
|
|
char shareopts[ZFS_MAXPROPLEN];
|
|
char sourcestr[ZFS_MAXPROPLEN];
|
|
libzfs_handle_t *hdl = zhp->zfs_hdl;
|
|
zfs_share_proto_t *curr_proto;
|
|
zprop_source_t sourcetype;
|
|
int error, ret;
|
|
|
|
if (!zfs_is_mountable(zhp, mountpoint, sizeof (mountpoint), NULL))
|
|
return (0);
|
|
|
|
for (curr_proto = proto; *curr_proto != PROTO_END; curr_proto++) {
|
|
/*
|
|
* Return success if there are no share options.
|
|
*/
|
|
if (zfs_prop_get(zhp, proto_table[*curr_proto].p_prop,
|
|
shareopts, sizeof (shareopts), &sourcetype, sourcestr,
|
|
ZFS_MAXPROPLEN, B_FALSE) != 0 ||
|
|
strcmp(shareopts, "off") == 0)
|
|
continue;
|
|
|
|
/*
|
|
* If the 'zoned' property is set, then zfs_is_mountable()
|
|
* will have already bailed out if we are in the global zone.
|
|
* But local zones cannot be NFS servers, so we ignore it for
|
|
* local zones as well.
|
|
*/
|
|
if (zfs_prop_get_int(zhp, ZFS_PROP_ZONED))
|
|
continue;
|
|
|
|
if (*curr_proto != PROTO_NFS) {
|
|
fprintf(stderr, "Unsupported share protocol: %d.\n",
|
|
*curr_proto);
|
|
continue;
|
|
}
|
|
|
|
#if 0
|
|
share = zfs_sa_find_share(hdl->libzfs_sharehdl, mountpoint);
|
|
if (share == NULL) {
|
|
/*
|
|
* This may be a new file system that was just
|
|
* created so isn't in the internal cache
|
|
* (second time through). Rather than
|
|
* reloading the entire configuration, we can
|
|
* assume ZFS has done the checking and it is
|
|
* safe to add this to the internal
|
|
* configuration.
|
|
*/
|
|
if (_sa_zfs_process_share(hdl->libzfs_sharehdl,
|
|
NULL, NULL, mountpoint,
|
|
proto_table[*curr_proto].p_name, sourcetype,
|
|
shareopts, sourcestr, zhp->zfs_name) != SA_OK) {
|
|
(void) zfs_error_fmt(hdl,
|
|
proto_table[*curr_proto].p_share_err,
|
|
dgettext(TEXT_DOMAIN, "cannot share '%s'"),
|
|
zfs_get_name(zhp));
|
|
return (-1);
|
|
}
|
|
hdl->libzfs_shareflags |= ZFSSHARE_MISS;
|
|
share = zfs_sa_find_share(hdl->libzfs_sharehdl,
|
|
mountpoint);
|
|
}
|
|
if (share != NULL) {
|
|
int err;
|
|
err = zfs_sa_enable_share(share,
|
|
proto_table[*curr_proto].p_name);
|
|
if (err != SA_OK) {
|
|
(void) zfs_error_fmt(hdl,
|
|
proto_table[*curr_proto].p_share_err,
|
|
dgettext(TEXT_DOMAIN, "cannot share '%s'"),
|
|
zfs_get_name(zhp));
|
|
return (-1);
|
|
}
|
|
} else
|
|
#else
|
|
if (strcmp(shareopts, "on") == 0)
|
|
error = fsshare(ZFS_EXPORTS_PATH, mountpoint, "");
|
|
else
|
|
error = fsshare(ZFS_EXPORTS_PATH, mountpoint, shareopts);
|
|
if (error != 0)
|
|
#endif
|
|
{
|
|
(void) zfs_error_fmt(hdl,
|
|
proto_table[*curr_proto].p_share_err,
|
|
dgettext(TEXT_DOMAIN, "cannot share '%s'"),
|
|
zfs_get_name(zhp));
|
|
return (-1);
|
|
}
|
|
}
|
|
return (0);
|
|
}
|
|
|
|
|
|
int
|
|
zfs_share_nfs(zfs_handle_t *zhp)
|
|
{
|
|
return (zfs_share_proto(zhp, nfs_only));
|
|
}
|
|
|
|
int
|
|
zfs_share_smb(zfs_handle_t *zhp)
|
|
{
|
|
return (zfs_share_proto(zhp, smb_only));
|
|
}
|
|
|
|
int
|
|
zfs_shareall(zfs_handle_t *zhp)
|
|
{
|
|
return (zfs_share_proto(zhp, share_all_proto));
|
|
}
|
|
|
|
/*
|
|
* Unshare a filesystem by mountpoint.
|
|
*/
|
|
static int
|
|
unshare_one(libzfs_handle_t *hdl, const char *name, const char *mountpoint,
|
|
zfs_share_proto_t proto)
|
|
{
|
|
char buf[MAXPATHLEN];
|
|
FILE *fp;
|
|
int error;
|
|
|
|
if (proto != PROTO_NFS) {
|
|
fprintf(stderr, "No SMB support in FreeBSD yet.\n");
|
|
return (EOPNOTSUPP);
|
|
}
|
|
|
|
error = fsunshare(ZFS_EXPORTS_PATH, mountpoint);
|
|
if (error != 0) {
|
|
zfs_error_aux(hdl, "%s", strerror(error));
|
|
return (zfs_error_fmt(hdl, EZFS_UNSHARENFSFAILED,
|
|
dgettext(TEXT_DOMAIN,
|
|
"cannot unshare '%s'"), name));
|
|
}
|
|
|
|
return (0);
|
|
}
|
|
|
|
/*
|
|
* Unshare the given filesystem.
|
|
*/
|
|
int
|
|
zfs_unshare_proto(zfs_handle_t *zhp, const char *mountpoint,
|
|
zfs_share_proto_t *proto)
|
|
{
|
|
libzfs_handle_t *hdl = zhp->zfs_hdl;
|
|
struct mnttab entry;
|
|
char *mntpt = NULL;
|
|
|
|
/* check to see if need to unmount the filesystem */
|
|
rewind(zhp->zfs_hdl->libzfs_mnttab);
|
|
if (mountpoint != NULL)
|
|
mountpoint = mntpt = zfs_strdup(hdl, mountpoint);
|
|
|
|
if (mountpoint != NULL || ((zfs_get_type(zhp) == ZFS_TYPE_FILESYSTEM) &&
|
|
libzfs_mnttab_find(hdl, zfs_get_name(zhp), &entry) == 0)) {
|
|
zfs_share_proto_t *curr_proto;
|
|
|
|
if (mountpoint == NULL)
|
|
mntpt = zfs_strdup(zhp->zfs_hdl, entry.mnt_mountp);
|
|
|
|
for (curr_proto = proto; *curr_proto != PROTO_END;
|
|
curr_proto++) {
|
|
|
|
if (is_shared(hdl, mntpt, *curr_proto) &&
|
|
unshare_one(hdl, zhp->zfs_name,
|
|
mntpt, *curr_proto) != 0) {
|
|
if (mntpt != NULL)
|
|
free(mntpt);
|
|
return (-1);
|
|
}
|
|
}
|
|
}
|
|
if (mntpt != NULL)
|
|
free(mntpt);
|
|
|
|
return (0);
|
|
}
|
|
|
|
int
|
|
zfs_unshare_nfs(zfs_handle_t *zhp, const char *mountpoint)
|
|
{
|
|
return (zfs_unshare_proto(zhp, mountpoint, nfs_only));
|
|
}
|
|
|
|
int
|
|
zfs_unshare_smb(zfs_handle_t *zhp, const char *mountpoint)
|
|
{
|
|
return (zfs_unshare_proto(zhp, mountpoint, smb_only));
|
|
}
|
|
|
|
/*
|
|
* Same as zfs_unmountall(), but for NFS and SMB unshares.
|
|
*/
|
|
int
|
|
zfs_unshareall_proto(zfs_handle_t *zhp, zfs_share_proto_t *proto)
|
|
{
|
|
prop_changelist_t *clp;
|
|
int ret;
|
|
|
|
clp = changelist_gather(zhp, ZFS_PROP_SHARENFS, 0, 0);
|
|
if (clp == NULL)
|
|
return (-1);
|
|
|
|
ret = changelist_unshare(clp, proto);
|
|
changelist_free(clp);
|
|
|
|
return (ret);
|
|
}
|
|
|
|
int
|
|
zfs_unshareall_nfs(zfs_handle_t *zhp)
|
|
{
|
|
return (zfs_unshareall_proto(zhp, nfs_only));
|
|
}
|
|
|
|
int
|
|
zfs_unshareall_smb(zfs_handle_t *zhp)
|
|
{
|
|
return (zfs_unshareall_proto(zhp, smb_only));
|
|
}
|
|
|
|
int
|
|
zfs_unshareall(zfs_handle_t *zhp)
|
|
{
|
|
return (zfs_unshareall_proto(zhp, share_all_proto));
|
|
}
|
|
|
|
int
|
|
zfs_unshareall_bypath(zfs_handle_t *zhp, const char *mountpoint)
|
|
{
|
|
return (zfs_unshare_proto(zhp, mountpoint, share_all_proto));
|
|
}
|
|
|
|
/*
|
|
* Remove the mountpoint associated with the current dataset, if necessary.
|
|
* We only remove the underlying directory if:
|
|
*
|
|
* - The mountpoint is not 'none' or 'legacy'
|
|
* - The mountpoint is non-empty
|
|
* - The mountpoint is the default or inherited
|
|
* - The 'zoned' property is set, or we're in a local zone
|
|
*
|
|
* Any other directories we leave alone.
|
|
*/
|
|
void
|
|
remove_mountpoint(zfs_handle_t *zhp)
|
|
{
|
|
char mountpoint[ZFS_MAXPROPLEN];
|
|
zprop_source_t source;
|
|
|
|
if (!zfs_is_mountable(zhp, mountpoint, sizeof (mountpoint),
|
|
&source))
|
|
return;
|
|
|
|
if (source == ZPROP_SRC_DEFAULT ||
|
|
source == ZPROP_SRC_INHERITED) {
|
|
/*
|
|
* Try to remove the directory, silently ignoring any errors.
|
|
* The filesystem may have since been removed or moved around,
|
|
* and this error isn't really useful to the administrator in
|
|
* any way.
|
|
*/
|
|
(void) rmdir(mountpoint);
|
|
}
|
|
}
|
|
|
|
boolean_t
|
|
zfs_is_shared_iscsi(zfs_handle_t *zhp)
|
|
{
|
|
|
|
/*
|
|
* If iscsi deamon isn't running then we aren't shared
|
|
*/
|
|
if (iscsitgt_svc_online && iscsitgt_svc_online() == 1)
|
|
return (B_FALSE);
|
|
else
|
|
return (iscsitgt_zfs_is_shared != NULL &&
|
|
iscsitgt_zfs_is_shared(zhp->zfs_name) != 0);
|
|
}
|
|
|
|
int
|
|
zfs_share_iscsi(zfs_handle_t *zhp)
|
|
{
|
|
char shareopts[ZFS_MAXPROPLEN];
|
|
const char *dataset = zhp->zfs_name;
|
|
libzfs_handle_t *hdl = zhp->zfs_hdl;
|
|
|
|
/*
|
|
* Return success if there are no share options.
|
|
*/
|
|
if (zfs_prop_get(zhp, ZFS_PROP_SHAREISCSI, shareopts,
|
|
sizeof (shareopts), NULL, NULL, 0, B_FALSE) != 0 ||
|
|
strcmp(shareopts, "off") == 0)
|
|
return (0);
|
|
|
|
/* We don't support iSCSI on FreeBSD yet. */
|
|
#ifdef TODO
|
|
if (iscsitgt_zfs_share == NULL || iscsitgt_zfs_share(dataset) != 0) {
|
|
int error = EZFS_SHAREISCSIFAILED;
|
|
|
|
/*
|
|
* If service isn't availabele and EPERM was
|
|
* returned then use special error.
|
|
*/
|
|
if (iscsitgt_svc_online && errno == EPERM &&
|
|
(iscsitgt_svc_online() != 0))
|
|
error = EZFS_ISCSISVCUNAVAIL;
|
|
|
|
return (zfs_error_fmt(hdl, error,
|
|
dgettext(TEXT_DOMAIN, "cannot share '%s'"), dataset));
|
|
}
|
|
#endif
|
|
|
|
return (0);
|
|
}
|
|
|
|
int
|
|
zfs_unshare_iscsi(zfs_handle_t *zhp)
|
|
{
|
|
const char *dataset = zfs_get_name(zhp);
|
|
libzfs_handle_t *hdl = zhp->zfs_hdl;
|
|
|
|
/* We don't support iSCSI on FreeBSD yet. */
|
|
#ifdef TODO
|
|
/*
|
|
* Return if the volume is not shared
|
|
*/
|
|
if (zfs_is_shared_iscsi(zhp) != SHARED_ISCSI)
|
|
return (0);
|
|
|
|
/*
|
|
* If this fails with ENODEV it indicates that zvol wasn't shared so
|
|
* we should return success in that case.
|
|
*/
|
|
if (iscsitgt_zfs_unshare == NULL ||
|
|
(iscsitgt_zfs_unshare(dataset) != 0 && errno != ENODEV)) {
|
|
if (errno == EPERM)
|
|
zfs_error_aux(hdl, dgettext(TEXT_DOMAIN,
|
|
"Insufficient privileges to unshare iscsi"));
|
|
return (zfs_error_fmt(hdl, EZFS_UNSHAREISCSIFAILED,
|
|
dgettext(TEXT_DOMAIN, "cannot unshare '%s'"), dataset));
|
|
}
|
|
#endif
|
|
|
|
return (0);
|
|
}
|
|
|
|
typedef struct mount_cbdata {
|
|
zfs_handle_t **cb_datasets;
|
|
int cb_used;
|
|
int cb_alloc;
|
|
} mount_cbdata_t;
|
|
|
|
static int
|
|
mount_cb(zfs_handle_t *zhp, void *data)
|
|
{
|
|
mount_cbdata_t *cbp = data;
|
|
|
|
if (!(zfs_get_type(zhp) & (ZFS_TYPE_FILESYSTEM | ZFS_TYPE_VOLUME))) {
|
|
zfs_close(zhp);
|
|
return (0);
|
|
}
|
|
|
|
if (zfs_prop_get_int(zhp, ZFS_PROP_CANMOUNT) == ZFS_CANMOUNT_NOAUTO) {
|
|
zfs_close(zhp);
|
|
return (0);
|
|
}
|
|
|
|
if (cbp->cb_alloc == cbp->cb_used) {
|
|
void *ptr;
|
|
|
|
if ((ptr = zfs_realloc(zhp->zfs_hdl,
|
|
cbp->cb_datasets, cbp->cb_alloc * sizeof (void *),
|
|
cbp->cb_alloc * 2 * sizeof (void *))) == NULL)
|
|
return (-1);
|
|
cbp->cb_datasets = ptr;
|
|
|
|
cbp->cb_alloc *= 2;
|
|
}
|
|
|
|
cbp->cb_datasets[cbp->cb_used++] = zhp;
|
|
|
|
return (zfs_iter_filesystems(zhp, mount_cb, cbp));
|
|
}
|
|
|
|
static int
|
|
dataset_cmp(const void *a, const void *b)
|
|
{
|
|
zfs_handle_t **za = (zfs_handle_t **)a;
|
|
zfs_handle_t **zb = (zfs_handle_t **)b;
|
|
char mounta[MAXPATHLEN];
|
|
char mountb[MAXPATHLEN];
|
|
boolean_t gota, gotb;
|
|
|
|
if ((gota = (zfs_get_type(*za) == ZFS_TYPE_FILESYSTEM)) != 0)
|
|
verify(zfs_prop_get(*za, ZFS_PROP_MOUNTPOINT, mounta,
|
|
sizeof (mounta), NULL, NULL, 0, B_FALSE) == 0);
|
|
if ((gotb = (zfs_get_type(*zb) == ZFS_TYPE_FILESYSTEM)) != 0)
|
|
verify(zfs_prop_get(*zb, ZFS_PROP_MOUNTPOINT, mountb,
|
|
sizeof (mountb), NULL, NULL, 0, B_FALSE) == 0);
|
|
|
|
if (gota && gotb)
|
|
return (strcmp(mounta, mountb));
|
|
|
|
if (gota)
|
|
return (-1);
|
|
if (gotb)
|
|
return (1);
|
|
|
|
return (strcmp(zfs_get_name(a), zfs_get_name(b)));
|
|
}
|
|
|
|
/*
|
|
* Mount and share all datasets within the given pool. This assumes that no
|
|
* datasets within the pool are currently mounted. Because users can create
|
|
* complicated nested hierarchies of mountpoints, we first gather all the
|
|
* datasets and mountpoints within the pool, and sort them by mountpoint. Once
|
|
* we have the list of all filesystems, we iterate over them in order and mount
|
|
* and/or share each one.
|
|
*/
|
|
#pragma weak zpool_mount_datasets = zpool_enable_datasets
|
|
int
|
|
zpool_enable_datasets(zpool_handle_t *zhp, const char *mntopts, int flags)
|
|
{
|
|
mount_cbdata_t cb = { 0 };
|
|
libzfs_handle_t *hdl = zhp->zpool_hdl;
|
|
zfs_handle_t *zfsp;
|
|
int i, ret = -1;
|
|
int *good;
|
|
|
|
/*
|
|
* Gather all non-snap datasets within the pool.
|
|
*/
|
|
if ((cb.cb_datasets = zfs_alloc(hdl, 4 * sizeof (void *))) == NULL)
|
|
return (-1);
|
|
cb.cb_alloc = 4;
|
|
|
|
if ((zfsp = zfs_open(hdl, zhp->zpool_name, ZFS_TYPE_DATASET)) == NULL)
|
|
goto out;
|
|
|
|
cb.cb_datasets[0] = zfsp;
|
|
cb.cb_used = 1;
|
|
|
|
if (zfs_iter_filesystems(zfsp, mount_cb, &cb) != 0)
|
|
goto out;
|
|
|
|
/*
|
|
* Sort the datasets by mountpoint.
|
|
*/
|
|
qsort(cb.cb_datasets, cb.cb_used, sizeof (void *), dataset_cmp);
|
|
|
|
/*
|
|
* And mount all the datasets, keeping track of which ones
|
|
* succeeded or failed.
|
|
*/
|
|
if ((good = zfs_alloc(zhp->zpool_hdl,
|
|
cb.cb_used * sizeof (int))) == NULL)
|
|
goto out;
|
|
|
|
ret = 0;
|
|
for (i = 0; i < cb.cb_used; i++) {
|
|
if (zfs_mount(cb.cb_datasets[i], mntopts, flags) != 0)
|
|
ret = -1;
|
|
else
|
|
good[i] = 1;
|
|
}
|
|
|
|
/*
|
|
* Then share all the ones that need to be shared. This needs
|
|
* to be a separate pass in order to avoid excessive reloading
|
|
* of the configuration. Good should never be NULL since
|
|
* zfs_alloc is supposed to exit if memory isn't available.
|
|
*/
|
|
for (i = 0; i < cb.cb_used; i++) {
|
|
if (good[i] && zfs_share(cb.cb_datasets[i]) != 0)
|
|
ret = -1;
|
|
}
|
|
|
|
free(good);
|
|
|
|
out:
|
|
for (i = 0; i < cb.cb_used; i++)
|
|
zfs_close(cb.cb_datasets[i]);
|
|
free(cb.cb_datasets);
|
|
|
|
return (ret);
|
|
}
|
|
|
|
|
|
static int
|
|
zvol_cb(const char *dataset, void *data)
|
|
{
|
|
libzfs_handle_t *hdl = data;
|
|
zfs_handle_t *zhp;
|
|
|
|
/*
|
|
* Ignore snapshots and ignore failures from non-existant datasets.
|
|
*/
|
|
if (strchr(dataset, '@') != NULL ||
|
|
(zhp = zfs_open(hdl, dataset, ZFS_TYPE_VOLUME)) == NULL)
|
|
return (0);
|
|
|
|
if (zfs_unshare_iscsi(zhp) != 0)
|
|
return (-1);
|
|
|
|
zfs_close(zhp);
|
|
|
|
return (0);
|
|
}
|
|
|
|
static int
|
|
mountpoint_compare(const void *a, const void *b)
|
|
{
|
|
const char *mounta = *((char **)a);
|
|
const char *mountb = *((char **)b);
|
|
|
|
return (strcmp(mountb, mounta));
|
|
}
|
|
|
|
/*
|
|
* Unshare and unmount all datasets within the given pool. We don't want to
|
|
* rely on traversing the DSL to discover the filesystems within the pool,
|
|
* because this may be expensive (if not all of them are mounted), and can fail
|
|
* arbitrarily (on I/O error, for example). Instead, we walk /etc/mnttab and
|
|
* gather all the filesystems that are currently mounted.
|
|
*/
|
|
#pragma weak zpool_unmount_datasets = zpool_disable_datasets
|
|
int
|
|
zpool_disable_datasets(zpool_handle_t *zhp, boolean_t force)
|
|
{
|
|
int used, alloc;
|
|
struct statfs *sfs;
|
|
size_t namelen;
|
|
char **mountpoints = NULL;
|
|
zfs_handle_t **datasets = NULL;
|
|
libzfs_handle_t *hdl = zhp->zpool_hdl;
|
|
int i, j, n;
|
|
int ret = -1;
|
|
int flags = (force ? MS_FORCE : 0);
|
|
|
|
/*
|
|
* First unshare all zvols.
|
|
*/
|
|
if (zpool_iter_zvol(zhp, zvol_cb, hdl) != 0)
|
|
return (-1);
|
|
|
|
namelen = strlen(zhp->zpool_name);
|
|
|
|
used = alloc = 0;
|
|
if ((n = getmntinfo(&sfs, MNT_WAIT)) == 0) {
|
|
fprintf(stderr, "getmntinfo(): %s\n", strerror(errno));
|
|
return (-1);
|
|
}
|
|
for (j = 0; j < n; j++) {
|
|
/*
|
|
* Ignore non-ZFS entries.
|
|
*/
|
|
if (strcmp(sfs[j].f_fstypename, MNTTYPE_ZFS) != 0)
|
|
continue;
|
|
|
|
/*
|
|
* Ignore filesystems not within this pool.
|
|
*/
|
|
if (strncmp(sfs[j].f_mntfromname, zhp->zpool_name, namelen) != 0 ||
|
|
(sfs[j].f_mntfromname[namelen] != '/' &&
|
|
sfs[j].f_mntfromname[namelen] != '\0'))
|
|
continue;
|
|
|
|
/*
|
|
* At this point we've found a filesystem within our pool. Add
|
|
* it to our growing list.
|
|
*/
|
|
if (used == alloc) {
|
|
if (alloc == 0) {
|
|
if ((mountpoints = zfs_alloc(hdl,
|
|
8 * sizeof (void *))) == NULL)
|
|
goto out;
|
|
|
|
if ((datasets = zfs_alloc(hdl,
|
|
8 * sizeof (void *))) == NULL)
|
|
goto out;
|
|
|
|
alloc = 8;
|
|
} else {
|
|
void *ptr;
|
|
|
|
if ((ptr = zfs_realloc(hdl, mountpoints,
|
|
alloc * sizeof (void *),
|
|
alloc * 2 * sizeof (void *))) == NULL)
|
|
goto out;
|
|
mountpoints = ptr;
|
|
|
|
if ((ptr = zfs_realloc(hdl, datasets,
|
|
alloc * sizeof (void *),
|
|
alloc * 2 * sizeof (void *))) == NULL)
|
|
goto out;
|
|
datasets = ptr;
|
|
|
|
alloc *= 2;
|
|
}
|
|
}
|
|
|
|
if ((mountpoints[used] = zfs_strdup(hdl,
|
|
sfs[j].f_mntonname)) == NULL)
|
|
goto out;
|
|
|
|
/*
|
|
* This is allowed to fail, in case there is some I/O error. It
|
|
* is only used to determine if we need to remove the underlying
|
|
* mountpoint, so failure is not fatal.
|
|
*/
|
|
datasets[used] = make_dataset_handle(hdl, sfs[j].f_mntfromname);
|
|
|
|
used++;
|
|
}
|
|
|
|
/*
|
|
* At this point, we have the entire list of filesystems, so sort it by
|
|
* mountpoint.
|
|
*/
|
|
qsort(mountpoints, used, sizeof (char *), mountpoint_compare);
|
|
|
|
/*
|
|
* Walk through and first unshare everything.
|
|
*/
|
|
for (i = 0; i < used; i++) {
|
|
zfs_share_proto_t *curr_proto;
|
|
for (curr_proto = share_all_proto; *curr_proto != PROTO_END;
|
|
curr_proto++) {
|
|
if (is_shared(hdl, mountpoints[i], *curr_proto) &&
|
|
unshare_one(hdl, mountpoints[i],
|
|
mountpoints[i], *curr_proto) != 0)
|
|
goto out;
|
|
}
|
|
}
|
|
|
|
/*
|
|
* Now unmount everything, removing the underlying directories as
|
|
* appropriate.
|
|
*/
|
|
for (i = 0; i < used; i++) {
|
|
if (unmount_one(hdl, mountpoints[i], flags) != 0)
|
|
goto out;
|
|
}
|
|
|
|
for (i = 0; i < used; i++) {
|
|
if (datasets[i])
|
|
remove_mountpoint(datasets[i]);
|
|
}
|
|
|
|
ret = 0;
|
|
out:
|
|
for (i = 0; i < used; i++) {
|
|
if (datasets[i])
|
|
zfs_close(datasets[i]);
|
|
free(mountpoints[i]);
|
|
}
|
|
free(datasets);
|
|
free(mountpoints);
|
|
|
|
return (ret);
|
|
}
|