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