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/uts/common/fs/nfs/nfs4_srv_attr.c
          +++ new/usr/src/uts/common/fs/nfs/nfs4_srv_attr.c
↓ open down ↓ 10 lines elided ↑ open up ↑
  11   11   * and limitations under the License.
  12   12   *
  13   13   * When distributing Covered Code, include this CDDL HEADER in each
  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   * Copyright 2010 Sun Microsystems, Inc.  All rights reserved.
  23   24   * Use is subject to license terms.
  24   25   */
       26 +
  25   27  /*
  26      - * Copyright 2012 Nexenta Systems, Inc. All rights reserved.
       28 + * Copyright 2018 Nexenta Systems, Inc.
  27   29   */
  28   30  
  29   31  #include <sys/systm.h>
  30   32  #include <sys/cmn_err.h>
  31   33  #include <nfs/nfs.h>
  32   34  #include <nfs/export.h>
  33   35  #include <nfs/nfs4.h>
  34   36  #include <sys/ddi.h>
  35   37  #include <sys/door.h>
  36   38  #include <sys/sdt.h>
↓ open down ↓ 89 lines elided ↑ open up ↑
 126  128   */
 127  129  void
 128  130  rfs4_attr_init()
 129  131  {
 130  132          int i;
 131  133          struct nfs4_svgetit_arg sarg;
 132  134          struct compound_state cs;
 133  135          struct statvfs64 sb;
 134  136  
 135  137          rfs4_init_compound_state(&cs);
      138 +        /*
      139 +         * This is global state checking, called once. We might be in
      140 +         * non-global-zone context here (say a modload happens from a zone
      141 +         * process) so in this case, we want the global-zone root vnode.
      142 +         */
 136  143          cs.vp = rootvp;
 137  144          cs.fh.nfs_fh4_val = NULL;
 138  145          cs.cr = kcred;
 139  146  
 140  147          /*
 141  148           * Get all the supported attributes
 142  149           */
 143  150          sarg.op = NFS4ATTR_SUPPORTED;
 144  151          sarg.cs = &cs;
 145  152          sarg.vap->va_mask = AT_ALL;
↓ open down ↓ 1148 lines elided ↑ open up ↑
1294 1301  static int
1295 1302  rfs4_get_mntdfileid(nfs4_attr_cmd_t cmd, struct nfs4_svgetit_arg *sarg)
1296 1303  {
1297 1304          int error = 0;
1298 1305          vattr_t *vap, va;
1299 1306          vnode_t *stubvp = NULL, *vp;
1300 1307  
1301 1308          vp = sarg->cs->vp;
1302 1309          sarg->mntdfid_set = FALSE;
1303 1310  
1304      -        /* VROOT object, must untraverse */
1305      -        if (vp->v_flag & VROOT) {
     1311 +        /*
     1312 +         * VROOT object or zone's root, must untraverse.
     1313 +         *
     1314 +         * NOTE: Not doing reality checks on curzone vs. compound
     1315 +         * state vnode because it will mismatch once at initialization
     1316 +         * if a non-global-zone triggers the module load, BUT in that case
     1317 +         * the vp is literally "/" which has VROOT set.
     1318 +         */
     1319 +        if ((vp->v_flag & VROOT) || VN_IS_CURZONEROOT(vp)) {
1306 1320  
1307 1321                  /* extra hold for vp since untraverse might rele */
1308 1322                  VN_HOLD(vp);
1309      -                stubvp = untraverse(vp);
     1323 +                stubvp = untraverse(vp, ZONE_ROOTVP());
1310 1324  
1311 1325                  /*
1312      -                 * If vp/stubvp are same, we must be at system
     1326 +                 * If vp/stubvp are same, we must be at system-or-zone
1313 1327                   * root because untraverse returned same vp
1314 1328                   * for a VROOT object.  sarg->vap was setup
1315 1329                   * before we got here, so there's no need to do
1316 1330                   * another getattr -- just use the one in sarg.
1317 1331                   */
1318 1332                  if (VN_CMP(vp, stubvp)) {
1319      -                        ASSERT(VN_CMP(vp, rootdir));
     1333 +                        ASSERT(VN_IS_CURZONEROOT(vp));
1320 1334                          vap = sarg->vap;
1321 1335                  } else {
1322 1336                          va.va_mask = AT_NODEID;
1323 1337                          vap = &va;
1324 1338                          error = rfs4_vop_getattr(stubvp, vap, 0, sarg->cs->cr);
1325 1339                  }
1326 1340  
1327 1341                  /*
1328 1342                   * Done with stub, time to rele.  If vp and stubvp
1329 1343                   * were the same, then we need to rele either vp or
↓ open down ↓ 38 lines elided ↑ open up ↑
1368 1382          if (RFS4_MANDATTR_ONLY)
1369 1383                  return (ENOTSUP);
1370 1384  
1371 1385          switch (cmd) {
1372 1386          case NFS4ATTR_SUPPORTED:
1373 1387                  if (sarg->op == NFS4ATTR_SETIT)
1374 1388                          error = EINVAL;
1375 1389                  break;          /* this attr is supported */
1376 1390          case NFS4ATTR_GETIT:
1377 1391          case NFS4ATTR_VERIT:
1378      -                if (! sarg->mntdfid_set)
     1392 +                if (!sarg->mntdfid_set)
1379 1393                          error = rfs4_get_mntdfileid(cmd, sarg);
1380 1394  
1381      -                if (! error && sarg->mntdfid_set) {
     1395 +                if (!error && sarg->mntdfid_set) {
1382 1396                          if (cmd == NFS4ATTR_GETIT)
1383 1397                                  na->mounted_on_fileid = sarg->mounted_on_fileid;
1384 1398                          else
1385 1399                                  if (na->mounted_on_fileid !=
1386 1400                                      sarg->mounted_on_fileid)
1387 1401                                          error = -1;
1388 1402                  }
1389 1403                  break;
1390 1404          case NFS4ATTR_SETIT:
1391 1405                  /* read-only attr */
↓ open down ↓ 196 lines elided ↑ open up ↑
1588 1602          if (RFS4_MANDATTR_ONLY)
1589 1603                  return (ENOTSUP);
1590 1604  
1591 1605          switch (cmd) {
1592 1606          case NFS4ATTR_SUPPORTED:
1593 1607                  if (sarg->op == NFS4ATTR_SETIT || sarg->op == NFS4ATTR_VERIT)
1594 1608                          error = EINVAL;
1595 1609                  break;  /* this attr is supported */
1596 1610  
1597 1611          case NFS4ATTR_GETIT:
     1612 +        {
     1613 +                kstat_named_t *stat =
     1614 +                    sarg->cs->exi->exi_ne->ne_globals->svstat[NFS_V4];
     1615 +
1598 1616                  fsl = fetch_referral(sarg->cs->vp, sarg->cs->cr);
1599 1617                  if (fsl == NULL)
1600 1618                          (void) memset(&(na->fs_locations), 0,
1601 1619                              sizeof (fs_locations4));
1602 1620                  else {
1603 1621                          na->fs_locations = *fsl;
1604 1622                          kmem_free(fsl, sizeof (fs_locations4));
1605 1623                  }
1606      -                global_svstat_ptr[4][NFS_REFERRALS].value.ui64++;
     1624 +                stat[NFS_REFERRALS].value.ui64++;
1607 1625                  break;
1608      -
     1626 +        }
1609 1627          case NFS4ATTR_FREEIT:
1610 1628                  if (sarg->op == NFS4ATTR_SETIT || sarg->op == NFS4ATTR_VERIT)
1611 1629                          error = EINVAL;
1612 1630                  rfs4_free_fs_locations4(&na->fs_locations);
1613 1631                  break;
1614 1632  
1615 1633          case NFS4ATTR_SETIT:
1616 1634          case NFS4ATTR_VERIT:
1617 1635                  /*
1618 1636                   * read-only attr
↓ open down ↓ 1242 lines elided ↑ open up ↑
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX