Whamcloud - gitweb
new mgc obd
authorlincent <lincent>
Tue, 2 Aug 2005 10:26:45 +0000 (10:26 +0000)
committerlincent <lincent>
Tue, 2 Aug 2005 10:26:45 +0000 (10:26 +0000)
lustre/mgc/Makefile.in [new file with mode: 0644]
lustre/mgc/autoMakefile.am [new file with mode: 0644]
lustre/mgc/mgc_internal.h [new file with mode: 0644]
lustre/mgc/mgc_request.c [new file with mode: 0644]

diff --git a/lustre/mgc/Makefile.in b/lustre/mgc/Makefile.in
new file mode 100644 (file)
index 0000000..2d7cad5
--- /dev/null
@@ -0,0 +1,4 @@
+MODULES := mgc
+mgc-objs := mgc_request.o
+
+@INCLUDE_RULES@
diff --git a/lustre/mgc/autoMakefile.am b/lustre/mgc/autoMakefile.am
new file mode 100644 (file)
index 0000000..2b3a807
--- /dev/null
@@ -0,0 +1,11 @@
+# Copyright (C) 2001  Cluster File Systems, Inc.
+#
+# This code is issued under the GNU General Public License.
+# See the file COPYING in this distribution
+
+if MODULES
+modulefs_DATA = mgc$(KMODEXT)
+endif
+
+MOSTLYCLEANFILES := @MOSTLYCLEANFILES@ 
+DIST_SOURCES := $(mgc-objs:%.o=%.c)
diff --git a/lustre/mgc/mgc_internal.h b/lustre/mgc/mgc_internal.h
new file mode 100644 (file)
index 0000000..8005ad3
--- /dev/null
@@ -0,0 +1,17 @@
+/* -*- mode: c; c-basic-offset: 8; indent-tabs-mode: nil; -*-
+ * vim:expandtab:shiftwidth=8:tabstop=8:
+ */
+
+#ifndef MGC_INTERNAL_H
+#define MGC_INTERNAL_H
+
+struct mgc_rpc_lock {
+        struct semaphore rpcl_sem;
+};
+
+static inline void mgc_init_rpc_lock(struct mgc_rpc_lock *lck)
+{
+        sema_init(&lck->rpcl_sem, 1);
+}
+
+#endif
diff --git a/lustre/mgc/mgc_request.c b/lustre/mgc/mgc_request.c
new file mode 100644 (file)
index 0000000..b5cafc1
--- /dev/null
@@ -0,0 +1,255 @@
+/* -*- mode: c; c-basic-offset: 8; indent-tabs-mode: nil; -*-
+ * vim:expandtab:shiftwidth=8:tabstop=8:
+ *
+ *  Copyright (C) 2001-2005 Cluster File Systems, Inc.
+ *   Author Nathan <nathan@clusterfs.com>
+ *   Author LinSongTao <lincent@clusterfs.com>
+ *
+ *   This file is part of Lustre, http://www.lustre.org
+ *
+ *   Lustre is free software; you can redistribute it and/or
+ *   modify it under the terms of version 2 of the GNU General Public
+ *   License as published by the Free Software Foundation.
+ *
+ *   Lustre 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 Lustre; if not, write to the Free Software
+ *   Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ *
+ *  For testing and management it is treated as an obd_device,
+ *  although * it does not export a full OBD method table (the
+ *  requests are coming * in over the wire, so object target modules
+ *  do not have a full * method table.)
+ */
+
+#ifndef EXPORT_SYMTAB
+# define EXPORT_SYMTAB
+#endif
+#define DEBUG_SUBSYSTEM S_MGC
+
+#ifdef __KERNEL__
+# include <linux/module.h>
+# include <linux/pagemap.h>
+# include <linux/miscdevice.h>
+# include <linux/init.h>
+#else
+# include <liblustre.h>
+#endif
+
+#include <linux/obd_class.h>
+//#include <linux/lustre_mds.h>
+#include <linux/lustre_dlm.h>
+#include <linux/lprocfs_status.h>
+#include "mgc_internal.h"
+
+static int mgc_setup(struct obd_device *obd, obd_count len, void *buf)
+{
+        struct mgc_obd *mgc = &obd->u.mgc;
+        struct lprocfs_static_vars lvars;
+        int rc;
+        ENTRY;
+
+        OBD_ALLOC(mgc->cl_rpc_lock, sizeof (*mgc->cl_rpc_lock));
+        if (!mgc->cl_rpc_lock)
+                RETURN(-ENOMEM);
+        mgc_init_rpc_lock(mgc->cl_rpc_lock);
+
+        ptlrpcd_addref();
+
+        rc = mgc_obd_setup(obd, len, buf);
+        if (rc)
+                GOTO(err_rpc_lock, rc);
+        lprocfs_init_vars(mgc, &lvars);
+        lprocfs_obd_setup(obd, lvars.obd_vars);
+
+        rc = obd_llog_init(obd, obd, 0, NULL);
+        if (rc) {
+                mgc_cleanup(obd);
+                CERROR("failed to setup llogging subsystems\n");
+        }
+        RETURN(rc);
+
+err_rpc_lock:
+        OBD_FREE(mgc->cl_rpc_lock, sizeof (*mgc->cl_rpc_lock));
+        ptlrpcd_decref();
+        RETURN(rc);
+}
+
+static int mgc_precleanup(struct obd_device *obd, int stage)
+{
+        int rc = 0;
+        ENTRY;
+
+        if (stage < 2)
+                RETURN(0);
+
+        rc = obd_llog_finish(obd, 0);
+        if (rc != 0)
+                CERROR("failed to cleanup llogging subsystems\n");
+
+        RETURN(rc);
+}
+
+static int mgc_cleanup(struct obd_device *obd)
+{
+        struct mgc_obd *mgc = &obd->u.mgc;
+
+        OBD_FREE(mgc->cl_rpc_lock, sizeof (*mgc->cl_rpc_lock));
+
+        lprocfs_obd_cleanup(obd);
+        ptlrpcd_decref();
+
+        return mgc_obd_cleanup(obd);
+}
+
+static int mgc_iocontrol(unsigned int cmd, struct obd_export *exp, int len,
+                         void *karg, void *uarg)
+{
+        struct obd_device *obd = exp->exp_obd;
+        struct obd_ioctl_data *data = karg;
+        struct obd_import *imp = obd->u.mgc.cl_import;
+        struct llog_ctxt *ctxt;
+        int rc;
+        ENTRY;
+
+#if (LINUX_VERSION_CODE < KERNEL_VERSION(2,5,0))
+        MOD_INC_USE_COUNT;
+#else
+        if (!try_module_get(THIS_MODULE)) {
+                CERROR("Can't get module. Is it alive?");
+                return -EINVAL;
+        }
+#endif
+        switch (cmd) {
+        case OBD_IOC_CLIENT_RECOVER:
+                rc = ptlrpc_recover_import(imp, data->ioc_inlbuf1);
+                if (rc < 0)
+                        GOTO(out, rc);
+                GOTO(out, rc = 0);
+        case IOC_OSC_SET_ACTIVE:
+                rc = ptlrpc_set_import_active(imp, data->ioc_offset);
+                GOTO(out, rc);
+        case OBD_IOC_PARSE: {
+                ctxt = llog_get_context(exp->exp_obd, LLOG_CONFIG_REPL_CTXT);
+                rc = class_config_parse_llog(ctxt, data->ioc_inlbuf1, NULL);
+                GOTO(out, rc);
+        }
+#ifdef __KERNEL__
+        case OBD_IOC_LLOG_INFO:
+        case OBD_IOC_LLOG_PRINT: {
+                ctxt = llog_get_context(obd, LLOG_CONFIG_REPL_CTXT);
+                rc = llog_ioctl(ctxt, cmd, data);
+
+                GOTO(out, rc);
+        }
+#endif
+        default:
+                CERROR("mgc_ioctl(): unrecognised ioctl %#x\n", cmd);
+                GOTO(out, rc = -ENOTTY);
+        }
+out:
+#if (LINUX_VERSION_CODE < KERNEL_VERSION(2,5,0))
+        MOD_DEC_USE_COUNT;
+#else
+        module_put(THIS_MODULE);
+#endif
+
+        return rc;
+}
+
+static int mgc_import_event(struct obd_device *obd,
+                            struct obd_import *imp,
+                            enum obd_import_event event)
+{
+        int rc = 0;
+
+        LASSERT(imp->imp_obd == obd);
+
+        switch (event) {
+        case IMP_EVENT_DISCON: {
+                break;
+        }
+        case IMP_EVENT_INACTIVE: {
+                if (obd->obd_observer)
+                        rc = obd_notify(obd->obd_observer, obd, 0);
+                break;
+        }
+        case IMP_EVENT_ACTIVE: {
+                if (obd->obd_observer)
+                        rc = obd_notify(obd->obd_observer, obd, 1);
+                break;
+        }
+        default:
+                CERROR("Unknown import event %d\n", event);
+                LBUG();
+        }
+        RETURN(rc);
+}
+
+static int mgc_llog_init(struct obd_device *obd, struct obd_device *tgt,
+                         int count, struct llog_catid *logid)
+{
+        struct llog_ctxt *ctxt;
+        int rc;
+        ENTRY;
+
+        rc = llog_setup(obd, LLOG_CONFIG_REPL_CTXT, tgt, 0, NULL,
+                        &llog_client_ops);
+        if (rc == 0) {
+                ctxt = llog_get_context(obd, LLOG_CONFIG_REPL_CTXT);
+                ctxt->loc_imp = obd->u.mgc.cl_import;
+        }
+
+        RETURN(rc);
+}
+
+static int mgc_llog_finish(struct obd_device *obd, int count)
+{
+        int rc;
+        ENTRY;
+
+        rc = llog_cleanup(llog_get_context(obd, LLOG_CONFIG_REPL_CTXT));
+        RETURN(rc);
+}
+
+/* reuse the client_import_[add/del]_conn*/
+struct obd_ops mgc_obd_ops = {
+        .o_owner        = THIS_MODULE,
+        .o_setup        = mgc_setup,
+        .o_precleanup   = mgc_precleanup,
+        .o_cleanup      = mgc_cleanup,
+        .o_add_conn     = client_import_add_conn,
+        .o_del_conn     = client_import_del_conn,
+        .o_connect      = mgc_connect_import,
+        .o_disconnect   = mgc_disconnect_export,
+        .o_iocontrol    = mgc_iocontrol,
+        .o_import_event = mgc_import_event,
+        .o_llog_init    = mgc_llog_init,
+        .o_llog_finish  = mgc_llog_finish,
+};
+
+int __init mgc_init(void)
+{
+        struct lprocfs_static_vars lvars;
+        lprocfs_init_vars(mgc, &lvars);
+        return class_register_type(&mgc_obd_ops, lvars.module_vars,
+                                   LUSTRE_MGC_NAME);
+}
+
+#ifdef __KERNEL__
+static void /*__exit*/ mgc_exit(void)
+{
+        class_unregister_type(LUSTRE_MGC_NAME);
+}
+
+MODULE_AUTHOR("Cluster File Systems, Inc. <info@clusterfs.com>");
+MODULE_DESCRIPTION("Lustre Management Client");
+MODULE_LICENSE("GPL");
+
+module_init(mgc_init);
+module_exit(mgc_exit);
+#endif