4 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License version 2 only,
8 * as published by the Free Software Foundation.
10 * This program is distributed in the hope that it will be useful, but
11 * WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * General Public License version 2 for more details (a copy is included
14 * in the LICENSE file that accompanied this code).
16 * You should have received a copy of the GNU General Public License
17 * version 2 along with this program; If not, see
18 * http://www.gnu.org/licenses/gpl-2.0.html
23 * Copyright (c) 2003, 2010, Oracle and/or its affiliates. All rights reserved.
24 * Use is subject to license terms.
26 * Copyright (c) 2011, 2016, Intel Corporation.
29 * This file is part of Lustre, http://www.lustre.org/
30 * Lustre is a trademark of Sun Microsystems, Inc.
32 * lustre/obdclass/obd_config.c
37 #define DEBUG_SUBSYSTEM S_CLASS
39 #include <linux/string.h>
41 #include <llog_swab.h>
42 #include <lprocfs_status.h>
43 #include <lustre_disk.h>
44 #include <uapi/linux/lustre/lustre_ioctl.h>
45 #include <lustre_log.h>
46 #include <uapi/linux/lustre/lustre_param.h>
47 #include <obd_class.h>
49 #include "llog_internal.h"
51 static struct cfs_hash_ops uuid_hash_ops;
52 static struct cfs_hash_ops nid_hash_ops;
53 static struct cfs_hash_ops nid_stat_hash_ops;
54 static struct cfs_hash_ops gen_hash_ops;
56 /*********** string parsing utils *********/
58 /* returns 0 if we find this key in the buffer, else 1 */
59 int class_find_param(char *buf, char *key, char **valp)
66 if ((ptr = strstr(buf, key)) == NULL)
70 *valp = ptr + strlen(key);
74 EXPORT_SYMBOL(class_find_param);
77 * Check whether the proc parameter \a param is an old parameter or not from
78 * the array \a ptr which contains the mapping from old parameters to new ones.
79 * If it's an old one, then return the pointer to the cfg_interop_param struc-
80 * ture which contains both the old and new parameters.
82 * \param param proc parameter
83 * \param ptr an array which contains the mapping from
84 * old parameters to new ones
86 * \retval valid-pointer pointer to the cfg_interop_param structure
87 * which contains the old and new parameters
88 * \retval NULL \a param or \a ptr is NULL,
89 * or \a param is not an old parameter
91 struct cfg_interop_param *class_find_old_param(const char *param,
92 struct cfg_interop_param *ptr)
97 if (param == NULL || ptr == NULL)
100 value = strchr(param, '=');
102 name_len = strlen(param);
104 name_len = value - param;
106 while (ptr->old_param != NULL) {
107 if (strncmp(param, ptr->old_param, name_len) == 0 &&
108 name_len == strlen(ptr->old_param))
115 EXPORT_SYMBOL(class_find_old_param);
118 * Finds a parameter in \a params and copies it to \a copy.
120 * Leading spaces are skipped. Next space or end of string is the
121 * parameter terminator with the exception that spaces inside single or double
122 * quotes get included into a parameter. The parameter is copied into \a copy
123 * which has to be allocated big enough by a caller, quotes are stripped in
124 * the copy and the copy is terminated by 0.
126 * On return \a params is set to next parameter or to NULL if last
127 * parameter is returned.
129 * \retval 0 if parameter is returned in \a copy
130 * \retval 1 otherwise
131 * \retval -EINVAL if unbalanced quota is found
133 int class_get_next_param(char **params, char *copy)
148 q1 = strpbrk(str, " '\"");
151 memcpy(copy, str, len);
158 memcpy(copy, str, len);
164 memcpy(copy, str, len);
167 /* search for the matching closing quote */
169 q2 = strchr(str, *q1);
171 CERROR("Unbalanced quota in parameters: \"%s\"\n",
176 memcpy(copy, str, len);
182 EXPORT_SYMBOL(class_get_next_param);
184 /* returns 0 if this is the first key in the buffer, else 1.
185 valp points to first char after key. */
186 int class_match_param(char *buf, const char *key, char **valp)
191 if (memcmp(buf, key, strlen(key)) != 0)
195 *valp = buf + strlen(key);
199 EXPORT_SYMBOL(class_match_param);
201 static int parse_nid(char *buf, void *value, int quiet)
203 lnet_nid_t *nid = (lnet_nid_t *)value;
205 *nid = libcfs_str2nid(buf);
206 if (*nid != LNET_NID_ANY)
210 LCONSOLE_ERROR_MSG(0x159, "Can't parse NID '%s'\n", buf);
214 static int parse_net(char *buf, void *value)
216 __u32 *net = (__u32 *)value;
218 *net = libcfs_str2net(buf);
219 CDEBUG(D_INFO, "Net %s\n", libcfs_net2str(*net));
231 endh is set to next separator */
232 static int class_parse_value(char *buf, int opc, void *value, char **endh,
241 while (*buf == ',' || *buf == ':')
243 if (*buf == ' ' || *buf == '/' || *buf == '\0')
246 /* nid separators or end of nids */
247 endp = strpbrk(buf, ",: /");
249 endp = buf + strlen(buf);
256 case CLASS_PARSE_NID:
257 rc = parse_nid(buf, value, quiet);
259 case CLASS_PARSE_NET:
260 rc = parse_net(buf, value);
271 int class_parse_nid(char *buf, lnet_nid_t *nid, char **endh)
273 return class_parse_value(buf, CLASS_PARSE_NID, (void *)nid, endh, 0);
275 EXPORT_SYMBOL(class_parse_nid);
277 int class_parse_nid_quiet(char *buf, lnet_nid_t *nid, char **endh)
279 return class_parse_value(buf, CLASS_PARSE_NID, (void *)nid, endh, 1);
281 EXPORT_SYMBOL(class_parse_nid_quiet);
283 int class_parse_net(char *buf, __u32 *net, char **endh)
285 return class_parse_value(buf, CLASS_PARSE_NET, (void *)net, endh, 0);
288 /* 1 param contains key and match
289 * 0 param contains key and not match
290 * -1 param does not contain key
292 int class_match_nid(char *buf, char *key, lnet_nid_t nid)
297 while (class_find_param(buf, key, &buf) == 0) {
298 /* please restrict to the nids pertaining to
299 * the specified nids */
300 while (class_parse_nid(buf, &tmp, &buf) == 0) {
309 int class_match_net(char *buf, char *key, __u32 net)
314 while (class_find_param(buf, key, &buf) == 0) {
315 /* please restrict to the nids pertaining to
316 * the specified networks */
317 while (class_parse_net(buf, &tmp, &buf) == 0) {
326 char *lustre_cfg_string(struct lustre_cfg *lcfg, u32 index)
330 if (!lcfg->lcfg_buflens[index])
333 s = lustre_cfg_buf(lcfg, index);
338 * make sure it's NULL terminated, even if this kills a char
339 * of data. Try to use the padding first though.
341 if (s[lcfg->lcfg_buflens[index] - 1] != '\0') {
342 size_t last = ALIGN(lcfg->lcfg_buflens[index], 8) - 1;
345 /* Use the smaller value */
346 if (last > lcfg->lcfg_buflens[index])
347 last = lcfg->lcfg_buflens[index];
352 CWARN("Truncated buf %d to '%s' (lost '%c'...)\n",
358 EXPORT_SYMBOL(lustre_cfg_string);
360 /********************** class fns **********************/
363 * Create a new obd device and set the type, name and uuid. If successful,
364 * the new device can be accessed by either name or uuid.
366 int class_attach(struct lustre_cfg *lcfg)
368 struct obd_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);
400 /* Already exists or out of obds */
402 CERROR("Cannot create device %s of type %s : %d\n",
406 LASSERTF(obd != NULL, "Cannot get obd device %s of type %s\n",
408 LASSERTF(obd->obd_magic == OBD_DEVICE_MAGIC,
409 "obd %p obd_magic %08X != %08X\n",
410 obd, obd->obd_magic, OBD_DEVICE_MAGIC);
411 LASSERTF(strncmp(obd->obd_name, name, strlen(name)) == 0,
412 "%p obd_name %s != %s\n", obd, obd->obd_name, name);
414 exp = class_new_export_self(obd, &obd->obd_uuid);
417 GOTO(out, rc = PTR_ERR(exp));
418 RETURN(PTR_ERR(exp));
421 obd->obd_self_export = exp;
422 list_del_init(&exp->exp_obd_chain_timed);
423 class_export_put(exp);
425 rc = class_register_device(obd);
429 obd->obd_attached = 1;
430 CDEBUG(D_IOCTL, "OBD: dev %d attached type %s with refcount %d\n",
431 obd->obd_minor, typename, atomic_read(&obd->obd_refcount));
434 class_decref(obd, "newdev", obd);
439 EXPORT_SYMBOL(class_attach);
441 /** Create hashes, self-export, and call type-specific setup.
442 * Setup is effectively the "start this obd" call.
444 int class_setup(struct obd_device *obd, struct lustre_cfg *lcfg)
449 LASSERT(obd != NULL);
450 LASSERTF(obd == class_num2obd(obd->obd_minor),
451 "obd %p != obd_devs[%d] %p\n",
452 obd, obd->obd_minor, class_num2obd(obd->obd_minor));
453 LASSERTF(obd->obd_magic == OBD_DEVICE_MAGIC,
454 "obd %p obd_magic %08x != %08x\n",
455 obd, obd->obd_magic, OBD_DEVICE_MAGIC);
457 /* have we attached a type to this device? */
458 if (!obd->obd_attached) {
459 CERROR("Device %d not attached\n", obd->obd_minor);
463 if (obd->obd_set_up) {
464 CERROR("Device %d already setup (type %s)\n",
465 obd->obd_minor, obd->obd_type->typ_name);
469 /* is someone else setting us up right now? (attach inits spinlock) */
470 spin_lock(&obd->obd_dev_lock);
471 if (obd->obd_starting) {
472 spin_unlock(&obd->obd_dev_lock);
473 CERROR("Device %d setup in progress (type %s)\n",
474 obd->obd_minor, obd->obd_type->typ_name);
477 /* just leave this on forever. I can't use obd_set_up here because
478 other fns check that status, and we're not actually set up yet. */
479 obd->obd_starting = 1;
480 obd->obd_uuid_hash = NULL;
481 obd->obd_nid_hash = NULL;
482 obd->obd_nid_stats_hash = NULL;
483 obd->obd_gen_hash = NULL;
484 spin_unlock(&obd->obd_dev_lock);
486 /* create an uuid-export lustre hash */
487 obd->obd_uuid_hash = cfs_hash_create("UUID_HASH",
490 HASH_UUID_BKT_BITS, 0,
493 &uuid_hash_ops, CFS_HASH_DEFAULT);
494 if (!obd->obd_uuid_hash)
495 GOTO(err_exit, err = -ENOMEM);
497 /* create a nid-export lustre hash */
498 obd->obd_nid_hash = cfs_hash_create("NID_HASH",
501 HASH_NID_BKT_BITS, 0,
504 &nid_hash_ops, CFS_HASH_DEFAULT);
505 if (!obd->obd_nid_hash)
506 GOTO(err_exit, err = -ENOMEM);
508 /* create a nid-stats lustre hash */
509 obd->obd_nid_stats_hash = cfs_hash_create("NID_STATS",
510 HASH_NID_STATS_CUR_BITS,
511 HASH_NID_STATS_MAX_BITS,
512 HASH_NID_STATS_BKT_BITS, 0,
515 &nid_stat_hash_ops, CFS_HASH_DEFAULT);
516 if (!obd->obd_nid_stats_hash)
517 GOTO(err_exit, err = -ENOMEM);
519 /* create a client_generation-export lustre hash */
520 obd->obd_gen_hash = cfs_hash_create("UUID_HASH",
523 HASH_GEN_BKT_BITS, 0,
526 &gen_hash_ops, CFS_HASH_DEFAULT);
527 if (!obd->obd_gen_hash)
528 GOTO(err_exit, err = -ENOMEM);
530 err = obd_setup(obd, lcfg);
536 spin_lock(&obd->obd_dev_lock);
537 /* cleanup drops this */
538 class_incref(obd, "setup", obd);
539 spin_unlock(&obd->obd_dev_lock);
541 CDEBUG(D_IOCTL, "finished setup of obd %s (uuid %s)\n",
542 obd->obd_name, obd->obd_uuid.uuid);
546 if (obd->obd_uuid_hash) {
547 cfs_hash_putref(obd->obd_uuid_hash);
548 obd->obd_uuid_hash = NULL;
550 if (obd->obd_nid_hash) {
551 cfs_hash_putref(obd->obd_nid_hash);
552 obd->obd_nid_hash = NULL;
554 if (obd->obd_nid_stats_hash) {
555 cfs_hash_putref(obd->obd_nid_stats_hash);
556 obd->obd_nid_stats_hash = NULL;
558 if (obd->obd_gen_hash) {
559 cfs_hash_putref(obd->obd_gen_hash);
560 obd->obd_gen_hash = NULL;
562 obd->obd_starting = 0;
563 CERROR("setup %s failed (%d)\n", obd->obd_name, err);
566 EXPORT_SYMBOL(class_setup);
568 /** We have finished using this obd and are ready to destroy it.
569 * There can be no more references to this obd.
571 int class_detach(struct obd_device *obd, struct lustre_cfg *lcfg)
575 if (obd->obd_set_up) {
576 CERROR("OBD device %d still set up\n", obd->obd_minor);
580 spin_lock(&obd->obd_dev_lock);
581 if (!obd->obd_attached) {
582 spin_unlock(&obd->obd_dev_lock);
583 CERROR("OBD device %d not attached\n", obd->obd_minor);
586 obd->obd_attached = 0;
587 spin_unlock(&obd->obd_dev_lock);
589 /* cleanup in progress. we don't like to find this device after now */
590 class_unregister_device(obd);
592 CDEBUG(D_IOCTL, "detach on obd %s (uuid %s)\n",
593 obd->obd_name, obd->obd_uuid.uuid);
595 class_decref(obd, "newdev", obd);
599 EXPORT_SYMBOL(class_detach);
601 /** Start shutting down the obd. There may be in-progess ops when
602 * this is called. We tell them to start shutting down with a call
603 * to class_disconnect_exports().
605 int class_cleanup(struct obd_device *obd, struct lustre_cfg *lcfg)
611 OBD_RACE(OBD_FAIL_LDLM_RECOV_CLIENTS);
613 if (!obd->obd_set_up) {
614 CERROR("Device %d not setup\n", obd->obd_minor);
618 spin_lock(&obd->obd_dev_lock);
619 if (obd->obd_stopping) {
620 spin_unlock(&obd->obd_dev_lock);
621 CERROR("OBD %d already stopping\n", obd->obd_minor);
624 /* Leave this on forever */
625 obd->obd_stopping = 1;
626 /* function can't return error after that point, so clear setup flag
627 * as early as possible to avoid finding via obd_devs / hash */
629 spin_unlock(&obd->obd_dev_lock);
631 /* wait for already-arrived-connections to finish. */
632 while (obd->obd_conn_inprogress > 0)
636 if (lcfg->lcfg_bufcount >= 2 && LUSTRE_CFG_BUFLEN(lcfg, 1) > 0) {
637 for (flag = lustre_cfg_string(lcfg, 1); *flag != 0; flag++)
643 LCONSOLE_WARN("Failing over %s\n",
646 obd->obd_no_transno = 1;
647 obd->obd_no_recov = 1;
648 if (OBP(obd, iocontrol)) {
649 obd_iocontrol(OBD_IOC_SYNC,
650 obd->obd_self_export,
655 CERROR("Unrecognised flag '%c'\n", *flag);
659 LASSERT(obd->obd_self_export);
661 CDEBUG(D_IOCTL, "%s: forcing exports to disconnect: %d/%d\n",
662 obd->obd_name, obd->obd_num_exports,
663 atomic_read(&obd->obd_refcount) - 2);
664 dump_exports(obd, 0, D_HA);
665 class_disconnect_exports(obd);
667 /* Precleanup, we must make sure all exports get destroyed. */
668 err = obd_precleanup(obd);
670 CERROR("Precleanup %s returned %d\n",
673 /* destroy an uuid-export hash body */
674 if (obd->obd_uuid_hash) {
675 cfs_hash_putref(obd->obd_uuid_hash);
676 obd->obd_uuid_hash = NULL;
679 /* destroy a nid-export hash body */
680 if (obd->obd_nid_hash) {
681 cfs_hash_putref(obd->obd_nid_hash);
682 obd->obd_nid_hash = NULL;
685 /* destroy a nid-stats hash body */
686 if (obd->obd_nid_stats_hash) {
687 cfs_hash_putref(obd->obd_nid_stats_hash);
688 obd->obd_nid_stats_hash = NULL;
691 /* destroy a client_generation-export hash body */
692 if (obd->obd_gen_hash) {
693 cfs_hash_putref(obd->obd_gen_hash);
694 obd->obd_gen_hash = NULL;
697 class_decref(obd, "setup", obd);
703 struct obd_device *class_incref(struct obd_device *obd,
704 const char *scope, const void *source)
706 lu_ref_add_atomic(&obd->obd_reference, scope, source);
707 atomic_inc(&obd->obd_refcount);
708 CDEBUG(D_INFO, "incref %s (%p) now %d\n", obd->obd_name, obd,
709 atomic_read(&obd->obd_refcount));
713 EXPORT_SYMBOL(class_incref);
715 void class_decref(struct obd_device *obd, const char *scope, const void *source)
719 CDEBUG(D_INFO, "Decref %s (%p) now %d - %s\n", obd->obd_name, obd,
720 atomic_read(&obd->obd_refcount), scope);
722 LASSERT(obd->obd_num_exports >= 0);
723 last = atomic_dec_and_test(&obd->obd_refcount);
724 lu_ref_del(&obd->obd_reference, scope, source);
727 struct obd_export *exp;
729 LASSERT(!obd->obd_attached);
730 /* All exports have been destroyed; there should
731 * be no more in-progress ops by this point.*/
732 exp = obd->obd_self_export;
735 exp->exp_flags |= exp_flags_from_obd(obd);
737 * note that we'll recurse into class_decref again
738 * but it's not a problem because we was last user
740 class_unlink_export(exp);
744 EXPORT_SYMBOL(class_decref);
746 /** Add a failover nid location.
747 * Client obd types contact server obd types using this nid list.
749 int class_add_conn(struct obd_device *obd, struct lustre_cfg *lcfg)
751 struct obd_import *imp;
752 struct obd_uuid uuid;
756 if (LUSTRE_CFG_BUFLEN(lcfg, 1) < 1 ||
757 LUSTRE_CFG_BUFLEN(lcfg, 1) > sizeof(struct obd_uuid)) {
758 CERROR("invalid conn_uuid\n");
761 if (strcmp(obd->obd_type->typ_name, LUSTRE_MDC_NAME) &&
762 strcmp(obd->obd_type->typ_name, LUSTRE_OSC_NAME) &&
763 strcmp(obd->obd_type->typ_name, LUSTRE_OSP_NAME) &&
764 strcmp(obd->obd_type->typ_name, LUSTRE_LWP_NAME) &&
765 strcmp(obd->obd_type->typ_name, LUSTRE_MGC_NAME)) {
766 CERROR("can't add connection on non-client dev\n");
770 imp = obd->u.cli.cl_import;
772 CERROR("try to add conn on immature client dev\n");
776 obd_str2uuid(&uuid, lustre_cfg_string(lcfg, 1));
777 rc = obd_add_conn(imp, &uuid, lcfg->lcfg_num);
782 /** Remove a failover nid location.
784 static int class_del_conn(struct obd_device *obd, struct lustre_cfg *lcfg)
786 struct obd_import *imp;
787 struct obd_uuid uuid;
791 if (LUSTRE_CFG_BUFLEN(lcfg, 1) < 1 ||
792 LUSTRE_CFG_BUFLEN(lcfg, 1) > sizeof(struct obd_uuid)) {
793 CERROR("invalid conn_uuid\n");
796 if (strcmp(obd->obd_type->typ_name, LUSTRE_MDC_NAME) &&
797 strcmp(obd->obd_type->typ_name, LUSTRE_OSC_NAME)) {
798 CERROR("can't del connection on non-client dev\n");
802 imp = obd->u.cli.cl_import;
804 CERROR("try to del conn on immature client dev\n");
808 obd_str2uuid(&uuid, lustre_cfg_string(lcfg, 1));
809 rc = obd_del_conn(imp, &uuid);
814 static LIST_HEAD(lustre_profile_list);
815 static DEFINE_SPINLOCK(lustre_profile_list_lock);
817 struct lustre_profile *class_get_profile(const char * prof)
819 struct lustre_profile *lprof;
822 spin_lock(&lustre_profile_list_lock);
823 list_for_each_entry(lprof, &lustre_profile_list, lp_list) {
824 if (!strcmp(lprof->lp_profile, prof)) {
826 spin_unlock(&lustre_profile_list_lock);
830 spin_unlock(&lustre_profile_list_lock);
833 EXPORT_SYMBOL(class_get_profile);
835 /** Create a named "profile".
836 * This defines the mdc and osc names to use for a client.
837 * This also is used to define the lov to be used by a mdt.
839 static int class_add_profile(int proflen, char *prof, int osclen, char *osc,
840 int mdclen, char *mdc)
842 struct lustre_profile *lprof;
846 CDEBUG(D_CONFIG, "Add profile %s\n", prof);
848 OBD_ALLOC(lprof, sizeof(*lprof));
851 INIT_LIST_HEAD(&lprof->lp_list);
853 LASSERT(proflen == (strlen(prof) + 1));
854 OBD_ALLOC(lprof->lp_profile, proflen);
855 if (lprof->lp_profile == NULL)
856 GOTO(out, err = -ENOMEM);
857 memcpy(lprof->lp_profile, prof, proflen);
859 LASSERT(osclen == (strlen(osc) + 1));
860 OBD_ALLOC(lprof->lp_dt, osclen);
861 if (lprof->lp_dt == NULL)
862 GOTO(out, err = -ENOMEM);
863 memcpy(lprof->lp_dt, osc, osclen);
866 LASSERT(mdclen == (strlen(mdc) + 1));
867 OBD_ALLOC(lprof->lp_md, mdclen);
868 if (lprof->lp_md == NULL)
869 GOTO(out, err = -ENOMEM);
870 memcpy(lprof->lp_md, mdc, mdclen);
873 spin_lock(&lustre_profile_list_lock);
875 lprof->lp_list_deleted = false;
877 list_add(&lprof->lp_list, &lustre_profile_list);
878 spin_unlock(&lustre_profile_list_lock);
883 OBD_FREE(lprof->lp_md, mdclen);
885 OBD_FREE(lprof->lp_dt, osclen);
886 if (lprof->lp_profile)
887 OBD_FREE(lprof->lp_profile, proflen);
888 OBD_FREE(lprof, sizeof(*lprof));
892 void class_del_profile(const char *prof)
894 struct lustre_profile *lprof;
897 CDEBUG(D_CONFIG, "Del profile %s\n", prof);
899 lprof = class_get_profile(prof);
901 spin_lock(&lustre_profile_list_lock);
902 /* because get profile increments the ref counter */
904 list_del(&lprof->lp_list);
905 lprof->lp_list_deleted = true;
906 spin_unlock(&lustre_profile_list_lock);
908 class_put_profile(lprof);
912 EXPORT_SYMBOL(class_del_profile);
914 void class_put_profile(struct lustre_profile *lprof)
916 spin_lock(&lustre_profile_list_lock);
917 if ((--lprof->lp_refs) > 0) {
918 LASSERT(lprof->lp_refs > 0);
919 spin_unlock(&lustre_profile_list_lock);
922 spin_unlock(&lustre_profile_list_lock);
924 /* confirm not a negative number */
925 LASSERT(lprof->lp_refs == 0);
927 /* At least one class_del_profile/profiles must be called
928 * on the target profile or lustre_profile_list will corrupt */
929 LASSERT(lprof->lp_list_deleted);
930 OBD_FREE(lprof->lp_profile, strlen(lprof->lp_profile) + 1);
931 OBD_FREE(lprof->lp_dt, strlen(lprof->lp_dt) + 1);
932 if (lprof->lp_md != NULL)
933 OBD_FREE(lprof->lp_md, strlen(lprof->lp_md) + 1);
934 OBD_FREE(lprof, sizeof(*lprof));
936 EXPORT_SYMBOL(class_put_profile);
939 void class_del_profiles(void)
941 struct lustre_profile *lprof, *n;
944 spin_lock(&lustre_profile_list_lock);
945 list_for_each_entry_safe(lprof, n, &lustre_profile_list, lp_list) {
946 list_del(&lprof->lp_list);
947 lprof->lp_list_deleted = true;
948 spin_unlock(&lustre_profile_list_lock);
950 class_put_profile(lprof);
952 spin_lock(&lustre_profile_list_lock);
954 spin_unlock(&lustre_profile_list_lock);
957 EXPORT_SYMBOL(class_del_profiles);
959 static int class_set_global(char *ptr, int val, struct lustre_cfg *lcfg)
962 if (class_match_param(ptr, PARAM_AT_MIN, NULL) == 0)
964 else if (class_match_param(ptr, PARAM_AT_MAX, NULL) == 0)
966 else if (class_match_param(ptr, PARAM_AT_EXTRA, NULL) == 0)
968 else if (class_match_param(ptr, PARAM_AT_EARLY_MARGIN, NULL) == 0)
969 at_early_margin = val;
970 else if (class_match_param(ptr, PARAM_AT_HISTORY, NULL) == 0)
972 else if (class_match_param(ptr, PARAM_JOBID_VAR, NULL) == 0)
973 strlcpy(obd_jobid_var, lustre_cfg_string(lcfg, 2),
974 JOBSTATS_JOBID_VAR_MAX_LEN + 1);
978 CDEBUG(D_IOCTL, "global %s = %d\n", ptr, val);
983 /* We can't call ll_process_config or lquota_process_config directly because
984 * it lives in a module that must be loaded after this one. */
985 static int (*client_process_config)(struct lustre_cfg *lcfg) = NULL;
986 static int (*quota_process_config)(struct lustre_cfg *lcfg) = NULL;
988 void lustre_register_client_process_config(int (*cpc)(struct lustre_cfg *lcfg))
990 client_process_config = cpc;
992 EXPORT_SYMBOL(lustre_register_client_process_config);
995 * Rename the proc parameter in \a cfg with a new name \a new_name.
997 * \param cfg config structure which contains the proc parameter
998 * \param new_name new name of the proc parameter
1000 * \retval valid-pointer pointer to the newly-allocated config structure
1001 * which contains the renamed proc parameter
1002 * \retval ERR_PTR(-EINVAL) if \a cfg or \a new_name is NULL, or \a cfg does
1003 * not contain a proc parameter
1004 * \retval ERR_PTR(-ENOMEM) if memory allocation failure occurs
1006 struct lustre_cfg *lustre_cfg_rename(struct lustre_cfg *cfg,
1007 const char *new_name)
1009 struct lustre_cfg_bufs *bufs = NULL;
1010 struct lustre_cfg *new_cfg = NULL;
1012 char *new_param = NULL;
1018 if (!cfg || !new_name)
1019 GOTO(out_nocfg, new_cfg = ERR_PTR(-EINVAL));
1021 param = lustre_cfg_string(cfg, 1);
1023 GOTO(out_nocfg, new_cfg = ERR_PTR(-EINVAL));
1025 value = strchr(param, '=');
1027 name_len = strlen(param);
1029 name_len = value - param;
1031 new_len = LUSTRE_CFG_BUFLEN(cfg, 1) + strlen(new_name) - name_len;
1033 OBD_ALLOC(new_param, new_len);
1035 GOTO(out_nocfg, new_cfg = ERR_PTR(-ENOMEM));
1037 strcpy(new_param, new_name);
1039 strcat(new_param, value);
1041 OBD_ALLOC_PTR(bufs);
1043 GOTO(out_free_param, new_cfg = ERR_PTR(-ENOMEM));
1045 lustre_cfg_bufs_reset(bufs, NULL);
1046 lustre_cfg_bufs_init(bufs, cfg);
1047 lustre_cfg_bufs_set_string(bufs, 1, new_param);
1049 OBD_ALLOC(new_cfg, lustre_cfg_len(bufs->lcfg_bufcount,
1050 bufs->lcfg_buflen));
1052 GOTO(out_free_buf, new_cfg = ERR_PTR(-ENOMEM));
1054 lustre_cfg_init(new_cfg, cfg->lcfg_command, bufs);
1056 new_cfg->lcfg_num = cfg->lcfg_num;
1057 new_cfg->lcfg_flags = cfg->lcfg_flags;
1058 new_cfg->lcfg_nid = cfg->lcfg_nid;
1059 new_cfg->lcfg_nal = cfg->lcfg_nal;
1063 OBD_FREE(new_param, new_len);
1067 EXPORT_SYMBOL(lustre_cfg_rename);
1069 static int process_param2_config(struct lustre_cfg *lcfg)
1071 char *param = lustre_cfg_string(lcfg, 1);
1072 char *upcall = lustre_cfg_string(lcfg, 2);
1074 [0] = "/usr/sbin/lctl",
1084 /* Add upcall processing here. Now only lctl is supported */
1085 if (strcmp(upcall, LCTL_UPCALL) != 0) {
1086 CERROR("Unsupported upcall %s\n", upcall);
1090 start = ktime_get();
1091 rc = call_usermodehelper(argv[0], argv, NULL, UMH_WAIT_PROC);
1095 CERROR("lctl: error invoking upcall %s %s %s: rc = %d; "
1096 "time %ldus\n", argv[0], argv[1], argv[2], rc,
1097 (long)ktime_us_delta(end, start));
1099 CDEBUG(D_HA, "lctl: invoked upcall %s %s %s, time %ldus\n",
1100 argv[0], argv[1], argv[2],
1101 (long)ktime_us_delta(end, start));
1108 void lustre_register_quota_process_config(int (*qpc)(struct lustre_cfg *lcfg))
1110 quota_process_config = qpc;
1112 EXPORT_SYMBOL(lustre_register_quota_process_config);
1114 /** Process configuration commands given in lustre_cfg form.
1115 * These may come from direct calls (e.g. class_manual_cleanup)
1116 * or processing the config llog, or ioctl from lctl.
1118 int class_process_config(struct lustre_cfg *lcfg)
1120 struct obd_device *obd;
1123 LASSERT(lcfg && !IS_ERR(lcfg));
1124 CDEBUG(D_IOCTL, "processing cmd: %x\n", lcfg->lcfg_command);
1126 /* Commands that don't need a device */
1127 switch(lcfg->lcfg_command) {
1129 err = class_attach(lcfg);
1132 case LCFG_ADD_UUID: {
1133 CDEBUG(D_IOCTL, "adding mapping from uuid %s to nid %#llx"
1134 " (%s)\n", lustre_cfg_string(lcfg, 1),
1135 lcfg->lcfg_nid, libcfs_nid2str(lcfg->lcfg_nid));
1137 err = class_add_uuid(lustre_cfg_string(lcfg, 1), lcfg->lcfg_nid);
1140 case LCFG_DEL_UUID: {
1141 CDEBUG(D_IOCTL, "removing mappings for uuid %s\n",
1142 (lcfg->lcfg_bufcount < 2 || LUSTRE_CFG_BUFLEN(lcfg, 1) == 0)
1143 ? "<all uuids>" : lustre_cfg_string(lcfg, 1));
1145 err = class_del_uuid(lustre_cfg_string(lcfg, 1));
1148 case LCFG_MOUNTOPT: {
1149 CDEBUG(D_IOCTL, "mountopt: profile %s osc %s mdc %s\n",
1150 lustre_cfg_string(lcfg, 1),
1151 lustre_cfg_string(lcfg, 2),
1152 lustre_cfg_string(lcfg, 3));
1153 /* set these mount options somewhere, so ll_fill_super
1155 err = class_add_profile(LUSTRE_CFG_BUFLEN(lcfg, 1),
1156 lustre_cfg_string(lcfg, 1),
1157 LUSTRE_CFG_BUFLEN(lcfg, 2),
1158 lustre_cfg_string(lcfg, 2),
1159 LUSTRE_CFG_BUFLEN(lcfg, 3),
1160 lustre_cfg_string(lcfg, 3));
1163 case LCFG_DEL_MOUNTOPT: {
1164 CDEBUG(D_IOCTL, "mountopt: profile %s\n",
1165 lustre_cfg_string(lcfg, 1));
1166 class_del_profile(lustre_cfg_string(lcfg, 1));
1169 case LCFG_SET_TIMEOUT: {
1170 CDEBUG(D_IOCTL, "changing lustre timeout from %d to %d\n",
1171 obd_timeout, lcfg->lcfg_num);
1172 obd_timeout = max(lcfg->lcfg_num, 1U);
1173 obd_timeout_set = 1;
1176 case LCFG_SET_LDLM_TIMEOUT: {
1177 CDEBUG(D_IOCTL, "changing lustre ldlm_timeout from %d to %d\n",
1178 ldlm_timeout, lcfg->lcfg_num);
1179 ldlm_timeout = max(lcfg->lcfg_num, 1U);
1180 if (ldlm_timeout >= obd_timeout)
1181 ldlm_timeout = max(obd_timeout / 3, 1U);
1182 ldlm_timeout_set = 1;
1185 case LCFG_SET_UPCALL: {
1186 LCONSOLE_ERROR_MSG(0x15a, "recovery upcall is deprecated\n");
1187 /* COMPAT_146 Don't fail on old configs */
1191 struct cfg_marker *marker;
1192 marker = lustre_cfg_buf(lcfg, 1);
1193 CDEBUG(D_IOCTL, "marker %d (%#x) %.16s %s\n", marker->cm_step,
1194 marker->cm_flags, marker->cm_tgtname, marker->cm_comment);
1199 /* llite has no obd */
1200 if ((class_match_param(lustre_cfg_string(lcfg, 1),
1201 PARAM_LLITE, NULL) == 0) &&
1202 client_process_config) {
1203 err = (*client_process_config)(lcfg);
1205 } else if ((class_match_param(lustre_cfg_string(lcfg, 1),
1206 PARAM_SYS, &tmp) == 0)) {
1207 /* Global param settings */
1208 err = class_set_global(tmp, lcfg->lcfg_num, lcfg);
1210 * Client or server should not fail to mount if
1211 * it hits an unknown configuration parameter.
1214 CWARN("Ignoring unknown param %s\n", tmp);
1217 } else if ((class_match_param(lustre_cfg_string(lcfg, 1),
1218 PARAM_QUOTA, &tmp) == 0) &&
1219 quota_process_config) {
1220 err = (*quota_process_config)(lcfg);
1226 case LCFG_SET_PARAM: {
1227 err = process_param2_config(lcfg);
1231 /* Commands that require a device */
1232 obd = class_name2obd(lustre_cfg_string(lcfg, 0));
1234 if (!LUSTRE_CFG_BUFLEN(lcfg, 0))
1235 CERROR("this lcfg command requires a device name\n");
1237 CERROR("no device for: %s\n",
1238 lustre_cfg_string(lcfg, 0));
1240 GOTO(out, err = -EINVAL);
1243 switch(lcfg->lcfg_command) {
1245 err = class_setup(obd, lcfg);
1249 err = class_detach(obd, lcfg);
1252 case LCFG_CLEANUP: {
1253 err = class_cleanup(obd, lcfg);
1256 case LCFG_ADD_CONN: {
1257 err = class_add_conn(obd, lcfg);
1260 case LCFG_DEL_CONN: {
1261 err = class_del_conn(obd, lcfg);
1264 case LCFG_POOL_NEW: {
1265 err = obd_pool_new(obd, lustre_cfg_string(lcfg, 2));
1268 case LCFG_POOL_ADD: {
1269 err = obd_pool_add(obd, lustre_cfg_string(lcfg, 2),
1270 lustre_cfg_string(lcfg, 3));
1273 case LCFG_POOL_REM: {
1274 err = obd_pool_rem(obd, lustre_cfg_string(lcfg, 2),
1275 lustre_cfg_string(lcfg, 3));
1278 case LCFG_POOL_DEL: {
1279 err = obd_pool_del(obd, lustre_cfg_string(lcfg, 2));
1283 err = obd_process_config(obd, sizeof(*lcfg), lcfg);
1289 if ((err < 0) && !(lcfg->lcfg_command & LCFG_REQUIRED)) {
1290 CWARN("Ignoring error %d on optional command %#x\n", err,
1291 lcfg->lcfg_command);
1296 EXPORT_SYMBOL(class_process_config);
1298 int class_process_proc_param(char *prefix, struct lprocfs_vars *lvars,
1299 struct lustre_cfg *lcfg, void *data)
1301 struct lprocfs_vars *var;
1302 struct file fakefile;
1303 struct seq_file fake_seqfile;
1305 int i, keylen, vallen;
1306 int matched = 0, j = 0;
1311 if (lcfg->lcfg_command != LCFG_PARAM) {
1312 CERROR("Unknown command: %d\n", lcfg->lcfg_command);
1316 /* fake a seq file so that var->fops->write can work... */
1317 fakefile.private_data = &fake_seqfile;
1318 fake_seqfile.private = data;
1319 /* e.g. tunefs.lustre --param mdt.group_upcall=foo /r/tmp/lustre-mdt
1320 or lctl conf_param lustre-MDT0000.mdt.group_upcall=bar
1321 or lctl conf_param lustre-OST0000.osc.max_dirty_mb=36 */
1322 for (i = 1; i < lcfg->lcfg_bufcount; i++) {
1323 key = lustre_cfg_buf(lcfg, i);
1324 /* Strip off prefix */
1325 if (class_match_param(key, prefix, &key))
1326 /* If the prefix doesn't match, return error so we
1327 * can pass it down the stack */
1329 sval = strchr(key, '=');
1330 if (!sval || *(sval + 1) == 0) {
1331 CERROR("%s: can't parse param '%s' (missing '=')\n",
1332 lustre_cfg_string(lcfg, 0),
1333 lustre_cfg_string(lcfg, i));
1334 /* rc = -EINVAL; continue parsing other params */
1337 keylen = sval - key;
1339 vallen = strlen(sval);
1342 /* Search proc entries */
1343 while (lvars[j].name) {
1345 if (class_match_param(key, var->name, NULL) == 0 &&
1346 keylen == strlen(var->name)) {
1350 if (var->fops && var->fops->write) {
1354 rc = (var->fops->write)(&fakefile, sval,
1363 /* It was upgraded from old MDT/OST device,
1364 * ignore the obsolete "sec_level" parameter. */
1365 if (strncmp("sec_level", key, keylen) == 0)
1368 CERROR("%s: unknown config parameter '%s'\n",
1369 lustre_cfg_string(lcfg, 0),
1370 lustre_cfg_string(lcfg, i));
1371 /* rc = -EINVAL; continue parsing other params */
1373 } else if (rc < 0) {
1374 CERROR("%s: error writing parameter '%s': rc = %d\n",
1375 lustre_cfg_string(lcfg, 0), key, rc);
1378 CDEBUG(D_CONFIG, "%s: set parameter '%s'\n",
1379 lustre_cfg_string(lcfg, 0), key);
1389 EXPORT_SYMBOL(class_process_proc_param);
1392 * Supplemental functions for config logs, it allocates lustre_cfg
1393 * buffers plus initialized llog record header at the beginning.
1395 struct llog_cfg_rec *lustre_cfg_rec_new(int cmd, struct lustre_cfg_bufs *bufs)
1397 struct llog_cfg_rec *lcr;
1402 reclen = lustre_cfg_len(bufs->lcfg_bufcount, bufs->lcfg_buflen);
1403 reclen = llog_data_len(reclen) + sizeof(struct llog_rec_hdr) +
1404 sizeof(struct llog_rec_tail);
1406 OBD_ALLOC(lcr, reclen);
1410 lustre_cfg_init(&lcr->lcr_cfg, cmd, bufs);
1412 lcr->lcr_hdr.lrh_len = reclen;
1413 lcr->lcr_hdr.lrh_type = OBD_CFG_REC;
1417 EXPORT_SYMBOL(lustre_cfg_rec_new);
1419 void lustre_cfg_rec_free(struct llog_cfg_rec *lcr)
1422 OBD_FREE(lcr, lcr->lcr_hdr.lrh_len);
1425 EXPORT_SYMBOL(lustre_cfg_rec_free);
1427 /** Parse a configuration llog, doing various manipulations on them
1428 * for various reasons, (modifications for compatibility, skip obsolete
1429 * records, change uuids, etc), then class_process_config() resulting
1432 int class_config_llog_handler(const struct lu_env *env,
1433 struct llog_handle *handle,
1434 struct llog_rec_hdr *rec, void *data)
1436 struct config_llog_instance *cfg = data;
1437 int cfg_len = rec->lrh_len;
1438 char *cfg_buf = (char *) (rec + 1);
1442 /* class_config_dump_handler(handle, rec, data); */
1444 switch (rec->lrh_type) {
1446 struct lustre_cfg *lcfg, *lcfg_new;
1447 struct lustre_cfg_bufs bufs;
1448 char *inst_name = NULL;
1452 lcfg = (struct lustre_cfg *)cfg_buf;
1453 if (lcfg->lcfg_version == __swab32(LUSTRE_CFG_VERSION)) {
1454 lustre_swab_lustre_cfg(lcfg);
1458 rc = lustre_cfg_sanity_check(cfg_buf, cfg_len);
1462 /* Figure out config state info */
1463 if (lcfg->lcfg_command == LCFG_MARKER) {
1464 struct cfg_marker *marker = lustre_cfg_buf(lcfg, 1);
1465 lustre_swab_cfg_marker(marker, swab,
1466 LUSTRE_CFG_BUFLEN(lcfg, 1));
1467 CDEBUG(D_CONFIG, "Marker, inst_flg=%#x mark_flg=%#x\n",
1468 cfg->cfg_flags, marker->cm_flags);
1469 if (marker->cm_flags & CM_START) {
1470 /* all previous flags off */
1471 cfg->cfg_flags = CFG_F_MARKER;
1472 server_name2index(marker->cm_tgtname,
1473 &cfg->cfg_lwp_idx, NULL);
1474 if (marker->cm_flags & CM_SKIP) {
1475 cfg->cfg_flags |= CFG_F_SKIP;
1476 CDEBUG(D_CONFIG, "SKIP #%d\n",
1478 } else if ((marker->cm_flags & CM_EXCLUDE) ||
1480 lustre_check_exclusion(cfg->cfg_sb,
1481 marker->cm_tgtname))) {
1482 cfg->cfg_flags |= CFG_F_EXCLUDE;
1483 CDEBUG(D_CONFIG, "EXCLUDE %d\n",
1486 } else if (marker->cm_flags & CM_END) {
1490 /* A config command without a start marker before it is
1491 illegal (post 146) */
1492 if (!(cfg->cfg_flags & CFG_F_COMPAT146) &&
1493 !(cfg->cfg_flags & CFG_F_MARKER) &&
1494 (lcfg->lcfg_command != LCFG_MARKER)) {
1495 CWARN("Config not inside markers, ignoring! "
1496 "(inst: %p, uuid: %s, flags: %#x)\n",
1498 cfg->cfg_uuid.uuid, cfg->cfg_flags);
1499 cfg->cfg_flags |= CFG_F_SKIP;
1501 if (cfg->cfg_flags & CFG_F_SKIP) {
1502 CDEBUG(D_CONFIG, "skipping %#x\n",
1505 /* No processing! */
1510 * For interoperability between 1.8 and 2.0,
1511 * rename "mds" obd device type to "mdt".
1514 char *typename = lustre_cfg_string(lcfg, 1);
1515 char *index = lustre_cfg_string(lcfg, 2);
1517 if ((lcfg->lcfg_command == LCFG_ATTACH && typename &&
1518 strcmp(typename, "mds") == 0)) {
1519 CWARN("For 1.8 interoperability, rename obd "
1520 "type from mds to mdt\n");
1523 if ((lcfg->lcfg_command == LCFG_SETUP && index &&
1524 strcmp(index, "type") == 0)) {
1525 CDEBUG(D_INFO, "For 1.8 interoperability, "
1526 "set this index to '0'\n");
1532 #ifdef HAVE_SERVER_SUPPORT
1533 /* newer MDS replaces LOV/OSC with LOD/OSP */
1535 char *typename = lustre_cfg_string(lcfg, 1);
1537 if ((lcfg->lcfg_command == LCFG_ATTACH && typename &&
1538 strcmp(typename, LUSTRE_LOV_NAME) == 0) &&
1539 cfg->cfg_sb && IS_MDT(s2lsi(cfg->cfg_sb))) {
1541 "For 2.x interoperability, rename obd "
1542 "type from lov to lod (%s)\n",
1543 s2lsi(cfg->cfg_sb)->lsi_svname);
1544 strcpy(typename, LUSTRE_LOD_NAME);
1546 if ((lcfg->lcfg_command == LCFG_ATTACH && typename &&
1547 strcmp(typename, LUSTRE_OSC_NAME) == 0) &&
1548 cfg->cfg_sb && IS_MDT(s2lsi(cfg->cfg_sb))) {
1550 "For 2.x interoperability, rename obd "
1551 "type from osc to osp (%s)\n",
1552 s2lsi(cfg->cfg_sb)->lsi_svname);
1553 strcpy(typename, LUSTRE_OSP_NAME);
1556 #endif /* HAVE_SERVER_SUPPORT */
1558 if (cfg->cfg_flags & CFG_F_EXCLUDE) {
1559 CDEBUG(D_CONFIG, "cmd: %x marked EXCLUDED\n",
1560 lcfg->lcfg_command);
1561 if (lcfg->lcfg_command == LCFG_LOV_ADD_OBD)
1562 /* Add inactive instead */
1563 lcfg->lcfg_command = LCFG_LOV_ADD_INA;
1566 lustre_cfg_bufs_reset(&bufs, NULL);
1567 lustre_cfg_bufs_init(&bufs, lcfg);
1569 if (cfg->cfg_instance &&
1570 LUSTRE_CFG_BUFLEN(lcfg, 0) > 0) {
1571 inst_len = LUSTRE_CFG_BUFLEN(lcfg, 0) +
1572 sizeof(cfg->cfg_instance) * 2 + 4;
1573 OBD_ALLOC(inst_name, inst_len);
1574 if (inst_name == NULL)
1575 GOTO(out, rc = -ENOMEM);
1576 snprintf(inst_name, inst_len, "%s-%p",
1577 lustre_cfg_string(lcfg, 0),
1579 lustre_cfg_bufs_set_string(&bufs, 0, inst_name);
1580 CDEBUG(D_CONFIG, "cmd %x, instance name: %s\n",
1581 lcfg->lcfg_command, inst_name);
1584 /* we override the llog's uuid for clients, to insure they
1586 if (cfg->cfg_instance != NULL &&
1587 lcfg->lcfg_command == LCFG_ATTACH) {
1588 lustre_cfg_bufs_set_string(&bufs, 2,
1589 cfg->cfg_uuid.uuid);
1592 * sptlrpc config record, we expect 2 data segments:
1593 * [0]: fs_name/target_name,
1595 * moving them to index [1] and [2], and insert MGC's
1596 * obdname at index [0].
1598 if (cfg->cfg_instance == NULL &&
1599 lcfg->lcfg_command == LCFG_SPTLRPC_CONF) {
1600 lustre_cfg_bufs_set(&bufs, 2, bufs.lcfg_buf[1],
1601 bufs.lcfg_buflen[1]);
1602 lustre_cfg_bufs_set(&bufs, 1, bufs.lcfg_buf[0],
1603 bufs.lcfg_buflen[0]);
1604 lustre_cfg_bufs_set_string(&bufs, 0,
1608 /* Add net info to setup command
1609 * if given on command line.
1610 * So config log will be:
1614 * [3]: inactive-on-startup
1615 * [4]: restrictive net
1617 if (cfg && cfg->cfg_sb && s2lsi(cfg->cfg_sb) &&
1618 !IS_SERVER(s2lsi(cfg->cfg_sb))) {
1619 struct lustre_sb_info *lsi = s2lsi(cfg->cfg_sb);
1620 char *nidnet = lsi->lsi_lmd->lmd_nidnet;
1622 if (lcfg->lcfg_command == LCFG_SETUP &&
1623 lcfg->lcfg_bufcount != 2 && nidnet) {
1624 CDEBUG(D_CONFIG, "Adding net %s info to setup "
1625 "command for client %s\n", nidnet,
1626 lustre_cfg_string(lcfg, 0));
1627 lustre_cfg_bufs_set_string(&bufs, 4, nidnet);
1631 /* Skip add_conn command if uuid is
1632 * not on restricted net */
1633 if (cfg && cfg->cfg_sb && s2lsi(cfg->cfg_sb) &&
1634 !IS_SERVER(s2lsi(cfg->cfg_sb))) {
1635 struct lustre_sb_info *lsi = s2lsi(cfg->cfg_sb);
1636 char *uuid_str = lustre_cfg_string(lcfg, 1);
1638 if (lcfg->lcfg_command == LCFG_ADD_CONN &&
1639 lsi->lsi_lmd->lmd_nidnet &&
1640 LNET_NIDNET(libcfs_str2nid(uuid_str)) !=
1641 libcfs_str2net(lsi->lsi_lmd->lmd_nidnet)) {
1642 CDEBUG(D_CONFIG, "skipping add_conn for %s\n",
1645 /* No processing! */
1650 OBD_ALLOC(lcfg_new, lustre_cfg_len(bufs.lcfg_bufcount,
1653 GOTO(out, rc = -ENOMEM);
1655 lustre_cfg_init(lcfg_new, lcfg->lcfg_command, &bufs);
1656 lcfg_new->lcfg_num = lcfg->lcfg_num;
1657 lcfg_new->lcfg_flags = lcfg->lcfg_flags;
1659 /* XXX Hack to try to remain binary compatible with
1660 * pre-newconfig logs */
1661 if (lcfg->lcfg_nal != 0 && /* pre-newconfig log? */
1662 (lcfg->lcfg_nid >> 32) == 0) {
1663 __u32 addr = (__u32)(lcfg->lcfg_nid & 0xffffffff);
1665 lcfg_new->lcfg_nid =
1666 LNET_MKNID(LNET_MKNET(lcfg->lcfg_nal, 0), addr);
1667 CWARN("Converted pre-newconfig NAL %d NID %x to %s\n",
1668 lcfg->lcfg_nal, addr,
1669 libcfs_nid2str(lcfg_new->lcfg_nid));
1671 lcfg_new->lcfg_nid = lcfg->lcfg_nid;
1674 lcfg_new->lcfg_nal = 0; /* illegal value for obsolete field */
1676 rc = class_process_config(lcfg_new);
1677 OBD_FREE(lcfg_new, lustre_cfg_len(lcfg_new->lcfg_bufcount,
1678 lcfg_new->lcfg_buflens));
1680 OBD_FREE(inst_name, inst_len);
1684 CERROR("Unknown llog record type %#x encountered\n",
1690 CERROR("%s: cfg command failed: rc = %d\n",
1691 handle->lgh_ctxt->loc_obd->obd_name, rc);
1692 class_config_dump_handler(NULL, handle, rec, data);
1696 EXPORT_SYMBOL(class_config_llog_handler);
1698 int class_config_parse_llog(const struct lu_env *env, struct llog_ctxt *ctxt,
1699 char *name, struct config_llog_instance *cfg)
1701 struct llog_process_cat_data cd = {
1702 .lpcd_first_idx = 0,
1704 struct llog_handle *llh;
1709 CDEBUG(D_INFO, "looking up llog %s\n", name);
1710 rc = llog_open(env, ctxt, &llh, NULL, name, LLOG_OPEN_EXISTS);
1714 rc = llog_init_handle(env, llh, LLOG_F_IS_PLAIN, NULL);
1716 GOTO(parse_out, rc);
1718 /* continue processing from where we last stopped to end-of-log */
1720 cd.lpcd_first_idx = cfg->cfg_last_idx;
1721 callback = cfg->cfg_callback;
1722 LASSERT(callback != NULL);
1724 callback = class_config_llog_handler;
1727 cd.lpcd_last_idx = 0;
1729 rc = llog_process(env, llh, callback, cfg, &cd);
1731 CDEBUG(D_CONFIG, "Processed log %s gen %d-%d (rc=%d)\n", name,
1732 cd.lpcd_first_idx + 1, cd.lpcd_last_idx, rc);
1734 cfg->cfg_last_idx = cd.lpcd_last_idx;
1737 llog_close(env, llh);
1740 EXPORT_SYMBOL(class_config_parse_llog);
1742 static struct lcfg_type_data {
1746 } lcfg_data_table[] = {
1747 { LCFG_ATTACH, "attach", { "type", "UUID", "3", "4" } },
1748 { LCFG_DETACH, "detach", { "1", "2", "3", "4" } },
1749 { LCFG_SETUP, "setup", { "UUID", "node", "options", "failout" } },
1750 { LCFG_CLEANUP, "cleanup", { "1", "2", "3", "4" } },
1751 { LCFG_ADD_UUID, "add_uuid", { "node", "2", "3", "4" } },
1752 { LCFG_DEL_UUID, "del_uuid", { "1", "2", "3", "4" } },
1753 { LCFG_MOUNTOPT, "new_profile", { "name", "lov", "lmv", "4" } },
1754 { LCFG_DEL_MOUNTOPT, "del_mountopt", { "1", "2", "3", "4" } , },
1755 { LCFG_SET_TIMEOUT, "set_timeout", { "parameter", "2", "3", "4" } },
1756 { LCFG_SET_UPCALL, "set_upcall", { "1", "2", "3", "4" } },
1757 { LCFG_ADD_CONN, "add_conn", { "node", "2", "3", "4" } },
1758 { LCFG_DEL_CONN, "del_conn", { "1", "2", "3", "4" } },
1759 { LCFG_LOV_ADD_OBD, "add_osc", { "ost", "index", "gen", "UUID" } },
1760 { LCFG_LOV_DEL_OBD, "del_osc", { "1", "2", "3", "4" } },
1761 { LCFG_PARAM, "set_param", { "parameter", "value", "3", "4" } },
1762 { LCFG_MARKER, "marker", { "1", "2", "3", "4" } },
1763 { LCFG_LOG_START, "log_start", { "1", "2", "3", "4" } },
1764 { LCFG_LOG_END, "log_end", { "1", "2", "3", "4" } },
1765 { LCFG_LOV_ADD_INA, "add_osc_inactive", { "1", "2", "3", "4" } },
1766 { LCFG_ADD_MDC, "add_mdc", { "mdt", "index", "gen", "UUID" } },
1767 { LCFG_DEL_MDC, "del_mdc", { "1", "2", "3", "4" } },
1768 { LCFG_SPTLRPC_CONF, "security", { "parameter", "2", "3", "4" } },
1769 { LCFG_POOL_NEW, "new_pool", { "fsname", "pool", "3", "4" } },
1770 { LCFG_POOL_ADD, "add_pool", { "fsname", "pool", "ost", "4" } },
1771 { LCFG_POOL_REM, "remove_pool", { "fsname", "pool", "ost", "4" } },
1772 { LCFG_POOL_DEL, "del_pool", { "fsname", "pool", "3", "4" } },
1773 { LCFG_SET_LDLM_TIMEOUT, "set_ldlm_timeout",
1774 { "parameter", "2", "3", "4" } },
1775 { 0, NULL, { NULL, NULL, NULL, NULL } }
1778 static struct lcfg_type_data *lcfg_cmd2data(__u32 cmd)
1782 while (lcfg_data_table[i].ltd_type != 0) {
1783 if (lcfg_data_table[i].ltd_type == cmd)
1784 return &lcfg_data_table[i];
1791 * Parse config record and output dump in supplied buffer.
1793 * This is separated from class_config_dump_handler() to use
1794 * for ioctl needs as well
1797 * - { index: 4, event: attach, device: lustrewt-clilov, type: lov,
1798 * UUID: lustrewt-clilov_UUID }
1800 int class_config_yaml_output(struct llog_rec_hdr *rec, char *buf, int size)
1802 struct lustre_cfg *lcfg = (struct lustre_cfg *)(rec + 1);
1804 char *end = buf + size;
1806 struct lcfg_type_data *ldata;
1808 LASSERT(rec->lrh_type == OBD_CFG_REC);
1809 rc = lustre_cfg_sanity_check(lcfg, rec->lrh_len);
1813 ldata = lcfg_cmd2data(lcfg->lcfg_command);
1817 if (lcfg->lcfg_command == LCFG_MARKER)
1820 /* form YAML entity */
1821 ptr += snprintf(ptr, end - ptr, "- { index: %u, event: %s",
1822 rec->lrh_index, ldata->ltd_name);
1824 if (lcfg->lcfg_flags)
1825 ptr += snprintf(ptr, end - ptr, ", flags: %#08x",
1828 ptr += snprintf(ptr, end - ptr, ", num: %#08x",
1830 if (lcfg->lcfg_nid) {
1831 char nidstr[LNET_NIDSTR_SIZE];
1833 libcfs_nid2str_r(lcfg->lcfg_nid, nidstr, sizeof(nidstr));
1834 ptr += snprintf(ptr, end - ptr, ", nid: %s(%#llx)",
1835 nidstr, lcfg->lcfg_nid);
1838 if (LUSTRE_CFG_BUFLEN(lcfg, 0) > 0)
1839 ptr += snprintf(ptr, end - ptr, ", device: %s",
1840 lustre_cfg_string(lcfg, 0));
1842 for (i = 1; i < lcfg->lcfg_bufcount; i++) {
1843 if (LUSTRE_CFG_BUFLEN(lcfg, i) > 0)
1844 ptr += snprintf(ptr, end - ptr, ", %s: %s",
1845 ldata->ltd_bufs[i - 1],
1846 lustre_cfg_string(lcfg, i));
1849 ptr += snprintf(ptr, end - ptr, " }\n");
1850 /* return consumed bytes */
1856 * parse config record and output dump in supplied buffer.
1857 * This is separated from class_config_dump_handler() to use
1858 * for ioctl needs as well
1860 static int class_config_parse_rec(struct llog_rec_hdr *rec, char *buf, int size)
1862 struct lustre_cfg *lcfg = (struct lustre_cfg *)(rec + 1);
1864 char *end = buf + size;
1869 LASSERT(rec->lrh_type == OBD_CFG_REC);
1870 rc = lustre_cfg_sanity_check(lcfg, rec->lrh_len);
1874 ptr += snprintf(ptr, end-ptr, "cmd=%05x ", lcfg->lcfg_command);
1875 if (lcfg->lcfg_flags)
1876 ptr += snprintf(ptr, end-ptr, "flags=%#08x ",
1880 ptr += snprintf(ptr, end-ptr, "num=%#08x ", lcfg->lcfg_num);
1882 if (lcfg->lcfg_nid) {
1883 char nidstr[LNET_NIDSTR_SIZE];
1885 libcfs_nid2str_r(lcfg->lcfg_nid, nidstr, sizeof(nidstr));
1886 ptr += snprintf(ptr, end-ptr, "nid=%s(%#llx)\n ",
1887 nidstr, lcfg->lcfg_nid);
1890 if (lcfg->lcfg_command == LCFG_MARKER) {
1891 struct cfg_marker *marker = lustre_cfg_buf(lcfg, 1);
1893 ptr += snprintf(ptr, end-ptr, "marker=%d(%#x)%s '%s'",
1894 marker->cm_step, marker->cm_flags,
1895 marker->cm_tgtname, marker->cm_comment);
1899 for (i = 0; i < lcfg->lcfg_bufcount; i++) {
1900 ptr += snprintf(ptr, end-ptr, "%d:%s ", i,
1901 lustre_cfg_string(lcfg, i));
1904 ptr += snprintf(ptr, end - ptr, "\n");
1905 /* return consumed bytes */
1910 int class_config_dump_handler(const struct lu_env *env,
1911 struct llog_handle *handle,
1912 struct llog_rec_hdr *rec, void *data)
1919 OBD_ALLOC(outstr, 256);
1923 if (rec->lrh_type == OBD_CFG_REC) {
1924 class_config_parse_rec(rec, outstr, 256);
1925 LCONSOLE(D_WARNING, " %s\n", outstr);
1927 LCONSOLE(D_WARNING, "unhandled lrh_type: %#x\n", rec->lrh_type);
1931 OBD_FREE(outstr, 256);
1935 /** Call class_cleanup and class_detach.
1936 * "Manual" only in the sense that we're faking lcfg commands.
1938 int class_manual_cleanup(struct obd_device *obd)
1941 struct lustre_cfg *lcfg;
1942 struct lustre_cfg_bufs bufs;
1947 CERROR("empty cleanup\n");
1956 CDEBUG(D_CONFIG, "Manual cleanup of %s (flags='%s')\n",
1957 obd->obd_name, flags);
1959 lustre_cfg_bufs_reset(&bufs, obd->obd_name);
1960 lustre_cfg_bufs_set_string(&bufs, 1, flags);
1961 OBD_ALLOC(lcfg, lustre_cfg_len(bufs.lcfg_bufcount, bufs.lcfg_buflen));
1964 lustre_cfg_init(lcfg, LCFG_CLEANUP, &bufs);
1966 rc = class_process_config(lcfg);
1968 CERROR("cleanup failed %d: %s\n", rc, obd->obd_name);
1972 /* the lcfg is almost the same for both ops */
1973 lcfg->lcfg_command = LCFG_DETACH;
1974 rc = class_process_config(lcfg);
1976 CERROR("detach failed %d: %s\n", rc, obd->obd_name);
1978 OBD_FREE(lcfg, lustre_cfg_len(lcfg->lcfg_bufcount, lcfg->lcfg_buflens));
1981 EXPORT_SYMBOL(class_manual_cleanup);
1984 * uuid<->export lustre hash operations
1988 uuid_hash(struct cfs_hash *hs, const void *key, unsigned mask)
1990 return cfs_hash_djb2_hash(((struct obd_uuid *)key)->uuid,
1991 sizeof(((struct obd_uuid *)key)->uuid), mask);
1995 uuid_key(struct hlist_node *hnode)
1997 struct obd_export *exp;
1999 exp = hlist_entry(hnode, struct obd_export, exp_uuid_hash);
2001 return &exp->exp_client_uuid;
2005 * NOTE: It is impossible to find an export that is in failed
2006 * state with this function
2009 uuid_keycmp(const void *key, struct hlist_node *hnode)
2011 struct obd_export *exp;
2014 exp = hlist_entry(hnode, struct obd_export, exp_uuid_hash);
2016 return obd_uuid_equals(key, &exp->exp_client_uuid) &&
2021 uuid_export_object(struct hlist_node *hnode)
2023 return hlist_entry(hnode, struct obd_export, exp_uuid_hash);
2027 uuid_export_get(struct cfs_hash *hs, struct hlist_node *hnode)
2029 struct obd_export *exp;
2031 exp = hlist_entry(hnode, struct obd_export, exp_uuid_hash);
2032 class_export_get(exp);
2036 uuid_export_put_locked(struct cfs_hash *hs, struct hlist_node *hnode)
2038 struct obd_export *exp;
2040 exp = hlist_entry(hnode, struct obd_export, exp_uuid_hash);
2041 class_export_put(exp);
2044 static struct cfs_hash_ops uuid_hash_ops = {
2045 .hs_hash = uuid_hash,
2047 .hs_keycmp = uuid_keycmp,
2048 .hs_object = uuid_export_object,
2049 .hs_get = uuid_export_get,
2050 .hs_put_locked = uuid_export_put_locked,
2055 * nid<->export hash operations
2059 nid_hash(struct cfs_hash *hs, const void *key, unsigned mask)
2061 return cfs_hash_djb2_hash(key, sizeof(lnet_nid_t), mask);
2065 nid_key(struct hlist_node *hnode)
2067 struct obd_export *exp;
2069 exp = hlist_entry(hnode, struct obd_export, exp_nid_hash);
2071 RETURN(&exp->exp_connection->c_peer.nid);
2075 * NOTE: It is impossible to find an export that is in failed
2076 * state with this function
2079 nid_kepcmp(const void *key, struct hlist_node *hnode)
2081 struct obd_export *exp;
2084 exp = hlist_entry(hnode, struct obd_export, exp_nid_hash);
2086 RETURN(exp->exp_connection->c_peer.nid == *(lnet_nid_t *)key &&
2091 nid_export_object(struct hlist_node *hnode)
2093 return hlist_entry(hnode, struct obd_export, exp_nid_hash);
2097 nid_export_get(struct cfs_hash *hs, struct hlist_node *hnode)
2099 struct obd_export *exp;
2101 exp = hlist_entry(hnode, struct obd_export, exp_nid_hash);
2102 class_export_get(exp);
2106 nid_export_put_locked(struct cfs_hash *hs, struct hlist_node *hnode)
2108 struct obd_export *exp;
2110 exp = hlist_entry(hnode, struct obd_export, exp_nid_hash);
2111 class_export_put(exp);
2114 static struct cfs_hash_ops nid_hash_ops = {
2115 .hs_hash = nid_hash,
2117 .hs_keycmp = nid_kepcmp,
2118 .hs_object = nid_export_object,
2119 .hs_get = nid_export_get,
2120 .hs_put_locked = nid_export_put_locked,
2125 * nid<->nidstats hash operations
2129 nidstats_key(struct hlist_node *hnode)
2131 struct nid_stat *ns;
2133 ns = hlist_entry(hnode, struct nid_stat, nid_hash);
2139 nidstats_keycmp(const void *key, struct hlist_node *hnode)
2141 return *(lnet_nid_t *)nidstats_key(hnode) == *(lnet_nid_t *)key;
2145 nidstats_object(struct hlist_node *hnode)
2147 return hlist_entry(hnode, struct nid_stat, nid_hash);
2151 nidstats_get(struct cfs_hash *hs, struct hlist_node *hnode)
2153 struct nid_stat *ns;
2155 ns = hlist_entry(hnode, struct nid_stat, nid_hash);
2160 nidstats_put_locked(struct cfs_hash *hs, struct hlist_node *hnode)
2162 struct nid_stat *ns;
2164 ns = hlist_entry(hnode, struct nid_stat, nid_hash);
2168 static struct cfs_hash_ops nid_stat_hash_ops = {
2169 .hs_hash = nid_hash,
2170 .hs_key = nidstats_key,
2171 .hs_keycmp = nidstats_keycmp,
2172 .hs_object = nidstats_object,
2173 .hs_get = nidstats_get,
2174 .hs_put_locked = nidstats_put_locked,
2179 * client_generation<->export hash operations
2183 gen_hash(struct cfs_hash *hs, const void *key, unsigned mask)
2185 return cfs_hash_djb2_hash(key, sizeof(__u32), mask);
2189 gen_key(struct hlist_node *hnode)
2191 struct obd_export *exp;
2193 exp = hlist_entry(hnode, struct obd_export, exp_gen_hash);
2195 RETURN(&exp->exp_target_data.ted_lcd->lcd_generation);
2199 * NOTE: It is impossible to find an export that is in failed
2200 * state with this function
2203 gen_kepcmp(const void *key, struct hlist_node *hnode)
2205 struct obd_export *exp;
2208 exp = hlist_entry(hnode, struct obd_export, exp_gen_hash);
2210 RETURN(exp->exp_target_data.ted_lcd->lcd_generation == *(__u32 *)key &&
2215 gen_export_object(struct hlist_node *hnode)
2217 return hlist_entry(hnode, struct obd_export, exp_gen_hash);
2221 gen_export_get(struct cfs_hash *hs, struct hlist_node *hnode)
2223 struct obd_export *exp;
2225 exp = hlist_entry(hnode, struct obd_export, exp_gen_hash);
2226 class_export_get(exp);
2230 gen_export_put_locked(struct cfs_hash *hs, struct hlist_node *hnode)
2232 struct obd_export *exp;
2234 exp = hlist_entry(hnode, struct obd_export, exp_gen_hash);
2235 class_export_put(exp);
2238 static struct cfs_hash_ops gen_hash_ops = {
2239 .hs_hash = gen_hash,
2241 .hs_keycmp = gen_kepcmp,
2242 .hs_object = gen_export_object,
2243 .hs_get = gen_export_get,
2244 .hs_put_locked = gen_export_put_locked,