Whamcloud - gitweb
Branch: b_new_cmd
authorwangdi <wangdi>
Thu, 20 Jul 2006 10:19:11 +0000 (10:19 +0000)
committerwangdi <wangdi>
Thu, 20 Jul 2006 10:19:11 +0000 (10:19 +0000)
add mdd obd for llog and lov

lustre/mdd/Makefile.in
lustre/mdd/mdd_internal.h
lustre/mdd/mdd_lov.c
lustre/mdd/mdd_obd.c [new file with mode: 0644]
lustre/mds/handler.c

index a2a7249..308761f 100644 (file)
@@ -1,4 +1,4 @@
 MODULES := mdd
-mdd-objs := mdd_handler.o mdd_lov.o
+mdd-objs := mdd_handler.o mdd_lov.o mdd_obd.o
 
 @INCLUDE_RULES@
index fb7d30e..4090ed1 100644 (file)
 #include <asm/semaphore.h>
 #include <md_object.h>
 
+#define MDD_OBD_NAME    "mdd_obd"
+#define MDD_OBD_UUID    "mdd_obd_uuid"
+#define MDD_OBD_TYPE    "mds"
+#define MDD_OBD_PROFILE "lustre-client"
 struct dt_device;
 
 struct mdd_device {
index 86de339..6d36baa 100644 (file)
@@ -4,7 +4,7 @@
  *  linux/mds/mds_lov.c
  *  Lustre Metadata Server (mds) handling of striped file data
  *
- *  Copyright (C) 2001-2003 Cluster File Systems, Inc.
+ *  Copyright (C) 2001-2006 Cluster File Systems, Inc.
  *   Author: Peter Braam <braam@clusterfs.com>
  *           wangdi <wangdi@clusterfs.com>
  *
diff --git a/lustre/mdd/mdd_obd.c b/lustre/mdd/mdd_obd.c
new file mode 100644 (file)
index 0000000..c56e880
--- /dev/null
@@ -0,0 +1,118 @@
+/* -*- mode: c; c-basic-offset: 8; indent-tabs-mode: nil; -*-
+ * vim:expandtab:shiftwidth=8:tabstop=8:
+ *
+ *  linux/mds/mds_lov.c
+ *  Lustre Metadata Server (mdd) OBD  
+ *
+ *  Copyright (C) 2006 Cluster File Systems, Inc.
+ *   Author: wangdi <wangdi@clusterfs.com>
+ *
+ *   This file is part of the Lustre file system, http://www.lustre.org
+ *   Lustre is a trademark of Cluster File Systems, Inc.
+ *
+ *   You may have signed or agreed to another license before downloading
+ *   this software.  If so, you are bound by the terms and conditions
+ *   of that agreement, and the following does not apply to you.  See the
+ *   LICENSE file included with this distribution for more information.
+ *
+ *   If you did not agree to a different license, then this copy of Lustre
+ *   is open source 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.
+ *
+ *   In either case, 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
+ *   license text for more details.
+ */
+#ifndef EXPORT_SYMTAB
+# define EXPORT_SYMTAB
+#endif
+#define DEBUG_SUBSYSTEM S_MDS
+
+#include <linux/module.h>
+
+#include <obd.h>
+#include <obd_class.h>
+#include <lustre_ver.h>
+#include <obd_support.h>
+#include <obd_lov.h>
+#include <lprocfs_status.h>
+
+#include <lu_object.h>
+#include <md_object.h>
+#include <dt_object.h>
+#include <lustre_mds.h>
+#include <lustre/lustre_idl.h>
+
+#include "mdd_internal.h"
+
+/*The obd is created for using llog in mdd layer*/
+int mdd_new_obd(struct mdd_device *mdd)
+{
+        struct lustre_cfg_bufs bufs;
+        struct lustre_cfg      *lcfg;
+        struct obd_device      *obd; 
+        int rc;
+        ENTRY;
+        
+        lustre_cfg_bufs_reset(&bufs, MDD_OBD_NAME);
+        lustre_cfg_bufs_set_string(&bufs, 1, MDD_OBD_TYPE);
+        lustre_cfg_bufs_set_string(&bufs, 2, MDD_OBD_UUID);
+        lustre_cfg_bufs_set_string(&bufs, 3, MDD_OBD_UUID);
+
+        lcfg = lustre_cfg_new(LCFG_ATTACH, &bufs);
+        if (!lcfg)
+                RETURN(-ENOMEM);
+        
+        rc = class_attach(lcfg);
+        if (rc)
+                GOTO(lcfg_cleanup, rc);
+       
+        obd = class_name2obd(MDD_OBD_NAME);
+        if (!obd) {
+                CERROR("can not find obd %s \n", MDD_OBD_NAME);
+                LBUG();
+        }
+        
+        rc = class_setup(obd, lcfg);
+        if (rc)
+                GOTO(class_detach, rc);
+        
+        mdd->mdd_md_dev.md_lu_dev.ld_obd = obd;
+class_detach:
+        if (rc)
+                class_detach(obd, lcfg);
+lcfg_cleanup:
+        lustre_cfg_free(lcfg);
+        RETURN(rc);
+}
+
+int mdd_cleanup_obd(struct mdd_device *mdd)
+{
+        struct lustre_cfg_bufs bufs;
+        struct lustre_cfg      *lcfg;
+        struct obd_device      *obd; 
+        int rc;
+        ENTRY;
+        
+        obd = mdd->mdd_md_dev.md_lu_dev.ld_obd;
+        LASSERT(obd);
+        lustre_cfg_bufs_reset(&bufs, MDD_OBD_NAME);
+        lcfg = lustre_cfg_new(LCFG_ATTACH, &bufs);
+       
+        if (!lcfg)
+                RETURN(-ENOMEM);
+
+        rc = class_cleanup(obd, lcfg);
+        if (rc)
+                GOTO(lcfg_cleanup, rc);
+        
+        rc = class_detach(obd, lcfg);
+        if (rc)
+                GOTO(lcfg_cleanup, rc);
+        mdd->mdd_md_dev.md_lu_dev.ld_obd = NULL;
+lcfg_cleanup:
+        lustre_cfg_free(lcfg);
+        RETURN(rc);
+}
index 0082869..fac5b55 100644 (file)
@@ -1786,6 +1786,30 @@ void fsoptions_to_mds_flags(struct mds_obd *mds, char *options)
                 options = ++p;
         }
 }
