-/* -*- mode: c; c-basic-offset: 8; indent-tabs-mode: nil; -*-
- * vim:expandtab:shiftwidth=8:tabstop=8:
- *
+/*
* GPL HEADER START
*
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* GPL HEADER END
*/
/*
- * Copyright 2008 Sun Microsystems, Inc. All rights reserved
+ * Copyright (c) 2003, 2010, Oracle and/or its affiliates. All rights reserved.
* Use is subject to license terms.
+ *
+ * Copyright (c) 2011, 2012, Intel Corporation.
*/
/*
* This file is part of Lustre, http://www.lustre.org/
int lcfg_set_devname(char *name)
{
+ char *ptr;
+ int digit = 1;
+
if (name) {
if (lcfg_devname)
free(lcfg_devname);
/* quietly strip the unnecessary '$' */
if (*name == '$' || *name == '%')
name++;
- if (isdigit(*name)) {
+
+ ptr = name;
+ while (*ptr != '\0') {
+ if (!isdigit(*ptr)) {
+ digit = 0;
+ break;
+ }
+ ptr++;
+ }
+
+ if (digit) {
/* We can't translate from dev # to name */
lcfg_devname = NULL;
} else {
}
/* Param set in config log on MGS */
-/* conf_param key1=value1 [key2=value2...] */
+/* conf_param key=value */
+/* Note we can actually send mgc conf_params from clients, but currently
+ * that's only done for default file striping (see ll_send_mgc_param),
+ * and not here. */
+/* After removal of a parameter (-d) Lustre will use the default
+ * AT NEXT REBOOT, not immediately. */
int jt_lcfg_mgsparam(int argc, char **argv)
{
- int i, rc;
+ int rc;
+ int del = 0;
struct lustre_cfg_bufs bufs;
struct lustre_cfg *lcfg;
+ char *buf = NULL;
- if ((argc >= LUSTRE_CFG_MAX_BUFCOUNT) || (argc <= 1))
+ /* mgs_setparam processes only lctl buf #1 */
+ if ((argc > 3) || (argc <= 1))
return CMD_HELP;
+ while ((rc = getopt(argc, argv, "d")) != -1) {
+ switch (rc) {
+ case 'd':
+ del = 1;
+ break;
+ default:
+ return CMD_HELP;
+ }
+ }
+
lustre_cfg_bufs_reset(&bufs, NULL);
- for (i = 1; i < argc; i++) {
- lustre_cfg_bufs_set_string(&bufs, i, argv[i]);
+ if (del) {
+ char *ptr;
+
+ /* for delete, make it "<param>=\0" */
+ buf = malloc(strlen(argv[optind]) + 2);
+ /* put an '=' on the end in case it doesn't have one */
+ sprintf(buf, "%s=", argv[optind]);
+ /* then truncate after the first '=' */
+ ptr = strchr(buf, '=');
+ *(++ptr) = '\0';
+ lustre_cfg_bufs_set_string(&bufs, 1, buf);
+ } else {
+ lustre_cfg_bufs_set_string(&bufs, 1, argv[optind]);
}
/* We could put other opcodes here. */
rc = lcfg_mgs_ioctl(argv[0], OBD_DEV_ID, lcfg);
lustre_cfg_free(lcfg);
+ if (buf)
+ free(buf);
if (rc < 0) {
fprintf(stderr, "error: %s: %s\n", jt_cmdname(argv[0]),
strerror(rc = errno));
if (strncmp(filename, "lustre/", strlen("lustre/")) == 0)
filename += strlen("lustre/");
+ else if (strncmp(filename, "lnet/", strlen("lnet/")) == 0)
+ filename += strlen("lnet/");
/* replace '/' with '.' to match conf_param and sysctl */
tmp = filename;
}
}
+/* Supporting file paths creates perilous behavoir: LU-888.
+ * Path support is deprecated.
+ * If a path is supplied it must begin with /proc. */
+static void lprocfs_param_pattern(const char *cmd, const char *path, char *buf,
+ size_t buf_size)
+{
+ /* test path to see if it begins with '/proc/' */
+ if (strncmp(path, "/proc/", strlen("/proc/")) == 0) {
+ static int warned;
+ if (!warned) {
+ fprintf(stderr, "%s: specifying parameters via "
+ "full paths is deprecated.\n", cmd);
+#if LUSTRE_VERSION_CODE >= OBD_OCD_VERSION(2, 6, 50, 0)
+#warning "remove deprecated full path tunable access"
+#endif
+ warned = 1;
+ }
+ snprintf(buf, buf_size, "%s", path);
+ } else {
+ snprintf(buf, buf_size, "/proc/{fs,sys}/{lnet,lustre}/%s",
+ path);
+ }
+}
+
struct param_opts {
- int only_path;
- int show_path;
- int show_type;
- int recursive;
+ int only_path:1;
+ int show_path:1;
+ int show_type:1;
+ int recursive:1;
};
static int listparam_cmdline(int argc, char **argv, struct param_opts *popt)
int jt_lcfg_listparam(int argc, char **argv)
{
- int fp;
int rc = 0, i;
struct param_opts popt;
char pattern[PATH_MAX];
clean_path(path);
- /* If the entire path is specified as input */
- fp = open(path, O_RDONLY);
- if (fp < 0) {
- snprintf(pattern, PATH_MAX, "/proc/{fs,sys}/{lnet,lustre}/%s",
- path);
- } else {
- strcpy(pattern, path);
- close(fp);
- }
+ lprocfs_param_pattern(argv[0], path, pattern, sizeof(pattern));
rc = listparam_display(&popt, pattern);
if (rc < 0)
popt->show_path = 1;
popt->only_path = 0;
popt->show_type = 0;
+ popt->recursive = 0;
while ((ch = getopt(argc, argv, "nNF")) != -1) {
switch (ch) {
int jt_lcfg_getparam(int argc, char **argv)
{
- int fp;
int rc = 0, i;
struct param_opts popt;
char pattern[PATH_MAX];
if (rc < 0 || rc >= argc)
return CMD_HELP;
- for (i = rc; i < argc; i++) {
- path = argv[i];
+ for (i = rc, rc = 0; i < argc; i++) {
+ int rc2;
- clean_path(path);
+ path = argv[i];
- /* If the entire path is specified as input */
- fp = open(path, O_RDONLY);
- if (fp < 0) {
- snprintf(pattern, PATH_MAX, "/proc/{fs,sys}/{lnet,lustre}/%s",
- path);
- } else {
- strcpy(pattern, path);
- close(fp);
- }
+ clean_path(path);
- if (popt.only_path)
- rc = listparam_display(&popt, pattern);
- else
- rc = getparam_display(&popt, pattern);
- if (rc < 0)
- return rc;
- }
+ lprocfs_param_pattern(argv[0], path, pattern, sizeof(pattern));
- return 0;
+ if (popt.only_path)
+ rc2 = listparam_display(&popt, pattern);
+ else
+ rc2 = getparam_display(&popt, pattern);
+ if (rc2 < 0 && rc == 0)
+ rc = rc2;
+ }
+
+ return rc;
}
static int setparam_cmdline(int argc, char **argv, struct param_opts *popt)
popt->show_path = 1;
popt->only_path = 0;
popt->show_type = 0;
+ popt->recursive = 0;
while ((ch = getopt(argc, argv, "n")) != -1) {
switch (ch) {
pattern, globerrstr(rc));
return -ESRCH;
}
- for (i = 0; i < glob_info.gl_pathc; i++) {
- char *valuename = NULL;
-
- if (popt->show_path) {
- strcpy(filename, glob_info.gl_pathv[i]);
- valuename = display_name(filename, 0);
- if (valuename)
- printf("%s=%s\n", valuename, value);
- }
- /* Write the new value to the file */
- fd = open(glob_info.gl_pathv[i], O_WRONLY);
- if (fd > 0) {
- rc = write(fd, value, strlen(value));
- if (rc < 0)
- fprintf(stderr, "error: set_param: "
- "writing to file %s: %s\n",
- glob_info.gl_pathv[i], strerror(errno));
- else
- rc = 0;
- close(fd);
- } else {
- fprintf(stderr, "error: set_param: %s opening %s\n",
- strerror(rc = errno), glob_info.gl_pathv[i]);
- }
- }
-
- globfree(&glob_info);
- return rc;
+ for (i = 0; i < glob_info.gl_pathc; i++) {
+ char *valuename = NULL;
+
+ if (popt->show_path) {
+ strcpy(filename, glob_info.gl_pathv[i]);
+ valuename = display_name(filename, 0);
+ if (valuename)
+ printf("%s=%s\n", valuename, value);
+ }
+ /* Write the new value to the file */
+ fd = open(glob_info.gl_pathv[i], O_WRONLY);
+ if (fd > 0) {
+ rc = write(fd, value, strlen(value));
+ if (rc < 0)
+ fprintf(stderr, "error: set_param: setting "
+ "%s=%s: %s\n", glob_info.gl_pathv[i],
+ value, strerror(errno));
+ else
+ rc = 0;
+ close(fd);
+ } else {
+ fprintf(stderr, "error: set_param: %s opening %s\n",
+ strerror(rc = errno), glob_info.gl_pathv[i]);
+ }
+ }
+
+ globfree(&glob_info);
+ return rc;
}
int jt_lcfg_setparam(int argc, char **argv)
{
- int fp;
int rc = 0, i;
struct param_opts popt;
char pattern[PATH_MAX];
if (rc < 0 || rc >= argc)
return CMD_HELP;
- for (i = rc; i < argc; i++) {
+ for (i = rc, rc = 0; i < argc; i++) {
+ int rc2;
+
if ((value = strchr(argv[i], '=')) != NULL) {
/* format: set_param a=b */
*value = '\0';
clean_path(path);
- /* If the entire path is specified as input */
- fp = open(path, O_RDONLY);
- if (fp < 0) {
- snprintf(pattern, PATH_MAX, "/proc/{fs,sys}/{lnet,lustre}/%s",
- path);
- } else {
- strcpy(pattern, path);
- close(fp);
- }
+ lprocfs_param_pattern(argv[0], path, pattern, sizeof(pattern));
- rc = setparam_display(&popt, pattern, value);
+ rc2 = setparam_display(&popt, pattern, value);
path = NULL;
value = NULL;
- if (rc < 0)
- return rc;
- }
+ if (rc2 < 0 && rc == 0)
+ rc = rc2;
+ }
- return 0;
+ return rc;
}
+