Print this page
11083 support NFS server in zone
Portions contributed by: Dan Kruchinin <dan.kruchinin@nexenta.com>
Portions contributed by: Stepan Zastupov <stepan.zastupov@gmail.com>
Portions contributed by: Joyce McIntosh <joyce.mcintosh@nexenta.com>
Portions contributed by: Mike Zeller <mike@mikezeller.net>
Portions contributed by: Dan McDonald <danmcd@joyent.com>
Portions contributed by: Gordon Ross <gordon.w.ross@gmail.com>
Portions contributed by: Vitaliy Gusev <gusev.vitaliy@gmail.com>
Reviewed by: Rick McNeal <rick.mcneal@nexenta.com>
Reviewed by: Rob Gittins <rob.gittins@nexenta.com>
Reviewed by: Sanjay Nadkarni <sanjay.nadkarni@nexenta.com>
Reviewed by: Jason King <jbk@joyent.com>
Reviewed by: C Fraire <cfraire@me.com>
Change-Id: I22f289d357503f9b48a0bc2482cc4328a6d43d16

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.
  25   24   * Copyright (c) 2014, 2016 by Delphix. All rights reserved.
       25 + * Copyright 2018 Nexenta Systems, Inc.
  26   26   */
  27   27  
  28   28  /*
  29   29   * NFS specific functions
  30   30   */
       31 +
  31   32  #include <stdio.h>
  32   33  #include <string.h>
  33   34  #include <ctype.h>
  34   35  #include <stdlib.h>
  35   36  #include <unistd.h>
  36      -#include <zone.h>
  37   37  #include <errno.h>
  38   38  #include <locale.h>
  39   39  #include <signal.h>
  40   40  #include <strings.h>
  41   41  #include "libshare.h"
  42   42  #include "libshare_impl.h"
  43   43  #include <nfs/export.h>
  44   44  #include <pwd.h>
  45   45  #include <grp.h>
  46   46  #include <limits.h>
↓ open down ↓ 1851 lines elided ↑ open up ↑
1898 1898                          sp[i].s_window = DEF_WIN;
1899 1899                          sp[i].s_rootcnt = 0;
1900 1900                          sp[i].s_rootnames = NULL;
1901 1901                          (void) fill_security_from_secopts(&sp[i], sec);
1902 1902                          if (sec != NULL)
1903 1903                                  sa_free_derived_security(sec);
1904 1904                          if (sectype != NULL)
1905 1905                                  sa_free_attr_string(sectype);
1906 1906                  }
1907 1907          }
1908      -        /*
1909      -         * when we get here, we can do the exportfs system call and
1910      -         * initiate things. We probably want to enable the
1911      -         * svc:/network/nfs/server service first if it isn't running.
1912      -         */
1913      -        /* check svc:/network/nfs/server status and start if needed */
     1908 +
