Print this page
8331 zfs_unshare returns wrong error code for smb unshare failure
Reviewed by: Marcel Telka <marcel@telka.sk>
Reviewed by: Toomas Soome <tsoome@me.com>


   7  *
   8  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
   9  * or http://www.opensolaris.org/os/licensing.
  10  * See the License for the specific language governing permissions
  11  * and limitations under the License.
  12  *
  13  * When distributing Covered Code, include this CDDL HEADER in each
  14  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
  15  * If applicable, add the following below this CDDL HEADER, with the
  16  * fields enclosed by brackets "[]" replaced with your own identifying
  17  * information: Portions Copyright [yyyy] [name of copyright owner]
  18  *
  19  * CDDL HEADER END
  20  */
  21 
  22 /*
  23  * Copyright 2015 Nexenta Systems, Inc.  All rights reserved.
  24  * Copyright (c) 2005, 2010, Oracle and/or its affiliates. All rights reserved.
  25  * Copyright (c) 2014, 2016 by Delphix. All rights reserved.
  26  * Copyright 2016 Igor Kozhukhov <ikozhukhov@gmail.com>

  27  */
  28 
  29 /*
  30  * Routines to manage ZFS mounts.  We separate all the nasty routines that have
  31  * to deal with the OS.  The following functions are the main entry points --
  32  * they are used by mount and unmount and when changing a filesystem's
  33  * mountpoint.
  34  *
  35  *      zfs_is_mounted()
  36  *      zfs_mount()
  37  *      zfs_unmount()
  38  *      zfs_unmountall()
  39  *
  40  * This file also contains the functions used to manage sharing filesystems via
  41  * NFS and iSCSI:
  42  *
  43  *      zfs_is_shared()
  44  *      zfs_share()
  45  *      zfs_unshare()
  46  *


  74 #include <unistd.h>
  75 #include <zone.h>
  76 #include <sys/mntent.h>
  77 #include <sys/mount.h>
  78 #include <sys/stat.h>
  79 #include <sys/statvfs.h>
  80 
  81 #include <libzfs.h>
  82 
  83 #include "libzfs_impl.h"
  84 
  85 #include <libshare.h>
  86 #include <sys/systeminfo.h>
  87 #define MAXISALEN       257     /* based on sysinfo(2) man page */
  88 
  89 static int zfs_share_proto(zfs_handle_t *, zfs_share_proto_t *);
  90 zfs_share_type_t zfs_is_shared_proto(zfs_handle_t *, char **,
  91     zfs_share_proto_t);
  92 
  93 /*
  94  * The share protocols table must be in the same order as the zfs_share_prot_t
  95  * enum in libzfs_impl.h
  96  */
  97 typedef struct {
  98         zfs_prop_t p_prop;
  99         char *p_name;
 100         int p_share_err;
 101         int p_unshare_err;
 102 } proto_table_t;
 103 
 104 proto_table_t proto_table[PROTO_END] = {
 105         {ZFS_PROP_SHARENFS, "nfs", EZFS_SHARENFSFAILED, EZFS_UNSHARENFSFAILED},
 106         {ZFS_PROP_SHARESMB, "smb", EZFS_SHARESMBFAILED, EZFS_UNSHARESMBFAILED},
 107 };
 108 
 109 zfs_share_proto_t nfs_only[] = {
 110         PROTO_NFS,
 111         PROTO_END
 112 };
 113 
 114 zfs_share_proto_t smb_only[] = {


 898         sa_share_t share;
 899         int err;
 900         char *mntpt;
 901 
 902         /*
 903          * Mountpoint could get trashed if libshare calls getmntany
 904          * which it does during API initialization, so strdup the
 905          * value.
 906          */
 907         mntpt = zfs_strdup(hdl, mountpoint);
 908 
 909         /*
 910          * make sure libshare initialized, initialize everything because we
 911          * don't know what other unsharing may happen later. Functions up the
 912          * stack are allowed to initialize instead a subset of shares at the
 913          * time the set is known.
 914          */
 915         if ((err = zfs_init_libshare_arg(hdl, SA_INIT_ONE_SHARE_FROM_NAME,
 916             (void *)name)) != SA_OK) {
 917                 free(mntpt);    /* don't need the copy anymore */
 918                 return (zfs_error_fmt(hdl, EZFS_UNSHARENFSFAILED,
 919                     dgettext(TEXT_DOMAIN, "cannot unshare '%s': %s"),
 920                     name, _sa_errorstr(err)));
 921         }
 922 
 923         share = zfs_sa_find_share(hdl->libzfs_sharehdl, mntpt);
 924         free(mntpt);    /* don't need the copy anymore */
 925 
 926         if (share != NULL) {
 927                 err = zfs_sa_disable_share(share, proto_table[proto].p_name);
 928                 if (err != SA_OK) {
 929                         return (zfs_error_fmt(hdl, EZFS_UNSHARENFSFAILED,

 930                             dgettext(TEXT_DOMAIN, "cannot unshare '%s': %s"),
 931                             name, _sa_errorstr(err)));
 932                 }
 933         } else {
 934                 return (zfs_error_fmt(hdl, EZFS_UNSHARENFSFAILED,
 935                     dgettext(TEXT_DOMAIN, "cannot unshare '%s': not found"),
 936                     name));
 937         }
 938         return (0);
 939 }
 940 
 941 /*
 942  * Unshare the given filesystem.
 943  */
 944 int
 945 zfs_unshare_proto(zfs_handle_t *zhp, const char *mountpoint,
 946     zfs_share_proto_t *proto)
 947 {
 948         libzfs_handle_t *hdl = zhp->zfs_hdl;
 949         struct mnttab entry;
 950         char *mntpt = NULL;
 951 
 952         /* check to see if need to unmount the filesystem */
 953         rewind(zhp->zfs_hdl->libzfs_mnttab);
 954         if (mountpoint != NULL)




   7  *
   8  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
   9  * or http://www.opensolaris.org/os/licensing.
  10  * See the License for the specific language governing permissions
  11  * and limitations under the License.
  12  *
  13  * When distributing Covered Code, include this CDDL HEADER in each
  14  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
  15  * If applicable, add the following below this CDDL HEADER, with the
  16  * fields enclosed by brackets "[]" replaced with your own identifying
  17  * information: Portions Copyright [yyyy] [name of copyright owner]
  18  *
  19  * CDDL HEADER END
  20  */
  21 
  22 /*
  23  * Copyright 2015 Nexenta Systems, Inc.  All rights reserved.
  24  * Copyright (c) 2005, 2010, Oracle and/or its affiliates. All rights reserved.
  25  * Copyright (c) 2014, 2016 by Delphix. All rights reserved.
  26  * Copyright 2016 Igor Kozhukhov <ikozhukhov@gmail.com>
  27  * Copyright 2017 RackTop Systems.
  28  */
  29 
  30 /*
  31  * Routines to manage ZFS mounts.  We separate all the nasty routines that have
  32  * to deal with the OS.  The following functions are the main entry points --
  33  * they are used by mount and unmount and when changing a filesystem's
  34  * mountpoint.
  35  *
  36  *      zfs_is_mounted()
  37  *      zfs_mount()
  38  *      zfs_unmount()
  39  *      zfs_unmountall()
  40  *
  41  * This file also contains the functions used to manage sharing filesystems via
  42  * NFS and iSCSI:
  43  *
  44  *      zfs_is_shared()
  45  *      zfs_share()
  46  *      zfs_unshare()
  47  *


  75 #include <unistd.h>
  76 #include <zone.h>
  77 #include <sys/mntent.h>
  78 #include <sys/mount.h>
  79 #include <sys/stat.h>
  80 #include <sys/statvfs.h>
  81 
  82 #include <libzfs.h>
  83 
  84 #include "libzfs_impl.h"
  85 
  86 #include <libshare.h>
  87 #include <sys/systeminfo.h>
  88 #define MAXISALEN       257     /* based on sysinfo(2) man page */
  89 
  90 static int zfs_share_proto(zfs_handle_t *, zfs_share_proto_t *);
  91 zfs_share_type_t zfs_is_shared_proto(zfs_handle_t *, char **,
  92     zfs_share_proto_t);
  93 
  94 /*
  95  * The share protocols table must be in the same order as the zfs_share_proto_t
  96  * enum in libzfs_impl.h
  97  */
  98 typedef struct {
  99         zfs_prop_t p_prop;
 100         char *p_name;
 101         int p_share_err;
 102         int p_unshare_err;
 103 } proto_table_t;
 104 
 105 proto_table_t proto_table[PROTO_END] = {
 106         {ZFS_PROP_SHARENFS, "nfs", EZFS_SHARENFSFAILED, EZFS_UNSHARENFSFAILED},
 107         {ZFS_PROP_SHARESMB, "smb", EZFS_SHARESMBFAILED, EZFS_UNSHARESMBFAILED},
 108 };
 109 
 110 zfs_share_proto_t nfs_only[] = {
 111         PROTO_NFS,
 112         PROTO_END
 113 };
 114 
 115 zfs_share_proto_t smb_only[] = {


 899         sa_share_t share;
 900         int err;
 901         char *mntpt;
 902 
 903         /*
 904          * Mountpoint could get trashed if libshare calls getmntany
 905          * which it does during API initialization, so strdup the
 906          * value.
 907          */
 908         mntpt = zfs_strdup(hdl, mountpoint);
 909 
 910         /*
 911          * make sure libshare initialized, initialize everything because we
 912          * don't know what other unsharing may happen later. Functions up the
 913          * stack are allowed to initialize instead a subset of shares at the
 914          * time the set is known.
 915          */
 916         if ((err = zfs_init_libshare_arg(hdl, SA_INIT_ONE_SHARE_FROM_NAME,
 917             (void *)name)) != SA_OK) {
 918                 free(mntpt);    /* don't need the copy anymore */
 919                 return (zfs_error_fmt(hdl, proto_table[proto].p_unshare_err,
 920                     dgettext(TEXT_DOMAIN, "cannot unshare '%s': %s"),
 921                     name, _sa_errorstr(err)));
 922         }
 923 
 924         share = zfs_sa_find_share(hdl->libzfs_sharehdl, mntpt);
 925         free(mntpt);    /* don't need the copy anymore */
 926 
 927         if (share != NULL) {
 928                 err = zfs_sa_disable_share(share, proto_table[proto].p_name);
 929                 if (err != SA_OK) {
 930                         return (zfs_error_fmt(hdl,
 931                             proto_table[proto].p_unshare_err,
 932                             dgettext(TEXT_DOMAIN, "cannot unshare '%s': %s"),
 933                             name, _sa_errorstr(err)));
 934                 }
 935         } else {
 936                 return (zfs_error_fmt(hdl, proto_table[proto].p_unshare_err,
 937                     dgettext(TEXT_DOMAIN, "cannot unshare '%s': not found"),
 938                     name));
 939         }
 940         return (0);
 941 }
 942 
 943 /*
 944  * Unshare the given filesystem.
 945  */
 946 int
 947 zfs_unshare_proto(zfs_handle_t *zhp, const char *mountpoint,
 948     zfs_share_proto_t *proto)
 949 {
 950         libzfs_handle_t *hdl = zhp->zfs_hdl;
 951         struct mnttab entry;
 952         char *mntpt = NULL;
 953 
 954         /* check to see if need to unmount the filesystem */
 955         rewind(zhp->zfs_hdl->libzfs_mnttab);
 956         if (mountpoint != NULL)