Motr
M0
|
#include <session.h>
Data Fields | |
uint64_t | s_session_id |
struct m0_rpc_conn * | s_conn |
struct m0_tlink | s_link |
uint32_t | s_hold_cnt |
struct m0_sm | s_sm |
uint64_t | s_magic |
uint64_t | s_xid |
struct m0_tl | s_xid_list |
struct m0_rpc_item_cache | s_reply_cache |
struct m0_rpc_item_cache | s_req_cache |
bool | s_cancelled |
struct m0_tl | s_pending_cache |
Rpc connection can be shared by multiple entities (e.g. users) by creating their own "session" on the connection. A session can be used to maintain authentication information or QoS parameters.
Liveness:
On sender side, allocation and deallocation of m0_rpc_session is entirely managed by user except for SESSION 0. SESSION 0 is allocated and deallocated by rpc-layer internally along with m0_rpc_conn.
On receiver side, m0_rpc_session object will be allocated and deallocated by rpc-layer internally, in response to session create and session terminate requests respectively.
Concurrency:
Users of rpc-layer are never expected to take lock on session. Rpc layer will internally synchronise access to m0_rpc_session.
All access to session are synchronized using session->s_conn->c_rpc_machine->rm_sm_grp.s_lock.
When session is in one of INITIALISED, TERMINATED, FINALISED and FAILED state, user is expected to serialise access to the session object. (It is assumed that session, in one of {INITIALISED, TERMINATED, FAILED, FINALISED} states, does not have concurrent users).
| |m0_rpc_session_init() m0_rpc_session_establish() != 0 V +----------------------INITIALISED | | | | m0_rpc_session_establish() | | | timed-out V +-----------------------ESTABLISHING | create_failed | create successful/n = 0 V | FAILED <------+ | n == 0 | | +-----------------+ | | | | +-----+ | |failed | | | | item add/n++ | | V item add/n++ | V | reply rcvd/n-- | +-------------IDLE--------------->BUSY----+ | | | | fini() | | m0_rpc_session_terminate() | | V | +----------TERMINATING | | | | | | | |session_terminated | V | TERMINATED | | | | fini() | V +----------------------> FINALISED
Typical sequence of execution of APIs on sender side. Error checking is omitted.
Receiver is not expected to call any of these APIs. Receiver side session structures will be set-up while handling fops m0_rpc_fop_[conn|session]_[establish|terminate].
When receiver needs to post reply, it uses m0_rpc_reply_post().
m0_rpc_reply_post() will copy all the session related information from request item to reply item and process reply item.
Note: rpc connection is a two-way communication channel. There are requests and corresponding reply items, on the same connection. Receiver NEED NOT have to establish other separate connection with sender, to be able to send replies.
bool s_cancelled |
Flag to indicate if this session has been cancelled. This flag is set to TRUE at the beginning of m0_rpc_session_cancel() execution. Once this flag is set to TRUE, subsequent m0_rpc_post() against the same session returns -ECANCELED error.
struct m0_rpc_conn* s_conn |
struct m0_tlink s_link |
Link in RPC conn. m0_rpc_conn::c_sessions List descriptor: session
struct m0_tl s_pending_cache |
struct m0_rpc_item_cache s_reply_cache |
struct m0_rpc_item_cache s_req_cache |
uint64_t s_session_id |
identifies a particular session. Unique in all sessions belonging to same m0_rpc_conn
struct m0_sm s_sm |
RPC session state machine
struct m0_tl s_xid_list |
List of all rpc items in the session that have xid and are going to be sent. Items in the list are in osr_xid increasing order.