21 
  22 /*
  23  * Copyright (c) 1989, 2010, Oracle and/or its affiliates. All rights reserved.
  24  * Copyright 2016 Nexenta Systems, Inc.  All rights reserved.
  25  * Copyright 2016 Jason King.
  26  * Copyright 2018 Nexenta Systems, Inc.  All rights reserved.
  27  */
  28 
  29 /*      Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T     */
  30 /*        All Rights Reserved   */
  31 
  32 #ifndef _NFS_EXPORT_H
  33 #define _NFS_EXPORT_H
  34 
  35 #include <nfs/nfs_sec.h>
  36 #include <nfs/auth.h>
  37 #include <sys/vnode.h>
  38 #include <nfs/nfs4.h>
  39 #include <sys/kiconv.h>
  40 #include <sys/avl.h>
  41 
  42 #ifdef _KERNEL
  43 #include <sys/pkp_hash.h> /* for PKP_HASH_SIZE */
  44 #endif /* _KERNEL */
  45 
  46 #ifdef  __cplusplus
  47 extern "C" {
  48 #endif
  49 
  50 /*
  51  * nfs pseudo flavor number is owned by IANA. Need to make sure the
  52  * Solaris specific NFS_FLAVOR_NOMAP number will not overlap with any
  53  * new IANA defined pseudo flavor numbers. The chance for the overlap
  54  * is very small since the growth of new flavor numbers is expected
  55  * to be limited.
  56  */
  57 #define NFS_FLAVOR_NOMAP        999999  /* no nfs flavor mapping */
  58 
  59 /*
  60  * As duplicate flavors can be passed into exportfs in the arguments, we
 
 455  * +===+  (VROOT)      +---+                    +---+
 456  *
 457  *
 458  * Bi-directional interconnect:
 459  * treenode_t::tree_exi ---------  exportinfo_t::exi_tree
 460  * One-way direction connection:
 461  * treenode_t::tree_vis .........> exp_visible_t
 462  */
 463 /* Access to treenode_t is under protection of exported_lock RW_LOCK */
 464 typedef struct treenode {
 465         /* support for generic n-ary trees */
 466         struct treenode *tree_parent;
 467         struct treenode *tree_child_first;
 468         struct treenode *tree_sibling; /* next sibling */
 469         /* private, nfs specific part */
 470         struct exportinfo  *tree_exi;
 471         struct exp_visible *tree_vis;
 472 } treenode_t;
 473 
 474 /*
 475  * TREE_ROOT checks if the node corresponds to a filesystem root
 476  * TREE_EXPORTED checks if the node is explicitly shared
 477  */
 478 
 479 #define TREE_ROOT(t) \
 480         ((t)->tree_exi && (t)->tree_exi->exi_vp->v_flag & VROOT)
 481 
 482 #define TREE_EXPORTED(t) \
 483         ((t)->tree_exi && !PSEUDO((t)->tree_exi))
 484 
 485 #define EXPTABLESIZE   256
 486 
 487 struct exp_hash {
 488         struct exportinfo       *prev;  /* ptr to the previous exportinfo */
 489         struct exportinfo       *next;  /* ptr to the next exportinfo */
 490         struct exportinfo       **bckt; /* backpointer to the hash bucket */
 491 };
 492 
 493 /*
 494  * A node associated with an export entry on the
 495  * list of exported filesystems.
 496  *
 497  * exi_count+exi_lock protects an individual exportinfo from being freed
 498  * when in use.
 499  *
 500  * You must have the writer lock on exported_lock to add/delete an exportinfo
 
 502  *
 503  * exi_volatile_dev maps to VSW_VOLATILEDEV.  It means that the
 504  * underlying fs devno can change on each mount.  When set, the server
 505  * should not use va_fsid for a GETATTR(FATTR4_FSID) reply.  It must
 506  * use exi_fsid because it is guaranteed to be persistent.  This isn't
 507  * in any way related to NFS4 volatile filehandles.
 508  *
 509  * The exi_cache_lock protects the exi_cache AVL trees.
 510  */
 511 struct exportinfo {
 512         struct exportdata       exi_export;
 513         fsid_t                  exi_fsid;
 514         struct fid              exi_fid;
 515         struct exp_hash         fid_hash;
 516         struct exp_hash         path_hash;
 517         struct treenode         *exi_tree;
 518         fhandle_t               exi_fh;
 519         krwlock_t               exi_cache_lock;
 520         kmutex_t                exi_lock;
 521         uint_t                  exi_count;
 522         vnode_t                 *exi_vp;
 523         vnode_t                 *exi_dvp;
 524         avl_tree_t              *exi_cache[AUTH_TABLESIZE];
 525         struct log_buffer       *exi_logbuffer;
 526         struct exp_visible      *exi_visible;
 527         struct charset_cache    *exi_charset;
 528         unsigned                exi_volatile_dev:1;
 529         unsigned                exi_moved:1;
 530         int                     exi_id;
 531         avl_node_t              exi_id_link;
 532         zoneid_t                exi_zoneid;
 533 #ifdef VOLATILE_FH_TEST
 534         uint32_t                exi_volatile_id;
 535         struct ex_vol_rename    *exi_vol_rename;
 536         kmutex_t                exi_vol_rename_lock;
 537 #endif /* VOLATILE_FH_TEST -- keep last! */
 538 };
 539 
 540 typedef struct exportinfo exportinfo_t;
 541 typedef struct exportdata exportdata_t;
 542 typedef struct secinfo secinfo_t;
 543 
 544 /*
 545  * exp_visible is a visible list per filesystem. It is for filesystems
 546  * that may need a limited view of its contents. A pseudo export and
 547  * a real export at the mount point (VROOT) which has a subtree shared
 548  * has a visible list.
 549  *
 550  * The exi_visible field is NULL for normal, non-pseudo filesystems
 551  * which do not have any subtree exported. If the field is non-null,
 552  * it points to a list of visible entries, identified by vis_fid and/or
 
 640 extern char    *build_symlink(vnode_t *, cred_t *, size_t *);
 641 
 642 extern fhandle_t nullfh2;       /* for comparing V2 filehandles */
 643 
 644 typedef struct nfs_export {
 645         /* Root of nfs pseudo namespace */
 646         treenode_t *ns_root;
 647 
 648         nfs_globals_t           *ne_globals;    /* "up" pointer */
 649 
 650         struct exportinfo *exptable_path_hash[PKP_HASH_SIZE];
 651         struct exportinfo *exptable[EXPTABLESIZE];
 652 
 653         /*
 654          * Read/Write lock that protects the exportinfo list.  This lock
 655          * must be held when searching or modifiying the exportinfo list.
 656          */
 657         krwlock_t exported_lock;
 658 
 659         /* "public" and default (root) location for public filehandle */
 660         struct exportinfo *exi_public, *exi_root;
 661         /* For checking default public file handle */
 662         fid_t exi_rootfid;
 663         /* For comparing V2 filehandles */
 664         fhandle_t nullfh2;
 665 
 666         /* The change attribute value of the root of nfs pseudo namespace */
 667         timespec_t ns_root_change;
 668 } nfs_export_t;
 669 
 670 /*
 671  * Functions that handle the NFSv4 server namespace
 672  */
 673 extern exportinfo_t *vis2exi(treenode_t *);
 674 extern int      treeclimb_export(struct exportinfo *);
 675 extern void     treeclimb_unexport(nfs_export_t *, struct exportinfo *);
 676 extern int      nfs_visible(struct exportinfo *, vnode_t *, int *);
 677 extern int      nfs_visible_inode(struct exportinfo *, ino64_t,
 678                     struct exp_visible **);
 679 extern int      has_visible(struct exportinfo *, vnode_t *);
 680 extern void     free_visible(struct exp_visible *);
 
 | 
 
 
  21 
  22 /*
  23  * Copyright (c) 1989, 2010, Oracle and/or its affiliates. All rights reserved.
  24  * Copyright 2016 Nexenta Systems, Inc.  All rights reserved.
  25  * Copyright 2016 Jason King.
  26  * Copyright 2018 Nexenta Systems, Inc.  All rights reserved.
  27  */
  28 
  29 /*      Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T     */
  30 /*        All Rights Reserved   */
  31 
  32 #ifndef _NFS_EXPORT_H
  33 #define _NFS_EXPORT_H
  34 
  35 #include <nfs/nfs_sec.h>
  36 #include <nfs/auth.h>
  37 #include <sys/vnode.h>
  38 #include <nfs/nfs4.h>
  39 #include <sys/kiconv.h>
  40 #include <sys/avl.h>
  41 #include <sys/zone.h>
  42 
  43 #ifdef _KERNEL
  44 #include <sys/pkp_hash.h> /* for PKP_HASH_SIZE */
  45 #endif /* _KERNEL */
  46 
  47 #ifdef  __cplusplus
  48 extern "C" {
  49 #endif
  50 
  51 /*
  52  * nfs pseudo flavor number is owned by IANA. Need to make sure the
  53  * Solaris specific NFS_FLAVOR_NOMAP number will not overlap with any
  54  * new IANA defined pseudo flavor numbers. The chance for the overlap
  55  * is very small since the growth of new flavor numbers is expected
  56  * to be limited.
  57  */
  58 #define NFS_FLAVOR_NOMAP        999999  /* no nfs flavor mapping */
  59 
  60 /*
  61  * As duplicate flavors can be passed into exportfs in the arguments, we
 
 456  * +===+  (VROOT)      +---+                    +---+
 457  *
 458  *
 459  * Bi-directional interconnect:
 460  * treenode_t::tree_exi ---------  exportinfo_t::exi_tree
 461  * One-way direction connection:
 462  * treenode_t::tree_vis .........> exp_visible_t
 463  */
 464 /* Access to treenode_t is under protection of exported_lock RW_LOCK */
 465 typedef struct treenode {
 466         /* support for generic n-ary trees */
 467         struct treenode *tree_parent;
 468         struct treenode *tree_child_first;
 469         struct treenode *tree_sibling; /* next sibling */
 470         /* private, nfs specific part */
 471         struct exportinfo  *tree_exi;
 472         struct exp_visible *tree_vis;
 473 } treenode_t;
 474 
 475 /*
 476  * Now that we have links to chase, we can get the zone rootvp just from
 477  * an export.  No current-zone-context needed.
 478  */
 479 #define EXI_TO_ZONEROOTVP(exi) ((exi)->exi_ne->exi_root->exi_vp)
 480 
 481 /*
 482  * TREE_ROOT checks if the node corresponds to a filesystem root or
 483  * the zone's root directory.
 484  * TREE_EXPORTED checks if the node is explicitly shared
 485  */
 486 
 487 #define TREE_ROOT(t) \
 488         ((t)->tree_exi != NULL && \
 489         (((t)->tree_exi->exi_vp->v_flag & VROOT) || \
 490         VN_CMP(EXI_TO_ZONEROOTVP((t)->tree_exi), (t)->tree_exi->exi_vp)))
 491 
 492 #define TREE_EXPORTED(t) \
 493         ((t)->tree_exi && !PSEUDO((t)->tree_exi))
 494 
 495 #define EXPTABLESIZE   256
 496 
 497 struct exp_hash {
 498         struct exportinfo       *prev;  /* ptr to the previous exportinfo */
 499         struct exportinfo       *next;  /* ptr to the next exportinfo */
 500         struct exportinfo       **bckt; /* backpointer to the hash bucket */
 501 };
 502 
 503 /*
 504  * A node associated with an export entry on the
 505  * list of exported filesystems.
 506  *
 507  * exi_count+exi_lock protects an individual exportinfo from being freed
 508  * when in use.
 509  *
 510  * You must have the writer lock on exported_lock to add/delete an exportinfo
 
 512  *
 513  * exi_volatile_dev maps to VSW_VOLATILEDEV.  It means that the
 514  * underlying fs devno can change on each mount.  When set, the server
 515  * should not use va_fsid for a GETATTR(FATTR4_FSID) reply.  It must
 516  * use exi_fsid because it is guaranteed to be persistent.  This isn't
 517  * in any way related to NFS4 volatile filehandles.
 518  *
 519  * The exi_cache_lock protects the exi_cache AVL trees.
 520  */
 521 struct exportinfo {
 522         struct exportdata       exi_export;
 523         fsid_t                  exi_fsid;
 524         struct fid              exi_fid;
 525         struct exp_hash         fid_hash;
 526         struct exp_hash         path_hash;
 527         struct treenode         *exi_tree;
 528         fhandle_t               exi_fh;
 529         krwlock_t               exi_cache_lock;
 530         kmutex_t                exi_lock;
 531         uint_t                  exi_count;
 532         zoneid_t                exi_zoneid;
 533         vnode_t                 *exi_vp;
 534         vnode_t                 *exi_dvp;
 535         avl_tree_t              *exi_cache[AUTH_TABLESIZE];
 536         struct log_buffer       *exi_logbuffer;
 537         struct exp_visible      *exi_visible;
 538         struct charset_cache    *exi_charset;
 539         unsigned                exi_volatile_dev:1;
 540         unsigned                exi_moved:1;
 541         int                     exi_id;
 542         avl_node_t              exi_id_link;
 543         /*
 544          * Soft-reference/backpointer to zone's nfs_export_t.
 545          * This allows us access to the zone's rootvp (stored in
 546          * exi_ne->exi_root->exi_vp) even if the current thread isn't in
 547          * same-zone context.
 548          */
 549         struct nfs_export       *exi_ne;
 550 #ifdef VOLATILE_FH_TEST
 551         uint32_t                exi_volatile_id;
 552         struct ex_vol_rename    *exi_vol_rename;
 553         kmutex_t                exi_vol_rename_lock;
 554 #endif /* VOLATILE_FH_TEST -- keep last! */
 555 };
 556 
 557 typedef struct exportinfo exportinfo_t;
 558 typedef struct exportdata exportdata_t;
 559 typedef struct secinfo secinfo_t;
 560 
 561 /*
 562  * exp_visible is a visible list per filesystem. It is for filesystems
 563  * that may need a limited view of its contents. A pseudo export and
 564  * a real export at the mount point (VROOT) which has a subtree shared
 565  * has a visible list.
 566  *
 567  * The exi_visible field is NULL for normal, non-pseudo filesystems
 568  * which do not have any subtree exported. If the field is non-null,
 569  * it points to a list of visible entries, identified by vis_fid and/or
 
 657 extern char    *build_symlink(vnode_t *, cred_t *, size_t *);
 658 
 659 extern fhandle_t nullfh2;       /* for comparing V2 filehandles */
 660 
 661 typedef struct nfs_export {
 662         /* Root of nfs pseudo namespace */
 663         treenode_t *ns_root;
 664 
 665         nfs_globals_t           *ne_globals;    /* "up" pointer */
 666 
 667         struct exportinfo *exptable_path_hash[PKP_HASH_SIZE];
 668         struct exportinfo *exptable[EXPTABLESIZE];
 669 
 670         /*
 671          * Read/Write lock that protects the exportinfo list.  This lock
 672          * must be held when searching or modifiying the exportinfo list.
 673          */
 674         krwlock_t exported_lock;
 675 
 676         /* "public" and default (root) location for public filehandle */
 677         struct exportinfo *exi_public;
 678         struct exportinfo *exi_root;
 679         /* For checking default public file handle */
 680         fid_t exi_rootfid;
 681         /* For comparing V2 filehandles */
 682         fhandle_t nullfh2;
 683 
 684         /* The change attribute value of the root of nfs pseudo namespace */
 685         timespec_t ns_root_change;
 686 } nfs_export_t;
 687 
 688 /*
 689  * Functions that handle the NFSv4 server namespace
 690  */
 691 extern exportinfo_t *vis2exi(treenode_t *);
 692 extern int      treeclimb_export(struct exportinfo *);
 693 extern void     treeclimb_unexport(nfs_export_t *, struct exportinfo *);
 694 extern int      nfs_visible(struct exportinfo *, vnode_t *, int *);
 695 extern int      nfs_visible_inode(struct exportinfo *, ino64_t,
 696                     struct exp_visible **);
 697 extern int      has_visible(struct exportinfo *, vnode_t *);
 698 extern void     free_visible(struct exp_visible *);
 
 |