4 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
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.
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).
16 * You should have received a copy of the GNU General Public License
17 * version 2 along with this program; If not, see
18 * http://www.sun.com/software/products/lustre/docs/GPLv2.pdf
20 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
21 * CA 95054 USA or visit www.sun.com if you need additional information or
27 * Copyright (c) 2007, 2010, Oracle and/or its affiliates. All rights reserved.
28 * Use is subject to license terms.
30 * Copyright (c) 2011, 2012, Intel Corporation.
33 * This file is part of Lustre, http://www.lustre.org/
34 * Lustre is a trademark of Sun Microsystems, Inc.
36 * lustre/mgc/mgc_request.c
38 * Author: Nathan Rutman <nathan@clusterfs.com>
41 #define DEBUG_SUBSYSTEM S_MGC
42 #define D_MGC D_CONFIG /*|D_WARNING*/
44 #include <linux/module.h>
45 #include "../include/obd_class.h"
46 #include "../include/lustre_dlm.h"
47 #include "../include/lprocfs_status.h"
48 #include "../include/lustre_log.h"
49 #include "../include/lustre_disk.h"
51 #include "mgc_internal.h"
53 static int mgc_name2resid(char *name
, int len
, struct ldlm_res_id
*res_id
,
58 if (len
> sizeof(resname
)) {
59 CERROR("name too long: %s\n", name
);
63 CERROR("missing name: %s\n", name
);
66 memcpy(&resname
, name
, len
);
68 /* Always use the same endianness for the resid */
69 memset(res_id
, 0, sizeof(*res_id
));
70 res_id
->name
[0] = cpu_to_le64(resname
);
71 /* XXX: unfortunately, sptlprc and config llog share one lock */
74 case CONFIG_T_SPTLRPC
:
77 case CONFIG_T_RECOVER
:
84 res_id
->name
[1] = cpu_to_le64(resname
);
85 CDEBUG(D_MGC
, "log %s to resid %#llx/%#llx (%.8s)\n", name
,
86 res_id
->name
[0], res_id
->name
[1], (char *)&res_id
->name
[0]);
90 int mgc_fsname2resid(char *fsname
, struct ldlm_res_id
*res_id
, int type
)
92 /* fsname is at most 8 chars long, maybe contain "-".
93 * e.g. "lustre", "SUN-000" */
94 return mgc_name2resid(fsname
, strlen(fsname
), res_id
, type
);
96 EXPORT_SYMBOL(mgc_fsname2resid
);
98 static int mgc_logname2resid(char *logname
, struct ldlm_res_id
*res_id
, int type
)
103 /* logname consists of "fsname-nodetype".
104 * e.g. "lustre-MDT0001", "SUN-000-client"
105 * there is an exception: llog "params" */
106 name_end
= strrchr(logname
, '-');
108 len
= strlen(logname
);
110 len
= name_end
- logname
;
111 return mgc_name2resid(logname
, len
, res_id
, type
);
114 /********************** config llog list **********************/
115 static LIST_HEAD(config_llog_list
);
116 static DEFINE_SPINLOCK(config_list_lock
);
118 /* Take a reference to a config log */
119 static int config_log_get(struct config_llog_data
*cld
)
121 atomic_inc(&cld
->cld_refcount
);
122 CDEBUG(D_INFO
, "log %s refs %d\n", cld
->cld_logname
,
123 atomic_read(&cld
->cld_refcount
));
127 /* Drop a reference to a config log. When no longer referenced,
128 we can free the config log data */
129 static void config_log_put(struct config_llog_data
*cld
)
131 CDEBUG(D_INFO
, "log %s refs %d\n", cld
->cld_logname
,
132 atomic_read(&cld
->cld_refcount
));
133 LASSERT(atomic_read(&cld
->cld_refcount
) > 0);
135 /* spinlock to make sure no item with 0 refcount in the list */
136 if (atomic_dec_and_lock(&cld
->cld_refcount
, &config_list_lock
)) {
137 list_del(&cld
->cld_list_chain
);
138 spin_unlock(&config_list_lock
);
140 CDEBUG(D_MGC
, "dropping config log %s\n", cld
->cld_logname
);
142 if (cld
->cld_recover
)
143 config_log_put(cld
->cld_recover
);
144 if (cld
->cld_sptlrpc
)
145 config_log_put(cld
->cld_sptlrpc
);
147 config_log_put(cld
->cld_params
);
148 if (cld_is_sptlrpc(cld
))
149 sptlrpc_conf_log_stop(cld
->cld_logname
);
151 class_export_put(cld
->cld_mgcexp
);
156 /* Find a config log by name */
158 struct config_llog_data
*config_log_find(char *logname
,
159 struct config_llog_instance
*cfg
)
161 struct config_llog_data
*cld
;
162 struct config_llog_data
*found
= NULL
;
165 LASSERT(logname
!= NULL
);
167 instance
= cfg
? cfg
->cfg_instance
: NULL
;
168 spin_lock(&config_list_lock
);
169 list_for_each_entry(cld
, &config_llog_list
, cld_list_chain
) {
170 /* check if instance equals */
171 if (instance
!= cld
->cld_cfg
.cfg_instance
)
174 /* instance may be NULL, should check name */
175 if (strcmp(logname
, cld
->cld_logname
) == 0) {
181 atomic_inc(&found
->cld_refcount
);
182 LASSERT(found
->cld_stopping
== 0 || cld_is_sptlrpc(found
) == 0);
184 spin_unlock(&config_list_lock
);
189 struct config_llog_data
*do_config_log_add(struct obd_device
*obd
,
192 struct config_llog_instance
*cfg
,
193 struct super_block
*sb
)
195 struct config_llog_data
*cld
;
198 CDEBUG(D_MGC
, "do adding config log %s:%p\n", logname
,
199 cfg
? cfg
->cfg_instance
: NULL
);
201 cld
= kzalloc(sizeof(*cld
) + strlen(logname
) + 1, GFP_NOFS
);
203 return ERR_PTR(-ENOMEM
);
205 strcpy(cld
->cld_logname
, logname
);
209 cld
->cld_cfg
.cfg_callback
= class_config_llog_handler
;
210 mutex_init(&cld
->cld_lock
);
211 cld
->cld_cfg
.cfg_last_idx
= 0;
212 cld
->cld_cfg
.cfg_flags
= 0;
213 cld
->cld_cfg
.cfg_sb
= sb
;
214 cld
->cld_type
= type
;
215 atomic_set(&cld
->cld_refcount
, 1);
217 /* Keep the mgc around until we are done */
218 cld
->cld_mgcexp
= class_export_get(obd
->obd_self_export
);
220 if (cld_is_sptlrpc(cld
)) {
221 sptlrpc_conf_log_start(logname
);
222 cld
->cld_cfg
.cfg_obdname
= obd
->obd_name
;
225 rc
= mgc_logname2resid(logname
, &cld
->cld_resid
, type
);
227 spin_lock(&config_list_lock
);
228 list_add(&cld
->cld_list_chain
, &config_llog_list
);
229 spin_unlock(&config_list_lock
);
236 if (cld_is_sptlrpc(cld
)) {
237 rc
= mgc_process_log(obd
, cld
);
238 if (rc
&& rc
!= -ENOENT
)
239 CERROR("failed processing sptlrpc log: %d\n", rc
);
245 static struct config_llog_data
*config_recover_log_add(struct obd_device
*obd
,
247 struct config_llog_instance
*cfg
,
248 struct super_block
*sb
)
250 struct config_llog_instance lcfg
= *cfg
;
251 struct lustre_sb_info
*lsi
= s2lsi(sb
);
252 struct config_llog_data
*cld
;
258 /* for osp-on-ost, see lustre_start_osp() */
259 if (IS_MDT(lsi
) && lcfg
.cfg_instance
)
262 /* we have to use different llog for clients and mdts for cmd
263 * where only clients are notified if one of cmd server restarts */
264 LASSERT(strlen(fsname
) < sizeof(logname
) / 2);
265 strcpy(logname
, fsname
);
266 LASSERT(lcfg
.cfg_instance
);
267 strcat(logname
, "-cliir");
269 cld
= do_config_log_add(obd
, logname
, CONFIG_T_RECOVER
, &lcfg
, sb
);
273 static struct config_llog_data
*config_params_log_add(struct obd_device
*obd
,
274 struct config_llog_instance
*cfg
, struct super_block
*sb
)
276 struct config_llog_instance lcfg
= *cfg
;
277 struct config_llog_data
*cld
;
279 lcfg
.cfg_instance
= sb
;
281 cld
= do_config_log_add(obd
, PARAMS_FILENAME
, CONFIG_T_PARAMS
,
287 /** Add this log to the list of active logs watched by an MGC.
288 * Active means we're watching for updates.
289 * We have one active log per "mount" - client instance or servername.
290 * Each instance may be at a different point in the log.
292 static int config_log_add(struct obd_device
*obd
, char *logname
,
293 struct config_llog_instance
*cfg
,
294 struct super_block
*sb
)
296 struct lustre_sb_info
*lsi
= s2lsi(sb
);
297 struct config_llog_data
*cld
;
298 struct config_llog_data
*sptlrpc_cld
;
299 struct config_llog_data
*params_cld
;
304 CDEBUG(D_MGC
, "adding config log %s:%p\n", logname
, cfg
->cfg_instance
);
307 * for each regular log, the depended sptlrpc log name is
308 * <fsname>-sptlrpc. multiple regular logs may share one sptlrpc log.
310 ptr
= strrchr(logname
, '-');
311 if (ptr
== NULL
|| ptr
- logname
> 8) {
312 CERROR("logname %s is too long\n", logname
);
316 memcpy(seclogname
, logname
, ptr
- logname
);
317 strcpy(seclogname
+ (ptr
- logname
), "-sptlrpc");
319 sptlrpc_cld
= config_log_find(seclogname
, NULL
);
320 if (sptlrpc_cld
== NULL
) {
321 sptlrpc_cld
= do_config_log_add(obd
, seclogname
,
322 CONFIG_T_SPTLRPC
, NULL
, NULL
);
323 if (IS_ERR(sptlrpc_cld
)) {
324 CERROR("can't create sptlrpc log: %s\n", seclogname
);
325 rc
= PTR_ERR(sptlrpc_cld
);
329 params_cld
= config_params_log_add(obd
, cfg
, sb
);
330 if (IS_ERR(params_cld
)) {
331 rc
= PTR_ERR(params_cld
);
332 CERROR("%s: can't create params log: rc = %d\n",
337 cld
= do_config_log_add(obd
, logname
, CONFIG_T_CONFIG
, cfg
, sb
);
339 CERROR("can't create log: %s\n", logname
);
344 cld
->cld_sptlrpc
= sptlrpc_cld
;
345 cld
->cld_params
= params_cld
;
347 LASSERT(lsi
->lsi_lmd
);
348 if (!(lsi
->lsi_lmd
->lmd_flags
& LMD_FLG_NOIR
)) {
349 struct config_llog_data
*recover_cld
;
350 *strrchr(seclogname
, '-') = 0;
351 recover_cld
= config_recover_log_add(obd
, seclogname
, cfg
, sb
);
352 if (IS_ERR(recover_cld
)) {
353 rc
= PTR_ERR(recover_cld
);
356 cld
->cld_recover
= recover_cld
;
365 config_log_put(params_cld
);
368 config_log_put(sptlrpc_cld
);
374 DEFINE_MUTEX(llog_process_lock
);
376 /** Stop watching for updates on this log.
378 static int config_log_end(char *logname
, struct config_llog_instance
*cfg
)
380 struct config_llog_data
*cld
;
381 struct config_llog_data
*cld_sptlrpc
= NULL
;
382 struct config_llog_data
*cld_params
= NULL
;
383 struct config_llog_data
*cld_recover
= NULL
;
386 cld
= config_log_find(logname
, cfg
);
390 mutex_lock(&cld
->cld_lock
);
392 * if cld_stopping is set, it means we didn't start the log thus
393 * not owning the start ref. this can happen after previous umount:
394 * the cld still hanging there waiting for lock cancel, and we
395 * remount again but failed in the middle and call log_end without
398 if (unlikely(cld
->cld_stopping
)) {
399 mutex_unlock(&cld
->cld_lock
);
400 /* drop the ref from the find */
405 cld
->cld_stopping
= 1;
407 cld_recover
= cld
->cld_recover
;
408 cld
->cld_recover
= NULL
;
409 mutex_unlock(&cld
->cld_lock
);
412 mutex_lock(&cld_recover
->cld_lock
);
413 cld_recover
->cld_stopping
= 1;
414 mutex_unlock(&cld_recover
->cld_lock
);
415 config_log_put(cld_recover
);
418 spin_lock(&config_list_lock
);
419 cld_sptlrpc
= cld
->cld_sptlrpc
;
420 cld
->cld_sptlrpc
= NULL
;
421 cld_params
= cld
->cld_params
;
422 cld
->cld_params
= NULL
;
423 spin_unlock(&config_list_lock
);
426 config_log_put(cld_sptlrpc
);
429 mutex_lock(&cld_params
->cld_lock
);
430 cld_params
->cld_stopping
= 1;
431 mutex_unlock(&cld_params
->cld_lock
);
432 config_log_put(cld_params
);
435 /* drop the ref from the find */
437 /* drop the start ref */
440 CDEBUG(D_MGC
, "end config log %s (%d)\n", logname
? logname
: "client",
445 int lprocfs_mgc_rd_ir_state(struct seq_file
*m
, void *data
)
447 struct obd_device
*obd
= data
;
448 struct obd_import
*imp
;
449 struct obd_connect_data
*ocd
;
450 struct config_llog_data
*cld
;
452 LPROCFS_CLIMP_CHECK(obd
);
453 imp
= obd
->u
.cli
.cl_import
;
454 ocd
= &imp
->imp_connect_data
;
456 seq_printf(m
, "imperative_recovery: %s\n",
457 OCD_HAS_FLAG(ocd
, IMP_RECOV
) ? "ENABLED" : "DISABLED");
458 seq_printf(m
, "client_state:\n");
460 spin_lock(&config_list_lock
);
461 list_for_each_entry(cld
, &config_llog_list
, cld_list_chain
) {
462 if (cld
->cld_recover
== NULL
)
464 seq_printf(m
, " - { client: %s, nidtbl_version: %u }\n",
466 cld
->cld_recover
->cld_cfg
.cfg_last_idx
);
468 spin_unlock(&config_list_lock
);
470 LPROCFS_CLIMP_EXIT(obd
);
474 /* reenqueue any lost locks */
475 #define RQ_RUNNING 0x1
479 #define RQ_PRECLEANUP 0x10
481 static wait_queue_head_t rq_waitq
;
482 static DECLARE_COMPLETION(rq_exit
);
483 static DECLARE_COMPLETION(rq_start
);
485 static void do_requeue(struct config_llog_data
*cld
)
487 LASSERT(atomic_read(&cld
->cld_refcount
) > 0);
489 /* Do not run mgc_process_log on a disconnected export or an
490 export which is being disconnected. Take the client
491 semaphore to make the check non-racy. */
492 down_read(&cld
->cld_mgcexp
->exp_obd
->u
.cli
.cl_sem
);
493 if (cld
->cld_mgcexp
->exp_obd
->u
.cli
.cl_conn_count
!= 0) {
494 CDEBUG(D_MGC
, "updating log %s\n", cld
->cld_logname
);
495 mgc_process_log(cld
->cld_mgcexp
->exp_obd
, cld
);
497 CDEBUG(D_MGC
, "disconnecting, won't update log %s\n",
500 up_read(&cld
->cld_mgcexp
->exp_obd
->u
.cli
.cl_sem
);
503 /* this timeout represents how many seconds MGC should wait before
504 * requeue config and recover lock to the MGS. We need to randomize this
505 * in order to not flood the MGS.
507 #define MGC_TIMEOUT_MIN_SECONDS 5
508 #define MGC_TIMEOUT_RAND_CENTISEC 0x1ff /* ~500 */
510 static int mgc_requeue_thread(void *data
)
514 CDEBUG(D_MGC
, "Starting requeue thread\n");
516 /* Keep trying failed locks periodically */
517 spin_lock(&config_list_lock
);
518 rq_state
|= RQ_RUNNING
;
520 struct l_wait_info lwi
;
521 struct config_llog_data
*cld
, *cld_prev
;
522 int rand
= cfs_rand() & MGC_TIMEOUT_RAND_CENTISEC
;
523 int stopped
= !!(rq_state
& RQ_STOP
);
526 /* Any new or requeued lostlocks will change the state */
527 rq_state
&= ~(RQ_NOW
| RQ_LATER
);
528 spin_unlock(&config_list_lock
);
535 /* Always wait a few seconds to allow the server who
536 caused the lock revocation to finish its setup, plus some
537 random so everyone doesn't try to reconnect at once. */
538 to
= MGC_TIMEOUT_MIN_SECONDS
* HZ
;
539 to
+= rand
* HZ
/ 100; /* rand is centi-seconds */
540 lwi
= LWI_TIMEOUT(to
, NULL
, NULL
);
541 l_wait_event(rq_waitq
, rq_state
& (RQ_STOP
| RQ_PRECLEANUP
),
545 * iterate & processing through the list. for each cld, process
546 * its depending sptlrpc cld firstly (if any) and then itself.
548 * it's guaranteed any item in the list must have
549 * reference > 0; and if cld_lostlock is set, at
550 * least one reference is taken by the previous enqueue.
554 spin_lock(&config_list_lock
);
555 rq_state
&= ~RQ_PRECLEANUP
;
556 list_for_each_entry(cld
, &config_llog_list
,
558 if (!cld
->cld_lostlock
)
561 spin_unlock(&config_list_lock
);
563 LASSERT(atomic_read(&cld
->cld_refcount
) > 0);
565 /* Whether we enqueued again or not in mgc_process_log,
566 * we're done with the ref from the old enqueue */
568 config_log_put(cld_prev
);
571 cld
->cld_lostlock
= 0;
572 if (likely(!stopped
))
575 spin_lock(&config_list_lock
);
577 spin_unlock(&config_list_lock
);
579 config_log_put(cld_prev
);
581 /* break after scanning the list so that we can drop
582 * refcount to losing lock clds */
583 if (unlikely(stopped
)) {
584 spin_lock(&config_list_lock
);
588 /* Wait a bit to see if anyone else needs a requeue */
589 lwi
= (struct l_wait_info
) { 0 };
590 l_wait_event(rq_waitq
, rq_state
& (RQ_NOW
| RQ_STOP
),
592 spin_lock(&config_list_lock
);
594 /* spinlock and while guarantee RQ_NOW and RQ_LATER are not set */
595 rq_state
&= ~RQ_RUNNING
;
596 spin_unlock(&config_list_lock
);
600 CDEBUG(D_MGC
, "Ending requeue thread\n");
604 /* Add a cld to the list to requeue. Start the requeue thread if needed.
605 We are responsible for dropping the config log reference from here on out. */
606 static void mgc_requeue_add(struct config_llog_data
*cld
)
608 CDEBUG(D_INFO
, "log %s: requeue (r=%d sp=%d st=%x)\n",
609 cld
->cld_logname
, atomic_read(&cld
->cld_refcount
),
610 cld
->cld_stopping
, rq_state
);
611 LASSERT(atomic_read(&cld
->cld_refcount
) > 0);
613 mutex_lock(&cld
->cld_lock
);
614 if (cld
->cld_stopping
|| cld
->cld_lostlock
) {
615 mutex_unlock(&cld
->cld_lock
);
618 /* this refcount will be released in mgc_requeue_thread. */
620 cld
->cld_lostlock
= 1;
621 mutex_unlock(&cld
->cld_lock
);
623 /* Hold lock for rq_state */
624 spin_lock(&config_list_lock
);
625 if (rq_state
& RQ_STOP
) {
626 spin_unlock(&config_list_lock
);
627 cld
->cld_lostlock
= 0;
631 spin_unlock(&config_list_lock
);
636 static int mgc_llog_init(const struct lu_env
*env
, struct obd_device
*obd
)
638 struct llog_ctxt
*ctxt
;
641 /* setup only remote ctxt, the local disk context is switched per each
642 * filesystem during mgc_fs_setup() */
643 rc
= llog_setup(env
, obd
, &obd
->obd_olg
, LLOG_CONFIG_REPL_CTXT
, obd
,
648 ctxt
= llog_get_context(obd
, LLOG_CONFIG_REPL_CTXT
);
651 llog_initiator_connect(ctxt
);
657 static int mgc_llog_fini(const struct lu_env
*env
, struct obd_device
*obd
)
659 struct llog_ctxt
*ctxt
;
661 ctxt
= llog_get_context(obd
, LLOG_CONFIG_REPL_CTXT
);
663 llog_cleanup(env
, ctxt
);
668 static atomic_t mgc_count
= ATOMIC_INIT(0);
669 static int mgc_precleanup(struct obd_device
*obd
, enum obd_cleanup_stage stage
)
675 case OBD_CLEANUP_EARLY
:
677 case OBD_CLEANUP_EXPORTS
:
678 if (atomic_dec_and_test(&mgc_count
)) {
679 LASSERT(rq_state
& RQ_RUNNING
);
680 /* stop requeue thread */
683 /* wakeup requeue thread to clean our cld */
684 temp
= RQ_NOW
| RQ_PRECLEANUP
;
686 spin_lock(&config_list_lock
);
688 spin_unlock(&config_list_lock
);
691 wait_for_completion(&rq_exit
);
692 obd_cleanup_client_import(obd
);
693 rc
= mgc_llog_fini(NULL
, obd
);
695 CERROR("failed to cleanup llogging subsystems\n");
701 static int mgc_cleanup(struct obd_device
*obd
)
703 /* COMPAT_146 - old config logs may have added profiles we don't
705 if (obd
->obd_type
->typ_refcnt
<= 1)
706 /* Only for the last mgc */
707 class_del_profiles();
709 lprocfs_obd_cleanup(obd
);
712 return client_obd_cleanup(obd
);
715 static int mgc_setup(struct obd_device
*obd
, struct lustre_cfg
*lcfg
)
717 struct lprocfs_static_vars lvars
= { NULL
};
722 rc
= client_obd_setup(obd
, lcfg
);
726 rc
= mgc_llog_init(NULL
, obd
);
728 CERROR("failed to setup llogging subsystems\n");
732 lprocfs_mgc_init_vars(&lvars
);
733 lprocfs_obd_setup(obd
, lvars
.obd_vars
, lvars
.sysfs_vars
);
734 sptlrpc_lprocfs_cliobd_attach(obd
);
736 if (atomic_inc_return(&mgc_count
) == 1) {
738 init_waitqueue_head(&rq_waitq
);
740 /* start requeue thread */
741 rc
= PTR_ERR(kthread_run(mgc_requeue_thread
, NULL
,
743 if (IS_ERR_VALUE(rc
)) {
744 CERROR("%s: Cannot start requeue thread (%d),no more log updates!\n",
748 /* rc is the task_struct pointer of mgc_requeue_thread. */
750 wait_for_completion(&rq_start
);
756 client_obd_cleanup(obd
);
762 /* based on ll_mdc_blocking_ast */
763 static int mgc_blocking_ast(struct ldlm_lock
*lock
, struct ldlm_lock_desc
*desc
,
764 void *data
, int flag
)
766 struct lustre_handle lockh
;
767 struct config_llog_data
*cld
= (struct config_llog_data
*)data
;
771 case LDLM_CB_BLOCKING
:
772 /* mgs wants the lock, give it up... */
773 LDLM_DEBUG(lock
, "MGC blocking CB");
774 ldlm_lock2handle(lock
, &lockh
);
775 rc
= ldlm_cli_cancel(&lockh
, LCF_ASYNC
);
777 case LDLM_CB_CANCELING
:
778 /* We've given up the lock, prepare ourselves to update. */
779 LDLM_DEBUG(lock
, "MGC cancel CB");
781 CDEBUG(D_MGC
, "Lock res "DLDLMRES
" (%.8s)\n",
782 PLDLMRES(lock
->l_resource
),
783 (char *)&lock
->l_resource
->lr_name
.name
[0]);
786 CDEBUG(D_INFO
, "missing data, won't requeue\n");
790 /* held at mgc_process_log(). */
791 LASSERT(atomic_read(&cld
->cld_refcount
) > 0);
792 /* Are we done with this log? */
793 if (cld
->cld_stopping
) {
794 CDEBUG(D_MGC
, "log %s: stopping, won't requeue\n",
799 /* Make sure not to re-enqueue when the mgc is stopping
800 (we get called from client_disconnect_export) */
801 if (!lock
->l_conn_export
||
802 !lock
->l_conn_export
->exp_obd
->u
.cli
.cl_conn_count
) {
803 CDEBUG(D_MGC
, "log %.8s: disconnecting, won't requeue\n",
810 mgc_requeue_add(cld
);
820 /* Not sure where this should go... */
821 /* This is the timeout value for MGS_CONNECT request plus a ping interval, such
822 * that we can have a chance to try the secondary MGS if any. */
823 #define MGC_ENQUEUE_LIMIT (INITIAL_CONNECT_TIMEOUT + (AT_OFF ? 0 : at_min) \
825 #define MGC_TARGET_REG_LIMIT 10
826 #define MGC_SEND_PARAM_LIMIT 10
828 /* Send parameter to MGS*/
829 static int mgc_set_mgs_param(struct obd_export
*exp
,
830 struct mgs_send_param
*msp
)
832 struct ptlrpc_request
*req
;
833 struct mgs_send_param
*req_msp
, *rep_msp
;
836 req
= ptlrpc_request_alloc_pack(class_exp2cliimp(exp
),
837 &RQF_MGS_SET_INFO
, LUSTRE_MGS_VERSION
,
842 req_msp
= req_capsule_client_get(&req
->rq_pill
, &RMF_MGS_SEND_PARAM
);
844 ptlrpc_req_finished(req
);
848 memcpy(req_msp
, msp
, sizeof(*req_msp
));
849 ptlrpc_request_set_replen(req
);
851 /* Limit how long we will wait for the enqueue to complete */
852 req
->rq_delay_limit
= MGC_SEND_PARAM_LIMIT
;
853 rc
= ptlrpc_queue_wait(req
);
855 rep_msp
= req_capsule_server_get(&req
->rq_pill
, &RMF_MGS_SEND_PARAM
);
856 memcpy(msp
, rep_msp
, sizeof(*rep_msp
));
859 ptlrpc_req_finished(req
);
864 /* Take a config lock so we can get cancel notifications */
865 static int mgc_enqueue(struct obd_export
*exp
, struct lov_stripe_md
*lsm
,
866 __u32 type
, ldlm_policy_data_t
*policy
, __u32 mode
,
867 __u64
*flags
, void *bl_cb
, void *cp_cb
, void *gl_cb
,
868 void *data
, __u32 lvb_len
, void *lvb_swabber
,
869 struct lustre_handle
*lockh
)
871 struct config_llog_data
*cld
= (struct config_llog_data
*)data
;
872 struct ldlm_enqueue_info einfo
= {
875 .ei_cb_bl
= mgc_blocking_ast
,
876 .ei_cb_cp
= ldlm_completion_ast
,
878 struct ptlrpc_request
*req
;
879 int short_limit
= cld_is_sptlrpc(cld
);
882 CDEBUG(D_MGC
, "Enqueue for %s (res %#llx)\n", cld
->cld_logname
,
883 cld
->cld_resid
.name
[0]);
885 /* We need a callback for every lockholder, so don't try to
886 ldlm_lock_match (see rev 1.1.2.11.2.47) */
887 req
= ptlrpc_request_alloc_pack(class_exp2cliimp(exp
),
888 &RQF_LDLM_ENQUEUE
, LUSTRE_DLM_VERSION
,
893 req_capsule_set_size(&req
->rq_pill
, &RMF_DLM_LVB
, RCL_SERVER
, 0);
894 ptlrpc_request_set_replen(req
);
896 /* Limit how long we will wait for the enqueue to complete */
897 req
->rq_delay_limit
= short_limit
? 5 : MGC_ENQUEUE_LIMIT
;
898 rc
= ldlm_cli_enqueue(exp
, &req
, &einfo
, &cld
->cld_resid
, NULL
, flags
,
899 NULL
, 0, LVB_T_NONE
, lockh
, 0);
900 /* A failed enqueue should still call the mgc_blocking_ast,
901 where it will be requeued if needed ("grant failed"). */
902 ptlrpc_req_finished(req
);
906 static void mgc_notify_active(struct obd_device
*unused
)
908 /* wakeup mgc_requeue_thread to requeue mgc lock */
909 spin_lock(&config_list_lock
);
911 spin_unlock(&config_list_lock
);
914 /* TODO: Help the MGS rebuild nidtbl. -jay */
917 /* Send target_reg message to MGS */
918 static int mgc_target_register(struct obd_export
*exp
,
919 struct mgs_target_info
*mti
)
921 struct ptlrpc_request
*req
;
922 struct mgs_target_info
*req_mti
, *rep_mti
;
925 req
= ptlrpc_request_alloc_pack(class_exp2cliimp(exp
),
926 &RQF_MGS_TARGET_REG
, LUSTRE_MGS_VERSION
,
931 req_mti
= req_capsule_client_get(&req
->rq_pill
, &RMF_MGS_TARGET_INFO
);
933 ptlrpc_req_finished(req
);
937 memcpy(req_mti
, mti
, sizeof(*req_mti
));
938 ptlrpc_request_set_replen(req
);
939 CDEBUG(D_MGC
, "register %s\n", mti
->mti_svname
);
940 /* Limit how long we will wait for the enqueue to complete */
941 req
->rq_delay_limit
= MGC_TARGET_REG_LIMIT
;
943 rc
= ptlrpc_queue_wait(req
);
945 rep_mti
= req_capsule_server_get(&req
->rq_pill
,
946 &RMF_MGS_TARGET_INFO
);
947 memcpy(mti
, rep_mti
, sizeof(*rep_mti
));
948 CDEBUG(D_MGC
, "register %s got index = %d\n",
949 mti
->mti_svname
, mti
->mti_stripe_index
);
951 ptlrpc_req_finished(req
);
956 static int mgc_set_info_async(const struct lu_env
*env
, struct obd_export
*exp
,
957 u32 keylen
, void *key
, u32 vallen
,
958 void *val
, struct ptlrpc_request_set
*set
)
962 /* Turn off initial_recov after we try all backup servers once */
963 if (KEY_IS(KEY_INIT_RECOV_BACKUP
)) {
964 struct obd_import
*imp
= class_exp2cliimp(exp
);
966 if (vallen
!= sizeof(int))
969 CDEBUG(D_MGC
, "InitRecov %s %d/d%d:i%d:r%d:or%d:%s\n",
970 imp
->imp_obd
->obd_name
, value
,
971 imp
->imp_deactive
, imp
->imp_invalid
,
972 imp
->imp_replayable
, imp
->imp_obd
->obd_replayable
,
973 ptlrpc_import_state_name(imp
->imp_state
));
974 /* Resurrect if we previously died */
975 if ((imp
->imp_state
!= LUSTRE_IMP_FULL
&&
976 imp
->imp_state
!= LUSTRE_IMP_NEW
) || value
> 1)
977 ptlrpc_reconnect_import(imp
);
980 if (KEY_IS(KEY_SET_INFO
)) {
981 struct mgs_send_param
*msp
;
983 msp
= (struct mgs_send_param
*)val
;
984 rc
= mgc_set_mgs_param(exp
, msp
);
987 if (KEY_IS(KEY_MGSSEC
)) {
988 struct client_obd
*cli
= &exp
->exp_obd
->u
.cli
;
989 struct sptlrpc_flavor flvr
;
992 * empty string means using current flavor, if which haven't
993 * been set yet, set it as null.
995 * if flavor has been set previously, check the asking flavor
996 * must match the existing one.
999 if (cli
->cl_flvr_mgc
.sf_rpc
!= SPTLRPC_FLVR_INVALID
)
1005 rc
= sptlrpc_parse_flavor(val
, &flvr
);
1007 CERROR("invalid sptlrpc flavor %s to MGS\n",
1013 * caller already hold a mutex
1015 if (cli
->cl_flvr_mgc
.sf_rpc
== SPTLRPC_FLVR_INVALID
) {
1016 cli
->cl_flvr_mgc
= flvr
;
1017 } else if (memcmp(&cli
->cl_flvr_mgc
, &flvr
,
1018 sizeof(flvr
)) != 0) {
1021 sptlrpc_flavor2name(&cli
->cl_flvr_mgc
,
1023 LCONSOLE_ERROR("asking sptlrpc flavor %s to MGS but currently %s is in use\n",
1033 static int mgc_get_info(const struct lu_env
*env
, struct obd_export
*exp
,
1034 __u32 keylen
, void *key
, __u32
*vallen
, void *val
,
1035 struct lov_stripe_md
*unused
)
1039 if (KEY_IS(KEY_CONN_DATA
)) {
1040 struct obd_import
*imp
= class_exp2cliimp(exp
);
1041 struct obd_connect_data
*data
= val
;
1043 if (*vallen
== sizeof(*data
)) {
1044 *data
= imp
->imp_connect_data
;
1052 static int mgc_import_event(struct obd_device
*obd
,
1053 struct obd_import
*imp
,
1054 enum obd_import_event event
)
1056 LASSERT(imp
->imp_obd
== obd
);
1057 CDEBUG(D_MGC
, "import event %#x\n", event
);
1060 case IMP_EVENT_DISCON
:
1061 /* MGC imports should not wait for recovery */
1062 if (OCD_HAS_FLAG(&imp
->imp_connect_data
, IMP_RECOV
))
1063 ptlrpc_pinger_ir_down();
1065 case IMP_EVENT_INACTIVE
:
1067 case IMP_EVENT_INVALIDATE
: {
1068 struct ldlm_namespace
*ns
= obd
->obd_namespace
;
1069 ldlm_namespace_cleanup(ns
, LDLM_FL_LOCAL_ONLY
);
1072 case IMP_EVENT_ACTIVE
:
1073 CDEBUG(D_INFO
, "%s: Reactivating import\n", obd
->obd_name
);
1074 /* Clearing obd_no_recov allows us to continue pinging */
1075 obd
->obd_no_recov
= 0;
1076 mgc_notify_active(obd
);
1077 if (OCD_HAS_FLAG(&imp
->imp_connect_data
, IMP_RECOV
))
1078 ptlrpc_pinger_ir_up();
1082 case IMP_EVENT_DEACTIVATE
:
1083 case IMP_EVENT_ACTIVATE
:
1086 CERROR("Unknown import event %#x\n", event
);
1093 CONFIG_READ_NRPAGES_INIT
= 1 << (20 - PAGE_CACHE_SHIFT
),
1094 CONFIG_READ_NRPAGES
= 4
1097 static int mgc_apply_recover_logs(struct obd_device
*mgc
,
1098 struct config_llog_data
*cld
,
1100 void *data
, int datalen
, bool mne_swab
)
1102 struct config_llog_instance
*cfg
= &cld
->cld_cfg
;
1103 struct mgs_nidtbl_entry
*entry
;
1104 struct lustre_cfg
*lcfg
;
1105 struct lustre_cfg_bufs bufs
;
1106 u64 prev_version
= 0;
1114 LASSERT(cfg
->cfg_instance
!= NULL
);
1115 LASSERT(cfg
->cfg_sb
== cfg
->cfg_instance
);
1117 inst
= kzalloc(PAGE_CACHE_SIZE
, GFP_NOFS
);
1121 pos
= snprintf(inst
, PAGE_CACHE_SIZE
, "%p", cfg
->cfg_instance
);
1122 if (pos
>= PAGE_CACHE_SIZE
) {
1129 bufsz
= PAGE_CACHE_SIZE
- pos
;
1131 while (datalen
> 0) {
1132 int entry_len
= sizeof(*entry
);
1134 struct obd_device
*obd
;
1141 if (datalen
< sizeof(*entry
))
1144 entry
= (typeof(entry
))(data
+ off
);
1147 if (entry
->mne_nid_type
!= 0) /* only support type 0 for ipv4 */
1149 if (entry
->mne_nid_count
== 0) /* at least one nid entry */
1151 if (entry
->mne_nid_size
!= sizeof(lnet_nid_t
))
1154 entry_len
+= entry
->mne_nid_count
* entry
->mne_nid_size
;
1155 if (datalen
< entry_len
) /* must have entry_len at least */
1158 /* Keep this swab for normal mixed endian handling. LU-1644 */
1160 lustre_swab_mgs_nidtbl_entry(entry
);
1161 if (entry
->mne_length
> PAGE_CACHE_SIZE
) {
1162 CERROR("MNE too large (%u)\n", entry
->mne_length
);
1166 if (entry
->mne_length
< entry_len
)
1169 off
+= entry
->mne_length
;
1170 datalen
-= entry
->mne_length
;
1174 if (entry
->mne_version
> max_version
) {
1175 CERROR("entry index(%lld) is over max_index(%lld)\n",
1176 entry
->mne_version
, max_version
);
1180 if (prev_version
>= entry
->mne_version
) {
1181 CERROR("index unsorted, prev %lld, now %lld\n",
1182 prev_version
, entry
->mne_version
);
1185 prev_version
= entry
->mne_version
;
1188 * Write a string with format "nid::instance" to
1189 * lustre/<osc|mdc>/<target>-<osc|mdc>-<instance>/import.
1192 is_ost
= entry
->mne_type
== LDD_F_SV_TYPE_OST
;
1193 memset(buf
, 0, bufsz
);
1197 /* lustre-OST0001-osc-<instance #> */
1198 strcpy(obdname
, cld
->cld_logname
);
1199 cname
= strrchr(obdname
, '-');
1200 if (cname
== NULL
) {
1201 CERROR("mgc %s: invalid logname %s\n",
1202 mgc
->obd_name
, obdname
);
1206 pos
= cname
- obdname
;
1208 pos
+= sprintf(obdname
+ pos
, "-%s%04x",
1209 is_ost
? "OST" : "MDT", entry
->mne_index
);
1211 cname
= is_ost
? "osc" : "mdc";
1212 pos
+= sprintf(obdname
+ pos
, "-%s-%s", cname
, inst
);
1213 lustre_cfg_bufs_reset(&bufs
, obdname
);
1215 /* find the obd by obdname */
1216 obd
= class_name2obd(obdname
);
1218 CDEBUG(D_INFO
, "mgc %s: cannot find obdname %s\n",
1219 mgc
->obd_name
, obdname
);
1221 /* this is a safe race, when the ost is starting up...*/
1225 /* osc.import = "connection=<Conn UUID>::<target instance>" */
1228 pos
+= sprintf(params
, "%s.import=%s", cname
, "connection=");
1231 down_read(&obd
->u
.cli
.cl_sem
);
1232 if (obd
->u
.cli
.cl_import
== NULL
) {
1233 /* client does not connect to the OST yet */
1234 up_read(&obd
->u
.cli
.cl_sem
);
1239 /* TODO: iterate all nids to find one */
1240 /* find uuid by nid */
1241 rc
= client_import_find_conn(obd
->u
.cli
.cl_import
,
1243 (struct obd_uuid
*)uuid
);
1244 up_read(&obd
->u
.cli
.cl_sem
);
1246 CERROR("mgc: cannot find uuid by nid %s\n",
1247 libcfs_nid2str(entry
->u
.nids
[0]));
1251 CDEBUG(D_INFO
, "Find uuid %s by nid %s\n",
1252 uuid
, libcfs_nid2str(entry
->u
.nids
[0]));
1254 pos
+= strlen(uuid
);
1255 pos
+= sprintf(buf
+ pos
, "::%u", entry
->mne_instance
);
1256 LASSERT(pos
< bufsz
);
1258 lustre_cfg_bufs_set_string(&bufs
, 1, params
);
1261 lcfg
= lustre_cfg_new(LCFG_PARAM
, &bufs
);
1263 CERROR("mgc: cannot allocate memory\n");
1267 CDEBUG(D_INFO
, "ir apply logs %lld/%lld for %s -> %s\n",
1268 prev_version
, max_version
, obdname
, params
);
1270 rc
= class_process_config(lcfg
);
1271 lustre_cfg_free(lcfg
);
1273 CDEBUG(D_INFO
, "process config for %s error %d\n",
1276 /* continue, even one with error */
1284 * This function is called if this client was notified for target restarting
1285 * by the MGS. A CONFIG_READ RPC is going to send to fetch recovery logs.
1287 static int mgc_process_recover_log(struct obd_device
*obd
,
1288 struct config_llog_data
*cld
)
1290 struct ptlrpc_request
*req
= NULL
;
1291 struct config_llog_instance
*cfg
= &cld
->cld_cfg
;
1292 struct mgs_config_body
*body
;
1293 struct mgs_config_res
*res
;
1294 struct ptlrpc_bulk_desc
*desc
;
1295 struct page
**pages
;
1298 bool mne_swab
= false;
1303 /* allocate buffer for bulk transfer.
1304 * if this is the first time for this mgs to read logs,
1305 * CONFIG_READ_NRPAGES_INIT will be used since it will read all logs
1306 * once; otherwise, it only reads increment of logs, this should be
1307 * small and CONFIG_READ_NRPAGES will be used.
1309 nrpages
= CONFIG_READ_NRPAGES
;
1310 if (cfg
->cfg_last_idx
== 0) /* the first time */
1311 nrpages
= CONFIG_READ_NRPAGES_INIT
;
1313 pages
= kcalloc(nrpages
, sizeof(*pages
), GFP_NOFS
);
1314 if (pages
== NULL
) {
1319 for (i
= 0; i
< nrpages
; i
++) {
1320 pages
[i
] = alloc_page(GFP_IOFS
);
1321 if (pages
[i
] == NULL
) {
1328 LASSERT(cld_is_recover(cld
));
1329 LASSERT(mutex_is_locked(&cld
->cld_lock
));
1330 req
= ptlrpc_request_alloc(class_exp2cliimp(cld
->cld_mgcexp
),
1331 &RQF_MGS_CONFIG_READ
);
1337 rc
= ptlrpc_request_pack(req
, LUSTRE_MGS_VERSION
, MGS_CONFIG_READ
);
1342 body
= req_capsule_client_get(&req
->rq_pill
, &RMF_MGS_CONFIG_BODY
);
1343 LASSERT(body
!= NULL
);
1344 LASSERT(sizeof(body
->mcb_name
) > strlen(cld
->cld_logname
));
1345 if (strlcpy(body
->mcb_name
, cld
->cld_logname
, sizeof(body
->mcb_name
))
1346 >= sizeof(body
->mcb_name
)) {
1350 body
->mcb_offset
= cfg
->cfg_last_idx
+ 1;
1351 body
->mcb_type
= cld
->cld_type
;
1352 body
->mcb_bits
= PAGE_CACHE_SHIFT
;
1353 body
->mcb_units
= nrpages
;
1355 /* allocate bulk transfer descriptor */
1356 desc
= ptlrpc_prep_bulk_imp(req
, nrpages
, 1, BULK_PUT_SINK
,
1363 for (i
= 0; i
< nrpages
; i
++)
1364 ptlrpc_prep_bulk_page_pin(desc
, pages
[i
], 0, PAGE_CACHE_SIZE
);
1366 ptlrpc_request_set_replen(req
);
1367 rc
= ptlrpc_queue_wait(req
);
1371 res
= req_capsule_server_get(&req
->rq_pill
, &RMF_MGS_CONFIG_RES
);
1372 if (res
->mcr_size
< res
->mcr_offset
) {
1377 /* always update the index even though it might have errors with
1378 * handling the recover logs */
1379 cfg
->cfg_last_idx
= res
->mcr_offset
;
1380 eof
= res
->mcr_offset
== res
->mcr_size
;
1382 CDEBUG(D_INFO
, "Latest version %lld, more %d.\n",
1383 res
->mcr_offset
, eof
== false);
1385 ealen
= sptlrpc_cli_unwrap_bulk_read(req
, req
->rq_bulk
, 0);
1391 if (ealen
> nrpages
<< PAGE_CACHE_SHIFT
) {
1396 if (ealen
== 0) { /* no logs transferred */
1402 mne_swab
= !!ptlrpc_rep_need_swab(req
);
1403 #if LUSTRE_VERSION_CODE < OBD_OCD_VERSION(3, 2, 50, 0)
1404 /* This import flag means the server did an extra swab of IR MNE
1405 * records (fixed in LU-1252), reverse it here if needed. LU-1644 */
1406 if (unlikely(req
->rq_import
->imp_need_mne_swab
))
1407 mne_swab
= !mne_swab
;
1409 #warning "LU-1644: Remove old OBD_CONNECT_MNE_SWAB fixup and imp_need_mne_swab"
1412 for (i
= 0; i
< nrpages
&& ealen
> 0; i
++) {
1416 ptr
= kmap(pages
[i
]);
1417 rc2
= mgc_apply_recover_logs(obd
, cld
, res
->mcr_offset
, ptr
,
1418 min_t(int, ealen
, PAGE_CACHE_SIZE
),
1422 CWARN("Process recover log %s error %d\n",
1423 cld
->cld_logname
, rc2
);
1427 ealen
-= PAGE_CACHE_SIZE
;
1432 ptlrpc_req_finished(req
);
1434 if (rc
== 0 && !eof
)
1438 for (i
= 0; i
< nrpages
; i
++) {
1439 if (pages
[i
] == NULL
)
1441 __free_page(pages
[i
]);
1448 /* local_only means it cannot get remote llogs */
1449 static int mgc_process_cfg_log(struct obd_device
*mgc
,
1450 struct config_llog_data
*cld
, int local_only
)
1452 struct llog_ctxt
*ctxt
;
1453 struct lustre_sb_info
*lsi
= NULL
;
1455 bool sptlrpc_started
= false;
1459 LASSERT(mutex_is_locked(&cld
->cld_lock
));
1462 * local copy of sptlrpc log is controlled elsewhere, don't try to
1465 if (cld_is_sptlrpc(cld
) && local_only
)
1468 if (cld
->cld_cfg
.cfg_sb
)
1469 lsi
= s2lsi(cld
->cld_cfg
.cfg_sb
);
1471 env
= kzalloc(sizeof(*env
), GFP_NOFS
);
1475 rc
= lu_env_init(env
, LCT_MG_THREAD
);
1479 ctxt
= llog_get_context(mgc
, LLOG_CONFIG_REPL_CTXT
);
1482 if (local_only
) /* no local log at client side */ {
1487 if (cld_is_sptlrpc(cld
)) {
1488 sptlrpc_conf_log_update_begin(cld
->cld_logname
);
1489 sptlrpc_started
= true;
1492 /* logname and instance info should be the same, so use our
1493 * copy of the instance for the update. The cfg_last_idx will
1494 * be updated here. */
1495 rc
= class_config_parse_llog(env
, ctxt
, cld
->cld_logname
,
1499 __llog_ctxt_put(env
, ctxt
);
1502 * update settings on existing OBDs. doing it inside
1503 * of llog_process_lock so no device is attaching/detaching
1505 * the logname must be <fsname>-sptlrpc
1507 if (sptlrpc_started
) {
1508 LASSERT(cld_is_sptlrpc(cld
));
1509 sptlrpc_conf_log_update_end(cld
->cld_logname
);
1510 class_notify_sptlrpc_conf(cld
->cld_logname
,
1511 strlen(cld
->cld_logname
) -
1512 strlen("-sptlrpc"));
1521 /** Get a config log from the MGS and process it.
1522 * This func is called for both clients and servers.
1523 * Copy the log locally before parsing it if appropriate (non-MGS server)
1525 int mgc_process_log(struct obd_device
*mgc
, struct config_llog_data
*cld
)
1527 struct lustre_handle lockh
= { 0 };
1528 __u64 flags
= LDLM_FL_NO_LRU
;
1533 /* I don't want multiple processes running process_log at once --
1534 sounds like badness. It actually might be fine, as long as
1535 we're not trying to update from the same log
1536 simultaneously (in which case we should use a per-log sem.) */
1537 mutex_lock(&cld
->cld_lock
);
1538 if (cld
->cld_stopping
) {
1539 mutex_unlock(&cld
->cld_lock
);
1543 OBD_FAIL_TIMEOUT(OBD_FAIL_MGC_PAUSE_PROCESS_LOG
, 20);
1545 CDEBUG(D_MGC
, "Process log %s:%p from %d\n", cld
->cld_logname
,
1546 cld
->cld_cfg
.cfg_instance
, cld
->cld_cfg
.cfg_last_idx
+ 1);
1548 /* Get the cfg lock on the llog */
1549 rcl
= mgc_enqueue(mgc
->u
.cli
.cl_mgc_mgsexp
, NULL
, LDLM_PLAIN
, NULL
,
1550 LCK_CR
, &flags
, NULL
, NULL
, NULL
,
1551 cld
, 0, NULL
, &lockh
);
1553 /* Get the cld, it will be released in mgc_blocking_ast. */
1554 config_log_get(cld
);
1555 rc
= ldlm_lock_set_data(&lockh
, (void *)cld
);
1558 CDEBUG(D_MGC
, "Can't get cfg lock: %d\n", rcl
);
1560 /* mark cld_lostlock so that it will requeue
1561 * after MGC becomes available. */
1562 cld
->cld_lostlock
= 1;
1563 /* Get extra reference, it will be put in requeue thread */
1564 config_log_get(cld
);
1568 if (cld_is_recover(cld
)) {
1569 rc
= 0; /* this is not a fatal error for recover log */
1571 rc
= mgc_process_recover_log(mgc
, cld
);
1573 rc
= mgc_process_cfg_log(mgc
, cld
, rcl
!= 0);
1576 CDEBUG(D_MGC
, "%s: configuration from log '%s' %sed (%d).\n",
1577 mgc
->obd_name
, cld
->cld_logname
, rc
? "fail" : "succeed", rc
);
1579 mutex_unlock(&cld
->cld_lock
);
1581 /* Now drop the lock so MGS can revoke it */
1583 ldlm_lock_decref(&lockh
, LCK_CR
);
1589 /** Called from lustre_process_log.
1590 * LCFG_LOG_START gets the config log from the MGS, processes it to start
1591 * any services, and adds it to the list logs to watch (follow).
1593 static int mgc_process_config(struct obd_device
*obd
, u32 len
, void *buf
)
1595 struct lustre_cfg
*lcfg
= buf
;
1596 struct config_llog_instance
*cfg
= NULL
;
1600 switch (lcfg
->lcfg_command
) {
1601 case LCFG_LOV_ADD_OBD
: {
1602 /* Overloading this cfg command: register a new target */
1603 struct mgs_target_info
*mti
;
1605 if (LUSTRE_CFG_BUFLEN(lcfg
, 1) !=
1606 sizeof(struct mgs_target_info
)) {
1611 mti
= (struct mgs_target_info
*)lustre_cfg_buf(lcfg
, 1);
1612 CDEBUG(D_MGC
, "add_target %s %#x\n",
1613 mti
->mti_svname
, mti
->mti_flags
);
1614 rc
= mgc_target_register(obd
->u
.cli
.cl_mgc_mgsexp
, mti
);
1617 case LCFG_LOV_DEL_OBD
:
1618 /* Unregister has no meaning at the moment. */
1619 CERROR("lov_del_obd unimplemented\n");
1622 case LCFG_SPTLRPC_CONF
: {
1623 rc
= sptlrpc_process_config(lcfg
);
1626 case LCFG_LOG_START
: {
1627 struct config_llog_data
*cld
;
1628 struct super_block
*sb
;
1630 logname
= lustre_cfg_string(lcfg
, 1);
1631 cfg
= (struct config_llog_instance
*)lustre_cfg_buf(lcfg
, 2);
1632 sb
= *(struct super_block
**)lustre_cfg_buf(lcfg
, 3);
1634 CDEBUG(D_MGC
, "parse_log %s from %d\n", logname
,
1637 /* We're only called through here on the initial mount */
1638 rc
= config_log_add(obd
, logname
, cfg
, sb
);
1641 cld
= config_log_find(logname
, cfg
);
1648 /* FIXME only set this for old logs! Right now this forces
1649 us to always skip the "inside markers" check */
1650 cld
->cld_cfg
.cfg_flags
|= CFG_F_COMPAT146
;
1652 rc
= mgc_process_log(obd
, cld
);
1653 if (rc
== 0 && cld
->cld_recover
!= NULL
) {
1654 if (OCD_HAS_FLAG(&obd
->u
.cli
.cl_import
->
1655 imp_connect_data
, IMP_RECOV
)) {
1656 rc
= mgc_process_log(obd
, cld
->cld_recover
);
1658 struct config_llog_data
*cir
= cld
->cld_recover
;
1659 cld
->cld_recover
= NULL
;
1660 config_log_put(cir
);
1663 CERROR("Cannot process recover llog %d\n", rc
);
1666 if (rc
== 0 && cld
->cld_params
!= NULL
) {
1667 rc
= mgc_process_log(obd
, cld
->cld_params
);
1668 if (rc
== -ENOENT
) {
1670 "There is no params config file yet\n");
1673 /* params log is optional */
1676 "%s: can't process params llog: rc = %d\n",
1679 config_log_put(cld
);
1683 case LCFG_LOG_END
: {
1684 logname
= lustre_cfg_string(lcfg
, 1);
1686 if (lcfg
->lcfg_bufcount
>= 2)
1687 cfg
= (struct config_llog_instance
*)lustre_cfg_buf(
1689 rc
= config_log_end(logname
, cfg
);
1693 CERROR("Unknown command: %d\n", lcfg
->lcfg_command
);
1703 struct obd_ops mgc_obd_ops
= {
1704 .o_owner
= THIS_MODULE
,
1705 .o_setup
= mgc_setup
,
1706 .o_precleanup
= mgc_precleanup
,
1707 .o_cleanup
= mgc_cleanup
,
1708 .o_add_conn
= client_import_add_conn
,
1709 .o_del_conn
= client_import_del_conn
,
1710 .o_connect
= client_connect_import
,
1711 .o_disconnect
= client_disconnect_export
,
1712 /* .o_enqueue = mgc_enqueue, */
1713 /* .o_iocontrol = mgc_iocontrol, */
1714 .o_set_info_async
= mgc_set_info_async
,
1715 .o_get_info
= mgc_get_info
,
1716 .o_import_event
= mgc_import_event
,
1717 .o_process_config
= mgc_process_config
,
1720 static int __init
mgc_init(void)
1722 return class_register_type(&mgc_obd_ops
, NULL
,
1723 LUSTRE_MGC_NAME
, NULL
);
1726 static void /*__exit*/ mgc_exit(void)
1728 class_unregister_type(LUSTRE_MGC_NAME
);
1731 MODULE_AUTHOR("Sun Microsystems, Inc. <http://www.lustre.org/>");
1732 MODULE_DESCRIPTION("Lustre Management Client");
1733 MODULE_LICENSE("GPL");
1735 module_init(mgc_init
);
1736 module_exit(mgc_exit
);