Print this page
NEX-15279 support NFS server in zone
NEX-15520 online NFS shares cause zoneadm halt to hang in nfs_export_zone_fini
Portions contributed by: Dan Kruchinin dan.kruchinin@nexenta.com
Portions contributed by: Stepan Zastupov stepan.zastupov@gmail.com
Reviewed by: Joyce McIntosh <joyce.mcintosh@nexenta.com>
Reviewed by: Rob Gittins <rob.gittins@nexenta.com>
Reviewed by: Gordon Ross <gordon.ross@nexenta.com>
NEX-16156 Excessive time spent checking status of NFS services when sharing datasets during import
Reviewed by: Gordon Ross <gordon.ross@nexenta.com>
Reviewed by: Evan Layton <evan.layton@nexenta.com>
Reviewed by: Sanjay Nadkarni <sanjay.nadkarni@nexenta.com>
NEX-16156 Excessive time spent checking status of NFS services when sharing datasets during import
Reviewed by: Gordon Ross <gordon.ross@nexenta.com>
Reviewed by: Evan Layton <evan.layton@nexenta.com>
Reviewed by: Sanjay Nadkarni <sanjay.nadkarni@nexenta.com>
NEX-4179 segmentation fault when sharing with 'sec=none,root=*' options
Reviewed by: Gordon Ross <gordon.ross@nexenta.com>
Reviewed by: Yuri Pankov <yuri.pankov@nexenta.com>
NEX-2502 4.0.3 RC4 Unable to mount NFS shares
Revert "NEX-2394 mountd() door services are sub-optimal in large scale deployments".
This reverts commit c6e1673e3a4b8ba866c77dee7b8f03f858be07d6.
The fix for NEX-2394 worked fine when putting the mountd binary in 4.0.2,
but needs additional work in a 4.0.3 environment
NEX-2394 mountd() door services are sub-optimal in large scale deployments
Reviewed by: Gordon Ross <gordon.ross@nexenta.com>
Reviewed by: Rob Gittins <rob.gittins@nexenta.com>
Reviewed by: Kevin Crowe <kevin.crowe@nexenta.com>
Reviewed by: Ryuji Masuda <ryuji.masuda@nexenta.com>
Reviewed by: Kirill Davydychev <kirill.davydychev@nexenta.com>
NEX-1128 NFS server: Generic uid and gid remapping for AUTH_SYS
Reviewed by: Jan Kryl <jan.kryl@nexenta.com>
OS-141 mountd(1m) needs to be able to set listen backlog
Reviewed by: Yuri Pankov <yuri.pankov@nexenta.com>
4295 libshare sa_get_proto_status sometimes returns unallocated strings
Reviewed by: Marcel Telka <marcel@telka.sk>
Approved by: Garrett D'Amore <garrett@damore.org>
OS-20 share_nfs(1m) charset handling is unreliable
OS-22 Page fault at nfscmd_dropped_entrysize+0x1e()
OS-23 NFSv2/3/4: READDIR responses are inconsistent when charset conversion fails
OS-24 rfs3_readdir(): Issues related to nfscmd_convdirent()
Reviewed by: Jan Kryl <jan.kryl@nexenta.com>
Reviewed by: Gordon Ross <gordon.ross@nexenta.com>
re #3541 rb11254 - nfs nohide - "nfssrv: need ability to go to submounts for v3 and v2 protocols"

Split Close
Expand all
Collapse all
          --- old/usr/src/lib/libshare/nfs/libshare_nfs.c
          +++ new/usr/src/lib/libshare/nfs/libshare_nfs.c
↓ open down ↓ 13 lines elided ↑ open up ↑
  14   14   * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
  15   15   * If applicable, add the following below this CDDL HEADER, with the
  16   16   * fields enclosed by brackets "[]" replaced with your own identifying
  17   17   * information: Portions Copyright [yyyy] [name of copyright owner]
  18   18   *
  19   19   * CDDL HEADER END
  20   20   */
  21   21  
  22   22  /*
  23   23   * Copyright (c) 2006, 2010, Oracle and/or its affiliates. All rights reserved.
  24      - * Copyright 2016 Nexenta Systems, Inc.
       24 + */
       25 +
       26 +/*
  25   27   * Copyright (c) 2014, 2016 by Delphix. All rights reserved.
       28 + * Copyright 2018 Nexenta Systems, Inc.
  26   29   */
  27   30  
  28   31  /*
  29   32   * NFS specific functions
  30   33   */
       34 +
  31   35  #include <stdio.h>
  32   36  #include <string.h>
  33   37  #include <ctype.h>
  34   38  #include <stdlib.h>
  35   39  #include <unistd.h>
  36      -#include <zone.h>
  37   40  #include <errno.h>
  38   41  #include <locale.h>
  39   42  #include <signal.h>
  40   43  #include <strings.h>
  41   44  #include "libshare.h"
  42   45  #include "libshare_impl.h"
  43   46  #include <nfs/export.h>
  44   47  #include <pwd.h>
  45   48  #include <grp.h>
  46   49  #include <limits.h>
