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 **********************/
124 * Create a new device and set the type, name and uuid. If successful, the new
125 * device can be accessed by either name or uuid.
127 int class_attach(struct lustre_cfg *lcfg)
129 struct obd_device *obd = NULL;
130 char *typename, *name, *uuid;
134 if (!LUSTRE_CFG_BUFLEN(lcfg, 1)) {
135 CERROR("No type passed!\n");
138 typename = lustre_cfg_string(lcfg, 1);
140 if (!LUSTRE_CFG_BUFLEN(lcfg, 0)) {
141 CERROR("No name passed!\n");
144 name = lustre_cfg_string(lcfg, 0);
146 if (!LUSTRE_CFG_BUFLEN(lcfg, 2)) {
147 CERROR("No UUID passed!\n");
150 uuid = lustre_cfg_string(lcfg, 2);
152 CDEBUG(D_IOCTL, "attach type %s name: %s uuid: %s\n",
153 MKSTR(typename), MKSTR(name), MKSTR(uuid));
155 obd = class_newdev(typename, name);
157 /* Already exists or out of obds */
160 CERROR("Cannot create device %s of type %s : %d\n",
164 LASSERTF(obd != NULL, "Cannot get obd device %s of type %s\n",
166 LASSERTF(obd->obd_magic == OBD_DEVICE_MAGIC,
167 "obd %p obd_magic %08X != %08X\n",
168 obd, obd->obd_magic, OBD_DEVICE_MAGIC);
169 LASSERTF(strncmp(obd->obd_name, name, strlen(name)) == 0, "%p obd_name %s != %s\n",
170 obd, obd->obd_name, name);
172 rwlock_init(&obd->obd_pool_lock);
173 obd->obd_pool_limit = 0;
174 obd->obd_pool_slv = 0;
176 CFS_INIT_LIST_HEAD(&obd->obd_exports);
177 CFS_INIT_LIST_HEAD(&obd->obd_exports_timed);
178 CFS_INIT_LIST_HEAD(&obd->obd_nid_stats);
179 spin_lock_init(&obd->obd_nid_lock);
180 spin_lock_init(&obd->obd_dev_lock);
181 sema_init(&obd->obd_dev_sem, 1);
182 spin_lock_init(&obd->obd_osfs_lock);
183 /* obd->obd_osfs_age must be set to a value in the distant
184 * past to guarantee a fresh statfs is fetched on mount. */
185 obd->obd_osfs_age = cfs_time_shift_64(-1000);
187 /* XXX belongs in setup not attach */
189 cfs_init_timer(&obd->obd_recovery_timer);
190 spin_lock_init(&obd->obd_processing_task_lock);
191 cfs_waitq_init(&obd->obd_next_transno_waitq);
192 cfs_waitq_init(&obd->obd_evict_inprogress_waitq);
193 CFS_INIT_LIST_HEAD(&obd->obd_req_replay_queue);
194 CFS_INIT_LIST_HEAD(&obd->obd_lock_replay_queue);
195 CFS_INIT_LIST_HEAD(&obd->obd_final_req_queue);
197 llog_group_init(&obd->obd_olg, OBD_LLOG_GROUP);
199 spin_lock_init(&obd->obd_uncommitted_replies_lock);
200 CFS_INIT_LIST_HEAD(&obd->obd_uncommitted_replies);
203 if (len >= sizeof(obd->obd_uuid)) {
204 CERROR("uuid must be < %d bytes long\n",
205 (int)sizeof(obd->obd_uuid));
206 GOTO(out, rc = -EINVAL);
208 memcpy(obd->obd_uuid.uuid, uuid, len);
211 if (OBP(obd, attach)) {
212 rc = OBP(obd,attach)(obd, sizeof *lcfg, lcfg);
214 GOTO(out, rc = -EINVAL);
217 /* Detach drops this */
218 spin_lock(&obd->obd_dev_lock);
219 atomic_set(&obd->obd_refcount, 1);
220 spin_unlock(&obd->obd_dev_lock);
222 obd->obd_attached = 1;
223 CDEBUG(D_IOCTL, "OBD: dev %d attached type %s with refcount %d\n",
224 obd->obd_minor, typename, atomic_read(&obd->obd_refcount));
228 class_release_dev(obd);
233 int class_setup(struct obd_device *obd, struct lustre_cfg *lcfg)
236 struct obd_export *exp;
239 LASSERT(obd != NULL);
240 LASSERTF(obd == class_num2obd(obd->obd_minor), "obd %p != obd_devs[%d] %p\n",
241 obd, obd->obd_minor, class_num2obd(obd->obd_minor));
242 LASSERTF(obd->obd_magic == OBD_DEVICE_MAGIC, "obd %p obd_magic %08x != %08x\n",
243 obd, obd->obd_magic, OBD_DEVICE_MAGIC);
245 /* have we attached a type to this device? */
246 if (!obd->obd_attached) {
247 CERROR("Device %d not attached\n", obd->obd_minor);
251 if (obd->obd_set_up) {
252 CERROR("Device %d already setup (type %s)\n",
253 obd->obd_minor, obd->obd_type->typ_name);
257 /* is someone else setting us up right now? (attach inits spinlock) */
258 spin_lock(&obd->obd_dev_lock);
259 if (obd->obd_starting) {
260 spin_unlock(&obd->obd_dev_lock);
261 CERROR("Device %d setup in progress (type %s)\n",
262 obd->obd_minor, obd->obd_type->typ_name);
265 /* just leave this on forever. I can't use obd_set_up here because
266 other fns check that status, and we're not actually set up yet. */
267 obd->obd_starting = 1;
268 spin_unlock(&obd->obd_dev_lock);
270 /* create an uuid-export hash body */
271 err = lustre_hash_init(&obd->obd_uuid_hash_body, "UUID_HASH",
272 128, &uuid_hash_operations);
276 /* create a nid-export hash body */
277 err = lustre_hash_init(&obd->obd_nid_hash_body, "NID_HASH",
278 128, &nid_hash_operations);
282 /* create a nid-stats hash body */
283 err = lustre_hash_init(&obd->obd_nid_stats_hash_body, "NID_STATS",
284 128, &nid_stat_hash_operations);
288 exp = class_new_export(obd, &obd->obd_uuid);
290 RETURN(PTR_ERR(exp));
292 obd->obd_self_export = exp;
293 list_del_init(&exp->exp_obd_chain_timed);
294 class_export_put(exp);
296 err = obd_setup(obd, lcfg);
302 spin_lock(&obd->obd_dev_lock);
303 /* cleanup drops this */
305 spin_unlock(&obd->obd_dev_lock);
307 CDEBUG(D_IOCTL, "finished setup of obd %s (uuid %s)\n",
308 obd->obd_name, obd->obd_uuid.uuid);
313 class_unlink_export(obd->obd_self_export);
314 obd->obd_self_export = NULL;
316 lustre_hash_exit(&obd->obd_uuid_hash_body);
317 lustre_hash_exit(&obd->obd_nid_hash_body);
318 lustre_hash_exit(&obd->obd_nid_stats_hash_body);
319 obd->obd_starting = 0;
320 CERROR("setup %s failed (%d)\n", obd->obd_name, err);
324 int class_detach(struct obd_device *obd, struct lustre_cfg *lcfg)
328 if (obd->obd_set_up) {
329 CERROR("OBD device %d still set up\n", obd->obd_minor);
333 spin_lock(&obd->obd_dev_lock);
334 if (!obd->obd_attached) {
335 spin_unlock(&obd->obd_dev_lock);
336 CERROR("OBD device %d not attached\n", obd->obd_minor);
339 obd->obd_attached = 0;
340 spin_unlock(&obd->obd_dev_lock);
342 CDEBUG(D_IOCTL, "detach on obd %s (uuid %s)\n",
343 obd->obd_name, obd->obd_uuid.uuid);
347 /* not strictly necessary, but cleans up eagerly */
348 obd_zombie_impexp_cull();
353 static void dump_exports(struct obd_device *obd)
355 struct obd_export *exp, *n;
357 list_for_each_entry_safe(exp, n, &obd->obd_exports, exp_obd_chain) {
358 struct ptlrpc_reply_state *rs;
359 struct ptlrpc_reply_state *first_reply = NULL;
362 list_for_each_entry (rs, &exp->exp_outstanding_replies,
369 CDEBUG(D_IOCTL, "%s: %p %s %s %d %d %d: %p %s\n",
370 obd->obd_name, exp, exp->exp_client_uuid.uuid,
371 obd_export_nid2str(exp),
372 atomic_read(&exp->exp_refcount),
373 exp->exp_failed, nreplies, first_reply,
374 nreplies > 3 ? "..." : "");
378 int class_cleanup(struct obd_device *obd, struct lustre_cfg *lcfg)
384 OBD_RACE(OBD_FAIL_LDLM_RECOV_CLIENTS);
386 if (!obd->obd_set_up) {
387 CERROR("Device %d not setup\n", obd->obd_minor);
391 spin_lock(&obd->obd_dev_lock);
392 if (obd->obd_stopping) {
393 spin_unlock(&obd->obd_dev_lock);
394 CERROR("OBD %d already stopping\n", obd->obd_minor);
397 /* Leave this on forever */
398 obd->obd_stopping = 1;
399 spin_unlock(&obd->obd_dev_lock);
401 if (lcfg->lcfg_bufcount >= 2 && LUSTRE_CFG_BUFLEN(lcfg, 1) > 0) {
402 for (flag = lustre_cfg_string(lcfg, 1); *flag != 0; flag++)
408 LCONSOLE_WARN("Failing over %s\n",
411 obd->obd_no_transno = 1;
412 obd->obd_no_recov = 1;
413 /* Set the obd readonly if we can */
414 if (OBP(obd, iocontrol))
415 obd_iocontrol(OBD_IOC_SET_READONLY,
416 obd->obd_self_export,
420 CERROR("unrecognised flag '%c'\n",
425 /* The three references that should be remaining are the
426 * obd_self_export and the attach and setup references. */
427 if (atomic_read(&obd->obd_refcount) > 3) {
428 #if 0 /* We should never fail to cleanup with mountconf */
429 if (!(obd->obd_fail || obd->obd_force)) {
430 CERROR("OBD %s is still busy with %d references\n"
431 "You should stop active file system users,"
432 " or use the --force option to cleanup.\n",
433 obd->obd_name, atomic_read(&obd->obd_refcount));
435 /* Allow a failed cleanup to try again. */
436 obd->obd_stopping = 0;
439 /* refcounf - 3 might be the number of real exports
440 (excluding self export). But class_incref is called
441 by other things as well, so don't count on it. */
442 CDEBUG(D_IOCTL, "%s: forcing exports to disconnect: %d\n",
443 obd->obd_name, atomic_read(&obd->obd_refcount) - 3);
445 class_disconnect_exports(obd);
447 LASSERT(obd->obd_self_export);
449 /* destroy an uuid-export hash body */
450 lustre_hash_exit(&obd->obd_uuid_hash_body);
452 /* destroy a nid-export hash body */
453 lustre_hash_exit(&obd->obd_nid_hash_body);
455 /* destroy a nid-stats hash body */
456 lustre_hash_exit(&obd->obd_nid_stats_hash_body);
458 /* Precleanup, we must make sure all exports get destroyed. */
459 err = obd_precleanup(obd, OBD_CLEANUP_EXPORTS);
461 CERROR("Precleanup %s returned %d\n",
469 struct obd_device *class_incref(struct obd_device *obd)
471 atomic_inc(&obd->obd_refcount);
472 CDEBUG(D_INFO, "incref %s (%p) now %d\n", obd->obd_name, obd,
473 atomic_read(&obd->obd_refcount));
478 void class_decref(struct obd_device *obd)
483 spin_lock(&obd->obd_dev_lock);
484 atomic_dec(&obd->obd_refcount);
485 refs = atomic_read(&obd->obd_refcount);
486 spin_unlock(&obd->obd_dev_lock);
488 CDEBUG(D_INFO, "Decref %s (%p) now %d\n", obd->obd_name, obd, refs);
490 if ((refs == 1) && obd->obd_stopping) {
491 /* All exports have been destroyed; there should
492 be no more in-progress ops by this point.*/
494 spin_lock(&obd->obd_self_export->exp_lock);
495 obd->obd_self_export->exp_flags |=
496 (obd->obd_fail ? OBD_OPT_FAILOVER : 0) |
497 (obd->obd_force ? OBD_OPT_FORCE : 0);
498 spin_unlock(&obd->obd_self_export->exp_lock);
500 /* note that we'll recurse into class_decref again */
501 class_unlink_export(obd->obd_self_export);
506 CDEBUG(D_CONFIG, "finishing cleanup of obd %s (%s)\n",
507 obd->obd_name, obd->obd_uuid.uuid);
508 LASSERT(!obd->obd_attached);
509 if (obd->obd_stopping) {
510 /* If we're not stopping, we were never set up */
511 err = obd_cleanup(obd);
513 CERROR("Cleanup %s returned %d\n",
516 if (OBP(obd, detach)) {
517 err = OBP(obd,detach)(obd);
519 CERROR("Detach returned %d\n", err);
521 class_release_dev(obd);
525 int class_add_conn(struct obd_device *obd, struct lustre_cfg *lcfg)
527 struct obd_import *imp;
528 struct obd_uuid uuid;
532 if (LUSTRE_CFG_BUFLEN(lcfg, 1) < 1 ||
533 LUSTRE_CFG_BUFLEN(lcfg, 1) > sizeof(struct obd_uuid)) {
534 CERROR("invalid conn_uuid\n");
537 if (strcmp(obd->obd_type->typ_name, LUSTRE_MDC_NAME) &&
538 strcmp(obd->obd_type->typ_name, LUSTRE_OSC_NAME) &&
539 strcmp(obd->obd_type->typ_name, LUSTRE_MGC_NAME)) {
540 CERROR("can't add connection on non-client dev\n");
544 imp = obd->u.cli.cl_import;
546 CERROR("try to add conn on immature client dev\n");
550 obd_str2uuid(&uuid, lustre_cfg_string(lcfg, 1));
551 rc = obd_add_conn(imp, &uuid, lcfg->lcfg_num);
556 int class_del_conn(struct obd_device *obd, struct lustre_cfg *lcfg)
558 struct obd_import *imp;
559 struct obd_uuid uuid;
563 if (LUSTRE_CFG_BUFLEN(lcfg, 1) < 1 ||
564 LUSTRE_CFG_BUFLEN(lcfg, 1) > sizeof(struct obd_uuid)) {
565 CERROR("invalid conn_uuid\n");
568 if (strcmp(obd->obd_type->typ_name, LUSTRE_MDC_NAME) &&
569 strcmp(obd->obd_type->typ_name, LUSTRE_OSC_NAME)) {
570 CERROR("can't del connection on non-client dev\n");
574 imp = obd->u.cli.cl_import;
576 CERROR("try to del conn on immature client dev\n");
580 obd_str2uuid(&uuid, lustre_cfg_string(lcfg, 1));
581 rc = obd_del_conn(imp, &uuid);
586 CFS_LIST_HEAD(lustre_profile_list);
588 struct lustre_profile *class_get_profile(const char * prof)
590 struct lustre_profile *lprof;
593 list_for_each_entry(lprof, &lustre_profile_list, lp_list) {
594 if (!strcmp(lprof->lp_profile, prof)) {
601 int class_add_profile(int proflen, char *prof, int osclen, char *osc,
602 int mdclen, char *mdc)
604 struct lustre_profile *lprof;
608 CDEBUG(D_CONFIG, "Add profile %s\n", prof);
610 OBD_ALLOC(lprof, sizeof(*lprof));
613 CFS_INIT_LIST_HEAD(&lprof->lp_list);
615 LASSERT(proflen == (strlen(prof) + 1));
616 OBD_ALLOC(lprof->lp_profile, proflen);
617 if (lprof->lp_profile == NULL)
618 GOTO(out, err = -ENOMEM);
619 memcpy(lprof->lp_profile, prof, proflen);
621 LASSERT(osclen == (strlen(osc) + 1));
622 OBD_ALLOC(lprof->lp_dt, osclen);
623 if (lprof->lp_dt == NULL)
624 GOTO(out, err = -ENOMEM);
625 memcpy(lprof->lp_dt, osc, osclen);
628 LASSERT(mdclen == (strlen(mdc) + 1));
629 OBD_ALLOC(lprof->lp_md, mdclen);
630 if (lprof->lp_md == NULL)
631 GOTO(out, err = -ENOMEM);
632 memcpy(lprof->lp_md, mdc, mdclen);
635 list_add(&lprof->lp_list, &lustre_profile_list);
640 OBD_FREE(lprof->lp_md, mdclen);
642 OBD_FREE(lprof->lp_dt, osclen);
643 if (lprof->lp_profile)
644 OBD_FREE(lprof->lp_profile, proflen);
645 OBD_FREE(lprof, sizeof(*lprof));
649 void class_del_profile(const char *prof)
651 struct lustre_profile *lprof;
654 CDEBUG(D_CONFIG, "Del profile %s\n", prof);
656 lprof = class_get_profile(prof);
658 list_del(&lprof->lp_list);
659 OBD_FREE(lprof->lp_profile, strlen(lprof->lp_profile) + 1);
660 OBD_FREE(lprof->lp_dt, strlen(lprof->lp_dt) + 1);
662 OBD_FREE(lprof->lp_md, strlen(lprof->lp_md) + 1);
663 OBD_FREE(lprof, sizeof *lprof);
669 void class_del_profiles(void)
671 struct lustre_profile *lprof, *n;
674 list_for_each_entry_safe(lprof, n, &lustre_profile_list, lp_list) {
675 list_del(&lprof->lp_list);
676 OBD_FREE(lprof->lp_profile, strlen(lprof->lp_profile) + 1);
677 OBD_FREE(lprof->lp_dt, strlen(lprof->lp_dt) + 1);
679 OBD_FREE(lprof->lp_md, strlen(lprof->lp_md) + 1);
680 OBD_FREE(lprof, sizeof *lprof);
685 /* We can't call ll_process_config directly because it lives in a module that
686 must be loaded after this one. */
687 static int (*client_process_config)(struct lustre_cfg *lcfg) = NULL;
689 void lustre_register_client_process_config(int (*cpc)(struct lustre_cfg *lcfg))
691 client_process_config = cpc;
693 EXPORT_SYMBOL(lustre_register_client_process_config);
695 int class_process_config(struct lustre_cfg *lcfg)
697 struct obd_device *obd;
700 LASSERT(lcfg && !IS_ERR(lcfg));
701 CDEBUG(D_IOCTL, "processing cmd: %x\n", lcfg->lcfg_command);
703 /* Commands that don't need a device */
704 switch(lcfg->lcfg_command) {
706 err = class_attach(lcfg);
709 case LCFG_ADD_UUID: {
710 CDEBUG(D_IOCTL, "adding mapping from uuid %s to nid "LPX64
711 " (%s)\n", lustre_cfg_string(lcfg, 1),
712 lcfg->lcfg_nid, libcfs_nid2str(lcfg->lcfg_nid));
714 err = class_add_uuid(lustre_cfg_string(lcfg, 1), lcfg->lcfg_nid);
717 case LCFG_DEL_UUID: {
718 CDEBUG(D_IOCTL, "removing mappings for uuid %s\n",
719 (lcfg->lcfg_bufcount < 2 || LUSTRE_CFG_BUFLEN(lcfg, 1) == 0)
720 ? "<all uuids>" : lustre_cfg_string(lcfg, 1));
722 err = class_del_uuid(lustre_cfg_string(lcfg, 1));
725 case LCFG_MOUNTOPT: {
726 CDEBUG(D_IOCTL, "mountopt: profile %s osc %s mdc %s\n",
727 lustre_cfg_string(lcfg, 1),
728 lustre_cfg_string(lcfg, 2),
729 lustre_cfg_string(lcfg, 3));
730 /* set these mount options somewhere, so ll_fill_super
732 err = class_add_profile(LUSTRE_CFG_BUFLEN(lcfg, 1),
733 lustre_cfg_string(lcfg, 1),
734 LUSTRE_CFG_BUFLEN(lcfg, 2),
735 lustre_cfg_string(lcfg, 2),
736 LUSTRE_CFG_BUFLEN(lcfg, 3),
737 lustre_cfg_string(lcfg, 3));
740 case LCFG_DEL_MOUNTOPT: {
741 CDEBUG(D_IOCTL, "mountopt: profile %s\n",
742 lustre_cfg_string(lcfg, 1));
743 class_del_profile(lustre_cfg_string(lcfg, 1));
746 case LCFG_SET_TIMEOUT: {
747 CDEBUG(D_IOCTL, "changing lustre timeout from %d to %d\n",
748 obd_timeout, lcfg->lcfg_num);
749 obd_timeout = max(lcfg->lcfg_num, 1U);
752 case LCFG_SET_UPCALL: {
753 LCONSOLE_ERROR_MSG(0x15a, "recovery upcall is deprecated\n");
754 /* COMPAT_146 Don't fail on old configs */
758 struct cfg_marker *marker;
759 marker = lustre_cfg_buf(lcfg, 1);
760 CDEBUG(D_IOCTL, "marker %d (%#x) %.16s %s\n", marker->cm_step,
761 marker->cm_flags, marker->cm_tgtname, marker->cm_comment);
765 /* llite has no obd */
766 if ((class_match_param(lustre_cfg_string(lcfg, 1),
767 PARAM_LLITE, 0) == 0) &&
768 client_process_config) {
769 err = (*client_process_config)(lcfg);
777 /* Commands that require a device */
778 obd = class_name2obd(lustre_cfg_string(lcfg, 0));
780 if (!LUSTRE_CFG_BUFLEN(lcfg, 0))
781 CERROR("this lcfg command requires a device name\n");
783 CERROR("no device for: %s\n",
784 lustre_cfg_string(lcfg, 0));
786 GOTO(out, err = -EINVAL);
789 switch(lcfg->lcfg_command) {
791 err = class_setup(obd, lcfg);
795 err = class_detach(obd, lcfg);
799 err = class_cleanup(obd, lcfg);
802 case LCFG_ADD_CONN: {
803 err = class_add_conn(obd, lcfg);
806 case LCFG_DEL_CONN: {
807 err = class_del_conn(obd, lcfg);
811 err = obd_process_config(obd, sizeof(*lcfg), lcfg);
817 if ((err < 0) && !(lcfg->lcfg_command & LCFG_REQUIRED)) {
818 CWARN("Ignoring error %d on optional command %#x\n", err,
825 int class_process_proc_param(char *prefix, struct lprocfs_vars *lvars,
826 struct lustre_cfg *lcfg, void *data)
829 struct lprocfs_vars *var;
831 int i, keylen, vallen;
832 int matched = 0, j = 0;
836 if (lcfg->lcfg_command != LCFG_PARAM) {
837 CERROR("Unknown command: %d\n", lcfg->lcfg_command);
841 /* e.g. tunefs.lustre --param mdt.group_upcall=foo /r/tmp/lustre-mdt
842 or lctl conf_param lustre-MDT0000.mdt.group_upcall=bar
843 or lctl conf_param lustre-OST0000.osc.max_dirty_mb=36 */
844 for (i = 1; i < lcfg->lcfg_bufcount; i++) {
845 key = lustre_cfg_buf(lcfg, i);
846 /* Strip off prefix */
847 class_match_param(key, prefix, &key);
848 sval = strchr(key, '=');
849 if (!sval || (*(sval + 1) == 0)) {
850 CERROR("Can't parse param %s\n", key);
852 /* continue parsing other params */
857 vallen = strlen(sval);
860 /* Search proc entries */
861 while (lvars[j].name) {
863 if (class_match_param(key, (char *)var->name, 0) == 0 &&
864 keylen == strlen(var->name)) {
867 if (var->write_fptr) {
871 rc = (var->write_fptr)(NULL, sval,
876 CERROR("writing proc entry %s err %d\n",
883 CERROR("%s: unknown param %s\n",
884 (char *)lustre_cfg_string(lcfg, 0), key);
885 /* rc = -EINVAL; continue parsing other params */
887 LCONSOLE_INFO("%s.%.*s: set parameter %.*s=%s\n",
888 (char *)lustre_cfg_string(lcfg, 0),
889 (int)strlen(prefix) - 1, prefix,
890 (int)(sval - key - 1), key, sval);
898 CDEBUG(D_CONFIG, "liblustre can't process params.\n");
899 /* Don't throw config error */
904 int class_config_dump_handler(struct llog_handle * handle,
905 struct llog_rec_hdr *rec, void *data);
908 extern int lustre_check_exclusion(struct super_block *sb, char *svname);
910 #define lustre_check_exclusion(a,b) 0
913 static int class_config_llog_handler(struct llog_handle * handle,
914 struct llog_rec_hdr *rec, void *data)
916 struct config_llog_instance *clli = data;
917 int cfg_len = rec->lrh_len;
918 char *cfg_buf = (char*) (rec + 1);
922 //class_config_dump_handler(handle, rec, data);
924 switch (rec->lrh_type) {
926 struct lustre_cfg *lcfg, *lcfg_new;
927 struct lustre_cfg_bufs bufs;
928 char *inst_name = NULL;
932 lcfg = (struct lustre_cfg *)cfg_buf;
933 if (lcfg->lcfg_version == __swab32(LUSTRE_CFG_VERSION))
934 lustre_swab_lustre_cfg(lcfg);
936 rc = lustre_cfg_sanity_check(cfg_buf, cfg_len);
940 /* Figure out config state info */
941 if (lcfg->lcfg_command == LCFG_MARKER) {
942 struct cfg_marker *marker = lustre_cfg_buf(lcfg, 1);
943 CDEBUG(D_CONFIG, "Marker, inst_flg=%#x mark_flg=%#x\n",
944 clli->cfg_flags, marker->cm_flags);
945 if (marker->cm_flags & CM_START) {
946 /* all previous flags off */
947 clli->cfg_flags = CFG_F_MARKER;
948 if (marker->cm_flags & CM_SKIP) {
949 clli->cfg_flags |= CFG_F_SKIP;
950 CDEBUG(D_CONFIG, "SKIP #%d\n",
952 } else if ((marker->cm_flags & CM_EXCLUDE) ||
953 lustre_check_exclusion(clli->cfg_sb,
954 marker->cm_tgtname)) {
955 clli->cfg_flags |= CFG_F_EXCLUDE;
956 CDEBUG(D_CONFIG, "EXCLUDE %d\n",
959 } else if (marker->cm_flags & CM_END) {
963 /* A config command without a start marker before it is
964 illegal (post 146) */
965 if (!(clli->cfg_flags & CFG_F_COMPAT146) &&
966 !(clli->cfg_flags & CFG_F_MARKER) &&
967 (lcfg->lcfg_command != LCFG_MARKER)) {
968 CWARN("Config not inside markers, ignoring! "
969 "(inst: %s, uuid: %s, flags: %#x)\n",
970 clli->cfg_instance ? clli->cfg_instance : "<null>",
971 clli->cfg_uuid.uuid, clli->cfg_flags);
972 clli->cfg_flags |= CFG_F_SKIP;
974 if (clli->cfg_flags & CFG_F_SKIP) {
975 CDEBUG(D_CONFIG, "skipping %#x\n",
982 if ((clli->cfg_flags & CFG_F_EXCLUDE) &&
983 (lcfg->lcfg_command == LCFG_LOV_ADD_OBD))
984 /* Add inactive instead */
985 lcfg->lcfg_command = LCFG_LOV_ADD_INA;
987 lustre_cfg_bufs_init(&bufs, lcfg);
989 if (clli && clli->cfg_instance &&
990 LUSTRE_CFG_BUFLEN(lcfg, 0) > 0){
992 inst_len = LUSTRE_CFG_BUFLEN(lcfg, 0) +
993 strlen(clli->cfg_instance) + 1;
994 OBD_ALLOC(inst_name, inst_len);
995 if (inst_name == NULL)
996 GOTO(out, rc = -ENOMEM);
997 sprintf(inst_name, "%s-%s",
998 lustre_cfg_string(lcfg, 0),
1000 lustre_cfg_bufs_set_string(&bufs, 0, inst_name);
1001 CDEBUG(D_CONFIG, "cmd %x, instance name: %s\n",
1002 lcfg->lcfg_command, inst_name);
1005 /* we override the llog's uuid for clients, to insure they
1007 if (clli && clli->cfg_instance &&
1008 lcfg->lcfg_command == LCFG_ATTACH) {
1009 lustre_cfg_bufs_set_string(&bufs, 2,
1010 clli->cfg_uuid.uuid);
1013 lcfg_new = lustre_cfg_new(lcfg->lcfg_command, &bufs);
1015 lcfg_new->lcfg_num = lcfg->lcfg_num;
1016 lcfg_new->lcfg_flags = lcfg->lcfg_flags;
1018 /* XXX Hack to try to remain binary compatible with
1019 * pre-newconfig logs */
1020 if (lcfg->lcfg_nal != 0 && /* pre-newconfig log? */
1021 (lcfg->lcfg_nid >> 32) == 0) {
1022 __u32 addr = (__u32)(lcfg->lcfg_nid & 0xffffffff);
1024 lcfg_new->lcfg_nid =
1025 LNET_MKNID(LNET_MKNET(lcfg->lcfg_nal, 0), addr);
1026 CWARN("Converted pre-newconfig NAL %d NID %x to %s\n",
1027 lcfg->lcfg_nal, addr,
1028 libcfs_nid2str(lcfg_new->lcfg_nid));
1030 lcfg_new->lcfg_nid = lcfg->lcfg_nid;
1033 lcfg_new->lcfg_nal = 0; /* illegal value for obsolete field */
1035 rc = class_process_config(lcfg_new);
1036 lustre_cfg_free(lcfg_new);
1039 OBD_FREE(inst_name, inst_len);
1043 CERROR("Unknown llog record type %#x encountered\n",
1049 CERROR("Err %d on cfg command:\n", rc);
1050 class_config_dump_handler(handle, rec, data);
1055 int class_config_parse_llog(struct llog_ctxt *ctxt, char *name,
1056 struct config_llog_instance *cfg)
1058 struct llog_process_cat_data cd = {0, 0};
1059 struct llog_handle *llh;
1063 CDEBUG(D_INFO, "looking up llog %s\n", name);
1064 rc = llog_create(ctxt, &llh, NULL, name);
1068 rc = llog_init_handle(llh, LLOG_F_IS_PLAIN, NULL);
1070 GOTO(parse_out, rc);
1072 /* continue processing from where we last stopped to end-of-log */
1074 cd.first_idx = cfg->cfg_last_idx;
1077 rc = llog_process(llh, class_config_llog_handler, cfg, &cd);
1079 CDEBUG(D_CONFIG, "Processed log %s gen %d-%d (rc=%d)\n", name,
1080 cd.first_idx + 1, cd.last_idx, rc);
1083 cfg->cfg_last_idx = cd.last_idx;
1086 rc2 = llog_close(llh);
1093 int class_config_dump_handler(struct llog_handle * handle,
1094 struct llog_rec_hdr *rec, void *data)
1096 int cfg_len = rec->lrh_len;
1097 char *cfg_buf = (char*) (rec + 1);
1098 char *outstr, *ptr, *end;
1102 OBD_ALLOC(outstr, 256);
1108 if (rec->lrh_type == OBD_CFG_REC) {
1109 struct lustre_cfg *lcfg;
1112 rc = lustre_cfg_sanity_check(cfg_buf, cfg_len);
1115 lcfg = (struct lustre_cfg *)cfg_buf;
1117 ptr += snprintf(ptr, end-ptr, "cmd=%05x ",
1118 lcfg->lcfg_command);
1119 if (lcfg->lcfg_flags) {
1120 ptr += snprintf(ptr, end-ptr, "flags=%#08x ",
1123 if (lcfg->lcfg_num) {
1124 ptr += snprintf(ptr, end-ptr, "num=%#08x ",
1127 if (lcfg->lcfg_nid) {
1128 ptr += snprintf(ptr, end-ptr, "nid=%s("LPX64")\n ",
1129 libcfs_nid2str(lcfg->lcfg_nid),
1132 if (lcfg->lcfg_command == LCFG_MARKER) {
1133 struct cfg_marker *marker = lustre_cfg_buf(lcfg, 1);
1134 ptr += snprintf(ptr, end-ptr, "marker=%d(%#x)%s '%s'",
1135 marker->cm_step, marker->cm_flags,
1136 marker->cm_tgtname, marker->cm_comment);
1138 for (i = 0; i < lcfg->lcfg_bufcount; i++) {
1139 ptr += snprintf(ptr, end-ptr, "%d:%s ", i,
1140 lustre_cfg_string(lcfg, i));
1143 LCONSOLE(D_WARNING, " %s\n", outstr);
1145 LCONSOLE(D_WARNING, "unhandled lrh_type: %#x\n", rec->lrh_type);
1149 OBD_FREE(outstr, 256);
1153 int class_config_dump_llog(struct llog_ctxt *ctxt, char *name,
1154 struct config_llog_instance *cfg)
1156 struct llog_handle *llh;
1160 LCONSOLE_INFO("Dumping config log %s\n", name);
1162 rc = llog_create(ctxt, &llh, NULL, name);
1166 rc = llog_init_handle(llh, LLOG_F_IS_PLAIN, NULL);
1168 GOTO(parse_out, rc);
1170 rc = llog_process(llh, class_config_dump_handler, cfg, NULL);
1172 rc2 = llog_close(llh);
1176 LCONSOLE_INFO("End config log %s\n", name);
1181 /* Cleanup and detach */
1182 int class_manual_cleanup(struct obd_device *obd)
1184 struct lustre_cfg *lcfg;
1185 struct lustre_cfg_bufs bufs;
1191 CERROR("empty cleanup\n");
1200 CDEBUG(D_CONFIG, "Manual cleanup of %s (flags='%s')\n",
1201 obd->obd_name, flags);
1203 lustre_cfg_bufs_reset(&bufs, obd->obd_name);
1204 lustre_cfg_bufs_set_string(&bufs, 1, flags);
1205 lcfg = lustre_cfg_new(LCFG_CLEANUP, &bufs);
1207 rc = class_process_config(lcfg);
1209 CERROR("cleanup failed %d: %s\n", rc, obd->obd_name);
1213 /* the lcfg is almost the same for both ops */
1214 lcfg->lcfg_command = LCFG_DETACH;
1215 rc = class_process_config(lcfg);
1217 CERROR("detach failed %d: %s\n", rc, obd->obd_name);
1219 lustre_cfg_free(lcfg);