X-Git-Url: https://git.whamcloud.com/?a=blobdiff_plain;f=lustre%2Futils%2Flustre_cfg.c;h=93adfb3075088cb21166122726f0ffcc587619be;hb=fd4cee4cc545679d2a00c2a20939564e36700631;hp=6860502bcc491d0be445844d134de67bbcdfe049;hpb=5e546603cbff0939c9f6335d9daddc641530dd7e;p=fs%2Flustre-release.git diff --git a/lustre/utils/lustre_cfg.c b/lustre/utils/lustre_cfg.c index 6860502..93adfb3 100644 --- a/lustre/utils/lustre_cfg.c +++ b/lustre/utils/lustre_cfg.c @@ -1,6 +1,4 @@ -/* -*- 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. @@ -26,8 +24,10 @@ * 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, Whamcloud, Inc. */ /* * This file is part of Lustre, http://www.lustre.org/ @@ -77,13 +77,26 @@ static char * lcfg_devname; 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 { @@ -570,6 +583,8 @@ static char *display_name(char *filename, int show_type) 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; @@ -644,11 +659,35 @@ static void clean_path(char *path) } } +/* 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) @@ -720,7 +759,6 @@ static int listparam_display(struct param_opts *popt, char *pattern) int jt_lcfg_listparam(int argc, char **argv) { - int fp; int rc = 0, i; struct param_opts popt; char pattern[PATH_MAX]; @@ -739,15 +777,7 @@ int jt_lcfg_listparam(int argc, char **argv) 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) @@ -764,6 +794,7 @@ static int getparam_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, "nNF")) != -1) { switch (ch) { @@ -860,7 +891,6 @@ static int getparam_display(struct param_opts *popt, char *pattern) int jt_lcfg_getparam(int argc, char **argv) { - int fp; int rc = 0, i; struct param_opts popt; char pattern[PATH_MAX]; @@ -875,15 +905,7 @@ int jt_lcfg_getparam(int argc, char **argv) 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)); if (popt.only_path) rc = listparam_display(&popt, pattern); @@ -903,6 +925,7 @@ 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) { @@ -962,7 +985,6 @@ static int setparam_display(struct param_opts *popt, char *pattern, char *value) int jt_lcfg_setparam(int argc, char **argv) { - int fp; int rc = 0, i; struct param_opts popt; char pattern[PATH_MAX]; @@ -990,15 +1012,7 @@ int jt_lcfg_setparam(int argc, char **argv) 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); path = NULL; @@ -1009,3 +1023,4 @@ int jt_lcfg_setparam(int argc, char **argv) return 0; } +