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/common/libshare_zfs.c
          +++ new/usr/src/lib/libshare/common/libshare_zfs.c
↓ open down ↓ 14 lines elided ↑ open up ↑
  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   24   */
       25 +
  25   26  /*
  26      - * Copyright 2012 Nexenta Systems, Inc.  All rights reserved.
  27   27   * Copyright (c) 2012, 2016 by Delphix. All rights reserved.
  28   28   * Copyright 2017 RackTop Systems.
       29 + * Copyright 2019 Nexenta Systems, Inc.
  29   30   */
  30   31  
  31   32  #include <stdio.h>
  32   33  #include <libzfs.h>
  33   34  #include <string.h>
  34   35  #include <strings.h>
  35   36  #include <errno.h>
       37 +#include <zone.h>
  36   38  #include <libshare.h>
  37   39  #include "libshare_impl.h"
  38   40  #include <libintl.h>
  39   41  #include <sys/mnttab.h>
  40   42  #include <sys/mntent.h>
  41   43  #include <assert.h>
  42   44  
  43   45  extern sa_share_t _sa_add_share(sa_group_t, char *, int, int *, uint64_t);
  44   46  extern sa_group_t _sa_create_zfs_group(sa_group_t, char *);
  45   47  extern char *sa_fstype(char *);
↓ open down ↓ 185 lines elided ↑ open up ↑
 231  233  /*
 232  234   * return legacy mountpoint.  Caller provides space for mountpoint and
 233  235   * dataset.
 234  236   */
 235  237  int
 236  238  get_legacy_mountpoint(const char *path, char *dataset, size_t dlen,
 237  239      char *mountpoint, size_t mlen)
 238  240  {
 239  241          FILE *fp;
 240  242          struct mnttab entry;
      243 +        int rc = 1;
 241  244  
 242  245          if ((fp = fopen(MNTTAB, "r")) == NULL) {
 243  246                  return (1);
 244  247          }
 245  248  
 246  249          while (getmntent(fp, &entry) == 0) {
 247  250  
 248  251                  if (entry.mnt_fstype == NULL ||
 249  252                      strcmp(entry.mnt_fstype, MNTTYPE_ZFS) != 0)
 250  253                          continue;
 251  254  
 252  255                  if (strcmp(entry.mnt_mountp, path) == 0) {
 253  256                          if (mlen > 0)
 254  257                                  (void) strlcpy(mountpoint, entry.mnt_mountp,
 255  258                                      mlen);
 256  259                          if (dlen > 0)
 257  260                                  (void) strlcpy(dataset, entry.mnt_special,
 258  261                                      dlen);
      262 +                        rc = 0;
 259  263                          break;
 260  264                  }
 261  265          }
 262  266          (void) fclose(fp);
 263      -        return (1);
      267 +        return (rc);
 264  268  }
 265  269  
 266  270  
 267  271  /*
 268  272   * Verifies that a specific zfs filesystem handle meets the criteria necessary
 269  273   * to be used by libshare operations. See get_zfs_dataset.
 270  274   */
 271  275  static char *
 272  276  verify_zfs_handle(zfs_handle_t *hdl, const char *path, boolean_t search_mnttab)
 273  277  {
↓ open down ↓ 536 lines elided ↑ open up ↑
 810  814                  return (SA_SYSTEM_ERR);
 811  815  
 812  816          /*
 813  817           * only deal with "mounted" file systems since
 814  818           * unmounted file systems can't actually be shared.
 815  819           */
 816  820  
 817  821          if (!zfs_is_mounted(fs_handle, NULL))
 818  822                  return (SA_SYSTEM_ERR);
 819  823  
      824 +        /*
      825 +         * Ignore "zoned" datasets in global zone.
      826 +         */
      827 +        if (getzoneid() == GLOBAL_ZONEID &&
      828 +            zfs_prop_get_int(fs_handle, ZFS_PROP_ZONED))
      829 +                return (SA_SYSTEM_ERR);
      830 +
 820  831          nfs = nfs_inherited = B_FALSE;
 821  832  
 822  833          if (zfs_prop_get(fs_handle, ZFS_PROP_SHARENFS, nfsshareopts,
 823  834              sizeof (nfsshareopts), &source, nfssourcestr,
 824  835              ZFS_MAXPROPLEN, B_FALSE) == 0 &&
 825  836              strcmp(nfsshareopts, "off") != 0) {
 826  837                  if (source & ZPROP_SRC_INHERITED)
 827  838                          nfs_inherited = B_TRUE;
 828  839                  else
 829  840                          nfs = B_TRUE;
↓ open down ↓ 138 lines elided ↑ open up ↑
 968  979          for (int i = 0; i < count; i++) {
 969  980                  err = sa_get_zfs_share_common(handle, zlist[i], NULL, zfsgroup);
 970  981          }
 971  982          /*
 972  983           * Don't need to free the "zlist" variable since it is only a
 973  984           * pointer to a cached value that will be freed when
 974  985           * sa_fini() is called.
 975  986           */
 976  987          return (err);
 977  988  }
      989 +
      990 +/*
      991 + * Initializes shares for only the dataset specified fs_handle.
      992 + * This is used as a performance optimization relative to sa_get_zfs_shares.
      993 + */
      994 +int
      995 +sa_get_zfs_share(sa_handle_t handle, char *groupname, zfs_handle_t *fs_handle)
      996 +{
      997 +        sa_group_t zfsgroup;
      998 +        libzfs_handle_t *zfs_libhandle;
      999 +        int err;
     1000 +
     1001 +        if ((err = prep_zfs_handle_and_group(handle, groupname, &zfs_libhandle,
     1002 +            &zfsgroup, &err)) != SA_OK) {
     1003 +                return (err);
     1004 +        }
     1005 +        /* Not an error, this could be a legacy condition */
     1006 +        if (zfsgroup == NULL)
     1007 +                return (SA_OK);
     1008 +
     1009 +        err = sa_get_zfs_share_common(handle, fs_handle, NULL, zfsgroup);
     1010 +        return (err);
     1011 +}
 978 1012  
 979 1013  /*
 980 1014   * Initializes only the handles specified in the sharearg for use with libshare.
 981 1015   * This is used as a performance optimization relative to sa_get_zfs_shares.
 982 1016   */
 983 1017  int
 984 1018  sa_get_one_zfs_share(sa_handle_t handle, char *groupname,
 985 1019      sa_init_selective_arg_t *sharearg, char ***paths, size_t *paths_len)
 986 1020  {
 987 1021          sa_group_t zfsgroup;
↓ open down ↓ 749 lines elided ↑ open up ↑
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX