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.gnu.org/licenses/gpl-2.0.html
23 * Copyright (c) 2003, 2010, Oracle and/or its affiliates. All rights reserved.
24 * Use is subject to license terms.
26 * Copyright (c) 2011, 2016, Intel Corporation.
29 * This file is part of Lustre, http://www.lustre.org/
30 * Lustre is a trademark of Sun Microsystems, Inc.
32 * lustre/obdclass/obd_config.c
37 #define DEBUG_SUBSYSTEM S_CLASS
39 #include <linux/string.h>
41 #include <llog_swab.h>
42 #include <lprocfs_status.h>
43 #include <lustre_disk.h>
44 #include <uapi/linux/lustre/lustre_ioctl.h>
45 #include <lustre_log.h>
46 #include <uapi/linux/lustre/lustre_param.h>
47 #include <obd_class.h>
49 #include "llog_internal.h"
51 static struct cfs_hash_ops uuid_hash_ops;
52 static struct cfs_hash_ops nid_hash_ops;
53 static struct cfs_hash_ops nid_stat_hash_ops;
54 static struct cfs_hash_ops gen_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, const 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);
288 /* 1 param contains key and match
289 * 0 param contains key and not match
290 * -1 param does not contain key
292 int class_match_nid(char *buf, char *key, lnet_nid_t nid)
297 while (class_find_param(buf, key, &buf) == 0) {
298 /* please restrict to the nids pertaining to
299 * the specified nids */
300 while (class_parse_nid(buf, &tmp, &buf) == 0) {
309 int class_match_net(char *buf, char *key, __u32 net)
314 while (class_find_param(buf, key, &buf) == 0) {
315 /* please restrict to the nids pertaining to
316 * the specified networks */
317 while (class_parse_net(buf, &tmp, &buf) == 0) {
326 char *lustre_cfg_string(struct lustre_cfg *lcfg, u32 index)
330 if (!lcfg->lcfg_buflens[index])
333 s = lustre_cfg_buf(lcfg, index);
338 * make sure it's NULL terminated, even if this kills a char
339 * of data. Try to use the padding first though.
341 if (s[lcfg->lcfg_buflens[index] - 1] != '\0') {
342 size_t last = ALIGN(lcfg->lcfg_buflens[index], 8) - 1;
345 /* Use the smaller value */
346 if (last > lcfg->lcfg_buflens[index])
347 last = lcfg->lcfg_buflens[index];
352 CWARN("Truncated buf %d to '%s' (lost '%c'...)\n",
358 EXPORT_SYMBOL(lustre_cfg_string);
360 /********************** class fns **********************/
363 * Create a new obd device and set the type, name and uuid. If successful,
364 * the new device can be accessed by either name or uuid.
366 int class_attach(struct lustre_cfg *lcfg)
368 struct obd_device *obd = NULL;
369 char *typename, *name, *uuid;
373 if (!LUSTRE_CFG_BUFLEN(lcfg, 1)) {
374 CERROR("No type passed!\n");
377 typename = lustre_cfg_string(lcfg, 1);
379 if (!LUSTRE_CFG_BUFLEN(lcfg, 0)) {
380 CERROR("No name passed!\n");
383 name = lustre_cfg_string(lcfg, 0);
385 if (!LUSTRE_CFG_BUFLEN(lcfg, 2)) {
386 CERROR("No UUID passed!\n");
389 uuid = lustre_cfg_string(lcfg, 2);
391 CDEBUG(D_IOCTL, "attach type %s name: %s uuid: %s\n",
392 MKSTR(typename), MKSTR(name), MKSTR(uuid));
394 obd = class_newdev(typename, name);
396 /* Already exists or out of obds */
399 CERROR("Cannot create device %s of type %s : %d\n",
403 LASSERTF(obd != NULL, "Cannot get obd device %s of type %s\n",
405 LASSERTF(obd->obd_magic == OBD_DEVICE_MAGIC,
406 "obd %p obd_magic %08X != %08X\n",
407 obd, obd->obd_magic, OBD_DEVICE_MAGIC);
408 LASSERTF(strncmp(obd->obd_name, name, strlen(name)) == 0,
409 "%p obd_name %s != %s\n", obd, obd->obd_name, name);
411 rwlock_init(&obd->obd_pool_lock);
412 obd->obd_pool_limit = 0;
413 obd->obd_pool_slv = 0;
415 INIT_LIST_HEAD(&obd->obd_exports);
416 INIT_LIST_HEAD(&obd->obd_unlinked_exports);
417 INIT_LIST_HEAD(&obd->obd_delayed_exports);
418 INIT_LIST_HEAD(&obd->obd_exports_timed);
419 INIT_LIST_HEAD(&obd->obd_nid_stats);
420 spin_lock_init(&obd->obd_nid_lock);
421 spin_lock_init(&obd->obd_dev_lock);
422 mutex_init(&obd->obd_dev_mutex);
423 spin_lock_init(&obd->obd_osfs_lock);
424 /* obd->obd_osfs_age must be set to a value in the distant
425 * past to guarantee a fresh statfs is fetched on mount. */
426 obd->obd_osfs_age = cfs_time_shift_64(-1000);
428 /* XXX belongs in setup not attach */
429 init_rwsem(&obd->obd_observer_link_sem);
431 init_timer(&obd->obd_recovery_timer);
432 spin_lock_init(&obd->obd_recovery_task_lock);
433 init_waitqueue_head(&obd->obd_next_transno_waitq);
434 init_waitqueue_head(&obd->obd_evict_inprogress_waitq);
435 INIT_LIST_HEAD(&obd->obd_req_replay_queue);
436 INIT_LIST_HEAD(&obd->obd_lock_replay_queue);
437 INIT_LIST_HEAD(&obd->obd_final_req_queue);
438 INIT_LIST_HEAD(&obd->obd_evict_list);
439 INIT_LIST_HEAD(&obd->obd_lwp_list);
441 llog_group_init(&obd->obd_olg);
443 obd->obd_conn_inprogress = 0;
446 if (len >= sizeof(obd->obd_uuid)) {
447 CERROR("uuid must be < %d bytes long\n",
448 (int)sizeof(obd->obd_uuid));
449 GOTO(out, rc = -EINVAL);
451 memcpy(obd->obd_uuid.uuid, uuid, len);
453 /* Detach drops this */
454 spin_lock(&obd->obd_dev_lock);
455 atomic_set(&obd->obd_refcount, 1);
456 spin_unlock(&obd->obd_dev_lock);
457 lu_ref_init(&obd->obd_reference);
458 lu_ref_add(&obd->obd_reference, "attach", obd);
460 obd->obd_attached = 1;
461 CDEBUG(D_IOCTL, "OBD: dev %d attached type %s with refcount %d\n",
462 obd->obd_minor, typename, atomic_read(&obd->obd_refcount));
466 class_release_dev(obd);
470 EXPORT_SYMBOL(class_attach);
472 /** Create hashes, self-export, and call type-specific setup.
473 * Setup is effectively the "start this obd" call.
475 int class_setup(struct obd_device *obd, struct lustre_cfg *lcfg)
478 struct obd_export *exp;
481 LASSERT(obd != NULL);
482 LASSERTF(obd == class_num2obd(obd->obd_minor),
483 "obd %p != obd_devs[%d] %p\n",
484 obd, obd->obd_minor, class_num2obd(obd->obd_minor));
485 LASSERTF(obd->obd_magic == OBD_DEVICE_MAGIC,
486 "obd %p obd_magic %08x != %08x\n",
487 obd, obd->obd_magic, OBD_DEVICE_MAGIC);
489 /* have we attached a type to this device? */
490 if (!obd->obd_attached) {
491 CERROR("Device %d not attached\n", obd->obd_minor);
495 if (obd->obd_set_up) {
496 CERROR("Device %d already setup (type %s)\n",
497 obd->obd_minor, obd->obd_type->typ_name);
501 /* is someone else setting us up right now? (attach inits spinlock) */
502 spin_lock(&obd->obd_dev_lock);
503 if (obd->obd_starting) {
504 spin_unlock(&obd->obd_dev_lock);
505 CERROR("Device %d setup in progress (type %s)\n",
506 obd->obd_minor, obd->obd_type->typ_name);
509 /* just leave this on forever. I can't use obd_set_up here because
510 other fns check that status, and we're not actually set up yet. */
511 obd->obd_starting = 1;
512 obd->obd_uuid_hash = NULL;
513 obd->obd_nid_hash = NULL;
514 obd->obd_nid_stats_hash = NULL;
515 obd->obd_gen_hash = NULL;
516 spin_unlock(&obd->obd_dev_lock);
518 /* create an uuid-export lustre hash */
519 obd->obd_uuid_hash = cfs_hash_create("UUID_HASH",
522 HASH_UUID_BKT_BITS, 0,
525 &uuid_hash_ops, CFS_HASH_DEFAULT);
526 if (!obd->obd_uuid_hash)
527 GOTO(err_hash, err = -ENOMEM);
529 /* create a nid-export lustre hash */
530 obd->obd_nid_hash = cfs_hash_create("NID_HASH",
533 HASH_NID_BKT_BITS, 0,
536 &nid_hash_ops, CFS_HASH_DEFAULT);
537 if (!obd->obd_nid_hash)
538 GOTO(err_hash, err = -ENOMEM);
540 /* create a nid-stats lustre hash */
541 obd->obd_nid_stats_hash = cfs_hash_create("NID_STATS",
542 HASH_NID_STATS_CUR_BITS,
543 HASH_NID_STATS_MAX_BITS,
544 HASH_NID_STATS_BKT_BITS, 0,
547 &nid_stat_hash_ops, CFS_HASH_DEFAULT);
548 if (!obd->obd_nid_stats_hash)
549 GOTO(err_hash, err = -ENOMEM);
551 /* create a client_generation-export lustre hash */
552 obd->obd_gen_hash = cfs_hash_create("UUID_HASH",
555 HASH_GEN_BKT_BITS, 0,
558 &gen_hash_ops, CFS_HASH_DEFAULT);
559 if (!obd->obd_gen_hash)
560 GOTO(err_hash, err = -ENOMEM);
562 exp = class_new_export(obd, &obd->obd_uuid);
564 GOTO(err_hash, err = PTR_ERR(exp));
566 obd->obd_self_export = exp;
567 list_del_init(&exp->exp_obd_chain_timed);
568 class_export_put(exp);
570 err = obd_setup(obd, lcfg);
576 spin_lock(&obd->obd_dev_lock);
577 /* cleanup drops this */
578 class_incref(obd, "setup", obd);
579 spin_unlock(&obd->obd_dev_lock);
581 CDEBUG(D_IOCTL, "finished setup of obd %s (uuid %s)\n",
582 obd->obd_name, obd->obd_uuid.uuid);
586 if (obd->obd_self_export) {
587 class_unlink_export(obd->obd_self_export);
588 obd->obd_self_export = NULL;
591 if (obd->obd_uuid_hash) {
592 cfs_hash_putref(obd->obd_uuid_hash);
593 obd->obd_uuid_hash = NULL;
595 if (obd->obd_nid_hash) {
596 cfs_hash_putref(obd->obd_nid_hash);
597 obd->obd_nid_hash = NULL;
599 if (obd->obd_nid_stats_hash) {
600 cfs_hash_putref(obd->obd_nid_stats_hash);
601 obd->obd_nid_stats_hash = NULL;
603 if (obd->obd_gen_hash) {
604 cfs_hash_putref(obd->obd_gen_hash);
605 obd->obd_gen_hash = NULL;
607 obd->obd_starting = 0;
608 CERROR("setup %s failed (%d)\n", obd->obd_name, err);
611 EXPORT_SYMBOL(class_setup);
613 /** We have finished using this obd and are ready to destroy it.
614 * There can be no more references to this obd.
616 int class_detach(struct obd_device *obd, struct lustre_cfg *lcfg)
620 if (obd->obd_set_up) {
621 CERROR("OBD device %d still set up\n", obd->obd_minor);
625 spin_lock(&obd->obd_dev_lock);
626 if (!obd->obd_attached) {
627 spin_unlock(&obd->obd_dev_lock);
628 CERROR("OBD device %d not attached\n", obd->obd_minor);
631 obd->obd_attached = 0;
632 spin_unlock(&obd->obd_dev_lock);
634 CDEBUG(D_IOCTL, "detach on obd %s (uuid %s)\n",
635 obd->obd_name, obd->obd_uuid.uuid);
637 class_decref(obd, "attach", obd);
640 EXPORT_SYMBOL(class_detach);
642 /** Start shutting down the obd. There may be in-progess ops when
643 * this is called. We tell them to start shutting down with a call
644 * to class_disconnect_exports().
646 int class_cleanup(struct obd_device *obd, struct lustre_cfg *lcfg)
652 OBD_RACE(OBD_FAIL_LDLM_RECOV_CLIENTS);
654 if (!obd->obd_set_up) {
655 CERROR("Device %d not setup\n", obd->obd_minor);
659 spin_lock(&obd->obd_dev_lock);
660 if (obd->obd_stopping) {
661 spin_unlock(&obd->obd_dev_lock);
662 CERROR("OBD %d already stopping\n", obd->obd_minor);
665 /* Leave this on forever */
666 obd->obd_stopping = 1;
667 spin_unlock(&obd->obd_dev_lock);
669 /* wait for already-arrived-connections to finish. */
670 while (obd->obd_conn_inprogress > 0)
674 if (lcfg->lcfg_bufcount >= 2 && LUSTRE_CFG_BUFLEN(lcfg, 1) > 0) {
675 for (flag = lustre_cfg_string(lcfg, 1); *flag != 0; flag++)
681 LCONSOLE_WARN("Failing over %s\n",
684 obd->obd_no_transno = 1;
685 obd->obd_no_recov = 1;
686 if (OBP(obd, iocontrol)) {
687 obd_iocontrol(OBD_IOC_SYNC,
688 obd->obd_self_export,
693 CERROR("Unrecognised flag '%c'\n", *flag);
697 LASSERT(obd->obd_self_export);
699 /* The three references that should be remaining are the
700 * obd_self_export and the attach and setup references. */
701 if (atomic_read(&obd->obd_refcount) > 3) {
702 /* refcounf - 3 might be the number of real exports
703 (excluding self export). But class_incref is called
704 by other things as well, so don't count on it. */
705 CDEBUG(D_IOCTL, "%s: forcing exports to disconnect: %d\n",
706 obd->obd_name, atomic_read(&obd->obd_refcount) - 3);
707 dump_exports(obd, 0, D_HA);
708 class_disconnect_exports(obd);
711 /* Precleanup, we must make sure all exports get destroyed. */
712 err = obd_precleanup(obd);
714 CERROR("Precleanup %s returned %d\n",
717 /* destroy an uuid-export hash body */
718 if (obd->obd_uuid_hash) {
719 cfs_hash_putref(obd->obd_uuid_hash);
720 obd->obd_uuid_hash = NULL;
723 /* destroy a nid-export hash body */
724 if (obd->obd_nid_hash) {
725 cfs_hash_putref(obd->obd_nid_hash);
726 obd->obd_nid_hash = NULL;
729 /* destroy a nid-stats hash body */
730 if (obd->obd_nid_stats_hash) {
731 cfs_hash_putref(obd->obd_nid_stats_hash);
732 obd->obd_nid_stats_hash = NULL;
735 /* destroy a client_generation-export hash body */
736 if (obd->obd_gen_hash) {
737 cfs_hash_putref(obd->obd_gen_hash);
738 obd->obd_gen_hash = NULL;
741 class_decref(obd, "setup", obd);
747 struct obd_device *class_incref(struct obd_device *obd,
748 const char *scope, const void *source)
750 lu_ref_add_atomic(&obd->obd_reference, scope, source);
751 atomic_inc(&obd->obd_refcount);
752 CDEBUG(D_INFO, "incref %s (%p) now %d\n", obd->obd_name, obd,
753 atomic_read(&obd->obd_refcount));
757 EXPORT_SYMBOL(class_incref);
759 void class_decref(struct obd_device *obd, const char *scope, const void *source)
764 spin_lock(&obd->obd_dev_lock);
765 atomic_dec(&obd->obd_refcount);
766 refs = atomic_read(&obd->obd_refcount);
767 spin_unlock(&obd->obd_dev_lock);
768 lu_ref_del(&obd->obd_reference, scope, source);
770 CDEBUG(D_INFO, "Decref %s (%p) now %d\n", obd->obd_name, obd, refs);
772 if ((refs == 1) && obd->obd_stopping) {
773 /* All exports have been destroyed; there should
774 be no more in-progress ops by this point.*/
776 spin_lock(&obd->obd_self_export->exp_lock);
777 obd->obd_self_export->exp_flags |= exp_flags_from_obd(obd);
778 spin_unlock(&obd->obd_self_export->exp_lock);
780 /* note that we'll recurse into class_decref again */
781 class_unlink_export(obd->obd_self_export);
786 CDEBUG(D_CONFIG, "finishing cleanup of obd %s (%s)\n",
787 obd->obd_name, obd->obd_uuid.uuid);
788 LASSERT(!obd->obd_attached);
789 if (obd->obd_stopping) {
790 /* If we're not stopping, we were never set up */
791 err = obd_cleanup(obd);
793 CERROR("Cleanup %s returned %d\n",
797 class_release_dev(obd);
800 EXPORT_SYMBOL(class_decref);
802 /** Add a failover nid location.
803 * Client obd types contact server obd types using this nid list.
805 int class_add_conn(struct obd_device *obd, struct lustre_cfg *lcfg)
807 struct obd_import *imp;
808 struct obd_uuid uuid;
812 if (LUSTRE_CFG_BUFLEN(lcfg, 1) < 1 ||
813 LUSTRE_CFG_BUFLEN(lcfg, 1) > sizeof(struct obd_uuid)) {
814 CERROR("invalid conn_uuid\n");
817 if (strcmp(obd->obd_type->typ_name, LUSTRE_MDC_NAME) &&
818 strcmp(obd->obd_type->typ_name, LUSTRE_OSC_NAME) &&
819 strcmp(obd->obd_type->typ_name, LUSTRE_OSP_NAME) &&
820 strcmp(obd->obd_type->typ_name, LUSTRE_LWP_NAME) &&
821 strcmp(obd->obd_type->typ_name, LUSTRE_MGC_NAME)) {
822 CERROR("can't add connection on non-client dev\n");
826 imp = obd->u.cli.cl_import;
828 CERROR("try to add conn on immature client dev\n");
832 obd_str2uuid(&uuid, lustre_cfg_string(lcfg, 1));
833 rc = obd_add_conn(imp, &uuid, lcfg->lcfg_num);
838 /** Remove a failover nid location.
840 static int class_del_conn(struct obd_device *obd, struct lustre_cfg *lcfg)
842 struct obd_import *imp;
843 struct obd_uuid uuid;
847 if (LUSTRE_CFG_BUFLEN(lcfg, 1) < 1 ||
848 LUSTRE_CFG_BUFLEN(lcfg, 1) > sizeof(struct obd_uuid)) {
849 CERROR("invalid conn_uuid\n");
852 if (strcmp(obd->obd_type->typ_name, LUSTRE_MDC_NAME) &&
853 strcmp(obd->obd_type->typ_name, LUSTRE_OSC_NAME)) {
854 CERROR("can't del connection on non-client dev\n");
858 imp = obd->u.cli.cl_import;
860 CERROR("try to del conn on immature client dev\n");
864 obd_str2uuid(&uuid, lustre_cfg_string(lcfg, 1));
865 rc = obd_del_conn(imp, &uuid);
870 static LIST_HEAD(lustre_profile_list);
871 static DEFINE_SPINLOCK(lustre_profile_list_lock);
873 struct lustre_profile *class_get_profile(const char * prof)
875 struct lustre_profile *lprof;
878 spin_lock(&lustre_profile_list_lock);
879 list_for_each_entry(lprof, &lustre_profile_list, lp_list) {
880 if (!strcmp(lprof->lp_profile, prof)) {
882 spin_unlock(&lustre_profile_list_lock);
886 spin_unlock(&lustre_profile_list_lock);
889 EXPORT_SYMBOL(class_get_profile);
891 /** Create a named "profile".
892 * This defines the mdc and osc names to use for a client.
893 * This also is used to define the lov to be used by a mdt.
895 static int class_add_profile(int proflen, char *prof, int osclen, char *osc,
896 int mdclen, char *mdc)
898 struct lustre_profile *lprof;
902 CDEBUG(D_CONFIG, "Add profile %s\n", prof);
904 OBD_ALLOC(lprof, sizeof(*lprof));
907 INIT_LIST_HEAD(&lprof->lp_list);
909 LASSERT(proflen == (strlen(prof) + 1));
910 OBD_ALLOC(lprof->lp_profile, proflen);
911 if (lprof->lp_profile == NULL)
912 GOTO(out, err = -ENOMEM);
913 memcpy(lprof->lp_profile, prof, proflen);
915 LASSERT(osclen == (strlen(osc) + 1));
916 OBD_ALLOC(lprof->lp_dt, osclen);
917 if (lprof->lp_dt == NULL)
918 GOTO(out, err = -ENOMEM);
919 memcpy(lprof->lp_dt, osc, osclen);
922 LASSERT(mdclen == (strlen(mdc) + 1));
923 OBD_ALLOC(lprof->lp_md, mdclen);
924 if (lprof->lp_md == NULL)
925 GOTO(out, err = -ENOMEM);
926 memcpy(lprof->lp_md, mdc, mdclen);
929 spin_lock(&lustre_profile_list_lock);
931 lprof->lp_list_deleted = false;
933 list_add(&lprof->lp_list, &lustre_profile_list);
934 spin_unlock(&lustre_profile_list_lock);
939 OBD_FREE(lprof->lp_md, mdclen);
941 OBD_FREE(lprof->lp_dt, osclen);
942 if (lprof->lp_profile)
943 OBD_FREE(lprof->lp_profile, proflen);
944 OBD_FREE(lprof, sizeof(*lprof));
948 void class_del_profile(const char *prof)
950 struct lustre_profile *lprof;
953 CDEBUG(D_CONFIG, "Del profile %s\n", prof);
955 lprof = class_get_profile(prof);
957 spin_lock(&lustre_profile_list_lock);
958 /* because get profile increments the ref counter */
960 list_del(&lprof->lp_list);
961 lprof->lp_list_deleted = true;
962 spin_unlock(&lustre_profile_list_lock);
964 class_put_profile(lprof);
968 EXPORT_SYMBOL(class_del_profile);
970 void class_put_profile(struct lustre_profile *lprof)
972 spin_lock(&lustre_profile_list_lock);
973 if ((--lprof->lp_refs) > 0) {
974 LASSERT(lprof->lp_refs > 0);
975 spin_unlock(&lustre_profile_list_lock);
978 spin_unlock(&lustre_profile_list_lock);
980 /* confirm not a negative number */
981 LASSERT(lprof->lp_refs == 0);
983 /* At least one class_del_profile/profiles must be called
984 * on the target profile or lustre_profile_list will corrupt */
985 LASSERT(lprof->lp_list_deleted);
986 OBD_FREE(lprof->lp_profile, strlen(lprof->lp_profile) + 1);
987 OBD_FREE(lprof->lp_dt, strlen(lprof->lp_dt) + 1);
988 if (lprof->lp_md != NULL)
989 OBD_FREE(lprof->lp_md, strlen(lprof->lp_md) + 1);
990 OBD_FREE(lprof, sizeof(*lprof));
992 EXPORT_SYMBOL(class_put_profile);
995 void class_del_profiles(void)
997 struct lustre_profile *lprof, *n;
1000 spin_lock(&lustre_profile_list_lock);
1001 list_for_each_entry_safe(lprof, n, &lustre_profile_list, lp_list) {
1002 list_del(&lprof->lp_list);
1003 lprof->lp_list_deleted = true;
1004 spin_unlock(&lustre_profile_list_lock);
1006 class_put_profile(lprof);
1008 spin_lock(&lustre_profile_list_lock);
1010 spin_unlock(&lustre_profile_list_lock);
1013 EXPORT_SYMBOL(class_del_profiles);
1015 static int class_set_global(char *ptr, int val, struct lustre_cfg *lcfg)
1018 if (class_match_param(ptr, PARAM_AT_MIN, NULL) == 0)
1020 else if (class_match_param(ptr, PARAM_AT_MAX, NULL) == 0)
1022 else if (class_match_param(ptr, PARAM_AT_EXTRA, NULL) == 0)
1024 else if (class_match_param(ptr, PARAM_AT_EARLY_MARGIN, NULL) == 0)
1025 at_early_margin = val;
1026 else if (class_match_param(ptr, PARAM_AT_HISTORY, NULL) == 0)
1028 else if (class_match_param(ptr, PARAM_JOBID_VAR, NULL) == 0)
1029 strlcpy(obd_jobid_var, lustre_cfg_string(lcfg, 2),
1030 JOBSTATS_JOBID_VAR_MAX_LEN + 1);
1034 CDEBUG(D_IOCTL, "global %s = %d\n", ptr, val);
1039 /* We can't call ll_process_config or lquota_process_config directly because
1040 * it lives in a module that must be loaded after this one. */
1041 static int (*client_process_config)(struct lustre_cfg *lcfg) = NULL;
1042 static int (*quota_process_config)(struct lustre_cfg *lcfg) = NULL;
1044 void lustre_register_client_process_config(int (*cpc)(struct lustre_cfg *lcfg))
1046 client_process_config = cpc;
1048 EXPORT_SYMBOL(lustre_register_client_process_config);
1051 * Rename the proc parameter in \a cfg with a new name \a new_name.
1053 * \param cfg config structure which contains the proc parameter
1054 * \param new_name new name of the proc parameter
1056 * \retval valid-pointer pointer to the newly-allocated config structure
1057 * which contains the renamed proc parameter
1058 * \retval ERR_PTR(-EINVAL) if \a cfg or \a new_name is NULL, or \a cfg does
1059 * not contain a proc parameter
1060 * \retval ERR_PTR(-ENOMEM) if memory allocation failure occurs
1062 struct lustre_cfg *lustre_cfg_rename(struct lustre_cfg *cfg,
1063 const char *new_name)
1065 struct lustre_cfg_bufs *bufs = NULL;
1066 struct lustre_cfg *new_cfg = NULL;
1068 char *new_param = NULL;
1074 if (!cfg || !new_name)
1075 GOTO(out_nocfg, new_cfg = ERR_PTR(-EINVAL));
1077 param = lustre_cfg_string(cfg, 1);
1079 GOTO(out_nocfg, new_cfg = ERR_PTR(-EINVAL));
1081 value = strchr(param, '=');
1083 name_len = strlen(param);
1085 name_len = value - param;
1087 new_len = LUSTRE_CFG_BUFLEN(cfg, 1) + strlen(new_name) - name_len;
1089 OBD_ALLOC(new_param, new_len);
1091 GOTO(out_nocfg, new_cfg = ERR_PTR(-ENOMEM));
1093 strcpy(new_param, new_name);
1095 strcat(new_param, value);
1097 OBD_ALLOC_PTR(bufs);
1099 GOTO(out_free_param, new_cfg = ERR_PTR(-ENOMEM));
1101 lustre_cfg_bufs_reset(bufs, NULL);
1102 lustre_cfg_bufs_init(bufs, cfg);
1103 lustre_cfg_bufs_set_string(bufs, 1, new_param);
1105 OBD_ALLOC(new_cfg, lustre_cfg_len(bufs->lcfg_bufcount,
1106 bufs->lcfg_buflen));
1108 GOTO(out_free_buf, new_cfg = ERR_PTR(-ENOMEM));
1110 lustre_cfg_init(new_cfg, cfg->lcfg_command, bufs);
1112 new_cfg->lcfg_num = cfg->lcfg_num;
1113 new_cfg->lcfg_flags = cfg->lcfg_flags;
1114 new_cfg->lcfg_nid = cfg->lcfg_nid;
1115 new_cfg->lcfg_nal = cfg->lcfg_nal;
1119 OBD_FREE(new_param, new_len);
1123 EXPORT_SYMBOL(lustre_cfg_rename);
1125 static int process_param2_config(struct lustre_cfg *lcfg)
1127 char *param = lustre_cfg_string(lcfg, 1);
1128 char *upcall = lustre_cfg_string(lcfg, 2);
1130 [0] = "/usr/sbin/lctl",
1140 /* Add upcall processing here. Now only lctl is supported */
1141 if (strcmp(upcall, LCTL_UPCALL) != 0) {
1142 CERROR("Unsupported upcall %s\n", upcall);
1146 start = ktime_get();
1147 rc = call_usermodehelper(argv[0], argv, NULL, UMH_WAIT_PROC);
1151 CERROR("lctl: error invoking upcall %s %s %s: rc = %d; "
1152 "time %ldus\n", argv[0], argv[1], argv[2], rc,
1153 (long)ktime_us_delta(end, start));
1155 CDEBUG(D_HA, "lctl: invoked upcall %s %s %s, time %ldus\n",
1156 argv[0], argv[1], argv[2],
1157 (long)ktime_us_delta(end, start));
1164 void lustre_register_quota_process_config(int (*qpc)(struct lustre_cfg *lcfg))
1166 quota_process_config = qpc;
1168 EXPORT_SYMBOL(lustre_register_quota_process_config);
1170 /** Process configuration commands given in lustre_cfg form.
1171 * These may come from direct calls (e.g. class_manual_cleanup)
1172 * or processing the config llog, or ioctl from lctl.
1174 int class_process_config(struct lustre_cfg *lcfg)
1176 struct obd_device *obd;
1179 LASSERT(lcfg && !IS_ERR(lcfg));
1180 CDEBUG(D_IOCTL, "processing cmd: %x\n", lcfg->lcfg_command);
1182 /* Commands that don't need a device */
1183 switch(lcfg->lcfg_command) {
1185 err = class_attach(lcfg);
1188 case LCFG_ADD_UUID: {
1189 CDEBUG(D_IOCTL, "adding mapping from uuid %s to nid %#llx"
1190 " (%s)\n", lustre_cfg_string(lcfg, 1),
1191 lcfg->lcfg_nid, libcfs_nid2str(lcfg->lcfg_nid));
1193 err = class_add_uuid(lustre_cfg_string(lcfg, 1), lcfg->lcfg_nid);
1196 case LCFG_DEL_UUID: {
1197 CDEBUG(D_IOCTL, "removing mappings for uuid %s\n",
1198 (lcfg->lcfg_bufcount < 2 || LUSTRE_CFG_BUFLEN(lcfg, 1) == 0)
1199 ? "<all uuids>" : lustre_cfg_string(lcfg, 1));
1201 err = class_del_uuid(lustre_cfg_string(lcfg, 1));
1204 case LCFG_MOUNTOPT: {
1205 CDEBUG(D_IOCTL, "mountopt: profile %s osc %s mdc %s\n",
1206 lustre_cfg_string(lcfg, 1),
1207 lustre_cfg_string(lcfg, 2),
1208 lustre_cfg_string(lcfg, 3));
1209 /* set these mount options somewhere, so ll_fill_super
1211 err = class_add_profile(LUSTRE_CFG_BUFLEN(lcfg, 1),
1212 lustre_cfg_string(lcfg, 1),
1213 LUSTRE_CFG_BUFLEN(lcfg, 2),
1214 lustre_cfg_string(lcfg, 2),
1215 LUSTRE_CFG_BUFLEN(lcfg, 3),
1216 lustre_cfg_string(lcfg, 3));
1219 case LCFG_DEL_MOUNTOPT: {
1220 CDEBUG(D_IOCTL, "mountopt: profile %s\n",
1221 lustre_cfg_string(lcfg, 1));
1222 class_del_profile(lustre_cfg_string(lcfg, 1));
1225 case LCFG_SET_TIMEOUT: {
1226 CDEBUG(D_IOCTL, "changing lustre timeout from %d to %d\n",
1227 obd_timeout, lcfg->lcfg_num);
1228 obd_timeout = max(lcfg->lcfg_num, 1U);
1229 obd_timeout_set = 1;
1232 case LCFG_SET_LDLM_TIMEOUT: {
1233 CDEBUG(D_IOCTL, "changing lustre ldlm_timeout from %d to %d\n",
1234 ldlm_timeout, lcfg->lcfg_num);
1235 ldlm_timeout = max(lcfg->lcfg_num, 1U);
1236 if (ldlm_timeout >= obd_timeout)
1237 ldlm_timeout = max(obd_timeout / 3, 1U);
1238 ldlm_timeout_set = 1;
1241 case LCFG_SET_UPCALL: {
1242 LCONSOLE_ERROR_MSG(0x15a, "recovery upcall is deprecated\n");
1243 /* COMPAT_146 Don't fail on old configs */
1247 struct cfg_marker *marker;
1248 marker = lustre_cfg_buf(lcfg, 1);
1249 CDEBUG(D_IOCTL, "marker %d (%#x) %.16s %s\n", marker->cm_step,
1250 marker->cm_flags, marker->cm_tgtname, marker->cm_comment);
1255 /* llite has no obd */
1256 if ((class_match_param(lustre_cfg_string(lcfg, 1),
1257 PARAM_LLITE, NULL) == 0) &&
1258 client_process_config) {
1259 err = (*client_process_config)(lcfg);
1261 } else if ((class_match_param(lustre_cfg_string(lcfg, 1),
1262 PARAM_SYS, &tmp) == 0)) {
1263 /* Global param settings */
1264 err = class_set_global(tmp, lcfg->lcfg_num, lcfg);
1266 * Client or server should not fail to mount if
1267 * it hits an unknown configuration parameter.
1270 CWARN("Ignoring unknown param %s\n", tmp);
1273 } else if ((class_match_param(lustre_cfg_string(lcfg, 1),
1274 PARAM_QUOTA, &tmp) == 0) &&
1275 quota_process_config) {
1276 err = (*quota_process_config)(lcfg);
1282 case LCFG_SET_PARAM: {
1283 err = process_param2_config(lcfg);
1287 /* Commands that require a device */
1288 obd = class_name2obd(lustre_cfg_string(lcfg, 0));
1290 if (!LUSTRE_CFG_BUFLEN(lcfg, 0))
1291 CERROR("this lcfg command requires a device name\n");
1293 CERROR("no device for: %s\n",
1294 lustre_cfg_string(lcfg, 0));
1296 GOTO(out, err = -EINVAL);
1299 switch(lcfg->lcfg_command) {
1301 err = class_setup(obd, lcfg);
1305 err = class_detach(obd, lcfg);
1308 case LCFG_CLEANUP: {
1309 err = class_cleanup(obd, lcfg);
1312 case LCFG_ADD_CONN: {
1313 err = class_add_conn(obd, lcfg);
1316 case LCFG_DEL_CONN: {
1317 err = class_del_conn(obd, lcfg);
1320 case LCFG_POOL_NEW: {
1321 err = obd_pool_new(obd, lustre_cfg_string(lcfg, 2));
1324 case LCFG_POOL_ADD: {
1325 err = obd_pool_add(obd, lustre_cfg_string(lcfg, 2),
1326 lustre_cfg_string(lcfg, 3));
1329 case LCFG_POOL_REM: {
1330 err = obd_pool_rem(obd, lustre_cfg_string(lcfg, 2),
1331 lustre_cfg_string(lcfg, 3));
1334 case LCFG_POOL_DEL: {
1335 err = obd_pool_del(obd, lustre_cfg_string(lcfg, 2));
1339 err = obd_process_config(obd, sizeof(*lcfg), lcfg);
1345 if ((err < 0) && !(lcfg->lcfg_command & LCFG_REQUIRED)) {
1346 CWARN("Ignoring error %d on optional command %#x\n", err,
1347 lcfg->lcfg_command);
1352 EXPORT_SYMBOL(class_process_config);
1354 int class_process_proc_param(char *prefix, struct lprocfs_vars *lvars,
1355 struct lustre_cfg *lcfg, void *data)
1357 struct lprocfs_vars *var;
1358 struct file fakefile;
1359 struct seq_file fake_seqfile;
1361 int i, keylen, vallen;
1362 int matched = 0, j = 0;
1367 if (lcfg->lcfg_command != LCFG_PARAM) {
1368 CERROR("Unknown command: %d\n", lcfg->lcfg_command);
1372 /* fake a seq file so that var->fops->write can work... */
1373 fakefile.private_data = &fake_seqfile;
1374 fake_seqfile.private = data;
1375 /* e.g. tunefs.lustre --param mdt.group_upcall=foo /r/tmp/lustre-mdt
1376 or lctl conf_param lustre-MDT0000.mdt.group_upcall=bar
1377 or lctl conf_param lustre-OST0000.osc.max_dirty_mb=36 */
1378 for (i = 1; i < lcfg->lcfg_bufcount; i++) {
1379 key = lustre_cfg_buf(lcfg, i);
1380 /* Strip off prefix */
1381 if (class_match_param(key, prefix, &key))
1382 /* If the prefix doesn't match, return error so we
1383 * can pass it down the stack */
1385 sval = strchr(key, '=');
1386 if (!sval || *(sval + 1) == 0) {
1387 CERROR("%s: can't parse param '%s' (missing '=')\n",
1388 lustre_cfg_string(lcfg, 0),
1389 lustre_cfg_string(lcfg, i));
1390 /* rc = -EINVAL; continue parsing other params */
1393 keylen = sval - key;
1395 vallen = strlen(sval);
1398 /* Search proc entries */
1399 while (lvars[j].name) {
1401 if (class_match_param(key, var->name, NULL) == 0 &&
1402 keylen == strlen(var->name)) {
1406 if (var->fops && var->fops->write) {
1410 rc = (var->fops->write)(&fakefile, sval,
1419 /* It was upgraded from old MDT/OST device,
1420 * ignore the obsolete "sec_level" parameter. */
1421 if (strncmp("sec_level", key, keylen) == 0)
1424 CERROR("%s: unknown config parameter '%s'\n",
1425 lustre_cfg_string(lcfg, 0),
1426 lustre_cfg_string(lcfg, i));
1427 /* rc = -EINVAL; continue parsing other params */
1429 } else if (rc < 0) {
1430 CERROR("%s: error writing proc '%s'='%s': rc = %d\n",
1431 lustre_cfg_string(lcfg, 0), key, sval, rc);
1434 CDEBUG(D_CONFIG, "%s: Set parameter '%s'='%s'\n",
1435 lustre_cfg_string(lcfg, 0), key, sval);
1445 EXPORT_SYMBOL(class_process_proc_param);
1448 * Supplemental functions for config logs, it allocates lustre_cfg
1449 * buffers plus initialized llog record header at the beginning.
1451 struct llog_cfg_rec *lustre_cfg_rec_new(int cmd, struct lustre_cfg_bufs *bufs)
1453 struct llog_cfg_rec *lcr;
1458 reclen = lustre_cfg_len(bufs->lcfg_bufcount, bufs->lcfg_buflen);
1459 reclen = llog_data_len(reclen) + sizeof(struct llog_rec_hdr) +
1460 sizeof(struct llog_rec_tail);
1462 OBD_ALLOC(lcr, reclen);
1466 lustre_cfg_init(&lcr->lcr_cfg, cmd, bufs);
1468 lcr->lcr_hdr.lrh_len = reclen;
1469 lcr->lcr_hdr.lrh_type = OBD_CFG_REC;
1473 EXPORT_SYMBOL(lustre_cfg_rec_new);
1475 void lustre_cfg_rec_free(struct llog_cfg_rec *lcr)
1478 OBD_FREE(lcr, lcr->lcr_hdr.lrh_len);
1481 EXPORT_SYMBOL(lustre_cfg_rec_free);
1483 /** Parse a configuration llog, doing various manipulations on them
1484 * for various reasons, (modifications for compatibility, skip obsolete
1485 * records, change uuids, etc), then class_process_config() resulting
1488 int class_config_llog_handler(const struct lu_env *env,
1489 struct llog_handle *handle,
1490 struct llog_rec_hdr *rec, void *data)
1492 struct config_llog_instance *cfg = data;
1493 int cfg_len = rec->lrh_len;
1494 char *cfg_buf = (char *) (rec + 1);
1498 /* class_config_dump_handler(handle, rec, data); */
1500 switch (rec->lrh_type) {
1502 struct lustre_cfg *lcfg, *lcfg_new;
1503 struct lustre_cfg_bufs bufs;
1504 char *inst_name = NULL;
1508 lcfg = (struct lustre_cfg *)cfg_buf;
1509 if (lcfg->lcfg_version == __swab32(LUSTRE_CFG_VERSION)) {
1510 lustre_swab_lustre_cfg(lcfg);
1514 rc = lustre_cfg_sanity_check(cfg_buf, cfg_len);
1518 /* Figure out config state info */
1519 if (lcfg->lcfg_command == LCFG_MARKER) {
1520 struct cfg_marker *marker = lustre_cfg_buf(lcfg, 1);
1521 lustre_swab_cfg_marker(marker, swab,
1522 LUSTRE_CFG_BUFLEN(lcfg, 1));
1523 CDEBUG(D_CONFIG, "Marker, inst_flg=%#x mark_flg=%#x\n",
1524 cfg->cfg_flags, marker->cm_flags);
1525 if (marker->cm_flags & CM_START) {
1526 /* all previous flags off */
1527 cfg->cfg_flags = CFG_F_MARKER;
1528 server_name2index(marker->cm_tgtname,
1529 &cfg->cfg_lwp_idx, NULL);
1530 if (marker->cm_flags & CM_SKIP) {
1531 cfg->cfg_flags |= CFG_F_SKIP;
1532 CDEBUG(D_CONFIG, "SKIP #%d\n",
1534 } else if ((marker->cm_flags & CM_EXCLUDE) ||
1536 lustre_check_exclusion(cfg->cfg_sb,
1537 marker->cm_tgtname))) {
1538 cfg->cfg_flags |= CFG_F_EXCLUDE;
1539 CDEBUG(D_CONFIG, "EXCLUDE %d\n",
1542 } else if (marker->cm_flags & CM_END) {
1546 /* A config command without a start marker before it is
1547 illegal (post 146) */
1548 if (!(cfg->cfg_flags & CFG_F_COMPAT146) &&
1549 !(cfg->cfg_flags & CFG_F_MARKER) &&
1550 (lcfg->lcfg_command != LCFG_MARKER)) {
1551 CWARN("Config not inside markers, ignoring! "
1552 "(inst: %p, uuid: %s, flags: %#x)\n",
1554 cfg->cfg_uuid.uuid, cfg->cfg_flags);
1555 cfg->cfg_flags |= CFG_F_SKIP;
1557 if (cfg->cfg_flags & CFG_F_SKIP) {
1558 CDEBUG(D_CONFIG, "skipping %#x\n",
1561 /* No processing! */
1566 * For interoperability between 1.8 and 2.0,
1567 * rename "mds" obd device type to "mdt".
1570 char *typename = lustre_cfg_string(lcfg, 1);
1571 char *index = lustre_cfg_string(lcfg, 2);
1573 if ((lcfg->lcfg_command == LCFG_ATTACH && typename &&
1574 strcmp(typename, "mds") == 0)) {
1575 CWARN("For 1.8 interoperability, rename obd "
1576 "type from mds to mdt\n");
1579 if ((lcfg->lcfg_command == LCFG_SETUP && index &&
1580 strcmp(index, "type") == 0)) {
1581 CDEBUG(D_INFO, "For 1.8 interoperability, "
1582 "set this index to '0'\n");
1588 #ifdef HAVE_SERVER_SUPPORT
1589 /* newer MDS replaces LOV/OSC with LOD/OSP */
1591 char *typename = lustre_cfg_string(lcfg, 1);
1593 if ((lcfg->lcfg_command == LCFG_ATTACH && typename &&
1594 strcmp(typename, LUSTRE_LOV_NAME) == 0) &&
1595 cfg->cfg_sb && IS_MDT(s2lsi(cfg->cfg_sb))) {
1597 "For 2.x interoperability, rename obd "
1598 "type from lov to lod (%s)\n",
1599 s2lsi(cfg->cfg_sb)->lsi_svname);
1600 strcpy(typename, LUSTRE_LOD_NAME);
1602 if ((lcfg->lcfg_command == LCFG_ATTACH && typename &&
1603 strcmp(typename, LUSTRE_OSC_NAME) == 0) &&
1604 cfg->cfg_sb && IS_MDT(s2lsi(cfg->cfg_sb))) {
1606 "For 2.x interoperability, rename obd "
1607 "type from osc to osp (%s)\n",
1608 s2lsi(cfg->cfg_sb)->lsi_svname);
1609 strcpy(typename, LUSTRE_OSP_NAME);
1612 #endif /* HAVE_SERVER_SUPPORT */
1614 if (cfg->cfg_flags & CFG_F_EXCLUDE) {
1615 CDEBUG(D_CONFIG, "cmd: %x marked EXCLUDED\n",
1616 lcfg->lcfg_command);
1617 if (lcfg->lcfg_command == LCFG_LOV_ADD_OBD)
1618 /* Add inactive instead */
1619 lcfg->lcfg_command = LCFG_LOV_ADD_INA;
1622 lustre_cfg_bufs_reset(&bufs, NULL);
1623 lustre_cfg_bufs_init(&bufs, lcfg);
1625 if (cfg->cfg_instance &&
1626 LUSTRE_CFG_BUFLEN(lcfg, 0) > 0) {
1627 inst_len = LUSTRE_CFG_BUFLEN(lcfg, 0) +
1628 sizeof(cfg->cfg_instance) * 2 + 4;
1629 OBD_ALLOC(inst_name, inst_len);
1630 if (inst_name == NULL)
1631 GOTO(out, rc = -ENOMEM);
1632 snprintf(inst_name, inst_len, "%s-%p",
1633 lustre_cfg_string(lcfg, 0),
1635 lustre_cfg_bufs_set_string(&bufs, 0, inst_name);
1636 CDEBUG(D_CONFIG, "cmd %x, instance name: %s\n",
1637 lcfg->lcfg_command, inst_name);
1640 /* we override the llog's uuid for clients, to insure they
1642 if (cfg->cfg_instance != NULL &&
1643 lcfg->lcfg_command == LCFG_ATTACH) {
1644 lustre_cfg_bufs_set_string(&bufs, 2,
1645 cfg->cfg_uuid.uuid);
1648 * sptlrpc config record, we expect 2 data segments:
1649 * [0]: fs_name/target_name,
1651 * moving them to index [1] and [2], and insert MGC's
1652 * obdname at index [0].
1654 if (cfg->cfg_instance == NULL &&
1655 lcfg->lcfg_command == LCFG_SPTLRPC_CONF) {
1656 lustre_cfg_bufs_set(&bufs, 2, bufs.lcfg_buf[1],
1657 bufs.lcfg_buflen[1]);
1658 lustre_cfg_bufs_set(&bufs, 1, bufs.lcfg_buf[0],
1659 bufs.lcfg_buflen[0]);
1660 lustre_cfg_bufs_set_string(&bufs, 0,
1664 /* Add net info to setup command
1665 * if given on command line.
1666 * So config log will be:
1670 * [3]: inactive-on-startup
1671 * [4]: restrictive net
1673 if (cfg && cfg->cfg_sb && s2lsi(cfg->cfg_sb) &&
1674 !IS_SERVER(s2lsi(cfg->cfg_sb))) {
1675 struct lustre_sb_info *lsi = s2lsi(cfg->cfg_sb);
1676 char *nidnet = lsi->lsi_lmd->lmd_nidnet;
1678 if (lcfg->lcfg_command == LCFG_SETUP &&
1679 lcfg->lcfg_bufcount != 2 && nidnet) {
1680 CDEBUG(D_CONFIG, "Adding net %s info to setup "
1681 "command for client %s\n", nidnet,
1682 lustre_cfg_string(lcfg, 0));
1683 lustre_cfg_bufs_set_string(&bufs, 4, nidnet);
1687 /* Skip add_conn command if uuid is
1688 * not on restricted net */
1689 if (cfg && cfg->cfg_sb && s2lsi(cfg->cfg_sb) &&
1690 !IS_SERVER(s2lsi(cfg->cfg_sb))) {
1691 struct lustre_sb_info *lsi = s2lsi(cfg->cfg_sb);
1692 char *uuid_str = lustre_cfg_string(lcfg, 1);
1694 if (lcfg->lcfg_command == LCFG_ADD_CONN &&
1695 lsi->lsi_lmd->lmd_nidnet &&
1696 LNET_NIDNET(libcfs_str2nid(uuid_str)) !=
1697 libcfs_str2net(lsi->lsi_lmd->lmd_nidnet)) {
1698 CDEBUG(D_CONFIG, "skipping add_conn for %s\n",
1701 /* No processing! */
1706 OBD_ALLOC(lcfg_new, lustre_cfg_len(bufs.lcfg_bufcount,
1709 GOTO(out, rc = -ENOMEM);
1711 lustre_cfg_init(lcfg_new, lcfg->lcfg_command, &bufs);
1712 lcfg_new->lcfg_num = lcfg->lcfg_num;
1713 lcfg_new->lcfg_flags = lcfg->lcfg_flags;
1715 /* XXX Hack to try to remain binary compatible with
1716 * pre-newconfig logs */
1717 if (lcfg->lcfg_nal != 0 && /* pre-newconfig log? */
1718 (lcfg->lcfg_nid >> 32) == 0) {
1719 __u32 addr = (__u32)(lcfg->lcfg_nid & 0xffffffff);
1721 lcfg_new->lcfg_nid =
1722 LNET_MKNID(LNET_MKNET(lcfg->lcfg_nal, 0), addr);
1723 CWARN("Converted pre-newconfig NAL %d NID %x to %s\n",
1724 lcfg->lcfg_nal, addr,
1725 libcfs_nid2str(lcfg_new->lcfg_nid));
1727 lcfg_new->lcfg_nid = lcfg->lcfg_nid;
1730 lcfg_new->lcfg_nal = 0; /* illegal value for obsolete field */
1732 rc = class_process_config(lcfg_new);
1733 OBD_FREE(lcfg_new, lustre_cfg_len(lcfg_new->lcfg_bufcount,
1734 lcfg_new->lcfg_buflens));
1736 OBD_FREE(inst_name, inst_len);
1740 CERROR("Unknown llog record type %#x encountered\n",
1746 CERROR("%s: cfg command failed: rc = %d\n",
1747 handle->lgh_ctxt->loc_obd->obd_name, rc);
1748 class_config_dump_handler(NULL, handle, rec, data);
1752 EXPORT_SYMBOL(class_config_llog_handler);
1754 int class_config_parse_llog(const struct lu_env *env, struct llog_ctxt *ctxt,
1755 char *name, struct config_llog_instance *cfg)
1757 struct llog_process_cat_data cd = {
1758 .lpcd_first_idx = 0,
1760 struct llog_handle *llh;
1765 CDEBUG(D_INFO, "looking up llog %s\n", name);
1766 rc = llog_open(env, ctxt, &llh, NULL, name, LLOG_OPEN_EXISTS);
1770 rc = llog_init_handle(env, llh, LLOG_F_IS_PLAIN, NULL);
1772 GOTO(parse_out, rc);
1774 /* continue processing from where we last stopped to end-of-log */
1776 cd.lpcd_first_idx = cfg->cfg_last_idx;
1777 callback = cfg->cfg_callback;
1778 LASSERT(callback != NULL);
1780 callback = class_config_llog_handler;
1783 cd.lpcd_last_idx = 0;
1785 rc = llog_process(env, llh, callback, cfg, &cd);
1787 CDEBUG(D_CONFIG, "Processed log %s gen %d-%d (rc=%d)\n", name,
1788 cd.lpcd_first_idx + 1, cd.lpcd_last_idx, rc);
1790 cfg->cfg_last_idx = cd.lpcd_last_idx;
1793 llog_close(env, llh);
1796 EXPORT_SYMBOL(class_config_parse_llog);
1798 static struct lcfg_type_data {
1802 } lcfg_data_table[] = {
1803 { LCFG_ATTACH, "attach", { "type", "UUID", "3", "4" } },
1804 { LCFG_DETACH, "detach", { "1", "2", "3", "4" } },
1805 { LCFG_SETUP, "setup", { "UUID", "node", "options", "failout" } },
1806 { LCFG_CLEANUP, "cleanup", { "1", "2", "3", "4" } },
1807 { LCFG_ADD_UUID, "add_uuid", { "node", "2", "3", "4" } },
1808 { LCFG_DEL_UUID, "del_uuid", { "1", "2", "3", "4" } },
1809 { LCFG_MOUNTOPT, "new_profile", { "name", "lov", "lmv", "4" } },
1810 { LCFG_DEL_MOUNTOPT, "del_mountopt", { "1", "2", "3", "4" } , },
1811 { LCFG_SET_TIMEOUT, "set_timeout", { "parameter", "2", "3", "4" } },
1812 { LCFG_SET_UPCALL, "set_upcall", { "1", "2", "3", "4" } },
1813 { LCFG_ADD_CONN, "add_conn", { "node", "2", "3", "4" } },
1814 { LCFG_DEL_CONN, "del_conn", { "1", "2", "3", "4" } },
1815 { LCFG_LOV_ADD_OBD, "add_osc", { "ost", "index", "gen", "UUID" } },
1816 { LCFG_LOV_DEL_OBD, "del_osc", { "1", "2", "3", "4" } },
1817 { LCFG_PARAM, "set_param", { "parameter", "value", "3", "4" } },
1818 { LCFG_MARKER, "marker", { "1", "2", "3", "4" } },
1819 { LCFG_LOG_START, "log_start", { "1", "2", "3", "4" } },
1820 { LCFG_LOG_END, "log_end", { "1", "2", "3", "4" } },
1821 { LCFG_LOV_ADD_INA, "add_osc_inactive", { "1", "2", "3", "4" } },
1822 { LCFG_ADD_MDC, "add_mdc", { "mdt", "index", "gen", "UUID" } },
1823 { LCFG_DEL_MDC, "del_mdc", { "1", "2", "3", "4" } },
1824 { LCFG_SPTLRPC_CONF, "security", { "parameter", "2", "3", "4" } },
1825 { LCFG_POOL_NEW, "new_pool", { "fsname", "pool", "3", "4" } },
1826 { LCFG_POOL_ADD, "add_pool", { "fsname", "pool", "ost", "4" } },
1827 { LCFG_POOL_REM, "remove_pool", { "fsname", "pool", "ost", "4" } },
1828 { LCFG_POOL_DEL, "del_pool", { "fsname", "pool", "3", "4" } },
1829 { LCFG_SET_LDLM_TIMEOUT, "set_ldlm_timeout",
1830 { "parameter", "2", "3", "4" } },
1831 { 0, NULL, { NULL, NULL, NULL, NULL } }
1834 static struct lcfg_type_data *lcfg_cmd2data(__u32 cmd)
1838 while (lcfg_data_table[i].ltd_type != 0) {
1839 if (lcfg_data_table[i].ltd_type == cmd)
1840 return &lcfg_data_table[i];
1847 * Parse config record and output dump in supplied buffer.
1849 * This is separated from class_config_dump_handler() to use
1850 * for ioctl needs as well
1853 * - { index: 4, event: attach, device: lustrewt-clilov, type: lov,
1854 * UUID: lustrewt-clilov_UUID }
1856 int class_config_yaml_output(struct llog_rec_hdr *rec, char *buf, int size)
1858 struct lustre_cfg *lcfg = (struct lustre_cfg *)(rec + 1);
1860 char *end = buf + size;
1862 struct lcfg_type_data *ldata;
1864 LASSERT(rec->lrh_type == OBD_CFG_REC);
1865 rc = lustre_cfg_sanity_check(lcfg, rec->lrh_len);
1869 ldata = lcfg_cmd2data(lcfg->lcfg_command);
1873 if (lcfg->lcfg_command == LCFG_MARKER)
1876 /* form YAML entity */
1877 ptr += snprintf(ptr, end - ptr, "- { index: %u, event: %s",
1878 rec->lrh_index, ldata->ltd_name);
1880 if (lcfg->lcfg_flags)
1881 ptr += snprintf(ptr, end - ptr, ", flags: %#08x",
1884 ptr += snprintf(ptr, end - ptr, ", num: %#08x",
1886 if (lcfg->lcfg_nid) {
1887 char nidstr[LNET_NIDSTR_SIZE];
1889 libcfs_nid2str_r(lcfg->lcfg_nid, nidstr, sizeof(nidstr));
1890 ptr += snprintf(ptr, end - ptr, ", nid: %s(%#llx)",
1891 nidstr, lcfg->lcfg_nid);
1894 if (LUSTRE_CFG_BUFLEN(lcfg, 0) > 0)
1895 ptr += snprintf(ptr, end - ptr, ", device: %s",
1896 lustre_cfg_string(lcfg, 0));
1898 for (i = 1; i < lcfg->lcfg_bufcount; i++) {
1899 if (LUSTRE_CFG_BUFLEN(lcfg, i) > 0)
1900 ptr += snprintf(ptr, end - ptr, ", %s: %s",
1901 ldata->ltd_bufs[i - 1],
1902 lustre_cfg_string(lcfg, i));
1905 ptr += snprintf(ptr, end - ptr, " }\n");
1906 /* return consumed bytes */
1912 * parse config record and output dump in supplied buffer.
1913 * This is separated from class_config_dump_handler() to use
1914 * for ioctl needs as well
1916 static int class_config_parse_rec(struct llog_rec_hdr *rec, char *buf, int size)
1918 struct lustre_cfg *lcfg = (struct lustre_cfg *)(rec + 1);
1920 char *end = buf + size;
1925 LASSERT(rec->lrh_type == OBD_CFG_REC);
1926 rc = lustre_cfg_sanity_check(lcfg, rec->lrh_len);
1930 ptr += snprintf(ptr, end-ptr, "cmd=%05x ", lcfg->lcfg_command);
1931 if (lcfg->lcfg_flags)
1932 ptr += snprintf(ptr, end-ptr, "flags=%#08x ",
1936 ptr += snprintf(ptr, end-ptr, "num=%#08x ", lcfg->lcfg_num);
1938 if (lcfg->lcfg_nid) {
1939 char nidstr[LNET_NIDSTR_SIZE];
1941 libcfs_nid2str_r(lcfg->lcfg_nid, nidstr, sizeof(nidstr));
1942 ptr += snprintf(ptr, end-ptr, "nid=%s(%#llx)\n ",
1943 nidstr, lcfg->lcfg_nid);
1946 if (lcfg->lcfg_command == LCFG_MARKER) {
1947 struct cfg_marker *marker = lustre_cfg_buf(lcfg, 1);
1949 ptr += snprintf(ptr, end-ptr, "marker=%d(%#x)%s '%s'",
1950 marker->cm_step, marker->cm_flags,
1951 marker->cm_tgtname, marker->cm_comment);
1955 for (i = 0; i < lcfg->lcfg_bufcount; i++) {
1956 ptr += snprintf(ptr, end-ptr, "%d:%s ", i,
1957 lustre_cfg_string(lcfg, i));
1960 ptr += snprintf(ptr, end - ptr, "\n");
1961 /* return consumed bytes */
1966 int class_config_dump_handler(const struct lu_env *env,
1967 struct llog_handle *handle,
1968 struct llog_rec_hdr *rec, void *data)
1975 OBD_ALLOC(outstr, 256);
1979 if (rec->lrh_type == OBD_CFG_REC) {
1980 class_config_parse_rec(rec, outstr, 256);
1981 LCONSOLE(D_WARNING, " %s\n", outstr);
1983 LCONSOLE(D_WARNING, "unhandled lrh_type: %#x\n", rec->lrh_type);
1987 OBD_FREE(outstr, 256);
1991 /** Call class_cleanup and class_detach.
1992 * "Manual" only in the sense that we're faking lcfg commands.
1994 int class_manual_cleanup(struct obd_device *obd)
1997 struct lustre_cfg *lcfg;
1998 struct lustre_cfg_bufs bufs;
2003 CERROR("empty cleanup\n");
2012 CDEBUG(D_CONFIG, "Manual cleanup of %s (flags='%s')\n",
2013 obd->obd_name, flags);
2015 lustre_cfg_bufs_reset(&bufs, obd->obd_name);
2016 lustre_cfg_bufs_set_string(&bufs, 1, flags);
2017 OBD_ALLOC(lcfg, lustre_cfg_len(bufs.lcfg_bufcount, bufs.lcfg_buflen));
2020 lustre_cfg_init(lcfg, LCFG_CLEANUP, &bufs);
2022 rc = class_process_config(lcfg);
2024 CERROR("cleanup failed %d: %s\n", rc, obd->obd_name);
2028 /* the lcfg is almost the same for both ops */
2029 lcfg->lcfg_command = LCFG_DETACH;
2030 rc = class_process_config(lcfg);
2032 CERROR("detach failed %d: %s\n", rc, obd->obd_name);
2034 OBD_FREE(lcfg, lustre_cfg_len(lcfg->lcfg_bufcount, lcfg->lcfg_buflens));
2037 EXPORT_SYMBOL(class_manual_cleanup);
2040 * uuid<->export lustre hash operations
2044 uuid_hash(struct cfs_hash *hs, const void *key, unsigned mask)
2046 return cfs_hash_djb2_hash(((struct obd_uuid *)key)->uuid,
2047 sizeof(((struct obd_uuid *)key)->uuid), mask);
2051 uuid_key(struct hlist_node *hnode)
2053 struct obd_export *exp;
2055 exp = hlist_entry(hnode, struct obd_export, exp_uuid_hash);
2057 return &exp->exp_client_uuid;
2061 * NOTE: It is impossible to find an export that is in failed
2062 * state with this function
2065 uuid_keycmp(const void *key, struct hlist_node *hnode)
2067 struct obd_export *exp;
2070 exp = hlist_entry(hnode, struct obd_export, exp_uuid_hash);
2072 return obd_uuid_equals(key, &exp->exp_client_uuid) &&
2077 uuid_export_object(struct hlist_node *hnode)
2079 return hlist_entry(hnode, struct obd_export, exp_uuid_hash);
2083 uuid_export_get(struct cfs_hash *hs, struct hlist_node *hnode)
2085 struct obd_export *exp;
2087 exp = hlist_entry(hnode, struct obd_export, exp_uuid_hash);
2088 class_export_get(exp);
2092 uuid_export_put_locked(struct cfs_hash *hs, struct hlist_node *hnode)
2094 struct obd_export *exp;
2096 exp = hlist_entry(hnode, struct obd_export, exp_uuid_hash);
2097 class_export_put(exp);
2100 static struct cfs_hash_ops uuid_hash_ops = {
2101 .hs_hash = uuid_hash,
2103 .hs_keycmp = uuid_keycmp,
2104 .hs_object = uuid_export_object,
2105 .hs_get = uuid_export_get,
2106 .hs_put_locked = uuid_export_put_locked,
2111 * nid<->export hash operations
2115 nid_hash(struct cfs_hash *hs, const void *key, unsigned mask)
2117 return cfs_hash_djb2_hash(key, sizeof(lnet_nid_t), mask);
2121 nid_key(struct hlist_node *hnode)
2123 struct obd_export *exp;
2125 exp = hlist_entry(hnode, struct obd_export, exp_nid_hash);
2127 RETURN(&exp->exp_connection->c_peer.nid);
2131 * NOTE: It is impossible to find an export that is in failed
2132 * state with this function
2135 nid_kepcmp(const void *key, struct hlist_node *hnode)
2137 struct obd_export *exp;
2140 exp = hlist_entry(hnode, struct obd_export, exp_nid_hash);
2142 RETURN(exp->exp_connection->c_peer.nid == *(lnet_nid_t *)key &&
2147 nid_export_object(struct hlist_node *hnode)
2149 return hlist_entry(hnode, struct obd_export, exp_nid_hash);
2153 nid_export_get(struct cfs_hash *hs, struct hlist_node *hnode)
2155 struct obd_export *exp;
2157 exp = hlist_entry(hnode, struct obd_export, exp_nid_hash);
2158 class_export_get(exp);
2162 nid_export_put_locked(struct cfs_hash *hs, struct hlist_node *hnode)
2164 struct obd_export *exp;
2166 exp = hlist_entry(hnode, struct obd_export, exp_nid_hash);
2167 class_export_put(exp);
2170 static struct cfs_hash_ops nid_hash_ops = {
2171 .hs_hash = nid_hash,
2173 .hs_keycmp = nid_kepcmp,
2174 .hs_object = nid_export_object,
2175 .hs_get = nid_export_get,
2176 .hs_put_locked = nid_export_put_locked,
2181 * nid<->nidstats hash operations
2185 nidstats_key(struct hlist_node *hnode)
2187 struct nid_stat *ns;
2189 ns = hlist_entry(hnode, struct nid_stat, nid_hash);
2195 nidstats_keycmp(const void *key, struct hlist_node *hnode)
2197 return *(lnet_nid_t *)nidstats_key(hnode) == *(lnet_nid_t *)key;
2201 nidstats_object(struct hlist_node *hnode)
2203 return hlist_entry(hnode, struct nid_stat, nid_hash);
2207 nidstats_get(struct cfs_hash *hs, struct hlist_node *hnode)
2209 struct nid_stat *ns;
2211 ns = hlist_entry(hnode, struct nid_stat, nid_hash);
2216 nidstats_put_locked(struct cfs_hash *hs, struct hlist_node *hnode)
2218 struct nid_stat *ns;
2220 ns = hlist_entry(hnode, struct nid_stat, nid_hash);
2224 static struct cfs_hash_ops nid_stat_hash_ops = {
2225 .hs_hash = nid_hash,
2226 .hs_key = nidstats_key,
2227 .hs_keycmp = nidstats_keycmp,
2228 .hs_object = nidstats_object,
2229 .hs_get = nidstats_get,
2230 .hs_put_locked = nidstats_put_locked,
2235 * client_generation<->export hash operations
2239 gen_hash(struct cfs_hash *hs, const void *key, unsigned mask)
2241 return cfs_hash_djb2_hash(key, sizeof(__u32), mask);
2245 gen_key(struct hlist_node *hnode)
2247 struct obd_export *exp;
2249 exp = hlist_entry(hnode, struct obd_export, exp_gen_hash);
2251 RETURN(&exp->exp_target_data.ted_lcd->lcd_generation);
2255 * NOTE: It is impossible to find an export that is in failed
2256 * state with this function
2259 gen_kepcmp(const void *key, struct hlist_node *hnode)
2261 struct obd_export *exp;
2264 exp = hlist_entry(hnode, struct obd_export, exp_gen_hash);
2266 RETURN(exp->exp_target_data.ted_lcd->lcd_generation == *(__u32 *)key &&
2271 gen_export_object(struct hlist_node *hnode)
2273 return hlist_entry(hnode, struct obd_export, exp_gen_hash);
2277 gen_export_get(struct cfs_hash *hs, struct hlist_node *hnode)
2279 struct obd_export *exp;
2281 exp = hlist_entry(hnode, struct obd_export, exp_gen_hash);
2282 class_export_get(exp);
2286 gen_export_put_locked(struct cfs_hash *hs, struct hlist_node *hnode)
2288 struct obd_export *exp;
2290 exp = hlist_entry(hnode, struct obd_export, exp_gen_hash);
2291 class_export_put(exp);
2294 static struct cfs_hash_ops gen_hash_ops = {
2295 .hs_hash = gen_hash,
2297 .hs_keycmp = gen_kepcmp,
2298 .hs_object = gen_export_object,
2299 .hs_get = gen_export_get,
2300 .hs_put_locked = gen_export_put_locked,