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, 2015, 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
38 #include "../include/obd_class.h"
39 #include <linux/string.h>
40 #include "../include/lustre/lustre_ioctl.h"
41 #include "../include/lustre_log.h"
42 #include "../include/lprocfs_status.h"
43 #include "../include/lustre_param.h"
45 #include "llog_internal.h"
47 static struct cfs_hash_ops uuid_hash_ops;
49 /*********** string parsing utils *********/
51 /* returns 0 if we find this key in the buffer, else 1 */
52 int class_find_param(char *buf, char *key, char **valp)
59 ptr = strstr(buf, key);
64 *valp = ptr + strlen(key);
68 EXPORT_SYMBOL(class_find_param);
70 /* returns 0 if this is the first key in the buffer, else 1.
71 * valp points to first char after key.
73 static int class_match_param(char *buf, const char *key, char **valp)
78 if (memcmp(buf, key, strlen(key)) != 0)
82 *valp = buf + strlen(key);
87 static int parse_nid(char *buf, void *value, int quiet)
89 lnet_nid_t *nid = value;
91 *nid = libcfs_str2nid(buf);
92 if (*nid != LNET_NID_ANY)
96 LCONSOLE_ERROR_MSG(0x159, "Can't parse NID '%s'\n", buf);
100 static int parse_net(char *buf, void *value)
104 *net = libcfs_str2net(buf);
105 CDEBUG(D_INFO, "Net %s\n", libcfs_net2str(*net));
117 * endh is set to next separator
119 static int class_parse_value(char *buf, int opc, void *value, char **endh,
128 while (*buf == ',' || *buf == ':')
130 if (*buf == ' ' || *buf == '/' || *buf == '\0')
133 /* nid separators or end of nids */
134 endp = strpbrk(buf, ",: /");
136 endp = buf + strlen(buf);
143 case CLASS_PARSE_NID:
144 rc = parse_nid(buf, value, quiet);
146 case CLASS_PARSE_NET:
147 rc = parse_net(buf, value);
158 int class_parse_nid(char *buf, lnet_nid_t *nid, char **endh)
160 return class_parse_value(buf, CLASS_PARSE_NID, (void *)nid, endh, 0);
162 EXPORT_SYMBOL(class_parse_nid);
164 int class_parse_nid_quiet(char *buf, lnet_nid_t *nid, char **endh)
166 return class_parse_value(buf, CLASS_PARSE_NID, (void *)nid, endh, 1);
168 EXPORT_SYMBOL(class_parse_nid_quiet);
170 /********************** class fns **********************/
173 * Create a new obd device and set the type, name and uuid. If successful,
174 * the new device can be accessed by either name or uuid.
176 static int class_attach(struct lustre_cfg *lcfg)
178 struct obd_device *obd = NULL;
179 char *typename, *name, *uuid;
182 if (!LUSTRE_CFG_BUFLEN(lcfg, 1)) {
183 CERROR("No type passed!\n");
186 typename = lustre_cfg_string(lcfg, 1);
188 if (!LUSTRE_CFG_BUFLEN(lcfg, 0)) {
189 CERROR("No name passed!\n");
192 name = lustre_cfg_string(lcfg, 0);
194 if (!LUSTRE_CFG_BUFLEN(lcfg, 2)) {
195 CERROR("No UUID passed!\n");
198 uuid = lustre_cfg_string(lcfg, 2);
200 CDEBUG(D_IOCTL, "attach type %s name: %s uuid: %s\n",
201 MKSTR(typename), MKSTR(name), MKSTR(uuid));
203 obd = class_newdev(typename, name);
205 /* Already exists or out of obds */
208 CERROR("Cannot create device %s of type %s : %d\n",
212 LASSERTF(obd, "Cannot get obd device %s of type %s\n",
214 LASSERTF(obd->obd_magic == OBD_DEVICE_MAGIC,
215 "obd %p obd_magic %08X != %08X\n",
216 obd, obd->obd_magic, OBD_DEVICE_MAGIC);
217 LASSERTF(strncmp(obd->obd_name, name, strlen(name)) == 0,
218 "%p obd_name %s != %s\n", obd, obd->obd_name, name);
220 rwlock_init(&obd->obd_pool_lock);
221 obd->obd_pool_limit = 0;
222 obd->obd_pool_slv = 0;
224 INIT_LIST_HEAD(&obd->obd_exports);
225 INIT_LIST_HEAD(&obd->obd_unlinked_exports);
226 INIT_LIST_HEAD(&obd->obd_delayed_exports);
227 spin_lock_init(&obd->obd_nid_lock);
228 spin_lock_init(&obd->obd_dev_lock);
229 mutex_init(&obd->obd_dev_mutex);
230 spin_lock_init(&obd->obd_osfs_lock);
231 /* obd->obd_osfs_age must be set to a value in the distant
232 * 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);
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);
254 /* Detach drops this */
255 spin_lock(&obd->obd_dev_lock);
256 atomic_set(&obd->obd_refcount, 1);
257 spin_unlock(&obd->obd_dev_lock);
258 lu_ref_init(&obd->obd_reference);
259 lu_ref_add(&obd->obd_reference, "attach", obd);
261 obd->obd_attached = 1;
262 CDEBUG(D_IOCTL, "OBD: dev %d attached type %s with refcount %d\n",
263 obd->obd_minor, typename, atomic_read(&obd->obd_refcount));
267 class_release_dev(obd);
272 /** Create hashes, self-export, and call type-specific setup.
273 * Setup is effectively the "start this obd" call.
275 static int class_setup(struct obd_device *obd, struct lustre_cfg *lcfg)
278 struct obd_export *exp;
281 LASSERTF(obd == class_num2obd(obd->obd_minor),
282 "obd %p != obd_devs[%d] %p\n",
283 obd, obd->obd_minor, class_num2obd(obd->obd_minor));
284 LASSERTF(obd->obd_magic == OBD_DEVICE_MAGIC,
285 "obd %p obd_magic %08x != %08x\n",
286 obd, obd->obd_magic, OBD_DEVICE_MAGIC);
288 /* have we attached a type to this device? */
289 if (!obd->obd_attached) {
290 CERROR("Device %d not attached\n", obd->obd_minor);
294 if (obd->obd_set_up) {
295 CERROR("Device %d already setup (type %s)\n",
296 obd->obd_minor, obd->obd_type->typ_name);
300 /* is someone else setting us up right now? (attach inits spinlock) */
301 spin_lock(&obd->obd_dev_lock);
302 if (obd->obd_starting) {
303 spin_unlock(&obd->obd_dev_lock);
304 CERROR("Device %d setup in progress (type %s)\n",
305 obd->obd_minor, obd->obd_type->typ_name);
308 /* just leave this on forever. I can't use obd_set_up here because
309 * other fns check that status, and we're not actually set up yet.
311 obd->obd_starting = 1;
312 obd->obd_uuid_hash = NULL;
313 spin_unlock(&obd->obd_dev_lock);
315 /* create an uuid-export lustre hash */
316 obd->obd_uuid_hash = cfs_hash_create("UUID_HASH",
319 HASH_UUID_BKT_BITS, 0,
322 &uuid_hash_ops, CFS_HASH_DEFAULT);
323 if (!obd->obd_uuid_hash) {
328 exp = class_new_export(obd, &obd->obd_uuid);
334 obd->obd_self_export = exp;
335 class_export_put(exp);
337 err = obd_setup(obd, lcfg);
343 spin_lock(&obd->obd_dev_lock);
344 /* cleanup drops this */
345 class_incref(obd, "setup", obd);
346 spin_unlock(&obd->obd_dev_lock);
348 CDEBUG(D_IOCTL, "finished setup of obd %s (uuid %s)\n",
349 obd->obd_name, obd->obd_uuid.uuid);
353 if (obd->obd_self_export) {
354 class_unlink_export(obd->obd_self_export);
355 obd->obd_self_export = NULL;
358 if (obd->obd_uuid_hash) {
359 cfs_hash_putref(obd->obd_uuid_hash);
360 obd->obd_uuid_hash = NULL;
362 obd->obd_starting = 0;
363 CERROR("setup %s failed (%d)\n", obd->obd_name, err);
367 /** We have finished using this obd and are ready to destroy it.
368 * There can be no more references to this obd.
370 static int class_detach(struct obd_device *obd, struct lustre_cfg *lcfg)
372 if (obd->obd_set_up) {
373 CERROR("OBD device %d still set up\n", obd->obd_minor);
377 spin_lock(&obd->obd_dev_lock);
378 if (!obd->obd_attached) {
379 spin_unlock(&obd->obd_dev_lock);
380 CERROR("OBD device %d not attached\n", obd->obd_minor);
383 obd->obd_attached = 0;
384 spin_unlock(&obd->obd_dev_lock);
386 CDEBUG(D_IOCTL, "detach on obd %s (uuid %s)\n",
387 obd->obd_name, obd->obd_uuid.uuid);
389 class_decref(obd, "attach", obd);
393 /** Start shutting down the obd. There may be in-progress ops when
394 * this is called. We tell them to start shutting down with a call
395 * to class_disconnect_exports().
397 static int class_cleanup(struct obd_device *obd, struct lustre_cfg *lcfg)
402 OBD_RACE(OBD_FAIL_LDLM_RECOV_CLIENTS);
404 if (!obd->obd_set_up) {
405 CERROR("Device %d not setup\n", obd->obd_minor);
409 spin_lock(&obd->obd_dev_lock);
410 if (obd->obd_stopping) {
411 spin_unlock(&obd->obd_dev_lock);
412 CERROR("OBD %d already stopping\n", obd->obd_minor);
415 /* Leave this on forever */
416 obd->obd_stopping = 1;
418 /* wait for already-arrived-connections to finish. */
419 while (obd->obd_conn_inprogress > 0) {
420 spin_unlock(&obd->obd_dev_lock);
424 spin_lock(&obd->obd_dev_lock);
426 spin_unlock(&obd->obd_dev_lock);
428 if (lcfg->lcfg_bufcount >= 2 && LUSTRE_CFG_BUFLEN(lcfg, 1) > 0) {
429 for (flag = lustre_cfg_string(lcfg, 1); *flag != 0; flag++)
435 LCONSOLE_WARN("Failing over %s\n",
438 obd->obd_no_transno = 1;
439 obd->obd_no_recov = 1;
440 if (OBP(obd, iocontrol)) {
441 obd_iocontrol(OBD_IOC_SYNC,
442 obd->obd_self_export,
447 CERROR("Unrecognised flag '%c'\n", *flag);
451 LASSERT(obd->obd_self_export);
453 /* Precleanup, we must make sure all exports get destroyed. */
454 err = obd_precleanup(obd, OBD_CLEANUP_EXPORTS);
456 CERROR("Precleanup %s returned %d\n",
459 /* destroy an uuid-export hash body */
460 if (obd->obd_uuid_hash) {
461 cfs_hash_putref(obd->obd_uuid_hash);
462 obd->obd_uuid_hash = NULL;
465 class_decref(obd, "setup", obd);
471 struct obd_device *class_incref(struct obd_device *obd,
472 const char *scope, const void *source)
474 lu_ref_add_atomic(&obd->obd_reference, scope, source);
475 atomic_inc(&obd->obd_refcount);
476 CDEBUG(D_INFO, "incref %s (%p) now %d\n", obd->obd_name, obd,
477 atomic_read(&obd->obd_refcount));
481 EXPORT_SYMBOL(class_incref);
483 void class_decref(struct obd_device *obd, const char *scope, const void *source)
488 spin_lock(&obd->obd_dev_lock);
489 atomic_dec(&obd->obd_refcount);
490 refs = atomic_read(&obd->obd_refcount);
491 spin_unlock(&obd->obd_dev_lock);
492 lu_ref_del(&obd->obd_reference, scope, source);
494 CDEBUG(D_INFO, "Decref %s (%p) now %d\n", obd->obd_name, obd, refs);
496 if ((refs == 1) && obd->obd_stopping) {
497 /* All exports have been destroyed; there should
498 * be no more in-progress ops by this point.
501 spin_lock(&obd->obd_self_export->exp_lock);
502 obd->obd_self_export->exp_flags |= exp_flags_from_obd(obd);
503 spin_unlock(&obd->obd_self_export->exp_lock);
505 /* note that we'll recurse into class_decref again */
506 class_unlink_export(obd->obd_self_export);
511 CDEBUG(D_CONFIG, "finishing cleanup of obd %s (%s)\n",
512 obd->obd_name, obd->obd_uuid.uuid);
513 LASSERT(!obd->obd_attached);
514 if (obd->obd_stopping) {
515 /* If we're not stopping, we were never set up */
516 err = obd_cleanup(obd);
518 CERROR("Cleanup %s returned %d\n",
521 class_release_dev(obd);
524 EXPORT_SYMBOL(class_decref);
526 /** Add a failover nid location.
527 * Client obd types contact server obd types using this nid list.
529 static int class_add_conn(struct obd_device *obd, struct lustre_cfg *lcfg)
531 struct obd_import *imp;
532 struct obd_uuid uuid;
535 if (LUSTRE_CFG_BUFLEN(lcfg, 1) < 1 ||
536 LUSTRE_CFG_BUFLEN(lcfg, 1) > sizeof(struct obd_uuid)) {
537 CERROR("invalid conn_uuid\n");
540 if (strcmp(obd->obd_type->typ_name, LUSTRE_MDC_NAME) &&
541 strcmp(obd->obd_type->typ_name, LUSTRE_OSC_NAME) &&
542 strcmp(obd->obd_type->typ_name, LUSTRE_OSP_NAME) &&
543 strcmp(obd->obd_type->typ_name, LUSTRE_LWP_NAME) &&
544 strcmp(obd->obd_type->typ_name, LUSTRE_MGC_NAME)) {
545 CERROR("can't add connection on non-client dev\n");
549 imp = obd->u.cli.cl_import;
551 CERROR("try to add conn on immature client dev\n");
555 obd_str2uuid(&uuid, lustre_cfg_string(lcfg, 1));
556 rc = obd_add_conn(imp, &uuid, lcfg->lcfg_num);
561 /** Remove a failover nid location.
563 static int class_del_conn(struct obd_device *obd, struct lustre_cfg *lcfg)
565 struct obd_import *imp;
566 struct obd_uuid uuid;
569 if (LUSTRE_CFG_BUFLEN(lcfg, 1) < 1 ||
570 LUSTRE_CFG_BUFLEN(lcfg, 1) > sizeof(struct obd_uuid)) {
571 CERROR("invalid conn_uuid\n");
574 if (strcmp(obd->obd_type->typ_name, LUSTRE_MDC_NAME) &&
575 strcmp(obd->obd_type->typ_name, LUSTRE_OSC_NAME)) {
576 CERROR("can't del connection on non-client dev\n");
580 imp = obd->u.cli.cl_import;
582 CERROR("try to del conn on immature client dev\n");
586 obd_str2uuid(&uuid, lustre_cfg_string(lcfg, 1));
587 rc = obd_del_conn(imp, &uuid);
592 static LIST_HEAD(lustre_profile_list);
594 struct lustre_profile *class_get_profile(const char *prof)
596 struct lustre_profile *lprof;
598 list_for_each_entry(lprof, &lustre_profile_list, lp_list) {
599 if (!strcmp(lprof->lp_profile, prof)) {
605 EXPORT_SYMBOL(class_get_profile);
607 /** Create a named "profile".
608 * This defines the mdc and osc names to use for a client.
609 * This also is used to define the lov to be used by a mdt.
611 static int class_add_profile(int proflen, char *prof, int osclen, char *osc,
612 int mdclen, char *mdc)
614 struct lustre_profile *lprof;
617 CDEBUG(D_CONFIG, "Add profile %s\n", prof);
619 lprof = kzalloc(sizeof(*lprof), GFP_NOFS);
622 INIT_LIST_HEAD(&lprof->lp_list);
624 LASSERT(proflen == (strlen(prof) + 1));
625 lprof->lp_profile = kmemdup(prof, proflen, GFP_NOFS);
626 if (!lprof->lp_profile) {
631 LASSERT(osclen == (strlen(osc) + 1));
632 lprof->lp_dt = kmemdup(osc, osclen, GFP_NOFS);
635 goto free_lp_profile;
639 LASSERT(mdclen == (strlen(mdc) + 1));
640 lprof->lp_md = kmemdup(mdc, mdclen, GFP_NOFS);
647 list_add(&lprof->lp_list, &lustre_profile_list);
653 kfree(lprof->lp_profile);
659 void class_del_profile(const char *prof)
661 struct lustre_profile *lprof;
663 CDEBUG(D_CONFIG, "Del profile %s\n", prof);
665 lprof = class_get_profile(prof);
667 list_del(&lprof->lp_list);
668 kfree(lprof->lp_profile);
674 EXPORT_SYMBOL(class_del_profile);
677 void class_del_profiles(void)
679 struct lustre_profile *lprof, *n;
681 list_for_each_entry_safe(lprof, n, &lustre_profile_list, lp_list) {
682 list_del(&lprof->lp_list);
683 kfree(lprof->lp_profile);
689 EXPORT_SYMBOL(class_del_profiles);
691 static int class_set_global(char *ptr, int val, struct lustre_cfg *lcfg)
693 if (class_match_param(ptr, PARAM_AT_MIN, NULL) == 0)
695 else if (class_match_param(ptr, PARAM_AT_MAX, NULL) == 0)
697 else if (class_match_param(ptr, PARAM_AT_EXTRA, NULL) == 0)
699 else if (class_match_param(ptr, PARAM_AT_EARLY_MARGIN, NULL) == 0)
700 at_early_margin = val;
701 else if (class_match_param(ptr, PARAM_AT_HISTORY, NULL) == 0)
703 else if (class_match_param(ptr, PARAM_JOBID_VAR, NULL) == 0)
704 strlcpy(obd_jobid_var, lustre_cfg_string(lcfg, 2),
705 JOBSTATS_JOBID_VAR_MAX_LEN + 1);
709 CDEBUG(D_IOCTL, "global %s = %d\n", ptr, val);
713 /* We can't call ll_process_config or lquota_process_config directly because
714 * it lives in a module that must be loaded after this one.
716 static int (*client_process_config)(struct lustre_cfg *lcfg);
717 static int (*quota_process_config)(struct lustre_cfg *lcfg);
719 void lustre_register_client_process_config(int (*cpc)(struct lustre_cfg *lcfg))
721 client_process_config = cpc;
723 EXPORT_SYMBOL(lustre_register_client_process_config);
725 static int process_param2_config(struct lustre_cfg *lcfg)
727 char *param = lustre_cfg_string(lcfg, 1);
728 char *upcall = lustre_cfg_string(lcfg, 2);
730 [0] = "/usr/sbin/lctl",
739 /* Add upcall processing here. Now only lctl is supported */
740 if (strcmp(upcall, LCTL_UPCALL) != 0) {
741 CERROR("Unsupported upcall %s\n", upcall);
746 rc = call_usermodehelper(argv[0], argv, NULL, 1);
751 "lctl: error invoking upcall %s %s %s: rc = %d; time %ldus\n",
752 argv[0], argv[1], argv[2], rc,
753 (long)ktime_us_delta(end, start));
755 CDEBUG(D_HA, "lctl: invoked upcall %s %s %s, time %ldus\n",
756 argv[0], argv[1], argv[2],
757 (long)ktime_us_delta(end, start));
764 /** Process configuration commands given in lustre_cfg form.
765 * These may come from direct calls (e.g. class_manual_cleanup)
766 * or processing the config llog, or ioctl from lctl.
768 int class_process_config(struct lustre_cfg *lcfg)
770 struct obd_device *obd;
773 LASSERT(lcfg && !IS_ERR(lcfg));
774 CDEBUG(D_IOCTL, "processing cmd: %x\n", lcfg->lcfg_command);
776 /* Commands that don't need a device */
777 switch (lcfg->lcfg_command) {
779 err = class_attach(lcfg);
782 case LCFG_ADD_UUID: {
783 CDEBUG(D_IOCTL, "adding mapping from uuid %s to nid %#llx (%s)\n",
784 lustre_cfg_string(lcfg, 1), lcfg->lcfg_nid,
785 libcfs_nid2str(lcfg->lcfg_nid));
787 err = class_add_uuid(lustre_cfg_string(lcfg, 1), lcfg->lcfg_nid);
790 case LCFG_DEL_UUID: {
791 CDEBUG(D_IOCTL, "removing mappings for uuid %s\n",
792 (lcfg->lcfg_bufcount < 2 || LUSTRE_CFG_BUFLEN(lcfg, 1) == 0)
793 ? "<all uuids>" : lustre_cfg_string(lcfg, 1));
795 err = class_del_uuid(lustre_cfg_string(lcfg, 1));
798 case LCFG_MOUNTOPT: {
799 CDEBUG(D_IOCTL, "mountopt: profile %s osc %s mdc %s\n",
800 lustre_cfg_string(lcfg, 1),
801 lustre_cfg_string(lcfg, 2),
802 lustre_cfg_string(lcfg, 3));
803 /* set these mount options somewhere, so ll_fill_super
806 err = class_add_profile(LUSTRE_CFG_BUFLEN(lcfg, 1),
807 lustre_cfg_string(lcfg, 1),
808 LUSTRE_CFG_BUFLEN(lcfg, 2),
809 lustre_cfg_string(lcfg, 2),
810 LUSTRE_CFG_BUFLEN(lcfg, 3),
811 lustre_cfg_string(lcfg, 3));
814 case LCFG_DEL_MOUNTOPT: {
815 CDEBUG(D_IOCTL, "mountopt: profile %s\n",
816 lustre_cfg_string(lcfg, 1));
817 class_del_profile(lustre_cfg_string(lcfg, 1));
821 case LCFG_SET_TIMEOUT: {
822 CDEBUG(D_IOCTL, "changing lustre timeout from %d to %d\n",
823 obd_timeout, lcfg->lcfg_num);
824 obd_timeout = max(lcfg->lcfg_num, 1U);
829 case LCFG_SET_LDLM_TIMEOUT: {
830 /* ldlm_timeout is not used on the client */
834 case LCFG_SET_UPCALL: {
835 LCONSOLE_ERROR_MSG(0x15a, "recovery upcall is deprecated\n");
836 /* COMPAT_146 Don't fail on old configs */
841 struct cfg_marker *marker;
843 marker = lustre_cfg_buf(lcfg, 1);
844 CDEBUG(D_IOCTL, "marker %d (%#x) %.16s %s\n", marker->cm_step,
845 marker->cm_flags, marker->cm_tgtname, marker->cm_comment);
851 /* llite has no obd */
852 if ((class_match_param(lustre_cfg_string(lcfg, 1),
853 PARAM_LLITE, NULL) == 0) &&
854 client_process_config) {
855 err = (*client_process_config)(lcfg);
857 } else if ((class_match_param(lustre_cfg_string(lcfg, 1),
858 PARAM_SYS, &tmp) == 0)) {
859 /* Global param settings */
860 err = class_set_global(tmp, lcfg->lcfg_num, lcfg);
862 * Client or server should not fail to mount if
863 * it hits an unknown configuration parameter.
866 CWARN("Ignoring unknown param %s\n", tmp);
870 } else if ((class_match_param(lustre_cfg_string(lcfg, 1),
871 PARAM_QUOTA, &tmp) == 0) &&
872 quota_process_config) {
873 err = (*quota_process_config)(lcfg);
879 case LCFG_SET_PARAM: {
880 err = process_param2_config(lcfg);
884 /* Commands that require a device */
885 obd = class_name2obd(lustre_cfg_string(lcfg, 0));
887 if (!LUSTRE_CFG_BUFLEN(lcfg, 0))
888 CERROR("this lcfg command requires a device name\n");
890 CERROR("no device for: %s\n",
891 lustre_cfg_string(lcfg, 0));
897 switch (lcfg->lcfg_command) {
899 err = class_setup(obd, lcfg);
903 err = class_detach(obd, lcfg);
908 err = class_cleanup(obd, lcfg);
912 case LCFG_ADD_CONN: {
913 err = class_add_conn(obd, lcfg);
917 case LCFG_DEL_CONN: {
918 err = class_del_conn(obd, lcfg);
922 case LCFG_POOL_NEW: {
923 err = obd_pool_new(obd, lustre_cfg_string(lcfg, 2));
927 case LCFG_POOL_ADD: {
928 err = obd_pool_add(obd, lustre_cfg_string(lcfg, 2),
929 lustre_cfg_string(lcfg, 3));
933 case LCFG_POOL_REM: {
934 err = obd_pool_rem(obd, lustre_cfg_string(lcfg, 2),
935 lustre_cfg_string(lcfg, 3));
939 case LCFG_POOL_DEL: {
940 err = obd_pool_del(obd, lustre_cfg_string(lcfg, 2));
945 err = obd_process_config(obd, sizeof(*lcfg), lcfg);
950 if ((err < 0) && !(lcfg->lcfg_command & LCFG_REQUIRED)) {
951 CWARN("Ignoring error %d on optional command %#x\n", err,
957 EXPORT_SYMBOL(class_process_config);
959 int class_process_proc_param(char *prefix, struct lprocfs_vars *lvars,
960 struct lustre_cfg *lcfg, void *data)
962 struct lprocfs_vars *var;
963 struct file fakefile;
964 struct seq_file fake_seqfile;
966 int i, keylen, vallen;
967 int matched = 0, j = 0;
971 if (lcfg->lcfg_command != LCFG_PARAM) {
972 CERROR("Unknown command: %d\n", lcfg->lcfg_command);
976 /* fake a seq file so that var->fops->write can work... */
977 fakefile.private_data = &fake_seqfile;
978 fake_seqfile.private = data;
979 /* e.g. tunefs.lustre --param mdt.group_upcall=foo /r/tmp/lustre-mdt
980 * or lctl conf_param lustre-MDT0000.mdt.group_upcall=bar
981 * or lctl conf_param lustre-OST0000.osc.max_dirty_mb=36
983 for (i = 1; i < lcfg->lcfg_bufcount; i++) {
984 key = lustre_cfg_buf(lcfg, i);
985 /* Strip off prefix */
986 if (class_match_param(key, prefix, &key)) {
988 * If the prefix doesn't match, return error so we
989 * can pass it down the stack
993 sval = strchr(key, '=');
994 if (!sval || (*(sval + 1) == 0)) {
995 CERROR("Can't parse param %s (missing '=')\n", key);
996 /* rc = -EINVAL; continue parsing other params */
1001 vallen = strlen(sval);
1004 /* Search proc entries */
1005 while (lvars[j].name) {
1007 if (!class_match_param(key, var->name, NULL) &&
1008 keylen == strlen(var->name)) {
1011 if (var->fops && var->fops->write) {
1016 rc = var->fops->write(&fakefile, sval,
1025 CERROR("%.*s: %s unknown param %s\n",
1026 (int)strlen(prefix) - 1, prefix,
1027 (char *)lustre_cfg_string(lcfg, 0), key);
1028 /* rc = -EINVAL; continue parsing other params */
1030 } else if (rc < 0) {
1031 CERROR("%s: error writing proc entry '%s': rc = %d\n",
1032 prefix, var->name, rc);
1035 CDEBUG(D_CONFIG, "%s.%.*s: Set parameter %.*s=%s\n",
1036 lustre_cfg_string(lcfg, 0),
1037 (int)strlen(prefix) - 1, prefix,
1038 (int)(sval - key - 1), key, sval);
1048 EXPORT_SYMBOL(class_process_proc_param);
1050 extern int lustre_check_exclusion(struct super_block *sb, char *svname);
1052 /** Parse a configuration llog, doing various manipulations on them
1053 * for various reasons, (modifications for compatibility, skip obsolete
1054 * records, change uuids, etc), then class_process_config() resulting
1057 int class_config_llog_handler(const struct lu_env *env,
1058 struct llog_handle *handle,
1059 struct llog_rec_hdr *rec, void *data)
1061 struct config_llog_instance *clli = data;
1062 int cfg_len = rec->lrh_len;
1063 char *cfg_buf = (char *)(rec + 1);
1066 switch (rec->lrh_type) {
1068 struct lustre_cfg *lcfg, *lcfg_new;
1069 struct lustre_cfg_bufs bufs;
1070 char *inst_name = NULL;
1072 int inst = 0, swab = 0;
1074 lcfg = (struct lustre_cfg *)cfg_buf;
1075 if (lcfg->lcfg_version == __swab32(LUSTRE_CFG_VERSION)) {
1076 lustre_swab_lustre_cfg(lcfg);
1080 rc = lustre_cfg_sanity_check(cfg_buf, cfg_len);
1084 /* Figure out config state info */
1085 if (lcfg->lcfg_command == LCFG_MARKER) {
1086 struct cfg_marker *marker = lustre_cfg_buf(lcfg, 1);
1088 lustre_swab_cfg_marker(marker, swab,
1089 LUSTRE_CFG_BUFLEN(lcfg, 1));
1090 CDEBUG(D_CONFIG, "Marker, inst_flg=%#x mark_flg=%#x\n",
1091 clli->cfg_flags, marker->cm_flags);
1092 if (marker->cm_flags & CM_START) {
1093 /* all previous flags off */
1094 clli->cfg_flags = CFG_F_MARKER;
1095 if (marker->cm_flags & CM_SKIP) {
1096 clli->cfg_flags |= CFG_F_SKIP;
1097 CDEBUG(D_CONFIG, "SKIP #%d\n",
1099 } else if ((marker->cm_flags & CM_EXCLUDE) ||
1101 lustre_check_exclusion(clli->cfg_sb,
1102 marker->cm_tgtname))) {
1103 clli->cfg_flags |= CFG_F_EXCLUDE;
1104 CDEBUG(D_CONFIG, "EXCLUDE %d\n",
1107 } else if (marker->cm_flags & CM_END) {
1108 clli->cfg_flags = 0;
1111 /* A config command without a start marker before it is
1112 * illegal (post 146)
1114 if (!(clli->cfg_flags & CFG_F_COMPAT146) &&
1115 !(clli->cfg_flags & CFG_F_MARKER) &&
1116 (lcfg->lcfg_command != LCFG_MARKER)) {
1117 CWARN("Config not inside markers, ignoring! (inst: %p, uuid: %s, flags: %#x)\n",
1119 clli->cfg_uuid.uuid, clli->cfg_flags);
1120 clli->cfg_flags |= CFG_F_SKIP;
1122 if (clli->cfg_flags & CFG_F_SKIP) {
1123 CDEBUG(D_CONFIG, "skipping %#x\n",
1126 /* No processing! */
1131 * For interoperability between 1.8 and 2.0,
1132 * rename "mds" obd device type to "mdt".
1135 char *typename = lustre_cfg_string(lcfg, 1);
1136 char *index = lustre_cfg_string(lcfg, 2);
1138 if ((lcfg->lcfg_command == LCFG_ATTACH && typename &&
1139 strcmp(typename, "mds") == 0)) {
1140 CWARN("For 1.8 interoperability, rename obd type from mds to mdt\n");
1143 if ((lcfg->lcfg_command == LCFG_SETUP && index &&
1144 strcmp(index, "type") == 0)) {
1145 CDEBUG(D_INFO, "For 1.8 interoperability, set this index to '0'\n");
1151 if (clli->cfg_flags & CFG_F_EXCLUDE) {
1152 CDEBUG(D_CONFIG, "cmd: %x marked EXCLUDED\n",
1153 lcfg->lcfg_command);
1154 if (lcfg->lcfg_command == LCFG_LOV_ADD_OBD)
1155 /* Add inactive instead */
1156 lcfg->lcfg_command = LCFG_LOV_ADD_INA;
1159 lustre_cfg_bufs_init(&bufs, lcfg);
1161 if (clli && clli->cfg_instance &&
1162 LUSTRE_CFG_BUFLEN(lcfg, 0) > 0) {
1164 inst_len = LUSTRE_CFG_BUFLEN(lcfg, 0) +
1165 sizeof(clli->cfg_instance) * 2 + 4;
1166 inst_name = kasprintf(GFP_NOFS, "%s-%p",
1167 lustre_cfg_string(lcfg, 0),
1168 clli->cfg_instance);
1173 lustre_cfg_bufs_set_string(&bufs, 0, inst_name);
1174 CDEBUG(D_CONFIG, "cmd %x, instance name: %s\n",
1175 lcfg->lcfg_command, inst_name);
1178 /* we override the llog's uuid for clients, to insure they
1181 if (clli && clli->cfg_instance &&
1182 lcfg->lcfg_command == LCFG_ATTACH) {
1183 lustre_cfg_bufs_set_string(&bufs, 2,
1184 clli->cfg_uuid.uuid);
1187 * sptlrpc config record, we expect 2 data segments:
1188 * [0]: fs_name/target_name,
1190 * moving them to index [1] and [2], and insert MGC's
1191 * obdname at index [0].
1193 if (clli && !clli->cfg_instance &&
1194 lcfg->lcfg_command == LCFG_SPTLRPC_CONF) {
1195 lustre_cfg_bufs_set(&bufs, 2, bufs.lcfg_buf[1],
1196 bufs.lcfg_buflen[1]);
1197 lustre_cfg_bufs_set(&bufs, 1, bufs.lcfg_buf[0],
1198 bufs.lcfg_buflen[0]);
1199 lustre_cfg_bufs_set_string(&bufs, 0,
1203 lcfg_new = lustre_cfg_new(lcfg->lcfg_command, &bufs);
1205 lcfg_new->lcfg_num = lcfg->lcfg_num;
1206 lcfg_new->lcfg_flags = lcfg->lcfg_flags;
1208 /* XXX Hack to try to remain binary compatible with
1209 * pre-newconfig logs
1211 if (lcfg->lcfg_nal != 0 && /* pre-newconfig log? */
1212 (lcfg->lcfg_nid >> 32) == 0) {
1213 __u32 addr = (__u32)(lcfg->lcfg_nid & 0xffffffff);
1215 lcfg_new->lcfg_nid =
1216 LNET_MKNID(LNET_MKNET(lcfg->lcfg_nal, 0), addr);
1217 CWARN("Converted pre-newconfig NAL %d NID %x to %s\n",
1218 lcfg->lcfg_nal, addr,
1219 libcfs_nid2str(lcfg_new->lcfg_nid));
1221 lcfg_new->lcfg_nid = lcfg->lcfg_nid;
1224 lcfg_new->lcfg_nal = 0; /* illegal value for obsolete field */
1226 rc = class_process_config(lcfg_new);
1227 lustre_cfg_free(lcfg_new);
1234 CERROR("Unknown llog record type %#x encountered\n",
1240 CERROR("%s: cfg command failed: rc = %d\n",
1241 handle->lgh_ctxt->loc_obd->obd_name, rc);
1242 class_config_dump_handler(NULL, handle, rec, data);
1246 EXPORT_SYMBOL(class_config_llog_handler);
1248 int class_config_parse_llog(const struct lu_env *env, struct llog_ctxt *ctxt,
1249 char *name, struct config_llog_instance *cfg)
1251 struct llog_process_cat_data cd = {0, 0};
1252 struct llog_handle *llh;
1256 CDEBUG(D_INFO, "looking up llog %s\n", name);
1257 rc = llog_open(env, ctxt, &llh, NULL, name, LLOG_OPEN_EXISTS);
1261 rc = llog_init_handle(env, llh, LLOG_F_IS_PLAIN, NULL);
1265 /* continue processing from where we last stopped to end-of-log */
1267 cd.lpcd_first_idx = cfg->cfg_last_idx;
1268 callback = cfg->cfg_callback;
1271 callback = class_config_llog_handler;
1274 cd.lpcd_last_idx = 0;
1276 rc = llog_process(env, llh, callback, cfg, &cd);
1278 CDEBUG(D_CONFIG, "Processed log %s gen %d-%d (rc=%d)\n", name,
1279 cd.lpcd_first_idx + 1, cd.lpcd_last_idx, rc);
1281 cfg->cfg_last_idx = cd.lpcd_last_idx;
1284 llog_close(env, llh);
1287 EXPORT_SYMBOL(class_config_parse_llog);
1290 * parse config record and output dump in supplied buffer.
1291 * This is separated from class_config_dump_handler() to use
1292 * for ioctl needs as well
1294 static int class_config_parse_rec(struct llog_rec_hdr *rec, char *buf,
1297 struct lustre_cfg *lcfg = (struct lustre_cfg *)(rec + 1);
1299 char *end = buf + size;
1302 LASSERT(rec->lrh_type == OBD_CFG_REC);
1303 rc = lustre_cfg_sanity_check(lcfg, rec->lrh_len);
1307 ptr += snprintf(ptr, end - ptr, "cmd=%05x ", lcfg->lcfg_command);
1308 if (lcfg->lcfg_flags)
1309 ptr += snprintf(ptr, end - ptr, "flags=%#08x ",
1313 ptr += snprintf(ptr, end - ptr, "num=%#08x ", lcfg->lcfg_num);
1315 if (lcfg->lcfg_nid) {
1316 char nidstr[LNET_NIDSTR_SIZE];
1318 libcfs_nid2str_r(lcfg->lcfg_nid, nidstr, sizeof(nidstr));
1319 ptr += snprintf(ptr, end - ptr, "nid=%s(%#llx)\n ",
1320 nidstr, lcfg->lcfg_nid);
1323 if (lcfg->lcfg_command == LCFG_MARKER) {
1324 struct cfg_marker *marker = lustre_cfg_buf(lcfg, 1);
1326 ptr += snprintf(ptr, end - ptr, "marker=%d(%#x)%s '%s'",
1327 marker->cm_step, marker->cm_flags,
1328 marker->cm_tgtname, marker->cm_comment);
1332 for (i = 0; i < lcfg->lcfg_bufcount; i++) {
1333 ptr += snprintf(ptr, end - ptr, "%d:%s ", i,
1334 lustre_cfg_string(lcfg, i));
1337 ptr += snprintf(ptr, end - ptr, "\n");
1338 /* return consumed bytes */
1343 int class_config_dump_handler(const struct lu_env *env,
1344 struct llog_handle *handle,
1345 struct llog_rec_hdr *rec, void *data)
1350 outstr = kzalloc(256, GFP_NOFS);
1354 if (rec->lrh_type == OBD_CFG_REC) {
1355 class_config_parse_rec(rec, outstr, 256);
1356 LCONSOLE(D_WARNING, " %s", outstr);
1358 LCONSOLE(D_WARNING, "unhandled lrh_type: %#x\n", rec->lrh_type);
1366 /** Call class_cleanup and class_detach.
1367 * "Manual" only in the sense that we're faking lcfg commands.
1369 int class_manual_cleanup(struct obd_device *obd)
1372 struct lustre_cfg *lcfg;
1373 struct lustre_cfg_bufs bufs;
1377 CERROR("empty cleanup\n");
1386 CDEBUG(D_CONFIG, "Manual cleanup of %s (flags='%s')\n",
1387 obd->obd_name, flags);
1389 lustre_cfg_bufs_reset(&bufs, obd->obd_name);
1390 lustre_cfg_bufs_set_string(&bufs, 1, flags);
1391 lcfg = lustre_cfg_new(LCFG_CLEANUP, &bufs);
1395 rc = class_process_config(lcfg);
1397 CERROR("cleanup failed %d: %s\n", rc, obd->obd_name);
1401 /* the lcfg is almost the same for both ops */
1402 lcfg->lcfg_command = LCFG_DETACH;
1403 rc = class_process_config(lcfg);
1405 CERROR("detach failed %d: %s\n", rc, obd->obd_name);
1407 lustre_cfg_free(lcfg);
1410 EXPORT_SYMBOL(class_manual_cleanup);
1413 * uuid<->export lustre hash operations
1417 uuid_hash(struct cfs_hash *hs, const void *key, unsigned mask)
1419 return cfs_hash_djb2_hash(((struct obd_uuid *)key)->uuid,
1420 sizeof(((struct obd_uuid *)key)->uuid), mask);
1424 uuid_key(struct hlist_node *hnode)
1426 struct obd_export *exp;
1428 exp = hlist_entry(hnode, struct obd_export, exp_uuid_hash);
1430 return &exp->exp_client_uuid;
1434 * NOTE: It is impossible to find an export that is in failed
1435 * state with this function
1438 uuid_keycmp(const void *key, struct hlist_node *hnode)
1440 struct obd_export *exp;
1443 exp = hlist_entry(hnode, struct obd_export, exp_uuid_hash);
1445 return obd_uuid_equals(key, &exp->exp_client_uuid) &&
1450 uuid_export_object(struct hlist_node *hnode)
1452 return hlist_entry(hnode, struct obd_export, exp_uuid_hash);
1456 uuid_export_get(struct cfs_hash *hs, struct hlist_node *hnode)
1458 struct obd_export *exp;
1460 exp = hlist_entry(hnode, struct obd_export, exp_uuid_hash);
1461 class_export_get(exp);
1465 uuid_export_put_locked(struct cfs_hash *hs, struct hlist_node *hnode)
1467 struct obd_export *exp;
1469 exp = hlist_entry(hnode, struct obd_export, exp_uuid_hash);
1470 class_export_put(exp);
1473 static struct cfs_hash_ops uuid_hash_ops = {
1474 .hs_hash = uuid_hash,
1476 .hs_keycmp = uuid_keycmp,
1477 .hs_object = uuid_export_object,
1478 .hs_get = uuid_export_get,
1479 .hs_put_locked = uuid_export_put_locked,