Whamcloud - gitweb
b=19933 control DCACHE_LUSTRE_INVALID flag with MDS_INODELOCK_LOOKUP lock
[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  2008 Sun Microsystems, Inc. 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 static int mgc_setup(struct obd_device *obd, obd_count len, void *buf)
59 {
60         int rc;
61         ENTRY;
62
63         ptlrpcd_addref();
64
65         rc = client_obd_setup(obd, len, buf);
66         if (rc)
67                 GOTO(err_decref, rc);
68
69         rc = obd_llog_init(obd, obd, NULL);
70         if (rc) {
71                 CERROR("failed to setup llogging subsystems\n");
72                 GOTO(err_cleanup, rc);
73         }
74
75         RETURN(rc);
76
77 err_cleanup:
78         client_obd_cleanup(obd);
79 err_decref:
80         ptlrpcd_decref();
81         RETURN(rc);
82 }
83
84 static int mgc_precleanup(struct obd_device *obd, enum obd_cleanup_stage stage)
85 {
86         int rc = 0;
87         ENTRY;
88
89         switch (stage) {
90         case OBD_CLEANUP_EARLY:
91         case OBD_CLEANUP_EXPORTS:
92                 /* client import will not have been cleaned. */
93                 down_write(&obd->u.cli.cl_sem);
94                 if (obd->u.cli.cl_import) {
95                         struct obd_import *imp;
96                         imp = obd->u.cli.cl_import;
97                         CERROR("client import never connected\n");
98                         class_destroy_import(imp);
99                         obd->u.cli.cl_import = NULL;
100                 }
101                 up_write(&obd->u.cli.cl_sem);
102
103                 rc = obd_llog_finish(obd, 0);
104                 if (rc != 0)
105                         CERROR("failed to cleanup llogging subsystems\n");
106                 break;
107         case OBD_CLEANUP_SELF_EXP:
108                 break;
109         case OBD_CLEANUP_OBD:
110                 break;
111         }
112         RETURN(rc);
113 }
114
115 static int mgc_cleanup(struct obd_device *obd)
116 {
117         struct client_obd *cli = &obd->u.cli;
118         int rc;
119         ENTRY;
120
121         LASSERT(cli->cl_mgc_vfsmnt == NULL);
122
123         ptlrpcd_decref();
124
125         rc = client_obd_cleanup(obd);
126         RETURN(rc);
127 }
128
129 static int mgc_llog_init(struct obd_device *obd, struct obd_device *disk_obd,
130                          int *index)
131 {
132         struct llog_ctxt *ctxt;
133         int rc;
134         ENTRY;
135
136         rc = llog_setup(obd, LLOG_CONFIG_REPL_CTXT, disk_obd, 0, NULL,
137                         &llog_client_ops);
138         if (rc == 0) {
139                 ctxt = llog_get_context(obd, LLOG_CONFIG_REPL_CTXT);
140                 llog_initiator_connect(ctxt);
141                 llog_ctxt_put(ctxt);
142         }
143
144         RETURN(rc);
145 }
146
147 static int mgc_llog_finish(struct obd_device *obd, int count)
148 {
149         int rc;
150         ENTRY;
151
152         rc = llog_cleanup(llog_get_context(obd, LLOG_CONFIG_REPL_CTXT));
153
154         RETURN(rc);
155 }
156
157 struct obd_ops mgc_obd_ops = {
158         .o_owner        = THIS_MODULE,
159         .o_setup        = mgc_setup,
160         .o_precleanup   = mgc_precleanup,
161         .o_cleanup      = mgc_cleanup,
162         .o_add_conn     = client_import_add_conn,
163         .o_del_conn     = client_import_del_conn,
164         .o_connect      = client_connect_import,
165         .o_disconnect   = client_disconnect_export,
166         .o_llog_init    = mgc_llog_init,
167         .o_llog_finish  = mgc_llog_finish,
168 };
169
170 int __init mgc_init(void)
171 {
172         return class_register_type(&mgc_obd_ops, NULL, LUSTRE_MGC_NAME);
173 }