↓ open down ↓ 69 lines elided ↑ open up ↑
 116  119  };
 117  120  
 118  121  /*
 119  122   * list of support services needed
 120  123   * defines should come from head/rpcsvc/daemon_utils.h
 121  124   */
 122  125  
 123  126  static char *service_list_default[] =
 124  127          { STATD, LOCKD, MOUNTD, NFSD, NFSMAPID, RQUOTAD, REPARSED, NULL };
 125  128  static char *service_list_logging[] =
 126      -        { STATD, LOCKD, MOUNTD, NFSD, NFSMAPID, RQUOTAD, NFSLOGD, REPARSED,
 127      -            NULL };
      129 +        { NFSLOGD, NULL };
 128  130  
 129  131  /*
 130  132   * option definitions.  Make sure to keep the #define for the option
 131  133   * index just before the entry it is the index for. Changing the order
 132  134   * can cause breakage.  E.g OPT_RW is index 1 and must precede the
 133  135   * line that includes the SHOPT_RW and OPT_RW entries.
 134  136   */
 135  137  
 136  138  struct option_defs optdefs[] = {
 137  139  #define OPT_RO          0
↓ open down ↓ 29 lines elided ↑ open up ↑
 167  169  #define OPT_ROOT_MAPPING        15
 168  170          {SHOPT_ROOT_MAPPING, OPT_ROOT_MAPPING, OPT_TYPE_USER},
 169  171  #define OPT_CHARSET_MAP 16
 170  172          {"", OPT_CHARSET_MAP, OPT_TYPE_ACCLIST},
 171  173  #define OPT_NOACLFAB    17
 172  174          {SHOPT_NOACLFAB, OPT_NOACLFAB, OPT_TYPE_BOOLEAN},
 173  175  #define OPT_UIDMAP      18
 174  176          {SHOPT_UIDMAP, OPT_UIDMAP, OPT_TYPE_MAPPING},
 175  177  #define OPT_GIDMAP      19
 176  178          {SHOPT_GIDMAP, OPT_GIDMAP, OPT_TYPE_MAPPING},
      179 +#define OPT_NOHIDE      20
      180 +        {SHOPT_NOHIDE, OPT_NOHIDE, OPT_TYPE_BOOLEAN},
 177  181  #ifdef VOLATILE_FH_TEST /* XXX added for testing volatile fh's only */
 178      -#define OPT_VOLFH       20
      182 +#define OPT_VOLFH       21
 179  183          {SHOPT_VOLFH, OPT_VOLFH},
 180  184  #endif /* VOLATILE_FH_TEST */
 181  185          NULL
 182  186  };
 183  187  
 184  188  /*
 185  189   * Codesets that may need to be converted to UTF-8 for file paths.
 186  190   * Add new names here to add new property support. If we ever get a
 187  191   * way to query the kernel for character sets, this should become
 188  192   * dynamically loaded. Make sure changes here are reflected in
 189      - * cmd/fs.d/nfs/mountd/nfscmd.c
      193 + * cmd/fs.d/nfs/mountd/nfs_cmd.c
 190  194   */
 191  195  
 192  196  static char *legal_conv[] = {
 193  197          "euc-cn",
 194  198          "euc-jp",
 195  199          "euc-jpms",
 196  200          "euc-kr",
 197  201          "euc-tw",
 198  202          "iso8859-1",
 199  203          "iso8859-2",
↓ open down ↓ 820 lines elided ↑ open up ↑
1020 1024                           */
1021 1025                          export->ex_flags |= EX_CHARMAP;
1022 1026                          break;
1023 1027                  case OPT_NOACLFAB:
1024 1028                          if (value != NULL && (strcasecmp(value, "true") == 0 ||
1025 1029                              strcmp(value, "1") == 0))
1026 1030                                  export->ex_flags |= EX_NOACLFAB;
1027 1031                          else
1028 1032                                  export->ex_flags &= ~EX_NOACLFAB;
1029 1033                          break;
     1034 +                case OPT_NOHIDE:
     1035 +                        if (value != NULL && (strcasecmp(value, "true") == 0 ||
     1036 +                            strcmp(value, "1") == 0))
     1037 +                                export->ex_flags |= EX_NOHIDE;
     1038 +                        else
     1039 +                                export->ex_flags &= ~EX_NOHIDE;
     1040 +
     1041 +                        break;
1030 1042                  default:
1031 1043                          /* have a syntactic error */
1032 1044                          (void) printf(dgettext(TEXT_DOMAIN,
1033 1045                              "NFS: unrecognized option %s=%s\n"),
1034 1046                              name != NULL ? name : "",
1035 1047                              value != NULL ? value : "");
1036 1048                          break;
1037 1049                  }
1038 1050                  if (name != NULL)
1039 1051                          sa_free_attr_string(name);
↓ open down ↓ 734 lines elided ↑ open up ↑
1774 1786          int num_secinfo;
1775 1787          sa_optionset_t opt;
1776 1788          sa_security_t sec;
1777 1789          sa_property_t prop;
1778 1790          char *path;
1779 1791          int err = SA_OK;
1780 1792          int i;
1781 1793          int iszfs;
1782 1794          sa_handle_t handle;
1783 1795  
     1796 +        static int check_services = B_TRUE;
     1797 +
