Whamcloud - gitweb
f7f737ed247e8c3a4f7be1950e7ddb5d5db1408c
[fs/lustre-release.git] / lustre / mgs / mgs_handler.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, Whamcloud, Inc.
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/mgs/mgs_handler.c
37  *
38  * Author: Nathan Rutman <nathan@clusterfs.com>
39  */
40
41 #define DEBUG_SUBSYSTEM S_MGS
42 #define D_MGS D_CONFIG
43
44 #ifdef __KERNEL__
45 # include <linux/module.h>
46 # include <linux/pagemap.h>
47 # include <linux/miscdevice.h>
48 # include <linux/init.h>
49 #else
50 # include <liblustre.h>
51 #endif
52
53 #include <obd_class.h>
54 #include <lustre_dlm.h>
55 #include <lprocfs_status.h>
56 #include <lustre_fsfilt.h>
57 #include <lustre_disk.h>
58 #include "mgs_internal.h"
59 #include <lustre_param.h>
60
61 /* Establish a connection to the MGS.*/
62 static int mgs_connect(const struct lu_env *env,
63                        struct obd_export **exp, struct obd_device *obd,
64                        struct obd_uuid *cluuid, struct obd_connect_data *data,
65                        void *localdata)
66 {
67         struct obd_export *lexp;
68         struct lustre_handle conn = { 0 };
69         int rc;
70         ENTRY;
71
72         if (!exp || !obd || !cluuid)
73                 RETURN(-EINVAL);
74
75         rc = class_connect(&conn, obd, cluuid);
76         if (rc)
77                 RETURN(rc);
78
79         lexp = class_conn2export(&conn);
80         if (lexp == NULL)
81                 GOTO(out, rc = -EFAULT);
82
83         mgs_counter_incr(lexp, LPROC_MGS_CONNECT);
84
85         if (data != NULL) {
86                 data->ocd_connect_flags &= MGS_CONNECT_SUPPORTED;
87                 lexp->exp_connect_flags = data->ocd_connect_flags;
88                 data->ocd_version = LUSTRE_VERSION_CODE;
89         }
90
91         rc = mgs_export_stats_init(obd, lexp, localdata);
92
93 out:
94         if (rc) {
95                 class_disconnect(lexp);
96         } else {
97                 *exp = lexp;
98         }
99
100         RETURN(rc);
101 }
102
103 static int mgs_reconnect(const struct lu_env *env,
104                          struct obd_export *exp, struct obd_device *obd,
105                          struct obd_uuid *cluuid, struct obd_connect_data *data,
106                          void *localdata)
107 {
108         ENTRY;
109
110         if (exp == NULL || obd == NULL || cluuid == NULL)
111                 RETURN(-EINVAL);
112
113         mgs_counter_incr(exp, LPROC_MGS_CONNECT);
114
115         if (data != NULL) {
116                 data->ocd_connect_flags &= MGS_CONNECT_SUPPORTED;
117                 exp->exp_connect_flags = data->ocd_connect_flags;
118                 data->ocd_version = LUSTRE_VERSION_CODE;
119         }
120
121         RETURN(mgs_export_stats_init(obd, exp, localdata));
122 }
123
124 static int mgs_disconnect(struct obd_export *exp)
125 {
126         int rc;
127         ENTRY;
128
129         LASSERT(exp);
130
131         mgs_fsc_cleanup(exp);
132
133         class_export_get(exp);
134         mgs_counter_incr(exp, LPROC_MGS_DISCONNECT);
135
136         rc = server_disconnect_export(exp);
137         class_export_put(exp);
138         RETURN(rc);
139 }
140
141 static int mgs_cleanup(struct obd_device *obd);
142 static int mgs_handle(struct ptlrpc_request *req);
143
144 static int mgs_llog_init(struct obd_device *obd, struct obd_llog_group *olg,
145                          struct obd_device *tgt, int *index)
146 {
147         int rc;
148         ENTRY;
149
150         LASSERT(olg == &obd->obd_olg);
151         rc = llog_setup(obd, olg, LLOG_CONFIG_ORIG_CTXT, obd, 0, NULL,
152                         &llog_lvfs_ops);
153         RETURN(rc);
154 }
155
156 static int mgs_llog_finish(struct obd_device *obd, int count)
157 {
158         struct llog_ctxt *ctxt;
159         int rc = 0;
160         ENTRY;
161
162         ctxt = llog_get_context(obd, LLOG_CONFIG_ORIG_CTXT);
163         if (ctxt)
164                 rc = llog_cleanup(ctxt);
165
166         RETURN(rc);
167 }
168
169 /* Start the MGS obd */
170 static int mgs_setup(struct obd_device *obd, struct lustre_cfg *lcfg)
171 {
172         static struct ptlrpc_service_conf       conf;
173         struct lprocfs_static_vars lvars;
174         struct mgs_device *mgs = &obd->u.mgs;
175         struct lustre_mount_info *lmi;
176         struct lustre_sb_info *lsi;
177         struct vfsmount *mnt;
178         int rc = 0;
179         ENTRY;
180
181         CDEBUG(D_CONFIG, "Starting MGS\n");
182
183         /* Find our disk */
184         lmi = server_get_mount(obd->obd_name);
185         if (!lmi)
186                 RETURN(rc = -EINVAL);
187
188         mnt = lmi->lmi_mnt;
189         lsi = s2lsi(lmi->lmi_sb);
190         obd->obd_fsops = fsfilt_get_ops(lsi->lsi_fstype);
191         if (IS_ERR(obd->obd_fsops))
192                 GOTO(err_put, rc = PTR_ERR(obd->obd_fsops));
193
194         if (lvfs_check_rdonly(lvfs_sbdev(mnt->mnt_sb))) {
195                 CERROR("%s: Underlying device is marked as read-only. "
196                        "Setup failed\n", obd->obd_name);
197                 GOTO(err_ops, rc = -EROFS);
198         }
199
200         obd->u.obt.obt_magic = OBT_MAGIC;
201         obd->u.obt.obt_instance = 0;
202         mgs->mgs_obd = obd;
203
204         /* namespace for mgs llog */
205         obd->obd_namespace = ldlm_namespace_new(obd ,"MGS",
206                                                 LDLM_NAMESPACE_SERVER,
207                                                 LDLM_NAMESPACE_MODEST,
208                                                 LDLM_NS_TYPE_MGT);
209         if (obd->obd_namespace == NULL)
210                 GOTO(err_ops, rc = -ENOMEM);
211
212         /* ldlm setup */
213         ptlrpc_init_client(LDLM_CB_REQUEST_PORTAL, LDLM_CB_REPLY_PORTAL,
214                            "mgs_ldlm_client", &obd->obd_ldlm_client);
215
216         rc = mgs_fs_setup(obd, mnt);
217         if (rc) {
218                 CERROR("%s: MGS filesystem method init failed: rc = %d\n",
219                        obd->obd_name, rc);
220                 GOTO(err_ns, rc);
221         }
222
223         rc = obd_llog_init(obd, &obd->obd_olg, obd, NULL);
224         if (rc)
225                 GOTO(err_fs, rc);
226
227         /* No recovery for MGC's */
228         obd->obd_replayable = 0;
229
230         /* Internal mgs setup */
231         mgs_init_fsdb_list(mgs);
232         cfs_mutex_init(&mgs->mgs_mutex);
233         mgs->mgs_start_time = cfs_time_current_sec();
234
235         /* Setup proc */
236         lprocfs_mgs_init_vars(&lvars);
237         if (lprocfs_obd_setup(obd, lvars.obd_vars) == 0) {
238                 lproc_mgs_setup(mgs);
239                 rc = lprocfs_alloc_md_stats(obd, LPROC_MGS_LAST);
240                 if (rc)
241                         GOTO(err_llog, rc);
242         }
243
244         conf = (typeof(conf)) {
245                 .psc_name               = LUSTRE_MGS_NAME,
246                 .psc_watchdog_factor    = MGS_SERVICE_WATCHDOG_FACTOR,
247                 .psc_buf                = {
248                         .bc_nbufs               = MGS_NBUFS,
249                         .bc_buf_size            = MGS_BUFSIZE,
250                         .bc_req_max_size        = MGS_MAXREQSIZE,
251                         .bc_rep_max_size        = MGS_MAXREPSIZE,
252                         .bc_req_portal          = MGS_REQUEST_PORTAL,
253                         .bc_rep_portal          = MGC_REPLY_PORTAL,
254                 },
255                 .psc_thr                = {
256                         .tc_thr_name            = "ll_mgs",
257                         .tc_nthrs_init          = MGS_NTHRS_INIT,
258                         .tc_nthrs_max           = MGS_NTHRS_MAX,
259                         .tc_ctx_tags            = LCT_MG_THREAD,
260                 },
261                 .psc_ops                = {
262                         .so_req_handler         = mgs_handle,
263                         .so_req_printer         = target_print_req,
264                 },
265         };
266         /* Start the service threads */
267         mgs->mgs_service = ptlrpc_register_service(&conf, obd->obd_proc_entry);
268         if (IS_ERR(mgs->mgs_service)) {
269                 rc = PTR_ERR(mgs->mgs_service);
270                 CERROR("failed to start service: %d\n", rc);
271                 GOTO(err_llog, rc);
272         }
273
274         ping_evictor_start();
275
276         CDEBUG(D_INFO, "MGS %s started\n", obd->obd_name);
277
278         RETURN(0);
279
280 err_llog:
281         lproc_mgs_cleanup(mgs);
282         obd_llog_finish(obd, 0);
283 err_fs:
284         /* No extra cleanup needed for llog_init_commit_thread() */
285         mgs_fs_cleanup(obd);
286 err_ns:
287         ldlm_namespace_free(obd->obd_namespace, NULL, 0);
288         obd->obd_namespace = NULL;
289 err_ops:
290         fsfilt_put_ops(obd->obd_fsops);
291 err_put:
292         server_put_mount(obd->obd_name, mnt);
293         mgs->mgs_sb = 0;
294         return rc;
295 }
296
297 static int mgs_precleanup(struct obd_device *obd, enum obd_cleanup_stage stage)
298 {
299         struct mgs_device *mgs = &obd->u.mgs;
300         int rc = 0;
301         ENTRY;
302
303         switch (stage) {
304         case OBD_CLEANUP_EARLY:
305                 break;
306         case OBD_CLEANUP_EXPORTS:
307                 ping_evictor_stop();
308                 ptlrpc_unregister_service(mgs->mgs_service);
309                 mgs_cleanup_fsdb_list(mgs);
310                 rc = obd_llog_finish(obd, 0);
311                 lproc_mgs_cleanup(mgs);
312                 break;
313         }
314         RETURN(rc);
315 }
316
317 /**
318  * Performs cleanup procedures for passed \a obd given it is mgs obd.
319  */
320 static int mgs_cleanup(struct obd_device *obd)
321 {
322         struct mgs_device *mgs = &obd->u.mgs;
323         ENTRY;
324
325         if (mgs->mgs_sb == NULL)
326                 RETURN(0);
327
328         mgs_fs_cleanup(obd);
329
330         server_put_mount(obd->obd_name, mgs->mgs_vfsmnt);
331         mgs->mgs_sb = NULL;
332
333         ldlm_namespace_free(obd->obd_namespace, NULL, 1);
334         obd->obd_namespace = NULL;
335
336         fsfilt_put_ops(obd->obd_fsops);
337
338         LCONSOLE_INFO("%s has stopped.\n", obd->obd_name);
339         RETURN(0);
340 }
341
342 static int mgs_completion_ast_config(struct ldlm_lock *lock, int flags,
343                                      void *cbdata)
344 {
345         ENTRY;
346
347         if (!(flags & (LDLM_FL_BLOCK_WAIT | LDLM_FL_BLOCK_GRANTED |
348                        LDLM_FL_BLOCK_CONV))) {
349                 struct fs_db *fsdb = (struct fs_db *)lock->l_ast_data;
350                 struct lustre_handle lockh;
351
352                 /* clear the bit before lock put */
353                 cfs_clear_bit(FSDB_REVOKING_LOCK, &fsdb->fsdb_flags);
354
355                 ldlm_lock2handle(lock, &lockh);
356                 ldlm_lock_decref_and_cancel(&lockh, LCK_EX);
357         }
358
359         RETURN(ldlm_completion_ast(lock, flags, cbdata));
360 }
361
362 static int mgs_completion_ast_ir(struct ldlm_lock *lock, int flags,
363                                  void *cbdata)
364 {
365         ENTRY;
366
367         if (!(flags & (LDLM_FL_BLOCK_WAIT | LDLM_FL_BLOCK_GRANTED |
368                        LDLM_FL_BLOCK_CONV))) {
369                 struct fs_db *fsdb;
370
371                 /* l_ast_data is used as a marker to avoid cancel ldlm lock
372                  * twice. See LU-1259. */
373                 lock_res_and_lock(lock);
374                 fsdb = (struct fs_db *)lock->l_ast_data;
375                 lock->l_ast_data = NULL;
376                 unlock_res_and_lock(lock);
377
378                 if (fsdb != NULL) {
379                         struct lustre_handle lockh;
380
381                         mgs_ir_notify_complete(fsdb);
382
383                         ldlm_lock2handle(lock, &lockh);
384                         ldlm_lock_decref_and_cancel(&lockh, LCK_EX);
385                 }
386         }
387
388         RETURN(ldlm_completion_ast(lock, flags, cbdata));
389 }
390
391 void mgs_revoke_lock(struct mgs_device *mgs, struct fs_db *fsdb, int type)
392 {
393         ldlm_completion_callback cp = NULL;
394         struct lustre_handle     lockh = { 0 };
395         struct ldlm_res_id       res_id;
396         int flags = LDLM_FL_ATOMIC_CB;
397         int rc;
398         ENTRY;
399
400         LASSERT(fsdb->fsdb_name[0] != '\0');
401         rc = mgc_fsname2resid(fsdb->fsdb_name, &res_id, type);
402         LASSERT(rc == 0);
403
404         switch (type) {
405         case CONFIG_T_CONFIG:
406                 cp = mgs_completion_ast_config;
407                 if (cfs_test_and_set_bit(FSDB_REVOKING_LOCK, &fsdb->fsdb_flags))
408                         rc = -EALREADY;
409                 break;
410         case CONFIG_T_RECOVER:
411                 cp = mgs_completion_ast_ir;
412         default:
413                 break;
414         }
415
416         if (!rc) {
417                 LASSERT(cp != NULL);
418                 rc = ldlm_cli_enqueue_local(mgs->mgs_obd->obd_namespace,
419                                             &res_id, LDLM_PLAIN, NULL, LCK_EX,
420                                             &flags, ldlm_blocking_ast, cp,
421                                             NULL, fsdb, 0, NULL, &lockh);
422                 if (rc != ELDLM_OK) {
423                         CERROR("can't take cfg lock for "LPX64"/"LPX64"(%d)\n",
424                                le64_to_cpu(res_id.name[0]),
425                                le64_to_cpu(res_id.name[1]), rc);
426
427                         if (type == CONFIG_T_CONFIG)
428                                 cfs_clear_bit(FSDB_REVOKING_LOCK,
429                                               &fsdb->fsdb_flags);
430                 }
431                 /* lock has been cancelled in completion_ast. */
432         }
433
434         RETURN_EXIT;
435 }
436
437 /* rc=0 means ok
438       1 means update
439      <0 means error */
440 static int mgs_check_target(const struct lu_env *env,
441                             struct mgs_device *mgs,
442                             struct mgs_target_info *mti)
443 {
444         int rc;
445         ENTRY;
446
447         rc = mgs_check_index(env, mgs, mti);
448         if (rc == 0) {
449                 LCONSOLE_ERROR_MSG(0x13b, "%s claims to have registered, but "
450                                    "this MGS does not know about it, preventing "
451                                    "registration.\n", mti->mti_svname);
452                 rc = -ENOENT;
453         } else if (rc == -1) {
454                 LCONSOLE_ERROR_MSG(0x13c, "Client log %s-client has "
455                                    "disappeared! Regenerating all logs.\n",
456                                    mti->mti_fsname);
457                 mti->mti_flags |= LDD_F_WRITECONF;
458                 rc = 1;
459         } else {
460                 /* Index is correctly marked as used */
461
462                 /* If the logs don't contain the mti_nids then add
463                    them as failover nids */
464                 rc = mgs_check_failnid(env, mgs, mti);
465         }
466
467         RETURN(rc);
468 }
469
470 /* Ensure this is not a failover node that is connecting first*/
471 static int mgs_check_failover_reg(struct mgs_target_info *mti)
472 {
473         lnet_nid_t nid;
474         char *ptr;
475         int i;
476
477         ptr = mti->mti_params;
478         while (class_find_param(ptr, PARAM_FAILNODE, &ptr) == 0) {
479                 while (class_parse_nid(ptr, &nid, &ptr) == 0) {
480                         for (i = 0; i < mti->mti_nid_count; i++) {
481                                 if (nid == mti->mti_nids[i]) {
482                                         LCONSOLE_WARN("Denying initial registra"
483                                                       "tion attempt from nid %s"
484                                                       ", specified as failover"
485                                                       "\n",libcfs_nid2str(nid));
486                                         return -EADDRNOTAVAIL;
487                                 }
488                         }
489                 }
490         }
491         return 0;
492 }
493
494 /* Called whenever a target starts up.  Flags indicate first connect, etc. */
495 static int mgs_handle_target_reg(struct ptlrpc_request *req)
496 {
497         struct obd_device *obd = req->rq_export->exp_obd;
498         struct mgs_device *mgs = exp2mgs_dev(req->rq_export);
499         struct lu_env     *env = req->rq_svc_thread->t_env;
500         struct mgs_target_info *mti, *rep_mti;
501         struct fs_db *fsdb;
502         int opc;
503         int rc = 0;
504         ENTRY;
505
506         mgs_counter_incr(req->rq_export, LPROC_MGS_TARGET_REG);
507
508         mti = req_capsule_client_get(&req->rq_pill, &RMF_MGS_TARGET_INFO);
509
510         opc = mti->mti_flags & LDD_F_OPC_MASK;
511         if (opc == LDD_F_OPC_READY) {
512                 CDEBUG(D_MGS, "fs: %s index: %d is ready to reconnect.\n",
513                        mti->mti_fsname, mti->mti_stripe_index);
514                 rc = mgs_ir_update(env, mgs, mti);
515                 if (rc) {
516                         LASSERT(!(mti->mti_flags & LDD_F_IR_CAPABLE));
517                         CERROR("Update IR return with %d(ignore and IR "
518                                "disabled)\n", rc);
519                 }
520                 GOTO(out_nolock, rc);
521         }
522
523         /* Do not support unregistering right now. */
524         if (opc != LDD_F_OPC_REG)
525                 GOTO(out_nolock, rc = -EINVAL);
526
527         CDEBUG(D_MGS, "fs: %s index: %d is registered to MGS.\n",
528                mti->mti_fsname, mti->mti_stripe_index);
529
530         if (mti->mti_flags & LDD_F_NEED_INDEX)
531                 mti->mti_flags |= LDD_F_WRITECONF;
532
533         if (!(mti->mti_flags & (LDD_F_WRITECONF | LDD_F_UPGRADE14 |
534                                 LDD_F_UPDATE))) {
535                 /* We're just here as a startup ping. */
536                 CDEBUG(D_MGS, "Server %s is running on %s\n",
537                        mti->mti_svname, obd_export_nid2str(req->rq_export));
538                 rc = mgs_check_target(env, mgs, mti);
539                 /* above will set appropriate mti flags */
540                 if (rc <= 0)
541                         /* Nothing wrong, or fatal error */
542                         GOTO(out_nolock, rc);
543         } else {
544                 if (!(mti->mti_flags & LDD_F_NO_PRIMNODE)
545                     && (rc = mgs_check_failover_reg(mti)))
546                         GOTO(out_nolock, rc);
547         }
548
549         OBD_FAIL_TIMEOUT(OBD_FAIL_MGS_PAUSE_TARGET_REG, 10);
550
551         if (mti->mti_flags & LDD_F_WRITECONF) {
552                 if (mti->mti_flags & LDD_F_SV_TYPE_MDT &&
553                     mti->mti_stripe_index == 0) {
554                         rc = mgs_erase_logs(env, mgs, mti->mti_fsname);
555                         LCONSOLE_WARN("%s: Logs for fs %s were removed by user "
556                                       "request.  All servers must be restarted "
557                                       "in order to regenerate the logs."
558                                       "\n", obd->obd_name, mti->mti_fsname);
559                 } else if (mti->mti_flags &
560                            (LDD_F_SV_TYPE_OST | LDD_F_SV_TYPE_MDT)) {
561                         rc = mgs_erase_log(env, mgs, mti->mti_svname);
562                         LCONSOLE_WARN("%s: Regenerating %s log by user "
563                                       "request.\n",
564                                       obd->obd_name, mti->mti_svname);
565                 }
566                 mti->mti_flags |= LDD_F_UPDATE;
567                 /* Erased logs means start from scratch. */
568                 mti->mti_flags &= ~LDD_F_UPGRADE14;
569                 if (rc)
570                         GOTO(out_nolock, rc);
571         }
572
573         rc = mgs_find_or_make_fsdb(env, mgs, mti->mti_fsname, &fsdb);
574         if (rc) {
575                 CERROR("Can't get db for %s: %d\n", mti->mti_fsname, rc);
576                 GOTO(out_nolock, rc);
577         }
578
579         /*
580          * Log writing contention is handled by the fsdb_mutex.
581          *
582          * It should be alright if someone was reading while we were
583          * updating the logs - if we revoke at the end they will just update
584          * from where they left off.
585          */
586
587         if (mti->mti_flags & LDD_F_UPGRADE14) {
588                 CERROR("Can't upgrade from 1.4 (%d)\n", rc);
589                 GOTO(out, rc);
590         }
591
592         if (mti->mti_flags & LDD_F_UPDATE) {
593                 CDEBUG(D_MGS, "updating %s, index=%d\n", mti->mti_svname,
594                        mti->mti_stripe_index);
595
596                 /* create or update the target log
597                    and update the client/mdt logs */
598                 rc = mgs_write_log_target(env, mgs, mti, fsdb);
599                 if (rc) {
600                         CERROR("Failed to write %s log (%d)\n",
601                                mti->mti_svname, rc);
602                         GOTO(out, rc);
603                 }
604
605                 mti->mti_flags &= ~(LDD_F_VIRGIN | LDD_F_UPDATE |
606                                     LDD_F_NEED_INDEX | LDD_F_WRITECONF |
607                                     LDD_F_UPGRADE14);
608                 mti->mti_flags |= LDD_F_REWRITE_LDD;
609         }
610
611 out:
612         mgs_revoke_lock(mgs, fsdb, CONFIG_T_CONFIG);
613
614 out_nolock:
615         CDEBUG(D_MGS, "replying with %s, index=%d, rc=%d\n", mti->mti_svname,
616                mti->mti_stripe_index, rc);
617         req->rq_status = rc;
618         if (rc)
619                 /* we need an error flag to tell the target what's going on,
620                  * instead of just doing it by error code only. */
621                 mti->mti_flags |= LDD_F_ERROR;
622
623         rc = req_capsule_server_pack(&req->rq_pill);
624         if (rc)
625                 RETURN(rc);
626
627         /* send back the whole mti in the reply */
628         rep_mti = req_capsule_server_get(&req->rq_pill, &RMF_MGS_TARGET_INFO);
629         *rep_mti = *mti;
630
631         /* Flush logs to disk */
632         fsfilt_sync(obd, obd->u.mgs.mgs_sb);
633         RETURN(rc);
634 }
635
636 static int mgs_set_info_rpc(struct ptlrpc_request *req)
637 {
638         struct mgs_device *mgs = exp2mgs_dev(req->rq_export);
639         struct lu_env     *env = req->rq_svc_thread->t_env;
640         struct mgs_send_param *msp, *rep_msp;
641         struct mgs_thread_info *mgi = mgs_env_info(env);
642         int rc;
643         struct lustre_cfg *lcfg;
644         ENTRY;
645
646         msp = req_capsule_client_get(&req->rq_pill, &RMF_MGS_SEND_PARAM);
647         LASSERT(msp);
648
649         /* Construct lustre_cfg structure to pass to function mgs_setparam */
650         lustre_cfg_bufs_reset(&mgi->mgi_bufs, NULL);
651         lustre_cfg_bufs_set_string(&mgi->mgi_bufs, 1, msp->mgs_param);
652         lcfg = lustre_cfg_new(LCFG_PARAM, &mgi->mgi_bufs);
653         if (IS_ERR(lcfg))
654                 GOTO(out, rc = PTR_ERR(lcfg));
655         rc = mgs_setparam(env, mgs, lcfg, mgi->mgi_fsname);
656         if (rc) {
657                 CERROR("Error %d in setting the parameter %s for fs %s\n",
658                        rc, msp->mgs_param, mgi->mgi_fsname);
659                 GOTO(out_cfg, rc);
660         }
661
662         rc = req_capsule_server_pack(&req->rq_pill);
663         if (rc == 0) {
664                 rep_msp = req_capsule_server_get(&req->rq_pill, &RMF_MGS_SEND_PARAM);
665                 rep_msp = msp;
666         }
667 out_cfg:
668         lustre_cfg_free(lcfg);
669 out:
670         RETURN(rc);
671 }
672
673 static int mgs_config_read(struct ptlrpc_request *req)
674 {
675         struct mgs_config_body *body;
676         int rc;
677         ENTRY;
678
679         body = req_capsule_client_get(&req->rq_pill, &RMF_MGS_CONFIG_BODY);
680         if (body == NULL)
681                 RETURN(-EINVAL);
682
683         switch (body->mcb_type) {
684         case CONFIG_T_RECOVER:
685                 rc = mgs_get_ir_logs(req);
686                 break;
687
688         case CONFIG_T_CONFIG:
689                 rc = -ENOTSUPP;
690                 break;
691
692         default:
693                 rc = -EINVAL;
694                 break;
695         }
696
697         RETURN(rc);
698 }
699
700 /*
701  * similar as in ost_connect_check_sptlrpc()
702  */
703 static int mgs_connect_check_sptlrpc(struct ptlrpc_request *req)
704 {
705         struct obd_export     *exp = req->rq_export;
706         struct mgs_device     *mgs = exp2mgs_dev(req->rq_export);
707         struct lu_env         *env = req->rq_svc_thread->t_env;
708         struct fs_db          *fsdb;
709         struct sptlrpc_flavor  flvr;
710         int                    rc = 0;
711
712         if (exp->exp_flvr.sf_rpc == SPTLRPC_FLVR_INVALID) {
713                 rc = mgs_find_or_make_fsdb(env, mgs, MGSSELF_NAME, &fsdb);
714                 if (rc)
715                         return rc;
716
717                 cfs_mutex_lock(&fsdb->fsdb_mutex);
718                 if (sptlrpc_rule_set_choose(&fsdb->fsdb_srpc_gen,
719                                             LUSTRE_SP_MGC, LUSTRE_SP_MGS,
720                                             req->rq_peer.nid,
721                                             &flvr) == 0) {
722                         /* by defualt allow any flavors */
723                         flvr.sf_rpc = SPTLRPC_FLVR_ANY;
724                 }
725                 cfs_mutex_unlock(&fsdb->fsdb_mutex);
726
727                 cfs_spin_lock(&exp->exp_lock);
728
729                 exp->exp_sp_peer = req->rq_sp_from;
730                 exp->exp_flvr = flvr;
731
732                 if (exp->exp_flvr.sf_rpc != SPTLRPC_FLVR_ANY &&
733                     exp->exp_flvr.sf_rpc != req->rq_flvr.sf_rpc) {
734                         CERROR("invalid rpc flavor %x, expect %x, from %s\n",
735                                req->rq_flvr.sf_rpc, exp->exp_flvr.sf_rpc,
736                                libcfs_nid2str(req->rq_peer.nid));
737                         rc = -EACCES;
738                 }
739
740                 cfs_spin_unlock(&exp->exp_lock);
741         } else {
742                 if (exp->exp_sp_peer != req->rq_sp_from) {
743                         CERROR("RPC source %s doesn't match %s\n",
744                                sptlrpc_part2name(req->rq_sp_from),
745                                sptlrpc_part2name(exp->exp_sp_peer));
746                         rc = -EACCES;
747                 } else {
748                         rc = sptlrpc_target_export_check(exp, req);
749                 }
750         }
751
752         return rc;
753 }
754
755 /* Called whenever a target cleans up. */
756 /* XXX - Currently unused */
757 static int mgs_handle_target_del(struct ptlrpc_request *req)
758 {
759         ENTRY;
760         mgs_counter_incr(req->rq_export, LPROC_MGS_TARGET_DEL);
761         RETURN(0);
762 }
763
764 /* XXX - Currently unused */
765 static int mgs_handle_exception(struct ptlrpc_request *req)
766 {
767         ENTRY;
768         mgs_counter_incr(req->rq_export, LPROC_MGS_EXCEPTION);
769         RETURN(0);
770 }
771
772 /*
773  * For old clients there is no direct way of knowing which filesystems
774  * a client is operating at the MGS side. But we need to pick up those
775  * clients so that the MGS can mark the corresponding filesystem as
776  * non-IR capable because old clients are not ready to be notified.
777  *
778  * This is why we have this _hack_ function. We detect the filesystem's
779  * name by hacking llog operation which is currently used by the clients
780  * to fetch configuration logs. At present this is fine because this is
781  * the ONLY llog operation between mgc and the MGS.
782  *
783  * If extra llog operation is going to be added, this function needs fixing.
784  *
785  * If releases prior than 2.0 are not supported, we can remove this function.
786  */
787 static int mgs_handle_fslog_hack(struct ptlrpc_request *req)
788 {
789         char *logname;
790         char fsname[16];
791         char *ptr;
792         int rc;
793
794         /* XXX: We suppose that llog at mgs is only used for
795          * fetching file system log */
796         logname = req_capsule_client_get(&req->rq_pill, &RMF_NAME);
797         if (logname == NULL) {
798                 CERROR("No logname, is llog on MGS used for something else?\n");
799                 return -EINVAL;
800         }
801
802         ptr = strchr(logname, '-');
803         rc = (int)(ptr - logname);
804         if (ptr == NULL || rc >= sizeof(fsname)) {
805                 CERROR("Invalid logname received: %s\n", logname);
806                 return -EINVAL;
807         }
808
809         strncpy(fsname, logname, rc);
810         fsname[rc] = 0;
811         rc = mgs_fsc_attach(req->rq_svc_thread->t_env, req->rq_export, fsname);
812         if (rc < 0 && rc != -EEXIST)
813                 CERROR("add fs client %s returns %d\n", fsname, rc);
814
815         return rc;
816 }
817
818 /* TODO: handle requests in a similar way as MDT: see mdt_handle_common() */
819 int mgs_handle(struct ptlrpc_request *req)
820 {
821         int fail = OBD_FAIL_MGS_ALL_REPLY_NET;
822         int opc, rc = 0;
823         ENTRY;
824
825         req_capsule_init(&req->rq_pill, req, RCL_SERVER);
826         CFS_FAIL_TIMEOUT_MS(OBD_FAIL_MGS_PAUSE_REQ, cfs_fail_val);
827         if (CFS_FAIL_CHECK(OBD_FAIL_MGS_ALL_REQUEST_NET))
828                 RETURN(0);
829
830         LASSERT(current->journal_info == NULL);
831         opc = lustre_msg_get_opc(req->rq_reqmsg);
832
833         if (opc == SEC_CTX_INIT ||
834             opc == SEC_CTX_INIT_CONT ||
835             opc == SEC_CTX_FINI)
836                 GOTO(out, rc = 0);
837
838         if (opc != MGS_CONNECT) {
839                 if (!class_connected_export(req->rq_export)) {
840                         DEBUG_REQ(D_MGS, req, "operation on unconnected MGS\n");
841                         req->rq_status = -ENOTCONN;
842                         GOTO(out, rc = -ENOTCONN);
843                 }
844         }
845
846         switch (opc) {
847         case MGS_CONNECT:
848                 DEBUG_REQ(D_MGS, req, "connect");
849                 /* MGS and MDS have same request format for connect */
850                 req_capsule_set(&req->rq_pill, &RQF_MDS_CONNECT);
851                 rc = target_handle_connect(req);
852                 if (rc == 0)
853                         rc = mgs_connect_check_sptlrpc(req);
854
855                 if (!rc && (lustre_msg_get_conn_cnt(req->rq_reqmsg) > 1))
856                         /* Make clients trying to reconnect after a MGS restart
857                            happy; also requires obd_replayable */
858                         lustre_msg_add_op_flags(req->rq_repmsg,
859                                                 MSG_CONNECT_RECONNECT);
860                 break;
861         case MGS_DISCONNECT:
862                 DEBUG_REQ(D_MGS, req, "disconnect");
863                 /* MGS and MDS have same request format for disconnect */
864                 req_capsule_set(&req->rq_pill, &RQF_MDS_DISCONNECT);
865                 rc = target_handle_disconnect(req);
866                 req->rq_status = rc;            /* superfluous? */
867                 break;
868         case MGS_EXCEPTION:
869                 DEBUG_REQ(D_MGS, req, "exception");
870                 rc = mgs_handle_exception(req);
871                 break;
872         case MGS_TARGET_REG:
873                 DEBUG_REQ(D_MGS, req, "target add");
874                 req_capsule_set(&req->rq_pill, &RQF_MGS_TARGET_REG);
875                 rc = mgs_handle_target_reg(req);
876                 break;
877         case MGS_TARGET_DEL:
878                 DEBUG_REQ(D_MGS, req, "target del");
879                 rc = mgs_handle_target_del(req);
880                 break;
881         case MGS_SET_INFO:
882                 DEBUG_REQ(D_MGS, req, "set_info");
883                 req_capsule_set(&req->rq_pill, &RQF_MGS_SET_INFO);
884                 rc = mgs_set_info_rpc(req);
885                 break;
886         case MGS_CONFIG_READ:
887                 DEBUG_REQ(D_MGS, req, "read config");
888                 req_capsule_set(&req->rq_pill, &RQF_MGS_CONFIG_READ);
889                 rc = mgs_config_read(req);
890                 break;
891         case LDLM_ENQUEUE:
892                 DEBUG_REQ(D_MGS, req, "enqueue");
893                 req_capsule_set(&req->rq_pill, &RQF_LDLM_ENQUEUE);
894                 rc = ldlm_handle_enqueue(req, ldlm_server_completion_ast,
895                                          ldlm_server_blocking_ast, NULL);
896                 break;
897         case LDLM_BL_CALLBACK:
898         case LDLM_CP_CALLBACK:
899                 DEBUG_REQ(D_MGS, req, "callback");
900                 CERROR("callbacks should not happen on MGS\n");
901                 LBUG();
902                 break;
903
904         case OBD_PING:
905                 DEBUG_REQ(D_INFO, req, "ping");
906                 req_capsule_set(&req->rq_pill, &RQF_OBD_PING);
907                 rc = target_handle_ping(req);
908                 break;
909         case OBD_LOG_CANCEL:
910                 DEBUG_REQ(D_MGS, req, "log cancel");
911                 rc = -ENOTSUPP; /* la la la */
912                 break;
913
914         case LLOG_ORIGIN_HANDLE_CREATE:
915                 DEBUG_REQ(D_MGS, req, "llog_open");
916                 req_capsule_set(&req->rq_pill, &RQF_LLOG_ORIGIN_HANDLE_CREATE);
917                 rc = llog_origin_handle_open(req);
918                 if (rc == 0)
919                         (void)mgs_handle_fslog_hack(req);
920                 break;
921         case LLOG_ORIGIN_HANDLE_NEXT_BLOCK:
922                 DEBUG_REQ(D_MGS, req, "llog next block");
923                 req_capsule_set(&req->rq_pill,
924                                 &RQF_LLOG_ORIGIN_HANDLE_NEXT_BLOCK);
925                 rc = llog_origin_handle_next_block(req);
926                 break;
927         case LLOG_ORIGIN_HANDLE_READ_HEADER:
928                 DEBUG_REQ(D_MGS, req, "llog read header");
929                 req_capsule_set(&req->rq_pill,
930                                 &RQF_LLOG_ORIGIN_HANDLE_READ_HEADER);
931                 rc = llog_origin_handle_read_header(req);
932                 break;
933         case LLOG_ORIGIN_HANDLE_CLOSE:
934                 DEBUG_REQ(D_MGS, req, "llog close");
935                 rc = llog_origin_handle_close(req);
936                 break;
937         default:
938                 rc = -EOPNOTSUPP;
939         }
940
941         LASSERT(current->journal_info == NULL);
942         if (rc) {
943                 DEBUG_REQ(D_MGS, req, "MGS fail to handle opc = %d: rc = %d\n",
944                           opc, rc);
945                 req->rq_status = rc;
946                 rc = ptlrpc_error(req);
947                 RETURN(rc);
948         }
949 out:
950         target_send_reply(req, rc, fail);
951         RETURN(0);
952 }
953
954 static inline int mgs_init_export(struct obd_export *exp)
955 {
956         struct mgs_export_data *data = &exp->u.eu_mgs_data;
957
958         /* init mgs_export_data for fsc */
959         cfs_spin_lock_init(&data->med_lock);
960         CFS_INIT_LIST_HEAD(&data->med_clients);
961
962         cfs_spin_lock(&exp->exp_lock);
963         exp->exp_connecting = 1;
964         cfs_spin_unlock(&exp->exp_lock);
965
966         /* self-export doesn't need client data and ldlm initialization */
967         if (unlikely(obd_uuid_equals(&exp->exp_obd->obd_uuid,
968                                      &exp->exp_client_uuid)))
969                 return 0;
970         return ldlm_init_export(exp);
971 }
972
973 static inline int mgs_destroy_export(struct obd_export *exp)
974 {
975         ENTRY;
976
977         target_destroy_export(exp);
978         mgs_client_free(exp);
979
980         if (unlikely(obd_uuid_equals(&exp->exp_obd->obd_uuid,
981                                      &exp->exp_client_uuid)))
982                 RETURN(0);
983
984         ldlm_destroy_export(exp);
985
986         RETURN(0);
987 }
988
989 static int mgs_extract_fs_pool(char * arg, char *fsname, char *poolname)
990 {
991         char *ptr;
992
993         ENTRY;
994         for (ptr = arg;  (*ptr != '\0') && (*ptr != '.'); ptr++ ) {
995                 *fsname = *ptr;
996                 fsname++;
997         }
998         if (*ptr == '\0')
999                 return -EINVAL;
1000         *fsname = '\0';
1001         ptr++;
1002         strcpy(poolname, ptr);
1003
1004         RETURN(0);
1005 }
1006
1007 static int mgs_iocontrol_pool(const struct lu_env *env,
1008                               struct mgs_device *mgs,
1009                               struct obd_ioctl_data *data)
1010 {
1011         struct mgs_thread_info *mgi = mgs_env_info(env);
1012         int rc;
1013         struct lustre_cfg *lcfg = NULL;
1014         struct llog_rec_hdr rec;
1015         char *poolname = NULL;
1016         ENTRY;
1017
1018         OBD_ALLOC(poolname, LOV_MAXPOOLNAME + 1);
1019         if (poolname == NULL)
1020                 RETURN(-ENOMEM);
1021         rec.lrh_len = llog_data_len(data->ioc_plen1);
1022
1023         if (data->ioc_type == LUSTRE_CFG_TYPE) {
1024                 rec.lrh_type = OBD_CFG_REC;
1025         } else {
1026                 CERROR("unknown cfg record type:%d \n", data->ioc_type);
1027                 GOTO(out_pool, rc = -EINVAL);
1028         }
1029
1030         if (data->ioc_plen1 > CFS_PAGE_SIZE)
1031                 GOTO(out_pool, rc = -E2BIG);
1032
1033         OBD_ALLOC(lcfg, data->ioc_plen1);
1034         if (lcfg == NULL)
1035                 GOTO(out_pool, rc = -ENOMEM);
1036
1037         if (cfs_copy_from_user(lcfg, data->ioc_pbuf1, data->ioc_plen1))
1038                 GOTO(out_lcfg, rc = -EFAULT);
1039
1040         if (lcfg->lcfg_bufcount < 2)
1041                 GOTO(out_lcfg, rc = -EFAULT);
1042
1043         /* first arg is always <fsname>.<poolname> */
1044         rc = mgs_extract_fs_pool(lustre_cfg_string(lcfg, 1), mgi->mgi_fsname,
1045                                  poolname);
1046         if (rc)
1047                 GOTO(out_lcfg, rc);
1048
1049         switch (lcfg->lcfg_command) {
1050         case LCFG_POOL_NEW:
1051                 if (lcfg->lcfg_bufcount != 2)
1052                         GOTO(out_lcfg, rc = -EINVAL);
1053                 rc = mgs_pool_cmd(env, mgs, LCFG_POOL_NEW, mgi->mgi_fsname,
1054                                   poolname, NULL);
1055                 break;
1056         case LCFG_POOL_ADD:
1057                 if (lcfg->lcfg_bufcount != 3)
1058                         GOTO(out_lcfg, rc = -EINVAL);
1059                 rc = mgs_pool_cmd(env, mgs, LCFG_POOL_ADD, mgi->mgi_fsname,
1060                                   poolname, lustre_cfg_string(lcfg, 2));
1061                 break;
1062         case LCFG_POOL_REM:
1063                 if (lcfg->lcfg_bufcount != 3)
1064                         GOTO(out_lcfg, rc = -EINVAL);
1065                 rc = mgs_pool_cmd(env, mgs, LCFG_POOL_REM, mgi->mgi_fsname,
1066                                   poolname, lustre_cfg_string(lcfg, 2));
1067                 break;
1068         case LCFG_POOL_DEL:
1069                 if (lcfg->lcfg_bufcount != 2)
1070                         GOTO(out_lcfg, rc = -EINVAL);
1071                 rc = mgs_pool_cmd(env, mgs, LCFG_POOL_DEL, mgi->mgi_fsname,
1072                                   poolname, NULL);
1073                 break;
1074         default:
1075                  rc = -EINVAL;
1076         }
1077
1078         if (rc) {
1079                 CERROR("OBD_IOC_POOL err %d, cmd %X for pool %s.%s\n",
1080                        rc, lcfg->lcfg_command, mgi->mgi_fsname, poolname);
1081                 GOTO(out_lcfg, rc);
1082         }
1083
1084 out_lcfg:
1085         OBD_FREE(lcfg, data->ioc_plen1);
1086 out_pool:
1087         OBD_FREE(poolname, LOV_MAXPOOLNAME + 1);
1088         RETURN(rc);
1089 }
1090
1091 /* from mdt_iocontrol */
1092 int mgs_iocontrol(unsigned int cmd, struct obd_export *exp, int len,
1093                   void *karg, void *uarg)
1094 {
1095         struct mgs_device *mgs = exp2mgs_dev(exp);
1096         struct obd_ioctl_data *data = karg;
1097         struct lvfs_run_ctxt saved;
1098         struct lu_env env;
1099         int rc = 0;
1100
1101         ENTRY;
1102         CDEBUG(D_IOCTL, "handling ioctl cmd %#x\n", cmd);
1103
1104         rc = lu_env_init(&env, LCT_MG_THREAD);
1105         if (rc)
1106                 RETURN(rc);
1107
1108         switch (cmd) {
1109
1110         case OBD_IOC_PARAM: {
1111                 struct mgs_thread_info *mgi = mgs_env_info(&env);
1112                 struct lustre_cfg *lcfg;
1113                 struct llog_rec_hdr rec;
1114
1115                 rec.lrh_len = llog_data_len(data->ioc_plen1);
1116
1117                 if (data->ioc_type == LUSTRE_CFG_TYPE) {
1118                         rec.lrh_type = OBD_CFG_REC;
1119                 } else {
1120                         CERROR("unknown cfg record type:%d \n", data->ioc_type);
1121                         GOTO(out, rc = -EINVAL);
1122                 }
1123
1124                 OBD_ALLOC(lcfg, data->ioc_plen1);
1125                 if (lcfg == NULL)
1126                         GOTO(out, rc = -ENOMEM);
1127                 if (cfs_copy_from_user(lcfg, data->ioc_pbuf1, data->ioc_plen1))
1128                         GOTO(out_free, rc = -EFAULT);
1129
1130                 if (lcfg->lcfg_bufcount < 1)
1131                         GOTO(out_free, rc = -EINVAL);
1132
1133                 rc = mgs_setparam(&env, mgs, lcfg, mgi->mgi_fsname);
1134                 if (rc)
1135                         CERROR("%s: setparam err: rc = %d\n",
1136                                exp->exp_obd->obd_name, rc);
1137 out_free:
1138                 OBD_FREE(lcfg, data->ioc_plen1);
1139                 break;
1140         }
1141
1142         case OBD_IOC_POOL:
1143                 rc = mgs_iocontrol_pool(&env, mgs, data);
1144                 break;
1145
1146         case OBD_IOC_DUMP_LOG: {
1147                 struct llog_ctxt *ctxt;
1148                 ctxt = llog_get_context(mgs->mgs_obd, LLOG_CONFIG_ORIG_CTXT);
1149                 push_ctxt(&saved, &mgs->mgs_obd->obd_lvfs_ctxt, NULL);
1150                 rc = class_config_dump_llog(ctxt, data->ioc_inlbuf1, NULL);
1151                 pop_ctxt(&saved, &mgs->mgs_obd->obd_lvfs_ctxt, NULL);
1152                 llog_ctxt_put(ctxt);
1153
1154                 break;
1155         }
1156
1157         case OBD_IOC_LLOG_CHECK:
1158         case OBD_IOC_LLOG_INFO:
1159         case OBD_IOC_LLOG_PRINT: {
1160                 struct llog_ctxt *ctxt;
1161                 ctxt = llog_get_context(mgs->mgs_obd, LLOG_CONFIG_ORIG_CTXT);
1162
1163                 push_ctxt(&saved, &ctxt->loc_exp->exp_obd->obd_lvfs_ctxt, NULL);
1164                 rc = llog_ioctl(ctxt, cmd, data);
1165                 pop_ctxt(&saved, &ctxt->loc_exp->exp_obd->obd_lvfs_ctxt, NULL);
1166                 llog_ctxt_put(ctxt);
1167
1168                 break;
1169         }
1170
1171         default:
1172                 CDEBUG(D_INFO, "unknown command %x\n", cmd);
1173                 rc = -EINVAL;
1174                 break;
1175         }
1176 out:
1177         lu_env_fini(&env);
1178         RETURN(rc);
1179 }
1180
1181 /* context key constructor/destructor: mgs_key_init, mgs_key_fini */
1182 LU_KEY_INIT_FINI(mgs, struct mgs_thread_info);
1183
1184 LU_CONTEXT_KEY_DEFINE(mgs, LCT_MG_THREAD);
1185
1186 /* use obd ops to offer management infrastructure */
1187 static struct obd_ops mgs_obd_ops = {
1188         .o_owner           = THIS_MODULE,
1189         .o_connect         = mgs_connect,
1190         .o_reconnect       = mgs_reconnect,
1191         .o_disconnect      = mgs_disconnect,
1192         .o_setup           = mgs_setup,
1193         .o_precleanup      = mgs_precleanup,
1194         .o_cleanup         = mgs_cleanup,
1195         .o_init_export     = mgs_init_export,
1196         .o_destroy_export  = mgs_destroy_export,
1197         .o_iocontrol       = mgs_iocontrol,
1198         .o_llog_init       = mgs_llog_init,
1199         .o_llog_finish     = mgs_llog_finish
1200 };
1201
1202 static int __init mgs_init(void)
1203 {
1204         struct lprocfs_static_vars lvars;
1205         int rc;
1206
1207         lprocfs_mgs_init_vars(&lvars);
1208         class_register_type(&mgs_obd_ops, NULL,
1209                             lvars.module_vars, LUSTRE_MGS_NAME, NULL);
1210
1211         LU_CONTEXT_KEY_INIT(&mgs_thread_key);
1212         rc = lu_context_key_register(&mgs_thread_key);
1213         if (rc)
1214                 class_unregister_type(LUSTRE_MGS_NAME);
1215
1216         return rc;
1217 }
1218
1219 static void /*__exit*/ mgs_exit(void)
1220 {
1221         class_unregister_type(LUSTRE_MGS_NAME);
1222         lu_context_key_degister(&mgs_thread_key);
1223 }
1224
1225 MODULE_AUTHOR("Sun Microsystems, Inc. <http://www.lustre.org/>");
1226 MODULE_DESCRIPTION("Lustre  Management Server (MGS)");
1227 MODULE_LICENSE("GPL");
1228
1229 module_init(mgs_init);
1230 module_exit(mgs_exit);