Print this page
11083 support NFS server in zone
Portions contributed by: Dan Kruchinin <dan.kruchinin@nexenta.com>
Portions contributed by: Stepan Zastupov <stepan.zastupov@gmail.com>
Portions contributed by: Joyce McIntosh <joyce.mcintosh@nexenta.com>
Portions contributed by: Mike Zeller <mike@mikezeller.net>
Portions contributed by: Dan McDonald <danmcd@joyent.com>
Portions contributed by: Gordon Ross <gordon.w.ross@gmail.com>
Portions contributed by: Vitaliy Gusev <gusev.vitaliy@gmail.com>
Reviewed by: Rick McNeal <rick.mcneal@nexenta.com>
Reviewed by: Rob Gittins <rob.gittins@nexenta.com>
Reviewed by: Sanjay Nadkarni <sanjay.nadkarni@nexenta.com>
Reviewed by: Jason King <jbk@joyent.com>
Reviewed by: C Fraire <cfraire@me.com>
Change-Id: I22f289d357503f9b48a0bc2482cc4328a6d43d16

Split Close
Expand all
Collapse all
          --- old/usr/src/uts/common/nfs/nfs4.h
          +++ new/usr/src/uts/common/nfs/nfs4.h
↓ open down ↓ 12 lines elided ↑ open up ↑
  13   13   * When distributing Covered Code, include this CDDL HEADER in each
  14   14   * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
  15   15   * If applicable, add the following below this CDDL HEADER, with the
  16   16   * fields enclosed by brackets "[]" replaced with your own identifying
  17   17   * information: Portions Copyright [yyyy] [name of copyright owner]
  18   18   *
  19   19   * CDDL HEADER END
  20   20   */
  21   21  
  22   22  /*
  23      - * Copyright 2015 Nexenta Systems, Inc.  All rights reserved.
       23 + * Copyright 2010 Sun Microsystems, Inc.  All rights reserved.
       24 + * Use is subject to license terms.
  24   25   */
  25   26  
  26   27  /*
  27      - * Copyright 2010 Sun Microsystems, Inc.  All rights reserved.
  28      - * Use is subject to license terms.
       28 + * Copyright 2018 Nexenta Systems, Inc.
       29 + * Copyright 2019 Nexenta by DDN, Inc.
  29   30   */
  30   31  
  31   32  #ifndef _NFS4_H
  32   33  #define _NFS4_H
  33   34  
  34   35  #include <sys/types.h>
  35   36  #include <sys/vnode.h>
  36   37  #include <sys/fem.h>
  37   38  #include <rpc/rpc.h>
  38   39  #include <nfs/nfs.h>
  39   40  
  40   41  #ifdef _KERNEL
  41   42  #include <nfs/nfs4_kprot.h>
       43 +#include <nfs/nfs4_drc.h>
  42   44  #include <sys/nvpair.h>
  43   45  #else
  44   46  #include <rpcsvc/nfs4_prot.h>
  45   47  #endif
  46   48  #include <nfs/nfs4_attr.h>
  47   49  #include <sys/acl.h>
  48   50  #include <sys/list.h>
  49   51  
  50   52  #ifdef  __cplusplus
  51   53  extern "C" {
↓ open down ↓ 60 lines elided ↑ open up ↑
 112  114  
 113  115  typedef struct rfs4_dbe rfs4_dbe_t;             /* basic opaque db entry */
 114  116  typedef struct rfs4_table rfs4_table_t;         /* basic table type */
 115  117  typedef struct rfs4_index rfs4_index_t;         /* index */
 116  118  typedef struct rfs4_database rfs4_database_t;   /* and database */
 117  119  
 118  120  typedef struct {                /* opaque entry type for later use */
 119  121          rfs4_dbe_t *dbe;
 120  122  } *rfs4_entry_t;
 121  123  
 122      -extern rfs4_table_t *rfs4_client_tab;
      124 +/*
      125 + * NFSv4 server state databases
      126 + *
      127 + * Initialized when the module is loaded and used by NFSv4 state tables.
      128 + * These kmem_cache free pools are used globally, the NFSv4 state tables
      129 + * which make use of these kmem_cache free pools are per zone.
      130 + */
      131 +extern kmem_cache_t *rfs4_client_mem_cache;
      132 +extern kmem_cache_t *rfs4_clntIP_mem_cache;
      133 +extern kmem_cache_t *rfs4_openown_mem_cache;
      134 +extern kmem_cache_t *rfs4_openstID_mem_cache;
      135 +extern kmem_cache_t *rfs4_lockstID_mem_cache;
      136 +extern kmem_cache_t *rfs4_lockown_mem_cache;
      137 +extern kmem_cache_t *rfs4_file_mem_cache;
      138 +extern kmem_cache_t *rfs4_delegstID_mem_cache;
 123  139  
 124  140  /* database, table, index creation entry points */
 125  141  extern rfs4_database_t *rfs4_database_create(uint32_t);
 126  142  extern void             rfs4_database_shutdown(rfs4_database_t *);
 127  143  extern void             rfs4_database_destroy(rfs4_database_t *);
 128  144  
 129  145  extern void             rfs4_database_destroy(rfs4_database_t *);
 130  146  
      147 +extern kmem_cache_t     *nfs4_init_mem_cache(char *, uint32_t, uint32_t,
      148 +                                uint32_t);
 131  149  extern rfs4_table_t     *rfs4_table_create(rfs4_database_t *, char *,
 132  150                                  time_t, uint32_t,
 133  151                                  bool_t (*create)(rfs4_entry_t, void *),
 134  152                                  void (*destroy)(rfs4_entry_t),
 135  153                                  bool_t (*expiry)(rfs4_entry_t),
 136  154                                  uint32_t, uint32_t, uint32_t, id_t);
 137  155  extern void             rfs4_table_destroy(rfs4_database_t *, rfs4_table_t *);
 138  156  extern rfs4_index_t     *rfs4_index_create(rfs4_table_t *, char *,
 139  157                                  uint32_t (*hash)(void *),
 140  158                                  bool_t (compare)(rfs4_entry_t, void *),
↓ open down ↓ 221 lines elided ↑ open up ↑
 362  380          struct rfs4_dss_path    *prev; /* for insque/remque */
 363  381          char                    *path;
 364  382          struct rfs4_servinst    *sip;
 365  383          unsigned                index; /* offset in servinst's array */
 366  384  } rfs4_dss_path_t;
 367  385  
 368  386  /* array of paths passed-in from nfsd command-line; stored in nvlist */
 369  387  char            **rfs4_dss_newpaths;
 370  388  uint_t          rfs4_dss_numnewpaths;
 371  389  
 372      -/*
 373      - * Circular doubly-linked list of paths for currently-served RGs.
 374      - * No locking required: only changed on warmstart. Managed with insque/remque.
 375      - */
 376      -rfs4_dss_path_t *rfs4_dss_pathlist;
 377      -
 378  390  /* nvlists of all DSS paths: current, and before last warmstart */
 379  391  nvlist_t *rfs4_dss_paths, *rfs4_dss_oldpaths;
 380  392  
 381  393  /*
 382  394   * The server maintains a set of state on a per client basis that
 383  395   * matches that of the protocol requirements.  A client's state is
 384  396   * rooted with the rfs4_client_t struct of which there is one per
 385  397   * client and is created when SETCLIENTID/SETCLIENTID_CONFIRM are
 386  398   * received.  From there, the server then creates rfs4_openowner_t
 387  399   * structs for each new open owner from that client and are initiated
↓ open down ↓ 345 lines elided ↑ open up ↑
 733  745          rfs4_dinfo_t    rf_dinfo;
 734  746          uint32_t        rf_share_deny;
 735  747          uint32_t        rf_share_access;
 736  748          uint32_t        rf_access_read;
 737  749          uint32_t        rf_access_write;
 738  750          uint32_t        rf_deny_read;
 739  751          uint32_t        rf_deny_write;
 740  752          krwlock_t       rf_file_rwlock;
 741  753  } rfs4_file_t;
 742  754  
 743      -extern int      rfs4_seen_first_compound;       /* set first time we see one */
 744      -
 745      -extern rfs4_servinst_t  *rfs4_cur_servinst;     /* current server instance */
 746      -extern kmutex_t         rfs4_servinst_lock;     /* protects linked list */
 747      -extern void             rfs4_servinst_create(int, int, char **);
 748      -extern void             rfs4_servinst_destroy_all(void);
 749      -extern void             rfs4_servinst_assign(rfs4_client_t *,
 750      -                            rfs4_servinst_t *);
 751      -extern rfs4_servinst_t  *rfs4_servinst(rfs4_client_t *);
 752      -extern int              rfs4_clnt_in_grace(rfs4_client_t *);
 753      -extern int              rfs4_servinst_in_grace(rfs4_servinst_t *);
 754      -extern int              rfs4_servinst_grace_new(rfs4_servinst_t *);
 755      -extern void             rfs4_grace_start(rfs4_servinst_t *);
 756      -extern void             rfs4_grace_start_new(void);
 757      -extern void             rfs4_grace_reset_all(void);
 758      -extern void             rfs4_ss_oldstate(rfs4_oldstate_t *, char *, char *);
 759      -extern void             rfs4_dss_readstate(int, char **);
 760      -
 761  755  /*
 762      - * rfs4_deleg_policy is used to signify the server's global delegation
      756 + * nfs4_deleg_policy is used to signify the server's global delegation
 763  757   * policy.  The default is to NEVER delegate files and the
 764  758   * administrator must configure the server to enable delegations.
 765  759   *
 766  760   * The disable/enable delegation functions are used to eliminate a
 767  761   * race with exclusive creates.
 768  762   */
 769  763  typedef enum {
 770  764          SRV_NEVER_DELEGATE = 0,
 771  765          SRV_NORMAL_DELEGATE = 1
 772  766  } srv_deleg_policy_t;
 773  767  
 774      -extern srv_deleg_policy_t rfs4_deleg_policy;
 775      -extern kmutex_t rfs4_deleg_lock;
 776  768  extern void rfs4_disable_delegation(void), rfs4_enable_delegation(void);
 777  769  
 778  770  /*
 779  771   * Request types for delegation. These correspond with
 780  772   * open_delegation_type4 with the addition of a new value, DELEG_ANY,
 781  773   * to reqequest any delegation.
 782  774   */
 783  775  typedef enum {
 784  776          DELEG_NONE = 0,         /* Corresponds to OPEN_DELEG_NONE */
 785  777          DELEG_READ = 1,         /* Corresponds to OPEN_DELEG_READ */
 786  778          DELEG_WRITE = 2,        /* Corresponds to OPEN_DELEG_WRITE */
 787  779          DELEG_ANY = -1          /* New value to request any delegation type */
 788  780  } delegreq_t;
 789  781  
 790  782  #define NFS4_DELEG4TYPE2REQTYPE(x) (delegreq_t)(x)
 791  783  
 792  784  /*
      785 + * Zone global variables of NFSv4 server
      786 + */
      787 +typedef struct nfs4_srv {
      788 +        /* Unique write verifier */
      789 +        verifier4       write4verf;
      790 +        /* Delegation lock */
      791 +        kmutex_t        deleg_lock;
      792 +        /* Used to serialize create/destroy of nfs4_server_state database */
      793 +        kmutex_t        state_lock;
      794 +        rfs4_database_t *nfs4_server_state;
      795 +        /* Used to manage access to server instance linked list */
      796 +        kmutex_t        servinst_lock;
      797 +        rfs4_servinst_t *nfs4_cur_servinst;
      798 +        /* Used to manage access to nfs4_deleg_policy */
      799 +        krwlock_t       deleg_policy_lock;
      800 +        srv_deleg_policy_t nfs4_deleg_policy;
      801 +        /* Set first time we see one */
      802 +        int             seen_first_compound;
      803 +        /*
      804 +         * Circular double-linked list of paths for currently-served RGs.
      805 +         * No locking required -- only changed on server start.
      806 +         * Managed with insque/remque.
      807 +         */
      808 +        rfs4_dss_path_t *dss_pathlist;
      809 +        /* Duplicate request cache */
      810 +        rfs4_drc_t      *nfs4_drc;
      811 +        /* nfsv4 server start time */
      812 +        time_t rfs4_start_time;
      813 +        /* Used to serialize lookups of clientids */
      814 +        krwlock_t rfs4_findclient_lock;
      815 +
      816 +        /* NFSv4 server state client tables */
      817 +        /* table expiry times */
      818 +        time_t rfs4_client_cache_time;
      819 +        time_t rfs4_openowner_cache_time;
      820 +        time_t rfs4_state_cache_time;
      821 +        time_t rfs4_lo_state_cache_time;
      822 +        time_t rfs4_lockowner_cache_time;
      823 +        time_t rfs4_file_cache_time;
      824 +        time_t rfs4_deleg_state_cache_time;
      825 +        time_t rfs4_clntip_cache_time;
      826 +        /* tables and indexes */
      827 +        /* client table */
      828 +        rfs4_table_t *rfs4_client_tab;
      829 +        rfs4_index_t *rfs4_clientid_idx;
      830 +        rfs4_index_t *rfs4_nfsclnt_idx;
      831 +        /* client IP table */
      832 +        rfs4_table_t *rfs4_clntip_tab;
      833 +        rfs4_index_t *rfs4_clntip_idx;
      834 +        /* Open Owner table */
      835 +        rfs4_table_t *rfs4_openowner_tab;
      836 +        rfs4_index_t *rfs4_openowner_idx;
      837 +        /* Open State ID table */
      838 +        rfs4_table_t *rfs4_state_tab;
      839 +        rfs4_index_t *rfs4_state_idx;
      840 +        rfs4_index_t *rfs4_state_owner_file_idx;
      841 +        rfs4_index_t *rfs4_state_file_idx;
      842 +        /* Lock State ID table */
      843 +        rfs4_table_t *rfs4_lo_state_tab;
      844 +        rfs4_index_t *rfs4_lo_state_idx;
      845 +        rfs4_index_t *rfs4_lo_state_owner_idx;
      846 +        /* Lock owner table */
      847 +        rfs4_table_t *rfs4_lockowner_tab;
      848 +        rfs4_index_t *rfs4_lockowner_idx;
      849 +        rfs4_index_t *rfs4_lockowner_pid_idx;
      850 +        /* File table */
      851 +        rfs4_table_t *rfs4_file_tab;
      852 +        rfs4_index_t *rfs4_file_idx;
      853 +        /* Deleg State table */
      854 +        rfs4_table_t *rfs4_deleg_state_tab;
      855 +        rfs4_index_t *rfs4_deleg_idx;
      856 +        rfs4_index_t *rfs4_deleg_state_idx;
      857 +
      858 +        /* client stable storage */
      859 +        int rfs4_ss_enabled;
      860 +} nfs4_srv_t;
      861 +
      862 +/*
      863 + * max length of the NFSv4 server database name
      864 + */
      865 +#define RFS4_MAX_MEM_CACHE_NAME 48
      866 +
      867 +/*
      868 + * global NFSv4 server kmem caches
      869 + * r_db_name - The name of the state database and the table that will use it
      870 + *             These tables are defined in nfs4_srv_t
      871 + * r_db_mem_cache - The kmem cache associated with the state database name
      872 + */
      873 +typedef struct rfs4_db_mem_cache {
      874 +        char            r_db_name[RFS4_MAX_MEM_CACHE_NAME];
      875 +        kmem_cache_t    *r_db_mem_cache;
      876 +} rfs4_db_mem_cache_t;
      877 +
      878 +#define RFS4_DB_MEM_CACHE_NUM 8
      879 +
      880 +rfs4_db_mem_cache_t rfs4_db_mem_cache_table[RFS4_DB_MEM_CACHE_NUM];
      881 +
      882 +
      883 +extern srv_deleg_policy_t nfs4_get_deleg_policy();
      884 +
      885 +extern void             rfs4_servinst_create(nfs4_srv_t *, int, int, char **);
      886 +extern void             rfs4_servinst_destroy_all(nfs4_srv_t *);
      887 +extern void             rfs4_servinst_assign(nfs4_srv_t *, rfs4_client_t *,
      888 +                            rfs4_servinst_t *);
      889 +extern rfs4_servinst_t  *rfs4_servinst(rfs4_client_t *);
      890 +extern int              rfs4_clnt_in_grace(rfs4_client_t *);
      891 +extern int              rfs4_servinst_in_grace(rfs4_servinst_t *);
      892 +extern int              rfs4_servinst_grace_new(rfs4_servinst_t *);
      893 +extern void             rfs4_grace_start(rfs4_servinst_t *);
      894 +extern void             rfs4_grace_start_new(nfs4_srv_t *);
      895 +extern void             rfs4_grace_reset_all(nfs4_srv_t *);
      896 +extern void             rfs4_ss_oldstate(rfs4_oldstate_t *, char *, char *);
      897 +extern void             rfs4_dss_readstate(nfs4_srv_t *, int, char **);
      898 +
      899 +/*
 793  900   * Various interfaces to manipulate the state structures introduced
 794  901   * above
 795  902   */
 796      -extern  kmutex_t        rfs4_state_lock;
 797      -extern  void            rfs4_clean_state_exi(struct exportinfo *exi);
 798  903  extern  void            rfs4_free_reply(nfs_resop4 *);
 799  904  extern  void            rfs4_copy_reply(nfs_resop4 *, nfs_resop4 *);
 800  905  
 801  906  /* rfs4_client_t handling */
 802  907  extern  rfs4_client_t   *rfs4_findclient(nfs_client_id4 *,
 803  908                                          bool_t *, rfs4_client_t *);
 804  909  extern  rfs4_client_t   *rfs4_findclient_by_id(clientid4, bool_t);
 805  910  extern  rfs4_client_t   *rfs4_findclient_by_addr(struct sockaddr *);
 806  911  extern  void            rfs4_client_rele(rfs4_client_t *);
 807  912  extern  void            rfs4_client_close(rfs4_client_t *);
↓ open down ↓ 131 lines elided ↑ open up ↑
 939 1044                  caller_context_t *);
 940 1045  
 941 1046  extern void rfs4_mon_hold(void *);
 942 1047  extern void rfs4_mon_rele(void *);
 943 1048  
 944 1049  extern fem_t    *deleg_rdops;
 945 1050  extern fem_t    *deleg_wrops;
 946 1051  
 947 1052  extern int rfs4_share(rfs4_state_t *, uint32_t, uint32_t);
 948 1053  extern int rfs4_unshare(rfs4_state_t *);
 949      -extern  void            rfs4_set_deleg_policy(srv_deleg_policy_t);
     1054 +extern void rfs4_set_deleg_policy(nfs4_srv_t *, srv_deleg_policy_t);
     1055 +extern void rfs4_hold_deleg_policy(nfs4_srv_t *);
     1056 +extern void rfs4_rele_deleg_policy(nfs4_srv_t *);
     1057 +
 950 1058  #ifdef DEBUG
 951 1059  #define NFS4_DEBUG(var, args) if (var) cmn_err args
 952 1060  
 953 1061  extern int rfs4_debug;
 954 1062  extern int nfs4_client_attr_debug;
 955 1063  extern int nfs4_client_state_debug;
 956 1064  extern int nfs4_client_shadow_debug;
 957 1065  extern int nfs4_client_lock_debug;
 958 1066  extern int nfs4_client_lease_debug;
 959 1067  extern int nfs4_seqid_sync;