+static int mds_lov_presetup (struct mds_obd *mds, struct lustre_cfg *lcfg)
+{
+        int rc;
+        ENTRY;
+
+        rc = llog_start_commit_thread();
+        if (rc < 0)
+                RETURN(rc);
+
+        if (lcfg->lcfg_bufcount >= 4 && LUSTRE_CFG_BUFLEN(lcfg, 3) > 0) {
+                class_uuid_t uuid;
+
+                generate_random_uuid(uuid);
+                class_uuid_unparse(uuid, &mds->mds_lov_uuid);
+
+                OBD_ALLOC(mds->mds_profile, LUSTRE_CFG_BUFLEN(lcfg, 3));
+                if (mds->mds_profile == NULL)
+                        RETURN(-ENOMEM);
+
+                strncpy(mds->mds_profile, lustre_cfg_string(lcfg, 3),
+                        LUSTRE_CFG_BUFLEN(lcfg, 3));
+        }
+        RETURN(rc);
+}
 
 /* mount the file system (secretly).  lustre_cfg parameters are:
  * 1 = device
@@ -1808,7 +1832,7 @@ static int mds_setup(struct obd_device *obd, struct lustre_cfg* lcfg)
         ENTRY;
 
         /* setup 1:/dev/loop/0 2:ext3 3:mdsA 4:errors=remount-ro,iopen_nopriv */
-
+        
         CLASSERT(offsetof(struct obd_device, u.obt) ==
                  offsetof(struct obd_device, u.mds.mds_obt));
 
@@ -1889,24 +1913,10 @@ static int mds_setup(struct obd_device *obd, struct lustre_cfg* lcfg)
                 GOTO(err_ns, rc);
         }
 
-        rc = llog_start_commit_thread();
+        rc = mds_lov_presetup(mds, lcfg);
         if (rc < 0)
                 GOTO(err_fs, rc);
 
-        if (lcfg->lcfg_bufcount >= 4 && LUSTRE_CFG_BUFLEN(lcfg, 3) > 0) {
-                class_uuid_t uuid;
-
-                generate_random_uuid(uuid);
-                class_uuid_unparse(uuid, &mds->mds_lov_uuid);
-
-                OBD_ALLOC(mds->mds_profile, LUSTRE_CFG_BUFLEN(lcfg, 3));
-                if (mds->mds_profile == NULL)
-                        GOTO(err_fs, rc = -ENOMEM);
-
-                strncpy(mds->mds_profile, lustre_cfg_string(lcfg, 3),
-                        LUSTRE_CFG_BUFLEN(lcfg, 3));
-        }
-
         ptlrpc_init_client(LDLM_CB_REQUEST_PORTAL, LDLM_CB_REPLY_PORTAL,
                            "mds_ldlm_client", &obd->obd_ldlm_client);
         obd->obd_replayable = 1;
@@ -2663,12 +2673,27 @@ static __attribute__((unused)) void /*__exit*/ mds_exit(void)
         class_unregister_type(LUSTRE_MDS_NAME);
         class_unregister_type(LUSTRE_MDT_NAME);
 }
-
+/*mds still need lov setup here*/
 static int mds_cmd_setup(struct obd_device *obd, struct lustre_cfg *lcfg)
 {
+        struct mds_obd *mds = &obd->u.mds;
+        int rc = 0;
         ENTRY;
 
-        RETURN(0);
+        CDEBUG(D_INFO, "obd %s setup \n", obd->obd_name);
+        if (strcmp(obd->obd_name, "mdd_obd"))
+                RETURN(0);
+        
+        rc = mds_lov_presetup(mds, lcfg);
+        if (rc < 0)
+                RETURN(rc);
+
+        /* Don't wait for mds_postrecov trying to clear orphans */
+        obd->obd_async_recov = 1;
+        rc = mds_postsetup(obd);
+        obd->obd_async_recov = 0;
+
+        RETURN(rc);
 }
 
 static int mds_cmd_cleanup(struct obd_device *obd)
@@ -2688,6 +2713,12 @@ static struct obd_ops mds_cmd_obd_ops = {
         .o_owner           = THIS_MODULE,
         .o_setup           = mds_cmd_setup,
         .o_cleanup         = mds_cmd_cleanup,
+        .o_precleanup      = mds_precleanup,
+        .o_create          = mds_obd_create,
+        .o_destroy         = mds_obd_destroy,
+        .o_llog_init       = mds_llog_init,
+        .o_llog_finish     = mds_llog_finish,
+        .o_notify          = mds_notify,
         .o_health_check    = mds_cmd_health_check,
 };