Whamcloud - gitweb
Land b_head_libcfs onto HEAD (20080805_1611)
[fs/lustre-release.git] / lustre / utils / lustre_cfg.c
1 /* -*- mode: c; c-basic-offset: 8; indent-tabs-mode: nil; -*-
2  * vim:expandtab:shiftwidth=8:tabstop=8:
3  *
4  * GPL HEADER START
5  *
6  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
7  *
8  * This program is free software; you can redistribute it and/or modify
9  * it under the terms of the GNU General Public License version 2 only,
10  * as published by the Free Software Foundation.
11  *
12  * This program is distributed in the hope that it will be useful, but
13  * WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
15  * General Public License version 2 for more details (a copy is included
16  * in the LICENSE file that accompanied this code).
17  *
18  * You should have received a copy of the GNU General Public License
19  * version 2 along with this program; If not, see [sun.com URL with a
20  * copy of GPLv2].
21  *
22  * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
23  * CA 95054 USA or visit www.sun.com if you need additional information or
24  * have any questions.
25  *
26  * GPL HEADER END
27  */
28 /*
29  * Copyright  2008 Sun Microsystems, Inc. All rights reserved
30  * Use is subject to license terms.
31  */
32 /*
33  * This file is part of Lustre, http://www.lustre.org/
34  * Lustre is a trademark of Sun Microsystems, Inc.
35  *
36  * lustre/utils/lustre_cfg.c
37  *
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>
42  */
43
44 #include <stdlib.h>
45 #include <sys/ioctl.h>
46 #include <stdio.h>
47 #include <stdarg.h>
48 #include <ctype.h>
49 #include <glob.h>
50
51 #ifndef __KERNEL__
52 #include <liblustre.h>
53 #endif
54 #include <lustre_lib.h>
55 #include <lustre_cfg.h>
56 #include <lustre/lustre_idl.h>
57 #include <lustre_dlm.h>
58 #include <obd.h>          /* for struct lov_stripe_md */
59 #include <obd_lov.h>
60 #include <lustre/lustre_build_version.h>
61
62 #include <unistd.h>
63 #include <sys/un.h>
64 #include <time.h>
65 #include <sys/time.h>
66 #include <errno.h>
67 #include <string.h>
68
69
70 #include "obdctl.h"
71 #include <lnet/lnetctl.h>
72 #include <libcfs/libcfsutil.h>
73 #include <stdio.h>
74
75 static char * lcfg_devname;
76
77 int lcfg_set_devname(char *name)
78 {
79         if (name) {
80                 if (lcfg_devname)
81                         free(lcfg_devname);
82                 /* quietly strip the unnecessary '$' */
83                 if (*name == '$' || *name == '%')
84                         name++;
85                 if (isdigit(*name)) { 
86                         /* We can't translate from dev # to name */
87                         lcfg_devname = NULL;
88                 } else {
89                         lcfg_devname = strdup(name);
90                 }
91         } else {
92                 lcfg_devname = NULL;
93         } 
94         return 0;
95 }
96
97 char * lcfg_get_devname(void)
98 {
99         return lcfg_devname;
100 }
101
102 int jt_lcfg_device(int argc, char **argv)
103 {
104         return jt_obd_device(argc, argv);
105 }
106
107 int jt_lcfg_attach(int argc, char **argv)
108 {
109         struct lustre_cfg_bufs bufs;
110         struct lustre_cfg *lcfg;
111         int rc;
112
113         if (argc != 4)
114                 return CMD_HELP;
115
116         lustre_cfg_bufs_reset(&bufs, NULL);
117
118         lustre_cfg_bufs_set_string(&bufs, 1, argv[1]);
119         lustre_cfg_bufs_set_string(&bufs, 0, argv[2]);
120         lustre_cfg_bufs_set_string(&bufs, 2, argv[3]);
121
122         lcfg = lustre_cfg_new(LCFG_ATTACH, &bufs);
123         rc = lcfg_ioctl(argv[0], OBD_DEV_ID, lcfg);
124         lustre_cfg_free(lcfg);
125         if (rc < 0) {
126                 fprintf(stderr, "error: %s: LCFG_ATTACH %s\n",
127                         jt_cmdname(argv[0]), strerror(rc = errno));
128         } else if (argc == 3) {
129                 char name[1024];
130
131                 lcfg_set_devname(argv[2]);
132                 if (strlen(argv[2]) > 128) {
133                         printf("Name too long to set environment\n");
134                         return -EINVAL;
135                 }
136                 snprintf(name, 512, "LUSTRE_DEV_%s", argv[2]);
137                 rc = setenv(name, argv[1], 1);
138                 if (rc) {
139                         printf("error setting env variable %s\n", name);
140                 }
141         } else {
142                 lcfg_set_devname(argv[2]);
143         }
144
145         return rc;
146 }
147
148 int jt_lcfg_setup(int argc, char **argv)
149 {
150         struct lustre_cfg_bufs bufs;
151         struct lustre_cfg *lcfg;
152         int i;
153         int rc;
154
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])); 
159                 return -EINVAL;
160         }
161
162         lustre_cfg_bufs_reset(&bufs, lcfg_devname);
163
164         if (argc > 6)
165                 return CMD_HELP;
166
167         for (i = 1; i < argc; i++) {
168                 lustre_cfg_bufs_set_string(&bufs, i, argv[i]);
169         }
170
171         lcfg = lustre_cfg_new(LCFG_SETUP, &bufs);
172         rc = lcfg_ioctl(argv[0], OBD_DEV_ID, lcfg);
173         lustre_cfg_free(lcfg);
174         if (rc < 0)
175                 fprintf(stderr, "error: %s: %s\n", jt_cmdname(argv[0]),
176                         strerror(rc = errno));
177
178         return rc;
179 }
180
181 int jt_obd_detach(int argc, char **argv)
182 {
183         struct lustre_cfg_bufs bufs;
184         struct lustre_cfg *lcfg;
185         int rc;
186
187         if (lcfg_devname == NULL) {
188                 fprintf(stderr, "%s: please use 'device name' to set the "
189                         "device name for config commands.\n", 
190                         jt_cmdname(argv[0])); 
191                 return -EINVAL;
192         }
193
194         lustre_cfg_bufs_reset(&bufs, lcfg_devname);
195
196         if (argc != 1)
197                 return CMD_HELP;
198
199         lcfg = lustre_cfg_new(LCFG_DETACH, &bufs);
200         rc = lcfg_ioctl(argv[0], OBD_DEV_ID, lcfg);
201         lustre_cfg_free(lcfg);
202         if (rc < 0)
203                 fprintf(stderr, "error: %s: %s\n", jt_cmdname(argv[0]),
204                         strerror(rc = errno));
205
206         return rc;
207 }
208
209 int jt_obd_cleanup(int argc, char **argv)
210 {
211         struct lustre_cfg_bufs bufs;
212         struct lustre_cfg *lcfg;
213         char force = 'F';
214         char failover = 'A';
215         char flags[3] = { 0 };
216         int flag_cnt = 0, n;
217         int rc;
218
219         if (lcfg_devname == NULL) {
220                 fprintf(stderr, "%s: please use 'device name' to set the "
221                         "device name for config commands.\n", 
222                         jt_cmdname(argv[0])); 
223                 return -EINVAL;
224         }
225
226         lustre_cfg_bufs_reset(&bufs, lcfg_devname);
227
228         if (argc < 1 || argc > 3)
229                 return CMD_HELP;
230
231         /* we are protected from overflowing our buffer by the argc
232          * check above
233          */
234         for (n = 1; n < argc; n++) {
235                 if (strcmp(argv[n], "force") == 0) {
236                         flags[flag_cnt++] = force;
237                 } else if (strcmp(argv[n], "failover") == 0) {
238                         flags[flag_cnt++] = failover;
239                 } else {
240                         fprintf(stderr, "unknown option: %s", argv[n]);
241                         return CMD_HELP;
242                 }
243         }
244
245         if (flag_cnt) {
246                 lustre_cfg_bufs_set_string(&bufs, 1, flags);
247         }
248
249         lcfg = lustre_cfg_new(LCFG_CLEANUP, &bufs);
250         rc = lcfg_ioctl(argv[0], OBD_DEV_ID, lcfg);
251         lustre_cfg_free(lcfg);
252         if (rc < 0)
253                 fprintf(stderr, "error: %s: %s\n", jt_cmdname(argv[0]),
254                         strerror(rc = errno));
255
256         return rc;
257 }
258
259 static 
260 int do_add_uuid(char * func, char *uuid, lnet_nid_t nid) 
261 {
262         int rc;
263         struct lustre_cfg_bufs bufs;
264         struct lustre_cfg *lcfg;
265
266         lustre_cfg_bufs_reset(&bufs, lcfg_devname);
267         if (uuid)
268                 lustre_cfg_bufs_set_string(&bufs, 1, uuid);
269
270         lcfg = lustre_cfg_new(LCFG_ADD_UUID, &bufs);
271         lcfg->lcfg_nid = nid;
272         /* Poison NAL -- pre 1.4.6 will LASSERT on 0 NAL, this way it 
273            doesn't work without crashing (bz 10130) */
274         lcfg->lcfg_nal = 0x5a;
275
276 #if 0
277         fprintf(stderr, "adding\tnid: %d\tuuid: %s\n",
278                lcfg->lcfg_nid, uuid);
279 #endif
280         rc = lcfg_ioctl(func, OBD_DEV_ID, lcfg);
281         lustre_cfg_free(lcfg);
282         if (rc) {
283                 fprintf(stderr, "IOC_PORTAL_ADD_UUID failed: %s\n",
284                         strerror(errno));
285                 return -1;
286         }
287
288         printf ("Added uuid %s: %s\n", uuid, libcfs_nid2str(nid));
289         return 0;
290 }
291
292 int jt_lcfg_add_uuid(int argc, char **argv)
293 {
294         lnet_nid_t nid;
295         
296         if (argc != 3) {                
297                 return CMD_HELP;
298         }
299
300         nid = libcfs_str2nid(argv[2]);
301         if (nid == LNET_NID_ANY) {
302                 fprintf (stderr, "Can't parse NID %s\n", argv[2]);
303                 return (-1);
304         }
305
306         return do_add_uuid(argv[0], argv[1], nid);
307 }
308
309 int obd_add_uuid(char *uuid, lnet_nid_t nid)
310 {
311         return do_add_uuid("obd_add_uuid", uuid, nid);
312 }
313
314 int jt_lcfg_del_uuid(int argc, char **argv)
315 {
316         int rc;
317         struct lustre_cfg_bufs bufs;
318         struct lustre_cfg *lcfg;
319
320         if (argc != 2) {
321                 fprintf(stderr, "usage: %s <uuid>\n", argv[0]);
322                 return 0;
323         }
324
325         lustre_cfg_bufs_reset(&bufs, lcfg_devname);
326         if (strcmp (argv[1], "_all_"))
327                 lustre_cfg_bufs_set_string(&bufs, 1, argv[1]);
328         
329         lcfg = lustre_cfg_new(LCFG_DEL_UUID, &bufs);
330         rc = lcfg_ioctl(argv[0], OBD_DEV_ID, lcfg);
331         lustre_cfg_free(lcfg);
332         if (rc) {
333                 fprintf(stderr, "IOC_PORTAL_DEL_UUID failed: %s\n",
334                         strerror(errno));
335                 return -1;
336         }
337         return 0;
338 }
339
340
341
342
343 int jt_lcfg_del_mount_option(int argc, char **argv)
344 {
345         int rc;
346         struct lustre_cfg_bufs bufs;
347         struct lustre_cfg *lcfg;
348
349         if (argc != 2)
350                 return CMD_HELP;
351
352         lustre_cfg_bufs_reset(&bufs, lcfg_devname);
353
354         /* profile name */
355         lustre_cfg_bufs_set_string(&bufs, 1, argv[1]);
356
357         lcfg = lustre_cfg_new(LCFG_DEL_MOUNTOPT, &bufs);
358         rc = lcfg_ioctl(argv[0], OBD_DEV_ID, lcfg);
359         lustre_cfg_free(lcfg);
360         if (rc < 0) {
361                 fprintf(stderr, "error: %s: %s\n", jt_cmdname(argv[0]),
362                         strerror(rc = errno));
363         }
364         return rc;
365 }
366
367 int jt_lcfg_set_timeout(int argc, char **argv)
368 {
369         int rc;
370         struct lustre_cfg_bufs bufs;
371         struct lustre_cfg *lcfg;
372
373         fprintf(stderr, "%s has been deprecated. Use conf_param instead.\n"
374                 "e.g. conf_param lustre-MDT0000 obd_timeout=50\n",
375                 jt_cmdname(argv[0]));
376         return CMD_HELP;
377
378
379         if (argc != 2)
380                 return CMD_HELP;
381
382         lustre_cfg_bufs_reset(&bufs, lcfg_devname);
383         lcfg = lustre_cfg_new(LCFG_SET_TIMEOUT, &bufs);
384         lcfg->lcfg_num = atoi(argv[1]);
385         
386         rc = lcfg_ioctl(argv[0], OBD_DEV_ID, lcfg);
387         //rc = lcfg_mgs_ioctl(argv[0], OBD_DEV_ID, lcfg);
388
389         lustre_cfg_free(lcfg);
390         if (rc < 0) {
391                 fprintf(stderr, "error: %s: %s\n", jt_cmdname(argv[0]),
392                         strerror(rc = errno));
393         }
394         return rc;
395 }
396
397
398
399 int jt_lcfg_add_conn(int argc, char **argv)
400 {
401         struct lustre_cfg_bufs bufs;
402         struct lustre_cfg *lcfg;
403         int priority;
404         int rc;
405
406         if (argc == 2)
407                 priority = 0;
408         else if (argc == 3)
409                 priority = 1;
410         else
411                 return CMD_HELP;
412
413         if (lcfg_devname == NULL) {
414                 fprintf(stderr, "%s: please use 'device name' to set the "
415                         "device name for config commands.\n", 
416                         jt_cmdname(argv[0])); 
417                 return -EINVAL;
418         }
419
420         lustre_cfg_bufs_reset(&bufs, lcfg_devname);
421
422         lustre_cfg_bufs_set_string(&bufs, 1, argv[1]);
423
424         lcfg = lustre_cfg_new(LCFG_ADD_CONN, &bufs);
425         lcfg->lcfg_num = priority;
426
427         rc = lcfg_ioctl(argv[0], OBD_DEV_ID, lcfg);
428         lustre_cfg_free (lcfg);
429         if (rc < 0) {
430                 fprintf(stderr, "error: %s: %s\n", jt_cmdname(argv[0]),
431                         strerror(rc = errno));
432         }
433
434         return rc;
435 }
436
437 int jt_lcfg_del_conn(int argc, char **argv)
438 {
439         struct lustre_cfg_bufs bufs;
440         struct lustre_cfg *lcfg;
441         int rc;
442
443         if (argc != 2)
444                 return CMD_HELP;
445
446         if (lcfg_devname == NULL) {
447                 fprintf(stderr, "%s: please use 'device name' to set the "
448                         "device name for config commands.\n", 
449                         jt_cmdname(argv[0])); 
450                 return -EINVAL;
451         }
452
453         lustre_cfg_bufs_reset(&bufs, lcfg_devname);
454
455         /* connection uuid */
456         lustre_cfg_bufs_set_string(&bufs, 1, argv[1]);
457
458         lcfg = lustre_cfg_new(LCFG_DEL_MOUNTOPT, &bufs);
459
460         rc = lcfg_ioctl(argv[0], OBD_DEV_ID, lcfg);
461         lustre_cfg_free(lcfg);
462         if (rc < 0) {
463                 fprintf(stderr, "error: %s: %s\n", jt_cmdname(argv[0]),
464                         strerror(rc = errno));
465         }
466
467         return rc;
468 }
469
470 /* Param set locally, directly on target */
471 int jt_lcfg_param(int argc, char **argv)
472 {
473         int i, rc;
474         struct lustre_cfg_bufs bufs;
475         struct lustre_cfg *lcfg;
476
477         if (argc >= LUSTRE_CFG_MAX_BUFCOUNT)
478                 return CMD_HELP;
479
480         lustre_cfg_bufs_reset(&bufs, NULL);
481
482         for (i = 1; i < argc; i++) {
483                 lustre_cfg_bufs_set_string(&bufs, i, argv[i]);
484         }
485
486         lcfg = lustre_cfg_new(LCFG_PARAM, &bufs);
487         
488         rc = lcfg_ioctl(argv[0], OBD_DEV_ID, lcfg);
489         lustre_cfg_free(lcfg);
490         if (rc < 0) {
491                 fprintf(stderr, "error: %s: %s\n", jt_cmdname(argv[0]),
492                         strerror(rc = errno));
493         }
494         return rc;
495 }
496
497 /* Param set in config log on MGS */
498 /* conf_param key1=value1 [key2=value2...] */
499 int jt_lcfg_mgsparam(int argc, char **argv)
500 {
501         int i, rc;
502         struct lustre_cfg_bufs bufs;
503         struct lustre_cfg *lcfg;
504
505         if ((argc >= LUSTRE_CFG_MAX_BUFCOUNT) || (argc <= 1))
506                 return CMD_HELP;
507
508         lustre_cfg_bufs_reset(&bufs, NULL);
509         for (i = 1; i < argc; i++) {
510                 lustre_cfg_bufs_set_string(&bufs, i, argv[i]);
511         }
512
513         /* We could put other opcodes here. */
514         lcfg = lustre_cfg_new(LCFG_PARAM, &bufs);
515
516         rc = lcfg_mgs_ioctl(argv[0], OBD_DEV_ID, lcfg);
517         lustre_cfg_free(lcfg);
518         if (rc < 0) {
519                 fprintf(stderr, "error: %s: %s\n", jt_cmdname(argv[0]),
520                         strerror(rc = errno));
521         }
522         
523         return rc;
524 }
525
526 /* Display the path in the same format as sysctl
527  * For eg. obdfilter.lustre-OST0000.stats */
528 static char *display_name(char *filename)
529 {
530         char *tmp;
531
532         filename += strlen("/proc/");
533         if (strncmp(filename, "fs/", strlen("fs/")) == 0)
534                 filename += strlen("fs/");
535         else
536                 filename += strlen("sys/");
537
538         if (strncmp(filename, "lustre/", strlen("lustre/")) == 0)
539                 filename += strlen("lustre/");
540
541         /* replace '/' with '.' to match conf_param and sysctl */
542         tmp = filename;
543         while ((tmp = strchr(tmp, '/')) != NULL)
544                 *tmp = '.';
545
546         return filename;
547 }
548
549 /* Find a character in a length limited string */
550 static char *strnchr(const char *p, char c, size_t n)
551 {
552        if (!p)
553                return (0);
554
555        while (n-- > 0) {
556                if (*p == c)
557                        return ((char *)p);
558                p++;
559        }
560        return (0);
561 }
562
563 int jt_lcfg_getparam(int argc, char **argv)
564 {
565         int fp;
566         int rc = 0, i, show_path = 0, only_path = 0;
567         char pattern[PATH_MAX];
568         char *path, *tmp, *buf;
569         glob_t glob_info;
570
571         if (argc == 3 && (strcmp(argv[1], "-n") == 0 || strcmp(argv[1], "-N") == 0)) {
572                 path = argv[2];
573                 if (strcmp(argv[1], "-N") == 0) {
574                         only_path = 1;
575                         show_path = 1;
576                 }
577         } else if (argc == 2) {
578                 show_path = 1;
579                 path = argv[1];
580         } else {
581                 return CMD_HELP;
582         }
583
584         /* If the input is in form Eg. obdfilter.*.stats */
585         if (strchr(path, '.')) {
586                 tmp = path;
587                 while (*tmp != '\0') {
588                         if (*tmp == '.')
589                                 *tmp = '/';
590                         tmp ++;
591                 }
592         }
593
594         /* If the entire path is specified as input */
595         fp = open(path, O_RDONLY);
596         if (fp < 0)
597                 snprintf(pattern, PATH_MAX, "/proc/{fs,sys}/{lnet,lustre}/%s",
598                          path);
599         else {
600                 strcpy(pattern, path);
601                 close(fp);
602         }
603
604         rc = glob(pattern, GLOB_BRACE, NULL, &glob_info);
605         if (rc) {
606                 fprintf(stderr, "error : glob %s: %s \n", pattern,strerror(rc));
607                 return rc;
608         }
609
610         buf = malloc(CFS_PAGE_SIZE);
611         for (i = 0; i  < glob_info.gl_pathc; i++) {
612                 char *valuename = NULL;
613
614                 memset(buf, 0, CFS_PAGE_SIZE);
615                 if (show_path) {
616                         char *filename;
617                         filename = strdup(glob_info.gl_pathv[i]);
618                         valuename = display_name(filename);
619                         if (valuename && only_path) {
620                                 printf("%s\n", valuename);
621                                 continue;
622                         }
623                 }
624
625                 /* Write the contents of file to stdout */
626                 fp = open(glob_info.gl_pathv[i], O_RDONLY);
627                 if (fp < 0) {
628                         fprintf(stderr, "error: %s: opening('%s') failed: %s\n",
629                                 jt_cmdname(argv[0]), glob_info.gl_pathv[i],
630                                 strerror(errno));
631                         continue;
632                 }
633
634                 do {
635                         rc = read(fp, buf, CFS_PAGE_SIZE);
636                         if (rc == 0)
637                                 break;
638                         if (rc < 0) {
639                                 fprintf(stderr, "error: %s: read('%s') "
640                                         "failed: %s\n", jt_cmdname(argv[0]),
641                                         glob_info.gl_pathv[i], strerror(errno));
642                                 break;
643                         }
644                         /* Print the output in the format path=value if the
645                          * value contains no new line character or cab be
646                          * occupied in a line, else print value on new line */
647                         if (valuename && show_path) {
648                                 int longbuf = strnchr(buf, rc - 1, '\n') != NULL
649                                               || rc > 60;
650                                 printf("%s=%s", valuename, longbuf ? "\n" : buf);
651                                 valuename = NULL;
652                                 if (!longbuf)
653                                         continue;
654                                 fflush(stdout);
655                         }
656                         rc = write(fileno(stdout), buf, rc);
657                         if (rc < 0) {
658                                 fprintf(stderr, "error: %s: write to stdout "
659                                         "failed: %s\n", jt_cmdname(argv[0]),
660                                         strerror(errno));
661                                 break;
662                         }
663                 } while (1);
664                 close(fp);
665         }
666
667         globfree(&glob_info);
668         free(buf);
669         return rc;
670 }
671
672
673 int jt_lcfg_setparam(int argc, char **argv)
674 {
675         int rc = 0, i;
676         int fp, show_path = 0;
677         char pattern[PATH_MAX];
678         char *path, *value, *tmp;
679         glob_t glob_info;
680
681         path = argv[1];
682         if (argc == 4 && (strcmp(argv[1], "-n") == 0)) {
683                 /* Format: lctl set_param -n param value */
684                 path = argv[2];
685                 value = argv[3];
686         } else if (argc == 3) {
687                 if (strcmp(argv[1], "-n") != 0) {
688                         /* Format: lctl set_param param value */
689                         show_path = 1;
690                         value = argv[2];
691                 } else if ((value = strchr(argv[2], '=')) != NULL) {
692                         /* Format: lctl set_param -n param=value */
693                         path = argv[2];
694                         *value = '\0';
695                         value ++;
696                 } else {
697                         fprintf(stderr, "error: %s Incorrect arguments."
698                                         "See Usage\n",
699                                 jt_cmdname(argv[0]));
700                         return CMD_HELP;
701                 }
702         } else if (argc == 2 && ((value = strchr(argv[1], '=')) != NULL)) {
703                 /* Format: lctl set_param param=value */
704                 show_path = 1;
705                 *value = '\0';
706                 value++;
707         } else {
708                 fprintf(stderr, "error: %s Incorrect arguments. See Usage\n",
709                         jt_cmdname(argv[0]));
710                 return CMD_HELP;
711         }
712
713         /* If the input is in form Eg. obdfilter.*.stats */
714         if (strchr(path, '.')) {
715                 tmp = path;
716                 while (*tmp != '\0') {
717                         if (*tmp == '.')
718                                 *tmp = '/';
719                         tmp ++;
720                 }
721         }
722
723         fp = open(path, O_RDONLY);
724         if (fp < 0)
725                 snprintf(pattern, PATH_MAX, "/proc/{fs,sys}/{lnet,lustre}/%s",
726                          path);
727         else {
728                 strcpy(pattern, path);
729                 close(fp);
730         }
731
732         rc = glob(pattern, GLOB_BRACE, NULL, &glob_info);
733         if (rc) {
734                 fprintf(stderr, "error : glob %s: %s \n", pattern,strerror(rc));
735                 return rc;
736         }
737         for (i = 0; i  < glob_info.gl_pathc; i++) {
738                 if (show_path) {
739                         char *valuename, *filename;
740                         filename = strdup(glob_info.gl_pathv[i]);
741                         valuename = display_name(filename);
742                         printf("%s=%s\n", valuename, value);
743                 }
744                 /* Write the new value to the file */
745                 fp = open(glob_info.gl_pathv[i], O_WRONLY);
746                 if (fp > 0) {
747                         rc = write(fp, value, strlen(value));
748                         if (rc < 0)
749                                 fprintf(stderr,
750                                         "error writing to file %s\n",
751                                         glob_info.gl_pathv[i]);
752                         else
753                                 rc = 0;
754                         close(fp);
755                 } else {
756                         fprintf(stderr, "error: %s: %s opening %s\n",
757                                 jt_cmdname(argv[0]), strerror(rc = errno),
758                                 glob_info.gl_pathv[i]);
759                 }
760         }
761
762         globfree(&glob_info);
763         return rc;
764 }