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/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_export *exp;
369 struct obd_device *obd = NULL;
370 char *typename, *name, *uuid;
374 if (!LUSTRE_CFG_BUFLEN(lcfg, 1)) {
375 CERROR("No type passed!\n");
378 typename = lustre_cfg_string(lcfg, 1);
380 if (!LUSTRE_CFG_BUFLEN(lcfg, 0)) {
381 CERROR("No name passed!\n");
384 name = lustre_cfg_string(lcfg, 0);
385 if (!LUSTRE_CFG_BUFLEN(lcfg, 2)) {
386 CERROR("No UUID passed!\n");
390 uuid = lustre_cfg_string(lcfg, 2);
392 if (len >= sizeof(obd->obd_uuid)) {
393 CERROR("%s: uuid must be < %d bytes long\n",
394 name, (int)sizeof(obd->obd_uuid));
398 obd = class_newdev(typename, name, uuid);
399 if (IS_ERR(obd)) { /* Already exists or out of obds */
401 CERROR("Cannot create device %s of type %s : %d\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 exp = class_new_export_self(obd, &obd->obd_uuid);
418 obd->obd_self_export = exp;
419 list_del_init(&exp->exp_obd_chain_timed);
420 class_export_put(exp);
422 rc = class_register_device(obd);
424 class_decref(obd, "newdev", obd);
428 obd->obd_attached = 1;
429 CDEBUG(D_IOCTL, "OBD: dev %d attached type %s with refcount %d\n",
430 obd->obd_minor, typename, atomic_read(&obd->obd_refcount));
434 EXPORT_SYMBOL(class_attach);
436 /** Create hashes, self-export, and call type-specific setup.
437 * Setup is effectively the "start this obd" call.
439 int class_setup(struct obd_device *obd, struct lustre_cfg *lcfg)
444 LASSERT(obd != NULL);
445 LASSERTF(obd == class_num2obd(obd->obd_minor),
446 "obd %p != obd_devs[%d] %p\n",
447 obd, obd->obd_minor, class_num2obd(obd->obd_minor));
448 LASSERTF(obd->obd_magic == OBD_DEVICE_MAGIC,
449 "obd %p obd_magic %08x != %08x\n",
450 obd, obd->obd_magic, OBD_DEVICE_MAGIC);
452 /* have we attached a type to this device? */
453 if (!obd->obd_attached) {
454 CERROR("Device %d not attached\n", obd->obd_minor);
458 if (obd->obd_set_up) {
459 CERROR("Device %d already setup (type %s)\n",
460 obd->obd_minor, obd->obd_type->typ_name);
464 /* is someone else setting us up right now? (attach inits spinlock) */
465 spin_lock(&obd->obd_dev_lock);
466 if (obd->obd_starting) {
467 spin_unlock(&obd->obd_dev_lock);
468 CERROR("Device %d setup in progress (type %s)\n",
469 obd->obd_minor, obd->obd_type->typ_name);
472 /* just leave this on forever. I can't use obd_set_up here because
473 other fns check that status, and we're not actually set up yet. */
474 obd->obd_starting = 1;
475 obd->obd_uuid_hash = NULL;
476 obd->obd_nid_hash = NULL;
477 obd->obd_nid_stats_hash = NULL;
478 obd->obd_gen_hash = NULL;
479 spin_unlock(&obd->obd_dev_lock);
481 /* create an uuid-export lustre hash */
482 obd->obd_uuid_hash = cfs_hash_create("UUID_HASH",
485 HASH_UUID_BKT_BITS, 0,
488 &uuid_hash_ops, CFS_HASH_DEFAULT);
489 if (!obd->obd_uuid_hash)
490 GOTO(err_exit, err = -ENOMEM);
492 /* create a nid-export lustre hash */
493 obd->obd_nid_hash = cfs_hash_create("NID_HASH",
496 HASH_NID_BKT_BITS, 0,
499 &nid_hash_ops, CFS_HASH_DEFAULT);
500 if (!obd->obd_nid_hash)
501 GOTO(err_exit, err = -ENOMEM);
503 /* create a nid-stats lustre hash */
504 obd->obd_nid_stats_hash = cfs_hash_create("NID_STATS",
505 HASH_NID_STATS_CUR_BITS,
506 HASH_NID_STATS_MAX_BITS,
507 HASH_NID_STATS_BKT_BITS, 0,
510 &nid_stat_hash_ops, CFS_HASH_DEFAULT);
511 if (!obd->obd_nid_stats_hash)
512 GOTO(err_exit, err = -ENOMEM);
514 /* create a client_generation-export lustre hash */
515 obd->obd_gen_hash = cfs_hash_create("UUID_HASH",
518 HASH_GEN_BKT_BITS, 0,
521 &gen_hash_ops, CFS_HASH_DEFAULT);
522 if (!obd->obd_gen_hash)
523 GOTO(err_exit, err = -ENOMEM);
525 err = obd_setup(obd, lcfg);
531 spin_lock(&obd->obd_dev_lock);
532 /* cleanup drops this */
533 class_incref(obd, "setup", obd);
534 spin_unlock(&obd->obd_dev_lock);
536 CDEBUG(D_IOCTL, "finished setup of obd %s (uuid %s)\n",
537 obd->obd_name, obd->obd_uuid.uuid);
541 if (obd->obd_uuid_hash) {
542 cfs_hash_putref(obd->obd_uuid_hash);
543 obd->obd_uuid_hash = NULL;
545 if (obd->obd_nid_hash) {
546 cfs_hash_putref(obd->obd_nid_hash);
547 obd->obd_nid_hash = NULL;
549 if (obd->obd_nid_stats_hash) {
550 cfs_hash_putref(obd->obd_nid_stats_hash);
551 obd->obd_nid_stats_hash = NULL;
553 if (obd->obd_gen_hash) {
554 cfs_hash_putref(obd->obd_gen_hash);
555 obd->obd_gen_hash = NULL;
557 obd->obd_starting = 0;
558 CERROR("setup %s failed (%d)\n", obd->obd_name, err);
561 EXPORT_SYMBOL(class_setup);
563 /** We have finished using this obd and are ready to destroy it.
564 * There can be no more references to this obd.
566 int class_detach(struct obd_device *obd, struct lustre_cfg *lcfg)
570 if (obd->obd_set_up) {
571 CERROR("OBD device %d still set up\n", obd->obd_minor);
575 spin_lock(&obd->obd_dev_lock);
576 if (!obd->obd_attached) {
577 spin_unlock(&obd->obd_dev_lock);
578 CERROR("OBD device %d not attached\n", obd->obd_minor);
581 obd->obd_attached = 0;
582 spin_unlock(&obd->obd_dev_lock);
584 /* cleanup in progress. we don't like to find this device after now */
585 class_unregister_device(obd);
587 CDEBUG(D_IOCTL, "detach on obd %s (uuid %s)\n",
588 obd->obd_name, obd->obd_uuid.uuid);
590 class_decref(obd, "newdev", obd);
594 EXPORT_SYMBOL(class_detach);
596 /** Start shutting down the obd. There may be in-progess ops when
597 * this is called. We tell them to start shutting down with a call
598 * to class_disconnect_exports().
600 int class_cleanup(struct obd_device *obd, struct lustre_cfg *lcfg)
606 OBD_RACE(OBD_FAIL_LDLM_RECOV_CLIENTS);
608 if (!obd->obd_set_up) {
609 CERROR("Device %d not setup\n", obd->obd_minor);
613 spin_lock(&obd->obd_dev_lock);
614 if (obd->obd_stopping) {
615 spin_unlock(&obd->obd_dev_lock);
616 CERROR("OBD %d already stopping\n", obd->obd_minor);
619 /* Leave this on forever */
620 obd->obd_stopping = 1;
621 /* function can't return error after that point, so clear setup flag
622 * as early as possible to avoid finding via obd_devs / hash */
624 spin_unlock(&obd->obd_dev_lock);
626 /* wait for already-arrived-connections to finish. */
627 while (obd->obd_conn_inprogress > 0)
631 if (lcfg->lcfg_bufcount >= 2 && LUSTRE_CFG_BUFLEN(lcfg, 1) > 0) {
632 for (flag = lustre_cfg_string(lcfg, 1); *flag != 0; flag++)
638 LCONSOLE_WARN("Failing over %s\n",
641 obd->obd_no_transno = 1;
642 obd->obd_no_recov = 1;
643 if (OBP(obd, iocontrol)) {
644 obd_iocontrol(OBD_IOC_SYNC,
645 obd->obd_self_export,
650 CERROR("Unrecognised flag '%c'\n", *flag);
654 LASSERT(obd->obd_self_export);
656 CDEBUG(D_IOCTL, "%s: forcing exports to disconnect: %d/%d\n",
657 obd->obd_name, obd->obd_num_exports,
658 atomic_read(&obd->obd_refcount) - 2);
659 dump_exports(obd, 0, D_HA);
660 class_disconnect_exports(obd);
662 /* Precleanup, we must make sure all exports get destroyed. */
663 err = obd_precleanup(obd);
665 CERROR("Precleanup %s returned %d\n",
668 /* destroy an uuid-export hash body */
669 if (obd->obd_uuid_hash) {
670 cfs_hash_putref(obd->obd_uuid_hash);
671 obd->obd_uuid_hash = NULL;
674 /* destroy a nid-export hash body */
675 if (obd->obd_nid_hash) {
676 cfs_hash_putref(obd->obd_nid_hash);
677 obd->obd_nid_hash = NULL;
680 /* destroy a nid-stats hash body */
681 if (obd->obd_nid_stats_hash) {
682 cfs_hash_putref(obd->obd_nid_stats_hash);
683 obd->obd_nid_stats_hash = NULL;
686 /* destroy a client_generation-export hash body */
687 if (obd->obd_gen_hash) {
688 cfs_hash_putref(obd->obd_gen_hash);
689 obd->obd_gen_hash = NULL;
692 class_decref(obd, "setup", obd);
698 struct obd_device *class_incref(struct obd_device *obd,
699 const char *scope, const void *source)
701 lu_ref_add_atomic(&obd->obd_reference, scope, source);
702 atomic_inc(&obd->obd_refcount);
703 CDEBUG(D_INFO, "incref %s (%p) now %d\n", obd->obd_name, obd,
704 atomic_read(&obd->obd_refcount));
708 EXPORT_SYMBOL(class_incref);
710 void class_decref(struct obd_device *obd, const char *scope, const void *source)
714 CDEBUG(D_INFO, "Decref %s (%p) now %d - %s\n", obd->obd_name, obd,
715 atomic_read(&obd->obd_refcount), scope);
717 LASSERT(obd->obd_num_exports >= 0);
718 last = atomic_dec_and_test(&obd->obd_refcount);
719 lu_ref_del(&obd->obd_reference, scope, source);
722 struct obd_export *exp;
724 LASSERT(!obd->obd_attached);
725 /* All exports have been destroyed; there should
726 * be no more in-progress ops by this point.*/
727 exp = obd->obd_self_export;
730 exp->exp_flags |= exp_flags_from_obd(obd);
731 class_unlink_export(exp);
735 EXPORT_SYMBOL(class_decref);
737 /** Add a failover nid location.
738 * Client obd types contact server obd types using this nid list.
740 int class_add_conn(struct obd_device *obd, struct lustre_cfg *lcfg)
742 struct obd_import *imp;
743 struct obd_uuid uuid;
747 if (LUSTRE_CFG_BUFLEN(lcfg, 1) < 1 ||
748 LUSTRE_CFG_BUFLEN(lcfg, 1) > sizeof(struct obd_uuid)) {
749 CERROR("invalid conn_uuid\n");
752 if (strcmp(obd->obd_type->typ_name, LUSTRE_MDC_NAME) &&
753 strcmp(obd->obd_type->typ_name, LUSTRE_OSC_NAME) &&
754 strcmp(obd->obd_type->typ_name, LUSTRE_OSP_NAME) &&
755 strcmp(obd->obd_type->typ_name, LUSTRE_LWP_NAME) &&
756 strcmp(obd->obd_type->typ_name, LUSTRE_MGC_NAME)) {
757 CERROR("can't add connection on non-client dev\n");
761 imp = obd->u.cli.cl_import;
763 CERROR("try to add conn on immature client dev\n");
767 obd_str2uuid(&uuid, lustre_cfg_string(lcfg, 1));
768 rc = obd_add_conn(imp, &uuid, lcfg->lcfg_num);
773 /** Remove a failover nid location.
775 static int class_del_conn(struct obd_device *obd, struct lustre_cfg *lcfg)
777 struct obd_import *imp;
778 struct obd_uuid uuid;
782 if (LUSTRE_CFG_BUFLEN(lcfg, 1) < 1 ||
783 LUSTRE_CFG_BUFLEN(lcfg, 1) > sizeof(struct obd_uuid)) {
784 CERROR("invalid conn_uuid\n");
787 if (strcmp(obd->obd_type->typ_name, LUSTRE_MDC_NAME) &&
788 strcmp(obd->obd_type->typ_name, LUSTRE_OSC_NAME)) {
789 CERROR("can't del connection on non-client dev\n");
793 imp = obd->u.cli.cl_import;
795 CERROR("try to del conn on immature client dev\n");
799 obd_str2uuid(&uuid, lustre_cfg_string(lcfg, 1));
800 rc = obd_del_conn(imp, &uuid);
805 static LIST_HEAD(lustre_profile_list);
806 static DEFINE_SPINLOCK(lustre_profile_list_lock);
808 struct lustre_profile *class_get_profile(const char * prof)
810 struct lustre_profile *lprof;
813 spin_lock(&lustre_profile_list_lock);
814 list_for_each_entry(lprof, &lustre_profile_list, lp_list) {
815 if (!strcmp(lprof->lp_profile, prof)) {
817 spin_unlock(&lustre_profile_list_lock);
821 spin_unlock(&lustre_profile_list_lock);
824 EXPORT_SYMBOL(class_get_profile);
826 /** Create a named "profile".
827 * This defines the mdc and osc names to use for a client.
828 * This also is used to define the lov to be used by a mdt.
830 static int class_add_profile(int proflen, char *prof, int osclen, char *osc,
831 int mdclen, char *mdc)
833 struct lustre_profile *lprof;
837 CDEBUG(D_CONFIG, "Add profile %s\n", prof);
839 OBD_ALLOC(lprof, sizeof(*lprof));
842 INIT_LIST_HEAD(&lprof->lp_list);
844 LASSERT(proflen == (strlen(prof) + 1));
845 OBD_ALLOC(lprof->lp_profile, proflen);
846 if (lprof->lp_profile == NULL)
847 GOTO(out, err = -ENOMEM);
848 memcpy(lprof->lp_profile, prof, proflen);
850 LASSERT(osclen == (strlen(osc) + 1));
851 OBD_ALLOC(lprof->lp_dt, osclen);
852 if (lprof->lp_dt == NULL)
853 GOTO(out, err = -ENOMEM);
854 memcpy(lprof->lp_dt, osc, osclen);
857 LASSERT(mdclen == (strlen(mdc) + 1));
858 OBD_ALLOC(lprof->lp_md, mdclen);
859 if (lprof->lp_md == NULL)
860 GOTO(out, err = -ENOMEM);
861 memcpy(lprof->lp_md, mdc, mdclen);
864 spin_lock(&lustre_profile_list_lock);
866 lprof->lp_list_deleted = false;
868 list_add(&lprof->lp_list, &lustre_profile_list);
869 spin_unlock(&lustre_profile_list_lock);
874 OBD_FREE(lprof->lp_md, mdclen);
876 OBD_FREE(lprof->lp_dt, osclen);
877 if (lprof->lp_profile)
878 OBD_FREE(lprof->lp_profile, proflen);
879 OBD_FREE(lprof, sizeof(*lprof));
883 void class_del_profile(const char *prof)
885 struct lustre_profile *lprof;
888 CDEBUG(D_CONFIG, "Del profile %s\n", prof);
890 lprof = class_get_profile(prof);
892 spin_lock(&lustre_profile_list_lock);
893 /* because get profile increments the ref counter */
895 list_del(&lprof->lp_list);
896 lprof->lp_list_deleted = true;
897 spin_unlock(&lustre_profile_list_lock);
899 class_put_profile(lprof);
903 EXPORT_SYMBOL(class_del_profile);
905 void class_put_profile(struct lustre_profile *lprof)
907 spin_lock(&lustre_profile_list_lock);
908 if ((--lprof->lp_refs) > 0) {
909 LASSERT(lprof->lp_refs > 0);
910 spin_unlock(&lustre_profile_list_lock);
913 spin_unlock(&lustre_profile_list_lock);
915 /* confirm not a negative number */
916 LASSERT(lprof->lp_refs == 0);
918 /* At least one class_del_profile/profiles must be called
919 * on the target profile or lustre_profile_list will corrupt */
920 LASSERT(lprof->lp_list_deleted);
921 OBD_FREE(lprof->lp_profile, strlen(lprof->lp_profile) + 1);
922 OBD_FREE(lprof->lp_dt, strlen(lprof->lp_dt) + 1);
923 if (lprof->lp_md != NULL)
924 OBD_FREE(lprof->lp_md, strlen(lprof->lp_md) + 1);
925 OBD_FREE(lprof, sizeof(*lprof));
927 EXPORT_SYMBOL(class_put_profile);
930 void class_del_profiles(void)
932 struct lustre_profile *lprof, *n;
935 spin_lock(&lustre_profile_list_lock);
936 list_for_each_entry_safe(lprof, n, &lustre_profile_list, lp_list) {
937 list_del(&lprof->lp_list);
938 lprof->lp_list_deleted = true;
939 spin_unlock(&lustre_profile_list_lock);
941 class_put_profile(lprof);
943 spin_lock(&lustre_profile_list_lock);
945 spin_unlock(&lustre_profile_list_lock);
948 EXPORT_SYMBOL(class_del_profiles);
950 static int class_set_global(char *ptr, int val, struct lustre_cfg *lcfg)
953 if (class_match_param(ptr, PARAM_AT_MIN, NULL) == 0)
955 else if (class_match_param(ptr, PARAM_AT_MAX, NULL) == 0)
957 else if (class_match_param(ptr, PARAM_AT_EXTRA, NULL) == 0)
959 else if (class_match_param(ptr, PARAM_AT_EARLY_MARGIN, NULL) == 0)
960 at_early_margin = val;
961 else if (class_match_param(ptr, PARAM_AT_HISTORY, NULL) == 0)
963 else if (class_match_param(ptr, PARAM_JOBID_VAR, NULL) == 0)
964 strlcpy(obd_jobid_var, lustre_cfg_string(lcfg, 2),
965 JOBSTATS_JOBID_VAR_MAX_LEN + 1);
969 CDEBUG(D_IOCTL, "global %s = %d\n", ptr, val);
974 /* We can't call ll_process_config or lquota_process_config directly because
975 * it lives in a module that must be loaded after this one. */
976 static int (*client_process_config)(struct lustre_cfg *lcfg) = NULL;
977 static int (*quota_process_config)(struct lustre_cfg *lcfg) = NULL;
979 void lustre_register_client_process_config(int (*cpc)(struct lustre_cfg *lcfg))
981 client_process_config = cpc;
983 EXPORT_SYMBOL(lustre_register_client_process_config);
986 * Rename the proc parameter in \a cfg with a new name \a new_name.
988 * \param cfg config structure which contains the proc parameter
989 * \param new_name new name of the proc parameter
991 * \retval valid-pointer pointer to the newly-allocated config structure
992 * which contains the renamed proc parameter
993 * \retval ERR_PTR(-EINVAL) if \a cfg or \a new_name is NULL, or \a cfg does
994 * not contain a proc parameter
995 * \retval ERR_PTR(-ENOMEM) if memory allocation failure occurs
997 struct lustre_cfg *lustre_cfg_rename(struct lustre_cfg *cfg,
998 const char *new_name)
1000 struct lustre_cfg_bufs *bufs = NULL;
1001 struct lustre_cfg *new_cfg = NULL;
1003 char *new_param = NULL;
1009 if (!cfg || !new_name)
1010 GOTO(out_nocfg, new_cfg = ERR_PTR(-EINVAL));
1012 param = lustre_cfg_string(cfg, 1);
1014 GOTO(out_nocfg, new_cfg = ERR_PTR(-EINVAL));
1016 value = strchr(param, '=');
1018 name_len = strlen(param);
1020 name_len = value - param;
1022 new_len = LUSTRE_CFG_BUFLEN(cfg, 1) + strlen(new_name) - name_len;
1024 OBD_ALLOC(new_param, new_len);
1026 GOTO(out_nocfg, new_cfg = ERR_PTR(-ENOMEM));
1028 strcpy(new_param, new_name);
1030 strcat(new_param, value);
1032 OBD_ALLOC_PTR(bufs);
1034 GOTO(out_free_param, new_cfg = ERR_PTR(-ENOMEM));
1036 lustre_cfg_bufs_reset(bufs, NULL);
1037 lustre_cfg_bufs_init(bufs, cfg);
1038 lustre_cfg_bufs_set_string(bufs, 1, new_param);
1040 OBD_ALLOC(new_cfg, lustre_cfg_len(bufs->lcfg_bufcount,
1041 bufs->lcfg_buflen));
1043 GOTO(out_free_buf, new_cfg = ERR_PTR(-ENOMEM));
1045 lustre_cfg_init(new_cfg, cfg->lcfg_command, bufs);
1047 new_cfg->lcfg_num = cfg->lcfg_num;
1048 new_cfg->lcfg_flags = cfg->lcfg_flags;
1049 new_cfg->lcfg_nid = cfg->lcfg_nid;
1050 new_cfg->lcfg_nal = cfg->lcfg_nal;
1054 OBD_FREE(new_param, new_len);
1058 EXPORT_SYMBOL(lustre_cfg_rename);
1060 static int process_param2_config(struct lustre_cfg *lcfg)
1062 char *param = lustre_cfg_string(lcfg, 1);
1063 char *upcall = lustre_cfg_string(lcfg, 2);
1065 [0] = "/usr/sbin/lctl",
1075 /* Add upcall processing here. Now only lctl is supported */
1076 if (strcmp(upcall, LCTL_UPCALL) != 0) {
1077 CERROR("Unsupported upcall %s\n", upcall);
1081 start = ktime_get();
1082 rc = call_usermodehelper(argv[0], argv, NULL, UMH_WAIT_PROC);
1086 CERROR("lctl: error invoking upcall %s %s %s: rc = %d; "
1087 "time %ldus\n", argv[0], argv[1], argv[2], rc,
1088 (long)ktime_us_delta(end, start));
1090 CDEBUG(D_HA, "lctl: invoked upcall %s %s %s, time %ldus\n",
1091 argv[0], argv[1], argv[2],
1092 (long)ktime_us_delta(end, start));
1099 void lustre_register_quota_process_config(int (*qpc)(struct lustre_cfg *lcfg))
1101 quota_process_config = qpc;
1103 EXPORT_SYMBOL(lustre_register_quota_process_config);
1105 /** Process configuration commands given in lustre_cfg form.
1106 * These may come from direct calls (e.g. class_manual_cleanup)
1107 * or processing the config llog, or ioctl from lctl.
1109 int class_process_config(struct lustre_cfg *lcfg)
1111 struct obd_device *obd;
1114 LASSERT(lcfg && !IS_ERR(lcfg));
1115 CDEBUG(D_IOCTL, "processing cmd: %x\n", lcfg->lcfg_command);
1117 /* Commands that don't need a device */
1118 switch(lcfg->lcfg_command) {
1120 err = class_attach(lcfg);
1123 case LCFG_ADD_UUID: {
1124 CDEBUG(D_IOCTL, "adding mapping from uuid %s to nid %#llx"
1125 " (%s)\n", lustre_cfg_string(lcfg, 1),
1126 lcfg->lcfg_nid, libcfs_nid2str(lcfg->lcfg_nid));
1128 err = class_add_uuid(lustre_cfg_string(lcfg, 1), lcfg->lcfg_nid);
1131 case LCFG_DEL_UUID: {
1132 CDEBUG(D_IOCTL, "removing mappings for uuid %s\n",
1133 (lcfg->lcfg_bufcount < 2 || LUSTRE_CFG_BUFLEN(lcfg, 1) == 0)
1134 ? "<all uuids>" : lustre_cfg_string(lcfg, 1));
1136 err = class_del_uuid(lustre_cfg_string(lcfg, 1));
1139 case LCFG_MOUNTOPT: {
1140 CDEBUG(D_IOCTL, "mountopt: profile %s osc %s mdc %s\n",
1141 lustre_cfg_string(lcfg, 1),
1142 lustre_cfg_string(lcfg, 2),
1143 lustre_cfg_string(lcfg, 3));
1144 /* set these mount options somewhere, so ll_fill_super
1146 err = class_add_profile(LUSTRE_CFG_BUFLEN(lcfg, 1),
1147 lustre_cfg_string(lcfg, 1),
1148 LUSTRE_CFG_BUFLEN(lcfg, 2),
1149 lustre_cfg_string(lcfg, 2),
1150 LUSTRE_CFG_BUFLEN(lcfg, 3),
1151 lustre_cfg_string(lcfg, 3));
1154 case LCFG_DEL_MOUNTOPT: {
1155 CDEBUG(D_IOCTL, "mountopt: profile %s\n",
1156 lustre_cfg_string(lcfg, 1));
1157 class_del_profile(lustre_cfg_string(lcfg, 1));
1160 case LCFG_SET_TIMEOUT: {
1161 CDEBUG(D_IOCTL, "changing lustre timeout from %d to %d\n",
1162 obd_timeout, lcfg->lcfg_num);
1163 obd_timeout = max(lcfg->lcfg_num, 1U);
1164 obd_timeout_set = 1;
1167 case LCFG_SET_LDLM_TIMEOUT: {
1168 CDEBUG(D_IOCTL, "changing lustre ldlm_timeout from %d to %d\n",
1169 ldlm_timeout, lcfg->lcfg_num);
1170 ldlm_timeout = max(lcfg->lcfg_num, 1U);
1171 if (ldlm_timeout >= obd_timeout)
1172 ldlm_timeout = max(obd_timeout / 3, 1U);
1173 ldlm_timeout_set = 1;
1176 case LCFG_SET_UPCALL: {
1177 LCONSOLE_ERROR_MSG(0x15a, "recovery upcall is deprecated\n");
1178 /* COMPAT_146 Don't fail on old configs */
1182 struct cfg_marker *marker;
1183 marker = lustre_cfg_buf(lcfg, 1);
1184 CDEBUG(D_IOCTL, "marker %d (%#x) %.16s %s\n", marker->cm_step,
1185 marker->cm_flags, marker->cm_tgtname, marker->cm_comment);
1190 /* llite has no obd */
1191 if ((class_match_param(lustre_cfg_string(lcfg, 1),
1192 PARAM_LLITE, NULL) == 0) &&
1193 client_process_config) {
1194 err = (*client_process_config)(lcfg);
1196 } else if ((class_match_param(lustre_cfg_string(lcfg, 1),
1197 PARAM_SYS, &tmp) == 0)) {
1198 /* Global param settings */
1199 err = class_set_global(tmp, lcfg->lcfg_num, lcfg);
1201 * Client or server should not fail to mount if
1202 * it hits an unknown configuration parameter.
1205 CWARN("Ignoring unknown param %s\n", tmp);
1208 } else if ((class_match_param(lustre_cfg_string(lcfg, 1),
1209 PARAM_QUOTA, &tmp) == 0) &&
1210 quota_process_config) {
1211 err = (*quota_process_config)(lcfg);
1217 case LCFG_SET_PARAM: {
1218 err = process_param2_config(lcfg);
1222 /* Commands that require a device */
1223 obd = class_name2obd(lustre_cfg_string(lcfg, 0));
1225 if (!LUSTRE_CFG_BUFLEN(lcfg, 0))
1226 CERROR("this lcfg command requires a device name\n");
1228 CERROR("no device for: %s\n",
1229 lustre_cfg_string(lcfg, 0));
1231 GOTO(out, err = -EINVAL);
1233 switch(lcfg->lcfg_command) {
1235 err = class_setup(obd, lcfg);
1239 err = class_detach(obd, lcfg);
1242 case LCFG_CLEANUP: {
1243 err = class_cleanup(obd, lcfg);
1246 case LCFG_ADD_CONN: {
1247 err = class_add_conn(obd, lcfg);
1250 case LCFG_DEL_CONN: {
1251 err = class_del_conn(obd, lcfg);
1254 case LCFG_POOL_NEW: {
1255 err = obd_pool_new(obd, lustre_cfg_string(lcfg, 2));
1258 case LCFG_POOL_ADD: {
1259 err = obd_pool_add(obd, lustre_cfg_string(lcfg, 2),
1260 lustre_cfg_string(lcfg, 3));
1263 case LCFG_POOL_REM: {
1264 err = obd_pool_rem(obd, lustre_cfg_string(lcfg, 2),
1265 lustre_cfg_string(lcfg, 3));
1268 case LCFG_POOL_DEL: {
1269 err = obd_pool_del(obd, lustre_cfg_string(lcfg, 2));
1272 /* Process config log ADD_MDC record twice to add MDC also to LOV
1275 * add 0:lustre-clilmv 1:lustre-MDT0000_UUID 2:0 3:1
1276 * 4:lustre-MDT0000-mdc_UUID
1278 case LCFG_ADD_MDC: {
1279 struct obd_device *lov_obd;
1282 err = obd_process_config(obd, sizeof(*lcfg), lcfg);
1286 /* make sure this is client LMV log entry */
1287 clilmv = strstr(lustre_cfg_string(lcfg, 0), "clilmv");
1291 /* replace 'lmv' with 'lov' name to address LOV device and
1292 * process llog record to add MDC there. */
1294 lov_obd = class_name2obd(lustre_cfg_string(lcfg, 0));
1295 if (lov_obd == NULL) {
1297 CERROR("%s: Cannot find LOV by %s name, rc = %d\n",
1298 obd->obd_name, lustre_cfg_string(lcfg, 0), err);
1300 err = obd_process_config(lov_obd, sizeof(*lcfg), lcfg);
1302 /* restore 'lmv' name */
1307 err = obd_process_config(obd, sizeof(*lcfg), lcfg);
1314 if ((err < 0) && !(lcfg->lcfg_command & LCFG_REQUIRED)) {
1315 CWARN("Ignoring error %d on optional command %#x\n", err,
1316 lcfg->lcfg_command);
1321 EXPORT_SYMBOL(class_process_config);
1323 int class_process_proc_param(char *prefix, struct lprocfs_vars *lvars,
1324 struct lustre_cfg *lcfg, void *data)
1326 struct lprocfs_vars *var;
1327 struct file fakefile;
1328 struct seq_file fake_seqfile;
1330 int i, keylen, vallen;
1331 int matched = 0, j = 0;
1336 if (lcfg->lcfg_command != LCFG_PARAM) {
1337 CERROR("Unknown command: %d\n", lcfg->lcfg_command);
1341 /* fake a seq file so that var->fops->write can work... */
1342 fakefile.private_data = &fake_seqfile;
1343 fake_seqfile.private = data;
1344 /* e.g. tunefs.lustre --param mdt.group_upcall=foo /r/tmp/lustre-mdt
1345 or lctl conf_param lustre-MDT0000.mdt.group_upcall=bar
1346 or lctl conf_param lustre-OST0000.osc.max_dirty_mb=36 */
1347 for (i = 1; i < lcfg->lcfg_bufcount; i++) {
1348 key = lustre_cfg_buf(lcfg, i);
1349 /* Strip off prefix */
1350 if (class_match_param(key, prefix, &key))
1351 /* If the prefix doesn't match, return error so we
1352 * can pass it down the stack */
1354 sval = strchr(key, '=');
1355 if (!sval || *(sval + 1) == 0) {
1356 CERROR("%s: can't parse param '%s' (missing '=')\n",
1357 lustre_cfg_string(lcfg, 0),
1358 lustre_cfg_string(lcfg, i));
1359 /* rc = -EINVAL; continue parsing other params */
1362 keylen = sval - key;
1364 vallen = strlen(sval);
1367 /* Search proc entries */
1368 while (lvars[j].name) {
1370 if (class_match_param(key, var->name, NULL) == 0 &&
1371 keylen == strlen(var->name)) {
1375 if (var->fops && var->fops->write) {
1379 rc = (var->fops->write)(&fakefile, sval,
1388 /* It was upgraded from old MDT/OST device,
1389 * ignore the obsolete "sec_level" parameter. */
1390 if (strncmp("sec_level", key, keylen) == 0)
1393 CERROR("%s: unknown config parameter '%s'\n",
1394 lustre_cfg_string(lcfg, 0),
1395 lustre_cfg_string(lcfg, i));
1396 /* rc = -EINVAL; continue parsing other params */
1398 } else if (rc < 0) {
1399 CERROR("%s: error writing parameter '%s': rc = %d\n",
1400 lustre_cfg_string(lcfg, 0), key, rc);
1403 CDEBUG(D_CONFIG, "%s: set parameter '%s'\n",
1404 lustre_cfg_string(lcfg, 0), key);
1414 EXPORT_SYMBOL(class_process_proc_param);
1417 * Supplemental functions for config logs, it allocates lustre_cfg
1418 * buffers plus initialized llog record header at the beginning.
1420 struct llog_cfg_rec *lustre_cfg_rec_new(int cmd, struct lustre_cfg_bufs *bufs)
1422 struct llog_cfg_rec *lcr;
1427 reclen = lustre_cfg_len(bufs->lcfg_bufcount, bufs->lcfg_buflen);
1428 reclen = llog_data_len(reclen) + sizeof(struct llog_rec_hdr) +
1429 sizeof(struct llog_rec_tail);
1431 OBD_ALLOC(lcr, reclen);
1435 lustre_cfg_init(&lcr->lcr_cfg, cmd, bufs);
1437 lcr->lcr_hdr.lrh_len = reclen;
1438 lcr->lcr_hdr.lrh_type = OBD_CFG_REC;
1442 EXPORT_SYMBOL(lustre_cfg_rec_new);
1444 void lustre_cfg_rec_free(struct llog_cfg_rec *lcr)
1447 OBD_FREE(lcr, lcr->lcr_hdr.lrh_len);
1450 EXPORT_SYMBOL(lustre_cfg_rec_free);
1452 /** Parse a configuration llog, doing various manipulations on them
1453 * for various reasons, (modifications for compatibility, skip obsolete
1454 * records, change uuids, etc), then class_process_config() resulting
1457 int class_config_llog_handler(const struct lu_env *env,
1458 struct llog_handle *handle,
1459 struct llog_rec_hdr *rec, void *data)
1461 struct config_llog_instance *cfg = data;
1462 int cfg_len = rec->lrh_len;
1463 char *cfg_buf = (char *) (rec + 1);
1467 /* class_config_dump_handler(handle, rec, data); */
1469 switch (rec->lrh_type) {
1471 struct lustre_cfg *lcfg, *lcfg_new;
1472 struct lustre_cfg_bufs bufs;
1473 char *inst_name = NULL;
1477 lcfg = (struct lustre_cfg *)cfg_buf;
1478 if (lcfg->lcfg_version == __swab32(LUSTRE_CFG_VERSION)) {
1479 lustre_swab_lustre_cfg(lcfg);
1483 rc = lustre_cfg_sanity_check(cfg_buf, cfg_len);
1487 /* Figure out config state info */
1488 if (lcfg->lcfg_command == LCFG_MARKER) {
1489 struct cfg_marker *marker = lustre_cfg_buf(lcfg, 1);
1490 lustre_swab_cfg_marker(marker, swab,
1491 LUSTRE_CFG_BUFLEN(lcfg, 1));
1492 CDEBUG(D_CONFIG, "Marker, inst_flg=%#x mark_flg=%#x\n",
1493 cfg->cfg_flags, marker->cm_flags);
1494 if (marker->cm_flags & CM_START) {
1495 /* all previous flags off */
1496 cfg->cfg_flags = CFG_F_MARKER;
1497 server_name2index(marker->cm_tgtname,
1498 &cfg->cfg_lwp_idx, NULL);
1499 if (marker->cm_flags & CM_SKIP) {
1500 cfg->cfg_flags |= CFG_F_SKIP;
1501 CDEBUG(D_CONFIG, "SKIP #%d\n",
1503 } else if ((marker->cm_flags & CM_EXCLUDE) ||
1505 lustre_check_exclusion(cfg->cfg_sb,
1506 marker->cm_tgtname))) {
1507 cfg->cfg_flags |= CFG_F_EXCLUDE;
1508 CDEBUG(D_CONFIG, "EXCLUDE %d\n",
1511 } else if (marker->cm_flags & CM_END) {
1515 /* A config command without a start marker before it is
1516 illegal (post 146) */
1517 if (!(cfg->cfg_flags & CFG_F_COMPAT146) &&
1518 !(cfg->cfg_flags & CFG_F_MARKER) &&
1519 (lcfg->lcfg_command != LCFG_MARKER)) {
1520 CWARN("Config not inside markers, ignoring! "
1521 "(inst: %p, uuid: %s, flags: %#x)\n",
1523 cfg->cfg_uuid.uuid, cfg->cfg_flags);
1524 cfg->cfg_flags |= CFG_F_SKIP;
1526 if (cfg->cfg_flags & CFG_F_SKIP) {
1527 CDEBUG(D_CONFIG, "skipping %#x\n",
1530 /* No processing! */
1535 * For interoperability between 1.8 and 2.0,
1536 * rename "mds" obd device type to "mdt".
1539 char *typename = lustre_cfg_string(lcfg, 1);
1540 char *index = lustre_cfg_string(lcfg, 2);
1542 if ((lcfg->lcfg_command == LCFG_ATTACH && typename &&
1543 strcmp(typename, "mds") == 0)) {
1544 CWARN("For 1.8 interoperability, rename obd "
1545 "type from mds to mdt\n");
1548 if ((lcfg->lcfg_command == LCFG_SETUP && index &&
1549 strcmp(index, "type") == 0)) {
1550 CDEBUG(D_INFO, "For 1.8 interoperability, "
1551 "set this index to '0'\n");
1557 #ifdef HAVE_SERVER_SUPPORT
1558 /* newer MDS replaces LOV/OSC with LOD/OSP */
1560 char *typename = lustre_cfg_string(lcfg, 1);
1562 if ((lcfg->lcfg_command == LCFG_ATTACH && typename &&
1563 strcmp(typename, LUSTRE_LOV_NAME) == 0) &&
1564 cfg->cfg_sb && IS_MDT(s2lsi(cfg->cfg_sb))) {
1566 "For 2.x interoperability, rename obd "
1567 "type from lov to lod (%s)\n",
1568 s2lsi(cfg->cfg_sb)->lsi_svname);
1569 strcpy(typename, LUSTRE_LOD_NAME);
1571 if ((lcfg->lcfg_command == LCFG_ATTACH && typename &&
1572 strcmp(typename, LUSTRE_OSC_NAME) == 0) &&
1573 cfg->cfg_sb && IS_MDT(s2lsi(cfg->cfg_sb))) {
1575 "For 2.x interoperability, rename obd "
1576 "type from osc to osp (%s)\n",
1577 s2lsi(cfg->cfg_sb)->lsi_svname);
1578 strcpy(typename, LUSTRE_OSP_NAME);
1581 #endif /* HAVE_SERVER_SUPPORT */
1583 if (cfg->cfg_flags & CFG_F_EXCLUDE) {
1584 CDEBUG(D_CONFIG, "cmd: %x marked EXCLUDED\n",
1585 lcfg->lcfg_command);
1586 if (lcfg->lcfg_command == LCFG_LOV_ADD_OBD)
1587 /* Add inactive instead */
1588 lcfg->lcfg_command = LCFG_LOV_ADD_INA;
1591 lustre_cfg_bufs_reset(&bufs, NULL);
1592 lustre_cfg_bufs_init(&bufs, lcfg);
1594 if (cfg->cfg_instance &&
1595 LUSTRE_CFG_BUFLEN(lcfg, 0) > 0) {
1596 inst_len = LUSTRE_CFG_BUFLEN(lcfg, 0) +
1597 sizeof(cfg->cfg_instance) * 2 + 4;
1598 OBD_ALLOC(inst_name, inst_len);
1599 if (inst_name == NULL)
1600 GOTO(out, rc = -ENOMEM);
1601 snprintf(inst_name, inst_len, "%s-%p",
1602 lustre_cfg_string(lcfg, 0),
1604 lustre_cfg_bufs_set_string(&bufs, 0, inst_name);
1605 CDEBUG(D_CONFIG, "cmd %x, instance name: %s\n",
1606 lcfg->lcfg_command, inst_name);
1609 /* we override the llog's uuid for clients, to insure they
1611 if (cfg->cfg_instance != NULL &&
1612 lcfg->lcfg_command == LCFG_ATTACH) {
1613 lustre_cfg_bufs_set_string(&bufs, 2,
1614 cfg->cfg_uuid.uuid);
1617 * sptlrpc config record, we expect 2 data segments:
1618 * [0]: fs_name/target_name,
1620 * moving them to index [1] and [2], and insert MGC's
1621 * obdname at index [0].
1623 if (cfg->cfg_instance == NULL &&
1624 lcfg->lcfg_command == LCFG_SPTLRPC_CONF) {
1625 lustre_cfg_bufs_set(&bufs, 2, bufs.lcfg_buf[1],
1626 bufs.lcfg_buflen[1]);
1627 lustre_cfg_bufs_set(&bufs, 1, bufs.lcfg_buf[0],
1628 bufs.lcfg_buflen[0]);
1629 lustre_cfg_bufs_set_string(&bufs, 0,
1633 /* Add net info to setup command
1634 * if given on command line.
1635 * So config log will be:
1639 * [3]: inactive-on-startup
1640 * [4]: restrictive net
1642 if (cfg && cfg->cfg_sb && s2lsi(cfg->cfg_sb) &&
1643 !IS_SERVER(s2lsi(cfg->cfg_sb))) {
1644 struct lustre_sb_info *lsi = s2lsi(cfg->cfg_sb);
1645 char *nidnet = lsi->lsi_lmd->lmd_nidnet;
1647 if (lcfg->lcfg_command == LCFG_SETUP &&
1648 lcfg->lcfg_bufcount != 2 && nidnet) {
1649 CDEBUG(D_CONFIG, "Adding net %s info to setup "
1650 "command for client %s\n", nidnet,
1651 lustre_cfg_string(lcfg, 0));
1652 lustre_cfg_bufs_set_string(&bufs, 4, nidnet);
1656 /* Skip add_conn command if uuid is
1657 * not on restricted net */
1658 if (cfg && cfg->cfg_sb && s2lsi(cfg->cfg_sb) &&
1659 !IS_SERVER(s2lsi(cfg->cfg_sb))) {
1660 struct lustre_sb_info *lsi = s2lsi(cfg->cfg_sb);
1661 char *uuid_str = lustre_cfg_string(lcfg, 1);
1663 if (lcfg->lcfg_command == LCFG_ADD_CONN &&
1664 lsi->lsi_lmd->lmd_nidnet &&
1665 LNET_NIDNET(libcfs_str2nid(uuid_str)) !=
1666 libcfs_str2net(lsi->lsi_lmd->lmd_nidnet)) {
1667 CDEBUG(D_CONFIG, "skipping add_conn for %s\n",
1670 /* No processing! */
1675 OBD_ALLOC(lcfg_new, lustre_cfg_len(bufs.lcfg_bufcount,
1678 GOTO(out, rc = -ENOMEM);
1680 lustre_cfg_init(lcfg_new, lcfg->lcfg_command, &bufs);
1681 lcfg_new->lcfg_num = lcfg->lcfg_num;
1682 lcfg_new->lcfg_flags = lcfg->lcfg_flags;
1684 /* XXX Hack to try to remain binary compatible with
1685 * pre-newconfig logs */
1686 if (lcfg->lcfg_nal != 0 && /* pre-newconfig log? */
1687 (lcfg->lcfg_nid >> 32) == 0) {
1688 __u32 addr = (__u32)(lcfg->lcfg_nid & 0xffffffff);
1690 lcfg_new->lcfg_nid =
1691 LNET_MKNID(LNET_MKNET(lcfg->lcfg_nal, 0), addr);
1692 CWARN("Converted pre-newconfig NAL %d NID %x to %s\n",
1693 lcfg->lcfg_nal, addr,
1694 libcfs_nid2str(lcfg_new->lcfg_nid));
1696 lcfg_new->lcfg_nid = lcfg->lcfg_nid;
1699 lcfg_new->lcfg_nal = 0; /* illegal value for obsolete field */
1701 rc = class_process_config(lcfg_new);
1702 OBD_FREE(lcfg_new, lustre_cfg_len(lcfg_new->lcfg_bufcount,
1703 lcfg_new->lcfg_buflens));
1705 OBD_FREE(inst_name, inst_len);
1709 CERROR("Unknown llog record type %#x encountered\n",
1715 CERROR("%s: cfg command failed: rc = %d\n",
1716 handle->lgh_ctxt->loc_obd->obd_name, rc);
1717 class_config_dump_handler(NULL, handle, rec, data);
1721 EXPORT_SYMBOL(class_config_llog_handler);
1723 int class_config_parse_llog(const struct lu_env *env, struct llog_ctxt *ctxt,
1724 char *name, struct config_llog_instance *cfg)
1726 struct llog_process_cat_data cd = {
1727 .lpcd_first_idx = 0,
1729 struct llog_handle *llh;
1734 CDEBUG(D_INFO, "looking up llog %s\n", name);
1735 rc = llog_open(env, ctxt, &llh, NULL, name, LLOG_OPEN_EXISTS);
1739 rc = llog_init_handle(env, llh, LLOG_F_IS_PLAIN, NULL);
1741 GOTO(parse_out, rc);
1743 /* continue processing from where we last stopped to end-of-log */
1745 cd.lpcd_first_idx = cfg->cfg_last_idx;
1746 callback = cfg->cfg_callback;
1747 LASSERT(callback != NULL);
1749 callback = class_config_llog_handler;
1752 cd.lpcd_last_idx = 0;
1754 rc = llog_process(env, llh, callback, cfg, &cd);
1756 CDEBUG(D_CONFIG, "Processed log %s gen %d-%d (rc=%d)\n", name,
1757 cd.lpcd_first_idx + 1, cd.lpcd_last_idx, rc);
1759 cfg->cfg_last_idx = cd.lpcd_last_idx;
1762 llog_close(env, llh);
1765 EXPORT_SYMBOL(class_config_parse_llog);
1767 static struct lcfg_type_data {
1771 } lcfg_data_table[] = {
1772 { LCFG_ATTACH, "attach", { "type", "UUID", "3", "4" } },
1773 { LCFG_DETACH, "detach", { "1", "2", "3", "4" } },
1774 { LCFG_SETUP, "setup", { "UUID", "node", "options", "failout" } },
1775 { LCFG_CLEANUP, "cleanup", { "1", "2", "3", "4" } },
1776 { LCFG_ADD_UUID, "add_uuid", { "node", "2", "3", "4" } },
1777 { LCFG_DEL_UUID, "del_uuid", { "1", "2", "3", "4" } },
1778 { LCFG_MOUNTOPT, "new_profile", { "name", "lov", "lmv", "4" } },
1779 { LCFG_DEL_MOUNTOPT, "del_mountopt", { "1", "2", "3", "4" } , },
1780 { LCFG_SET_TIMEOUT, "set_timeout", { "parameter", "2", "3", "4" } },
1781 { LCFG_SET_UPCALL, "set_upcall", { "1", "2", "3", "4" } },
1782 { LCFG_ADD_CONN, "add_conn", { "node", "2", "3", "4" } },
1783 { LCFG_DEL_CONN, "del_conn", { "1", "2", "3", "4" } },
1784 { LCFG_LOV_ADD_OBD, "add_osc", { "ost", "index", "gen", "UUID" } },
1785 { LCFG_LOV_DEL_OBD, "del_osc", { "1", "2", "3", "4" } },
1786 { LCFG_PARAM, "set_param", { "parameter", "value", "3", "4" } },
1787 { LCFG_MARKER, "marker", { "1", "2", "3", "4" } },
1788 { LCFG_LOG_START, "log_start", { "1", "2", "3", "4" } },
1789 { LCFG_LOG_END, "log_end", { "1", "2", "3", "4" } },
1790 { LCFG_LOV_ADD_INA, "add_osc_inactive", { "1", "2", "3", "4" } },
1791 { LCFG_ADD_MDC, "add_mdc", { "mdt", "index", "gen", "UUID" } },
1792 { LCFG_DEL_MDC, "del_mdc", { "1", "2", "3", "4" } },
1793 { LCFG_SPTLRPC_CONF, "security", { "parameter", "2", "3", "4" } },
1794 { LCFG_POOL_NEW, "new_pool", { "fsname", "pool", "3", "4" } },
1795 { LCFG_POOL_ADD, "add_pool", { "fsname", "pool", "ost", "4" } },
1796 { LCFG_POOL_REM, "remove_pool", { "fsname", "pool", "ost", "4" } },
1797 { LCFG_POOL_DEL, "del_pool", { "fsname", "pool", "3", "4" } },
1798 { LCFG_SET_LDLM_TIMEOUT, "set_ldlm_timeout",
1799 { "parameter", "2", "3", "4" } },
1800 { 0, NULL, { NULL, NULL, NULL, NULL } }
1803 static struct lcfg_type_data *lcfg_cmd2data(__u32 cmd)
1807 while (lcfg_data_table[i].ltd_type != 0) {
1808 if (lcfg_data_table[i].ltd_type == cmd)
1809 return &lcfg_data_table[i];
1816 * Parse config record and output dump in supplied buffer.
1818 * This is separated from class_config_dump_handler() to use
1819 * for ioctl needs as well
1822 * - { index: 4, event: attach, device: lustrewt-clilov, type: lov,
1823 * UUID: lustrewt-clilov_UUID }
1825 int class_config_yaml_output(struct llog_rec_hdr *rec, char *buf, int size)
1827 struct lustre_cfg *lcfg = (struct lustre_cfg *)(rec + 1);
1829 char *end = buf + size;
1831 struct lcfg_type_data *ldata;
1833 LASSERT(rec->lrh_type == OBD_CFG_REC);
1834 rc = lustre_cfg_sanity_check(lcfg, rec->lrh_len);
1838 ldata = lcfg_cmd2data(lcfg->lcfg_command);
1842 if (lcfg->lcfg_command == LCFG_MARKER)
1845 /* form YAML entity */
1846 ptr += snprintf(ptr, end - ptr, "- { index: %u, event: %s",
1847 rec->lrh_index, ldata->ltd_name);
1849 if (lcfg->lcfg_flags)
1850 ptr += snprintf(ptr, end - ptr, ", flags: %#08x",
1853 ptr += snprintf(ptr, end - ptr, ", num: %#08x",
1855 if (lcfg->lcfg_nid) {
1856 char nidstr[LNET_NIDSTR_SIZE];
1858 libcfs_nid2str_r(lcfg->lcfg_nid, nidstr, sizeof(nidstr));
1859 ptr += snprintf(ptr, end - ptr, ", nid: %s(%#llx)",
1860 nidstr, lcfg->lcfg_nid);
1863 if (LUSTRE_CFG_BUFLEN(lcfg, 0) > 0)
1864 ptr += snprintf(ptr, end - ptr, ", device: %s",
1865 lustre_cfg_string(lcfg, 0));
1867 for (i = 1; i < lcfg->lcfg_bufcount; i++) {
1868 if (LUSTRE_CFG_BUFLEN(lcfg, i) > 0)
1869 ptr += snprintf(ptr, end - ptr, ", %s: %s",
1870 ldata->ltd_bufs[i - 1],
1871 lustre_cfg_string(lcfg, i));
1874 ptr += snprintf(ptr, end - ptr, " }\n");
1875 /* return consumed bytes */
1881 * parse config record and output dump in supplied buffer.
1882 * This is separated from class_config_dump_handler() to use
1883 * for ioctl needs as well
1885 static int class_config_parse_rec(struct llog_rec_hdr *rec, char *buf, int size)
1887 struct lustre_cfg *lcfg = (struct lustre_cfg *)(rec + 1);
1889 char *end = buf + size;
1894 LASSERT(rec->lrh_type == OBD_CFG_REC);
1895 rc = lustre_cfg_sanity_check(lcfg, rec->lrh_len);
1899 ptr += snprintf(ptr, end-ptr, "cmd=%05x ", lcfg->lcfg_command);
1900 if (lcfg->lcfg_flags)
1901 ptr += snprintf(ptr, end-ptr, "flags=%#08x ",
1905 ptr += snprintf(ptr, end-ptr, "num=%#08x ", lcfg->lcfg_num);
1907 if (lcfg->lcfg_nid) {
1908 char nidstr[LNET_NIDSTR_SIZE];
1910 libcfs_nid2str_r(lcfg->lcfg_nid, nidstr, sizeof(nidstr));
1911 ptr += snprintf(ptr, end-ptr, "nid=%s(%#llx)\n ",
1912 nidstr, lcfg->lcfg_nid);
1915 if (lcfg->lcfg_command == LCFG_MARKER) {
1916 struct cfg_marker *marker = lustre_cfg_buf(lcfg, 1);
1918 ptr += snprintf(ptr, end-ptr, "marker=%d(%#x)%s '%s'",
1919 marker->cm_step, marker->cm_flags,
1920 marker->cm_tgtname, marker->cm_comment);
1924 for (i = 0; i < lcfg->lcfg_bufcount; i++) {
1925 ptr += snprintf(ptr, end-ptr, "%d:%s ", i,
1926 lustre_cfg_string(lcfg, i));
1929 ptr += snprintf(ptr, end - ptr, "\n");
1930 /* return consumed bytes */
1935 int class_config_dump_handler(const struct lu_env *env,
1936 struct llog_handle *handle,
1937 struct llog_rec_hdr *rec, void *data)
1944 OBD_ALLOC(outstr, 256);
1948 if (rec->lrh_type == OBD_CFG_REC) {
1949 class_config_parse_rec(rec, outstr, 256);
1950 LCONSOLE(D_WARNING, " %s\n", outstr);
1952 LCONSOLE(D_WARNING, "unhandled lrh_type: %#x\n", rec->lrh_type);
1956 OBD_FREE(outstr, 256);
1960 /** Call class_cleanup and class_detach.
1961 * "Manual" only in the sense that we're faking lcfg commands.
1963 int class_manual_cleanup(struct obd_device *obd)
1966 struct lustre_cfg *lcfg;
1967 struct lustre_cfg_bufs bufs;
1972 CERROR("empty cleanup\n");
1981 CDEBUG(D_CONFIG, "Manual cleanup of %s (flags='%s')\n",
1982 obd->obd_name, flags);
1984 lustre_cfg_bufs_reset(&bufs, obd->obd_name);
1985 lustre_cfg_bufs_set_string(&bufs, 1, flags);
1986 OBD_ALLOC(lcfg, lustre_cfg_len(bufs.lcfg_bufcount, bufs.lcfg_buflen));
1989 lustre_cfg_init(lcfg, LCFG_CLEANUP, &bufs);
1991 rc = class_process_config(lcfg);
1993 CERROR("cleanup failed %d: %s\n", rc, obd->obd_name);
1997 /* the lcfg is almost the same for both ops */
1998 lcfg->lcfg_command = LCFG_DETACH;
1999 rc = class_process_config(lcfg);
2001 CERROR("detach failed %d: %s\n", rc, obd->obd_name);
2003 OBD_FREE(lcfg, lustre_cfg_len(lcfg->lcfg_bufcount, lcfg->lcfg_buflens));
2006 EXPORT_SYMBOL(class_manual_cleanup);
2009 * uuid<->export lustre hash operations
2013 uuid_hash(struct cfs_hash *hs, const void *key, unsigned mask)
2015 return cfs_hash_djb2_hash(((struct obd_uuid *)key)->uuid,
2016 sizeof(((struct obd_uuid *)key)->uuid), mask);
2020 uuid_key(struct hlist_node *hnode)
2022 struct obd_export *exp;
2024 exp = hlist_entry(hnode, struct obd_export, exp_uuid_hash);
2026 return &exp->exp_client_uuid;
2030 * NOTE: It is impossible to find an export that is in failed
2031 * state with this function
2034 uuid_keycmp(const void *key, struct hlist_node *hnode)
2036 struct obd_export *exp;
2039 exp = hlist_entry(hnode, struct obd_export, exp_uuid_hash);
2041 return obd_uuid_equals(key, &exp->exp_client_uuid) &&
2046 uuid_export_object(struct hlist_node *hnode)
2048 return hlist_entry(hnode, struct obd_export, exp_uuid_hash);
2052 uuid_export_get(struct cfs_hash *hs, struct hlist_node *hnode)
2054 struct obd_export *exp;
2056 exp = hlist_entry(hnode, struct obd_export, exp_uuid_hash);
2057 class_export_get(exp);
2061 uuid_export_put_locked(struct cfs_hash *hs, struct hlist_node *hnode)
2063 struct obd_export *exp;
2065 exp = hlist_entry(hnode, struct obd_export, exp_uuid_hash);
2066 class_export_put(exp);
2069 static struct cfs_hash_ops uuid_hash_ops = {
2070 .hs_hash = uuid_hash,
2072 .hs_keycmp = uuid_keycmp,
2073 .hs_object = uuid_export_object,
2074 .hs_get = uuid_export_get,
2075 .hs_put_locked = uuid_export_put_locked,
2080 * nid<->export hash operations
2084 nid_hash(struct cfs_hash *hs, const void *key, unsigned mask)
2086 return cfs_hash_djb2_hash(key, sizeof(lnet_nid_t), mask);
2090 nid_key(struct hlist_node *hnode)
2092 struct obd_export *exp;
2094 exp = hlist_entry(hnode, struct obd_export, exp_nid_hash);
2096 RETURN(&exp->exp_connection->c_peer.nid);
2100 * NOTE: It is impossible to find an export that is in failed
2101 * state with this function
2104 nid_kepcmp(const void *key, struct hlist_node *hnode)
2106 struct obd_export *exp;
2109 exp = hlist_entry(hnode, struct obd_export, exp_nid_hash);
2111 RETURN(exp->exp_connection->c_peer.nid == *(lnet_nid_t *)key &&
2116 nid_export_object(struct hlist_node *hnode)
2118 return hlist_entry(hnode, struct obd_export, exp_nid_hash);
2122 nid_export_get(struct cfs_hash *hs, struct hlist_node *hnode)
2124 struct obd_export *exp;
2126 exp = hlist_entry(hnode, struct obd_export, exp_nid_hash);
2127 class_export_get(exp);
2131 nid_export_put_locked(struct cfs_hash *hs, struct hlist_node *hnode)
2133 struct obd_export *exp;
2135 exp = hlist_entry(hnode, struct obd_export, exp_nid_hash);
2136 class_export_put(exp);
2139 static struct cfs_hash_ops nid_hash_ops = {
2140 .hs_hash = nid_hash,
2142 .hs_keycmp = nid_kepcmp,
2143 .hs_object = nid_export_object,
2144 .hs_get = nid_export_get,
2145 .hs_put_locked = nid_export_put_locked,
2150 * nid<->nidstats hash operations
2154 nidstats_key(struct hlist_node *hnode)
2156 struct nid_stat *ns;
2158 ns = hlist_entry(hnode, struct nid_stat, nid_hash);
2164 nidstats_keycmp(const void *key, struct hlist_node *hnode)
2166 return *(lnet_nid_t *)nidstats_key(hnode) == *(lnet_nid_t *)key;
2170 nidstats_object(struct hlist_node *hnode)
2172 return hlist_entry(hnode, struct nid_stat, nid_hash);
2176 nidstats_get(struct cfs_hash *hs, struct hlist_node *hnode)
2178 struct nid_stat *ns;
2180 ns = hlist_entry(hnode, struct nid_stat, nid_hash);
2185 nidstats_put_locked(struct cfs_hash *hs, struct hlist_node *hnode)
2187 struct nid_stat *ns;
2189 ns = hlist_entry(hnode, struct nid_stat, nid_hash);
2193 static struct cfs_hash_ops nid_stat_hash_ops = {
2194 .hs_hash = nid_hash,
2195 .hs_key = nidstats_key,
2196 .hs_keycmp = nidstats_keycmp,
2197 .hs_object = nidstats_object,
2198 .hs_get = nidstats_get,
2199 .hs_put_locked = nidstats_put_locked,
2204 * client_generation<->export hash operations
2208 gen_hash(struct cfs_hash *hs, const void *key, unsigned mask)
2210 return cfs_hash_djb2_hash(key, sizeof(__u32), mask);
2214 gen_key(struct hlist_node *hnode)
2216 struct obd_export *exp;
2218 exp = hlist_entry(hnode, struct obd_export, exp_gen_hash);
2220 RETURN(&exp->exp_target_data.ted_lcd->lcd_generation);
2224 * NOTE: It is impossible to find an export that is in failed
2225 * state with this function
2228 gen_kepcmp(const void *key, struct hlist_node *hnode)
2230 struct obd_export *exp;
2233 exp = hlist_entry(hnode, struct obd_export, exp_gen_hash);
2235 RETURN(exp->exp_target_data.ted_lcd->lcd_generation == *(__u32 *)key &&
2240 gen_export_object(struct hlist_node *hnode)
2242 return hlist_entry(hnode, struct obd_export, exp_gen_hash);
2246 gen_export_get(struct cfs_hash *hs, struct hlist_node *hnode)
2248 struct obd_export *exp;
2250 exp = hlist_entry(hnode, struct obd_export, exp_gen_hash);
2251 class_export_get(exp);
2255 gen_export_put_locked(struct cfs_hash *hs, struct hlist_node *hnode)
2257 struct obd_export *exp;
2259 exp = hlist_entry(hnode, struct obd_export, exp_gen_hash);
2260 class_export_put(exp);
2263 static struct cfs_hash_ops gen_hash_ops = {
2264 .hs_hash = gen_hash,
2266 .hs_keycmp = gen_kepcmp,
2267 .hs_object = gen_export_object,
2268 .hs_get = gen_export_get,
2269 .hs_put_locked = gen_export_put_locked,