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