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