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