↓ open down ↓ 381 lines elided ↑ open up ↑
1341 1449  extern fs_locations4 *fetch_referral(vnode_t *, cred_t *);
1342 1450  extern char     *build_symlink(vnode_t *, cred_t *, size_t *);
1343 1451  
1344 1452  extern int      stateid4_cmp(stateid4 *, stateid4 *);
1345 1453  
1346 1454  extern vtype_t  nf4_to_vt[];
1347 1455  
1348 1456  extern struct nfs4_ntov_map nfs4_ntov_map[];
1349 1457  extern uint_t nfs4_ntov_map_size;
1350 1458  
1351      -extern kstat_named_t    *rfsproccnt_v4_ptr;
1352 1459  extern struct vfsops    *nfs4_vfsops;
1353 1460  extern struct vnodeops  *nfs4_vnodeops;
1354 1461  extern const struct     fs_operation_def nfs4_vnodeops_template[];
1355 1462  extern vnodeops_t       *nfs4_trigger_vnodeops;
1356 1463  extern const struct     fs_operation_def nfs4_trigger_vnodeops_template[];
1357 1464  
1358 1465  extern uint_t nfs4_tsize(struct knetconfig *);
1359 1466  extern uint_t rfs4_tsize(struct svc_req *);
1360 1467  
1361 1468  extern bool_t   xdr_inline_decode_nfs_fh4(uint32_t *, nfs_fh4_fmt_t *,
↓ open down ↓ 8 lines elided ↑ open up ↑
1370 1477  
1371 1478  extern stateid4 clnt_special0;
1372 1479  extern stateid4 clnt_special1;
1373 1480  #define CLNT_ISSPECIAL(id) (stateid4_cmp(id, &clnt_special0) || \
1374 1481                                  stateid4_cmp(id, &clnt_special1))
1375 1482  
1376 1483  /*
1377 1484   * The NFS Version 4 service procedures.
1378 1485   */
1379 1486  
     1487 +extern void     rfs4_do_server_start(int, int, int);
