主要数据结
ocfs2_stack_plugin
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,必须实例化一个该结构体。
2. ocfs2_stack_operations
/* * 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 代码无关。
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_protocol
/* * 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_lksb
/* * 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;};
二. 函数
ocfs2_cluster_connect
/* 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 argument237 * for the ast and bast functions. They will pass the lksb to the ast238 * and bast. The caller can wrap the lksb with their own structure to239 * 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 else251 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);