Whamcloud - gitweb
LU-327 cleanup the client import of mgc
[fs/lustre-release.git] / lustre / mgc / libmgc.c
1 /* -*- mode: c; c-basic-offset: 8; indent-tabs-mode: nil; -*-
2  * vim:expandtab:shiftwidth=8:tabstop=8:
3  *
4  * GPL HEADER START
5  *
6  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
7  *
8  * This program is free software; you can redistribute it and/or modify
9  * it under the terms of the GNU General Public License version 2 only,
10  * as published by the Free Software Foundation.
11  *
12  * This program is distributed in the hope that it will be useful, but
13  * WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
15  * General Public License version 2 for more details (a copy is included
16  * in the LICENSE file that accompanied this code).
17  *
18  * You should have received a copy of the GNU General Public License
19  * version 2 along with this program; If not, see
20  * http://www.sun.com/software/products/lustre/docs/GPLv2.pdf
21  *
22  * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
23  * CA 95054 USA or visit www.sun.com if you need additional information or
24  * have any questions.
25  *
26  * GPL HEADER END
27  */
28 /*
29  * Copyright (c) 2007, 2010, Oracle and/or its affiliates. All rights reserved.
30  * Use is subject to license terms.
31  */
32 /*
33  * This file is part of Lustre, http://www.lustre.org/
34  * Lustre is a trademark of Sun Microsystems, Inc.
35  *
36  * lustre/mgc/libmgc.c
37  *
38  * Lustre Management Client
39  * Author: Nathan Rutman <nathan@clusterfs.com>
40  */
41
42 /* Minimal MGC for liblustre: only used to read the config log from the MGS
43    at setup time, no updates. */
44
45 #ifndef EXPORT_SYMTAB
46 # define EXPORT_SYMTAB
47 #endif
48 #define DEBUG_SUBSYSTEM S_MGC
49
50 #include <liblustre.h>
51
52 #include <obd_class.h>
53 #include <lustre_dlm.h>
54 #include <lustre_log.h>
55 #include <lustre_fsfilt.h>
56 #include <lustre_disk.h>
57
58
59 static int mgc_setup(struct obd_device *obd, struct lustre_cfg *lcfg)
60 {
61         int rc;
62         ENTRY;
63
64         ptlrpcd_addref();
65
66         rc = client_obd_setup(obd, lcfg);
67         if (rc)
68                 GOTO(err_decref, rc);
69
70         /* liblustre only support null flavor to MGS */
71         obd->u.cli.cl_flvr_mgc.sf_rpc = SPTLRPC_FLVR_NULL;
72
73         rc = obd_llog_init(obd, &obd->obd_olg, obd, NULL);
74         if (rc) {
75                 CERROR("failed to setup llogging subsystems\n");
76                 GOTO(err_cleanup, rc);
77         }
78
79         RETURN(rc);
80
81 err_cleanup:
82         client_obd_cleanup(obd);
83 err_decref:
84         ptlrpcd_decref();
85         RETURN(rc);
86 }
87
88 static int mgc_precleanup(struct obd_device *obd, enum obd_cleanup_stage stage)
89 {
90         int rc = 0;
91         ENTRY;
92
93         switch (stage) {
94         case OBD_CLEANUP_EARLY:
95         case OBD_CLEANUP_EXPORTS:
96                 obd_cleanup_client_import(obd);
97                 rc = obd_llog_finish(obd, 0);
98                 if (rc != 0)
99                         CERROR("failed to cleanup llogging subsystems\n");
100                 break;
101         }
102         RETURN(rc);
103 }
104
105 static int mgc_cleanup(struct obd_device *obd)
106 {
107         struct client_obd *cli = &obd->u.cli;
108         int rc;
109         ENTRY;
110
111         LASSERT(cli->cl_mgc_vfsmnt == NULL);
112
113         ptlrpcd_decref();
114
115         rc = client_obd_cleanup(obd);
116         RETURN(rc);
117 }
118
119 static int mgc_llog_init(struct obd_device *obd, struct obd_llog_group *olg,
120                          struct obd_device *tgt, int *index)
121 {
122         struct llog_ctxt *ctxt;
123         int rc;
124         ENTRY;
125
126         LASSERT(olg == &obd->obd_olg);
127         rc = llog_setup(obd, olg, LLOG_CONFIG_REPL_CTXT, tgt, 0, NULL,
128                         &llog_client_ops);
129         if (rc == 0) {
130                 ctxt = llog_group_get_ctxt(olg, LLOG_CONFIG_REPL_CTXT);
131                 llog_initiator_connect(ctxt);
132                 llog_ctxt_put(ctxt);
133         }
134
135         RETURN(rc);
136 }
137
138 static int mgc_llog_finish(struct obd_device *obd, int count)
139 {
140         int rc;
141         ENTRY;
142
143         rc = llog_cleanup(llog_get_context(obd, LLOG_CONFIG_REPL_CTXT));
144
145         RETURN(rc);
146 }
147
148 struct obd_ops mgc_obd_ops = {
149         .o_owner        = THIS_MODULE,
150         .o_setup        = mgc_setup,
151         .o_precleanup   = mgc_precleanup,
152         .o_cleanup      = mgc_cleanup,
153         .o_add_conn     = client_import_add_conn,
154         .o_del_conn     = client_import_del_conn,
155         .o_connect      = client_connect_import,
156         .o_disconnect   = client_disconnect_export,
157         .o_llog_init    = mgc_llog_init,
158         .o_llog_finish  = mgc_llog_finish,
159 };
160
161 int __init mgc_init(void)
162 {
163         return class_register_type(&mgc_obd_ops, NULL,
164                                    NULL, LUSTRE_MGC_NAME, NULL);
165 }