150acfb2bSThomas Gleixner /* SPDX-License-Identifier: GPL-2.0-only */ 2*fa60ce2cSMasahiro Yamada /* 324ef1815SJoel Becker * stackglue.h 424ef1815SJoel Becker * 524ef1815SJoel Becker * Glue to the underlying cluster stack. 624ef1815SJoel Becker * 724ef1815SJoel Becker * Copyright (C) 2007 Oracle. All rights reserved. 824ef1815SJoel Becker */ 924ef1815SJoel Becker 1024ef1815SJoel Becker 1124ef1815SJoel Becker #ifndef STACKGLUE_H 1224ef1815SJoel Becker #define STACKGLUE_H 1324ef1815SJoel Becker 14bd3e7610SJoel Becker #include <linux/types.h> 15bd3e7610SJoel Becker #include <linux/list.h> 16bd3e7610SJoel Becker #include <linux/dlmconstants.h> 17bd3e7610SJoel Becker 18e3dad42bSJoel Becker #include "dlm/dlmapi.h" 19cf4d8d75SDavid Teigland #include <linux/dlm.h> 20e3dad42bSJoel Becker 2153da4939SMark Fasheh /* Needed for plock-related prototypes */ 2253da4939SMark Fasheh struct file; 2353da4939SMark Fasheh struct file_lock; 2453da4939SMark Fasheh 25bd3e7610SJoel Becker /* 26bd3e7610SJoel Becker * dlmconstants.h does not have a LOCAL flag. We hope to remove it 27bd3e7610SJoel Becker * some day, but right now we need it. Let's fake it. This value is larger 28bd3e7610SJoel Becker * than any flag in dlmconstants.h. 29bd3e7610SJoel Becker */ 30bd3e7610SJoel Becker #define DLM_LKF_LOCAL 0x00100000 31bd3e7610SJoel Becker 324670c46dSJoel Becker /* 334670c46dSJoel Becker * This shadows DLM_LOCKSPACE_LEN in fs/dlm/dlm_internal.h. That probably 344670c46dSJoel Becker * wants to be in a public header. 354670c46dSJoel Becker */ 364670c46dSJoel Becker #define GROUP_NAME_MAX 64 374670c46dSJoel Becker 38c74a3bddSGoldwyn Rodrigues /* This shadows OCFS2_CLUSTER_NAME_LEN */ 39c74a3bddSGoldwyn Rodrigues #define CLUSTER_NAME_MAX 16 40c74a3bddSGoldwyn Rodrigues 414670c46dSJoel Becker 42e3dad42bSJoel Becker /* 43e3dad42bSJoel Becker * ocfs2_protocol_version changes when ocfs2 does something different in 44e3dad42bSJoel Becker * its inter-node behavior. See dlmglue.c for more information. 45e3dad42bSJoel Becker */ 464670c46dSJoel Becker struct ocfs2_protocol_version { 474670c46dSJoel Becker u8 pv_major; 484670c46dSJoel Becker u8 pv_minor; 494670c46dSJoel Becker }; 504670c46dSJoel Becker 51e3dad42bSJoel Becker /* 52cf4d8d75SDavid Teigland * The dlm_lockstatus struct includes lvb space, but the dlm_lksb struct only 53cf4d8d75SDavid Teigland * has a pointer to separately allocated lvb space. This struct exists only to 54cf4d8d75SDavid Teigland * include in the lksb union to make space for a combined dlm_lksb and lvb. 55cf4d8d75SDavid Teigland */ 56cf4d8d75SDavid Teigland struct fsdlm_lksb_plus_lvb { 57cf4d8d75SDavid Teigland struct dlm_lksb lksb; 58cf4d8d75SDavid Teigland char lvb[DLM_LVB_LEN]; 59cf4d8d75SDavid Teigland }; 60cf4d8d75SDavid Teigland 61e3dad42bSJoel Becker /* 62e3dad42bSJoel Becker * A union of all lock status structures. We define it here so that the 63e3dad42bSJoel Becker * size of the union is known. Lock status structures are embedded in 64e3dad42bSJoel Becker * ocfs2 inodes. 65e3dad42bSJoel Becker */ 66c0e41338SJoel Becker struct ocfs2_cluster_connection; 67c0e41338SJoel Becker struct ocfs2_dlm_lksb { 68c0e41338SJoel Becker union { 698f2c9c1bSJoel Becker struct dlm_lockstatus lksb_o2dlm; 70cf4d8d75SDavid Teigland struct dlm_lksb lksb_fsdlm; 71cf4d8d75SDavid Teigland struct fsdlm_lksb_plus_lvb padding; 728f2c9c1bSJoel Becker }; 73c0e41338SJoel Becker struct ocfs2_cluster_connection *lksb_conn; 74c0e41338SJoel Becker }; 758f2c9c1bSJoel Becker 76e3dad42bSJoel Becker /* 77a796d286SJoel Becker * The ocfs2_locking_protocol defines the handlers called on ocfs2's behalf. 78a796d286SJoel Becker */ 79a796d286SJoel Becker struct ocfs2_locking_protocol { 80a796d286SJoel Becker struct ocfs2_protocol_version lp_max_version; 81c0e41338SJoel Becker void (*lp_lock_ast)(struct ocfs2_dlm_lksb *lksb); 82c0e41338SJoel Becker void (*lp_blocking_ast)(struct ocfs2_dlm_lksb *lksb, int level); 83c0e41338SJoel Becker void (*lp_unlock_ast)(struct ocfs2_dlm_lksb *lksb, int error); 84a796d286SJoel Becker }; 85a796d286SJoel Becker 86a796d286SJoel Becker 87a796d286SJoel Becker /* 88e3dad42bSJoel Becker * A cluster connection. Mostly opaque to ocfs2, the connection holds 89e3dad42bSJoel Becker * state for the underlying stack. ocfs2 does use cc_version to determine 90e3dad42bSJoel Becker * locking compatibility. 91e3dad42bSJoel Becker */ 924670c46dSJoel Becker struct ocfs2_cluster_connection { 93c74a3bddSGoldwyn Rodrigues char cc_name[GROUP_NAME_MAX + 1]; 944670c46dSJoel Becker int cc_namelen; 95c74a3bddSGoldwyn Rodrigues char cc_cluster_name[CLUSTER_NAME_MAX + 1]; 96c74a3bddSGoldwyn Rodrigues int cc_cluster_name_len; 974670c46dSJoel Becker struct ocfs2_protocol_version cc_version; 98110946c8SJoel Becker struct ocfs2_locking_protocol *cc_proto; 994670c46dSJoel Becker void (*cc_recovery_handler)(int node_num, void *recovery_data); 1004670c46dSJoel Becker void *cc_recovery_data; 1014670c46dSJoel Becker void *cc_lockspace; 1024670c46dSJoel Becker void *cc_private; 1034670c46dSJoel Becker }; 1044670c46dSJoel Becker 105e3dad42bSJoel Becker /* 106e3dad42bSJoel Becker * Each cluster stack implements the stack operations structure. Not used 107e3dad42bSJoel Becker * in the ocfs2 code, the stackglue code translates generic cluster calls 108e3dad42bSJoel Becker * into stack operations. 109e3dad42bSJoel Becker */ 110e3dad42bSJoel Becker struct ocfs2_stack_operations { 111e3dad42bSJoel Becker /* 112e3dad42bSJoel Becker * The fs code calls ocfs2_cluster_connect() to attach a new 113e3dad42bSJoel Becker * filesystem to the cluster stack. The ->connect() op is passed 114e3dad42bSJoel Becker * an ocfs2_cluster_connection with the name and recovery field 115e3dad42bSJoel Becker * filled in. 116e3dad42bSJoel Becker * 117e3dad42bSJoel Becker * The stack must set up any notification mechanisms and create 118e3dad42bSJoel Becker * the filesystem lockspace in the DLM. The lockspace should be 119e3dad42bSJoel Becker * stored on cc_lockspace. Any other information can be stored on 120e3dad42bSJoel Becker * cc_private. 121e3dad42bSJoel Becker * 122e3dad42bSJoel Becker * ->connect() must not return until it is guaranteed that 123e3dad42bSJoel Becker * 12425985edcSLucas De Marchi * - Node down notifications for the filesystem will be received 125e3dad42bSJoel Becker * and passed to conn->cc_recovery_handler(). 126e3dad42bSJoel Becker * - Locking requests for the filesystem will be processed. 127e3dad42bSJoel Becker */ 128e3dad42bSJoel Becker int (*connect)(struct ocfs2_cluster_connection *conn); 129e3dad42bSJoel Becker 130e3dad42bSJoel Becker /* 131e3dad42bSJoel Becker * The fs code calls ocfs2_cluster_disconnect() when a filesystem 132e3dad42bSJoel Becker * no longer needs cluster services. All DLM locks have been 133e3dad42bSJoel Becker * dropped, and recovery notification is being ignored by the 134e3dad42bSJoel Becker * fs code. The stack must disengage from the DLM and discontinue 135e3dad42bSJoel Becker * recovery notification. 136e3dad42bSJoel Becker * 137e3dad42bSJoel Becker * Once ->disconnect() has returned, the connection structure will 138e3dad42bSJoel Becker * be freed. Thus, a stack must not return from ->disconnect() 139e3dad42bSJoel Becker * until it will no longer reference the conn pointer. 140286eaa95SJoel Becker * 1412c39450bSJoel Becker * Once this call returns, the stack glue will be dropping this 1422c39450bSJoel Becker * connection's reference on the module. 143e3dad42bSJoel Becker */ 1442c39450bSJoel Becker int (*disconnect)(struct ocfs2_cluster_connection *conn); 145e3dad42bSJoel Becker 146e3dad42bSJoel Becker /* 147e3dad42bSJoel Becker * ->this_node() returns the cluster's unique identifier for the 148e3dad42bSJoel Becker * local node. 149e3dad42bSJoel Becker */ 1503e834151SGoldwyn Rodrigues int (*this_node)(struct ocfs2_cluster_connection *conn, 1513e834151SGoldwyn Rodrigues unsigned int *node); 152e3dad42bSJoel Becker 153e3dad42bSJoel Becker /* 154e3dad42bSJoel Becker * Call the underlying dlm lock function. The ->dlm_lock() 155e3dad42bSJoel Becker * callback should convert the flags and mode as appropriate. 156e3dad42bSJoel Becker * 157e3dad42bSJoel Becker * ast and bast functions are not part of the call because the 158e3dad42bSJoel Becker * stack will likely want to wrap ast and bast calls before passing 159a796d286SJoel Becker * them to stack->sp_proto. There is no astarg. The lksb will 160a796d286SJoel Becker * be passed back to the ast and bast functions. The caller can 161a796d286SJoel Becker * use this to find their object. 162e3dad42bSJoel Becker */ 163e3dad42bSJoel Becker int (*dlm_lock)(struct ocfs2_cluster_connection *conn, 164e3dad42bSJoel Becker int mode, 165c0e41338SJoel Becker struct ocfs2_dlm_lksb *lksb, 166e3dad42bSJoel Becker u32 flags, 167e3dad42bSJoel Becker void *name, 168a796d286SJoel Becker unsigned int namelen); 169e3dad42bSJoel Becker 170e3dad42bSJoel Becker /* 171e3dad42bSJoel Becker * Call the underlying dlm unlock function. The ->dlm_unlock() 172e3dad42bSJoel Becker * function should convert the flags as appropriate. 173e3dad42bSJoel Becker * 174e3dad42bSJoel Becker * The unlock ast is not passed, as the stack will want to wrap 175a796d286SJoel Becker * it before calling stack->sp_proto->lp_unlock_ast(). There is 176a796d286SJoel Becker * no astarg. The lksb will be passed back to the unlock ast 177a796d286SJoel Becker * function. The caller can use this to find their object. 178e3dad42bSJoel Becker */ 179e3dad42bSJoel Becker int (*dlm_unlock)(struct ocfs2_cluster_connection *conn, 180c0e41338SJoel Becker struct ocfs2_dlm_lksb *lksb, 181a796d286SJoel Becker u32 flags); 182e3dad42bSJoel Becker 183e3dad42bSJoel Becker /* 184e3dad42bSJoel Becker * Return the status of the current lock status block. The fs 185e3dad42bSJoel Becker * code should never dereference the union. The ->lock_status() 186e3dad42bSJoel Becker * callback pulls out the stack-specific lksb, converts the status 187e3dad42bSJoel Becker * to a proper errno, and returns it. 188e3dad42bSJoel Becker */ 189c0e41338SJoel Becker int (*lock_status)(struct ocfs2_dlm_lksb *lksb); 190e3dad42bSJoel Becker 191e3dad42bSJoel Becker /* 1921c520dfbSJoel Becker * Return non-zero if the LVB is valid. 1931c520dfbSJoel Becker */ 194c0e41338SJoel Becker int (*lvb_valid)(struct ocfs2_dlm_lksb *lksb); 1951c520dfbSJoel Becker 1961c520dfbSJoel Becker /* 197e3dad42bSJoel Becker * Pull the lvb pointer off of the stack-specific lksb. 198e3dad42bSJoel Becker */ 199c0e41338SJoel Becker void *(*lock_lvb)(struct ocfs2_dlm_lksb *lksb); 200e3dad42bSJoel Becker 201e3dad42bSJoel Becker /* 20253da4939SMark Fasheh * Cluster-aware posix locks 20353da4939SMark Fasheh * 20453da4939SMark Fasheh * This is NULL for stacks which do not support posix locks. 20553da4939SMark Fasheh */ 20653da4939SMark Fasheh int (*plock)(struct ocfs2_cluster_connection *conn, 20753da4939SMark Fasheh u64 ino, 20853da4939SMark Fasheh struct file *file, 20953da4939SMark Fasheh int cmd, 21053da4939SMark Fasheh struct file_lock *fl); 21153da4939SMark Fasheh 21253da4939SMark Fasheh /* 213e3dad42bSJoel Becker * This is an optoinal debugging hook. If provided, the 214e3dad42bSJoel Becker * stack can dump debugging information about this lock. 215e3dad42bSJoel Becker */ 216c0e41338SJoel Becker void (*dump_lksb)(struct ocfs2_dlm_lksb *lksb); 217e3dad42bSJoel Becker }; 218e3dad42bSJoel Becker 219286eaa95SJoel Becker /* 220286eaa95SJoel Becker * Each stack plugin must describe itself by registering a 221286eaa95SJoel Becker * ocfs2_stack_plugin structure. This is only seen by stackglue and the 222286eaa95SJoel Becker * stack driver. 223286eaa95SJoel Becker */ 224286eaa95SJoel Becker struct ocfs2_stack_plugin { 225286eaa95SJoel Becker char *sp_name; 226286eaa95SJoel Becker struct ocfs2_stack_operations *sp_ops; 227286eaa95SJoel Becker struct module *sp_owner; 228286eaa95SJoel Becker 229286eaa95SJoel Becker /* These are managed by the stackglue code. */ 230286eaa95SJoel Becker struct list_head sp_list; 231286eaa95SJoel Becker unsigned int sp_count; 232e603cfb0SJoel Becker struct ocfs2_protocol_version sp_max_proto; 233286eaa95SJoel Becker }; 234286eaa95SJoel Becker 235286eaa95SJoel Becker 236286eaa95SJoel Becker /* Used by the filesystem */ 2379c6c877cSJoel Becker int ocfs2_cluster_connect(const char *stack_name, 238c74a3bddSGoldwyn Rodrigues const char *cluster_name, 239c74a3bddSGoldwyn Rodrigues int cluster_name_len, 2409c6c877cSJoel Becker const char *group, 2414670c46dSJoel Becker int grouplen, 242553b5eb9SJoel Becker struct ocfs2_locking_protocol *lproto, 2434670c46dSJoel Becker void (*recovery_handler)(int node_num, 2444670c46dSJoel Becker void *recovery_data), 2454670c46dSJoel Becker void *recovery_data, 2464670c46dSJoel Becker struct ocfs2_cluster_connection **conn); 247cbe0e331SJoel Becker /* 248cbe0e331SJoel Becker * Used by callers that don't store their stack name. They must ensure 249cbe0e331SJoel Becker * all nodes have the same stack. 250cbe0e331SJoel Becker */ 251cbe0e331SJoel Becker int ocfs2_cluster_connect_agnostic(const char *group, 252cbe0e331SJoel Becker int grouplen, 253cbe0e331SJoel Becker struct ocfs2_locking_protocol *lproto, 254cbe0e331SJoel Becker void (*recovery_handler)(int node_num, 255cbe0e331SJoel Becker void *recovery_data), 256cbe0e331SJoel Becker void *recovery_data, 257cbe0e331SJoel Becker struct ocfs2_cluster_connection **conn); 258286eaa95SJoel Becker int ocfs2_cluster_disconnect(struct ocfs2_cluster_connection *conn, 259286eaa95SJoel Becker int hangup_pending); 2606953b4c0SJoel Becker void ocfs2_cluster_hangup(const char *group, int grouplen); 2613e834151SGoldwyn Rodrigues int ocfs2_cluster_this_node(struct ocfs2_cluster_connection *conn, 2623e834151SGoldwyn Rodrigues unsigned int *node); 2634670c46dSJoel Becker 264cf4d8d75SDavid Teigland struct ocfs2_lock_res; 2654670c46dSJoel Becker int ocfs2_dlm_lock(struct ocfs2_cluster_connection *conn, 26624ef1815SJoel Becker int mode, 267c0e41338SJoel Becker struct ocfs2_dlm_lksb *lksb, 26824ef1815SJoel Becker u32 flags, 26924ef1815SJoel Becker void *name, 270a796d286SJoel Becker unsigned int namelen); 2714670c46dSJoel Becker int ocfs2_dlm_unlock(struct ocfs2_cluster_connection *conn, 272c0e41338SJoel Becker struct ocfs2_dlm_lksb *lksb, 273a796d286SJoel Becker u32 flags); 27424ef1815SJoel Becker 275c0e41338SJoel Becker int ocfs2_dlm_lock_status(struct ocfs2_dlm_lksb *lksb); 276c0e41338SJoel Becker int ocfs2_dlm_lvb_valid(struct ocfs2_dlm_lksb *lksb); 277c0e41338SJoel Becker void *ocfs2_dlm_lvb(struct ocfs2_dlm_lksb *lksb); 278c0e41338SJoel Becker void ocfs2_dlm_dump_lksb(struct ocfs2_dlm_lksb *lksb); 2798f2c9c1bSJoel Becker 28053da4939SMark Fasheh int ocfs2_stack_supports_plocks(void); 28153da4939SMark Fasheh int ocfs2_plock(struct ocfs2_cluster_connection *conn, u64 ino, 28253da4939SMark Fasheh struct file *file, int cmd, struct file_lock *fl); 28353da4939SMark Fasheh 284553b5eb9SJoel Becker void ocfs2_stack_glue_set_max_proto_version(struct ocfs2_protocol_version *max_proto); 28524ef1815SJoel Becker 286286eaa95SJoel Becker 287286eaa95SJoel Becker /* Used by stack plugins */ 288286eaa95SJoel Becker int ocfs2_stack_glue_register(struct ocfs2_stack_plugin *plugin); 289286eaa95SJoel Becker void ocfs2_stack_glue_unregister(struct ocfs2_stack_plugin *plugin); 2903878f110SJoel Becker 2919dde5e4fSGang He extern struct kset *ocfs2_kset; 2929dde5e4fSGang He 29324ef1815SJoel Becker #endif /* STACKGLUE_H */ 294