[Ocfs2-commits] zab commits r1842 - trunk/fs/ocfs2/cluster
svn-commits at oss.oracle.com
svn-commits at oss.oracle.com
Mon Jan 24 18:31:48 CST 2005
Author: zab
Date: 2005-01-24 18:31:46 -0600 (Mon, 24 Jan 2005)
New Revision: 1842
Added:
trunk/fs/ocfs2/cluster/gsd.c
trunk/fs/ocfs2/cluster/gsd.h
Modified:
trunk/fs/ocfs2/cluster/Makefile
trunk/fs/ocfs2/cluster/tcp.c
Log:
o move gsd goo into its own file (also known as a better place)
Modified: trunk/fs/ocfs2/cluster/Makefile
===================================================================
--- trunk/fs/ocfs2/cluster/Makefile 2005-01-25 00:03:04 UTC (rev 1841)
+++ trunk/fs/ocfs2/cluster/Makefile 2005-01-25 00:31:46 UTC (rev 1842)
@@ -30,7 +30,7 @@
ocfs2_heartbeat-objs := heartbeat.o util.o transaction_file.o $(COMPAT_LIBFS)
-ocfs2_tcp-objs := tcp.o util.o $(COMPAT_LIBFS)
+ocfs2_tcp-objs := gsd.o tcp.o util.o $(COMPAT_LIBFS)
ifeq ($(KERNELRELEASE),)
@@ -40,6 +40,7 @@
SOURCES = \
compat_libfs.c \
+ gsd.c \
heartbeat.c \
nodemanager.c \
tcp.c \
@@ -50,6 +51,7 @@
clcommon.h \
cl_compat.h \
compat_libfs.h \
+ gsd.h \
heartbeat.h \
nodemanager.h \
ocfs2_heartbeat.h \
Added: trunk/fs/ocfs2/cluster/gsd.c
===================================================================
--- trunk/fs/ocfs2/cluster/gsd.c 2005-01-25 00:03:04 UTC (rev 1841)
+++ trunk/fs/ocfs2/cluster/gsd.c 2005-01-25 00:31:46 UTC (rev 1842)
@@ -0,0 +1,243 @@
+/* -*- mode: c; c-basic-offset: 8; -*-
+ * vim: noexpandtab sw=8 ts=8 sts=0:
+ *
+ * Copyright (C) 2005 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; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * 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.
+ *
+ * You should have received a copy of the GNU General Public
+ * License along with this program; if not, write to the
+ * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ * Boston, MA 021110-1307, USA.
+ *
+ */
+#include <linux/config.h>
+#include <linux/module.h>
+#include <linux/fs.h>
+#include <linux/file.h>
+
+#include "cl_compat.h"
+#include "util.h"
+#include "clcommon.h"
+#include "nodemanager.h"
+#include "tcp.h"
+#include "gsd.h"
+
+static char *gsd_handler_buf = NULL;
+/* sigh. these will be claned up, I'm just sure of it. */
+static u16 gsd_node_num;
+static struct inode *gsd_inode;
+
+static int gsd_message_action(gsd_message *g)
+{
+ int ret;
+ nm_op op;
+ int namelen = g->namelen;
+ struct inode *node=NULL, *group=NULL;
+ char name[NM_MAX_NAME_LEN+1];
+
+ if (namelen > NM_MAX_NAME_LEN)
+ return -EINVAL;
+ strncpy(name, g->name, namelen);
+ name[namelen] = '\0';
+
+ memset(&op, 0, sizeof(op));
+ switch (g->action) {
+ case GSD_ACTION_ADD_GROUP:
+ group = nm_get_group_by_name(name);
+ if (group) {
+ ret = 0;
+ break;
+ }
+ op.arg_u.gc.group_num = NM_INVALID_SLOT_NUM;
+ memcpy(op.arg_u.gc.name, name, namelen);
+ memcpy(op.arg_u.gc.disk_uuid, name, namelen);
+
+ ret = nm_create_group(gsd_handler_buf, &op);
+ if (ret >= 0)
+ ret = 0;
+ break;
+
+ case GSD_ACTION_ADD_GROUP_NODE:
+ group = nm_get_group_by_name(name);
+ if (!group) {
+ ret = -EINVAL;
+ break;
+ }
+ node = nm_get_group_node_by_index(group, g->from);
+ if (node) {
+ ret = 0;
+ if (nm_get_node_global_index(node) != g->from)
+ ret = -EINVAL;
+ break;
+ }
+ op.arg_u.gc.group_num = nm_get_group_global_index(group);
+ op.arg_u.gc.node_num = g->from;
+ op.arg_u.gc.slot_num = g->from;
+ ret = nm_add_node_to_group(gsd_handler_buf, &op);
+ if (ret >= 0)
+ ret = 0;
+ break;
+ default:
+ ret = -EINVAL;
+ break;
+ }
+
+ if (node)
+ iput(node);
+ if (group)
+ iput(group);
+ return ret;
+}
+
+static int gsd_message_handler(net_msg *msg, u32 len, void *data)
+{
+ gsd_message *g = (gsd_message *)msg->buf;
+ gsd_message_to_host(g);
+ return gsd_message_action(g);
+}
+
+int gsd_ioctl(struct inode *inode, struct file *filp, unsigned int cmd,
+ unsigned long arg)
+{
+ gsd_ioc gsd_data;
+ int ret = 0;
+ gsd_message g;
+ int response = 0;
+ struct inode *to = NULL;
+ struct file *file = NULL;
+
+ switch (cmd) {
+ case GSD_IOC_CREATE_GROUP:
+ memset(&gsd_data, 0, sizeof(gsd_ioc));
+ ret = copy_from_user(&gsd_data, (gsd_ioc *)arg,
+ sizeof(gsd_ioc));
+
+ file = fget(gsd_data.fd);
+ if (!file || !file->f_dentry || !file->f_dentry->d_inode) {
+ ret = -EINVAL;
+ break;
+ }
+ to = file->f_dentry->d_inode;
+
+ g.action = GSD_ACTION_ADD_GROUP;
+ g.from = gsd_node_num;
+ g.namelen = gsd_data.namelen;
+ memcpy(g.name, gsd_data.name, gsd_data.namelen);
+
+ if (to == gsd_inode) {
+ /* create the group locally */
+ ret = gsd_message_action(&g);
+ } else {
+ /* create the group on remote node */
+ gsd_message_to_net(&g);
+ ret = net_send_message(GSD_MESSAGE, 0, &g,
+ sizeof(g), to, &response);
+ if (ret == 0)
+ ret = response;
+ }
+
+ memset(&gsd_data, 0, sizeof(gsd_ioc));
+ gsd_data.status = ret;
+ ret = copy_to_user((gsd_ioc *)arg, &gsd_data,
+ sizeof(gsd_ioc));
+ break;
+
+ case GSD_IOC_ADD_GROUP_NODE:
+ memset(&gsd_data, 0, sizeof(gsd_ioc));
+ ret = copy_from_user(&gsd_data, (gsd_ioc *)arg,
+ sizeof(gsd_ioc));
+
+ file = fget(gsd_data.fd);
+ if (!file || !file->f_dentry || !file->f_dentry->d_inode) {
+ ret = -EINVAL;
+ break;
+ }
+ to = file->f_dentry->d_inode;
+
+ g.action = GSD_ACTION_ADD_GROUP_NODE;
+ g.from = gsd_node_num;
+ g.namelen = gsd_data.namelen;
+ memcpy(g.name, gsd_data.name, gsd_data.namelen);
+
+ if (to == gsd_inode) {
+ /* create the group locally */
+ ret = gsd_message_action(&g);
+ } else {
+ /* create the group on remote node */
+ gsd_message_to_net(&g);
+ ret = net_send_message(GSD_MESSAGE, 0, &g,
+ sizeof(g), to, &response);
+ if (ret == 0)
+ ret = response;
+ }
+ memset(&gsd_data, 0, sizeof(gsd_ioc));
+ gsd_data.status = ret;
+ ret = copy_to_user((gsd_ioc *)arg, &gsd_data,
+ sizeof(gsd_ioc));
+ break;
+ default:
+ BUG();
+ break;
+ }
+
+ if (file)
+ fput(file);
+
+ return ret;
+} /* net_ioctl */
+
+int gsd_setup(void)
+{
+ int ret;
+
+ gsd_node_num = nm_this_node(NULL);
+ if (gsd_node_num >= NM_MAX_NODES) {
+ printk("local nm node number not initialized!\n");
+ ret = -EINVAL;
+ goto out;
+ }
+
+ gsd_inode = nm_get_node_by_num(gsd_node_num);
+ if (!gsd_inode) {
+ printk("local nm node inode not initialized!\n");
+ return -1;
+ }
+
+ /* need this stupidity until I can divorce the actual nm actions
+ * from the output they send to their user buffer */
+ gsd_handler_buf = (char *) __get_free_page(GFP_KERNEL);
+ if (!gsd_handler_buf) {
+ ret = -ENOMEM;
+ goto out;
+ }
+
+ ret = net_register_handler(GSD_MESSAGE, 0, 0, sizeof(gsd_message),
+ gsd_message_handler, NULL);
+out:
+ if (ret)
+ if (gsd_inode) {
+ iput(gsd_inode);
+ gsd_inode = NULL;
+ }
+
+ return ret;
+}
+
+void gsd_teardown(void)
+{
+ free_page((unsigned long)gsd_handler_buf);
+ if (gsd_inode) {
+ iput(gsd_inode);
+ gsd_inode = NULL;
+ }
+}
+
Added: trunk/fs/ocfs2/cluster/gsd.h
===================================================================
--- trunk/fs/ocfs2/cluster/gsd.h 2005-01-25 00:03:04 UTC (rev 1841)
+++ trunk/fs/ocfs2/cluster/gsd.h 2005-01-25 00:31:46 UTC (rev 1842)
@@ -0,0 +1,31 @@
+/* -*- mode: c; c-basic-offset: 8; -*-
+ * vim: noexpandtab sw=8 ts=8 sts=0:
+ *
+ * Copyright (C) 2005 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; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * 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.
+ *
+ * You should have received a copy of the GNU General Public
+ * License along with this program; if not, write to the
+ * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ * Boston, MA 021110-1307, USA.
+ */
+
+#ifndef CLUSTER_GSD_H
+#define CLUSTER_GSD_H
+
+int gsd_ioctl(struct inode *inode, struct file *filp, unsigned int cmd,
+ unsigned long arg);
+
+int gsd_setup(void);
+void gsd_teardown(void);
+
+#endif
Modified: trunk/fs/ocfs2/cluster/tcp.c
===================================================================
--- trunk/fs/ocfs2/cluster/tcp.c 2005-01-25 00:03:04 UTC (rev 1841)
+++ trunk/fs/ocfs2/cluster/tcp.c 2005-01-25 00:31:46 UTC (rev 1842)
@@ -75,8 +75,6 @@
* - make sure ->net.page gets torn down with net_inode_private
* - tear down sockets on exit.. via removing their inodes?
* - simplify rx thread exit path (completion, etc)
- *
- * - move gsd into its own file
*/
#include <linux/module.h>
@@ -103,6 +101,7 @@
#include "util.h"
+#include "gsd.h"
#include "heartbeat.h"
#include "tcp.h"
#include "nodemanager.h"
@@ -151,9 +150,6 @@
static struct inode *net_inode = NULL;
static u16 net_node_num;
-char *gsd_handler_buf = NULL;
-
-
/* all this state should eventually be brought up by object activation
* and tied to that object rather than being globally valid at insmod */
static spinlock_t net_handler_lock = SPIN_LOCK_UNLOCKED;
@@ -196,12 +192,6 @@
struct socket **sock_ret);
static void net_sock_decref(struct inode *inode, int error);
-int gsd_message_action(gsd_message *g);
-int gsd_message_handler(net_msg *msg, u32 len, void *data);
-void gsd_teardown(void);
-int gsd_setup(void);
-
-
//////////////////////
static void net_get_handler(net_msg_handler *nmh)
@@ -246,14 +236,11 @@
return 0;
} /* net_driver_entry */
-static int net_ioctl (struct inode *inode, struct file *filp, unsigned int cmd, unsigned long arg)
+static int net_ioctl(struct inode *inode, struct file *filp, unsigned int cmd,
+ unsigned long arg)
{
net_ioc data;
- gsd_ioc gsd_data;
int ret = 0;
- gsd_message g;
- int response = 0;
- struct inode *to = NULL;
struct file *file = NULL;
if (_IOC_TYPE (cmd) != NET_IOC_MAGIC) {
@@ -291,66 +278,8 @@
break;
case GSD_IOC_CREATE_GROUP:
- memset(&gsd_data, 0, sizeof(gsd_ioc));
- ret = copy_from_user(&gsd_data, (gsd_ioc *)arg, sizeof(gsd_ioc));
-
- file = fget(gsd_data.fd);
- if (!file || !file->f_dentry || !file->f_dentry->d_inode) {
- ret = -EINVAL;
- break;
- }
- to = file->f_dentry->d_inode;
-
- g.action = GSD_ACTION_ADD_GROUP;
- g.from = net_node_num;
- g.namelen = gsd_data.namelen;
- memcpy(g.name, gsd_data.name, gsd_data.namelen);
-
- if (to == net_inode) {
- /* create the group locally */
- ret = gsd_message_action(&g);
- } else {
- /* create the group on remote node */
- gsd_message_to_net(&g);
- ret = net_send_message(GSD_MESSAGE, 0, &g, sizeof(g), to, &response);
- if (ret == 0)
- ret = response;
- }
-
- memset(&gsd_data, 0, sizeof(gsd_ioc));
- gsd_data.status = ret;
- ret = copy_to_user((gsd_ioc *)arg, &gsd_data, sizeof(gsd_ioc));
- break;
-
case GSD_IOC_ADD_GROUP_NODE:
- memset(&gsd_data, 0, sizeof(gsd_ioc));
- ret = copy_from_user(&gsd_data, (gsd_ioc *)arg, sizeof(gsd_ioc));
-
- file = fget(gsd_data.fd);
- if (!file || !file->f_dentry || !file->f_dentry->d_inode) {
- ret = -EINVAL;
- break;
- }
- to = file->f_dentry->d_inode;
-
- g.action = GSD_ACTION_ADD_GROUP_NODE;
- g.from = net_node_num;
- g.namelen = gsd_data.namelen;
- memcpy(g.name, gsd_data.name, gsd_data.namelen);
-
- if (to == net_inode) {
- /* create the group locally */
- ret = gsd_message_action(&g);
- } else {
- /* create the group on remote node */
- gsd_message_to_net(&g);
- ret = net_send_message(GSD_MESSAGE, 0, &g, sizeof(g), to, &response);
- if (ret == 0)
- ret = response;
- }
- memset(&gsd_data, 0, sizeof(gsd_ioc));
- gsd_data.status = ret;
- ret = copy_to_user((gsd_ioc *)arg, &gsd_data, sizeof(gsd_ioc));
+ ret = gsd_ioctl(inode, filp, cmd, arg);
break;
default:
ret = -ENOTTY;
@@ -500,100 +429,6 @@
return 0;
}
-//////////////////////////////////////////////////////////////////////////////
-/* for lack of a better place to do this */
-
-int gsd_setup()
-{
- int ret;
- /* need this stupidity until I can divorce the actual nm actions
- * from the output they send to their user buffer */
- gsd_handler_buf = (char *) __get_free_page(GFP_KERNEL);
- if (!gsd_handler_buf)
- return -ENOMEM;
-
- ret = net_register_handler(GSD_MESSAGE, 0, 0, sizeof(gsd_message),
- gsd_message_handler, NULL);
-
- return ret;
-}
-
-void gsd_teardown()
-{
- free_page((unsigned long)gsd_handler_buf);
-}
-
-int gsd_message_handler(net_msg *msg, u32 len, void *data)
-{
- gsd_message *g = (gsd_message *)msg->buf;
- gsd_message_to_host(g);
- return gsd_message_action(g);
-}
-
-int gsd_message_action(gsd_message *g)
-{
- int ret;
- nm_op op;
- int namelen = g->namelen;
- struct inode *node=NULL, *group=NULL;
- char name[NM_MAX_NAME_LEN+1];
-
- if (namelen > NM_MAX_NAME_LEN)
- return -EINVAL;
- strncpy(name, g->name, namelen);
- name[namelen] = '\0';
-
- memset(&op, 0, sizeof(op));
- switch (g->action) {
- case GSD_ACTION_ADD_GROUP:
- group = nm_get_group_by_name(name);
- if (group) {
- ret = 0;
- break;
- }
- op.arg_u.gc.group_num = NM_INVALID_SLOT_NUM;
- memcpy(op.arg_u.gc.name, name, namelen);
- memcpy(op.arg_u.gc.disk_uuid, name, namelen);
-
- ret = nm_create_group(gsd_handler_buf, &op);
- if (ret >= 0)
- ret = 0;
- break;
-
- case GSD_ACTION_ADD_GROUP_NODE:
- group = nm_get_group_by_name(name);
- if (!group) {
- ret = -EINVAL;
- break;
- }
- node = nm_get_group_node_by_index(group, g->from);
- if (node) {
- ret = 0;
- if (nm_get_node_global_index(node) != g->from)
- ret = -EINVAL;
- break;
- }
- op.arg_u.gc.group_num = nm_get_group_global_index(group);
- op.arg_u.gc.node_num = g->from;
- op.arg_u.gc.slot_num = g->from;
- ret = nm_add_node_to_group(gsd_handler_buf, &op);
- if (ret >= 0)
- ret = 0;
- break;
- default:
- ret = -EINVAL;
- break;
- }
-
- if (node)
- iput(node);
- if (group)
- iput(group);
- return ret;
-}
-
-//////////////////////////////////////////////////////////////////////////////
-
/* max_len is protection for the handler func. incoming messages won't
* be given to the handler if their payload is longer than the max. */
int net_register_handler(u32 msg_type, u32 key, int flags, u32 max_len,
More information about the Ocfs2-commits
mailing list