Whamcloud - gitweb
88fe853768796d29672c5ab8d1bee3a316b7fcb1
[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  *  lustre/mgc/mgc_request.c
5  *  Lustre Management Client
6  *
7  *  Copyright (C) 2006 Cluster File Systems, Inc.
8  *   Author: Nathan Rutman <nathan@clusterfs.com>
9  *
10  *   This file is part of Lustre, http://www.lustre.org
11  *
12  *   Lustre is free software; you can redistribute it and/or
13  *   modify it under the terms of version 2 of the GNU General Public
14  *   License as published by the Free Software Foundation.
15  *
16  *   Lustre is distributed in the hope that it will be useful,
17  *   but WITHOUT ANY WARRANTY; without even the implied warranty of
18  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
19  *   GNU General Public License for more details.
20  *
21  *   You should have received a copy of the GNU General Public License
22  *   along with Lustre; if not, write to the Free Software
23  *   Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
24  *
25  */
26 /* Minimal MGC for liblustre: only used to read the config log from the MGS
27    at setup time, no updates. */
28  
29 #ifndef EXPORT_SYMTAB
30 # define EXPORT_SYMTAB
31 #endif
32 #define DEBUG_SUBSYSTEM S_MGC
33
34 #include <liblustre.h>
35
36 #include <obd_class.h>
37 #include <lustre_dlm.h>
38 #include <lustre_log.h>
39 #include <lustre_fsfilt.h>
40 #include <lustre_disk.h>
41
42
43 static int mgc_setup(struct obd_device *obd, struct lustre_cfg *lcfg)
44 {
45         int rc;
46         ENTRY;
47
48         ptlrpcd_addref();
49
50         rc = client_obd_setup(obd, lcfg);
51         if (rc)
52                 GOTO(err_decref, rc);
53
54         rc = obd_llog_init(obd, NULL, obd, 0, NULL, NULL);
55         if (rc) {
56                 CERROR("failed to setup llogging subsystems\n");
57                 GOTO(err_cleanup, rc);
58         }
59
60         RETURN(rc);
61
62 err_cleanup:
63         client_obd_cleanup(obd);
64 err_decref:
65         ptlrpcd_decref();
66         RETURN(rc);
67 }
68
69 static int mgc_precleanup(struct obd_device *obd, enum obd_cleanup_stage stage)
70 {
71         int rc = 0;
72         ENTRY;
73
74         switch (stage) {
75         case OBD_CLEANUP_EARLY: 
76         case OBD_CLEANUP_EXPORTS:
77                 break;
78         case OBD_CLEANUP_SELF_EXP:
79                 rc = obd_llog_finish(obd, 0);
80                 if (rc != 0)
81                         CERROR("failed to cleanup llogging subsystems\n");
82                 break;
83         case OBD_CLEANUP_OBD:
84                 break;
85         }
86         RETURN(rc);
87 }
88
89 static int mgc_cleanup(struct obd_device *obd)
90 {
91         struct client_obd *cli = &obd->u.cli;
92         int rc;
93         ENTRY;
94
95         LASSERT(cli->cl_mgc_vfsmnt == NULL);
96         
97         ptlrpcd_decref();
98
99         rc = client_obd_cleanup(obd);
100         RETURN(rc);
101 }
102
103 static int mgc_llog_init(struct obd_device *obd, struct obd_llogs *llogs,
104                          struct obd_device *tgt, int count, 
105                          struct llog_catid *logid, struct obd_uuid *uuid)
106 {
107         struct llog_ctxt *ctxt;
108         int rc;
109         ENTRY;
110
111         rc = llog_setup(obd, llogs, LLOG_CONFIG_REPL_CTXT, tgt, 0, NULL,
112                         &llog_client_ops);
113         if (rc == 0) {
114                 ctxt = llog_get_context(obd, LLOG_CONFIG_REPL_CTXT);
115                 ctxt->loc_imp = obd->u.cli.cl_import;
116         }
117
118         RETURN(rc);
119 }
120
121 static int mgc_llog_finish(struct obd_device *obd, int count)
122 {
123         int rc;
124         ENTRY;
125
126         rc = llog_cleanup(llog_get_context(obd, LLOG_CONFIG_REPL_CTXT));
127
128         RETURN(rc);
129 }
130
131 struct obd_ops mgc_obd_ops = {
132         .o_owner        = THIS_MODULE,
133         .o_setup        = mgc_setup,
134         .o_precleanup   = mgc_precleanup,
135         .o_cleanup      = mgc_cleanup,
136         .o_add_conn     = client_import_add_conn,
137         .o_del_conn     = client_import_del_conn,
138         .o_connect      = client_connect_import,
139         .o_disconnect   = client_disconnect_export,
140         .o_llog_init    = mgc_llog_init,
141         .o_llog_finish  = mgc_llog_finish,
142 };
143
144 int __init mgc_init(void)
145 {
146         return class_register_type(&mgc_obd_ops, NULL, 
147                                    NULL, LUSTRE_MGC_NAME, NULL);
148 }
149