Print this page
    
Revert exi_zone to exi_zoneid, and install exi_ne backpointer
Caution with use after exi_rele()
Ooops exi_zoneid isn't a variable again yet
Be far more judicious in the use of curzone-using macros.
(Merge and extra asserts by danmcd.)
curzone reality check and teardown changes to use the RIGHT zone
Try to remove assumption that zone's root vnode is marked VROOT
    
      
        | Split | 
	Close | 
      
      | Expand all | 
      | Collapse all | 
    
    
          --- old/usr/src/uts/common/fs/nfs/nfs4_srv_ns.c
          +++ new/usr/src/uts/common/fs/nfs/nfs4_srv_ns.c
   1    1  /*
   2    2   * CDDL HEADER START
   3    3   *
   4    4   * The contents of this file are subject to the terms of the
   5    5   * Common Development and Distribution License (the "License").
   6    6   * You may not use this file except in compliance with the License.
   7    7   *
   8    8   * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
   9    9   * or http://www.opensolaris.org/os/licensing.
  10   10   * See the License for the specific language governing permissions
  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   23   * Copyright (c) 2003, 2010, Oracle and/or its affiliates. All rights reserved.
  24   24   */
  25   25  
  26   26  /*
  27   27   * Copyright 2018 Nexenta Systems, Inc.
  28   28   * Copyright (c) 2015, Joyent, Inc.
  29   29   */
  30   30  
  31   31  #include <sys/systm.h>
  32   32  
  33   33  #include <nfs/nfs.h>
  34   34  #include <nfs/export.h>
  35   35  #include <sys/cmn_err.h>
  36   36  #include <sys/avl.h>
  37   37  
  38   38  #define PSEUDOFS_SUFFIX         " (pseudo)"
  39   39  
  40   40  /*
  41   41   * A version of VOP_FID that deals with a remote VOP_FID for nfs.
  42   42   * If vp is an nfs node, nfs4_fid() returns EREMOTE, nfs3_fid() and nfs_fid()
  43   43   * returns the filehandle of vp as its fid. When nfs uses fid to set the
  44   44   * exportinfo filehandle template, a remote nfs filehandle would be too big for
  45   45   * the fid of the exported directory. This routine remaps the value of the
  46   46   * attribute va_nodeid of vp to be the fid of vp, so that the fid can fit.
  47   47   *
  48   48   * We need this fid mainly for setting up NFSv4 server namespace where an
  49   49   * nfs filesystem is also part of it. Thus, need to be able to setup a pseudo
  50   50   * exportinfo for an nfs node.
  51   51   *
  52   52   * e.g. mount a filesystem on top of a nfs dir, and then share the new mount
  53   53   *      (like exporting a local disk from a "diskless" client)
  54   54   */
  55   55  int
  56   56  vop_fid_pseudo(vnode_t *vp, fid_t *fidp)
  57   57  {
  58   58          struct vattr va;
  59   59          int error;
  60   60  
  61   61          error = VOP_FID(vp, fidp, NULL);
  62   62  
  63   63          /*
  64   64           * XXX nfs4_fid() does nothing and returns EREMOTE.
  65   65           * XXX nfs3_fid()/nfs_fid() returns nfs filehandle as its fid
  66   66           * which has a bigger length than local fid.
  67   67           * NFS_FH4MAXDATA is the size of
  68   68           * fhandle4_t.fh_xdata[NFS_FH4MAXDATA].
  69   69           *
  70   70           * Note: nfs[2,3,4]_fid() only gets called for diskless clients.
  71   71           */
  72   72          if (error == EREMOTE ||
  73   73              (error == 0 && fidp->fid_len > NFS_FH4MAXDATA)) {
  74   74  
  75   75                  va.va_mask = AT_NODEID;
  76   76                  error = VOP_GETATTR(vp, &va, 0, CRED(), NULL);
  77   77                  if (error)
  78   78                          return (error);
  79   79  
  80   80                  fidp->fid_len = sizeof (va.va_nodeid);
  81   81                  bcopy(&va.va_nodeid, fidp->fid_data, fidp->fid_len);
  82   82                  return (0);
  83   83          }
  84   84  
  85   85          return (error);
  86   86  }
  87   87  
  88   88  /*
  89   89   * Get an nfsv4 vnode of the given fid from the visible list of an
  90   90   * nfs filesystem or get the exi_vp if it is the root node.
  91   91   */
  92   92  int
  93   93  nfs4_vget_pseudo(struct exportinfo *exi, vnode_t **vpp, fid_t *fidp)
  94   94  {
  95   95          fid_t exp_fid;
  96   96          struct exp_visible *visp;
  97   97          int error;
  98   98  
  99   99          /* check if the given fid is in the visible list */
 100  100  
 101  101          for (visp = exi->exi_visible; visp; visp = visp->vis_next) {
 102  102                  if (EQFID(fidp, &visp->vis_fid)) {
 103  103                          VN_HOLD(visp->vis_vp);
 104  104                          *vpp = visp->vis_vp;
 105  105                          return (0);
 106  106                  }
 107  107          }
 108  108  
 109  109          /* check if the given fid is the same as the exported node */
 110  110  
 111  111          bzero(&exp_fid, sizeof (exp_fid));
 112  112          exp_fid.fid_len = MAXFIDSZ;
 113  113          error = vop_fid_pseudo(exi->exi_vp, &exp_fid);
 114  114          if (error)
 115  115                  return (error);
 116  116  
 117  117          if (EQFID(fidp, &exp_fid)) {
 118  118                  VN_HOLD(exi->exi_vp);
 119  119                  *vpp = exi->exi_vp;
 120  120                  return (0);
 121  121          }
 122  122  
 123  123          return (ENOENT);
 124  124  }
 125  125  
 126  126  /*
 127  127   * Create a pseudo export entry
 128  128   *
 129  129   * This is an export entry that's created as the
 130  130   * side-effect of a "real" export.  As a part of
 131  131   * a real export, the pathname to the export is
 132  132   * checked to see if all the directory components
 133  133   * are accessible via an NFSv4 client, i.e. are
 134  134   * exported.  If treeclimb_export() finds an unexported
  
    | 
      ↓ open down ↓ | 
    134 lines elided | 
    
      ↑ open up ↑ | 
  
 135  135   * mountpoint along the path, then it calls this
 136  136   * function to export it.
 137  137   *
 138  138   * This pseudo export differs from a real export in that
 139  139   * it only allows read-only access.  A "visible" list of
 140  140   * directories is added to filter lookup and readdir results
 141  141   * to only contain dirnames which lead to descendant shares.
 142  142   *
 143  143   * A visible list has a per-file-system scope.  Any exportinfo
 144  144   * struct (real or pseudo) can have a visible list as long as
 145      - * a) its export root is VROOT
      145 + * a) its export root is VROOT, or is the zone's root for in-zone NFS service
 146  146   * b) a descendant of the export root is shared
 147  147   */
 148  148  struct exportinfo *
 149      -pseudo_exportfs(nfs_export_t *ne, vnode_t *vp, fid_t *fid, struct exp_visible *vis_head,
 150      -    struct exportdata *exdata)
      149 +pseudo_exportfs(nfs_export_t *ne, vnode_t *vp, fid_t *fid,
      150 +    struct exp_visible *vis_head, struct exportdata *exdata)
 151  151  {
 152  152          struct exportinfo *exi;
 153  153          struct exportdata *kex;
 154  154          fsid_t fsid;
 155  155          int vpathlen;
 156  156          int i;
 157  157  
 158  158          ASSERT(RW_WRITE_HELD(&ne->exported_lock));
 159  159  
 160  160          fsid = vp->v_vfsp->vfs_fsid;
 161  161          exi = kmem_zalloc(sizeof (*exi), KM_SLEEP);
 162  162          exi->exi_fsid = fsid;
 163  163          exi->exi_fid = *fid;
 164  164          exi->exi_vp = vp;
 165  165          VN_HOLD(exi->exi_vp);
 166  166          exi->exi_visible = vis_head;
 167  167          exi->exi_count = 1;
      168 +        exi->exi_zoneid = ne->ne_globals->nfs_zoneid;
 168  169          exi->exi_volatile_dev = (vfssw[vp->v_vfsp->vfs_fstype].vsw_flag &
 169  170              VSW_VOLATILEDEV) ? 1 : 0;
 170  171          mutex_init(&exi->exi_lock, NULL, MUTEX_DEFAULT, NULL);
 171      -        exi->exi_zoneid = ne->ne_globals->nfs_zoneid;
 172  172  
 173  173          /*
 174  174           * Build up the template fhandle
 175  175           */
 176  176          exi->exi_fh.fh_fsid = fsid;
 177  177          ASSERT(exi->exi_fid.fid_len <= sizeof (exi->exi_fh.fh_xdata));
 178  178          exi->exi_fh.fh_xlen = exi->exi_fid.fid_len;
 179  179          bcopy(exi->exi_fid.fid_data, exi->exi_fh.fh_xdata,
 180  180              exi->exi_fid.fid_len);
 181  181          exi->exi_fh.fh_len = sizeof (exi->exi_fh.fh_data);
 182  182  
 183  183          kex = &exi->exi_export;
 184  184          kex->ex_flags = EX_PSEUDO;
 185  185  
 186  186          vpathlen = strlen(vp->v_path);
 187  187          kex->ex_pathlen = vpathlen + strlen(PSEUDOFS_SUFFIX);
 188  188          kex->ex_path = kmem_alloc(kex->ex_pathlen + 1, KM_SLEEP);
 189  189  
 190  190          if (vpathlen)
 191  191                  (void) strncpy(kex->ex_path, vp->v_path, vpathlen);
 192  192          (void) strcpy(kex->ex_path + vpathlen, PSEUDOFS_SUFFIX);
 193  193  
 194  194          /* Transfer the secinfo data from exdata to this new pseudo node */
 195  195          if (exdata)
 196  196                  srv_secinfo_exp2pseu(&exi->exi_export, exdata);
 197  197  
 198  198          /*
 199  199           * Initialize auth cache and auth cache lock
 200  200           */
 201  201          for (i = 0; i < AUTH_TABLESIZE; i++) {
 202  202                  exi->exi_cache[i] = kmem_alloc(sizeof (avl_tree_t), KM_SLEEP);
 203  203                  avl_create(exi->exi_cache[i], nfsauth_cache_clnt_compar,
 204  204                      sizeof (struct auth_cache_clnt),
 205  205                      offsetof(struct auth_cache_clnt, authc_link));
 206  206          }
 207  207          rw_init(&exi->exi_cache_lock, NULL, RW_DEFAULT, NULL);
 208  208  
 209  209          /*
 210  210           * Insert the new entry at the front of the export list
 211  211           */
 212  212          export_link(ne, exi);
 213  213  
 214  214          /*
 215  215           * Initialize exi_id and exi_kstats
 216  216           */
 217  217          mutex_enter(&nfs_exi_id_lock);
 218  218          exi->exi_id = exi_id_get_next();
 219  219          avl_add(&exi_id_tree, exi);
 220  220          mutex_exit(&nfs_exi_id_lock);
 221  221  
 222  222          return (exi);
 223  223  }
 224  224  
 225  225  /*
 226  226   * Free a list of visible directories
 227  227   */
 228  228  void
 229  229  free_visible(struct exp_visible *head)
 230  230  {
 231  231          struct exp_visible *visp, *next;
 232  232  
 233  233          for (visp = head; visp; visp = next) {
 234  234                  if (visp->vis_vp != NULL)
 235  235                          VN_RELE(visp->vis_vp);
 236  236  
 237  237                  next = visp->vis_next;
 238  238                  srv_secinfo_list_free(visp->vis_secinfo, visp->vis_seccnt);
 239  239                  kmem_free(visp, sizeof (*visp));
 240  240          }
 241  241  }
 242  242  
 243  243  /*
 244  244   * Connects newchild (or subtree with newchild in head)
 245  245   * to the parent node. We always add it to the beginning
 246  246   * of sibling list.
 247  247   */
 248  248  static void
 249  249  tree_add_child(treenode_t *parent, treenode_t *newchild)
 250  250  {
 251  251          newchild->tree_parent = parent;
 252  252          newchild->tree_sibling = parent->tree_child_first;
 253  253          parent->tree_child_first = newchild;
 254  254  }
 255  255  
 256  256  /* Look up among direct children a node with the exact tree_vis pointer */
 257  257  static treenode_t *
 258  258  tree_find_child_by_vis(treenode_t *t, exp_visible_t *vis)
 259  259  {
 260  260          for (t = t->tree_child_first; t; t = t->tree_sibling)
 261  261                  if (t->tree_vis == vis)
 262  262                          return (t);
 263  263          return (NULL);
 264  264  }
 265  265  
 266  266  /*
 267  267   * Add new node to the head of subtree pointed by 'n'. n can be NULL.
 268  268   * Interconnects the new treenode with exp_visible and exportinfo
 269  269   * if needed.
 270  270   */
 271  271  static treenode_t *
 272  272  tree_prepend_node(treenode_t *n, exp_visible_t *v, exportinfo_t *e)
 273  273  {
 274  274          treenode_t *tnode = kmem_zalloc(sizeof (*tnode), KM_SLEEP);
 275  275  
 276  276          if (n) {
 277  277                  tnode->tree_child_first = n;
 278  278                  n->tree_parent = tnode;
 279  279          }
 280  280          if (v) {
 281  281                  tnode->tree_vis = v;
 282  282          }
 283  283          if (e) {
 284  284                  tnode->tree_exi = e;
 285  285                  e->exi_tree = tnode;
 286  286          }
 287  287          return (tnode);
 288  288  }
 289  289  
 290  290  /*
 291  291   * Removes node from the tree and frees the treenode struct.
 292  292   * Does not free structures pointed by tree_exi and tree_vis,
 293  293   * they should be already freed.
 294  294   */
 295  295  static void
 296  296  tree_remove_node(nfs_export_t *ne, treenode_t *node)
 297  297  {
 298  298          treenode_t *parent = node->tree_parent;
 299  299          treenode_t *s; /* s for sibling */
 300  300  
 301  301          if (parent == NULL) {
 302  302                  kmem_free(node, sizeof (*node));
 303  303                  ne->ns_root = NULL;
 304  304                  return;
 305  305          }
 306  306          /* This node is first child */
 307  307          if (parent->tree_child_first == node) {
 308  308                  parent->tree_child_first = node->tree_sibling;
 309  309          /* This node is not first child */
 310  310          } else {
 311  311                  s = parent->tree_child_first;
 312  312                  while (s->tree_sibling != node)
 313  313                          s = s->tree_sibling;
 314  314                  s->tree_sibling = s->tree_sibling->tree_sibling;
 315  315          }
 316  316          kmem_free(node, sizeof (*node));
 317  317  }
 318  318  
 319  319  /*
 320  320   * When we export a new directory we need to add a new
 321  321   * path segment through the pseudofs to reach the new
 322  322   * directory. This new path is reflected in a list of
 323  323   * directories added to the "visible" list.
 324  324   *
 325  325   * Here there are two lists of visible fids: one hanging off the
 326  326   * pseudo exportinfo, and the one we want to add.  It's possible
 327  327   * that the two lists share a common path segment
 328  328   * and have some common directories.  We need to combine
 329  329   * the lists so there's no duplicate entries. Where a common
 330  330   * path component is found, the vis_count field is bumped.
 331  331   *
 332  332   * This example shows that the treenode chain (tree_head) and
 333  333   * exp_visible chain (vis_head) can differ in length. The latter
 334  334   * can be shorter. The outer loop must loop over the vis_head chain.
 335  335   *
 336  336   * share /x/a
 337  337   * mount -F ufs /dev/dsk/... /x/y
 338  338   * mkdir -p /x/y/a/b
 339  339   * share  /x/y/a/b
 340  340   *
 341  341   * When more_visible() is called during the second share,
 342  342   * the existing namespace is following:
 343  343   *                                   exp_visible_t
 344  344   *   treenode_t       exportinfo_t      v0     v1
 345  345   * ns_root+---+        +------------+  +---+  +---+
 346  346   *      t0| / |........| E0 pseudo  |->| x |->| a |
 347  347   *        +---+        +------------+  +---+  +---+
 348  348   *          |                           /    /
 349  349   *        +---+                        /    /
 350  350   *      t1| x |------------------------    /
 351  351   *        +---+                           /
 352  352   *          |                            /
 353  353   *        +---+                         /
 354  354   *      t2| a |-------------------------
 355  355   *        +---+........+------------+
 356  356   *                     | E1 real    |
 357  357   *                     +------------+
 358  358   *
 359  359   * This is being added:
 360  360   *
 361  361   *    tree_head  vis_head
 362  362   *        +---+  +---+
 363  363   *      t3| x |->| x |v2
 364  364   *        +---+  +---+
 365  365   *          |      |
 366  366   *        +---+  +---+                     v4     v5
 367  367   *      t4| y |->| y |v3  +------------+  +---+  +---+
 368  368   *        +---+\ +---+    | E2 pseudo  |->| a |->| b |
 369  369   *          |   \....... >+------------+  +---+  +---+
 370  370   *        +---+                           /      /
 371  371   *      t5| a |---------------------------      /
 372  372   *        +---+                                /
 373  373   *          |                                 /
 374  374   *        +---+-------------------------------
 375  375   *      t6| b |           +------------+
 376  376   *        +---+..........>| E3 real    |
 377  377   *                        +------------+
 378  378   *
 379  379   * more_visible() will:
 380  380   * - kmem_free() t3 and v2
 381  381   * - add t4, t5, t6 as a child of t1 (t4 will become sibling of t2)
 382  382   * - add v3 to the end of E0->exi_visible
 383  383   *
 384  384   * Note that v4 and v5 were already processed in pseudo_exportfs() and
 385  385   * added to E2. The outer loop of more_visible() will loop only over v2
 386  386   * and v3. The inner loop of more_visible() always loops over v0 and v1.
 387  387   *
 388  388   * Illustration for this scenario:
 389  389   *
 390  390   * mkdir -p /v/a/b/c
 391  391   * share /v/a/b/c
 392  392   * mkdir /v/a/b/c1
 393  393   * mkdir -p /v/a1
 394  394   * mv /v/a/b /v/a1
 395  395   * share /v/a1/b/c1
 396  396   *
 397  397   *           EXISTING
 398  398   *           treenode
 399  399   *           namespace:    +-----------+   visibles
 400  400   *                         |exportinfo |-->v->a->b->c
 401  401   * connect_point->+---+--->+-----------+
 402  402   *                | / |T0
 403  403   *                +---+
 404  404   *                  |                            NEW treenode chain:
 405  405   *         child->+---+
 406  406   *                | v |T1                          +---+<-curr
 407  407   *                +---+                          N1| v |
 408  408   *                  |                              +---+
 409  409   *                +---+                              |
 410  410   *                | a |T2                          +---+<-tree_head
 411  411   *                +---+                          N2| a1|
 412  412   *                  |                              +---+
 413  413   *                +---+                              |
 414  414   *                | b |T3                          +---+
 415  415   *                +---+                          N3| b |
 416  416   *                  |                              +---+
 417  417   *                +---+                              |
 418  418   *                | c |T4                          +---+
 419  419   *                +---+                          N4| c1|
 420  420   *                                                 +---+
 421  421   *
 422  422   * The picture above illustrates the position of following pointers after line
 423  423   * 'child = tree_find_child_by_vis(connect_point, curr->tree_vis);'
 424  424   * was executed for the first time in the outer 'for' loop:
 425  425   *
 426  426   * connect_point..parent treenode in the EXISTING namespace to which the 'curr'
 427  427   *                should be connected. If 'connect_point' already has a child
 428  428   *                with the same value of tree_vis as the curr->tree_vis is,
 429  429   *                the 'curr' will not be added, but kmem_free()d.
 430  430   * child..........the result of tree_find_child_by_vis()
 431  431   * curr...........currently processed treenode from the NEW treenode chain
 432  432   * tree_head......current head of the NEW treenode chain, in this case it was
 433  433   *                already moved down to its child - preparation for another loop
 434  434   *
 435  435   * What will happen to NEW treenodes N1, N2, N3, N4 in more_visible() later:
 436  436   *
 437  437   * N1: is merged - i.e. N1 is kmem_free()d. T0 has a child T1 with the same
 438  438   *     tree_vis as N1
 439  439   * N2: is added as a new child of T1
 440  440   *     Note: not just N2, but the whole chain N2->N3->N4 is added
 441  441   * N3: not processed separately (it was added together with N2)
 442  442   *     Even that N3 and T3 have same tree_vis, they are NOT merged, but will
 443  443   *     become duplicates.
 444  444   * N4: not processed separately
 445  445   */
 446  446  static void
 447  447  more_visible(struct exportinfo *exi, treenode_t *tree_head)
 448  448  {
 449  449          struct exp_visible *vp1, *vp2, *vis_head, *tail, *next;
 450  450          int found;
 451  451          treenode_t *child, *curr, *connect_point;
 452  452          nfs_export_t *ne = nfs_get_export();
 453  453  
 454  454          vis_head = tree_head->tree_vis;
 455  455          connect_point = exi->exi_tree;
 456  456  
 457  457          /*
 458  458           * If exportinfo doesn't already have a visible
 459  459           * list just assign the entire supplied list.
 460  460           */
 461  461          if (exi->exi_visible == NULL) {
 462  462                  tree_add_child(connect_point, tree_head);
 463  463                  exi->exi_visible = vis_head;
 464  464  
 465  465                  /* Update the change timestamp */
 466  466                  tree_update_change(ne, connect_point, &vis_head->vis_change);
 467  467  
 468  468                  return;
 469  469          }
 470  470  
 471  471          /* The outer loop traverses the supplied list. */
 472  472          for (vp1 = vis_head; vp1; vp1 = next) {
 473  473                  found = 0;
 474  474                  next = vp1->vis_next;
 475  475  
 476  476                  /* The inner loop searches the exportinfo visible list. */
 477  477                  for (vp2 = exi->exi_visible; vp2; vp2 = vp2->vis_next) {
 478  478                          tail = vp2;
 479  479                          if (EQFID(&vp1->vis_fid, &vp2->vis_fid)) {
 480  480                                  found = 1;
 481  481                                  vp2->vis_count++;
 482  482                                  VN_RELE(vp1->vis_vp);
 483  483                                  /* Transfer vis_exported from vp1 to vp2. */
 484  484                                  if (vp1->vis_exported && !vp2->vis_exported)
 485  485                                          vp2->vis_exported = 1;
 486  486                                  kmem_free(vp1, sizeof (*vp1));
 487  487                                  tree_head->tree_vis = vp2;
 488  488                                  break;
 489  489                          }
 490  490                  }
 491  491  
 492  492                  /* If not found - add to the end of the list */
 493  493                  if (! found) {
 494  494                          tail->vis_next = vp1;
 495  495                          vp1->vis_next = NULL;
 496  496                  }
 497  497  
 498  498                  curr = tree_head;
 499  499                  tree_head = tree_head->tree_child_first;
 500  500  
 501  501                  if (! connect_point) /* No longer merging */
 502  502                          continue;
 503  503                  /*
 504  504                   * The inner loop could set curr->tree_vis to the EXISTING
 505  505                   * exp_visible vp2, so we can search among the children of
 506  506                   * connect_point for the curr->tree_vis. No need for EQFID.
 507  507                   */
 508  508                  child = tree_find_child_by_vis(connect_point, curr->tree_vis);
 509  509  
 510  510                  /*
 511  511                   * Merging cannot be done if a valid child->tree_exi would
 512  512                   * be overwritten by a new curr->tree_exi.
 513  513                   */
 514  514                  if (child &&
 515  515                      (child->tree_exi == NULL || curr->tree_exi == NULL)) {
 516  516                          if (curr->tree_exi) { /* Transfer the exportinfo */
 517  517                                  child->tree_exi = curr->tree_exi;
 518  518                                  child->tree_exi->exi_tree = child;
 519  519                          }
 520  520                          kmem_free(curr, sizeof (treenode_t));
 521  521                          connect_point = child;
 522  522                  } else { /* Branching */
 523  523                          tree_add_child(connect_point, curr);
 524  524  
 525  525                          /* Update the change timestamp */
 526  526                          tree_update_change(ne, connect_point,
 527  527                              &curr->tree_vis->vis_change);
 528  528  
 529  529                          connect_point = NULL;
 530  530                  }
 531  531          }
 532  532  }
 533  533  
 534  534  /*
 535  535   * Remove one visible entry from the pseudo exportfs.
 536  536   *
 537  537   * When we unexport a directory, we have to remove path
 538  538   * components from the visible list in the pseudo exportfs
 539  539   * entry. The supplied visible contains one fid of one path
 540  540   * component. The visible list of the export
 541  541   * is checked against provided visible, matching fid has its
 542  542   * reference count decremented.  If a reference count drops to
 543  543   * zero, then it means no paths now use this directory, so its
 544  544   * fid can be removed from the visible list.
 545  545   *
 546  546   * When the last path is removed, the visible list will be null.
 547  547   */
 548  548  static void
 549  549  less_visible(struct exportinfo *exi, struct exp_visible *vp1)
 550  550  {
 551  551          struct exp_visible *vp2;
 552  552          struct exp_visible *prev, *next;
 553  553  
 554  554          for (vp2 = exi->exi_visible, prev = NULL; vp2; vp2 = next) {
 555  555  
 556  556                  next = vp2->vis_next;
 557  557  
 558  558                  if (vp1 == vp2) {
 559  559                          /*
 560  560                           * Decrement the ref count.
 561  561                           * Remove the entry if it's zero.
 562  562                           */
 563  563                          if (--vp2->vis_count <= 0) {
 564  564                                  if (prev == NULL)
 565  565                                          exi->exi_visible = next;
 566  566                                  else
 567  567                                          prev->vis_next = next;
 568  568                                  VN_RELE(vp2->vis_vp);
 569  569                                  srv_secinfo_list_free(vp2->vis_secinfo,
 570  570                                      vp2->vis_seccnt);
 571  571                                  kmem_free(vp2, sizeof (*vp1));
 572  572                          }
 573  573                          break;
 574  574                  }
 575  575                  prev = vp2;
 576  576          }
 577  577  }
 578  578  
 579  579  /*
 580  580   * This function checks the path to a new export to
 581  581   * check whether all the pathname components are
 582  582   * exported. It works by climbing the file tree one
 583  583   * component at a time via "..", crossing mountpoints
 584  584   * if necessary until an export entry is found, or the
 585  585   * system root is reached.
 586  586   *
 587  587   * If an unexported mountpoint is found, then
 588  588   * a new pseudo export is added and the pathname from
 589  589   * the mountpoint down to the export is added to the
 590  590   * visible list for the new pseudo export.  If an existing
 591  591   * pseudo export is found, then the pathname is added
 592  592   * to its visible list.
 593  593   *
 594  594   * Note that there's some tests for exportdir.
 595  595   * The exportinfo entry that's passed as a parameter
 596  596   * is that of the real export and exportdir is set
 597  597   * for this case.
 598  598   *
 599  599   * Here is an example of a possible setup:
 600  600   *
 601  601   * () - a new fs; fs mount point
 602  602   * EXPORT - a real exported node
 603  603   * PSEUDO - a pseudo node
 604  604   * vis - visible list
 605  605   * f# - security flavor#
 606  606   * (f#) - security flavor# propagated from its descendents
 607  607   * "" - covered vnode
 608  608   *
 609  609   *
 610  610   *                 /
 611  611   *                 |
 612  612   *                 (a) PSEUDO (f1,f2)
 613  613   *                 |   vis: b,b,"c","n"
 614  614   *                 |
 615  615   *                 b
 616  616   *        ---------|------------------
 617  617   *        |                          |
 618  618   *        (c) EXPORT,f1(f2)          (n) PSEUDO (f1,f2)
 619  619   *        |   vis: "e","d"           |   vis: m,m,,p,q,"o"
 620  620   *        |                          |
 621  621   *  ------------------          -------------------
 622  622   *  |        |        |         |                  |
 623  623   *  (d)      (e)      f         m EXPORT,f1(f2)    p
 624  624   *  EXPORT   EXPORT             |                  |
 625  625   *  f1       f2                 |                  |
 626  626   *           |                  |                  |
 627  627   *           j                 (o) EXPORT,f2       q EXPORT f2
 628  628   *
 629  629   */
 630  630  int
 631  631  treeclimb_export(struct exportinfo *exip)
 632  632  {
  
    | 
      ↓ open down ↓ | 
    451 lines elided | 
    
      ↑ open up ↑ | 
  
 633  633          vnode_t *dvp, *vp;
 634  634          fid_t fid;
 635  635          int error;
 636  636          int exportdir;
 637  637          struct exportinfo *new_exi = exip;
 638  638          struct exp_visible *visp;
 639  639          struct exp_visible *vis_head = NULL;
 640  640          struct vattr va;
 641  641          treenode_t *tree_head = NULL;
 642  642          timespec_t now;
 643      -        nfs_export_t *ne = nfs_get_export();
      643 +        nfs_export_t *ne;
 644  644  
      645 +        ne = exip->exi_ne;
      646 +        ASSERT3P(ne, ==, nfs_get_export());     /* curzone reality check */
 645  647          ASSERT(RW_WRITE_HELD(&ne->exported_lock));
 646  648  
 647  649          gethrestime(&now);
 648  650  
 649  651          vp = exip->exi_vp;
 650  652          VN_HOLD(vp);
 651  653          exportdir = 1;
 652  654  
 653  655          for (;;) {
 654  656  
 655  657                  bzero(&fid, sizeof (fid));
 656  658                  fid.fid_len = MAXFIDSZ;
 657  659                  error = vop_fid_pseudo(vp, &fid);
 658  660                  if (error)
 659  661                          break;
 660  662  
      663 +                /* XXX KEBE ASKS DO WE NEED THIS?!? */
      664 +                ASSERT3U(exip->exi_zoneid, ==, curzone->zone_id);
 661  665                  /*
 662      -                 * The root of the file system needs special handling
      666 +                 * The root of the file system, or the zone's root for
      667 +                 * in-zone NFS service needs special handling
 663  668                   */
 664      -                if (vp->v_flag & VROOT) {
 665      -                        if (! exportdir) {
      669 +                if (vp->v_flag & VROOT || vp == EXI_TO_ZONEROOTVP(exip)) {
      670 +                        if (!exportdir) {
 666  671                                  struct exportinfo *exi;
 667  672  
 668  673                                  /*
 669  674                                   * Check if this VROOT dir is already exported.
 670  675                                   * If so, then attach the pseudonodes.  If not,
 671  676                                   * then continue .. traversal until we hit a
 672  677                                   * VROOT export (pseudo or real).
 673  678                                   */
 674  679                                  exi = checkexport4(&vp->v_vfsp->vfs_fsid, &fid,
 675  680                                      vp);
 676  681                                  if (exi != NULL) {
 677  682                                          /*
 678  683                                           * Found an export info
 679  684                                           *
 680  685                                           * Extend the list of visible
 681  686                                           * directories whether it's a pseudo
 682  687                                           * or a real export.
 683  688                                           */
 684  689                                          more_visible(exi, tree_head);
 685  690                                          break;  /* and climb no further */
 686  691                                  }
 687  692  
 688  693                                  /*
  
    | 
      ↓ open down ↓ | 
    13 lines elided | 
    
      ↑ open up ↑ | 
  
 689  694                                   * Found the root directory of a filesystem
 690  695                                   * that isn't exported.  Need to export
 691  696                                   * this as a pseudo export so that an NFS v4
 692  697                                   * client can do lookups in it.
 693  698                                   */
 694  699                                  new_exi = pseudo_exportfs(ne, vp, &fid,
 695  700                                      vis_head, NULL);
 696  701                                  vis_head = NULL;
 697  702                          }
 698  703  
 699      -                        if (VN_CMP(vp, ZONE_ROOTVP())) {
      704 +                        if (VN_IS_CURZONEROOT(vp)) {
 700  705                                  /* at system root */
 701  706                                  /*
 702  707                                   * If sharing "/", new_exi is shared exportinfo
 703  708                                   * (exip). Otherwise, new_exi is exportinfo
 704  709                                   * created by pseudo_exportfs() above.
 705  710                                   */
 706  711                                  ne->ns_root = tree_prepend_node(tree_head, NULL,
 707  712                                      new_exi);
 708  713  
 709  714                                  /* Update the change timestamp */
 710  715                                  tree_update_change(ne, ne->ns_root, &now);
 711  716  
 712  717                                  break;
 713  718                          }
 714  719  
 715  720                          /*
 716  721                           * Traverse across the mountpoint and continue the
 717  722                           * climb on the mounted-on filesystem.
 718  723                           */
 719  724                          vp = untraverse(vp);
 720  725                          exportdir = 0;
 721  726                          continue;
 722  727                  }
 723  728  
 724  729                  /*
 725  730                   * Do a getattr to obtain the nodeid (inode num)
 726  731                   * for this vnode.
 727  732                   */
 728  733                  va.va_mask = AT_NODEID;
 729  734                  error = VOP_GETATTR(vp, &va, 0, CRED(), NULL);
 730  735                  if (error)
 731  736                          break;
 732  737  
 733  738                  /*
 734  739                   *  Add this directory fid to visible list
 735  740                   */
 736  741                  visp = kmem_alloc(sizeof (*visp), KM_SLEEP);
 737  742                  VN_HOLD(vp);
 738  743                  visp->vis_vp = vp;
 739  744                  visp->vis_fid = fid;            /* structure copy */
 740  745                  visp->vis_ino = va.va_nodeid;
 741  746                  visp->vis_count = 1;
 742  747                  visp->vis_exported = exportdir;
 743  748                  visp->vis_secinfo = NULL;
 744  749                  visp->vis_seccnt = 0;
 745  750                  visp->vis_change = now;         /* structure copy */
 746  751                  visp->vis_next = vis_head;
 747  752                  vis_head = visp;
 748  753  
 749  754                  /*
 750  755                   * Will set treenode's pointer to exportinfo to
 751  756                   * 1. shared exportinfo (exip) - if first visit here
 752  757                   * 2. freshly allocated pseudo export (if any)
 753  758                   * 3. null otherwise
 754  759                   */
 755  760                  tree_head = tree_prepend_node(tree_head, visp, new_exi);
 756  761                  new_exi = NULL;
 757  762  
 758  763                  /*
 759  764                   * Now, do a ".." to find parent dir of vp.
 760  765                   */
 761  766                  error = VOP_LOOKUP(vp, "..", &dvp, NULL, 0, NULL, CRED(),
 762  767                      NULL, NULL, NULL);
 763  768  
 764  769                  if (error == ENOTDIR && exportdir) {
 765  770                          dvp = exip->exi_dvp;
 766  771                          ASSERT(dvp != NULL);
 767  772                          VN_HOLD(dvp);
 768  773                          error = 0;
 769  774                  }
 770  775  
 771  776                  if (error)
 772  777                          break;
 773  778  
 774  779                  exportdir = 0;
 775  780                  VN_RELE(vp);
 776  781                  vp = dvp;
 777  782          }
 778  783  
 779  784          VN_RELE(vp);
 780  785  
 781  786          /*
 782  787           * We can have set error due to error in:
 783  788           * 1. vop_fid_pseudo()
 784  789           * 2. VOP_GETATTR()
 785  790           * 3. VOP_LOOKUP()
 786  791           * We must free pseudo exportinfos, visibles and treenodes.
 787  792           * Visibles are referenced from treenode_t::tree_vis and
 788  793           * exportinfo_t::exi_visible. To avoid double freeing, only
 789  794           * exi_visible pointer is used, via exi_rele(), for the clean-up.
 790  795           */
 791  796          if (error) {
 792  797                  /* Free unconnected visibles, if there are any. */
 793  798                  if (vis_head)
 794  799                          free_visible(vis_head);
 795  800  
 796  801                  /* Connect unconnected exportinfo, if there is any. */
 797  802                  if (new_exi && new_exi != exip)
 798  803                          tree_head = tree_prepend_node(tree_head, NULL, new_exi);
 799  804  
 800  805                  while (tree_head) {
 801  806                          treenode_t *t2 = tree_head;
 802  807                          exportinfo_t *e  = tree_head->tree_exi;
 803  808                          /* exip will be freed in exportfs() */
 804  809                          if (e && e != exip) {
 805  810                                  mutex_enter(&nfs_exi_id_lock);
 806  811                                  avl_remove(&exi_id_tree, e);
 807  812                                  mutex_exit(&nfs_exi_id_lock);
 808  813                                  export_unlink(ne, e);
 809  814                                  exi_rele(e);
 810  815                          }
 811  816                          tree_head = tree_head->tree_child_first;
 812  817                          kmem_free(t2, sizeof (*t2));
 813  818                  }
 814  819          }
 815  820  
 816  821          return (error);
 817  822  }
 818  823  
  
    | 
      ↓ open down ↓ | 
    109 lines elided | 
    
      ↑ open up ↑ | 
  
 819  824  /*
 820  825   * Walk up the tree and:
 821  826   * 1. release pseudo exportinfo if it has no child
 822  827   * 2. release visible in parent's exportinfo
 823  828   * 3. delete non-exported leaf nodes from tree
 824  829   *
 825  830   * Deleting of nodes will start only if the unshared
 826  831   * node was a leaf node.
 827  832   * Deleting of nodes will finish when we reach a node which
 828  833   * has children or is a real export, then we might still need
 829      - * to continue releasing visibles, until we reach VROOT node.
      834 + * to continue releasing visibles, until we reach VROOT or zone's root node.
 830  835   */
 831  836  void
 832  837  treeclimb_unexport(nfs_export_t *ne, struct exportinfo *exip)
 833  838  {
 834  839          treenode_t *tnode, *old_nd;
 835  840          treenode_t *connect_point = NULL;
 836  841  
 837  842          ASSERT(RW_WRITE_HELD(&ne->exported_lock));
      843 +        ASSERT(curzone->zone_id == exip->exi_zoneid ||
      844 +            curzone->zone_id == global_zone->zone_id);
 838  845  
 839  846          /*
 840  847           * exi_tree can be null for the zone root
 841  848           * which means we're already at the "top"
 842  849           * and there's nothing more to "climb".
 843  850           */
 844  851          tnode = exip->exi_tree;
 845  852          if (tnode == NULL) {
 846  853                  /* Should only happen for... */
 847  854                  ASSERT(exip == ne->exi_root);
 848  855                  return;
 849  856          }
 850  857  
 851  858          /*
  
    | 
      ↓ open down ↓ | 
    4 lines elided | 
    
      ↑ open up ↑ | 
  
 852  859           * The unshared exportinfo was unlinked in unexport().
 853  860           * Zeroing tree_exi ensures that we will skip it.
 854  861           */
 855  862          tnode->tree_exi = NULL;
 856  863  
 857  864          if (tnode->tree_vis != NULL) /* system root has tree_vis == NULL */
 858  865                  tnode->tree_vis->vis_exported = 0;
 859  866  
 860  867          while (tnode != NULL) {
 861  868  
 862      -                /* Stop at VROOT node which is exported or has child */
      869 +                /*
      870 +                 * Stop at VROOT (or zone root) node which is exported or has
      871 +                 * child.
      872 +                 */
 863  873                  if (TREE_ROOT(tnode) &&
 864  874                      (TREE_EXPORTED(tnode) || tnode->tree_child_first != NULL))
 865  875                          break;
 866  876  
 867  877                  /* Release pseudo export if it has no child */
 868  878                  if (TREE_ROOT(tnode) && !TREE_EXPORTED(tnode) &&
 869  879                      tnode->tree_child_first == NULL) {
 870  880                          mutex_enter(&nfs_exi_id_lock);
 871  881                          avl_remove(&exi_id_tree, tnode->tree_exi);
 872  882                          mutex_exit(&nfs_exi_id_lock);
 873  883                          export_unlink(ne, tnode->tree_exi);
 874  884                          exi_rele(tnode->tree_exi);
      885 +                        tnode->tree_exi = NULL;
 875  886                  }
 876  887  
 877  888                  /* Release visible in parent's exportinfo */
 878  889                  if (tnode->tree_vis != NULL)
 879  890                          less_visible(vis2exi(tnode), tnode->tree_vis);
 880  891  
 881  892                  /* Continue with parent */
 882  893                  old_nd = tnode;
 883  894                  tnode = tnode->tree_parent;
 884  895  
 885  896                  /* Remove itself, if this is a leaf and non-exported node */
 886  897                  if (old_nd->tree_child_first == NULL &&
 887  898                      !TREE_EXPORTED(old_nd)) {
 888  899                          tree_remove_node(ne, old_nd);
 889  900                          connect_point = tnode;
 890  901                  }
 891  902          }
  
    | 
      ↓ open down ↓ | 
    7 lines elided | 
    
      ↑ open up ↑ | 
  
 892  903  
 893  904          /* Update the change timestamp */
 894  905          if (connect_point != NULL)
 895  906                  tree_update_change(ne, connect_point, NULL);
 896  907  }
 897  908  
 898  909  /*
 899  910   * Traverse backward across mountpoint from the
 900  911   * root vnode of a filesystem to its mounted-on
 901  912   * vnode.
      913 + *
      914 + * Callers to this function have confirmed the use of curzone is safe here.
 902  915   */
 903  916  vnode_t *
 904  917  untraverse(vnode_t *vp)
 905  918  {
 906  919          vnode_t *tvp, *nextvp;
 907  920  
 908  921          tvp = vp;
 909  922          for (;;) {
 910      -                if (! (tvp->v_flag & VROOT))
      923 +                if (!(tvp->v_flag & VROOT) && !VN_IS_CURZONEROOT(tvp))
 911  924                          break;
 912  925  
 913  926                  /* lock vfs to prevent unmount of this vfs */
 914  927                  vfs_lock_wait(tvp->v_vfsp);
 915  928  
 916  929                  if ((nextvp = tvp->v_vfsp->vfs_vnodecovered) == NULL) {
 917  930                          vfs_unlock(tvp->v_vfsp);
 918  931                          break;
 919  932                  }
 920  933  
 921  934                  /*
 922  935                   * Hold nextvp to prevent unmount.  After unlock vfs and
 923  936                   * rele tvp, any number of overlays could be unmounted.
 924  937                   * Putting a hold on vfs_vnodecovered will only allow
 925  938                   * tvp's vfs to be unmounted. Of course if caller placed
 926  939                   * extra hold on vp before calling untraverse, the following
 927  940                   * hold would not be needed.  Since prev actions of caller
 928  941                   * are unknown, we need to hold here just to be safe.
 929  942                   */
 930  943                  VN_HOLD(nextvp);
  
    | 
      ↓ open down ↓ | 
    10 lines elided | 
    
      ↑ open up ↑ | 
  
 931  944                  vfs_unlock(tvp->v_vfsp);
 932  945                  VN_RELE(tvp);
 933  946                  tvp = nextvp;
 934  947          }
 935  948  
 936  949          return (tvp);
 937  950  }
 938  951  
 939  952  /*
 940  953   * Given an exportinfo, climb up to find the exportinfo for the VROOT
 941      - * of the filesystem.
      954 + * (or zone root) of the filesystem.
 942  955   *
 943  956   * e.g.         /
 944  957   *              |
 945  958   *              a (VROOT) pseudo-exportinfo
 946  959   *              |
 947  960   *              b
 948  961   *              |
 949  962   *              c  #share /a/b/c
 950  963   *              |
 951  964   *              d
 952  965   *
 953  966   * where c is in the same filesystem as a.
 954  967   * So, get_root_export(*exportinfo_for_c) returns exportinfo_for_a
 955  968   *
 956  969   * If d is shared, then c will be put into a's visible list.
 957  970   * Note: visible list is per filesystem and is attached to the
 958      - * VROOT exportinfo.
      971 + * VROOT exportinfo.  Returned exi does NOT have a new hold.
 959  972   */
 960  973  struct exportinfo *
 961  974  get_root_export(struct exportinfo *exip)
 962  975  {
 963  976          treenode_t *tnode = exip->exi_tree;
 964  977          exportinfo_t *exi = NULL;
 965  978  
 966  979          while (tnode) {
 967  980                  if (TREE_ROOT(tnode)) {
 968  981                          exi = tnode->tree_exi;
 969  982                          break;
 970  983                  }
 971  984                  tnode = tnode->tree_parent;
 972  985          }
 973  986          ASSERT(exi);
 974  987          return (exi);
 975  988  }
 976  989  
 977  990  /*
 978  991   * Return true if the supplied vnode has a sub-directory exported.
 979  992   */
  
    | 
      ↓ open down ↓ | 
    11 lines elided | 
    
      ↑ open up ↑ | 
  
 980  993  int
 981  994  has_visible(struct exportinfo *exi, vnode_t *vp)
 982  995  {
 983  996          struct exp_visible *visp;
 984  997          fid_t fid;
 985  998          bool_t vp_is_exported;
 986  999  
 987 1000          vp_is_exported = VN_CMP(vp, exi->exi_vp);
 988 1001  
 989 1002          /*
 990      -         * An exported root vnode has a sub-dir shared if it has a visible list.
 991      -         * i.e. if it does not have a visible list, then there is no node in
 992      -         * this filesystem leads to any other shared node.
     1003 +         * An exported root vnode has a sub-dir shared if it has a visible
     1004 +         * list.  i.e. if it does not have a visible list, then there is no
     1005 +         * node in this filesystem leads to any other shared node.
 993 1006           */
 994      -        if (vp_is_exported && (vp->v_flag & VROOT))
     1007 +        ASSERT3P(curzone->zone_id, ==, exi->exi_zoneid);
     1008 +        if (vp_is_exported &&
     1009 +            ((vp->v_flag & VROOT) || VN_IS_CURZONEROOT(vp))) {
 995 1010                  return (exi->exi_visible ? 1 : 0);
     1011 +        }
 996 1012  
 997 1013          /*
 998 1014           * Only the exportinfo of a fs root node may have a visible list.
 999 1015           * Either it is a pseudo root node, or a real exported root node.
1000 1016           */
1001 1017          exi = get_root_export(exi);
1002 1018  
1003 1019          if (!exi->exi_visible)
1004 1020                  return (0);
1005 1021  
1006 1022          /* Get the fid of the vnode */
1007 1023          bzero(&fid, sizeof (fid));
1008 1024          fid.fid_len = MAXFIDSZ;
1009 1025          if (vop_fid_pseudo(vp, &fid) != 0) {
1010 1026                  return (0);
1011 1027          }
1012 1028  
1013 1029          /*
1014 1030           * See if vp is in the visible list of the root node exportinfo.
1015 1031           */
1016 1032          for (visp = exi->exi_visible; visp; visp = visp->vis_next) {
1017 1033                  if (EQFID(&fid, &visp->vis_fid)) {
1018 1034                          /*
1019 1035                           * If vp is an exported non-root node with only 1 path
1020 1036                           * count (for itself), it indicates no sub-dir shared
1021 1037                           * using this vp as a path.
1022 1038                           */
1023 1039                          if (vp_is_exported && visp->vis_count < 2)
1024 1040                                  break;
1025 1041  
1026 1042                          return (1);
1027 1043                  }
1028 1044          }
1029 1045  
1030 1046          return (0);
1031 1047  }
1032 1048  
1033 1049  /*
1034 1050   * Returns true if the supplied vnode is visible
1035 1051   * in this export.  If vnode is visible, return
1036 1052   * vis_exported in expseudo.
1037 1053   */
1038 1054  int
1039 1055  nfs_visible(struct exportinfo *exi, vnode_t *vp, int *expseudo)
1040 1056  {
1041 1057          struct exp_visible *visp;
1042 1058          fid_t fid;
1043 1059  
1044 1060          /*
1045 1061           * First check to see if vp is export root.
1046 1062           *
1047 1063           * A pseudo export root can never be exported
1048 1064           * (it would be a real export then); however,
1049 1065           * it is always visible.  If a pseudo root object
1050 1066           * was exported by server admin, then the entire
1051 1067           * pseudo exportinfo (and all visible entries) would
1052 1068           * be destroyed.  A pseudo exportinfo only exists
1053 1069           * to provide access to real (descendant) export(s).
1054 1070           *
1055 1071           * Previously, rootdir was special cased here; however,
1056 1072           * the export root special case handles the rootdir
1057 1073           * case also.
  
    | 
      ↓ open down ↓ | 
    52 lines elided | 
    
      ↑ open up ↑ | 
  
1058 1074           */
1059 1075          if (VN_CMP(vp, exi->exi_vp)) {
1060 1076                  *expseudo = 0;
1061 1077                  return (1);
1062 1078          }
1063 1079  
1064 1080          /*
1065 1081           * Only a PSEUDO node has a visible list or an exported VROOT
1066 1082           * node may have a visible list.
1067 1083           */
1068      -        if (! PSEUDO(exi))
     1084 +        if (!PSEUDO(exi))
1069 1085                  exi = get_root_export(exi);
1070 1086  
1071 1087          /* Get the fid of the vnode */
1072 1088  
1073 1089          bzero(&fid, sizeof (fid));
1074 1090          fid.fid_len = MAXFIDSZ;
1075 1091          if (vop_fid_pseudo(vp, &fid) != 0) {
1076 1092                  *expseudo = 0;
1077 1093                  return (0);
1078 1094          }
1079 1095  
1080 1096          /*
1081 1097           * We can't trust VN_CMP() above because of LOFS.
1082 1098           * Even though VOP_CMP will do the right thing for LOFS
1083 1099           * objects, VN_CMP will short circuit out early when the
1084 1100           * vnode ops ptrs are different.  Just in case we're dealing
1085 1101           * with LOFS, compare exi_fid/fsid here.
1086 1102           *
1087 1103           * expseudo is not set because this is not an export
1088 1104           */
1089 1105          if (EQFID(&exi->exi_fid, &fid) &&
1090 1106              EQFSID(&exi->exi_fsid, &vp->v_vfsp->vfs_fsid)) {
1091 1107                  *expseudo = 0;
1092 1108                  return (1);
1093 1109          }
1094 1110  
1095 1111  
1096 1112          /* See if it matches any fid in the visible list */
1097 1113  
1098 1114          for (visp = exi->exi_visible; visp; visp = visp->vis_next) {
1099 1115                  if (EQFID(&fid, &visp->vis_fid)) {
1100 1116                          *expseudo = visp->vis_exported;
1101 1117                          return (1);
1102 1118                  }
1103 1119          }
1104 1120  
1105 1121          *expseudo = 0;
1106 1122  
1107 1123          return (0);
1108 1124  }
1109 1125  
1110 1126  /*
1111 1127   * Returns true if the supplied vnode is the
1112 1128   * directory of an export point.
1113 1129   */
1114 1130  int
1115 1131  nfs_exported(struct exportinfo *exi, vnode_t *vp)
1116 1132  {
1117 1133          struct exp_visible *visp;
1118 1134          fid_t fid;
1119 1135  
1120 1136          /*
1121 1137           * First check to see if vp is the export root
1122 1138           * This check required for the case of lookup ..
1123 1139           * where .. is a V_ROOT vnode and a pseudo exportroot.
1124 1140           * Pseudo export root objects do not have an entry
1125 1141           * in the visible list even though every V_ROOT
1126 1142           * pseudonode is visible.  It is safe to compare
1127 1143           * vp here because pseudo_exportfs put a hold on
1128 1144           * it when exi_vp was initialized.
1129 1145           *
1130 1146           * Note: VN_CMP() won't match for LOFS shares, but they're
1131 1147           * handled below w/EQFID/EQFSID.
1132 1148           */
1133 1149          if (VN_CMP(vp, exi->exi_vp))
1134 1150                  return (1);
1135 1151  
1136 1152          /* Get the fid of the vnode */
1137 1153  
1138 1154          bzero(&fid, sizeof (fid));
1139 1155          fid.fid_len = MAXFIDSZ;
1140 1156          if (vop_fid_pseudo(vp, &fid) != 0)
1141 1157                  return (0);
1142 1158  
1143 1159          if (EQFID(&fid, &exi->exi_fid) &&
1144 1160              EQFSID(&vp->v_vfsp->vfs_fsid, &exi->exi_fsid)) {
1145 1161                  return (1);
1146 1162          }
1147 1163  
1148 1164          /* See if it matches any fid in the visible list */
1149 1165  
1150 1166          for (visp = exi->exi_visible; visp; visp = visp->vis_next) {
1151 1167                  if (EQFID(&fid, &visp->vis_fid))
1152 1168                          return (visp->vis_exported);
1153 1169          }
1154 1170  
1155 1171          return (0);
1156 1172  }
1157 1173  
1158 1174  /*
1159 1175   * Returns true if the supplied inode is visible
1160 1176   * in this export.  This function is used by
1161 1177   * readdir which uses inode numbers from the
1162 1178   * directory.
1163 1179   *
1164 1180   * NOTE: this code does not match inode number for ".",
1165 1181   * but it isn't required because NFS4 server rddir
  
    | 
      ↓ open down ↓ | 
    87 lines elided | 
    
      ↑ open up ↑ | 
  
1166 1182   * skips . and .. entries.
1167 1183   */
1168 1184  int
1169 1185  nfs_visible_inode(struct exportinfo *exi, ino64_t ino,
1170 1186      struct exp_visible **visp)
1171 1187  {
1172 1188          /*
1173 1189           * Only a PSEUDO node has a visible list or an exported VROOT
1174 1190           * node may have a visible list.
1175 1191           */
1176      -        if (! PSEUDO(exi))
     1192 +        if (!PSEUDO(exi))
1177 1193                  exi = get_root_export(exi);
1178 1194  
1179 1195          for (*visp = exi->exi_visible; *visp != NULL; *visp = (*visp)->vis_next)
1180 1196                  if ((u_longlong_t)ino == (*visp)->vis_ino) {
1181 1197                          return (1);
1182 1198                  }
1183 1199  
1184 1200          return (0);
1185 1201  }
1186 1202  
1187 1203  /*
1188 1204   * Get the change attribute from visible and returns TRUE.
1189 1205   * If the change value is not available returns FALSE.
1190 1206   */
1191 1207  bool_t
1192 1208  nfs_visible_change(struct exportinfo *exi, vnode_t *vp, timespec_t *change)
1193 1209  {
1194 1210          struct exp_visible *visp;
1195 1211          fid_t fid;
1196 1212          treenode_t *node;
1197 1213          nfs_export_t *ne = nfs_get_export();
1198 1214  
1199 1215          /*
1200 1216           * First check to see if vp is export root.
1201 1217           */
1202 1218          if (VN_CMP(vp, exi->exi_vp))
1203 1219                  goto exproot;
1204 1220  
1205 1221          /*
1206 1222           * Only a PSEUDO node has a visible list or an exported VROOT
1207 1223           * node may have a visible list.
1208 1224           */
1209 1225          if (!PSEUDO(exi))
1210 1226                  exi = get_root_export(exi);
1211 1227  
1212 1228          /* Get the fid of the vnode */
1213 1229          bzero(&fid, sizeof (fid));
1214 1230          fid.fid_len = MAXFIDSZ;
1215 1231          if (vop_fid_pseudo(vp, &fid) != 0)
1216 1232                  return (FALSE);
1217 1233  
1218 1234          /*
1219 1235           * We can't trust VN_CMP() above because of LOFS.
1220 1236           * Even though VOP_CMP will do the right thing for LOFS
1221 1237           * objects, VN_CMP will short circuit out early when the
1222 1238           * vnode ops ptrs are different.  Just in case we're dealing
1223 1239           * with LOFS, compare exi_fid/fsid here.
1224 1240           */
1225 1241          if (EQFID(&exi->exi_fid, &fid) &&
1226 1242              EQFSID(&exi->exi_fsid, &vp->v_vfsp->vfs_fsid))
1227 1243                  goto exproot;
1228 1244  
1229 1245          /* See if it matches any fid in the visible list */
1230 1246          for (visp = exi->exi_visible; visp; visp = visp->vis_next) {
1231 1247                  if (EQFID(&fid, &visp->vis_fid)) {
1232 1248                          *change = visp->vis_change;
1233 1249                          return (TRUE);
1234 1250                  }
1235 1251          }
1236 1252  
1237 1253          return (FALSE);
1238 1254  
1239 1255  exproot:
1240 1256          /* The VROOT export have its visible available through treenode */
1241 1257          node = exi->exi_tree;
1242 1258          if (node != ne->ns_root) {
1243 1259                  ASSERT(node->tree_vis != NULL);
1244 1260                  *change = node->tree_vis->vis_change;
1245 1261          } else {
1246 1262                  ASSERT(node->tree_vis == NULL);
1247 1263                  *change = ne->ns_root_change;
1248 1264          }
1249 1265          return (TRUE);
1250 1266  }
1251 1267  
1252 1268  /*
1253 1269   * Update the change attribute value for a particular treenode.  The change
1254 1270   * attribute value is stored in the visible attached to the treenode, or in the
1255 1271   * ns_root_change.
1256 1272   *
1257 1273   * If the change value is not supplied, the current time is used.
1258 1274   */
1259 1275  void
1260 1276  tree_update_change(nfs_export_t *ne, treenode_t *tnode, timespec_t *change)
1261 1277  {
1262 1278          timespec_t *vis_change;
1263 1279  
1264 1280          ASSERT(tnode != NULL);
1265 1281          ASSERT((tnode != ne->ns_root && tnode->tree_vis != NULL) ||
1266 1282              (tnode == ne->ns_root && tnode->tree_vis == NULL));
1267 1283  
1268 1284          vis_change = tnode == ne->ns_root ? &ne->ns_root_change
1269 1285              : &tnode->tree_vis->vis_change;
1270 1286  
1271 1287          if (change != NULL)
1272 1288                  *vis_change = *change;
1273 1289          else
1274 1290                  gethrestime(vis_change);
1275 1291  }
  
    | 
      ↓ open down ↓ | 
    89 lines elided | 
    
      ↑ open up ↑ | 
  
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX