* Copyright (c) 2003, 2010, Oracle and/or its affiliates. All rights reserved.
* Use is subject to license terms.
*
- * Copyright (c) 2011, 2016, Intel Corporation.
+ * Copyright (c) 2011, 2017, Intel Corporation.
*/
/*
* This file is part of Lustre, http://www.lustre.org/
#define DEBUG_SUBSYSTEM S_CLASS
+#include <linux/kobject.h>
#include <linux/string.h>
#include <llog_swab.h>
#include <lprocfs_status.h>
#include <lustre_disk.h>
-#include <lustre_ioctl.h>
+#include <uapi/linux/lustre/lustre_ioctl.h>
#include <lustre_log.h>
-#include <lustre_param.h>
+#include <uapi/linux/lustre/lustre_param.h>
#include <obd_class.h>
#include "llog_internal.h"
return rc;
}
+char *lustre_cfg_string(struct lustre_cfg *lcfg, u32 index)
+{
+ char *s;
+
+ if (!lcfg->lcfg_buflens[index])
+ return NULL;
+
+ s = lustre_cfg_buf(lcfg, index);
+ if (!s)
+ return NULL;
+
+ /*
+ * make sure it's NULL terminated, even if this kills a char
+ * of data. Try to use the padding first though.
+ */
+ if (s[lcfg->lcfg_buflens[index] - 1] != '\0') {
+ size_t last = ALIGN(lcfg->lcfg_buflens[index], 8) - 1;
+ char lost;
+
+ /* Use the smaller value */
+ if (last > lcfg->lcfg_buflens[index])
+ last = lcfg->lcfg_buflens[index];
+
+ lost = s[last];
+ s[last] = '\0';
+ if (lost != '\0') {
+ CWARN("Truncated buf %d to '%s' (lost '%c'...)\n",
+ index, s, lost);
+ }
+ }
+ return s;
+}
+EXPORT_SYMBOL(lustre_cfg_string);
+
/********************** class fns **********************/
/**
*/
int class_attach(struct lustre_cfg *lcfg)
{
+ struct obd_export *exp;
struct obd_device *obd = NULL;
char *typename, *name, *uuid;
int rc, len;
RETURN(-EINVAL);
}
name = lustre_cfg_string(lcfg, 0);
-
if (!LUSTRE_CFG_BUFLEN(lcfg, 2)) {
CERROR("No UUID passed!\n");
RETURN(-EINVAL);
}
- uuid = lustre_cfg_string(lcfg, 2);
- CDEBUG(D_IOCTL, "attach type %s name: %s uuid: %s\n",
- MKSTR(typename), MKSTR(name), MKSTR(uuid));
+ uuid = lustre_cfg_string(lcfg, 2);
+ len = strlen(uuid);
+ if (len >= sizeof(obd->obd_uuid)) {
+ CERROR("%s: uuid must be < %d bytes long\n",
+ name, (int)sizeof(obd->obd_uuid));
+ RETURN(-EINVAL);
+ }
- obd = class_newdev(typename, name);
- if (IS_ERR(obd)) {
- /* Already exists or out of obds */
- rc = PTR_ERR(obd);
- obd = NULL;
+ obd = class_newdev(typename, name, uuid);
+ if (IS_ERR(obd)) { /* Already exists or out of obds */
+ rc = PTR_ERR(obd);
CERROR("Cannot create device %s of type %s : %d\n",
name, typename, rc);
- GOTO(out, rc);
+ RETURN(rc);
}
- LASSERTF(obd != NULL, "Cannot get obd device %s of type %s\n",
- name, typename);
LASSERTF(obd->obd_magic == OBD_DEVICE_MAGIC,
"obd %p obd_magic %08X != %08X\n",
obd, obd->obd_magic, OBD_DEVICE_MAGIC);
LASSERTF(strncmp(obd->obd_name, name, strlen(name)) == 0,
"%p obd_name %s != %s\n", obd, obd->obd_name, name);
- rwlock_init(&obd->obd_pool_lock);
- obd->obd_pool_limit = 0;
- obd->obd_pool_slv = 0;
-
- INIT_LIST_HEAD(&obd->obd_exports);
- INIT_LIST_HEAD(&obd->obd_unlinked_exports);
- INIT_LIST_HEAD(&obd->obd_delayed_exports);
- INIT_LIST_HEAD(&obd->obd_exports_timed);
- INIT_LIST_HEAD(&obd->obd_nid_stats);
- spin_lock_init(&obd->obd_nid_lock);
- spin_lock_init(&obd->obd_dev_lock);
- mutex_init(&obd->obd_dev_mutex);
- spin_lock_init(&obd->obd_osfs_lock);
- /* obd->obd_osfs_age must be set to a value in the distant
- * past to guarantee a fresh statfs is fetched on mount. */
- obd->obd_osfs_age = cfs_time_shift_64(-1000);
-
- /* XXX belongs in setup not attach */
- init_rwsem(&obd->obd_observer_link_sem);
- /* recovery data */
- init_timer(&obd->obd_recovery_timer);
- spin_lock_init(&obd->obd_recovery_task_lock);
- init_waitqueue_head(&obd->obd_next_transno_waitq);
- init_waitqueue_head(&obd->obd_evict_inprogress_waitq);
- INIT_LIST_HEAD(&obd->obd_req_replay_queue);
- INIT_LIST_HEAD(&obd->obd_lock_replay_queue);
- INIT_LIST_HEAD(&obd->obd_final_req_queue);
- INIT_LIST_HEAD(&obd->obd_evict_list);
- INIT_LIST_HEAD(&obd->obd_lwp_list);
-
- llog_group_init(&obd->obd_olg);
-
- obd->obd_conn_inprogress = 0;
-
- len = strlen(uuid);
- if (len >= sizeof(obd->obd_uuid)) {
- CERROR("uuid must be < %d bytes long\n",
- (int)sizeof(obd->obd_uuid));
- GOTO(out, rc = -EINVAL);
- }
- memcpy(obd->obd_uuid.uuid, uuid, len);
+ exp = class_new_export_self(obd, &obd->obd_uuid);
+ if (IS_ERR(exp)) {
+ rc = PTR_ERR(exp);
+ class_free_dev(obd);
+ RETURN(rc);
+ }
- /* Detach drops this */
- spin_lock(&obd->obd_dev_lock);
- atomic_set(&obd->obd_refcount, 1);
- spin_unlock(&obd->obd_dev_lock);
- lu_ref_init(&obd->obd_reference);
- lu_ref_add(&obd->obd_reference, "attach", obd);
+ obd->obd_self_export = exp;
+ list_del_init(&exp->exp_obd_chain_timed);
+ class_export_put(exp);
+
+ rc = class_register_device(obd);
+ if (rc != 0) {
+ class_decref(obd, "newdev", obd);
+ RETURN(rc);
+ }
- obd->obd_attached = 1;
- CDEBUG(D_IOCTL, "OBD: dev %d attached type %s with refcount %d\n",
+ obd->obd_attached = 1;
+ CDEBUG(D_IOCTL, "OBD: dev %d attached type %s with refcount %d\n",
obd->obd_minor, typename, atomic_read(&obd->obd_refcount));
- RETURN(0);
- out:
- if (obd != NULL) {
- class_release_dev(obd);
- }
- return rc;
+
+ RETURN(0);
}
EXPORT_SYMBOL(class_attach);
int class_setup(struct obd_device *obd, struct lustre_cfg *lcfg)
{
int err = 0;
- struct obd_export *exp;
ENTRY;
LASSERT(obd != NULL);
CFS_HASH_MAX_THETA,
&uuid_hash_ops, CFS_HASH_DEFAULT);
if (!obd->obd_uuid_hash)
- GOTO(err_hash, err = -ENOMEM);
+ GOTO(err_exit, err = -ENOMEM);
/* create a nid-export lustre hash */
obd->obd_nid_hash = cfs_hash_create("NID_HASH",
CFS_HASH_MAX_THETA,
&nid_hash_ops, CFS_HASH_DEFAULT);
if (!obd->obd_nid_hash)
- GOTO(err_hash, err = -ENOMEM);
+ GOTO(err_exit, err = -ENOMEM);
/* create a nid-stats lustre hash */
obd->obd_nid_stats_hash = cfs_hash_create("NID_STATS",
CFS_HASH_MIN_THETA,
CFS_HASH_MAX_THETA,
&nid_stat_hash_ops, CFS_HASH_DEFAULT);
- if (!obd->obd_nid_stats_hash)
- GOTO(err_hash, err = -ENOMEM);
+ if (!obd->obd_nid_stats_hash)
+ GOTO(err_exit, err = -ENOMEM);
/* create a client_generation-export lustre hash */
obd->obd_gen_hash = cfs_hash_create("UUID_HASH",
CFS_HASH_MAX_THETA,
&gen_hash_ops, CFS_HASH_DEFAULT);
if (!obd->obd_gen_hash)
- GOTO(err_hash, err = -ENOMEM);
+ GOTO(err_exit, err = -ENOMEM);
- exp = class_new_export(obd, &obd->obd_uuid);
- if (IS_ERR(exp))
- GOTO(err_hash, err = PTR_ERR(exp));
-
- obd->obd_self_export = exp;
- list_del_init(&exp->exp_obd_chain_timed);
- class_export_put(exp);
-
- err = obd_setup(obd, lcfg);
- if (err)
- GOTO(err_exp, err);
+ err = obd_setup(obd, lcfg);
+ if (err)
+ GOTO(err_exit, err);
- obd->obd_set_up = 1;
+ obd->obd_set_up = 1;
spin_lock(&obd->obd_dev_lock);
/* cleanup drops this */
obd->obd_name, obd->obd_uuid.uuid);
RETURN(0);
-err_exp:
- if (obd->obd_self_export) {
- class_unlink_export(obd->obd_self_export);
- obd->obd_self_export = NULL;
- }
-err_hash:
+err_exit:
if (obd->obd_uuid_hash) {
cfs_hash_putref(obd->obd_uuid_hash);
obd->obd_uuid_hash = NULL;
obd->obd_attached = 0;
spin_unlock(&obd->obd_dev_lock);
+ /* cleanup in progress. we don't like to find this device after now */
+ class_unregister_device(obd);
+
CDEBUG(D_IOCTL, "detach on obd %s (uuid %s)\n",
obd->obd_name, obd->obd_uuid.uuid);
- class_decref(obd, "attach", obd);
+ class_decref(obd, "newdev", obd);
+
RETURN(0);
}
EXPORT_SYMBOL(class_detach);
}
/* Leave this on forever */
obd->obd_stopping = 1;
+ /* function can't return error after that point, so clear setup flag
+ * as early as possible to avoid finding via obd_devs / hash */
+ obd->obd_set_up = 0;
spin_unlock(&obd->obd_dev_lock);
/* wait for already-arrived-connections to finish. */
LASSERT(obd->obd_self_export);
- /* The three references that should be remaining are the
- * obd_self_export and the attach and setup references. */
- if (atomic_read(&obd->obd_refcount) > 3) {
- /* refcounf - 3 might be the number of real exports
- (excluding self export). But class_incref is called
- by other things as well, so don't count on it. */
- CDEBUG(D_IOCTL, "%s: forcing exports to disconnect: %d\n",
- obd->obd_name, atomic_read(&obd->obd_refcount) - 3);
- dump_exports(obd, 0, D_HA);
- class_disconnect_exports(obd);
- }
+ CDEBUG(D_IOCTL, "%s: forcing exports to disconnect: %d/%d\n",
+ obd->obd_name, obd->obd_num_exports,
+ atomic_read(&obd->obd_refcount) - 2);
+ dump_exports(obd, 0, D_HA);
+ class_disconnect_exports(obd);
/* Precleanup, we must make sure all exports get destroyed. */
err = obd_precleanup(obd);
void class_decref(struct obd_device *obd, const char *scope, const void *source)
{
- int err;
- int refs;
+ int last;
- spin_lock(&obd->obd_dev_lock);
- atomic_dec(&obd->obd_refcount);
- refs = atomic_read(&obd->obd_refcount);
- spin_unlock(&obd->obd_dev_lock);
+ CDEBUG(D_INFO, "Decref %s (%p) now %d - %s\n", obd->obd_name, obd,
+ atomic_read(&obd->obd_refcount), scope);
+
+ LASSERT(obd->obd_num_exports >= 0);
+ last = atomic_dec_and_test(&obd->obd_refcount);
lu_ref_del(&obd->obd_reference, scope, source);
- CDEBUG(D_INFO, "Decref %s (%p) now %d\n", obd->obd_name, obd, refs);
+ if (last) {
+ struct obd_export *exp;
- if ((refs == 1) && obd->obd_stopping) {
+ LASSERT(!obd->obd_attached);
/* All exports have been destroyed; there should
- be no more in-progress ops by this point.*/
-
- spin_lock(&obd->obd_self_export->exp_lock);
- obd->obd_self_export->exp_flags |= exp_flags_from_obd(obd);
- spin_unlock(&obd->obd_self_export->exp_lock);
-
- /* note that we'll recurse into class_decref again */
- class_unlink_export(obd->obd_self_export);
- return;
- }
+ * be no more in-progress ops by this point.*/
+ exp = obd->obd_self_export;
- if (refs == 0) {
- CDEBUG(D_CONFIG, "finishing cleanup of obd %s (%s)\n",
- obd->obd_name, obd->obd_uuid.uuid);
- LASSERT(!obd->obd_attached);
- if (obd->obd_stopping) {
- /* If we're not stopping, we were never set up */
- err = obd_cleanup(obd);
- if (err)
- CERROR("Cleanup %s returned %d\n",
- obd->obd_name, err);
+ if (exp) {
+ exp->exp_flags |= exp_flags_from_obd(obd);
+ class_unlink_export(exp);
}
-
- class_release_dev(obd);
}
}
EXPORT_SYMBOL(class_decref);
RETURN(rc);
}
-static struct list_head lustre_profile_list =
- LIST_HEAD_INIT(lustre_profile_list);
+static LIST_HEAD(lustre_profile_list);
static DEFINE_SPINLOCK(lustre_profile_list_lock);
struct lustre_profile *class_get_profile(const char * prof)
}
EXPORT_SYMBOL(class_del_profiles);
-static int class_set_global(char *ptr, int val, struct lustre_cfg *lcfg)
-{
- ENTRY;
- if (class_match_param(ptr, PARAM_AT_MIN, NULL) == 0)
- at_min = val;
- else if (class_match_param(ptr, PARAM_AT_MAX, NULL) == 0)
- at_max = val;
- else if (class_match_param(ptr, PARAM_AT_EXTRA, NULL) == 0)
- at_extra = val;
- else if (class_match_param(ptr, PARAM_AT_EARLY_MARGIN, NULL) == 0)
- at_early_margin = val;
- else if (class_match_param(ptr, PARAM_AT_HISTORY, NULL) == 0)
- at_history = val;
- else if (class_match_param(ptr, PARAM_JOBID_VAR, NULL) == 0)
- strlcpy(obd_jobid_var, lustre_cfg_string(lcfg, 2),
- JOBSTATS_JOBID_VAR_MAX_LEN + 1);
- else
- RETURN(-EINVAL);
-
- CDEBUG(D_IOCTL, "global %s = %d\n", ptr, val);
- RETURN(0);
-}
-
-
-/* We can't call ll_process_config or lquota_process_config directly because
- * it lives in a module that must be loaded after this one. */
-static int (*client_process_config)(struct lustre_cfg *lcfg) = NULL;
+/* We can't call lquota_process_config directly because
+ * it lives in a module that must be loaded after this one.
+ */
+#ifdef HAVE_SERVER_SUPPORT
static int (*quota_process_config)(struct lustre_cfg *lcfg) = NULL;
-
-void lustre_register_client_process_config(int (*cpc)(struct lustre_cfg *lcfg))
-{
- client_process_config = cpc;
-}
-EXPORT_SYMBOL(lustre_register_client_process_config);
+#endif /* HAVE_SERVER_SUPPORT */
/**
* Rename the proc parameter in \a cfg with a new name \a new_name.
int new_len = 0;
ENTRY;
- if (cfg == NULL || new_name == NULL)
- RETURN(ERR_PTR(-EINVAL));
+ if (!cfg || !new_name)
+ GOTO(out_nocfg, new_cfg = ERR_PTR(-EINVAL));
param = lustre_cfg_string(cfg, 1);
- if (param == NULL)
- RETURN(ERR_PTR(-EINVAL));
+ if (!param)
+ GOTO(out_nocfg, new_cfg = ERR_PTR(-EINVAL));
value = strchr(param, '=');
if (value == NULL)
new_len = LUSTRE_CFG_BUFLEN(cfg, 1) + strlen(new_name) - name_len;
OBD_ALLOC(new_param, new_len);
- if (new_param == NULL)
- RETURN(ERR_PTR(-ENOMEM));
+ if (!new_param)
+ GOTO(out_nocfg, new_cfg = ERR_PTR(-ENOMEM));
strcpy(new_param, new_name);
if (value != NULL)
strcat(new_param, value);
OBD_ALLOC_PTR(bufs);
- if (bufs == NULL) {
- OBD_FREE(new_param, new_len);
- RETURN(ERR_PTR(-ENOMEM));
- }
+ if (!bufs)
+ GOTO(out_free_param, new_cfg = ERR_PTR(-ENOMEM));
lustre_cfg_bufs_reset(bufs, NULL);
lustre_cfg_bufs_init(bufs, cfg);
lustre_cfg_bufs_set_string(bufs, 1, new_param);
- new_cfg = lustre_cfg_new(cfg->lcfg_command, bufs);
- OBD_FREE(new_param, new_len);
- OBD_FREE_PTR(bufs);
- if (new_cfg == NULL)
- RETURN(ERR_PTR(-ENOMEM));
+ OBD_ALLOC(new_cfg, lustre_cfg_len(bufs->lcfg_bufcount,
+ bufs->lcfg_buflen));
+ if (!new_cfg)
+ GOTO(out_free_buf, new_cfg = ERR_PTR(-ENOMEM));
+
+ lustre_cfg_init(new_cfg, cfg->lcfg_command, bufs);
new_cfg->lcfg_num = cfg->lcfg_num;
new_cfg->lcfg_flags = cfg->lcfg_flags;
new_cfg->lcfg_nid = cfg->lcfg_nid;
new_cfg->lcfg_nal = cfg->lcfg_nal;
-
+out_free_buf:
+ OBD_FREE_PTR(bufs);
+out_free_param:
+ OBD_FREE(new_param, new_len);
+out_nocfg:
RETURN(new_cfg);
}
EXPORT_SYMBOL(lustre_cfg_rename);
-static int process_param2_config(struct lustre_cfg *lcfg)
+static ssize_t process_param2_config(struct lustre_cfg *lcfg)
{
char *param = lustre_cfg_string(lcfg, 1);
char *upcall = lustre_cfg_string(lcfg, 2);
+ struct kobject *kobj = NULL;
+ const char *subsys = param;
char *argv[] = {
[0] = "/usr/sbin/lctl",
[1] = "set_param",
[2] = param,
[3] = NULL
};
- struct timeval start;
- struct timeval end;
- int rc;
+ ktime_t start;
+ ktime_t end;
+ size_t len;
+ int rc;
+
ENTRY;
+ print_lustre_cfg(lcfg);
+
+ len = strcspn(param, ".=");
+ if (!len)
+ return -EINVAL;
+
+ /* If we find '=' then its the top level sysfs directory */
+ if (param[len] == '=')
+ return class_set_global(param);
+
+ subsys = kstrndup(param, len, GFP_KERNEL);
+ if (!subsys)
+ return -ENOMEM;
+
+ kobj = kset_find_obj(lustre_kset, subsys);
+ kfree(subsys);
+ if (kobj) {
+ char *value = param;
+ char *envp[3];
+ int i;
+
+ param = strsep(&value, "=");
+ envp[0] = kasprintf(GFP_KERNEL, "PARAM=%s", param);
+ envp[1] = kasprintf(GFP_KERNEL, "SETTING=%s", value);
+ envp[2] = NULL;
+
+ rc = kobject_uevent_env(kobj, KOBJ_CHANGE, envp);
+ for (i = 0; i < ARRAY_SIZE(envp); i++)
+ kfree(envp[i]);
+
+ kobject_put(kobj);
+
+ RETURN(rc);
+ }
/* Add upcall processing here. Now only lctl is supported */
if (strcmp(upcall, LCTL_UPCALL) != 0) {
RETURN(-EINVAL);
}
- do_gettimeofday(&start);
+ start = ktime_get();
rc = call_usermodehelper(argv[0], argv, NULL, UMH_WAIT_PROC);
- do_gettimeofday(&end);
+ end = ktime_get();
if (rc < 0) {
CERROR("lctl: error invoking upcall %s %s %s: rc = %d; "
"time %ldus\n", argv[0], argv[1], argv[2], rc,
- cfs_timeval_sub(&end, &start, NULL));
+ (long)ktime_us_delta(end, start));
} else {
CDEBUG(D_HA, "lctl: invoked upcall %s %s %s, time %ldus\n",
argv[0], argv[1], argv[2],
- cfs_timeval_sub(&end, &start, NULL));
+ (long)ktime_us_delta(end, start));
rc = 0;
}
RETURN(rc);
}
+#ifdef HAVE_SERVER_SUPPORT
void lustre_register_quota_process_config(int (*qpc)(struct lustre_cfg *lcfg))
{
quota_process_config = qpc;
}
EXPORT_SYMBOL(lustre_register_quota_process_config);
+#endif /* HAVE_SERVER_SUPPORT */
/** Process configuration commands given in lustre_cfg form.
* These may come from direct calls (e.g. class_manual_cleanup)
}
case LCFG_PARAM: {
char *tmp;
+
/* llite has no obd */
- if ((class_match_param(lustre_cfg_string(lcfg, 1),
- PARAM_LLITE, NULL) == 0) &&
- client_process_config) {
- err = (*client_process_config)(lcfg);
- GOTO(out, err);
+ if (class_match_param(lustre_cfg_string(lcfg, 1),
+ PARAM_LLITE, NULL) == 0) {
+ struct lustre_sb_info *lsi;
+ unsigned long addr;
+ ssize_t count;
+
+ /* The instance name contains the sb:
+ * lustre-client-aacfe000
+ */
+ tmp = strrchr(lustre_cfg_string(lcfg, 0), '-');
+ if (!tmp || !*(++tmp))
+ GOTO(out, err = -EINVAL);
+
+ if (sscanf(tmp, "%lx", &addr) != 1)
+ GOTO(out, err = -EINVAL);
+
+ lsi = s2lsi((struct super_block *)addr);
+ /* This better be a real Lustre superblock! */
+ LASSERT(lsi->lsi_lmd->lmd_magic == LMD_MAGIC);
+
+ count = class_modify_config(lcfg, PARAM_LLITE,
+ lsi->lsi_kobj);
+ err = count < 0 ? count : 0;
+ GOTO(out, err);
} else if ((class_match_param(lustre_cfg_string(lcfg, 1),
PARAM_SYS, &tmp) == 0)) {
/* Global param settings */
- err = class_set_global(tmp, lcfg->lcfg_num, lcfg);
+ err = class_set_global(tmp);
/*
* Client or server should not fail to mount if
* it hits an unknown configuration parameter.
*/
- if (err != 0)
+ if (err < 0)
CWARN("Ignoring unknown param %s\n", tmp);
GOTO(out, err = 0);
+#ifdef HAVE_SERVER_SUPPORT
} else if ((class_match_param(lustre_cfg_string(lcfg, 1),
PARAM_QUOTA, &tmp) == 0) &&
quota_process_config) {
err = (*quota_process_config)(lcfg);
GOTO(out, err);
+#endif /* HAVE_SERVER_SUPPORT */
}
break;
GOTO(out, err = -EINVAL);
}
-
switch(lcfg->lcfg_command) {
case LCFG_SETUP: {
err = class_setup(obd, lcfg);
err = obd_pool_del(obd, lustre_cfg_string(lcfg, 2));
GOTO(out, err = 0);
}
- default: {
- err = obd_process_config(obd, sizeof(*lcfg), lcfg);
- GOTO(out, err);
+ /* Process config log ADD_MDC record twice to add MDC also to LOV
+ * for Data-on-MDT:
+ *
+ * add 0:lustre-clilmv 1:lustre-MDT0000_UUID 2:0 3:1
+ * 4:lustre-MDT0000-mdc_UUID
+ */
+ case LCFG_ADD_MDC: {
+ struct obd_device *lov_obd;
+ char *clilmv;
+
+ err = obd_process_config(obd, sizeof(*lcfg), lcfg);
+ if (err)
+ GOTO(out, err);
+
+ /* make sure this is client LMV log entry */
+ clilmv = strstr(lustre_cfg_string(lcfg, 0), "clilmv");
+ if (!clilmv)
+ GOTO(out, err);
+
+ /* replace 'lmv' with 'lov' name to address LOV device and
+ * process llog record to add MDC there. */
+ clilmv[4] = 'o';
+ lov_obd = class_name2obd(lustre_cfg_string(lcfg, 0));
+ if (lov_obd == NULL) {
+ err = -ENOENT;
+ CERROR("%s: Cannot find LOV by %s name, rc = %d\n",
+ obd->obd_name, lustre_cfg_string(lcfg, 0), err);
+ } else {
+ err = obd_process_config(lov_obd, sizeof(*lcfg), lcfg);
+ }
+ /* restore 'lmv' name */
+ clilmv[4] = 'm';
+ GOTO(out, err);
+ }
+ default: {
+ err = obd_process_config(obd, sizeof(*lcfg), lcfg);
+ GOTO(out, err);
}
}
+ EXIT;
out:
if ((err < 0) && !(lcfg->lcfg_command & LCFG_REQUIRED)) {
CWARN("Ignoring error %d on optional command %#x\n", err,
}
EXPORT_SYMBOL(class_process_config);
+ssize_t class_modify_config(struct lustre_cfg *lcfg, const char *prefix,
+ struct kobject *kobj)
+{
+ struct kobj_type *typ;
+ ssize_t count = 0;
+ int i;
+
+ if (lcfg->lcfg_command != LCFG_PARAM) {
+ CERROR("Unknown command: %d\n", lcfg->lcfg_command);
+ return -EINVAL;
+ }
+
+ typ = get_ktype(kobj);
+ if (!typ || !typ->default_attrs)
+ return -ENODEV;
+
+ print_lustre_cfg(lcfg);
+
+ /*
+ * e.g. tunefs.lustre --param mdt.group_upcall=foo /r/tmp/lustre-mdt
+ * or lctl conf_param lustre-MDT0000.mdt.group_upcall=bar
+ * or lctl conf_param lustre-OST0000.osc.max_dirty_mb=36
+ */
+ for (i = 1; i < lcfg->lcfg_bufcount; i++) {
+ struct attribute *attr;
+ size_t keylen;
+ char *value;
+ char *key;
+ int j;
+
+ key = lustre_cfg_buf(lcfg, i);
+ /* Strip off prefix */
+ if (class_match_param(key, prefix, &key))
+ /* If the prefix doesn't match, return error so we
+ * can pass it down the stack
+ */
+ return -EINVAL;
+
+ value = strchr(key, '=');
+ if (!value || *(value + 1) == 0) {
+ CERROR("%s: can't parse param '%s' (missing '=')\n",
+ lustre_cfg_string(lcfg, 0),
+ lustre_cfg_string(lcfg, i));
+ /* continue parsing other params */
+ continue;
+ }
+ keylen = value - key;
+ value++;
+
+ attr = NULL;
+ for (j = 0; typ->default_attrs[j]; j++) {
+ if (!strncmp(typ->default_attrs[j]->name, key,
+ keylen)) {
+ attr = typ->default_attrs[j];
+ break;
+ }
+ }
+
+ if (!attr) {
+ char *envp[3];
+
+ envp[0] = kasprintf(GFP_KERNEL, "PARAM=%s.%s.%.*s",
+ kobject_name(kobj->parent),
+ kobject_name(kobj),
+ (int) keylen, key);
+ envp[1] = kasprintf(GFP_KERNEL, "SETTING=%s", value);
+ envp[2] = NULL;
+
+ if (kobject_uevent_env(kobj, KOBJ_CHANGE, envp)) {
+ CERROR("%s: failed to send uevent %s\n",
+ kobject_name(kobj), key);
+ }
+
+ for (i = 0; i < ARRAY_SIZE(envp); i++)
+ kfree(envp[i]);
+ } else {
+ count += lustre_attr_store(kobj, attr, value,
+ strlen(value));
+ }
+ }
+ return count;
+}
+EXPORT_SYMBOL(class_modify_config);
+
int class_process_proc_param(char *prefix, struct lprocfs_vars *lvars,
struct lustre_cfg *lcfg, void *data)
{
* can pass it down the stack */
RETURN(-ENOSYS);
sval = strchr(key, '=');
- if (!sval || (*(sval + 1) == 0)) {
- CERROR("Can't parse param %s (missing '=')\n", key);
+ if (!sval || *(sval + 1) == 0) {
+ CERROR("%s: can't parse param '%s' (missing '=')\n",
+ lustre_cfg_string(lcfg, 0),
+ lustre_cfg_string(lcfg, i));
/* rc = -EINVAL; continue parsing other params */
continue;
}
if (strncmp("sec_level", key, keylen) == 0)
continue;
- CERROR("%.*s: %s unknown param %s\n",
- (int)strlen(prefix) - 1, prefix,
- (char *)lustre_cfg_string(lcfg, 0), key);
+ CERROR("%s: unknown config parameter '%s'\n",
+ lustre_cfg_string(lcfg, 0),
+ lustre_cfg_string(lcfg, i));
/* rc = -EINVAL; continue parsing other params */
skip++;
} else if (rc < 0) {
- CERROR("%s: error writing proc entry '%s': rc = %d\n",
- prefix, var->name, rc);
+ CERROR("%s: error writing parameter '%s': rc = %d\n",
+ lustre_cfg_string(lcfg, 0), key, rc);
rc = 0;
} else {
- CDEBUG(D_CONFIG, "%s.%.*s: Set parameter %.*s=%s\n",
- lustre_cfg_string(lcfg, 0),
- (int)strlen(prefix) - 1, prefix,
- (int)(sval - key - 1), key, sval);
+ CDEBUG(D_CONFIG, "%s: set parameter '%s'\n",
+ lustre_cfg_string(lcfg, 0), key);
}
}
struct lustre_cfg_bufs bufs;
char *inst_name = NULL;
int inst_len = 0;
- int inst = 0, swab = 0;
+ int swab = 0;
lcfg = (struct lustre_cfg *)cfg_buf;
if (lcfg->lcfg_version == __swab32(LUSTRE_CFG_VERSION)) {
}
}
/* A config command without a start marker before it is
- illegal (post 146) */
- if (!(cfg->cfg_flags & CFG_F_COMPAT146) &&
- !(cfg->cfg_flags & CFG_F_MARKER) &&
+ * illegal
+ */
+ if (!(cfg->cfg_flags & CFG_F_MARKER) &&
(lcfg->lcfg_command != LCFG_MARKER)) {
CWARN("Config not inside markers, ignoring! "
"(inst: %p, uuid: %s, flags: %#x)\n",
lustre_cfg_bufs_init(&bufs, lcfg);
if (cfg->cfg_instance &&
+ lcfg->lcfg_command != LCFG_SPTLRPC_CONF &&
LUSTRE_CFG_BUFLEN(lcfg, 0) > 0) {
- inst = 1;
inst_len = LUSTRE_CFG_BUFLEN(lcfg, 0) +
sizeof(cfg->cfg_instance) * 2 + 4;
OBD_ALLOC(inst_name, inst_len);
* moving them to index [1] and [2], and insert MGC's
* obdname at index [0].
*/
- if (cfg->cfg_instance == NULL &&
+ if (cfg->cfg_instance &&
lcfg->lcfg_command == LCFG_SPTLRPC_CONF) {
+ struct obd_device *obd = cfg->cfg_instance;
+
lustre_cfg_bufs_set(&bufs, 2, bufs.lcfg_buf[1],
bufs.lcfg_buflen[1]);
lustre_cfg_bufs_set(&bufs, 1, bufs.lcfg_buf[0],
bufs.lcfg_buflen[0]);
lustre_cfg_bufs_set_string(&bufs, 0,
- cfg->cfg_obdname);
+ obd->obd_name);
}
/* Add net info to setup command
}
}
- lcfg_new = lustre_cfg_new(lcfg->lcfg_command, &bufs);
- if (lcfg_new == NULL)
+ OBD_ALLOC(lcfg_new, lustre_cfg_len(bufs.lcfg_bufcount,
+ bufs.lcfg_buflen));
+ if (!lcfg_new)
GOTO(out, rc = -ENOMEM);
+ lustre_cfg_init(lcfg_new, lcfg->lcfg_command, &bufs);
lcfg_new->lcfg_num = lcfg->lcfg_num;
lcfg_new->lcfg_flags = lcfg->lcfg_flags;
lcfg_new->lcfg_nal = 0; /* illegal value for obsolete field */
rc = class_process_config(lcfg_new);
- lustre_cfg_free(lcfg_new);
-
- if (inst)
+ OBD_FREE(lcfg_new, lustre_cfg_len(lcfg_new->lcfg_bufcount,
+ lcfg_new->lcfg_buflens));
+ if (inst_name)
OBD_FREE(inst_name, inst_len);
break;
}
{ LCFG_DEL_CONN, "del_conn", { "1", "2", "3", "4" } },
{ LCFG_LOV_ADD_OBD, "add_osc", { "ost", "index", "gen", "UUID" } },
{ LCFG_LOV_DEL_OBD, "del_osc", { "1", "2", "3", "4" } },
- { LCFG_PARAM, "set_param", { "parameter", "value", "3", "4" } },
+ { LCFG_PARAM, "conf_param", { "parameter", "value", "3", "4" } },
{ LCFG_MARKER, "marker", { "1", "2", "3", "4" } },
{ LCFG_LOG_START, "log_start", { "1", "2", "3", "4" } },
{ LCFG_LOG_END, "log_end", { "1", "2", "3", "4" } },
{ LCFG_POOL_DEL, "del_pool", { "fsname", "pool", "3", "4" } },
{ LCFG_SET_LDLM_TIMEOUT, "set_ldlm_timeout",
{ "parameter", "2", "3", "4" } },
+ { LCFG_SET_PARAM, "set_param", { "parameter", "value", "3", "4" } },
{ 0, NULL, { NULL, NULL, NULL, NULL } }
};
}
/**
- * parse config record and output dump in supplied buffer.
+ * Parse config record and output dump in supplied buffer.
+ *
* This is separated from class_config_dump_handler() to use
* for ioctl needs as well
*
* Sample Output:
- * - { event: attach, device: lustrewt-clilov, type: lov, UUID:
- * lustrewt-clilov_UUID }
+ * - { index: 4, event: attach, device: lustrewt-clilov, type: lov,
+ * UUID: lustrewt-clilov_UUID }
*/
int class_config_yaml_output(struct llog_rec_hdr *rec, char *buf, int size)
{
return 0;
/* form YAML entity */
- ptr += snprintf(ptr, end - ptr, "- { event: %s", ldata->ltd_name);
+ ptr += snprintf(ptr, end - ptr, "- { index: %u, event: %s",
+ rec->lrh_index, ldata->ltd_name);
if (lcfg->lcfg_flags)
ptr += snprintf(ptr, end - ptr, ", flags: %#08x",
ptr += snprintf(ptr, end - ptr, ", device: %s",
lustre_cfg_string(lcfg, 0));
+ if (lcfg->lcfg_command == LCFG_SET_PARAM) {
+ /*
+ * set_param -P parameters have param=val here, separate
+ * them through pointer magic and print them out in
+ * native yamlese
+ */
+ char *cfg_str = lustre_cfg_string(lcfg, 1);
+ char *tmp = strchr(cfg_str, '=');
+ size_t len;
+
+ if (tmp == NULL)
+ return -ENOTTY;
+
+ ptr += snprintf(ptr, end - ptr, ", %s: ", ldata->ltd_bufs[0]);
+ len = tmp - cfg_str + 1;
+ snprintf(ptr, len, "%s", cfg_str);
+ ptr += len - 1;
+
+ ptr += snprintf(ptr, end - ptr, ", %s: ", ldata->ltd_bufs[1]);
+ ptr += snprintf(ptr, end - ptr, "%s", tmp + 1);
+
+ goto out_done;
+ }
+
for (i = 1; i < lcfg->lcfg_bufcount; i++) {
if (LUSTRE_CFG_BUFLEN(lcfg, i) > 0)
ptr += snprintf(ptr, end - ptr, ", %s: %s",
lustre_cfg_string(lcfg, i));
}
+out_done:
ptr += snprintf(ptr, end - ptr, " }\n");
/* return consumed bytes */
rc = ptr - buf;
lustre_cfg_bufs_reset(&bufs, obd->obd_name);
lustre_cfg_bufs_set_string(&bufs, 1, flags);
- lcfg = lustre_cfg_new(LCFG_CLEANUP, &bufs);
- if (lcfg == NULL)
+ OBD_ALLOC(lcfg, lustre_cfg_len(bufs.lcfg_bufcount, bufs.lcfg_buflen));
+ if (!lcfg)
RETURN(-ENOMEM);
+ lustre_cfg_init(lcfg, LCFG_CLEANUP, &bufs);
rc = class_process_config(lcfg);
if (rc) {
if (rc)
CERROR("detach failed %d: %s\n", rc, obd->obd_name);
out:
- lustre_cfg_free(lcfg);
- RETURN(rc);
+ OBD_FREE(lcfg, lustre_cfg_len(lcfg->lcfg_bufcount, lcfg->lcfg_buflens));
+ RETURN(rc);
}
EXPORT_SYMBOL(class_manual_cleanup);