1. Owner
在NFS协议里,Owner是一串数字,它代表着Client端向Sever端说明自己对某种资源的拥有权。一般分为Open Owner,还有Lock Owner。
1.1 Open Owner
Open owner代表对一个打开的文件的所有权。Client端要求Sever打开一个文件,需要提供一个Open Owner。Sever打开后,会在内存里维护一个State对象,对应这个打开的文件。打开后会返回一个数字stateid。以后Client操作这个文件,都提供这个stateid,Server端就能找到对应的State对象。
1.2 Lock Owner
Lock owner代表对一个lock的所有权。Client端要求Sever端lock一个文件,需要提供有一个Lock Owner。Sever端lock后,会在内存里维护一个State对象,对应这个lock的这个范围。lock后会返回一个数字stateid。以后Client取消这个lock,需要提供这个stateid,Server端就能找到对应的State对象。
Linux Kernel Client分配的大小20Byte,
1.3 Owner的表示
Open Owner和Lock Owner,都由state_owner_t
表示,内部通过so_type
区分。
struct state_owner_t {
state_owner_type_t so_type; /*< Owner type */
struct glist_head so_lock_list; /*< Locks for this owner */
#ifdef DEBUG_SAL
struct glist_head so_all_owners; /**< Global list of all state owners */
#endif /* _DEBUG_MEMLEAKS */
pthread_mutex_t so_mutex; /*< Mutex on this owner */
int32_t so_refcount; /*< Reference count for lifecyce management */
int so_owner_len; /*< Length of owner name */
char *so_owner_val; /*< Owner name */
union {
state_nfs4_owner_t so_nfs4_owner; /*< All NFSv4 state owners */
state_nlm_owner_t so_nlm_owner; /*< NLM lock and share
owners */
#ifdef _USE_9P
state_9p_owner_t so_9p_owner; /*< 9P lock owners */
#endif
} so_owner;
};
2. State
State有多种(如下),主要的是open state和lock state。
enum state_type {
STATE_TYPE_NONE = 0,
STATE_TYPE_SHARE = 1,//open state
STATE_TYPE_DELEG = 2,
STATE_TYPE_LOCK = 3,//lock state
STATE_TYPE_LAYOUT = 4,
STATE_TYPE_NLM_LOCK = 5,
STATE_TYPE_NLM_SHARE = 6,
STATE_TYPE_9P_FID = 7,
};
State的表示
union state_data {
struct state_share share;
struct state_nlm_share nlm_share;
struct state_lock lock;
struct state_deleg deleg;
struct state_layout layout;
struct state_9p_fid fid;
uint32_t io_advise;
};
Ganesha中文件的描述
NFS所有操作的实体是由struct fsal_obj_handle
描述的,对于一个文件来说,可以通过struct fsal_obj_handle
,得到struct state_file
。它有一个链表,记录着都有谁打开它,lock它。参见代码_state_add_impl()
struct state_file {
/** File owning state */
struct fsal_obj_handle *obj;
/** NFSv4 states on this file. Protected by state_lock */
struct glist_head list_of_states;
/** Layout recalls on this file. Protected by state_lock */
struct glist_head layoutrecall_list;
/** Pointers for lock list. Protected by state_lock */
struct glist_head lock_list;
/** Pointers for NLM share list. Protected by state_lock */
struct glist_head nlm_share_list;
/** true iff write delegated */
bool write_delegated;
/** Delegation statistics. Protected by state_lock */
struct file_deleg_stats fdeleg_stats;
uint32_t anon_ops; /* number of anonymous operations
* happening at the moment which
* prevents delegations from being
* granted */
};
网友评论