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.sun.com/software/products/lustre/docs/GPLv2.pdf
20 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
21 * CA 95054 USA or visit www.sun.com if you need additional information or
27 * Copyright (c) 2003, 2010, Oracle and/or its affiliates. All rights reserved.
28 * Use is subject to license terms.
30 * Copyright (c) 2011, 2015, Intel Corporation.
33 * This file is part of Lustre, http://www.lustre.org/
34 * Lustre is a trademark of Sun Microsystems, Inc.
36 * lustre/utils/lustre_cfg.c
38 * Author: Peter J. Braam <braam@clusterfs.com>
39 * Author: Phil Schwan <phil@clusterfs.com>
40 * Author: Andreas Dilger <adilger@clusterfs.com>
41 * Author: Robert Read <rread@clusterfs.com>
45 #include <sys/ioctl.h>
53 #include <libcfs/util/string.h>
54 #include <libcfs/util/parser.h>
55 #include <lnet/nidstr.h>
56 #include <lustre_cfg.h>
57 #include <lustre/lustre_idl.h>
58 #include <lustre/lustre_build_version.h>
68 #include <lnet/lnetctl.h>
71 static char * lcfg_devname;
73 int lcfg_set_devname(char *name)
81 /* quietly strip the unnecessary '$' */
82 if (*name == '$' || *name == '%')
86 while (*ptr != '\0') {
95 /* We can't translate from dev # to name */
98 lcfg_devname = strdup(name);
106 char * lcfg_get_devname(void)
111 int jt_lcfg_device(int argc, char **argv)
113 return jt_obd_device(argc, argv);
116 int jt_lcfg_attach(int argc, char **argv)
118 struct lustre_cfg_bufs bufs;
119 struct lustre_cfg *lcfg;
125 lustre_cfg_bufs_reset(&bufs, NULL);
127 lustre_cfg_bufs_set_string(&bufs, 1, argv[1]);
128 lustre_cfg_bufs_set_string(&bufs, 0, argv[2]);
129 lustre_cfg_bufs_set_string(&bufs, 2, argv[3]);
131 lcfg = lustre_cfg_new(LCFG_ATTACH, &bufs);
135 rc = lcfg_ioctl(argv[0], OBD_DEV_ID, lcfg);
136 lustre_cfg_free(lcfg);
139 fprintf(stderr, "error: %s: LCFG_ATTACH %s\n",
140 jt_cmdname(argv[0]), strerror(rc = errno));
142 lcfg_set_devname(argv[2]);
148 int jt_lcfg_setup(int argc, char **argv)
150 struct lustre_cfg_bufs bufs;
151 struct lustre_cfg *lcfg;
155 if (lcfg_devname == NULL) {
156 fprintf(stderr, "%s: please use 'device name' to set the "
157 "device name for config commands.\n",
158 jt_cmdname(argv[0]));
162 lustre_cfg_bufs_reset(&bufs, lcfg_devname);
167 for (i = 1; i < argc; i++) {
168 lustre_cfg_bufs_set_string(&bufs, i, argv[i]);
171 lcfg = lustre_cfg_new(LCFG_SETUP, &bufs);
175 rc = lcfg_ioctl(argv[0], OBD_DEV_ID, lcfg);
176 lustre_cfg_free(lcfg);
179 fprintf(stderr, "error: %s: %s\n", jt_cmdname(argv[0]),
180 strerror(rc = errno));
185 int jt_obd_detach(int argc, char **argv)
187 struct lustre_cfg_bufs bufs;
188 struct lustre_cfg *lcfg;
191 if (lcfg_devname == NULL) {
192 fprintf(stderr, "%s: please use 'device name' to set the "
193 "device name for config commands.\n",
194 jt_cmdname(argv[0]));
198 lustre_cfg_bufs_reset(&bufs, lcfg_devname);
203 lcfg = lustre_cfg_new(LCFG_DETACH, &bufs);
207 rc = lcfg_ioctl(argv[0], OBD_DEV_ID, lcfg);
208 lustre_cfg_free(lcfg);
211 fprintf(stderr, "error: %s: %s\n", jt_cmdname(argv[0]),
212 strerror(rc = errno));
217 int jt_obd_cleanup(int argc, char **argv)
219 struct lustre_cfg_bufs bufs;
220 struct lustre_cfg *lcfg;
223 char flags[3] = { 0 };
227 if (lcfg_devname == NULL) {
228 fprintf(stderr, "%s: please use 'device name' to set the "
229 "device name for config commands.\n",
230 jt_cmdname(argv[0]));
234 lustre_cfg_bufs_reset(&bufs, lcfg_devname);
236 if (argc < 1 || argc > 3)
239 /* we are protected from overflowing our buffer by the argc
242 for (n = 1; n < argc; n++) {
243 if (strcmp(argv[n], "force") == 0) {
244 flags[flag_cnt++] = force;
245 } else if (strcmp(argv[n], "failover") == 0) {
246 flags[flag_cnt++] = failover;
248 fprintf(stderr, "unknown option: %s\n", argv[n]);
254 lustre_cfg_bufs_set_string(&bufs, 1, flags);
257 lcfg = lustre_cfg_new(LCFG_CLEANUP, &bufs);
261 rc = lcfg_ioctl(argv[0], OBD_DEV_ID, lcfg);
262 lustre_cfg_free(lcfg);
265 fprintf(stderr, "error: %s: %s\n", jt_cmdname(argv[0]),
266 strerror(rc = errno));
272 int do_add_uuid(char * func, char *uuid, lnet_nid_t nid)
275 struct lustre_cfg_bufs bufs;
276 struct lustre_cfg *lcfg;
278 lustre_cfg_bufs_reset(&bufs, lcfg_devname);
280 lustre_cfg_bufs_set_string(&bufs, 1, uuid);
282 lcfg = lustre_cfg_new(LCFG_ADD_UUID, &bufs);
286 lcfg->lcfg_nid = nid;
288 rc = lcfg_ioctl(func, OBD_DEV_ID, lcfg);
289 lustre_cfg_free(lcfg);
292 fprintf(stderr, "IOC_PORTAL_ADD_UUID failed: %s\n",
298 printf("Added uuid %s: %s\n", uuid, libcfs_nid2str(nid));
303 int jt_lcfg_add_uuid(int argc, char **argv)
311 nid = libcfs_str2nid(argv[2]);
312 if (nid == LNET_NID_ANY) {
313 fprintf (stderr, "Can't parse NID %s\n", argv[2]);
317 return do_add_uuid(argv[0], argv[1], nid);
320 int jt_lcfg_del_uuid(int argc, char **argv)
323 struct lustre_cfg_bufs bufs;
324 struct lustre_cfg *lcfg;
327 fprintf(stderr, "usage: %s <uuid>\n", argv[0]);
331 lustre_cfg_bufs_reset(&bufs, lcfg_devname);
332 if (strcmp (argv[1], "_all_"))
333 lustre_cfg_bufs_set_string(&bufs, 1, argv[1]);
335 lcfg = lustre_cfg_new(LCFG_DEL_UUID, &bufs);
339 rc = lcfg_ioctl(argv[0], OBD_DEV_ID, lcfg);
340 lustre_cfg_free(lcfg);
343 fprintf(stderr, "IOC_PORTAL_DEL_UUID failed: %s\n",
350 int jt_lcfg_del_mount_option(int argc, char **argv)
353 struct lustre_cfg_bufs bufs;
354 struct lustre_cfg *lcfg;
359 lustre_cfg_bufs_reset(&bufs, lcfg_devname);
362 lustre_cfg_bufs_set_string(&bufs, 1, argv[1]);
364 lcfg = lustre_cfg_new(LCFG_DEL_MOUNTOPT, &bufs);
368 rc = lcfg_ioctl(argv[0], OBD_DEV_ID, lcfg);
369 lustre_cfg_free(lcfg);
372 fprintf(stderr, "error: %s: %s\n", jt_cmdname(argv[0]),
373 strerror(rc = errno));
378 int jt_lcfg_set_timeout(int argc, char **argv)
381 struct lustre_cfg_bufs bufs;
382 struct lustre_cfg *lcfg;
384 fprintf(stderr, "%s has been deprecated. Use conf_param instead.\n"
385 "e.g. conf_param lustre-MDT0000 obd_timeout=50\n",
386 jt_cmdname(argv[0]));
393 lustre_cfg_bufs_reset(&bufs, lcfg_devname);
394 lcfg = lustre_cfg_new(LCFG_SET_TIMEOUT, &bufs);
398 lcfg->lcfg_num = atoi(argv[1]);
400 rc = lcfg_ioctl(argv[0], OBD_DEV_ID, lcfg);
401 lustre_cfg_free(lcfg);
404 fprintf(stderr, "error: %s: %s\n", jt_cmdname(argv[0]),
405 strerror(rc = errno));
410 int jt_lcfg_add_conn(int argc, char **argv)
412 struct lustre_cfg_bufs bufs;
413 struct lustre_cfg *lcfg;
424 if (lcfg_devname == NULL) {
425 fprintf(stderr, "%s: please use 'device name' to set the "
426 "device name for config commands.\n",
427 jt_cmdname(argv[0]));
431 lustre_cfg_bufs_reset(&bufs, lcfg_devname);
433 lustre_cfg_bufs_set_string(&bufs, 1, argv[1]);
435 lcfg = lustre_cfg_new(LCFG_ADD_CONN, &bufs);
439 lcfg->lcfg_num = priority;
441 rc = lcfg_ioctl(argv[0], OBD_DEV_ID, lcfg);
442 lustre_cfg_free(lcfg);
445 fprintf(stderr, "error: %s: %s\n", jt_cmdname(argv[0]),
446 strerror(rc = errno));
452 int jt_lcfg_del_conn(int argc, char **argv)
454 struct lustre_cfg_bufs bufs;
455 struct lustre_cfg *lcfg;
461 if (lcfg_devname == NULL) {
462 fprintf(stderr, "%s: please use 'device name' to set the "
463 "device name for config commands.\n",
464 jt_cmdname(argv[0]));
468 lustre_cfg_bufs_reset(&bufs, lcfg_devname);
470 /* connection uuid */
471 lustre_cfg_bufs_set_string(&bufs, 1, argv[1]);
473 lcfg = lustre_cfg_new(LCFG_DEL_MOUNTOPT, &bufs);
477 rc = lcfg_ioctl(argv[0], OBD_DEV_ID, lcfg);
478 lustre_cfg_free(lcfg);
481 fprintf(stderr, "error: %s: %s\n", jt_cmdname(argv[0]),
482 strerror(rc = errno));
488 /* Param set locally, directly on target */
489 int jt_lcfg_param(int argc, char **argv)
492 struct lustre_cfg_bufs bufs;
493 struct lustre_cfg *lcfg;
495 if (argc >= LUSTRE_CFG_MAX_BUFCOUNT)
498 lustre_cfg_bufs_reset(&bufs, NULL);
500 for (i = 1; i < argc; i++) {
501 lustre_cfg_bufs_set_string(&bufs, i, argv[i]);
504 lcfg = lustre_cfg_new(LCFG_PARAM, &bufs);
508 rc = lcfg_ioctl(argv[0], OBD_DEV_ID, lcfg);
509 lustre_cfg_free(lcfg);
512 fprintf(stderr, "error: %s: %s\n", jt_cmdname(argv[0]),
513 strerror(rc = errno));
519 unsigned int po_only_path:1;
520 unsigned int po_show_path:1;
521 unsigned int po_show_type:1;
522 unsigned int po_recursive:1;
523 unsigned int po_params2:1;
524 unsigned int po_delete:1;
525 unsigned int po_only_dir:1;
528 /* Param set to single log file, used by all clients and servers.
529 * This should be loaded after the individual config logs.
530 * Called from set param with -P option.
532 static int jt_lcfg_mgsparam2(int argc, char **argv, struct param_opts *popt)
536 struct lustre_cfg_bufs bufs;
537 struct lustre_cfg *lcfg;
541 first_param = optind;
542 if (first_param < 0 || first_param >= argc)
545 for (i = first_param, rc = 0; i < argc; i++) {
546 lustre_cfg_bufs_reset(&bufs, NULL);
547 /* This same command would be executed on all nodes, many
548 * of which should fail (silently) because they don't have
549 * that proc file existing locally. There would be no
550 * preprocessing on the MGS to try to figure out which
551 * parameter files to add this to, there would be nodes
552 * processing on the cluster nodes to try to figure out
553 * if they are the intended targets. They will blindly
554 * try to set the parameter, and ENOTFOUND means it wasn't
556 * Target name "general" means call on all targets. It is
557 * left here in case some filtering will be added in
560 lustre_cfg_bufs_set_string(&bufs, 0, "general");
562 len = strlen(argv[i]);
564 /* put an '=' on the end in case it doesn't have one */
565 if (popt->po_delete && argv[i][len - 1] != '=') {
566 buf = malloc(len + 1);
567 sprintf(buf, "%s=", argv[i]);
571 lustre_cfg_bufs_set_string(&bufs, 1, buf);
573 lcfg = lustre_cfg_new(LCFG_SET_PARAM, &bufs);
575 fprintf(stderr, "error: allocating lcfg for %s: %s\n",
576 jt_cmdname(argv[0]), strerror(-ENOMEM));
580 int rc2 = lcfg_mgs_ioctl(argv[0], OBD_DEV_ID, lcfg);
582 fprintf(stderr, "error: executing %s: %s\n",
583 jt_cmdname(argv[0]), strerror(errno));
587 lustre_cfg_free(lcfg);
596 /* Param set in config log on MGS */
597 /* conf_param key=value */
598 /* Note we can actually send mgc conf_params from clients, but currently
599 * that's only done for default file striping (see ll_send_mgc_param),
601 /* After removal of a parameter (-d) Lustre will use the default
602 * AT NEXT REBOOT, not immediately. */
603 int jt_lcfg_mgsparam(int argc, char **argv)
607 struct lustre_cfg_bufs bufs;
608 struct lustre_cfg *lcfg;
611 #if LUSTRE_VERSION_CODE >= OBD_OCD_VERSION(2, 8, 53, 0)
612 fprintf(stderr, "warning: 'lctl conf_param' is deprecated, "
613 "use 'lctl set_param -P' instead\n");
616 /* mgs_setparam processes only lctl buf #1 */
617 if ((argc > 3) || (argc <= 1))
620 while ((rc = getopt(argc, argv, "d")) != -1) {
630 lustre_cfg_bufs_reset(&bufs, NULL);
634 /* for delete, make it "<param>=\0" */
635 buf = malloc(strlen(argv[optind]) + 2);
636 /* put an '=' on the end in case it doesn't have one */
637 sprintf(buf, "%s=", argv[optind]);
638 /* then truncate after the first '=' */
639 ptr = strchr(buf, '=');
641 lustre_cfg_bufs_set_string(&bufs, 1, buf);
643 lustre_cfg_bufs_set_string(&bufs, 1, argv[optind]);
646 /* We could put other opcodes here. */
647 lcfg = lustre_cfg_new(LCFG_PARAM, &bufs);
651 rc = lcfg_mgs_ioctl(argv[0], OBD_DEV_ID, lcfg);
652 lustre_cfg_free(lcfg);
657 fprintf(stderr, "error: %s: %s\n", jt_cmdname(argv[0]),
658 strerror(rc = errno));
664 /* Display the path in the same format as sysctl
665 * For eg. obdfilter.lustre-OST0000.stats */
667 display_name(char *filename, size_t filename_size, struct param_opts *popt)
673 if (popt->po_show_type || popt->po_only_dir) {
674 if (lstat(filename, &st) == -1)
677 if (popt->po_show_type) {
678 if (S_ISDIR(st.st_mode))
680 else if (S_ISLNK(st.st_mode))
682 else if (st.st_mode & S_IWUSR)
684 } else if (popt->po_only_dir) {
685 if (!S_ISDIR(st.st_mode))
690 filename += strlen("/proc/");
691 if (strncmp(filename, "fs/", strlen("fs/")) == 0)
692 filename += strlen("fs/");
694 filename += strlen("sys/");
696 if (strncmp(filename, "lustre/", strlen("lustre/")) == 0)
697 filename += strlen("lustre/");
698 else if (strncmp(filename, "lnet/", strlen("lnet/")) == 0)
699 filename += strlen("lnet/");
701 /* replace '/' with '.' to match conf_param and sysctl */
703 while ((tmp = strchr(tmp, '/')) != NULL)
706 /* Append the indicator to entries. We know there is enough space
707 * for the suffix, since the path prefix was deleted. */
708 if (popt->po_show_type && suffix != NULL)
709 strncat(filename, suffix, filename_size);
714 /* Find a character in a length limited string */
715 /* BEWARE - kernel definition of strnchr has args in different order! */
716 static char *strnchr(const char *p, char c, size_t n)
729 static char *globerrstr(int glob_rc)
733 return "Out of memory";
737 return "Found no match";
739 return "Unknown error";
742 static void clean_path(char *path)
746 /* If the input is in form Eg. obdfilter.*.stats */
747 if (strchr(path, '.')) {
749 while (*tmp != '\0') {
751 (tmp != path) && (*(tmp - 1) != '\\'))
756 /* get rid of '\', glob doesn't like it */
757 if ((tmp = strrchr(path, '\\')) != NULL) {
758 char *tail = path + strlen(path);
759 while (tmp != path) {
761 memmove(tmp, tmp + 1, tail - tmp);
769 /* Take a parameter name and turn it into a pathname glob.
770 * Disallow relative pathnames to avoid potential problems. */
771 static int lprocfs_param_pattern(const char *pattern, char *buf, size_t bufsize)
775 rc = snprintf(buf, bufsize, "/proc/{fs,sys}/{lnet,lustre}/%s", pattern);
778 } else if (rc >= bufsize) {
779 fprintf(stderr, "error: parameter '%s' too long\n", pattern);
786 static int listparam_cmdline(int argc, char **argv, struct param_opts *popt)
790 popt->po_show_path = 1;
791 popt->po_only_path = 1;
793 while ((ch = getopt(argc, argv, "FRD")) != -1) {
796 popt->po_show_type = 1;
799 popt->po_recursive = 1;
802 popt->po_only_dir = 1;
812 static int listparam_display(struct param_opts *popt, char *pattern)
818 rc = glob(pattern, /* GLOB_ONLYDIR doesn't guarantee, only a hint */
819 GLOB_BRACE | (popt->po_only_dir ? GLOB_ONLYDIR : 0) |
820 (popt->po_recursive ? GLOB_MARK : 0),
823 fprintf(stderr, "error: list_param: %s: %s\n",
824 pattern, globerrstr(rc));
828 for (i = 0; i < glob_info.gl_pathc; i++) {
829 char pathname[PATH_MAX + 1]; /* extra 1 byte for file type */
830 int len = sizeof(pathname), last;
831 char *paramname = NULL;
833 /* Trailing '/' will indicate recursion into directory */
834 last = strlen(glob_info.gl_pathv[i]) - 1;
836 /* Remove trailing '/' or it will be converted to '.' */
837 if (last > 0 && glob_info.gl_pathv[i][last] == '/')
838 glob_info.gl_pathv[i][last] = '\0';
841 strlcpy(pathname, glob_info.gl_pathv[i], len);
842 paramname = display_name(pathname, len, popt);
844 printf("%s\n", paramname);
846 strlcpy(pathname, glob_info.gl_pathv[i], len);
847 strlcat(pathname, "/*", len);
848 listparam_display(popt, pathname);
852 globfree(&glob_info);
856 int jt_lcfg_listparam(int argc, char **argv)
859 struct param_opts popt;
860 char pattern[PATH_MAX];
863 memset(&popt, 0, sizeof(popt));
864 rc = listparam_cmdline(argc, argv, &popt);
865 if (rc == argc && popt.po_recursive) {
866 rc--; /* we know at least "-R" is a parameter */
868 } else if (rc < 0 || rc >= argc) {
872 for (i = rc; i < argc; i++) {
876 rc = lprocfs_param_pattern(path, pattern, sizeof(pattern));
880 rc = listparam_display(&popt, pattern);
888 static int getparam_cmdline(int argc, char **argv, struct param_opts *popt)
892 popt->po_show_path = 1;
894 while ((ch = getopt(argc, argv, "FnNR")) != -1) {
897 popt->po_show_type = 1;
900 popt->po_show_path = 0;
903 popt->po_only_path = 1;
906 popt->po_recursive = 1;
916 static int getparam_display(struct param_opts *popt, char *pattern)
918 long page_size = sysconf(_SC_PAGESIZE);
925 rc = glob(pattern, GLOB_BRACE | (popt->po_recursive ? GLOB_MARK : 0),
928 fprintf(stderr, "error: get_param: %s: %s\n",
929 pattern, globerrstr(rc));
933 buf = malloc(page_size);
937 for (i = 0; i < glob_info.gl_pathc; i++) {
938 char pathname[PATH_MAX + 1]; /* extra 1 byte for file type */
939 int len = sizeof(pathname), last;
940 char *paramname = NULL;
942 memset(buf, 0, page_size);
943 /* Trailing '/' will indicate recursion into directory */
944 last = strlen(glob_info.gl_pathv[i]) - 1;
946 /* Remove trailing '/' or it will be converted to '.' */
947 if (last > 0 && glob_info.gl_pathv[i][last] == '/')
948 glob_info.gl_pathv[i][last] = '\0';
953 strlcpy(pathname, glob_info.gl_pathv[i], len);
954 strlcat(pathname, "/*", len);
955 getparam_display(popt, pathname);
959 if (popt->po_show_path) {
960 if (strlen(glob_info.gl_pathv[i]) >
961 sizeof(pathname) - 1) {
965 strncpy(pathname, glob_info.gl_pathv[i],
967 paramname = display_name(pathname, sizeof(pathname),
971 /* Write the contents of file to stdout */
972 fd = open(glob_info.gl_pathv[i], O_RDONLY);
975 "error: get_param: opening('%s') failed: %s\n",
976 glob_info.gl_pathv[i], strerror(errno));
981 rc = read(fd, buf, page_size);
985 fprintf(stderr, "error: get_param: "
986 "read('%s') failed: %s\n",
987 glob_info.gl_pathv[i], strerror(errno));
990 /* Print the output in the format path=value if the
991 * value contains no new line character or can be
992 * occupied in a line, else print value on new line */
993 if (paramname && popt->po_show_path) {
996 longbuf = strnchr(buf, rc - 1, '\n') != NULL ||
997 rc + strlen(paramname) >= 80;
998 printf("%s=%s", paramname,
999 longbuf ? "\n" : buf);
1005 rc = write(fileno(stdout), buf, rc);
1007 fprintf(stderr, "error: get_param: "
1008 "write to stdout failed: %s\n",
1016 globfree(&glob_info);
1021 int jt_lcfg_getparam(int argc, char **argv)
1024 struct param_opts popt;
1025 char pattern[PATH_MAX];
1028 memset(&popt, 0, sizeof(popt));
1029 rc = getparam_cmdline(argc, argv, &popt);
1030 if (rc == argc && popt.po_recursive) {
1031 rc--; /* we know at least "-R" is a parameter */
1033 } else if (rc < 0 || rc >= argc) {
1037 for (i = rc, rc = 0; i < argc; i++) {
1043 rc2 = lprocfs_param_pattern(path, pattern, sizeof(pattern));
1047 if (popt.po_only_path)
1048 rc2 = listparam_display(&popt, pattern);
1050 rc2 = getparam_display(&popt, pattern);
1051 if (rc2 < 0 && rc == 0)
1059 * Output information about nodemaps.
1060 * \param argc number of args
1061 * \param argv[] variable string arguments
1063 * [list|nodemap_name|all] \a list will list all nodemaps (default).
1064 * Specifying a \a nodemap_name will
1065 * display info about that specific nodemap.
1066 * \a all will display info for all nodemaps.
1067 * \retval 0 on success
1069 int jt_nodemap_info(int argc, char **argv)
1071 const char usage_str[] = "usage: nodemap_info "
1072 "[list|nodemap_name|all]\n";
1073 struct param_opts popt;
1076 memset(&popt, 0, sizeof(popt));
1077 popt.po_show_path = 1;
1080 fprintf(stderr, usage_str);
1084 if (argc == 1 || strcmp("list", argv[1]) == 0) {
1085 popt.po_only_path = 1;
1086 popt.po_only_dir = 1;
1087 rc = listparam_display(&popt, "nodemap/*");
1088 } else if (strcmp("all", argv[1]) == 0) {
1089 rc = getparam_display(&popt, "nodemap/*/*");
1091 char pattern[PATH_MAX];
1093 snprintf(pattern, sizeof(pattern), "nodemap/%s/*", argv[1]);
1094 rc = getparam_display(&popt, pattern);
1096 fprintf(stderr, "error: nodemap_info: cannot find"
1097 "nodemap %s\n", argv[1]);
1103 static int setparam_cmdline(int argc, char **argv, struct param_opts *popt)
1107 popt->po_show_path = 1;
1108 popt->po_only_path = 0;
1109 popt->po_show_type = 0;
1110 popt->po_recursive = 0;
1111 popt->po_params2 = 0;
1112 popt->po_delete = 0;
1114 while ((ch = getopt(argc, argv, "nPd")) != -1) {
1117 popt->po_show_path = 0;
1120 popt->po_params2 = 1;
1123 popt->po_delete = 1;
1132 static int setparam_display(struct param_opts *popt, char *pattern, char *value)
1139 rc = glob(pattern, GLOB_BRACE, NULL, &glob_info);
1141 fprintf(stderr, "error: set_param: %s: %s\n",
1142 pattern, globerrstr(rc));
1145 for (i = 0; i < glob_info.gl_pathc; i++) {
1146 char pathname[PATH_MAX + 1]; /* extra 1 byte for file type */
1147 char *paramname = NULL;
1149 if (popt->po_show_path) {
1150 if (strlen(glob_info.gl_pathv[i]) >
1151 sizeof(pathname) - 1)
1153 strncpy(pathname, glob_info.gl_pathv[i],
1155 paramname = display_name(pathname, sizeof(pathname),
1158 printf("%s=%s\n", paramname, value);
1160 /* Write the new value to the file */
1161 fd = open(glob_info.gl_pathv[i], O_WRONLY);
1165 rc2 = write(fd, value, strlen(value));
1169 fprintf(stderr, "error: set_param: setting "
1170 "%s=%s: %s\n", glob_info.gl_pathv[i],
1171 value, strerror(errno));
1177 fprintf(stderr, "error: set_param: opening %s: %s\n",
1178 strerror(errno), glob_info.gl_pathv[i]);
1182 globfree(&glob_info);
1186 int jt_lcfg_setparam(int argc, char **argv)
1189 struct param_opts popt;
1190 char pattern[PATH_MAX];
1191 char *path = NULL, *value = NULL;
1193 memset(&popt, 0, sizeof(popt));
1194 rc = setparam_cmdline(argc, argv, &popt);
1195 if (rc < 0 || rc >= argc)
1198 if (popt.po_params2)
1199 /* We can't delete parameters that were
1200 * set with old conf_param interface */
1201 return jt_lcfg_mgsparam2(argc, argv, &popt);
1203 for (i = rc, rc = 0; i < argc; i++) {
1206 value = strchr(argv[i], '=');
1207 if (value != NULL) {
1208 /* format: set_param a=b */
1215 /* format: set_param a b */
1225 rc2 = lprocfs_param_pattern(path, pattern, sizeof(pattern));
1229 rc2 = setparam_display(&popt, pattern, value);
1232 if (rc2 < 0 && rc == 0)
1235 if (path != NULL && (value == NULL || *value == '\0'))
1236 fprintf(stderr, "error: %s: setting %s=: %s\n",
1237 jt_cmdname(argv[0]), pattern, strerror(rc = EINVAL));