1380 1488  extern void     rfs4_compound(COMPOUND4args *, COMPOUND4res *,
1381 1489                          struct exportinfo *, struct svc_req *, cred_t *, int *);
1382 1490  extern void     rfs4_compound_free(COMPOUND4res *);
1383 1491  extern void     rfs4_compound_flagproc(COMPOUND4args *, int *);
1384 1492  
1385      -extern int      rfs4_srvrinit(void);
     1493 +extern void     rfs4_srvrinit(void);
1386 1494  extern void     rfs4_srvrfini(void);
1387      -extern void     rfs4_state_init(void);
1388      -extern void     rfs4_state_fini(void);
     1495 +extern void     rfs4_srv_zone_init(nfs_globals_t *);
     1496 +extern void     rfs4_srv_zone_fini(nfs_globals_t *);
     1497 +extern void     rfs4_state_g_init(void);
     1498 +extern void     rfs4_state_zone_init(nfs4_srv_t *);
     1499 +extern void     rfs4_state_g_fini(void);
     1500 +extern void     rfs4_state_zone_fini(void);
     1501 +extern nfs4_srv_t *nfs4_get_srv(void);
1389 1502  
1390 1503  #endif
1391 1504  #ifdef  __cplusplus
1392 1505  }
1393 1506  #endif
1394 1507  
1395 1508  #endif /* _NFS4_H */
    
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX