^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1) /* SPDX-License-Identifier: GPL-2.0 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3) * fs/nfs/nfs4session.h
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5) * Copyright (c) 2012 Trond Myklebust <Trond.Myklebust@netapp.com>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8) #ifndef __LINUX_FS_NFS_NFS4SESSION_H
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9) #define __LINUX_FS_NFS_NFS4SESSION_H
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11) /* maximum number of slots to use */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12) #define NFS4_DEF_SLOT_TABLE_SIZE (64U)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13) #define NFS4_DEF_CB_SLOT_TABLE_SIZE (16U)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14) #define NFS4_MAX_SLOT_TABLE (1024U)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15) #define NFS4_NO_SLOT ((u32)-1)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17) #if IS_ENABLED(CONFIG_NFS_V4)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19) /* Sessions slot seqid */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20) struct nfs4_slot {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21) struct nfs4_slot_table *table;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 22) struct nfs4_slot *next;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 23) unsigned long generation;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 24) u32 slot_nr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 25) u32 seq_nr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 26) u32 seq_nr_last_acked;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 27) u32 seq_nr_highest_sent;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 28) unsigned int privileged : 1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 29) seq_done : 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 30) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 31)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 32) /* Sessions */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 33) enum nfs4_slot_tbl_state {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 34) NFS4_SLOT_TBL_DRAINING,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 35) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 36)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 37) #define SLOT_TABLE_SZ DIV_ROUND_UP(NFS4_MAX_SLOT_TABLE, 8*sizeof(long))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 38) struct nfs4_slot_table {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 39) struct nfs4_session *session; /* Parent session */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 40) struct nfs4_slot *slots; /* seqid per slot */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 41) unsigned long used_slots[SLOT_TABLE_SZ]; /* used/unused bitmap */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 42) spinlock_t slot_tbl_lock;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 43) struct rpc_wait_queue slot_tbl_waitq; /* allocators may wait here */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 44) wait_queue_head_t slot_waitq; /* Completion wait on slot */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 45) u32 max_slots; /* # slots in table */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 46) u32 max_slotid; /* Max allowed slotid value */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 47) u32 highest_used_slotid; /* sent to server on each SEQ.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 48) * op for dynamic resizing */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 49) u32 target_highest_slotid; /* Server max_slot target */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 50) u32 server_highest_slotid; /* Server highest slotid */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 51) s32 d_target_highest_slotid; /* Derivative */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 52) s32 d2_target_highest_slotid; /* 2nd derivative */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 53) unsigned long generation; /* Generation counter for
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 54) target_highest_slotid */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 55) struct completion complete;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 56) unsigned long slot_tbl_state;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 57) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 58)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 59) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 60) * Session related parameters
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 61) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 62) struct nfs4_session {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 63) struct nfs4_sessionid sess_id;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 64) u32 flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 65) unsigned long session_state;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 66) u32 hash_alg;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 67) u32 ssv_len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 68)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 69) /* The fore and back channel */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 70) struct nfs4_channel_attrs fc_attrs;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 71) struct nfs4_slot_table fc_slot_table;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 72) struct nfs4_channel_attrs bc_attrs;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 73) struct nfs4_slot_table bc_slot_table;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 74) struct nfs_client *clp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 75) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 76)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 77) enum nfs4_session_state {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 78) NFS4_SESSION_INITING,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 79) NFS4_SESSION_ESTABLISHED,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 80) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 81)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 82) extern int nfs4_setup_slot_table(struct nfs4_slot_table *tbl,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 83) unsigned int max_reqs, const char *queue);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 84) extern void nfs4_shutdown_slot_table(struct nfs4_slot_table *tbl);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 85) extern struct nfs4_slot *nfs4_alloc_slot(struct nfs4_slot_table *tbl);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 86) extern struct nfs4_slot *nfs4_lookup_slot(struct nfs4_slot_table *tbl, u32 slotid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 87) extern int nfs4_slot_wait_on_seqid(struct nfs4_slot_table *tbl,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 88) u32 slotid, u32 seq_nr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 89) unsigned long timeout);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 90) extern bool nfs4_try_to_lock_slot(struct nfs4_slot_table *tbl, struct nfs4_slot *slot);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 91) extern void nfs4_free_slot(struct nfs4_slot_table *tbl, struct nfs4_slot *slot);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 92) extern void nfs4_slot_tbl_drain_complete(struct nfs4_slot_table *tbl);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 93) bool nfs41_wake_and_assign_slot(struct nfs4_slot_table *tbl,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 94) struct nfs4_slot *slot);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 95) void nfs41_wake_slot_table(struct nfs4_slot_table *tbl);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 96)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 97) static inline bool nfs4_slot_tbl_draining(struct nfs4_slot_table *tbl)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 98) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 99) return !!test_bit(NFS4_SLOT_TBL_DRAINING, &tbl->slot_tbl_state);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) static inline bool nfs4_test_locked_slot(const struct nfs4_slot_table *tbl,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) u32 slotid)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) return !!test_bit(slotid, tbl->used_slots);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) static inline struct nfs4_session *nfs4_get_session(const struct nfs_client *clp)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) return clp->cl_session;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) #if defined(CONFIG_NFS_V4_1)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) extern void nfs41_set_target_slotid(struct nfs4_slot_table *tbl,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) u32 target_highest_slotid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) extern void nfs41_update_target_slotid(struct nfs4_slot_table *tbl,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) struct nfs4_slot *slot,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) struct nfs4_sequence_res *res);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) extern int nfs4_setup_session_slot_tables(struct nfs4_session *ses);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) extern struct nfs4_session *nfs4_alloc_session(struct nfs_client *clp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) extern void nfs4_destroy_session(struct nfs4_session *session);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) extern int nfs4_init_session(struct nfs_client *clp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) extern int nfs4_init_ds_session(struct nfs_client *, unsigned long);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) * Determine if sessions are in use.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) static inline int nfs4_has_session(const struct nfs_client *clp)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) if (clp->cl_session)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) return 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) static inline int nfs4_has_persistent_session(const struct nfs_client *clp)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) if (nfs4_has_session(clp))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) return (clp->cl_session->flags & SESSION4_PERSIST);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) static inline void nfs4_copy_sessionid(struct nfs4_sessionid *dst,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) const struct nfs4_sessionid *src)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) memcpy(dst->data, src->data, NFS4_MAX_SESSIONID_LEN);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) #ifdef CONFIG_CRC32
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) * nfs_session_id_hash - calculate the crc32 hash for the session id
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153) * @session - pointer to session
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155) #define nfs_session_id_hash(sess_id) \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) (~crc32_le(0xFFFFFFFF, &(sess_id)->data[0], sizeof((sess_id)->data)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157) #else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158) #define nfs_session_id_hash(session) (0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160) #else /* defined(CONFIG_NFS_V4_1) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162) static inline int nfs4_init_session(struct nfs_client *clp)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168) * Determine if sessions are in use.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170) static inline int nfs4_has_session(const struct nfs_client *clp)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175) static inline int nfs4_has_persistent_session(const struct nfs_client *clp)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180) #define nfs_session_id_hash(session) (0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182) #endif /* defined(CONFIG_NFS_V4_1) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183) #endif /* IS_ENABLED(CONFIG_NFS_V4) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184) #endif /* __LINUX_FS_NFS_NFS4SESSION_H */