Joel Becker | 24ef181 | 2008-01-29 17:37:32 -0800 | [diff] [blame] | 1 | /* -*- mode: c; c-basic-offset: 8; -*- |
| 2 | * vim: noexpandtab sw=8 ts=8 sts=0: |
| 3 | * |
| 4 | * stackglue.h |
| 5 | * |
| 6 | * Glue to the underlying cluster stack. |
| 7 | * |
| 8 | * Copyright (C) 2007 Oracle. All rights reserved. |
| 9 | * |
| 10 | * This program is free software; you can redistribute it and/or |
| 11 | * modify it under the terms of the GNU General Public |
| 12 | * License as published by the Free Software Foundation, version 2. |
| 13 | * |
| 14 | * This program is distributed in the hope that it will be useful, |
| 15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 17 | * General Public License for more details. |
| 18 | */ |
| 19 | |
| 20 | |
| 21 | #ifndef STACKGLUE_H |
| 22 | #define STACKGLUE_H |
| 23 | |
Joel Becker | bd3e761 | 2008-02-01 12:14:57 -0800 | [diff] [blame] | 24 | #include <linux/types.h> |
| 25 | #include <linux/list.h> |
| 26 | #include <linux/dlmconstants.h> |
| 27 | |
Joel Becker | e3dad42 | 2008-02-01 15:02:36 -0800 | [diff] [blame] | 28 | #include "dlm/dlmapi.h" |
| 29 | |
Joel Becker | bd3e761 | 2008-02-01 12:14:57 -0800 | [diff] [blame] | 30 | /* |
| 31 | * dlmconstants.h does not have a LOCAL flag. We hope to remove it |
| 32 | * some day, but right now we need it. Let's fake it. This value is larger |
| 33 | * than any flag in dlmconstants.h. |
| 34 | */ |
| 35 | #define DLM_LKF_LOCAL 0x00100000 |
| 36 | |
Joel Becker | 4670c46 | 2008-02-01 14:39:35 -0800 | [diff] [blame] | 37 | /* |
| 38 | * This shadows DLM_LOCKSPACE_LEN in fs/dlm/dlm_internal.h. That probably |
| 39 | * wants to be in a public header. |
| 40 | */ |
| 41 | #define GROUP_NAME_MAX 64 |
| 42 | |
| 43 | |
Joel Becker | e3dad42 | 2008-02-01 15:02:36 -0800 | [diff] [blame] | 44 | /* |
| 45 | * ocfs2_protocol_version changes when ocfs2 does something different in |
| 46 | * its inter-node behavior. See dlmglue.c for more information. |
| 47 | */ |
Joel Becker | 4670c46 | 2008-02-01 14:39:35 -0800 | [diff] [blame] | 48 | struct ocfs2_protocol_version { |
| 49 | u8 pv_major; |
| 50 | u8 pv_minor; |
| 51 | }; |
| 52 | |
Joel Becker | e3dad42 | 2008-02-01 15:02:36 -0800 | [diff] [blame] | 53 | /* |
| 54 | * The ocfs2_locking_protocol defines the handlers called on ocfs2's behalf. |
| 55 | */ |
Joel Becker | 24ef181 | 2008-01-29 17:37:32 -0800 | [diff] [blame] | 56 | struct ocfs2_locking_protocol { |
Joel Becker | 4670c46 | 2008-02-01 14:39:35 -0800 | [diff] [blame] | 57 | struct ocfs2_protocol_version lp_max_version; |
Joel Becker | 24ef181 | 2008-01-29 17:37:32 -0800 | [diff] [blame] | 58 | void (*lp_lock_ast)(void *astarg); |
| 59 | void (*lp_blocking_ast)(void *astarg, int level); |
Joel Becker | 7431cd7 | 2008-02-01 12:15:37 -0800 | [diff] [blame] | 60 | void (*lp_unlock_ast)(void *astarg, int error); |
Joel Becker | 24ef181 | 2008-01-29 17:37:32 -0800 | [diff] [blame] | 61 | }; |
| 62 | |
Joel Becker | e3dad42 | 2008-02-01 15:02:36 -0800 | [diff] [blame] | 63 | /* |
| 64 | * A union of all lock status structures. We define it here so that the |
| 65 | * size of the union is known. Lock status structures are embedded in |
| 66 | * ocfs2 inodes. |
| 67 | */ |
Joel Becker | 8f2c9c1 | 2008-02-01 12:16:57 -0800 | [diff] [blame] | 68 | union ocfs2_dlm_lksb { |
| 69 | struct dlm_lockstatus lksb_o2dlm; |
| 70 | }; |
| 71 | |
Joel Becker | e3dad42 | 2008-02-01 15:02:36 -0800 | [diff] [blame] | 72 | /* |
| 73 | * A cluster connection. Mostly opaque to ocfs2, the connection holds |
| 74 | * state for the underlying stack. ocfs2 does use cc_version to determine |
| 75 | * locking compatibility. |
| 76 | */ |
Joel Becker | 4670c46 | 2008-02-01 14:39:35 -0800 | [diff] [blame] | 77 | struct ocfs2_cluster_connection { |
| 78 | char cc_name[GROUP_NAME_MAX]; |
| 79 | int cc_namelen; |
| 80 | struct ocfs2_protocol_version cc_version; |
| 81 | void (*cc_recovery_handler)(int node_num, void *recovery_data); |
| 82 | void *cc_recovery_data; |
| 83 | void *cc_lockspace; |
| 84 | void *cc_private; |
| 85 | }; |
| 86 | |
Joel Becker | e3dad42 | 2008-02-01 15:02:36 -0800 | [diff] [blame] | 87 | /* |
| 88 | * Each cluster stack implements the stack operations structure. Not used |
| 89 | * in the ocfs2 code, the stackglue code translates generic cluster calls |
| 90 | * into stack operations. |
| 91 | */ |
| 92 | struct ocfs2_stack_operations { |
| 93 | /* |
| 94 | * The fs code calls ocfs2_cluster_connect() to attach a new |
| 95 | * filesystem to the cluster stack. The ->connect() op is passed |
| 96 | * an ocfs2_cluster_connection with the name and recovery field |
| 97 | * filled in. |
| 98 | * |
| 99 | * The stack must set up any notification mechanisms and create |
| 100 | * the filesystem lockspace in the DLM. The lockspace should be |
| 101 | * stored on cc_lockspace. Any other information can be stored on |
| 102 | * cc_private. |
| 103 | * |
| 104 | * ->connect() must not return until it is guaranteed that |
| 105 | * |
| 106 | * - Node down notifications for the filesystem will be recieved |
| 107 | * and passed to conn->cc_recovery_handler(). |
| 108 | * - Locking requests for the filesystem will be processed. |
| 109 | */ |
| 110 | int (*connect)(struct ocfs2_cluster_connection *conn); |
| 111 | |
| 112 | /* |
| 113 | * The fs code calls ocfs2_cluster_disconnect() when a filesystem |
| 114 | * no longer needs cluster services. All DLM locks have been |
| 115 | * dropped, and recovery notification is being ignored by the |
| 116 | * fs code. The stack must disengage from the DLM and discontinue |
| 117 | * recovery notification. |
| 118 | * |
| 119 | * Once ->disconnect() has returned, the connection structure will |
| 120 | * be freed. Thus, a stack must not return from ->disconnect() |
| 121 | * until it will no longer reference the conn pointer. |
Joel Becker | 286eaa9 | 2008-02-01 15:03:57 -0800 | [diff] [blame] | 122 | * |
| 123 | * If hangup_pending is zero, ocfs2_cluster_disconnect() will also |
| 124 | * be dropping the reference on the module. |
Joel Becker | e3dad42 | 2008-02-01 15:02:36 -0800 | [diff] [blame] | 125 | */ |
Joel Becker | 286eaa9 | 2008-02-01 15:03:57 -0800 | [diff] [blame] | 126 | int (*disconnect)(struct ocfs2_cluster_connection *conn, |
| 127 | int hangup_pending); |
Joel Becker | e3dad42 | 2008-02-01 15:02:36 -0800 | [diff] [blame] | 128 | |
| 129 | /* |
| 130 | * ocfs2_cluster_hangup() exists for compatibility with older |
| 131 | * ocfs2 tools. Only the classic stack really needs it. As such |
| 132 | * ->hangup() is not required of all stacks. See the comment by |
| 133 | * ocfs2_cluster_hangup() for more details. |
Joel Becker | 286eaa9 | 2008-02-01 15:03:57 -0800 | [diff] [blame] | 134 | * |
| 135 | * Note that ocfs2_cluster_hangup() can only be called if |
| 136 | * hangup_pending was passed to ocfs2_cluster_disconnect(). |
Joel Becker | e3dad42 | 2008-02-01 15:02:36 -0800 | [diff] [blame] | 137 | */ |
| 138 | void (*hangup)(const char *group, int grouplen); |
| 139 | |
| 140 | /* |
| 141 | * ->this_node() returns the cluster's unique identifier for the |
| 142 | * local node. |
| 143 | */ |
| 144 | int (*this_node)(unsigned int *node); |
| 145 | |
| 146 | /* |
| 147 | * Call the underlying dlm lock function. The ->dlm_lock() |
| 148 | * callback should convert the flags and mode as appropriate. |
| 149 | * |
| 150 | * ast and bast functions are not part of the call because the |
| 151 | * stack will likely want to wrap ast and bast calls before passing |
| 152 | * them to stack->sp_proto. |
| 153 | */ |
| 154 | int (*dlm_lock)(struct ocfs2_cluster_connection *conn, |
| 155 | int mode, |
| 156 | union ocfs2_dlm_lksb *lksb, |
| 157 | u32 flags, |
| 158 | void *name, |
| 159 | unsigned int namelen, |
| 160 | void *astarg); |
| 161 | |
| 162 | /* |
| 163 | * Call the underlying dlm unlock function. The ->dlm_unlock() |
| 164 | * function should convert the flags as appropriate. |
| 165 | * |
| 166 | * The unlock ast is not passed, as the stack will want to wrap |
| 167 | * it before calling stack->sp_proto->lp_unlock_ast(). |
| 168 | */ |
| 169 | int (*dlm_unlock)(struct ocfs2_cluster_connection *conn, |
| 170 | union ocfs2_dlm_lksb *lksb, |
| 171 | u32 flags, |
| 172 | void *astarg); |
| 173 | |
| 174 | /* |
| 175 | * Return the status of the current lock status block. The fs |
| 176 | * code should never dereference the union. The ->lock_status() |
| 177 | * callback pulls out the stack-specific lksb, converts the status |
| 178 | * to a proper errno, and returns it. |
| 179 | */ |
| 180 | int (*lock_status)(union ocfs2_dlm_lksb *lksb); |
| 181 | |
| 182 | /* |
| 183 | * Pull the lvb pointer off of the stack-specific lksb. |
| 184 | */ |
| 185 | void *(*lock_lvb)(union ocfs2_dlm_lksb *lksb); |
| 186 | |
| 187 | /* |
| 188 | * This is an optoinal debugging hook. If provided, the |
| 189 | * stack can dump debugging information about this lock. |
| 190 | */ |
| 191 | void (*dump_lksb)(union ocfs2_dlm_lksb *lksb); |
| 192 | }; |
| 193 | |
Joel Becker | 286eaa9 | 2008-02-01 15:03:57 -0800 | [diff] [blame] | 194 | /* |
| 195 | * Each stack plugin must describe itself by registering a |
| 196 | * ocfs2_stack_plugin structure. This is only seen by stackglue and the |
| 197 | * stack driver. |
| 198 | */ |
| 199 | struct ocfs2_stack_plugin { |
| 200 | char *sp_name; |
| 201 | struct ocfs2_stack_operations *sp_ops; |
| 202 | struct module *sp_owner; |
| 203 | |
| 204 | /* These are managed by the stackglue code. */ |
| 205 | struct list_head sp_list; |
| 206 | unsigned int sp_count; |
| 207 | struct ocfs2_locking_protocol *sp_proto; |
| 208 | }; |
| 209 | |
| 210 | |
| 211 | /* Used by the filesystem */ |
Joel Becker | 9c6c877 | 2008-02-01 15:17:30 -0800 | [diff] [blame^] | 212 | int ocfs2_cluster_connect(const char *stack_name, |
| 213 | const char *group, |
Joel Becker | 4670c46 | 2008-02-01 14:39:35 -0800 | [diff] [blame] | 214 | int grouplen, |
| 215 | void (*recovery_handler)(int node_num, |
| 216 | void *recovery_data), |
| 217 | void *recovery_data, |
| 218 | struct ocfs2_cluster_connection **conn); |
Joel Becker | 286eaa9 | 2008-02-01 15:03:57 -0800 | [diff] [blame] | 219 | int ocfs2_cluster_disconnect(struct ocfs2_cluster_connection *conn, |
| 220 | int hangup_pending); |
Joel Becker | 6953b4c | 2008-01-29 16:59:56 -0800 | [diff] [blame] | 221 | void ocfs2_cluster_hangup(const char *group, int grouplen); |
Joel Becker | 19fdb62 | 2008-01-30 15:38:24 -0800 | [diff] [blame] | 222 | int ocfs2_cluster_this_node(unsigned int *node); |
Joel Becker | 4670c46 | 2008-02-01 14:39:35 -0800 | [diff] [blame] | 223 | |
| 224 | int ocfs2_dlm_lock(struct ocfs2_cluster_connection *conn, |
Joel Becker | 24ef181 | 2008-01-29 17:37:32 -0800 | [diff] [blame] | 225 | int mode, |
Joel Becker | 8f2c9c1 | 2008-02-01 12:16:57 -0800 | [diff] [blame] | 226 | union ocfs2_dlm_lksb *lksb, |
Joel Becker | 24ef181 | 2008-01-29 17:37:32 -0800 | [diff] [blame] | 227 | u32 flags, |
| 228 | void *name, |
| 229 | unsigned int namelen, |
| 230 | void *astarg); |
Joel Becker | 4670c46 | 2008-02-01 14:39:35 -0800 | [diff] [blame] | 231 | int ocfs2_dlm_unlock(struct ocfs2_cluster_connection *conn, |
Joel Becker | 8f2c9c1 | 2008-02-01 12:16:57 -0800 | [diff] [blame] | 232 | union ocfs2_dlm_lksb *lksb, |
Joel Becker | 24ef181 | 2008-01-29 17:37:32 -0800 | [diff] [blame] | 233 | u32 flags, |
| 234 | void *astarg); |
| 235 | |
Joel Becker | 8f2c9c1 | 2008-02-01 12:16:57 -0800 | [diff] [blame] | 236 | int ocfs2_dlm_lock_status(union ocfs2_dlm_lksb *lksb); |
| 237 | void *ocfs2_dlm_lvb(union ocfs2_dlm_lksb *lksb); |
Joel Becker | cf0acdc | 2008-01-29 16:59:55 -0800 | [diff] [blame] | 238 | void ocfs2_dlm_dump_lksb(union ocfs2_dlm_lksb *lksb); |
Joel Becker | 8f2c9c1 | 2008-02-01 12:16:57 -0800 | [diff] [blame] | 239 | |
Joel Becker | 63e0c48 | 2008-01-30 16:58:36 -0800 | [diff] [blame] | 240 | void ocfs2_stack_glue_set_locking_protocol(struct ocfs2_locking_protocol *proto); |
Joel Becker | 24ef181 | 2008-01-29 17:37:32 -0800 | [diff] [blame] | 241 | |
Joel Becker | 286eaa9 | 2008-02-01 15:03:57 -0800 | [diff] [blame] | 242 | |
| 243 | /* Used by stack plugins */ |
| 244 | int ocfs2_stack_glue_register(struct ocfs2_stack_plugin *plugin); |
| 245 | void ocfs2_stack_glue_unregister(struct ocfs2_stack_plugin *plugin); |
Joel Becker | 24ef181 | 2008-01-29 17:37:32 -0800 | [diff] [blame] | 246 | #endif /* STACKGLUE_H */ |