1784 1798          /* Don't drop core if the NFS module isn't loaded. */
1785 1799          (void) signal(SIGSYS, SIG_IGN);
1786 1800  
1787 1801          /* get the path since it is important in several places */
1788 1802          path = sa_get_share_attr(share, "path");
1789 1803          if (path == NULL)
1790 1804                  return (SA_NO_SUCH_PATH);
1791 1805  
1792 1806          iszfs = sa_path_is_zfs(path);
1793 1807          /*
↓ open down ↓ 94 lines elided ↑ open up ↑
1888 1902                          sp[i].s_window = DEF_WIN;
1889 1903                          sp[i].s_rootcnt = 0;
1890 1904                          sp[i].s_rootnames = NULL;
1891 1905                          (void) fill_security_from_secopts(&sp[i], sec);
1892 1906                          if (sec != NULL)
1893 1907                                  sa_free_derived_security(sec);
1894 1908                          if (sectype != NULL)
1895 1909                                  sa_free_attr_string(sectype);
1896 1910                  }
1897 1911          }
1898      -        /*
1899      -         * when we get here, we can do the exportfs system call and
1900      -         * initiate things. We probably want to enable the
1901      -         * svc:/network/nfs/server service first if it isn't running.
1902      -         */
1903      -        /* check svc:/network/nfs/server status and start if needed */
     1912 +
