主要數據結
node
ocfs2_stack_pluginapp
struct ocfs2_stack_plugin { char *sp_name; struct ocfs2_stack_operations *sp_ops; struct module *sp_owner; /* These are managed by the stackglue code. */ struct list_head sp_list; unsigned int sp_count; struct ocfs2_protocol_version sp_max_proto; };
每一個stack plugin,即o2cb或pacemaker,必須實例化一個該結構體。less
2. ocfs2_stack_operationsdom
/* * Each cluster stack implements the stack operations structure. Not used * in the ocfs2 code, the stackglue code translates generic cluster calls * into stack operations. */ struct ocfs2_stack_operations { /* * The fs code calls ocfs2_cluster_connect() to attach a new * filesystem to the cluster stack. The ->connect() op is passed * an ocfs2_cluster_connection with the name and recovery field * filled in. * * The stack must set up any notification mechanisms and create * the filesystem lockspace in the DLM. The lockspace should be * stored on cc_lockspace. Any other information can be stored on * cc_private. * * ->connect() must not return until it is guaranteed that * * - Node down notifications for the filesystem will be received * and passed to conn->cc_recovery_handler(). * - Locking requests for the filesystem will be processed. */ int (*connect)(struct ocfs2_cluster_connection *conn); /* * The fs code calls ocfs2_cluster_disconnect() when a filesystem * no longer needs cluster services. All DLM locks have been * dropped, and recovery notification is being ignored by the * fs code. The stack must disengage from the DLM and discontinue * recovery notification. * * Once ->disconnect() has returned, the connection structure will * be freed. Thus, a stack must not return from ->disconnect() * until it will no longer reference the conn pointer. * * Once this call returns, the stack glue will be dropping this * connection's reference on the module. */ int (*disconnect)(struct ocfs2_cluster_connection *conn); /* * ->this_node() returns the cluster's unique identifier for the * local node. */ int (*this_node)(struct ocfs2_cluster_connection *conn, unsigned int *node); /* * Call the underlying dlm lock function. The ->dlm_lock() * callback should convert the flags and mode as appropriate. * * ast and bast functions are not part of the call because the * stack will likely want to wrap ast and bast calls before passing * them to stack->sp_proto. There is no astarg. The lksb will * be passed back to the ast and bast functions. The caller can * use this to find their object. */ int (*dlm_lock)(struct ocfs2_cluster_connection *conn, int mode, struct ocfs2_dlm_lksb *lksb, u32 flags, void *name, unsigned int namelen); /* * Call the underlying dlm unlock function. The ->dlm_unlock() * function should convert the flags as appropriate. * * The unlock ast is not passed, as the stack will want to wrap * it before calling stack->sp_proto->lp_unlock_ast(). There is * no astarg. The lksb will be passed back to the unlock ast * function. The caller can use this to find their object. */ int (*dlm_unlock)(struct ocfs2_cluster_connection *conn, struct ocfs2_dlm_lksb *lksb, u32 flags); /* * Return the status of the current lock status block. The fs * code should never dereference the union. The ->lock_status() * callback pulls out the stack-specific lksb, converts the status * to a proper errno, and returns it. */ int (*lock_status)(struct ocfs2_dlm_lksb *lksb); /* * Return non-zero if the LVB is valid. */ int (*lvb_valid)(struct ocfs2_dlm_lksb *lksb); /* * Pull the lvb pointer off of the stack-specific lksb. */ void *(*lock_lvb)(struct ocfs2_dlm_lksb *lksb); /* * Cluster-aware posix locks * * This is NULL for stacks which do not support posix locks. */ int (*plock)(struct ocfs2_cluster_connection *conn, u64 ino, struct file *file, int cmd, struct file_lock *fl); /* * This is an optoinal debugging hook. If provided, the * stack can dump debugging information about this lock. */ void (*dump_lksb)(struct ocfs2_dlm_lksb *lksb); };
和ocfs2_stack_plugin同樣,stack plugin必須實例化一個棧操做集。該結構體是對通用操做的抽象,與ocfs2 代碼無關。ide
3. ocfs2_cluster_connection函數
/* * A cluster connection. Mostly opaque to ocfs2, the connection holds * state for the underlying stack. ocfs2 does use cc_version to determine * locking compatibility. */ struct ocfs2_cluster_connection { char cc_name[GROUP_NAME_MAX + 1]; int cc_namelen; char cc_cluster_name[CLUSTER_NAME_MAX + 1]; int cc_cluster_name_len; struct ocfs2_protocol_version cc_version; struct ocfs2_locking_protocol *cc_proto; void (*cc_recovery_handler)(int node_num, void *recovery_data); void *cc_recovery_data; void *cc_lockspace; void *cc_private; };
4. ocfs2_locking_protocolpost
/* * The ocfs2_locking_protocol defines the handlers called on ocfs2's behalf. */ struct ocfs2_locking_protocol { struct ocfs2_protocol_version lp_max_version; void (*lp_lock_ast)(struct ocfs2_dlm_lksb *lksb); void (*lp_blocking_ast)(struct ocfs2_dlm_lksb *lksb, int level); void (*lp_unlock_ast)(struct ocfs2_dlm_lksb *lksb, int error); };
5. ocfs2_dlm_lksbui
/* * A union of all lock status structures. We define it here so that the * size of the union is known. Lock status structures are embedded in * ocfs2 inodes. */ struct ocfs2_cluster_connection; struct ocfs2_dlm_lksb { union { struct dlm_lockstatus lksb_o2dlm; struct dlm_lksb lksb_fsdlm; struct fsdlm_lksb_plus_lvb padding; }; struct ocfs2_cluster_connection *lksb_conn; };
二. 函數this
ocfs2_cluster_connect
spa
/* Used by the filesystem */ int ocfs2_cluster_connect(const char *stack_name, const char *cluster_name, int cluster_name_len, const char *group, int grouplen, struct ocfs2_locking_protocol *lproto, void (*recovery_handler)(int node_num, void *recovery_data), void *recovery_data, struct ocfs2_cluster_connection **conn);
struct ocfs2_super 包含 了struct ocfs2_cluster_connection *cconn。其被初始化的調用流程如:
ocfs2_fill_super --> ocfs2_mount_volume --> ocfs2_dlm_init --> ocfs2_cluster_connect代碼片斷以下。
3009 /* for now, uuid == domain */ 3010 status = ocfs2_cluster_connect(osb->osb_cluster_stack, 3011 osb->osb_cluster_name, 3012 strlen(osb->osb_cluster_name), 3013 osb->uuid_str, 3014 strlen(osb->uuid_str), 3015 &lproto, ocfs2_do_node_down, osb, 3016 &conn);
相似的函數有ocfs2_cluster_connect_agnostic,agnostic翻譯過來是不可知論的,這裏是指調用者未指定cluster stack的名字。
相反的函數天然是ocfs2_cluster_disconnect了。
2. ocfs2_cluster_hangup
/* * Hangup is a required post-umount. ocfs2-tools software expects the * filesystem to call "ocfs2_hb_ctl" during unmount. This happens * regardless of whether the DLM got started, so we can't do it * in ocfs2_cluster_disconnect(). The ocfs2_leave_group() function does * the actual work. */ void ocfs2_cluster_hangup(const char *group, int grouplen) { BUG_ON(group == NULL); BUG_ON(group[grouplen] != '\0'); ocfs2_leave_group(group); /* cluster_disconnect() was called with hangup_pending==1 */ ocfs2_stack_driver_put(); } EXPORT_SYMBOL_GPL(ocfs2_cluster_hangup);
3. ocfs2_cluster_this_node
int ocfs2_cluster_this_node(struct ocfs2_cluster_connection *conn, unsigned int *node) { return active_stack->sp_ops->this_node(conn, node); } EXPORT_SYMBOL_GPL(ocfs2_cluster_this_node);
4. ocfs2_dlm_lock
235 /* 236 * The ocfs2_dlm_lock() and ocfs2_dlm_unlock() functions take no argument 237 * for the ast and bast functions. They will pass the lksb to the ast 238 * and bast. The caller can wrap the lksb with their own structure to 239 * get more information. 240 */ 241 int ocfs2_dlm_lock(struct ocfs2_cluster_connection *conn, 242 int mode, 243 struct ocfs2_dlm_lksb *lksb, 244 u32 flags, 245 void *name, 246 unsigned int namelen) 247 { 248 if (!lksb->lksb_conn) 249 lksb->lksb_conn = conn; 250 else 251 BUG_ON(lksb->lksb_conn != conn); 252 return active_stack->sp_ops->dlm_lock(conn, mode, lksb, flags, 253 name, namelen); 254 } 255 EXPORT_SYMBOL_GPL(ocfs2_dlm_lock);
相似的封裝函數還有:
257 int ocfs2_dlm_unlock(struct ocfs2_cluster_connection *conn, 258 struct ocfs2_dlm_lksb *lksb, 259 u32 flags) 260 { 261 BUG_ON(lksb->lksb_conn == NULL); 262 263 return active_stack->sp_ops->dlm_unlock(conn, lksb, flags); 264 } 265 EXPORT_SYMBOL_GPL(ocfs2_dlm_unlock); 266 267 int ocfs2_dlm_lock_status(struct ocfs2_dlm_lksb *lksb) 268 { 269 return active_stack->sp_ops->lock_status(lksb); 270 } 271 EXPORT_SYMBOL_GPL(ocfs2_dlm_lock_status); 272 273 int ocfs2_dlm_lvb_valid(struct ocfs2_dlm_lksb *lksb) 274 { 275 return active_stack->sp_ops->lvb_valid(lksb); 276 } 277 EXPORT_SYMBOL_GPL(ocfs2_dlm_lvb_valid); 278 279 void *ocfs2_dlm_lvb(struct ocfs2_dlm_lksb *lksb) 280 { 281 return active_stack->sp_ops->lock_lvb(lksb); 282 } 283 EXPORT_SYMBOL_GPL(ocfs2_dlm_lvb); 284 285 void ocfs2_dlm_dump_lksb(struct ocfs2_dlm_lksb *lksb) 286 { 287 active_stack->sp_ops->dump_lksb(lksb); 288 } 289 EXPORT_SYMBOL_GPL(ocfs2_dlm_dump_lksb);