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
        
*** 20,40 ****
   */
  
  /*
   * Copyright (c) 2006, 2010, Oracle and/or its affiliates. All rights reserved.
   */
  /*
-  * Copyright 2012 Nexenta Systems, Inc.  All rights reserved.
   * Copyright (c) 2012, 2016 by Delphix. All rights reserved.
   * Copyright 2017 RackTop Systems.
   */
  
  #include <stdio.h>
  #include <libzfs.h>
  #include <string.h>
  #include <strings.h>
  #include <errno.h>
  #include <libshare.h>
  #include "libshare_impl.h"
  #include <libintl.h>
  #include <sys/mnttab.h>
  #include <sys/mntent.h>
--- 20,42 ----
   */
  
  /*
   * Copyright (c) 2006, 2010, Oracle and/or its affiliates. All rights reserved.
   */
+ 
  /*
   * Copyright (c) 2012, 2016 by Delphix. All rights reserved.
   * Copyright 2017 RackTop Systems.
+  * Copyright 2019 Nexenta Systems, Inc.
   */
  
  #include <stdio.h>
  #include <libzfs.h>
  #include <string.h>
  #include <strings.h>
  #include <errno.h>
+ #include <zone.h>
  #include <libshare.h>
  #include "libshare_impl.h"
  #include <libintl.h>
  #include <sys/mnttab.h>
  #include <sys/mntent.h>
*** 236,245 ****
--- 238,248 ----
  get_legacy_mountpoint(const char *path, char *dataset, size_t dlen,
      char *mountpoint, size_t mlen)
  {
          FILE *fp;
          struct mnttab entry;
+         int rc = 1;
  
          if ((fp = fopen(MNTTAB, "r")) == NULL) {
                  return (1);
          }
  
*** 254,268 ****
                                  (void) strlcpy(mountpoint, entry.mnt_mountp,
                                      mlen);
                          if (dlen > 0)
                                  (void) strlcpy(dataset, entry.mnt_special,
                                      dlen);
                          break;
                  }
          }
          (void) fclose(fp);
!         return (1);
  }
  
  
  /*
   * Verifies that a specific zfs filesystem handle meets the criteria necessary
--- 257,272 ----
                                  (void) strlcpy(mountpoint, entry.mnt_mountp,
                                      mlen);
                          if (dlen > 0)
                                  (void) strlcpy(dataset, entry.mnt_special,
                                      dlen);
+                         rc = 0;
                          break;
                  }
          }
          (void) fclose(fp);
!         return (rc);
  }
  
  
  /*
   * Verifies that a specific zfs filesystem handle meets the criteria necessary
*** 815,824 ****
--- 819,835 ----
           */
  
          if (!zfs_is_mounted(fs_handle, NULL))
                  return (SA_SYSTEM_ERR);
  
+         /*
+          * Ignore "zoned" datasets in global zone.
+          */
+         if (getzoneid() == GLOBAL_ZONEID &&
+             zfs_prop_get_int(fs_handle, ZFS_PROP_ZONED))
+                 return (SA_SYSTEM_ERR);
+ 
          nfs = nfs_inherited = B_FALSE;
  
          if (zfs_prop_get(fs_handle, ZFS_PROP_SHARENFS, nfsshareopts,
              sizeof (nfsshareopts), &source, nfssourcestr,
              ZFS_MAXPROPLEN, B_FALSE) == 0 &&
*** 973,982 ****
--- 984,1016 ----
           * pointer to a cached value that will be freed when
           * sa_fini() is called.
           */
          return (err);
  }
+ 
+ /*
+  * Initializes shares for only the dataset specified fs_handle.
+  * This is used as a performance optimization relative to sa_get_zfs_shares.
+  */
+ int
+ sa_get_zfs_share(sa_handle_t handle, char *groupname, zfs_handle_t *fs_handle)
+ {
+         sa_group_t zfsgroup;
+         libzfs_handle_t *zfs_libhandle;
+         int err;
+ 
+         if ((err = prep_zfs_handle_and_group(handle, groupname, &zfs_libhandle,
+             &zfsgroup, &err)) != SA_OK) {
+                 return (err);
+         }
+         /* Not an error, this could be a legacy condition */
+         if (zfsgroup == NULL)
+                 return (SA_OK);
+ 
+         err = sa_get_zfs_share_common(handle, fs_handle, NULL, zfsgroup);
+         return (err);
+ }
  
  /*
   * Initializes only the handles specified in the sharearg for use with libshare.
   * This is used as a performance optimization relative to sa_get_zfs_shares.
   */