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