1 /* -*- mode: c; c-basic-offset: 8; indent-tabs-mode: nil; -*-
2 * vim:expandtab:shiftwidth=8:tabstop=8:
4 * Copyright (c) 2001-2006 Cluster File Systems, Inc.
6 * This file is part of the Lustre file system, http://www.lustre.org
7 * Lustre is a trademark of Cluster File Systems, Inc.
9 * You may have signed or agreed to another license before downloading
10 * this software. If so, you are bound by the terms and conditions
11 * of that agreement, and the following does not apply to you. See the
12 * LICENSE file included with this distribution for more information.
14 * If you did not agree to a different license, then this copy of Lustre
15 * is open source software; you can redistribute it and/or modify it
16 * under the terms of version 2 of the GNU General Public License as
17 * published by the Free Software Foundation.
19 * In either case, Lustre is distributed in the hope that it will be
20 * useful, but WITHOUT ANY WARRANTY; without even the implied warranty
21 * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 * license text for more details.
28 #define DEBUG_SUBSYSTEM S_CLASS
30 #include <obd_class.h>
31 #include <linux/string.h>
33 #include <liblustre.h>
34 #include <obd_class.h>
37 #include <lustre_log.h>
38 #include <lprocfs_status.h>
39 #include <libcfs/list.h>
40 #include <lustre_param.h>
41 #include <class_hash.h>
43 extern struct lustre_hash_operations uuid_hash_operations;
44 extern struct lustre_hash_operations nid_hash_operations;
46 /*********** string parsing utils *********/
48 /* returns 0 if we find this key in the buffer, else 1 */
49 int class_find_param(char *buf, char *key, char **valp)
56 if ((ptr = strstr(buf, key)) == NULL)
60 *valp = ptr + strlen(key);
65 /* returns 0 if this is the first key in the buffer, else 1.
66 valp points to first char after key. */
67 int class_match_param(char *buf, char *key, char **valp)
72 if (memcmp(buf, key, strlen(key)) != 0)
76 *valp = buf + strlen(key);
84 endh is set to next separator */
85 int class_parse_nid(char *buf, lnet_nid_t *nid, char **endh)
91 while (*buf == ',' || *buf == ':')
93 if (*buf == ' ' || *buf == '/' || *buf == '\0')
96 /* nid separators or end of nids */
97 endp = strpbrk(buf, ",: /");
99 endp = buf + strlen(buf);
103 *nid = libcfs_str2nid(buf);
104 if (*nid == LNET_NID_ANY) {
105 LCONSOLE_ERROR_MSG(0x159, "Can't parse NID '%s'\n", buf);
113 CDEBUG(D_INFO, "Nid %s\n", libcfs_nid2str(*nid));
117 EXPORT_SYMBOL(class_find_param);
118 EXPORT_SYMBOL(class_match_param);
119 EXPORT_SYMBOL(class_parse_nid);
121 /********************** class fns **********************/
123 /* Create a new device and set the type, name and uuid. If
124 * successful, the new device can be accessed by either name or uuid.
126 int class_attach(struct lustre_cfg *lcfg)
128 struct obd_device *obd = NULL;
129 char *typename, *name, *uuid;
133 if (!LUSTRE_CFG_BUFLEN(lcfg, 1)) {
134 CERROR("No type passed!\n");
137 typename = lustre_cfg_string(lcfg, 1);
139 if (!LUSTRE_CFG_BUFLEN(lcfg, 0)) {
140 CERROR("No name passed!\n");
143 name = lustre_cfg_string(lcfg, 0);
145 if (!LUSTRE_CFG_BUFLEN(lcfg, 2)) {
146 CERROR("No UUID passed!\n");
149 uuid = lustre_cfg_string(lcfg, 2);
151 CDEBUG(D_IOCTL, "attach type %s name: %s uuid: %s\n",
152 MKSTR(typename), MKSTR(name), MKSTR(uuid));
154 obd = class_newdev(typename, name);
156 /* Already exists or out of obds */
159 CERROR("Cannot create device %s of type %s : %d\n",
163 LASSERTF(obd != NULL, "Cannot get obd device %s of type %s\n",
165 LASSERTF(obd->obd_magic == OBD_DEVICE_MAGIC,
166 "obd %p obd_magic %08X != %08X\n",
167 obd, obd->obd_magic, OBD_DEVICE_MAGIC);
168 LASSERTF(strncmp(obd->obd_name, name, strlen(name)) == 0, "%p obd_name %s != %s\n",
169 obd, obd->obd_name, name);
171 CFS_INIT_LIST_HEAD(&obd->obd_exports);
172 CFS_INIT_LIST_HEAD(&obd->obd_exports_timed);
173 spin_lock_init(&obd->obd_dev_lock);
174 sema_init(&obd->obd_dev_sem, 1);
175 sema_init(&obd->obd_proc_exp_sem, 1);
176 spin_lock_init(&obd->obd_osfs_lock);
177 /* obd->obd_osfs_age must be set to a value in the distant
178 * past to guarantee a fresh statfs is fetched on mount. */
179 obd->obd_osfs_age = cfs_time_shift_64(-1000);
181 /* XXX belongs in setup not attach */
183 cfs_init_timer(&obd->obd_recovery_timer);
184 spin_lock_init(&obd->obd_processing_task_lock);
185 cfs_waitq_init(&obd->obd_next_transno_waitq);
186 cfs_waitq_init(&obd->obd_evict_inprogress_waitq);
187 CFS_INIT_LIST_HEAD(&obd->obd_req_replay_queue);
188 CFS_INIT_LIST_HEAD(&obd->obd_lock_replay_queue);
189 CFS_INIT_LIST_HEAD(&obd->obd_final_req_queue);
191 spin_lock_init(&obd->obd_uncommitted_replies_lock);
192 CFS_INIT_LIST_HEAD(&obd->obd_uncommitted_replies);
195 if (len >= sizeof(obd->obd_uuid)) {
196 CERROR("uuid must be < "LPSZ" bytes long\n",
197 sizeof(obd->obd_uuid));
198 GOTO(out, rc = -EINVAL);
200 memcpy(obd->obd_uuid.uuid, uuid, len);
203 if (OBP(obd, attach)) {
204 rc = OBP(obd,attach)(obd, sizeof *lcfg, lcfg);
206 GOTO(out, rc = -EINVAL);
209 /* Detach drops this */
210 spin_lock(&obd->obd_dev_lock);
211 atomic_set(&obd->obd_refcount, 1);
212 spin_unlock(&obd->obd_dev_lock);
214 obd->obd_attached = 1;
215 CDEBUG(D_IOCTL, "OBD: dev %d attached type %s with refcount %d\n",
216 obd->obd_minor, typename, atomic_read(&obd->obd_refcount));
220 class_release_dev(obd);
225 int class_setup(struct obd_device *obd, struct lustre_cfg *lcfg)
228 struct obd_export *exp;
231 LASSERT(obd != NULL);
232 LASSERTF(obd == class_num2obd(obd->obd_minor), "obd %p != obd_devs[%d] %p\n",
233 obd, obd->obd_minor, class_num2obd(obd->obd_minor));
234 LASSERTF(obd->obd_magic == OBD_DEVICE_MAGIC, "obd %p obd_magic %08x != %08x\n",
235 obd, obd->obd_magic, OBD_DEVICE_MAGIC);
237 /* have we attached a type to this device? */
238 if (!obd->obd_attached) {
239 CERROR("Device %d not attached\n", obd->obd_minor);
243 if (obd->obd_set_up) {
244 CERROR("Device %d already setup (type %s)\n",
245 obd->obd_minor, obd->obd_type->typ_name);
249 /* is someone else setting us up right now? (attach inits spinlock) */
250 spin_lock(&obd->obd_dev_lock);
251 if (obd->obd_starting) {
252 spin_unlock(&obd->obd_dev_lock);
253 CERROR("Device %d setup in progress (type %s)\n",
254 obd->obd_minor, obd->obd_type->typ_name);
257 /* just leave this on forever. I can't use obd_set_up here because
258 other fns check that status, and we're not actually set up yet. */
259 obd->obd_starting = 1;
260 spin_unlock(&obd->obd_dev_lock);
262 /* create an uuid-export hash body */
263 err = lustre_hash_init(&obd->obd_uuid_hash_body, "UUID_HASH",
264 128, &uuid_hash_operations);
269 /* create a nid-export hash body */
270 err = lustre_hash_init(&obd->obd_nid_hash_body, "NID_HASH",
271 128, &nid_hash_operations);
275 exp = class_new_export(obd, &obd->obd_uuid);
277 RETURN(PTR_ERR(exp));
278 obd->obd_self_export = exp;
279 list_del_init(&exp->exp_obd_chain_timed);
280 class_export_put(exp);
282 err = obd_setup(obd, lcfg);
288 spin_lock(&obd->obd_dev_lock);
289 /* cleanup drops this */
291 spin_unlock(&obd->obd_dev_lock);
293 CDEBUG(D_IOCTL, "finished setup of obd %s (uuid %s)\n",
294 obd->obd_name, obd->obd_uuid.uuid);
299 class_unlink_export(obd->obd_self_export);
300 obd->obd_self_export = NULL;
302 lustre_hash_exit(&obd->obd_uuid_hash_body);
303 lustre_hash_exit(&obd->obd_nid_hash_body);
304 obd->obd_starting = 0;
305 CERROR("setup %s failed (%d)\n", obd->obd_name, err);
309 int class_detach(struct obd_device *obd, struct lustre_cfg *lcfg)
313 if (obd->obd_set_up) {
314 CERROR("OBD device %d still set up\n", obd->obd_minor);
318 spin_lock(&obd->obd_dev_lock);
319 if (!obd->obd_attached) {
320 spin_unlock(&obd->obd_dev_lock);
321 CERROR("OBD device %d not attached\n", obd->obd_minor);
324 obd->obd_attached = 0;
325 spin_unlock(&obd->obd_dev_lock);
327 CDEBUG(D_IOCTL, "detach on obd %s (uuid %s)\n",
328 obd->obd_name, obd->obd_uuid.uuid);
332 /* not strictly necessary, but cleans up eagerly */
333 obd_zombie_impexp_cull();
338 static void dump_exports(struct obd_device *obd)
340 struct obd_export *exp, *n;
342 list_for_each_entry_safe(exp, n, &obd->obd_exports, exp_obd_chain) {
343 struct ptlrpc_reply_state *rs;
344 struct ptlrpc_reply_state *first_reply = NULL;
347 list_for_each_entry (rs, &exp->exp_outstanding_replies,
354 CDEBUG(D_IOCTL, "%s: %p %s %s %d %d %d: %p %s\n",
355 obd->obd_name, exp, exp->exp_client_uuid.uuid,
356 obd_export_nid2str(exp),
357 atomic_read(&exp->exp_refcount),
358 exp->exp_failed, nreplies, first_reply,
359 nreplies > 3 ? "..." : "");
363 int class_cleanup(struct obd_device *obd, struct lustre_cfg *lcfg)
369 OBD_RACE(OBD_FAIL_LDLM_RECOV_CLIENTS);
371 if (!obd->obd_set_up) {
372 CERROR("Device %d not setup\n", obd->obd_minor);
376 spin_lock(&obd->obd_dev_lock);
377 if (obd->obd_stopping) {
378 spin_unlock(&obd->obd_dev_lock);
379 CERROR("OBD %d already stopping\n", obd->obd_minor);
382 /* Leave this on forever */
383 obd->obd_stopping = 1;
384 spin_unlock(&obd->obd_dev_lock);
386 if (lcfg->lcfg_bufcount >= 2 && LUSTRE_CFG_BUFLEN(lcfg, 1) > 0) {
387 for (flag = lustre_cfg_string(lcfg, 1); *flag != 0; flag++)
393 LCONSOLE_WARN("Failing over %s\n",
396 obd->obd_no_transno = 1;
397 obd->obd_no_recov = 1;
398 /* Set the obd readonly if we can */
399 if (OBP(obd, iocontrol))
400 obd_iocontrol(OBD_IOC_SET_READONLY,
401 obd->obd_self_export,
405 CERROR("unrecognised flag '%c'\n",
410 /* The three references that should be remaining are the
411 * obd_self_export and the attach and setup references. */
412 if (atomic_read(&obd->obd_refcount) > 3) {
413 #if 0 /* We should never fail to cleanup with mountconf */
414 if (!(obd->obd_fail || obd->obd_force)) {
415 CERROR("OBD %s is still busy with %d references\n"
416 "You should stop active file system users,"
417 " or use the --force option to cleanup.\n",
418 obd->obd_name, atomic_read(&obd->obd_refcount));
420 /* Allow a failed cleanup to try again. */
421 obd->obd_stopping = 0;
424 /* refcounf - 3 might be the number of real exports
425 (excluding self export). But class_incref is called
426 by other things as well, so don't count on it. */
427 CDEBUG(D_IOCTL, "%s: forcing exports to disconnect: %d\n",
428 obd->obd_name, atomic_read(&obd->obd_refcount) - 3);
430 class_disconnect_exports(obd);
432 LASSERT(obd->obd_self_export);
434 /* destroy an uuid-export hash body */
435 lustre_hash_exit(&obd->obd_uuid_hash_body);
437 /* destroy a nid-export hash body */
438 lustre_hash_exit(&obd->obd_nid_hash_body);
440 /* Precleanup stage 1, we must make sure all exports (other than the
441 self-export) get destroyed. */
442 err = obd_precleanup(obd, OBD_CLEANUP_EXPORTS);
444 CERROR("Precleanup %s returned %d\n",
452 struct obd_device *class_incref(struct obd_device *obd)
454 atomic_inc(&obd->obd_refcount);
455 CDEBUG(D_INFO, "incref %s (%p) now %d\n", obd->obd_name, obd,
456 atomic_read(&obd->obd_refcount));
461 void class_decref(struct obd_device *obd)
466 spin_lock(&obd->obd_dev_lock);
467 atomic_dec(&obd->obd_refcount);
468 refs = atomic_read(&obd->obd_refcount);
469 spin_unlock(&obd->obd_dev_lock);
471 CDEBUG(D_INFO, "Decref %s (%p) now %d\n", obd->obd_name, obd, refs);
473 if ((refs == 1) && obd->obd_stopping) {
474 /* All exports (other than the self-export) have been
475 destroyed; there should be no more in-progress ops
477 /* if we're not stopping, we didn't finish setup */
478 /* Precleanup stage 2, do other type-specific
479 cleanup requiring the self-export. */
480 err = obd_precleanup(obd, OBD_CLEANUP_SELF_EXP);
482 CERROR("Precleanup %s returned %d\n",
485 spin_lock(&obd->obd_self_export->exp_lock);
486 obd->obd_self_export->exp_flags |=
487 (obd->obd_fail ? OBD_OPT_FAILOVER : 0) |
488 (obd->obd_force ? OBD_OPT_FORCE : 0);
489 spin_unlock(&obd->obd_self_export->exp_lock);
491 /* note that we'll recurse into class_decref again */
492 class_unlink_export(obd->obd_self_export);
497 CDEBUG(D_CONFIG, "finishing cleanup of obd %s (%s)\n",
498 obd->obd_name, obd->obd_uuid.uuid);
499 LASSERT(!obd->obd_attached);
500 if (obd->obd_stopping) {
501 /* If we're not stopping, we were never set up */
502 err = obd_cleanup(obd);
504 CERROR("Cleanup %s returned %d\n",
507 if (OBP(obd, detach)) {
508 err = OBP(obd,detach)(obd);
510 CERROR("Detach returned %d\n", err);
512 class_release_dev(obd);
516 int class_add_conn(struct obd_device *obd, struct lustre_cfg *lcfg)
518 struct obd_import *imp;
519 struct obd_uuid uuid;
523 if (LUSTRE_CFG_BUFLEN(lcfg, 1) < 1 ||
524 LUSTRE_CFG_BUFLEN(lcfg, 1) > sizeof(struct obd_uuid)) {
525 CERROR("invalid conn_uuid\n");
528 if (strcmp(obd->obd_type->typ_name, LUSTRE_MDC_NAME) &&
529 strcmp(obd->obd_type->typ_name, LUSTRE_OSC_NAME) &&
530 strcmp(obd->obd_type->typ_name, LUSTRE_MGC_NAME)) {
531 CERROR("can't add connection on non-client dev\n");
535 imp = obd->u.cli.cl_import;
537 CERROR("try to add conn on immature client dev\n");
541 obd_str2uuid(&uuid, lustre_cfg_string(lcfg, 1));
542 rc = obd_add_conn(imp, &uuid, lcfg->lcfg_num);
547 int class_del_conn(struct obd_device *obd, struct lustre_cfg *lcfg)
549 struct obd_import *imp;
550 struct obd_uuid uuid;
554 if (LUSTRE_CFG_BUFLEN(lcfg, 1) < 1 ||
555 LUSTRE_CFG_BUFLEN(lcfg, 1) > sizeof(struct obd_uuid)) {
556 CERROR("invalid conn_uuid\n");
559 if (strcmp(obd->obd_type->typ_name, LUSTRE_MDC_NAME) &&
560 strcmp(obd->obd_type->typ_name, LUSTRE_OSC_NAME)) {
561 CERROR("can't del connection on non-client dev\n");
565 imp = obd->u.cli.cl_import;
567 CERROR("try to del conn on immature client dev\n");
571 obd_str2uuid(&uuid, lustre_cfg_string(lcfg, 1));
572 rc = obd_del_conn(imp, &uuid);
577 CFS_LIST_HEAD(lustre_profile_list);
579 struct lustre_profile *class_get_profile(const char * prof)
581 struct lustre_profile *lprof;
584 list_for_each_entry(lprof, &lustre_profile_list, lp_list) {
585 if (!strcmp(lprof->lp_profile, prof)) {
592 int class_add_profile(int proflen, char *prof, int osclen, char *osc,
593 int mdclen, char *mdc)
595 struct lustre_profile *lprof;
599 CDEBUG(D_CONFIG, "Add profile %s\n", prof);
601 OBD_ALLOC(lprof, sizeof(*lprof));
604 CFS_INIT_LIST_HEAD(&lprof->lp_list);
606 LASSERT(proflen == (strlen(prof) + 1));
607 OBD_ALLOC(lprof->lp_profile, proflen);
608 if (lprof->lp_profile == NULL)
609 GOTO(out, err = -ENOMEM);
610 memcpy(lprof->lp_profile, prof, proflen);
612 LASSERT(osclen == (strlen(osc) + 1));
613 OBD_ALLOC(lprof->lp_dt, osclen);
614 if (lprof->lp_dt == NULL)
615 GOTO(out, err = -ENOMEM);
616 memcpy(lprof->lp_dt, osc, osclen);
619 LASSERT(mdclen == (strlen(mdc) + 1));
620 OBD_ALLOC(lprof->lp_md, mdclen);
621 if (lprof->lp_md == NULL)
622 GOTO(out, err = -ENOMEM);
623 memcpy(lprof->lp_md, mdc, mdclen);
626 list_add(&lprof->lp_list, &lustre_profile_list);
631 OBD_FREE(lprof->lp_md, mdclen);
633 OBD_FREE(lprof->lp_dt, osclen);
634 if (lprof->lp_profile)
635 OBD_FREE(lprof->lp_profile, proflen);
636 OBD_FREE(lprof, sizeof(*lprof));
640 void class_del_profile(const char *prof)
642 struct lustre_profile *lprof;
645 CDEBUG(D_CONFIG, "Del profile %s\n", prof);
647 lprof = class_get_profile(prof);
649 list_del(&lprof->lp_list);
650 OBD_FREE(lprof->lp_profile, strlen(lprof->lp_profile) + 1);
651 OBD_FREE(lprof->lp_dt, strlen(lprof->lp_dt) + 1);
653 OBD_FREE(lprof->lp_md, strlen(lprof->lp_md) + 1);
654 OBD_FREE(lprof, sizeof *lprof);
660 void class_del_profiles(void)
662 struct lustre_profile *lprof, *n;
665 list_for_each_entry_safe(lprof, n, &lustre_profile_list, lp_list) {
666 list_del(&lprof->lp_list);
667 OBD_FREE(lprof->lp_profile, strlen(lprof->lp_profile) + 1);
668 OBD_FREE(lprof->lp_dt, strlen(lprof->lp_dt) + 1);
670 OBD_FREE(lprof->lp_md, strlen(lprof->lp_md) + 1);
671 OBD_FREE(lprof, sizeof *lprof);
676 /* We can't call ll_process_config directly because it lives in a module that
677 must be loaded after this one. */
678 static int (*client_process_config)(struct lustre_cfg *lcfg) = NULL;
680 void lustre_register_client_process_config(int (*cpc)(struct lustre_cfg *lcfg))
682 client_process_config = cpc;
684 EXPORT_SYMBOL(lustre_register_client_process_config);
686 int class_process_config(struct lustre_cfg *lcfg)
688 struct obd_device *obd;
691 LASSERT(lcfg && !IS_ERR(lcfg));
692 CDEBUG(D_IOCTL, "processing cmd: %x\n", lcfg->lcfg_command);
694 /* Commands that don't need a device */
695 switch(lcfg->lcfg_command) {
697 err = class_attach(lcfg);
700 case LCFG_ADD_UUID: {
701 CDEBUG(D_IOCTL, "adding mapping from uuid %s to nid "LPX64
702 " (%s)\n", lustre_cfg_string(lcfg, 1),
703 lcfg->lcfg_nid, libcfs_nid2str(lcfg->lcfg_nid));
705 err = class_add_uuid(lustre_cfg_string(lcfg, 1), lcfg->lcfg_nid);
708 case LCFG_DEL_UUID: {
709 CDEBUG(D_IOCTL, "removing mappings for uuid %s\n",
710 (lcfg->lcfg_bufcount < 2 || LUSTRE_CFG_BUFLEN(lcfg, 1) == 0)
711 ? "<all uuids>" : lustre_cfg_string(lcfg, 1));
713 err = class_del_uuid(lustre_cfg_string(lcfg, 1));
716 case LCFG_MOUNTOPT: {
717 CDEBUG(D_IOCTL, "mountopt: profile %s osc %s mdc %s\n",
718 lustre_cfg_string(lcfg, 1),
719 lustre_cfg_string(lcfg, 2),
720 lustre_cfg_string(lcfg, 3));
721 /* set these mount options somewhere, so ll_fill_super
723 err = class_add_profile(LUSTRE_CFG_BUFLEN(lcfg, 1),
724 lustre_cfg_string(lcfg, 1),
725 LUSTRE_CFG_BUFLEN(lcfg, 2),
726 lustre_cfg_string(lcfg, 2),
727 LUSTRE_CFG_BUFLEN(lcfg, 3),
728 lustre_cfg_string(lcfg, 3));
731 case LCFG_DEL_MOUNTOPT: {
732 CDEBUG(D_IOCTL, "mountopt: profile %s\n",
733 lustre_cfg_string(lcfg, 1));
734 class_del_profile(lustre_cfg_string(lcfg, 1));
737 case LCFG_SET_TIMEOUT: {
738 CDEBUG(D_IOCTL, "changing lustre timeout from %d to %d\n",
739 obd_timeout, lcfg->lcfg_num);
740 obd_timeout = max(lcfg->lcfg_num, 1U);
741 obd_health_check_timeout = HEALTH_CHECK_TIMEOUT;
744 case LCFG_SET_UPCALL: {
745 LCONSOLE_ERROR_MSG(0x15a, "recovery upcall is deprecated\n");
746 /* COMPAT_146 Don't fail on old configs */
750 struct cfg_marker *marker;
751 marker = lustre_cfg_buf(lcfg, 1);
752 CDEBUG(D_IOCTL, "marker %d (%#x) %.16s %s\n", marker->cm_step,
753 marker->cm_flags, marker->cm_tgtname, marker->cm_comment);
757 /* llite has no obd */
758 if ((class_match_param(lustre_cfg_string(lcfg, 1),
759 PARAM_LLITE, 0) == 0) &&
760 client_process_config) {
761 err = (*client_process_config)(lcfg);
769 /* Commands that require a device */
770 obd = class_name2obd(lustre_cfg_string(lcfg, 0));
772 if (!LUSTRE_CFG_BUFLEN(lcfg, 0))
773 CERROR("this lcfg command requires a device name\n");
775 CERROR("no device for: %s\n",
776 lustre_cfg_string(lcfg, 0));
778 GOTO(out, err = -EINVAL);
781 switch(lcfg->lcfg_command) {
783 err = class_setup(obd, lcfg);
787 err = class_detach(obd, lcfg);
791 err = class_cleanup(obd, lcfg);
794 case LCFG_ADD_CONN: {
795 err = class_add_conn(obd, lcfg);
798 case LCFG_DEL_CONN: {
799 err = class_del_conn(obd, lcfg);
803 err = obd_process_config(obd, sizeof(*lcfg), lcfg);
809 if ((err < 0) && !(lcfg->lcfg_command & LCFG_REQUIRED)) {
810 CWARN("Ignoring error %d on optional command %#x\n", err,
817 int class_process_proc_param(char *prefix, struct lprocfs_vars *lvars,
818 struct lustre_cfg *lcfg, void *data)
821 struct lprocfs_vars *var;
823 int i, keylen, vallen;
824 int matched = 0, j = 0;
828 if (lcfg->lcfg_command != LCFG_PARAM) {
829 CERROR("Unknown command: %d\n", lcfg->lcfg_command);
833 /* e.g. tunefs.lustre --param mdt.group_upcall=foo /r/tmp/lustre-mdt
834 or lctl conf_param lustre-MDT0000.mdt.group_upcall=bar
835 or lctl conf_param lustre-OST0000.osc.max_dirty_mb=36 */
836 for (i = 1; i < lcfg->lcfg_bufcount; i++) {
837 key = lustre_cfg_buf(lcfg, i);
838 /* Strip off prefix */
839 class_match_param(key, prefix, &key);
840 sval = strchr(key, '=');
841 if (!sval || (*(sval + 1) == 0)) {
842 CERROR("Can't parse param %s\n", key);
844 /* continue parsing other params */
849 vallen = strlen(sval);
852 /* Search proc entries */
853 while (lvars[j].name) {
855 if (class_match_param(key, (char *)var->name, 0) == 0 &&
856 keylen == strlen(var->name)) {
859 if (var->write_fptr) {
863 rc = (var->write_fptr)(NULL, sval,
868 CERROR("writing proc entry %s err %d\n",
875 CERROR("%s: unknown param %s\n",
876 (char *)lustre_cfg_string(lcfg, 0), key);
878 /* continue parsing other params */
880 LCONSOLE_INFO("%s.%.*s: set parameter %.*s=%s\n",
881 (char *)lustre_cfg_string(lcfg, 0),
882 (int)strlen(prefix) - 1, prefix,
883 (int)(sval - key - 1), key, sval);
891 CDEBUG(D_CONFIG, "liblustre can't process params.\n");
892 /* Don't throw config error */
897 int class_config_dump_handler(struct llog_handle * handle,
898 struct llog_rec_hdr *rec, void *data);
901 extern int lustre_check_exclusion(struct super_block *sb, char *svname);
903 #define lustre_check_exclusion(a,b) 0
906 static int class_config_llog_handler(struct llog_handle * handle,
907 struct llog_rec_hdr *rec, void *data)
909 struct config_llog_instance *clli = data;
910 int cfg_len = rec->lrh_len;
911 char *cfg_buf = (char*) (rec + 1);
915 //class_config_dump_handler(handle, rec, data);
917 switch (rec->lrh_type) {
919 struct lustre_cfg *lcfg, *lcfg_new;
920 struct lustre_cfg_bufs bufs;
921 char *inst_name = NULL;
925 lcfg = (struct lustre_cfg *)cfg_buf;
926 if (lcfg->lcfg_version == __swab32(LUSTRE_CFG_VERSION))
927 lustre_swab_lustre_cfg(lcfg);
929 rc = lustre_cfg_sanity_check(cfg_buf, cfg_len);
933 /* Figure out config state info */
934 if (lcfg->lcfg_command == LCFG_MARKER) {
935 struct cfg_marker *marker = lustre_cfg_buf(lcfg, 1);
936 CDEBUG(D_CONFIG, "Marker, inst_flg=%#x mark_flg=%#x\n",
937 clli->cfg_flags, marker->cm_flags);
938 if (marker->cm_flags & CM_START) {
939 /* all previous flags off */
940 clli->cfg_flags = CFG_F_MARKER;
941 if (marker->cm_flags & CM_SKIP) {
942 clli->cfg_flags |= CFG_F_SKIP;
943 CDEBUG(D_CONFIG, "SKIP #%d\n",
945 } else if ((marker->cm_flags & CM_EXCLUDE) ||
946 lustre_check_exclusion(clli->cfg_sb,
947 marker->cm_tgtname)) {
948 clli->cfg_flags |= CFG_F_EXCLUDE;
949 CDEBUG(D_CONFIG, "EXCLUDE %d\n",
952 } else if (marker->cm_flags & CM_END) {
956 /* A config command without a start marker before it is
957 illegal (post 146) */
958 if (!(clli->cfg_flags & CFG_F_COMPAT146) &&
959 !(clli->cfg_flags & CFG_F_MARKER) &&
960 (lcfg->lcfg_command != LCFG_MARKER)) {
961 CWARN("Config not inside markers, ignoring! "
962 "(inst: %s, uuid: %s, flags: %#x)\n",
963 clli->cfg_instance ? clli->cfg_instance : "<null>",
964 clli->cfg_uuid.uuid, clli->cfg_flags);
965 clli->cfg_flags |= CFG_F_SKIP;
967 if (clli->cfg_flags & CFG_F_SKIP) {
968 CDEBUG(D_CONFIG, "skipping %#x\n",
975 if ((clli->cfg_flags & CFG_F_EXCLUDE) &&
976 (lcfg->lcfg_command == LCFG_LOV_ADD_OBD))
977 /* Add inactive instead */
978 lcfg->lcfg_command = LCFG_LOV_ADD_INA;
980 lustre_cfg_bufs_init(&bufs, lcfg);
982 if (clli && clli->cfg_instance &&
983 LUSTRE_CFG_BUFLEN(lcfg, 0) > 0){
985 inst_len = LUSTRE_CFG_BUFLEN(lcfg, 0) +
986 strlen(clli->cfg_instance) + 1;
987 OBD_ALLOC(inst_name, inst_len);
988 if (inst_name == NULL)
989 GOTO(out, rc = -ENOMEM);
990 sprintf(inst_name, "%s-%s",
991 lustre_cfg_string(lcfg, 0),
993 lustre_cfg_bufs_set_string(&bufs, 0, inst_name);
994 CDEBUG(D_CONFIG, "cmd %x, instance name: %s\n",
995 lcfg->lcfg_command, inst_name);
998 /* we override the llog's uuid for clients, to insure they
1000 if (clli && clli->cfg_instance &&
1001 lcfg->lcfg_command == LCFG_ATTACH) {
1002 lustre_cfg_bufs_set_string(&bufs, 2,
1003 clli->cfg_uuid.uuid);
1006 lcfg_new = lustre_cfg_new(lcfg->lcfg_command, &bufs);
1008 lcfg_new->lcfg_num = lcfg->lcfg_num;
1009 lcfg_new->lcfg_flags = lcfg->lcfg_flags;
1011 /* XXX Hack to try to remain binary compatible with
1012 * pre-newconfig logs */
1013 if (lcfg->lcfg_nal != 0 && /* pre-newconfig log? */
1014 (lcfg->lcfg_nid >> 32) == 0) {
1015 __u32 addr = (__u32)(lcfg->lcfg_nid & 0xffffffff);
1017 lcfg_new->lcfg_nid =
1018 LNET_MKNID(LNET_MKNET(lcfg->lcfg_nal, 0), addr);
1019 CWARN("Converted pre-newconfig NAL %d NID %x to %s\n",
1020 lcfg->lcfg_nal, addr,
1021 libcfs_nid2str(lcfg_new->lcfg_nid));
1023 lcfg_new->lcfg_nid = lcfg->lcfg_nid;
1026 lcfg_new->lcfg_nal = 0; /* illegal value for obsolete field */
1028 rc = class_process_config(lcfg_new);
1029 lustre_cfg_free(lcfg_new);
1032 OBD_FREE(inst_name, inst_len);
1036 CERROR("Unknown llog record type %#x encountered\n",
1042 CERROR("Err %d on cfg command:\n", rc);
1043 class_config_dump_handler(handle, rec, data);
1048 int class_config_parse_llog(struct llog_ctxt *ctxt, char *name,
1049 struct config_llog_instance *cfg)
1051 struct llog_process_cat_data cd = {0, 0};
1052 struct llog_handle *llh;
1056 CDEBUG(D_INFO, "looking up llog %s\n", name);
1057 rc = llog_create(ctxt, &llh, NULL, name);
1061 rc = llog_init_handle(llh, LLOG_F_IS_PLAIN, NULL);
1063 GOTO(parse_out, rc);
1065 /* continue processing from where we last stopped to end-of-log */
1067 cd.first_idx = cfg->cfg_last_idx;
1070 rc = llog_process(llh, class_config_llog_handler, cfg, &cd);
1072 CDEBUG(D_CONFIG, "Processed log %s gen %d-%d (rc=%d)\n", name,
1073 cd.first_idx + 1, cd.last_idx, rc);
1076 cfg->cfg_last_idx = cd.last_idx;
1079 rc2 = llog_close(llh);
1086 int class_config_dump_handler(struct llog_handle * handle,
1087 struct llog_rec_hdr *rec, void *data)
1089 int cfg_len = rec->lrh_len;
1090 char *cfg_buf = (char*) (rec + 1);
1091 char *outstr, *ptr, *end;
1095 OBD_ALLOC(outstr, 256);
1101 if (rec->lrh_type == OBD_CFG_REC) {
1102 struct lustre_cfg *lcfg;
1105 rc = lustre_cfg_sanity_check(cfg_buf, cfg_len);
1108 lcfg = (struct lustre_cfg *)cfg_buf;
1110 ptr += snprintf(ptr, end-ptr, "cmd=%05x ",
1111 lcfg->lcfg_command);
1112 if (lcfg->lcfg_flags) {
1113 ptr += snprintf(ptr, end-ptr, "flags=%#08x ",
1116 if (lcfg->lcfg_num) {
1117 ptr += snprintf(ptr, end-ptr, "num=%#08x ",
1120 if (lcfg->lcfg_nid) {
1121 ptr += snprintf(ptr, end-ptr, "nid=%s("LPX64")\n ",
1122 libcfs_nid2str(lcfg->lcfg_nid),
1125 if (lcfg->lcfg_command == LCFG_MARKER) {
1126 struct cfg_marker *marker = lustre_cfg_buf(lcfg, 1);
1127 ptr += snprintf(ptr, end-ptr, "marker=%d(%#x)%s '%s'",
1128 marker->cm_step, marker->cm_flags,
1129 marker->cm_tgtname, marker->cm_comment);
1131 for (i = 0; i < lcfg->lcfg_bufcount; i++) {
1132 ptr += snprintf(ptr, end-ptr, "%d:%s ", i,
1133 lustre_cfg_string(lcfg, i));
1136 LCONSOLE(D_WARNING, " %s\n", outstr);
1138 LCONSOLE(D_WARNING, "unhandled lrh_type: %#x\n", rec->lrh_type);
1142 OBD_FREE(outstr, 256);
1146 int class_config_dump_llog(struct llog_ctxt *ctxt, char *name,
1147 struct config_llog_instance *cfg)
1149 struct llog_handle *llh;
1153 LCONSOLE_INFO("Dumping config log %s\n", name);
1155 rc = llog_create(ctxt, &llh, NULL, name);
1159 rc = llog_init_handle(llh, LLOG_F_IS_PLAIN, NULL);
1161 GOTO(parse_out, rc);
1163 rc = llog_process(llh, class_config_dump_handler, cfg, NULL);
1165 rc2 = llog_close(llh);
1169 LCONSOLE_INFO("End config log %s\n", name);
1174 /* Cleanup and detach */
1175 int class_manual_cleanup(struct obd_device *obd)
1177 struct lustre_cfg *lcfg;
1178 struct lustre_cfg_bufs bufs;
1184 CERROR("empty cleanup\n");
1193 CDEBUG(D_CONFIG, "Manual cleanup of %s (flags='%s')\n",
1194 obd->obd_name, flags);
1196 lustre_cfg_bufs_reset(&bufs, obd->obd_name);
1197 lustre_cfg_bufs_set_string(&bufs, 1, flags);
1198 lcfg = lustre_cfg_new(LCFG_CLEANUP, &bufs);
1200 rc = class_process_config(lcfg);
1202 CERROR("cleanup failed %d: %s\n", rc, obd->obd_name);
1206 /* the lcfg is almost the same for both ops */
1207 lcfg->lcfg_command = LCFG_DETACH;
1208 rc = class_process_config(lcfg);
1210 CERROR("detach failed %d: %s\n", rc, obd->obd_name);
1212 lustre_cfg_free(lcfg);