mirror of
https://git.proxmox.com/git/mirror_zfs.git
synced 2026-05-22 02:27:36 +03:00
Allow zfs unshare <protocol> -a
Allow `zfs unshare <protocol> -a` command to share or unshare all datasets of a given protocol, nfs or smb. Additionally, enable most of ZFS Test Suite zfs_share/zfs_unshare test cases. To work around some Illumos-specific functionalities ($SHARE/$UNSHARE) some function wrappers were added around them. Finally, fix and issue in smb_is_share_active() that would leave SMB shares exported when invoking 'zfs unshare -a' Reviewed-by: Giuseppe Di Natale <dinatale2@llnl.gov> Reviewed-by: Brian Behlendorf <behlendorf1@llnl.gov> Signed-off-by: Turbo Fredriksson <turbo@bayour.com> Signed-off-by: loli10K <ezomori.nozomu@gmail.com> Closes #3238 Closes #5367
This commit is contained in:
+23
-5
@@ -270,7 +270,7 @@ get_usage(zfs_help_t idx)
|
||||
return (gettext("\tset <property=value> ... "
|
||||
"<filesystem|volume|snapshot> ...\n"));
|
||||
case HELP_SHARE:
|
||||
return (gettext("\tshare <-a | filesystem>\n"));
|
||||
return (gettext("\tshare <-a [nfs|smb] | filesystem>\n"));
|
||||
case HELP_SNAPSHOT:
|
||||
return (gettext("\tsnapshot|snap [-r] [-o property=value] ... "
|
||||
"<filesystem|volume>@<snap> ...\n"));
|
||||
@@ -279,7 +279,7 @@ get_usage(zfs_help_t idx)
|
||||
"<-a | filesystem|mountpoint>\n"));
|
||||
case HELP_UNSHARE:
|
||||
return (gettext("\tunshare "
|
||||
"<-a | filesystem|mountpoint>\n"));
|
||||
"<-a [nfs|smb] | filesystem|mountpoint>\n"));
|
||||
case HELP_ALLOW:
|
||||
return (gettext("\tallow <filesystem|volume>\n"
|
||||
"\tallow [-ldug] "
|
||||
@@ -6436,7 +6436,7 @@ unshare_unmount(int op, int argc, char **argv)
|
||||
char sharesmb[ZFS_MAXPROPLEN];
|
||||
|
||||
/* check options */
|
||||
while ((c = getopt(argc, argv, op == OP_SHARE ? "a" : "af")) != -1) {
|
||||
while ((c = getopt(argc, argv, op == OP_SHARE ? ":a" : "af")) != -1) {
|
||||
switch (c) {
|
||||
case 'a':
|
||||
do_all = 1;
|
||||
@@ -6444,6 +6444,11 @@ unshare_unmount(int op, int argc, char **argv)
|
||||
case 'f':
|
||||
flags = MS_FORCE;
|
||||
break;
|
||||
case ':':
|
||||
(void) fprintf(stderr, gettext("missing argument for "
|
||||
"'%c' option\n"), optopt);
|
||||
usage(B_FALSE);
|
||||
break;
|
||||
case '?':
|
||||
(void) fprintf(stderr, gettext("invalid option '%c'\n"),
|
||||
optopt);
|
||||
@@ -6475,6 +6480,19 @@ unshare_unmount(int op, int argc, char **argv)
|
||||
unshare_unmount_node_t *node;
|
||||
uu_avl_index_t idx;
|
||||
uu_avl_walk_t *walk;
|
||||
char *protocol = NULL;
|
||||
|
||||
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];
|
||||
argc--;
|
||||
argv++;
|
||||
}
|
||||
|
||||
if (argc != 0) {
|
||||
(void) fprintf(stderr, gettext("too many arguments\n"));
|
||||
@@ -6567,8 +6585,8 @@ unshare_unmount(int op, int argc, char **argv)
|
||||
|
||||
switch (op) {
|
||||
case OP_SHARE:
|
||||
if (zfs_unshareall_bypath(node->un_zhp,
|
||||
node->un_mountp) != 0)
|
||||
if (zfs_unshareall_bytype(node->un_zhp,
|
||||
node->un_mountp, protocol) != 0)
|
||||
ret = 1;
|
||||
break;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user