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 <uapi/linux/lustre/lustre_ioctl.h>
42 #include <llog_swab.h>
43 #include <lprocfs_status.h>
44 #include <lustre_log.h>
45 #include <uapi/linux/lustre/lustre_param.h>
46 #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 char *lustre_cfg_string(struct lustre_cfg *lcfg, u32 index)
177 if (!lcfg->lcfg_buflens[index])
180 s = lustre_cfg_buf(lcfg, index);
185 * make sure it's NULL terminated, even if this kills a char
186 * of data. Try to use the padding first though.
188 if (s[lcfg->lcfg_buflens[index] - 1] != '\0') {
189 size_t last = ALIGN(lcfg->lcfg_buflens[index], 8) - 1;
192 /* Use the smaller value */
193 if (last > lcfg->lcfg_buflens[index])
194 last = lcfg->lcfg_buflens[index];
199 CWARN("Truncated buf %d to '%s' (lost '%c'...)\n",
205 EXPORT_SYMBOL(lustre_cfg_string);
207 /********************** class fns **********************/
210 * Create a new obd device and set the type, name and uuid. If successful,
211 * the new device can be accessed by either name or uuid.
213 static int class_attach(struct lustre_cfg *lcfg)
215 struct obd_device *obd = NULL;
216 char *typename, *name, *uuid;
219 if (!LUSTRE_CFG_BUFLEN(lcfg, 1)) {
220 CERROR("No type passed!\n");
223 typename = lustre_cfg_string(lcfg, 1);
225 if (!LUSTRE_CFG_BUFLEN(lcfg, 0)) {
226 CERROR("No name passed!\n");
229 name = lustre_cfg_string(lcfg, 0);
231 if (!LUSTRE_CFG_BUFLEN(lcfg, 2)) {
232 CERROR("No UUID passed!\n");
235 uuid = lustre_cfg_string(lcfg, 2);
237 CDEBUG(D_IOCTL, "attach type %s name: %s uuid: %s\n",
238 MKSTR(typename), MKSTR(name), MKSTR(uuid));
240 obd = class_newdev(typename, name);
242 /* Already exists or out of obds */
245 CERROR("Cannot create device %s of type %s : %d\n",
249 LASSERTF(obd, "Cannot get obd device %s of type %s\n",
251 LASSERTF(obd->obd_magic == OBD_DEVICE_MAGIC,
252 "obd %p obd_magic %08X != %08X\n",
253 obd, obd->obd_magic, OBD_DEVICE_MAGIC);
254 LASSERTF(strncmp(obd->obd_name, name, strlen(name)) == 0,
255 "%p obd_name %s != %s\n", obd, obd->obd_name, name);
257 rwlock_init(&obd->obd_pool_lock);
258 obd->obd_pool_limit = 0;
259 obd->obd_pool_slv = 0;
261 INIT_LIST_HEAD(&obd->obd_exports);
262 INIT_LIST_HEAD(&obd->obd_unlinked_exports);
263 INIT_LIST_HEAD(&obd->obd_delayed_exports);
264 spin_lock_init(&obd->obd_nid_lock);
265 spin_lock_init(&obd->obd_dev_lock);
266 mutex_init(&obd->obd_dev_mutex);
267 spin_lock_init(&obd->obd_osfs_lock);
268 /* obd->obd_osfs_age must be set to a value in the distant
269 * past to guarantee a fresh statfs is fetched on mount.
271 obd->obd_osfs_age = cfs_time_shift_64(-1000);
273 /* XXX belongs in setup not attach */
274 init_rwsem(&obd->obd_observer_link_sem);
276 init_waitqueue_head(&obd->obd_evict_inprogress_waitq);
278 llog_group_init(&obd->obd_olg);
280 obd->obd_conn_inprogress = 0;
283 if (len >= sizeof(obd->obd_uuid)) {
284 CERROR("uuid must be < %d bytes long\n",
285 (int)sizeof(obd->obd_uuid));
289 memcpy(obd->obd_uuid.uuid, uuid, len);
291 /* Detach drops this */
292 spin_lock(&obd->obd_dev_lock);
293 atomic_set(&obd->obd_refcount, 1);
294 spin_unlock(&obd->obd_dev_lock);
295 lu_ref_init(&obd->obd_reference);
296 lu_ref_add(&obd->obd_reference, "attach", obd);
298 obd->obd_attached = 1;
299 CDEBUG(D_IOCTL, "OBD: dev %d attached type %s with refcount %d\n",
300 obd->obd_minor, typename, atomic_read(&obd->obd_refcount));
304 class_release_dev(obd);
309 /** Create hashes, self-export, and call type-specific setup.
310 * Setup is effectively the "start this obd" call.
312 static int class_setup(struct obd_device *obd, struct lustre_cfg *lcfg)
315 struct obd_export *exp;
318 LASSERTF(obd == class_num2obd(obd->obd_minor),
319 "obd %p != obd_devs[%d] %p\n",
320 obd, obd->obd_minor, class_num2obd(obd->obd_minor));
321 LASSERTF(obd->obd_magic == OBD_DEVICE_MAGIC,
322 "obd %p obd_magic %08x != %08x\n",
323 obd, obd->obd_magic, OBD_DEVICE_MAGIC);
325 /* have we attached a type to this device? */
326 if (!obd->obd_attached) {
327 CERROR("Device %d not attached\n", obd->obd_minor);
331 if (obd->obd_set_up) {
332 CERROR("Device %d already setup (type %s)\n",
333 obd->obd_minor, obd->obd_type->typ_name);
337 /* is someone else setting us up right now? (attach inits spinlock) */
338 spin_lock(&obd->obd_dev_lock);
339 if (obd->obd_starting) {
340 spin_unlock(&obd->obd_dev_lock);
341 CERROR("Device %d setup in progress (type %s)\n",
342 obd->obd_minor, obd->obd_type->typ_name);
345 /* just leave this on forever. I can't use obd_set_up here because
346 * other fns check that status, and we're not actually set up yet.
348 obd->obd_starting = 1;
349 obd->obd_uuid_hash = NULL;
350 spin_unlock(&obd->obd_dev_lock);
352 /* create an uuid-export lustre hash */
353 obd->obd_uuid_hash = cfs_hash_create("UUID_HASH",
356 HASH_UUID_BKT_BITS, 0,
359 &uuid_hash_ops, CFS_HASH_DEFAULT);
360 if (!obd->obd_uuid_hash) {
365 exp = class_new_export(obd, &obd->obd_uuid);
371 obd->obd_self_export = exp;
372 class_export_put(exp);
374 err = obd_setup(obd, lcfg);
380 spin_lock(&obd->obd_dev_lock);
381 /* cleanup drops this */
382 class_incref(obd, "setup", obd);
383 spin_unlock(&obd->obd_dev_lock);
385 CDEBUG(D_IOCTL, "finished setup of obd %s (uuid %s)\n",
386 obd->obd_name, obd->obd_uuid.uuid);
390 if (obd->obd_self_export) {
391 class_unlink_export(obd->obd_self_export);
392 obd->obd_self_export = NULL;
395 if (obd->obd_uuid_hash) {
396 cfs_hash_putref(obd->obd_uuid_hash);
397 obd->obd_uuid_hash = NULL;
399 obd->obd_starting = 0;
400 CERROR("setup %s failed (%d)\n", obd->obd_name, err);
404 /** We have finished using this obd and are ready to destroy it.
405 * There can be no more references to this obd.
407 static int class_detach(struct obd_device *obd, struct lustre_cfg *lcfg)
409 if (obd->obd_set_up) {
410 CERROR("OBD device %d still set up\n", obd->obd_minor);
414 spin_lock(&obd->obd_dev_lock);
415 if (!obd->obd_attached) {
416 spin_unlock(&obd->obd_dev_lock);
417 CERROR("OBD device %d not attached\n", obd->obd_minor);
420 obd->obd_attached = 0;
421 spin_unlock(&obd->obd_dev_lock);
423 CDEBUG(D_IOCTL, "detach on obd %s (uuid %s)\n",
424 obd->obd_name, obd->obd_uuid.uuid);
426 class_decref(obd, "attach", obd);
430 /** Start shutting down the obd. There may be in-progress ops when
431 * this is called. We tell them to start shutting down with a call
432 * to class_disconnect_exports().
434 static int class_cleanup(struct obd_device *obd, struct lustre_cfg *lcfg)
439 OBD_RACE(OBD_FAIL_LDLM_RECOV_CLIENTS);
441 if (!obd->obd_set_up) {
442 CERROR("Device %d not setup\n", obd->obd_minor);
446 spin_lock(&obd->obd_dev_lock);
447 if (obd->obd_stopping) {
448 spin_unlock(&obd->obd_dev_lock);
449 CERROR("OBD %d already stopping\n", obd->obd_minor);
452 /* Leave this on forever */
453 obd->obd_stopping = 1;
454 spin_unlock(&obd->obd_dev_lock);
456 while (obd->obd_conn_inprogress > 0)
460 if (lcfg->lcfg_bufcount >= 2 && LUSTRE_CFG_BUFLEN(lcfg, 1) > 0) {
461 for (flag = lustre_cfg_string(lcfg, 1); *flag != 0; flag++)
467 LCONSOLE_WARN("Failing over %s\n",
470 obd->obd_no_transno = 1;
471 obd->obd_no_recov = 1;
472 if (OBP(obd, iocontrol)) {
473 obd_iocontrol(OBD_IOC_SYNC,
474 obd->obd_self_export,
479 CERROR("Unrecognised flag '%c'\n", *flag);
483 LASSERT(obd->obd_self_export);
485 /* Precleanup, we must make sure all exports get destroyed. */
486 err = obd_precleanup(obd);
488 CERROR("Precleanup %s returned %d\n",
491 /* destroy an uuid-export hash body */
492 if (obd->obd_uuid_hash) {
493 cfs_hash_putref(obd->obd_uuid_hash);
494 obd->obd_uuid_hash = NULL;
497 class_decref(obd, "setup", obd);
503 struct obd_device *class_incref(struct obd_device *obd,
504 const char *scope, const void *source)
506 lu_ref_add_atomic(&obd->obd_reference, scope, source);
507 atomic_inc(&obd->obd_refcount);
508 CDEBUG(D_INFO, "incref %s (%p) now %d\n", obd->obd_name, obd,
509 atomic_read(&obd->obd_refcount));
513 EXPORT_SYMBOL(class_incref);
515 void class_decref(struct obd_device *obd, const char *scope, const void *source)
520 spin_lock(&obd->obd_dev_lock);
521 atomic_dec(&obd->obd_refcount);
522 refs = atomic_read(&obd->obd_refcount);
523 spin_unlock(&obd->obd_dev_lock);
524 lu_ref_del(&obd->obd_reference, scope, source);
526 CDEBUG(D_INFO, "Decref %s (%p) now %d\n", obd->obd_name, obd, refs);
528 if ((refs == 1) && obd->obd_stopping) {
529 /* All exports have been destroyed; there should
530 * be no more in-progress ops by this point.
533 spin_lock(&obd->obd_self_export->exp_lock);
534 obd->obd_self_export->exp_flags |= exp_flags_from_obd(obd);
535 spin_unlock(&obd->obd_self_export->exp_lock);
537 /* note that we'll recurse into class_decref again */
538 class_unlink_export(obd->obd_self_export);
543 CDEBUG(D_CONFIG, "finishing cleanup of obd %s (%s)\n",
544 obd->obd_name, obd->obd_uuid.uuid);
545 LASSERT(!obd->obd_attached);
546 if (obd->obd_stopping) {
547 /* If we're not stopping, we were never set up */
548 err = obd_cleanup(obd);
550 CERROR("Cleanup %s returned %d\n",
553 class_release_dev(obd);
556 EXPORT_SYMBOL(class_decref);
558 /** Add a failover nid location.
559 * Client obd types contact server obd types using this nid list.
561 static int class_add_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 strcmp(obd->obd_type->typ_name, LUSTRE_OSP_NAME) &&
575 strcmp(obd->obd_type->typ_name, LUSTRE_LWP_NAME) &&
576 strcmp(obd->obd_type->typ_name, LUSTRE_MGC_NAME)) {
577 CERROR("can't add connection on non-client dev\n");
581 imp = obd->u.cli.cl_import;
583 CERROR("try to add conn on immature client dev\n");
587 obd_str2uuid(&uuid, lustre_cfg_string(lcfg, 1));
588 rc = obd_add_conn(imp, &uuid, lcfg->lcfg_num);
593 /** Remove a failover nid location.
595 static int class_del_conn(struct obd_device *obd, struct lustre_cfg *lcfg)
597 struct obd_import *imp;
598 struct obd_uuid uuid;
601 if (LUSTRE_CFG_BUFLEN(lcfg, 1) < 1 ||
602 LUSTRE_CFG_BUFLEN(lcfg, 1) > sizeof(struct obd_uuid)) {
603 CERROR("invalid conn_uuid\n");
606 if (strcmp(obd->obd_type->typ_name, LUSTRE_MDC_NAME) &&
607 strcmp(obd->obd_type->typ_name, LUSTRE_OSC_NAME)) {
608 CERROR("can't del connection on non-client dev\n");
612 imp = obd->u.cli.cl_import;
614 CERROR("try to del conn on immature client dev\n");
618 obd_str2uuid(&uuid, lustre_cfg_string(lcfg, 1));
619 rc = obd_del_conn(imp, &uuid);
624 static LIST_HEAD(lustre_profile_list);
625 static DEFINE_SPINLOCK(lustre_profile_list_lock);
627 struct lustre_profile *class_get_profile(const char *prof)
629 struct lustre_profile *lprof;
631 spin_lock(&lustre_profile_list_lock);
632 list_for_each_entry(lprof, &lustre_profile_list, lp_list) {
633 if (!strcmp(lprof->lp_profile, prof)) {
635 spin_unlock(&lustre_profile_list_lock);
639 spin_unlock(&lustre_profile_list_lock);
642 EXPORT_SYMBOL(class_get_profile);
644 /** Create a named "profile".
645 * This defines the mdc and osc names to use for a client.
646 * This also is used to define the lov to be used by a mdt.
648 static int class_add_profile(int proflen, char *prof, int osclen, char *osc,
649 int mdclen, char *mdc)
651 struct lustre_profile *lprof;
654 CDEBUG(D_CONFIG, "Add profile %s\n", prof);
656 lprof = kzalloc(sizeof(*lprof), GFP_NOFS);
659 INIT_LIST_HEAD(&lprof->lp_list);
661 LASSERT(proflen == (strlen(prof) + 1));
662 lprof->lp_profile = kmemdup(prof, proflen, GFP_NOFS);
663 if (!lprof->lp_profile) {
668 LASSERT(osclen == (strlen(osc) + 1));
669 lprof->lp_dt = kmemdup(osc, osclen, GFP_NOFS);
672 goto free_lp_profile;
676 LASSERT(mdclen == (strlen(mdc) + 1));
677 lprof->lp_md = kmemdup(mdc, mdclen, GFP_NOFS);
684 spin_lock(&lustre_profile_list_lock);
686 lprof->lp_list_deleted = false;
687 list_add(&lprof->lp_list, &lustre_profile_list);
688 spin_unlock(&lustre_profile_list_lock);
694 kfree(lprof->lp_profile);
700 void class_del_profile(const char *prof)
702 struct lustre_profile *lprof;
704 CDEBUG(D_CONFIG, "Del profile %s\n", prof);
706 lprof = class_get_profile(prof);
708 spin_lock(&lustre_profile_list_lock);
709 /* because get profile increments the ref counter */
711 list_del(&lprof->lp_list);
712 lprof->lp_list_deleted = true;
713 spin_unlock(&lustre_profile_list_lock);
715 class_put_profile(lprof);
718 EXPORT_SYMBOL(class_del_profile);
720 void class_put_profile(struct lustre_profile *lprof)
722 spin_lock(&lustre_profile_list_lock);
723 if (--lprof->lp_refs > 0) {
724 LASSERT(lprof->lp_refs > 0);
725 spin_unlock(&lustre_profile_list_lock);
728 spin_unlock(&lustre_profile_list_lock);
730 /* confirm not a negative number */
731 LASSERT(!lprof->lp_refs);
734 * At least one class_del_profile/profiles must be called
735 * on the target profile or lustre_profile_list will corrupt
737 LASSERT(lprof->lp_list_deleted);
738 kfree(lprof->lp_profile);
743 EXPORT_SYMBOL(class_put_profile);
746 void class_del_profiles(void)
748 struct lustre_profile *lprof, *n;
750 spin_lock(&lustre_profile_list_lock);
751 list_for_each_entry_safe(lprof, n, &lustre_profile_list, lp_list) {
752 list_del(&lprof->lp_list);
753 lprof->lp_list_deleted = true;
754 spin_unlock(&lustre_profile_list_lock);
756 class_put_profile(lprof);
758 spin_lock(&lustre_profile_list_lock);
760 spin_unlock(&lustre_profile_list_lock);
762 EXPORT_SYMBOL(class_del_profiles);
764 static int class_set_global(char *ptr, int val, struct lustre_cfg *lcfg)
766 if (class_match_param(ptr, PARAM_AT_MIN, NULL) == 0)
768 else if (class_match_param(ptr, PARAM_AT_MAX, NULL) == 0)
770 else if (class_match_param(ptr, PARAM_AT_EXTRA, NULL) == 0)
772 else if (class_match_param(ptr, PARAM_AT_EARLY_MARGIN, NULL) == 0)
773 at_early_margin = val;
774 else if (class_match_param(ptr, PARAM_AT_HISTORY, NULL) == 0)
776 else if (class_match_param(ptr, PARAM_JOBID_VAR, NULL) == 0)
777 strlcpy(obd_jobid_var, lustre_cfg_string(lcfg, 2),
778 JOBSTATS_JOBID_VAR_MAX_LEN + 1);
782 CDEBUG(D_IOCTL, "global %s = %d\n", ptr, val);
786 /* We can't call ll_process_config or lquota_process_config directly because
787 * it lives in a module that must be loaded after this one.
789 static int (*client_process_config)(struct lustre_cfg *lcfg);
790 static int (*quota_process_config)(struct lustre_cfg *lcfg);
792 void lustre_register_client_process_config(int (*cpc)(struct lustre_cfg *lcfg))
794 client_process_config = cpc;
796 EXPORT_SYMBOL(lustre_register_client_process_config);
798 static int process_param2_config(struct lustre_cfg *lcfg)
800 char *param = lustre_cfg_string(lcfg, 1);
801 char *upcall = lustre_cfg_string(lcfg, 2);
803 [0] = "/usr/sbin/lctl",
812 /* Add upcall processing here. Now only lctl is supported */
813 if (strcmp(upcall, LCTL_UPCALL) != 0) {
814 CERROR("Unsupported upcall %s\n", upcall);
819 rc = call_usermodehelper(argv[0], argv, NULL, UMH_WAIT_PROC);
824 "lctl: error invoking upcall %s %s %s: rc = %d; time %ldus\n",
825 argv[0], argv[1], argv[2], rc,
826 (long)ktime_us_delta(end, start));
828 CDEBUG(D_HA, "lctl: invoked upcall %s %s %s, time %ldus\n",
829 argv[0], argv[1], argv[2],
830 (long)ktime_us_delta(end, start));
837 /** Process configuration commands given in lustre_cfg form.
838 * These may come from direct calls (e.g. class_manual_cleanup)
839 * or processing the config llog, or ioctl from lctl.
841 int class_process_config(struct lustre_cfg *lcfg)
843 struct obd_device *obd;
846 LASSERT(lcfg && !IS_ERR(lcfg));
847 CDEBUG(D_IOCTL, "processing cmd: %x\n", lcfg->lcfg_command);
849 /* Commands that don't need a device */
850 switch (lcfg->lcfg_command) {
852 err = class_attach(lcfg);
855 case LCFG_ADD_UUID: {
856 CDEBUG(D_IOCTL, "adding mapping from uuid %s to nid %#llx (%s)\n",
857 lustre_cfg_string(lcfg, 1), lcfg->lcfg_nid,
858 libcfs_nid2str(lcfg->lcfg_nid));
860 err = class_add_uuid(lustre_cfg_string(lcfg, 1), lcfg->lcfg_nid);
863 case LCFG_DEL_UUID: {
864 CDEBUG(D_IOCTL, "removing mappings for uuid %s\n",
865 (lcfg->lcfg_bufcount < 2 || LUSTRE_CFG_BUFLEN(lcfg, 1) == 0)
866 ? "<all uuids>" : lustre_cfg_string(lcfg, 1));
868 err = class_del_uuid(lustre_cfg_string(lcfg, 1));
871 case LCFG_MOUNTOPT: {
872 CDEBUG(D_IOCTL, "mountopt: profile %s osc %s mdc %s\n",
873 lustre_cfg_string(lcfg, 1),
874 lustre_cfg_string(lcfg, 2),
875 lustre_cfg_string(lcfg, 3));
876 /* set these mount options somewhere, so ll_fill_super
879 err = class_add_profile(LUSTRE_CFG_BUFLEN(lcfg, 1),
880 lustre_cfg_string(lcfg, 1),
881 LUSTRE_CFG_BUFLEN(lcfg, 2),
882 lustre_cfg_string(lcfg, 2),
883 LUSTRE_CFG_BUFLEN(lcfg, 3),
884 lustre_cfg_string(lcfg, 3));
887 case LCFG_DEL_MOUNTOPT: {
888 CDEBUG(D_IOCTL, "mountopt: profile %s\n",
889 lustre_cfg_string(lcfg, 1));
890 class_del_profile(lustre_cfg_string(lcfg, 1));
894 case LCFG_SET_TIMEOUT: {
895 CDEBUG(D_IOCTL, "changing lustre timeout from %d to %d\n",
896 obd_timeout, lcfg->lcfg_num);
897 obd_timeout = max(lcfg->lcfg_num, 1U);
902 case LCFG_SET_LDLM_TIMEOUT: {
903 /* ldlm_timeout is not used on the client */
907 case LCFG_SET_UPCALL: {
908 LCONSOLE_ERROR_MSG(0x15a, "recovery upcall is deprecated\n");
909 /* COMPAT_146 Don't fail on old configs */
914 struct cfg_marker *marker;
916 marker = lustre_cfg_buf(lcfg, 1);
917 CDEBUG(D_IOCTL, "marker %d (%#x) %.16s %s\n", marker->cm_step,
918 marker->cm_flags, marker->cm_tgtname, marker->cm_comment);
924 /* llite has no obd */
925 if ((class_match_param(lustre_cfg_string(lcfg, 1),
926 PARAM_LLITE, NULL) == 0) &&
927 client_process_config) {
928 err = (*client_process_config)(lcfg);
930 } else if ((class_match_param(lustre_cfg_string(lcfg, 1),
931 PARAM_SYS, &tmp) == 0)) {
932 /* Global param settings */
933 err = class_set_global(tmp, lcfg->lcfg_num, lcfg);
935 * Client or server should not fail to mount if
936 * it hits an unknown configuration parameter.
939 CWARN("Ignoring unknown param %s\n", tmp);
943 } else if ((class_match_param(lustre_cfg_string(lcfg, 1),
944 PARAM_QUOTA, &tmp) == 0) &&
945 quota_process_config) {
946 err = (*quota_process_config)(lcfg);
952 case LCFG_SET_PARAM: {
953 err = process_param2_config(lcfg);
957 /* Commands that require a device */
958 obd = class_name2obd(lustre_cfg_string(lcfg, 0));
960 if (!LUSTRE_CFG_BUFLEN(lcfg, 0))
961 CERROR("this lcfg command requires a device name\n");
963 CERROR("no device for: %s\n",
964 lustre_cfg_string(lcfg, 0));
970 switch (lcfg->lcfg_command) {
972 err = class_setup(obd, lcfg);
976 err = class_detach(obd, lcfg);
981 err = class_cleanup(obd, lcfg);
985 case LCFG_ADD_CONN: {
986 err = class_add_conn(obd, lcfg);
990 case LCFG_DEL_CONN: {
991 err = class_del_conn(obd, lcfg);
995 case LCFG_POOL_NEW: {
996 err = obd_pool_new(obd, lustre_cfg_string(lcfg, 2));
1000 case LCFG_POOL_ADD: {
1001 err = obd_pool_add(obd, lustre_cfg_string(lcfg, 2),
1002 lustre_cfg_string(lcfg, 3));
1006 case LCFG_POOL_REM: {
1007 err = obd_pool_rem(obd, lustre_cfg_string(lcfg, 2),
1008 lustre_cfg_string(lcfg, 3));
1012 case LCFG_POOL_DEL: {
1013 err = obd_pool_del(obd, lustre_cfg_string(lcfg, 2));
1018 err = obd_process_config(obd, sizeof(*lcfg), lcfg);
1023 if ((err < 0) && !(lcfg->lcfg_command & LCFG_REQUIRED)) {
1024 CWARN("Ignoring error %d on optional command %#x\n", err,
1025 lcfg->lcfg_command);
1030 EXPORT_SYMBOL(class_process_config);
1032 int class_process_proc_param(char *prefix, struct lprocfs_vars *lvars,
1033 struct lustre_cfg *lcfg, void *data)
1035 struct lprocfs_vars *var;
1036 struct file fakefile;
1037 struct seq_file fake_seqfile;
1039 int i, keylen, vallen;
1040 int matched = 0, j = 0;
1044 if (lcfg->lcfg_command != LCFG_PARAM) {
1045 CERROR("Unknown command: %d\n", lcfg->lcfg_command);
1049 /* fake a seq file so that var->fops->write can work... */
1050 fakefile.private_data = &fake_seqfile;
1051 fake_seqfile.private = data;
1052 /* e.g. tunefs.lustre --param mdt.group_upcall=foo /r/tmp/lustre-mdt
1053 * or lctl conf_param lustre-MDT0000.mdt.group_upcall=bar
1054 * or lctl conf_param lustre-OST0000.osc.max_dirty_mb=36
1056 for (i = 1; i < lcfg->lcfg_bufcount; i++) {
1057 key = lustre_cfg_buf(lcfg, i);
1058 /* Strip off prefix */
1059 if (class_match_param(key, prefix, &key)) {
1061 * If the prefix doesn't match, return error so we
1062 * can pass it down the stack
1066 sval = strchr(key, '=');
1067 if (!sval || (*(sval + 1) == 0)) {
1068 CERROR("Can't parse param %s (missing '=')\n", key);
1069 /* rc = -EINVAL; continue parsing other params */
1072 keylen = sval - key;
1074 vallen = strlen(sval);
1077 /* Search proc entries */
1078 while (lvars[j].name) {
1080 if (!class_match_param(key, var->name, NULL) &&
1081 keylen == strlen(var->name)) {
1084 if (var->fops && var->fops->write) {
1089 rc = var->fops->write(&fakefile,
1090 (const char __user *)sval,
1099 CERROR("%.*s: %s unknown param %s\n",
1100 (int)strlen(prefix) - 1, prefix,
1101 (char *)lustre_cfg_string(lcfg, 0), key);
1102 /* rc = -EINVAL; continue parsing other params */
1104 } else if (rc < 0) {
1105 CERROR("%s: error writing proc entry '%s': rc = %d\n",
1106 prefix, var->name, rc);
1109 CDEBUG(D_CONFIG, "%s.%.*s: Set parameter %.*s=%s\n",
1110 lustre_cfg_string(lcfg, 0),
1111 (int)strlen(prefix) - 1, prefix,
1112 (int)(sval - key - 1), key, sval);
1122 EXPORT_SYMBOL(class_process_proc_param);
1124 /** Parse a configuration llog, doing various manipulations on them
1125 * for various reasons, (modifications for compatibility, skip obsolete
1126 * records, change uuids, etc), then class_process_config() resulting
1129 int class_config_llog_handler(const struct lu_env *env,
1130 struct llog_handle *handle,
1131 struct llog_rec_hdr *rec, void *data)
1133 struct config_llog_instance *clli = data;
1134 int cfg_len = rec->lrh_len;
1135 char *cfg_buf = (char *)(rec + 1);
1138 switch (rec->lrh_type) {
1140 struct lustre_cfg *lcfg, *lcfg_new;
1141 struct lustre_cfg_bufs bufs;
1142 char *inst_name = NULL;
1147 lcfg = (struct lustre_cfg *)cfg_buf;
1148 if (lcfg->lcfg_version == __swab32(LUSTRE_CFG_VERSION)) {
1149 lustre_swab_lustre_cfg(lcfg);
1153 rc = lustre_cfg_sanity_check(cfg_buf, cfg_len);
1157 /* Figure out config state info */
1158 if (lcfg->lcfg_command == LCFG_MARKER) {
1159 struct cfg_marker *marker = lustre_cfg_buf(lcfg, 1);
1161 lustre_swab_cfg_marker(marker, swab,
1162 LUSTRE_CFG_BUFLEN(lcfg, 1));
1163 CDEBUG(D_CONFIG, "Marker, inst_flg=%#x mark_flg=%#x\n",
1164 clli->cfg_flags, marker->cm_flags);
1165 if (marker->cm_flags & CM_START) {
1166 /* all previous flags off */
1167 clli->cfg_flags = CFG_F_MARKER;
1168 if (marker->cm_flags & CM_SKIP) {
1169 clli->cfg_flags |= CFG_F_SKIP;
1170 CDEBUG(D_CONFIG, "SKIP #%d\n",
1172 } else if ((marker->cm_flags & CM_EXCLUDE) ||
1174 lustre_check_exclusion(clli->cfg_sb,
1175 marker->cm_tgtname))) {
1176 clli->cfg_flags |= CFG_F_EXCLUDE;
1177 CDEBUG(D_CONFIG, "EXCLUDE %d\n",
1180 } else if (marker->cm_flags & CM_END) {
1181 clli->cfg_flags = 0;
1184 /* A config command without a start marker before it is
1185 * illegal (post 146)
1187 if (!(clli->cfg_flags & CFG_F_COMPAT146) &&
1188 !(clli->cfg_flags & CFG_F_MARKER) &&
1189 (lcfg->lcfg_command != LCFG_MARKER)) {
1190 CWARN("Config not inside markers, ignoring! (inst: %p, uuid: %s, flags: %#x)\n",
1192 clli->cfg_uuid.uuid, clli->cfg_flags);
1193 clli->cfg_flags |= CFG_F_SKIP;
1195 if (clli->cfg_flags & CFG_F_SKIP) {
1196 CDEBUG(D_CONFIG, "skipping %#x\n",
1199 /* No processing! */
1204 * For interoperability between 1.8 and 2.0,
1205 * rename "mds" obd device type to "mdt".
1208 char *typename = lustre_cfg_string(lcfg, 1);
1209 char *index = lustre_cfg_string(lcfg, 2);
1211 if ((lcfg->lcfg_command == LCFG_ATTACH && typename &&
1212 strcmp(typename, "mds") == 0)) {
1213 CWARN("For 1.8 interoperability, rename obd type from mds to mdt\n");
1216 if ((lcfg->lcfg_command == LCFG_SETUP && index &&
1217 strcmp(index, "type") == 0)) {
1218 CDEBUG(D_INFO, "For 1.8 interoperability, set this index to '0'\n");
1224 if (clli->cfg_flags & CFG_F_EXCLUDE) {
1225 CDEBUG(D_CONFIG, "cmd: %x marked EXCLUDED\n",
1226 lcfg->lcfg_command);
1227 if (lcfg->lcfg_command == LCFG_LOV_ADD_OBD)
1228 /* Add inactive instead */
1229 lcfg->lcfg_command = LCFG_LOV_ADD_INA;
1232 lustre_cfg_bufs_init(&bufs, lcfg);
1234 if (clli && clli->cfg_instance &&
1235 LUSTRE_CFG_BUFLEN(lcfg, 0) > 0) {
1236 inst_len = LUSTRE_CFG_BUFLEN(lcfg, 0) +
1237 sizeof(clli->cfg_instance) * 2 + 4;
1238 inst_name = kasprintf(GFP_NOFS, "%s-%p",
1239 lustre_cfg_string(lcfg, 0),
1240 clli->cfg_instance);
1245 lustre_cfg_bufs_set_string(&bufs, 0, inst_name);
1246 CDEBUG(D_CONFIG, "cmd %x, instance name: %s\n",
1247 lcfg->lcfg_command, inst_name);
1250 /* we override the llog's uuid for clients, to insure they
1253 if (clli && clli->cfg_instance &&
1254 lcfg->lcfg_command == LCFG_ATTACH) {
1255 lustre_cfg_bufs_set_string(&bufs, 2,
1256 clli->cfg_uuid.uuid);
1259 * sptlrpc config record, we expect 2 data segments:
1260 * [0]: fs_name/target_name,
1262 * moving them to index [1] and [2], and insert MGC's
1263 * obdname at index [0].
1265 if (clli && !clli->cfg_instance &&
1266 lcfg->lcfg_command == LCFG_SPTLRPC_CONF) {
1267 lustre_cfg_bufs_set(&bufs, 2, bufs.lcfg_buf[1],
1268 bufs.lcfg_buflen[1]);
1269 lustre_cfg_bufs_set(&bufs, 1, bufs.lcfg_buf[0],
1270 bufs.lcfg_buflen[0]);
1271 lustre_cfg_bufs_set_string(&bufs, 0,
1275 lcfg_len = lustre_cfg_len(bufs.lcfg_bufcount, bufs.lcfg_buflen);
1276 lcfg_new = kzalloc(lcfg_len, GFP_NOFS);
1282 lustre_cfg_init(lcfg_new, lcfg->lcfg_command, &bufs);
1283 lcfg_new->lcfg_num = lcfg->lcfg_num;
1284 lcfg_new->lcfg_flags = lcfg->lcfg_flags;
1286 /* XXX Hack to try to remain binary compatible with
1287 * pre-newconfig logs
1289 if (lcfg->lcfg_nal != 0 && /* pre-newconfig log? */
1290 (lcfg->lcfg_nid >> 32) == 0) {
1291 __u32 addr = (__u32)(lcfg->lcfg_nid & 0xffffffff);
1293 lcfg_new->lcfg_nid =
1294 LNET_MKNID(LNET_MKNET(lcfg->lcfg_nal, 0), addr);
1295 CWARN("Converted pre-newconfig NAL %d NID %x to %s\n",
1296 lcfg->lcfg_nal, addr,
1297 libcfs_nid2str(lcfg_new->lcfg_nid));
1299 lcfg_new->lcfg_nid = lcfg->lcfg_nid;
1302 lcfg_new->lcfg_nal = 0; /* illegal value for obsolete field */
1304 rc = class_process_config(lcfg_new);
1310 CERROR("Unknown llog record type %#x encountered\n",
1316 CERROR("%s: cfg command failed: rc = %d\n",
1317 handle->lgh_ctxt->loc_obd->obd_name, rc);
1318 class_config_dump_handler(NULL, handle, rec, data);
1322 EXPORT_SYMBOL(class_config_llog_handler);
1324 int class_config_parse_llog(const struct lu_env *env, struct llog_ctxt *ctxt,
1325 char *name, struct config_llog_instance *cfg)
1327 struct llog_process_cat_data cd = {0, 0};
1328 struct llog_handle *llh;
1332 CDEBUG(D_INFO, "looking up llog %s\n", name);
1333 rc = llog_open(env, ctxt, &llh, NULL, name, LLOG_OPEN_EXISTS);
1337 rc = llog_init_handle(env, llh, LLOG_F_IS_PLAIN, NULL);
1341 /* continue processing from where we last stopped to end-of-log */
1343 cd.lpcd_first_idx = cfg->cfg_last_idx;
1344 callback = cfg->cfg_callback;
1347 callback = class_config_llog_handler;
1350 cd.lpcd_last_idx = 0;
1352 rc = llog_process(env, llh, callback, cfg, &cd);
1354 CDEBUG(D_CONFIG, "Processed log %s gen %d-%d (rc=%d)\n", name,
1355 cd.lpcd_first_idx + 1, cd.lpcd_last_idx, rc);
1357 cfg->cfg_last_idx = cd.lpcd_last_idx;
1360 llog_close(env, llh);
1363 EXPORT_SYMBOL(class_config_parse_llog);
1366 * parse config record and output dump in supplied buffer.
1367 * This is separated from class_config_dump_handler() to use
1368 * for ioctl needs as well
1370 static int class_config_parse_rec(struct llog_rec_hdr *rec, char *buf,
1373 struct lustre_cfg *lcfg = (struct lustre_cfg *)(rec + 1);
1375 char *end = buf + size;
1378 LASSERT(rec->lrh_type == OBD_CFG_REC);
1379 rc = lustre_cfg_sanity_check(lcfg, rec->lrh_len);
1383 ptr += snprintf(ptr, end - ptr, "cmd=%05x ", lcfg->lcfg_command);
1384 if (lcfg->lcfg_flags)
1385 ptr += snprintf(ptr, end - ptr, "flags=%#08x ",
1389 ptr += snprintf(ptr, end - ptr, "num=%#08x ", lcfg->lcfg_num);
1391 if (lcfg->lcfg_nid) {
1392 char nidstr[LNET_NIDSTR_SIZE];
1394 libcfs_nid2str_r(lcfg->lcfg_nid, nidstr, sizeof(nidstr));
1395 ptr += snprintf(ptr, end - ptr, "nid=%s(%#llx)\n ",
1396 nidstr, lcfg->lcfg_nid);
1399 if (lcfg->lcfg_command == LCFG_MARKER) {
1400 struct cfg_marker *marker = lustre_cfg_buf(lcfg, 1);
1402 ptr += snprintf(ptr, end - ptr, "marker=%d(%#x)%s '%s'",
1403 marker->cm_step, marker->cm_flags,
1404 marker->cm_tgtname, marker->cm_comment);
1408 for (i = 0; i < lcfg->lcfg_bufcount; i++) {
1409 ptr += snprintf(ptr, end - ptr, "%d:%s ", i,
1410 lustre_cfg_string(lcfg, i));
1413 ptr += snprintf(ptr, end - ptr, "\n");
1414 /* return consumed bytes */
1419 int class_config_dump_handler(const struct lu_env *env,
1420 struct llog_handle *handle,
1421 struct llog_rec_hdr *rec, void *data)
1426 outstr = kzalloc(256, GFP_NOFS);
1430 if (rec->lrh_type == OBD_CFG_REC) {
1431 class_config_parse_rec(rec, outstr, 256);
1432 LCONSOLE(D_WARNING, " %s", outstr);
1434 LCONSOLE(D_WARNING, "unhandled lrh_type: %#x\n", rec->lrh_type);
1442 /** Call class_cleanup and class_detach.
1443 * "Manual" only in the sense that we're faking lcfg commands.
1445 int class_manual_cleanup(struct obd_device *obd)
1448 struct lustre_cfg *lcfg;
1449 struct lustre_cfg_bufs bufs;
1453 CERROR("empty cleanup\n");
1462 CDEBUG(D_CONFIG, "Manual cleanup of %s (flags='%s')\n",
1463 obd->obd_name, flags);
1465 lustre_cfg_bufs_reset(&bufs, obd->obd_name);
1466 lustre_cfg_bufs_set_string(&bufs, 1, flags);
1467 lcfg = kzalloc(lustre_cfg_len(bufs.lcfg_bufcount, bufs.lcfg_buflen),
1471 lustre_cfg_init(lcfg, LCFG_CLEANUP, &bufs);
1473 rc = class_process_config(lcfg);
1475 CERROR("cleanup failed %d: %s\n", rc, obd->obd_name);
1479 /* the lcfg is almost the same for both ops */
1480 lcfg->lcfg_command = LCFG_DETACH;
1481 rc = class_process_config(lcfg);
1483 CERROR("detach failed %d: %s\n", rc, obd->obd_name);
1488 EXPORT_SYMBOL(class_manual_cleanup);
1491 * uuid<->export lustre hash operations
1495 uuid_hash(struct cfs_hash *hs, const void *key, unsigned int mask)
1497 return cfs_hash_djb2_hash(((struct obd_uuid *)key)->uuid,
1498 sizeof(((struct obd_uuid *)key)->uuid), mask);
1502 uuid_key(struct hlist_node *hnode)
1504 struct obd_export *exp;
1506 exp = hlist_entry(hnode, struct obd_export, exp_uuid_hash);
1508 return &exp->exp_client_uuid;
1512 * NOTE: It is impossible to find an export that is in failed
1513 * state with this function
1516 uuid_keycmp(const void *key, struct hlist_node *hnode)
1518 struct obd_export *exp;
1521 exp = hlist_entry(hnode, struct obd_export, exp_uuid_hash);
1523 return obd_uuid_equals(key, &exp->exp_client_uuid) &&
1528 uuid_export_object(struct hlist_node *hnode)
1530 return hlist_entry(hnode, struct obd_export, exp_uuid_hash);
1534 uuid_export_get(struct cfs_hash *hs, struct hlist_node *hnode)
1536 struct obd_export *exp;
1538 exp = hlist_entry(hnode, struct obd_export, exp_uuid_hash);
1539 class_export_get(exp);
1543 uuid_export_put_locked(struct cfs_hash *hs, struct hlist_node *hnode)
1545 struct obd_export *exp;
1547 exp = hlist_entry(hnode, struct obd_export, exp_uuid_hash);
1548 class_export_put(exp);
1551 static struct cfs_hash_ops uuid_hash_ops = {
1552 .hs_hash = uuid_hash,
1554 .hs_keycmp = uuid_keycmp,
1555 .hs_object = uuid_export_object,
1556 .hs_get = uuid_export_get,
1557 .hs_put_locked = uuid_export_put_locked,