1914 1909          /* now add the share to the internal tables */
1915 1910          printarg(path, &export);
1916 1911          /*
1917 1912           * call the exportfs system call which is implemented
1918 1913           * via the nfssys() call as the EXPORTFS subfunction.
1919 1914           */
1920 1915          if (iszfs) {
1921 1916                  struct exportfs_args ea;
1922 1917                  share_t sh;
1923      -                char *str;
1924      -                priv_set_t *priv_effective;
1925      -                int privileged;
1926 1918  
1927      -                /*
1928      -                 * If we aren't a privileged user
1929      -                 * and NFS server service isn't running
1930      -                 * then print out an error message
1931      -                 * and return EPERM
1932      -                 */
     1919 +                ea.dname = path;
     1920 +                ea.uex = &export;
1933 1921  
1934      -                priv_effective = priv_allocset();
1935      -                (void) getppriv(PRIV_EFFECTIVE, priv_effective);
1936      -
1937      -                privileged = (priv_isfullset(priv_effective) == B_TRUE);
1938      -                priv_freeset(priv_effective);
1939      -
1940      -                if (!privileged &&
1941      -                    (str = smf_get_state(NFS_SERVER_SVC)) != NULL) {
1942      -                        err = 0;
1943      -                        if (strcmp(str, SCF_STATE_STRING_ONLINE) != 0) {
1944      -                                (void) printf(dgettext(TEXT_DOMAIN,
1945      -                                    "NFS: Cannot share remote "
1946      -                                    "filesystem: %s\n"), path);
1947      -                                (void) printf(dgettext(TEXT_DOMAIN,
1948      -                                    "NFS: Service needs to be enabled "
1949      -                                    "by a privileged user\n"));
1950      -                                err = SA_SYSTEM_ERR;
1951      -                                errno = EPERM;
1952      -                        }
1953      -                        free(str);
     1922 +                (void) sa_sharetab_fill_zfs(share, &sh, "nfs");
     1923 +                err = sa_share_zfs(share, NULL, path, &sh, &ea, ZFS_SHARE_NFS);
     1924 +                if (err != SA_OK) {
     1925 +                        errno = err;
     1926 +                        err = -1;
1954 1927                  }
1955      -
1956      -                if (err == 0) {
1957      -                        ea.dname = path;
1958      -                        ea.uex = &export;
1959      -
1960      -                        (void) sa_sharetab_fill_zfs(share, &sh, "nfs");
1961      -                        err = sa_share_zfs(share, NULL, path, &sh,
1962      -                            &ea, ZFS_SHARE_NFS);
1963      -                        if (err != SA_OK) {
1964      -                                errno = err;
1965      -                                err = -1;
1966      -                        }
1967      -                        sa_emptyshare(&sh);
1968      -                }
     1928 +                sa_emptyshare(&sh);
1969 1929          } else {
1970 1930                  err = exportfs(path, &export);
1971 1931          }
1972 1932  
1973 1933          if (err < 0) {
1974 1934                  err = SA_SYSTEM_ERR;
1975 1935                  switch (errno) {
1976      -                case EREMOTE:
1977      -                        (void) printf(dgettext(TEXT_DOMAIN,
1978      -                            "NFS: Cannot share filesystems "
1979      -                            "in non-global zones: %s\n"), path);
1980      -                        err = SA_NOT_SUPPORTED;
1981      -                        break;
1982 1936                  case EPERM:
1983      -                        if (getzoneid() != GLOBAL_ZONEID) {
1984      -                                (void) printf(dgettext(TEXT_DOMAIN,
1985      -                                    "NFS: Cannot share file systems "
1986      -                                    "in non-global zones: %s\n"), path);
1987      -                                err = SA_NOT_SUPPORTED;
1988      -                                break;
1989      -                        }
1990 1937                          err = SA_NO_PERMISSION;
1991 1938                          break;
1992 1939                  case EEXIST:
1993 1940                          err = SA_SHARE_EXISTS;
1994 1941                          break;
1995 1942                  default:
1996 1943                          break;
1997 1944                  }
1998 1945          } else {
1999 1946                  /* update sharetab with an add/modify */
↓ open down ↓ 91 lines elided ↑ open up ↑
2091 2038          }
2092 2039          if (err < 0) {
2093 2040                  /*
2094 2041                   * TBD: only an error in some
2095 2042                   * cases - need better analysis
2096 2043                   */
2097 2044                  switch (errno) {
2098 2045                  case EPERM:
2099 2046                  case EACCES:
2100 2047                          ret = SA_NO_PERMISSION;
2101      -                        if (getzoneid() != GLOBAL_ZONEID) {
2102      -                                ret = SA_NOT_SUPPORTED;
2103      -                        }
2104 2048                          break;
2105 2049                  case EINVAL:
2106 2050                  case ENOENT:
2107 2051                          ret = SA_NO_SUCH_PATH;
2108 2052                          break;
2109 2053                  default:
2110 2054                          ret = SA_SYSTEM_ERR;
2111 2055                          break;
2112 2056                  }
2113 2057          }
↓ open down ↓ 1139 lines elided ↑ open up ↑
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX