(void) fprintf(stderr, gettext("filesystem "
"successfully created, but not mounted\n"));
ret = 1;
- } else if (zfs_share(zhp) != 0) {
+ } else if (zfs_share(zhp, NULL) != 0) {
(void) fprintf(stderr, gettext("filesystem "
"successfully created, but not shared\n"));
ret = 1;
}
- zfs_commit_all_shares();
+ zfs_commit_shares(NULL);
}
zfs_close(zhp);
boolean_t sm_verbose;
int sm_flags;
char *sm_options;
- char *sm_proto; /* only valid for OP_SHARE */
+ enum sa_protocol sm_proto; /* only valid for OP_SHARE */
pthread_mutex_t sm_lock; /* protects the remaining fields */
uint_t sm_total; /* number of filesystems to process */
uint_t sm_done; /* number of filesystems processed */
* Share or mount a dataset.
*/
static int
-share_mount_one(zfs_handle_t *zhp, int op, int flags, char *protocol,
+share_mount_one(zfs_handle_t *zhp, int op, int flags, enum sa_protocol protocol,
boolean_t explicit, const char *options)
{
char mountpoint[ZFS_MAXPROPLEN];
return (0);
if (op == OP_SHARE && !zfs_is_mounted(zhp, NULL)) {
/* also purge it from existing exports */
- zfs_unshareall_bypath(zhp, mountpoint);
+ zfs_unshare(zhp, mountpoint, NULL);
return (0);
}
}
* filesystem.
*/
switch (op) {
- case OP_SHARE:
-
- shared_nfs = zfs_is_shared_nfs(zhp, NULL);
- shared_smb = zfs_is_shared_smb(zhp, NULL);
+ case OP_SHARE: {
+ enum sa_protocol prot[] = {SA_PROTOCOL_NFS, SA_NO_PROTOCOL};
+ shared_nfs = zfs_is_shared(zhp, NULL, prot);
+ *prot = SA_PROTOCOL_SMB;
+ shared_smb = zfs_is_shared(zhp, NULL, prot);
if ((shared_nfs && shared_smb) ||
(shared_nfs && strcmp(shareopts, "on") == 0 &&
zfs_mount(zhp, NULL, flags) != 0)
return (1);
- if (protocol == NULL) {
- if (zfs_shareall(zhp) != 0)
- return (1);
- } else if (strcmp(protocol, "nfs") == 0) {
- if (zfs_share_nfs(zhp))
- return (1);
- } else if (strcmp(protocol, "smb") == 0) {
- if (zfs_share_smb(zhp))
- return (1);
- } else {
- (void) fprintf(stderr, gettext("cannot share "
- "'%s': invalid share type '%s' "
- "specified\n"),
- zfs_get_name(zhp), protocol);
+ *prot = protocol;
+ if (zfs_share(zhp, protocol == SA_NO_PROTOCOL ? NULL : prot))
return (1);
- }
+ }
break;
case OP_MOUNT:
(void) strcpy(&mntopts[len], newopts);
}
+static enum sa_protocol
+sa_protocol_decode(const char *protocol)
+{
+ for (enum sa_protocol i = 0; i < ARRAY_SIZE(sa_protocol_names); ++i)
+ if (strcmp(protocol, sa_protocol_names[i]) == 0)
+ return (i);
+
+ (void) fputs(gettext("share type must be one of: "), stderr);
+ for (enum sa_protocol i = 0;
+ i < ARRAY_SIZE(sa_protocol_names); ++i)
+ (void) fprintf(stderr, "%s%s",
+ i != 0 ? ", " : "", sa_protocol_names[i]);
+ (void) fputc('\n', stderr);
+ usage(B_FALSE);
+}
+
static int
share_mount(int op, int argc, char **argv)
{
/* check number of arguments */
if (do_all) {
- char *protocol = NULL;
+ enum sa_protocol protocol = SA_NO_PROTOCOL;
if (op == OP_SHARE && argc > 0) {
- if (strcmp(argv[0], "nfs") != 0 &&
- strcmp(argv[0], "smb") != 0) {
- (void) fprintf(stderr, gettext("share type "
- "must be 'nfs' or 'smb'\n"));
- usage(B_FALSE);
- }
- protocol = argv[0];
+ protocol = sa_protocol_decode(argv[0]);
argc--;
argv++;
}
zfs_foreach_mountpoint(g_zfs, cb.cb_handles, cb.cb_used,
share_mount_one_cb, &share_mount_state,
op == OP_MOUNT && !(flags & MS_CRYPT));
- zfs_commit_all_shares();
+ zfs_commit_shares(NULL);
ret = share_mount_state.sm_status;
ZFS_TYPE_FILESYSTEM)) == NULL) {
ret = 1;
} else {
- ret = share_mount_one(zhp, op, flags, NULL, B_TRUE,
- options);
- zfs_commit_all_shares();
+ ret = share_mount_one(zhp, op, flags, SA_NO_PROTOCOL,
+ B_TRUE, options);
+ zfs_commit_shares(NULL);
zfs_close(zhp);
}
}
}
/*
- * zfs mount -a [nfs]
+ * zfs mount -a
* zfs mount filesystem
*
* Mount all filesystems, or mount the given filesystem.
"'%s': legacy share\n"), path);
(void) fprintf(stderr, gettext("use exportfs(8) "
"or smbcontrol(1) to unshare this filesystem\n"));
- } else if (!zfs_is_shared(zhp)) {
+ } else if (!zfs_is_shared(zhp, NULL, NULL)) {
(void) fprintf(stderr, gettext("cannot unshare '%s': "
"not currently shared\n"), path);
} else {
- ret = zfs_unshareall_bypath(zhp, path);
- zfs_commit_all_shares();
+ ret = zfs_unshare(zhp, path, NULL);
+ zfs_commit_shares(NULL);
}
} else {
char mtpt_prop[ZFS_MAXPROPLEN];
unshare_unmount_node_t *node;
uu_avl_index_t idx;
uu_avl_walk_t *walk;
- char *protocol = NULL;
+ enum sa_protocol *protocol = NULL,
+ single_protocol[] = {SA_NO_PROTOCOL, SA_NO_PROTOCOL};
if (op == OP_SHARE && argc > 0) {
- if (strcmp(argv[0], "nfs") != 0 &&
- strcmp(argv[0], "smb") != 0) {
- (void) fprintf(stderr, gettext("share type "
- "must be 'nfs' or 'smb'\n"));
- usage(B_FALSE);
- }
- protocol = argv[0];
+ *single_protocol = sa_protocol_decode(argv[0]);
+ protocol = single_protocol;
argc--;
argv++;
}
uu_avl_remove(tree, node);
switch (op) {
case OP_SHARE:
- if (zfs_unshareall_bytype(node->un_zhp,
+ if (zfs_unshare(node->un_zhp,
node->un_mountp, protocol) != 0)
ret = 1;
break;
"exports(5) or smb.conf(5) to unshare "
"this filesystem\n"));
ret = 1;
- } else if (!zfs_is_shared(zhp)) {
+ } else if (!zfs_is_shared(zhp, NULL, NULL)) {
(void) fprintf(stderr, gettext("cannot "
"unshare '%s': not currently "
"shared\n"), zfs_get_name(zhp));
ret = 1;
- } else if (zfs_unshareall(zhp) != 0) {
+ } else if (zfs_unshareall(zhp, NULL) != 0) {
ret = 1;
}
break;