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);
1298 switch(lcfg->lcfg_command) {
1300 err = class_setup(obd, lcfg);
1304 err = class_detach(obd, lcfg);
1307 case LCFG_CLEANUP: {
1308 err = class_cleanup(obd, lcfg);
1311 case LCFG_ADD_CONN: {
1312 err = class_add_conn(obd, lcfg);
1315 case LCFG_DEL_CONN: {
1316 err = class_del_conn(obd, lcfg);
1319 case LCFG_POOL_NEW: {
1320 err = obd_pool_new(obd, lustre_cfg_string(lcfg, 2));
1323 case LCFG_POOL_ADD: {
1324 err = obd_pool_add(obd, lustre_cfg_string(lcfg, 2),
1325 lustre_cfg_string(lcfg, 3));
1328 case LCFG_POOL_REM: {
1329 err = obd_pool_rem(obd, lustre_cfg_string(lcfg, 2),
1330 lustre_cfg_string(lcfg, 3));
1333 case LCFG_POOL_DEL: {
1334 err = obd_pool_del(obd, lustre_cfg_string(lcfg, 2));
1337 /* Process config log ADD_MDC record twice to add MDC also to LOV
1340 * add 0:lustre-clilmv 1:lustre-MDT0000_UUID 2:0 3:1
1341 * 4:lustre-MDT0000-mdc_UUID
1343 case LCFG_ADD_MDC: {
1344 struct obd_device *lov_obd;
1347 err = obd_process_config(obd, sizeof(*lcfg), lcfg);
1351 /* make sure this is client LMV log entry */
1352 clilmv = strstr(lustre_cfg_string(lcfg, 0), "clilmv");
1356 /* replace 'lmv' with 'lov' name to address LOV device and
1357 * process llog record to add MDC there. */
1359 lov_obd = class_name2obd(lustre_cfg_string(lcfg, 0));
1360 if (lov_obd == NULL) {
1362 CERROR("%s: Cannot find LOV by %s name, rc = %d\n",
1363 obd->obd_name, lustre_cfg_string(lcfg, 0), err);
1365 err = obd_process_config(lov_obd, sizeof(*lcfg), lcfg);
1367 /* restore 'lmv' name */
1372 err = obd_process_config(obd, sizeof(*lcfg), lcfg);
1379 if ((err < 0) && !(lcfg->lcfg_command & LCFG_REQUIRED)) {
1380 CWARN("Ignoring error %d on optional command %#x\n", err,
1381 lcfg->lcfg_command);
1386 EXPORT_SYMBOL(class_process_config);
1388 int class_process_proc_param(char *prefix, struct lprocfs_vars *lvars,
1389 struct lustre_cfg *lcfg, void *data)
1391 struct lprocfs_vars *var;
1392 struct file fakefile;
1393 struct seq_file fake_seqfile;
1395 int i, keylen, vallen;
1396 int matched = 0, j = 0;
1401 if (lcfg->lcfg_command != LCFG_PARAM) {
1402 CERROR("Unknown command: %d\n", lcfg->lcfg_command);
1406 /* fake a seq file so that var->fops->write can work... */
1407 fakefile.private_data = &fake_seqfile;
1408 fake_seqfile.private = data;
1409 /* e.g. tunefs.lustre --param mdt.group_upcall=foo /r/tmp/lustre-mdt
1410 or lctl conf_param lustre-MDT0000.mdt.group_upcall=bar
1411 or lctl conf_param lustre-OST0000.osc.max_dirty_mb=36 */
1412 for (i = 1; i < lcfg->lcfg_bufcount; i++) {
1413 key = lustre_cfg_buf(lcfg, i);
1414 /* Strip off prefix */
1415 if (class_match_param(key, prefix, &key))
1416 /* If the prefix doesn't match, return error so we
1417 * can pass it down the stack */
1419 sval = strchr(key, '=');
1420 if (!sval || *(sval + 1) == 0) {
1421 CERROR("%s: can't parse param '%s' (missing '=')\n",
1422 lustre_cfg_string(lcfg, 0),
1423 lustre_cfg_string(lcfg, i));
1424 /* rc = -EINVAL; continue parsing other params */
1427 keylen = sval - key;
1429 vallen = strlen(sval);
1432 /* Search proc entries */
1433 while (lvars[j].name) {
1435 if (class_match_param(key, var->name, NULL) == 0 &&
1436 keylen == strlen(var->name)) {
1440 if (var->fops && var->fops->write) {
1444 rc = (var->fops->write)(&fakefile, sval,
1453 /* It was upgraded from old MDT/OST device,
1454 * ignore the obsolete "sec_level" parameter. */
1455 if (strncmp("sec_level", key, keylen) == 0)
1458 CERROR("%s: unknown config parameter '%s'\n",
1459 lustre_cfg_string(lcfg, 0),
1460 lustre_cfg_string(lcfg, i));
1461 /* rc = -EINVAL; continue parsing other params */
1463 } else if (rc < 0) {
1464 CERROR("%s: error writing proc '%s'='%s': rc = %d\n",
1465 lustre_cfg_string(lcfg, 0), key, sval, rc);
1468 CDEBUG(D_CONFIG, "%s: Set parameter '%s'='%s'\n",
1469 lustre_cfg_string(lcfg, 0), key, sval);
1479 EXPORT_SYMBOL(class_process_proc_param);
1482 * Supplemental functions for config logs, it allocates lustre_cfg
1483 * buffers plus initialized llog record header at the beginning.
1485 struct llog_cfg_rec *lustre_cfg_rec_new(int cmd, struct lustre_cfg_bufs *bufs)
1487 struct llog_cfg_rec *lcr;
1492 reclen = lustre_cfg_len(bufs->lcfg_bufcount, bufs->lcfg_buflen);
1493 reclen = llog_data_len(reclen) + sizeof(struct llog_rec_hdr) +
1494 sizeof(struct llog_rec_tail);
1496 OBD_ALLOC(lcr, reclen);
1500 lustre_cfg_init(&lcr->lcr_cfg, cmd, bufs);
1502 lcr->lcr_hdr.lrh_len = reclen;
1503 lcr->lcr_hdr.lrh_type = OBD_CFG_REC;
1507 EXPORT_SYMBOL(lustre_cfg_rec_new);
1509 void lustre_cfg_rec_free(struct llog_cfg_rec *lcr)
1512 OBD_FREE(lcr, lcr->lcr_hdr.lrh_len);
1515 EXPORT_SYMBOL(lustre_cfg_rec_free);
1517 /** Parse a configuration llog, doing various manipulations on them
1518 * for various reasons, (modifications for compatibility, skip obsolete
1519 * records, change uuids, etc), then class_process_config() resulting
1522 int class_config_llog_handler(const struct lu_env *env,
1523 struct llog_handle *handle,
1524 struct llog_rec_hdr *rec, void *data)
1526 struct config_llog_instance *cfg = data;
1527 int cfg_len = rec->lrh_len;
1528 char *cfg_buf = (char *) (rec + 1);
1532 /* class_config_dump_handler(handle, rec, data); */
1534 switch (rec->lrh_type) {
1536 struct lustre_cfg *lcfg, *lcfg_new;
1537 struct lustre_cfg_bufs bufs;
1538 char *inst_name = NULL;
1542 lcfg = (struct lustre_cfg *)cfg_buf;
1543 if (lcfg->lcfg_version == __swab32(LUSTRE_CFG_VERSION)) {
1544 lustre_swab_lustre_cfg(lcfg);
1548 rc = lustre_cfg_sanity_check(cfg_buf, cfg_len);
1552 /* Figure out config state info */
1553 if (lcfg->lcfg_command == LCFG_MARKER) {
1554 struct cfg_marker *marker = lustre_cfg_buf(lcfg, 1);
1555 lustre_swab_cfg_marker(marker, swab,
1556 LUSTRE_CFG_BUFLEN(lcfg, 1));
1557 CDEBUG(D_CONFIG, "Marker, inst_flg=%#x mark_flg=%#x\n",
1558 cfg->cfg_flags, marker->cm_flags);
1559 if (marker->cm_flags & CM_START) {
1560 /* all previous flags off */
1561 cfg->cfg_flags = CFG_F_MARKER;
1562 server_name2index(marker->cm_tgtname,
1563 &cfg->cfg_lwp_idx, NULL);
1564 if (marker->cm_flags & CM_SKIP) {
1565 cfg->cfg_flags |= CFG_F_SKIP;
1566 CDEBUG(D_CONFIG, "SKIP #%d\n",
1568 } else if ((marker->cm_flags & CM_EXCLUDE) ||
1570 lustre_check_exclusion(cfg->cfg_sb,
1571 marker->cm_tgtname))) {
1572 cfg->cfg_flags |= CFG_F_EXCLUDE;
1573 CDEBUG(D_CONFIG, "EXCLUDE %d\n",
1576 } else if (marker->cm_flags & CM_END) {
1580 /* A config command without a start marker before it is
1581 illegal (post 146) */
1582 if (!(cfg->cfg_flags & CFG_F_COMPAT146) &&
1583 !(cfg->cfg_flags & CFG_F_MARKER) &&
1584 (lcfg->lcfg_command != LCFG_MARKER)) {
1585 CWARN("Config not inside markers, ignoring! "
1586 "(inst: %p, uuid: %s, flags: %#x)\n",
1588 cfg->cfg_uuid.uuid, cfg->cfg_flags);
1589 cfg->cfg_flags |= CFG_F_SKIP;
1591 if (cfg->cfg_flags & CFG_F_SKIP) {
1592 CDEBUG(D_CONFIG, "skipping %#x\n",
1595 /* No processing! */
1600 * For interoperability between 1.8 and 2.0,
1601 * rename "mds" obd device type to "mdt".
1604 char *typename = lustre_cfg_string(lcfg, 1);
1605 char *index = lustre_cfg_string(lcfg, 2);
1607 if ((lcfg->lcfg_command == LCFG_ATTACH && typename &&
1608 strcmp(typename, "mds") == 0)) {
1609 CWARN("For 1.8 interoperability, rename obd "
1610 "type from mds to mdt\n");
1613 if ((lcfg->lcfg_command == LCFG_SETUP && index &&
1614 strcmp(index, "type") == 0)) {
1615 CDEBUG(D_INFO, "For 1.8 interoperability, "
1616 "set this index to '0'\n");
1622 #ifdef HAVE_SERVER_SUPPORT
1623 /* newer MDS replaces LOV/OSC with LOD/OSP */
1625 char *typename = lustre_cfg_string(lcfg, 1);
1627 if ((lcfg->lcfg_command == LCFG_ATTACH && typename &&
1628 strcmp(typename, LUSTRE_LOV_NAME) == 0) &&
1629 cfg->cfg_sb && IS_MDT(s2lsi(cfg->cfg_sb))) {
1631 "For 2.x interoperability, rename obd "
1632 "type from lov to lod (%s)\n",
1633 s2lsi(cfg->cfg_sb)->lsi_svname);
1634 strcpy(typename, LUSTRE_LOD_NAME);
1636 if ((lcfg->lcfg_command == LCFG_ATTACH && typename &&
1637 strcmp(typename, LUSTRE_OSC_NAME) == 0) &&
1638 cfg->cfg_sb && IS_MDT(s2lsi(cfg->cfg_sb))) {
1640 "For 2.x interoperability, rename obd "
1641 "type from osc to osp (%s)\n",
1642 s2lsi(cfg->cfg_sb)->lsi_svname);
1643 strcpy(typename, LUSTRE_OSP_NAME);
1646 #endif /* HAVE_SERVER_SUPPORT */
1648 if (cfg->cfg_flags & CFG_F_EXCLUDE) {
1649 CDEBUG(D_CONFIG, "cmd: %x marked EXCLUDED\n",
1650 lcfg->lcfg_command);
1651 if (lcfg->lcfg_command == LCFG_LOV_ADD_OBD)
1652 /* Add inactive instead */
1653 lcfg->lcfg_command = LCFG_LOV_ADD_INA;
1656 lustre_cfg_bufs_reset(&bufs, NULL);
1657 lustre_cfg_bufs_init(&bufs, lcfg);
1659 if (cfg->cfg_instance &&
1660 LUSTRE_CFG_BUFLEN(lcfg, 0) > 0) {
1661 inst_len = LUSTRE_CFG_BUFLEN(lcfg, 0) +
1662 sizeof(cfg->cfg_instance) * 2 + 4;
1663 OBD_ALLOC(inst_name, inst_len);
1664 if (inst_name == NULL)
1665 GOTO(out, rc = -ENOMEM);
1666 snprintf(inst_name, inst_len, "%s-%p",
1667 lustre_cfg_string(lcfg, 0),
1669 lustre_cfg_bufs_set_string(&bufs, 0, inst_name);
1670 CDEBUG(D_CONFIG, "cmd %x, instance name: %s\n",
1671 lcfg->lcfg_command, inst_name);
1674 /* we override the llog's uuid for clients, to insure they
1676 if (cfg->cfg_instance != NULL &&
1677 lcfg->lcfg_command == LCFG_ATTACH) {
1678 lustre_cfg_bufs_set_string(&bufs, 2,
1679 cfg->cfg_uuid.uuid);
1682 * sptlrpc config record, we expect 2 data segments:
1683 * [0]: fs_name/target_name,
1685 * moving them to index [1] and [2], and insert MGC's
1686 * obdname at index [0].
1688 if (cfg->cfg_instance == NULL &&
1689 lcfg->lcfg_command == LCFG_SPTLRPC_CONF) {
1690 lustre_cfg_bufs_set(&bufs, 2, bufs.lcfg_buf[1],
1691 bufs.lcfg_buflen[1]);
1692 lustre_cfg_bufs_set(&bufs, 1, bufs.lcfg_buf[0],
1693 bufs.lcfg_buflen[0]);
1694 lustre_cfg_bufs_set_string(&bufs, 0,
1698 /* Add net info to setup command
1699 * if given on command line.
1700 * So config log will be:
1704 * [3]: inactive-on-startup
1705 * [4]: restrictive net
1707 if (cfg && cfg->cfg_sb && s2lsi(cfg->cfg_sb) &&
1708 !IS_SERVER(s2lsi(cfg->cfg_sb))) {
1709 struct lustre_sb_info *lsi = s2lsi(cfg->cfg_sb);
1710 char *nidnet = lsi->lsi_lmd->lmd_nidnet;
1712 if (lcfg->lcfg_command == LCFG_SETUP &&
1713 lcfg->lcfg_bufcount != 2 && nidnet) {
1714 CDEBUG(D_CONFIG, "Adding net %s info to setup "
1715 "command for client %s\n", nidnet,
1716 lustre_cfg_string(lcfg, 0));
1717 lustre_cfg_bufs_set_string(&bufs, 4, nidnet);
1721 /* Skip add_conn command if uuid is
1722 * not on restricted net */
1723 if (cfg && cfg->cfg_sb && s2lsi(cfg->cfg_sb) &&
1724 !IS_SERVER(s2lsi(cfg->cfg_sb))) {
1725 struct lustre_sb_info *lsi = s2lsi(cfg->cfg_sb);
1726 char *uuid_str = lustre_cfg_string(lcfg, 1);
1728 if (lcfg->lcfg_command == LCFG_ADD_CONN &&
1729 lsi->lsi_lmd->lmd_nidnet &&
1730 LNET_NIDNET(libcfs_str2nid(uuid_str)) !=
1731 libcfs_str2net(lsi->lsi_lmd->lmd_nidnet)) {
1732 CDEBUG(D_CONFIG, "skipping add_conn for %s\n",
1735 /* No processing! */
1740 OBD_ALLOC(lcfg_new, lustre_cfg_len(bufs.lcfg_bufcount,
1743 GOTO(out, rc = -ENOMEM);
1745 lustre_cfg_init(lcfg_new, lcfg->lcfg_command, &bufs);
1746 lcfg_new->lcfg_num = lcfg->lcfg_num;
1747 lcfg_new->lcfg_flags = lcfg->lcfg_flags;
1749 /* XXX Hack to try to remain binary compatible with
1750 * pre-newconfig logs */
1751 if (lcfg->lcfg_nal != 0 && /* pre-newconfig log? */
1752 (lcfg->lcfg_nid >> 32) == 0) {
1753 __u32 addr = (__u32)(lcfg->lcfg_nid & 0xffffffff);
1755 lcfg_new->lcfg_nid =
1756 LNET_MKNID(LNET_MKNET(lcfg->lcfg_nal, 0), addr);
1757 CWARN("Converted pre-newconfig NAL %d NID %x to %s\n",
1758 lcfg->lcfg_nal, addr,
1759 libcfs_nid2str(lcfg_new->lcfg_nid));
1761 lcfg_new->lcfg_nid = lcfg->lcfg_nid;
1764 lcfg_new->lcfg_nal = 0; /* illegal value for obsolete field */
1766 rc = class_process_config(lcfg_new);
1767 OBD_FREE(lcfg_new, lustre_cfg_len(lcfg_new->lcfg_bufcount,
1768 lcfg_new->lcfg_buflens));
1770 OBD_FREE(inst_name, inst_len);
1774 CERROR("Unknown llog record type %#x encountered\n",
1780 CERROR("%s: cfg command failed: rc = %d\n",
1781 handle->lgh_ctxt->loc_obd->obd_name, rc);
1782 class_config_dump_handler(NULL, handle, rec, data);
1786 EXPORT_SYMBOL(class_config_llog_handler);
1788 int class_config_parse_llog(const struct lu_env *env, struct llog_ctxt *ctxt,
1789 char *name, struct config_llog_instance *cfg)
1791 struct llog_process_cat_data cd = {
1792 .lpcd_first_idx = 0,
1794 struct llog_handle *llh;
1799 CDEBUG(D_INFO, "looking up llog %s\n", name);
1800 rc = llog_open(env, ctxt, &llh, NULL, name, LLOG_OPEN_EXISTS);
1804 rc = llog_init_handle(env, llh, LLOG_F_IS_PLAIN, NULL);
1806 GOTO(parse_out, rc);
1808 /* continue processing from where we last stopped to end-of-log */
1810 cd.lpcd_first_idx = cfg->cfg_last_idx;
1811 callback = cfg->cfg_callback;
1812 LASSERT(callback != NULL);
1814 callback = class_config_llog_handler;
1817 cd.lpcd_last_idx = 0;
1819 rc = llog_process(env, llh, callback, cfg, &cd);
1821 CDEBUG(D_CONFIG, "Processed log %s gen %d-%d (rc=%d)\n", name,
1822 cd.lpcd_first_idx + 1, cd.lpcd_last_idx, rc);
1824 cfg->cfg_last_idx = cd.lpcd_last_idx;
1827 llog_close(env, llh);
1830 EXPORT_SYMBOL(class_config_parse_llog);
1832 static struct lcfg_type_data {
1836 } lcfg_data_table[] = {
1837 { LCFG_ATTACH, "attach", { "type", "UUID", "3", "4" } },
1838 { LCFG_DETACH, "detach", { "1", "2", "3", "4" } },
1839 { LCFG_SETUP, "setup", { "UUID", "node", "options", "failout" } },
1840 { LCFG_CLEANUP, "cleanup", { "1", "2", "3", "4" } },
1841 { LCFG_ADD_UUID, "add_uuid", { "node", "2", "3", "4" } },
1842 { LCFG_DEL_UUID, "del_uuid", { "1", "2", "3", "4" } },
1843 { LCFG_MOUNTOPT, "new_profile", { "name", "lov", "lmv", "4" } },
1844 { LCFG_DEL_MOUNTOPT, "del_mountopt", { "1", "2", "3", "4" } , },
1845 { LCFG_SET_TIMEOUT, "set_timeout", { "parameter", "2", "3", "4" } },
1846 { LCFG_SET_UPCALL, "set_upcall", { "1", "2", "3", "4" } },
1847 { LCFG_ADD_CONN, "add_conn", { "node", "2", "3", "4" } },
1848 { LCFG_DEL_CONN, "del_conn", { "1", "2", "3", "4" } },
1849 { LCFG_LOV_ADD_OBD, "add_osc", { "ost", "index", "gen", "UUID" } },
1850 { LCFG_LOV_DEL_OBD, "del_osc", { "1", "2", "3", "4" } },
1851 { LCFG_PARAM, "set_param", { "parameter", "value", "3", "4" } },
1852 { LCFG_MARKER, "marker", { "1", "2", "3", "4" } },
1853 { LCFG_LOG_START, "log_start", { "1", "2", "3", "4" } },
1854 { LCFG_LOG_END, "log_end", { "1", "2", "3", "4" } },
1855 { LCFG_LOV_ADD_INA, "add_osc_inactive", { "1", "2", "3", "4" } },
1856 { LCFG_ADD_MDC, "add_mdc", { "mdt", "index", "gen", "UUID" } },
1857 { LCFG_DEL_MDC, "del_mdc", { "1", "2", "3", "4" } },
1858 { LCFG_SPTLRPC_CONF, "security", { "parameter", "2", "3", "4" } },
1859 { LCFG_POOL_NEW, "new_pool", { "fsname", "pool", "3", "4" } },
1860 { LCFG_POOL_ADD, "add_pool", { "fsname", "pool", "ost", "4" } },
1861 { LCFG_POOL_REM, "remove_pool", { "fsname", "pool", "ost", "4" } },
1862 { LCFG_POOL_DEL, "del_pool", { "fsname", "pool", "3", "4" } },
1863 { LCFG_SET_LDLM_TIMEOUT, "set_ldlm_timeout",
1864 { "parameter", "2", "3", "4" } },
1865 { 0, NULL, { NULL, NULL, NULL, NULL } }
1868 static struct lcfg_type_data *lcfg_cmd2data(__u32 cmd)
1872 while (lcfg_data_table[i].ltd_type != 0) {
1873 if (lcfg_data_table[i].ltd_type == cmd)
1874 return &lcfg_data_table[i];
1881 * Parse config record and output dump in supplied buffer.
1883 * This is separated from class_config_dump_handler() to use
1884 * for ioctl needs as well
1887 * - { index: 4, event: attach, device: lustrewt-clilov, type: lov,
1888 * UUID: lustrewt-clilov_UUID }
1890 int class_config_yaml_output(struct llog_rec_hdr *rec, char *buf, int size)
1892 struct lustre_cfg *lcfg = (struct lustre_cfg *)(rec + 1);
1894 char *end = buf + size;
1896 struct lcfg_type_data *ldata;
1898 LASSERT(rec->lrh_type == OBD_CFG_REC);
1899 rc = lustre_cfg_sanity_check(lcfg, rec->lrh_len);
1903 ldata = lcfg_cmd2data(lcfg->lcfg_command);
1907 if (lcfg->lcfg_command == LCFG_MARKER)
1910 /* form YAML entity */
1911 ptr += snprintf(ptr, end - ptr, "- { index: %u, event: %s",
1912 rec->lrh_index, ldata->ltd_name);
1914 if (lcfg->lcfg_flags)
1915 ptr += snprintf(ptr, end - ptr, ", flags: %#08x",
1918 ptr += snprintf(ptr, end - ptr, ", num: %#08x",
1920 if (lcfg->lcfg_nid) {
1921 char nidstr[LNET_NIDSTR_SIZE];
1923 libcfs_nid2str_r(lcfg->lcfg_nid, nidstr, sizeof(nidstr));
1924 ptr += snprintf(ptr, end - ptr, ", nid: %s(%#llx)",
1925 nidstr, lcfg->lcfg_nid);
1928 if (LUSTRE_CFG_BUFLEN(lcfg, 0) > 0)
1929 ptr += snprintf(ptr, end - ptr, ", device: %s",
1930 lustre_cfg_string(lcfg, 0));
1932 for (i = 1; i < lcfg->lcfg_bufcount; i++) {
1933 if (LUSTRE_CFG_BUFLEN(lcfg, i) > 0)
1934 ptr += snprintf(ptr, end - ptr, ", %s: %s",
1935 ldata->ltd_bufs[i - 1],
1936 lustre_cfg_string(lcfg, i));
1939 ptr += snprintf(ptr, end - ptr, " }\n");
1940 /* return consumed bytes */
1946 * parse config record and output dump in supplied buffer.
1947 * This is separated from class_config_dump_handler() to use
1948 * for ioctl needs as well
1950 static int class_config_parse_rec(struct llog_rec_hdr *rec, char *buf, int size)
1952 struct lustre_cfg *lcfg = (struct lustre_cfg *)(rec + 1);
1954 char *end = buf + size;
1959 LASSERT(rec->lrh_type == OBD_CFG_REC);
1960 rc = lustre_cfg_sanity_check(lcfg, rec->lrh_len);
1964 ptr += snprintf(ptr, end-ptr, "cmd=%05x ", lcfg->lcfg_command);
1965 if (lcfg->lcfg_flags)
1966 ptr += snprintf(ptr, end-ptr, "flags=%#08x ",
1970 ptr += snprintf(ptr, end-ptr, "num=%#08x ", lcfg->lcfg_num);
1972 if (lcfg->lcfg_nid) {
1973 char nidstr[LNET_NIDSTR_SIZE];
1975 libcfs_nid2str_r(lcfg->lcfg_nid, nidstr, sizeof(nidstr));
1976 ptr += snprintf(ptr, end-ptr, "nid=%s(%#llx)\n ",
1977 nidstr, lcfg->lcfg_nid);
1980 if (lcfg->lcfg_command == LCFG_MARKER) {
1981 struct cfg_marker *marker = lustre_cfg_buf(lcfg, 1);
1983 ptr += snprintf(ptr, end-ptr, "marker=%d(%#x)%s '%s'",
1984 marker->cm_step, marker->cm_flags,
1985 marker->cm_tgtname, marker->cm_comment);
1989 for (i = 0; i < lcfg->lcfg_bufcount; i++) {
1990 ptr += snprintf(ptr, end-ptr, "%d:%s ", i,
1991 lustre_cfg_string(lcfg, i));
1994 ptr += snprintf(ptr, end - ptr, "\n");
1995 /* return consumed bytes */
2000 int class_config_dump_handler(const struct lu_env *env,
2001 struct llog_handle *handle,
2002 struct llog_rec_hdr *rec, void *data)
2009 OBD_ALLOC(outstr, 256);
2013 if (rec->lrh_type == OBD_CFG_REC) {
2014 class_config_parse_rec(rec, outstr, 256);
2015 LCONSOLE(D_WARNING, " %s\n", outstr);
2017 LCONSOLE(D_WARNING, "unhandled lrh_type: %#x\n", rec->lrh_type);
2021 OBD_FREE(outstr, 256);
2025 /** Call class_cleanup and class_detach.
2026 * "Manual" only in the sense that we're faking lcfg commands.
2028 int class_manual_cleanup(struct obd_device *obd)
2031 struct lustre_cfg *lcfg;
2032 struct lustre_cfg_bufs bufs;
2037 CERROR("empty cleanup\n");
2046 CDEBUG(D_CONFIG, "Manual cleanup of %s (flags='%s')\n",
2047 obd->obd_name, flags);
2049 lustre_cfg_bufs_reset(&bufs, obd->obd_name);
2050 lustre_cfg_bufs_set_string(&bufs, 1, flags);
2051 OBD_ALLOC(lcfg, lustre_cfg_len(bufs.lcfg_bufcount, bufs.lcfg_buflen));
2054 lustre_cfg_init(lcfg, LCFG_CLEANUP, &bufs);
2056 rc = class_process_config(lcfg);
2058 CERROR("cleanup failed %d: %s\n", rc, obd->obd_name);
2062 /* the lcfg is almost the same for both ops */
2063 lcfg->lcfg_command = LCFG_DETACH;
2064 rc = class_process_config(lcfg);
2066 CERROR("detach failed %d: %s\n", rc, obd->obd_name);
2068 OBD_FREE(lcfg, lustre_cfg_len(lcfg->lcfg_bufcount, lcfg->lcfg_buflens));
2071 EXPORT_SYMBOL(class_manual_cleanup);
2074 * uuid<->export lustre hash operations
2078 uuid_hash(struct cfs_hash *hs, const void *key, unsigned mask)
2080 return cfs_hash_djb2_hash(((struct obd_uuid *)key)->uuid,
2081 sizeof(((struct obd_uuid *)key)->uuid), mask);
2085 uuid_key(struct hlist_node *hnode)
2087 struct obd_export *exp;
2089 exp = hlist_entry(hnode, struct obd_export, exp_uuid_hash);
2091 return &exp->exp_client_uuid;
2095 * NOTE: It is impossible to find an export that is in failed
2096 * state with this function
2099 uuid_keycmp(const void *key, struct hlist_node *hnode)
2101 struct obd_export *exp;
2104 exp = hlist_entry(hnode, struct obd_export, exp_uuid_hash);
2106 return obd_uuid_equals(key, &exp->exp_client_uuid) &&
2111 uuid_export_object(struct hlist_node *hnode)
2113 return hlist_entry(hnode, struct obd_export, exp_uuid_hash);
2117 uuid_export_get(struct cfs_hash *hs, struct hlist_node *hnode)
2119 struct obd_export *exp;
2121 exp = hlist_entry(hnode, struct obd_export, exp_uuid_hash);
2122 class_export_get(exp);
2126 uuid_export_put_locked(struct cfs_hash *hs, struct hlist_node *hnode)
2128 struct obd_export *exp;
2130 exp = hlist_entry(hnode, struct obd_export, exp_uuid_hash);
2131 class_export_put(exp);
2134 static struct cfs_hash_ops uuid_hash_ops = {
2135 .hs_hash = uuid_hash,
2137 .hs_keycmp = uuid_keycmp,
2138 .hs_object = uuid_export_object,
2139 .hs_get = uuid_export_get,
2140 .hs_put_locked = uuid_export_put_locked,
2145 * nid<->export hash operations
2149 nid_hash(struct cfs_hash *hs, const void *key, unsigned mask)
2151 return cfs_hash_djb2_hash(key, sizeof(lnet_nid_t), mask);
2155 nid_key(struct hlist_node *hnode)
2157 struct obd_export *exp;
2159 exp = hlist_entry(hnode, struct obd_export, exp_nid_hash);
2161 RETURN(&exp->exp_connection->c_peer.nid);
2165 * NOTE: It is impossible to find an export that is in failed
2166 * state with this function
2169 nid_kepcmp(const void *key, struct hlist_node *hnode)
2171 struct obd_export *exp;
2174 exp = hlist_entry(hnode, struct obd_export, exp_nid_hash);
2176 RETURN(exp->exp_connection->c_peer.nid == *(lnet_nid_t *)key &&
2181 nid_export_object(struct hlist_node *hnode)
2183 return hlist_entry(hnode, struct obd_export, exp_nid_hash);
2187 nid_export_get(struct cfs_hash *hs, struct hlist_node *hnode)
2189 struct obd_export *exp;
2191 exp = hlist_entry(hnode, struct obd_export, exp_nid_hash);
2192 class_export_get(exp);
2196 nid_export_put_locked(struct cfs_hash *hs, struct hlist_node *hnode)
2198 struct obd_export *exp;
2200 exp = hlist_entry(hnode, struct obd_export, exp_nid_hash);
2201 class_export_put(exp);
2204 static struct cfs_hash_ops nid_hash_ops = {
2205 .hs_hash = nid_hash,
2207 .hs_keycmp = nid_kepcmp,
2208 .hs_object = nid_export_object,
2209 .hs_get = nid_export_get,
2210 .hs_put_locked = nid_export_put_locked,
2215 * nid<->nidstats hash operations
2219 nidstats_key(struct hlist_node *hnode)
2221 struct nid_stat *ns;
2223 ns = hlist_entry(hnode, struct nid_stat, nid_hash);
2229 nidstats_keycmp(const void *key, struct hlist_node *hnode)
2231 return *(lnet_nid_t *)nidstats_key(hnode) == *(lnet_nid_t *)key;
2235 nidstats_object(struct hlist_node *hnode)
2237 return hlist_entry(hnode, struct nid_stat, nid_hash);
2241 nidstats_get(struct cfs_hash *hs, struct hlist_node *hnode)
2243 struct nid_stat *ns;
2245 ns = hlist_entry(hnode, struct nid_stat, nid_hash);
2250 nidstats_put_locked(struct cfs_hash *hs, struct hlist_node *hnode)
2252 struct nid_stat *ns;
2254 ns = hlist_entry(hnode, struct nid_stat, nid_hash);
2258 static struct cfs_hash_ops nid_stat_hash_ops = {
2259 .hs_hash = nid_hash,
2260 .hs_key = nidstats_key,
2261 .hs_keycmp = nidstats_keycmp,
2262 .hs_object = nidstats_object,
2263 .hs_get = nidstats_get,
2264 .hs_put_locked = nidstats_put_locked,
2269 * client_generation<->export hash operations
2273 gen_hash(struct cfs_hash *hs, const void *key, unsigned mask)
2275 return cfs_hash_djb2_hash(key, sizeof(__u32), mask);
2279 gen_key(struct hlist_node *hnode)
2281 struct obd_export *exp;
2283 exp = hlist_entry(hnode, struct obd_export, exp_gen_hash);
2285 RETURN(&exp->exp_target_data.ted_lcd->lcd_generation);
2289 * NOTE: It is impossible to find an export that is in failed
2290 * state with this function
2293 gen_kepcmp(const void *key, struct hlist_node *hnode)
2295 struct obd_export *exp;
2298 exp = hlist_entry(hnode, struct obd_export, exp_gen_hash);
2300 RETURN(exp->exp_target_data.ted_lcd->lcd_generation == *(__u32 *)key &&
2305 gen_export_object(struct hlist_node *hnode)
2307 return hlist_entry(hnode, struct obd_export, exp_gen_hash);
2311 gen_export_get(struct cfs_hash *hs, struct hlist_node *hnode)
2313 struct obd_export *exp;
2315 exp = hlist_entry(hnode, struct obd_export, exp_gen_hash);
2316 class_export_get(exp);
2320 gen_export_put_locked(struct cfs_hash *hs, struct hlist_node *hnode)
2322 struct obd_export *exp;
2324 exp = hlist_entry(hnode, struct obd_export, exp_gen_hash);
2325 class_export_put(exp);
2328 static struct cfs_hash_ops gen_hash_ops = {
2329 .hs_hash = gen_hash,
2331 .hs_keycmp = gen_kepcmp,
2332 .hs_object = gen_export_object,
2333 .hs_get = gen_export_get,
2334 .hs_put_locked = gen_export_put_locked,