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
39 #include <linux/string.h>
41 #include "../include/lustre/lustre_ioctl.h"
42 #include "../include/llog_swab.h"
43 #include "../include/lprocfs_status.h"
44 #include "../include/lustre_log.h"
45 #include "../include/lustre_param.h"
46 #include "../include/obd_class.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.
76 static int class_match_param(char *buf, const char *key, char **valp)
81 if (memcmp(buf, key, strlen(key)) != 0)
85 *valp = buf + strlen(key);
90 static int parse_nid(char *buf, void *value, int quiet)
92 lnet_nid_t *nid = value;
94 *nid = libcfs_str2nid(buf);
95 if (*nid != LNET_NID_ANY)
99 LCONSOLE_ERROR_MSG(0x159, "Can't parse NID '%s'\n", buf);
103 static int parse_net(char *buf, void *value)
107 *net = libcfs_str2net(buf);
108 CDEBUG(D_INFO, "Net %s\n", libcfs_net2str(*net));
120 * endh is set to next separator
122 static int class_parse_value(char *buf, int opc, void *value, char **endh,
131 while (*buf == ',' || *buf == ':')
133 if (*buf == ' ' || *buf == '/' || *buf == '\0')
136 /* nid separators or end of nids */
137 endp = strpbrk(buf, ",: /");
139 endp = buf + strlen(buf);
146 case CLASS_PARSE_NID:
147 rc = parse_nid(buf, value, quiet);
149 case CLASS_PARSE_NET:
150 rc = parse_net(buf, value);
161 int class_parse_nid(char *buf, lnet_nid_t *nid, char **endh)
163 return class_parse_value(buf, CLASS_PARSE_NID, (void *)nid, endh, 0);
165 EXPORT_SYMBOL(class_parse_nid);
167 int class_parse_nid_quiet(char *buf, lnet_nid_t *nid, char **endh)
169 return class_parse_value(buf, CLASS_PARSE_NID, (void *)nid, endh, 1);
171 EXPORT_SYMBOL(class_parse_nid_quiet);
173 /********************** class fns **********************/
176 * Create a new obd device and set the type, name and uuid. If successful,
177 * the new device can be accessed by either name or uuid.
179 static int class_attach(struct lustre_cfg *lcfg)
181 struct obd_device *obd = NULL;
182 char *typename, *name, *uuid;
185 if (!LUSTRE_CFG_BUFLEN(lcfg, 1)) {
186 CERROR("No type passed!\n");
189 typename = lustre_cfg_string(lcfg, 1);
191 if (!LUSTRE_CFG_BUFLEN(lcfg, 0)) {
192 CERROR("No name passed!\n");
195 name = lustre_cfg_string(lcfg, 0);
197 if (!LUSTRE_CFG_BUFLEN(lcfg, 2)) {
198 CERROR("No UUID passed!\n");
201 uuid = lustre_cfg_string(lcfg, 2);
203 CDEBUG(D_IOCTL, "attach type %s name: %s uuid: %s\n",
204 MKSTR(typename), MKSTR(name), MKSTR(uuid));
206 obd = class_newdev(typename, name);
208 /* Already exists or out of obds */
211 CERROR("Cannot create device %s of type %s : %d\n",
215 LASSERTF(obd, "Cannot get obd device %s of type %s\n",
217 LASSERTF(obd->obd_magic == OBD_DEVICE_MAGIC,
218 "obd %p obd_magic %08X != %08X\n",
219 obd, obd->obd_magic, OBD_DEVICE_MAGIC);
220 LASSERTF(strncmp(obd->obd_name, name, strlen(name)) == 0,
221 "%p obd_name %s != %s\n", obd, obd->obd_name, name);
223 rwlock_init(&obd->obd_pool_lock);
224 obd->obd_pool_limit = 0;
225 obd->obd_pool_slv = 0;
227 INIT_LIST_HEAD(&obd->obd_exports);
228 INIT_LIST_HEAD(&obd->obd_unlinked_exports);
229 INIT_LIST_HEAD(&obd->obd_delayed_exports);
230 spin_lock_init(&obd->obd_nid_lock);
231 spin_lock_init(&obd->obd_dev_lock);
232 mutex_init(&obd->obd_dev_mutex);
233 spin_lock_init(&obd->obd_osfs_lock);
234 /* obd->obd_osfs_age must be set to a value in the distant
235 * past to guarantee a fresh statfs is fetched on mount.
237 obd->obd_osfs_age = cfs_time_shift_64(-1000);
239 /* XXX belongs in setup not attach */
240 init_rwsem(&obd->obd_observer_link_sem);
242 init_waitqueue_head(&obd->obd_evict_inprogress_waitq);
244 llog_group_init(&obd->obd_olg);
246 obd->obd_conn_inprogress = 0;
249 if (len >= sizeof(obd->obd_uuid)) {
250 CERROR("uuid must be < %d bytes long\n",
251 (int)sizeof(obd->obd_uuid));
255 memcpy(obd->obd_uuid.uuid, uuid, len);
257 /* Detach drops this */
258 spin_lock(&obd->obd_dev_lock);
259 atomic_set(&obd->obd_refcount, 1);
260 spin_unlock(&obd->obd_dev_lock);
261 lu_ref_init(&obd->obd_reference);
262 lu_ref_add(&obd->obd_reference, "attach", obd);
264 obd->obd_attached = 1;
265 CDEBUG(D_IOCTL, "OBD: dev %d attached type %s with refcount %d\n",
266 obd->obd_minor, typename, atomic_read(&obd->obd_refcount));
270 class_release_dev(obd);
275 /** Create hashes, self-export, and call type-specific setup.
276 * Setup is effectively the "start this obd" call.
278 static int class_setup(struct obd_device *obd, struct lustre_cfg *lcfg)
281 struct obd_export *exp;
284 LASSERTF(obd == class_num2obd(obd->obd_minor),
285 "obd %p != obd_devs[%d] %p\n",
286 obd, obd->obd_minor, class_num2obd(obd->obd_minor));
287 LASSERTF(obd->obd_magic == OBD_DEVICE_MAGIC,
288 "obd %p obd_magic %08x != %08x\n",
289 obd, obd->obd_magic, OBD_DEVICE_MAGIC);
291 /* have we attached a type to this device? */
292 if (!obd->obd_attached) {
293 CERROR("Device %d not attached\n", obd->obd_minor);
297 if (obd->obd_set_up) {
298 CERROR("Device %d already setup (type %s)\n",
299 obd->obd_minor, obd->obd_type->typ_name);
303 /* is someone else setting us up right now? (attach inits spinlock) */
304 spin_lock(&obd->obd_dev_lock);
305 if (obd->obd_starting) {
306 spin_unlock(&obd->obd_dev_lock);
307 CERROR("Device %d setup in progress (type %s)\n",
308 obd->obd_minor, obd->obd_type->typ_name);
311 /* just leave this on forever. I can't use obd_set_up here because
312 * other fns check that status, and we're not actually set up yet.
314 obd->obd_starting = 1;
315 obd->obd_uuid_hash = NULL;
316 spin_unlock(&obd->obd_dev_lock);
318 /* create an uuid-export lustre hash */
319 obd->obd_uuid_hash = cfs_hash_create("UUID_HASH",
322 HASH_UUID_BKT_BITS, 0,
325 &uuid_hash_ops, CFS_HASH_DEFAULT);
326 if (!obd->obd_uuid_hash) {
331 exp = class_new_export(obd, &obd->obd_uuid);
337 obd->obd_self_export = exp;
338 class_export_put(exp);
340 err = obd_setup(obd, lcfg);
346 spin_lock(&obd->obd_dev_lock);
347 /* cleanup drops this */
348 class_incref(obd, "setup", obd);
349 spin_unlock(&obd->obd_dev_lock);
351 CDEBUG(D_IOCTL, "finished setup of obd %s (uuid %s)\n",
352 obd->obd_name, obd->obd_uuid.uuid);
356 if (obd->obd_self_export) {
357 class_unlink_export(obd->obd_self_export);
358 obd->obd_self_export = NULL;
361 if (obd->obd_uuid_hash) {
362 cfs_hash_putref(obd->obd_uuid_hash);
363 obd->obd_uuid_hash = NULL;
365 obd->obd_starting = 0;
366 CERROR("setup %s failed (%d)\n", obd->obd_name, err);
370 /** We have finished using this obd and are ready to destroy it.
371 * There can be no more references to this obd.
373 static int class_detach(struct obd_device *obd, struct lustre_cfg *lcfg)
375 if (obd->obd_set_up) {
376 CERROR("OBD device %d still set up\n", obd->obd_minor);
380 spin_lock(&obd->obd_dev_lock);
381 if (!obd->obd_attached) {
382 spin_unlock(&obd->obd_dev_lock);
383 CERROR("OBD device %d not attached\n", obd->obd_minor);
386 obd->obd_attached = 0;
387 spin_unlock(&obd->obd_dev_lock);
389 CDEBUG(D_IOCTL, "detach on obd %s (uuid %s)\n",
390 obd->obd_name, obd->obd_uuid.uuid);
392 class_decref(obd, "attach", obd);
396 /** Start shutting down the obd. There may be in-progress ops when
397 * this is called. We tell them to start shutting down with a call
398 * to class_disconnect_exports().
400 static int class_cleanup(struct obd_device *obd, struct lustre_cfg *lcfg)
405 OBD_RACE(OBD_FAIL_LDLM_RECOV_CLIENTS);
407 if (!obd->obd_set_up) {
408 CERROR("Device %d not setup\n", obd->obd_minor);
412 spin_lock(&obd->obd_dev_lock);
413 if (obd->obd_stopping) {
414 spin_unlock(&obd->obd_dev_lock);
415 CERROR("OBD %d already stopping\n", obd->obd_minor);
418 /* Leave this on forever */
419 obd->obd_stopping = 1;
420 spin_unlock(&obd->obd_dev_lock);
422 while (obd->obd_conn_inprogress > 0)
426 if (lcfg->lcfg_bufcount >= 2 && LUSTRE_CFG_BUFLEN(lcfg, 1) > 0) {
427 for (flag = lustre_cfg_string(lcfg, 1); *flag != 0; flag++)
433 LCONSOLE_WARN("Failing over %s\n",
436 obd->obd_no_transno = 1;
437 obd->obd_no_recov = 1;
438 if (OBP(obd, iocontrol)) {
439 obd_iocontrol(OBD_IOC_SYNC,
440 obd->obd_self_export,
445 CERROR("Unrecognised flag '%c'\n", *flag);
449 LASSERT(obd->obd_self_export);
451 /* Precleanup, we must make sure all exports get destroyed. */
452 err = obd_precleanup(obd);
454 CERROR("Precleanup %s returned %d\n",
457 /* destroy an uuid-export hash body */
458 if (obd->obd_uuid_hash) {
459 cfs_hash_putref(obd->obd_uuid_hash);
460 obd->obd_uuid_hash = NULL;
463 class_decref(obd, "setup", obd);
469 struct obd_device *class_incref(struct obd_device *obd,
470 const char *scope, const void *source)
472 lu_ref_add_atomic(&obd->obd_reference, scope, source);
473 atomic_inc(&obd->obd_refcount);
474 CDEBUG(D_INFO, "incref %s (%p) now %d\n", obd->obd_name, obd,
475 atomic_read(&obd->obd_refcount));
479 EXPORT_SYMBOL(class_incref);
481 void class_decref(struct obd_device *obd, const char *scope, const void *source)
486 spin_lock(&obd->obd_dev_lock);
487 atomic_dec(&obd->obd_refcount);
488 refs = atomic_read(&obd->obd_refcount);
489 spin_unlock(&obd->obd_dev_lock);
490 lu_ref_del(&obd->obd_reference, scope, source);
492 CDEBUG(D_INFO, "Decref %s (%p) now %d\n", obd->obd_name, obd, refs);
494 if ((refs == 1) && obd->obd_stopping) {
495 /* All exports have been destroyed; there should
496 * be no more in-progress ops by this point.
499 spin_lock(&obd->obd_self_export->exp_lock);
500 obd->obd_self_export->exp_flags |= exp_flags_from_obd(obd);
501 spin_unlock(&obd->obd_self_export->exp_lock);
503 /* note that we'll recurse into class_decref again */
504 class_unlink_export(obd->obd_self_export);
509 CDEBUG(D_CONFIG, "finishing cleanup of obd %s (%s)\n",
510 obd->obd_name, obd->obd_uuid.uuid);
511 LASSERT(!obd->obd_attached);
512 if (obd->obd_stopping) {
513 /* If we're not stopping, we were never set up */
514 err = obd_cleanup(obd);
516 CERROR("Cleanup %s returned %d\n",
519 class_release_dev(obd);
522 EXPORT_SYMBOL(class_decref);
524 /** Add a failover nid location.
525 * Client obd types contact server obd types using this nid list.
527 static int class_add_conn(struct obd_device *obd, struct lustre_cfg *lcfg)
529 struct obd_import *imp;
530 struct obd_uuid uuid;
533 if (LUSTRE_CFG_BUFLEN(lcfg, 1) < 1 ||
534 LUSTRE_CFG_BUFLEN(lcfg, 1) > sizeof(struct obd_uuid)) {
535 CERROR("invalid conn_uuid\n");
538 if (strcmp(obd->obd_type->typ_name, LUSTRE_MDC_NAME) &&
539 strcmp(obd->obd_type->typ_name, LUSTRE_OSC_NAME) &&
540 strcmp(obd->obd_type->typ_name, LUSTRE_OSP_NAME) &&
541 strcmp(obd->obd_type->typ_name, LUSTRE_LWP_NAME) &&
542 strcmp(obd->obd_type->typ_name, LUSTRE_MGC_NAME)) {
543 CERROR("can't add connection on non-client dev\n");
547 imp = obd->u.cli.cl_import;
549 CERROR("try to add conn on immature client dev\n");
553 obd_str2uuid(&uuid, lustre_cfg_string(lcfg, 1));
554 rc = obd_add_conn(imp, &uuid, lcfg->lcfg_num);
559 /** Remove a failover nid location.
561 static int class_del_conn(struct obd_device *obd, struct lustre_cfg *lcfg)
563 struct obd_import *imp;
564 struct obd_uuid uuid;
567 if (LUSTRE_CFG_BUFLEN(lcfg, 1) < 1 ||
568 LUSTRE_CFG_BUFLEN(lcfg, 1) > sizeof(struct obd_uuid)) {
569 CERROR("invalid conn_uuid\n");
572 if (strcmp(obd->obd_type->typ_name, LUSTRE_MDC_NAME) &&
573 strcmp(obd->obd_type->typ_name, LUSTRE_OSC_NAME)) {
574 CERROR("can't del connection on non-client dev\n");
578 imp = obd->u.cli.cl_import;
580 CERROR("try to del conn on immature client dev\n");
584 obd_str2uuid(&uuid, lustre_cfg_string(lcfg, 1));
585 rc = obd_del_conn(imp, &uuid);
590 static LIST_HEAD(lustre_profile_list);
591 static DEFINE_SPINLOCK(lustre_profile_list_lock);
593 struct lustre_profile *class_get_profile(const char *prof)
595 struct lustre_profile *lprof;
597 spin_lock(&lustre_profile_list_lock);
598 list_for_each_entry(lprof, &lustre_profile_list, lp_list) {
599 if (!strcmp(lprof->lp_profile, prof)) {
601 spin_unlock(&lustre_profile_list_lock);
605 spin_unlock(&lustre_profile_list_lock);
608 EXPORT_SYMBOL(class_get_profile);
610 /** Create a named "profile".
611 * This defines the mdc and osc names to use for a client.
612 * This also is used to define the lov to be used by a mdt.
614 static int class_add_profile(int proflen, char *prof, int osclen, char *osc,
615 int mdclen, char *mdc)
617 struct lustre_profile *lprof;
620 CDEBUG(D_CONFIG, "Add profile %s\n", prof);
622 lprof = kzalloc(sizeof(*lprof), GFP_NOFS);
625 INIT_LIST_HEAD(&lprof->lp_list);
627 LASSERT(proflen == (strlen(prof) + 1));
628 lprof->lp_profile = kmemdup(prof, proflen, GFP_NOFS);
629 if (!lprof->lp_profile) {
634 LASSERT(osclen == (strlen(osc) + 1));
635 lprof->lp_dt = kmemdup(osc, osclen, GFP_NOFS);
638 goto free_lp_profile;
642 LASSERT(mdclen == (strlen(mdc) + 1));
643 lprof->lp_md = kmemdup(mdc, mdclen, GFP_NOFS);
650 spin_lock(&lustre_profile_list_lock);
652 lprof->lp_list_deleted = false;
653 list_add(&lprof->lp_list, &lustre_profile_list);
654 spin_unlock(&lustre_profile_list_lock);
660 kfree(lprof->lp_profile);
666 void class_del_profile(const char *prof)
668 struct lustre_profile *lprof;
670 CDEBUG(D_CONFIG, "Del profile %s\n", prof);
672 lprof = class_get_profile(prof);
674 spin_lock(&lustre_profile_list_lock);
675 /* because get profile increments the ref counter */
677 list_del(&lprof->lp_list);
678 lprof->lp_list_deleted = true;
679 spin_unlock(&lustre_profile_list_lock);
681 class_put_profile(lprof);
684 EXPORT_SYMBOL(class_del_profile);
686 void class_put_profile(struct lustre_profile *lprof)
688 spin_lock(&lustre_profile_list_lock);
689 if (--lprof->lp_refs > 0) {
690 LASSERT(lprof->lp_refs > 0);
691 spin_unlock(&lustre_profile_list_lock);
694 spin_unlock(&lustre_profile_list_lock);
696 /* confirm not a negative number */
697 LASSERT(!lprof->lp_refs);
700 * At least one class_del_profile/profiles must be called
701 * on the target profile or lustre_profile_list will corrupt
703 LASSERT(lprof->lp_list_deleted);
704 kfree(lprof->lp_profile);
709 EXPORT_SYMBOL(class_put_profile);
712 void class_del_profiles(void)
714 struct lustre_profile *lprof, *n;
716 spin_lock(&lustre_profile_list_lock);
717 list_for_each_entry_safe(lprof, n, &lustre_profile_list, lp_list) {
718 list_del(&lprof->lp_list);
719 lprof->lp_list_deleted = true;
720 spin_unlock(&lustre_profile_list_lock);
722 class_put_profile(lprof);
724 spin_lock(&lustre_profile_list_lock);
726 spin_unlock(&lustre_profile_list_lock);
728 EXPORT_SYMBOL(class_del_profiles);
730 static int class_set_global(char *ptr, int val, struct lustre_cfg *lcfg)
732 if (class_match_param(ptr, PARAM_AT_MIN, NULL) == 0)
734 else if (class_match_param(ptr, PARAM_AT_MAX, NULL) == 0)
736 else if (class_match_param(ptr, PARAM_AT_EXTRA, NULL) == 0)
738 else if (class_match_param(ptr, PARAM_AT_EARLY_MARGIN, NULL) == 0)
739 at_early_margin = val;
740 else if (class_match_param(ptr, PARAM_AT_HISTORY, NULL) == 0)
742 else if (class_match_param(ptr, PARAM_JOBID_VAR, NULL) == 0)
743 strlcpy(obd_jobid_var, lustre_cfg_string(lcfg, 2),
744 JOBSTATS_JOBID_VAR_MAX_LEN + 1);
748 CDEBUG(D_IOCTL, "global %s = %d\n", ptr, val);
752 /* We can't call ll_process_config or lquota_process_config directly because
753 * it lives in a module that must be loaded after this one.
755 static int (*client_process_config)(struct lustre_cfg *lcfg);
756 static int (*quota_process_config)(struct lustre_cfg *lcfg);
758 void lustre_register_client_process_config(int (*cpc)(struct lustre_cfg *lcfg))
760 client_process_config = cpc;
762 EXPORT_SYMBOL(lustre_register_client_process_config);
764 static int process_param2_config(struct lustre_cfg *lcfg)
766 char *param = lustre_cfg_string(lcfg, 1);
767 char *upcall = lustre_cfg_string(lcfg, 2);
769 [0] = "/usr/sbin/lctl",
778 /* Add upcall processing here. Now only lctl is supported */
779 if (strcmp(upcall, LCTL_UPCALL) != 0) {
780 CERROR("Unsupported upcall %s\n", upcall);
785 rc = call_usermodehelper(argv[0], argv, NULL, UMH_WAIT_PROC);
790 "lctl: error invoking upcall %s %s %s: rc = %d; time %ldus\n",
791 argv[0], argv[1], argv[2], rc,
792 (long)ktime_us_delta(end, start));
794 CDEBUG(D_HA, "lctl: invoked upcall %s %s %s, time %ldus\n",
795 argv[0], argv[1], argv[2],
796 (long)ktime_us_delta(end, start));
803 /** Process configuration commands given in lustre_cfg form.
804 * These may come from direct calls (e.g. class_manual_cleanup)
805 * or processing the config llog, or ioctl from lctl.
807 int class_process_config(struct lustre_cfg *lcfg)
809 struct obd_device *obd;
812 LASSERT(lcfg && !IS_ERR(lcfg));
813 CDEBUG(D_IOCTL, "processing cmd: %x\n", lcfg->lcfg_command);
815 /* Commands that don't need a device */
816 switch (lcfg->lcfg_command) {
818 err = class_attach(lcfg);
821 case LCFG_ADD_UUID: {
822 CDEBUG(D_IOCTL, "adding mapping from uuid %s to nid %#llx (%s)\n",
823 lustre_cfg_string(lcfg, 1), lcfg->lcfg_nid,
824 libcfs_nid2str(lcfg->lcfg_nid));
826 err = class_add_uuid(lustre_cfg_string(lcfg, 1), lcfg->lcfg_nid);
829 case LCFG_DEL_UUID: {
830 CDEBUG(D_IOCTL, "removing mappings for uuid %s\n",
831 (lcfg->lcfg_bufcount < 2 || LUSTRE_CFG_BUFLEN(lcfg, 1) == 0)
832 ? "<all uuids>" : lustre_cfg_string(lcfg, 1));
834 err = class_del_uuid(lustre_cfg_string(lcfg, 1));
837 case LCFG_MOUNTOPT: {
838 CDEBUG(D_IOCTL, "mountopt: profile %s osc %s mdc %s\n",
839 lustre_cfg_string(lcfg, 1),
840 lustre_cfg_string(lcfg, 2),
841 lustre_cfg_string(lcfg, 3));
842 /* set these mount options somewhere, so ll_fill_super
845 err = class_add_profile(LUSTRE_CFG_BUFLEN(lcfg, 1),
846 lustre_cfg_string(lcfg, 1),
847 LUSTRE_CFG_BUFLEN(lcfg, 2),
848 lustre_cfg_string(lcfg, 2),
849 LUSTRE_CFG_BUFLEN(lcfg, 3),
850 lustre_cfg_string(lcfg, 3));
853 case LCFG_DEL_MOUNTOPT: {
854 CDEBUG(D_IOCTL, "mountopt: profile %s\n",
855 lustre_cfg_string(lcfg, 1));
856 class_del_profile(lustre_cfg_string(lcfg, 1));
860 case LCFG_SET_TIMEOUT: {
861 CDEBUG(D_IOCTL, "changing lustre timeout from %d to %d\n",
862 obd_timeout, lcfg->lcfg_num);
863 obd_timeout = max(lcfg->lcfg_num, 1U);
868 case LCFG_SET_LDLM_TIMEOUT: {
869 /* ldlm_timeout is not used on the client */
873 case LCFG_SET_UPCALL: {
874 LCONSOLE_ERROR_MSG(0x15a, "recovery upcall is deprecated\n");
875 /* COMPAT_146 Don't fail on old configs */
880 struct cfg_marker *marker;
882 marker = lustre_cfg_buf(lcfg, 1);
883 CDEBUG(D_IOCTL, "marker %d (%#x) %.16s %s\n", marker->cm_step,
884 marker->cm_flags, marker->cm_tgtname, marker->cm_comment);
890 /* llite has no obd */
891 if ((class_match_param(lustre_cfg_string(lcfg, 1),
892 PARAM_LLITE, NULL) == 0) &&
893 client_process_config) {
894 err = (*client_process_config)(lcfg);
896 } else if ((class_match_param(lustre_cfg_string(lcfg, 1),
897 PARAM_SYS, &tmp) == 0)) {
898 /* Global param settings */
899 err = class_set_global(tmp, lcfg->lcfg_num, lcfg);
901 * Client or server should not fail to mount if
902 * it hits an unknown configuration parameter.
905 CWARN("Ignoring unknown param %s\n", tmp);
909 } else if ((class_match_param(lustre_cfg_string(lcfg, 1),
910 PARAM_QUOTA, &tmp) == 0) &&
911 quota_process_config) {
912 err = (*quota_process_config)(lcfg);
918 case LCFG_SET_PARAM: {
919 err = process_param2_config(lcfg);
923 /* Commands that require a device */
924 obd = class_name2obd(lustre_cfg_string(lcfg, 0));
926 if (!LUSTRE_CFG_BUFLEN(lcfg, 0))
927 CERROR("this lcfg command requires a device name\n");
929 CERROR("no device for: %s\n",
930 lustre_cfg_string(lcfg, 0));
936 switch (lcfg->lcfg_command) {
938 err = class_setup(obd, lcfg);
942 err = class_detach(obd, lcfg);
947 err = class_cleanup(obd, lcfg);
951 case LCFG_ADD_CONN: {
952 err = class_add_conn(obd, lcfg);
956 case LCFG_DEL_CONN: {
957 err = class_del_conn(obd, lcfg);
961 case LCFG_POOL_NEW: {
962 err = obd_pool_new(obd, lustre_cfg_string(lcfg, 2));
966 case LCFG_POOL_ADD: {
967 err = obd_pool_add(obd, lustre_cfg_string(lcfg, 2),
968 lustre_cfg_string(lcfg, 3));
972 case LCFG_POOL_REM: {
973 err = obd_pool_rem(obd, lustre_cfg_string(lcfg, 2),
974 lustre_cfg_string(lcfg, 3));
978 case LCFG_POOL_DEL: {
979 err = obd_pool_del(obd, lustre_cfg_string(lcfg, 2));
984 err = obd_process_config(obd, sizeof(*lcfg), lcfg);
989 if ((err < 0) && !(lcfg->lcfg_command & LCFG_REQUIRED)) {
990 CWARN("Ignoring error %d on optional command %#x\n", err,
996 EXPORT_SYMBOL(class_process_config);
998 int class_process_proc_param(char *prefix, struct lprocfs_vars *lvars,
999 struct lustre_cfg *lcfg, void *data)
1001 struct lprocfs_vars *var;
1002 struct file fakefile;
1003 struct seq_file fake_seqfile;
1005 int i, keylen, vallen;
1006 int matched = 0, j = 0;
1010 if (lcfg->lcfg_command != LCFG_PARAM) {
1011 CERROR("Unknown command: %d\n", lcfg->lcfg_command);
1015 /* fake a seq file so that var->fops->write can work... */
1016 fakefile.private_data = &fake_seqfile;
1017 fake_seqfile.private = data;
1018 /* e.g. tunefs.lustre --param mdt.group_upcall=foo /r/tmp/lustre-mdt
1019 * or lctl conf_param lustre-MDT0000.mdt.group_upcall=bar
1020 * or lctl conf_param lustre-OST0000.osc.max_dirty_mb=36
1022 for (i = 1; i < lcfg->lcfg_bufcount; i++) {
1023 key = lustre_cfg_buf(lcfg, i);
1024 /* Strip off prefix */
1025 if (class_match_param(key, prefix, &key)) {
1027 * If the prefix doesn't match, return error so we
1028 * can pass it down the stack
1032 sval = strchr(key, '=');
1033 if (!sval || (*(sval + 1) == 0)) {
1034 CERROR("Can't parse param %s (missing '=')\n", key);
1035 /* rc = -EINVAL; continue parsing other params */
1038 keylen = sval - key;
1040 vallen = strlen(sval);
1043 /* Search proc entries */
1044 while (lvars[j].name) {
1046 if (!class_match_param(key, var->name, NULL) &&
1047 keylen == strlen(var->name)) {
1050 if (var->fops && var->fops->write) {
1055 rc = var->fops->write(&fakefile, sval,
1064 CERROR("%.*s: %s unknown param %s\n",
1065 (int)strlen(prefix) - 1, prefix,
1066 (char *)lustre_cfg_string(lcfg, 0), key);
1067 /* rc = -EINVAL; continue parsing other params */
1069 } else if (rc < 0) {
1070 CERROR("%s: error writing proc entry '%s': rc = %d\n",
1071 prefix, var->name, rc);
1074 CDEBUG(D_CONFIG, "%s.%.*s: Set parameter %.*s=%s\n",
1075 lustre_cfg_string(lcfg, 0),
1076 (int)strlen(prefix) - 1, prefix,
1077 (int)(sval - key - 1), key, sval);
1087 EXPORT_SYMBOL(class_process_proc_param);
1089 /** Parse a configuration llog, doing various manipulations on them
1090 * for various reasons, (modifications for compatibility, skip obsolete
1091 * records, change uuids, etc), then class_process_config() resulting
1094 int class_config_llog_handler(const struct lu_env *env,
1095 struct llog_handle *handle,
1096 struct llog_rec_hdr *rec, void *data)
1098 struct config_llog_instance *clli = data;
1099 int cfg_len = rec->lrh_len;
1100 char *cfg_buf = (char *)(rec + 1);
1103 switch (rec->lrh_type) {
1105 struct lustre_cfg *lcfg, *lcfg_new;
1106 struct lustre_cfg_bufs bufs;
1107 char *inst_name = NULL;
1109 int inst = 0, swab = 0;
1111 lcfg = (struct lustre_cfg *)cfg_buf;
1112 if (lcfg->lcfg_version == __swab32(LUSTRE_CFG_VERSION)) {
1113 lustre_swab_lustre_cfg(lcfg);
1117 rc = lustre_cfg_sanity_check(cfg_buf, cfg_len);
1121 /* Figure out config state info */
1122 if (lcfg->lcfg_command == LCFG_MARKER) {
1123 struct cfg_marker *marker = lustre_cfg_buf(lcfg, 1);
1125 lustre_swab_cfg_marker(marker, swab,
1126 LUSTRE_CFG_BUFLEN(lcfg, 1));
1127 CDEBUG(D_CONFIG, "Marker, inst_flg=%#x mark_flg=%#x\n",
1128 clli->cfg_flags, marker->cm_flags);
1129 if (marker->cm_flags & CM_START) {
1130 /* all previous flags off */
1131 clli->cfg_flags = CFG_F_MARKER;
1132 if (marker->cm_flags & CM_SKIP) {
1133 clli->cfg_flags |= CFG_F_SKIP;
1134 CDEBUG(D_CONFIG, "SKIP #%d\n",
1136 } else if ((marker->cm_flags & CM_EXCLUDE) ||
1138 lustre_check_exclusion(clli->cfg_sb,
1139 marker->cm_tgtname))) {
1140 clli->cfg_flags |= CFG_F_EXCLUDE;
1141 CDEBUG(D_CONFIG, "EXCLUDE %d\n",
1144 } else if (marker->cm_flags & CM_END) {
1145 clli->cfg_flags = 0;
1148 /* A config command without a start marker before it is
1149 * illegal (post 146)
1151 if (!(clli->cfg_flags & CFG_F_COMPAT146) &&
1152 !(clli->cfg_flags & CFG_F_MARKER) &&
1153 (lcfg->lcfg_command != LCFG_MARKER)) {
1154 CWARN("Config not inside markers, ignoring! (inst: %p, uuid: %s, flags: %#x)\n",
1156 clli->cfg_uuid.uuid, clli->cfg_flags);
1157 clli->cfg_flags |= CFG_F_SKIP;
1159 if (clli->cfg_flags & CFG_F_SKIP) {
1160 CDEBUG(D_CONFIG, "skipping %#x\n",
1163 /* No processing! */
1168 * For interoperability between 1.8 and 2.0,
1169 * rename "mds" obd device type to "mdt".
1172 char *typename = lustre_cfg_string(lcfg, 1);
1173 char *index = lustre_cfg_string(lcfg, 2);
1175 if ((lcfg->lcfg_command == LCFG_ATTACH && typename &&
1176 strcmp(typename, "mds") == 0)) {
1177 CWARN("For 1.8 interoperability, rename obd type from mds to mdt\n");
1180 if ((lcfg->lcfg_command == LCFG_SETUP && index &&
1181 strcmp(index, "type") == 0)) {
1182 CDEBUG(D_INFO, "For 1.8 interoperability, set this index to '0'\n");
1188 if (clli->cfg_flags & CFG_F_EXCLUDE) {
1189 CDEBUG(D_CONFIG, "cmd: %x marked EXCLUDED\n",
1190 lcfg->lcfg_command);
1191 if (lcfg->lcfg_command == LCFG_LOV_ADD_OBD)
1192 /* Add inactive instead */
1193 lcfg->lcfg_command = LCFG_LOV_ADD_INA;
1196 lustre_cfg_bufs_init(&bufs, lcfg);
1198 if (clli && clli->cfg_instance &&
1199 LUSTRE_CFG_BUFLEN(lcfg, 0) > 0) {
1201 inst_len = LUSTRE_CFG_BUFLEN(lcfg, 0) +
1202 sizeof(clli->cfg_instance) * 2 + 4;
1203 inst_name = kasprintf(GFP_NOFS, "%s-%p",
1204 lustre_cfg_string(lcfg, 0),
1205 clli->cfg_instance);
1210 lustre_cfg_bufs_set_string(&bufs, 0, inst_name);
1211 CDEBUG(D_CONFIG, "cmd %x, instance name: %s\n",
1212 lcfg->lcfg_command, inst_name);
1215 /* we override the llog's uuid for clients, to insure they
1218 if (clli && clli->cfg_instance &&
1219 lcfg->lcfg_command == LCFG_ATTACH) {
1220 lustre_cfg_bufs_set_string(&bufs, 2,
1221 clli->cfg_uuid.uuid);
1224 * sptlrpc config record, we expect 2 data segments:
1225 * [0]: fs_name/target_name,
1227 * moving them to index [1] and [2], and insert MGC's
1228 * obdname at index [0].
1230 if (clli && !clli->cfg_instance &&
1231 lcfg->lcfg_command == LCFG_SPTLRPC_CONF) {
1232 lustre_cfg_bufs_set(&bufs, 2, bufs.lcfg_buf[1],
1233 bufs.lcfg_buflen[1]);
1234 lustre_cfg_bufs_set(&bufs, 1, bufs.lcfg_buf[0],
1235 bufs.lcfg_buflen[0]);
1236 lustre_cfg_bufs_set_string(&bufs, 0,
1240 lcfg_new = lustre_cfg_new(lcfg->lcfg_command, &bufs);
1242 lcfg_new->lcfg_num = lcfg->lcfg_num;
1243 lcfg_new->lcfg_flags = lcfg->lcfg_flags;
1245 /* XXX Hack to try to remain binary compatible with
1246 * pre-newconfig logs
1248 if (lcfg->lcfg_nal != 0 && /* pre-newconfig log? */
1249 (lcfg->lcfg_nid >> 32) == 0) {
1250 __u32 addr = (__u32)(lcfg->lcfg_nid & 0xffffffff);
1252 lcfg_new->lcfg_nid =
1253 LNET_MKNID(LNET_MKNET(lcfg->lcfg_nal, 0), addr);
1254 CWARN("Converted pre-newconfig NAL %d NID %x to %s\n",
1255 lcfg->lcfg_nal, addr,
1256 libcfs_nid2str(lcfg_new->lcfg_nid));
1258 lcfg_new->lcfg_nid = lcfg->lcfg_nid;
1261 lcfg_new->lcfg_nal = 0; /* illegal value for obsolete field */
1263 rc = class_process_config(lcfg_new);
1264 lustre_cfg_free(lcfg_new);
1271 CERROR("Unknown llog record type %#x encountered\n",
1277 CERROR("%s: cfg command failed: rc = %d\n",
1278 handle->lgh_ctxt->loc_obd->obd_name, rc);
1279 class_config_dump_handler(NULL, handle, rec, data);
1283 EXPORT_SYMBOL(class_config_llog_handler);
1285 int class_config_parse_llog(const struct lu_env *env, struct llog_ctxt *ctxt,
1286 char *name, struct config_llog_instance *cfg)
1288 struct llog_process_cat_data cd = {0, 0};
1289 struct llog_handle *llh;
1293 CDEBUG(D_INFO, "looking up llog %s\n", name);
1294 rc = llog_open(env, ctxt, &llh, NULL, name, LLOG_OPEN_EXISTS);
1298 rc = llog_init_handle(env, llh, LLOG_F_IS_PLAIN, NULL);
1302 /* continue processing from where we last stopped to end-of-log */
1304 cd.lpcd_first_idx = cfg->cfg_last_idx;
1305 callback = cfg->cfg_callback;
1308 callback = class_config_llog_handler;
1311 cd.lpcd_last_idx = 0;
1313 rc = llog_process(env, llh, callback, cfg, &cd);
1315 CDEBUG(D_CONFIG, "Processed log %s gen %d-%d (rc=%d)\n", name,
1316 cd.lpcd_first_idx + 1, cd.lpcd_last_idx, rc);
1318 cfg->cfg_last_idx = cd.lpcd_last_idx;
1321 llog_close(env, llh);
1324 EXPORT_SYMBOL(class_config_parse_llog);
1327 * parse config record and output dump in supplied buffer.
1328 * This is separated from class_config_dump_handler() to use
1329 * for ioctl needs as well
1331 static int class_config_parse_rec(struct llog_rec_hdr *rec, char *buf,
1334 struct lustre_cfg *lcfg = (struct lustre_cfg *)(rec + 1);
1336 char *end = buf + size;
1339 LASSERT(rec->lrh_type == OBD_CFG_REC);
1340 rc = lustre_cfg_sanity_check(lcfg, rec->lrh_len);
1344 ptr += snprintf(ptr, end - ptr, "cmd=%05x ", lcfg->lcfg_command);
1345 if (lcfg->lcfg_flags)
1346 ptr += snprintf(ptr, end - ptr, "flags=%#08x ",
1350 ptr += snprintf(ptr, end - ptr, "num=%#08x ", lcfg->lcfg_num);
1352 if (lcfg->lcfg_nid) {
1353 char nidstr[LNET_NIDSTR_SIZE];
1355 libcfs_nid2str_r(lcfg->lcfg_nid, nidstr, sizeof(nidstr));
1356 ptr += snprintf(ptr, end - ptr, "nid=%s(%#llx)\n ",
1357 nidstr, lcfg->lcfg_nid);
1360 if (lcfg->lcfg_command == LCFG_MARKER) {
1361 struct cfg_marker *marker = lustre_cfg_buf(lcfg, 1);
1363 ptr += snprintf(ptr, end - ptr, "marker=%d(%#x)%s '%s'",
1364 marker->cm_step, marker->cm_flags,
1365 marker->cm_tgtname, marker->cm_comment);
1369 for (i = 0; i < lcfg->lcfg_bufcount; i++) {
1370 ptr += snprintf(ptr, end - ptr, "%d:%s ", i,
1371 lustre_cfg_string(lcfg, i));
1374 ptr += snprintf(ptr, end - ptr, "\n");
1375 /* return consumed bytes */
1380 int class_config_dump_handler(const struct lu_env *env,
1381 struct llog_handle *handle,
1382 struct llog_rec_hdr *rec, void *data)
1387 outstr = kzalloc(256, GFP_NOFS);
1391 if (rec->lrh_type == OBD_CFG_REC) {
1392 class_config_parse_rec(rec, outstr, 256);
1393 LCONSOLE(D_WARNING, " %s", outstr);
1395 LCONSOLE(D_WARNING, "unhandled lrh_type: %#x\n", rec->lrh_type);
1403 /** Call class_cleanup and class_detach.
1404 * "Manual" only in the sense that we're faking lcfg commands.
1406 int class_manual_cleanup(struct obd_device *obd)
1409 struct lustre_cfg *lcfg;
1410 struct lustre_cfg_bufs bufs;
1414 CERROR("empty cleanup\n");
1423 CDEBUG(D_CONFIG, "Manual cleanup of %s (flags='%s')\n",
1424 obd->obd_name, flags);
1426 lustre_cfg_bufs_reset(&bufs, obd->obd_name);
1427 lustre_cfg_bufs_set_string(&bufs, 1, flags);
1428 lcfg = lustre_cfg_new(LCFG_CLEANUP, &bufs);
1432 rc = class_process_config(lcfg);
1434 CERROR("cleanup failed %d: %s\n", rc, obd->obd_name);
1438 /* the lcfg is almost the same for both ops */
1439 lcfg->lcfg_command = LCFG_DETACH;
1440 rc = class_process_config(lcfg);
1442 CERROR("detach failed %d: %s\n", rc, obd->obd_name);
1444 lustre_cfg_free(lcfg);
1447 EXPORT_SYMBOL(class_manual_cleanup);
1450 * uuid<->export lustre hash operations
1454 uuid_hash(struct cfs_hash *hs, const void *key, unsigned int mask)
1456 return cfs_hash_djb2_hash(((struct obd_uuid *)key)->uuid,
1457 sizeof(((struct obd_uuid *)key)->uuid), mask);
1461 uuid_key(struct hlist_node *hnode)
1463 struct obd_export *exp;
1465 exp = hlist_entry(hnode, struct obd_export, exp_uuid_hash);
1467 return &exp->exp_client_uuid;
1471 * NOTE: It is impossible to find an export that is in failed
1472 * state with this function
1475 uuid_keycmp(const void *key, struct hlist_node *hnode)
1477 struct obd_export *exp;
1480 exp = hlist_entry(hnode, struct obd_export, exp_uuid_hash);
1482 return obd_uuid_equals(key, &exp->exp_client_uuid) &&
1487 uuid_export_object(struct hlist_node *hnode)
1489 return hlist_entry(hnode, struct obd_export, exp_uuid_hash);
1493 uuid_export_get(struct cfs_hash *hs, struct hlist_node *hnode)
1495 struct obd_export *exp;
1497 exp = hlist_entry(hnode, struct obd_export, exp_uuid_hash);
1498 class_export_get(exp);
1502 uuid_export_put_locked(struct cfs_hash *hs, struct hlist_node *hnode)
1504 struct obd_export *exp;
1506 exp = hlist_entry(hnode, struct obd_export, exp_uuid_hash);
1507 class_export_put(exp);
1510 static struct cfs_hash_ops uuid_hash_ops = {
1511 .hs_hash = uuid_hash,
1513 .hs_keycmp = uuid_keycmp,
1514 .hs_object = uuid_export_object,
1515 .hs_get = uuid_export_get,
1516 .hs_put_locked = uuid_export_put_locked,