]> git.kernelconcepts.de Git - karo-tx-linux.git/blob - drivers/staging/lustre/lustre/mgc/mgc_request.c
f6e4bacc3a15629166829dc9719b2746cef04fad
[karo-tx-linux.git] / drivers / staging / lustre / lustre / mgc / mgc_request.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/mgc_request.c
37  *
38  * Author: Nathan Rutman <nathan@clusterfs.com>
39  */
40
41 #define DEBUG_SUBSYSTEM S_MGC
42 #define D_MGC D_CONFIG /*|D_WARNING*/
43
44 #include <linux/module.h>
45 #include <obd_class.h>
46 #include <lustre_dlm.h>
47 #include <lprocfs_status.h>
48 #include <lustre_log.h>
49 #include <lustre_disk.h>
50 #include <dt_object.h>
51
52 #include "mgc_internal.h"
53
54 static int mgc_name2resid(char *name, int len, struct ldlm_res_id *res_id,
55                           int type)
56 {
57         __u64 resname = 0;
58
59         if (len > 8) {
60                 CERROR("name too long: %s\n", name);
61                 return -EINVAL;
62         }
63         if (len <= 0) {
64                 CERROR("missing name: %s\n", name);
65                 return -EINVAL;
66         }
67         memcpy(&resname, name, len);
68
69         /* Always use the same endianness for the resid */
70         memset(res_id, 0, sizeof(*res_id));
71         res_id->name[0] = cpu_to_le64(resname);
72         /* XXX: unfortunately, sptlprc and config llog share one lock */
73         switch(type) {
74         case CONFIG_T_CONFIG:
75         case CONFIG_T_SPTLRPC:
76                 resname = 0;
77                 break;
78         case CONFIG_T_RECOVER:
79                 resname = type;
80                 break;
81         default:
82                 LBUG();
83         }
84         res_id->name[1] = cpu_to_le64(resname);
85         CDEBUG(D_MGC, "log %s to resid "LPX64"/"LPX64" (%.8s)\n", name,
86                res_id->name[0], res_id->name[1], (char *)&res_id->name[0]);
87         return 0;
88 }
89
90 int mgc_fsname2resid(char *fsname, struct ldlm_res_id *res_id, int type)
91 {
92         /* fsname is at most 8 chars long, maybe contain "-".
93          * e.g. "lustre", "SUN-000" */
94         return mgc_name2resid(fsname, strlen(fsname), res_id, type);
95 }
96 EXPORT_SYMBOL(mgc_fsname2resid);
97
98 int mgc_logname2resid(char *logname, struct ldlm_res_id *res_id, int type)
99 {
100         char *name_end;
101         int len;
102
103         /* logname consists of "fsname-nodetype".
104          * e.g. "lustre-MDT0001", "SUN-000-client" */
105         name_end = strrchr(logname, '-');
106         LASSERT(name_end);
107         len = name_end - logname;
108         return mgc_name2resid(logname, len, res_id, type);
109 }
110
111 /********************** config llog list **********************/
112 static LIST_HEAD(config_llog_list);
113 static DEFINE_SPINLOCK(config_list_lock);
114
115 /* Take a reference to a config log */
116 static int config_log_get(struct config_llog_data *cld)
117 {
118         atomic_inc(&cld->cld_refcount);
119         CDEBUG(D_INFO, "log %s refs %d\n", cld->cld_logname,
120                atomic_read(&cld->cld_refcount));
121         return 0;
122 }
123
124 /* Drop a reference to a config log.  When no longer referenced,
125    we can free the config log data */
126 static void config_log_put(struct config_llog_data *cld)
127 {
128         CDEBUG(D_INFO, "log %s refs %d\n", cld->cld_logname,
129                atomic_read(&cld->cld_refcount));
130         LASSERT(atomic_read(&cld->cld_refcount) > 0);
131
132         /* spinlock to make sure no item with 0 refcount in the list */
133         if (atomic_dec_and_lock(&cld->cld_refcount, &config_list_lock)) {
134                 list_del(&cld->cld_list_chain);
135                 spin_unlock(&config_list_lock);
136
137                 CDEBUG(D_MGC, "dropping config log %s\n", cld->cld_logname);
138
139                 if (cld->cld_recover)
140                         config_log_put(cld->cld_recover);
141                 if (cld->cld_sptlrpc)
142                         config_log_put(cld->cld_sptlrpc);
143                 if (cld_is_sptlrpc(cld))
144                         sptlrpc_conf_log_stop(cld->cld_logname);
145
146                 class_export_put(cld->cld_mgcexp);
147                 OBD_FREE(cld, sizeof(*cld) + strlen(cld->cld_logname) + 1);
148         }
149 }
150
151 /* Find a config log by name */
152 static
153 struct config_llog_data *config_log_find(char *logname,
154                                          struct config_llog_instance *cfg)
155 {
156         struct config_llog_data *cld;
157         struct config_llog_data *found = NULL;
158         void *             instance;
159
160         LASSERT(logname != NULL);
161
162         instance = cfg ? cfg->cfg_instance : NULL;
163         spin_lock(&config_list_lock);
164         list_for_each_entry(cld, &config_llog_list, cld_list_chain) {
165                 /* check if instance equals */
166                 if (instance != cld->cld_cfg.cfg_instance)
167                         continue;
168
169                 /* instance may be NULL, should check name */
170                 if (strcmp(logname, cld->cld_logname) == 0) {
171                         found = cld;
172                         break;
173                 }
174         }
175         if (found) {
176                 atomic_inc(&found->cld_refcount);
177                 LASSERT(found->cld_stopping == 0 || cld_is_sptlrpc(found) == 0);
178         }
179         spin_unlock(&config_list_lock);
180         return found;
181 }
182
183 static
184 struct config_llog_data *do_config_log_add(struct obd_device *obd,
185                                            char *logname,
186                                            int type,
187                                            struct config_llog_instance *cfg,
188                                            struct super_block *sb)
189 {
190         struct config_llog_data *cld;
191         int                   rc;
192
193         CDEBUG(D_MGC, "do adding config log %s:%p\n", logname,
194                cfg ? cfg->cfg_instance : 0);
195
196         OBD_ALLOC(cld, sizeof(*cld) + strlen(logname) + 1);
197         if (!cld)
198                 return ERR_PTR(-ENOMEM);
199
200         strcpy(cld->cld_logname, logname);
201         if (cfg)
202                 cld->cld_cfg = *cfg;
203         else
204                 cld->cld_cfg.cfg_callback = class_config_llog_handler;
205         mutex_init(&cld->cld_lock);
206         cld->cld_cfg.cfg_last_idx = 0;
207         cld->cld_cfg.cfg_flags = 0;
208         cld->cld_cfg.cfg_sb = sb;
209         cld->cld_type = type;
210         atomic_set(&cld->cld_refcount, 1);
211
212         /* Keep the mgc around until we are done */
213         cld->cld_mgcexp = class_export_get(obd->obd_self_export);
214
215         if (cld_is_sptlrpc(cld)) {
216                 sptlrpc_conf_log_start(logname);
217                 cld->cld_cfg.cfg_obdname = obd->obd_name;
218         }
219
220         rc = mgc_logname2resid(logname, &cld->cld_resid, type);
221
222         spin_lock(&config_list_lock);
223         list_add(&cld->cld_list_chain, &config_llog_list);
224         spin_unlock(&config_list_lock);
225
226         if (rc) {
227                 config_log_put(cld);
228                 return ERR_PTR(rc);
229         }
230
231         if (cld_is_sptlrpc(cld)) {
232                 rc = mgc_process_log(obd, cld);
233                 if (rc && rc != -ENOENT)
234                         CERROR("failed processing sptlrpc log: %d\n", rc);
235         }
236
237         return cld;
238 }
239
240 static struct config_llog_data *config_recover_log_add(struct obd_device *obd,
241         char *fsname,
242         struct config_llog_instance *cfg,
243         struct super_block *sb)
244 {
245         struct config_llog_instance lcfg = *cfg;
246         struct lustre_sb_info *lsi = s2lsi(sb);
247         struct config_llog_data *cld;
248         char logname[32];
249
250         if (IS_OST(lsi))
251                 return NULL;
252
253         /* for osp-on-ost, see lustre_start_osp() */
254         if (IS_MDT(lsi) && lcfg.cfg_instance)
255                 return NULL;
256
257         /* we have to use different llog for clients and mdts for cmd
258          * where only clients are notified if one of cmd server restarts */
259         LASSERT(strlen(fsname) < sizeof(logname) / 2);
260         strcpy(logname, fsname);
261         if (IS_SERVER(lsi)) { /* mdt */
262                 LASSERT(lcfg.cfg_instance == NULL);
263                 lcfg.cfg_instance = sb;
264                 strcat(logname, "-mdtir");
265         } else {
266                 LASSERT(lcfg.cfg_instance != NULL);
267                 strcat(logname, "-cliir");
268         }
269
270         cld = do_config_log_add(obd, logname, CONFIG_T_RECOVER, &lcfg, sb);
271         return cld;
272 }
273
274
275 /** Add this log to the list of active logs watched by an MGC.
276  * Active means we're watching for updates.
277  * We have one active log per "mount" - client instance or servername.
278  * Each instance may be at a different point in the log.
279  */
280 static int config_log_add(struct obd_device *obd, char *logname,
281                           struct config_llog_instance *cfg,
282                           struct super_block *sb)
283 {
284         struct lustre_sb_info *lsi = s2lsi(sb);
285         struct config_llog_data *cld;
286         struct config_llog_data *sptlrpc_cld;
287         char                 seclogname[32];
288         char                *ptr;
289
290         CDEBUG(D_MGC, "adding config log %s:%p\n", logname, cfg->cfg_instance);
291
292         /*
293          * for each regular log, the depended sptlrpc log name is
294          * <fsname>-sptlrpc. multiple regular logs may share one sptlrpc log.
295          */
296         ptr = strrchr(logname, '-');
297         if (ptr == NULL || ptr - logname > 8) {
298                 CERROR("logname %s is too long\n", logname);
299                 return -EINVAL;
300         }
301
302         memcpy(seclogname, logname, ptr - logname);
303         strcpy(seclogname + (ptr - logname), "-sptlrpc");
304
305         sptlrpc_cld = config_log_find(seclogname, NULL);
306         if (sptlrpc_cld == NULL) {
307                 sptlrpc_cld = do_config_log_add(obd, seclogname,
308                                                 CONFIG_T_SPTLRPC, NULL, NULL);
309                 if (IS_ERR(sptlrpc_cld)) {
310                         CERROR("can't create sptlrpc log: %s\n", seclogname);
311                         return PTR_ERR(sptlrpc_cld);
312                 }
313         }
314
315         cld = do_config_log_add(obd, logname, CONFIG_T_CONFIG, cfg, sb);
316         if (IS_ERR(cld)) {
317                 CERROR("can't create log: %s\n", logname);
318                 config_log_put(sptlrpc_cld);
319                 return PTR_ERR(cld);
320         }
321
322         cld->cld_sptlrpc = sptlrpc_cld;
323
324         LASSERT(lsi->lsi_lmd);
325         if (!(lsi->lsi_lmd->lmd_flags & LMD_FLG_NOIR)) {
326                 struct config_llog_data *recover_cld;
327                 *strrchr(seclogname, '-') = 0;
328                 recover_cld = config_recover_log_add(obd, seclogname, cfg, sb);
329                 if (IS_ERR(recover_cld)) {
330                         config_log_put(cld);
331                         return PTR_ERR(recover_cld);
332                 }
333                 cld->cld_recover = recover_cld;
334         }
335
336         return 0;
337 }
338
339 DEFINE_MUTEX(llog_process_lock);
340
341 /** Stop watching for updates on this log.
342  */
343 static int config_log_end(char *logname, struct config_llog_instance *cfg)
344 {
345         struct config_llog_data *cld;
346         struct config_llog_data *cld_sptlrpc = NULL;
347         struct config_llog_data *cld_recover = NULL;
348         int rc = 0;
349
350         cld = config_log_find(logname, cfg);
351         if (cld == NULL)
352                 return -ENOENT;
353
354         mutex_lock(&cld->cld_lock);
355         /*
356          * if cld_stopping is set, it means we didn't start the log thus
357          * not owning the start ref. this can happen after previous umount:
358          * the cld still hanging there waiting for lock cancel, and we
359          * remount again but failed in the middle and call log_end without
360          * calling start_log.
361          */
362         if (unlikely(cld->cld_stopping)) {
363                 mutex_unlock(&cld->cld_lock);
364                 /* drop the ref from the find */
365                 config_log_put(cld);
366                 return rc;
367         }
368
369         cld->cld_stopping = 1;
370
371         cld_recover = cld->cld_recover;
372         cld->cld_recover = NULL;
373         mutex_unlock(&cld->cld_lock);
374
375         if (cld_recover) {
376                 mutex_lock(&cld_recover->cld_lock);
377                 cld_recover->cld_stopping = 1;
378                 mutex_unlock(&cld_recover->cld_lock);
379                 config_log_put(cld_recover);
380         }
381
382         spin_lock(&config_list_lock);
383         cld_sptlrpc = cld->cld_sptlrpc;
384         cld->cld_sptlrpc = NULL;
385         spin_unlock(&config_list_lock);
386
387         if (cld_sptlrpc)
388                 config_log_put(cld_sptlrpc);
389
390         /* drop the ref from the find */
391         config_log_put(cld);
392         /* drop the start ref */
393         config_log_put(cld);
394
395         CDEBUG(D_MGC, "end config log %s (%d)\n", logname ? logname : "client",
396                rc);
397         return rc;
398 }
399
400 int lprocfs_mgc_rd_ir_state(struct seq_file *m, void *data)
401 {
402         struct obd_device       *obd = data;
403         struct obd_import       *imp = obd->u.cli.cl_import;
404         struct obd_connect_data *ocd = &imp->imp_connect_data;
405         struct config_llog_data *cld;
406
407         seq_printf(m, "imperative_recovery: %s\n",
408                       OCD_HAS_FLAG(ocd, IMP_RECOV) ? "ENABLED" : "DISABLED");
409         seq_printf(m, "client_state:\n");
410
411         spin_lock(&config_list_lock);
412         list_for_each_entry(cld, &config_llog_list, cld_list_chain) {
413                 if (cld->cld_recover == NULL)
414                         continue;
415                 seq_printf(m,  "    - { client: %s, nidtbl_version: %u }\n",
416                                cld->cld_logname,
417                                cld->cld_recover->cld_cfg.cfg_last_idx);
418         }
419         spin_unlock(&config_list_lock);
420
421         return 0;
422 }
423
424 /* reenqueue any lost locks */
425 #define RQ_RUNNING 0x1
426 #define RQ_NOW     0x2
427 #define RQ_LATER   0x4
428 #define RQ_STOP    0x8
429 static int                  rq_state = 0;
430 static wait_queue_head_t            rq_waitq;
431 static DECLARE_COMPLETION(rq_exit);
432
433 static void do_requeue(struct config_llog_data *cld)
434 {
435         LASSERT(atomic_read(&cld->cld_refcount) > 0);
436
437         /* Do not run mgc_process_log on a disconnected export or an
438            export which is being disconnected. Take the client
439            semaphore to make the check non-racy. */
440         down_read(&cld->cld_mgcexp->exp_obd->u.cli.cl_sem);
441         if (cld->cld_mgcexp->exp_obd->u.cli.cl_conn_count != 0) {
442                 CDEBUG(D_MGC, "updating log %s\n", cld->cld_logname);
443                 mgc_process_log(cld->cld_mgcexp->exp_obd, cld);
444         } else {
445                 CDEBUG(D_MGC, "disconnecting, won't update log %s\n",
446                        cld->cld_logname);
447         }
448         up_read(&cld->cld_mgcexp->exp_obd->u.cli.cl_sem);
449 }
450
451 /* this timeout represents how many seconds MGC should wait before
452  * requeue config and recover lock to the MGS. We need to randomize this
453  * in order to not flood the MGS.
454  */
455 #define MGC_TIMEOUT_MIN_SECONDS   5
456 #define MGC_TIMEOUT_RAND_CENTISEC 0x1ff /* ~500 */
457
458 static int mgc_requeue_thread(void *data)
459 {
460         int rc = 0;
461
462         CDEBUG(D_MGC, "Starting requeue thread\n");
463
464         /* Keep trying failed locks periodically */
465         spin_lock(&config_list_lock);
466         rq_state |= RQ_RUNNING;
467         while (1) {
468                 struct l_wait_info lwi;
469                 struct config_llog_data *cld, *cld_prev;
470                 int rand = cfs_rand() & MGC_TIMEOUT_RAND_CENTISEC;
471                 int stopped = !!(rq_state & RQ_STOP);
472                 int to;
473
474                 /* Any new or requeued lostlocks will change the state */
475                 rq_state &= ~(RQ_NOW | RQ_LATER);
476                 spin_unlock(&config_list_lock);
477
478                 /* Always wait a few seconds to allow the server who
479                    caused the lock revocation to finish its setup, plus some
480                    random so everyone doesn't try to reconnect at once. */
481                 to = MGC_TIMEOUT_MIN_SECONDS * HZ;
482                 to += rand * HZ / 100; /* rand is centi-seconds */
483                 lwi = LWI_TIMEOUT(to, NULL, NULL);
484                 l_wait_event(rq_waitq, rq_state & RQ_STOP, &lwi);
485
486                 /*
487                  * iterate & processing through the list. for each cld, process
488                  * its depending sptlrpc cld firstly (if any) and then itself.
489                  *
490                  * it's guaranteed any item in the list must have
491                  * reference > 0; and if cld_lostlock is set, at
492                  * least one reference is taken by the previous enqueue.
493                  */
494                 cld_prev = NULL;
495
496                 spin_lock(&config_list_lock);
497                 list_for_each_entry(cld, &config_llog_list,
498                                         cld_list_chain) {
499                         if (!cld->cld_lostlock)
500                                 continue;
501
502                         spin_unlock(&config_list_lock);
503
504                         LASSERT(atomic_read(&cld->cld_refcount) > 0);
505
506                         /* Whether we enqueued again or not in mgc_process_log,
507                          * we're done with the ref from the old enqueue */
508                         if (cld_prev)
509                                 config_log_put(cld_prev);
510                         cld_prev = cld;
511
512                         cld->cld_lostlock = 0;
513                         if (likely(!stopped))
514                                 do_requeue(cld);
515
516                         spin_lock(&config_list_lock);
517                 }
518                 spin_unlock(&config_list_lock);
519                 if (cld_prev)
520                         config_log_put(cld_prev);
521
522                 /* break after scanning the list so that we can drop
523                  * refcount to losing lock clds */
524                 if (unlikely(stopped)) {
525                         spin_lock(&config_list_lock);
526                         break;
527                 }
528
529                 /* Wait a bit to see if anyone else needs a requeue */
530                 lwi = (struct l_wait_info) { 0 };
531                 l_wait_event(rq_waitq, rq_state & (RQ_NOW | RQ_STOP),
532                              &lwi);
533                 spin_lock(&config_list_lock);
534         }
535         /* spinlock and while guarantee RQ_NOW and RQ_LATER are not set */
536         rq_state &= ~RQ_RUNNING;
537         spin_unlock(&config_list_lock);
538
539         complete(&rq_exit);
540
541         CDEBUG(D_MGC, "Ending requeue thread\n");
542         return rc;
543 }
544
545 /* Add a cld to the list to requeue.  Start the requeue thread if needed.
546    We are responsible for dropping the config log reference from here on out. */
547 static void mgc_requeue_add(struct config_llog_data *cld)
548 {
549         CDEBUG(D_INFO, "log %s: requeue (r=%d sp=%d st=%x)\n",
550                cld->cld_logname, atomic_read(&cld->cld_refcount),
551                cld->cld_stopping, rq_state);
552         LASSERT(atomic_read(&cld->cld_refcount) > 0);
553
554         mutex_lock(&cld->cld_lock);
555         if (cld->cld_stopping || cld->cld_lostlock) {
556                 mutex_unlock(&cld->cld_lock);
557                 return;
558         }
559         /* this refcount will be released in mgc_requeue_thread. */
560         config_log_get(cld);
561         cld->cld_lostlock = 1;
562         mutex_unlock(&cld->cld_lock);
563
564         /* Hold lock for rq_state */
565         spin_lock(&config_list_lock);
566         if (rq_state & RQ_STOP) {
567                 spin_unlock(&config_list_lock);
568                 cld->cld_lostlock = 0;
569                 config_log_put(cld);
570         } else {
571                 rq_state |= RQ_NOW;
572                 spin_unlock(&config_list_lock);
573                 wake_up(&rq_waitq);
574         }
575 }
576
577 /********************** class fns **********************/
578 static int mgc_local_llog_init(const struct lu_env *env,
579                                struct obd_device *obd,
580                                struct obd_device *disk)
581 {
582         struct llog_ctxt        *ctxt;
583         int                      rc;
584
585         rc = llog_setup(env, obd, &obd->obd_olg, LLOG_CONFIG_ORIG_CTXT, disk,
586                         &llog_osd_ops);
587         if (rc)
588                 return rc;
589
590         ctxt = llog_get_context(obd, LLOG_CONFIG_ORIG_CTXT);
591         LASSERT(ctxt);
592         ctxt->loc_dir = obd->u.cli.cl_mgc_configs_dir;
593         llog_ctxt_put(ctxt);
594
595         return 0;
596 }
597
598 static int mgc_local_llog_fini(const struct lu_env *env,
599                                struct obd_device *obd)
600 {
601         struct llog_ctxt *ctxt;
602
603         ctxt = llog_get_context(obd, LLOG_CONFIG_ORIG_CTXT);
604         llog_cleanup(env, ctxt);
605
606         return 0;
607 }
608
609 static int mgc_fs_setup(struct obd_device *obd, struct super_block *sb)
610 {
611         struct lustre_sb_info   *lsi = s2lsi(sb);
612         struct client_obd       *cli = &obd->u.cli;
613         struct lu_fid            rfid, fid;
614         struct dt_object        *root, *dto;
615         struct lu_env           *env;
616         int                      rc = 0;
617
618         LASSERT(lsi);
619         LASSERT(lsi->lsi_dt_dev);
620
621         OBD_ALLOC_PTR(env);
622         if (env == NULL)
623                 return -ENOMEM;
624
625         /* The mgc fs exclusion sem. Only one fs can be setup at a time. */
626         down(&cli->cl_mgc_sem);
627
628         cfs_cleanup_group_info();
629
630         /* Setup the configs dir */
631         rc = lu_env_init(env, LCT_MG_THREAD);
632         if (rc)
633                 GOTO(out_err, rc);
634
635         fid.f_seq = FID_SEQ_LOCAL_NAME;
636         fid.f_oid = 1;
637         fid.f_ver = 0;
638         rc = local_oid_storage_init(env, lsi->lsi_dt_dev, &fid,
639                                     &cli->cl_mgc_los);
640         if (rc)
641                 GOTO(out_env, rc);
642
643         rc = dt_root_get(env, lsi->lsi_dt_dev, &rfid);
644         if (rc)
645                 GOTO(out_env, rc);
646
647         root = dt_locate_at(env, lsi->lsi_dt_dev, &rfid,
648                             &cli->cl_mgc_los->los_dev->dd_lu_dev);
649         if (unlikely(IS_ERR(root)))
650                 GOTO(out_los, rc = PTR_ERR(root));
651
652         dto = local_file_find_or_create(env, cli->cl_mgc_los, root,
653                                         MOUNT_CONFIGS_DIR,
654                                         S_IFDIR | S_IRUGO | S_IWUSR | S_IXUGO);
655         lu_object_put_nocache(env, &root->do_lu);
656         if (IS_ERR(dto))
657                 GOTO(out_los, rc = PTR_ERR(dto));
658
659         cli->cl_mgc_configs_dir = dto;
660
661         LASSERT(lsi->lsi_osd_exp->exp_obd->obd_lvfs_ctxt.dt);
662         rc = mgc_local_llog_init(env, obd, lsi->lsi_osd_exp->exp_obd);
663         if (rc)
664                 GOTO(out_llog, rc);
665
666         /* We take an obd ref to insure that we can't get to mgc_cleanup
667          * without calling mgc_fs_cleanup first. */
668         class_incref(obd, "mgc_fs", obd);
669
670         /* We keep the cl_mgc_sem until mgc_fs_cleanup */
671 out_llog:
672         if (rc) {
673                 lu_object_put(env, &cli->cl_mgc_configs_dir->do_lu);
674                 cli->cl_mgc_configs_dir = NULL;
675         }
676 out_los:
677         if (rc < 0) {
678                 local_oid_storage_fini(env, cli->cl_mgc_los);
679                 cli->cl_mgc_los = NULL;
680                 up(&cli->cl_mgc_sem);
681         }
682 out_env:
683         lu_env_fini(env);
684 out_err:
685         OBD_FREE_PTR(env);
686         return rc;
687 }
688
689 static int mgc_fs_cleanup(struct obd_device *obd)
690 {
691         struct lu_env            env;
692         struct client_obd       *cli = &obd->u.cli;
693         int                      rc;
694
695         LASSERT(cli->cl_mgc_los != NULL);
696
697         rc = lu_env_init(&env, LCT_MG_THREAD);
698         if (rc)
699                 GOTO(unlock, rc);
700
701         mgc_local_llog_fini(&env, obd);
702
703         lu_object_put_nocache(&env, &cli->cl_mgc_configs_dir->do_lu);
704         cli->cl_mgc_configs_dir = NULL;
705
706         local_oid_storage_fini(&env, cli->cl_mgc_los);
707         cli->cl_mgc_los = NULL;
708         lu_env_fini(&env);
709
710 unlock:
711         class_decref(obd, "mgc_fs", obd);
712         up(&cli->cl_mgc_sem);
713
714         return 0;
715 }
716
717 static int mgc_llog_init(const struct lu_env *env, struct obd_device *obd)
718 {
719         struct llog_ctxt        *ctxt;
720         int                      rc;
721
722         /* setup only remote ctxt, the local disk context is switched per each
723          * filesystem during mgc_fs_setup() */
724         rc = llog_setup(env, obd, &obd->obd_olg, LLOG_CONFIG_REPL_CTXT, obd,
725                         &llog_client_ops);
726         if (rc)
727                 return rc;
728
729         ctxt = llog_get_context(obd, LLOG_CONFIG_REPL_CTXT);
730         LASSERT(ctxt);
731
732         llog_initiator_connect(ctxt);
733         llog_ctxt_put(ctxt);
734
735         return 0;
736 }
737
738 static int mgc_llog_fini(const struct lu_env *env, struct obd_device *obd)
739 {
740         struct llog_ctxt *ctxt;
741
742         ctxt = llog_get_context(obd, LLOG_CONFIG_REPL_CTXT);
743         if (ctxt)
744                 llog_cleanup(env, ctxt);
745
746         return 0;
747 }
748
749 static atomic_t mgc_count = ATOMIC_INIT(0);
750 static int mgc_precleanup(struct obd_device *obd, enum obd_cleanup_stage stage)
751 {
752         int rc = 0;
753
754         switch (stage) {
755         case OBD_CLEANUP_EARLY:
756                 break;
757         case OBD_CLEANUP_EXPORTS:
758                 if (atomic_dec_and_test(&mgc_count)) {
759                         int running;
760                         /* stop requeue thread */
761                         spin_lock(&config_list_lock);
762                         running = rq_state & RQ_RUNNING;
763                         if (running)
764                                 rq_state |= RQ_STOP;
765                         spin_unlock(&config_list_lock);
766                         if (running) {
767                                 wake_up(&rq_waitq);
768                                 wait_for_completion(&rq_exit);
769                         }
770                 }
771                 obd_cleanup_client_import(obd);
772                 rc = mgc_llog_fini(NULL, obd);
773                 if (rc != 0)
774                         CERROR("failed to cleanup llogging subsystems\n");
775                 break;
776         }
777         return rc;
778 }
779
780 static int mgc_cleanup(struct obd_device *obd)
781 {
782         int rc;
783
784         /* COMPAT_146 - old config logs may have added profiles we don't
785            know about */
786         if (obd->obd_type->typ_refcnt <= 1)
787                 /* Only for the last mgc */
788                 class_del_profiles();
789
790         lprocfs_obd_cleanup(obd);
791         ptlrpcd_decref();
792
793         rc = client_obd_cleanup(obd);
794         return rc;
795 }
796
797 static int mgc_setup(struct obd_device *obd, struct lustre_cfg *lcfg)
798 {
799         struct lprocfs_static_vars lvars;
800         int rc;
801
802         ptlrpcd_addref();
803
804         rc = client_obd_setup(obd, lcfg);
805         if (rc)
806                 GOTO(err_decref, rc);
807
808         rc = mgc_llog_init(NULL, obd);
809         if (rc) {
810                 CERROR("failed to setup llogging subsystems\n");
811                 GOTO(err_cleanup, rc);
812         }
813
814         lprocfs_mgc_init_vars(&lvars);
815         lprocfs_obd_setup(obd, lvars.obd_vars);
816         sptlrpc_lprocfs_cliobd_attach(obd);
817
818         if (atomic_inc_return(&mgc_count) == 1) {
819                 rq_state = 0;
820                 init_waitqueue_head(&rq_waitq);
821
822                 /* start requeue thread */
823                 rc = PTR_ERR(kthread_run(mgc_requeue_thread, NULL,
824                                              "ll_cfg_requeue"));
825                 if (IS_ERR_VALUE(rc)) {
826                         CERROR("%s: Cannot start requeue thread (%d),"
827                                "no more log updates!\n",
828                                obd->obd_name, rc);
829                         GOTO(err_cleanup, rc);
830                 }
831                 /* rc is the task_struct pointer of mgc_requeue_thread. */
832                 rc = 0;
833         }
834
835         return rc;
836
837 err_cleanup:
838         client_obd_cleanup(obd);
839 err_decref:
840         ptlrpcd_decref();
841         return rc;
842 }
843
844 /* based on ll_mdc_blocking_ast */
845 static int mgc_blocking_ast(struct ldlm_lock *lock, struct ldlm_lock_desc *desc,
846                             void *data, int flag)
847 {
848         struct lustre_handle lockh;
849         struct config_llog_data *cld = (struct config_llog_data *)data;
850         int rc = 0;
851
852         switch (flag) {
853         case LDLM_CB_BLOCKING:
854                 /* mgs wants the lock, give it up... */
855                 LDLM_DEBUG(lock, "MGC blocking CB");
856                 ldlm_lock2handle(lock, &lockh);
857                 rc = ldlm_cli_cancel(&lockh, LCF_ASYNC);
858                 break;
859         case LDLM_CB_CANCELING:
860                 /* We've given up the lock, prepare ourselves to update. */
861                 LDLM_DEBUG(lock, "MGC cancel CB");
862
863                 CDEBUG(D_MGC, "Lock res "DLDLMRES" (%.8s)\n",
864                        PLDLMRES(lock->l_resource),
865                        (char *)&lock->l_resource->lr_name.name[0]);
866
867                 if (!cld) {
868                         CDEBUG(D_INFO, "missing data, won't requeue\n");
869                         break;
870                 }
871
872                 /* held at mgc_process_log(). */
873                 LASSERT(atomic_read(&cld->cld_refcount) > 0);
874                 /* Are we done with this log? */
875                 if (cld->cld_stopping) {
876                         CDEBUG(D_MGC, "log %s: stopping, won't requeue\n",
877                                cld->cld_logname);
878                         config_log_put(cld);
879                         break;
880                 }
881                 /* Make sure not to re-enqueue when the mgc is stopping
882                    (we get called from client_disconnect_export) */
883                 if (!lock->l_conn_export ||
884                     !lock->l_conn_export->exp_obd->u.cli.cl_conn_count) {
885                         CDEBUG(D_MGC, "log %.8s: disconnecting, won't requeue\n",
886                                cld->cld_logname);
887                         config_log_put(cld);
888                         break;
889                 }
890
891                 /* Re-enqueue now */
892                 mgc_requeue_add(cld);
893                 config_log_put(cld);
894                 break;
895         default:
896                 LBUG();
897         }
898
899         return rc;
900 }
901
902 /* Not sure where this should go... */
903 #define  MGC_ENQUEUE_LIMIT 50
904 #define  MGC_TARGET_REG_LIMIT 10
905 #define  MGC_SEND_PARAM_LIMIT 10
906
907 /* Send parameter to MGS*/
908 static int mgc_set_mgs_param(struct obd_export *exp,
909                              struct mgs_send_param *msp)
910 {
911         struct ptlrpc_request *req;
912         struct mgs_send_param *req_msp, *rep_msp;
913         int rc;
914
915         req = ptlrpc_request_alloc_pack(class_exp2cliimp(exp),
916                                         &RQF_MGS_SET_INFO, LUSTRE_MGS_VERSION,
917                                         MGS_SET_INFO);
918         if (!req)
919                 return -ENOMEM;
920
921         req_msp = req_capsule_client_get(&req->rq_pill, &RMF_MGS_SEND_PARAM);
922         if (!req_msp) {
923                 ptlrpc_req_finished(req);
924                 return -ENOMEM;
925         }
926
927         memcpy(req_msp, msp, sizeof(*req_msp));
928         ptlrpc_request_set_replen(req);
929
930         /* Limit how long we will wait for the enqueue to complete */
931         req->rq_delay_limit = MGC_SEND_PARAM_LIMIT;
932         rc = ptlrpc_queue_wait(req);
933         if (!rc) {
934                 rep_msp = req_capsule_server_get(&req->rq_pill, &RMF_MGS_SEND_PARAM);
935                 memcpy(msp, rep_msp, sizeof(*rep_msp));
936         }
937
938         ptlrpc_req_finished(req);
939
940         return rc;
941 }
942
943 /* Take a config lock so we can get cancel notifications */
944 static int mgc_enqueue(struct obd_export *exp, struct lov_stripe_md *lsm,
945                        __u32 type, ldlm_policy_data_t *policy, __u32 mode,
946                        __u64 *flags, void *bl_cb, void *cp_cb, void *gl_cb,
947                        void *data, __u32 lvb_len, void *lvb_swabber,
948                        struct lustre_handle *lockh)
949 {
950         struct config_llog_data *cld = (struct config_llog_data *)data;
951         struct ldlm_enqueue_info einfo = {
952                 .ei_type        = type,
953                 .ei_mode        = mode,
954                 .ei_cb_bl       = mgc_blocking_ast,
955                 .ei_cb_cp       = ldlm_completion_ast,
956         };
957         struct ptlrpc_request *req;
958         int short_limit = cld_is_sptlrpc(cld);
959         int rc;
960
961         CDEBUG(D_MGC, "Enqueue for %s (res "LPX64")\n", cld->cld_logname,
962                cld->cld_resid.name[0]);
963
964         /* We need a callback for every lockholder, so don't try to
965            ldlm_lock_match (see rev 1.1.2.11.2.47) */
966         req = ptlrpc_request_alloc_pack(class_exp2cliimp(exp),
967                                         &RQF_LDLM_ENQUEUE, LUSTRE_DLM_VERSION,
968                                         LDLM_ENQUEUE);
969         if (req == NULL)
970                 return -ENOMEM;
971
972         req_capsule_set_size(&req->rq_pill, &RMF_DLM_LVB, RCL_SERVER, 0);
973         ptlrpc_request_set_replen(req);
974
975         /* check if this is server or client */
976         if (cld->cld_cfg.cfg_sb) {
977                 struct lustre_sb_info *lsi = s2lsi(cld->cld_cfg.cfg_sb);
978                 if (lsi && IS_SERVER(lsi))
979                         short_limit = 1;
980         }
981         /* Limit how long we will wait for the enqueue to complete */
982         req->rq_delay_limit = short_limit ? 5 : MGC_ENQUEUE_LIMIT;
983         rc = ldlm_cli_enqueue(exp, &req, &einfo, &cld->cld_resid, NULL, flags,
984                               NULL, 0, LVB_T_NONE, lockh, 0);
985         /* A failed enqueue should still call the mgc_blocking_ast,
986            where it will be requeued if needed ("grant failed"). */
987         ptlrpc_req_finished(req);
988         return rc;
989 }
990
991 static int mgc_cancel(struct obd_export *exp, struct lov_stripe_md *md,
992                       __u32 mode, struct lustre_handle *lockh)
993 {
994         ldlm_lock_decref(lockh, mode);
995
996         return 0;
997 }
998
999 static void mgc_notify_active(struct obd_device *unused)
1000 {
1001         /* wakeup mgc_requeue_thread to requeue mgc lock */
1002         spin_lock(&config_list_lock);
1003         rq_state |= RQ_NOW;
1004         spin_unlock(&config_list_lock);
1005         wake_up(&rq_waitq);
1006
1007         /* TODO: Help the MGS rebuild nidtbl. -jay */
1008 }
1009
1010 /* Send target_reg message to MGS */
1011 static int mgc_target_register(struct obd_export *exp,
1012                                struct mgs_target_info *mti)
1013 {
1014         struct ptlrpc_request  *req;
1015         struct mgs_target_info *req_mti, *rep_mti;
1016         int                  rc;
1017
1018         req = ptlrpc_request_alloc_pack(class_exp2cliimp(exp),
1019                                         &RQF_MGS_TARGET_REG, LUSTRE_MGS_VERSION,
1020                                         MGS_TARGET_REG);
1021         if (req == NULL)
1022                 return -ENOMEM;
1023
1024         req_mti = req_capsule_client_get(&req->rq_pill, &RMF_MGS_TARGET_INFO);
1025         if (!req_mti) {
1026                 ptlrpc_req_finished(req);
1027                 return -ENOMEM;
1028         }
1029
1030         memcpy(req_mti, mti, sizeof(*req_mti));
1031         ptlrpc_request_set_replen(req);
1032         CDEBUG(D_MGC, "register %s\n", mti->mti_svname);
1033         /* Limit how long we will wait for the enqueue to complete */
1034         req->rq_delay_limit = MGC_TARGET_REG_LIMIT;
1035
1036         rc = ptlrpc_queue_wait(req);
1037         if (!rc) {
1038                 rep_mti = req_capsule_server_get(&req->rq_pill,
1039                                                  &RMF_MGS_TARGET_INFO);
1040                 memcpy(mti, rep_mti, sizeof(*rep_mti));
1041                 CDEBUG(D_MGC, "register %s got index = %d\n",
1042                        mti->mti_svname, mti->mti_stripe_index);
1043         }
1044         ptlrpc_req_finished(req);
1045
1046         return rc;
1047 }
1048
1049 int mgc_set_info_async(const struct lu_env *env, struct obd_export *exp,
1050                        obd_count keylen, void *key, obd_count vallen,
1051                        void *val, struct ptlrpc_request_set *set)
1052 {
1053         int rc = -EINVAL;
1054
1055         /* Turn off initial_recov after we try all backup servers once */
1056         if (KEY_IS(KEY_INIT_RECOV_BACKUP)) {
1057                 struct obd_import *imp = class_exp2cliimp(exp);
1058                 int value;
1059                 if (vallen != sizeof(int))
1060                         return -EINVAL;
1061                 value = *(int *)val;
1062                 CDEBUG(D_MGC, "InitRecov %s %d/d%d:i%d:r%d:or%d:%s\n",
1063                        imp->imp_obd->obd_name, value,
1064                        imp->imp_deactive, imp->imp_invalid,
1065                        imp->imp_replayable, imp->imp_obd->obd_replayable,
1066                        ptlrpc_import_state_name(imp->imp_state));
1067                 /* Resurrect if we previously died */
1068                 if ((imp->imp_state != LUSTRE_IMP_FULL &&
1069                      imp->imp_state != LUSTRE_IMP_NEW) || value > 1)
1070                         ptlrpc_reconnect_import(imp);
1071                 return 0;
1072         }
1073         /* FIXME move this to mgc_process_config */
1074         if (KEY_IS(KEY_REGISTER_TARGET)) {
1075                 struct mgs_target_info *mti;
1076                 if (vallen != sizeof(struct mgs_target_info))
1077                         return -EINVAL;
1078                 mti = (struct mgs_target_info *)val;
1079                 CDEBUG(D_MGC, "register_target %s %#x\n",
1080                        mti->mti_svname, mti->mti_flags);
1081                 rc =  mgc_target_register(exp, mti);
1082                 return rc;
1083         }
1084         if (KEY_IS(KEY_SET_FS)) {
1085                 struct super_block *sb = (struct super_block *)val;
1086
1087                 if (vallen != sizeof(struct super_block))
1088                         return -EINVAL;
1089
1090                 rc = mgc_fs_setup(exp->exp_obd, sb);
1091                 if (rc) {
1092                         CERROR("set_fs got %d\n", rc);
1093                 }
1094                 return rc;
1095         }
1096         if (KEY_IS(KEY_CLEAR_FS)) {
1097                 if (vallen != 0)
1098                         return -EINVAL;
1099                 rc = mgc_fs_cleanup(exp->exp_obd);
1100                 if (rc) {
1101                         CERROR("clear_fs got %d\n", rc);
1102                 }
1103                 return rc;
1104         }
1105         if (KEY_IS(KEY_SET_INFO)) {
1106                 struct mgs_send_param *msp;
1107
1108                 msp = (struct mgs_send_param *)val;
1109                 rc =  mgc_set_mgs_param(exp, msp);
1110                 return rc;
1111         }
1112         if (KEY_IS(KEY_MGSSEC)) {
1113                 struct client_obd     *cli = &exp->exp_obd->u.cli;
1114                 struct sptlrpc_flavor  flvr;
1115
1116                 /*
1117                  * empty string means using current flavor, if which haven't
1118                  * been set yet, set it as null.
1119                  *
1120                  * if flavor has been set previously, check the asking flavor
1121                  * must match the existing one.
1122                  */
1123                 if (vallen == 0) {
1124                         if (cli->cl_flvr_mgc.sf_rpc != SPTLRPC_FLVR_INVALID)
1125                                 return 0;
1126                         val = "null";
1127                         vallen = 4;
1128                 }
1129
1130                 rc = sptlrpc_parse_flavor(val, &flvr);
1131                 if (rc) {
1132                         CERROR("invalid sptlrpc flavor %s to MGS\n",
1133                                (char *) val);
1134                         return rc;
1135                 }
1136
1137                 /*
1138                  * caller already hold a mutex
1139                  */
1140                 if (cli->cl_flvr_mgc.sf_rpc == SPTLRPC_FLVR_INVALID) {
1141                         cli->cl_flvr_mgc = flvr;
1142                 } else if (memcmp(&cli->cl_flvr_mgc, &flvr,
1143                                   sizeof(flvr)) != 0) {
1144                         char    str[20];
1145
1146                         sptlrpc_flavor2name(&cli->cl_flvr_mgc,
1147                                             str, sizeof(str));
1148                         LCONSOLE_ERROR("asking sptlrpc flavor %s to MGS but "
1149                                        "currently %s is in use\n",
1150                                        (char *) val, str);
1151                         rc = -EPERM;
1152                 }
1153                 return rc;
1154         }
1155
1156         return rc;
1157 }
1158
1159 static int mgc_get_info(const struct lu_env *env, struct obd_export *exp,
1160                         __u32 keylen, void *key, __u32 *vallen, void *val,
1161                         struct lov_stripe_md *unused)
1162 {
1163         int rc = -EINVAL;
1164
1165         if (KEY_IS(KEY_CONN_DATA)) {
1166                 struct obd_import *imp = class_exp2cliimp(exp);
1167                 struct obd_connect_data *data = val;
1168
1169                 if (*vallen == sizeof(*data)) {
1170                         *data = imp->imp_connect_data;
1171                         rc = 0;
1172                 }
1173         }
1174
1175         return rc;
1176 }
1177
1178 static int mgc_import_event(struct obd_device *obd,
1179                             struct obd_import *imp,
1180                             enum obd_import_event event)
1181 {
1182         int rc = 0;
1183
1184         LASSERT(imp->imp_obd == obd);
1185         CDEBUG(D_MGC, "import event %#x\n", event);
1186
1187         switch (event) {
1188         case IMP_EVENT_DISCON:
1189                 /* MGC imports should not wait for recovery */
1190                 if (OCD_HAS_FLAG(&imp->imp_connect_data, IMP_RECOV))
1191                         ptlrpc_pinger_ir_down();
1192                 break;
1193         case IMP_EVENT_INACTIVE:
1194                 break;
1195         case IMP_EVENT_INVALIDATE: {
1196                 struct ldlm_namespace *ns = obd->obd_namespace;
1197                 ldlm_namespace_cleanup(ns, LDLM_FL_LOCAL_ONLY);
1198                 break;
1199         }
1200         case IMP_EVENT_ACTIVE:
1201                 CDEBUG(D_INFO, "%s: Reactivating import\n", obd->obd_name);
1202                 /* Clearing obd_no_recov allows us to continue pinging */
1203                 obd->obd_no_recov = 0;
1204                 mgc_notify_active(obd);
1205                 if (OCD_HAS_FLAG(&imp->imp_connect_data, IMP_RECOV))
1206                         ptlrpc_pinger_ir_up();
1207                 break;
1208         case IMP_EVENT_OCD:
1209                 break;
1210         case IMP_EVENT_DEACTIVATE:
1211         case IMP_EVENT_ACTIVATE:
1212                 break;
1213         default:
1214                 CERROR("Unknown import event %#x\n", event);
1215                 LBUG();
1216         }
1217         return rc;
1218 }
1219
1220 enum {
1221         CONFIG_READ_NRPAGES_INIT = 1 << (20 - PAGE_CACHE_SHIFT),
1222         CONFIG_READ_NRPAGES      = 4
1223 };
1224
1225 static int mgc_apply_recover_logs(struct obd_device *mgc,
1226                                   struct config_llog_data *cld,
1227                                   __u64 max_version,
1228                                   void *data, int datalen, bool mne_swab)
1229 {
1230         struct config_llog_instance *cfg = &cld->cld_cfg;
1231         struct lustre_sb_info       *lsi = s2lsi(cfg->cfg_sb);
1232         struct mgs_nidtbl_entry *entry;
1233         struct lustre_cfg       *lcfg;
1234         struct lustre_cfg_bufs   bufs;
1235         u64   prev_version = 0;
1236         char *inst;
1237         char *buf;
1238         int   bufsz;
1239         int   pos;
1240         int   rc  = 0;
1241         int   off = 0;
1242
1243         LASSERT(cfg->cfg_instance != NULL);
1244         LASSERT(cfg->cfg_sb == cfg->cfg_instance);
1245
1246         OBD_ALLOC(inst, PAGE_CACHE_SIZE);
1247         if (inst == NULL)
1248                 return -ENOMEM;
1249
1250         if (!IS_SERVER(lsi)) {
1251                 pos = snprintf(inst, PAGE_CACHE_SIZE, "%p", cfg->cfg_instance);
1252                 if (pos >= PAGE_CACHE_SIZE) {
1253                         OBD_FREE(inst, PAGE_CACHE_SIZE);
1254                         return -E2BIG;
1255                 }
1256         } else {
1257                 LASSERT(IS_MDT(lsi));
1258                 rc = server_name2svname(lsi->lsi_svname, inst, NULL,
1259                                         PAGE_CACHE_SIZE);
1260                 if (rc) {
1261                         OBD_FREE(inst, PAGE_CACHE_SIZE);
1262                         return -EINVAL;
1263                 }
1264                 pos = strlen(inst);
1265         }
1266
1267         ++pos;
1268         buf   = inst + pos;
1269         bufsz = PAGE_CACHE_SIZE - pos;
1270
1271         while (datalen > 0) {
1272                 int   entry_len = sizeof(*entry);
1273                 int   is_ost;
1274                 struct obd_device *obd;
1275                 char *obdname;
1276                 char *cname;
1277                 char *params;
1278                 char *uuid;
1279
1280                 rc = -EINVAL;
1281                 if (datalen < sizeof(*entry))
1282                         break;
1283
1284                 entry = (typeof(entry))(data + off);
1285
1286                 /* sanity check */
1287                 if (entry->mne_nid_type != 0) /* only support type 0 for ipv4 */
1288                         break;
1289                 if (entry->mne_nid_count == 0) /* at least one nid entry */
1290                         break;
1291                 if (entry->mne_nid_size != sizeof(lnet_nid_t))
1292                         break;
1293
1294                 entry_len += entry->mne_nid_count * entry->mne_nid_size;
1295                 if (datalen < entry_len) /* must have entry_len at least */
1296                         break;
1297
1298                 /* Keep this swab for normal mixed endian handling. LU-1644 */
1299                 if (mne_swab)
1300                         lustre_swab_mgs_nidtbl_entry(entry);
1301                 if (entry->mne_length > PAGE_CACHE_SIZE) {
1302                         CERROR("MNE too large (%u)\n", entry->mne_length);
1303                         break;
1304                 }
1305
1306                 if (entry->mne_length < entry_len)
1307                         break;
1308
1309                 off     += entry->mne_length;
1310                 datalen -= entry->mne_length;
1311                 if (datalen < 0)
1312                         break;
1313
1314                 if (entry->mne_version > max_version) {
1315                         CERROR("entry index(%lld) is over max_index(%lld)\n",
1316                                entry->mne_version, max_version);
1317                         break;
1318                 }
1319
1320                 if (prev_version >= entry->mne_version) {
1321                         CERROR("index unsorted, prev %lld, now %lld\n",
1322                                prev_version, entry->mne_version);
1323                         break;
1324                 }
1325                 prev_version = entry->mne_version;
1326
1327                 /*
1328                  * Write a string with format "nid::instance" to
1329                  * lustre/<osc|mdc>/<target>-<osc|mdc>-<instance>/import.
1330                  */
1331
1332                 is_ost = entry->mne_type == LDD_F_SV_TYPE_OST;
1333                 memset(buf, 0, bufsz);
1334                 obdname = buf;
1335                 pos = 0;
1336
1337                 /* lustre-OST0001-osc-<instance #> */
1338                 strcpy(obdname, cld->cld_logname);
1339                 cname = strrchr(obdname, '-');
1340                 if (cname == NULL) {
1341                         CERROR("mgc %s: invalid logname %s\n",
1342                                mgc->obd_name, obdname);
1343                         break;
1344                 }
1345
1346                 pos = cname - obdname;
1347                 obdname[pos] = 0;
1348                 pos += sprintf(obdname + pos, "-%s%04x",
1349                                   is_ost ? "OST" : "MDT", entry->mne_index);
1350
1351                 cname = is_ost ? "osc" : "mdc",
1352                 pos += sprintf(obdname + pos, "-%s-%s", cname, inst);
1353                 lustre_cfg_bufs_reset(&bufs, obdname);
1354
1355                 /* find the obd by obdname */
1356                 obd = class_name2obd(obdname);
1357                 if (obd == NULL) {
1358                         CDEBUG(D_INFO, "mgc %s: cannot find obdname %s\n",
1359                                mgc->obd_name, obdname);
1360                         rc = 0;
1361                         /* this is a safe race, when the ost is starting up...*/
1362                         continue;
1363                 }
1364
1365                 /* osc.import = "connection=<Conn UUID>::<target instance>" */
1366                 ++pos;
1367                 params = buf + pos;
1368                 pos += sprintf(params, "%s.import=%s", cname, "connection=");
1369                 uuid = buf + pos;
1370
1371                 down_read(&obd->u.cli.cl_sem);
1372                 if (obd->u.cli.cl_import == NULL) {
1373                         /* client does not connect to the OST yet */
1374                         up_read(&obd->u.cli.cl_sem);
1375                         rc = 0;
1376                         continue;
1377                 }
1378
1379                 /* TODO: iterate all nids to find one */
1380                 /* find uuid by nid */
1381                 rc = client_import_find_conn(obd->u.cli.cl_import,
1382                                              entry->u.nids[0],
1383                                              (struct obd_uuid *)uuid);
1384                 up_read(&obd->u.cli.cl_sem);
1385                 if (rc < 0) {
1386                         CERROR("mgc: cannot find uuid by nid %s\n",
1387                                libcfs_nid2str(entry->u.nids[0]));
1388                         break;
1389                 }
1390
1391                 CDEBUG(D_INFO, "Find uuid %s by nid %s\n",
1392                        uuid, libcfs_nid2str(entry->u.nids[0]));
1393
1394                 pos += strlen(uuid);
1395                 pos += sprintf(buf + pos, "::%u", entry->mne_instance);
1396                 LASSERT(pos < bufsz);
1397
1398                 lustre_cfg_bufs_set_string(&bufs, 1, params);
1399
1400                 rc = -ENOMEM;
1401                 lcfg = lustre_cfg_new(LCFG_PARAM, &bufs);
1402                 if (lcfg == NULL) {
1403                         CERROR("mgc: cannot allocate memory\n");
1404                         break;
1405                 }
1406
1407                 CDEBUG(D_INFO, "ir apply logs "LPD64"/"LPD64" for %s -> %s\n",
1408                        prev_version, max_version, obdname, params);
1409
1410                 rc = class_process_config(lcfg);
1411                 lustre_cfg_free(lcfg);
1412                 if (rc)
1413                         CDEBUG(D_INFO, "process config for %s error %d\n",
1414                                obdname, rc);
1415
1416                 /* continue, even one with error */
1417         }
1418
1419         OBD_FREE(inst, PAGE_CACHE_SIZE);
1420         return rc;
1421 }
1422
1423 /**
1424  * This function is called if this client was notified for target restarting
1425  * by the MGS. A CONFIG_READ RPC is going to send to fetch recovery logs.
1426  */
1427 static int mgc_process_recover_log(struct obd_device *obd,
1428                                    struct config_llog_data *cld)
1429 {
1430         struct ptlrpc_request *req = NULL;
1431         struct config_llog_instance *cfg = &cld->cld_cfg;
1432         struct mgs_config_body *body;
1433         struct mgs_config_res  *res;
1434         struct ptlrpc_bulk_desc *desc;
1435         struct page **pages;
1436         int nrpages;
1437         bool eof = true;
1438         bool mne_swab = false;
1439         int i;
1440         int ealen;
1441         int rc;
1442
1443         /* allocate buffer for bulk transfer.
1444          * if this is the first time for this mgs to read logs,
1445          * CONFIG_READ_NRPAGES_INIT will be used since it will read all logs
1446          * once; otherwise, it only reads increment of logs, this should be
1447          * small and CONFIG_READ_NRPAGES will be used.
1448          */
1449         nrpages = CONFIG_READ_NRPAGES;
1450         if (cfg->cfg_last_idx == 0) /* the first time */
1451                 nrpages = CONFIG_READ_NRPAGES_INIT;
1452
1453         OBD_ALLOC(pages, sizeof(*pages) * nrpages);
1454         if (pages == NULL)
1455                 GOTO(out, rc = -ENOMEM);
1456
1457         for (i = 0; i < nrpages; i++) {
1458                 pages[i] = alloc_page(GFP_IOFS);
1459                 if (pages[i] == NULL)
1460                         GOTO(out, rc = -ENOMEM);
1461         }
1462
1463 again:
1464         LASSERT(cld_is_recover(cld));
1465         LASSERT(mutex_is_locked(&cld->cld_lock));
1466         req = ptlrpc_request_alloc(class_exp2cliimp(cld->cld_mgcexp),
1467                                    &RQF_MGS_CONFIG_READ);
1468         if (req == NULL)
1469                 GOTO(out, rc = -ENOMEM);
1470
1471         rc = ptlrpc_request_pack(req, LUSTRE_MGS_VERSION, MGS_CONFIG_READ);
1472         if (rc)
1473                 GOTO(out, rc);
1474
1475         /* pack request */
1476         body = req_capsule_client_get(&req->rq_pill, &RMF_MGS_CONFIG_BODY);
1477         LASSERT(body != NULL);
1478         LASSERT(sizeof(body->mcb_name) > strlen(cld->cld_logname));
1479         if (strlcpy(body->mcb_name, cld->cld_logname, sizeof(body->mcb_name))
1480             >= sizeof(body->mcb_name))
1481                 GOTO(out, rc = -E2BIG);
1482         body->mcb_offset = cfg->cfg_last_idx + 1;
1483         body->mcb_type   = cld->cld_type;
1484         body->mcb_bits   = PAGE_CACHE_SHIFT;
1485         body->mcb_units  = nrpages;
1486
1487         /* allocate bulk transfer descriptor */
1488         desc = ptlrpc_prep_bulk_imp(req, nrpages, 1, BULK_PUT_SINK,
1489                                     MGS_BULK_PORTAL);
1490         if (desc == NULL)
1491                 GOTO(out, rc = -ENOMEM);
1492
1493         for (i = 0; i < nrpages; i++)
1494                 ptlrpc_prep_bulk_page_pin(desc, pages[i], 0, PAGE_CACHE_SIZE);
1495
1496         ptlrpc_request_set_replen(req);
1497         rc = ptlrpc_queue_wait(req);
1498         if (rc)
1499                 GOTO(out, rc);
1500
1501         res = req_capsule_server_get(&req->rq_pill, &RMF_MGS_CONFIG_RES);
1502         if (res->mcr_size < res->mcr_offset)
1503                 GOTO(out, rc = -EINVAL);
1504
1505         /* always update the index even though it might have errors with
1506          * handling the recover logs */
1507         cfg->cfg_last_idx = res->mcr_offset;
1508         eof = res->mcr_offset == res->mcr_size;
1509
1510         CDEBUG(D_INFO, "Latest version "LPD64", more %d.\n",
1511                res->mcr_offset, eof == false);
1512
1513         ealen = sptlrpc_cli_unwrap_bulk_read(req, req->rq_bulk, 0);
1514         if (ealen < 0)
1515                 GOTO(out, rc = ealen);
1516
1517         if (ealen > nrpages << PAGE_CACHE_SHIFT)
1518                 GOTO(out, rc = -EINVAL);
1519
1520         if (ealen == 0) { /* no logs transferred */
1521                 if (!eof)
1522                         rc = -EINVAL;
1523                 GOTO(out, rc);
1524         }
1525
1526         mne_swab = !!ptlrpc_rep_need_swab(req);
1527 #if LUSTRE_VERSION_CODE < OBD_OCD_VERSION(3, 2, 50, 0)
1528         /* This import flag means the server did an extra swab of IR MNE
1529          * records (fixed in LU-1252), reverse it here if needed. LU-1644 */
1530         if (unlikely(req->rq_import->imp_need_mne_swab))
1531                 mne_swab = !mne_swab;
1532 #else
1533 #warning "LU-1644: Remove old OBD_CONNECT_MNE_SWAB fixup and imp_need_mne_swab"
1534 #endif
1535
1536         for (i = 0; i < nrpages && ealen > 0; i++) {
1537                 int rc2;
1538                 void *ptr;
1539
1540                 ptr = kmap(pages[i]);
1541                 rc2 = mgc_apply_recover_logs(obd, cld, res->mcr_offset, ptr,
1542                                              min_t(int, ealen, PAGE_CACHE_SIZE),
1543                                              mne_swab);
1544                 kunmap(pages[i]);
1545                 if (rc2 < 0) {
1546                         CWARN("Process recover log %s error %d\n",
1547                               cld->cld_logname, rc2);
1548                         break;
1549                 }
1550
1551                 ealen -= PAGE_CACHE_SIZE;
1552         }
1553
1554 out:
1555         if (req)
1556                 ptlrpc_req_finished(req);
1557
1558         if (rc == 0 && !eof)
1559                 goto again;
1560
1561         if (pages) {
1562                 for (i = 0; i < nrpages; i++) {
1563                         if (pages[i] == NULL)
1564                                 break;
1565                         __free_page(pages[i]);
1566                 }
1567                 OBD_FREE(pages, sizeof(*pages) * nrpages);
1568         }
1569         return rc;
1570 }
1571
1572 static int mgc_llog_local_copy(const struct lu_env *env,
1573                                struct obd_device *obd,
1574                                struct llog_ctxt *rctxt,
1575                                struct llog_ctxt *lctxt, char *logname)
1576 {
1577         char    *temp_log;
1578         int      rc;
1579
1580
1581
1582         /*
1583          * - copy it to backup using llog_backup()
1584          * - copy remote llog to logname using llog_backup()
1585          * - if failed then move bakup to logname again
1586          */
1587
1588         OBD_ALLOC(temp_log, strlen(logname) + 1);
1589         if (!temp_log)
1590                 return -ENOMEM;
1591         sprintf(temp_log, "%sT", logname);
1592
1593         /* make a copy of local llog at first */
1594         rc = llog_backup(env, obd, lctxt, lctxt, logname, temp_log);
1595         if (rc < 0 && rc != -ENOENT)
1596                 GOTO(out, rc);
1597         /* copy remote llog to the local copy */
1598         rc = llog_backup(env, obd, rctxt, lctxt, logname, logname);
1599         if (rc == -ENOENT) {
1600                 /* no remote llog, delete local one too */
1601                 llog_erase(env, lctxt, NULL, logname);
1602         } else if (rc < 0) {
1603                 /* error during backup, get local one back from the copy */
1604                 llog_backup(env, obd, lctxt, lctxt, temp_log, logname);
1605 out:
1606                 CERROR("%s: failed to copy remote log %s: rc = %d\n",
1607                        obd->obd_name, logname, rc);
1608         }
1609         llog_erase(env, lctxt, NULL, temp_log);
1610         OBD_FREE(temp_log, strlen(logname) + 1);
1611         return rc;
1612 }
1613
1614 /* local_only means it cannot get remote llogs */
1615 static int mgc_process_cfg_log(struct obd_device *mgc,
1616                                struct config_llog_data *cld, int local_only)
1617 {
1618         struct llog_ctxt        *ctxt, *lctxt = NULL;
1619         struct dt_object        *cl_mgc_dir = mgc->u.cli.cl_mgc_configs_dir;
1620         struct lustre_sb_info   *lsi = NULL;
1621         int                      rc = 0;
1622         bool                     sptlrpc_started = false;
1623         struct lu_env           *env;
1624
1625         LASSERT(cld);
1626         LASSERT(mutex_is_locked(&cld->cld_lock));
1627
1628         /*
1629          * local copy of sptlrpc log is controlled elsewhere, don't try to
1630          * read it up here.
1631          */
1632         if (cld_is_sptlrpc(cld) && local_only)
1633                 return 0;
1634
1635         if (cld->cld_cfg.cfg_sb)
1636                 lsi = s2lsi(cld->cld_cfg.cfg_sb);
1637
1638         OBD_ALLOC_PTR(env);
1639         if (env == NULL)
1640                 return -ENOMEM;
1641
1642         rc = lu_env_init(env, LCT_MG_THREAD);
1643         if (rc)
1644                 GOTO(out_free, rc);
1645
1646         ctxt = llog_get_context(mgc, LLOG_CONFIG_REPL_CTXT);
1647         LASSERT(ctxt);
1648
1649         lctxt = llog_get_context(mgc, LLOG_CONFIG_ORIG_CTXT);
1650
1651         /* Copy the setup log locally if we can. Don't mess around if we're
1652          * running an MGS though (logs are already local). */
1653         if (lctxt && lsi && IS_SERVER(lsi) && !IS_MGS(lsi) &&
1654             cl_mgc_dir != NULL &&
1655             lu2dt_dev(cl_mgc_dir->do_lu.lo_dev) == lsi->lsi_dt_dev) {
1656                 if (!local_only)
1657                         /* Only try to copy log if we have the lock. */
1658                         rc = mgc_llog_local_copy(env, mgc, ctxt, lctxt,
1659                                                  cld->cld_logname);
1660                 if (local_only || rc) {
1661                         if (llog_is_empty(env, lctxt, cld->cld_logname)) {
1662                                 LCONSOLE_ERROR_MSG(0x13a,
1663                                                    "Failed to get MGS log %s and no local copy.\n",
1664                                                    cld->cld_logname);
1665                                 GOTO(out_pop, rc = -ENOTCONN);
1666                         }
1667                         CDEBUG(D_MGC,
1668                                "Failed to get MGS log %s, using local copy for now, will try to update later.\n",
1669                                cld->cld_logname);
1670                 }
1671                 /* Now, whether we copied or not, start using the local llog.
1672                  * If we failed to copy, we'll start using whatever the old
1673                  * log has. */
1674                 llog_ctxt_put(ctxt);
1675                 ctxt = lctxt;
1676                 lctxt = NULL;
1677         } else {
1678                 if (local_only) /* no local log at client side */
1679                         GOTO(out_pop, rc = -EIO);
1680         }
1681
1682         if (cld_is_sptlrpc(cld)) {
1683                 sptlrpc_conf_log_update_begin(cld->cld_logname);
1684                 sptlrpc_started = true;
1685         }
1686
1687         /* logname and instance info should be the same, so use our
1688          * copy of the instance for the update.  The cfg_last_idx will
1689          * be updated here. */
1690         rc = class_config_parse_llog(env, ctxt, cld->cld_logname,
1691                                      &cld->cld_cfg);
1692
1693 out_pop:
1694         __llog_ctxt_put(env, ctxt);
1695         if (lctxt)
1696                 __llog_ctxt_put(env, lctxt);
1697
1698         /*
1699          * update settings on existing OBDs. doing it inside
1700          * of llog_process_lock so no device is attaching/detaching
1701          * in parallel.
1702          * the logname must be <fsname>-sptlrpc
1703          */
1704         if (sptlrpc_started) {
1705                 LASSERT(cld_is_sptlrpc(cld));
1706                 sptlrpc_conf_log_update_end(cld->cld_logname);
1707                 class_notify_sptlrpc_conf(cld->cld_logname,
1708                                           strlen(cld->cld_logname) -
1709                                           strlen("-sptlrpc"));
1710         }
1711
1712         lu_env_fini(env);
1713 out_free:
1714         OBD_FREE_PTR(env);
1715         return rc;
1716 }
1717
1718 /** Get a config log from the MGS and process it.
1719  * This func is called for both clients and servers.
1720  * Copy the log locally before parsing it if appropriate (non-MGS server)
1721  */
1722 int mgc_process_log(struct obd_device *mgc, struct config_llog_data *cld)
1723 {
1724         struct lustre_handle lockh = { 0 };
1725         __u64 flags = LDLM_FL_NO_LRU;
1726         int rc = 0, rcl;
1727
1728         LASSERT(cld);
1729
1730         /* I don't want multiple processes running process_log at once --
1731            sounds like badness.  It actually might be fine, as long as
1732            we're not trying to update from the same log
1733            simultaneously (in which case we should use a per-log sem.) */
1734         mutex_lock(&cld->cld_lock);
1735         if (cld->cld_stopping) {
1736                 mutex_unlock(&cld->cld_lock);
1737                 return 0;
1738         }
1739
1740         OBD_FAIL_TIMEOUT(OBD_FAIL_MGC_PAUSE_PROCESS_LOG, 20);
1741
1742         CDEBUG(D_MGC, "Process log %s:%p from %d\n", cld->cld_logname,
1743                cld->cld_cfg.cfg_instance, cld->cld_cfg.cfg_last_idx + 1);
1744
1745         /* Get the cfg lock on the llog */
1746         rcl = mgc_enqueue(mgc->u.cli.cl_mgc_mgsexp, NULL, LDLM_PLAIN, NULL,
1747                           LCK_CR, &flags, NULL, NULL, NULL,
1748                           cld, 0, NULL, &lockh);
1749         if (rcl == 0) {
1750                 /* Get the cld, it will be released in mgc_blocking_ast. */
1751                 config_log_get(cld);
1752                 rc = ldlm_lock_set_data(&lockh, (void *)cld);
1753                 LASSERT(rc == 0);
1754         } else {
1755                 CDEBUG(D_MGC, "Can't get cfg lock: %d\n", rcl);
1756
1757                 /* mark cld_lostlock so that it will requeue
1758                  * after MGC becomes available. */
1759                 cld->cld_lostlock = 1;
1760                 /* Get extra reference, it will be put in requeue thread */
1761                 config_log_get(cld);
1762         }
1763
1764
1765         if (cld_is_recover(cld)) {
1766                 rc = 0; /* this is not a fatal error for recover log */
1767                 if (rcl == 0)
1768                         rc = mgc_process_recover_log(mgc, cld);
1769         } else {
1770                 rc = mgc_process_cfg_log(mgc, cld, rcl != 0);
1771         }
1772
1773         CDEBUG(D_MGC, "%s: configuration from log '%s' %sed (%d).\n",
1774                mgc->obd_name, cld->cld_logname, rc ? "fail" : "succeed", rc);
1775
1776         mutex_unlock(&cld->cld_lock);
1777
1778         /* Now drop the lock so MGS can revoke it */
1779         if (!rcl) {
1780                 rcl = mgc_cancel(mgc->u.cli.cl_mgc_mgsexp, NULL,
1781                                  LCK_CR, &lockh);
1782                 if (rcl)
1783                         CERROR("Can't drop cfg lock: %d\n", rcl);
1784         }
1785
1786         return rc;
1787 }
1788
1789
1790 /** Called from lustre_process_log.
1791  * LCFG_LOG_START gets the config log from the MGS, processes it to start
1792  * any services, and adds it to the list logs to watch (follow).
1793  */
1794 static int mgc_process_config(struct obd_device *obd, obd_count len, void *buf)
1795 {
1796         struct lustre_cfg *lcfg = buf;
1797         struct config_llog_instance *cfg = NULL;
1798         char *logname;
1799         int rc = 0;
1800
1801         switch(lcfg->lcfg_command) {
1802         case LCFG_LOV_ADD_OBD: {
1803                 /* Overloading this cfg command: register a new target */
1804                 struct mgs_target_info *mti;
1805
1806                 if (LUSTRE_CFG_BUFLEN(lcfg, 1) !=
1807                     sizeof(struct mgs_target_info))
1808                         GOTO(out, rc = -EINVAL);
1809
1810                 mti = (struct mgs_target_info *)lustre_cfg_buf(lcfg, 1);
1811                 CDEBUG(D_MGC, "add_target %s %#x\n",
1812                        mti->mti_svname, mti->mti_flags);
1813                 rc = mgc_target_register(obd->u.cli.cl_mgc_mgsexp, mti);
1814                 break;
1815         }
1816         case LCFG_LOV_DEL_OBD:
1817                 /* Unregister has no meaning at the moment. */
1818                 CERROR("lov_del_obd unimplemented\n");
1819                 rc = -ENOSYS;
1820                 break;
1821         case LCFG_SPTLRPC_CONF: {
1822                 rc = sptlrpc_process_config(lcfg);
1823                 break;
1824         }
1825         case LCFG_LOG_START: {
1826                 struct config_llog_data *cld;
1827                 struct super_block *sb;
1828
1829                 logname = lustre_cfg_string(lcfg, 1);
1830                 cfg = (struct config_llog_instance *)lustre_cfg_buf(lcfg, 2);
1831                 sb = *(struct super_block **)lustre_cfg_buf(lcfg, 3);
1832
1833                 CDEBUG(D_MGC, "parse_log %s from %d\n", logname,
1834                        cfg->cfg_last_idx);
1835
1836                 /* We're only called through here on the initial mount */
1837                 rc = config_log_add(obd, logname, cfg, sb);
1838                 if (rc)
1839                         break;
1840                 cld = config_log_find(logname, cfg);
1841                 if (cld == NULL) {
1842                         rc = -ENOENT;
1843                         break;
1844                 }
1845
1846                 /* COMPAT_146 */
1847                 /* FIXME only set this for old logs!  Right now this forces
1848                    us to always skip the "inside markers" check */
1849                 cld->cld_cfg.cfg_flags |= CFG_F_COMPAT146;
1850
1851                 rc = mgc_process_log(obd, cld);
1852                 if (rc == 0 && cld->cld_recover != NULL) {
1853                         if (OCD_HAS_FLAG(&obd->u.cli.cl_import->
1854                                          imp_connect_data, IMP_RECOV)) {
1855                                 rc = mgc_process_log(obd, cld->cld_recover);
1856                         } else {
1857                                 struct config_llog_data *cir = cld->cld_recover;
1858                                 cld->cld_recover = NULL;
1859                                 config_log_put(cir);
1860                         }
1861                         if (rc)
1862                                 CERROR("Cannot process recover llog %d\n", rc);
1863                 }
1864                 config_log_put(cld);
1865
1866                 break;
1867         }
1868         case LCFG_LOG_END: {
1869                 logname = lustre_cfg_string(lcfg, 1);
1870
1871                 if (lcfg->lcfg_bufcount >= 2)
1872                         cfg = (struct config_llog_instance *)lustre_cfg_buf(
1873                                 lcfg, 2);
1874                 rc = config_log_end(logname, cfg);
1875                 break;
1876         }
1877         default: {
1878                 CERROR("Unknown command: %d\n", lcfg->lcfg_command);
1879                 GOTO(out, rc = -EINVAL);
1880
1881         }
1882         }
1883 out:
1884         return rc;
1885 }
1886
1887 struct obd_ops mgc_obd_ops = {
1888         .o_owner        = THIS_MODULE,
1889         .o_setup        = mgc_setup,
1890         .o_precleanup   = mgc_precleanup,
1891         .o_cleanup      = mgc_cleanup,
1892         .o_add_conn     = client_import_add_conn,
1893         .o_del_conn     = client_import_del_conn,
1894         .o_connect      = client_connect_import,
1895         .o_disconnect   = client_disconnect_export,
1896         //.o_enqueue      = mgc_enqueue,
1897         .o_cancel       = mgc_cancel,
1898         //.o_iocontrol    = mgc_iocontrol,
1899         .o_set_info_async = mgc_set_info_async,
1900         .o_get_info       = mgc_get_info,
1901         .o_import_event = mgc_import_event,
1902         .o_process_config = mgc_process_config,
1903 };
1904
1905 int __init mgc_init(void)
1906 {
1907         return class_register_type(&mgc_obd_ops, NULL, NULL,
1908                                    LUSTRE_MGC_NAME, NULL);
1909 }
1910
1911 static void /*__exit*/ mgc_exit(void)
1912 {
1913         class_unregister_type(LUSTRE_MGC_NAME);
1914 }
1915
1916 MODULE_AUTHOR("Sun Microsystems, Inc. <http://www.lustre.org/>");
1917 MODULE_DESCRIPTION("Lustre Management Client");
1918 MODULE_LICENSE("GPL");
1919
1920 module_init(mgc_init);
1921 module_exit(mgc_exit);