1 /* -*- mode: c; c-basic-offset: 8; indent-tabs-mode: nil; -*-
2 * vim:expandtab:shiftwidth=8:tabstop=8:
6 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License version 2 only,
10 * as published by the Free Software Foundation.
12 * This program is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * General Public License version 2 for more details (a copy is included
16 * in the LICENSE file that accompanied this code).
18 * You should have received a copy of the GNU General Public License
19 * version 2 along with this program; If not, see
20 * http://www.sun.com/software/products/lustre/docs/GPLv2.pdf
22 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
23 * CA 95054 USA or visit www.sun.com if you need additional information or
29 * Copyright 2008 Sun Microsystems, Inc. All rights reserved
30 * Use is subject to license terms.
33 * This file is part of Lustre, http://www.lustre.org/
34 * Lustre is a trademark of Sun Microsystems, Inc.
36 * lustre/obdclass/obd_config.c
41 #define DEBUG_SUBSYSTEM S_CLASS
43 #include <obd_class.h>
44 #include <linux/string.h>
46 #include <liblustre.h>
47 #include <obd_class.h>
50 #include <lustre_log.h>
51 #include <lprocfs_status.h>
52 #include <libcfs/list.h>
53 #include <lustre_param.h>
54 #include <class_hash.h>
56 extern struct lustre_hash_operations uuid_hash_operations;
57 extern struct lustre_hash_operations nid_hash_operations;
59 /*********** string parsing utils *********/
61 /* returns 0 if we find this key in the buffer, else 1 */
62 int class_find_param(char *buf, char *key, char **valp)
69 if ((ptr = strstr(buf, key)) == NULL)
73 *valp = ptr + strlen(key);
78 /* returns 0 if this is the first key in the buffer, else 1.
79 valp points to first char after key. */
80 int class_match_param(char *buf, char *key, char **valp)
85 if (memcmp(buf, key, strlen(key)) != 0)
89 *valp = buf + strlen(key);
97 endh is set to next separator */
98 int class_parse_nid(char *buf, lnet_nid_t *nid, char **endh)
104 while (*buf == ',' || *buf == ':')
106 if (*buf == ' ' || *buf == '/' || *buf == '\0')
109 /* nid separators or end of nids */
110 endp = strpbrk(buf, ",: /");
112 endp = buf + strlen(buf);
116 *nid = libcfs_str2nid(buf);
117 if (*nid == LNET_NID_ANY) {
118 LCONSOLE_ERROR_MSG(0x159, "Can't parse NID '%s'\n", buf);
126 CDEBUG(D_INFO, "Nid %s\n", libcfs_nid2str(*nid));
130 EXPORT_SYMBOL(class_find_param);
131 EXPORT_SYMBOL(class_match_param);
132 EXPORT_SYMBOL(class_parse_nid);
134 /********************** class fns **********************/
137 * Create a new device and set the type, name and uuid. If successful, the new
138 * device can be accessed by either name or uuid.
140 int class_attach(struct lustre_cfg *lcfg)
142 struct obd_device *obd = NULL;
143 char *typename, *name, *uuid;
147 if (!LUSTRE_CFG_BUFLEN(lcfg, 1)) {
148 CERROR("No type passed!\n");
151 typename = lustre_cfg_string(lcfg, 1);
153 if (!LUSTRE_CFG_BUFLEN(lcfg, 0)) {
154 CERROR("No name passed!\n");
157 name = lustre_cfg_string(lcfg, 0);
159 if (!LUSTRE_CFG_BUFLEN(lcfg, 2)) {
160 CERROR("No UUID passed!\n");
163 uuid = lustre_cfg_string(lcfg, 2);
165 CDEBUG(D_IOCTL, "attach type %s name: %s uuid: %s\n",
166 MKSTR(typename), MKSTR(name), MKSTR(uuid));
168 obd = class_newdev(typename, name);
170 /* Already exists or out of obds */
173 CERROR("Cannot create device %s of type %s : %d\n",
177 LASSERTF(obd != NULL, "Cannot get obd device %s of type %s\n",
179 LASSERTF(obd->obd_magic == OBD_DEVICE_MAGIC,
180 "obd %p obd_magic %08X != %08X\n",
181 obd, obd->obd_magic, OBD_DEVICE_MAGIC);
182 LASSERTF(strncmp(obd->obd_name, name, strlen(name)) == 0, "%p obd_name %s != %s\n",
183 obd, obd->obd_name, name);
185 rwlock_init(&obd->obd_pool_lock);
186 obd->obd_pool_limit = 0;
187 obd->obd_pool_slv = 0;
189 CFS_INIT_LIST_HEAD(&obd->obd_exports);
190 CFS_INIT_LIST_HEAD(&obd->obd_exports_timed);
191 CFS_INIT_LIST_HEAD(&obd->obd_nid_stats);
192 spin_lock_init(&obd->obd_nid_lock);
193 spin_lock_init(&obd->obd_dev_lock);
194 sema_init(&obd->obd_dev_sem, 1);
195 spin_lock_init(&obd->obd_osfs_lock);
196 /* obd->obd_osfs_age must be set to a value in the distant
197 * past to guarantee a fresh statfs is fetched on mount. */
198 obd->obd_osfs_age = cfs_time_shift_64(-1000);
200 /* XXX belongs in setup not attach */
202 cfs_init_timer(&obd->obd_recovery_timer);
203 spin_lock_init(&obd->obd_processing_task_lock);
204 cfs_waitq_init(&obd->obd_next_transno_waitq);
205 cfs_waitq_init(&obd->obd_evict_inprogress_waitq);
206 CFS_INIT_LIST_HEAD(&obd->obd_req_replay_queue);
207 CFS_INIT_LIST_HEAD(&obd->obd_lock_replay_queue);
208 CFS_INIT_LIST_HEAD(&obd->obd_final_req_queue);
210 llog_group_init(&obd->obd_olg, OBD_LLOG_GROUP);
212 spin_lock_init(&obd->obd_uncommitted_replies_lock);
213 CFS_INIT_LIST_HEAD(&obd->obd_uncommitted_replies);
216 if (len >= sizeof(obd->obd_uuid)) {
217 CERROR("uuid must be < %d bytes long\n",
218 (int)sizeof(obd->obd_uuid));
219 GOTO(out, rc = -EINVAL);
221 memcpy(obd->obd_uuid.uuid, uuid, len);
224 if (OBP(obd, attach)) {
225 rc = OBP(obd,attach)(obd, sizeof *lcfg, lcfg);
227 GOTO(out, rc = -EINVAL);
230 /* Detach drops this */
231 spin_lock(&obd->obd_dev_lock);
232 atomic_set(&obd->obd_refcount, 1);
233 spin_unlock(&obd->obd_dev_lock);
235 obd->obd_attached = 1;
236 CDEBUG(D_IOCTL, "OBD: dev %d attached type %s with refcount %d\n",
237 obd->obd_minor, typename, atomic_read(&obd->obd_refcount));
241 class_release_dev(obd);
246 int class_setup(struct obd_device *obd, struct lustre_cfg *lcfg)
249 struct obd_export *exp;
252 LASSERT(obd != NULL);
253 LASSERTF(obd == class_num2obd(obd->obd_minor),
254 "obd %p != obd_devs[%d] %p\n",
255 obd, obd->obd_minor, class_num2obd(obd->obd_minor));
256 LASSERTF(obd->obd_magic == OBD_DEVICE_MAGIC,
257 "obd %p obd_magic %08x != %08x\n",
258 obd, obd->obd_magic, OBD_DEVICE_MAGIC);
260 /* have we attached a type to this device? */
261 if (!obd->obd_attached) {
262 CERROR("Device %d not attached\n", obd->obd_minor);
266 if (obd->obd_set_up) {
267 CERROR("Device %d already setup (type %s)\n",
268 obd->obd_minor, obd->obd_type->typ_name);
272 /* is someone else setting us up right now? (attach inits spinlock) */
273 spin_lock(&obd->obd_dev_lock);
274 if (obd->obd_starting) {
275 spin_unlock(&obd->obd_dev_lock);
276 CERROR("Device %d setup in progress (type %s)\n",
277 obd->obd_minor, obd->obd_type->typ_name);
280 /* just leave this on forever. I can't use obd_set_up here because
281 other fns check that status, and we're not actually set up yet. */
282 obd->obd_starting = 1;
283 spin_unlock(&obd->obd_dev_lock);
285 /* create an uuid-export hash body */
286 err = lustre_hash_init(&obd->obd_uuid_hash_body, "UUID_HASH",
287 128, &uuid_hash_operations);
291 /* create a nid-export hash body */
292 err = lustre_hash_init(&obd->obd_nid_hash_body, "NID_HASH",
293 128, &nid_hash_operations);
297 /* create a nid-stats hash body */
298 err = lustre_hash_init(&obd->obd_nid_stats_hash_body, "NID_STATS",
299 128, &nid_stat_hash_operations);
303 exp = class_new_export(obd, &obd->obd_uuid);
305 RETURN(PTR_ERR(exp));
307 obd->obd_self_export = exp;
308 list_del_init(&exp->exp_obd_chain_timed);
309 class_export_put(exp);
311 err = obd_setup(obd, lcfg);
317 spin_lock(&obd->obd_dev_lock);
318 /* cleanup drops this */
320 spin_unlock(&obd->obd_dev_lock);
322 CDEBUG(D_IOCTL, "finished setup of obd %s (uuid %s)\n",
323 obd->obd_name, obd->obd_uuid.uuid);
328 class_unlink_export(obd->obd_self_export);
329 obd->obd_self_export = NULL;
331 lustre_hash_exit(&obd->obd_uuid_hash_body);
332 lustre_hash_exit(&obd->obd_nid_hash_body);
333 lustre_hash_exit(&obd->obd_nid_stats_hash_body);
334 obd->obd_starting = 0;
335 CERROR("setup %s failed (%d)\n", obd->obd_name, err);
339 int class_detach(struct obd_device *obd, struct lustre_cfg *lcfg)
343 if (obd->obd_set_up) {
344 CERROR("OBD device %d still set up\n", obd->obd_minor);
348 spin_lock(&obd->obd_dev_lock);
349 if (!obd->obd_attached) {
350 spin_unlock(&obd->obd_dev_lock);
351 CERROR("OBD device %d not attached\n", obd->obd_minor);
354 obd->obd_attached = 0;
355 spin_unlock(&obd->obd_dev_lock);
357 CDEBUG(D_IOCTL, "detach on obd %s (uuid %s)\n",
358 obd->obd_name, obd->obd_uuid.uuid);
362 /* not strictly necessary, but cleans up eagerly */
363 obd_zombie_impexp_cull();
368 static void dump_exports(struct obd_device *obd)
370 struct obd_export *exp, *n;
372 list_for_each_entry_safe(exp, n, &obd->obd_exports, exp_obd_chain) {
373 struct ptlrpc_reply_state *rs;
374 struct ptlrpc_reply_state *first_reply = NULL;
377 list_for_each_entry (rs, &exp->exp_outstanding_replies,
384 CDEBUG(D_IOCTL, "%s: %p %s %s %d %d %d: %p %s\n",
385 obd->obd_name, exp, exp->exp_client_uuid.uuid,
386 obd_export_nid2str(exp),
387 atomic_read(&exp->exp_refcount),
388 exp->exp_failed, nreplies, first_reply,
389 nreplies > 3 ? "..." : "");
393 int class_cleanup(struct obd_device *obd, struct lustre_cfg *lcfg)
399 OBD_RACE(OBD_FAIL_LDLM_RECOV_CLIENTS);
401 if (!obd->obd_set_up) {
402 CERROR("Device %d not setup\n", obd->obd_minor);
406 spin_lock(&obd->obd_dev_lock);
407 if (obd->obd_stopping) {
408 spin_unlock(&obd->obd_dev_lock);
409 CERROR("OBD %d already stopping\n", obd->obd_minor);
412 /* Leave this on forever */
413 obd->obd_stopping = 1;
414 spin_unlock(&obd->obd_dev_lock);
416 if (lcfg->lcfg_bufcount >= 2 && LUSTRE_CFG_BUFLEN(lcfg, 1) > 0) {
417 for (flag = lustre_cfg_string(lcfg, 1); *flag != 0; flag++)
423 LCONSOLE_WARN("Failing over %s\n",
426 obd->obd_no_transno = 1;
427 obd->obd_no_recov = 1;
428 /* Set the obd readonly if we can */
429 if (OBP(obd, iocontrol))
430 obd_iocontrol(OBD_IOC_SET_READONLY,
431 obd->obd_self_export,
435 CERROR("unrecognised flag '%c'\n",
440 /* The three references that should be remaining are the
441 * obd_self_export and the attach and setup references. */
442 if (atomic_read(&obd->obd_refcount) > 3) {
443 #if 0 /* We should never fail to cleanup with mountconf */
444 if (!(obd->obd_fail || obd->obd_force)) {
445 CERROR("OBD %s is still busy with %d references\n"
446 "You should stop active file system users,"
447 " or use the --force option to cleanup.\n",
448 obd->obd_name, atomic_read(&obd->obd_refcount));
450 /* Allow a failed cleanup to try again. */
451 obd->obd_stopping = 0;
454 /* refcounf - 3 might be the number of real exports
455 (excluding self export). But class_incref is called
456 by other things as well, so don't count on it. */
457 CDEBUG(D_IOCTL, "%s: forcing exports to disconnect: %d\n",
458 obd->obd_name, atomic_read(&obd->obd_refcount) - 3);
460 class_disconnect_exports(obd);
462 LASSERT(obd->obd_self_export);
464 /* destroy an uuid-export hash body */
465 lustre_hash_exit(&obd->obd_uuid_hash_body);
467 /* destroy a nid-export hash body */
468 lustre_hash_exit(&obd->obd_nid_hash_body);
470 /* destroy a nid-stats hash body */
471 lustre_hash_exit(&obd->obd_nid_stats_hash_body);
473 /* Precleanup, we must make sure all exports get destroyed. */
474 err = obd_precleanup(obd, OBD_CLEANUP_EXPORTS);
476 CERROR("Precleanup %s returned %d\n",
483 struct obd_device *class_incref(struct obd_device *obd)
485 atomic_inc(&obd->obd_refcount);
486 CDEBUG(D_INFO, "incref %s (%p) now %d\n", obd->obd_name, obd,
487 atomic_read(&obd->obd_refcount));
492 void class_decref(struct obd_device *obd)
497 spin_lock(&obd->obd_dev_lock);
498 atomic_dec(&obd->obd_refcount);
499 refs = atomic_read(&obd->obd_refcount);
500 spin_unlock(&obd->obd_dev_lock);
502 CDEBUG(D_INFO, "Decref %s (%p) now %d\n", obd->obd_name, obd, refs);
504 if ((refs == 1) && obd->obd_stopping) {
505 /* All exports have been destroyed; there should
506 be no more in-progress ops by this point.*/
508 spin_lock(&obd->obd_self_export->exp_lock);
509 obd->obd_self_export->exp_flags |=
510 (obd->obd_fail ? OBD_OPT_FAILOVER : 0) |
511 (obd->obd_force ? OBD_OPT_FORCE : 0);
512 spin_unlock(&obd->obd_self_export->exp_lock);
514 /* note that we'll recurse into class_decref again */
515 class_unlink_export(obd->obd_self_export);
520 CDEBUG(D_CONFIG, "finishing cleanup of obd %s (%s)\n",
521 obd->obd_name, obd->obd_uuid.uuid);
522 LASSERT(!obd->obd_attached);
523 if (obd->obd_stopping) {
524 /* If we're not stopping, we were never set up */
525 err = obd_cleanup(obd);
527 CERROR("Cleanup %s returned %d\n",
530 if (OBP(obd, detach)) {
531 err = OBP(obd,detach)(obd);
533 CERROR("Detach returned %d\n", err);
535 class_release_dev(obd);
539 int class_add_conn(struct obd_device *obd, struct lustre_cfg *lcfg)
541 struct obd_import *imp;
542 struct obd_uuid uuid;
546 if (LUSTRE_CFG_BUFLEN(lcfg, 1) < 1 ||
547 LUSTRE_CFG_BUFLEN(lcfg, 1) > sizeof(struct obd_uuid)) {
548 CERROR("invalid conn_uuid\n");
551 if (strcmp(obd->obd_type->typ_name, LUSTRE_MDC_NAME) &&
552 strcmp(obd->obd_type->typ_name, LUSTRE_OSC_NAME) &&
553 strcmp(obd->obd_type->typ_name, LUSTRE_MGC_NAME)) {
554 CERROR("can't add connection on non-client dev\n");
558 imp = obd->u.cli.cl_import;
560 CERROR("try to add conn on immature client dev\n");
564 obd_str2uuid(&uuid, lustre_cfg_string(lcfg, 1));
565 rc = obd_add_conn(imp, &uuid, lcfg->lcfg_num);
570 int class_del_conn(struct obd_device *obd, struct lustre_cfg *lcfg)
572 struct obd_import *imp;
573 struct obd_uuid uuid;
577 if (LUSTRE_CFG_BUFLEN(lcfg, 1) < 1 ||
578 LUSTRE_CFG_BUFLEN(lcfg, 1) > sizeof(struct obd_uuid)) {
579 CERROR("invalid conn_uuid\n");
582 if (strcmp(obd->obd_type->typ_name, LUSTRE_MDC_NAME) &&
583 strcmp(obd->obd_type->typ_name, LUSTRE_OSC_NAME)) {
584 CERROR("can't del connection on non-client dev\n");
588 imp = obd->u.cli.cl_import;
590 CERROR("try to del conn on immature client dev\n");
594 obd_str2uuid(&uuid, lustre_cfg_string(lcfg, 1));
595 rc = obd_del_conn(imp, &uuid);
600 CFS_LIST_HEAD(lustre_profile_list);
602 struct lustre_profile *class_get_profile(const char * prof)
604 struct lustre_profile *lprof;
607 list_for_each_entry(lprof, &lustre_profile_list, lp_list) {
608 if (!strcmp(lprof->lp_profile, prof)) {
615 int class_add_profile(int proflen, char *prof, int osclen, char *osc,
616 int mdclen, char *mdc)
618 struct lustre_profile *lprof;
622 CDEBUG(D_CONFIG, "Add profile %s\n", prof);
624 OBD_ALLOC(lprof, sizeof(*lprof));
627 CFS_INIT_LIST_HEAD(&lprof->lp_list);
629 LASSERT(proflen == (strlen(prof) + 1));
630 OBD_ALLOC(lprof->lp_profile, proflen);
631 if (lprof->lp_profile == NULL)
632 GOTO(out, err = -ENOMEM);
633 memcpy(lprof->lp_profile, prof, proflen);
635 LASSERT(osclen == (strlen(osc) + 1));
636 OBD_ALLOC(lprof->lp_dt, osclen);
637 if (lprof->lp_dt == NULL)
638 GOTO(out, err = -ENOMEM);
639 memcpy(lprof->lp_dt, osc, osclen);
642 LASSERT(mdclen == (strlen(mdc) + 1));
643 OBD_ALLOC(lprof->lp_md, mdclen);
644 if (lprof->lp_md == NULL)
645 GOTO(out, err = -ENOMEM);
646 memcpy(lprof->lp_md, mdc, mdclen);
649 list_add(&lprof->lp_list, &lustre_profile_list);
654 OBD_FREE(lprof->lp_md, mdclen);
656 OBD_FREE(lprof->lp_dt, osclen);
657 if (lprof->lp_profile)
658 OBD_FREE(lprof->lp_profile, proflen);
659 OBD_FREE(lprof, sizeof(*lprof));
663 void class_del_profile(const char *prof)
665 struct lustre_profile *lprof;
668 CDEBUG(D_CONFIG, "Del profile %s\n", prof);
670 lprof = class_get_profile(prof);
672 list_del(&lprof->lp_list);
673 OBD_FREE(lprof->lp_profile, strlen(lprof->lp_profile) + 1);
674 OBD_FREE(lprof->lp_dt, strlen(lprof->lp_dt) + 1);
676 OBD_FREE(lprof->lp_md, strlen(lprof->lp_md) + 1);
677 OBD_FREE(lprof, sizeof *lprof);
683 void class_del_profiles(void)
685 struct lustre_profile *lprof, *n;
688 list_for_each_entry_safe(lprof, n, &lustre_profile_list, lp_list) {
689 list_del(&lprof->lp_list);
690 OBD_FREE(lprof->lp_profile, strlen(lprof->lp_profile) + 1);
691 OBD_FREE(lprof->lp_dt, strlen(lprof->lp_dt) + 1);
693 OBD_FREE(lprof->lp_md, strlen(lprof->lp_md) + 1);
694 OBD_FREE(lprof, sizeof *lprof);
699 /* We can't call ll_process_config directly because it lives in a module that
700 must be loaded after this one. */
701 static int (*client_process_config)(struct lustre_cfg *lcfg) = NULL;
703 void lustre_register_client_process_config(int (*cpc)(struct lustre_cfg *lcfg))
705 client_process_config = cpc;
707 EXPORT_SYMBOL(lustre_register_client_process_config);
709 int class_process_config(struct lustre_cfg *lcfg)
711 struct obd_device *obd;
714 LASSERT(lcfg && !IS_ERR(lcfg));
715 CDEBUG(D_IOCTL, "processing cmd: %x\n", lcfg->lcfg_command);
717 /* Commands that don't need a device */
718 switch(lcfg->lcfg_command) {
720 err = class_attach(lcfg);
723 case LCFG_ADD_UUID: {
724 CDEBUG(D_IOCTL, "adding mapping from uuid %s to nid "LPX64
725 " (%s)\n", lustre_cfg_string(lcfg, 1),
726 lcfg->lcfg_nid, libcfs_nid2str(lcfg->lcfg_nid));
728 err = class_add_uuid(lustre_cfg_string(lcfg, 1), lcfg->lcfg_nid);
731 case LCFG_DEL_UUID: {
732 CDEBUG(D_IOCTL, "removing mappings for uuid %s\n",
733 (lcfg->lcfg_bufcount < 2 || LUSTRE_CFG_BUFLEN(lcfg, 1) == 0)
734 ? "<all uuids>" : lustre_cfg_string(lcfg, 1));
736 err = class_del_uuid(lustre_cfg_string(lcfg, 1));
739 case LCFG_MOUNTOPT: {
740 CDEBUG(D_IOCTL, "mountopt: profile %s osc %s mdc %s\n",
741 lustre_cfg_string(lcfg, 1),
742 lustre_cfg_string(lcfg, 2),
743 lustre_cfg_string(lcfg, 3));
744 /* set these mount options somewhere, so ll_fill_super
746 err = class_add_profile(LUSTRE_CFG_BUFLEN(lcfg, 1),
747 lustre_cfg_string(lcfg, 1),
748 LUSTRE_CFG_BUFLEN(lcfg, 2),
749 lustre_cfg_string(lcfg, 2),
750 LUSTRE_CFG_BUFLEN(lcfg, 3),
751 lustre_cfg_string(lcfg, 3));
754 case LCFG_DEL_MOUNTOPT: {
755 CDEBUG(D_IOCTL, "mountopt: profile %s\n",
756 lustre_cfg_string(lcfg, 1));
757 class_del_profile(lustre_cfg_string(lcfg, 1));
760 case LCFG_SET_TIMEOUT: {
761 CDEBUG(D_IOCTL, "changing lustre timeout from %d to %d\n",
762 obd_timeout, lcfg->lcfg_num);
763 obd_timeout = max(lcfg->lcfg_num, 1U);
766 case LCFG_SET_UPCALL: {
767 LCONSOLE_ERROR_MSG(0x15a, "recovery upcall is deprecated\n");
768 /* COMPAT_146 Don't fail on old configs */
772 struct cfg_marker *marker;
773 marker = lustre_cfg_buf(lcfg, 1);
774 CDEBUG(D_IOCTL, "marker %d (%#x) %.16s %s\n", marker->cm_step,
775 marker->cm_flags, marker->cm_tgtname, marker->cm_comment);
779 /* llite has no obd */
780 if ((class_match_param(lustre_cfg_string(lcfg, 1),
781 PARAM_LLITE, 0) == 0) &&
782 client_process_config) {
783 err = (*client_process_config)(lcfg);
791 /* Commands that require a device */
792 obd = class_name2obd(lustre_cfg_string(lcfg, 0));
794 if (!LUSTRE_CFG_BUFLEN(lcfg, 0))
795 CERROR("this lcfg command requires a device name\n");
797 CERROR("no device for: %s\n",
798 lustre_cfg_string(lcfg, 0));
800 GOTO(out, err = -EINVAL);
803 switch(lcfg->lcfg_command) {
805 err = class_setup(obd, lcfg);
809 err = class_detach(obd, lcfg);
813 err = class_cleanup(obd, lcfg);
816 case LCFG_ADD_CONN: {
817 err = class_add_conn(obd, lcfg);
820 case LCFG_DEL_CONN: {
821 err = class_del_conn(obd, lcfg);
825 err = obd_process_config(obd, sizeof(*lcfg), lcfg);
831 if ((err < 0) && !(lcfg->lcfg_command & LCFG_REQUIRED)) {
832 CWARN("Ignoring error %d on optional command %#x\n", err,
839 int class_process_proc_param(char *prefix, struct lprocfs_vars *lvars,
840 struct lustre_cfg *lcfg, void *data)
843 struct lprocfs_vars *var;
845 int i, keylen, vallen;
846 int matched = 0, j = 0;
850 if (lcfg->lcfg_command != LCFG_PARAM) {
851 CERROR("Unknown command: %d\n", lcfg->lcfg_command);
855 /* e.g. tunefs.lustre --param mdt.group_upcall=foo /r/tmp/lustre-mdt
856 or lctl conf_param lustre-MDT0000.mdt.group_upcall=bar
857 or lctl conf_param lustre-OST0000.osc.max_dirty_mb=36 */
858 for (i = 1; i < lcfg->lcfg_bufcount; i++) {
859 key = lustre_cfg_buf(lcfg, i);
860 /* Strip off prefix */
861 class_match_param(key, prefix, &key);
862 sval = strchr(key, '=');
863 if (!sval || (*(sval + 1) == 0)) {
864 CERROR("Can't parse param %s\n", key);
865 /* rc = -EINVAL; continue parsing other params */
870 vallen = strlen(sval);
873 /* Search proc entries */
874 while (lvars[j].name) {
876 if (class_match_param(key, (char *)var->name, 0) == 0 &&
877 keylen == strlen(var->name)) {
880 if (var->write_fptr) {
884 rc = (var->write_fptr)(NULL, sval,
889 CERROR("writing proc entry %s err %d\n",
896 CERROR("%s: unknown param %s\n",
897 (char *)lustre_cfg_string(lcfg, 0), key);
898 /* rc = -EINVAL; continue parsing other params */
900 LCONSOLE_INFO("%s.%.*s: set parameter %.*s=%s\n",
901 lustre_cfg_string(lcfg, 0),
902 (int)strlen(prefix) - 1, prefix,
903 (int)(sval - key - 1), key, sval);
911 CDEBUG(D_CONFIG, "liblustre can't process params.\n");
912 /* Don't throw config error */
917 int class_config_dump_handler(struct llog_handle * handle,
918 struct llog_rec_hdr *rec, void *data);
921 extern int lustre_check_exclusion(struct super_block *sb, char *svname);
923 #define lustre_check_exclusion(a,b) 0
926 static int class_config_llog_handler(struct llog_handle * handle,
927 struct llog_rec_hdr *rec, void *data)
929 struct config_llog_instance *clli = data;
930 int cfg_len = rec->lrh_len;
931 char *cfg_buf = (char*) (rec + 1);
935 //class_config_dump_handler(handle, rec, data);
937 switch (rec->lrh_type) {
939 struct lustre_cfg *lcfg, *lcfg_new;
940 struct lustre_cfg_bufs bufs;
941 char *inst_name = NULL;
945 lcfg = (struct lustre_cfg *)cfg_buf;
946 if (lcfg->lcfg_version == __swab32(LUSTRE_CFG_VERSION))
947 lustre_swab_lustre_cfg(lcfg);
949 rc = lustre_cfg_sanity_check(cfg_buf, cfg_len);
953 /* Figure out config state info */
954 if (lcfg->lcfg_command == LCFG_MARKER) {
955 struct cfg_marker *marker = lustre_cfg_buf(lcfg, 1);
956 CDEBUG(D_CONFIG, "Marker, inst_flg=%#x mark_flg=%#x\n",
957 clli->cfg_flags, marker->cm_flags);
958 if (marker->cm_flags & CM_START) {
959 /* all previous flags off */
960 clli->cfg_flags = CFG_F_MARKER;
961 if (marker->cm_flags & CM_SKIP) {
962 clli->cfg_flags |= CFG_F_SKIP;
963 CDEBUG(D_CONFIG, "SKIP #%d\n",
965 } else if ((marker->cm_flags & CM_EXCLUDE) ||
966 lustre_check_exclusion(clli->cfg_sb,
967 marker->cm_tgtname)) {
968 clli->cfg_flags |= CFG_F_EXCLUDE;
969 CDEBUG(D_CONFIG, "EXCLUDE %d\n",
972 } else if (marker->cm_flags & CM_END) {
976 /* A config command without a start marker before it is
977 illegal (post 146) */
978 if (!(clli->cfg_flags & CFG_F_COMPAT146) &&
979 !(clli->cfg_flags & CFG_F_MARKER) &&
980 (lcfg->lcfg_command != LCFG_MARKER)) {
981 CWARN("Config not inside markers, ignoring! "
982 "(inst: %s, uuid: %s, flags: %#x)\n",
983 clli->cfg_instance ? clli->cfg_instance : "<null>",
984 clli->cfg_uuid.uuid, clli->cfg_flags);
985 clli->cfg_flags |= CFG_F_SKIP;
987 if (clli->cfg_flags & CFG_F_SKIP) {
988 CDEBUG(D_CONFIG, "skipping %#x\n",
995 if ((clli->cfg_flags & CFG_F_EXCLUDE) &&
996 (lcfg->lcfg_command == LCFG_LOV_ADD_OBD))
997 /* Add inactive instead */
998 lcfg->lcfg_command = LCFG_LOV_ADD_INA;
1000 lustre_cfg_bufs_init(&bufs, lcfg);
1002 if (clli && clli->cfg_instance &&
1003 LUSTRE_CFG_BUFLEN(lcfg, 0) > 0){
1005 inst_len = LUSTRE_CFG_BUFLEN(lcfg, 0) +
1006 strlen(clli->cfg_instance) + 1;
1007 OBD_ALLOC(inst_name, inst_len);
1008 if (inst_name == NULL)
1009 GOTO(out, rc = -ENOMEM);
1010 sprintf(inst_name, "%s-%s",
1011 lustre_cfg_string(lcfg, 0),
1012 clli->cfg_instance);
1013 lustre_cfg_bufs_set_string(&bufs, 0, inst_name);
1014 CDEBUG(D_CONFIG, "cmd %x, instance name: %s\n",
1015 lcfg->lcfg_command, inst_name);
1018 /* we override the llog's uuid for clients, to insure they
1020 if (clli && clli->cfg_instance &&
1021 lcfg->lcfg_command == LCFG_ATTACH) {
1022 lustre_cfg_bufs_set_string(&bufs, 2,
1023 clli->cfg_uuid.uuid);
1026 lcfg_new = lustre_cfg_new(lcfg->lcfg_command, &bufs);
1028 lcfg_new->lcfg_num = lcfg->lcfg_num;
1029 lcfg_new->lcfg_flags = lcfg->lcfg_flags;
1031 /* XXX Hack to try to remain binary compatible with
1032 * pre-newconfig logs */
1033 if (lcfg->lcfg_nal != 0 && /* pre-newconfig log? */
1034 (lcfg->lcfg_nid >> 32) == 0) {
1035 __u32 addr = (__u32)(lcfg->lcfg_nid & 0xffffffff);
1037 lcfg_new->lcfg_nid =
1038 LNET_MKNID(LNET_MKNET(lcfg->lcfg_nal, 0), addr);
1039 CWARN("Converted pre-newconfig NAL %d NID %x to %s\n",
1040 lcfg->lcfg_nal, addr,
1041 libcfs_nid2str(lcfg_new->lcfg_nid));
1043 lcfg_new->lcfg_nid = lcfg->lcfg_nid;
1046 lcfg_new->lcfg_nal = 0; /* illegal value for obsolete field */
1048 rc = class_process_config(lcfg_new);
1049 lustre_cfg_free(lcfg_new);
1052 OBD_FREE(inst_name, inst_len);
1056 CERROR("Unknown llog record type %#x encountered\n",
1062 CERROR("Err %d on cfg command:\n", rc);
1063 class_config_dump_handler(handle, rec, data);
1068 int class_config_parse_llog(struct llog_ctxt *ctxt, char *name,
1069 struct config_llog_instance *cfg)
1071 struct llog_process_cat_data cd = {0, 0};
1072 struct llog_handle *llh;
1076 CDEBUG(D_INFO, "looking up llog %s\n", name);
1077 rc = llog_create(ctxt, &llh, NULL, name);
1081 rc = llog_init_handle(llh, LLOG_F_IS_PLAIN, NULL);
1083 GOTO(parse_out, rc);
1085 /* continue processing from where we last stopped to end-of-log */
1087 cd.lpcd_first_idx = cfg->cfg_last_idx;
1088 cd.lpcd_last_idx = 0;
1090 rc = llog_process(llh, class_config_llog_handler, cfg, &cd);
1092 CDEBUG(D_CONFIG, "Processed log %s gen %d-%d (rc=%d)\n", name,
1093 cd.lpcd_first_idx + 1, cd.lpcd_last_idx, rc);
1096 cfg->cfg_last_idx = cd.lpcd_last_idx;
1099 rc2 = llog_close(llh);
1106 int class_config_dump_handler(struct llog_handle * handle,
1107 struct llog_rec_hdr *rec, void *data)
1109 int cfg_len = rec->lrh_len;
1110 char *cfg_buf = (char*) (rec + 1);
1111 char *outstr, *ptr, *end;
1115 OBD_ALLOC(outstr, 256);
1121 if (rec->lrh_type == OBD_CFG_REC) {
1122 struct lustre_cfg *lcfg;
1125 rc = lustre_cfg_sanity_check(cfg_buf, cfg_len);
1128 lcfg = (struct lustre_cfg *)cfg_buf;
1130 ptr += snprintf(ptr, end-ptr, "cmd=%05x ",
1131 lcfg->lcfg_command);
1132 if (lcfg->lcfg_flags) {
1133 ptr += snprintf(ptr, end-ptr, "flags=%#08x ",
1136 if (lcfg->lcfg_num) {
1137 ptr += snprintf(ptr, end-ptr, "num=%#08x ",
1140 if (lcfg->lcfg_nid) {
1141 ptr += snprintf(ptr, end-ptr, "nid=%s("LPX64")\n ",
1142 libcfs_nid2str(lcfg->lcfg_nid),
1145 if (lcfg->lcfg_command == LCFG_MARKER) {
1146 struct cfg_marker *marker = lustre_cfg_buf(lcfg, 1);
1147 ptr += snprintf(ptr, end-ptr, "marker=%d(%#x)%s '%s'",
1148 marker->cm_step, marker->cm_flags,
1149 marker->cm_tgtname, marker->cm_comment);
1151 for (i = 0; i < lcfg->lcfg_bufcount; i++) {
1152 ptr += snprintf(ptr, end-ptr, "%d:%s ", i,
1153 lustre_cfg_string(lcfg, i));
1156 LCONSOLE(D_WARNING, " %s\n", outstr);
1158 LCONSOLE(D_WARNING, "unhandled lrh_type: %#x\n", rec->lrh_type);
1162 OBD_FREE(outstr, 256);
1166 int class_config_dump_llog(struct llog_ctxt *ctxt, char *name,
1167 struct config_llog_instance *cfg)
1169 struct llog_handle *llh;
1173 LCONSOLE_INFO("Dumping config log %s\n", name);
1175 rc = llog_create(ctxt, &llh, NULL, name);
1179 rc = llog_init_handle(llh, LLOG_F_IS_PLAIN, NULL);
1181 GOTO(parse_out, rc);
1183 rc = llog_process(llh, class_config_dump_handler, cfg, NULL);
1185 rc2 = llog_close(llh);
1189 LCONSOLE_INFO("End config log %s\n", name);
1194 /* Cleanup and detach */
1195 int class_manual_cleanup(struct obd_device *obd)
1197 struct lustre_cfg *lcfg;
1198 struct lustre_cfg_bufs bufs;
1204 CERROR("empty cleanup\n");
1213 CDEBUG(D_CONFIG, "Manual cleanup of %s (flags='%s')\n",
1214 obd->obd_name, flags);
1216 lustre_cfg_bufs_reset(&bufs, obd->obd_name);
1217 lustre_cfg_bufs_set_string(&bufs, 1, flags);
1218 lcfg = lustre_cfg_new(LCFG_CLEANUP, &bufs);
1220 rc = class_process_config(lcfg);
1222 CERROR("cleanup failed %d: %s\n", rc, obd->obd_name);
1226 /* the lcfg is almost the same for both ops */
1227 lcfg->lcfg_command = LCFG_DETACH;
1228 rc = class_process_config(lcfg);
1230 CERROR("detach failed %d: %s\n", rc, obd->obd_name);
1232 lustre_cfg_free(lcfg);