blob: e197367b6bd6ef01bdf8c56ab63acc59a8198a18 [file] [log] [blame]
Joel Becker24ef1812008-01-29 17:37:32 -08001/* -*- 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 Becker4670c462008-02-01 14:39:35 -080021#include <linux/slab.h>
Joel Becker6953b4c2008-01-29 16:59:56 -080022#include <linux/kmod.h>
Joel Becker4670c462008-02-01 14:39:35 -080023
24/* Needed for AOP_TRUNCATED_PAGE in mlog_errno() */
25#include <linux/fs.h>
26
Joel Becker7431cd72008-02-01 12:15:37 -080027#include "cluster/masklog.h"
Joel Becker19fdb622008-01-30 15:38:24 -080028
Joel Becker24ef1812008-01-29 17:37:32 -080029#include "stackglue.h"
30
Joel Beckere3dad422008-02-01 15:02:36 -080031struct ocfs2_locking_protocol *stack_glue_lproto;
Joel Becker24ef1812008-01-29 17:37:32 -080032
Joel Becker24ef1812008-01-29 17:37:32 -080033
Joel Becker553aa7e2008-02-01 14:51:03 -080034int ocfs2_dlm_lock(struct ocfs2_cluster_connection *conn,
35 int mode,
36 union ocfs2_dlm_lksb *lksb,
37 u32 flags,
38 void *name,
39 unsigned int namelen,
40 void *astarg)
41{
Joel Beckere3dad422008-02-01 15:02:36 -080042 BUG_ON(stack_glue_lproto == NULL);
Joel Becker553aa7e2008-02-01 14:51:03 -080043
Joel Beckere3dad422008-02-01 15:02:36 -080044 return o2cb_stack_ops.dlm_lock(conn, mode, lksb, flags,
45 name, namelen, astarg);
Joel Becker24ef1812008-01-29 17:37:32 -080046}
47
Joel Becker553aa7e2008-02-01 14:51:03 -080048int ocfs2_dlm_unlock(struct ocfs2_cluster_connection *conn,
49 union ocfs2_dlm_lksb *lksb,
50 u32 flags,
51 void *astarg)
52{
Joel Beckere3dad422008-02-01 15:02:36 -080053 BUG_ON(stack_glue_lproto == NULL);
Joel Becker553aa7e2008-02-01 14:51:03 -080054
Joel Beckere3dad422008-02-01 15:02:36 -080055 return o2cb_stack_ops.dlm_unlock(conn, lksb, flags, astarg);
Joel Becker8f2c9c12008-02-01 12:16:57 -080056}
57
Joel Becker553aa7e2008-02-01 14:51:03 -080058int ocfs2_dlm_lock_status(union ocfs2_dlm_lksb *lksb)
59{
Joel Beckere3dad422008-02-01 15:02:36 -080060 return o2cb_stack_ops.lock_status(lksb);
Joel Becker553aa7e2008-02-01 14:51:03 -080061}
62
Joel Becker8f2c9c12008-02-01 12:16:57 -080063/*
64 * Why don't we cast to ocfs2_meta_lvb? The "clean" answer is that we
65 * don't cast at the glue level. The real answer is that the header
66 * ordering is nigh impossible.
67 */
Joel Becker553aa7e2008-02-01 14:51:03 -080068void *ocfs2_dlm_lvb(union ocfs2_dlm_lksb *lksb)
69{
Joel Beckere3dad422008-02-01 15:02:36 -080070 return o2cb_stack_ops.lock_lvb(lksb);
Joel Beckercf0acdc2008-01-29 16:59:55 -080071}
72
Joel Becker553aa7e2008-02-01 14:51:03 -080073void ocfs2_dlm_dump_lksb(union ocfs2_dlm_lksb *lksb)
74{
Joel Beckere3dad422008-02-01 15:02:36 -080075 o2cb_stack_ops.dump_lksb(lksb);
Joel Becker553aa7e2008-02-01 14:51:03 -080076}
77
Joel Becker4670c462008-02-01 14:39:35 -080078int ocfs2_cluster_connect(const char *group,
79 int grouplen,
80 void (*recovery_handler)(int node_num,
81 void *recovery_data),
82 void *recovery_data,
83 struct ocfs2_cluster_connection **conn)
84{
85 int rc = 0;
86 struct ocfs2_cluster_connection *new_conn;
Joel Becker4670c462008-02-01 14:39:35 -080087
88 BUG_ON(group == NULL);
89 BUG_ON(conn == NULL);
90 BUG_ON(recovery_handler == NULL);
91
92 if (grouplen > GROUP_NAME_MAX) {
93 rc = -EINVAL;
94 goto out;
95 }
96
97 new_conn = kzalloc(sizeof(struct ocfs2_cluster_connection),
98 GFP_KERNEL);
99 if (!new_conn) {
100 rc = -ENOMEM;
101 goto out;
102 }
103
104 memcpy(new_conn->cc_name, group, grouplen);
105 new_conn->cc_namelen = grouplen;
106 new_conn->cc_recovery_handler = recovery_handler;
107 new_conn->cc_recovery_data = recovery_data;
108
109 /* Start the new connection at our maximum compatibility level */
Joel Beckere3dad422008-02-01 15:02:36 -0800110 new_conn->cc_version = stack_glue_lproto->lp_max_version;
Joel Becker4670c462008-02-01 14:39:35 -0800111
Joel Beckere3dad422008-02-01 15:02:36 -0800112 rc = o2cb_stack_ops.connect(new_conn);
Joel Becker553aa7e2008-02-01 14:51:03 -0800113 if (rc) {
Joel Becker4670c462008-02-01 14:39:35 -0800114 mlog_errno(rc);
115 goto out_free;
116 }
117
Joel Becker4670c462008-02-01 14:39:35 -0800118 *conn = new_conn;
119
120out_free:
Joel Becker553aa7e2008-02-01 14:51:03 -0800121 if (rc)
Joel Becker4670c462008-02-01 14:39:35 -0800122 kfree(new_conn);
Joel Becker4670c462008-02-01 14:39:35 -0800123
124out:
125 return rc;
126}
127
Joel Becker553aa7e2008-02-01 14:51:03 -0800128int ocfs2_cluster_disconnect(struct ocfs2_cluster_connection *conn)
129{
130 int ret;
131
132 BUG_ON(conn == NULL);
133
Joel Beckere3dad422008-02-01 15:02:36 -0800134 ret = o2cb_stack_ops.disconnect(conn);
Joel Becker553aa7e2008-02-01 14:51:03 -0800135
136 /* XXX Should we free it anyway? */
137 if (!ret)
138 kfree(conn);
139
140 return ret;
141}
142
Joel Becker6953b4c2008-01-29 16:59:56 -0800143void ocfs2_cluster_hangup(const char *group, int grouplen)
144{
145 BUG_ON(group == NULL);
146 BUG_ON(group[grouplen] != '\0');
147
Joel Beckere3dad422008-02-01 15:02:36 -0800148 o2cb_stack_ops.hangup(group, grouplen);
Joel Becker19fdb622008-01-30 15:38:24 -0800149}
150
Joel Becker553aa7e2008-02-01 14:51:03 -0800151int ocfs2_cluster_this_node(unsigned int *node)
152{
Joel Beckere3dad422008-02-01 15:02:36 -0800153 return o2cb_stack_ops.this_node(node);
Joel Becker553aa7e2008-02-01 14:51:03 -0800154}
155
Joel Becker63e0c482008-01-30 16:58:36 -0800156void ocfs2_stack_glue_set_locking_protocol(struct ocfs2_locking_protocol *proto)
Joel Becker24ef1812008-01-29 17:37:32 -0800157{
Joel Becker63e0c482008-01-30 16:58:36 -0800158 BUG_ON(proto != NULL);
Joel Becker24ef1812008-01-29 17:37:32 -0800159
Joel Beckere3dad422008-02-01 15:02:36 -0800160 stack_glue_lproto = proto;
Joel Becker24ef1812008-01-29 17:37:32 -0800161}
162