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, 2017, 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/kobject.h>
40 #include <linux/string.h>
42 #include <llog_swab.h>
43 #include <lprocfs_status.h>
44 #include <lustre_disk.h>
45 #include <uapi/linux/lustre/lustre_ioctl.h>
46 #include <lustre_log.h>
47 #include <uapi/linux/lustre/lustre_param.h>
48 #include <obd_class.h>
50 #include "llog_internal.h"
52 static struct cfs_hash_ops uuid_hash_ops;
53 static struct cfs_hash_ops nid_hash_ops;
54 static struct cfs_hash_ops nid_stat_hash_ops;
55 static struct cfs_hash_ops gen_hash_ops;
57 /*********** string parsing utils *********/
59 /* returns 0 if we find this key in the buffer, else 1 */
60 int class_find_param(char *buf, char *key, char **valp)
67 ptr = strstr(buf, key);
72 *valp = ptr + strlen(key);
76 EXPORT_SYMBOL(class_find_param);
79 * Check whether the proc parameter \a param is an old parameter or not from
80 * the array \a ptr which contains the mapping from old parameters to new ones.
81 * If it's an old one, then return the pointer to the cfg_interop_param struc-
82 * ture which contains both the old and new parameters.
84 * \param param proc parameter
85 * \param ptr an array which contains the mapping from
86 * old parameters to new ones
88 * \retval valid-pointer pointer to the cfg_interop_param structure
89 * which contains the old and new parameters
90 * \retval NULL \a param or \a ptr is NULL,
91 * or \a param is not an old parameter
93 struct cfg_interop_param *class_find_old_param(const char *param,
94 struct cfg_interop_param *ptr)
102 value = strchr(param, '=');
104 name_len = value - param;
106 name_len = strlen(param);
108 while (ptr->old_param) {
109 if (strncmp(param, ptr->old_param, name_len) == 0 &&
110 name_len == strlen(ptr->old_param))
117 EXPORT_SYMBOL(class_find_old_param);
120 * Finds a parameter in \a params and copies it to \a copy.
122 * Leading spaces are skipped. Next space or end of string is the
123 * parameter terminator with the exception that spaces inside single or double
124 * quotes get included into a parameter. The parameter is copied into \a copy
125 * which has to be allocated big enough by a caller, quotes are stripped in
126 * the copy and the copy is terminated by 0.
128 * On return \a params is set to next parameter or to NULL if last
129 * parameter is returned.
131 * \retval 0 if parameter is returned in \a copy
132 * \retval 1 otherwise
133 * \retval -EINVAL if unbalanced quota is found
135 int class_get_next_param(char **params, char *copy)
150 q1 = strpbrk(str, " '\"");
153 memcpy(copy, str, len);
160 memcpy(copy, str, len);
166 memcpy(copy, str, len);
169 /* search for the matching closing quote */
171 q2 = strchr(str, *q1);
173 CERROR("Unbalanced quota in parameters: \"%s\"\n",
178 memcpy(copy, str, len);
184 EXPORT_SYMBOL(class_get_next_param);
187 * returns 0 if this is the first key in the buffer, else 1.
188 * valp points to first char after key.
190 int class_match_param(char *buf, const char *key, char **valp)
195 if (memcmp(buf, key, strlen(key)) != 0)
199 *valp = buf + strlen(key);
203 EXPORT_SYMBOL(class_match_param);
205 static int parse_nid(char *buf, void *value, int quiet)
207 lnet_nid_t *nid = (lnet_nid_t *)value;
209 *nid = libcfs_str2nid(buf);
210 if (*nid != LNET_NID_ANY)
214 LCONSOLE_ERROR_MSG(0x159, "Can't parse NID '%s'\n", buf);
218 static int parse_net(char *buf, void *value)
220 __u32 *net = (__u32 *)value;
222 *net = libcfs_str2net(buf);
223 CDEBUG(D_INFO, "Net %s\n", libcfs_net2str(*net));
236 * endh is set to next separator
238 static int class_parse_value(char *buf, int opc, void *value, char **endh,
247 while (*buf == ',' || *buf == ':')
249 if (*buf == ' ' || *buf == '/' || *buf == '\0')
252 /* NID separators or end of NIDs */
253 endp = strpbrk(buf, ",: /");
255 endp = buf + strlen(buf);
262 case CLASS_PARSE_NID:
263 rc = parse_nid(buf, value, quiet);
265 case CLASS_PARSE_NET:
266 rc = parse_net(buf, value);
277 int class_parse_nid(char *buf, lnet_nid_t *nid, char **endh)
279 return class_parse_value(buf, CLASS_PARSE_NID, (void *)nid, endh, 0);
281 EXPORT_SYMBOL(class_parse_nid);
283 int class_parse_nid_quiet(char *buf, lnet_nid_t *nid, char **endh)
285 return class_parse_value(buf, CLASS_PARSE_NID, (void *)nid, endh, 1);
287 EXPORT_SYMBOL(class_parse_nid_quiet);
289 int class_parse_net(char *buf, __u32 *net, char **endh)
291 return class_parse_value(buf, CLASS_PARSE_NET, (void *)net, endh, 0);
295 * 1 param contains key and match
296 * 0 param contains key and not match
297 * -1 param does not contain key
299 int class_match_nid(char *buf, char *key, lnet_nid_t nid)
304 while (class_find_param(buf, key, &buf) == 0) {
306 * please restrict to the NIDs pertaining to
309 while (class_parse_nid(buf, &tmp, &buf) == 0) {
318 int class_match_net(char *buf, char *key, __u32 net)
323 while (class_find_param(buf, key, &buf) == 0) {
325 * please restrict to the NIDs pertaining to
326 * the specified networks
328 while (class_parse_net(buf, &tmp, &buf) == 0) {
337 char *lustre_cfg_string(struct lustre_cfg *lcfg, u32 index)
341 if (!lcfg->lcfg_buflens[index])
344 s = lustre_cfg_buf(lcfg, index);
349 * make sure it's NULL terminated, even if this kills a char
350 * of data. Try to use the padding first though.
352 if (s[lcfg->lcfg_buflens[index] - 1] != '\0') {
353 size_t last = ALIGN(lcfg->lcfg_buflens[index], 8) - 1;
356 /* Use the smaller value */
357 if (last > lcfg->lcfg_buflens[index])
358 last = lcfg->lcfg_buflens[index];
363 CWARN("Truncated buf %d to '%s' (lost '%c'...)\n",
369 EXPORT_SYMBOL(lustre_cfg_string);
371 /********************** class fns **********************/
374 * Create a new OBD device and set the type, name and uuid. If successful,
375 * the new device can be accessed by either name or uuid.
377 int class_attach(struct lustre_cfg *lcfg)
379 struct obd_export *exp;
380 struct obd_device *obd = NULL;
381 char *typename, *name, *uuid;
386 if (!LUSTRE_CFG_BUFLEN(lcfg, 1)) {
387 CERROR("No type passed!\n");
390 typename = lustre_cfg_string(lcfg, 1);
392 if (!LUSTRE_CFG_BUFLEN(lcfg, 0)) {
393 CERROR("No name passed!\n");
396 name = lustre_cfg_string(lcfg, 0);
397 if (!LUSTRE_CFG_BUFLEN(lcfg, 2)) {
398 CERROR("No UUID passed!\n");
402 uuid = lustre_cfg_string(lcfg, 2);
404 if (len >= sizeof(obd->obd_uuid)) {
405 CERROR("%s: uuid must be < %d bytes long\n",
406 name, (int)sizeof(obd->obd_uuid));
410 obd = class_newdev(typename, name, uuid);
411 if (IS_ERR(obd)) { /* Already exists or out of obds */
413 CERROR("Cannot create device %s of type %s : %d\n",
417 LASSERTF(obd->obd_magic == OBD_DEVICE_MAGIC,
418 "obd %p obd_magic %08X != %08X\n",
419 obd, obd->obd_magic, OBD_DEVICE_MAGIC);
420 LASSERTF(strncmp(obd->obd_name, name, strlen(name)) == 0,
421 "%p obd_name %s != %s\n", obd, obd->obd_name, name);
423 exp = class_new_export_self(obd, &obd->obd_uuid);
430 obd->obd_self_export = exp;
431 list_del_init(&exp->exp_obd_chain_timed);
432 class_export_put(exp);
434 rc = class_register_device(obd);
436 class_decref(obd, "newdev", obd);
440 obd->obd_attached = 1;
441 CDEBUG(D_IOCTL, "OBD: dev %d attached type %s with refcount %d\n",
442 obd->obd_minor, typename, atomic_read(&obd->obd_refcount));
446 EXPORT_SYMBOL(class_attach);
449 * Create hashes, self-export, and call type-specific setup.
450 * Setup is effectively the "start this obd" call.
452 int class_setup(struct obd_device *obd, struct lustre_cfg *lcfg)
458 LASSERT(obd != NULL);
459 LASSERTF(obd == class_num2obd(obd->obd_minor),
460 "obd %p != obd_devs[%d] %p\n",
461 obd, obd->obd_minor, class_num2obd(obd->obd_minor));
462 LASSERTF(obd->obd_magic == OBD_DEVICE_MAGIC,
463 "obd %p obd_magic %08x != %08x\n",
464 obd, obd->obd_magic, OBD_DEVICE_MAGIC);
466 /* have we attached a type to this device? */
467 if (!obd->obd_attached) {
468 CERROR("Device %d not attached\n", obd->obd_minor);
472 if (obd->obd_set_up) {
473 CERROR("Device %d already setup (type %s)\n",
474 obd->obd_minor, obd->obd_type->typ_name);
478 /* is someone else setting us up right now? (attach inits spinlock) */
479 spin_lock(&obd->obd_dev_lock);
480 if (obd->obd_starting) {
481 spin_unlock(&obd->obd_dev_lock);
482 CERROR("Device %d setup in progress (type %s)\n",
483 obd->obd_minor, obd->obd_type->typ_name);
487 * just leave this on forever. I can't use obd_set_up here because
488 * other fns check that status, and we're not actually set up yet.
490 obd->obd_starting = 1;
491 obd->obd_uuid_hash = NULL;
492 obd->obd_nid_hash = NULL;
493 obd->obd_nid_stats_hash = NULL;
494 obd->obd_gen_hash = NULL;
495 spin_unlock(&obd->obd_dev_lock);
497 /* create an uuid-export lustre hash */
498 obd->obd_uuid_hash = cfs_hash_create("UUID_HASH",
501 HASH_UUID_BKT_BITS, 0,
504 &uuid_hash_ops, CFS_HASH_DEFAULT);
505 if (!obd->obd_uuid_hash)
506 GOTO(err_exit, err = -ENOMEM);
508 /* create a nid-export lustre hash */
509 obd->obd_nid_hash = cfs_hash_create("NID_HASH",
512 HASH_NID_BKT_BITS, 0,
515 &nid_hash_ops, CFS_HASH_DEFAULT);
516 if (!obd->obd_nid_hash)
517 GOTO(err_exit, err = -ENOMEM);
519 /* create a nid-stats lustre hash */
520 obd->obd_nid_stats_hash = cfs_hash_create("NID_STATS",
521 HASH_NID_STATS_CUR_BITS,
522 HASH_NID_STATS_MAX_BITS,
523 HASH_NID_STATS_BKT_BITS, 0,
528 if (!obd->obd_nid_stats_hash)
529 GOTO(err_exit, err = -ENOMEM);
531 /* create a client_generation-export lustre hash */
532 obd->obd_gen_hash = cfs_hash_create("UUID_HASH",
535 HASH_GEN_BKT_BITS, 0,
538 &gen_hash_ops, CFS_HASH_DEFAULT);
539 if (!obd->obd_gen_hash)
540 GOTO(err_exit, err = -ENOMEM);
542 err = obd_setup(obd, lcfg);
548 spin_lock(&obd->obd_dev_lock);
549 /* cleanup drops this */
550 class_incref(obd, "setup", obd);
551 spin_unlock(&obd->obd_dev_lock);
553 CDEBUG(D_IOCTL, "finished setup of obd %s (uuid %s)\n",
554 obd->obd_name, obd->obd_uuid.uuid);
558 if (obd->obd_uuid_hash) {
559 cfs_hash_putref(obd->obd_uuid_hash);
560 obd->obd_uuid_hash = NULL;
562 if (obd->obd_nid_hash) {
563 cfs_hash_putref(obd->obd_nid_hash);
564 obd->obd_nid_hash = NULL;
566 if (obd->obd_nid_stats_hash) {
567 cfs_hash_putref(obd->obd_nid_stats_hash);
568 obd->obd_nid_stats_hash = NULL;
570 if (obd->obd_gen_hash) {
571 cfs_hash_putref(obd->obd_gen_hash);
572 obd->obd_gen_hash = NULL;
574 obd->obd_starting = 0;
575 CERROR("setup %s failed (%d)\n", obd->obd_name, err);
578 EXPORT_SYMBOL(class_setup);
581 * We have finished using this OBD and are ready to destroy it.
582 * There can be no more references to this obd.
584 int class_detach(struct obd_device *obd, struct lustre_cfg *lcfg)
588 if (obd->obd_set_up) {
589 CERROR("OBD device %d still set up\n", obd->obd_minor);
593 spin_lock(&obd->obd_dev_lock);
594 if (!obd->obd_attached) {
595 spin_unlock(&obd->obd_dev_lock);
596 CERROR("OBD device %d not attached\n", obd->obd_minor);
599 obd->obd_attached = 0;
600 spin_unlock(&obd->obd_dev_lock);
602 /* cleanup in progress. we don't like to find this device after now */
603 class_unregister_device(obd);
605 CDEBUG(D_IOCTL, "detach on obd %s (uuid %s)\n",
606 obd->obd_name, obd->obd_uuid.uuid);
608 class_decref(obd, "newdev", obd);
612 EXPORT_SYMBOL(class_detach);
615 * Start shutting down the OBD. There may be in-progess ops when
616 * this is called. We tell them to start shutting down with a call
617 * to class_disconnect_exports().
619 int class_cleanup(struct obd_device *obd, struct lustre_cfg *lcfg)
625 OBD_RACE(OBD_FAIL_LDLM_RECOV_CLIENTS);
627 if (!obd->obd_set_up) {
628 CERROR("Device %d not setup\n", obd->obd_minor);
632 spin_lock(&obd->obd_dev_lock);
633 if (obd->obd_stopping) {
634 spin_unlock(&obd->obd_dev_lock);
635 CERROR("OBD %d already stopping\n", obd->obd_minor);
638 /* Leave this on forever */
639 obd->obd_stopping = 1;
641 * function can't return error after that point, so clear setup flag
642 * as early as possible to avoid finding via obd_devs / hash
645 spin_unlock(&obd->obd_dev_lock);
647 /* wait for already-arrived-connections to finish. */
648 while (obd->obd_conn_inprogress > 0)
652 if (lcfg->lcfg_bufcount >= 2 && LUSTRE_CFG_BUFLEN(lcfg, 1) > 0) {
653 for (flag = lustre_cfg_string(lcfg, 1); *flag != 0; flag++)
659 LCONSOLE_WARN("Failing over %s\n",
662 obd->obd_no_transno = 1;
663 obd->obd_no_recov = 1;
664 if (OBP(obd, iocontrol)) {
665 obd_iocontrol(OBD_IOC_SYNC,
666 obd->obd_self_export,
671 CERROR("Unrecognised flag '%c'\n", *flag);
675 LASSERT(obd->obd_self_export);
677 CDEBUG(D_IOCTL, "%s: forcing exports to disconnect: %d/%d\n",
678 obd->obd_name, obd->obd_num_exports,
679 atomic_read(&obd->obd_refcount) - 2);
680 dump_exports(obd, 0, D_HA);
681 class_disconnect_exports(obd);
683 /* Precleanup, we must make sure all exports get destroyed. */
684 err = obd_precleanup(obd);
686 CERROR("Precleanup %s returned %d\n",
689 /* destroy an uuid-export hash body */
690 if (obd->obd_uuid_hash) {
691 cfs_hash_putref(obd->obd_uuid_hash);
692 obd->obd_uuid_hash = NULL;
695 /* destroy a nid-export hash body */
696 if (obd->obd_nid_hash) {
697 cfs_hash_putref(obd->obd_nid_hash);
698 obd->obd_nid_hash = NULL;
701 /* destroy a nid-stats hash body */
702 if (obd->obd_nid_stats_hash) {
703 cfs_hash_putref(obd->obd_nid_stats_hash);
704 obd->obd_nid_stats_hash = NULL;
707 /* destroy a client_generation-export hash body */
708 if (obd->obd_gen_hash) {
709 cfs_hash_putref(obd->obd_gen_hash);
710 obd->obd_gen_hash = NULL;
713 class_decref(obd, "setup", obd);
719 struct obd_device *class_incref(struct obd_device *obd,
723 lu_ref_add_atomic(&obd->obd_reference, scope, source);
724 atomic_inc(&obd->obd_refcount);
725 CDEBUG(D_INFO, "incref %s (%p) now %d\n", obd->obd_name, obd,
726 atomic_read(&obd->obd_refcount));
730 EXPORT_SYMBOL(class_incref);
732 void class_decref(struct obd_device *obd, const char *scope, const void *source)
736 CDEBUG(D_INFO, "Decref %s (%p) now %d - %s\n", obd->obd_name, obd,
737 atomic_read(&obd->obd_refcount), scope);
739 LASSERT(obd->obd_num_exports >= 0);
740 last = atomic_dec_and_test(&obd->obd_refcount);
741 lu_ref_del(&obd->obd_reference, scope, source);
744 struct obd_export *exp;
746 LASSERT(!obd->obd_attached);
748 * All exports have been destroyed; there should
749 * be no more in-progress ops by this point.
751 exp = obd->obd_self_export;
754 exp->exp_flags |= exp_flags_from_obd(obd);
755 class_unlink_export(exp);
759 EXPORT_SYMBOL(class_decref);
762 * Add a failover NID location.
763 * Client OBD types contact server OBD types using this NID list.
765 int class_add_conn(struct obd_device *obd, struct lustre_cfg *lcfg)
767 struct obd_import *imp;
768 struct obd_uuid uuid;
773 if (LUSTRE_CFG_BUFLEN(lcfg, 1) < 1 ||
774 LUSTRE_CFG_BUFLEN(lcfg, 1) > sizeof(struct obd_uuid)) {
775 CERROR("invalid conn_uuid\n");
778 if (strcmp(obd->obd_type->typ_name, LUSTRE_MDC_NAME) &&
779 strcmp(obd->obd_type->typ_name, LUSTRE_OSC_NAME) &&
780 strcmp(obd->obd_type->typ_name, LUSTRE_OSP_NAME) &&
781 strcmp(obd->obd_type->typ_name, LUSTRE_LWP_NAME) &&
782 strcmp(obd->obd_type->typ_name, LUSTRE_MGC_NAME)) {
783 CERROR("can't add connection on non-client dev\n");
787 imp = obd->u.cli.cl_import;
789 CERROR("try to add conn on immature client dev\n");
793 obd_str2uuid(&uuid, lustre_cfg_string(lcfg, 1));
794 rc = obd_add_conn(imp, &uuid, lcfg->lcfg_num);
799 /** Remove a failover NID location. */
800 static int class_del_conn(struct obd_device *obd, struct lustre_cfg *lcfg)
802 struct obd_import *imp;
803 struct obd_uuid uuid;
808 if (LUSTRE_CFG_BUFLEN(lcfg, 1) < 1 ||
809 LUSTRE_CFG_BUFLEN(lcfg, 1) > sizeof(struct obd_uuid)) {
810 CERROR("invalid conn_uuid\n");
813 if (strcmp(obd->obd_type->typ_name, LUSTRE_MDC_NAME) &&
814 strcmp(obd->obd_type->typ_name, LUSTRE_OSC_NAME)) {
815 CERROR("can't del connection on non-client dev\n");
819 imp = obd->u.cli.cl_import;
821 CERROR("try to del conn on immature client dev\n");
825 obd_str2uuid(&uuid, lustre_cfg_string(lcfg, 1));
826 rc = obd_del_conn(imp, &uuid);
831 static LIST_HEAD(lustre_profile_list);
832 static DEFINE_SPINLOCK(lustre_profile_list_lock);
834 struct lustre_profile *class_get_profile(const char *prof)
836 struct lustre_profile *lprof;
839 spin_lock(&lustre_profile_list_lock);
840 list_for_each_entry(lprof, &lustre_profile_list, lp_list) {
841 if (!strcmp(lprof->lp_profile, prof)) {
843 spin_unlock(&lustre_profile_list_lock);
847 spin_unlock(&lustre_profile_list_lock);
850 EXPORT_SYMBOL(class_get_profile);
853 * Create a named "profile".
854 * This defines the MDC and OSC names to use for a client.
855 * This also is used to define the LOV to be used by a MDT.
857 static int class_add_profile(int proflen, char *prof, int osclen, char *osc,
858 int mdclen, char *mdc)
860 struct lustre_profile *lprof;
865 CDEBUG(D_CONFIG, "Add profile %s\n", prof);
867 OBD_ALLOC(lprof, sizeof(*lprof));
870 INIT_LIST_HEAD(&lprof->lp_list);
872 LASSERT(proflen == (strlen(prof) + 1));
873 OBD_ALLOC(lprof->lp_profile, proflen);
874 if (!lprof->lp_profile)
875 GOTO(out, err = -ENOMEM);
876 memcpy(lprof->lp_profile, prof, proflen);
878 LASSERT(osclen == (strlen(osc) + 1));
879 OBD_ALLOC(lprof->lp_dt, osclen);
881 GOTO(out, err = -ENOMEM);
882 memcpy(lprof->lp_dt, osc, osclen);
885 LASSERT(mdclen == (strlen(mdc) + 1));
886 OBD_ALLOC(lprof->lp_md, mdclen);
888 GOTO(out, err = -ENOMEM);
889 memcpy(lprof->lp_md, mdc, mdclen);
892 spin_lock(&lustre_profile_list_lock);
894 lprof->lp_list_deleted = false;
896 list_add(&lprof->lp_list, &lustre_profile_list);
897 spin_unlock(&lustre_profile_list_lock);
902 OBD_FREE(lprof->lp_md, mdclen);
904 OBD_FREE(lprof->lp_dt, osclen);
905 if (lprof->lp_profile)
906 OBD_FREE(lprof->lp_profile, proflen);
907 OBD_FREE(lprof, sizeof(*lprof));
911 void class_del_profile(const char *prof)
913 struct lustre_profile *lprof;
917 CDEBUG(D_CONFIG, "Del profile %s\n", prof);
919 lprof = class_get_profile(prof);
921 spin_lock(&lustre_profile_list_lock);
922 /* because get profile increments the ref counter */
924 list_del(&lprof->lp_list);
925 lprof->lp_list_deleted = true;
926 spin_unlock(&lustre_profile_list_lock);
928 class_put_profile(lprof);
932 EXPORT_SYMBOL(class_del_profile);
934 void class_put_profile(struct lustre_profile *lprof)
936 spin_lock(&lustre_profile_list_lock);
937 if ((--lprof->lp_refs) > 0) {
938 LASSERT(lprof->lp_refs > 0);
939 spin_unlock(&lustre_profile_list_lock);
942 spin_unlock(&lustre_profile_list_lock);
944 /* confirm not a negative number */
945 LASSERT(lprof->lp_refs == 0);
948 * At least one class_del_profile/profiles must be called
949 * on the target profile or lustre_profile_list will corrupt
951 LASSERT(lprof->lp_list_deleted);
952 OBD_FREE(lprof->lp_profile, strlen(lprof->lp_profile) + 1);
953 OBD_FREE(lprof->lp_dt, strlen(lprof->lp_dt) + 1);
955 OBD_FREE(lprof->lp_md, strlen(lprof->lp_md) + 1);
956 OBD_FREE(lprof, sizeof(*lprof));
958 EXPORT_SYMBOL(class_put_profile);
961 void class_del_profiles(void)
963 struct lustre_profile *lprof, *n;
966 spin_lock(&lustre_profile_list_lock);
967 list_for_each_entry_safe(lprof, n, &lustre_profile_list, lp_list) {
968 list_del(&lprof->lp_list);
969 lprof->lp_list_deleted = true;
970 spin_unlock(&lustre_profile_list_lock);
972 class_put_profile(lprof);
974 spin_lock(&lustre_profile_list_lock);
976 spin_unlock(&lustre_profile_list_lock);
979 EXPORT_SYMBOL(class_del_profiles);
982 * We can't call lquota_process_config directly because
983 * it lives in a module that must be loaded after this one.
985 #ifdef HAVE_SERVER_SUPPORT
986 static int (*quota_process_config)(struct lustre_cfg *lcfg) = NULL;
987 #endif /* HAVE_SERVER_SUPPORT */
990 * Rename the proc parameter in \a cfg with a new name \a new_name.
992 * \param cfg config structure which contains the proc parameter
993 * \param new_name new name of the proc parameter
995 * \retval valid-pointer pointer to the newly-allocated config structure
996 * which contains the renamed proc parameter
997 * \retval ERR_PTR(-EINVAL) if \a cfg or \a new_name is NULL, or \a cfg does
998 * not contain a proc parameter
999 * \retval ERR_PTR(-ENOMEM) if memory allocation failure occurs
1001 struct lustre_cfg *lustre_cfg_rename(struct lustre_cfg *cfg,
1002 const char *new_name)
1004 struct lustre_cfg_bufs *bufs = NULL;
1005 struct lustre_cfg *new_cfg = NULL;
1007 char *new_param = NULL;
1014 if (!cfg || !new_name)
1015 GOTO(out_nocfg, new_cfg = ERR_PTR(-EINVAL));
1017 param = lustre_cfg_string(cfg, 1);
1019 GOTO(out_nocfg, new_cfg = ERR_PTR(-EINVAL));
1021 value = strchr(param, '=');
1023 name_len = value - param;
1025 name_len = strlen(param);
1027 new_len = LUSTRE_CFG_BUFLEN(cfg, 1) + strlen(new_name) - name_len;
1029 OBD_ALLOC(new_param, new_len);
1031 GOTO(out_nocfg, new_cfg = ERR_PTR(-ENOMEM));
1033 strlcpy(new_param, new_name, new_len);
1035 strcat(new_param, value);
1037 OBD_ALLOC_PTR(bufs);
1039 GOTO(out_free_param, new_cfg = ERR_PTR(-ENOMEM));
1041 lustre_cfg_bufs_reset(bufs, NULL);
1042 lustre_cfg_bufs_init(bufs, cfg);
1043 lustre_cfg_bufs_set_string(bufs, 1, new_param);
1045 OBD_ALLOC(new_cfg, lustre_cfg_len(bufs->lcfg_bufcount,
1046 bufs->lcfg_buflen));
1048 GOTO(out_free_buf, new_cfg = ERR_PTR(-ENOMEM));
1050 lustre_cfg_init(new_cfg, cfg->lcfg_command, bufs);
1052 new_cfg->lcfg_num = cfg->lcfg_num;
1053 new_cfg->lcfg_flags = cfg->lcfg_flags;
1054 new_cfg->lcfg_nid = cfg->lcfg_nid;
1055 new_cfg->lcfg_nal = cfg->lcfg_nal;
1059 OBD_FREE(new_param, new_len);
1063 EXPORT_SYMBOL(lustre_cfg_rename);
1065 static ssize_t process_param2_config(struct lustre_cfg *lcfg)
1067 char *param = lustre_cfg_string(lcfg, 1);
1068 char *upcall = lustre_cfg_string(lcfg, 2);
1069 struct kobject *kobj = NULL;
1070 const char *subsys = param;
1072 [0] = "/usr/sbin/lctl",
1083 print_lustre_cfg(lcfg);
1085 len = strcspn(param, ".=");
1089 /* If we find '=' then its the top level sysfs directory */
1090 if (param[len] == '=')
1091 return class_set_global(param);
1093 subsys = kstrndup(param, len, GFP_KERNEL);
1097 kobj = kset_find_obj(lustre_kset, subsys);
1100 char *value = param;
1104 param = strsep(&value, "=");
1105 envp[0] = kasprintf(GFP_KERNEL, "PARAM=%s", param);
1106 envp[1] = kasprintf(GFP_KERNEL, "SETTING=%s", value);
1107 envp[2] = kasprintf(GFP_KERNEL, "TIME=%lld",
1108 ktime_get_real_seconds());
1111 rc = kobject_uevent_env(kobj, KOBJ_CHANGE, envp);
1112 for (i = 0; i < ARRAY_SIZE(envp); i++)
1120 /* Add upcall processing here. Now only lctl is supported */
1121 if (strcmp(upcall, LCTL_UPCALL) != 0) {
1122 CERROR("Unsupported upcall %s\n", upcall);
1126 start = ktime_get();
1127 rc = call_usermodehelper(argv[0], argv, NULL, UMH_WAIT_PROC);
1131 CERROR("lctl: error invoking upcall %s %s %s: rc = %d; "
1132 "time %ldus\n", argv[0], argv[1], argv[2], rc,
1133 (long)ktime_us_delta(end, start));
1135 CDEBUG(D_HA, "lctl: invoked upcall %s %s %s, time %ldus\n",
1136 argv[0], argv[1], argv[2],
1137 (long)ktime_us_delta(end, start));
1144 #ifdef HAVE_SERVER_SUPPORT
1145 void lustre_register_quota_process_config(int (*qpc)(struct lustre_cfg *lcfg))
1147 quota_process_config = qpc;
1149 EXPORT_SYMBOL(lustre_register_quota_process_config);
1150 #endif /* HAVE_SERVER_SUPPORT */
1153 * Process configuration commands given in lustre_cfg form.
1154 * These may come from direct calls (e.g. class_manual_cleanup)
1155 * or processing the config llog, or ioctl from lctl.
1157 int class_process_config(struct lustre_cfg *lcfg)
1159 struct obd_device *obd;
1162 LASSERT(lcfg && !IS_ERR(lcfg));
1163 CDEBUG(D_IOCTL, "processing cmd: %x\n", lcfg->lcfg_command);
1165 /* Commands that don't need a device */
1166 switch (lcfg->lcfg_command) {
1168 err = class_attach(lcfg);
1171 case LCFG_ADD_UUID: {
1173 "adding mapping from uuid %s to nid %#llx (%s)\n",
1174 lustre_cfg_string(lcfg, 1), lcfg->lcfg_nid,
1175 libcfs_nid2str(lcfg->lcfg_nid));
1177 err = class_add_uuid(lustre_cfg_string(lcfg, 1),
1181 case LCFG_DEL_UUID: {
1182 CDEBUG(D_IOCTL, "removing mappings for uuid %s\n",
1183 (lcfg->lcfg_bufcount < 2 || LUSTRE_CFG_BUFLEN(lcfg, 1) ==
1184 0) ? "<all uuids>" : lustre_cfg_string(lcfg, 1));
1186 err = class_del_uuid(lustre_cfg_string(lcfg, 1));
1189 case LCFG_MOUNTOPT: {
1190 CDEBUG(D_IOCTL, "mountopt: profile %s osc %s mdc %s\n",
1191 lustre_cfg_string(lcfg, 1),
1192 lustre_cfg_string(lcfg, 2),
1193 lustre_cfg_string(lcfg, 3));
1195 * set these mount options somewhere, so ll_fill_super
1198 err = class_add_profile(LUSTRE_CFG_BUFLEN(lcfg, 1),
1199 lustre_cfg_string(lcfg, 1),
1200 LUSTRE_CFG_BUFLEN(lcfg, 2),
1201 lustre_cfg_string(lcfg, 2),
1202 LUSTRE_CFG_BUFLEN(lcfg, 3),
1203 lustre_cfg_string(lcfg, 3));
1206 case LCFG_DEL_MOUNTOPT: {
1207 CDEBUG(D_IOCTL, "mountopt: profile %s\n",
1208 lustre_cfg_string(lcfg, 1));
1209 class_del_profile(lustre_cfg_string(lcfg, 1));
1212 case LCFG_SET_TIMEOUT: {
1213 CDEBUG(D_IOCTL, "changing lustre timeout from %d to %d\n",
1214 obd_timeout, lcfg->lcfg_num);
1215 obd_timeout = max(lcfg->lcfg_num, 1U);
1216 obd_timeout_set = 1;
1219 case LCFG_SET_LDLM_TIMEOUT: {
1220 CDEBUG(D_IOCTL, "changing lustre ldlm_timeout from %d to %d\n",
1221 ldlm_timeout, lcfg->lcfg_num);
1222 ldlm_timeout = max(lcfg->lcfg_num, 1U);
1223 if (ldlm_timeout >= obd_timeout)
1224 ldlm_timeout = max(obd_timeout / 3, 1U);
1225 ldlm_timeout_set = 1;
1228 case LCFG_SET_UPCALL: {
1229 LCONSOLE_ERROR_MSG(0x15a, "recovery upcall is deprecated\n");
1230 /* COMPAT_146 Don't fail on old configs */
1234 struct cfg_marker *marker;
1236 marker = lustre_cfg_buf(lcfg, 1);
1237 CDEBUG(D_IOCTL, "marker %d (%#x) %.16s %s\n", marker->cm_step,
1238 marker->cm_flags, marker->cm_tgtname,
1239 marker->cm_comment);
1245 /* llite has no OBD */
1246 if (class_match_param(lustre_cfg_string(lcfg, 1),
1247 PARAM_LLITE, NULL) == 0) {
1248 struct lustre_sb_info *lsi;
1253 * The instance name contains the sb:
1254 * lustre-client-aacfe000
1256 tmp = strrchr(lustre_cfg_string(lcfg, 0), '-');
1257 if (!tmp || !*(++tmp))
1258 GOTO(out, err = -EINVAL);
1260 if (sscanf(tmp, "%lx", &addr) != 1)
1261 GOTO(out, err = -EINVAL);
1263 lsi = s2lsi((struct super_block *)addr);
1264 /* This better be a real Lustre superblock! */
1265 LASSERT(lsi->lsi_lmd->lmd_magic == LMD_MAGIC);
1267 count = class_modify_config(lcfg, PARAM_LLITE,
1269 err = count < 0 ? count : 0;
1271 } else if ((class_match_param(lustre_cfg_string(lcfg, 1),
1272 PARAM_SYS, &tmp) == 0)) {
1273 /* Global param settings */
1274 err = class_set_global(tmp);
1276 * Client or server should not fail to mount if
1277 * it hits an unknown configuration parameter.
1280 CWARN("Ignoring unknown param %s\n", tmp);
1283 #ifdef HAVE_SERVER_SUPPORT
1284 } else if ((class_match_param(lustre_cfg_string(lcfg, 1),
1285 PARAM_QUOTA, &tmp) == 0) &&
1286 quota_process_config) {
1287 err = (*quota_process_config)(lcfg);
1289 #endif /* HAVE_SERVER_SUPPORT */
1294 case LCFG_SET_PARAM: {
1295 err = process_param2_config(lcfg);
1299 /* Commands that require a device */
1300 obd = class_name2obd(lustre_cfg_string(lcfg, 0));
1302 if (!LUSTRE_CFG_BUFLEN(lcfg, 0))
1303 CERROR("this lcfg command requires a device name\n");
1305 CERROR("no device for: %s\n",
1306 lustre_cfg_string(lcfg, 0));
1308 GOTO(out, err = -EINVAL);
1310 switch(lcfg->lcfg_command) {
1312 err = class_setup(obd, lcfg);
1316 err = class_detach(obd, lcfg);
1319 case LCFG_CLEANUP: {
1320 err = class_cleanup(obd, lcfg);
1323 case LCFG_ADD_CONN: {
1324 err = class_add_conn(obd, lcfg);
1327 case LCFG_DEL_CONN: {
1328 err = class_del_conn(obd, lcfg);
1331 case LCFG_POOL_NEW: {
1332 err = obd_pool_new(obd, lustre_cfg_string(lcfg, 2));
1335 case LCFG_POOL_ADD: {
1336 err = obd_pool_add(obd, lustre_cfg_string(lcfg, 2),
1337 lustre_cfg_string(lcfg, 3));
1340 case LCFG_POOL_REM: {
1341 err = obd_pool_rem(obd, lustre_cfg_string(lcfg, 2),
1342 lustre_cfg_string(lcfg, 3));
1345 case LCFG_POOL_DEL: {
1346 err = obd_pool_del(obd, lustre_cfg_string(lcfg, 2));
1350 * Process config log ADD_MDC record twice to add MDC also to LOV
1353 * add 0:lustre-clilmv 1:lustre-MDT0000_UUID 2:0 3:1
1354 * 4:lustre-MDT0000-mdc_UUID
1356 case LCFG_ADD_MDC: {
1357 struct obd_device *lov_obd;
1360 err = obd_process_config(obd, sizeof(*lcfg), lcfg);
1364 /* make sure this is client LMV log entry */
1365 clilmv = strstr(lustre_cfg_string(lcfg, 0), "clilmv");
1370 * replace 'lmv' with 'lov' name to address LOV device and
1371 * process llog record to add MDC there.
1374 lov_obd = class_name2obd(lustre_cfg_string(lcfg, 0));
1376 err = obd_process_config(lov_obd, sizeof(*lcfg), lcfg);
1379 CERROR("%s: Cannot find LOV by %s name, rc = %d\n",
1380 obd->obd_name, lustre_cfg_string(lcfg, 0), err);
1382 /* restore 'lmv' name */
1387 err = obd_process_config(obd, sizeof(*lcfg), lcfg);
1393 if ((err < 0) && !(lcfg->lcfg_command & LCFG_REQUIRED)) {
1394 CWARN("Ignoring error %d on optional command %#x\n", err,
1395 lcfg->lcfg_command);
1400 EXPORT_SYMBOL(class_process_config);
1402 ssize_t class_modify_config(struct lustre_cfg *lcfg, const char *prefix,
1403 struct kobject *kobj)
1405 struct kobj_type *typ;
1409 if (lcfg->lcfg_command != LCFG_PARAM) {
1410 CERROR("Unknown command: %d\n", lcfg->lcfg_command);
1414 typ = get_ktype(kobj);
1415 if (!typ || !typ->default_attrs)
1418 print_lustre_cfg(lcfg);
1421 * e.g. tunefs.lustre --param mdt.group_upcall=foo /r/tmp/lustre-mdt
1422 * or lctl conf_param lustre-MDT0000.mdt.group_upcall=bar
1423 * or lctl conf_param lustre-OST0000.osc.max_dirty_mb=36
1425 for (i = 1; i < lcfg->lcfg_bufcount; i++) {
1426 struct attribute *attr;
1432 key = lustre_cfg_buf(lcfg, i);
1433 /* Strip off prefix */
1434 if (class_match_param(key, prefix, &key))
1436 * If the prefix doesn't match, return error so we
1437 * can pass it down the stack
1441 value = strchr(key, '=');
1442 if (!value || *(value + 1) == 0) {
1443 CERROR("%s: can't parse param '%s' (missing '=')\n",
1444 lustre_cfg_string(lcfg, 0),
1445 lustre_cfg_string(lcfg, i));
1446 /* continue parsing other params */
1449 keylen = value - key;
1453 for (j = 0; typ->default_attrs[j]; j++) {
1454 if (!strncmp(typ->default_attrs[j]->name, key,
1456 attr = typ->default_attrs[j];
1462 char *envp[4], *param, *path;
1464 path = kobject_get_path(kobj, GFP_KERNEL);
1468 /* convert sysfs path to uevent format */
1470 while ((param = strchr(param, '/')) != NULL)
1473 param = strstr(path, "fs.lustre.") + 10;
1475 envp[0] = kasprintf(GFP_KERNEL, "PARAM=%s.%.*s",
1476 param, (int) keylen, key);
1477 envp[1] = kasprintf(GFP_KERNEL, "SETTING=%s", value);
1478 envp[2] = kasprintf(GFP_KERNEL, "TIME=%lld",
1479 ktime_get_real_seconds());
1482 if (kobject_uevent_env(kobj, KOBJ_CHANGE, envp)) {
1483 CERROR("%s: failed to send uevent %s\n",
1484 kobject_name(kobj), key);
1487 for (i = 0; i < ARRAY_SIZE(envp); i++)
1491 count += lustre_attr_store(kobj, attr, value,
1497 EXPORT_SYMBOL(class_modify_config);
1499 int class_process_proc_param(char *prefix, struct lprocfs_vars *lvars,
1500 struct lustre_cfg *lcfg, void *data)
1502 struct lprocfs_vars *var;
1503 struct file fakefile;
1504 struct seq_file fake_seqfile;
1506 int i, keylen, vallen;
1507 int matched = 0, j = 0;
1513 if (lcfg->lcfg_command != LCFG_PARAM) {
1514 CERROR("Unknown command: %d\n", lcfg->lcfg_command);
1518 /* fake a seq file so that var->fops->write can work... */
1519 fakefile.private_data = &fake_seqfile;
1520 fake_seqfile.private = data;
1522 * e.g. tunefs.lustre --param mdt.group_upcall=foo /r/tmp/lustre-mdt
1523 * or lctl conf_param lustre-MDT0000.mdt.group_upcall=bar
1524 * or lctl conf_param lustre-OST0000.osc.max_dirty_mb=36
1526 for (i = 1; i < lcfg->lcfg_bufcount; i++) {
1527 key = lustre_cfg_buf(lcfg, i);
1528 /* Strip off prefix */
1529 if (class_match_param(key, prefix, &key))
1531 * If the prefix doesn't match, return error so we
1532 * can pass it down the stack
1535 sval = strchr(key, '=');
1536 if (!sval || *(sval + 1) == 0) {
1537 CERROR("%s: can't parse param '%s' (missing '=')\n",
1538 lustre_cfg_string(lcfg, 0),
1539 lustre_cfg_string(lcfg, i));
1540 /* rc = -EINVAL; continue parsing other params */
1543 keylen = sval - key;
1545 vallen = strlen(sval);
1548 /* Search proc entries */
1549 while (lvars[j].name) {
1551 if (class_match_param(key, var->name, NULL) == 0 &&
1552 keylen == strlen(var->name)) {
1556 if (var->fops && var->fops->write) {
1560 rc = (var->fops->write)(&fakefile, sval,
1570 * It was upgraded from old MDT/OST device,
1571 * ignore the obsolete "sec_level" parameter.
1573 if (strncmp("sec_level", key, keylen) == 0)
1576 CERROR("%s: unknown config parameter '%s'\n",
1577 lustre_cfg_string(lcfg, 0),
1578 lustre_cfg_string(lcfg, i));
1579 /* rc = -EINVAL; continue parsing other params */
1581 } else if (rc < 0) {
1582 CERROR("%s: error writing parameter '%s': rc = %d\n",
1583 lustre_cfg_string(lcfg, 0), key, rc);
1586 CDEBUG(D_CONFIG, "%s: set parameter '%s'\n",
1587 lustre_cfg_string(lcfg, 0), key);
1597 EXPORT_SYMBOL(class_process_proc_param);
1600 * Supplemental functions for config logs, it allocates lustre_cfg
1601 * buffers plus initialized llog record header at the beginning.
1603 struct llog_cfg_rec *lustre_cfg_rec_new(int cmd, struct lustre_cfg_bufs *bufs)
1605 struct llog_cfg_rec *lcr;
1610 reclen = lustre_cfg_len(bufs->lcfg_bufcount, bufs->lcfg_buflen);
1611 reclen = llog_data_len(reclen) + sizeof(struct llog_rec_hdr) +
1612 sizeof(struct llog_rec_tail);
1614 OBD_ALLOC(lcr, reclen);
1618 lustre_cfg_init(&lcr->lcr_cfg, cmd, bufs);
1620 lcr->lcr_hdr.lrh_len = reclen;
1621 lcr->lcr_hdr.lrh_type = OBD_CFG_REC;
1625 EXPORT_SYMBOL(lustre_cfg_rec_new);
1627 void lustre_cfg_rec_free(struct llog_cfg_rec *lcr)
1630 OBD_FREE(lcr, lcr->lcr_hdr.lrh_len);
1633 EXPORT_SYMBOL(lustre_cfg_rec_free);
1636 * Parse a configuration llog, doing various manipulations on them
1637 * for various reasons, (modifications for compatibility, skip obsolete
1638 * records, change uuids, etc), then class_process_config() resulting
1641 int class_config_llog_handler(const struct lu_env *env,
1642 struct llog_handle *handle,
1643 struct llog_rec_hdr *rec, void *data)
1645 struct config_llog_instance *cfg = data;
1646 int cfg_len = rec->lrh_len;
1647 char *cfg_buf = (char *) (rec + 1);
1651 /* class_config_dump_handler(handle, rec, data); */
1653 switch (rec->lrh_type) {
1655 struct lustre_cfg *lcfg, *lcfg_new;
1656 struct lustre_cfg_bufs bufs;
1657 char *inst_name = NULL;
1661 lcfg = (struct lustre_cfg *)cfg_buf;
1662 if (lcfg->lcfg_version == __swab32(LUSTRE_CFG_VERSION)) {
1663 lustre_swab_lustre_cfg(lcfg);
1667 rc = lustre_cfg_sanity_check(cfg_buf, cfg_len);
1671 /* Figure out config state info */
1672 if (lcfg->lcfg_command == LCFG_MARKER) {
1673 struct cfg_marker *marker = lustre_cfg_buf(lcfg, 1);
1674 lustre_swab_cfg_marker(marker, swab,
1675 LUSTRE_CFG_BUFLEN(lcfg, 1));
1676 CDEBUG(D_CONFIG, "Marker, inst_flg=%#x mark_flg=%#x\n",
1677 cfg->cfg_flags, marker->cm_flags);
1678 if (marker->cm_flags & CM_START) {
1679 /* all previous flags off */
1680 cfg->cfg_flags = CFG_F_MARKER;
1681 server_name2index(marker->cm_tgtname,
1682 &cfg->cfg_lwp_idx, NULL);
1683 if (marker->cm_flags & CM_SKIP) {
1684 cfg->cfg_flags |= CFG_F_SKIP;
1685 CDEBUG(D_CONFIG, "SKIP #%d\n",
1687 } else if ((marker->cm_flags & CM_EXCLUDE) ||
1689 lustre_check_exclusion(cfg->cfg_sb,
1690 marker->cm_tgtname))) {
1691 cfg->cfg_flags |= CFG_F_EXCLUDE;
1692 CDEBUG(D_CONFIG, "EXCLUDE %d\n",
1695 } else if (marker->cm_flags & CM_END) {
1700 * A config command without a start marker before it is
1703 if (!(cfg->cfg_flags & CFG_F_MARKER) &&
1704 (lcfg->lcfg_command != LCFG_MARKER)) {
1705 CWARN("Skip config outside markers, (inst: %016lx, uuid: %s, flags: %#x)\n",
1707 cfg->cfg_uuid.uuid, cfg->cfg_flags);
1708 cfg->cfg_flags |= CFG_F_SKIP;
1710 if (cfg->cfg_flags & CFG_F_SKIP) {
1711 CDEBUG(D_CONFIG, "skipping %#x\n",
1714 /* No processing! */
1719 * For interoperability between 1.8 and 2.0,
1720 * rename "mds" OBD device type to "mdt".
1723 char *typename = lustre_cfg_string(lcfg, 1);
1724 char *index = lustre_cfg_string(lcfg, 2);
1726 if ((lcfg->lcfg_command == LCFG_ATTACH && typename &&
1727 strcmp(typename, "mds") == 0)) {
1728 CWARN("For 1.8 interoperability, rename obd "
1729 "type from mds to mdt\n");
1732 if ((lcfg->lcfg_command == LCFG_SETUP && index &&
1733 strcmp(index, "type") == 0)) {
1734 CDEBUG(D_INFO, "For 1.8 interoperability, "
1735 "set this index to '0'\n");
1741 #ifdef HAVE_SERVER_SUPPORT
1742 /* newer MDS replaces LOV/OSC with LOD/OSP */
1744 char *typename = lustre_cfg_string(lcfg, 1);
1746 if ((lcfg->lcfg_command == LCFG_ATTACH && typename &&
1747 strcmp(typename, LUSTRE_LOV_NAME) == 0) &&
1748 cfg->cfg_sb && IS_MDT(s2lsi(cfg->cfg_sb))) {
1750 "For 2.x interoperability, rename obd "
1751 "type from lov to lod (%s)\n",
1752 s2lsi(cfg->cfg_sb)->lsi_svname);
1753 strcpy(typename, LUSTRE_LOD_NAME);
1755 if ((lcfg->lcfg_command == LCFG_ATTACH && typename &&
1756 strcmp(typename, LUSTRE_OSC_NAME) == 0) &&
1757 cfg->cfg_sb && IS_MDT(s2lsi(cfg->cfg_sb))) {
1759 "For 2.x interoperability, rename obd "
1760 "type from osc to osp (%s)\n",
1761 s2lsi(cfg->cfg_sb)->lsi_svname);
1762 strcpy(typename, LUSTRE_OSP_NAME);
1765 #endif /* HAVE_SERVER_SUPPORT */
1767 if (cfg->cfg_flags & CFG_F_EXCLUDE) {
1768 CDEBUG(D_CONFIG, "cmd: %x marked EXCLUDED\n",
1769 lcfg->lcfg_command);
1770 if (lcfg->lcfg_command == LCFG_LOV_ADD_OBD)
1771 /* Add inactive instead */
1772 lcfg->lcfg_command = LCFG_LOV_ADD_INA;
1775 lustre_cfg_bufs_reset(&bufs, NULL);
1776 lustre_cfg_bufs_init(&bufs, lcfg);
1778 if (cfg->cfg_instance &&
1779 lcfg->lcfg_command != LCFG_SPTLRPC_CONF &&
1780 LUSTRE_CFG_BUFLEN(lcfg, 0) > 0) {
1781 inst_len = LUSTRE_CFG_BUFLEN(lcfg, 0) + 16 + 4;
1782 OBD_ALLOC(inst_name, inst_len);
1784 GOTO(out, rc = -ENOMEM);
1785 snprintf(inst_name, inst_len, "%s-%016lx",
1786 lustre_cfg_string(lcfg, 0),
1788 lustre_cfg_bufs_set_string(&bufs, 0, inst_name);
1789 CDEBUG(D_CONFIG, "cmd %x, instance name: %s\n",
1790 lcfg->lcfg_command, inst_name);
1793 /* override llog UUID for clients, to insure they are unique */
1794 if (cfg->cfg_instance && lcfg->lcfg_command == LCFG_ATTACH)
1795 lustre_cfg_bufs_set_string(&bufs, 2,
1796 cfg->cfg_uuid.uuid);
1798 * sptlrpc config record, we expect 2 data segments:
1799 * [0]: fs_name/target_name,
1801 * moving them to index [1] and [2], and insert MGC's
1802 * obdname at index [0].
1804 if (cfg->cfg_instance &&
1805 lcfg->lcfg_command == LCFG_SPTLRPC_CONF) {
1806 /* After ASLR changes cfg_instance this needs fixing */
1807 /* "obd" is set in config_log_find_or_add() */
1808 struct obd_device *obd = (void *)cfg->cfg_instance;
1810 lustre_cfg_bufs_set(&bufs, 2, bufs.lcfg_buf[1],
1811 bufs.lcfg_buflen[1]);
1812 lustre_cfg_bufs_set(&bufs, 1, bufs.lcfg_buf[0],
1813 bufs.lcfg_buflen[0]);
1814 lustre_cfg_bufs_set_string(&bufs, 0,
1819 * Add net info to setup command
1820 * if given on command line.
1821 * So config log will be:
1825 * [3]: inactive-on-startup
1826 * [4]: restrictive net
1828 if (cfg && cfg->cfg_sb && s2lsi(cfg->cfg_sb) &&
1829 !IS_SERVER(s2lsi(cfg->cfg_sb))) {
1830 struct lustre_sb_info *lsi = s2lsi(cfg->cfg_sb);
1831 char *nidnet = lsi->lsi_lmd->lmd_nidnet;
1833 if (lcfg->lcfg_command == LCFG_SETUP &&
1834 lcfg->lcfg_bufcount != 2 && nidnet) {
1835 CDEBUG(D_CONFIG, "Adding net %s info to setup "
1836 "command for client %s\n", nidnet,
1837 lustre_cfg_string(lcfg, 0));
1838 lustre_cfg_bufs_set_string(&bufs, 4, nidnet);
1843 * Skip add_conn command if uuid is
1844 * not on restricted net
1846 if (cfg && cfg->cfg_sb && s2lsi(cfg->cfg_sb) &&
1847 !IS_SERVER(s2lsi(cfg->cfg_sb))) {
1848 struct lustre_sb_info *lsi = s2lsi(cfg->cfg_sb);
1849 char *uuid_str = lustre_cfg_string(lcfg, 1);
1851 if (lcfg->lcfg_command == LCFG_ADD_CONN &&
1852 lsi->lsi_lmd->lmd_nidnet &&
1853 LNET_NIDNET(libcfs_str2nid(uuid_str)) !=
1854 libcfs_str2net(lsi->lsi_lmd->lmd_nidnet)) {
1855 CDEBUG(D_CONFIG, "skipping add_conn for %s\n",
1858 /* No processing! */
1863 OBD_ALLOC(lcfg_new, lustre_cfg_len(bufs.lcfg_bufcount,
1866 GOTO(out, rc = -ENOMEM);
1868 lustre_cfg_init(lcfg_new, lcfg->lcfg_command, &bufs);
1869 lcfg_new->lcfg_num = lcfg->lcfg_num;
1870 lcfg_new->lcfg_flags = lcfg->lcfg_flags;
1873 * XXX Hack to try to remain binary compatible with
1874 * pre-newconfig logs
1876 if (lcfg->lcfg_nal != 0 && /* pre-newconfig log? */
1877 (lcfg->lcfg_nid >> 32) == 0) {
1878 __u32 addr = (__u32)(lcfg->lcfg_nid & 0xffffffff);
1880 lcfg_new->lcfg_nid =
1881 LNET_MKNID(LNET_MKNET(lcfg->lcfg_nal, 0), addr);
1882 CWARN("Converted pre-newconfig NAL %d NID %x to %s\n",
1883 lcfg->lcfg_nal, addr,
1884 libcfs_nid2str(lcfg_new->lcfg_nid));
1886 lcfg_new->lcfg_nid = lcfg->lcfg_nid;
1889 lcfg_new->lcfg_nal = 0; /* illegal value for obsolete field */
1891 rc = class_process_config(lcfg_new);
1892 OBD_FREE(lcfg_new, lustre_cfg_len(lcfg_new->lcfg_bufcount,
1893 lcfg_new->lcfg_buflens));
1895 OBD_FREE(inst_name, inst_len);
1899 CERROR("Unknown llog record type %#x encountered\n",
1905 CERROR("%s: cfg command failed: rc = %d\n",
1906 handle->lgh_ctxt->loc_obd->obd_name, rc);
1907 class_config_dump_handler(NULL, handle, rec, data);
1911 EXPORT_SYMBOL(class_config_llog_handler);
1913 int class_config_parse_llog(const struct lu_env *env, struct llog_ctxt *ctxt,
1914 char *name, struct config_llog_instance *cfg)
1916 struct llog_process_cat_data cd = {
1917 .lpcd_first_idx = 0,
1919 struct llog_handle *llh;
1924 CDEBUG(D_INFO, "looking up llog %s\n", name);
1925 rc = llog_open(env, ctxt, &llh, NULL, name, LLOG_OPEN_EXISTS);
1929 rc = llog_init_handle(env, llh, LLOG_F_IS_PLAIN, NULL);
1931 GOTO(parse_out, rc);
1933 /* continue processing from where we last stopped to end-of-log */
1935 cd.lpcd_first_idx = cfg->cfg_last_idx;
1936 callback = cfg->cfg_callback;
1937 LASSERT(callback != NULL);
1939 callback = class_config_llog_handler;
1942 cd.lpcd_last_idx = 0;
1944 rc = llog_process(env, llh, callback, cfg, &cd);
1946 CDEBUG(D_CONFIG, "Processed log %s gen %d-%d (rc=%d)\n", name,
1947 cd.lpcd_first_idx + 1, cd.lpcd_last_idx, rc);
1949 cfg->cfg_last_idx = cd.lpcd_last_idx;
1952 llog_close(env, llh);
1955 EXPORT_SYMBOL(class_config_parse_llog);
1957 static struct lcfg_type_data {
1961 } lcfg_data_table[] = {
1962 { LCFG_ATTACH, "attach", { "type", "UUID", "3", "4" } },
1963 { LCFG_DETACH, "detach", { "1", "2", "3", "4" } },
1964 { LCFG_SETUP, "setup", { "UUID", "node", "options", "failout" } },
1965 { LCFG_CLEANUP, "cleanup", { "1", "2", "3", "4" } },
1966 { LCFG_ADD_UUID, "add_uuid", { "node", "2", "3", "4" } },
1967 { LCFG_DEL_UUID, "del_uuid", { "1", "2", "3", "4" } },
1968 { LCFG_MOUNTOPT, "new_profile", { "name", "lov", "lmv", "4" } },
1969 { LCFG_DEL_MOUNTOPT, "del_mountopt", { "1", "2", "3", "4" } , },
1970 { LCFG_SET_TIMEOUT, "set_timeout", { "parameter", "2", "3", "4" } },
1971 { LCFG_SET_UPCALL, "set_upcall", { "1", "2", "3", "4" } },
1972 { LCFG_ADD_CONN, "add_conn", { "node", "2", "3", "4" } },
1973 { LCFG_DEL_CONN, "del_conn", { "1", "2", "3", "4" } },
1974 { LCFG_LOV_ADD_OBD, "add_osc", { "ost", "index", "gen", "UUID" } },
1975 { LCFG_LOV_DEL_OBD, "del_osc", { "1", "2", "3", "4" } },
1976 { LCFG_PARAM, "conf_param", { "parameter", "value", "3", "4" } },
1977 { LCFG_MARKER, "marker", { "1", "2", "3", "4" } },
1978 { LCFG_LOG_START, "log_start", { "1", "2", "3", "4" } },
1979 { LCFG_LOG_END, "log_end", { "1", "2", "3", "4" } },
1980 { LCFG_LOV_ADD_INA, "add_osc_inactive", { "1", "2", "3", "4" } },
1981 { LCFG_ADD_MDC, "add_mdc", { "mdt", "index", "gen", "UUID" } },
1982 { LCFG_DEL_MDC, "del_mdc", { "1", "2", "3", "4" } },
1983 { LCFG_SPTLRPC_CONF, "security", { "parameter", "2", "3", "4" } },
1984 { LCFG_POOL_NEW, "new_pool", { "fsname", "pool", "3", "4" } },
1985 { LCFG_POOL_ADD, "add_pool", { "fsname", "pool", "ost", "4" } },
1986 { LCFG_POOL_REM, "remove_pool", { "fsname", "pool", "ost", "4" } },
1987 { LCFG_POOL_DEL, "del_pool", { "fsname", "pool", "3", "4" } },
1988 { LCFG_SET_LDLM_TIMEOUT, "set_ldlm_timeout",
1989 { "parameter", "2", "3", "4" } },
1990 { LCFG_SET_PARAM, "set_param", { "parameter", "value", "3", "4" } },
1991 { 0, NULL, { NULL, NULL, NULL, NULL } }
1994 static struct lcfg_type_data *lcfg_cmd2data(__u32 cmd)
1998 while (lcfg_data_table[i].ltd_type != 0) {
1999 if (lcfg_data_table[i].ltd_type == cmd)
2000 return &lcfg_data_table[i];
2007 * Parse config record and output dump in supplied buffer.
2009 * This is separated from class_config_dump_handler() to use
2010 * for ioctl needs as well
2013 * - { index: 4, event: attach, device: lustrewt-clilov, type: lov,
2014 * UUID: lustrewt-clilov_UUID }
2016 int class_config_yaml_output(struct llog_rec_hdr *rec, char *buf, int size)
2018 struct lustre_cfg *lcfg = (struct lustre_cfg *)(rec + 1);
2020 char *end = buf + size;
2022 struct lcfg_type_data *ldata;
2024 LASSERT(rec->lrh_type == OBD_CFG_REC);
2025 rc = lustre_cfg_sanity_check(lcfg, rec->lrh_len);
2029 ldata = lcfg_cmd2data(lcfg->lcfg_command);
2033 if (lcfg->lcfg_command == LCFG_MARKER)
2036 /* form YAML entity */
2037 ptr += snprintf(ptr, end - ptr, "- { index: %u, event: %s",
2038 rec->lrh_index, ldata->ltd_name);
2042 if (lcfg->lcfg_flags) {
2043 ptr += snprintf(ptr, end - ptr, ", flags: %#08x",
2048 if (lcfg->lcfg_num) {
2049 ptr += snprintf(ptr, end - ptr, ", num: %#08x",
2054 if (lcfg->lcfg_nid) {
2055 char nidstr[LNET_NIDSTR_SIZE];
2057 libcfs_nid2str_r(lcfg->lcfg_nid, nidstr, sizeof(nidstr));
2058 ptr += snprintf(ptr, end - ptr, ", nid: %s(%#llx)",
2059 nidstr, lcfg->lcfg_nid);
2064 if (LUSTRE_CFG_BUFLEN(lcfg, 0) > 0) {
2065 ptr += snprintf(ptr, end - ptr, ", device: %s",
2066 lustre_cfg_string(lcfg, 0));
2071 if (lcfg->lcfg_command == LCFG_SET_PARAM) {
2073 * set_param -P parameters have param=val here, separate
2074 * them through pointer magic and print them out in
2077 char *cfg_str = lustre_cfg_string(lcfg, 1);
2078 char *tmp = strchr(cfg_str, '=');
2084 ptr += snprintf(ptr, end - ptr, ", %s: ", ldata->ltd_bufs[0]);
2085 len = tmp - cfg_str + 1;
2086 snprintf(ptr, len, "%s", cfg_str);
2089 ptr += snprintf(ptr, end - ptr, ", %s: ", ldata->ltd_bufs[1]);
2090 ptr += snprintf(ptr, end - ptr, "%s", tmp + 1);
2095 for (i = 1; i < lcfg->lcfg_bufcount; i++) {
2096 if (LUSTRE_CFG_BUFLEN(lcfg, i) > 0) {
2097 ptr += snprintf(ptr, end - ptr, ", %s: %s",
2098 ldata->ltd_bufs[i - 1],
2099 lustre_cfg_string(lcfg, i));
2106 ptr += snprintf(ptr, end - ptr, " }\n");
2108 /* Return consumed bytes. If the buffer overflowed, zero last byte */
2119 * parse config record and output dump in supplied buffer.
2120 * This is separated from class_config_dump_handler() to use
2121 * for ioctl needs as well
2123 static int class_config_parse_rec(struct llog_rec_hdr *rec, char *buf, int size)
2125 struct lustre_cfg *lcfg = (struct lustre_cfg *)(rec + 1);
2127 char *end = buf + size;
2132 LASSERT(rec->lrh_type == OBD_CFG_REC);
2133 rc = lustre_cfg_sanity_check(lcfg, rec->lrh_len);
2137 ptr += snprintf(ptr, end-ptr, "cmd=%05x ", lcfg->lcfg_command);
2138 if (lcfg->lcfg_flags)
2139 ptr += snprintf(ptr, end-ptr, "flags=%#08x ",
2143 ptr += snprintf(ptr, end-ptr, "num=%#08x ", lcfg->lcfg_num);
2145 if (lcfg->lcfg_nid) {
2146 char nidstr[LNET_NIDSTR_SIZE];
2148 libcfs_nid2str_r(lcfg->lcfg_nid, nidstr, sizeof(nidstr));
2149 ptr += snprintf(ptr, end-ptr, "nid=%s(%#llx) ",
2150 nidstr, lcfg->lcfg_nid);
2153 if (lcfg->lcfg_command == LCFG_MARKER) {
2154 struct cfg_marker *marker = lustre_cfg_buf(lcfg, 1);
2156 ptr += snprintf(ptr, end-ptr, "marker=%d(%#x)%s '%s'",
2157 marker->cm_step, marker->cm_flags,
2158 marker->cm_tgtname, marker->cm_comment);
2162 for (i = 0; i < lcfg->lcfg_bufcount; i++) {
2163 ptr += snprintf(ptr, end-ptr, "%d:%s ", i,
2164 lustre_cfg_string(lcfg, i));
2167 ptr += snprintf(ptr, end - ptr, "\n");
2168 /* return consumed bytes */
2173 int class_config_dump_handler(const struct lu_env *env,
2174 struct llog_handle *handle,
2175 struct llog_rec_hdr *rec, void *data)
2182 OBD_ALLOC(outstr, 256);
2186 if (rec->lrh_type == OBD_CFG_REC) {
2187 class_config_parse_rec(rec, outstr, 256);
2188 LCONSOLE(D_WARNING, " %s\n", outstr);
2190 LCONSOLE(D_WARNING, "unhandled lrh_type: %#x\n", rec->lrh_type);
2194 OBD_FREE(outstr, 256);
2199 * Call class_cleanup and class_detach.
2200 * "Manual" only in the sense that we're faking lcfg commands.
2202 int class_manual_cleanup(struct obd_device *obd)
2205 struct lustre_cfg *lcfg;
2206 struct lustre_cfg_bufs bufs;
2212 CERROR("empty cleanup\n");
2217 strlcat(flags, "F", sizeof(flags));
2219 strlcat(flags, "A", sizeof(flags));
2221 CDEBUG(D_CONFIG, "Manual cleanup of %s (flags='%s')\n",
2222 obd->obd_name, flags);
2224 lustre_cfg_bufs_reset(&bufs, obd->obd_name);
2225 lustre_cfg_bufs_set_string(&bufs, 1, flags);
2226 OBD_ALLOC(lcfg, lustre_cfg_len(bufs.lcfg_bufcount, bufs.lcfg_buflen));
2229 lustre_cfg_init(lcfg, LCFG_CLEANUP, &bufs);
2231 rc = class_process_config(lcfg);
2233 CERROR("cleanup failed %d: %s\n", rc, obd->obd_name);
2237 /* the lcfg is almost the same for both ops */
2238 lcfg->lcfg_command = LCFG_DETACH;
2239 rc = class_process_config(lcfg);
2241 CERROR("detach failed %d: %s\n", rc, obd->obd_name);
2243 OBD_FREE(lcfg, lustre_cfg_len(lcfg->lcfg_bufcount, lcfg->lcfg_buflens));
2246 EXPORT_SYMBOL(class_manual_cleanup);
2249 * uuid<->export lustre hash operations
2253 uuid_hash(struct cfs_hash *hs, const void *key, unsigned mask)
2255 return cfs_hash_djb2_hash(((struct obd_uuid *)key)->uuid,
2256 sizeof(((struct obd_uuid *)key)->uuid), mask);
2260 uuid_key(struct hlist_node *hnode)
2262 struct obd_export *exp;
2264 exp = hlist_entry(hnode, struct obd_export, exp_uuid_hash);
2266 return &exp->exp_client_uuid;
2270 * NOTE: It is impossible to find an export that is in failed
2271 * state with this function
2274 uuid_keycmp(const void *key, struct hlist_node *hnode)
2276 struct obd_export *exp;
2279 exp = hlist_entry(hnode, struct obd_export, exp_uuid_hash);
2281 return obd_uuid_equals(key, &exp->exp_client_uuid) &&
2286 uuid_export_object(struct hlist_node *hnode)
2288 return hlist_entry(hnode, struct obd_export, exp_uuid_hash);
2292 uuid_export_get(struct cfs_hash *hs, struct hlist_node *hnode)
2294 struct obd_export *exp;
2296 exp = hlist_entry(hnode, struct obd_export, exp_uuid_hash);
2297 class_export_get(exp);
2301 uuid_export_put_locked(struct cfs_hash *hs, struct hlist_node *hnode)
2303 struct obd_export *exp;
2305 exp = hlist_entry(hnode, struct obd_export, exp_uuid_hash);
2306 class_export_put(exp);
2309 static struct cfs_hash_ops uuid_hash_ops = {
2310 .hs_hash = uuid_hash,
2312 .hs_keycmp = uuid_keycmp,
2313 .hs_object = uuid_export_object,
2314 .hs_get = uuid_export_get,
2315 .hs_put_locked = uuid_export_put_locked,
2320 * nid<->export hash operations
2324 nid_hash(struct cfs_hash *hs, const void *key, unsigned mask)
2326 return cfs_hash_djb2_hash(key, sizeof(lnet_nid_t), mask);
2330 nid_key(struct hlist_node *hnode)
2332 struct obd_export *exp;
2334 exp = hlist_entry(hnode, struct obd_export, exp_nid_hash);
2336 RETURN(&exp->exp_connection->c_peer.nid);
2340 * NOTE: It is impossible to find an export that is in failed
2341 * state with this function
2344 nid_kepcmp(const void *key, struct hlist_node *hnode)
2346 struct obd_export *exp;
2349 exp = hlist_entry(hnode, struct obd_export, exp_nid_hash);
2351 RETURN(exp->exp_connection->c_peer.nid == *(lnet_nid_t *)key &&
2356 nid_export_object(struct hlist_node *hnode)
2358 return hlist_entry(hnode, struct obd_export, exp_nid_hash);
2362 nid_export_get(struct cfs_hash *hs, struct hlist_node *hnode)
2364 struct obd_export *exp;
2366 exp = hlist_entry(hnode, struct obd_export, exp_nid_hash);
2367 class_export_get(exp);
2371 nid_export_put_locked(struct cfs_hash *hs, struct hlist_node *hnode)
2373 struct obd_export *exp;
2375 exp = hlist_entry(hnode, struct obd_export, exp_nid_hash);
2376 class_export_put(exp);
2379 static struct cfs_hash_ops nid_hash_ops = {
2380 .hs_hash = nid_hash,
2382 .hs_keycmp = nid_kepcmp,
2383 .hs_object = nid_export_object,
2384 .hs_get = nid_export_get,
2385 .hs_put_locked = nid_export_put_locked,
2390 * nid<->nidstats hash operations
2394 nidstats_key(struct hlist_node *hnode)
2396 struct nid_stat *ns;
2398 ns = hlist_entry(hnode, struct nid_stat, nid_hash);
2404 nidstats_keycmp(const void *key, struct hlist_node *hnode)
2406 return *(lnet_nid_t *)nidstats_key(hnode) == *(lnet_nid_t *)key;
2410 nidstats_object(struct hlist_node *hnode)
2412 return hlist_entry(hnode, struct nid_stat, nid_hash);
2416 nidstats_get(struct cfs_hash *hs, struct hlist_node *hnode)
2418 struct nid_stat *ns;
2420 ns = hlist_entry(hnode, struct nid_stat, nid_hash);
2425 nidstats_put_locked(struct cfs_hash *hs, struct hlist_node *hnode)
2427 struct nid_stat *ns;
2429 ns = hlist_entry(hnode, struct nid_stat, nid_hash);
2433 static struct cfs_hash_ops nid_stat_hash_ops = {
2434 .hs_hash = nid_hash,
2435 .hs_key = nidstats_key,
2436 .hs_keycmp = nidstats_keycmp,
2437 .hs_object = nidstats_object,
2438 .hs_get = nidstats_get,
2439 .hs_put_locked = nidstats_put_locked,
2444 * client_generation<->export hash operations
2448 gen_hash(struct cfs_hash *hs, const void *key, unsigned mask)
2450 return cfs_hash_djb2_hash(key, sizeof(__u32), mask);
2454 gen_key(struct hlist_node *hnode)
2456 struct obd_export *exp;
2458 exp = hlist_entry(hnode, struct obd_export, exp_gen_hash);
2460 RETURN(&exp->exp_target_data.ted_lcd->lcd_generation);
2464 * NOTE: It is impossible to find an export that is in failed
2465 * state with this function
2468 gen_kepcmp(const void *key, struct hlist_node *hnode)
2470 struct obd_export *exp;
2473 exp = hlist_entry(hnode, struct obd_export, exp_gen_hash);
2475 RETURN(exp->exp_target_data.ted_lcd->lcd_generation == *(__u32 *)key &&
2480 gen_export_object(struct hlist_node *hnode)
2482 return hlist_entry(hnode, struct obd_export, exp_gen_hash);
2486 gen_export_get(struct cfs_hash *hs, struct hlist_node *hnode)
2488 struct obd_export *exp;
2490 exp = hlist_entry(hnode, struct obd_export, exp_gen_hash);
2491 class_export_get(exp);
2495 gen_export_put_locked(struct cfs_hash *hs, struct hlist_node *hnode)
2497 struct obd_export *exp;
2499 exp = hlist_entry(hnode, struct obd_export, exp_gen_hash);
2500 class_export_put(exp);
2503 static struct cfs_hash_ops gen_hash_ops = {
2504 .hs_hash = gen_hash,
2506 .hs_keycmp = gen_kepcmp,
2507 .hs_object = gen_export_object,
2508 .hs_get = gen_export_get,
2509 .hs_put_locked = gen_export_put_locked,