Whamcloud - gitweb
b=11691
[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 static int mgc_setup(struct obd_device *obd, obd_count len, void *buf)
43 {
44         int rc;
45         ENTRY;
46
47         ptlrpcd_addref();
48
49         rc = client_obd_setup(obd, len, buf);
50         if (rc)
51                 GOTO(err_decref, rc);
52
53         rc = obd_llog_init(obd, obd, 0, NULL, NULL);
54         if (rc) {
55                 CERROR("failed to setup llogging subsystems\n");
56                 GOTO(err_cleanup, rc);
57         }
58
59         RETURN(rc);
60
61 err_cleanup:
62         client_obd_cleanup(obd);
63 err_decref:
64         ptlrpcd_decref();
65         RETURN(rc);
66 }
67
68 static int mgc_precleanup(struct obd_device *obd, enum obd_cleanup_stage stage)
69 {
70         int rc = 0;
71         ENTRY;
72
73         switch (stage) {
74         case OBD_CLEANUP_EARLY: 
75         case OBD_CLEANUP_EXPORTS:
76                 break;
77         case OBD_CLEANUP_SELF_EXP:
78                 rc = obd_llog_finish(obd, 0);
79                 if (rc != 0)
80                         CERROR("failed to cleanup llogging subsystems\n");
81                 break;
82         case OBD_CLEANUP_OBD:
83                 break;
84         }
85         RETURN(rc);
86 }
87
88 static int mgc_cleanup(struct obd_device *obd)
89 {
90         struct client_obd *cli = &obd->u.cli;
91         int rc;
92         ENTRY;
93
94         LASSERT(cli->cl_mgc_vfsmnt == NULL);
95         
96         ptlrpcd_decref();
97
98         rc = client_obd_cleanup(obd);
99         RETURN(rc);
100 }
101
102 static int mgc_llog_init(struct obd_device *obd, struct obd_device *tgt,
103                          int count, struct llog_catid *logid, 
104                          struct obd_uuid *uuid)
105 {
106         struct llog_ctxt *ctxt;
107         int rc;
108         ENTRY;
109
110         rc = llog_setup(obd, LLOG_CONFIG_REPL_CTXT, tgt, 0, NULL,
111                         &llog_client_ops);
112         if (rc == 0) {
113                 ctxt = llog_get_context(obd, LLOG_CONFIG_REPL_CTXT);
114                 ctxt->loc_imp = obd->u.cli.cl_import;
115         }
116
117         RETURN(rc);
118 }
119
120 static int mgc_llog_finish(struct obd_device *obd, int count)
121 {
122         int rc;
123         ENTRY;
124
125         rc = llog_cleanup(llog_get_context(obd, LLOG_CONFIG_REPL_CTXT));
126
127         RETURN(rc);
128 }
129
130 struct obd_ops mgc_obd_ops = {
131         .o_owner        = THIS_MODULE,
132         .o_setup        = mgc_setup,
133         .o_precleanup   = mgc_precleanup,
134         .o_cleanup      = mgc_cleanup,
135         .o_add_conn     = client_import_add_conn,
136         .o_del_conn     = client_import_del_conn,
137         .o_connect      = client_connect_import,
138         .o_disconnect   = client_disconnect_export,
139         .o_llog_init    = mgc_llog_init,
140         .o_llog_finish  = mgc_llog_finish,
141 };
142
143 int __init mgc_init(void)
144 {
145         return class_register_type(&mgc_obd_ops, NULL, LUSTRE_MGC_NAME);
146 }
147