Back to home page

OSCL-LXR

 
 

    


0001 /* SPDX-License-Identifier: GPL-2.0 */
0002 /*
0003  * fs/nfs/nfs4session.h
0004  *
0005  * Copyright (c) 2012 Trond Myklebust <Trond.Myklebust@netapp.com>
0006  *
0007  */
0008 #ifndef __LINUX_FS_NFS_NFS4SESSION_H
0009 #define __LINUX_FS_NFS_NFS4SESSION_H
0010 
0011 /* maximum number of slots to use */
0012 #define NFS4_DEF_SLOT_TABLE_SIZE (64U)
0013 #define NFS4_DEF_CB_SLOT_TABLE_SIZE (16U)
0014 #define NFS4_MAX_SLOT_TABLE (1024U)
0015 #define NFS4_MAX_SLOTID (NFS4_MAX_SLOT_TABLE - 1U)
0016 #define NFS4_NO_SLOT ((u32)-1)
0017 
0018 #if IS_ENABLED(CONFIG_NFS_V4)
0019 
0020 /* Sessions slot seqid */
0021 struct nfs4_slot {
0022     struct nfs4_slot_table  *table;
0023     struct nfs4_slot    *next;
0024     unsigned long       generation;
0025     u32         slot_nr;
0026     u32         seq_nr;
0027     u32         seq_nr_last_acked;
0028     u32         seq_nr_highest_sent;
0029     unsigned int        privileged : 1,
0030                 seq_done : 1;
0031 };
0032 
0033 /* Sessions */
0034 enum nfs4_slot_tbl_state {
0035     NFS4_SLOT_TBL_DRAINING,
0036 };
0037 
0038 #define SLOT_TABLE_SZ DIV_ROUND_UP(NFS4_MAX_SLOT_TABLE, BITS_PER_LONG)
0039 struct nfs4_slot_table {
0040     struct nfs4_session *session;       /* Parent session */
0041     struct nfs4_slot *slots;        /* seqid per slot */
0042     unsigned long   used_slots[SLOT_TABLE_SZ]; /* used/unused bitmap */
0043     spinlock_t  slot_tbl_lock;
0044     struct rpc_wait_queue   slot_tbl_waitq; /* allocators may wait here */
0045     wait_queue_head_t   slot_waitq; /* Completion wait on slot */
0046     u32     max_slots;      /* # slots in table */
0047     u32     max_slotid;     /* Max allowed slotid value */
0048     u32     highest_used_slotid;    /* sent to server on each SEQ.
0049                          * op for dynamic resizing */
0050     u32     target_highest_slotid;  /* Server max_slot target */
0051     u32     server_highest_slotid;  /* Server highest slotid */
0052     s32     d_target_highest_slotid; /* Derivative */
0053     s32     d2_target_highest_slotid; /* 2nd derivative */
0054     unsigned long   generation;     /* Generation counter for
0055                            target_highest_slotid */
0056     struct completion complete;
0057     unsigned long   slot_tbl_state;
0058 };
0059 
0060 /*
0061  * Session related parameters
0062  */
0063 struct nfs4_session {
0064     struct nfs4_sessionid       sess_id;
0065     u32             flags;
0066     unsigned long           session_state;
0067     u32             hash_alg;
0068     u32             ssv_len;
0069 
0070     /* The fore and back channel */
0071     struct nfs4_channel_attrs   fc_attrs;
0072     struct nfs4_slot_table      fc_slot_table;
0073     struct nfs4_channel_attrs   bc_attrs;
0074     struct nfs4_slot_table      bc_slot_table;
0075     struct nfs_client       *clp;
0076 };
0077 
0078 enum nfs4_session_state {
0079     NFS4_SESSION_INITING,
0080     NFS4_SESSION_ESTABLISHED,
0081 };
0082 
0083 extern int nfs4_setup_slot_table(struct nfs4_slot_table *tbl,
0084         unsigned int max_reqs, const char *queue);
0085 extern void nfs4_shutdown_slot_table(struct nfs4_slot_table *tbl);
0086 extern struct nfs4_slot *nfs4_alloc_slot(struct nfs4_slot_table *tbl);
0087 extern struct nfs4_slot *nfs4_lookup_slot(struct nfs4_slot_table *tbl, u32 slotid);
0088 extern int nfs4_slot_wait_on_seqid(struct nfs4_slot_table *tbl,
0089         u32 slotid, u32 seq_nr,
0090         unsigned long timeout);
0091 extern bool nfs4_try_to_lock_slot(struct nfs4_slot_table *tbl, struct nfs4_slot *slot);
0092 extern void nfs4_free_slot(struct nfs4_slot_table *tbl, struct nfs4_slot *slot);
0093 extern void nfs4_slot_tbl_drain_complete(struct nfs4_slot_table *tbl);
0094 bool nfs41_wake_and_assign_slot(struct nfs4_slot_table *tbl,
0095         struct nfs4_slot *slot);
0096 void nfs41_wake_slot_table(struct nfs4_slot_table *tbl);
0097 
0098 static inline bool nfs4_slot_tbl_draining(struct nfs4_slot_table *tbl)
0099 {
0100     return !!test_bit(NFS4_SLOT_TBL_DRAINING, &tbl->slot_tbl_state);
0101 }
0102 
0103 static inline bool nfs4_test_locked_slot(const struct nfs4_slot_table *tbl,
0104         u32 slotid)
0105 {
0106     return !!test_bit(slotid, tbl->used_slots);
0107 }
0108 
0109 static inline struct nfs4_session *nfs4_get_session(const struct nfs_client *clp)
0110 {
0111     return clp->cl_session;
0112 }
0113 
0114 #if defined(CONFIG_NFS_V4_1)
0115 extern void nfs41_set_target_slotid(struct nfs4_slot_table *tbl,
0116         u32 target_highest_slotid);
0117 extern void nfs41_update_target_slotid(struct nfs4_slot_table *tbl,
0118         struct nfs4_slot *slot,
0119         struct nfs4_sequence_res *res);
0120 
0121 extern int nfs4_setup_session_slot_tables(struct nfs4_session *ses);
0122 
0123 extern struct nfs4_session *nfs4_alloc_session(struct nfs_client *clp);
0124 extern void nfs4_destroy_session(struct nfs4_session *session);
0125 extern int nfs4_init_session(struct nfs_client *clp);
0126 extern int nfs4_init_ds_session(struct nfs_client *, unsigned long);
0127 
0128 /*
0129  * Determine if sessions are in use.
0130  */
0131 static inline int nfs4_has_session(const struct nfs_client *clp)
0132 {
0133     if (clp->cl_session)
0134         return 1;
0135     return 0;
0136 }
0137 
0138 static inline int nfs4_has_persistent_session(const struct nfs_client *clp)
0139 {
0140     if (nfs4_has_session(clp))
0141         return (clp->cl_session->flags & SESSION4_PERSIST);
0142     return 0;
0143 }
0144 
0145 static inline void nfs4_copy_sessionid(struct nfs4_sessionid *dst,
0146         const struct nfs4_sessionid *src)
0147 {
0148     memcpy(dst->data, src->data, NFS4_MAX_SESSIONID_LEN);
0149 }
0150 
0151 #ifdef CONFIG_CRC32
0152 /*
0153  * nfs_session_id_hash - calculate the crc32 hash for the session id
0154  * @session - pointer to session
0155  */
0156 #define nfs_session_id_hash(sess_id) \
0157     (~crc32_le(0xFFFFFFFF, &(sess_id)->data[0], sizeof((sess_id)->data)))
0158 #else
0159 #define nfs_session_id_hash(session) (0)
0160 #endif
0161 #else /* defined(CONFIG_NFS_V4_1) */
0162 
0163 static inline int nfs4_init_session(struct nfs_client *clp)
0164 {
0165     return 0;
0166 }
0167 
0168 /*
0169  * Determine if sessions are in use.
0170  */
0171 static inline int nfs4_has_session(const struct nfs_client *clp)
0172 {
0173     return 0;
0174 }
0175 
0176 static inline int nfs4_has_persistent_session(const struct nfs_client *clp)
0177 {
0178     return 0;
0179 }
0180 
0181 #define nfs_session_id_hash(session) (0)
0182 
0183 #endif /* defined(CONFIG_NFS_V4_1) */
0184 #endif /* IS_ENABLED(CONFIG_NFS_V4) */
0185 #endif /* __LINUX_FS_NFS_NFS4SESSION_H */