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.sun.com/software/products/lustre/docs/GPLv2.pdf
20 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
21 * CA 95054 USA or visit www.sun.com if you need additional information or
27 * Copyright (c) 2003, 2010, Oracle and/or its affiliates. All rights reserved.
28 * Use is subject to license terms.
30 * Copyright (c) 2011, 2015, Intel Corporation.
33 * This file is part of Lustre, http://www.lustre.org/
34 * Lustre is a trademark of Sun Microsystems, Inc.
36 * lustre/obdclass/obd_config.c
41 #define DEBUG_SUBSYSTEM S_CLASS
42 #include "../include/obd_class.h"
43 #include <linux/string.h>
44 #include "../include/lustre_log.h"
45 #include "../include/lprocfs_status.h"
46 #include "../include/lustre_param.h"
48 #include "llog_internal.h"
50 static struct cfs_hash_ops uuid_hash_ops;
52 /*********** string parsing utils *********/
54 /* returns 0 if we find this key in the buffer, else 1 */
55 int class_find_param(char *buf, char *key, char **valp)
62 ptr = strstr(buf, key);
67 *valp = ptr + strlen(key);
71 EXPORT_SYMBOL(class_find_param);
73 /* returns 0 if this is the first key in the buffer, else 1.
74 valp points to first char after key. */
75 static int class_match_param(char *buf, const char *key, char **valp)
80 if (memcmp(buf, key, strlen(key)) != 0)
84 *valp = buf + strlen(key);
89 static int parse_nid(char *buf, void *value, int quiet)
91 lnet_nid_t *nid = value;
93 *nid = libcfs_str2nid(buf);
94 if (*nid != LNET_NID_ANY)
98 LCONSOLE_ERROR_MSG(0x159, "Can't parse NID '%s'\n", buf);
102 static int parse_net(char *buf, void *value)
106 *net = libcfs_str2net(buf);
107 CDEBUG(D_INFO, "Net %s\n", libcfs_net2str(*net));
119 endh is set to next separator */
120 static int class_parse_value(char *buf, int opc, void *value, char **endh,
129 while (*buf == ',' || *buf == ':')
131 if (*buf == ' ' || *buf == '/' || *buf == '\0')
134 /* nid separators or end of nids */
135 endp = strpbrk(buf, ",: /");
137 endp = buf + strlen(buf);
144 case CLASS_PARSE_NID:
145 rc = parse_nid(buf, value, quiet);
147 case CLASS_PARSE_NET:
148 rc = parse_net(buf, value);
159 int class_parse_nid(char *buf, lnet_nid_t *nid, char **endh)
161 return class_parse_value(buf, CLASS_PARSE_NID, (void *)nid, endh, 0);
163 EXPORT_SYMBOL(class_parse_nid);
165 int class_parse_nid_quiet(char *buf, lnet_nid_t *nid, char **endh)
167 return class_parse_value(buf, CLASS_PARSE_NID, (void *)nid, endh, 1);
169 EXPORT_SYMBOL(class_parse_nid_quiet);
171 /********************** class fns **********************/
174 * Create a new obd device and set the type, name and uuid. If successful,
175 * the new device can be accessed by either name or uuid.
177 static int class_attach(struct lustre_cfg *lcfg)
179 struct obd_device *obd = NULL;
180 char *typename, *name, *uuid;
183 if (!LUSTRE_CFG_BUFLEN(lcfg, 1)) {
184 CERROR("No type passed!\n");
187 typename = lustre_cfg_string(lcfg, 1);
189 if (!LUSTRE_CFG_BUFLEN(lcfg, 0)) {
190 CERROR("No name passed!\n");
193 name = lustre_cfg_string(lcfg, 0);
195 if (!LUSTRE_CFG_BUFLEN(lcfg, 2)) {
196 CERROR("No UUID passed!\n");
199 uuid = lustre_cfg_string(lcfg, 2);
201 CDEBUG(D_IOCTL, "attach type %s name: %s uuid: %s\n",
202 MKSTR(typename), MKSTR(name), MKSTR(uuid));
204 obd = class_newdev(typename, name);
206 /* Already exists or out of obds */
209 CERROR("Cannot create device %s of type %s : %d\n",
213 LASSERTF(obd, "Cannot get obd device %s of type %s\n",
215 LASSERTF(obd->obd_magic == OBD_DEVICE_MAGIC,
216 "obd %p obd_magic %08X != %08X\n",
217 obd, obd->obd_magic, OBD_DEVICE_MAGIC);
218 LASSERTF(strncmp(obd->obd_name, name, strlen(name)) == 0,
219 "%p obd_name %s != %s\n", obd, obd->obd_name, name);
221 rwlock_init(&obd->obd_pool_lock);
222 obd->obd_pool_limit = 0;
223 obd->obd_pool_slv = 0;
225 INIT_LIST_HEAD(&obd->obd_exports);
226 INIT_LIST_HEAD(&obd->obd_unlinked_exports);
227 INIT_LIST_HEAD(&obd->obd_delayed_exports);
228 spin_lock_init(&obd->obd_nid_lock);
229 spin_lock_init(&obd->obd_dev_lock);
230 mutex_init(&obd->obd_dev_mutex);
231 spin_lock_init(&obd->obd_osfs_lock);
232 /* obd->obd_osfs_age must be set to a value in the distant
233 * past to guarantee a fresh statfs is fetched on mount. */
234 obd->obd_osfs_age = cfs_time_shift_64(-1000);
236 /* XXX belongs in setup not attach */
237 init_rwsem(&obd->obd_observer_link_sem);
239 init_waitqueue_head(&obd->obd_evict_inprogress_waitq);
241 llog_group_init(&obd->obd_olg, FID_SEQ_LLOG);
243 obd->obd_conn_inprogress = 0;
246 if (len >= sizeof(obd->obd_uuid)) {
247 CERROR("uuid must be < %d bytes long\n",
248 (int)sizeof(obd->obd_uuid));
252 memcpy(obd->obd_uuid.uuid, uuid, len);
255 if (OBP(obd, attach)) {
256 rc = OBP(obd, attach)(obd, sizeof(*lcfg), lcfg);
263 /* Detach drops this */
264 spin_lock(&obd->obd_dev_lock);
265 atomic_set(&obd->obd_refcount, 1);
266 spin_unlock(&obd->obd_dev_lock);
267 lu_ref_init(&obd->obd_reference);
268 lu_ref_add(&obd->obd_reference, "attach", obd);
270 obd->obd_attached = 1;
271 CDEBUG(D_IOCTL, "OBD: dev %d attached type %s with refcount %d\n",
272 obd->obd_minor, typename, atomic_read(&obd->obd_refcount));
276 class_release_dev(obd);
281 /** Create hashes, self-export, and call type-specific setup.
282 * Setup is effectively the "start this obd" call.
284 static int class_setup(struct obd_device *obd, struct lustre_cfg *lcfg)
287 struct obd_export *exp;
290 LASSERTF(obd == class_num2obd(obd->obd_minor),
291 "obd %p != obd_devs[%d] %p\n",
292 obd, obd->obd_minor, class_num2obd(obd->obd_minor));
293 LASSERTF(obd->obd_magic == OBD_DEVICE_MAGIC,
294 "obd %p obd_magic %08x != %08x\n",
295 obd, obd->obd_magic, OBD_DEVICE_MAGIC);
297 /* have we attached a type to this device? */
298 if (!obd->obd_attached) {
299 CERROR("Device %d not attached\n", obd->obd_minor);
303 if (obd->obd_set_up) {
304 CERROR("Device %d already setup (type %s)\n",
305 obd->obd_minor, obd->obd_type->typ_name);
309 /* is someone else setting us up right now? (attach inits spinlock) */
310 spin_lock(&obd->obd_dev_lock);
311 if (obd->obd_starting) {
312 spin_unlock(&obd->obd_dev_lock);
313 CERROR("Device %d setup in progress (type %s)\n",
314 obd->obd_minor, obd->obd_type->typ_name);
317 /* just leave this on forever. I can't use obd_set_up here because
318 other fns check that status, and we're not actually set up yet. */
319 obd->obd_starting = 1;
320 obd->obd_uuid_hash = NULL;
321 spin_unlock(&obd->obd_dev_lock);
323 /* create an uuid-export lustre hash */
324 obd->obd_uuid_hash = cfs_hash_create("UUID_HASH",
327 HASH_UUID_BKT_BITS, 0,
330 &uuid_hash_ops, CFS_HASH_DEFAULT);
331 if (!obd->obd_uuid_hash) {
336 exp = class_new_export(obd, &obd->obd_uuid);
342 obd->obd_self_export = exp;
343 class_export_put(exp);
345 err = obd_setup(obd, lcfg);
351 spin_lock(&obd->obd_dev_lock);
352 /* cleanup drops this */
353 class_incref(obd, "setup", obd);
354 spin_unlock(&obd->obd_dev_lock);
356 CDEBUG(D_IOCTL, "finished setup of obd %s (uuid %s)\n",
357 obd->obd_name, obd->obd_uuid.uuid);
361 if (obd->obd_self_export) {
362 class_unlink_export(obd->obd_self_export);
363 obd->obd_self_export = NULL;
366 if (obd->obd_uuid_hash) {
367 cfs_hash_putref(obd->obd_uuid_hash);
368 obd->obd_uuid_hash = NULL;
370 obd->obd_starting = 0;
371 CERROR("setup %s failed (%d)\n", obd->obd_name, err);
375 /** We have finished using this obd and are ready to destroy it.
376 * There can be no more references to this obd.
378 static int class_detach(struct obd_device *obd, struct lustre_cfg *lcfg)
380 if (obd->obd_set_up) {
381 CERROR("OBD device %d still set up\n", obd->obd_minor);
385 spin_lock(&obd->obd_dev_lock);
386 if (!obd->obd_attached) {
387 spin_unlock(&obd->obd_dev_lock);
388 CERROR("OBD device %d not attached\n", obd->obd_minor);
391 obd->obd_attached = 0;
392 spin_unlock(&obd->obd_dev_lock);
394 CDEBUG(D_IOCTL, "detach on obd %s (uuid %s)\n",
395 obd->obd_name, obd->obd_uuid.uuid);
397 class_decref(obd, "attach", obd);
401 /** Start shutting down the obd. There may be in-progress ops when
402 * this is called. We tell them to start shutting down with a call
403 * to class_disconnect_exports().
405 static int class_cleanup(struct obd_device *obd, struct lustre_cfg *lcfg)
410 OBD_RACE(OBD_FAIL_LDLM_RECOV_CLIENTS);
412 if (!obd->obd_set_up) {
413 CERROR("Device %d not setup\n", obd->obd_minor);
417 spin_lock(&obd->obd_dev_lock);
418 if (obd->obd_stopping) {
419 spin_unlock(&obd->obd_dev_lock);
420 CERROR("OBD %d already stopping\n", obd->obd_minor);
423 /* Leave this on forever */
424 obd->obd_stopping = 1;
426 /* wait for already-arrived-connections to finish. */
427 while (obd->obd_conn_inprogress > 0) {
428 spin_unlock(&obd->obd_dev_lock);
432 spin_lock(&obd->obd_dev_lock);
434 spin_unlock(&obd->obd_dev_lock);
436 if (lcfg->lcfg_bufcount >= 2 && LUSTRE_CFG_BUFLEN(lcfg, 1) > 0) {
437 for (flag = lustre_cfg_string(lcfg, 1); *flag != 0; flag++)
443 LCONSOLE_WARN("Failing over %s\n",
446 obd->obd_no_transno = 1;
447 obd->obd_no_recov = 1;
448 if (OBP(obd, iocontrol)) {
449 obd_iocontrol(OBD_IOC_SYNC,
450 obd->obd_self_export,
455 CERROR("Unrecognised flag '%c'\n", *flag);
459 LASSERT(obd->obd_self_export);
461 /* Precleanup, we must make sure all exports get destroyed. */
462 err = obd_precleanup(obd, OBD_CLEANUP_EXPORTS);
464 CERROR("Precleanup %s returned %d\n",
467 /* destroy an uuid-export hash body */
468 if (obd->obd_uuid_hash) {
469 cfs_hash_putref(obd->obd_uuid_hash);
470 obd->obd_uuid_hash = NULL;
473 class_decref(obd, "setup", obd);
479 struct obd_device *class_incref(struct obd_device *obd,
480 const char *scope, const void *source)
482 lu_ref_add_atomic(&obd->obd_reference, scope, source);
483 atomic_inc(&obd->obd_refcount);
484 CDEBUG(D_INFO, "incref %s (%p) now %d\n", obd->obd_name, obd,
485 atomic_read(&obd->obd_refcount));
489 EXPORT_SYMBOL(class_incref);
491 void class_decref(struct obd_device *obd, const char *scope, const void *source)
496 spin_lock(&obd->obd_dev_lock);
497 atomic_dec(&obd->obd_refcount);
498 refs = atomic_read(&obd->obd_refcount);
499 spin_unlock(&obd->obd_dev_lock);
500 lu_ref_del(&obd->obd_reference, scope, source);
502 CDEBUG(D_INFO, "Decref %s (%p) now %d\n", obd->obd_name, obd, refs);
504 if ((refs == 1) && obd->obd_stopping) {
505 /* All exports have been destroyed; there should
506 be no more in-progress ops by this point.*/
508 spin_lock(&obd->obd_self_export->exp_lock);
509 obd->obd_self_export->exp_flags |= exp_flags_from_obd(obd);
510 spin_unlock(&obd->obd_self_export->exp_lock);
512 /* note that we'll recurse into class_decref again */
513 class_unlink_export(obd->obd_self_export);
518 CDEBUG(D_CONFIG, "finishing cleanup of obd %s (%s)\n",
519 obd->obd_name, obd->obd_uuid.uuid);
520 LASSERT(!obd->obd_attached);
521 if (obd->obd_stopping) {
522 /* If we're not stopping, we were never set up */
523 err = obd_cleanup(obd);
525 CERROR("Cleanup %s returned %d\n",
528 if (OBP(obd, detach)) {
529 err = OBP(obd, detach)(obd);
531 CERROR("Detach returned %d\n", err);
533 class_release_dev(obd);
536 EXPORT_SYMBOL(class_decref);
538 /** Add a failover nid location.
539 * Client obd types contact server obd types using this nid list.
541 static int class_add_conn(struct obd_device *obd, struct lustre_cfg *lcfg)
543 struct obd_import *imp;
544 struct obd_uuid uuid;
547 if (LUSTRE_CFG_BUFLEN(lcfg, 1) < 1 ||
548 LUSTRE_CFG_BUFLEN(lcfg, 1) > sizeof(struct obd_uuid)) {
549 CERROR("invalid conn_uuid\n");
552 if (strcmp(obd->obd_type->typ_name, LUSTRE_MDC_NAME) &&
553 strcmp(obd->obd_type->typ_name, LUSTRE_OSC_NAME) &&
554 strcmp(obd->obd_type->typ_name, LUSTRE_OSP_NAME) &&
555 strcmp(obd->obd_type->typ_name, LUSTRE_LWP_NAME) &&
556 strcmp(obd->obd_type->typ_name, LUSTRE_MGC_NAME)) {
557 CERROR("can't add connection on non-client dev\n");
561 imp = obd->u.cli.cl_import;
563 CERROR("try to add conn on immature client dev\n");
567 obd_str2uuid(&uuid, lustre_cfg_string(lcfg, 1));
568 rc = obd_add_conn(imp, &uuid, lcfg->lcfg_num);
573 /** Remove a failover nid location.
575 static int class_del_conn(struct obd_device *obd, struct lustre_cfg *lcfg)
577 struct obd_import *imp;
578 struct obd_uuid uuid;
581 if (LUSTRE_CFG_BUFLEN(lcfg, 1) < 1 ||
582 LUSTRE_CFG_BUFLEN(lcfg, 1) > sizeof(struct obd_uuid)) {
583 CERROR("invalid conn_uuid\n");
586 if (strcmp(obd->obd_type->typ_name, LUSTRE_MDC_NAME) &&
587 strcmp(obd->obd_type->typ_name, LUSTRE_OSC_NAME)) {
588 CERROR("can't del connection on non-client dev\n");
592 imp = obd->u.cli.cl_import;
594 CERROR("try to del conn on immature client dev\n");
598 obd_str2uuid(&uuid, lustre_cfg_string(lcfg, 1));
599 rc = obd_del_conn(imp, &uuid);
604 LIST_HEAD(lustre_profile_list);
606 struct lustre_profile *class_get_profile(const char *prof)
608 struct lustre_profile *lprof;
610 list_for_each_entry(lprof, &lustre_profile_list, lp_list) {
611 if (!strcmp(lprof->lp_profile, prof)) {
617 EXPORT_SYMBOL(class_get_profile);
619 /** Create a named "profile".
620 * This defines the mdc and osc names to use for a client.
621 * This also is used to define the lov to be used by a mdt.
623 static int class_add_profile(int proflen, char *prof, int osclen, char *osc,
624 int mdclen, char *mdc)
626 struct lustre_profile *lprof;
629 CDEBUG(D_CONFIG, "Add profile %s\n", prof);
631 lprof = kzalloc(sizeof(*lprof), GFP_NOFS);
634 INIT_LIST_HEAD(&lprof->lp_list);
636 LASSERT(proflen == (strlen(prof) + 1));
637 lprof->lp_profile = kmemdup(prof, proflen, GFP_NOFS);
638 if (!lprof->lp_profile) {
643 LASSERT(osclen == (strlen(osc) + 1));
644 lprof->lp_dt = kmemdup(osc, osclen, GFP_NOFS);
647 goto free_lp_profile;
651 LASSERT(mdclen == (strlen(mdc) + 1));
652 lprof->lp_md = kmemdup(mdc, mdclen, GFP_NOFS);
659 list_add(&lprof->lp_list, &lustre_profile_list);
665 kfree(lprof->lp_profile);
671 void class_del_profile(const char *prof)
673 struct lustre_profile *lprof;
675 CDEBUG(D_CONFIG, "Del profile %s\n", prof);
677 lprof = class_get_profile(prof);
679 list_del(&lprof->lp_list);
680 kfree(lprof->lp_profile);
686 EXPORT_SYMBOL(class_del_profile);
689 void class_del_profiles(void)
691 struct lustre_profile *lprof, *n;
693 list_for_each_entry_safe(lprof, n, &lustre_profile_list, lp_list) {
694 list_del(&lprof->lp_list);
695 kfree(lprof->lp_profile);
701 EXPORT_SYMBOL(class_del_profiles);
703 static int class_set_global(char *ptr, int val, struct lustre_cfg *lcfg)
705 if (class_match_param(ptr, PARAM_AT_MIN, NULL) == 0)
707 else if (class_match_param(ptr, PARAM_AT_MAX, NULL) == 0)
709 else if (class_match_param(ptr, PARAM_AT_EXTRA, NULL) == 0)
711 else if (class_match_param(ptr, PARAM_AT_EARLY_MARGIN, NULL) == 0)
712 at_early_margin = val;
713 else if (class_match_param(ptr, PARAM_AT_HISTORY, NULL) == 0)
715 else if (class_match_param(ptr, PARAM_JOBID_VAR, NULL) == 0)
716 strlcpy(obd_jobid_var, lustre_cfg_string(lcfg, 2),
717 JOBSTATS_JOBID_VAR_MAX_LEN + 1);
721 CDEBUG(D_IOCTL, "global %s = %d\n", ptr, val);
725 /* We can't call ll_process_config or lquota_process_config directly because
726 * it lives in a module that must be loaded after this one. */
727 static int (*client_process_config)(struct lustre_cfg *lcfg);
728 static int (*quota_process_config)(struct lustre_cfg *lcfg);
730 void lustre_register_client_process_config(int (*cpc)(struct lustre_cfg *lcfg))
732 client_process_config = cpc;
734 EXPORT_SYMBOL(lustre_register_client_process_config);
736 static int process_param2_config(struct lustre_cfg *lcfg)
738 char *param = lustre_cfg_string(lcfg, 1);
739 char *upcall = lustre_cfg_string(lcfg, 2);
741 [0] = "/usr/sbin/lctl",
750 /* Add upcall processing here. Now only lctl is supported */
751 if (strcmp(upcall, LCTL_UPCALL) != 0) {
752 CERROR("Unsupported upcall %s\n", upcall);
757 rc = call_usermodehelper(argv[0], argv, NULL, 1);
762 "lctl: error invoking upcall %s %s %s: rc = %d; time %ldus\n",
763 argv[0], argv[1], argv[2], rc,
764 (long)ktime_us_delta(end, start));
766 CDEBUG(D_HA, "lctl: invoked upcall %s %s %s, time %ldus\n",
767 argv[0], argv[1], argv[2],
768 (long)ktime_us_delta(end, start));
775 /** Process configuration commands given in lustre_cfg form.
776 * These may come from direct calls (e.g. class_manual_cleanup)
777 * or processing the config llog, or ioctl from lctl.
779 int class_process_config(struct lustre_cfg *lcfg)
781 struct obd_device *obd;
784 LASSERT(lcfg && !IS_ERR(lcfg));
785 CDEBUG(D_IOCTL, "processing cmd: %x\n", lcfg->lcfg_command);
787 /* Commands that don't need a device */
788 switch (lcfg->lcfg_command) {
790 err = class_attach(lcfg);
793 case LCFG_ADD_UUID: {
794 CDEBUG(D_IOCTL, "adding mapping from uuid %s to nid %#llx (%s)\n",
795 lustre_cfg_string(lcfg, 1), lcfg->lcfg_nid,
796 libcfs_nid2str(lcfg->lcfg_nid));
798 err = class_add_uuid(lustre_cfg_string(lcfg, 1), lcfg->lcfg_nid);
801 case LCFG_DEL_UUID: {
802 CDEBUG(D_IOCTL, "removing mappings for uuid %s\n",
803 (lcfg->lcfg_bufcount < 2 || LUSTRE_CFG_BUFLEN(lcfg, 1) == 0)
804 ? "<all uuids>" : lustre_cfg_string(lcfg, 1));
806 err = class_del_uuid(lustre_cfg_string(lcfg, 1));
809 case LCFG_MOUNTOPT: {
810 CDEBUG(D_IOCTL, "mountopt: profile %s osc %s mdc %s\n",
811 lustre_cfg_string(lcfg, 1),
812 lustre_cfg_string(lcfg, 2),
813 lustre_cfg_string(lcfg, 3));
814 /* set these mount options somewhere, so ll_fill_super
816 err = class_add_profile(LUSTRE_CFG_BUFLEN(lcfg, 1),
817 lustre_cfg_string(lcfg, 1),
818 LUSTRE_CFG_BUFLEN(lcfg, 2),
819 lustre_cfg_string(lcfg, 2),
820 LUSTRE_CFG_BUFLEN(lcfg, 3),
821 lustre_cfg_string(lcfg, 3));
824 case LCFG_DEL_MOUNTOPT: {
825 CDEBUG(D_IOCTL, "mountopt: profile %s\n",
826 lustre_cfg_string(lcfg, 1));
827 class_del_profile(lustre_cfg_string(lcfg, 1));
831 case LCFG_SET_TIMEOUT: {
832 CDEBUG(D_IOCTL, "changing lustre timeout from %d to %d\n",
833 obd_timeout, lcfg->lcfg_num);
834 obd_timeout = max(lcfg->lcfg_num, 1U);
839 case LCFG_SET_LDLM_TIMEOUT: {
840 /* ldlm_timeout is not used on the client */
844 case LCFG_SET_UPCALL: {
845 LCONSOLE_ERROR_MSG(0x15a, "recovery upcall is deprecated\n");
846 /* COMPAT_146 Don't fail on old configs */
851 struct cfg_marker *marker;
853 marker = lustre_cfg_buf(lcfg, 1);
854 CDEBUG(D_IOCTL, "marker %d (%#x) %.16s %s\n", marker->cm_step,
855 marker->cm_flags, marker->cm_tgtname, marker->cm_comment);
861 /* llite has no obd */
862 if ((class_match_param(lustre_cfg_string(lcfg, 1),
863 PARAM_LLITE, NULL) == 0) &&
864 client_process_config) {
865 err = (*client_process_config)(lcfg);
867 } else if ((class_match_param(lustre_cfg_string(lcfg, 1),
868 PARAM_SYS, &tmp) == 0)) {
869 /* Global param settings */
870 err = class_set_global(tmp, lcfg->lcfg_num, lcfg);
872 * Client or server should not fail to mount if
873 * it hits an unknown configuration parameter.
876 CWARN("Ignoring unknown param %s\n", tmp);
880 } else if ((class_match_param(lustre_cfg_string(lcfg, 1),
881 PARAM_QUOTA, &tmp) == 0) &&
882 quota_process_config) {
883 err = (*quota_process_config)(lcfg);
889 case LCFG_SET_PARAM: {
890 err = process_param2_config(lcfg);
894 /* Commands that require a device */
895 obd = class_name2obd(lustre_cfg_string(lcfg, 0));
897 if (!LUSTRE_CFG_BUFLEN(lcfg, 0))
898 CERROR("this lcfg command requires a device name\n");
900 CERROR("no device for: %s\n",
901 lustre_cfg_string(lcfg, 0));
907 switch (lcfg->lcfg_command) {
909 err = class_setup(obd, lcfg);
913 err = class_detach(obd, lcfg);
918 err = class_cleanup(obd, lcfg);
922 case LCFG_ADD_CONN: {
923 err = class_add_conn(obd, lcfg);
927 case LCFG_DEL_CONN: {
928 err = class_del_conn(obd, lcfg);
932 case LCFG_POOL_NEW: {
933 err = obd_pool_new(obd, lustre_cfg_string(lcfg, 2));
937 case LCFG_POOL_ADD: {
938 err = obd_pool_add(obd, lustre_cfg_string(lcfg, 2),
939 lustre_cfg_string(lcfg, 3));
943 case LCFG_POOL_REM: {
944 err = obd_pool_rem(obd, lustre_cfg_string(lcfg, 2),
945 lustre_cfg_string(lcfg, 3));
949 case LCFG_POOL_DEL: {
950 err = obd_pool_del(obd, lustre_cfg_string(lcfg, 2));
955 err = obd_process_config(obd, sizeof(*lcfg), lcfg);
961 if ((err < 0) && !(lcfg->lcfg_command & LCFG_REQUIRED)) {
962 CWARN("Ignoring error %d on optional command %#x\n", err,
968 EXPORT_SYMBOL(class_process_config);
970 int class_process_proc_param(char *prefix, struct lprocfs_vars *lvars,
971 struct lustre_cfg *lcfg, void *data)
973 struct lprocfs_vars *var;
974 struct file fakefile;
975 struct seq_file fake_seqfile;
977 int i, keylen, vallen;
978 int matched = 0, j = 0;
982 if (lcfg->lcfg_command != LCFG_PARAM) {
983 CERROR("Unknown command: %d\n", lcfg->lcfg_command);
987 /* fake a seq file so that var->fops->write can work... */
988 fakefile.private_data = &fake_seqfile;
989 fake_seqfile.private = data;
990 /* e.g. tunefs.lustre --param mdt.group_upcall=foo /r/tmp/lustre-mdt
991 or lctl conf_param lustre-MDT0000.mdt.group_upcall=bar
992 or lctl conf_param lustre-OST0000.osc.max_dirty_mb=36 */
993 for (i = 1; i < lcfg->lcfg_bufcount; i++) {
994 key = lustre_cfg_buf(lcfg, i);
995 /* Strip off prefix */
996 class_match_param(key, prefix, &key);
997 sval = strchr(key, '=');
998 if (!sval || (*(sval + 1) == 0)) {
999 CERROR("Can't parse param %s (missing '=')\n", key);
1000 /* rc = -EINVAL; continue parsing other params */
1003 keylen = sval - key;
1005 vallen = strlen(sval);
1008 /* Search proc entries */
1009 while (lvars[j].name) {
1011 if (!class_match_param(key, var->name, NULL)
1012 && keylen == strlen(var->name)) {
1015 if (var->fops && var->fops->write) {
1020 rc = (var->fops->write)(&fakefile, sval,
1029 /* If the prefix doesn't match, return error so we
1030 can pass it down the stack */
1031 if (strnchr(key, keylen, '.'))
1033 CERROR("%s: unknown param %s\n",
1034 (char *)lustre_cfg_string(lcfg, 0), key);
1035 /* rc = -EINVAL; continue parsing other params */
1037 } else if (rc < 0) {
1038 CERROR("writing proc entry %s err %d\n",
1042 CDEBUG(D_CONFIG, "%s.%.*s: Set parameter %.*s=%s\n",
1043 lustre_cfg_string(lcfg, 0),
1044 (int)strlen(prefix) - 1, prefix,
1045 (int)(sval - key - 1), key, sval);
1055 EXPORT_SYMBOL(class_process_proc_param);
1057 extern int lustre_check_exclusion(struct super_block *sb, char *svname);
1059 /** Parse a configuration llog, doing various manipulations on them
1060 * for various reasons, (modifications for compatibility, skip obsolete
1061 * records, change uuids, etc), then class_process_config() resulting
1064 int class_config_llog_handler(const struct lu_env *env,
1065 struct llog_handle *handle,
1066 struct llog_rec_hdr *rec, void *data)
1068 struct config_llog_instance *clli = data;
1069 int cfg_len = rec->lrh_len;
1070 char *cfg_buf = (char *) (rec + 1);
1073 switch (rec->lrh_type) {
1075 struct lustre_cfg *lcfg, *lcfg_new;
1076 struct lustre_cfg_bufs bufs;
1077 char *inst_name = NULL;
1079 int inst = 0, swab = 0;
1081 lcfg = (struct lustre_cfg *)cfg_buf;
1082 if (lcfg->lcfg_version == __swab32(LUSTRE_CFG_VERSION)) {
1083 lustre_swab_lustre_cfg(lcfg);
1087 rc = lustre_cfg_sanity_check(cfg_buf, cfg_len);
1091 /* Figure out config state info */
1092 if (lcfg->lcfg_command == LCFG_MARKER) {
1093 struct cfg_marker *marker = lustre_cfg_buf(lcfg, 1);
1095 lustre_swab_cfg_marker(marker, swab,
1096 LUSTRE_CFG_BUFLEN(lcfg, 1));
1097 CDEBUG(D_CONFIG, "Marker, inst_flg=%#x mark_flg=%#x\n",
1098 clli->cfg_flags, marker->cm_flags);
1099 if (marker->cm_flags & CM_START) {
1100 /* all previous flags off */
1101 clli->cfg_flags = CFG_F_MARKER;
1102 if (marker->cm_flags & CM_SKIP) {
1103 clli->cfg_flags |= CFG_F_SKIP;
1104 CDEBUG(D_CONFIG, "SKIP #%d\n",
1106 } else if ((marker->cm_flags & CM_EXCLUDE) ||
1108 lustre_check_exclusion(clli->cfg_sb,
1109 marker->cm_tgtname))) {
1110 clli->cfg_flags |= CFG_F_EXCLUDE;
1111 CDEBUG(D_CONFIG, "EXCLUDE %d\n",
1114 } else if (marker->cm_flags & CM_END) {
1115 clli->cfg_flags = 0;
1118 /* A config command without a start marker before it is
1119 illegal (post 146) */
1120 if (!(clli->cfg_flags & CFG_F_COMPAT146) &&
1121 !(clli->cfg_flags & CFG_F_MARKER) &&
1122 (lcfg->lcfg_command != LCFG_MARKER)) {
1123 CWARN("Config not inside markers, ignoring! (inst: %p, uuid: %s, flags: %#x)\n",
1125 clli->cfg_uuid.uuid, clli->cfg_flags);
1126 clli->cfg_flags |= CFG_F_SKIP;
1128 if (clli->cfg_flags & CFG_F_SKIP) {
1129 CDEBUG(D_CONFIG, "skipping %#x\n",
1132 /* No processing! */
1137 * For interoperability between 1.8 and 2.0,
1138 * rename "mds" obd device type to "mdt".
1141 char *typename = lustre_cfg_string(lcfg, 1);
1142 char *index = lustre_cfg_string(lcfg, 2);
1144 if ((lcfg->lcfg_command == LCFG_ATTACH && typename &&
1145 strcmp(typename, "mds") == 0)) {
1146 CWARN("For 1.8 interoperability, rename obd type from mds to mdt\n");
1149 if ((lcfg->lcfg_command == LCFG_SETUP && index &&
1150 strcmp(index, "type") == 0)) {
1151 CDEBUG(D_INFO, "For 1.8 interoperability, set this index to '0'\n");
1157 if (clli->cfg_flags & CFG_F_EXCLUDE) {
1158 CDEBUG(D_CONFIG, "cmd: %x marked EXCLUDED\n",
1159 lcfg->lcfg_command);
1160 if (lcfg->lcfg_command == LCFG_LOV_ADD_OBD)
1161 /* Add inactive instead */
1162 lcfg->lcfg_command = LCFG_LOV_ADD_INA;
1165 lustre_cfg_bufs_init(&bufs, lcfg);
1167 if (clli && clli->cfg_instance &&
1168 LUSTRE_CFG_BUFLEN(lcfg, 0) > 0) {
1170 inst_len = LUSTRE_CFG_BUFLEN(lcfg, 0) +
1171 sizeof(clli->cfg_instance) * 2 + 4;
1172 inst_name = kasprintf(GFP_NOFS, "%s-%p",
1173 lustre_cfg_string(lcfg, 0),
1174 clli->cfg_instance);
1179 lustre_cfg_bufs_set_string(&bufs, 0, inst_name);
1180 CDEBUG(D_CONFIG, "cmd %x, instance name: %s\n",
1181 lcfg->lcfg_command, inst_name);
1184 /* we override the llog's uuid for clients, to insure they
1186 if (clli && clli->cfg_instance &&
1187 lcfg->lcfg_command == LCFG_ATTACH) {
1188 lustre_cfg_bufs_set_string(&bufs, 2,
1189 clli->cfg_uuid.uuid);
1192 * sptlrpc config record, we expect 2 data segments:
1193 * [0]: fs_name/target_name,
1195 * moving them to index [1] and [2], and insert MGC's
1196 * obdname at index [0].
1198 if (clli && !clli->cfg_instance &&
1199 lcfg->lcfg_command == LCFG_SPTLRPC_CONF) {
1200 lustre_cfg_bufs_set(&bufs, 2, bufs.lcfg_buf[1],
1201 bufs.lcfg_buflen[1]);
1202 lustre_cfg_bufs_set(&bufs, 1, bufs.lcfg_buf[0],
1203 bufs.lcfg_buflen[0]);
1204 lustre_cfg_bufs_set_string(&bufs, 0,
1208 lcfg_new = lustre_cfg_new(lcfg->lcfg_command, &bufs);
1210 lcfg_new->lcfg_num = lcfg->lcfg_num;
1211 lcfg_new->lcfg_flags = lcfg->lcfg_flags;
1213 /* XXX Hack to try to remain binary compatible with
1214 * pre-newconfig logs */
1215 if (lcfg->lcfg_nal != 0 && /* pre-newconfig log? */
1216 (lcfg->lcfg_nid >> 32) == 0) {
1217 __u32 addr = (__u32)(lcfg->lcfg_nid & 0xffffffff);
1219 lcfg_new->lcfg_nid =
1220 LNET_MKNID(LNET_MKNET(lcfg->lcfg_nal, 0), addr);
1221 CWARN("Converted pre-newconfig NAL %d NID %x to %s\n",
1222 lcfg->lcfg_nal, addr,
1223 libcfs_nid2str(lcfg_new->lcfg_nid));
1225 lcfg_new->lcfg_nid = lcfg->lcfg_nid;
1228 lcfg_new->lcfg_nal = 0; /* illegal value for obsolete field */
1230 rc = class_process_config(lcfg_new);
1231 lustre_cfg_free(lcfg_new);
1238 CERROR("Unknown llog record type %#x encountered\n",
1244 CERROR("%s: cfg command failed: rc = %d\n",
1245 handle->lgh_ctxt->loc_obd->obd_name, rc);
1246 class_config_dump_handler(NULL, handle, rec, data);
1250 EXPORT_SYMBOL(class_config_llog_handler);
1252 int class_config_parse_llog(const struct lu_env *env, struct llog_ctxt *ctxt,
1253 char *name, struct config_llog_instance *cfg)
1255 struct llog_process_cat_data cd = {0, 0};
1256 struct llog_handle *llh;
1260 CDEBUG(D_INFO, "looking up llog %s\n", name);
1261 rc = llog_open(env, ctxt, &llh, NULL, name, LLOG_OPEN_EXISTS);
1265 rc = llog_init_handle(env, llh, LLOG_F_IS_PLAIN, NULL);
1269 /* continue processing from where we last stopped to end-of-log */
1271 cd.lpcd_first_idx = cfg->cfg_last_idx;
1272 callback = cfg->cfg_callback;
1275 callback = class_config_llog_handler;
1278 cd.lpcd_last_idx = 0;
1280 rc = llog_process(env, llh, callback, cfg, &cd);
1282 CDEBUG(D_CONFIG, "Processed log %s gen %d-%d (rc=%d)\n", name,
1283 cd.lpcd_first_idx + 1, cd.lpcd_last_idx, rc);
1285 cfg->cfg_last_idx = cd.lpcd_last_idx;
1288 llog_close(env, llh);
1291 EXPORT_SYMBOL(class_config_parse_llog);
1294 * parse config record and output dump in supplied buffer.
1295 * This is separated from class_config_dump_handler() to use
1296 * for ioctl needs as well
1298 static int class_config_parse_rec(struct llog_rec_hdr *rec, char *buf,
1301 struct lustre_cfg *lcfg = (struct lustre_cfg *)(rec + 1);
1303 char *end = buf + size;
1306 LASSERT(rec->lrh_type == OBD_CFG_REC);
1307 rc = lustre_cfg_sanity_check(lcfg, rec->lrh_len);
1311 ptr += snprintf(ptr, end-ptr, "cmd=%05x ", lcfg->lcfg_command);
1312 if (lcfg->lcfg_flags)
1313 ptr += snprintf(ptr, end-ptr, "flags=%#08x ",
1317 ptr += snprintf(ptr, end-ptr, "num=%#08x ", lcfg->lcfg_num);
1319 if (lcfg->lcfg_nid) {
1320 char nidstr[LNET_NIDSTR_SIZE];
1322 libcfs_nid2str_r(lcfg->lcfg_nid, nidstr, sizeof(nidstr));
1323 ptr += snprintf(ptr, end-ptr, "nid=%s(%#llx)\n ",
1324 nidstr, lcfg->lcfg_nid);
1327 if (lcfg->lcfg_command == LCFG_MARKER) {
1328 struct cfg_marker *marker = lustre_cfg_buf(lcfg, 1);
1330 ptr += snprintf(ptr, end-ptr, "marker=%d(%#x)%s '%s'",
1331 marker->cm_step, marker->cm_flags,
1332 marker->cm_tgtname, marker->cm_comment);
1336 for (i = 0; i < lcfg->lcfg_bufcount; i++) {
1337 ptr += snprintf(ptr, end-ptr, "%d:%s ", i,
1338 lustre_cfg_string(lcfg, i));
1341 /* return consumed bytes */
1346 int class_config_dump_handler(const struct lu_env *env,
1347 struct llog_handle *handle,
1348 struct llog_rec_hdr *rec, void *data)
1353 outstr = kzalloc(256, GFP_NOFS);
1357 if (rec->lrh_type == OBD_CFG_REC) {
1358 class_config_parse_rec(rec, outstr, 256);
1359 LCONSOLE(D_WARNING, " %s\n", outstr);
1361 LCONSOLE(D_WARNING, "unhandled lrh_type: %#x\n", rec->lrh_type);
1369 /** Call class_cleanup and class_detach.
1370 * "Manual" only in the sense that we're faking lcfg commands.
1372 int class_manual_cleanup(struct obd_device *obd)
1375 struct lustre_cfg *lcfg;
1376 struct lustre_cfg_bufs bufs;
1380 CERROR("empty cleanup\n");
1389 CDEBUG(D_CONFIG, "Manual cleanup of %s (flags='%s')\n",
1390 obd->obd_name, flags);
1392 lustre_cfg_bufs_reset(&bufs, obd->obd_name);
1393 lustre_cfg_bufs_set_string(&bufs, 1, flags);
1394 lcfg = lustre_cfg_new(LCFG_CLEANUP, &bufs);
1398 rc = class_process_config(lcfg);
1400 CERROR("cleanup failed %d: %s\n", rc, obd->obd_name);
1404 /* the lcfg is almost the same for both ops */
1405 lcfg->lcfg_command = LCFG_DETACH;
1406 rc = class_process_config(lcfg);
1408 CERROR("detach failed %d: %s\n", rc, obd->obd_name);
1410 lustre_cfg_free(lcfg);
1413 EXPORT_SYMBOL(class_manual_cleanup);
1416 * uuid<->export lustre hash operations
1420 uuid_hash(struct cfs_hash *hs, const void *key, unsigned mask)
1422 return cfs_hash_djb2_hash(((struct obd_uuid *)key)->uuid,
1423 sizeof(((struct obd_uuid *)key)->uuid), mask);
1427 uuid_key(struct hlist_node *hnode)
1429 struct obd_export *exp;
1431 exp = hlist_entry(hnode, struct obd_export, exp_uuid_hash);
1433 return &exp->exp_client_uuid;
1437 * NOTE: It is impossible to find an export that is in failed
1438 * state with this function
1441 uuid_keycmp(const void *key, struct hlist_node *hnode)
1443 struct obd_export *exp;
1446 exp = hlist_entry(hnode, struct obd_export, exp_uuid_hash);
1448 return obd_uuid_equals(key, &exp->exp_client_uuid) &&
1453 uuid_export_object(struct hlist_node *hnode)
1455 return hlist_entry(hnode, struct obd_export, exp_uuid_hash);
1459 uuid_export_get(struct cfs_hash *hs, struct hlist_node *hnode)
1461 struct obd_export *exp;
1463 exp = hlist_entry(hnode, struct obd_export, exp_uuid_hash);
1464 class_export_get(exp);
1468 uuid_export_put_locked(struct cfs_hash *hs, struct hlist_node *hnode)
1470 struct obd_export *exp;
1472 exp = hlist_entry(hnode, struct obd_export, exp_uuid_hash);
1473 class_export_put(exp);
1476 static struct cfs_hash_ops uuid_hash_ops = {
1477 .hs_hash = uuid_hash,
1479 .hs_keycmp = uuid_keycmp,
1480 .hs_object = uuid_export_object,
1481 .hs_get = uuid_export_get,
1482 .hs_put_locked = uuid_export_put_locked,