blob: d3867100aca8a5b02f0298d55168d624dd6e2d9e [file] [log] [blame]
Joel Becker8adf0532007-11-28 14:38:40 -08001/* -*- mode: c; c-basic-offset: 8; -*-
2 * vim: noexpandtab sw=8 ts=8 sts=0:
3 *
4 * stack_user.c
5 *
6 * Code which interfaces ocfs2 with fs/dlm and a userspace 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#include <linux/module.h>
Joel Becker6427a722008-02-18 19:23:28 -080021#include <linux/fs.h>
22#include <linux/miscdevice.h>
23#include <linux/mutex.h>
Tejun Heo5a0e3ad2010-03-24 17:04:11 +090024#include <linux/slab.h>
Joel Becker6427a722008-02-18 19:23:28 -080025#include <linux/reboot.h>
Joel Becker462c7e62008-02-18 19:40:12 -080026#include <asm/uaccess.h>
Joel Becker8adf0532007-11-28 14:38:40 -080027
28#include "stackglue.h"
29
Mark Fasheh53da4932008-07-21 14:29:16 -070030#include <linux/dlm_plock.h>
Joel Becker8adf0532007-11-28 14:38:40 -080031
Joel Becker6427a722008-02-18 19:23:28 -080032/*
33 * The control protocol starts with a handshake. Until the handshake
34 * is complete, the control device will fail all write(2)s.
35 *
36 * The handshake is simple. First, the client reads until EOF. Each line
37 * of output is a supported protocol tag. All protocol tags are a single
38 * character followed by a two hex digit version number. Currently the
39 * only things supported is T01, for "Text-base version 0x01". Next, the
Joel Beckerde870ef2008-02-18 17:07:09 -080040 * client writes the version they would like to use, including the newline.
41 * Thus, the protocol tag is 'T01\n'. If the version tag written is
42 * unknown, -EINVAL is returned. Once the negotiation is complete, the
43 * client can start sending messages.
44 *
Joel Beckerd4b95ee2008-02-20 15:39:44 -080045 * The T01 protocol has three messages. First is the "SETN" message.
Joel Becker3cfd4ab2008-02-20 14:44:34 -080046 * It has the following syntax:
47 *
48 * SETN<space><8-char-hex-nodenum><newline>
49 *
50 * This is 14 characters.
51 *
52 * The "SETN" message must be the first message following the protocol.
53 * It tells ocfs2_control the local node number.
54 *
Joel Beckerd4b95ee2008-02-20 15:39:44 -080055 * Next comes the "SETV" message. It has the following syntax:
56 *
57 * SETV<space><2-char-hex-major><space><2-char-hex-minor><newline>
58 *
59 * This is 11 characters.
60 *
61 * The "SETV" message sets the filesystem locking protocol version as
62 * negotiated by the client. The client negotiates based on the maximum
63 * version advertised in /sys/fs/ocfs2/max_locking_protocol. The major
64 * number from the "SETV" message must match
Joel Beckere603cfb2010-01-29 16:06:29 -080065 * ocfs2_user_plugin.sp_max_proto.pv_major, and the minor number
66 * must be less than or equal to ...sp_max_version.pv_minor.
Joel Beckerd4b95ee2008-02-20 15:39:44 -080067 *
68 * Once this information has been set, mounts will be allowed. From this
69 * point on, the "DOWN" message can be sent for node down notification.
70 * It has the following syntax:
Joel Beckerde870ef2008-02-18 17:07:09 -080071 *
72 * DOWN<space><32-char-cap-hex-uuid><space><8-char-hex-nodenum><newline>
73 *
74 * eg:
75 *
76 * DOWN 632A924FDD844190BDA93C0DF6B94899 00000001\n
77 *
78 * This is 47 characters.
Joel Becker6427a722008-02-18 19:23:28 -080079 */
80
81/*
Joel Becker462c7e62008-02-18 19:40:12 -080082 * Whether or not the client has done the handshake.
83 * For now, we have just one protocol version.
84 */
85#define OCFS2_CONTROL_PROTO "T01\n"
86#define OCFS2_CONTROL_PROTO_LEN 4
Joel Becker3cfd4ab2008-02-20 14:44:34 -080087
88/* Handshake states */
Joel Becker462c7e62008-02-18 19:40:12 -080089#define OCFS2_CONTROL_HANDSHAKE_INVALID (0)
90#define OCFS2_CONTROL_HANDSHAKE_READ (1)
Joel Becker3cfd4ab2008-02-20 14:44:34 -080091#define OCFS2_CONTROL_HANDSHAKE_PROTOCOL (2)
92#define OCFS2_CONTROL_HANDSHAKE_VALID (3)
93
94/* Messages */
95#define OCFS2_CONTROL_MESSAGE_OP_LEN 4
96#define OCFS2_CONTROL_MESSAGE_SETNODE_OP "SETN"
97#define OCFS2_CONTROL_MESSAGE_SETNODE_TOTAL_LEN 14
Joel Beckerd4b95ee2008-02-20 15:39:44 -080098#define OCFS2_CONTROL_MESSAGE_SETVERSION_OP "SETV"
99#define OCFS2_CONTROL_MESSAGE_SETVERSION_TOTAL_LEN 11
Joel Becker3cfd4ab2008-02-20 14:44:34 -0800100#define OCFS2_CONTROL_MESSAGE_DOWN_OP "DOWN"
Joel Beckerde870ef2008-02-18 17:07:09 -0800101#define OCFS2_CONTROL_MESSAGE_DOWN_TOTAL_LEN 47
102#define OCFS2_TEXT_UUID_LEN 32
Joel Beckerd4b95ee2008-02-20 15:39:44 -0800103#define OCFS2_CONTROL_MESSAGE_VERNUM_LEN 2
Joel Beckerde870ef2008-02-18 17:07:09 -0800104#define OCFS2_CONTROL_MESSAGE_NODENUM_LEN 8
Goldwyn Rodrigues41503632014-01-21 15:48:25 -0800105#define VERSION_LOCK "version_lock"
Joel Becker462c7e62008-02-18 19:40:12 -0800106
Goldwyn Rodrigues3e834152014-01-21 15:48:24 -0800107enum ocfs2_connection_type {
108 WITH_CONTROLD,
109 NO_CONTROLD
110};
111
Joel Becker462c7e62008-02-18 19:40:12 -0800112/*
Joel Becker6427a722008-02-18 19:23:28 -0800113 * ocfs2_live_connection is refcounted because the filesystem and
114 * miscdevice sides can detach in different order. Let's just be safe.
115 */
116struct ocfs2_live_connection {
117 struct list_head oc_list;
118 struct ocfs2_cluster_connection *oc_conn;
Goldwyn Rodrigues3e834152014-01-21 15:48:24 -0800119 enum ocfs2_connection_type oc_type;
Goldwyn Rodrigues66e188f2014-01-21 15:48:22 -0800120 atomic_t oc_this_node;
121 int oc_our_slot;
Goldwyn Rodrigues41503632014-01-21 15:48:25 -0800122 struct dlm_lksb oc_version_lksb;
123 char oc_lvb[DLM_LVB_LEN];
124 struct completion oc_sync_wait;
Joel Becker6427a722008-02-18 19:23:28 -0800125};
126
Joel Becker462c7e62008-02-18 19:40:12 -0800127struct ocfs2_control_private {
128 struct list_head op_list;
129 int op_state;
Joel Becker3cfd4ab2008-02-20 14:44:34 -0800130 int op_this_node;
Joel Beckerd4b95ee2008-02-20 15:39:44 -0800131 struct ocfs2_protocol_version op_proto;
Joel Becker3cfd4ab2008-02-20 14:44:34 -0800132};
133
134/* SETN<space><8-char-hex-nodenum><newline> */
135struct ocfs2_control_message_setn {
136 char tag[OCFS2_CONTROL_MESSAGE_OP_LEN];
137 char space;
138 char nodestr[OCFS2_CONTROL_MESSAGE_NODENUM_LEN];
139 char newline;
140};
141
Joel Beckerd4b95ee2008-02-20 15:39:44 -0800142/* SETV<space><2-char-hex-major><space><2-char-hex-minor><newline> */
143struct ocfs2_control_message_setv {
144 char tag[OCFS2_CONTROL_MESSAGE_OP_LEN];
145 char space1;
146 char major[OCFS2_CONTROL_MESSAGE_VERNUM_LEN];
147 char space2;
148 char minor[OCFS2_CONTROL_MESSAGE_VERNUM_LEN];
149 char newline;
150};
151
Joel Becker3cfd4ab2008-02-20 14:44:34 -0800152/* DOWN<space><32-char-cap-hex-uuid><space><8-char-hex-nodenum><newline> */
153struct ocfs2_control_message_down {
154 char tag[OCFS2_CONTROL_MESSAGE_OP_LEN];
155 char space1;
156 char uuid[OCFS2_TEXT_UUID_LEN];
157 char space2;
158 char nodestr[OCFS2_CONTROL_MESSAGE_NODENUM_LEN];
159 char newline;
160};
161
162union ocfs2_control_message {
163 char tag[OCFS2_CONTROL_MESSAGE_OP_LEN];
164 struct ocfs2_control_message_setn u_setn;
Joel Beckerd4b95ee2008-02-20 15:39:44 -0800165 struct ocfs2_control_message_setv u_setv;
Joel Becker3cfd4ab2008-02-20 14:44:34 -0800166 struct ocfs2_control_message_down u_down;
Joel Becker462c7e62008-02-18 19:40:12 -0800167};
168
Joel Beckera12630b2008-05-09 18:49:29 -0700169static struct ocfs2_stack_plugin ocfs2_user_plugin;
David Teiglandcf4d8d72008-02-20 14:29:27 -0800170
Joel Becker6427a722008-02-18 19:23:28 -0800171static atomic_t ocfs2_control_opened;
Joel Becker3cfd4ab2008-02-20 14:44:34 -0800172static int ocfs2_control_this_node = -1;
Joel Beckerd4b95ee2008-02-20 15:39:44 -0800173static struct ocfs2_protocol_version running_proto;
Joel Becker6427a722008-02-18 19:23:28 -0800174
175static LIST_HEAD(ocfs2_live_connection_list);
Joel Becker462c7e62008-02-18 19:40:12 -0800176static LIST_HEAD(ocfs2_control_private_list);
Joel Becker6427a722008-02-18 19:23:28 -0800177static DEFINE_MUTEX(ocfs2_control_lock);
178
Joel Becker462c7e62008-02-18 19:40:12 -0800179static inline void ocfs2_control_set_handshake_state(struct file *file,
180 int state)
181{
182 struct ocfs2_control_private *p = file->private_data;
183 p->op_state = state;
184}
185
186static inline int ocfs2_control_get_handshake_state(struct file *file)
187{
188 struct ocfs2_control_private *p = file->private_data;
189 return p->op_state;
190}
191
Joel Becker6427a722008-02-18 19:23:28 -0800192static struct ocfs2_live_connection *ocfs2_connection_find(const char *name)
193{
194 size_t len = strlen(name);
195 struct ocfs2_live_connection *c;
196
197 BUG_ON(!mutex_is_locked(&ocfs2_control_lock));
198
199 list_for_each_entry(c, &ocfs2_live_connection_list, oc_list) {
200 if ((c->oc_conn->cc_namelen == len) &&
201 !strncmp(c->oc_conn->cc_name, name, len))
202 return c;
203 }
204
dann frazier226291a2010-11-18 15:03:09 -0700205 return NULL;
Joel Becker6427a722008-02-18 19:23:28 -0800206}
207
208/*
209 * ocfs2_live_connection structures are created underneath the ocfs2
210 * mount path. Since the VFS prevents multiple calls to
211 * fill_super(), we can't get dupes here.
212 */
Goldwyn Rodrigues24aa3382014-01-21 15:48:23 -0800213static int ocfs2_live_connection_attach(struct ocfs2_cluster_connection *conn,
214 struct ocfs2_live_connection *c)
Joel Becker6427a722008-02-18 19:23:28 -0800215{
216 int rc = 0;
Joel Becker6427a722008-02-18 19:23:28 -0800217
218 mutex_lock(&ocfs2_control_lock);
219 c->oc_conn = conn;
220
221 if (atomic_read(&ocfs2_control_opened))
222 list_add(&c->oc_list, &ocfs2_live_connection_list);
223 else {
224 printk(KERN_ERR
225 "ocfs2: Userspace control daemon is not present\n");
226 rc = -ESRCH;
227 }
228
229 mutex_unlock(&ocfs2_control_lock);
Joel Becker6427a722008-02-18 19:23:28 -0800230 return rc;
231}
232
233/*
234 * This function disconnects the cluster connection from ocfs2_control.
235 * Afterwards, userspace can't affect the cluster connection.
236 */
237static void ocfs2_live_connection_drop(struct ocfs2_live_connection *c)
238{
239 mutex_lock(&ocfs2_control_lock);
240 list_del_init(&c->oc_list);
241 c->oc_conn = NULL;
242 mutex_unlock(&ocfs2_control_lock);
243
244 kfree(c);
245}
246
Joel Becker3cfd4ab2008-02-20 14:44:34 -0800247static int ocfs2_control_cfu(void *target, size_t target_len,
248 const char __user *buf, size_t count)
Joel Becker462c7e62008-02-18 19:40:12 -0800249{
250 /* The T01 expects write(2) calls to have exactly one command */
Joel Becker3cfd4ab2008-02-20 14:44:34 -0800251 if ((count != target_len) ||
252 (count > sizeof(union ocfs2_control_message)))
Joel Becker462c7e62008-02-18 19:40:12 -0800253 return -EINVAL;
254
255 if (copy_from_user(target, buf, target_len))
256 return -EFAULT;
257
Joel Becker3cfd4ab2008-02-20 14:44:34 -0800258 return 0;
Joel Becker462c7e62008-02-18 19:40:12 -0800259}
260
Joel Becker3cfd4ab2008-02-20 14:44:34 -0800261static ssize_t ocfs2_control_validate_protocol(struct file *file,
262 const char __user *buf,
263 size_t count)
Joel Becker462c7e62008-02-18 19:40:12 -0800264{
265 ssize_t ret;
266 char kbuf[OCFS2_CONTROL_PROTO_LEN];
267
268 ret = ocfs2_control_cfu(kbuf, OCFS2_CONTROL_PROTO_LEN,
269 buf, count);
Joel Becker3cfd4ab2008-02-20 14:44:34 -0800270 if (ret)
Joel Becker462c7e62008-02-18 19:40:12 -0800271 return ret;
272
273 if (strncmp(kbuf, OCFS2_CONTROL_PROTO, OCFS2_CONTROL_PROTO_LEN))
274 return -EINVAL;
275
Joel Becker462c7e62008-02-18 19:40:12 -0800276 ocfs2_control_set_handshake_state(file,
Joel Becker3cfd4ab2008-02-20 14:44:34 -0800277 OCFS2_CONTROL_HANDSHAKE_PROTOCOL);
Joel Becker462c7e62008-02-18 19:40:12 -0800278
279 return count;
280}
281
Joel Beckerde870ef2008-02-18 17:07:09 -0800282static void ocfs2_control_send_down(const char *uuid,
283 int nodenum)
284{
285 struct ocfs2_live_connection *c;
286
287 mutex_lock(&ocfs2_control_lock);
288
289 c = ocfs2_connection_find(uuid);
290 if (c) {
291 BUG_ON(c->oc_conn == NULL);
292 c->oc_conn->cc_recovery_handler(nodenum,
293 c->oc_conn->cc_recovery_data);
294 }
295
296 mutex_unlock(&ocfs2_control_lock);
297}
298
Joel Becker3cfd4ab2008-02-20 14:44:34 -0800299/*
300 * Called whenever configuration elements are sent to /dev/ocfs2_control.
301 * If all configuration elements are present, try to set the global
Joel Beckerd4b95ee2008-02-20 15:39:44 -0800302 * values. If there is a problem, return an error. Skip any missing
303 * elements, and only bump ocfs2_control_opened when we have all elements
304 * and are successful.
Joel Becker3cfd4ab2008-02-20 14:44:34 -0800305 */
306static int ocfs2_control_install_private(struct file *file)
Joel Beckerde870ef2008-02-18 17:07:09 -0800307{
Joel Becker3cfd4ab2008-02-20 14:44:34 -0800308 int rc = 0;
309 int set_p = 1;
310 struct ocfs2_control_private *p = file->private_data;
311
312 BUG_ON(p->op_state != OCFS2_CONTROL_HANDSHAKE_PROTOCOL);
313
Joel Becker3cfd4ab2008-02-20 14:44:34 -0800314 mutex_lock(&ocfs2_control_lock);
Joel Beckerd4b95ee2008-02-20 15:39:44 -0800315
316 if (p->op_this_node < 0) {
317 set_p = 0;
318 } else if ((ocfs2_control_this_node >= 0) &&
319 (ocfs2_control_this_node != p->op_this_node)) {
Joel Becker3cfd4ab2008-02-20 14:44:34 -0800320 rc = -EINVAL;
Joel Beckerd4b95ee2008-02-20 15:39:44 -0800321 goto out_unlock;
322 }
323
324 if (!p->op_proto.pv_major) {
325 set_p = 0;
326 } else if (!list_empty(&ocfs2_live_connection_list) &&
327 ((running_proto.pv_major != p->op_proto.pv_major) ||
328 (running_proto.pv_minor != p->op_proto.pv_minor))) {
329 rc = -EINVAL;
330 goto out_unlock;
331 }
332
333 if (set_p) {
334 ocfs2_control_this_node = p->op_this_node;
335 running_proto.pv_major = p->op_proto.pv_major;
336 running_proto.pv_minor = p->op_proto.pv_minor;
337 }
338
339out_unlock:
Joel Becker3cfd4ab2008-02-20 14:44:34 -0800340 mutex_unlock(&ocfs2_control_lock);
341
342 if (!rc && set_p) {
343 /* We set the global values successfully */
344 atomic_inc(&ocfs2_control_opened);
345 ocfs2_control_set_handshake_state(file,
346 OCFS2_CONTROL_HANDSHAKE_VALID);
347 }
348
349 return rc;
350}
351
David Teiglandcf4d8d72008-02-20 14:29:27 -0800352static int ocfs2_control_get_this_node(void)
353{
354 int rc;
355
356 mutex_lock(&ocfs2_control_lock);
357 if (ocfs2_control_this_node < 0)
358 rc = -EINVAL;
359 else
360 rc = ocfs2_control_this_node;
361 mutex_unlock(&ocfs2_control_lock);
362
363 return rc;
364}
365
Joel Becker3cfd4ab2008-02-20 14:44:34 -0800366static int ocfs2_control_do_setnode_msg(struct file *file,
367 struct ocfs2_control_message_setn *msg)
368{
Joel Beckerde870ef2008-02-18 17:07:09 -0800369 long nodenum;
Joel Becker3cfd4ab2008-02-20 14:44:34 -0800370 char *ptr = NULL;
371 struct ocfs2_control_private *p = file->private_data;
Joel Beckerde870ef2008-02-18 17:07:09 -0800372
Joel Becker3cfd4ab2008-02-20 14:44:34 -0800373 if (ocfs2_control_get_handshake_state(file) !=
374 OCFS2_CONTROL_HANDSHAKE_PROTOCOL)
Joel Beckerde870ef2008-02-18 17:07:09 -0800375 return -EINVAL;
376
Joel Becker3cfd4ab2008-02-20 14:44:34 -0800377 if (strncmp(msg->tag, OCFS2_CONTROL_MESSAGE_SETNODE_OP,
378 OCFS2_CONTROL_MESSAGE_OP_LEN))
Joel Beckerde870ef2008-02-18 17:07:09 -0800379 return -EINVAL;
Joel Beckerde870ef2008-02-18 17:07:09 -0800380
Joel Becker3cfd4ab2008-02-20 14:44:34 -0800381 if ((msg->space != ' ') || (msg->newline != '\n'))
382 return -EINVAL;
383 msg->space = msg->newline = '\0';
384
385 nodenum = simple_strtol(msg->nodestr, &ptr, 16);
386 if (!ptr || *ptr)
387 return -EINVAL;
388
389 if ((nodenum == LONG_MIN) || (nodenum == LONG_MAX) ||
390 (nodenum > INT_MAX) || (nodenum < 0))
391 return -ERANGE;
392 p->op_this_node = nodenum;
393
394 return ocfs2_control_install_private(file);
395}
396
Joel Beckerd4b95ee2008-02-20 15:39:44 -0800397static int ocfs2_control_do_setversion_msg(struct file *file,
398 struct ocfs2_control_message_setv *msg)
399 {
400 long major, minor;
401 char *ptr = NULL;
402 struct ocfs2_control_private *p = file->private_data;
403 struct ocfs2_protocol_version *max =
Joel Beckere603cfb2010-01-29 16:06:29 -0800404 &ocfs2_user_plugin.sp_max_proto;
Joel Beckerd4b95ee2008-02-20 15:39:44 -0800405
406 if (ocfs2_control_get_handshake_state(file) !=
407 OCFS2_CONTROL_HANDSHAKE_PROTOCOL)
408 return -EINVAL;
409
410 if (strncmp(msg->tag, OCFS2_CONTROL_MESSAGE_SETVERSION_OP,
411 OCFS2_CONTROL_MESSAGE_OP_LEN))
412 return -EINVAL;
413
414 if ((msg->space1 != ' ') || (msg->space2 != ' ') ||
415 (msg->newline != '\n'))
416 return -EINVAL;
417 msg->space1 = msg->space2 = msg->newline = '\0';
418
419 major = simple_strtol(msg->major, &ptr, 16);
420 if (!ptr || *ptr)
421 return -EINVAL;
422 minor = simple_strtol(msg->minor, &ptr, 16);
423 if (!ptr || *ptr)
424 return -EINVAL;
425
426 /*
427 * The major must be between 1 and 255, inclusive. The minor
428 * must be between 0 and 255, inclusive. The version passed in
429 * must be within the maximum version supported by the filesystem.
430 */
431 if ((major == LONG_MIN) || (major == LONG_MAX) ||
432 (major > (u8)-1) || (major < 1))
433 return -ERANGE;
434 if ((minor == LONG_MIN) || (minor == LONG_MAX) ||
435 (minor > (u8)-1) || (minor < 0))
436 return -ERANGE;
437 if ((major != max->pv_major) ||
438 (minor > max->pv_minor))
439 return -EINVAL;
440
441 p->op_proto.pv_major = major;
442 p->op_proto.pv_minor = minor;
443
444 return ocfs2_control_install_private(file);
445}
446
Joel Becker3cfd4ab2008-02-20 14:44:34 -0800447static int ocfs2_control_do_down_msg(struct file *file,
448 struct ocfs2_control_message_down *msg)
449{
450 long nodenum;
451 char *p = NULL;
452
453 if (ocfs2_control_get_handshake_state(file) !=
454 OCFS2_CONTROL_HANDSHAKE_VALID)
455 return -EINVAL;
456
457 if (strncmp(msg->tag, OCFS2_CONTROL_MESSAGE_DOWN_OP,
458 OCFS2_CONTROL_MESSAGE_OP_LEN))
459 return -EINVAL;
460
461 if ((msg->space1 != ' ') || (msg->space2 != ' ') ||
462 (msg->newline != '\n'))
463 return -EINVAL;
464 msg->space1 = msg->space2 = msg->newline = '\0';
465
466 nodenum = simple_strtol(msg->nodestr, &p, 16);
Joel Beckerde870ef2008-02-18 17:07:09 -0800467 if (!p || *p)
468 return -EINVAL;
469
470 if ((nodenum == LONG_MIN) || (nodenum == LONG_MAX) ||
471 (nodenum > INT_MAX) || (nodenum < 0))
472 return -ERANGE;
473
Joel Becker3cfd4ab2008-02-20 14:44:34 -0800474 ocfs2_control_send_down(msg->uuid, nodenum);
Joel Beckerde870ef2008-02-18 17:07:09 -0800475
Joel Becker3cfd4ab2008-02-20 14:44:34 -0800476 return 0;
477}
478
479static ssize_t ocfs2_control_message(struct file *file,
480 const char __user *buf,
481 size_t count)
482{
483 ssize_t ret;
484 union ocfs2_control_message msg;
485
486 /* Try to catch padding issues */
487 WARN_ON(offsetof(struct ocfs2_control_message_down, uuid) !=
488 (sizeof(msg.u_down.tag) + sizeof(msg.u_down.space1)));
489
490 memset(&msg, 0, sizeof(union ocfs2_control_message));
491 ret = ocfs2_control_cfu(&msg, count, buf, count);
492 if (ret)
493 goto out;
494
495 if ((count == OCFS2_CONTROL_MESSAGE_SETNODE_TOTAL_LEN) &&
496 !strncmp(msg.tag, OCFS2_CONTROL_MESSAGE_SETNODE_OP,
497 OCFS2_CONTROL_MESSAGE_OP_LEN))
498 ret = ocfs2_control_do_setnode_msg(file, &msg.u_setn);
Joel Beckerd4b95ee2008-02-20 15:39:44 -0800499 else if ((count == OCFS2_CONTROL_MESSAGE_SETVERSION_TOTAL_LEN) &&
500 !strncmp(msg.tag, OCFS2_CONTROL_MESSAGE_SETVERSION_OP,
501 OCFS2_CONTROL_MESSAGE_OP_LEN))
502 ret = ocfs2_control_do_setversion_msg(file, &msg.u_setv);
Joel Becker3cfd4ab2008-02-20 14:44:34 -0800503 else if ((count == OCFS2_CONTROL_MESSAGE_DOWN_TOTAL_LEN) &&
504 !strncmp(msg.tag, OCFS2_CONTROL_MESSAGE_DOWN_OP,
505 OCFS2_CONTROL_MESSAGE_OP_LEN))
506 ret = ocfs2_control_do_down_msg(file, &msg.u_down);
507 else
508 ret = -EINVAL;
509
510out:
511 return ret ? ret : count;
Joel Beckerde870ef2008-02-18 17:07:09 -0800512}
Joel Becker6427a722008-02-18 19:23:28 -0800513
514static ssize_t ocfs2_control_write(struct file *file,
515 const char __user *buf,
516 size_t count,
517 loff_t *ppos)
Joel Becker8adf0532007-11-28 14:38:40 -0800518{
Joel Becker462c7e62008-02-18 19:40:12 -0800519 ssize_t ret;
520
521 switch (ocfs2_control_get_handshake_state(file)) {
522 case OCFS2_CONTROL_HANDSHAKE_INVALID:
523 ret = -EINVAL;
524 break;
525
526 case OCFS2_CONTROL_HANDSHAKE_READ:
Joel Becker3cfd4ab2008-02-20 14:44:34 -0800527 ret = ocfs2_control_validate_protocol(file, buf,
528 count);
Joel Becker462c7e62008-02-18 19:40:12 -0800529 break;
530
Joel Becker3cfd4ab2008-02-20 14:44:34 -0800531 case OCFS2_CONTROL_HANDSHAKE_PROTOCOL:
Joel Becker462c7e62008-02-18 19:40:12 -0800532 case OCFS2_CONTROL_HANDSHAKE_VALID:
Joel Beckerde870ef2008-02-18 17:07:09 -0800533 ret = ocfs2_control_message(file, buf, count);
Joel Becker462c7e62008-02-18 19:40:12 -0800534 break;
535
536 default:
537 BUG();
538 ret = -EIO;
539 break;
540 }
541
542 return ret;
Joel Becker8adf0532007-11-28 14:38:40 -0800543}
544
Joel Becker462c7e62008-02-18 19:40:12 -0800545/*
546 * This is a naive version. If we ever have a new protocol, we'll expand
547 * it. Probably using seq_file.
548 */
Joel Becker6427a722008-02-18 19:23:28 -0800549static ssize_t ocfs2_control_read(struct file *file,
550 char __user *buf,
551 size_t count,
552 loff_t *ppos)
553{
Akinobu Mita7600c722008-06-09 16:34:23 -0700554 ssize_t ret;
Joel Becker462c7e62008-02-18 19:40:12 -0800555
Akinobu Mita7600c722008-06-09 16:34:23 -0700556 ret = simple_read_from_buffer(buf, count, ppos,
557 OCFS2_CONTROL_PROTO, OCFS2_CONTROL_PROTO_LEN);
Joel Becker462c7e62008-02-18 19:40:12 -0800558
559 /* Have we read the whole protocol list? */
Akinobu Mita7600c722008-06-09 16:34:23 -0700560 if (ret > 0 && *ppos >= OCFS2_CONTROL_PROTO_LEN)
Joel Becker462c7e62008-02-18 19:40:12 -0800561 ocfs2_control_set_handshake_state(file,
562 OCFS2_CONTROL_HANDSHAKE_READ);
563
Akinobu Mita7600c722008-06-09 16:34:23 -0700564 return ret;
Joel Becker6427a722008-02-18 19:23:28 -0800565}
566
567static int ocfs2_control_release(struct inode *inode, struct file *file)
568{
Joel Becker462c7e62008-02-18 19:40:12 -0800569 struct ocfs2_control_private *p = file->private_data;
570
571 mutex_lock(&ocfs2_control_lock);
572
573 if (ocfs2_control_get_handshake_state(file) !=
574 OCFS2_CONTROL_HANDSHAKE_VALID)
575 goto out;
576
Joel Becker6427a722008-02-18 19:23:28 -0800577 if (atomic_dec_and_test(&ocfs2_control_opened)) {
Joel Becker6427a722008-02-18 19:23:28 -0800578 if (!list_empty(&ocfs2_live_connection_list)) {
579 /* XXX: Do bad things! */
580 printk(KERN_ERR
581 "ocfs2: Unexpected release of ocfs2_control!\n"
582 " Loss of cluster connection requires "
583 "an emergency restart!\n");
584 emergency_restart();
585 }
Joel Beckerd4b95ee2008-02-20 15:39:44 -0800586 /*
587 * Last valid close clears the node number and resets
588 * the locking protocol version
589 */
Joel Becker3cfd4ab2008-02-20 14:44:34 -0800590 ocfs2_control_this_node = -1;
Joel Beckerd4b95ee2008-02-20 15:39:44 -0800591 running_proto.pv_major = 0;
592 running_proto.pv_major = 0;
Joel Becker6427a722008-02-18 19:23:28 -0800593 }
594
Joel Becker462c7e62008-02-18 19:40:12 -0800595out:
596 list_del_init(&p->op_list);
597 file->private_data = NULL;
598
599 mutex_unlock(&ocfs2_control_lock);
600
601 kfree(p);
602
Joel Becker6427a722008-02-18 19:23:28 -0800603 return 0;
604}
605
606static int ocfs2_control_open(struct inode *inode, struct file *file)
607{
Joel Becker462c7e62008-02-18 19:40:12 -0800608 struct ocfs2_control_private *p;
609
610 p = kzalloc(sizeof(struct ocfs2_control_private), GFP_KERNEL);
611 if (!p)
612 return -ENOMEM;
Joel Becker3cfd4ab2008-02-20 14:44:34 -0800613 p->op_this_node = -1;
Joel Becker462c7e62008-02-18 19:40:12 -0800614
615 mutex_lock(&ocfs2_control_lock);
616 file->private_data = p;
617 list_add(&p->op_list, &ocfs2_control_private_list);
618 mutex_unlock(&ocfs2_control_lock);
Joel Becker6427a722008-02-18 19:23:28 -0800619
620 return 0;
621}
622
623static const struct file_operations ocfs2_control_fops = {
624 .open = ocfs2_control_open,
625 .release = ocfs2_control_release,
626 .read = ocfs2_control_read,
627 .write = ocfs2_control_write,
628 .owner = THIS_MODULE,
Arnd Bergmann6038f372010-08-15 18:52:59 +0200629 .llseek = default_llseek,
Joel Becker6427a722008-02-18 19:23:28 -0800630};
631
Adrian Bunk4d8755b2008-04-21 11:49:26 +0300632static struct miscdevice ocfs2_control_device = {
Joel Becker6427a722008-02-18 19:23:28 -0800633 .minor = MISC_DYNAMIC_MINOR,
634 .name = "ocfs2_control",
635 .fops = &ocfs2_control_fops,
636};
637
638static int ocfs2_control_init(void)
639{
640 int rc;
641
642 atomic_set(&ocfs2_control_opened, 0);
643
644 rc = misc_register(&ocfs2_control_device);
645 if (rc)
646 printk(KERN_ERR
647 "ocfs2: Unable to register ocfs2_control device "
648 "(errno %d)\n",
649 -rc);
650
651 return rc;
652}
653
654static void ocfs2_control_exit(void)
655{
656 int rc;
657
658 rc = misc_deregister(&ocfs2_control_device);
659 if (rc)
660 printk(KERN_ERR
661 "ocfs2: Unable to deregister ocfs2_control device "
662 "(errno %d)\n",
663 -rc);
664}
665
David Teiglandcf4d8d72008-02-20 14:29:27 -0800666static void fsdlm_lock_ast_wrapper(void *astarg)
667{
Joel Beckerc0e41332010-01-29 14:46:44 -0800668 struct ocfs2_dlm_lksb *lksb = astarg;
Joel Beckera796d282010-01-28 19:22:39 -0800669 int status = lksb->lksb_fsdlm.sb_status;
David Teiglandcf4d8d72008-02-20 14:29:27 -0800670
David Teiglandcf4d8d72008-02-20 14:29:27 -0800671 /*
672 * For now we're punting on the issue of other non-standard errors
673 * where we can't tell if the unlock_ast or lock_ast should be called.
674 * The main "other error" that's possible is EINVAL which means the
675 * function was called with invalid args, which shouldn't be possible
676 * since the caller here is under our control. Other non-standard
677 * errors probably fall into the same category, or otherwise are fatal
678 * which means we can't carry on anyway.
679 */
680
681 if (status == -DLM_EUNLOCK || status == -DLM_ECANCEL)
Joel Becker110946c2010-01-29 15:46:23 -0800682 lksb->lksb_conn->cc_proto->lp_unlock_ast(lksb, 0);
David Teiglandcf4d8d72008-02-20 14:29:27 -0800683 else
Joel Becker110946c2010-01-29 15:46:23 -0800684 lksb->lksb_conn->cc_proto->lp_lock_ast(lksb);
David Teiglandcf4d8d72008-02-20 14:29:27 -0800685}
686
687static void fsdlm_blocking_ast_wrapper(void *astarg, int level)
688{
Joel Beckerc0e41332010-01-29 14:46:44 -0800689 struct ocfs2_dlm_lksb *lksb = astarg;
Joel Beckera796d282010-01-28 19:22:39 -0800690
Joel Becker110946c2010-01-29 15:46:23 -0800691 lksb->lksb_conn->cc_proto->lp_blocking_ast(lksb, level);
David Teiglandcf4d8d72008-02-20 14:29:27 -0800692}
693
694static int user_dlm_lock(struct ocfs2_cluster_connection *conn,
695 int mode,
Joel Beckerc0e41332010-01-29 14:46:44 -0800696 struct ocfs2_dlm_lksb *lksb,
David Teiglandcf4d8d72008-02-20 14:29:27 -0800697 u32 flags,
698 void *name,
Joel Beckera796d282010-01-28 19:22:39 -0800699 unsigned int namelen)
David Teiglandcf4d8d72008-02-20 14:29:27 -0800700{
701 int ret;
702
703 if (!lksb->lksb_fsdlm.sb_lvbptr)
704 lksb->lksb_fsdlm.sb_lvbptr = (char *)lksb +
705 sizeof(struct dlm_lksb);
706
707 ret = dlm_lock(conn->cc_lockspace, mode, &lksb->lksb_fsdlm,
708 flags|DLM_LKF_NODLCKWT, name, namelen, 0,
Joel Beckera796d282010-01-28 19:22:39 -0800709 fsdlm_lock_ast_wrapper, lksb,
David Teiglandcf4d8d72008-02-20 14:29:27 -0800710 fsdlm_blocking_ast_wrapper);
711 return ret;
712}
713
714static int user_dlm_unlock(struct ocfs2_cluster_connection *conn,
Joel Beckerc0e41332010-01-29 14:46:44 -0800715 struct ocfs2_dlm_lksb *lksb,
Joel Beckera796d282010-01-28 19:22:39 -0800716 u32 flags)
David Teiglandcf4d8d72008-02-20 14:29:27 -0800717{
718 int ret;
719
720 ret = dlm_unlock(conn->cc_lockspace, lksb->lksb_fsdlm.sb_lkid,
Joel Beckera796d282010-01-28 19:22:39 -0800721 flags, &lksb->lksb_fsdlm, lksb);
David Teiglandcf4d8d72008-02-20 14:29:27 -0800722 return ret;
723}
724
Joel Beckerc0e41332010-01-29 14:46:44 -0800725static int user_dlm_lock_status(struct ocfs2_dlm_lksb *lksb)
David Teiglandcf4d8d72008-02-20 14:29:27 -0800726{
727 return lksb->lksb_fsdlm.sb_status;
728}
729
Joel Beckerc0e41332010-01-29 14:46:44 -0800730static int user_dlm_lvb_valid(struct ocfs2_dlm_lksb *lksb)
Joel Becker1c520df2009-06-19 15:14:13 -0700731{
732 int invalid = lksb->lksb_fsdlm.sb_flags & DLM_SBF_VALNOTVALID;
733
734 return !invalid;
735}
736
Joel Beckerc0e41332010-01-29 14:46:44 -0800737static void *user_dlm_lvb(struct ocfs2_dlm_lksb *lksb)
David Teiglandcf4d8d72008-02-20 14:29:27 -0800738{
David Teigland66f502a2008-11-10 16:24:57 -0600739 if (!lksb->lksb_fsdlm.sb_lvbptr)
740 lksb->lksb_fsdlm.sb_lvbptr = (char *)lksb +
741 sizeof(struct dlm_lksb);
David Teiglandcf4d8d72008-02-20 14:29:27 -0800742 return (void *)(lksb->lksb_fsdlm.sb_lvbptr);
743}
744
Joel Beckerc0e41332010-01-29 14:46:44 -0800745static void user_dlm_dump_lksb(struct ocfs2_dlm_lksb *lksb)
David Teiglandcf4d8d72008-02-20 14:29:27 -0800746{
747}
748
Mark Fasheh53da4932008-07-21 14:29:16 -0700749static int user_plock(struct ocfs2_cluster_connection *conn,
750 u64 ino,
751 struct file *file,
752 int cmd,
753 struct file_lock *fl)
754{
755 /*
756 * This more or less just demuxes the plock request into any
757 * one of three dlm calls.
758 *
759 * Internally, fs/dlm will pass these to a misc device, which
760 * a userspace daemon will read and write to.
761 *
762 * For now, cancel requests (which happen internally only),
763 * are turned into unlocks. Most of this function taken from
764 * gfs2_lock.
765 */
766
767 if (cmd == F_CANCELLK) {
768 cmd = F_SETLK;
769 fl->fl_type = F_UNLCK;
770 }
771
772 if (IS_GETLK(cmd))
773 return dlm_posix_get(conn->cc_lockspace, ino, file, fl);
774 else if (fl->fl_type == F_UNLCK)
775 return dlm_posix_unlock(conn->cc_lockspace, ino, file, fl);
776 else
777 return dlm_posix_lock(conn->cc_lockspace, ino, file, cmd, fl);
778}
779
David Teiglandcf4d8d72008-02-20 14:29:27 -0800780/*
781 * Compare a requested locking protocol version against the current one.
782 *
783 * If the major numbers are different, they are incompatible.
784 * If the current minor is greater than the request, they are incompatible.
785 * If the current minor is less than or equal to the request, they are
786 * compatible, and the requester should run at the current minor version.
787 */
788static int fs_protocol_compare(struct ocfs2_protocol_version *existing,
789 struct ocfs2_protocol_version *request)
790{
791 if (existing->pv_major != request->pv_major)
792 return 1;
793
794 if (existing->pv_minor > request->pv_minor)
795 return 1;
796
797 if (existing->pv_minor < request->pv_minor)
798 request->pv_minor = existing->pv_minor;
799
800 return 0;
801}
802
Goldwyn Rodrigues41503632014-01-21 15:48:25 -0800803static void lvb_to_version(char *lvb, struct ocfs2_protocol_version *ver)
804{
805 struct ocfs2_protocol_version *pv =
806 (struct ocfs2_protocol_version *)lvb;
807 /*
808 * ocfs2_protocol_version has two u8 variables, so we don't
809 * need any endian conversion.
810 */
811 ver->pv_major = pv->pv_major;
812 ver->pv_minor = pv->pv_minor;
813}
814
815static void version_to_lvb(struct ocfs2_protocol_version *ver, char *lvb)
816{
817 struct ocfs2_protocol_version *pv =
818 (struct ocfs2_protocol_version *)lvb;
819 /*
820 * ocfs2_protocol_version has two u8 variables, so we don't
821 * need any endian conversion.
822 */
823 pv->pv_major = ver->pv_major;
824 pv->pv_minor = ver->pv_minor;
825}
826
827static void sync_wait_cb(void *arg)
828{
829 struct ocfs2_cluster_connection *conn = arg;
830 struct ocfs2_live_connection *lc = conn->cc_private;
831 complete(&lc->oc_sync_wait);
832}
833
834static int sync_unlock(struct ocfs2_cluster_connection *conn,
835 struct dlm_lksb *lksb, char *name)
836{
837 int error;
838 struct ocfs2_live_connection *lc = conn->cc_private;
839
840 error = dlm_unlock(conn->cc_lockspace, lksb->sb_lkid, 0, lksb, conn);
841 if (error) {
842 printk(KERN_ERR "%s lkid %x error %d\n",
843 name, lksb->sb_lkid, error);
844 return error;
845 }
846
847 wait_for_completion(&lc->oc_sync_wait);
848
849 if (lksb->sb_status != -DLM_EUNLOCK) {
850 printk(KERN_ERR "%s lkid %x status %d\n",
851 name, lksb->sb_lkid, lksb->sb_status);
852 return -1;
853 }
854 return 0;
855}
856
857static int sync_lock(struct ocfs2_cluster_connection *conn,
858 int mode, uint32_t flags,
859 struct dlm_lksb *lksb, char *name)
860{
861 int error, status;
862 struct ocfs2_live_connection *lc = conn->cc_private;
863
864 error = dlm_lock(conn->cc_lockspace, mode, lksb, flags,
865 name, strlen(name),
866 0, sync_wait_cb, conn, NULL);
867 if (error) {
868 printk(KERN_ERR "%s lkid %x flags %x mode %d error %d\n",
869 name, lksb->sb_lkid, flags, mode, error);
870 return error;
871 }
872
873 wait_for_completion(&lc->oc_sync_wait);
874
875 status = lksb->sb_status;
876
877 if (status && status != -EAGAIN) {
878 printk(KERN_ERR "%s lkid %x flags %x mode %d status %d\n",
879 name, lksb->sb_lkid, flags, mode, status);
880 }
881
882 return status;
883}
884
885
886static int version_lock(struct ocfs2_cluster_connection *conn, int mode,
887 int flags)
888{
889 struct ocfs2_live_connection *lc = conn->cc_private;
890 return sync_lock(conn, mode, flags,
891 &lc->oc_version_lksb, VERSION_LOCK);
892}
893
894static int version_unlock(struct ocfs2_cluster_connection *conn)
895{
896 struct ocfs2_live_connection *lc = conn->cc_private;
897 return sync_unlock(conn, &lc->oc_version_lksb, VERSION_LOCK);
898}
899
Goldwyn Rodrigues66e188f2014-01-21 15:48:22 -0800900static void user_recover_prep(void *arg)
901{
902}
903
904static void user_recover_slot(void *arg, struct dlm_slot *slot)
905{
906 struct ocfs2_cluster_connection *conn = arg;
907 printk(KERN_INFO "ocfs2: Node %d/%d down. Initiating recovery.\n",
908 slot->nodeid, slot->slot);
909 conn->cc_recovery_handler(slot->nodeid, conn->cc_recovery_data);
910
911}
912
913static void user_recover_done(void *arg, struct dlm_slot *slots,
914 int num_slots, int our_slot,
915 uint32_t generation)
916{
917 struct ocfs2_cluster_connection *conn = arg;
918 struct ocfs2_live_connection *lc = conn->cc_private;
919 int i;
920
921 for (i = 0; i < num_slots; i++)
922 if (slots[i].slot == our_slot) {
923 atomic_set(&lc->oc_this_node, slots[i].nodeid);
924 break;
925 }
926
927 lc->oc_our_slot = our_slot;
928}
929
930const struct dlm_lockspace_ops ocfs2_ls_ops = {
931 .recover_prep = user_recover_prep,
932 .recover_slot = user_recover_slot,
933 .recover_done = user_recover_done,
934};
935
David Teiglandcf4d8d72008-02-20 14:29:27 -0800936static int user_cluster_connect(struct ocfs2_cluster_connection *conn)
937{
938 dlm_lockspace_t *fsdlm;
Goldwyn Rodrigues24aa3382014-01-21 15:48:23 -0800939 struct ocfs2_live_connection *lc;
940 int rc;
David Teiglandcf4d8d72008-02-20 14:29:27 -0800941
942 BUG_ON(conn == NULL);
943
Goldwyn Rodrigues24aa3382014-01-21 15:48:23 -0800944 lc = kzalloc(sizeof(struct ocfs2_live_connection), GFP_KERNEL);
945 if (!lc) {
946 rc = -ENOMEM;
947 goto out;
948 }
949
Goldwyn Rodrigues3e834152014-01-21 15:48:24 -0800950 lc->oc_type = WITH_CONTROLD;
Goldwyn Rodrigues24aa3382014-01-21 15:48:23 -0800951 rc = ocfs2_live_connection_attach(conn, lc);
David Teiglandcf4d8d72008-02-20 14:29:27 -0800952 if (rc)
953 goto out;
954
955 /*
956 * running_proto must have been set before we allowed any mounts
957 * to proceed.
958 */
959 if (fs_protocol_compare(&running_proto, &conn->cc_version)) {
960 printk(KERN_ERR
961 "Unable to mount with fs locking protocol version "
962 "%u.%u because the userspace control daemon has "
963 "negotiated %u.%u\n",
964 conn->cc_version.pv_major, conn->cc_version.pv_minor,
965 running_proto.pv_major, running_proto.pv_minor);
966 rc = -EPROTO;
Goldwyn Rodrigues24aa3382014-01-21 15:48:23 -0800967 ocfs2_live_connection_drop(lc);
968 lc = NULL;
David Teiglandcf4d8d72008-02-20 14:29:27 -0800969 goto out;
970 }
971
David Teigland60f98d12011-11-02 14:30:58 -0500972 rc = dlm_new_lockspace(conn->cc_name, NULL, DLM_LSFL_FS, DLM_LVB_LEN,
973 NULL, NULL, NULL, &fsdlm);
David Teiglandcf4d8d72008-02-20 14:29:27 -0800974 if (rc) {
Goldwyn Rodrigues24aa3382014-01-21 15:48:23 -0800975 ocfs2_live_connection_drop(lc);
976 lc = NULL;
David Teiglandcf4d8d72008-02-20 14:29:27 -0800977 goto out;
978 }
979
Goldwyn Rodrigues24aa3382014-01-21 15:48:23 -0800980 conn->cc_private = lc;
David Teiglandcf4d8d72008-02-20 14:29:27 -0800981 conn->cc_lockspace = fsdlm;
982out:
Goldwyn Rodrigues24aa3382014-01-21 15:48:23 -0800983 if (rc && lc)
984 kfree(lc);
David Teiglandcf4d8d72008-02-20 14:29:27 -0800985 return rc;
986}
987
Joel Becker2c394502008-05-30 15:58:26 -0700988static int user_cluster_disconnect(struct ocfs2_cluster_connection *conn)
David Teiglandcf4d8d72008-02-20 14:29:27 -0800989{
990 dlm_release_lockspace(conn->cc_lockspace, 2);
991 conn->cc_lockspace = NULL;
992 ocfs2_live_connection_drop(conn->cc_private);
993 conn->cc_private = NULL;
994 return 0;
995}
996
Goldwyn Rodrigues3e834152014-01-21 15:48:24 -0800997static int user_cluster_this_node(struct ocfs2_cluster_connection *conn,
998 unsigned int *this_node)
David Teiglandcf4d8d72008-02-20 14:29:27 -0800999{
1000 int rc;
Goldwyn Rodrigues3e834152014-01-21 15:48:24 -08001001 struct ocfs2_live_connection *lc = conn->cc_private;
David Teiglandcf4d8d72008-02-20 14:29:27 -08001002
Goldwyn Rodrigues3e834152014-01-21 15:48:24 -08001003 if (lc->oc_type == WITH_CONTROLD)
1004 rc = ocfs2_control_get_this_node();
1005 else
1006 rc = -EINVAL;
David Teiglandcf4d8d72008-02-20 14:29:27 -08001007 if (rc < 0)
1008 return rc;
1009
1010 *this_node = rc;
1011 return 0;
1012}
1013
Joel Beckera12630b2008-05-09 18:49:29 -07001014static struct ocfs2_stack_operations ocfs2_user_plugin_ops = {
David Teiglandcf4d8d72008-02-20 14:29:27 -08001015 .connect = user_cluster_connect,
1016 .disconnect = user_cluster_disconnect,
1017 .this_node = user_cluster_this_node,
1018 .dlm_lock = user_dlm_lock,
1019 .dlm_unlock = user_dlm_unlock,
1020 .lock_status = user_dlm_lock_status,
Joel Becker1c520df2009-06-19 15:14:13 -07001021 .lvb_valid = user_dlm_lvb_valid,
David Teiglandcf4d8d72008-02-20 14:29:27 -08001022 .lock_lvb = user_dlm_lvb,
Mark Fasheh53da4932008-07-21 14:29:16 -07001023 .plock = user_plock,
David Teiglandcf4d8d72008-02-20 14:29:27 -08001024 .dump_lksb = user_dlm_dump_lksb,
1025};
1026
Joel Beckera12630b2008-05-09 18:49:29 -07001027static struct ocfs2_stack_plugin ocfs2_user_plugin = {
David Teiglandcf4d8d72008-02-20 14:29:27 -08001028 .sp_name = "user",
Joel Beckera12630b2008-05-09 18:49:29 -07001029 .sp_ops = &ocfs2_user_plugin_ops,
David Teiglandcf4d8d72008-02-20 14:29:27 -08001030 .sp_owner = THIS_MODULE,
1031};
1032
1033
Joel Beckera12630b2008-05-09 18:49:29 -07001034static int __init ocfs2_user_plugin_init(void)
Joel Becker6427a722008-02-18 19:23:28 -08001035{
David Teiglandcf4d8d72008-02-20 14:29:27 -08001036 int rc;
1037
1038 rc = ocfs2_control_init();
1039 if (!rc) {
Joel Beckera12630b2008-05-09 18:49:29 -07001040 rc = ocfs2_stack_glue_register(&ocfs2_user_plugin);
David Teiglandcf4d8d72008-02-20 14:29:27 -08001041 if (rc)
1042 ocfs2_control_exit();
1043 }
1044
1045 return rc;
Joel Becker6427a722008-02-18 19:23:28 -08001046}
1047
Joel Beckera12630b2008-05-09 18:49:29 -07001048static void __exit ocfs2_user_plugin_exit(void)
Joel Becker8adf0532007-11-28 14:38:40 -08001049{
Joel Beckera12630b2008-05-09 18:49:29 -07001050 ocfs2_stack_glue_unregister(&ocfs2_user_plugin);
Joel Becker6427a722008-02-18 19:23:28 -08001051 ocfs2_control_exit();
Joel Becker8adf0532007-11-28 14:38:40 -08001052}
1053
1054MODULE_AUTHOR("Oracle");
1055MODULE_DESCRIPTION("ocfs2 driver for userspace cluster stacks");
1056MODULE_LICENSE("GPL");
Joel Beckera12630b2008-05-09 18:49:29 -07001057module_init(ocfs2_user_plugin_init);
1058module_exit(ocfs2_user_plugin_exit);