1904 1913          /* now add the share to the internal tables */
1905 1914          printarg(path, &export);
1906 1915          /*
1907 1916           * call the exportfs system call which is implemented
1908 1917           * via the nfssys() call as the EXPORTFS subfunction.
1909 1918           */
1910 1919          if (iszfs) {
1911 1920                  struct exportfs_args ea;
1912 1921                  share_t sh;
1913      -                char *str;
1914      -                priv_set_t *priv_effective;
1915      -                int privileged;
1916 1922  
1917      -                /*
1918      -                 * If we aren't a privileged user
1919      -                 * and NFS server service isn't running
1920      -                 * then print out an error message
1921      -                 * and return EPERM
1922      -                 */
     1923 +                ea.dname = path;
     1924 +                ea.uex = &export;
1923 1925  
1924      -                priv_effective = priv_allocset();
1925      -                (void) getppriv(PRIV_EFFECTIVE, priv_effective);
1926      -
1927      -                privileged = (priv_isfullset(priv_effective) == B_TRUE);
1928      -                priv_freeset(priv_effective);
1929      -
1930      -                if (!privileged &&
1931      -                    (str = smf_get_state(NFS_SERVER_SVC)) != NULL) {
1932      -                        err = 0;
1933      -                        if (strcmp(str, SCF_STATE_STRING_ONLINE) != 0) {
1934      -                                (void) printf(dgettext(TEXT_DOMAIN,
1935      -                                    "NFS: Cannot share remote "
1936      -                                    "filesystem: %s\n"), path);
1937      -                                (void) printf(dgettext(TEXT_DOMAIN,
1938      -                                    "NFS: Service needs to be enabled "
1939      -                                    "by a privileged user\n"));
1940      -                                err = SA_SYSTEM_ERR;
1941      -                                errno = EPERM;
1942      -                        }
1943      -                        free(str);
     1926 +                (void) sa_sharetab_fill_zfs(share, &sh, "nfs");
     1927 +                err = sa_share_zfs(share, NULL, path, &sh, &ea, ZFS_SHARE_NFS);
     1928 +                if (err != SA_OK) {
     1929 +                        errno = err;
     1930 +                        err = -1;
1944 1931                  }
1945      -
1946      -                if (err == 0) {
1947      -                        ea.dname = path;
1948      -                        ea.uex = &export;
1949      -
1950      -                        (void) sa_sharetab_fill_zfs(share, &sh, "nfs");
1951      -                        err = sa_share_zfs(share, NULL, path, &sh,
1952      -                            &ea, ZFS_SHARE_NFS);
1953      -                        if (err != SA_OK) {
1954      -                                errno = err;
1955      -                                err = -1;
1956      -                        }
1957      -                        sa_emptyshare(&sh);
1958      -                }
     1932 +                sa_emptyshare(&sh);
1959 1933          } else {
1960 1934                  err = exportfs(path, &export);
1961 1935          }
1962 1936  
1963 1937          if (err < 0) {
1964 1938                  err = SA_SYSTEM_ERR;
1965 1939                  switch (errno) {
1966      -                case EREMOTE:
1967      -                        (void) printf(dgettext(TEXT_DOMAIN,
1968      -                            "NFS: Cannot share filesystems "
1969      -                            "in non-global zones: %s\n"), path);
1970      -                        err = SA_NOT_SUPPORTED;
1971      -                        break;
1972 1940                  case EPERM:
1973      -                        if (getzoneid() != GLOBAL_ZONEID) {
1974      -                                (void) printf(dgettext(TEXT_DOMAIN,
1975      -                                    "NFS: Cannot share file systems "
1976      -                                    "in non-global zones: %s\n"), path);
1977      -                                err = SA_NOT_SUPPORTED;
1978      -                                break;
1979      -                        }
1980 1941                          err = SA_NO_PERMISSION;
1981 1942                          break;
1982 1943                  case EEXIST:
1983 1944                          err = SA_SHARE_EXISTS;
1984 1945                          break;
1985 1946                  default:
1986 1947                          break;
1987 1948                  }
1988 1949          } else {
1989 1950                  /* update sharetab with an add/modify */
1990 1951                  if (!iszfs) {
1991 1952                          (void) sa_update_sharetab(share, "nfs");
1992 1953                  }
1993 1954          }
1994 1955  
1995 1956          if (err == SA_OK) {
1996 1957                  /*
1997      -                 * enable services as needed. This should probably be
1998      -                 * done elsewhere in order to minimize the calls to
1999      -                 * check services.
     1958 +                 * Enable services, if required.
     1959 +                 * This is only done the first time the function is called,
     1960 +                 * per instatiation of the library.
2000 1961                   */
     1962 +                if (check_services) {
     1963 +                        _check_services(service_list_default);
     1964 +                        check_services = B_FALSE;
     1965 +                }
     1966 +
2001 1967                  /*
2002      -                 * check to see if logging and other services need to
2003      -                 * be triggered, but only if there wasn't an
2004      -                 * error. This is probably where sharetab should be
2005      -                 * updated with the NFS specific entry.
     1968 +                 * Enable logging.
2006 1969                   */
2007 1970                  if (export.ex_flags & EX_LOG) {
2008      -                        /* enable logging */
2009 1971                          if (nfslogtab_add(path, export.ex_log_buffer,
2010 1972                              export.ex_tag) != 0) {
2011 1973                                  (void) fprintf(stderr, dgettext(TEXT_DOMAIN,
2012 1974                                      "Could not enable logging for %s\n"),
2013 1975                                      path);
2014 1976                          }
2015 1977                          _check_services(service_list_logging);
2016 1978                  } else {
2017 1979                          /*
2018 1980                           * don't have logging so remove it from file. It might
2019 1981                           * not be thre, but that doesn't matter.
2020 1982                           */
2021 1983                          (void) nfslogtab_deactivate(path);
2022      -                        _check_services(service_list_default);
2023 1984                  }
2024 1985          }
2025 1986  
2026 1987  out:
2027 1988          if (path != NULL)
2028 1989                  free(path);
2029 1990  
2030 1991          cleanup_export(&export);
2031 1992          if (opt != NULL)
2032 1993                  sa_free_derived_optionset(opt);
↓ open down ↓ 48 lines elided ↑ open up ↑
2081 2042          }
2082 2043          if (err < 0) {
2083 2044                  /*
2084 2045                   * TBD: only an error in some
2085 2046                   * cases - need better analysis
2086 2047                   */
2087 2048                  switch (errno) {
2088 2049                  case EPERM:
2089 2050                  case EACCES:
2090 2051                          ret = SA_NO_PERMISSION;
2091      -                        if (getzoneid() != GLOBAL_ZONEID) {
2092      -                                ret = SA_NOT_SUPPORTED;
2093      -                        }
2094 2052                          break;
2095 2053                  case EINVAL:
2096 2054                  case ENOENT:
2097 2055                          ret = SA_NO_SUCH_PATH;
2098 2056                          break;
2099 2057                  default:
2100 2058                          ret = SA_SYSTEM_ERR;
2101 2059                          break;
2102 2060                  }
2103 2061          }
↓ open down ↓ 1139 lines elided ↑ open up ↑
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX