stackglue.c 3.5 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
/* -*- 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.
 *
 * Copyright (C) 2007 Oracle.  All rights reserved.
 *
 * 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.
 */

21
#include <linux/slab.h>
22
#include <linux/kmod.h>
23 24 25 26

/* Needed for AOP_TRUNCATED_PAGE in mlog_errno() */
#include <linux/fs.h>

27
#include "cluster/masklog.h"
28

29 30
#include "stackglue.h"

31
struct ocfs2_locking_protocol *stack_glue_lproto;
32

33

34 35 36 37 38 39 40 41
int ocfs2_dlm_lock(struct ocfs2_cluster_connection *conn,
		   int mode,
		   union ocfs2_dlm_lksb *lksb,
		   u32 flags,
		   void *name,
		   unsigned int namelen,
		   void *astarg)
{
42
	BUG_ON(stack_glue_lproto == NULL);
43

44 45
	return o2cb_stack_ops.dlm_lock(conn, mode, lksb, flags,
				       name, namelen, astarg);
46 47
}

48 49 50 51 52
int ocfs2_dlm_unlock(struct ocfs2_cluster_connection *conn,
		     union ocfs2_dlm_lksb *lksb,
		     u32 flags,
		     void *astarg)
{
53
	BUG_ON(stack_glue_lproto == NULL);
54

55
	return o2cb_stack_ops.dlm_unlock(conn, lksb, flags, astarg);
56 57
}

58 59
int ocfs2_dlm_lock_status(union ocfs2_dlm_lksb *lksb)
{
60
	return o2cb_stack_ops.lock_status(lksb);
61 62
}

63 64 65 66 67
/*
 * Why don't we cast to ocfs2_meta_lvb?  The "clean" answer is that we
 * don't cast at the glue level.  The real answer is that the header
 * ordering is nigh impossible.
 */
68 69
void *ocfs2_dlm_lvb(union ocfs2_dlm_lksb *lksb)
{
70
	return o2cb_stack_ops.lock_lvb(lksb);
71 72
}

73 74
void ocfs2_dlm_dump_lksb(union ocfs2_dlm_lksb *lksb)
{
75
	o2cb_stack_ops.dump_lksb(lksb);
76 77
}

78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109
int ocfs2_cluster_connect(const char *group,
			  int grouplen,
			  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;

	BUG_ON(group == NULL);
	BUG_ON(conn == NULL);
	BUG_ON(recovery_handler == NULL);

	if (grouplen > GROUP_NAME_MAX) {
		rc = -EINVAL;
		goto out;
	}

	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;

	/* Start the new connection at our maximum compatibility level */
110
	new_conn->cc_version = stack_glue_lproto->lp_max_version;
111

112
	rc = o2cb_stack_ops.connect(new_conn);
113
	if (rc) {
114 115 116 117 118 119 120
		mlog_errno(rc);
		goto out_free;
	}

	*conn = new_conn;

out_free:
121
	if (rc)
122 123 124 125 126 127
		kfree(new_conn);

out:
	return rc;
}

128 129 130 131 132 133
int ocfs2_cluster_disconnect(struct ocfs2_cluster_connection *conn)
{
	int ret;

	BUG_ON(conn == NULL);

134
	ret = o2cb_stack_ops.disconnect(conn);
135 136 137 138 139 140 141 142

	/* XXX Should we free it anyway? */
	if (!ret)
		kfree(conn);

	return ret;
}

143 144 145 146 147
void ocfs2_cluster_hangup(const char *group, int grouplen)
{
	BUG_ON(group == NULL);
	BUG_ON(group[grouplen] != '\0');

148
	o2cb_stack_ops.hangup(group, grouplen);
149 150
}

151 152
int ocfs2_cluster_this_node(unsigned int *node)
{
153
	return o2cb_stack_ops.this_node(node);
154 155
}

156
void ocfs2_stack_glue_set_locking_protocol(struct ocfs2_locking_protocol *proto)
157
{
158
	BUG_ON(proto != NULL);
159

160
	stack_glue_lproto = proto;
161 162
}