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.c |
| 5 | * |
| 6 | * Code which implements an OCFS2 specific interface to underlying |
| 7 | * cluster stacks. |
| 8 | * |
| 9 | * Copyright (C) 2007 Oracle. All rights reserved. |
| 10 | * |
| 11 | * This program is free software; you can redistribute it and/or |
| 12 | * modify it under the terms of the GNU General Public |
| 13 | * License as published by the Free Software Foundation, version 2. |
| 14 | * |
| 15 | * This program is distributed in the hope that it will be useful, |
| 16 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 17 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 18 | * General Public License for more details. |
| 19 | */ |
| 20 | |
Joel Becker | 286eaa9 | 2008-02-01 15:03:57 -0800 | [diff] [blame] | 21 | #include <linux/list.h> |
| 22 | #include <linux/spinlock.h> |
| 23 | #include <linux/module.h> |
Joel Becker | 4670c46 | 2008-02-01 14:39:35 -0800 | [diff] [blame] | 24 | #include <linux/slab.h> |
Joel Becker | 6953b4c | 2008-01-29 16:59:56 -0800 | [diff] [blame] | 25 | #include <linux/kmod.h> |
Joel Becker | 74ae4e1 | 2008-01-31 23:56:17 -0800 | [diff] [blame] | 26 | #include <linux/fs.h> |
| 27 | #include <linux/kobject.h> |
| 28 | #include <linux/sysfs.h> |
Joel Becker | 3878f11 | 2008-05-30 15:30:49 -0700 | [diff] [blame^] | 29 | #include <linux/sysctl.h> |
Joel Becker | 4670c46 | 2008-02-01 14:39:35 -0800 | [diff] [blame] | 30 | |
Joel Becker | 9c6c877 | 2008-02-01 15:17:30 -0800 | [diff] [blame] | 31 | #include "ocfs2_fs.h" |
| 32 | |
Joel Becker | 24ef181 | 2008-01-29 17:37:32 -0800 | [diff] [blame] | 33 | #include "stackglue.h" |
| 34 | |
Joel Becker | 9c6c877 | 2008-02-01 15:17:30 -0800 | [diff] [blame] | 35 | #define OCFS2_STACK_PLUGIN_O2CB "o2cb" |
| 36 | #define OCFS2_STACK_PLUGIN_USER "user" |
| 37 | |
Joel Becker | 286eaa9 | 2008-02-01 15:03:57 -0800 | [diff] [blame] | 38 | static struct ocfs2_locking_protocol *lproto; |
| 39 | static DEFINE_SPINLOCK(ocfs2_stack_lock); |
| 40 | static LIST_HEAD(ocfs2_stack_list); |
Joel Becker | 9c6c877 | 2008-02-01 15:17:30 -0800 | [diff] [blame] | 41 | static char cluster_stack_name[OCFS2_STACK_LABEL_LEN + 1]; |
Joel Becker | 286eaa9 | 2008-02-01 15:03:57 -0800 | [diff] [blame] | 42 | |
| 43 | /* |
| 44 | * The stack currently in use. If not null, active_stack->sp_count > 0, |
| 45 | * the module is pinned, and the locking protocol cannot be changed. |
| 46 | */ |
| 47 | static struct ocfs2_stack_plugin *active_stack; |
| 48 | |
| 49 | static struct ocfs2_stack_plugin *ocfs2_stack_lookup(const char *name) |
| 50 | { |
| 51 | struct ocfs2_stack_plugin *p; |
| 52 | |
| 53 | assert_spin_locked(&ocfs2_stack_lock); |
| 54 | |
| 55 | list_for_each_entry(p, &ocfs2_stack_list, sp_list) { |
| 56 | if (!strcmp(p->sp_name, name)) |
| 57 | return p; |
| 58 | } |
| 59 | |
| 60 | return NULL; |
| 61 | } |
| 62 | |
Joel Becker | 9c6c877 | 2008-02-01 15:17:30 -0800 | [diff] [blame] | 63 | static int ocfs2_stack_driver_request(const char *stack_name, |
| 64 | const char *plugin_name) |
Joel Becker | 286eaa9 | 2008-02-01 15:03:57 -0800 | [diff] [blame] | 65 | { |
| 66 | int rc; |
| 67 | struct ocfs2_stack_plugin *p; |
| 68 | |
| 69 | spin_lock(&ocfs2_stack_lock); |
| 70 | |
Joel Becker | 9c6c877 | 2008-02-01 15:17:30 -0800 | [diff] [blame] | 71 | /* |
| 72 | * If the stack passed by the filesystem isn't the selected one, |
| 73 | * we can't continue. |
| 74 | */ |
| 75 | if (strcmp(stack_name, cluster_stack_name)) { |
| 76 | rc = -EBUSY; |
| 77 | goto out; |
| 78 | } |
| 79 | |
Joel Becker | 286eaa9 | 2008-02-01 15:03:57 -0800 | [diff] [blame] | 80 | if (active_stack) { |
| 81 | /* |
| 82 | * If the active stack isn't the one we want, it cannot |
| 83 | * be selected right now. |
| 84 | */ |
Joel Becker | 9c6c877 | 2008-02-01 15:17:30 -0800 | [diff] [blame] | 85 | if (!strcmp(active_stack->sp_name, plugin_name)) |
Joel Becker | 286eaa9 | 2008-02-01 15:03:57 -0800 | [diff] [blame] | 86 | rc = 0; |
| 87 | else |
| 88 | rc = -EBUSY; |
| 89 | goto out; |
| 90 | } |
| 91 | |
Joel Becker | 9c6c877 | 2008-02-01 15:17:30 -0800 | [diff] [blame] | 92 | p = ocfs2_stack_lookup(plugin_name); |
Joel Becker | 286eaa9 | 2008-02-01 15:03:57 -0800 | [diff] [blame] | 93 | if (!p || !try_module_get(p->sp_owner)) { |
| 94 | rc = -ENOENT; |
| 95 | goto out; |
| 96 | } |
| 97 | |
| 98 | /* Ok, the stack is pinned */ |
| 99 | p->sp_count++; |
| 100 | active_stack = p; |
| 101 | |
| 102 | rc = 0; |
| 103 | |
| 104 | out: |
| 105 | spin_unlock(&ocfs2_stack_lock); |
| 106 | return rc; |
| 107 | } |
| 108 | |
| 109 | /* |
| 110 | * This function looks up the appropriate stack and makes it active. If |
| 111 | * there is no stack, it tries to load it. It will fail if the stack still |
| 112 | * cannot be found. It will also fail if a different stack is in use. |
| 113 | */ |
Joel Becker | 9c6c877 | 2008-02-01 15:17:30 -0800 | [diff] [blame] | 114 | static int ocfs2_stack_driver_get(const char *stack_name) |
Joel Becker | 286eaa9 | 2008-02-01 15:03:57 -0800 | [diff] [blame] | 115 | { |
| 116 | int rc; |
Joel Becker | 9c6c877 | 2008-02-01 15:17:30 -0800 | [diff] [blame] | 117 | char *plugin_name = OCFS2_STACK_PLUGIN_O2CB; |
Joel Becker | 286eaa9 | 2008-02-01 15:03:57 -0800 | [diff] [blame] | 118 | |
Joel Becker | 9c6c877 | 2008-02-01 15:17:30 -0800 | [diff] [blame] | 119 | /* |
| 120 | * Classic stack does not pass in a stack name. This is |
| 121 | * compatible with older tools as well. |
| 122 | */ |
| 123 | if (!stack_name || !*stack_name) |
| 124 | stack_name = OCFS2_STACK_PLUGIN_O2CB; |
| 125 | |
| 126 | if (strlen(stack_name) != OCFS2_STACK_LABEL_LEN) { |
| 127 | printk(KERN_ERR |
| 128 | "ocfs2 passed an invalid cluster stack label: \"%s\"\n", |
| 129 | stack_name); |
| 130 | return -EINVAL; |
| 131 | } |
| 132 | |
| 133 | /* Anything that isn't the classic stack is a user stack */ |
| 134 | if (strcmp(stack_name, OCFS2_STACK_PLUGIN_O2CB)) |
| 135 | plugin_name = OCFS2_STACK_PLUGIN_USER; |
| 136 | |
| 137 | rc = ocfs2_stack_driver_request(stack_name, plugin_name); |
Joel Becker | 286eaa9 | 2008-02-01 15:03:57 -0800 | [diff] [blame] | 138 | if (rc == -ENOENT) { |
Joel Becker | 9c6c877 | 2008-02-01 15:17:30 -0800 | [diff] [blame] | 139 | request_module("ocfs2_stack_%s", plugin_name); |
| 140 | rc = ocfs2_stack_driver_request(stack_name, plugin_name); |
Joel Becker | 286eaa9 | 2008-02-01 15:03:57 -0800 | [diff] [blame] | 141 | } |
| 142 | |
| 143 | if (rc == -ENOENT) { |
| 144 | printk(KERN_ERR |
| 145 | "ocfs2: Cluster stack driver \"%s\" cannot be found\n", |
Joel Becker | 9c6c877 | 2008-02-01 15:17:30 -0800 | [diff] [blame] | 146 | plugin_name); |
Joel Becker | 286eaa9 | 2008-02-01 15:03:57 -0800 | [diff] [blame] | 147 | } else if (rc == -EBUSY) { |
| 148 | printk(KERN_ERR |
Joel Becker | 9c6c877 | 2008-02-01 15:17:30 -0800 | [diff] [blame] | 149 | "ocfs2: A different cluster stack is in use\n"); |
Joel Becker | 286eaa9 | 2008-02-01 15:03:57 -0800 | [diff] [blame] | 150 | } |
| 151 | |
| 152 | return rc; |
| 153 | } |
| 154 | |
| 155 | static void ocfs2_stack_driver_put(void) |
| 156 | { |
| 157 | spin_lock(&ocfs2_stack_lock); |
| 158 | BUG_ON(active_stack == NULL); |
| 159 | BUG_ON(active_stack->sp_count == 0); |
| 160 | |
| 161 | active_stack->sp_count--; |
| 162 | if (!active_stack->sp_count) { |
| 163 | module_put(active_stack->sp_owner); |
| 164 | active_stack = NULL; |
| 165 | } |
| 166 | spin_unlock(&ocfs2_stack_lock); |
| 167 | } |
| 168 | |
| 169 | int ocfs2_stack_glue_register(struct ocfs2_stack_plugin *plugin) |
| 170 | { |
| 171 | int rc; |
| 172 | |
| 173 | spin_lock(&ocfs2_stack_lock); |
| 174 | if (!ocfs2_stack_lookup(plugin->sp_name)) { |
| 175 | plugin->sp_count = 0; |
| 176 | plugin->sp_proto = lproto; |
| 177 | list_add(&plugin->sp_list, &ocfs2_stack_list); |
| 178 | printk(KERN_INFO "ocfs2: Registered cluster interface %s\n", |
| 179 | plugin->sp_name); |
| 180 | rc = 0; |
| 181 | } else { |
| 182 | printk(KERN_ERR "ocfs2: Stack \"%s\" already registered\n", |
| 183 | plugin->sp_name); |
| 184 | rc = -EEXIST; |
| 185 | } |
| 186 | spin_unlock(&ocfs2_stack_lock); |
| 187 | |
| 188 | return rc; |
| 189 | } |
| 190 | EXPORT_SYMBOL_GPL(ocfs2_stack_glue_register); |
| 191 | |
| 192 | void ocfs2_stack_glue_unregister(struct ocfs2_stack_plugin *plugin) |
| 193 | { |
| 194 | struct ocfs2_stack_plugin *p; |
| 195 | |
| 196 | spin_lock(&ocfs2_stack_lock); |
| 197 | p = ocfs2_stack_lookup(plugin->sp_name); |
| 198 | if (p) { |
| 199 | BUG_ON(p != plugin); |
| 200 | BUG_ON(plugin == active_stack); |
| 201 | BUG_ON(plugin->sp_count != 0); |
| 202 | list_del_init(&plugin->sp_list); |
| 203 | printk(KERN_INFO "ocfs2: Unregistered cluster interface %s\n", |
| 204 | plugin->sp_name); |
| 205 | } else { |
| 206 | printk(KERN_ERR "Stack \"%s\" is not registered\n", |
| 207 | plugin->sp_name); |
| 208 | } |
| 209 | spin_unlock(&ocfs2_stack_lock); |
| 210 | } |
| 211 | EXPORT_SYMBOL_GPL(ocfs2_stack_glue_unregister); |
| 212 | |
| 213 | void ocfs2_stack_glue_set_locking_protocol(struct ocfs2_locking_protocol *proto) |
| 214 | { |
| 215 | struct ocfs2_stack_plugin *p; |
| 216 | |
| 217 | BUG_ON(proto == NULL); |
| 218 | |
| 219 | spin_lock(&ocfs2_stack_lock); |
| 220 | BUG_ON(active_stack != NULL); |
| 221 | |
| 222 | lproto = proto; |
| 223 | list_for_each_entry(p, &ocfs2_stack_list, sp_list) { |
| 224 | p->sp_proto = lproto; |
| 225 | } |
| 226 | |
| 227 | spin_unlock(&ocfs2_stack_lock); |
| 228 | } |
| 229 | EXPORT_SYMBOL_GPL(ocfs2_stack_glue_set_locking_protocol); |
Joel Becker | 24ef181 | 2008-01-29 17:37:32 -0800 | [diff] [blame] | 230 | |
Joel Becker | 24ef181 | 2008-01-29 17:37:32 -0800 | [diff] [blame] | 231 | |
David Teigland | cf4d8d7 | 2008-02-20 14:29:27 -0800 | [diff] [blame] | 232 | /* |
| 233 | * The ocfs2_dlm_lock() and ocfs2_dlm_unlock() functions take |
| 234 | * "struct ocfs2_lock_res *astarg" instead of "void *astarg" because the |
| 235 | * underlying stack plugins need to pilfer the lksb off of the lock_res. |
| 236 | * If some other structure needs to be passed as an astarg, the plugins |
| 237 | * will need to be given a different avenue to the lksb. |
| 238 | */ |
Joel Becker | 553aa7e | 2008-02-01 14:51:03 -0800 | [diff] [blame] | 239 | int ocfs2_dlm_lock(struct ocfs2_cluster_connection *conn, |
| 240 | int mode, |
| 241 | union ocfs2_dlm_lksb *lksb, |
| 242 | u32 flags, |
| 243 | void *name, |
| 244 | unsigned int namelen, |
David Teigland | cf4d8d7 | 2008-02-20 14:29:27 -0800 | [diff] [blame] | 245 | struct ocfs2_lock_res *astarg) |
Joel Becker | 553aa7e | 2008-02-01 14:51:03 -0800 | [diff] [blame] | 246 | { |
Joel Becker | 286eaa9 | 2008-02-01 15:03:57 -0800 | [diff] [blame] | 247 | BUG_ON(lproto == NULL); |
Joel Becker | 553aa7e | 2008-02-01 14:51:03 -0800 | [diff] [blame] | 248 | |
Joel Becker | 286eaa9 | 2008-02-01 15:03:57 -0800 | [diff] [blame] | 249 | return active_stack->sp_ops->dlm_lock(conn, mode, lksb, flags, |
| 250 | name, namelen, astarg); |
Joel Becker | 24ef181 | 2008-01-29 17:37:32 -0800 | [diff] [blame] | 251 | } |
Joel Becker | 286eaa9 | 2008-02-01 15:03:57 -0800 | [diff] [blame] | 252 | EXPORT_SYMBOL_GPL(ocfs2_dlm_lock); |
Joel Becker | 24ef181 | 2008-01-29 17:37:32 -0800 | [diff] [blame] | 253 | |
Joel Becker | 553aa7e | 2008-02-01 14:51:03 -0800 | [diff] [blame] | 254 | int ocfs2_dlm_unlock(struct ocfs2_cluster_connection *conn, |
| 255 | union ocfs2_dlm_lksb *lksb, |
| 256 | u32 flags, |
David Teigland | cf4d8d7 | 2008-02-20 14:29:27 -0800 | [diff] [blame] | 257 | struct ocfs2_lock_res *astarg) |
Joel Becker | 553aa7e | 2008-02-01 14:51:03 -0800 | [diff] [blame] | 258 | { |
Joel Becker | 286eaa9 | 2008-02-01 15:03:57 -0800 | [diff] [blame] | 259 | BUG_ON(lproto == NULL); |
Joel Becker | 553aa7e | 2008-02-01 14:51:03 -0800 | [diff] [blame] | 260 | |
Joel Becker | 286eaa9 | 2008-02-01 15:03:57 -0800 | [diff] [blame] | 261 | return active_stack->sp_ops->dlm_unlock(conn, lksb, flags, astarg); |
Joel Becker | 8f2c9c1 | 2008-02-01 12:16:57 -0800 | [diff] [blame] | 262 | } |
Joel Becker | 286eaa9 | 2008-02-01 15:03:57 -0800 | [diff] [blame] | 263 | EXPORT_SYMBOL_GPL(ocfs2_dlm_unlock); |
Joel Becker | 8f2c9c1 | 2008-02-01 12:16:57 -0800 | [diff] [blame] | 264 | |
Joel Becker | 553aa7e | 2008-02-01 14:51:03 -0800 | [diff] [blame] | 265 | int ocfs2_dlm_lock_status(union ocfs2_dlm_lksb *lksb) |
| 266 | { |
Joel Becker | 286eaa9 | 2008-02-01 15:03:57 -0800 | [diff] [blame] | 267 | return active_stack->sp_ops->lock_status(lksb); |
Joel Becker | 553aa7e | 2008-02-01 14:51:03 -0800 | [diff] [blame] | 268 | } |
Joel Becker | 286eaa9 | 2008-02-01 15:03:57 -0800 | [diff] [blame] | 269 | EXPORT_SYMBOL_GPL(ocfs2_dlm_lock_status); |
Joel Becker | 553aa7e | 2008-02-01 14:51:03 -0800 | [diff] [blame] | 270 | |
Joel Becker | 8f2c9c1 | 2008-02-01 12:16:57 -0800 | [diff] [blame] | 271 | /* |
| 272 | * Why don't we cast to ocfs2_meta_lvb? The "clean" answer is that we |
| 273 | * don't cast at the glue level. The real answer is that the header |
| 274 | * ordering is nigh impossible. |
| 275 | */ |
Joel Becker | 553aa7e | 2008-02-01 14:51:03 -0800 | [diff] [blame] | 276 | void *ocfs2_dlm_lvb(union ocfs2_dlm_lksb *lksb) |
| 277 | { |
Joel Becker | 286eaa9 | 2008-02-01 15:03:57 -0800 | [diff] [blame] | 278 | return active_stack->sp_ops->lock_lvb(lksb); |
Joel Becker | cf0acdc | 2008-01-29 16:59:55 -0800 | [diff] [blame] | 279 | } |
Joel Becker | 286eaa9 | 2008-02-01 15:03:57 -0800 | [diff] [blame] | 280 | EXPORT_SYMBOL_GPL(ocfs2_dlm_lvb); |
Joel Becker | cf0acdc | 2008-01-29 16:59:55 -0800 | [diff] [blame] | 281 | |
Joel Becker | 553aa7e | 2008-02-01 14:51:03 -0800 | [diff] [blame] | 282 | void ocfs2_dlm_dump_lksb(union ocfs2_dlm_lksb *lksb) |
| 283 | { |
Joel Becker | 286eaa9 | 2008-02-01 15:03:57 -0800 | [diff] [blame] | 284 | active_stack->sp_ops->dump_lksb(lksb); |
Joel Becker | 553aa7e | 2008-02-01 14:51:03 -0800 | [diff] [blame] | 285 | } |
Joel Becker | 286eaa9 | 2008-02-01 15:03:57 -0800 | [diff] [blame] | 286 | EXPORT_SYMBOL_GPL(ocfs2_dlm_dump_lksb); |
Joel Becker | 553aa7e | 2008-02-01 14:51:03 -0800 | [diff] [blame] | 287 | |
Joel Becker | 9c6c877 | 2008-02-01 15:17:30 -0800 | [diff] [blame] | 288 | int ocfs2_cluster_connect(const char *stack_name, |
| 289 | const char *group, |
Joel Becker | 4670c46 | 2008-02-01 14:39:35 -0800 | [diff] [blame] | 290 | int grouplen, |
| 291 | void (*recovery_handler)(int node_num, |
| 292 | void *recovery_data), |
| 293 | void *recovery_data, |
| 294 | struct ocfs2_cluster_connection **conn) |
| 295 | { |
| 296 | int rc = 0; |
| 297 | struct ocfs2_cluster_connection *new_conn; |
Joel Becker | 4670c46 | 2008-02-01 14:39:35 -0800 | [diff] [blame] | 298 | |
| 299 | BUG_ON(group == NULL); |
| 300 | BUG_ON(conn == NULL); |
| 301 | BUG_ON(recovery_handler == NULL); |
| 302 | |
| 303 | if (grouplen > GROUP_NAME_MAX) { |
| 304 | rc = -EINVAL; |
| 305 | goto out; |
| 306 | } |
| 307 | |
| 308 | new_conn = kzalloc(sizeof(struct ocfs2_cluster_connection), |
| 309 | GFP_KERNEL); |
| 310 | if (!new_conn) { |
| 311 | rc = -ENOMEM; |
| 312 | goto out; |
| 313 | } |
| 314 | |
| 315 | memcpy(new_conn->cc_name, group, grouplen); |
| 316 | new_conn->cc_namelen = grouplen; |
| 317 | new_conn->cc_recovery_handler = recovery_handler; |
| 318 | new_conn->cc_recovery_data = recovery_data; |
| 319 | |
| 320 | /* Start the new connection at our maximum compatibility level */ |
Joel Becker | 286eaa9 | 2008-02-01 15:03:57 -0800 | [diff] [blame] | 321 | new_conn->cc_version = lproto->lp_max_version; |
Joel Becker | 4670c46 | 2008-02-01 14:39:35 -0800 | [diff] [blame] | 322 | |
Joel Becker | 286eaa9 | 2008-02-01 15:03:57 -0800 | [diff] [blame] | 323 | /* This will pin the stack driver if successful */ |
Joel Becker | 9c6c877 | 2008-02-01 15:17:30 -0800 | [diff] [blame] | 324 | rc = ocfs2_stack_driver_get(stack_name); |
Joel Becker | 286eaa9 | 2008-02-01 15:03:57 -0800 | [diff] [blame] | 325 | if (rc) |
| 326 | goto out_free; |
| 327 | |
| 328 | rc = active_stack->sp_ops->connect(new_conn); |
Joel Becker | 553aa7e | 2008-02-01 14:51:03 -0800 | [diff] [blame] | 329 | if (rc) { |
Joel Becker | 286eaa9 | 2008-02-01 15:03:57 -0800 | [diff] [blame] | 330 | ocfs2_stack_driver_put(); |
Joel Becker | 4670c46 | 2008-02-01 14:39:35 -0800 | [diff] [blame] | 331 | goto out_free; |
| 332 | } |
| 333 | |
Joel Becker | 4670c46 | 2008-02-01 14:39:35 -0800 | [diff] [blame] | 334 | *conn = new_conn; |
| 335 | |
| 336 | out_free: |
Joel Becker | 553aa7e | 2008-02-01 14:51:03 -0800 | [diff] [blame] | 337 | if (rc) |
Joel Becker | 4670c46 | 2008-02-01 14:39:35 -0800 | [diff] [blame] | 338 | kfree(new_conn); |
Joel Becker | 4670c46 | 2008-02-01 14:39:35 -0800 | [diff] [blame] | 339 | |
| 340 | out: |
| 341 | return rc; |
| 342 | } |
Joel Becker | 286eaa9 | 2008-02-01 15:03:57 -0800 | [diff] [blame] | 343 | EXPORT_SYMBOL_GPL(ocfs2_cluster_connect); |
Joel Becker | 4670c46 | 2008-02-01 14:39:35 -0800 | [diff] [blame] | 344 | |
Joel Becker | 286eaa9 | 2008-02-01 15:03:57 -0800 | [diff] [blame] | 345 | /* If hangup_pending is 0, the stack driver will be dropped */ |
| 346 | int ocfs2_cluster_disconnect(struct ocfs2_cluster_connection *conn, |
| 347 | int hangup_pending) |
Joel Becker | 553aa7e | 2008-02-01 14:51:03 -0800 | [diff] [blame] | 348 | { |
| 349 | int ret; |
| 350 | |
| 351 | BUG_ON(conn == NULL); |
| 352 | |
Joel Becker | 286eaa9 | 2008-02-01 15:03:57 -0800 | [diff] [blame] | 353 | ret = active_stack->sp_ops->disconnect(conn, hangup_pending); |
Joel Becker | 553aa7e | 2008-02-01 14:51:03 -0800 | [diff] [blame] | 354 | |
| 355 | /* XXX Should we free it anyway? */ |
Joel Becker | 286eaa9 | 2008-02-01 15:03:57 -0800 | [diff] [blame] | 356 | if (!ret) { |
Joel Becker | 553aa7e | 2008-02-01 14:51:03 -0800 | [diff] [blame] | 357 | kfree(conn); |
Joel Becker | 286eaa9 | 2008-02-01 15:03:57 -0800 | [diff] [blame] | 358 | if (!hangup_pending) |
| 359 | ocfs2_stack_driver_put(); |
| 360 | } |
Joel Becker | 553aa7e | 2008-02-01 14:51:03 -0800 | [diff] [blame] | 361 | |
| 362 | return ret; |
| 363 | } |
Joel Becker | 286eaa9 | 2008-02-01 15:03:57 -0800 | [diff] [blame] | 364 | EXPORT_SYMBOL_GPL(ocfs2_cluster_disconnect); |
Joel Becker | 553aa7e | 2008-02-01 14:51:03 -0800 | [diff] [blame] | 365 | |
Joel Becker | 6953b4c | 2008-01-29 16:59:56 -0800 | [diff] [blame] | 366 | void ocfs2_cluster_hangup(const char *group, int grouplen) |
| 367 | { |
| 368 | BUG_ON(group == NULL); |
| 369 | BUG_ON(group[grouplen] != '\0'); |
| 370 | |
David Teigland | cf4d8d7 | 2008-02-20 14:29:27 -0800 | [diff] [blame] | 371 | if (active_stack->sp_ops->hangup) |
| 372 | active_stack->sp_ops->hangup(group, grouplen); |
Joel Becker | 286eaa9 | 2008-02-01 15:03:57 -0800 | [diff] [blame] | 373 | |
| 374 | /* cluster_disconnect() was called with hangup_pending==1 */ |
| 375 | ocfs2_stack_driver_put(); |
Joel Becker | 19fdb62 | 2008-01-30 15:38:24 -0800 | [diff] [blame] | 376 | } |
Joel Becker | 286eaa9 | 2008-02-01 15:03:57 -0800 | [diff] [blame] | 377 | EXPORT_SYMBOL_GPL(ocfs2_cluster_hangup); |
Joel Becker | 19fdb62 | 2008-01-30 15:38:24 -0800 | [diff] [blame] | 378 | |
Joel Becker | 553aa7e | 2008-02-01 14:51:03 -0800 | [diff] [blame] | 379 | int ocfs2_cluster_this_node(unsigned int *node) |
| 380 | { |
Joel Becker | 286eaa9 | 2008-02-01 15:03:57 -0800 | [diff] [blame] | 381 | return active_stack->sp_ops->this_node(node); |
Joel Becker | 553aa7e | 2008-02-01 14:51:03 -0800 | [diff] [blame] | 382 | } |
Joel Becker | 286eaa9 | 2008-02-01 15:03:57 -0800 | [diff] [blame] | 383 | EXPORT_SYMBOL_GPL(ocfs2_cluster_this_node); |
Joel Becker | 553aa7e | 2008-02-01 14:51:03 -0800 | [diff] [blame] | 384 | |
Joel Becker | 286eaa9 | 2008-02-01 15:03:57 -0800 | [diff] [blame] | 385 | |
Joel Becker | 74ae4e1 | 2008-01-31 23:56:17 -0800 | [diff] [blame] | 386 | /* |
| 387 | * Sysfs bits |
| 388 | */ |
| 389 | |
| 390 | static ssize_t ocfs2_max_locking_protocol_show(struct kobject *kobj, |
| 391 | struct kobj_attribute *attr, |
| 392 | char *buf) |
| 393 | { |
| 394 | ssize_t ret = 0; |
| 395 | |
| 396 | spin_lock(&ocfs2_stack_lock); |
| 397 | if (lproto) |
| 398 | ret = snprintf(buf, PAGE_SIZE, "%u.%u\n", |
| 399 | lproto->lp_max_version.pv_major, |
| 400 | lproto->lp_max_version.pv_minor); |
| 401 | spin_unlock(&ocfs2_stack_lock); |
| 402 | |
| 403 | return ret; |
| 404 | } |
| 405 | |
| 406 | static struct kobj_attribute ocfs2_attr_max_locking_protocol = |
| 407 | __ATTR(max_locking_protocol, S_IFREG | S_IRUGO, |
| 408 | ocfs2_max_locking_protocol_show, NULL); |
| 409 | |
| 410 | static ssize_t ocfs2_loaded_cluster_plugins_show(struct kobject *kobj, |
| 411 | struct kobj_attribute *attr, |
| 412 | char *buf) |
| 413 | { |
| 414 | ssize_t ret = 0, total = 0, remain = PAGE_SIZE; |
| 415 | struct ocfs2_stack_plugin *p; |
| 416 | |
| 417 | spin_lock(&ocfs2_stack_lock); |
| 418 | list_for_each_entry(p, &ocfs2_stack_list, sp_list) { |
| 419 | ret = snprintf(buf, remain, "%s\n", |
| 420 | p->sp_name); |
| 421 | if (ret < 0) { |
| 422 | total = ret; |
| 423 | break; |
| 424 | } |
| 425 | if (ret == remain) { |
| 426 | /* snprintf() didn't fit */ |
| 427 | total = -E2BIG; |
| 428 | break; |
| 429 | } |
| 430 | total += ret; |
| 431 | remain -= ret; |
| 432 | } |
| 433 | spin_unlock(&ocfs2_stack_lock); |
| 434 | |
| 435 | return total; |
| 436 | } |
| 437 | |
| 438 | static struct kobj_attribute ocfs2_attr_loaded_cluster_plugins = |
| 439 | __ATTR(loaded_cluster_plugins, S_IFREG | S_IRUGO, |
| 440 | ocfs2_loaded_cluster_plugins_show, NULL); |
| 441 | |
| 442 | static ssize_t ocfs2_active_cluster_plugin_show(struct kobject *kobj, |
| 443 | struct kobj_attribute *attr, |
| 444 | char *buf) |
| 445 | { |
| 446 | ssize_t ret = 0; |
| 447 | |
| 448 | spin_lock(&ocfs2_stack_lock); |
| 449 | if (active_stack) { |
| 450 | ret = snprintf(buf, PAGE_SIZE, "%s\n", |
| 451 | active_stack->sp_name); |
| 452 | if (ret == PAGE_SIZE) |
| 453 | ret = -E2BIG; |
| 454 | } |
| 455 | spin_unlock(&ocfs2_stack_lock); |
| 456 | |
| 457 | return ret; |
| 458 | } |
| 459 | |
| 460 | static struct kobj_attribute ocfs2_attr_active_cluster_plugin = |
| 461 | __ATTR(active_cluster_plugin, S_IFREG | S_IRUGO, |
| 462 | ocfs2_active_cluster_plugin_show, NULL); |
| 463 | |
Joel Becker | 9c6c877 | 2008-02-01 15:17:30 -0800 | [diff] [blame] | 464 | static ssize_t ocfs2_cluster_stack_show(struct kobject *kobj, |
| 465 | struct kobj_attribute *attr, |
| 466 | char *buf) |
| 467 | { |
| 468 | ssize_t ret; |
| 469 | spin_lock(&ocfs2_stack_lock); |
| 470 | ret = snprintf(buf, PAGE_SIZE, "%s\n", cluster_stack_name); |
| 471 | spin_unlock(&ocfs2_stack_lock); |
| 472 | |
| 473 | return ret; |
| 474 | } |
| 475 | |
| 476 | static ssize_t ocfs2_cluster_stack_store(struct kobject *kobj, |
| 477 | struct kobj_attribute *attr, |
| 478 | const char *buf, size_t count) |
| 479 | { |
| 480 | size_t len = count; |
| 481 | ssize_t ret; |
| 482 | |
| 483 | if (len == 0) |
| 484 | return len; |
| 485 | |
| 486 | if (buf[len - 1] == '\n') |
| 487 | len--; |
| 488 | |
| 489 | if ((len != OCFS2_STACK_LABEL_LEN) || |
| 490 | (strnlen(buf, len) != len)) |
| 491 | return -EINVAL; |
| 492 | |
| 493 | spin_lock(&ocfs2_stack_lock); |
| 494 | if (active_stack) { |
| 495 | if (!strncmp(buf, cluster_stack_name, len)) |
| 496 | ret = count; |
| 497 | else |
| 498 | ret = -EBUSY; |
| 499 | } else { |
| 500 | memcpy(cluster_stack_name, buf, len); |
| 501 | ret = count; |
| 502 | } |
| 503 | spin_unlock(&ocfs2_stack_lock); |
| 504 | |
| 505 | return ret; |
| 506 | } |
| 507 | |
| 508 | |
| 509 | static struct kobj_attribute ocfs2_attr_cluster_stack = |
| 510 | __ATTR(cluster_stack, S_IFREG | S_IRUGO | S_IWUSR, |
| 511 | ocfs2_cluster_stack_show, |
| 512 | ocfs2_cluster_stack_store); |
| 513 | |
Joel Becker | 74ae4e1 | 2008-01-31 23:56:17 -0800 | [diff] [blame] | 514 | static struct attribute *ocfs2_attrs[] = { |
| 515 | &ocfs2_attr_max_locking_protocol.attr, |
| 516 | &ocfs2_attr_loaded_cluster_plugins.attr, |
| 517 | &ocfs2_attr_active_cluster_plugin.attr, |
Joel Becker | 9c6c877 | 2008-02-01 15:17:30 -0800 | [diff] [blame] | 518 | &ocfs2_attr_cluster_stack.attr, |
Joel Becker | 74ae4e1 | 2008-01-31 23:56:17 -0800 | [diff] [blame] | 519 | NULL, |
| 520 | }; |
| 521 | |
| 522 | static struct attribute_group ocfs2_attr_group = { |
| 523 | .attrs = ocfs2_attrs, |
| 524 | }; |
| 525 | |
| 526 | static struct kset *ocfs2_kset; |
| 527 | |
| 528 | static void ocfs2_sysfs_exit(void) |
| 529 | { |
| 530 | kset_unregister(ocfs2_kset); |
| 531 | } |
| 532 | |
| 533 | static int ocfs2_sysfs_init(void) |
| 534 | { |
| 535 | int ret; |
| 536 | |
| 537 | ocfs2_kset = kset_create_and_add("ocfs2", NULL, fs_kobj); |
| 538 | if (!ocfs2_kset) |
| 539 | return -ENOMEM; |
| 540 | |
| 541 | ret = sysfs_create_group(&ocfs2_kset->kobj, &ocfs2_attr_group); |
| 542 | if (ret) |
| 543 | goto error; |
| 544 | |
| 545 | return 0; |
| 546 | |
| 547 | error: |
| 548 | kset_unregister(ocfs2_kset); |
| 549 | return ret; |
| 550 | } |
| 551 | |
Joel Becker | 3878f11 | 2008-05-30 15:30:49 -0700 | [diff] [blame^] | 552 | /* |
| 553 | * Sysctl bits |
| 554 | * |
| 555 | * The sysctl lives at /proc/sys/fs/ocfs2/nm/hb_ctl_path. The 'nm' doesn't |
| 556 | * make as much sense in a multiple cluster stack world, but it's safer |
| 557 | * and easier to preserve the name. |
| 558 | */ |
| 559 | |
| 560 | #define FS_OCFS2_NM 1 |
| 561 | |
| 562 | #define OCFS2_MAX_HB_CTL_PATH 256 |
| 563 | static char ocfs2_hb_ctl_path[OCFS2_MAX_HB_CTL_PATH] = "/sbin/ocfs2_hb_ctl"; |
| 564 | |
| 565 | static ctl_table ocfs2_nm_table[] = { |
| 566 | { |
| 567 | .ctl_name = 1, |
| 568 | .procname = "hb_ctl_path", |
| 569 | .data = ocfs2_hb_ctl_path, |
| 570 | .maxlen = OCFS2_MAX_HB_CTL_PATH, |
| 571 | .mode = 0644, |
| 572 | .proc_handler = &proc_dostring, |
| 573 | .strategy = &sysctl_string, |
| 574 | }, |
| 575 | { .ctl_name = 0 } |
| 576 | }; |
| 577 | |
| 578 | static ctl_table ocfs2_mod_table[] = { |
| 579 | { |
| 580 | .ctl_name = FS_OCFS2_NM, |
| 581 | .procname = "nm", |
| 582 | .data = NULL, |
| 583 | .maxlen = 0, |
| 584 | .mode = 0555, |
| 585 | .child = ocfs2_nm_table |
| 586 | }, |
| 587 | { .ctl_name = 0} |
| 588 | }; |
| 589 | |
| 590 | static ctl_table ocfs2_kern_table[] = { |
| 591 | { |
| 592 | .ctl_name = FS_OCFS2, |
| 593 | .procname = "ocfs2", |
| 594 | .data = NULL, |
| 595 | .maxlen = 0, |
| 596 | .mode = 0555, |
| 597 | .child = ocfs2_mod_table |
| 598 | }, |
| 599 | { .ctl_name = 0} |
| 600 | }; |
| 601 | |
| 602 | static ctl_table ocfs2_root_table[] = { |
| 603 | { |
| 604 | .ctl_name = CTL_FS, |
| 605 | .procname = "fs", |
| 606 | .data = NULL, |
| 607 | .maxlen = 0, |
| 608 | .mode = 0555, |
| 609 | .child = ocfs2_kern_table |
| 610 | }, |
| 611 | { .ctl_name = 0 } |
| 612 | }; |
| 613 | |
| 614 | static struct ctl_table_header *ocfs2_table_header = NULL; |
| 615 | |
| 616 | const char *ocfs2_get_hb_ctl_path(void) |
| 617 | { |
| 618 | return ocfs2_hb_ctl_path; |
| 619 | } |
| 620 | EXPORT_SYMBOL_GPL(ocfs2_get_hb_ctl_path); |
| 621 | |
| 622 | |
| 623 | /* |
| 624 | * Initialization |
| 625 | */ |
| 626 | |
Joel Becker | 286eaa9 | 2008-02-01 15:03:57 -0800 | [diff] [blame] | 627 | static int __init ocfs2_stack_glue_init(void) |
Joel Becker | 24ef181 | 2008-01-29 17:37:32 -0800 | [diff] [blame] | 628 | { |
Joel Becker | 9c6c877 | 2008-02-01 15:17:30 -0800 | [diff] [blame] | 629 | strcpy(cluster_stack_name, OCFS2_STACK_PLUGIN_O2CB); |
| 630 | |
Joel Becker | 3878f11 | 2008-05-30 15:30:49 -0700 | [diff] [blame^] | 631 | ocfs2_table_header = register_sysctl_table(ocfs2_root_table); |
| 632 | if (!ocfs2_table_header) { |
| 633 | printk(KERN_ERR |
| 634 | "ocfs2 stack glue: unable to register sysctl\n"); |
| 635 | return -ENOMEM; /* or something. */ |
| 636 | } |
| 637 | |
Joel Becker | 74ae4e1 | 2008-01-31 23:56:17 -0800 | [diff] [blame] | 638 | return ocfs2_sysfs_init(); |
Joel Becker | 24ef181 | 2008-01-29 17:37:32 -0800 | [diff] [blame] | 639 | } |
| 640 | |
Joel Becker | 286eaa9 | 2008-02-01 15:03:57 -0800 | [diff] [blame] | 641 | static void __exit ocfs2_stack_glue_exit(void) |
| 642 | { |
| 643 | lproto = NULL; |
Joel Becker | 74ae4e1 | 2008-01-31 23:56:17 -0800 | [diff] [blame] | 644 | ocfs2_sysfs_exit(); |
Joel Becker | 3878f11 | 2008-05-30 15:30:49 -0700 | [diff] [blame^] | 645 | if (ocfs2_table_header) |
| 646 | unregister_sysctl_table(ocfs2_table_header); |
Joel Becker | 286eaa9 | 2008-02-01 15:03:57 -0800 | [diff] [blame] | 647 | } |
| 648 | |
| 649 | MODULE_AUTHOR("Oracle"); |
| 650 | MODULE_DESCRIPTION("ocfs2 cluter stack glue layer"); |
| 651 | MODULE_LICENSE("GPL"); |
| 652 | module_init(ocfs2_stack_glue_init); |
| 653 | module_exit(ocfs2_stack_glue_exit); |