Whamcloud - gitweb
LU-3810 obd: Cleanup client import if client_obd_setup fails
[fs/lustre-release.git] / lustre / mgc / libmgc.c
index a9f6737..bcc3617 100644 (file)
@@ -1,6 +1,4 @@
-/* -*- mode: c; c-basic-offset: 8; indent-tabs-mode: nil; -*-
- * vim:expandtab:shiftwidth=8:tabstop=8:
- *
+/*
  * GPL HEADER START
  *
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  * GPL HEADER END
  */
 /*
- * Copyright  2008 Sun Microsystems, Inc. All rights reserved
+ * Copyright (c) 2007, 2010, Oracle and/or its affiliates. All rights reserved.
  * Use is subject to license terms.
+ *
+ * Copyright (c) 2011, 2012, Intel Corporation.
  */
 /*
  * This file is part of Lustre, http://www.lustre.org/
 
 /* Minimal MGC for liblustre: only used to read the config log from the MGS
    at setup time, no updates. */
-#ifndef EXPORT_SYMTAB
-# define EXPORT_SYMTAB
-#endif
+
 #define DEBUG_SUBSYSTEM S_MGC
 
 #include <liblustre.h>
 #include <obd_class.h>
 #include <lustre_dlm.h>
 #include <lustre_log.h>
-#include <lustre_fsfilt.h>
 #include <lustre_disk.h>
 
-
 static int mgc_setup(struct obd_device *obd, struct lustre_cfg *lcfg)
 {
-        int rc;
-        ENTRY;
+       int rc;
+       ENTRY;
 
-        ptlrpcd_addref();
+       rc = ptlrpcd_addref();
+       if (rc < 0)
+               RETURN(rc);
 
-        rc = client_obd_setup(obd, lcfg);
-        if (rc)
-                GOTO(err_decref, rc);
+       rc = client_obd_setup(obd, lcfg);
+       if (rc)
+               GOTO(err_decref, rc);
 
-        rc = obd_llog_init(obd, &obd->obd_olg, obd, 0, NULL, NULL);
-        if (rc) {
-                CERROR("failed to setup llogging subsystems\n");
-                GOTO(err_cleanup, rc);
-        }
+       /* liblustre only support null flavor to MGS */
+       obd->u.cli.cl_flvr_mgc.sf_rpc = SPTLRPC_FLVR_NULL;
 
-        RETURN(rc);
+       rc = obd_llog_init(obd, &obd->obd_olg, obd, NULL);
+       if (rc) {
+               CERROR("failed to setup llogging subsystems\n");
+               GOTO(err_cleanup, rc);
+       }
+
+       RETURN(rc);
 
 err_cleanup:
-        client_obd_cleanup(obd);
+       client_obd_cleanup(obd);
 err_decref:
-        ptlrpcd_decref();
-        RETURN(rc);
+       ptlrpcd_decref();
+       RETURN(rc);
 }
 
 static int mgc_precleanup(struct obd_device *obd, enum obd_cleanup_stage stage)
@@ -88,8 +88,9 @@ static int mgc_precleanup(struct obd_device *obd, enum obd_cleanup_stage stage)
         ENTRY;
 
         switch (stage) {
-        case OBD_CLEANUP_EARLY: 
+        case OBD_CLEANUP_EARLY:
         case OBD_CLEANUP_EXPORTS:
+                obd_cleanup_client_import(obd);
                 rc = obd_llog_finish(obd, 0);
                 if (rc != 0)
                         CERROR("failed to cleanup llogging subsystems\n");
@@ -100,12 +101,9 @@ static int mgc_precleanup(struct obd_device *obd, enum obd_cleanup_stage stage)
 
 static int mgc_cleanup(struct obd_device *obd)
 {
-        struct client_obd *cli = &obd->u.cli;
         int rc;
         ENTRY;
 
-        LASSERT(cli->cl_mgc_vfsmnt == NULL);
-
         ptlrpcd_decref();
 
         rc = client_obd_cleanup(obd);
@@ -113,33 +111,36 @@ static int mgc_cleanup(struct obd_device *obd)
 }
 
 static int mgc_llog_init(struct obd_device *obd, struct obd_llog_group *olg,
-                         struct obd_device *tgt, int count, 
-                         struct llog_catid *logid, struct obd_uuid *uuid)
+                         struct obd_device *tgt, int *index)
 {
         struct llog_ctxt *ctxt;
         int rc;
         ENTRY;
 
         LASSERT(olg == &obd->obd_olg);
-        rc = llog_setup(obd, olg, LLOG_CONFIG_REPL_CTXT, tgt, 0, NULL,
-                        &llog_client_ops);
-        if (rc == 0) {
-                ctxt = llog_group_get_ctxt(olg, LLOG_CONFIG_REPL_CTXT);
-                llog_initiator_connect(ctxt);
-                llog_ctxt_put(ctxt);
-        }
+       rc = llog_setup(NULL, obd, olg, LLOG_CONFIG_REPL_CTXT, tgt,
+                       &llog_client_ops);
+       if (rc < 0)
+               RETURN(rc);
 
-        RETURN(rc);
+       ctxt = llog_group_get_ctxt(olg, LLOG_CONFIG_REPL_CTXT);
+       llog_initiator_connect(ctxt);
+       llog_ctxt_put(ctxt);
+
+       RETURN(rc);
 }
 
 static int mgc_llog_finish(struct obd_device *obd, int count)
 {
-        int rc;
-        ENTRY;
+       struct llog_ctxt *ctxt;
 
-        rc = llog_cleanup(llog_get_context(obd, LLOG_CONFIG_REPL_CTXT));
+       ENTRY;
 
-        RETURN(rc);
+       ctxt = llog_get_context(obd, LLOG_CONFIG_REPL_CTXT);
+       if (ctxt)
+               llog_cleanup(NULL, ctxt);
+
+       RETURN(0);
 }
 
 struct obd_ops mgc_obd_ops = {
@@ -157,6 +158,6 @@ struct obd_ops mgc_obd_ops = {
 
 int __init mgc_init(void)
 {
-        return class_register_type(&mgc_obd_ops, NULL, 
+        return class_register_type(&mgc_obd_ops, NULL,
                                    NULL, LUSTRE_MGC_NAME, NULL);
 }