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 <linux/pagemap.h>
46 # include <linux/miscdevice.h>
47 # include <linux/init.h>
49 #include <obd_class.h>
50 #include <lustre_dlm.h>
51 #include <lprocfs_status.h>
52 #include <lustre_log.h>
53 #include <lustre_fsfilt.h>
54 #include <lustre_disk.h>
55 #include "mgc_internal.h"
57 static int mgc_name2resid(char *name, int len, struct ldlm_res_id *res_id,
63 CERROR("name too long: %s\n", name);
67 CERROR("missing name: %s\n", name);
70 memcpy(&resname, name, len);
72 /* Always use the same endianness for the resid */
73 memset(res_id, 0, sizeof(*res_id));
74 res_id->name[0] = cpu_to_le64(resname);
75 /* XXX: unfortunately, sptlprc and config llog share one lock */
78 case CONFIG_T_SPTLRPC:
81 case CONFIG_T_RECOVER:
87 res_id->name[1] = cpu_to_le64(resname);
88 CDEBUG(D_MGC, "log %s to resid "LPX64"/"LPX64" (%.8s)\n", name,
89 res_id->name[0], res_id->name[1], (char *)&res_id->name[0]);
93 int mgc_fsname2resid(char *fsname, struct ldlm_res_id *res_id, int type)
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);
99 EXPORT_SYMBOL(mgc_fsname2resid);
101 int mgc_logname2resid(char *logname, struct ldlm_res_id *res_id, int type)
106 /* logname consists of "fsname-nodetype".
107 * e.g. "lustre-MDT0001", "SUN-000-client" */
108 name_end = strrchr(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);
146 if (cld_is_sptlrpc(cld))
147 sptlrpc_conf_log_stop(cld->cld_logname);
149 class_export_put(cld->cld_mgcexp);
150 OBD_FREE(cld, sizeof(*cld) + strlen(cld->cld_logname) + 1);
154 /* Find a config log by name */
156 struct config_llog_data *config_log_find(char *logname,
157 struct config_llog_instance *cfg)
159 struct config_llog_data *cld;
160 struct config_llog_data *found = NULL;
163 LASSERT(logname != NULL);
165 instance = cfg ? cfg->cfg_instance : NULL;
166 spin_lock(&config_list_lock);
167 list_for_each_entry(cld, &config_llog_list, cld_list_chain) {
168 /* check if instance equals */
169 if (instance != cld->cld_cfg.cfg_instance)
172 /* instance may be NULL, should check name */
173 if (strcmp(logname, cld->cld_logname) == 0) {
179 atomic_inc(&found->cld_refcount);
180 LASSERT(found->cld_stopping == 0 || cld_is_sptlrpc(found) == 0);
182 spin_unlock(&config_list_lock);
187 struct config_llog_data *do_config_log_add(struct obd_device *obd,
190 struct config_llog_instance *cfg,
191 struct super_block *sb)
193 struct config_llog_data *cld;
196 CDEBUG(D_MGC, "do adding config log %s:%p\n", logname,
197 cfg ? cfg->cfg_instance : 0);
199 OBD_ALLOC(cld, sizeof(*cld) + strlen(logname) + 1);
201 return ERR_PTR(-ENOMEM);
203 strcpy(cld->cld_logname, logname);
207 cld->cld_cfg.cfg_callback = class_config_llog_handler;
208 mutex_init(&cld->cld_lock);
209 cld->cld_cfg.cfg_last_idx = 0;
210 cld->cld_cfg.cfg_flags = 0;
211 cld->cld_cfg.cfg_sb = sb;
212 cld->cld_type = type;
213 atomic_set(&cld->cld_refcount, 1);
215 /* Keep the mgc around until we are done */
216 cld->cld_mgcexp = class_export_get(obd->obd_self_export);
218 if (cld_is_sptlrpc(cld)) {
219 sptlrpc_conf_log_start(logname);
220 cld->cld_cfg.cfg_obdname = obd->obd_name;
223 rc = mgc_logname2resid(logname, &cld->cld_resid, type);
225 spin_lock(&config_list_lock);
226 list_add(&cld->cld_list_chain, &config_llog_list);
227 spin_unlock(&config_list_lock);
234 if (cld_is_sptlrpc(cld)) {
235 rc = mgc_process_log(obd, cld);
236 if (rc && rc != -ENOENT)
237 CERROR("failed processing sptlrpc log: %d\n", rc);
243 static struct config_llog_data *config_recover_log_add(struct obd_device *obd,
245 struct config_llog_instance *cfg,
246 struct super_block *sb)
248 struct config_llog_instance lcfg = *cfg;
249 struct lustre_sb_info *lsi = s2lsi(sb);
250 struct config_llog_data *cld;
256 /* for osp-on-ost, see lustre_start_osp() */
257 if (IS_MDT(lsi) && lcfg.cfg_instance)
260 /* we have to use different llog for clients and mdts for cmd
261 * where only clients are notified if one of cmd server restarts */
262 LASSERT(strlen(fsname) < sizeof(logname) / 2);
263 strcpy(logname, fsname);
264 if (IS_SERVER(lsi)) { /* mdt */
265 LASSERT(lcfg.cfg_instance == NULL);
266 lcfg.cfg_instance = sb;
267 strcat(logname, "-mdtir");
269 LASSERT(lcfg.cfg_instance != NULL);
270 strcat(logname, "-cliir");
273 cld = do_config_log_add(obd, logname, CONFIG_T_RECOVER, &lcfg, sb);
278 /** Add this log to the list of active logs watched by an MGC.
279 * Active means we're watching for updates.
280 * We have one active log per "mount" - client instance or servername.
281 * Each instance may be at a different point in the log.
283 static int config_log_add(struct obd_device *obd, char *logname,
284 struct config_llog_instance *cfg,
285 struct super_block *sb)
287 struct lustre_sb_info *lsi = s2lsi(sb);
288 struct config_llog_data *cld;
289 struct config_llog_data *sptlrpc_cld;
293 CDEBUG(D_MGC, "adding config log %s:%p\n", logname, cfg->cfg_instance);
296 * for each regular log, the depended sptlrpc log name is
297 * <fsname>-sptlrpc. multiple regular logs may share one sptlrpc log.
299 ptr = strrchr(logname, '-');
300 if (ptr == NULL || ptr - logname > 8) {
301 CERROR("logname %s is too long\n", logname);
305 memcpy(seclogname, logname, ptr - logname);
306 strcpy(seclogname + (ptr - logname), "-sptlrpc");
308 sptlrpc_cld = config_log_find(seclogname, NULL);
309 if (sptlrpc_cld == NULL) {
310 sptlrpc_cld = do_config_log_add(obd, seclogname,
311 CONFIG_T_SPTLRPC, NULL, NULL);
312 if (IS_ERR(sptlrpc_cld)) {
313 CERROR("can't create sptlrpc log: %s\n", seclogname);
314 return PTR_ERR(sptlrpc_cld);
318 cld = do_config_log_add(obd, logname, CONFIG_T_CONFIG, cfg, sb);
320 CERROR("can't create log: %s\n", logname);
321 config_log_put(sptlrpc_cld);
325 cld->cld_sptlrpc = sptlrpc_cld;
327 LASSERT(lsi->lsi_lmd);
328 if (!(lsi->lsi_lmd->lmd_flags & LMD_FLG_NOIR)) {
329 struct config_llog_data *recover_cld;
330 *strrchr(seclogname, '-') = 0;
331 recover_cld = config_recover_log_add(obd, seclogname, cfg, sb);
332 if (IS_ERR(recover_cld)) {
334 return PTR_ERR(recover_cld);
336 cld->cld_recover = recover_cld;
342 DEFINE_MUTEX(llog_process_lock);
344 /** Stop watching for updates on this log.
346 static int config_log_end(char *logname, struct config_llog_instance *cfg)
348 struct config_llog_data *cld;
349 struct config_llog_data *cld_sptlrpc = NULL;
350 struct config_llog_data *cld_recover = NULL;
353 cld = config_log_find(logname, cfg);
357 mutex_lock(&cld->cld_lock);
359 * if cld_stopping is set, it means we didn't start the log thus
360 * not owning the start ref. this can happen after previous umount:
361 * the cld still hanging there waiting for lock cancel, and we
362 * remount again but failed in the middle and call log_end without
365 if (unlikely(cld->cld_stopping)) {
366 mutex_unlock(&cld->cld_lock);
367 /* drop the ref from the find */
372 cld->cld_stopping = 1;
374 cld_recover = cld->cld_recover;
375 cld->cld_recover = NULL;
376 mutex_unlock(&cld->cld_lock);
379 mutex_lock(&cld_recover->cld_lock);
380 cld_recover->cld_stopping = 1;
381 mutex_unlock(&cld_recover->cld_lock);
382 config_log_put(cld_recover);
385 spin_lock(&config_list_lock);
386 cld_sptlrpc = cld->cld_sptlrpc;
387 cld->cld_sptlrpc = NULL;
388 spin_unlock(&config_list_lock);
391 config_log_put(cld_sptlrpc);
393 /* drop the ref from the find */
395 /* drop the start ref */
398 CDEBUG(D_MGC, "end config log %s (%d)\n", logname ? logname : "client",
403 int lprocfs_mgc_rd_ir_state(struct seq_file *m, void *data)
405 struct obd_device *obd = data;
406 struct obd_import *imp = obd->u.cli.cl_import;
407 struct obd_connect_data *ocd = &imp->imp_connect_data;
408 struct config_llog_data *cld;
410 seq_printf(m, "imperative_recovery: %s\n",
411 OCD_HAS_FLAG(ocd, IMP_RECOV) ? "ENABLED" : "DISABLED");
412 seq_printf(m, "client_state:\n");
414 spin_lock(&config_list_lock);
415 list_for_each_entry(cld, &config_llog_list, cld_list_chain) {
416 if (cld->cld_recover == NULL)
418 seq_printf(m, " - { client: %s, nidtbl_version: %u }\n",
420 cld->cld_recover->cld_cfg.cfg_last_idx);
422 spin_unlock(&config_list_lock);
427 /* reenqueue any lost locks */
428 #define RQ_RUNNING 0x1
432 static int rq_state = 0;
433 static wait_queue_head_t rq_waitq;
434 static DECLARE_COMPLETION(rq_exit);
436 static void do_requeue(struct config_llog_data *cld)
438 LASSERT(atomic_read(&cld->cld_refcount) > 0);
440 /* Do not run mgc_process_log on a disconnected export or an
441 export which is being disconnected. Take the client
442 semaphore to make the check non-racy. */
443 down_read(&cld->cld_mgcexp->exp_obd->u.cli.cl_sem);
444 if (cld->cld_mgcexp->exp_obd->u.cli.cl_conn_count != 0) {
445 CDEBUG(D_MGC, "updating log %s\n", cld->cld_logname);
446 mgc_process_log(cld->cld_mgcexp->exp_obd, cld);
448 CDEBUG(D_MGC, "disconnecting, won't update log %s\n",
451 up_read(&cld->cld_mgcexp->exp_obd->u.cli.cl_sem);
454 /* this timeout represents how many seconds MGC should wait before
455 * requeue config and recover lock to the MGS. We need to randomize this
456 * in order to not flood the MGS.
458 #define MGC_TIMEOUT_MIN_SECONDS 5
459 #define MGC_TIMEOUT_RAND_CENTISEC 0x1ff /* ~500 */
461 static int mgc_requeue_thread(void *data)
465 CDEBUG(D_MGC, "Starting requeue thread\n");
467 /* Keep trying failed locks periodically */
468 spin_lock(&config_list_lock);
469 rq_state |= RQ_RUNNING;
471 struct l_wait_info lwi;
472 struct config_llog_data *cld, *cld_prev;
473 int rand = cfs_rand() & MGC_TIMEOUT_RAND_CENTISEC;
474 int stopped = !!(rq_state & RQ_STOP);
477 /* Any new or requeued lostlocks will change the state */
478 rq_state &= ~(RQ_NOW | RQ_LATER);
479 spin_unlock(&config_list_lock);
481 /* Always wait a few seconds to allow the server who
482 caused the lock revocation to finish its setup, plus some
483 random so everyone doesn't try to reconnect at once. */
484 to = MGC_TIMEOUT_MIN_SECONDS * HZ;
485 to += rand * HZ / 100; /* rand is centi-seconds */
486 lwi = LWI_TIMEOUT(to, NULL, NULL);
487 l_wait_event(rq_waitq, rq_state & RQ_STOP, &lwi);
490 * iterate & processing through the list. for each cld, process
491 * its depending sptlrpc cld firstly (if any) and then itself.
493 * it's guaranteed any item in the list must have
494 * reference > 0; and if cld_lostlock is set, at
495 * least one reference is taken by the previous enqueue.
499 spin_lock(&config_list_lock);
500 list_for_each_entry(cld, &config_llog_list,
502 if (!cld->cld_lostlock)
505 spin_unlock(&config_list_lock);
507 LASSERT(atomic_read(&cld->cld_refcount) > 0);
509 /* Whether we enqueued again or not in mgc_process_log,
510 * we're done with the ref from the old enqueue */
512 config_log_put(cld_prev);
515 cld->cld_lostlock = 0;
516 if (likely(!stopped))
519 spin_lock(&config_list_lock);
521 spin_unlock(&config_list_lock);
523 config_log_put(cld_prev);
525 /* break after scanning the list so that we can drop
526 * refcount to losing lock clds */
527 if (unlikely(stopped)) {
528 spin_lock(&config_list_lock);
532 /* Wait a bit to see if anyone else needs a requeue */
533 lwi = (struct l_wait_info) { 0 };
534 l_wait_event(rq_waitq, rq_state & (RQ_NOW | RQ_STOP),
536 spin_lock(&config_list_lock);
538 /* spinlock and while guarantee RQ_NOW and RQ_LATER are not set */
539 rq_state &= ~RQ_RUNNING;
540 spin_unlock(&config_list_lock);
544 CDEBUG(D_MGC, "Ending requeue thread\n");
548 /* Add a cld to the list to requeue. Start the requeue thread if needed.
549 We are responsible for dropping the config log reference from here on out. */
550 static void mgc_requeue_add(struct config_llog_data *cld)
552 CDEBUG(D_INFO, "log %s: requeue (r=%d sp=%d st=%x)\n",
553 cld->cld_logname, atomic_read(&cld->cld_refcount),
554 cld->cld_stopping, rq_state);
555 LASSERT(atomic_read(&cld->cld_refcount) > 0);
557 mutex_lock(&cld->cld_lock);
558 if (cld->cld_stopping || cld->cld_lostlock) {
559 mutex_unlock(&cld->cld_lock);
562 /* this refcount will be released in mgc_requeue_thread. */
564 cld->cld_lostlock = 1;
565 mutex_unlock(&cld->cld_lock);
567 /* Hold lock for rq_state */
568 spin_lock(&config_list_lock);
569 if (rq_state & RQ_STOP) {
570 spin_unlock(&config_list_lock);
571 cld->cld_lostlock = 0;
575 spin_unlock(&config_list_lock);
580 /********************** class fns **********************/
582 static int mgc_fs_setup(struct obd_device *obd, struct super_block *sb,
583 struct vfsmount *mnt)
585 struct lvfs_run_ctxt saved;
586 struct lustre_sb_info *lsi = s2lsi(sb);
587 struct client_obd *cli = &obd->u.cli;
588 struct dentry *dentry;
593 LASSERT(lsi->lsi_srv_mnt == mnt);
595 /* The mgc fs exclusion sem. Only one fs can be setup at a time. */
596 down(&cli->cl_mgc_sem);
598 cfs_cleanup_group_info();
600 obd->obd_fsops = fsfilt_get_ops(lsi->lsi_fstype);
601 if (IS_ERR(obd->obd_fsops)) {
602 up(&cli->cl_mgc_sem);
603 CERROR("%s: No fstype %s: rc = %ld\n", lsi->lsi_fstype,
604 obd->obd_name, PTR_ERR(obd->obd_fsops));
605 return PTR_ERR(obd->obd_fsops);
608 cli->cl_mgc_vfsmnt = mnt;
609 err = fsfilt_setup(obd, mnt->mnt_sb);
613 OBD_SET_CTXT_MAGIC(&obd->obd_lvfs_ctxt);
614 obd->obd_lvfs_ctxt.pwdmnt = mnt;
615 obd->obd_lvfs_ctxt.pwd = mnt->mnt_root;
616 obd->obd_lvfs_ctxt.fs = get_ds();
618 push_ctxt(&saved, &obd->obd_lvfs_ctxt, NULL);
619 dentry = ll_lookup_one_len(MOUNT_CONFIGS_DIR, cfs_fs_pwd(current->fs),
620 strlen(MOUNT_CONFIGS_DIR));
621 pop_ctxt(&saved, &obd->obd_lvfs_ctxt, NULL);
622 if (IS_ERR(dentry)) {
623 err = PTR_ERR(dentry);
624 CERROR("cannot lookup %s directory: rc = %d\n",
625 MOUNT_CONFIGS_DIR, err);
628 cli->cl_mgc_configs_dir = dentry;
630 /* We take an obd ref to insure that we can't get to mgc_cleanup
631 without calling mgc_fs_cleanup first. */
632 class_incref(obd, "mgc_fs", obd);
634 label = fsfilt_get_label(obd, mnt->mnt_sb);
636 CDEBUG(D_MGC, "MGC using disk labelled=%s\n", label);
638 /* We keep the cl_mgc_sem until mgc_fs_cleanup */
642 fsfilt_put_ops(obd->obd_fsops);
643 obd->obd_fsops = NULL;
644 cli->cl_mgc_vfsmnt = NULL;
645 up(&cli->cl_mgc_sem);
649 static int mgc_fs_cleanup(struct obd_device *obd)
651 struct client_obd *cli = &obd->u.cli;
654 LASSERT(cli->cl_mgc_vfsmnt != NULL);
656 if (cli->cl_mgc_configs_dir != NULL) {
657 struct lvfs_run_ctxt saved;
658 push_ctxt(&saved, &obd->obd_lvfs_ctxt, NULL);
659 l_dput(cli->cl_mgc_configs_dir);
660 cli->cl_mgc_configs_dir = NULL;
661 pop_ctxt(&saved, &obd->obd_lvfs_ctxt, NULL);
662 class_decref(obd, "mgc_fs", obd);
665 cli->cl_mgc_vfsmnt = NULL;
667 fsfilt_put_ops(obd->obd_fsops);
669 up(&cli->cl_mgc_sem);
674 static atomic_t mgc_count = ATOMIC_INIT(0);
675 static int mgc_precleanup(struct obd_device *obd, enum obd_cleanup_stage stage)
680 case OBD_CLEANUP_EARLY:
682 case OBD_CLEANUP_EXPORTS:
683 if (atomic_dec_and_test(&mgc_count)) {
685 /* stop requeue thread */
686 spin_lock(&config_list_lock);
687 running = rq_state & RQ_RUNNING;
690 spin_unlock(&config_list_lock);
693 wait_for_completion(&rq_exit);
696 obd_cleanup_client_import(obd);
697 rc = obd_llog_finish(obd, 0);
699 CERROR("failed to cleanup llogging subsystems\n");
705 static int mgc_cleanup(struct obd_device *obd)
707 struct client_obd *cli = &obd->u.cli;
710 LASSERT(cli->cl_mgc_vfsmnt == NULL);
712 /* COMPAT_146 - old config logs may have added profiles we don't
714 if (obd->obd_type->typ_refcnt <= 1)
715 /* Only for the last mgc */
716 class_del_profiles();
718 lprocfs_obd_cleanup(obd);
721 rc = client_obd_cleanup(obd);
725 static int mgc_setup(struct obd_device *obd, struct lustre_cfg *lcfg)
727 struct lprocfs_static_vars lvars;
732 rc = client_obd_setup(obd, lcfg);
734 GOTO(err_decref, rc);
736 rc = obd_llog_init(obd, &obd->obd_olg, obd, NULL);
738 CERROR("failed to setup llogging subsystems\n");
739 GOTO(err_cleanup, rc);
742 lprocfs_mgc_init_vars(&lvars);
743 lprocfs_obd_setup(obd, lvars.obd_vars);
744 sptlrpc_lprocfs_cliobd_attach(obd);
746 if (atomic_inc_return(&mgc_count) == 1) {
748 init_waitqueue_head(&rq_waitq);
750 /* start requeue thread */
751 rc = PTR_ERR(kthread_run(mgc_requeue_thread, NULL,
753 if (IS_ERR_VALUE(rc)) {
754 CERROR("%s: Cannot start requeue thread (%d),"
755 "no more log updates!\n",
757 GOTO(err_cleanup, rc);
759 /* rc is the task_struct pointer of mgc_requeue_thread. */
766 client_obd_cleanup(obd);
772 /* based on ll_mdc_blocking_ast */
773 static int mgc_blocking_ast(struct ldlm_lock *lock, struct ldlm_lock_desc *desc,
774 void *data, int flag)
776 struct lustre_handle lockh;
777 struct config_llog_data *cld = (struct config_llog_data *)data;
781 case LDLM_CB_BLOCKING:
782 /* mgs wants the lock, give it up... */
783 LDLM_DEBUG(lock, "MGC blocking CB");
784 ldlm_lock2handle(lock, &lockh);
785 rc = ldlm_cli_cancel(&lockh, LCF_ASYNC);
787 case LDLM_CB_CANCELING:
788 /* We've given up the lock, prepare ourselves to update. */
789 LDLM_DEBUG(lock, "MGC cancel CB");
791 CDEBUG(D_MGC, "Lock res "LPX64" (%.8s)\n",
792 lock->l_resource->lr_name.name[0],
793 (char *)&lock->l_resource->lr_name.name[0]);
796 CDEBUG(D_INFO, "missing data, won't requeue\n");
800 /* held at mgc_process_log(). */
801 LASSERT(atomic_read(&cld->cld_refcount) > 0);
802 /* Are we done with this log? */
803 if (cld->cld_stopping) {
804 CDEBUG(D_MGC, "log %s: stopping, won't requeue\n",
809 /* Make sure not to re-enqueue when the mgc is stopping
810 (we get called from client_disconnect_export) */
811 if (!lock->l_conn_export ||
812 !lock->l_conn_export->exp_obd->u.cli.cl_conn_count) {
813 CDEBUG(D_MGC, "log %.8s: disconnecting, won't requeue\n",
820 mgc_requeue_add(cld);
830 /* Not sure where this should go... */
831 #define MGC_ENQUEUE_LIMIT 50
832 #define MGC_TARGET_REG_LIMIT 10
833 #define MGC_SEND_PARAM_LIMIT 10
835 /* Send parameter to MGS*/
836 static int mgc_set_mgs_param(struct obd_export *exp,
837 struct mgs_send_param *msp)
839 struct ptlrpc_request *req;
840 struct mgs_send_param *req_msp, *rep_msp;
843 req = ptlrpc_request_alloc_pack(class_exp2cliimp(exp),
844 &RQF_MGS_SET_INFO, LUSTRE_MGS_VERSION,
849 req_msp = req_capsule_client_get(&req->rq_pill, &RMF_MGS_SEND_PARAM);
851 ptlrpc_req_finished(req);
855 memcpy(req_msp, msp, sizeof(*req_msp));
856 ptlrpc_request_set_replen(req);
858 /* Limit how long we will wait for the enqueue to complete */
859 req->rq_delay_limit = MGC_SEND_PARAM_LIMIT;
860 rc = ptlrpc_queue_wait(req);
862 rep_msp = req_capsule_server_get(&req->rq_pill, &RMF_MGS_SEND_PARAM);
863 memcpy(msp, rep_msp, sizeof(*rep_msp));
866 ptlrpc_req_finished(req);
871 /* Take a config lock so we can get cancel notifications */
872 static int mgc_enqueue(struct obd_export *exp, struct lov_stripe_md *lsm,
873 __u32 type, ldlm_policy_data_t *policy, __u32 mode,
874 __u64 *flags, void *bl_cb, void *cp_cb, void *gl_cb,
875 void *data, __u32 lvb_len, void *lvb_swabber,
876 struct lustre_handle *lockh)
878 struct config_llog_data *cld = (struct config_llog_data *)data;
879 struct ldlm_enqueue_info einfo = {
882 .ei_cb_bl = mgc_blocking_ast,
883 .ei_cb_cp = ldlm_completion_ast,
885 struct ptlrpc_request *req;
886 int short_limit = cld_is_sptlrpc(cld);
889 CDEBUG(D_MGC, "Enqueue for %s (res "LPX64")\n", cld->cld_logname,
890 cld->cld_resid.name[0]);
892 /* We need a callback for every lockholder, so don't try to
893 ldlm_lock_match (see rev 1.1.2.11.2.47) */
894 req = ptlrpc_request_alloc_pack(class_exp2cliimp(exp),
895 &RQF_LDLM_ENQUEUE, LUSTRE_DLM_VERSION,
900 req_capsule_set_size(&req->rq_pill, &RMF_DLM_LVB, RCL_SERVER, 0);
901 ptlrpc_request_set_replen(req);
903 /* check if this is server or client */
904 if (cld->cld_cfg.cfg_sb) {
905 struct lustre_sb_info *lsi = s2lsi(cld->cld_cfg.cfg_sb);
906 if (lsi && IS_SERVER(lsi))
909 /* Limit how long we will wait for the enqueue to complete */
910 req->rq_delay_limit = short_limit ? 5 : MGC_ENQUEUE_LIMIT;
911 rc = ldlm_cli_enqueue(exp, &req, &einfo, &cld->cld_resid, NULL, flags,
912 NULL, 0, LVB_T_NONE, lockh, 0);
913 /* A failed enqueue should still call the mgc_blocking_ast,
914 where it will be requeued if needed ("grant failed"). */
915 ptlrpc_req_finished(req);
919 static int mgc_cancel(struct obd_export *exp, struct lov_stripe_md *md,
920 __u32 mode, struct lustre_handle *lockh)
922 ldlm_lock_decref(lockh, mode);
927 static void mgc_notify_active(struct obd_device *unused)
929 /* wakeup mgc_requeue_thread to requeue mgc lock */
930 spin_lock(&config_list_lock);
932 spin_unlock(&config_list_lock);
935 /* TODO: Help the MGS rebuild nidtbl. -jay */
938 /* Send target_reg message to MGS */
939 static int mgc_target_register(struct obd_export *exp,
940 struct mgs_target_info *mti)
942 struct ptlrpc_request *req;
943 struct mgs_target_info *req_mti, *rep_mti;
946 req = ptlrpc_request_alloc_pack(class_exp2cliimp(exp),
947 &RQF_MGS_TARGET_REG, LUSTRE_MGS_VERSION,
952 req_mti = req_capsule_client_get(&req->rq_pill, &RMF_MGS_TARGET_INFO);
954 ptlrpc_req_finished(req);
958 memcpy(req_mti, mti, sizeof(*req_mti));
959 ptlrpc_request_set_replen(req);
960 CDEBUG(D_MGC, "register %s\n", mti->mti_svname);
961 /* Limit how long we will wait for the enqueue to complete */
962 req->rq_delay_limit = MGC_TARGET_REG_LIMIT;
964 rc = ptlrpc_queue_wait(req);
966 rep_mti = req_capsule_server_get(&req->rq_pill,
967 &RMF_MGS_TARGET_INFO);
968 memcpy(mti, rep_mti, sizeof(*rep_mti));
969 CDEBUG(D_MGC, "register %s got index = %d\n",
970 mti->mti_svname, mti->mti_stripe_index);
972 ptlrpc_req_finished(req);
977 int mgc_set_info_async(const struct lu_env *env, struct obd_export *exp,
978 obd_count keylen, void *key, obd_count vallen,
979 void *val, struct ptlrpc_request_set *set)
983 /* Turn off initial_recov after we try all backup servers once */
984 if (KEY_IS(KEY_INIT_RECOV_BACKUP)) {
985 struct obd_import *imp = class_exp2cliimp(exp);
987 if (vallen != sizeof(int))
990 CDEBUG(D_MGC, "InitRecov %s %d/d%d:i%d:r%d:or%d:%s\n",
991 imp->imp_obd->obd_name, value,
992 imp->imp_deactive, imp->imp_invalid,
993 imp->imp_replayable, imp->imp_obd->obd_replayable,
994 ptlrpc_import_state_name(imp->imp_state));
995 /* Resurrect if we previously died */
996 if ((imp->imp_state != LUSTRE_IMP_FULL &&
997 imp->imp_state != LUSTRE_IMP_NEW) || value > 1)
998 ptlrpc_reconnect_import(imp);
1001 /* FIXME move this to mgc_process_config */
1002 if (KEY_IS(KEY_REGISTER_TARGET)) {
1003 struct mgs_target_info *mti;
1004 if (vallen != sizeof(struct mgs_target_info))
1006 mti = (struct mgs_target_info *)val;
1007 CDEBUG(D_MGC, "register_target %s %#x\n",
1008 mti->mti_svname, mti->mti_flags);
1009 rc = mgc_target_register(exp, mti);
1012 if (KEY_IS(KEY_SET_FS)) {
1013 struct super_block *sb = (struct super_block *)val;
1014 struct lustre_sb_info *lsi;
1015 if (vallen != sizeof(struct super_block))
1018 rc = mgc_fs_setup(exp->exp_obd, sb, lsi->lsi_srv_mnt);
1020 CERROR("set_fs got %d\n", rc);
1024 if (KEY_IS(KEY_CLEAR_FS)) {
1027 rc = mgc_fs_cleanup(exp->exp_obd);
1029 CERROR("clear_fs got %d\n", rc);
1033 if (KEY_IS(KEY_SET_INFO)) {
1034 struct mgs_send_param *msp;
1036 msp = (struct mgs_send_param *)val;
1037 rc = mgc_set_mgs_param(exp, msp);
1040 if (KEY_IS(KEY_MGSSEC)) {
1041 struct client_obd *cli = &exp->exp_obd->u.cli;
1042 struct sptlrpc_flavor flvr;
1045 * empty string means using current flavor, if which haven't
1046 * been set yet, set it as null.
1048 * if flavor has been set previously, check the asking flavor
1049 * must match the existing one.
1052 if (cli->cl_flvr_mgc.sf_rpc != SPTLRPC_FLVR_INVALID)
1058 rc = sptlrpc_parse_flavor(val, &flvr);
1060 CERROR("invalid sptlrpc flavor %s to MGS\n",
1066 * caller already hold a mutex
1068 if (cli->cl_flvr_mgc.sf_rpc == SPTLRPC_FLVR_INVALID) {
1069 cli->cl_flvr_mgc = flvr;
1070 } else if (memcmp(&cli->cl_flvr_mgc, &flvr,
1071 sizeof(flvr)) != 0) {
1074 sptlrpc_flavor2name(&cli->cl_flvr_mgc,
1076 LCONSOLE_ERROR("asking sptlrpc flavor %s to MGS but "
1077 "currently %s is in use\n",
1087 static int mgc_get_info(const struct lu_env *env, struct obd_export *exp,
1088 __u32 keylen, void *key, __u32 *vallen, void *val,
1089 struct lov_stripe_md *unused)
1093 if (KEY_IS(KEY_CONN_DATA)) {
1094 struct obd_import *imp = class_exp2cliimp(exp);
1095 struct obd_connect_data *data = val;
1097 if (*vallen == sizeof(*data)) {
1098 *data = imp->imp_connect_data;
1106 static int mgc_import_event(struct obd_device *obd,
1107 struct obd_import *imp,
1108 enum obd_import_event event)
1112 LASSERT(imp->imp_obd == obd);
1113 CDEBUG(D_MGC, "import event %#x\n", event);
1116 case IMP_EVENT_DISCON:
1117 /* MGC imports should not wait for recovery */
1118 if (OCD_HAS_FLAG(&imp->imp_connect_data, IMP_RECOV))
1119 ptlrpc_pinger_ir_down();
1121 case IMP_EVENT_INACTIVE:
1123 case IMP_EVENT_INVALIDATE: {
1124 struct ldlm_namespace *ns = obd->obd_namespace;
1125 ldlm_namespace_cleanup(ns, LDLM_FL_LOCAL_ONLY);
1128 case IMP_EVENT_ACTIVE:
1129 CDEBUG(D_INFO, "%s: Reactivating import\n", obd->obd_name);
1130 /* Clearing obd_no_recov allows us to continue pinging */
1131 obd->obd_no_recov = 0;
1132 mgc_notify_active(obd);
1133 if (OCD_HAS_FLAG(&imp->imp_connect_data, IMP_RECOV))
1134 ptlrpc_pinger_ir_up();
1138 case IMP_EVENT_DEACTIVATE:
1139 case IMP_EVENT_ACTIVATE:
1142 CERROR("Unknown import event %#x\n", event);
1148 static int mgc_llog_init(struct obd_device *obd, struct obd_llog_group *olg,
1149 struct obd_device *tgt, int *index)
1151 struct llog_ctxt *ctxt;
1154 LASSERT(olg == &obd->obd_olg);
1157 rc = llog_setup(NULL, obd, olg, LLOG_CONFIG_REPL_CTXT, tgt,
1162 ctxt = llog_group_get_ctxt(olg, LLOG_CONFIG_REPL_CTXT);
1164 GOTO(out, rc = -ENODEV);
1166 llog_initiator_connect(ctxt);
1167 llog_ctxt_put(ctxt);
1171 ctxt = llog_get_context(obd, LLOG_CONFIG_ORIG_CTXT);
1173 llog_cleanup(NULL, ctxt);
1177 static int mgc_llog_finish(struct obd_device *obd, int count)
1179 struct llog_ctxt *ctxt;
1181 ctxt = llog_get_context(obd, LLOG_CONFIG_REPL_CTXT);
1183 llog_cleanup(NULL, ctxt);
1185 ctxt = llog_get_context(obd, LLOG_CONFIG_ORIG_CTXT);
1187 llog_cleanup(NULL, ctxt);
1192 CONFIG_READ_NRPAGES_INIT = 1 << (20 - PAGE_CACHE_SHIFT),
1193 CONFIG_READ_NRPAGES = 4
1196 static int mgc_apply_recover_logs(struct obd_device *mgc,
1197 struct config_llog_data *cld,
1199 void *data, int datalen, bool mne_swab)
1201 struct config_llog_instance *cfg = &cld->cld_cfg;
1202 struct lustre_sb_info *lsi = s2lsi(cfg->cfg_sb);
1203 struct mgs_nidtbl_entry *entry;
1204 struct lustre_cfg *lcfg;
1205 struct lustre_cfg_bufs bufs;
1206 u64 prev_version = 0;
1214 LASSERT(cfg->cfg_instance != NULL);
1215 LASSERT(cfg->cfg_sb == cfg->cfg_instance);
1217 OBD_ALLOC(inst, PAGE_CACHE_SIZE);
1221 if (!IS_SERVER(lsi)) {
1222 pos = snprintf(inst, PAGE_CACHE_SIZE, "%p", cfg->cfg_instance);
1223 if (pos >= PAGE_CACHE_SIZE) {
1224 OBD_FREE(inst, PAGE_CACHE_SIZE);
1228 LASSERT(IS_MDT(lsi));
1229 rc = server_name2svname(lsi->lsi_svname, inst, NULL,
1232 OBD_FREE(inst, PAGE_CACHE_SIZE);
1240 bufsz = PAGE_CACHE_SIZE - pos;
1242 while (datalen > 0) {
1243 int entry_len = sizeof(*entry);
1245 struct obd_device *obd;
1252 if (datalen < sizeof(*entry))
1255 entry = (typeof(entry))(data + off);
1258 if (entry->mne_nid_type != 0) /* only support type 0 for ipv4 */
1260 if (entry->mne_nid_count == 0) /* at least one nid entry */
1262 if (entry->mne_nid_size != sizeof(lnet_nid_t))
1265 entry_len += entry->mne_nid_count * entry->mne_nid_size;
1266 if (datalen < entry_len) /* must have entry_len at least */
1269 /* Keep this swab for normal mixed endian handling. LU-1644 */
1271 lustre_swab_mgs_nidtbl_entry(entry);
1272 if (entry->mne_length > PAGE_CACHE_SIZE) {
1273 CERROR("MNE too large (%u)\n", entry->mne_length);
1277 if (entry->mne_length < entry_len)
1280 off += entry->mne_length;
1281 datalen -= entry->mne_length;
1285 if (entry->mne_version > max_version) {
1286 CERROR("entry index(%lld) is over max_index(%lld)\n",
1287 entry->mne_version, max_version);
1291 if (prev_version >= entry->mne_version) {
1292 CERROR("index unsorted, prev %lld, now %lld\n",
1293 prev_version, entry->mne_version);
1296 prev_version = entry->mne_version;
1299 * Write a string with format "nid::instance" to
1300 * lustre/<osc|mdc>/<target>-<osc|mdc>-<instance>/import.
1303 is_ost = entry->mne_type == LDD_F_SV_TYPE_OST;
1304 memset(buf, 0, bufsz);
1308 /* lustre-OST0001-osc-<instance #> */
1309 strcpy(obdname, cld->cld_logname);
1310 cname = strrchr(obdname, '-');
1311 if (cname == NULL) {
1312 CERROR("mgc %s: invalid logname %s\n",
1313 mgc->obd_name, obdname);
1317 pos = cname - obdname;
1319 pos += sprintf(obdname + pos, "-%s%04x",
1320 is_ost ? "OST" : "MDT", entry->mne_index);
1322 cname = is_ost ? "osc" : "mdc",
1323 pos += sprintf(obdname + pos, "-%s-%s", cname, inst);
1324 lustre_cfg_bufs_reset(&bufs, obdname);
1326 /* find the obd by obdname */
1327 obd = class_name2obd(obdname);
1329 CDEBUG(D_INFO, "mgc %s: cannot find obdname %s\n",
1330 mgc->obd_name, obdname);
1332 /* this is a safe race, when the ost is starting up...*/
1336 /* osc.import = "connection=<Conn UUID>::<target instance>" */
1339 pos += sprintf(params, "%s.import=%s", cname, "connection=");
1342 down_read(&obd->u.cli.cl_sem);
1343 if (obd->u.cli.cl_import == NULL) {
1344 /* client does not connect to the OST yet */
1345 up_read(&obd->u.cli.cl_sem);
1350 /* TODO: iterate all nids to find one */
1351 /* find uuid by nid */
1352 rc = client_import_find_conn(obd->u.cli.cl_import,
1354 (struct obd_uuid *)uuid);
1355 up_read(&obd->u.cli.cl_sem);
1357 CERROR("mgc: cannot find uuid by nid %s\n",
1358 libcfs_nid2str(entry->u.nids[0]));
1362 CDEBUG(D_INFO, "Find uuid %s by nid %s\n",
1363 uuid, libcfs_nid2str(entry->u.nids[0]));
1365 pos += strlen(uuid);
1366 pos += sprintf(buf + pos, "::%u", entry->mne_instance);
1367 LASSERT(pos < bufsz);
1369 lustre_cfg_bufs_set_string(&bufs, 1, params);
1372 lcfg = lustre_cfg_new(LCFG_PARAM, &bufs);
1374 CERROR("mgc: cannot allocate memory\n");
1378 CDEBUG(D_INFO, "ir apply logs "LPD64"/"LPD64" for %s -> %s\n",
1379 prev_version, max_version, obdname, params);
1381 rc = class_process_config(lcfg);
1382 lustre_cfg_free(lcfg);
1384 CDEBUG(D_INFO, "process config for %s error %d\n",
1387 /* continue, even one with error */
1390 OBD_FREE(inst, PAGE_CACHE_SIZE);
1395 * This function is called if this client was notified for target restarting
1396 * by the MGS. A CONFIG_READ RPC is going to send to fetch recovery logs.
1398 static int mgc_process_recover_log(struct obd_device *obd,
1399 struct config_llog_data *cld)
1401 struct ptlrpc_request *req = NULL;
1402 struct config_llog_instance *cfg = &cld->cld_cfg;
1403 struct mgs_config_body *body;
1404 struct mgs_config_res *res;
1405 struct ptlrpc_bulk_desc *desc;
1406 struct page **pages;
1409 bool mne_swab = false;
1414 /* allocate buffer for bulk transfer.
1415 * if this is the first time for this mgs to read logs,
1416 * CONFIG_READ_NRPAGES_INIT will be used since it will read all logs
1417 * once; otherwise, it only reads increment of logs, this should be
1418 * small and CONFIG_READ_NRPAGES will be used.
1420 nrpages = CONFIG_READ_NRPAGES;
1421 if (cfg->cfg_last_idx == 0) /* the first time */
1422 nrpages = CONFIG_READ_NRPAGES_INIT;
1424 OBD_ALLOC(pages, sizeof(*pages) * nrpages);
1426 GOTO(out, rc = -ENOMEM);
1428 for (i = 0; i < nrpages; i++) {
1429 pages[i] = alloc_page(GFP_IOFS);
1430 if (pages[i] == NULL)
1431 GOTO(out, rc = -ENOMEM);
1435 LASSERT(cld_is_recover(cld));
1436 LASSERT(mutex_is_locked(&cld->cld_lock));
1437 req = ptlrpc_request_alloc(class_exp2cliimp(cld->cld_mgcexp),
1438 &RQF_MGS_CONFIG_READ);
1440 GOTO(out, rc = -ENOMEM);
1442 rc = ptlrpc_request_pack(req, LUSTRE_MGS_VERSION, MGS_CONFIG_READ);
1447 body = req_capsule_client_get(&req->rq_pill, &RMF_MGS_CONFIG_BODY);
1448 LASSERT(body != NULL);
1449 LASSERT(sizeof(body->mcb_name) > strlen(cld->cld_logname));
1450 if (strlcpy(body->mcb_name, cld->cld_logname, sizeof(body->mcb_name))
1451 >= sizeof(body->mcb_name))
1452 GOTO(out, rc = -E2BIG);
1453 body->mcb_offset = cfg->cfg_last_idx + 1;
1454 body->mcb_type = cld->cld_type;
1455 body->mcb_bits = PAGE_CACHE_SHIFT;
1456 body->mcb_units = nrpages;
1458 /* allocate bulk transfer descriptor */
1459 desc = ptlrpc_prep_bulk_imp(req, nrpages, 1, BULK_PUT_SINK,
1462 GOTO(out, rc = -ENOMEM);
1464 for (i = 0; i < nrpages; i++)
1465 ptlrpc_prep_bulk_page_pin(desc, pages[i], 0, PAGE_CACHE_SIZE);
1467 ptlrpc_request_set_replen(req);
1468 rc = ptlrpc_queue_wait(req);
1472 res = req_capsule_server_get(&req->rq_pill, &RMF_MGS_CONFIG_RES);
1473 if (res->mcr_size < res->mcr_offset)
1474 GOTO(out, rc = -EINVAL);
1476 /* always update the index even though it might have errors with
1477 * handling the recover logs */
1478 cfg->cfg_last_idx = res->mcr_offset;
1479 eof = res->mcr_offset == res->mcr_size;
1481 CDEBUG(D_INFO, "Latest version "LPD64", more %d.\n",
1482 res->mcr_offset, eof == false);
1484 ealen = sptlrpc_cli_unwrap_bulk_read(req, req->rq_bulk, 0);
1486 GOTO(out, rc = ealen);
1488 if (ealen > nrpages << PAGE_CACHE_SHIFT)
1489 GOTO(out, rc = -EINVAL);
1491 if (ealen == 0) { /* no logs transferred */
1497 mne_swab = !!ptlrpc_rep_need_swab(req);
1498 #if LUSTRE_VERSION_CODE < OBD_OCD_VERSION(3, 2, 50, 0)
1499 /* This import flag means the server did an extra swab of IR MNE
1500 * records (fixed in LU-1252), reverse it here if needed. LU-1644 */
1501 if (unlikely(req->rq_import->imp_need_mne_swab))
1502 mne_swab = !mne_swab;
1504 #warning "LU-1644: Remove old OBD_CONNECT_MNE_SWAB fixup and imp_need_mne_swab"
1507 for (i = 0; i < nrpages && ealen > 0; i++) {
1511 ptr = kmap(pages[i]);
1512 rc2 = mgc_apply_recover_logs(obd, cld, res->mcr_offset, ptr,
1513 min_t(int, ealen, PAGE_CACHE_SIZE),
1517 CWARN("Process recover log %s error %d\n",
1518 cld->cld_logname, rc2);
1522 ealen -= PAGE_CACHE_SIZE;
1527 ptlrpc_req_finished(req);
1529 if (rc == 0 && !eof)
1533 for (i = 0; i < nrpages; i++) {
1534 if (pages[i] == NULL)
1536 __free_page(pages[i]);
1538 OBD_FREE(pages, sizeof(*pages) * nrpages);
1544 /* local_only means it cannot get remote llogs */
1545 static int mgc_process_cfg_log(struct obd_device *mgc,
1546 struct config_llog_data *cld,
1549 struct llog_ctxt *ctxt, *lctxt = NULL;
1550 struct lvfs_run_ctxt *saved_ctxt;
1551 struct lustre_sb_info *lsi = NULL;
1552 int rc = 0, must_pop = 0;
1553 bool sptlrpc_started = false;
1556 LASSERT(mutex_is_locked(&cld->cld_lock));
1559 * local copy of sptlrpc log is controlled elsewhere, don't try to
1562 if (cld_is_sptlrpc(cld) && local_only)
1565 if (cld->cld_cfg.cfg_sb)
1566 lsi = s2lsi(cld->cld_cfg.cfg_sb);
1568 ctxt = llog_get_context(mgc, LLOG_CONFIG_REPL_CTXT);
1570 CERROR("missing llog context\n");
1574 OBD_ALLOC_PTR(saved_ctxt);
1575 if (saved_ctxt == NULL)
1578 lctxt = llog_get_context(mgc, LLOG_CONFIG_ORIG_CTXT);
1580 if (local_only) { /* no local log at client side */
1581 GOTO(out_pop, rc = -EIO);
1584 if (cld_is_sptlrpc(cld)) {
1585 sptlrpc_conf_log_update_begin(cld->cld_logname);
1586 sptlrpc_started = true;
1589 /* logname and instance info should be the same, so use our
1590 copy of the instance for the update. The cfg_last_idx will
1592 rc = class_config_parse_llog(NULL, ctxt, cld->cld_logname,
1596 llog_ctxt_put(ctxt);
1598 llog_ctxt_put(lctxt);
1600 pop_ctxt(saved_ctxt, &mgc->obd_lvfs_ctxt, NULL);
1602 OBD_FREE_PTR(saved_ctxt);
1604 * update settings on existing OBDs. doing it inside
1605 * of llog_process_lock so no device is attaching/detaching
1607 * the logname must be <fsname>-sptlrpc
1609 if (sptlrpc_started) {
1610 LASSERT(cld_is_sptlrpc(cld));
1611 sptlrpc_conf_log_update_end(cld->cld_logname);
1612 class_notify_sptlrpc_conf(cld->cld_logname,
1613 strlen(cld->cld_logname) -
1614 strlen("-sptlrpc"));
1620 /** Get a config log from the MGS and process it.
1621 * This func is called for both clients and servers.
1622 * Copy the log locally before parsing it if appropriate (non-MGS server)
1624 int mgc_process_log(struct obd_device *mgc, struct config_llog_data *cld)
1626 struct lustre_handle lockh = { 0 };
1627 __u64 flags = LDLM_FL_NO_LRU;
1632 /* I don't want multiple processes running process_log at once --
1633 sounds like badness. It actually might be fine, as long as
1634 we're not trying to update from the same log
1635 simultaneously (in which case we should use a per-log sem.) */
1636 mutex_lock(&cld->cld_lock);
1637 if (cld->cld_stopping) {
1638 mutex_unlock(&cld->cld_lock);
1642 OBD_FAIL_TIMEOUT(OBD_FAIL_MGC_PAUSE_PROCESS_LOG, 20);
1644 CDEBUG(D_MGC, "Process log %s:%p from %d\n", cld->cld_logname,
1645 cld->cld_cfg.cfg_instance, cld->cld_cfg.cfg_last_idx + 1);
1647 /* Get the cfg lock on the llog */
1648 rcl = mgc_enqueue(mgc->u.cli.cl_mgc_mgsexp, NULL, LDLM_PLAIN, NULL,
1649 LCK_CR, &flags, NULL, NULL, NULL,
1650 cld, 0, NULL, &lockh);
1652 /* Get the cld, it will be released in mgc_blocking_ast. */
1653 config_log_get(cld);
1654 rc = ldlm_lock_set_data(&lockh, (void *)cld);
1657 CDEBUG(D_MGC, "Can't get cfg lock: %d\n", rcl);
1659 /* mark cld_lostlock so that it will requeue
1660 * after MGC becomes available. */
1661 cld->cld_lostlock = 1;
1662 /* Get extra reference, it will be put in requeue thread */
1663 config_log_get(cld);
1667 if (cld_is_recover(cld)) {
1668 rc = 0; /* this is not a fatal error for recover log */
1670 rc = mgc_process_recover_log(mgc, cld);
1672 rc = mgc_process_cfg_log(mgc, cld, rcl != 0);
1675 CDEBUG(D_MGC, "%s: configuration from log '%s' %sed (%d).\n",
1676 mgc->obd_name, cld->cld_logname, rc ? "fail" : "succeed", rc);
1678 mutex_unlock(&cld->cld_lock);
1680 /* Now drop the lock so MGS can revoke it */
1682 rcl = mgc_cancel(mgc->u.cli.cl_mgc_mgsexp, NULL,
1685 CERROR("Can't drop cfg lock: %d\n", rcl);
1692 /** Called from lustre_process_log.
1693 * LCFG_LOG_START gets the config log from the MGS, processes it to start
1694 * any services, and adds it to the list logs to watch (follow).
1696 static int mgc_process_config(struct obd_device *obd, obd_count len, void *buf)
1698 struct lustre_cfg *lcfg = buf;
1699 struct config_llog_instance *cfg = NULL;
1703 switch(lcfg->lcfg_command) {
1704 case LCFG_LOV_ADD_OBD: {
1705 /* Overloading this cfg command: register a new target */
1706 struct mgs_target_info *mti;
1708 if (LUSTRE_CFG_BUFLEN(lcfg, 1) !=
1709 sizeof(struct mgs_target_info))
1710 GOTO(out, rc = -EINVAL);
1712 mti = (struct mgs_target_info *)lustre_cfg_buf(lcfg, 1);
1713 CDEBUG(D_MGC, "add_target %s %#x\n",
1714 mti->mti_svname, mti->mti_flags);
1715 rc = mgc_target_register(obd->u.cli.cl_mgc_mgsexp, mti);
1718 case LCFG_LOV_DEL_OBD:
1719 /* Unregister has no meaning at the moment. */
1720 CERROR("lov_del_obd unimplemented\n");
1723 case LCFG_SPTLRPC_CONF: {
1724 rc = sptlrpc_process_config(lcfg);
1727 case LCFG_LOG_START: {
1728 struct config_llog_data *cld;
1729 struct super_block *sb;
1731 logname = lustre_cfg_string(lcfg, 1);
1732 cfg = (struct config_llog_instance *)lustre_cfg_buf(lcfg, 2);
1733 sb = *(struct super_block **)lustre_cfg_buf(lcfg, 3);
1735 CDEBUG(D_MGC, "parse_log %s from %d\n", logname,
1738 /* We're only called through here on the initial mount */
1739 rc = config_log_add(obd, logname, cfg, sb);
1742 cld = config_log_find(logname, cfg);
1749 /* FIXME only set this for old logs! Right now this forces
1750 us to always skip the "inside markers" check */
1751 cld->cld_cfg.cfg_flags |= CFG_F_COMPAT146;
1753 rc = mgc_process_log(obd, cld);
1754 if (rc == 0 && cld->cld_recover != NULL) {
1755 if (OCD_HAS_FLAG(&obd->u.cli.cl_import->
1756 imp_connect_data, IMP_RECOV)) {
1757 rc = mgc_process_log(obd, cld->cld_recover);
1759 struct config_llog_data *cir = cld->cld_recover;
1760 cld->cld_recover = NULL;
1761 config_log_put(cir);
1764 CERROR("Cannot process recover llog %d\n", rc);
1766 config_log_put(cld);
1770 case LCFG_LOG_END: {
1771 logname = lustre_cfg_string(lcfg, 1);
1773 if (lcfg->lcfg_bufcount >= 2)
1774 cfg = (struct config_llog_instance *)lustre_cfg_buf(
1776 rc = config_log_end(logname, cfg);
1780 CERROR("Unknown command: %d\n", lcfg->lcfg_command);
1781 GOTO(out, rc = -EINVAL);
1789 struct obd_ops mgc_obd_ops = {
1790 .o_owner = THIS_MODULE,
1791 .o_setup = mgc_setup,
1792 .o_precleanup = mgc_precleanup,
1793 .o_cleanup = mgc_cleanup,
1794 .o_add_conn = client_import_add_conn,
1795 .o_del_conn = client_import_del_conn,
1796 .o_connect = client_connect_import,
1797 .o_disconnect = client_disconnect_export,
1798 //.o_enqueue = mgc_enqueue,
1799 .o_cancel = mgc_cancel,
1800 //.o_iocontrol = mgc_iocontrol,
1801 .o_set_info_async = mgc_set_info_async,
1802 .o_get_info = mgc_get_info,
1803 .o_import_event = mgc_import_event,
1804 .o_llog_init = mgc_llog_init,
1805 .o_llog_finish = mgc_llog_finish,
1806 .o_process_config = mgc_process_config,
1809 int __init mgc_init(void)
1811 return class_register_type(&mgc_obd_ops, NULL, NULL,
1812 LUSTRE_MGC_NAME, NULL);
1815 static void /*__exit*/ mgc_exit(void)
1817 class_unregister_type(LUSTRE_MGC_NAME);
1820 MODULE_AUTHOR("Sun Microsystems, Inc. <http://www.lustre.org/>");
1821 MODULE_DESCRIPTION("Lustre Management Client");
1822 MODULE_LICENSE("GPL");
1824 module_init(mgc_init);
1825 module_exit(mgc_exit);