美文网首页
nfs-ganesha - NFS协议里的一些术语

nfs-ganesha - NFS协议里的一些术语

作者: 帆子_8c3a | 来源:发表于2019-08-19 16:49 被阅读0次

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 */
};

3 Client Owner 和 Client ID

相关文章

网友评论

      本文标题:nfs-ganesha - NFS协议里的一些术语

      本文链接:https://www.haomeiwen.com/subject/qehesctx.html