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) 2003, 2010, Oracle and/or its affiliates. All rights reserved.
28 * Use is subject to license terms.
30 * Copyright (c) 2011, 2013, Intel Corporation.
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
42 #include <obd_class.h>
43 #include <linux/string.h>
44 #include <lustre_disk.h>
45 #include <lustre_ioctl.h>
46 #include <lustre_log.h>
47 #include <lprocfs_status.h>
48 #include <lustre_param.h>
50 #include "llog_internal.h"
52 static cfs_hash_ops_t uuid_hash_ops;
53 static cfs_hash_ops_t nid_hash_ops;
54 static cfs_hash_ops_t nid_stat_hash_ops;
56 /*********** string parsing utils *********/
58 /* returns 0 if we find this key in the buffer, else 1 */
59 int class_find_param(char *buf, char *key, char **valp)
66 if ((ptr = strstr(buf, key)) == NULL)
70 *valp = ptr + strlen(key);
74 EXPORT_SYMBOL(class_find_param);
77 * Check whether the proc parameter \a param is an old parameter or not from
78 * the array \a ptr which contains the mapping from old parameters to new ones.
79 * If it's an old one, then return the pointer to the cfg_interop_param struc-
80 * ture which contains both the old and new parameters.
82 * \param param proc parameter
83 * \param ptr an array which contains the mapping from
84 * old parameters to new ones
86 * \retval valid-pointer pointer to the cfg_interop_param structure
87 * which contains the old and new parameters
88 * \retval NULL \a param or \a ptr is NULL,
89 * or \a param is not an old parameter
91 struct cfg_interop_param *class_find_old_param(const char *param,
92 struct cfg_interop_param *ptr)
97 if (param == NULL || ptr == NULL)
100 value = strchr(param, '=');
102 name_len = strlen(param);
104 name_len = value - param;
106 while (ptr->old_param != NULL) {
107 if (strncmp(param, ptr->old_param, name_len) == 0 &&
108 name_len == strlen(ptr->old_param))
115 EXPORT_SYMBOL(class_find_old_param);
118 * Finds a parameter in \a params and copies it to \a copy.
120 * Leading spaces are skipped. Next space or end of string is the
121 * parameter terminator with the exception that spaces inside single or double
122 * quotes get included into a parameter. The parameter is copied into \a copy
123 * which has to be allocated big enough by a caller, quotes are stripped in
124 * the copy and the copy is terminated by 0.
126 * On return \a params is set to next parameter or to NULL if last
127 * parameter is returned.
129 * \retval 0 if parameter is returned in \a copy
130 * \retval 1 otherwise
131 * \retval -EINVAL if unbalanced quota is found
133 int class_get_next_param(char **params, char *copy)
148 q1 = strpbrk(str, " '\"");
151 memcpy(copy, str, len);
158 memcpy(copy, str, len);
164 memcpy(copy, str, len);
167 /* search for the matching closing quote */
169 q2 = strchr(str, *q1);
171 CERROR("Unbalanced quota in parameters: \"%s\"\n",
176 memcpy(copy, str, len);
182 EXPORT_SYMBOL(class_get_next_param);
184 /* returns 0 if this is the first key in the buffer, else 1.
185 valp points to first char after key. */
186 int class_match_param(char *buf, char *key, char **valp)
191 if (memcmp(buf, key, strlen(key)) != 0)
195 *valp = buf + strlen(key);
199 EXPORT_SYMBOL(class_match_param);
201 static int parse_nid(char *buf, void *value, int quiet)
203 lnet_nid_t *nid = (lnet_nid_t *)value;
205 *nid = libcfs_str2nid(buf);
206 if (*nid != LNET_NID_ANY)
210 LCONSOLE_ERROR_MSG(0x159, "Can't parse NID '%s'\n", buf);
214 static int parse_net(char *buf, void *value)
216 __u32 *net = (__u32 *)value;
218 *net = libcfs_str2net(buf);
219 CDEBUG(D_INFO, "Net %s\n", libcfs_net2str(*net));
231 endh is set to next separator */
232 static int class_parse_value(char *buf, int opc, void *value, char **endh,
241 while (*buf == ',' || *buf == ':')
243 if (*buf == ' ' || *buf == '/' || *buf == '\0')
246 /* nid separators or end of nids */
247 endp = strpbrk(buf, ",: /");
249 endp = buf + strlen(buf);
256 case CLASS_PARSE_NID:
257 rc = parse_nid(buf, value, quiet);
259 case CLASS_PARSE_NET:
260 rc = parse_net(buf, value);
271 int class_parse_nid(char *buf, lnet_nid_t *nid, char **endh)
273 return class_parse_value(buf, CLASS_PARSE_NID, (void *)nid, endh, 0);
275 EXPORT_SYMBOL(class_parse_nid);
277 int class_parse_nid_quiet(char *buf, lnet_nid_t *nid, char **endh)
279 return class_parse_value(buf, CLASS_PARSE_NID, (void *)nid, endh, 1);
281 EXPORT_SYMBOL(class_parse_nid_quiet);
283 int class_parse_net(char *buf, __u32 *net, char **endh)
285 return class_parse_value(buf, CLASS_PARSE_NET, (void *)net, endh, 0);
287 EXPORT_SYMBOL(class_parse_net);
289 /* 1 param contains key and match
290 * 0 param contains key and not match
291 * -1 param does not contain key
293 int class_match_nid(char *buf, char *key, lnet_nid_t nid)
298 while (class_find_param(buf, key, &buf) == 0) {
299 /* please restrict to the nids pertaining to
300 * the specified nids */
301 while (class_parse_nid(buf, &tmp, &buf) == 0) {
309 EXPORT_SYMBOL(class_match_nid);
311 int class_match_net(char *buf, char *key, __u32 net)
316 while (class_find_param(buf, key, &buf) == 0) {
317 /* please restrict to the nids pertaining to
318 * the specified networks */
319 while (class_parse_net(buf, &tmp, &buf) == 0) {
327 EXPORT_SYMBOL(class_match_net);
329 /********************** class fns **********************/
332 * Create a new obd device and set the type, name and uuid. If successful,
333 * the new device can be accessed by either name or uuid.
335 int class_attach(struct lustre_cfg *lcfg)
337 struct obd_device *obd = NULL;
338 char *typename, *name, *uuid;
342 if (!LUSTRE_CFG_BUFLEN(lcfg, 1)) {
343 CERROR("No type passed!\n");
346 typename = lustre_cfg_string(lcfg, 1);
348 if (!LUSTRE_CFG_BUFLEN(lcfg, 0)) {
349 CERROR("No name passed!\n");
352 name = lustre_cfg_string(lcfg, 0);
354 if (!LUSTRE_CFG_BUFLEN(lcfg, 2)) {
355 CERROR("No UUID passed!\n");
358 uuid = lustre_cfg_string(lcfg, 2);
360 CDEBUG(D_IOCTL, "attach type %s name: %s uuid: %s\n",
361 MKSTR(typename), MKSTR(name), MKSTR(uuid));
363 obd = class_newdev(typename, name);
365 /* Already exists or out of obds */
368 CERROR("Cannot create device %s of type %s : %d\n",
372 LASSERTF(obd != NULL, "Cannot get obd device %s of type %s\n",
374 LASSERTF(obd->obd_magic == OBD_DEVICE_MAGIC,
375 "obd %p obd_magic %08X != %08X\n",
376 obd, obd->obd_magic, OBD_DEVICE_MAGIC);
377 LASSERTF(strncmp(obd->obd_name, name, strlen(name)) == 0,
378 "%p obd_name %s != %s\n", obd, obd->obd_name, name);
380 rwlock_init(&obd->obd_pool_lock);
381 obd->obd_pool_limit = 0;
382 obd->obd_pool_slv = 0;
384 INIT_LIST_HEAD(&obd->obd_exports);
385 INIT_LIST_HEAD(&obd->obd_unlinked_exports);
386 INIT_LIST_HEAD(&obd->obd_delayed_exports);
387 INIT_LIST_HEAD(&obd->obd_exports_timed);
388 INIT_LIST_HEAD(&obd->obd_nid_stats);
389 spin_lock_init(&obd->obd_nid_lock);
390 spin_lock_init(&obd->obd_dev_lock);
391 mutex_init(&obd->obd_dev_mutex);
392 spin_lock_init(&obd->obd_osfs_lock);
393 /* obd->obd_osfs_age must be set to a value in the distant
394 * past to guarantee a fresh statfs is fetched on mount. */
395 obd->obd_osfs_age = cfs_time_shift_64(-1000);
397 /* XXX belongs in setup not attach */
398 init_rwsem(&obd->obd_observer_link_sem);
400 cfs_init_timer(&obd->obd_recovery_timer);
401 spin_lock_init(&obd->obd_recovery_task_lock);
402 init_waitqueue_head(&obd->obd_next_transno_waitq);
403 init_waitqueue_head(&obd->obd_evict_inprogress_waitq);
404 INIT_LIST_HEAD(&obd->obd_req_replay_queue);
405 INIT_LIST_HEAD(&obd->obd_lock_replay_queue);
406 INIT_LIST_HEAD(&obd->obd_final_req_queue);
407 INIT_LIST_HEAD(&obd->obd_evict_list);
408 INIT_LIST_HEAD(&obd->obd_lwp_list);
410 llog_group_init(&obd->obd_olg);
412 obd->obd_conn_inprogress = 0;
415 if (len >= sizeof(obd->obd_uuid)) {
416 CERROR("uuid must be < %d bytes long\n",
417 (int)sizeof(obd->obd_uuid));
418 GOTO(out, rc = -EINVAL);
420 memcpy(obd->obd_uuid.uuid, uuid, len);
422 /* Detach drops this */
423 spin_lock(&obd->obd_dev_lock);
424 atomic_set(&obd->obd_refcount, 1);
425 spin_unlock(&obd->obd_dev_lock);
426 lu_ref_init(&obd->obd_reference);
427 lu_ref_add(&obd->obd_reference, "attach", obd);
429 obd->obd_attached = 1;
430 CDEBUG(D_IOCTL, "OBD: dev %d attached type %s with refcount %d\n",
431 obd->obd_minor, typename, atomic_read(&obd->obd_refcount));
435 class_release_dev(obd);
439 EXPORT_SYMBOL(class_attach);
441 /** Create hashes, self-export, and call type-specific setup.
442 * Setup is effectively the "start this obd" call.
444 int class_setup(struct obd_device *obd, struct lustre_cfg *lcfg)
447 struct obd_export *exp;
450 LASSERT(obd != NULL);
451 LASSERTF(obd == class_num2obd(obd->obd_minor),
452 "obd %p != obd_devs[%d] %p\n",
453 obd, obd->obd_minor, class_num2obd(obd->obd_minor));
454 LASSERTF(obd->obd_magic == OBD_DEVICE_MAGIC,
455 "obd %p obd_magic %08x != %08x\n",
456 obd, obd->obd_magic, OBD_DEVICE_MAGIC);
458 /* have we attached a type to this device? */
459 if (!obd->obd_attached) {
460 CERROR("Device %d not attached\n", obd->obd_minor);
464 if (obd->obd_set_up) {
465 CERROR("Device %d already setup (type %s)\n",
466 obd->obd_minor, obd->obd_type->typ_name);
470 /* is someone else setting us up right now? (attach inits spinlock) */
471 spin_lock(&obd->obd_dev_lock);
472 if (obd->obd_starting) {
473 spin_unlock(&obd->obd_dev_lock);
474 CERROR("Device %d setup in progress (type %s)\n",
475 obd->obd_minor, obd->obd_type->typ_name);
478 /* just leave this on forever. I can't use obd_set_up here because
479 other fns check that status, and we're not actually set up yet. */
480 obd->obd_starting = 1;
481 obd->obd_uuid_hash = NULL;
482 obd->obd_nid_hash = NULL;
483 obd->obd_nid_stats_hash = NULL;
484 spin_unlock(&obd->obd_dev_lock);
486 /* create an uuid-export lustre hash */
487 obd->obd_uuid_hash = cfs_hash_create("UUID_HASH",
490 HASH_UUID_BKT_BITS, 0,
493 &uuid_hash_ops, CFS_HASH_DEFAULT);
494 if (!obd->obd_uuid_hash)
495 GOTO(err_hash, err = -ENOMEM);
497 /* create a nid-export lustre hash */
498 obd->obd_nid_hash = cfs_hash_create("NID_HASH",
501 HASH_NID_BKT_BITS, 0,
504 &nid_hash_ops, CFS_HASH_DEFAULT);
505 if (!obd->obd_nid_hash)
506 GOTO(err_hash, err = -ENOMEM);
508 /* create a nid-stats lustre hash */
509 obd->obd_nid_stats_hash = cfs_hash_create("NID_STATS",
510 HASH_NID_STATS_CUR_BITS,
511 HASH_NID_STATS_MAX_BITS,
512 HASH_NID_STATS_BKT_BITS, 0,
515 &nid_stat_hash_ops, CFS_HASH_DEFAULT);
516 if (!obd->obd_nid_stats_hash)
517 GOTO(err_hash, err = -ENOMEM);
519 exp = class_new_export(obd, &obd->obd_uuid);
521 GOTO(err_hash, err = PTR_ERR(exp));
523 obd->obd_self_export = exp;
524 list_del_init(&exp->exp_obd_chain_timed);
525 class_export_put(exp);
527 err = obd_setup(obd, lcfg);
533 spin_lock(&obd->obd_dev_lock);
534 /* cleanup drops this */
535 class_incref(obd, "setup", obd);
536 spin_unlock(&obd->obd_dev_lock);
538 CDEBUG(D_IOCTL, "finished setup of obd %s (uuid %s)\n",
539 obd->obd_name, obd->obd_uuid.uuid);
543 if (obd->obd_self_export) {
544 class_unlink_export(obd->obd_self_export);
545 obd->obd_self_export = NULL;
548 if (obd->obd_uuid_hash) {
549 cfs_hash_putref(obd->obd_uuid_hash);
550 obd->obd_uuid_hash = NULL;
552 if (obd->obd_nid_hash) {
553 cfs_hash_putref(obd->obd_nid_hash);
554 obd->obd_nid_hash = NULL;
556 if (obd->obd_nid_stats_hash) {
557 cfs_hash_putref(obd->obd_nid_stats_hash);
558 obd->obd_nid_stats_hash = NULL;
560 obd->obd_starting = 0;
561 CERROR("setup %s failed (%d)\n", obd->obd_name, err);
564 EXPORT_SYMBOL(class_setup);
566 /** We have finished using this obd and are ready to destroy it.
567 * There can be no more references to this obd.
569 int class_detach(struct obd_device *obd, struct lustre_cfg *lcfg)
573 if (obd->obd_set_up) {
574 CERROR("OBD device %d still set up\n", obd->obd_minor);
578 spin_lock(&obd->obd_dev_lock);
579 if (!obd->obd_attached) {
580 spin_unlock(&obd->obd_dev_lock);
581 CERROR("OBD device %d not attached\n", obd->obd_minor);
584 obd->obd_attached = 0;
585 spin_unlock(&obd->obd_dev_lock);
587 CDEBUG(D_IOCTL, "detach on obd %s (uuid %s)\n",
588 obd->obd_name, obd->obd_uuid.uuid);
590 class_decref(obd, "attach", obd);
593 EXPORT_SYMBOL(class_detach);
595 /** Start shutting down the obd. There may be in-progess ops when
596 * this is called. We tell them to start shutting down with a call
597 * to class_disconnect_exports().
599 int class_cleanup(struct obd_device *obd, struct lustre_cfg *lcfg)
605 OBD_RACE(OBD_FAIL_LDLM_RECOV_CLIENTS);
607 if (!obd->obd_set_up) {
608 CERROR("Device %d not setup\n", obd->obd_minor);
612 spin_lock(&obd->obd_dev_lock);
613 if (obd->obd_stopping) {
614 spin_unlock(&obd->obd_dev_lock);
615 CERROR("OBD %d already stopping\n", obd->obd_minor);
618 /* Leave this on forever */
619 obd->obd_stopping = 1;
620 spin_unlock(&obd->obd_dev_lock);
622 /* wait for already-arrived-connections to finish. */
623 while (obd->obd_conn_inprogress > 0)
627 if (lcfg->lcfg_bufcount >= 2 && LUSTRE_CFG_BUFLEN(lcfg, 1) > 0) {
628 for (flag = lustre_cfg_string(lcfg, 1); *flag != 0; flag++)
634 LCONSOLE_WARN("Failing over %s\n",
637 obd->obd_no_transno = 1;
638 obd->obd_no_recov = 1;
639 if (OBP(obd, iocontrol)) {
640 obd_iocontrol(OBD_IOC_SYNC,
641 obd->obd_self_export,
646 CERROR("Unrecognised flag '%c'\n", *flag);
650 LASSERT(obd->obd_self_export);
652 /* The three references that should be remaining are the
653 * obd_self_export and the attach and setup references. */
654 if (atomic_read(&obd->obd_refcount) > 3) {
655 /* refcounf - 3 might be the number of real exports
656 (excluding self export). But class_incref is called
657 by other things as well, so don't count on it. */
658 CDEBUG(D_IOCTL, "%s: forcing exports to disconnect: %d\n",
659 obd->obd_name, atomic_read(&obd->obd_refcount) - 3);
660 dump_exports(obd, 0);
661 class_disconnect_exports(obd);
664 /* Precleanup, we must make sure all exports get destroyed. */
665 err = obd_precleanup(obd, OBD_CLEANUP_EXPORTS);
667 CERROR("Precleanup %s returned %d\n",
670 /* destroy an uuid-export hash body */
671 if (obd->obd_uuid_hash) {
672 cfs_hash_putref(obd->obd_uuid_hash);
673 obd->obd_uuid_hash = NULL;
676 /* destroy a nid-export hash body */
677 if (obd->obd_nid_hash) {
678 cfs_hash_putref(obd->obd_nid_hash);
679 obd->obd_nid_hash = NULL;
682 /* destroy a nid-stats hash body */
683 if (obd->obd_nid_stats_hash) {
684 cfs_hash_putref(obd->obd_nid_stats_hash);
685 obd->obd_nid_stats_hash = NULL;
688 class_decref(obd, "setup", obd);
693 EXPORT_SYMBOL(class_cleanup);
695 struct obd_device *class_incref(struct obd_device *obd,
696 const char *scope, const void *source)
698 lu_ref_add_atomic(&obd->obd_reference, scope, source);
699 atomic_inc(&obd->obd_refcount);
700 CDEBUG(D_INFO, "incref %s (%p) now %d\n", obd->obd_name, obd,
701 atomic_read(&obd->obd_refcount));
705 EXPORT_SYMBOL(class_incref);
707 void class_decref(struct obd_device *obd, const char *scope, const void *source)
712 spin_lock(&obd->obd_dev_lock);
713 atomic_dec(&obd->obd_refcount);
714 refs = atomic_read(&obd->obd_refcount);
715 spin_unlock(&obd->obd_dev_lock);
716 lu_ref_del(&obd->obd_reference, scope, source);
718 CDEBUG(D_INFO, "Decref %s (%p) now %d\n", obd->obd_name, obd, refs);
720 if ((refs == 1) && obd->obd_stopping) {
721 /* All exports have been destroyed; there should
722 be no more in-progress ops by this point.*/
724 spin_lock(&obd->obd_self_export->exp_lock);
725 obd->obd_self_export->exp_flags |= exp_flags_from_obd(obd);
726 spin_unlock(&obd->obd_self_export->exp_lock);
728 /* note that we'll recurse into class_decref again */
729 class_unlink_export(obd->obd_self_export);
734 CDEBUG(D_CONFIG, "finishing cleanup of obd %s (%s)\n",
735 obd->obd_name, obd->obd_uuid.uuid);
736 LASSERT(!obd->obd_attached);
737 if (obd->obd_stopping) {
738 /* If we're not stopping, we were never set up */
739 err = obd_cleanup(obd);
741 CERROR("Cleanup %s returned %d\n",
745 class_release_dev(obd);
748 EXPORT_SYMBOL(class_decref);
750 /** Add a failover nid location.
751 * Client obd types contact server obd types using this nid list.
753 int class_add_conn(struct obd_device *obd, struct lustre_cfg *lcfg)
755 struct obd_import *imp;
756 struct obd_uuid uuid;
760 if (LUSTRE_CFG_BUFLEN(lcfg, 1) < 1 ||
761 LUSTRE_CFG_BUFLEN(lcfg, 1) > sizeof(struct obd_uuid)) {
762 CERROR("invalid conn_uuid\n");
765 if (strcmp(obd->obd_type->typ_name, LUSTRE_MDC_NAME) &&
766 strcmp(obd->obd_type->typ_name, LUSTRE_OSC_NAME) &&
767 strcmp(obd->obd_type->typ_name, LUSTRE_OSP_NAME) &&
768 strcmp(obd->obd_type->typ_name, LUSTRE_LWP_NAME) &&
769 strcmp(obd->obd_type->typ_name, LUSTRE_MGC_NAME)) {
770 CERROR("can't add connection on non-client dev\n");
774 imp = obd->u.cli.cl_import;
776 CERROR("try to add conn on immature client dev\n");
780 obd_str2uuid(&uuid, lustre_cfg_string(lcfg, 1));
781 rc = obd_add_conn(imp, &uuid, lcfg->lcfg_num);
785 EXPORT_SYMBOL(class_add_conn);
787 /** Remove a failover nid location.
789 int class_del_conn(struct obd_device *obd, struct lustre_cfg *lcfg)
791 struct obd_import *imp;
792 struct obd_uuid uuid;
796 if (LUSTRE_CFG_BUFLEN(lcfg, 1) < 1 ||
797 LUSTRE_CFG_BUFLEN(lcfg, 1) > sizeof(struct obd_uuid)) {
798 CERROR("invalid conn_uuid\n");
801 if (strcmp(obd->obd_type->typ_name, LUSTRE_MDC_NAME) &&
802 strcmp(obd->obd_type->typ_name, LUSTRE_OSC_NAME)) {
803 CERROR("can't del connection on non-client dev\n");
807 imp = obd->u.cli.cl_import;
809 CERROR("try to del conn on immature client dev\n");
813 obd_str2uuid(&uuid, lustre_cfg_string(lcfg, 1));
814 rc = obd_del_conn(imp, &uuid);
819 struct list_head lustre_profile_list =
820 LIST_HEAD_INIT(lustre_profile_list);
822 struct lustre_profile *class_get_profile(const char * prof)
824 struct lustre_profile *lprof;
827 list_for_each_entry(lprof, &lustre_profile_list, lp_list) {
828 if (!strcmp(lprof->lp_profile, prof)) {
834 EXPORT_SYMBOL(class_get_profile);
836 /** Create a named "profile".
837 * This defines the mdc and osc names to use for a client.
838 * This also is used to define the lov to be used by a mdt.
840 int class_add_profile(int proflen, char *prof, int osclen, char *osc,
841 int mdclen, char *mdc)
843 struct lustre_profile *lprof;
847 CDEBUG(D_CONFIG, "Add profile %s\n", prof);
849 OBD_ALLOC(lprof, sizeof(*lprof));
852 INIT_LIST_HEAD(&lprof->lp_list);
854 LASSERT(proflen == (strlen(prof) + 1));
855 OBD_ALLOC(lprof->lp_profile, proflen);
856 if (lprof->lp_profile == NULL)
857 GOTO(out, err = -ENOMEM);
858 memcpy(lprof->lp_profile, prof, proflen);
860 LASSERT(osclen == (strlen(osc) + 1));
861 OBD_ALLOC(lprof->lp_dt, osclen);
862 if (lprof->lp_dt == NULL)
863 GOTO(out, err = -ENOMEM);
864 memcpy(lprof->lp_dt, osc, osclen);
867 LASSERT(mdclen == (strlen(mdc) + 1));
868 OBD_ALLOC(lprof->lp_md, mdclen);
869 if (lprof->lp_md == NULL)
870 GOTO(out, err = -ENOMEM);
871 memcpy(lprof->lp_md, mdc, mdclen);
874 list_add(&lprof->lp_list, &lustre_profile_list);
879 OBD_FREE(lprof->lp_md, mdclen);
881 OBD_FREE(lprof->lp_dt, osclen);
882 if (lprof->lp_profile)
883 OBD_FREE(lprof->lp_profile, proflen);
884 OBD_FREE(lprof, sizeof(*lprof));
888 void class_del_profile(const char *prof)
890 struct lustre_profile *lprof;
893 CDEBUG(D_CONFIG, "Del profile %s\n", prof);
895 lprof = class_get_profile(prof);
897 list_del(&lprof->lp_list);
898 OBD_FREE(lprof->lp_profile, strlen(lprof->lp_profile) + 1);
899 OBD_FREE(lprof->lp_dt, strlen(lprof->lp_dt) + 1);
901 OBD_FREE(lprof->lp_md, strlen(lprof->lp_md) + 1);
902 OBD_FREE(lprof, sizeof *lprof);
906 EXPORT_SYMBOL(class_del_profile);
909 void class_del_profiles(void)
911 struct lustre_profile *lprof, *n;
914 list_for_each_entry_safe(lprof, n, &lustre_profile_list, lp_list) {
915 list_del(&lprof->lp_list);
916 OBD_FREE(lprof->lp_profile, strlen(lprof->lp_profile) + 1);
917 OBD_FREE(lprof->lp_dt, strlen(lprof->lp_dt) + 1);
919 OBD_FREE(lprof->lp_md, strlen(lprof->lp_md) + 1);
920 OBD_FREE(lprof, sizeof *lprof);
924 EXPORT_SYMBOL(class_del_profiles);
926 static int class_set_global(char *ptr, int val, struct lustre_cfg *lcfg)
929 if (class_match_param(ptr, PARAM_AT_MIN, NULL) == 0)
931 else if (class_match_param(ptr, PARAM_AT_MAX, NULL) == 0)
933 else if (class_match_param(ptr, PARAM_AT_EXTRA, NULL) == 0)
935 else if (class_match_param(ptr, PARAM_AT_EARLY_MARGIN, NULL) == 0)
936 at_early_margin = val;
937 else if (class_match_param(ptr, PARAM_AT_HISTORY, NULL) == 0)
939 else if (class_match_param(ptr, PARAM_JOBID_VAR, NULL) == 0)
940 strlcpy(obd_jobid_var, lustre_cfg_string(lcfg, 2),
941 JOBSTATS_JOBID_VAR_MAX_LEN + 1);
945 CDEBUG(D_IOCTL, "global %s = %d\n", ptr, val);
950 /* We can't call ll_process_config or lquota_process_config directly because
951 * it lives in a module that must be loaded after this one. */
952 static int (*client_process_config)(struct lustre_cfg *lcfg) = NULL;
953 static int (*quota_process_config)(struct lustre_cfg *lcfg) = NULL;
955 void lustre_register_client_process_config(int (*cpc)(struct lustre_cfg *lcfg))
957 client_process_config = cpc;
959 EXPORT_SYMBOL(lustre_register_client_process_config);
962 * Rename the proc parameter in \a cfg with a new name \a new_name.
964 * \param cfg config structure which contains the proc parameter
965 * \param new_name new name of the proc parameter
967 * \retval valid-pointer pointer to the newly-allocated config structure
968 * which contains the renamed proc parameter
969 * \retval ERR_PTR(-EINVAL) if \a cfg or \a new_name is NULL, or \a cfg does
970 * not contain a proc parameter
971 * \retval ERR_PTR(-ENOMEM) if memory allocation failure occurs
973 struct lustre_cfg *lustre_cfg_rename(struct lustre_cfg *cfg,
974 const char *new_name)
976 struct lustre_cfg_bufs *bufs = NULL;
977 struct lustre_cfg *new_cfg = NULL;
979 char *new_param = NULL;
985 if (cfg == NULL || new_name == NULL)
986 RETURN(ERR_PTR(-EINVAL));
988 param = lustre_cfg_string(cfg, 1);
990 RETURN(ERR_PTR(-EINVAL));
992 value = strchr(param, '=');
994 name_len = strlen(param);
996 name_len = value - param;
998 new_len = LUSTRE_CFG_BUFLEN(cfg, 1) + strlen(new_name) - name_len;
1000 OBD_ALLOC(new_param, new_len);
1001 if (new_param == NULL)
1002 RETURN(ERR_PTR(-ENOMEM));
1004 strcpy(new_param, new_name);
1006 strcat(new_param, value);
1008 OBD_ALLOC_PTR(bufs);
1010 OBD_FREE(new_param, new_len);
1011 RETURN(ERR_PTR(-ENOMEM));
1014 lustre_cfg_bufs_reset(bufs, NULL);
1015 lustre_cfg_bufs_init(bufs, cfg);
1016 lustre_cfg_bufs_set_string(bufs, 1, new_param);
1018 new_cfg = lustre_cfg_new(cfg->lcfg_command, bufs);
1020 OBD_FREE(new_param, new_len);
1022 if (new_cfg == NULL)
1023 RETURN(ERR_PTR(-ENOMEM));
1025 new_cfg->lcfg_num = cfg->lcfg_num;
1026 new_cfg->lcfg_flags = cfg->lcfg_flags;
1027 new_cfg->lcfg_nid = cfg->lcfg_nid;
1028 new_cfg->lcfg_nal = cfg->lcfg_nal;
1032 EXPORT_SYMBOL(lustre_cfg_rename);
1034 static int process_param2_config(struct lustre_cfg *lcfg)
1036 char *param = lustre_cfg_string(lcfg, 1);
1037 char *upcall = lustre_cfg_string(lcfg, 2);
1039 [0] = "/usr/sbin/lctl",
1044 struct timeval start;
1049 /* Add upcall processing here. Now only lctl is supported */
1050 if (strcmp(upcall, LCTL_UPCALL) != 0) {
1051 CERROR("Unsupported upcall %s\n", upcall);
1055 do_gettimeofday(&start);
1056 rc = call_usermodehelper(argv[0], argv, NULL, 0);
1057 do_gettimeofday(&end);
1060 CERROR("lctl: error invoking upcall %s %s %s: rc = %d; "
1061 "time %ldus\n", argv[0], argv[1], argv[2], rc,
1062 cfs_timeval_sub(&end, &start, NULL));
1064 CDEBUG(D_HA, "lctl: invoked upcall %s %s %s, time %ldus\n",
1065 argv[0], argv[1], argv[2],
1066 cfs_timeval_sub(&end, &start, NULL));
1073 void lustre_register_quota_process_config(int (*qpc)(struct lustre_cfg *lcfg))
1075 quota_process_config = qpc;
1077 EXPORT_SYMBOL(lustre_register_quota_process_config);
1079 /** Process configuration commands given in lustre_cfg form.
1080 * These may come from direct calls (e.g. class_manual_cleanup)
1081 * or processing the config llog, or ioctl from lctl.
1083 int class_process_config(struct lustre_cfg *lcfg)
1085 struct obd_device *obd;
1088 LASSERT(lcfg && !IS_ERR(lcfg));
1089 CDEBUG(D_IOCTL, "processing cmd: %x\n", lcfg->lcfg_command);
1091 /* Commands that don't need a device */
1092 switch(lcfg->lcfg_command) {
1094 err = class_attach(lcfg);
1097 case LCFG_ADD_UUID: {
1098 CDEBUG(D_IOCTL, "adding mapping from uuid %s to nid "LPX64
1099 " (%s)\n", lustre_cfg_string(lcfg, 1),
1100 lcfg->lcfg_nid, libcfs_nid2str(lcfg->lcfg_nid));
1102 err = class_add_uuid(lustre_cfg_string(lcfg, 1), lcfg->lcfg_nid);
1105 case LCFG_DEL_UUID: {
1106 CDEBUG(D_IOCTL, "removing mappings for uuid %s\n",
1107 (lcfg->lcfg_bufcount < 2 || LUSTRE_CFG_BUFLEN(lcfg, 1) == 0)
1108 ? "<all uuids>" : lustre_cfg_string(lcfg, 1));
1110 err = class_del_uuid(lustre_cfg_string(lcfg, 1));
1113 case LCFG_MOUNTOPT: {
1114 CDEBUG(D_IOCTL, "mountopt: profile %s osc %s mdc %s\n",
1115 lustre_cfg_string(lcfg, 1),
1116 lustre_cfg_string(lcfg, 2),
1117 lustre_cfg_string(lcfg, 3));
1118 /* set these mount options somewhere, so ll_fill_super
1120 err = class_add_profile(LUSTRE_CFG_BUFLEN(lcfg, 1),
1121 lustre_cfg_string(lcfg, 1),
1122 LUSTRE_CFG_BUFLEN(lcfg, 2),
1123 lustre_cfg_string(lcfg, 2),
1124 LUSTRE_CFG_BUFLEN(lcfg, 3),
1125 lustre_cfg_string(lcfg, 3));
1128 case LCFG_DEL_MOUNTOPT: {
1129 CDEBUG(D_IOCTL, "mountopt: profile %s\n",
1130 lustre_cfg_string(lcfg, 1));
1131 class_del_profile(lustre_cfg_string(lcfg, 1));
1134 case LCFG_SET_TIMEOUT: {
1135 CDEBUG(D_IOCTL, "changing lustre timeout from %d to %d\n",
1136 obd_timeout, lcfg->lcfg_num);
1137 obd_timeout = max(lcfg->lcfg_num, 1U);
1138 obd_timeout_set = 1;
1141 case LCFG_SET_LDLM_TIMEOUT: {
1142 CDEBUG(D_IOCTL, "changing lustre ldlm_timeout from %d to %d\n",
1143 ldlm_timeout, lcfg->lcfg_num);
1144 ldlm_timeout = max(lcfg->lcfg_num, 1U);
1145 if (ldlm_timeout >= obd_timeout)
1146 ldlm_timeout = max(obd_timeout / 3, 1U);
1147 ldlm_timeout_set = 1;
1150 case LCFG_SET_UPCALL: {
1151 LCONSOLE_ERROR_MSG(0x15a, "recovery upcall is deprecated\n");
1152 /* COMPAT_146 Don't fail on old configs */
1156 struct cfg_marker *marker;
1157 marker = lustre_cfg_buf(lcfg, 1);
1158 CDEBUG(D_IOCTL, "marker %d (%#x) %.16s %s\n", marker->cm_step,
1159 marker->cm_flags, marker->cm_tgtname, marker->cm_comment);
1164 /* llite has no obd */
1165 if ((class_match_param(lustre_cfg_string(lcfg, 1),
1166 PARAM_LLITE, 0) == 0) &&
1167 client_process_config) {
1168 err = (*client_process_config)(lcfg);
1170 } else if ((class_match_param(lustre_cfg_string(lcfg, 1),
1171 PARAM_SYS, &tmp) == 0)) {
1172 /* Global param settings */
1173 err = class_set_global(tmp, lcfg->lcfg_num, lcfg);
1175 * Client or server should not fail to mount if
1176 * it hits an unknown configuration parameter.
1179 CWARN("Ignoring unknown param %s\n", tmp);
1182 } else if ((class_match_param(lustre_cfg_string(lcfg, 1),
1183 PARAM_QUOTA, &tmp) == 0) &&
1184 quota_process_config) {
1185 err = (*quota_process_config)(lcfg);
1191 case LCFG_SET_PARAM: {
1192 err = process_param2_config(lcfg);
1196 /* Commands that require a device */
1197 obd = class_name2obd(lustre_cfg_string(lcfg, 0));
1199 if (!LUSTRE_CFG_BUFLEN(lcfg, 0))
1200 CERROR("this lcfg command requires a device name\n");
1202 CERROR("no device for: %s\n",
1203 lustre_cfg_string(lcfg, 0));
1205 GOTO(out, err = -EINVAL);
1208 switch(lcfg->lcfg_command) {
1210 err = class_setup(obd, lcfg);
1214 err = class_detach(obd, lcfg);
1217 case LCFG_CLEANUP: {
1218 err = class_cleanup(obd, lcfg);
1221 case LCFG_ADD_CONN: {
1222 err = class_add_conn(obd, lcfg);
1225 case LCFG_DEL_CONN: {
1226 err = class_del_conn(obd, lcfg);
1229 case LCFG_POOL_NEW: {
1230 err = obd_pool_new(obd, lustre_cfg_string(lcfg, 2));
1233 case LCFG_POOL_ADD: {
1234 err = obd_pool_add(obd, lustre_cfg_string(lcfg, 2),
1235 lustre_cfg_string(lcfg, 3));
1238 case LCFG_POOL_REM: {
1239 err = obd_pool_rem(obd, lustre_cfg_string(lcfg, 2),
1240 lustre_cfg_string(lcfg, 3));
1243 case LCFG_POOL_DEL: {
1244 err = obd_pool_del(obd, lustre_cfg_string(lcfg, 2));
1248 err = obd_process_config(obd, sizeof(*lcfg), lcfg);
1254 if ((err < 0) && !(lcfg->lcfg_command & LCFG_REQUIRED)) {
1255 CWARN("Ignoring error %d on optional command %#x\n", err,
1256 lcfg->lcfg_command);
1261 EXPORT_SYMBOL(class_process_config);
1263 int class_process_proc_param(char *prefix, struct lprocfs_seq_vars *lvars,
1264 struct lustre_cfg *lcfg, void *data)
1266 struct lprocfs_seq_vars *var;
1267 struct file fakefile;
1268 struct seq_file fake_seqfile;
1270 int i, keylen, vallen;
1271 int matched = 0, j = 0;
1276 if (lcfg->lcfg_command != LCFG_PARAM) {
1277 CERROR("Unknown command: %d\n", lcfg->lcfg_command);
1281 /* fake a seq file so that var->fops->write can work... */
1282 fakefile.private_data = &fake_seqfile;
1283 fake_seqfile.private = data;
1284 /* e.g. tunefs.lustre --param mdt.group_upcall=foo /r/tmp/lustre-mdt
1285 or lctl conf_param lustre-MDT0000.mdt.group_upcall=bar
1286 or lctl conf_param lustre-OST0000.osc.max_dirty_mb=36 */
1287 for (i = 1; i < lcfg->lcfg_bufcount; i++) {
1288 key = lustre_cfg_buf(lcfg, i);
1289 /* Strip off prefix */
1290 if (class_match_param(key, prefix, &key))
1291 /* If the prefix doesn't match, return error so we
1292 * can pass it down the stack */
1294 sval = strchr(key, '=');
1295 if (!sval || (*(sval + 1) == 0)) {
1296 CERROR("Can't parse param %s (missing '=')\n", key);
1297 /* rc = -EINVAL; continue parsing other params */
1300 keylen = sval - key;
1302 vallen = strlen(sval);
1305 /* Search proc entries */
1306 while (lvars[j].name) {
1308 if (class_match_param(key, (char *)var->name, 0) == 0 &&
1309 keylen == strlen(var->name)) {
1313 if (var->fops && var->fops->write) {
1317 rc = (var->fops->write)(&fakefile, sval,
1326 CERROR("%.*s: %s unknown param %s\n",
1327 (int)strlen(prefix) - 1, prefix,
1328 (char *)lustre_cfg_string(lcfg, 0), key);
1329 /* rc = -EINVAL; continue parsing other params */
1331 } else if (rc < 0) {
1332 CERROR("%s: error writing proc entry '%s': rc = %d\n",
1333 prefix, var->name, rc);
1336 CDEBUG(D_CONFIG, "%s.%.*s: Set parameter %.*s=%s\n",
1337 lustre_cfg_string(lcfg, 0),
1338 (int)strlen(prefix) - 1, prefix,
1339 (int)(sval - key - 1), key, sval);
1349 EXPORT_SYMBOL(class_process_proc_param);
1351 extern int lustre_check_exclusion(struct super_block *sb, char *svname);
1354 * Supplemental functions for config logs, it allocates lustre_cfg
1355 * buffers plus initialized llog record header at the beginning.
1357 struct llog_cfg_rec *lustre_cfg_rec_new(int cmd, struct lustre_cfg_bufs *bufs)
1359 struct llog_cfg_rec *lcr;
1364 reclen = lustre_cfg_len(bufs->lcfg_bufcount, bufs->lcfg_buflen);
1365 reclen = llog_data_len(reclen) + sizeof(struct llog_rec_hdr) +
1366 sizeof(struct llog_rec_tail);
1368 OBD_ALLOC(lcr, reclen);
1372 lustre_cfg_init(&lcr->lcr_cfg, cmd, bufs);
1374 lcr->lcr_hdr.lrh_len = reclen;
1375 lcr->lcr_hdr.lrh_type = OBD_CFG_REC;
1379 EXPORT_SYMBOL(lustre_cfg_rec_new);
1381 void lustre_cfg_rec_free(struct llog_cfg_rec *lcr)
1384 OBD_FREE(lcr, lcr->lcr_hdr.lrh_len);
1387 EXPORT_SYMBOL(lustre_cfg_rec_free);
1389 /** Parse a configuration llog, doing various manipulations on them
1390 * for various reasons, (modifications for compatibility, skip obsolete
1391 * records, change uuids, etc), then class_process_config() resulting
1394 int class_config_llog_handler(const struct lu_env *env,
1395 struct llog_handle *handle,
1396 struct llog_rec_hdr *rec, void *data)
1398 struct config_llog_instance *clli = data;
1399 int cfg_len = rec->lrh_len;
1400 char *cfg_buf = (char*) (rec + 1);
1404 //class_config_dump_handler(handle, rec, data);
1406 switch (rec->lrh_type) {
1408 struct lustre_cfg *lcfg, *lcfg_new;
1409 struct lustre_cfg_bufs bufs;
1410 char *inst_name = NULL;
1412 int inst = 0, swab = 0;
1414 lcfg = (struct lustre_cfg *)cfg_buf;
1415 if (lcfg->lcfg_version == __swab32(LUSTRE_CFG_VERSION)) {
1416 lustre_swab_lustre_cfg(lcfg);
1420 rc = lustre_cfg_sanity_check(cfg_buf, cfg_len);
1424 /* Figure out config state info */
1425 if (lcfg->lcfg_command == LCFG_MARKER) {
1426 struct cfg_marker *marker = lustre_cfg_buf(lcfg, 1);
1427 lustre_swab_cfg_marker(marker, swab,
1428 LUSTRE_CFG_BUFLEN(lcfg, 1));
1429 CDEBUG(D_CONFIG, "Marker, inst_flg=%#x mark_flg=%#x\n",
1430 clli->cfg_flags, marker->cm_flags);
1431 if (marker->cm_flags & CM_START) {
1432 /* all previous flags off */
1433 clli->cfg_flags = CFG_F_MARKER;
1434 server_name2index(marker->cm_tgtname,
1435 &clli->cfg_lwp_idx, NULL);
1436 if (marker->cm_flags & CM_SKIP) {
1437 clli->cfg_flags |= CFG_F_SKIP;
1438 CDEBUG(D_CONFIG, "SKIP #%d\n",
1440 } else if ((marker->cm_flags & CM_EXCLUDE) ||
1442 lustre_check_exclusion(clli->cfg_sb,
1443 marker->cm_tgtname))) {
1444 clli->cfg_flags |= CFG_F_EXCLUDE;
1445 CDEBUG(D_CONFIG, "EXCLUDE %d\n",
1448 } else if (marker->cm_flags & CM_END) {
1449 clli->cfg_flags = 0;
1452 /* A config command without a start marker before it is
1453 illegal (post 146) */
1454 if (!(clli->cfg_flags & CFG_F_COMPAT146) &&
1455 !(clli->cfg_flags & CFG_F_MARKER) &&
1456 (lcfg->lcfg_command != LCFG_MARKER)) {
1457 CWARN("Config not inside markers, ignoring! "
1458 "(inst: %p, uuid: %s, flags: %#x)\n",
1460 clli->cfg_uuid.uuid, clli->cfg_flags);
1461 clli->cfg_flags |= CFG_F_SKIP;
1463 if (clli->cfg_flags & CFG_F_SKIP) {
1464 CDEBUG(D_CONFIG, "skipping %#x\n",
1467 /* No processing! */
1472 * For interoperability between 1.8 and 2.0,
1473 * rename "mds" obd device type to "mdt".
1476 char *typename = lustre_cfg_string(lcfg, 1);
1477 char *index = lustre_cfg_string(lcfg, 2);
1479 if ((lcfg->lcfg_command == LCFG_ATTACH && typename &&
1480 strcmp(typename, "mds") == 0)) {
1481 CWARN("For 1.8 interoperability, rename obd "
1482 "type from mds to mdt\n");
1485 if ((lcfg->lcfg_command == LCFG_SETUP && index &&
1486 strcmp(index, "type") == 0)) {
1487 CDEBUG(D_INFO, "For 1.8 interoperability, "
1488 "set this index to '0'\n");
1494 #ifdef HAVE_SERVER_SUPPORT
1495 /* newer MDS replaces LOV/OSC with LOD/OSP */
1497 char *typename = lustre_cfg_string(lcfg, 1);
1499 if ((lcfg->lcfg_command == LCFG_ATTACH && typename &&
1500 strcmp(typename, LUSTRE_LOV_NAME) == 0) &&
1501 IS_MDT(s2lsi(clli->cfg_sb))) {
1503 "For 2.x interoperability, rename obd "
1504 "type from lov to lod (%s)\n",
1505 s2lsi(clli->cfg_sb)->lsi_svname);
1506 strcpy(typename, LUSTRE_LOD_NAME);
1508 if ((lcfg->lcfg_command == LCFG_ATTACH && typename &&
1509 strcmp(typename, LUSTRE_OSC_NAME) == 0) &&
1510 IS_MDT(s2lsi(clli->cfg_sb))) {
1512 "For 2.x interoperability, rename obd "
1513 "type from osc to osp (%s)\n",
1514 s2lsi(clli->cfg_sb)->lsi_svname);
1515 strcpy(typename, LUSTRE_OSP_NAME);
1518 #endif /* HAVE_SERVER_SUPPORT */
1520 if (clli->cfg_flags & CFG_F_EXCLUDE) {
1521 CDEBUG(D_CONFIG, "cmd: %x marked EXCLUDED\n",
1522 lcfg->lcfg_command);
1523 if (lcfg->lcfg_command == LCFG_LOV_ADD_OBD)
1524 /* Add inactive instead */
1525 lcfg->lcfg_command = LCFG_LOV_ADD_INA;
1528 lustre_cfg_bufs_init(&bufs, lcfg);
1530 if (clli && clli->cfg_instance &&
1531 LUSTRE_CFG_BUFLEN(lcfg, 0) > 0){
1533 inst_len = LUSTRE_CFG_BUFLEN(lcfg, 0) +
1534 sizeof(clli->cfg_instance) * 2 + 4;
1535 OBD_ALLOC(inst_name, inst_len);
1536 if (inst_name == NULL)
1537 GOTO(out, rc = -ENOMEM);
1538 sprintf(inst_name, "%s-%p",
1539 lustre_cfg_string(lcfg, 0),
1540 clli->cfg_instance);
1541 lustre_cfg_bufs_set_string(&bufs, 0, inst_name);
1542 CDEBUG(D_CONFIG, "cmd %x, instance name: %s\n",
1543 lcfg->lcfg_command, inst_name);
1546 /* we override the llog's uuid for clients, to insure they
1548 if (clli && clli->cfg_instance != NULL &&
1549 lcfg->lcfg_command == LCFG_ATTACH) {
1550 lustre_cfg_bufs_set_string(&bufs, 2,
1551 clli->cfg_uuid.uuid);
1554 * sptlrpc config record, we expect 2 data segments:
1555 * [0]: fs_name/target_name,
1557 * moving them to index [1] and [2], and insert MGC's
1558 * obdname at index [0].
1560 if (clli && clli->cfg_instance == NULL &&
1561 lcfg->lcfg_command == LCFG_SPTLRPC_CONF) {
1562 lustre_cfg_bufs_set(&bufs, 2, bufs.lcfg_buf[1],
1563 bufs.lcfg_buflen[1]);
1564 lustre_cfg_bufs_set(&bufs, 1, bufs.lcfg_buf[0],
1565 bufs.lcfg_buflen[0]);
1566 lustre_cfg_bufs_set_string(&bufs, 0,
1570 lcfg_new = lustre_cfg_new(lcfg->lcfg_command, &bufs);
1571 if (lcfg_new == NULL)
1572 GOTO(out, rc = -ENOMEM);
1574 lcfg_new->lcfg_num = lcfg->lcfg_num;
1575 lcfg_new->lcfg_flags = lcfg->lcfg_flags;
1577 /* XXX Hack to try to remain binary compatible with
1578 * pre-newconfig logs */
1579 if (lcfg->lcfg_nal != 0 && /* pre-newconfig log? */
1580 (lcfg->lcfg_nid >> 32) == 0) {
1581 __u32 addr = (__u32)(lcfg->lcfg_nid & 0xffffffff);
1583 lcfg_new->lcfg_nid =
1584 LNET_MKNID(LNET_MKNET(lcfg->lcfg_nal, 0), addr);
1585 CWARN("Converted pre-newconfig NAL %d NID %x to %s\n",
1586 lcfg->lcfg_nal, addr,
1587 libcfs_nid2str(lcfg_new->lcfg_nid));
1589 lcfg_new->lcfg_nid = lcfg->lcfg_nid;
1592 lcfg_new->lcfg_nal = 0; /* illegal value for obsolete field */
1594 rc = class_process_config(lcfg_new);
1595 lustre_cfg_free(lcfg_new);
1598 OBD_FREE(inst_name, inst_len);
1602 CERROR("Unknown llog record type %#x encountered\n",
1608 CERROR("%s: cfg command failed: rc = %d\n",
1609 handle->lgh_ctxt->loc_obd->obd_name, rc);
1610 class_config_dump_handler(NULL, handle, rec, data);
1614 EXPORT_SYMBOL(class_config_llog_handler);
1616 int class_config_parse_llog(const struct lu_env *env, struct llog_ctxt *ctxt,
1617 char *name, struct config_llog_instance *cfg)
1619 struct llog_process_cat_data cd = {0, 0};
1620 struct llog_handle *llh;
1625 CDEBUG(D_INFO, "looking up llog %s\n", name);
1626 rc = llog_open(env, ctxt, &llh, NULL, name, LLOG_OPEN_EXISTS);
1630 rc = llog_init_handle(env, llh, LLOG_F_IS_PLAIN, NULL);
1632 GOTO(parse_out, rc);
1634 /* continue processing from where we last stopped to end-of-log */
1636 cd.lpcd_first_idx = cfg->cfg_last_idx;
1637 callback = cfg->cfg_callback;
1638 LASSERT(callback != NULL);
1640 callback = class_config_llog_handler;
1643 cd.lpcd_last_idx = 0;
1645 rc = llog_process(env, llh, callback, cfg, &cd);
1647 CDEBUG(D_CONFIG, "Processed log %s gen %d-%d (rc=%d)\n", name,
1648 cd.lpcd_first_idx + 1, cd.lpcd_last_idx, rc);
1650 cfg->cfg_last_idx = cd.lpcd_last_idx;
1653 llog_close(env, llh);
1656 EXPORT_SYMBOL(class_config_parse_llog);
1658 struct lcfg_type_data {
1662 } lcfg_data_table[] = {
1663 { LCFG_ATTACH, "attach", { "type", "UUID", "3", "4" } },
1664 { LCFG_DETACH, "detach", { "1", "2", "3", "4" } },
1665 { LCFG_SETUP, "setup", { "UUID", "node", "options", "failout" } },
1666 { LCFG_CLEANUP, "cleanup", { "1", "2", "3", "4" } },
1667 { LCFG_ADD_UUID, "add_uuid", { "node", "2", "3", "4" } },
1668 { LCFG_DEL_UUID, "del_uuid", { "1", "2", "3", "4" } },
1669 { LCFG_MOUNTOPT, "new_profile", { "name", "lov", "lmv", "4" } },
1670 { LCFG_DEL_MOUNTOPT, "del_mountopt", { "1", "2", "3", "4" } , },
1671 { LCFG_SET_TIMEOUT, "set_timeout", { "parameter", "2", "3", "4" } },
1672 { LCFG_SET_UPCALL, "set_upcall", { "1", "2", "3", "4" } },
1673 { LCFG_ADD_CONN, "add_conn", { "node", "2", "3", "4" } },
1674 { LCFG_DEL_CONN, "del_conn", { "1", "2", "3", "4" } },
1675 { LCFG_LOV_ADD_OBD, "add_osc", { "ost", "index", "gen", "UUID" } },
1676 { LCFG_LOV_DEL_OBD, "del_osc", { "1", "2", "3", "4" } },
1677 { LCFG_PARAM, "set_param", { "parameter", "value", "3", "4" } },
1678 { LCFG_MARKER, "marker", { "1", "2", "3", "4" } },
1679 { LCFG_LOG_START, "log_start", { "1", "2", "3", "4" } },
1680 { LCFG_LOG_END, "log_end", { "1", "2", "3", "4" } },
1681 { LCFG_LOV_ADD_INA, "add_osc_inactive", { "1", "2", "3", "4" } },
1682 { LCFG_ADD_MDC, "add_mdc", { "mdt", "index", "gen", "UUID" } },
1683 { LCFG_DEL_MDC, "del_mdc", { "1", "2", "3", "4" } },
1684 { LCFG_SPTLRPC_CONF, "security", { "parameter", "2", "3", "4" } },
1685 { LCFG_POOL_NEW, "new_pool", { "fsname", "pool", "3", "4" } },
1686 { LCFG_POOL_ADD, "add_pool", { "fsname", "pool", "ost", "4" } },
1687 { LCFG_POOL_REM, "remove_pool", { "fsname", "pool", "ost", "4" } },
1688 { LCFG_POOL_DEL, "del_pool", { "fsname", "pool", "3", "4" } },
1689 { LCFG_SET_LDLM_TIMEOUT, "set_ldlm_timeout",
1690 { "parameter", "2", "3", "4" } },
1691 { 0, NULL, { NULL, NULL, NULL, NULL } }
1694 static struct lcfg_type_data *lcfg_cmd2data(__u32 cmd)
1698 while (lcfg_data_table[i].ltd_type != 0) {
1699 if (lcfg_data_table[i].ltd_type == cmd)
1700 return &lcfg_data_table[i];
1707 * parse config record and output dump in supplied buffer.
1708 * This is separated from class_config_dump_handler() to use
1709 * for ioctl needs as well
1712 * - { event: attach, device: lustrewt-clilov, type: lov, UUID:
1713 * lustrewt-clilov_UUID }
1715 int class_config_yaml_output(struct llog_rec_hdr *rec, char *buf, int size)
1717 struct lustre_cfg *lcfg = (struct lustre_cfg *)(rec + 1);
1719 char *end = buf + size;
1721 struct lcfg_type_data *ldata;
1723 LASSERT(rec->lrh_type == OBD_CFG_REC);
1724 rc = lustre_cfg_sanity_check(lcfg, rec->lrh_len);
1728 ldata = lcfg_cmd2data(lcfg->lcfg_command);
1732 if (lcfg->lcfg_command == LCFG_MARKER)
1735 /* form YAML entity */
1736 ptr += snprintf(ptr, end - ptr, "- { event: %s", ldata->ltd_name);
1738 if (lcfg->lcfg_flags)
1739 ptr += snprintf(ptr, end - ptr, ", flags: %#08x",
1742 ptr += snprintf(ptr, end - ptr, ", num: %#08x",
1745 ptr += snprintf(ptr, end - ptr, ", nid: %s("LPX64")",
1746 libcfs_nid2str(lcfg->lcfg_nid),
1749 if (LUSTRE_CFG_BUFLEN(lcfg, 0) > 0)
1750 ptr += snprintf(ptr, end - ptr, ", device: %s",
1751 lustre_cfg_string(lcfg, 0));
1753 for (i = 1; i < lcfg->lcfg_bufcount; i++) {
1754 if (LUSTRE_CFG_BUFLEN(lcfg, i) > 0)
1755 ptr += snprintf(ptr, end - ptr, ", %s: %s",
1756 ldata->ltd_bufs[i - 1],
1757 lustre_cfg_string(lcfg, i));
1760 ptr += snprintf(ptr, end - ptr, " }\n");
1761 /* return consumed bytes */
1767 * parse config record and output dump in supplied buffer.
1768 * This is separated from class_config_dump_handler() to use
1769 * for ioctl needs as well
1771 int class_config_parse_rec(struct llog_rec_hdr *rec, char *buf, int size)
1773 struct lustre_cfg *lcfg = (struct lustre_cfg *)(rec + 1);
1775 char *end = buf + size;
1780 LASSERT(rec->lrh_type == OBD_CFG_REC);
1781 rc = lustre_cfg_sanity_check(lcfg, rec->lrh_len);
1785 ptr += snprintf(ptr, end-ptr, "cmd=%05x ", lcfg->lcfg_command);
1786 if (lcfg->lcfg_flags)
1787 ptr += snprintf(ptr, end-ptr, "flags=%#08x ",
1791 ptr += snprintf(ptr, end-ptr, "num=%#08x ", lcfg->lcfg_num);
1794 ptr += snprintf(ptr, end-ptr, "nid=%s("LPX64")\n ",
1795 libcfs_nid2str(lcfg->lcfg_nid),
1798 if (lcfg->lcfg_command == LCFG_MARKER) {
1799 struct cfg_marker *marker = lustre_cfg_buf(lcfg, 1);
1801 ptr += snprintf(ptr, end-ptr, "marker=%d(%#x)%s '%s'",
1802 marker->cm_step, marker->cm_flags,
1803 marker->cm_tgtname, marker->cm_comment);
1807 for (i = 0; i < lcfg->lcfg_bufcount; i++) {
1808 ptr += snprintf(ptr, end-ptr, "%d:%s ", i,
1809 lustre_cfg_string(lcfg, i));
1812 ptr += snprintf(ptr, end - ptr, "\n");
1813 /* return consumed bytes */
1818 int class_config_dump_handler(const struct lu_env *env,
1819 struct llog_handle *handle,
1820 struct llog_rec_hdr *rec, void *data)
1827 OBD_ALLOC(outstr, 256);
1831 if (rec->lrh_type == OBD_CFG_REC) {
1832 class_config_parse_rec(rec, outstr, 256);
1833 LCONSOLE(D_WARNING, " %s\n", outstr);
1835 LCONSOLE(D_WARNING, "unhandled lrh_type: %#x\n", rec->lrh_type);
1839 OBD_FREE(outstr, 256);
1843 int class_config_dump_llog(const struct lu_env *env, struct llog_ctxt *ctxt,
1844 char *name, struct config_llog_instance *cfg)
1846 struct llog_handle *llh;
1851 LCONSOLE_INFO("Dumping config log %s\n", name);
1853 rc = llog_open(env, ctxt, &llh, NULL, name, LLOG_OPEN_EXISTS);
1857 rc = llog_init_handle(env, llh, LLOG_F_IS_PLAIN, NULL);
1859 GOTO(parse_out, rc);
1861 rc = llog_process(env, llh, class_config_dump_handler, cfg, NULL);
1863 llog_close(env, llh);
1865 LCONSOLE_INFO("End config log %s\n", name);
1868 EXPORT_SYMBOL(class_config_dump_llog);
1870 /** Call class_cleanup and class_detach.
1871 * "Manual" only in the sense that we're faking lcfg commands.
1873 int class_manual_cleanup(struct obd_device *obd)
1876 struct lustre_cfg *lcfg;
1877 struct lustre_cfg_bufs bufs;
1882 CERROR("empty cleanup\n");
1891 CDEBUG(D_CONFIG, "Manual cleanup of %s (flags='%s')\n",
1892 obd->obd_name, flags);
1894 lustre_cfg_bufs_reset(&bufs, obd->obd_name);
1895 lustre_cfg_bufs_set_string(&bufs, 1, flags);
1896 lcfg = lustre_cfg_new(LCFG_CLEANUP, &bufs);
1900 rc = class_process_config(lcfg);
1902 CERROR("cleanup failed %d: %s\n", rc, obd->obd_name);
1906 /* the lcfg is almost the same for both ops */
1907 lcfg->lcfg_command = LCFG_DETACH;
1908 rc = class_process_config(lcfg);
1910 CERROR("detach failed %d: %s\n", rc, obd->obd_name);
1912 lustre_cfg_free(lcfg);
1915 EXPORT_SYMBOL(class_manual_cleanup);
1918 * uuid<->export lustre hash operations
1922 uuid_hash(cfs_hash_t *hs, const void *key, unsigned mask)
1924 return cfs_hash_djb2_hash(((struct obd_uuid *)key)->uuid,
1925 sizeof(((struct obd_uuid *)key)->uuid), mask);
1929 uuid_key(struct hlist_node *hnode)
1931 struct obd_export *exp;
1933 exp = hlist_entry(hnode, struct obd_export, exp_uuid_hash);
1935 return &exp->exp_client_uuid;
1939 * NOTE: It is impossible to find an export that is in failed
1940 * state with this function
1943 uuid_keycmp(const void *key, struct hlist_node *hnode)
1945 struct obd_export *exp;
1948 exp = hlist_entry(hnode, struct obd_export, exp_uuid_hash);
1950 return obd_uuid_equals(key, &exp->exp_client_uuid) &&
1955 uuid_export_object(struct hlist_node *hnode)
1957 return hlist_entry(hnode, struct obd_export, exp_uuid_hash);
1961 uuid_export_get(cfs_hash_t *hs, struct hlist_node *hnode)
1963 struct obd_export *exp;
1965 exp = hlist_entry(hnode, struct obd_export, exp_uuid_hash);
1966 class_export_get(exp);
1970 uuid_export_put_locked(cfs_hash_t *hs, struct hlist_node *hnode)
1972 struct obd_export *exp;
1974 exp = hlist_entry(hnode, struct obd_export, exp_uuid_hash);
1975 class_export_put(exp);
1978 static cfs_hash_ops_t uuid_hash_ops = {
1979 .hs_hash = uuid_hash,
1981 .hs_keycmp = uuid_keycmp,
1982 .hs_object = uuid_export_object,
1983 .hs_get = uuid_export_get,
1984 .hs_put_locked = uuid_export_put_locked,
1989 * nid<->export hash operations
1993 nid_hash(cfs_hash_t *hs, const void *key, unsigned mask)
1995 return cfs_hash_djb2_hash(key, sizeof(lnet_nid_t), mask);
1999 nid_key(struct hlist_node *hnode)
2001 struct obd_export *exp;
2003 exp = hlist_entry(hnode, struct obd_export, exp_nid_hash);
2005 RETURN(&exp->exp_connection->c_peer.nid);
2009 * NOTE: It is impossible to find an export that is in failed
2010 * state with this function
2013 nid_kepcmp(const void *key, struct hlist_node *hnode)
2015 struct obd_export *exp;
2018 exp = hlist_entry(hnode, struct obd_export, exp_nid_hash);
2020 RETURN(exp->exp_connection->c_peer.nid == *(lnet_nid_t *)key &&
2025 nid_export_object(struct hlist_node *hnode)
2027 return hlist_entry(hnode, struct obd_export, exp_nid_hash);
2031 nid_export_get(cfs_hash_t *hs, struct hlist_node *hnode)
2033 struct obd_export *exp;
2035 exp = hlist_entry(hnode, struct obd_export, exp_nid_hash);
2036 class_export_get(exp);
2040 nid_export_put_locked(cfs_hash_t *hs, struct hlist_node *hnode)
2042 struct obd_export *exp;
2044 exp = hlist_entry(hnode, struct obd_export, exp_nid_hash);
2045 class_export_put(exp);
2048 static cfs_hash_ops_t nid_hash_ops = {
2049 .hs_hash = nid_hash,
2051 .hs_keycmp = nid_kepcmp,
2052 .hs_object = nid_export_object,
2053 .hs_get = nid_export_get,
2054 .hs_put_locked = nid_export_put_locked,
2059 * nid<->nidstats hash operations
2063 nidstats_key(struct hlist_node *hnode)
2065 struct nid_stat *ns;
2067 ns = hlist_entry(hnode, struct nid_stat, nid_hash);
2073 nidstats_keycmp(const void *key, struct hlist_node *hnode)
2075 return *(lnet_nid_t *)nidstats_key(hnode) == *(lnet_nid_t *)key;
2079 nidstats_object(struct hlist_node *hnode)
2081 return hlist_entry(hnode, struct nid_stat, nid_hash);
2085 nidstats_get(cfs_hash_t *hs, struct hlist_node *hnode)
2087 struct nid_stat *ns;
2089 ns = hlist_entry(hnode, struct nid_stat, nid_hash);
2094 nidstats_put_locked(cfs_hash_t *hs, struct hlist_node *hnode)
2096 struct nid_stat *ns;
2098 ns = hlist_entry(hnode, struct nid_stat, nid_hash);
2102 static cfs_hash_ops_t nid_stat_hash_ops = {
2103 .hs_hash = nid_hash,
2104 .hs_key = nidstats_key,
2105 .hs_keycmp = nidstats_keycmp,
2106 .hs_object = nidstats_object,
2107 .hs_get = nidstats_get,
2108 .hs_put_locked = nidstats_put_locked,